Peripheral Drivers(Autosar)

Motive:

  1. To get understanding of what Port Driver in Autosaur MCAL Layer stack do: Done: What is Port Driver in Autosaur?
  2. To get understanding of Different Functions and Data Types in Port Driver Module: Their description, their description with respect to parameters that are send to them, and how are those paramters configured via tool.
  3. How to configure different pins in autosar, using Port Driver Module.
  4. To get familiarity with Usecases and how to use different Port Driver Module APIs in what chronology.

Autosar Documentation blogs:

  1. Understanding AUTOSAR and its Applications in the Automotive Industry (einfochips.com)
  2. AUTOSAR_SWS_BSWGeneral.pdf : This document explains the BSW layer configurtaion

What is Port Driver of Autosar MCAL Layer?

  • Port Driver or Port Module of the MCAL layer is used to initialize and configure the mode of Microcontroller pins.
  • In a microcontroller there are many peripherals like GPIO, ADC, SPI, UART, I2C, PWM, CAN, Ethernet and etc. A single MCU pin have capabilities to be used in multiple peripherals. But in an application, at a time a single MCU pin can be used for only 1 peripheral. The peripheral in which this MCU pin is used for is termed as mode of pin.
  • It is job of Port Module of Autosar MCAL Layer, which configures and initializes the MCU pin for which peripheral that pin has to be used. It is often termed as alternate function setting of a MCU pin.

In addition to the aforementioned features, the PORT Driver also allows for the configuration of pins that are not utilized in an application. For example, if in an application only 2 pins of a microcontroller are used, and let’s say for UART function, the PORT Driver will configure the Port Driver Parameter’s for remaining unused pins. Furthermore, if there are specific pins whose parameters should remain unchanged, such as debugging pins or the crystal oscillator, the PORT Driver has the capability to retain their factory default or bootloader default port driver parameter’s without altering them.

Functional concepts of PORT Driver

In order to effectively utilize the PORT Driver within the Autosar MCAL Layer, it is essential to understand two key functional concepts. These concepts are crucial for building a strong foundational knowledge in this area. These 2 concepts are:

  • Concept of PCR value for MCU Pins
  • Port Driver Parameters:

Concept of PCR value for MCU Pins

To use the Microcontroller, their are pins attached to it through which it connects to outside world and exchanges data. And to refer to these pins, their is concept of Ports in microcontroller. The pins of microcontroller are referred by grouping 32 pins in a single group. And these groups are called as Ports.

Port are named according to alphaphets, that is PORTA, PORTB, PORTC, PORTD and etc. Each Port can have max 32 pins of MCU. So MCU pins are referred as Port Pins as: PTA0-PTA31, PTB0-PTB31, PTC0-PTC31, PTD0-PTD31 and etc. Each

Now when we want to configure these port pins for alternate functions, we refer them via PCR values in Autosar MCAL Layer. PCR value is the mapping of mathematical logic numbers to each MCU port pin.

A is the first alphaphet thus PORTA numbering starts from 0. And PORTA can have max 32 numbers, so PORTA numbering ends at 31. Meaning PTA0 is referred as 0 PCR value, PTA1 as 1PCR value, PTA 15 as 15 PCR value and PTA30 as 30 PCR value. After that B is the second alphaphet, thus PORTB numbering starts after PORTA pins are finished that is from 32 and ends at 63. Meaning PTB0 is 32 PCR value and PTB16 as 47 PCR value and PTB31 as 63 value.

So and so PCR values are calculated for each MCU pin according to its port and pin number.

The number of pins in indiviual ports can vary from MCU to MCU. Like in S32K144 their are 16 pins in PORTA, whearas in S32K344 their are 32 pins in PORTA. So MCU’s having number of pins less then 32 in port’s, doesnt mean the next Port PCR values are changed. PCR values remain same irrespective of pins present in each port. Its just MCU which doesnt have 32 pins in its port, PCR values of those port pins is not applicable on those mcu’s.

Like in S32K144, their are only 16 pins in PORTA, so PCR values from 0-15 are used to refer to pins of PTA0 to PTA15. PCR values from 16-31 are not applicable for S32K144 MCU, as those pins doesnt not exist in MCU.

whearas in S32K344 their are 32 pins in PORTA, so PCR values from 0-31 are used to refer to pins of PTA0 to PTA31. Over here S32K344 has 32 pins in PORTA, so all pins are avialable and this PCR values are applicable.

PCR value based mapping is used in Autosar MCAL layer to refer to differrnt pins of MCU. As this is universal and applicable to all MCU’s. Which makes the Port Driver as a universal Standard port stack for configuring different pins of MCU.

Port Driver Parameters

  1. Port Direction: Port Direction parameter refers to Input Direction, Output Direction, Input-Output Direction or High-Impedence Direction for the Microcontroller Pins.
    1. Input Direction means, that on the configured pin some external signal would be fed and MCU have to read its Logic Levels like whether external signal is Low(0) or High(1).
    2. Output Direction means, that the configured pin would be generating a signal of High(1) and Low(0) volatge level. High Volatge level means a signal of +5 or +3.3 Voltage would be generated from the pin of the MCU, Low Voltage level means a signal of 0V would be generated from the pin of the MCU.
    3. Input-Output Direction means, that the configured pin can both send(output) and receive(input) signals at different times. The pin can be toggled to work as input or output through software or hardware(I2C). In some protocols like I2C, harwdare can manage the switching automatically while in others software needs to control this quickly like for communication protocols like 1-wire.
    4. High-Impedence means, that the configured pin of the microcontroller is left open and it is neither connected to Power or GND of the MCU circuit. When a pin is set in High Impedence state it has very high resistance, which prevents it from drawing significant current or affecting other circuit elements connected to the same line. High-impedance mode is often used in systems with multiple devices sharing a single communication bus, such as I2C, SPI, or data buses in parallel interfaces. High-Impedence states is also referred as Floating state and tristate.
  2. Port Mode: Port Mode parameter refers to the peripheral type for which the corresponding MCU pin has to be used. As mentioned earlier a single MCU pin can be used for multiple peripheral’s. We can configure, MCU pin has to be used as which peripheral. Peripheral’s like: GPIO, UART, I2C, TIMER, ADC or any other peripheral of MCU that needs physical end point to communicate with outside world.
  3. Port Level: Port Level parameter refers to the Logic level that is assigned to MCU pin when it is configured as OutPut. As when Pin direction is configured as OutPut and Mode as GPIO, then MCU pin can either generate a logic High Level(1) or Logic Low Level(0), that thing is done using Port Level parameter. Port level parameter have PORT_HIGH_LEVEL or PORT_LOW_LEVEL. As the name says, PORT_HIGH_LEVEL makes the pin of the MCU to logic high level, that is either +5 or +3.3 V is outputted from MCU Pin. PORT_LOW_LEVEL makes the pin of the MCU to logic low level, that is 0V is outputted from MCU pin that can be treated as GND also.
  4. Port Drive Strength: Port Drive Strength parameter refers to the amount of current the pin can provide to external components or absorb of external components( in the case of logic low level) when it is configured as output. This setting affects the ability of the pin to drive loads connected to it and is particularly important for applications requiring high speed communications or driving external components(LED’s, small relays) with specific current needs. Their are 2 options in Port Drive Strenth: Low_Drive_Strength or High_Drive_Strength.
    1. Low_Drive_Strenth: This setting provides the limited current, ideal for low-power applications and low-speed signals.
    2. High_Drive_Strength: This setting allows the pin to source or sink more current, useful for faster signals or driving more demanding loads like LED’s, small relays or long signal traces.
  5. Port Pull Enable/Strength:
Kunal Gupta
Author: Kunal Gupta

Author

Kunal Gupta

Leave a comment

Stay Updated With Us

Error: Contact form not found.

      Blog