📄 bsp.c
字号:
* 8 turns ON LED8
*
* Notes : 1) Jumper JP2 on the Explorer 16 board must be connected to enable the onboard LEDs
*********************************************************************************************************
*/
void LED_On (INT8U led)
{
if (led == 0) {
PORTB |= 0xFF; /* Turn on all of the LEDs if a 0 is passed in */
return;
}
if ((led >= 1) && (led <= 8)) {
led--; /* Convert the LED number to a pin number by subtracting 1 */
PORTB |= (1 << led); /* Turn on the chosen LED */
}
}
/*
*********************************************************************************************************
* 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 LED1
* 2 turns OFF LED2
* .
* 8 turns OFF LED8
*
* Notes : 1) Jumper JP2 on the Explorer 16 board must be connected to enable the onboard LEDs
*********************************************************************************************************
*/
void LED_Off (INT8U led)
{
if (led == 0) {
PORTB &= ~0xFF; /* Turn on all of the LEDs if a 0 is passed in */
return;
}
if ((led >= 1) && (led <= 8)) {
led--; /* Convert the LED number to a pin number by subtracting 1 */
PORTB &= ~(1 << led); /* Turn on the chosen LED */
}
}
/*
*********************************************************************************************************
* 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 LED1
* 2 toggles LED2
* .
* 8 toggles LED8
*
* Notes : 1) Jumper JP2 on the Explorer 16 board must be connected to enable the onboard LEDs
*********************************************************************************************************
*/
void LED_Toggle (INT8U led)
{
if (led == 0) {
PORTB ^= 0xFF; /* Turn on all of the LEDs if a 0 is passed in */
return;
}
if ((led >= 1) && (led <= 8)) {
led--; /* Convert the LED number to a pin number by subtracting 1 */
PORTB ^= (1 << led); /* Turn on the chosen LED */
}
}
/*
*********************************************************************************************************
* OSProbe_TmrInit()
*
* 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) : 1) This timer is shared with the uC/OS-II time tick and is initialized
* from Tmr_TickInit().
*********************************************************************************************************
*/
#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN == 1)
void OSProbe_TmrInit (void)
{
#if OS_PROBE_TIMER_SEL == 3
T3CON = 0; /* Use Internal Osc (Fosc / 4), 16 bit mode, prescaler = 1 */
TMR3 = 0; /* Start counting from 0 and clear the prescaler count */
PR3 = 0xFFFF; /* Set the period register to its maximum value */
T3CON |= TON; /* Start the timer */
#endif
#if OS_PROBE_TIMER_SEL == 5
T5CON = 0; /* Use Internal Osc (Fosc / 4), 16 bit mode, prescaler = 1 */
TMR5 = 0; /* Start counting from 0 and clear the prescaler count */
PR5 = 0xFFFF; /* Set the period register to its maximum value */
T5CON |= TON; /* Start the timer */
#endif
}
#endif
/*
*********************************************************************************************************
* OSProbe_TmrRd()
*
* Description : This function is called to read the current counts of a 16 bit free running timer.
*
* Arguments : none
*
* Returns ; The 16 bit count (in a 32 bit variable) 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 == 3
return ((INT32U)TMR3); /* Return the value of timer 3 if selected */
#endif
#if OS_PROBE_TIMER_SEL == 5
return ((INT32U)TMR5); /* Return the value of timer 5 if selected */
#endif
}
#endif
/*
*********************************************************************************************************
* 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 operates at a frequency of Fosc / 4
* 2) The timer resets to 0 after period register match interrupt is generated
*********************************************************************************************************
*/
static void Tmr_TickInit (void)
{
INT32U tmr_frq;
INT16U cnts;
tmr_frq = BSP_CPU_ClkFrq(); /* Get the CPU Clock Frequency (Hz) (Fcy) */
cnts = (tmr_frq / OS_TICKS_PER_SEC) - 1; /* Calaculate the number of timer ticks between interrupts */
#if BSP_OS_TMR_SEL == 2
T2CON = 0; /* Use Internal Osc (Fcy), 16 bit mode, prescaler = 1 */
TMR2 = 0; /* Start counting from 0 and clear the prescaler count */
PR2 = cnts; /* Set the period register */
IPC1 &= ~T2IP_MASK; /* Clear all timer 2 interrupt priority bits */
IPC1 |= (TIMER_INT_PRIO << 12); /* Set timer 2 to operate with an interrupt priority of 4 */
IFS0 &= ~T2IF; /* Clear the interrupt for timer 2 */
IEC0 |= T2IE; /* Enable interrupts for timer 2 */
T2CON |= TON; /* Start the timer */
#endif
#if BSP_OS_TMR_SEL == 4
T4CON = 0; /* Use Internal Osc (Fcy), 16 bit mode, prescaler = 1 */
TMR4 = 0; /* Start counting from 0 and clear the prescaler count */
PR4 = cnts; /* Set the period register */
IPC6 &= ~T4IP_MASK; /* Clear all timer 4 interrupt priority bits */
IPC6 |= (TIMER_INT_PRIO << 12); /* Set timer 4 to operate with an interrupt priority of 4 */
IFS1 &= ~T4IF; /* Clear the interrupt for timer 4 */
IEC1 |= T4IE; /* Enable interrupts for timer 4 */
T4CON |= TON; /* Start the timer */
#endif
}
/*
*********************************************************************************************************
* OS TICK INTERRUPT SERVICE ROUTINE
*
* Description : This function handles the timer interrupt that is used to generate TICKs for uC/OS-II.
*********************************************************************************************************
*/
void OS_Tick_ISR_Handler (void)
{
OSTimeTick();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -