add initial support for the crisarchitecture used on foxboards to openwrt
[openwrt/staging/dedeckeh.git] / target / linux / etrax-2.6 / image / e100boot / src / cbl / src / ser_init.c
1 #define ser_init init_interface
2 #define handle_serial_read handle_read
3 #define send_serial_ack send_ack
4 #define send_serial_string send_string
5 #define send_serial_hex send_hex
6
7 #include "hwregs.h"
8 #include "sv_addr_ag.h"
9 #include "e100boot.h"
10
11 void
12 ser_init(void)
13 {
14 REG_SET__R_SERIAL0_XOFF
15 (
16 tx_stop, enable,
17 auto_xoff, disable,
18 xoff_char, 0
19 );
20
21 REG_SET__R_SERIAL0_BAUD
22 (
23 tr_baud, c9600Hz,
24 rec_baud, c9600Hz
25 );
26
27 REG_SET__R_SERIAL0_REC_CTRL
28 (
29 dma_err, stop,
30 rec_enable, enable,
31 rts_, inactive,
32 sampling, middle,
33 rec_stick_par, normal,
34 rec_par, even,
35 rec_par_en, disable,
36 rec_bitnr, rec_8bit
37 );
38
39 REG_SET__R_SERIAL0_TR_CTRL
40 (
41 txd, 0,
42 tr_enable, enable,
43 auto_cts, disabled,
44 stop_bits, one_bit,
45 tr_stick_par, normal,
46 tr_par, even,
47 tr_par_en, disable,
48 tr_bitnr, tr_8bit
49 );
50
51 serial_up = TRUE;
52 }
53
54 #define SER_MASK (IO_MASK(R_SERIAL0_READ, data_avail) | IO_MASK(R_SERIAL0_READ, data_in))
55
56 int
57 handle_serial_read(void)
58 {
59 udword status_and_data_in = *R_SERIAL0_READ & SER_MASK;
60
61 if (status_and_data_in & IO_STATE(R_SERIAL0_READ, data_avail, yes)) {
62 *(char*)(target_address + nbr_read++) = status_and_data_in & 0xff; /* ugly mask */
63 last_timeout = REG_GET(R_TIMER0_DATA, count);
64 return TRUE;
65 }
66
67 return FALSE;
68 }
69
70 void
71 send_serial_ack(void)
72 {
73 while (!REG_EQL(R_SERIAL0_STATUS, tr_ready, ready))
74 ;
75
76 REG_ISET(0, R_SERIAL0_TR_DATA, data_out, '+');
77 }
78
79 void
80 send_serial_string(char *str)
81 {
82 int i;
83
84 for (i = 0; str[i];) {
85 if (REG_IEQL(0, R_SERIAL0_STATUS, tr_ready, ready)) {
86 REG_ISET(0, R_SERIAL0_TR_DATA, data_out, str[i]);
87 i++;
88 }
89 }
90 }
91
92 void
93 send_serial_hex(udword v, byte nl)
94 {
95 int i;
96 byte buf[13];
97 byte nybble;
98
99 buf[0] = '0';
100 buf[1] = 'x';
101 buf[10] = '\r';
102 buf[11] = '\n';
103 buf[12] = '\0';
104
105 if (nl == FALSE) {
106 buf[10] = '\0';
107 }
108
109 for (i = 0; i != 8; i++) {
110 nybble = (v >> (i*4)) & 0xf;
111 if (nybble > 9) {
112 nybble += 7;
113 }
114 buf[7-i+2] = nybble + '0';
115 }
116 send_serial_string(buf);
117 }