1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup ClassicTasks |
---|
7 | * |
---|
8 | * @brief RTEMS Task Create |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) |
---|
13 | * |
---|
14 | * Redistribution and use in source and binary forms, with or without |
---|
15 | * modification, are permitted provided that the following conditions |
---|
16 | * are met: |
---|
17 | * 1. Redistributions of source code must retain the above copyright |
---|
18 | * notice, this list of conditions and the following disclaimer. |
---|
19 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
20 | * notice, this list of conditions and the following disclaimer in the |
---|
21 | * documentation and/or other materials provided with the distribution. |
---|
22 | * |
---|
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
33 | * POSSIBILITY OF SUCH DAMAGE. |
---|
34 | */ |
---|
35 | |
---|
36 | #ifdef HAVE_CONFIG_H |
---|
37 | #include "config.h" |
---|
38 | #endif |
---|
39 | |
---|
40 | #include <rtems/rtems/tasksimpl.h> |
---|
41 | #include <rtems/score/stackimpl.h> |
---|
42 | |
---|
43 | #include <string.h> |
---|
44 | |
---|
45 | static rtems_status_code _RTEMS_tasks_Allocate_and_prepare_stack( |
---|
46 | Thread_Configuration *thread_config, |
---|
47 | const rtems_task_config *config |
---|
48 | ) |
---|
49 | { |
---|
50 | size_t size; |
---|
51 | |
---|
52 | thread_config->stack_free = _Stack_Free; |
---|
53 | size = _Stack_Ensure_minimum( config->storage_size ); |
---|
54 | size = _Stack_Extend_size( size, thread_config->is_fp ); |
---|
55 | thread_config->stack_size = size; |
---|
56 | thread_config->stack_area = _Stack_Allocate( size ); |
---|
57 | |
---|
58 | if ( thread_config->stack_area == NULL ) { |
---|
59 | return RTEMS_UNSATISFIED; |
---|
60 | } |
---|
61 | |
---|
62 | return RTEMS_SUCCESSFUL; |
---|
63 | } |
---|
64 | |
---|
65 | rtems_status_code rtems_task_create( |
---|
66 | rtems_name name, |
---|
67 | rtems_task_priority initial_priority, |
---|
68 | size_t stack_size, |
---|
69 | rtems_mode initial_modes, |
---|
70 | rtems_attribute attribute_set, |
---|
71 | rtems_id *id |
---|
72 | ) |
---|
73 | { |
---|
74 | rtems_task_config config; |
---|
75 | |
---|
76 | memset( &config, 0, sizeof( config ) ); |
---|
77 | config.name = name; |
---|
78 | config.initial_priority = initial_priority; |
---|
79 | config.storage_size = stack_size; |
---|
80 | config.initial_modes = initial_modes; |
---|
81 | config.attributes = attribute_set; |
---|
82 | |
---|
83 | return _RTEMS_tasks_Create( |
---|
84 | &config, |
---|
85 | id, |
---|
86 | _RTEMS_tasks_Allocate_and_prepare_stack |
---|
87 | ); |
---|
88 | } |
---|