ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
Error reporting and handling

Functions and definitions for errors and error handling. More...

Files

file  ruuvi_nrf5_sdk15_error.h
 
file  ruuvi_driver_error.c
 Check given error code, log warning on non-fatal error and reset on fatal error.
 
file  ruuvi_driver_error.h
 Ruuvi error codes and error check function.
 

Macros

#define RD_FLOAT_INVALID   NAN
 Signal that value should not be used. More...
 
#define RD_UINT64_INVALID   UINT64_MAX
 Signal that value should not be used. More...
 
#define RD_INT64_INVALID   INT64_MIN
 Signal that value should not be used. More...
 
#define RD_INT32_INVALID   INT32_MIN
 Signal that value should not be used. More...
 
#define RD_SUCCESS   (0U)
 Internal Error. More...
 
#define RD_ERROR_INTERNAL   (1U<<0U)
 Internal Error. More...
 
#define RD_ERROR_NO_MEM   (1U<<1U)
 No Memory for operation. More...
 
#define RD_ERROR_NOT_FOUND   (1U<<2U)
 Not found. More...
 
#define RD_ERROR_NOT_SUPPORTED   (1U<<3U)
 Not supported. More...
 
#define RD_ERROR_INVALID_PARAM   (1U<<4U)
 Invalid Parameter. More...
 
#define RD_ERROR_INVALID_STATE   (1U<<5U)
 Invalid state, operation disallowed in this state. More...
 
#define RD_ERROR_INVALID_LENGTH   (1U<<6U)
 Invalid Length. More...
 
#define RD_ERROR_INVALID_FLAGS   (1U<<7U)
 Invalid Flags. More...
 
#define RD_ERROR_INVALID_DATA   (1U<<8U)
 Invalid Data. More...
 
#define RD_ERROR_DATA_SIZE   (1U<<9U)
 Invalid Data size. More...
 
#define RD_ERROR_TIMEOUT   (1U<<10U)
 Operation timed out. More...
 
#define RD_ERROR_NULL   (1U<<11U)
 Null Pointer. More...
 
#define RD_ERROR_FORBIDDEN   (1U<<12U)
 Forbidden Operation. More...
 
#define RD_ERROR_INVALID_ADDR   (1U<<13U)
 Bad Memory Address. More...
 
#define RD_ERROR_BUSY   (1U<<14U)
 Busy. More...
 
#define RD_ERROR_RESOURCES   (1U<<15U)
 Not enough resources for operation. More...
 
#define RD_ERROR_NOT_IMPLEMENTED   (1U<<16U)
 Not implemented yet. More...
 
#define RD_ERROR_SELFTEST   (1U<<17U)
 Self-test fail. More...
 
#define RD_STATUS_MORE_AVAILABLE   (1U<<18U)
 Driver has more data queued. More...
 
#define RD_ERROR_NOT_INITIALIZED   (1U<<19U)
 Driver is not initialized. More...
 
#define RD_ERROR_NOT_ACKNOWLEDGED   (1U<<20U)
 Ack was expected but not received. More...
 
#define RD_ERROR_NOT_ENABLED   (1U<<21U)
 Driver is not enabled. More...
 
#define RD_WARNING_DEPRECATED   (1U<<22U)
 Deprecated function, warn user. More...
 
#define RD_ERROR_FATAL   (1U<<31U)
 Program should always reset after this. More...
 
#define RD_ERROR_CHECK(error, mask)   rd_error_check(error, mask, __FILE__, __LINE__)
 Shorthand macro for calling the rd_error_check with current file & line. More...
 

Typedefs

typedef uint32_t rd_status_t
 bitfield for representing errors More...
 
typedef void(* rd_error_cb) (const rd_status_t error, const bool fatal, const char *file, const int line)
 

Functions

rd_status_t ruuvi_nrf5_sdk15_to_ruuvi_error (const ret_code_t error)
 convert nrf5 sdk15 error code into Ruuvi error code. More...
 
void rd_error_check (const rd_status_t error, const rd_status_t non_fatal_mask, const char *p_file, const int line)
 Check given error code and compare it to non-fatal errors. More...
 
rd_status_t rd_errors_clear ()
 
void rd_error_cb_set (rd_error_cb cb)
 Configure application callback for errors. More...
 

Detailed Description

Functions and definitions for errors and error handling.

Macro Definition Documentation

◆ RD_ERROR_BUSY

#define RD_ERROR_BUSY   (1U<<14U)

Busy.

Definition at line 43 of file ruuvi_driver_error.h.

◆ RD_ERROR_CHECK

#define RD_ERROR_CHECK (   error,
  mask 
)    rd_error_check(error, mask, __FILE__, __LINE__)

Shorthand macro for calling the rd_error_check with current file & line.

If error is considered fatal (or not non-fatal), reset the device If the error is non-fatal, log an error on the console and return Resetting requires that APPLICATION_POWER_ENABLED evaluates to true and is implemented on platform. Logging requires that APPLICATION_LOG_ENABLED evaluates to true and is implemented on platform.

Parameters
[in]errorerror code, might have several flags in it.
[in]maskSignal that this error is acceptable for program flow and execution may continue.

Definition at line 83 of file ruuvi_driver_error.h.

◆ RD_ERROR_DATA_SIZE

#define RD_ERROR_DATA_SIZE   (1U<<9U)

Invalid Data size.

Definition at line 38 of file ruuvi_driver_error.h.

◆ RD_ERROR_FATAL

#define RD_ERROR_FATAL   (1U<<31U)

Program should always reset after this.

Definition at line 52 of file ruuvi_driver_error.h.

◆ RD_ERROR_FORBIDDEN

#define RD_ERROR_FORBIDDEN   (1U<<12U)

Forbidden Operation.

Definition at line 41 of file ruuvi_driver_error.h.

◆ RD_ERROR_INTERNAL

#define RD_ERROR_INTERNAL   (1U<<0U)

Internal Error.

Definition at line 29 of file ruuvi_driver_error.h.

◆ RD_ERROR_INVALID_ADDR

#define RD_ERROR_INVALID_ADDR   (1U<<13U)

Bad Memory Address.

Definition at line 42 of file ruuvi_driver_error.h.

◆ RD_ERROR_INVALID_DATA

#define RD_ERROR_INVALID_DATA   (1U<<8U)

Invalid Data.

Definition at line 37 of file ruuvi_driver_error.h.

◆ RD_ERROR_INVALID_FLAGS

#define RD_ERROR_INVALID_FLAGS   (1U<<7U)

Invalid Flags.

Definition at line 36 of file ruuvi_driver_error.h.

◆ RD_ERROR_INVALID_LENGTH

#define RD_ERROR_INVALID_LENGTH   (1U<<6U)

Invalid Length.

Definition at line 35 of file ruuvi_driver_error.h.

◆ RD_ERROR_INVALID_PARAM

#define RD_ERROR_INVALID_PARAM   (1U<<4U)

Invalid Parameter.

Definition at line 33 of file ruuvi_driver_error.h.

◆ RD_ERROR_INVALID_STATE

#define RD_ERROR_INVALID_STATE   (1U<<5U)

Invalid state, operation disallowed in this state.

Definition at line 34 of file ruuvi_driver_error.h.

◆ RD_ERROR_NO_MEM

#define RD_ERROR_NO_MEM   (1U<<1U)

No Memory for operation.

Definition at line 30 of file ruuvi_driver_error.h.

◆ RD_ERROR_NOT_ACKNOWLEDGED

#define RD_ERROR_NOT_ACKNOWLEDGED   (1U<<20U)

Ack was expected but not received.

Definition at line 49 of file ruuvi_driver_error.h.

◆ RD_ERROR_NOT_ENABLED

#define RD_ERROR_NOT_ENABLED   (1U<<21U)

Driver is not enabled.

Definition at line 50 of file ruuvi_driver_error.h.

◆ RD_ERROR_NOT_FOUND

#define RD_ERROR_NOT_FOUND   (1U<<2U)

Not found.

Definition at line 31 of file ruuvi_driver_error.h.

◆ RD_ERROR_NOT_IMPLEMENTED

#define RD_ERROR_NOT_IMPLEMENTED   (1U<<16U)

Not implemented yet.

Definition at line 45 of file ruuvi_driver_error.h.

◆ RD_ERROR_NOT_INITIALIZED

#define RD_ERROR_NOT_INITIALIZED   (1U<<19U)

Driver is not initialized.

Definition at line 48 of file ruuvi_driver_error.h.

◆ RD_ERROR_NOT_SUPPORTED

#define RD_ERROR_NOT_SUPPORTED   (1U<<3U)

Not supported.

Definition at line 32 of file ruuvi_driver_error.h.

◆ RD_ERROR_NULL

#define RD_ERROR_NULL   (1U<<11U)

Null Pointer.

Definition at line 40 of file ruuvi_driver_error.h.

◆ RD_ERROR_RESOURCES

#define RD_ERROR_RESOURCES   (1U<<15U)

Not enough resources for operation.

Definition at line 44 of file ruuvi_driver_error.h.

◆ RD_ERROR_SELFTEST

#define RD_ERROR_SELFTEST   (1U<<17U)

Self-test fail.

Definition at line 46 of file ruuvi_driver_error.h.

◆ RD_ERROR_TIMEOUT

#define RD_ERROR_TIMEOUT   (1U<<10U)

Operation timed out.

Definition at line 39 of file ruuvi_driver_error.h.

◆ RD_FLOAT_INVALID

#define RD_FLOAT_INVALID   NAN

Signal that value should not be used.

Definition at line 23 of file ruuvi_driver_error.h.

◆ RD_INT32_INVALID

#define RD_INT32_INVALID   INT32_MIN

Signal that value should not be used.

Definition at line 26 of file ruuvi_driver_error.h.

◆ RD_INT64_INVALID

#define RD_INT64_INVALID   INT64_MIN

Signal that value should not be used.

Definition at line 25 of file ruuvi_driver_error.h.

◆ RD_STATUS_MORE_AVAILABLE

#define RD_STATUS_MORE_AVAILABLE   (1U<<18U)

Driver has more data queued.

Definition at line 47 of file ruuvi_driver_error.h.

◆ RD_SUCCESS

#define RD_SUCCESS   (0U)

Internal Error.

Definition at line 28 of file ruuvi_driver_error.h.

◆ RD_UINT64_INVALID

#define RD_UINT64_INVALID   UINT64_MAX

Signal that value should not be used.

Definition at line 24 of file ruuvi_driver_error.h.

◆ RD_WARNING_DEPRECATED

#define RD_WARNING_DEPRECATED   (1U<<22U)

Deprecated function, warn user.

Definition at line 51 of file ruuvi_driver_error.h.

Typedef Documentation

◆ rd_error_cb

typedef void(* rd_error_cb) (const rd_status_t error, const bool fatal, const char *file, const int line)

Definition at line 101 of file ruuvi_driver_error.h.

◆ rd_status_t

typedef uint32_t rd_status_t

bitfield for representing errors

Definition at line 54 of file ruuvi_driver_error.h.

Function Documentation

◆ rd_error_cb_set()

void rd_error_cb_set ( rd_error_cb  cb)

Configure application callback for errors.

Parameters
[in]cbCallback on error, NULL to clear callback

Definition at line 88 of file ruuvi_driver_error.c.

◆ rd_error_check()

void rd_error_check ( const rd_status_t  error,
const rd_status_t  non_fatal_mask,
const char *  p_file,
const int  line 
)

Check given error code and compare it to non-fatal errors.

If error is considered fatal (or not non-fatal), reset the device If the error is non-fatal, log an error on the console and return Resetting requires that APPLICATION_POWER_ENABLED evaluates to true and is implemented on platform. Logging requires that APPLICATION_LOG_ENABLED evaluates to true and is implemented on platform.

Parameters
[in]errorerror code, might have several flags in it.
[in]non_fatal_maskSignal that this error is acceptable for program flow and execution may continue.
[in]p_filefile from which function was called
[in]lineline from which the function was called

Definition at line 27 of file ruuvi_driver_error.c.

◆ rd_errors_clear()

rd_status_t rd_errors_clear ( )

Definition at line 81 of file ruuvi_driver_error.c.

◆ ruuvi_nrf5_sdk15_to_ruuvi_error()

rd_status_t ruuvi_nrf5_sdk15_to_ruuvi_error ( const ret_code_t  error)

convert nrf5 sdk15 error code into Ruuvi error code.

Parameters
[in]errorerror to convert
Returns
Ruuvi error corresponding to given error.