API Documentation¶
-
struct
sc_error_data
¶ - #include <sc_error.h>
Representation of a single error type. Each error must be unique in the system.
-
struct
sc_error_module_data
¶
-
struct
sc_event_type_t
¶
-
file
sc.h
- #include <stdint.h>#include <stdbool.h>#include <stdio.h>#include <string.h>#include “sc_event.h”#include “sc_error.h”#include “sc_sensor.h”#include <zephyr.h>
Typedefs
-
typedef enum SC_THREAD_PRIORITY
SC_THREAD_PRIORITY
Enums
-
typedef enum SC_THREAD_PRIORITY
-
file
sc_error.h
- #include “sc.h”
Error logging and tracking.
All logged errors in the system must be unique. The error logging and tracking module keeps track of the number of each error and provides the timestamp of the last occurance.
Typedefs
-
typedef struct sc_error_data
sc_error_data
Representation of a single error type. Each error must be unique in the system.
Functions
-
bool
sc_error_register
(char *name, sc_error_data *data, uint8_t data_size, uint8_t *module)¶ Register errors for a module.
- Parameters
name
: Name of the module.data
: An array of errors for the module. The error struct fields must be initialized to zero except for the message that must be the name of the error.data_size
: Number of error elements in the data array.module
: The index number of the module. This must be called when logging the actual errors. This is only set if the registration succeeds.
- Return Value
true
: if successful.false
: if failed.
-
void
sc_error_log
(uint8_t module, uint8_t error)¶ Log an error.
The module must be acquired first by calling sc_error_register.
- Parameters
module
: Index of the module.error
: Index of the error in the module’s error list passed to sc_error_register.
- Return Value
true
: if successful.false
: if failed.
-
void
sc_error_log_int
(uint8_t module, uint8_t error, uint32_t param)¶ Log an error with one integer parameter.
Same as sc_error_log but with additional integered parameter. The module must be acquired first by calling sc_error_register.
- Parameters
module
: Index of the module.error
: Index of the error in the module’s error list passed to sc_error_register.param
: Integer variable to be printed as a part of the error message.
- Return Value
true
: if successful.false
: if failed.
-
typedef struct sc_error_data
-
file
sc_event.h
- #include “sc.h”
Event Loop.
The event loop implements the asynchronous core logic of the framework. It enables different drivers and tasks to run asynchronously and notify the main application once there is an event to react to.
Typedefs
-
typedef void (*
sc_event_cb
)(void)¶ Callback for an event
Functions
-
bool
sc_event_init
(void)¶ Initialize the event loop.
Must be called before initializing other subsystems.
- Return Value
true
: if successful.false
: if failed.
-
bool
sc_event_post
(uint8_t type)¶ Post an event.
The type must be registered first with sc_event_register_type (TODO: link)
- Parameters
type
: Event type.
- Return Value
true
: if successful.false
: if failed.
-
bool
sc_event_register_type
(const char *name, uint8_t *type)¶ Register a type.
Calling this function will return an index for the type. If one did not exist yet, it was registered. If it was already registered, the index of that event is returned.
- Parameters
name
: Name of the event. The name must be a well-known name between the caller and the callee.type
: Index the type is returned in this pointer if the retval is true.
- Return Value
true
: if successful.false
: if failed.
-
bool
sc_event_register_cb
(uint8_t type, sc_event_cb func)¶ Register a callback for an event type.
The callback will be called from the Event Loop’s thread. The callback must return as soon as possible to unblock handling of other events.
The type must be registered first with sc_event_register_type (TODO: link)
- Parameters
type
: Event type.func
: Callback function.
- Return Value
true
: if successful.false
: if failed.
-
bool
sc_event_register_type_cb
(const char *name, sc_event_cb func)¶ A convenience function to register and event and assign a callback.
Internally this calls first sc_event_register_type() and then sc_event_register_cb(). Event type is not returned.
- Return Value
true
: if successful.false
: if failed.
-
typedef void (*
-
file
sc_sensor.h
Sensor framework for Zephyr’s sensor API.
Support multiple sensors using Zephyr’s sensor API. Provide events to the main application using the event thread so that the main application doesn’t need to care about thread safety in its implementation.
-
file
main-sht3x.c
- #include “sc.h”#include <misc/printk.h>#include <sensor.h>
Typedefs
-
typedef enum sc_error_main
sc_error_main
Enums
Variables
-
sc_error_data
sc_error_list1
[SC_ERROR_MAIN_COUNT
] = { {0, 0, "sc_event_post failed"},}¶
-
uint8_t
sht3x_index
¶
-
typedef enum sc_error_main
-
file
main-test.c
- #include “sc.h”#include <misc/printk.h>
Typedefs
-
typedef enum sc_error_main
sc_error_main
Enums
-
enum
sc_error_main
Values:
-
SC_ERROR_MAIN_EVENT_POST_FAIL
= 0
-
SC_ERROR_MAIN_COUNT
-
SC_ERROR_MAIN_EVENT_POST_FAIL
= 0
-
SC_ERROR_MAIN_COUNT
-
Variables
-
sc_error_data
sc_error_list1
[SC_ERROR_MAIN_COUNT
] = { {0, 0, "sc_event_post failed"},}
-
typedef enum sc_error_main
-
file
sc.c
- #include “sc.h”#include <shell/shell.h>
Functions
-
bool
sc_init
(uint32_t subsystems)
-
void
sc_halt
(void)
-
bool
-
file
sc_error.c
- #include “sc_error.h”#include <misc/printk.h>
Defines
-
SC_ERROR_MODULE_MAX
¶
Typedefs
-
typedef struct sc_error_module_data
sc_error_module_data
Functions
-
static void
sc_error_log_ext
(uint8_t module, uint8_t error, bool has_param, uint32_t param)¶
-
K_MUTEX_DEFINE
(sc_error_module_data_mutex)¶
-
bool
sc_error_register
(char *name, sc_error_data *data, uint8_t data_size, uint8_t *module) Register errors for a module.
- Parameters
name
: Name of the module.data
: An array of errors for the module. The error struct fields must be initialized to zero except for the message that must be the name of the error.data_size
: Number of error elements in the data array.module
: The index number of the module. This must be called when logging the actual errors. This is only set if the registration succeeds.
- Return Value
true
: if successful.false
: if failed.
-
void
sc_error_log
(uint8_t module, uint8_t error) Log an error.
The module must be acquired first by calling sc_error_register.
- Parameters
module
: Index of the module.error
: Index of the error in the module’s error list passed to sc_error_register.
- Return Value
true
: if successful.false
: if failed.
-
void
sc_error_log_int
(uint8_t module, uint8_t error, uint32_t param) Log an error with one integer parameter.
Same as sc_error_log but with additional integered parameter. The module must be acquired first by calling sc_error_register.
- Parameters
module
: Index of the module.error
: Index of the error in the module’s error list passed to sc_error_register.param
: Integer variable to be printed as a part of the error message.
- Return Value
true
: if successful.false
: if failed.
Variables
-
sc_error_module_data
sc_error_module_data_list
[SC_ERROR_MODULE_MAX
]¶
-
-
file
sc_event.c
- #include “sc.h”#include <string.h>
Enums
-
enum
sc_error_event
¶ Values:
-
SC_ERROR_EVENT_K_MSGQ_GET
= 0¶
-
SC_ERROR_EVENT_LOOP_UNKNOWN_EVENT
¶
-
SC_ERROR_EVENT_POST_UNKNOWN_EVENT
¶
-
SC_ERROR_EVENT_NO_CALLBACK
¶
-
SC_ERROR_EVENT_MSGQ_PUT
¶
-
SC_ERROR_EVENT_GET_INVALID_PARAMETER
¶
-
SC_ERROR_EVENT_GET_MODULE_OVERFLOW
¶
-
SC_ERROR_EVENT_NOT_INITIALIZED
¶
-
SC_ERROR_EVENT_REGCB_MODULE_UNKNOWN
¶
-
SC_ERROR_EVENT_REGCB_ALREADY_REGISTERED
¶
-
SC_ERROR_EVENT_COUNT
¶
-
Functions
-
K_MUTEX_DEFINE
(sc_event_data_mutex)¶
-
K_MSGQ_DEFINE(sc_event_msgq, sizeof(uint32_t), SC_EVENT_QUEUE_SIZE, 4)
-
void
sc_event_loop
(void *arg1, void *arg2, void *arg3)¶
-
K_THREAD_DEFINE
(sc_event_thread, SC_EVENT_THREAD_STACK_SIZE, sc_event_loop, NULL, NULL, NULL, SC_THREAD_PRIORITY_HIGH, K_ESSENTIAL, K_NO_WAIT)¶
-
bool
sc_event_init
(void) Initialize the event loop.
Must be called before initializing other subsystems.
- Return Value
true
: if successful.false
: if failed.
-
bool
sc_event_post
(uint8_t type) Post an event.
The type must be registered first with sc_event_register_type (TODO: link)
- Parameters
type
: Event type.
- Return Value
true
: if successful.false
: if failed.
-
bool
sc_event_register_type
(const char *name, uint8_t *type) Register a type.
Calling this function will return an index for the type. If one did not exist yet, it was registered. If it was already registered, the index of that event is returned.
- Parameters
name
: Name of the event. The name must be a well-known name between the caller and the callee.type
: Index the type is returned in this pointer if the retval is true.
- Return Value
true
: if successful.false
: if failed.
-
bool
sc_event_register_cb
(uint8_t type, sc_event_cb func) Register a callback for an event type.
The callback will be called from the Event Loop’s thread. The callback must return as soon as possible to unblock handling of other events.
The type must be registered first with sc_event_register_type (TODO: link)
- Parameters
type
: Event type.func
: Callback function.
- Return Value
true
: if successful.false
: if failed.
-
bool
sc_event_register_type_cb
(const char *name, sc_event_cb func) A convenience function to register and event and assign a callback.
Internally this calls first sc_event_register_type() and then sc_event_register_cb(). Event type is not returned.
- Return Value
true
: if successful.false
: if failed.
Variables
-
sc_error_data
sc_error_list
[SC_ERROR_EVENT_COUNT
] = { {0, 0, "k_msgq_get failed"}, {0, 0, "loop: unknown event"}, {0, 0, "post: unknown event"}, {0, 0, "no callback function set"}, {0, 0, "k_msgq_put failed"}, {0, 0, "get: invalid parameter"}, {0, 0, "get: module overflow"}, {0, 0, "not initialized"}, {0, 0, "reg_cb: module overflow"}, {0, 0, "reg_cb: already registered"},}¶
-
uint8_t
error_module
¶
-
sc_event_type
sc_event_type_list
[SC_EVENT_MAX_TYPE
]¶
-
bool
is_initialized
= false¶
-
enum
-
file
sc_sensor.c
- #include “sc_sensor.h”
-
group
sc_error
Typedefs
-
typedef struct sc_error_data
sc_error_data
Representation of a single error type. Each error must be unique in the system.
-
typedef struct sc_error_data
-
group
sc_event_loop
Typedefs
-
typedef void (*
sc_event_cb
)(void) Callback for an event
-
typedef void (*
-
dir
include
-
dir
src