Merge pull request #202 from cyberman54/development

SPI slave code fixes
This commit is contained in:
Verkehrsrot 2018-11-12 12:00:47 +01:00 committed by GitHub
commit 8a53ed0602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 8 deletions

View File

@ -29,7 +29,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng
[common] [common]
; for release_version use max. 10 chars total, use any decimal format like "a.b.c" ; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
release_version = 1.6.62 release_version = 1.6.63
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
debug_level = 0 debug_level = 0
@ -46,7 +46,7 @@ lib_deps_all =
lib_deps_lora = lib_deps_lora =
; MCCI LoRaWAN LMIC library@^2.2.2 ; MCCI LoRaWAN LMIC library@^2.2.2
lib_deps_display = lib_deps_display =
U8g2@>=2.23.16 U8g2@>=2.25.0
lib_deps_rgbled = lib_deps_rgbled =
SmartLeds@>=1.1.3 SmartLeds@>=1.1.3
lib_deps_gps = lib_deps_gps =

View File

@ -8,7 +8,10 @@ static const char TAG[] = "main";
// helper function // helper function
void do_reset() { void do_reset() {
ESP_LOGI(TAG, "Remote command: restart device"); ESP_LOGI(TAG, "Remote command: restart device");
if (irqHandlerTask != NULL)
vTaskDelete(irqHandlerTask);
LMIC_shutdown(); LMIC_shutdown();
vTaskDelay(3000 / portTICK_PERIOD_MS);
esp_restart(); esp_restart();
} }

View File

@ -35,7 +35,9 @@ static const char TAG[] = __FILE__;
// https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_slave.html // https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_slave.html
#define BUFFER_SIZE \ #define BUFFER_SIZE \
(MAX(8, HEADER_SIZE + PAYLOAD_BUFFER_SIZE) + \ (MAX(8, HEADER_SIZE + PAYLOAD_BUFFER_SIZE) + \
(4 - MAX(8, HEADER_SIZE + PAYLOAD_BUFFER_SIZE) % 4)) (PAYLOAD_BUFFER_SIZE % 4 == 0 \
? 0 \
: 4 - MAX(8, HEADER_SIZE + PAYLOAD_BUFFER_SIZE) % 4))
DMA_ATTR uint8_t txbuf[BUFFER_SIZE]; DMA_ATTR uint8_t txbuf[BUFFER_SIZE];
DMA_ATTR uint8_t rxbuf[BUFFER_SIZE]; DMA_ATTR uint8_t rxbuf[BUFFER_SIZE];
@ -64,13 +66,17 @@ void spi_slave_task(void *param) {
uint8_t *messageSize = txbuf + 3; uint8_t *messageSize = txbuf + 3;
*messageSize = msg.MessageSize; *messageSize = msg.MessageSize;
memcpy(txbuf + HEADER_SIZE, &msg.Message, msg.MessageSize); memcpy(txbuf + HEADER_SIZE, &msg.Message, msg.MessageSize);
// calculate crc16 checksum, not used yet // calculate crc16 checksum
// uint16_t *crc = (uint16_t *)txbuf; uint16_t *crc = (uint16_t *)txbuf;
//*crc = crc16_be(0, messageType, msg.MessageSize + HEADER_SIZE - 2); *crc = crc16_be(0, messageType, msg.MessageSize + HEADER_SIZE - 2);
// set length for spi slave driver // set length for spi slave driver
transaction_size = HEADER_SIZE + msg.MessageSize; transaction_size = HEADER_SIZE + msg.MessageSize;
transaction_size += (4 - transaction_size % 4); // SPI transaction size needs to be at least 8 bytes and dividable by 4, see
// https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_slave.html
if (transaction_size % 4 != 0) {
transaction_size += (4 - transaction_size % 4);
}
// prepare spi transaction // prepare spi transaction
spi_slave_transaction_t spi_transaction = {0}; spi_slave_transaction_t spi_transaction = {0};
@ -149,7 +155,8 @@ void spi_enqueuedata(uint8_t messageType, MessageBuffer_t *message) {
BaseType_t ret = BaseType_t ret =
xQueueSendToBack(SPISendQueue, (void *)message, (TickType_t)0); xQueueSendToBack(SPISendQueue, (void *)message, (TickType_t)0);
if (ret == pdTRUE) { if (ret == pdTRUE) {
ESP_LOGI(TAG, "%d byte(s) enqueued for SPI interface", message->MessageSize); ESP_LOGI(TAG, "%d byte(s) enqueued for SPI interface",
message->MessageSize);
} else { } else {
ESP_LOGW(TAG, "SPI sendqueue is full"); ESP_LOGW(TAG, "SPI sendqueue is full");
} }