Do not allocate memory for LUA Rx fifo from the USB ISR
Rather use explicit allocation when the serial is set as the on-demand method that was used previously.
This commit is contained in:
@@ -103,13 +103,25 @@ static int luaRxFifoGetByte(void*, uint8_t* data)
|
|||||||
return luaRxFifo->pop(*data);
|
return luaRxFifo->pop(*data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void luaReceiveData(uint8_t* buf, uint32_t len)
|
void luaAllocRxFifo()
|
||||||
{
|
{
|
||||||
if (!luaRxFifo) {
|
if (!luaRxFifo) {
|
||||||
luaRxFifo = new Fifo<uint8_t, LUA_FIFO_SIZE>();
|
auto fifo = new Fifo<uint8_t, LUA_FIFO_SIZE>();
|
||||||
|
luaRxFifo = fifo;
|
||||||
luaSetGetSerialByte(nullptr, luaRxFifoGetByte);
|
luaSetGetSerialByte(nullptr, luaRxFifoGetByte);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void luaFreeRxFifo()
|
||||||
|
{
|
||||||
|
auto fifo = luaRxFifo;
|
||||||
|
luaSetGetSerialByte(nullptr, nullptr);
|
||||||
|
luaRxFifo = nullptr;
|
||||||
|
delete(fifo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void luaReceiveData(uint8_t* buf, uint32_t len)
|
||||||
|
{
|
||||||
if (luaRxFifo) {
|
if (luaRxFifo) {
|
||||||
while(len--) luaRxFifo->push(*buf++);
|
while(len--) luaRxFifo->push(*buf++);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,10 @@ extern "C" {
|
|||||||
|
|
||||||
// LUA serial connection
|
// LUA serial connection
|
||||||
#define LUA_FIFO_SIZE 256
|
#define LUA_FIFO_SIZE 256
|
||||||
|
void luaAllocRxFifo();
|
||||||
|
void luaFreeRxFifo();
|
||||||
void luaReceiveData(uint8_t* buf, uint32_t len);
|
void luaReceiveData(uint8_t* buf, uint32_t len);
|
||||||
|
|
||||||
void luaSetSendCb(void* ctx, void (*cb)(void*, uint8_t));
|
void luaSetSendCb(void* ctx, void (*cb)(void*, uint8_t));
|
||||||
void luaSetGetSerialByte(void* ctx, int (*fct)(void*, uint8_t*));
|
void luaSetGetSerialByte(void* ctx, int (*fct)(void*, uint8_t*));
|
||||||
|
|
||||||
|
|||||||
@@ -148,7 +148,10 @@ static void serialSetCallBacks(int mode, void* ctx, const etx_serial_port_t* por
|
|||||||
if (getByte) {
|
if (getByte) {
|
||||||
luaSetGetSerialByte(ctx, getByte);
|
luaSetGetSerialByte(ctx, getByte);
|
||||||
} else if (setRxCb) {
|
} else if (setRxCb) {
|
||||||
|
luaAllocRxFifo();
|
||||||
setRxCb(ctx, luaReceiveData);
|
setRxCb(ctx, luaReceiveData);
|
||||||
|
} else {
|
||||||
|
luaFreeRxFifo();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user