* @fn main
* @brief First function called after startup.
* @return don't care
*/
int main( void )
{
// Turn off interrupts
osal_int_disable( INTS_ALL );
// Initialization for board related stuff such as LEDs 初始化板子固有外设
HAL_BOARD_INIT();
// Make sure supply voltage is high enough to run ad检测电源电压
zmain_vdd_check();
// Initialize board I/O 初始化外设io 不太明白
InitBoard( OB_COLD );
// Initialze HAL drivers
HalDriverInit();
// Initialize NV System
osal_nv_init( NULL );
// Initialize the MAC
ZMacInit();
// Determine the extended address
zmain_ext_addr();
#if defined ZCL_KEY_ESTABLISH
// Initialize the Certicom certificate information.
zmain_cert_init();
#endif
// Initialize basic NV items
zgInit();
#ifndef NONWK
// Since the AF isn't a task, call it's initialization routine
afInit();
#endif
// Initialize the operating system
osal_init_system();
// Allow interrupts
osal_int_enable( INTS_ALL );
// Final board initialization
InitBoard( OB_READY );
// Display information about this device
zmain_dev_info();
/* Display the device info on the LCD */
#ifdef LCD_SUPPORTED
zmain_lcd_init();
#endif
#ifdef WDT_IN_PM1
/* If WDT is used, this is a good place to enable it. */
WatchDogEnable( WDTIMX );
#endif
osal_start_system(); // No Return from here
return 0; // Shouldn't get here.
} // main()
第一步:关中断
函数本体
uint8 osal_int_disable( uint8 interrupt_id )
{
if ( interrupt_id == INTS_ALL )
{
HAL_DISABLE_INTERRUPTS(); //EA = 0 关全局中断
return ( SUCCESS ); //0x00
}
else
{
return ( INVALID_INTERRUPT_ID ); // 0x07
}
}
第二步:初始化板子相关外设
根据预编译来选择两个初始化中的一个
/* ----------- Board Initialization ---------- */
#if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) && !defined (HAL_PA_LNA_CC2590)
#define HAL_BOARD_INIT() \
{ \
uint16 i; \
\ /* 初始化时钟(CC2530datasheet中没有说明 )参考cc2430 */
SLEEPCMD &= ~OSC_PD; /* turn on 16MHz RC and 32MHz XOSC */ \
while (!(SLEEPSTA & XOSC_STB)); /* wait for 32MHz XOSC stable */ \
asm("NOP"); /* chip bug workaround */ \
for (i=0; i<504; i++) asm("NOP"); /* Require 63us delay for all revs */ \
CLKCONCMD = (CLKCONCMD_32MHZ | OSC_32KHZ); /* Select 32MHz XOSC and the source for 32K clock */\
while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ));/* Wait for the change to be effective */ \
SLEEPCMD |= OSC_PD; /* turn off 16MHz RC */ \
\
/* Turn on cache prefetch mode */ \
PREFETCH_ENABLE(); \
\
HAL_TURN_OFF_LED1(); \
LED1_DDR |= LED1_BV; \
HAL_TURN_OFF_LED2(); \
LED2_DDR |= LED2_BV; \
HAL_TURN_OFF_LED3(); \
LED3_DDR |= LED3_BV; \
\
/* configure tristates */ \
P0INP |= PUSH2_BV; \
}
#elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) || defined (HAL_PA_LNA_CC2590)
#define HAL_BOARD_INIT() \
{ \
uint16 i; \
\
SLEEPCMD &= ~OSC_PD; /* turn on 16MHz RC and 32MHz XOSC */ \
while (!(SLEEPSTA & XOSC_STB)); /* wait for 32MHz XOSC stable */ \
asm("NOP"); /* chip bug workaround */ \
for (i=0; i<504; i++) asm("NOP"); /* Require 63us delay for all revs */ \
CLKCONCMD = (CLKCONCMD_32MHZ | OSC_32KHZ); /* Select 32MHz XOSC and the source for 32K clock */ \
while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); /* Wait for the change to be effective */ \
SLEEPCMD |= OSC_PD; /* turn off 16MHz RC */ \
\
/* Turn on cache prefetch mode */ \
PREFETCH_ENABLE(); \
\
/* set direction for GPIO outputs */ \
LED1_DDR |= LED1_BV; \
\
/* Set PA/LNA HGM control P0_7 */ \
P0DIR |= BV(7); \
\
/* configure tristates */ \
P0INP |= PUSH2_BV; \
\
/* setup RF frontend if necessary */ \
HAL_BOARD_RF_FRONTEND_SETUP(); \
}
#endif
①CC2530数据手册对SLEEPCMD的说明不够,这里看CC2430的
(对SLEEPCMD &= ~OSC_PD;等几句的功能存在疑惑 )
②PREFETCH_ENABLE(); 写或擦除操作激活
/* ----------- Cache Prefetch control ---------- */
#define PREFETCH_ENABLE() st( = 0x08; )
#define PREFETCH_DISABLE() st( FCTL = 0x04; )
③对io口连接的led的配置:略
④配置对pa/lna放大器的控制口p0_7 (两段代码区别所在)
函数HAL_BOARD_RF_FRONTEND_SETUP();暂不分析