mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-05 06:25:16 +00:00
interrupt safe USB send function
This commit is contained in:
parent
5137457545
commit
c05d248f83
13 changed files with 38 additions and 73 deletions
|
|
@ -119,6 +119,7 @@ inline void App_Init() {
|
|||
inline void App_Process() {
|
||||
while(1) {
|
||||
uint32_t notification;
|
||||
LED::Toggle();
|
||||
if(xTaskNotifyWait(0x00, UINT32_MAX, ¬ification, 100) == pdPASS) {
|
||||
// something happened
|
||||
if(notification & FLAG_USB_PACKET) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
static uint8_t inputBuffer[1024];
|
||||
uint16_t inputCnt = 0;
|
||||
static uint8_t outputBuffer[1024];
|
||||
static Communication::Callback callback = nullptr;
|
||||
static uint8_t blockAcks = 0;
|
||||
|
||||
|
|
@ -45,6 +44,7 @@ void Communication::Input(const uint8_t *buf, uint16_t len) {
|
|||
#include "Hardware.hpp"
|
||||
bool Communication::Send(const Protocol::PacketInfo &packet) {
|
||||
// DEBUG1_HIGH();
|
||||
uint8_t outputBuffer[512];
|
||||
uint16_t len = Protocol::EncodePacket(packet, outputBuffer,
|
||||
sizeof(outputBuffer));
|
||||
// DEBUG1_LOW();
|
||||
|
|
|
|||
|
|
@ -59,6 +59,12 @@ uint16_t Protocol::DecodeBuffer(uint8_t *buf, uint16_t len, PacketInfo *info) {
|
|||
return data - buf;
|
||||
}
|
||||
|
||||
if(length > sizeof(PacketInfo) * 2) {
|
||||
// larger than twice the maximum expected packet size, probably an error, ignore
|
||||
info->type = PacketType::None;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* The complete frame has been received, check checksum */
|
||||
auto type = (PacketType) data[3];
|
||||
uint32_t crc = *(uint32_t*) &data[length - 4];
|
||||
|
|
|
|||
|
|
@ -230,7 +230,6 @@ bool usb_transmit(const uint8_t *data, uint16_t length) {
|
|||
// grab pointer to write position
|
||||
__disable_irq();
|
||||
uint16_t write_index = usb_transmit_read_index + usb_transmit_fifo_level;
|
||||
__enable_irq();
|
||||
write_index %= sizeof(usb_transmit_fifo);
|
||||
// copy the data to the fifo
|
||||
uint16_t continous_length = sizeof(usb_transmit_fifo) - write_index;
|
||||
|
|
@ -243,21 +242,19 @@ bool usb_transmit(const uint8_t *data, uint16_t length) {
|
|||
memcpy(&usb_transmit_fifo[0], data + continous_length, length - continous_length);
|
||||
}
|
||||
// increment fifo level
|
||||
__disable_irq();
|
||||
usb_transmit_fifo_level += length;
|
||||
__enable_irq();
|
||||
|
||||
static bool first = true;
|
||||
if(first) {
|
||||
log_transmission_active = false;
|
||||
first = false;
|
||||
}
|
||||
bool ret = true;
|
||||
if(!data_transmission_active) {
|
||||
return trigger_next_fifo_transmission();
|
||||
} else {
|
||||
// still transmitting, no need to trigger
|
||||
return true;
|
||||
ret = trigger_next_fifo_transmission();
|
||||
}
|
||||
__enable_irq();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void usb_log(const char *log, uint16_t length) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue