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

📄 updown.c

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

   PRINT_DEBUG_MSG_NL2;
   PRINT_DEBUG_MSG_LVL2("holdOff: ");
   PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)holdOff);
   PRINT_DEBUG_MSG_NL2;

   /* delay */
   (void)memcpy(&delay, bufPtr, sizeof(int32_T));
   bufPtr+=sizeof(int32_T);

   PRINT_DEBUG_MSG_NL2;
   PRINT_DEBUG_MSG_LVL2("delay: ");
   PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)delay);
   PRINT_DEBUG_MSG_NL2;

   /* nsections */
   (void)memcpy(&nSections, bufPtr, sizeof(int32_T));
   bufPtr+=sizeof(int32_T);

   PRINT_DEBUG_MSG_NL2;
   PRINT_DEBUG_MSG_LVL2("nSects: ");
   PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)nSections);
   PRINT_DEBUG_MSG_NL2;

   /* each section */
   for(i=0; i<nSections; i++) {

      const int   B=0;
      const int   S=1;
      const int   W=2;
      const int   DI=3;
      int32_T     tmpBuf[4];

      (void)memcpy(&tmpBuf, bufPtr, sizeof(int32_T)*4);
      bufPtr+=(sizeof(int32_T)*4);

      PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)tmpBuf[B]);
      PRINT_DEBUG_MSG_LVL2_Raw(" ");
      PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)tmpBuf[S]);
      PRINT_DEBUG_MSG_LVL2_Raw(" ");
      PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)tmpBuf[W]);
      PRINT_DEBUG_MSG_LVL2_Raw(" ");
      PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)tmpBuf[DI]);
      PRINT_DEBUG_MSG_NL2;

   }
   PRINT_DEBUG_MSG_NL2;

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

   PRINT_DEBUG_MSG_LVL2("direction: ");
   PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)direction);
   PRINT_DEBUG_MSG_NL2;

   /* level */
   (void)memcpy(&level, bufPtr, sizeof(real_T));

   PRINT_DEBUG_MSG_LVL2("level:");
   #if DEBUG_MSG_LVL >= 3
   {
      int   i;

      for(i=0; i<sizeof(real_T); i++) {

         PRINT_DEBUG_MSG_LVL2_Raw(" 0x");
         PRINT_DEBUG_MSG_LVL2_UHex((uint8_T)bufPtr[i]);

      }
   }
   #endif
   PRINT_DEBUG_MSG_NL2;

   bufPtr+=sizeof(real_T);

} /* end DumpSelectTriggerPkt */
#else
#define DumpSelectTriggerPkt(buf) /* do nothing */
#endif


/* Function ====================================================================
 * Initialize a UploadSection.
 */
PRIVATE void InitUploadSection(RTWExtModeInfo *ei, const int32_T *buf, UploadSection *section)   /* out */ {

   int_T                         elSize;
   int_T                         offset;
   int_T                         nBytes;
   char_T                        *tranAddress;
   int_T                         tranIsComplex;

   const DataTypeTransInfo       *dtInfo=rteiGetModelMappingInfo(ei);
   const DataTypeTransitionTable *dtTable=dtGetBIODataTypeTrans(dtInfo);
   const uint_T                  *dtSizes=dtGetDataTypeSizes(dtInfo);

   const int                     BI=0;  /* index into dtype tran table (base address)  */
   const int                     SI=1;  /* starting index - wrt to base address        */
   const int                     W=2;  /* width of section (number of elements)       */
   const int                     DI=3;  /* index into data type tables                 */

   tranAddress=dtTransGetAddress(dtTable, buf[BI]);
   tranIsComplex=dtTransGetComplexFlag(dtTable, buf[BI]);

   elSize=dtSizes[buf[DI]]*(tranIsComplex?2:1);
   nBytes=(int_T)(buf[W]*elSize);
   offset=(int_T)(buf[SI]*elSize);

   section->start=tranAddress+offset;
   section->nBytes=nBytes;

} /* end InitUploadSection */


/* Function ====================================================================
 * Initialize a SysUploadTable.  The callerBufPtr points to the current place in
 * the EXT_SELECT_SIGNALS pkt which should be the enableIdx field.  This
 * function moves the callerBufPtr to the next unread field of the packet.
 */
PRIVATE boolean_T InitSysUploadTable(RTWExtModeInfo *ei, int_T          numSampTimes, SysUploadTable *sysTable, const char **callerBufPtr) /* in/out */ {

   int_T       i;
   int32_T     nTids;
   const char_T *bufPtr= *callerBufPtr;
   boolean_T   error=EXT_NO_ERROR;

   /*
    * Set pointer to enable mode.
    */
   {
      int32_T  sysIdx;

      /* read sysIdx */
      (void)memcpy(&sysIdx, bufPtr, sizeof(int32_T));
      bufPtr+=sizeof(int32_T);

      sysTable->enableState=rteiGetAddrOfSubSystemActiveVector(ei, sysIdx);
   }

   /*
    * Allocate/initialize each tid's uploadMap.
    */

   /* ...read [nTids] */
   (void)memcpy(&nTids, bufPtr, sizeof(int32_T));
   bufPtr+=sizeof(int32_T);

   /* Allocate the array of pointers to UploadMaps. */
   PRINT_DEBUG_MSG_LVL2("Allocating memory for sysTable->uploadMap (updown.c)");
   PRINT_DEBUG_MSG_NL2;
   sysTable->uploadMap=(UploadMap**)calloc(numSampTimes, sizeof(UploadMap*));
   if(sysTable->uploadMap==NULL) {

      error=EXT_ERROR; goto EXIT_POINT;

   }

   for(i=0; i<nTids; i++) {

      int32_T  tid;
      int32_T  section;
      UploadMap *map;

      /* read tid */
      (void)memcpy(&tid, bufPtr, sizeof(int32_T));
      bufPtr+=sizeof(int32_T);

      /* allocate UploadMap */
      assert(sysTable->uploadMap[tid]==NULL);
      PRINT_DEBUG_MSG_LVL2("Allocating memory for sysTable->uploadMap[tid] (updown.c)");
      PRINT_DEBUG_MSG_NL2;
      sysTable->uploadMap[tid]=(UploadMap*)calloc(1, sizeof(UploadMap));
      if(sysTable->uploadMap[tid]==NULL) {

         error=EXT_ERROR; goto EXIT_POINT;

      }
      map=sysTable->uploadMap[tid];

      /* read nSections */
      (void)memcpy(&map->nSections, bufPtr, sizeof(int32_T));
      bufPtr+=sizeof(int32_T);

      /* Allocate the blockio sections. */
      assert(map->sections==NULL);
      PRINT_DEBUG_MSG_LVL2("Allocating memory for map->sections (updown.c)");
      PRINT_DEBUG_MSG_NL2;
      map->sections=(UploadSection*)calloc((int_T)(map->nSections), sizeof(UploadSection));
      if(map->sections==NULL) {

         error=EXT_ERROR; goto EXIT_POINT;

      }

      /*
       * Init the UploadSections.
       */
      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;

      }

   }

   EXIT_POINT:*callerBufPtr=bufPtr;
   return(error);

} /* end InitSysUploadTable */


/* Function ====================================================================
 * Initialize circular buffer fields and allocate required memory.
 */
PRIVATE boolean_T UploadBufInit(CircularBuf *circBuf, int_T size) {

   boolean_T   error=NO_ERR;

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

   assert(circBuf->buf==NULL);

   circBuf->empty=TRUE;
   
   #ifdef HOSTALIVECHECK
   circBuf->full = FALSE;       /* now also monitoring 'buffer full' condition  --  fw-07-07 */
   #endif
   
   if(size>0) {

      assert(circBuf->buf==NULL);
      PRINT_DEBUG_MSG_LVL2("Allocating memory for circBuf->buf (updown.c)");
      PRINT_DEBUG_MSG_NL2;
      circBuf->buf=(char_T*)malloc(size);
      if(circBuf->buf==NULL) {

         abort_LED(96);
         error=EXT_ERROR; goto EXIT_POINT;

      }

   }
   else {

      circBuf->buf=NULL;

   }
   circBuf->bufSize=size;

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

   circBuf->newTail=NULL;
   

   #if TARGET_BOARD != C32BASED
   #if DISP_CIRCBUF_FREE == 1
   /* indicate 'buffer empty' on the 7-segment display (if chosen) */
   displayDigit(9);
   #endif
   #endif


EXIT_POINT:
   
   return(error);

} /* end UploadBufInit */


/* Function ====================================================================
 * Free all dynamically allocated fields of the trigInfo structure.
 */
PRIVATE void UploadDestroyTrigger(int32_T upInfoIdx) {

   BdUploadInfo *uploadInfo= &uploadInfoArray[upInfoIdx];
   TriggerInfo *trigInfo= &uploadInfo->trigInfo;
   UploadMap   *map= &trigInfo->trigSignals;

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

   if(map->sections!=NULL) {

      PRINT_DEBUG_MSG_LVL2("Freeing memory of map->sections (updown.c)");
      PRINT_DEBUG_MSG_NL2;
      free(map->sections);
      map->sections=NULL;

   }

   if(trigInfo->oldTrigSigVals!=NULL) {

      PRINT_DEBUG_MSG_LVL2("Freeing memory of trigInfo->oldTrigSigVals (updown.c)");
      PRINT_DEBUG_MSG_NL2;
      free(trigInfo->oldTrigSigVals);
      trigInfo->oldTrigSigVals=NULL;

   }

   /*
    * Reset trigger info.
    */
   trigInfo->state=TRIGGER_UNARMED;
   trigInfo->duration=0;
   trigInfo->holdOff=0;
   trigInfo->delay=0;
   trigInfo->lookForRising=TRUE;
   trigInfo->lookForFalling=FALSE;
   trigInfo->level=(real_T)0;
   trigInfo->count=0;
   trigInfo->overFlow=FALSE;

   trigInfo->trigSignals.nSections=0;
   trigInfo->trigSignals.sections=NULL;
   trigInfo->trigSignals.nBytes=0;

   trigInfo->oldTrigSigVals=NULL;
   trigInfo->haveOldTrigSigVal=FALSE;

   trigInfo->preTrig.duration=0;
   trigInfo->preTrig.count=0;
   trigInfo->preTrig.checkUnderFlow=FALSE;

} /* end UploadDestroyTrigger */


/* Function ====================================================================
 * Reset fields of the uploadinfo struct.
 */
PUBLIC void UploadLogInfoReset(int32_T upInfoIdx, int_T numSampTimes) {

   static boolean_T  firstTime=TRUE;
   BdUploadInfo      *uploadInfo= &uploadInfoArray[upInfoIdx];

   UNUSED_PARAMETER(numSampTimes);

   /*
    * uploadInfoArray is declared as global static, so most compilers will
    * initialize the memory to zero.  However, the tic6000 assigns this
    * variable into uninitialized memory.  When this function is called for
    * the first time, we attempt to free garbage pointers and crash.  By
    * clearing unloadInfoArray explicitly the first time this function is
    * called, we can ensure that this function will work for all compilers.
    */
   if(firstTime) {

      memset(uploadInfo, 0, sizeof(BdUploadInfo));
      firstTime=FALSE;

   }

   /* sysUploadTable */
   uploadInfo->nSys=0;
   uploadInfo->sysTables=NULL;

   uploadInfo->circBufs=NULL;

   uploadInfo->bufMemList.bufs=NULL;
   uploadInfo->bufMemList.tids=NULL;

   /* Reset trigger info */
   UploadDestroyTrigger(upInfoIdx);

} /* end UploadLogInfoReset */


/* Function ====================================================================
 * Destroy all data associated with data logging.  Fields are re-initialized
 * and pointers NULL'ed out by UploadLogInfoReset().
 */
PUBLIC void UploadLogInfoTerm(int32_T upInfoIdx, int_T numSampTimes) {

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

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

   /* Expl.: This function is called several times during shutdown... only need it once  (fw-07-07) */
   if(uploadInfo->nSys==0) {

      return;

   } /* Nothing to terminate */
   
   /* re-ordered to improve garbage collection with static memory handler... fw-07-07 */

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

   /* Free ciruclar buf fields and bufMemLists. */
   if(uploadInfo->circBufs) {

      for(i=0; i<numSampTimes; i++) {

         PRINT_DEBUG_MSG_LVL2("Freeing memory of uploadInfo->circBufs[i].Buf (updown.c)");
         PRINT_DEBUG_MSG_NL2;
         free(uploadInfo->circBufs[i].buf);

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

   }

   /*
    * Free fields of the sysUpload tables and then the table itself.
    */
   for(i=0; i<uploadInfo->nSys; i++) {

      int_T    tid;
      UploadMap **uploadMap=uploadInfo->sysTables[i].uploadMap;

      for(tid=0; tid<numSampTimes; tid++) {

         if(uploadMap[tid]!=NULL) {

⌨️ 快捷键说明

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