📄 bsp.c
字号:
* MAM_Init()
*
* Description: This function initializes the memory acceleration module.
*
* Arguments : None
*
* Returns : None
*********************************************************************************************************
*/
static void BSP_MAM_Init (void)
{
MAMCR = 0x00; /* Disable the Memory Accelerator Module */
MAMTIM = 0x03; /* MAM fetch cycles are 3 CCLKs in duration */
MAMCR = 0x02; /* Enable the Memory Accelerator Module */
}
/*
*********************************************************************************************************
* EXCEPTION HANDLER
*
* Description : This function should be used to handle any exceptions. It is called by
* OS_CPU_ARM_EXCEPT_HANDLER(), which is declared in os_cpu_a.s
*
* Arguments : none
*********************************************************************************************************
*/
void OS_CPU_ExceptHndlr (CPU_INT32U except_id)
{
PFNCT pfnct;
pfnct = (PFNCT)VICVectAddr; /* Read the interrupt vector from the VIC */
while (pfnct != (PFNCT)0) { /* Make sure we don't have a NULL pointer */
(*pfnct)(); /* Execute the ISR for the interrupting device */
pfnct = (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
*
* 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 peripheral_clk_freq;
/* VIC TIMER #0 Initialization */
VICIntSelect &= ~(1 << VIC_TIMER0); /* Enable interrupts */
VICVectAddr2 = (CPU_INT32U)Tmr_TickISR_Handler; /* Set the vector address */
VICVectCntl2 = 0x20 | VIC_TIMER0; /* Enable vectored interrupts */
VICIntEnable = (1 << VIC_TIMER0); /* Enable Interrupts */
peripheral_clk_freq = BSP_CPU_ClkFreqPeripheral();
Tmr_ReloadCnts = peripheral_clk_freq / OS_TICKS_PER_SEC;
T0TCR = 0; /* Disable timer 0. */
T0PC = 0; /* Prescaler is set to no division. */
T0MR0 = Tmr_ReloadCnts;
T0MCR = 3; /* Interrupt on MR0 (reset TC) */
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
*
* 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)
{
T0IR = 0xFF; /* Clear timer #0 interrupt */
/* Reload 'relative' to current interrupt time */
T0MR0 = Tmr_ReloadCnts;
if( ++ComCount>150 )
{
ComCount = 0;
ComState = Header;
}
VICVectAddr = 0;
OSTimeTick(); /* Call uC/OS-II's OSTimeTick() */
}
/*
*********************************************************************************************************
* Vectored Interrupt Controller
*********************************************************************************************************
*/
static void VIC_Init (void)
{
VICIntEnClr = 0xFFFFFFFF; /* Disable ALL interrupts */
VICProtection = 0; /* Setup interrupt controller */
VICVectAddr1 = (CPU_INT32U)VIC_DummyWDT; /* Set the vector address */
VICVectAddr2 = (CPU_INT32U)VIC_DummyTIMER0;
VICVectAddr3 = (CPU_INT32U)VIC_DummyTIMER1;
VICVectAddr4 = (CPU_INT32U)VIC_DummyUART0;
VICVectAddr5 = (CPU_INT32U)VIC_DummyUART1;
VICVectAddr6 = (CPU_INT32U)VIC_DummyPWM0;
VICVectAddr7 = (CPU_INT32U)VIC_DummyI2C;
VICVectAddr8 = (CPU_INT32U)VIC_DummySPI;
VICVectAddr9 = (CPU_INT32U)VIC_DummyRTC;
VICVectAddr10 = (CPU_INT32U)VIC_DummyEINT0;
VICVectAddr11 = (CPU_INT32U)VIC_DummyEINT1;
VICVectAddr12 = (CPU_INT32U)VIC_DummyEINT2;
}
static void VIC_Dummy (void)
{
while (1) {
(void)VIC_SpuriousInt;
}
}
static void VIC_DummyWDT (void)
{
VIC_SpuriousInt = VIC_WDT;
VIC_Dummy();
}
static void VIC_DummyTIMER0 (void)
{
VIC_SpuriousInt = VIC_TIMER0;
VIC_Dummy();
}
static void VIC_DummyTIMER1 (void)
{
VIC_SpuriousInt = VIC_TIMER1;
VIC_Dummy();
}
static void VIC_DummyUART0 (void)
{
VIC_SpuriousInt = VIC_UART0;
VIC_Dummy();
}
static void VIC_DummyUART1 (void)
{
VIC_SpuriousInt = VIC_UART1;
VIC_Dummy();
}
static void VIC_DummyPWM0 (void)
{
VIC_SpuriousInt = VIC_UART1;
VIC_Dummy();
}
static void VIC_DummyI2C (void)
{
VIC_SpuriousInt = VIC_I2C;
VIC_Dummy();
}
static void VIC_DummySPI (void)
{
VIC_SpuriousInt = VIC_SPI;
VIC_Dummy();
}
static void VIC_DummyRTC (void)
{
VIC_SpuriousInt = VIC_RTC;
VIC_Dummy();
}
static void VIC_DummyEINT0 (void)
{
VIC_SpuriousInt = VIC_EINT0;
VIC_Dummy();
}
static void VIC_DummyEINT1 (void)
{
VIC_SpuriousInt = VIC_EINT1;
VIC_Dummy();
}
static void VIC_DummyEINT2 (void)
{
VIC_SpuriousInt = VIC_EINT2;
VIC_Dummy();
}
/*
*********************************************************************************************************
* Tmr1_Init()
*
* Description : This function is called to initialize a second timer
*
* Arguments : None
*
* Returns : None
*********************************************************************************************************
*/
void Tmr1_Init (void)
{
T1PR = 0;
T1TCR = 0x00000001; /* Enable the timer */
}
/*
*********************************************************************************************************
* Tmr1_Init()
*
* Description : Uses the second timer to produce a short delay
*
* Arguments : dly The number of microseconds for which to delay
*
* Returns : None
*********************************************************************************************************
*/
void Tmr1_Dly (CPU_INT32U dly)
{
CPU_INT32U original_val;
CPU_INT32U current_val;
CPU_INT32U dly_cycles;
CPU_INT32U mult;
original_val = T1TC;
mult = (BSP_CPU_ClkFreqPeripheral()) / 1000000;
dly_cycles = mult * dly;
current_val = T1TC;
while ((current_val - original_val) < dly_cycles)
{
current_val = T1TC;
}
}
/*
*********************************************************************************************************
* SPI_Init()
*
* Description: This function initializes the SSP Controller
*
* Arguments : None
*
* Returns : None
*********************************************************************************************************
*/
void SPI_Init (void)
{
#if (BSP_CFG_SPI == BSP_USE_SPI) /* SSP Controller */
CPU_INT32U pin_status;
CPU_INT32U power_status;
CPU_INT32U io_dir;
power_status = PCONP;
power_status |= 0x00000400;
PCONP = power_status;
/* SSEL is left as a GPIO pin */
pin_status = PINSEL1;
pin_status &= 0xFFFFFCAB;
pin_status |= 0x000000A8;
PINSEL1 = pin_status;
io_dir = FIO0DIR;
io_dir |= 0x00100000;
FIO0DIR = io_dir;
SSPCPSR = 0x0000001E; /* Use a clock rate of 400 kHz */
SSPCR0 = 0x000001C7; /* 8-bit data transfers will be used */
SSPCR1 = 0x00000002; /* Enable the SSP Controller */
#endif
#if (BSP_CFG_SPI == BSP_USE_GPIO) /* GPIO Pins using fast GPIO registers */
CPU_INT32U pin_status;
CPU_INT32U io_dir;
pin_status = PINSEL1; /* Initialize the appropriate pins */
pin_status &= 0xFFFFFC03;
PINSEL1 = pin_status;
io_dir = FIO0DIR;
io_dir |= 0x001A0000;
io_dir &= 0xFFFBFFFF;
FIO0DIR = io_dir;
#endif
}
/*
*********************************************************************************************************
* ExtInt0()
*
* Description: This function initializes the ExtInt0
*
* Arguments : None
*
* Returns : None
*********************************************************************************************************
*/
static void Ext0_Init (void)
{
/* VIC Ext #0 Initialization */
VICIntSelect &= ~(1 << VIC_EINT0); /* Enable interrupts */
VICVectAddr10 = (CPU_INT32U)Ext0_Init_Handler; /* Set the vector address */
VICVectCntl10 = 0x20 | VIC_EINT0; /* Enable vectored interrupts */
VICIntEnable = (1 << VIC_EINT0); /* Enable Interrupts */
PINSEL1 |= 0x00000001; /* set P0.16 as EINT0 */
EXTMODE = 0x00000001; /* INT0 edge trigger */
EXTPOLAR = 1; /* INT0 is falling edge by default */
}
/*
*********************************************************************************************************
* Ext0_Init #0 IRQ HANDLER
*
* Description : This function handles the Ext0_Init interrupt that is used to generate TICKs for uC/OS-II.
*
* Arguments : none
*
* Note(s) :
*********************************************************************************************************
*/
void Ext0_Init_Handler (void)
{
static int flag = 0;
EXTINT = 0x00000001; /* clear interrupt */
flag ++;
if( (flag % 2) == 0 )
LED_Off(0);
else
LED_On(0);
EXTINT = 0x00000001; /* clear interrupt */
VICVectAddr = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -