![]() |
Pico Core
|
Harp Core that handles management of common bank registers. Implemented as a singleton to simplify attaching interrupt callbacks (and since you can only have one per device.) More...
#include <harp_core.h>
Public Member Functions | |
HarpCore ()=delete | |
HarpCore (HarpCore &other)=delete | |
void | operator= (const HarpCore &other)=delete |
void | run () |
Periodically handle tasks based on the current time, state, and inputs. Should be called in a loop. Calls tud_task() and process_cdc_input(). | |
msg_header_t & | get_buffered_msg_header () |
return a reference to the message header in the rx_buffer_. | |
msg_t | get_buffered_msg () |
return a reference to the message in the rx_buffer_. Inline. | |
bool | new_msg () |
flag indicating whether or not a new message is in the rx_buffer_. | |
void | clear_msg () |
flag that new message has been handled. Inline. | |
Static Public Member Functions | |
static HarpCore & | init (uint16_t who_am_i, uint8_t hw_version_major, uint8_t hw_version_minor, uint8_t assembly_version, uint8_t harp_version_major, uint8_t harp_version_minor, uint8_t fw_version_major, uint8_t fw_version_minor, uint16_t serial_number, const char name[], const uint8_t tag[]) |
initialize the harp core singleton with parameters and init Tinyusb. | |
static HarpCore & | instance () |
returns the singleton. | |
static void | write_reg_generic (msg_t &msg) |
generic handler function to write a message payload to a core or app register and issue a harp reply (unless is_muted()). | |
static void | read_reg_generic (uint8_t reg_name) |
generic handler function to read a message payload to a core or app register and issue a harp reply (unless is_muted()). | |
static void | write_to_read_only_reg_error (msg_t &msg) |
write handler function. Sends a harp reply indicating a write error to the specified register. | |
static void | copy_msg_payload_to_register (msg_t &msg) |
update local (app or core) register data with the payload provided in the input msg. | |
static void | send_harp_reply (msg_type_t reply_type, uint8_t reg_name, const volatile uint8_t *data, uint8_t num_bytes, reg_type_t payload_type, uint64_t harp_time_us) |
Construct and send a Harp-compliant timestamped reply message from provided arguments. | |
static void | send_harp_reply (msg_type_t reply_type, uint8_t reg_name, const volatile uint8_t *data, uint8_t num_bytes, reg_type_t payload_type) |
Construct and send a Harp-compliant timestamped reply message from provided arguments. Timestamp is generated automatically at the time this function is called. | |
static void | send_harp_reply (msg_type_t reply_type, uint8_t reg_name) |
Construct and send a Harp-compliant timestamped reply message where payload data is written from the specified register. | |
static void | send_harp_reply (msg_type_t reply_type, uint8_t reg_name, uint64_t harp_time_us) |
Send a Harp-compliant reply with a specific timestamp. | |
static bool | is_muted () |
true if the mute flag has been set in the R_OPERATION_CTRL register. | |
static bool | is_synced () |
true if the device is synchronized via external CLKIN input. | |
static bool | events_enabled () |
true if the "events enabled" flag has been set in the R_OPERATION_CTRL register. | |
static uint64_t | harp_time_us_64 () |
get the total elapsed microseconds (64-bit) in "Harp" time. | |
static uint32_t | harp_time_s () |
get the current elapsed seconds in "Harp" time. | |
static uint64_t | harp_to_system_us_64 (uint64_t harp_time_us) |
convert harp time (in 64-bit microseconds) to local system time (in 64-bit microseconds). | |
static uint32_t | harp_to_system_us_32 (uint64_t harp_time_us) |
convert harp time (in 32-bit microseconds) to local system time (in 32-bit microseconds). | |
static uint64_t | system_to_harp_us_64 (uint64_t system_time_us) |
convert system time (in 64-bit microseconds) to local system time (in 64-bit microseconds). | |
static void | set_harp_time_us_64 (uint64_t harp_time_us) |
Override the current Harp time with a specific time. | |
static void | set_synchronizer (HarpSynchronizer *sync) |
attach a synchronizer. If the synchronizer is attached, then calls to harp_time_us_64() and harp_time_us_32() will reflect the synchronizer's time. | |
static void | set_visual_indicators_fn (void(*func)(bool)) |
attach a callback function to control external visual indicators (i.e: LEDs). | |
static void | force_state (op_mode_t next_state) |
force the op mode state. Useful to put the core in an error state. | |
static void | set_uuid (uint8_t *uuid, size_t num_bytes, size_t offset=0) |
set the 16 bytews in the R_UUID register. Any unspecified bytes will be set to zero. Usage: | |
Public Attributes | |
RegValues & | regs = regs_.regs_ |
reference to the struct of reg values for easy access. | |
Static Public Attributes | |
static HarpCore * | self = nullptr |
Protected Member Functions | |
HarpCore (uint16_t who_am_i, uint8_t hw_version_major, uint8_t hw_version_minor, uint8_t assembly_version, uint8_t harp_version_major, uint8_t harp_version_minor, uint8_t fw_version_major, uint8_t fw_version_minor, uint16_t serial_number, const char name[], const uint8_t tag[]) | |
~HarpCore () | |
void | handle_buffered_core_message () |
entry point for handling incoming harp messages to core registers. Dispatches message to the appropriate handler. | |
virtual void | handle_buffered_app_message () |
Handle incoming messages for the derived class. Does nothing here, but not pure virtual since we need to be able to instantiate a standalone harp core. | |
virtual void | update_app_state () |
update state of the derived class. Does nothing in the base class, but not pure virtual since we need to be able to instantiate a standalone harp core. | |
virtual void | reset_app () |
reset the app. Called when the writing to the RESET_DEF register. Does nothing in the base class, but not pure virtual since we need to be able to instantiate a standalone harp core. | |
void | set_visual_indicators (bool enabled) |
Enable or disable external virtual indicators. | |
virtual void | dump_app_registers () |
send one harp reply read message per app register. Called when the writing to the R_OPERATION_CTRL's DUMP bit. Does nothing in the base class, but not pure virtual since we need to be able to instantiate a standalone harp core. | |
virtual const RegSpecs & | address_to_app_reg_specs (uint8_t address) |
Protected Attributes | |
bool | new_msg_ |
flag indicating whether or not a new message is in the rx_buffer_. | |
void(* | set_visual_indicators_fn_ )(bool) |
function pointer to function that enables/disables visual indicators. | |
HarpSynchronizer * | sync_ |
function pointer to synchronizer if configured. | |
Harp Core that handles management of common bank registers. Implemented as a singleton to simplify attaching interrupt callbacks (and since you can only have one per device.)
|
protected |
|
protected |
|
delete |
|
delete |
|
inlineprotectedvirtual |
|
inline |
flag that new message has been handled. Inline.
|
inlinestatic |
update local (app or core) register data with the payload provided in the input msg.
|
inlineprotectedvirtual |
send one harp reply read message per app register. Called when the writing to the R_OPERATION_CTRL's DUMP bit. Does nothing in the base class, but not pure virtual since we need to be able to instantiate a standalone harp core.
|
inlinestatic |
true if the "events enabled" flag has been set in the R_OPERATION_CTRL register.
|
inlinestatic |
force the op mode state. Useful to put the core in an error state.
msg_t HarpCore::get_buffered_msg | ( | ) |
return a reference to the message in the rx_buffer_. Inline.
|
inline |
return a reference to the message header in the rx_buffer_.
|
inlineprotectedvirtual |
Handle incoming messages for the derived class. Does nothing here, but not pure virtual since we need to be able to instantiate a standalone harp core.
|
protected |
entry point for handling incoming harp messages to core registers. Dispatches message to the appropriate handler.
|
inlinestatic |
get the current elapsed seconds in "Harp" time.
|
inlinestatic |
get the total elapsed microseconds (64-bit) in "Harp" time.
Internally, an offset is tracked and updated where \(t_{Harp} = t_{local} - t_{offset} \)
|
inlinestatic |
convert harp time (in 32-bit microseconds) to local system time (in 32-bit microseconds).
this utility function is useful for setting alarms in the device's local time domain, which is monotonic and unchanged by adjustments to the harp time.
harp_time_us | the current time in microseconds |
|
inlinestatic |
convert harp time (in 64-bit microseconds) to local system time (in 64-bit microseconds).
this utility function is useful for setting alarms in the device's local time domain, which is monotonic and unchanged by adjustments to the harp time.
harp_time_us | the current time in microseconds |
|
static |
initialize the harp core singleton with parameters and init Tinyusb.
|
inlinestatic |
returns the singleton.
|
inlinestatic |
true if the mute flag has been set in the R_OPERATION_CTRL register.
|
inlinestatic |
true if the device is synchronized via external CLKIN input.
true if the device has received and handled at least one synchronization signal from its external CLKIN input. As implemented, this function will never return false after synchronizing at least once, but that may change later.
|
inline |
flag indicating whether or not a new message is in the rx_buffer_.
|
delete |
|
static |
generic handler function to read a message payload to a core or app register and issue a harp reply (unless is_muted()).
|
inlineprotectedvirtual |
reset the app. Called when the writing to the RESET_DEF register. Does nothing in the base class, but not pure virtual since we need to be able to instantiate a standalone harp core.
void HarpCore::run | ( | ) |
Periodically handle tasks based on the current time, state, and inputs. Should be called in a loop. Calls tud_task() and process_cdc_input().
|
inlinestatic |
Construct and send a Harp-compliant timestamped reply message where payload data is written from the specified register.
this function will lookup the particular core-or-app register's specs for the provided address and construct a reply based on those specs.
tud_task()
. reply_type | READ , WRITE , EVENT , READ_ERROR , or WRITE_ERROR enum. |
reg_name | address to mark the origin point of the data. |
|
inlinestatic |
Construct and send a Harp-compliant timestamped reply message from provided arguments. Timestamp is generated automatically at the time this function is called.
tud_task()
. reply_type | READ , WRITE , EVENT , READ_ERROR , or WRITE_ERROR enum. |
reg_name | address to mark the origin point of the data. |
data | pointer to payload content of the data. |
num_bytes | sizeof(data) |
payload_type | U8 , S8 , U16 , U32 , U64 , S64 , or Float enum. |
|
static |
Construct and send a Harp-compliant timestamped reply message from provided arguments.
tud_task()
. reply_type | READ , WRITE , EVENT , READ_ERROR , or WRITE_ERROR enum. |
reg_name | address to mark the origin point of the data. |
data | pointer to payload content of the data. |
num_bytes | sizeof(data) |
payload_type | U8 , S8 , U16 , U32 , U64 , S64 , or Float enum. |
harp_time_us | the harp time (in microseconds) to timestamp onto the outgoing message. |
|
inlinestatic |
Send a Harp-compliant reply with a specific timestamp.
tud_task()
. reply_type | READ , WRITE , EVENT , READ_ERROR , or WRITE_ERROR enum. |
reg_name | address to mark the origin point of the data. |
harp_time_us | the harp time (in microseconds) to timestamp onto the outgoing message. |
|
inlinestatic |
Override the current Harp time with a specific time.
|
inlinestatic |
attach a synchronizer. If the synchronizer is attached, then calls to harp_time_us_64() and harp_time_us_32() will reflect the synchronizer's time.
|
inlinestatic |
set the 16 bytews in the R_UUID register. Any unspecified bytes will be set to zero. Usage:
|
inlineprotected |
Enable or disable external virtual indicators.
|
inlinestatic |
attach a callback function to control external visual indicators (i.e: LEDs).
|
inlinestatic |
convert system time (in 64-bit microseconds) to local system time (in 64-bit microseconds).
this utility function is useful for timestamping events in the local time domain and then calculating when they happened in Harp time.
system_to_harp_us_32()
command does not exist because Harp time is only available in 64-bit time. system_time_us | the current system time in microseconds |
|
inlineprotectedvirtual |
update state of the derived class. Does nothing in the base class, but not pure virtual since we need to be able to instantiate a standalone harp core.
|
static |
generic handler function to write a message payload to a core or app register and issue a harp reply (unless is_muted()).
|
static |
write handler function. Sends a harp reply indicating a write error to the specified register.
|
protected |
flag indicating whether or not a new message is in the rx_buffer_.
RegValues& HarpCore::regs = regs_.regs_ |
reference to the struct of reg values for easy access.
|
inlinestatic |
|
protected |
function pointer to function that enables/disables visual indicators.
|
protected |
function pointer to synchronizer if configured.