-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathesp32_hal.inl
108 lines (85 loc) · 2.71 KB
/
esp32_hal.inl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
Copyright 2019-2024 (C) Alexey Dynda
This file is part of Tiny Protocol Library.
GNU General Public License Usage
Protocol Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Protocol Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Protocol Library. If not, see <http://www.gnu.org/licenses/>.
Commercial License Usage
Licensees holding valid commercial Tiny Protocol licenses may use this file in
accordance with the commercial license agreement provided in accordance with
the terms contained in a written agreement between you and Alexey Dynda.
For further information contact via email on github account.
*/
#include "esp_timer.h"
void tiny_mutex_create(tiny_mutex_t *mutex)
{
*mutex = xSemaphoreCreateMutex();
}
void tiny_mutex_destroy(tiny_mutex_t *mutex)
{
vSemaphoreDelete(*mutex);
}
void tiny_mutex_lock(tiny_mutex_t *mutex)
{
xSemaphoreTake(*mutex, portMAX_DELAY);
}
uint8_t tiny_mutex_try_lock(tiny_mutex_t *mutex)
{
return xSemaphoreTake(*mutex, 0) == pdTRUE;
}
void tiny_mutex_unlock(tiny_mutex_t *mutex)
{
xSemaphoreGive(*mutex);
}
void tiny_events_create(tiny_events_t *events)
{
*events = xEventGroupCreate();
}
void tiny_events_destroy(tiny_events_t *events)
{
vEventGroupDelete(*events);
}
uint8_t tiny_events_wait(tiny_events_t *events, uint8_t bits, uint8_t clear, uint32_t timeout)
{
return xEventGroupWaitBits(*events, bits, clear ? pdTRUE : pdFALSE, pdFALSE, timeout / portTICK_PERIOD_MS) & bits;
}
uint8_t tiny_events_check_int(tiny_events_t *event, uint8_t bits, uint8_t clear)
{
return tiny_events_wait(event, bits, clear, 0);
}
void tiny_events_set(tiny_events_t *events, uint8_t bits)
{
xEventGroupSetBits(*events, bits);
}
void tiny_events_clear(tiny_events_t *events, uint8_t bits)
{
xEventGroupClearBits(*events, bits);
}
void tiny_sleep(uint32_t millis)
{
vTaskDelay(millis / portTICK_PERIOD_MS);
}
void tiny_sleep_us(uint32_t us)
{
uint32_t start = tiny_micros();
while ( (uint32_t)(tiny_micros() - start) < us )
{
__asm__ __volatile__ ("nop\n\t");
}
}
uint32_t tiny_millis()
{
return (uint32_t)(esp_timer_get_time() / 1000);
}
uint32_t tiny_micros()
{
return (uint32_t)(esp_timer_get_time());
}