kopia lustrzana https://github.com/DL7AD/pecanpico10
More WIP on radio manager refactoring.
- RSSI now reported per RX packet - TCXO update reworked - Split of external and internal radio manager commands WIPDevelopment
rodzic
761f71d9d6
commit
3195ccf0aa
|
@ -358,8 +358,8 @@ THD_FUNCTION(pktConsole, arg) {
|
|||
* If the channel disconnected go to IDLE else resume TRACE
|
||||
*/
|
||||
if(CON_DEBUG_TRACE)
|
||||
TRACE_DEBUG("CON > Terminating shell thread %x with events %x & flags %x"
|
||||
" in state %s",
|
||||
TRACE_DEBUG("CON > Terminating shell thread %x with events"
|
||||
" %x & flags %x in state %s",
|
||||
shelltp, evt, evtf, console_state_name(console_state));
|
||||
if(shelltp != NULL) {
|
||||
chEvtUnregister(&shell_terminated, &shell_el);
|
||||
|
|
|
@ -1722,10 +1722,10 @@ THD_FUNCTION(bloc_si_fifo_feeder_afsk, arg) {
|
|||
|
||||
/* Wait for receive stream in progress. Terminate on timeout. */
|
||||
#if PKT_RTO_USE_SETTING == TRUE
|
||||
pktSetReceiveInactive(radio, rto->radio_dat.rssi == PKT_SI446X_NO_CCA_RSSI
|
||||
pktSetReceiveStreamInactive(radio, rto->radio_dat.rssi == PKT_SI446X_NO_CCA_RSSI
|
||||
? TIME_IMMEDIATE : TIME_MS2I(300));
|
||||
#else
|
||||
pktSetReceiveInactive(radio, rto->squelch == PKT_SI446X_NO_CCA_RSSI
|
||||
pktSetReceiveStreamInactive(radio, rto, rto->squelch == PKT_SI446X_NO_CCA_RSSI
|
||||
? TIME_IMMEDIATE : TIME_MS2I(300));
|
||||
#endif
|
||||
/*
|
||||
|
@ -1855,7 +1855,7 @@ THD_FUNCTION(bloc_si_fifo_feeder_afsk, arg) {
|
|||
}
|
||||
|
||||
/* Wait for receive stream in progress. Terminate on timeout. */
|
||||
(void)pktSetReceiveInactive(radio, rto->squelch == PKT_SI446X_NO_CCA_RSSI
|
||||
(void)pktSetReceiveStreamInactive(radio, rto->squelch == PKT_SI446X_NO_CCA_RSSI
|
||||
? TIME_IMMEDIATE : TIME_MS2I(300));
|
||||
|
||||
/*
|
||||
|
@ -2232,10 +2232,10 @@ THD_FUNCTION(bloc_si_fifo_feeder_fsk, arg) {
|
|||
|
||||
/* Stop packet system reception. */
|
||||
#if PKT_RTO_USE_SETTING == TRUE
|
||||
pktSetReceiveInactive(radio, rto->radio_dat.rssi == PKT_SI446X_NO_CCA_RSSI
|
||||
pktSetReceiveStreamInactive(radio, rto->radio_dat.rssi == PKT_SI446X_NO_CCA_RSSI
|
||||
? TIME_IMMEDIATE : TIME_MS2I(300));
|
||||
#else
|
||||
pktSetReceiveInactive(radio, rto->squelch == PKT_SI446X_NO_CCA_RSSI
|
||||
pktSetReceiveStreamInactive(radio, rto, rto->squelch == PKT_SI446X_NO_CCA_RSSI
|
||||
? TIME_IMMEDIATE : TIME_MS2I(300));
|
||||
#endif
|
||||
/* Initialize radio before any commands as it may have been powered down. */
|
||||
|
@ -2354,7 +2354,7 @@ THD_FUNCTION(bloc_si_fifo_feeder_fsk, arg) {
|
|||
}
|
||||
|
||||
/* Wait for receive stream in progress. Terminate on timeout. */
|
||||
(void)pktSetReceiveInactive(radio, rto->squelch == PKT_SI446X_NO_CCA_RSSI
|
||||
(void)pktSetReceiveStreamInactive(radio, rto->squelch == PKT_SI446X_NO_CCA_RSSI
|
||||
? TIME_IMMEDIATE : TIME_MS2I(300));
|
||||
|
||||
/*
|
||||
|
|
|
@ -852,7 +852,8 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
|
|||
switch(stream.pwm.valley) {
|
||||
case PWM_TERM_PWM_STOP: {
|
||||
/*
|
||||
* The PWM stream has been aborted by a stop request.
|
||||
* This may not be found if HDLC closing flag happened already.
|
||||
* If found the PWM stream has been aborted by a stop request.
|
||||
* Can be TX or a service stop as part of closing a service.
|
||||
* PWM stop places an in-band message in the PWM stream if open.
|
||||
* The decoder will then (eventually) process the in-band message.
|
||||
|
|
|
@ -151,7 +151,7 @@ void pktDetachRadio(const radio_unit_t radio) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Enables PWM stream from radio.
|
||||
* @brief Enables PWM stream from radio for DSP.
|
||||
* @post The ICU is configured and started.
|
||||
* @post The ports and timers for CCA input are configured.
|
||||
*
|
||||
|
@ -163,46 +163,66 @@ void pktEnableRadioStream(const radio_unit_t radio) {
|
|||
|
||||
packet_svc_t *myHandler = pktGetServiceObject(radio);
|
||||
|
||||
/* Is the AFSK decoder active? */
|
||||
if(myHandler->rx_state != PACKET_RX_ENABLED)
|
||||
return;
|
||||
/*
|
||||
* Is the AFSK decoder active?
|
||||
* TODO: Need to rationalise the tests.
|
||||
* This should be AFSK or other DSP based modulation only.
|
||||
*/
|
||||
|
||||
AFSKDemodDriver *myDemod = (AFSKDemodDriver *)myHandler->rx_link_control;
|
||||
chDbgAssert(myDemod != NULL, "no link controller");
|
||||
chDbgAssert(myDemod->icudriver != NULL, "no ICU driver");
|
||||
switch(myHandler->rx_link_type) {
|
||||
|
||||
switch(myDemod->icustate) {
|
||||
case PKT_PWM_INIT: {
|
||||
/* Enable CCA callback. */
|
||||
const ICUConfig *icucfg = pktLLDradioStreamEnable(radio,
|
||||
(palcallback_t)pktRadioCCAInput);
|
||||
case MOD_AFSK: {
|
||||
AFSKDemodDriver *myDemod = (AFSKDemodDriver *)myHandler->rx_link_control;
|
||||
chDbgAssert(myDemod != NULL, "no link controller");
|
||||
chDbgAssert(myDemod->icudriver != NULL, "no ICU driver");
|
||||
|
||||
/* Start ICU and start capture. */
|
||||
icuStart(myDemod->icudriver, icucfg);
|
||||
icuStartCapture(myDemod->icudriver);
|
||||
myDemod->icustate = PKT_PWM_READY;
|
||||
return;
|
||||
switch(myDemod->icustate) {
|
||||
case PKT_PWM_INIT: {
|
||||
/* Enable CCA callback. */
|
||||
const ICUConfig *icucfg = pktLLDradioStreamEnable(radio,
|
||||
(palcallback_t)pktRadioCCAInput);
|
||||
|
||||
}
|
||||
case PKT_PWM_STOP: {
|
||||
/* Enable CCA callback. */
|
||||
pktLLDradioStreamEnable(radio, (palcallback_t)pktRadioCCAInput);
|
||||
/* Start ICU and start capture. */
|
||||
icuStart(myDemod->icudriver, icucfg);
|
||||
icuStartCapture(myDemod->icudriver);
|
||||
myDemod->icustate = PKT_PWM_READY;
|
||||
return;
|
||||
} /* End case PKT_PWM_INIT. */
|
||||
|
||||
/* Start ICU capture. */
|
||||
icuStartCapture(myDemod->icudriver);
|
||||
myDemod->icustate = PKT_PWM_READY;
|
||||
case PKT_PWM_STOP: {
|
||||
/* Enable CCA callback. */
|
||||
(void)pktLLDradioStreamEnable(radio, (palcallback_t)pktRadioCCAInput);
|
||||
|
||||
/* Start ICU capture. */
|
||||
icuStartCapture(myDemod->icudriver);
|
||||
myDemod->icustate = PKT_PWM_READY;
|
||||
return;
|
||||
} /* End case PKT_PWM_STOP. */
|
||||
|
||||
case PKT_PWM_READY:
|
||||
return;
|
||||
|
||||
case PKT_PWM_WAITING:
|
||||
case PKT_PWM_ACTIVE: {
|
||||
chDbgAssert(false, "wrong PWM state");
|
||||
return;
|
||||
} /* End case PKT_PWM_WAITING or PKT_PWM_ACTIVE. */
|
||||
} /* End switch on ICU state. */
|
||||
} /* End case MOD_AFSK. */
|
||||
|
||||
case MOD_NONE:
|
||||
case MOD_CW:
|
||||
case MOD_2FSK_300:
|
||||
case MOD_2FSK_9k6:
|
||||
case MOD_2FSK_19k2:
|
||||
case MOD_2FSK_38k4:
|
||||
case MOD_2FSK_57k6:
|
||||
case MOD_2FSK_76k8:
|
||||
case MOD_2FSK_96k:
|
||||
case MOD_2FSK_115k2: {
|
||||
return;
|
||||
}
|
||||
|
||||
case PKT_PWM_READY:
|
||||
return;
|
||||
|
||||
case PKT_PWM_WAITING:
|
||||
case PKT_PWM_ACTIVE: {
|
||||
chDbgAssert(false, "wrong PWM state");
|
||||
return;
|
||||
}
|
||||
} /* End switch. */
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -228,11 +248,6 @@ void pktDisableRadioStream(const radio_unit_t radio) {
|
|||
/* Is the receiver active? */
|
||||
if(!pktIsReceiveEnabled(radio))
|
||||
return;
|
||||
/* if(myHandler->rx_state != PACKET_RX_ENABLED)
|
||||
return;*/
|
||||
AFSKDemodDriver *myDemod = (AFSKDemodDriver *)myHandler->rx_link_control;
|
||||
chDbgAssert(myDemod != NULL, "no link controller");
|
||||
chDbgAssert(myDemod->icudriver != NULL, "no ICU driver");
|
||||
|
||||
/* Process under locked. */
|
||||
chSysLock();
|
||||
|
@ -240,6 +255,10 @@ void pktDisableRadioStream(const radio_unit_t radio) {
|
|||
|
||||
case MOD_AFSK: {
|
||||
|
||||
AFSKDemodDriver *myDemod = (AFSKDemodDriver *)myHandler->rx_link_control;
|
||||
chDbgAssert(myDemod != NULL, "no link controller");
|
||||
chDbgAssert(myDemod->icudriver != NULL, "no ICU driver");
|
||||
|
||||
switch(myDemod->icustate) {
|
||||
case PKT_PWM_WAITING:
|
||||
case PKT_PWM_ACTIVE: {
|
||||
|
@ -262,7 +281,6 @@ void pktDisableRadioStream(const radio_unit_t radio) {
|
|||
pktClosePWMchannelI(myDemod->icudriver, EVT_NONE, PWM_TERM_PWM_STOP);
|
||||
|
||||
myDemod->icustate = PKT_PWM_STOP;
|
||||
|
||||
/*
|
||||
* Reschedule to avoid a "priority order violation".
|
||||
*/
|
||||
|
@ -297,6 +315,7 @@ void pktDisableRadioStream(const radio_unit_t radio) {
|
|||
/* Stop ICU capture. */
|
||||
icuStopCaptureI(myDemod->icudriver);
|
||||
myDemod->icustate = PKT_PWM_STOP;
|
||||
|
||||
chSysUnlock();
|
||||
return;
|
||||
} /* End case PKT_PWM_READY. */
|
||||
|
@ -360,7 +379,8 @@ void pktRadioJammingReset(ICUDriver *myICU) {
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
void pktClosePWMchannelI(ICUDriver *myICU, eventflags_t evt, pwm_code_t reason) {
|
||||
void pktClosePWMchannelI(ICUDriver *myICU, eventflags_t evt,
|
||||
pwm_code_t reason) {
|
||||
/* Stop posting data and write end marker. */
|
||||
AFSKDemodDriver *myDemod = myICU->link;
|
||||
packet_svc_t *myHandler = myDemod->packet_handler;
|
||||
|
@ -783,64 +803,45 @@ void pktRadioCCAInput(ICUDriver *myICU) {
|
|||
return;
|
||||
}
|
||||
|
||||
#if PKT_RTO_USE_SETTING == TRUE
|
||||
/**
|
||||
* Callback after radio manager gets RSSI from radio
|
||||
*/
|
||||
static void pktRadioRSSIreadCB(radio_task_object_t *rt) {
|
||||
AFSKDemodDriver *myDemod = rt->handler->rx_link_control;
|
||||
|
||||
radio_pwm_fifo_t *myFIFO = myDemod->active_radio_stream;
|
||||
if(myFIFO == NULL)
|
||||
return false;
|
||||
/*
|
||||
* Is the callback still good for current RX sequence?
|
||||
* Can be out of sync if the radio manager is delayed or PWM is jittery.
|
||||
*/
|
||||
if(myFIFO->seq_num == rt->radio_dat.rt_seq)
|
||||
/* Set the RSSI or flag unable to read. */
|
||||
myFIFO->rssi = (rt->result == MSG_OK) ? rt->rssi : 0xFF;
|
||||
}
|
||||
#else
|
||||
/**
|
||||
* Callback after radio manager gets RSSI from radio
|
||||
*/
|
||||
static bool pktRadioRSSIreadCB(radio_task_object_t *rt) {
|
||||
AFSKDemodDriver *myDemod = rt->handler->rx_link_control;
|
||||
|
||||
#if PKT_USE_OPENING_RSSI == TRUE
|
||||
radio_pwm_fifo_t *myFIFO = myDemod->active_radio_stream;
|
||||
if(myFIFO != NULL) {
|
||||
/*
|
||||
* Is the callback still good for current RX sequence?
|
||||
* Can be out of sync if the radio manager is delayed or PWM is jittery.
|
||||
*/
|
||||
#if PKT_RTO_USE_SETTING == TRUE
|
||||
if(myFIFO->seq_num == rt->radio_dat.seq_num) {
|
||||
#else
|
||||
if(myFIFO->seq_num == rt->rt_seq) {
|
||||
#endif
|
||||
/* Set the RSSI or flag unable to read. */
|
||||
myFIFO->rssi = (rt->result == MSG_OK) ? rt->rssi : 0xFF;
|
||||
}
|
||||
}
|
||||
radio_pwm_fifo_t *myFIFO = myDemod->active_radio_stream;
|
||||
if(myFIFO == NULL)
|
||||
return false;
|
||||
/*
|
||||
* Is the callback still good for current RX sequence?
|
||||
* Can be out of sync if the radio manager is delayed or PWM is jittery.
|
||||
*/
|
||||
if(myFIFO->seq_num == rt->rt_seq)
|
||||
/* Set the RSSI or flag unable to read. */
|
||||
myFIFO->rssi = (rt->result == MSG_OK) ? rt->rssi : 0xFF;
|
||||
return false;
|
||||
#else
|
||||
/* Get the current PWM queue object. */
|
||||
radio_pwm_object_t *myObject =
|
||||
myDemod->active_radio_stream->radio_pwm_queue;
|
||||
if(myObject == NULL)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* Write the RSSI captured in-band message to the current queue object.
|
||||
* When the decoder encounters this in-band it fetches the RSSI from the stream FIFO object.
|
||||
* TODO: It would be possible to have an averaged RSSI.
|
||||
* Currently only the opening period RSSI is captured.
|
||||
* RSSI could be captured at intervals throughout the PWM stream.
|
||||
*/
|
||||
|
||||
#if USE_12_BIT_PWM == TRUE
|
||||
byte_packed_pwm_t pack = {{PWM_IN_BAND_PREFIX, PWM_INF_RADIO_RSSI, 0}};
|
||||
#else
|
||||
byte_packed_pwm_t pack = {{PWM_IN_BAND_PREFIX, PWM_INF_RADIO_RSSI}};
|
||||
#endif
|
||||
//return false;
|
||||
chSysLock();
|
||||
/* Write the RSSI message to the PWM queue. */
|
||||
msg_t qs = pktWritePWMQueueI(&myObject->queue, pack);
|
||||
if(qs == MSG_OK) {
|
||||
myObject->rssi = (radio_signal_t)rt->result;
|
||||
} else {
|
||||
myObject->rssi = 0;
|
||||
}
|
||||
chSysUnlock();
|
||||
}
|
||||
/* Indicate this RTO can be released. */
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Width callback from ICU driver.
|
||||
|
@ -883,7 +884,7 @@ void pktRadioICUWidth(ICUDriver *myICU) {
|
|||
msg_t msg = pktQueuePriorityRadioCommandI(radio,
|
||||
PKT_RADIO_RX_RSSI,
|
||||
&rp,
|
||||
(radio_task_cb_t)pktRadioRSSIreadCB);
|
||||
pktRadioRSSIreadCB);
|
||||
#else
|
||||
radio_task_object_t rt = myDemod->packet_handler->radio_rx_config;
|
||||
|
||||
|
|
Plik diff jest za duży
Load Diff
|
@ -83,17 +83,20 @@ typedef struct indicatorIO {
|
|||
typedef enum radioCommand {
|
||||
PKT_RADIO_RX_OPEN,
|
||||
PKT_RADIO_RX_START,
|
||||
PKT_RADIO_RX_START_UNLOCK,
|
||||
PKT_RADIO_RX_STOP,
|
||||
PKT_RADIO_RX_STOP_LOCK,
|
||||
PKT_RADIO_TX_SEND,
|
||||
PKT_RADIO_RX_CLOSE,
|
||||
PKT_RADIO_TX_DONE,
|
||||
PKT_RADIO_MGR_CLOSE,
|
||||
/* Internal RM tasks only. */
|
||||
PKT_RADIO_RX_DECODE,
|
||||
PKT_RADIO_RX_RSSI,
|
||||
PKT_RADIO_RX_START_UNLOCK,
|
||||
PKT_RADIO_RX_STOP_LOCK,
|
||||
PKT_RADIO_TCXO_UPDATE
|
||||
} radio_command_t;
|
||||
|
||||
#define PKT_RADIO_TASK_MAX PKT_RADIO_MGR_CLOSE
|
||||
/**
|
||||
* Forward declare structure types.
|
||||
*/
|
||||
|
@ -115,16 +118,6 @@ typedef bool (*radio_task_cb_t)(radio_task_object_t *task_object);
|
|||
|
||||
|
||||
#include "ax25_pad.h"
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/*typedef struct radioSettings {
|
||||
radio_mod_t type;
|
||||
radio_freq_hz_t base_frequency;
|
||||
radio_chan_hz_t step_hz;
|
||||
radio_ch_t channel;
|
||||
radio_squelch_t squelch;
|
||||
} radio_settings_t;*/
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -208,10 +201,6 @@ extern "C" {
|
|||
#endif
|
||||
thread_t *pktRadioManagerCreate(const radio_unit_t radio);
|
||||
msg_t pktRadioManagerRelease(const radio_unit_t radio);
|
||||
msg_t pktStartRadioReceive(const radio_unit_t radio,
|
||||
radio_task_object_t *rto, sysinterval_t timeout);
|
||||
msg_t pktStopRadioReceive(const radio_unit_t radio,
|
||||
sysinterval_t timeout);
|
||||
void pktRadioManager(void *arg);
|
||||
msg_t pktGetRadioTaskObject(const radio_unit_t radio,
|
||||
const sysinterval_t timeout,
|
||||
|
@ -266,20 +255,17 @@ extern "C" {
|
|||
const radio_chan_hz_t step,
|
||||
const radio_ch_t chan,
|
||||
const radio_mode_t mode);
|
||||
msg_t pktSetReceiveInactive(const radio_unit_t radio,
|
||||
sysinterval_t timeout);
|
||||
void pktRadioStartDecoder(const radio_unit_t radio);
|
||||
void pktRadioStopDecoder(const radio_unit_t radio);
|
||||
msg_t pktSetReceiveStreamInactive(const radio_unit_t radio,
|
||||
const radio_task_object_t *rto,
|
||||
const sysinterval_t timeout);
|
||||
void pktRadioSendComplete(radio_task_object_t *rto,
|
||||
thread_t *thread);
|
||||
thread_t *thread);
|
||||
ICUDriver *pktLLDradioAttachStream(const radio_unit_t radio);
|
||||
void pktLLDradioDetachStream(const radio_unit_t radio);
|
||||
const ICUConfig *pktLLDradioStreamEnable(const radio_unit_t radio,
|
||||
palcallback_t cb);
|
||||
palcallback_t cb);
|
||||
void pktLLDradioStreamDisableI(const radio_unit_t radio);
|
||||
bool pktRadioGetInProgress(const radio_unit_t radio);
|
||||
void pktStartDecoder(const radio_unit_t radio);
|
||||
void pktStopDecoder(const radio_unit_t radio);
|
||||
int pktDisplayFrequencyCode(radio_freq_hz_t code, char *buf,
|
||||
size_t size);
|
||||
const radio_config_t *pktGetRadioData(radio_unit_t radio);
|
||||
|
|
|
@ -553,6 +553,11 @@ msg_t pktOpenReceiveService(const radio_unit_t radio,
|
|||
if(handler->state != PACKET_READY || cb == NULL)
|
||||
return MSG_ERROR;
|
||||
|
||||
/*
|
||||
* TODO: Move state checks into radio manager.
|
||||
* Use RM internal callbacks to transition between states.
|
||||
*/
|
||||
|
||||
switch(handler->rx_state) {
|
||||
/**
|
||||
*
|
||||
|
@ -631,6 +636,7 @@ msg_t pktOpenReceiveService(const radio_unit_t radio,
|
|||
|
||||
/* TODO: Check other parameters match current values in rx_config.
|
||||
* Encoding, frequency, step... actually only encoding matters.
|
||||
* In that case close the channel and re-open with new encoding.
|
||||
*/
|
||||
#if PKT_RTO_USE_SETTING == TRUE
|
||||
msg_t msg = pktQueueRadioCommand(radio,
|
||||
|
@ -662,74 +668,7 @@ msg_t pktOpenReceiveService(const radio_unit_t radio,
|
|||
return MSG_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables a packet decoder.
|
||||
* @pre The packet channel must have been opened.
|
||||
* @post The packet decoder is running.
|
||||
*
|
||||
* @param[in] radio unit ID.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void pktStartDecoder(const radio_unit_t radio) {
|
||||
|
||||
packet_svc_t *handler = pktGetServiceObject(radio);
|
||||
|
||||
if(!pktIsReceiveReady(radio)) {
|
||||
/* Wrong state. */
|
||||
chDbgAssert(false, "wrong state for decoder start");
|
||||
return;
|
||||
}
|
||||
/* Set state before starting decoder. */
|
||||
//handler->rx_state = PACKET_RX_ENABLED;
|
||||
event_listener_t el;
|
||||
event_source_t *esp;
|
||||
|
||||
switch(handler->radio_rx_config.type) {
|
||||
case MOD_AFSK: {
|
||||
|
||||
esp = pktGetEventSource((AFSKDemodDriver *)handler->rx_link_control);
|
||||
|
||||
pktRegisterEventListener(esp, &el, USR_COMMAND_ACK, DEC_START_EXEC);
|
||||
|
||||
thread_t *the_decoder =
|
||||
((AFSKDemodDriver *)handler->rx_link_control)->decoder_thd;
|
||||
chEvtSignal(the_decoder, DEC_COMMAND_START);
|
||||
break;
|
||||
} /* End case. */
|
||||
|
||||
case MOD_2FSK_9k6:
|
||||
case MOD_2FSK_19k2:
|
||||
case MOD_2FSK_38k4:
|
||||
case MOD_2FSK_57k6:
|
||||
case MOD_2FSK_76k8:
|
||||
case MOD_2FSK_96k:
|
||||
case MOD_2FSK_115k2: {
|
||||
return;
|
||||
}
|
||||
|
||||
case MOD_CW: {
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
} /* End switch. */
|
||||
|
||||
/* Wait for the decoder to start. */
|
||||
eventflags_t evt;
|
||||
do {
|
||||
/* In reality this is redundant as the only masked event is START. */
|
||||
chEvtWaitAny(USR_COMMAND_ACK);
|
||||
|
||||
/*
|
||||
* Wait for correct event at source.
|
||||
* The decoder has attached the stream and started.
|
||||
*/
|
||||
evt = chEvtGetAndClearFlags(&el);
|
||||
} while (evt != DEC_START_EXEC);
|
||||
pktUnregisterEventListener(esp, &el);
|
||||
}
|
||||
|
||||
#if PKT_RTO_USE_SETTING != TRUE
|
||||
/**
|
||||
|
@ -797,68 +736,7 @@ msg_t pktDisableDataReception(radio_unit_t radio) {
|
|||
return MSG_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables a packet decoder.
|
||||
* @pre The packet channel must be running.
|
||||
* @post The packet decoder is stopped.
|
||||
*
|
||||
* @param[in] radio unit ID.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void pktStopDecoder(radio_unit_t radio) {
|
||||
|
||||
packet_svc_t *handler = pktGetServiceObject(radio);
|
||||
|
||||
if(!pktIsReceiveEnabled(radio)) {
|
||||
/* Wrong state. */
|
||||
chDbgAssert(false, "wrong state for decoder stop");
|
||||
return;
|
||||
}
|
||||
event_listener_t el;
|
||||
event_source_t *esp;
|
||||
|
||||
switch(handler->radio_rx_config.type) {
|
||||
case MOD_AFSK: {
|
||||
esp = pktGetEventSource((AFSKDemodDriver *)handler->rx_link_control);
|
||||
|
||||
pktRegisterEventListener(esp, &el, USR_COMMAND_ACK, DEC_STOP_EXEC);
|
||||
|
||||
thread_t *the_decoder =
|
||||
((AFSKDemodDriver *)handler->rx_link_control)->decoder_thd;
|
||||
chEvtSignal(the_decoder, DEC_COMMAND_STOP);
|
||||
break;
|
||||
} /* End case. */
|
||||
|
||||
case MOD_2FSK_9k6:
|
||||
case MOD_2FSK_19k2:
|
||||
case MOD_2FSK_38k4:
|
||||
case MOD_2FSK_57k6:
|
||||
case MOD_2FSK_76k8:
|
||||
case MOD_2FSK_96k:
|
||||
case MOD_2FSK_115k2: {
|
||||
return;
|
||||
}
|
||||
|
||||
case MOD_CW:
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
} /* End switch. */
|
||||
|
||||
/* Wait for the decoder to stop. */
|
||||
eventflags_t evt;
|
||||
do {
|
||||
chEvtWaitAny(USR_COMMAND_ACK);
|
||||
|
||||
/* Wait for correct event at source.
|
||||
*/
|
||||
evt = chEvtGetAndClearFlags(&el);
|
||||
} while (evt != DEC_STOP_EXEC);
|
||||
pktUnregisterEventListener(esp, &el);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* @brief Closes a packet receive service.
|
||||
* @pre The packet service must have been stopped.
|
||||
|
@ -904,7 +782,7 @@ msg_t pktCloseRadioReceive(radio_unit_t radio) {
|
|||
pktAddEventFlags(handler, EVT_PKT_CHANNEL_CLOSE);
|
||||
return MSG_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* @brief Stores receive data in a packet channel buffer.
|
||||
* @post The character is stored and the internal buffer index is updated.
|
||||
|
@ -1082,7 +960,21 @@ THD_FUNCTION(pktCallback, arg) {
|
|||
}
|
||||
|
||||
/*
|
||||
* This function was originally a factory FIFO used in a packet RX mailbox posting system.
|
||||
* RX packets were posted to the FIFO and a consumer thread polled the mailbox.
|
||||
*
|
||||
* Now all packets are dispatched exclusively via a callback mechanism.
|
||||
* The packet control objects and linked AX25 buffers are taken directly from heap.
|
||||
* This is unthrottled but seeing as packet RX is serial it isn't a risk.
|
||||
* Only opportunity for excess memory use would be if callbacks don't release.
|
||||
* In that case there would be a lot of callback threads running as well consuming memory.
|
||||
*
|
||||
* If implementing a fixed size RX buffer pool (non factory) to limit max RX packets outstanding this could be reworked.
|
||||
* It would also be possible to simply check the rx_count variable and reject a new packet creation.
|
||||
* That would be a whole lot simpler....
|
||||
*
|
||||
* An alternative would be to have a common pool of buffer control objects created when the service is created.
|
||||
* Then each radio would get packet buffers and use an object from the buffer control object pool.
|
||||
*/
|
||||
dyn_objects_fifo_t *pktIncomingBufferPoolCreate(radio_unit_t radio) {
|
||||
|
||||
|
@ -1114,6 +1006,9 @@ dyn_objects_fifo_t *pktIncomingBufferPoolCreate(radio_unit_t radio) {
|
|||
|
||||
/* Save the factory FIFO reference. */
|
||||
handler->the_packet_fifo = dyn_fifo;
|
||||
/* Initialize packet buffer pointer. */
|
||||
handler->active_packet_object = NULL;
|
||||
return dyn_fifo;
|
||||
#else
|
||||
dyn_objects_fifo_t *dyn_fifo = NULL;
|
||||
#endif
|
||||
|
|
|
@ -105,6 +105,7 @@ typedef struct packetHandlerData {
|
|||
radio_unit_t radio;
|
||||
|
||||
xtal_osc_t xtal; /**< XO frequency of main clock. */
|
||||
bool xo_update; /**< XO update in progress. */
|
||||
|
||||
/**
|
||||
* @brief Radio part number.
|
||||
|
@ -252,11 +253,11 @@ extern "C" {
|
|||
bool pktSystemDeinit(void);
|
||||
bool pktServiceCreate(const radio_unit_t radio);
|
||||
bool pktServiceRelease(const radio_unit_t radio);
|
||||
msg_t pktOpenRadioReceive(const radio_unit_t radio,
|
||||
/* msg_t pktOpenRadioReceive(const radio_unit_t radio,
|
||||
const radio_mod_t encoding,
|
||||
const radio_freq_hz_t frequency,
|
||||
const radio_chan_hz_t ch_step,
|
||||
const sysinterval_t timeout);
|
||||
const sysinterval_t timeout);*/
|
||||
#if PKT_RTO_USE_SETTING == TRUE
|
||||
msg_t pktEnableDataReception(const radio_unit_t radio,
|
||||
const radio_ch_t channel,
|
||||
|
@ -272,10 +273,10 @@ extern "C" {
|
|||
const radio_squelch_t sq,
|
||||
const pkt_buffer_cb_t cb,
|
||||
const sysinterval_t to);
|
||||
void pktStartDecoder(const radio_unit_t radio);
|
||||
msg_t pktStartDecoder(const radio_unit_t radio);
|
||||
msg_t pktDisableDataReception(const radio_unit_t radio);
|
||||
void pktStopDecoder(const radio_unit_t radio);
|
||||
msg_t pktCloseRadioReceive(const radio_unit_t radio);
|
||||
//msg_t pktCloseRadioReceive(const radio_unit_t radio);
|
||||
bool pktStoreReceiveData(pkt_data_object_t *buffer,
|
||||
ax25char_t data);
|
||||
eventflags_t pktDispatchReceivedBuffer(pkt_data_object_t *pkt_buffer);
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
|
||||
/* Extend standard OS result codes. */
|
||||
#define MSG_ERROR (msg_t)-3 /**< @brief Error condition. */
|
||||
#define MSG_LOCKED (msg_t)-4 /**< @brief Resource locked. */
|
||||
|
||||
/* General event definitions. */
|
||||
#define EVT_NONE 0
|
||||
|
@ -261,7 +262,9 @@ static inline int8_t pktReadGPIOline(ioline_t line) {
|
|||
* @param[in] radio radio unit ID.
|
||||
* @param[in] task pointer to the task descriptor.
|
||||
* this is usually a persistent descriptor in the handler.
|
||||
* @param[in] timeout to wait for a radio object to be available.
|
||||
* @param[in] cmd the radio task to be queued
|
||||
* @param[in] cfg pointer to radio configuration
|
||||
* @param[in] timeout expressed in sysinterval units.
|
||||
* @param[in] cb function to call with result (can be NULL).
|
||||
*
|
||||
* @return status of operation
|
||||
|
@ -279,7 +282,10 @@ static inline msg_t pktQueueRadioCommand(const radio_unit_t radio,
|
|||
#endif
|
||||
const sysinterval_t timeout,
|
||||
const radio_task_cb_t cb) {
|
||||
|
||||
#if PKT_RTO_USE_SETTING == TRUE
|
||||
if(cmd > PKT_RADIO_TASK_MAX)
|
||||
return MSG_ERROR;
|
||||
#endif
|
||||
radio_task_object_t *rt = NULL;
|
||||
#if PKT_RTO_USE_SETTING != TRUE
|
||||
msg_t msg = pktGetRadioTaskObject(radio, timeout, &rt);
|
||||
|
@ -306,8 +312,14 @@ static inline msg_t pktQueueRadioCommand(const radio_unit_t radio,
|
|||
* @param[in] radio radio unit ID.
|
||||
* @param[in] task pointer to the task descriptor.
|
||||
* this is usually a persistent descriptor in the handler.
|
||||
* @param[in] cmd the radio task to be queued
|
||||
* @param[in] cfg pointer to radio configuration
|
||||
* @param[in] cb function to call with result (can be NULL).
|
||||
*
|
||||
* @return status of operation
|
||||
* @retval MSG_OK Command has been queued.
|
||||
* @retval MSG_TIMEOUT No task object available.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static inline msg_t pktQueuePriorityRadioCommandI(const radio_unit_t radio,
|
||||
|
@ -318,6 +330,10 @@ static inline msg_t pktQueuePriorityRadioCommandI(const radio_unit_t radio,
|
|||
const radio_params_t *cfg,
|
||||
#endif
|
||||
const radio_task_cb_t cb) {
|
||||
#if PKT_RTO_USE_SETTING == TRUE
|
||||
if(cmd > PKT_RADIO_TASK_MAX)
|
||||
return MSG_ERROR;
|
||||
#endif
|
||||
radio_task_object_t *rt = NULL;
|
||||
#if PKT_RTO_USE_SETTING != TRUE
|
||||
msg_t msg = pktGetRadioTaskObjectI(radio, &rt);
|
||||
|
@ -344,9 +360,16 @@ static inline msg_t pktQueuePriorityRadioCommandI(const radio_unit_t radio,
|
|||
* @param[in] radio radio unit ID.
|
||||
* @param[in] task pointer to the task descriptor.
|
||||
* this is usually a persistent descriptor in the handler.
|
||||
* @param[in] timeout
|
||||
* @param[in] cmd the radio task to be queued
|
||||
* @param[in] cfg pointer to radio configuration
|
||||
* @param[in] timeout expressed in sysinterval units.
|
||||
* @param[in] cb function to call with result (can be NULL).
|
||||
*
|
||||
* @return status of operation
|
||||
* @retval MSG_OK Command has been queued.
|
||||
* @retval MSG_TIMEOUT No task object available.
|
||||
* @retval MSG_ERROR Command is invalid from outer level.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static inline msg_t pktQueuePriorityRadioCommand(const radio_unit_t radio,
|
||||
|
@ -358,6 +381,10 @@ static inline msg_t pktQueuePriorityRadioCommand(const radio_unit_t radio,
|
|||
#endif
|
||||
const sysinterval_t timeout,
|
||||
const radio_task_cb_t cb) {
|
||||
#if PKT_RTO_USE_SETTING == TRUE
|
||||
if(cmd > PKT_RADIO_TASK_MAX)
|
||||
return MSG_ERROR;
|
||||
#endif
|
||||
radio_task_object_t *rt = NULL;
|
||||
#if PKT_RTO_USE_SETTING != TRUE
|
||||
msg_t msg = pktGetRadioTaskObject(radio, timeout, &rt);
|
||||
|
|
Ładowanie…
Reference in New Issue