for (int i = 0; i < nbTK; i++) {
Circular_Buffer<float, infoTK[i].echantillonnage> coldJunction_CB[i];
Circular_Buffer<float, infoTK[i].echantillonnage> compensedTemp_CB[i];
}
I havn't played with SD or USB utils so I wouldn't be of much help on that part, but a circular queue you could assign 512 bytes and when it is full via size() you can write that block to the SD or usb I guess. you are limited by the memory obviously and buffers are in powers of 2. You could also manage it with a fixed array in code, if its just appending bytes to an index, but you'll have to manage the indice counter whereas push or popping the queue shifts it in or out, a little less work for you.
typedef struct {
uint8_t type = NO_RD_WR; // Used for CMD_RD_10 or CMD_WR_10 only, else 0.
bool completed;
void *buffer;
msCommandBlockWrapper_t *CBW;
} MSC_transfer_t;
// ---------------------------------------------------------------------------------------------------------
// Read Sectors using queued reads
// ---------------------------------------------------------------------------------------------------------
uint8_t msController::msReadSectors(void *sectorBuffer, const uint32_t BlockAddress, const uint16_t Blocks) {
uint8_t msResult = 0;
#ifdef DBGprint
Serial.printf("msReadSectors()\n");
#endif
uint8_t BlockHi = (Blocks >> 8) & 0xFF;
uint8_t BlockLo = Blocks & 0xFF;
msCommandBlockWrapper_t CommandBlockWrapper = (msCommandBlockWrapper_t)
{
.Signature = CBW_SIGNATURE,
.Tag = ++CBWTag,
.TransferLength = (uint32_t)(Blocks * (uint16_t)512),
.Flags = CMD_DIR_DATA_IN,
.LUN = currentLUN,
.CommandLength = 10,
.CommandData = {CMD_RD_10, 0x00,
(uint8_t)(BlockAddress >> 24),
(uint8_t)(BlockAddress >> 16),
(uint8_t)(BlockAddress >> 8),
(uint8_t)(BlockAddress & 0xFF),
0x00, BlockHi, BlockLo, 0x00}
};
mscTransfer.CBW = &CommandBlockWrapper;
mscTransfer.buffer = sectorBuffer;
mscTransfer.type = CMD_RD_10;
[COLOR="#FF0000"] uint8_t buf[sizeof(MSC_transfer_t)];
memmove(buf, &mscTransfer, sizeof(mscTransfer));
cbamsc.push_back(buf, sizeof(MSC_transfer_t));
cbamsc.list();
Serial.printf("cbamsc.size() = %d\n", cbamsc.size());
cbamsc.pop_front(buf, sizeof(MSC_transfer_t));
memmove(&mscTransfer, buf, sizeof(mscTransfer));
Serial.printf("cbamsc.size() = %d\n", cbamsc.size());[/COLOR]
// msResult = msDispatchTransfer(mscXferEvent);
msResult = msDoCommand(mscTransfer.CBW, mscTransfer.buffer);
//#ifdef DBGprint
Serial.printf("transferIndex = %d\n",transferIndex);
Serial.printf("mscTransfer.completed = %d\n"
,mscTransfer.completed);
//#endif
return msResult;
}
Circular_Buffer<uint8_t, MAX_TRANSFERS,sizeof(msController::MSC_transfer_t)> cbamsc;
Teensy USB MSD testing
Checking for msDrive1
msDrive1 init: OK
msDrive1 is NOT Mounted
connected 1
initialized 1
USB Vendor ID: 0951
USB Product ID: 1666
HUB Number: 0
HUB Port: 0
Device Address: 1
Removable Device: YES
VendorID: Kingston
ProductID: DataTraveler 3.0
RevisionID:
Version: 6
Sector Count: 30218841
Sector size: 512
Disk Capacity: 15472046592 Bytes
Select:
1) Test Sector Read Speed Drive 1
3) Test Sector Write Speed Drive 1 ******** CAUTION!!! DESTROY'S FORMATTING OF DRIVE!! *********
Reading From USB Drive 1
Circular Array Buffer Queue Size: 1 / 10
First Entry: 40 0 0 0 32 0 0 0 144 255 5 32 (12 entries.)
Last Entry: 40 0 0 0 32 0 0 0 144 255 5 32 (12 entries.)
[Indice] [Entries]
0 40 0 0 0 32 0 0 0 144 255 5 32 (12 entries.)
cbamsc.size() = 1
cbamsc.size() = 0
transferIndex = 0
mscTransfer.completed = 1
Circular Array Buffer Queue Size: 1 / 10
First Entry: 40 1 0 0 32 0 0 0 144 255 5 32 (12 entries.)
Last Entry: 40 1 0 0 32 0 0 0 144 255 5 32 (12 entries.)
[Indice] [Entries]
1 40 1 0 0 32 0 0 0 144 255 5 32 (12 entries.)
cbamsc.size() = 1
cbamsc.size() = 0
transferIndex = 0
mscTransfer.completed = 1
Read 131072 bytes in 0.009599 seconds. Speed: 13.654756 MB/s
sizeof(SecBuf[0]) = 1
SecBufSize = 65536
----------------------------------------------------------
pushing back puts your data at the end. popping front pulls data from the front (oldest)
this is why you can do FIFO/LIFO
1 2 3 4 5 6 7 8
push front 9 will become:
9 1 2 3 4 5 6 7 8
push back 6 will become:
9 1 2 3 4 5 6 7 8 6
pop front returns 9, your data becomes:
1 2 3 4 5 6 7 8 6
pop back returns 6, your data becomes:
1 2 3 4 5 6 7 8
#include "circular_buffer.h"
Circular_Buffer<float, 8> k1;
void setup() {
k1.push_front(1.0f);
k1.push_front(2.0f);
k1.push_front(3.0f);
k1.push_front(4.0f);
k1.push_front(5.0f);
k1.push_front(6.0f);
k1.push_front(7.0f);
k1.push_front(8.0f);
k1.push_front(9.0f);
//uint32_t temp = k1.pop_back();
Serial.println(k1.pop_back());
Serial.println(k1.pop_back());
Serial.println(k1.pop_back());
k1.list();
}
void loop() {
// put your main code here, to run repeatedly:
}
9.00
2.00
3.00
Circular Ring Buffer Queue Size: 5 / 8
Indice: [7] [0] [1] [2] [3]
Entries: 9.00 8.00 7.00 6.00 5.00
can you setup a small example i can load to test?
[URL="https://github.com/tonton81/Circular_Buffer/commit/6ec0bc149ac4b40a71b9b4aec26ccb11c34da917#diff-05031bd28244fb1791d9704abd4df93cb9b7b7f89a9e373b7a857ca91373bb87"]https://github.com/tonton81/Circular_Buffer/commit/6ec0bc149ac4b40a71b9b4aec26ccb11c34da917#diff-05031bd28244fb1791d9704abd4df93cb9b7b7f89a9e373b7a857ca91373bb87[/URL]
2.00
3.00
4.00
Circular Ring Buffer Queue Size: 5 / 8
Indice: [7] [0] [1] [2] [3]
Entries: 9.00 8.00 7.00 6.00 5.00
Fixed:
Code:[URL="https://github.com/tonton81/Circular_Buffer/commit/6ec0bc149ac4b40a71b9b4aec26ccb11c34da917#diff-05031bd28244fb1791d9704abd4df93cb9b7b7f89a9e373b7a857ca91373bb87"]https://github.com/tonton81/Circular_Buffer/commit/6ec0bc149ac4b40a71b9b4aec26ccb11c34da917#diff-05031bd28244fb1791d9704abd4df93cb9b7b7f89a9e373b7a857ca91373bb87[/URL]
Code:2.00 3.00 4.00 Circular Ring Buffer Queue Size: 5 / 8 Indice: [7] [0] [1] [2] [3] Entries: 9.00 8.00 7.00 6.00 5.00