hirokuma hirokuma / RCS730
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RCS730.h Source File

RCS730.h

Go to the documentation of this file.
00001 /** FeliCa Link(RC-S730) Library
00002  *
00003  * @file    RCS730.h
00004  * @author  hiro99ma
00005  * @version 1.00
00006  */
00007 
00008 #ifndef RCS730_H
00009 #define RCS730_H
00010 
00011 #include "mbed.h"
00012 
00013 /** callback function type */
00014 typedef bool (*RCS730_CALLBACK_T)(void *pUser, uint8_t *pData, uint8_t Len);
00015 
00016 
00017 /** FeliCa Link(RC-S730) class
00018  *
00019  * @class RCS730
00020  */
00021 class RCS730 {
00022 public:
00023     static const uint16_t BLK_PAD0 = 0x0000;        //!< [addr]PAD0
00024     static const uint16_t BLK_PAD1 = 0x0001;        //!< [addr]PAD1
00025     static const uint16_t BLK_PAD2 = 0x0002;        //!< [addr]PAD2
00026     static const uint16_t BLK_PAD3 = 0x0003;        //!< [addr]PAD3
00027     static const uint16_t BLK_PAD4 = 0x0004;        //!< [addr]PAD4
00028     static const uint16_t BLK_PAD5 = 0x0005;        //!< [addr]PAD5
00029     static const uint16_t BLK_PAD6 = 0x0006;        //!< [addr]PAD6
00030     static const uint16_t BLK_PAD7 = 0x0007;        //!< [addr]PAD7
00031     static const uint16_t BLK_PAD8 = 0x0008;        //!< [addr]PAD8
00032     static const uint16_t BLK_PAD9 = 0x0009;        //!< [addr]PAD9
00033     static const uint16_t BLK_PAD10 = 0x000a;       //!< [addr]PAD10
00034     static const uint16_t BLK_PAD11 = 0x000b;       //!< [addr]PAD11
00035     static const uint16_t BLK_PAD12 = 0x000c;       //!< [addr]PAD12
00036     static const uint16_t BLK_PAD13 = 0x000d;       //!< [addr]PAD13
00037     static const uint16_t BLK_REG = 0x000e;         //!< [addr]REG
00038     static const uint16_t BLK_RC = 0x0080;          //!< [addr]RC
00039     static const uint16_t BLK_MAC = 0x0081;         //!< [addr]MAC
00040     static const uint16_t BLK_ID = 0x0082;          //!< [addr]ID
00041     static const uint16_t BLK_D_ID = 0x0083;        //!< [addr]D_ID
00042     static const uint16_t BLK_SER_C = 0x0084;       //!< [addr]SER_C
00043     static const uint16_t BLK_SYS_C = 0x0085;       //!< [addr]SYS_C
00044     static const uint16_t BLK_CKV = 0x0086;         //!< [addr]CKV
00045     static const uint16_t BLK_CK = 0x0087;          //!< [addr]CK
00046     static const uint16_t BLK_MC = 0x0088;          //!< [addr]MC
00047     static const uint16_t BLK_WCNT = 0x0090;        //!< [addr]WCNT
00048     static const uint16_t BLK_MAC_A = 0x0091;       //!< [addr]MAC_A
00049     static const uint16_t BLK_STATE = 0x0092;       //!< [addr]STATE
00050     static const uint16_t BLK_CRC_CHECK = 0x00a0;   //!< [addr]CRC_CHECK
00051 
00052     static const uint16_t REG_OPMODE = 0x0b00;              //!< [addr]Operation Mode register
00053     static const uint16_t REG_TAG_TX_CTRL = 0x0b04;         //!< [addr]Tag TX Control register
00054     static const uint16_t REG_TAG_RX_CTRL = 0x0b08;         //!< [addr]Tag RX Control register
00055     static const uint16_t REG_RF_STATUS = 0x0b0c;           //!< [addr]RF Status register
00056     static const uint16_t REG_I2C_SLAVE_ADDR = 0x0b10;      //!< [addr]I2C Slave Address register
00057     static const uint16_t REG_I2C_BUFF_CTRL = 0x0b14;       //!< [addr]I2C Buffer Control register
00058     static const uint16_t REG_I2C_STATUS = 0x0b18;          //!< [addr]I2C Status register
00059     static const uint16_t REG_INT_MASK = 0x0b20;            //!< [addr]Interrupt Mask register
00060     static const uint16_t REG_INT_RAW_STATUS = 0x0b24;      //!< [addr]Interrupt Raw Status register
00061     static const uint16_t REG_INT_STATUS = 0x0b28;          //!< [addr]Interrupt Status register
00062     static const uint16_t REG_INT_CLEAR = 0x0b2c;           //!< [addr]Interrupt Clear register
00063     static const uint16_t REG_WRT_PROTECT = 0x0b30;         //!< [addr]Write Protect register
00064     static const uint16_t REG_STBY_CTRL = 0x0b34;           //!< [addr]Standby Control register
00065     static const uint16_t REG_INIT_CTRL = 0x0b38;           //!< [addr]Initialize Control register
00066     static const uint16_t REG_HOST_IF_SECURITY = 0x0b40;    //!< [addr]Host Interface Security register
00067     static const uint16_t REG_HOST_IF_WCNT = 0x0b44;        //!< [addr]Host Interface WCNT register
00068     static const uint16_t REG_RF_PARAM = 0x0b50;            //!< [addr]RF Parameter register
00069     static const uint16_t REG_LITES_HT_CONF = 0x0b60;       //!< [addr]Lite-S Host Through Configration register
00070     static const uint16_t REG_LITES_PMM = 0x0b64;           //!< [addr]Lite-S PMm register
00071     static const uint16_t REG_PLUG_CONF1 = 0x0b80;          //!< [addr]Plug Configration 1 register
00072     static const uint16_t REG_PLUG_CONF2 = 0x0b84;          //!< [addr]Plug Configration 2 register
00073     static const uint16_t REG_PLUG_CONF3 = 0x0b88;          //!< [addr]Plug Configration 3 register
00074     static const uint16_t REG_DEP_CONF = 0x0ba0;            //!< [addr]DEP Configration register
00075     static const uint16_t REG_DEP_PMM1 = 0x0ba4;            //!< [addr]DEP PMm1 register
00076     static const uint16_t REG_DEP_PMM2 = 0x0ba8;            //!< [addr]DEP PMm2 register
00077     static const uint16_t REG_RW_CONF = 0x0bc0;             //!< [addr]RW Configration register
00078     static const uint16_t REG_RW_CTRL = 0x0b4c;             //!< [addr]RW Control register
00079     static const uint16_t REG_RW_TIMEOUT = 0x0bc8;          //!< [addr]RW Timeout register
00080 
00081     static const uint16_t BUF_RF_COMM = 0x0c00;                         //!< [addr]RF Communication
00082     static const uint16_t BUF_I2CFELICA_COMM = 0x0d00;                  //!< [addr]I2C FeliCa Communication
00083 
00084     static const uint32_t MSK_MODE_CHANGED = 0x80000000;                //!< OPMODE changed
00085     static const uint32_t MSK_INT_RW_RX_ERROR = 0x00080000;             //!< [R/W]
00086     static const uint32_t MSK_INT_RW_RX_TIMEOUT = 0x00040000;           //!< [R/W]
00087     static const uint32_t MSK_INT_RW_RX_DONE = 0x00020000;              //!< [R/W]
00088     static const uint32_t MSK_INT_RW_TX_DONE = 0x00010000;              //!< [R/W]
00089     static const uint32_t MSK_INT_I2C_FELICA_CMD_ERROR = 0x00000200;    //!< [I2C]
00090     static const uint32_t MSK_INT_I2C_FELICA_CMD_DONE = 0x00000100;     //!< [I2C]
00091     static const uint32_t MSK_INT_TAG_TX_DONE = 0x00000040;             //!< [tag/DEP]Tx done
00092     static const uint32_t MSK_INT_TAG_NFC_DEP_RX_DONE = 0x00000020;     //!< [DEP]D4 command Rx done
00093     static const uint32_t MSK_INT_TAG_RW_RX_DONE3 = 0x00000010;         //!< [tag]Write w/o Enc Rx done for HT block
00094     static const uint32_t MSK_INT_TAG_RW_RX_DONE2 = 0x00000008;         //!< [tag]Read or Write w/o Enc Rx done for HT block
00095     static const uint32_t MSK_INT_TAG_RW_RX_DONE1 = 0x00000004;         //!< [tag]Write w/o Enc Rx done for User block
00096     static const uint32_t MSK_INT_TAG_PL_RX_DONE = 0x00000002;          //!< [tag]Polling Rx done
00097     static const uint32_t MSK_INT_TAG_RX_DONE = 0x00000001;             //!< [tag]Read or Write w/o Enc Rx done
00098     static const uint32_t MSK_ALL = 0x800f037f;
00099 
00100 public:
00101 
00102     /** Operation Mode
00103      *
00104      * @enum    OpMode
00105      */
00106     enum OpMode {
00107         OPMODE_LITES_HT = 0x00,        //!< Lite-S HT mode
00108         OPMODE_PLUG = 0x01,            //!< Plug mode
00109         OPMODE_NFCDEP = 0x02,          //!< NFC-DEP mode
00110         OPMODE_LITES = 0x03            //!< Lite-S mode
00111     };
00112 
00113 
00114     /** System Code in Plug mode
00115      *
00116      * @enum    PlugSysCode
00117      */
00118     enum PlugSysCode {
00119         PLUG_SYS_CODE_FEEL = 0,     //!< 0xFEE1
00120         PLUG_SYS_CODE_NDEF = 2,     //!< 0x12FC
00121     };
00122 
00123 
00124     /** Callback Table
00125      *
00126      * @struct  callbacktable_t
00127      */
00128     struct callbacktable_t {
00129         void                    *pUserData;         //!< User Data pointer
00130         RCS730_CALLBACK_T       pCbRxHTRDone;       //!< Rx Done(Read w/o Enc[HT mode])
00131         RCS730_CALLBACK_T       pCbRxHTWDone;       //!< Rx Done(Write w/o Enc[HT mode])
00132 #if 0
00133         RCS730_CALLBACK_T       pCbTxDone;          //!< Tx Done
00134         RCS730_CALLBACK_T       pCbRxDepDone;       //!< Rx Done(DEP mode)
00135         RCS730_CALLBACK_T       pCbOther;           //!< Other IRQ interrupt
00136 #endif
00137     };
00138 
00139 public:
00140     /** constructor
00141      *
00142      * @param   [in,out]    I2c     I2C
00143      */
00144     RCS730(I2C &I2c);
00145     
00146     /** destructor
00147      */
00148     virtual ~RCS730();
00149 
00150     /** Set Callback Table
00151      *
00152      * @param   [in]        pInitTable      callback table
00153      */
00154     void setCallbackTable(const callbacktable_t *pInitTable);
00155 
00156 
00157 public:
00158     /** Byte Write(1byte)
00159      *
00160      * @param   [in]    MemAddr     memory address to write
00161      * @param   [in]    pData       data to write
00162      * @retval  0       success
00163      */
00164     int byteWrite(uint16_t MemAddr, uint8_t Data);
00165 
00166 
00167     /** Page Write
00168      *
00169      * @param   [in]    MemAddr     memory address to write
00170      * @param   [in]    pData       data to write
00171      * @param   [in]    Length      pData Length
00172      * @retval  0       success
00173      */
00174     int pageWrite(uint16_t MemAddr, const uint8_t *pData, int Length);
00175 
00176 
00177     /** Random Read(1byte)
00178      *
00179      * @param   [in]    MemAddr     memory address to read
00180      * @param   [out]   pData       data buffer to read
00181      * @retval  0       success
00182      */
00183     int randomRead(uint16_t MemAddr, uint8_t *pData);
00184 
00185 
00186     /** Sequential Read
00187      *
00188      * @param   [in]    MemAddr     memory address to read
00189      * @param   [out]   pData       data buffer to read
00190      * @param   [in]    Length      pData Length
00191      * @retval  0       success
00192      */
00193     int sequentialRead(uint16_t MemAddr, uint8_t *pData, int Length);
00194 
00195 
00196     /** Current Address Read(1byte)
00197      *
00198      * @param   [out]   pData       data buffer to read
00199      * @retval  0       success
00200      */
00201     int currentAddrRead(uint8_t *pData);
00202 
00203 
00204     /** Read Register
00205      *
00206      * @param   [in]    Reg         FeliCa Link Register
00207      * @param   [out]   pData       data buffer to read
00208      * @retval  0       success
00209      */
00210     inline int readRegister(uint16_t Reg, uint32_t *pData);
00211 
00212 
00213     /** Write Register Force
00214      *
00215      * @param   [in]    Reg         FeliCa Link Register
00216      * @param   [in]    Data        data buffer to write
00217      * @retval  0       success
00218      */
00219     inline int writeRegisterForce(uint16_t Reg, uint32_t Data);
00220 
00221 
00222     /** Write Register
00223      *
00224      * Write Register if not same value.
00225      *
00226      * @param   [in]    Reg         FeliCa Link Register
00227      * @param   [in]    Data        data buffer to write
00228      * @param   [in]    Mask        write mask(default: 0xffffffff)
00229      * @retval  0       success
00230      *
00231      * @note
00232      *      - this API like below:
00233      *          @code
00234      *              uint32_t val_old = REG[Reg];
00235      *              uint32_t val_new = (val_old & ~Mask) | Data;
00236      *              if (val_old != val_new) {
00237      *                  REG[Reg] = val_new;
00238      *              }
00239      *          @endcode
00240      */
00241     int writeRegister(uint16_t Reg, uint32_t Data, uint32_t Mask=0xffffffff);
00242 
00243 
00244     /** Set operation mode
00245      *
00246      * @param   [in]    Mode        Operation Mode
00247      * @retval  0       success
00248      *
00249      * @note
00250      *      - This value is written to non-volatile memory in FeliCa Link.
00251      */
00252     int setRegOpMode(OpMode Mode);
00253 
00254 
00255     /** Set I2C Slave Address
00256      *
00257      * @param   [in]    SAddr       Slave Address(7bit address)
00258      * @retval  0       success
00259      *
00260      * @attention
00261      *      - SAddr is "7bit" address(not 8bit address).
00262      *
00263      * @note
00264      *      - This value is written to non-volatile memory in FeliCa Link.
00265      *      - Default slave address is 0x40.
00266      */
00267     int setRegSlaveAddr(int SAddr);
00268 
00269 
00270     /** Set interrupt mask
00271      *
00272      * @param   [in]    Mask        Bit Mask
00273      * @param   [in]    Value       Set value to Mask
00274      * @retval  0       success
00275      *
00276      * @note
00277      *      - This value is written to non-volatile memory in FeliCa Link.
00278      */
00279     int setRegInterruptMask(uint32_t Mask, uint32_t Value);
00280 
00281 
00282     /** Set System Code in Plug mode
00283      *
00284      * @param   [in]    SysCode     System Code
00285      * @retval  0       success
00286      *
00287      * @note
00288      *      - This value is written to non-volatile memory in FeliCa Link.
00289      */
00290     int setRegPlugSysCode(PlugSysCode SysCode);
00291 
00292 
00293     /** go to initialize status
00294      *
00295      * @retval  0       success
00296      */
00297     int goToInitializeStatus();
00298 
00299 
00300     /** initialize to FeliCa Through(FT) mode
00301      *
00302      * @param   [in]    Mode    Operation Mode(OPMODE_LITES_HT or OPMODE_PLUG)
00303      * @retval  0       success
00304      */
00305     int initFTMode(OpMode Mode);
00306 
00307 
00308 #if 0
00309     /** initialize to NFC-DEP mode
00310      *
00311      * @retval  0       success
00312      */
00313     int initNfcDepMode();
00314 #endif
00315 
00316 
00317     /** Interrupt Service Routine(IRQ pin)
00318      *
00319      */
00320     void isrIrq();
00321 
00322 
00323 private:
00324     I2C&                    _i2c;           //!< I2C
00325     int                     _slvAddr;       //!< Slave Address(8bit)
00326     callbacktable_t         _cbTable;       //!< Callback Table
00327 };
00328 
00329 #endif /* RCS730_H */
00330 
00331 
00332 
00333