acc_integration.h
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2019-2023
2 // All rights reserved
3
4 #ifndef ACC_INTEGRATION_H_
5 #define ACC_INTEGRATION_H_
6
7 #include <stdbool.h>
8 #include <stdint.h>
9 #include <stdlib.h>
10
11
12 typedef void (*acc_integration_uart_read_func_t)(uint8_t data, uint32_t status);
13
14
15 /**
16 * @brief Sleep for a specified number of microseconds
17 *
18 * @param time_usec Time in microseconds to sleep
19 */
20 void acc_integration_sleep_us(uint32_t time_usec);
21
22
23 /**
24 * @brief Sleep for a specified number of milliseconds
25 *
26 * @param time_msec Time in milliseconds to sleep
27 */
28 void acc_integration_sleep_ms(uint32_t time_msec);
29
30
31 /**
32 * @brief Set up a periodic timer used to wake up the system from sleep
33 *
34 * This function will start a periodic timer with the specified time.
35 * This is useful when the drift of the wakeup interval should be kept
36 * at a minimum.
37 *
38 * If the time_msec is set to zero the periodic wakeup will be disabled.
39 *
40 * @param time_msec Time in milliseconds
41 */
42 void acc_integration_set_periodic_wakeup(uint32_t time_msec);
43
44
45 /**
46 * @brief Put the system in sleep until the periodic timer triggers
47 *
48 * The periodic timer must be started using
49 * @ref acc_integration_set_periodic_wakeup prior to
50 * invoking this function.
51 * The target specific implementation of this function will determine
52 * the sleep depth based on the set sleep interval and it will be a
53 * trade-off between wake-up latency and power consumption.
54 */
55 void acc_integration_sleep_until_periodic_wakeup(void);
56
57
58 /**
59 * @brief Allocate dynamic memory
60 *
61 * @param[in] size The bytesize of the reuested memory block
62 * @return Returns either NULL or a unique pointer to a memory block
63 */
64 void *acc_integration_mem_alloc(size_t size);
65
66
67 /**
68 * @brief Allocate dynamic memory
69 *
70 * Allocate an array of nmemb elements of size bytes each.
71 *
72 * @param[in] nmemb The number of elements in the array
73 * @param[in] size The bytesize of the element
74 * @return Returns either NULL or a unique pointer to a memory block
75 */
76 void *acc_integration_mem_calloc(size_t nmemb, size_t size);
77
78
79 /**
80 * @brief Free dynamic memory
81 *
82 * @param[in] ptr A pointer to the memory space to be freed
83 */
84 void acc_integration_mem_free(void *ptr);
85
86
87 /**
88 * Enter a critical section
89 */
90 void acc_integration_critical_section_enter(void);
91
92
93 /**
94 * Exit a critical section
95 */
96 void acc_integration_critical_section_exit(void);
97
98
99 /**
100 * @brief Get current time
101 *
102 * It is important that this value wraps correctly and uses all bits. I.e. it should count
103 * upwards to 2^32 - 1 and then 0 again.
104 *
105 * @returns Current time as milliseconds
106 */
107 uint32_t acc_integration_get_time(void);
108
109
110 #endif
acc_integration_mem_calloc
void * acc_integration_mem_calloc(size_t nmemb, size_t size)
Allocate dynamic memory.
Definition: acc_integration_stm32.c:638
acc_integration_get_time
uint32_t acc_integration_get_time(void)
Get current time.
Definition: acc_integration_stm32.c:626
acc_integration_sleep_us
void acc_integration_sleep_us(uint32_t time_usec)
Sleep for a specified number of microseconds.
Definition: acc_integration_stm32.c:507
acc_integration_uart_read_func_t
void(* acc_integration_uart_read_func_t)(uint8_t data, uint32_t status)
Definition: acc_integration.h:12
acc_integration_critical_section_exit
void acc_integration_critical_section_exit(void)
Definition: acc_integration_cortex.c:18
acc_integration_mem_alloc
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
Definition: acc_integration_stm32.c:632
acc_integration_set_periodic_wakeup
void acc_integration_set_periodic_wakeup(uint32_t time_msec)
Set up a periodic timer used to wake up the system from sleep.
Definition: acc_integration_stm32.c:531
acc_integration_sleep_ms
void acc_integration_sleep_ms(uint32_t time_msec)
Sleep for a specified number of milliseconds.
Definition: acc_integration_stm32.c:501
acc_integration_mem_free
void acc_integration_mem_free(void *ptr)
Free dynamic memory.
Definition: acc_integration_stm32.c:644
acc_integration_critical_section_enter
void acc_integration_critical_section_enter(void)
Definition: acc_integration_cortex.c:10
acc_integration_sleep_until_periodic_wakeup
void acc_integration_sleep_until_periodic_wakeup(void)
Put the system in sleep until the periodic timer triggers.
Definition: acc_integration_stm32.c:590