mirror of https://github.com/m-labs/artiq.git
runtime: monitor RTIO clock status
This commit is contained in:
parent
299bc1cb7e
commit
09d837e4ba
|
@ -26,6 +26,16 @@ long long int clock_get_ms(void)
|
||||||
return clock_ms;
|
return clock_ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void busywait_us(long long int us)
|
||||||
|
{
|
||||||
|
long long int threshold;
|
||||||
|
|
||||||
|
timer0_update_value_write(1);
|
||||||
|
threshold = timer0_value_read() - us*(long long int)identifier_frequency_read()/1000000LL;
|
||||||
|
while(timer0_value_read() > threshold)
|
||||||
|
timer0_update_value_write(1);
|
||||||
|
}
|
||||||
|
|
||||||
struct watchdog {
|
struct watchdog {
|
||||||
int active;
|
int active;
|
||||||
long long int threshold;
|
long long int threshold;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
void clock_init(void);
|
void clock_init(void);
|
||||||
long long int clock_get_ms(void);
|
long long int clock_get_ms(void);
|
||||||
|
void busywait_us(long long us);
|
||||||
|
|
||||||
#define MAX_WATCHDOGS 16
|
#define MAX_WATCHDOGS 16
|
||||||
|
|
||||||
|
|
|
@ -128,20 +128,30 @@ static int check_flash_storage_key_len(char *key, unsigned int key_len)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void switch_clock(int clk)
|
static int switch_clock(int clk)
|
||||||
{
|
{
|
||||||
int current_clk;
|
int current_clk;
|
||||||
|
|
||||||
current_clk = rtio_crg_clock_sel_read();
|
current_clk = rtio_crg_clock_sel_read();
|
||||||
if(clk == current_clk)
|
if(clk == current_clk) {
|
||||||
return;
|
#ifdef CSR_RTIO_CRG_PLL_RESET_ADDR
|
||||||
|
busywait_us(150);
|
||||||
|
if(!rtio_crg_pll_locked_read())
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
#ifdef CSR_RTIO_CRG_PLL_RESET_ADDR
|
#ifdef CSR_RTIO_CRG_PLL_RESET_ADDR
|
||||||
rtio_crg_pll_reset_write(1);
|
rtio_crg_pll_reset_write(1);
|
||||||
#endif
|
#endif
|
||||||
rtio_crg_clock_sel_write(clk);
|
rtio_crg_clock_sel_write(clk);
|
||||||
#ifdef CSR_RTIO_CRG_PLL_RESET_ADDR
|
#ifdef CSR_RTIO_CRG_PLL_RESET_ADDR
|
||||||
rtio_crg_pll_reset_write(0);
|
rtio_crg_pll_reset_write(0);
|
||||||
|
busywait_us(150);
|
||||||
|
if(!rtio_crg_pll_locked_read())
|
||||||
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int process_input(void)
|
static int process_input(void)
|
||||||
|
@ -170,8 +180,10 @@ static int process_input(void)
|
||||||
submit_output(9);
|
submit_output(9);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch_clock(buffer_in[9]);
|
if(switch_clock(buffer_in[9]))
|
||||||
buffer_out[8] = REMOTEMSG_TYPE_CLOCK_SWITCH_COMPLETED;
|
buffer_out[8] = REMOTEMSG_TYPE_CLOCK_SWITCH_COMPLETED;
|
||||||
|
else
|
||||||
|
buffer_out[8] = REMOTEMSG_TYPE_CLOCK_SWITCH_FAILED;
|
||||||
submit_output(9);
|
submit_output(9);
|
||||||
break;
|
break;
|
||||||
case REMOTEMSG_TYPE_LOAD_OBJECT:
|
case REMOTEMSG_TYPE_LOAD_OBJECT:
|
||||||
|
@ -543,11 +555,20 @@ void session_poll(void **data, int *len)
|
||||||
{
|
{
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
if((user_kernel_state == USER_KERNEL_RUNNING) && watchdog_expired()) {
|
if(user_kernel_state == USER_KERNEL_RUNNING) {
|
||||||
|
if(watchdog_expired()) {
|
||||||
log("Watchdog expired");
|
log("Watchdog expired");
|
||||||
*len = -1;
|
*len = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#ifdef CSR_RTIO_CRG_PLL_RESET_ADDR
|
||||||
|
if(!rtio_crg_pll_locked_read()) {
|
||||||
|
log("RTIO clock failure");
|
||||||
|
*len = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
l = get_out_packet_len();
|
l = get_out_packet_len();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue