1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
32 33 34
35
36 package ti.sysbios.rts.iar;
37
38 import xdc.runtime.Error;
39 import xdc.runtime.Assert;
40
41 import ti.sysbios.knl.Task;
42
43 /*!
44 * ======== MultithreadSupport ========
45 * This Multithread support module uses Hook Functions, Hook Context
46 * and an overloaded implementation of the library's lock and thread
47 * local storage access functions to make C runtime library calls re-entrant.
48 *
49 * Multithread support will be enabled when IAR linker option "--threaded_lib"
50 * is passed as the target's linker options prefix. This can be done in one
51 * of the following ways:
52 * - When building an application in IAR Embedded Workbench, under
53 * Project -> Options -> General Options -> Library Configuration,
54 * check the "Enable thread support in Library" box.
55 * - When building an application through makefile using configuro, pass
56 * the linker options on configuro command line using "--linkOptions"
57 * option.
58 * - When building an application through XDC build system using config.bld,
59 * pass the linker options through the XDC target linkOpts.prefix in
60 * config.bld.
61 *
62 * Note: Calling C runtime functions from SWI and HWI threads
63 * is not supported and will generate an exception if
64 * multithread support is enabled.
65 *
66 */
67
68 module MultithreadSupport
69 {
70 /*!
71 * ======== enableMultithreadSupport ========
72 * Enable/Disable multithread support
73 *
74 * @_nodoc
75 */
76 config Bool enableMultithreadSupport = false;
77
78 /*!
79 * ======== A_badThreadType ========
80 * Asserted in MultithreadSupport_perThreadAccess()
81 *
82 * @_nodoc
83 */
84 config Assert.Id A_badThreadType = {
85 msg: "A_badThreadType: Cannot call a C runtime library API from a Hwi or Swi thread."
86 };
87
88 /*!
89 * ======== A_badLockRelease ========
90 * Asserted in MultithreadSupport_releaseLock()
91 *
92 * @_nodoc
93 */
94 config Assert.Id A_badLockRelease = {
95 msg: "A_badLockRelease: Trying to release a lock not owned by this thread."
96 };
97
98 internal:
99
100 /*!
101 * ======== perThreadAccess ========
102 * Returns a pointer the symbol in the current task's TLS memory
103 *
104 * Calculates the symbol address based on the input symbol pointer
105 * in main task's TLS memory and returns the address to the symbol
106 * in the current task's TLS memory.
107 *
108 * @param(symbp) Pointer to symbol in the main task's TLS memory.
109 *
110 */
111 Void *perThreadAccess(Void *symbp);
112
113 /*!
114 * ======== getTlsPtr ========
115 * Returns a pointer to the current task's TLS memory
116 */
117 Void *getTlsPtr();
118
119 /*!
120 * ======== initLock ========
121 * Initializes a system lock
122 *
123 * Creates a system lock and assigns it to the pointer passed as input.
124 *
125 * @param(ptr) Pointer to a lock struct pointer.
126 *
127 */
128 Void initLock(Void **ptr);
129
130 /*!
131 * ======== destroyLock ========
132 * Destroy a system lock
133 *
134 * Deletes the semaphore in the lock and frees the lock.
135 *
136 * @param(ptr) Pointer to a lock struct pointer.
137 *
138 */
139 Void destroyLock(Void **ptr);
140
141 /*!
142 * ======== acquireLock ========
143 * Acquire a system lock
144 *
145 * Blocks the task if lock is not available. Supports nested calls.
146 *
147 * @param(ptr) Pointer to a lock struct pointer.
148 *
149 */
150 Void acquireLock(Void **ptr);
151
152 /*!
153 * ======== releaseLock ========
154 * Release a system lock
155 *
156 * Releases the lock to other waiting task if any. Supports nested calls.
157 *
158 * @param(ptr) Pointer to a lock struct pointer.
159 *
160 */
161 Void releaseLock(Void **ptr);
162
163 /*!
164 * ======== taskCreateHook ========
165 * Create task hook function
166 *
167 * It is used to create and initialize all task's hook context.
168 *
169 * @param(task) Handle of the Task to initialize.
170 * @param(eb) Error block.
171 *
172 */
173 Void taskCreateHook(Task.Handle task, Error.Block *eb);
174
175 /*!
176 * ======== taskDeleteHook ========
177 * Delete hook function used to remove the task's hook context.
178 *
179 * @param(task) Handle of the Task to delete.
180 *
181 */
182 Void taskDeleteHook(Task.Handle task);
183
184 /*!
185 * ======== taskRegHook ========
186 * Registration function for the module's hook
187 *
188 * @param(id) The id of the hook for use in load.
189 *
190 */
191 Void taskRegHook(Int id);
192
193
194
195 struct Module_State {
196 Int taskHId;
197 };
198 }