2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 03:08:27 +08:00

runtime: monitor RTIO clock status

This commit is contained in:
Sebastien Bourdeauducq 2015-07-28 00:05:24 +08:00
parent 299bc1cb7e
commit 09d837e4ba
3 changed files with 41 additions and 9 deletions

View File

@ -26,6 +26,16 @@ long long int clock_get_ms(void)
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 {
int active;
long long int threshold;

View File

@ -3,6 +3,7 @@
void clock_init(void);
long long int clock_get_ms(void);
void busywait_us(long long us);
#define MAX_WATCHDOGS 16

View File

@ -128,20 +128,30 @@ static int check_flash_storage_key_len(char *key, unsigned int key_len)
return 1;
}
static void switch_clock(int clk)
static int switch_clock(int clk)
{
int current_clk;
current_clk = rtio_crg_clock_sel_read();
if(clk == current_clk)
return;
if(clk == current_clk) {
#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
rtio_crg_pll_reset_write(1);
#endif
rtio_crg_clock_sel_write(clk);
#ifdef CSR_RTIO_CRG_PLL_RESET_ADDR
rtio_crg_pll_reset_write(0);
busywait_us(150);
if(!rtio_crg_pll_locked_read())
return 0;
#endif
return 1;
}
static int process_input(void)
@ -170,8 +180,10 @@ static int process_input(void)
submit_output(9);
break;
}
switch_clock(buffer_in[9]);
buffer_out[8] = REMOTEMSG_TYPE_CLOCK_SWITCH_COMPLETED;
if(switch_clock(buffer_in[9]))
buffer_out[8] = REMOTEMSG_TYPE_CLOCK_SWITCH_COMPLETED;
else
buffer_out[8] = REMOTEMSG_TYPE_CLOCK_SWITCH_FAILED;
submit_output(9);
break;
case REMOTEMSG_TYPE_LOAD_OBJECT:
@ -543,10 +555,19 @@ void session_poll(void **data, int *len)
{
int l;
if((user_kernel_state == USER_KERNEL_RUNNING) && watchdog_expired()) {
log("Watchdog expired");
*len = -1;
return;
if(user_kernel_state == USER_KERNEL_RUNNING) {
if(watchdog_expired()) {
log("Watchdog expired");
*len = -1;
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();