kopia lustrzana https://github.com/DL7AD/pecanpico10
				
				
				
			Update to revised version of decoder.
							rodzic
							
								
									8c84dd7c1e
								
							
						
					
					
						commit
						d1843f57a7
					
				| 
						 | 
				
			
			@ -231,9 +231,8 @@ bool pktProcessAFSK(AFSKDemodDriver *myDriver, min_pwmcnt_t current_tone[]) {
 | 
			
		|||
        if(!pktDecodeAFSKSymbol(myDriver))
 | 
			
		||||
          return false;
 | 
			
		||||
      }
 | 
			
		||||
      myDriver->decimation_accumulator -=
 | 
			
		||||
          (icucnt_t)((ICU_COUNT_FREQUENCY / AFSK_BAUD_RATE)
 | 
			
		||||
                       / SYMBOL_DECIMATION);
 | 
			
		||||
      myDriver->decimation_accumulator -= myDriver->decimation_size;
 | 
			
		||||
 | 
			
		||||
    } /* End while. Accumulator has underflowed. */
 | 
			
		||||
  } /* End for. */
 | 
			
		||||
  return true;
 | 
			
		||||
| 
						 | 
				
			
			@ -454,6 +453,9 @@ AFSKDemodDriver *pktCreateAFSKDecoder(packet_rx_t *pktHandler,
 | 
			
		|||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  myDriver->decimation_size = ((pwm_accum_t)ICU_COUNT_FREQUENCY
 | 
			
		||||
                                / (pwm_accum_t)AFSK_BAUD_RATE)
 | 
			
		||||
                                / (pwm_accum_t)SYMBOL_DECIMATION;
 | 
			
		||||
  return myDriver;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -521,8 +523,9 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
 | 
			
		|||
  tprio_t decoder_idle_priority = chThdGetPriorityX();
 | 
			
		||||
 | 
			
		||||
  /* Setup LED for decoder blinker. */
 | 
			
		||||
  palSetLineMode(LINE_BLUE_LED, PAL_MODE_OUTPUT_PUSHPULL);
 | 
			
		||||
  palSetLine(LINE_BLUE_LED);
 | 
			
		||||
  pktSetLineModeDecoderLED();
 | 
			
		||||
 | 
			
		||||
  pktWriteDecoderLED(PAL_HIGH);
 | 
			
		||||
 | 
			
		||||
   /* Wait for start or close of decoder. */
 | 
			
		||||
  myDriver->decoder_state = DECODER_WAIT;
 | 
			
		||||
| 
						 | 
				
			
			@ -550,7 +553,7 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
 | 
			
		|||
          /* Something went wrong if we arrive here. */
 | 
			
		||||
          chSysHalt("ThdExit");
 | 
			
		||||
        }
 | 
			
		||||
        palToggleLine(LINE_BLUE_LED);
 | 
			
		||||
        pktWriteDecoderLED(PAL_TOGGLE);
 | 
			
		||||
        continue;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -581,8 +584,8 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
 | 
			
		|||
        if(fifo_msg != MSG_OK) {
 | 
			
		||||
 | 
			
		||||
          if(++led_count >= DECODER_LED_RATE_POLL) {
 | 
			
		||||
            /* Toggle blue LED. */
 | 
			
		||||
            palToggleLine(LINE_BLUE_LED);
 | 
			
		||||
            /* Toggle decoder LED. */
 | 
			
		||||
            pktWriteDecoderLED(PAL_TOGGLE);
 | 
			
		||||
            led_count = 0;
 | 
			
		||||
          }
 | 
			
		||||
          /* No FIFO posted so loop again. */
 | 
			
		||||
| 
						 | 
				
			
			@ -640,8 +643,8 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
 | 
			
		|||
 | 
			
		||||
        /* Increase thread priority. */
 | 
			
		||||
        (void)chThdSetPriority(DECODER_RUN_PRIORITY);
 | 
			
		||||
        /* Turn on the blue breadboard LED. */
 | 
			
		||||
        palSetLine(LINE_BLUE_LED);
 | 
			
		||||
        /* Turn on the decoder LED. */
 | 
			
		||||
        pktWriteDecoderLED(PAL_HIGH);
 | 
			
		||||
        break;
 | 
			
		||||
      } /* End case DECODER_SESSION_POLL. */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -703,7 +706,6 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
 | 
			
		|||
                myHandler->active_packet_object->packet_size);
 | 
			
		||||
 | 
			
		||||
            /* Close packet and send event. */
 | 
			
		||||
 | 
			
		||||
            eventflags_t evt = (magicCRC == CRC_INCLUSIVE_CONSTANT)
 | 
			
		||||
                    ? EVT_AX25_FRAME_RDY
 | 
			
		||||
                    : EVT_AX25_CRC_ERROR;
 | 
			
		||||
| 
						 | 
				
			
			@ -714,9 +716,9 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
 | 
			
		|||
          }
 | 
			
		||||
          /* Queued data processed OK but not at frame end.
 | 
			
		||||
           * Get next data in queue.
 | 
			
		||||
           * Toggle blue LED.
 | 
			
		||||
           * Toggle decoder LED.
 | 
			
		||||
           */
 | 
			
		||||
          palToggleLine(LINE_BLUE_LED);
 | 
			
		||||
          pktWriteDecoderLED(PAL_TOGGLE);
 | 
			
		||||
          continue;
 | 
			
		||||
        }
 | 
			
		||||
        /* Data not received in time.
 | 
			
		||||
| 
						 | 
				
			
			@ -731,8 +733,6 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
 | 
			
		|||
      } /* End case DECODER_ACTIVE. */
 | 
			
		||||
 | 
			
		||||
      case DECODER_CLOSE: {
 | 
			
		||||
        /* Turn on the breadboard red LED. */
 | 
			
		||||
        //palSetLine(LINE_RED_LED);
 | 
			
		||||
        myDriver->decoder_state = DECODER_SUSPEND;
 | 
			
		||||
        break;
 | 
			
		||||
      } /* End case DECODER_CLOSE. */
 | 
			
		||||
| 
						 | 
				
			
			@ -740,9 +740,6 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
 | 
			
		|||
      case DECODER_TIMEOUT: {
 | 
			
		||||
        pktAddEventFlags(myHandler, EVT_AFSK_DATA_TIMEOUT);
 | 
			
		||||
        myDriver->active_demod_object->status |= EVT_AFSK_DATA_TIMEOUT;
 | 
			
		||||
        /* Turn on the breadboard red LED. */
 | 
			
		||||
        //palSetLine(LINE_RED_LED);
 | 
			
		||||
 | 
			
		||||
        myDriver->decoder_state = DECODER_SUSPEND;
 | 
			
		||||
        break;
 | 
			
		||||
      } /* End case DECODER_TIMEOUT. */
 | 
			
		||||
| 
						 | 
				
			
			@ -751,8 +748,6 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
 | 
			
		|||
      case DECODER_ERROR: {
 | 
			
		||||
        pktAddEventFlags(myHandler, EVT_DECODER_ERROR);
 | 
			
		||||
        myDriver->active_demod_object->status |= EVT_DECODER_ERROR;
 | 
			
		||||
        /* Turn on the breadboard red LED. */
 | 
			
		||||
        //palSetLine(LINE_RED_LED);
 | 
			
		||||
        myDriver->decoder_state = DECODER_SUSPEND;
 | 
			
		||||
        break;
 | 
			
		||||
      } /* End case DECODER_ERROR. */
 | 
			
		||||
| 
						 | 
				
			
			@ -785,15 +780,9 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
 | 
			
		|||
        pktResetAFSKDecoder(myDriver);
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
         * LED setup.
 | 
			
		||||
         */
 | 
			
		||||
 | 
			
		||||
        /* Turn off the breadboard red and yellow LEDs.
 | 
			
		||||
         * Turn off blue LED and reset time interval
 | 
			
		||||
         */
 | 
			
		||||
        //palClearLine(LINE_RED_LED);
 | 
			
		||||
 | 
			
		||||
        palClearLine(LINE_BLUE_LED);
 | 
			
		||||
        pktWriteDecoderLED(PAL_LOW);
 | 
			
		||||
 | 
			
		||||
        /* Clear the LED blink scaler. */
 | 
			
		||||
        led_count = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -832,7 +821,7 @@ THD_FUNCTION(pktAFSKDecoder, arg) {
 | 
			
		|||
          TIME_US2I(DECODER_SUSPEND_TIME));
 | 
			
		||||
        if(evt == 0) {
 | 
			
		||||
          if(++led_count >= DECODER_LED_RATE_SUSPEND) {
 | 
			
		||||
            palToggleLine(LINE_BLUE_LED);
 | 
			
		||||
            pktWriteDecoderLED(PAL_TOGGLE);
 | 
			
		||||
            led_count = 0;
 | 
			
		||||
          }
 | 
			
		||||
          /* No event so loop again. */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,7 +33,7 @@
 | 
			
		|||
#define AFSK_SPACE_FREQUENCY        2200U
 | 
			
		||||
 | 
			
		||||
/* Thread working area size. */
 | 
			
		||||
#define PKT_AFSK_DECODER_WA_SIZE 1024
 | 
			
		||||
#define PKT_AFSK_DECODER_WA_SIZE    1024
 | 
			
		||||
 | 
			
		||||
/* AFSK decoder type selection. */
 | 
			
		||||
#define AFSK_NULL_DECODE            0
 | 
			
		||||
| 
						 | 
				
			
			@ -74,16 +74,19 @@
 | 
			
		|||
#if AFSK_DECODE_TYPE == AFSK_DSP_QCORR_DECODE
 | 
			
		||||
/* BPF followed by fixed point IQ correlation decoder. */
 | 
			
		||||
#define SYMBOL_DECIMATION           (24U)
 | 
			
		||||
/* Sample rate in Hz. */
 | 
			
		||||
#define FILTER_SAMPLE_RATE          (SYMBOL_DECIMATION * AFSK_BAUD_RATE)
 | 
			
		||||
#define DECODE_FILTER_LENGTH        (2U * SYMBOL_DECIMATION)
 | 
			
		||||
#elif
 | 
			
		||||
/* BPF followed by floating point IQ correlation decoder. */
 | 
			
		||||
#define SYMBOL_DECIMATION           (24U)
 | 
			
		||||
/* Sample rate in Hz. */
 | 
			
		||||
#define FILTER_SAMPLE_RATE          (SYMBOL_DECIMATION * AFSK_BAUD_RATE)
 | 
			
		||||
#define DECODE_FILTER_LENGTH        (2U * SYMBOL_DECIMATION)
 | 
			
		||||
#else
 | 
			
		||||
/* Any other decoder. */
 | 
			
		||||
#define SYMBOL_DECIMATION           (24U)
 | 
			
		||||
/* Sample rate in Hz. */
 | 
			
		||||
#define FILTER_SAMPLE_RATE          (SYMBOL_DECIMATION * AFSK_BAUD_RATE)
 | 
			
		||||
#define DECODE_FILTER_LENGTH        (2U * SYMBOL_DECIMATION)
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -128,7 +131,7 @@ typedef enum {
 | 
			
		|||
  DECODER_TERMINATED
 | 
			
		||||
} afskdemodstate_t;
 | 
			
		||||
 | 
			
		||||
typedef int32_t     pwm_accum_t;
 | 
			
		||||
typedef float32_t   pwm_accum_t;
 | 
			
		||||
typedef int16_t     dsp_phase_t;
 | 
			
		||||
 | 
			
		||||
#include "rxpwm.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -177,6 +180,11 @@ typedef struct AFSK_data {
 | 
			
		|||
   */
 | 
			
		||||
  pwm_accum_t               decimation_accumulator;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Decimation amount per slice.
 | 
			
		||||
   */
 | 
			
		||||
  pwm_accum_t               decimation_size;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief ICU driver being used.
 | 
			
		||||
   */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,12 +38,12 @@
 | 
			
		|||
/* Module exported variables.                                                */
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
 | 
			
		||||
/* ICU configuration used for TIM3 CH1 (PA6).
 | 
			
		||||
/* ICU configuration.
 | 
			
		||||
 * TODO: Work out where to put this and manage assigning ICU.
 | 
			
		||||
 * There could be multiple radios so there needs to be an assignment method.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
ICUConfig pwm_icucfg = {
 | 
			
		||||
const ICUConfig pwm_icucfg = {
 | 
			
		||||
  ICU_INPUT_ACTIVE_HIGH,
 | 
			
		||||
  ICU_COUNT_FREQUENCY,          /* ICU clock frequency. */
 | 
			
		||||
  NULL,                         /* ICU width callback. */
 | 
			
		||||
| 
						 | 
				
			
			@ -88,34 +88,30 @@ ICUDriver *pktAttachICU(radio_unit_t radio_id) {
 | 
			
		|||
   * Initialize the RX_DATA capture ICU.
 | 
			
		||||
   */
 | 
			
		||||
 | 
			
		||||
  /* TODO: Make the ICU selectable in pktconf.h. */
 | 
			
		||||
  ICUDriver *myICU = &ICUD4;
 | 
			
		||||
  /* Set the ICU as declared in portab.h. */
 | 
			
		||||
  ICUDriver *myICU = &PWM_ICU;
 | 
			
		||||
  icuObjectInit(myICU);
 | 
			
		||||
 | 
			
		||||
  /* The RX_DATA input is routed to ICU timer.
 | 
			
		||||
   * Set in portab.h
 | 
			
		||||
   */
 | 
			
		||||
  pktSetLineModeICU();
 | 
			
		||||
 | 
			
		||||
  /* Initialise the timers. */
 | 
			
		||||
  chVTObjectInit(&myICU->cca_timer);
 | 
			
		||||
  chVTObjectInit(&myICU->icu_timer);
 | 
			
		||||
  chVTObjectInit(&myICU->pwm_timer);
 | 
			
		||||
 | 
			
		||||
  /* Configure ports. */
 | 
			
		||||
  palSetLineMode(LINE_CCA, PAL_MODE_INPUT_PULLUP);
 | 
			
		||||
  pktSetLineModeCCA();
 | 
			
		||||
 | 
			
		||||
  /* The RX_DATA input is routed to ICU timer.
 | 
			
		||||
   * Set in portab.c
 | 
			
		||||
   */
 | 
			
		||||
  pktSetLineModeICU();
 | 
			
		||||
  /* Setup the squelch LED. */
 | 
			
		||||
  pktSetLineModeSquelchLED();
 | 
			
		||||
  pktWriteSquelchLED(PAL_LOW);
 | 
			
		||||
 | 
			
		||||
  /* Setup the offboard green LED. */
 | 
			
		||||
  //palSetLineMode(LINE_GREEN_LED, PAL_MODE_OUTPUT_PUSHPULL);
 | 
			
		||||
  //palClearLine(LINE_GREEN_LED);
 | 
			
		||||
 | 
			
		||||
  /* Setup onboard red LED for diagnostic. */
 | 
			
		||||
  //palSetLineMode(LINE_ONBOARD_LED, PAL_MODE_OUTPUT_PUSHPULL);
 | 
			
		||||
  //palClearLine(LINE_ONBOARD_LED);
 | 
			
		||||
 | 
			
		||||
  /* Setup offboard yellow LED. */
 | 
			
		||||
  //palSetLineMode(LINE_YELLOW_LED, PAL_MODE_OUTPUT_PUSHPULL);
 | 
			
		||||
  //palClearLine(LINE_YELLOW_LED);
 | 
			
		||||
  /* Setup the overflow LED. */
 | 
			
		||||
  pktSetLineModeOverflowLED();
 | 
			
		||||
  pktWriteOverflowLED(PAL_LOW);
 | 
			
		||||
 | 
			
		||||
  return myICU;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -138,14 +134,11 @@ void pktDetachICU(ICUDriver *myICU) {
 | 
			
		|||
   */
 | 
			
		||||
  icuStop(myICU);
 | 
			
		||||
 | 
			
		||||
  /* Disable the offboard green LED. */
 | 
			
		||||
  //palSetLineMode(LINE_GREEN_LED, PAL_MODE_UNCONNECTED);
 | 
			
		||||
  /* Disable the squelch LED. */
 | 
			
		||||
  pktUnsetLineModeSquelchLED();
 | 
			
		||||
 | 
			
		||||
  /* Disable offboard yellow LED. */
 | 
			
		||||
  //palSetLineMode(LINE_YELLOW_LED, PAL_MODE_UNCONNECTED);
 | 
			
		||||
 | 
			
		||||
  /* Setup onboard red LED for diagnostic. */
 | 
			
		||||
  //palSetLineMode(LINE_ONBOARD_LED, PAL_MODE_UNCONNECTED);
 | 
			
		||||
  /* Disable overflow LED. */
 | 
			
		||||
  pktUnsetLineModeOverflowLED();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -188,7 +181,7 @@ void pktClosePWMChannelI(ICUDriver *myICU, eventflags_t evt) {
 | 
			
		|||
    byte_packed_pwm_t pack = {{0, 0, 0}};
 | 
			
		||||
    msg_t qs = pktWritePWMQueue(myQueue, pack);
 | 
			
		||||
    if(qs != MSG_OK) {
 | 
			
		||||
      //palSetLine(LINE_YELLOW_LED);
 | 
			
		||||
      pktWriteOverflowLED(PAL_HIGH);
 | 
			
		||||
      myDemod->active_radio_object->status |= EVT_PWM_QUEUE_FULL;
 | 
			
		||||
      pktAddEventFlagsI(myHandler, EVT_PWM_QUEUE_FULL);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -297,11 +290,11 @@ void pktRadioCCATimer(ICUDriver *myICU) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    case PAL_HIGH: {
 | 
			
		||||
      /* Turn on the green LED. */
 | 
			
		||||
      //palSetLine(LINE_GREEN_LED);
 | 
			
		||||
      /* Turn on the squelch LED. */
 | 
			
		||||
      pktWriteSquelchLED(PAL_HIGH);
 | 
			
		||||
 | 
			
		||||
      /* Turn off the yellow LED. */
 | 
			
		||||
      //palClearLine(LINE_YELLOW_LED);
 | 
			
		||||
      /* Turn off the overflow LED. */
 | 
			
		||||
      pktWriteOverflowLED(PAL_LOW);
 | 
			
		||||
 | 
			
		||||
      if(myDemod->active_radio_object != NULL) {
 | 
			
		||||
        /* TODO: Work out correct handling.
 | 
			
		||||
| 
						 | 
				
			
			@ -394,9 +387,6 @@ void pktRadioCCAInput(ICUDriver *myICU) {
 | 
			
		|||
  /* CCA changed. */
 | 
			
		||||
  switch(palReadLine(LINE_CCA)) {
 | 
			
		||||
    case PAL_LOW: {
 | 
			
		||||
      /* Turn off the OB red LED. */
 | 
			
		||||
      //palClearLine(LINE_ONBOARD_LED);
 | 
			
		||||
 | 
			
		||||
      if(chVTIsArmedI(&myICU->cca_timer)) {
 | 
			
		||||
        /* CCA has dropped during timer so CCA is a glitch. */
 | 
			
		||||
        chVTResetI(&myICU->cca_timer);
 | 
			
		||||
| 
						 | 
				
			
			@ -406,10 +396,9 @@ void pktRadioCCAInput(ICUDriver *myICU) {
 | 
			
		|||
      }
 | 
			
		||||
 | 
			
		||||
      /*
 | 
			
		||||
       * Turn off the green LED.
 | 
			
		||||
       * TODO: Refactor LED assignment into portability setup.
 | 
			
		||||
       * Turn off the squelch LED.
 | 
			
		||||
       */
 | 
			
		||||
      //palClearLine(LINE_GREEN_LED);
 | 
			
		||||
      pktWriteSquelchLED(PAL_LOW);
 | 
			
		||||
 | 
			
		||||
      if(myDemod->active_radio_object == NULL) {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -436,9 +425,6 @@ void pktRadioCCAInput(ICUDriver *myICU) {
 | 
			
		|||
      /* TODO: Calculate de-glitch time as number of symbol times. */
 | 
			
		||||
      chVTSetI(&myICU->cca_timer, TIME_MS2I(66),
 | 
			
		||||
               (vtfunc_t)pktRadioCCATimer, myICU);
 | 
			
		||||
 | 
			
		||||
      /* Turn on the OB red LED. */
 | 
			
		||||
      //palSetLine(LINE_ONBOARD_LED);
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
  } /* End switch. */
 | 
			
		||||
| 
						 | 
				
			
			@ -494,7 +480,7 @@ void pktRadioICUPeriod(ICUDriver *myICU) {
 | 
			
		|||
 | 
			
		||||
  msg_t qs = pktQueuePWMDataI(myICU);
 | 
			
		||||
  if(qs != MSG_OK) {
 | 
			
		||||
    //palSetLine(LINE_YELLOW_LED);
 | 
			
		||||
    pktWriteOverflowLED(PAL_HIGH);
 | 
			
		||||
    pktClosePWMChannelI(myICU, EVT_PWM_QUEUE_FULL);
 | 
			
		||||
  }
 | 
			
		||||
  chSysUnlockFromISR();
 | 
			
		||||
| 
						 | 
				
			
			@ -530,14 +516,14 @@ void PktRadioICUOverflow(ICUDriver *myICU) {
 | 
			
		|||
 * @details Byte values of packed PWM data are written into an input queue.
 | 
			
		||||
 *          The operation will succeed if sufficient queue space is available.
 | 
			
		||||
 *          If the queue will become full then an in-band QOV flag is written.
 | 
			
		||||
 *          in that case PWM data will not be queued unless it was an EOD flag.
 | 
			
		||||
 *          In that case PWM data will not be queued unless it was an EOD flag.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] myICU      pointer to the ICU driver structure
 | 
			
		||||
 *
 | 
			
		||||
 * @return              The operation status.
 | 
			
		||||
 * @retval MSG_OK       The PWM data has been queued.
 | 
			
		||||
 * @retval MSG_TIMEOUT  The queue is already full.
 | 
			
		||||
 * @retval MSG_RESET    Queue space would be exhausted so an QOF
 | 
			
		||||
 * @retval MSG_RESET    Queue space would be exhausted so a QOV
 | 
			
		||||
 *                      flag is written in place of PWM data.
 | 
			
		||||
 *
 | 
			
		||||
 * @iclass
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,8 +37,8 @@
 | 
			
		|||
 * TODO: This should be calculated using SYSTEM CLOCK.
 | 
			
		||||
 * ICU has to run at an integer divide from SYSTEM CLOCK.
 | 
			
		||||
 */
 | 
			
		||||
#define ICU_COUNT_FREQUENCY     2880000U
 | 
			
		||||
 | 
			
		||||
//#define ICU_COUNT_FREQUENCY     2880000U
 | 
			
		||||
#define ICU_COUNT_FREQUENCY     2000000U
 | 
			
		||||
 | 
			
		||||
/* Limit of ICU and PWM count for packed format. */
 | 
			
		||||
#define ICU_MAX_COUNT   0xFFFFFF
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,7 +21,7 @@
 | 
			
		|||
 */
 | 
			
		||||
 | 
			
		||||
#if PKT_CFG_USE_SERIAL == TRUE
 | 
			
		||||
static const SerialConfig debug_config = {
 | 
			
		||||
const SerialConfig debug_config = {
 | 
			
		||||
  115200,
 | 
			
		||||
  0,
 | 
			
		||||
  0,
 | 
			
		||||
| 
						 | 
				
			
			@ -29,20 +29,13 @@ static const SerialConfig debug_config = {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
/* Declare UART aliases. */
 | 
			
		||||
BaseSequentialStream* diag_out = (BaseSequentialStream*) &SD4;
 | 
			
		||||
BaseSequentialStream* pkt_out = (BaseSequentialStream*) &SD3;
 | 
			
		||||
BaseSequentialStream* diag_out = (BaseSequentialStream*) &SD3;
 | 
			
		||||
BaseSequentialStream* pkt_out = (BaseSequentialStream*) &SD4;
 | 
			
		||||
 | 
			
		||||
void pktSerialStart() {
 | 
			
		||||
  /* UART4 TX.       */
 | 
			
		||||
  palSetLineMode(LINE_UART4_TX, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
 | 
			
		||||
  /* UART4 RX.       */
 | 
			
		||||
  palSetLineMode(LINE_UART4_RX, PAL_MODE_INPUT);
 | 
			
		||||
  pktConfigSerialDiag();
 | 
			
		||||
  pktConfigSerialPkt();
 | 
			
		||||
  sdStart(&SD4, &debug_config);
 | 
			
		||||
 | 
			
		||||
  /* UART3 TX.       */
 | 
			
		||||
  palSetLineMode(LINE_USART3_TX, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
 | 
			
		||||
  /* UART3 RX.       */
 | 
			
		||||
  palSetLineMode(LINE_USART3_RX, PAL_MODE_INPUT);
 | 
			
		||||
  sdStart(&SD3, &debug_config);
 | 
			
		||||
}
 | 
			
		||||
#endif /* PKT_CFG_USE_SERIAL */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,6 +24,8 @@
 | 
			
		|||
extern BaseSequentialStream* diag_out;
 | 
			
		||||
extern BaseSequentialStream* pkt_out;
 | 
			
		||||
 | 
			
		||||
extern const SerialConfig debug_config;
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,7 +26,6 @@
 | 
			
		|||
 | 
			
		||||
#include "ch.h"
 | 
			
		||||
#include "hal.h"
 | 
			
		||||
#include "portab.h"
 | 
			
		||||
#include "chprintf.h"
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -42,30 +41,37 @@
 | 
			
		|||
/* Decoder system events. */
 | 
			
		||||
#define EVT_NONE                0
 | 
			
		||||
#define EVT_PRIORITY_BASE       0
 | 
			
		||||
 | 
			
		||||
#define EVT_AX25_FRAME_RDY      EVENT_MASK(EVT_PRIORITY_BASE + 0)
 | 
			
		||||
#define EVT_RADIO_CCA_GLITCH    EVENT_MASK(EVT_PRIORITY_BASE + 1)
 | 
			
		||||
#define EVT_RADIO_CCA_CLOSE     EVENT_MASK(EVT_PRIORITY_BASE + 2)
 | 
			
		||||
#define EVT_DECODER_ERROR       EVENT_MASK(EVT_PRIORITY_BASE + 3)
 | 
			
		||||
 | 
			
		||||
#define EVT_AFSK_TERMINATED     EVENT_MASK(EVT_PRIORITY_BASE + 4)
 | 
			
		||||
#define EVT_PWM_UNKNOWN_INBAND  EVENT_MASK(EVT_PRIORITY_BASE + 5)
 | 
			
		||||
#define EVT_ICU_OVERFLOW        EVENT_MASK(EVT_PRIORITY_BASE + 6)
 | 
			
		||||
#define EVT_SUSPEND_EXIT        EVENT_MASK(EVT_PRIORITY_BASE + 7)
 | 
			
		||||
 | 
			
		||||
#define EVT_PWM_NO_DATA         EVENT_MASK(EVT_PRIORITY_BASE + 8)
 | 
			
		||||
#define EVT_PWM_FIFO_SENT       EVENT_MASK(EVT_PRIORITY_BASE + 9)
 | 
			
		||||
#define EVT_RADIO_CCA_OPEN      EVENT_MASK(EVT_PRIORITY_BASE + 10)
 | 
			
		||||
#define EVT_PWM_QUEUE_FULL      EVENT_MASK(EVT_PRIORITY_BASE + 11)
 | 
			
		||||
 | 
			
		||||
#define EVT_PWM_FIFO_EMPTY      EVENT_MASK(EVT_PRIORITY_BASE + 12)
 | 
			
		||||
#define EVT_PWM_STREAM_TIMEOUT  EVENT_MASK(EVT_PRIORITY_BASE + 13)
 | 
			
		||||
#define EVT_PWM_FIFO_LOCK       EVENT_MASK(EVT_PRIORITY_BASE + 14)
 | 
			
		||||
#define EVT_DECODER_START       EVENT_MASK(EVT_PRIORITY_BASE + 15)
 | 
			
		||||
 | 
			
		||||
#define EVT_DECODER_STOP        EVENT_MASK(EVT_PRIORITY_BASE + 16)
 | 
			
		||||
#define EVT_RADIO_CCA_FIFO_ERR  EVENT_MASK(EVT_PRIORITY_BASE + 17)
 | 
			
		||||
#define EVT_AX25_BUFFER_FULL    EVENT_MASK(EVT_PRIORITY_BASE + 18)
 | 
			
		||||
#define EVT_AFSK_DATA_TIMEOUT   EVENT_MASK(EVT_PRIORITY_BASE + 19)
 | 
			
		||||
 | 
			
		||||
#define EVT_AX25_CRC_ERROR      EVENT_MASK(EVT_PRIORITY_BASE + 20)
 | 
			
		||||
#define EVT_HDLC_RESET_RCVD     EVENT_MASK(EVT_PRIORITY_BASE + 21)
 | 
			
		||||
#define EVT_AX25_NO_BUFFER      EVENT_MASK(EVT_PRIORITY_BASE + 22)
 | 
			
		||||
#define EVT_ICU_SLEEP_TIMEOUT   EVENT_MASK(EVT_PRIORITY_BASE + 23)
 | 
			
		||||
 | 
			
		||||
#define EVT_PWM_STREAM_ABORT    EVENT_MASK(EVT_PRIORITY_BASE + 24)
 | 
			
		||||
#define EVT_PKT_CHANNEL_CLOSE   EVENT_MASK(EVT_PRIORITY_BASE + 25)
 | 
			
		||||
#define EVT_DECODER_ACK         EVENT_MASK(EVT_PRIORITY_BASE + 26)
 | 
			
		||||
| 
						 | 
				
			
			@ -82,6 +88,9 @@
 | 
			
		|||
 | 
			
		||||
#define SUSPEND_HANDLING        NO_SUSPEND
 | 
			
		||||
 | 
			
		||||
/* Extra GPIO value. */
 | 
			
		||||
#define PAL_TOGGLE          2U
 | 
			
		||||
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
/**
 | 
			
		||||
 * @name Subsystems configuration
 | 
			
		||||
| 
						 | 
				
			
			@ -122,6 +131,7 @@ typedef struct radioConfig {
 | 
			
		|||
/* Aerospace decoder subsystem includes.                                     */
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
 | 
			
		||||
#include "portab.h"
 | 
			
		||||
#include "dbguart.h"
 | 
			
		||||
#include "dsp.h"
 | 
			
		||||
#include "ax25.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -134,6 +144,95 @@ typedef struct radioConfig {
 | 
			
		|||
#include "rxpacket.h"
 | 
			
		||||
#include "ihex_out.h"
 | 
			
		||||
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
/* External declarations.                                                    */
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
/* Module inline functions.                                                  */
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
 | 
			
		||||
static inline void pktSetLineModeCCA(void) {
 | 
			
		||||
  palSetLineMode(LINE_CCA, PAL_MODE_INPUT_PULLUP);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void pktSetLineModeDecoderLED(void) {
 | 
			
		||||
#if defined(LINE_DECODER_LED)
 | 
			
		||||
  palSetLineMode(LINE_DECODER_LED, PAL_MODE_OUTPUT_PUSHPULL);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void pktUnsetLineModeDecoderLED(void) {
 | 
			
		||||
#if defined(LINE_DECODER_LED)
 | 
			
		||||
  palSetLineMode(LINE_DECODER_LED, PAL_MODE_UNCONNECTED);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void pktWriteDecoderLED(uint8_t state) {
 | 
			
		||||
#if defined(LINE_DECODER_LED)
 | 
			
		||||
  if(state != PAL_TOGGLE)
 | 
			
		||||
    palWriteLine(LINE_DECODER_LED, state);
 | 
			
		||||
  else
 | 
			
		||||
    palToggleLine(LINE_DECODER_LED);
 | 
			
		||||
#else
 | 
			
		||||
  (void)state;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void pktSetLineModeSquelchLED(void) {
 | 
			
		||||
#if defined(LINE_SQUELCH_LED)
 | 
			
		||||
  palSetLineMode(LINE_SQUELCH_LED, PAL_MODE_OUTPUT_PUSHPULL);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void pktWriteSquelchLED(uint8_t state) {
 | 
			
		||||
#if defined(LINE_SQUELCH_LED)
 | 
			
		||||
  if(state != PAL_TOGGLE)
 | 
			
		||||
    palWriteLine(LINE_SQUELCH_LED, state);
 | 
			
		||||
  else
 | 
			
		||||
    palToggleLine(LINE_SQUELCH_LED);
 | 
			
		||||
#else
 | 
			
		||||
  (void)state;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void pktUnsetLineModeSquelchLED(void) {
 | 
			
		||||
#if defined(LINE_SQUELCH_LED)
 | 
			
		||||
  palSetLineMode(LINE_SQUELCH_LED, PAL_MODE_UNCONNECTED);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void pktSetLineModeOverflowLED(void) {
 | 
			
		||||
#if defined(LINE_OVERFLOW_LED)
 | 
			
		||||
  palSetLineMode(LINE_OVERFLOW_LED, PAL_MODE_OUTPUT_PUSHPULL);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void pktWriteOverflowLED(uint8_t state) {
 | 
			
		||||
#if defined(LINE_OVERFLOW_LED)
 | 
			
		||||
  if(state != PAL_TOGGLE)
 | 
			
		||||
    palWriteLine(LINE_OVERFLOW_LED, state);
 | 
			
		||||
  else
 | 
			
		||||
    palToggleLine(LINE_OVERFLOW_LED);
 | 
			
		||||
#else
 | 
			
		||||
  (void)state;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void pktUnsetLineModeOverflowLED(void) {
 | 
			
		||||
#if defined( LINE_OVERFLOW_LED)
 | 
			
		||||
  palSetLineMode(LINE_OVERFLOW_LED, PAL_MODE_UNCONNECTED);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif /* _PKTCONF_H_ */
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,7 +15,8 @@
 | 
			
		|||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "pktconf.h"
 | 
			
		||||
#include "hal.h"
 | 
			
		||||
#include "portab.h"
 | 
			
		||||
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
/* Module local definitions.                                                 */
 | 
			
		||||
| 
						 | 
				
			
			@ -41,9 +42,22 @@
 | 
			
		|||
/* Module exported functions.                                                */
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
 | 
			
		||||
void pktConfigSerialDiag(void) {
 | 
			
		||||
  /* USART3 TX.       */
 | 
			
		||||
  //palSetLineMode(LINE_USART3_TX, PAL_MODE_OUTPUT_PUSHPULL | PAL_MODE_ALTERNATE(3));
 | 
			
		||||
  /* USART3 RX.       */
 | 
			
		||||
  //palSetLineMode(LINE_USART3_RX, PAL_MODE_ALTERNATE(3));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pktConfigSerialPkt(void) {
 | 
			
		||||
  /* UART4 TX.       */
 | 
			
		||||
  palSetLineMode(LINE_UART4_TX, PAL_MODE_OUTPUT_PUSHPULL | PAL_MODE_ALTERNATE(11));
 | 
			
		||||
  /* UART4 RX.       */
 | 
			
		||||
  palSetLineMode(LINE_UART4_RX, PAL_MODE_INPUT | PAL_MODE_ALTERNATE(11));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pktSetLineModeICU(void) {
 | 
			
		||||
  //palSetLineMode(LINE_ICU, PAL_MODE_INPUT_PULLUP);
 | 
			
		||||
  palSetLineMode(LINE_ICU, PAL_MODE_ALTERNATE(2)); /* F413. */
 | 
			
		||||
  palSetLineMode(LINE_ICU, PAL_MODE_INPUT | PAL_MODE_ALTERNATE(2));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,23 +13,17 @@
 | 
			
		|||
/* Module constants.                                                         */
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
 | 
			
		||||
/* TODO: Set LED line associations - will need to remove some for PP10. */
 | 
			
		||||
//#define LINE_BUTTON         PAL_LINE(GPIOA, 0U)
 | 
			
		||||
//#define LINE_ONBOARD_LED    PAL_LINE(GPIOB, 0U)
 | 
			
		||||
//#define LINE_YELLOW_LED     PAL_LINE(GPIOA, 5U)
 | 
			
		||||
//#define LINE_RED_LED        PAL_LINE(GPIOA, 7U)
 | 
			
		||||
//#define LINE_BLUE_LED       PAL_LINE(GPIOB, 1U)
 | 
			
		||||
#define LINE_BLUE_LED       PAL_LINE(GPIOC, 1U) /* PP10 blue LED. */
 | 
			
		||||
//#define LINE_GREEN_LED      PAL_LINE(GPIOA, 3U)
 | 
			
		||||
//#define LINE_CCA            PAL_LINE(GPIOC, 1U)
 | 
			
		||||
#define LINE_CCA            PAL_LINE(GPIOD, 2U)
 | 
			
		||||
//#define LINE_ICU            PAL_LINE(GPIOA, 6U)
 | 
			
		||||
#define LINE_ICU            PAL_LINE(GPIOB, 6U) /* PP10 si4464 GPIO1. */
 | 
			
		||||
//#define LINE_OVERFLOW_LED   LINE_LED3
 | 
			
		||||
#define LINE_DECODER_LED    LINE_IO_BLUE
 | 
			
		||||
//#define LINE_SQUELCH_LED    LINE_LED1
 | 
			
		||||
 | 
			
		||||
#define LINE_USART3_TX      PAL_LINE(GPIOB, 10U)
 | 
			
		||||
#define LINE_USART3_RX      PAL_LINE(GPIOB, 11U)
 | 
			
		||||
#define LINE_UART4_TX       PAL_LINE(GPIOC, 10U)
 | 
			
		||||
#define LINE_UART4_RX       PAL_LINE(GPIOC, 11U)
 | 
			
		||||
#define LINE_CCA            PAL_LINE(GPIOE, 0U)
 | 
			
		||||
#define LINE_ICU            PAL_LINE(GPIOB, 6U)
 | 
			
		||||
 | 
			
		||||
#define LINE_UART4_TX       PAL_LINE(GPIOA, 12U)
 | 
			
		||||
#define LINE_UART4_RX       PAL_LINE(GPIOA, 11U)
 | 
			
		||||
 | 
			
		||||
#define PWM_ICU             ICUD4
 | 
			
		||||
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
/* Module pre-compile time settings.                                         */
 | 
			
		||||
| 
						 | 
				
			
			@ -51,10 +45,11 @@
 | 
			
		|||
/* External declarations.                                                    */
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
  void pktConfigSerialDiag(void);
 | 
			
		||||
  void pktConfigSerialPkt(void);
 | 
			
		||||
  void pktSetLineModeICU(void);
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue