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

📄 bsp.c

📁 基于 Philips 公司的 ARM-7 使用之 uC/OS-II 作业系统,此例程是移植于 LPC-2148 上的应用,不同于一般的 Porting 其最主要是加入了支援 OS_View 观察器功能
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
*********************************************************************************************************
*                                               Philips LPC214x
*                                 LPC2148 Kick Start Card 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
*********************************************************************************************************
*/

#define  LED_1_BIT                           (CPU_INT32U)(1 << 25)

#define  LCD_BIT_RW                          (CPU_INT32U)(1 << 29)
#define  LCD_BIT_E                           (CPU_INT32U)(1 << 28)
#define  LCD_BIT_RS                          (CPU_INT32U)(1 << 22)
#define  LCD_BIT_DATA3                       (CPU_INT32U)(1 << 13)
#define  LCD_BIT_DATA2                       (CPU_INT32U)(1 << 12)
#define  LCD_BIT_DATA1                       (CPU_INT32U)(1 << 11)
#define  LCD_BIT_DATA0                       (CPU_INT32U)(1 << 10)


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

typedef  void (*PFNCT)(void);

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

        CPU_INT32U      Tmr_ReloadCnts;
        CPU_INT32U      VIC_SpuriousInt;

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

static  void  BSP_PLL_Init (void);
static  void  BSP_IO_Init(void);
static  void  BSP_MAM_Init(void);

#ifdef DISP_MODULE_PRESENT
static  void  DispE_High(void);
static  void  DispE_Low(void);
static  void  DispRW_High(void);
static  void  DispRW_Low (void);
#endif

static  void  Tmr_TickInit(void);

static  void  VIC_Init(void);
static  void  VIC_Dummy(void);
static  void  VIC_DummyWDT(void);
static  void  VIC_DummyTIMER0(void);
static  void  VIC_DummyTIMER1(void);
static  void  VIC_DummyUART0(void);
static  void  VIC_DummyUART1(void);
static  void  VIC_DummyPWM0(void);
static  void  VIC_DummyI2C(void);
static  void  VIC_DummySPI(void);
static  void  VIC_DummyRTC(void);
static  void  VIC_DummyEINT0(void);
static  void  VIC_DummyEINT1(void);
static  void  VIC_DummyEINT2(void);

/*
*********************************************************************************************************
*                                        Set up the PLL
*
* Description: This function sets up and activates the PLL
*********************************************************************************************************
*/

static  void  BSP_PLL_Init (void)
{
#if OS_CRITICAL_METHOD == 3                                     /* Allocate storage for CPU status register                 */
    OS_CPU_SR   cpu_sr = 0;
#endif
    INT16U  loop_ctr;

                                                                /* Configure PLL0, which determines the CPU clock           */
    PLLCFG            = 0x00000023;                             /* Use PLL values of M = 4 and P = 2                        */
    PLLCON_bit.PLLE   = 1;                                      /* Set the PLL Enable bit                                   */

    OS_ENTER_CRITICAL();
    PLLFEED           = 0xAA;                                   /* Write to the PLL Feed register                           */
    PLLFEED           = 0x55;
    OS_EXIT_CRITICAL();

    loop_ctr = 10000;                                           /* Wait for the PLL to lock into the new frequency          */
    while (((PLLSTAT_bit.PLOCK) == 0) && (loop_ctr > 0)) {
        loop_ctr--;
    }

    PLLCON_bit.PLLC   = 1;                                      /* Connect the PLL                                          */

    OS_ENTER_CRITICAL();
    PLLFEED           = 0xAA;                                   /* Write to the PLL Feed register                           */
    PLLFEED           = 0x55;
    OS_EXIT_CRITICAL();

    VPBDIV            = 0x00000002;                             /* Set the VPB frequency to one-half of the CPU clock       */
}

/*
*********************************************************************************************************
*                                      Get the CPU Clock Frequency
*
* Description: This function reads CPU registers to determine the CPU clock frequency of the chip.
*********************************************************************************************************
*/

CPU_INT32U  BSP_CPU_ClkFreq (void)
{
    CPU_INT32U  msel;
    CPU_INT32U  cpu_clk_freq;


    msel         = (CPU_INT32U)(PLLCFG & 0x1F);
    cpu_clk_freq = CPU_OSC_FREQ * (msel + 1);
    return (cpu_clk_freq);
}

/*
*********************************************************************************************************
*                                   Get the Peripheral Clock Frequency
*
* Description: This function reads CPU registers to determine the peripheral clock frequency of the chip.
*********************************************************************************************************
*/

CPU_INT32U  BSP_CPU_ClkFreqPeripheral (void)
{
    CPU_INT32U  msel;
    CPU_INT32U  vpbdiv;
    CPU_INT32U  cpu_clk_freq;
    CPU_INT32U  cpu_peripheral_clk_freq;


    msel         = (CPU_INT32U)(PLLCFG   & 0x1F);
    cpu_clk_freq = CPU_OSC_FREQ * (msel + 1);

    vpbdiv       = (CPU_INT32U)(VPBDIV & 0x03);
    switch (vpbdiv) {
        case 0:
             cpu_peripheral_clk_freq = cpu_clk_freq / 4;
             break;

        case 1:
             cpu_peripheral_clk_freq = cpu_clk_freq;
             break;

        case 2:
             cpu_peripheral_clk_freq = cpu_clk_freq / 2;
             break;

        default:
             cpu_peripheral_clk_freq = cpu_clk_freq / 4;
             break;
    }
    return (cpu_peripheral_clk_freq);
}

/*
*********************************************************************************************************
*                                         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)
{
    MEMMAP                            = 2;                      /* Remap 64 bytes of int. RAM to 0x00                       */


    OS_CPU_InitExceptVect();

    BSP_PLL_Init();                                             /* Initialize PLL0 and the VPB Divider Register             */

    BSP_MAM_Init();                                             /* Initialize the Memory Acceleration Module                */

    BSP_IO_Init();                                              /* Initialize the board's I/Os                              */

    VIC_Init();                                                 /* Initialize the Vectored Interrupt Controller             */

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

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

#ifdef DISP_MODULE_PRESENT
    Tmr1_Init();
#endif
}

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

void  BSP_IntDisAll (void)
{
    VICIntEnClear = 0xFFFFFFFFL;                                /* Disable ALL interrupts                                   */
}


/*
*********************************************************************************************************
*                                          INITIALIZE I/Os
*
* Description : This function initializes the GPIO pins.  All the I/O pins are initialized in this function
*               so you don't have to look at multiple places for I/O initialization.
*
* Arguments   : none
*********************************************************************************************************
*/

static  void  BSP_IO_Init (void)
{
    CPU_INT32U  value;


    SCS = 0x00000001;                                       /* Fast GPIO registers will be used                             */

#if OS_VIEW_MODULE == 0
    PINSEL0  = 0x00000000;
#endif

#if (OS_VIEW_MODULE > 0) && (OS_VIEW_COMM_SEL == OS_VIEW_UART_0)
    PINSEL0  = 0x00000005;                                  /* Enable UART0 I/Os                                            */
#endif

#if (OS_VIEW_MODULE > 0) && (OS_VIEW_COMM_SEL == OS_VIEW_UART_1)
    PINSEL0  = 0x00050000;                                  /* Enable UART1 I/Os                                            */
#endif

    value    = (1 << 16) | (1 << 15);                       /* Push buttons B2 and B1                                       */

    FIO0DIR &= ~value;

                                                            /* LCD control lines                                            */
    value    = ~((3 << 20) | (3 << 22) | (3 << 24) | (3 << 26));
    PINSEL0 &= value;
                                                            /* LCD data    lines                                            */
    value    = ~((3 << 12) | (3 << 24) | (3 << 26));
    PINSEL1 &= value;
    value    = LCD_BIT_DATA3 | LCD_BIT_DATA2 | LCD_BIT_DATA1 | LCD_BIT_DATA0 | LCD_BIT_E | LCD_BIT_RS | LCD_BIT_RW | LED_1_BIT;

    FIO0DIR |= value;

#ifdef DISP_MODULE_PRESENT
    DispRW_High();
#endif

    PINSEL2  = 0x00000004;
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                      WRITE DATA TO DISPLAY DEVICE
*
* Description : This function sends a single BYTE to the display device.
* Arguments   : 'data'  is the BYTE to send to the display device
* Returns     : none
* Notes       : 1) The LPC2148 evaluation board uses a 4 bit interface.
*                  If an 8 bit interface is used. BSP_IO_Init() and DispDataWr() will need
*                  to be modified to reflect the new databus. In 8 bit mode, DispDataWrOneNibble()
*                  is not necessary.
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
void  DispDataWr (CPU_INT08U data)
{
    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) << 10;

    FIO0SET = value;
    value  = (~(data >> 4) & 0x0F) << 10;
    FIO0CLR = value;

    DispDly_uS(100);
    DispE_Low();

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

⌨️ 快捷键说明

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