2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-23 02:14:01 +08:00
artiq/soc/runtime/dds.c

93 lines
2.0 KiB
C
Raw Normal View History

2014-09-12 15:34:11 +08:00
#include <generated/csr.h>
2014-08-28 16:56:48 +08:00
#include <hw/common.h>
2014-09-12 15:34:11 +08:00
#include <stdio.h>
2014-08-28 16:56:48 +08:00
#include "exceptions.h"
2014-08-28 16:56:48 +08:00
#include "dds.h"
#define DDS_FTW0 0x0a
#define DDS_FTW1 0x0b
#define DDS_FTW2 0x0c
#define DDS_FTW3 0x0d
#define DDS_GPIO 0x41
#define DDS_READ(addr) \
2014-09-05 12:03:22 +08:00
MMPTR(0xb0000000 + (addr)*4)
2014-08-28 16:56:48 +08:00
#define DDS_WRITE(addr, data) \
2014-09-05 12:03:22 +08:00
MMPTR(0xb0000000 + (addr)*4) = data
2014-08-28 16:56:48 +08:00
2014-09-12 15:34:11 +08:00
#define RTIO_FUD_CHANNEL 4
static void fud_sync(void)
{
rtio_chan_sel_write(RTIO_FUD_CHANNEL);
while(rtio_o_level_read() != 0);
}
2014-09-12 15:34:11 +08:00
static void fud(long long int fud_time)
{
int r;
long long int fud_end_time;
static long long int previous_fud_end_time;
2014-10-10 20:12:22 +08:00
r = rtio_reset_counter_read();
if(r)
previous_fud_end_time = 0;
2014-10-10 20:12:22 +08:00
rtio_reset_counter_write(0);
2014-09-12 15:34:11 +08:00
rtio_chan_sel_write(RTIO_FUD_CHANNEL);
if(fud_time < 0) {
rtio_counter_update_write(1);
fud_time = rtio_counter_read() + 4000;
2014-09-12 15:34:11 +08:00
}
fud_end_time = fud_time + 3*8;
if(fud_time < previous_fud_end_time)
exception_raise(EID_RTIO_SEQUENCE_ERROR);
previous_fud_end_time = fud_end_time;
2014-09-12 15:34:11 +08:00
rtio_o_timestamp_write(fud_time);
rtio_o_value_write(1);
rtio_o_we_write(1);
rtio_o_timestamp_write(fud_end_time);
2014-09-12 15:34:11 +08:00
rtio_o_value_write(0);
rtio_o_we_write(1);
2014-10-10 20:12:22 +08:00
if(rtio_o_error_read()) {
rtio_reset_logic_write(1);
rtio_reset_logic_write(0);
exception_raise(EID_RTIO_UNDERFLOW);
2014-10-10 20:12:22 +08:00
}
2014-09-12 15:34:11 +08:00
if(r) {
fud_sync();
2014-10-10 20:12:22 +08:00
rtio_reset_counter_write(1);
}
2014-09-12 15:34:11 +08:00
}
2014-08-28 16:56:48 +08:00
void dds_init(void)
{
2014-09-05 12:03:22 +08:00
int i;
for(i=0;i<8;i++) {
2014-09-11 19:25:55 +08:00
DDS_WRITE(DDS_GPIO, i | (1 << 7));
2014-09-05 12:03:22 +08:00
DDS_WRITE(DDS_GPIO, i);
DDS_WRITE(0x00, 0x78);
DDS_WRITE(0x01, 0x00);
DDS_WRITE(0x02, 0x00);
DDS_WRITE(0x03, 0x00);
2014-09-12 15:34:11 +08:00
fud(-1);
fud_sync();
2014-09-05 12:03:22 +08:00
}
2014-08-28 16:56:48 +08:00
}
2014-09-12 15:34:11 +08:00
void dds_program(int channel, int ftw, long long int fud_time)
2014-08-28 16:56:48 +08:00
{
2014-09-12 15:34:11 +08:00
fud_sync();
2014-09-05 12:03:22 +08:00
DDS_WRITE(DDS_GPIO, channel);
DDS_WRITE(DDS_FTW0, ftw & 0xff);
DDS_WRITE(DDS_FTW1, (ftw >> 8) & 0xff);
DDS_WRITE(DDS_FTW2, (ftw >> 16) & 0xff);
DDS_WRITE(DDS_FTW3, (ftw >> 24) & 0xff);
2014-09-12 15:34:11 +08:00
fud(fud_time);
2014-08-28 16:56:48 +08:00
}