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

📄 m500auc.c

📁 飞利浦公司提供的mfrc设计资料
💻 C
📖 第 1 页 / 共 5 页
字号:
     {

        M500PcdSetTmo(3);     // long timeout

        ResetInfo(MInfo);
        memcpy(MSndBuffer,_data,16);
        MInfo.nBytesToSend   = 16;
        status = M500PcdCmd(PCD_TRANSCEIVE,
                            MSndBuffer,
                            MRcvBuffer,
                            &MInfo);

        if (status & 0x80)    // timeout occured
        {
           status = MI_NOTAGERR;
        }
        else
        {

           if (MInfo.nBitsReceived != 4)  // 4 bits are necessary
           {
              status = MI_BITCOUNTERR;
           }
           else                     // 4 bit received
           {
              MRcvBuffer[0] &= 0x0f; // mask out upper nibble
              if ((MRcvBuffer[0] & 0x0a) == 0)
              {
                 status = MI_WRITEERR;
              }
              else
              {
                 if (MRcvBuffer[0] == 0x0a)
                 {
                    status = MI_OK;
                 }
                 else
                 {
                    status = MI_CODEERR;
                 }
              }
           }
        }
        M500PcdSetTmo(1);    // short timeout
     }
  return status;
}

///////////////////////////////////////////////////////////////////////
//                V A L U E   M A N I P U L A T I O N
///////////////////////////////////////////////////////////////////////
char M500PiccValue(unsigned char dd_mode,
                    unsigned char addr,
                    unsigned char *value,
                    unsigned char trans_addr)
{
   char status = MI_OK;

   M500PcdSetTmo(1);    // short timeout
   // ************* Cmd Sequence **********************************
   ResetInfo(MInfo);
   MSndBuffer[0] = dd_mode;        // Inc,Dec command code
   MSndBuffer[1] = addr;
   MInfo.nBytesToSend   = 2;
   status = M500PcdCmd(PCD_TRANSCEIVE,
                       MSndBuffer,
                       MRcvBuffer,
                       &MInfo);

   if (status != MI_NOTAGERR)   // no timeout error
   {
        if (MInfo.nBitsReceived != 4)   // 4 bits are necessary
        {
           status = MI_BITCOUNTERR;
        }
        else                     // 4 bit received
        {
           MRcvBuffer[0] &= 0x0f; // mask out upper nibble
           switch(MRcvBuffer[0])
           {
              case 0x00:
                 status = MI_NOTAUTHERR;
                 break;
              case 0x0a:
                 status = MI_OK;
                 break;
              case 0x01:
                 status = MI_VALERR;
                 break;
              default:
                 status = MI_CODEERR;
                 break;
           }
        }
     }

     if ( status == MI_OK)
     {
        M500PcdSetTmo(3);     // long timeout

        ResetInfo(MInfo);
        memcpy(MSndBuffer,value,4);
        MInfo.nBytesToSend   = 4;
        status = M500PcdCmd(PCD_TRANSCEIVE,
                            MSndBuffer,
                            MRcvBuffer,
                            &MInfo);

        if (status == MI_OK)    // no timeout occured
        {
            if (MInfo.nBitsReceived != 4)   // 4 bits are necessary
            {
               status = MI_BITCOUNTERR;
            }
            else                     // 4 bit received
            {
               MRcvBuffer[0] &= 0x0f; // mask out upper nibble
               switch(MRcvBuffer[0])
               {
                  case 0x00:
                     status = MI_NOTAUTHERR;
                     break;
                  case 0x01:
                     status = MI_VALERR;
                     break;
                  default:
                     status = MI_CODEERR;
                     break;
               }
            }
         }
         else
         if (status == MI_NOTAGERR )
            status = MI_OK;  // no response after 4 byte value -
                             // transfer command has to follow
     }
     if ( status == MI_OK)
     {
        ResetInfo(MInfo);
        MSndBuffer[0] = PICC_TRANSFER;        // transfer command code
        MSndBuffer[1] = trans_addr;
        MInfo.nBytesToSend   = 2;
        status = M500PcdCmd(PCD_TRANSCEIVE,
                            MSndBuffer,
                            MRcvBuffer,
                            &MInfo);

        if (status != MI_NOTAGERR)    // timeout occured
        {
            if (MInfo.nBitsReceived != 4)   // 4 bits are necessary
            {
               status = MI_BITCOUNTERR;
            }
            else                     // 4 bit received
            {
               MRcvBuffer[0] &= 0x0f; // mask out upper nibble
               switch(MRcvBuffer[0])
               {
                  case 0x00:
                     status = MI_NOTAUTHERR;
                     break;
                  case 0x0a:
                     status = MI_OK;
                     break;
                  case 0x01:
                     status = MI_VALERR;
                     break;
                  default:
                     status = MI_CODEERR;
                     break;
               }
            }
        }
     }
   return status;
}

///////////////////////////////////////////////////////////////////////
//   V A L U E   M A N I P U L A T I O N   W I T H   B A C K U P
///////////////////////////////////////////////////////////////////////
char M500PiccValueDebit(unsigned char dd_mode,
                         unsigned char addr,
                         unsigned char *value)
{
   char status = MI_OK;

   M500PcdSetTmo(1);    // short timeout
   ResetInfo(MInfo);
   MSndBuffer[0] = dd_mode;        // Inc,Dec command code
   MSndBuffer[1] = addr;
   MInfo.nBytesToSend   = 2;
   status = M500PcdCmd(PCD_TRANSCEIVE,
                       MSndBuffer,
                       MRcvBuffer,
                       &MInfo);

   if (status != MI_NOTAGERR)   // no timeout error
   {
        if (MInfo.nBitsReceived != 4)   // 4 bits are necessary
        {
           status = MI_BITCOUNTERR;
        }
        else                     // 4 bit received
        {
           MRcvBuffer[0] &= 0x0f; // mask out upper nibble
           switch(MRcvBuffer[0])
           {
              case 0x00:
                 status = MI_NOTAUTHERR;
                 break;
              case 0x0a:
                 status = MI_OK;
                 break;
              case 0x01:
                 status = MI_VALERR;
                 break;
              default:
                 status = MI_CODEERR;
                 break;
           }
        }
     }

     if ( status == MI_OK)
     {
        M500PcdSetTmo(3);     // long timeout

        ResetInfo(MInfo);
        memcpy(MSndBuffer,value,4);
        MInfo.nBytesToSend   = 4;
        status = M500PcdCmd(PCD_TRANSCEIVE,
                            MSndBuffer,
                            MRcvBuffer,
                            &MInfo);

        if (status == MI_OK)    // no timeout occured
        {
            if (MInfo.nBitsReceived != 4)   // 4 bits are necessary
            {
               status = MI_BITCOUNTERR;
            }
            else                     // 4 bit received
            {
               MRcvBuffer[0] &= 0x0f; // mask out upper nibble
               switch(MRcvBuffer[0])
               {
                  case 0x00:
                     status = MI_NOTAUTHERR;
                     break;
                  case 0x0a:
                     status = MI_OK;
                     break;
                  case 0x05:
                  case 0x01:
                     status = MI_VALERR;
                     break;
                  default:
                     status = MI_CODEERR;
                     break;
               }
            }
        }
     }

   return status;
}

//////////////////////////////////////////////////////////////////////
//           P I C C   E X C H A N G E   B L O C K
///////////////////////////////////////////////////////////////////////
char M500PiccExchangeBlock(unsigned char *send_data,
                           unsigned char send_bytelen,
                           unsigned char *rec_data,
                           unsigned char *rec_bytelen,
                           unsigned char append_crc,
                           unsigned char timeout )
{
   char   status = MI_OK;

   if (append_crc)
   {
      // RxCRC and TxCRC enable, parity enable
      WriteIO(RegChannelRedundancy,0x0F);
      send_bytelen -= 2;
   }
   else
   {
      // RxCRC and TxCRC disable, parity enable
      WriteIO(RegChannelRedundancy,0x03);
   }
   M500PcdSetTmo(timeout);

   status = ExchangeByteStream(PCD_TRANSCEIVE,
                               send_data,
                               send_bytelen,
                               rec_data,
                               rec_bytelen);

   if ( status == MI_OK )
   {
      if (append_crc)
      {
         *rec_bytelen += 2; // for two CRC bytes
         rec_data[*rec_bytelen - 2] = 0x00;
         rec_data[*rec_bytelen - 1] = 0x00;
      }
   }
   else
   {
      *rec_bytelen = 0;
   }
   return status;
}

//////////////////////////////////////////////////////////////////////
//           E X C H A N G E   B Y T E   S T R E A M
///////////////////////////////////////////////////////////////////////
char ExchangeByteStream(unsigned char Cmd,
                        unsigned char *send_data,
                        unsigned char send_bytelen,
                        unsigned char *rec_data,
                        unsigned char *rec_bytelen)
{
   signed char status = MI_OK;
   signed char state;

   FlushFIFO();    // empty FIFO
   ResetInfo(MInfo); // initialise ISR Info structure

   if (send_bytelen > 0)
   {
      memcpy(MSndBuffer,send_data,send_bytelen); // write n bytes
      MInfo.nBytesToSend = send_bytelen;
      // write load command
      state = status = M500PcdCmd(Cmd,
                      MSndBuffer,
                      MRcvBuffer,
                      &MInfo);
      if ( status == MI_OK )
      {
         *rec_bytelen = MInfo.nBytesReceived;
         if (*rec_bytelen)
         {
            memcpy(rec_data,MRcvBuffer,MInfo.nBytesReceived);
         }
      }
   }
   else
   {
      status = MI_WRONG_PARAMETER_VALUE;
   }
   return status;
}

///////////////////////////////////////////////////////////////////////
//          M I F A R E     H A L T
///////////////////////////////////////////////////////////////////////
char M500PiccHalt(void)
{
   char idata status = MI_CODEERR;

   // ************* Cmd Sequence *****************************

⌨️ 快捷键说明

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