What is Hardware abstraction Layer and and how to implement it?

I read on some thread that we can create our virtual photon/core by using HAL. How can we do it ? I didnot really understood the answers given there. Anybody please tell me in simple terms. Sorry If i sounds dumb.

A HAL is basically just a layer of abstraction to the hardware. It is a way to structure the code so that, in theory, you can run it on any hardware just by providing some necessary functions for your specific hardware. The core logic is contained in a set of files that don’t directly deal with the hardware.

For example, let’s say you wanted to abstract away setting of a GPIO pin with the digitalWrite function. Instead of creating a function that looks like this:
void digitalWrite(int pin) {
//Do some very hardware specific stuff, like call the STM32 library directly
}

You create a function like this:
void digitalWrite(int pin) {
HAL_digital_write(pin);
}

In a different file, perhaps called stm32_gpio_hal.c, you then have this function:
void HAL_digital_write(int pin) {
//Do some very hardware specific stuff, like call the STM32 library directly
}

Now, at compile time, you can choose which file to use based on some settings, like in a Makefile, and you can target a specific hardware platform. So if you wanted to port this over to, say, the nrf51, you would just create a HAL_digital_write function in another library, say called nrf51_gpio_hal.c, that calls the nrf51 libraries for that hardware, and you’d be good. At compile time, the right function gets compiled and used based on what hardware you are targeting.

I think what you are referring to is that Spark internally created a way to run the Core/Photon FW on a regular PC. They implemented the necessary libraries to run the FW as a desktop compiled application rather embedded FW. This is, I believe, an internal tool for their testing and not publicly supported. You can try and compile it as others have, but you may have issues.

5 Likes

Thank you very much for you time. I understood it very well now.

1 Like

@alok, @eely22 is completely correct unless you are talking about the HAL 9000, in which case, that is totally different :stuck_out_tongue:

3 Likes

Now that would be interesting … :sunglasses:

1 Like

“Run the Core/Photon FW on a regular PC”…
A software emulation of a Photon would be VERY valuable to me!

I wrote one once for a Computer Automation computer for an electron microscope… but that was simple compared to the Photon. I think I would be out of my league.