2014-07-04 23:49:08 +08:00
|
|
|
#include <stdio.h>
|
2014-09-15 22:40:33 +08:00
|
|
|
#include <string.h>
|
2014-07-04 23:49:08 +08:00
|
|
|
#include <irq.h>
|
|
|
|
#include <uart.h>
|
2015-03-12 05:02:19 +08:00
|
|
|
#include <console.h>
|
2014-07-04 23:49:08 +08:00
|
|
|
#include <system.h>
|
2014-09-15 22:56:23 +08:00
|
|
|
#include <time.h>
|
|
|
|
#include <generated/csr.h>
|
2014-07-04 23:49:08 +08:00
|
|
|
|
2015-03-12 05:02:19 +08:00
|
|
|
#include "test_mode.h"
|
2015-04-22 01:31:31 +08:00
|
|
|
#include "session.h"
|
2014-07-24 07:10:49 +08:00
|
|
|
|
2015-04-22 01:31:31 +08:00
|
|
|
void comm_service(void)
|
2014-09-15 22:40:33 +08:00
|
|
|
{
|
2015-04-22 01:31:31 +08:00
|
|
|
char *txdata;
|
|
|
|
int txlen;
|
|
|
|
static char rxdata;
|
|
|
|
static int rxpending;
|
|
|
|
int r, i;
|
|
|
|
|
|
|
|
if(!rxpending && uart_read_nonblock()) {
|
|
|
|
rxdata = uart_read();
|
|
|
|
rxpending = 1;
|
2014-09-15 22:40:33 +08:00
|
|
|
}
|
2015-04-22 01:31:31 +08:00
|
|
|
if(rxpending) {
|
|
|
|
r = session_input(&rxdata, 1);
|
|
|
|
if(r > 0)
|
|
|
|
rxpending = 0;
|
2014-09-15 22:40:33 +08:00
|
|
|
}
|
|
|
|
|
2015-04-22 01:31:31 +08:00
|
|
|
session_poll((void **)&txdata, &txlen);
|
|
|
|
if(txlen > 0) {
|
|
|
|
for(i=0;i<txlen;i++)
|
|
|
|
uart_write(txdata[i]);
|
|
|
|
session_ack(txlen);
|
2015-04-05 22:04:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-22 01:31:31 +08:00
|
|
|
static void regular_main(void)
|
2014-07-04 23:49:08 +08:00
|
|
|
{
|
2015-04-22 01:31:31 +08:00
|
|
|
session_start();
|
|
|
|
while(1)
|
|
|
|
comm_service();
|
2014-09-15 22:40:33 +08:00
|
|
|
}
|
|
|
|
|
2015-04-22 01:31:31 +08:00
|
|
|
|
2014-09-15 22:56:23 +08:00
|
|
|
static void blink_led(void)
|
|
|
|
{
|
|
|
|
int i, ev, p;
|
|
|
|
|
|
|
|
p = identifier_frequency_read()/10;
|
|
|
|
time_init();
|
|
|
|
for(i=0;i<3;i++) {
|
|
|
|
leds_out_write(1);
|
|
|
|
while(!elapsed(&ev, p));
|
|
|
|
leds_out_write(0);
|
|
|
|
while(!elapsed(&ev, p));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-12 05:02:19 +08:00
|
|
|
static int check_test_mode(void)
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
|
|
|
|
timer0_en_write(0);
|
|
|
|
timer0_reload_write(0);
|
|
|
|
timer0_load_write(identifier_frequency_read() >> 2);
|
|
|
|
timer0_en_write(1);
|
|
|
|
timer0_update_value_write(1);
|
|
|
|
while(timer0_value_read()) {
|
|
|
|
if(readchar_nonblock()) {
|
|
|
|
c = readchar();
|
|
|
|
if((c == 't')||(c == 'T'))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
timer0_update_value_write(1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-15 22:40:33 +08:00
|
|
|
int main(void)
|
|
|
|
{
|
2014-09-05 12:03:22 +08:00
|
|
|
irq_setmask(0);
|
|
|
|
irq_setie(1);
|
|
|
|
uart_init();
|
2014-09-22 13:18:48 +08:00
|
|
|
|
2015-04-05 17:55:05 +08:00
|
|
|
#ifdef ARTIQ_AMP
|
|
|
|
puts("ARTIQ runtime built "__DATE__" "__TIME__" for AMP systems\n");
|
2015-04-03 17:44:56 +08:00
|
|
|
#else
|
2015-04-05 17:55:05 +08:00
|
|
|
puts("ARTIQ runtime built "__DATE__" "__TIME__" for UP systems\n");
|
2015-04-03 17:44:56 +08:00
|
|
|
#endif
|
2014-09-15 22:56:23 +08:00
|
|
|
blink_led();
|
2015-03-12 05:02:19 +08:00
|
|
|
|
|
|
|
if(check_test_mode()) {
|
|
|
|
puts("Entering test mode.");
|
|
|
|
test_main();
|
|
|
|
} else {
|
|
|
|
puts("Entering regular mode.");
|
2015-04-22 01:31:31 +08:00
|
|
|
regular_main();
|
2015-03-12 05:02:19 +08:00
|
|
|
}
|
2014-09-05 12:03:22 +08:00
|
|
|
return 0;
|
2014-07-04 23:49:08 +08:00
|
|
|
}
|