//***************************************************************************** //***************************************************************************** //** API Functions //***************************************************************************** //***************************************************************************** GERR GD_DMA_Init(void) { GERR err = GD_OK; GD_INT_OPEN_PARAMS_S intParams; if(initialised) { return(GD_OK); } memset((void *)dmaDescriptor, 0, sizeof(GD_DMA_DESCRIPTOR_S)*DMA_CHAN_MAX_NUM*DMA_CHAN_MAX_DESC); memset((void *)dmaDev, 0, sizeof(DMA_DEVICE_S)*DMA_CHAN_MAX_NUM); intParams.type = GD_INT_DMA_IRQ; intParams.sensitivity = GD_INT_LEVEL_HIGH; intParams.active = GD_INT_NO_INVERT_IRQ; intParams.priority = GD_INT_MID_PRIORITY; intParams.isrFct.lowPrio = dma_int_handler; err = GD_INT_Open(&intParams,&dmaIntHandle); if(err != GD_OK) { return err; } GD_INT_Enable(&dmaIntHandle, GD_INT_ENABLED); initialised = 1; return GD_OK; }
GERR GD_ICC_UART_Init() { GD_INT_OPEN_PARAMS_S int_params; GD_HANDLE int_handle; GD_HANDLE gpio_handle; GD_GPIO_INT_CONFIG_S gpiocfg; GD_GPIO_OpenFunctionMode( GD_GPIO_TYPE_OUTPUT_ICC0_DATA, &gpio_handle ); GD_GPIO_OpenFunctionMode( GD_GPIO_TYPE_INPUT_ICC0_DATA, &gpio_handle ); int_params.type = (S8)GD_INT_ICC0_IRQ; int_params.sensitivity = GD_INT_LEVEL_SENSITIVE; int_params.active = GD_INT_INVERT_IRQ; int_params.priority = GD_INT_LOW_PRIORITY; //int_params.priority = GD_INT_MID_PRIORITY; int_params.isrFct.lowPrio = GD_ICC0_ISR; //int_params.isrFct.midPrio = GD_ICC0_MID_ISR; GH_ICC_init(); GH_ICC_set_GuardTimer( 0, (U32)ICC_DEFAULT_GUART_TIME + 10); GH_ICC_set_PortControl( 0, (U32)0 ); GH_ICC_set_GlobalControl( 0, (U32)0 ); GH_ICC_set_ExtendedControl(0,0); //GH_ICC_set_PortControl_TRIMOD( 0, 0 );//? //GH_ICC_set_PortControl_IO1EN( 0, 1 );//? GH_ICC_set_PortControl_RS232(0,0); GH_ICC_set_CardClock_INTEGER(0,6); GH_ICC_set_CardClock_FRACTION(0,0x12); GH_ICC_set_Baudrate(0,0xF); //115200 GH_ICC_set_GlobalControl_FRM0(0,1); GH_ICC_set_GlobalControl_FRM1(0,0); GH_ICC_set_ExtendedControl_ENABLE_10ETU(0,1); // GD_INT_SetHandler( int_params.type, GD_ICC_Handler ); if( GD_INT_Open( &int_params, &int_handle ) != GD_OK ) { GM_PrStr( "[ICC0] Open ICC UArt Error!\n"); return( GD_ERR_DEVICE_BUSY ); } GM_PrStr( "[ICC0] Open ICC UArt Correct!\n"); return( GD_OK ); }
/*---------------------------------------------------------------------------*/ GERR GND_I2C_Init(GD_I2C_INIT_PARAMS_S* paramsP) { GD_HANDLE gpioHd; /* Reset the SCL & SDA pin of I2C */ GD_GPIO_Open(GD_GPIO_INOUT_I2C_CLK , GD_GPIO_TYPE_INOUT_I2C_CLK, 0, &gpioHd ); GD_GPIO_Open(GD_GPIO_INOUT_I2C_DATA , GD_GPIO_TYPE_INOUT_I2C_DATA, 0, &gpioHd ); /* initialize I2c registers */ /* GH_I2C_set_ControlReg0(0L); GH_I2C_set_ControlReg0_USE_ADD(1); GH_I2C_set_ControlReg0_AM_ON(1); GH_I2C_set_ControlReg0_SPIKE_FILT(1); GH_I2C_set_ControlReg0_OI_DLY_AL(1); CtrlReg0Shadow = GH_I2C_get_ControlReg0(); */ CtrlReg0Shadow = BIT7|BIT4|BIT10|BIT11; GNH_EXT_SetRegister(REG_I2C_CONTROLREG0,CtrlReg0Shadow); /* GH_I2C_set_ControlReg1(0L); GH_I2C_set_ControlReg1_SL_SLA_ADD(MPEG_SLAADD>>1); CtrlReg1Shadow = GH_I2C_get_ControlReg1(); */ CtrlReg1Shadow = MPEG_SLAADD; GNH_EXT_SetRegister(REG_I2C_CONTROLREG1,CtrlReg1Shadow); /* GH_I2C_set_IRQMask0(0L); GH_I2C_set_IRQMask1(0L); */ GNH_EXT_SetRegister(REG_I2C_IRQMASK0,0); GNH_EXT_SetRegister(REG_I2C_IRQMASK1,0); /* Open the I2C interrupt */ GD_INT_OPEN_PARAMS_S paramsInt; paramsInt.active = GD_INT_INVERT_IRQ; paramsInt.priority = GD_INT_LOW_PRIORITY; paramsInt.sensitivity = GD_INT_LEVEL_SENSITIVE; paramsInt.type = GD_INT_IIC_IRQ; paramsInt.isrFct.lowPrio = GND_ISR_I2C_Handler; GD_INT_Open(¶msInt, NULL); return GD_OK; }
/*! ******************************************************************************* ** ** \brief Initialises the IR driver. ** ** This function must be called at start-up to set the interrupt service ** routine for the infrared interrupt and to register the callback ** function. ** ** \param pInitParams Pointer to the init parameters. ** ** \return Possible return codes: ** - #GD_OK ** - #GD_ERR_ALREADY_INITIALIZED ** ** \sa GD_IR_SetNotifyFunction() ** ******************************************************************************/ GERR GD_IR_Init(GD_IR_INIT_PARAMS_S *pInitParams) { GD_INT_OPEN_PARAMS_S intparams; GERR ret = GD_OK; GD_HANDLE handle; intparams.type = GD_INT_IR_IRQ; intparams.sensitivity = GD_INT_LEVEL_SENSITIVE; intparams.active = GD_INT_INVERT_IRQ; intparams.priority = GD_INT_LOW_PRIORITY; intparams.isrFct.lowPrio = FI_IR_ISR; NotifyFunction = pInitParams->notifyFunction; ret = GD_INT_Open(&intparams,&handle); if (ret != GD_OK) { return GD_ERR_ALREADY_INITIALIZED; } return GD_OK; }
int XD_UaInitUart(GD_UART_BAUDRATE_E BaudRate) { volatile T_SMARTMPEG_UART_PORT *pUART; OpU8 RxChar; U32 mode; // Steven Yu GD_HANDLE gpioHd; #ifdef DEBUG GD_HANDLE uartHd; #endif GD_GPIO_Open(GD_GPIO_28 , GD_GPIO_TYPE_INPUT_UART_RX, 0, &gpioHd ); GD_GPIO_Open(GD_GPIO_29 , GD_GPIO_TYPE_OUTPUT_UART_TX, 0, &gpioHd ); //XD_CiSetMpegSRegBits(SHR16IDX_GPIO_SELECT_LOW, GPIO_L_UART_TX|GPIO_L_UART_RX); // enable UART operation #ifdef DEBUG OSAddTask((void (*)(void *))UartTask, TASK_UART_PRIO, STACK_UART, UART_TASK_STK_SIZE); GD_INT_OPEN_PARAMS_S intparams; intparams.type = GD_INT_UART_IRQ; intparams.sensitivity = GD_INT_LEVEL_SENSITIVE; intparams.active = GD_INT_INVERT_IRQ; intparams.priority = GD_INT_LOW_PRIORITY; intparams.isrFct.lowPrio = ISR_UART_Handler; GNH_EXT_SetRegister(REG_UART_IRQCLEAR,0x03); /* clear interrupt */ GD_INT_Open(&intparams, &uartHd); #endif mode = getDataRateMode(BaudRate); pUART = (volatile T_SMARTMPEG_UART_PORT*) REG_UART_DATA; // Init Pointer to UART Control Registers pUART->LineControl = 0x00F0; // 8 Databits, 1 Stop, no parity pUART->Enable = 0x0003; // Internal clock, RX enable pUART->Delta1 = BaudRateTable[mode * 4 + 2] & 0xff; //0x53; pUART->ClkBound = BaudRateTable[mode * 4 + 1] & 0xffff; //0x0D; // DPLL bound pUART->DifDelt = BaudRateTable[mode * 4 + 3] & 0x3ff; //0x2D; pUART->DmaReqCtrl = 0x0000; //pUART->IrqMaskReg = BIT1; // enable RxInt. just for Test pUART->IrqMaskReg = 0; // disable RxInt. RxChar = pUART->Data; // empty receive register return RxChar; }
/*! ***************************************************************************** ** \brief Initialize the Ethernet driver. ** ** This function initializes Ethernet driver. ** It allocates and initializes driver handle structures as well as ** internal buffers for succeeding GD_ETH_Open(). Currently buffers are ** statically allocated. Setting up hardware is not part of GD_ETH_Init(), ** but is executed in GD_ETH_Open(). ** ** \note This function is the implementation of ** GD_SYS_DriverT::initDriverFunc. ** ** \return ** - #GD_OK On success ** - #GD_ERR_ALREADY_INITIALIZED Driver is already initialized ** - #GD_ERR_INVALID_HANDLE Invalid handle is specified ** - #GD_ERR_SEMAPHORE_CREATE Semaphore can not be created ** - #GD_ERR_OUT_OF_MEMORY Memory allocation failed ** Not Implemented yet ** ** \sa GD_ETH_Exit() ***************************************************************************** */ GERR GD_ETH_Init(GD_ETH_InitParamsT* pInitParams) { S32 retval; GD_INT_OPEN_PARAMS_S intOpenParams; if(ethIntHandle) { return GD_ERR_ALREADY_INITIALIZED; } if(pInitParams == NULL) { return GD_ERR_BAD_PARAMETER; } intOpenParams.type = GD_INT_ETH_IRQ; intOpenParams.sensitivity = GD_INT_LEVEL_HIGH; intOpenParams.priority = GD_INT_MID_PRIORITY; intOpenParams.active = GD_INT_INVERT_IRQ; intOpenParams.isrFct.lowPrio = GD_ETH_Isr; retval = GD_INT_Open(&intOpenParams, ðIntHandle); if (retval != GD_OK) { return retval; } if (pInitParams->phyreset != GD_GPIO_0) { GD_GPIO_Open(pInitParams->phyreset, GD_GPIO_TYPE_OUTPUT_1, NULL, ðdevice.phyreset); } if(pInitParams->bHWReset) { GD_ETH_PHY_HWReset((GD_HANDLE)ðdevice); } ethdevice.phyType = pInitParams->phyType; GD_ETH_PHY_Init(pInitParams->phyType); return retval; }
/*! ******************************************************************************* ** ** \brief Initializes the driver. ** ** This function initializes the TIMER driver. It initializes the ** internal timer variables and registers the interrupts of hard- and ** soft timer. Furthermore it starts the time GPREG timer. ** ** \param initParams Pointer to TIMER init data structure containing all ** customizable driver parameter. ** ** \return One of the following status codes: ** - #GD_OK if successful ** - #GD_ERR_ALREADY_INITIALIZED if this function has already been ** called. ** - #GD_ERR_BAD_PARAMETER if the initialization parameter are not ** correctly specified. ******************************************************************************/ GERR GD_TIMER_Init(GD_TIMER_INIT_PARAMS_S* initParams) { GERR ret = GD_OK; GD_INT_OPEN_PARAMS_S params; int i; nTimeStamp = 0; if (gd_timer_TimerInitFlag != GFALSE) return GD_ERR_ALREADY_INITIALIZED; if ((initParams->softTimerReg != GD_REG_TIMER1 && initParams->softTimerReg != GD_REG_TIMER2 && initParams->softTimerReg != GD_REG_TIMER3) || (initParams->hardTimerReg != GD_REG_TIMER1 && initParams->hardTimerReg != GD_REG_TIMER2 && initParams->hardTimerReg != GD_REG_TIMER3) || (initParams->gpregTimerReg != GD_REG_TIMER1 && initParams->gpregTimerReg != GD_REG_TIMER2 && initParams->gpregTimerReg != GD_REG_TIMER3) || (initParams->hardTimerReg == initParams->softTimerReg) || (initParams->gpregTimerReg == initParams->softTimerReg) || (initParams->hardTimerReg == initParams->gpregTimerReg) ) { return GD_ERR_BAD_PARAMETER; } for ( i = 0; i <= GD_TIMER_MAX_SOFT_TIME; i++ ) { gd_timer_sSoftTime[i].nIndex = i; gd_timer_sSoftTime[i].nTimeCount = 0; gd_timer_sSoftTime[i].nStoreCount = 0; gd_timer_sSoftTime[i].eState = TIME_FREE; gd_timer_sSoftTime[i].bpTimeEnd = NULL; gd_timer_sSoftTime[i].fpCallBackAddress=NULL; } gd_timer_sHardTime.eState = TIME_FREE; gd_timer_sHardTime.nTimeCount = 0; gd_timer_sHardTime.bpTimeEnd = NULL; gd_timer_sHardTime.fpCallBackAddress = NULL; gd_timer_sGpregTime.eState = TIME_FREE; gd_timer_sGpregTime.nTimeCount = 0; gd_timer_sGpregTime.bpTimeEnd = NULL; gd_timer_sGpregTime.fpCallBackAddress = NULL; params.active = GD_INT_NO_INVERT_IRQ; params.sensitivity = GD_INT_RISING_EDGE; /* soft timer init */ if (initParams->softTimerReg == GD_REG_TIMER1) params.type = GD_INT_TIMER1_IRQ; else if (initParams->softTimerReg == GD_REG_TIMER2) params.type = GD_INT_TIMER2_IRQ; else if (initParams->softTimerReg == GD_REG_TIMER3) params.type = GD_INT_TIMER3_IRQ; for ( i = 0; i <= GD_TIMER_MAX_SOFT_TIME; i++ ) { gd_timer_sSoftTime[i].timer_irq = GD_REG_SOFT_TIMER_IRQ; gd_timer_sSoftTime[i].timerReg = (GD_TIMER_REG_E)initParams->softTimerReg; } params.priority = initParams->softTimerpriority; params.isrFct.lowPrio = GI_TIME_ISR; ret = GD_INT_Open(¶ms, &gd_timer_sSoftTime[0].handle); if (ret != GD_OK) { return ret; } for ( i = 1; i <= GD_TIMER_MAX_SOFT_TIME; i++ ) { gd_timer_sSoftTime[i].handle = gd_timer_sSoftTime[0].handle; } /* General the soft timer Interrupt pre 10ms */ GH_TIMER_set_CntnSts(initParams->softTimerReg, (GD_GET_APB_ClkHz() / RTOS_TICK_PER_SECOND)); GH_TIMER_set_Reloadn(initParams->softTimerReg, (GD_GET_APB_ClkHz() / RTOS_TICK_PER_SECOND)); GH_TIMER_set_Match1(initParams->softTimerReg, 0x00); GH_TIMER_set_Match2(initParams->softTimerReg, 0x00); /* hard timer init */ if (initParams->hardTimerReg == GD_REG_TIMER1) params.type = GD_INT_TIMER1_IRQ; else if (initParams->hardTimerReg == GD_REG_TIMER2) params.type = GD_INT_TIMER2_IRQ; else if (initParams->hardTimerReg == GD_REG_TIMER3) params.type = GD_INT_TIMER3_IRQ; gd_timer_sHardTime.timer_irq = GD_REG_HARD_TIMER_IRQ; params.priority = initParams->hardTimerpriority; params.isrFct.lowPrio = GI_TIMER_HardTimerISR; ret = GD_INT_Open(¶ms, &gd_timer_sHardTime.handle); if (ret != GD_OK) { GD_INT_Close(&gd_timer_sSoftTime[0].handle); for ( i = 1; i <= GD_TIMER_MAX_SOFT_TIME; i++ ) { gd_timer_sSoftTime[i].handle = 0; } return ret; } gd_timer_sHardTime.timerReg = (GD_TIMER_REG_E)initParams->hardTimerReg; /* General the hard timer Interrupt pre 100ms */ GH_TIMER_set_CntnSts(initParams->hardTimerReg, (GD_GET_APB_ClkHz() / RTOS_TICK_PER_SECOND)); GH_TIMER_set_Reloadn(initParams->hardTimerReg, (GD_GET_APB_ClkHz() / RTOS_TICK_PER_SECOND)); GH_TIMER_set_Match1(initParams->hardTimerReg, 0x00); GH_TIMER_set_Match2(initParams->hardTimerReg, 0x00); /* init time stamp timer */ /* gpreg timer init */ if (initParams->gpregTimerReg == GD_REG_TIMER1) params.type = GD_INT_TIMER1_IRQ; else if (initParams->gpregTimerReg == GD_REG_TIMER2) params.type = GD_INT_TIMER2_IRQ; else if (initParams->gpregTimerReg == GD_REG_TIMER3) params.type = GD_INT_TIMER3_IRQ; gd_timer_sGpregTime.timer_irq = GD_REG_GPREG_TIMER_IRQ; params.priority = initParams->gpregTimerpriority; params.isrFct.lowPrio = GI_TIMER_GPREGTimerISR; ret = GD_INT_Open(¶ms, &gd_timer_sGpregTime.handle); if (ret != GD_OK) { GD_INT_Close(&gd_timer_sSoftTime[0].handle); for ( i = 1; i <= GD_TIMER_MAX_SOFT_TIME; i++ ) { gd_timer_sSoftTime[i].handle = 0; } GD_INT_Close(&gd_timer_sHardTime.handle); return ret; } gd_timer_sGpregTime.timerReg = (GD_TIMER_REG_E)initParams->gpregTimerReg; /*set presclaer for generating the interrupt per 100ms*/ GH_TIMER_set_CntnSts(initParams->gpregTimerReg, (GD_GET_APB_ClkHz() / RTOS_TICK_PER_SECOND)); GH_TIMER_set_Reloadn(initParams->gpregTimerReg, (GD_GET_APB_ClkHz() / RTOS_TICK_PER_SECOND)); GH_TIMER_set_Match1(initParams->gpregTimerReg, 0x00); GH_TIMER_set_Match2(initParams->gpregTimerReg, 0x00); gd_timer_TimerInitFlag = GTRUE; timer_enable(gd_timer_sSoftTime[0].timerReg, GD_INT_ENABLED); GD_INT_Enable(&gd_timer_sSoftTime[0].handle, GD_INT_ENABLED); return ret; }