112 lines
2.1 KiB
C
Executable File
112 lines
2.1 KiB
C
Executable File
#include <stdatomic.h>
|
|
|
|
#include <di/stdio.h>
|
|
#include <di/time.h>
|
|
#include <di/device.h>
|
|
#include <di/log.h>
|
|
#include <di/device/lock.h>
|
|
|
|
static const char *g_type = NULL;
|
|
static uint32_t g_board_rev = 0;
|
|
static uint8_t g_board_minor = 0;
|
|
static bool g_board_is_strapped = false;
|
|
static enum di_device_redundant_roles g_board_redundant_role = DI_DEVICE_REDUNDANT_ROLE_PASSIVE;
|
|
|
|
void di_device_init(void)
|
|
{
|
|
di_time_init();
|
|
di_device_lock_init();
|
|
di_device_error_reset_all();
|
|
}
|
|
|
|
void di_device_set_type(const char *type)
|
|
{
|
|
g_type = type;
|
|
}
|
|
|
|
const char *di_device_get_type(void)
|
|
{
|
|
return g_type;
|
|
}
|
|
|
|
void di_device_set_board_revision(uint32_t rev)
|
|
{
|
|
g_board_rev = rev;
|
|
}
|
|
|
|
uint32_t di_device_get_board_revision(void)
|
|
{
|
|
return g_board_rev;
|
|
}
|
|
|
|
void di_device_set_board_minor(const uint8_t minor)
|
|
{
|
|
g_board_minor = minor;
|
|
}
|
|
|
|
uint8_t di_device_get_board_minor(void)
|
|
{
|
|
return g_board_minor;
|
|
}
|
|
|
|
void di_device_get_board_version_str(char *version, const size_t n)
|
|
{
|
|
di_snprintf(version, n, "%d.%d", g_board_rev, g_board_minor);
|
|
}
|
|
|
|
void di_device_set_board_is_strapped(bool strapped)
|
|
{
|
|
g_board_is_strapped = strapped;
|
|
}
|
|
|
|
bool di_device_get_board_is_strapped(void)
|
|
{
|
|
return g_board_is_strapped;
|
|
}
|
|
|
|
void di_device_set_board_redundant_role(enum di_device_redundant_roles role)
|
|
{
|
|
g_board_redundant_role = role;
|
|
}
|
|
|
|
enum di_device_redundant_roles di_device_get_board_redundant_role(void)
|
|
{
|
|
return g_board_redundant_role;
|
|
}
|
|
|
|
bool di_device_board_has_redundant_role(enum di_device_redundant_roles role)
|
|
{
|
|
enum di_device_redundant_roles current_role;
|
|
|
|
current_role = di_device_get_board_redundant_role();
|
|
if (current_role == role)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
di_errno_t di_device_get_state_transition_error(enum di_device_state state)
|
|
{
|
|
di_errno_t ret = DNE_OPDENIED;
|
|
|
|
switch (state) {
|
|
case DI_DEVICE_STATE_SERVICE:
|
|
ret = DNE_FIRMWARE_DEVICE_SERVICE;
|
|
break;
|
|
case DI_DEVICE_STATE_IDLE:
|
|
ret = DNE_FIRMWARE_DEVICE_IDLE;
|
|
break;
|
|
case DI_DEVICE_STATE_ARMED:
|
|
ret = DNE_FIRMWARE_DEVICE_ARMED;
|
|
break;
|
|
case DI_DEVICE_STATE_ACTIVE:
|
|
ret = DNE_FIRMWARE_DEVICE_ACTIVE;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|