📄 os_viewc.c
字号:
/*
*********************************************************************************************************
* uC/OS-View PORT
*
* (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may NOT be used to develop a similar product.
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* uC/OS-View PORT
*
* Atmel AT91SAM9263
*
* Filename : os_viewc.c
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* PROTOTYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* EXIT uC/OS-View
*
* Description: This function is called if your target needs to 'uninstall' uC/OS-View.
*
* Arguments : none
*
* Returns ; none
*********************************************************************************************************
*/
void OSView_Exit (void)
{
;
}
/*
*********************************************************************************************************
* Obtain CPU name
*
* Description: This function is used to fetch the CPU name.
*
* Arguments : s is a pointer to a string in which the CPU name will be stored.
*
* Returns ; none.
*********************************************************************************************************
*/
void OSView_GetCPUName (INT8U *s)
{
INT8U cpu_clk_freq;
cpu_clk_freq = (INT8U)(BSP_CPU_ClkFreq() / 1000000L); /* Convert cpu_clk_frequency from khz to hz */
(void)OS_StrCopy(s, "AT91SAM9263 (xxx MHz)");
s[13] = cpu_clk_freq / 100 + '0';
s[14] = (cpu_clk_freq % 100) / 10 + '0';
s[15] = cpu_clk_freq % 10 + '0';
}
/*
*********************************************************************************************************
* Obtain Interrupt Stack information
*
* Description: These functions return the base and size of the interrupt stack, if used.
*
* Arguments : none
*
* Returns ; Stack location.
*
* Notes : Because no ISR stack is used, these functions return zero.
*********************************************************************************************************
*/
INT32U OSView_GetIntStkBase (void)
{
return (0); /* We are not using an ISR stack */
}
INT32U OSView_GetIntStkSize (void)
{
return (0); /* We are not using an ISR stack */
}
/*
*********************************************************************************************************
* INITIALIZE uC/OS-View COM PORT
*
* Description: Initialize the hardware required for the OS to run. This will work on any target hardware,
* but may have to be tailored a little (regarding the clock frequency). Of course the same
* holds true if for some reason you choose to use another timer.
*
* Arguments : baud_rate is the intended baud rate for the port.
*
* Returns ; none.
*
* Note(s) : 1) This function assumes that a free running timer has been initialized. The timer can
* either be a 16 bits or 32 bits timer. Your application needs to provide a function
* called OSView_TmrRd() that reads the current counts of this timer. The free running
* timer is initialized by the BSP function OSView_TmrInit().
*********************************************************************************************************
*/
void OSView_InitTarget (INT32U baud_rate)
{
INT32U mclk_freq;
OSView_TmrInit(); /* Initialize the free running timer */
mclk_freq = BSP_CPU_MclkFreq(); /* peripheral_clk_freq = MCLK (set in US_MR) */
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
/* Set GPIOB pins 26, 27, 28, & 29 as USART0 pins */
AT91C_BASE_PIOA->PIO_PDR = AT91C_PA26_TXD0
| AT91C_PA27_RXD0
| AT91C_PA28_RTS0
| AT91C_PA29_CTS0;
/* Select GPIOB attached peripheral (USART0) */
AT91C_BASE_PIOA->PIO_ASR = AT91C_PA26_TXD0
| AT91C_PA27_RXD0
| AT91C_PA28_RTS0
| AT91C_PA29_CTS0;
AT91C_BASE_US0->US_IDR = AT91C_US_RXRDY /* Disable Rx interrupts */
| AT91C_US_TXRDY; /* Disable Tx interrupt */
AT91C_BASE_US0->US_CR = AT91C_US_RXEN /* Enable the receiver */
| AT91C_US_TXEN; /* Enable the transmitter */
AT91C_BASE_US0->US_MR = AT91C_US_USMODE_NORMAL /* RS232C mode selected */
| AT91C_US_CLKS_CLOCK /* USART input CLK is MCK */
| AT91C_US_CHRL_8_BITS /* 8 bit data to be sent */
| AT91C_US_PAR_NONE /* No parity bit selected */
| AT91C_US_NBSTOP_1_BIT; /* 1 stop bit selected */
/* Set the USART baud rate */
AT91C_BASE_US0->US_BRGR = (INT16U)((mclk_freq) / baud_rate / 16);
/* Set the vector address for USART0 */
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_US0] = (INT32U)OSView_RxTxISRHandler;
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_US0] = AT91C_AIC_SRCTYPE_EXT_HIGH_LEVEL | AT91C_AIC_PRIOR_LOWEST;
AT91C_BASE_AIC->AIC_ICCR = 1 << AT91C_ID_US0;
AT91C_BASE_AIC->AIC_IECR = 1 << AT91C_ID_US0;
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_US0); /* Enable the USART0 peripheral clock */
#endif
}
/*
*********************************************************************************************************
* Disable & Enable Rx Interrupts
*
* Description: These functions enable and disable the Rx interrupt.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
void OSView_RxIntDis (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
AT91C_BASE_US0->US_IDR = AT91C_US_RXRDY;
#endif
}
void OSView_RxIntEn (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
AT91C_BASE_US0->US_IER = AT91C_US_RXRDY;
#endif
}
/*
*********************************************************************************************************
* Rx & Tx Communication handler for uC/OS-View
*
* Note(s) : This adaptation of uC/OS-View assumes that a 'combined' interrupt is generated by the UART
* and thus these functions need not be populated.
*********************************************************************************************************
*/
void OSView_RxISRHandler (void)
{
;
}
void OSView_TxISRHandler (void)
{
;
}
/*
*********************************************************************************************************
* Rx/Tx Communication handler for uC/OS-View ('combined' interrupt handler)
*
* Description: The Rx/Tx ISR handler.
*
* Arguments : none.
*
* Returns : none
*********************************************************************************************************
*/
void OSView_RxTxISRHandler (void)
{
INT8U rx_data;
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
/* If we received a byte */
if ((AT91C_BASE_US0->US_CSR & AT91C_US_RXRDY) == AT91C_US_RXRDY) {
rx_data = (INT8U)(AT91C_BASE_US0->US_RHR & 0x00FF); /* Remove the data from the holding register */
OSView_RxHandler(rx_data); /* Call the generic Rx handler */
}
/* If we completed transmitting a byte */
if ((AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY) == AT91C_US_TXRDY) {
OSView_TxHandler(); /* Call the generic Tx handler */
}
AT91C_BASE_AIC->AIC_IVR = 0; /* Debug variant of IVR (protect mode is used) */
AT91C_BASE_AIC->AIC_ICCR = AT91C_ID_US0; /* Clear USART0 interrupt */
AT91C_BASE_AIC->AIC_EOICR = 0; /* Signal end of interrupt */
if ((AT91C_BASE_US0->US_CSR & AT91C_US_OVRE) == AT91C_US_OVRE) {
AT91C_BASE_US0->US_CSR = AT91C_US_RSTSTA; /* If an overrun occurs, reset the OR flag */
}
#endif
}
/*
*********************************************************************************************************
* Communication for uC/OS-View
*
* Description: Send 1 character to COM Port
*
* Arguments : c is the character to send.
*
* Returns : none
*********************************************************************************************************
*/
void OSView_Tx1 (INT8U c)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
AT91C_BASE_US0->US_THR = c;
#endif
}
/*
*********************************************************************************************************
* Disable & Enable Tx Interrupts
*
* Description: These functions enable and disable the Tx interrupt.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
void OSView_TxIntDis (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
AT91C_BASE_US0->US_IDR = AT91C_US_TXRDY;
#endif
}
void OSView_TxIntEn (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
AT91C_BASE_US0->US_IER = AT91C_US_TXRDY;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -