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

📄 pc_m1.c

📁 SPI主机模式进行串行通信
💻 C
📖 第 1 页 / 共 5 页
字号:
**         NAME            - DESCRIPTION
**       * p_sPCMasterComm - Pointer to
**                           structure with SCI communication
**                           settings.
**     Returns     :
**         ---             - The function returns the PASS (0).
** ===================================================================
*/
Word16 PC_M1_pcmasterdrvInit(sPCMasterComm *p_sPCMasterComm)
{
  /* store sPCMasterComm structure address */
  PCMasterComm=(sPCMasterComm *)p_sPCMasterComm;

  inChar = 1;
  status = 0; /* reset receiver */

  #ifdef PCMDRV_INCLUDE_CMD_SCOPE
    /* reset scope */
    ((pcmdrv_sScope *)(PCMasterComm->p_scope))->varCnt=0;
  #endif

  #ifdef PCMDRV_INCLUDE_CMD_RECORDER
    /* reset recorder */
    ((pcmdrv_sScope *)(PCMasterComm->p_recorder))->varCnt=0;
  #endif

  #ifdef PCMDRV_INCLUDE_CMD_APPCMD
    /* initialize application command status */
    pcmdrvAppCmdSts = PCMDRV_APPCMD_NOCMD;
  #endif

  return(0);
}

/*
** ===================================================================
**     Method      :  PC_M1_pcmasterdrvGetAppCmdSts (bean PC_Master)
**
**     Description :
**         Get Application Command Status. This function is used to
**         check if an application command has been received from PC.
**     Parameters  : None
**     Returns     :
**         ---             - Return value:
**                           1 - new application command received
**                           0 - no new application command.
** ===================================================================
*/
UWord16 PC_M1_pcmasterdrvGetAppCmdSts(void)
{
  if (pcmdrvAppCmdSts == PCMDRV_APPCMD_RUNNING)
    return(1);                         /* new application command received */
  else
    return(0);                         /* no new application command */
}

/*
** ===================================================================
**     Method      :  PC_M1_pcmasterdrvWriteAppCmdSts (bean PC_Master)
**
**     Description :
**         Write Application Command Status. This function clears
**         the flags in application command status word.
**     Parameters  :
**         NAME            - DESCRIPTION
**         state           - Application command status word.
**     Returns     :
**         ---             - The function returns the PASS (0).
** ===================================================================
*/
Word16 PC_M1_pcmasterdrvWriteAppCmdSts(UWord16 state)
{
  pcmdrvAppCmdSts = (UInt8)state;
  return(0);                           /* OK */
}

/*
** ===================================================================
**     Method      :  PC_M1_pcmasterdrvIsr (bean PC_Master)
**
**     Description :
**         Main PC Master Communication routine which provide
**         receiving, decoding of incoming message and sending
**         response to PC.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
void PC_M1_pcmasterdrvIsr(void)
{
  if (status & ST_SENDING) {           /* message is transmitting */
    sendBuffer();                      /* send data */
    return;                            /* response is sending to PC */
  }
  SCIread(inChar);                     /* read received character */
  if ((status & ST_ST_CHAR_REC) == 0) { /* last byte was not '+' */
    if (inChar == '+') {               /* '+' received */
      bitSet(ST_ST_CHAR_REC,status);
    }
    else {                             /* any byte received */
      messageData(0);                  /* byte received */
    }
  }
  else {                               /* the last byte was '+' */
    if (inChar == '+') {               /* doubled '+' (this is the second one) */
      messageData(0);                  /* byte received */
    }
    else {                             /* start of message */
      messageData(1);                  /* byte received */
    }
    bitClear(ST_ST_CHAR_REC,status);   /* clear flag */
  }
}

/*
** ===================================================================
**     Method      :  PC_M1_pcmasterdrvRecorder (bean PC_Master)
**
**     Description :
**         Recorder Routine. It performs sampling of data into
**         buffer which is located on the address p_recBuff item is
**         pointing and its length is determined by recSize item in
**         the initialization structure of sPCMasterComm type.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
void PC_M1_pcmasterdrvRecorder(void)
{
  volatile union{
           UInt8      uch;
           Int8        ch;
           UWord16     uw;
           Word16      sw;
           UWord32     ud;
           Word32      sd;
  } actual;

  if (status & ST_RECACTIVATED) {      /* recorder activated */
    if (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recTime ==
      ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->timeDiv) { /* now is the right time to make samples  */
        if (!(ST_REC_READ_PRETRIG & status)) {
          if (recPretrigCount >= (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->totalSmps -
            (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recSetLen *
            ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->postTrigger)))
              bitSet(ST_REC_READ_PRETRIG, status);
            else recPretrigCount += ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recSetLen;
        }
        /* read actual trigger value  */
        memCopy((UInt8*)(((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgVarAddr[0]),
          (UInt8*)(&actual.uch),(Int8)(((sSetupRec *)(PCMasterComm->p_recorder))->trgVarSize));
        /* read new samples  */
        ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recPos=
          readRecSample(((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recPos );
        /* wrap around */
        if (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recPos >=
          ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->totalSmps)
            ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recPos=0;
        switch (status & 0x000f) {
          case REC_CHAR_UNSIGNED: {    /* size=1, unsigned char   */
              if( (!(status & ST_RECRUNNING)) && (status & ST_REC_READ_PRETRIG) ) {
                if ((((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgMode == PCMDRV_REC_TRIGRIS) &&
                  (actual.uch >= ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgThreshold.uch) &&
                  (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recLastVal.uch <
                  ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgThreshold.uch)) {
                    /* recorder is configured to rising edge actual value       */
                    /* greater than threshold last value smaller than threshold */
                    bitSet(ST_RECRUNNING,status);
                    ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd =
                      ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->postTrigger-1;
                }
                else
                  if ((((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgMode == PCMDRV_REC_TRIGFAL) &&
                    (actual.uch <= ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgThreshold.uch) &&
                    (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recLastVal.uch >
                    ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgThreshold.uch)) {
                      /* recorder is configured to falling edge actual value      */
                      /* smaller than Threshold last value greater than Threshold */
                      bitSet(ST_RECRUNNING,status);
                      ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd =
                        ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->postTrigger-1;
                  }
              }
              else
                if(status & ST_REC_READ_PRETRIG)((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd--;
              /* buffer is full */
              if (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd==0) {
                bitClear(ST_RECRUNNING | ST_RECACTIVATED | ST_REC_READ_PRETRIG,status);
                ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd=1;
              }
              /* remember last value  */
              ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recLastVal.uch = actual.uch;
              /* reset recorder time  */
              ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recTime = 0;
          }break;
          case REC_CHAR_SIGNED: {      /* size=1,  signed  char   */
              if( (!(status & ST_RECRUNNING)) && (status & ST_REC_READ_PRETRIG) ) {
                if ((((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgMode == PCMDRV_REC_TRIGRIS) &&
                  (actual.ch >= ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgThreshold.ch) &&
                  (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recLastVal.ch <
                  ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgThreshold.ch)) {
                    /* recorder is configured to rising edge actual value       */
                    /* greater than threshold last value smaller than threshold */
                    bitSet(ST_RECRUNNING,status);
                    ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd =
                    ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->postTrigger-1;
                }
                else
                  if ((((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgMode == PCMDRV_REC_TRIGFAL) &&
                    (actual.ch <= ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgThreshold.ch) &&
                    (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recLastVal.ch >
                    ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgThreshold.ch)) {
                      /* recorder is configured to falling edge actual value      */
                      /* smaller than Threshold last value greater than Threshold */
                      bitSet(ST_RECRUNNING,status);
                      ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd =
                      ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->postTrigger-1;
                  }
              }
              else
                if(status & ST_REC_READ_PRETRIG)((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd--;
              /* buffer is full */
              if (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd==0) {
                bitClear(ST_RECRUNNING | ST_RECACTIVATED | ST_REC_READ_PRETRIG,status);
                ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd=1;
              }
              /* remember last value  */
              ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recLastVal.ch = actual.ch;
              /* reset recorder time  */
              ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recTime = 0;
          }break;
          case REC_WORD_UNSIGNED: {    /* size=2, unsigned word  */
              if( (!(status & ST_RECRUNNING)) && (status & ST_REC_READ_PRETRIG) ) {
                if ((((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgMode == PCMDRV_REC_TRIGRIS) &&
                  (actual.uw >= ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgThreshold.uw) &&
                  (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recLastVal.uw <
                  ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgThreshold.uw)) {
                    /* recorder is configured to rising edge actual value       */
                    /* greater than threshold last value smaller than threshold */
                    bitSet(ST_RECRUNNING,status);
                    ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd =
                      ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->postTrigger-1;
                }
                else
                  if ((((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgMode == PCMDRV_REC_TRIGFAL) &&
                    (actual.uw <= ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgThreshold.uw) &&
                    (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recLastVal.uw >
                    ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgThreshold.uw)) {
                      /* recorder is configured to falling edge actual value      */
                      /* smaller than Threshold last value greater than Threshold */
                      bitSet(ST_RECRUNNING,status);
                      ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd =
                      ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->postTrigger-1;
                  }
              }
              else
                if(status & ST_REC_READ_PRETRIG)((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd--;
              /* buffer is full */
              if (((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd==0) {
                bitClear(ST_RECRUNNING | ST_RECACTIVATED | ST_REC_READ_PRETRIG,status);
                ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recToEnd=1;
              }
              /* remember last value  */
              ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recLastVal.uw = actual.uw;
              /* reset recorder time   */
              ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->recTime = 0;
          }break;
          case REC_WORD_SIGNED: {      /* size=2, signed word */
              if( (!(status & ST_RECRUNNING)) && (status & ST_REC_READ_PRETRIG) ) {
                if ((((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgMode == PCMDRV_REC_TRIGRIS) &&
                  (actual.sw >= ((pcmdrv_sRecorder *)(PCMasterComm->p_recorder))->trgThreshold.sw) &&

⌨️ 快捷键说明

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