?? bsp.c
字號:
/*
*********************************************************************************************************
* Microchip PIC24FJ
* Board Support Package
*
* Micrium
* (c) Copyright 2005, Micrium, Weston, FL
* All Rights Reserved
*
*
* File : BSP.C
* By : Eric Shufro
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* MPLAB CONFIGURATION MACROS
*********************************************************************************************************
*/
_CONFIG1(JTAGEN_OFF); /* Disable the JTAG which allows use of all port A pins */
_CONFIG2(FNOSC_PRIPLL & POSCMOD_XT); /* Select the primary (XT, HS, EC) Oscillator with PLL */
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* PROTOTYPES
*********************************************************************************************************
*/
static void BSP_PLL_Init(void);
static void Tmr_TickInit(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)
{
LED_Init(); /* Initialize the I/Os for the LED controls */
Tmr_TickInit(); /* Initialize the uC/OS-II tick interrupt */
}
/*
*********************************************************************************************************
* BSP_CPU_ClkFrq()
* Description : This function determines the CPU clock frequency (Fcy)
* Returns : The CPU frequency in (HZ)
*********************************************************************************************************
*/
INT32U BSP_CPU_ClkFrq (void)
{
INT8U Clk_Selected;
INT16U FRC_Div;
INT32U CPU_Clk_Frq;
FRC_Div = ((CLKDIV & FRCDIV_MASK) >> 8); /* Get the FRC Oscillator Divider register value */
FRC_Div = ((1 << FRC_Div) * 2); /* Compute the FRC Divider value */
Clk_Selected = (OSCCON & COSC_MASK) >> 12; /* Determine which clock source is currently selected */
switch (Clk_Selected) {
case 0: /* Fast Oscillator (FRC) Selected */
CPU_Clk_Frq = CPU_FRC_OSC_FRQ; /* Return the frequency of the internal fast oscillator */
break;
case 1: /* Fast Oscillator (FRC) with PLL Selected */
CPU_Clk_Frq = (CPU_FRC_OSC_FRQ * 4); /* Compute the PLL output frequency = (FRC * 4) */
break;
case 2: /* Primary External Oscillator Selected */
CPU_Clk_Frq = CPU_PRIMARY_OSC_FRQ; /* Return the frequency of the primary external oscillator */
break;
case 3: /* Primary External Oscillator with PLL Selected */
CPU_Clk_Frq = (CPU_PRIMARY_OSC_FRQ * 4); /* Compute the PLL output frq as (CPU_PRIMARY_OSC_FRQ * 4) */
break;
case 4: /* Secondary Oscillator Selected (SOCS) */
CPU_Clk_Frq = CPU_SECONDARY_OSC_FRQ; /* Return the frq of the external secondary oscillator */
break;
case 5: /* Low Power Oscillator (LPOSC) Selected */
CPU_Clk_Frq = CPU_LOW_POWER_OSC_FRQ; /* Return the frq of the Low Power Oscillator */
break;
case 6:
CPU_Clk_Frq = 0; /* Return 0 for the Reserved clock setting */
break;
case 7: /* Fast Oscillator (FRC) with FRCDIV Selected */
CPU_Clk_Frq = CPU_FRC_OSC_FRQ / FRC_Div; /* Return the clock frequency of FRC / FRC_Div */
break;
default:
CPU_Clk_Frq = 0; /* Return 0 if the clock source cannot be determined */
break;
}
CPU_Clk_Frq /= 2; /* Divide the final frq by 2, get the actual CPU Frq (Fcy) */
return (CPU_Clk_Frq); /* Return the operating frequency */
}
/*
*********************************************************************************************************
* DISABLE ALL INTERRUPTS
*
* Description : This function disables all interrupts from the interrupt controller.
*
* Arguments : none
*********************************************************************************************************
*/
void BSP_IntDisAll (void)
{
}
/*
*********************************************************************************************************
* LED I/O INITIALIZATION
*
* Description : This function initializes the I/O Pins used by the onboard LEDs
*
* Arguments : none
*
* Notes : 1) Jumper JP2 on the Explorer 16 board must be connected to enable the onboard LEDs
* 2) JTAG must be DISABLED in order to utilize all of PORTA I/O Lines for LEDs
*********************************************************************************************************
*/
void LED_Init (void)
{
TRISA = 0; /* Set all PORTA pins to output */
LED_Off(0); /* Shut off all LEDs */
}
/*
*********************************************************************************************************
* 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 LED1
* 2 turns ON LED2
* ...
* 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) {
PORTA |= 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 */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -