📄 bsp.c
字号:
*/
void LED_Off (CPU_INT08U led)
{
switch (led) {
case 0:
case 1:
GPIOPinWrite(GPIO_PORTF_BASE, GPIOF_PWM0, 1);
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;
switch (led) {
case 0:
case 1:
pins = GPIOPinRead(GPIO_PORTF_BASE, GPIOF_PWM0);
if ((pins & GPIOF_PWM0) == 0) {
GPIOPinWrite(GPIO_PORTF_BASE, GPIOF_PWM0, 1);
} else {
GPIOPinWrite(GPIO_PORTF_BASE, GPIOF_PWM0, 0);
}
break;
default:
break;
}
}
/*
*********************************************************************************************************
* BUZZER INITIALIZATION
*
* Description : This function initializes the buzzer on the board.
*
* Arguments : none
*
* Returns ; none
*********************************************************************************************************
*/
static void Buzzer_Init (void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
PWMOutputState(PWM_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, 0);
PWMGenDisable(PWM_BASE, PWM_GEN_0);
GPIOPinTypePWM(GPIO_PORTD_BASE, GPIOD_PWM1);
PWMGenConfigure(PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenEnable(PWM_BASE, PWM_GEN_0);
PWMGenPeriodSet( PWM_BASE, PWM_GEN_0, 0x4000);
PWMPulseWidthSet(PWM_BASE, PWM_OUT_1, 0x400);
}
/*
*********************************************************************************************************
* BUZZER ON
*
* Description : This function is used to turn on the buzzer.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
void Buzzer_On (void)
{
PWMOutputState(PWM_BASE, PWM_OUT_1_BIT, 1);
}
/*
*********************************************************************************************************
* BUZZER OFF
*
* Description : This function is used to turn off the buzzer.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
void Buzzer_Off (void)
{
PWMOutputState(PWM_BASE, PWM_OUT_1_BIT, 0);
}
/*
*********************************************************************************************************
* BUZZER LEVEL
*
* Description : This function is used to set the level of the buzzer.
*
* Arguments : level is an integer between 0 and 100, the percentage of "ON" time of the PWM.
*
* Returns : none
*********************************************************************************************************
*/
void Buzzer_SetLevel (CPU_INT08U level)
{
CPU_INT16U period;
CPU_INT16U width;
if (level > 100) {
return;
}
period = PWMGenPeriodGet( PWM_BASE, PWM_GEN_0);
width = period * level / 100;
PWMPulseWidthSet(PWM_BASE, PWM_OUT_1, width);
}
/*
******************************************************************************************************************************
******************************************************************************************************************************
* 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)
{
#if (OS_PROBE_TIMER_SEL == 0)
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER);
TimerPrescaleSet(TIMER0_BASE, TIMER_A, 0);
TimerEnable(TIMER0_BASE, TIMER_A);
#elif (OS_PROBE_TIMER_SEL == 1)
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
TimerConfigure(TIMER1_BASE, TIMER_CFG_32_BIT_PER);
TimerPrescaleSet(TIMER1_BASE, TIMER_A, 0;
TimerEnable(TIMER1_BASE, TIMER_A);
#elif (OS_PROBE_TIMER_SEL == 2)
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
TimerConfigure(TIMER2_BASE, TIMER_CFG_32_BIT_PER);
TimerPrescaleSet(TIMER2_BASE, TIMER_A, 0);
TimerEnable(TIMER2_BASE, TIMER_A);
#elif (OS_PROBE_TIMER_SEL == 3)
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
TimerConfigure(TIMER3_BASE, TIMER_CFG_32_BIT_PER);
TimerPrescaleSet(TIMER3_BASE, TIMER_A, 0);
TimerEnable(TIMER3_BASE, TIMER_A);
#endif
OSProbeTmrInited = DEF_TRUE;
}
#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 == 0)
if (OSProbeTmrInited == DEF_TRUE) {
return (~(TimerValueGet(TIMER0_BASE, TIMER_A)));
} else {
return (0);
}
#elif (OS_PROBE_TIMER_SEL == 1)
if (OSProbeTmrInited == DEF_TRUE) {
return (~(TimerValueGet(TIMER1_BASE, TIMER_A)));
} else {
return (0);
}
#elif (OS_PROBE_TIMER_SEL == 2)
if (OSProbeTmrInited == DEF_TRUE) {
return (~(TimerValueGet(TIMER2_BASE, TIMER_A)));
} else {
return (0);
}
#elif (OS_PROBE_TIMER_SEL == 3)
if (OSProbeTmrInited == DEF_TRUE) {
return (~(TimerValueGet(TIMER3_BASE, TIMER_A)));
} else {
return (0);
}
#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)
{
CPU_INT32U cnts;
cnts = (CPU_INT32U)SysCtlClockGet() / OS_TICKS_PER_SEC;
SysTickPeriodSet(cnts);
SysTickEnable();
SysTickIntEnable();
}
/*
*********************************************************************************************************
* 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 + -