A.Mak
A.Mak

Reputation: 23

interfaces for uncommon features in HAL layer

I am trying to make a layered architecture and apply hardware abstraction using the HAL concept (hardware abstraction layer).
But I have to stick to the common features only between MCUs, in order to make a generic interface that can be portable between different MCUs. So that I won't have to change the upper layer at all when I move to another MCU.
But I won't be able to use costum features that exist in a specific MCU while others don't have it.

So if there is a specific extra feature in a gpio module that exists in a specific MCU and I want to use it but it doesn't exist in HAL (because it's not a common feature). How can I make an interface for it?

Example:
I want to make a HAL that contains standard interface between atmega328p and Dspic33. Dspic33 has a feature in the Gpio which is Internal Pull Down. This feature does not exist in the atmega328p (so I can't include it in the HAL standard interface).
So if I want to use this uncommon feature how am I going to do that?

Upvotes: 1

Views: 202

Answers (1)

Yunnosch
Yunnosch

Reputation: 26753

You can either or all of the following:

  • provide an interface with abstracted semantic parameters, with e.g. the meaning "I want to use internal pull down, if present: yes/no"; on platforms which do not have it, the function would effectively be empty
  • provide a query API, which allows to check whether a feature is available; if it is then the calling code can use it, with implicit knowledge needed on how to do that (this can be done in the shape of a macro, which would allow querying without the knowledge whether the querying API itself exists, via #ifdef; which in turn would allow to skip implementing it on the environments which do not support the feature)
  • combine both, i.e. semantic interface with a return value indicating whether the feature has been successfully applied

Upvotes: 2

Related Questions