Code Monkey home page Code Monkey logo

pi4-irq-systemtimer's Introduction

Pi4 System Timer IRQ

This is a minimal baremetal code to test system timer interrupt during a main loop on raspberry Pi4 and aarch64.

Many bare metal tutorials and code examples are:

  • to complex to understand (many 32/64bit and Pi3/4 switches)
  • do polling instead of interrupt for the timer
  • uses Exceptions in a kind of bluescreen without saving registers
  • did not use System Timer; they use the clockrate depending timer of a core
  • did not explain or share a minimal example for GIC-400 (gicv2) on the Pi4

This minimum example has/is:

  • Pi4 only
  • AArch64 only
  • minimum assembler code
  • many in code comments
  • minimum code tweaks and files

What this code do:

  • hint: some firmware armstub8 code init System Timer to 1MHz before switching from EL3 to EL2
  • startup.S use only core0 (subcores are idle)
  • set 2 stacks: 0x80000 for c code, 0x40000 for exception asm/c code
  • switch from EL2 to EL1 with an valid exception vector for IRQ
  • kernel.c mask interrupts
  • init the GIC-400 to forward all interrupts to core0 with prio A0
  • init the GIC-400 core0 to react on prio lower than F0 (00 is the highest prio)
  • say GIC-400 to react on SPI 99 (= system timer comparator 3)
  • set comparator3 on system timer to an initial value
  • say system timer to make IRQ if comparator3 is reached
  • clear interrupt mask
  • init uart and send "boo"
  • no framebuffer output, just an output on UART 115200 on GPIO Pins 4 and 5
  • NOT aux mini uart, not GPIO Pin 14,15
  • running a loop and send sometimes "m" for signaling "main loop"
  • if interrupt occours, a "i" is sended
  • if interrupt is a timer interrupt a "t" is sended and comparator gets an new value

The code maybe not compatible with qemu (April 2020) or AEMv8-A Base Fixed Virtual Platform.

Compile (on linux) kernel8.img

Take a look into Makefile and get/set your noeabi gcc crosscompile toolchain. Then cross your fingers and do make.

Take a look into config.txt for additional files you need.

A Graphical Clock and Pi1

Look into the someGraphics and someGraphics_pi1 Branch. There is a cool digital graphical clock and a good comparison between Pi1 and Pi4 interrupt handling.

Links and Sources

This code is the best minimal mix from serveral different open source projects:

pi4-irq-systemtimer's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

max9004

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.