自学笔记①Zmain.c中主函数main:一

/*********************************************************************
 * @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();暂不分析      



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值