1 /** ###################################################################
\r
2 ** THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
\r
4 ** Project : RTOSDemo
\r
5 ** Processor : MC9S12DP256BCPV
\r
6 ** Beantype : AsynchroSerial
\r
7 ** Version : Bean 02.231, Driver 01.08, CPU db: 2.87.283
\r
8 ** Compiler : Metrowerks HC12 C Compiler
\r
9 ** Date/Time : 19/06/2005, 15:07
\r
11 ** This bean "AsynchroSerial" implements an asynchronous serial
\r
12 ** communication. The bean supports different settings of
\r
13 ** parity, word width, stop-bit and communication speed,
\r
14 ** user can select interrupt or polling handler.
\r
15 ** Communication speed can be changed also in runtime.
\r
16 ** The bean requires one on-chip asynchronous serial channel.
\r
18 ** Serial channel : SCI0
\r
21 ** Init baud rate : 38400baud
\r
25 ** Breaks : Disabled
\r
28 ** Input buffer : SCI0DRL [207]
\r
29 ** Output buffer : SCI0DRL [207]
\r
30 ** Control register : SCI0CR1 [202]
\r
31 ** Mode register : SCI0CR2 [203]
\r
32 ** Baud setting reg. : SCI0BD [200]
\r
33 ** Special register : SCI0SR1 [204]
\r
36 ** Vector name : INT_SCI0
\r
40 ** Vector name : INT_SCI0
\r
44 ** ----------------------------------------------------
\r
45 ** Function | On package | Name
\r
46 ** ----------------------------------------------------
\r
47 ** Input | 89 | PS0_RxD0
\r
48 ** Output | 90 | PS1_TxD0
\r
49 ** ----------------------------------------------------
\r
52 ** Used baud modes :
\r
53 ** ----------------------------------------------------
\r
54 ** No. | Mode ID | Baud rate
\r
55 ** ----------------------------------------------------
\r
56 ** 0 | Bm_38400baud | 38400baud
\r
57 ** 1 | Bm_19200baud | 19200baud
\r
58 ** 2 | Bm_9600baud | 9600baud
\r
59 ** 3 | Bm_4800baud | 4800baud
\r
60 ** ----------------------------------------------------
\r
62 ** SetBaudRateMode - byte COM0_SetBaudRateMode(byte Mod);
\r
64 ** (c) Copyright UNIS, spol. s r.o. 1997-2002
\r
65 ** UNIS, spol. s r.o.
\r
69 ** http : www.processorexpert.com
\r
70 ** mail : info@processorexpert.com
\r
71 ** ###################################################################*/
\r
75 #pragma MESSAGE DISABLE C4002 /* WARNING C4002: Result not used is ignored */
\r
76 #pragma MESSAGE DISABLE C4301 /* INFORMATION C4301: Inline expansion done for function call */
\r
79 #include "TickTimer.h"
\r
82 /* Definition of DATA and CODE segments for this bean. User can specify where
\r
83 these segments will be located on "Build options" tab of the selected CPU bean. */
\r
84 #pragma DATA_SEG COM0_DATA /* Data section for this module. */
\r
85 #pragma CODE_SEG COM0_CODE /* Code section for this module. */
\r
88 #define OVERRUN_ERR 1 /* Overrun error flag bit */
\r
89 #define FRAMING_ERR 2 /* Framing error flag bit */
\r
90 #define PARITY_ERR 4 /* Parity error flag bit */
\r
91 #define CHAR_IN_RX 8 /* Char is in RX buffer */
\r
92 #define FULL_TX 16 /* Full transmit buffer */
\r
93 #define RUNINT_FROM_TX 32 /* Interrupt is in progress */
\r
94 #define FULL_RX 64 /* Full receive buffer */
\r
95 #define NOISE_ERR 128 /* Noise erorr flag bit */
\r
96 #define IDLE_ERR 256 /* Idle character flag bit */
\r
97 #define BREAK_ERR 512 /* Break detect */
\r
99 static word SerFlag; /* Flags for serial communication */
\r
100 /* Bits: 0 - OverRun error */
\r
101 /* 1 - Framing error */
\r
102 /* 2 - Parity error */
\r
103 /* 3 - Char in RX buffer */
\r
104 /* 4 - Full TX buffer */
\r
105 /* 5 - Running int from TX */
\r
106 /* 6 - Full RX buffer */
\r
107 /* 7 - Noise error */
\r
108 /* 8 - Idle character */
\r
109 /* 9 - Break detected */
\r
111 static word PrescHigh;
\r
112 static byte NumMode; /* Number of selected baud mode */
\r
116 ** ===================================================================
\r
117 ** Method : HWEnDi (bean AsynchroSerial)
\r
120 ** This method is internal. It is used by Processor Expert
\r
122 ** ===================================================================
\r
124 static void HWEnDi(void)
\r
126 SCI0CR2_TE = 1; /* Enable transmitter */
\r
127 SCI0CR2_RE = 1; /* Enable receiver */
\r
128 SCI0CR2_RIE = 1; /* Enable recieve interrupt */
\r
132 ** ===================================================================
\r
133 ** Method : COM0_SetBaudRateMode (bean AsynchroSerial)
\r
136 ** This method changes the channel communication speed (baud
\r
137 ** rate). This method can be used only if you specify a list
\r
138 ** of possible period settings at design time (see <Timing
\r
139 ** dialog box> - Runtime setting - from a list of values).
\r
140 ** Each of these settings constitutes a mode and Processor
\r
141 ** Expert^[TM] assigns them a mode identifier. The prescaler
\r
142 ** and compare values corresponding to each mode are
\r
143 ** calculated at design time. You may switch modes at
\r
144 ** runtime by referring only to a mode identifier. No
\r
145 ** run-time calculations are performed, all the calculations
\r
146 ** are performed at design time.
\r
148 ** NAME - DESCRIPTION
\r
149 ** Mod - Timing mode to set
\r
151 ** --- - Error code, possible codes:
\r
153 ** ERR_SPEED - This device does not work in
\r
154 ** the active speed mode
\r
155 ** ===================================================================
\r
157 byte COM0_SetBaudRateMode(byte Mod)
\r
159 static const word COM0_PrescHigh[4] = {41,81,163,326};
\r
161 if(Mod >= 4) /* Is mode in baud mode list */
\r
162 return ERR_VALUE; /* If no then error */
\r
163 NumMode = Mod; /* New baud mode */
\r
164 PrescHigh = COM0_PrescHigh[Mod]; /* Prescaler in high speed mode */
\r
165 SCI0BD = PrescHigh; /* Set prescaler bits */
\r
166 return ERR_OK; /* OK */
\r
170 ** ===================================================================
\r
171 ** Method : COM0_Init (bean AsynchroSerial)
\r
174 ** This method is internal. It is used by Processor Expert
\r
176 ** ===================================================================
\r
178 void COM0_Init(void)
\r
180 PrescHigh = 41; /* Precaler in high speed mode */
\r
181 SerFlag = 0; /* Reset flags */
\r
182 NumMode = 0; /* Number of selected baud mode */
\r
183 /* SCI0CR1: LOOPS=0,SCISWAI=1,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */
\r
184 SCI0CR1 = 64; /* Set the SCI configuration */
\r
185 /* SCI0SR2: ??=0,??=0,??=0,??=0,??=0,BRK13=0,TXDIR=0,RAF=0 */
\r
186 SCI0SR2 = 0; /* Set the Break Character Length and Transmitter pin data direction in Single-wire mode */
\r
187 SCI0SR1; /* Reset interrupt request flags */
\r
188 /* SCI0CR2: SCTIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */
\r
189 SCI0CR2 = 0; /* Disable error interrupts */
\r
190 SCI0BD = PrescHigh; /* Set prescaler bits */
\r
191 HWEnDi(); /* Enable/disable device according to status flags */
\r
199 ** ###################################################################
\r
201 ** This file was created by UNIS Processor Expert 03.33 for
\r
202 ** the Motorola HCS12 series of microcontrollers.
\r
204 ** ###################################################################
\r