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

📄 bsp.c

📁 官方的UCOSii的移植文件
💻 C
📖 第 1 页 / 共 4 页
字号:
* Return(s)   : none.
*
* Caller(s)   : OS_CPU_ARM_EXCEPT_HANDLER(), which is declared in os_cpu_a.s.
*********************************************************************************************************
*/

void  OS_CPU_ExceptHndlr (CPU_DATA except_id)
{
    CPU_FNCT_VOID  pfnct;
    CPU_INT32U    *sp;

                                                                        /* If this exception is either an IRQ or FIQ        */
    if ((except_id == OS_CPU_ARM_EXCEPT_IRQ) || (except_id == OS_CPU_ARM_EXCEPT_FIQ)) {
        pfnct = (CPU_FNCT_VOID)VICAddress;                              /* Read the interrupt vector from the VIC           */
        if (pfnct != (CPU_FNCT_VOID)0) {                                /* Make sure we don't have a NULL pointer           */
          (*pfnct)();                                                   /* Execute the ISR for the interrupting device      */
            VICAddress = 1;                                             /* Acknowlege the VIC interrupt                     */
        }
    } else {
        sp = (CPU_INT32U *)OSTCBCur->OSTCBStkPtr;
        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)
{
    VICIntEnClear = 0xFFFFFFFFL;                                /* Disable ALL interrupts                                   */
}


/*
******************************************************************************************************************************
******************************************************************************************************************************
**                                       LED, PB AND ADC FUNCTIONS
******************************************************************************************************************************
******************************************************************************************************************************
*/

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

void  LED_Init (void)
{
    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
*                       .
*                       .
*                       .
*                       8    turn ON LED8
*
* Return(s)   : none.
*********************************************************************************************************
*/

void  LED_On (CPU_INT08U led)
{
    if (led == 0) {
        FIO2SET    =    0xFF;                                           /* Turn on ALL LEDs                                        */
    }

    if ((led >= 1) && (led <= 8)) {
        led--;                                                          /* Ex: If led is 1, then subtract 1 to indicate bit 0       */
        FIO2SET =  (1 << led);                                          /* Turn on the selected LED                                 */
    }
}


/*
*********************************************************************************************************
*                                             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
*                       .
*                       .
*                       .
*                       8    turn OFF LED8
*
* Return(s)   : none.
*********************************************************************************************************
*/

void  LED_Off (CPU_INT08U led)
{
    if (led == 0) {
        FIO2CLR    =    0xFF;                                           /* Turn off ALL LEDs                                        */
    }

    if ((led >= 1) && (led <= 8)) {
        led--;                                                          /* Ex: If led is 1, then subtract 1 to indicate bit 0       */
        FIO2CLR =  (1 << led);                                          /* Turn off the selected LED                                */
    }
}


/*
*********************************************************************************************************
*                                             LED_Toggle()
*
* Description : TOGGLE any or all the LEDs on the board.
*
* Argument(s) : led     The ID of the LED to control:
*
*                       0    TOGGLE all LEDs on the board
*                       1    TOGGLE LED1
*                       .
*                       .
*                       .
*                       8    TOGGLE LED8
*
* Return(s)   : none.
*********************************************************************************************************
*/

void  LED_Toggle (CPU_INT08U led)
{
    CPU_INT08U  status;


    if (led == 0) {
        status     =    FIO2PIN;
        FIO2SET    =   ~status;
        FIO2CLR    =    status;
    }

    if ((led >= 1) && (led <= 8)) {
        led--;                                                          /* Ex: If led is 1, then subtract 1 to indicate bit 0       */
        if ((FIO2PIN & (1 << led)) == 0) {                              /* If the LED is currently off                              */
            FIO2SET =  (1 << 0);                                        /* Turn on the selected LED                                 */
        } else {
            FIO2CLR =  (1 << led);                                      /* Turn off the selected LED                                */
        }
    }
}


/*
*********************************************************************************************************
*                                           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 INT1
*
* 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_FALSE;

    switch (pb) {
        case 1:
             if ((FIO2PIN & GPIO2_PB1) == 0) {
                 status =  (DEF_TRUE);
             }
             break;

        default:
             break;
    }

    return (status);
}

/*
*********************************************************************************************************
*                                           ADC_Init()
*
* Description : Initialize the board's ADC.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  ADC_Init (void)
{
    CPU_INT08U  div;
    CPU_INT32U  pinsel;


    PCONP      |=  DEF_BIT_12;

    div         = (BSP_CPU_PclkFreq(PCLK_ADC) / 4500000) + 1;
                                                                /* Configure ADC ...                                        */
    AD0CR       = (0x01 <<  0)                                  /*  ... Sample/convert pin AD0.0 ...                        */
                | (div  <<  8)                                  /*  ... Set divider so sample freq. < 4.5 MHz ...           */
                |  DEF_BIT_16                                   /*  ... Use burst mode for continuous conversion ...        */
                | (0x00 << 17)                                  /*  ... Use 11 clocks per conversion for 10-bit accuracy ...*/
                |  DEF_BIT_21;                                  /*  ... Power up the ADC.                                   */

                                                                /* Select AD0.0 function for P0.23                          */
    pinsel      = PINSEL1;
    pinsel     &= 0xFFFF3FFF;
    pinsel     |= 0x00004000;
    PINSEL1     = pinsel;
}


/*
*********************************************************************************************************
*                                           ADC_GetStatus()
*
* Description : Get the status of an ADC input.
*
* Argument(s) : pb      The ID of the push button to probe
*
*                       0   probes AD0.0, the potentiometer
*
* Return(s)   : The numerator of the binary fraction representing the result of the latest ADC conversion.
*               This value will be a 10-bit value between 0x0000 and 0x03FF, inclusive.
*********************************************************************************************************
*/

CPU_INT16U  ADC_GetStatus (CPU_INT08U  adc)
{
    if (adc == 0) {
        return ((ADDR0 >> 6) & 0x03FF);
    } else {
        return (0);
    }
}

/*
*********************************************************************************************************
*********************************************************************************************************
**                                          uC/LCD FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                            DispInitPort()
*
* Description : Initializes the I/O ports used by the display driver.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Note(s)     : (1) The I/Os for the LCD module are initialized in BSP_IO_Init().
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
void  DispInitPort (void)
{
}
#endif


/*
*********************************************************************************************************
*                                              DispDataWr()
*
* Description : Sends a single byte to the display device.
*
* Argument(s) : 'data'      Data to send to the display device
*
* Return(s)   : none.
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
void  DispDataWr (CPU_INT08U data)
{
    CPU_INT32U  value;


    DispRW_Low();                                                       /* Set R/W write LOW to write to the LCD module             */

    DispE_High();                                                       /* Write the UPPER nibble to the LCD module                 */
    value  =  ((data >> 4) & 0x0F) << 24;
    IO1SET = value;
    value  = (~(data >> 4) & 0x0F) << 24;
    IO1CLR = value;

    DispDly_uS(100);
    DispE_Low();

    DispDly_uS(100);                                                    /* Write the LOWER nibble to the LCD module                 */
    DispE_High();

    value  =  (data & 0x0F) << 24;
    IO1SET = value;
    value  = (~data & 0x0F) << 24;
    IO1CLR = value;

    DispDly_uS(100);
    DispE_Low();
}

#if DISP_BUS_WIDTH == 4
void DispDataWrOneNibble(CPU_INT08U data)
{
    CPU_INT32U  value;


    DispRW_Low();                                                       /* Set R/W write LOW to write to the LCD module             */

    DispE_High();                                                       /* Write the UPPER nibble to the LCD module                 */
    value  =  ((data >> 4) & 0x0F) << 24;
    IO1SET = value;
    value  = (~(data >> 4) & 0x0F) << 24;
    IO1CLR = value;

⌨️ 快捷键说明

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