⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bsp.c

📁 GNU环境下uC/OS-II的移植代码:BSP & OS部分
💻 C
📖 第 1 页 / 共 2 页
字号:
*
* 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_00 |
                                           DEF_BIT_01 |
                                           DEF_BIT_02);
             break;

        case 1:
             BSP_CSB_ARM_LED_RegImage &=  ~DEF_BIT_02;
             break;

        case 2:
             BSP_CSB_ARM_LED_RegImage &=  ~DEF_BIT_01;
             break;

        case 3:
             BSP_CSB_ARM_LED_RegImage &=  ~DEF_BIT_00;
             break;
    }

   *AT91C_PIOB_SODR =  BSP_CSB_ARM_LED_RegImage & (DEF_BIT_00 |
                                                   DEF_BIT_01 |
                                                   DEF_BIT_02);
   *AT91C_PIOB_CODR = ~BSP_CSB_ARM_LED_RegImage & (DEF_BIT_00 |
                                                   DEF_BIT_01 |
                                                   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_00 |
                                          DEF_BIT_01 |
                                          DEF_BIT_02);
             break;

        case 1:
             BSP_CSB_ARM_LED_RegImage |=  DEF_BIT_02;
             break;

        case 2:
             BSP_CSB_ARM_LED_RegImage |=  DEF_BIT_01;
             break;

        case 3:
             BSP_CSB_ARM_LED_RegImage |=  DEF_BIT_00;
             break;
    }

   *AT91C_PIOB_SODR =  BSP_CSB_ARM_LED_RegImage & (DEF_BIT_00 |
                                                   DEF_BIT_01 |
                                                   DEF_BIT_02);
   *AT91C_PIOB_CODR = ~BSP_CSB_ARM_LED_RegImage & (DEF_BIT_00 |
                                                   DEF_BIT_01 |
                                                   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_00 |
                                          DEF_BIT_01 |
                                          DEF_BIT_02);
             break;

        case 1:
             BSP_CSB_ARM_LED_RegImage ^=  DEF_BIT_02;
             break;

        case 2:
             BSP_CSB_ARM_LED_RegImage ^=  DEF_BIT_01;
             break;

        case 3:
             BSP_CSB_ARM_LED_RegImage ^=  DEF_BIT_00;
             break;
    }

   *AT91C_PIOB_SODR =  BSP_CSB_ARM_LED_RegImage & (DEF_BIT_00 |
                                                   DEF_BIT_01 |
                                                   DEF_BIT_02);
   *AT91C_PIOB_CODR = ~BSP_CSB_ARM_LED_RegImage & (DEF_BIT_00 |
                                                   DEF_BIT_01 |
                                                   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;

        case 2:
             status = ((*AT91C_PIOB_PDSR & DEF_BIT_28) == 0);
             break;

        case 3:
             status = ((*AT91C_PIOA_PDSR & DEF_BIT_21) == 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;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -