static int __init base_mod_init(void) { COMM_Init(); /* init proc switch */ if(HI_SUCCESS != COMM_init_proc_ctrl()) { COMM_Exit(); return -1; } return 0; }
/** * @brief Main function * @return None */ int main(void) { COMM_Init(COMM_BAUD_RATE); // initialize communication with PC println("***********************************************"); println("Starting program"); // Print a string to terminal TIMER_Init(SYSTICK_FREQ); // Initialize timer // Add a soft timer with callback running every 1000ms int8_t timerID = TIMER_AddSoftTimer(1000, softTimerCallback); TIMER_StartSoftTimer(timerID); // start the timer LED_Init(LED0); // Add an LED LED_Init(LED1); // Add an LED LED_Init(LED2); // Add an LED LED_Init(LED3); // Add an LED LED_Init(LED5); // Add nonexising LED for test LED_ChangeState(LED5, LED_ON); KEYS_Init(); // Initialize matrix keyboard uint8_t buf[255]; // buffer for receiving commands from PC uint8_t len; // length of command // test another way of measuring time delays uint32_t softTimer = TIMER_GetTime(); // get start time for delay SD_Init(); // FAT_Init(SD_Init, SD_ReadSectors, SD_WriteSectors); // Initialize USB device stack USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb); while (1) { // test delay method if (TIMER_DelayTimer(1000, softTimer)) { LED_Toggle(LED3); softTimer = TIMER_GetTime(); // get start time for delay } // check for new frames from PC if (!COMM_GetFrame(buf, &len)) { println("Got frame of length %d: %s", (int)len, (char*)buf); // control LED0 from terminal if (!strcmp((char*)buf, ":LED0 ON")) { LED_ChangeState(LED0, LED_ON); } if (!strcmp((char*)buf, ":LED0 OFF")) { LED_ChangeState(LED0, LED_OFF); } } TIMER_SoftTimersUpdate(); // run timers key = KEYS_Update(); // run keyboard } }
/*主程序*/ void main() { u8 i = 0; /*时钟初始化*/ CLK_Config(); #ifdef _IWDG_ /* Check if the system has resumed from IWDG reset */ if (RST_GetFlagStatus(RST_FLAG_IWDGF) != RESET) { /* Clear IWDGF Flag */ RST_ClearFlag(RST_FLAG_IWDGF); } /* get measured LSI frequency */ LsiFreq = LSIMeasurment(); /* IWDG Configuration */ IWDG_Config(); #endif /*初始化电源控制*/ GPIO_DeInit(GPIOD); GPIO_Init(GPIOD,GPIO_PIN_3,GPIO_MODE_OUT_PP_LOW_FAST); GPIO_DeInit(GPIOC); GPIO_Init(GPIOC,GPIO_PIN_1,GPIO_MODE_OUT_PP_LOW_FAST); #ifdef __DEBUG__ /*底板MCU调试串口配置*/ DBG_Config(); #endif /*按键初始化*/ KEY_Init(); /*串口初始化*/ COMM_Init(); /*遥控器硬件初始化*/ IR_Init(); /*初始化CAN*/ CAN_Initialize(); /*打开全局中断*/ enableInterrupts(); /*上电,3.3V/12V*/ VDD3V3_ON(); VDD12_ON(); while (1) { /*按键检测*/ KEY_Process(); /*红外遥控器处理*/ IR_Process(); /*CAN通信处理*/ CAN_Process(); #ifdef _IWDG_ /*独立看门狗喂狗*/ IWDG_ReloadCounter(); #endif } }