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