📄 os_viewc.c
字号:
/*
*********************************************************************************************************
* uC/OS-View
*
* (c) Copyright 2006, Micrium, Inc., Weston, FL
* All Rights Reserved
*
* Atmel AVR
* ATmega128
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* EXIT uC/OS-View
*
* Description:
*
* Note(s) :
*********************************************************************************************************
*/
void OSView_Exit (void)
{
}
/*
*********************************************************************************************************
* Obtain CPU name
*********************************************************************************************************
*/
void OSView_GetCPUName (char *s)
{
OS_StrCopy(s, "AVR - ATmega128");
}
/*
*********************************************************************************************************
* Obtain Interrupt Stack information
*********************************************************************************************************
*/
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 */
}
/*
*********************************************************************************************************
* INITIALISE 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 an other timer.
*
* Note(s) : 1) Assumes UART #1
*********************************************************************************************************
*/
void OSView_InitTarget (INT32U baud_rate)
{
INT16U divisor;
INT16U temp;
/* -------- INITIALIZE THE SERIAL PORT ---------- */
/* Compute baud rate divisor and round off */
temp = (CPU_CLK_FREQ * 2) / (16 * baud_rate);
divisor = (temp + 1) / 2 - 1;
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_0
UBRR0H = divisor >> 8;
UBRR0L = divisor & 0x00FF;
UCSR0A &= ~(1 << U2X0); /* DO NOT double the USART transmission speed */
UCSR0B = (1 << RXCIE0) /* Enable USART Rx Complete Interrupt */
| (1 << RXEN0) /* Enable the receiver */
| (1 << TXEN0); /* Enable the transmitter */
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); /* 8 Bits, 1 stop, no parity */
#endif
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_1
UBRR1H = divisor >> 8;
UBRR1L = divisor & 0x00FF;
UCSR1A &= ~(1 << U2X1); /* DO NOT double the USART transmission speed */
UCSR1B = (1 << RXCIE1) /* Enable USART Rx Complete Interrupt */
| (1 << RXEN1) /* Enable the receiver */
| (1 << TXEN1); /* Enable the transmitter */
UCSR1C = (1 << UCSZ11) | (1 << UCSZ10); /* 8 Bits, 1 stop, no parity */
#endif
/* ------------ INITIALIZE THE TIMER ------------ */
#if OS_VIEW_TMR_SEL == OS_VIEW_TMR_1 /* See if we use Timer #1 */
TCCR1B = 0x00; /* Stop timer */
TCNT1 = 0xFFFF; /* Setup TCNT */
TCCR1A = 0x00; /* Normal Mode, count up 0x0000 to 0xFFFF */
TCCR1B = 0x02; /* Start timer, prescale by 8 */
#endif
#if OS_VIEW_TMR_SEL == OS_VIEW_TMR_3 /* See if we use Timer #3 */
TCCR3B = 0x00; /* Stop timer */
TCNT3 = 0xFFFF; /* Setup TCNT */
TCCR3A = 0x00; /* Normal Mode, count up 0x0000 to 0xFFFF */
TCCR3B = 0x02; /* Start timer, prescale by 8 */
#endif
OSView_TmrCntsPrev = 0;
}
/*
*********************************************************************************************************
* Disable Rx Interrupts
*********************************************************************************************************
*/
void OSView_RxIntDis (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_0
UCSR0B &= ~(1 << RXCIE0);
#endif
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_1
UCSR1B &= ~(1 << RXCIE1);
#endif
}
/*
*********************************************************************************************************
* Enable Rx Interrupts
*********************************************************************************************************
*/
void OSView_RxIntEn (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_0
UCSR0B |= (1 << RXCIE0);
#endif
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_1
UCSR1B |= (1 << RXCIE1);
#endif
}
/*
*********************************************************************************************************
* Rx Communication handler for uC/OS-View
*
* Description: This function is called by OSView_RxISR (see OS_VIEWa.ASM) to process a received
* character interrupt.
*********************************************************************************************************
*/
void OSView_RxISRHandler (void)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
INT8U rx_status;
INT8U rx_data;
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_0
OS_ENTER_CRITICAL();
rx_status = UCSR0A;
rx_data = UDR0; /* Clear interrupt source by reading Rx Data */
if (rx_status & (1 << RXC0)) { /* Check if received character? */
OSView_RxHandler(rx_data); /* Call the generic Rx handler */
}
OS_EXIT_CRITICAL();
#endif
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_1
OS_ENTER_CRITICAL();
rx_status = UCSR1A;
rx_data = UDR1; /* Clear interrupt source by reading Rx Data */
if (rx_status & (1 << RXC1)) { /* Check if received character? */
OSView_RxHandler(rx_data); /* Call the generic Rx handler */
}
OS_EXIT_CRITICAL();
#endif
}
/*
*********************************************************************************************************
* Rx/Tx Communication handler for uC/OS-View
*
* Description: This function is NOT called because the ATmega128 has a separate Rx and Tx ISR.
*********************************************************************************************************
*/
void OSView_RxTxISRHandler (void)
{
}
/*
*********************************************************************************************************
* Read uC/OS-View TIMER
*
* Note(s): 1) This function simply reads the current value of a 16-bit free-running UP timer.
*
* 2) The timer doesn't generate interrupts.
*********************************************************************************************************
*/
INT32U OSView_TmrRd (void)
{
INT16U cnts;
#if OS_VIEW_TMR_SEL == OS_VIEW_TMR_1
cnts = (INT16U)TCNT1; /* Read current counts of Timer #1 */
#endif
#if OS_VIEW_TMR_SEL == OS_VIEW_TMR_3
cnts = (INT16U)TCNT3; /* Read current counts of Timer #3 */
#endif
return ((INT32U)cnts);
}
/*
*********************************************************************************************************
* Communication for uC/OS-View
*
* Description: Send 1 character to COM Port
*********************************************************************************************************
*/
void OSView_Tx1 (INT8U c)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_0
UDR0 = c;
#endif
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_1
UDR1 = c;
#endif
}
/*
*********************************************************************************************************
* Disable Tx Interrupts
*********************************************************************************************************
*/
void OSView_TxIntDis (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_0
UCSR0B &= ~(1 << TXCIE0);
#endif
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_1
UCSR1B &= ~(1 << TXCIE1);
#endif
}
/*
*********************************************************************************************************
* Enable Tx Interrupts
*********************************************************************************************************
*/
void OSView_TxIntEn (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_0
UCSR0B |= (1 << TXCIE0);
#endif
#if OS_VIEW_COMM_SEL == OS_VIEW_COMM_1
UCSR1B |= (1 << TXCIE1);
#endif
}
/*
*********************************************************************************************************
* Tx Communication handler for uC/OS-View
* (PORT SPECIFIC)
*
* Description: Handle transmission of a character
*
* Note(s) : 1) This function is called by OSView_RxISR (see OS_VIEWa.ASM)
*********************************************************************************************************
*/
void OSView_TxISRHandler (void)
{
OSView_TxHandler();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -