diff options
author | Christian Cunningham <cc@localhost> | 2022-03-24 18:52:56 -0700 |
---|---|---|
committer | Christian Cunningham <cc@localhost> | 2022-03-24 18:52:56 -0700 |
commit | 7753da66d7d72f441dadd76f357fd5ceb50e7c8f (patch) | |
tree | c79cee644108ecb65952eff2104127a19e72d0c4 /usr | |
parent | 78493b1d441ef888910cf958a16f260bc3c1a7bd (diff) |
Modularize Userspace
Diffstat (limited to 'usr')
-rw-r--r-- | usr/main.c | 90 | ||||
-rw-r--r-- | usr/string.c | 19 | ||||
-rw-r--r-- | usr/timed.c | 43 | ||||
-rw-r--r-- | usr/uart.c | 22 |
4 files changed, 101 insertions, 73 deletions
@@ -1,79 +1,9 @@ -#include <graphics/lfb.h> #include <globals.h> #include <symbols.h> #include <sys/schedule.h> -#include <util/time.h> - -void loop(void); - -void handle_data(unsigned char data) -{ - // Newline Case - if (data == 0x0D) { - // Backspace Case - } else if (data == 0x08 || data == 0x7F) { - } else if (data == 0x61) { - add_thread(uart_scheduler, 0, 2); - } else if (data == 0x62) { - //add_thread(test_entry, 0, 2); - } - // Draw it on the screen - { - draw_chex32(0, 9, data, 0xAA00FF); - } -} - -char* ulong_to_string(unsigned long value, char* data) -{ - unsigned long t = value; - unsigned long c; - char* dptr = data + 10; - for (int i = 0; i <= 10; i++) { - c = t%10; - *dptr = 0x30 + (c&0xF); - t /= 10; - if (t==0) - break; - dptr -= 1; - if (i == 5) { - *dptr = '.'; - dptr -= 1; - } - } - return dptr; -} - -void loop(void) -{ - static char str[13]; - static unsigned long previous = 0; - char* start; - unsigned long current = *(volatile unsigned long*)SYS_TIMER_CHI; - start = ulong_to_string(current, str); - draw_string(0, 10, " "); - draw_string(0, 10, start); - start = ulong_to_string(previous, str); - draw_string(0, 11, " "); - draw_string(0, 11, start); - start = ulong_to_string(nextpid, str); - draw_string(0, 12, " "); - draw_string(0, 12, start); - previous++; - wait_msec(3000); - add_thread(loop, 0, 3); -} - -void loopt(void) -{ - static char str[13]; - static char cnt = 18; - draw_string(0, 14, ulong_to_string(*(volatile unsigned long*)SYS_TIMER_CHI, str)); - cnt--; - if (cnt == 2) - unsubscribe_irq(SYS_TIMER_1_IRQ); - if (cnt == 0) - unsubscribe_irq(SYS_TIMER_0_IRQ); -} +#include <usr/string.h> +#include <usr/timed.h> +#include <usr/uart.h> static struct SysTimerInfo stime_0 = { .tick_rate = 5000000, @@ -82,6 +12,12 @@ static struct SysTimerInfo stime_0 = { }; static struct SysTimerInfo stime_1 = { + .tick_rate = 700000, + .priority = 0, + .arg = 0, +}; + +static struct SysTimerInfo stime_2 = { .tick_rate = 300000, .priority = 0, .arg = 0, @@ -91,10 +27,18 @@ static struct UartInfo UART_INFO = { .priority = 2, }; +static struct SysTimerInfo stime_3 = { + .tick_rate = 70000, + .priority = 0, + .arg = 0, +}; + void main(void) { subscribe_irq(UART_IRQ, handle_data, &UART_INFO); subscribe_irq(SYS_TIMER_0_IRQ, loopt, &stime_0); subscribe_irq(SYS_TIMER_1_IRQ, loopt, &stime_1); + subscribe_irq(SYS_TIMER_2_IRQ, loopt, &stime_2); + subscribe_irq(SYS_TIMER_3_IRQ, loopt, &stime_3); add_thread(loop, 0, 0); } diff --git a/usr/string.c b/usr/string.c new file mode 100644 index 0000000..8c94900 --- /dev/null +++ b/usr/string.c @@ -0,0 +1,19 @@ +char* ulong_to_string(unsigned long value, char* data) +{ + unsigned long t = value; + unsigned long c; + char* dptr = data + 10; + for (int i = 0; i <= 10; i++) { + c = t%10; + *dptr = 0x30 + (c&0xF); + t /= 10; + if (t==0) + break; + dptr -= 1; + if (i == 5) { + *dptr = '.'; + dptr -= 1; + } + } + return dptr; +} diff --git a/usr/timed.c b/usr/timed.c new file mode 100644 index 0000000..9247acf --- /dev/null +++ b/usr/timed.c @@ -0,0 +1,43 @@ +#define USR_TIMED_C +#include <globals.h> +#include <graphics/lfb.h> +#include <symbols.h> +#include <usr/string.h> +#include <usr/timed.h> +#include <util/time.h> + +void loop(void) +{ + static char str[13]; + static unsigned long previous = 0; + char* start; + unsigned long current = *(volatile unsigned long*)SYS_TIMER_CHI; + start = ulong_to_string(current, str); + draw_string(0, 10, " "); + draw_string(0, 10, start); + start = ulong_to_string(previous, str); + draw_string(0, 11, " "); + draw_string(0, 11, start); + start = ulong_to_string(nextpid, str); + draw_string(0, 12, " "); + draw_string(0, 12, start); + previous++; + wait_msec(3000); + add_thread(loop, 0, 3); +} + +void loopt(void) +{ + static char str[13]; + static char cnt = 18; + draw_string(0, 14, ulong_to_string(*(volatile unsigned long*)SYS_TIMER_CHI, str)); + cnt--; + if (cnt == 6) + unsubscribe_irq(SYS_TIMER_3_IRQ); + if (cnt == 4) + unsubscribe_irq(SYS_TIMER_2_IRQ); + else if (cnt == 2) + unsubscribe_irq(SYS_TIMER_1_IRQ); + else if (cnt == 0) + unsubscribe_irq(SYS_TIMER_0_IRQ); +} diff --git a/usr/uart.c b/usr/uart.c new file mode 100644 index 0000000..8782a74 --- /dev/null +++ b/usr/uart.c @@ -0,0 +1,22 @@ +#define USR_UART_C +#include <graphics/lfb.h> +#include <sys/schedule.h> +#include <usr/string.h> +#include <usr/uart.h> + +void handle_data(unsigned char data) +{ + // Newline Case + if (data == 0x0D) { + // Backspace Case + } else if (data == 0x08 || data == 0x7F) { + } else if (data == 0x61) { + add_thread(uart_scheduler, 0, 2); + } else if (data == 0x62) { + //add_thread(test_entry, 0, 2); + } + // Draw it on the screen + { + draw_chex32(0, 9, data, 0xAA00FF); + } +} |