despagetizace
This commit is contained in:
parent
e0e9239489
commit
9f238310f1
2 changed files with 446 additions and 432 deletions
|
@ -188,19 +188,7 @@ void cdc_class::init() {
|
||||||
USBFS_Device_Init( true );
|
USBFS_Device_Init( true );
|
||||||
while (!USBFS_DevEnumStatus);
|
while (!USBFS_DevEnumStatus);
|
||||||
}
|
}
|
||||||
|
__always_inline void cdc_class::InTokenHandler(const uint8_t intst) {
|
||||||
void cdc_class::cdc_irq() {
|
|
||||||
uint8_t intflag, intst, errflag;
|
|
||||||
uint16_t len;
|
|
||||||
//uint32_t baudrate;
|
|
||||||
|
|
||||||
intflag = USBFSD->INT_FG;
|
|
||||||
intst = USBFSD->INT_ST;
|
|
||||||
|
|
||||||
if( intflag & USBFS_UIF_TRANSFER ) {
|
|
||||||
switch (intst & USBFS_UIS_TOKEN_MASK) {
|
|
||||||
/* data-in stage processing */
|
|
||||||
case USBFS_UIS_TOKEN_IN:
|
|
||||||
switch ( intst & ( USBFS_UIS_TOKEN_MASK | USBFS_UIS_ENDP_MASK ) ) {
|
switch ( intst & ( USBFS_UIS_TOKEN_MASK | USBFS_UIS_ENDP_MASK ) ) {
|
||||||
/* end-point 0 data in interrupt */
|
/* end-point 0 data in interrupt */
|
||||||
case USBFS_UIS_TOKEN_IN | DEF_UEP0:
|
case USBFS_UIS_TOKEN_IN | DEF_UEP0:
|
||||||
|
@ -212,19 +200,17 @@ void cdc_class::cdc_irq() {
|
||||||
} else {
|
} else {
|
||||||
/* Standard request endpoint 0 Data upload */
|
/* Standard request endpoint 0 Data upload */
|
||||||
switch( USBFS_SetupReqCode ) {
|
switch( USBFS_SetupReqCode ) {
|
||||||
case USB_GET_DESCRIPTOR:
|
case USB_GET_DESCRIPTOR: {
|
||||||
len = USBFS_SetupReqLen >= DEF_USBD_UEP0_SIZE ? DEF_USBD_UEP0_SIZE : USBFS_SetupReqLen;
|
const uint16_t len = USBFS_SetupReqLen >= DEF_USBD_UEP0_SIZE ? DEF_USBD_UEP0_SIZE : USBFS_SetupReqLen;
|
||||||
memcpy( USBFS_EP0_Buf, pUSBFS_Descr, len );
|
memcpy( USBFS_EP0_Buf, pUSBFS_Descr, len );
|
||||||
USBFS_SetupReqLen -= len;
|
USBFS_SetupReqLen -= len;
|
||||||
pUSBFS_Descr += len;
|
pUSBFS_Descr += len;
|
||||||
USBFSD->UEP0_TX_LEN = len;
|
USBFSD->UEP0_TX_LEN = len;
|
||||||
USBFSD->UEP0_TX_CTRL ^= USBFS_UEP_T_TOG;
|
USBFSD->UEP0_TX_CTRL ^= USBFS_UEP_T_TOG;
|
||||||
break;
|
} break;
|
||||||
|
|
||||||
case USB_SET_ADDRESS:
|
case USB_SET_ADDRESS:
|
||||||
USBFSD->DEV_ADDR = (USBFSD->DEV_ADDR & USBFS_UDA_GP_BIT) | USBFS_DevAddr;
|
USBFSD->DEV_ADDR = (USBFSD->DEV_ADDR & USBFS_UDA_GP_BIT) | USBFS_DevAddr;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -249,14 +235,14 @@ void cdc_class::cdc_irq() {
|
||||||
default :
|
default :
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
__always_inline void cdc_class::OutTokenHandler(const uint8_t intst) {
|
||||||
/* data-out stage processing */
|
uint16_t len;
|
||||||
case USBFS_UIS_TOKEN_OUT:
|
|
||||||
switch ( intst & ( USBFS_UIS_TOKEN_MASK | USBFS_UIS_ENDP_MASK ) ) {
|
switch ( intst & ( USBFS_UIS_TOKEN_MASK | USBFS_UIS_ENDP_MASK ) ) {
|
||||||
/* end-point 0 data out interrupt */
|
/* end-point 0 data out interrupt */
|
||||||
case USBFS_UIS_TOKEN_OUT | DEF_UEP0:
|
case USBFS_UIS_TOKEN_OUT | DEF_UEP0:
|
||||||
len = USBFSD->RX_LEN;
|
len = USBFSD->RX_LEN;
|
||||||
|
(void) len;
|
||||||
if ( intst & USBFS_UIS_TOG_OK ) {
|
if ( intst & USBFS_UIS_TOG_OK ) {
|
||||||
if ( ( USBFS_SetupReqType & USB_REQ_TYP_MASK ) != USB_REQ_TYP_STANDARD ) {
|
if ( ( USBFS_SetupReqType & USB_REQ_TYP_MASK ) != USB_REQ_TYP_STANDARD ) {
|
||||||
/* Non-standard request end-point 0 Data download */
|
/* Non-standard request end-point 0 Data download */
|
||||||
|
@ -312,10 +298,10 @@ void cdc_class::cdc_irq() {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
void cdc_class::SetupTokenHandler() {
|
||||||
/* Setup stage processing */
|
uint8_t errflag;
|
||||||
case USBFS_UIS_TOKEN_SETUP:
|
uint16_t len;
|
||||||
USBFSD->UEP0_TX_CTRL = USBFS_UEP_T_TOG|USBFS_UEP_T_RES_NAK;
|
USBFSD->UEP0_TX_CTRL = USBFS_UEP_T_TOG|USBFS_UEP_T_RES_NAK;
|
||||||
USBFSD->UEP0_RX_CTRL = USBFS_UEP_R_TOG|USBFS_UEP_R_RES_NAK;
|
USBFSD->UEP0_RX_CTRL = USBFS_UEP_R_TOG|USBFS_UEP_R_RES_NAK;
|
||||||
/* Store All Setup Values */
|
/* Store All Setup Values */
|
||||||
|
@ -613,12 +599,35 @@ void cdc_class::cdc_irq() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
__always_inline void cdc_class::TransferHandler() {
|
||||||
|
const uint8_t intst = USBFSD->INT_ST;
|
||||||
|
|
||||||
|
switch (intst & USBFS_UIS_TOKEN_MASK) {
|
||||||
|
/* data-in stage processing */
|
||||||
|
case USBFS_UIS_TOKEN_IN:
|
||||||
|
InTokenHandler(intst);
|
||||||
|
break;
|
||||||
|
/* data-out stage processing */
|
||||||
|
case USBFS_UIS_TOKEN_OUT:
|
||||||
|
OutTokenHandler(intst);
|
||||||
|
break;
|
||||||
|
/* Setup stage processing */
|
||||||
|
case USBFS_UIS_TOKEN_SETUP:
|
||||||
|
SetupTokenHandler();
|
||||||
|
break;
|
||||||
default :
|
default :
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
USBFSD->INT_FG = USBFS_UIF_TRANSFER;
|
USBFSD->INT_FG = USBFS_UIF_TRANSFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cdc_class::cdc_irq() {
|
||||||
|
const uint8_t intflag = USBFSD->INT_FG;
|
||||||
|
|
||||||
|
if( intflag & USBFS_UIF_TRANSFER ) {
|
||||||
|
TransferHandler ();
|
||||||
} else if( intflag & USBFS_UIF_BUS_RST ) {
|
} else if( intflag & USBFS_UIF_BUS_RST ) {
|
||||||
/* usb reset interrupt processing */
|
/* usb reset interrupt processing */
|
||||||
USBFS_DevConfig = 0;
|
USBFS_DevConfig = 0;
|
||||||
|
@ -648,19 +657,20 @@ void cdc_class::cdc_irq() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void cdc_class::TxDataDeal() {
|
void cdc_class::TxDataDeal() {
|
||||||
/* Asi by to mělo fungovat nějak přes frontu, ale zatím nevím jak to nastartovat */
|
/* Asi by to mělo fungovat nějak přes frontu, ale zatím nevím jak to nastartovat, nepoužito */
|
||||||
}
|
}
|
||||||
|
/* Pozor - funkce je blokující, lze použít jen v hlavní smyčce programu, ne v přerušení */
|
||||||
uint32_t cdc_class::Down (const char * data, const uint32_t len) {
|
uint32_t cdc_class::Down (const char * data, const uint32_t len) {
|
||||||
if ((!Ready) or (!USBFS_DevEnumStatus)) return 0;
|
if ((!Ready) or (!USBFS_DevEnumStatus)) return 0;
|
||||||
uint32_t rem = len;
|
uint32_t rem = len;
|
||||||
const uint32_t max = 64;
|
const uint32_t max = DEF_USBD_ENDP3_SIZE;
|
||||||
const uint8_t * ptr = reinterpret_cast<const uint8_t*> (data);
|
const uint8_t * ptr = reinterpret_cast<const uint8_t*> (data);
|
||||||
delay_us(5'000); // zde se musí počkat, nevím proč, ale jinak to nechodí
|
// zde se musí počkat, nevím proč, ale jinak to nechodí
|
||||||
|
delay_us(1'000); // 1ms stačí pro odchod paketu po USB
|
||||||
while (rem) {
|
while (rem) {
|
||||||
const uint32_t chunk = rem > max ? max : rem;
|
const uint32_t chunk = rem > max ? max : rem;
|
||||||
if (USBFS_Endp_DataUp (DEF_UEP3, ptr, chunk, DEF_UEP_CPY_LOAD)) {
|
if (USBFS_Endp_DataUp (DEF_UEP3, ptr, chunk, DEF_UEP_CPY_LOAD)) {
|
||||||
delay_us(1000);
|
delay_us(1'000); // čekej dokud je USBFS_Endp_Busy
|
||||||
} else {
|
} else {
|
||||||
ptr += chunk;
|
ptr += chunk;
|
||||||
rem -= chunk;
|
rem -= chunk;
|
||||||
|
|
|
@ -88,6 +88,10 @@ class cdc_class : public BaseLayer {
|
||||||
void USBFS_Device_Endp_Init ();
|
void USBFS_Device_Endp_Init ();
|
||||||
uint8_t USBFS_Endp_DataUp(uint8_t endp, const uint8_t *pbuf, uint16_t len, uint8_t mod);
|
uint8_t USBFS_Endp_DataUp(uint8_t endp, const uint8_t *pbuf, uint16_t len, uint8_t mod);
|
||||||
void TxDataDeal ();
|
void TxDataDeal ();
|
||||||
|
void TransferHandler ();
|
||||||
|
void InTokenHandler (const uint8_t intst);
|
||||||
|
void OutTokenHandler (const uint8_t intst);
|
||||||
|
void SetupTokenHandler ();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CDC_CLASS_H
|
#endif // CDC_CLASS_H
|
||||||
|
|
Loading…
Reference in a new issue