You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
7 years ago
|
//
|
||
|
// Created by MightyPork on 2017/11/21.
|
||
|
//
|
||
|
// TinyFrame integration
|
||
|
//
|
||
|
|
||
|
#include "platform.h"
|
||
|
#include "task_main.h"
|
||
|
|
||
|
#include "USB/usbd_cdc_if.h"
|
||
|
#include "TinyFrame.h"
|
||
|
|
||
|
extern osSemaphoreId semVcomTxReadyHandle;
|
||
|
extern osMutexId mutTinyFrameTxHandle;
|
||
|
|
||
|
void TF_WriteImpl(TinyFrame *tf, const uint8_t *buff, size_t len)
|
||
|
{
|
||
|
(void) tf;
|
||
|
#define CHUNK 64 // same as TF_SENDBUF_LEN, so we should always have only one run of the loop
|
||
|
int32_t total = (int32_t) len;
|
||
|
while (total > 0) {
|
||
|
assert_param(osOK == osSemaphoreWait(semVcomTxReadyHandle, 5000));
|
||
|
assert_param(USBD_OK == CDC_Transmit_FS((uint8_t *) buff, (uint16_t) MIN(total, CHUNK)));
|
||
|
buff += CHUNK;
|
||
|
total -= CHUNK;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/** Claim the TX interface before composing and sending a frame */
|
||
|
void TF_ClaimTx(TinyFrame *tf)
|
||
|
{
|
||
|
(void) tf;
|
||
|
assert_param(osThreadGetId() != tskMainHandle);
|
||
|
assert_param(!inIRQ());
|
||
|
|
||
|
assert_param(osOK == osMutexWait(mutTinyFrameTxHandle, 5000));
|
||
|
}
|
||
|
|
||
|
/** Free the TX interface after composing and sending a frame */
|
||
|
void TF_ReleaseTx(TinyFrame *tf)
|
||
|
{
|
||
|
(void) tf;
|
||
|
assert_param(osOK == osMutexRelease(mutTinyFrameTxHandle));
|
||
|
}
|