Blame |
Last modification |
View Log
| RSS feed
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Giacomo Guidi <giacomo@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
#include <kernel/kern.h>
#include <stdlib.h>
#include <math.h>
#include "nmea.h"
#include <drivers/shark_keyb26.h>
#include <drivers/shark_fb26.h>
/* Number of available COM links */
#define COM_LINKS 4
#define COM1 0
#define COM2 1
#define COM3 2
#define COM4 3
/* These values identify interrupt type */
#define RX_FULL 1
#define TX_EMPTY 2
#define LS_CHANGED 4
#define MS_CHANGED 8
/* Register displacements */
#define THR 0
#define RBR 0
#define IER 1
#define FCR 2
#define IIR 2
#define LCR 3
#define MCR 4
#define LSR 5
#define MSR 6
#define SPad 7
/* Parity value */
#define NONE 0
#define ODD 1
#define EVEN 3
static unsigned int com_base
[] = {0x03F8,0x02F8,0x03E8,0x02E8};
struct OUTDATA gNMEAdata
;
unsigned int com_read
(unsigned int port
,unsigned int reg
)
{
unsigned int b
;
if (port
> 3 || reg
> 7) return(0);
b
= ll_in
(com_base
[port
]+reg
);
return(b
);
}
void com_write
(unsigned int port
,unsigned int reg
,unsigned int value
)
{
if (port
> 3 || reg
> 7) return;
ll_out
(com_base
[port
]+reg
,value
);
}
void com_send
(unsigned int port
,BYTE b
)
{
while ((com_read
(port
,LSR
) & 32) == 0);
com_write
(port
,THR
,b
);
}
unsigned int com_receive
(unsigned int port
)
{
while ((com_read
(port
,LSR
) & 1) == 0);
return(com_read
(port
,RBR
));
}
int open_com
(unsigned int port
, DWORD speed
, BYTE parity
, BYTE len
, BYTE stop
)
{
unsigned long div,b_mask
;
/* Now set up the serial link */
b_mask
= (parity
& 3) * 8 + (stop
& 1) * 4 + ((len
- 5) & 3);
div = 115200L / speed
;
/* Clear serial interrupt enable register */
com_write
(port
,IER
,0);
/* Empty input buffer */
com_read
(port
,RBR
);
/* Activate DLAB bit for speed setting */
com_write
(port
,LCR
,0x80);
/* Load baud divisor */
com_write
(port
,0,div & 0x00FF);
div >>= 8;
com_write
(port
,1,div & 0x00FF);
/* Load control word (parity,stop bit,bit len) */
com_write
(port
,LCR
,b_mask
);
/* Attiva OUT1 & OUT2 */
com_write
(port
,MCR
,0x0C);
return 0;
}
int main
(int argc
, char **argv
)
{
unsigned int ch
,i
;
char temp
[100];
open_com
(COM1
,4800,NONE
,8,0);
i
= 0;
while(1) {
ch
= com_receive
(COM1
);
temp
[i
] = ch
;
if (ch
== 13) {
temp
[i
] = 0;
cprintf
("%s\n",temp
);
process_message
(temp
+ 1);
i
= 0;
cprintf
("Lat: %f Lon: %f Alt: %f Sat: %d View: %d Mod: %d Time: %s\n",
gNMEAdata.
latitude,
gNMEAdata.
longitude,
gNMEAdata.
altitude,
gNMEAdata.
satellites,
gNMEAdata.
in_view,
gNMEAdata.
mode,
gNMEAdata.
utc);
ch
= com_receive
(COM1
);
} else {
i
++;
}
}
return 0;
}