input/output for shelly seems to be working! poggers

This commit is contained in:
Aurel Feer 2022-05-25 16:18:20 +02:00
parent b892aeaeb6
commit 5773c47d49
2 changed files with 25 additions and 13 deletions

View File

@ -16,9 +16,16 @@
__attribute__((__used__)) __attribute__((__used__))
static void shelly_interrupt_handler(void * arg) { static void shelly_interrupt_handler(void * arg) {
// struct shelly_st * shelly_s = (struct shelly_st *) arg; errval_t err;
SHELLY_DEBUG("[shelly_interrupt_handler]\n"); struct shelly_st * shelly_s = (struct shelly_st *) arg;
return; // 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[]) int main(int argc, char *argv[])
@ -26,7 +33,8 @@ int main(int argc, char *argv[])
errval_t err; errval_t err;
debug_printf("welcome to shelly!\n"); 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 //afeer: map lpuart registers
struct capref cap_arg0 = { struct capref cap_arg0 = {
@ -34,7 +42,7 @@ int main(int argc, char *argv[])
.slot = 0 .slot = 0
}; };
err = paging_map_frame_attr(get_current_paging_state(), 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); cap_arg0, VREGION_FLAGS_READ_WRITE_NOCACHE);
if (err_is_fail(err)) USER_PANIC_ERR(err, "while mapping lpuart registers"); 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 .slot = 1
}; };
err = paging_map_frame_attr(get_current_paging_state(), 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); cap_arg1, VREGION_FLAGS_READ_WRITE_NOCACHE);
if (err_is_fail(err)) USER_PANIC_ERR(err, "while mapping gic registers"); if (err_is_fail(err)) USER_PANIC_ERR(err, "while mapping gic registers");
SHELLY_DEBUG("mapped gic\n"); SHELLY_DEBUG("mapped gic\n");
//afeer: init gic driver //afeer: init gic driver
struct gic_dist_s * gic_s; err = gic_dist_init(&shelly_s->gic_s, shelly_s->gic_base);
err = gic_dist_init(&gic_s, shelly_s.gic_base);
if (err_is_fail(err)) USER_PANIC_ERR(err, "couln't init gic_dist interrupts"); if (err_is_fail(err)) USER_PANIC_ERR(err, "couln't init gic_dist interrupts");
SHELLY_DEBUG("initialized gic driver\n"); SHELLY_DEBUG("initialized gic driver\n");
//afeer: init lpuart driver //afeer: init lpuart driver
struct lpuart_s * uart_s; err = lpuart_init(&shelly_s->uart_s, shelly_s->lpuart_base);
err = lpuart_init(&uart_s, shelly_s.lpuart_base);
if (err_is_fail(err)) { if (err_is_fail(err)) {
USER_PANIC_ERR(err, "couldn't init lpuart"); USER_PANIC_ERR(err, "couldn't init lpuart");
} }
@ -78,17 +84,17 @@ int main(int argc, char *argv[])
debug_printf(buf); debug_printf(buf);
struct waitset * ws = get_default_waitset(); 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"); if (err_is_fail(err)) USER_PANIC_ERR(err, "couln't setup interrupt handler");
SHELLY_DEBUG("setup interrupt handler\n"); 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"); if (err_is_fail(err)) USER_PANIC_ERR(err, "couln't enable gic interrupts");
SHELLY_DEBUG("enabled gic interrupt\n"); 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"); if (err_is_fail(err)) USER_PANIC_ERR(err, "couln't enable lpuart interrupts");
SHELLY_DEBUG("enabled lpuart interrupt\n"); SHELLY_DEBUG("enabled lpuart interrupt\n");

View File

@ -18,9 +18,15 @@
#define SHELLY_DEBUG(x, ...) ((void)0) #define SHELLY_DEBUG(x, ...) ((void)0)
#endif #endif
#include <drivers/lpuart.h>
#include <drivers/gic_dist.h>
struct shelly_st { struct shelly_st {
void * lpuart_base; // < virtual address of the lpuart device registers void * lpuart_base; // < virtual address of the lpuart device registers
void * gic_base; // < virtual address of the gic 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_ #endif // ndef SHELLY_H_