9 years, 2 months ago.

#include rtos.h causing Timer problems?

Hi, I have this simple I/O code, which I'm trying to change to a threaded implementation.

=

#include "mbed.h"
#include "MODSERIAL.h"

MODSERIAL In(p13, p14); // serial object to read data coming in
MODSERIAL Out(p9, p10); // serial object to send data
MODSERIAL pc(USBTX, USBRX);
Timer dbg;
int dataIn[32];
int dataOut[32];

int main()
{
    dbg.start();
    In.baud(921600);
    Out.baud(921600);
    pc.baud(9600);
    int jj=0;
    float temp;
    while(1) {
        dbg.reset();
        for(int ii=0; ii<32; ii++) {
            Out.putc(ii);
        }
        temp=dbg.read_us();
        pc.printf("Out time: %f, ", temp);
        dbg.reset();
        while(In.readable() && jj<32) {
            dataIn[jj]=In.getc();
            jj++;
        }
        jj=0;
        temp=dbg.read_us();
        pc.printf("In time: %f \r\n", temp);
    }
}

dbg records a time of 330 us at the first print statement, but I've had trouble replicating this on my threaded file; usually it takes 560 us instead. I've been able to get 330 by copying code directly from the original file, but attempting to include rtos.h causes the timer to go back to 560, and it stays that way, even after I comment out the #include statement, leaving the file exactly identical to the previously-working version. Has anyone experienced a similar problem? Thanks!

Be the first to answer this question.