⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csr.c

📁 GSM手机设计软件代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* 
+----------------------------------------------------------------------------- 
|  Project :  
|  Modul   :  J:\g23m-gsm\csr\bridge\csr.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 :  
+----------------------------------------------------------------------------- 
*/ 
#include "interface/csr.h"
#include "sms/csr_sms.h"

/****************************************************************************
 * OS functions
 ****************************************************************************/

/* Cursor signals */
typedef enum {
  SIG_RR_CSR_MEAS_IND,
  SIG_RR_CSR_MEAS_CNF,
  SIG_RR_CSR_MEAS_REQ,
  SIG_RR_CSR_TIMINGADV_IND,
  SIG_CSR_POSN_DATA_REQ,
  SIG_CSR_POSN_DATA_CNF,
  SIG_CSR_PROCEEDING_IND,
  SIG_CSR_ABORT_REQ,
  SIG_CSR_ABORT_CNF,
  SIG_TIMER_EXPIRY
} SignalId;

typedef struct {
  SignalId type;
  union {
    RrCsrMeasInd rrCsrMeasInd;
    RrCsrTimingAdvInd rrCsrTimingAdvInd;
    CsrPosnDataReq csrPosnDataReq;
    CsrPosnDataCnf csrPosnDataCnf;
    CsrProceedingInd csrProceedingInd;
    CsrAbortReq csrAbortReq;
    CsrAbortCnf csrAbortCnf;
    /* No particular type for timer expiry */
  } sig;
} SignalBuffer;

void GetRelativeTime (FrameTicks *);

/* A notional timer type */
typedef int Timer;

/* With these operations */
void StartTimer (Timer *timer);
void StopTimer (Timer *timer);
void SetTimeoutPeriod (Timer *timer,int period);
void InitializeTimer (Timer *timer);
Boolean TimerRunning (Timer *timer);

void ReceiveSignal(int queue, SignalBuffer *buffer);
void SendSignal(int task, SignalBuffer *buffer);

/* Macro definitions */
#define NULL 0
#define MAX_CALLS 1
#define SECONDS_TO_TICKS(secs) ((secs) * (13000 / 60))
#define CSR_QUEUE_ID 0

#define CSR_TASK_ID 0
#define RR_TASK_ID 1
#define AL_TASK_ID 2

#define TIMER_NOT_RUNNING 0

#define FALSE 0
#define TRUE 1

/* Forward declarations */
void sendCsrProceedingInd(      SignalBuffer * const signalOut,
                          const CallReference * const callRef);

void sendCsrAbortCnf(      SignalBuffer  * const signalOut,
                     const CallReference * const callRef);

void sendCsrPosnDataCnf(const TaBuffer          * const taBuffers,
                              SignalBuffer      * const signalOut,
                        const CallReference     * const callRef,
                        const CalledPartyBcdNum * const bcdNum,
                        const Boolean                   gotData );

void sendRrCsrMeasReq(SignalBuffer * const signalOut);

/* The main task function */
void CsrTask(void)
{
  /* used to receive signals */
  static SignalBuffer receivedSignal;

  /* used to send signals */
  static SignalBuffer signalToSend;

  /* this timer is used to timeout on a position data request. */
  Timer         ctDataTimer;

  /* CsrPosnDataReq variables.

     When a CsrPosnDataReq signal is received these are initialised to
     values in the signal. They then get included in the response
     signal.

     For each posn request that comes in, the following information is
     stored for it: after receipt of an abort message for one of the
     position requests, requireTa is used to determine whether we
     should be in WANT_DATA or WANT_TA state. */

  CallReference         theCallReference[MAX_CALLS];
  CalledPartyBcdNum     theBcdNum[MAX_CALLS];
  Boolean               requireTa[MAX_CALLS];

  typedef enum StateIdTag {
    CT_STATE_IDLE,
    CT_STATE_WANT_DATA,
    CT_STATE_WANT_TA
  } StateId;
  StateId ctState;
  
  UInt8 looper,looper2;

  /* circular data buffer. Initialise to "EMPTY" */
  static DataBuffer dataBuffer;
  static TaBuffer taBuffer;

  /* counts the number of position request calls currently being setup
     by CC.  We don't expect this to be >1, but the code has been
     written to allow this. */
  UInt8 nCalls = 0;

  /* time allowed after receiving data until invalid. */
  const FrameTicks MAX_DATA_TIME = SECONDS_TO_TICKS(300);

  /* holds the currentTime; */
  FrameTicks currentTime;
  /* Whether we have valid data. */
  Boolean validData = FALSE;

  Boolean dataOkToLoad;

  /* CODE STARTS HERE. */

  /* initialise timer. */
  InitializeTimer (&ctDataTimer);
  SetTimeoutPeriod(&ctDataTimer,SECONDS_TO_TICKS(30)); 
  /* Initialise State Machine. */
  ctState = CT_STATE_IDLE;

  dataBuffer.dataValid = FALSE;
  taBuffer.taValid = FALSE;

  while (TRUE)
  {
    /* After we have handled a message, this variable says if we are
       ready to send a PosnDataConf to AL */
    Boolean readyToSend = FALSE;
    /* get a signal */
    ReceiveSignal (CSR_QUEUE_ID, &receivedSignal);

    /* switch on received signal */
    switch (receivedSignal.type)
    {
      case SIG_RR_CSR_MEAS_IND:
      case SIG_RR_CSR_MEAS_CNF:
        /* Either of these messages pass us data from RR in a
           rrCsrMeasInd structure. So we can treat them
           equivalently. */
        
        /* Check to see if serving cell is available. Don't bother
           writing over possibly good data if it isn't */
        dataOkToLoad = FALSE;
        
        if (receivedSignal.sig.rrCsrMeasInd.servingCellCsrData1.csrDataValid)
        {
          /* get CurrentTime. */
          GetRelativeTime ( &currentTime );
          
          /* We invalidate the dataBuffer if it is older than
             MAX_DATA_TIME. */
          if ((UInt32)(currentTime - (dataBuffer.timeTag)) >= MAX_DATA_TIME) 
          {
            dataBuffer.dataValid = FALSE;
          }   
          
          /* If the data in the buffer is valid then don't want to wipe
             over it with data lacking neighbours. If data in the buffer
             invalid will write it anyway as serving cell is still
             info. */
          if (dataBuffer.dataValid)
          {
            for (looper = 0; looper < N_CSR_NEIGHBOURS; ++looper)
            {
              if (receivedSignal.sig.rrCsrMeasInd.
                  neighbourCsrData[looper].neighbourCsrDataValid)
              {
                dataOkToLoad = TRUE;
                /* Break out of the loop - not the switch case (okay as
                   C breaks out of the innermost block. */
                break;
              }
            }
          }
          else {
            dataOkToLoad = TRUE;
          }
        }

        if (dataOkToLoad)
        {
          /* store data in the buffer with timetag of currentTime. Also
             tag it with the current time. */
          dataBuffer.timeTag = currentTime;
          /* take info. from theData to theBuffer. */
          dataBuffer.csrData = receivedSignal.sig.rrCsrMeasInd;
          dataBuffer.dataValid = TRUE;

          /* And call updateTimings */
          csrUpdateTimings(&dataBuffer);
        }

        /* if waiting for data: you've got it now so go ahead and send it. */
        if (ctState == CT_STATE_WANT_DATA)
        {
          /* we expect the timer to be still running at this
             point, so stop it. */
          if (TimerRunning (&ctDataTimer))
          {
            StopTimer (&ctDataTimer);
          }

          readyToSend = TRUE;
          ctState = CT_STATE_IDLE;
        }
        break;

      case (SIG_CSR_POSN_DATA_REQ):
        /* It is a CsrPosnDataReq message. */
        
        if (ctState == CT_STATE_IDLE)
        {
          /* extract info from signal */
          nCalls = 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -