/* ** =================================================================== ** Method : CDC1_App_Task (component FSL_USB_CDC_Device) ** Description : ** Application task to be called periodically from the main ** task. ** Parameters : ** NAME - DESCRIPTION ** * txBuf - Pointer to temporary buffer used to ** transmit data over USB. Should be equal or ** greater than the endpoint buffer size. Data ** will be sent in an asynchronous way, so ** make sure the buffer is *not* on the stack. ** This buffer must be available until the ** next transmission. ** txBufSize - Size of the buffer in bytes ** Returns : ** --- - Error code, returns ERR_OK if USB ** enumeration has been finished, error code ** otherwise. ** =================================================================== */ uint8_t CDC1_App_Task(uint8_t *txBuf, size_t txBufSize) { uint8_t i, res; /* device is Kinetis L2K */ CDC1_RunUsbEngine(); /* call the periodic task function */ USB_Class_CDC_Periodic_Task(); /* check whether enumeration is complete or not */ if ((start_app==TRUE) && (start_transactions==TRUE)) { if (Tx1_NofElements()!=0) { i = 0; while(i<txBufSize && Tx1_Get(&txBuf[i])==ERR_OK) { i++; } res = CDC1_SendDataBlock(txBuf, i); if (res!=ERR_OK) { return res; } #if 1 /* workaround for problem in USB stack v3.1.1: if last block is 8, 16, 32, 40, 48, ... bytes, it does not get out until the next transfer? */ if ((i%8)==0) { /* workaround: sending a dummy block of zero bytes */ res = CDC1_SendDataBlock(txBuf, 0); if (res!=ERR_OK) { return res; } } #endif } /* if */ return ERR_OK; } else { return ERR_BUSOFF; /* USB bus not available yet */ } }
/****************************************************************************** * * @name TestApp_Task * * @brief Application task function. It is called from the main loop * * @param None * * @return None * ***************************************************************************** * Application task function. It is called from the main loop *****************************************************************************/ void TestApp_Task(void) { #if (defined _MC9S08JE128_H) || (defined _MC9S08JM16_H) || (defined _MC9S08JM60_H) || (defined _MC9S08JS16_H) || (defined _MC9S08MM128_H) if(USB_PROCESS_PENDING()) { USB_Engine(); } #endif /* call the periodic task function */ USB_Class_CDC_Periodic_Task(); /*check whether enumeration is complete or not */ if((start_app==TRUE) && (start_transactions==TRUE)) { Virtual_Com_App(); } }