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 );
|
||||
while (!USBFS_DevEnumStatus);
|
||||
}
|
||||
|
||||
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:
|
||||
__always_inline void cdc_class::InTokenHandler(const uint8_t intst) {
|
||||
switch ( intst & ( USBFS_UIS_TOKEN_MASK | USBFS_UIS_ENDP_MASK ) ) {
|
||||
/* end-point 0 data in interrupt */
|
||||
case USBFS_UIS_TOKEN_IN | DEF_UEP0:
|
||||
|
@ -212,19 +200,17 @@ void cdc_class::cdc_irq() {
|
|||
} else {
|
||||
/* Standard request endpoint 0 Data upload */
|
||||
switch( USBFS_SetupReqCode ) {
|
||||
case USB_GET_DESCRIPTOR:
|
||||
len = USBFS_SetupReqLen >= DEF_USBD_UEP0_SIZE ? DEF_USBD_UEP0_SIZE : USBFS_SetupReqLen;
|
||||
case USB_GET_DESCRIPTOR: {
|
||||
const uint16_t len = USBFS_SetupReqLen >= DEF_USBD_UEP0_SIZE ? DEF_USBD_UEP0_SIZE : USBFS_SetupReqLen;
|
||||
memcpy( USBFS_EP0_Buf, pUSBFS_Descr, len );
|
||||
USBFS_SetupReqLen -= len;
|
||||
pUSBFS_Descr += len;
|
||||
USBFSD->UEP0_TX_LEN = len;
|
||||
USBFSD->UEP0_TX_CTRL ^= USBFS_UEP_T_TOG;
|
||||
break;
|
||||
|
||||
} break;
|
||||
case USB_SET_ADDRESS:
|
||||
USBFSD->DEV_ADDR = (USBFSD->DEV_ADDR & USBFS_UDA_GP_BIT) | USBFS_DevAddr;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -249,14 +235,14 @@ void cdc_class::cdc_irq() {
|
|||
default :
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
/* data-out stage processing */
|
||||
case USBFS_UIS_TOKEN_OUT:
|
||||
}
|
||||
__always_inline void cdc_class::OutTokenHandler(const uint8_t intst) {
|
||||
uint16_t len;
|
||||
switch ( intst & ( USBFS_UIS_TOKEN_MASK | USBFS_UIS_ENDP_MASK ) ) {
|
||||
/* end-point 0 data out interrupt */
|
||||
case USBFS_UIS_TOKEN_OUT | DEF_UEP0:
|
||||
len = USBFSD->RX_LEN;
|
||||
(void) len;
|
||||
if ( intst & USBFS_UIS_TOG_OK ) {
|
||||
if ( ( USBFS_SetupReqType & USB_REQ_TYP_MASK ) != USB_REQ_TYP_STANDARD ) {
|
||||
/* Non-standard request end-point 0 Data download */
|
||||
|
@ -312,10 +298,10 @@ void cdc_class::cdc_irq() {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Setup stage processing */
|
||||
case USBFS_UIS_TOKEN_SETUP:
|
||||
}
|
||||
void cdc_class::SetupTokenHandler() {
|
||||
uint8_t errflag;
|
||||
uint16_t len;
|
||||
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;
|
||||
/* 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 :
|
||||
break;
|
||||
}
|
||||
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 ) {
|
||||
/* usb reset interrupt processing */
|
||||
USBFS_DevConfig = 0;
|
||||
|
@ -648,19 +657,20 @@ void cdc_class::cdc_irq() {
|
|||
}
|
||||
}
|
||||
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) {
|
||||
if ((!Ready) or (!USBFS_DevEnumStatus)) return 0;
|
||||
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);
|
||||
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) {
|
||||
const uint32_t chunk = rem > max ? max : rem;
|
||||
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 {
|
||||
ptr += chunk;
|
||||
rem -= chunk;
|
||||
|
|
|
@ -88,6 +88,10 @@ class cdc_class : public BaseLayer {
|
|||
void USBFS_Device_Endp_Init ();
|
||||
uint8_t USBFS_Endp_DataUp(uint8_t endp, const uint8_t *pbuf, uint16_t len, uint8_t mod);
|
||||
void TxDataDeal ();
|
||||
void TransferHandler ();
|
||||
void InTokenHandler (const uint8_t intst);
|
||||
void OutTokenHandler (const uint8_t intst);
|
||||
void SetupTokenHandler ();
|
||||
};
|
||||
|
||||
#endif // CDC_CLASS_H
|
||||
|
|
Loading…
Reference in a new issue