📄 bsp.c
字号:
CPU_INT08U BSP_Ser_RdByte (void)
{
CPU_INT08U rx_byte;
while ((U0LSR & BSP_LSR_RDR) == 0) {
OSTimeDly(1);
}
rx_byte = (CPU_INT08U)(U0RBR & 0x00FF); /* Remove the data from the holding register */
return (rx_byte);
}
/*
*********************************************************************************************************
* BSP_Ser_RdStr()
*
* Description : This function reads a string from a UART.
*
* Argument(s) : s A pointer to a buffer at which the string can be stored.
*
* len The size of the string that will be read.
*
* Return(s) : none.
*********************************************************************************************************
*/
void BSP_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 = BSP_Ser_RdByte();
if ((input == '\r') ||
(input == '\n')) {
BSP_Ser_Printf("\n");
rx_str[input_ix] = 0;
break;
}
if (input == '\b') {
if (input_ix > 0) {
BSP_Ser_Printf("\b \b");
input_ix--;
rx_str[input_ix] = 0;
}
}
if (ASCII_IsPrint(input)) {
BSP_Ser_Printf("%c", input);
rx_str[input_ix] = input;
input_ix++;
if (input_ix >= len) {
input_ix = len;
}
}
}
}
/*
*********************************************************************************************************
* BSP_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).
*
* Argument(s) : Format string follwing the C format convention.
*
* Return(s) : none.
*********************************************************************************************************
*/
void BSP_Ser_Printf (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);
BSP_Ser_WrStr((CPU_CHAR*) buffer);
}
/*
*********************************************************************************************************
*********************************************************************************************************
** ADC FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* BSP_ADC_GetStatus()
*
* Description : This function gets the status of the ADC
*
* Argument(s) : ch Channel of the ADC:
*
* BSP_ADC_CH0 probe input AD0.0
* BSP_ADC_CH1 probe input AD0.1
* BSP_ADC_CH2 probe input AD0.2
* BSP_ADC_CH3 probe input AD0.3
* BSP_ADC_CH7 probe input AD0.7
*
* Return(s) : The numerator of the binary fraction representing the result of the latest ADC conversion.
* This value will be a 10-bit value between 0x0000 and 0x03FF, inclusive.
*********************************************************************************************************
*/
CPU_INT16U BSP_ADC_GetStatus (CPU_INT08U ch)
{
CPU_INT16U status;
switch (ch) {
case BSP_ADC_CH0:
status = (CPU_INT16U)((ADDR0 >> 6) & 0x03FF);
break;
case BSP_ADC_CH1:
status = (CPU_INT16U)((ADDR1 >> 6) & 0x03FF);
break;
case BSP_ADC_CH2:
status = (CPU_INT16U)((ADDR2 >> 6) & 0x03FF);
break;
case BSP_ADC_CH3:
status = (CPU_INT16U)((ADDR3 >> 6) & 0x03FF);
break;
case BSP_ADC_CH7:
status = (CPU_INT16U)((ADDR7 >> 6) & 0x03FF);
default:
break;
}
return (status);
}
/*
*********************************************************************************************************
*********************************************************************************************************
* uC/Probe PLUG-IN FOR uC/OS-II FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* OSProbe_TmrInit()
*
* Description : Select & initialize a timer for use with the uC/Probe Plug-In for uC/OS-II.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : OSProbe_Init()
*
* Note(s) : none.
*********************************************************************************************************
*/
#if (APP_CFG_PROBE_OS_PLUGIN_EN == DEF_ENABLED) && (OS_PROBE_HOOKS_EN == 1)
void OSProbe_TmrInit (void)
{
T1PR = 256;
T1TCR = 0x00000001; /* Enable the timer. */
}
#endif
/*
*********************************************************************************************************
* OSProbe_TmrRd()
*
* Description : Read the current counts of a 32-bit free running timer.
*
* Argument(s) : none.
*
* Return(s) : The 32bit counts of the timer.
*
* Caller(s) : OSProbe_TimeGetCycles()
*
* Note(s) : none.
*********************************************************************************************************
*/
#if (APP_CFG_PROBE_OS_PLUGIN_EN == DEF_ENABLED) && (OS_PROBE_HOOKS_EN == 1)
CPU_INT32U OSProbe_TmrRd (void)
{
return ((CPU_INT32U)T1TC);
}
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
** uC/OS-II TIMER FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* BSP_Tmr_TickISR_Handler()
*
* Description : Handle the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : This is a ISR
*
* Note(s) : None.
*********************************************************************************************************
*/
void BSP_Tmr_TickISR_Handler (void)
{
T0IR = 0xFF; /* Clear timer #0 interrupt. */
OSTimeTick(); /* Call uC/OS-II's OSTimeTick(). */
}
/*
*********************************************************************************************************
*********************************************************************************************************
** LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* BSP_ADC_Init()
*
* Description : Initializes the board's ADC.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : BSP_Init()
*
* Note(s) : none.
*********************************************************************************************************
*/
static void BSP_ADC_Init (void)
{
CPU_INT08U div;
PINSEL0 = BSP_PINSEL0_ADC7_VAL;
PCONP |= BSP_PCONP_ADC_EN;
div = (BSP_CPU_PclkFreq(BSP_PCLK_ADC) / 4500000) + 1;
/* Configure ADC ... */
AD0CR = (CPU_INT32U)(BSP_ADCR_CH_EN_GRP) /* ... Sample/convert pin AD0.0 AD0.1 AD0.2 ... */
| (CPU_INT32U)(div << 8) /* ... Set divider so sample freq. < 4.5 MHz ... */
| (CPU_INT32U)(BSP_ADCR_BURST_EN) /* ... Use burst mode for continuous conversion ... */
| (CPU_INT32U)(BSP_ADCR_CLKS_11) /* ... Use 11 clks per conversion for 10-bit ... */
| (CPU_INT32U)(BSP_ADCR_PDN_EN); /* ... Power up the ADC. */
}
/*
*********************************************************************************************************
* BSP_PLL_Init()
*
* Description : Set up and activate the PLL.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : BSP_Init()
*
* Note(s) : (1) The PLL output frequency is calculated by:
*
* Fcco = 2 * Fin * m / n
*
* where
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -