diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2018-01-06 13:38:34 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2018-01-06 13:38:34 -0500 |
commit | 67243b6d986179da11fc1d364606d8e1653688ff (patch) | |
tree | deb5387a2d01b6a5863f1349750fa9b97d77ed75 | |
parent | e5ae7f10f3e144f4a08ee7a66b4105a5aa86e6e7 (diff) |
SVC calls
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | include/lcd.h | 9 | ||||
-rw-r--r-- | src/lcd.c | 36 | ||||
-rw-r--r-- | src/main.c | 16 | ||||
-rw-r--r-- | src/stm32l4xx_it.c | 12 | ||||
-rw-r--r-- | src/svc.c | 33 |
6 files changed, 95 insertions, 12 deletions
@@ -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 <stdint.h> +/** + * 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_ @@ -1,6 +1,7 @@ #include <lcd.h> #include <clock.h> #include <gpio.h> +#include <string.h> #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); + } +} @@ -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 <stdint.h> +#include <gpio.h> +#include <clock.h> +#include <lcd.h> + +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; + } +} + |