📄 bsp.c
字号:
divlo = div & 0x00FF; /* Split divisor into LOW and HIGH bytes */
divhi = (div >> 8) & 0x00FF;
lcr = DEF_BIT_00 | DEF_BIT_01; /* 8 Bits, 1 Stop, No Parity */
/* Configure P0.2 & P0.3 for UART0 */
pinsel = PINSEL0;
pinsel &= 0xFFFFFF0F;
pinsel |= 0x00000050;
PINSEL0 = pinsel;
U0LCR = DEF_BIT_07; /* Set divisor access bit */
U0DLL = divlo; /* Load divisor */
U0DLM = divhi;
U0LCR = lcr; /* Set line control register (Bit 8 is 0) */
U0IER = 0x00; /* Disable both Rx and Tx interrupts */
U0FCR = DEF_BIT_00 | DEF_BIT_01 | DEF_BIT_02; /* Enable FIFO, flush Rx & Tx */
#endif
#if SER_COMM_SEL == SER_UART_1
/* Compute divisor for desired baud rate */
pclk_freq = BSP_CPU_PclkFreq(PCLK_UART1); /* Get the CPU clock frequency */
div = (CPU_INT16U)(((2 * pclk_freq / 16 / 115200) + 1) / 2);
divlo = div & 0x00FF; /* Split divisor into LOW and HIGH bytes */
divhi = (div >> 8) & 0x00FF;
lcr = DEF_BIT_00 | DEF_BIT_01; /* 8 Bits, 1 Stop, No Parity */
/* Configure P3.16 & P3.17 for UART1 */
pinsel = PINSEL7;
pinsel &= 0xFFFFFFF0;
pinsel |= 0x0000000F;
PINSEL7 = pinsel;
U1LCR = DEF_BIT_07; /* Set divisor access bit */
U1DLL = divlo; /* Load divisor */
U1DLM = divhi;
U1LCR = lcr; /* Set line control register (Bit 8 is 0) */
U1IER = 0x00; /* Disable both Rx and Tx interrupts */
U1FCR = DEF_BIT_00 | DEF_BIT_01 | DEF_BIT_02; /* Enable FIFO, flush Rx & Tx */
#endif
}
/*
*********************************************************************************************************
* 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)
{
#if SER_COMM_SEL == SER_UART_0
U0THR = tx_byte;
#endif
#if SER_COMM_SEL == SER_UART_1
U1THR = tx_byte;
#endif
}
/*
*********************************************************************************************************
* Ser_WrStr
*
* Description : Transmits a string using UART0
*
* Arguments : The string that will be transmitted.
*
* Returns : None.
*********************************************************************************************************
*/
void Ser_WrStr (const CPU_CHAR * tx_str)
{
while ((*tx_str) != 0) {
Ser_WrByte(*tx_str++);
#if SER_COMM_SEL == SER_UART_0
while ((U0LSR & DEF_BIT_05) == 0) {
OSTimeDly(1);
}
#endif
#if SER_COMM_SEL == SER_UART_1
while ((U1LSR & DEF_BIT_05) == 0) {
OSTimeDly(1);
}
#endif
}
}
/*
*********************************************************************************************************
* Ser_RdByte
*
* Description : Receive a single byte using UART0
*
* Arguments : None.
*
* Returns : The received byte
*********************************************************************************************************
*/
CPU_INT08U Ser_RdByte (void)
{
CPU_INT08U rx_byte;
#if SER_COMM_SEL == SER_UART_0
while ((U0LSR & DEF_BIT_00) == 0) {
OSTimeDly(1);
}
rx_byte = (CPU_INT08U)(U0RBR); /* Remove the data from the holding register */
return (rx_byte);
#endif
#if SER_COMM_SEL == SER_UART_1
while ((U1LSR & DEF_BIT_00) == 0) {
OSTimeDly(1);
}
rx_byte = (CPU_INT08U)(U1RBR); /* Remove the data from the holding register */
return (rx_byte);
#endif
}
/*
*********************************************************************************************************
* Ser_RdStr
*
* Description : This function reads a string using Channel 0 of the UART.
*
* Arguments : s A pointer to a buffer at which the string can be stored
* len The size of the string that will be read
*
* Returns : None
*********************************************************************************************************
*/
void Ser_RdStr (CPU_CHAR *rx_str,
CPU_INT32U len)
{
CPU_CHAR input;
CPU_CHAR input_ix;
input_ix = 0;
rx_str[0] = 0;
while (1)
{
input = Ser_RdByte();
if ((input == '\r') ||
(input == '\n')) {
Ser_Printf("\n");
rx_str[input_ix] = 0;
break;
}
if (input == '\b') {
if (input_ix > 0) {
Ser_Printf("\b \b");
input_ix--;
rx_str[input_ix] = 0;
}
}
if (Str_IsPrint(input)) {
Ser_Printf("%c", input);
rx_str[input_ix] = input;
input_ix++;
if (input_ix >= len) {
input_ix = len;
}
}
}
}
/*
*********************************************************************************************************
* 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 (const 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);
}
/*
******************************************************************************************************************************
******************************************************************************************************************************
** DCC Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* DCC INITIALIZATION
*
* Description : This function initializes the interrupts for DCC receive/transmit.
*
* Arguments : none
*
* Returns ; none
*********************************************************************************************************
*/
#if OS_CPU_ARM_DCC_EN > 0
static void DCC_Init (void)
{
/* VIC DEBUG RX Initialization */
VICIntEnClear = (1 << VIC_DEBUGRX); /* Enable the timer interrupt source */
VICIntSelect &= ~(1 << VIC_DEBUGRX); /* Configure the DCC Rx function as an IRQ source */
VICVectAddr2 = (CPU_INT32U)DCC_RxISR_Handler; /* Set the vector address */
VICIntEnable = (1 << VIC_DEBUGRX); /* Enable the timer interrupt source */
}
#endif
/*
*********************************************************************************************************
* DCC ISR HANDLERS
*
* Description : These functions are the handlers for DCC receive and transmit.
*
* Arguments : none
*
* Returns ; none
*********************************************************************************************************
*/
#if OS_CPU_ARM_DCC_EN > 0
void DCC_RxISR_Handler (void)
{
OSDCC_Handler();
}
void DCC_TxISR_Handler (void)
{
OSDCC_Handler();
}
#endif
/*
******************************************************************************************************************************
******************************************************************************************************************************
** Static Board Support Initialization Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* Set the CPU Clock Frequency
*
* Description: This function sets up and activates the PLL
*
* Arguements : None
*
* Returns : None
*
* Notes : 1) The PLL output frequency is calculated by the following formula:
* Fcco = 2 * Fin * m / n, where Fin is the PLL input clock. In
* this particular case, Fin is set to the Main Oscillator
* whose frequency is #define'd in bsp.h. M is the PLL
* clock multiplier. M must be written to the PLLCFG register
* as the desired multiplier - 1. N is the PLL clock divider
* and must be written to PLLCFG as the desired divider - 1.
*
* 2) Fcco must be between 250 and 550 MHz. The ARM Core clock
* must never exceed 72 MHz. Use cClkDiv to divide Fcco accordingly.
*
* 3) When using the USB device, you must choose Fcco as a multiple
* of 96 MHz, and then use usbClkDiv to divide Fcco to exactly
* 48 MHz.
*
* 4) In this example, Fin = 12MHz, M = 12, N = 1, cClkDiv = 6 and usbClkDiv = 6.
* Therefore, Fcco = 2 * Fin * M / N = (2 * 12 * 12 / 1) = 288MHz.
* The processor clock = (Fcco / cClkDiv) = (288MHz / 6) = 48MHz.
* Finally, the USB clock = (Fcco / usbClkDib) = (288MHz / 6) = 48MHz.
*
* 5) Early revisions of the part have a PLL errata preventing Fcco from
* being greater than 288MHz.
*
* 6) For later revisions, M = 20, cCLKDiv = 8, and usbClkDiv = 10 yield
* 60MHz for the processor clock and 48MHz for the USB clock.
*********************************************************************************************************
*/
static void PLL_Init (void)
{
#if CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL /* Allocate storage for CPU status register */
CPU_SR cpu_sr = 0;
#endif
CPU_INT32U m;
CPU_INT32U n;
CPU_INT32U clk_div;
CPU_INT32U clk_div_usb;
m = 11; /* PLL Multiplier = 20, MSEL bits = 12 - 1 = 11 */
n = 0; /* PLL Divider = 1, NSEL bits = 1 - 1 = 0 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -