BASICS OF AUTOSAR MCAL
Published: 2023-12-07 07:25:33

Hello Readers,

My name is Sana, and I work at Luxoft India as a Junior Software Developer. Luxoft has given me several opportunities to work on various projects, which has inspired me to learn the essential processes involved in developing AUTOSAR Modulеs and Add-Ons in AUTOSAR MCAL.

**Introduction**
MCAL stand for Microcontroller Abstraction Layer. The MCAL layer is one of the four layers of the AUTOSAR architecture, the other three are Application Layer, the RTE Layer, and the ECU Abstraction Layer.  MCAL is the lowest layer of BSW(Basic Software). It contains driver with direct access to microcontroller , internal peripheral and memory mapped microcontroller external device. Its act as bridge between Application software and hardware. MCAL is hardware specific layer that ensures a standard interface to the basic software. Its makes higher software layer independent of microcontroller.

- The Microcontroller Abstraction Layer sub divided into four parts:

Controller Driver
Memory Driver
Com Driver
I/O Driver

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mcxowdl4oosowp1ec017.png)



**How does MCAL Work**
MCAL layer is the set of software modules that provide a standardized interface for accessing the microcontroller and other hardware components of the ECU. MCAL contains drivers for the microcontroller, communication interfaces, timers, and other peripherals.
MCAL layer provides set of services that can be accessed by the application software by the AUTOSAR interface. These services consist of functions for initializing the hardware, configuring the hardware, and controlling the hardware. it can be used to customize the behavior of the software modules. 

**How MCAL layer play important role in AUTOSAR**
The MCAL layer act as important role in automotive software development. By providing a standardized interface for accessing the hardware, it allows the application software to be independent of the specific microcontroller and  hardware components used in the ECU. This layer makes it easy to develop, test, and maintain the software. Hardware upgrades can be implemented without the need to modify the application software.

**Software Architecture of MCAL**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ffdr2oqrdexxhy9kge3.png)
MCAL provides a collection of specialized software components, each tailored to a specific hardware function. These components, known as drivers, interact directly with the corresponding on-chip peripheral hardware. For example, CAN Driver will ensure that CAN messages can be received and transmitted by the MCU.

**Modules in MCAL**
MCAL each module is responsible for abstracting different hardware components of the ECU. 

_Microcontroller Driver_

- MCU Driver : MCU (Micro Controller Unit) Driver module provides a standardized interface for accessing the microcontroller, including its core functions and its integrated peripherals (e.g., ADC, PWM, CAN, SPI, and FLS).MCU (Micro Controller Unit) Driver, this device driver helps configure MCU settings, initializes clock and helps configure power mode settings.

- GPT Driver: GPT (General Purpose Timer) driver allows you to configure and use the General Purpose Timer available in the microcontroller for various timing and measurement tasks, such as generating delays, managing input captures, or creating periodic events. device driver uses on-chip MCU timer. Initializes GPT and performs timer count.

- WDG Driver: WDG (Watchdog) Driver, The primary purpose of a watchdog timer is to detect and recover from software or system failures, such as code execution errors, infinite loops, or other unexpected behavior.it is a hardware peripheral that is used to prevent software errors from causing the system to become unresponsive. This on-chip device driver Initializes  and performs WDG mode settings.

_Memory Driver_

Memory Drivers provides a standardized interface for retrieve the memory of the ECU, which includes RAM, ROM, and flash memory.
The memory driver typically provides the following services:
1. Initialization of the memory devices	
2. Reading and writing to memory
3. Erasing memory
4. Managing memory protection
5. Testing the memory devices

- Flash driver: Flash drivers are an essential part of any system that uses flash memory. This will help to ensure that our  software is portable, reliable, and efficient. Its initialize Flash and reads/writes to Flash memory.

_Communication Drivers_

This module Provides a standardized interface for retrieve the communication interfaces used in the ECU, such as CAN, LIN, and FlexRay. 

- FlexRay: A high-speed communication protocol used in advanced driver assistance systems (ADAS) and other safety-critical applications. Its initializes FlexRay and performs FlexRay input/output. 

- CAN (Controller Area Network): A widely used communication protocol in automotive applications for inter-ECU communication. It allows multiple ECUs to communicate with each other over a shared bus. Driver that initializes and performs CAN input/output.
 
_I/O Driver_

An I/O driver in MCAL is a software module that provides access to the microcontroller's (MCU) I/O ports. It abstracts the physical layer of I/O port, making it easier for the upper software layer to interact with them.

**Conclusion**
The MCAL layer play a vital role in AUTOSAR software architecture, its allows easy development for automotive Software. making it easy to integrate different software components. 

I have written some of the basics of AUTOSAR MCAL and I will continue this topic in my upcoming Articles Thank you..