chg: waiting for shiftregisters (@pwpiwi)

This commit is contained in:
iceman1001 2020-03-31 09:44:36 +02:00
commit 392da6400a

View file

@ -473,10 +473,12 @@ static void SpinDelayUs(int us) {
} }
} }
//*---------------------------------------------------------------------------- /*
//* \fn usb_disable *----------------------------------------------------------------------------
//* \brief This function deactivates the USB device * \fn usb_disable
//*---------------------------------------------------------------------------- * \brief This function deactivates the USB device
*----------------------------------------------------------------------------
*/
void usb_disable() { void usb_disable() {
// Disconnect the USB device // Disconnect the USB device
AT91C_BASE_PIOA->PIO_ODR = GPIO_USB_PU; AT91C_BASE_PIOA->PIO_ODR = GPIO_USB_PU;
@ -487,10 +489,12 @@ void usb_disable() {
} }
} }
//*---------------------------------------------------------------------------- /*
//* \fn usb_enable *----------------------------------------------------------------------------
//* \brief This function Activates the USB device * \fn usb_enable
//*---------------------------------------------------------------------------- * \brief This function Activates the USB device
*----------------------------------------------------------------------------
*/
void usb_enable() { void usb_enable() {
// Set the PLL USB Divider // Set the PLL USB Divider
AT91C_BASE_CKGR->CKGR_PLLR |= AT91C_CKGR_USBDIV_1 ; AT91C_BASE_CKGR->CKGR_PLLR |= AT91C_CKGR_USBDIV_1 ;
@ -523,10 +527,12 @@ void usb_enable() {
AT91C_BASE_PIOA->PIO_OER = GPIO_USB_PU; AT91C_BASE_PIOA->PIO_OER = GPIO_USB_PU;
} }
//*---------------------------------------------------------------------------- /*
//* \fn usb_check *----------------------------------------------------------------------------
//* \brief Test if the device is configured and handle enumeration * \fn usb_check
//*---------------------------------------------------------------------------- * \brief Test if the device is configured and handle enumeration
*----------------------------------------------------------------------------
*/
static int usb_reconnect = 0; static int usb_reconnect = 0;
static int usb_configured = 0; static int usb_configured = 0;
void SetUSBreconnect(int value) { void SetUSBreconnect(int value) {
@ -612,10 +618,12 @@ bool usb_poll_validate_length() {
return ((pUdp->UDP_CSR[AT91C_EP_OUT] & AT91C_UDP_RXBYTECNT) >> 16) > 0; return ((pUdp->UDP_CSR[AT91C_EP_OUT] & AT91C_UDP_RXBYTECNT) >> 16) > 0;
} }
//*---------------------------------------------------------------------------- /*
//* \fn usb_read *----------------------------------------------------------------------------
//* \brief Read available data from Endpoint 1 OUT (host to device) * \fn usb_read
//*---------------------------------------------------------------------------- * \brief Read available data from Endpoint 1 OUT (host to device)
*----------------------------------------------------------------------------
*/
uint32_t usb_read(uint8_t *data, size_t len) { uint32_t usb_read(uint8_t *data, size_t len) {
if (len == 0) return 0; if (len == 0) return 0;
@ -709,10 +717,12 @@ uint32_t usb_read_ng(uint8_t *data, size_t len) {
return nbBytesRcv; return nbBytesRcv;
} }
//*---------------------------------------------------------------------------- /*
//* \fn usb_write *----------------------------------------------------------------------------
//* \brief Send through endpoint 2 (device to host) * \fn usb_write
//*---------------------------------------------------------------------------- * \brief Send through endpoint 2 (device to host)
*----------------------------------------------------------------------------
*/
int usb_write(const uint8_t *data, const size_t len) { int usb_write(const uint8_t *data, const size_t len) {
if (!len) return PM3_EINVARG; if (!len) return PM3_EINVARG;
@ -733,6 +743,7 @@ int usb_write(const uint8_t *data, const size_t len) {
} }
UDP_SET_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXPKTRDY); UDP_SET_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXPKTRDY);
while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXPKTRDY) {};
while (length) { while (length) {
// Send next chunk // Send next chunk
@ -750,8 +761,9 @@ int usb_write(const uint8_t *data, const size_t len) {
UDP_CLEAR_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXCOMP); UDP_CLEAR_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXCOMP);
while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) {}; while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) {};
UDP_SET_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXPKTRDY);
UDP_SET_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXPKTRDY);
while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXPKTRDY) {};
} }
// Wait for the end of transfer // Wait for the end of transfer
@ -762,13 +774,25 @@ int usb_write(const uint8_t *data, const size_t len) {
UDP_CLEAR_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXCOMP); UDP_CLEAR_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXCOMP);
while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) {}; while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) {};
if (len % AT91C_EP_IN_SIZE == 0) {
UDP_SET_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXPKTRDY);
while (!(pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP)) {};
UDP_CLEAR_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXCOMP);
while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) {};
}
return PM3_SUCCESS; return PM3_SUCCESS;
} }
//*---------------------------------------------------------------------------- /*
//* \fn AT91F_USB_SendData *----------------------------------------------------------------------------
//* \brief Send Data through the control endpoint * \fn AT91F_USB_SendData
//*---------------------------------------------------------------------------- * \brief Send Data through the control endpoint
*----------------------------------------------------------------------------
*/
void AT91F_USB_SendData(AT91PS_UDP pUdp, const char *pData, uint32_t length) { void AT91F_USB_SendData(AT91PS_UDP pUdp, const char *pData, uint32_t length) {
AT91_REG csr; AT91_REG csr;