view src/g23m-fad/t30/t30_tim.c @ 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 fa8dc04885d8
children
line wrap: on
line source

/* 
+----------------------------------------------------------------------------- 
|  Project :  GSM-F&D (8411)
|  Modul   :  T30_TIM
+----------------------------------------------------------------------------- 
|  Copyright 2002 Texas Instruments Berlin, AG 
|                 All rights reserved. 
| 
|                 This file is confidential and a trade secret of Texas 
|                 Instruments Berlin, AG 
|                 The receipt of or possession of this file does not convey 
|                 any rights to reproduce or disclose its contents or to 
|                 manufacture, use, or sell anything it may describe, in 
|                 whole, or in part, without the specific written consent of 
|                 Texas Instruments Berlin, AG. 
+----------------------------------------------------------------------------- 
|  Purpose :  This Modul defines the timer handling functions
|             for the component T30 of the mobile station
+----------------------------------------------------------------------------- 
*/ 

#ifndef T30_TIM_C
#define T30_TIM_C
#endif

#define ENTITY_T30

/*==== INCLUDES ===================================================*/

#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include "typedefs.h"
#include "pcm.h"
#include "vsi.h"
#include "macdef.h"
#include "pconst.cdg"
#include "mconst.cdg"
#include "message.h"
#include "ccdapi.h"
#include "custom.h"
#include "gsm.h"
#include "prim.h"
#include "cnf_t30.h"
#include "mon_t30.h"
#include "pei.h"
#include "tok.h"
#include "dti.h"      /* functionality of the dti library */
#include "t30.h"

/*==== EXPORT =====================================================*/

/*==== PRIVAT =====================================================*/

/*==== VARIABLES ==================================================*/

/*==== FUNCTIONS ==================================================*/

/*
+--------------------------------------------------------------------+
| PROJECT : GSM-F&D (8411)        MODULE  : T30_TIM                  |
| STATE   : code                  ROUTINE : tim_t1                   |
+--------------------------------------------------------------------+

  PURPOSE : Timeout of timer T1

*/
LOCAL void tim_t1 (void)
{
  TRACE_FUNCTION ("tim_t1()");

  switch (GET_STATE (KER))
  {
    case T30_IDLE:
      snd_error_ind(ERR_PH_A_T1_TIMEOUT);
      break;

#ifdef _SIMULATION_ /* test of timer T1 */
    case T30_RCV_DIS:
#endif
    case T30_RCV_DCS:
      snd_error_ind(ERR_PH_A_T1_TIMEOUT);
      TIMERSTOP (T4_INDEX);
      SET_STATE (KER, T30_IDLE);
      break;

    default:
      break;
  }
  t30_data->data_cnf = FALSE;
}

/*
+--------------------------------------------------------------------+
| PROJECT : GSM-F&D (8411)        MODULE  : T30_TIM                  |
| STATE   : code                  ROUTINE : tim_t2                   |
+--------------------------------------------------------------------+

  PURPOSE : Timeout of timer T2

*/

LOCAL void tim_t2 (void)
{
  TRACE_FUNCTION ("tim_t2()");

  switch (GET_STATE (KER))
  {
    case T30_RCV_TCF:
      snd_error_ind(ERR_PH_B_RCV_NO_RESP);
      SET_STATE (KER, T30_IDLE);
      break;

    case T30_RCV_DCN:
    case T30_RCV_MSG:
    case T30_RCV_PST:
      snd_error_ind(ERR_PH_D_RCV_NO_RESP);
      SET_STATE (KER, T30_IDLE);
      break;

    case T30_RCV_T2:
      snd_complete_ind(CMPL_EOM);
      break;

    default:
      break;
  }
  t30_data->rate_modified = FALSE;
  t30_data->data_cnf = FALSE;
}

/*
+--------------------------------------------------------------------+
| PROJECT : GSM-F&D (8411)        MODULE  : T30_TIM                  |
| STATE   : code                  ROUTINE : tim_t4                   |
+--------------------------------------------------------------------+

  PURPOSE : Timeout of timer T4

*/

LOCAL void tim_t4 (void)
{
  TRACE_FUNCTION ("tim_t4()");

  if (!t30_data->data_cnf)
    TRACE_EVENT ("*** no fad_data_cnf received");

  switch (GET_STATE (KER))
  {
    case T30_RCV_DCS:
    {
      if (t30_data->rate_modified)
      {
        TIMERSTART (T4_INDEX, T4_VALUE);
        break;
      }
      SET_STATE (KER, T30_RCV_DIS);

      if (t30_data->data_cnf)
        ker_send_dis ();
      else
        TIMERSTART (T4_INDEX, T4_VALUE);

      break;
    }

    case T30_SND_CFR:
    {
      if (t30_data->repeat EQ 3)
      {
        snd_error_ind(ERR_PH_B_SND_DCS_RPTD_3_TIMES);
        SET_STATE (KER, T30_DCN);
        if (t30_data->data_cnf)
        {
          _decodedMsg[0] = BCS_DCN;
          sig_ker_bcs_bdat_req (FINAL_YES);
        }
      }
      else
      {
        t30_data->repeat++;
        if (t30_data->data_cnf)
        {
          SET_STATE (KER, T30_SND_CAP);
          snd_t30_sgn_ind(SGN_NO_RES);
        }
        else
        {
          TIMERSTART (T4_INDEX, T4_VALUE);
        }
      }
      break;
    }

    case T30_SND_DCN:
    {
      snd_complete_ind(CMPL_EOP);
      break;
    }

    case T30_SND_MCF:
    {
      if (t30_data->repeat EQ 3)
      {
        switch (t30_data->sgn_req)
        {
          case SGN_EOM:
          case SGN_PRI_EOM:
            snd_error_ind(ERR_PH_D_SND_EOM_RPTD_3_TIMES);
            break;

          case SGN_EOP:
          case SGN_PRI_EOP:
            snd_error_ind(ERR_PH_D_SND_EOP_RPTD_3_TIMES);
            break;

          case SGN_MPS:
          case SGN_PRI_MPS:
            snd_error_ind(ERR_PH_D_SND_MPS_RPTD_3_TIMES);
            break;

          default:
            snd_error_ind(ERR_PH_D_SND_UNSPEC);
            break;
        }
        SET_STATE (KER, T30_DCN);
        if (t30_data->data_cnf)
        {
          _decodedMsg[0] = BCS_DCN;
          sig_ker_bcs_bdat_req (FINAL_YES);
        }
      }
      else /* t30_data->repeat < 3 */
      {
        t30_data->repeat++;
        act_on_sgn_req();
        if (!t30_data->data_cnf)
        {
          TIMERSTART (T4_INDEX, T4_VALUE);
        }
      }
      break;
    }

    default:
      break;

  } /* end switch */

  t30_data->data_cnf = FALSE;
}

/*
+--------------------------------------------------------------------+
| PROJECT : GSM-F&D (8411)        MODULE  : T30_TIM                  |
| STATE   : code                  ROUTINE : t30_timeout              |
+--------------------------------------------------------------------+

  PURPOSE : execute timeout function

*/

GLOBAL void t30_timeout (USHORT index)
{
  TRACE_FUNCTION ("t30_timeout()");
  switch (index)
  {
  case T1_INDEX:
    tim_t1 ();
    break;
  case T2_INDEX:
    tim_t2 ();
    break;
  case T4_INDEX:
    tim_t4 ();
    break;
  }
}