30 #include "VMXErrors.h" 35 #define VMXCAN_IS_FRAME_REMOTE 0x80000000 36 #define VMXCAN_IS_FRAME_11BIT 0x40000000 37 #define VMXCAN_29BIT_MESSAGE_ID_MASK 0x1FFFFFFF 38 #define VMXCAN_11BIT_MESSAGE_ID_MASK 0x000007FF 40 #define VMXCAN_SEND_PERIOD_NO_REPEAT 0 41 #define VMXCAN_SEND_PERIOD_STOP_REPEATING -1 49 void setData(
const uint8_t *p_data_in, uint8_t len) {
53 for(
int i = 0; i < len; i++ ) {
54 data[i] = p_data_in[i];
57 void getData(uint8_t *p_data_out, uint8_t len) {
61 for(
int i = 0; i < len; i++ ) {
62 p_data_out[i] = data[i];
70 uint64_t sysTimeStampUS;
112 typedef uint32_t VMXCANReceiveStreamHandle;
117 class VMXCANReceiveStreamManager;
127 uint64_t lastSendTimestampUS;
128 uint32_t repeatEveryMS;
129 } VMXCANTimestampedMessageRepeating;
134 VMXCANReceiveStreamManager *p_stream_mgr;
138 thread * repeating_packet_thread_task;
139 bool repeating_packet_thread_task_done;
140 std::map<uint32_t, VMXCANTimestampedMessageRepeating> repeatingMessageMap;
144 void ReleaseResources();
146 static void CANNewRxDataNotifyHandler(
void *param, uint64_t timestamp_us);
147 static int ThreadFunc(
VMXCAN *);
148 static int RepeatingPacketThreadFunc(
VMXCAN *);
150 bool RemoveFromRepeatingMessageMap(uint32_t);
151 bool AddToRepeatingMessageMap(uint32_t,
VMXCANMessage&, uint32_t repeatEveryMS);
152 bool SendMessageInternal(
VMXCANMessage& msg, VMXErrorCode *errcode);
155 void DisplayMasksAndFilters();
159 typedef enum { CAN_BUS_BITRATE_1MBPS, CAN_BUS_BITRATE_500KBPS, CAN_BUS_BITRATE_250KBPS } CANBusBitrate;
182 bool SendMessage(
VMXCANMessage& msg, int32_t periodMs, VMXErrorCode *errcode);
200 bool OpenReceiveStream(VMXCANReceiveStreamHandle& streamHandle, uint32_t messageID, uint32_t messageMask, uint32_t maxMessages, VMXErrorCode *errcode);
213 bool ReadReceiveStream(VMXCANReceiveStreamHandle streamHandle,
VMXCANTimestampedMessage *messages, uint32_t messagesToRead, uint32_t& messagesRead, VMXErrorCode *errcode);
219 bool CloseReceiveStream(VMXCANReceiveStreamHandle streamHandle, VMXErrorCode *errcode);
225 bool GetCANBUSStatus(
VMXCANBusStatus& bus_status, VMXErrorCode *errcode);
233 bool Reset(VMXErrorCode *errcode);
242 bool ResetBusBitrate(VMXCAN::CANBusBitrate can_bus_bitrate, VMXErrorCode *errcode);
248 bool FlushTxFIFO(VMXErrorCode *errcode);
253 bool FlushRxFIFO(VMXErrorCode *errcode);
288 bool SetMode(VMXCANMode mode, VMXErrorCode *errcode);
294 bool GetMode(VMXCANMode& current_mode, VMXErrorCode *errcode);
302 bool ClearErrors(VMXErrorCode *errcode);
304 bool RetrieveAllCANData(uint64_t sys_timestamp, VMXErrorCode *errcode);
306 bool EnableReceiveStreamBlackboard(VMXCANReceiveStreamHandle streamHandle,
bool enable, VMXErrorCode *errcode);
308 bool IsReceveStreamBlackboardEnabled(VMXCANReceiveStreamHandle streamHandle,
bool& enabled, VMXErrorCode *errcode);
310 bool GetBlackboardEntry(VMXCANReceiveStreamHandle streamid, uint32_t messageID,
VMXCANTimestampedMessage& msg, uint64_t& sys_timestamp,
bool& already_retrieved, VMXErrorCode *errcode);
Places the CAN Controller into normal mode, where it may transmit messages onto the CAN Bus...
Definition: VMXCAN.h:270
Top-level Library Class providing access to all VMX-pi functionality.
Definition: VMXPi.h:40
VMXCANMode
Enumeration of VMX CAN operational modes.
Definition: VMXCAN.h:256
uint32_t txFullCount
txFullCount: The number of times that sendMessage failed with a txFifoFull error indicating that mess...
Definition: VMXCAN.h:89
The xVMXCANMessage structure encapsulates a CAN Bus message.
Definition: VMXCAN.h:44
bool busPassiveError
Currently a bus passive condition exists.
Definition: VMXCAN.h:97
uint32_t receiveErrorCount
receiveErrorCount: The count of receive errors as reported by the CAN driver.
Definition: VMXCAN.h:91
Places the CAN Controller into a listen-only mode where it passively listens to the CAN Bus...
Definition: VMXCAN.h:275
bool messageError
Controller message error detected.
Definition: VMXCAN.h:109
Places the CAN Controller into configuration mode, during which the Receive Masks/ Fiters may be modi...
Definition: VMXCAN.h:264
bool busOffError
Currently a bus off condition exists.
Definition: VMXCAN.h:99
Places the CAN Transceiver/Controller into a sleep state, which may be automatically woken from if CA...
Definition: VMXCAN.h:260
bool hwRxOverflow
Hardware-level buffer overflow.
Definition: VMXCAN.h:101
bool busWarning
Currently a bus warning condition exists.
Definition: VMXCAN.h:95
uint32_t busOffCount
busOffCount: The number of times that sendMessage failed with a busOff error indicating that messages...
Definition: VMXCAN.h:85
The VMXTime class provides time management functions, including system timestamps, VMX Real-time Clock access, timer notifications and current thread time-delay.
Definition: VMXTime.h:38
bool swRxOverflow
Firmware-level buffer overflow.
Definition: VMXCAN.h:103
uint32_t transmitErrorCount
transmitErrorCount: The count of transmit errors as reported by the CAN driver.
Definition: VMXCAN.h:93
float percentBusUtilization
Percentage of total CAN bus bandwidth currently utilized.
Definition: VMXCAN.h:81
The sVMXTimestampedCANMessage encapsulates a timestamped CAN Bus message.
Definition: VMXCAN.h:68
The VMXCAN class provides a hardware-abstraction of the VMX-pi CAN functionality. ...
Definition: VMXCAN.h:122
The VMXCANBusStatus structure contains CAN Bus utilitization, status and error information.
Definition: VMXCAN.h:79
bool busError
Transceiver bus error detected.
Definition: VMXCAN.h:105
bool wake
Transceiver wakeup event occurred.
Definition: VMXCAN.h:107