?? rtosinit_430f2274.c
字號:
/*********************************************************************
* SEGGER MICROCONTROLLER GmbH & Co KG *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1995 - 2008 SEGGER Microcontroller GmbH & Co KG *
* *
* www.segger.com Support: support@segger.com *
* *
**********************************************************************
* *
* embOS * Real time operating system for microcontrollers *
* *
* *
* Please note: *
* *
* Knowledge of this file may under no circumstances *
* be used to write a similar product or a real-time *
* operating system for in-house use. *
* *
* Thank you for your fairness ! *
* *
**********************************************************************
* *
* embOS version: 3.60a *
* *
**********************************************************************
----------------------------------------------------------------------
File : RTOSInit.c for Texas Instruments MSP430 with IAR compiler
Purpose : Initializes and handles the hardware for embOS as far
as required by embOS.
Feel free to modify this file if required for your target
-------- END-OF-HEADER ---------------------------------------------
*/
#include "RTOS.H"
#include <msp430.h>
/*********************************************************************
*
* Configuration
*
**********************************************************************
Define clock frequency for CPU
Select UART for embOSView, set baudrate,
If you do not want (or can not due to hardware limitations) to dedicate
a UART to embOSView, please define OS_UART to -1
Define the system stack size that embOS should use. Rowley only
*/
#ifndef OS_FSYS
#define OS_FSYS 1000000L
#endif
#ifndef OS_UART
#define OS_UART 0
#endif
#ifndef OS_BAUDSRC_MCLK
#define OS_BAUDSRC_MCLK 0
#endif
#ifndef OS_BAUDRATE
#define OS_BAUDRATE 9600L
#endif
#define EMBOS_TIMER_VECTOR TIMERA0_VECTOR
/****** End of configuration settings *******************************/
/*********************************************************************
*
* OS_InitHW()
*
* Initialize the hardware (timer) required for embOS to run.
* May be modified, if an other timer should be used
*/
void OS_InitHW(void) {
WDTCTL = WDTPW + WDTHOLD; /* Stop watchdog timer */
//
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
BCSCTL1 = 0x87; // Set DCO
DCOCTL = 0x40;
}
else
{
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
}
TACTL = 0 /* Reset Timer_A3, division 1 */
| (1<<2) /* Clear timer */
| (2<<8); /* Use SMCLK as timer clock */
CCR0 = (OS_FSYS/100) - 1; /* Set to 10ms */
CCTL0 = 0 /* Initilize capture control */
| (1<<4); /* Enable compare interrupt */
TACTL |= (1<<4); /* Start timer in UP-Mode */
OS_COM_Init(); /* Initialize UART */
}
/*********************************************************************
*
* Idle loop (OS_Idle)
*
* Please note:
* This is basically the "core" of the idle loop.
* This core loop can be changed, but:
* The idle loop does not have a stack of its own, therefore no
* functionality should be implemented that relies on the stack
* to be preserved. However, a simple program loop can be programmed
* (like toggeling an output or incrementing a counter)
*
* We just enter low power 0 mode here.
*/
void OS_Idle(void) { /* Idle loop: No task is ready to exec */
_BIS_SR(0x18); /* Nothing to do ... enter low power mode 0 */
for (;;); /* Alternative endless loop, required */
/* when simulator is used ! */
}
/*********************************************************************
*
* Get time [cycles]
*
* This routine is required for task-info via embOSView or high
* resolution time maesurement functions.
* It returns the system time in timer clock cycles.
*/
OS_U32 OS_GetTime_Cycles(void) {
unsigned int t_cnt = TAR;
OS_U32 time = OS_Time;
if (CCTL0 & (1<<0)) { /* If timer interrupt pending, */
t_cnt = TAR; /* correct result */
time++;
}
return (OS_FSYS/1000)*time + t_cnt;
}
/*********************************************************************
*
* OS_ConvertCycles2us
*
* Convert Cycles into micro seconds.
*
* If your clock frequency is not a multiple of 1 MHz,
* you may have to modify this routine in order to get proper
* diagonstics.
*
* This routine is required for profiling or high resolution time
* measurement only. It does not affect operation of the OS.
*/
OS_U32 OS_ConvertCycles2us(OS_U32 Cycles) {
#if (OS_FSYS >= 1000000)
return Cycles/(OS_FSYS/1000000);
#else
return Cycles * (1000000/OS_FSYS);
#endif
}
/*********************************************************************
*
* OS_Tick interrupt Handler
*/
#pragma vector=EMBOS_TIMER_VECTOR
static __interrupt void OS_ISR_Tick(void) {
OS_EnterInterrupt();
OS_HandleTick();
OS_LeaveInterrupt();
}
/*********************************************************************
*
* Communication for embOSView (UART 0)
*
**********************************************************************
*/
#if OS_BAUDSRC_MCLK
#define BAUDDIVIDE ((OS_FSYS+(OS_BAUDRATE/2))/OS_BAUDRATE)
#define UxBR0 (BAUDDIVIDE & 0xFF)
#define UxBR1 ((BAUDDIVIDE >> 8) & 0xFF)
#define UxMCTL 0x00
#define UxTCTL 0x20 /* Use MCLK for baudrate generator */
#else
#define UxTCTL 0x10 /* Use ACLK for baudrate generator */
#if (OS_BAUDRATE == 9600)
#define UxBR0 0x03
#define UxBR1 0x00
#define UxMCTL 0x4A
#elif (OS_BAUDRATE == 4800)
#define UxBR0 0x06
#define UxBR1 0x00
#define UxMCTL 0x6F
#else
#error Setting of OS_BAUDRATE not supported when using ACLK for baudrate generation
#endif
#endif
#if (OS_UART == 0)
#define EMBOS_UARTRX_VECTOR USCIAB0RX_VECTOR
#define EMBOS_UARTTX_VECTOR USCIAB0TX_VECTOR
/*********************************************************************
*
* OS_COM_Init()
* Initialize UART for embOSView
*/
void OS_COM_Init(void) {
P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD
P3DIR = 0xFF; // All P3.x outputs
P3OUT = 0; // All P3.x reset
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
UCA0CTL1 |= UCSSEL_2; // SMCLK
// UCA0BR0 = 104; // 1MHz 9600
// UCA0BR1 = 0; // 1MHz 9600
UCA0BR0 = 64; // 1MHz 1200
UCA0BR1 = 3; // 1MHz 1200
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= ( UCA0RXIE | UCA0TXIE ); // Enable USCI_A0 RX interrupt
}
/*********************************************************************
*
* OS_COM_Send1()
* Never call this function directly from your application
*/
void OS_COM_Send1(OS_U8 c) {
UCA0TXBUF = c;
}
/*********************************************************************
*
* OS_ISR_rx()
* embOS UART rx interrupt handler
*/
#pragma vector=EMBOS_UARTRX_VECTOR
static __interrupt void OS_ISR_rx(void) {
IE2 &= ~UCA0RXIE;
OS_EnterNestableInterrupt(); /* We will enable interrupts */
OS_OnRx(UCA0RXBUF); /* Process data */
OS_DI();
IE2 |= UCA0RXIE;
OS_LeaveNestableInterrupt();
}
/*********************************************************************
*
* OS_ISR_tx()
* embOS UART tx interrupt handler
*/
#pragma vector=EMBOS_UARTTX_VECTOR
static __interrupt void OS_ISR_tx(void) {
OS_EnterInterrupt();
IFG2 &= ~UCA0TXIFG;
OS_OnTx();
OS_LeaveInterrupt();
}
#elif (OS_UART == -1) /* No communication routines */
void OS_COM_Init(void) {}
void OS_COM_Send1(OS_U8 c) {
OS_USEPARA(c);
OS_COM_ClearTxActive(); /* let OS know that tx is not busy */
}
#else /* unsupported USART selected */
#error Unsupported USART (OS_UART) selected !!!
#endif /* (OS_UART == 0) */
/***** EOF ********************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -