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

📄 updown.c

📁 RT9S12 target document
💻 C
📖 第 1 页 / 共 5 页
字号:

            /* Free fields of uploadMap. */
            PRINT_DEBUG_MSG_LVL2("Freeing memory of uploadMap[tid]->sections (updown.c)");
            PRINT_DEBUG_MSG_NL2;
            free(uploadMap[tid]->sections);

            /* Free the uploadMap. */
            PRINT_DEBUG_MSG_LVL2("Freeing memory of uploadMap[tid] (updown.c)");
            PRINT_DEBUG_MSG_NL2;
            free(uploadMap[tid]);

         }

      }

      PRINT_DEBUG_MSG_LVL2("Freeing memory of uploadMap (updown.c)");
      PRINT_DEBUG_MSG_NL2;
      free(uploadMap);

   }

   PRINT_DEBUG_MSG_LVL2("Freeing memory of uploadInfo->sysTables (updown.c)");
   PRINT_DEBUG_MSG_NL2;
   free(uploadInfo->sysTables);

   /*
    * Free trigger info.
    */
   UploadDestroyTrigger(upInfoIdx);

   /*
    * Reset all vals to initial value and NULL out pointers.
    */
   UploadLogInfoReset(upInfoIdx, numSampTimes);

} /* end UploadLogInfoTerm */


/* Function ====================================================================
 * Prepare for final flush of buffers.  This involves setting the trigger
 * state to appropriate values.
 */
PUBLIC void UploadPrepareForFinalFlush(int32_T upInfoIdx) {

   BdUploadInfo *uploadInfo= &uploadInfoArray[upInfoIdx];

   switch(uploadInfo->trigInfo.state) {

      case TRIGGER_FIRED:
      case TRIGGER_TERMINATING:
         /*
          * 1) set trig state to "terminating" so that the eventual call to
          *    UploadBufGetData knows to add the terminator flag to
          *    the data stream.
          * 2) set trig state to "oneshot" to prevent re-arming
          */
         uploadInfo->trigInfo.state=TRIGGER_TERMINATING; /* 1 */
         uploadInfo->trigInfo.holdOff=TRIGMODE_ONESHOT;    /* 2 */
         break;

      case TRIGGER_UNARMED:
      case TRIGGER_HOLDING_OFF:
      case TRIGGER_ARMED:
      case TRIGGER_DELAYED:
         /* do nothing */
         break;

   }

   #ifdef VXWORKS
   /* Let upload server run to ensure that term pkt is sent to host. One
      semGive() is for the background task and the other is for the explicit
      call to rt_UploadServerWork() in DisconnectFromHost(). */
   semGive(uploadSem);
   semGive(uploadSem);
   #endif

   #ifdef LCDUSE4ERRORS
   /* cosmetics and debug msgs */
   DisplayTriggerStateOnLCD(upInfoIdx);
   #endif

} /* end UploadPrepareForFinalFlush */


/* Function ====================================================================
 * Initialize data uploading by processing the EXT_SELECT_SIGNALS packet
 * (which is passed in).  Return the error status.  See DumpSelectSignalPkt()
 * for a detailed description of the packet.
 */
PUBLIC boolean_T UploadLogInfoInit(RTWExtModeInfo *ei, int_T          numSampTimes, const char *pkt, int32_T        upInfoIdx) {

   int         nActiveTids;
   int_T       i;
   boolean_T   error=EXT_NO_ERROR;
   const char  *bufPtr=pkt;
   BdUploadInfo *uploadInfo;

   // local function name... debugging only
   #if DEBUG_MSG_LVL > 0
   const char  *funct_name="UploadLogInfoInit";
   #endif

   PRINT_DEBUG_MSG_LVL2("IN\n\r");

   DumpSelectSignalPkt(pkt, numSampTimes);

   /* Point to the correct uploadInfo */
   uploadInfo= &uploadInfoArray[upInfoIdx];
   uploadInfo->upInfoIdx=upInfoIdx;

   /* Free upInfo if fields are already allocated */
   UploadLogInfoTerm(upInfoIdx, numSampTimes);

   /* nSys */
   (void)memcpy(&uploadInfo->nSys, bufPtr, sizeof(int32_T));
   bufPtr+=sizeof(int32_T);
   assert(uploadInfo->sysTables==NULL);
   PRINT_DEBUG_MSG_LVL2("Allocating memory for uploadInfo->sysTables (updown.c)");
   PRINT_DEBUG_MSG_NL2;
   uploadInfo->sysTables=(SysUploadTable*)calloc((int_T)(uploadInfo->nSys), sizeof(SysUploadTable));
   if(uploadInfo->sysTables==NULL) {

      error=EXT_ERROR; goto EXIT_POINT;

   }

   /*
    * Init each system table.
    */
   for(i=0; i<uploadInfo->nSys; i++) {

      error=InitSysUploadTable(ei, numSampTimes, &uploadInfo->sysTables[i], &bufPtr);
      if(error!=EXT_NO_ERROR) {

         goto EXIT_POINT;

      }

   }

   assert(uploadInfo->circBufs==NULL);
   PRINT_DEBUG_MSG_LVL2("Allocating memory for uploadInfo->circBufs (updown.c)");
   PRINT_DEBUG_MSG_NL2;
   uploadInfo->circBufs=(CircularBuf*)calloc(numSampTimes, sizeof(CircularBuf));

   /*
    * Allocate the circular buffers.
    */
   nActiveTids=0;
   for(i=0; i<numSampTimes; i++) {

      int32_T  size;

      (void)memcpy(&size, bufPtr, sizeof(int32_T));

      /* limit size on the 9S12 - only 12k of RAM available, heap limited to 8k  --  fw-03-05 */
      #ifndef MATLAB_MEX_FILE
      if(size>CIRCBUFSIZE) {

         size=CIRCBUFSIZE;

      }
      #endif

      bufPtr+=sizeof(int32_T);

      error=UploadBufInit(&uploadInfo->circBufs[i], (int_T)size);
      if(error!=EXT_NO_ERROR) {

         goto EXIT_POINT;

      }

      nActiveTids+=(size!=0);

   }

   /*
    * Initialize/Allocate the bufMemLists - these are used by
    * ext_svr to pull the appropriate data out of the buffers and send it
    * to the host.
    */
   #if ASSERTS_ON
   uploadInfo->bufMemList.maxBufs=nActiveTids;
   #endif
   uploadInfo->bufMemList.nActiveBufs=0;

   assert(uploadInfo->bufMemList.bufs==NULL);
   PRINT_DEBUG_MSG_LVL2("Allocating memory for uploadInfo->bufMemList.bufs (updown.c)");
   PRINT_DEBUG_MSG_NL2;
   uploadInfo->bufMemList.bufs=(BufMem*)malloc(nActiveTids*sizeof(BufMem));
   if(uploadInfo->bufMemList.bufs==NULL) {

      error=EXT_ERROR; goto EXIT_POINT;

   }

   assert(uploadInfo->bufMemList.tids==NULL);
   PRINT_DEBUG_MSG_LVL2("Allocating memory for uploadInfo->bufMemList.tids (updown.c)");
   PRINT_DEBUG_MSG_NL2;
   uploadInfo->bufMemList.tids=(int_T*)malloc(nActiveTids*sizeof(int_T));
   if(uploadInfo->bufMemList.tids==NULL) {

      error=EXT_ERROR; goto EXIT_POINT;

   }

   EXIT_POINT:
   if(error!=EXT_NO_ERROR) {

      UploadLogInfoTerm(upInfoIdx, numSampTimes);

   }

   PRINT_DEBUG_MSG_LVL2("OUT, error status: ");
   PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)error);
   PRINT_DEBUG_MSG_NL2;

   return(error);

} /* end UploadLogInfoInit */


/* Function ====================================================================
 * Initialize and configure the trigger attributes.  See DumpSelectTriggerPkt()
 * for a detailed description of the packet.
 */
PUBLIC boolean_T UploadInitTrigger(RTWExtModeInfo *ei, const char *pkt, int32_T         upInfoIdx) {

   int_T       nSections;
   int32_T     i32_tid;
   int32_T     direction;
   TriggerInfo *trigInfo;
   boolean_T   error=EXT_NO_ERROR;
   const char  *bufPtr=pkt;

   // local function name... debugging only
   #if DEBUG_MSG_LVL > 0
   const char  *funct_name="UploadInitTrigger";
   #endif

   DumpSelectTriggerPkt(pkt);

   /* Select the trig Info */
   trigInfo= &uploadInfoArray[upInfoIdx].trigInfo;

   /* tid, duration, holdOff, delay and nsections */
   (void)memcpy(&i32_tid, bufPtr, sizeof(int32_T));
   bufPtr+=sizeof(int32_T);
   trigInfo->tid=(int_T)i32_tid;

   (void)memcpy(&trigInfo->duration, bufPtr, sizeof(int32_T));
   bufPtr+=sizeof(int32_T);

   (void)memcpy(&trigInfo->holdOff, bufPtr, sizeof(int32_T));
   bufPtr+=sizeof(int32_T);

   (void)memcpy(&trigInfo->delay, bufPtr, sizeof(int32_T));
   bufPtr+=sizeof(int32_T);

   (void)memcpy(&trigInfo->trigSignals.nSections, bufPtr, sizeof(int32_T));
   bufPtr+=sizeof(int32_T);

   nSections=(int_T)(trigInfo->trigSignals.nSections);

   /*
    * Init the UploadSections - if the trigger is signal based.
    */
   if(nSections>0) {

      /* trigger is signal based */
      int      section;
      UploadMap *map= &trigInfo->trigSignals;

      assert(map->nBytes==0);
      assert(map->sections==NULL);
      PRINT_DEBUG_MSG_LVL2("Allocating memory for map->sections (updown.c)");
      PRINT_DEBUG_MSG_NL2;
      map->sections=(UploadSection*)malloc(nSections*sizeof(UploadSection));
      if(map->sections==NULL) {

         error=EXT_ERROR; goto EXIT_POINT;

      }

      for(section=0; section<map->nSections; section++) {

         int32_T        tmpBuf[4];
         UploadSection  *uploadSection= &map->sections[section];

         /* read [B S W DI] */
         (void)memcpy(&tmpBuf, bufPtr, sizeof(int32_T)*4);
         bufPtr+=(sizeof(int32_T)*4);

         InitUploadSection(ei, tmpBuf, uploadSection);

         /* keep track of total number of bytes in this map */
         map->nBytes+=uploadSection->nBytes;

      }

      /*
       * Allocate space to hold the old values of the trigger signals.  Note
       * that trigger signals are gauranteed to be of type SL_DOUBLE (real_T)
       * and noncomplex.
       */
      assert(trigInfo->oldTrigSigVals==NULL);
      assert(trigInfo->oldTrigSigVals==NULL);
      PRINT_DEBUG_MSG_LVL2("Allocating memory for trigInfo->oldTrigSigVals (updown.c)");
      PRINT_DEBUG_MSG_NL2;
      trigInfo->oldTrigSigVals=(real_T*)malloc(map->nBytes);
      if(trigInfo->oldTrigSigVals==NULL) {

         error=EXT_ERROR; goto EXIT_POINT;

      }

   }

   /* Direction. */
   (void)memcpy(&direction, bufPtr, sizeof(int32_T));
   bufPtr+=sizeof(int32_T);

   trigInfo->lookForRising=((direction==UPLOAD_RISING_TRIGGER)||(direction==UPLOAD_EITHER_RISING_OR_FALLING_TRIGGER));

   trigInfo->lookForFalling=((direction==UPLOAD_FALLING_TRIGGER)||(direction==UPLOAD_EITHER_RISING_OR_FALLING_TRIGGER));

   /* level */
   (void)memcpy(&trigInfo->level, bufPtr, sizeof(real_T));
   bufPtr+=sizeof(real_T);

   /*
    * Convert delay to pre-trigger duration.
    */
   if(trigInfo->delay<0) {

      trigInfo->preTrig.duration= -trigInfo->delay;
      trigInfo->delay=0;

   }
   else {

      trigInfo->preTrig.duration=0;

   }

   EXIT_POINT:
   if(error!=EXT_NO_ERROR) {

      UploadDestroyTrigger(upInfoIdx);

   }
   return(error);

} /* end UploadInitTrigger */


/* Function ====================================================================
 * Arm the trigger.
 */
PUBLIC void UploadArmTrigger(int32_T upInfoIdx, int_T numSampTimes) {

   int_T       tid;
   BdUploadInfo *uploadInfo= &uploadInfoArray[upInfoIdx];

   assert((uploadInfo->trigInfo.state==TRIGGER_UNARMED)||(uploadInfo->trigInfo.state==TRIGGER_HOLDING_OFF));

   /*
    * Re-initialize.
    */
   uploadInfo->trigInfo.overFlow=FALSE;
   for(tid=0; tid<numSampTimes; tid++) {

      CircularBuf *circBuf= &uploadInfo->circBufs[tid];
      if(circBuf->bufSize>0) {

         circBuf->head=circBuf->buf;
         circBuf->tail=circBuf->buf;

         circBuf->newTail=NULL;
         circBuf->empty=TRUE;

         #ifdef HOSTALIVECHECK
         circBuf->full = FALSE;       /* now also monitoring 'buffer full' condition  --  fw-07-07 */
         #endif

      }

   }

   /* 
    * Re-initialize trigger fields.
    */
   uploadInfo->trigInfo.count=0;
   uploadInfo->trigInfo.haveOldTrigSigVal=FALSE;

   /* 
    * Reset pre-trig counts for normal mode.
    */
   uploadInfo->trigInfo.preTrig.count=0;

   /* 
    * Re-arm after all initialization.  Make sure that trigInfo.state is
    * set last since this routine may be interupted.
    */
   uploadInfo->trigInfo.state=TRIGGER_ARMED;

   #ifdef LCDUSE4ERRORS
   /* cosmetics and debug msgs */
   DisplayTriggerStateOnLCD(upInfoIdx);
   #endif

} /* end UploadArmTrigger */


/* Function ====================================================================
 * Terminate this data logging session by destroying the uploadInfo and
 * setting the trigger backed to the unarmed state.
 */
PUBLIC void UploadEndLoggingSession(int32_T upInfoIdx, int_T numSampTimes) {

   BdUploadInfo *uploadInfo= &uploadInfoArray[upInfoIdx];

   uploadInfo->trigInfo.state=TRIGGER_UNARMED;

   #ifdef LCDUSE4ERRORS
   /* cosmetics and debug msgs */
   DisplayTriggerStateOnLCD(upInfoIdx);
   #endif

   UploadLogInfoTerm(upInfoIdx, numSampTimes);

} /* end UploadEndLoggingSession */


/* Function ====================================================================
 * Cancel this data logging session.
 */
PUBLIC void UploadCancelLogging(int32_T upInfoIdx) {

⌨️ 快捷键说明

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