]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - src_ose/frsh_fosa.c
AQuoSA: Avoid redefinition of preprocessor symbols if they were defined earlier
[frescor/fosa.git] / src_ose / frsh_fosa.c
1 // -----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2007 by the FRESCOR consortium:
3 //
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
10 //    ENEA                                   SWEDEN
11 //    Thales Communication S.A.              FRANCE
12 //    Visual Tools S.A.                      SPAIN
13 //    Rapita Systems Ltd                     UK
14 //    Evidence                               ITALY
15 //
16 //    See http://www.frescor.org
17 //
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
21 //        made of this code.
22 //
23 //  All rights reserved.
24 //
25 //  Redistribution and use in source and binary forms, with or 
26 //  without modification, are permitted provided that the 
27 //  following conditions are met:
28 //
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.
40 //
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 // -----------------------------------------------------------------------
56 // frsh_fosa.h
57 //========================================================================================
58 //  ******** *******    ********  **      **    ********  ******    ********  **********
59 //  **///// /**////**  **//////  /**     /**    **///// /**    **  **//////  /**     /**
60 //  **      /**   /** /**        /**     /**    **      /**    ** /**        /**     /**
61 //  ******* /*******  /********* /**********    ******* /**    ** /********* /**********
62 //  **////  /**///**  ////////** /**//////**    **////  /**    ** ////////** /**//////**
63 //  **      /**  //**        /** /**     /**    **      /**    **        /** /**     /**
64 //  **      /**   //** ********  /**     /**    **      /**    **  ********  /**     /**
65 //  //       //     // ////////   //      //    //       /******/  ////////   //      // 
66 //
67 // FRSH(FRescor ScHeduler), pronounced "fresh" FOSA(Frescor Oper System Adaptation layer)
68 //========================================================================================
69
70
71 /**
72  * @file frsh_fosa.c
73  **/
74
75
76 /**
77  * @defgroup frshfosa FRSH FOSA public interfaces
78  *
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.
82  *
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.
87  *
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.
91  *
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
95  * the native OS.
96  *
97  * Since there are some parts which are platform dependent a define
98  * has been introduced for each platform.  Currently the supported
99  * defines are:
100  *
101  *         -DRT_LINUX
102  *         -DOSE
103  *         -DMARTE_OS
104  *
105  * This module contains the FOSA part exposed by the FRSH_API and
106  * visible for the application.
107  *
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.
113  *
114  * @{
115  **/
116
117
118 //////////////////////////////// OSE ////////////////////////////////////
119 #if defined(OSE)
120
121 #include "frsh_fosa.h"
122 #include "frsh_configuration_parameters.h"
123
124 #include "heapapi.h"
125
126 /*************************
127  * Thread attributes
128  *************************/ 
129
130 /**
131  * frsh_thread_attr_init()
132  *
133  * Initialize a thread attributes object
134  *
135  * This function initializes the object pointed to by attr to all 
136  * the default values defined by FRSH
137  *
138  * @return 0 if successful; otherwise it returns \n
139  *   FOSA_ENOMEM: insufficient memory exists to initialize the thread 
140  *           attributes object
141  **/
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;
149     
150     return 0;
151 }
152
153 /**
154  * frsh_thread_attr_destroy()
155  *
156  * Destroy a thread attributes object
157  *
158  * This function is used to destroy the thread attributes object,
159  * pointed to by attr, and deallocate any system resources allocated for it
160  * 
161  * Returns 0
162  */
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);
167     return 0;
168 }
169
170 /**
171  * frsh_thread_attr_set_stacksize()
172  *
173  * Set the thread minimum stack size in a thread attributes object
174  *
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
180  * 
181  * @return 0 if successful, or the following error code:
182  *    FOSA_EINVAL: the specified stacksize  value is not supported in
183  *            this implementation
184  */
185 int frsh_thread_attr_set_stacksize
186         (frsh_thread_attr_t *attr, size_t stacksize)
187 {
188     //How to check if valid stack size? Possible?.........................
189     //if (??) return FOSA_EINVAL;
190     
191     attr->stack_size = (unsigned long) stacksize;
192     return 0;
193 }
194
195 /**
196  * frsh_thread_attr_get_stacksize()
197  *
198  * Get the thread minimum stack size from a thread attributes object
199  *
200  * This function sets the variable pointed to by stacksize to the
201  * minimum stack size stored in the thread attributes object attr.
202  * 
203  * @return 0
204  */
205 int frsh_thread_attr_get_stacksize
206         (const frsh_thread_attr_t *attr, size_t *stacksize)
207 {
208     *stacksize = attr->stack_size;
209     return 0;
210 }
211
212 /*@}*/
213
214 #endif
215 //////////////////////////// End of OSE /////////////////////////////////