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: micropython/micropython
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: fupy/micropython
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.

Commits on Aug 8, 2019

  1. Take a copy of the minimal target

    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    0cfa609 View commit details
  2. lm32: Basic port to the litex SoC with a lm32 CPU

    This port requires a lm32 cross compiler with libgcc enabled.
    
    I built a GCC 6.2 toolchain with newlib by doing the following:
    
      $ ls
      binutils-2.27  gcc-6.2.0  mpc-1.0.2   newlib-2.4.0.20161025
      gmp-6.1.1  mpfr-3.1.5
      $ mkdir build
      $ cd build
      $ ../gcc-6.2.0/configure  --prefix=/opt/lm32 --enable-languages=c --target=lm32-elf
      $ make
      $ mkdir /opt/lm32 && chown $USER /opt/lm32
      $ make install
    
    Then build a litex Qemu with the following:
    
      $ git clone https://github.com/shenki/qemu-litex
      $ cd qemu-litex
      $ ./configure --target-list=lm32-softmmu
      $ make
    
    To build Micropython:
    
      $ cd micropython/lm32
      $ CROSS_COMPILE=/opt/lm32/bin/lm32-elf- make deploy
    
    This produces an elf at lm32/build/firmware.elf. To run it:
    
      ./lm32-softmmu/qemu-system-lm32 -M litex -nographic -nodefaults \
       -serial stdio -kernel ~/dev/micropython/lm32/build/firmware.elf
       MicroPython v1.8.6-12-g674efbf5680a on 2016-11-20; litex with lm32
       Type "help()" for more information.
       >>>
    
    To debug it:
    
      ./lm32-softmmu/qemu-system-lm32 -M litex -nographic -nodefaults \
       -serial stdio -kernel ~/dev/micropython/lm32/build/firmware.elf \
       -S -s -monitor pty
      char device redirected to /dev/pts/12 (label compat_monitor0)
    
    This requires a lm32 GDB:
    
      $ conda/bin/lm32-elf-gdb build/firmware.elf -ex 'target remote localhost:1234'
      Reading symbols from build/firmware.elf...done.
      Remote debugging using localhost:1234
      0x40000000 in _start ()
      (gdb) c
      Continuing.
    
    You can attach to the monitor to view the lm32 registers that are not
    exposed by qemu:
    
      screen /dev/pts/12
      (qemu) QEMU 2.7.50 monitor - type 'help' for more information
      (qemu) info registers
      IN: PC=40000000
      ie=00000000 (IE=0 EIE=0 BIE=0) im=00000000 ip=00000000
      eba=00000000 deba=00000000
    
    The port currently assumes you are running on the opsis-soc, targeted
    for the minispartan6. You can adjust this by replacing the
    include/generated directories with the ones from your litex soc in both
    Qemu and Micropython.
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    f41bf29 View commit details
  3. lm32: Build .bin as default target

    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    b4ea4ba View commit details
  4. lm32: Update generated headers

    Updated to use mimasv2 using headers from HDMI2USB build at commit
    cbd1e31b3a9f88e0d1ecb682b51f6d41454766de
    katharosada authored and mithro committed Aug 8, 2019
    Copy the full SHA
    89863dc View commit details
  5. lm32: include generated memory regions linker script

    We were hardcoding the memory regions in the micropython linker script
    (lm32.ld). This way we pull in the correct definitions whenever we
    update the generated files.
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    e986102 View commit details
  6. lm32: remove unused code from main

    This follows what other ports do here.
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    4b74d77 View commit details
  7. lm32: Attempt to implement ctrl+c interrupt

    Doesn't work.
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    27c469a View commit details
  8. lm32: Fix exception keystroke handling

    ctrl+c can now interrupt execution.
    
    >>> while True:
    ...     pass
    ...
    Traceback (most recent call last):
      File "<stdin>", in <module>
    KeyboardInterrupt:
    >>>
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    5ad8bda View commit details
  9. lm32: remove unused defines

    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    caa159f View commit details
  10. lm32: Don't build in frozen modules yet

    We don't have any, and this was breaking building. It can be added back
    later when we need it.
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    0ddc239 View commit details
  11. lm32: clean up the makefile

    This does change some flags passed to the compiler, but for the most
    part should not result in any functional change.
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    9947b51 View commit details
  12. lm32: Add longint implementation

    Adds about 12k to the code size. Most ports MPZ over the LONGLONG
    version, which was my criteria for picking it.
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    58519ec View commit details
  13. lm32: Add machine module

    This is the first module we've enabled. With these changes in place we
    it should't be much effort to add modules.
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    f1a653a View commit details
  14. gitignore: add vim .un~ undo files to ignore

    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    7ddfe04 View commit details
  15. lm32: Add litex module

    Doesn't do anything yet.
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    277b347 View commit details
  16. lm32: Update generated headers

    Only change is the addition of the CAS module for allowing software
    access to the push buttons and LEDs
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    e341311 View commit details
  17. lm32: Add leds module

    This lets micropython control the LEDs
    
    >>> import litex
    >>> led1 = litex.LED(1)
    >>> led1
    LED(1)
    >>> led1.on()
    >>> led1.off()
    >>> led1.read()
    False
    >>> led1.on()
    >>> led1.read()
    False
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    f6dfed0 View commit details
  18. lm32: point to latest gcc directory

    This should not be hardcoded.
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    692046e View commit details
  19. lm32: link with GCC and remove hardcoded paths

    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    67a419b View commit details
  20. lm32: update generated directory

    Generated from
    
     https://github.com/timvideos/HDMI2USB-litex-firmware
     cba56bb65db62a4ee25bb66f5858349f8b043b9b.
    
    Signed-off-by: Joel Stanley <joel@jms.id.au>
    shenki authored and mithro committed Aug 8, 2019
    Copy the full SHA
    4edb711 View commit details
  21. Removing generated files.

    mithro committed Aug 8, 2019
    Copy the full SHA
    5a8aad4 View commit details
  22. Working on Makefile.

    mithro committed Aug 8, 2019
    Copy the full SHA
    7897471 View commit details
  23. Copy the full SHA
    07cc426 View commit details
  24. Better Makefile.

    mithro committed Aug 8, 2019
    Copy the full SHA
    f52efdd View commit details
  25. Allow litex leds to build with out cas

    This is needed for opsis.
    
    Created issue to get cas enabled on opsis
    timvideos/HDMI2USB-litex-firmware#344
    karl-malakoff authored and mithro committed Aug 8, 2019
    Copy the full SHA
    f07e051 View commit details
  26. Fixed read function for cas leds

    litex_led_read now returns the correct value based on the state of the
    led.
    karl-malakoff authored and mithro committed Aug 8, 2019
    Copy the full SHA
    1cd8571 View commit details
  27. Copy the full SHA
    1f59d08 View commit details
  28. Copy the full SHA
    7ef348f View commit details
  29. Move "litex" port to "ports/fupy"

    ewenmcneill authored and mithro committed Aug 8, 2019
    Copy the full SHA
    5b1cb82 View commit details
  30. Copy the full SHA
    4c7bfee View commit details
  31. Enable floating point

    Tisham Dhar authored and mithro committed Aug 8, 2019
    Copy the full SHA
    35110cf View commit details
  32. Copy the full SHA
    470a72b View commit details
  33. Update crt0 name and build rules to track LiteX changes. Copying crt0…

    … no longer needed.
    cr1901 authored and mithro committed Aug 8, 2019
    Copy the full SHA
    edb89e1 View commit details
  34. Copy the full SHA
    47bd489 View commit details
  35. Copy the full SHA
    13a55a9 View commit details
  36. Include files from litex.

    Files come from the following revision;
    ```
    commit 537b0e9058e6a5b77f434f46f3a56849c82064bd
    Merge: 9c6f76f1 5c83c881
    Author: enjoy-digital <florent@enjoy-digital.fr>
    Date:   Tue Sep 18 08:19:09 2018 +0200
    
        Merge pull request #101 from cr1901/icestorm-migen-pull
    
        Icestorm Improvements
    ```
    mithro committed Aug 8, 2019
    Copy the full SHA
    0a3e016 View commit details
  37. Added switch support for MimasV2.

    Added a switch object to the litex module based off the led object.
    karl-malakoff authored and mithro committed Aug 8, 2019
    Copy the full SHA
    03b18aa View commit details
  38. Fixed function header

    Fixed function header for cas_switches_in_read to match real definition.
    karl-malakoff authored and mithro committed Aug 8, 2019
    Copy the full SHA
    be0af15 View commit details
  39. Copy the full SHA
    f020cd4 View commit details
  40. Improve include guards for boards which are missing some components o…

    …f ControlAndStatus module.
    cr1901 authored and mithro committed Aug 8, 2019
    Copy the full SHA
    405b1f7 View commit details
  41. Copy the full SHA
    cebb385 View commit details
  42. Copy the full SHA
    24065ed View commit details
  43. fupy/litex.ld: Account for .srodata.* sections which may be generated…

    … by RISCV backends.
    cr1901 authored and mithro committed Aug 8, 2019
    Copy the full SHA
    6024305 View commit details
  44. Copy the full SHA
    b856c7a View commit details

Commits on Mar 13, 2020

  1. ports/fupy: Remove hw includes (use litex upstream)

    ports/fupy/hw were cached copies of the litex software includes;
    however these change from time to time, which has caused the
    CSR access includes to be out of date.  Instead of just caching
    a new version, remove the "hw" directory, and build with an
    environment that has a symlink to the litex includes.
    ewenmcneill committed Mar 13, 2020
    Copy the full SHA
    e23216b View commit details

Commits on Apr 7, 2020

  1. Merge pull request #58 from ewenmcneill/modern-litex

    ports/fupy: Remove hw includes (use litex upstream)
    ewenmcneill authored Apr 7, 2020
    Copy the full SHA
    a6b259a View commit details
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -19,10 +19,12 @@
# VIM Swap Files
######################
*.swp
*.un~

# Build directory
######################
build/
generated/

# Test failure outputs
######################
140 changes: 140 additions & 0 deletions ports/fupy/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
BUILDINC_DIRECTORY ?= .
ifeq ($(wildcard $(BUILDINC_DIRECTORY)/generated/variables.mak),)
define ERROR_MSG

$(BUILDINC_DIRECTORY)/generated/variables.mak not found.

MicroPython for LiteX requires these generated files to build. It
is important that the files match the gateware you are using and
are specific to each board / platform.

The LiteX generated files are found in build output directory
under "software/include/generated".

To allow MicroPython to find these files, you must do one of the
following;
* Set BUILDINC_DIRECTORY.
* Copy the files into a local generated directory.
* Run ./get-gateware.sh script (setting PLATFORM/TARGET value).

endef
$(error $(ERROR_MSG))
endif # no generated/variables.mak
include $(BUILDINC_DIRECTORY)/generated/variables.mak

include ../../py/mkenv.mk

# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h

# include py core make definitions
include ../../py/py.mk

CROSS_COMPILE ?= $(TRIPLE)-

INC += -I.
INC += -I../..
INC += -I../../lib/mp-readline
INC += -I$(BUILD)
INC += -I$(BUILDINC_DIRECTORY)

# Ensure assembler can also found our custom include files, for crt0
ASFLAGS += -I$(BUILDINC_DIRECTORY)

CFLAGS += $(CPUFLAGS)
CFLAGS += $(INC) -Wall -Werror -std=gnu11 -ggdb $(COPT)
CFLAGS += -Og -Wdouble-promotion -Wall -Werror

ifneq ($(DEBUG), 1)
CFLAGS += -DNDEBUG
endif

ifeq ($(COPY_TO_MAIN_RAM), 1)
LDFLAGS += -nostartfiles -T litex.ld -Wl,-Map=$@.map -Wl,--cref
else
LDFLAGS += -nostartfiles -T litex-flash.ld -Wl,-Map=$@.map -Wl,--cref
endif

LDFLAGS += -L$(BUILDINC_DIRECTORY)
LIBS = -Wl,-lc -Wl,-lm

SRC_C = \
main.c \
uart.c \
isr.c \
modmachine.c \
modlitex.c \
litex_leds.c \
litex_switches.c \
lib/utils/stdout_helpers.c \
lib/utils/interrupt_char.c \
lib/utils/pyexec.c \
lib/libc/string0.c \
lib/mp-readline/readline.c

# FIXME: Should use crt0 from newlib? However it seems to cause memory access
# at 0x0

ifeq ($(COPY_TO_MAIN_RAM), 1)
CRT0_S ?= $(LIBBASE_DIRECTORY)/crt0-$(CPU).S
CRT0_O = $(BUILD)/crt0-$(CPU)-ctr.o
CRT0FLAGS =
else ifeq ($(EXECUTE_IN_PLACE), 1)
CRT0_S ?= $(LIBBASE_DIRECTORY)/crt0-$(CPU).S
CRT0_O = $(BUILD)/crt0-$(CPU)-xip.o
CRT0FLAGS = -DEXECUTE_IN_PLACE
else
$(error You need to define one of COPY_TO_MAIN_RAM or EXECUTE_IN_PLACE to 1)
endif

# CPU-specific overrides.
ifeq ($(CPU), picorv32)
# Extract the arch-specific flags, otherwise firmware won't link.
LDFLAGS += $(filter -march=% -mabi=%, $(CPUFLAGS))
# picorv32 needs a special assembly include to compile crt0.
ASFLAGS += -I$(SOC_DIRECTORY)/software/include/base
else ifeq ($(CPU), vexriscv)
LDFLAGS += $(filter -march=% -mabi=%, $(CPUFLAGS))
endif

# No extra assembly files for now.
SRC_S =

OBJ = $(CRT0_O) $(addprefix $(BUILD)/, $(SRC_S:.S=.o)) $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))

all: $(BUILD)/firmware.bin

# List of sources for qstr extraction
SRC_QSTR += $(SRC_C) $(SRC_LIB)

# crt0 override for normal assembler rule- needed to distinguish
# whether we need to assemble a crt0 that copies a data section to RAM from
# flash, or a crt0 that assumes a bootloader does it ahead of time.
$(CRT0_O): $(CRT0_S)
$(CC) -c $(ASFLAGS) $(CFLAGS) $(CRT0FLAGS) -o $@ $<

$(BUILD)/_frozen_mpy.c: frozentest.mpy $(BUILD)/genhdr/qstrdefs.generated.h
$(ECHO) "MISC freezing bytecode"
$(Q)../tools/mpy-tool.py -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $< > $@

$(BUILD)/firmware.elf: $(OBJ)
$(ECHO) "LINK $@"
$(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
$(Q)$(SIZE) $@

$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
$(Q)$(OBJCOPY) -O binary $^ $(BUILD)/firmware.bin

# Run emulation build on a POSIX system with suitable terminal settings
run:
stty raw opost -echo
build/firmware.elf
@echo Resetting terminal...
# This sleep is useful to spot segfaults
sleep 1
reset

test: $(BUILD)/firmware.elf
$(Q)/bin/echo -e "print('hello world!', list(x+1 for x in range(10)), end='eol\\\\n')\\r\\n\\x04" | $(BUILD)/firmware.elf | tail -n2 | grep "^hello world! \\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\]eol"

include ../../py/mkrules.mk
35 changes: 35 additions & 0 deletions ports/fupy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# The minimal port

This port is intended to be a minimal MicroPython port that actually runs.
It can run under Linux (or similar) and on any STM32F4xx MCU (eg the pyboard).

## Building and running Linux version

By default the port will be built for the host machine:

$ make

To run a small test script do:

$ make run

## Building for an STM32 MCU

The Makefile has the ability to build for a Cortex-M CPU, and by default
includes some start-up code for an STM32F4xx MCU and also enables a UART
for communication. To build:

$ make CROSS=1

If you previously built the Linux version, you will need to first run
`make clean` to get rid of incompatible object files.

Building will produce the build/firmware.dfu file which can be programmed
to an MCU using:

$ make CROSS=1 deploy

This version of the build will work out-of-the-box on a pyboard (and
anything similar), and will give you a MicroPython REPL on UART1 at 9600
baud. Pin PA13 will also be driven high, and this turns on the red LED on
the pyboard.
11 changes: 11 additions & 0 deletions ports/fupy/csr-defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef CSR_DEFS__H
#define CSR_DEFS__H

#define CSR_MSTATUS_MIE 0x8

#define CSR_IRQ_MASK 0xBC0
#define CSR_IRQ_PENDING 0xFC0

#define CSR_DCACHE_INFO 0xCC0

#endif /* CSR_DEFS__H */
Binary file added ports/fupy/frozentest.mpy
Binary file not shown.
7 changes: 7 additions & 0 deletions ports/fupy/frozentest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
print('uPy')
print('a long string that is not interned')
print('a string that has unicode αβγ chars')
print(b'bytes 1234\x01')
print(123456789)
for i in range(4):
print(i)
27 changes: 27 additions & 0 deletions ports/fupy/get-gateware.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

PLATFORM="${PLATFORM:-mimasv2}"
TARGET="${TARGET:-base}"
CPU="${CPU:-lm32}"
BRANCH="${BRANCH:-master}"

GITHUB_URL=https://github.com/timvideos/HDMI2USB-firmware-prebuilt/

# Automatically figure out the latest revision
if [ "$REV" = "" ]; then
REV=$(svn ls $GITHUB_URL/trunk/archive/$BRANCH | sort | tail -n1 | sed -e's-/$--')
echo "Using revision $REV"
fi

# archive/master/v0.0.3-696-g2f815c1/minispartan6/base/lm32
BASE_DIR=archive/$BRANCH/$REV/$PLATFORM/$TARGET/$CPU

# Get the generated header files
svn export --force $GITHUB_URL/trunk/$BASE_DIR/software/include/generated | grep -v "^Exported"

# Get the flash file
#svn export --force $SVN_URL/flash.bin

# Get gateware and bios files (to allow image building)
#svn export --force $SVN_URL/gateware/top.bin gateware.bin
#svn export --force $SVN_URL/software/bios/bios.bin
144 changes: 144 additions & 0 deletions ports/fupy/irq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#ifndef __IRQ_H
#define __IRQ_H

#ifdef __cplusplus
extern "C" {
#endif

#include <system.h>

#ifdef __picorv32__
// PicoRV32 has a very limited interrupt support, implemented via custom
// instructions. It also doesn't have a global interrupt enable/disable, so
// we have to emulate it via saving and restoring a mask and using 0/~1 as a
// hardware mask.
// Due to all this somewhat low-level mess, all of the glue is implemented in
// the RiscV crt0, and this header is kept as a thin wrapper. Since interrupts
// managed by this layer, do not call interrupt instructions directly, as the
// state will go out of sync with the hardware.

// Read only.
extern unsigned int _irq_pending;
// Read only.
extern unsigned int _irq_mask;
// Read only.
extern unsigned int _irq_enabled;
extern void _irq_enable(void);
extern void _irq_disable(void);
extern void _irq_setmask(unsigned int);
#endif

static inline unsigned int irq_getie(void)
{
#if defined (__lm32__)
unsigned int ie;
__asm__ __volatile__("rcsr %0, IE" : "=r" (ie));
return ie;
#elif defined (__or1k__)
return !!(mfspr(SPR_SR) & SPR_SR_IEE);
#elif defined (__picorv32__)
return _irq_enabled != 0;
#elif defined (__vexriscv__)
return (csrr(mstatus) & CSR_MSTATUS_MIE) != 0;
#elif defined (__minerva__)
return (csrr(mstatus) & CSR_MSTATUS_MIE) != 0;
#else
#error Unsupported architecture
#endif
}

static inline void irq_setie(unsigned int ie)
{
#if defined (__lm32__)
__asm__ __volatile__("wcsr IE, %0" : : "r" (ie));
#elif defined (__or1k__)
if (ie & 0x1)
mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
else
mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_IEE);
#elif defined (__picorv32__)
if (ie & 0x1)
_irq_enable();
else
_irq_disable();
#elif defined (__vexriscv__)
if(ie) csrs(mstatus,CSR_MSTATUS_MIE); else csrc(mstatus,CSR_MSTATUS_MIE);
#elif defined (__minerva__)
if(ie) csrs(mstatus,CSR_MSTATUS_MIE); else csrc(mstatus,CSR_MSTATUS_MIE);
#else
#error Unsupported architecture
#endif
}

static inline unsigned int irq_getmask(void)
{
#if defined (__lm32__)
unsigned int mask;
__asm__ __volatile__("rcsr %0, IM" : "=r" (mask));
return mask;
#elif defined (__or1k__)
return mfspr(SPR_PICMR);
#elif defined (__picorv32__)
// PicoRV32 interrupt mask bits are high-disabled. This is the inverse of how
// LiteX sees things.
return ~_irq_mask;
#elif defined (__vexriscv__)
unsigned int mask;
asm volatile ("csrr %0, %1" : "=r"(mask) : "i"(CSR_IRQ_MASK));
return mask;
#elif defined (__minerva__)
unsigned int mask;
asm volatile ("csrr %0, %1" : "=r"(mask) : "i"(CSR_IRQ_MASK));
return mask;
#else
#error Unsupported architecture
#endif
}

static inline void irq_setmask(unsigned int mask)
{
#if defined (__lm32__)
__asm__ __volatile__("wcsr IM, %0" : : "r" (mask));
#elif defined (__or1k__)
mtspr(SPR_PICMR, mask);
#elif defined (__picorv32__)
// PicoRV32 interrupt mask bits are high-disabled. This is the inverse of how
// LiteX sees things.
_irq_setmask(~mask);
#elif defined (__vexriscv__)
asm volatile ("csrw %0, %1" :: "i"(CSR_IRQ_MASK), "r"(mask));
#elif defined (__minerva__)
asm volatile ("csrw %0, %1" :: "i"(CSR_IRQ_MASK), "r"(mask));
#else
#error Unsupported architecture
#endif
}

static inline unsigned int irq_pending(void)
{
#if defined (__lm32__)
unsigned int pending;
__asm__ __volatile__("rcsr %0, IP" : "=r" (pending));
return pending;
#elif defined (__or1k__)
return mfspr(SPR_PICSR);
#elif defined (__picorv32__)
return _irq_pending;
#elif defined (__vexriscv__)
unsigned int pending;
asm volatile ("csrr %0, %1" : "=r"(pending) : "i"(CSR_IRQ_PENDING));
return pending;
#elif defined (__minerva__)
unsigned int pending;
asm volatile ("csrr %0, %1" : "=r"(pending) : "i"(CSR_IRQ_PENDING));
return pending;
#else
#error Unsupported architecture
#endif
}

#ifdef __cplusplus
}
#endif

#endif /* __IRQ_H */
13 changes: 13 additions & 0 deletions ports/fupy/isr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <generated/csr.h>
#include <irq.h>
#include <uart.h>

void isr(void)
{
unsigned int irqs;

irqs = irq_pending() & irq_getmask();

if(irqs & (1 << UART_INTERRUPT))
uart_isr();
}
Loading