Tiny protocol  0.7.0
Tiny communication protocol for microcontrollers
tiny_defines.h
1 /*
2  Copyright 2016 (C) Alexey Dynda
3 
4  This file is part of Tiny Protocol Library.
5 
6  Protocol Library is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Protocol Library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with Protocol Library. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef _TINY_DEFINES_H_
21 #define _TINY_DEFINES_H_
22 
23 #include <pthread.h>
24 #include <unistd.h>
25 #include <stdint.h>
26 #include <time.h>
27 
28 #define PLATFORM_MUTEX pthread_mutex_t
29 
30 #define MUTEX_INIT(x) pthread_mutex_init(&x, NULL)
31 
32 #define MUTEX_LOCK(x) pthread_mutex_lock(&x)
33 
34 #define MUTEX_TRY_LOCK(x) pthread_mutex_trylock(&x)
35 
36 #define MUTEX_UNLOCK(x) pthread_mutex_unlock(&x)
37 
38 #define MUTEX_DESTROY(x) pthread_mutex_destroy(&x)
39 
40 #define PLATFORM_COND pthread_cond_t
41 
42 #define COND_INIT(x) pthread_cond_init(&x, NULL)
43 
44 #define COND_DESTROY(x) pthread_cond_destroy(&x)
45 
46 #define COND_WAIT(cond, mutex) pthread_cond_wait(&cond, &mutex)
47 
48 #define COND_SIGNAL(x) pthread_cond_signal(&x)
49 
50 #define TASK_YIELD() sleep(0)
51 
52 
53 static inline uint16_t PLATFORM_TICKS()
54 {
55  struct timespec ts;
56  clock_gettime(CLOCK_MONOTONIC, &ts);
57  return (ts.tv_sec * 1000) + ts.tv_nsec / 1000000;
58 }
59 
60 
61 #endif /* _TINY_DEFINES_H_ */
62 
63