diff options
author | Christian Cunningham <cc@localhost> | 2022-03-24 22:55:13 -0700 |
---|---|---|
committer | Christian Cunningham <cc@localhost> | 2022-03-24 22:55:13 -0700 |
commit | 75ca654c2a3a4cce24459a381311c259ce7ce8a3 (patch) | |
tree | 2549dd19a9bd1484f8ca48246d4bf4b40b937f42 /usr | |
parent | c5b6f1611ea1f4685ef02f65fc0362f9c22c344f (diff) |
GPIO Interrupts
Diffstat (limited to 'usr')
-rw-r--r-- | usr/main.c | 28 | ||||
-rw-r--r-- | usr/timed.c | 29 |
2 files changed, 40 insertions, 17 deletions
@@ -1,4 +1,3 @@ -#include <cpu.h> #include <globals.h> #include <graphics/lfb.h> #include <symbols.h> @@ -35,23 +34,19 @@ static struct UartInfo UART_INFO = { .priority = 2, }; -static unsigned long simulated = 0; - -void producer(void) -{ - draw_string(0, 15, "Producing..."); - sys1(SYS_SEMAPHORE_V, &simulated); - draw_string(0, 15, "Produced! "); -} +static struct GPIOInfo gpinfo = { + .pin = (1<<16), + .priority = 0, +}; -void consumer(void) +void gptest(void) { - add_thread(producer, 0, 4); - while (1) { - draw_string(0, 16, "Consuming..."); - sys1(SYS_SEMAPHORE_P, &simulated); - draw_string(0, 16, "Consumed! "); - } + static unsigned long count = 0; + unsigned long gplev0 = *GPLEV0; + static char str[14]; + draw_hex32(0, 30, gplev0); + char* start = ulong_to_string(count++, str); + draw_string(0, 31, start); } void main(void) @@ -61,6 +56,7 @@ void main(void) 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); + subscribe_irq(GPIO_BANK_1_IRQ, gptest, &gpinfo); add_thread(loop, 0, 8); add_thread(consumer, 0, 3); } diff --git a/usr/timed.c b/usr/timed.c index 9247acf..fd4f923 100644 --- a/usr/timed.c +++ b/usr/timed.c @@ -1,4 +1,5 @@ #define USR_TIMED_C +#include <cpu.h> #include <globals.h> #include <graphics/lfb.h> #include <symbols.h> @@ -6,6 +7,25 @@ #include <usr/timed.h> #include <util/time.h> +static unsigned long simulated = 0; + +void producer(void) +{ + draw_string(0, 15, "Producing..."); + sys1(SYS_SEMAPHORE_V, &simulated); + draw_string(0, 15, "Produced! "); +} + +void consumer(void) +{ + add_thread(producer, 0, 4); + while (1) { + draw_string(0, 16, "Consuming..."); + sys1(SYS_SEMAPHORE_P, &simulated); + draw_string(0, 16, "Consumed! "); + } +} + void loop(void) { static char str[13]; @@ -22,7 +42,14 @@ void loop(void) draw_string(0, 12, " "); draw_string(0, 12, start); previous++; - wait_msec(3000); + //unsigned long gplev0 = *(volatile unsigned long*)GPLEV0; + //static unsigned long count = 0; + //draw_hex32(0, 13, gplev0); + //if (gplev0 & (1 << 16)) { + // draw_hex32(0, 17, count++); + // add_thread(producer, 0, 4); + //} + wait_msec(30000); add_thread(loop, 0, 3); } |