blast.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:9k
- /*****************************************************************************
- File name : blast.c
- Description : STBlast interface.
- COPYRIGHT (C) STMicroelectronics 2002.
- Authors TM Chua (tm.chua@st.com)
- Original Work: blast.c
- ===========================
- * IMPROVEMENTS OF THOUGHT *
- ===========================
- ========================
- * MODIFICATION HISTORY *
- ========================
- Date Name Modification
- ---- ---- ------------
- 04 Sep 03 TM Created
- 01 Mar 04 TM Adpat for HD STB
- *****************************************************************************/
- #ifndef __BLAST_C__ /* Prevent multiple inclusion of the file */
- #define __BLAST_C__
- /* C++ support */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /* ************************************************************************
- I N C L U D E S
- ************************************************************************ */
- #include <string.h>
- #include "stdevice.h"
- #include "sttbx.h"
- #include "stpio.h"
- #include "stevt.h"
- #include "errors.h"
- #include "blast.h"
- /* ************************************************************************
- EVENT
- ************************************************************************ */
- #define NUMBER_EVT 1
- #define EVT_MAX_EVENTS 15
- #define EVT_MAX_CONNECTIONS 15
- #define EVT_MAX_SUBSCRIBERS 10
- static ST_DeviceName_t EvtblastDeviceName[] = {"EVTBlast"};
- static STEVT_Handle_t EvtHandle[NUMBER_EVT];
- enum
- {
- EVT_DEVICE_0,
- EVT_DEVICE_1,
- EVT_DEVICE_2
- };
- /* ************************************************************************
- D E F I N E S
- ************************************************************************ */
- #define BLAST_EVT_DEV EvtblastDeviceName[0]
- #define BLAST_CLOCK_FREQUENCY ST_ClockInfo.CommsBlock
- #define BLAST_TXD_TYPE STBLAST_DEVICE_IR_TRANSMITTER
- #define BLAST_RXD_TYPE STBLAST_DEVICE_IR_RECEIVER
- #define BLAST_RXD_NUM 0
- #define BLAST_EVT_HDL EvtHandle[EVT_DEVICE_0]
- STBLAST_Handle_t BlasterHandle[NUMBER_BLAST];
- /* Variables used by event handler */
- ST_ErrorCode_t LastEvent;
- ST_ErrorCode_t LastError;
- /* semaphore used by event handler */
- semaphore_t BlasterSemaphore;
- /* Blaster device names for transmitter and receiver */
- static ST_DeviceName_t BlasterDeviceName[] =
- {
- "TX",
- "RX"
- };
- static ST_ClockInfo_t ST_ClockInfo;
- extern partition_t *SystemPartition;
- /* Extern function ------------------------------------------------------*/
- /* Static function ------------------------------------------------------*/
- static ST_ErrorCode_t blaster_Init(void);
- static void blaster_Callback(STEVT_CallReason_t Reason,
- const ST_DeviceName_t RegistrantName,
- STEVT_EventConstant_t Event,
- const void *EventData,
- const void *SubscriberData_p);
- static BOOL blaster_EvtInit(void);
- /* ************************************************************************
- F U N C T I O N S
- ************************************************************************ */
- static BOOL blaster_EvtInit(void)
- {
- int i;
- 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;
- for (i = 0; i < NUMBER_EVT && error == ST_NO_ERROR; i++)
- {
- error = STEVT_Init(EvtblastDeviceName[i], &EVTInitParams);
- if (error == ST_NO_ERROR)
- {
- error = STEVT_Open(EvtblastDeviceName[i], &EVTOpenParams,
- &EvtHandle[i]);
- }
- }
- return error ? TRUE : FALSE;
- }
- /* stdoc ******************************************************************
- Name: blaster_Callback
-
- Purpose: Event handler for IR Blaster device events.
-
- Arguments: <STEVT_CallReason_t Reason> The reason because the
- callback has been invoked
- <const ST_DeviceName_t RegistrantName> The registrant name
- <STEVT_EventConstant_t Event> The event to check and
- manage
- <const void *EventData> The event data
- <const void *SubscriberData_p> The data to indentify
- a specific subscriber
-
- ReturnValue: None
-
- Public: No
-
- ************************************************************************ */
- static void blaster_Callback(STEVT_CallReason_t Reason,
- const ST_DeviceName_t RegistrantName,
- STEVT_EventConstant_t Event,
- const void *EventData,
- const void *SubscriberData_p)
- {
- switch (Event)
- {
- /* A infrared command has been transmitted or received */
- case STBLAST_READ_DONE_EVT:
- case STBLAST_WRITE_DONE_EVT:
- LastEvent = Event;
- LastError = ((STBLAST_EvtReadDoneParams_t *)EventData)->Result;
- /* signal the blaster semaphore */
- semaphore_signal(&BlasterSemaphore);
- break;
- default:
- break;
- }
- }
- /* stdoc ******************************************************************
- Name: BLASTER_Setup
-
- Purpose: Init and open the blast driver for receiver and transmitter
- mode.
-
- Arguments: None
-
- ReturnValue: ST_NO_ERROR if all is ok, or a specific error code depending
- on the called api
-
- Public: No
-
- ************************************************************************ */
- static ST_ErrorCode_t blaster_Init(void)
- {
- ST_ErrorCode_t error = ST_NO_ERROR;
- STBLAST_InitParams_t BLASTInitParams;
- STBLAST_OpenParams_t BlastOpenParams;
- STEVT_DeviceSubscribeParams_t EvtSubParams;
- memset(&BLASTInitParams, 0, sizeof(STBLAST_InitParams_t));
- memset(&BlastOpenParams, 0, sizeof(STBLAST_OpenParams_t));
- (void) ST_GetClockInfo(&ST_ClockInfo);
- /* Set glitch width */
- BlastOpenParams.RxParams.GlitchWidth = 0;
-
- /* General parameter for blaster initialization */
- BLASTInitParams.DeviceType = BLAST_TXD_TYPE;
- 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[0]/*BLAST_EVT_DEV*/);
- /* Parameters for IR receiver */
- BLASTInitParams.DeviceType = BLAST_RXD_TYPE;
- /*BLASTInitParams.DeviceNumber = BLAST_RXD_NUM;*/
- strcpy(BLASTInitParams.RxPin.PortName, BLAST_RXD_PIO);
- BLASTInitParams.RxPin.BitMask = BLAST_RXD_BIT;
- error = STBLAST_Init(BlasterDeviceName[BLASTER_RECEIVER], &BLASTInitParams);
-
- if (error == ST_NO_ERROR)
- {
- STTBX_Print (("STBLAST_Init(RX)=%sn", STBLAST_GetRevision()));
- }
- else
- {
- }
-
- if (error == ST_NO_ERROR)
- {
- error = STBLAST_Open(BlasterDeviceName[BLASTER_RECEIVER], &BlastOpenParams,
- &BlasterHandle[BLASTER_RECEIVER]);
- if (error != ST_NO_ERROR)
- {
- return error;
- }
- if (error == ST_NO_ERROR)
- {
- /* Subscribe to the relevant blaster events */
- memset(&EvtSubParams, 0, sizeof(EvtSubParams));
- EvtSubParams.NotifyCallback = blaster_Callback;
- error = STEVT_SubscribeDeviceEvent(BLAST_EVT_HDL,
- BlasterDeviceName[BLASTER_RECEIVER],
- STBLAST_READ_DONE_EVT,
- &EvtSubParams);
- if (error != ST_NO_ERROR)
- {
- return error;
- }
- }
- }
- /* Initialize BlasterSemaphore semaphore */
- semaphore_init_fifo(&BlasterSemaphore, 0);
- return error;
-
- }/* end BLASTER_Setup() */
- ST_ErrorCode_t BLASTER_Setup ( void )
- {
- ST_ErrorCode_t error=ST_NO_ERROR;
-
- error = blaster_EvtInit();
- if ( error != ST_NO_ERROR )
- {
- STTBX_Print(("InitEvt for BLAST failn"));
- return error;
- }
- error = blaster_Init();
- if ( error != ST_NO_ERROR )
- {
- STTBX_Print(("InitBlast failn"));
- return error;
- }
- return error;
- }
- /* end C++ support */
- #ifdef __cplusplus
- }
- #endif
- #endif /* #ifndef __BLAST_C__ */
- /*EOF*/