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

📄 bsp.c

📁 可以在ARM嵌入式单片机上运行的uCOS源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                                Logic PD
*                                         Board Support Package
*                                          LH79520 Card Engine
*
*                             (c) Copyright 2004, Micrium, Inc., Weston, FL
*                                          All Rights Reserved
*
*
* File         : BSP.C
* Originally by: Jean J. Labrosse
*********************************************************************************************************
*/

#include <includes.h>

/*
*********************************************************************************************************
*                                               CONSTANTS                                                
*********************************************************************************************************
*/

#define  BSP_UNDEF_INSTRUCTION_VECTOR_ADDR   (*(INT32U *)        0x00000004L)
#define  BSP_SWI_VECTOR_ADDR                 (*(INT32U *)        0x00000008L)
#define  BSP_PREFETCH_ABORT_VECTOR_ADDR      (*(INT32U *)        0x0000000CL)
#define  BSP_DATA_ABORT_VECTOR_ADDR          (*(INT32U *)        0x00000010L)
#define  BSP_IRQ_VECTOR_ADDR                 (*(INT32U *)        0x00000018L)
#define  BSP_FIQ_VECTOR_ADDR                 (*(INT32U *)        0x0000001CL)

#define  BSP_IRQ_ISR_ADDR                    (*(INT32U *)        0x00000038L)
#define  BSP_FIQ_ISR_ADDR                    (*(INT32U *)        0x0000003CL)


#define  LED_PORT                            (*(volatile INT8U *)0x55600000L)

/*
*********************************************************************************************************
*                                               DATA TYPES
*********************************************************************************************************
*/

typedef  void (*PFNCT)(void);

/*
*********************************************************************************************************
*                                            GLOBAL VARIABLES
*********************************************************************************************************
*/

static  INT8U  LED_Image;

/*
*********************************************************************************************************
*                                               PROTOTYPES
*********************************************************************************************************
*/

static  void  BSP_InitIntCtrl(void);
static  void  Tmr_TickInit(void);

/*
*********************************************************************************************************
*                                           BSP 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  BSP_Init (void)
{
    VIC->intenclear     = 0xFFFFFFFFL;                /* Disable ALL interrupts                        */
    RCPC->intclear      = 0x000000FFL;                /* Clear ALL external interrupts                 */                                            

#if 1
    RCPC->remap         = 0x00000002L;                /* Remap internal SRAM to 0x00000000             */
#endif

    RCPC->periphclkctrl = 0x00000000L;                /* Initialize the peripheral clock control       */
    RCPC->spareclkctrl  = 0x00000000L;

    BSP_InitIntCtrl();                                /* Initialize the interrupt controller           */

    Tmr_Init();                                       /* Initialize the timers                         */

    Tmr_TickInit();                                   /* Initialize uC/OS-II's tick ISR                */

    LED_Init();                                       /* Initialize LEDs                               */
}

/*
*********************************************************************************************************
*                                    INITIALIZE INTERRUPT CONTROLLER
*
* 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
*
* Note(s)     : 1) 0xE59FF020 is opcode of:  ldr pc,[pc,#+0x20]
*********************************************************************************************************
*/

static  void  BSP_InitIntCtrl (void)
{
    VIC->intenclear                   = 0xFFFFFFFF;   /* Disable ALL interrupts                        */

    BSP_IRQ_VECTOR_ADDR               = 0xE59FF018;                /* LDR PC,[PC,#0x18] instruction    */
    BSP_IRQ_ISR_ADDR                  = (INT32U)OS_CPU_IRQ_ISR;    /* IRQ exception vector address     */

    BSP_FIQ_VECTOR_ADDR               = 0xE59FF018;                /* LDR PC,[PC,#0x18] instruction    */
    BSP_FIQ_ISR_ADDR                  = (INT32U)OS_CPU_FIQ_ISR;    /* FIQ exception vector address     */


    BSP_UNDEF_INSTRUCTION_VECTOR_ADDR = 0xEAFFFFFE;   /* Jump to itself                                */
    BSP_SWI_VECTOR_ADDR               = 0xEAFFFFFE;
    BSP_PREFETCH_ABORT_VECTOR_ADDR    = 0xEAFFFFFE;
    BSP_DATA_ABORT_VECTOR_ADDR        = 0xEAFFFFFE;
    BSP_FIQ_VECTOR_ADDR               = 0xEAFFFFFE;
}

/*
*********************************************************************************************************
*                                     DISABLE ALL INTERRUPTS
*
* Description : This function disables all interrupts from the interrupt controller.
*               
* Arguments   : none
*********************************************************************************************************
*/

void  BSP_IntDisAll (void)
{
    VIC->intenclear = 0xFFFFFFFFL;           /* Disable ALL interrupts                                 */
}

/*
*********************************************************************************************************
*                                           BSP 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 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 (INT8U led)
{
#if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
    OS_CPU_SR  cpu_sr;
#endif    


    OS_ENTER_CRITICAL();
    switch (led) {
        case 0:
             LED_Image  =  0x00;
             LED_PORT   = LED_Image;
             GPIOB->dr &= ~0x02;
             break;

        case 1:
             LED_Image &= ~0x01;
             LED_PORT   = LED_Image;
             break;

        case 2:
             LED_Image &= ~0x02;
             LED_PORT   = LED_Image;
             break;

        case 3:
             GPIOB->dr &= ~0x02;
             break;

        case 4:
             LED_Image &= ~0x08;
             LED_PORT   = LED_Image;
             break;
    }
    OS_EXIT_CRITICAL();
}

/*
*********************************************************************************************************
*                                                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 (INT8U led)
{
#if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
    OS_CPU_SR  cpu_sr;
#endif    


    OS_ENTER_CRITICAL();
    switch (led) {
        case 0:
             LED_Image  = 0xFF;
             LED_PORT   = LED_Image;
             GPIOB->dr |= 0x02;
             break;

        case 1:
             LED_Image |= 0x01;
             LED_PORT   = LED_Image;
             break;

        case 2:
             LED_Image |= 0x02;
             LED_PORT   = LED_Image;
             break;

        case 3:
             GPIOB->dr |= 0x02;
             break;

        case 4:
             LED_Image |= 0x08;
             LED_PORT   = LED_Image;
             break;
    }
    OS_EXIT_CRITICAL();
}

⌨️ 快捷键说明

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