DIO and Port Overview

Micael Coutinho,autosarbswdio

Being able to read and write digital inputs and outputs are among basic microcontroller functionalities. Learn how you can use DIO and Port to this goal

One of the simplest functionalities of a microcontroller is to read and write digital inputs and outputs. In Autosar, this functionality is splitted between two modules: DIO and Port. With DIO, you can read and write from / to pins, ports and channel groups (the differences between them will be obvious in a few moments, hang on). With Port, you can configure the pins to accomplish this goal. In essence, you need both together, and they are an integral part of the MCAL (Microcontroller Abstraction Layer).

So, let's look at the modules one by one, starting with the DIO. It provides you basic functionality to read and write pins and ports synchronously. Since the pins are configured directly on the Port driver, this is module does not contain initialization or configuration. Regarding how it's used in the Autosar layered architecture, you would develop an I/O Hardware Abstraction layer component to abstract this functionality to the upper layers. If you need more information on this type of Software Component, you can visit our article Types of Software Components (opens in a new tab). You can take a look below on where the DIO (and Port, also) are situated in the layered architecture and hot they relate to the hardware itself:

DIO and Port location in the architecture, as per Autosar Specification { w: 732, h: 885 }

DIO and Port location in the architecture, as per Autosar Specification

Regarding the APIs available for DIO, they are what you would expect for its functionality:

Now, that we got the DIO out of the way, let's focus on the Port module. As said, Port is the place where you configure all your inputs and outputs. This functionality, of course, is not limited to be used by the DIO. Sometimes, you want to configure pins as analog (which you can then use with the ADC. We'll cover that module one day), or one of the special functionalities, such as CAN, SPI, PWM, among others.

As such, Port contains an init function, Port_Init, which initializes all ports and pins. It should be called before the initialization of other MCAL modules, in order to prevent undefined behavior. The main configurations you will find on Port are: pin direction, initial value, if a direction / mode change is allowed during runtime, slew rate, internal pull-ups, input thresholds (3.3V or 5V, normally), mode (push-pull or open drain) and the type of readback support (pin level or output register value).

Aside from the Port_Init function, there are more APIs you will find relevant. Two of them are:

Alright, that is all for today! If you want to learn more about the MCAL drivers in Autosar, we have recently covered the SPI module in Autosar, which you can find in the article SPI Overview (opens in a new tab). We will also cover other modules soon, so make sure you stay tuned, in order to not miss anything. It will for sure help you become a better automotive software engineer.

Author: Micael Coutinho (opens in a new tab)

References:

© AutosarToday —@LinkedIn