void gtimer_init (gtimer_t *obj, uint32_t tid) { PTIMER_ADAPTER pTimerAdapter = &(obj->hal_gtimer_adp); if ((tid == 1) || (tid == 6) || (tid == 7)) { DBG_TIMER_ERR("gtimer_init: This timer is reserved for HAL driver\r\n", tid); return; } if (tid > GTIMER_MAX) { DBG_TIMER_ERR("gtimer_init: Invalid TimerId=%d\r\n", tid); return; } pTimerAdapter->IrqDis = 0; // Enable Irq @ initial pTimerAdapter->IrqHandle.IrqFun = (IRQ_FUN) gtimer_timeout_handler; if(tid == 0) { pTimerAdapter->IrqHandle.IrqNum = TIMER0_IRQ; } else if(tid == 1) { pTimerAdapter->IrqHandle.IrqNum = TIMER1_IRQ; } else { pTimerAdapter->IrqHandle.IrqNum = TIMER2_7_IRQ; } pTimerAdapter->IrqHandle.Priority = 0; pTimerAdapter->IrqHandle.Data = (u32)obj; pTimerAdapter->TimerId = (u8)tid; pTimerAdapter->TimerIrqPriority = 0; pTimerAdapter->TimerLoadValueUs = 0xFFFFFFFF; // Just a whatever value pTimerAdapter->TimerMode = USER_DEFINED; HalTimerInit ((VOID*) pTimerAdapter); }
static void initTimer3() { if (isInitTimer3 == 0) { GPIO_LedsInit(); HalTimerInit(); HalTimerConfig(HAL_TIMER_0, HAL_TIMER_MODE_CTC, HAL_TIMER_CHANNEL_SINGLE, HAL_TIMER_CH_MODE_OUTPUT_COMPARE, TRUE, showsomething); isInitTimer3 = 1; } count = 0; flag = 0; IRLED = 0; }
void main ( void ) { uint8_t monitorState; static uint8_t oldMute = 0x00; BOOL externalAccess; uint8_t u8Data, rotarySwitch; externalAccess = false; oldMute = true; HalInitialize(); HalTimerInit(); HalUartInit(); HalTimerWait(100); GPIOC->DDR |= 0x30; GPIOC->CR1 |= 0x30; GPIOC->ODR |= 0x30; /* Perform a hard reset on the device to ensure that it is in a known */ /* state (also downloads a fresh copy of EDID from NVRAM). */ DEBUG_PRINT(MSG_ALWAYS,("\nPower up Initialize...")); u8Data = SI_DevicePowerUpBoot(0); if ( u8Data <= 0x02 ) { DEBUG_PRINT( MSG_ALWAYS, ( "0 FAILED - " )); } DEBUG_PRINT(MSG_ALWAYS,("\n0 Base Address: %02X BSM Status: %02X\n", (int)u8Data, (int)SiIRegioRead(0, REG_BSM_STAT ))); /*u8Data = SI_DevicePowerUpBoot(1); if ( u8Data <= 0x02 ) { DEBUG_PRINT( MSG_ALWAYS, ( "1 FAILED - " )); } DEBUG_PRINT(MSG_ALWAYS,("\n1 Base Address: %02X BSM Status: %02X\n", (int)u8Data, (int)SiIRegioRead(1, REG_BSM_STAT ))); */ CpDisplayChipInfo(0); //CpDisplayChipInfo(1); //HalTimerSet( TIMER_POLLING, DEM_POLLING_DELAY ); while ( 1 ) { HalTimerWait(100); process(0); // process(1); } }
/** * @brief Initialize the HAL layer module. * *****************************************************************************/ halReturn_t HalInit(void) { halReturn_t status; if (gHalInitedFlag) { SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE, "Error: Hal layer already inited!\n"); return HAL_RET_ALREADY_INITIALIZED; } gMhlDevice.driver.driver.name = NULL; gMhlDevice.driver.id_table = NULL; gMhlDevice.driver.probe = NULL; gMhlDevice.driver.remove = NULL; gMhlDevice.pI2cClient = NULL; gMhlDevice.irqHandler = NULL; #ifdef CONFIG_SII8334_MHL_TX sema_init(&gIsrLock, 1); #else /* CONFIG_SII8334_MHL_TX */ // sema_init(&gIsrLock, 1); init_MUTEX(&gIsrLock); #endif /* CONFIG_SII8334_MHL_TX */ HalTimerInit(); status = HalGpioInit(); if(status != HAL_RET_SUCCESS) { return status; } gHalInitedFlag = true; return HAL_RET_SUCCESS; }
/********************************************************************* * @fn SampleApp_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void SampleApp_Init( uint8 task_id ) { SampleApp_TaskID = task_id; SampleApp_NwkState = DEV_INIT; SampleApp_TransID = 0; MT_UartInit();//串口初始化 MT_UartRegisterTaskID(task_id);//登记任务号 #ifdef MODE_ED //终端节点下才配置 /**************超声波***************/ #define trig P0_1 #define echo P0_0 P0DIR |= 0x02; //P01输出trig P0DIR &= ~0x01; //P00输入echo trig=0; /*定时器配置*/ HalTimerInit(); HalTimerConfig(HAL_TIMER_0, HAL_TIMER_MODE_CTC, HAL_TIMER_CHANNEL_SINGLE, HAL_TIMER_CH_MODE_OUTPUT_COMPARE, TRUE, timer_callback); /***********步进电机**************/ #define in1 P0_4 #define in2 P0_5 #define in3 P0_6 #define in4 P0_7 P0SEL &=~0xf0; P0DIR |= 0xf0; P0INP &=~0Xf0; //打开上拉 in1=0; in2=0; in3=0; in4=0; /*测试*/ int i=0; for(i=0;i<128;i++) { MotorCW(); } for(i=0;i<128;i++) { MotorCCW(); } HalLedBlink( HAL_LED_2, 2,50, 500); #endif // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). #if defined ( BUILD_ALL_DEVICES ) // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJumper() ) zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER; #endif // BUILD_ALL_DEVICES #if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif // Setup for the periodic message's destination address // Broadcast to everyone SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; // Setup for the flash command's destination address - Group 1 SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup; SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP; // 网蜂点对点通讯定义 Point_To_Point_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;//点播 Point_To_Point_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; Point_To_Point_DstAddr.addr.shortAddr = 0x0000; //发给协调器 // Fill out the endpoint description. SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_epDesc.task_id = &SampleApp_TaskID; SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc; SampleApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &SampleApp_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( SampleApp_TaskID ); // By default, all devices start out in Group 1 SampleApp_Group.ID = 0x0001; osal_memcpy( SampleApp_Group.name, "Group 1", 7 ); aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group ); #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "SmartPark", HAL_LCD_LINE_1 ); #endif }
/************************************************************************************************** * @fn Hal_DriverInit (ªì©l¤ÆµwÅ骺ÅX°Êµ{§Ç, ¨Ï¥ÎªÌ¥i¦b¦¹¨ç¼Æ²K¥[¬ÛÃöµwÅé) * * @brief Initialize HW - These need to be initialized before anyone. * * @param task_id - Hal TaskId * * @return None **************************************************************************************************/ void HalDriverInit (void) { /* TIMER */ #if (defined HAL_TIMER) && (HAL_TIMER == TRUE) HalTimerInit(); #endif /* ADC */ #if (defined HAL_ADC) && (HAL_ADC == TRUE) HalAdcInit(); #if defined(M170) M170_Init(); #endif #endif /* DMA */ #if (defined HAL_DMA) && (HAL_DMA == TRUE) // Must be called before the init call to any module that uses DMA. HalDmaInit(); #endif /* Flash */ #if (defined HAL_FLASH) && (HAL_FLASH == TRUE) // Must be called before the init call to any module that uses Flash access or NV. HalFlashInit(); #endif /* AES */ #if (defined HAL_AES) && (HAL_AES == TRUE) HalAesInit(); #endif /* LCD */ #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdInit(); #endif /* UART */ #if (defined HAL_UART) && (HAL_UART == TRUE) HalUARTInit(); #endif /* KEY */ #if (defined HAL_KEY) && (HAL_KEY == TRUE) HalKeyInit(); #endif /* SPI */ #if (defined HAL_SPI) && (HAL_SPI == TRUE) HalSpiInit(); #endif /* HID */ #if (defined HAL_HID) && (HAL_HID == TRUE) usbHidInit(); #endif /* KEYPAD */ #if (defined HAL_KEYPAD) && (HAL_KEYPAD == TRUE) halKeypadInit(); #endif /* BUZZER */ #if (defined HAL_BUZZER) && (HAL_BUZZER == TRUE) halBuzzerInit(); #endif /* I2C (M200 module) */ #if (defined HAL_I2C) && (HAL_I2C == TRUE) #if defined(M200) M200_Init(); #endif #endif /* LED */ #if (defined HAL_LED) && (HAL_LED == TRUE) HalLedInit(); #endif }