view src/g23m-gsm/ss/ss.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 fa8dc04885d8
children
line wrap: on
line source

/* 
+----------------------------------------------------------------------------- 
|  Project :  GSM-PS (6147)
|  Modul   :  SS
+----------------------------------------------------------------------------- 
|  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 :  Definitions for the Protocol Stack Entity
|             Supplementary Services.
+----------------------------------------------------------------------------- 
*/ 

#ifndef SS_H
#define SS_H

#include <stdlib.h>
#include <stdio.h>
#if defined (TI_PS_HCOMM_CHANGE)
#include "cl_hComm_handle.h"
#endif
/*
 * Definition whether a shared CCD buffer shall be used
 */
#define SHARED_CCD_BUF

/* #define SS_TEST */ /* set for T() debug outputs */

#define ENCODE_OFFSET            24
#define PD_SS                    11

#ifdef SS_TEST
#define T(f,v)    sprintf ((char*)trc, f, v); TRACE_FUNCTION ((char*)trc)
#else
#define T(f,v)                    ;
#endif

/*
 * Macros (common for SS and CC)
 */

#define GET_SS_STATE(s,t) ((s>>(2*t)) & 0x03)
#define SET_SS_STATE(s,t,STATE) (s=(s & (~(((ULONG)0x03)<<(2*t)))) |(STATE<<(2*t)))


#ifdef FRAME_OFFSET_ZERO

#define GET_PD(s,p)  p = s.buf[3] & 0x0F
#define GET_TI(s,t)  t = (s.buf[3] & 0xF0) >> 4
#define SET_PD(s,p)  s.buf[3] = (s.buf[3] & 0xF0) + p
#define SET_TI(s,t)  s.buf[3] = (s.buf[3] & 0x0F) + (t << 4)

#else

#define GET_PD(s,p)  ccd_decodeByte(s.buf, (USHORT)(s.o_buf + 4), 4, &p)
#define GET_TI(s,t)  ccd_decodeByte(s.buf, s.o_buf, 4, &t)
#define SET_PD(s,p)  ccd_codeByte(s.buf, (USHORT)(s.o_buf - 4), 4, p)
#define SET_TI(s,t)  ccd_codeByte(s.buf, (USHORT)(s.o_buf - 8), 4, t)

#endif

/*
 * States of the Suppl. Services
 */
#define SS_IDLE                   0
#define SS_CONNECTION_PENDING     1
#define SS_CONNECTED              2

/*
 * limits
 */
#define MAX_INST                  16
#define MAX_SIZE_SS_MESSAGE       256

/*
 * Length of uplink messages
 * These are comprised of the minimum 'safe' air i/f message length 
 * according to the SS message catalogue
 */
#define LEN_U_SS_REGISTER           (7*8)
#define LEN_U_SS_RELEASE_COMPLETE   (7*8)
#define LEN_U_SS_FACILITY           (7*8)




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

typedef struct
{
  BOOL                  est_flag;

  UBYTE                 pd;
  ULONG                 ss_state;
  T_PRIM              * prim [MAX_INST];
  UBYTE                 ti;
  UINT                  error;
} T_SS_DATA;

EXTERN T_SS_DATA ss_data_base;
#define GET_INSTANCE_DATA  register T_SS_DATA * ss_data = &ss_data_base

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


/*
 * Prototypes Customer Specific Functions
 */

/*
 *  Prototypes SS
 */


/*
 *  SS Suppl. Services
 */

/*
 * suppl. services primitives
 */

EXTERN void ss_init_ss_data         (void);
EXTERN void ss_mmss_error_ind       (T_MMSS_ERROR_IND    *mmss_error_ind);
EXTERN void ss_mmss_establish_cnf   (T_MMSS_ESTABLISH_CNF*mmss_establish_cnf);
EXTERN void ss_mmss_release_ind     (T_MMSS_RELEASE_IND  *mmss_release_ind);
EXTERN void ss_mnss_begin_req       (T_MNSS_BEGIN_REQ    *mnss_begin_req);
EXTERN void ss_mnss_end_req         (T_MNSS_END_REQ      *mnss_end_req);
EXTERN void ss_mnss_facility_req    (T_MNSS_FACILITY_REQ *mnss_facility_req);



/*
 *  suppl. services signalling
 */
EXTERN void ss_b_ss_rel_comp            (void);
EXTERN void ss_d_ss_facility            (void);
EXTERN void ss_d_ss_register            (void);

/*
 *  suppl. services procedures
 */
EXTERN void ss_init                     (void);
EXTERN void send_rel_comp               (U8                  cause);

EXTERN BOOL ss_check_critical_error(UINT ccd_err);
/*
 *  Formatter
 */

/*
 *  formatter primitives
 */
EXTERN void for_init_ss_data         (void);
EXTERN void for_mmss_establish_ind   (T_MMSS_ESTABLISH_IND *mmss_establish_ind);
EXTERN void for_mmss_data_ind        (T_MMSS_DATA_IND     *mmss_data_ind);

/*
 *  formatter signalling
 */
EXTERN void ss_for_data_req                (USHORT               bit_size_message);


/*
 * If all entities are linked into one module this definitions
 * prefixes the global data with the enity name
 */
#if defined (TI_PS_HCOMM_CHANGE)
#if defined (NEW_FRAME)
EXTERN T_HANDLE ss_handle;
#endif
#else /* (TI_PS_HCOMM_CHANGE) */
#ifdef OPTION_MULTITHREAD
  #define hCommMM        _ENTITY_PREFIXED(hCommMM)
  #define hCommMMI       _ENTITY_PREFIXED(hCommMMI)
#endif
#if defined (NEW_FRAME)
EXTERN T_HANDLE         hCommMMI;        /* MM  Communication        */
EXTERN T_HANDLE         hCommMM;         /* MM  Communication        */
EXTERN T_HANDLE         ss_handle;
#else
EXTERN T_VSI_CHANDLE  hCommMMI;        /* MM  Communication        */
EXTERN T_VSI_CHANDLE  hCommMM;         /* MM  Communication        */
#endif
#endif /* (TI_PS_HCOMM_CHANGE) */
/*
 * If all entities are linked into one module this definitions
 * prefixes the global data with the enity name
 */
#ifdef OPTION_MULTITHREAD
  #define _decodedMsg   _ENTITY_PREFIXED(_decodedMsg)
#endif

#if !defined SHARED_CCD_BUF
#define CCD_START
#define CCD_END
EXTERN UBYTE          _decodedMsg [];
#else
EXTERN UBYTE *        _decodedMsg;
#define CCD_START _decodedMsg = ccd_begin();
#define CCD_END   ccd_end();
#endif



#endif