Time unit conversion macros

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: tfAteba, barthess, RoccoMarco, lbednarz, utzig

szmodz
Posts: 11
Joined: Thu Jul 11, 2013 1:07 am
Been thanked: 1 time

Time unit conversion macros

Postby szmodz » Tue Mar 31, 2015 11:02 am

The time unit conversion macros give rather unexpected results when passing 0 as an argument. I know that 0 is not a valid argument for functions accepting systime_t, but the current behavior breaks valid code like this:

Code: Select all

uint32_t ms = 0;
systime_t delta = whatever();
...

if (delta > MS2ST(ms)) blah();


Here's a fix:
https://github.com/szmodz/ChibiOS/commi ... 657e04baec

There's also a bunch of other stuff at:
https://github.com/szmodz/ChibiOS/commits/fixes-3.x

User avatar
Giovanni
Site Admin
Posts: 14704
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1146 times
Been thanked: 960 times

Re: Time unit conversion macros

Postby Giovanni » Tue Mar 31, 2015 11:17 am

OK for the macros, all the other changes would be worth a dedicated thread if changes or tickets if bug fixes.

For example that change about rxfifos what is it meant for?

Giovanni

szmodz
Posts: 11
Joined: Thu Jul 11, 2013 1:07 am
Been thanked: 1 time

Re: Time unit conversion macros

Postby szmodz » Tue Mar 31, 2015 1:53 pm

They probably would be, but I'm swamped with work for the foreseeable future (aren't we all?). Most of the patches are rather simple fixes.

The RX FIFO patch adds a larger receive buffer for UART_RX_IDLE / rxchar_cb mode. It makes the driver less prone to overrun, and the system is not interrupted for each new character. Without the patch, the driver only provides a single character buffer.

It's used like this:

Code: Select all

    static const UARTConfig cfg = {
        uart_txend,
        NULL,
        NULL,
        uart_rxdata,
        uart_rxerr,
        SERBOOT_BRATE,
        0, /*cr1*/
        0, /*cr2*/
        0, /*cr3*/
        ldr.rxfifo,
        sizeof(ldr.rxfifo)
    };

    uartStart(MAIN_UART, &cfg);


Notice the additional struct members at the end. The buffer can be as large as required.

It's implemented using DMA circular buffer mode, DMA Transfer Complete and Half Transfer interrupts, and the USART IDLE interrupt. The receive buffer is drained (meaning, the rxchar_cb callback is called for each new character) when any of those interrupts fires. Perhaps the FIFO should be drained by a dedicated thread. Currently it's done in ISR context.

The patch wasn't thoroughly tested.

I've provided it for reference mostly, you can do whatever you like with the patches.

colin
Posts: 149
Joined: Thu Dec 22, 2011 7:44 pm

Re: Time unit conversion macros

Postby colin » Tue Mar 31, 2015 8:19 pm

This is an example of a situation where Git and GitHub's features that make it easy to share, review, and merge changes would really shine. The author has made some apparently useful changes/fixes to ChibiOS but doesn't have time to formally submit the patches. But it would take only a few seconds to click "Create issue" or "Create pull request", and discussion and review could take place before the maintainer merges the code with a simple "git merge" command. Git is sooooo much nicer than SVN, and it doesn't have to be hard, once you learn a handful of command syntaxes and the terminology like branches, commits, remotes... some day you'll feel ready to switch to Git and then you'll be glad you did, I'm sure. ;)

User avatar
Giovanni
Site Admin
Posts: 14704
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1146 times
Been thanked: 960 times

Re: Time unit conversion macros

Postby Giovanni » Sat Apr 04, 2015 9:19 am

I committed the time conversion macros fixes in RT, NIL and OSAL. I will look also into the other changes.

Giovanni


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 130 guests