Tiny protocol  0.9.3
Tiny communication protocol for microcontrollers
mingw32_hal.h
1 /*
2  Copyright 2016,2019 (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 #pragma once
21 
22 #include <pthread.h>
23 #include <unistd.h>
24 #include <stdint.h>
25 #include <time.h>
26 #include <windows.h>
27 
28 #ifndef CONFIG_ENABLE_CHECKSUM
29 # define CONFIG_ENABLE_CHECKSUM
30 #endif
31 
32 #ifndef CONFIG_ENABLE_FCS16
33 # define CONFIG_ENABLE_FCS16
34 #endif
35 
36 #ifndef CONFIG_ENABLE_FCS32
37 # define CONFIG_ENABLE_FCS32
38 #endif
39 
40 #ifndef DOXYGEN_SHOULD_SKIP_THIS
41 
46 typedef pthread_mutex_t tiny_mutex_t;
47 
52 typedef struct
53 {
54  uint8_t bits;
55  uint16_t waiters;
56  pthread_mutex_t mutex;
57  pthread_cond_t cond;
58 } tiny_events_t;
59 
60 //#define TASK_YIELD() Sleep(0)
61 
62 
63 /*static inline uint16_t PLATFORM_TICKS()
64 {
65  return GetTickCount();
66 }
67 */
68 
69 #if 0
70 
71 #include <pthread.h>
72 #include <unistd.h>
73 #include <stdint.h>
74 #include <time.h>
75 #include <Windows.h>
76 
77 #define PLATFORM_MUTEX pthread_mutex_t
78 
79 #define MUTEX_INIT(x) pthread_mutex_init(&x, NULL)
80 
81 #define MUTEX_LOCK(x) pthread_mutex_lock(&x)
82 
83 #define MUTEX_TRY_LOCK(x) pthread_mutex_trylock(&x)
84 
85 #define MUTEX_UNLOCK(x) pthread_mutex_unlock(&x)
86 
87 #define MUTEX_DESTROY(x) pthread_mutex_destroy(&x)
88 
89 #define PLATFORM_COND pthread_cond_t
90 
91 #define COND_INIT(x) pthread_cond_init(&x, NULL)
92 
93 #define COND_DESTROY(x) pthread_cond_destroy(&x)
94 
95 #define COND_WAIT(cond, mutex) pthread_cond_wait(&cond, &mutex)
96 
97 #define COND_SIGNAL(x) pthread_cond_signal(&x)
98 
99 #define TASK_YIELD() sleep(0)
100 
101 
102 static inline uint16_t PLATFORM_TICKS()
103 {
104  return GetTickCount();
105 }
106 
107 #endif
108 
109 #endif