Webserver+3d print
Embed:
(wiki syntax)
Show/hide line numbers
os_port_none.c
Go to the documentation of this file.
00001 /** 00002 * @file os_port_none.c 00003 * @brief RTOS-less environment 00004 * 00005 * @section License 00006 * 00007 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. 00008 * 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU General Public License 00011 * as published by the Free Software Foundation; either version 2 00012 * of the License, or (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software Foundation, 00021 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00022 * 00023 * @author Oryx Embedded SARL (www.oryx-embedded.com) 00024 * @version 1.7.6 00025 **/ 00026 00027 //Switch to the appropriate trace level 00028 #define TRACE_LEVEL TRACE_LEVEL_OFF 00029 00030 //Dependencies 00031 #include <stdio.h> 00032 #include <stdlib.h> 00033 #include "os_port.h" 00034 #include "os_port_none.h" 00035 #include "debug.h" 00036 00037 //Platform-specific dependencies 00038 #if defined(__linux__) || defined(__FreeBSD__) 00039 #include <sys/time.h> 00040 #elif defined(_WIN32) 00041 #include <windows.h> 00042 #endif 00043 00044 //Tick count 00045 systime_t systemTicks = 0; 00046 00047 00048 /** 00049 * @brief Kernel initialization 00050 **/ 00051 00052 void osInitKernel(void) 00053 { 00054 //Initialize tick count 00055 systemTicks = 0; 00056 } 00057 00058 00059 /** 00060 * @brief Start kernel 00061 **/ 00062 00063 void osStartKernel(void) 00064 { 00065 } 00066 00067 00068 /** 00069 * @brief Create a new task 00070 * @param[in] name A name identifying the task 00071 * @param[in] taskCode Pointer to the task entry function 00072 * @param[in] params A pointer to a variable to be passed to the task 00073 * @param[in] stackSize The initial size of the stack, in words 00074 * @param[in] priority The priority at which the task should run 00075 * @return If the function succeeds, the return value is a pointer to the 00076 * new task. If the function fails, the return value is NULL 00077 **/ 00078 00079 OsTask *osCreateTask(const char_t *name, OsTaskCode taskCode, 00080 void *params, size_t stackSize, int_t priority) 00081 { 00082 //Return a non-NULL pointer 00083 return (OsTask *) (-1); 00084 } 00085 00086 00087 /** 00088 * @brief Delete a task 00089 * @param[in] task Pointer to the task to be deleted 00090 **/ 00091 00092 void osDeleteTask(OsTask *task) 00093 { 00094 } 00095 00096 00097 /** 00098 * @brief Delay routine 00099 * @param[in] delay Amount of time for which the calling task should block 00100 **/ 00101 00102 void osDelayTask(systime_t delay) 00103 { 00104 } 00105 00106 00107 /** 00108 * @brief Yield control to the next task 00109 **/ 00110 00111 void osSwitchTask(void) 00112 { 00113 } 00114 00115 00116 /** 00117 * @brief Suspend scheduler activity 00118 **/ 00119 00120 void osSuspendAllTasks(void) 00121 { 00122 } 00123 00124 00125 /** 00126 * @brief Resume scheduler activity 00127 **/ 00128 00129 void osResumeAllTasks(void) 00130 { 00131 } 00132 00133 00134 /** 00135 * @brief Create an event object 00136 * @param[in] event Pointer to the event object 00137 * @return The function returns TRUE if the event object was successfully 00138 * created. Otherwise, FALSE is returned 00139 **/ 00140 00141 bool_t osCreateEvent(OsEvent *event) 00142 { 00143 //Force the event to the nonsignaled state 00144 *event = FALSE; 00145 //Event successfully created 00146 return TRUE; 00147 } 00148 00149 00150 /** 00151 * @brief Delete an event object 00152 * @param[in] event Pointer to the event object 00153 **/ 00154 00155 void osDeleteEvent(OsEvent *event) 00156 { 00157 } 00158 00159 00160 /** 00161 * @brief Set the specified event object to the signaled state 00162 * @param[in] event Pointer to the event object 00163 **/ 00164 00165 void osSetEvent(OsEvent *event) 00166 { 00167 //Set the specified event to the signaled state 00168 *event = TRUE; 00169 } 00170 00171 00172 /** 00173 * @brief Set the specified event object to the nonsignaled state 00174 * @param[in] event Pointer to the event object 00175 **/ 00176 00177 void osResetEvent(OsEvent *event) 00178 { 00179 //Force the specified event to the nonsignaled state 00180 *event = FALSE; 00181 } 00182 00183 00184 /** 00185 * @brief Wait until the specified event is in the signaled state 00186 * @param[in] event Pointer to the event object 00187 * @param[in] timeout Timeout interval 00188 * @return The function returns TRUE if the state of the specified object is 00189 * signaled. FALSE is returned if the timeout interval elapsed 00190 **/ 00191 00192 bool_t osWaitForEvent(OsEvent *event, systime_t timeout) 00193 { 00194 //Check whether the specified event is set 00195 if(*event) 00196 { 00197 //Clear event 00198 *event = FALSE; 00199 //The event is in the signaled state 00200 return TRUE; 00201 } 00202 else 00203 { 00204 //The event is not in the signaled state 00205 return FALSE; 00206 } 00207 } 00208 00209 00210 /** 00211 * @brief Set an event object to the signaled state from an interrupt service routine 00212 * @param[in] event Pointer to the event object 00213 * @return TRUE if setting the event to signaled state caused a task to unblock 00214 * and the unblocked task has a priority higher than the currently running task 00215 **/ 00216 00217 bool_t osSetEventFromIsr(OsEvent *event) 00218 { 00219 //Set the specified event to the signaled state 00220 *event = TRUE; 00221 //A higher priority task has been woken? 00222 return FALSE; 00223 } 00224 00225 00226 /** 00227 * @brief Create a semaphore object 00228 * @param[in] semaphore Pointer to the semaphore object 00229 * @param[in] count The maximum count for the semaphore object. This value 00230 * must be greater than zero 00231 * @return The function returns TRUE if the semaphore was successfully 00232 * created. Otherwise, FALSE is returned 00233 **/ 00234 00235 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count) 00236 { 00237 //Create a semaphore 00238 *semaphore = count; 00239 //The semaphore was successfully created 00240 return TRUE; 00241 } 00242 00243 00244 /** 00245 * @brief Delete a semaphore object 00246 * @param[in] semaphore Pointer to the semaphore object 00247 **/ 00248 00249 void osDeleteSemaphore(OsSemaphore *semaphore) 00250 { 00251 } 00252 00253 00254 /** 00255 * @brief Wait for the specified semaphore to be available 00256 * @param[in] semaphore Pointer to the semaphore object 00257 * @param[in] timeout Timeout interval 00258 * @return The function returns TRUE if the semaphore is available. FALSE is 00259 * returned if the timeout interval elapsed 00260 **/ 00261 00262 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout) 00263 { 00264 //Check whether the specified semaphore is available 00265 if(*semaphore > 0) 00266 { 00267 //Decrement semaphore value 00268 *semaphore -= 1; 00269 //The semaphore is available 00270 return TRUE; 00271 } 00272 else 00273 { 00274 //The semaphore is not available 00275 return FALSE; 00276 } 00277 } 00278 00279 00280 /** 00281 * @brief Release the specified semaphore object 00282 * @param[in] semaphore Pointer to the semaphore object 00283 **/ 00284 00285 void osReleaseSemaphore(OsSemaphore *semaphore) 00286 { 00287 //Release the semaphore 00288 *semaphore += 1; 00289 } 00290 00291 00292 /** 00293 * @brief Create a mutex object 00294 * @param[in] mutex Pointer to the mutex object 00295 * @return The function returns TRUE if the mutex was successfully 00296 * created. Otherwise, FALSE is returned 00297 **/ 00298 00299 bool_t osCreateMutex(OsMutex *mutex) 00300 { 00301 //The mutex was successfully created 00302 return TRUE; 00303 } 00304 00305 00306 /** 00307 * @brief Delete a mutex object 00308 * @param[in] mutex Pointer to the mutex object 00309 **/ 00310 00311 void osDeleteMutex(OsMutex *mutex) 00312 { 00313 } 00314 00315 00316 /** 00317 * @brief Acquire ownership of the specified mutex object 00318 * @param[in] mutex Pointer to the mutex object 00319 **/ 00320 00321 void osAcquireMutex(OsMutex *mutex) 00322 { 00323 } 00324 00325 00326 /** 00327 * @brief Release ownership of the specified mutex object 00328 * @param[in] mutex Pointer to the mutex object 00329 **/ 00330 00331 void osReleaseMutex(OsMutex *mutex) 00332 { 00333 } 00334 00335 00336 /** 00337 * @brief Retrieve system time 00338 * @return Number of milliseconds elapsed since the system was last started 00339 **/ 00340 00341 systime_t osGetSystemTime(void) 00342 { 00343 systime_t time; 00344 00345 #if defined(__linux__) || defined(__FreeBSD__) 00346 struct timeval tv; 00347 //Get current time 00348 gettimeofday(&tv, NULL); 00349 //Convert resulting value to milliseconds 00350 time = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); 00351 #elif defined(_WIN32) 00352 //Get current tick count 00353 time = GetTickCount(); 00354 #else 00355 //Get current tick count 00356 time = systemTicks; 00357 #endif 00358 00359 //Convert system ticks to milliseconds 00360 return OS_SYSTICKS_TO_MS(time); 00361 } 00362 00363 00364 /** 00365 * @brief Allocate a memory block 00366 * @param[in] size Bytes to allocate 00367 * @return A pointer to the allocated memory block or NULL if 00368 * there is insufficient memory available 00369 **/ 00370 00371 void *osAllocMem(size_t size) 00372 { 00373 void *p; 00374 00375 //Allocate a memory block 00376 p = malloc(size); 00377 00378 //Debug message 00379 TRACE_DEBUG("Allocating %" PRIuSIZE " bytes at 0x%08" PRIXPTR "\r\n", size, (uintptr_t) p); 00380 00381 //Return a pointer to the newly allocated memory block 00382 return p; 00383 } 00384 00385 00386 /** 00387 * @brief Release a previously allocated memory block 00388 * @param[in] p Previously allocated memory block to be freed 00389 **/ 00390 00391 void osFreeMem(void *p) 00392 { 00393 //Make sure the pointer is valid 00394 if(p != NULL) 00395 { 00396 //Debug message 00397 TRACE_DEBUG("Freeing memory at 0x%08" PRIXPTR "\r\n", (uintptr_t) p); 00398 00399 //Free memory block 00400 free(p); 00401 } 00402 } 00403
Generated on Tue Jul 12 2022 17:10:15 by
