硬件环境:SLANRF-2530DK
编辑器:IAR7.51A
主机环境:windows XP
*********************************************************************
很多人在研究ZigBee,小弟最近刚加入这一行列,写下一些东西方便自己学习,网上也有很多资料,慢慢学吧就……
之前看了一些cc2530自带的基础例程,基本上是51例程没有涉及到无线部分,不得不说他的51核心的确是增强版,文档里面寄存器神马的都是一大坨,头都大了。不管怎么说还是先熟悉下他的环境,用到了再去看吧。先看例子程序吧,这里我打开的是GenericApp例程,关于左侧目录的构成这里就不多说了,文档里面都有很多的。
进入主函数里面,
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
zmain_vdd_check();
// Initialize stack memory
zmain_ram_init();
// Initialize board I/O
InitBoard( OB_COLD );
// Initialze HAL drivers
HalDriverInit();
// Initialize NV System
osal_nv_init( NULL );
// Initialize basic NV items
zgInit();
// Initialize the MAC
ZMacInit();
// Determine the extended address
zmain_ext_addr();
#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 ); //sd rest
// 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
// Shouldn't get here
return ( 0 );
} // main()
均是一些初始化操作,完了之后进入到osal_start_system()里面去了,感觉有点像uCOS,鸭梨山大那,一步步看吧
关于第一句osal_int_disable(INTS_ALL)这个没啥说的看名字就知道了,点击进入源码查看
uint8 osal_int_disable( uint8 interrupt_id )
{
if ( interrupt_id == INTS_ALL )
{
HAL_DISABLE_INTERRUPTS();
}
else
return ( INVALID_INTERRUPT_ID );
return ( SUCCESS );
}
继续查看
#define HAL_DISABLE_INTERRUPTS() st( EA = 0; )
感觉看到本质了,EA=0,继续
#define st(x) do { x } while (__LINE__ == -1)
这下就清除了,这个__LINE__在网上看了下,说是被编译成当前行号,不晓得为啥要这么写,感觉用0代替更方便些,经过句代码的查看就可以发现这里面的宏定义实在是太多了,灰常简单的一句关中断就用了三层。真是严谨的态度。