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

📄 disk3.lst

📁 用于Slave I2C得读写,此代码针对特定得芯片,但对其他得芯片也有借鉴作用.
💻 LST
📖 第 1 页 / 共 5 页
字号:
C51 COMPILER V7.02b   DISK3                                                                03/16/2006 13:52:41 PAGE 1   


C51 COMPILER V7.02b, COMPILATION OF MODULE DISK3
OBJECT MODULE PLACED IN .\output\disk3.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE disk3.c LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\output\disk3.lst) OBJECT(.\
                    -output\disk3.obj)

stmt level    source

   1          /*
   2          **********************************************************************************************
   3          * Project:      T8Lib
   4          * File:         ezT8.c
   5          * Contents: 
   6          *           The ezT8 library  c file
   7          *
   8          * $Date: 10/13/05    Michal    T8R01LIB v0.1  initial
   9          * $Date: 11/29/05    Michal    T8R01LIB v0.2  test finish  both 51 and MCF5249
  10          * $Date: 11/30/05    Michal    T8R01LIB v0.3  make lib OK  on  MCF5249
  11          * $Date: 12/01/05    Michal    T8R01LIB v0.4  Add HW_IIC ,HW_SPI macro  
  12          * $Date: 12/02/05    Michal    T8R01LIB v0.5  Add  function below in this file  
  13          *                 static void DoXX(BYTE* out ,BYTE* in,BYTE len,BOOL mode)
  14          *                 static BOOL DoComunication(BYTE* array, BYTE len,BOOL mode)
  15          *
  16          *                 BOOL  GetCustomIdWriteStatusCmd(); 
  17          *                 BOOL  GetCustomIdResponseCmd(); 
  18          *                 BOOL  ChallengeCustomIdCmd(BYTE * CId,BYTE len,BYTE Nvmoffset); 
  19          *                 BOOL  IsCustomIdResponseCmd(); 
  20          *                 BOOL WriteCustomIdCmd(BYTE * CId,BYTE len,BYTE Nvmoffset)  ;   
  21          *                 BOOL IsWriteCustomIdReadyCmd();         
  22          *                 BOOL IsWriteCustomIdNotReadyCmd();  
  23          *
  24          *                Moidfy some *Cmd Fuction and Reply() function
  25          * $Date: 12/05/05    Michal    T8R02LIB v0.1  Add errcode1 in this file
  26          *                              to identify T8 off i2c bus state 
  27          * $Date: 12/29/05 Michal T8R02LIB v0.2
  28                               Modify InitezT8(BOOL mode ) to BOOL  InitezT8Lib(BOOL ComMod,BYTE I2cSlvAdr,BOOL I2cIsHigh,B
             -YTE SpiCLkMod,WORD SpiRate,BYTE *key);
  29                                  void I2c_Init( ); void I2c_Sel( BYTE  SlvAdr, BOOL isHigh)  to void I2c_Init(BYTE 
             - SlvAdr, BOOL isHigh);
  30                                  void  Spi_Init();BOOL  Spi_ClkSel(BYTE mode, WORD rate);  To void  Spi_Init(BYTE m
             -ode, WORD rate);
  31                           Delete void SpiClkSelOpr(BYTE mode, WORD rate) ;
  32                                  void I2c_Sel( BYTE  SlvAdr, BOOL isHigh);  
  33                                  void SetXXKey(BYTE* key); 
  34          * $Date: 12/29/05 Michal T8R02LIB v0.5 test communiction at 400khz speed  is OK  
  35          * Copyright (c) 2005 Fameg, Inc. All rights reserved
  36          
  37          ***********************************************************************************************
  38          */
  39           
  40          
  41          #include <string.h>         //memset ,memcpy 
  42          
  43          #define IMPORT_LIB 0
  44          #include "ezT8i.h" 
  45          #include "des.h"
  46          
  47          #include "spi.h"          
  48          #include "i2c.h"
  49            
  50          
  51          
C51 COMPILER V7.02b   DISK3                                                                03/16/2006 13:52:41 PAGE 2   

  52          
  53          
  54          
  55          /***************************************************************
  56                        //intenal command  
  57          ****************************************************************/
  58                                               //write  
  59            BOOL  SendPlainTextCmd(BYTE *text,BYTE len);
  60            BOOL  SendEncryptedDigestCmd(BYTE *text);
  61          
  62            BOOL  GetReceiveStatusCmd();
  63            BOOL  GetResponseCmd();
  64            BOOL  GetKeyWriteStatusCmd();
  65            BOOL  GetPowerDownReceiveStatusCmd();
  66            BOOL  GetResetReceiveStatusCmd();
  67            BOOL  GetChipIdCmd();
  68          
  69            BOOL  GetCustomIdWriteStatusCmd(); //add
  70            BOOL  GetCustomIdResponseCmd(); //add
  71            
  72                  
  73            BOOL GetReply(BYTE len);        //read
  74          
  75            BOOL IsReceiveReadyCmd();      //check
  76            BOOL IsReceiveNotReadyCmd();
  77            BOOL IsPowerDownReadyCmd();
  78            BOOL IsPowerDownNotReadyCmd();
  79            BOOL IsResetReadyCmd();
  80            BOOL IsResetNotReadyCmd();
  81            BOOL IsChipIdCmd(BYTE *pID);
  82          
  83            BOOL ChallengeCmd(BYTE *text);
  84            BOOL IsReponseCmd(BYTE *text);
  85          
  86           BOOL  ChallengeCustomIdCmd(BYTE * CId,BYTE len,BYTE Nvmoffset); //add
  87            BOOL  IsCustomIdResponseCmd(BYTE *text); //add
  88            
  89            BOOL WriteKeyCmd(BYTE *nId,BYTE adr,BYTE * KEY) ;
  90           BOOL WriteCustomIdCmd(BYTE * CId,BYTE len,BYTE Nvmoffset)  ;   //add
  91           
  92            BOOL IsWriteKeyReadyCmd();
  93            BOOL IsWriteKeyNotReadyCmd();
  94          
  95            BOOL IsWriteCustomIdReadyCmd();         //add
  96            BOOL IsWriteCustomIdNotReadyCmd();  //add
  97            
  98            BOOL  ResetCmd();              // 
  99            BOOL  PowerDownCmd();
 100          
 101            void ToSpiModeOpr(); 
 102            BOOL SendPlainTextOpr(BYTE *text,BYTE len);
 103          
 104            BOOL SendEncryptedDigestOpr( BYTE *text);
 105          
 106            BOOL ChallengeOpr(BYTE *from,BYTE *to );
 107          
 108          
 109           BOOL WriteCustomIdOpr(BYTE * CId,BYTE len,BYTE Nvmoffset)  ;   //add
 110           BOOL ChallengeCustomIdOpr(BYTE * CId,BYTE len,BYTE Nvmoffset);  //add
 111          
 112          extern WORD uCal(BYTE *dat, BYTE len);
 113          
C51 COMPILER V7.02b   DISK3                                                                03/16/2006 13:52:41 PAGE 3   

 114          /*************************************************
 115             Local Variables and Function
 116          *************************************************/
 117          
 118          
 119                                                  
 120           BYTE  package[8+64+2];          //package for communiction
 121          
 122          static BYTE MCU_SN,SN_diff,RN;                 //package SN ,RN couner  
 123          static BYTE SN_High;
 124          
 125          static BOOL  CommMode=0;            /*communiation mode:  =0 ,i2c (default)
 126                                                                    =1, spi*/
 127          static BYTE dist[8];             //DES encrytion and decryption KEY   
 128          
 129          
 130          static BYTE   errcode;             //error code  about operation on T8          
 131                                                 /*=00    no error
 132                                                  0x01  input param error
 133                                                  0x02  I2c comuniction error 
 134                                                  0x03  CRC error
 135                                                  0x04  cmd error(incorrect reply)                                  
             -      
 136                                                  0x05  ready error(sn error)
 137                                                  0x06  sn right,cmd error
 138                                                  */
 139           BYTE errcode1;      /*extra errcode about I2c comuniction
 140                                                 0xFF   T8OffI2cBus
 141                                                 0~64  i byte no ack
 142                                                  */
 143          /*
 144          **************************************************
 145          * prototype :  void Reverse(BYTE *array,BYTE len)  
 146          *   Des: Reverse the array.  
 147          * "dat" is array's start address,"len" is the length.
 148          ***************************************************
 149          */
 150          void Reverse(BYTE *array,BYTE len)
 151          {
 152   1         BYTE temp,j;
 153   1         for(j=0;j<len/2;j++)
 154   1         {
 155   2           temp=array[j];
 156   2               array[j]=array[len-1-j];
 157   2               array[len-1-j]=temp;
 158   2              }       
 159   1      }
 160          
 161          /*
 162          **************************************************
 163          * prototype :  DoXX(BYTE* out ,BYTE* in,BYTE len,BOOL mode)
 164          *   Des: do Des Encrypty or Descrypty operation .  
 165          * "in" is input array's start address,"len" is the length.
 166          * "out" is output array's start address.
 167          * mode=1 Encrypty " in " to "out"
 168          * mode=0 Descrypty " in " to "out"
 169          ***************************************************
 170          */
 171          static void DoXX(BYTE* out ,BYTE* in,BYTE len,BOOL mode)
 172          {
 173   1               DES_CBC_CTX blk;  //desctx
 174   1               BYTE code iv[8]={0,0,0,0,0,0,0,0}; //DES vertor
C51 COMPILER V7.02b   DISK3                                                                03/16/2006 13:52:41 PAGE 4   

 175   1               
 176   1                BYTE j;        
 177   1                if (mode)  //Encrpty
 178   1                {
 179   2                  Reverse(in,8);
 180   2                  Disk2_Init(&blk, dist, iv, 1);
 181   2                  Disk2_Update(&blk, out,in, 8);
 182   2                  Reverse(out,8);
 183   2      
 184   2                 for(j=8;j<len;j+=8)
 185   2                 {
 186   3                   Reverse(in+j,8);
 187   3                   Disk2_Restart(&blk);
 188   3                   Disk2_Update(&blk, out+j,in+j, 8);
 189   3                   Reverse(out+j,8);
 190   3                 }
 191   2        }
 192   1        else         //Dencrpty
 193   1        {
 194   2                 Reverse(in,len);
 195   2      
 196   2                 Disk2_Init(&blk, dist, iv, 0);          //get DES decryption data
 197   2                 Disk2_Update(&blk, out,in, 8);   
 198   2                 for(j=8;j<len;j+=8)
 199   2                 {
 200   3                   Disk2_Restart(&blk);
 201   3                   Disk2_Update(&blk, out+j,in+j, 8);
 202   3                 }
 203   2                 Reverse(out,len);
 204   2              }
 205   1      }
 206          
 207          /*
 208          **************************************************
 209          * prototype :  BOOL DoComunication(BYTE* array, BYTE len,BOOL mode)
 210          *   Des: do Des Comunication operation .  
 211          * "array" is  buffer to send or receive ,"len" is the length.
 212          * mode=1 send ''len''
 213          * mode=0 receive ''len'
 214          ***************************************************
 215          */
 216          #define NoAck 0x02
 217          
 218          static BOOL DoComunication(BYTE* array, BYTE len,BOOL mode)
 219          {
 220   1        errcode=0;
 221   1        errcode1=0;
 222   1        //vDisableIsrs();//add
 223   1       if (mode)    //send
 224   1        {
 225   2                 if(CommMode)
 226   2                      Spi_WriteData(array, len);
 227   2                 else
 228   2                 {
 229   3                     errcode1=I2c_SendStr(BusSlvAdr, array, len);
 230   3                      if(errcode1!=0)
 231   3                      {
 232   4                         errcode=NoAck;
 233   4                         //vEnableIsrs();//add
 234   4                        return false;
 235   4                      }
 236   3            }
C51 COMPILER V7.02b   DISK3                                                                03/16/2006 13:52:41 PAGE 5   

 237   2        }
 238   1        else           //receive
 239   1        {
 240   2                 if(CommMode)                  //read data
 241   2                      Spi_ReadData(package, len);
 242   2                 else
 243   2                 {
 244   3                     errcode1=I2c_RcvStr(BusSlvAdr, package, len);
 245   3                      if(errcode1!=0)
 246   3                      {
 247   4                         errcode=NoAck;
 248   4                      // vEnableIsrs();//add   
 249   4                         return false;
 250   4                      }
 251   3                 }
 252   2        }    
 253   1        //vEnableIsrs();//add
 254   1        return true;
 255   1      }
 256                  
 257          /*
 258          **************************************************
 259          * prototype :  static BOOL ChkRn(BYTE *dat,BYTE len) 
 260          *   Des: check CRC value of receive package. if the 
 261          *    Rceived CRC value is equal to CRC value calculated 
 262          *    by firmare  ,it returns true,otherwise it returns false. 
 263          *   "dat" is package's start address,"len" is the length. 
 264          ***************************************************
 265          */
 266          static BOOL ChkRn(BYTE *dat,BYTE len)              //len=8
 267          {
 268   1         WORD  chksum,chksum1;
 269   1         chksum=uCal(dat,len-2);
 270   1           
 271   1         chksum1=uCal(dat,len);         //==800d?
 272   1         if(chksum!= dat[len-1]*256+dat[len-2])

⌨️ 快捷键说明

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