Page 1 of 1

hal in Arduino

Posted: Fri Apr 18, 2014 10:11 am
by matteo_malosio
Dear all,

I'd like to access to hal functionalities (e.g. RTT2US, halGetCounterFrequency(), ...) but I cannot.

I noticed that in the file

Code: Select all

hal.h

there is

Code: Select all

#ifndef _HAL_H_
#define _HAL_H_

#include "ch.h"

#if 0  // WHG
#include "board.h"
#include "halconf.h"
....................
.....................



It is not clear to me why

Code: Select all

#if 0  // WHG


Do you have any suggestion?
Thank you in advance!

Matteo

Re: hal in Arduino

Posted: Fri Apr 18, 2014 11:01 am
by Tectu
matteo_malosio wrote:It is not clear to me why

Code: Select all

#if 0  // WHG

I couldn't find that one in my /os/hal/include/hal.h, where did you find that? Which ChibiOS/RT version are you using?

Anyway, to answer your question: Many developers do wrap code around an #if 0 macro to exclude code. When the 0 is toggled to a 1 it will be included again. This is pretty much like when you would comment out the whole code block using /* ... */ but this one is simpler to re-enable again.
Another (important) reason why this technique is used is because you cannot have nested multi-line comments. This post explains it pretty well.


~ Tectu

Re: hal in Arduino

Posted: Fri Apr 18, 2014 12:57 pm
by Giovanni
That must be a customization because in the ChibiOS code there are no "#if 0".

halGetCounterFrequency() is an optional API, the AVR HAL does not implement it.

Giovanni