ruuvi.drivers.c ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
Loading...
Searching...
No Matches
ruuvi_driver_error.h
Go to the documentation of this file.
1#ifndef RUUVI_DRIVER_ERROR_H
2#define RUUVI_DRIVER_ERROR_H
18#include <float.h>
19#include <math.h>
20#include <stdbool.h>
21#include <stdint.h>
22
23#define RD_FLOAT_INVALID NAN
24#define RD_UINT64_INVALID UINT64_MAX
25#define RD_INT64_INVALID INT64_MIN
26#define RD_INT32_INVALID INT32_MIN
27
28#define RD_SUCCESS (0U)
29#define RD_ERROR_INTERNAL (1U<<0U)
30#define RD_ERROR_NO_MEM (1U<<1U)
31#define RD_ERROR_NOT_FOUND (1U<<2U)
32#define RD_ERROR_NOT_SUPPORTED (1U<<3U)
33#define RD_ERROR_INVALID_PARAM (1U<<4U)
34#define RD_ERROR_INVALID_STATE (1U<<5U)
35#define RD_ERROR_INVALID_LENGTH (1U<<6U)
36#define RD_ERROR_INVALID_FLAGS (1U<<7U)
37#define RD_ERROR_INVALID_DATA (1U<<8U)
38#define RD_ERROR_DATA_SIZE (1U<<9U)
39#define RD_ERROR_TIMEOUT (1U<<10U)
40#define RD_ERROR_NULL (1U<<11U)
41#define RD_ERROR_FORBIDDEN (1U<<12U)
42#define RD_ERROR_INVALID_ADDR (1U<<13U)
43#define RD_ERROR_BUSY (1U<<14U)
44#define RD_ERROR_RESOURCES (1U<<15U)
45#define RD_ERROR_NOT_IMPLEMENTED (1U<<16U)
46#define RD_ERROR_SELFTEST (1U<<17U)
47#define RD_STATUS_MORE_AVAILABLE (1U<<18U)
48#define RD_ERROR_NOT_INITIALIZED (1U<<19U)
49#define RD_ERROR_NOT_ACKNOWLEDGED (1U<<20U)
50#define RD_ERROR_NOT_ENABLED (1U<<21U)
51#define RD_WARNING_DEPRECATED (1U<<22U)
52#define RD_ERROR_FATAL (1U<<31U)
53
54typedef uint32_t rd_status_t;
55
69void rd_error_check (const rd_status_t error,
70 const rd_status_t non_fatal_mask, const char * p_file, const int line);
71
83#define RD_ERROR_CHECK(error, mask) rd_error_check(error, mask, __FILE__, __LINE__)
84
85/*
86 * @brief reset global error flags and return their value.
87 *
88 * @return errors occured after last call to this function.
89 */
91
92/* @brief Application callback on error
93 *
94 * If this callback is set, it will get called on error.
95 *
96 * @param[in] error Type of error
97 * @param[in] fatal True if error is considered non-recoverable
98 * @param[in] file Pointer to name of file where error occured
99 * @param[in] line line where error occured
100 */
101typedef void (*rd_error_cb) (const rd_status_t error,
102 const bool fatal,
103 const char * file,
104 const int line);
105
112
114#endif
void rd_error_cb_set(rd_error_cb cb)
Configure application callback for errors.
uint32_t rd_status_t
bitfield for representing errors
void(* rd_error_cb)(const rd_status_t error, const bool fatal, const char *file, const int line)
void rd_error_check(rd_status_t error, rd_status_t non_fatal_mask, const char *file, int line)
Check given error code and compare it to non-fatal errors.
rd_status_t rd_errors_clear()