Subversion Repositories Code-Repo

Rev

Rev 148 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 148 Rev 154
Line 29... Line 29...
29
    nfc_data_p->packetbuffer[0] = PN532_COMMAND_SAMCONFIGURATION;
29
    nfc_data_p->packetbuffer[0] = PN532_COMMAND_SAMCONFIGURATION;
30
    nfc_data_p->packetbuffer[1] = 0x01; // Normal mode
30
    nfc_data_p->packetbuffer[1] = 0x01; // Normal mode
31
    nfc_data_p->packetbuffer[2] = 0x14; // Timeout 50ms * 20 = 1s
31
    nfc_data_p->packetbuffer[2] = 0x14; // Timeout 50ms * 20 = 1s
32
    nfc_data_p->packetbuffer[3] = 0x01; // Use IRQ pin
32
    nfc_data_p->packetbuffer[3] = 0x01; // Use IRQ pin
33
 
33
 
34
    if (!NFC_sendCommandCheckAck(nfc_data_p->packetbuffer, 4))
34
    if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 4))
35
        return 0;
35
        return 0;
36
 
36
 
37
    NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 8);
37
    NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 8);
38
 
38
 
39
    return (nfc_data_p->packetbuffer[7] == 0x15);
39
    return (nfc_data_p->packetbuffer[7] == 0x15);
40
}
40
}
41
 
41
 
42
// Checks the firmware version of the PN5xx chip
42
// Checks the firmware version of the PN5xx chip
43
NFC_FIRMWARE_VERSION NFC_getFirmwareVersion(void) {
43
NFC_FIRMWARE_VERSION NFC_Get_Firmware_Version(void) {
44
    NFC_FIRMWARE_VERSION response = {0, 0, 0, 0};
44
    NFC_FIRMWARE_VERSION response = {0, 0, 0, 0};
45
 
45
 
46
    // Create and send command
46
    // Create and send command
47
    nfc_data_p->packetbuffer[0] = PN532_COMMAND_GETFIRMWAREVERSION;
47
    nfc_data_p->packetbuffer[0] = PN532_COMMAND_GETFIRMWAREVERSION;
48
 
48
 
49
    if (!NFC_sendCommandCheckAck(nfc_data_p->packetbuffer, 1))
49
    if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 1))
50
        return response;
50
        return response;
51
 
51
 
52
    // Read back data from the PN532
52
    // Read back data from the PN532
53
    NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 12);
53
    NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 12);
54
 
54
 
Line 64... Line 64...
64
 
64
 
65
    return response;
65
    return response;
66
}
66
}
67
 
67
 
68
// Sends a command and waits a specified period for the ACK
68
// Sends a command and waits a specified period for the ACK
69
unsigned char NFC_sendCommandCheckAck(unsigned char *cmd, unsigned char cmdlen) {
69
unsigned char NFC_Send_Command_Check_Ack(unsigned char *cmd, unsigned char cmdlen) {
70
    unsigned int timer = 0;
70
    unsigned int timer = 0;
71
 
71
 
72
    // Write the command
72
    // Write the command
73
    NFC_I2C_Write_Cmd(cmd, cmdlen);
73
    NFC_I2C_Write_Cmd(cmd, cmdlen);
74
 
74
 
Line 89... Line 89...
89
 
89
 
90
    return 1;
90
    return 1;
91
}
91
}
92
 
92
 
93
// Passive polling, waits for an ISO14443A target to enter the field
93
// Passive polling, waits for an ISO14443A target to enter the field
94
unsigned char NFC_readPassiveTargetID(NFC_TargetDataMiFare *cardData) {
94
unsigned char NFC_Read_Passive_Target_ID(NFC_TargetDataMiFare *cardData) {
95
    
95
    
96
    nfc_data_p->packetbuffer[0] = PN532_COMMAND_INLISTPASSIVETARGET;
96
    nfc_data_p->packetbuffer[0] = PN532_COMMAND_INLISTPASSIVETARGET;
97
    nfc_data_p->packetbuffer[1] = 2; // Max 2 cards at once
97
    nfc_data_p->packetbuffer[1] = 2; // Max 2 cards at once
98
    nfc_data_p->packetbuffer[2] = PN532_MIFARE_ISO14443A;  // Mifare only
98
    nfc_data_p->packetbuffer[2] = PN532_MIFARE_ISO14443A;  // Mifare only
99
 
99
 
100
    if (!NFC_sendCommandCheckAck(nfc_data_p->packetbuffer, 3))
100
    if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 3))
101
        return 0;
101
        return 0;
102
 
102
 
103
    // Wait for IRQ line
103
    // Wait for IRQ line
104
    while (NFC_I2C_Read_Status() != PN532_I2C_READY);
104
    while (NFC_I2C_Read_Status() != PN532_I2C_READY);
105
 
105
 
Line 147... Line 147...
147
    // Return the number of cards detected
147
    // Return the number of cards detected
148
    return nfc_data_p->packetbuffer[8];
148
    return nfc_data_p->packetbuffer[8];
149
}
149
}
150
 
150
 
151
// Active polling, returns number of cards in the field
151
// Active polling, returns number of cards in the field
152
unsigned char NFC_pollTargets(unsigned char number, unsigned char period, NFC_TargetDataMiFare *cardData) {
152
unsigned char NFC_Poll_Targets(unsigned char number, unsigned char period, NFC_TargetDataMiFare *cardData) {
153
    
153
    
154
    nfc_data_p->packetbuffer[0] = PN532_COMMAND_INAUTOPOLL;
154
    nfc_data_p->packetbuffer[0] = PN532_COMMAND_INAUTOPOLL;
155
    nfc_data_p->packetbuffer[1] = number; // Number of polling
155
    nfc_data_p->packetbuffer[1] = number; // Number of polling
156
    nfc_data_p->packetbuffer[2] = period; // Polling period in units of 150ms
156
    nfc_data_p->packetbuffer[2] = period; // Polling period in units of 150ms
157
    nfc_data_p->packetbuffer[3] = 0x10; // Check for Mifare cards only
157
    nfc_data_p->packetbuffer[3] = 0x10; // Check for Mifare cards only
158
 
158
 
159
    if (!NFC_sendCommandCheckAck(nfc_data_p->packetbuffer, 4))
159
    if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 4))
160
        return 0;
160
        return 0;
161
 
161
 
162
    // Wait for IRQ line
162
    // Wait for IRQ line
163
    while (NFC_I2C_Read_Status() != PN532_I2C_READY);
163
    while (NFC_I2C_Read_Status() != PN532_I2C_READY);
164
 
164
 
Line 248... Line 248...
248
    for (i = 0; i < uidLen; i++) {
248
    for (i = 0; i < uidLen; i++) {
249
        nfc_data_p->packetbuffer[10 + i] = uid[i];
249
        nfc_data_p->packetbuffer[10 + i] = uid[i];
250
    }
250
    }
251
 
251
 
252
    // Send frame and check for ACK
252
    // Send frame and check for ACK
253
    if (!NFC_sendCommandCheckAck(nfc_data_p->packetbuffer, 10 + uidLen))
253
    if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 10 + uidLen))
254
        return 0;
254
        return 0;
255
 
255
 
256
    // Read response from PN532
256
    // Read response from PN532
257
    NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 12);
257
    NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 12);
258
 
258
 
Line 268... Line 268...
268
    nfc_data_p->packetbuffer[1] = 1; /* Card number */
268
    nfc_data_p->packetbuffer[1] = 1; /* Card number */
269
    nfc_data_p->packetbuffer[2] = MIFARE_CMD_READ; /* Mifare Read command = 0x30 */
269
    nfc_data_p->packetbuffer[2] = MIFARE_CMD_READ; /* Mifare Read command = 0x30 */
270
    nfc_data_p->packetbuffer[3] = blockNumber; /* Block Number (0..63 for 1K, 0..255 for 4K) */
270
    nfc_data_p->packetbuffer[3] = blockNumber; /* Block Number (0..63 for 1K, 0..255 for 4K) */
271
 
271
 
272
    // Send frame and check for ACK
272
    // Send frame and check for ACK
273
    if (!NFC_sendCommandCheckAck(nfc_data_p->packetbuffer, 4))
273
    if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 4))
274
        return 0;
274
        return 0;
275
 
275
 
276
    // Read reponse
276
    // Read reponse
277
    NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 26);
277
    NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 26);
278
 
278
 
Line 302... Line 302...
302
    for (i = 0; i < 16; i++) { /* Data Payload */
302
    for (i = 0; i < 16; i++) { /* Data Payload */
303
        nfc_data_p->packetbuffer[4 + i] = data[i];
303
        nfc_data_p->packetbuffer[4 + i] = data[i];
304
    }
304
    }
305
 
305
 
306
    // Send frame and check for ACK
306
    // Send frame and check for ACK
307
    if (!NFC_sendCommandCheckAck(nfc_data_p->packetbuffer, 20))
307
    if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 20))
308
        return 0;
308
        return 0;
309
 
309
 
310
    // Read response
310
    // Read response
311
    NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 26);
311
    NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 26);
312
 
312