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

📄 pc_m1.c

📁 PWM同步
💻 C
📖 第 1 页 / 共 4 页
字号:
        /* copy identification string */
        for (cnt=0 ; cnt < PCMDRV_IDT_STRING_LEN ; cnt++) {
          ((sReturnData *)((PCMasterComm)->p_dataBuff))->data[10 + cnt] = PCMasterComm->idtString[cnt];
        }
        /* OK */
        respPrepare(PCMDRV_STC_OK,(1 + 10 + PCMDRV_IDT_STRING_LEN));
    }break;
    #endif
    #ifdef PCMDRV_INCLUDE_CMD_RECORDER
    case PCMDRV_CMD_STARTREC: {        /* start recorder */
        if (PCMasterComm->recSize==0) { /* recorder not implemented  */
          respPrepare(PCMDRV_STC_INVCMD,1); /* invalid command */
          return;
        }
        if(((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->varCnt) { /* recorder initialized      */
          if (!(status & ST_RECRUNNING)) { /* recorder not running      */
            bitClear(ST_RECRUNNING,status); /* stop recorder if it is running   */
            (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recTime) = /* initialize time div       */
              ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->timeDiv; /* addr. of triggering variable  */
            varaddr=(unsigned char*)(((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgVarAddr);
            memCopy((UInt8*)(((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgVarAddr[0]),
              (UInt8*)(&(((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recLastVal.ud)),
              (Int8)(((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgVarSize));
            bitSet(ST_RECACTIVATED,status); /* activate recorder to wait for trigger */
            respPrepare(PCMDRV_STC_OK,1); /* OK */
          }
          else {
            respPrepare(PCMDRV_STC_RECRUN,1); /* recorder is running  */
          }
        }
        else {                         /* recorder is not initialized   */
          respPrepare(PCMDRV_STC_NOTINIT,1); /* recorder not initialized   */
        }
    }break;
    #endif
    #ifdef PCMDRV_INCLUDE_CMD_RECORDER /* start recorder */
    case PCMDRV_CMD_STOPREC: {         /* stop recorder  */
        if (PCMasterComm->recSize==0) { /* recorder not implemented   */
          respPrepare(PCMDRV_STC_INVCMD,1); /* invalid command   */
          return;
        }
        if (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->varCnt) { /* recorder initialized */
          if (status & ST_RECACTIVATED) { /* recorder activated   */
            if (status & ST_RECRUNNING) { /* recorder running     */
              respPrepare(PCMDRV_STC_RECDONE,1); /* recorder finished    */
            }
            else {                     /* recorder not running */
              /* initialize posttrigger value  */
              (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd)=
                (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->postTrigger);
              bitSet(ST_RECRUNNING,status); /* manually trigger the recorder */
              respPrepare(PCMDRV_STC_OK,1); /* OK */
            }
          }
          else {                       /* recorder not activated  */
            respPrepare(PCMDRV_STC_RECDONE,1); /* recorder finished       */
          }
        }
        else {                         /* recorder not initialized*/
          respPrepare(PCMDRV_STC_NOTINIT,1);
        }
    }break;
    #endif
    #ifdef PCMDRV_INCLUDE_CMD_RECORDER /* start recorder          */
    case PCMDRV_CMD_GETRECBUFFEX: {    /* get recorder buffer     */
        UWord16        tmp;            /* temporary variable      */

        if (PCMasterComm->recSize==0) { /* recorder not implemented*/
          respPrepare(PCMDRV_STC_INVCMD,1);
          return;
        }
        if ((((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->varCnt) != 0) { /* recorder initialized */
          if (!(status & ST_RECRUNNING)) { /* recorder not running */
            /* recorder buffer address */
            memCopy((UInt8*)(&(PCMasterComm->p_recBuff)),(UInt8*)(&(PCMasterComm->p_dataBuff[1])),LONG_LEN);
            tmp=(((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recPos)/
              (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recSetLen);
            (PCMasterComm)->p_dataBuff[5]= (UInt8)(tmp & 0x00FF); /* position of the last sample in rec.buff. LSB */
            (PCMasterComm)->p_dataBuff[6]= (UInt8)(tmp >> 8); /* position of the last sample in rec.buff. MSB */
            respPrepare(PCMDRV_STC_OK,7); /* OK */
          }
          else {                       /* recorder running  */
            respPrepare(PCMDRV_STC_SERVBUSY,1); /*  service busy     */
          }
        }
        else {                         /* recorder initialized */
          respPrepare(PCMDRV_STC_NOTINIT,1); /* recorder not initialized   */
        }
    }break;
    #endif
    #ifdef PCMDRV_INCLUDE_CMD_RECORDER /* recorder status            */
    case PCMDRV_CMD_GETRECSTS: {       /* get recorder status        */
        if (PCMasterComm->recSize==0) { /* recorder not implemented   */
          respPrepare(PCMDRV_STC_INVCMD,1); /* invalid command            */
          return;
        }
        if (((pcmdrv_sScope *)(PCMasterComm->p_recorder))->varCnt) { /* recorder is initialized    */
          if (!(status & ST_RECACTIVATED)) {
            respPrepare(PCMDRV_STC_RECDONE,1); /* recorder finished          */
          }
          else {
            respPrepare(PCMDRV_STC_RECRUN,1); /* recorder running           */
          }
        }
        else {                         /* recorder is not initialized*/
          respPrepare(PCMDRV_STC_NOTINIT,1); /* recorder not initialized   */
        }
    }break;
    #endif
    /* --------------------------
        standard format commands
       -------------------------- */
    #ifdef PCMDRV_INCLUDE_CMD_SCOPE
    case PCMDRV_CMD_SETUPSCOPEEX: {    /* setup scope */
        unsigned char cnt,i;

        cnt = (((sSetupScopeEx *)(PCMasterComm->p_dataBuff))->varCnt);
        if ( (cnt == 0) || (cnt > 8) ) {
          /* varCnt is zero or greater than 8 */
          respPrepare(PCMDRV_STC_INVBUFF,1); /* invalid buffer size */
          return;
        }
        /* read varCnt */
        ((pcmdrv_sScope *)(PCMasterComm->p_scope))->varCnt = cnt;
        for (i=0; i < cnt; i++) {
          /* read size of variable */
          ((pcmdrv_sScope *)(PCMasterComm->p_scope))->varDef[i].varSize =
          ((sSetupScopeEx *)(PCMasterComm->p_dataBuff))->dataByte[i*5];
          /* read address of variable */
          memCopy( (unsigned char *)&((sSetupScopeEx *)
            (PCMasterComm->p_dataBuff))->dataByte[1 + 5*i],
            ((pcmdrv_sScope *)(PCMasterComm->p_scope))->
            varDef[i].addrByte, POINT32_LEN);
        }
        /* check size of variable s */
        for(i=0 ; i<(((pcmdrv_sScope *)(PCMasterComm->p_scope))->varCnt) ; i++) {
          /* varSize is 0,3 or greater than 4 */
          if ( ((((pcmdrv_sScope *)(PCMasterComm->p_scope))->varDef[i].varSize) == 0) || \
            ((((pcmdrv_sScope *)(PCMasterComm->p_scope))->varDef[i].varSize) == 3) || \
            ((((pcmdrv_sScope *)(PCMasterComm->p_scope))->varDef[i].varSize) > 4) ) {
              /* invalid size of variable */
              respPrepare(PCMDRV_STC_INVSIZE,1);
              /* reset scope */
              (((pcmdrv_sScope *)(PCMasterComm->p_scope))->varCnt) = 0;
              return;
          }
        }
        respPrepare(PCMDRV_STC_OK,1);
    }break;
    #endif
    #ifdef PCMDRV_INCLUDE_CMD_RECORDER
    case PCMDRV_CMD_SETUPRECEX: {
        unsigned char i;               /* auxiliariy variables definition   */

        if (PCMasterComm->recSize==0) { /* recorder not implemented  */
          respPrepare(PCMDRV_STC_INVCMD,1); /* invalid command  */
          return;
        }
        /* reset the recorder */
        bitClear(ST_RECRUNNING | ST_RECACTIVATED,status);
        /* initialize recorder
        /* (copy data from dataBuff to Recorder structure) => copy structure form PCMasterComm->p_dataBuff to */
        /* PCMasterComm->p_recorder =>  copy and organize data  to recorder structure. It is necessary to do  */
        /* conversions byte variables to word by reason of arrange data to even address                       */
        /* read command             */
        ((sSetupRec *)(PCMasterComm->p_recorder))->cmd     = *((PCMasterComm->p_dataBuff)+0);
        /* read cmdLen              */
        ((sSetupRec *)(PCMasterComm->p_recorder))->cmdLen  = *((PCMasterComm->p_dataBuff)+1);
        /* read trigger mode        */
        ((sSetupRec *)(PCMasterComm->p_recorder))->trgMode = *((PCMasterComm->p_dataBuff)+2);
        if( ((sSetupRec *)(PCMasterComm->p_recorder))->trgMode > 2 ) { /* test value {0,1,2}       */
          respPrepare(PCMDRV_STC_INVBUFF,1); /* invalid trigger mode     */
          return;
        }
        /* read total samples        */
        memCopy((PCMasterComm->p_dataBuff)+3,
        (UInt8*)(&(((sSetupRec *)(PCMasterComm->p_recorder))->totalSmps)),WORD_LEN);
        /* read post tiger size      */
        memCopy((PCMasterComm->p_dataBuff)+5,
        (UInt8*)(&(((sSetupRec *)(PCMasterComm->p_recorder))->postTrigger)),WORD_LEN);
        /* read timeDiv             */
        memCopy((PCMasterComm->p_dataBuff)+7,
        (UInt8*)(&(((sSetupRec *)(PCMasterComm->p_recorder))->timeDiv)),WORD_LEN);
        /* read trig. variab. address*/
        memCopy((PCMasterComm->p_dataBuff)+9,
        (UInt8*)(&(((sSetupRec *)(PCMasterComm->p_recorder))->trgVarAddr[0])),POINT32_LEN);
        /* read trig. variab. size   */
        ((sSetupRec *)(PCMasterComm->p_recorder))->trgVarSize       = *((PCMasterComm->p_dataBuff)+13);
        if(!((((sSetupRec *)(PCMasterComm->p_recorder))->trgVarSize==1) || /* test trig. variab. size   */
          (((sSetupRec *)(PCMasterComm->p_recorder))->trgVarSize==2) ||
          (((sSetupRec *)(PCMasterComm->p_recorder))->trgVarSize==4))) {
            respPrepare(PCMDRV_STC_INVSIZE,1); /* invalid buffer size       */
            (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->varCnt) =  0;
            return;
        }
        /* read trig. compare mode    */
        ((sSetupRec *)(PCMasterComm->p_recorder))->trgVarSigned     = *((PCMasterComm->p_dataBuff)+14);
        memCopy((PCMasterComm->p_dataBuff)+15,
          (UInt8*)(&(((sSetupRec *)(PCMasterComm->p_recorder))->trgThreshold.ud)),LONG_LEN);
        /* read variable definitions  */
        ((sSetupRec *)(PCMasterComm->p_recorder))->varCnt           = *((PCMasterComm->p_dataBuff)+19);
        if ( (((sSetupRec *)(PCMasterComm->p_recorder))->varCnt == 0) || /* testing of data correctness*/
          (((sSetupRec *)(PCMasterComm->p_recorder))->varCnt > 8) ) {
            respPrepare(PCMDRV_STC_INVBUFF,1); /* if varCnt is zero or greater than 8 => invalid buffer size */
            (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->varCnt) =  0;
            return;
        }
        status = (status & 0xfff0) | ((((sSetupRec *)(PCMasterComm->p_recorder))->trgVarSize)<<1) +
          ((sSetupRec *)(PCMasterComm->p_recorder))->trgVarSigned; /* set status                 */
            for(i=0;i<((sSetupRec *)(PCMasterComm->p_recorder))->varCnt;i++) { /* data descriptions => scope */
              /* initialization             */
              /* read variable size         */
              ((sSetupRec *)(PCMasterComm->p_recorder))->varDef[i].varSize = *((PCMasterComm->p_dataBuff)+20+i*5);
              if((((sSetupRec *)(PCMasterComm->p_recorder))->varDef[i].varSize==0) ||
                (((sSetupRec *)(PCMasterComm->p_recorder))->varDef[i].varSize==3)) { /* test variable sizes        */
                  respPrepare(PCMDRV_STC_INVSIZE,1); /* invalid buffer size        */
                  (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->varCnt) =  0;
                  return;
              }
              memCopy((PCMasterComm->p_dataBuff)+21+i*5,
                (UInt8*)(&(((sSetupRec *)(PCMasterComm->p_recorder))->varDef[i].varAddr[0])),POINT32_LEN);
            }
            /*  next samples position in recorder buffer - incremented by RecSetLen */
            status = (status & 0xfff0) | ((((sSetupRec *)(PCMasterComm->p_recorder))->trgVarSize)<<1) +
              ((sSetupRec *)(PCMasterComm->p_recorder))->trgVarSigned; /* set status                 */
            ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recPos = 0;
            /*  length of requiered variables set [Word] */
            ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recSetLen =   0;
            /*  position to end of buffer */
            ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd  =   1;
            /*  recorder time div         */
            ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recTime   =
               ((sSetupRec *)(PCMasterComm->p_recorder))->timeDiv;
            /* check if recorder buffer size is valid */
            ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recSetLen = 0; /* clear result before cycle  */
            for(i=0;i<((sSetupRec *)(PCMasterComm->p_recorder))->varCnt;i++) { /* get one set of samples [B] */
              ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recSetLen +=
              ((sSetupRec *)(PCMasterComm->p_recorder))->varDef[i].varSize;
            }
            ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->totalSmps *= /* required buffer size [W]   */
              ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recSetLen;
            if(((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->totalSmps <= /* required buffer size is    */
              PCMasterComm->recSize) { /* smaller than record. buffer*/
                /* read last value of trig. variable   */
                memCopy((UInt8*)(((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgVarAddr[0]),
                  (UInt8*)(&(((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recLastVal.ud)),
                  (Int8)(((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgVarSize));
                respPrepare(PCMDRV_STC_OK,1);
                bitSet(ST_RECACTIVATED,status); /* recorder activated  */
            }
            else {
              respPrepare(PCMDRV_STC_INVSIZE,1); /* invalid buffer size */
              (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->varCnt) =  0;
              return;
            }
    }break;
    #endif
    case PCMDRV_CMD_READMEMEX: {       /* read block of memory */
        /* read size of data */
        memCopy(&(((sReadMemEx *)(PCMasterComm->p_dataBuff))->size),
          (unsigned char *)&length, BYTE_LEN);
        if (length <= ((PCMasterComm)->dataBuffSize)) {
          /* read address */

⌨️ 快捷键说明

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