📄 bsp.c
字号:
/*
*********************************************************************************************************
* MICIRUM BOARD SUPPORT PACKAGE
*
* (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may not be used to write a similar
* product. This file may only be used in accordance with a license
* and should not be redistributed in any way.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* BOARD SUPPORT PACKAGE
*
* Atmel AT91SAM9260
* on the
* AT91SAM9260-EK Evaluation Board
*
* Filename : bsp.c
* Version : V1.00
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* #DEFINE CONSTANTS
*********************************************************************************************************
*/
#define BSP_XTAL_FREQ 18432000 /* Onboard crystal frequency (khz) */
#define BSP_RAM_REMAP_TEST_BYTE (*(CPU_INT08U *)0x00000030L)
#define GPIOB_TXD
#define GPIOB_RTXD (1 << 14)
#define GPIOB_DTXD (1 << 15)
#define GPIOC_USBCNX (1 << 5)
/*
*********************************************************************************************************
* MACROS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
typedef void (*BSP_PFNCT)(void);
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void BSP_DummyISR_Handler(void);
static void BSP_IntCtrlInit(void);
static void PLL_Init(void);
static void LED_Init(void);
static void PB_Init(void);
static void SDRAM_Init(void);
static void NANDFlash_Init(void);
static void Tmr_TickInit(void);
static void Tmr_TickISR_Handler(void);
/*
******************************************************************************************************************************
******************************************************************************************************************************
** Global Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* 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
*
* Returns : none
*********************************************************************************************************
*/
void BSP_Init (void)
{
AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS; /* Disable the Watchdog Timer */
LED_Init(); /* Initialize the I/Os for the LEDs */
PB_Init(); /* Initialize the I/Os for the Push Buttons */
PLL_Init(); /* Initialize the PLL and select it for MCLK */
BSP_IntCtrlInit(); /* Initialize the Interrupt Controller */
Tmr_TickInit(); /* Initialize uC/OS-II's Tick Rate */
}
/*
*********************************************************************************************************
* DETERMINE AND RETURN CPU OPERATING FREQUENCY
*
* Description : This function returns the CPU clock frequency, assuming the clock is driven by PLLB.
*
* Arguments : none
*
* Returns : The CPU clock frequency in hz.
*
* Notes : MCLK must be derived from PLLA for this to return the correct value of MCLK.
*********************************************************************************************************
*/
CPU_INT32U BSP_CPU_ClkFreq (void)
{
CPU_INT32U pll_mult;
CPU_INT32U pll_div;
CPU_INT32U mclk_div;
CPU_INT32U cpu_freq;
pll_mult = (AT91C_BASE_CKGR->CKGR_PLLBR & 0x07FF0000) >> 16;
pll_div = (AT91C_BASE_CKGR->CKGR_PLLBR & 0x000000FF) >> 0;
if (pll_div == 0) {
return (BSP_XTAL_FREQ); /* If the PLL mult is 0, then the PLL is disabled */
}
/* Read the Master Clock divider */
mclk_div = (AT91C_BASE_PMC->PMC_MCKR >> 2) & 0x07;
mclk_div = 1 << mclk_div; /* Convert 0-7 into 1, 2, 4, 8, 16, 32, or 64 */
if (mclk_div >= 128) { /* Divider pattern for 128 is reserved */
return (BSP_XTAL_FREQ);
}
cpu_freq = ((BSP_XTAL_FREQ / pll_div) / mclk_div) * (pll_mult + 1);
return (cpu_freq);
}
/*
*********************************************************************************************************
* 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 : ID, an identifier used to indicate what type of ARM exception has been triggered
* Possible ID values are shown below.
* OS_CPU_ARM_EXCEPT_RESET 0x00
* OS_CPU_ARM_EXCEPT_UNDEF_INSTR 0x01
* OS_CPU_ARM_EXCEPT_SWI 0x02
* OS_CPU_ARM_EXCEPT_PREFETCH_ABORT 0x03
* OS_CPU_ARM_EXCEPT_DATA_ABORT 0x04
* OS_CPU_ARM_EXCEPT_ADDR_ABORT 0x05
* OS_CPU_ARM_EXCEPT_IRQ 0x06
* OS_CPU_ARM_EXCEPT_FIQ 0x07
*********************************************************************************************************
*/
void OS_CPU_ExceptHndlr (CPU_INT32U except_id)
{
BSP_PFNCT pfnct;
if (except_id == OS_CPU_ARM_EXCEPT_IRQ) {
pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_IVR; /* Read the interrupt vector from the VIC */
if (pfnct != (BSP_PFNCT)0) { /* Make sure we don't have a NULL pointer */
(*pfnct)(); /* Execute the ISR for the interrupting device */
}
} else if (except_id == OS_CPU_ARM_EXCEPT_FIQ) {
pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_FVR; /* Read the interrupt vector from the VIC */
if (pfnct != (BSP_PFNCT)0) { /* Make sure we don't have a NULL pointer */
(*pfnct)(); /* Execute the ISR for the interrupting device */
}
}
}
/*
*********************************************************************************************************
* DISABLE ALL INTERRUPTS
*
* Description : This function is called to disable ALL interrupts.
*
* Argument(s) : none
*
* Returns : none
*********************************************************************************************************
*/
void BSP_IntDisAll (void)
{
AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF; /* Disable all interrupts */
}
/*
******************************************************************************************************************************
******************************************************************************************************************************
** PB, LED, and ADC Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* LED INITIALIZATION
*
* Description : This function initializes the LED I/O pins.
*
* Argument(s) : none
*
* Returns : none
*********************************************************************************************************
*/
void LED_Init (void)
{
AT91C_BASE_PIOA->PIO_PER = BSP_LED2 | BSP_LED1; /* Enable register */
AT91C_BASE_PIOA->PIO_OER = BSP_LED2 | BSP_LED1; /* Output enable */
AT91C_BASE_PIOA->PIO_IDR = BSP_LED2 | BSP_LED1; /* Disable LED pin interrupt */
LED_Off(BSP_LED_ALL); /* Turn OFF all the LEDs */
}
/*
*********************************************************************************************************
* LED ON
*
* Description : This function is used turn on any or all of 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
* 2 turns ON LED2 on the board
*
* Returns : none
*********************************************************************************************************
*/
void LED_On (CPU_INT08U led)
{
switch (led) {
case 0:
AT91C_BASE_PIOA->PIO_CODR = BSP_LED2 | BSP_LED1;
break;
case 1:
AT91C_BASE_PIOA->PIO_CODR = BSP_LED1;
break;
case 2:
AT91C_BASE_PIOA->PIO_CODR = BSP_LED2;
break;
}
}
/*
*********************************************************************************************************
* LED OFF
*
* Description : This function is used turn off any or all of 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
* 2 turns OFF LED2 on the board
*
* Returns : none
*********************************************************************************************************
*/
void LED_Off (CPU_INT08U led)
{
switch (led) {
case 0:
AT91C_BASE_PIOA->PIO_SODR = BSP_LED2 | BSP_LED1;
break;
case 1:
AT91C_BASE_PIOA->PIO_SODR = BSP_LED1;
break;
case 2:
AT91C_BASE_PIOA->PIO_SODR = BSP_LED2;
break;
}
}
/*
*********************************************************************************************************
* 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 toggle
* 0 indicates that you want ALL the LEDs to be toggle
* 1 toggles LED1 on the board
* 2 toggles LED2 on the board
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -