- Merge and update si446x.c revisions
- WIP of PWM buffer memory use reduction
pull/4/head
bob 2018-06-13 11:42:37 +10:00
commit 9918acb2fe
7 zmienionych plików z 82 dodań i 8 usunięć

Wyświetl plik

@ -123,7 +123,7 @@
* Stratgey: Allocate PWM buffers from a CCM heap/pool.
* Requires some special handling in PWM and AFSK decoder TBI.
*/
#define USE_HEAP_PWM_BUFFER TRUE
#define USE_HEAP_PWM_BUFFER FALSE
/* Definitions for ICU FIFO implemented using chfactory. */
#if USE_HEAP_PWM_BUFFER == TRUE

Wyświetl plik

@ -213,7 +213,8 @@ CPPWARN = -Wall -Wextra -Wundef
# List all user C define here, like -D_DEBUG=1
UDEFS = -D_GNU_SOURCE -DARM_MATH_CM4 -DSHELL_CMD_TEST_ENABLED=0 \
-DSHELL_CMD_EXIT_ENABLED=1 -DUSB_TRACE_LEVEL=5 \
-DSHELL_CMD_MEM_ENABLED=0 -DDISABLE_HW_WATCHDOG=1
-DSHELL_CMD_MEM_ENABLED=0
# -DDISABLE_HW_WATCHDOG=1
# Define ASM defines here
UADEFS =

Wyświetl plik

@ -10,6 +10,7 @@
#include "commands.h"
#include "pflash.h"
#include "ublox.h"
#include <string.h>
static uint8_t usb_buffer[16*1024] __attribute__((aligned(32))); // USB image buffer
@ -26,6 +27,7 @@ const ShellCommand commands[] = {
{"mem", usb_cmd_ccm_heap},
#endif
{"sats", usb_cmd_get_gps_sat_info},
{"error_list", usb_cmd_get_error_list},
{NULL, NULL}
};
@ -284,3 +286,22 @@ void usb_cmd_send_aprs_message(BaseSequentialStream *chp, int argc, char *argv[]
chprintf(chp, "Message sent!\r\n");
}
void usb_cmd_get_error_list(BaseSequentialStream *chp, int argc, char *argv[])
{
(void)argc;
(void)argv;
uint8_t cntr = 0;
for(uint8_t i=0; i<ERROR_LIST_SIZE; i++)
{
if(strlen((char*)error_list[i]) > 0) {
chprintf(chp, "%s\r\n", error_list[i]);
cntr++;
}
}
if(!cntr) {
chprintf(chp, "No errors recorded\r\n");
}
}

Wyświetl plik

@ -13,6 +13,7 @@ void usb_cmd_send_aprs_message(BaseSequentialStream *chp, int argc, char *argv[]
void usb_cmd_set_test_gps(BaseSequentialStream *chp, int argc, char *argv[]);
void usb_cmd_ccm_heap(BaseSequentialStream *chp, int argc, char *argv[]);
void usb_cmd_get_gps_sat_info(BaseSequentialStream *chp, int argc, char *argv[]);
void usb_cmd_get_error_list(BaseSequentialStream *chp, int argc, char *argv[]);
extern const ShellCommand commands[];
#endif

Wyświetl plik

@ -1,10 +1,15 @@
#include "ch.h"
#include "hal.h"
#include "debug.h"
mutex_t trace_mtx; // Used internal to synchronize multiple chprintf in debug.h
char error_list[ERROR_LIST_SIZE][ERROR_LIST_LENGTH];
uint8_t error_counter;
#ifdef USB_TRACE_LEVEL
uint8_t usb_trace_level = USB_TRACE_LEVEL; // Set in makefile UDEFS
#else
uint8_t usb_trace_level = 2; // Level: Errors + Warnings
#endif

Wyświetl plik

@ -10,8 +10,13 @@
#include "usbcfg.h"
#include "usb.h"
#define ERROR_LIST_LENGTH 64
#define ERROR_LIST_SIZE 32
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
extern char error_list[ERROR_LIST_SIZE][ERROR_LIST_LENGTH];
extern uint8_t error_counter;
extern mutex_t trace_mtx;
extern const SerialConfig uart_config;
extern uint8_t usb_trace_level;
@ -41,7 +46,15 @@ extern uint8_t usb_trace_level;
#define TRACE_INFO(format, args...) if(usb_trace_level > 3) { TRACE_BASE(format, " ", ##args) }
#define TRACE_MON(format, args...) if(usb_trace_level > 2) { TRACE_BASE(format, " ", ##args) }
#define TRACE_WARN(format, args...) if(usb_trace_level > 1) { TRACE_BASE(format, "WARN ", ##args) }
#define TRACE_ERROR(format, args...) if(usb_trace_level > 0) { TRACE_BASE(format, "ERROR", ##args) }
#define TRACE_ERROR(format, args...) { \
if(usb_trace_level > 0) { \
TRACE_BASE(format, "ERROR", ##args); \
} \
\
uint8_t strcnt = chsnprintf(error_list[error_counter], ERROR_LIST_LENGTH, "[%8d.%03d] ", chVTGetSystemTime()/CH_CFG_ST_FREQUENCY, (chVTGetSystemTime()*1000/CH_CFG_ST_FREQUENCY)%1000); \
chsnprintf(&error_list[error_counter][strcnt], ERROR_LIST_LENGTH-strcnt, (format), ##args); \
error_counter = (error_counter+1)%ERROR_LIST_SIZE; \
}
#if TRACE_TIME && TRACE_FILE
#define TRACE_TAB " "

Wyświetl plik

@ -27,7 +27,7 @@ static const SPIConfig ls_spicfg = {
.cr1 = SPI_CR1_MSTR
};
static void Si446x_write(const uint8_t* txData, uint32_t len) {
static bool Si446x_write(const uint8_t* txData, uint32_t len) {
// Transmit data by SPI
/* TODO: Add radio unit ID and get specific radio SPI driver. */
uint8_t null_spi[len];
@ -37,13 +37,24 @@ static void Si446x_write(const uint8_t* txData, uint32_t len) {
spiStart(PKT_RADIO_SPI, &ls_spicfg);
/* Poll for CTS. */
uint8_t timeout = 100;
uint8_t rx_ready[] = {Si446x_READ_CMD_BUFF, 0x00};
do {
spiSelect(PKT_RADIO_SPI);
spiExchange(PKT_RADIO_SPI, 1, rx_ready, &rx_ready[1]);
spiUnselect(PKT_RADIO_SPI);
} while(rx_ready[1] != Si446x_COMMAND_CTS);
if(timeout != 100)
chThdSleep(TIME_MS2I(1));
} while(rx_ready[1] != Si446x_COMMAND_CTS && timeout--);
if(!timeout) {
TRACE_ERROR("SI > CTS not received");
/* Stop SPI and relinquish bus. */
spiStop(PKT_RADIO_SPI);
spiReleaseBus(PKT_RADIO_SPI);
return false;
}
/* Transfer data. Discard read back. */
spiSelect(PKT_RADIO_SPI);
spiExchange(PKT_RADIO_SPI, len, txData, null_spi);
@ -52,12 +63,14 @@ static void Si446x_write(const uint8_t* txData, uint32_t len) {
/* Stop SPI and relinquish bus. */
spiStop(PKT_RADIO_SPI);
spiReleaseBus(PKT_RADIO_SPI);
return true;
}
/**
* Read data from Si446x.
*/
static void Si446x_read(const uint8_t* txData, uint32_t txlen,
static bool Si446x_read(const uint8_t* txData, uint32_t txlen,
uint8_t* rxData, uint32_t rxlen) {
// Transmit data by SPI
/* TODO: Add radio unit ID and get SPI configuration accordingly. */
@ -73,12 +86,23 @@ static void Si446x_read(const uint8_t* txData, uint32_t txlen,
* This command does not itself cause CTS to report busy.
* Allocate a buffer to use for CTS check.
*/
uint8_t timeout = 100;
uint8_t rx_ready[] = {Si446x_READ_CMD_BUFF, 0x00};
do {
spiSelect(PKT_RADIO_SPI);
spiExchange(PKT_RADIO_SPI, 1, rx_ready, &rx_ready[1]);
spiUnselect(PKT_RADIO_SPI);
} while(rx_ready[1] != Si446x_COMMAND_CTS);
if(timeout != 100)
chThdSleep(TIME_MS2I(1));
} while(rx_ready[1] != Si446x_COMMAND_CTS && timeout--);
if(!timeout) {
TRACE_ERROR("SI > CTS not received");
/* Stop SPI (de-asserts select as well) and relinquish bus. */
spiStop(PKT_RADIO_SPI);
spiReleaseBus(PKT_RADIO_SPI);
return false;
}
/*
* Now write command and data. Discard the read back.
@ -91,15 +115,24 @@ static void Si446x_read(const uint8_t* txData, uint32_t txlen,
* Once CTS is received the response data is ready in the rx data buffer.
* The buffer contains the command, CTS and 0 - 16 bytes of response.
*/
timeout = 100;
do {
spiUnselect(PKT_RADIO_SPI);
if(timeout != 100)
chThdSleep(TIME_MS2I(1));
spiSelect(PKT_RADIO_SPI);
spiExchange(PKT_RADIO_SPI, rxlen, rx_ready, rxData);
} while(rxData[1] != Si446x_COMMAND_CTS);
} while(rxData[1] != Si446x_COMMAND_CTS && timeout--);
/* Stop SPI (de-asserts select as well) and relinquish bus. */
spiStop(PKT_RADIO_SPI);
spiReleaseBus(PKT_RADIO_SPI);
if(!timeout) {
TRACE_ERROR("SI > CTS not received");
return false;
}
return true;
}
static void Si446x_setProperty8(uint16_t reg, uint8_t val) {