diff --git a/usr/shelly/shelly.c b/usr/shelly/shelly.c index 9922ce4..e97872f 100644 --- a/usr/shelly/shelly.c +++ b/usr/shelly/shelly.c @@ -16,9 +16,16 @@ __attribute__((__used__)) static void shelly_interrupt_handler(void * arg) { - // struct shelly_st * shelly_s = (struct shelly_st *) arg; - SHELLY_DEBUG("[shelly_interrupt_handler]\n"); - return; + errval_t err; + struct shelly_st * shelly_s = (struct shelly_st *) arg; + // SHELLY_DEBUG("[shelly_interrupt_handler]\n"); + + char input_char; + err = lpuart_getchar(shelly_s->uart_s, &input_char); + if (err_is_fail(err)) USER_PANIC_ERR(err, "while trying to get character"); + + err = lpuart_putchar(shelly_s->uart_s, input_char); + if (err_is_fail(err)) USER_PANIC_ERR(err, "while trying to put character"); } int main(int argc, char *argv[]) @@ -26,7 +33,8 @@ int main(int argc, char *argv[]) errval_t err; debug_printf("welcome to shelly!\n"); - struct shelly_st shelly_s; + struct shelly_st * shelly_s = calloc(sizeof(struct shelly_st), 1); + assert(shelly_s); //afeer: map lpuart registers struct capref cap_arg0 = { @@ -34,7 +42,7 @@ int main(int argc, char *argv[]) .slot = 0 }; err = paging_map_frame_attr(get_current_paging_state(), - (void **) &shelly_s.lpuart_base, IMX8X_UART_SIZE, + (void **) &shelly_s->lpuart_base, IMX8X_UART_SIZE, cap_arg0, VREGION_FLAGS_READ_WRITE_NOCACHE); if (err_is_fail(err)) USER_PANIC_ERR(err, "while mapping lpuart registers"); @@ -46,22 +54,20 @@ int main(int argc, char *argv[]) .slot = 1 }; err = paging_map_frame_attr(get_current_paging_state(), - (void**) &shelly_s.gic_base, IMX8X_GIC_DIST_SIZE, + (void**) &shelly_s->gic_base, IMX8X_GIC_DIST_SIZE, cap_arg1, VREGION_FLAGS_READ_WRITE_NOCACHE); if (err_is_fail(err)) USER_PANIC_ERR(err, "while mapping gic registers"); SHELLY_DEBUG("mapped gic\n"); //afeer: init gic driver - struct gic_dist_s * gic_s; - err = gic_dist_init(&gic_s, shelly_s.gic_base); + err = gic_dist_init(&shelly_s->gic_s, shelly_s->gic_base); if (err_is_fail(err)) USER_PANIC_ERR(err, "couln't init gic_dist interrupts"); SHELLY_DEBUG("initialized gic driver\n"); //afeer: init lpuart driver - struct lpuart_s * uart_s; - err = lpuart_init(&uart_s, shelly_s.lpuart_base); + err = lpuart_init(&shelly_s->uart_s, shelly_s->lpuart_base); if (err_is_fail(err)) { USER_PANIC_ERR(err, "couldn't init lpuart"); } @@ -78,17 +84,17 @@ int main(int argc, char *argv[]) debug_printf(buf); struct waitset * ws = get_default_waitset(); - err = inthandler_setup(inter_cap, ws, MKCLOSURE(shelly_interrupt_handler, (void *) &shelly_s)); + err = inthandler_setup(inter_cap, ws, MKCLOSURE(shelly_interrupt_handler, (void *) shelly_s)); if (err_is_fail(err)) USER_PANIC_ERR(err, "couln't setup interrupt handler"); SHELLY_DEBUG("setup interrupt handler\n"); - err = gic_dist_enable_interrupt(gic_s, IMX8X_UART3_INT, 0b11111111, 0); + err = gic_dist_enable_interrupt(shelly_s->gic_s, IMX8X_UART3_INT, 0b11111111, 0); if (err_is_fail(err)) USER_PANIC_ERR(err, "couln't enable gic interrupts"); SHELLY_DEBUG("enabled gic interrupt\n"); - err = lpuart_enable_interrupt(uart_s); + err = lpuart_enable_interrupt(shelly_s->uart_s); if (err_is_fail(err)) USER_PANIC_ERR(err, "couln't enable lpuart interrupts"); SHELLY_DEBUG("enabled lpuart interrupt\n"); diff --git a/usr/shelly/shelly.h b/usr/shelly/shelly.h index 8ea68fc..33497fa 100644 --- a/usr/shelly/shelly.h +++ b/usr/shelly/shelly.h @@ -18,9 +18,15 @@ #define SHELLY_DEBUG(x, ...) ((void)0) #endif +#include +#include + struct shelly_st { void * lpuart_base; // < virtual address of the lpuart device registers void * gic_base; // < virtual address of the gic device registers + + struct lpuart_s * uart_s; // < state of the uart driver + struct gic_dist_s * gic_s; // < state of the gic driver }; #endif // ndef SHELLY_H_