diff --git a/include/metalsvm/tasks_types.h b/include/metalsvm/tasks_types.h index 1d9c4c27..49f7a612 100644 --- a/include/metalsvm/tasks_types.h +++ b/include/metalsvm/tasks_types.h @@ -33,6 +33,7 @@ extern "C" { #define TASK_RUNNING 2 #define TASK_BLOCKED 3 #define TASK_FINISHED 4 +#define TASK_IDLE 5 typedef void* (STDCALL *entry_point_t)(void*); typedef unsigned int tid_t; @@ -47,7 +48,6 @@ typedef struct { unsigned char blocked_tasks[MAX_TASKS]; void* return_value; unsigned char status; - unsigned char idle; } task_t; #ifdef __cplusplus diff --git a/kernel/main.c b/kernel/main.c index 1428984e..6e98509c 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -32,7 +32,10 @@ #include #include #include +#include +#include #include +//#include #endif static sem_t consuming, producing; @@ -116,6 +119,15 @@ void* STDCALL join_test(void* arg) #ifdef USE_LWIP void* STDCALL lwip_task(void* arg) { + struct netif netif; + struct ip_addr ipaddr; + struct ip_addr netmask; + struct ip_addr gw; + err_t err; + + sleep(10); + kputs("LWIP task is started\n"); + stats_init(); /* Clears the structure where runtime statistics are gathered */ sys_init(); mem_init(); /* Initializes the dynamic memory heap defined by MEM_SIZE. */ @@ -126,10 +138,26 @@ void* STDCALL lwip_task(void* arg) udp_init(); /* Clears the UDP PCB list */ tcp_init(); /* Clears the TCP PCB list and clears some internal TCP timers. */ - kputs("LWIP task is started\n"); + /* Bring up the network interface */ + //if (!netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcnetif_init, ethernet_input)) { + // kputs("Unable to add network interface\n"); + // return NULL; + //} - while(1) { - } + /* This will bring the interface up and set its IP address when it can acquire one. */ + //err = dhcp_start(&netif); + //if (err != ERR_OK) { + // kprintf("Unable to get IP via DHCP: %s\n", lwip_strerr(err)); + // return NULL; + //} + + //if (netif_is_up(&netif)) { + // kputs("Network interface is not up\n"); + // return NULL; + //} + + //while(1) { + //} return 0; } @@ -175,7 +203,7 @@ int main(void) create_kernel_task(&id1, foo, "Hello from foo1\n", 8192); create_kernel_task(&id2, join_test, NULL, 0); create_kernel_task(&id3, producer, NULL, 0); - current_task->idle = 1; + current_task->status = TASK_IDLE; schedule(); while(1) { diff --git a/kernel/tasks.c b/kernel/tasks.c index 5f5d02fd..32dc09ac 100644 --- a/kernel/tasks.c +++ b/kernel/tasks.c @@ -36,7 +36,6 @@ int multitasking_init(void) { task_table[0].stack = NULL; task_table[0].stack_size = 8192; task_table[0].status = TASK_RUNNING; - task_table[0].idle = 0; current_task = task_table; return 0; } @@ -122,7 +121,6 @@ int create_kernel_task(tid_t* id, entry_point_t ep, void* arg, size_t stack_size memset(task_table[i].blocked_tasks, 0x00, sizeof(unsigned char)*MAX_TASKS); task_table[i].return_value = NULL; task_table[i].status = TASK_READY; - task_table[i].idle = 0; if (id) *id = i; @@ -145,7 +143,7 @@ int join_kernel_task(tid_t id, void** result) * idle tasks are not allowed to wait for another task * they should always run... */ - if (BUILTIN_EXPECT(current_task->idle, 0)) + if (BUILTIN_EXPECT(current_task->status, TASK_IDLE)) goto join_out; /* a task is not able to wait for itself */ @@ -215,7 +213,7 @@ task_t* get_new_task(void) for(i=1; i <= MAX_TASKS; i++) { new_id = (current_task->id + i) % MAX_TASKS; - if (!task_table[new_id].idle && task_table[new_id].status == TASK_READY) { + if (task_table[new_id].status == TASK_READY) { if (current_task->status == TASK_RUNNING) current_task->status = TASK_READY; task_table[new_id].status = TASK_RUNNING; @@ -225,7 +223,7 @@ task_t* get_new_task(void) } } - if (!(current_task->idle) && (current_task->status == TASK_RUNNING)) { + if (current_task->status == TASK_RUNNING) { ret = current_task; goto get_task_out; } @@ -234,8 +232,6 @@ task_t* get_new_task(void) * we switch to the idle task (id=0), if the current task terminates * and no other is ready */ - task_table[0].status = TASK_RUNNING; - ret = task_table+0; get_task_out: