From a4087588fa519a24b029fcaf847fb62a411d053f Mon Sep 17 00:00:00 2001 From: Sven Steudte Date: Sat, 9 Sep 2017 00:00:55 +0200 Subject: [PATCH] Increased FIFO buffer in Si4464 to 129bytes Decreased buffer of USB image capturing Removed defines.h Moved mutex initialization to radio.c and image.c --- tracker/software/debug.c | 2 +- tracker/software/defines.h | 11 ---------- tracker/software/drivers/ov5640.c | 1 - tracker/software/drivers/si4464.c | 10 +++++++++ tracker/software/drivers/si4464.h | 4 +++- tracker/software/drivers/ublox.c | 2 +- tracker/software/drivers/wrapper/padc.c | 2 +- tracker/software/main.c | 28 ++++++++++++------------- tracker/software/radio.c | 14 ++++++++----- tracker/software/threads/image.c | 6 ++++++ tracker/software/threads/threads.c | 4 ++-- tracker/software/types.h | 3 --- 12 files changed, 46 insertions(+), 41 deletions(-) delete mode 100644 tracker/software/defines.h diff --git a/tracker/software/debug.c b/tracker/software/debug.c index 76bd736..8bebba6 100644 --- a/tracker/software/debug.c +++ b/tracker/software/debug.c @@ -33,7 +33,7 @@ void debugOnUSB_On(BaseSequentialStream *chp, int argc, char *argv[]) debug_on_usb = true; } -static uint8_t usb_buffer[128*1024] __attribute__((aligned(32))); // USB image buffer +static uint8_t usb_buffer[96*1024] __attribute__((aligned(32))); // USB image buffer void printPicture(BaseSequentialStream *chp, int argc, char *argv[]) { (void)chp; diff --git a/tracker/software/defines.h b/tracker/software/defines.h deleted file mode 100644 index f46a7f9..0000000 --- a/tracker/software/defines.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __DEFINES_H__ -#define __DEFINES_H__ - -#include "ch.h" -#include "hal.h" - -#define HIGH true -#define LOW false - -#endif - diff --git a/tracker/software/drivers/ov5640.c b/tracker/software/drivers/ov5640.c index 0c742f9..6cd895f 100644 --- a/tracker/software/drivers/ov5640.c +++ b/tracker/software/drivers/ov5640.c @@ -8,7 +8,6 @@ #include "ov5640.h" #include "pi2c.h" #include "board.h" -#include "defines.h" #include "debug.h" #include "ssdv.h" #include diff --git a/tracker/software/drivers/si4464.c b/tracker/software/drivers/si4464.c index bcaf7d4..cfa7e18 100644 --- a/tracker/software/drivers/si4464.c +++ b/tracker/software/drivers/si4464.c @@ -287,6 +287,16 @@ void setModem2GFSK(gfsk_conf_t* conf) { uint8_t set_fifo_irq[] = {0x11, 0x12, 0x01, 0x0B, 0x20}; Si4464_write(set_fifo_irq, 5); + // Set FIFO to 129 byte + uint8_t set_129byte[] = {0x11, 0x00, 0x01, 0x03, 0x10}; + Si4464_write(set_129byte, 5); + + // Reset FIFO + uint8_t reset_fifo[] = {0x15, 0x01}; + Si4464_write(reset_fifo, 2); + uint8_t unreset_fifo[] = {0x15, 0x00}; + Si4464_write(unreset_fifo, 2); + // Disable preamble uint8_t disable_preamble[] = {0x11, 0x10, 0x01, 0x00, 0x00}; Si4464_write(disable_preamble, 5); diff --git a/tracker/software/drivers/si4464.h b/tracker/software/drivers/si4464.h index 7531784..7506351 100644 --- a/tracker/software/drivers/si4464.h +++ b/tracker/software/drivers/si4464.h @@ -3,13 +3,15 @@ #include "ch.h" #include "hal.h" -#include "defines.h" #include "types.h" #define RADIO_WRITE_GPIO(state) palWriteLine(LINE_RADIO_GPIO, state) #define RADIO_READ_GPIO() palReadLine(LINE_RADIO_GPIO) #define inRadioBand(freq) (RADIO_MIN_FREQ <= (freq) && (freq) <= RADIO_MAX_FREQ) +#define HIGH true +#define LOW false + #define SI4464_STATE_NOCHANGE 0 #define SI4464_STATE_SLEEP 1 #define SI4464_STATE_SPI_ACTIVE 2 diff --git a/tracker/software/drivers/ublox.c b/tracker/software/drivers/ublox.c index 774c91e..e50f89e 100644 --- a/tracker/software/drivers/ublox.c +++ b/tracker/software/drivers/ublox.c @@ -4,11 +4,11 @@ #include "ch.h" #include "hal.h" + #include "ublox.h" #include "pi2c.h" #include "debug.h" #include "config.h" -#include "defines.h" // Serial driver configuration for GPS const SerialConfig gps_config = diff --git a/tracker/software/drivers/wrapper/padc.c b/tracker/software/drivers/wrapper/padc.c index 20ccdbf..6c1fddd 100644 --- a/tracker/software/drivers/wrapper/padc.c +++ b/tracker/software/drivers/wrapper/padc.c @@ -1,6 +1,6 @@ #include "ch.h" #include "hal.h" -#include "defines.h" + #include "config.h" #include "padc.h" #include "pac1720.h" diff --git a/tracker/software/main.c b/tracker/software/main.c index 3b80540..7fc0dd9 100644 --- a/tracker/software/main.c +++ b/tracker/software/main.c @@ -28,28 +28,26 @@ int main(void) { chSysInit(); // Startup RTOS // Voltage switching (1.8V <=> 3.0V) - if(ACTIVATE_USB || ACTIVATE_3V) - { - boost_voltage(true); // Ramp up voltage to 3V - chThdSleepMilliseconds(100); - } + #if ACTIVATE_USB || ACTIVATE_3V + boost_voltage(true); // Ramp up voltage to 3V + chThdSleepMilliseconds(100); + #endif // Init debugging (Serial debug port, LEDs) DEBUG_INIT(); TRACE_INFO("MAIN > Startup"); // Start USB - if(ACTIVATE_USB) - { - sduObjectInit(&SDU1); - sduStart(&SDU1, &serusbcfg); + #if ACTIVATE_USB + sduObjectInit(&SDU1); + sduStart(&SDU1, &serusbcfg); - usbDisconnectBus(serusbcfg.usbp); - chThdSleepMilliseconds(100); - usbStart(serusbcfg.usbp, &usbcfg); - usbConnectBus(serusbcfg.usbp); - usb_initialized = true; - } + usbDisconnectBus(serusbcfg.usbp); + chThdSleepMilliseconds(100); + usbStart(serusbcfg.usbp, &usbcfg); + usbConnectBus(serusbcfg.usbp); + usb_initialized = true; + #endif // Startup threads start_essential_threads(); // Startup required modules (tracking managemer, watchdog) diff --git a/tracker/software/radio.c b/tracker/software/radio.c index 03e2ea8..c625d91 100644 --- a/tracker/software/radio.c +++ b/tracker/software/radio.c @@ -1,7 +1,6 @@ #include "ch.h" #include "hal.h" -#include "defines.h" #include "tracking.h" #include "debug.h" #include "radio.h" @@ -18,6 +17,8 @@ #define PHASE_DELTA_2200 (((2 * 2200) << 16) / PLAYBACK_RATE) /* Delta-phase per sample for 2200Hz tone */ mutex_t radio_mtx; // Radio mutex +bool radio_mtx_init = false; + mod_t active_mod = MOD_NOT_SET; static uint32_t phase_delta; // 1200/2200 for standard AX.25 static uint32_t phase; // Fixed point 9.7 (2PI = TABLE_SIZE) @@ -105,8 +106,6 @@ THD_FUNCTION(si_fifo_feeder_thd, arg) radioTune(tim_msg.freq, 0, tim_msg.power, all); while(c < all) { // Do while bytes not written into FIFO completely - //chThdSuspendS(&feeder_ref); // Suspend until interrupt resumes it - // Determine free memory in Si4464-FIFO uint8_t more = Si4464_freeFIFO(); if(more > all-c) { @@ -115,7 +114,7 @@ THD_FUNCTION(si_fifo_feeder_thd, arg) } Si4464_writeFIFO(&tim_msg.msg[c], more); // Write into FIFO c += more; - chThdSleepMilliseconds(5); + chThdSleepMilliseconds(15); // That value is ok up to 38k4 } // Shutdown radio (and wait for Si4464 to finish transmission) @@ -292,7 +291,7 @@ void shutdownRadio(void) { // Wait for PH to finish transmission for 2GFSK while(active_mod == MOD_2GFSK && Si4464_getState() == SI4464_STATE_TX) - chThdSleepMilliseconds(5); + chThdSleepMilliseconds(10); Si4464_shutdown(); active_mod = MOD_NOT_SET; @@ -435,6 +434,11 @@ uint32_t getFrequency(freq_conf_t *config) void lockRadio(void) { + // Initialize mutex + if(!radio_mtx_init) + chMtxObjectInit(&radio_mtx); + radio_mtx_init = true; + chMtxLock(&radio_mtx); // Wait for old feeder thread to terminate diff --git a/tracker/software/threads/image.c b/tracker/software/threads/image.c index 5713a0e..041936f 100644 --- a/tracker/software/threads/image.c +++ b/tracker/software/threads/image.c @@ -275,6 +275,7 @@ const uint8_t noCameraFound[4071] = { static uint8_t gimage_id; // Global image ID (for all image threads) mutex_t camera_mtx; +bool camera_mtx_init = false; void encode_ssdv(const uint8_t *image, uint32_t image_len, module_conf_t* conf, uint8_t image_id, bool redudantTx) { @@ -419,6 +420,11 @@ bool takePicture(ssdv_conf_t *conf, bool enableJpegValidation) { bool camera_found = false; + // Initialize mutex + if(!camera_mtx_init) + chMtxObjectInit(&camera_mtx); + camera_mtx_init = true; + // Lock camera TRACE_INFO("IMG > Lock camera"); chMtxLock(&camera_mtx); diff --git a/tracker/software/threads/threads.c b/tracker/software/threads/threads.c index 8cc1db4..cb80d5a 100644 --- a/tracker/software/threads/threads.c +++ b/tracker/software/threads/threads.c @@ -16,8 +16,8 @@ void start_essential_threads(void) { init_watchdog(); // Initialize essential mutex's - chMtxObjectInit(&camera_mtx); - chMtxObjectInit(&radio_mtx); + + pi2cInit(); // Initialize I2C pac1720_init(); // Initialize current measurement diff --git a/tracker/software/types.h b/tracker/software/types.h index 4d896fe..e137576 100644 --- a/tracker/software/types.h +++ b/tracker/software/types.h @@ -1,9 +1,6 @@ #ifndef __TYPES_H__ #define __TYPES_H__ -#define HIGH true -#define LOW false - typedef enum { // Modulation type MOD_NOT_SET, MOD_OOK,