Tiny protocol  0.9.0
Tiny communication protocol for microcontrollers
tiny_types.h
Go to the documentation of this file.
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 
27 #pragma once
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #if defined(__AVR__)
34 #include "include/avr_hal.h"
35 #elif defined(__XTENSA__)
36 #include "include/esp32_hal.h"
37 #elif defined(ARDUINO)
38 #include "include/arduino_hal.h"
39 #elif defined(__linux__)
40 #include "include/linux_hal.h"
41 #elif defined(__MINGW32__)
42 #include "include/mingw32_hal.h"
43 #else
44 #warning "Platform not supported. Multithread support is disabled"
45 #include "include/no_platform_hal.h"
46 #endif
47 
48 #include <stdint.h>
49 
51 #ifdef CONFIG_ENABLE_FCS32
52  typedef uint32_t fcs_t;
53 #else
54  typedef uint16_t fcs_t;
55 #endif
56 
62 #define TINY_SUCCESS (0)
64 #define TINY_ERR_FAILED (-1)
66 #define TINY_ERR_TIMEOUT (-2)
68 #define TINY_ERR_DATA_TOO_LARGE (-3)
70 #define TINY_ERR_INVALID_DATA (-4)
72 #define TINY_ERR_BUSY (-5)
74 #define TINY_ERR_OUT_OF_SYNC (-6)
76 #define TINY_ERR_AGAIN (-7)
78 #define TINY_ERR_WRONG_CRC (-8)
80 
88 #define TINY_FLAG_NO_WAIT (0)
90 #define TINY_FLAG_READ_ALL (1)
92 #define TINY_FLAG_LOCK_SEND (2)
94 #define TINY_FLAG_WAIT_FOREVER (0x80)
96 
103 typedef struct
104 {
106  uint32_t oosyncBytes;
108  uint32_t bytesSent;
110  uint32_t bytesReceived;
112  uint32_t framesSent;
114  uint32_t framesReceived;
116  uint32_t framesBroken;
117 } STinyStats;
118 
128 typedef int (*write_block_cb_t)(void *pdata, const void *buffer, int size);
129 
139 typedef int (*read_block_cb_t)(void *pdata, void *buffer, int size);
140 
141 
152 typedef void (*on_frame_cb_t)(void *handle, uint16_t uid, uint8_t *pdata, int size);
153 
154 #define EVENT_BIS_ALL 0xFF
155 #define EVENT_BITS_CLEAR 1
156 #define EVENT_BITS_LEAVE 0
157 
158 
162 void tiny_mutex_create(tiny_mutex_t *mutex);
163 
168 void tiny_mutex_destroy(tiny_mutex_t *mutex);
169 
174 void tiny_mutex_lock(tiny_mutex_t *mutex);
175 
182 uint8_t tiny_mutex_try_lock(tiny_mutex_t *mutex);
183 
188 void tiny_mutex_unlock(tiny_mutex_t *mutex);
189 
194 void tiny_events_create(tiny_events_t *events);
195 
200 void tiny_events_destroy(tiny_events_t *events);
201 
211 uint8_t tiny_events_wait(tiny_events_t *event, uint8_t bits,
212  uint8_t clear, uint32_t timeout);
213 
219 void tiny_events_set(tiny_events_t *event, uint8_t bits);
220 
226 void tiny_events_clear(tiny_events_t *event, uint8_t bits);
227 
232 void tiny_sleep(uint32_t ms);
233 
237 uint32_t tiny_millis();
238 
243 void tiny_log_level(uint8_t level);
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 
void tiny_mutex_destroy(tiny_mutex_t *mutex)
uint32_t framesBroken
Number of broken frames received.
Definition: tiny_types.h:116
uint32_t bytesReceived
Number of payload bytes totally received through the channel.
Definition: tiny_types.h:110
uint8_t tiny_events_wait(tiny_events_t *event, uint8_t bits, uint8_t clear, uint32_t timeout)
uint32_t framesSent
Number of frames, successfully sent through the channel.
Definition: tiny_types.h:112
void tiny_events_clear(tiny_events_t *event, uint8_t bits)
Definition: tiny_types.h:103
uint32_t tiny_millis()
int(* read_block_cb_t)(void *pdata, void *buffer, int size)
Definition: tiny_types.h:139
void(* on_frame_cb_t)(void *handle, uint16_t uid, uint8_t *pdata, int size)
Definition: tiny_types.h:152
uint32_t framesReceived
Number of frames, successfully received through the communication channel.
Definition: tiny_types.h:114
uint32_t oosyncBytes
Number of bytes received out of frame bytes.
Definition: tiny_types.h:106
void tiny_mutex_lock(tiny_mutex_t *mutex)
void tiny_mutex_unlock(tiny_mutex_t *mutex)
uint8_t tiny_mutex_try_lock(tiny_mutex_t *mutex)
void tiny_sleep(uint32_t ms)
int(* write_block_cb_t)(void *pdata, const void *buffer, int size)
Definition: tiny_types.h:128
void tiny_events_destroy(tiny_events_t *events)
void tiny_events_set(tiny_events_t *event, uint8_t bits)
uint32_t bytesSent
Number of payload bytes totally sent through the channel.
Definition: tiny_types.h:108
void tiny_log_level(uint8_t level)
Definition: tiny_types.c:41
void tiny_events_create(tiny_events_t *events)
void tiny_mutex_create(tiny_mutex_t *mutex)