Webserver+3d print

Dependents:   Nucleo

Committer:
Sergunb
Date:
Sat Feb 04 18:15:49 2017 +0000
Revision:
0:8918a71cdbe9
nothing else

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sergunb 0:8918a71cdbe9 1 /**
Sergunb 0:8918a71cdbe9 2 * @file os_port_windows.c
Sergunb 0:8918a71cdbe9 3 * @brief RTOS abstraction layer (Windows)
Sergunb 0:8918a71cdbe9 4 *
Sergunb 0:8918a71cdbe9 5 * @section License
Sergunb 0:8918a71cdbe9 6 *
Sergunb 0:8918a71cdbe9 7 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
Sergunb 0:8918a71cdbe9 8 *
Sergunb 0:8918a71cdbe9 9 * This program is free software; you can redistribute it and/or
Sergunb 0:8918a71cdbe9 10 * modify it under the terms of the GNU General Public License
Sergunb 0:8918a71cdbe9 11 * as published by the Free Software Foundation; either version 2
Sergunb 0:8918a71cdbe9 12 * of the License, or (at your option) any later version.
Sergunb 0:8918a71cdbe9 13 *
Sergunb 0:8918a71cdbe9 14 * This program is distributed in the hope that it will be useful,
Sergunb 0:8918a71cdbe9 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Sergunb 0:8918a71cdbe9 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Sergunb 0:8918a71cdbe9 17 * GNU General Public License for more details.
Sergunb 0:8918a71cdbe9 18 *
Sergunb 0:8918a71cdbe9 19 * You should have received a copy of the GNU General Public License
Sergunb 0:8918a71cdbe9 20 * along with this program; if not, write to the Free Software Foundation,
Sergunb 0:8918a71cdbe9 21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Sergunb 0:8918a71cdbe9 22 *
Sergunb 0:8918a71cdbe9 23 * @author Oryx Embedded SARL (www.oryx-embedded.com)
Sergunb 0:8918a71cdbe9 24 * @version 1.7.6
Sergunb 0:8918a71cdbe9 25 **/
Sergunb 0:8918a71cdbe9 26
Sergunb 0:8918a71cdbe9 27 //Switch to the appropriate trace level
Sergunb 0:8918a71cdbe9 28 #define TRACE_LEVEL TRACE_LEVEL_OFF
Sergunb 0:8918a71cdbe9 29
Sergunb 0:8918a71cdbe9 30 //Memory leaks detection
Sergunb 0:8918a71cdbe9 31 #if (defined(_WIN32) && defined(_DEBUG))
Sergunb 0:8918a71cdbe9 32 #define _CRTDBG_MAP_ALLOC
Sergunb 0:8918a71cdbe9 33 #include <stdlib.h>
Sergunb 0:8918a71cdbe9 34 #include <crtdbg.h>
Sergunb 0:8918a71cdbe9 35 #endif
Sergunb 0:8918a71cdbe9 36
Sergunb 0:8918a71cdbe9 37 //Dependencies
Sergunb 0:8918a71cdbe9 38 #include <stdio.h>
Sergunb 0:8918a71cdbe9 39 #include <stdlib.h>
Sergunb 0:8918a71cdbe9 40 #include <windows.h>
Sergunb 0:8918a71cdbe9 41 #include "os_port.h"
Sergunb 0:8918a71cdbe9 42 #include "os_port_windows.h"
Sergunb 0:8918a71cdbe9 43 #include "debug.h"
Sergunb 0:8918a71cdbe9 44
Sergunb 0:8918a71cdbe9 45
Sergunb 0:8918a71cdbe9 46 /**
Sergunb 0:8918a71cdbe9 47 * @brief Kernel initialization
Sergunb 0:8918a71cdbe9 48 **/
Sergunb 0:8918a71cdbe9 49
Sergunb 0:8918a71cdbe9 50 void osInitKernel(void)
Sergunb 0:8918a71cdbe9 51 {
Sergunb 0:8918a71cdbe9 52 //Not implemented
Sergunb 0:8918a71cdbe9 53 }
Sergunb 0:8918a71cdbe9 54
Sergunb 0:8918a71cdbe9 55
Sergunb 0:8918a71cdbe9 56 /**
Sergunb 0:8918a71cdbe9 57 * @brief Start kernel
Sergunb 0:8918a71cdbe9 58 **/
Sergunb 0:8918a71cdbe9 59
Sergunb 0:8918a71cdbe9 60 void osStartKernel(void)
Sergunb 0:8918a71cdbe9 61 {
Sergunb 0:8918a71cdbe9 62 //Not implemented
Sergunb 0:8918a71cdbe9 63 }
Sergunb 0:8918a71cdbe9 64
Sergunb 0:8918a71cdbe9 65
Sergunb 0:8918a71cdbe9 66 /**
Sergunb 0:8918a71cdbe9 67 * @brief Create a new task
Sergunb 0:8918a71cdbe9 68 * @param[in] name A name identifying the task
Sergunb 0:8918a71cdbe9 69 * @param[in] taskCode Pointer to the task entry function
Sergunb 0:8918a71cdbe9 70 * @param[in] params A pointer to a variable to be passed to the task
Sergunb 0:8918a71cdbe9 71 * @param[in] stackSize The initial size of the stack, in words
Sergunb 0:8918a71cdbe9 72 * @param[in] priority The priority at which the task should run
Sergunb 0:8918a71cdbe9 73 * @return If the function succeeds, the return value is a pointer to the
Sergunb 0:8918a71cdbe9 74 * new task. If the function fails, the return value is NULL
Sergunb 0:8918a71cdbe9 75 **/
Sergunb 0:8918a71cdbe9 76
Sergunb 0:8918a71cdbe9 77 OsTask *osCreateTask(const char_t *name, OsTaskCode taskCode,
Sergunb 0:8918a71cdbe9 78 void *params, size_t stackSize, int_t priority)
Sergunb 0:8918a71cdbe9 79 {
Sergunb 0:8918a71cdbe9 80 void *handle;
Sergunb 0:8918a71cdbe9 81
Sergunb 0:8918a71cdbe9 82 //Create a new thread
Sergunb 0:8918a71cdbe9 83 handle = CreateThread(NULL, 0,
Sergunb 0:8918a71cdbe9 84 (LPTHREAD_START_ROUTINE) taskCode, params, 0, NULL);
Sergunb 0:8918a71cdbe9 85
Sergunb 0:8918a71cdbe9 86 //Return a pointer to the newly created thread
Sergunb 0:8918a71cdbe9 87 return handle;
Sergunb 0:8918a71cdbe9 88 }
Sergunb 0:8918a71cdbe9 89
Sergunb 0:8918a71cdbe9 90
Sergunb 0:8918a71cdbe9 91 /**
Sergunb 0:8918a71cdbe9 92 * @brief Delete a task
Sergunb 0:8918a71cdbe9 93 * @param[in] task Pointer to the task to be deleted
Sergunb 0:8918a71cdbe9 94 **/
Sergunb 0:8918a71cdbe9 95
Sergunb 0:8918a71cdbe9 96 void osDeleteTask(OsTask *task)
Sergunb 0:8918a71cdbe9 97 {
Sergunb 0:8918a71cdbe9 98 //Delete the calling thread?
Sergunb 0:8918a71cdbe9 99 if(task == NULL)
Sergunb 0:8918a71cdbe9 100 {
Sergunb 0:8918a71cdbe9 101 //Kill ourselves
Sergunb 0:8918a71cdbe9 102 ExitThread(0);
Sergunb 0:8918a71cdbe9 103 }
Sergunb 0:8918a71cdbe9 104 else
Sergunb 0:8918a71cdbe9 105 {
Sergunb 0:8918a71cdbe9 106 //Delete the specified thread
Sergunb 0:8918a71cdbe9 107 TerminateThread(task, 0);
Sergunb 0:8918a71cdbe9 108 }
Sergunb 0:8918a71cdbe9 109 }
Sergunb 0:8918a71cdbe9 110
Sergunb 0:8918a71cdbe9 111
Sergunb 0:8918a71cdbe9 112 /**
Sergunb 0:8918a71cdbe9 113 * @brief Delay routine
Sergunb 0:8918a71cdbe9 114 * @param[in] delay Amount of time for which the calling task should block
Sergunb 0:8918a71cdbe9 115 **/
Sergunb 0:8918a71cdbe9 116
Sergunb 0:8918a71cdbe9 117 void osDelayTask(systime_t delay)
Sergunb 0:8918a71cdbe9 118 {
Sergunb 0:8918a71cdbe9 119 //Delay the task for the specified duration
Sergunb 0:8918a71cdbe9 120 Sleep(delay);
Sergunb 0:8918a71cdbe9 121 }
Sergunb 0:8918a71cdbe9 122
Sergunb 0:8918a71cdbe9 123
Sergunb 0:8918a71cdbe9 124 /**
Sergunb 0:8918a71cdbe9 125 * @brief Yield control to the next task
Sergunb 0:8918a71cdbe9 126 **/
Sergunb 0:8918a71cdbe9 127
Sergunb 0:8918a71cdbe9 128 void osSwitchTask(void)
Sergunb 0:8918a71cdbe9 129 {
Sergunb 0:8918a71cdbe9 130 //Not implemented
Sergunb 0:8918a71cdbe9 131 }
Sergunb 0:8918a71cdbe9 132
Sergunb 0:8918a71cdbe9 133
Sergunb 0:8918a71cdbe9 134 /**
Sergunb 0:8918a71cdbe9 135 * @brief Suspend scheduler activity
Sergunb 0:8918a71cdbe9 136 **/
Sergunb 0:8918a71cdbe9 137
Sergunb 0:8918a71cdbe9 138 void osSuspendAllTasks(void)
Sergunb 0:8918a71cdbe9 139 {
Sergunb 0:8918a71cdbe9 140 //Not implemented
Sergunb 0:8918a71cdbe9 141 }
Sergunb 0:8918a71cdbe9 142
Sergunb 0:8918a71cdbe9 143
Sergunb 0:8918a71cdbe9 144 /**
Sergunb 0:8918a71cdbe9 145 * @brief Resume scheduler activity
Sergunb 0:8918a71cdbe9 146 **/
Sergunb 0:8918a71cdbe9 147
Sergunb 0:8918a71cdbe9 148 void osResumeAllTasks(void)
Sergunb 0:8918a71cdbe9 149 {
Sergunb 0:8918a71cdbe9 150 //Not implemented
Sergunb 0:8918a71cdbe9 151 }
Sergunb 0:8918a71cdbe9 152
Sergunb 0:8918a71cdbe9 153
Sergunb 0:8918a71cdbe9 154 /**
Sergunb 0:8918a71cdbe9 155 * @brief Create an event object
Sergunb 0:8918a71cdbe9 156 * @param[in] event Pointer to the event object
Sergunb 0:8918a71cdbe9 157 * @return The function returns TRUE if the event object was successfully
Sergunb 0:8918a71cdbe9 158 * created. Otherwise, FALSE is returned
Sergunb 0:8918a71cdbe9 159 **/
Sergunb 0:8918a71cdbe9 160
Sergunb 0:8918a71cdbe9 161 bool_t osCreateEvent(OsEvent *event)
Sergunb 0:8918a71cdbe9 162 {
Sergunb 0:8918a71cdbe9 163 //Create an event object
Sergunb 0:8918a71cdbe9 164 event->handle = CreateEvent(NULL, FALSE, FALSE, NULL);
Sergunb 0:8918a71cdbe9 165
Sergunb 0:8918a71cdbe9 166 //Check whether the returned handle is valid
Sergunb 0:8918a71cdbe9 167 if(event->handle != NULL)
Sergunb 0:8918a71cdbe9 168 return TRUE;
Sergunb 0:8918a71cdbe9 169 else
Sergunb 0:8918a71cdbe9 170 return FALSE;
Sergunb 0:8918a71cdbe9 171 }
Sergunb 0:8918a71cdbe9 172
Sergunb 0:8918a71cdbe9 173
Sergunb 0:8918a71cdbe9 174 /**
Sergunb 0:8918a71cdbe9 175 * @brief Delete an event object
Sergunb 0:8918a71cdbe9 176 * @param[in] event Pointer to the event object
Sergunb 0:8918a71cdbe9 177 **/
Sergunb 0:8918a71cdbe9 178
Sergunb 0:8918a71cdbe9 179 void osDeleteEvent(OsEvent *event)
Sergunb 0:8918a71cdbe9 180 {
Sergunb 0:8918a71cdbe9 181 //Make sure the handle is valid
Sergunb 0:8918a71cdbe9 182 if(event->handle != NULL)
Sergunb 0:8918a71cdbe9 183 {
Sergunb 0:8918a71cdbe9 184 //Properly dispose the event object
Sergunb 0:8918a71cdbe9 185 CloseHandle(event->handle);
Sergunb 0:8918a71cdbe9 186 }
Sergunb 0:8918a71cdbe9 187 }
Sergunb 0:8918a71cdbe9 188
Sergunb 0:8918a71cdbe9 189
Sergunb 0:8918a71cdbe9 190 /**
Sergunb 0:8918a71cdbe9 191 * @brief Set the specified event object to the signaled state
Sergunb 0:8918a71cdbe9 192 * @param[in] event Pointer to the event object
Sergunb 0:8918a71cdbe9 193 **/
Sergunb 0:8918a71cdbe9 194
Sergunb 0:8918a71cdbe9 195 void osSetEvent(OsEvent *event)
Sergunb 0:8918a71cdbe9 196 {
Sergunb 0:8918a71cdbe9 197 //Set the specified event to the signaled state
Sergunb 0:8918a71cdbe9 198 SetEvent(event->handle);
Sergunb 0:8918a71cdbe9 199 }
Sergunb 0:8918a71cdbe9 200
Sergunb 0:8918a71cdbe9 201
Sergunb 0:8918a71cdbe9 202 /**
Sergunb 0:8918a71cdbe9 203 * @brief Set the specified event object to the nonsignaled state
Sergunb 0:8918a71cdbe9 204 * @param[in] event Pointer to the event object
Sergunb 0:8918a71cdbe9 205 **/
Sergunb 0:8918a71cdbe9 206
Sergunb 0:8918a71cdbe9 207 void osResetEvent(OsEvent *event)
Sergunb 0:8918a71cdbe9 208 {
Sergunb 0:8918a71cdbe9 209 //Force the specified event to the nonsignaled state
Sergunb 0:8918a71cdbe9 210 ResetEvent(event->handle);
Sergunb 0:8918a71cdbe9 211 }
Sergunb 0:8918a71cdbe9 212
Sergunb 0:8918a71cdbe9 213
Sergunb 0:8918a71cdbe9 214 /**
Sergunb 0:8918a71cdbe9 215 * @brief Wait until the specified event is in the signaled state
Sergunb 0:8918a71cdbe9 216 * @param[in] event Pointer to the event object
Sergunb 0:8918a71cdbe9 217 * @param[in] timeout Timeout interval
Sergunb 0:8918a71cdbe9 218 * @return The function returns TRUE if the state of the specified object is
Sergunb 0:8918a71cdbe9 219 * signaled. FALSE is returned if the timeout interval elapsed
Sergunb 0:8918a71cdbe9 220 **/
Sergunb 0:8918a71cdbe9 221
Sergunb 0:8918a71cdbe9 222 bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Sergunb 0:8918a71cdbe9 223 {
Sergunb 0:8918a71cdbe9 224 //Wait until the specified event is in the signaled state
Sergunb 0:8918a71cdbe9 225 if(WaitForSingleObject(event->handle, timeout) == WAIT_OBJECT_0)
Sergunb 0:8918a71cdbe9 226 return TRUE;
Sergunb 0:8918a71cdbe9 227 else
Sergunb 0:8918a71cdbe9 228 return FALSE;
Sergunb 0:8918a71cdbe9 229 }
Sergunb 0:8918a71cdbe9 230
Sergunb 0:8918a71cdbe9 231
Sergunb 0:8918a71cdbe9 232 /**
Sergunb 0:8918a71cdbe9 233 * @brief Set an event object to the signaled state from an interrupt service routine
Sergunb 0:8918a71cdbe9 234 * @param[in] event Pointer to the event object
Sergunb 0:8918a71cdbe9 235 * @return TRUE if setting the event to signaled state caused a task to unblock
Sergunb 0:8918a71cdbe9 236 * and the unblocked task has a priority higher than the currently running task
Sergunb 0:8918a71cdbe9 237 **/
Sergunb 0:8918a71cdbe9 238
Sergunb 0:8918a71cdbe9 239 bool_t osSetEventFromIsr(OsEvent *event)
Sergunb 0:8918a71cdbe9 240 {
Sergunb 0:8918a71cdbe9 241 //Not implemented
Sergunb 0:8918a71cdbe9 242 return FALSE;
Sergunb 0:8918a71cdbe9 243 }
Sergunb 0:8918a71cdbe9 244
Sergunb 0:8918a71cdbe9 245
Sergunb 0:8918a71cdbe9 246 /**
Sergunb 0:8918a71cdbe9 247 * @brief Create a semaphore object
Sergunb 0:8918a71cdbe9 248 * @param[in] semaphore Pointer to the semaphore object
Sergunb 0:8918a71cdbe9 249 * @param[in] count The maximum count for the semaphore object. This value
Sergunb 0:8918a71cdbe9 250 * must be greater than zero
Sergunb 0:8918a71cdbe9 251 * @return The function returns TRUE if the semaphore was successfully
Sergunb 0:8918a71cdbe9 252 * created. Otherwise, FALSE is returned
Sergunb 0:8918a71cdbe9 253 **/
Sergunb 0:8918a71cdbe9 254
Sergunb 0:8918a71cdbe9 255 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Sergunb 0:8918a71cdbe9 256 {
Sergunb 0:8918a71cdbe9 257 //Create a semaphore object
Sergunb 0:8918a71cdbe9 258 semaphore->handle = CreateSemaphore(NULL, count, count, NULL);
Sergunb 0:8918a71cdbe9 259
Sergunb 0:8918a71cdbe9 260 //Check whether the returned handle is valid
Sergunb 0:8918a71cdbe9 261 if(semaphore->handle != NULL)
Sergunb 0:8918a71cdbe9 262 return TRUE;
Sergunb 0:8918a71cdbe9 263 else
Sergunb 0:8918a71cdbe9 264 return FALSE;
Sergunb 0:8918a71cdbe9 265 }
Sergunb 0:8918a71cdbe9 266
Sergunb 0:8918a71cdbe9 267
Sergunb 0:8918a71cdbe9 268 /**
Sergunb 0:8918a71cdbe9 269 * @brief Delete a semaphore object
Sergunb 0:8918a71cdbe9 270 * @param[in] semaphore Pointer to the semaphore object
Sergunb 0:8918a71cdbe9 271 **/
Sergunb 0:8918a71cdbe9 272
Sergunb 0:8918a71cdbe9 273 void osDeleteSemaphore(OsSemaphore *semaphore)
Sergunb 0:8918a71cdbe9 274 {
Sergunb 0:8918a71cdbe9 275 //Make sure the handle is valid
Sergunb 0:8918a71cdbe9 276 if(semaphore->handle != NULL)
Sergunb 0:8918a71cdbe9 277 {
Sergunb 0:8918a71cdbe9 278 //Properly dispose the semaphore object
Sergunb 0:8918a71cdbe9 279 CloseHandle(semaphore->handle);
Sergunb 0:8918a71cdbe9 280 }
Sergunb 0:8918a71cdbe9 281 }
Sergunb 0:8918a71cdbe9 282
Sergunb 0:8918a71cdbe9 283
Sergunb 0:8918a71cdbe9 284 /**
Sergunb 0:8918a71cdbe9 285 * @brief Wait for the specified semaphore to be available
Sergunb 0:8918a71cdbe9 286 * @param[in] semaphore Pointer to the semaphore object
Sergunb 0:8918a71cdbe9 287 * @param[in] timeout Timeout interval
Sergunb 0:8918a71cdbe9 288 * @return The function returns TRUE if the semaphore is available. FALSE is
Sergunb 0:8918a71cdbe9 289 * returned if the timeout interval elapsed
Sergunb 0:8918a71cdbe9 290 **/
Sergunb 0:8918a71cdbe9 291
Sergunb 0:8918a71cdbe9 292 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Sergunb 0:8918a71cdbe9 293 {
Sergunb 0:8918a71cdbe9 294 //Wait until the specified semaphore becomes available
Sergunb 0:8918a71cdbe9 295 if(WaitForSingleObject(semaphore->handle, timeout) == WAIT_OBJECT_0)
Sergunb 0:8918a71cdbe9 296 return TRUE;
Sergunb 0:8918a71cdbe9 297 else
Sergunb 0:8918a71cdbe9 298 return FALSE;
Sergunb 0:8918a71cdbe9 299 }
Sergunb 0:8918a71cdbe9 300
Sergunb 0:8918a71cdbe9 301
Sergunb 0:8918a71cdbe9 302 /**
Sergunb 0:8918a71cdbe9 303 * @brief Release the specified semaphore object
Sergunb 0:8918a71cdbe9 304 * @param[in] semaphore Pointer to the semaphore object
Sergunb 0:8918a71cdbe9 305 **/
Sergunb 0:8918a71cdbe9 306
Sergunb 0:8918a71cdbe9 307 void osReleaseSemaphore(OsSemaphore *semaphore)
Sergunb 0:8918a71cdbe9 308 {
Sergunb 0:8918a71cdbe9 309 //Release the semaphore
Sergunb 0:8918a71cdbe9 310 ReleaseSemaphore(semaphore->handle, 1, NULL);
Sergunb 0:8918a71cdbe9 311 }
Sergunb 0:8918a71cdbe9 312
Sergunb 0:8918a71cdbe9 313
Sergunb 0:8918a71cdbe9 314 /**
Sergunb 0:8918a71cdbe9 315 * @brief Create a mutex object
Sergunb 0:8918a71cdbe9 316 * @param[in] mutex Pointer to the mutex object
Sergunb 0:8918a71cdbe9 317 * @return The function returns TRUE if the mutex was successfully
Sergunb 0:8918a71cdbe9 318 * created. Otherwise, FALSE is returned
Sergunb 0:8918a71cdbe9 319 **/
Sergunb 0:8918a71cdbe9 320
Sergunb 0:8918a71cdbe9 321 bool_t osCreateMutex(OsMutex *mutex)
Sergunb 0:8918a71cdbe9 322 {
Sergunb 0:8918a71cdbe9 323 //Create a mutex object
Sergunb 0:8918a71cdbe9 324 mutex->handle = CreateMutex(NULL, FALSE, NULL);
Sergunb 0:8918a71cdbe9 325
Sergunb 0:8918a71cdbe9 326 //Check whether the returned handle is valid
Sergunb 0:8918a71cdbe9 327 if(mutex->handle != NULL)
Sergunb 0:8918a71cdbe9 328 return TRUE;
Sergunb 0:8918a71cdbe9 329 else
Sergunb 0:8918a71cdbe9 330 return FALSE;
Sergunb 0:8918a71cdbe9 331 }
Sergunb 0:8918a71cdbe9 332
Sergunb 0:8918a71cdbe9 333
Sergunb 0:8918a71cdbe9 334 /**
Sergunb 0:8918a71cdbe9 335 * @brief Delete a mutex object
Sergunb 0:8918a71cdbe9 336 * @param[in] mutex Pointer to the mutex object
Sergunb 0:8918a71cdbe9 337 **/
Sergunb 0:8918a71cdbe9 338
Sergunb 0:8918a71cdbe9 339 void osDeleteMutex(OsMutex *mutex)
Sergunb 0:8918a71cdbe9 340 {
Sergunb 0:8918a71cdbe9 341 //Make sure the handle is valid
Sergunb 0:8918a71cdbe9 342 if(mutex->handle != NULL)
Sergunb 0:8918a71cdbe9 343 {
Sergunb 0:8918a71cdbe9 344 //Properly dispose the mutex object
Sergunb 0:8918a71cdbe9 345 CloseHandle(mutex->handle);
Sergunb 0:8918a71cdbe9 346 }
Sergunb 0:8918a71cdbe9 347 }
Sergunb 0:8918a71cdbe9 348
Sergunb 0:8918a71cdbe9 349
Sergunb 0:8918a71cdbe9 350 /**
Sergunb 0:8918a71cdbe9 351 * @brief Acquire ownership of the specified mutex object
Sergunb 0:8918a71cdbe9 352 * @param[in] mutex A handle to the mutex object
Sergunb 0:8918a71cdbe9 353 **/
Sergunb 0:8918a71cdbe9 354
Sergunb 0:8918a71cdbe9 355 void osAcquireMutex(OsMutex *mutex)
Sergunb 0:8918a71cdbe9 356 {
Sergunb 0:8918a71cdbe9 357 //Obtain ownership of the mutex object
Sergunb 0:8918a71cdbe9 358 WaitForSingleObject(mutex->handle, INFINITE);
Sergunb 0:8918a71cdbe9 359 }
Sergunb 0:8918a71cdbe9 360
Sergunb 0:8918a71cdbe9 361
Sergunb 0:8918a71cdbe9 362 /**
Sergunb 0:8918a71cdbe9 363 * @brief Release ownership of the specified mutex object
Sergunb 0:8918a71cdbe9 364 * @param[in] mutex Pointer to the mutex object
Sergunb 0:8918a71cdbe9 365 **/
Sergunb 0:8918a71cdbe9 366
Sergunb 0:8918a71cdbe9 367 void osReleaseMutex(OsMutex *mutex)
Sergunb 0:8918a71cdbe9 368 {
Sergunb 0:8918a71cdbe9 369 //Release ownership of the mutex object
Sergunb 0:8918a71cdbe9 370 ReleaseMutex(mutex->handle);
Sergunb 0:8918a71cdbe9 371 }
Sergunb 0:8918a71cdbe9 372
Sergunb 0:8918a71cdbe9 373
Sergunb 0:8918a71cdbe9 374 /**
Sergunb 0:8918a71cdbe9 375 * @brief Retrieve system time
Sergunb 0:8918a71cdbe9 376 * @return Number of milliseconds elapsed since the system was last started
Sergunb 0:8918a71cdbe9 377 **/
Sergunb 0:8918a71cdbe9 378
Sergunb 0:8918a71cdbe9 379 systime_t osGetSystemTime(void)
Sergunb 0:8918a71cdbe9 380 {
Sergunb 0:8918a71cdbe9 381 //Get current tick count
Sergunb 0:8918a71cdbe9 382 return GetTickCount();
Sergunb 0:8918a71cdbe9 383 }
Sergunb 0:8918a71cdbe9 384
Sergunb 0:8918a71cdbe9 385
Sergunb 0:8918a71cdbe9 386 /**
Sergunb 0:8918a71cdbe9 387 * @brief Allocate a memory block
Sergunb 0:8918a71cdbe9 388 * @param[in] size Bytes to allocate
Sergunb 0:8918a71cdbe9 389 * @return A pointer to the allocated memory block or NULL if
Sergunb 0:8918a71cdbe9 390 * there is insufficient memory available
Sergunb 0:8918a71cdbe9 391 **/
Sergunb 0:8918a71cdbe9 392
Sergunb 0:8918a71cdbe9 393 void *osAllocMem(size_t size)
Sergunb 0:8918a71cdbe9 394 {
Sergunb 0:8918a71cdbe9 395 //Allocate a memory block
Sergunb 0:8918a71cdbe9 396 return malloc(size);
Sergunb 0:8918a71cdbe9 397 }
Sergunb 0:8918a71cdbe9 398
Sergunb 0:8918a71cdbe9 399
Sergunb 0:8918a71cdbe9 400 /**
Sergunb 0:8918a71cdbe9 401 * @brief Release a previously allocated memory block
Sergunb 0:8918a71cdbe9 402 * @param[in] p Previously allocated memory block to be freed
Sergunb 0:8918a71cdbe9 403 **/
Sergunb 0:8918a71cdbe9 404
Sergunb 0:8918a71cdbe9 405 void osFreeMem(void *p)
Sergunb 0:8918a71cdbe9 406 {
Sergunb 0:8918a71cdbe9 407 //Free memory block
Sergunb 0:8918a71cdbe9 408 free(p);
Sergunb 0:8918a71cdbe9 409 }
Sergunb 0:8918a71cdbe9 410