Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1655 | giacomo | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | #include <kernel/kern.h> |
||
20 | #include <stdlib.h> |
||
21 | #include <math.h> |
||
22 | |||
23 | #include "nmea.h" |
||
24 | |||
25 | #include <drivers/shark_keyb26.h> |
||
26 | #include <drivers/shark_fb26.h> |
||
27 | |||
28 | /* Number of available COM links */ |
||
29 | #define COM_LINKS 4 |
||
30 | |||
31 | #define COM1 0 |
||
32 | #define COM2 1 |
||
33 | #define COM3 2 |
||
34 | #define COM4 3 |
||
35 | |||
36 | /* These values identify interrupt type */ |
||
37 | #define RX_FULL 1 |
||
38 | #define TX_EMPTY 2 |
||
39 | #define LS_CHANGED 4 |
||
40 | #define MS_CHANGED 8 |
||
41 | |||
42 | /* Register displacements */ |
||
43 | #define THR 0 |
||
44 | #define RBR 0 |
||
45 | #define IER 1 |
||
46 | #define FCR 2 |
||
47 | #define IIR 2 |
||
48 | #define LCR 3 |
||
49 | #define MCR 4 |
||
50 | #define LSR 5 |
||
51 | #define MSR 6 |
||
52 | #define SPad 7 |
||
53 | |||
54 | /* Parity value */ |
||
55 | #define NONE 0 |
||
56 | #define ODD 1 |
||
57 | #define EVEN 3 |
||
58 | |||
59 | static unsigned int com_base[] = {0x03F8,0x02F8,0x03E8,0x02E8}; |
||
60 | |||
61 | struct OUTDATA gNMEAdata; |
||
62 | |||
63 | unsigned int com_read(unsigned int port,unsigned int reg) |
||
64 | { |
||
65 | unsigned int b; |
||
66 | if (port > 3 || reg > 7) return(0); |
||
67 | b = ll_in(com_base[port]+reg); |
||
68 | return(b); |
||
69 | } |
||
70 | |||
71 | void com_write(unsigned int port,unsigned int reg,unsigned int value) |
||
72 | { |
||
73 | if (port > 3 || reg > 7) return; |
||
74 | ll_out(com_base[port]+reg,value); |
||
75 | } |
||
76 | |||
77 | void com_send(unsigned int port,BYTE b) |
||
78 | { |
||
79 | while ((com_read(port,LSR) & 32) == 0); |
||
80 | com_write(port,THR,b); |
||
81 | } |
||
82 | |||
83 | unsigned int com_receive(unsigned int port) |
||
84 | { |
||
85 | while ((com_read(port,LSR) & 1) == 0); |
||
86 | return(com_read(port,RBR)); |
||
87 | } |
||
88 | |||
89 | int open_com(unsigned int port, DWORD speed, BYTE parity, BYTE len, BYTE stop) |
||
90 | { |
||
91 | unsigned long div,b_mask; |
||
92 | |||
93 | /* Now set up the serial link */ |
||
94 | b_mask = (parity & 3) * 8 + (stop & 1) * 4 + ((len - 5) & 3); |
||
95 | div = 115200L / speed; |
||
96 | /* Clear serial interrupt enable register */ |
||
97 | com_write(port,IER,0); |
||
98 | /* Empty input buffer */ |
||
99 | com_read(port,RBR); |
||
100 | /* Activate DLAB bit for speed setting */ |
||
101 | com_write(port,LCR,0x80); |
||
102 | /* Load baud divisor */ |
||
103 | com_write(port,0,div & 0x00FF); |
||
104 | div >>= 8; |
||
105 | com_write(port,1,div & 0x00FF); |
||
106 | /* Load control word (parity,stop bit,bit len) */ |
||
107 | com_write(port,LCR,b_mask); |
||
108 | /* Attiva OUT1 & OUT2 */ |
||
109 | com_write(port,MCR,0x0C); |
||
110 | |||
111 | return 0; |
||
112 | |||
113 | } |
||
114 | |||
115 | |||
116 | int main(int argc, char **argv) |
||
117 | { |
||
118 | |||
119 | unsigned int ch,i; |
||
120 | char temp[100]; |
||
121 | |||
122 | open_com(COM1,4800,NONE,8,0); |
||
123 | i = 0; |
||
124 | |||
125 | while(1) { |
||
126 | |||
127 | ch = com_receive(COM1); |
||
128 | temp[i] = ch; |
||
129 | if (ch == 13) { |
||
130 | temp[i] = 0; |
||
131 | cprintf("%s\n",temp); |
||
132 | process_message(temp + 1); |
||
133 | i = 0; |
||
134 | |||
135 | cprintf("Lat: %f Lon: %f Alt: %f Sat: %d View: %d Mod: %d Time: %s\n", |
||
136 | gNMEAdata.latitude, |
||
137 | gNMEAdata.longitude, |
||
138 | gNMEAdata.altitude, |
||
139 | gNMEAdata.satellites, |
||
140 | gNMEAdata.in_view, |
||
141 | gNMEAdata.mode, |
||
142 | gNMEAdata.utc); |
||
143 | |||
144 | ch = com_receive(COM1); |
||
145 | |||
146 | } else { |
||
147 | i++; |
||
148 | } |
||
149 | |||
150 | } |
||
151 | |||
152 | return 0; |
||
153 | |||
154 | } |
||
155 |