📄 bsp.c
字号:
* 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 to turn off all of the board's LEDs
* 1 turn off LED1
* 2 turn off LED2
* .
* 16 turn off LED16
*********************************************************************************************************
*/
void LED_Off (CPU_INT08U led)
{
switch (led) {
case 0:
GPIO_WriteBit(GPIO9, GPIO_Pin_6, Bit_RESET);
GPIO_WriteBit(GPIO3, GPIO_Pin_7, Bit_RESET);
GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET);
GPIO_WriteBit(GPIO6, GPIO_Pin_6, Bit_RESET);
break;
case 1:
GPIO_WriteBit(GPIO9, GPIO_Pin_6, Bit_RESET);
break;
case 2:
GPIO_WriteBit(GPIO3, GPIO_Pin_7, Bit_RESET);
break;
case 3:
GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET);
break;
case 4:
GPIO_WriteBit(GPIO6, GPIO_Pin_6, Bit_RESET);
break;
default:
break;
}
}
/*
*********************************************************************************************************
* LED TOGGLE
*
* Description : This function is used to alternate the state of an LED
*
* Arguments : led is the number of the LED to control
* 0 indicates that you want ALL the LEDs to toggle
* 1 toggle LED1
* 2 toggle LED2
* .
* 16 toggle LED16
*********************************************************************************************************
*/
void LED_Toggle (CPU_INT08U led)
{
switch (led) {
case 0:
GPIO_WriteBit(GPIO9, GPIO_Pin_6, (BitAction)((1-GPIO_ReadBit(GPIO9, GPIO_Pin_6))));
GPIO_WriteBit(GPIO3, GPIO_Pin_7, (BitAction)((1-GPIO_ReadBit(GPIO3, GPIO_Pin_7))));
GPIO_WriteBit(GPIO0, GPIO_Pin_1, (BitAction)((1-GPIO_ReadBit(GPIO0, GPIO_Pin_1))));
GPIO_WriteBit(GPIO6, GPIO_Pin_6, (BitAction)((1-GPIO_ReadBit(GPIO6, GPIO_Pin_6))));
break;
case 1:
GPIO_WriteBit(GPIO9, GPIO_Pin_6, (BitAction)((1-GPIO_ReadBit(GPIO9, GPIO_Pin_6))));
break;
case 2:
GPIO_WriteBit(GPIO3, GPIO_Pin_7, (BitAction)((1-GPIO_ReadBit(GPIO3, GPIO_Pin_7))));
break;
case 3:
GPIO_WriteBit(GPIO0, GPIO_Pin_1, (BitAction)((1-GPIO_ReadBit(GPIO0, GPIO_Pin_1))));
break;
case 4:
GPIO_WriteBit(GPIO6, GPIO_Pin_6, (BitAction)((1-GPIO_ReadBit(GPIO6, GPIO_Pin_6))));
break;
default:
break;
}
}
/*
*********************************************************************************************************
* GET 'PUSH BUTTON' STATUS
*
* Description : This function is used to get the status of any push button on the board.
*
* Arguments : push_button is the number of the push button to probe
* 1 probe the push button B1
* 2 probe the push button B2
*********************************************************************************************************
*/
BOOLEAN PB_GetStatus (INT8U push_button_id)
{
BOOLEAN status;
status = OS_FALSE;
switch (push_button_id) {
case 1:
if ((GPIO_ReadBit(GPIO9, GPIO_Pin_5)) == Bit_SET) {
status = OS_TRUE;
}
break;
case 2:
if ((GPIO_ReadBit(GPIO9, GPIO_Pin_7)) == Bit_SET) {
status = OS_TRUE;
}
break;
default:
break;
}
return (status);
}
/*
*********************************************************************************************************
* 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
*********************************************************************************************************
*/
static void Tmr_TickInit (void)
{
CPU_INT32U pclk_freq;
SCU_APBPeriphClockConfig(__TIM01, ENABLE); /* Enable the timer's clock signal */
SCU_APBPeriphReset(__TIM01, DISABLE); /* Remove the timer from reset state */
TIM_DeInit(TIM0); /* Return the timer's registers to default values */
/* Set up the timer's interrupt */
VIC_Config(TIM0_ITLine, (VIC_ITLineMode)VIC_IRQ, BSP_TMR0_INT_PRIO);
VIC_ITCmd(TIM0_ITLine, ENABLE);
pclk_freq = SCU_GetPCLKFreqValue();
pclk_freq *= 1000;
/* Calculate the required period */
BSP_Tmr0_Cmp_Value = (pclk_freq / BSP_TMR0_PRESCALER) / OS_TICKS_PER_SEC;
TIM0->OC1R = BSP_Tmr0_Cmp_Value; /* Set the output compare register */
/* Set the timer's prescaler */
TIM_PrescalerConfig(TIM0, (BSP_TMR0_PRESCALER - 1));
TIM_ITConfig(TIM0, TIM_IT_OC1, ENABLE); /* Enable the interrupt */
TIM_CounterCmd(TIM0, TIM_START); /* Start the timer */
}
/*
*********************************************************************************************************
* INITIALIZE TIMER FOR halWait
*
* Description : This function is called to by uC/OS-View to initialize the free running timer that is
* used to make time measurements.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
void halWait_TmrInit (void)
{
TIM_DeInit(TIM1); /* Ensure that TIM1 registers are at reset values */
TIM_CounterCmd(TIM1, TIM_START); /* Start the timer */
}
/*
*********************************************************************************************************
* halWait
*
* Description : 延时xx微秒
*
*
* Arguments : u32 timeout
*
* Returns : none
*********************************************************************************************************
*/
void halWait(u32 timeout) {
u32 tim1_freq;
u32 dly_period;
u32 tmr_start_val;
u32 tmr_cur_val;
u32 ms_dly;
if (timeout < 1000) {
tmr_start_val = TIM_GetCounterValue(TIM1);
tim1_freq = SCU_GetPCLKFreqValue();
tim1_freq /= 2; /* The default TIM1 divider of 2 is being used */
dly_period = (u16)((tim1_freq / 1000) * timeout);
tmr_cur_val = TIM_GetCounterValue(TIM1);
while (((u16)(tmr_cur_val - tmr_start_val)) < dly_period) {
tmr_cur_val = TIM_GetCounterValue(TIM1);
}
} else {
ms_dly = timeout / 1000;
OSTimeDlyHMSM(0,0,0,ms_dly);
}
} // halWait
/*
*********************************************************************************************************
* 设置外部中断
*
* Description : 外部中断初始化
*
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
void VIC_Configuration(void)
{
// Configure the External interrupt group 2 priority
VIC_Config(EXTIT2_ITLine, VIC_IRQ, 0);
//VIC_ITCmd(EXTIT2_ITLine, ENABLE);
}
void WIU_Configuration(void)
{
WIU_InitTypeDef WIU_InitStructure;
WIU_ClearITPendingBit(WIU_Line17);
// WIU_InitStructure.WIU_Mode = WIU_Mode_Interrupt ;
WIU_InitStructure.WIU_Line = WIU_Line17 ;
WIU_InitStructure.WIU_TriggerEdge = WIU_RisingEdge ;
WIU_Init(&WIU_InitStructure);
SCU_WakeUpLineConfig(17);
}
/*
*********************************************************************************************************
* READ TIMER USED TO MEASURE INTERRUPT DISABLE TIME
*
* Description : This function is called to read the current counts of the interrupt disable time
* measurement timer.
*
* Arguments : none
*
* Returns : The 16 bit counts of the timer assuming the timer is an UP counter.
*********************************************************************************************************
*/
#if OS_CPU_INT_DIS_MEAS_EN > 0
CPU_INT16U OS_CPU_IntDisMeasTmrRd (void)
{
}
#endif
/*
*********************************************************************************************************
* SPI_INIT
*
* Description : This function prepares SSP0 FOR CC2420
*
* Arguments : None.
*
* Returns : None.
*********************************************************************************************************
*/
void SPI_INIT(void){
SSP_InitTypeDef SSP_InitStructure;
/* SSP0 configuration */
SSP_DeInit(SSP0);
SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola;
SSP_InitStructure.SSP_Mode = SSP_Mode_Master;
SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low;
SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge;
SSP_InitStructure.SSP_DataSize = SSP_DataSize_8b;
//SSP_InitStructure.SSP_ClockRate = 5;
SSP_InitStructure.SSP_ClockPrescaler = 0xc;
SSP_Init(SSP0, &SSP_InitStructure);
/* SSP0 enable */
SSP_Cmd(SSP0, ENABLE);
}
/*
*********************************************************************************************************
* UART_Configuration
*
* Description : This function prepares UART0 for display
*
* Arguments : None.
*
* Returns : None.
*********************************************************************************************************
*/
void UART_Configuration(void)
{
UART_InitTypeDef UART_InitStructure;
UART_InitStructure.UART_WordLength = UART_WordLength_8D;
UART_InitStructure.UART_StopBits = UART_StopBits_1;
UART_InitStructure.UART_Parity = UART_Parity_No ;
UART_InitStructure.UART_BaudRate = 115200;
UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;
UART_InitStructure.UART_FIFO = UART_FIFO_Enable;
UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2;
UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2;
UART_DeInit(UART0);
UART_Init(UART0, &UART_InitStructure);
UART_Cmd(UART0, ENABLE);
}
/*
*********************************************************************************************************
* Ser_WrByte
*
* Description : Transmit a single byte using UART0
*
* Arguments : The byte that should be transmitted.
*
* Returns : None.
*********************************************************************************************************
*/
void Ser_WrByte (CPU_INT08U tx_byte)
{
CPU_INT16U tx_flag;
tx_flag = UART0->FR;
while ((tx_flag & 0x0020) != 0) { /* Wait for an empty entry in the Tx FIFO */
tx_flag = UART0->FR;
}
UART_SendData(UART0, tx_byte);
}
/*
*********************************************************************************************************
* Ser_WrStr
*
* Description : Transmits a string using UART0
*
* Arguments : The string that will be transmitted.
*
* Returns : None.
*********************************************************************************************************
*/
void Ser_WrStr (CPU_CHAR *tx_str)
{
while ((*tx_str) != 0) {
Ser_WrByte(*tx_str++);
}
}
/*
*********************************************************************************************************
* Ser_RdByte
*
* Description : Receive a single byte using UART0
*
* Arguments : None.
*
* Returns : The received byte
*********************************************************************************************************
*/
CPU_INT08U Ser_RdByte (void)
{
CPU_INT16U rx_flag;
CPU_INT08U rx_byte;
rx_flag = UART0->FR;
while ((rx_flag & 0x0010) != 0) { /* Wait for a byte to appear in the FIFO */
OSTimeDly(5);
rx_flag = UART0->FR;
}
rx_byte = UART_ReceiveData(UART0);
return (rx_byte);
}
/*
*********************************************************************************************************
* Ser_Printf
*
* Description : Formatted outout to the serial port.
* This funcion reads a string from a serial port. This call blocks until a
* character appears at the port and the last character is a Carriage
* Return (0x0D).
*
* Arguments : Format string follwing the C format convention.
*
* Returns : None.
*********************************************************************************************************
*/
void Ser_Printf (CPU_CHAR *format, ...)
{
static CPU_CHAR buffer[80 + 1];
va_list vArgs;
va_start(vArgs, format);
vsprintf((char *)buffer, (char const *)format, vArgs);
va_end(vArgs);
Ser_WrStr((CPU_CHAR*) buffer);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -