irp.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:10k
- #include <gendef.h>
- #include <stblast.h>
- #include <stcommon.h>
- #include <string.h>
- #include <sti5105.h>
- #include <swconfig.h>
- #include <stsys.h>
- #include "irp.h"
- #include "osp.h"
- /******************************************************************************
- * Extern variables
- ******************************************************************************/
- extern void IRCEvtCallback
- (
- STEVT_CallReason_t Reason,
- const ST_DeviceName_t RegistrantName,
- STEVT_EventConstant_t Event,
- const void *EventData,
- const void *SubscriberData_p
- );
- /******************************************************************************
- * Local variables
- ******************************************************************************/
- static ST_DeviceName_t BLAST_DeviceName = {"RX"};
- ST_ClockInfo_t ST_ClockInfo;
- static ST_DeviceName_t EvtblastDeviceName = "EVTBlast";
- extern partition_t *SystemPartition;
- STBLAST_Handle_t BLAST_Handle;
- UINT32 BlasterSemaphore_p;
- static STEVT_Handle_t IrEvtHandle;
- UINT32 blaster_EvtInit(void)
- {
- ST_ErrorCode_t error = ST_NO_ERROR;
- STEVT_InitParams_t EVTInitParams;
- STEVT_OpenParams_t EVTOpenParams;
- EVTInitParams.EventMaxNum = EVT_MAX_EVENTS;
- EVTInitParams.ConnectMaxNum = EVT_MAX_CONNECTIONS;
- EVTInitParams.SubscrMaxNum = EVT_MAX_SUBSCRIBERS;
- EVTInitParams.MemoryPartition = SystemPartition;
- error = STEVT_Init(EvtblastDeviceName, &EVTInitParams);
- if (error == ST_NO_ERROR)
- {
- error = STEVT_Open(EvtblastDeviceName, &EVTOpenParams,&IrEvtHandle);
- if(error != ST_NO_ERROR)
- {
- STTBX_Print(("STEVT_Open for blast failed"));
- return RETFIAL1;
- }
- }
- else
- {
- STTBX_Print(("STEVT_Init for blast failed"));
- return RETFIAL1;
- }
- return RETOK;
- }
- UINT32 blaster_Init(void)
- {
- ST_ErrorCode_t error;
- STBLAST_InitParams_t BLASTInitParams;
- STBLAST_OpenParams_t BlastOpenParams;
- STEVT_DeviceSubscribeParams_t EvtSubParams;
- STBLAST_Protocol_t Protocol;
- STBLAST_ProtocolParams_t ProtocolParams;
- memset(&BLASTInitParams, 0, sizeof(STBLAST_InitParams_t));
- memset(&BlastOpenParams, 0, sizeof(STBLAST_OpenParams_t));
- memset(&ProtocolParams, 0, sizeof(STBLAST_ProtocolParams_t));
-
- ST_GetClockInfo(&ST_ClockInfo);
-
- /* General parameter for blaster initialization */
- /* Parameters for IR receiver */
- BLASTInitParams.DeviceType = STBLAST_DEVICE_IR_RECEIVER;
- BLASTInitParams.DriverPartition = SystemPartition;
- BLASTInitParams.ClockSpeed = BLAST_CLOCK_FREQUENCY;
- BLASTInitParams.SymbolBufferSize = SYMBOL_BUFFER_SIZE;
- BLASTInitParams.BaseAddress = (U32 *)IRB_BASE_ADDRESS;
- BLASTInitParams.InterruptNumber = IRB_INTERRUPT;
- BLASTInitParams.InterruptLevel = IRB_INTERRUPT_LEVEL;
- BLASTInitParams.InputActiveLow = TRUE;
- strcpy(BLASTInitParams.EVTDeviceName, EvtblastDeviceName);
- strcpy(BLASTInitParams.RxPin.PortName, BLAST_RXD_PIO);
-
- BLASTInitParams.RxPin.BitMask = BLAST_RXD_BIT;
- error = STBLAST_Init(BLAST_DeviceName, &BLASTInitParams);
- if (error != ST_NO_ERROR)
- {
- STTBX_Print(("nSTBLAST_Init Error,Code=0x%x",error));
- return RETFIAL1;
- }
- BlastOpenParams.RxParams.GlitchWidth = 0;
- error = STBLAST_Open(BLAST_DeviceName, &BlastOpenParams, &BLAST_Handle);
- if (error != ST_NO_ERROR)
- {
- STTBX_Print(("nSTBLAST_Open Error"));
- return RETFIAL1;
- }
- /* Subscribe to the relevant blaster events */
- memset(&EvtSubParams, 0, sizeof(EvtSubParams));
- EvtSubParams.NotifyCallback = IRCEvtCallback;
- error = STEVT_SubscribeDeviceEvent(IrEvtHandle,
- BLAST_DeviceName,
- STBLAST_READ_DONE_EVT,
- &EvtSubParams);
- if (error != ST_NO_ERROR)
- {
- STTBX_Print(("IRC Sbscribe Event Error"));
- }
-
- KB_OSPSemInit("BLAS", 0, J_OSP_WAIT_FIFO, &BlasterSemaphore_p);
-
- /* Config the protocol */
- #if defined (PROTOCOL_RC6A)
- Protocol = STBLAST_PROTOCOL_RC6A;
- ProtocolParams.RC6A.CustomerCode = 0x00000000;
- ProtocolParams.RC6A.BufferElementsPerPayload = 1; /* not used yet */
- ProtocolParams.RC6A.NumberPayloadBits = 12;
- error = STBLAST_SetProtocol(BLAST_Handle, Protocol, &ProtocolParams);
- #elif defined (PROTOCOL_RC6_MODE0)
- Protocol = STBLAST_PROTOCOL_RC6_MODE0;
- ProtocolParams.RC6A.CustomerCode = 39;
- ProtocolParams.RC6A.BufferElementsPerPayload = 1; /* not used yet */
- ProtocolParams.RC6A.NumberPayloadBits = 8;
- error = STBLAST_SetProtocol(BLAST_Handle, Protocol, &ProtocolParams);
- #elif defined (PROTOCOL_RC5) /* protocol params is not required for the RC5 */
- Protocol = STBLAST_PROTOCOL_RC5;
- memset(&ProtocolParams, 0, sizeof(STBLAST_ProtocolParams_t));
- error = STBLAST_SetProtocol(BLAST_Handle, Protocol, &ProtocolParams);
- #elif defined (PROTOCOL_USER_DEFINED)
- Protocol = STBLAST_PROTOCOL_USER_DEFINED;
- /*----------------- NEC Remote Control ------------------*/
- ProtocolParams.UserDefined.Coding = STBLAST_CODING_SPACE;
- ProtocolParams.UserDefined.SubCarrierFreq = 38000;
- ProtocolParams.UserDefined.NumberStartSymbols = 1;
- ProtocolParams.UserDefined.NumberStopSymbols = 0;
- #if defined(ST_7100)
- /* for 7100 the received value tolerence is diffrent
- depends on receiver */
- ProtocolParams.UserDefined.HighDataSymbol.MarkPeriod = 600;
- ProtocolParams.UserDefined.HighDataSymbol.SymbolPeriod = 2240;
- ProtocolParams.UserDefined.LowDataSymbol.MarkPeriod = 600;
- ProtocolParams.UserDefined.LowDataSymbol.SymbolPeriod = 1120;
- #else
- ProtocolParams.UserDefined.HighDataSymbol.MarkPeriod = 560;
- ProtocolParams.UserDefined.HighDataSymbol.SymbolPeriod = 2240;
- ProtocolParams.UserDefined.LowDataSymbol.MarkPeriod = 560;
- ProtocolParams.UserDefined.LowDataSymbol.SymbolPeriod = 1120;
- #endif
- ProtocolParams.UserDefined.NumberPayloadBits = 32;
- ProtocolParams.UserDefined.BufferElementsPerPayload = 1;
- /* Setup the SPACE coded protocol */
- /* Start symbol */
- ProtocolParams.UserDefined.StartSymbols[0].MarkPeriod = 9000;
- ProtocolParams.UserDefined.StartSymbols[0].SymbolPeriod = 13500;
-
- #if 0
- /*--------- Force Remote Control ------------*/
- ProtocolParams.UserDefined.Coding = STBLAST_CODING_SPACE;
- ProtocolParams.UserDefined.SubCarrierFreq = 38000;
- ProtocolParams.UserDefined.NumberStartSymbols = 10;
- ProtocolParams.UserDefined.NumberStopSymbols = 0;
- ProtocolParams.UserDefined.HighDataSymbol.MarkPeriod = 600;
- ProtocolParams.UserDefined.HighDataSymbol.SymbolPeriod = 2000;
- ProtocolParams.UserDefined.LowDataSymbol.MarkPeriod = 600;
- ProtocolParams.UserDefined.LowDataSymbol.SymbolPeriod = 1000;
- ProtocolParams.UserDefined.NumberPayloadBits = 8;
- ProtocolParams.UserDefined.BufferElementsPerPayload=1;
- /* Setup the SPACE coded protocol */
- /* Start symbol */
- ProtocolParams.UserDefined.StartSymbols[0].MarkPeriod = 8000;
- ProtocolParams.UserDefined.StartSymbols[0].SymbolPeriod = 12000;
-
- /* Address symbols */
- ProtocolParams.UserDefined.StartSymbols[1].MarkPeriod = 600; /* 0*/
- ProtocolParams.UserDefined.StartSymbols[1].SymbolPeriod = 1000;
- ProtocolParams.UserDefined.StartSymbols[2].MarkPeriod = 600; /* 0*/
- ProtocolParams.UserDefined.StartSymbols[2].SymbolPeriod = 1000;
- ProtocolParams.UserDefined.StartSymbols[3].MarkPeriod = 600; /* 0*/
- ProtocolParams.UserDefined.StartSymbols[3].SymbolPeriod = 1000;
- ProtocolParams.UserDefined.StartSymbols[4].MarkPeriod = 600; /* 1*/
- ProtocolParams.UserDefined.StartSymbols[4].SymbolPeriod = 2000;
- ProtocolParams.UserDefined.StartSymbols[5].MarkPeriod = 600; /* 0*/
- ProtocolParams.UserDefined.StartSymbols[5].SymbolPeriod = 1000;
- ProtocolParams.UserDefined.StartSymbols[6].MarkPeriod = 600; /* 0*/
- ProtocolParams.UserDefined.StartSymbols[6].SymbolPeriod = 1000;
- ProtocolParams.UserDefined.StartSymbols[7].MarkPeriod = 600; /* 0*/
- ProtocolParams.UserDefined.StartSymbols[7].SymbolPeriod = 1000;
- ProtocolParams.UserDefined.StartSymbols[8].MarkPeriod = 600; /* 0*/
- ProtocolParams.UserDefined.StartSymbols[8].SymbolPeriod = 1000;
-
- /* Padding symbol */
- ProtocolParams.UserDefined.StartSymbols[9].MarkPeriod = 600;
- ProtocolParams.UserDefined.StartSymbols[9].SymbolPeriod = 4500;
-
- /*----------------- Sony Remote Control ------------------*/
- ProtocolParams.UserDefined.Coding = STBLAST_CODING_PULSE;
- ProtocolParams.UserDefined.SubCarrierFreq = 40000;
- ProtocolParams.UserDefined.NumberStartSymbols = 1;
- ProtocolParams.UserDefined.NumberStopSymbols = 0;
- ProtocolParams.UserDefined.HighDataSymbol.MarkPeriod = 600;
- ProtocolParams.UserDefined.HighDataSymbol.SymbolPeriod = 1200;
- ProtocolParams.UserDefined.LowDataSymbol.MarkPeriod = 1200;
- ProtocolParams.UserDefined.LowDataSymbol.SymbolPeriod = 1800;
- ProtocolParams.UserDefined.NumberPayloadBits = 12;
- ProtocolParams.UserDefined.StartSymbols[0].MarkPeriod = 2400;
- ProtocolParams.UserDefined.StartSymbols[0].SymbolPeriod = 3000;
- /*----------------- ST Remote Control --------------------*/
- ProtocolParams.UserDefined.Coding = STBLAST_CODING_SPACE;
- ProtocolParams.UserDefined.SubCarrierFreq = 5000;
- ProtocolParams.UserDefined.NumberStartSymbols = 0;
- ProtocolParams.UserDefined.NumberStopSymbols = 0;
- ProtocolParams.UserDefined.HighDataSymbol.MarkPeriod = 250;
- ProtocolParams.UserDefined.HighDataSymbol.SymbolPeriod = 7600;
- ProtocolParams.UserDefined.LowDataSymbol.MarkPeriod = 250;
- ProtocolParams.UserDefined.LowDataSymbol.SymbolPeriod = 5100;
- ProtocolParams.UserDefined.NumberPayloadBits = 12;
- #endif
-
- error = STBLAST_SetProtocol(BLAST_Handle, Protocol, &ProtocolParams);
- #endif
- if (error != ST_NO_ERROR)
- {
- STTBX_Print(("nSTBLAST_SetProtocol Error %dn", error));
- return RETFIAL1;
- }
- STTBX_Print(("nblaster_Init OKn"));
- return RETOK;
- }
- /* End of file */