![]() |
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. | |
Private Member Functions | |
void | process_cdc_input () |
Read incoming bytes from the USB serial port. Does not block. | |
const RegSpecs & | reg_address_to_specs (uint8_t address) |
return a reference to the specified core or app register's specs used for issuing a harp reply for that register. | |
Static Private Member Functions | |
static void | update_next_heartbeat_from_curr_harp_time_us (uint64_t curr_harp_time_us) |
recompute the next heartbeat event time based on the current time. | |
static void | update_state (bool force=false, op_mode_t forced_next_state=STANDBY) |
update internal state machine. | |
static void | update_timestamp_regs () |
Write the current Harp time to the timestamp registers. | |
static void | set_timestamp_regs (uint64_t harp_time_us) |
Write the a specified Harp time to the timestamp registers. | |
static void | read_timestamp_second (uint8_t reg_name) |
static void | read_timestamp_microsecond (uint8_t reg_name) |
static void | write_timestamp_second (msg_t &msg) |
Handle writing to the R_TIMESTAMP_SECOND register and update the device's Harp time to reflect the seconds written to this register. | |
static void | write_timestamp_microsecond (msg_t &msg) |
Handle writing to the R_TIMESTAMP_MICROSECOND register and update the device's Harp time to reflect the microseconds written to this register. | |
static void | write_operation_ctrl (msg_t &msg) |
static void | write_reset_dev (msg_t &msg) |
static void | write_device_name (msg_t &msg) |
static void | write_serial_number (msg_t &msg) |
static void | write_clock_config (msg_t &msg) |
static void | write_timestamp_offset (msg_t &msg) |
Private Attributes | |
const uint8_t & | total_bytes_read_ |
the total number of bytes read into the the msg receive buffer. This is implemented as a read-only reference to the rx_buffer_index_. | |
uint8_t | rx_buffer_ [MAX_PACKET_SIZE] |
buffer to contain data read from the serial port. | |
uint8_t | rx_buffer_index_ |
rx_buffer_ index where the next incoming byte will be written. | |
uint64_t | offset_us_64_ |
local offset from "Harp time" to device hardware timer tracing elapsed microseconds since boot, where \(t_{offset} = t_{local} - t_{Harp} \) | |
uint32_t | next_heartbeat_time_us_ |
next time a heartbeat message is scheduled to issue. | |
uint32_t | heartbeat_interval_us_ |
the current interval at which the next_neartbeat_time_us_ is being updated. | |
uint32_t | disconnect_start_time_us_ |
last time device detects no connection with the PC in microseconds. | |
bool | disconnect_handled_ |
flag to indicate the the device was disconnected and the event has been handled. | |
bool | connect_handled_ |
flag to indicate the the device was connected and the event has been handled. | |
bool | sync_handled_ |
true if the device has synchronized and all consequential activity has been handled. | |
Registers | regs_ |
struct of Harp core registers | |
RegFnPair | reg_func_table_ [CORE_REG_COUNT] |
Function table containing the read/write handler functions, one pair per core register. Index is the register address. | |
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 |
|
private |
Read incoming bytes from the USB serial port. Does not block.
|
static |
generic handler function to read a message payload to a core or app register and issue a harp reply (unless is_muted()).
|
staticprivate |
|
staticprivate |
|
private |
return a reference to the specified core or app register's specs used for issuing a harp reply for that register.
address is the full address range where 0 is the first core register, and APP_REG_START_ADDRESS is the first app register.
|
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.
|
staticprivate |
Write the a specified Harp time to the timestamp registers.
|
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.
|
inlinestaticprivate |
recompute the next heartbeat event time based on the current time.
|
staticprivate |
update internal state machine.
force. | If true, the state will change to the #forced_next_state. Otherwise, the #forced_next_state is ignored. |
forced_next_state | if #force then this is the next state that the op mode state machine will enter. |
|
inlinestaticprivate |
Write the current Harp time to the timestamp registers.
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
static |
generic handler function to write a message payload to a core or app register and issue a harp reply (unless is_muted()).
|
staticprivate |
|
staticprivate |
|
staticprivate |
Handle writing to the R_TIMESTAMP_MICROSECOND
register and update the device's Harp time to reflect the microseconds written to this register.
|
staticprivate |
|
staticprivate |
Handle writing to the R_TIMESTAMP_SECOND
register and update the device's Harp time to reflect the seconds written to this register.
|
static |
write handler function. Sends a harp reply indicating a write error to the specified register.
|
private |
flag to indicate the the device was connected and the event has been handled.
|
private |
flag to indicate the the device was disconnected and the event has been handled.
|
private |
last time device detects no connection with the PC in microseconds.
|
private |
the current interval at which the next_neartbeat_time_us_
is being updated.
|
protected |
flag indicating whether or not a new message is in the rx_buffer_.
|
private |
next time a heartbeat message is scheduled to issue.
|
private |
local offset from "Harp time" to device hardware timer tracing elapsed microseconds since boot, where \(t_{offset} = t_{local} - t_{Harp} \)
|
private |
Function table containing the read/write handler functions, one pair per core register. Index is the register address.
RegValues& HarpCore::regs = regs_.regs_ |
reference to the struct of reg values for easy access.
|
private |
struct of Harp core registers
|
private |
buffer to contain data read from the serial port.
|
private |
rx_buffer_ index where the next incoming byte will be written.
|
inlinestatic |
|
protected |
function pointer to function that enables/disables visual indicators.
|
protected |
function pointer to synchronizer if configured.
|
private |
true if the device has synchronized and all consequential activity has been handled.
|
private |
the total number of bytes read into the the msg receive buffer. This is implemented as a read-only reference to the rx_buffer_index_.