📄 bsp.c
字号:
/*
*********************************************************************************************************
* TIMER #0 IRQ HANDLER
*
* Description : This function handles the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Arguments : None.
*********************************************************************************************************
*/
static void Tmr_TickHandler (void)
{
CPU_INT32U reg_val;
reg_val = *AT91C_ST_SR;
if (reg_val & AT91C_ST_PITS) { /* If the interrupt is from the tick source, call */
OSTimeTick(); /* OSTimeTick(). */
}
#if APP_VIEW_EN
#if 0 /* WIP */
OSView_RxTxISRHandler();
#endif
#endif
}
/*
*********************************************************************************************************
* LED INITIALIZATION
*
* Description : This function should be called by your application code before you make use of any of the
* functions found in this module.
*
* Arguments : None.
*********************************************************************************************************
*/
void LED_Init (void)
{
LED_On(0); /* Turn ON all the LEDs. */
}
/*
*********************************************************************************************************
* LED OFF
*
* Description : This function is used to control any or all the LEDs on the board.
*
* Arguments : led is the number of the LED to turn OFF
* 0 indicates that you want ALL the LEDs to be OFF
* 1 turns OFF User LED0 on the board
* .
* .
* 3 turns OFF User LED2 on the board
*********************************************************************************************************
*/
void LED_Off (CPU_INT08U led)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
CPU_SR cpu_sr;
#endif
CPU_CRITICAL_ENTER();
switch (led) {
case 0:
BSP_CSB_ARM_LED_RegImage &= ~DEF_BIT_02;
break;
case 1:
BSP_CSB_ARM_LED_RegImage &= ~DEF_BIT_02;
break;
}
*AT91C_PIOB_SODR = BSP_CSB_ARM_LED_RegImage & DEF_BIT_02;
*AT91C_PIOB_CODR = ~BSP_CSB_ARM_LED_RegImage & DEF_BIT_02;
CPU_CRITICAL_EXIT();
}
/*
*********************************************************************************************************
* LED ON
*
* Description : This function is used to control any or all the LEDs on the board.
*
* Arguments : led is the number of the LED to control
* 0 indicates that you want ALL the LEDs to be ON
* 1 turns ON User LED 0 on the board
* .
* .
* 3 turns ON User LED 2 on the board
*********************************************************************************************************
*/
void LED_On (CPU_INT08U led)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
CPU_SR cpu_sr;
#endif
CPU_CRITICAL_ENTER();
switch (led) {
case 0:
BSP_CSB_ARM_LED_RegImage |= DEF_BIT_02;
break;
case 1:
BSP_CSB_ARM_LED_RegImage |= DEF_BIT_02;
break;
}
*AT91C_PIOB_SODR = BSP_CSB_ARM_LED_RegImage & DEF_BIT_02;
*AT91C_PIOB_CODR = ~BSP_CSB_ARM_LED_RegImage & DEF_BIT_02;
CPU_CRITICAL_EXIT();
}
/*
*********************************************************************************************************
* LED TOGGLE
*
* Description : This function is used to alternate the state of any LED.
*
* Arguments : led is the number of the LED to control
* 0 indicates that you want ALL the LEDs to toggle
* 1 toggle User LED 0 on the board
* .
* .
* 3 toggle User LED 2 on the board
*********************************************************************************************************
*/
void LED_Toggle (CPU_INT08U led)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
CPU_SR cpu_sr;
#endif
CPU_CRITICAL_ENTER();
switch (led) {
case 0:
BSP_CSB_ARM_LED_RegImage ^= DEF_BIT_02;
break;
case 1:
BSP_CSB_ARM_LED_RegImage ^= DEF_BIT_02;
break;
}
*AT91C_PIOB_SODR = BSP_CSB_ARM_LED_RegImage & DEF_BIT_02;
*AT91C_PIOB_CODR = ~BSP_CSB_ARM_LED_RegImage & DEF_BIT_02;
CPU_CRITICAL_EXIT();
}
/*
*********************************************************************************************************
* GET 'PUSH BUTTON' STATUS
*
* Description : This function is used to get the status of any push button on the board.
*
* Arguments : push_button is the number of the push button to probe
* 1 probe the push button 0
* .
* .
* 3 probe the push button 2
*********************************************************************************************************
*/
CPU_BOOLEAN PB_GetStatus (CPU_INT08U push_button)
{
CPU_BOOLEAN status;
switch (push_button) {
case 1:
status = ((*AT91C_PIOB_PDSR & DEF_BIT_29) == 0);
break;
default:
status = DEF_OFF;
break;
}
return (status);
}
/*
*********************************************************************************************************
* SERIAL READ
*
* Description : Read a string from serial port until end-of-line.
*
* Arguments : string pre-allocated string to write to.
* len maximum len of string.
*********************************************************************************************************
*/
void Ser_RdStr (CPU_CHAR *string,
CPU_INT32U len)
{
CPU_CHAR input;
CPU_CHAR input_ix;
input_ix = 0;
string[0] = 0;
while (DEF_TRUE)
{
input = mon_getchar();
if ((input == '\r') ||
(input == '\n')) {
APP_TRACE_INFO(("\n"));
string[input_ix] = 0;
break;
}
if (input == '\b') {
if (input_ix > 0) {
APP_TRACE_INFO(("\b \b"));
input_ix--;
string[input_ix] = 0;
}
}
if (Str_IsPrint(input)) {
APP_TRACE_INFO(("%c", input));
string[input_ix] = input;
input_ix++;
if (input_ix >= len) {
input_ix = len;
}
}
}
}
void OSView_TmrInit (void)
{
#if 0 /* WIP */
*AT91C_TC0_IDR = 0xFFFFFFFF;
*AT91C_TC0_CMR = 0;
*AT91C_TC0_CCR = AT91C_TC_CLKEN |
AT91C_TC_SWTRG;
#endif
}
CPU_INT32U OSView_TmrRd (void)
{
#if 0 /* WIP */
return (*AT91C_TC0_CV);
#else
return (0);
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -