mirror of https://github.com/m-labs/artiq.git
runtime: allow selecting external clock at startup
This commit is contained in:
parent
09d837e4ba
commit
7feaca7c7c
|
@ -1,6 +1,6 @@
|
||||||
include $(MSCDIR)/software/common.mak
|
include $(MSCDIR)/software/common.mak
|
||||||
|
|
||||||
OBJECTS := isr.o flash_storage.o clock.o elf_loader.o services.o session.o log.o test_mode.o kloader.o bridge_ctl.o mailbox.o ksupport_data.o kserver.o moninj.o main.o
|
OBJECTS := isr.o flash_storage.o clock.o rtiocrg.o elf_loader.o services.o session.o log.o test_mode.o kloader.o bridge_ctl.o mailbox.o ksupport_data.o kserver.o moninj.o main.o
|
||||||
OBJECTS_KSUPPORT := ksupport.o exception_jmp.o exceptions.o mailbox.o bridge.o rtio.o ttl.o dds.o
|
OBJECTS_KSUPPORT := ksupport.o exception_jmp.o exceptions.o mailbox.o bridge.o rtio.o ttl.o dds.o
|
||||||
|
|
||||||
CFLAGS += -Ilwip/src/include -Iliblwip
|
CFLAGS += -Ilwip/src/include -Iliblwip
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "kloader.h"
|
#include "kloader.h"
|
||||||
#include "flash_storage.h"
|
#include "flash_storage.h"
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
|
#include "rtiocrg.h"
|
||||||
#include "test_mode.h"
|
#include "test_mode.h"
|
||||||
#include "kserver.h"
|
#include "kserver.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
|
@ -250,13 +251,10 @@ int main(void)
|
||||||
puts("ARTIQ runtime built "__DATE__" "__TIME__"\n");
|
puts("ARTIQ runtime built "__DATE__" "__TIME__"\n");
|
||||||
|
|
||||||
clock_init();
|
clock_init();
|
||||||
|
rtiocrg_init();
|
||||||
puts("Press 't' to enter test mode...");
|
puts("Press 't' to enter test mode...");
|
||||||
blink_led();
|
blink_led();
|
||||||
|
|
||||||
#ifdef CSR_RTIO_CRG_PLL_RESET_ADDR
|
|
||||||
rtio_crg_pll_reset_write(0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(check_test_mode()) {
|
if(check_test_mode()) {
|
||||||
puts("Entering test mode.");
|
puts("Entering test mode.");
|
||||||
test_main();
|
test_main();
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <generated/csr.h>
|
||||||
|
|
||||||
|
#include "clock.h"
|
||||||
|
#include "flash_storage.h"
|
||||||
|
#include "rtiocrg.h"
|
||||||
|
|
||||||
|
void rtiocrg_init(void)
|
||||||
|
{
|
||||||
|
char b;
|
||||||
|
int clk;
|
||||||
|
|
||||||
|
#ifdef CSR_RTIO_CRG_PLL_RESET_ADDR
|
||||||
|
rtio_crg_pll_reset_write(0);
|
||||||
|
#endif
|
||||||
|
b = 'i';
|
||||||
|
clk = 0;
|
||||||
|
fs_read("startup_clock", &b, 1, NULL);
|
||||||
|
if(b == 'i')
|
||||||
|
printf("Startup RTIO clock: internal\n");
|
||||||
|
else if(b == 'e') {
|
||||||
|
printf("Startup RTIO clock: external\n");
|
||||||
|
clk = 1;
|
||||||
|
} else
|
||||||
|
printf("WARNING: unknown startup_clock entry in flash storage\n");
|
||||||
|
|
||||||
|
if(!rtiocrg_switch_clock(clk))
|
||||||
|
printf("WARNING: startup RTIO clock failed\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int rtiocrg_check(void)
|
||||||
|
{
|
||||||
|
#ifdef CSR_RTIO_CRG_PLL_RESET_ADDR
|
||||||
|
return rtio_crg_pll_locked_read();
|
||||||
|
#else
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int rtiocrg_switch_clock(int clk)
|
||||||
|
{
|
||||||
|
int current_clk;
|
||||||
|
|
||||||
|
current_clk = rtio_crg_clock_sel_read();
|
||||||
|
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;
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef __RTIOCRG_H
|
||||||
|
#define __RTIOCRG_H
|
||||||
|
|
||||||
|
void rtiocrg_init(void);
|
||||||
|
int rtiocrg_check(void);
|
||||||
|
int rtiocrg_switch_clock(int clk);
|
||||||
|
|
||||||
|
#endif /* __RTIOCRG_H */
|
|
@ -12,6 +12,7 @@
|
||||||
#include "kloader.h"
|
#include "kloader.h"
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
#include "flash_storage.h"
|
#include "flash_storage.h"
|
||||||
|
#include "rtiocrg.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
|
|
||||||
#define BUFFER_IN_SIZE (1024*1024)
|
#define BUFFER_IN_SIZE (1024*1024)
|
||||||
|
@ -128,32 +129,6 @@ static int check_flash_storage_key_len(char *key, unsigned int key_len)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int switch_clock(int clk)
|
|
||||||
{
|
|
||||||
int current_clk;
|
|
||||||
|
|
||||||
current_clk = rtio_crg_clock_sel_read();
|
|
||||||
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)
|
static int process_input(void)
|
||||||
{
|
{
|
||||||
switch(buffer_in[8]) {
|
switch(buffer_in[8]) {
|
||||||
|
@ -180,7 +155,7 @@ static int process_input(void)
|
||||||
submit_output(9);
|
submit_output(9);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(switch_clock(buffer_in[9]))
|
if(rtiocrg_switch_clock(buffer_in[9]))
|
||||||
buffer_out[8] = REMOTEMSG_TYPE_CLOCK_SWITCH_COMPLETED;
|
buffer_out[8] = REMOTEMSG_TYPE_CLOCK_SWITCH_COMPLETED;
|
||||||
else
|
else
|
||||||
buffer_out[8] = REMOTEMSG_TYPE_CLOCK_SWITCH_FAILED;
|
buffer_out[8] = REMOTEMSG_TYPE_CLOCK_SWITCH_FAILED;
|
||||||
|
@ -561,13 +536,11 @@ void session_poll(void **data, int *len)
|
||||||
*len = -1;
|
*len = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef CSR_RTIO_CRG_PLL_RESET_ADDR
|
if(!rtiocrg_check()) {
|
||||||
if(!rtio_crg_pll_locked_read()) {
|
|
||||||
log("RTIO clock failure");
|
log("RTIO clock failure");
|
||||||
*len = -1;
|
*len = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l = get_out_packet_len();
|
l = get_out_packet_len();
|
||||||
|
|
Loading…
Reference in New Issue