1 int main( void ) 2 { 3 // Turn off interrupts 4 osal_int_disable( INTS_ALL ); 5 6 // Initialization for board related stuff such as LEDs 7 HAL_BOARD_INIT(); 8 9 // Make sure supply voltage is high enough to run 10 zmain_vdd_check(); 11 12 // Initialize board I/O 13 InitBoard( OB_COLD ); 14 15 // Initialze HAL drivers 16 HalDriverInit(); 17 18 // Initialize NV System 19 osal_nv_init( NULL ); 20 21 // Initialize the MAC 22 ZMacInit(); 23 24 // Determine the extended address 25 zmain_ext_addr(); 26 27 #if defined ZCL_KEY_ESTABLISH 28 // Initialize the Certicom certificate information. 29 zmain_cert_init(); 30 #endif 31 32 // Initialize basic NV items 33 zgInit(); 34 35 #ifndef NONWK 36 // Since the AF isn‘t a task, call it‘s initialization routine 37 afInit(); 38 #endif 39 40 // Initialize the operating system 41 osal_init_system(); 42 43 // Allow interrupts 44 osal_int_enable( INTS_ALL ); 45 46 // Final board initialization 47 InitBoard( OB_READY ); 48 49 // Display information about this device 50 zmain_dev_info(); 51 52 /* Display the device info on the LCD */ 53 #ifdef LCD_SUPPORTED 54 zmain_lcd_init(); 55 #endif 56 57 #ifdef WDT_IN_PM1 58 /* If WDT is used, this is a good place to enable it. */ 59 WatchDogEnable( WDTIMX ); 60 #endif 61 62 osal_start_system(); // No Return from here 63 64 return 0; // Shouldn‘t get here. 65 } // main()
HAL_BOARD_INIT()关于LED灯的板级初始化
1 #define HAL_BOARD_INIT() 2 { 3 uint16 i; 4 5 SLEEPCMD &= ~OSC_PD; /* turn on 16MHz RC and 32MHz XOSC */ 6 while (!(SLEEPSTA & XOSC_STB)); /* wait for 32MHz XOSC stable */ 7 asm("NOP"); /* chip bug workaround */ 8 for (i=0; i<504; i++) asm("NOP"); /* Require 63us delay for all revs */ 9 CLKCONCMD = (CLKCONCMD_32MHZ | OSC_32KHZ); /* Select 32MHz XOSC and the source for 32K clock */ 10 while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); /* Wait for the change to be effective */ 11 SLEEPCMD |= OSC_PD; /* turn off 16MHz RC */ 12 13 /* Turn on cache prefetch mode */ 14 PREFETCH_ENABLE(); 15 16 HAL_TURN_OFF_LED1(); 17 LED1_DDR |= LED1_BV; 18 HAL_TURN_OFF_LED2(); 19 LED2_DDR |= LED2_BV; 20 HAL_TURN_OFF_LED3(); 21 LED3_DDR |= LED3_BV; 22 23 /* configure tristates */ 24 P0INP |= PUSH2_BV; 25 }
程序解读:16~21行代码,定义了三个LED灯的IO口,分别为P1_0、P1_1、P1_4。第24行代码,定义P0_0为三态
HalDriverInit()初始化硬件层各驱动
1 void HalDriverInit (void) 2 { 3 /* TIMER */ 4 #if (defined HAL_TIMER) && (HAL_TIMER == TRUE) 5 #error "The hal timer driver module is removed." 6 #endif 7 8 /* ADC */ 9 #if (defined HAL_ADC) && (HAL_ADC == TRUE) 10 HalAdcInit(); 11 #endif 12 13 /* DMA */ 14 #if (defined HAL_DMA) && (HAL_DMA == TRUE) 15 // Must be called before the init call to any module that uses DMA. 16 HalDmaInit(); 17 #endif 18 19 /* AES */ 20 #if (defined HAL_AES) && (HAL_AES == TRUE) 21 HalAesInit(); 22 #endif 23 24 /* LCD */ 25 #if (defined HAL_LCD) && (HAL_LCD == TRUE) 26 HalLcdInit(); 27 #endif 28 29 /* LED */ 30 #if (defined HAL_LED) && (HAL_LED == TRUE) 31 HalLedInit(); 32 #endif 33 34 /* UART */ 35 #if (defined HAL_UART) && (HAL_UART == TRUE) 36 HalUARTInit(); 37 #endif 38 39 /* KEY */ 40 #if (defined HAL_KEY) && (HAL_KEY == TRUE) 41 HalKeyInit(); 42 #endif 43 44 /* SPI */ 45 #if (defined HAL_SPI) && (HAL_SPI == TRUE) 46 HalSpiInit(); 47 #endif 48 49 /* HID */ 50 #if (defined HAL_HID) && (HAL_HID == TRUE) 51 usbHidInit(); 52 #endif 53 }
程序解析:以上程序分别进行了,
时间: 2024-10-11 08:00:11