| 174 | } |
| 175 | |
| 176 | static rt_err_t _thread_init(struct rt_thread *thread, |
| 177 | const char *name, |
| 178 | void (*entry)(void *parameter), |
| 179 | void *parameter, |
| 180 | void *stack_start, |
| 181 | rt_uint32_t stack_size, |
| 182 | rt_uint8_t priority, |
| 183 | rt_uint32_t tick) |
| 184 | { |
| 185 | RT_UNUSED(name); |
| 186 | |
| 187 | rt_sched_thread_init_ctx(thread, tick, priority); |
| 188 | |
| 189 | #ifdef RT_USING_MEM_PROTECTION |
| 190 | thread->mem_regions = RT_NULL; |
| 191 | #endif |
| 192 | |
| 193 | #ifdef RT_USING_SMART |
| 194 | thread->wakeup_handle.func = RT_NULL; |
| 195 | #endif |
| 196 | |
| 197 | thread->entry = (void *)entry; |
| 198 | thread->parameter = parameter; |
| 199 | |
| 200 | /* stack init */ |
| 201 | thread->stack_addr = stack_start; |
| 202 | thread->stack_size = stack_size; |
| 203 | |
| 204 | /* init thread stack */ |
| 205 | rt_memset(thread->stack_addr, '#', thread->stack_size); |
| 206 | #ifdef RT_USING_HW_STACK_GUARD |
| 207 | rt_hw_stack_guard_init(thread); |
| 208 | #endif |
| 209 | #ifdef ARCH_CPU_STACK_GROWS_UPWARD |
| 210 | thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter, |
| 211 | (void *)((char *)thread->stack_addr), |
| 212 | (void *)_thread_exit); |
| 213 | #else |
| 214 | thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter, |
| 215 | (rt_uint8_t *)((char *)thread->stack_addr + thread->stack_size - sizeof(rt_ubase_t)), |
| 216 | (void *)_thread_exit); |
| 217 | #endif /* ARCH_CPU_STACK_GROWS_UPWARD */ |
| 218 | |
| 219 | #ifdef RT_USING_MUTEX |
| 220 | rt_list_init(&thread->taken_object_list); |
| 221 | thread->pending_object = RT_NULL; |
| 222 | #endif |
| 223 | |
| 224 | #ifdef RT_USING_EVENT |
| 225 | thread->event_set = 0; |
| 226 | thread->event_info = 0; |
| 227 | #endif /* RT_USING_EVENT */ |
| 228 | |
| 229 | /* error and flags */ |
| 230 | thread->error = RT_EOK; |
| 231 | |
| 232 | /* lock init */ |
| 233 | #ifdef RT_USING_SMP |
no test coverage detected