From e4251c7f414b0cebaf2912b04d3cc46b3332796c Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 22 Apr 2015 15:01:32 +0800 Subject: [PATCH] runtime: get lwip to run --- artiq/gateware/amp/kernel_cpu.py | 2 +- soc/runtime/Makefile | 2 + soc/runtime/kloader.h | 4 +- soc/runtime/ksupport.ld | 4 +- soc/runtime/linker.ld | 2 +- soc/runtime/main.c | 80 ++++++++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 6 deletions(-) diff --git a/artiq/gateware/amp/kernel_cpu.py b/artiq/gateware/amp/kernel_cpu.py index bd8255f66..b66641997 100644 --- a/artiq/gateware/amp/kernel_cpu.py +++ b/artiq/gateware/amp/kernel_cpu.py @@ -9,7 +9,7 @@ from misoclib.soc import mem_decoder class KernelCPU(Module): def __init__(self, platform, lasmim, - exec_address=0x40020000, + exec_address=0x40400000, main_mem_origin=0x40000000, l2_size=8192): self._reset = CSRStorage(reset=1) diff --git a/soc/runtime/Makefile b/soc/runtime/Makefile index 100f72b2d..78b9d4d4d 100644 --- a/soc/runtime/Makefile +++ b/soc/runtime/Makefile @@ -20,6 +20,8 @@ $(error failed to determine UP/AMP build) endif endif +CFLAGS += -Ilwip/src/include -Iliblwip + all: runtime.bin runtime.fbi # pull in dependency info for *existing* .o files diff --git a/soc/runtime/kloader.h b/soc/runtime/kloader.h index 380ca2fb3..c2f1e5ead 100644 --- a/soc/runtime/kloader.h +++ b/soc/runtime/kloader.h @@ -1,8 +1,8 @@ #ifndef __KLOADER_H #define __KLOADER_H -#define KERNELCPU_EXEC_ADDRESS 0x40020000 -#define KERNELCPU_PAYLOAD_ADDRESS 0x40024000 +#define KERNELCPU_EXEC_ADDRESS 0x40400000 +#define KERNELCPU_PAYLOAD_ADDRESS 0x40404000 typedef void (*kernel_function)(void); diff --git a/soc/runtime/ksupport.ld b/soc/runtime/ksupport.ld index bc6912f83..b4a35873b 100644 --- a/soc/runtime/ksupport.ld +++ b/soc/runtime/ksupport.ld @@ -3,11 +3,11 @@ ENTRY(_start) INCLUDE generated/regions.ld -/* First 128K of main memory are reserved for runtime code/data +/* First 4M of main memory are reserved for runtime code/data * then comes kernel memory. First 16K of kernel memory are for support code. */ MEMORY { - ksupport : ORIGIN = 0x40020000, LENGTH = 0x4000 + ksupport : ORIGIN = 0x40400000, LENGTH = 0x4000 } /* On AMP systems, kernel stack is at the end of main RAM, diff --git a/soc/runtime/linker.ld b/soc/runtime/linker.ld index fa988613c..5fc12b610 100644 --- a/soc/runtime/linker.ld +++ b/soc/runtime/linker.ld @@ -7,7 +7,7 @@ INCLUDE generated/regions.ld * ld does not allow this expression here. */ MEMORY { - runtime : ORIGIN = 0x40000000, LENGTH = 0x20000 /* 128K */ + runtime : ORIGIN = 0x40000000, LENGTH = 0x400000 /* 4M */ } /* Kernel memory space start right after the runtime, diff --git a/soc/runtime/main.c b/soc/runtime/main.c index 873e2aaca..49158d0e6 100644 --- a/soc/runtime/main.c +++ b/soc/runtime/main.c @@ -6,10 +6,66 @@ #include #include #include +#include + +#ifdef CSR_ETHMAC_BASE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif #include "test_mode.h" #include "session.h" +#ifdef CSR_ETHMAC_BASE +unsigned char macadr[6] = {0x10, 0xe2, 0xd5, 0x00, 0x00, 0x00}; + +u32_t clock_ms; + +static void clock_init(void) +{ + timer0_en_write(0); + timer0_load_write(0xffffffff); + timer0_reload_write(0xffffffff); + timer0_en_write(1); + clock_ms = 0; +} + +u32_t sys_now(void) +{ + unsigned int freq; + unsigned int prescaler; + + freq = identifier_frequency_read(); + prescaler = freq/1000; /* sys_now expect time in ms */ + timer0_update_value_write(1); + clock_ms += (0xffffffff - timer0_value_read())/prescaler; + /* Reset timer to avoid rollover, this will increase clock_ms + drift but we don't need precision */ + timer0_en_write(0); + timer0_en_write(1); + return clock_ms; +} + +static struct netif netif; + +static void lwip_service(void) +{ + sys_check_timeouts(); + if(ethmac_sram_writer_ev_pending_read() & ETHMAC_EV_SRAM_WRITER) { + liteeth_input(&netif); + ethmac_sram_writer_ev_pending_write(ETHMAC_EV_SRAM_WRITER); + } +} +#endif + void comm_service(void) { char *txdata; @@ -18,6 +74,10 @@ void comm_service(void) static int rxpending; int r, i; +#ifdef CSR_ETHMAC_BASE + lwip_service(); +#endif + if(!rxpending && uart_read_nonblock()) { rxdata = uart_read(); rxpending = 1; @@ -38,6 +98,26 @@ void comm_service(void) static void regular_main(void) { +#ifdef CSR_ETHMAC_BASE + struct ip4_addr local_ip; + struct ip4_addr netmask; + struct ip4_addr gateway_ip; + + time_init(); + clock_init(); + + IP4_ADDR(&local_ip, 192, 168, 0, 42); + IP4_ADDR(&netmask, 255, 255, 255, 0); + IP4_ADDR(&gateway_ip, 192, 168, 0, 1); + + lwip_init(); + + netif_add(&netif, &local_ip, &netmask, &gateway_ip, 0, liteeth_init, ethernet_input); + netif_set_default(&netif); + netif_set_up(&netif); + netif_set_link_up(&netif); +#endif + session_start(); while(1) comm_service();