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

📄 bsp.c

📁 基于 Luminary Micro 公司的 Cortex-M3 (ARM)内核使用之 uC/OS-II 作业系统,此例程是移植于 LM3S102 上的应用,于 IAR EWARM V4.41A 工程编
💻 C
字号:
/*
*********************************************************************************************************
*                                                Luminary Micro
*                                             Board Support Package
*
*                                    (c) Copyright 2006, Micrium, Weston, FL
*                                              All Rights Reserved
*
*
* File : BSP.C
* By   : Jean J. Labrosse
*********************************************************************************************************
*/

#define  BSP_GLOBALS
#include <includes.h>

#define  BSP_DEBUG                           1

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

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

typedef  void (*PFNCT)(void);

/*
*********************************************************************************************************
*                                              VARIABLES
*********************************************************************************************************
*/

static  CPU_INT08U  LED_Image;

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

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)
{
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);

    PDCInit();                                    /* Must initialize the PDC in order to access ...    */
                                                  /* ... LEDs, dip sw. and the GPIOX, GPIOY and GPIOZ  */

    PDCLCDInit();                                 /* Initialize the 16x2 LCD character module          */
    PDCLCDBacklightOn();
    PDCLCDClear();

    LED_Init();                                   /* Initialize the I/Os for the LED controls          */

    Tmr_TickInit();                               /* Initialize the uC/OS-II tick interrupt            */
}

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

void  BSP_IntDisAll (void)
{
    CPU_DI();
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                         LED INITIALIZATION
*
* Description : This function initializes the board's LEDs
*
* Arguments   : none
*********************************************************************************************************
*/

void  LED_Init (void)
{
    LED_Image = 0x00;

    LED_Off(0);                                   /* Turn OFF 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 LED1  on the board
*                      .
*                      .
*                     16    turns ON LED16 on the board
*********************************************************************************************************
*/

void  LED_On (CPU_INT08U led)
{
    switch (led) {
        case 0:
             LED_Image |= 0xFF;
             break;

        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
             LED_Image |= 1 << (led - 1);
             break;

        default:
             break;
    }
    PDCLEDWrite(LED_Image);
}

/*
*********************************************************************************************************
*                                             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 LED1  on the board
*                      .
*                      .
*                     16    turns OFF LED16 on the board
*********************************************************************************************************
*/

void  LED_Off (CPU_INT08U led)
{
    switch (led) {
        case 0:
             LED_Image &= 0x00;
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
             LED_Image &= ~(1 << (led - 1));
             break;

        default:
             break;
    }
    PDCLEDWrite(LED_Image);
}

/*
*********************************************************************************************************
*                                             LED TOGGLE
*
* Description : This function is used to toggle any or all the LEDs on the board.
*
* Arguments   : led    is the number of the LED to control
*                      0    indicates that you want to toggle ALL the LEDs
*                      1    toggles LED1  on the board
*                      .
*                      .
*                     16    toggles LED16 on the board
*********************************************************************************************************
*/

void  LED_Toggle (CPU_INT08U led)
{
    switch (led) {
        case 0:
             LED_Image ^= 0xFF;
             break;

        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
             LED_Image ^= 1 << (led - 1);
             break;

        default:
             break;
    }
    PDCLEDWrite(LED_Image);
}

/*
*********************************************************************************************************
*                                     INITIALIZE TIMER FOR uC/OS-View
*
* Description : This function is called to by uC/OS-View to initialize the free running timer that is
*               used to make time measurements.
*
* Arguments   : none
*
* Returns     ; none
*
* Note(s)     : This function is EMPTY because the timer is initialized elsewhere.
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
void  OSView_TmrInit (void)
{
}
#endif

/*
*********************************************************************************************************
*                                     READ TIMER FOR uC/OS-View
*
* Description : This function is called to read the current counts of a 32 bit free running timer.
*
*               Timer #0 of the LPC2000 is used.  This is an UP-timer.
*
* Arguments   : none
*
* Returns     ; The 32 bit counts of the timer assuming the timer (MUST be an UP counter).
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
INT32U  OSView_TmrRd (void)
{
    return ((INT32U)0);
}
#endif

/*
*********************************************************************************************************
*                                       TICKER INITIALIZATION
*
* Description : This function is called to initialize uC/OS-II's tick source (typically a timer generating
*               interrupts every 1 to 100 mS).
*
* Arguments   : none
*
* Note(s)     : 1) The timer is setup for output compare mode BUT 'MUST' also 'freerun' so that the timer
*                  count goes from 0x00000000 to 0xFFFFFFFF to ALSO be able to read the free running count.
*                  The reason this is needed is because we use the free-running count in uC/OS-View.
*********************************************************************************************************
*/

static  void  Tmr_TickInit (void)
{
    CPU_INT32U  cnts;


    cnts = (CPU_INT32U)SysCtlClockGet() / OS_TICKS_PER_SEC;
    SysTickPeriodSet(cnts);
    SysTickEnable();
    SysTickIntEnable();
}


/*
*********************************************************************************************************
*                                         TIMER IRQ HANDLER
*
* Description : This function handles the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Arguments   : none
*
* Note(s)     : 1) The timer is 'reloaded' with the count at compare + the time for the next interrupt.
*                  Since we are using 'unsigned' integer math, overflows are irrelevant.
*********************************************************************************************************
*/

void  Tmr_TickISR_Handler (void)
{
    OS_CPU_SR  cpu_sr;


    OS_ENTER_CRITICAL();                         /* Tell uC/OS-II that we are starting an ISR          */
    OSIntNesting++;
    OS_EXIT_CRITICAL();

    OSTimeTick();                                /* Call uC/OS-II's OSTimeTick()                       */

    OSIntExit();                                 /* Tell uC/OS-II that we are leaving the ISR          */
}

⌨️ 快捷键说明

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