📄 bsp.c
字号:
/*
*********************************************************************************************************
* IAR STR912-SK Board
* Board Support Package
*
*
* (c) Copyright 2006, Micrium, Weston, FL
* All Rights Reserved
*
*
* File : BSP.C
*********************************************************************************************************
*/
#define BSP_GLOBALS
#include "includes.h"
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define BSP_SRAM_SIZE_MASK 0xFFFFFFE7
#define BSP_WSR_AHB_MASK 0xFFFFFFFB
#define BSP_WSR_DTCM_MASK 0xFFFFFFFD
#define BSP_SRAM_LK_EN_MASK 0xFFFFFFDF
#define BSP_SRAM_SIZE 0x02
#define BSP_WSR_AHB_VAL 0
#define BSP_WSR_DTCM_VAL 0
#define BSP_SRAM_LK_EN_VAL 1
#define BSP_TMR0_PRESCALER 0x0030
#define BSP_VIC_CHANNELS 16
#define BSP_NBR_INT 32
/* PLL dividers and multipliers */
#define BSP_PLL_M 25
#define BSP_PLL_N 192
#define BSP_PLL_P 2
/* Tick interrupt priority */
#define BSP_TMR0_INT_PRIO 15
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
typedef void (*BSP_PFNCT)(void);
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
INT16U BSP_Tmr0_Cmp_Value;
static GPIO_InitTypeDef BSP_GPIOInit;
/*
*********************************************************************************************************
* PROTOTYPES
*********************************************************************************************************
*/
static void BSP_IO_Init(void);
static void Tmr_TickInit(void);
static void VIC_Init(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)
{
SCU_MCLKSourceConfig(SCU_MCLK_OSC);
SCU_PLLCmd(DISABLE);
SCU_PLLFactorsConfig(192,25,2);
SCU_PLLCmd(ENABLE);
SCU_RCLKDivisorConfig(SCU_RCLK_Div1); /* Set RCLK, the CPU clock's main divider */
SCU_PCLKDivisorConfig(SCU_PCLK_Div1); /* Set APBDIV, the PCLK divider */
SCU_FMICLKDivisorConfig(SCU_FMICLK_Div2);
SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2);
while(!(SCU->SYSSTATUS&SCU_FLAG_LOCK));
SCU_MCLKSourceConfig(SCU_MCLK_PLL);
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 */
// LCD_Init();
// LCD_Clr();
Tmr_TickInit(); /* Initialize the uC/OS-II tick interrupt */
//初始化延时所用的时钟
// halWait_TmrInit();
//初始化串口
UART_Configuration();
//初始化中断向量
// VIC_Configuration();
//初始化
// WIU_Configuration();
//初始化串行外设接口
// SPI_INIT();
}
/*
*********************************************************************************************************
* INITIALIZE INTERRUPT CONTROLLER
*
* Description : This function initializes the Vectored Interrupt Controller (VIC).
*
* Arguments : none
*********************************************************************************************************
*/
static void VIC_Init (void)
{
CPU_INT08U i;
CPU_INT32U int_src;
int_src = 0;
SCU_AHBPeriphClockConfig(__VIC, ENABLE); /* Enable the VIC's clock signal */
SCU_AHBPeriphReset(__VIC, DISABLE); /* Remove the VIC from reset state */
for (i = 0; i < BSP_VIC_CHANNELS; i++) {
VIC_ITCmd(int_src, DISABLE);
int_src++;
}
for (i = 0; i < BSP_VIC_CHANNELS; i++) {
VIC_ITCmd(int_src, DISABLE);
int_src++;
}
}
/*
*********************************************************************************************************
* DISABLE ALL INTERRUPTS
*
* Description : This function disables all interrupts from the interrupt controller.
*
* Arguments : none
*********************************************************************************************************
*/
void BSP_IntDisAll (void)
{
CPU_INT08U i;
for (i = 0; i < BSP_NBR_INT; i++) {
VIC_ITCmd(i, DISABLE);
}
}
/*
*********************************************************************************************************
* 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_ExceptHndlr (void)
{
BSP_PFNCT pfnct;
while (((VIC0->ISR) != 0) || ((VIC1->ISR) != 0)) {
/* Read the interrupt vector */
pfnct = (BSP_PFNCT)(VIC_GetCurrentISRAdd(VIC0));
if (pfnct != (BSP_PFNCT)0) { /* Make sure we don't have a NULL pointer */
(*pfnct)(); /* Execute the ISR for the interrupting device */
} else {
VIC0->VAR = 0x00000000; /* Signal the end of the interrupt */
VIC1->VAR = 0x00000000;
}
}
}
/*
*********************************************************************************************************
* 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)
{
}
/*
*********************************************************************************************************
* INITIALIZE I/Os
*
* Description : This function initializes the GPIO pins used by the application.
*
* Arguments : none
*********************************************************************************************************
*/
static void BSP_IO_Init (void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SCU_APBPeriphClockConfig(__GPIO9 ,ENABLE);
SCU_APBPeriphClockConfig(__GPIO3 ,ENABLE);
SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE);
SCU_APBPeriphClockConfig(__GPIO2 ,ENABLE);
SCU_APBPeriphClockConfig(__GPIO6 ,ENABLE);
SCU_APBPeriphClockConfig(__GPIO8 ,ENABLE);
//Enable CC2420 Interface
SCU_APBPeriphClockConfig(__GPIO4 ,ENABLE);
// Enable WIU clock
SCU_APBPeriphClockConfig(__WIU, ENABLE);
WIU_DeInit();
// Enable VIC clock
SCU_AHBPeriphClockConfig(__VIC,ENABLE);
VIC_DeInit();
//SSP
SCU_APBPeriphClockConfig(__SSP0 ,ENABLE);
//Enable UART0
SCU_APBPeriphClockConfig(__UART0, ENABLE);
GPIO_DeInit(GPIO8);
GPIO_DeInit(GPIO9);
GPIO_DeInit(GPIO3);
GPIO_DeInit(GPIO6);
GPIO_DeInit(GPIO2);
GPIO_DeInit(GPIO4);
GPIO_DeInit(GPIO0);
//L2
GPIO_StructInit(&BSP_GPIOInit);
BSP_GPIOInit.GPIO_Direction = GPIO_PinOutput;
BSP_GPIOInit.GPIO_Pin = GPIO_Pin_6;
BSP_GPIOInit.GPIO_Type = GPIO_Type_PushPull ;
GPIO_Init (GPIO9, &BSP_GPIOInit);
//L3
GPIO_StructInit(&BSP_GPIOInit);
BSP_GPIOInit.GPIO_Direction = GPIO_PinOutput;
BSP_GPIOInit.GPIO_Pin = GPIO_Pin_7;
BSP_GPIOInit.GPIO_Type = GPIO_Type_PushPull ;
BSP_GPIOInit.GPIO_Alternate = GPIO_OutputAlt1;
GPIO_Init (GPIO3, &BSP_GPIOInit);
//L4
GPIO_StructInit(&BSP_GPIOInit);
BSP_GPIOInit.GPIO_Direction = GPIO_PinOutput;
BSP_GPIOInit.GPIO_Pin = GPIO_Pin_1;
BSP_GPIOInit.GPIO_Type = GPIO_Type_PushPull ;
BSP_GPIOInit.GPIO_Alternate = GPIO_OutputAlt1;
GPIO_Init (GPIO0, &BSP_GPIOInit);
//L5
GPIO_StructInit(&BSP_GPIOInit);
BSP_GPIOInit.GPIO_Direction = GPIO_PinOutput;
BSP_GPIOInit.GPIO_Pin = GPIO_Pin_6;
BSP_GPIOInit.GPIO_Type = GPIO_Type_PushPull ;
BSP_GPIOInit.GPIO_Alternate = GPIO_OutputAlt1;
GPIO_Init (GPIO6, &BSP_GPIOInit);
//key
// GPIO_StructInit(&BSP_GPIOInit);
// BSP_GPIOInit.GPIO_Direction = GPIO_PinInput;
// BSP_GPIOInit.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;
// BSP_GPIOInit.GPIO_Type = GPIO_Type_PushPull ;
// BSP_GPIOInit.GPIO_Alternate = GPIO_OutputAlt1;
// GPIO_Init (GPIO9, &BSP_GPIOInit);
//Configure CC2420 Interface
//FIFOP FIFO
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_0;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_Init (GPIO6, &GPIO_InitStructure);
//CCA SFD
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_Init (GPIO4, &GPIO_InitStructure);
//RESET VREG_EN
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
GPIO_Init (GPIO4, &GPIO_InitStructure);
//Gonfigure SSP0_CLK, SSP0_MOSI, SSP0_nSS pins
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2 ;
GPIO_Init (GPIO2, &GPIO_InitStructure);
//SSP0_nSS pins
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1 ;
GPIO_Init (GPIO2, &GPIO_InitStructure);
//Gonfigure SSP0_MISO pin GPIO2.6
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ;
GPIO_Init (GPIO2, &GPIO_InitStructure);
//Gonfigure UART0_Rx pin GPIO3.0
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ;
GPIO_Init (GPIO3, &GPIO_InitStructure);
//Gonfigure UART0_Tx pin GPIO3.4
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3 ;
GPIO_Init (GPIO3, &GPIO_InitStructure);
}
/*
*********************************************************************************************************
* LED INITIALIZATION
*
* Description : This function initializes the board's LEDs.
*
* Arguments : none
*********************************************************************************************************
*/
void LED_Init (void)
{
LED_Off(0);
}
/*
*********************************************************************************************************
* 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 to turn on all of the board's LEDs
* 1 turn on LED1
* 2 turn on LED2
* .
* 16 turn on LED16
*********************************************************************************************************
*/
void LED_On (CPU_INT08U led)
{
switch (led) {
case 0:
GPIO_WriteBit(GPIO9, GPIO_Pin_6, Bit_SET);
GPIO_WriteBit(GPIO3, GPIO_Pin_7, Bit_SET);
GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET);
GPIO_WriteBit(GPIO6, GPIO_Pin_6, Bit_SET);
break;
case 1:
GPIO_WriteBit(GPIO9, GPIO_Pin_6, Bit_SET);
break;
case 2:
GPIO_WriteBit(GPIO3, GPIO_Pin_7, Bit_SET);
break;
case 3:
GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET);
break;
case 4:
GPIO_WriteBit(GPIO6, GPIO_Pin_6, Bit_SET);
break;
default:
break;
}
}
/*
*********************************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -