Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/misoc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3640cab439a1
Choose a base ref
...
head repository: m-labs/misoc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fdf7f10f54cf
Choose a head ref
  • 2 commits
  • 43 files changed
  • 1 contributor

Commits on Mar 25, 2013

  1. software/include/base: C++ compatibility

    Sebastien Bourdeauducq committed Mar 25, 2013
    Copy the full SHA
    6a54276 View commit details
  2. Automatically build CSR access functions

    Sebastien Bourdeauducq committed Mar 25, 2013
    Copy the full SHA
    fdf7f10 View commit details
Showing with 357 additions and 398 deletions.
  1. +1 −0 .gitignore
  2. +7 −1 build.py
  3. +63 −0 cif.py
  4. +0 −10 cmacros.py
  5. +0 −16 common/csrbase.h
  6. +0 −8 common/interrupt.h
  7. +1 −2 software/bios/isr.c
  8. +1 −12 software/bios/main.c
  9. +29 −16 software/bios/microudp.c
  10. +2 −0 software/bios/microudp.h
  11. +28 −36 software/bios/sdram.c
  12. +8 −0 software/include/base/board.h
  13. +8 −0 software/include/base/console.h
  14. +8 −0 software/include/base/crc.h
  15. +8 −0 software/include/base/ctype.h
  16. +8 −0 software/include/base/endian.h
  17. +8 −0 software/include/base/errno.h
  18. +8 −0 software/include/base/float.h
  19. +8 −0 software/include/base/irq.h
  20. +8 −0 software/include/base/limits.h
  21. +8 −1 software/include/base/setjmp.h
  22. +8 −0 software/include/base/stdarg.h
  23. +8 −0 software/include/base/stddef.h
  24. +8 −0 software/include/base/stdint.h
  25. +7 −0 software/include/base/stdio.h
  26. +8 −0 software/include/base/stdlib.h
  27. +8 −0 software/include/base/string.h
  28. +8 −2 software/include/base/system.h
  29. +8 −0 software/include/base/timer.h
  30. +8 −0 software/include/base/uart.h
  31. +0 −65 software/include/hw/dfii.h
  32. +0 −51 software/include/hw/dvisampler.h
  33. +21 −0 software/include/hw/flags.h
  34. +0 −18 software/include/hw/gpio.h
  35. +0 −18 software/include/hw/identifier.h
  36. +4 −0 software/include/hw/mem.h
  37. +0 −32 software/include/hw/minimac.h
  38. +0 −27 software/include/hw/timer.h
  39. +0 −20 software/include/hw/uart.h
  40. +7 −9 software/libbase/board.c
  41. +6 −19 software/libbase/timer.c
  42. +9 −13 software/libbase/uart.c
  43. +27 −22 top.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -9,3 +9,4 @@ tools/bin2hex
tools/flterm
tools/mkmmimg
tools/byteswap
software/include/hw/csr.h
8 changes: 7 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env python3

import os

from mibuild.platforms import m1
from mibuild.tools import write_to_file

import top
import cif

def main():
plat = m1.Platform()
@@ -68,8 +72,10 @@ def main():
"lm32_dcache.v", "lm32_top.v", "lm32_debug.v", "lm32_jtag.v", "jtag_cores.v",
"jtag_tap_spartan6.v", "lm32_itlb.v", "lm32_dtlb.v")
plat.add_sources(os.path.join("verilog", "lm32"), "lm32_config.v")

plat.build_cmdline(soc)
csr_header = cif.get_csr_header(soc.csr_base, soc.csrbankarray, soc.interrupt_map)
write_to_file("software/include/hw/csr.h", csr_header)

if __name__ == "__main__":
main()
63 changes: 63 additions & 0 deletions cif.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from operator import itemgetter
import re

def get_macros(filename):
f = open(filename, "r")
r = {}
for line in f:
match = re.match("\w*#define\s+(\w+)\s+(.*)", line, re.IGNORECASE)
if match:
r[match.group(1)] = match.group(2)
return r

def _get_rw_functions(reg_name, reg_base, size):
r = ""
if size > 8:
raise NotImplementedError("Register too large")
elif size > 4:
ctype = "unsigned long long int"
elif size > 2:
ctype = "unsigned int"
elif size > 1:
ctype = "unsigned short int"
else:
ctype = "unsigned char"

r += "static inline "+ctype+" "+reg_name+"_read(void) {\n"
if size > 1:
r += "\t"+ctype+" r = MMPTR("+hex(reg_base)+");\n"
for byte in range(1, size):
r += "\tr <<= 8;\n\tr |= MMPTR("+hex(reg_base+4*byte)+");\n"
r += "\treturn r;\n}\n"
else:
r += "\treturn MMPTR("+hex(reg_base)+");\n}\n"

r += "static inline void "+reg_name+"_write("+ctype+" value) {\n"
for byte in range(size):
shift = (size-byte-1)*8
if shift:
value_shifted = "value >> "+str(shift)
else:
value_shifted = "value"
r += "\tMMPTR("+hex(reg_base+4*byte)+") = "+value_shifted+";\n"
r += "}\n"
return r

def get_csr_header(csr_base, bank_array, interrupt_map):
r = "#ifndef __HW_CSR_H\n#define __HW_CSR_H\n#include <hw/common.h>\n"
for name, rmap in bank_array.banks:
r += "\n/* "+name+" */\n"
reg_base = csr_base + 0x800*rmap.address
r += "#define "+name.upper()+"_BASE "+hex(reg_base)+"\n"
for register in rmap.description:
nr = (register.get_size() + 7)//8
r += _get_rw_functions(name + "_" + register.name, reg_base, nr)
reg_base += 4*nr
try:
interrupt_nr = interrupt_map[name]
except KeyError:
pass
else:
r += "#define "+name.upper()+"_INTERRUPT "+str(interrupt_nr)+"\n"
r += "\n#endif\n"
return r
10 changes: 0 additions & 10 deletions cmacros.py

This file was deleted.

16 changes: 0 additions & 16 deletions common/csrbase.h

This file was deleted.

8 changes: 0 additions & 8 deletions common/interrupt.h

This file was deleted.

3 changes: 1 addition & 2 deletions software/bios/isr.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <hw/uart.h>
#include <interrupt.h>
#include <hw/csr.h>
#include <irq.h>
#include <uart.h>

13 changes: 1 addition & 12 deletions software/bios/main.c
Original file line number Diff line number Diff line change
@@ -11,11 +11,11 @@
#include <timer.h>

#include <hw/mem.h>
#include <hw/minimac.h>

#include "sdram.h"
#include "dataflow.h"
#include "boot.h"
#include "microudp.h"

enum {
CSR_IE = 1, CSR_IM, CSR_IP, CSR_ICC, CSR_DCC, CSR_CC, CSR_CFG, CSR_EBA,
@@ -403,17 +403,6 @@ static void crcbios(void)
}
}

static void ethreset(void)
{
CSR_MINIMAC_PHYRST = 0;
busy_wait(2);
/* that pesky ethernet PHY needs two resets at times... */
CSR_MINIMAC_PHYRST = 1;
busy_wait(2);
CSR_MINIMAC_PHYRST = 0;
busy_wait(2);
}

static void print_mac(void)
{
unsigned char *macadr = (unsigned char *)FLASH_OFFSET_MAC_ADDRESS;
45 changes: 29 additions & 16 deletions software/bios/microudp.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include <stdio.h>
#include <system.h>
#include <crc.h>
#include <hw/minimac.h>
#include <timer.h>
#include <hw/csr.h>
#include <hw/flags.h>
#include <hw/mem.h>

#include "microudp.h"

@@ -93,11 +96,11 @@ typedef union {
} ethernet_buffer;


static int rxlen;
static unsigned int rxlen;
static ethernet_buffer *rxbuffer;
static ethernet_buffer *rxbuffer0;
static ethernet_buffer *rxbuffer1;
static int txlen;
static unsigned int txlen;
static ethernet_buffer *txbuffer;

static void send_packet(void)
@@ -110,11 +113,10 @@ static void send_packet(void)
txbuffer->raw[txlen+2] = (crc & 0xff0000) >> 16;
txbuffer->raw[txlen+3] = (crc & 0xff000000) >> 24;
txlen += 4;
CSR_MINIMAC_TXCOUNTH = (txlen & 0xff00) >> 8;
CSR_MINIMAC_TXCOUNTL = txlen & 0x00ff;
CSR_MINIMAC_TXSTART = 1;
while(!(CSR_MINIMAC_EV_PENDING & MINIMAC_EV_TX));
CSR_MINIMAC_EV_PENDING = MINIMAC_EV_TX;
minimac_tx_count_write(txlen);
minimac_tx_start_write(1);
while(!(minimac_ev_pending_read() & MINIMAC_EV_TX));
minimac_ev_pending_write(MINIMAC_EV_TX);
}

static unsigned char my_mac[6];
@@ -215,7 +217,7 @@ int microudp_arp_resolve(unsigned int ip)
static unsigned short ip_checksum(unsigned int r, void *buffer, unsigned int length, int complete)
{
unsigned char *ptr;
int i;
unsigned int i;

ptr = (unsigned char *)buffer;
length >>= 1;
@@ -349,7 +351,7 @@ void microudp_start(unsigned char *macaddr, unsigned int ip)
{
int i;

CSR_MINIMAC_EV_PENDING = MINIMAC_EV_RX0 | MINIMAC_EV_RX1 | MINIMAC_EV_TX;
minimac_ev_pending_write(MINIMAC_EV_RX0 | MINIMAC_EV_RX1 | MINIMAC_EV_TX);

rxbuffer0 = (ethernet_buffer *)MINIMAC_RX0_BASE;
rxbuffer1 = (ethernet_buffer *)MINIMAC_RX1_BASE;
@@ -368,16 +370,27 @@ void microudp_start(unsigned char *macaddr, unsigned int ip)

void microudp_service(void)
{
if(CSR_MINIMAC_EV_PENDING & MINIMAC_EV_RX0) {
rxlen = (CSR_MINIMAC_RXCOUNT0H << 8) | CSR_MINIMAC_RXCOUNT0L;
if(minimac_ev_pending_read() & MINIMAC_EV_RX0) {
rxlen = minimac_rx_count_0_read();
rxbuffer = rxbuffer0;
process_frame();
CSR_MINIMAC_EV_PENDING = MINIMAC_EV_RX0;
minimac_ev_pending_write(MINIMAC_EV_RX0);
}
if(CSR_MINIMAC_EV_PENDING & MINIMAC_EV_RX1) {
rxlen = (CSR_MINIMAC_RXCOUNT1H << 8) | CSR_MINIMAC_RXCOUNT1L;
if(minimac_ev_pending_read() & MINIMAC_EV_RX1) {
rxlen = minimac_rx_count_1_read();
rxbuffer = rxbuffer1;
process_frame();
CSR_MINIMAC_EV_PENDING = MINIMAC_EV_RX1;
minimac_ev_pending_write(MINIMAC_EV_RX1);
}
}

void ethreset(void)
{
minimac_phy_reset_write(0);
busy_wait(2);
/* that pesky ethernet PHY needs two resets at times... */
minimac_phy_reset_write(1);
busy_wait(2);
minimac_phy_reset_write(0);
busy_wait(2);
}
2 changes: 2 additions & 0 deletions software/bios/microudp.h
Original file line number Diff line number Diff line change
@@ -14,4 +14,6 @@ int microudp_send(unsigned short src_port, unsigned short dst_port, unsigned int
void microudp_set_callback(udp_callback callback);
void microudp_service(void);

void ethreset(void);

#endif /* __MICROUDP_H */
Loading