#include #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 /* * Function which delays for a bit. */ void delay(void); void main(void); uint32_t collatz(uint32_t n) { uint32_t c = 0; while (n > 1) { if (n % 2 == 0) { n /= 2; } else { n = n * 3 + 1; } c++; } return c; } void blink_n(int n) { uint32_t bit = 1 << 8; while (n > 0) { GPIO_PORT.out.set(GPIO_PORT_A, OFF, 8); delay(); GPIO_PORT.out.set(GPIO_PORT_A, ON, 8); delay(); --n; } } void delay(void) { 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. */ 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 (;;) { 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(); } } IRQ(systick) { collatz(5); } IRQ(exc) {} IRQ(nmi) {}