41unsigned Can::numReceivedPackets_{0};
42unsigned Can::numTransmittedPackets_{0};
60 HASSERT((count %
sizeof(
struct can_frame)) == 0);
62 struct can_frame *data = (
struct can_frame*)buf;
65 count /=
sizeof(
struct can_frame);
74 size_t frames_read =
rxBuf->
get(data, count < 8 ? count : 8);
80 if ((file->
flags & O_NONBLOCK) || result > 0)
87 rxBuf->block_until_condition(file,
true);
92 result += frames_read;
96 if (!result && (file->
flags & O_NONBLOCK))
101 return result *
sizeof(
struct can_frame);
112 HASSERT((count %
sizeof(
struct can_frame)) == 0);
114 const struct can_frame *data = (
const struct can_frame*)buf;
117 count /=
sizeof(
struct can_frame);
121 portENTER_CRITICAL();
126 size_t frames_written =
txBuf->
put(data, count < 8 ? count : 8);
128 if (frames_written == 0)
132 if ((file->
flags & O_NONBLOCK) || result > 0)
141 txBuf->block_until_condition(file,
false);
148 result += frames_written;
149 count -= frames_written;
150 data += frames_written;
154 if (!result && (file->
flags & O_NONBLOCK))
159 return result *
sizeof(
struct can_frame);
170 portENTER_CRITICAL();
DeviceBuffer< struct can_frame > * txBuf
transmit buffer
int read(struct can_frame *frame)
Read a frame if there is one available.
void flush_buffers() OVERRIDE
called after disable
DeviceBuffer< struct can_frame > * rxBuf
receive buffer
virtual void tx_msg()=0
function to try and transmit a message
bool select(File *file, int mode) OVERRIDE
Device select method.
int write(const struct can_frame *frame)
Send a frame if there is space available.
void flush()
flush all the data out of the buffer and reset the buffer.
size_t space()
Return the number of items for which space is available.
size_t pending()
Return the number of items in the queue.
void select_insert()
Add client to list of clients needing woken.
size_t get(T *buf, size_t items)
remove a number of items from the buffer.
size_t put(const T *buf, size_t items)
Insert a number of items to the buffer.
#define FWRITE
Workaround for missing header defines on some newlib versions.
#define FREAD
Workaround for missing header defines on some newlib versions.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.