Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/src/serial.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (show annotations) (download) (as text)
Wed Aug 22 08:03:12 2012 UTC (11 years, 9 months ago) by tekken_boss
File MIME type: text/x-csrc
File size: 31563 byte(s)
000.001.012: 2012/08/22 16:59 : Single chip mode is implemented.

== Modification
 * [GEN] Single chip mode (Enable ROM_VERSION, default off)
      --> TO CHANGE TO SINGLE CHIP MODE
       * Enable ROM_VERSION
       * Modify Makefile to apply H8-3069_single.x as linker script.
 * [SCI] Transfer debug UI is added.

== Confirmation
 * Compilable. 



1
2 /* --------------------------------------------- */
3 /* H8-3069F Serial communicate function */
4 /* */
5 /* CPU : Renesus H8/3069F 25MHz */
6 /* Memory : ROM 512KB, RAM 16KB E-RAM 2MB */
7 /* (c) KAZ.Imamura */
8 /* --------------------------------------------- */
9
10 #include "serial.h"
11 #include "key.h"
12
13 #define READ_BUF_SIZE 16
14 #define SENT_BUF_SIZE 16
15
16 // #define RECEIVE_DATA_EVENIF_ERR
17
18 // -------------------------------------------
19 // Macros
20 // -------------------------------------------
21 typedef struct {
22 unsigned char speed_setting_index;
23 unsigned char code_setting_index;
24 unsigned char param_setting_index;
25 unsigned char flow_control_request;
26 } SCI_SETTING, *P_SCI_SETTING;
27
28 typedef struct {
29 unsigned long file_size;
30 unsigned long sent_bytes;
31 unsigned char* p_buf;
32 unsigned char tx_in_progress;
33 } TX_STATUS, *P_TX_STATUS;
34
35 // -------------------------------------------
36 // Proto type definitions
37 // -------------------------------------------
38 // Global
39 void serial_1ms_handler(void);
40 int serial_initialize(void);
41 void serial_process(void);
42 void ui_serial_progress( void );
43 unsigned char serial_status(REQUEST_TO_CLASS req);
44
45 //int ui_function_serial(UI_COMMAND uicmd);
46 void int_ERI0();
47 void int_RXI0();
48 void int_TXI0();
49 void int_TEI0();
50
51 unsigned char TransferStartRequest( unsigned char* pBuf, unsigned long size );
52 int ui_function_serial(UI_COMMAND uicmd);
53
54 // Local
55 static unsigned char Cnv2Iso( unsigned char ascii_char );
56 static unsigned char Cnv2Eia( unsigned char ascii_char );
57 static int ui_function_serial_nop(UI_COMMAND uicmd, int param);
58 static int ui_function_serial_debug(UI_COMMAND uicmd, int param);
59 static int ui_function_serial_config(UI_COMMAND uicmd, int param);
60 static int ui_function_serial_trans(UI_COMMAND uicmd, int param);
61 static int ui_function_serial_trans_debug(UI_COMMAND uicmd, int param);
62
63 // -------------------------------------------
64 // Variables
65 // -------------------------------------------
66 // Global
67 // Locals
68 static int serial_disable_timer;
69 static unsigned char serial_proc;
70 static unsigned char serial_error;
71 static unsigned char ui_serial_proc;
72
73 static SCI_SETTING sci_setting;
74 static TX_STATUS tx_status;
75 static unsigned char ReceiveBuf[READ_BUF_SIZE];
76 static unsigned char SentBuf[SENT_BUF_SIZE];
77 static unsigned char ReceiveCnt;
78 static unsigned char ReadCnt;
79 static unsigned int SCIErrorDebug;
80
81
82 enum serial_flow_ctl_req {
83 FLOW_REQ_NONE,
84 FLOW_REQ_PAUSE,
85 FLOW_REQ_RESUME,
86 };
87
88
89 enum serial_error_code {
90 SCI_ERR_NONE,
91 SCI_PROCESS_ERROR = 100,
92 };
93
94 enum serial_process_mode {
95 SCI_INITIALIZE,
96 SCI_READY_WAIT,
97 SCI_IDLE = 0x80, // Idle
98 SCI_DATA_SET,
99 SCI_WAIT_TX_OK,
100
101
102 SCI_TX_IN_PROGRESS,
103 SCI_TX_IN_PAUSE,
104 SCI_TX_IN_END,
105 SCI_ERROR_STOP = 0xFF,
106 };
107
108 static const SPEED_SETTING speed_setting[] = {
109 { COMM_SPEED_UNKNOWN, 1, 0, " ---- bps", },
110 { COMM_SPEED_1200BPS, 1, 162, " 1200 bps", },
111 { COMM_SPEED_2400BPS, 1, 80, " 2400 bps", },
112 { COMM_SPEED_4800BPS, 0, 162, " 4800 bps", },
113 { COMM_SPEED_9600BPS, 0, 80, " 9600 bps", },
114 { COMM_SPEED_19200BPS, 0, 40, " 19200 bps", },
115 { 0xFF, 0, 0, "0123456789ABCDEF", },
116 };
117 static const CODE_SETTING code_setting[] = {
118 { COMM_CODE_UNKNOWN, " Unknown", },
119 { COMM_CODE_ISO, " ISO", },
120 { COMM_CODE_EIA, " EIA", },
121 { COMM_CODE_ASCII, " ASCII", },
122 { 0xFF, "0123456789ABCDEF", },
123 };
124
125 static const PARAM_SETTING param_setting[] = {
126 { COMM_PARAM_UNKNOWN, 0x00, " Unknown ", },
127 { COMM_PARAM_8BIT_NONPARITY_STOP1, 0x00, " 8bit/NonP/Stop1", }, // SMR=0000 00.. << Default
128 { COMM_PARAM_8BIT_NONPARITY_STOP2, 0x08, " 8bit/NonP/Stop2", }, // SMR=0000 10..
129 { COMM_PARAM_8BIT_ODDPARITY_STOP1, 0x30, " 8bit/OddP/Stop1", }, // SMR=0011 00..
130 { COMM_PARAM_8BIT_ODDPARITY_STOP2, 0x38, " 8bit/OddP/Stop2", }, // SMR=0011 10..
131 { COMM_PARAM_8BIT_EVNPARITY_STOP1, 0x20, " 8bit/EvnP/Stop1", }, // SMR=0010 00..
132 { COMM_PARAM_8BIT_EVNPARITY_STOP2, 0x28, " 8bit/EvnP/Stop2", }, // SMR=0010 10..
133 { COMM_PARAM_7BIT_NONPARITY_STOP1, 0x40, " 7bit/NonP/Stop1", }, // SMR=0100 00..
134 { COMM_PARAM_7BIT_NONPARITY_STOP2, 0x48, " 7bit/NonP/Stop2", }, // SMR=0100 10..
135 { COMM_PARAM_7BIT_ODDPARITY_STOP1, 0x70, " 7bit/OddP/Stop1", }, // SMR=0111 00..
136 { COMM_PARAM_7BIT_ODDPARITY_STOP2, 0x78, " 7bit/OddP/Stop2", }, // SMR=0111 10..
137 { COMM_PARAM_7BIT_EVNPARITY_STOP1, 0x60, " 7bit/EvnP/Stop1", }, // SMR=0110 00..
138 { COMM_PARAM_7BIT_EVNPARITY_STOP2, 0x68, " 7bit/EvnP/Stop2", }, // SMR=0110 10..
139 { 0xFF, 0, "0123456789ABCDEF", },
140 };
141
142 static const MODULE_MENU_TABLE serial_app_table[] = { // interval time will be ignored.
143 { 0, 0, ui_function_serial_debug, " Debug ", },
144 { 1, 0, ui_function_serial_config, " Config ", },
145 { 2, 0, ui_function_serial_trans, " Transfer ", },
146 { 3, 0, ui_function_serial_trans_debug, " Transfer(Dbg) ", },
147 { -1, 0, ui_function_serial_nop, "0123456789ABCDEF", },
148 };
149
150 static const DEBUG_VAR_TABLE debug_var_table[] = {
151 { 0, 1, "Process number: ", &serial_proc, },
152 { 1, 1, "Error Code: ", &serial_error, },
153 { 2, 2, "Int. Err Debug: ", &SCIErrorDebug, },
154 { 3, 3, "txsts.sentbytes:", &tx_status.sent_bytes, },
155 { 4, 3, "txsts.file_size:", &tx_status.file_size, },
156 { 5, 4, "Receive Buffer: ", ReceiveBuf, },
157 { 6, 4, "Sent Buffer: ", SentBuf, },
158 { -1, 1, "0123456789ABCDEF", 0, },
159 };
160
161 // Only for this table, "type" member SHOULD BE index number.
162 static const DEBUG_VAR_TABLE config_var_table[] = {
163 { 0, 0, "Speed setting : ", &sci_setting.speed_setting_index },
164 { 1, 1, "Code setting: ", &sci_setting.code_setting_index },
165 { 2, 2, "COM Parameter: ", &sci_setting.param_setting_index },
166 { -1, 1, "0123456789ABCDEF", 0, },
167 };
168
169 // -------------------------------------------
170 // Interrupt handlers (1ms)
171 // -------------------------------------------
172 void serial_1ms_handler(void) {
173 if( serial_disable_timer ) serial_disable_timer--;
174 }
175
176 // -------------------------------------------
177 // Interrupt handlers (SCI Error)
178 // -------------------------------------------
179 #pragma interrupt (int_ERI0)
180 void int_ERI0(void) {
181 if(SCI0.SSR.BIT.FER) {
182 SCI0.SSR.BIT.FER = 0;
183 SCIErrorDebug++;
184 }
185 if(SCI0.SSR.BIT.ORER) {
186 SCI0.SSR.BIT.ORER = 0;
187 SCIErrorDebug += 0x10;
188 }
189 if(SCI0.SSR.BIT.PER) {
190 SCI0.SSR.BIT.PER = 0;
191 SCIErrorDebug+=0x100;
192 #ifdef RECEIVE_DATA_EVENIF_ERR
193 ReceiveBuf[ReceiveCnt] = SCI0.RDR; // �f�[�^���M
194 // DC code was refered from http://www5a.biglobe.ne.jp/~NCPRO/pc_nc.htm.
195 if( ReceiveBuf[ReceiveCnt] == 0x11
196 || ReceiveBuf[ReceiveCnt] == 0xA5
197 || ReceiveBuf[ReceiveCnt] == 0x25 ) {
198 sci_setting.flow_control_request = FLOW_REQ_RESUME;
199 } else if( ReceiveBuf[ReceiveCnt] == 0x93
200 || ReceiveBuf[ReceiveCnt] == 0x13
201 || ReceiveBuf[ReceiveCnt]== 0x14 ) {
202 sci_setting.flow_control_request = FLOW_REQ_PAUSE;
203 } else {
204 sci_setting.flow_control_request = FLOW_REQ_NONE;
205 }
206 if( ++ReceiveCnt >= READ_BUF_SIZE ) ReceiveCnt = 0;
207 if(SCI0.SSR.BIT.PER) SCI0.SSR.BIT.RDRF = 0;
208 #endif
209
210 }
211 }
212
213 // -------------------------------------------
214 // Interrupt handlers (SCI RX data ready)
215 // -------------------------------------------
216 #pragma interrupt (int_RXI0)
217 void int_RXI0(void) {
218 if(SCI0.SSR.BIT.RDRF) {
219 ReceiveBuf[ReceiveCnt] = SCI0.RDR; // �f�[�^���M
220
221 // DC code was refered from http://www5a.biglobe.ne.jp/~NCPRO/pc_nc.htm.
222 if( ReceiveBuf[ReceiveCnt] == 0x11
223 || ReceiveBuf[ReceiveCnt] == 0xA5
224 || ReceiveBuf[ReceiveCnt] == 0x25 ) {
225 sci_setting.flow_control_request = FLOW_REQ_RESUME;
226 } else if( ReceiveBuf[ReceiveCnt] == 0x93
227 || ReceiveBuf[ReceiveCnt] == 0x13
228 || ReceiveBuf[ReceiveCnt]== 0x14 ) {
229 sci_setting.flow_control_request = FLOW_REQ_PAUSE;
230 } else {
231 sci_setting.flow_control_request = FLOW_REQ_NONE;
232 }
233
234 if( ++ReceiveCnt >= READ_BUF_SIZE ) ReceiveCnt = 0;
235 }
236 SCI0.SSR.BIT.RDRF = 0;
237
238 }
239
240 // -------------------------------------------
241 // Interrupt handlers (SCI TX Buffer ready)
242 // -------------------------------------------
243 #pragma interrupt (int_TXI0)
244 void int_TXI0(void) {
245 // if( serial_proc == SCI_TX_IN_PROGRESS ) {
246 if( serial_proc == SCI_WAIT_TX_OK ) {
247 if(SCI0.SSR.BIT.TDRE) {
248 /*
249 if( sci_setting.flow_control_request == FLOW_REQ_PAUSE ) {
250 sci_setting.flow_control_request = FLOW_REQ_NONE;
251 serial_proc = SCI_TX_IN_PAUSE;
252 tx_status.sent_bytes++;
253 SCI0.SCR.BIT.TIE = 0; // TX empty intr. disable
254 } else if( tx_status.sent_bytes < tx_status.file_size ) {
255 switch( sci_setting.code_setting_index ) {
256 case COMM_CODE_ISO:
257 SCI0.TDR = Cnv2Iso( (unsigned char) tx_status.p_buf[tx_status.sent_bytes++]);
258 break;
259 case COMM_CODE_EIA:
260 SCI0.TDR = Cnv2Eia( (unsigned char) tx_status.p_buf[tx_status.sent_bytes++]);
261 break;
262 default:
263 SCI0.TDR = (unsigned char) tx_status.p_buf[tx_status.sent_bytes++];
264 break;
265 }
266 SentBuf[tx_status.sent_bytes&0x0F] = SCI0.TDR;
267 } else {
268 SCI0.SCR.BIT.TIE = 0; // TX empty intr. disable
269 }
270 */
271 tx_status.tx_in_progress = 0;
272 SCI0.SCR.BIT.TIE = 0;
273 }
274 } else {
275 SCI0.SCR.BIT.TIE = 0;
276 }
277
278 }
279
280 // -------------------------------------------
281 // Interrupt handlers (SCI TX End)
282 // -------------------------------------------
283 #pragma interrupt (int_TEI0)
284 void int_TEI0(void) {
285 if(SCI0.SSR.BIT.TEND) SCI0.SSR.BIT.TEND = 0;
286 }
287
288 // -------------------------------------------
289 // Initialize
290 // -------------------------------------------
291 int serial_initialize(void) {
292 serial_proc = SCI_INITIALIZE;
293 serial_error = SCI_ERR_NONE;
294 SCIErrorDebug = 0;
295
296 // Default setting
297 sci_setting.speed_setting_index = COMM_SPEED_4800BPS;
298 sci_setting.code_setting_index = COMM_CODE_ASCII;
299 sci_setting.param_setting_index = COMM_PARAM_7BIT_EVNPARITY_STOP2;
300 sci_setting.flow_control_request = FLOW_REQ_NONE;
301 // UI related
302 ui_serial_proc = 0x00;
303 }
304
305 // -------------------------------------------
306 // Query for FAT class status
307 // -------------------------------------------
308 unsigned char serial_status(REQUEST_TO_CLASS req) {
309 switch( req ) {
310 case CLASS_REQ_RESET:
311 serial_initialize();
312 return CLASS_STS_RESET_IN_PROGRESS;
313
314 default:
315 break;
316 }
317
318 // Status return
319 if( serial_proc < SCI_IDLE ) return CLASS_STS_RESET_IN_PROGRESS;
320 else if( serial_proc == SCI_IDLE ) return CLASS_STS_READY;
321 else if( serial_proc == SCI_ERROR_STOP ) return CLASS_STS_ERROR_STOP;
322 else return CLASS_STS_NOT_READY;
323 }
324
325 // -------------------------------------------
326 // Transfer Start Request
327 // -------------------------------------------
328 unsigned char TransferStartRequest( unsigned char* pBuf, unsigned long size ) {
329 if( serial_proc != SCI_IDLE && serial_proc != SCI_TX_IN_PAUSE ) return CLASS_REQ_BUSY;
330
331 if( size != 0 ) { // Start request
332 tx_status.file_size = size;
333 tx_status.sent_bytes = 0;
334 tx_status.p_buf = pBuf;
335 tx_status.tx_in_progress = 0;
336 serial_proc = SCI_DATA_SET;
337 sci_setting.flow_control_request = FLOW_REQ_PAUSE;
338 #ifdef SCI_DEBUG_ON
339 printf("[SCI] TX Req Set\r\n");
340 #endif
341 }
342 /*
343 else { // Continue request
344 serial_proc = SCI_TX_IN_PROGRESS;
345 // Transfer start
346 switch( sci_setting.code_setting_index ) {
347 case COMM_CODE_ISO:
348 SCI0.TDR = Cnv2Iso( (unsigned char) tx_status.p_buf[tx_status.sent_bytes++]);
349 break;
350 case COMM_CODE_EIA:
351 SCI0.TDR = Cnv2Eia( (unsigned char) tx_status.p_buf[tx_status.sent_bytes++]);
352 break;
353 default:
354 SCI0.TDR = (unsigned char) tx_status.p_buf[tx_status.sent_bytes++];
355 break;
356 }
357 SentBuf[tx_status.sent_bytes&0x0F] = SCI0.TDR;
358
359 if(SCI0.SSR.BIT.TDRE) SCI0.SSR.BIT.TDRE = 0; // TX empty intr. clear
360 SCI0.SCR.BIT.TIE = 1; // TX empty intr. enable
361 }
362 */
363 }
364
365 // -------------------------------------------
366 // Main process
367 // -------------------------------------------
368 void serial_process( void ) {
369 int i;
370 if( serial_disable_timer ) return;
371
372 switch( serial_proc ) {
373 case SCI_INITIALIZE:
374 SCI0.SCR.BYTE = 0x00; // Clear firstly. RX/TX stop
375
376 SCI0.SMR.BYTE = param_setting[sci_setting.param_setting_index].smr_setting
377 | speed_setting[sci_setting.speed_setting_index].cks_setting;
378 SCI0.BRR = speed_setting[sci_setting.speed_setting_index].brr_setting;
379
380 for(i=0; i<READ_BUF_SIZE; i++) ReceiveBuf[i] = 0x00;
381 for(i=0; i<SENT_BUF_SIZE; i++) SentBuf[i] = 0x00;
382 ReceiveCnt = 0;
383 ReadCnt = 0;
384 serial_proc = SCI_READY_WAIT;
385 serial_disable_timer = 10;
386 break;
387
388 case SCI_READY_WAIT:
389 SCI0.SCR.BIT.TE = 1; //TX OK
390 SCI0.SCR.BIT.RE = 1; //RX OK
391 SCI0.SCR.BIT.TIE = 1; //TX Interrupt enable
392 SCI0.SCR.BIT.RIE = 1; //RX Interrupt enable
393 serial_proc = SCI_IDLE;
394 break;
395
396 case SCI_IDLE:
397 break;
398
399 case SCI_DATA_SET:
400 if( sci_setting.flow_control_request != FLOW_REQ_PAUSE ) {
401 // 1 byte Transfer start
402 switch( sci_setting.code_setting_index ) {
403 case COMM_CODE_ISO:
404 SCI0.TDR = Cnv2Iso( (unsigned char) tx_status.p_buf[tx_status.sent_bytes++]);
405 break;
406 case COMM_CODE_EIA:
407 SCI0.TDR = Cnv2Eia( (unsigned char) tx_status.p_buf[tx_status.sent_bytes++]);
408 break;
409 default:
410 SCI0.TDR = (unsigned char) tx_status.p_buf[tx_status.sent_bytes++];
411 break;
412 }
413 serial_proc = SCI_WAIT_TX_OK;
414 serial_disable_timer = 2;
415 SentBuf[tx_status.sent_bytes&0x0F] = SCI0.TDR;
416 tx_status.tx_in_progress = 1;
417
418 if(SCI0.SSR.BIT.TDRE) SCI0.SSR.BIT.TDRE = 0; // TX empty intr. clear
419 SCI0.SCR.BIT.TIE = 1; // TX empty intr. enable
420 }
421 break;
422
423 case SCI_WAIT_TX_OK:
424 if( tx_status.tx_in_progress ) break;
425 if( tx_status.sent_bytes >= tx_status.file_size ) {
426 SCI0.SCR.BIT.TIE = 0; //TX empty Interrupt disable
427 serial_proc = SCI_TX_IN_END;
428 serial_disable_timer = 1000;
429 } else {
430 serial_proc = SCI_DATA_SET;
431 }
432 break;
433
434 case SCI_TX_IN_PROGRESS:
435 if( tx_status.sent_bytes >= tx_status.file_size ) {
436 SCI0.SCR.BIT.TIE = 0; //TX empty Interrupt disable
437 serial_proc = SCI_TX_IN_END;
438 serial_disable_timer = 1000;
439 }
440 break;
441
442 case SCI_TX_IN_PAUSE:
443 if( sci_setting.flow_control_request == FLOW_REQ_RESUME ) {
444 sci_setting.flow_control_request = FLOW_REQ_NONE;
445 TransferStartRequest(0, 0);
446 }
447 break;
448
449 case SCI_TX_IN_END:
450 #ifdef SCI_DEBUG_ON
451 printf("[SCI] TX Complete\r\n");
452 #endif
453 serial_proc = SCI_IDLE;
454 break;
455
456 case SCI_ERROR_STOP:
457 break;
458 }
459 }
460
461 // -------------------------------------------
462 // Convert to ISO code
463 // -------------------------------------------
464 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
465 unsigned char bitnum[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
466 static unsigned char Cnv2Iso( unsigned char ascii_char ) {
467 unsigned char num;
468
469 // num = bitnum[(ascii_char>>4)&0x0F] + bitnum[ascii_char&0x0F];
470
471 num = 0;
472 if( ascii_char & 0x80 ) num++;
473 if( ascii_char & 0x40 ) num++;
474 if( ascii_char & 0x20 ) num++;
475 if( ascii_char & 0x10 ) num++;
476 if( ascii_char & 0x08 ) num++;
477 if( ascii_char & 0x04 ) num++;
478 if( ascii_char & 0x02 ) num++;
479 if( ascii_char & 0x01 ) num++;
480
481 if( num&0x01 )
482 return (0x80|ascii_char);
483 else
484 return ascii_char;
485 }
486
487 // -------------------------------------------
488 // Convert to EIA code
489 // -------------------------------------------
490 unsigned char table_EIA[256] =
491 { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x2A,0x3E,0x80,0x0B,0x0C,0x0D,0x0E,0x0F, // 0x00
492 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, // 0x10
493 0x10,0x21,0x22,0x23,0x94,0x0B,0x0E,0x27,0x1A,0x4A,0x98,0x70,0x3B,0x40,0x6B,0x31, // 0x20
494 0x20,0x01,0x02,0x13,0x04,0x15,0x16,0x07,0x08,0x19,0x3A,0x3B,0x3C,0x8C,0x3E,0x9E, // 0x30 0-9(39)
495 0x8F,0x61,0x62,0x73,0x64,0x75,0x76,0x67,0x68,0x79,0x51,0x52,0x43,0x54,0x45,0x46, // 0x40 A(41)-O
496 0x57,0x58,0x49,0x32,0x23,0x34,0x25,0x26,0x37,0x38,0x29,0xB0,0x5C,0xA2,0x5E,0x5F, // 0x50 P-Z(5A)
497 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F, // 0x60
498 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F, // 0x70
499 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, // 0x80
500 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, // 0x90
501 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, // 0xA0
502 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, // 0xB0
503 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, // 0xC0
504 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, // 0xD0
505 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, // 0xE0
506 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF }; // 0xF0
507 static unsigned char Cnv2Eia( unsigned char ascii_char ) {
508 return table_EIA[ascii_char];
509 }
510
511
512 // -------------------------------------------
513 // UI Function - Serial function
514 // -------------------------------------------
515 int ui_function_serial(UI_COMMAND uicmd) {
516 static unsigned int current_index;
517 static unsigned int cursol_position;
518 int ret_val;
519 UI_COMMAND ui_cmd_sub;
520
521 ret_val = UI_RET_READY;
522
523 switch( ui_serial_proc ) {
524 case 0x00:
525 // Event check
526 switch( uicmd.cmd ) {
527 case UI_CMD_NOP:
528 case UI_CMD_INTEVAL:
529 break;
530
531 case UI_CMD_STARTED:
532 current_index = 0;
533 cursol_position = 0;
534 break;
535
536 case UI_CMD_KEY_PRESS_BACK:
537 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
538 ret_val = UI_RET_QUIT;
539 break;
540
541 case UI_CMD_KEY_PRESS_UP:
542 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
543 if( cursol_position == 1 ) {
544 cursol_position = 0;
545 current_index--;
546 } else {
547 if( current_index != 0 ) current_index--;
548 }
549 break;
550 case UI_CMD_KEY_PRESS_DOWN:
551 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
552 if( cursol_position == 0 ) {
553 cursol_position = 1;
554 current_index++;
555 } else {
556 if( serial_app_table[current_index+1].num != -1 ) current_index++;
557 }
558 break;
559 case UI_CMD_KEY_PRESS_OK:
560 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
561 ui_cmd_sub.cmd = UI_CMD_STARTED;
562 serial_app_table[current_index].pExecFunc(ui_cmd_sub, serial_app_table[current_index].param); // Initialize
563 ui_serial_proc = 0x01;
564 break;
565 }
566
567 // Menu view
568 if( cursol_position == 0) { // cursol in first line
569 sc1602_set_buffer_cursol( 0, serial_app_table[current_index ].display );
570 sc1602_set_buffer ( 1, serial_app_table[current_index+1].display );
571 } else {
572 sc1602_set_buffer ( 0, serial_app_table[current_index-1].display );
573 sc1602_set_buffer_cursol( 1, serial_app_table[current_index ].display );
574 }
575 break;
576
577 case 0x01:
578 switch( serial_app_table[current_index].pExecFunc(uicmd, serial_app_table[current_index].param) ) {
579 case UI_RET_QUIT:
580 ui_serial_proc = 0x00;
581 break;
582 default:
583 break;
584 }
585 break;
586 default:
587 break;
588 }
589 return ret_val;
590 }
591
592
593 // -------------------------------------------
594 // UI Function - SERIAL debug
595 // -------------------------------------------
596 static int ui_function_serial_debug(UI_COMMAND uicmd, int param) {
597 static unsigned char current_index;
598 static unsigned char ok_press;
599 int ret_val;
600
601 ret_val = UI_RET_READY;
602
603 switch( uicmd.cmd ) {
604 case UI_CMD_NOP:
605 break;
606
607 case UI_CMD_KEY_PRESS_OK:
608 if( uicmd.param == OFF_EDGE ) ok_press = 0;
609 else ok_press = 1;
610 break;
611
612 case UI_CMD_INTEVAL:
613 // Title
614 sc1602_set_buffer( 0, debug_var_table[current_index].display );
615 switch(debug_var_table[current_index].type) {
616 case 1:
617 sc1602_set_buffer_variable1 ( 1, debug_var_table[current_index].p_variable );
618 break;
619 case 2:
620 sc1602_set_buffer_variable2 ( 1, debug_var_table[current_index].p_variable );
621 break;
622 case 3:
623 sc1602_set_buffer_variable3 ( 1, debug_var_table[current_index].p_variable );
624 break;
625 case 4:
626 sc1602_set_buffer_dump (1, debug_var_table[current_index].p_variable );
627 break;
628 }
629 break;
630
631 case UI_CMD_STARTED:
632 current_index = 0;
633 ok_press = 0;
634 break;
635
636 case UI_CMD_KEY_PRESS_UP:
637 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
638 if( current_index != 0 ) current_index--;
639 break;
640 case UI_CMD_KEY_PRESS_DOWN:
641 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
642 if( ok_press == 0 ) {
643 if( debug_var_table[current_index+1].num != -1 ) current_index++;
644 } else {
645 // TODO
646 }
647 break;
648 case UI_CMD_KEY_PRESS_BACK:
649 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
650 ret_val = UI_RET_QUIT;
651 break;
652 }
653 return ret_val;
654 }
655
656 // -------------------------------------------
657 // UI Function - SERIAL config
658 // -------------------------------------------
659 static int ui_function_serial_config(UI_COMMAND uicmd, int param) {
660 static unsigned char current_index;
661 int ret_val;
662
663 ret_val = UI_RET_READY;
664
665 switch( uicmd.cmd ) {
666 case UI_CMD_NOP:
667 break;
668
669 case UI_CMD_KEY_PRESS_OK:
670 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
671 switch( current_index ) {
672 case 0:
673 sci_setting.speed_setting_index++;
674 if( speed_setting[sci_setting.speed_setting_index].index == 0xFF )
675 sci_setting.speed_setting_index = 0x01;
676 break;
677 case 1:
678 sci_setting.code_setting_index++;
679 if( code_setting[sci_setting.code_setting_index].index == 0xFF )
680 sci_setting.code_setting_index = 0x01;
681 break;
682 case 2:
683 sci_setting.param_setting_index++;
684 if( param_setting[sci_setting.param_setting_index].index == 0xFF )
685 sci_setting.param_setting_index = 0x01;
686 break;
687 default:
688 break;
689 }
690 break;
691
692 case UI_CMD_INTEVAL:
693 // Title
694 sc1602_set_buffer( 0, config_var_table[current_index].display );
695 switch( current_index ) {
696 case 0:
697 sc1602_set_buffer ( 1, speed_setting[sci_setting.speed_setting_index].Name );
698 break;
699 case 1:
700 sc1602_set_buffer ( 1, code_setting[sci_setting.code_setting_index].Name );
701 break;
702 case 2:
703 sc1602_set_buffer ( 1, param_setting[sci_setting.param_setting_index].Name );
704 break;
705 }
706 break;
707
708 case UI_CMD_STARTED:
709 current_index = 0;
710 break;
711
712 case UI_CMD_KEY_PRESS_UP:
713 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
714 if( current_index != 0 ) current_index--;
715 break;
716 case UI_CMD_KEY_PRESS_DOWN:
717 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
718 if( config_var_table[current_index+1].num != -1 ) current_index++;
719 break;
720 case UI_CMD_KEY_PRESS_BACK:
721 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
722 ret_val = UI_RET_QUIT;
723 break;
724 }
725 return ret_val;
726 }
727
728 // -------------------------------------------
729 // UI Function - SERIAL trans
730 // -------------------------------------------
731 static int ui_function_serial_trans(UI_COMMAND uicmd, int param) {
732 static unsigned char current_index;
733 static unsigned char ok_press;
734 int ret_val;
735
736 ret_val = UI_RET_READY;
737
738 switch( uicmd.cmd ) {
739 case UI_CMD_NOP:
740 break;
741
742 case UI_CMD_KEY_PRESS_OK:
743 if( uicmd.param == OFF_EDGE ) ok_press = 0;
744 else ok_press = 1;
745 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
746
747 break;
748
749 case UI_CMD_INTEVAL:
750 // Title
751 switch( serial_proc ) {
752 case SCI_INITIALIZE:
753 case SCI_ERROR_STOP:
754 case SCI_READY_WAIT:
755 sc1602_set_buffer( 0, "SCI is not ready" );
756 break;
757
758 case SCI_IDLE:
759 sc1602_set_buffer( 0, "SCI is ready. " );
760 break;
761
762 case SCI_DATA_SET:
763 case SCI_WAIT_TX_OK:
764 if( sci_setting.flow_control_request == FLOW_REQ_PAUSE ) sc1602_set_buffer( 0, "Pause.... " );
765 else sc1602_set_buffer( 0, "Sending... " );
766 break;
767
768 case SCI_TX_IN_PROGRESS:
769 sc1602_set_buffer( 0, "Sending... " );
770 break;
771
772 case SCI_TX_IN_PAUSE:
773 sc1602_set_buffer( 0, "Pause.... " );
774 break;
775
776 case SCI_TX_IN_END:
777 sc1602_set_buffer( 0, "Complete! " );
778 break;
779 }
780 sc1602_set_buffer_progress_kb(1, tx_status.sent_bytes, tx_status.file_size);
781 break;
782
783 case UI_CMD_STARTED:
784 current_index = 0;
785 ok_press = 0;
786 break;
787
788 case UI_CMD_KEY_PRESS_UP:
789 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
790 if( current_index != 0 ) current_index--;
791 break;
792 case UI_CMD_KEY_PRESS_DOWN:
793 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
794 if( ok_press == 0 ) {
795 if( debug_var_table[current_index+1].num != -1 ) current_index++;
796 } else {
797 // TODO
798 }
799 break;
800 case UI_CMD_KEY_PRESS_BACK:
801 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
802 ret_val = UI_RET_QUIT;
803 break;
804 }
805 return ret_val;
806 }
807
808 static const char hex2ascii[] = "0123456789ABCDEF";
809 // -------------------------------------------
810 // UI Function - SERIAL trans (debug)
811 // -------------------------------------------
812 static int ui_function_serial_trans_debug(UI_COMMAND uicmd, int param) {
813 static unsigned char current_index;
814 static unsigned char ok_press;
815 unsigned char *data;
816 int ret_val;
817 unsigned int uint_val;
818 char tempbuf[2][16];
819 // 0123456789ABCDEF
820 // ----------------
821 // R[?]:........|**
822 // S..C..P.. ...%
823 tempbuf[0][0x0]='R'; tempbuf[0][0x1]='['; tempbuf[0][0x2]=' '; tempbuf[0][0x3]=']';
824 tempbuf[0][0x4]=' '; tempbuf[0][0x5]=' '; tempbuf[0][0x6]=' '; tempbuf[0][0x7]=' ';
825 tempbuf[0][0x8]=' '; tempbuf[0][0x9]=' '; tempbuf[0][0xA]=' '; tempbuf[0][0xB]=' ';
826 tempbuf[0][0xC]=' '; tempbuf[0][0xD]='|'; tempbuf[0][0xE]=' '; tempbuf[0][0xF]=' ';
827
828 tempbuf[1][0x0]='S'; tempbuf[1][0x1]=' '; tempbuf[1][0x2]=' '; tempbuf[1][0x3]='C';
829 tempbuf[1][0x4]=' '; tempbuf[1][0x5]=' '; tempbuf[1][0x6]='P'; tempbuf[1][0x7]=' ';
830 tempbuf[1][0x8]=' '; tempbuf[1][0x9]=' '; tempbuf[1][0xA]=' '; tempbuf[1][0xB]=' ';
831 tempbuf[1][0xC]=' '; tempbuf[1][0xD]=' '; tempbuf[1][0xE]=' '; tempbuf[1][0xF]='%';
832
833
834 ret_val = UI_RET_READY;
835
836 switch( uicmd.cmd ) {
837 case UI_CMD_NOP:
838 break;
839
840 case UI_CMD_KEY_PRESS_OK:
841 if( uicmd.param == OFF_EDGE ) ok_press = 0;
842 else ok_press = 1;
843 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
844 break;
845
846 case UI_CMD_INTEVAL:
847 // Title
848 switch( serial_proc ) {
849 case SCI_INITIALIZE:
850 case SCI_ERROR_STOP:
851 case SCI_READY_WAIT:
852 //sc1602_set_buffer( 0, "SCI is not ready" );
853 tempbuf[0][0xE]='N'; tempbuf[0][0xF]='R'; // NR / Not ready
854 break;
855
856 case SCI_IDLE:
857 //sc1602_set_buffer( 0, "SCI is ready. " );
858 tempbuf[0][0xE]='R'; tempbuf[0][0xF]='D'; // RD / Ready
859 break;
860
861 case SCI_DATA_SET:
862 case SCI_WAIT_TX_OK:
863 if( sci_setting.flow_control_request == FLOW_REQ_PAUSE )
864 /*sc1602_set_buffer( 0, "Pause.... " );*/ {tempbuf[0][0xE]='P'; tempbuf[0][0xF]='S';} // PS / Pause
865 else
866 /*sc1602_set_buffer( 0, "Sending... " );*/ {tempbuf[0][0xE]='S'; tempbuf[0][0xF]='D';} // SD / Sending
867 break;
868
869 case SCI_TX_IN_PROGRESS:
870 //sc1602_set_buffer( 0, "Sending... " );
871 tempbuf[0][0xE]='S'; tempbuf[0][0xF]='D'; // SD / Sending
872 break;
873
874 case SCI_TX_IN_PAUSE:
875 //sc1602_set_buffer( 0, "Pause.... " );
876 tempbuf[0][0xE]='P'; tempbuf[0][0xF]='S'; // PS / Pause
877 break;
878
879 case SCI_TX_IN_END:
880 //sc1602_set_buffer( 0, "Complete! " );
881 tempbuf[0][0xE]='P'; tempbuf[0][0xF]='S'; // DN / Complete
882 break;
883 }
884
885 // Read buf dump
886 data = &ReceiveBuf[(ReceiveCnt&0x03)];
887 tempbuf[0][0x2] = hex2ascii[ReceiveCnt & 0x0F ];
888 tempbuf[0][0x5] = hex2ascii[(*(data + 0) >> 4) & 0x0F ];
889 tempbuf[0][0x6] = hex2ascii[(*(data + 0) ) & 0x0F ];
890 tempbuf[0][0x7] = hex2ascii[(*(data + 1) >> 4) & 0x0F ];
891 tempbuf[0][0x8] = hex2ascii[(*(data + 1) ) & 0x0F ];
892 tempbuf[0][0x9] = hex2ascii[(*(data + 2) >> 4) & 0x0F ];
893 tempbuf[0][0xA] = hex2ascii[(*(data + 2) ) & 0x0F ];
894 tempbuf[0][0xB] = hex2ascii[(*(data + 3) >> 4) & 0x0F ];
895 tempbuf[0][0xC] = hex2ascii[(*(data + 3) ) & 0x0F ];
896
897 // Registers
898 tempbuf[1][0x1] = hex2ascii[(SCI0.SSR.BYTE >> 4) & 0x0F ];
899 tempbuf[1][0x2] = hex2ascii[(SCI0.SSR.BYTE ) & 0x0F ];
900 tempbuf[1][0x4] = hex2ascii[(SCI0.SCR.BYTE >> 4) & 0x0F ];
901 tempbuf[1][0x5] = hex2ascii[(SCI0.SCR.BYTE ) & 0x0F ];
902 tempbuf[1][0x7] = hex2ascii[(serial_proc >> 4) & 0x0F ];
903 tempbuf[1][0x8] = hex2ascii[(serial_proc ) & 0x0F ];
904
905 // Percentage
906 uint_val = (unsigned int) (tx_status.sent_bytes/tx_status.file_size)*100;
907 tempbuf[1][0xC] = hex2ascii[(uint_val/100) % 10 ];
908 tempbuf[1][0xD] = hex2ascii[(uint_val/10) % 10 ];
909 tempbuf[1][0xE] = hex2ascii[(uint_val) % 10 ];
910
911 sc1602_set_buffer(0,tempbuf[0]);
912 sc1602_set_buffer(1,tempbuf[1]);
913 break;
914
915 case UI_CMD_STARTED:
916 current_index = 0;
917 ok_press = 0;
918 break;
919
920 case UI_CMD_KEY_PRESS_UP:
921 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
922 if( current_index != 0 ) current_index--;
923 break;
924
925 case UI_CMD_KEY_PRESS_DOWN:
926 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
927 if( ok_press == 0 ) {
928 if( debug_var_table[current_index+1].num != -1 ) current_index++;
929 } else {
930 // TODO
931 }
932 break;
933
934 case UI_CMD_KEY_PRESS_BACK:
935 if( uicmd.param == OFF_EDGE ) break; // Ignore off edge
936 ret_val = UI_RET_QUIT;
937 break;
938 }
939 return ret_val;
940 }
941
942 // -------------------------------------------
943 // UI Sub Function - SERIAL nop
944 // -------------------------------------------
945 static int ui_function_serial_nop(UI_COMMAND uicmd, int param) {
946 return UI_RET_QUIT;
947 }
948
949
950 // -------------------------------------------
951 // UI service Function - SERIAL progress
952 // -------------------------------------------
953 void ui_serial_progress( void ) {
954 // Title
955 switch( serial_proc ) {
956 case SCI_INITIALIZE:
957 case SCI_ERROR_STOP:
958 case SCI_READY_WAIT:
959 sc1602_set_buffer( 0, "SCI is not ready" );
960 break;
961
962 case SCI_IDLE:
963 sc1602_set_buffer( 0, "SCI is ready. " );
964 break;
965
966 case SCI_DATA_SET:
967 case SCI_WAIT_TX_OK:
968 if( sci_setting.flow_control_request == FLOW_REQ_PAUSE ) sc1602_set_buffer( 0, "Pause.... " );
969 else sc1602_set_buffer( 0, "Sending... " );
970 break;
971
972 case SCI_TX_IN_PROGRESS:
973 sc1602_set_buffer( 0, "Sending... " );
974 break;
975
976 case SCI_TX_IN_PAUSE:
977 sc1602_set_buffer( 0, "Pause.... " );
978 break;
979
980 case SCI_TX_IN_END:
981 sc1602_set_buffer( 0, "Complete! " );
982 break;
983 }
984 sc1602_set_buffer_progress_kb(1, tx_status.sent_bytes, tx_status.file_size);
985 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26