AUTOSAR-like MCU Driver
The MCU driver provides services for basic microcontroller initialization, power down functionality, reset and microcontroller specific functions required by other MCAL [Microcontroller Abstraction Layer] software modules. The initialization services allow a flexible and application related MCU initialization in addition to the start-up code (see figure below). The start-up code is very MCU specific. The start-up code is provided by Evidence Srl within Erika Enterprise.
MCU driver Features:
- Initialization of MCU clock, PLL, clock prescalers and MCU clock distribution
- Initialization of RAM sections
- Activation of μC reduced power modes
- Activation of a μC reset
- Provides a service to get the reset reason from hardware
The MCU driver accesses the microcontroller hardware directly and is located in the Microcontroller Abstraction Layer.
To enable AUTOSAR-like MCU Driver in Erika Enterprise compiler toolchain, the following
EE_OPT attribute is needed in the
OS object of the OSEK/VDX configuration:
EE_OPT = "__AS_MCU_DRIVER__";
The configuration C header file inclusion is done by
CFLAGS attribute in the
OS object of the OSEK/VDX configuration:
CFLAGS = "-I<PATH>";
<PATH> is the absolute or relative directory path which configuration C header file is stored.
Instead the configurations C source file is added to the compilation process by
APP_SRC attribute in the
CPU_DATA object of the OSEK/VDX configuration:
APP_SRC = "<PATH>/Mcu_Cfg.c";
<PATH> is the absolute or relative directory path which configuration C source file is stored.
typedef uint8 Std_ReturnType
Standard Return Type.
This type can be used as standard API return type which is shared between AUTOSAR-like modules.
The Std_ReturnType shall normally be used with value E_OK or E_NOT_OK. If those return values are not sufficient user specific values can be defined by using the 6 least specific bits.
Standard Version Informations Type.
This type shall be used to request the version of a AUTOSAR-like module using the <Module Name>_GetVersionInfo() function.
Software Version Major Number.
Software Version Minor Number.
Software Version Patch Number.
MCU Configuration Parameters.
The structure Mcu_ConfigType is an external data structure (i.e. implementation specific) and shall contain the initialization data for the MCU module. It shall contain:
- MCU dependent properties
- Reset Configuration
- Definition of MCU modes
- Definition of Clock settings
- Definition of RAM sections
The structure Mcu_ConfigType shall provide a configurable (enable/disable) clock failure notification if the MCU provides an interrupt for such detection. If the clock failure is detected with other HW mechanisms e.g., the generation of a trap, this notification shall be disabled and the failure reporting shall be done outside the MCU driver.
The definitions for each MCU mode within the structure Mcu_ConfigType shall contain: (depending on MCU)
- MCU specific properties
- Change of CPU clock
- Change of Peripheral clock
- Change of PLL settings
- Change of MCU power supply
The definitions for each Clock setting within the structure Mcu_ConfigType shall contain:
- MCU specific properties as, e.g., clock safety features and special clock distribution settings
- PLL settings /start lock options
- Internal oscillator setting
The definitions for each RAM section within the structure Mcu_ConfigType shall contain:
- RAM section base address
- Section size
- Data pre-setting to be initialized
Usage of linker symbols instead of scalar values is allowed.
PLL Status Type.
The type Mcu_PllStatusType is the type of the return value of the API function Mcu_GetPllStatus().
The type of Mcu_PllStatusType is an enumeration with the following values: MCU_PLL_LOCKED, MCU_PLL_UNLOCKED, MCU_PLL_STATUS_UNDEFINED.
- MCU_PLL_LOCKED: PLL is locked.
- MCU_PLL_UNLOCKED: PLL is unlocked.
- MCU_PLL_STATUS_UNDEFINED: PLL Status is unknown.
typedef uint Mcu_ClockType
The type Mcu_ClockType defines the identification (ID) for clock setting configured via the configuration structure.
The type shall be uint8, uint16 or uint32, depending on μC platform.
This type represents the different reset that a specified MCU can have.
The MCU module shall provide at least the values MCU_POWER_ON_RESET and MCU_RESET_UNDEFINED.
Note: Additional reset types may be added depending on MCU.
- MCU_POWER_ON_RESET: Power On Reset (default)
- MCU_WATCHDOG_RESET: Internal Watchdog Timer Reset
- MCU_SW_RESET: Software Reset
- MCU_RESET_UNDEFINED: Reset is undefined
typedef uint Mcu_RawResetType
Raw Reset Type.
The type Mcu_RawResetType specifies the reset reason in raw register format, read from a reset status register.
The type shall be uint8, uint16 or uint32 based on best performance.
typedef uint Mcu_ModeType
The Mcu_ModeType specifies the identification (ID) for a MCU mode, configured via configuration structure.
The type shall be uint8, uint16 or uint32.
typedef uint Mcu_RamSectionType
Ram Section Type.
The Mcu_RamSectionType specifies the identification (ID) for a RAM section, configured via the configuration structure.
The type shall be uint8, uint16 or uint32 , based on best performance.
Ram State Type.
This is the Ram State data type returned by the function Mcu_GetRamState() of the Mcu module. It is not required that all RAM state types are supported by the hardware.
- MCU_RAM_STATE_INVALID: Ram content is not valid or unknown (default)
- MCU_RAM_STATE_VALID: Ram content is valid
void Mcu_Init(const Mcu_ConfigType *ConfigPtr)
MCU Driver Initialization.
- ConfigPtr : Pointer to MCU driver configuration set.
This service initializes the MCU driver.
The function Mcu_Init() shall initialize the MCU module, i.e. make the configuration settings for power down, clock and RAM sections visible within the MCU module.
Note: After the execution of the function Mcu_Init(), the configuration data are accessible and can be used by the MCU module functions as, e.g., Mcu_InitRamSection().
The MCU module's implementer shall apply the following rules regarding initialization of controller registers within the function Mcu_Init():
- If the hardware allows for only one usage of the register, the driver module implementing that functionality is responsible for initializing the register.
- If the register can affect several hardware modules and if it is an I/O register, it shall be initialised by the PORT driver.
- If the register can affect several hardware modules and if it is not an I/O register, it shall be initialised by this MCU driver.
- One-time writable registers that require initialisation directly after reset shall be initialised by the startup code.
- All other registers not mentioned before shall be initialised by the start-up code.
If not applicable, the MCU module's environment shall pass a NULL pointer to the function Mcu_Init(). In this case the check for this NULL pointer has to be omitted.
Note: The term 'Hardware Module' refers to internal modules of the MCU.
Usage examples of the AUTOSAR-like MCU Driver for can be found at examples/cortex_mx/lm4f232xxxx/as