📄 bsp.c
字号:
static void DispE_High (void)
{
GPIO_WriteBit(GPIO9, 0x10, Bit_SET);
}
static void DispE_Low (void)
{
GPIO_WriteBit(GPIO9, 0x10, Bit_RESET);
}
static void DispRW_Low (void)
{
GPIO_WriteBit(GPIO9, 0x40, Bit_RESET);
}
#endif
/*
*********************************************************************************************************
* GET 'PUSH BUTTON' STATUS
*
* Description : This function is used to get the status of any push button on the board.
*
* Arguments : push_button is the number of the push button to probe
* 1 probe the push button B1
* 2 probe the push button B2
*********************************************************************************************************
*/
BOOLEAN PB_GetStatus (INT8U push_button_id)
{
BOOLEAN status;
status = OS_FALSE;
switch (push_button_id) {
case 1:
if ((GPIO_ReadBit(GPIO7, GPIO_Pin_5)) == Bit_RESET) {
status = OS_TRUE;
}
break;
case 2:
if ((GPIO_ReadBit(GPIO7, GPIO_Pin_6)) == Bit_RESET) {
status = OS_TRUE;
}
break;
default:
break;
}
return (status);
}
/*
*********************************************************************************************************
* 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).
*
* We decided to use Timer #0 as the tick interrupt source.
*
* Arguments : none
*********************************************************************************************************
*/
static void Tmr_TickInit (void)
{
CPU_INT32U pclk_freq;
SCU_APBPeriphClockConfig(__TIM01, ENABLE); /* Enable the timer's clock signal */
SCU_APBPeriphReset(__TIM01, DISABLE); /* Remove the timer from reset state */
TIM_DeInit(TIM0); /* Return the timer's registers to default values */
/* Set up the timer's interrupt */
VIC_Config(TIM0_ITLine, (VIC_ITLineMode)VIC_IRQ, BSP_TMR0_INT_PRIO);
VIC_ITCmd(TIM0_ITLine, ENABLE);
pclk_freq = SCU_GetPCLKFreqValue();
pclk_freq *= 1000;
/* Calculate the required period */
BSP_Tmr0_Cmp_Value = (pclk_freq / BSP_TMR0_PRESCALER) / OS_TICKS_PER_SEC;
TIM0->OC1R = BSP_Tmr0_Cmp_Value; /* Set the output compare register */
/* Set the timer's prescaler */
TIM_PrescalerConfig(TIM0, (BSP_TMR0_PRESCALER - 1));
TIM_ITConfig(TIM0, TIM_IT_OC1, ENABLE); /* Enable the interrupt */
TIM_CounterCmd(TIM0, TIM_START); /* Start the timer */
}
/*
*********************************************************************************************************
* READ TIMER USED TO MEASURE INTERRUPT DISABLE TIME
*
* Description : This function is called to read the current counts of the interrupt disable time
* measurement timer.
*
* Arguments : none
*
* Returns : The 16 bit counts of the timer assuming the timer is an UP counter.
*********************************************************************************************************
*/
#if OS_CPU_INT_DIS_MEAS_EN > 0
CPU_INT16U OS_CPU_IntDisMeasTmrRd (void)
{
}
#endif
/*
*********************************************************************************************************
* INITIALIZE TIMER FOR uC/OS-View
*
* Description : This function is called to by uC/OS-View to initialize the free running timer that is
* used to make time measurements.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
void OSView_TmrInit (void)
{
TIM_DeInit(TIM1); /* Ensure that TIM1 registers are at reset values */
TIM_CounterCmd(TIM1, TIM_START); /* Start the timer */
}
#endif
/*
*********************************************************************************************************
* READ TIMER FOR uC/OS-View
*
* Description : This function is called to read the current counts of a 16-bit free running timer.
*
* Arguments : none
*
* Returns : A 32-bit value representing the current time
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
CPU_INT32U OSView_TmrRd (void)
{
CPU_INT32U tmr_val;
tmr_val = (CPU_INT32U)(TIM_GetCounterValue(TIM1));
return (tmr_val);
}
#endif
/*
*********************************************************************************************************
* UART INITIALIZATION
*
* Description : This function is called by uC/OS-View to initialize the UART.
*
* Arguments : baud_rate The baud rate to which the UART will be initialized
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
void OSView_UARTInit (CPU_INT32U baud_rate)
{
SCU_APBPeriphClockConfig(__UART1, ENABLE); /* Enable the UART's clock signal */
SCU_APBPeriphReset(__UART1, DISABLE); /* Remove the UART from reset state */
UART_DeInit(UART1); /* Ensure that UART registers are at reset values */
UART_ITConfig(UART1, UART_IT_Transmit, ENABLE);
VIC_Config(UART1_ITLine, (VIC_ITLineMode)VIC_IRQ, BSP_UART1_INT_PRIO);
VIC_ITCmd(UART1_ITLine, ENABLE);
BSP_UARTInit.UART_WordLength = UART_WordLength_8D;
BSP_UARTInit.UART_StopBits = UART_StopBits_1;
BSP_UARTInit.UART_Parity = UART_Parity_No;
BSP_UARTInit.UART_BaudRate = baud_rate;
BSP_UARTInit.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
BSP_UARTInit.UART_Mode = UART_Mode_Tx_Rx;
BSP_UARTInit.UART_FIFO = UART_FIFO_Disable;
BSP_UARTInit.UART_TxFIFOLevel = UART_FIFOLevel_1_8;
BSP_UARTInit.UART_RxFIFOLevel = UART_FIFOLevel_1_8;
UART_Init(UART1, &BSP_UARTInit); /* Use 8 data bits, 1 stop bit, and no parity */
UART_Cmd(UART1, ENABLE); /* Enable UART1 */
}
#endif
/*
*********************************************************************************************************
* Ser_Init
*
* Description : This function prepares UART0 for use with uC/TTCP.
*
* Arguments : None.
*
* Returns : None.
*********************************************************************************************************
*/
void Ser_Init (void)
{
SCU_APBPeriphClockConfig(__GPIO3, ENABLE); /* Enable the appropriate devices' clock signals */
SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
SCU_APBPeriphClockConfig(__UART0, ENABLE);
SCU_APBPeriphReset(__GPIO3, DISABLE); /* Remove the devices from reset */
SCU_APBPeriphReset(__GPIO5, DISABLE);
SCU_APBPeriphReset(__UART0, DISABLE);
BSP_GPIOInit.GPIO_Pin = 0x10;
BSP_GPIOInit.GPIO_Direction = GPIO_PinOutput;
BSP_GPIOInit.GPIO_Type = GPIO_Type_PushPull;
BSP_GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Disable;
BSP_GPIOInit.GPIO_Alternate = GPIO_OutputAlt3;
/* Initialize Port 3 pins used by the UART */
GPIO_Init(GPIO3, &BSP_GPIOInit);
BSP_GPIOInit.GPIO_Pin = 0x02;
BSP_GPIOInit.GPIO_Direction = GPIO_PinInput;
BSP_GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Enable;
BSP_GPIOInit.GPIO_Alternate = GPIO_InputAlt1;
/* Initialize Port 5 pins used by the UART */
GPIO_Init(GPIO5, &BSP_GPIOInit);
BSP_UARTInit.UART_WordLength = UART_WordLength_8D;
BSP_UARTInit.UART_StopBits = UART_StopBits_1;
BSP_UARTInit.UART_Parity = UART_Parity_No;
BSP_UARTInit.UART_BaudRate = 19200;
BSP_UARTInit.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
BSP_UARTInit.UART_Mode = UART_Mode_Tx_Rx;
BSP_UARTInit.UART_FIFO = UART_FIFO_Enable;
BSP_UARTInit.UART_TxFIFOLevel = UART_FIFOLevel_1_8;
BSP_UARTInit.UART_RxFIFOLevel = UART_FIFOLevel_1_8;
UART_Init(UART0, &BSP_UARTInit); /* Use 8 data bits, 1 stop bit, and no parity */
UART_Cmd(UART0, ENABLE); /* Enable UART0 */
}
/*
*********************************************************************************************************
* 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)
{
CPU_INT16U tx_flag;
tx_flag = UART0->FR;
while ((tx_flag & 0x0020) != 0) { /* Wait for an empty entry in the Tx FIFO */
tx_flag = UART0->FR;
}
UART_SendData(UART0, tx_byte);
}
/*
*********************************************************************************************************
* Ser_WrStr
*
* Description : Transmits a string using UART0
*
* Arguments : The string that will be transmitted.
*
* Returns : None.
*********************************************************************************************************
*/
void Ser_WrStr (CPU_CHAR *tx_str)
{
while ((*tx_str) != 0) {
Ser_WrByte(*tx_str++);
}
}
/*
*********************************************************************************************************
* Ser_RdByte
*
* Description : Receive a single byte using UART0
*
* Arguments : None.
*
* Returns : The received byte
*********************************************************************************************************
*/
CPU_INT08U Ser_RdByte (void)
{
CPU_INT16U rx_flag;
CPU_INT08U rx_byte;
rx_flag = UART0->FR;
while ((rx_flag & 0x0010) != 0) { /* Wait for a byte to appear in the FIFO */
OSTimeDly(5);
rx_flag = UART0->FR;
}
rx_byte = UART_ReceiveData(UART0);
return (rx_byte);
}
/*
*********************************************************************************************************
* 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 (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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -