Hi Atommann,
Sorry I didn't reply to your email for so long. Thanks for getting involved! I'll reply to the individual questions inline below:
On Wed, Sep 30, 2015 at 03:43:27PM +0800, Atommann wrote:
> DHT22 is a single wire data bus, the timing is critical, so before the
> reading starts I add
> vTaskSuspendAll(); // timing critical start
>
> And
> xTaskResumeAll(); // timing critical ends
> at the end of the reading. Is it the right way to do this (timing
> critical stuff)?
That's the right approach. The best functions to use for this are probably
portENTER_CRITICAL(); // timing critical start
portEXIT_CRITICAL(); // timing critical end
... which is the "FreeRTOS way" of managing critical sections (handles things like recursive entry where a critical section is called inside a critical section, etc.)
The timing you see will be "pretty good", but in esp-open-rtos there is also an NMI exception which (as per the name Non Maskable Interrupt) can't be disabled.[*]
Probably the only thing you can really do from a driver perspective is try to detect when this has happened (ie you see an invalid read response), reocver, and retry.
> BTW, this is the first time I use FreeRTOS and am also not a good C programmer.
> Question: Is there any guideline/framework for how to write device
> drivers for FreeRTOS?
>
> If there is a framework I want to write more drivers.
FreeRTOS itself steers away from "drivers" as a concept, that part's really up to people who implement a FreeRTOS-based system (ie esp-open-rtos in this case).
There are some existing peripherals drivers in extras/i2c and extras/bmp180. Each one is just a single source file and a single header file. So I'm thinking maybe we coordinate those into a single "extras/peripherals" and put all external peripheral drivers in the same place. So a dht22 driver would just be another header file and source file under extras/peripherals.
Would you be interested in submitting it as a contribution? I can help walk you through any steps required.
Neat!
If you're up to it as well, it'd be great to have an example in esp-open-rtos that showed how to push data to
data.sparkfun.com.
Angus