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

📄 bsp.c

📁 IAR ARM + uC/OS-II2.76 + LPC2129
💻 C
字号:
/*
*********************************************************************************************************
*                                               Philips LPC210x
*                                     Keil's MCB2100 Board Support Package
*
*                                    (c) Copyright 2005, Micrium, Weston, FL
*                                              All Rights Reserved
*
*
* File : BSP.C
* 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)

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

typedef  void (*BSP_PFNCT)(void);


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

INT32U  VIC_SpuriousInt;

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

void  VIC_Init(void);
void  VIC_Dummy(void);
void  VIC_DummyWDT(void);
void  VIC_DummyTIMER0(void);
void  VIC_DummyTIMER1(void);
void  VIC_DummyUART0(void);
void  VIC_DummyUART1(void);
void  VIC_DummyPWM0(void);
void  VIC_DummyI2C(void);
void  VIC_DummySPI(void);
void  VIC_DummyRTC(void);
void  VIC_DummyEINT0(void);
void  VIC_DummyEINT1(void);
void  VIC_DummyEINT2(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)
{
    MEMMAP                            = 2;                      /* Remap 64 bytes of int. RAM to 0x00  */

    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;

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

    LED_Init();
    Tmr_TickInit();
}


/*
*********************************************************************************************************
*                                         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)
{
    PINSEL0   = 0;
    PINSEL1   = 0;                                /* Use GPIO pins P1.16 to P1.23 for LEDs             */
    IO0DIR   |= 0x0f000000;                       /* Set GPIO pins as outputs                          */

//    LED_On(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
*                      .
*                      .
*                      8    turns ON LED8 on the board
*********************************************************************************************************
*/

void  LED_On0 (INT8U led)
{
    IO0SET |= 0x02000000;
}
void  LED_On1 (INT8U led)
{
    IO0SET |= 0x01000000;
}
/*
*********************************************************************************************************
*                                             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
*                      .
*                      .
*                      8    turns OFF LED8 on the board
*********************************************************************************************************
*/

void  LED_Off0 (INT8U led)
{
    IO0CLR = 0x02000000;
}
void  LED_Off1 (INT8U led)
{
    IO0CLR = 0x01000000;
}

/*
*********************************************************************************************************
*                                           IRQ ISR HANDLER
*
* Description : This function is called by OS_CPU_IRQ_ISR() to determine the source of the interrupt
*               and process it accordingly.
*
* Arguments   : none
*********************************************************************************************************
*/

void  OS_CPU_IRQ_ISR_Handler (void)
{
    BSP_PFNCT  pfnct;


    pfnct = (BSP_PFNCT)VICVectAddr;             /* Read the interrupt vector from the VIC               */
    while (pfnct != (BSP_PFNCT)0) {             /* Make sure we don't have a NULL pointer               */
      (*pfnct)();                               /* Execute the ISR for the interrupting device          */
        pfnct = (BSP_PFNCT)VICVectAddr;         /* Read the interrupt vector from the VIC               */
    }
}


/*
*********************************************************************************************************
*                                           FIQ ISR HANDLER
*
* Description : This function is called by OS_CPU_FIQ_ISR() to determine the source of the interrupt
*               and process it accordingly.
*
* Arguments   : none
*********************************************************************************************************
*/

void  OS_CPU_FIQ_ISR_Handler (void)
{
    BSP_PFNCT  pfnct;


    pfnct = (BSP_PFNCT)VICVectAddr;             /* Read the interrupt vector from the VIC               */
    while (pfnct != (BSP_PFNCT)0) {             /* Make sure we don't have a NULL pointer               */
      (*pfnct)();                               /* Execute the ISR for the interrupting device          */
        pfnct = (BSP_PFNCT)VICVectAddr;         /* Read the interrupt vector from the VIC               */
    }
}


/*
*********************************************************************************************************
*                                       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
*********************************************************************************************************
*/

void  Tmr_TickInit (void)
{
                                                 /* VIC TIMER #0 Initialization                        */
    VICIntSelect &= ~(1 << VIC_TIMER0);          /* Enable interrupts                                  */
    VICVectAddr2  = (INT32U)Tmr_TickISR_Handler; /* Set the vector address                             */
    VICVectCntl2  = 0x20 | VIC_TIMER0;           /* Enable vectored interrupts                         */
    VICIntEnable  =  (1 << VIC_TIMER0);          /* Enable Interrupts                                  */

    T0TCR         = 0;                           /* Disable timer 0.                                   */
    T0PC          = 0;                           /* Prescaler is set to no division.                   */
    T0MR0         = CPU_PERIPHERAL_CLK_FREQ / OS_TICKS_PER_SEC;  /* Count up to this value.            */
    T0MCR         = 3;                           /* Reset and interrupt on MR0 (match register 0).     */
    T0CCR         = 0;                           /* Capture is disabled.                               */
    T0EMR         = 0;                           /* No external match output.                          */
    T0TCR         = 1;                           /* Enable timer 0                                     */
}


/*
*********************************************************************************************************
*                                         TIMER #0 IRQ HANDLER
*
* Description : This function handles the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Arguments   : none
*********************************************************************************************************
*/

void  Tmr_TickISR_Handler (void)
{
    T0IR        = 0xFF;                 /* Clear timer #0 interrupt                                    */
    OSTimeTick();                       /* If the interrupt is from the tick source, call OSTimeTick() */
    VICVectAddr = 0;
}


/*
*********************************************************************************************************
*                                        Vectored Interrupt Controller
*********************************************************************************************************
*/

void  VIC_Init (void)
{
    VICIntEnClear = 0xFFFFFFFF;                  /* Disable ALL interrupts                             */
    VICProtection = 0;                           /* Setup interrupt controller                         */

    VICVectAddr1  = (INT32U)VIC_DummyWDT;        /* Set the vector address                             */
    VICVectAddr2  = (INT32U)VIC_DummyTIMER0;
    VICVectAddr3  = (INT32U)VIC_DummyTIMER1;
    VICVectAddr4  = (INT32U)VIC_DummyUART0;
    VICVectAddr5  = (INT32U)VIC_DummyUART1;
    VICVectAddr6  = (INT32U)VIC_DummyPWM0;
    VICVectAddr7  = (INT32U)VIC_DummyI2C;
    VICVectAddr8  = (INT32U)VIC_DummySPI;
    VICVectAddr9  = (INT32U)VIC_DummyRTC;
    VICVectAddr10 = (INT32U)VIC_DummyEINT0;
    VICVectAddr11 = (INT32U)VIC_DummyEINT1;
    VICVectAddr12 = (INT32U)VIC_DummyEINT2;
}


void  VIC_Dummy (void)
{
    while (1) {
        (void)VIC_SpuriousInt;
    }
}


void  VIC_DummyWDT (void)
{
    VIC_SpuriousInt = VIC_WDT;
    VIC_Dummy();
}


void  VIC_DummyTIMER0 (void)
{
    VIC_SpuriousInt = VIC_TIMER0;
    VIC_Dummy();
}


void  VIC_DummyTIMER1 (void)
{
    VIC_SpuriousInt = VIC_TIMER1;
    VIC_Dummy();
}


void  VIC_DummyUART0 (void)
{
    VIC_SpuriousInt = VIC_UART0;
    VIC_Dummy();
}


void  VIC_DummyUART1 (void)
{
    VIC_SpuriousInt = VIC_UART1;
    VIC_Dummy();
}


void  VIC_DummyPWM0 (void)
{
    VIC_SpuriousInt = VIC_UART1;
    VIC_Dummy();
}


void  VIC_DummyI2C (void)
{
    VIC_SpuriousInt = VIC_I2C;
    VIC_Dummy();
}


void  VIC_DummySPI (void)
{
    VIC_SpuriousInt = VIC_I2C;
    VIC_Dummy();
}


void  VIC_DummyRTC (void)
{
    VIC_SpuriousInt = VIC_RTC;
    VIC_Dummy();
}


void  VIC_DummyEINT0 (void)
{
    VIC_SpuriousInt = VIC_EINT0;
    VIC_Dummy();
}


void  VIC_DummyEINT1 (void)
{
    VIC_SpuriousInt = VIC_EINT1;
    VIC_Dummy();
}


void  VIC_DummyEINT2 (void)
{
    VIC_SpuriousInt = VIC_EINT2;
    VIC_Dummy();
}

⌨️ 快捷键说明

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