Functions for accessing M24SR device.

Dependents:   Nucleo_NFC_Example I2C_NFC_Master Print_Entire_Nucleo_NFC01A1_Memory

Fork of lib_M24SR by Enrico Gregoratto

Warning: Deprecated!

Supported drivers and applications can be found at this link.

Committer:
EnricoG
Date:
Mon Dec 15 19:41:52 2014 +0000
Revision:
0:ffc2448b65ef
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EnricoG 0:ffc2448b65ef 1 /**
EnricoG 0:ffc2448b65ef 2 ******************************************************************************
EnricoG 0:ffc2448b65ef 3 * @file drv_M24SR.h
EnricoG 0:ffc2448b65ef 4 * @author MMY Application Team
EnricoG 0:ffc2448b65ef 5 * @version V4.5.0
EnricoG 0:ffc2448b65ef 6 * @date 08-May-2013
EnricoG 0:ffc2448b65ef 7 * @brief This file provides a set of functions needed to manage M24SR
EnricoG 0:ffc2448b65ef 8 ******************************************************************************
EnricoG 0:ffc2448b65ef 9 * @attention
EnricoG 0:ffc2448b65ef 10 *
EnricoG 0:ffc2448b65ef 11 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
EnricoG 0:ffc2448b65ef 12 *
EnricoG 0:ffc2448b65ef 13 * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License");
EnricoG 0:ffc2448b65ef 14 * You may not use this file except in compliance with the License.
EnricoG 0:ffc2448b65ef 15 * You may obtain a copy of the License at:
EnricoG 0:ffc2448b65ef 16 *
EnricoG 0:ffc2448b65ef 17 * http://www.st.com/software_license_agreement_liberty_v2
EnricoG 0:ffc2448b65ef 18 *
EnricoG 0:ffc2448b65ef 19 * Unless required by applicable law or agreed to in writing, software
EnricoG 0:ffc2448b65ef 20 * distributed under the License is distributed on an "AS IS" BASIS,
EnricoG 0:ffc2448b65ef 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
EnricoG 0:ffc2448b65ef 22 * See the License for the specific language governing permissions and
EnricoG 0:ffc2448b65ef 23 * limitations under the License.
EnricoG 0:ffc2448b65ef 24 *
EnricoG 0:ffc2448b65ef 25 ******************************************************************************
EnricoG 0:ffc2448b65ef 26 */
EnricoG 0:ffc2448b65ef 27
EnricoG 0:ffc2448b65ef 28 /* Define to prevent recursive inclusion -------------------------------------*/
EnricoG 0:ffc2448b65ef 29 #ifndef __DRV_M24SR_H
EnricoG 0:ffc2448b65ef 30 #define __DRV_M24SR_H
EnricoG 0:ffc2448b65ef 31
EnricoG 0:ffc2448b65ef 32 #ifdef __cplusplus
EnricoG 0:ffc2448b65ef 33 extern "C" {
EnricoG 0:ffc2448b65ef 34 #endif
EnricoG 0:ffc2448b65ef 35
EnricoG 0:ffc2448b65ef 36 /* Includes ------------------------------------------------------------------*/
EnricoG 0:ffc2448b65ef 37 #include "drv_I2C_M24SR.h"
EnricoG 0:ffc2448b65ef 38
EnricoG 0:ffc2448b65ef 39
EnricoG 0:ffc2448b65ef 40 /* ---------------------- macro function -------------------------------------*/
EnricoG 0:ffc2448b65ef 41 #define GETMSB(val) ( (uint8_t) ((val & 0xFF00 )>>8) )
EnricoG 0:ffc2448b65ef 42 #define GETLSB(val) ( (uint8_t) (val & 0x00FF ))
EnricoG 0:ffc2448b65ef 43
EnricoG 0:ffc2448b65ef 44 #define TOGGLE(val) ((val != 0x00)? 0x00 : 0x01)
EnricoG 0:ffc2448b65ef 45
EnricoG 0:ffc2448b65ef 46 /* ---------------------- status code ----------------------------------------*/
EnricoG 0:ffc2448b65ef 47 #define M24SR_ACTION_COMPLETED 0x9000
EnricoG 0:ffc2448b65ef 48 #define UB_STATUS_OFFSET 4
EnricoG 0:ffc2448b65ef 49 #define LB_STATUS_OFFSET 3
EnricoG 0:ffc2448b65ef 50
EnricoG 0:ffc2448b65ef 51 #define M24SR_NBBYTE_INVALID 0xFFFE
EnricoG 0:ffc2448b65ef 52
EnricoG 0:ffc2448b65ef 53 /*-------------------------- File Identifier ---------------------------------*/
EnricoG 0:ffc2448b65ef 54 #define SYSTEM_FILE_ID 0xE101
EnricoG 0:ffc2448b65ef 55 #define CC_FILE_ID 0xE103
EnricoG 0:ffc2448b65ef 56 #define NDEF_FILE_ID 0x0001
EnricoG 0:ffc2448b65ef 57
EnricoG 0:ffc2448b65ef 58 /*-------------------------- Password Management -----------------------------*/
EnricoG 0:ffc2448b65ef 59 #define READ_PWD 0x0001
EnricoG 0:ffc2448b65ef 60 #define WRITE_PWD 0x0002
EnricoG 0:ffc2448b65ef 61 #define I2C_PWD 0x0003
EnricoG 0:ffc2448b65ef 62
EnricoG 0:ffc2448b65ef 63 /*-------------------------- Verify command answer ----------------------------*/
EnricoG 0:ffc2448b65ef 64 #define M24SR_PWD_NOT_NEEDED 0x9000
EnricoG 0:ffc2448b65ef 65 #define M24SR_PWD_NEEDED 0x6300
EnricoG 0:ffc2448b65ef 66
EnricoG 0:ffc2448b65ef 67 #define M24SR_PWD_CORRECT 0x9000
EnricoG 0:ffc2448b65ef 68
EnricoG 0:ffc2448b65ef 69
EnricoG 0:ffc2448b65ef 70
EnricoG 0:ffc2448b65ef 71
EnricoG 0:ffc2448b65ef 72 /* special M24SR command ----------------------------------------------------------------------*/
EnricoG 0:ffc2448b65ef 73 #define M24SR_OPENSESSION 0x26
EnricoG 0:ffc2448b65ef 74 #define M24SR_KILLSESSION 0x52
EnricoG 0:ffc2448b65ef 75
EnricoG 0:ffc2448b65ef 76 /* Length ----------------------------------------------------------------------------------*/
EnricoG 0:ffc2448b65ef 77 #define M24SR_STATUS_NBBYTE 2
EnricoG 0:ffc2448b65ef 78 #define M24SR_CRC_NBBYTE 2
EnricoG 0:ffc2448b65ef 79 #define M24SR_STATUSRESPONSE_NBBYTE 5
EnricoG 0:ffc2448b65ef 80 #define M24SR_DESELECTREQUEST_NBBYTE 3
EnricoG 0:ffc2448b65ef 81 #define M24SR_DESELECTRESPONSE_NBBYTE 3
EnricoG 0:ffc2448b65ef 82 #define M24SR_WATINGTIMEEXTRESPONSE_NBBYTE 4
EnricoG 0:ffc2448b65ef 83 #define M24SR_PASSWORD_NBBYTE 0x10
EnricoG 0:ffc2448b65ef 84
EnricoG 0:ffc2448b65ef 85 /* Command structure ------------------------------------------------------------------------*/
EnricoG 0:ffc2448b65ef 86 #define M24SR_CMDSTRUCT_SELECTAPPLICATION 0x01FF
EnricoG 0:ffc2448b65ef 87 #define M24SR_CMDSTRUCT_SELECTCCFILE 0x017F
EnricoG 0:ffc2448b65ef 88 #define M24SR_CMDSTRUCT_SELECTNDEFFILE 0x017F
EnricoG 0:ffc2448b65ef 89 #define M24SR_CMDSTRUCT_READBINARY 0x019F
EnricoG 0:ffc2448b65ef 90 #define M24SR_CMDSTRUCT_UPDATEBINARY 0x017F
EnricoG 0:ffc2448b65ef 91 #define M24SR_CMDSTRUCT_VERIFYBINARYWOPWD 0x013F
EnricoG 0:ffc2448b65ef 92 #define M24SR_CMDSTRUCT_VERIFYBINARYWITHPWD 0x017F
EnricoG 0:ffc2448b65ef 93 #define M24SR_CMDSTRUCT_CHANGEREFDATA 0x017F
EnricoG 0:ffc2448b65ef 94 #define M24SR_CMDSTRUCT_ENABLEVERIFREQ 0x011F
EnricoG 0:ffc2448b65ef 95 #define M24SR_CMDSTRUCT_DISABLEVERIFREQ 0x011F
EnricoG 0:ffc2448b65ef 96 #define M24SR_CMDSTRUCT_SENDINTERRUPT 0x013F
EnricoG 0:ffc2448b65ef 97 #define M24SR_CMDSTRUCT_GPOSTATE 0x017F
EnricoG 0:ffc2448b65ef 98
EnricoG 0:ffc2448b65ef 99 /* Command structure Mask -------------------------------------------------------------------*/
EnricoG 0:ffc2448b65ef 100 #define M24SR_PCB_NEEDED 0x0001 /* PCB byte present or not */
EnricoG 0:ffc2448b65ef 101 #define M24SR_CLA_NEEDED 0x0002 /* CLA byte present or not */
EnricoG 0:ffc2448b65ef 102 #define M24SR_INS_NEEDED 0x0004 /* Operation code present or not*/
EnricoG 0:ffc2448b65ef 103 #define M24SR_P1_NEEDED 0x0008 /* Selection Mode present or not*/
EnricoG 0:ffc2448b65ef 104 #define M24SR_P2_NEEDED 0x0010 /* Selection Option present or not*/
EnricoG 0:ffc2448b65ef 105 #define M24SR_LC_NEEDED 0x0020 /* Data field length byte present or not */
EnricoG 0:ffc2448b65ef 106 #define M24SR_DATA_NEEDED 0x0040 /* Data present or not */
EnricoG 0:ffc2448b65ef 107 #define M24SR_LE_NEEDED 0x0080 /* Expected length present or not */
EnricoG 0:ffc2448b65ef 108 #define M24SR_CRC_NEEDED 0x0100 /* 2 CRC bytes present or not */
EnricoG 0:ffc2448b65ef 109
EnricoG 0:ffc2448b65ef 110 #define M24SR_DID_NEEDED 0x08 /* DID byte present or not */
EnricoG 0:ffc2448b65ef 111
EnricoG 0:ffc2448b65ef 112 /* Offset ----------------------------------------------------------------------------------*/
EnricoG 0:ffc2448b65ef 113 #define M24SR_OFFSET_PCB 0
EnricoG 0:ffc2448b65ef 114 #define M24SR_OFFSET_CLASS 1
EnricoG 0:ffc2448b65ef 115 #define M24SR_OFFSET_INS 2
EnricoG 0:ffc2448b65ef 116 #define M24SR_OFFSET_P1 3
EnricoG 0:ffc2448b65ef 117
EnricoG 0:ffc2448b65ef 118
EnricoG 0:ffc2448b65ef 119 /* mask ------------------------------------------------------------------------------------*/
EnricoG 0:ffc2448b65ef 120 #define M24SR_MASK_BLOCK 0xC0
EnricoG 0:ffc2448b65ef 121 #define M24SR_MASK_IBLOCK 0x00
EnricoG 0:ffc2448b65ef 122 #define M24SR_MASK_RBLOCK 0x80
EnricoG 0:ffc2448b65ef 123 #define M24SR_MASK_SBLOCK 0xC0
EnricoG 0:ffc2448b65ef 124
EnricoG 0:ffc2448b65ef 125
EnricoG 0:ffc2448b65ef 126 /* APDU Command: class list -------------------------------------------*/
EnricoG 0:ffc2448b65ef 127 #define C_APDU_CLA_DEFAULT 0x00
EnricoG 0:ffc2448b65ef 128 #define C_APDU_CLA_ST 0xA2
EnricoG 0:ffc2448b65ef 129
EnricoG 0:ffc2448b65ef 130 /*------------------------ Data Area Management Commands ---------------------*/
EnricoG 0:ffc2448b65ef 131 #define C_APDU_SELECT_FILE 0xA4
EnricoG 0:ffc2448b65ef 132 #define C_APDU_GET_RESPONCE 0xC0
EnricoG 0:ffc2448b65ef 133 #define C_APDU_STATUS 0xF2
EnricoG 0:ffc2448b65ef 134 #define C_APDU_UPDATE_BINARY 0xD6
EnricoG 0:ffc2448b65ef 135 #define C_APDU_READ_BINARY 0xB0
EnricoG 0:ffc2448b65ef 136 #define C_APDU_WRITE_BINARY 0xD0
EnricoG 0:ffc2448b65ef 137 #define C_APDU_UPDATE_RECORD 0xDC
EnricoG 0:ffc2448b65ef 138 #define C_APDU_READ_RECORD 0xB2
EnricoG 0:ffc2448b65ef 139
EnricoG 0:ffc2448b65ef 140 /*-------------------------- Safety Management Commands ----------------------*/
EnricoG 0:ffc2448b65ef 141 #define C_APDU_VERIFY 0x20
EnricoG 0:ffc2448b65ef 142 #define C_APDU_CHANGE 0x24
EnricoG 0:ffc2448b65ef 143 #define C_APDU_DISABLE 0x26
EnricoG 0:ffc2448b65ef 144 #define C_APDU_ENABLE 0x28
EnricoG 0:ffc2448b65ef 145
EnricoG 0:ffc2448b65ef 146 /*-------------------------- Gpio Management Commands ------------------------*/
EnricoG 0:ffc2448b65ef 147 #define C_APDU_INTERRUPT 0xD6
EnricoG 0:ffc2448b65ef 148
EnricoG 0:ffc2448b65ef 149
EnricoG 0:ffc2448b65ef 150 /* APDU-Header command structure ---------------------------------------------*/
EnricoG 0:ffc2448b65ef 151 typedef struct
EnricoG 0:ffc2448b65ef 152 {
EnricoG 0:ffc2448b65ef 153 uint8_t CLA; /* Command class */
EnricoG 0:ffc2448b65ef 154 uint8_t INS; /* Operation code */
EnricoG 0:ffc2448b65ef 155 uint8_t P1; /* Selection Mode */
EnricoG 0:ffc2448b65ef 156 uint8_t P2; /* Selection Option */
EnricoG 0:ffc2448b65ef 157 } C_APDU_Header;
EnricoG 0:ffc2448b65ef 158
EnricoG 0:ffc2448b65ef 159 /* APDU-Body command structure -----------------------------------------------*/
EnricoG 0:ffc2448b65ef 160 typedef struct
EnricoG 0:ffc2448b65ef 161 {
EnricoG 0:ffc2448b65ef 162 uint8_t LC; /* Data field length */
EnricoG 0:ffc2448b65ef 163 uint8_t *pData ; /* Command parameters */
EnricoG 0:ffc2448b65ef 164 uint8_t LE; /* Expected length of data to be returned */
EnricoG 0:ffc2448b65ef 165 } C_APDU_Body;
EnricoG 0:ffc2448b65ef 166
EnricoG 0:ffc2448b65ef 167 /* APDU Command structure ----------------------------------------------------*/
EnricoG 0:ffc2448b65ef 168 typedef struct
EnricoG 0:ffc2448b65ef 169 {
EnricoG 0:ffc2448b65ef 170 C_APDU_Header Header;
EnricoG 0:ffc2448b65ef 171 C_APDU_Body Body;
EnricoG 0:ffc2448b65ef 172 } C_APDU;
EnricoG 0:ffc2448b65ef 173
EnricoG 0:ffc2448b65ef 174 /* SC response structure -----------------------------------------------------*/
EnricoG 0:ffc2448b65ef 175 typedef struct
EnricoG 0:ffc2448b65ef 176 {
EnricoG 0:ffc2448b65ef 177 uint8_t *pData ; /* Data returned from the card */ // pointer on the transceiver buffer = ReaderRecBuf[CR95HF_DATA_OFFSET ];
EnricoG 0:ffc2448b65ef 178 uint8_t SW1; /* Command Processing status */
EnricoG 0:ffc2448b65ef 179 uint8_t SW2; /* Command Processing qualification */
EnricoG 0:ffc2448b65ef 180 } R_APDU;
EnricoG 0:ffc2448b65ef 181
EnricoG 0:ffc2448b65ef 182 /* GPO mode structure -------------------------------------------------------*/
EnricoG 0:ffc2448b65ef 183 typedef enum{
EnricoG 0:ffc2448b65ef 184 RF_GPO= 0,
EnricoG 0:ffc2448b65ef 185 I2C_GPO
EnricoG 0:ffc2448b65ef 186 }M24SR_GPO_MODE;
EnricoG 0:ffc2448b65ef 187
EnricoG 0:ffc2448b65ef 188 /* GPO state structure -------------------------------------------------------*/
EnricoG 0:ffc2448b65ef 189 typedef enum{
EnricoG 0:ffc2448b65ef 190 HIGH_IMPEDANCE= 0,
EnricoG 0:ffc2448b65ef 191 SESSION_OPENED,
EnricoG 0:ffc2448b65ef 192 WIP,
EnricoG 0:ffc2448b65ef 193 I2C_ANSWER_READY,
EnricoG 0:ffc2448b65ef 194 INTERRUPT,
EnricoG 0:ffc2448b65ef 195 STATE_CONTROL
EnricoG 0:ffc2448b65ef 196 }M24SR_GPO_MGMT;
EnricoG 0:ffc2448b65ef 197
EnricoG 0:ffc2448b65ef 198
EnricoG 0:ffc2448b65ef 199 /* public function --------------------------------------------------------------------------*/
EnricoG 0:ffc2448b65ef 200
EnricoG 0:ffc2448b65ef 201 void M24SR_Init ( void );
EnricoG 0:ffc2448b65ef 202 uint16_t M24SR_GetSession ( void );
EnricoG 0:ffc2448b65ef 203 uint16_t M24SR_KillSession ( void );
EnricoG 0:ffc2448b65ef 204 uint16_t M24SR_Deselect ( void );
EnricoG 0:ffc2448b65ef 205 uint16_t M24SR_SelectApplication ( void );
EnricoG 0:ffc2448b65ef 206 uint16_t M24SR_SelectCCfile ( void );
EnricoG 0:ffc2448b65ef 207 uint16_t M24SR_SelectNDEFfile ( uc16 NDEFfileId );
EnricoG 0:ffc2448b65ef 208 uint16_t M24SR_SelectSystemfile ( void );
EnricoG 0:ffc2448b65ef 209 uint16_t M24SR_ReadBinary ( uc16 Offset, uc8 NbByteToRead, uint8_t *pBufferRead );
EnricoG 0:ffc2448b65ef 210 uint16_t M24SR_STReadBinary ( uc16 Offset, uc8 NbByteToRead, uint8_t *pBufferRead );
EnricoG 0:ffc2448b65ef 211 uint16_t M24SR_UpdateBinary ( uc16 Offset, uc8 NbByteToWrite, uc8 *pDataToWrite );
EnricoG 0:ffc2448b65ef 212 uint16_t M24SR_Verify ( uc16 uPwdId, uc8 NbPwdByte, uc8 *pPwd );
EnricoG 0:ffc2448b65ef 213 uint16_t M24SR_ChangeReferenceData ( uc16 uPwdId, uc8 *pPwd );
EnricoG 0:ffc2448b65ef 214 uint16_t M24SR_EnableVerificationRequirement ( uc16 uReadOrWrite );
EnricoG 0:ffc2448b65ef 215 uint16_t M24SR_DisableVerificationRequirement ( uc16 uReadOrWrite );
EnricoG 0:ffc2448b65ef 216 uint16_t M24SR_EnablePermanentState ( uc16 uReadOrWrite );
EnricoG 0:ffc2448b65ef 217 uint16_t M24SR_DisablePermanentState ( uc16 uReadOrWrite );
EnricoG 0:ffc2448b65ef 218 uint16_t M24SR_SendInterrupt ( void );
EnricoG 0:ffc2448b65ef 219 uint16_t M24SR_StateControl ( uc8 uSetOrReset );
EnricoG 0:ffc2448b65ef 220 uint16_t M24SR_ManageI2CGPO ( uc8 GPO_I2Cconfig);
EnricoG 0:ffc2448b65ef 221 uint16_t M24SR_ManageRFGPO ( uc8 GPO_RFconfig);
EnricoG 0:ffc2448b65ef 222 void M24SR_RFConfig ( uc8 OnOffChoice);
EnricoG 0:ffc2448b65ef 223
EnricoG 0:ffc2448b65ef 224 #ifdef __cplusplus
EnricoG 0:ffc2448b65ef 225 }
EnricoG 0:ffc2448b65ef 226 #endif
EnricoG 0:ffc2448b65ef 227
EnricoG 0:ffc2448b65ef 228 #endif /* __DRV_M24SR_H */
EnricoG 0:ffc2448b65ef 229
EnricoG 0:ffc2448b65ef 230
EnricoG 0:ffc2448b65ef 231
EnricoG 0:ffc2448b65ef 232
EnricoG 0:ffc2448b65ef 233 /******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/