diff --git a/.gitignore b/.gitignore index b2b7881..7c35034 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ out/* main.hex +initrd.img diff --git a/include/lcd.h b/include/lcd.h index 0962e08..441d463 100644 --- a/include/lcd.h +++ b/include/lcd.h @@ -3,6 +3,9 @@ #include +/** + * Direct access + */ void lcd_init(void); void lcd_puts(const char *s); @@ -11,4 +14,10 @@ void lcd_puth(int h); void lcd_putb(uint8_t b); void lcd_clear(void); +/** + * Buffered/async access + */ +void lcd_handler(void); +void lcd_put(const char *s); + #endif // LCD_H_ diff --git a/src/lcd.c b/src/lcd.c index ca1c1a6..1c29d54 100644 --- a/src/lcd.c +++ b/src/lcd.c @@ -1,6 +1,7 @@ #include #include #include +#include #define LCD_D0 GPIO_PORT(A, 0) #define LCD_D1 GPIO_PORT(A, 1) @@ -115,3 +116,38 @@ void lcd_init(void) delay(5); lcd_clear(); } + +/** + * Task code + */ + +static int bufpos = 0; +static char buf[64]; +void lcd_clearbuf(void) +{ + bufpos = 0; + for (int i = 0; i < 32; i++) + buf[i] = 0; +} + +void lcd_put(const char *s) +{ + int len = strlen(s); + int off = (bufpos + len < 64) ? len : 64 - bufpos; + strncpy(buf + bufpos, s, off); + bufpos += off; +} + +void lcd_handler(void) +{ + lcd_init(); + lcd_clearbuf(); + + while (1) { + if (buf[0] != '\0') { + lcd_puts(buf); + lcd_clearbuf(); + } + delay(100); + } +} diff --git a/src/main.c b/src/main.c index e71e712..d974ebc 100644 --- a/src/main.c +++ b/src/main.c @@ -45,12 +45,20 @@ void kmain(void) { asm("cpsie i"); - lcd_init(); + task_start(lcd_handler, 128); + delay(200); char *s = initrd_getfile("test.txt"); - lcd_puts(s); + const char *t = "Yoyoyo"; - while (1) - delay(100); + asm("mov r0, %0; svc 2" :: "r" (s)); + asm("mov r0, %0; svc 2" :: "r" (t)); + + while (1) { + gpio_dout(GPIOA, 5, 1); + delay(500); + gpio_dout(GPIOA, 5, 0); + delay(500); + } } diff --git a/src/stm32l4xx_it.c b/src/stm32l4xx_it.c index 2aac023..368fed5 100644 --- a/src/stm32l4xx_it.c +++ b/src/stm32l4xx_it.c @@ -4,31 +4,27 @@ void NMI_Handler(void) {} void HardFault_Handler(void) { - GPIOA->BSRR |= (1 << 5) | (1 << 6); + GPIOA->BSRR |= (1 << 5); while (1); } void MemManage_Handler(void) { - GPIOA->BSRR |= (1 << 5) | (1 << 6); + GPIOA->BSRR |= (1 << 5); while (1); } void BusFault_Handler(void) { - GPIOA->BSRR |= (1 << 5) | (1 << 6); + GPIOA->BSRR |= (1 << 5); while (1); } void UsageFault_Handler(void) { - GPIOA->BSRR |= (1 << 5) | (1 << 6); + GPIOA->BSRR |= (1 << 5); while (1); } -void SVC_Handler(void) { - -} - void DebugMon_Handler(void) {} diff --git a/src/svc.c b/src/svc.c new file mode 100644 index 0000000..507855d --- /dev/null +++ b/src/svc.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +void SVC_Handler(void) { + uint32_t *stack; + uint8_t index; + + asm("\ + mrs r0, psp; \ + mov %0, r0; \ + ldr r0, [r0, #24]; \ + ldr %1, [r0, #-2]; \ + " : "=r" (stack), "=r" (index)); + + gpio_mode(GPIOA, 6, OUTPUT); + + switch (index) { + case 1: + gpio_dout(GPIOA, 6, 1); + for (int i = 0; i < 100000; i++) + asm(""); + gpio_dout(GPIOA, 6, 0); + break; + case 2: + lcd_put((char *)stack[0]); + break; + default: + break; + } +} +