view src/cs/layer1/gtt_include/ctm/tonedemod.h @ 220:0ed36de51973

ABB semaphore protection overhaul The ABB semaphone protection logic that came with TCS211 from TI was broken in several ways: * Some semaphore-protected functions were called from Application_Initialize() context. NU_Obtain_Semaphore() called with NU_SUSPEND fails with NU_INVALID_SUSPEND in this context, but the return value wasn't checked, and NU_Release_Semaphore() would be called unconditionally at the end. The latter call would increment the semaphore count past 1, making the semaphore no longer binary and thus no longer effective for resource protection. The fix is to check the return value from NU_Obtain_Semaphore() and skip the NU_Release_Semaphore() call if the semaphore wasn't properly obtained. * Some SPI hardware manipulation was being done before entering the semaphore- protected critical section. The fix is to reorder the code: first obtain the semaphore, then do everything else. * In the corner case of L1/DSP recovery, l1_abb_power_on() would call some non-semaphore-protected ABB & SPI init functions. The fix is to skip those calls in the case of recovery. * A few additional corner cases existed, all of which are fixed by making ABB semaphore protection 100% consistent for all ABB functions and code paths. There is still one remaining problem of priority inversion: suppose a low- priority task calls an ABB function, and some medium-priority task just happens to preempt right in the middle of that semaphore-protected ABB operation. Then the high-priority SPI task is locked out for a non-deterministic time until that medium-priority task finishes its work and goes back to sleep. This priority inversion problem remains outstanding for now.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Apr 2021 20:55:25 +0000
parents 4e78acac3d88
children
line wrap: on
line source

/*
*******************************************************************************
*
*      COPYRIGHT (C) 2000 BY ERICSSON EUROLAB DEUTSCHLAND GmbH
*      90411 NUERNBERG, GERMANY, Tel Int + 49 911 5217 100
*
*      The program(s) may be used and/or copied only with the
*      written permission from Ericsson or in accordance
*      with the terms and conditions stipulated in the agreement or
*      contract under which the program(s) have been supplied.
*
*******************************************************************************
*
*      File             : tonedemod.h
*      Purpose          : Demodulator for the Cellular Text Telephone Modem
*                         1-out-of-4 tones (400, 600, 800, 1000 Hz)
*                         for the coding of each pair of two adjacent bits
*
*                         Definition of the type demod_state_t and of the 
*                         functions init_tonedemod() and tonedemod()
*
*******************************************************************************
*/

#ifndef tonedemod_h
#define tonedemod_h "$Id: $"

/*
*******************************************************************************
*                         INCLUDE FILES
*******************************************************************************
*/

#include "ctm_defines.h"

/*
*******************************************************************************
*                         DECLARATION OF PROTOTYPES
*******************************************************************************
*/

typedef struct {
  WORD16  buffer_tone_rx[3*SYMB_LEN];
  WORD16  xcorr_t0[2*SYMB_LEN];
  WORD16  xcorr_t1[2*SYMB_LEN];
  WORD16  xcorr_t2[2*SYMB_LEN];
  WORD16  xcorr_t3[2*SYMB_LEN];
  WORD16  xcorr_wb[2*SYMB_LEN];
  WORD16  lowpass[SYMB_LEN];
  WORD16  waveform_t0[SYMB_LEN];
  WORD16  waveform_t1[SYMB_LEN];
  WORD16  waveform_t2[SYMB_LEN];
  WORD16  waveform_t3[SYMB_LEN];
  WORD16  diff_smooth[SYMB_LEN];
} demod_state_t;


/* ----------------------------------------------------------------------- */
/* FUNCTION tonedemod()                                                    */
/* ********************                                                    */
/* Tone Demodulator for the Cellular Text Telephone Modem                  */
/* using one out of four tones for coding two bits in parallel within a    */
/* frame of 40 samples (5 ms).                                             */
/*                                                                         */
/* The function has to be called for every frame of 40 samples of the      */
/* received tone sequence. However, in order to track a non-ideal          */
/* of the transmitter's and the receiver's clock frequencies, one frame    */
/* might be shorter (only 39 samples) or longer (41 samples). The          */
/* of the following frame is indicated by the variable                     */
/* *sampling_correction, which is calculated and returned by this function.*/
/*                                                                         */
/* input variables:                                                         */
/* bits_out            contains the 39, 40 or 41 actual samples of the     */
/*                     received tones; the bits are soft bits, i.e. they   */
/*                     are in the range between -1.0 and 1.0, where the    */
/*                     magnitude serves as reliability information         */
/* num_in_samples      number of valid samples in bits_out                 */
/*                                                                         */
/* output variables:                                                        */
/* bits_out            contains the two actual decoded soft bits           */
/* sampling_correction is either -1, 0, or 1 and indicates whether the     */
/*                     next frame shall contain 39, 40, or 41 samples      */
/* demod_state         contains all the memory of tonedemod. Must be       */
/*                     initialized using the function init_tonedemod()     */
/* ----------------------------------------------------------------------- */

void tonedemod(WORD16 *bits_out,
               WORD16 *rx_tone_vec,
               WORD16 num_in_samples,
               WORD16 *ptr_sampling_correction,
               demod_state_t *demod_state);


/* ----------------------------------------------------------------------- */
/* FUNCTION init_tonedemod()                                               */
/* *************************                                               */
/* Initialization of one instance of the Tone Demodulator. The argument    */
/* must contain a pointer to a variable of type demod_state_t, which       */
/* contains all the memory of the tone demodulator. Each instance of       */
/* tonedemod must have its own variable.                                   */
/* ----------------------------------------------------------------------- */

void init_tonedemod(demod_state_t *demod_state);

#endif