static void blinkf() { res_type_t type = res_compose (RES_DEV, RES_GPIO, 0, 0); int prd; int on = 1; int off = 0; char msg[4]; uint32_t volatile ra = 0;// mmio_read (GPFSEL4); ra = 1 << 3; //mmio_write (GPFSEL4, ra); *((volatile uint32_t*) GPFSEL2) = ra; ra = 1 << 21; GET_RES (prd, type, 0, 0); while (1) { ssleep (0x60000); *((volatile uint32_t*) GPSET0) = ra; //mmio_write (GPSET1, ra); SEND(&on, 4, 5); ssleep (0x60000); //mmio_write (GPCLR1, ra); *((volatile uint32_t*) GPCLR0) = ra; SEND(&off, 4, 5); } GIVE_RES (prd, type, 0, 0); }
int hardware_init() { int i, ret; res_unit** table = res_table_get(); if (table == NULL) return -EINVAL; res_unit* processor = (res_unit*) kcalloc (1, sizeof(res_unit)); if (processor == NULL) return -ENOMEM; res_unit* gpio = (res_unit*) kcalloc (GPIO_NUM, sizeof(res_unit)); if (gpio == NULL) { kfree(processor); return -ENOMEM; } processor->pid = 0; processor->tb = (ftable*) &proc_ftable; processor->type = res_compose(RES_CPU, 0, 0, 0); res_add(processor); for (i = 0; i < GPIO_NUM; ++i) { *((int*) gpio[i].data) = i; gpio[i].tb = (ftable*) &gpio_ftable; gpio[i].type = res_compose(RES_DEV, RES_GPIO, 0, 0); res_add(gpio + i); } for (i = 0; table[i] != NULL; ++i) { ret = table[i]->tb->res_init(table[i]); if (ret != 0) { goto fail; } } return 0; fail: kfree(processor); kfree(gpio); return ret; }
void terminal_func() { char* str = (char*) kcalloc (256, sizeof (char)); int retv = -1; res_type_t type = res_compose (RES_CPU, 0, 0, 0); int prd; while(1) { GET_RES (prd, type, 3, R_WAITFROM); //dump_rbuffer(GET_KERNEL_THREAD()->buffer, msg_d); while (try_receive (str) >= 0) kprint ("%s", str); GIVE_RES (prd, type, 3, R_SENDTO); } }
void thread_2_func() { char* str = (char*) kcalloc (256, sizeof (char)); res_type_t type = res_compose (RES_CPU, 0, 0, 0); int prd; GET_RES (prd, type, 0, 0); while(1) { GET_RES (prd, type, 2, R_WAITFROM); //dump_rbuffer(GET_KERNEL_THREAD()->buffer, msg_d); SEND_STR ("Hello #2\r\n", strlen ("Hello #2\r\n") + 1); kprint ("%d\r\n", prd); GIVE_RES (prd, type, 2, R_SENDTO); } }