27 #ifdef POK_NEEDS_PARTITIONS
49 uint8_t pok_partitions_index = 0;
57 void pok_partition_setup_scheduler (
const uint8_t pid)
59 #ifdef POK_CONFIG_PARTITIONS_SCHEDULER
60 switch (((
pok_sched_t[])POK_CONFIG_PARTITIONS_SCHEDULER)[pid])
62 #ifdef POK_NEEDS_SCHED_RMS
64 pok_partitions[pid].sched_func = &pok_sched_part_rms;
73 pok_partitions[pid].sched_func = &pok_sched_part_rr;
77 pok_partitions[pid].sched_func = &pok_sched_part_rr;
88 #ifdef POK_NEEDS_ERROR_HANDLING
89 void pok_partition_reinit (
const uint8_t pid)
95 pok_partition_setup_scheduler (pid);
97 pok_partitions[pid].thread_index = 0;
98 pok_partitions[pid].current_thread = pok_partitions[pid].thread_index_low;
99 pok_partitions[pid].prev_current_thread = IDLE_THREAD;
101 #ifdef POK_NEEDS_ERROR_HANDLING
102 pok_partitions[pid].thread_error = 0;
103 pok_partitions[pid].error_status.failed_thread = 0;
104 pok_partitions[pid].error_status.failed_addr = 0;
105 pok_partitions[pid].error_status.error_kind = POK_ERROR_KIND_INVALID;
106 pok_partitions[pid].error_status.msg_size = 0;
111 pok_partitions[pid].thread_main_entry = tmp;
113 pok_partition_setup_main_thread (pid);
120 void pok_partition_setup_main_thread (
const uint8_t pid)
123 pok_thread_attr_t attr;
125 attr.entry = (
uint32_t*)pok_partitions[pid].thread_main_entry;
129 attr.time_capacity = 0;
131 pok_partition_thread_create (&main_thread, &attr, pid);
132 pok_partitions[pid].thread_main = main_thread;
147 #ifdef POK_CONFIG_PARTITIONS_LOADADDR
149 = POK_CONFIG_PROGRAM_LOADADDR;
151 #ifdef POK_NEEDS_LOCKOBJECTS
158 #ifndef POK_CONFIG_PARTITIONS_LOADADDR
161 uint32_t base_addr = program_loadaddr[i];
166 pok_partitions[i].base_addr = base_addr;
167 pok_partitions[i].size =
size;
170 #ifdef POK_NEEDS_COVERAGE_INFOS
172 printf (
"[XCOV] Partition %d loaded at addr virt=|%x|, phys=|%x|\n", i, base_vaddr, base_addr);
175 pok_partition_setup_scheduler (i);
179 pok_partitions[i].base_vaddr = base_vaddr;
182 pok_partitions[i].thread_index_low = threads_index;
183 pok_partitions[i].nthreads = ((
uint32_t[]) POK_CONFIG_PARTITIONS_NTHREADS) [i];
185 #ifdef POK_NEEDS_ERROR_HANDLING
186 if (pok_partitions[i].nthreads <= 1)
188 pok_partition_error (i, POK_ERROR_KIND_PARTITION_CONFIGURATION);
192 #ifdef POK_CONFIG_PARTITIONS_SCHEDULER
193 pok_partitions[i].sched = ((
pok_sched_t[]) POK_CONFIG_PARTITIONS_SCHEDULER) [i];
196 pok_partitions[i].thread_index_high = pok_partitions[i].thread_index_low + ((
uint32_t[]) POK_CONFIG_PARTITIONS_NTHREADS) [i];
197 pok_partitions[i].activation = 0;
198 pok_partitions[i].period = 0;
199 pok_partitions[i].thread_index = 0;
200 pok_partitions[i].thread_main = 0;
201 pok_partitions[i].current_thread = IDLE_THREAD;
202 pok_partitions[i].prev_current_thread = IDLE_THREAD;
204 #ifdef POK_NEEDS_SCHED_HFPPS
205 pok_partitions[i].payback = 0;
208 threads_index = threads_index + pok_partitions[i].nthreads;
211 pok_partitions[i].mode = POK_PARTITION_MODE_INIT_WARM;
213 #ifdef POK_NEEDS_LOCKOBJECTS
214 pok_partitions[i].lockobj_index_low = lockobj_index;
215 pok_partitions[i].lockobj_index_high = lockobj_index + ((
uint8_t[]) POK_CONFIG_PARTITIONS_NLOCKOBJECTS[i]);
216 pok_partitions[i].nlockobjs = ((
uint8_t[]) POK_CONFIG_PARTITIONS_NLOCKOBJECTS[i]);
217 lockobj_index = lockobj_index + pok_partitions[i].nlockobjs;
221 #ifdef POK_NEEDS_ERROR_HANDLING
222 pok_partitions[i].thread_error = 0;
223 pok_partitions[i].error_status.failed_thread = 0;
224 pok_partitions[i].error_status.failed_addr = 0;
225 pok_partitions[i].error_status.error_kind = POK_ERROR_KIND_INVALID;
226 pok_partitions[i].error_status.msg_size = 0;
233 pok_partitions[i].thread_main_entry = program_entry;
235 pok_partitions[i].lock_level = 0;
236 pok_partitions[i].start_condition = NORMAL_START;
238 #ifdef POK_NEEDS_INSTRUMENTATION
239 pok_instrumentation_partition_archi (i);
242 pok_partition_setup_main_thread (i);
254 pok_ret_t pok_partition_set_mode (
const uint8_t pid,
const pok_partition_mode_t mode)
258 case POK_PARTITION_MODE_NORMAL:
264 if (pok_partitions[pid].mode == POK_PARTITION_MODE_IDLE)
269 if (POK_SCHED_CURRENT_THREAD != POK_CURRENT_PARTITION.thread_main)
274 pok_partitions[pid].mode = mode;
276 pok_sched_stop_thread (pok_partitions[pid].thread_main);
291 #ifdef POK_NEEDS_ERROR_HANDLING
292 case POK_PARTITION_MODE_STOPPED:
297 if ((POK_CURRENT_PARTITION.thread_error == 0 ) ||
298 (POK_SCHED_CURRENT_THREAD != POK_CURRENT_PARTITION.thread_error))
303 pok_partitions[pid].mode = mode;
307 case POK_PARTITION_MODE_INIT_WARM:
308 case POK_PARTITION_MODE_INIT_COLD:
309 if (pok_partitions[pid].mode == POK_PARTITION_MODE_INIT_COLD && mode == POK_PARTITION_MODE_INIT_WARM)
317 if ((POK_CURRENT_PARTITION.thread_error == 0 ) ||
318 (POK_SCHED_CURRENT_THREAD != POK_CURRENT_PARTITION.thread_error))
328 pok_partitions[pid].mode = mode;
330 pok_partition_reinit (pid);
347 pok_ret_t pok_partition_set_mode_current (
const pok_partition_mode_t mode)
349 #ifdef POK_NEEDS_ERROR_HANDLING
350 if ((POK_SCHED_CURRENT_THREAD != POK_CURRENT_PARTITION.thread_main) &&
351 (POK_SCHED_CURRENT_THREAD != POK_CURRENT_PARTITION.thread_error))
353 if (POK_SCHED_CURRENT_THREAD != POK_CURRENT_PARTITION.thread_main)
365 return (pok_partition_set_mode (POK_SCHED_CURRENT_PARTITION, mode));
373 *
id = POK_SCHED_CURRENT_PARTITION;
379 *period = POK_CURRENT_PARTITION.period;
385 *duration = pok_sched_slots[POK_SCHED_CURRENT_PARTITION];
389 pok_ret_t pok_current_partition_get_operating_mode (pok_partition_mode_t *op_mode)
391 *op_mode = POK_CURRENT_PARTITION.mode;
397 *lock_level = POK_CURRENT_PARTITION.lock_level;
401 pok_ret_t pok_current_partition_get_start_condition (pok_start_condition_t *start_condition)
403 *start_condition = POK_CURRENT_PARTITION.start_condition;
407 #ifdef POK_NEEDS_ERROR_HANDLING
417 if (POK_SCHED_CURRENT_THREAD != POK_CURRENT_PARTITION.thread_error)
426 pok_sched_stop_thread (tid + POK_CURRENT_PARTITION.thread_index_low);
436 if (POK_SCHED_CURRENT_THREAD != POK_CURRENT_PARTITION.thread_error)
445 pok_thread_restart (tid + POK_CURRENT_PARTITION.thread_index_low);