POK(kernelpart)
thread.h
Go to the documentation of this file.
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Thu Jan 15 23:34:13 2009
15  */
16 
17 
18 #ifndef __POK_THREAD_H__
19 #define __POK_THREAD_H__
20 
21 #ifdef POK_NEEDS_THREADS
22 
23 #include <types.h>
24 #include <errno.h>
25 #include <core/sched.h>
26 
27 
28 /*
29  * In POK, we add a kernel thread and an idle thread. The kernel
30  * thread is used to execute kernel code while the idle thread
31  * is used to save processor resources.
32  */
33 
34 #define KERNEL_THREAD POK_CONFIG_NB_THREADS -2
35 #define IDLE_THREAD POK_CONFIG_NB_THREADS -1
36 
37 #define POK_THREAD_DEFAULT_TIME_CAPACITY 10
38 
39 /*
40 #define KERNEL_THREAD POK_CONFIG_NB_THREADS
41 #define IDLE_THREAD POK_CONFIG_NB_THREADS + 1
42 */
43 
44 #define POK_THREAD_MAX_PRIORITY 200
45 
46 
47 /*
48  * IDLE_STACK_SIZE is the stack size of the idle thread
49  * DEFAULT_STACK_SIZE if the stack size of regulard threads
50  */
51 #define IDLE_STACK_SIZE 1024
52 #define DEFAULT_STACK_SIZE 4096
53 
54 #ifndef POK_USER_STACK_SIZE
55 #define POK_USER_STACK_SIZE 8096
56 #endif
57 
58 typedef struct
59 {
60  uint8_t priority;
61  uint64_t period;
62  uint64_t deadline;
63  uint64_t time_capacity;
64  uint64_t remaining_time_capacity;
65  uint64_t next_activation;
66  pok_state_t state;
67  uint64_t end_time;
68  uint64_t wakeup_time;
69 #ifdef POK_NEEDS_SCHED_HFPPS
70  uint64_t payback;
71 #endif /* POK_NEEDS_SCHED_HFPPS */
72  void *entry;
73  uint8_t partition;
74  uint32_t sp;
75  uint32_t init_stack_addr;
76  /* stack pointer
77  * FIXME: this is platform-dependent code, we have to handle that ! */
78 } pok_thread_t;
79 
80 typedef struct
81 {
82  uint8_t priority; /* Priority is from 0 to 255 */
83  void* entry; /* entrypoint of the thread */
84  uint64_t period;
85  uint64_t deadline;
86  uint64_t time_capacity;
87  uint32_t stack_size;
88  pok_state_t state;
89 } pok_thread_attr_t;
90 /*
91  * Attributes given to create a thread
92  */
93 
94 void pok_thread_init (void);
95 pok_ret_t pok_thread_create (uint8_t* thread_id, const pok_thread_attr_t* attr);
96 pok_ret_t pok_thread_sleep (const uint32_t ms);
97 pok_ret_t pok_thread_sleep_until (const uint32_t ms);
98 pok_ret_t pok_thread_suspend (void);
99 void pok_thread_start (void (*entry)(), unsigned int id);
100 pok_ret_t pok_thread_suspend (void);
101 pok_ret_t pok_thread_restart (const uint32_t tid);
102 pok_ret_t pok_thread_get_status (const uint32_t id, pok_thread_attr_t *attr);
103 
104 #ifdef POK_NEEDS_PARTITIONS
105 pok_ret_t pok_partition_thread_create (uint32_t* thread_id,
106  const pok_thread_attr_t* attr,
107  const uint8_t partition_id);
108 #endif
109 
110 extern pok_thread_t pok_threads[POK_CONFIG_NB_THREADS];
111 
112 #define POK_CURRENT_THREAD pok_threads[POK_SCHED_CURRENT_THREAD]
113 
114 #endif /* __POK_NEEDS_THREADS */
115 
116 #endif /* __POK_THREAD_H__ */