1 // -----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2007 by the FRESCOR consortium:
4 // Universidad de Cantabria, SPAIN
5 // University of York, UK
6 // Scuola Superiore Sant'Anna, ITALY
7 // Kaiserslautern University, GERMANY
8 // Univ. Politecnica Valencia, SPAIN
9 // Czech Technical University in Prague, CZECH REPUBLIC
11 // Thales Communication S.A. FRANCE
12 // Visual Tools S.A. SPAIN
13 // Rapita Systems Ltd UK
16 // See http://www.frescor.org
18 // The FRESCOR project (FP6/2005/IST/5-034026) is funded
19 // in part by the European Union Sixth Framework Programme
20 // The European Union is not liable of any use that may be
23 // All rights reserved.
25 // Redistribution and use in source and binary forms, with or
26 // without modification, are permitted provided that the
27 // following conditions are met:
29 // * Redistributions of source code must retain the above
30 // copyright notice, this list of conditions and the
31 // following disclaimer.
32 // * Redistributions in binary form must reproduce the above
33 // copyright notice, this list of conditions and the
34 // following disclaimer in the documentation and/or other
35 // materials provided with the distribution.
36 // * Neither the name of FRESCOR nor the names of its
37 // contributors may be used to endorse or promote products
38 // derived from this software without specific prior
39 // written permission.
41 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42 // CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
46 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
47 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
48 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
49 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
50 // BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
51 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
53 // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54 // POSSIBILITY OF SUCH DAMAGE.
55 // -----------------------------------------------------------------------
57 //========================================================================================
58 // ******** ******* ******** ** ** ******** ****** ******** **********
59 // **///// /**////** **////// /** /** **///// /** ** **////// /** /**
60 // ** /** /** /** /** /** ** /** ** /** /** /**
61 // ******* /******* /********* /********** ******* /** ** /********* /**********
62 // **//// /**///** ////////** /**//////** **//// /** ** ////////** /**//////**
63 // ** /** //** /** /** /** ** /** ** /** /** /**
64 // ** /** //** ******** /** /** ** /** ** ******** /** /**
65 // // // // //////// // // // /******/ //////// // //
67 // FRSH(FRescor ScHeduler), pronounced "fresh" FOSA(Frescor Oper System Adaptation layer)
68 //========================================================================================
77 * @defgroup frshfosa FRSH FOSA public interfaces
79 * FOSA is an OS adaption layer that encapsulates all POSIX types and
80 * functions into neutral names so that FRSH can compile and be used in
81 * non-POSIX operating systems such as OSE.
83 * It is divided in two parts:
84 * - FRSH_FOSA: Types visibles to the application via FRSH_API
85 * (thread, signal, mutexes).
86 * - FOSA: Types and functions only used within FRSH.
88 * The former reside in the FRSH subversion directory and the latter
89 * have their own. They need to be separated because the application
90 * must not see FOSA itself.
92 * For simplicity, we have chosen to hide the operation function on
93 * signals and mutexes with the assumption that a direct mapping
94 * exists for frsh_signal_t, frsh_signal_info_t and frsh_mutext_t in
97 * Since there are some parts which are platform dependent a define
98 * has been introduced for each platform. Currently the supported
105 * This module contains the FOSA part exposed by the FRSH_API and
106 * visible for the application.
108 * On the other hand, there was another file in the API which was also
109 * OS-dependent: frsh_os_compatibility.h. However this dependency
110 * relates more to the implementation of FRSH and therefore it has
111 * been moved to the src directory. It may be integrated in FOSA
112 * during the implementation.
118 //////////////////////////////// OSE ////////////////////////////////////
121 #include "frsh_fosa.h"
122 #include "frsh_configuration_parameters.h"
126 /*************************
128 *************************/
131 * frsh_thread_attr_init()
133 * Initialize a thread attributes object
135 * This function initializes the object pointed to by attr to all
136 * the default values defined by FRSH
138 * @return 0 if successful; otherwise it returns \n
139 * FOSA_ENOMEM: insufficient memory exists to initialize the thread
142 int frsh_thread_attr_init(frsh_thread_attr_t *attr){
143 // The lowest(!) OSE priority is used.
144 attr->prio = FRSH_HIGHEST_THREAD_PRIORITY;
145 attr->stack_size = 1000;
146 attr->app_scheduled = false;
147 attr->appsched_param = NULL;
148 attr->appsched_param_size = 0;
154 * frsh_thread_attr_destroy()
156 * Destroy a thread attributes object
158 * This function is used to destroy the thread attributes object,
159 * pointed to by attr, and deallocate any system resources allocated for it
163 int frsh_thread_attr_destroy(frsh_thread_attr_t *attr) {
164 if(attr->appsched_param != NULL)
165 heap_free_shared(attr->appsched_param);
166 frsh_thread_attr_init(attr);
171 * frsh_thread_attr_set_stacksize()
173 * Set the thread minimum stack size in a thread attributes object
175 * This function sets the minimum stack size of the thread attributes
176 * object attr to the value given by stacksize, in bytes. This
177 * function has no runtime effect on the stack size, except when the
178 * attributes object is used to create a thread, when it will be
179 * created with the specified minimum stack size
181 * @return 0 if successful, or the following error code:
182 * FOSA_EINVAL: the specified stacksize value is not supported in
183 * this implementation
185 int frsh_thread_attr_set_stacksize
186 (frsh_thread_attr_t *attr, size_t stacksize)
188 //How to check if valid stack size? Possible?.........................
189 //if (??) return FOSA_EINVAL;
191 attr->stack_size = (unsigned long) stacksize;
196 * frsh_thread_attr_get_stacksize()
198 * Get the thread minimum stack size from a thread attributes object
200 * This function sets the variable pointed to by stacksize to the
201 * minimum stack size stored in the thread attributes object attr.
205 int frsh_thread_attr_get_stacksize
206 (const frsh_thread_attr_t *attr, size_t *stacksize)
208 *stacksize = attr->stack_size;
215 //////////////////////////// End of OSE /////////////////////////////////