📄 bsp.c
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 2003, Micrium, Inc., Weston, FL
* (c) Copyright 2003, JIDEC Consultants, Sherbrooke, QC
* All Rights Reserved
*
* Cogent CSB335
* Board Support Package
*
* File : BSP.C
* Originally by: Jean J. Labrosse
* Modified by : Jean-Denis Hatier
*
*********************************************************************************************************
*/
#include <includes.h>/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define UMON_ENTRY_POINT (*(INT32U *) 0x40000050L)
#define LED_PORT (*(volatile INT8U *)0x44000080L)#define PB_PORT (*(volatile INT8U *)0x44000080L)
#define LH79520_CLK 51609600L
#define DEFAULT_STK_SIZE 2048
#define EXCEPT_STK_SIZE 2048
/*********************************************************************************************************** GLOBAL VARIABLES**********************************************************************************************************/static INT8U LED_Image; INT8U *punDefaultStackTop; INT8U *punExceptStackTop;/*********************************************************************************************************** PROTOTYPES**********************************************************************************************************/void BSP_InitIntCtrl(void);void SetStackPointers(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){ static INT8U aunDefaultStack[DEFAULT_STK_SIZE]; static INT8U aunExceptStack[EXCEPT_STK_SIZE]; punDefaultStackTop = &aunDefaultStack[DEFAULT_STK_SIZE - 1]; punExceptStackTop = &aunExceptStack[EXCEPT_STK_SIZE - 1]; VIC->intenclear = 0xFFFFFFFFL; /* Disable ALL interrupts */ RCPC->remap = 0x00000001L; /* Remap SRAM to 0x00000000 */ RCPC->periphclkctrl = 0x00000000L; /* Initialize the peripheral clock control */ RCPC->spareclkctrl = 0x00000000L;
BSP_InitIntCtrl(); /* Initialize the interrupt controller */ SetStackPointers(); /* Initialize the default and exception stacks */ monConnect(UMON_ENTRY_POINT, NULL, NULL); /* Initialize monitor services */
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**********************************************************************************************************/void BSP_InitIntCtrl (void){ VIC->intenclear = 0xFFFFFFFFL; /* Disable ALL interrupts */ /* 0xE51FFFF0L is opcode of (ldr pc,[pc,#-0xff0]) */ *(INT32U *)0x00000018L = 0xE51FFFF0L; /* IRQ exception vector - install redirection to 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).** We decided to use Timer #0 as the tick interrupt source.** Arguments : none** Notes :**********************************************************************************************************/void Tmr_TickInit (void){ /* Initialize the timer to generate 100 Hz */ TIMER0->load = LH79520_CLK / 16 / 100; TIMER0->control = TMRCTRL_ENABLE | TMRCTRL_MODE_PERIODIC | TMRCTRL_PRESCALE16; TIMER0->clear = 0; /* Setup the interrupt vector for the tick ISR */ /* Timer interrupt is a medium priority */ VIC->vectaddr[VIC_VECT_0] = (INT32U)OS_CPU_Tick_ISR; VIC->vectcntl[VIC_VECT_0] = VIC_VECTCNTL_ENABLE | VIC_TIMER0; VIC->intenable = _BIT(VIC_TIMER0);}/*********************************************************************************************************** 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_TickHandler (void){ TIMER0->clear = 0x00000000L; /* Clear the tick interrupt source */ VIC->vectoraddr = 0x00000000L; /* Clear the vector address register */ OSTimeTick(); /* If the interrupt is from the tick source, */ /* call OSTimeTick() */}/*********************************************************************************************************** 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_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 User LED 0 on the board* .* .* 3 turns ON User LED 2 on the board**********************************************************************************************************/void LED_On (INT8U led){ switch (led) { case 0: LED_Image = 0x00; LED_PORT = LED_Image; break; case 1: LED_Image &= ~0x01; LED_PORT = LED_Image; break; case 2: LED_Image &= ~0x02; LED_PORT = LED_Image; break; case 3: LED_Image &= ~0x04; LED_PORT = LED_Image; break; }}/*********************************************************************************************************** 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){ switch (led) { case 0: LED_Image = 0x07; LED_PORT = LED_Image; break; case 1: LED_Image |= 0x01; LED_PORT = LED_Image; break; case 2: LED_Image |= 0x02; LED_PORT = LED_Image; break; case 3: LED_Image |= 0x04; LED_PORT = LED_Image; break; }}/*********************************************************************************************************** GET PUSH BUTTON STATUS** Description : This function is used to get the status of any push button on the board.** Arguments : pushbutton is the number of the push button to probe* 1 probe the push button 0* .* .* 3 probe the push button 2**********************************************************************************************************/BOOLEAN GetPushButtonStatus (INT8U pushbutton){ BOOLEAN pbStatus = FALSE; switch (pushbutton) { case 1: pbStatus = ((PB_PORT & 0x01) == 0); break; case 2: pbStatus = ((PB_PORT & 0x02) == 0); break; case 3: pbStatus = ((PB_PORT & 0x04) == 0); break; } return pbStatus;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -