LED配置
代码位于hal_board_cfg.h文件中
TI开发板有4个LED灯,P1_0 P1_1 P1_4 P0_1,都是高电平有效ACTIVE_HIGH
宏定义BV(n)函数 1<<(n) 表示1左移的位数,即寄存器置1的位数
#if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) &&
!defined (HAL_PA_LNA_CC2590) && !defined (HAL_PA_LNA_SE2431L) &&
!defined (HAL_PA_LNA_CC2592)
#define HAL_NUM_LEDS 3
#elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) ||
defined (HAL_PA_LNA_CC2590) || defined (HAL_PA_LNA_CC2592) ||
defined (HAL_PA_LNA_SE2431L)
#define HAL_NUM_LEDS 1
#else
#error Unknown Board Indentifier
#endif
#define HAL_LED_BLINK_DELAY() st( { volatile uint32 i; for (i=0; i<0x5800; i++) { }; } )
/* 1 - Green */
#define LED1_BV BV(0)
#define LED1_SBIT P1_0
#define LED1_DDR P1DIR
#define LED1_POLARITY ACTIVE_HIGH
#if defined (HAL_BOARD_CC2530EB_REV17)
/* 2 - Red */
#define LED2_BV BV(1)
#define LED2_SBIT P1_1
#define LED2_DDR P1DIR
#define LED2_POLARITY ACTIVE_HIGH
/* 3 - Yellow */
#define LED3_BV BV(4)
#define LED3_SBIT P1_4
#define LED3_DDR P1DIR
#define LED3_POLARITY ACTIVE_HIGH
#ifdef ENABLE_LED4_DISABLE_S1
/* 4 - Orange */
#define LED4_BV BV(1)
#define LED4_SBIT P0_1
#define LED4_DDR P0DIR
#define LED4_POLARITY ACTIVE_HIGH
#define LED4_SET_DIR() do {LED4_DDR |= LED4_BV;} while (0)
#else
#define LED4_SET_DIR()
#endif
#endif
LED置位位于hal_led.h中
#define HAL_LED_1 0x01
#define HAL_LED_2 0x02
#define HAL_LED_3 0x04
#define HAL_LED_4 0x08
#define HAL_LED_ALL (HAL_LED_1 | HAL_LED_2 | HAL_LED_3 | HAL_LED_4)
/* Modes */
#define HAL_LED_MODE_OFF 0x00
#define HAL_LED_MODE_ON 0x01
#define HAL_LED_MODE_BLINK 0x02
#define HAL_LED_MODE_FLASH 0x04
#define HAL_LED_MODE_TOGGLE 0x08
/* Defaults */
#define HAL_LED_DEFAULT_MAX_LEDS 4
#define HAL_LED_DEFAULT_DUTY_CYCLE 5
#define HAL_LED_DEFAULT_FLASH_COUNT 50
#define HAL_LED_DEFAULT_FLASH_TIME 1000
#LED初始化
代码位于两个位置hal_borad_cfg.h和hal_led.c
hal_borad_cfg.h中初始化方向位PxDIR,置1为输出
#define HAL_BOARD_INIT()
{
......
HAL_TURN_OFF_LED1();
LED1_DDR |= LED1_BV;
HAL_TURN_OFF_LED2();
LED2_DDR |= LED2_BV;
HAL_TURN_OFF_LED3();
LED3_DDR |= LED3_BV;
HAL_TURN_OFF_LED4();
LED4_SET_DIR();
......
}
hal_led.c中初始化LED为关状态
void HalLedInit (void)
{
#if (HAL_LED == TRUE)
/* Initialize all LEDs to OFF */
HalLedSet (HAL_LED_ALL, HAL_LED_MODE_OFF);
#endif /* HAL_LED */
#ifdef BLINK_LEDS
/* Initialize sleepActive to FALSE */
HalLedStatusControl.sleepActive = FALSE;
#endif
}
#LED驱动函数
hal_led.c文件中常用的有:
灯光模式选择函数HalLedSet(uint8 leds, uint8 mode )
灯光闪烁功能函数HalLedBlink( uint8 leds, uint8 numBlinks, uint8 percent, uint16 period)
还有:
用于blink的LED更新函数HalLedUpdate (void)
LED开关控制函数HalLedOnOff (uint8 leds, uint8 mode)
LED状态获取函数HalLedGetState ()
休眠前存储当前LED状态函数HalLedEnterSleep( void )
休眠后恢复LED状态函数HalLedExitSleep( void )
灯光模式选择函数HalLedSet()中mode的选择控制:
/***************************************************************************************************
* @fn HalLedSet
*
* @brief Tun ON/OFF/TOGGLE given LEDs
*
* @param led - bit mask value of leds to be turned ON/OFF/TOGGLE
* mode - BLINK, FLASH, TOGGLE, ON, OFF
* @return None
***************************************************************************************************/
uint8 HalLedSet (uint8 leds, uint8 mode)
{
#if (defined (BLINK_LEDS)) && (HAL_LED == TRUE)
uint8 led;
HalLedControl_t *sts;
switch (mode)
{
case HAL_LED_MODE_BLINK:
/* Default blink, 1 time, D% duty cycle */
HalLedBlink (leds, 1, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME);
break;
case HAL_LED_MODE_FLASH:
/* Default flash, N times, D% duty cycle */
HalLedBlink (leds, HAL_LED_DEFAULT_FLASH_COUNT, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME);
break;
case HAL_LED_MODE_ON:
case HAL_LED_MODE_OFF:
case HAL_LED_MODE_TOGGLE:
led = HAL_LED_1;
leds &= HAL_LED_ALL;
sts = HalLedStatusControl.HalLedControlTable;
while (leds)
{
if (leds & led)
{
if (mode != HAL_LED_MODE_TOGGLE)
{
sts->mode = mode; /* ON or OFF */
}
else
{
sts->mode ^= HAL_LED_MODE_ON; /* Toggle */
}
HalLedOnOff (led, sts->mode);
leds ^= led;
}
led <<= 1;
sts++;
}
break;
default:
break;
}
#elif (HAL_LED == TRUE)
LedOnOff(leds, mode);
#else
// HAL LED is disabled, suppress unused argument warnings
(void) leds;
(void) mode;
#endif /* BLINK_LEDS && HAL_LED */
return ( HalLedState );
}
灯光闪烁函数HalLedBlink()
/***************************************************************************************************
* @fn HalLedBlink
*
* @brief Blink the leds
*
* @param leds - bit mask value of leds to be blinked
* numBlinks - number of blinks
* percent - the percentage in each period where the led
* will be on
* period - length of each cycle in milliseconds
*
* @return None
***************************************************************************************************/
void HalLedBlink (uint8 leds, uint8 numBlinks, uint8 percent, uint16 period)
{
#if (defined (BLINK_LEDS)) && (HAL_LED == TRUE)
uint8 led;
HalLedControl_t *sts;
if (leds && percent && period)
{
if (percent < 100)
{
led = HAL_LED_1;
leds &= HAL_LED_ALL;
sts = HalLedStatusControl.HalLedControlTable;
while (leds)
{
if (leds & led)
{
/* Store the current state of the led before going to blinking if not already blinking */
if(sts->mode < HAL_LED_MODE_BLINK )
preBlinkState |= (led & HalLedState);
sts->mode = HAL_LED_MODE_OFF; /* Stop previous blink */
sts->time = period; /* Time for one on/off cycle */
sts->onPct = percent; /* % of cycle LED is on */
sts->todo = numBlinks; /* Number of blink cycles */
if (!numBlinks) sts->mode |= HAL_LED_MODE_FLASH; /* Continuous */
sts->next = osal_GetSystemClock(); /* Start now */
sts->mode |= HAL_LED_MODE_BLINK; /* Enable blinking */
leds ^= led;
}
led <<= 1;
sts++;
}
// Cancel any overlapping timer for blink events
osal_stop_timerEx(Hal_TaskID, HAL_LED_BLINK_EVENT);
osal_set_event (Hal_TaskID, HAL_LED_BLINK_EVENT);
}
else
{
HalLedSet (leds, HAL_LED_MODE_ON); /* >= 100%, turn on */
}
}
else
{
HalLedSet (leds, HAL_LED_MODE_OFF); /* No on time, turn off */
}
#elif (HAL_LED == TRUE)
percent = (leds & HalLedState) ? HAL_LED_MODE_OFF : HAL_LED_MODE_ON;
HalLedOnOff (leds, percent); /* Toggle */
#else
// HAL LED is disabled, suppress unused argument warnings
(void) leds;
(void) numBlinks;
(void) percent;
(void) period;
#endif /* BLINK_LEDS && HAL_LED */
}
LED配置
代码位于hal_board_cfg.h文件中
TI开发板有4个LED灯,P1_0 P1_1 P1_4 P0_1,都是高电平有效ACTIVE_HIGH
宏定义BV(n)函数 1<<(n) 表示1左移的位数,即寄存器置1的位数
#if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) &&
!defined (HAL_PA_LNA_CC2590) && !defined (HAL_PA_LNA_SE2431L) &&
!defined (HAL_PA_LNA_CC2592)
#define HAL_NUM_LEDS 3
#elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) ||
defined (HAL_PA_LNA_CC2590) || defined (HAL_PA_LNA_CC2592) ||
defined (HAL_PA_LNA_SE2431L)
#define HAL_NUM_LEDS 1
#else
#error Unknown Board Indentifier
#endif
#define HAL_LED_BLINK_DELAY() st( { volatile uint32 i; for (i=0; i<0x5800; i++) { }; } )
/* 1 - Green */
#define LED1_BV BV(0)
#define LED1_SBIT P1_0
#define LED1_DDR P1DIR
#define LED1_POLARITY ACTIVE_HIGH
#if defined (HAL_BOARD_CC2530EB_REV17)
/* 2 - Red */
#define LED2_BV BV(1)
#define LED2_SBIT P1_1
#define LED2_DDR P1DIR
#define LED2_POLARITY ACTIVE_HIGH
/* 3 - Yellow */
#define LED3_BV BV(4)
#define LED3_SBIT P1_4
#define LED3_DDR P1DIR
#define LED3_POLARITY ACTIVE_HIGH
#ifdef ENABLE_LED4_DISABLE_S1
/* 4 - Orange */
#define LED4_BV BV(1)
#define LED4_SBIT P0_1
#define LED4_DDR P0DIR
#define LED4_POLARITY ACTIVE_HIGH
#define LED4_SET_DIR() do {LED4_DDR |= LED4_BV;} while (0)
#else
#define LED4_SET_DIR()
#endif
#endif
LED置位位于hal_led.h中
#define HAL_LED_1 0x01
#define HAL_LED_2 0x02
#define HAL_LED_3 0x04
#define HAL_LED_4 0x08
#define HAL_LED_ALL (HAL_LED_1 | HAL_LED_2 | HAL_LED_3 | HAL_LED_4)
/* Modes */
#define HAL_LED_MODE_OFF 0x00
#define HAL_LED_MODE_ON 0x01
#define HAL_LED_MODE_BLINK 0x02
#define HAL_LED_MODE_FLASH 0x04
#define HAL_LED_MODE_TOGGLE 0x08
/* Defaults */
#define HAL_LED_DEFAULT_MAX_LEDS 4
#define HAL_LED_DEFAULT_DUTY_CYCLE 5
#define HAL_LED_DEFAULT_FLASH_COUNT 50
#define HAL_LED_DEFAULT_FLASH_TIME 1000
#LED初始化
代码位于两个位置hal_borad_cfg.h和hal_led.c
hal_borad_cfg.h中初始化方向位PxDIR,置1为输出
#define HAL_BOARD_INIT()
{
......
HAL_TURN_OFF_LED1();
LED1_DDR |= LED1_BV;
HAL_TURN_OFF_LED2();
LED2_DDR |= LED2_BV;
HAL_TURN_OFF_LED3();
LED3_DDR |= LED3_BV;
HAL_TURN_OFF_LED4();
LED4_SET_DIR();
......
}
hal_led.c中初始化LED为关状态
void HalLedInit (void)
{
#if (HAL_LED == TRUE)
/* Initialize all LEDs to OFF */
HalLedSet (HAL_LED_ALL, HAL_LED_MODE_OFF);
#endif /* HAL_LED */
#ifdef BLINK_LEDS
/* Initialize sleepActive to FALSE */
HalLedStatusControl.sleepActive = FALSE;
#endif
}
#LED驱动函数
hal_led.c文件中常用的有:
灯光模式选择函数HalLedSet(uint8 leds, uint8 mode )
灯光闪烁功能函数HalLedBlink( uint8 leds, uint8 numBlinks, uint8 percent, uint16 period)
还有:
用于blink的LED更新函数HalLedUpdate (void)
LED开关控制函数HalLedOnOff (uint8 leds, uint8 mode)
LED状态获取函数HalLedGetState ()
休眠前存储当前LED状态函数HalLedEnterSleep( void )
休眠后恢复LED状态函数HalLedExitSleep( void )
灯光模式选择函数HalLedSet()中mode的选择控制:
/***************************************************************************************************
* @fn HalLedSet
*
* @brief Tun ON/OFF/TOGGLE given LEDs
*
* @param led - bit mask value of leds to be turned ON/OFF/TOGGLE
* mode - BLINK, FLASH, TOGGLE, ON, OFF
* @return None
***************************************************************************************************/
uint8 HalLedSet (uint8 leds, uint8 mode)
{
#if (defined (BLINK_LEDS)) && (HAL_LED == TRUE)
uint8 led;
HalLedControl_t *sts;
switch (mode)
{
case HAL_LED_MODE_BLINK:
/* Default blink, 1 time, D% duty cycle */
HalLedBlink (leds, 1, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME);
break;
case HAL_LED_MODE_FLASH:
/* Default flash, N times, D% duty cycle */
HalLedBlink (leds, HAL_LED_DEFAULT_FLASH_COUNT, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME);
break;
case HAL_LED_MODE_ON:
case HAL_LED_MODE_OFF:
case HAL_LED_MODE_TOGGLE:
led = HAL_LED_1;
leds &= HAL_LED_ALL;
sts = HalLedStatusControl.HalLedControlTable;
while (leds)
{
if (leds & led)
{
if (mode != HAL_LED_MODE_TOGGLE)
{
sts->mode = mode; /* ON or OFF */
}
else
{
sts->mode ^= HAL_LED_MODE_ON; /* Toggle */
}
HalLedOnOff (led, sts->mode);
leds ^= led;
}
led <<= 1;
sts++;
}
break;
default:
break;
}
#elif (HAL_LED == TRUE)
LedOnOff(leds, mode);
#else
// HAL LED is disabled, suppress unused argument warnings
(void) leds;
(void) mode;
#endif /* BLINK_LEDS && HAL_LED */
return ( HalLedState );
}
灯光闪烁函数HalLedBlink()
/***************************************************************************************************
* @fn HalLedBlink
*
* @brief Blink the leds
*
* @param leds - bit mask value of leds to be blinked
* numBlinks - number of blinks
* percent - the percentage in each period where the led
* will be on
* period - length of each cycle in milliseconds
*
* @return None
***************************************************************************************************/
void HalLedBlink (uint8 leds, uint8 numBlinks, uint8 percent, uint16 period)
{
#if (defined (BLINK_LEDS)) && (HAL_LED == TRUE)
uint8 led;
HalLedControl_t *sts;
if (leds && percent && period)
{
if (percent < 100)
{
led = HAL_LED_1;
leds &= HAL_LED_ALL;
sts = HalLedStatusControl.HalLedControlTable;
while (leds)
{
if (leds & led)
{
/* Store the current state of the led before going to blinking if not already blinking */
if(sts->mode < HAL_LED_MODE_BLINK )
preBlinkState |= (led & HalLedState);
sts->mode = HAL_LED_MODE_OFF; /* Stop previous blink */
sts->time = period; /* Time for one on/off cycle */
sts->onPct = percent; /* % of cycle LED is on */
sts->todo = numBlinks; /* Number of blink cycles */
if (!numBlinks) sts->mode |= HAL_LED_MODE_FLASH; /* Continuous */
sts->next = osal_GetSystemClock(); /* Start now */
sts->mode |= HAL_LED_MODE_BLINK; /* Enable blinking */
leds ^= led;
}
led <<= 1;
sts++;
}
// Cancel any overlapping timer for blink events
osal_stop_timerEx(Hal_TaskID, HAL_LED_BLINK_EVENT);
osal_set_event (Hal_TaskID, HAL_LED_BLINK_EVENT);
}
else
{
HalLedSet (leds, HAL_LED_MODE_ON); /* >= 100%, turn on */
}
}
else
{
HalLedSet (leds, HAL_LED_MODE_OFF); /* No on time, turn off */
}
#elif (HAL_LED == TRUE)
percent = (leds & HalLedState) ? HAL_LED_MODE_OFF : HAL_LED_MODE_ON;
HalLedOnOff (leds, percent); /* Toggle */
#else
// HAL LED is disabled, suppress unused argument warnings
(void) leds;
(void) numBlinks;
(void) percent;
(void) period;
#endif /* BLINK_LEDS && HAL_LED */
}
举报