Refactor UART debug outputs. Fix USB event handler.

pull/4/head
bob 2018-07-15 18:24:07 +10:00
rodzic 5b6b8f5c52
commit eda158af9b
12 zmienionych plików z 84 dodań i 58 usunięć

Wyświetl plik

@ -111,9 +111,9 @@ void pktConfigSerialDiag(void) {
#endif
}
void pktConfigSerialPkt(void) {
/*void pktConfigSerialPkt(void) {
}
}*/
/**
* TODO: Move this into pktconf.h and use general GPIO to setup.
@ -136,9 +136,9 @@ uint8_t pktReadIOlines() {
}
void pktSerialStart(void) {
#if ENABLE_EXTERNAL_I2C == FALSE
#if ENABLE_SERIAL_DEBUG == TRUE
pktConfigSerialDiag();
pktConfigSerialPkt();
//pktConfigSerialPkt();
sdStart(SERIAL_CFG_DEBUG_DRIVER, &debug_config);
#endif
/* Setup diagnostic resource access semaphore. */
@ -148,7 +148,7 @@ void pktSerialStart(void) {
void dbgWrite(uint8_t level, uint8_t *buf, uint32_t len) {
(void)level;
#if ENABLE_EXTERNAL_I2C == FALSE
#if ENABLE_SERIAL_DEBUG == TRUE
chnWrite((BaseSequentialStream*)SERIAL_CFG_DEBUG_DRIVER, buf, len);
#else
(void)buf;
@ -158,7 +158,7 @@ void dbgWrite(uint8_t level, uint8_t *buf, uint32_t len) {
int dbgPrintf(uint8_t level, const char *format, ...) {
(void)level;
#if ENABLE_EXTERNAL_I2C == FALSE
#if ENABLE_SERIAL_DEBUG == TRUE
va_list arg;
int done;
@ -174,7 +174,12 @@ int dbgPrintf(uint8_t level, const char *format, ...) {
}
void pktWrite(uint8_t *buf, uint32_t len) {
#if ENABLE_SERIAL_DEBUG == TRUE
chnWrite((BaseSequentialStream*)SERIAL_CFG_DEBUG_DRIVER, buf, len);
#else
(void)buf;
(void)len;
#endif
}
void pktConfigureCoreIO(void) {

Wyświetl plik

@ -21,7 +21,7 @@
#define USE_SPI_ATTACHED_RADIO TRUE
#define DUMP_PACKET_TO_SERIAL FALSE
//#define DUMP_PACKET_TO_SERIAL FALSE
/*
* TODO: Need to use radio unit ID to set assigned GPIO & SPI.
@ -157,7 +157,7 @@
#define ENABLE_SERIAL_DEBUG FALSE
#if ENABLE_EXTERNAL_I2C == TRUE && ENABLE_SERIAL_DEBUG == TRUE
#error "Cannot enable serial debug when using external I2C"
#error "Cannot enable serial debug and external I2C together"
#elif ENABLE_EXTERNAL_I2C == FALSE && ENABLE_SERIAL_DEBUG == TRUE
#define LINE_USART3_TX LINE_IO_TXD
#define LINE_USART3_RX LINE_IO_RXD

Wyświetl plik

@ -112,9 +112,9 @@ void pktConfigSerialDiag(void) {
/**
* Configure packet dump output
*/
void pktConfigSerialPkt(void) {
/*void pktConfigSerialPkt(void) {
}
}*/
/**
* TODO: Move this into pktconf.h and use general GPIO to setup.
@ -140,7 +140,7 @@ uint8_t pktReadIOlines() {
void pktSerialStart(void) {
#if ENABLE_SERIAL_DEBUG == TRUE
pktConfigSerialDiag();
pktConfigSerialPkt();
//pktConfigSerialPkt();
sdStart(SERIAL_CFG_DEBUG_DRIVER, &debug_config);
#endif
/* Setup diagnostic resource access semaphore. */
@ -150,7 +150,7 @@ void pktSerialStart(void) {
void dbgWrite(uint8_t level, uint8_t *buf, uint32_t len) {
(void)level;
#if ENABLE_EXTERNAL_I2C == FALSE
#if ENABLE_SERIAL_DEBUG == TRUE
chnWrite((BaseSequentialStream*)SERIAL_CFG_DEBUG_DRIVER, buf, len);
#else
(void)buf;
@ -160,7 +160,7 @@ void dbgWrite(uint8_t level, uint8_t *buf, uint32_t len) {
int dbgPrintf(uint8_t level, const char *format, ...) {
(void)level;
#if ENABLE_EXTERNAL_I2C == FALSE
#if ENABLE_SERIAL_DEBUG == TRUE
va_list arg;
int done;
@ -176,7 +176,12 @@ int dbgPrintf(uint8_t level, const char *format, ...) {
}
void pktWrite(uint8_t *buf, uint32_t len) {
#if ENABLE_SERIAL_DEBUG == TRUE
chnWrite((BaseSequentialStream*)SERIAL_CFG_DEBUG_DRIVER, buf, len);
#else
(void)buf;
(void)len;
#endif
}
void pktConfigureCoreIO(void) {

Wyświetl plik

@ -21,7 +21,7 @@
#define USE_SPI_ATTACHED_RADIO TRUE
#define DUMP_PACKET_TO_SERIAL FALSE
//#define DUMP_PACKET_TO_SERIAL FALSE
/*
* TODO: Need to use radio unit ID to set assigned GPIO & SPI.

Wyświetl plik

@ -540,7 +540,7 @@ radio_signal_t Si446x_getCurrentRSSI(const radio_unit_t radio) {
void Si446x_getPartInfo(const radio_unit_t radio, si446x_info_t *info) {
/* TODO: add hardware mapping. */
(void)radio;
/* Get status. Leave any pending interrupts intact. */
/* Get information for this chip. */
const uint8_t status_info[] = {Si446x_GET_PART_INFO};
Si446x_read(status_info, sizeof(status_info), (uint8_t *)info,
sizeof(si446x_info_t));

Wyświetl plik

@ -27,11 +27,10 @@ THD_FUNCTION(pktConsole, arg) {
event_listener_t con_el;
thread_t *shelltp;
/* chEvtRegisterMaskWithFlags(chnGetEventSource(driver),
chEvtRegisterMaskWithFlags(chnGetEventSource(driver),
&con_el,
CONSOLE_CHANNEL_EVT,
CHN_CONNECTED | CHN_DISCONNECTED | CHN_INPUT_AVAILABLE);*/
chEvtRegister(chnGetEventSource(driver), &con_el, CONSOLE_CHANNEL_EVT);
CHN_CONNECTED | CHN_DISCONNECTED | CHN_INPUT_AVAILABLE);
console_state = CON_CHN_READY;
/* Initialisation done. Wait for start from initiator. */
@ -42,7 +41,7 @@ THD_FUNCTION(pktConsole, arg) {
chMsgRelease(initiator, MSG_OK);
while(true) {
chEvtWaitAny(EVENT_MASK(CONSOLE_CHANNEL_EVT));
chEvtWaitAny(CONSOLE_CHANNEL_EVT);
BaseSequentialStream *chp = (BaseSequentialStream *)driver;
eventflags_t evtf = chEvtGetAndClearFlags(&con_el);

Wyświetl plik

@ -199,7 +199,7 @@ void pktDisablePWM(AFSKDemodDriver *myDriver) {
chSysLock();
/* Close the PWM stream. */
pktClosePWMChannelI(myDriver->icudriver, 0, PWM_TERM_DECODE_STOP);
pktClosePWMChannelI(myDriver->icudriver, EVT_NONE, PWM_TERM_DECODE_STOP);
/* Stop ICU capture. */
icuStopCaptureI(myDriver->icudriver);
@ -832,6 +832,12 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
pkt_data_object_t *myPktBuffer = pktTakeDataBuffer(myHandler,
pkt_buffer_pool,
TIME_MS2I(100));
#if AFSK_DEBUG_TYPE == AFSK_PWM_DATA_CAPTURE_DEBUG
char buf[80];
int out = chsnprintf(buf, sizeof(buf),
"\r\n======= START ===========\r\n");
pktWrite( (uint8_t *)buf, out);
#endif
/* If no buffer is available the handler pointer is also set to NULL. */
if(myPktBuffer == NULL) {
@ -844,12 +850,7 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
break;
}
#if AFSK_DEBUG_TYPE == AFSK_PWM_DATA_CAPTURE_DEBUG
char buf[80];
int out = chsnprintf(buf, sizeof(buf),
"\r\n======= START ===========\r\n");
chnWrite(pkt_out, (uint8_t *)buf, out);
#endif
/* Increase thread priority. */
(void)chThdSetPriority(DECODER_RUN_PRIORITY);
/* Turn on the decoder LED. */
@ -896,7 +897,7 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
char buf[80];
int out = chsnprintf(buf, sizeof(buf), "%i, %i\r\n",
radio.pwm.impulse, radio.pwm.valley);
chnWrite(pkt_out, (uint8_t *)buf, out);
pktWrite( (uint8_t *)buf, out);
#endif
/* Look for "in band" message in radio data. */
@ -932,7 +933,7 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
continue; /* Decoder state switch. */
} /* End case. */
/* If PWM reports a zero valley.
/* If PWM reports a zero impulse or valley.
* The PWM side has already posted a PWM_STREAM_CLOSE event.
*/
case PWM_TERM_ICU_ZERO:
@ -1050,6 +1051,19 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
*/
case DECODER_RESET: {
if(myHandler->active_packet_object != NULL) {
#if AFSK_DEBUG_TYPE == AFSK_PWM_DATA_CAPTURE_DEBUG
char buf[80];
int out = chsnprintf(buf, sizeof(buf),
"\r\n======= STOP ===========\r\n");
pktWrite( (uint8_t *)buf, out);
#endif
#if AFSK_DEBUG_TYPE == AFSK_AX25_RAW_PACKET_DUMP \
|| AFSK_DEBUG_TYPE == AFSK_PWM_DATA_CAPTURE_DEBUG
pktDumpAX25Frame(myHandler->active_packet_object->buffer,
myHandler->active_packet_object->packet_size,
AX25_DUMP_RAW);
#endif
#if USE_CCM_HEAP_RX_BUFFERS == TRUE
/* Free the packet buffer in the heap now. */
chHeapFree(myHandler->active_packet_object->buffer);
@ -1078,9 +1092,6 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
/*
* Wait for FIFO stream control object to be free from the radio.
* Normally this semaphore will not suspend as decoding is slow.
* If can be a forced release by semaphore reset.
* TODO: This may happen if the watchdog system forces reset.
* TBD.
*/
(void)chBSemWait(&myFIFO->sem);

Wyświetl plik

@ -51,7 +51,8 @@
#define AFSK_QCORR_DEC_CS_DEBUG 5
#define AFSK_QCORR_DEC_MFIL_DEBUG 6
#define AFSK_PWM_DATA_CAPTURE_DEBUG 7
#define AFSK_PWM_DATA_REPLAY_DEBUG 8
//#define AFSK_PWM_DATA_REPLAY_DEBUG 8
#define AFSK_AX25_RAW_PACKET_DUMP 9
#define AFSK_DEBUG_TYPE AFSK_PWM_DATA_CAPTURE_DEBUG

Wyświetl plik

@ -527,10 +527,10 @@ void pktRadioCCATrailTimer(ICUDriver *myICU) {
* Hence the decoder is responsible for releasing the PWM FIFO object.
* Prior to releasing the FIFO the decoder waits on the FIFO semaphore.
* Closing PWM from here sets the FIFO management semaphore.
* This caters for the case where the decoder terminates stram processing first.
* This caters for the case where the decoder terminates stream processing first.
* This may happen if noise produces a long string of data.
*/
pktClosePWMChannelI(myICU, EVT_PWM_STREAM_CLOSE, PWM_TERM_CCA_CLOSE);
pktClosePWMChannelI(myICU, EVT_NONE, PWM_TERM_CCA_CLOSE);
break;
}
@ -667,12 +667,10 @@ void pktRadioICUPeriod(ICUDriver *myICU) {
}
/*
* Check if either ICU value is zero and thus invalid.
* Check if impulse ICU value is zero and thus invalid.
*/
icucnt_t impulse = icuGetWidthX(myICU);
icucnt_t valley = icuGetPeriodX(myICU) - impulse;
if(impulse == 0 || valley == 0) {
pktClosePWMChannelI(myICU, EVT_PWM_STREAM_CLOSE, PWM_TERM_ICU_ZERO);
if(icuGetWidthX(myICU) == 0) {
pktClosePWMChannelI(myICU, EVT_NONE, PWM_TERM_ICU_ZERO);
chSysUnlockFromISR();
return;
}

Wyświetl plik

@ -207,7 +207,7 @@ q31_t push_qcorr_sample(AFSKDemodDriver *myDriver, bit_t sample) {
#if AFSK_DEBUG_TYPE == AFSK_QCORR_FIR_DEBUG
char buf[80];
int out = chsnprintf(buf, sizeof(buf), "%X\r\n", scaledOut);
chnWrite(pkt_out, (uint8_t *)buf, out);
pktWrite( (uint8_t *)buf, out);
#endif
/*
@ -261,7 +261,7 @@ bool process_qcorr_output(AFSKDemodDriver *myDriver) {
int out = chsnprintf(buf, sizeof(buf), "%i, %i\r\n",
myBin->cos_out, myBin->sin_out);
}
chnWrite(pkt_out, (uint8_t *)buf, out);
pktWrite( (uint8_t *)buf, out);
#endif
}
@ -294,7 +294,7 @@ bool process_qcorr_output(AFSKDemodDriver *myDriver) {
i, decoder->filter_bins[i].mag,
decoder->current_n,
decoder->current_n % decoder->decode_length);
chnWrite(pkt_out, (uint8_t *)buf, out);
pktWrite( (uint8_t *)buf, out);
}
#endif
@ -508,7 +508,7 @@ void calc_qcorr_magnitude(AFSKDemodDriver *myDriver) {
int out = chsnprintf(buf, sizeof(buf), \
"MAG SQRT failed bin %i, cosQ %X, sinQ %X, cos %f, sin %f, mag2 %f, mag %X, index %i\r\n", \
i, myBin->cos_out, myBin->sin_out, cos, sin, mag2, raw_mag, decoder->current_n);
chnWrite(pkt_out, (uint8_t *)buf, out);
pktWrite( (uint8_t *)buf, out);
#endif /* AFSK_ERROR_TYPE == AFSK_SQRT_ERROR */
#else
@ -528,7 +528,7 @@ void calc_qcorr_magnitude(AFSKDemodDriver *myDriver) {
"mag2 %X, mag %X, index %i\r\n",
i, myBin->cos_out, myBin->sin_out, cos, sin, mag2,
decoder->filter_bins[i].raw_mag, decoder->current_n);
chnWrite(pkt_out, (uint8_t *)buf, out);
pktWrite( (uint8_t *)buf, out);
#endif /* AFSK_ERROR_TYPE == AFSK_SQRT_ERROR */
#endif /* QCORR_MAG_USE_FLOAT */
}
@ -540,7 +540,7 @@ void calc_qcorr_magnitude(AFSKDemodDriver *myDriver) {
} else {
out = chsnprintf(buf, sizeof(buf), "%i\r\n", raw_mag);
}
chnWrite(pkt_out, (uint8_t *)buf, out);
pktWrite( (uint8_t *)buf, out);
#endif
}
}
@ -576,7 +576,7 @@ void filter_qcorr_magnitude(AFSKDemodDriver *myDriver) {
decoder->filter_bins[i].raw_mag,
decoder->filter_bins[i].filtered_mag);
}
chnWrite(pkt_out, (uint8_t *)buf, out);
pktWrite( (uint8_t *)buf, out);
#endif
}
}
@ -619,7 +619,7 @@ void evaluate_qcorr_tone(AFSKDemodDriver *myDriver) {
char buf[200];
int out = chsnprintf(buf, sizeof(buf), "%i, %i\r\n",
mark, space);
chnWrite(pkt_out, (uint8_t *)buf, out);
pktWrite( (uint8_t *)buf, out);
#endif
}
@ -660,7 +660,7 @@ static void setup_qcorr_prefilter(qcorr_decoder_t *decoder) {
char buf[80];
int out = chsnprintf(buf, sizeof(buf),
"PRE FILTER COEFF %f %x\r\n", coeff_total_f32, coeff_total_q31);
chnWrite(pkt_out, (uint8_t *)buf, out);
pktWrite( (uint8_t *)buf, out);
#endif
}
@ -791,7 +791,7 @@ static void setup_qcorr_magfilter(qcorr_decoder_t *decoder) {
char buf[80];
int out = chsnprintf(buf, sizeof(buf),
"MAG FILTER COEFF %f %x\r\n", bin_coeff_total_f32, bin_coeff_total_q31);
chnWrite(pkt_out, (uint8_t *)buf, out);
pktWrite( (uint8_t *)buf, out);
#endif
}
#endif

Wyświetl plik

@ -23,6 +23,6 @@
binary_semaphore_t debug_out_sem;
BaseSequentialStream* pkt_out = (BaseSequentialStream*)SERIAL_CFG_DEBUG_DRIVER;
//BaseSequentialStream* pkt_out = (BaseSequentialStream*)SERIAL_CFG_DEBUG_DRIVER;
/** @} */

Wyświetl plik

@ -79,7 +79,7 @@
#define EVT_PWM_STREAM_OPEN EVENT_MASK(EVT_PRIORITY_BASE + 16)
#define EVT_PWM_FIFO_REMNANT EVENT_MASK(EVT_PRIORITY_BASE + 17)
#define EVT_PWM_STREAM_CLOSE EVENT_MASK(EVT_PRIORITY_BASE + 18)
//#define EVT_PWM_STREAM_CLOSE EVENT_MASK(EVT_PRIORITY_BASE + 18)
#define EVT_PKT_INVALID_FRAME EVENT_MASK(EVT_PRIORITY_BASE + 19)
#define EVT_PKT_FAILED_CB_THD EVENT_MASK(EVT_PRIORITY_BASE + 20)
@ -104,9 +104,8 @@
#define DEC_COMMAND_CLOSE EVENT_MASK(EVT_PRIORITY_BASE + 2)
#define DEC_DIAG_OUT_END EVENT_MASK(EVT_PRIORITY_BASE + 3)
/* Reserved system event broadcast IDs (set mask in user threads level). */
//#define CONSOLE_SHELL_EVT EVT_PRIORITY_BASE + 0
#define CONSOLE_CHANNEL_EVT EVT_PRIORITY_BASE + 16
/* Console thread event masks. */
#define CONSOLE_CHANNEL_EVT EVENT_MASK(EVT_PRIORITY_BASE + 0)
/* Response thread event masks (from decoder to initiator). */
#define DEC_OPEN_EXEC EVENT_MASK(EVT_PRIORITY_BASE + 15)
@ -115,12 +114,20 @@
#define DEC_CLOSE_EXEC EVENT_MASK(EVT_PRIORITY_BASE + 18)
#define USR_COMMAND_ACK EVENT_MASK(EVT_PRIORITY_BASE + 19)
/* Diagnostic event masks. */
#define EVT_DIAG_OUT_END EVENT_MASK(EVT_PRIORITY_BASE + 20)
#define EVT_PKT_OUT_END EVENT_MASK(EVT_PRIORITY_BASE + 21)
#define EVT_STATUS_CLEAR EVT_NONE
/**
* PWM stream status bits.
*/
typedef uint32_t statusmask_t; /**< Mask of status identifiers. */
/**
* @brief Returns an event mask from an event identifier.
*/
#define STATUS_MASK(sid) ((statusmask_t)1 << (statusmask_t)(sid))
#define STA_AFSK_DECODE_RESET STATUS_MASK(0)
#define useCCM __attribute__((section(".ram4")))
#ifdef PKT_IS_TEST_PROJECT