source: rc_autosar_rh850/trunk/driver/rlin3x.c@ 113

Last change on this file since 113 was 113, checked in by ertl-honda, 8 years ago

ドライバーの追加.

File size: 8.3 KB
Line 
1/*
2 * TOPPERS Software
3 * Toyohashi Open Platform for Embedded Real-Time Systems
4 * Software
5 *
6 * Copyright (C) 2015 by Center for Embedded Computing Systems
7 * Graduate School of Information Science, Nagoya Univ., JAPAN
8 *
9 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
10 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
11 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
12 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
13 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
14 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
15 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
16 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
17ƒƒ“ƒgi—˜—p
18 * ŽÒƒ}ƒjƒ…
19ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
20 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
21 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
22 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
23 * ‚ƁD
24 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
25ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
26ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
27 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
28 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
29 * •ñ‚·‚邱‚ƁD
30 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
31 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
32 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
33 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
34 * –Ɛӂ·‚邱‚ƁD
35 *
36 * –{ƒ\ƒtƒgƒEƒFƒA‚́CAUTOSARiAUTomotive Open System ARchitecturejŽd
37 * —l‚ÉŠî‚¢‚Ä‚¢‚éDã‹L‚Ì‹–‘ø‚́CAUTOSAR‚Ì’m“IàŽYŒ ‚ð‹–‘ø‚·‚é‚à‚Ì‚Å
38 * ‚Í‚È‚¢DAUTOSAR‚́CAUTOSARŽd—l‚ÉŠî‚¢‚½ƒ\ƒtƒgƒEƒFƒA‚ð¤—p–Ú“I‚Å—˜
39 * —p‚·‚éŽÒ‚ɑ΂µ‚āCAUTOSARƒp[ƒgƒi[‚ɂȂ邱‚Æ‚ð‹‚ß‚Ä‚¢‚éD
40 *
41 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
42 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
43 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
44 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
45 * ‚̐ӔC‚𕉂í‚È‚¢D
46 *
47 * $Id: rlin3x.c 20 2015-04-20 14:29:19Z honda $
48 */
49/*
50 * ’ʐMƒ‚ƒWƒ…
51[ƒ‹—pUART(RLIN)ƒhƒ‰ƒCƒo
52 */
53#include "Os.h"
54#include "t_stdlib.h"
55#include "target_sysmod.h"
56#include "rlin3x.h"
57
58#undef RLIN3x_BASE
59#define RLIN3x_BASE RLIN32_BASE
60
61#define RLIN3xLWBR_B 0x00000001
62#define RLIN3xLBRP01_H 0x00000002
63#define RLIN3xLBRP0_B 0x00000002
64#define RLIN3xLBRP1_B 0x00000003
65#define RLIN3xLSTC_B 0x00000004
66#define RLIN3xLMD_B 0x00000008
67#define RLIN3xLBFC_B 0x00000009
68#define RLIN3xLSC_B 0x0000000a
69#define RLIN3xLWUP_B 0x0000000b
70#define RLIN3xLIE_B 0x0000000c
71#define RLIN3xLEDE_B 0x0000000d
72#define RLIN3xLCUC_B 0x0000000e
73#define RLIN3xLTRC_B 0x00000010
74#define RLIN3xLMST_B 0x00000011
75#define RLIN3xLST_B 0x00000012
76#define RLIN3xLEST_B 0x00000013
77#define RLIN3xLDFC_B 0x00000014
78#define RLIN3xLIDB_B 0x00000015
79#define RLIN3xLCBR_B 0x00000016
80#define RLIN3xLUDB0_B 0x00000017
81#define RLIN3xLDBR1_B 0x00000018
82#define RLIN3xLDBR2_B 0x00000019
83#define RLIN3xLDBR3_B 0x0000001a
84#define RLIN3xLDBR4_B 0x0000001b
85#define RLIN3xLDBR5_B 0x0000001c
86#define RLIN3xLDBR6_B 0x0000001d
87#define RLIN3xLDBR7_B 0x0000001e
88#define RLIN3xLDBR8_B 0x0000001f
89#define RLIN3xLUOER_B 0x00000020
90#define RLIN3xLUOR1_B 0x00000021
91#define RLIN3xLUTDR_H 0x00000024
92#define RLIN3xLUTDRL_B 0x00000024
93#define RLIN3xLUTDRH_B 0x00000025
94#define RLIN3xLURDR_H 0x00000026
95#define RLIN3xLURDRL_B 0x00000026
96#define RLIN3xLURDRH_B 0x00000027
97#define RLIN3xLUWTDR_H 0x00000028
98#define RLIN3xLUWTDRL_B 0x00000028
99#define RLIN3xLUWTDRH_B 0x00000029
100
101/*
102 * 7 : TX
103 * 8 : RX
104 */
105
106/*
107 * Port 0 Configration for RLIN32
108 * P10_13 : RLIN32RX : ‘æ2Œ“—p
109 * P10_14 : RLIN32TX : ‘æ2Œ“—p
110 */
111#define RLIN32_P10_MASK ((uint16) 0x6000)
112#define RLIN32_PMC10_INIT ((uint16) 0x6000)
113#define RLIN32_PFCAE10_INIT ((uint16) 0x0000)
114#define RLIN32_PFCE10_INIT ((uint16) 0x0000)
115#define RLIN32_PFC10_INIT ((uint16) 0x6000)
116#define RLIN32_PM10_INIT ((uint16) 0x2000)
117#define RLIN32_PIBC10_INIT ((uint16) 0x2000)
118
119/*
120 * RLIN32—pƒ|[ƒg‚̏‰Šú‰»
121 */
122void
123rlin3x_portinit(void)
124{
125 uint16 wk;
126
127 /*
128 * PORT10(RLIN32)
129 */
130 /* PFCAE10 Ý’è */
131 wk = sil_reh_mem((void *) PFCAE(10));
132 wk &= ~RLIN32_P10_MASK;
133 wk |= (RLIN32_PFCAE10_INIT & RLIN32_P10_MASK);
134 sil_wrh_mem((void *) PFCAE(10), wk);
135
136 /* PFCE10 Ý’è */
137 wk = sil_reh_mem((void *) PFCE(10));
138 wk &= ~RLIN32_P10_MASK;
139 wk |= (RLIN32_PFCE10_INIT & RLIN32_P10_MASK);
140 sil_wrh_mem((void *) PFCE(10), wk);
141
142 /* PFC10 Ý’è */
143 wk = sil_reh_mem((void *) PFC(10));
144 wk &= ~RLIN32_P10_MASK;
145 wk |= (RLIN32_PFC10_INIT & RLIN32_P10_MASK);
146 sil_wrh_mem((void *) PFC(10), wk);
147
148 /* PMC10 Ý’è */
149 wk = sil_reh_mem((void *) PMC(10));
150 wk &= ~RLIN32_P10_MASK;
151 wk |= (RLIN32_PMC10_INIT & RLIN32_P10_MASK);
152 sil_wrh_mem((void *) PMC(10), wk);
153
154 /* PM10 Ý’è */
155 wk = sil_reh_mem((void *) PM(10));
156 wk &= ~RLIN32_P10_MASK;
157 wk |= (RLIN32_PM10_INIT & RLIN32_P10_MASK);
158 sil_wrh_mem((void *) PM(10), wk);
159
160 /* PIBC10 Ý’è */
161 wk = sil_reh_mem((void *) PIBC(10));
162 wk &= ~RLIN32_P10_MASK;
163 wk |= (RLIN32_PIBC10_INIT & RLIN32_P10_MASK);
164 sil_wrh_mem((void *) PIBC(10), wk);
165}
166
167/*
168 * ƒ{[ƒŒ[ƒgƒŒƒWƒXƒ^‚ւ̐ݒè’l PCLK=40MHz, 115200bps
169 */
170#define RLIN3xLWBR_VAL 0xf2
171#define RLIN3xLBRP01_VAL 10
172
173#define RxBUFF_SIZE 256
174#define TxBUFF_SIZE 256
175
176static uint8 s_rxbuff[RxBUFF_SIZE];
177static uint8 s_txbuff[TxBUFF_SIZE];
178
179static int s_rxbuff_tail;
180static int s_rxbuff_head;
181static int s_rxbuff_cnt;
182static int s_txbuff_tail;
183static int s_txbuff_head;
184static int s_txbuff_cnt;
185static boolean s_do_tx;
186
187/*
188 * ‰Šú‰»
189 */
190void
191rlin3x_init(void)
192{
193 s_rxbuff_tail = 0;
194 s_rxbuff_head = 0;
195 s_rxbuff_cnt = 0;
196 s_txbuff_tail = 0;
197 s_txbuff_head = 0;
198 s_txbuff_cnt = 0;
199 s_do_tx = FALSE;
200
201 /* Uart Mode ‚ð—LŒø(ƒmƒCƒYƒtƒBƒ‹ƒ^‚à—LŒø) */
202 sil_wrb_mem((void *) (RLIN3x_BASE + RLIN3xLMD_B), 0x31);
203
204 /* ƒ{[ƒŒ[ƒgÝ’è */
205 sil_wrb_mem((void *) (RLIN3x_BASE + RLIN3xLWBR_B), RLIN3xLWBR_VAL);
206 sil_wrh_mem((void *) (RLIN3x_BASE + RLIN3xLBRP01_H), RLIN3xLBRP01_VAL);
207
208 /* ƒGƒ‰[ŒŸo‹–‰Â */
209 sil_wrb_mem((void *) (RLIN3x_BASE + RLIN3xLEDE_B), 0x0d);
210
211 /* ƒf[ƒ^ ƒtƒH[ƒ}ƒbƒg */
212 sil_wrb_mem((void *) (RLIN3x_BASE + RLIN3xLBFC_B), 0x00);
213
214 /* ƒŠƒZƒbƒg‰ðœ */
215 sil_wrb_mem((void *) (RLIN3x_BASE + RLIN3xLCUC_B), 0x01);
216
217 /* ƒŠƒZƒbƒg‰ðœ‘Ò‚¿ */
218 while (sil_reb_mem((void *) (RLIN3x_BASE + RLIN3xLMST_B)) == 0x00) {
219 }
220
221 /* ‘—ŽóM“®ì‹–‰Â */
222 sil_wrb_mem((void *) (RLIN3x_BASE + RLIN3xLUOER_B), 0x03);
223
224 /* ‘—ŽóMŠ„ž‚Ý‹–‰Â */
225 sil_wrb_mem((void *) (RLIN3x_BASE + RLIN3xLIE_B), 0x03);
226
227 /* ƒ|[ƒg‚̏‰Šú‰» */
228 rlin3x_portinit();
229}
230
231
232/*
233 * ŽóM‚µ‚½ƒf[ƒ^’·
234 */
235int
236rlin3x_get_rxcnt(void)
237{
238 return s_rxbuff_cnt;
239}
240
241/*
242 * RLIN32ŽóM
243 */
244boolean
245rlin3x_receive(unsigned char *data, int len)
246{
247 boolean result = TRUE;
248 int loop;
249
250 SuspendOSInterrupts();
251 if (s_rxbuff_cnt < len) {
252 result = FALSE;
253 }else {
254 for(loop = 0; loop < len; loop++) {
255 *data++ = s_rxbuff[s_rxbuff_head++];
256 s_rxbuff_head = s_rxbuff_head % RxBUFF_SIZE;
257 s_rxbuff_cnt--;
258 }
259 }
260 ResumeOSInterrupts();
261
262 return result;
263}
264
265/*
266 * RLIN32‘—M
267 */
268boolean
269rlin3x_send(const unsigned char *data, int len)
270{
271 int loop;
272 char c;
273
274 /* ‹ó‚«‚ª–³‚¯‚ê‚΃Gƒ‰[ */
275 if (s_txbuff_cnt + len > TxBUFF_SIZE) {
276 return FALSE;
277 }
278
279 /* ƒŠƒ“ƒOƒoƒbƒtƒ@‚ɃRƒs[ */
280 for(loop = 0; loop < len; loop++){
281 s_txbuff[s_txbuff_tail++] = *data++;
282 s_txbuff_tail = s_txbuff_tail % TxBUFF_SIZE;
283 s_txbuff_cnt++;
284 }
285
286 if (!(s_do_tx)) {
287 SuspendOSInterrupts();
288 /* ƒŠƒ“ƒOƒoƒbƒtƒ@‚©‚çŽæ‚èo‚µ‘—M */
289 c = s_txbuff[s_txbuff_head++];
290 s_txbuff_head = s_txbuff_head % TxBUFF_SIZE;
291 s_txbuff_cnt--;
292 s_do_tx = TRUE;
293 sil_wrb_mem((void *) (RLIN3x_BASE + RLIN3xLUTDRL_B), c);
294 ResumeOSInterrupts();
295 }
296
297 return TRUE;
298}
299
300void
301rlin3x_tx_interrupt(void)
302{
303 char c;
304
305 if (s_txbuff_cnt == 0) {
306 /* ƒoƒbƒtƒ@‚ª‹ó */
307 s_do_tx = FALSE;
308 }
309 else {
310 /* ƒoƒbƒtƒ@‚©‚çƒf[ƒ^‚ðŽæ‚èo‚µo—Í */
311 c = s_txbuff[s_txbuff_head++];
312 s_txbuff_head = s_txbuff_head % TxBUFF_SIZE;
313 s_txbuff_cnt--;
314 sil_wrb_mem((void *) (RLIN3x_BASE + RLIN3xLUTDRL_B), c);
315 s_do_tx = TRUE;
316 }
317}
318
319ISR(RLIN3x_TX_ISR)
320{
321 rlin3x_tx_interrupt();
322}
323
324void
325rlin3x_rx_interrupt(void)
326{
327 char c;
328
329 c = sil_reb_mem((void *) (RLIN3x_BASE + RLIN3xLURDRL_B));
330
331 if (s_rxbuff_cnt < RxBUFF_SIZE) {
332 s_rxbuff[s_rxbuff_tail++] = c;
333 s_rxbuff_tail = s_rxbuff_tail % RxBUFF_SIZE;
334 s_rxbuff_cnt++;
335 }
336}
337
338ISR(RLIN3x_RX_ISR)
339{
340 rlin3x_rx_interrupt();
341}
Note: See TracBrowser for help on using the repository browser.