2015-04-16 21:47:05 +08:00
|
|
|
#include "mailbox.h"
|
|
|
|
#include "messages.h"
|
|
|
|
#include "rtio.h"
|
2015-05-08 16:20:12 +08:00
|
|
|
#include "ttl.h"
|
2015-04-16 21:47:05 +08:00
|
|
|
#include "dds.h"
|
|
|
|
#include "bridge.h"
|
|
|
|
|
2015-07-27 10:50:25 +08:00
|
|
|
#define TIME_BUFFER (8000 << RTIO_FINE_TS_WIDTH)
|
|
|
|
|
2015-05-08 14:44:39 +08:00
|
|
|
static void dds_write(int addr, int data)
|
|
|
|
{
|
|
|
|
rtio_chan_sel_write(RTIO_DDS_CHANNEL);
|
|
|
|
rtio_o_address_write(addr);
|
|
|
|
rtio_o_data_write(data);
|
2015-07-27 10:50:25 +08:00
|
|
|
rtio_o_timestamp_write(rtio_get_counter() + TIME_BUFFER);
|
2015-05-08 14:44:39 +08:00
|
|
|
rtio_o_we_write(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dds_read(int addr)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2015-08-21 17:51:01 +08:00
|
|
|
#ifdef DDS_AD9858
|
|
|
|
#define DDS_READ_FLAG 128
|
|
|
|
#endif
|
|
|
|
#ifdef DDS_AD9914
|
|
|
|
#define DDS_READ_FLAG 256
|
|
|
|
#endif
|
|
|
|
dds_write(addr | DDS_READ_FLAG, 0);
|
2015-05-08 14:44:39 +08:00
|
|
|
while(rtio_i_status_read() & RTIO_I_STATUS_EMPTY);
|
|
|
|
r = rtio_i_data_read();
|
|
|
|
rtio_i_re_write(1);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2015-04-16 21:47:05 +08:00
|
|
|
static void send_ready(void)
|
|
|
|
{
|
|
|
|
struct msg_base msg;
|
|
|
|
|
|
|
|
msg.type = MESSAGE_TYPE_BRG_READY;
|
2015-08-02 11:41:05 +08:00
|
|
|
mailbox_send_and_wait(&msg);
|
2015-04-16 21:47:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void bridge_main(void)
|
|
|
|
{
|
|
|
|
struct msg_base *umsg;
|
|
|
|
|
2015-05-02 12:27:15 +08:00
|
|
|
rtio_init();
|
2015-04-16 21:47:05 +08:00
|
|
|
send_ready();
|
|
|
|
while(1) {
|
|
|
|
umsg = mailbox_wait_and_receive();
|
|
|
|
switch(umsg->type) {
|
2015-05-02 12:16:09 +08:00
|
|
|
case MESSAGE_TYPE_BRG_TTL_OE: {
|
|
|
|
struct msg_brg_ttl_out *msg;
|
|
|
|
|
|
|
|
msg = (struct msg_brg_ttl_out *)umsg;
|
2015-07-27 10:50:25 +08:00
|
|
|
ttl_set_oe(rtio_get_counter() + TIME_BUFFER, msg->channel, msg->value);
|
2015-05-02 12:16:09 +08:00
|
|
|
mailbox_acknowledge();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MESSAGE_TYPE_BRG_TTL_O: {
|
2015-04-16 21:47:05 +08:00
|
|
|
struct msg_brg_ttl_out *msg;
|
|
|
|
|
|
|
|
msg = (struct msg_brg_ttl_out *)umsg;
|
2015-07-27 10:50:25 +08:00
|
|
|
ttl_set_o(rtio_get_counter() + TIME_BUFFER, msg->channel, msg->value);
|
2015-04-16 21:47:05 +08:00
|
|
|
mailbox_acknowledge();
|
|
|
|
break;
|
|
|
|
}
|
2015-05-09 17:11:34 +08:00
|
|
|
case MESSAGE_TYPE_BRG_DDS_INITALL:
|
|
|
|
dds_init_all();
|
|
|
|
mailbox_acknowledge();
|
|
|
|
break;
|
2015-04-16 21:47:05 +08:00
|
|
|
case MESSAGE_TYPE_BRG_DDS_SEL: {
|
|
|
|
struct msg_brg_dds_sel *msg;
|
|
|
|
|
|
|
|
msg = (struct msg_brg_dds_sel *)umsg;
|
2015-07-08 23:22:43 +08:00
|
|
|
dds_write(DDS_GPIO, msg->channel << 1);
|
2015-04-16 21:47:05 +08:00
|
|
|
mailbox_acknowledge();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MESSAGE_TYPE_BRG_DDS_RESET: {
|
|
|
|
unsigned int g;
|
|
|
|
|
2015-05-08 14:44:39 +08:00
|
|
|
g = dds_read(DDS_GPIO);
|
2015-07-08 23:22:43 +08:00
|
|
|
dds_write(DDS_GPIO, g | 1);
|
2015-05-08 14:44:39 +08:00
|
|
|
dds_write(DDS_GPIO, g);
|
2015-04-16 21:47:05 +08:00
|
|
|
|
|
|
|
mailbox_acknowledge();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MESSAGE_TYPE_BRG_DDS_READ_REQUEST: {
|
|
|
|
struct msg_brg_dds_read_request *msg;
|
|
|
|
struct msg_brg_dds_read_reply rmsg;
|
|
|
|
|
|
|
|
msg = (struct msg_brg_dds_read_request *)umsg;
|
|
|
|
rmsg.type = MESSAGE_TYPE_BRG_DDS_READ_REPLY;
|
2015-05-08 14:44:39 +08:00
|
|
|
rmsg.data = dds_read(msg->address);
|
2015-04-16 21:47:05 +08:00
|
|
|
mailbox_send_and_wait(&rmsg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MESSAGE_TYPE_BRG_DDS_WRITE: {
|
|
|
|
struct msg_brg_dds_write *msg;
|
|
|
|
|
|
|
|
msg = (struct msg_brg_dds_write *)umsg;
|
2015-05-08 14:44:39 +08:00
|
|
|
dds_write(msg->address, msg->data);
|
2015-04-16 21:47:05 +08:00
|
|
|
mailbox_acknowledge();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MESSAGE_TYPE_BRG_DDS_FUD:
|
2015-05-08 14:44:39 +08:00
|
|
|
dds_write(DDS_FUD, 0);
|
2015-04-16 21:47:05 +08:00
|
|
|
mailbox_acknowledge();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mailbox_acknowledge();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|