Skip to content

Commit

Permalink
mio168 sd card support
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Dec 11, 2020
1 parent a00415a commit 13b3835
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
19 changes: 15 additions & 4 deletions src/eez/modules/dib-mio168/dib-mio168.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ struct Mio168Module : public Module {
TestResult testResult = TEST_NONE;
bool synchronized = false;
int numCrcErrors = 0;
int numTransferErrors = 0;
uint8_t input[sizeof(FromSlaveToMaster)];
uint8_t output[sizeof(FromSlaveToMaster)];
bool spiReady = false;
Expand Down Expand Up @@ -1039,6 +1040,7 @@ struct Mio168Module : public Module {
if (bp3c::comm::masterSynchro(slotIndex)) {
synchronized = true;
numCrcErrors = 0;
numTransferErrors = 0;
testResult = TEST_OK;
#ifdef EEZ_PLATFORM_SIMULATOR
sendMessageToLowPriorityThread(THREAD_MESSAGE_FS_DRIVER_LINK, slotIndex, 0);
Expand Down Expand Up @@ -1136,6 +1138,7 @@ struct Mio168Module : public Module {
}

numCrcErrors = 0;
numTransferErrors = 0;

FromSlaveToMaster &data = (FromSlaveToMaster &)*input;

Expand Down Expand Up @@ -1167,15 +1170,23 @@ struct Mio168Module : public Module {
return true;
} else {
if (status == bp3c::comm::TRANSFER_STATUS_CRC_ERROR) {
if (++numCrcErrors >= 10) {
numCrcErrors++;
if (numCrcErrors >= 10) {
event_queue::pushEvent(event_queue::EVENT_ERROR_SLOT1_CRC_CHECK_ERROR + slotIndex);
synchronized = false;
testResult = TEST_FAILED;
} else {
DebugTrace("Slot %d CRC %d\n", slotIndex + 1, numCrcErrors);
} else if (numCrcErrors > 5) {
DebugTrace("Slot %d CRC error no. %d\n", slotIndex + 1, numCrcErrors);
}
} else {
DebugTrace("Slot %d SPI transfer error %d\n", slotIndex + 1, status);
numTransferErrors++;
if (numTransferErrors >= 10) {
event_queue::pushEvent(event_queue::EVENT_ERROR_SLOT1_SYNC_ERROR + slotIndex);
synchronized = false;
testResult = TEST_FAILED;
} else if (numTransferErrors > 5) {
DebugTrace("Slot %d SPI transfer error %d no. %d\n", slotIndex + 1, status, numTransferErrors);
}
}

return false;
Expand Down
27 changes: 26 additions & 1 deletion src/eez/modules/mcu/ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,32 @@ void releaseInputBuffer() {

int writeBuffer(const char *buffer, uint32_t length) {
#if defined(EEZ_PLATFORM_STM32)
netconn_write(g_tcpClientConnection, (void *)buffer, (uint16_t)length, NETCONN_COPY);
if (length <= 1024) {
static const size_t NUM_BUFFERS = 4;
static uint8_t g_buffers[NUM_BUFFERS][1024];
static bool g_isBufferUsed[NUM_BUFFERS];

size_t i;
for (i = 0; i < NUM_BUFFERS; i++) {
if (!g_isBufferUsed[i]) {
memcpy(&g_buffers[i][0], buffer, length);
netconn_write(g_tcpClientConnection, (void *)&g_buffers[i][0], (uint16_t)length, NETCONN_NOCOPY);
g_isBufferUsed[i] = true;
break;
}
}

if (i == NUM_BUFFERS) {
netconn_write(g_tcpClientConnection, (void *)buffer, (uint16_t)length, NETCONN_COPY);

for (size_t i = 0; i < NUM_BUFFERS; i++) {
g_isBufferUsed[i] = false;
}
}
} else {
netconn_write(g_tcpClientConnection, (void *)buffer, (uint16_t)length, NETCONN_COPY);
}

return length;
#endif

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2F62501ED4689FB349E356AB974DBE57=6324EFC706C094AE3B0AEB00227A953C
8DF89ED150041C4CBC7CB9A9CAA90856=6324EFC706C094AE3B0AEB00227A953C
DC22A860405A8BF2F2C095E5B6529F12=C8E89020F1502089B9D4C78CEB9BD12A
2F62501ED4689FB349E356AB974DBE57=618266508428BDF06C84712473DD5FAA
8DF89ED150041C4CBC7CB9A9CAA90856=618266508428BDF06C84712473DD5FAA
DC22A860405A8BF2F2C095E5B6529F12=42CF0666AD1D078F9BC5A8F2E0EF7764
eclipse.preferences.version=1

0 comments on commit 13b3835

Please sign in to comment.