AUTOSAR-like MCU Driver

From ErikaWiki

Revision as of 08:15, 16 July 2013 by Eguidieri (Talk | contribs)
Jump to: navigation, search

Contents

Synopsis

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.

Startup Code.png

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.

File Structure

MCU Driver File structure.png

Configuration

Build

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>";

Where <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";

Where <PATH> is the absolute or relative directory path which configuration C source file is stored.

API Specification

Imported Types

typedef uint8 Std_ReturnType

 #include "Std_Types.h"

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.

struct Std_VersionInfoType

 #include "Std_Types.h"

Standard Version Informations Type.

This type shall be used to request the version of a AUTOSAR-like module using the <Module Name>_GetVersionInfo() function.

Field Documentation:

 uint16 Std_VersionInfoType::moduleID

Module Identifier.

 uint8 Std_VersionInfoType::sw_major_version

Software Version Major Number.

 uint8 Std_VersionInfoType::sw_minor_version

Software Version Minor Number.

 uint8 Std_VersionInfoType::sw_patch_version

Software Version Patch Number.

 uint16 Std_VersionInfoType::vendorID

Vendor Identifier.

Types Defintions

struct Mcu_ConfigType

 #include "Mcu.h"

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.

enum Mcu_PllStatusType

 #include "Mcu.h"

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.

Enumerator:

  • MCU_PLL_LOCKED: PLL is locked.
  • MCU_PLL_UNLOCKED: PLL is unlocked.
  • MCU_PLL_STATUS_UNDEFINED: PLL Status is unknown.

typedef uint Mcu_ClockType

 #include "Mcu.h"

Clock Type.

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.

enum Mcu_ResetType

 #include "Mcu.h"

Reset Type.

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.

Enumerator:

  • 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

 #include "Mcu.h"

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

 #include "Mcu.h"

Mode Type.

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

 #include "Mcu.h"

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.

enum Mcu_RamStateType

 #include "Mcu.h"

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.

Enumerator:

  • MCU_RAM_STATE_INVALID: Ram content is not valid or unknown (default)
  • MCU_RAM_STATE_VALID: Ram content is valid

Functions Definitions

void Mcu_Init(const Mcu_ConfigType *ConfigPtr)

 #include "Mcu.h"

MCU Driver Initialization.

Parameters:

  • ConfigPtr : Pointer to MCU driver configuration set.

Returns:

  • None.

This service initializes the MCU driver.

Service 0x00

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.

Examples

Usage examples of the AUTOSAR-like MCU Driver for can be found at examples/cortex_mx/lm4f232xxxx/as

Personal tools