2014-08-28 16:56:48 +08:00
|
|
|
#include <generated/csr.h>
|
|
|
|
|
2014-09-25 12:55:50 +08:00
|
|
|
#include "exceptions.h"
|
2014-08-28 16:56:48 +08:00
|
|
|
#include "rtio.h"
|
|
|
|
|
|
|
|
void rtio_init(void)
|
|
|
|
{
|
2014-11-30 00:13:54 +08:00
|
|
|
rtio_reset_write(1);
|
|
|
|
rtio_reset_write(0);
|
2015-05-02 11:47:11 +08:00
|
|
|
rtio_reset_phy_write(0);
|
2014-08-28 16:56:48 +08:00
|
|
|
}
|
|
|
|
|
2015-05-08 14:44:39 +08:00
|
|
|
long long int rtio_get_counter(void)
|
2014-08-28 16:56:48 +08:00
|
|
|
{
|
2015-05-08 14:44:39 +08:00
|
|
|
rtio_counter_update_write(1);
|
|
|
|
return rtio_counter_read();
|
2014-09-11 23:14:45 +08:00
|
|
|
}
|
|
|
|
|
2015-04-14 19:44:45 +08:00
|
|
|
void rtio_set_o(long long int timestamp, int channel, int value)
|
|
|
|
{
|
|
|
|
rtio_chan_sel_write(channel);
|
|
|
|
rtio_o_timestamp_write(timestamp);
|
|
|
|
rtio_o_address_write(0);
|
|
|
|
rtio_o_data_write(value);
|
2015-05-08 14:44:39 +08:00
|
|
|
rtio_write_and_process_status(timestamp, channel);
|
2015-04-14 19:44:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rtio_set_oe(long long int timestamp, int channel, int oe)
|
|
|
|
{
|
|
|
|
rtio_chan_sel_write(channel);
|
|
|
|
rtio_o_timestamp_write(timestamp);
|
|
|
|
rtio_o_address_write(1);
|
|
|
|
rtio_o_data_write(oe);
|
2015-05-08 14:44:39 +08:00
|
|
|
rtio_write_and_process_status(timestamp, channel);
|
2015-04-14 19:44:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rtio_set_sensitivity(long long int timestamp, int channel, int sensitivity)
|
|
|
|
{
|
|
|
|
rtio_chan_sel_write(channel);
|
|
|
|
rtio_o_timestamp_write(timestamp);
|
|
|
|
rtio_o_address_write(2);
|
|
|
|
rtio_o_data_write(sensitivity);
|
2015-05-08 14:44:39 +08:00
|
|
|
rtio_write_and_process_status(timestamp, channel);
|
2014-11-21 04:32:56 +08:00
|
|
|
}
|
|
|
|
|
2014-11-30 00:13:54 +08:00
|
|
|
long long int rtio_get(int channel, long long int time_limit)
|
2014-09-14 23:30:33 +08:00
|
|
|
{
|
|
|
|
long long int r;
|
2014-12-01 14:29:50 +08:00
|
|
|
int status;
|
2014-09-14 23:30:33 +08:00
|
|
|
|
|
|
|
rtio_chan_sel_write(channel);
|
2014-12-01 17:32:36 +08:00
|
|
|
while((status = rtio_i_status_read())) {
|
2014-12-01 14:29:50 +08:00
|
|
|
if(rtio_i_status_read() & RTIO_I_STATUS_OVERFLOW) {
|
2014-11-30 00:13:54 +08:00
|
|
|
rtio_i_overflow_reset_write(1);
|
2015-03-13 21:55:18 +08:00
|
|
|
exception_raise_params(EID_RTIO_OVERFLOW,
|
|
|
|
channel, 0, 0);
|
2014-10-21 23:41:02 +08:00
|
|
|
}
|
2014-12-01 14:29:50 +08:00
|
|
|
if(rtio_get_counter() >= time_limit) {
|
|
|
|
/* check empty flag again to prevent race condition.
|
|
|
|
* now we are sure that the time limit has been exceeded.
|
|
|
|
*/
|
|
|
|
if(rtio_i_status_read() & RTIO_I_STATUS_EMPTY)
|
|
|
|
return -1;
|
2014-09-14 23:30:33 +08:00
|
|
|
}
|
2014-12-01 14:29:50 +08:00
|
|
|
/* input FIFO is empty - keep waiting */
|
2014-09-14 23:30:33 +08:00
|
|
|
}
|
2014-12-01 14:29:50 +08:00
|
|
|
r = rtio_i_timestamp_read();
|
|
|
|
rtio_i_re_write(1);
|
|
|
|
return r;
|
2014-09-14 23:30:33 +08:00
|
|
|
}
|