/** @file system.h
*   @brief System Driver Header File
*   @date 15.March.2013
*   @version 03.05.00
*   
*   This file contains:
*   - Definitions
*   - Types
*   .
*   which are relevant for the System driver.
*/

/* (c) Texas Instruments 2009-2013, All rights reserved. */

#ifndef __SYS_SYSTEM_H__
#define __SYS_SYSTEM_H__

#include "reg_system.h"
#include "reg_m3core.h"
#include "reg_pcr.h"
#include "reg_flash.h"

/* USER CODE BEGIN (0) */
/* USER CODE END */

/* System General Definitions */

/** @enum systemClockSource
*   @brief Alias names for clock sources
*
*   This enumeration is used to provide alias names for the clock sources:
*     - Oscillator
*     - Pll
*     - 32 kHz Oscillator
*     - External
*     - Low Power Oscillator Low
*     - Low Power Oscillator High
*     - Synchronous VCLK1
*/
enum systemClockSource
{
    SYS_OSC      = 0U, /**< Alias for oscillator clock Source                */
    SYS_PLL      = 1U, /**< Alias for Pll clock Source                       */
    SYS_O32      = 2U, /**< Alias for 32 kHz oscillator clock Source         */
    SYS_EXTERNAL = 3U, /**< Alias for external clock Source                  */
    SYS_LPO_LOW  = 4U, /**< Alias for low power oscillator low clock Source  */
    SYS_LPO_HIGH = 5U, /**< Alias for low power oscillator high clock Source */
    SYS_VCLK     = 9U  /**< Alias for synchronous VCLK1 clock Source         */
};

/** @enum systemClockDomain
*   @brief Alias names for clock domain
*
*   This enumeration is used to provide alias names for the clock domains:
*     - GCLK
*     - ACCLK1
*     
*/
enum systemClockDomain
{
    SYS_GCLK     = 8U,   /**< Alias for GCLK1 clock domain     */
    SYS_AVCLK1   = 11U   /**< Alias for AVCLK1 clock domain    */
};

/** @def SYS_PRE1
*   @brief Alias name for RTI1CLK PRE clock source
*
*   This is an alias name for the RTI1CLK pre clock source.
*   This can be either:
*     - Oscillator
*     - Pll
*     - 32 kHz Oscillator
*     - External
*     - Low Power Oscillator Low
*     - Low Power Oscillator High
*/
/*SAFETYMCUSW 79 S MR:19.4 <REVIEWED> "Macro filled using GUI parameter cannot be avoided" */
#define SYS_PRE1 SYS_PLL

/** @def SYS_PRE2
*   @brief Alias name for RTI2CLK pre clock source
*
*   This is an alias name for the RTI2CLK pre clock source.
*   This can be either:
*     - Oscillator
*     - Pll
*     - 32 kHz Oscillator
*     - External
*     - Low Power Oscillator Low
*     - Low Power Oscillator High
*/
/*SAFETYMCUSW 79 S MR:19.4 <REVIEWED> "Macro filled using GUI parameter cannot be avoided" */
#define SYS_PRE2 SYS_PLL

/* USER CODE BEGIN (1) */
/* USER CODE END */

/**************************************/
/*    Defining the MPU regions        */
/**************************************/
#define REGION0			0x0U
#define REGION1 		0x1U
#define REGION2			0x2U
#define REGION3			0x3U
#define REGION4			0x4U
#define REGION5			0x5U	
#define REGION6			0x6U
#define REGION7			0x7U

/*************************************************/
/*    Defining the MPU access permissions        */
/*************************************************/

#define AP_EXE_NOACCESS		0x00000000U
#define AP_EXE_READWRITE	0x03000000U
#define AP_EXE_READONLY		0x07000000U

#define AP_NON_EXE_NOACCESS	  0x10000000U
#define AP_NON_EXE_READWRITE  0x13000000U
#define AP_NON_EXE_READONLY	  0x17000000U

/**************************************/
/*    Defining the MPU region size    */
/**************************************/

#define Size_32B			0x00000008U
#define Size_64B			0x0000000AU
#define Size_128B			0x0000000CU
#define Size_256B	 		0x0000000EU
#define Size_512B			0x00000010U
#define Size_1KB			0x00000012U
#define Size_2KB			0x00000014U
#define Size_4KB			0x00000016U
#define Size_8KB			0x00000018U
#define Size_16KB			0x0000001AU
#define Size_32KB			0x0000001CU
#define Size_64KB			0x0000001EU
#define Size_128KB		    0x00000020U
#define Size_256KB		    0x00000022U
#define Size_512KB		    0x00000024U
#define Size_1MB 			0x00000026U
#define Size_2MB		   	0x00000028U
#define Size_4MB			0x0000002AU
#define Size_8MB			0x0000002CU
#define Size_16MB			0x0000002EU
#define Size_32MB			0x00000030U
#define Size_64MB			0x00000032U
#define Size_128MB		    0x00000034U
#define Size_256MB		    0x00000036U
#define Size_512MB		    0x00000038U
#define Size_1GB			0x0000003AU
#define Size_2GB			0x0000003CU
#define Size_4GB			0x0000003EU

/* USER CODE BEGIN (2) */
/* USER CODE END */

/* FlashW General Definitions */

/** @enum flashWPowerModes
*   @brief Alias names for flash bank power modes
*
*   This enumeration is used to provide alias names for the flash bank power modes:
*     - sleep
*     - standby
*     - active
*/
enum flashWPowerModes
{
    SYS_SLEEP   = 0U, /**< Alias for flash bank power mode sleep   */
    SYS_STANDBY = 1U, /**< Alias for flash bank power mode standby */
    SYS_ACTIVE  = 3U  /**< Alias for flash bank power mode active  */
};

/* USER CODE BEGIN (3) */
/* USER CODE END */

/* System Interface Functions */

void systemInit(void);
void _memoryInit(void);
void systemPowerDown(uint32 mode);
void _mpuInit(void);
void mpuEnable(void);
void mpuDisable(void);
void mpuDisableRegion(uint32 region);
void mpuSetRegion(uint32 region, uint32 base_addr, uint32 size, uint32 access);
void _switch_to_usermode(void);

/* USER CODE BEGIN (4) */
/* USER CODE END */


#endif
