Skip to content

Commit

Permalink
Cleaned up and modernized usb_cdc.c
Browse files Browse the repository at this point in the history
  • Loading branch information
jlitewski committed May 27, 2024
1 parent 85d9e53 commit e48d8c0
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 337 deletions.
13 changes: 11 additions & 2 deletions armsrc/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,9 @@ static void SendVersion(void) {

static void TimingIntervalAcquisition(void) {
// trigger new acquisition by turning main oscillator off and on
if(PRINT_DEBUG) Dbprintf("Turning Main Oscillator off...");
mck_from_pll_to_slck();
if(PRINT_DEBUG) Dbprintf("Turning Main Oscillator on...");
mck_from_slck_to_pll();
// wait for MCFR and recompute RTMR scaler
StartTickCount();
Expand Down Expand Up @@ -430,7 +432,7 @@ static void print_debug_level(void) {
// Note: this mimics GetFromBigbuf(), i.e. we have the overhead of the PacketCommandNG structure included.
static void printConnSpeed(uint32_t wait) {
DbpString(_CYAN_("Transfer Speed"));
Dbprintf(" Sending packets to client...");
Dbprintf(_CYAN_(" [<--] Sending packets to client..."));

uint8_t *test_data = (uint8_t*)palloc(2, PM3_CMD_DATA_SIZE);

Expand All @@ -444,6 +446,10 @@ static void printConnSpeed(uint32_t wait) {
uint32_t delta_time = 0;
uint32_t bytes_transferred = 0;

// Disable debug logging to get an accurate speed
debug_level old_debug_level = g_dbglevel;
g_dbglevel = DEBUG_NONE;

LED_B_ON();

while (delta_time < wait) {
Expand All @@ -454,6 +460,9 @@ static void printConnSpeed(uint32_t wait) {

LED_B_OFF();

// Reenable the debug logging
g_dbglevel = old_debug_level;

Dbprintf(" Time elapsed................... %dms", delta_time);
Dbprintf(" Bytes transferred.............. %d", bytes_transferred);
if (delta_time) {
Expand Down Expand Up @@ -506,7 +515,7 @@ static void SendStatus(uint32_t wait) {
Dbprintf(_YELLOW_(" Slow Clock actual speed seems closer to %d kHz"),
(16 * MAINCK / 1000) / mainf * delta_time / SLCK_CHECK_MS);
}
DbpString(_CYAN_("Installed StandAlone Mode"));
DbpString(_CYAN_("Installed Standalone Mode"));
ModInfo();

#ifdef WITH_FLASH
Expand Down
8 changes: 4 additions & 4 deletions armsrc/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const v
#endif

#ifdef DEBUG_ARM
Dbprintf(_BACK_BRIGHT_BLUE_("[<--] Reply OLD Packet (%d bytes payload, command 0x%04x, args: %d %d %d)"), len, cmd, arg0, arg1, arg2);
if(PRINT_DEBUG) Dbprintf(_BACK_BRIGHT_BLUE_("[<--] Reply OLD Packet (%d bytes payload, command 0x%04x, args: %d %d %d)"), len, cmd, arg0, arg1, arg2);
#endif

return PM3_SUCCESS;
Expand Down Expand Up @@ -157,7 +157,7 @@ static int reply_ng_internal(uint16_t cmd, int16_t status, const uint8_t *data,
#ifdef DEBUG_ARM
uint8_t upper = (cmd >> 8) & 0xFF;
if(upper != 0xF0) { // Filter out debug commands
Dbprintf(_BACK_BRIGHT_BLUE_("[<--] Reply NG Packet (%d bytes payload, command 0x%04x)"), txBufferNGLen, cmd);
if(PRINT_DEBUG) Dbprintf(_BACK_BRIGHT_BLUE_("[<--] Reply NG Packet (%d bytes payload, command 0x%04x)"), txBufferNGLen, cmd);
}
#endif

Expand Down Expand Up @@ -243,7 +243,7 @@ static int receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t *da
g_reply_via_fpc = fpc;

#ifdef DEBUG_ARM
Dbprintf(_BRIGHT_BLUE_("[-->] Recv NG packet (%d bytes payload, command: 0x%04x)"), rx->length, rx->cmd);
if(PRINT_DEBUG) Dbprintf(_BRIGHT_BLUE_("[-->] Recv NG packet (%d bytes payload, command: 0x%04x)"), rx->length, rx->cmd);
#endif
} else { // Old style command
PacketCommandOLD rx_old;
Expand All @@ -267,7 +267,7 @@ static int receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t *da
palloc_copy(&rx->data, &rx_old.d.asBytes, rx->length);

#ifdef DEBUG_ARM
Dbprintf(_BRIGHT_BLUE_("[-->] Recv OLD packet (%d bytes payload, command: 0x%04x, args: %d %d %d)"), rx->length, rx->cmd, rx->oldarg[0], rx->oldarg[1], rx->oldarg[2]);
if(PRINT_DEBUG) Dbprintf(_BRIGHT_BLUE_("[-->] Recv OLD packet (%d bytes payload, command: 0x%04x, args: %d %d %d)"), rx->length, rx->cmd, rx->oldarg[0], rx->oldarg[1], rx->oldarg[2]);
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions common_arm/clocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// See LICENSE.txt for the text of the license.
//-----------------------------------------------------------------------------
#include "clocks.h"

#include "at91sam7s512.h"
#include "proxmark3_arm.h"

void mck_from_pll_to_slck(void) {
Expand Down
Loading

0 comments on commit e48d8c0

Please sign in to comment.