S32 SDK
osif.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
19 #ifndef OSIF_H
20 #define OSIF_H
21 
22 #include <stdint.h>
23 
40 /*******************************************************************************
41  * Definitions
42  ******************************************************************************/
43 
46 #ifdef USING_OS_FREERTOS
47 /* FreeRTOS implementation */
48 #include "FreeRTOS.h"
49 #include "semphr.h"
51 typedef SemaphoreHandle_t mutex_t;
53 typedef SemaphoreHandle_t semaphore_t;
54 
55 #else
56 /* Bare-metal implementation */
58 typedef uint8_t mutex_t;
60 typedef volatile uint8_t semaphore_t;
61 #endif /* ifdef USING_OS_FREERTOS */
62 
65 #define OSIF_WAIT_FOREVER 0xFFFFFFFFu
66 
67 #include "status.h"
68 
69 /*******************************************************************************
70  * API
71  ******************************************************************************/
72 
73 #if defined (__cplusplus)
74 extern "C" {
75 #endif
76 
82 void OSIF_TimeDelay(const uint32_t delay);
83 
90 uint32_t OSIF_GetMilliseconds(void);
91 
103 status_t OSIF_MutexLock(const mutex_t * const pMutex,
104  const uint32_t timeout);
105 
114 status_t OSIF_MutexUnlock(const mutex_t * const pMutex);
115 
116 
125 status_t OSIF_MutexCreate(mutex_t * const pMutex);
126 
134 status_t OSIF_MutexDestroy(const mutex_t * const pMutex);
135 
136 
146 status_t OSIF_SemaWait(semaphore_t * const pSem,
147  const uint32_t timeout);
148 
149 
158 status_t OSIF_SemaPost(semaphore_t * const pSem);
159 
160 
170 status_t OSIF_SemaCreate(semaphore_t * const pSem,
171  const uint8_t initValue);
172 
173 
181 status_t OSIF_SemaDestroy(const semaphore_t * const pSem);
182 
184 #if defined (__cplusplus)
185 }
186 #endif
187 
190 #endif /* OSIF_H */
191 /*******************************************************************************
192  * EOF
193  ******************************************************************************/
status_t OSIF_MutexDestroy(const mutex_t *const pMutex)
Destroys a previously created mutex.
status_t OSIF_SemaDestroy(const semaphore_t *const pSem)
Destroys a previously created semaphore.
void OSIF_TimeDelay(const uint32_t delay)
Delays execution for a number of milliseconds.
status_t OSIF_MutexUnlock(const mutex_t *const pMutex)
Unlocks a previously locked mutex.
status_t OSIF_MutexLock(const mutex_t *const pMutex, const uint32_t timeout)
Waits for a mutex and locks it.
uint32_t OSIF_GetMilliseconds(void)
Returns the number of miliseconds elapsed since starting the internal timer or starting the scheduler...
status_t OSIF_SemaCreate(semaphore_t *const pSem, const uint8_t initValue)
Creates a semaphore with a given value.
status_t OSIF_MutexCreate(mutex_t *const pMutex)
Create an unlocked mutex.
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:31
status_t OSIF_SemaWait(semaphore_t *const pSem, const uint32_t timeout)
Decrement a semaphore with timeout.
status_t OSIF_SemaPost(semaphore_t *const pSem)
Increment a semaphore.