/** * Initialize threads array, put their default values * and so on */ void pok_thread_init(void) { uint32_t i; #ifdef POK_NEEDS_PARTITIONS uint32_t total_threads; uint8_t j; total_threads = 0; for (j = 0 ; j < POK_CONFIG_NB_PARTITIONS ; j++) { total_threads = total_threads + pok_partitions[j].nthreads; } #if defined (POK_NEEDS_DEBUG) || defined (POK_NEEDS_ERROR_HANDLING) if (total_threads != (POK_CONFIG_NB_THREADS - 2)) { #ifdef POK_NEEDS_DEBUG printf ("Error in configuration, bad number of threads\n"); #endif #ifdef POK_NEEDS_ERROR_HANDLING pok_kernel_error (POK_ERROR_KIND_KERNEL_CONFIG); #endif } #endif #endif pok_threads[KERNEL_THREAD].priority = pok_sched_get_priority_min(0); pok_threads[KERNEL_THREAD].state = POK_STATE_RUNNABLE; pok_threads[KERNEL_THREAD].next_activation = 0; pok_threads[IDLE_THREAD].period = 0; pok_threads[IDLE_THREAD].deadline = 0; pok_threads[IDLE_THREAD].time_capacity = 0; pok_threads[IDLE_THREAD].next_activation = 0; pok_threads[IDLE_THREAD].remaining_time_capacity = 0; pok_threads[IDLE_THREAD].wakeup_time = 0; pok_threads[IDLE_THREAD].entry = pok_arch_idle; pok_threads[IDLE_THREAD].priority = pok_sched_get_priority_min(0); pok_threads[IDLE_THREAD].state = POK_STATE_RUNNABLE; pok_threads[IDLE_THREAD].sp = pok_context_create (IDLE_THREAD, IDLE_STACK_SIZE, (uint32_t)pok_arch_idle); for (i = 0; i < POK_CONFIG_NB_THREADS; ++i) { pok_threads[i].period = 0; pok_threads[i].deadline = 0; pok_threads[i].time_capacity = 0; pok_threads[i].remaining_time_capacity = 0; pok_threads[i].next_activation = 0; pok_threads[i].wakeup_time = 0; pok_threads[i].state = POK_STATE_STOPPED; } }
/** * Init the array of lockobjects */ pok_ret_t pok_lockobj_init () { #if POK_CONFIG_NB_LOCKOBJECTS > 0 // i.e. defined (POK_NEEDS_LOCKOBJECTS) uint8_t i; #ifdef POK_NEEDS_PARTITIONS #ifdef POK_NEEDS_ERROR_HANDLING uint32_t total_lockobjects; total_lockobjects = 0; for ( i = 0 ; i < POK_CONFIG_NB_PARTITIONS ; i++) { total_lockobjects = total_lockobjects + pok_partitions[i].nlockobjs; } if (total_lockobjects != POK_CONFIG_NB_LOCKOBJECTS) { pok_kernel_error (POK_ERROR_KIND_KERNEL_CONFIG); } #endif // POK_NEEDS_ERROR_HANDLING #endif // POK_NEEDS_PARTITIONS for ( i = 0 ; i < POK_CONFIG_NB_LOCKOBJECTS ; i++) { // pok_partitions_lockobjs[i].spin = 0; #ifdef POK_NEEDS_SCHED_O1_SPLIT /* the bitmask is init with all 0s (event is not locked) */ pok_partitions_lockobjs[i].is_locked = 0; #else pok_partitions_lockobjs[i].is_locked = FALSE; #endif pok_partitions_lockobjs[i].initialized = FALSE; } #endif // POK_CONFIG_NB_LOCKOBJECTS > 0 return POK_ERRNO_OK; }
/** * \brief Init scheduling service */ void pok_sched_init (void) { #ifdef POK_NEEDS_PARTITIONS #if defined (POK_NEEDS_ERROR_HANDLING) || defined (POK_NEEDS_DEBUG) /* * We check that the total time of time frame * corresponds to the sum of each slot */ uint64_t total_time; uint8_t slot; total_time = 0; for (slot = 0 ; slot < POK_CONFIG_SCHEDULING_NBSLOTS ; slot++) { total_time = total_time + pok_sched_slots[slot]; } if (total_time != POK_CONFIG_SCHEDULING_MAJOR_FRAME) { #ifdef POK_NEEDS_DEBUG printf ("[DEBUG]\n ERROR: Major frame is not compliant with all time slots\n"); #endif #ifdef POK_NEEDS_ERROR_HANDLING pok_kernel_error (POK_ERROR_KIND_KERNEL_CONFIG); #endif } #endif /* POK_NEEDS_ERROR_HANDLING) || defined (POK_NEEDS_DEBUG) */ #endif /* POK_NEEDS_PARTITIONS */ pok_sched_current_slot = 0; /* POK_CONFIG_SCHEDULING_MAJOR_FRAME = sum of all scheduling slots */ pok_sched_next_major_frame = POK_CONFIG_SCHEDULING_MAJOR_FRAME; pok_sched_next_deadline = pok_sched_slots[0]; // start to execute the first partition pok_current_partition = pok_sched_slots_allocation[0]; #ifdef POK_NEEDS_SCHED_O1 uint32_t i; for(i=0; i<POK_CONFIG_NB_THREADS; i++) pok_thread_ids_to_pos_map[i]=i; // *************************** ASYNCH EVENTS QUEUES **************************************** // // adjust initial slot and major frame values to work with interval timer scheduling (start-up) pok_sched_current_slot--; pok_sched_next_major_frame++; uint8_t part=0; uint8_t index=0; uint8_t index_low=0; uint8_t counter; while (part < POK_CONFIG_NB_PARTITIONS) { index = pok_asynch_events[part]; //init pointers of queue elements for (counter = index_low; counter < index_low + index; counter++) { if (counter -1 >= index_low) asynch_queue[counter].previous = &(asynch_queue[counter-1]); else asynch_queue[counter].previous = POK_NULL; if (counter +1 < index) asynch_queue[counter].next = &(asynch_queue[counter+1]); else asynch_queue[counter].next = POK_NULL; } if (index > 0) { pok_partitions[part].head_asynch_queue = POK_NULL; pok_partitions[part].head_asynch_empty = &(asynch_queue[index_low]); pok_partitions[part].head_asynch_temporary = POK_NULL; } #ifdef POK_NEEDS_DEBUG_O1 printf("[DEBUG_O1]\t QUEUE for partition %d starts from index %d\n", part, index_low); print_queue(pok_partitions[part].head_asynch_empty); #endif index_low += index; part++; } #endif }