added some helper functions

This commit is contained in:
iceman1001 committed 2023-10-01 13:05:08 +02:00
1 parent 7320f0dd16
commit bb5d61dca7
11 files changed
+111 -28

No files matched your search

+21 -13
View File
@@ -76,11 +76,11 @@ void Dbprintf(const char *fmt, ...) {
// prints HEX & ASCII
void Dbhexdump(int len, const uint8_t *d, bool bAsci) {
#if DEBUG
char ascii[9];
char ascii[17];
while (len > 0) {
int l = (len > 8) ? 8 : len;
int l = (len > 16) ? 16 : len;
memcpy(ascii, d, l);
ascii[l] = 0;
@@ -97,36 +97,44 @@ void Dbhexdump(int len, const uint8_t *d, bool bAsci) {
else
Dbprintf("%*D", l, d, " ");
len -= 8;
d += 8;
len -= 16;
d += 16;
}
#endif
}
void print_result(const char *name, const uint8_t *buf, size_t len) {
void print_result(const char *name, const uint8_t *d, size_t n) {
const uint8_t *p = buf;
uint16_t tmp = len & 0xFFF0;
const uint8_t *p = d;
uint16_t tmp = n & 0xFFF0;
for (; p - buf < tmp; p += 16) {
for (; p - d < tmp; p += 16) {
Dbprintf("[%s: %02d/%02d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
name,
p - buf,
len,
p - d,
n,
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]
);
}
if (len % 16 != 0) {
if (n % 16 != 0) {
char s[46] = {0};
char *sp = s;
for (; p - buf < len; p++) {
for (; p - d < n; p++) {
sprintf(sp, "%02x ", p[0]);
sp += 3;
}
Dbprintf("[%s: %02d/%02d] %s", name, p - buf, len, s);
Dbprintf("[%s: %02d/%02d] %s", name, p - d, n, s);
}
}
// Prints message and hexdump
void print_dbg(char *msg, uint8_t *d, uint16_t n) {
if (g_dbglevel == DBG_DEBUG) {
print_result(msg, d, n);
}
}
/* useful when debugging new protocol implementations like FeliCa
void PrintToSendBuffer(void) {
DbpString("Printing ToSendBuffer:");
+1
View File
@@ -28,6 +28,7 @@ void Dbprintf(const char *fmt, ...);
void DbprintfEx(uint32_t flags, const char *fmt, ...);
void Dbhexdump(int len, const uint8_t *d, bool bAsci);
void print_result(const char *name, const uint8_t *buf, size_t len);
void print_dbg(char *msg, uint8_t *d, uint16_t n);
//void PrintToSendBuffer(void);
#endif
-8
View File
@@ -39,11 +39,6 @@
#define I2C_ERROR "I2C_WaitAck Error"
// 8051 speaks with smart card.
// 1000*50*3.07 = 153.5ms
// 1 byte transfer == 1ms with max frame being 256 bytes
#define SIM_WAIT_DELAY 88000 // about 270ms delay // 109773 -- about 337.7ms delay
// Direct use the loop to delay. 6 instructions loop, Masterclock 48MHz,
// delay=1 is about 200kbps
// timer.
@@ -58,9 +53,6 @@ static void __attribute__((optimize("O0"))) I2CSpinDelayClk(uint16_t delay) {
#define I2C_DELAY_2CLK I2CSpinDelayClk(2)
#define I2C_DELAY_XCLK(x) I2CSpinDelayClk((x))
// The SIM module v4 supports up to 384 bytes for the length.
#define ISO7816_MAX_FRAME 270
// try i2c bus recovery at 100kHz = 5us high, 5us low
void I2C_recovery(void) {
+9
View File
@@ -30,6 +30,15 @@
#define I2C_DEVICE_CMD_GETVERSION 0x06
#define I2C_DEVICE_CMD_SEND_T0 0x07
// The SIM module v4 supports up to 384 bytes for the length.
#define ISO7816_MAX_FRAME 270
// 8051 speaks with smart card.
// 1000*50*3.07 = 153.5ms
// 1 byte transfer == 1ms with max frame being 256 bytes
#define SIM_WAIT_DELAY 88000 // about 270ms delay // 109773 -- about 337.7ms delay
void I2C_recovery(void);
void I2C_init(bool has_ticks);
void I2C_Reset(void);