forked from M-Labs/artiq
1
0
Fork 0

runtime: support real-time FUD

This commit is contained in:
Sebastien Bourdeauducq 2014-09-12 15:34:11 +08:00
parent b5f145d976
commit 16b2d9f177
4 changed files with 34 additions and 7 deletions

View File

@ -12,7 +12,7 @@ _syscalls = {
"rtio_set": "Iii:n", "rtio_set": "Iii:n",
"rtio_replace": "Iii:n", "rtio_replace": "Iii:n",
"rtio_sync": "i:n", "rtio_sync": "i:n",
"dds_program": "ii:n", "dds_program": "iiI:n",
} }
_chr_to_type = { _chr_to_type = {

View File

@ -1,4 +1,6 @@
#include <generated/csr.h>
#include <hw/common.h> #include <hw/common.h>
#include <stdio.h>
#include "dds.h" #include "dds.h"
@ -6,7 +8,6 @@
#define DDS_FTW1 0x0b #define DDS_FTW1 0x0b
#define DDS_FTW2 0x0c #define DDS_FTW2 0x0c
#define DDS_FTW3 0x0d #define DDS_FTW3 0x0d
#define DDS_FUD 0x40
#define DDS_GPIO 0x41 #define DDS_GPIO 0x41
#define DDS_READ(addr) \ #define DDS_READ(addr) \
@ -15,6 +16,30 @@
#define DDS_WRITE(addr, data) \ #define DDS_WRITE(addr, data) \
MMPTR(0xb0000000 + (addr)*4) = data MMPTR(0xb0000000 + (addr)*4) = data
#define RTIO_FUD_CHANNEL 4
static void fud(long long int fud_time)
{
rtio_reset_write(0);
rtio_chan_sel_write(RTIO_FUD_CHANNEL);
if(fud_time < 0) {
rtio_counter_update_write(1);
fud_time = rtio_counter_read() + 3000;
}
rtio_o_timestamp_write(fud_time);
rtio_o_value_write(1);
rtio_o_we_write(1);
rtio_o_timestamp_write(fud_time+3*8);
rtio_o_value_write(0);
rtio_o_we_write(1);
}
static void fud_sync(void)
{
rtio_chan_sel_write(RTIO_FUD_CHANNEL);
while(rtio_o_level_read() != 0);
}
void dds_init(void) void dds_init(void)
{ {
int i; int i;
@ -26,16 +51,18 @@ void dds_init(void)
DDS_WRITE(0x01, 0x00); DDS_WRITE(0x01, 0x00);
DDS_WRITE(0x02, 0x00); DDS_WRITE(0x02, 0x00);
DDS_WRITE(0x03, 0x00); DDS_WRITE(0x03, 0x00);
DDS_WRITE(DDS_FUD, 0); fud(-1);
fud_sync();
} }
} }
void dds_program(int channel, int ftw) void dds_program(int channel, int ftw, long long int fud_time)
{ {
fud_sync();
DDS_WRITE(DDS_GPIO, channel); DDS_WRITE(DDS_GPIO, channel);
DDS_WRITE(DDS_FTW0, ftw & 0xff); DDS_WRITE(DDS_FTW0, ftw & 0xff);
DDS_WRITE(DDS_FTW1, (ftw >> 8) & 0xff); DDS_WRITE(DDS_FTW1, (ftw >> 8) & 0xff);
DDS_WRITE(DDS_FTW2, (ftw >> 16) & 0xff); DDS_WRITE(DDS_FTW2, (ftw >> 16) & 0xff);
DDS_WRITE(DDS_FTW3, (ftw >> 24) & 0xff); DDS_WRITE(DDS_FTW3, (ftw >> 24) & 0xff);
DDS_WRITE(DDS_FUD, 0); fud(fud_time);
} }

View File

@ -2,6 +2,6 @@
#define __DDS_H #define __DDS_H
void dds_init(void); void dds_init(void);
void dds_program(int channel, int ftw); void dds_program(int channel, int ftw, long long int fud_time);
#endif /* __DDS_H */ #endif /* __DDS_H */

View File

@ -29,8 +29,8 @@ int main(void)
if(length > 0) { if(length > 0) {
k = load_elf(resolve_symbol, "run", kbuf, length, kcode, sizeof(kcode)); k = load_elf(resolve_symbol, "run", kbuf, length, kcode, sizeof(kcode));
if(k != NULL) { if(k != NULL) {
rtio_init();
dds_init(); dds_init();
rtio_init();
flush_cpu_icache(); flush_cpu_icache();
k(); k();
kernel_finished(); kernel_finished();