diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/init.c | 6 | ||||
-rw-r--r-- | src/main.c | 19 | ||||
-rw-r--r-- | src/systick.c | 34 |
3 files changed, 57 insertions, 2 deletions
@@ -1,12 +1,17 @@ #include <stddef.h> #include <stdint.h> +#include <stdio.h> +#include "ch573/systick.h" #include "clock.h" #include "io.h" #include "isr_vector.h" void on_reset(void); +#define SYSTICK_I CH573_SYSTICK__SYSTICK_T_INTF +#define SYSTICK ch573_systick__systick + void __attribute__((weak, interrupt, __section__(".isr_vector.routines"))) default_irq_handler(void) { @@ -111,6 +116,7 @@ static __attribute((__section__(".sinit.1"))) void start(void) init_data_segments(); /* Set the mtvec to the isr_vector. */ set_mtvec(&isr_vector); + enable_interrupts(); /* Initialize stdout. */ init_uart1_for_stdout(); @@ -1,10 +1,10 @@ #include <math.h> #include <stdint.h> #include <stdio.h> -#include "string.h" #include "byte_math.h" #include "ch573/gpio.h" +#include "ch573/pfic.h" #include "ch573/pwr.h" #include "ch573/uart.h" #include "clock.h" @@ -13,8 +13,12 @@ #include "string.h" #include "sysled.h" #include "system.h" +#include "systick.h" #include "ws2812b.h" +#define PFIC_I CH573_PFIC__PFIC_T_INTF +#define PFIC ch573_pfic__pfic + #define GPIO_PORT_A ch573_gpio__gpio_port_a #define GPIO_PORT_B ch573_gpio__gpio_port_b #define GPIO_PORT CH573_GPIO__GPIO_PORT_T_INTF @@ -203,14 +207,25 @@ int main(void) { char buf[N_LEDS * TOTAL_BYTES_PER_LED]; + PFIC_I.vector_table_control.set(PFIC, 1); + PFIC->interrupt_priority_threshold = 0x10; + PFIC->interrupt_enable |= IRQ_SysTick; + + printf( + "PFIC enable status 1: %08x\n", + (uint32_t)(PFIC->interrupt_enable_status)); + set_system_clock_60Mhz(); + + set_systick(250000); + enable_sysled(); enable_spi(); size_t n = sizeof(buf); struct ws2812b_buf ws_buf; make_wsb2812b(&ws_buf, buf, n); - ws_buf.byte_order = BYTE_ORDER_RGB; + ws_buf.byte_order = BYTE_ORDER_GRB; rgb_t color; uint32_t time = 0; diff --git a/src/systick.c b/src/systick.c new file mode 100644 index 0000000..506f6df --- /dev/null +++ b/src/systick.c @@ -0,0 +1,34 @@ +#include "systick.h" + +#include <stdio.h> + +#include "ch573/systick.h" +#include "isr_vector.h" + +#define SYSTICK_I CH573_SYSTICK__SYSTICK_T_INTF +#define SYSTICK ch573_systick__systick + +void set_systick(uint64_t systick) +{ + SYSTICK_I.reload.set(SYSTICK, systick); + SYSTICK_I.cfg.st_reload.set(SYSTICK, 1); + SYSTICK_I.cfg.interrupt_enable.set(SYSTICK, 1); + + SYSTICK_I.cfg.enabled.set(SYSTICK, ENABLED); +} + +uint64_t get_systick() +{ + return ((uint64_t)SYSTICK_I.count_high.get(SYSTICK) << 32) | + SYSTICK_I.count_low.get(SYSTICK); +} + +int systick_interrupt() +{ + return SYSTICK_I.counter_interrupt_flag.get(SYSTICK); +} + +IRQ(systick) +{ + SYSTICK_I.counter_interrupt_flag.set(SYSTICK, 0); +} |