I've got my test code working (as anticipated, as stupid mistake...) and can now log the priority of the executing callback. Turns out you can set it before or after EncoderTool initialisation, it doesn't matter.
@clinker8, do you really mean "instantiation"? That implies you're creating it after your program starts executing, rather than having it defined as a static object...
Darn right you can, and must. Everything with the
remotest chance of taking significant time must be rigorously excluded from your ISRs / callbacks.
Looking back, the code you
posted in #140 looks disturbing, because you're using
print. Never mind that it's (presumably) to a filesystem in PSRAM - you don't really know what's going on under the hood.
- Decide what you want in a log record (encoder value(s), timestamp, error flag etc.)
- Define a
struct with members that can hold one log record
- Define a big enough array of those structs - in PSRAM if needed, the speed really won't matter
- Triggered by something, fill the array with records, probably one record per callback
- Only when it's safe to do so, you can use any Serial port, filesystem,
print, printf etc. to dump out the results for inspection
My test log code looks like this:
C++:
struct logRecord
{
uint32_t cyccnt, quadPos, encPos, priority;
bool wasError;
};
#define NUM_RECORDS (4096*2)
EXTMEM logRecord logRecords[NUM_RECORDS];
volatile int idx = NUM_RECORDS;
void addToLog(uint32_t cyc,uint32_t enc, bool err)
{
if (idx < NUM_RECORDS)
{
logRecords[idx] = {cyc,myQuad.read(),enc,getNVICpriority(),err};
idx++;
}
}
addToLog() is called from either the normal or the error callback, with its
err parameter set appropriately.
My dump function ended up being very terse, with output suitable for putting into a spreadsheet - I often find that a great way to visualise results, filter for errors, etc.