mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
chg: clean up
This commit is contained in:
parent
26ff7fa297
commit
3ecff83de2
3 changed files with 36 additions and 26 deletions
|
@ -381,7 +381,7 @@ void SendStatus(void) {
|
||||||
Fpga_print_status();
|
Fpga_print_status();
|
||||||
Flashmem_print_status();
|
Flashmem_print_status();
|
||||||
#ifdef WITH_SMARTCARD
|
#ifdef WITH_SMARTCARD
|
||||||
i2c_print_status();
|
I2C_print_status();
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_LF
|
#ifdef WITH_LF
|
||||||
printConfig(); //LF Sampling config
|
printConfig(); //LF Sampling config
|
||||||
|
@ -1015,14 +1015,17 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
||||||
iClass_Clone(c->arg[0], c->arg[1], c->d.asBytes);
|
iClass_Clone(c->arg[0], c->arg[1], c->d.asBytes);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_HFSNOOP
|
#ifdef WITH_HFSNOOP
|
||||||
case CMD_HF_SNIFFER:
|
case CMD_HF_SNIFFER:
|
||||||
HfSnoop(c->arg[0], c->arg[1]);
|
HfSnoop(c->arg[0], c->arg[1]);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_SMARTCARD
|
#ifdef WITH_SMARTCARD
|
||||||
case CMD_SMART_SEND: {
|
case CMD_SMART_SEND: {
|
||||||
|
|
||||||
|
I2C_init();
|
||||||
// sending to smart card.
|
// sending to smart card.
|
||||||
I2C_Reset_EnterMainProgram();
|
I2C_Reset_EnterMainProgram();
|
||||||
|
|
||||||
|
|
53
common/i2c.c
53
common/i2c.c
|
@ -22,17 +22,29 @@
|
||||||
|
|
||||||
#define SCL_read (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SCL)
|
#define SCL_read (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SCL)
|
||||||
#define SDA_read (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SDA)
|
#define SDA_read (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SDA)
|
||||||
|
|
||||||
#define I2C_PageSize 8
|
volatile unsigned long c;
|
||||||
|
|
||||||
|
|
||||||
// 直接使用循环来延时,一个循环 6 条指令,48M, Delay=1 大概为 200kbps
|
// 直接使用循环来延时,一个循环 6 条指令,48M, Delay=1 大概为 200kbps
|
||||||
void I2CSpinDelayClk(uint16_t delay) __attribute__((optimize("O0")));
|
//void I2CSpinDelayClk(uint16_t delay) ;
|
||||||
void I2CSpinDelayClk(uint16_t delay) {
|
void __attribute__((optimize("O0"))) I2CSpinDelayClk(uint16_t delay) {
|
||||||
volatile uint32_t c;
|
|
||||||
for (c = delay * 2; c; c--) {};
|
for (c = delay * 2; c; c--) {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define I2C_DELAY_1CLK I2CSpinDelayClk(1)
|
||||||
|
#define I2C_DELAY_2CLK I2CSpinDelayClk(2)
|
||||||
|
#define I2C_DELAY_XCLK(x) I2CSpinDelayClk((x))
|
||||||
|
*/
|
||||||
|
// ͨѶÑÓ³Ùº¯Êý ommunication delay function
|
||||||
|
#define I2C_DELAY_1CLK I2C_DELAY_1()
|
||||||
|
#define I2C_DELAY_2CLK I2C_DELAY_2()
|
||||||
|
#define I2C_DELAY_XCLK(x) I2C_DELAY_X((x))
|
||||||
|
void I2C_DELAY_1(void) { I2CSpinDelayClk(1);}
|
||||||
|
void I2C_DELAY_2(void) { I2CSpinDelayClk(2);}
|
||||||
|
void I2C_DELAY_X(uint16_t delay) { I2CSpinDelayClk(delay);}
|
||||||
|
|
||||||
|
|
||||||
void I2C_init(void) {
|
void I2C_init(void) {
|
||||||
// 配置复位引脚,关闭上拉,推挽输出,默认高
|
// 配置复位引脚,关闭上拉,推挽输出,默认高
|
||||||
// Configure reset pin, close up pull up, push-pull output, default high
|
// Configure reset pin, close up pull up, push-pull output, default high
|
||||||
|
@ -54,9 +66,6 @@ void I2C_init(void) {
|
||||||
AT91C_BASE_PIOA->PIO_PER = GPIO_SCL | GPIO_SDA | GPIO_RST;
|
AT91C_BASE_PIOA->PIO_PER = GPIO_SCL | GPIO_SDA | GPIO_RST;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define I2C_DELAY_1CLK I2CSpinDelayClk(1)
|
|
||||||
#define I2C_DELAY_2CLK I2CSpinDelayClk(2)
|
|
||||||
#define I2C_DELAY_XCLK(x) I2CSpinDelayClk((x))
|
|
||||||
|
|
||||||
// 设置复位状态
|
// 设置复位状态
|
||||||
// set the reset state
|
// set the reset state
|
||||||
|
@ -99,9 +108,10 @@ void I2C_Reset_EnterBootloader(void) {
|
||||||
|
|
||||||
// 等待时钟变高
|
// 等待时钟变高
|
||||||
// Wait for the clock to go High.
|
// Wait for the clock to go High.
|
||||||
|
volatile uint16_t count;
|
||||||
bool WaitSCL_H(void) {
|
bool WaitSCL_H(void) {
|
||||||
|
|
||||||
volatile uint16_t count = 5000;
|
count = 5000;
|
||||||
|
|
||||||
while (count--) {
|
while (count--) {
|
||||||
if (SCL_read) {
|
if (SCL_read) {
|
||||||
|
@ -196,7 +206,7 @@ void I2C_SendByte(uint8_t data) {
|
||||||
SCL_L;
|
SCL_L;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t I2C_ReceiveByte(void) {
|
uint8_t I2C_ReadByte(void) {
|
||||||
uint8_t i = 8, b = 0;
|
uint8_t i = 8, b = 0;
|
||||||
|
|
||||||
SDA_H;
|
SDA_H;
|
||||||
|
@ -241,7 +251,7 @@ bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address) {
|
||||||
|
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
DbpString("I2C_WaitAck Error\n");
|
DbpString("I2C_WaitAck Error");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +296,7 @@ bool I2C_BufferWrite(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t dev
|
||||||
|
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
DbpString("I2C_WaitAck Error\n");
|
DbpString("I2C_WaitAck Error");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,14 +335,14 @@ uint8_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t d
|
||||||
|
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
DbpString("I2C_WaitAck Error\n");
|
DbpString("I2C_WaitAck Error");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reading
|
// reading
|
||||||
while (len) {
|
while (len) {
|
||||||
len--;
|
len--;
|
||||||
*data = I2C_ReceiveByte();
|
*data = I2C_ReadByte();
|
||||||
// 读取的第一个字节为后续长度
|
// 读取的第一个字节为后续长度
|
||||||
// The first byte read is the message length
|
// The first byte read is the message length
|
||||||
if (!readcount && (len > *data))
|
if (!readcount && (len > *data))
|
||||||
|
@ -351,14 +361,11 @@ uint8_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t d
|
||||||
return readcount;
|
return readcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_print_status(void) {
|
void I2C_print_status(void) {
|
||||||
DbpString("Smart card module (ISO 7816)");
|
|
||||||
|
|
||||||
I2C_init();
|
I2C_init();
|
||||||
I2C_Reset_EnterMainProgram();
|
I2C_Reset_EnterMainProgram();
|
||||||
// get version
|
uint8_t resp[4] = {0};
|
||||||
uint8_t resp[3] = {0};
|
uint8_t len = I2C_BufferRead(resp, 4, I2C_DEVICE_CMD_GETVERSION, I2C_DEVICE_ADDRESS_MAIN);
|
||||||
uint8_t len = I2C_BufferRead(resp, 3, I2C_DEVICE_CMD_GETVERSION, I2C_DEVICE_ADDRESS_MAIN);
|
DbpString("Smart card module (ISO 7816)");
|
||||||
if ( len == 3)
|
Dbprintf(" FW version................v%x.%02x (len %d", resp[1], resp[2], len);
|
||||||
Dbprintf(" FW version................v%x.%02x", resp[1], resp[2]);
|
|
||||||
}
|
}
|
|
@ -25,9 +25,9 @@ void I2C_SetResetStatus(uint8_t LineRST, uint8_t LineSCK, uint8_t LineSDA);
|
||||||
void I2C_Reset_EnterMainProgram(void);
|
void I2C_Reset_EnterMainProgram(void);
|
||||||
void I2C_Reset_EnterBootloader(void);
|
void I2C_Reset_EnterBootloader(void);
|
||||||
|
|
||||||
bool I2C_WriteByte(uint8_t SendData, uint8_t device_cmd, uint8_t device_address);
|
bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address);
|
||||||
bool I2C_BufferWrite(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t device_address);
|
bool I2C_BufferWrite(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t device_address);
|
||||||
uint8_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t device_address);
|
uint8_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t device_address);
|
||||||
|
|
||||||
void i2c_print_status(void);
|
void I2C_print_status(void);
|
||||||
#endif
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue