SVC calls

master
Clyne Sullivan 7 years ago
parent e5ae7f10f3
commit 67243b6d98

1
.gitignore vendored

@ -1,2 +1,3 @@
out/* out/*
main.hex main.hex
initrd.img

@ -3,6 +3,9 @@
#include <stdint.h> #include <stdint.h>
/**
* Direct access
*/
void lcd_init(void); void lcd_init(void);
void lcd_puts(const char *s); void lcd_puts(const char *s);
@ -11,4 +14,10 @@ void lcd_puth(int h);
void lcd_putb(uint8_t b); void lcd_putb(uint8_t b);
void lcd_clear(void); void lcd_clear(void);
/**
* Buffered/async access
*/
void lcd_handler(void);
void lcd_put(const char *s);
#endif // LCD_H_ #endif // LCD_H_

@ -1,6 +1,7 @@
#include <lcd.h> #include <lcd.h>
#include <clock.h> #include <clock.h>
#include <gpio.h> #include <gpio.h>
#include <string.h>
#define LCD_D0 GPIO_PORT(A, 0) #define LCD_D0 GPIO_PORT(A, 0)
#define LCD_D1 GPIO_PORT(A, 1) #define LCD_D1 GPIO_PORT(A, 1)
@ -115,3 +116,38 @@ void lcd_init(void)
delay(5); delay(5);
lcd_clear(); 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"); asm("cpsie i");
lcd_init(); task_start(lcd_handler, 128);
delay(200);
char *s = initrd_getfile("test.txt"); char *s = initrd_getfile("test.txt");
lcd_puts(s); const char *t = "Yoyoyo";
while (1) asm("mov r0, %0; svc 2" :: "r" (s));
delay(100); asm("mov r0, %0; svc 2" :: "r" (t));
while (1) {
gpio_dout(GPIOA, 5, 1);
delay(500);
gpio_dout(GPIOA, 5, 0);
delay(500);
}
} }

@ -4,31 +4,27 @@ void NMI_Handler(void) {}
void HardFault_Handler(void) void HardFault_Handler(void)
{ {
GPIOA->BSRR |= (1 << 5) | (1 << 6); GPIOA->BSRR |= (1 << 5);
while (1); while (1);
} }
void MemManage_Handler(void) void MemManage_Handler(void)
{ {
GPIOA->BSRR |= (1 << 5) | (1 << 6); GPIOA->BSRR |= (1 << 5);
while (1); while (1);
} }
void BusFault_Handler(void) void BusFault_Handler(void)
{ {
GPIOA->BSRR |= (1 << 5) | (1 << 6); GPIOA->BSRR |= (1 << 5);
while (1); while (1);
} }
void UsageFault_Handler(void) void UsageFault_Handler(void)
{ {
GPIOA->BSRR |= (1 << 5) | (1 << 6); GPIOA->BSRR |= (1 << 5);
while (1); while (1);
} }
void SVC_Handler(void) {
}
void DebugMon_Handler(void) {} void DebugMon_Handler(void) {}

@ -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;
}
}
Loading…
Cancel
Save