Tiny protocol  0.11.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 #elif defined(_WIN32)
44 #include "include/win32_hal.h"
45 #else
46 #info "Platform not supported. Multithread support is disabled"
47 #include "include/no_platform_hal.h"
48 #endif
49 
50 #include <stdint.h>
51 
53 #ifdef CONFIG_ENABLE_FCS32
54  typedef uint32_t fcs_t;
55 #else
56  typedef uint16_t fcs_t;
57 #endif
58 
64 #define TINY_SUCCESS (0)
66 #define TINY_ERR_FAILED (-1)
68 #define TINY_ERR_TIMEOUT (-2)
70 #define TINY_ERR_DATA_TOO_LARGE (-3)
72 #define TINY_ERR_INVALID_DATA (-4)
74 #define TINY_ERR_BUSY (-5)
76 #define TINY_ERR_OUT_OF_SYNC (-6)
78 #define TINY_ERR_AGAIN (-7)
80 #define TINY_ERR_WRONG_CRC (-8)
82 
90 #define TINY_FLAG_NO_WAIT (0)
92 #define TINY_FLAG_READ_ALL (1)
94 #define TINY_FLAG_LOCK_SEND (2)
96 #define TINY_FLAG_WAIT_FOREVER (0x80)
98 
105 typedef struct
106 {
108  uint32_t oosyncBytes;
110  uint32_t bytesSent;
112  uint32_t bytesReceived;
114  uint32_t framesSent;
116  uint32_t framesReceived;
118  uint32_t framesBroken;
119 } STinyStats;
120 
130 typedef int (*write_block_cb_t)(void *pdata, const void *buffer, int size);
131 
141 typedef int (*read_block_cb_t)(void *pdata, void *buffer, int size);
142 
143 
154 typedef void (*on_frame_cb_t)(void *handle, uint16_t uid, uint8_t *pdata, int size);
155 
156 #define EVENT_BIS_ALL 0xFF
157 #define EVENT_BITS_CLEAR 1
158 #define EVENT_BITS_LEAVE 0
159 
160 
164 void tiny_mutex_create(tiny_mutex_t *mutex);
165 
170 void tiny_mutex_destroy(tiny_mutex_t *mutex);
171 
176 void tiny_mutex_lock(tiny_mutex_t *mutex);
177 
184 uint8_t tiny_mutex_try_lock(tiny_mutex_t *mutex);
185 
190 void tiny_mutex_unlock(tiny_mutex_t *mutex);
191 
196 void tiny_events_create(tiny_events_t *events);
197 
202 void tiny_events_destroy(tiny_events_t *events);
203 
213 uint8_t tiny_events_wait(tiny_events_t *event, uint8_t bits,
214  uint8_t clear, uint32_t timeout);
215 
225 uint8_t tiny_events_check_int(tiny_events_t *event, uint8_t bits, uint8_t clear);
226 
232 void tiny_events_set(tiny_events_t *event, uint8_t bits);
233 
239 void tiny_events_clear(tiny_events_t *event, uint8_t bits);
240 
245 void tiny_sleep(uint32_t ms);
246 
250 uint32_t tiny_millis();
251 
256 void tiny_log_level(uint8_t level);
257 
258 #ifdef __cplusplus
259 }
260 #endif
261 
void tiny_mutex_destroy(tiny_mutex_t *mutex)
uint32_t framesBroken
Number of broken frames received.
Definition: tiny_types.h:118
uint32_t bytesReceived
Number of payload bytes totally received through the channel.
Definition: tiny_types.h:112
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:114
void tiny_events_clear(tiny_events_t *event, uint8_t bits)
Definition: tiny_types.h:105
uint32_t tiny_millis()
int(* read_block_cb_t)(void *pdata, void *buffer, int size)
Definition: tiny_types.h:141
void(* on_frame_cb_t)(void *handle, uint16_t uid, uint8_t *pdata, int size)
Definition: tiny_types.h:154
uint32_t framesReceived
Number of frames, successfully received through the communication channel.
Definition: tiny_types.h:116
uint32_t oosyncBytes
Number of bytes received out of frame bytes.
Definition: tiny_types.h:108
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:130
void tiny_events_destroy(tiny_events_t *events)
uint8_t tiny_events_check_int(tiny_events_t *event, uint8_t bits, uint8_t clear)
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:110
void tiny_log_level(uint8_t level)
Definition: tiny_types.c:43
void tiny_events_create(tiny_events_t *events)
void tiny_mutex_create(tiny_mutex_t *mutex)