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

📄 bsp.c

📁 AT91SAM7SE,ucos移植范例
💻 C
📖 第 1 页 / 共 4 页
字号:
        APP_TRACE_INFO(("\nCPU_ARM_EXCEPTION #%d trapped.\n", except_id));
        APP_TRACE_INFO(("R0  : 0x%08x\n", *(sp + 0x01)));
        APP_TRACE_INFO(("R1  : 0x%08x\n", *(sp + 0x02)));
        APP_TRACE_INFO(("R2  : 0x%08x\n", *(sp + 0x03)));
        APP_TRACE_INFO(("R3  : 0x%08x\n", *(sp + 0x04)));
        APP_TRACE_INFO(("R4  : 0x%08x\n", *(sp + 0x05)));
        APP_TRACE_INFO(("R5  : 0x%08x\n", *(sp + 0x06)));
        APP_TRACE_INFO(("R6  : 0x%08x\n", *(sp + 0x07)));
        APP_TRACE_INFO(("R7  : 0x%08x\n", *(sp + 0x08)));
        APP_TRACE_INFO(("R8  : 0x%08x\n", *(sp + 0x09)));
        APP_TRACE_INFO(("R9  : 0x%08x\n", *(sp + 0x0A)));
        APP_TRACE_INFO(("R10 : 0x%08x\n", *(sp + 0x0B)));
        APP_TRACE_INFO(("R11 : 0x%08x\n", *(sp + 0x0C)));
        APP_TRACE_INFO(("R12 : 0x%08x\n", *(sp + 0x0D)));
        APP_TRACE_INFO(("SP  : 0x%08x\n",   sp));
        APP_TRACE_INFO(("LR  : 0x%08x\n", *(sp + 0x0E)));
        APP_TRACE_INFO(("PC  : 0x%08x\n", *(sp + 0x0F)));
        APP_TRACE_INFO(("CPSR: 0x%08x\n", *(sp + 0x00)));

                                                                /* Infinite loop on other exceptions.                       */
                                                                /* Should be replaced by other behavior (reboot, etc.)      */
        while (DEF_TRUE) {
            ;
        }
    }
}


/*
*********************************************************************************************************
*                                           BSP_IntDisAll()
*
* Description : Disable ALL interrupts.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

void  BSP_IntDisAll (void)
{
    AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF;                              /* Disable all interrupts                                   */
}


/*
******************************************************************************************************************************
******************************************************************************************************************************
**                                       LED, PB & JOYSTICK FUNCTIONS
******************************************************************************************************************************
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                             LED_Init()
*
* Description : Setup the I/O for the LEDs.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  LED_Init (void)
{
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;                          /* Enable peripheral clock                      */
    AT91C_BASE_PIOA->PIO_PER = GPIOA_LED1 | GPIOA_LED2 | GPIOA_LED_POWER;   /* Enable PIO control of pins                   */
    AT91C_BASE_PIOA->PIO_OER = GPIOA_LED1 | GPIOA_LED2 | GPIOA_LED_POWER;   /* Enable output on pins                        */
    AT91C_BASE_PIOA->PIO_IDR = GPIOA_LED1 | GPIOA_LED2 | GPIOA_LED_POWER;   /* Disable interrupt on pins                    */

    LED_Off(0);                                                             /* Turn OFF all the LEDs                        */
}

/*
*********************************************************************************************************
*                                             LED_On()
*
* Description : Turn ON any or all the LEDs on the board.
*
* Argument(s) : led     The ID of the LED to control:
*
*                       0    turn ON all LEDs on the board
*                       1    turn ON LED1 on the board
*                       2    turn ON LED2 on the board
*                       3    turn ON LED3 on the board (the power LED)
*
* Return(s)   : none.
*********************************************************************************************************
*/

void  LED_On (CPU_INT08U led)
{
    switch (led) {
        case 0:
             AT91C_BASE_PIOA->PIO_CODR = GPIOA_LED1 | GPIOA_LED2 | GPIOA_LED_POWER;
             break;

        case 1:
             AT91C_BASE_PIOA->PIO_CODR = GPIOA_LED1;
             break;

        case 2:
             AT91C_BASE_PIOA->PIO_CODR = GPIOA_LED2;
             break;

        case 3:
             AT91C_BASE_PIOA->PIO_CODR = GPIOA_LED_POWER;
             break;
    }
}

/*
*********************************************************************************************************
*                                             LED_Off()
*
* Description : Turn OFF any or all the LEDs on the board.
*
* Argument(s) : led     The ID of the LED to control:
*
*                       0    turn OFF all LEDs on the board
*                       1    turn OFF LED1 on the board
*                       2    turn OFF LED2 on the board
*                       3    turn OFF LED3 on the board (the power LED)
*
* Return(s)   : none.
*********************************************************************************************************
*/

void  LED_Off (CPU_INT08U led)
{
    switch (led) {
        case 0:
             AT91C_BASE_PIOA->PIO_SODR = GPIOA_LED1 | GPIOA_LED2 | GPIOA_LED_POWER;
             break;

        case 1:
             AT91C_BASE_PIOA->PIO_SODR = GPIOA_LED1;
             break;

        case 2:
             AT91C_BASE_PIOA->PIO_SODR = GPIOA_LED2;
             break;

        case 3:
             AT91C_BASE_PIOA->PIO_SODR = GPIOA_LED_POWER;
             break;
    }
}

/*
*********************************************************************************************************
*                                             LED_Toggle()
*
* Description : TOGGLE any or all the LEDs on the board.
*
* Argument(s) : led     The ID of the LED to control:
*
*                       0    turn TOGGLE all LEDs on the board
*                       1    turn TOGGLE LED1 on the board
*                       2    turn TOGGLE LED2 on the board
*                       3    turn TOGGLE LED3 on the board (the power LED)
*
* Return(s)   : none.
*********************************************************************************************************
*/

void  LED_Toggle (CPU_INT08U led)
{
    switch (led) {
        case 0:
             if (AT91C_BASE_PIOA->PIO_ODSR & GPIOA_LED1) {
                 AT91C_BASE_PIOA->PIO_CODR = GPIOA_LED1;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = GPIOA_LED1;
             }
             if (AT91C_BASE_PIOA->PIO_ODSR & GPIOA_LED2) {
                 AT91C_BASE_PIOA->PIO_CODR = GPIOA_LED2;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = GPIOA_LED2;
             }
             if (AT91C_BASE_PIOA->PIO_ODSR & GPIOA_LED_POWER) {
                 AT91C_BASE_PIOA->PIO_CODR = GPIOA_LED_POWER;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = GPIOA_LED_POWER;
             }
             break;

        case 1:
             if (AT91C_BASE_PIOA->PIO_ODSR & GPIOA_LED1) {
                 AT91C_BASE_PIOA->PIO_CODR = GPIOA_LED1;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = GPIOA_LED1;
             }
             break;

        case 2:
             if (AT91C_BASE_PIOA->PIO_ODSR & GPIOA_LED2) {
                 AT91C_BASE_PIOA->PIO_CODR = GPIOA_LED2;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = GPIOA_LED2;
             }
             break;
        case 3:
             if (AT91C_BASE_PIOA->PIO_ODSR & GPIOA_LED_POWER) {
                 AT91C_BASE_PIOA->PIO_CODR = GPIOA_LED_POWER;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = GPIOA_LED_POWER;
             }
             break;
    }
}

/*
*********************************************************************************************************
*                                         PB_Init()
*
* Description : Initializes the I/O for the push buttons.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  PB_Init (void)
{
    AT91C_BASE_PMC->PMC_PCER   = 1 << AT91C_ID_PIOB;            /* Enable peripheral clock                                  */
    AT91C_BASE_PIOB->PIO_PER   = GPIOB_PB2 | GPIOB_PB1;         /* Enable PIO control of pins                               */
    AT91C_BASE_PIOB->PIO_ODR   = GPIOB_PB2 | GPIOB_PB1;         /* Disable output on pins                                   */
    AT91C_BASE_PIOB->PIO_IDR   = GPIOB_PB2 | GPIOB_PB1;         /* Disable interrupt on pins                                */
    AT91C_BASE_PIOB->PIO_PPUER = GPIOB_PB2 | GPIOB_PB1;         /* Enable pull-up on pins                                   */
}

/*
*********************************************************************************************************
*                                         PB_GetStatus()
*
* Description : Get the status of a push button on the board.
*
* Argument(s) : pb      The ID of the push button to probe
*
*                       1    probe the push button B1
*                       2    probe the push button B2
*
* Return(s)   : DEF_FALSE   if the push button is pressed
*               DEF_TRUE    if the push button is not pressed
*********************************************************************************************************
*/

CPU_BOOLEAN  PB_GetStatus (CPU_INT08U pb)
{
    CPU_BOOLEAN  status;


    status  = DEF_TRUE;

    switch (pb) {
        case 1:
            if (AT91C_BASE_PIOB->PIO_PDSR & GPIOB_PB1) {
                status  = DEF_FALSE;
            }
            break;

        case 2:
            if (AT91C_BASE_PIOB->PIO_PDSR & GPIOB_PB2) {
                status  = DEF_FALSE;
            }
            break;

        default:
            break;
    }

    return (status);
}


/*
*********************************************************************************************************
*                                         Joystick_Init()
*
* Description : Initializes the I/O for the joystick.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  Joystick_Init (void)
{
    AT91C_BASE_PMC->PMC_PCER   = 1 << AT91C_ID_PIOB;                /* Enable peripheral clock                              */
    AT91C_BASE_PIOB->PIO_PER   = GPIOB_JOY_UP   | GPIOB_JOY_DOWN    /* Enable PIO control of pins                           */
                               | GPIOB_JOY_LEFT | GPIOB_JOY_RIGHT;
    AT91C_BASE_PIOB->PIO_ODR   = GPIOB_JOY_UP   | GPIOB_JOY_DOWN    /* Disable output on pins                               */
                               | GPIOB_JOY_LEFT | GPIOB_JOY_RIGHT;
    AT91C_BASE_PIOB->PIO_IDR   = GPIOB_JOY_UP   | GPIOB_JOY_DOWN    /* Disable interrupt on pins                            */
                               | GPIOB_JOY_LEFT | GPIOB_JOY_RIGHT;
    AT91C_BASE_PIOB->PIO_PPUER = GPIOB_JOY_UP   | GPIOB_JOY_DOWN    /* Enable pull-up on pins                               */
                               | GPIOB_JOY_LEFT | GPIOB_JOY_RIGHT;
}


/*
*********************************************************************************************************
*                                         Joystick_GetStatus()

⌨️ 快捷键说明

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