diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-11-14 02:19:09 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-11-14 02:19:09 -0700 |
commit | d1ebd3bd806f4b4e1f74703f682ca64994c79a28 (patch) | |
tree | 248a6a35a3b7c5232bcdafe6a6bfbe556be8ad0f /src/blinky.c | |
parent | c9402e5a5d67ef877fa7f5f67c07a794574ded35 (diff) | |
download | ch573-d1ebd3bd806f4b4e1f74703f682ca64994c79a28.tar.gz ch573-d1ebd3bd806f4b4e1f74703f682ca64994c79a28.tar.bz2 ch573-d1ebd3bd806f4b4e1f74703f682ca64994c79a28.zip |
Get a good, basic framework for ISRs and properly handle the data sections.
Diffstat (limited to 'src/blinky.c')
-rw-r--r-- | src/blinky.c | 74 |
1 files changed, 20 insertions, 54 deletions
diff --git a/src/blinky.c b/src/blinky.c index d8a29bd..9f89238 100644 --- a/src/blinky.c +++ b/src/blinky.c @@ -1,50 +1,19 @@ #include <stdint.h> +#include "isr_vector.h" #include "ch573/gpio.h" #define GPIO_PORT_A ch573_gpio__gpio_port_a #define GPIO_PORT CH573_GPIO__GPIO_PORT_T_INTF -static void start(void); - -/* - * Function (or really pointer to code) for the reset interrupt handler. - */ -void on_reset(void); - /* * Function which delays for a bit. */ void delay(void); -/* Type def to a void function to make things mor ereadable. */ -typedef void (*isr_routine)(void); - -/** The ISR Vector structure. This is linked to starting at address 0. */ -// __attribute((__section__(".isr_vector"))) volatile struct { -// // What NULL points to. nothing useful. -// uint32_t reserved__; -// // Called when the device boots or reset is pressed. -// isr_routine reset_cb; -// isr_routine nmi_cb; -// isr_routine exc_cb; -// } isr_vectors = {.reset_cb = on_reset}; - -/* - * The reset callback.This has to be a naked function because the stack pointer - * may not be initialized!!. - */ -__attribute((naked)) void on_reset(void) -{ - // Set up the stack pointer to point to the end of SRAM. - asm volatile( - "li sp,0x20008000\n" - "addi sp,sp,-4\n" - "jalr %0\n" - "spin:\n" - "j spin\n" - : - : "r"(start)); +void main(void); +IRQ(irq_on_systick) { + main(); } uint32_t collatz(uint32_t n) @@ -77,38 +46,35 @@ void blink_n(int n) void delay(void) { - for (volatile uint32_t i = 0; i < 10000; ++i); + for (volatile uint32_t i = 0; i < 10000; ++i) { + asm volatile(""); + } } +volatile uint32_t deadbeef = 0xdeadbeef; + +// Memory-mapped address of the data values in flash. +extern uint32_t DATA_VALUES_IN_FLASH; + +// Where the data is located in sram. +extern uint32_t DATA_SEGMENT_START; +extern uint32_t DATA_SEGMENT_STOP; + /* Main routine. This is called on_reset once everything else has been set up. */ -static void start(void) +void main(void) { GPIO_PORT.dir.set(GPIO_PORT_A, DIR_OUT, 8); GPIO_PORT.pd_drv.set(GPIO_PORT_A, PD_DRV_OPEN_DRAIN, 8); for (;;) { - GPIO_PORT.out.set(GPIO_PORT_A, ON, 8); + if (deadbeef == 0xdeadbeef) { + GPIO_PORT.out.set(GPIO_PORT_A, ON, 8); + } delay(); delay(); delay(); GPIO_PORT.out.set(GPIO_PORT_A, OFF, 8); delay(); } - - // uint32_t i; - // for (i = 1;; ++i) { - // uint32_t c = collatz(i); - // blink_n(c); - - // delay(); - // delay(); - // delay(); - // delay(); - // delay(); - // delay(); - // delay(); - // delay(); - // delay(); - // } } |