canlib function reference
-
struct can_msg_t
-
struct can_timing_t
-
struct srb_ctx_t
- file msg_actuator.h
Functions
-
bool build_actuator_cmd_msg(can_msg_prio_t prio, uint16_t timestamp, can_actuator_id_t actuator_id, can_actuator_state_t actuator_cmd, can_msg_t *output)
-
bool build_actuator_analog_cmd_msg(can_msg_prio_t prio, uint32_t timestamp, can_actuator_id_t actuator_id, uint16_t actuator_cmd, can_msg_t *output)
-
bool build_actuator_status_msg(can_msg_prio_t prio, uint16_t timestamp, can_actuator_id_t actuator_id, can_actuator_state_t actuator_curr_state, can_actuator_state_t actuator_cmd_state, can_msg_t *output)
-
bool build_actuator_cmd_msg(can_msg_prio_t prio, uint16_t timestamp, can_actuator_id_t actuator_id, can_actuator_state_t actuator_cmd, can_msg_t *output)
- file msg_common.h
- file msg_general.h
Functions
-
bool build_general_board_status_msg(can_msg_prio_t prio, uint16_t timestamp, uint32_t general_error_bitfield, uint16_t board_specific_error_bitfield, can_msg_t *output)
-
bool build_reset_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t board_type_id, uint8_t board_inst_id, can_msg_t *output)
-
bool build_debug_raw_msg(can_msg_prio_t prio, uint16_t timestamp, const uint8_t *data, can_msg_t *output)
-
bool build_config_set_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t board_type_id, uint8_t board_inst_id, uint16_t config_id, uint16_t config_value, can_msg_t *output)
-
bool build_config_status_msg(can_msg_prio_t prio, uint16_t timestamp, uint16_t config_id, uint16_t config_value, can_msg_t *output)
-
bool get_general_board_status(const can_msg_t *msg, uint32_t *general_error_bitfield, uint16_t *board_specific_error_bitfield)
-
bool build_general_board_status_msg(can_msg_prio_t prio, uint16_t timestamp, uint32_t general_error_bitfield, uint16_t board_specific_error_bitfield, can_msg_t *output)
- file msg_gps.h
Functions
-
bool build_gps_time_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t utc_hours, uint8_t utc_mins, uint8_t utc_secs, uint8_t utc_dsecs, can_msg_t *output)
-
bool build_gps_lat_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t degrees, uint8_t minutes, uint16_t dminutes, uint8_t direction, can_msg_t *output)
-
bool build_gps_lon_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t degrees, uint8_t minutes, uint16_t dminutes, uint8_t direction, can_msg_t *output)
-
bool build_gps_alt_msg(can_msg_prio_t prio, uint16_t timestamp, uint16_t altitude, uint8_t daltitude, uint8_t units, can_msg_t *output)
-
bool build_gps_info_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t num_sat, uint8_t quality, can_msg_t *output)
-
bool get_gps_time(const can_msg_t *msg, uint8_t *utc_hours, uint8_t *utc_mins, uint8_t *utc_secs, uint8_t *utc_dsecs)
-
bool get_gps_lat(const can_msg_t *msg, uint8_t *degrees, uint8_t *minutes, uint16_t *dminutes, uint8_t *direction)
-
bool build_gps_time_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t utc_hours, uint8_t utc_mins, uint8_t utc_secs, uint8_t utc_dsecs, can_msg_t *output)
- file msg_recovery.h
Functions
-
bool build_alt_arm_cmd_msg(can_msg_prio_t prio, uint16_t timestamp, can_altimeter_id_t alt_id, can_alt_arm_state_t arm_cmd, can_msg_t *output)
-
bool build_alt_arm_status_msg(can_msg_prio_t prio, uint16_t timestamp, can_altimeter_id_t alt_id, can_alt_arm_state_t arm_state, uint16_t v_drogue, uint16_t v_main, can_msg_t *output)
-
bool get_alt_arm_state(const can_msg_t *msg, can_altimeter_id_t *alt_id, can_alt_arm_state_t *arm_state)
-
bool build_alt_arm_cmd_msg(can_msg_prio_t prio, uint16_t timestamp, can_altimeter_id_t alt_id, can_alt_arm_state_t arm_cmd, can_msg_t *output)
- file msg_sensor.h
Functions
-
bool build_altitude_data_msg(can_msg_prio_t prio, uint16_t timestamp, int32_t altitude, can_apogee_state_t apogee_state, can_msg_t *output)
-
bool build_imu_data_msg(can_msg_prio_t prio, uint16_t timestamp, char axis, can_imu_id_t imu_id, uint16_t linear_accel, uint16_t angular_velocity, can_msg_t *output)
-
bool build_mag_data_msg(can_msg_prio_t prio, uint16_t timestamp, char axis, can_imu_id_t imu_id, uint16_t mag_value, can_msg_t *output)
-
bool build_baro_data_msg(can_msg_prio_t prio, uint16_t timestamp, can_imu_id_t imu_id, uint32_t pressure, uint16_t temp, can_msg_t *output)
-
bool build_analog_data_msg(can_msg_prio_t prio, uint16_t timestamp, can_analog_sensor_id_t sensor_id, uint16_t sensor_data, can_msg_t *output)
-
bool get_altitude_data(const can_msg_t *msg, int32_t *altitude, can_apogee_state_t *apogee_state)
-
bool get_imu_mag_id_dimension(const can_msg_t *msg, can_imu_id_t *imu_id, char *dimension)
-
bool get_baro_data(const can_msg_t *msg, can_imu_id_t *imu_id, uint32_t *pressure, uint16_t *temp)
-
bool get_analog_data(const can_msg_t *msg, can_analog_sensor_id_t *sensor_id, uint16_t *output_data)
-
bool build_altitude_data_msg(can_msg_prio_t prio, uint16_t timestamp, int32_t altitude, can_apogee_state_t apogee_state, can_msg_t *output)
- file msg_state_est.h
Functions
-
bool build_state_est_data_msg(can_msg_prio_t prio, uint16_t timestamp, can_state_est_id_t state_id, const float *state_data, can_msg_t *output)
-
bool get_state_est_data(const can_msg_t *msg, can_state_est_id_t *state_id, float *state_data)
-
bool build_state_est_data_msg(can_msg_prio_t prio, uint16_t timestamp, can_state_est_id_t state_id, const float *state_data, can_msg_t *output)
- file message_types.h
Enums
-
enum can_msg_prio_t
Values:
-
enumerator PRIO_HIGHEST
-
enumerator PRIO_HIGH
-
enumerator PRIO_MEDIUM
-
enumerator PRIO_LOW
-
enumerator PRIO_HIGHEST
-
enum can_msg_type_t
Values:
-
enumerator MSG_UNDEFINED
-
enumerator MSG_GENERAL_BOARD_STATUS
-
enumerator MSG_RESET_CMD
-
enumerator MSG_DEBUG_RAW
-
enumerator MSG_CONFIG_SET
-
enumerator MSG_CONFIG_STATUS
-
enumerator MSG_ACTUATOR_CMD
-
enumerator MSG_ACTUATOR_ANALOG_CMD
-
enumerator MSG_ACTUATOR_STATUS
-
enumerator MSG_ALT_ARM_CMD
-
enumerator MSG_ALT_ARM_STATUS
-
enumerator MSG_SENSOR_ALTITUDE
-
enumerator MSG_SENSOR_IMU_X
-
enumerator MSG_SENSOR_IMU_Y
-
enumerator MSG_SENSOR_IMU_Z
-
enumerator MSG_SENSOR_MAG_X
-
enumerator MSG_SENSOR_MAG_Y
-
enumerator MSG_SENSOR_MAG_Z
-
enumerator MSG_SENSOR_BARO
-
enumerator MSG_SENSOR_ANALOG
-
enumerator MSG_GPS_TIMESTAMP
-
enumerator MSG_GPS_LATITUDE
-
enumerator MSG_GPS_LONGITUDE
-
enumerator MSG_GPS_ALTITUDE
-
enumerator MSG_GPS_INFO
-
enumerator MSG_STATE_EST_DATA
-
enumerator MSG_STREAM_STATUS
-
enumerator MSG_STREAM_DATA
-
enumerator MSG_STREAM_RETRY
-
enumerator MSG_LEDS_ON
-
enumerator MSG_LEDS_OFF
-
enumerator MSG_ID_ENUM_MAX
-
enumerator MSG_UNDEFINED
-
enum can_board_type_id_t
Values:
-
enumerator BOARD_TYPE_ID_ANY
-
enumerator BOARD_TYPE_ID_INJ_SENSOR
-
enumerator BOARD_TYPE_ID_CANARD_MOTOR
-
enumerator BOARD_TYPE_ID_CAMERA
-
enumerator BOARD_TYPE_ID_POWER
-
enumerator BOARD_TYPE_ID_LOGGER
-
enumerator BOARD_TYPE_ID_PROCESSOR
-
enumerator BOARD_TYPE_ID_TELEMETRY
-
enumerator BOARD_TYPE_ID_GPS
-
enumerator BOARD_TYPE_ID_SRAD_GNSS
-
enumerator BOARD_TYPE_ID_ALTIMETER
-
enumerator BOARD_TYPE_ID_ARMING
-
enumerator BOARD_TYPE_ID_PHESEUS
-
enumerator BOARD_TYPE_ID_PAY_SENSOR
-
enumerator BOARD_TYPE_ID_PAY_MOTOR
-
enumerator BOARD_TYPE_ID_RLCS_GLS
-
enumerator BOARD_TYPE_ID_RLCS_RELAY
-
enumerator BOARD_TYPE_ID_DAQ
-
enumerator BOARD_TYPE_ID_ENUM_MAX
-
enumerator BOARD_TYPE_ID_ANY
-
enum can_board_inst_id_t
Values:
-
enumerator BOARD_INST_ID_ANY
-
enumerator BOARD_INST_ID_GROUND
-
enumerator BOARD_INST_ID_ROCKET
-
enumerator BOARD_INST_ID_PAYLOAD
-
enumerator BOARD_INST_ID_ANY
-
enum can_board_inst_id_canard_motor_t
Values:
-
enumerator BOARD_INST_ID_CANARD_MOTOR_PRIMARY
-
enumerator BOARD_INST_ID_CANARD_MOTOR_FAILSAFE
-
enumerator BOARD_INST_ID_CANARD_MOTOR_ENUM_MAX
-
enumerator BOARD_INST_ID_CANARD_MOTOR_PRIMARY
-
enum can_board_inst_id_camera_t
Values:
-
enumerator BOARD_INST_ID_CAMERA_CANARD_A
-
enumerator BOARD_INST_ID_CAMERA_CANARD_B
-
enumerator BOARD_INST_ID_CAMERA_RECOVERY
-
enumerator BOARD_INST_ID_CAMERA_ENUM_MAX
-
enumerator BOARD_INST_ID_CAMERA_CANARD_A
-
enum can_actuator_id_t
Values:
-
enumerator ACTUATOR_OX_INJECTOR_VALVE
-
enumerator ACTUATOR_FUEL_INJECTOR_VALVE
-
enumerator ACTUATOR_ROCKET_CHARGE_ENABLE
-
enumerator ACTUATOR_PAYLOAD_CHARGE_ENABLE
-
enumerator ACTUATOR_5V_RAIL_ROCKET
-
enumerator ACTUATOR_5V_RAIL_PAYLOAD
-
enumerator ACTUATOR_12V_RAIL_ROCKET
-
enumerator ACTUATOR_12V_RAIL_PAYLOAD
-
enumerator ACTUATOR_TELEMETRY
-
enumerator ACTUATOR_CAMERA_CANARD_A
-
enumerator ACTUATOR_CAMERA_CANARD_B
-
enumerator ACTUATOR_CAMERA_RECOVERY
-
enumerator ACTUATOR_CAMERA_PAYLOAD
-
enumerator ACTUATOR_PROC_ESTIMATOR_INIT
-
enumerator ACTUATOR_SRAD_ALT_ESTIMATOR_INIT
-
enumerator ACTUATOR_SRAD_ALT_GPS_RESET
-
enumerator ACTUATOR_CANARD_ENABLE
-
enumerator ACTUATOR_CANARD_ANGLE
-
enumerator ACTUATOR_CAMERA_CAPTURE
-
enumerator ACTUATOR_PAYLOAD_LOGGING_ENABLE
-
enumerator ACTUATOR_THESEUS_ACTUATOR_1
-
enumerator ACTUATOR_THESEUS_ACTUATOR_2
-
enumerator ACTUATOR_RLCS_RELAY_POWER
-
enumerator ACTUATOR_RLCS_RELAY_SELECT
-
enumerator ACTUATOR_ENUM_MAX
-
enumerator ACTUATOR_OX_INJECTOR_VALVE
-
enum can_actuator_state_t
Values:
-
enumerator ACT_STATE_ON
-
enumerator ACT_STATE_OFF
-
enumerator ACT_STATE_UNK
-
enumerator ACT_STATE_ILLEGAL
-
enumerator ACT_STATE_ENUM_MAX
-
enumerator ACT_STATE_ON
-
enum can_altimeter_id_t
Values:
-
enumerator ALTIMETER_ROCKET_RAVEN
-
enumerator ALTIMETER_ROCKET_STRATOLOGGER
-
enumerator ALTIMETER_ROCKET_SRAD
-
enumerator ALTIMETER_PAYLOAD_RAVEN
-
enumerator ALTIMETER_PAYLOAD_STRATOLOGGER
-
enumerator ALTIMETER_ENUM_MAX
-
enumerator ALTIMETER_ROCKET_RAVEN
-
enum can_alt_arm_state_t
Values:
-
enumerator ALT_ARM_STATE_DISARMED
-
enumerator ALT_ARM_STATE_ARMED
-
enumerator ALT_ARM_STATE_ENUM_MAX
-
enumerator ALT_ARM_STATE_DISARMED
-
enum can_imu_id_t
Values:
-
enumerator IMU_PROC_ALTIMU10
-
enumerator IMU_PROC_MTI630
-
enumerator IMU_PROC_LSM6DSO32
-
enumerator IMU_SRAD_ALT_ALTIMU10
-
enumerator IMU_ENUM_MAX
-
enumerator IMU_PROC_ALTIMU10
-
enum can_analog_sensor_id_t
Values:
-
enumerator SENSOR_5V_VOLT
-
enumerator SENSOR_5V_CURR
-
enumerator SENSOR_12V_VOLT
-
enumerator SENSOR_12V_CURR
-
enumerator SENSOR_CHARGE_VOLT
-
enumerator SENSOR_CHARGE_CURR
-
enumerator SENSOR_BATT_VOLT
-
enumerator SENSOR_BATT_CURR
-
enumerator SENSOR_MOTOR_CURR
-
enumerator SENSOR_RADIO_CURR
-
enumerator SENSOR_GPS_CURR
-
enumerator SENSOR_LOCAL_CURR
-
enumerator SENSOR_PT_CHANNEL_1
-
enumerator SENSOR_PT_CHANNEL_2
-
enumerator SENSOR_PT_CHANNEL_3
-
enumerator SENSOR_PT_CHANNEL_4
-
enumerator SENSOR_PT_CHANNEL_5
-
enumerator SENSOR_HALL_CHANNEL_1
-
enumerator SENSOR_HALL_CHANNEL_2
-
enumerator SENSOR_HALL_CHANNEL_3
-
enumerator SENSOR_BARO_PRESSURE
-
enumerator SENSOR_BARO_TEMP
-
enumerator SENSOR_RA_BATT_VOLT_1
-
enumerator SENSOR_RA_BATT_VOLT_2
-
enumerator SENSOR_RA_BATT_CURR_1
-
enumerator SENSOR_RA_BATT_CURR_2
-
enumerator SENSOR_RA_MAG_VOLT_1
-
enumerator SENSOR_RA_MAG_VOLT_2
-
enumerator SENSOR_FPS
-
enumerator SENSOR_CANARD_ENCODER_1
-
enumerator SENSOR_CANARD_ENCODER_2
-
enumerator SENSOR_PROC_FLIGHT_PHASE_STATUS
-
enumerator SENSOR_PAYLOAD_LIM_1
-
enumerator SENSOR_PAYLOAD_LIM_2
-
enumerator SENSOR_PAYLOAD_SERVO_DIRECTION
-
enumerator SENSOR_PAYLOAD_INFRARED
-
enumerator SENSOR_THESEUS_TEMP_1
-
enumerator SENSOR_THESEUS_TEMP_2
-
enumerator SENSOR_THESEUS_TEMP_3
-
enumerator SENSOR_RLCS_RELAY_OUTPUT_VOLT_A
-
enumerator SENSOR_RLCS_RELAY_OUTPUT_VOLT_B
-
enumerator SENSOR_RLCS_RELAY_OUTPUT_CURR_A
-
enumerator SENSOR_RLCS_RELAY_OUTPUT_CURR_B
-
enumerator SENSOR_RLCS_RELAY_LIM_VOLT_A
-
enumerator SENSOR_RLCS_RELAY_LIM_VOLT_B
-
enumerator SENSOR_ENUM_MAX
-
enumerator SENSOR_5V_VOLT
-
enum can_state_est_id_t
Values:
-
enumerator STATE_ID_ATT_Q0
-
enumerator STATE_ID_ATT_Q1
-
enumerator STATE_ID_ATT_Q2
-
enumerator STATE_ID_ATT_Q3
-
enumerator STATE_ID_RATE_WX
-
enumerator STATE_ID_RATE_WY
-
enumerator STATE_ID_RATE_WZ
-
enumerator STATE_ID_VEL_VX
-
enumerator STATE_ID_VEL_VY
-
enumerator STATE_ID_VEL_VZ
-
enumerator STATE_ID_ALT
-
enumerator STATE_ID_COEFF_CL
-
enumerator STATE_ID_CANARD_ANGLE
-
enumerator STATE_ID_ENUM_MAX
-
enumerator STATE_ID_ATT_Q0
-
enum can_apogee_state_t
Values:
-
enumerator APOGEE_UNKNOWN
-
enumerator APOGEE_NOT_REACHED
-
enumerator APOGEE_REACHED
-
enumerator APOGEE_ENUM_MAX
-
enumerator APOGEE_UNKNOWN
-
enum can_general_board_status_offset_t
Values:
-
enumerator E_5V_OVER_CURRENT_OFFSET
-
enumerator E_5V_OVER_VOLTAGE_OFFSET
-
enumerator E_5V_UNDER_VOLTAGE_OFFSET
-
enumerator E_12V_OVER_CURRENT_OFFSET
-
enumerator E_12V_OVER_VOLTAGE_OFFSET
-
enumerator E_12V_UNDER_VOLTAGE_OFFSET
-
enumerator E_BATT_OVER_CURRENT_OFFSET
-
enumerator E_BATT_OVER_VOLTAGE_OFFSET
-
enumerator E_BATT_UNDER_VOLTAGE_OFFSET
-
enumerator E_MOTOR_OVER_CURRENT_OFFSET
-
enumerator E_IO_ERROR_OFFSET
-
enumerator E_FS_ERROR_OFFSET
-
enumerator E_WATCHDOG_TIMEOUT_OFFSET
-
enumerator E_GENERAL_BOARD_STATUS_OFFSET_MAX
-
enumerator E_5V_OVER_CURRENT_OFFSET
-
enum can_msg_prio_t
- file pic18f26k83_can.h
Functions
-
void pic18f26k83_can_init(const can_timing_t *timing, void (*receive_callback)(const can_msg_t *message))
Initialize PIC18F26K83 CAN Controller.
Warning
Note that this function DOES NOT setup the inputs and outputs from the CAN module to the output pins, application code must do that. In order to do that, CANRXPPS must be set to the proper pin value for the CANRX pin, and ___PPS must be set to 0x33 to mark it as outputting from the CAN module. In addition, TRIS and ANSEL registers for whatever pin is being used must be set to the right values.
- Parameters:
timing – Timing parameters generated by
can_generate_timing_paramsfunctionreceive_callback – CAN message receive handler, the function would be called when a CAN message is received
-
void pic18f26k83_can_send(const can_msg_t *message)
Send a CAN message.
- Parameters:
message – CAN message to be sent
-
bool pic18f26k83_can_send_rdy(void)
Check if CAN controller is ready to send a message.
- Returns:
return
trueif ready to send a message
-
void pic18f26k83_can_handle_interrupt(void)
Call this function in an interrupt context whenever PIR5 is nonzero.
Note
This function clears PIR5 interrupt flags
-
void pic18f26k83_can_init(const can_timing_t *timing, void (*receive_callback)(const can_msg_t *message))
- file can_rcv_buffer.h
A module for buffering CAN messages that are received from the CAN module. The module operates as a ring buffer, with the memory provided by the caller of the module.
The whole goal of this module is allowing you to write application code that doesn’t have to concern itself with ISR vs main thread code. If you set buffer_received_can_message as the can callback, then you can dequeue the buffered messages from the main thread without worrying about missing any messages from the bus.
The ring buffer is designed to be pseudo-thread safe. None of the functions are rentrant, and there are no locking or atomic mechanisms, but flags are used to show whether a particular memory element contains valid data. This should allow the writer function (buffer_received_can_message) and the reader function (get_buffered_can_message) to operate from separate contexts (the former can be run in the ISR and the latter in the main thread) without any problems.
Functions
-
void rcvb_init(void *pool, size_t pool_size)
Initializes the reecive buffer module.
- Parameters:
pool – memory buffer, which must be provided by the caller
pool_size – the size of pool, in bytes
-
void rcvb_push_message(const can_msg_t *msg)
Copies msg into our internal buffering system.
This function fails silently if we’re out of memory/space to hold the CAN message. This is so that you can use this buffering system as the CAN callback, whose signature is void
- Parameters:
msg – message to be sent
-
bool rcvb_has_overflowed(void)
returns true if the CAN receive buffer has ever overflowed.
Because the push function is meant to be called from an ISR, it won’t be able to do anything if it runs out of memory, it will just drop the message. That drop shouldn’t be silent, so this function will return true if a message has ever been dropped. You can clear this flag with rcvb_reset_overflow_flag.
-
void rcvb_clear_overflow_flag(void)
Clears the overflow flag, so that rcvb_has_overflowed will start returning false again. This function isn’t perfectly concurrency safe: If you call this function and during the call the receive buffer overflows again, you’ll miss that flag.
-
bool rcvb_is_full(void)
returns true if the receive buffer is full
This function exists to make up for the signature of rcvb_push_message. If this function returns true, then you know that we’re out of memory and we can’t enqueue your new message
-
bool rcvb_is_empty(void)
returns false if there’s a CAN message that has been buffered, but has not yet been read. Returns true otherwise
-
void rcvb_init(void *pool, size_t pool_size)
- file can_tx_buffer.h
Functions
-
void txb_init(void *pool, size_t pool_size, void (*can_send)(const can_msg_t*), bool (*can_tx_ready)(void))
-
bool txb_enqueue(const can_msg_t *msg)
Buffers message.
If there is room in the can_tx buffer, this function will not send the message. The only calls to
can_send()will be made duringtxb_heartbeat()- Parameters:
msg – message to be buffered
- Returns:
trueif success,falseif failed(i.e. buffer is full)
-
void txb_heartbeat(void)
This function is called every iteration through the main application loop.
If there are any messages that are in the “to transmit” queue, and
can_tx_ready()returns true, thencan_send()will be called with that message
-
void txb_init(void *pool, size_t pool_size, void (*can_send)(const can_msg_t*), bool (*can_tx_ready)(void))
- file safe_ring_buffer.h
Functions
- file timing_util.h
Functions
-
bool can_generate_timing_params(uint32_t system_freq, can_timing_t *timing)
Generate CAN bus timing setting for PIC microcontrollers.
- Parameters:
system_freq – PIC Fosc frequency in Hz
timing – buffer to write timing parameters to
- Returns:
trueif system_freq is valid and parameters have been written totiming
-
bool can_generate_timing_params(uint32_t system_freq, can_timing_t *timing)
- dir /home/runner/work/docs/docs/firmware-library/canlib
- dir /home/runner/work/docs/docs/firmware-library/canlib/canlib
- dir /home/runner/work/docs/docs/firmware-library
- dir /home/runner/work/docs/docs/firmware-library/canlib/canlib/message
- dir /home/runner/work/docs/docs/firmware-library/canlib/canlib/pic18f26k83
- dir /home/runner/work/docs/docs/firmware-library/canlib/canlib/util