Line 35... |
Line 35... |
//
|
//
|
//
|
//
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
//
|
//
|
|
#include "artyboard.h"
|
#include "zipcpu.h"
|
#include "zipcpu.h"
|
#include "zipsys.h"
|
#include "zipsys.h"
|
#include "artyboard.h"
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#define sys _sys
|
|
|
void idle_task(void) {
|
void idle_task(void) {
|
while(1)
|
while(1)
|
zip_idle();
|
zip_idle();
|
}
|
}
|
|
|
void wait_on_interrupt(int mask) {
|
void wait_on_interrupt(int mask) {
|
|
if (mask & SYSINT_AUX) {
|
|
zip->z_apic = INT_ENABLE;
|
|
}
|
zip->z_pic = DALLPIC|mask;
|
zip->z_pic = DALLPIC|mask;
|
zip->z_pic = EINT(mask);
|
zip->z_pic = EINT(mask);
|
zip_rtu();
|
zip_rtu();
|
}
|
}
|
|
|
Line 56... |
Line 63... |
void user_task(void) {
|
void user_task(void) {
|
const unsigned white = 0x070707, black = 0;
|
const unsigned white = 0x070707, black = 0;
|
while(1) {
|
while(1) {
|
unsigned btn, subnow, sw;
|
unsigned btn, subnow, sw;
|
|
|
subnow = (sys->io_gps_sub >> 28)&0x0f;
|
subnow = (sys->io_b.i_tim.sub >> 28)&0x0f;
|
|
|
// If the button is pressed, toggle the LED
|
// If the button is pressed, toggle the LED
|
// Otherwise, turn the LED off.
|
// Otherwise, turn the LED off.
|
//
|
//
|
|
|
// First, get all the pressed buttons
|
// First, get all the pressed buttons
|
btn = (sys->io_btnsw) & 0x0f0;
|
btn = (sys->io_b.i_btnsw) & 0x0f0;
|
// Now, acknowledge the button presses that we just read
|
// Now, acknowledge the button presses that we just read
|
sys->io_btnsw = btn;
|
sys->io_b.i_btnsw = btn;
|
btn >>= 4;
|
btn >>= 4;
|
|
|
// Now, use the time as the toggle function.
|
// Now, use the time as the toggle function.
|
btn = (subnow ^ btn)&btn & 0x07;
|
btn = (subnow ^ btn)&btn & 0x07;
|
|
|
sys->io_ledctrl = btn | 0x070;
|
sys->io_b.i_leds = btn | 0x070;
|
|
|
sw = sys->io_btnsw & 0x0f;
|
sw = sys->io_b.i_btnsw & 0x0f;
|
for(int i=0; i<4; i++)
|
for(int i=0; i<4; i++)
|
sys->io_clrled[i] = (sw & (1<<i)) ? white : black;
|
sys->io_b.i_clrled[i] = (sw & (1<<i)) ? white : black;
|
|
|
}
|
}
|
}
|
}
|
|
|
int mpyuhi(int a, int b) {
|
int mpyuhi(int a, int b) {
|
Line 101... |
Line 108... |
return (rhi >> 16) + f;
|
return (rhi >> 16) + f;
|
// return f;
|
// return f;
|
// return ahi;
|
// return ahi;
|
}
|
}
|
|
|
int hexdigit(int v) {
|
|
if (v < 10)
|
int gps_lock = 0;
|
return v + '0';
|
void gps_process_line(const char *line) {
|
|
if ((line[0] != '$')||(line[1] != 'G')
|
|
||(line[2] != 'P'))
|
|
return;
|
|
|
|
// GGA, GSV(x3), RMC, VTG
|
|
if (line[3] == 'G') {
|
|
/*
|
|
if ((line[4] == 'G')&&(line[5] == 'A')) {
|
|
} // else if ((line[5] == 'S')&&(line[6] == 'V')) {
|
|
}
|
|
*/
|
|
// printf("GPS Line: %s\r\n", line);
|
|
} else if (line[3] == 'R') {
|
|
// if ((line[4] == 'M')&&(line[5] == 'C')&&(line[6] == ','))
|
|
{
|
|
// char outbuf[256], *outptr = outbuf;
|
|
// const char *here = &line[8], *there;
|
|
// there = strchr(here, ',');
|
|
fputs("RMC-Line\r\n", stdout);
|
|
#ifdef PROCLINE
|
|
if ((there)&&(there - here > 6)) {
|
|
outptr += sprintf(outptr,
|
|
"TIME: %c%c:%c%c:%c%c\r\n",
|
|
here[0], here[1],
|
|
here[2], here[3],
|
|
here[4], here[5]);
|
|
here = there + 1;
|
|
there = strchr(here, ',');
|
|
} if (there) {
|
|
if (*here == 'A')
|
|
gps_lock = 1;
|
else
|
else
|
return v + 'A' - 10;
|
gps_lock = 0;
|
|
here = there + 1;
|
|
there = strchr(there+1, ',');
|
|
} if (there) {
|
|
there = strchr(there+1, ',');
|
|
} if (there) {
|
|
char tmp[32];
|
|
strncpy(tmp, here, there-here);
|
|
outptr += sprintf(outptr, "LATITUDE: %s\r\n");
|
|
here = there + 1;
|
|
there = strchr(there+1, ',');
|
|
} if (there) {
|
|
there = strchr(there+1, ',');
|
|
} if (there) {
|
|
char tmp[32];
|
|
strncpy(tmp, here, there-here);
|
|
outptr += sprintf(outptr, "LONGITUDE: %s\r\n");
|
|
} if (gps_lock)
|
|
fputs(outbuf, stdout);
|
|
else puts("No GPS lock\r\n");
|
|
#endif
|
}
|
}
|
|
printf("GPS RMC Line: %s\r\n", line);
|
|
} else if (line[3] == 'V') {
|
|
/*
|
|
if ((line[4] == 'T')&&(line[5] == 'G')) {
|
|
}
|
|
*/
|
|
// printf("GPS Line: %s\r\n", line);
|
|
} else printf("Other GPS Line: %s\r\n", line);
|
|
}
|
|
|
|
char errstring[128];
|
|
|
int errstring[128];
|
|
|
|
void main(int argc, char **argv) {
|
void main(int argc, char **argv) {
|
const unsigned red = 0x0ff0000, green = 0x0ff00, blue = 0x0ff,
|
const unsigned red = 0x0ff0000, green = 0x0ff00, blue = 0x0ff,
|
white = 0x070707, black = 0, dimgreen = 0x1f00,
|
white = 0x070707, black = 0, dimgreen = 0x1f00,
|
second = CLOCKFREQHZ;
|
second = CLOCKFREQHZ;
|
Line 121... |
Line 189... |
// Start the GPS converging ...
|
// Start the GPS converging ...
|
sys->io_gps.g_alpha = 2;
|
sys->io_gps.g_alpha = 2;
|
sys->io_gps.g_beta = 0x14bda12f;
|
sys->io_gps.g_beta = 0x14bda12f;
|
sys->io_gps.g_gamma = 0x1f533ae8;
|
sys->io_gps.g_gamma = 0x1f533ae8;
|
|
|
|
//
|
int user_context[16];
|
int user_context[16];
|
for(i=0; i<15; i++)
|
for(i=0; i<15; i++)
|
user_context[i] = 0;
|
user_context[i] = 0;
|
user_context[15] = (unsigned)idle_task;
|
user_context[15] = (unsigned)idle_task;
|
zip_restore_context(user_context);
|
zip_restore_context(user_context);
|
|
|
for(i=0; i<4; i++)
|
for(i=0; i<4; i++)
|
sys->io_clrled[i] = red;
|
sys->io_b.i_clrled[i] = red;
|
sys->io_ledctrl = 0x0ff;
|
sys->io_b.i_leds = 0x0ff;
|
|
|
// Clear the PIC
|
// Clear the PIC
|
//
|
//
|
// Acknowledge all interrupts, turn off all interrupts
|
// Acknowledge all interrupts, turn off all interrupts
|
//
|
//
|
zip->z_pic = CLEARPIC;
|
zip->z_pic = CLEARPIC;
|
while(sys->io_pwrcount < (second >> 4))
|
while(sys->io_b.i_pwrcount < (second >> 4))
|
;
|
;
|
|
|
// Repeating timer, every 250ms
|
// Repeating timer, every 250ms
|
zip->z_tma = TMR_INTERVAL | (second/4);
|
zip->z_tma = TMR_INTERVAL | (second/4);
|
wait_on_interrupt(SYSINT_TMA);
|
wait_on_interrupt(SYSINT_TMA);
|
|
|
sys->io_clrled[0] = green;
|
sys->io_b.i_clrled[0] = green;
|
sys->io_ledctrl = 0x010;
|
sys->io_b.i_leds = 0x010;
|
|
|
wait_on_interrupt(SYSINT_TMA);
|
wait_on_interrupt(SYSINT_TMA);
|
|
|
sys->io_clrled[0] = dimgreen;
|
sys->io_b.i_clrled[0] = dimgreen;
|
sys->io_clrled[1] = green;
|
sys->io_b.i_clrled[1] = green;
|
sys->io_scope[0].s_ctrl = SCOPE_NO_RESET | 32;
|
sys->io_scope[0].s_ctrl = WBSCOPE_NO_RESET | 32;
|
sys->io_ledctrl = 0x020;
|
sys->io_b.i_leds = 0x020;
|
|
|
wait_on_interrupt(SYSINT_TMA);
|
wait_on_interrupt(SYSINT_TMA);
|
|
|
sys->io_clrled[1] = dimgreen;
|
sys->io_b.i_clrled[1] = dimgreen;
|
sys->io_clrled[2] = green;
|
sys->io_b.i_clrled[2] = green;
|
sys->io_ledctrl = 0x040;
|
sys->io_b.i_leds = 0x040;
|
|
|
wait_on_interrupt(SYSINT_TMA);
|
wait_on_interrupt(SYSINT_TMA);
|
|
|
sys->io_clrled[2] = dimgreen;
|
sys->io_b.i_clrled[2] = dimgreen;
|
sys->io_clrled[3] = green;
|
sys->io_b.i_clrled[3] = green;
|
sys->io_ledctrl = 0x080;
|
sys->io_b.i_leds = 0x080;
|
|
|
wait_on_interrupt(SYSINT_TMA);
|
wait_on_interrupt(SYSINT_TMA);
|
|
|
sys->io_clrled[3] = dimgreen;
|
sys->io_b.i_clrled[3] = dimgreen;
|
|
|
wait_on_interrupt(SYSINT_TMA);
|
wait_on_interrupt(SYSINT_TMA);
|
|
|
for(i=0; i<4; i++)
|
for(i=0; i<4; i++)
|
sys->io_clrled[i] = black;
|
sys->io_b.i_clrled[i] = black;
|
|
|
// Wait one second ...
|
// Wait one second ...
|
for(i=0; i<4; i++)
|
for(i=0; i<4; i++)
|
wait_on_interrupt(SYSINT_TMA);
|
wait_on_interrupt(SYSINT_TMA);
|
|
|
// Blink all the LEDs
|
// Blink all the LEDs
|
// First turn them on
|
// First turn them on
|
sys->io_ledctrl = 0x0ff;
|
sys->io_b.i_leds = 0x0ff;
|
// Then wait a quarter second
|
// Then wait a quarter second
|
wait_on_interrupt(SYSINT_TMA);
|
wait_on_interrupt(SYSINT_TMA);
|
// Then turn the back off
|
// Then turn the back off
|
sys->io_ledctrl = 0x0f0;
|
sys->io_b.i_leds = 0x0f0;
|
// and wait another quarter second
|
// and wait another quarter second
|
wait_on_interrupt(SYSINT_TMA);
|
wait_on_interrupt(SYSINT_TMA);
|
|
|
// Now, read buttons, and flash an LED on any button being held
|
// Now, read buttons, and flash an LED on any button being held
|
// down ... ? neat?
|
// down ... ? neat?
|
Line 200... |
Line 269... |
|
|
do {
|
do {
|
wait_on_interrupt(SYSINT_PPS|SYSINT_TMA);
|
wait_on_interrupt(SYSINT_PPS|SYSINT_TMA);
|
} while((zip->z_pic & SYSINT_PPS)==0);
|
} while((zip->z_pic & SYSINT_PPS)==0);
|
|
|
|
printf("GPS RECORD START\r\n");
|
|
|
|
zip->z_tma = TMR_INTERVAL | (second/1000);
|
|
wait_on_interrupt(SYSINT_TMA);
|
|
sys->io_gpsu.u_rx = 0x01000;
|
while(1) {
|
while(1) {
|
int *s = errstring;
|
char *s = errstring;
|
|
|
zip->z_wdt = CLOCKFREQ_HZ*4;
|
zip->z_wdt = CLOCKFREQ_HZ*4;
|
sys->io_ledctrl = 0x088;
|
sys->io_b.i_leds = 0x088;
|
|
|
// 1. Read and report the GPS tracking err
|
// 1. Read and report the GPS tracking err
|
|
|
// Get the upper 32-bits of the error;
|
// Get the upper 32-bits of the error;
|
int err = *(int *)(&sys->io_gpstb.tb_err);
|
int err = *(int *)(&sys->io_gpstb.tb_err);
|
int err_in_ns;
|
int err_in_ns, err_in_us;
|
/*
|
int err_sgn = (err < 0)?1:0, err_in_ns_rem;
|
long err_in_ns_long = err;
|
|
err_in_ns_long *= 1000000000l;
|
|
err_in_ns_long >>= 32;
|
|
int err_in_ns = (int)(err_in_ns_long);
|
|
*/
|
|
int err_sgn = (err < 0)?1:0;
|
|
err_in_ns = (err<0)?-err:err;
|
err_in_ns = (err<0)?-err:err;
|
err_in_ns = mpyuhi(err_in_ns, 1000000000);
|
err_in_ns = mpyuhi(err_in_ns, 1000000000);
|
int digit;
|
|
|
|
|
err_in_us = err_in_ns / 1000;
|
|
err_in_ns_rem = err_in_ns - err_in_us * 1000;
|
|
if (err_sgn)
|
|
err_in_us = - err_in_us;
|
|
|
*s++ = '\r';
|
printf("\r\nGPS PPS Err: 0x%08x => 0x%08x => %+5d.%03d us\r\n",
|
*s++ = '\n';
|
err, err_in_ns, err_in_us, err_in_ns_rem);
|
*s++ = 'G';
|
|
*s++ = 'P';
|
|
*s++ = 'S';
|
|
*s++ = ' ';
|
|
*s++ = 'P';
|
|
*s++ = 'P';
|
|
*s++ = 'S';
|
|
*s++ = ' ';
|
|
*s++ = 'E';
|
|
*s++ = 'r';
|
|
*s++ = 'r';
|
|
*s++ = ':';
|
|
*s++ = ' ';
|
|
|
|
|
|
*s++ = '0';
|
|
*s++ = 'x';
|
|
*s++ = hexdigit((err>>28)&0x0f);
|
|
*s++ = hexdigit((err>>24)&0x0f);
|
|
*s++ = hexdigit((err>>20)&0x0f);
|
|
*s++ = hexdigit((err>>16)&0x0f);
|
|
*s++ = hexdigit((err>>12)&0x0f);
|
|
*s++ = hexdigit((err>> 8)&0x0f);
|
|
*s++ = hexdigit((err>> 4)&0x0f);
|
|
*s++ = hexdigit((err )&0x0f);
|
|
|
|
*s++ = ' ';
|
|
*s++ = '=';
|
|
*s++ = '>';
|
|
*s++ = ' ';
|
|
|
|
*s++ = '0';
|
|
*s++ = 'x';
|
|
*s++ = hexdigit((err_in_ns>>28)&0x0f);
|
|
*s++ = hexdigit((err_in_ns>>24)&0x0f);
|
|
*s++ = hexdigit((err_in_ns>>20)&0x0f);
|
|
*s++ = hexdigit((err_in_ns>>16)&0x0f);
|
|
*s++ = hexdigit((err_in_ns>>12)&0x0f);
|
|
*s++ = hexdigit((err_in_ns>> 8)&0x0f);
|
|
*s++ = hexdigit((err_in_ns>> 4)&0x0f);
|
|
*s++ = hexdigit((err_in_ns )&0x0f);
|
|
|
|
*s++ = ' ';
|
|
*s++ = '=';
|
|
*s++ = '>';
|
|
*s++ = ' ';
|
|
|
|
*s++ = (err_sgn)?'-':' ';
|
|
// Milliseconds
|
|
digit = err_in_ns / 100000000;
|
|
*s++ = digit+'0';
|
|
err_in_ns -= digit * 100000000;
|
|
//
|
|
digit = err_in_ns / 10000000;
|
|
*s++ = digit+'0';
|
|
err_in_ns -= digit * 10000000;
|
|
//
|
|
digit = err_in_ns / 1000000;
|
|
*s++ = digit+'0';
|
|
err_in_ns -= digit * 1000000;
|
|
// Micro seconds
|
|
digit = err_in_ns / 100000;
|
|
*s++ = digit+'0';
|
|
err_in_ns -= digit * 100000;
|
|
//
|
|
digit = err_in_ns / 10000;
|
|
*s++ = digit+'0';
|
|
err_in_ns -= digit * 10000;
|
|
//
|
|
digit = err_in_ns / 1000;
|
|
*s++ = digit+'0';
|
|
err_in_ns -= digit * 1000;
|
|
// Nano seconds
|
|
*s++ = '.';
|
|
digit = err_in_ns / 100;
|
|
*s++ = digit+'0';
|
|
err_in_ns -= digit * 100;
|
|
//
|
|
digit = err_in_ns / 10;
|
|
*s++ = digit+'0';
|
|
err_in_ns -= digit * 10;
|
|
//
|
|
digit = err_in_ns;
|
|
*s++ = digit+'0';
|
|
//
|
|
*s++ = ' ';
|
|
*s++ = 'u';
|
|
*s++ = 'S';
|
|
*s++ = '\r';
|
|
*s++ = '\n';
|
|
*s++ = '\r';
|
|
*s++ = '\n';
|
|
*s++ = '\0';
|
|
|
|
/*
|
|
zip->z_dma.d_ctrl = DMACLEAR;
|
|
zip->z_dma.d_rd = errstring;
|
|
zip->z_dma.d_wr = &sys->io_uart_tx;
|
|
zip->z_dma.d_len = s - errstring-1;
|
|
zip->z_dma.d_ctrl = (DMAONEATATIME|DMA_CONSTDST|DMA_GPSRX);
|
|
wait_on_interrupt(SYSINT_DMAC);
|
|
*/
|
|
|
|
for(int i=0; errstring[i]; i++) {
|
|
wait_on_interrupt(SYSINT_UARTTX);
|
|
sys->io_uart_tx = errstring[i];
|
|
zip->z_pic = SYSINT_UARTTX;
|
|
}
|
|
|
|
sys->io_ledctrl = 0x080;
|
|
|
|
/*
|
|
zip->z_dma.d_rd = &sys->io_gps_rx;
|
|
zip->z_dma.d_wr = &sys->io_uart_tx;
|
|
zip->z_dma.d_len = 0x01000000;
|
|
zip->z_dma.d_ctrl = (DMAONEATATIME|DMA_CONSTDST|DMA_CONSTSRC|DMA_ONGPSRX);
|
|
wait_on_interrupt(SYSINT_PPS);
|
|
*/
|
|
|
|
/*
|
sys->io_b.i_leds = 0x080;
|
if (zip_ucc() & CC_FAULT) {
|
|
zip_save_context(user_context);
|
|
user_context[14] = CC_GIE;
|
|
user_context[15] = (int)&idle_task;
|
|
zip_restore_context(user_context);
|
|
}
|
|
*/
|
|
|
|
zip->z_pic = SYSINT_GPSRX | SYSINT_PPS;
|
zip->z_pic = SYSINT_GPSRXF | SYSINT_PPS | SYSINT_TMA;
|
|
{
|
|
const int LINEBUFSZ = 80;
|
|
char line[LINEBUFSZ], *linep = line;
|
do {
|
do {
|
wait_on_interrupt(SYSINT_PPS|SYSINT_GPSRX);
|
int v;
|
if (zip->z_pic & SYSINT_GPSRX) {
|
wait_on_interrupt(SYSINT_PPS|SYSINT_GPSRXF|SYSINT_TMA);
|
sys->io_uart_tx = sys->io_gps_rx;
|
|
zip->z_pic = SYSINT_GPSRX;
|
while(((v = sys->io_gpsu.u_rx)&0x100)==0) {
|
|
v &= 0x0ff;
|
|
// putchar(v);
|
|
// sys->io_uart.u_tx = v;
|
|
*linep++ = v;
|
|
if(linep-line > LINEBUFSZ)
|
|
linep = line;
|
|
if ((v == '\r')||(v == '\n')) {
|
|
*linep = '\0';
|
|
if (line[0] == '$')
|
|
gps_process_line(line);
|
|
linep = line;
|
|
}
|
}
|
}
|
} while((zip->z_pic & SYSINT_PPS)==0);
|
} while((zip->z_pic & SYSINT_PPS)==0);
|
|
}
|
// wait_on_interrupt(SYSINT_PPS);
|
|
// zip->z_dma.d_ctrl= DMACLEAR;
|
|
}
|
}
|
|
|
zip_halt();
|
zip_halt();
|
}
|
}
|
|
|