mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-21 05:43:23 -07:00
usb communication (device side) refactoring
* merge cmd.c into usb_cdc.c * move back usb_cdc.[ch] to common/ * declare low level functions usb_read() and usb_write() and more functions as static * use cmd_receive() in bootrom.c and appmain.c * remove unused memory wasting csrTab[100] in usb_cdc.c * replace more byte_t by uint8_t * more whitespace fixes
This commit is contained in:
parent
72622d6429
commit
867e10a5fd
23 changed files with 98 additions and 195 deletions
|
@ -6,17 +6,15 @@
|
|||
// Main code for the bootloader
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <proxmark3.h>
|
||||
#include "proxmark3.h"
|
||||
#include "usb_cdc.h"
|
||||
#include "cmd.h"
|
||||
//#include "usb_hid.h"
|
||||
|
||||
void DbpString(char *str) {
|
||||
byte_t len = 0;
|
||||
uint8_t len = 0;
|
||||
while (str[len] != 0x00) {
|
||||
len++;
|
||||
}
|
||||
cmd_send(CMD_DEBUG_PRINT_STRING,len,0,0,(byte_t*)str,len);
|
||||
cmd_send(CMD_DEBUG_PRINT_STRING,len,0,0,(uint8_t*)str,len);
|
||||
}
|
||||
|
||||
struct common_area common_area __attribute__((section(".commonarea")));
|
||||
|
@ -89,15 +87,10 @@ static void Fatal(void)
|
|||
for(;;);
|
||||
}
|
||||
|
||||
void UsbPacketReceived(uint8_t *packet, int len) {
|
||||
void UsbPacketReceived(UsbCommand *c) {
|
||||
int i, dont_ack=0;
|
||||
UsbCommand* c = (UsbCommand *)packet;
|
||||
volatile uint32_t *p;
|
||||
|
||||
if(len != sizeof(UsbCommand)) {
|
||||
Fatal();
|
||||
}
|
||||
|
||||
uint32_t arg0 = (uint32_t)c->arg[0];
|
||||
|
||||
switch(c->cmd) {
|
||||
|
@ -199,21 +192,17 @@ static void flash_mode(int externally_entered)
|
|||
start_addr = 0;
|
||||
end_addr = 0;
|
||||
bootrom_unlocked = 0;
|
||||
byte_t rx[sizeof(UsbCommand)];
|
||||
size_t rx_len;
|
||||
UsbCommand rx;
|
||||
|
||||
usb_enable();
|
||||
for (volatile size_t i=0; i<0x100000; i++) {};
|
||||
usb_enable();
|
||||
for (volatile size_t i=0; i<0x100000; i++) {};
|
||||
|
||||
for(;;) {
|
||||
WDT_HIT();
|
||||
|
||||
if (usb_poll()) {
|
||||
rx_len = usb_read(rx,sizeof(UsbCommand));
|
||||
if (rx_len) {
|
||||
UsbPacketReceived(rx,rx_len);
|
||||
}
|
||||
}
|
||||
if (cmd_receive(&rx)) {
|
||||
UsbPacketReceived(&rx);
|
||||
}
|
||||
|
||||
if(!externally_entered && !BUTTON_PRESS()) {
|
||||
/* Perform a reset to leave flash mode */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue