FreeCalypso > hg > fc-tourmaline
view src/g23m-fad/l2r/tra_upf.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_upf.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 procedures and functions for | the component TRA +----------------------------------------------------------------------------- */ #ifndef TRA_UPF_C #define TRA_UPF_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" #ifdef _TARGET_ #include "ra_l1int.h" #endif /*==== CONST =======================================================*/ /*==== TYPES =======================================================*/ /*==== VAR EXPORT ==================================================*/ /*==== VAR LOCAL ===================================================*/ /*==== FUNCTIONS ===================================================*/ /* +------------------------------------------------------------------------------ | Function : up_init +------------------------------------------------------------------------------ | Description : initialise the tra data for the uplink process | | Parameters : - | | | Return : - +------------------------------------------------------------------------------ */ GLOBAL void ul_init(T_TRA_UP *dul) { TRACE_FUNCTION ("ul_init()"); dul->sa = FL_INACTIVE; dul->sb = FL_INACTIVE; dul->x = FL_INACTIVE; dul->List_off = 0; INIT_STATE (UP, UP_INACTIVE); } /* +------------------------------------------------------------------------------ | Function : snd_break_to_RA +------------------------------------------------------------------------------ | Description : | | Parameters : - | | | Return : +------------------------------------------------------------------------------ */ GLOBAL void snd_break_to_RA(USHORT break_len) { #ifndef _SIMULATION_ T_RA_BREAK_REQ RA_break_req; RA_break_req.break_len = break_len; #endif TRACE_FUNCTION ("snd_break_to_RA()"); #ifndef _SIMULATION_ l1i_ra_break_req (&RA_break_req); #else { PALLOC (ra_break_req, RA_BREAK_REQ); ra_break_req->break_len = break_len; PSENDX (RA, ra_break_req); } #endif } /* +------------------------------------------------------------------------------ | Function : snd_data_to_RA +------------------------------------------------------------------------------ | Description : | | Parameters : - | | | Return : +------------------------------------------------------------------------------ */ GLOBAL void snd_data_to_RA(void) { T_TRA_UP *dul = &tra_data->up; T_FD *pFD = &dul->fd; T_desc2 *desc = (T_desc2*)dul->Prim->desc_list2.first; USHORT data_off = dul->List_off; /* offset within current data block */ USHORT data_len = dul->Prim->desc_list2.list_len; /* local mark for overall data size to be copied */ TRACE_FUNCTION ("snd_data_to_RA()"); pFD->type = FR_TRANS; pFD->status = 0; pFD->len = 0; /* to mark current sdu fill status */ if (dul->req_frames) { while (desc) { if (desc->len <= (dul->req_frames - pFD->len)) /* DTI data size less than SDU space*/ { T_desc2 *desc_im = (T_desc2*)desc->next; memcpy(&dul->to_ra[pFD->len], desc->buffer + data_off, desc->len); pFD->len += desc->len; data_len -= desc->len; data_off = 0; /* list is copied completely! */ MFREE (desc); desc = (T_desc2*) desc_im; } else /* more DTI data than SDU space*/ { memcpy(&dul->to_ra[pFD->len], desc->buffer + data_off, dul->req_frames - pFD->len); data_off += (dul->req_frames - pFD->len); /* remember for next copying! */ desc->len -= (dul->req_frames - pFD->len); desc->size = desc->len; data_len -= (dul->req_frames - pFD->len); pFD->len = dul->req_frames; /* the SDU is full */ break; } } /* * write back current standings */ dul->Prim->desc_list2.first = (ULONG)desc; dul->Prim->desc_list2.list_len = data_len; dul->List_off = data_off; } if (dul->sa EQ DTI_SA_OFF) pFD->status |= ST_SA; if (dul->sb EQ DTI_SB_OFF) pFD->status |= ST_SB; if (dul->x EQ DTI_FLOW_OFF) pFD->status |= ST_X; #ifdef _TARGET_ l1i_ra_data_req_new(pFD); #else { PALLOC_SDU (ra_data_req, RA_DATA_REQ, (USHORT)(dul->req_frames<<3)); if (hCommRA < VSI_OK) { hCommRA = vsi_c_open (VSI_CALLER RA_NAME); } ra_data_req->fr_type = pFD->type; ra_data_req->status = pFD->status; ra_data_req->dtx_flg = DTX_DIS; ra_data_req->sdu.l_buf = pFD->len << 3; ra_data_req->sdu.o_buf = 0; memcpy(&ra_data_req->sdu.buf[0], &dul->to_ra[0], pFD->len); PSENDX (RA, ra_data_req); } #endif } /* +------------------------------------------------------------------------------ | Function : up_start_dti_flow +------------------------------------------------------------------------------ | Description : | | Parameters : - | | | Return : - +------------------------------------------------------------------------------ */ GLOBAL void up_start_dti_flow(void) { TRACE_FUNCTION ("up_start_dti_flow()"); dti_start(l2r_hDTI, TRA_DTI_UP_INSTANCE, TRA_DTI_UP_INTERFACE, TRA_DTI_UP_CHANNEL); }