📄 bsp.c
字号:
return (status);
}
/*
*********************************************************************************************************
* LED INITIALIZATION
*
* Description : This function initializes the board's LEDs
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
static void LED_Init (void)
{
GPIO_InitTypeDef gpio_init;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
gpio_init.GPIO_Pin = GPIOC_LED1 | GPIOC_LED2 | GPIOC_LED3 | GPIOC_LED4;
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
gpio_init.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &gpio_init);
}
/*
*********************************************************************************************************
* 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 on the board
*
* Returns : none
*********************************************************************************************************
*/
void LED_On (CPU_INT08U led)
{
switch (led) {
case 0:
GPIO_SetBits(GPIOC, GPIOC_LED1 | GPIOC_LED2 | GPIOC_LED3 | GPIOC_LED4);
break;
case 1:
GPIO_SetBits(GPIOC, GPIOC_LED1);
break;
case 2:
GPIO_SetBits(GPIOC, GPIOC_LED2);
break;
case 3:
GPIO_SetBits(GPIOC, GPIOC_LED3);
break;
case 4:
GPIO_SetBits(GPIOC, GPIOC_LED4);
break;
default:
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 LED on the board
*
* Returns ; none
*********************************************************************************************************
*/
void LED_Off (CPU_INT08U led)
{
switch (led) {
case 0:
GPIO_ResetBits(GPIOC, GPIOC_LED1 | GPIOC_LED2 | GPIOC_LED3 | GPIOC_LED4);
break;
case 1:
GPIO_ResetBits(GPIOC, GPIOC_LED1);
break;
case 2:
GPIO_ResetBits(GPIOC, GPIOC_LED2);
break;
case 3:
GPIO_ResetBits(GPIOC, GPIOC_LED3);
break;
case 4:
GPIO_ResetBits(GPIOC, GPIOC_LED4);
break;
default:
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 control
* 0 indicates that you want to toggle ALL the LEDs
* 1 toggles user LED on the board
*
* Returns ; none
*********************************************************************************************************
*/
void LED_Toggle (CPU_INT08U led)
{
CPU_INT32U pins;
pins = GPIO_ReadOutputData(GPIOC);
switch (led) {
case 0:
if ((pins & GPIOC_LED1) == 0) {
GPIO_SetBits( GPIOC, GPIOC_LED1);
} else {
GPIO_ResetBits(GPIOC, GPIOC_LED1);
}
if ((pins & GPIOC_LED2) == 0) {
GPIO_SetBits( GPIOC, GPIOC_LED2);
} else {
GPIO_ResetBits(GPIOC, GPIOC_LED2);
}
if ((pins & GPIOC_LED3) == 0) {
GPIO_SetBits( GPIOC, GPIOC_LED3);
} else {
GPIO_ResetBits(GPIOC, GPIOC_LED3);
}
if ((pins & GPIOC_LED4) == 0) {
GPIO_SetBits( GPIOC, GPIOC_LED4);
} else {
GPIO_ResetBits(GPIOC, GPIOC_LED4);
}
break;
case 1:
if ((pins & GPIOC_LED1) == 0) {
GPIO_SetBits( GPIOC, GPIOC_LED1);
} else {
GPIO_ResetBits(GPIOC, GPIOC_LED1);
}
break;
case 2:
if ((pins & GPIOC_LED2) == 0) {
GPIO_SetBits( GPIOC, GPIOC_LED2);
} else {
GPIO_ResetBits(GPIOC, GPIOC_LED2);
}
break;
case 3:
if ((pins & GPIOC_LED3) == 0) {
GPIO_SetBits( GPIOC, GPIOC_LED3);
} else {
GPIO_ResetBits(GPIOC, GPIOC_LED3);
}
break;
case 4:
if ((pins & GPIOC_LED4) == 0) {
GPIO_SetBits( GPIOC, GPIOC_LED4);
} else {
GPIO_ResetBits(GPIOC, GPIOC_LED4);
}
break;
default:
break;
}
}
/*
******************************************************************************************************************************
******************************************************************************************************************************
* uC/Probe Plug-In for uC/OS-II Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* INITIALIZE TIMER FOR uC/Probe Plug-In for uC/OS-II
*
* Description : This function is called to by uC/Probe Plug-In for uC/OS-II to initialize the
* free running timer that is used to make time measurements.
*
* Arguments : none
*
* Returns : none
*
* Note(s) : This function is EMPTY because the timer is initialized elsewhere.
*********************************************************************************************************
*/
#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN == 1)
void OSProbe_TmrInit (void)
{
TIM_TimeBaseInitTypeDef tim_init;
#if (OS_PROBE_TIMER_SEL == 2)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
tim_init.TIM_Period = 0xFFFF;
tim_init.TIM_Prescaler = 0x00;
tim_init.TIM_ClockDivision = 0x0;
tim_init.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &tim_init);
TIM_SetCounter(TIM2, 0);
TIM_PrescalerConfig(TIM2, 256, TIM_PSCReloadMode_Immediate);
TIM_Cmd(TIM2, ENABLE);
#elif (OS_PROBE_TIMER_SEL == 3)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
tim_init.TIM_Period = 0xFFFF;
tim_init.TIM_Prescaler = 0x00;
tim_init.TIM_ClockDivision = 0x0;
tim_init.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &tim_init);
TIM_SetCounter(TIM3, 0);
TIM_PrescalerConfig(TIM3, 256, TIM_PSCReloadMode_Immediate);
TIM_Cmd(TIM3, ENABLE);
#elif (OS_PROBE_TIMER_SEL == 4)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
tim_init.TIM_Period = 0xFFFF;
tim_init.TIM_Prescaler = 0x00;
tim_init.TIM_ClockDivision = 0x0;
tim_init.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &tim_init);
TIM_SetCounter(TIM4, 0);
TIM_PrescalerConfig(TIM4, 256, TIM_PSCReloadMode_Immediate);
TIM_Cmd(TIM4, ENABLE);
#endif
}
#endif
/*
*********************************************************************************************************
* READ TIMER FOR uC/Probe Plug-In for uC/OS-II
*
* Description : This function is called to read the current counts of a 16 bit free running timer.
*
* Arguments : none
*
* Returns : The 16 or 32 bit count of the timer assuming the timer is an UP counter.
*********************************************************************************************************
*/
#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN == 1)
CPU_INT32U OSProbe_TmrRd (void)
{
#if (OS_PROBE_TIMER_SEL == 2)
return ((CPU_INT32U)TIM_GetCounter(TIM2));
#elif (OS_PROBE_TIMER_SEL == 3)
return ((CPU_INT32U)TIM_GetCounter(TIM3));
#elif (OS_PROBE_TIMER_SEL == 4)
return ((CPU_INT32U)TIM_GetCounter(TIM4));
#endif
}
#endif
/*
******************************************************************************************************************************
******************************************************************************************************************************
** uC/OS-II Timer Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* 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)
{
RCC_ClocksTypeDef rcc_clocks;
CPU_INT32U cnts;
RCC_GetClocksFreq(&rcc_clocks);
cnts = (CPU_INT32U)rcc_clocks.HCLK_Frequency / OS_TICKS_PER_SEC;
SysTick_SetReload(cnts);
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
SysTick_CounterCmd(SysTick_Counter_Enable);
SysTick_ITConfig(ENABLE);
}
/*
*********************************************************************************************************
* TIMER 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)
{
OS_CPU_SR cpu_sr;
OS_ENTER_CRITICAL(); /* Tell uC/OS-II that we are starting an ISR */
OSIntNesting++;
OS_EXIT_CRITICAL();
OSTimeTick(); /* Call uC/OS-II's OSTimeTick() */
OSIntExit(); /* Tell uC/OS-II that we are leaving the ISR */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -