/** * Send the header of the message - everything before the data block. */ static void send_msg_header(uint8_t addr, uint8_t cmd, uint16_t datalen) { crc_init(); buffer_send(addr, true); buffer_send(cmd, true); buffer_send(READ_U16_BYTE(datalen, 0), true); buffer_send(READ_U16_BYTE(datalen, 1), true); }
void send_msg(uint8_t addr, uint8_t cmd, const volatile __memx void *data, uint16_t datalen) { const volatile __memx uint8_t *data_u8 = data; send_msg_header(addr, cmd, datalen); for (size_t i = 0; i < datalen; ++i) { buffer_send(data_u8[i], true); } send_checksum(); }
static void sig_sendbuffer(NET_SENDBUF_REC *rec) { if (rec->buffer != NULL) { if (!buffer_send(rec)) return; } g_source_remove(rec->send_tag); rec->send_tag = -1; }
/* Flush the buffer, blocks until finished. */ void net_sendbuffer_flush(NET_SENDBUF_REC *rec) { int handle; if (rec->buffer == NULL) return; /* set the socket blocking while doing this */ handle = g_io_channel_unix_get_fd(rec->handle); #ifndef WIN32 fcntl(handle, F_SETFL, 0); #endif while (!buffer_send(rec)) ; #ifndef WIN32 fcntl(handle, F_SETFL, O_NONBLOCK); #endif }
static void producer(int* id) { buffer_send(&b, id); pthread_exit(NULL); }
/** * Get the checksum from the CRC peripheral and send it. */ static void send_checksum(void) { uint16_t crc = crc_get_checksum(); buffer_send(READ_U16_BYTE(crc, 1), false); buffer_send(READ_U16_BYTE(crc, 0), false); }
/** * Transmit multiple bytes. This does clear and set the interrupts, and must not be * run from the same interrupt level as LOOP_DREINTLVL. * * This function will spin until the buffer is ready, so do not call it if the * USART is not enabled or the DRE interrupt will not run for any reason. It will * result in a deadlock in that case. * * @param data - the data to send * @param len - length of the data * @param crc - iff true, also push the data to the CRC peripheral */ void buffer_send_bytes(const uint8_t *data, size_t len, bool crc) { for (size_t i = 0; i < len; ++i) { buffer_send(data[i], crc); } }
void *buffer_thread(void *arg) { buffer_send(); return NULL; }