Commit c8b68c52 authored by Tristan Gingold's avatar Tristan Gingold

Demo fip urv program (just leds).

parent 645eb52d
# and don't touch the rest unless you know what you're doing.
CROSS_COMPILE ?= riscv32-elf-
XCC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
OUTPUT=fip_urv
CFLAGS = -mabi=ilp32 -march=rv32im -O
OBJS = crt0.o $(OUTPUT).o
LDS = ram.ld
all: $(OUTPUT).hex
fip_urv_regs.h: ../../hdl/rtl/urv_wic/fip_urv_regs.cheby
cheby --gen-c=$@ -i $<
%.bin: %.elf
${OBJCOPY} -O binary $< $@
%.hex: %.bin
./tobin.py $< > $@
$(OUTPUT).elf: $(LDS) $(OBJS)
${XCC} $(CFLAGS) -o $@ -nostartfiles $(OBJS) -T $(LDS)
$(SIZE) $@
clean:
rm -f $(OUTPUT).elf $(OUTPUT).bin $(OUTPUT).hex $(OBJS)
%.o: %.S
${XCC} -c $(CFLAGS) $< -o $@
%.o: %.c
${XCC} -c $(CFLAGS) $< -o $@
.section .boot, "ax", @progbits
.global _start
_start:
la gp, _gp # Initialize global pointer
la sp, _fstack
# clear the bss segment
la t0, _fbss
la t1, _end
1:
sw zero,0(t0)
addi t0, t0, 4
bltu t0, t1, 1b
call main
#include <stdint.h>
#include "fip_urv_regs.h"
int
main (void)
{
unsigned char leds;
volatile struct fip_urv_regs *regs =
(volatile struct fip_urv_regs *)0x100000;
int j;
/* Init. */
leds = 1;
/* Infinite loop. */
while (1)
{
/* Check for FIP message. */
regs->leds = leds;
leds = ((leds << 1) & 0x3f) | ((leds >> 6) & 1);
for (j = 0; j < 1000000; j++)
asm volatile ("nop");
}
}
#ifndef __CHEBY__FIP_URV_REGS__H__
#define __CHEBY__FIP_URV_REGS__H__
#define FIP_URV_REGS_SIZE 16384
/* PLC processor control */
#define FIP_URV_REGS_PLC_CTRL 0x0UL
#define FIP_URV_REGS_PLC_CTRL_RST 0x1UL
/* Status bits from NanoFIP */
#define FIP_URV_REGS_FIP_STATUS 0x4UL
#define FIP_URV_REGS_FIP_STATUS_VAR1_RDY 0x1UL
#define FIP_URV_REGS_FIP_STATUS_VAR3_RDY 0x2UL
/* presence lines for boards */
#define FIP_URV_REGS_PRESENCE 0x8UL
#define FIP_URV_REGS_PRESENCE_EN_MASK 0xffUL
#define FIP_URV_REGS_PRESENCE_EN_SHIFT 0
/* led */
#define FIP_URV_REGS_LEDS 0xcUL
#define FIP_URV_REGS_LEDS_VAL_MASK 0x3fUL
#define FIP_URV_REGS_LEDS_VAL_SHIFT 0
/* None */
#define FIP_URV_REGS_BOARDS 0x20UL
#define FIP_URV_REGS_BOARDS_SIZE 32
/* None */
#define FIP_URV_REGS_BOARDS_PINS_0 0x20UL
/* None */
#define FIP_URV_REGS_BOARDS_PINS_1 0x24UL
/* None */
#define FIP_URV_REGS_BOARDS_PINS_2 0x28UL
/* None */
#define FIP_URV_REGS_BOARDS_PINS_3 0x2cUL
/* None */
#define FIP_URV_REGS_BOARDS_PINS_4 0x30UL
/* None */
#define FIP_URV_REGS_BOARDS_PINS_5 0x34UL
/* None */
#define FIP_URV_REGS_BOARDS_PINS_6 0x38UL
/* None */
#define FIP_URV_REGS_BOARDS_PINS_7 0x3cUL
/* NanoFIP internal memory/registers */
#define FIP_URV_REGS_FIP_REG 0x200UL
#define FIP_URV_REGS_FIP_REG_SIZE 512
/* Memory of the PLC urv */
#define FIP_URV_REGS_PLC_MEM 0x2000UL
#define FIP_URV_REGS_PLC_MEM_SIZE 8192
struct fip_urv_regs {
/* [0x0]: REG (rw) PLC processor control */
uint32_t plc_ctrl;
/* [0x4]: REG (ro) Status bits from NanoFIP */
uint32_t fip_status;
/* [0x8]: REG (ro) presence lines for boards */
uint32_t presence;
/* [0xc]: REG (rw) led */
uint32_t leds;
/* padding to: 8 words */
uint32_t __padding_0[4];
/* [0x20]: BLOCK (no description) */
struct boards {
/* [0x0]: REG (ro) (no description) */
uint32_t pins_0;
/* [0x4]: REG (ro) (no description) */
uint32_t pins_1;
/* [0x8]: REG (ro) (no description) */
uint32_t pins_2;
/* [0xc]: REG (ro) (no description) */
uint32_t pins_3;
/* [0x10]: REG (ro) (no description) */
uint32_t pins_4;
/* [0x14]: REG (ro) (no description) */
uint32_t pins_5;
/* [0x18]: REG (ro) (no description) */
uint32_t pins_6;
/* [0x1c]: REG (ro) (no description) */
uint32_t pins_7;
} boards;
/* padding to: 128 words */
uint32_t __padding_1[112];
/* [0x200]: SUBMAP NanoFIP internal memory/registers */
uint32_t fip_reg[128];
/* padding to: 2048 words */
uint32_t __padding_2[1792];
/* [0x2000]: SUBMAP Memory of the PLC urv */
uint32_t plc_mem[2048];
};
#endif /* __CHEBY__FIP_URV_REGS__H__ */
OUTPUT_FORMAT("elf32-littleriscv")
ENTRY(_start)
MEMORY
{
rom :
ORIGIN = 0x00000000,
LENGTH = 2048
bss :
ORIGIN = 0x00010000,
LENGTH = 2048
/* Sorry, but there is no initialized ram. */
empty :
ORIGIN = 0x00020000,
LENGTH = 0
}
SECTIONS
{
.boot : { *(.boot) } > rom
.text : { *(.text .text.*) } > rom =0
_gp = .;
.rodata : { *(.rodata .rodata.*) } > empty
.data : { *(.data .data.*) } > empty
.bss : {
_fbss = .;
*(.bss .bss.*)
*(COMMON)
_ebss = .;
. = ALIGN(.);
_fstack = . + 1024;
_end = .;
} > bss
}
#!/usr/bin/env python
import struct
import sys
def main():
if len(sys.argv) < 2:
sys.exit("Usage: {} FILE".format(sys.argv[0]))
filename = sys.argv[1]
b = open(filename, 'rb').read()
if len(b) % 4 != 0:
sys.exit("length of {} is not a multiple of 4".format(filename))
for i in range(0, len(b), 4):
v, = struct.unpack('<I', b[i:i+4])
print('{:08x}'.format(v))
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment