view src/g23m-fad/l2r/tra_dnp.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 :  CSD (8411)
|  Modul   :  tra_dnp.c
+----------------------------------------------------------------------------- 
|  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 functions for processing
|             of incomming primitives for the component TRA
+----------------------------------------------------------------------------- 
*/ 

#ifndef TRA_DNP_C
#define TRA_DNP_C
#endif

#define ENTITY_L2R

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

#include <string.h>

#include "typedefs.h"
#include "pconst.cdg"
#include "vsi.h"
#include "macdef.h"
#include "custom.h"
#include "gsm.h"
#include "prim.h"
#include "pei.h"
#include "tok.h"
#include "dti.h"

#include "cl_ribu.h"
#include "tra_pei.h"
#include "tra.h"

/*==== CONST =======================================================*/

/*==== TYPES =======================================================*/

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

/*==== VAR LOCAL ===================================================*/

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

/*
+------------------------------------------------------------------------------
|  Function    : sig_dti_tra_dn_tx_buffer_ready_ind
+------------------------------------------------------------------------------
|  Description : Process signal DTI_REASON_TX_BUFFER_READY received from
|                dti library callback function.
|
|  Parameters  : -
|
|  Return      : -
+------------------------------------------------------------------------------
*/
GLOBAL void sig_dti_tra_dn_tx_buffer_ready_ind()
{
  TRACE_FUNCTION ("sig_dti_tra_dn_tx_buffer_ready_ind()");

  if (tra_data->dn.Brk_dti_data_ind NEQ NULL)
  {
    /*
     * if there is a pending break indication to be sent via DTI,
     * send it now
     */
    sig_any_tra_dn_send_break_req();
    return;
  }

  switch (GET_STATE (DN))
  {
    case DN_IDLE:
    {
      SET_STATE (DN, DN_WAIT);
      break;
    }
    case DN_SEND:
    {
      if (dl_send_data_ind())
      {
        SET_STATE (DN, DN_IDLE);
      }
      break;
    }
  }
}

/*
+------------------------------------------------------------------------------
|  Function    : sig_dti_tra_dn_tx_buffer_full_ind
+------------------------------------------------------------------------------
|  Description : Process signal DTI_REASON_TX_BUFFER_FULL received from
|                dti library callback function.
|
|  Parameters  : -
|
|  Return      : -
+------------------------------------------------------------------------------

  The buffer function of DTILIB is not used.
  So there is nothing to be done here yet...

*/

GLOBAL void sig_dti_tra_dn_tx_buffer_full_ind()
{
  TRACE_FUNCTION ("sig_dti_tra_dn_tx_buffer_full_ind()");
}


/*
+------------------------------------------------------------------------------
|  Function    : rcv_ra_data_ind
+------------------------------------------------------------------------------
|  Description : Process primitive RA_DATA_IND received from RA.
|                This function is called if the primitive RA_DATA_IND is
|                received or from the signal processing in l2r_pei (tra).
|
|  Parameters  : ra_data_ind -
|
|
|  Return      : -
+------------------------------------------------------------------------------
*/

GLOBAL void rcv_ra_data_ind(T_RA_DATA_IND *ra_data_ind)
{
  T_TRA_DN *ddl = &tra_data->dn;
  T_FD *pFD = NULL;

  TRACE_FUNCTION("rcv_ra_data_ind()");

  if (GET_STATE (MGT) NEQ MGT_IDLE)
  {
    TRACE_EVENT ("data rcvd while not in state MGT_IDLE");

    while (cl_ribu_data_avail(ddl->ribu))
    {
      cl_ribu_get(ddl->ribu);
    }

#ifdef _SIMULATION_
    PFREE (ra_data_ind);
#endif
    return;
  }

#ifdef _SIMULATION_
  PACCESS (ra_data_ind);
  if (ra_data_ind->sdu.l_buf)
  {
    pFD = tra_get_next_FrameDesc();
    TRACE_EVENT_P2("put - wi=%d - ri=%d", ddl->ribu->idx.wi, ddl->ribu->idx.ri);
    memcpy(pFD->buf, ra_data_ind->sdu.buf, ra_data_ind->sdu.l_buf >> 3);
    pFD->len = ra_data_ind->sdu.l_buf >> 3;
  }
#endif

  ddl->sa = 0;
  ddl->sb = 0;
  ddl->x = 0;

  if (ra_data_ind->status & ST_SA)
    ddl->sa = DTI_SA_OFF;
  if (ra_data_ind->status & ST_SB)
    ddl->sb = DTI_SB_OFF;
  if (ra_data_ind->status & ST_X)
    ddl->x = DTI_FLOW_OFF;

  if (ddl->ribu->idx.filled > 1)
    TRACE_EVENT_P3("RIBU ddl: filled=%d; wi=%d; ri=%d", ddl->ribu->idx.filled, ddl->ribu->idx.wi, ddl->ribu->idx.ri);

  while (cl_ribu_data_avail(ddl->ribu))
  {
    pFD = cl_ribu_get(ddl->ribu);
    dl_prep_data_ind(pFD);
  }

  switch (GET_STATE (DN))
  {
  case DN_SEND:
    break;

  case DN_IDLE:
    if (pFD NEQ NULL)
    {
      SET_STATE (DN, DN_SEND);
    }
    break;

  case DN_WAIT:
    if (dl_send_data_ind())
    {
      SET_STATE (DN, DN_IDLE);
    }
    break;

  default:
    break;
  }
#ifdef _SIMULATION_
  PFREE (ra_data_ind);
#endif
}