From: richardbarry Date: Mon, 1 Jun 2009 11:45:26 +0000 (+0000) Subject: Add new demo files. X-Git-Tag: V5.3.0~1 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6bfd76c0f6ffd25dd19cb5087a28ef56a2ab94bb;p=freertos Add new demo files. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@765 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/cmsis/core_cm3.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/cmsis/core_cm3.c new file mode 100644 index 000000000..a64aa5c72 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/cmsis/core_cm3.c @@ -0,0 +1,805 @@ +/****************************************************************************** + * @file: core_cm3.c + * @purpose: CMSIS Cortex-M3 Core Peripheral Access Layer Source File + * @version: V1.10 + * @date: 24. Feb. 2009 + *---------------------------------------------------------------------------- + * + * Copyright (C) 2009 ARM Limited. All rights reserved. + * + * ARM Limited (ARM) is supplying this software for use with Cortex-Mx + * processor based microcontrollers. This file can be freely distributed + * within development tools that are supporting such ARM based processors. + * + * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED + * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. + * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR + * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. + * + ******************************************************************************/ + + + +#include + + +/* define compiler specific symbols */ +#if defined ( __CC_ARM ) + #define __ASM __asm /*!< asm keyword for armcc */ + #define __INLINE __inline /*!< inline keyword for armcc */ + +#elif defined ( __ICCARM__ ) + #define __ASM __asm /*!< asm keyword for iarcc */ + #define __INLINE inline /*!< inline keyword for iarcc. Only avaiable in High optimization mode! */ + #define __nop __no_operation /*!< no operation intrinsic in iarcc */ + +#elif defined ( __GNUC__ ) + #define __ASM asm /*!< asm keyword for gcc */ + #define __INLINE inline /*!< inline keyword for gcc */ +#endif + + + +#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ + +/** + * @brief Return the Process Stack Pointer + * + * @param none + * @return uint32_t ProcessStackPointer + * + * Return the actual process stack pointer + */ +__ASM uint32_t __get_PSP(void) +{ + mrs r0, psp + bx lr +} + +/** + * @brief Set the Process Stack Pointer + * + * @param uint32_t Process Stack Pointer + * @return none + * + * Assign the value ProcessStackPointer to the MSP + * (process stack pointer) Cortex processor register + */ +__ASM void __set_PSP(uint32_t topOfProcStack) +{ + msr psp, r0 + bx lr +} + +/** + * @brief Return the Main Stack Pointer + * + * @param none + * @return uint32_t Main Stack Pointer + * + * Return the current value of the MSP (main stack pointer) + * Cortex processor register + */ +__ASM uint32_t __get_MSP(void) +{ + mrs r0, msp + bx lr +} + +/** + * @brief Set the Main Stack Pointer + * + * @param uint32_t Main Stack Pointer + * @return none + * + * Assign the value mainStackPointer to the MSP + * (main stack pointer) Cortex processor register + */ +__ASM void __set_MSP(uint32_t mainStackPointer) +{ + msr msp, r0 + bx lr +} + +/** + * @brief Reverse byte order in unsigned short value + * + * @param uint16_t value to reverse + * @return uint32_t reversed value + * + * Reverse byte order in unsigned short value + */ +__ASM uint32_t __REV16(uint16_t value) +{ + rev16 r0, r0 + bx lr +} + +/** + * @brief Reverse byte order in signed short value with sign extension to integer + * + * @param int16_t value to reverse + * @return int32_t reversed value + * + * Reverse byte order in signed short value with sign extension to integer + */ +__ASM int32_t __REVSH(int16_t value) +{ + revsh r0, r0 + bx lr +} + + +#if (__ARMCC_VERSION < 400000) + +/** + * @brief Remove the exclusive lock created by ldrex + * + * @param none + * @return none + * + * Removes the exclusive lock which is created by ldrex. + */ +__ASM void __CLREX(void) +{ + clrex +} + +/** + * @brief Return the Base Priority value + * + * @param none + * @return uint32_t BasePriority + * + * Return the content of the base priority register + */ +__ASM uint32_t __get_BASEPRI(void) +{ + mrs r0, basepri + bx lr +} + +/** + * @brief Set the Base Priority value + * + * @param uint32_t BasePriority + * @return none + * + * Set the base priority register + */ +__ASM void __set_BASEPRI(uint32_t basePri) +{ + msr basepri, r0 + bx lr +} + +/** + * @brief Return the Priority Mask value + * + * @param none + * @return uint32_t PriMask + * + * Return the state of the priority mask bit from the priority mask + * register + */ +__ASM uint32_t __get_PRIMASK(void) +{ + mrs r0, primask + bx lr +} + +/** + * @brief Set the Priority Mask value + * + * @param uint32_t PriMask + * @return none + * + * Set the priority mask bit in the priority mask register + */ +__ASM void __set_PRIMASK(uint32_t priMask) +{ + msr primask, r0 + bx lr +} + +/** + * @brief Return the Fault Mask value + * + * @param none + * @return uint32_t FaultMask + * + * Return the content of the fault mask register + */ +__ASM uint32_t __get_FAULTMASK(void) +{ + mrs r0, faultmask + bx lr +} + +/** + * @brief Set the Fault Mask value + * + * @param uint32_t faultMask value + * @return none + * + * Set the fault mask register + */ +__ASM void __set_FAULTMASK(uint32_t faultMask) +{ + msr faultmask, r0 + bx lr +} + +/** + * @brief Return the Control Register value + * + * @param none + * @return uint32_t Control value + * + * Return the content of the control register + */ +__ASM uint32_t __get_CONTROL(void) +{ + mrs r0, control + bx lr +} + +/** + * @brief Set the Control Register value + * + * @param uint32_t Control value + * @return none + * + * Set the control register + */ +__ASM void __set_CONTROL(uint32_t control) +{ + msr control, r0 + bx lr +} + +#endif /* __ARMCC_VERSION */ + + +#elif (defined (__ICCARM__)) /*------------------ ICC Compiler -------------------*/ +#pragma diag_suppress=Pe940 + +/** + * @brief Return the Process Stack Pointer + * + * @param none + * @return uint32_t ProcessStackPointer + * + * Return the actual process stack pointer + */ +uint32_t __get_PSP(void) +{ + __ASM("mrs r0, psp"); + __ASM("bx lr"); +} + +/** + * @brief Set the Process Stack Pointer + * + * @param uint32_t Process Stack Pointer + * @return none + * + * Assign the value ProcessStackPointer to the MSP + * (process stack pointer) Cortex processor register + */ +void __set_PSP(uint32_t topOfProcStack) +{ + __ASM("msr psp, r0"); + __ASM("bx lr"); +} + +/** + * @brief Return the Main Stack Pointer + * + * @param none + * @return uint32_t Main Stack Pointer + * + * Return the current value of the MSP (main stack pointer) + * Cortex processor register + */ +uint32_t __get_MSP(void) +{ + __ASM("mrs r0, msp"); + __ASM("bx lr"); +} + +/** + * @brief Set the Main Stack Pointer + * + * @param uint32_t Main Stack Pointer + * @return none + * + * Assign the value mainStackPointer to the MSP + * (main stack pointer) Cortex processor register + */ +void __set_MSP(uint32_t topOfMainStack) +{ + __ASM("msr msp, r0"); + __ASM("bx lr"); +} + +/** + * @brief Reverse byte order in unsigned short value + * + * @param uint16_t value to reverse + * @return uint32_t reversed value + * + * Reverse byte order in unsigned short value + */ +uint32_t __REV16(uint16_t value) +{ + __ASM("rev16 r0, r0"); + __ASM("bx lr"); +} + +/** + * @brief Reverse bit order of value + * + * @param uint32_t value to reverse + * @return uint32_t reversed value + * + * Reverse bit order of value + */ +uint32_t __RBIT(uint32_t value) +{ + __ASM("rbit r0, r0"); + __ASM("bx lr"); +} + +/** + * @brief LDR Exclusive + * + * @param uint8_t* address + * @return uint8_t value of (*address) + * + * Exclusive LDR command + */ +uint8_t __LDREXB(uint8_t *addr) +{ + __ASM("ldrexb r0, [r0]"); + __ASM("bx lr"); +} + +/** + * @brief LDR Exclusive + * + * @param uint16_t* address + * @return uint16_t value of (*address) + * + * Exclusive LDR command + */ +uint16_t __LDREXH(uint16_t *addr) +{ + __ASM("ldrexh r0, [r0]"); + __ASM("bx lr"); +} + +/** + * @brief LDR Exclusive + * + * @param uint32_t* address + * @return uint32_t value of (*address) + * + * Exclusive LDR command + */ +uint32_t __LDREXW(uint32_t *addr) +{ + __ASM("ldrex r0, [r0]"); + __ASM("bx lr"); +} + +/** + * @brief STR Exclusive + * + * @param uint8_t *address + * @param uint8_t value to store + * @return uint32_t successful / failed + * + * Exclusive STR command + */ +uint32_t __STREXB(uint8_t value, uint8_t *addr) +{ + __ASM("strexb r0, r0, [r1]"); + __ASM("bx lr"); +} + +/** + * @brief STR Exclusive + * + * @param uint16_t *address + * @param uint16_t value to store + * @return uint32_t successful / failed + * + * Exclusive STR command + */ +uint32_t __STREXH(uint16_t value, uint16_t *addr) +{ + __ASM("strexh r0, r0, [r1]"); + __ASM("bx lr"); +} + +/** + * @brief STR Exclusive + * + * @param uint32_t *address + * @param uint32_t value to store + * @return uint32_t successful / failed + * + * Exclusive STR command + */ +uint32_t __STREXW(uint32_t value, uint32_t *addr) +{ + __ASM("strex r0, r0, [r1]"); + __ASM("bx lr"); +} + +#pragma diag_default=Pe940 + + +#elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/ + +/** + * @brief Return the Process Stack Pointer + * + * @param none + * @return uint32_t ProcessStackPointer + * + * Return the actual process stack pointer + */ +uint32_t __get_PSP(void) +{ + uint32_t result=0; + + __ASM volatile ("MRS %0, psp" : "=r" (result) ); + return(result); +} + +/** + * @brief Set the Process Stack Pointer + * + * @param uint32_t Process Stack Pointer + * @return none + * + * Assign the value ProcessStackPointer to the MSP + * (process stack pointer) Cortex processor register + */ +void __set_PSP(uint32_t topOfProcStack) +{ + __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) ); +} + +/** + * @brief Return the Main Stack Pointer + * + * @param none + * @return uint32_t Main Stack Pointer + * + * Return the current value of the MSP (main stack pointer) + * Cortex processor register + */ +uint32_t __get_MSP(void) +{ + uint32_t result=0; + + __ASM volatile ("MRS %0, msp" : "=r" (result) ); + return(result); +} + +/** + * @brief Set the Main Stack Pointer + * + * @param uint32_t Main Stack Pointer + * @return none + * + * Assign the value mainStackPointer to the MSP + * (main stack pointer) Cortex processor register + */ +void __set_MSP(uint32_t topOfMainStack) +{ + __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) ); +} + +/** + * @brief Return the Base Priority value + * + * @param none + * @return uint32_t BasePriority + * + * Return the content of the base priority register + */ +uint32_t __get_BASEPRI(void) +{ + uint32_t result=0; + + __ASM volatile ("MRS %0, basepri_max" : "=r" (result) ); + return(result); +} + +/** + * @brief Set the Base Priority value + * + * @param uint32_t BasePriority + * @return none + * + * Set the base priority register + */ +void __set_BASEPRI(uint32_t value) +{ + __ASM volatile ("MSR basepri, %0" : : "r" (value) ); +} + +/** + * @brief Return the Priority Mask value + * + * @param none + * @return uint32_t PriMask + * + * Return the state of the priority mask bit from the priority mask + * register + */ +uint32_t __get_PRIMASK(void) +{ + uint32_t result=0; + + __ASM volatile ("MRS %0, primask" : "=r" (result) ); + return(result); +} + +/** + * @brief Set the Priority Mask value + * + * @param uint32_t PriMask + * @return none + * + * Set the priority mask bit in the priority mask register + */ +void __set_PRIMASK(uint32_t priMask) +{ + __ASM volatile ("MSR primask, %0" : : "r" (priMask) ); +} + +/** + * @brief Return the Fault Mask value + * + * @param none + * @return uint32_t FaultMask + * + * Return the content of the fault mask register + */ +uint32_t __get_FAULTMASK(void) +{ + uint32_t result=0; + + __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); + return(result); +} + +/** + * @brief Set the Fault Mask value + * + * @param uint32_t faultMask value + * @return none + * + * Set the fault mask register + */ +void __set_FAULTMASK(uint32_t faultMask) +{ + __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) ); +} + +/** + * @brief Reverse byte order in integer value + * + * @param uint32_t value to reverse + * @return uint32_t reversed value + * + * Reverse byte order in integer value + */ +uint32_t __REV(uint32_t value) +{ + uint32_t result=0; + + __ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value) ); + return(result); +} + +/** + * @brief Reverse byte order in unsigned short value + * + * @param uint16_t value to reverse + * @return uint32_t reversed value + * + * Reverse byte order in unsigned short value + */ +uint32_t __REV16(uint16_t value) +{ + uint32_t result=0; + + __ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value) ); + return(result); +} + +/** + * @brief Reverse byte order in signed short value with sign extension to integer + * + * @param int32_t value to reverse + * @return int32_t reversed value + * + * Reverse byte order in signed short value with sign extension to integer + */ +int32_t __REVSH(int16_t value) +{ + uint32_t result=0; + + __ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value) ); + return(result); +} + +/** + * @brief Reverse bit order of value + * + * @param uint32_t value to reverse + * @return uint32_t reversed value + * + * Reverse bit order of value + */ +uint32_t __RBIT(uint32_t value) +{ + uint32_t result=0; + + __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) ); + return(result); +} + +/** + * @brief LDR Exclusive + * + * @param uint8_t* address + * @return uint8_t value of (*address) + * + * Exclusive LDR command + */ +uint8_t __LDREXB(uint8_t *addr) +{ + uint8_t result=0; + + __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) ); + return(result); +} + +/** + * @brief LDR Exclusive + * + * @param uint16_t* address + * @return uint16_t value of (*address) + * + * Exclusive LDR command + */ +uint16_t __LDREXH(uint16_t *addr) +{ + uint16_t result=0; + + __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) ); + return(result); +} + +/** + * @brief LDR Exclusive + * + * @param uint32_t* address + * @return uint32_t value of (*address) + * + * Exclusive LDR command + */ +uint32_t __LDREXW(uint32_t *addr) +{ + uint32_t result=0; + + __ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr) ); + return(result); +} + +/** + * @brief STR Exclusive + * + * @param uint8_t *address + * @param uint8_t value to store + * @return uint32_t successful / failed + * + * Exclusive STR command + */ +uint32_t __STREXB(uint8_t value, uint8_t *addr) +{ + uint32_t result=0; + + __ASM volatile ("strexb %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) ); + return(result); +} + +/** + * @brief STR Exclusive + * + * @param uint16_t *address + * @param uint16_t value to store + * @return uint32_t successful / failed + * + * Exclusive STR command + */ +uint32_t __STREXH(uint16_t value, uint16_t *addr) +{ + uint32_t result=0; + + __ASM volatile ("strexh %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) ); + return(result); +} + +/** + * @brief STR Exclusive + * + * @param uint32_t *address + * @param uint32_t value to store + * @return uint32_t successful / failed + * + * Exclusive STR command + */ +uint32_t __STREXW(uint32_t value, uint32_t *addr) +{ + uint32_t result=0; + + __ASM volatile ("strex %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) ); + return(result); +} + +/** + * @brief Return the Control Register value + * + * @param none + * @return uint32_t Control value + * + * Return the content of the control register + */ +uint32_t __get_CONTROL(void) +{ + uint32_t result=0; + + __ASM volatile ("MRS %0, control" : "=r" (result) ); + return(result); +} + +/** + * @brief Set the Control Register value + * + * @param uint32_t Control value + * @return none + * + * Set the control register + */ +void __set_CONTROL(uint32_t control) +{ + __ASM volatile ("MSR control, %0" : : "r" (control) ); +} + +#endif + + + + + + + + + + + + + + + + + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/cmsis/core_cm3.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/cmsis/core_cm3.h new file mode 100644 index 000000000..9f83c1c0a --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/cmsis/core_cm3.h @@ -0,0 +1,1265 @@ +/****************************************************************************** + * @file: core_cm3.h + * @purpose: CMSIS Cortex-M3 Core Peripheral Access Layer Header File + * @version: V1.10 + * @date: 24. Feb. 2009 + *---------------------------------------------------------------------------- + * + * Copyright (C) 2009 ARM Limited. All rights reserved. + * + * ARM Limited (ARM) is supplying this software for use with Cortex-Mx + * processor based microcontrollers. This file can be freely distributed + * within development tools that are supporting such ARM based processors. + * + * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED + * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. + * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR + * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. + * + ******************************************************************************/ + + + + +#ifndef __CM3_CORE_H__ +#define __CM3_CORE_H__ + + +#define __CM3_CMSIS_VERSION_MAIN (0x01) /*!< [31:16] CMSIS HAL main version */ +#define __CM3_CMSIS_VERSION_SUB (0x10) /*!< [15:0] CMSIS HAL sub version */ +#define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16) | __CM3_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number */ + +#define __CORTEX_M (0x03) /*!< Cortex core */ + +/** + * Lint configuration \n + * ----------------------- \n + * + * The following Lint messages will be suppressed and not shown: \n + * \n + * --- Error 10: --- \n + * register uint32_t __regBasePri __asm("basepri"); \n + * Error 10: Expecting ';' \n + * \n + * --- Error 530: --- \n + * return(__regBasePri); \n + * Warning 530: Symbol '__regBasePri' (line 264) not initialized \n + * \n + * --- Error 550: --- \n + * __regBasePri = (basePri & 0x1ff); \n + * } \n + * Warning 550: Symbol '__regBasePri' (line 271) not accessed \n + * \n + * --- Error 754: --- \n + * uint32_t RESERVED0[24]; \n + * Info 754: local structure member '' (line 109, file ./cm3_core.h) not referenced \n + * \n + * --- Error 750: --- \n + * #define __CM3_CORE_H__ \n + * Info 750: local macro '__CM3_CORE_H__' (line 43, file./cm3_core.h) not referenced \n + * \n + * --- Error 528: --- \n + * static __INLINE void NVIC_DisableIRQ(uint32_t IRQn) \n + * Warning 528: Symbol 'NVIC_DisableIRQ(unsigned int)' (line 419, file ./cm3_core.h) not referenced \n + * \n + * --- Error 751: --- \n + * } InterruptType_Type; \n + * Info 751: local typedef 'InterruptType_Type' (line 170, file ./cm3_core.h) not referenced \n + * \n + * \n + * Note: To re-enable a Message, insert a space before 'lint' * \n + * + */ + +/*lint -save */ +/*lint -e10 */ +/*lint -e530 */ +/*lint -e550 */ +/*lint -e754 */ +/*lint -e750 */ +/*lint -e528 */ +/*lint -e751 */ + + +#include /* Include standard types */ + +#if defined (__ICCARM__) + #include /* IAR Intrinsics */ +#endif + + +#ifndef __NVIC_PRIO_BITS + #define __NVIC_PRIO_BITS 4 /*!< standard definition for NVIC Priority Bits */ +#endif + + + + +/** + * IO definitions + * + * define access restrictions to peripheral registers + */ + +#define __I volatile const /*!< defines 'read only' permissions */ +#define __O volatile /*!< defines 'write only' permissions */ +#define __IO volatile /*!< defines 'read / write' permissions */ + + + +/******************************************************************************* + * Register Abstraction + ******************************************************************************/ + + +/* System Reset */ +#define NVIC_VECTRESET 0 /*!< Vector Reset Bit */ +#define NVIC_SYSRESETREQ 2 /*!< System Reset Request */ +#define NVIC_AIRCR_VECTKEY (0x5FA << 16) /*!< AIRCR Key for write access */ +#define NVIC_AIRCR_ENDIANESS 15 /*!< Endianess */ + +/* Core Debug */ +#define CoreDebug_DEMCR_TRCENA (1 << 24) /*!< DEMCR TRCENA enable */ +#define ITM_TCR_ITMENA 1 /*!< ITM enable */ + + + + +/* memory mapping struct for Nested Vectored Interrupt Controller (NVIC) */ +typedef struct +{ + __IO uint32_t ISER[8]; /*!< Interrupt Set Enable Register */ + uint32_t RESERVED0[24]; + __IO uint32_t ICER[8]; /*!< Interrupt Clear Enable Register */ + uint32_t RSERVED1[24]; + __IO uint32_t ISPR[8]; /*!< Interrupt Set Pending Register */ + uint32_t RESERVED2[24]; + __IO uint32_t ICPR[8]; /*!< Interrupt Clear Pending Register */ + uint32_t RESERVED3[24]; + __IO uint32_t IABR[8]; /*!< Interrupt Active bit Register */ + uint32_t RESERVED4[56]; + __IO uint8_t IP[240]; /*!< Interrupt Priority Register, 8Bit wide */ + uint32_t RESERVED5[644]; + __O uint32_t STIR; /*!< Software Trigger Interrupt Register */ +} NVIC_Type; + + +/* memory mapping struct for System Control Block */ +typedef struct +{ + __I uint32_t CPUID; /*!< CPU ID Base Register */ + __IO uint32_t ICSR; /*!< Interrupt Control State Register */ + __IO uint32_t VTOR; /*!< Vector Table Offset Register */ + __IO uint32_t AIRCR; /*!< Application Interrupt / Reset Control Register */ + __IO uint32_t SCR; /*!< System Control Register */ + __IO uint32_t CCR; /*!< Configuration Control Register */ + __IO uint8_t SHP[12]; /*!< System Handlers Priority Registers (4-7, 8-11, 12-15) */ + __IO uint32_t SHCSR; /*!< System Handler Control and State Register */ + __IO uint32_t CFSR; /*!< Configurable Fault Status Register */ + __IO uint32_t HFSR; /*!< Hard Fault Status Register */ + __IO uint32_t DFSR; /*!< Debug Fault Status Register */ + __IO uint32_t MMFAR; /*!< Mem Manage Address Register */ + __IO uint32_t BFAR; /*!< Bus Fault Address Register */ + __IO uint32_t AFSR; /*!< Auxiliary Fault Status Register */ + __I uint32_t PFR[2]; /*!< Processor Feature Register */ + __I uint32_t DFR; /*!< Debug Feature Register */ + __I uint32_t ADR; /*!< Auxiliary Feature Register */ + __I uint32_t MMFR[4]; /*!< Memory Model Feature Register */ + __I uint32_t ISAR[5]; /*!< ISA Feature Register */ +} SCB_Type; + + +/* memory mapping struct for SysTick */ +typedef struct +{ + __IO uint32_t CTRL; /*!< SysTick Control and Status Register */ + __IO uint32_t LOAD; /*!< SysTick Reload Value Register */ + __IO uint32_t VAL; /*!< SysTick Current Value Register */ + __I uint32_t CALIB; /*!< SysTick Calibration Register */ +} SysTick_Type; + + +/* memory mapping structur for ITM */ +typedef struct +{ + __O union + { + __O uint8_t u8; /*!< ITM Stimulus Port 8-bit */ + __O uint16_t u16; /*!< ITM Stimulus Port 16-bit */ + __O uint32_t u32; /*!< ITM Stimulus Port 32-bit */ + } PORT [32]; /*!< ITM Stimulus Port Registers */ + uint32_t RESERVED0[864]; + __IO uint32_t TER; /*!< ITM Trace Enable Register */ + uint32_t RESERVED1[15]; + __IO uint32_t TPR; /*!< ITM Trace Privilege Register */ + uint32_t RESERVED2[15]; + __IO uint32_t TCR; /*!< ITM Trace Control Register */ + uint32_t RESERVED3[29]; + __IO uint32_t IWR; /*!< ITM Integration Write Register */ + __IO uint32_t IRR; /*!< ITM Integration Read Register */ + __IO uint32_t IMCR; /*!< ITM Integration Mode Control Register */ + uint32_t RESERVED4[43]; + __IO uint32_t LAR; /*!< ITM Lock Access Register */ + __IO uint32_t LSR; /*!< ITM Lock Status Register */ + uint32_t RESERVED5[6]; + __I uint32_t PID4; /*!< ITM Product ID Registers */ + __I uint32_t PID5; + __I uint32_t PID6; + __I uint32_t PID7; + __I uint32_t PID0; + __I uint32_t PID1; + __I uint32_t PID2; + __I uint32_t PID3; + __I uint32_t CID0; + __I uint32_t CID1; + __I uint32_t CID2; + __I uint32_t CID3; +} ITM_Type; + + +/* memory mapped struct for Interrupt Type */ +typedef struct +{ + uint32_t RESERVED0; + __I uint32_t ICTR; /*!< Interrupt Control Type Register */ +#if ((defined __CM3_REV) && (__CM3_REV >= 0x200)) + __IO uint32_t ACTLR; /*!< Auxiliary Control Register */ +#else + uint32_t RESERVED1; +#endif +} InterruptType_Type; + + +/* Memory Protection Unit */ +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1) +typedef struct +{ + __I uint32_t TYPE; /*!< MPU Type Register */ + __IO uint32_t CTRL; /*!< MPU Control Register */ + __IO uint32_t RNR; /*!< MPU Region RNRber Register */ + __IO uint32_t RBAR; /*!< MPU Region Base Address Register */ + __IO uint32_t RASR; /*!< MPU Region Attribute and Size Register */ + __IO uint32_t RBAR_A1; /*!< MPU Alias 1 Region Base Address Register */ + __IO uint32_t RASR_A1; /*!< MPU Alias 1 Region Attribute and Size Register */ + __IO uint32_t RBAR_A2; /*!< MPU Alias 2 Region Base Address Register */ + __IO uint32_t RASR_A2; /*!< MPU Alias 2 Region Attribute and Size Register */ + __IO uint32_t RBAR_A3; /*!< MPU Alias 3 Region Base Address Register */ + __IO uint32_t RASR_A3; /*!< MPU Alias 3 Region Attribute and Size Register */ +} MPU_Type; +#endif + + +/* Core Debug Register */ +typedef struct +{ + __IO uint32_t DHCSR; /*!< Debug Halting Control and Status Register */ + __O uint32_t DCRSR; /*!< Debug Core Register Selector Register */ + __IO uint32_t DCRDR; /*!< Debug Core Register Data Register */ + __IO uint32_t DEMCR; /*!< Debug Exception and Monitor Control Register */ +} CoreDebug_Type; + + +/* Memory mapping of Cortex-M3 Hardware */ +#define SCS_BASE (0xE000E000) /*!< System Control Space Base Address */ +#define ITM_BASE (0xE0000000) /*!< ITM Base Address */ +#define CoreDebug_BASE (0xE000EDF0) /*!< Core Debug Base Address */ +#define SysTick_BASE (SCS_BASE + 0x0010) /*!< SysTick Base Address */ +#define NVIC_BASE (SCS_BASE + 0x0100) /*!< NVIC Base Address */ +#define SCB_BASE (SCS_BASE + 0x0D00) /*!< System Control Block Base Address */ + +#define InterruptType ((InterruptType_Type *) SCS_BASE) /*!< Interrupt Type Register */ +#define SCB ((SCB_Type *) SCB_BASE) /*!< SCB configuration struct */ +#define SysTick ((SysTick_Type *) SysTick_BASE) /*!< SysTick configuration struct */ +#define NVIC ((NVIC_Type *) NVIC_BASE) /*!< NVIC configuration struct */ +#define ITM ((ITM_Type *) ITM_BASE) /*!< ITM configuration struct */ +#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */ + +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1) + #define MPU_BASE (SCS_BASE + 0x0D90) /*!< Memory Protection Unit */ + #define MPU ((MPU_Type*) MPU_BASE) /*!< Memory Protection Unit */ +#endif + + + +/******************************************************************************* + * Hardware Abstraction Layer + ******************************************************************************/ + + +#if defined ( __CC_ARM ) + #define __ASM __asm /*!< asm keyword for ARM Compiler */ + #define __INLINE __inline /*!< inline keyword for ARM Compiler */ + +#elif defined ( __ICCARM__ ) + #define __ASM __asm /*!< asm keyword for IAR Compiler */ + #define __INLINE inline /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */ + #define __NOP __no_operation /*!< no operation intrinsic in IAR Compiler */ + +#elif defined ( __GNUC__ ) + #define __ASM asm /*!< asm keyword for GNU Compiler */ + #define __INLINE inline /*!< inline keyword for GNU Compiler */ + +#endif + + +/* ################### Compiler specific Intrinsics ########################### */ + +#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ +/* ARM armcc specific functions */ + +#define __enable_fault_irq __enable_fiq +#define __disable_fault_irq __disable_fiq + +#define __NOP __nop +#define __WFI __wfi +#define __WFE __wfe +#define __SEV __sev +#define __ISB() __isb(0) +#define __DSB() __dsb(0) +#define __DMB() __dmb(0) +#define __REV __rev +#define __RBIT __rbit +#define __LDREXB(ptr) ((unsigned char ) __ldrex(ptr)) +#define __LDREXH(ptr) ((unsigned short) __ldrex(ptr)) +#define __LDREXW(ptr) ((unsigned int ) __ldrex(ptr)) +#define __STREXB(value, ptr) __strex(value, ptr) +#define __STREXH(value, ptr) __strex(value, ptr) +#define __STREXW(value, ptr) __strex(value, ptr) + + + /* intrinsic unsigned long long __ldrexd(volatile void *ptr) */ + /* intrinsic int __strexd(unsigned long long val, volatile void *ptr) */ + /* intrinsic void __enable_irq(); */ + /* intrinsic void __disable_irq(); */ + + +/** + * @brief Return the Process Stack Pointer + * + * @param none + * @return uint32_t ProcessStackPointer + * + * Return the actual process stack pointer + */ +extern uint32_t __get_PSP(void); + +/** + * @brief Set the Process Stack Pointer + * + * @param uint32_t Process Stack Pointer + * @return none + * + * Assign the value ProcessStackPointer to the MSP + * (process stack pointer) Cortex processor register + */ +extern void __set_PSP(uint32_t topOfProcStack); + +/** + * @brief Return the Main Stack Pointer + * + * @param none + * @return uint32_t Main Stack Pointer + * + * Return the current value of the MSP (main stack pointer) + * Cortex processor register + */ +extern uint32_t __get_MSP(void); + +/** + * @brief Set the Main Stack Pointer + * + * @param uint32_t Main Stack Pointer + * @return none + * + * Assign the value mainStackPointer to the MSP + * (main stack pointer) Cortex processor register + */ +extern void __set_MSP(uint32_t topOfMainStack); + +/** + * @brief Reverse byte order in unsigned short value + * + * @param uint16_t value to reverse + * @return uint32_t reversed value + * + * Reverse byte order in unsigned short value + */ +extern uint32_t __REV16(uint16_t value); + +/* + * @brief Reverse byte order in signed short value with sign extension to integer + * + * @param int16_t value to reverse + * @return int32_t reversed value + * + * Reverse byte order in signed short value with sign extension to integer + */ +extern int32_t __REVSH(int16_t value); + + +#if (__ARMCC_VERSION < 400000) + +/** + * @brief Remove the exclusive lock created by ldrex + * + * @param none + * @return none + * + * Removes the exclusive lock which is created by ldrex. + */ +extern void __CLREX(void); + +/** + * @brief Return the Base Priority value + * + * @param none + * @return uint32_t BasePriority + * + * Return the content of the base priority register + */ +extern uint32_t __get_BASEPRI(void); + +/** + * @brief Set the Base Priority value + * + * @param uint32_t BasePriority + * @return none + * + * Set the base priority register + */ +extern void __set_BASEPRI(uint32_t basePri); + +/** + * @brief Return the Priority Mask value + * + * @param none + * @return uint32_t PriMask + * + * Return the state of the priority mask bit from the priority mask + * register + */ +extern uint32_t __get_PRIMASK(void); + +/** + * @brief Set the Priority Mask value + * + * @param uint32_t PriMask + * @return none + * + * Set the priority mask bit in the priority mask register + */ +extern void __set_PRIMASK(uint32_t priMask); + +/** + * @brief Return the Fault Mask value + * + * @param none + * @return uint32_t FaultMask + * + * Return the content of the fault mask register + */ +extern uint32_t __get_FAULTMASK(void); + +/** + * @brief Set the Fault Mask value + * + * @param uint32_t faultMask value + * @return none + * + * Set the fault mask register + */ +extern void __set_FAULTMASK(uint32_t faultMask); + +/** + * @brief Return the Control Register value + * + * @param none + * @return uint32_t Control value + * + * Return the content of the control register + */ +extern uint32_t __get_CONTROL(void); + +/** + * @brief Set the Control Register value + * + * @param uint32_t Control value + * @return none + * + * Set the control register + */ +extern void __set_CONTROL(uint32_t control); + +#else /* (__ARMCC_VERSION >= 400000) */ + + +/** + * @brief Remove the exclusive lock created by ldrex + * + * @param none + * @return none + * + * Removes the exclusive lock which is created by ldrex. + */ +#define __CLREX __clrex + +/** + * @brief Return the Base Priority value + * + * @param none + * @return uint32_t BasePriority + * + * Return the content of the base priority register + */ +static __INLINE uint32_t __get_BASEPRI(void) +{ + register uint32_t __regBasePri __ASM("basepri"); + return(__regBasePri); +} + +/** + * @brief Set the Base Priority value + * + * @param uint32_t BasePriority + * @return none + * + * Set the base priority register + */ +static __INLINE void __set_BASEPRI(uint32_t basePri) +{ + register uint32_t __regBasePri __ASM("basepri"); + __regBasePri = (basePri & 0x1ff); +} + +/** + * @brief Return the Priority Mask value + * + * @param none + * @return uint32_t PriMask + * + * Return the state of the priority mask bit from the priority mask + * register + */ +static __INLINE uint32_t __get_PRIMASK(void) +{ + register uint32_t __regPriMask __ASM("primask"); + return(__regPriMask); +} + +/** + * @brief Set the Priority Mask value + * + * @param uint32_t PriMask + * @return none + * + * Set the priority mask bit in the priority mask register + */ +static __INLINE void __set_PRIMASK(uint32_t priMask) +{ + register uint32_t __regPriMask __ASM("primask"); + __regPriMask = (priMask); +} + +/** + * @brief Return the Fault Mask value + * + * @param none + * @return uint32_t FaultMask + * + * Return the content of the fault mask register + */ +static __INLINE uint32_t __get_FAULTMASK(void) +{ + register uint32_t __regFaultMask __ASM("faultmask"); + return(__regFaultMask); +} + +/** + * @brief Set the Fault Mask value + * + * @param uint32_t faultMask value + * @return none + * + * Set the fault mask register + */ +static __INLINE void __set_FAULTMASK(uint32_t faultMask) +{ + register uint32_t __regFaultMask __ASM("faultmask"); + __regFaultMask = (faultMask & 1); +} + +/** + * @brief Return the Control Register value + * + * @param none + * @return uint32_t Control value + * + * Return the content of the control register + */ +static __INLINE uint32_t __get_CONTROL(void) +{ + register uint32_t __regControl __ASM("control"); + return(__regControl); +} + +/** + * @brief Set the Control Register value + * + * @param uint32_t Control value + * @return none + * + * Set the control register + */ +static __INLINE void __set_CONTROL(uint32_t control) +{ + register uint32_t __regControl __ASM("control"); + __regControl = control; +} + +#endif /* __ARMCC_VERSION */ + + + +#elif (defined (__ICCARM__)) /*------------------ ICC Compiler -------------------*/ +/* IAR iccarm specific functions */ + +#define __enable_irq __enable_interrupt /*!< global Interrupt enable */ +#define __disable_irq __disable_interrupt /*!< global Interrupt disable */ + +static __INLINE void __enable_fault_irq() { __ASM ("cpsie f"); } +static __INLINE void __disable_fault_irq() { __ASM ("cpsid f"); } + +static __INLINE void __WFI() { __ASM ("wfi"); } +static __INLINE void __WFE() { __ASM ("wfe"); } +static __INLINE void __SEV() { __ASM ("sev"); } +static __INLINE void __CLREX() { __ASM ("clrex"); } + +/** + * @brief Return the Process Stack Pointer + * + * @param none + * @return uint32_t ProcessStackPointer + * + * Return the actual process stack pointer + */ +extern uint32_t __get_PSP(void); + +/** + * @brief Set the Process Stack Pointer + * + * @param uint32_t Process Stack Pointer + * @return none + * + * Assign the value ProcessStackPointer to the MSP + * (process stack pointer) Cortex processor register + */ +extern void __set_PSP(uint32_t topOfProcStack); + +/** + * @brief Return the Main Stack Pointer + * + * @param none + * @return uint32_t Main Stack Pointer + * + * Return the current value of the MSP (main stack pointer) + * Cortex processor register + */ +extern uint32_t __get_MSP(void); + +/** + * @brief Set the Main Stack Pointer + * + * @param uint32_t Main Stack Pointer + * @return none + * + * Assign the value mainStackPointer to the MSP + * (main stack pointer) Cortex processor register + */ +extern void __set_MSP(uint32_t topOfMainStack); + +/** + * @brief Reverse byte order in unsigned short value + * + * @param uint16_t value to reverse + * @return uint32_t reversed value + * + * Reverse byte order in unsigned short value + */ +extern uint32_t __REV16(uint16_t value); + +/** + * @brief Reverse bit order of value + * + * @param uint32_t value to reverse + * @return uint32_t reversed value + * + * Reverse bit order of value + */ +extern uint32_t __RBIT(uint32_t value); + +/** + * @brief LDR Exclusive + * + * @param uint8_t* address + * @return uint8_t value of (*address) + * + * Exclusive LDR command + */ +extern uint8_t __LDREXB(uint8_t *addr); + +/** + * @brief LDR Exclusive + * + * @param uint16_t* address + * @return uint16_t value of (*address) + * + * Exclusive LDR command + */ +extern uint16_t __LDREXH(uint16_t *addr); + +/** + * @brief LDR Exclusive + * + * @param uint32_t* address + * @return uint32_t value of (*address) + * + * Exclusive LDR command + */ +extern uint32_t __LDREXW(uint32_t *addr); + +/** + * @brief STR Exclusive + * + * @param uint8_t *address + * @param uint8_t value to store + * @return uint32_t successful / failed + * + * Exclusive STR command + */ +extern uint32_t __STREXB(uint8_t value, uint8_t *addr); + +/** + * @brief STR Exclusive + * + * @param uint16_t *address + * @param uint16_t value to store + * @return uint32_t successful / failed + * + * Exclusive STR command + */ +extern uint32_t __STREXH(uint16_t value, uint16_t *addr); + +/** + * @brief STR Exclusive + * + * @param uint32_t *address + * @param uint32_t value to store + * @return uint32_t successful / failed + * + * Exclusive STR command + */ +extern uint32_t __STREXW(uint32_t value, uint32_t *addr); + + +/* intrinsic void __set_PRIMASK(); */ +/* intrinsic void __get_PRIMASK(); */ +/* intrinsic void __set_FAULTMASK(); */ +/* intrinsic void __get_FAULTMASK(); */ +/* intrinsic uint32_t __REV(uint32_t value); */ +/* intrinsic uint32_t __REVSH(uint32_t value); */ +/* intrinsic unsigned long __STREX(unsigned long, unsigned long); */ +/* intrinsic unsigned long __LDREX(unsigned long *); */ + + + +#elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/ +/* GNU gcc specific functions */ + +static __INLINE void __NOP() { __ASM volatile ("nop"); } +static __INLINE void __enable_irq() { __ASM volatile ("cpsie i"); } +static __INLINE void __disable_irq() { __ASM volatile ("cpsid i"); } + +static __INLINE void __enable_fault_irq() { __ASM volatile ("cpsie f"); } +static __INLINE void __disable_fault_irq() { __ASM volatile ("cpsid f"); } + +static __INLINE void __WFI() { __ASM volatile ("wfi"); } +static __INLINE void __WFE() { __ASM volatile ("wfe"); } +static __INLINE void __SEV() { __ASM volatile ("sev"); } +static __INLINE void __ISB(arg) { __ASM volatile ("isb"); } +static __INLINE void __DSB(arg) { __ASM volatile ("dsb"); } +static __INLINE void __DMB(arg) { __ASM volatile ("dmb"); } +static __INLINE void __CLREX() { __ASM volatile ("clrex"); } + + +/** + * @brief Return the Process Stack Pointer + * + * @param none + * @return uint32_t ProcessStackPointer + * + * Return the actual process stack pointer + */ +extern uint32_t __get_PSP(void); + +/** + * @brief Set the Process Stack Pointer + * + * @param uint32_t Process Stack Pointer + * @return none + * + * Assign the value ProcessStackPointer to the MSP + * (process stack pointer) Cortex processor register + */ +extern void __set_PSP(uint32_t topOfProcStack); + +/** + * @brief Return the Main Stack Pointer + * + * @param none + * @return uint32_t Main Stack Pointer + * + * Return the current value of the MSP (main stack pointer) + * Cortex processor register + */ +extern uint32_t __get_MSP(void); + +/** + * @brief Set the Main Stack Pointer + * + * @param uint32_t Main Stack Pointer + * @return none + * + * Assign the value mainStackPointer to the MSP + * (main stack pointer) Cortex processor register + */ +extern void __set_MSP(uint32_t topOfMainStack); + +/** + * @brief Return the Base Priority value + * + * @param none + * @return uint32_t BasePriority + * + * Return the content of the base priority register + */ +extern uint32_t __get_BASEPRI(void); + +/** + * @brief Set the Base Priority value + * + * @param uint32_t BasePriority + * @return none + * + * Set the base priority register + */ +extern void __set_BASEPRI(uint32_t basePri); + +/** + * @brief Return the Priority Mask value + * + * @param none + * @return uint32_t PriMask + * + * Return the state of the priority mask bit from the priority mask + * register + */ +extern uint32_t __get_PRIMASK(void); + +/** + * @brief Set the Priority Mask value + * + * @param uint32_t PriMask + * @return none + * + * Set the priority mask bit in the priority mask register + */ +extern void __set_PRIMASK(uint32_t priMask); + +/** + * @brief Return the Fault Mask value + * + * @param none + * @return uint32_t FaultMask + * + * Return the content of the fault mask register + */ +extern uint32_t __get_FAULTMASK(void); + +/** + * @brief Set the Fault Mask value + * + * @param uint32_t faultMask value + * @return none + * + * Set the fault mask register + */ +extern void __set_FAULTMASK(uint32_t faultMask); + +/** + * @brief Return the Control Register value +* +* @param none +* @return uint32_t Control value + * + * Return the content of the control register + */ +extern uint32_t __get_CONTROL(void); + +/** + * @brief Set the Control Register value + * + * @param uint32_t Control value + * @return none + * + * Set the control register + */ +extern void __set_CONTROL(uint32_t control); + +/** + * @brief Reverse byte order in integer value + * + * @param uint32_t value to reverse + * @return uint32_t reversed value + * + * Reverse byte order in integer value + */ +extern uint32_t __REV(uint32_t value); + +/** + * @brief Reverse byte order in unsigned short value + * + * @param uint16_t value to reverse + * @return uint32_t reversed value + * + * Reverse byte order in unsigned short value + */ +extern uint32_t __REV16(uint16_t value); + +/* + * Reverse byte order in signed short value with sign extension to integer + * + * @param int16_t value to reverse + * @return int32_t reversed value + * + * @brief Reverse byte order in signed short value with sign extension to integer + */ +extern int32_t __REVSH(int16_t value); + +/** + * @brief Reverse bit order of value + * + * @param uint32_t value to reverse + * @return uint32_t reversed value + * + * Reverse bit order of value + */ +extern uint32_t __RBIT(uint32_t value); + +/** + * @brief LDR Exclusive + * + * @param uint8_t* address + * @return uint8_t value of (*address) + * + * Exclusive LDR command + */ +extern uint8_t __LDREXB(uint8_t *addr); + +/** + * @brief LDR Exclusive + * + * @param uint16_t* address + * @return uint16_t value of (*address) + * + * Exclusive LDR command + */ +extern uint16_t __LDREXH(uint16_t *addr); + +/** + * @brief LDR Exclusive + * + * @param uint32_t* address + * @return uint32_t value of (*address) + * + * Exclusive LDR command + */ +extern uint32_t __LDREXW(uint32_t *addr); + +/** + * @brief STR Exclusive + * + * @param uint8_t *address + * @param uint8_t value to store + * @return uint32_t successful / failed + * + * Exclusive STR command + */ +extern uint32_t __STREXB(uint8_t value, uint8_t *addr); + +/** + * @brief STR Exclusive + * + * @param uint16_t *address + * @param uint16_t value to store + * @return uint32_t successful / failed + * + * Exclusive STR command + */ +extern uint32_t __STREXH(uint16_t value, uint16_t *addr); + +/** + * @brief STR Exclusive + * + * @param uint32_t *address + * @param uint32_t value to store + * @return uint32_t successful / failed + * + * Exclusive STR command + */ +extern uint32_t __STREXW(uint32_t value, uint32_t *addr); + + +#endif + + + +/* ########################## NVIC functions #################################### */ + +/** + * @brief Set the Priority Grouping in NVIC Interrupt Controller + * + * @param uint32_t priority_grouping is priority grouping field + * @return + * + * Set the priority grouping field using the required unlock sequence. + * The parameter priority_grouping is assigned to the field + * SCB->AIRCR [10:8] PRIGROUP field. + */ +static __INLINE void NVIC_SetPriorityGrouping(uint32_t priority_grouping) +{ + uint32_t reg_value=0; + + reg_value = SCB->AIRCR; /* read old register configuration */ + reg_value &= ~((0xFFFFU << 16) | (0x0F << 8)); /* clear bits to change */ + reg_value = ((reg_value | NVIC_AIRCR_VECTKEY | (priority_grouping << 8))); /* Insert write key and priorty group */ + SCB->AIRCR = reg_value; +} + +/** + * @brief Enable Interrupt in NVIC Interrupt Controller + * + * @param IRQn_Type IRQn specifies the interrupt number + * @return none + * + * Enable a device specific interupt in the NVIC interrupt controller. + * The interrupt number cannot be a negative value. + */ +static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) +{ + NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* enable interrupt */ +} + +/** + * @brief Disable the interrupt line for external interrupt specified + * + * @param IRQn_Type IRQn is the positive number of the external interrupt + * @return none + * + * Disable a device specific interupt in the NVIC interrupt controller. + * The interrupt number cannot be a negative value. + */ +static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) +{ + NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* disable interrupt */ +} + +/** + * @brief Read the interrupt pending bit for a device specific interrupt source + * + * @param IRQn_Type IRQn is the number of the device specifc interrupt + * @return IRQn_Type Number of pending interrupt or zero + * + * Read the pending register in NVIC and return the number of the + * specified interrupt if its status is pending, otherwise it returns + * zero. The interrupt number cannot be a negative value. + */ +static __INLINE IRQn_Type NVIC_GetPendingIRQ(IRQn_Type IRQn) +{ + return((IRQn_Type) (NVIC->ISPR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))); /* Return Interrupt bit or 'zero' */ +} + +/** + * @brief Set the pending bit for an external interrupt + * + * @param IRQn_Type IRQn is the Number of the interrupt + * @return none + * + * Set the pending bit for the specified interrupt. + * The interrupt number cannot be a negative value. + */ +static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) +{ + NVIC->ISPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* set interrupt pending */ +} + +/** + * @brief Clear the pending bit for an external interrupt + * + * @param IRQn_Type IRQn is the Number of the interrupt + * @return none + * + * Clear the pending bit for the specified interrupt. + * The interrupt number cannot be a negative value. + */ +static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) +{ + NVIC->ICPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */ +} + +/** + * @brief Read the active bit for an external interrupt + * + * @param IRQn_Type IRQn is the Number of the interrupt + * @return IRQn_Type Number of pending interrupt or zero + * + * Read the active register in NVIC and returns the number of the + * specified interrupt if its status is active, otherwise it + * returns zero. The interrupt number cannot be a negative value. + */ +static __INLINE IRQn_Type NVIC_GetActive(IRQn_Type IRQn) +{ + return((IRQn_Type)(NVIC->IABR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))); /* Return Interruptnumber or 'zero' */ +} + +/** + * @brief Set the priority for an interrupt + * + * @param IRQn_Type IRQn is the Number of the interrupt + * @param priority is the priority for the interrupt + * @return none + * + * Set the priority for the specified interrupt. The interrupt + * number can be positive to specify an external (device specific) + * interrupt, or negative to specify an internal (core) interrupt. \n + * + * Note: The priority cannot be set for every core interrupt. + */ +static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, int32_t priority) +{ + if(IRQn < 0) { + SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M3 System Interrupts */ + else { + //NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for device specific Interrupts */ + NVIC->IP[(uint32_t)(IRQn)] = (priority & 0xff); } /* set Priority for device specific Interrupts */ +} + +/** + * @brief Read the priority for an interrupt + * + * @param IRQn_Type IRQn is the Number of the interrupt + * @return priority is the priority for the interrupt + * + * Read the priority for the specified interrupt. The interrupt + * number can be positive to specify an external (device specific) + * interrupt, or negative to specify an internal (core) interrupt. + * + * The returned priority value is automatically aligned to the implemented + * priority bits of the microcontroller. + * + * Note: The priority cannot be set for every core interrupt. + */ +static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn) +{ + + if(IRQn < 0) { + return((uint32_t)(SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M3 system interrupts */ + else { + return((uint32_t)(NVIC->IP[(uint32_t)(IRQn)] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */ +} + + + +/* ################################## SysTick function ############################################ */ + +#if (!defined (__Vendor_SysTickConfig)) || (__Vendor_SysTickConfig == 0) + +/* SysTick constants */ +#define SYSTICK_ENABLE 0 /* Config-Bit to start or stop the SysTick Timer */ +#define SYSTICK_TICKINT 1 /* Config-Bit to enable or disable the SysTick interrupt */ +#define SYSTICK_CLKSOURCE 2 /* Clocksource has the offset 2 in SysTick Control and Status Register */ +#define SYSTICK_MAXCOUNT ((1<<24) -1) /* SysTick MaxCount */ + +/** + * @brief Initialize and start the SysTick counter and its interrupt. + * + * @param uint32_t ticks is the number of ticks between two interrupts + * @return none + * + * Initialise the system tick timer and its interrupt and start the + * system tick timer / counter in free running mode to generate + * periodical interrupts. + */ +static __INLINE uint32_t SysTick_Config(uint32_t ticks) +{ + if (ticks > SYSTICK_MAXCOUNT) return (1); /* Reload value impossible */ + + SysTick->LOAD = (ticks & SYSTICK_MAXCOUNT) - 1; /* set reload register */ + NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */ + SysTick->VAL = (0x00); /* Load the SysTick Counter Value */ + SysTick->CTRL = (1 << SYSTICK_CLKSOURCE) | (1<AIRCR = (NVIC_AIRCR_VECTKEY | (SCB->AIRCR & (0x700)) | (1<DEMCR & CoreDebug_DEMCR_TRCENA) && + (ITM->TCR & ITM_TCR_ITMENA) && + (ITM->TER & (1UL << 0)) ) + { + while (ITM->PORT[0].u32 == 0); + ITM->PORT[0].u8 = (uint8_t) ch; + } + return (ch); +} + +#endif + +/*lint -restore */ diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/components/hx8347/hx8347.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/components/hx8347/hx8347.c new file mode 100644 index 000000000..6c99d52c0 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/components/hx8347/hx8347.c @@ -0,0 +1,376 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// HX8347 driver +/// +/// !Usage +/// +/// Explanation on the usage of the code made available through the header file. +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ +#include +#include + +#ifdef BOARD_LCD_HX8347 + +#include "hx8347.h" + +//------------------------------------------------------------------------------ +// Types +//------------------------------------------------------------------------------ +typedef volatile unsigned short REG16; + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ +/// LCD index register address +#define LCD_IR(baseAddr) (*((REG16 *)(baseAddr))) +/// LCD status register address +#define LCD_SR(baseAddr) (*((REG16 *)(baseAddr))) +/// LCD data address +#define LCD_D(baseAddr) (*((REG16 *)((unsigned int)(baseAddr) + BOARD_LCD_RS))) + +/// HX8347 ID code +#define HX8347_HIMAXID_CODE 0x47 + +/// HX8347 LCD Registers +#define HX8347_R00H 0x00 +#define HX8347_R01H 0x01 +#define HX8347_R02H 0x02 +#define HX8347_R03H 0x03 +#define HX8347_R04H 0x04 +#define HX8347_R05H 0x05 +#define HX8347_R06H 0x06 +#define HX8347_R07H 0x07 +#define HX8347_R08H 0x08 +#define HX8347_R09H 0x09 +#define HX8347_R0AH 0x0A +#define HX8347_R0CH 0x0C +#define HX8347_R0DH 0x0D +#define HX8347_R0EH 0x0E +#define HX8347_R0FH 0x0F +#define HX8347_R10H 0x10 +#define HX8347_R11H 0x11 +#define HX8347_R12H 0x12 +#define HX8347_R13H 0x13 +#define HX8347_R14H 0x14 +#define HX8347_R15H 0x15 +#define HX8347_R16H 0x16 +#define HX8347_R18H 0x18 +#define HX8347_R19H 0x19 +#define HX8347_R1AH 0x1A +#define HX8347_R1BH 0x1B +#define HX8347_R1CH 0x1C +#define HX8347_R1DH 0x1D +#define HX8347_R1EH 0x1E +#define HX8347_R1FH 0x1F +#define HX8347_R20H 0x20 +#define HX8347_R21H 0x21 +#define HX8347_R22H 0x22 +#define HX8347_R23H 0x23 +#define HX8347_R24H 0x24 +#define HX8347_R25H 0x25 +#define HX8347_R26H 0x26 +#define HX8347_R27H 0x27 +#define HX8347_R28H 0x28 +#define HX8347_R29H 0x29 +#define HX8347_R2AH 0x2A +#define HX8347_R2BH 0x2B +#define HX8347_R2CH 0x2C +#define HX8347_R2DH 0x2D +#define HX8347_R35H 0x35 +#define HX8347_R36H 0x36 +#define HX8347_R37H 0x37 +#define HX8347_R38H 0x38 +#define HX8347_R39H 0x39 +#define HX8347_R3AH 0x3A +#define HX8347_R3BH 0x3B +#define HX8347_R3CH 0x3C +#define HX8347_R3DH 0x3D +#define HX8347_R3EH 0x3E +#define HX8347_R40H 0x40 +#define HX8347_R41H 0x41 +#define HX8347_R42H 0x42 +#define HX8347_R43H 0x43 +#define HX8347_R44H 0x44 +#define HX8347_R45H 0x45 +#define HX8347_R46H 0x46 +#define HX8347_R47H 0x47 +#define HX8347_R48H 0x48 +#define HX8347_R49H 0x49 +#define HX8347_R4AH 0x4A +#define HX8347_R4BH 0x4B +#define HX8347_R4CH 0x4C +#define HX8347_R4DH 0x4D +#define HX8347_R4EH 0x4E +#define HX8347_R4FH 0x4F +#define HX8347_R50H 0x50 +#define HX8347_R51H 0x51 +#define HX8347_R64H 0x64 +#define HX8347_R65H 0x65 +#define HX8347_R66H 0x66 +#define HX8347_R67H 0x67 +#define HX8347_R70H 0x70 +#define HX8347_R72H 0x72 +#define HX8347_R90H 0x90 +#define HX8347_R91H 0x91 +#define HX8347_R93H 0x93 +#define HX8347_R94H 0x94 +#define HX8347_R95H 0x95 + +//------------------------------------------------------------------------------ +// External functions +//------------------------------------------------------------------------------ +// External delay 1 ms function +#include "FreeRTOS.h" +#include "task.h" +#define Delay(ms) vTaskDelay(ms/portTICK_RATE_MS) + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Write data to LCD Register. +/// \param pLcdBase LCD base address. +/// \param reg Register address. +/// \param data Data to be written. +//------------------------------------------------------------------------------ +void LCD_WriteReg(void *pLcdBase, unsigned char reg, unsigned short data) +{ + LCD_IR(pLcdBase) = reg; + LCD_D(pLcdBase) = data; +} + +//------------------------------------------------------------------------------ +/// Read data from LCD Register. +/// \param pLcdBase LCD base address. +/// \param reg Register address. +/// \return data Data to be read. +//------------------------------------------------------------------------------ +unsigned short LCD_ReadReg(void *pLcdBase, unsigned char reg) +{ + LCD_IR(pLcdBase) = reg; + return LCD_D(pLcdBase); +} + +//------------------------------------------------------------------------------ +/// Read LCD status Register. +/// \param pLcdBase LCD base address. +/// \param reg Register address. +/// \return data Status Data. +//------------------------------------------------------------------------------ +unsigned short LCD_ReadStatus(void *pLcdBase) +{ + return LCD_SR(pLcdBase); +} + +//------------------------------------------------------------------------------ +/// Prepare to write GRAM data. +/// \param pLcdBase LCD base address. +//------------------------------------------------------------------------------ +void LCD_WriteRAM_Prepare(void *pLcdBase) +{ + LCD_IR(pLcdBase) = HX8347_R22H; +} + +//------------------------------------------------------------------------------ +/// Write data to LCD GRAM. +/// \param pLcdBase LCD base address. +/// \param color 16-bits RGB color. +//------------------------------------------------------------------------------ +void LCD_WriteRAM(void *pLcdBase, unsigned short color) +{ + // Write 16-bit GRAM Reg + LCD_D(pLcdBase) = color; +} + +//------------------------------------------------------------------------------ +/// Read GRAM data. +/// \param pLcdBase LCD base address. +/// \return 16-bits RGB color. +//------------------------------------------------------------------------------ +unsigned short LCD_ReadRAM(void *pLcdBase) +{ + // Read 16-bit GRAM Reg + return LCD_D(pLcdBase); +} + +//------------------------------------------------------------------------------ +/// Dump register data. +/// \param pLcdBase LCD base address. +/// \param startAddr Register start address. +/// \param endAddr Register end address. +//------------------------------------------------------------------------------ +void LCD_DumpReg(void *pLcdBase, unsigned char startAddr, unsigned char endAddr) +{ + unsigned short tmp; + unsigned char addr; + + for (addr = startAddr; addr <= endAddr; addr++) { + + tmp = LCD_ReadReg(pLcdBase, addr); + printf("LCD.r 0x%x = 0x%x\n\r", addr, tmp); + } +} + +//------------------------------------------------------------------------------ +/// Initialize the LCD controller. +/// \param pLcdBase LCD base address. +//------------------------------------------------------------------------------ +void LCD_Initialize(void *pLcdBase) +{ + unsigned short chipid; + + // Check HX8347 chipid + chipid = LCD_ReadReg(pLcdBase, HX8347_R67H); + if(chipid != HX8347_HIMAXID_CODE) { + + printf("Read HX8347 chip ID error, skip initialization.\r\n"); + return ; + } + + // Start internal OSC + LCD_WriteReg(pLcdBase, HX8347_R19H, 0x49); // OSCADJ=10 0000, OSD_EN=1 //60Hz + LCD_WriteReg(pLcdBase, HX8347_R93H, 0x0C); // RADJ=1100 + + // Power on flow + LCD_WriteReg(pLcdBase, HX8347_R44H, 0x4D); // VCM=100 1101 + LCD_WriteReg(pLcdBase, HX8347_R45H, 0x11); // VDV=1 0001 + LCD_WriteReg(pLcdBase, HX8347_R20H, 0x40); // BT=0100 + LCD_WriteReg(pLcdBase, HX8347_R1DH, 0x07); // VC1=111 + LCD_WriteReg(pLcdBase, HX8347_R1EH, 0x00); // VC3=000 + LCD_WriteReg(pLcdBase, HX8347_R1FH, 0x04); // VRH=0100 + + LCD_WriteReg(pLcdBase, HX8347_R1CH, 0x04); // AP=100 + LCD_WriteReg(pLcdBase, HX8347_R1BH, 0x10); // GASENB=0, PON=1, DK=0, XDK=0, DDVDH_TRI=0, STB=0 + Delay(50); + + LCD_WriteReg(pLcdBase, HX8347_R43H, 0x80); // Set VCOMG=1 + Delay(50); + + // Gamma for CMO 2.8 + LCD_WriteReg(pLcdBase, HX8347_R46H, 0x95); + LCD_WriteReg(pLcdBase, HX8347_R47H, 0x51); + LCD_WriteReg(pLcdBase, HX8347_R48H, 0x00); + LCD_WriteReg(pLcdBase, HX8347_R49H, 0x36); + LCD_WriteReg(pLcdBase, HX8347_R4AH, 0x11); + LCD_WriteReg(pLcdBase, HX8347_R4BH, 0x66); + LCD_WriteReg(pLcdBase, HX8347_R4CH, 0x14); + LCD_WriteReg(pLcdBase, HX8347_R4DH, 0x77); + LCD_WriteReg(pLcdBase, HX8347_R4EH, 0x13); + LCD_WriteReg(pLcdBase, HX8347_R4FH, 0x4C); + LCD_WriteReg(pLcdBase, HX8347_R50H, 0x46); + LCD_WriteReg(pLcdBase, HX8347_R51H, 0x46); + + //240x320 window setting + LCD_WriteReg(pLcdBase, HX8347_R02H, 0x00); // Column address start2 + LCD_WriteReg(pLcdBase, HX8347_R03H, 0x00); // Column address start1 + LCD_WriteReg(pLcdBase, HX8347_R04H, 0x00); // Column address end2 + LCD_WriteReg(pLcdBase, HX8347_R05H, 0xEF); // Column address end1 + LCD_WriteReg(pLcdBase, HX8347_R06H, 0x00); // Row address start2 + LCD_WriteReg(pLcdBase, HX8347_R07H, 0x00); // Row address start1 + LCD_WriteReg(pLcdBase, HX8347_R08H, 0x01); // Row address end2 + LCD_WriteReg(pLcdBase, HX8347_R09H, 0x3F); // Row address end1 + + // Display Setting + LCD_WriteReg(pLcdBase, HX8347_R01H, 0x06); // IDMON=0, INVON=1, NORON=1, PTLON=0 + LCD_WriteReg(pLcdBase, HX8347_R16H, 0xC8); // MY=1, MX=1, MV=0, BGR=1 + LCD_WriteReg(pLcdBase, HX8347_R23H, 0x95); // N_DC=1001 0101 + LCD_WriteReg(pLcdBase, HX8347_R24H, 0x95); // P_DC=1001 0101 + LCD_WriteReg(pLcdBase, HX8347_R25H, 0xFF); // I_DC=1111 1111 + LCD_WriteReg(pLcdBase, HX8347_R27H, 0x06); // N_BP=0000 0110 + LCD_WriteReg(pLcdBase, HX8347_R28H, 0x06); // N_FP=0000 0110 + LCD_WriteReg(pLcdBase, HX8347_R29H, 0x06); // P_BP=0000 0110 + LCD_WriteReg(pLcdBase, HX8347_R2AH, 0x06); // P_FP=0000 0110 + LCD_WriteReg(pLcdBase, HX8347_R2CH, 0x06); // I_BP=0000 0110 + LCD_WriteReg(pLcdBase, HX8347_R2DH, 0x06); // I_FP=0000 0110 + LCD_WriteReg(pLcdBase, HX8347_R3AH, 0x01); // N_RTN=0000, N_NW=001 + LCD_WriteReg(pLcdBase, HX8347_R3BH, 0x01); // P_RTN=0000, P_NW=001 + LCD_WriteReg(pLcdBase, HX8347_R3CH, 0xF0); // I_RTN=1111, I_NW=000 + LCD_WriteReg(pLcdBase, HX8347_R3DH, 0x00); // DIV=00 + LCD_WriteReg(pLcdBase, HX8347_R3EH, 0x38); // SON=38h + LCD_WriteReg(pLcdBase, HX8347_R40H, 0x0F); // GDON=0Fh + LCD_WriteReg(pLcdBase, HX8347_R41H, 0xF0); // GDOF=F0h +} + +//------------------------------------------------------------------------------ +/// Turn on the LCD. +/// \param pLcdBase LCD base address. +//------------------------------------------------------------------------------ +void LCD_On(void *pLcdBase) +{ + // Display ON Setting + LCD_WriteReg(pLcdBase, HX8347_R90H, 0x7F); // SAP=0111 1111 + LCD_WriteReg(pLcdBase, HX8347_R26H, 0x04); // GON=0, DTE=0, D=01 + Delay(100); + LCD_WriteReg(pLcdBase, HX8347_R26H, 0x24); // GON=1, DTE=0, D=01 + LCD_WriteReg(pLcdBase, HX8347_R26H, 0x2C); // GON=1, DTE=0, D=11 + Delay(100); + LCD_WriteReg(pLcdBase, HX8347_R26H, 0x3C); // GON=1, DTE=1, D=11 +} + +//------------------------------------------------------------------------------ +/// Turn off the LCD. +/// \param pLcdBase LCD base address. +//------------------------------------------------------------------------------ +void LCD_Off(void *pLcdBase) +{ + LCD_WriteReg(pLcdBase, HX8347_R90H, 0x00); // SAP=0000 0000 + LCD_WriteReg(pLcdBase, HX8347_R26H, 0x00); // GON=0, DTE=0, D=00 +} + +//------------------------------------------------------------------------------ +/// Set cursor of LCD srceen. +/// \param pLcdBase LCD base address. +/// \param x X-coordinate of upper-left corner on LCD. +/// \param y Y-coordinate of upper-left corner on LCD. +//------------------------------------------------------------------------------ +void LCD_SetCursor(void *pLcdBase, unsigned short x, unsigned short y) +{ + unsigned char x1, x2, y1, y2; + + x1 = x & 0xff; + x2 = (x & 0xff00) >>8; + y1 = y & 0xff; + y2 = (y & 0xff00) >>8; + LCD_WriteReg(pLcdBase, HX8347_R02H, x2); // column high + LCD_WriteReg(pLcdBase, HX8347_R03H, x1); // column low + LCD_WriteReg(pLcdBase, HX8347_R06H, y2); // row high + LCD_WriteReg(pLcdBase, HX8347_R07H, y1); // row low +} +#endif //#ifdef BOARD_LCD_HX8347 diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/components/hx8347/hx8347.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/components/hx8347/hx8347.h new file mode 100644 index 000000000..6affa9ea9 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/components/hx8347/hx8347.h @@ -0,0 +1,87 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Definition of methods for HX8347 driver. +/// +/// !!!Usage +/// +/// -# LCD_WriteReg +/// -# LCD_ReadReg +/// -# LCD_ReadStatus +/// -# LCD_DumpReg +/// -# LCD_WriteRAM_Prepare +/// -# LCD_WriteRAM +/// -# LCD_ReadRAM +/// -# LCD_Initialize +/// -# LCD_SetCursor +/// -# LCD_On +/// -# LCD_Off +//------------------------------------------------------------------------------ + +#ifndef HX8347_H +#define HX8347_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ +#include + +#ifdef BOARD_LCD_HX8347 + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ +/// Convert 24-bits color to 16-bits color +#define RGB24ToRGB16(color) (((color >> 8) & 0xF800) | \ + ((color >> 5) & 0x7E0) | \ + ((color >> 3) & 0x1F)) + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +void LCD_WriteReg(void *pLcdBase, unsigned char reg, unsigned short data); +unsigned short LCD_ReadReg(void *pLcdBase, unsigned char reg); +unsigned short LCD_ReadStatus(void *pLcdBase); +void LCD_DumpReg(void *pLcdBase, unsigned char startAddr, unsigned char endAddr); +void LCD_WriteRAM_Prepare(void *pLcdBase); +void LCD_WriteRAM(void *pLcdBase, unsigned short color); +unsigned short LCD_ReadRAM(void *pLcdBase); +void LCD_Initialize(void *pLcdBase); +void LCD_SetCursor(void *pLcdBase, unsigned short x, unsigned short y); +void LCD_On(void *pLcdBase); +void LCD_Off(void *pLcdBase); + +#endif //#ifdef BOARD_LCD_HX8347 +#endif //#ifndef HX8347_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/color.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/color.h new file mode 100644 index 000000000..68128c28d --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/color.h @@ -0,0 +1,132 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef COLOR_H +#define COLOR_H + +//------------------------------------------------------------------------------ +/// RGB 24 Bpp +/// RGB 888 +/// R7R6R5R4 R3R2R1R0 G7G6G5G4 G3G2G1G0 B7B6B5B4 B3B2B1B0 +//------------------------------------------------------------------------------ +#define COLOR_BLACK 0x000000 +#define COLOR_WHITE 0xFFFFFF + +#define COLOR_BLUE 0x0000FF +#define COLOR_GREEN 0x00FF00 +#define COLOR_RED 0xFF0000 + +#define COLOR_NAVY 0x000080 +#define COLOR_DARKBLUE 0x00008B +#define COLOR_DARKGREEN 0x006400 +#define COLOR_DARKCYAN 0x008B8B +#define COLOR_CYAN 0x00FFFF +#define COLOR_TURQUOISE 0x40E0D0 +#define COLOR_INDIGO 0x4B0082 +#define COLOR_DARKRED 0x800000 +#define COLOR_OLIVE 0x808000 +#define COLOR_GRAY 0x808080 +#define COLOR_SKYBLUE 0x87CEEB +#define COLOR_BLUEVIOLET 0x8A2BE2 +#define COLOR_LIGHTGREEN 0x90EE90 +#define COLOR_DARKVIOLET 0x9400D3 +#define COLOR_YELLOWGREEN 0x9ACD32 +#define COLOR_BROWN 0xA52A2A +#define COLOR_DARKGRAY 0xA9A9A9 +#define COLOR_SIENNA 0xA0522D +#define COLOR_LIGHTBLUE 0xADD8E6 +#define COLOR_GREENYELLOW 0xADFF2F +#define COLOR_SILVER 0xC0C0C0 +#define COLOR_LIGHTGREY 0xD3D3D3 +#define COLOR_LIGHTCYAN 0xE0FFFF +#define COLOR_VIOLET 0xEE82EE +#define COLOR_AZUR 0xF0FFFF +#define COLOR_BEIGE 0xF5F5DC +#define COLOR_MAGENTA 0xFF00FF +#define COLOR_TOMATO 0xFF6347 +#define COLOR_GOLD 0xFFD700 +#define COLOR_ORANGE 0xFFA500 +#define COLOR_SNOW 0xFFFAFA +#define COLOR_YELLOW 0xFFFF00 + +#endif // #define COLOR_H + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/draw.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/draw.h new file mode 100644 index 000000000..f74e04b70 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/draw.h @@ -0,0 +1,81 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Provides simple drawing function to use with the LCD. +/// +/// !!!Usage +/// +/// -# Use LCDD_Fill to fill the LCD buffer with a specific color. +/// -# Draw a pixel on the screen at the specified coordinates using +/// LCDD_DrawPixel. +/// -# Draw a rectangle with LCDD_DrawRectangle. +/// -# Draw a string on the LCD with LCDD_DrawString. +//------------------------------------------------------------------------------ + +#ifndef DRAW_H +#define DRAW_H + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void LCDD_Fill(void *pBuffer, unsigned int color); + +extern void LCDD_DrawPixel( + void *pBuffer, + unsigned int x, + unsigned int y, + unsigned int c); + +extern void LCDD_DrawRectangle( + void *pBuffer, + unsigned int x, + unsigned int y, + unsigned int width, + unsigned int height, + unsigned int color); + +extern void LCDD_DrawString( + void *pBuffer, + unsigned int x, + unsigned int y, + const char *pString, + unsigned int color); + +extern void LCDD_GetStringSize( + const char *pString, + unsigned int *pWidth, + unsigned int *pHeight); + +#endif //#ifndef DRAW_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/draw_hx8347.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/draw_hx8347.c new file mode 100644 index 000000000..87e07a826 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/draw_hx8347.c @@ -0,0 +1,181 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "draw.h" +#include "font.h" +#include +#include +#include + +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Fills the given LCD buffer with a particular color. +/// Only works in 24-bits packed mode for now. +/// \param pBuffer LCD buffer to fill. +/// \param color Fill color. +//------------------------------------------------------------------------------ +void LCDD_Fill(void *pBuffer, unsigned int color) +{ + unsigned int i; + unsigned short color16 = RGB24ToRGB16(color); + + + LCD_SetCursor((void *)BOARD_LCD_BASE, 0, 0); + LCD_WriteRAM_Prepare((void *)BOARD_LCD_BASE); + for (i = 0; i < (BOARD_LCD_WIDTH * BOARD_LCD_HEIGHT); i++) { + + LCD_WriteRAM((void *)BOARD_LCD_BASE, color16); + } +} + +//------------------------------------------------------------------------------ +/// Sets the specified pixel to the given color. +/// !!! Only works in 24-bits packed mode for now. !!! +/// \param pBuffer LCD buffer to draw on. +/// \param x X-coordinate of pixel. +/// \param y Y-coordinate of pixel. +/// \param color Pixel color. +//------------------------------------------------------------------------------ +void LCDD_DrawPixel( + void *pBuffer, + unsigned int x, + unsigned int y, + unsigned int color) +{ + unsigned short color16 = RGB24ToRGB16(color); + + LCD_SetCursor(pBuffer, x, y); + LCD_WriteRAM_Prepare(pBuffer); + LCD_WriteRAM(pBuffer, color16); +} + +//------------------------------------------------------------------------------ +/// Draws a rectangle inside a LCD buffer, at the given coordinates. +/// \param pBuffer LCD buffer to draw on. +/// \param x X-coordinate of upper-left rectangle corner. +/// \param y Y-coordinate of upper-left rectangle corner. +/// \param width Rectangle width in pixels. +/// \param height Rectangle height in pixels. +/// \param color Rectangle color. +//------------------------------------------------------------------------------ +void LCDD_DrawRectangle( + void *pBuffer, + unsigned int x, + unsigned int y, + unsigned int width, + unsigned int height, + unsigned int color) +{ + unsigned int rx, ry; + + for (ry=0; ry < height; ry++) { + + for (rx=0; rx < width; rx++) { + + LCDD_DrawPixel(pBuffer, x+rx, y+ry, color); + } + } +} + +//------------------------------------------------------------------------------ +/// Draws a string inside a LCD buffer, at the given coordinates. Line breaks +/// will be honored. +/// \param pBuffer Buffer to draw on. +/// \param x X-coordinate of string top-left corner. +/// \param y Y-coordinate of string top-left corner. +/// \param pString String to display. +/// \param color String color. +//------------------------------------------------------------------------------ +void LCDD_DrawString( + void *pBuffer, + unsigned int x, + unsigned int y, + const char *pString, + unsigned int color) +{ + unsigned xorg = x; + + while (*pString != 0) { + if (*pString == '\n') { + + y += gFont.height + 2; + x = xorg; + } + else { + + LCDD_DrawChar(pBuffer, x, y, *pString, color); + x += gFont.width + 2; + } + pString++; + } +} + +//------------------------------------------------------------------------------ +/// Returns the width & height in pixels that a string will occupy on the screen +/// if drawn using LCDD_DrawString. +/// \param pString String. +/// \param pWidth Pointer for storing the string width (optional). +/// \param pHeight Pointer for storing the string height (optional). +/// \return String width in pixels. +//------------------------------------------------------------------------------ +void LCDD_GetStringSize( + const char *pString, + unsigned int *pWidth, + unsigned int *pHeight) +{ + unsigned int width = 0; + unsigned int height = gFont.height; + + while (*pString != 0) { + + if (*pString == '\n') { + + height += gFont.height + 2; + } + else { + + width += gFont.width + 2; + } + pString++; + } + + if (width > 0) width -= 2; + + if (pWidth) *pWidth = width; + if (pHeight) *pHeight = height; +} diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/font.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/font.c new file mode 100644 index 000000000..95c528e85 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/font.c @@ -0,0 +1,86 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "font.h" +#include "draw.h" +#include "font10x14.h" +#include + +//------------------------------------------------------------------------------ +// Local variables +//------------------------------------------------------------------------------ + +/// Global variable describing the font being instancied. +const Font gFont = {10, 14}; + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Draws an ASCII character on the given LCD buffer. +/// \param pBuffer Buffer to write on. +/// \param x X-coordinate of character upper-left corner. +/// \param y Y-coordinate of character upper-left corner. +/// \param c Character to output. +/// \param color Character color. +//------------------------------------------------------------------------------ +void LCDD_DrawChar( + void *pBuffer, + unsigned int x, + unsigned int y, + char c, + unsigned int color) +{ + unsigned int row, col; + + SANITY_CHECK((c >= 0x20) && (c <= 0x7F)); + + for (col = 0; col < 10; col++) { + + for (row = 0; row < 8; row++) { + + if ((pCharset10x14[((c - 0x20) * 20) + col * 2] >> (7 - row)) & 0x1) { + + LCDD_DrawPixel(pBuffer, x+col, y+row, color); + } + } + for (row = 0; row < 6; row++) { + + if ((pCharset10x14[((c - 0x20) * 20) + col * 2 + 1] >> (7 - row)) & 0x1) { + + LCDD_DrawPixel(pBuffer, x+col, y+row+8, color); + } + } + } +} diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/font.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/font.h new file mode 100644 index 000000000..37321b562 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/font.h @@ -0,0 +1,89 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// The font.h files declares a font structure and a LCDD_DrawChar function +/// that must be implemented by a font definition file to be used with the +/// LCDD_DrawString method of draw.h. +/// +/// The font10x14.c implements the necessary variable and function for a 10x14 +/// font. +/// +/// !!!Usage +/// +/// -# Declare a gFont global variable with the necessary Font information. +/// -# Implement an LCDD_DrawChar function which displays the specified +/// character on the LCD. +/// -# Use the LCDD_DrawString method defined in draw.h to display a complete +/// string. +//------------------------------------------------------------------------------ + +#ifndef FONT_H +#define FONT_H + +//------------------------------------------------------------------------------ +// Global types +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Describes the font (width, height, supported characters, etc.) used by +/// the LCD driver draw API. +//------------------------------------------------------------------------------ +typedef struct _Font { + + /// Font width in pixels. + unsigned char width; + /// Font height in pixels. + unsigned char height; + +} Font; + +//------------------------------------------------------------------------------ +// Global variables +//------------------------------------------------------------------------------ + +/// Global variable describing the font being instancied. +extern const Font gFont; + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void LCDD_DrawChar( + void *pBuffer, + unsigned int x, + unsigned int y, + char c, + unsigned int color); + +#endif //#ifndef FONT_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/font10x14.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/font10x14.h new file mode 100644 index 000000000..b86612a43 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/font10x14.h @@ -0,0 +1,237 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef LCD_FONT_10x14_H +#define LCD_FONT_10x14_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +const unsigned char pCharset10x14[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xCC, + 0xFF, 0xCC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0xF0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xF0, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0C, 0xC0, 0x0C, 0xC0, 0xFF, 0xFC, 0xFF, 0xFC, 0x0C, 0xC0, + 0x0C, 0xC0, 0xFF, 0xFC, 0xFF, 0xFC, 0x0C, 0xC0, 0x0C, 0xC0, + 0x0C, 0x60, 0x1E, 0x70, 0x3F, 0x30, 0x33, 0x30, 0xFF, 0xFC, + 0xFF, 0xFC, 0x33, 0x30, 0x33, 0xF0, 0x39, 0xE0, 0x18, 0xC0, + 0x60, 0x00, 0xF0, 0x0C, 0xF0, 0x3C, 0x60, 0xF0, 0x03, 0xC0, + 0x0F, 0x00, 0x3C, 0x18, 0xF0, 0x3C, 0xC0, 0x3C, 0x00, 0x18, + 0x3C, 0xF0, 0x7F, 0xF8, 0xC3, 0x1C, 0xC7, 0x8C, 0xCF, 0xCC, + 0xDC, 0xEC, 0x78, 0x78, 0x30, 0x30, 0x00, 0xFC, 0x00, 0xCC, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0xEC, 0x00, + 0xF8, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0F, 0xC0, 0x3F, 0xF0, 0x78, 0x78, + 0x60, 0x18, 0xC0, 0x0C, 0xC0, 0x0C, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x0C, 0xC0, 0x0C, 0x60, 0x18, + 0x78, 0x78, 0x3F, 0xF0, 0x0F, 0xC0, 0x00, 0x00, 0x00, 0x00, + 0x0C, 0x60, 0x0E, 0xE0, 0x07, 0xC0, 0x03, 0x80, 0x3F, 0xF8, + 0x3F, 0xF8, 0x03, 0x80, 0x07, 0xC0, 0x0E, 0xE0, 0x0C, 0x60, + 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x3F, 0xF0, + 0x3F, 0xF0, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, + 0x00, 0x44, 0x00, 0xEC, 0x00, 0xF8, 0x00, 0x70, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, + 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, + 0x00, 0x18, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x18, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0C, 0x00, 0x3C, 0x00, 0xF0, 0x03, 0xC0, + 0x0F, 0x00, 0x3C, 0x00, 0xF0, 0x00, 0xC0, 0x00, 0x00, 0x00, + 0x3F, 0xF0, 0x7F, 0xF8, 0xE0, 0xFC, 0xC1, 0xCC, 0xC3, 0x8C, + 0xC7, 0x0C, 0xCE, 0x0C, 0xFC, 0x1C, 0x7F, 0xF8, 0x3F, 0xF0, + 0x00, 0x00, 0x00, 0x00, 0x30, 0x0C, 0x70, 0x0C, 0xFF, 0xFC, + 0xFF, 0xFC, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x0C, 0x70, 0x1C, 0xE0, 0x3C, 0xC0, 0x7C, 0xC0, 0xEC, + 0xC1, 0xCC, 0xC3, 0x8C, 0xE7, 0x0C, 0x7E, 0x0C, 0x3C, 0x0C, + 0x30, 0x30, 0x70, 0x38, 0xE0, 0x1C, 0xC0, 0x0C, 0xC0, 0x0C, + 0xC3, 0x0C, 0xC3, 0x0C, 0xE3, 0x1C, 0x7F, 0xF8, 0x3C, 0xF0, + 0x03, 0xC0, 0x07, 0xC0, 0x0E, 0xC0, 0x1C, 0xC0, 0x38, 0xC0, + 0x70, 0xC0, 0xFF, 0xFC, 0xFF, 0xFC, 0x00, 0xC0, 0x00, 0xC0, + 0xFC, 0x30, 0xFC, 0x38, 0xCC, 0x1C, 0xCC, 0x0C, 0xCC, 0x0C, + 0xCC, 0x0C, 0xCC, 0x0C, 0xCE, 0x1C, 0xC7, 0xF8, 0xC3, 0xF0, + 0x3F, 0xF0, 0x7F, 0xF8, 0xE3, 0x1C, 0xC3, 0x0C, 0xC3, 0x0C, + 0xC3, 0x0C, 0xC3, 0x0C, 0xE3, 0x9C, 0x71, 0xF8, 0x30, 0xF0, + 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC3, 0xFC, + 0xC7, 0xFC, 0xCE, 0x00, 0xDC, 0x00, 0xF8, 0x00, 0xF0, 0x00, + 0x3C, 0xF0, 0x7F, 0xF8, 0xE7, 0x9C, 0xC3, 0x0C, 0xC3, 0x0C, + 0xC3, 0x0C, 0xC3, 0x0C, 0xE7, 0x9C, 0x7F, 0xF8, 0x3C, 0xF0, + 0x3C, 0x00, 0x7E, 0x00, 0xE7, 0x0C, 0xC3, 0x0C, 0xC3, 0x1C, + 0xC3, 0x38, 0xC3, 0x70, 0xE7, 0xE0, 0x7F, 0xC0, 0x3F, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x60, 0x3C, 0xF0, + 0x3C, 0xF0, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x44, 0x3C, 0xEC, + 0x3C, 0xF8, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x03, 0x00, 0x07, 0x80, 0x0F, 0xC0, 0x1C, 0xE0, + 0x38, 0x70, 0x70, 0x38, 0xE0, 0x1C, 0xC0, 0x0C, 0x00, 0x00, + 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, + 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, + 0x00, 0x00, 0xC0, 0x0C, 0xE0, 0x1C, 0x70, 0x38, 0x38, 0x70, + 0x1C, 0xE0, 0x0F, 0xC0, 0x07, 0x80, 0x03, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x70, 0x00, 0xE0, 0x00, 0xC0, 0x00, 0xC1, 0xEC, + 0xC3, 0xEC, 0xC3, 0x00, 0xE6, 0x00, 0x7E, 0x00, 0x3C, 0x00, + 0x30, 0xF0, 0x71, 0xF8, 0xE3, 0x9C, 0xC3, 0x0C, 0xC3, 0xFC, + 0xC3, 0xFC, 0xC0, 0x0C, 0xE0, 0x1C, 0x7F, 0xF8, 0x3F, 0xF0, + 0x3F, 0xFC, 0x7F, 0xFC, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, + 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xC0, 0x7F, 0xFC, 0x3F, 0xFC, + 0xFF, 0xFC, 0xFF, 0xFC, 0xC3, 0x0C, 0xC3, 0x0C, 0xC3, 0x0C, + 0xC3, 0x0C, 0xC3, 0x0C, 0xE7, 0x9C, 0x7F, 0xF8, 0x3C, 0xF0, + 0x3F, 0xF0, 0x7F, 0xF8, 0xE0, 0x1C, 0xC0, 0x0C, 0xC0, 0x0C, + 0xC0, 0x0C, 0xC0, 0x0C, 0xE0, 0x1C, 0x70, 0x38, 0x30, 0x30, + 0xFF, 0xFC, 0xFF, 0xFC, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, + 0xC0, 0x0C, 0xC0, 0x0C, 0xE0, 0x1C, 0x7F, 0xF8, 0x3F, 0xF0, + 0xFF, 0xFC, 0xFF, 0xFC, 0xC3, 0x0C, 0xC3, 0x0C, 0xC3, 0x0C, + 0xC3, 0x0C, 0xC3, 0x0C, 0xC3, 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, + 0xFF, 0xFC, 0xFF, 0xFC, 0xC3, 0x00, 0xC3, 0x00, 0xC3, 0x00, + 0xC3, 0x00, 0xC3, 0x00, 0xC3, 0x00, 0xC0, 0x00, 0xC0, 0x00, + 0x3F, 0xF0, 0x7F, 0xF8, 0xE0, 0x1C, 0xC0, 0x0C, 0xC0, 0x0C, + 0xC3, 0x0C, 0xC3, 0x0C, 0xE3, 0x1C, 0x73, 0xF8, 0x33, 0xF0, + 0xFF, 0xFC, 0xFF, 0xFC, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, + 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0xFF, 0xFC, 0xFF, 0xFC, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x0C, 0xC0, 0x0C, 0xFF, 0xFC, + 0xFF, 0xFC, 0xC0, 0x0C, 0xC0, 0x0C, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x38, 0xC0, 0x1C, 0xC0, 0x0C, 0xC0, 0x0C, + 0xC0, 0x1C, 0xFF, 0xF8, 0xFF, 0xF0, 0xC0, 0x00, 0xC0, 0x00, + 0xFF, 0xFC, 0xFF, 0xFC, 0x07, 0x80, 0x07, 0x80, 0x0F, 0xC0, + 0x1C, 0xE0, 0x38, 0x70, 0x70, 0x38, 0xE0, 0x1C, 0xC0, 0x0C, + 0xFF, 0xFC, 0xFF, 0xFC, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, + 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, + 0xFF, 0xFC, 0xFF, 0xFC, 0x70, 0x00, 0x38, 0x00, 0x1F, 0x00, + 0x1F, 0x00, 0x38, 0x00, 0x70, 0x00, 0xFF, 0xFC, 0xFF, 0xFC, + 0xFF, 0xFC, 0xFF, 0xFC, 0x1C, 0x00, 0x0E, 0x00, 0x07, 0x00, + 0x03, 0x80, 0x01, 0xC0, 0x00, 0xE0, 0xFF, 0xFC, 0xFF, 0xFC, + 0x3F, 0xF0, 0x7F, 0xF8, 0xE0, 0x1C, 0xC0, 0x0C, 0xC0, 0x0C, + 0xC0, 0x0C, 0xC0, 0x0C, 0xE0, 0x1C, 0x7F, 0xF8, 0x3F, 0xF0, + 0xFF, 0xFC, 0xFF, 0xFC, 0xC3, 0x00, 0xC3, 0x00, 0xC3, 0x00, + 0xC3, 0x00, 0xC3, 0x00, 0xE7, 0x00, 0x7E, 0x00, 0x3C, 0x00, + 0x3F, 0xF0, 0x7F, 0xF8, 0xE0, 0x1C, 0xC0, 0x0C, 0xC0, 0xCC, + 0xC0, 0xEC, 0xC0, 0x7C, 0xE0, 0x38, 0x7F, 0xFC, 0x3F, 0xEC, + 0xFF, 0xFC, 0xFF, 0xFC, 0xC3, 0x00, 0xC3, 0x80, 0xC3, 0x80, + 0xC3, 0xC0, 0xC3, 0xC0, 0xE7, 0x70, 0x7E, 0x3C, 0x3C, 0x1C, + 0x3C, 0x18, 0x7E, 0x1C, 0xE7, 0x0C, 0xC3, 0x0C, 0xC3, 0x0C, + 0xC3, 0x0C, 0xC3, 0x0C, 0xC3, 0x9C, 0xE1, 0xF8, 0x60, 0xF0, + 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xFF, 0xFC, + 0xFF, 0xFC, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, + 0xFF, 0xF0, 0xFF, 0xF8, 0x00, 0x1C, 0x00, 0x0C, 0x00, 0x0C, + 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x1C, 0xFF, 0xF8, 0xFF, 0xF0, + 0xFF, 0xC0, 0xFF, 0xE0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1C, + 0x00, 0x1C, 0x00, 0x38, 0x00, 0x70, 0xFF, 0xE0, 0xFF, 0xC0, + 0xFF, 0xF0, 0xFF, 0xF8, 0x00, 0x1C, 0x00, 0x3C, 0x00, 0xF8, + 0x00, 0xF8, 0x00, 0x3C, 0x00, 0x1C, 0xFF, 0xF8, 0xFF, 0xF0, + 0xF0, 0x3C, 0xF8, 0x7C, 0x1C, 0xE0, 0x0F, 0xC0, 0x07, 0x80, + 0x07, 0x80, 0x0F, 0xC0, 0x1C, 0xE0, 0xF8, 0x7C, 0xF0, 0x3C, + 0xFC, 0x00, 0xFE, 0x00, 0x07, 0x00, 0x03, 0x80, 0x01, 0xFC, + 0x01, 0xFC, 0x03, 0x80, 0x07, 0x00, 0xFE, 0x00, 0xFC, 0x00, + 0xC0, 0x3C, 0xC0, 0x7C, 0xC0, 0xEC, 0xC1, 0xCC, 0xC3, 0x8C, + 0xC7, 0x0C, 0xCE, 0x0C, 0xDC, 0x0C, 0xF8, 0x0C, 0xF0, 0x0C, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFC, 0xFF, 0xFC, 0xC0, 0x0C, + 0xC0, 0x0C, 0xC0, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x30, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x03, 0x00, + 0x03, 0x00, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0x30, 0x00, 0x30, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, + 0xFF, 0xFC, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0C, 0x00, 0x1C, 0x00, 0x38, 0x00, 0x70, 0x00, 0xE0, 0x00, + 0xE0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1C, 0x00, 0x0C, 0x00, + 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, + 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0xE0, 0x00, 0x70, 0x00, + 0x38, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x30, 0x06, 0x78, 0x0E, 0xFC, 0x0C, 0xCC, 0x0C, 0xCC, + 0x0C, 0xCC, 0x0C, 0xCC, 0x0E, 0xCC, 0x07, 0xFC, 0x03, 0xF8, + 0xFF, 0xFC, 0xFF, 0xFC, 0x03, 0x0C, 0x03, 0x0C, 0x03, 0x0C, + 0x03, 0x0C, 0x03, 0x0C, 0x03, 0x9C, 0x01, 0xF8, 0x00, 0xF0, + 0x03, 0xF0, 0x07, 0xF8, 0x0E, 0x1C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0E, 0x1C, 0x07, 0x38, 0x03, 0x30, + 0x00, 0xF0, 0x01, 0xF8, 0x03, 0x9C, 0x03, 0x0C, 0x03, 0x0C, + 0x03, 0x0C, 0x03, 0x0C, 0x03, 0x0C, 0xFF, 0xFC, 0xFF, 0xFC, + 0x03, 0xF0, 0x07, 0xF8, 0x0E, 0xDC, 0x0C, 0xCC, 0x0C, 0xCC, + 0x0C, 0xCC, 0x0C, 0xCC, 0x0E, 0xDC, 0x07, 0xD8, 0x03, 0x90, + 0x00, 0x00, 0x03, 0x00, 0x3F, 0xFC, 0x7F, 0xFC, 0xE3, 0x00, + 0xE3, 0x00, 0x70, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x18, 0x07, 0x9C, 0x0F, 0xCC, 0x0C, 0xCC, 0x0C, 0xCC, + 0x0C, 0xCC, 0x0C, 0xCC, 0x0C, 0xDC, 0x0F, 0xF8, 0x07, 0xF0, + 0xFF, 0xFC, 0xFF, 0xFC, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, + 0x03, 0x00, 0x03, 0x80, 0x01, 0xFC, 0x00, 0xFC, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0xFC, + 0x1B, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x30, 0x00, 0x38, 0x00, 0x1C, 0x00, 0x0C, + 0x00, 0x0C, 0x00, 0x1C, 0xCF, 0xF8, 0xCF, 0xF0, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0xFC, 0xFF, 0xFC, 0x00, 0xE0, 0x01, 0xE0, + 0x03, 0xF0, 0x07, 0x38, 0x0E, 0x1C, 0x0C, 0x0C, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x0C, 0xC0, 0x0C, 0xFF, 0xFC, + 0xFF, 0xFC, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, + 0x0F, 0xFC, 0x0F, 0xFC, 0x0E, 0x00, 0x07, 0x00, 0x03, 0xC0, + 0x03, 0xC0, 0x07, 0x00, 0x0E, 0x00, 0x0F, 0xFC, 0x0F, 0xFC, + 0x0F, 0xFC, 0x0F, 0xFC, 0x03, 0x00, 0x07, 0x00, 0x0E, 0x00, + 0x0C, 0x00, 0x0C, 0x00, 0x0E, 0x00, 0x07, 0xFC, 0x03, 0xFC, + 0x03, 0xF0, 0x07, 0xF8, 0x0E, 0x1C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0E, 0x1C, 0x07, 0xF8, 0x03, 0xF0, + 0x0F, 0xFC, 0x0F, 0xFC, 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, + 0x0C, 0xC0, 0x0C, 0xC0, 0x0F, 0xC0, 0x07, 0x80, 0x03, 0x00, + 0x03, 0x00, 0x07, 0x80, 0x0F, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, + 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, 0x0F, 0xFC, 0x0F, 0xFC, + 0x0F, 0xFC, 0x0F, 0xFC, 0x03, 0x80, 0x07, 0x00, 0x0E, 0x00, + 0x0C, 0x00, 0x0C, 0x00, 0x0E, 0x00, 0x07, 0x00, 0x03, 0x00, + 0x03, 0x18, 0x07, 0x9C, 0x0F, 0xCC, 0x0C, 0xCC, 0x0C, 0xCC, + 0x0C, 0xCC, 0x0C, 0xCC, 0x0C, 0xFC, 0x0E, 0x78, 0x06, 0x30, + 0x00, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0xFF, 0xF0, 0xFF, 0xF8, + 0x0C, 0x1C, 0x0C, 0x1C, 0x0C, 0x38, 0x0C, 0x30, 0x00, 0x00, + 0x0F, 0xF0, 0x0F, 0xF8, 0x00, 0x1C, 0x00, 0x0C, 0x00, 0x0C, + 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x1C, 0x0F, 0xF8, 0x0F, 0xF0, + 0x0F, 0xC0, 0x0F, 0xE0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1C, + 0x00, 0x1C, 0x00, 0x38, 0x00, 0x70, 0x0F, 0xE0, 0x0F, 0xC0, + 0x0F, 0xF0, 0x0F, 0xF8, 0x00, 0x1C, 0x00, 0x1C, 0x00, 0xF8, + 0x00, 0xF8, 0x00, 0x1C, 0x00, 0x1C, 0x0F, 0xF8, 0x0F, 0xF0, + 0x0C, 0x0C, 0x0E, 0x1C, 0x07, 0x38, 0x03, 0xF0, 0x01, 0xE0, + 0x01, 0xE0, 0x03, 0xF0, 0x07, 0x38, 0x0E, 0x1C, 0x0C, 0x0C, + 0x0C, 0x00, 0x0E, 0x00, 0x07, 0x0C, 0x03, 0x9C, 0x01, 0xF8, + 0x01, 0xF0, 0x03, 0x80, 0x07, 0x00, 0x0E, 0x00, 0x0C, 0x00, + 0x0C, 0x0C, 0x0C, 0x1C, 0x0C, 0x3C, 0x0C, 0x7C, 0x0C, 0xEC, + 0x0D, 0xCC, 0x0F, 0x8C, 0x0F, 0x0C, 0x0E, 0x0C, 0x0C, 0x0C, + 0x00, 0x00, 0x03, 0x00, 0x07, 0x80, 0x3F, 0xF0, 0x7C, 0xF8, + 0xE0, 0x1C, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, 0x00, 0x00, + 0x03, 0x0C, 0x03, 0x0C, 0x3F, 0xFC, 0x7F, 0xFC, 0xE3, 0x0C, + 0xC3, 0x0C, 0xC0, 0x0C, 0xE0, 0x0C, 0x70, 0x0C, 0x30, 0x0C, + 0x00, 0x00, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, 0xE0, 0x1C, + 0x7C, 0xF8, 0x3F, 0xF0, 0x07, 0x80, 0x03, 0x00, 0x00, 0x00, + 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, + 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, + 0xFF, 0xFC, 0xFF, 0xFC, 0xFF, 0xFC, 0xFF, 0xFC, 0xFF, 0xFC, + 0xFF, 0xFC, 0xFF, 0xFC, 0xFF, 0xFC, 0xFF, 0xFC, 0xFF, 0xFC +}; + + +#endif // #ifdef _LCD_FONT_10x14_h diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/lcdd.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/lcdd.h new file mode 100644 index 000000000..27da07322 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/lcdd.h @@ -0,0 +1,61 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Simple driver for the LCD, which takes care of the initialization. +/// +/// !!!Usage +/// +/// -# Call LCDD_Initialize to configure the LCD controller. +/// -# Set the buffer displayed by the LCD with LCDD_DisplayBuffer if using +/// peripheral LCDC, or start displaying with LCDD_Start if using HX8347. +//------------------------------------------------------------------------------ + +#ifndef LCDD_H +#define LCDD_H + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void LCDD_Initialize(void); // For peripheral LCDC & HX8347 + +extern void * LCDD_DisplayBuffer(void *pBuffer); // For peripheral LCDC only + +extern void LCDD_Start(void); // For HX8347 only + +extern void LCDD_Stop(void); // For peripheral LCDC & HX8347 + +extern void LCDD_SetBacklight (unsigned int step); // For peripheral LCDC only + +#endif //#ifndef LCDD_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/lcdd_hx8347.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/lcdd_hx8347.c new file mode 100644 index 000000000..7d0c90f27 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/drivers/lcd/lcdd_hx8347.c @@ -0,0 +1,143 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "lcdd.h" + +#include +#include +#include +#include + +#include "FreeRTOS.h" +#include "task.h" + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Initializes the LCD controller. +/// \param pLcdBase LCD base address. +//------------------------------------------------------------------------------ +void LCDD_Initialize(void) +{ + const Pin pPins[] = {BOARD_LCD_PINS}; + AT91PS_HSMC4_CS pSMC = AT91C_BASE_HSMC4_CS2; + unsigned int rMode; + + // Enable pins + PIO_Configure(pPins, PIO_LISTSIZE(pPins)); + + // Enable peripheral clock + PMC_EnablePeripheral(AT91C_ID_HSMC4); + + // EBI SMC Configuration + pSMC->HSMC4_SETUP = 0 + | ((4 << 0) & AT91C_HSMC4_NWE_SETUP) + | ((2 << 8) & AT91C_HSMC4_NCS_WR_SETUP) + | ((4 << 16) & AT91C_HSMC4_NRD_SETUP) + | ((2 << 24) & AT91C_HSMC4_NCS_RD_SETUP) + ; + + pSMC->HSMC4_PULSE = 0 + | (( 5 << 0) & AT91C_HSMC4_NWE_PULSE) + | (( 18 << 8) & AT91C_HSMC4_NCS_WR_PULSE) + | (( 5 << 16) & AT91C_HSMC4_NRD_PULSE) + | (( 18 << 24) & AT91C_HSMC4_NCS_RD_PULSE) + ; + + pSMC->HSMC4_CYCLE = 0 + | ((22 << 0) & AT91C_HSMC4_NWE_CYCLE) + | ((22 << 16) & AT91C_HSMC4_NRD_CYCLE) + ; + + rMode = pSMC->HSMC4_MODE; + pSMC->HSMC4_MODE = (rMode & ~(AT91C_HSMC4_DBW | AT91C_HSMC4_READ_MODE + | AT91C_HSMC4_WRITE_MODE | AT91C_HSMC4_PMEN)) + | (AT91C_HSMC4_READ_MODE) + | (AT91C_HSMC4_WRITE_MODE) + | (AT91C_HSMC4_DBW_WIDTH_SIXTEEN_BITS) + ; + + // Initialize LCD controller (HX8347) + LCD_Initialize((void *)BOARD_LCD_BASE); + + // Set LCD backlight + LCDD_SetBacklight(25); +} + +//------------------------------------------------------------------------------ +/// Turn on the LCD +//------------------------------------------------------------------------------ +void LCDD_Start(void) +{ + LCD_On((void *)BOARD_LCD_BASE); +} + +//------------------------------------------------------------------------------ +/// Turn off the LCD +//------------------------------------------------------------------------------ +void LCDD_Stop(void) +{ + LCD_Off((void *)BOARD_LCD_BASE); +} + +//------------------------------------------------------------------------------ +/// Set the backlight of the LCD. +/// \param level Backlight brightness level [1..32], 32 is maximum level. +//------------------------------------------------------------------------------ +void LCDD_SetBacklight (unsigned int level) +{ + unsigned int i; + const Pin pPins[] = {BOARD_BACKLIGHT_PIN}; + + // Enable pins + PIO_Configure(pPins, PIO_LISTSIZE(pPins)); + + // Switch off backlight + PIO_Clear(pPins); + vTaskDelay( 2 ); + + // Set new backlight level + for (i = 0; i < level; i++) { + + PIO_Set(pPins); + PIO_Set(pPins); + PIO_Set(pPins); + + PIO_Clear(pPins); + PIO_Clear(pPins); + PIO_Clear(pPins); + } + PIO_Set(pPins); +} diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ac97c/ac97c.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ac97c/ac97c.c new file mode 100644 index 000000000..d9b177153 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ac97c/ac97c.c @@ -0,0 +1,692 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "ac97c.h" +#include +#include +#include +#include +#include + +//------------------------------------------------------------------------------ +// Local constants +//------------------------------------------------------------------------------ + +/// Maximum size of one PDC buffer (in bytes). +#define MAX_PDC_COUNTER 65535 + +//------------------------------------------------------------------------------ +// Local types +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// AC97 transfer descriptor. Tracks the status and parameters of a transfer +/// on the AC97 bus. +//------------------------------------------------------------------------------ +typedef struct _Ac97Transfer { + + /// Buffer containing the slots to send. + unsigned char *pBuffer; + /// Total number of samples to send. + volatile unsigned int numSamples; + /// Optional callback function. + Ac97Callback callback; + /// Optional argument to the callback function. + void *pArg; + +} Ac97Transfer; + +//------------------------------------------------------------------------------ +/// AC97 controller driver structure. Monitors the status of transfers on all +/// AC97 channels. +//------------------------------------------------------------------------------ +typedef struct _Ac97c { + + /// List of transfers occuring on each channel. + Ac97Transfer transfers[5]; +} Ac97c; + +//------------------------------------------------------------------------------ +// Local variables +//------------------------------------------------------------------------------ + +/// Global AC97 controller instance. +static Ac97c ac97c; + +//------------------------------------------------------------------------------ +// Local functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Returns the size of one sample (in bytes) on the given channel. +/// \param channel Channel number. +//------------------------------------------------------------------------------ +static unsigned char GetSampleSize(unsigned char channel) +{ + unsigned int size = 0; + + SANITY_CHECK((channel == AC97C_CHANNEL_A) + || (channel == AC97C_CHANNEL_B) + || (channel == AC97C_CHANNEL_CODEC)); + + // Check selected channel + switch (channel) { + case AC97C_CHANNEL_CODEC: return 2; + + case AC97C_CHANNEL_A: + size = (AT91C_BASE_AC97C->AC97C_CAMR & AT91C_AC97C_SIZE) >> 16; + break; + + case AC97C_CHANNEL_B: + size = (AT91C_BASE_AC97C->AC97C_CBMR & AT91C_AC97C_SIZE) >> 16; + break; + } + + // Compute size in bytes given SIZE field + if ((size & 2) != 0) { + + return 2; + } + else { + + return 4; + } +} + +//------------------------------------------------------------------------------ +/// Interrupt service routine for Codec, is invoked by AC97C_Handler. +//------------------------------------------------------------------------------ +static void CodecHandler(void) +{ + unsigned int status; + unsigned int data; + Ac97Transfer *pTransfer = &(ac97c.transfers[AC97C_CODEC_TRANSFER]); + + // Read CODEC status register + status = AT91C_BASE_AC97C->AC97C_COSR; + status &= AT91C_BASE_AC97C->AC97C_COMR; + + // A sample has been transmitted + if (status & AT91C_AC97C_TXRDY) { + + pTransfer->numSamples--; + + // If there are remaining samples, transmit one + if (pTransfer->numSamples > 0) { + + data = *((unsigned int *) pTransfer->pBuffer); + AT91C_BASE_AC97C->AC97C_COMR &= ~(AT91C_AC97C_TXRDY); + AT91C_BASE_AC97C->AC97C_COTHR = data; + + // Check if transfer is read or write + if ((data & AT91C_AC97C_READ) != 0) { + + AT91C_BASE_AC97C->AC97C_COMR |= AT91C_AC97C_RXRDY; + } + else { + + pTransfer->pBuffer += sizeof(unsigned int); + AT91C_BASE_AC97C->AC97C_COMR |= AT91C_AC97C_TXRDY; + } + } + // Transfer finished + else { + + AT91C_BASE_AC97C->AC97C_IDR = AT91C_AC97C_COEVT; + AT91C_BASE_AC97C->AC97C_COMR &= ~(AT91C_AC97C_TXRDY); + if (pTransfer->callback) { + + pTransfer->callback(pTransfer->pArg, 0, 0); + } + } + } + + // A sample has been received + if (status & AT91C_AC97C_RXRDY) { + + // Store sample + data = AT91C_BASE_AC97C->AC97C_CORHR; + *((unsigned int *) pTransfer->pBuffer) = data; + + pTransfer->pBuffer += sizeof(unsigned int); + pTransfer->numSamples--; + + // Transfer finished + if (pTransfer->numSamples > 0) { + + data = *((unsigned int *) pTransfer->pBuffer); + AT91C_BASE_AC97C->AC97C_COMR &= ~(AT91C_AC97C_RXRDY); + AT91C_BASE_AC97C->AC97C_COTHR = data; + + // Check if transfer is read or write + if ((data & AT91C_AC97C_READ) != 0) { + + AT91C_BASE_AC97C->AC97C_COMR |= AT91C_AC97C_RXRDY; + } + else { + + pTransfer->pBuffer += sizeof(unsigned int); + AT91C_BASE_AC97C->AC97C_COMR |= AT91C_AC97C_TXRDY; + } + } + else { + + AT91C_BASE_AC97C->AC97C_IDR = AT91C_AC97C_COEVT; + AT91C_BASE_AC97C->AC97C_COMR &= ~(AT91C_AC97C_RXRDY); + if (pTransfer->callback) { + + pTransfer->callback(pTransfer->pArg, 0, 0); + } + } + } +} + +//------------------------------------------------------------------------------ +/// Interrupt service routine for channel A, is invoked by AC97C_Handler. +//------------------------------------------------------------------------------ +static void ChannelAHandler(void) +{ + unsigned int status; + Ac97Transfer *pTransmit = &(ac97c.transfers[AC97C_CHANNEL_A_TRANSMIT]); + Ac97Transfer *pReceive = &(ac97c.transfers[AC97C_CHANNEL_A_RECEIVE]); + + // Read channel A status register + status = AT91C_BASE_AC97C->AC97C_CASR; + + // A buffer has been transmitted + if ((status & AT91C_AC97C_ENDTX) != 0) { + + // Update transfer information + if (pTransmit->numSamples > MAX_PDC_COUNTER) { + + pTransmit->numSamples -= MAX_PDC_COUNTER; + } + else { + + pTransmit->numSamples = 0; + } + + // Transmit new buffers if necessary + if (pTransmit->numSamples > MAX_PDC_COUNTER) { + + // Fill next PDC + AT91C_BASE_AC97C->AC97C_TNPR = (unsigned int) pTransmit->pBuffer; + if (pTransmit->numSamples > 2 * MAX_PDC_COUNTER) { + + AT91C_BASE_AC97C->AC97C_TNCR = MAX_PDC_COUNTER; + pTransmit->pBuffer += MAX_PDC_COUNTER + * GetSampleSize(AC97C_CHANNEL_A); + } + else { + + AT91C_BASE_AC97C->AC97C_TNCR = pTransmit->numSamples + - MAX_PDC_COUNTER; + } + } + // Only one buffer remaining + else { + + AT91C_BASE_AC97C->AC97C_CAMR &= ~AT91C_AC97C_ENDTX; + AT91C_BASE_AC97C->AC97C_CAMR |= AT91C_AC97C_TXBUFE; + } + } + + // Transmit completed + if ((status & AT91C_AC97C_TXBUFE) != 0) { + + pTransmit->numSamples = 0; + AT91C_BASE_AC97C->AC97C_PTCR = AT91C_PDC_TXTDIS; + AT91C_BASE_AC97C->AC97C_CAMR &= ~AT91C_AC97C_TXBUFE; + if (pTransmit->callback) { + + pTransmit->callback(pTransmit->pArg, 0, 0); + } + } + + // A buffer has been received + if (status & AT91C_AC97C_ENDRX) { + + if (pReceive->numSamples > MAX_PDC_COUNTER) { + + pReceive->numSamples -= MAX_PDC_COUNTER; + } + else { + + pReceive->numSamples = 0; + } + + // Transfer remaining samples + if (pReceive->numSamples > MAX_PDC_COUNTER) { + + AT91C_BASE_AC97C->AC97C_RNPR = (unsigned int) pReceive->pBuffer; + if (pReceive->numSamples > 2 * MAX_PDC_COUNTER) { + + AT91C_BASE_AC97C->AC97C_RNCR = MAX_PDC_COUNTER; + pReceive->pBuffer += MAX_PDC_COUNTER + * GetSampleSize(AC97C_CHANNEL_A); + } + else { + + AT91C_BASE_AC97C->AC97C_RNCR = pReceive->numSamples + - MAX_PDC_COUNTER; + } + } + // Only one buffer remaining + else { + + AT91C_BASE_AC97C->AC97C_CAMR &= ~(AT91C_AC97C_ENDRX); + AT91C_BASE_AC97C->AC97C_CAMR |= AT91C_AC97C_RXBUFF; + } + } + + // Receive complete + if ((status & AT91C_AC97C_RXBUFF) != 0) { + + pReceive->numSamples = 0; + AT91C_BASE_AC97C->AC97C_PTCR = AT91C_PDC_RXTDIS; + AT91C_BASE_AC97C->AC97C_CAMR &= ~AT91C_AC97C_RXBUFF; + if (pReceive->callback) { + + pReceive->callback(pReceive->pArg, 0, 0); + } + } +} + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +/// This handler function must be called by the AC97C interrupt service routine. +/// Identifies which event was activated and calls the associated function. +//------------------------------------------------------------------------------ +void AC97C_Handler(void) +{ + unsigned int status; + + // Get the real interrupt source + status = AT91C_BASE_AC97C->AC97C_SR; + status &= AT91C_BASE_AC97C->AC97C_IMR; + + // Check if an event on the codec channel is active + if ((status & AT91C_AC97C_COEVT) != 0) { + + CodecHandler(); + } + // Check if an event on channel A is active + if ((status & AT91C_AC97C_CAEVT) != 0) { + + ChannelAHandler(); + } +} + +//------------------------------------------------------------------------------ +/// Starts a read or write transfer on the given channel +/// \param channel particular channel (AC97C_CODEC_TRANSFER, +/// AC97C_CHANNEL_A_RECEIVE, AC97C_CHANNEL_A_TRANSMIT, +/// AC97C_CHANNEL_B_RECEIVE or AC97C_CHANNEL_B_TRANSMIT). +/// \param pBuffer buffer containing the slots to send. +/// \param numSamples total number of samples to send. +/// \param callback optional callback function. +/// \param pArg optional argument to the callback function. +//------------------------------------------------------------------------------ +unsigned char AC97C_Transfer( + unsigned char channel, + unsigned char *pBuffer, + unsigned int numSamples, + Ac97Callback callback, + void *pArg) +{ + unsigned int size; + unsigned int data; + Ac97Transfer *pTransfer; + + SANITY_CHECK(channel <= 5); + SANITY_CHECK(pBuffer); + SANITY_CHECK(numSamples > 0); + + // Check that no transfer is pending on the channel + pTransfer = &(ac97c.transfers[channel]); + if (pTransfer->numSamples > 0) { + + TRACE_WARNING( + "AC97C_Transfer: Channel %d is busy\n\r", channel); + return AC97C_ERROR_BUSY; + } + + // Fill transfer information + pTransfer->pBuffer = pBuffer; + pTransfer->numSamples = numSamples; + pTransfer->callback = callback; + pTransfer->pArg = pArg; + + // Transmit or receive over codec channel + if (channel == AC97C_CODEC_TRANSFER) { + + // Send command + data = *((unsigned int *) pTransfer->pBuffer); + AT91C_BASE_AC97C->AC97C_COTHR = data; + + // Check if transfer is read or write + if ((data & AT91C_AC97C_READ) != 0) { + + AT91C_BASE_AC97C->AC97C_COMR |= AT91C_AC97C_RXRDY; + } + else { + + pTransfer->pBuffer += sizeof(unsigned int); + AT91C_BASE_AC97C->AC97C_COMR |= AT91C_AC97C_TXRDY; + } + + // Enable interrupts + AT91C_BASE_AC97C->AC97C_IER |= AT91C_AC97C_COEVT; + } + // Transmit over channel A + else if (channel == AC97C_CHANNEL_A_TRANSMIT) { + + // Disable PDC + AT91C_BASE_AC97C->AC97C_PTCR = AT91C_PDC_TXTDIS; + + // Fill PDC buffers + size = min(pTransfer->numSamples, MAX_PDC_COUNTER); + AT91C_BASE_AC97C->AC97C_TPR = (unsigned int) pTransfer->pBuffer; + AT91C_BASE_AC97C->AC97C_TCR = size; + pTransfer->pBuffer += size * GetSampleSize(AC97C_CHANNEL_A); + + size = min(pTransfer->numSamples - size, MAX_PDC_COUNTER); + if (size > 0) { + + AT91C_BASE_AC97C->AC97C_TNPR = (unsigned int) pTransfer->pBuffer; + AT91C_BASE_AC97C->AC97C_TNCR = size; + pTransfer->pBuffer += size * GetSampleSize(AC97C_CHANNEL_A); + } + + // Enable interrupts + AT91C_BASE_AC97C->AC97C_CAMR |= AT91C_AC97C_PDCEN | AT91C_AC97C_ENDTX; + AT91C_BASE_AC97C->AC97C_IER |= AT91C_AC97C_CAEVT; + + // Start transfer + AT91C_BASE_AC97C->AC97C_PTCR = AT91C_PDC_TXTEN; + } + // Receive over channel A + else if (channel == AC97C_CHANNEL_A_RECEIVE) { + + // Disable PDC + AT91C_BASE_AC97C->AC97C_PTCR = AT91C_PDC_RXTDIS; + + // Fill PDC buffers + size = min(pTransfer->numSamples, MAX_PDC_COUNTER); + AT91C_BASE_AC97C->AC97C_RPR = (unsigned int) pTransfer->pBuffer; + AT91C_BASE_AC97C->AC97C_RCR = size; + pTransfer->pBuffer += size * GetSampleSize(AC97C_CHANNEL_A); + + size = min(pTransfer->numSamples - size, MAX_PDC_COUNTER); + if (size > 0) { + + AT91C_BASE_AC97C->AC97C_RNPR = (unsigned int) pTransfer->pBuffer; + AT91C_BASE_AC97C->AC97C_RNCR = size; + pTransfer->pBuffer += size * GetSampleSize(AC97C_CHANNEL_A); + } + + // Enable interrupts + AT91C_BASE_AC97C->AC97C_CAMR |= AT91C_AC97C_PDCEN | AT91C_AC97C_ENDRX; + AT91C_BASE_AC97C->AC97C_IER |= AT91C_AC97C_CAEVT; + + // Start transfer + AT91C_BASE_AC97C->AC97C_PTCR = AT91C_PDC_RXTEN; + } + + return 0; +} + +//------------------------------------------------------------------------------ +/// Stop read or write transfer on the given channel. +/// \param channel Channel number. +//------------------------------------------------------------------------------ +void AC97C_CancelTransfer(unsigned char channel) +{ + unsigned int size = 0; + Ac97Transfer *pTransfer; + + SANITY_CHECK(channel <= AC97C_CHANNEL_B_TRANSMIT); + + // Save remaining size + pTransfer = &(ac97c.transfers[channel]); + size = pTransfer->numSamples; + pTransfer->numSamples = 0; + + // Stop PDC + if (channel == AC97C_CHANNEL_A_TRANSMIT) { + + AT91C_BASE_AC97C->AC97C_PTCR = AT91C_PDC_TXTDIS; + size -= min(size, MAX_PDC_COUNTER) - AT91C_BASE_AC97C->AC97C_TCR; + } + if (channel == AC97C_CHANNEL_A_RECEIVE) { + + AT91C_BASE_AC97C->AC97C_PTCR = AT91C_PDC_RXTDIS; + size -= min(size, MAX_PDC_COUNTER) - AT91C_BASE_AC97C->AC97C_RCR; + } + + // Invoke callback if provided + if (pTransfer->callback) { + + pTransfer->callback(pTransfer->pArg, AC97C_ERROR_STOPPED, size); + } +} + +//------------------------------------------------------------------------------ +/// Initializes the AC97 controller. +//------------------------------------------------------------------------------ +void AC97C_Configure(void) +{ + unsigned char channel; + + // Enable the AC97 controller peripheral clock + AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_AC97C); + + // Enable the peripheral and variable rate adjustment + AT91C_BASE_AC97C->AC97C_MR = AT91C_AC97C_ENA | AT91C_AC97C_VRA; + + // Unassigns all input & output slots + AC97C_AssignInputSlots(0, 0xFFFF); + AC97C_AssignOutputSlots(0, 0xFFFF); + + // Install the AC97C interrupt handler + AT91C_BASE_AC97C->AC97C_IDR = 0xFFFFFFFF; + AIC_ConfigureIT(AT91C_ID_AC97C, 0, AC97C_Handler); + AIC_EnableIT(AT91C_ID_AC97C); + + // Disable PDC transfers + AT91C_BASE_AC97C->AC97C_PTCR = AT91C_PDC_TXTDIS | AT91C_PDC_RXTDIS; + + // Clear channel transfers + for (channel = 0; channel < AC97C_CHANNEL_B_TRANSMIT; channel++) { + + ac97c.transfers[channel].numSamples = 0; + } +} + +//------------------------------------------------------------------------------ +/// Configures the desired channel with the given value. +/// \param channel Channel number. +/// \param cfg Configuration value. +//------------------------------------------------------------------------------ +void AC97C_ConfigureChannel(unsigned char channel, unsigned int cfg) +{ + SANITY_CHECK((channel == AC97C_CHANNEL_A) || (channel == AC97C_CHANNEL_B)); + + if (channel == AC97C_CHANNEL_A) { + + AT91C_BASE_AC97C->AC97C_CAMR = cfg; + } + else { + + AT91C_BASE_AC97C->AC97C_CBMR = cfg; + } +} + +//------------------------------------------------------------------------------ +/// Assigns the desired input slots to a particular channel. +/// \param channel Channel number (or 0 to unassign slots). +/// \param slots Bitfield value of slots to assign. +//------------------------------------------------------------------------------ +void AC97C_AssignInputSlots(unsigned char channel, unsigned int slots) +{ + unsigned int value; + unsigned int i; + + SANITY_CHECK(channel <= AC97C_CHANNEL_B); + + // Assign all slots + slots >>= 3; + for (i = 3; i < 15; i++) { + + // Check if slots is selected + if (slots & 1) { + + value = AT91C_BASE_AC97C->AC97C_ICA; + value &= ~(0x07 << ((i - 3) * 3)); + value |= channel << ((i - 3) * 3); + AT91C_BASE_AC97C->AC97C_ICA = value; + } + slots >>= 1; + } +} + +//------------------------------------------------------------------------------ +/// Assigns the desired output slots to a particular channel. +/// \param channel Channel number (or 0 to unassign slots). +/// \param slots Bitfield value of slots to assign. +//------------------------------------------------------------------------------ +void AC97C_AssignOutputSlots(unsigned char channel, unsigned int slots) +{ + unsigned int value; + unsigned int i; + + SANITY_CHECK(channel <= AC97C_CHANNEL_B); + + // Assign all slots + slots >>= 3; + for (i = 3; i < 15; i++) { + + // Check if slots is selected + if (slots & 1) { + + value = AT91C_BASE_AC97C->AC97C_OCA; + value &= ~(0x07 << ((i - 3) * 3)); + value |= channel << ((i - 3) * 3); + AT91C_BASE_AC97C->AC97C_OCA = value; + } + slots >>= 1; + } +} + +//------------------------------------------------------------------------------ +/// Returns 1 if no transfer is currently pending on the given channel; +/// otherwise, returns 0. +/// \param channel Channel number. +//------------------------------------------------------------------------------ +unsigned char AC97C_IsFinished(unsigned char channel) +{ + SANITY_CHECK(channel <= AC97C_CHANNEL_B_TRANSMIT); + + if (ac97c.transfers[channel].numSamples > 0) { + + return 0; + } + else { + + return 1; + } +} + +//------------------------------------------------------------------------------ +/// Convenience function for synchronously sending commands to the codec. +/// \param address Register address. +/// \param data Command data. +//------------------------------------------------------------------------------ +void AC97C_WriteCodec(unsigned char address, unsigned short data) +{ + unsigned int sample; + + sample = (address << 16) | data; + AC97C_Transfer(AC97C_CODEC_TRANSFER, (unsigned char *) &sample, 1, 0, 0); + while (!AC97C_IsFinished(AC97C_CODEC_TRANSFER)); +} + +//------------------------------------------------------------------------------ +/// Convenience function for receiving data from the AC97 codec. +/// \param address Register address. +//------------------------------------------------------------------------------ +unsigned short AC97C_ReadCodec(unsigned char address) +{ + unsigned int sample; + + sample = AT91C_AC97C_READ | (address << 16); + AC97C_Transfer(AC97C_CODEC_TRANSFER, (unsigned char *) &sample, 1, 0, 0); + while (!AC97C_IsFinished(AC97C_CODEC_TRANSFER)); + + return sample; +} + +//------------------------------------------------------------------------------ +/// Sets the size in bits of one sample on the given channel. +/// \param channel Channel number. +/// \param size Size of one sample in bits (10, 16, 18 or 24). +//------------------------------------------------------------------------------ +void AC97C_SetChannelSize(unsigned char channel, unsigned char size) +{ + unsigned int bits = 0; + + SANITY_CHECK((size == 10) || (size == 16) || (size == 18) || (size == 24)); + SANITY_CHECK((channel == AC97C_CHANNEL_A) || (channel == AC97C_CHANNEL_B)); + + switch (size) { + + case 10 : bits = AT91C_AC97C_SIZE_10_BITS; break; + case 16 : bits = AT91C_AC97C_SIZE_16_BITS; break; + case 18 : bits = AT91C_AC97C_SIZE_18_BITS; break; + case 20 : bits = AT91C_AC97C_SIZE_20_BITS; break; + } + + if (channel == AC97C_CHANNEL_A) { + + AT91C_BASE_AC97C->AC97C_CAMR &= ~(AT91C_AC97C_SIZE); + AT91C_BASE_AC97C->AC97C_CAMR |= bits; + } + else { + + AT91C_BASE_AC97C->AC97C_CBMR &= ~(AT91C_AC97C_SIZE); + AT91C_BASE_AC97C->AC97C_CBMR |= bits; + } +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ac97c/ac97c.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ac97c/ac97c.h new file mode 100644 index 000000000..1dbb1a8e4 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ac97c/ac97c.h @@ -0,0 +1,168 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// This module provides definitions and functions for using the AC'97 +/// controller (AC97C). +/// +/// !!!Usage +/// +/// -# Enable the AC'97 interface pins (see pio & board.h). +/// -# Configure the AC'97 controller using AC97C_Configure +/// -# Assign the input and output slots to channels, and the data size used to +/// transfer AC97 data stream. +/// - Three functions can be used: +/// - AC97C_AssignInputSlots: set slots for AC'97 data in, recording. +/// - AC97C_AssignOutputSlots: set slots for AC'97 data out, playing. +/// - AC97C_SetChannelSize: set data sizes in bits for AC'97 data stream. +/// - Three different channels can be configured: +/// - AC97C_CHANNEL_CODEC: AC'97 register access channel, its size is +/// fixed and #must not# change by AC97C_SetChannelSize +/// - AC97C_CHANNEL_A: AC'97 stream channel, with PDC support. +/// - AC97C_CHANNEL_B: AC'97 data channel, without PDC support. +/// -# Configure the used AC97 channel with AC97C_ConfigureChannel, to enable +/// the channel. +/// -# Then you can operate the connected AC'97 codec: +/// - AC97C_ReadCodec / AC97C_WriteCodec: Read / Write codec register. +/// - AC97C_Transfer: Transfer through AC97C channels to setup codec register +/// or transfer %audio data stream. +/// - AC97C_CODEC_TRANSFER: access the codec register. +/// - AC97C_CHANNEL_A_RECEIVE, AC97C_CHANNEL_B_RECEIVE: start reading. +/// - AC97C_CHANNEL_A_TRANSMIT, AC97C_CHANNEL_B_TRANSMIT: start writing. +/// Normally you can initialize a set of AC'97 codec registers to initialize +/// the codec for %audio playing and recording. +/// -# Example code for playing & recording: +/// - General process: +/// -# Configure the codec registers for the %audio settings and formats; +/// -# Setup the channel size if necessery; +/// -# Start %audio stream transfer. +/// - Audio playing sample: +/// \code +/// // Configure sample rate of codec +/// AC97C_WriteCodec(AD1981B_PMC_DAC, expectedSampleRate); +/// // Set channel size +/// AC97C_SetChannelSize(AC97C_CHANNEL_A, bitsPerSample); +/// // Start channel A transfer +/// AC97C_Transfer(AC97C_CHANNEL_A_TRANSMIT, +/// (unsigned char *) (pointerToAudioDataBuffer), +/// numberOfSamplesToSend, +/// (Ac97Callback) PlayingFinished, +/// 0); +/// \endcode +/// - Audio recording sample: +/// \code +/// // Enable recording +/// AC97C_WriteCodec(AD1981B_REC_SEL, 0); +/// // Set sample rate +/// AC97C_WriteCodec(AD1981B_PMC_ADC, 7000); +/// // Always use 16-bits recording +/// AC97C_SetChannelSize(AC97C_CHANNEL_A, 16); +/// // Start recording +/// AC97C_Transfer(AC97C_CHANNEL_A_RECEIVE, +/// (unsigned char *) RECORD_ADDRESS, +/// MAX_RECORD_SIZE, +/// (Ac97Callback) RecordFinished, +/// 0); +/// \endcode +//------------------------------------------------------------------------------ + +#ifndef AC97C_H +#define AC97C_H + +//------------------------------------------------------------------------------ +// Constants +//------------------------------------------------------------------------------ + +/// The channel is already busy with a transfer. +#define AC97C_ERROR_BUSY 1 +/// The transfer has been stopped by the user. +#define AC97C_ERROR_STOPPED 2 + +/// Codec channel index. +#define AC97C_CHANNEL_CODEC 0 +/// Channel A index. +#define AC97C_CHANNEL_A 1 +/// Channel B index. +#define AC97C_CHANNEL_B 2 + +/// Codec transmit/receive transfer index. +#define AC97C_CODEC_TRANSFER 0 +/// Channel A receive transfer index. +#define AC97C_CHANNEL_A_RECEIVE 1 +/// Channel A transmit transfer index. +#define AC97C_CHANNEL_A_TRANSMIT 2 +/// Channel B receive transfer index. +#define AC97C_CHANNEL_B_RECEIVE 3 +/// Channel B transmit transfer index. +#define AC97C_CHANNEL_B_TRANSMIT 4 + +//------------------------------------------------------------------------------ +// Types +//------------------------------------------------------------------------------ + +/// AC97C transfer callback function. +typedef void (*Ac97Callback)(void *pArg, + unsigned char status, + unsigned int remaining); + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +extern void AC97C_Configure(); + +extern void AC97C_ConfigureChannel(unsigned char channel, unsigned int cfg); + +extern void AC97C_AssignInputSlots(unsigned char channel, unsigned int slots); + +extern void AC97C_AssignOutputSlots(unsigned char channel, unsigned int slots); + +extern unsigned char AC97C_Transfer( + unsigned char channel, + unsigned char *pBuffer, + unsigned int numSamples, + Ac97Callback callback, + void *pArg); + +extern unsigned char AC97C_IsFinished(unsigned char channel); + +extern void AC97C_WriteCodec(unsigned char address, unsigned short data); + +extern unsigned short AC97C_ReadCodec(unsigned char address); + +extern void AC97C_SetChannelSize(unsigned char channel, unsigned char size); + +extern void AC97C_CancelTransfer(unsigned char channel); + +#endif //#ifndef AC97C_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/adc/adc.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/adc/adc.c new file mode 100644 index 000000000..8c1283674 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/adc/adc.c @@ -0,0 +1,346 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include +#include +#include +#include + +//----------------------------------------------------------------------------- +/// Configure the Mode Register of the ADC controller +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \param mode value to write in mode register +//----------------------------------------------------------------------------- + +//replaced with macro definition in adc.h + +//void ADC_CfgModeReg(AT91S_ADC *pAdc, unsigned int mode, unsigned int extmode) +//{ +// ASSERT((mode&0xF00000C0)== 0, "ADC Bad configuration ADC MR"); +// +// // Write to the MR register +// pAdc->ADC_MR = mode; +//} + +//------------------------------------------------------------------------------ +// Global Functions +//------------------------------------------------------------------------------ + +//----------------------------------------------------------------------------- +/// Initialize the ADC controller +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \param trgEn trigger mode, software or Hardware +/// \param trgSel hardware trigger selection +/// \param sleepMode sleep mode selection +/// \param resolution resolution selection 8 bits or 10 bits +/// \param mckClock value of MCK in Hz +/// \param adcClock value of the ADC clock in Hz +/// \param startupTime value of the start up time (in µs) (see datasheet) +/// \param sampleAndHoldTime (in ns) +//----------------------------------------------------------------------------- +void ADC_Initialize (AT91S_ADC *pAdc, + unsigned char idAdc, + unsigned char trgEn, + unsigned char trgSel, + unsigned char sleepMode, + unsigned char resolution, + unsigned int mckClock, + unsigned int adcClock, + unsigned int startupTime, + unsigned int sampleAndHoldTime) +{ + unsigned int prescal; + unsigned int startup; + unsigned int shtim; + + ASSERT(startupTime<=ADC_STARTUP_TIME_MAX, "ADC Bad startupTime\n\r"); + ASSERT(sampleAndHoldTime>=ADC_TRACK_HOLD_TIME_MIN, "ADC Bad sampleAndHoldTime\n\r"); + + // Example: + // 5 MHz operation, 20µs startup time, 600ns track and hold time + // PRESCAL: Prescaler Rate Selection ADCClock = MCK / ( (PRESCAL+1) * 2 ) + // PRESCAL = [MCK / (ADCClock * 2)] -1 = [48/(5*2)]-1 = 3,8 + // PRESCAL = 4 -> 48/((4+1)*2) = 48/10 = 4.8MHz + // 48/((3+1)*2) = 48/8 = 6MHz + // Startup Time = (STARTUP+1) * 8 / ADCClock + // STARTUP = [(Startup Time * ADCClock)/8]-1 = [(20 10e-6 * 5000000)/8]-1 = 11,5 + // STARTUP = 11 -> (11+1)*8/48000000 = 96/4800000 = 20µs + // + // Sample & Hold Time = (SHTIM+1) / ADCClock + // SHTIM = (HoldTime * ADCClock)-1 = (600 10e-9 * 5000000)-1 = 2 + // SHTIM = 2 -> (2+1)/4800000 = 1/1200000 = 833ns + prescal = (mckClock / (2*adcClock)) - 1; + startup = ((adcClock/1000000) * startupTime / 8) - 1; + shtim = (((adcClock/1000000) * sampleAndHoldTime)/1000) - 1; + + ASSERT( (prescal<0x3F), "ADC Bad PRESCAL\n\r"); + ASSERT(startup<0x7F, "ADC Bad STARTUP\n\r"); + ASSERT(shtim<0xF, "ADC Bad SampleAndHoldTime\n\r"); + + TRACE_DEBUG("adcClock:%d MasterClock:%d\n\r", (mckClock/((prescal+1)*2)), mckClock); + TRACE_DEBUG("prescal:0x%X startup:0x%X shtim:0x%X\n\r", prescal, startup, shtim); + + if( adcClock != (mckClock/((prescal+1)*2)) ) { + TRACE_WARNING("User and calculated adcClocks are different : user=%d calc=%d\n\r", + adcClock, (mckClock/((prescal+1)*2))); + } + + // Enable peripheral clock + AT91C_BASE_PMC->PMC_PCER = 1 << idAdc; + + // Reset the controller + ADC_SoftReset(pAdc); + + // Write to the MR register + ADC_CfgModeReg( pAdc, + ( trgEn & AT91C_ADC_TRGEN) + | ( trgSel & AT91C_ADC_TRGSEL) + | ( resolution & AT91C_ADC_LOWRES) + | ( sleepMode & AT91C_ADC_SLEEP) + | ( (prescal<<8) & AT91C_ADC_PRESCAL) + | ( (startup<<16) & AT91C_ADC_STARTUP) + | ( (shtim<<24) & AT91C_ADC_SHTIM) ); +} + +//----------------------------------------------------------------------------- +/// Return the Mode Register of the ADC controller value +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \return ADC Mode register +//----------------------------------------------------------------------------- + +//replaced with macro definition in adc.h + +//unsigned int ADC_GetModeReg(AT91S_ADC *pAdc) +//{ +// return pAdc->ADC_MR; +//} + +//----------------------------------------------------------------------------- +/// Enable Channel +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \param channel channel to enable +//----------------------------------------------------------------------------- +//void ADC_EnableChannel(AT91S_ADC *pAdc, unsigned int channel) +//{ +// ASSERT(channel < 8, "ADC Channel not exist"); +// +// // Write to the CHER register +// pAdc->ADC_CHER = (1 << channel); +//} + +//----------------------------------------------------------------------------- +/// Disable Channel +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \param channel channel to disable +//----------------------------------------------------------------------------- +//void ADC_DisableChannel (AT91S_ADC *pAdc, unsigned int channel) +//{ +// ASSERT(channel < 8, "ADC Channel not exist"); +// +// // Write to the CHDR register +// pAdc->ADC_CHDR = (1 << channel); +//} + +//----------------------------------------------------------------------------- +/// Return chanel status +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \return ADC Channel Status Register +//----------------------------------------------------------------------------- +//unsigned int ADC_GetChannelStatus(AT91S_ADC *pAdc) +//{ +// return pAdc->ADC_CHSR; +//} + +//----------------------------------------------------------------------------- +/// Software request for a analog to digital conversion +/// \param pAdc Pointer to an AT91S_ADC instance. +//----------------------------------------------------------------------------- +//void ADC_StartConversion(AT91S_ADC *pAdc) +//{ +// pAdc->ADC_CR = AT91C_ADC_START; +//} + +//----------------------------------------------------------------------------- +/// Software reset +/// \param pAdc Pointer to an AT91S_ADC instance. +//----------------------------------------------------------------------------- +//void ADC_SoftReset(AT91S_ADC *pAdc) +//{ +// pAdc->ADC_CR = AT91C_ADC_SWRST; +//} + +//----------------------------------------------------------------------------- +/// Return the Last Converted Data +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \return Last Converted Data +//----------------------------------------------------------------------------- +//unsigned int ADC_GetLastConvertedData(AT91S_ADC *pAdc) +//{ +// return pAdc->ADC_LCDR; +//} + +//----------------------------------------------------------------------------- +/// Return the Channel Converted Data +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \param channel channel to get converted value +/// \return Channel converted data of the specified channel +//----------------------------------------------------------------------------- +unsigned int ADC_GetConvertedData(AT91S_ADC *pAdc, unsigned int channel) +{ + unsigned int data=0; + + ASSERT(channel < 8, "ADC channel not exist"); + + switch(channel) { + case 0: data = pAdc->ADC_CDR0; break; + case 1: data = pAdc->ADC_CDR1; break; + case 2: data = pAdc->ADC_CDR2; break; + case 3: data = pAdc->ADC_CDR3; break; + #ifdef AT91C_ADC_CDR4 + case 4: data = pAdc->ADC_CDR4; break; + #endif + #ifdef AT91C_ADC_CDR5 + case 5: data = pAdc->ADC_CDR5; break; + #endif + #ifdef AT91C_ADC_CDR6 + case 6: data = pAdc->ADC_CDR6; break; + #endif + #ifdef AT91C_ADC_CDR7 + case 7: data = pAdc->ADC_CDR7; break; + #endif + } + return data; +} + +//----------------------------------------------------------------------------- +/// Enable ADC interrupt +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \param flag IT to be enabled +//----------------------------------------------------------------------------- +//void ADC_EnableIt(AT91S_ADC *pAdc, unsigned int flag) +//{ +// ASSERT((flag&0xFFF00000)== 0, "ADC bad interrupt IER"); +// +// // Write to the IER register +// pAdc->ADC_IER = flag; +//} + +//----------------------------------------------------------------------------- +/// Enable ADC Data Ready interrupt +/// \param pAdc Pointer to an AT91S_ADC instance. +//----------------------------------------------------------------------------- + +//void ADC_EnableDataReadyIt(AT91S_ADC *pAdc) +//{ +// pAdc->ADC_IER = AT91C_ADC_DRDY; +//} + +//----------------------------------------------------------------------------- +/// Disable ADC interrupt +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \param flag IT to be disabled +//----------------------------------------------------------------------------- +//void ADC_DisableIt(AT91S_ADC *pAdc, unsigned int flag) +//{ +// ASSERT((flag&0xFFF00000)== 0, "ADC bad interrupt IDR"); +// +// // Write to the IDR register +// pAdc->ADC_IDR = flag; +//} + +//----------------------------------------------------------------------------- +/// Return ADC Interrupt Status +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \return ADC Stats register +//----------------------------------------------------------------------------- +//unsigned int ADC_GetStatus(AT91S_ADC *pAdc) +//{ +// return pAdc->ADC_SR; +//} + +//----------------------------------------------------------------------------- +/// Return ADC Interrupt Mask Status +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \return ADC Interrupt Mask Register +//----------------------------------------------------------------------------- +//unsigned int ADC_GetInterruptMaskStatus(AT91S_ADC *pAdc) +//{ +// return pAdc->ADC_IMR; +//} + +//----------------------------------------------------------------------------- +/// Test if ADC Interrupt is Masked +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \param flag flag to be tested +/// \return 1 if interrupt is masked, otherwise 0 +//----------------------------------------------------------------------------- +unsigned int ADC_IsInterruptMasked(AT91S_ADC *pAdc, unsigned int flag) +{ + return (ADC_GetInterruptMaskStatus(pAdc) & flag); +} + +//----------------------------------------------------------------------------- +/// Test if ADC Status is Set +/// \param pAdc Pointer to an AT91S_ADC instance. +/// \param flag flag to be tested +/// \return 1 if the staus is set; 0 otherwise +//----------------------------------------------------------------------------- +unsigned int ADC_IsStatusSet(AT91S_ADC *pAdc, unsigned int flag) +{ + return (ADC_GetStatus(pAdc) & flag); +} + + +//----------------------------------------------------------------------------- +/// Test if ADC channel interrupt Status is Set +/// \param adc_sr Value of SR register +/// \param channel Channel to be tested +/// \return 1 if interrupt status is set, otherwise 0 +//----------------------------------------------------------------------------- +unsigned char ADC_IsChannelInterruptStatusSet(unsigned int adc_sr, + unsigned int channel) +{ + unsigned char status; + + if((adc_sr & (1< + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ +#define ADC_CHANNEL_0 0 +#define ADC_CHANNEL_1 1 +#define ADC_CHANNEL_2 2 +#define ADC_CHANNEL_3 3 +#define ADC_CHANNEL_4 4 +#define ADC_CHANNEL_5 5 +#define ADC_CHANNEL_6 6 +#define ADC_CHANNEL_7 7 + +//------------------------------------------------------------------------------ +// Macros function of register access +//------------------------------------------------------------------------------ +#define ADC_CfgModeReg(pAdc, mode) { \ + ASSERT(((mode)&0xF00000C0)== 0, "ADC Bad configuration ADC MR");\ + (pAdc)->ADC_MR = (mode);\ + } + +#define ADC_GetModeReg(pAdc) ((pAdc)->ADC_MR) + +#define ADC_StartConversion(pAdc) ((pAdc)->ADC_CR = AT91C_ADC_START) + +#define ADC_SoftReset(pAdc) ((pAdc)->ADC_CR = AT91C_ADC_SWRST) + +#define ADC_EnableChannel(pAdc, channel) {\ + ASSERT(channel < 8, "ADC Channel not exist");\ + (pAdc)->ADC_CHER = (1 << (channel));\ + } + +#define ADC_DisableChannel (pAdc, channel) {\ + ASSERT((channel) < 8, "ADC Channel not exist");\ + (pAdc)->ADC_CHDR = (1 << (channel));\ + } + + +#define ADC_EnableIt(pAdc, mode) {\ + ASSERT(((mode)&0xFFF00000)== 0, "ADC bad interrupt IER");\ + (pAdc)->ADC_IER = (mode);\ + } + +#define ADC_DisableIt(pAdc, mode) {\ + ASSERT(((mode)&0xFFF00000)== 0, "ADC bad interrupt IDR");\ + (pAdc)->ADC_IDR = (mode);\ + } + +#define ADC_EnableDataReadyIt(pAdc) ((pAdc)->ADC_IER = AT91C_ADC_DRDY) + +#define ADC_GetStatus(pAdc) ((pAdc)->ADC_SR) + +#define ADC_GetChannelStatus(pAdc) ((pAdc)->ADC_CHSR) + +#define ADC_GetInterruptMaskStatus(pAdc) ((pAdc)->ADC_IMR) + +#define ADC_GetLastConvertedData(pAdc) ((pAdc)->ADC_LCDR) + + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +extern void ADC_Initialize (AT91S_ADC *pAdc, + unsigned char idAdc, + unsigned char trgEn, + unsigned char trgSel, + unsigned char sleepMode, + unsigned char resolution, + unsigned int mckClock, + unsigned int adcClock, + unsigned int startupTime, + unsigned int sampleAndHoldTime); +//extern void ADC_CfgModeReg(AT91S_ADC *pAdc, unsigned int mode); +//extern unsigned int ADC_GetModeReg(AT91S_ADC *pAdc); +//extern void ADC_EnableChannel(AT91S_ADC *pAdc, unsigned int channel); +//extern void ADC_DisableChannel (AT91S_ADC *pAdc, unsigned int channel); +//extern unsigned int ADC_GetChannelStatus(AT91S_ADC *pAdc); +//extern void ADC_StartConversion(AT91S_ADC *pAdc); +//extern void ADC_SoftReset(AT91S_ADC *pAdc); +//extern unsigned int ADC_GetLastConvertedData(AT91S_ADC *pAdc); +extern unsigned int ADC_GetConvertedData(AT91S_ADC *pAdc, unsigned int channel); +//extern void ADC_EnableIt(AT91S_ADC *pAdc, unsigned int flag); +//extern void ADC_EnableDataReadyIt(AT91S_ADC *pAdc); +//extern void ADC_DisableIt(AT91S_ADC *pAdc, unsigned int flag); +//extern unsigned int ADC_GetStatus(AT91S_ADC *pAdc); +//extern unsigned int ADC_GetInterruptMaskStatus(AT91S_ADC *pAdc); +extern unsigned int ADC_IsInterruptMasked(AT91S_ADC *pAdc, unsigned int flag); +extern unsigned int ADC_IsStatusSet(AT91S_ADC *pAdc, unsigned int flag); +extern unsigned char ADC_IsChannelInterruptStatusSet(unsigned int adc_sr, + unsigned int channel); + +#endif //#ifndef ADC_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/adc/adc12.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/adc/adc12.h new file mode 100644 index 000000000..bbf3b46f4 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/adc/adc12.h @@ -0,0 +1,142 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Interface for configuration the Analog-to-Digital Converter (ADC) peripheral. +/// +/// !Usage +/// +/// -# Configurate the pins for ADC +/// -# Initialize the ADC with ADC_Initialize(). +/// -# Select the active channel using ADC_EnableChannel() +/// -# Start the conversion with ADC_StartConversion() +// -# Wait the end of the conversion by polling status with ADC_GetStatus() +// -# Finally, get the converted data using ADC_GetConvertedData() +/// +//------------------------------------------------------------------------------ +#ifndef ADC12_H +#define ADC12_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ +#define ADC_CHANNEL_0 0 +#define ADC_CHANNEL_1 1 +#define ADC_CHANNEL_2 2 +#define ADC_CHANNEL_3 3 +#define ADC_CHANNEL_4 4 +#define ADC_CHANNEL_5 5 +#define ADC_CHANNEL_6 6 +#define ADC_CHANNEL_7 7 + +//------------------------------------------------------------------------------ +// Macros function of register access +//------------------------------------------------------------------------------ +#define ADC12_CfgModeReg(pAdc, mode) { \ + ASSERT(((mode)&0xF00000C0)== 0, "ADC Bad configuration ADC MR");\ + (pAdc)->ADC_MR = (mode);\ + } + +#define ADC12_GetModeReg(pAdc) ((pAdc)->ADC_MR) + +#define ADC12_StartConversion(pAdc) ((pAdc)->ADC_CR = AT91C_ADC_START) + +#define ADC12_SoftReset(pAdc) ((pAdc)->ADC_CR = AT91C_ADC_SWRST) + +#define ADC12_EnableChannel(pAdc, channel) {\ + ASSERT(channel < 8, "ADC Channel not exist");\ + (pAdc)->ADC_CHER = (1 << (channel));\ + } + +#define ADC12_DisableChannel (pAdc, channel) {\ + ASSERT((channel) < 8, "ADC Channel not exist");\ + (pAdc)->ADC_CHDR = (1 << (channel));\ + } + +#define ADC12_EnableIt(pAdc, mode) {\ + ASSERT(((mode)&0xFFF00000)== 0, "ADC bad interrupt IER");\ + (pAdc)->ADC_IER = (mode);\ + } + +#define ADC12_DisableIt(pAdc, mode) {\ + ASSERT(((mode)&0xFFF00000)== 0, "ADC bad interrupt IDR");\ + (pAdc)->ADC_IDR = (mode);\ + } + +#define ADC12_EnableDataReadyIt(pAdc) ((pAdc)->ADC_IER = AT91C_ADC_DRDY) + +#define ADC12_GetStatus(pAdc) ((pAdc)->ADC_SR) + +#define ADC12_GetChannelStatus(pAdc) ((pAdc)->ADC_CHSR) + +#define ADC12_GetInterruptMaskStatus(pAdc) ((pAdc)->ADC_IMR) + +#define ADC12_GetLastConvertedData(pAdc) ((pAdc)->ADC_LCDR) + +#define ADC12_CfgAnalogCtrlReg(pAdc,mode) {\ + ASSERT(((mode) & 0xFFFCFF3C)==0, "ADC bad analog control config");\ + (pAdc)->ADC_ACR = (mode);\ + } + +#define ADC12_CfgExtModeReg(pAdc, extmode) {\ + ASSERT(((extmode) & 0xFF00FFFE)==0, "ADC bad extended mode config");\ + (pAdc)->ADC_EMR = (extmode);\ + } + +#define ADC12_GetAnalogCtrlReg(pAdc) ((pAdc)->ADC_ACR) + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +extern void ADC12_Initialize (AT91S_ADC *pAdc, + unsigned char idAdc, + unsigned char trgEn, + unsigned char trgSel, + unsigned char sleepMode, + unsigned char resolution, + unsigned int mckClock, + unsigned int adcClock, + unsigned int startupTime, + unsigned int sampleAndHoldTime); +extern unsigned int ADC12_GetConvertedData(AT91S_ADC *pAdc, unsigned int channel); +extern unsigned int ADC12_IsInterruptMasked(AT91S_ADC *pAdc, unsigned int flag); +extern unsigned int ADC12_IsStatusSet(AT91S_ADC *pAdc, unsigned int flag); +extern unsigned char ADC12_IsChannelInterruptStatusSet(unsigned int adc_sr, + unsigned int channel); + +#endif //#ifndef ADC12_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/aes/aes.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/aes/aes.c new file mode 100644 index 000000000..09848f8b0 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/aes/aes.c @@ -0,0 +1,192 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "aes.h" +#include +#include +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Configures the AES peripheral to encrypt/decrypt, start mode (manual, auto, +/// PDC) and operating mode (ECB, CBC, OFB, CFB, CTR). +/// \param cipher Indicates if the peripheral should encrypt or decrypt data. +/// \param smode Start mode. +/// \param opmode Operating mode. +//------------------------------------------------------------------------------ +void AES_Configure( + unsigned char cipher, + unsigned int smode, + unsigned int opmode) +{ + TRACE_DEBUG("AES_Configure()\n\r"); + SANITY_CHECK((cipher & 0xFFFFFFFE) == 0); + SANITY_CHECK((smode & 0xFFFFFCFF) == 0); + SANITY_CHECK((opmode & 0xFFFF8FFF) == 0); + + // Reset the peripheral first + AT91C_BASE_AES->AES_CR = AT91C_AES_SWRST; + + // Configure mode register + AT91C_BASE_AES->AES_MR = cipher | smode | opmode; +} + +//------------------------------------------------------------------------------ +/// Sets the key used by the AES algorithm to cipher the plain text or +/// decipher the encrypted text. +/// \param pKey Pointer to a 16-bytes cipher key. +//------------------------------------------------------------------------------ +void AES_SetKey(const unsigned int *pKey) +{ + TRACE_DEBUG("AES_SetKey()\n\r"); + SANITY_CHECK(pKey); + + AT91C_BASE_AES->AES_KEYWxR[0] = pKey[0]; + AT91C_BASE_AES->AES_KEYWxR[1] = pKey[1]; + AT91C_BASE_AES->AES_KEYWxR[2] = pKey[2]; + AT91C_BASE_AES->AES_KEYWxR[3] = pKey[3]; +} + +//------------------------------------------------------------------------------ +/// Sets the initialization vector that is used to encrypt the plain text or +/// decrypt the cipher text in chained block modes (CBC, CFB, OFB & CTR). +/// \param pVector Pointer to a 16-bytes initialization vector. +//------------------------------------------------------------------------------ +void AES_SetVector(const unsigned int *pVector) +{ + TRACE_DEBUG("AES_SetVector()\n\r"); + SANITY_CHECK(pVector); + + AT91C_BASE_AES->AES_IVxR[0] = pVector[0]; + AT91C_BASE_AES->AES_IVxR[1] = pVector[1]; + AT91C_BASE_AES->AES_IVxR[2] = pVector[2]; + AT91C_BASE_AES->AES_IVxR[3] = pVector[3]; +} + +//------------------------------------------------------------------------------ +/// Sets the input data of the AES algorithm (i.e. plain text in cipher mode, +/// ciphered text in decipher mode). If auto mode is active, the encryption is +/// started automatically after writing the last word. +/// \param pData Pointer to the 16-bytes data to cipher/decipher. +//------------------------------------------------------------------------------ +void AES_SetInputData(const unsigned int *pData) +{ + TRACE_DEBUG("AES_SetInputData()\n\r"); + SANITY_CHECK(pData); + + AT91C_BASE_AES->AES_IDATAxR[0] = pData[0]; + AT91C_BASE_AES->AES_IDATAxR[1] = pData[1]; + AT91C_BASE_AES->AES_IDATAxR[2] = pData[2]; + AT91C_BASE_AES->AES_IDATAxR[3] = pData[3]; +} + +//------------------------------------------------------------------------------ +/// Stores the result of the last AES operation (encrypt/decrypt) in the +/// provided buffer. +/// \param pData Pointer to a 16-bytes buffer. +//------------------------------------------------------------------------------ +void AES_GetOutputData(unsigned int *pData) +{ + TRACE_DEBUG("AES_GetOutputData()\n\r"); + SANITY_CHECK(pData); + + pData[0] = AT91C_BASE_AES->AES_ODATAxR[0]; + pData[1] = AT91C_BASE_AES->AES_ODATAxR[1]; + pData[2] = AT91C_BASE_AES->AES_ODATAxR[2]; + pData[3] = AT91C_BASE_AES->AES_ODATAxR[3]; +} + +//------------------------------------------------------------------------------ +/// Sets the input buffer to use when in PDC mode. +/// \param pInput Pointer to the input buffer. +//------------------------------------------------------------------------------ +void AES_SetInputBuffer(const unsigned int *pInput) +{ + TRACE_DEBUG("AES_SetInputBuffer()\n\r"); + SANITY_CHECK(pInput); + + AT91C_BASE_AES->AES_TPR = (unsigned int) pInput; + AT91C_BASE_AES->AES_TCR = 4; +} + +//------------------------------------------------------------------------------ +/// Sets the output buffer to use when in PDC mode. +/// \param pOutput Pointer to the output buffer. +//------------------------------------------------------------------------------ +void AES_SetOutputBuffer(unsigned int *pOutput) +{ + TRACE_DEBUG("AES_SetOutputBuffer()\n\r"); + SANITY_CHECK(pOutput); + + AT91C_BASE_AES->AES_RPR = (unsigned int) pOutput; + AT91C_BASE_AES->AES_RCR = 4; +} + +//------------------------------------------------------------------------------ +/// Starts the encryption/decryption process when in manual or PDC mode. In +/// manual mode, the key and input data must have been entered using +/// AES_SetKey() and AES_SetInputData(). In PDC mode, the key, input & output +/// buffer must have been set using AES_SetKey(), AES_SetInputBuffer() and +/// AES_SetOutputBuffer(). +//------------------------------------------------------------------------------ +void AES_Start(void) +{ + TRACE_DEBUG("AES_Start()\n\r"); + SANITY_CHECK(((AT91C_BASE_AES->AES_MR & AT91C_AES_SMOD) == AT91C_AES_SMOD_MANUAL) + || ((AT91C_BASE_AES->AES_MR & AT91C_AES_SMOD) == AT91C_AES_SMOD_PDC)); + + // Manual mode + if ((AT91C_BASE_AES->AES_MR & AT91C_AES_SMOD) == AT91C_AES_SMOD_MANUAL) { + + AT91C_BASE_AES->AES_CR = AT91C_AES_START; + } + // PDC + else { + + AT91C_BASE_AES->AES_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTEN; + } +} + +//------------------------------------------------------------------------------ +/// Returns the current value of the AES interrupt status register. +//------------------------------------------------------------------------------ +unsigned int AES_GetStatus(void) +{ + TRACE_DEBUG("AES_GetStatus()\n\r"); + + return AT91C_BASE_AES->AES_ISR; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/aes/aes.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/aes/aes.h new file mode 100644 index 000000000..9f2f857bf --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/aes/aes.h @@ -0,0 +1,76 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef AES_H +#define AES_H + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Methods to manage the Advanced Encryption Standard (AES) +/// +/// !Usage +/// +/// -# Configure AES +/// -# Sets the key used by the AES algorithm +/// -# Sets the input data of the AES algorithm +/// -# Starts the encryption/decryption process +/// -# Stores the result of the last AES operation +/// +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void AES_Configure( + unsigned char cipher, + unsigned int smode, + unsigned int opmode); + +extern void AES_SetKey(const unsigned int *pKey); + +extern void AES_SetVector(const unsigned int *pVector); + +extern void AES_SetInputData(const unsigned int *pData); + +extern void AES_GetOutputData(unsigned int *pData); + +extern void AES_SetInputBuffer(const unsigned int *pInput); + +extern void AES_SetOutputBuffer(unsigned int *pOutput); + +extern void AES_Start(void); + +extern unsigned int AES_GetStatus(void); + +#endif //#ifndef AES_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/aic/aic.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/aic/aic.c new file mode 100644 index 000000000..4ff52c2fc --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/aic/aic.c @@ -0,0 +1,87 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "aic.h" +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Configures an interrupt in the AIC. The interrupt is identified by its +/// source (AT91C_ID_xxx) and is configured to use the specified mode and +/// interrupt handler function. Mode is the value that will be put in AIC_SMRx +/// and the function address will be set in AIC_SVRx. +/// The interrupt is disabled before configuration, so it is useless +/// to do it before calling this function. When AIC_ConfigureIT returns, the +/// interrupt will always be disabled and cleared; it must be enabled by a +/// call to AIC_EnableIT(). +/// \param source Interrupt source to configure. +/// \param mode Triggering mode and priority of the interrupt. +/// \param handler Interrupt handler function. +//------------------------------------------------------------------------------ +void AIC_ConfigureIT( + unsigned int source, + unsigned int mode, + void (*handler)(void)) +{ + // Disable the interrupt first + AT91C_BASE_AIC->AIC_IDCR = 1 << source; + + // Configure mode and handler + AT91C_BASE_AIC->AIC_SMR[source] = mode; + AT91C_BASE_AIC->AIC_SVR[source] = (unsigned int) handler; + + // Clear interrupt + AT91C_BASE_AIC->AIC_ICCR = 1 << source; +} + +//------------------------------------------------------------------------------ +/// Enables interrupts coming from the given (unique) source (AT91C_ID_xxx). +/// \param source Interrupt source to enable. +//------------------------------------------------------------------------------ +void AIC_EnableIT(unsigned int source) +{ + AT91C_BASE_AIC->AIC_IECR = 1 << source; +} + +//------------------------------------------------------------------------------ +/// Disables interrupts coming from the given (unique) source (AT91C_ID_xxx). +/// \param source Interrupt source to enable. +//------------------------------------------------------------------------------ +void AIC_DisableIT(unsigned int source) +{ + AT91C_BASE_AIC->AIC_IDCR = 1 << source; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/aic/aic.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/aic/aic.h new file mode 100644 index 000000000..bddf78796 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/aic/aic.h @@ -0,0 +1,79 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Methods and definitions for configuring interrupts using the Advanced +/// Interrupt Controller (AIC). +/// +/// !Usage +/// +/// -# Configure an interrupt source using AIC_ConfigureIT +/// -# Enable or disable interrupt generation of a particular source with +/// AIC_EnableIT and AIC_DisableIT. +/// +/// \note Most of the time, peripheral interrupts must be also configured +/// inside the peripheral itself. +//------------------------------------------------------------------------------ + +#ifndef AIC_H +#define AIC_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +#ifndef AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL + /// Interrupt is internal and uses a logical 1 level. + #define AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE +#endif + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void AIC_ConfigureIT(unsigned int source, + unsigned int mode, + void (*handler)( void )); + +extern void AIC_EnableIT(unsigned int source); + +extern void AIC_DisableIT(unsigned int source); + +#endif //#ifndef AIC_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/can/can.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/can/can.c new file mode 100644 index 000000000..3c2683521 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/can/can.c @@ -0,0 +1,1066 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include +#include +#include +#include +#include "can.h" + +//------------------------------------------------------------------------------ +// Local definitions +//------------------------------------------------------------------------------ +// CAN state +#define CAN_DISABLED 0 +#define CAN_HALTED 1 +#define CAN_IDLE 2 +#define CAN_SENDING 3 +#define CAN_RECEIVING 4 + +// MOT: Mailbox Object Type +#define CAN_MOT_DISABLE 0 // Mailbox is disabled +#define CAN_MOT_RECEPT 1 // Reception Mailbox +#define CAN_MOT_RECEPT_OW 2 // Reception mailbox with overwrite +#define CAN_MOT_TRANSMIT 3 // Transmit mailbox +#define CAN_MOT_CONSUMER 4 // Consumer mailbox +#define CAN_MOT_PRODUCER 5 // Producer mailbox + +//------------------------------------------------------------------------------ +// Local variables +//------------------------------------------------------------------------------ +#if defined (PINS_CAN_TRANSCEIVER_TXD) +static const Pin pins_can_transceiver_txd[] = {PINS_CAN_TRANSCEIVER_TXD}; +#endif +#if defined (PINS_CAN_TRANSCEIVER_RXD) +static const Pin pins_can_transceiver_rxd[] = {PINS_CAN_TRANSCEIVER_RXD}; +#endif +static const Pin pin_can_transceiver_rs = PIN_CAN_TRANSCEIVER_RS; +#if defined (PIN_CAN_TRANSCEIVER_RXEN) +static const Pin pin_can_transceiver_rxen = PIN_CAN_TRANSCEIVER_RXEN; +#endif + +static CanTransfer *pCAN0Transfer=NULL; +#ifdef AT91C_BASE_CAN1 +static CanTransfer *pCAN1Transfer=NULL; +#endif + +//------------------------------------------------------------------------------ +// Local functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// CAN Error Detection +/// \param status error type +/// \param can_number can nulber +//------------------------------------------------------------------------------ +static void CAN_ErrorHandling( unsigned int status, unsigned char can_number) +{ + if( (status&AT91C_CAN_ERRA) == AT91C_CAN_ERRA) { + TRACE_ERROR("(CAN) CAN is in active Error Active mode\n\r"); + } + else if( (status&AT91C_CAN_ERRP) == AT91C_CAN_ERRP) { + TRACE_ERROR("(CAN) CAN is in Error Passive mode\n\r"); + } + else if( (status&AT91C_CAN_BOFF) == AT91C_CAN_BOFF) { + TRACE_ERROR("(CAN) CAN is in Buff Off mode\n\r"); + // CAN reset + TRACE_ERROR("(CAN) CAN%d reset\n\r", can_number); + // CAN Controller Disable + if (can_number == 0) { + AT91C_BASE_CAN0->CAN_MR &= ~AT91C_CAN_CANEN; + // CAN Controller Enable + AT91C_BASE_CAN0->CAN_MR |= AT91C_CAN_CANEN; + } +#ifdef AT91C_BASE_CAN1 + else if (can_number == 1) { + AT91C_BASE_CAN1->CAN_MR &= ~AT91C_CAN_CANEN; + // CAN Controller Enable + AT91C_BASE_CAN1->CAN_MR |= AT91C_CAN_CANEN; + } +#endif + } + + // Error for Frame dataframe + // CRC error + if( (status&AT91C_CAN_CERR) == AT91C_CAN_CERR) { + TRACE_ERROR("(CAN) CRC Error\n\r"); + } + // Bit-stuffing error + else if( (status&AT91C_CAN_SERR) == AT91C_CAN_SERR) { + TRACE_ERROR("(CAN) Stuffing Error\n\r"); + } + // Bit error + else if( (status&AT91C_CAN_BERR) == AT91C_CAN_BERR) { + TRACE_ERROR("(CAN) Bit Error\n\r"); + } + // Form error + else if( (status&AT91C_CAN_FERR) == AT91C_CAN_FERR) { + TRACE_ERROR("(CAN) Form Error\n\r"); + } + // Acknowledgment error + else if( (status&AT91C_CAN_AERR) == AT91C_CAN_AERR) { + TRACE_ERROR("(CAN) Acknowledgment Error\n\r"); + } + + // Error interrupt handler + // Represent the current status of the CAN bus and are not latched. + // See CAN, par. Error Interrupt Handler + // AT91C_CAN_WARN + // AT91C_CAN_ERRA +} + +//------------------------------------------------------------------------------ +// Generic CAN Interrupt handler +/// \param can_number can nulber +//------------------------------------------------------------------------------ +static void CAN_Handler( unsigned char can_number ) +{ + AT91PS_CAN base_can; + AT91PS_CAN_MB CAN_Mailbox; + + unsigned int status; + unsigned int can_msr; + unsigned int* pCan_mcr; + unsigned int message_mode; + unsigned char numMailbox; + unsigned char state0=CAN_DISABLED; + unsigned char state1=CAN_DISABLED; + + if( can_number == 0 ) { + base_can = AT91C_BASE_CAN0; + CAN_Mailbox = AT91C_BASE_CAN0_MB0; + state0 = pCAN0Transfer->state; + } +#ifdef AT91C_BASE_CAN1 + else { + base_can = AT91C_BASE_CAN1; + CAN_Mailbox = AT91C_BASE_CAN1_MB0; + state1 = pCAN1Transfer->state; + } +#endif + status = (base_can->CAN_SR) & (base_can->CAN_IMR); + base_can->CAN_IDR = status; + + TRACE_DEBUG("CAN0 status=0x%X\n\r", status); + if(status & AT91C_CAN_WAKEUP) { + if( can_number == 0 ) { + pCAN0Transfer->test_can = AT91C_TEST_OK; + pCAN0Transfer->state = CAN_IDLE; + } +#ifdef AT91C_BASE_CAN1 + else { + pCAN1Transfer->test_can = AT91C_TEST_OK; + pCAN1Transfer->state = CAN_IDLE; + } +#endif + } + // Mailbox event ? + else if ((status&0x0000FFFF) != 0) { + TRACE_DEBUG("Mailbox event\n\r"); + + // Handle Mailbox interrupts + for (numMailbox = 0; numMailbox < NUM_MAILBOX_MAX; numMailbox++) { + + can_msr = *(unsigned int*)((unsigned int)CAN_Mailbox+(unsigned int)(0x10+(0x20*numMailbox))); + if ((AT91C_CAN_MRDY & can_msr) == AT91C_CAN_MRDY) { + // Mailbox object type + message_mode = ((*(unsigned int*)((unsigned int)CAN_Mailbox+(unsigned int)(0x00+(0x20*numMailbox))))>>24)&0x7; + TRACE_DEBUG("message_mode 0x%X\n\r", message_mode); + TRACE_DEBUG("numMailbox 0x%X\n\r", numMailbox); + + if( message_mode == 0 ) { + TRACE_ERROR("Error in MOT\n\r"); + } + else if( ( message_mode == CAN_MOT_RECEPT ) + || ( message_mode == CAN_MOT_RECEPT_OW ) + || ( message_mode == CAN_MOT_PRODUCER ) ) { + TRACE_DEBUG("Mailbox is in RECEPTION\n\r"); + TRACE_DEBUG("Length 0x%X\n\r", (can_msr>>16)&0xF); + TRACE_DEBUG("CAN_MB_MID 0x%X\n\r", ((*(unsigned int*)((unsigned int)CAN_Mailbox+(unsigned int)(0x08+(0x20*numMailbox)))&AT91C_CAN_MIDvA)>>18)); + + TRACE_DEBUG("can_number %d\n\r", can_number); + if( can_number == 0 ) { + //CAN_MB_MDLx + pCAN0Transfer->data_low_reg = + (*(unsigned int*)((unsigned int)CAN_Mailbox+(unsigned int)(0x14+(0x20*numMailbox)))); + //CAN_MB_MDHx + pCAN0Transfer->data_high_reg = + (*(unsigned int*)((unsigned int)CAN_Mailbox+(unsigned int)(0x18+(0x20*numMailbox)))); + pCAN0Transfer->size = (can_msr>>16)&0xF; + pCAN0Transfer->mailbox_number = numMailbox; + state0 = CAN_IDLE; + } +#ifdef AT91C_BASE_CAN1 + else { + //CAN_MB_MDLx + pCAN1Transfer->data_low_reg = + (*(unsigned int*)((unsigned int)CAN_Mailbox+(unsigned int)(0x14+(0x20*numMailbox)))); + //CAN_MB_MDHx + pCAN1Transfer->data_high_reg = + (*(unsigned int*)((unsigned int)CAN_Mailbox+(unsigned int)(0x18+(0x20*numMailbox)))); + pCAN1Transfer->size = (can_msr>>16)&0xF; + pCAN1Transfer->mailbox_number = numMailbox; + state1 = CAN_IDLE; + } +#endif + // Message Data has been received + pCan_mcr = (unsigned int*)((unsigned int)CAN_Mailbox+0x1C+(0x20*numMailbox)); + *pCan_mcr = AT91C_CAN_MTCR; + + } + else { + TRACE_DEBUG("Mailbox is in TRANSMIT\n\r"); + TRACE_DEBUG("Length 0x%X\n\r", (can_msr>>16)&0xF); + TRACE_DEBUG("can_number %d\n\r", can_number); + if( can_number == 0 ) { + state0 = CAN_IDLE; + } + else { + state1 = CAN_IDLE; + } + } + } + } + if( can_number == 0 ) { + pCAN0Transfer->state = state0; + } +#ifdef AT91C_BASE_CAN1 + else { + pCAN1Transfer->state = state1; + } +#endif + } + if ((status&0xFFCF0000) != 0) { + CAN_ErrorHandling(status, 0); + } +} + +//------------------------------------------------------------------------------ +/// CAN 0 Interrupt handler +//------------------------------------------------------------------------------ +static void CAN0_Handler(void) +{ + CAN_Handler( 0 ); +} + +//------------------------------------------------------------------------------ +/// CAN 1 Interrupt handler +//------------------------------------------------------------------------------ +#if defined AT91C_BASE_CAN1 +static void CAN1_Handler(void) +{ + CAN_Handler( 1 ); +} +#endif + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Configure the corresponding mailbox +/// \param pTransfer can transfer structure +//------------------------------------------------------------------------------ +void CAN_InitMailboxRegisters( CanTransfer *pTransfer ) +{ + AT91PS_CAN base_can; + AT91PS_CAN_MB CAN_Mailbox; + + if( pTransfer->can_number == 0 ) { + base_can = AT91C_BASE_CAN0; + CAN_Mailbox = AT91C_BASE_CAN0_MB0; + } +#ifdef AT91C_BASE_CAN1 + else { + base_can = AT91C_BASE_CAN1; + CAN_Mailbox = AT91C_BASE_CAN1_MB0; + } +#endif + CAN_Mailbox = (AT91PS_CAN_MB)((unsigned int)CAN_Mailbox+(unsigned int)(0x20*pTransfer->mailbox_number)); + + pTransfer->mailbox_in_use |= 1<<(pTransfer->mailbox_number); + // MailBox Control Register + CAN_Mailbox->CAN_MB_MCR = 0x0; + // MailBox Mode Register + CAN_Mailbox->CAN_MB_MMR = 0x00; + // CAN Message Acceptance Mask Register + CAN_Mailbox->CAN_MB_MAM = pTransfer->acceptance_mask_reg; + // MailBox ID Register + // Disable the mailbox before writing to CAN_MIDx registers + if( (pTransfer->identifier & AT91C_CAN_MIDE) == AT91C_CAN_MIDE ) { + // Extended + CAN_Mailbox->CAN_MB_MAM |= AT91C_CAN_MIDE; + } + else { + CAN_Mailbox->CAN_MB_MAM &= ~AT91C_CAN_MIDE; + } + CAN_Mailbox->CAN_MB_MID = pTransfer->identifier; + + // MailBox Mode Register + CAN_Mailbox->CAN_MB_MMR = pTransfer->mode_reg; + // MailBox Data Low Register + CAN_Mailbox->CAN_MB_MDL = pTransfer->data_low_reg; + // MailBox Data High Register + CAN_Mailbox->CAN_MB_MDH = pTransfer->data_high_reg; + // MailBox Control Register + CAN_Mailbox->CAN_MB_MCR = pTransfer->control_reg; +} + +//------------------------------------------------------------------------------ +/// Reset the MBx +//------------------------------------------------------------------------------ +void CAN_ResetAllMailbox( void ) +{ + unsigned char i; + +#if defined (AT91C_BASE_CAN0_MB0) + CAN_ResetTransfer( pCAN0Transfer ); + for( i=0; i<8; i++ ) { + pCAN0Transfer->can_number = 0; + pCAN0Transfer->mailbox_number = i; + pCAN0Transfer->mode_reg = AT91C_CAN_MOT_DIS; + pCAN0Transfer->acceptance_mask_reg = 0; + pCAN0Transfer->identifier = 0; + pCAN0Transfer->data_low_reg = 0x00000000; + pCAN0Transfer->data_high_reg = 0x00000000; + pCAN0Transfer->control_reg = 0x00000000; + CAN_InitMailboxRegisters( pCAN0Transfer ); + } +#endif +#if defined (AT91C_BASE_CAN0_MB8) + for( i=0; i<8; i++ ) { + pCAN0Transfer->can_number = 0; + pCAN0Transfer->mailbox_number = i+8; + pCAN0Transfer->mode_reg = AT91C_CAN_MOT_DIS; + pCAN0Transfer->acceptance_mask_reg = 0; + pCAN0Transfer->identifier = 0; + pCAN0Transfer->data_low_reg = 0x00000000; + pCAN0Transfer->data_high_reg = 0x00000000; + pCAN0Transfer->control_reg = 0x00000000; + CAN_InitMailboxRegisters( pCAN0Transfer ); + } +#endif + +#if defined (AT91C_BASE_CAN1_MB0) + if( pCAN1Transfer != NULL ) { + CAN_ResetTransfer( pCAN1Transfer ); + for( i=0; i<8; i++ ) { + pCAN1Transfer->can_number = 1; + pCAN1Transfer->mailbox_number = i; + pCAN1Transfer->mode_reg = AT91C_CAN_MOT_DIS; + pCAN1Transfer->acceptance_mask_reg = 0; + pCAN1Transfer->identifier = 0; + pCAN1Transfer->data_low_reg = 0x00000000; + pCAN1Transfer->data_high_reg = 0x00000000; + pCAN1Transfer->control_reg = 0x00000000; + CAN_InitMailboxRegisters( pCAN1Transfer ); + } + } +#endif +#if defined (AT91C_BASE_CAN1_MB8) + if( pCAN1Transfer != NULL ) { + for( i=0; i<8; i++ ) { + pCAN1Transfer->can_number = 1; + pCAN1Transfer->mailbox_number = i+8; + pCAN1Transfer->mode_reg = AT91C_CAN_MOT_DIS; + pCAN1Transfer->acceptance_mask_reg = 0; + pCAN1Transfer->identifier = 0; + pCAN1Transfer->data_low_reg = 0x00000000; + pCAN1Transfer->data_high_reg = 0x00000000; + pCAN1Transfer->control_reg = 0x00000000; + CAN_InitMailboxRegisters( pCAN1Transfer ); + } + } +#endif + +} + +//------------------------------------------------------------------------------ +/// CAN reset Transfer descriptor +/// \param pTransfer can transfer structure +//------------------------------------------------------------------------------ +void CAN_ResetTransfer( CanTransfer *pTransfer ) +{ + pTransfer->state = CAN_IDLE; + pTransfer->can_number = 0; + pTransfer->mailbox_number = 0; + pTransfer->test_can = 0; + pTransfer->mode_reg = 0; + pTransfer->acceptance_mask_reg = 0; + pTransfer->identifier = 0; + pTransfer->data_low_reg = 0; + pTransfer->data_high_reg = 0; + pTransfer->control_reg = 0; + pTransfer->mailbox_in_use = 0; + pTransfer->size = 0; +} + +//------------------------------------------------------------------------------ +/// Wait for CAN synchronisation +/// \return return 1 for good initialisation, otherwise return 0 +//------------------------------------------------------------------------------ +static unsigned char CAN_Synchronisation( void ) +{ + unsigned int tick=0; + + TRACE_INFO("CAN_Synchronisation\n\r"); + + pCAN0Transfer->test_can = AT91C_TEST_NOK; +#ifdef AT91C_BASE_CAN1 + if( pCAN1Transfer != NULL ) { + pCAN1Transfer->test_can = AT91C_TEST_NOK; + } +#endif + // Enable CAN and Wait for WakeUp Interrupt + AT91C_BASE_CAN0->CAN_IER = AT91C_CAN_WAKEUP; + // CAN Controller Enable + AT91C_BASE_CAN0->CAN_MR = AT91C_CAN_CANEN; + // Enable Autobaud/Listen mode + // dangerous, CAN not answer in this mode + + while( (pCAN0Transfer->test_can != AT91C_TEST_OK) + && (tick < AT91C_CAN_TIMEOUT) ) { + tick++; + } + if (tick == AT91C_CAN_TIMEOUT) { + TRACE_ERROR("CAN0 Initialisations FAILED\n\r"); + return 0; + } else { + TRACE_INFO("CAN0 Initialisations Completed\n\r"); + } + +#if defined AT91C_BASE_CAN1 + if( pCAN1Transfer != NULL ) { + AT91C_BASE_CAN1->CAN_IER = AT91C_CAN_WAKEUP; + // CAN Controller Enable + AT91C_BASE_CAN1->CAN_MR = AT91C_CAN_CANEN; + + tick = 0; + // Wait for WAKEUP flag raising <=> 11-recessive-bit were scanned by the transceiver + while( ((pCAN1Transfer->test_can != AT91C_TEST_OK)) + && (tick < AT91C_CAN_TIMEOUT) ) { + tick++; + } + + if (tick == AT91C_CAN_TIMEOUT) { + TRACE_ERROR("CAN1 Initialisations FAILED\n\r"); + return 0; + } else { + TRACE_INFO("CAN1 Initialisations Completed\n\r"); + } + } +#endif + return 1; +} + +//------------------------------------------------------------------------------ +/// Write a CAN transfer +/// \param pTransfer can transfer structure +/// \return return CAN_STATUS_SUCCESS if command passed, otherwise +/// return CAN_STATUS_LOCKED +//------------------------------------------------------------------------------ +unsigned char CAN_Write( CanTransfer *pTransfer ) +{ + AT91PS_CAN base_can; + + if (pTransfer->state == CAN_RECEIVING) { + pTransfer->state = CAN_IDLE; + } + + if (pTransfer->state != CAN_IDLE) { + return CAN_STATUS_LOCKED; + } + + TRACE_DEBUG("CAN_Write\n\r"); + pTransfer->state = CAN_SENDING; + if( pTransfer->can_number == 0 ) { + base_can = AT91C_BASE_CAN0; + } +#ifdef AT91C_BASE_CAN1 + else { + base_can = AT91C_BASE_CAN1; + } +#endif + base_can->CAN_TCR = pTransfer->mailbox_in_use; + base_can->CAN_IER = pTransfer->mailbox_in_use; + + return CAN_STATUS_SUCCESS; + +} + + +//------------------------------------------------------------------------------ +/// Read a CAN transfer +/// \param pTransfer can transfer structure +/// \return return CAN_STATUS_SUCCESS if command passed, otherwise +/// return CAN_STATUS_LOCKED +//------------------------------------------------------------------------------ +unsigned char CAN_Read( CanTransfer *pTransfer ) +{ + AT91PS_CAN base_can; + + if (pTransfer->state != CAN_IDLE) { + return CAN_STATUS_LOCKED; + } + + TRACE_DEBUG("CAN_Read\n\r"); + pTransfer->state = CAN_RECEIVING; + + + if( pTransfer->can_number == 0 ) { + base_can = AT91C_BASE_CAN0; + } +#ifdef AT91C_BASE_CAN1 + else { + base_can = AT91C_BASE_CAN1; + } +#endif + // enable interrupt + base_can->CAN_IER = pTransfer->mailbox_in_use; + + return CAN_STATUS_SUCCESS; +} + +//------------------------------------------------------------------------------ +/// Test if CAN is in IDLE state +/// \param pTransfer can transfer structure +/// \return return 0 if CAN is in IDLE, otherwise return 1 +//------------------------------------------------------------------------------ +unsigned char CAN_IsInIdle( CanTransfer *pTransfer ) +{ + return( pTransfer->state != CAN_IDLE ); +} + +//------------------------------------------------------------------------------ +/// Basic CAN test without Interrupt +//------------------------------------------------------------------------------ +void CAN_BasicTestSuiteWithoutInterrupt(void) +{ +#if defined AT91C_BASE_CAN1 + unsigned int status; + unsigned int tick=0; + + TRACE_INFO("Without Interrupt "); + TRACE_INFO("CAN0 Mailbox 0 transmitting to CAN1 Mailbox 0\n\r"); + // Init CAN0 Mailbox 0, transmit + CAN_ResetTransfer( pCAN0Transfer ); + pCAN0Transfer->can_number = 0; + pCAN0Transfer->mailbox_number = 0; + pCAN0Transfer->mode_reg = AT91C_CAN_MOT_TX | AT91C_CAN_PRIOR; + pCAN0Transfer->acceptance_mask_reg = 0x00000000; + pCAN0Transfer->identifier = AT91C_CAN_MIDvA & (0x07<<18); + pCAN0Transfer->data_low_reg = 0x11223344; + pCAN0Transfer->data_high_reg = 0x01234567; + pCAN0Transfer->control_reg = (AT91C_CAN_MDLC & (0x8<<16)); + CAN_InitMailboxRegisters( pCAN0Transfer ); + + // Init CAN1 Mailbox 0, receive, + CAN_ResetTransfer( pCAN1Transfer ); + pCAN1Transfer->can_number = 1; + pCAN1Transfer->mailbox_number = 0; + pCAN1Transfer->mode_reg = AT91C_CAN_MOT_RX; + pCAN1Transfer->acceptance_mask_reg = AT91C_CAN_MIDvA | AT91C_CAN_MIDvB; + pCAN1Transfer->identifier = AT91C_CAN_MIDvA & (0x07<<18); + pCAN1Transfer->data_low_reg = 0x00000000; + pCAN1Transfer->data_high_reg = 0x00000000; + pCAN1Transfer->control_reg = 0x00000000; + CAN_InitMailboxRegisters( pCAN1Transfer ); + + // Transfer Request for Mailbox 0 + AT91C_BASE_CAN0->CAN_TCR = AT91C_CAN_MB0; + + tick = 0; + do { + // CAN Message Status Register + status = AT91C_BASE_CAN0_MB0->CAN_MB_MSR; + } + while( !(status & AT91C_CAN_MRDY) && (++tick < AT91C_CAN_TIMEOUT) ); + + if (tick == AT91C_CAN_TIMEOUT) { + TRACE_ERROR("Test FAILED\n\r"); + } + else { + TRACE_DEBUG("Transfer completed: CAN1 Mailbox 0 MRDY flag has raised\n\r"); + if( AT91C_BASE_CAN0_MB0->CAN_MB_MDL != AT91C_BASE_CAN1_MB0->CAN_MB_MDL ) { + TRACE_ERROR("Data Corrupted\n\r"); + } + else if( AT91C_BASE_CAN0_MB0->CAN_MB_MDH != AT91C_BASE_CAN1_MB0->CAN_MB_MDH ) { + TRACE_ERROR("Data Corrupted\n\r"); + } + else { + TRACE_INFO("Test passed\n\r"); + } + } + + CAN_ResetAllMailbox(); + + TRACE_INFO("Without Interrupt "); + TRACE_INFO("CAN0 Mailboxes 1 & 2 transmitting to CAN1 Mailbox 15\n\r"); + // Init CAN0 Mailbox 1, transmit + CAN_ResetTransfer( pCAN0Transfer ); + pCAN0Transfer->can_number = 0; + pCAN0Transfer->mailbox_number = 1; + pCAN0Transfer->mode_reg = AT91C_CAN_MOT_TX | AT91C_CAN_PRIOR; + pCAN0Transfer->acceptance_mask_reg = 0x00000000; + pCAN0Transfer->identifier = AT91C_CAN_MIDvA & (0x09<<18); // ID 9 + pCAN0Transfer->data_low_reg = 0xAABBCCDD; + pCAN0Transfer->data_high_reg = 0xCAFEDECA; + pCAN0Transfer->control_reg = (AT91C_CAN_MDLC & (0x8<<16)); // Mailbox Data Length Code + CAN_InitMailboxRegisters( pCAN0Transfer ); + + // Init CAN0 Mailbox 2, transmit + pCAN0Transfer->can_number = 0; + pCAN0Transfer->mailbox_number = 2; + pCAN0Transfer->mode_reg = AT91C_CAN_MOT_TX | (AT91C_CAN_PRIOR-(1<<16)); + pCAN0Transfer->acceptance_mask_reg = 0x00000000; + pCAN0Transfer->identifier = AT91C_CAN_MIDvA & (0x0A<<18); // ID 10 + pCAN0Transfer->data_low_reg = 0x55667788; + pCAN0Transfer->data_high_reg = 0x99AABBCC; + pCAN0Transfer->control_reg = (AT91C_CAN_MDLC & (0x8<<16)); // Mailbox Data Length Code + CAN_InitMailboxRegisters( pCAN0Transfer ); + + // Init CAN1 Mailbox 15, reception with overwrite + CAN_ResetTransfer( pCAN1Transfer ); + pCAN1Transfer->can_number = 1; + pCAN1Transfer->mailbox_number = 15; + pCAN1Transfer->mode_reg = AT91C_CAN_MOT_RXOVERWRITE; + pCAN1Transfer->acceptance_mask_reg = 0; + pCAN1Transfer->identifier = 0x0; + pCAN1Transfer->data_low_reg = 0x00000000; + pCAN1Transfer->data_high_reg = 0x00000000; + pCAN1Transfer->control_reg = 0x00000000; + CAN_InitMailboxRegisters( pCAN1Transfer ); + + // Ask Transmissions on Mailbox 1 & 2 --> AT91C_CAN_MRDY & AT91C_CAN_MMI raises for Mailbox 15 CAN_MB_SR + AT91C_BASE_CAN0->CAN_TCR = AT91C_CAN_MB1 | AT91C_CAN_MB2; + + // Wait for Last Transmit Mailbox + tick = 0; + do { + status = AT91C_BASE_CAN1_MB15->CAN_MB_MSR; + } + while( !(status & AT91C_CAN_MMI) && (++tick < AT91C_CAN_TIMEOUT) ); + + if (tick == AT91C_CAN_TIMEOUT) { + } + else { + TRACE_DEBUG("Transfer completed: CAN1 Mailbox 15 MRDY and MMI flags have raised\n\r"); + if( AT91C_BASE_CAN0_MB1->CAN_MB_MDL != AT91C_BASE_CAN1_MB15->CAN_MB_MDL ) { + TRACE_ERROR("Data Corrupted\n\r"); + } + else if( AT91C_BASE_CAN0_MB1->CAN_MB_MDH != AT91C_BASE_CAN1_MB15->CAN_MB_MDH ) { + TRACE_ERROR("Data Corrupted\n\r"); + } + else { + TRACE_INFO("Test passed\n\r"); + } + } + + CAN_ResetAllMailbox(); + TRACE_INFO("Without Interrupt "); + TRACE_INFO("CAN0 Mailboxes 1 & 2 transmitting to CAN1 Mailbox 15\n\r"); + // Init CAN0 Mailbox 1, transmit + CAN_ResetTransfer( pCAN0Transfer ); + pCAN0Transfer->can_number = 0; + pCAN0Transfer->mailbox_number = 1; + pCAN0Transfer->mode_reg = AT91C_CAN_MOT_TX | AT91C_CAN_PRIOR; + pCAN0Transfer->acceptance_mask_reg = 0x00000000; + pCAN0Transfer->identifier = AT91C_CAN_MIDvA & (0x09<<18); // ID 9 + pCAN0Transfer->data_low_reg = 0xAABBCCDD; + pCAN0Transfer->data_high_reg = 0xCAFEDECA; + pCAN0Transfer->control_reg = (AT91C_CAN_MDLC & (0x8<<16)); // Mailbox Data Length Code + CAN_InitMailboxRegisters( pCAN0Transfer ); + + // Init CAN0 Mailbox 2, transmit + pCAN0Transfer->can_number = 0; + pCAN0Transfer->mailbox_number = 2; + pCAN0Transfer->mode_reg = AT91C_CAN_MOT_TX | (AT91C_CAN_PRIOR-(1<<16)); + pCAN0Transfer->acceptance_mask_reg = 0x00000000; + pCAN0Transfer->identifier = AT91C_CAN_MIDvA & (0x0A<<18); // ID 10 + pCAN0Transfer->data_low_reg = 0x55667788; + pCAN0Transfer->data_high_reg = 0x99AABBCC; + pCAN0Transfer->control_reg = (AT91C_CAN_MDLC & (0x8<<16)); // Mailbox Data Length Code + CAN_InitMailboxRegisters( pCAN0Transfer ); + + // Init CAN1 Mailbox 15, reception with overwrite + CAN_ResetTransfer( pCAN1Transfer ); + pCAN1Transfer->can_number = 1; + pCAN1Transfer->mailbox_number = 15; + pCAN1Transfer->mode_reg = AT91C_CAN_MOT_RX; + pCAN1Transfer->acceptance_mask_reg = 0; + pCAN1Transfer->identifier = 0x0; + pCAN1Transfer->data_low_reg = 0x00000000; + pCAN1Transfer->data_high_reg = 0x00000000; + pCAN1Transfer->control_reg = 0x00000000; + CAN_InitMailboxRegisters( pCAN1Transfer ); + + // Ask Transmissions on Mailbox 1 & 2 --> AT91C_CAN_MRDY & AT91C_CAN_MMI raises for Mailbox 15 CAN_MB_SR + AT91C_BASE_CAN0->CAN_TCR = AT91C_CAN_MB1 | AT91C_CAN_MB2; + + // Wait for Last Transmit Mailbox + tick = 0; + do { + status = AT91C_BASE_CAN1_MB15->CAN_MB_MSR; + } + while( !(status & AT91C_CAN_MMI) && (++tick < AT91C_CAN_TIMEOUT) ); + + if (tick == AT91C_CAN_TIMEOUT) { + TRACE_ERROR("Test FAILED\n\r"); + } + else { + TRACE_DEBUG("Transfer completed: CAN1 Mailbox 15 MRDY and MMI flags have raised\n\r"); + TRACE_DEBUG("MB_MDL: 0x%X\n\r", AT91C_BASE_CAN1_MB15->CAN_MB_MDL); + TRACE_DEBUG("MB_MDLH: 0x%X\n\r", AT91C_BASE_CAN1_MB15->CAN_MB_MDH); + if( AT91C_BASE_CAN0_MB2->CAN_MB_MDL != AT91C_BASE_CAN1_MB15->CAN_MB_MDL ) { + TRACE_ERROR("Data Corrupted\n\r"); + } + else if( AT91C_BASE_CAN0_MB2->CAN_MB_MDH != AT91C_BASE_CAN1_MB15->CAN_MB_MDH ) { + TRACE_ERROR("Data Corrupted\n\r"); + } + else { + TRACE_INFO("Test passed\n\r"); + } + } + + CAN_ResetAllMailbox(); + TRACE_INFO("Without Interrupt "); + TRACE_INFO("CAN0 Mailbox 3 asking for CAN1 Mailbox 3 transmission\n\r"); + // Init CAN0 Mailbox 3, consumer mailbox + // Sends a remote frame and waits for an answer + CAN_ResetTransfer( pCAN0Transfer ); + pCAN0Transfer->can_number = 0; + pCAN0Transfer->mailbox_number = 3; + pCAN0Transfer->mode_reg = AT91C_CAN_MOT_CONSUMER | AT91C_CAN_PRIOR; + pCAN0Transfer->acceptance_mask_reg = AT91C_CAN_MIDvA | AT91C_CAN_MIDvB; + pCAN0Transfer->identifier = AT91C_CAN_MIDvA & (0x0B<<18); // ID 11 + pCAN0Transfer->data_low_reg = 0x00000000; + pCAN0Transfer->data_high_reg = 0x00000000; + pCAN0Transfer->control_reg = 0x00000000; + CAN_InitMailboxRegisters( pCAN0Transfer ); + + // Init CAN1 Mailbox 3, porducer mailbox + // Waits to receive a Remote Frame before sending its contents + CAN_ResetTransfer( pCAN1Transfer ); + pCAN1Transfer->can_number = 1; + pCAN1Transfer->mailbox_number = 3; + pCAN1Transfer->mode_reg = AT91C_CAN_MOT_PRODUCER | AT91C_CAN_PRIOR; + pCAN1Transfer->acceptance_mask_reg = 0; + pCAN1Transfer->identifier = AT91C_CAN_MIDvA & (0x0B<<18); // ID 11 + pCAN1Transfer->data_low_reg = 0xEEDDFF00; + pCAN1Transfer->data_high_reg = 0x34560022; + pCAN1Transfer->control_reg = (AT91C_CAN_MDLC & (0x8<<16)); + CAN_InitMailboxRegisters( pCAN1Transfer ); + + // Ask Transmissions on Mailbox 3 --> AT91C_CAN_MRDY raises for Mailbox 3 CAN_MB_SR + AT91C_BASE_CAN1->CAN_TCR = AT91C_CAN_MB3; + AT91C_BASE_CAN0->CAN_TCR = AT91C_CAN_MB3; + + // Wait for Last Transmit Mailbox + tick = 0; + do { + status = AT91C_BASE_CAN0_MB3->CAN_MB_MSR; + } + while( !(status & AT91C_CAN_MRDY) && (++tick < AT91C_CAN_TIMEOUT) ); + + if (tick == AT91C_CAN_TIMEOUT) { + TRACE_ERROR("Test FAILED\n\r"); + } + else { + TRACE_DEBUG("Transfer Completed: CAN0 & CAN1 Mailboxes 3 MRDY flags have raised\n\r"); + if( AT91C_BASE_CAN0_MB3->CAN_MB_MDL != AT91C_BASE_CAN1_MB3->CAN_MB_MDL ) { + TRACE_ERROR("Data Corrupted\n\r"); + } + else if( AT91C_BASE_CAN0_MB3->CAN_MB_MDH != AT91C_BASE_CAN1_MB3->CAN_MB_MDH ) { + TRACE_ERROR("Data Corrupted\n\r"); + } + else { + TRACE_INFO("Test passed\n\r"); + } + } +#endif // AT91C_BASE_CAN1 + + return; +} + + +//------------------------------------------------------------------------------ +/// Disable CAN and enter in low power +//------------------------------------------------------------------------------ +void CAN_disable( void ) +{ + // Disable the interrupt on the interrupt controller + AIC_DisableIT(AT91C_ID_CAN0); + // disable all IT + AT91C_BASE_CAN0->CAN_IDR = 0x1FFFFFFF; +#if defined AT91C_BASE_CAN1 + AIC_DisableIT(AT91C_ID_CAN1); + // disable all IT + AT91C_BASE_CAN1->CAN_IDR = 0x1FFFFFFF; +#endif + + // Enable Low Power mode + AT91C_BASE_CAN0->CAN_MR |= AT91C_CAN_LPM; + + // Disable CANs Transceivers + // Enter standby mode + PIO_Set(&pin_can_transceiver_rs); +#if defined (PIN_CAN_TRANSCEIVER_RXEN) + // Enable ultra Low Power mode + PIO_Clear(&pin_can_transceiver_rxen); +#endif + + // Disable clock for CAN PIO +#if defined(AT91C_ID_PIOA) + AT91C_BASE_PMC->PMC_PCDR = (1 << AT91C_ID_PIOA); +#elif defined(AT91C_ID_PIOABCD) + AT91C_BASE_PMC->PMC_PCDR = (1 << AT91C_ID_PIOABCD); +#elif defined(AT91C_ID_PIOABCDE) + AT91C_BASE_PMC->PMC_PCDR = (1 << AT91C_ID_PIOABCDE); +#endif + + // Disable the CAN0 controller peripheral clock + AT91C_BASE_PMC->PMC_PCDR = (1 << AT91C_ID_CAN0); + +} + +//------------------------------------------------------------------------------ +/// baudrate calcul +/// \param base_CAN CAN base address +/// \param baudrate Baudrate value (kB/s) +/// allowed values: 1000, 800, 500, 250, 125, 50, 25, 10 +/// \return return 1 in success, otherwise return 0 +//------------------------------------------------------------------------------ +unsigned char CAN_BaudRateCalculate( AT91PS_CAN base_CAN, + unsigned int baudrate ) +{ + unsigned int BRP; + unsigned int PROPAG; + unsigned int PHASE1; + unsigned int PHASE2; + unsigned int SJW; + unsigned int t1t2; + unsigned char TimeQuanta; + + base_CAN->CAN_BR = 0; + + if( baudrate == 1000) { + TimeQuanta = 8; + } + else { + TimeQuanta = 16; + } + + BRP = (BOARD_MCK / (baudrate*1000*TimeQuanta))-1; + //TRACE_DEBUG("BRP = 0x%X\n\r", BRP); + // timing Delay: + // Delay Bus Driver: 50 ns + // Delay Receiver: 30 ns + // Delay Bus Line (20m): 110 ns + if( (TimeQuanta*baudrate*2*(50+30+110)/1000000) >= 1) { + PROPAG = (TimeQuanta*baudrate*2*(50+30+110)/1000000)-1; + } + else { + PROPAG = 0; + } + //TRACE_DEBUG("PROPAG = 0x%X\n\r", PROPAG); + + t1t2 = TimeQuanta-1-(PROPAG+1); + //TRACE_DEBUG("t1t2 = 0x%X\n\r", t1t2); + + if( (t1t2 & 0x01) == 0x01 ) { + // ODD + //TRACE_DEBUG("ODD\n\r"); + PHASE1 = ((t1t2-1)/2)-1; + PHASE2 = PHASE1+1; + } + else { + // EVEN + //TRACE_DEBUG("EVEN\n\r"); + PHASE1 = (t1t2/2)-1; + PHASE2 = PHASE1; + } + //TRACE_DEBUG("PHASE1 = 0x%X\n\r", PHASE1); + //TRACE_DEBUG("PHASE2 = 0x%X\n\r", PHASE2); + + if( 1 > (4/(PHASE1+1)) ) { + //TRACE_DEBUG("4*Tcsc\n\r"); + SJW = 3; + } + else { + //TRACE_DEBUG("Tphs1\n\r"); + SJW = PHASE1; + } + //TRACE_DEBUG("SJW = 0x%X\n\r", SJW); + // Verif + if( BRP == 0 ) { + TRACE_DEBUG("BRP = 0 is not authorized\n\r"); + return 0; + } + + if( (PROPAG + PHASE1 + PHASE2) != (TimeQuanta-4) ) { + TRACE_DEBUG("Pb (PROPAG + PHASE1 + PHASE2) = %d\n\r", PROPAG + PHASE1 + PHASE2); + TRACE_DEBUG("with TimeQuanta-4 = %d\n\r", TimeQuanta-4); + return 0; + } + base_CAN->CAN_BR = (AT91C_CAN_PHASE2 & (PHASE2 << 0)) + + (AT91C_CAN_PHASE1 & (PHASE1 << 4)) + + (AT91C_CAN_PROPAG & (PROPAG << 8)) + + (AT91C_CAN_SYNC & (SJW << 12)) + + (AT91C_CAN_BRP & (BRP << 16)) + + (AT91C_CAN_SMP & (0 << 24)); + return 1; + +} + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +/// Init of the CAN peripheral +/// \param baudrate Baudrate value (kB/s) +/// allowed values: 1000, 800, 500, 250, 125, 50, 25, 10 +/// \param canTransfer0 CAN0 structure transfer +/// \param canTransfer1 CAN1 structure transfer +/// \return return 1 if CAN has good baudrate and CAN is synchronized, +/// otherwise return 0 +//------------------------------------------------------------------------------ +unsigned char CAN_Init( unsigned int baudrate, + CanTransfer *canTransfer0, + CanTransfer *canTransfer1 ) +{ + unsigned char ret; + + // CAN Transmit Serial Data +#if defined (PINS_CAN_TRANSCEIVER_TXD) + PIO_Configure(pins_can_transceiver_txd, PIO_LISTSIZE(pins_can_transceiver_txd)); +#endif +#if defined (PINS_CAN_TRANSCEIVER_RXD) + // CAN Receive Serial Data + PIO_Configure(pins_can_transceiver_rxd, PIO_LISTSIZE(pins_can_transceiver_rxd)); +#endif + // CAN RS + PIO_Configure(&pin_can_transceiver_rs, PIO_LISTSIZE(pin_can_transceiver_rs)); +#if defined (PIN_CAN_TRANSCEIVER_RXEN) + // CAN RXEN + PIO_Configure(&pin_can_transceiver_rxen, PIO_LISTSIZE(pin_can_transceiver_rxen)); +#endif + + // Enable clock for CAN PIO +#if defined(AT91C_ID_PIOA) + AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOA); +#elif defined(AT91C_ID_PIOABCD) + AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOABCD); +#elif defined(AT91C_ID_PIOABCDE) + AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOABCDE); +#endif + + // Enable the CAN0 controller peripheral clock + AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_CAN0); + + // disable all IT + AT91C_BASE_CAN0->CAN_IDR = 0x1FFFFFFF; + + // Enable CANs Transceivers +#if defined (PIN_CAN_TRANSCEIVER_RXEN) + // Disable ultra Low Power mode + PIO_Set(&pin_can_transceiver_rxen); +#endif + // Normal Mode (versus Standby mode) + PIO_Clear(&pin_can_transceiver_rs); + + // Configure the AIC for CAN interrupts + AIC_ConfigureIT(AT91C_ID_CAN0, AT91C_AIC_PRIOR_HIGHEST, CAN0_Handler); + + // Enable the interrupt on the interrupt controller + AIC_EnableIT(AT91C_ID_CAN0); + + if( CAN_BaudRateCalculate(AT91C_BASE_CAN0, baudrate) == 0 ) { + // Baudrate problem + TRACE_DEBUG("Baudrate CAN0 problem\n\r"); + return 0; + } + + pCAN0Transfer = canTransfer0; + +#if defined AT91C_BASE_CAN1 + if( canTransfer1 != NULL ) { + pCAN1Transfer = canTransfer1; + // Enable CAN1 Clocks + AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_CAN1); + + // disable all IT + AT91C_BASE_CAN1->CAN_IDR = 0x1FFFFFFF; + + // Configure the AIC for CAN interrupts + AIC_ConfigureIT(AT91C_ID_CAN1, AT91C_AIC_PRIOR_HIGHEST, CAN1_Handler); + + // Enable the interrupt on the interrupt controller + AIC_EnableIT(AT91C_ID_CAN1); + + if( CAN_BaudRateCalculate(AT91C_BASE_CAN1, baudrate) == 0 ) { + // Baudrate problem + TRACE_DEBUG("Baudrate CAN1 problem\n\r"); + return 0; + } + } +#endif + // Reset all mailbox + CAN_ResetAllMailbox(); + + // Enable the interrupt with all error cases + AT91C_BASE_CAN0->CAN_IER = AT91C_CAN_CERR // (CAN) CRC Error + | AT91C_CAN_SERR // (CAN) Stuffing Error + | AT91C_CAN_BERR // (CAN) Bit Error + | AT91C_CAN_FERR // (CAN) Form Error + | AT91C_CAN_AERR; // (CAN) Acknowledgment Error + +#if defined AT91C_BASE_CAN1 + if( canTransfer1 != NULL ) { + AT91C_BASE_CAN1->CAN_IER = AT91C_CAN_CERR // (CAN) CRC Error + | AT91C_CAN_SERR // (CAN) Stuffing Error + | AT91C_CAN_BERR // (CAN) Bit Error + | AT91C_CAN_FERR // (CAN) Form Error + | AT91C_CAN_AERR; // (CAN) Acknowledgment Error + } +#endif + + // Wait for CAN synchronisation + if( CAN_Synchronisation( ) == 1 ) { + ret = 1; + } + else { + ret = 0; + } + + return ret; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/can/can.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/can/can.h new file mode 100644 index 000000000..63a83b3c4 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/can/can.h @@ -0,0 +1,113 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef _CAN_H +#define _CAN_H + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ +#define AT91C_CAN_TIMEOUT 100000 + +#define AT91C_TEST_NOK 0 +#define AT91C_TEST_OK 1 + +#define CAN_STATUS_SUCCESS 0 +#define CAN_STATUS_LOCKED 1 +#define CAN_STATUS_ABORTED 2 +#define CAN_STATUS_RESET 3 + +#if defined (AT91C_BASE_CAN) + #define AT91C_BASE_CAN0 AT91C_BASE_CAN +#endif +#if defined (AT91C_ID_CAN) + #define AT91C_ID_CAN0 AT91C_ID_CAN +#endif +#if defined (AT91C_BASE_CAN_MB0) + #define AT91C_BASE_CAN0_MB0 AT91C_BASE_CAN_MB0 + #define AT91C_BASE_CAN0_MB1 AT91C_BASE_CAN_MB1 + #define AT91C_BASE_CAN0_MB2 AT91C_BASE_CAN_MB2 + #define AT91C_BASE_CAN0_MB3 AT91C_BASE_CAN_MB3 + #define AT91C_BASE_CAN0_MB4 AT91C_BASE_CAN_MB4 + #define AT91C_BASE_CAN0_MB5 AT91C_BASE_CAN_MB5 + #define AT91C_BASE_CAN0_MB6 AT91C_BASE_CAN_MB6 + #define AT91C_BASE_CAN0_MB7 AT91C_BASE_CAN_MB7 +#endif +#if defined (AT91C_BASE_CAN_MB8) + #define AT91C_BASE_CAN0_MB8 AT91C_BASE_CAN_MB8 + #define AT91C_BASE_CAN0_MB9 AT91C_BASE_CAN_MB9 + #define AT91C_BASE_CAN0_MB10 AT91C_BASE_CAN_MB10 + #define AT91C_BASE_CAN0_MB11 AT91C_BASE_CAN_MB11 + #define AT91C_BASE_CAN0_MB12 AT91C_BASE_CAN_MB12 + #define AT91C_BASE_CAN0_MB13 AT91C_BASE_CAN_MB13 + #define AT91C_BASE_CAN0_MB14 AT91C_BASE_CAN_MB14 + #define AT91C_BASE_CAN0_MB15 AT91C_BASE_CAN_MB15 +#endif + +#define NUM_MAILBOX_MAX 16 + +//------------------------------------------------------------------------------ +// Types +//------------------------------------------------------------------------------ +typedef struct +{ + volatile unsigned char state; + volatile unsigned char can_number; + volatile unsigned char mailbox_number; + volatile unsigned char test_can; + volatile unsigned int mode_reg; + volatile unsigned int acceptance_mask_reg; + volatile unsigned int identifier; + volatile unsigned int data_low_reg; + volatile unsigned int data_high_reg; + volatile unsigned int control_reg; + volatile unsigned int mailbox_in_use; + volatile int size; +} CanTransfer; + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +extern unsigned char CAN_Init( unsigned int baudrate, + CanTransfer *canTransferRead, + CanTransfer *canTransferWrite ); +extern void CAN_BasicTestSuite(void); +extern void CAN_disable( void ); +extern void CAN_ResetAllMailbox( void ); +extern void CAN_ResetTransfer( CanTransfer *pTransfer ); +extern void CAN_InitMailboxRegisters( CanTransfer *pTransfer ); +extern unsigned char CAN_IsInIdle( CanTransfer *pTransfer ); + +extern unsigned char CAN_Write( CanTransfer *pTransfer ); +extern unsigned char CAN_Read( CanTransfer *pTransfer ); + +extern void CAN_BasicTestSuiteWithoutInterrupt( void ); +extern unsigned char CAN_IsInIdle( CanTransfer *pTransfer ); +#endif // _CAN_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/cp15/cp15.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/cp15/cp15.c new file mode 100644 index 000000000..17a1f7058 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/cp15/cp15.c @@ -0,0 +1,268 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- + +#include + +#ifdef CP15_PRESENT + +#include +#include "cp15.h" + +#if defined(__ICCARM__) +#include +#endif + + +//----------------------------------------------------------------------------- +// Macros +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Defines +//----------------------------------------------------------------------------- +/* +#define CP15_RR_BIT 14 // RR bit Replacement strategy for ICache and DCache: + // 0 = Random replacement + // 1 = Round-robin replacement. + +#define CP15_V_BIT 13 // V bit Location of exception vectors: + // 0 = Normal exception vectors selected address range = 0x0000 0000 to 0x0000 001C + // 1 = High exception vect selected, address range = 0xFFFF 0000 to 0xFFFF 001C +*/ +#define CP15_I_BIT 12 // I bit ICache enable/disable: + // 0 = ICache disabled + // 1 = ICache enabled +/* +#define CP15_R_BIT 9 // R bit ROM protection + +#define CP15_S_BIT 8 // S bit System protection + +#define CP15_B_BIT 7 // B bit Endianness: + // 0 = Little-endian operation + // 1 = Big-endian operation. +*/ +#define CP15_C_BIT 2 // C bit DCache enable/disable: + // 0 = Cache disabled + // 1 = Cache enabled +/* +#define CP15_A_BIT 1 // A bit Alignment fault enable/disable: + // 0 = Data address alignment fault checking disabled + // 1 = Data address alignment fault checking enabled +*/ +#define CP15_M_BIT 0 // M bit MMU enable/disable: 0 = disabled 1 = enabled. + // 0 = disabled + // 1 = enabled + + +//----------------------------------------------------------------------------- +// Global functions +//----------------------------------------------------------------------------- + +//------------------------------------------------------------------------------ +/// Check Instruction Cache +/// \return 0 if I_Cache disable, 1 if I_Cache enable +//------------------------------------------------------------------------------ +unsigned int CP15_Is_I_CacheEnabled(void) +{ + unsigned int control; + + control = _readControlRegister(); + return ((control & (1 << CP15_I_BIT)) != 0); +} + +//------------------------------------------------------------------------------ +/// Enable Instruction Cache +//------------------------------------------------------------------------------ +void CP15_Enable_I_Cache(void) +{ + unsigned int control; + + control = _readControlRegister(); + + // Check if cache is disabled + if ((control & (1 << CP15_I_BIT)) == 0) { + + control |= (1 << CP15_I_BIT); + _writeControlRegister(control); + TRACE_INFO("I cache enabled.\n\r"); + } +#if !defined(OP_BOOTSTRAP_on) + else { + + TRACE_INFO("I cache is already enabled.\n\r"); + } +#endif +} + +//------------------------------------------------------------------------------ +/// Disable Instruction Cache +//------------------------------------------------------------------------------ +void CP15_Disable_I_Cache(void) +{ + unsigned int control; + + control = _readControlRegister(); + + // Check if cache is enabled + if ((control & (1 << CP15_I_BIT)) != 0) { + + control &= ~(1 << CP15_I_BIT); + _writeControlRegister(control); + TRACE_INFO("I cache disabled.\n\r"); + } + else { + + TRACE_INFO("I cache is already disabled.\n\r"); + } +} + +//------------------------------------------------------------------------------ +/// Check MMU +/// \return 0 if MMU disable, 1 if MMU enable +//------------------------------------------------------------------------------ +unsigned int CP15_Is_MMUEnabled(void) +{ + unsigned int control; + + control = _readControlRegister(); + return ((control & (1 << CP15_M_BIT)) != 0); +} + +//------------------------------------------------------------------------------ +/// Enable MMU +//------------------------------------------------------------------------------ +void CP15_EnableMMU(void) +{ + unsigned int control; + + control = _readControlRegister(); + + // Check if MMU is disabled + if ((control & (1 << CP15_M_BIT)) == 0) { + + control |= (1 << CP15_M_BIT); + _writeControlRegister(control); + TRACE_INFO("MMU enabled.\n\r"); + } + else { + + TRACE_INFO("MMU is already enabled.\n\r"); + } +} + +//------------------------------------------------------------------------------ +/// Disable MMU +//------------------------------------------------------------------------------ +void CP15_DisableMMU(void) +{ + unsigned int control; + + control = _readControlRegister(); + + // Check if MMU is enabled + if ((control & (1 << CP15_M_BIT)) != 0) { + + control &= ~(1 << CP15_M_BIT); + control &= ~(1 << CP15_C_BIT); + _writeControlRegister(control); + TRACE_INFO("MMU disabled.\n\r"); + } + else { + + TRACE_INFO("MMU is already disabled.\n\r"); + } +} + +//------------------------------------------------------------------------------ +/// Check D_Cache +/// \return 0 if D_Cache disable, 1 if D_Cache enable (with MMU of course) +//------------------------------------------------------------------------------ +unsigned int CP15_Is_DCacheEnabled(void) +{ + unsigned int control; + + control = _readControlRegister(); + return ((control & ((1 << CP15_C_BIT)||(1 << CP15_M_BIT))) != 0); +} + +//------------------------------------------------------------------------------ +/// Enable Data Cache +//------------------------------------------------------------------------------ +void CP15_Enable_D_Cache(void) +{ + unsigned int control; + + control = _readControlRegister(); + + if( !CP15_Is_MMUEnabled() ) { + TRACE_ERROR("Do nothing: MMU not enabled\n\r"); + } + else { + // Check if cache is disabled + if ((control & (1 << CP15_C_BIT)) == 0) { + + control |= (1 << CP15_C_BIT); + _writeControlRegister(control); + TRACE_INFO("D cache enabled.\n\r"); + } + else { + + TRACE_INFO("D cache is already enabled.\n\r"); + } + } +} + +//------------------------------------------------------------------------------ +/// Disable Data Cache +//------------------------------------------------------------------------------ +void CP15_Disable_D_Cache(void) +{ + unsigned int control; + + control = _readControlRegister(); + + // Check if cache is enabled + if ((control & (1 << CP15_C_BIT)) != 0) { + + control &= ~(1 << CP15_C_BIT); + _writeControlRegister(control); + TRACE_INFO("D cache disabled.\n\r"); + } + else { + + TRACE_INFO("D cache is already disabled.\n\r"); + } +} + +#endif // CP15_PRESENT + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/cp15/cp15.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/cp15/cp15.h new file mode 100644 index 000000000..ddaaeb6b8 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/cp15/cp15.h @@ -0,0 +1,84 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Methods to manage the Coprocessor 15. Coprocessor 15, or System Control +/// Coprocessor CP15, is used to configure and control all the items in the +/// list below: +/// • ARM core +/// • Caches (ICache, DCache and write buffer) +/// • TCM +/// • MMU +/// • Other system options +/// +/// !Usage +/// +/// -# Enable or disable D cache with Enable_D_Cache and Disable_D_Cache +/// -# Enable or disable I cache with Enable_I_Cache and Disable_I_Cache +/// +//------------------------------------------------------------------------------ + +#ifndef _CP15_H +#define _CP15_H + +#ifdef CP15_PRESENT + +//----------------------------------------------------------------------------- +// Exported functions +//----------------------------------------------------------------------------- +extern void CP15_Enable_I_Cache(void); +extern unsigned int CP15_Is_I_CacheEnabled(void); +extern void CP15_Enable_I_Cache(void); +extern void CP15_Disable_I_Cache(void); +extern unsigned int CP15_Is_MMUEnabled(void); +extern void CP15_EnableMMU(void); +extern void CP15_DisableMMU(void); +extern unsigned int CP15_Is_DCacheEnabled(void); +extern void CP15_Enable_D_Cache(void); +extern void CP15_Disable_D_Cache(void); + +//----------------------------------------------------------------------------- +// External functions defined in cp15.S +//----------------------------------------------------------------------------- +extern unsigned int _readControlRegister(void); +extern void _writeControlRegister(unsigned int value); +extern void _waitForInterrupt(void); +extern void _writeTTB(unsigned int value); +extern void _writeDomain(unsigned int value); +extern void _writeITLBLockdown(unsigned int value); +extern void _prefetchICacheLine(unsigned int value); + +#endif // CP15_PRESENT + +#endif // #ifndef _CP15_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/cp15/cp15_asm_iar.s b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/cp15/cp15_asm_iar.s new file mode 100644 index 000000000..0c76139f0 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/cp15/cp15_asm_iar.s @@ -0,0 +1,145 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + + MODULE ?cp15 + + ;; Forward declaration of sections. + SECTION IRQ_STACK:DATA:NOROOT(2) + SECTION CSTACK:DATA:NOROOT(3) + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#define __ASSEMBLY__ +#include "board.h" + +#ifdef CP15_PRESENT + +//------------------------------------------------------------------------------ +/// Functions to access CP15 coprocessor register +//------------------------------------------------------------------------------ + + PUBLIC _readControlRegister + PUBLIC _writeControlRegister + PUBLIC _waitForInterrupt + PUBLIC _writeTTB + PUBLIC _writeDomain + PUBLIC _writeITLBLockdown + PUBLIC _prefetchICacheLine + +//------------------------------------------------------------------------------ +/// Control Register c1 +/// Register c1 is the Control Register for the ARM926EJ-S processor. +/// This register specifies the configuration used to enable and disable the +/// caches and MMU. It is recommended that you access this register using a +/// read-modify-write sequence. +//------------------------------------------------------------------------------ +// CP15 Read Control Register +_readControlRegister: + mov r0, #0 + mrc p15, 0, r0, c1, c0, 0 + bx lr + +// CP15 Write Control Register +_writeControlRegister: + mcr p15, 0, r0, c1, c0, 0 + bx lr + +//------------------------------------------------------------------------------ +/// CP15 Wait For Interrupt operation +/// The purpose of the Wait For Interrupt operation is to put the processor in +/// to a low power state. +/// This puts the processor into a low-power state and stops it executing more +/// instructions until an interrupt, or debug request occurs, regardless of +/// whether the interrupts are disabled by the masks in the CPSR. +/// When an interrupt does occur, the MCR instruction completes and the IRQ or +/// FIQ handler is entered as normal. The return link in r14_irq or r14_fiq +/// contains the address of the MCR instruction plus 8, so that the normal +/// instruction used for interrupt return (SUBS PC,R14,#4) returns to the +/// instruction following the MCR. +/// Wait For Interrupt : MCR p15, 0, , c7, c0, 4 +//------------------------------------------------------------------------------ +_waitForInterrupt: + mov r0, #0 + mcr p15, 0, r0, c7, c0, 4 + bx lr + +//------------------------------------------------------------------------------ +/// CP15 Translation Table Base Register c2 +/// Register c2 is the Translation Table Base Register (TTBR), for the base +/// address of the first-level translation table. +/// Reading from c2 returns the pointer to the currently active first-level +/// translation table in bits [31:14] and an Unpredictable value in bits [13:0]. +/// Writing to register c2 updates the pointer to the first-level translation +/// table from the value in bits [31:14] of the written value. Bits [13:0] +/// Should Be Zero. +/// You can use the following instructions to access the TTBR: +/// Read TTBR : MRC p15, 0, , c2, c0, 0 +/// Write TTBR : MCR p15, 0, , c2, c0, 0 +//------------------------------------------------------------------------------ +_writeTTB: + MCR p15, 0, r0, c2, c0, 0 + bx lr + +//------------------------------------------------------------------------------ +/// Domain Access Control Register c3 +/// Read domain access permissions : MRC p15, 0, , c3, c0, 0 +/// Write domain access permissions : MCR p15, 0, , c3, c0, 0 +//------------------------------------------------------------------------------ +_writeDomain: + MCR p15, 0, r0, c3, c0, 0 + bx lr + +//------------------------------------------------------------------------------ +/// TLB Lockdown Register c10 +/// The TLB Lockdown Register controls where hardware page table walks place the +/// TLB entry, in the set associative region or the lockdown region of the TLB, +/// and if in the lockdown region, which entry is written. The lockdown region +/// of the TLB contains eight entries. See TLB structure for a description of +/// the structure of the TLB. +/// Read data TLB lockdown victim : MRC p15,0,,c10,c0,0 +/// Write data TLB lockdown victim : MCR p15,0,,c10,c0,0 +//------------------------------------------------------------------------------ +_writeITLBLockdown: + MCR p15, 0, r0, c10, c0, 0 + bx lr + +//------------------------------------------------------------------------------ +/// Prefetch ICache line +/// Performs an ICache lookup of the specified modified virtual address. +/// If the cache misses, and the region is cacheable, a linefill is performed. +/// Prefetch ICache line (MVA): MCR p15, 0, , c7, c13, 1 +//------------------------------------------------------------------------------ +_prefetchICacheLine: + MCR p15, 0, r0, c7, c13, 1 + bx lr +#endif + END + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/dbgu/dbgu.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/dbgu/dbgu.c new file mode 100644 index 000000000..20347304b --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/dbgu/dbgu.c @@ -0,0 +1,174 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "dbgu.h" +#include +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +/// Initializes the DBGU with the given parameters, and enables both the +/// transmitter and the receiver. The mode parameter contains the value of the +/// DBGU_MR register. +/// Value DBGU_STANDARD can be used for mode to get the most common configuration +/// (i.e. aysnchronous, 8bits, no parity, 1 stop bit, no flow control). +/// \param mode Operating mode to configure. +/// \param baudrate Desired baudrate (e.g. 115200). +/// \param mck Frequency of the system master clock in Hz. +//------------------------------------------------------------------------------ +void DBGU_Configure( + unsigned int mode, + unsigned int baudrate, + unsigned int mck) +{ + // Reset & disable receiver and transmitter, disable interrupts + AT91C_BASE_DBGU->DBGU_CR = AT91C_US_RSTRX | AT91C_US_RSTTX; + AT91C_BASE_DBGU->DBGU_IDR = 0xFFFFFFFF; + + // Configure baud rate + AT91C_BASE_DBGU->DBGU_BRGR = mck / (baudrate * 16); + + // Configure mode register + AT91C_BASE_DBGU->DBGU_MR = mode; + + // Disable DMA channel + AT91C_BASE_DBGU->DBGU_PTCR = AT91C_PDC_RXTDIS | AT91C_PDC_TXTDIS; + + // Enable receiver and transmitter + AT91C_BASE_DBGU->DBGU_CR = AT91C_US_RXEN | AT91C_US_TXEN; +} + +//------------------------------------------------------------------------------ +/// Outputs a character on the DBGU line. +/// \note This function is synchronous (i.e. uses polling). +/// \param c Character to send. +//------------------------------------------------------------------------------ +void DBGU_PutChar(unsigned char c) +{ + // Wait for the transmitter to be ready + while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXEMPTY) == 0); + + // Send character + AT91C_BASE_DBGU->DBGU_THR = c; + + // Wait for the transfer to complete + while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXEMPTY) == 0); +} + +//------------------------------------------------------------------------------ +/// Return 1 if a character can be read in DBGU +//------------------------------------------------------------------------------ +unsigned int DBGU_IsRxReady() +{ + return (AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_RXRDY); +} + +//------------------------------------------------------------------------------ +/// Reads and returns a character from the DBGU. +/// \note This function is synchronous (i.e. uses polling). +/// \return Character received. +//------------------------------------------------------------------------------ +unsigned char DBGU_GetChar(void) +{ + while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_RXRDY) == 0); + return AT91C_BASE_DBGU->DBGU_RHR; +} + +#ifndef NOFPUT +#include + +//------------------------------------------------------------------------------ +/// \exclude +/// Implementation of fputc using the DBGU as the standard output. Required +/// for printf(). +/// \param c Character to write. +/// \param pStream Output stream. +/// \param The character written if successful, or -1 if the output stream is +/// not stdout or stderr. +//------------------------------------------------------------------------------ +signed int fputc(signed int c, FILE *pStream) +{ + if ((pStream == stdout) || (pStream == stderr)) { + + DBGU_PutChar(c); + return c; + } + else { + + return EOF; + } +} + +//------------------------------------------------------------------------------ +/// \exclude +/// Implementation of fputs using the DBGU as the standard output. Required +/// for printf(). Does NOT currently use the PDC. +/// \param pStr String to write. +/// \param pStream Output stream. +/// \return Number of characters written if successful, or -1 if the output +/// stream is not stdout or stderr. +//------------------------------------------------------------------------------ +signed int fputs(const char *pStr, FILE *pStream) +{ + signed int num = 0; + + while (*pStr != 0) { + + if (fputc(*pStr, pStream) == -1) { + + return -1; + } + num++; + pStr++; + } + + return num; +} + +#undef putchar + +//------------------------------------------------------------------------------ +/// \exclude +/// Outputs a character on the DBGU. +/// \param c Character to output. +/// \return The character that was output. +//------------------------------------------------------------------------------ +signed int putchar(signed int c) +{ + return fputc(c, stdout); +} + +#endif //#ifndef NOFPUT + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/dbgu/dbgu.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/dbgu/dbgu.h new file mode 100644 index 000000000..816f11dcf --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/dbgu/dbgu.h @@ -0,0 +1,79 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// This module provides definitions and functions for using the Debug Unit +/// (DBGU). +/// +/// It also overloads the fputc(), fputs() & putchar() functions so the printf() +/// method outputs its data on the DBGU. This behavior can be suppressed by +/// defining NOFPUT during compilation. +/// +/// !Usage +/// +/// -# Enable the DBGU pins (see pio & board.h). +/// -# Configure the DBGU using DBGU_Configure with the desired operating mode. +/// -# Send characters using DBGU_PutChar() or the printf() method. +/// -# Receive characters using DBGU_GetChar(). +/// +/// \note Unless specified, all the functions defined here operate synchronously; +/// i.e. they all wait the data is sent/received before returning. +//------------------------------------------------------------------------------ + +#ifndef DBGU_H +#define DBGU_H + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +/// Standard operating mode (asynchronous, 8bit, no parity, 1 stop bit) +#define DBGU_STANDARD AT91C_US_PAR_NONE + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void DBGU_Configure( + unsigned int mode, + unsigned int baudrate, + unsigned int mck); + +extern unsigned char DBGU_GetChar(void); + +extern void DBGU_PutChar(unsigned char c); + +extern unsigned int DBGU_IsRxReady(void); + +#endif //#ifndef DBGU_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/dma/dma.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/dma/dma.c new file mode 100644 index 000000000..e78a7c5cd --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/dma/dma.c @@ -0,0 +1,355 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "dma.h" +#include +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Configure a DMAC peripheral +//------------------------------------------------------------------------------ +void DMA_Config(unsigned int flag) +{ + AT91C_BASE_HDMA->HDMA_GCFG = flag; +} + +//------------------------------------------------------------------------------ +/// Enables a DMAC peripheral +//------------------------------------------------------------------------------ +void DMA_Enable(void) +{ + AT91C_BASE_HDMA->HDMA_EN = AT91C_HDMA_ENABLE; +} + +//------------------------------------------------------------------------------ +/// Disables DMAC peripheral +//------------------------------------------------------------------------------ +void DMA_Disable(void) +{ + AT91C_BASE_HDMA->HDMA_EN = ~(AT91C_HDMA_ENABLE); +} + +//----------------------------------------------------------------------------- +/// Enable DMA interrupt +/// \param flag IT to be enabled +//----------------------------------------------------------------------------- +void DMA_EnableIt (unsigned int flag) +{ + AT91C_BASE_HDMA->HDMA_EBCIER = flag; +} + +//----------------------------------------------------------------------------- +/// Disable DMA interrupt +/// \param flag IT to be enabled +//----------------------------------------------------------------------------- +void DMA_DisableIt (unsigned int flag) +{ + AT91C_BASE_HDMA->HDMA_EBCIDR = flag; +} + +//----------------------------------------------------------------------------- +/// Return DMA Interrupt Status +//----------------------------------------------------------------------------- +unsigned int DMA_GetStatus(void) +{ + return (AT91C_BASE_HDMA->HDMA_EBCISR); +} + +//----------------------------------------------------------------------------- +/// Return DMA Interrupt Mask Status +//----------------------------------------------------------------------------- +unsigned int DMA_GetInterruptMask(void) +{ + return (AT91C_BASE_HDMA->HDMA_EBCIMR); +} + +//----------------------------------------------------------------------------- +/// Returns the current status register of the given DMA peripheral, but +/// masking interrupt sources which are not currently enabled. +//----------------------------------------------------------------------------- +unsigned int DMA_GetMaskedStatus(void) +{ + unsigned int status; + status = AT91C_BASE_HDMA->HDMA_EBCISR; + status &= AT91C_BASE_HDMA->HDMA_EBCIMR; + return status; +} + +//------------------------------------------------------------------------------ +/// Enables DMAC channel +/// \param channel Particular channel number. +//------------------------------------------------------------------------------ +void DMA_EnableChannel(unsigned int channel) +{ + ASSERT(channel < DMA_CHANNEL_NUM, "this channel does not exist"); + AT91C_BASE_HDMA->HDMA_CHER |= DMA_ENA << channel; +} + +//------------------------------------------------------------------------------ +/// Disables a DMAC channel +/// \param channel Particular channel number. +//------------------------------------------------------------------------------ +void DMA_DisableChannel(unsigned int channel) +{ + ASSERT(channel < DMA_CHANNEL_NUM, "this channel does not exist"); + AT91C_BASE_HDMA->HDMA_CHDR |= DMA_DIS << channel; +} + +//------------------------------------------------------------------------------ +/// Resume DMAC channel from an stall state. +/// \param channel Particular channel number. +//------------------------------------------------------------------------------ +void DMA_KeeponChannel(unsigned int channel) +{ + ASSERT(channel < DMA_CHANNEL_NUM, "this channel does not exist"); + AT91C_BASE_HDMA->HDMA_CHER |= DMA_KEEPON << channel; +} + +//------------------------------------------------------------------------------ +/// Clear automatic mode for multi-buffer transfer. +/// \param channel Particular channel number. +//------------------------------------------------------------------------------ +void DMA_ClearAutoMode(unsigned int channel) +{ + ASSERT(channel < DMA_CHANNEL_NUM, "this channel does not exist"); + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CTRLB &= 0x7FFFFFFF; +} + +//------------------------------------------------------------------------------ +/// Return DMAC channel status +//------------------------------------------------------------------------------ +unsigned int DMA_GetChannelStatus(void) +{ + return( AT91C_BASE_HDMA->HDMA_CHSR); +} + +//----------------------------------------------------------------------------- +/// Set DMA source address used by a HDMA channel. +/// \param channel Particular channel number. +/// \param sources sources address. +//----------------------------------------------------------------------------- +void DMA_SetSourceAddr(unsigned char channel, unsigned int address) +{ + ASSERT(channel < DMA_CHANNEL_NUM, "this channel does not exist"); + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_SADDR = address; +} + +//----------------------------------------------------------------------------- +/// Set DMA destination address used by a HDMA channel. +/// \param channel Particular channel number. +/// \param sources destination address. +//----------------------------------------------------------------------------- +void DMA_SetDestinationAddr(unsigned char channel, unsigned int address) +{ + ASSERT(channel < DMA_CHANNEL_NUM, "this channel does not exist"); + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_DADDR = address; +} + +//----------------------------------------------------------------------------- +/// Set DMA descriptor address used by a HDMA channel. +/// \param channel Particular channel number. +/// \param sources destination address. +//----------------------------------------------------------------------------- +void DMA_SetDescriptorAddr(unsigned char channel, unsigned int address) +{ + ASSERT(channel < DMA_CHANNEL_NUM, "this channel does not exist"); + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_DSCR = address ; +} + + +//----------------------------------------------------------------------------- +/// Set DMA control A register used by a HDMA channel. +/// \param channel Particular channel number. +/// \param size Dma transfer size in byte. +/// \param sourceWidth Single transfer width for source. +/// \param destWidth Single transfer width for destination. +/// \param done Transfer done field. +//----------------------------------------------------------------------------- +void DMA_SetSourceBufferSize(unsigned char channel, + unsigned int size, + unsigned char sourceWidth, + unsigned char destWidth, + unsigned char done) +{ + ASSERT(channel < DMA_CHANNEL_NUM, "this channel does not exist"); + ASSERT(sourceWidth < 4, "width does not support"); + ASSERT(destWidth < 4, "width does not support"); + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CTRLA = (size | + sourceWidth << 24 | + destWidth << 28 | + done << 31); +} + +//----------------------------------------------------------------------------- +/// Set DMA transfer mode for source used by a HDMA channel. +/// \param channel Particular channel number. +/// \param transferMode Transfer buffer mode (single, LLI, reload or contiguous) +/// \param addressingType Type of addrassing mode +/// 0 : incrementing, 1: decrementing, 2: fixed. +//----------------------------------------------------------------------------- +void DMA_SetSourceBufferMode(unsigned char channel, + unsigned char transferMode, + unsigned char addressingType) +{ + unsigned int value; + + ASSERT(channel < DMA_CHANNEL_NUM, "this channel does not exist"); + + value = AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CTRLB; + value &= ~ (AT91C_SRC_DSCR | AT91C_SRC_INCR | 1<<31); + switch(transferMode){ + case DMA_TRANSFER_SINGLE: + value |= AT91C_SRC_DSCR | addressingType << 24; + break; + case DMA_TRANSFER_LLI: + value |= addressingType << 24; + break; + case DMA_TRANSFER_RELOAD: + case DMA_TRANSFER_CONTIGUOUS: + value |= AT91C_SRC_DSCR | addressingType << 24 | 1<<31; + break; + } + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CTRLB = value; + + if(transferMode == DMA_TRANSFER_RELOAD || transferMode == DMA_TRANSFER_CONTIGUOUS){ + value = AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CFG; + value &= ~ (AT91C_SRC_REP); + // When automatic mode is activated, the source address and the control register are reloaded from previous transfer. + if(transferMode == DMA_TRANSFER_RELOAD) { + value |= AT91C_SRC_REP; + } + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CFG = value; + } + else { + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CFG = 0; + } +} + +//----------------------------------------------------------------------------- +/// Set DMA transfer mode for destination used by a HDMA channel. +/// \param channel Particular channel number. +/// \param transferMode Transfer buffer mode (single, LLI, reload or contiguous) +/// \param addressingType Type of addrassing mode +/// 0 : incrementing, 1: decrementing, 2: fixed. +//----------------------------------------------------------------------------- +void DMA_SetDestBufferMode(unsigned char channel, + unsigned char transferMode, + unsigned char addressingType) +{ + unsigned int value; + + ASSERT(channel < DMA_CHANNEL_NUM, "this channel does not exist"); + + value = AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CTRLB; + value &= ~ (AT91C_DST_DSCR | AT91C_DST_INCR); + + switch(transferMode){ + case DMA_TRANSFER_SINGLE: + case DMA_TRANSFER_RELOAD: + case DMA_TRANSFER_CONTIGUOUS: + value |= AT91C_DST_DSCR | addressingType << 24; + break; + case DMA_TRANSFER_LLI: + value |= addressingType << 24; + break; + } + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CTRLB = value; + if(transferMode == DMA_TRANSFER_RELOAD || transferMode == DMA_TRANSFER_CONTIGUOUS){ + value = AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CFG; + value &= ~ (AT91C_DST_REP); + // When automatic mode is activated, the source address and the control register are reloaded from previous transfer. + if(transferMode == DMA_TRANSFER_RELOAD) { + value |= AT91C_DST_REP; + } + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CFG = value; + } + else { + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CFG = 0; + } +} + +//------------------------------------------------------------------------------ +/// Set DMA configuration registe used by a HDMA channel. +/// \param channel Particular channel number. +/// \param value configuration value. +//------------------------------------------------------------------------------ +void DMA_SetConfiguration(unsigned char channel, unsigned int value) +{ + ASSERT(channel < DMA_CHANNEL_NUM, "this channel does not exist"); + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CFG = value; +} + +//------------------------------------------------------------------------------ +/// Set DMA source PIP configuration used by a HDMA channel. +/// \param channel Particular channel number. +/// \param pipHole stop on done mode. +/// \param pipBoundary lock mode. +//------------------------------------------------------------------------------ +void DMA_SPIPconfiguration(unsigned char channel, + unsigned int pipHole, + unsigned int pipBoundary) + +{ + unsigned int value; + ASSERT(channel < DMA_CHANNEL_NUM, "this channel does not exist"); + value = AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CTRLB; + value &= ~ (AT91C_SRC_PIP); + value |= AT91C_SRC_PIP; + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CTRLB = value; + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_SPIP = (pipHole + 1) | pipBoundary <<16; +} + +//------------------------------------------------------------------------------ +/// Set DMA destination PIP configuration used by a HDMA channel. +/// \param channel Particular channel number. +/// \param pipHole stop on done mode. +/// \param pipBoundary lock mode. +//------------------------------------------------------------------------------ +void DMA_DPIPconfiguration(unsigned char channel, + unsigned int pipHole, + unsigned int pipBoundary) + +{ + unsigned int value; + ASSERT(channel < DMA_CHANNEL_NUM, "this channel does not exist"); + value = AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CTRLB; + value &= ~ (AT91C_DST_PIP); + value |= AT91C_DST_PIP; + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_CTRLB = value; + AT91C_BASE_HDMA->HDMA_CH[channel].HDMA_DPIP = (pipHole + 1) | pipBoundary <<16; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/dma/dma.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/dma/dma.h new file mode 100644 index 000000000..0bd46f841 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/dma/dma.h @@ -0,0 +1,171 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support - ROUSSET - + * ---------------------------------------------------------------------------- + * Copyright (c) 2006, Atmel Corporation + + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaiimer below. + * + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer below in the documentation and/or + * other materials provided with the distribution. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// !Purpose +/// +/// Interface for configuration the %DMA controller(DMAC). +/// +/// !Usage +/// +/// -# Enable or disable the a DMAC controller with +/// DMA_Enable() and or DMA_Disable(). +/// -# Enable or disable %Dma interrupt using DMA_EnableIt() +/// or DMA_DisableIt(). +/// -# Get %Dma interrupt status by DMA_GetStatus(). +/// -# Enable or disable specified %Dma channel with +/// DMA_EnableChannel() or DMA_DisableChannel(). +/// -# Get %Dma channel status by DMA_GetChannelStatus(). +/// -# Configure source and/or destination start address with +/// DMA_SetSourceAddr() and/or DMA_SetDestAddr(). +/// -# Set %Dma descriptor address using DMA_SetDescriptorAddr(). +/// -# Set source transfer buffer size with DMA_SetSourceBufferSize(). +/// -# Configure source and/or destination transfer mode with +/// DMA_SetSourceBufferMode() and/or DMA_SetDestBufferMode(). +/// -# Configure source and/or destination Picture-In-Picutre +/// mode with DMA_SPIPconfiguration() and/or DMA_DPIPconfiguration(). +//------------------------------------------------------------------------------ + +#ifndef DMA_H +#define DMA_H + +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ +#define DMA_CHANNEL_0 0 +#define DMA_CHANNEL_1 1 +#define DMA_CHANNEL_2 2 +#define DMA_CHANNEL_3 3 +#define DMA_CHANNEL_4 4 +#define DMA_CHANNEL_5 5 +#define DMA_CHANNEL_6 6 +#define DMA_CHANNEL_7 7 + +#if defined(CHIP_DMA_CHANNEL_NUM) +#define DMA_CHANNEL_NUM CHIP_DMA_CHANNEL_NUM +#endif + +#define DMA_TRANSFER_SINGLE 0 +#define DMA_TRANSFER_LLI 1 +#define DMA_TRANSFER_RELOAD 2 +#define DMA_TRANSFER_CONTIGUOUS 3 + + +#define DMA_ENA (1 << 0) +#define DMA_DIS (1 << 0) +#define DMA_SUSP (1 << 8) +#define DMA_KEEPON (1 << 24) + +#define DMA_BTC (1 << 0) +#define DMA_CBTC (1 << 8) +#define DMA_ERR (1 << 16) + +#if defined(at91sam9m10) || defined(at91sam9m11) || defined(at91sam3u4) + #define AT91C_SRC_DSCR AT91C_HDMA_SRC_DSCR + #define AT91C_DST_DSCR AT91C_HDMA_DST_DSCR + #define AT91C_SRC_INCR AT91C_HDMA_SRC_ADDRESS_MODE + #define AT91C_DST_INCR AT91C_HDMA_DST_ADDRESS_MODE + #define AT91C_SRC_PER AT91C_HDMA_SRC_PER + #define AT91C_DST_PER AT91C_HDMA_DST_PER + #define AT91C_SRC_REP AT91C_HDMA_SRC_REP + #define AT91C_DST_REP AT91C_HDMA_DST_REP + #define AT91C_SRC_PIP AT91C_HDMA_SRC_PIP + #define AT91C_DST_PIP AT91C_HDMA_DST_PIP + + #define AT91C_BTC (0xFF << 0) + #define AT91C_CBTC (0xFF << 8) + #define AT91C_ERR (0xFF << 16) +#endif + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +extern void DMA_Config(unsigned int flag); + +extern void DMA_Enable(void); + +extern void DMA_Disable(void); + +extern void DMA_EnableChannel(unsigned int channel); + +extern void DMA_DisableChannel(unsigned int channel); + +extern void DMA_KeeponChannel(unsigned int channel); + +extern void DMA_ClearAutoMode(unsigned int channel); + +extern unsigned int DMA_GetChannelStatus(void); + +extern unsigned int DMA_GetStatus(void); + +extern unsigned int DMA_GetInterruptMask(void); + +extern unsigned int DMA_GetMaskedStatus(void); + +extern void DMA_EnableIt (unsigned int flag); + +extern void DMA_DisableIt (unsigned int flag); + +extern void DMA_SetSourceAddr(unsigned char channel, unsigned int address); + +extern void DMA_SetDestinationAddr(unsigned char channel, unsigned int address); + +extern void DMA_SetDescriptorAddr(unsigned char channel, unsigned int address); + +extern void DMA_SetSourceBufferSize(unsigned char channel, + unsigned int size, + unsigned char sourceWidth, + unsigned char desDMAdth, + unsigned char done); + +extern void DMA_SetSourceBufferMode(unsigned char channel, + unsigned char transferMode, + unsigned char addressingType); + +extern void DMA_SetDestBufferMode(unsigned char channel, + unsigned char transferMode, + unsigned char addressingType); + +extern void DMA_SetConfiguration(unsigned char channel, unsigned int value); + +extern void DMA_SPIPconfiguration(unsigned char channel, + unsigned int pipHole, unsigned int pipBoundary); + +extern void DMA_DPIPconfiguration(unsigned char channel, + unsigned int pipHole, unsigned int pipBoundary); + +#endif //#ifndef DMA_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/eefc/eefc.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/eefc/eefc.c new file mode 100644 index 000000000..4ca75f86d --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/eefc/eefc.c @@ -0,0 +1,274 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2009, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include +#include "eefc.h" + +#if !defined (CHIP_FLASH_EEFC) +#error eefc not supported +#endif + +#include +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Enables the flash ready interrupt source on the EEFC peripheral. +/// \param pEfc Pointer to an AT91S_EFC structure. +//------------------------------------------------------------------------------ +void EFC_EnableFrdyIt(AT91S_EFC *pEfc) +{ + pEfc->EFC_FMR |= AT91C_EFC_FRDY; +} + +//------------------------------------------------------------------------------ +/// Disables the flash ready interrupt source on the EEFC peripheral. +/// \param pEfc Pointer to an AT91S_EFC structure. +//------------------------------------------------------------------------------ +void EFC_DisableFrdyIt(AT91S_EFC *pEfc) +{ + pEfc->EFC_FMR &= ~AT91C_EFC_FRDY; +} + +//------------------------------------------------------------------------------ +/// Translates the given address page and offset values. The resulting +/// values are stored in the provided variables if they are not null. +/// \param ppEfc Pointer to target EFC peripheral. +/// \param address Address to translate. +/// \param pPage First page accessed. +/// \param pOffset Byte offset in first page. +//------------------------------------------------------------------------------ +void EFC_TranslateAddress( + AT91S_EFC **ppEfc, + unsigned int address, + unsigned short *pPage, + unsigned short *pOffset) +{ + AT91S_EFC *pEfc; + unsigned short page; + unsigned short offset; + +#if defined(AT91C_BASE_EFC1) + SANITY_CHECK(address >= AT91C_IFLASH); + if (address >= AT91C_IFLASH1) { + SANITY_CHECK(address <= (AT91C_IFLASH1 + AT91C_IFLASH1_SIZE)); + } + else { + SANITY_CHECK(address <= (AT91C_IFLASH + AT91C_IFLASH_SIZE)); + } +#else + SANITY_CHECK(address >= AT91C_IFLASH); + SANITY_CHECK(address <= (AT91C_IFLASH + AT91C_IFLASH_SIZE)); +#endif + + pEfc = AT91C_BASE_EFC; + page = (address - AT91C_IFLASH) / AT91C_IFLASH_PAGE_SIZE; + offset = (address - AT91C_IFLASH) % AT91C_IFLASH_PAGE_SIZE; + +#if defined(AT91C_BASE_EFC1) + if (address >= AT91C_IFLASH1) { + pEfc = AT91C_BASE_EFC1; + page = (address - AT91C_IFLASH1) / AT91C_IFLASH1_PAGE_SIZE; + offset = (address - AT91C_IFLASH1) % AT91C_IFLASH1_PAGE_SIZE; + } +#endif + + TRACE_DEBUG("Translated 0x%08X to page=%d and offset=%d\n\r", + address, page, offset); + + // Store values + if (ppEfc) { + *ppEfc = pEfc; + } + if (pPage) { + + *pPage = page; + } + if (pOffset) { + + *pOffset = offset; + } +} + +//------------------------------------------------------------------------------ +/// Computes the address of a flash access given the page and offset. +/// \param pEfc Pointer to an AT91S_EFC structure. +/// \param page Page number. +/// \param offset Byte offset inside page. +/// \param pAddress Computed address (optional). +//------------------------------------------------------------------------------ +void EFC_ComputeAddress( + AT91S_EFC *pEfc, + unsigned short page, + unsigned short offset, + unsigned int *pAddress) +{ + unsigned int address; + SANITY_CHECK(pEfc); + SANITY_CHECK(page <= AT91C_IFLASH_NB_OF_PAGES); + SANITY_CHECK(offset < AT91C_IFLASH_PAGE_SIZE); + + // Compute address + address = AT91C_IFLASH + page * AT91C_IFLASH_PAGE_SIZE + offset; +#if defined(AT91C_BASE_EFC1) + if (pEfc == AT91C_BASE_EFC1) { + address = AT91C_IFLASH1 + page * AT91C_IFLASH1_PAGE_SIZE + offset; + } +#endif + + // Store result + if (pAddress) { + + *pAddress = address; + } +} + +//------------------------------------------------------------------------------ +/// Starts the executing the given command on the EEFC. This function returns +/// as soon as the command is started. It does NOT set the FMCN field automatically. +/// \param pEfc Pointer to an AT91S_EFC structure. +/// \param command Command to execute. +/// \param argument Command argument (should be 0 if not used). +//------------------------------------------------------------------------------ +#if defined(flash) || defined (USE_FLASH) + #ifdef __ICCARM__ +__ramfunc + #else +__attribute__ ((section (".ramfunc"))) + #endif +#endif +void EFC_StartCommand(AT91S_EFC *pEfc, unsigned char command, unsigned short argument) +{ + // Check command & argument + switch (command) { + + case AT91C_EFC_FCMD_WP: + case AT91C_EFC_FCMD_WPL: + case AT91C_EFC_FCMD_EWP: + case AT91C_EFC_FCMD_EWPL: + case AT91C_EFC_FCMD_EPL: + case AT91C_EFC_FCMD_EPA: + case AT91C_EFC_FCMD_SLB: + case AT91C_EFC_FCMD_CLB: + ASSERT(argument < AT91C_IFLASH_NB_OF_PAGES, + "-F- Embedded flash has only %d pages\n\r", + AT91C_IFLASH_NB_OF_PAGES); + break; + + case AT91C_EFC_FCMD_SFB: + case AT91C_EFC_FCMD_CFB: + ASSERT(argument < CHIP_EFC_NUM_GPNVMS, "-F- Embedded flash has only %d GPNVMs\n\r", CHIP_EFC_NUM_GPNVMS); + break; + + case AT91C_EFC_FCMD_GETD: + case AT91C_EFC_FCMD_EA: + case AT91C_EFC_FCMD_GLB: + case AT91C_EFC_FCMD_GFB: +#ifdef AT91C_EFC_FCMD_STUI + case AT91C_EFC_FCMD_STUI: +#endif + ASSERT(argument == 0, "-F- Argument is meaningless for the given command.\n\r"); + break; + + default: ASSERT(0, "-F- Unknown command %d\n\r", command); + } + + // Start commandEmbedded flash + ASSERT((pEfc->EFC_FSR & AT91C_EFC_FRDY) == AT91C_EFC_FRDY, "-F- EEFC is not ready\n\r"); + pEfc->EFC_FCR = (0x5A << 24) | (argument << 8) | command; +} + +//------------------------------------------------------------------------------ +/// Performs the given command and wait until its completion (or an error). +/// Returns 0 if successful; otherwise returns an error code. +/// \param pEfc Pointer to an AT91S_EFC structure. +/// \param command Command to perform. +/// \param argument Optional command argument. +//------------------------------------------------------------------------------ +#if defined(flash) || defined (USE_FLASH) + #ifdef __ICCARM__ +__ramfunc + #else +__attribute__ ((section (".ramfunc"))) + #endif +#endif +unsigned char EFC_PerformCommand(AT91S_EFC *pEfc, unsigned char command, unsigned short argument) +{ + unsigned int status; + +#ifdef CHIP_FLASH_IAP_ADDRESS + // Pointer on IAP function in ROM + static void (*IAP_PerformCommand)(unsigned int); + IAP_PerformCommand = (void (*)(unsigned int)) *((unsigned int *) CHIP_FLASH_IAP_ADDRESS); + + // Check if IAP function is implemented (opcode in SWI != 'b' or 'ldr') */ + if ((((((unsigned long) IAP_PerformCommand >> 24) & 0xFF) != 0xEA) && + (((unsigned long) IAP_PerformCommand >> 24) & 0xFF) != 0xE5)) { + + IAP_PerformCommand((0x5A << 24) | (argument << 8) | command); + return (pEfc->EFC_FSR & (AT91C_EFC_LOCKE | AT91C_EFC_FCMDE)); + } +#endif + + pEfc->EFC_FCR = (0x5A << 24) | (argument << 8) | command; + do { + + status = pEfc->EFC_FSR; + } + while ((status & AT91C_EFC_FRDY) != AT91C_EFC_FRDY); + + return (status & (AT91C_EFC_LOCKE | AT91C_EFC_FCMDE)); +} + +//------------------------------------------------------------------------------ +/// Returns the current status of the EEFC. Keep in mind that this function clears +/// the value of some status bits (LOCKE, PROGE). +/// \param pEfc Pointer to an AT91S_EFC structure. +//------------------------------------------------------------------------------ +unsigned int EFC_GetStatus(AT91S_EFC *pEfc) +{ + return pEfc->EFC_FSR; +} + +//------------------------------------------------------------------------------ +/// Returns the result of the last executed command. +/// \param pEfc Pointer to an AT91S_EFC structure. +//------------------------------------------------------------------------------ +unsigned int EFC_GetResult(AT91S_EFC *pEfc) { + + return pEfc->EFC_FRR; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/eefc/eefc.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/eefc/eefc.h new file mode 100644 index 000000000..a5ebd095b --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/eefc/eefc.h @@ -0,0 +1,147 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2009, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Interface for configuration the Enhanced Embedded Flash Controller (EEFC) +/// peripheral. +/// +/// !Usage +/// +/// -# Enable/disable %flash ready interrupt sources using EFC_EnableFrdyIt() +/// and EFC_DisableFrdyIt(). +/// -# Translates the given address into which EEFC, page and offset values +/// for difference density %flash memory using EFC_TranslateAddress(). +/// -# Computes the address of a %flash access given the EFC, page and offset +/// for difference density %flash memory using EFC_ComputeAddress(). +/// -# Start the executing command with EFC_StartCommand() +/// -# Retrieve the current status of the EFC using EFC_GetStatus(). +/// -# Retrieve the result of the last executed command with EFC_GetResult(). +//------------------------------------------------------------------------------ +#ifndef EEFC_H +#define EEFC_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +#if !defined (CHIP_FLASH_EEFC) +#error eefc not supported +#endif + +//------------------------------------------------------------------------------ +// Constants +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Types +//------------------------------------------------------------------------------ + +// Needed when EEFC is integrated in MC. +#if !defined(AT91C_BASE_EFC) && defined(AT91C_BASE_MC) +typedef struct _AT91S_EFC { + AT91_REG EFC_FMR; // EFC Flash Mode Register + AT91_REG EFC_FCR; // EFC Flash Command Register + AT91_REG EFC_FSR; // EFC Flash Status Register + AT91_REG EFC_FRR; // EFC Flash Result Register + AT91_REG EFC_FVR; // EFC Flash Version Register +} AT91S_EFC, *AT91PS_EFC; + +#define AT91C_EFC_FRDY AT91C_MC_FRDY +#define AT91C_EFC_FWS AT91C_MC_FWS +#define AT91C_EFC_FWS_0WS AT91C_MC_FWS_0WS +#define AT91C_EFC_FWS_1WS AT91C_MC_FWS_1WS +#define AT91C_EFC_FWS_2WS AT91C_MC_FWS_2WS +#define AT91C_EFC_FWS_3WS AT91C_MC_FWS_3WS +#define AT91C_EFC_FCMD AT91C_MC_FCMD +#define AT91C_EFC_FCMD_GETD AT91C_MC_FCMD_GETD +#define AT91C_EFC_FCMD_WP AT91C_MC_FCMD_WP +#define AT91C_EFC_FCMD_WPL AT91C_MC_FCMD_WPL +#define AT91C_EFC_FCMD_EWP AT91C_MC_FCMD_EWP +#define AT91C_EFC_FCMD_EWPL AT91C_MC_FCMD_EWPL +#define AT91C_EFC_FCMD_EA AT91C_MC_FCMD_EA +#define AT91C_EFC_FCMD_EPL AT91C_MC_FCMD_EPL +#define AT91C_EFC_FCMD_EPA AT91C_MC_FCMD_EPA +#define AT91C_EFC_FCMD_SLB AT91C_MC_FCMD_SLB +#define AT91C_EFC_FCMD_CLB AT91C_MC_FCMD_CLB +#define AT91C_EFC_FCMD_GLB AT91C_MC_FCMD_GLB +#define AT91C_EFC_FCMD_SFB AT91C_MC_FCMD_SFB +#define AT91C_EFC_FCMD_CFB AT91C_MC_FCMD_CFB +#define AT91C_EFC_FCMD_GFB AT91C_MC_FCMD_GFB +#define AT91C_EFC_FARG AT91C_MC_FARG +#define AT91C_EFC_FKEY AT91C_MC_FKEY +#define AT91C_EFC_FRDY_S AT91C_MC_FRDY_S +#define AT91C_EFC_FCMDE AT91C_MC_FCMDE +#define AT91C_EFC_LOCKE AT91C_MC_LOCKE +#define AT91C_EFC_FVALUE AT91C_MC_FVALUE + +#define AT91C_BASE_EFC (AT91_CAST(AT91PS_EFC) 0xFFFFFF60) + +#endif //#if !defined(AT91C_BASE_EFC) && defined(AT91C_BASE_MC) + +//------------------------------------------------------------------------------ +// Functions +//------------------------------------------------------------------------------ + +extern void EFC_EnableFrdyIt(AT91S_EFC *pEfc); + +extern void EFC_DisableFrdyIt(AT91S_EFC *pEfc); + +extern void EFC_TranslateAddress( + AT91S_EFC **ppEfc, + unsigned int address, + unsigned short *pPage, + unsigned short *pOffset); + +extern void EFC_ComputeAddress( + AT91S_EFC *pEfc, + unsigned short page, + unsigned short offset, + unsigned int *pAddress); + +extern void EFC_StartCommand( + AT91S_EFC *pEfc, + unsigned char command, + unsigned short argument); + +extern unsigned char EFC_PerformCommand( + AT91S_EFC *pEfc, + unsigned char command, + unsigned short argument); + +extern unsigned int EFC_GetStatus(AT91S_EFC *pEfc); + +extern unsigned int EFC_GetResult(AT91S_EFC *pEfc); + +#endif //#ifndef EEFC_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/efc/efc.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/efc/efc.c new file mode 100644 index 000000000..c12a60a5e --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/efc/efc.c @@ -0,0 +1,395 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "efc.h" + +#ifdef BOARD_FLASH_EFC + +#include +#include + +//------------------------------------------------------------------------------ +// Local definitions +//------------------------------------------------------------------------------ + +// Round a number to the nearest integral value (number must have been +// multiplied by 10, e.g. to round 10.3 enter 103). +#define ROUND(n) ((((n) % 10) >= 5) ? (((n) / 10) + 1) : ((n) / 10)) + +// Returns the FMCN field value when manipulating lock bits, given MCK. +#if defined(at91sam7a3) + #define FMCN_BITS(mck) (ROUND((mck) / 1000000) << 16) +#else + #define FMCN_BITS(mck) (ROUND((mck) / 100000) << 16) +#endif + +// Returns the FMCN field value when manipulating the rest of the flash. +#define FMCN_FLASH(mck) ((((mck) / 2000000) * 3) << 16) + +//------------------------------------------------------------------------------ +// Local functions +//------------------------------------------------------------------------------ + +/// Master clock frequency, used to infer the value of the FMCN field. +#ifdef MCK_VARIABLE +static unsigned int lMck = 0; +#else +static const unsigned int lMck = BOARD_MCK; +#endif + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Sets the system master clock so the FMCN field of the EFC(s) can be +/// programmed properly. +/// \param mck Master clock frequency in Hz. +//------------------------------------------------------------------------------ +void EFC_SetMasterClock(unsigned int mck) +{ +#ifdef MCK_VARIABLE + lMck = mck; +#else + ASSERT(mck == BOARD_MCK, "-F- EFC has not been configured to work at a freq. different from %dMHz", BOARD_MCK); +#endif +} + +//------------------------------------------------------------------------------ +/// Enables the given interrupt sources on an EFC peripheral. +/// \param pEfc Pointer to an AT91S_EFC structure. +/// \param sources Interrupt sources to enable. +//------------------------------------------------------------------------------ +void EFC_EnableIt(AT91S_EFC *pEfc, unsigned int sources) +{ + SANITY_CHECK(pEfc); + SANITY_CHECK((sources & ~0x0000000D) == 0); + + pEfc->EFC_FMR |= sources; +} + +//------------------------------------------------------------------------------ +/// Disables the given interrupt sources on an EFC peripheral. +/// \param pEfc Pointer to an AT91S_EFC structure. +/// \param sources Interrupt sources to disable. +//------------------------------------------------------------------------------ +void EFC_DisableIt(AT91S_EFC *pEfc, unsigned int sources) +{ + SANITY_CHECK(pEfc); + SANITY_CHECK((sources & ~(AT91C_MC_FRDY | AT91C_MC_LOCKE | AT91C_MC_PROGE)) == 0); + + pEfc->EFC_FMR &= ~sources; +} + +//------------------------------------------------------------------------------ +/// Enables or disable the "Erase before programming" feature of an EFC. +/// \param pEfc Pointer to an AT91S_EFC structure. +/// \param enable If 1, the feature is enabled; otherwise it is disabled. +//------------------------------------------------------------------------------ +void EFC_SetEraseBeforeProgramming(AT91S_EFC *pEfc, unsigned char enable) +{ + SANITY_CHECK(pEfc); + + if (enable) { + + pEfc->EFC_FMR &= ~AT91C_MC_NEBP; + } + else { + + pEfc->EFC_FMR |= AT91C_MC_NEBP; + } +} + +//------------------------------------------------------------------------------ +/// Translates the given address into EFC, page and offset values. The resulting +/// values are stored in the provided variables if they are not null. +/// \param address Address to translate. +/// \param ppEfc Pointer to target EFC peripheral. +/// \param pPage First page accessed. +/// \param pOffset Byte offset in first page. +//------------------------------------------------------------------------------ +void EFC_TranslateAddress( + unsigned int address, + AT91S_EFC **ppEfc, + unsigned short *pPage, + unsigned short *pOffset) +{ + AT91S_EFC *pEfc; + unsigned short page; + unsigned short offset; + + SANITY_CHECK(address >= AT91C_IFLASH); + SANITY_CHECK(address <= (AT91C_IFLASH + AT91C_IFLASH_SIZE)); + +#if defined(AT91C_BASE_EFC0) + if (address >= (AT91C_IFLASH + AT91C_IFLASH_SIZE / 2)) { + + pEfc = AT91C_BASE_EFC1; + page = (address - AT91C_IFLASH - AT91C_IFLASH_SIZE / 2) / AT91C_IFLASH_PAGE_SIZE; + offset = (address - AT91C_IFLASH - AT91C_IFLASH_SIZE / 2) % AT91C_IFLASH_PAGE_SIZE; + } + else { + + pEfc = AT91C_BASE_EFC0; + page = (address - AT91C_IFLASH) / AT91C_IFLASH_PAGE_SIZE; + offset = (address - AT91C_IFLASH) % AT91C_IFLASH_PAGE_SIZE; + } +#else + pEfc = AT91C_BASE_EFC; + page = (address - AT91C_IFLASH) / AT91C_IFLASH_PAGE_SIZE; + offset = (address - AT91C_IFLASH) % AT91C_IFLASH_PAGE_SIZE; +#endif + TRACE_DEBUG("Translated 0x%08X to EFC=0x%08X, page=%d and offset=%d\n\r", + address, (unsigned int) pEfc, page, offset); + + // Store values + if (ppEfc) { + + *ppEfc = pEfc; + } + if (pPage) { + + *pPage = page; + } + if (pOffset) { + + *pOffset = offset; + } +} + +//------------------------------------------------------------------------------ +/// Computes the address of a flash access given the EFC, page and offset. +/// \param pEfc Pointer to an AT91S_EFC structure. +/// \param page Page number. +/// \param offset Byte offset inside page. +/// \param pAddress Computed address (optional). +//------------------------------------------------------------------------------ +void EFC_ComputeAddress( + AT91S_EFC *pEfc, + unsigned short page, + unsigned short offset, + unsigned int *pAddress) +{ + unsigned int address; + + SANITY_CHECK(pEfc); +#if defined(AT91C_BASE_EFC1) + SANITY_CHECK(page <= (AT91C_IFLASH_NB_OF_PAGES / 2)); +#else + SANITY_CHECK(page <= AT91C_IFLASH_NB_OF_PAGES); +#endif + SANITY_CHECK(offset < AT91C_IFLASH_PAGE_SIZE); + + // Compute address + address = AT91C_IFLASH + page * AT91C_IFLASH_PAGE_SIZE + offset; +#if defined(AT91C_BASE_EFC1) + if (pEfc == AT91C_BASE_EFC1) { + + address += AT91C_IFLASH_SIZE / 2; + } +#endif + + // Store result + if (pAddress) { + + *pAddress = address; + } +} + +//------------------------------------------------------------------------------ +/// Starts the executing the given command on an EFC. This function returns +/// as soon as the command is started. It does NOT set the FMCN field automatically. +/// \param pEfc Pointer to an AT91S_EFC structure. +/// \param command Command to execute. +/// \param argument Command argument (should be 0 if not used). +//------------------------------------------------------------------------------ +#if defined(flash) + #ifdef __ICCARM__ +__ramfunc + #else +__attribute__ ((section (".ramfunc"))) + #endif +#endif +void EFC_StartCommand( + AT91S_EFC *pEfc, + unsigned char command, + unsigned short argument) +{ + SANITY_CHECK(pEfc); + ASSERT(lMck != 0, "-F- Master clock not set.\n\r"); + + // Check command & argument + switch (command) { + + case AT91C_MC_FCMD_PROG_AND_LOCK: + ASSERT(0, "-F- Write and lock command cannot be carried out.\n\r"); + break; + + case AT91C_MC_FCMD_START_PROG: + case AT91C_MC_FCMD_LOCK: + case AT91C_MC_FCMD_UNLOCK: + ASSERT(argument < AT91C_IFLASH_NB_OF_PAGES, + "-F- Maximum number of pages is %d (argument was %d)\n\r", + AT91C_IFLASH_NB_OF_PAGES, + argument); + break; + +#if (EFC_NUM_GPNVMS > 0) + case AT91C_MC_FCMD_SET_GP_NVM: + case AT91C_MC_FCMD_CLR_GP_NVM: + ASSERT(argument < EFC_NUM_GPNVMS, "-F- A maximum of %d GPNVMs are available on the chip.\n\r", EFC_NUM_GPNVMS); + break; +#endif + + case AT91C_MC_FCMD_ERASE_ALL: + +#if !defined(EFC_NO_SECURITY_BIT) + case AT91C_MC_FCMD_SET_SECURITY: +#endif + ASSERT(argument == 0, "-F- Argument is meaningless for the given command\n\r"); + break; + + default: ASSERT(0, "-F- Unknown command %d\n\r", command); + } + + // Set FMCN + switch (command) { + + case AT91C_MC_FCMD_LOCK: + case AT91C_MC_FCMD_UNLOCK: +#if (EFC_NUM_GPNVMS > 0) + case AT91C_MC_FCMD_SET_GP_NVM: + case AT91C_MC_FCMD_CLR_GP_NVM: +#endif +#if !defined(EFC_NO_SECURITY_BIT) + case AT91C_MC_FCMD_SET_SECURITY: +#endif + pEfc->EFC_FMR = (pEfc->EFC_FMR & ~AT91C_MC_FMCN) | FMCN_BITS(lMck); + break; + + case AT91C_MC_FCMD_START_PROG: + case AT91C_MC_FCMD_ERASE_ALL: + pEfc->EFC_FMR = (pEfc->EFC_FMR & ~AT91C_MC_FMCN) | FMCN_FLASH(lMck); + break; + } + + // Start command + ASSERT((pEfc->EFC_FSR & AT91C_MC_FRDY) != 0, "-F- Efc is not ready\n\r"); + pEfc->EFC_FCR = (0x5A << 24) | (argument << 8) | command; +} + +//------------------------------------------------------------------------------ +/// Performs the given command and wait until its completion (or an error). +/// Returns 0 if successful; otherwise returns an error code. +/// \param pEfc Pointer to an AT91S_EFC structure. +/// \param command Command to perform. +/// \param argument Optional command argument. +//------------------------------------------------------------------------------ +#if defined(flash) + #ifdef __ICCARM__ +__ramfunc + #else +__attribute__ ((section (".ramfunc"))) + #endif +#endif +unsigned char EFC_PerformCommand( + AT91S_EFC *pEfc, + unsigned char command, + unsigned short argument) +{ + unsigned int status; + + // Set FMCN + switch (command) { + + case AT91C_MC_FCMD_LOCK: + case AT91C_MC_FCMD_UNLOCK: +#if (EFC_NUM_GPNVMS > 0) + case AT91C_MC_FCMD_SET_GP_NVM: + case AT91C_MC_FCMD_CLR_GP_NVM: +#endif +#if !defined(EFC_NO_SECURITY_BIT) + case AT91C_MC_FCMD_SET_SECURITY: +#endif + pEfc->EFC_FMR = (pEfc->EFC_FMR & ~AT91C_MC_FMCN) | FMCN_BITS(lMck); + break; + + case AT91C_MC_FCMD_START_PROG: + case AT91C_MC_FCMD_ERASE_ALL: + pEfc->EFC_FMR = (pEfc->EFC_FMR & ~AT91C_MC_FMCN) | FMCN_FLASH(lMck); + break; + } + +#ifdef BOARD_FLASH_IAP_ADDRESS + // Pointer on IAP function in ROM + static void (*IAP_PerformCommand)(unsigned int, unsigned int); + unsigned int index = 0; +#ifdef AT91C_BASE_EFC1 + if (pEfc == AT91C_BASE_EFC1) { + + index = 1; + } +#endif + IAP_PerformCommand = (void (*)(unsigned int, unsigned int)) *((unsigned int *) BOARD_FLASH_IAP_ADDRESS); + + // Check if IAP function is implemented (opcode in SWI != 'b' or 'ldr') */ + if ((((((unsigned long) IAP_PerformCommand >> 24) & 0xFF) != 0xEA) && + (((unsigned long) IAP_PerformCommand >> 24) & 0xFF) != 0xE5)) { + + IAP_PerformCommand(index, (0x5A << 24) | (argument << 8) | command); + return (pEfc->EFC_FSR & (AT91C_MC_LOCKE | AT91C_MC_PROGE)); + } +#endif + + pEfc->EFC_FCR = (0x5A << 24) | (argument << 8) | command; + do { + + status = pEfc->EFC_FSR; + } + while ((status & AT91C_MC_FRDY) == 0); + + return (status & (AT91C_MC_PROGE | AT91C_MC_LOCKE)); +} + +//------------------------------------------------------------------------------ +/// Returns the current status of an EFC. Keep in mind that this function clears +/// the value of some status bits (LOCKE, PROGE). +/// \param pEfc Pointer to an AT91S_EFC structure. +//------------------------------------------------------------------------------ +unsigned int EFC_GetStatus(AT91S_EFC *pEfc) +{ + return pEfc->EFC_FSR; +} + +#endif //#ifdef BOARD_FLASH_EFC + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/efc/efc.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/efc/efc.h new file mode 100644 index 000000000..ecf7a69d7 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/efc/efc.h @@ -0,0 +1,147 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Interface for configuration the Embedded Flash Controller (EFC) peripheral. +/// +/// !Usage +/// +/// -# Initialize system master clock of the EFC with EFC_SetMasterClock(). +/// -# Enable/disable interrupt sources using EFC_EnableIt() and EFC_DisableIt(). +/// -# Enables or disable the "Erase before programming" feature using +/// EFC_SetEraseBeforeProgramming(). +/// -# Translates the given address into which EFC, page and offset values for +/// difference density %flash memory using EFC_TranslateAddress(). +/// -# Computes the address of a %flash access given the EFC, page and offset +/// for difference density %flash memory using EFC_ComputeAddress(). +/// -# Start the executing command with EFC_StartCommand() +/// -# Retrieve the current status of the EFC using EFC_GetStatus(). +/// +//------------------------------------------------------------------------------ +#ifndef EFC_H +#define EFC_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +#ifdef BOARD_FLASH_EFC + +//------------------------------------------------------------------------------ +// Constants +//------------------------------------------------------------------------------ + +/// Number of GPNVMs available on each chip. +#if defined(at91sam7s16) || defined(at91sam7s161) || defined(at91sam7s32) \ + || defined(at91sam7s321) || defined(at91sam7s64) || defined(at91sam7s128) \ + || defined(at91sam7s256) || defined(at91sam7s512) + + #define EFC_NUM_GPNVMS 2 + +#elif defined(at91sam7se32) || defined(at91sam7se256) || defined(at91sam7se512) \ + || defined(at91sam7x128) || defined(at91sam7x256) || defined(at91sam7x512) \ + || defined(at91sam7xc128) || defined(at91sam7xc256) || defined(at91sam7xc512) \ + + #define EFC_NUM_GPNVMS 3 + +#elif defined(at91sam7a3) + + #define EFC_NUM_GPNVMS 0 +#endif + +// Missing FRDY bit for SAM7A3 +#if defined(at91sam7a3) + #define AT91C_MC_FRDY (AT91C_MC_EOP | AT91C_MC_EOL) +#endif + +// No security bit on SAM7A3 +#if defined(at91sam7a3) + #define EFC_NO_SECURITY_BIT +#endif + +//------------------------------------------------------------------------------ +// Types +//------------------------------------------------------------------------------ + +// For chips which do not define AT91S_EFC +#if !defined(AT91C_BASE_EFC) && !defined(AT91C_BASE_EFC0) +typedef struct _AT91S_EFC { + + AT91_REG EFC_FMR; + AT91_REG EFC_FCR; + AT91_REG EFC_FSR; + +} AT91S_EFC, *AT91PS_EFC; + #define AT91C_BASE_EFC (AT91_CAST(AT91PS_EFC) 0xFFFFFF60) +#endif + +//------------------------------------------------------------------------------ +// Functions +//------------------------------------------------------------------------------ + +extern void EFC_SetMasterClock(unsigned int mck); + +extern void EFC_EnableIt(AT91S_EFC *pEfc, unsigned int sources); + +extern void EFC_DisableIt(AT91S_EFC *pEfc, unsigned int sources); + +extern void EFC_SetEraseBeforeProgramming(AT91S_EFC *pEfc, unsigned char enable); + +extern void EFC_TranslateAddress( + unsigned int address, + AT91S_EFC **ppEfc, + unsigned short *pPage, + unsigned short *pOffset); + +extern void EFC_ComputeAddress( + AT91S_EFC *pEfc, + unsigned short page, + unsigned short offset, + unsigned int *pAddress); + +extern void EFC_StartCommand( + AT91S_EFC *pEfc, + unsigned char command, + unsigned short argument); + +extern unsigned char EFC_PerformCommand( + AT91S_EFC *pEfc, + unsigned char command, + unsigned short argument); + +extern unsigned int EFC_GetStatus(AT91S_EFC *pEfc); + +#endif //#ifdef BOARD_FLASH_EFC +#endif //#ifndef EFC_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/emac/emac.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/emac/emac.c new file mode 100644 index 000000000..93ba2d5d0 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/emac/emac.c @@ -0,0 +1,832 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- +#include +#include "emac.h" +#include +#include +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ +/// The buffer addresses written into the descriptors must be aligned so the +/// last few bits are zero. These bits have special meaning for the EMAC +/// peripheral and cannot be used as part of the address. +#define EMAC_ADDRESS_MASK ((unsigned int)0xFFFFFFFC) +#define EMAC_LENGTH_FRAME ((unsigned int)0x0FFF) /// Length of frame mask + +// receive buffer descriptor bits +#define EMAC_RX_OWNERSHIP_BIT (1 << 0) +#define EMAC_RX_WRAP_BIT (1 << 1) +#define EMAC_RX_SOF_BIT (1 << 14) +#define EMAC_RX_EOF_BIT (1 << 15) + +// Transmit buffer descriptor bits +#define EMAC_TX_LAST_BUFFER_BIT (1 << 15) +#define EMAC_TX_WRAP_BIT (1 << 30) +#define EMAC_TX_USED_BIT (1 << 31) + +//----------------------------------------------------------------------------- +// Circular buffer management +//----------------------------------------------------------------------------- +// Return count in buffer +#define CIRC_CNT(head,tail,size) (((head) - (tail)) & ((size)-1)) + +// Return space available, 0..size-1 +// We always leave one free char as a completely full buffer +// has head == tail, which is the same as empty +#define CIRC_SPACE(head,tail,size) CIRC_CNT((tail),((head)+1),(size)) + +// Return count up to the end of the buffer. +// Carefully avoid accessing head and tail more than once, +// so they can change underneath us without returning inconsistent results +#define CIRC_CNT_TO_END(head,tail,size) \ + ({int end = (size) - (tail); \ + int n = ((head) + end) & ((size)-1); \ + n < end ? n : end;}) + +// Return space available up to the end of the buffer +#define CIRC_SPACE_TO_END(head,tail,size) \ + ({int end = (size) - 1 - (head); \ + int n = (end + (tail)) & ((size)-1); \ + n <= end ? n : end+1;}) + +// Increment head or tail +#define CIRC_INC(headortail,size) \ + headortail++; \ + if(headortail >= size) { \ + headortail = 0; \ + } + +#define CIRC_EMPTY(circ) ((circ)->head == (circ)->tail) +#define CIRC_CLEAR(circ) ((circ)->head = (circ)->tail = 0) + + +//------------------------------------------------------------------------------ +// Structures +//------------------------------------------------------------------------------ +#ifdef __ICCARM__ // IAR +#pragma pack(4) // IAR +#define __attribute__(...) // IAR +#endif // IAR +/// Describes the type and attribute of Receive Transfer descriptor. +typedef struct _EmacRxTDescriptor { + unsigned int addr; + unsigned int status; +} __attribute__((packed, aligned(8))) EmacRxTDescriptor, *PEmacRxTDescriptor; + +/// Describes the type and attribute of Transmit Transfer descriptor. +typedef struct _EmacTxTDescriptor { + unsigned int addr; + unsigned int status; +} __attribute__((packed, aligned(8))) EmacTxTDescriptor, *PEmacTxTDescriptor; +#ifdef __ICCARM__ // IAR +#pragma pack() // IAR +#endif // IAR + +#ifdef __ICCARM__ // IAR +#pragma data_alignment=8 // IAR +#endif // IAR +/// Descriptors for RX (required aligned by 8) +typedef struct { + volatile EmacRxTDescriptor td[RX_BUFFERS]; + EMAC_RxCallback rxCb; /// Callback function to be invoked once a frame has been received + unsigned short idx; +} RxTd; + +#ifdef __ICCARM__ // IAR +#pragma data_alignment=8 // IAR +#endif // IAR +/// Descriptors for TX (required aligned by 8) +typedef struct { + volatile EmacTxTDescriptor td[TX_BUFFERS]; + EMAC_TxCallback txCb[TX_BUFFERS]; /// Callback function to be invoked once TD has been processed + EMAC_WakeupCallback wakeupCb; /// Callback function to be invoked once several TD have been released + unsigned short wakeupThreshold; /// Number of free TD before wakeupCb is invoked + unsigned short head; /// Circular buffer head pointer incremented by the upper layer (buffer to be sent) + unsigned short tail; /// Circular buffer head pointer incremented by the IT handler (buffer sent) +} TxTd; + +//------------------------------------------------------------------------------ +// Internal variables +//------------------------------------------------------------------------------ +// Receive Transfer Descriptor buffer +static volatile RxTd rxTd; +// Transmit Transfer Descriptor buffer +static volatile TxTd txTd; +/// Send Buffer +// Section 3.6 of AMBA 2.0 spec states that burst should not cross 1K Boundaries. +// Receive buffer manager writes are burst of 2 words => 3 lsb bits of the address shall be set to 0 +#ifdef __ICCARM__ // IAR +#pragma data_alignment=8 // IAR +#endif // IAR +static volatile unsigned char pTxBuffer[TX_BUFFERS * EMAC_TX_UNITSIZE] __attribute__((aligned(8))); + +#ifdef __ICCARM__ // IAR +#pragma data_alignment=8 // IAR +#endif // IAR +/// Receive Buffer +static volatile unsigned char pRxBuffer[RX_BUFFERS * EMAC_RX_UNITSIZE] __attribute__((aligned(8))); +/// Statistics +static volatile EmacStats EmacStatistics; + +//----------------------------------------------------------------------------- +// Internal functions +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +/// Wait PHY operation complete. +/// Return 1 if the operation completed successfully. +/// May be need to re-implemented to reduce CPU load. +/// \param retry: the retry times, 0 to wait forever until complete. +//----------------------------------------------------------------------------- +static unsigned char EMAC_WaitPhy( unsigned int retry ) +{ + unsigned int retry_count = 0; + + while((AT91C_BASE_EMAC->EMAC_NSR & AT91C_EMAC_IDLE) == 0) { + + // Dead LOOP! + if (retry == 0) { + + continue; + } + + // Timeout check + retry_count++; + if(retry_count >= retry) { + + TRACE_ERROR("E: Wait PHY time out\n\r"); + return 0; + } + } + + return 1; +} + +//----------------------------------------------------------------------------- +// Exported functions +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// PHY management functions +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +/// Set MDC clock according to current board clock. Per 802.3, MDC should be +/// less then 2.5MHz. +/// Return 1 if successfully, 0 if MDC clock not found. +//----------------------------------------------------------------------------- +unsigned char EMAC_SetMdcClock( unsigned int mck ) +{ + int clock_dividor; + + if (mck <= 20000000) { + clock_dividor = AT91C_EMAC_CLK_HCLK_8; /// MDC clock = MCK/8 + } + else if (mck <= 40000000) { + clock_dividor = AT91C_EMAC_CLK_HCLK_16; /// MDC clock = MCK/16 + } + else if (mck <= 80000000) { + clock_dividor = AT91C_EMAC_CLK_HCLK_32; /// MDC clock = MCK/32 + } + else if (mck <= 160000000) { + clock_dividor = AT91C_EMAC_CLK_HCLK_64; /// MDC clock = MCK/64 + } + else { + TRACE_ERROR("E: No valid MDC clock.\n\r"); + return 0; + } + AT91C_BASE_EMAC->EMAC_NCFGR = (AT91C_BASE_EMAC->EMAC_NCFGR & (~AT91C_EMAC_CLK)) + | clock_dividor; + return 1; +} + +//----------------------------------------------------------------------------- +/// Enable MDI with PHY +//----------------------------------------------------------------------------- +void EMAC_EnableMdio( void ) +{ + AT91C_BASE_EMAC->EMAC_NCR |= AT91C_EMAC_MPE; +} + +//----------------------------------------------------------------------------- +/// Enable MDI with PHY +//----------------------------------------------------------------------------- +void EMAC_DisableMdio( void ) +{ + AT91C_BASE_EMAC->EMAC_NCR &= ~AT91C_EMAC_MPE; +} + +//----------------------------------------------------------------------------- +/// Enable MII mode for EMAC, called once after autonegotiate +//----------------------------------------------------------------------------- +void EMAC_EnableMII( void ) +{ + AT91C_BASE_EMAC->EMAC_USRIO = AT91C_EMAC_CLKEN; +} + +//----------------------------------------------------------------------------- +/// Enable RMII mode for EMAC, called once after autonegotiate +//----------------------------------------------------------------------------- +void EMAC_EnableRMII( void ) +{ + AT91C_BASE_EMAC->EMAC_USRIO = AT91C_EMAC_CLKEN | AT91C_EMAC_RMII; +} + +//----------------------------------------------------------------------------- +/// Read PHY register. +/// Return 1 if successfully, 0 if timeout. +/// \param PhyAddress PHY Address +/// \param Address Register Address +/// \param pValue Pointer to a 32 bit location to store read data +/// \param retry The retry times, 0 to wait forever until complete. +//----------------------------------------------------------------------------- +unsigned char EMAC_ReadPhy(unsigned char PhyAddress, + unsigned char Address, + unsigned int *pValue, + unsigned int retry) +{ + AT91C_BASE_EMAC->EMAC_MAN = (AT91C_EMAC_SOF & (0x01 << 30)) + | (AT91C_EMAC_CODE & (2 << 16)) + | (AT91C_EMAC_RW & (2 << 28)) + | (AT91C_EMAC_PHYA & ((PhyAddress & 0x1f) << 23)) + | (AT91C_EMAC_REGA & (Address << 18)); + + if ( EMAC_WaitPhy(retry) == 0 ) { + + TRACE_ERROR("TimeOut EMAC_ReadPhy\n\r"); + return 0; + } + *pValue = ( AT91C_BASE_EMAC->EMAC_MAN & 0x0000ffff ); + return 1; +} + +//----------------------------------------------------------------------------- +/// Write PHY register +/// Return 1 if successfully, 0 if timeout. +/// \param PhyAddress PHY Address +/// \param Address Register Address +/// \param Value Data to write ( Actually 16 bit data ) +/// \param retry The retry times, 0 to wait forever until complete. +//----------------------------------------------------------------------------- +unsigned char EMAC_WritePhy(unsigned char PhyAddress, + unsigned char Address, + unsigned int Value, + unsigned int retry) +{ + AT91C_BASE_EMAC->EMAC_MAN = (AT91C_EMAC_SOF & (0x01 << 30)) + | (AT91C_EMAC_CODE & (2 << 16)) + | (AT91C_EMAC_RW & (1 << 28)) + | (AT91C_EMAC_PHYA & ((PhyAddress & 0x1f) << 23)) + | (AT91C_EMAC_REGA & (Address << 18)) + | (AT91C_EMAC_DATA & Value) ; + if ( EMAC_WaitPhy(retry) == 0 ) { + + TRACE_ERROR("TimeOut EMAC_WritePhy\n\r"); + return 0; + } + return 1; +} + +//----------------------------------------------------------------------------- +/// Setup the EMAC for the link : speed 100M/10M and Full/Half duplex +/// \param speed Link speed, 0 for 10M, 1 for 100M +/// \param fullduplex 1 for Full Duplex mode +//----------------------------------------------------------------------------- +void EMAC_SetLinkSpeed(unsigned char speed, unsigned char fullduplex) +{ + unsigned int ncfgr; + + ncfgr = AT91C_BASE_EMAC->EMAC_NCFGR; + ncfgr &= ~(AT91C_EMAC_SPD | AT91C_EMAC_FD); + if (speed) { + + ncfgr |= AT91C_EMAC_SPD; + } + if (fullduplex) { + + ncfgr |= AT91C_EMAC_FD; + } + AT91C_BASE_EMAC->EMAC_NCFGR = ncfgr; +} + + + +//----------------------------------------------------------------------------- +// EMAC functions +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +/// EMAC Interrupt handler +//----------------------------------------------------------------------------- +void EMAC_Handler(void) +{ + volatile EmacTxTDescriptor *pTxTd; + volatile EMAC_TxCallback *pTxCb; + unsigned int isr; + unsigned int rsr; + unsigned int tsr; + unsigned int rxStatusFlag; + unsigned int txStatusFlag; + + //TRACE_DEBUG("EMAC_Handler\n\r"); + isr = AT91C_BASE_EMAC->EMAC_ISR & AT91C_BASE_EMAC->EMAC_IMR; + rsr = AT91C_BASE_EMAC->EMAC_RSR; + tsr = AT91C_BASE_EMAC->EMAC_TSR; + + // RX packet + if ((isr & AT91C_EMAC_RCOMP) || (rsr & AT91C_EMAC_REC)) { + rxStatusFlag = AT91C_EMAC_REC; + + // Frame received + EmacStatistics.rx_packets++; + + // Check OVR + if (rsr & AT91C_EMAC_OVR) { + rxStatusFlag |= AT91C_EMAC_OVR; + EmacStatistics.rx_ovrs++; + } + // Check BNA + if (rsr & AT91C_EMAC_BNA) { + rxStatusFlag |= AT91C_EMAC_BNA; + EmacStatistics.rx_bnas++; + } + // Clear status + AT91C_BASE_EMAC->EMAC_RSR |= rxStatusFlag; + + // Invoke callbacks + if (rxTd.rxCb) { + rxTd.rxCb(rxStatusFlag); + } + } + + // TX packet + if ((isr & AT91C_EMAC_TCOMP) || (tsr & AT91C_EMAC_COMP)) { + + txStatusFlag = AT91C_EMAC_COMP; + EmacStatistics.tx_comp ++; + + // A frame transmitted + // Check RLE + if (tsr & AT91C_EMAC_RLES) { + txStatusFlag |= AT91C_EMAC_RLES; + EmacStatistics.tx_errors++; + } + // Check COL + if (tsr & AT91C_EMAC_COL) { + txStatusFlag |= AT91C_EMAC_COL; + EmacStatistics.collisions++; + } + // Check BEX + if (tsr & AT91C_EMAC_BEX) { + txStatusFlag |= AT91C_EMAC_BEX; + EmacStatistics.tx_exausts++; + } + // Check UND + if (tsr & AT91C_EMAC_UND) { + txStatusFlag |= AT91C_EMAC_UND; + EmacStatistics.tx_underruns++; + } + // Clear status + AT91C_BASE_EMAC->EMAC_TSR |= txStatusFlag; + + // Sanity check: Tx buffers have to be scheduled + ASSERT(!CIRC_EMPTY(&txTd), + "-F- EMAC Tx interrupt received meanwhile no TX buffers has been scheduled\n\r"); + + // Check the buffers + while (CIRC_CNT(txTd.head, txTd.tail, TX_BUFFERS)) { + pTxTd = txTd.td + txTd.tail; + pTxCb = txTd.txCb + txTd.tail; + + // Exit if buffer has not been sent yet + if ((pTxTd->status & EMAC_TX_USED_BIT) == 0) { + break; + } + + // Notify upper layer that packet has been sent + if (*pTxCb) { + (*pTxCb)(txStatusFlag); + } + + CIRC_INC( txTd.tail, TX_BUFFERS ); + } + + // If a wakeup has been scheduled, notify upper layer that it can send + // other packets, send will be successfull. + if( (CIRC_SPACE(txTd.head, txTd.tail, TX_BUFFERS) >= txTd.wakeupThreshold) + && txTd.wakeupCb) { + txTd.wakeupCb(); + } + } +} + +//----------------------------------------------------------------------------- +/// Initialize the EMAC with the emac controller address +/// \param id HW ID for power management +/// \param pTxWakeUpfct Thresold TX Wakeup Callback +/// \param pRxfct RX Wakeup Callback +/// \param pMacAddress Mac Address +/// \param enableCAF enable AT91C_EMAC_CAF if needed by application +/// \param enableNBC AT91C_EMAC_NBC if needed by application +//----------------------------------------------------------------------------- +void EMAC_Init( unsigned char id, const unsigned char *pMacAddress, + unsigned char enableCAF, unsigned char enableNBC ) +{ + int Index; + unsigned int Address; + + // Check parameters + ASSERT(RX_BUFFERS * EMAC_RX_UNITSIZE > EMAC_FRAME_LENTGH_MAX, + "E: RX buffers too small\n\r"); + + TRACE_DEBUG("EMAC_Init\n\r"); + + // Power ON + AT91C_BASE_PMC->PMC_PCER = 1 << id; + + // Disable TX & RX and more + AT91C_BASE_EMAC->EMAC_NCR = 0; + + // disable + AT91C_BASE_EMAC->EMAC_IDR = ~0; + + rxTd.idx = 0; + CIRC_CLEAR(&txTd); + + // Setup the RX descriptors. + for(Index = 0; Index < RX_BUFFERS; Index++) { + + Address = (unsigned int)(&(pRxBuffer[Index * EMAC_RX_UNITSIZE])); + // Remove EMAC_RX_OWNERSHIP_BIT and EMAC_RX_WRAP_BIT + rxTd.td[Index].addr = Address & EMAC_ADDRESS_MASK; + rxTd.td[Index].status = 0; + } + rxTd.td[RX_BUFFERS - 1].addr |= EMAC_RX_WRAP_BIT; + + // Setup the TX descriptors. + for(Index = 0; Index < TX_BUFFERS; Index++) { + + Address = (unsigned int)(&(pTxBuffer[Index * EMAC_TX_UNITSIZE])); + txTd.td[Index].addr = Address; + txTd.td[Index].status = EMAC_TX_USED_BIT; + } + txTd.td[TX_BUFFERS - 1].status = EMAC_TX_USED_BIT | EMAC_TX_WRAP_BIT; + + // Set the MAC address + if( pMacAddress != (unsigned char *)0 ) { + AT91C_BASE_EMAC->EMAC_SA1L = ( ((unsigned int)pMacAddress[3] << 24) + | ((unsigned int)pMacAddress[2] << 16) + | ((unsigned int)pMacAddress[1] << 8 ) + | pMacAddress[0] ); + + AT91C_BASE_EMAC->EMAC_SA1H = ( ((unsigned int)pMacAddress[5] << 8 ) + | pMacAddress[4] ); + } + // Now setup the descriptors + // Receive Buffer Queue Pointer Register + AT91C_BASE_EMAC->EMAC_RBQP = (unsigned int) (rxTd.td); + // Transmit Buffer Queue Pointer Register + AT91C_BASE_EMAC->EMAC_TBQP = (unsigned int) (txTd.td); + + AT91C_BASE_EMAC->EMAC_NCR = AT91C_EMAC_CLRSTAT; + + // Clear all status bits in the receive status register. + AT91C_BASE_EMAC->EMAC_RSR = (AT91C_EMAC_OVR | AT91C_EMAC_REC | AT91C_EMAC_BNA); + + // Clear all status bits in the transmit status register + AT91C_BASE_EMAC->EMAC_TSR = ( AT91C_EMAC_UBR | AT91C_EMAC_COL | AT91C_EMAC_RLES + | AT91C_EMAC_BEX | AT91C_EMAC_COMP + | AT91C_EMAC_UND ); + + // Clear interrupts + AT91C_BASE_EMAC->EMAC_ISR; + + // Enable the copy of data into the buffers + // ignore broadcasts, and don't copy FCS. + AT91C_BASE_EMAC->EMAC_NCFGR |= (AT91C_EMAC_DRFCS | AT91C_EMAC_PAE); + + if( enableCAF == EMAC_CAF_ENABLE ) { + AT91C_BASE_EMAC->EMAC_NCFGR |= AT91C_EMAC_CAF; + } + if( enableNBC == EMAC_NBC_ENABLE ) { + AT91C_BASE_EMAC->EMAC_NCFGR |= AT91C_EMAC_NBC; + } + + // Enable Rx and Tx, plus the stats register. + AT91C_BASE_EMAC->EMAC_NCR |= (AT91C_EMAC_TE | AT91C_EMAC_RE | AT91C_EMAC_WESTAT); + + // Setup the interrupts for TX (and errors) + AT91C_BASE_EMAC->EMAC_IER = AT91C_EMAC_RXUBR + | AT91C_EMAC_TUNDR + | AT91C_EMAC_RLEX + | AT91C_EMAC_TXERR + | AT91C_EMAC_TCOMP + | AT91C_EMAC_ROVR + | AT91C_EMAC_HRESP; + +} + +//----------------------------------------------------------------------------- +/// Get the statstic information & reset it +/// \param pStats Pointer to EmacStats structure to copy the informations +/// \param reset Reset the statistics after copy it +//----------------------------------------------------------------------------- +void EMAC_GetStatistics(EmacStats *pStats, unsigned char reset) +{ + unsigned int ncrBackup = 0; + + TRACE_DEBUG("EMAC_GetStatistics\n\r"); + + // Sanity check + if (pStats == (EmacStats *) 0) { + return; + } + + ncrBackup = AT91C_BASE_EMAC->EMAC_NCR & (AT91C_EMAC_TE | AT91C_EMAC_RE); + + // Disable TX/RX + AT91C_BASE_EMAC->EMAC_NCR = ncrBackup & ~(AT91C_EMAC_TE | AT91C_EMAC_RE); + + // Copy the informations + memcpy(pStats, (void*)&EmacStatistics, sizeof(EmacStats)); + + // Reset the statistics + if (reset) { + memset((void*)&EmacStatistics, 0x00, sizeof(EmacStats)); + AT91C_BASE_EMAC->EMAC_NCR = ncrBackup | AT91C_EMAC_CLRSTAT; + } + + // restore NCR + AT91C_BASE_EMAC->EMAC_NCR = ncrBackup; +} + +//----------------------------------------------------------------------------- +/// Send a packet with EMAC. +/// If the packet size is larger than transfer buffer size error returned. +/// \param buffer The buffer to be send +/// \param size The size of buffer to be send +/// \param fEMAC_TxCallback Threshold Wakeup callback +/// \param fWakeUpCb TX Wakeup +/// \return OK, Busy or invalid packet +//----------------------------------------------------------------------------- +unsigned char EMAC_Send(void *pBuffer, + unsigned int size, + EMAC_TxCallback fEMAC_TxCallback) +{ + volatile EmacTxTDescriptor *pTxTd; + volatile EMAC_TxCallback *pTxCb; + + //TRACE_DEBUG("EMAC_Send\n\r"); + + // Check parameter + if (size > EMAC_TX_UNITSIZE) { + + TRACE_ERROR("EMAC driver does not split send packets."); + TRACE_ERROR(" It can send %d bytes max in one packet (%d bytes requested)\n\r", + EMAC_TX_UNITSIZE, size); + return EMAC_TX_INVALID_PACKET; + } + + // If no free TxTd, buffer can't be sent, schedule the wakeup callback + if( CIRC_SPACE(txTd.head, txTd.tail, TX_BUFFERS) == 0) { + return EMAC_TX_BUFFER_BUSY; + + } + + // Pointers to the current TxTd + pTxTd = txTd.td + txTd.head; + pTxCb = txTd.txCb + txTd.head; + + // Sanity check + ASSERT((pTxTd->status & EMAC_TX_USED_BIT) != 0, + "-F- Buffer is still under EMAC control\n\r"); + + // Setup/Copy data to transmition buffer + if (pBuffer && size) { + // Driver manage the ring buffer + memcpy((void *)pTxTd->addr, pBuffer, size); + } + + // Tx Callback + *pTxCb = fEMAC_TxCallback; + + // Update TD status + // The buffer size defined is length of ethernet frame + // so it's always the last buffer of the frame. + if (txTd.head == TX_BUFFERS-1) { + pTxTd->status = + (size & EMAC_LENGTH_FRAME) | EMAC_TX_LAST_BUFFER_BIT | EMAC_TX_WRAP_BIT; + } + else { + pTxTd->status = (size & EMAC_LENGTH_FRAME) | EMAC_TX_LAST_BUFFER_BIT; + } + + CIRC_INC(txTd.head, TX_BUFFERS) + + // Tx packets count + EmacStatistics.tx_packets++; + + // Now start to transmit if it is not already done + AT91C_BASE_EMAC->EMAC_NCR |= AT91C_EMAC_TSTART; + + return EMAC_TX_OK; +} + +//----------------------------------------------------------------------------- +/// Receive a packet with EMAC +/// If not enough buffer for the packet, the remaining data is lost but right +/// frame length is returned. +/// \param pFrame Buffer to store the frame +/// \param frameSize Size of the frame +/// \param pRcvSize Received size +/// \return OK, no data, or frame too small +//----------------------------------------------------------------------------- +unsigned char EMAC_Poll(unsigned char *pFrame, + unsigned int frameSize, + unsigned int *pRcvSize) +{ + unsigned short bufferLength; + unsigned int tmpFrameSize=0; + unsigned char *pTmpFrame=0; + unsigned int tmpIdx = rxTd.idx; + volatile EmacRxTDescriptor *pRxTd = rxTd.td + rxTd.idx; + + ASSERT(pFrame, "F: EMAC_Poll\n\r"); + + char isFrame = 0; + // Set the default return value + *pRcvSize = 0; + + // Process received RxTd + while ((pRxTd->addr & EMAC_RX_OWNERSHIP_BIT) == EMAC_RX_OWNERSHIP_BIT) { + + // A start of frame has been received, discard previous fragments + if ((pRxTd->status & EMAC_RX_SOF_BIT) == EMAC_RX_SOF_BIT) { + // Skip previous fragment + while (tmpIdx != rxTd.idx) { + pRxTd = rxTd.td + rxTd.idx; + pRxTd->addr &= ~(EMAC_RX_OWNERSHIP_BIT); + CIRC_INC(rxTd.idx, RX_BUFFERS); + } + // Reset the temporary frame pointer + pTmpFrame = pFrame; + tmpFrameSize = 0; + // Start to gather buffers in a frame + isFrame = 1; + } + + // Increment the pointer + CIRC_INC(tmpIdx, RX_BUFFERS); + + // Copy data in the frame buffer + if (isFrame) { + if (tmpIdx == rxTd.idx) { + TRACE_INFO("no EOF (Invalid of buffers too small)\n\r"); + + do { + + pRxTd = rxTd.td + rxTd.idx; + pRxTd->addr &= ~(EMAC_RX_OWNERSHIP_BIT); + CIRC_INC(rxTd.idx, RX_BUFFERS); + } while(tmpIdx != rxTd.idx); + return EMAC_RX_NO_DATA; + } + // Copy the buffer into the application frame + bufferLength = EMAC_RX_UNITSIZE; + if ((tmpFrameSize + bufferLength) > frameSize) { + bufferLength = frameSize - tmpFrameSize; + } + + memcpy(pTmpFrame, (void*)(pRxTd->addr & EMAC_ADDRESS_MASK), bufferLength); + pTmpFrame += bufferLength; + tmpFrameSize += bufferLength; + + // An end of frame has been received, return the data + if ((pRxTd->status & EMAC_RX_EOF_BIT) == EMAC_RX_EOF_BIT) { + // Frame size from the EMAC + *pRcvSize = (pRxTd->status & EMAC_LENGTH_FRAME); + + // Application frame buffer is too small all data have not been copied + if (tmpFrameSize < *pRcvSize) { + printf("size req %d size allocated %d\n\r", *pRcvSize, frameSize); + + return EMAC_RX_FRAME_SIZE_TOO_SMALL; + } + + TRACE_DEBUG("packet %d-%d (%d)\n\r", rxTd.idx, tmpIdx, *pRcvSize); + // All data have been copied in the application frame buffer => release TD + while (rxTd.idx != tmpIdx) { + pRxTd = rxTd.td + rxTd.idx; + pRxTd->addr &= ~(EMAC_RX_OWNERSHIP_BIT); + CIRC_INC(rxTd.idx, RX_BUFFERS); + } + EmacStatistics.rx_packets++; + return EMAC_RX_OK; + } + } + + // SOF has not been detected, skip the fragment + else { + pRxTd->addr &= ~(EMAC_RX_OWNERSHIP_BIT); + rxTd.idx = tmpIdx; + } + + // Process the next buffer + pRxTd = rxTd.td + tmpIdx; + } + + //TRACE_DEBUG("E"); + return EMAC_RX_NO_DATA; +} + +//----------------------------------------------------------------------------- +/// Registers pRxCb callback. Callback will be invoked after the next received +/// frame. +/// When EMAC_Poll() returns EMAC_RX_NO_DATA the application task call EMAC_Set_RxCb() +/// to register pRxCb() callback and enters suspend state. The callback is in charge +/// to resume the task once a new frame has been received. The next time EMAC_Poll() +/// is called, it will be successfull. +/// \param pRxCb Pointer to callback function +//----------------------------------------------------------------------------- +void EMAC_Set_RxCb(EMAC_RxCallback pRxCb) +{ + rxTd.rxCb = pRxCb; + AT91C_BASE_EMAC->EMAC_IER = AT91C_EMAC_RCOMP; +} + +//----------------------------------------------------------------------------- +/// Remove the RX callback function. +/// This function is usually invoked from the RX callback itself. Once the callback +/// has resumed the application task, there is no need to invoke the callback again. +//----------------------------------------------------------------------------- +void EMAC_Clear_RxCb(void) +{ + AT91C_BASE_EMAC->EMAC_IDR = AT91C_EMAC_RCOMP; + rxTd.rxCb = (EMAC_RxCallback) 0; +} + +//----------------------------------------------------------------------------- +/// Registers TX wakeup callback callback. Callback will be invoked once several +/// transfer descriptors are available. +/// When EMAC_Send() returns EMAC_TX_BUFFER_BUSY (all TD busy) the application +/// task calls EMAC_Set_TxWakeUpCb() to register pTxWakeUpCb() callback and +/// enters suspend state. The callback is in charge to resume the task once +/// several TD have been released. The next time EMAC_Send() will be called, it +/// shall be successfull. +/// \param pTxWakeUpCb Pointer to callback function +/// \param threshold Minimum number of available transfer descriptors before pTxWakeUpCb() is invoked +/// \return 0= success, 1 = threshold exceeds nuber of transfer descriptors +//----------------------------------------------------------------------------- +char EMAC_Set_TxWakeUpCb(EMAC_WakeupCallback pTxWakeUpCb, unsigned short threshold) +{ + if (threshold <= TX_BUFFERS) { + txTd.wakeupCb = pTxWakeUpCb; + txTd.wakeupThreshold = threshold; + return 0; + } + return 1; +} + +//----------------------------------------------------------------------------- +/// Remove the TX wakeup callback function. +/// This function is usually invoked from the TX wakeup callback itself. Once the callback +/// has resumed the application task, there is no need to invoke the callback again. +//----------------------------------------------------------------------------- +void EMAC_Clear_TxWakeUpCb(void) +{ + txTd.wakeupCb = (EMAC_WakeupCallback) 0; +} + + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/emac/emac.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/emac/emac.h new file mode 100644 index 000000000..ccaa53926 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/emac/emac.h @@ -0,0 +1,163 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +// peripherals/emac/emac.h + +#ifndef EMAC_H +#define EMAC_H + +//----------------------------------------------------------------------------- +/// \dir +/// !Purpose +/// +/// Definition of methods and structures for using EMAC +/// +/// !Usage +/// +/// -# Initialize EMAC with EMAC_Init with MAC address. +/// -# Then the caller application need to initialize the PHY driver before further calling EMAC +/// driver. +/// -# Get a packet from network +/// -# Interrupt mode: EMAC_Set_RxCb to register a function to process the frame packet +/// -# Polling mode: EMAC_Poll for a data packet from network +/// -# Send a packet to network with EMAC_Send. +/// +/// Please refer to the list of functions in the #Overview# tab of this unit +/// for more detailed information. +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Definitions +//----------------------------------------------------------------------------- +/// Number of buffer for RX, be carreful: MUST be 2^n +#define RX_BUFFERS 16 +/// Number of buffer for TX, be carreful: MUST be 2^n +#define TX_BUFFERS 8 + +/// Buffer Size +#define EMAC_RX_UNITSIZE 128 /// Fixed size for RX buffer +#define EMAC_TX_UNITSIZE 1518 /// Size for ETH frame length + +// The MAC can support frame lengths up to 1536 bytes. +#define EMAC_FRAME_LENTGH_MAX 1536 + + +//----------------------------------------------------------------------------- +// Types +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +/// Describes the statistics of the EMAC. +//----------------------------------------------------------------------------- +typedef struct _EmacStats { + + // TX errors + unsigned int tx_packets; /// Total Number of packets sent + unsigned int tx_comp; /// Packet complete + unsigned int tx_errors; /// TX errors ( Retry Limit Exceed ) + unsigned int collisions; /// Collision + unsigned int tx_exausts; /// Buffer exhausted + unsigned int tx_underruns; /// Under Run, not able to read from memory + // RX errors + unsigned int rx_packets; /// Total Number of packets RX + unsigned int rx_eof; /// No EOF error + unsigned int rx_ovrs; /// Over Run, not able to store to memory + unsigned int rx_bnas; /// Buffer is not available + +} EmacStats, *PEmacStats; + +//----------------------------------------------------------------------------- +// PHY Exported functions +//----------------------------------------------------------------------------- +extern unsigned char EMAC_SetMdcClock( unsigned int mck ); + +extern void EMAC_EnableMdio( void ); + +extern void EMAC_DisableMdio( void ); + +extern void EMAC_EnableMII( void ); + +extern void EMAC_EnableRMII( void ); + +extern unsigned char EMAC_ReadPhy(unsigned char PhyAddress, + unsigned char Address, + unsigned int *pValue, + unsigned int retry); + +extern unsigned char EMAC_WritePhy(unsigned char PhyAddress, + unsigned char Address, + unsigned int Value, + unsigned int retry); + +extern void EMAC_SetLinkSpeed(unsigned char speed, + unsigned char fullduplex); + +//----------------------------------------------------------------------------- +// EMAC Exported functions +//----------------------------------------------------------------------------- +/// Callback used by send function +typedef void (*EMAC_TxCallback)(unsigned int status); +typedef void (*EMAC_RxCallback)(unsigned int status); +typedef void (*EMAC_WakeupCallback)(void); + +extern void EMAC_Init( unsigned char id, const unsigned char *pMacAddress, + unsigned char enableCAF, unsigned char enableNBC ); +#define EMAC_CAF_DISABLE 0 +#define EMAC_CAF_ENABLE 1 +#define EMAC_NBC_DISABLE 0 +#define EMAC_NBC_ENABLE 1 + +extern void EMAC_Handler(void); + +extern unsigned char EMAC_Send(void *pBuffer, + unsigned int size, + EMAC_TxCallback fEMAC_TxCallback); +/// Return for EMAC_Send function +#define EMAC_TX_OK 0 +#define EMAC_TX_BUFFER_BUSY 1 +#define EMAC_TX_INVALID_PACKET 2 + + +extern unsigned char EMAC_Poll(unsigned char *pFrame, + unsigned int frameSize, + unsigned int *pRcvSize); +/// Return for EMAC_Poll function +#define EMAC_RX_OK 0 +#define EMAC_RX_NO_DATA 1 +#define EMAC_RX_FRAME_SIZE_TOO_SMALL 2 + +extern void EMAC_GetStatistics(EmacStats *pStats, unsigned char reset); + +#endif // #ifndef EMAC_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/irq/irq.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/irq/irq.h new file mode 100644 index 000000000..b85990c30 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/irq/irq.h @@ -0,0 +1,82 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Methods and definitions for configuring interrupts. +/// +/// !Usage +/// +/// -# Configure an interrupt source using IRQ_ConfigureIT +/// -# Enable or disable interrupt generation of a particular source with +/// IRQ_EnableIT and IRQ_DisableIT. +/// +/// \note Most of the time, peripheral interrupts must be also configured +/// inside the peripheral itself. +//------------------------------------------------------------------------------ + +#ifndef IRQ_H +#define IRQ_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include +#if defined(cortexm3) +#include +#endif + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ +#if defined(cortexm3) +#ifdef __NVIC_PRIO_BITS +#undef __NVIC_PRIO_BITS +#define __NVIC_PRIO_BITS ((SCB->AIRCR & 0x700) >> 8) +#endif +#endif + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void IRQ_ConfigureIT(unsigned int source, + unsigned int mode, // mode for AIC, priority for NVIC + void( *handler )( void )); // ISR + +extern void IRQ_EnableIT(unsigned int source); + +extern void IRQ_DisableIT(unsigned int source); + +#endif //#ifndef IRQ_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/irq/nvic.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/irq/nvic.c new file mode 100644 index 000000000..1e61aa12e --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/irq/nvic.c @@ -0,0 +1,144 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "board.h" +#include "irq.h" +#include "exceptions.h" +#include + +/// The index of IRQ handler in the exception table +#define NVIC_IRQ_HANDLER_INDEX 16 + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Configures an interrupt in the NVIC. The interrupt is identified by its +/// source (AT91C_ID_xxx) and is configured to a specified priority and +/// interrupt handler function. priority is the value that will be put in NVIC_IPRx +/// and the function address will be set in "ExceptionTable". The parameter priority +/// will include the preemptionPriority and the subPriority, where the subPriority +/// defined in the B[7:0] of the parameter "priority", and the preemptionPriority defined +/// in the B[15:8] of the parameter "priority". +/// The interrupt is disabled before configuration, so it is useless +/// to do it before calling this function. When NVIC_ConfigureIT returns, the +/// interrupt will always be disabled and cleared; it must be enabled by a +/// call to NVIC_EnableIT(). +/// \param source Interrupt source to configure. +/// \param priority Pre-emption priority (B[15:8] )+ subPriority (B[7:0]) +/// \param handler Interrupt handler function. +//------------------------------------------------------------------------------ +void IRQ_ConfigureIT( + unsigned int source, + //unsigned int preemptionPriority, + //unsigned int subPriority, + unsigned int priority, + IntFunc handler) +{ + unsigned int priGroup = __NVIC_PRIO_BITS; + unsigned int nPre = 7 - priGroup; + unsigned int nSub = priGroup + 1; + unsigned int preemptionPriority; + unsigned int subPriority; + unsigned int IRQpriority; + + preemptionPriority = (priority & 0xff00) >> 8; + subPriority = (priority & 0xff); + + // Disable the interrupt first + NVIC_DisableIRQ((IRQn_Type)source); + + // Clear any pending status + NVIC_ClearPendingIRQ((IRQn_Type)source); + + // Configure interrupt handler + //if (handler == 0) handler = IrqHandlerNotUsed; + // GetExceptionTable()[NVIC_IRQ_HANDLER_INDEX + source] = handler; + + if (subPriority >= (0x01 << nSub)) + subPriority = (0x01 << nSub) - 1; + if (preemptionPriority >= (0x01 << nPre)) + preemptionPriority = (0x01 << nPre) - 1; + + IRQpriority = (subPriority | (preemptionPriority << nSub)); + NVIC_SetPriority((IRQn_Type)source, IRQpriority); +} + +//------------------------------------------------------------------------------ +/// Enables interrupt coming from the given (unique) source (AT91C_ID_xxx). +/// \param source Interrupt source to enable. +//------------------------------------------------------------------------------ +void IRQ_EnableIT(unsigned int source) +{ + NVIC_EnableIRQ((IRQn_Type)source); +} + +//------------------------------------------------------------------------------ +/// Disables interrupt coming from the given (unique) source (AT91C_ID_xxx). +/// \param source Interrupt source to disable. +//------------------------------------------------------------------------------ +void IRQ_DisableIT(unsigned int source) +{ + NVIC_DisableIRQ((IRQn_Type)source); +} + +//------------------------------------------------------------------------------ +/// Set interrupt pending bit from the given (unique) source (AT91C_ID_xxx). +/// \param source Interrupt source to set. +//------------------------------------------------------------------------------ +void NVIC_SetPending(unsigned int source) +{ + NVIC_SetPendingIRQ((IRQn_Type)source); +} + +//------------------------------------------------------------------------------ +/// Clear interrupt pending bit from the given (unique) source (AT91C_ID_xxx). +/// \param source Interrupt source to clear. +//------------------------------------------------------------------------------ +void NVIC_ClrPending(unsigned int source) +{ + NVIC_ClearPendingIRQ((IRQn_Type)source); +} + +#if !defined(USE_CMSIS_on) +//------------------------------------------------------------------------------ +/// Use the Software Trigger Interrupt Register to pend an interrupt. +/// \param source Interrupt source to trigger. +//------------------------------------------------------------------------------ +void NVIC_Swi(unsigned int source) +{ + AT91C_BASE_NVIC->NVIC_STIR = source; +} +#endif + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/isi/isi.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/isi/isi.c new file mode 100644 index 000000000..05feb4bad --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/isi/isi.c @@ -0,0 +1,261 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Image Sensor Interface (ISI) driver +/// +/// !Usage +/// +/// Explanation on the usage of the code made available through the header file. +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include +#include +#include +#include "isi.h" + +#if !defined (BOARD_ISI_V200) + +//----------------------------------------------------------------------------- +/// Enable ISI +//----------------------------------------------------------------------------- +void ISI_Enable(void) +{ + AT91C_BASE_ISI->ISI_CR1 &= ~AT91C_ISI_DIS; +} + +//----------------------------------------------------------------------------- +/// Disable ISI +//----------------------------------------------------------------------------- +void ISI_Disable(void) +{ + AT91C_BASE_ISI->ISI_CR1 |= AT91C_ISI_DIS; +} + +//----------------------------------------------------------------------------- +/// Enable ISI interrupt +/// \param flag of interrupt to enable +//----------------------------------------------------------------------------- +void ISI_EnableInterrupt(unsigned int flag) +{ + AT91C_BASE_ISI->ISI_IER = flag; +} + +//----------------------------------------------------------------------------- +/// Disable ISI interrupt +/// \param flag of interrupt to disable +//----------------------------------------------------------------------------- +void ISI_DisableInterrupt(unsigned int flag) +{ + AT91C_BASE_ISI->ISI_IDR = flag; +} + +//----------------------------------------------------------------------------- +/// Return ISI status register +/// \return Status of ISI register +//----------------------------------------------------------------------------- +unsigned int ISI_StatusRegister(void) +{ + return(AT91C_BASE_ISI->ISI_SR); +} + +//----------------------------------------------------------------------------- +/// Enable Codec path for capture next frame +//----------------------------------------------------------------------------- +void ISI_CodecPathFull(void) +{ + // The codec path is enabled and the next frame is captured. + // Both codec and preview datapaths are working simultaneously + AT91C_BASE_ISI->ISI_CR1 |= AT91C_ISI_CODEC_ON | AT91C_ISI_FULL; +} + +//----------------------------------------------------------------------------- +/// Set frame rate +/// \param frate frame rate capture +/// \return +//----------------------------------------------------------------------------- +void ISI_SetFrame(unsigned int frate) +{ + if( frate > 7 ) { + TRACE_ERROR("FRate too big\n\r"); + frate = 7; + } + AT91C_BASE_ISI->ISI_CR1 |= ((frate<<8) & AT91C_ISI_FRATE); +} + +//----------------------------------------------------------------------------- +/// Get the number of byte per pixels +/// \param bmpRgb BMP type can be YUV or RGB +/// \return Number of byte for one pixel +//----------------------------------------------------------------------------- +unsigned char ISI_BytesForOnePixel(unsigned char bmpRgb) +{ + unsigned char nbByte_Pixel; + + if (bmpRgb == RGB) { + if ((AT91C_BASE_ISI->ISI_CR2 & AT91C_ISI_RGB_MODE) == AT91C_ISI_RGB_MODE_RGB_565){ + // RGB: 5:6:5 16bits/pixels + nbByte_Pixel = 2; + } + else { + // RGB: 8:8:8 24bits/pixels + nbByte_Pixel = 3; + } + } + else { + // YUV: 2 pixels for 4 bytes + nbByte_Pixel = 2; + } + return nbByte_Pixel; +} + +//----------------------------------------------------------------------------- +/// Reset ISI +//----------------------------------------------------------------------------- +void ISI_Reset(void) +{ + unsigned int timeout=0; + + // Resets the image sensor interface. + // Finish capturing the current frame and then shut down the module. + AT91C_BASE_ISI->ISI_CR1 = AT91C_ISI_RST | AT91C_ISI_DIS; + // wait Software reset has completed successfully. + while( (!(volatile int)AT91C_BASE_ISI->ISI_SR & AT91C_ISI_SOFTRST) + && (timeout < 0x5000) ){ + timeout++; + } + if( timeout == 0x5000 ) { + TRACE_ERROR("ISI-Reset timeout\n\r"); + } +} + +//----------------------------------------------------------------------------- +/// ISI initialize with the pVideo parameters. +/// By default, put ISI in RGB mode 565, YCC mode 3, different value for +/// Color Space Conversion Matrix Coefficient +/// \param pVideo structure of video driver +//----------------------------------------------------------------------------- +void ISI_Init(AT91PS_VIDEO pVideo) +{ + ISI_Reset(); + + // AT91C_ISI_HSYNC_POL Horizontal synchronisation polarity + // AT91C_ISI_VSYNC_POL Vertical synchronisation polarity + // AT91C_ISI_PIXCLK_POL Pixel Clock Polarity + + // SLD pixel clock periods to wait before the beginning of a line. + // SFD lines are skipped at the beginning of the frame. + AT91C_BASE_ISI->ISI_CR1 |= ((pVideo->Hblank << 16) & AT91C_ISI_SLD) + + ((pVideo->Vblank << 24) & AT91C_ISI_SFD); + TRACE_DEBUG("ISI_CR1=0x%X\n\r", AT91C_BASE_ISI->ISI_CR1); + + // IM_VSIZE: Vertical size of the Image sensor [0..2047] + // Vertical size = IM_VSIZE + 1 + // IM_HSIZE: Horizontal size of the Image sensor [0..2047] + // Horizontal size = IM_HSIZE + 1 + // YCC_SWAP : YCC image data + AT91C_BASE_ISI->ISI_CR2 = ((pVideo->codec_vsize-1) & AT91C_ISI_IM_VSIZE) + + (((pVideo->codec_hsize-1) << 16) & AT91C_ISI_IM_HSIZE) + + AT91C_ISI_YCC_SWAP_YCC_MODE2; + + if (pVideo->rgb_or_yuv == RGB) { + AT91C_BASE_ISI->ISI_CR2 |= AT91C_ISI_COL_SPACE | AT91C_ISI_RGB_MODE_RGB_565 + | AT91C_ISI_RGB_CFG_RGB_DEFAULT; + } + else { + // AT91C_BASE_HISI->ISI_CR2 &= ~AT91C_ISI_COL_SPACE; + } + TRACE_DEBUG("ISI_CR2=0x%X\n\r", AT91C_BASE_ISI->ISI_CR2); + + // Vertical Preview size = PREV_VSIZE + 1 (480 max only in RGB mode). + // Horizontal Preview size = PREV_HSIZE + 1 (640 max only in RGB mode). +#if defined (AT91C_ID_LCDC) + if( (pVideo->lcd_vsize > 480) || (pVideo->lcd_hsize > 640)) { + TRACE_ERROR("Size LCD bad define\n\r"); + AT91C_BASE_ISI->ISI_PSIZE = ((BOARD_LCD_HEIGHT-1) & AT91C_ISI_PREV_VSIZE) + + (((BOARD_LCD_WIDTH-1) << 16) & AT91C_ISI_PREV_HSIZE); + } + else { + + AT91C_BASE_ISI->ISI_PSIZE = ((pVideo->lcd_vsize -1) & AT91C_ISI_PREV_VSIZE) + + (((pVideo->lcd_hsize -1) << 16) & AT91C_ISI_PREV_HSIZE); + } +#endif + + + // DEC_FACTOR is 8-bit width, range is from 16 to 255. + // Values from 0 to 16 do not perform any decimation. + AT91C_BASE_ISI->ISI_PDECF = (16 * pVideo->codec_hsize) / pVideo->lcd_hsize; + + TRACE_DEBUG("codec_hsize: %d\n\r", pVideo->codec_hsize); + TRACE_DEBUG("lcd_hsize: %d\n\r", pVideo->lcd_hsize); + TRACE_DEBUG("ISI_PDECF: %d\n\r", AT91C_BASE_ISI->ISI_PDECF); + if( AT91C_BASE_ISI->ISI_PDECF <16) { + TRACE_ERROR("ISI_PDECF, forbidden value: %d\n\r", AT91C_BASE_ISI->ISI_PDECF); + AT91C_BASE_ISI->ISI_PDECF = 16; + } + + // Written with the address of the start of the preview frame buffer queue, + // reads as a pointer to the current buffer being used. + // The frame buffer is forced to word alignment. + AT91C_BASE_ISI->ISI_PPFBD = pVideo->Isi_fbd_base; + + // This register contains codec datapath start address of buffer location. + // CODEC_DMA_ADDR: Base address for codec DMA + AT91C_BASE_ISI->ISI_CDBA = pVideo->codec_fb_addr; + + // C0: Color Space Conversion Matrix Coefficient C0 + // C1: Color Space Conversion Matrix Coefficient C1 + // C2: Color Space Conversion Matrix Coefficient C2 + // C3: Color Space Conversion Matrix Coefficient C3 + AT91C_BASE_ISI->ISI_Y2RSET0 = ( (0x95<< 0) & AT91C_ISI_Y2R_C0) + + ( (0xFF<< 8) & AT91C_ISI_Y2R_C1) + + ( (0x68<<16) & AT91C_ISI_Y2R_C2) + + ( (0x32<<24) & AT91C_ISI_Y2R_C3); + + // C4: Color Space Conversion Matrix coefficient C4 + // Yoff: Color Space Conversion Luminance 128 offset + // Croff: Color Space Conversion Red Chrominance 16 offset + // Cboff: Color Space Conversion Blue Chrominance 16 offset + AT91C_BASE_ISI->ISI_Y2RSET1 = ( (0xCC<< 0) & AT91C_ISI_Y2R_C4) + + ( AT91C_ISI_Y2R_YOFF_128) + + ( AT91C_ISI_Y2R_CROFF_16) + + ( AT91C_ISI_Y2R_CBOFF_16); +} + +#endif // !defined (BOARD_ISI_V200) + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/isi/isi.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/isi/isi.h new file mode 100644 index 000000000..0a8143713 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/isi/isi.h @@ -0,0 +1,99 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Interface for configuration the Image Sensor Interface (ISI) peripheral. +/// +/// !Usage +/// +/// -# ISI_Init: initialize ISI with default parameters +/// -# ISI_EnableInterrupt: enable one or more interrupts +/// -# ISI_DisableInterrupt: disable one or more interrupts +/// -# ISI_Enable: enable isi module +/// -# ISI_Disable: disable isi module +/// -# ISI_CodecPathFull: enable codec path +/// -# ISI_SetFrame: set frame rate +/// -# ISI_BytesForOnePixel: return number of byte for one pixel +/// -# ISI_StatusRegister: return ISI status register +/// -# ISI_Reset: make a software reset +//------------------------------------------------------------------------------ + +#ifndef ISI_H +#define ISI_H + +//------------------------------------------------------------------------------ +// Types +//------------------------------------------------------------------------------ + +/// ISI descriptors +typedef struct +{ + /// Current LCD index, used with AT91C_ISI_MAX_PREV_BUFFER + unsigned int CurrentLcdIndex; + /// set if Fifo Codec Empty is present + volatile unsigned int DisplayCodec; + /// upgrade for each Fifo Codec Overflow (statistics use) + unsigned int nb_codec_ovf; + /// upgrade for each Fifo Preview Overflow (statistics use) + unsigned int nb_prev_ovf; +}ISI_Descriptors; + +/// Frame Buffer Descriptors +typedef struct +{ + /// Address of the Current FrameBuffer + unsigned int Current; +#if defined (BOARD_ISI_V200) + /// Address of the Control + unsigned int Control; +#endif + /// Address of the Next FrameBuffer + unsigned int Next; +}ISI_FrameBufferDescriptors; + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +extern void ISI_Enable(void); +extern void ISI_Disable(void); +extern void ISI_EnableInterrupt(unsigned int flag); +extern void ISI_DisableInterrupt(unsigned int flag); +extern void ISI_CodecPathFull(void); +extern void ISI_SetFrame(unsigned int frate); +extern unsigned char ISI_BytesForOnePixel(unsigned char bmpRgb); +extern void ISI_Reset(void); +extern void ISI_Init(AT91PS_VIDEO pVideo); +extern unsigned int ISI_StatusRegister(void); + +#endif //#ifndef ISI_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/isi/isi2.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/isi/isi2.c new file mode 100644 index 000000000..9ed61f89c --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/isi/isi2.c @@ -0,0 +1,246 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include +#include +#include +#include "isi.h" + +#if defined (BOARD_ISI_V200) + +//----------------------------------------------------------------------------- +/// Enable ISI +//----------------------------------------------------------------------------- +void ISI_Enable(void) +{ + AT91C_BASE_ISI->ISI_CTRL |= AT91C_ISI_EN_1; + while( (AT91C_BASE_ISI->ISI_SR & AT91C_ISI_EN_1)!=AT91C_ISI_EN_1); + AT91C_BASE_ISI->ISI_DMACHER |= AT91C_ISI_P_CH_EN_1; +} + +//----------------------------------------------------------------------------- +/// Disable ISI +//----------------------------------------------------------------------------- +void ISI_Disable(void) +{ + AT91C_BASE_ISI->ISI_CTRL |= AT91C_ISI_DIS_1; + AT91C_BASE_ISI->ISI_DMACHDR &= ~AT91C_ISI_P_CH_DIS_1; +} + +//----------------------------------------------------------------------------- +/// Enable ISI interrupt +/// \param flag of interrupt to enable +//----------------------------------------------------------------------------- +void ISI_EnableInterrupt(unsigned int flag) +{ + AT91C_BASE_ISI->ISI_IER = flag; +} + +//----------------------------------------------------------------------------- +/// Disable ISI interrupt +/// \param flag of interrupt to disable +//----------------------------------------------------------------------------- +void ISI_DisableInterrupt(unsigned int flag) +{ + AT91C_BASE_ISI->ISI_IDR = flag; +} + +//----------------------------------------------------------------------------- +/// Return ISI status register +/// \return Status of ISI register +//----------------------------------------------------------------------------- +unsigned int ISI_StatusRegister(void) +{ + return(AT91C_BASE_ISI->ISI_SR); +} + +//----------------------------------------------------------------------------- +/// Enable Codec path for capture next frame +//----------------------------------------------------------------------------- +void ISI_CodecPathFull(void) +{ + // The codec path is enabled and the next frame is captured. + // Both codec and preview datapaths are working simultaneously + AT91C_BASE_ISI->ISI_CTRL |= AT91C_ISI_CDC_1; + AT91C_BASE_ISI->ISI_CFG1 |= AT91C_ISI_FULL; +} + +//----------------------------------------------------------------------------- +/// Set frame rate +/// \param frate frame rate capture +/// \return +//----------------------------------------------------------------------------- +void ISI_SetFrame(unsigned int frate) +{ + if( frate > 7 ) { + TRACE_ERROR("FRate too big\n\r"); + frate = 7; + } + AT91C_BASE_ISI->ISI_CFG1 |= ((frate<<8) & AT91C_ISI_FRATE); +} + +//----------------------------------------------------------------------------- +/// Get the number of byte per pixels +/// \param bmpRgb BMP type can be YUV or RGB +/// \return Number of byte for one pixel +//----------------------------------------------------------------------------- +unsigned char ISI_BytesForOnePixel(unsigned char bmpRgb) +{ + unsigned char nbByte_Pixel; + + if (bmpRgb == RGB) { + if ((AT91C_BASE_ISI->ISI_CFG2 & AT91C_ISI_RGB_MODE) == AT91C_ISI_RGB_MODE_RGB_565){ + // RGB: 5:6:5 16bits/pixels + nbByte_Pixel = 2; + } + else { + // RGB: 8:8:8 24bits/pixels + nbByte_Pixel = 3; + } + } + else { + // YUV: 2 pixels for 4 bytes + nbByte_Pixel = 2; + } + return nbByte_Pixel; +} + +//----------------------------------------------------------------------------- +/// Reset ISI +//----------------------------------------------------------------------------- +void ISI_Reset(void) +{ + unsigned int timeout=0; + + // Resets the image sensor interface. + // Finish capturing the current frame and then shut down the module. + AT91C_BASE_ISI->ISI_CTRL = AT91C_ISI_SRST_1 | AT91C_ISI_DIS_1; + // wait Software reset has completed successfully. + while( (!(volatile int)AT91C_BASE_ISI->ISI_SR & AT91C_ISI_SRST) + && (timeout < 0x5000) ){ + timeout++; + } + if( timeout == 0x5000 ) { + TRACE_ERROR("ISI-Reset timeout\n\r"); + } +} + +//----------------------------------------------------------------------------- +/// ISI initialize +/// \param pVideo structure of video driver +//----------------------------------------------------------------------------- +void ISI_Init(AT91PS_VIDEO pVideo) +{ + ISI_Reset(); + + // AT91C_ISI_HSYNC_POL Horizontal synchronisation polarity + // AT91C_ISI_VSYNC_POL Vertical synchronisation polarity + // AT91C_ISI_PIXCLK_POL Pixel Clock Polarity + + // SLD pixel clock periods to wait before the beginning of a line. + // SFD lines are skipped at the beginning of the frame. + AT91C_BASE_ISI->ISI_CFG1 |= ((pVideo->Hblank << 16) & AT91C_ISI_SLD) + + ((pVideo->Vblank << 24) & AT91C_ISI_SFD); + TRACE_DEBUG("ISI_CFG1=0x%X\n\r", AT91C_BASE_ISI->ISI_CFG1); + + // IM_VSIZE: Vertical size of the Image sensor [0..2047] + // Vertical size = IM_VSIZE + 1 + // IM_HSIZE: Horizontal size of the Image sensor [0..2047] + // Horizontal size = IM_HSIZE + 1 + // YCC_SWAP : YCC image data + AT91C_BASE_ISI->ISI_CFG2 = ((pVideo->codec_vsize-1) & AT91C_ISI_IM_VSIZE) + + (((pVideo->codec_hsize-1) << 16) & AT91C_ISI_IM_HSIZE) + + AT91C_ISI_YCC_SWAP_YCC_MODE2; + + if (pVideo->rgb_or_yuv == RGB) { + AT91C_BASE_ISI->ISI_CFG2 |= AT91C_ISI_COL_SPACE | AT91C_ISI_RGB_MODE_RGB_565 + | AT91C_ISI_RGB_CFG_RGB_DEFAULT; + } + else { + // AT91C_BASE_HISI->ISI_CFG2 &= ~AT91C_ISI_COL_SPACE; + } + TRACE_DEBUG("ISI_CFG2=0x%X\n\r", AT91C_BASE_ISI->ISI_CFG2); + + // Vertical Preview size = PREV_VSIZE + 1 (480 max only in RGB mode). + // Horizontal Preview size = PREV_HSIZE + 1 (640 max only in RGB mode). +#if defined (AT91C_ID_LCDC) + if( (pVideo->lcd_vsize > 480) || (pVideo->lcd_hsize > 640)) { + TRACE_ERROR("Size LCD bad define\n\r"); + AT91C_BASE_ISI->ISI_PSIZE = ((BOARD_LCD_HEIGHT-1) & AT91C_ISI_PREV_VSIZE) + + (((BOARD_LCD_WIDTH-1) << 16) & AT91C_ISI_PREV_HSIZE); + } + else { + + AT91C_BASE_ISI->ISI_PSIZE = ((pVideo->lcd_vsize -1) & AT91C_ISI_PREV_VSIZE) + + (((pVideo->lcd_hsize -1) << 16) & AT91C_ISI_PREV_HSIZE); + } +#endif + + + // DEC_FACTOR is 8-bit width, range is from 16 to 255. + // Values from 0 to 16 do not perform any decimation. + AT91C_BASE_ISI->ISI_PDECF = (16 * pVideo->codec_hsize) / pVideo->lcd_hsize; + + TRACE_DEBUG("codec_hsize: %d\n\r", pVideo->codec_hsize); + TRACE_DEBUG("lcd_hsize: %d\n\r", pVideo->lcd_hsize); + TRACE_DEBUG("ISI_PDECF: %d\n\r", AT91C_BASE_ISI->ISI_PDECF); + if( AT91C_BASE_ISI->ISI_PDECF <16) { + TRACE_ERROR("ISI_PDECF, forbidden value: %d\n\r", AT91C_BASE_ISI->ISI_PDECF); + AT91C_BASE_ISI->ISI_PDECF = 16; + } + + AT91C_BASE_ISI->ISI_DMAPDSCR = pVideo->Isi_fbd_base; + AT91C_BASE_ISI->ISI_DMAPCTRL = AT91C_ISI_P_FETCH_ENABLE; + AT91C_BASE_ISI->ISI_DMAPADDR = pVideo->lcd_fb_addr; + + // C0: Color Space Conversion Matrix Coefficient C0 + // C1: Color Space Conversion Matrix Coefficient C1 + // C2: Color Space Conversion Matrix Coefficient C2 + // C3: Color Space Conversion Matrix Coefficient C3 + AT91C_BASE_ISI->ISI_Y2RSET0 = ( (0x95<< 0) & AT91C_ISI_Y2R_C0) + + ( (0xFF<< 8) & AT91C_ISI_Y2R_C1) + + ( (0x68<<16) & AT91C_ISI_Y2R_C2) + + ( (0x32<<24) & AT91C_ISI_Y2R_C3); + + // C4: Color Space Conversion Matrix coefficient C4 + // Yoff: Color Space Conversion Luminance 128 offset + // Croff: Color Space Conversion Red Chrominance 16 offset + // Cboff: Color Space Conversion Blue Chrominance 16 offset + AT91C_BASE_ISI->ISI_Y2RSET1 = ( (0xCC<< 0) & AT91C_ISI_Y2R_C4) + + ( AT91C_ISI_Y2R_YOFF_128) + + ( AT91C_ISI_Y2R_CROFF_16) + + ( AT91C_ISI_Y2R_CBOFF_16); +} + +#endif // defined (BOARD_ISI_V200) + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/lcd/lcd.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/lcd/lcd.c new file mode 100644 index 000000000..f5fab9254 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/lcd/lcd.c @@ -0,0 +1,466 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#include + +#if defined (AT91C_ID_LCDC) + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "lcd.h" +#include +#include + + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Enables the LCD controller, after waiting for the specified number of +/// frames. +/// \param frames Number of frames before the LCD is enabled. +//------------------------------------------------------------------------------ +void LCD_Enable(unsigned int frames) +{ + TRACE_DEBUG("LCD enable\n\r"); + ASSERT((frames & 0xFFFFFF80) == 0, + "LCD_Enable: Wrong frames value.\n\r"); + if( (AT91C_BASE_LCDC->LCDC_PWRCON & AT91C_LCDC_BUSY) == AT91C_LCDC_BUSY ) { + TRACE_DEBUG("LCD BUSY E\n\r"); + } + AT91C_BASE_LCDC->LCDC_PWRCON = AT91C_LCDC_PWR | (frames << 1); +} + +//------------------------------------------------------------------------------ +/// Disables the LCD controller, after waiting for the specified number of +/// frames. +/// \param frames Number of frames before the LCD is shut down. +//------------------------------------------------------------------------------ +void LCD_Disable(unsigned int frames) +{ + TRACE_DEBUG("LCD disable\n\r"); + ASSERT((frames & 0xFFFFFF80) == 0, + "LCD_Disable: Wrong frames value.\n\r"); + // Remove AT91C_LCDC_PWR + AT91C_BASE_LCDC->LCDC_PWRCON = frames << 1; + // wait LCDC Core is in idle state + while( (AT91C_BASE_LCDC->LCDC_PWRCON & AT91C_LCDC_BUSY) == AT91C_LCDC_BUSY ) { + } + TRACE_DEBUG("LCD is in IDLE state\n\r"); +} + +//------------------------------------------------------------------------------ +/// Enables the DMA of the LCD controller. +//------------------------------------------------------------------------------ +void LCD_EnableDma(void) +{ + if( (AT91C_BASE_LCDC->LCDC_DMACON & AT91C_LCDC_DMABUSY) == AT91C_LCDC_DMABUSY ) { + TRACE_DEBUG("LCD DMA BUSY E\n\r"); + } + AT91C_BASE_LCDC->LCDC_DMACON = AT91C_LCDC_DMAEN; +} + +//------------------------------------------------------------------------------ +/// Disables the DMA of the LCD controller. +//------------------------------------------------------------------------------ +void LCD_DisableDma(void) +{ + AT91C_BASE_LCDC->LCDC_DMACON = 0; + // wait LCDC DMA is in idle state + while( (AT91C_BASE_LCDC->LCDC_DMACON & AT91C_LCDC_DMABUSY) == AT91C_LCDC_DMABUSY ) { + } + TRACE_DEBUG("LCD DMA is in IDLE state\n\r"); +} + +//------------------------------------------------------------------------------ +/// Enables the selected LDC interrupt sources. +/// \param sources Interrupt sources to enable. +//------------------------------------------------------------------------------ +void LCD_EnableInterrupts(unsigned int sources) +{ + AT91C_BASE_LCDC->LCDC_IER = sources; +} + +//------------------------------------------------------------------------------ +/// Configures the internal clock of the LCD controller given the master clock of +/// the system and the desired pixel clock in MHz. +/// \param masterClock Master clock frequency. +/// \param pixelClock Pixel clock frequency. +//------------------------------------------------------------------------------ +void LCD_SetPixelClock(unsigned int masterClock, unsigned int pixelClock) +{ + AT91C_BASE_LCDC->LCDC_LCDCON1 = ((masterClock / 2 / pixelClock) - 2) << 12; +} + +//------------------------------------------------------------------------------ +/// DMA reset +//------------------------------------------------------------------------------ +void LCD_DMAReset(void) +{ + // DMA Module should be reset only when disabled and in idle state + if( AT91C_LCDC_DMABUSY == (AT91C_BASE_LCDC->LCDC_DMACON & AT91C_LCDC_DMABUSY)) { + TRACE_ERROR("LCD BUSY so NO DMA RESET\n\r"); + } + if( AT91C_LCDC_DMAEN == (AT91C_BASE_LCDC->LCDC_DMACON & AT91C_LCDC_DMAEN)) { + TRACE_ERROR("DMA Enabled, so NO DMA RESET\n\r"); + } + AT91C_BASE_LCDC->LCDC_DMACON = AT91C_LCDC_DMARST; +} + +//------------------------------------------------------------------------------ +/// Sets the type of display used with the LCD controller. +/// \param displayType Type of display used. +//------------------------------------------------------------------------------ +void LCD_SetDisplayType(unsigned int displayType) +{ + unsigned int value; + + ASSERT((displayType & ~AT91C_LCDC_DISTYPE) == 0, + "LCD_SetDisplayType: Wrong display type value.\n\r"); + + value = AT91C_BASE_LCDC->LCDC_LCDCON2; + value &= ~AT91C_LCDC_DISTYPE; + value |= displayType; + AT91C_BASE_LCDC->LCDC_LCDCON2 = value; +} + +//------------------------------------------------------------------------------ +/// Sets the scan mode used by the LCD (either single scan or double-scan). +/// \param scanMode Scan mode to use. +//------------------------------------------------------------------------------ +void LCD_SetScanMode(unsigned int scanMode) +{ + unsigned int value; + + ASSERT((scanMode & ~AT91C_LCDC_SCANMOD) == 0, + "LCD_SetScanMode: Wrong scan mode value.\n\r"); + + value = AT91C_BASE_LCDC->LCDC_LCDCON2; + value &= ~AT91C_LCDC_SCANMOD; + value |= scanMode; + AT91C_BASE_LCDC->LCDC_LCDCON2 = value; +} + +//------------------------------------------------------------------------------ +/// Sets the number of bits per pixel used by the LCD display. +/// \param bitsPerPixel Number of bits per pixel to use. +//------------------------------------------------------------------------------ +void LCD_SetBitsPerPixel(unsigned int bitsPerPixel) +{ + unsigned int value; + + ASSERT((bitsPerPixel & ~AT91C_LCDC_PIXELSIZE) == 0, + "LCD_SetScanMode: Wrong bitsPerPixel value.\n\r"); + + value = AT91C_BASE_LCDC->LCDC_LCDCON2; + value &= ~AT91C_LCDC_PIXELSIZE; + value |= bitsPerPixel; + AT91C_BASE_LCDC->LCDC_LCDCON2 = value; +} + +//------------------------------------------------------------------------------ +/// Sets the LCDD, LCDVSYNC, LCDHSYNC, LCDDOTCLK and LCDDEN signal polarities. +/// \param lcdd LCDD signal polarity. +/// \param lcdvsync LCDVSYNC signal polarity. +/// \param lcdhsync LCDHSYNC signal polarity. +/// \param lcddotclk LCDDOTCLK signal polarity. +/// \param lcdden LCDDEN signal polarity. +//------------------------------------------------------------------------------ +void LCD_SetPolarities( + unsigned int lcdd, + unsigned int lcdvsync, + unsigned int lcdhsync, + unsigned int lcddotclk, + unsigned int lcdden) +{ + unsigned int value; + + ASSERT((lcdd & ~AT91C_LCDC_INVVD) == 0, + "LCD_SetPolarities: Wrong lcdd value.\n\r"); + ASSERT((lcdvsync & ~AT91C_LCDC_INVFRAME) == 0, + "LCD_SetPolarities: Wrong lcdvsync value.\n\r"); + ASSERT((lcdhsync & ~AT91C_LCDC_INVLINE) == 0, + "LCD_SetPolarities: Wrong lcdhsync value.\n\r"); + ASSERT((lcddotclk & ~AT91C_LCDC_INVCLK) == 0, + "LCD_SetPolarities: Wrong lcddotclk value.\n\r"); + ASSERT((lcdden & ~AT91C_LCDC_INVDVAL) == 0, + "LCD_SetPolarities: Wrong lcdden value.\n\r"); + + value = AT91C_BASE_LCDC->LCDC_LCDCON2; + value &= 0xFFFFE0FF; + value |= lcdd | lcdvsync | lcdhsync | lcddotclk | lcdden; + AT91C_BASE_LCDC->LCDC_LCDCON2 = value; +} + +//------------------------------------------------------------------------------ +/// Sets the LCD clock mode, i.e. always active or active only during display +/// period. +/// \param clockMode Clock mode to use. +//------------------------------------------------------------------------------ +void LCD_SetClockMode(unsigned int clockMode) +{ + unsigned int value; + + ASSERT((clockMode & ~AT91C_LCDC_CLKMOD) == 0, + "LCD_SetScanMode: Wrong scan mode value.\n\r"); + + value = AT91C_BASE_LCDC->LCDC_LCDCON2; + value &= ~AT91C_LCDC_CLKMOD; + value |= clockMode; + AT91C_BASE_LCDC->LCDC_LCDCON2 = value; +} + +//------------------------------------------------------------------------------ +/// Sets the format of the frame buffer memory. +/// \param format Memory ordering format. +//------------------------------------------------------------------------------ +void LCD_SetMemoryFormat(unsigned int format) +{ + unsigned int value; + + ASSERT((format & ~AT91C_LCDC_MEMOR) == 0, + "LCD_SetMemoryFormat: Wrong memory format value.\n\r"); + + value = AT91C_BASE_LCDC->LCDC_LCDCON2; + value &= ~AT91C_LCDC_MEMOR; + value |= format; + AT91C_BASE_LCDC->LCDC_LCDCON2 = value; +} + +//------------------------------------------------------------------------------ +/// Sets the size in pixel of the LCD display. +/// \param width Width in pixel of the LCD display. +/// \param height Height in pixel of the LCD display. +//------------------------------------------------------------------------------ +void LCD_SetSize(unsigned int width, unsigned int height) +{ + ASSERT(((width - 1) & 0xFFFFF800) == 0, + "LCD_SetSize: Wrong width value.\n\r"); + ASSERT(((height - 1) & 0xFFFFF800) == 0, + "LCD_SetSize: Wrong height value.\n\r"); + + AT91C_BASE_LCDC->LCDC_LCDFRCFG = ((width - 1) << 21) | (height - 1); +} + +//------------------------------------------------------------------------------ +/// Sets the vertical timings of the LCD controller. Only meaningful when +/// using a TFT display. +/// \param vfp Number of idle lines at the end of a frame. +/// \param vbp Number of idle lines at the beginning of a frame. +/// \param vpw Vertical synchronization pulse width in number of lines. +/// \param vhdly Delay between LCDVSYNC edge and LCDHSYNC rising edge, in +/// LCDDOTCLK cycles. +//------------------------------------------------------------------------------ +void LCD_SetVerticalTimings( + unsigned int vfp, + unsigned int vbp, + unsigned int vpw, + unsigned int vhdly) +{ + ASSERT((vfp & 0xFFFFFF00) == 0, + "LCD_SetVerticalTimings: Wrong vfp value.\n\r"); + ASSERT((vbp & 0xFFFFFF00) == 0, + "LCD_SetVerticalTimings: Wrong vbp value.\n\r"); + ASSERT(((vpw-1) & 0xFFFFFFC0) == 0, + "LCD_SetVerticalTimings: Wrong vpw value.\n\r"); + ASSERT(((vhdly-1) & 0xFFFFFFF0) == 0, + "LCD_SetVerticalTimings: Wrong vhdly value.\n\r"); + + AT91C_BASE_LCDC->LCDC_TIM1 = vfp + | (vbp << 8) + | ((vpw-1) << 16) + | ((vhdly-1) << 24); +} + +//------------------------------------------------------------------------------ +/// Sets the horizontal timings of the LCD controller. Meaningful for both +/// STN and TFT displays. +/// \param hbp Number of idle LCDDOTCLK cycles at the beginning of a line. +/// \param hpw Width of the LCDHSYNC pulse, in LCDDOTCLK cycles. +/// \param hfp Number of idel LCDDOTCLK cycles at the end of a line. +//------------------------------------------------------------------------------ +void LCD_SetHorizontalTimings( + unsigned int hbp, + unsigned int hpw, + unsigned int hfp) +{ + ASSERT(((hbp-1) & 0xFFFFFF00) == 0, + "LCD_SetHorizontalTimings: Wrong hbp value.\n\r"); + ASSERT(((hpw-1) & 0xFFFFFFC0) == 0, + "LCD_SetHorizontalTimings: Wrong hpw value.\n\r"); + ASSERT(((hfp-1) & 0xFFFFFF00) == 0, + "LCD_SetHorizontalTimings: Wrong hfp value.\n\r"); + + AT91C_BASE_LCDC->LCDC_TIM2 = (hbp-1) | ((hpw-1) << 8) | ((hfp-1) << 24); +} + +//------------------------------------------------------------------------------ +/// Sets the address of the frame buffer in the LCD controller DMA. When using +/// dual-scan mode, this is the upper frame buffer. +/// \param address Frame buffer address. +//------------------------------------------------------------------------------ +void* LCD_SetFrameBufferAddress(void *address) +{ + void *pOldBuffer; + + pOldBuffer = (void *) AT91C_BASE_LCDC->LCDC_BA1; + AT91C_BASE_LCDC->LCDC_BA1 = (unsigned int) address; + + return pOldBuffer; +} + +//------------------------------------------------------------------------------ +/// Sets the size in pixels of a frame (height * width * bpp). +/// \param frameSize Size of frame in pixels. +//------------------------------------------------------------------------------ +void LCD_SetFrameSize(unsigned int frameSize) +{ + ASSERT((frameSize & 0xFF800000) == 0, + "LCD_SetFrameSize: Wrong frameSize value.\n\r"); + + AT91C_BASE_LCDC->LCDC_FRMCFG = (frameSize& AT91C_LCDC_FRSIZE) + | (AT91C_BASE_LCDC->LCDC_FRMCFG & AT91C_LCDC_BLENGTH); +} + +//------------------------------------------------------------------------------ +/// Sets the DMA controller burst length. +/// \param burstLength Desired burst length. +//------------------------------------------------------------------------------ +void LCD_SetBurstLength(unsigned int burstLength) +{ + ASSERT(((burstLength-1) & 0xFFFFFF80) == 0, + "LCD_SetBurstLength: Wrong burstLength value.\n\r"); + + AT91C_BASE_LCDC->LCDC_FRMCFG &= ~AT91C_LCDC_BLENGTH; + AT91C_BASE_LCDC->LCDC_FRMCFG |= (((burstLength-1) << 24) & AT91C_LCDC_BLENGTH); + + AT91C_BASE_LCDC->LCDC_FIFO = (2048 - (2 * burstLength + 3)) & AT91C_LCDC_FIFOTH; +} + +//------------------------------------------------------------------------------ +/// Sets the prescaler value of the contrast control PWM. +/// \param prescaler Desired prescaler value. +//------------------------------------------------------------------------------ +void LCD_SetContrastPrescaler(unsigned int prescaler) +{ + ASSERT((prescaler & ~AT91C_LCDC_PS) == 0, + "LCD_SetContrastPrescaler: Wrong prescaler value\n\r"); + + AT91C_BASE_LCDC->LCDC_CTRSTCON &= ~AT91C_LCDC_PS; + AT91C_BASE_LCDC->LCDC_CTRSTCON |= prescaler; +} + +//------------------------------------------------------------------------------ +/// Sets the polarity of the contrast PWM. +/// \param polarity PWM polarity +//------------------------------------------------------------------------------ +void LCD_SetContrastPolarity(unsigned int polarity) +{ + ASSERT((polarity & ~AT91C_LCDC_POL) == 0, + "LCD_SetContrastPolarity: Wrong polarity value\n\r"); + + AT91C_BASE_LCDC->LCDC_CTRSTCON &= ~AT91C_LCDC_POL; + AT91C_BASE_LCDC->LCDC_CTRSTCON |= polarity; +} + +//------------------------------------------------------------------------------ +/// Sets the threshold value of the constrast PWM. +/// \param value PWM threshold value. +//------------------------------------------------------------------------------ +void LCD_SetContrastValue(unsigned int value) +{ + ASSERT((value & ~AT91C_LCDC_CVAL) == 0, + "LCD_SetContrastValue: Wrong value.\n\r"); + + AT91C_BASE_LCDC->LCDC_CTRSTVAL = value; +} + +//------------------------------------------------------------------------------ +/// Enables the contrast PWM generator. +//------------------------------------------------------------------------------ +void LCD_EnableContrast(void) +{ + AT91C_BASE_LCDC->LCDC_CTRSTCON |= AT91C_LCDC_ENA_PWMGEMENABLED; +} + +//------------------------------------------------------------------------------ +/// Decode the RGB file +/// \param file Buffer which holds the RGB file. +/// \param bufferLCD Buffer in which to store the decoded image adapted to LCD. +/// \param width Buffer width in pixels. +/// \param height Buffer height in pixels. +/// \param bpp Number of bits per pixels that the buffer stores. +//------------------------------------------------------------------------------ +void LCD_DecodeRGB( + unsigned char *file, + unsigned char *bufferLCD, + unsigned int width, + unsigned int height, + unsigned char bpp) +{ + unsigned int offsetLine=0, offsetLCD=0; + unsigned int offset=1; + + while( offset < (BOARD_LCD_HEIGHT)) { + //TRACE_DEBUG("LCD:%d LINE:%d off:%d\n\r", offsetLCD, offsetLine, offset); + if( width < BOARD_LCD_WIDTH ) { + //TRACE_DEBUG("width < BOARD_LCD_WIDTH\n\r"); + while( offsetLine < (width*offset*(bpp/8)) ) { + bufferLCD[offsetLCD] = file[offsetLine]; + offsetLine++; + offsetLCD++; + } + //TRACE_DEBUG("add white\n\r"); + while( offsetLCD < (BOARD_LCD_WIDTH*offset*(bpp/8)) ) { + bufferLCD[offsetLCD] = 0; + //offsetLine++; + offsetLCD++; + } + } + else { + //TRACE_DEBUG(">"); + while( offsetLCD < (BOARD_LCD_WIDTH*offset*(bpp/8)) ) { + bufferLCD[offsetLCD] = file[offsetLine]; + offsetLine++; + offsetLCD++; + } + //TRACE_DEBUG("r "); + while( offsetLine < (width*offset*(bpp/8)) ) { + offsetLine++; + } + } + offset++; + } +} + +#endif + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/lcd/lcd.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/lcd/lcd.h new file mode 100644 index 000000000..5974aaa3e --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/lcd/lcd.h @@ -0,0 +1,124 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Interface for configuration the LCD Controller (LCDC) peripheral. +/// +/// !Usage +/// +/// -# Decode the RGB file to designated buffer using LCD_DecodeRGB(). +/// -# Sets the address of the frame buffer in the LCD controller DMA using +/// LCD_SetFrameBufferAddress(). +/// -# LCD Configuration functions prefixed with "LCD_Set" refer to +/// the functions in the #Overview# tab. +/// +/// Please refer to the list of functions in the #Overview# tab of this unit +/// for more detailed information. +//------------------------------------------------------------------------------ + +#ifndef LCD_H +#define LCD_H + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +extern void LCD_Enable(unsigned int frames); + +extern void LCD_Disable(unsigned int frames); + +extern void LCD_EnableDma(void); + +extern void LCD_DisableDma(void); + +extern void LCD_EnableInterrupts(unsigned int sources); + +extern void LCD_SetPixelClock(unsigned int masterClock, unsigned int pixelClock); + +extern void LCD_SetDisplayType(unsigned int displayType); + +extern void LCD_SetScanMode(unsigned int scanMode); + +extern void LCD_SetBitsPerPixel(unsigned int bitsPerPixel); + +extern void LCD_SetPolarities( + unsigned int lcdd, + unsigned int lcdvsync, + unsigned int lcdhsync, + unsigned int lcddotclk, + unsigned int lcdden); + +extern void LCD_SetClockMode(unsigned int clockMode); + +extern void LCD_SetMemoryFormat(unsigned int format); + +extern void LCD_SetSize(unsigned int width, unsigned int height); + +extern void LCD_SetVerticalTimings( + unsigned int vfp, + unsigned int vbp, + unsigned int vpw, + unsigned int vhdly); + +extern void LCD_SetHorizontalTimings( + unsigned int hbp, + unsigned int hpw, + unsigned int hfp); + +extern void* LCD_SetFrameBufferAddress(void *address); + +extern void LCD_SetFrameSize(unsigned int frameSize); + +extern void LCD_SetBurstLength(unsigned int burstLength); + +extern void LCD_SetContrastPrescaler(unsigned int prescaler); + +extern void LCD_SetContrastPolarity(unsigned int polarity); + +extern void LCD_SetContrastValue(unsigned int value); + +extern void LCD_EnableContrast(void); + +extern void LCD_SetPixelClock(unsigned int masterClock, unsigned int pixelClock); + +extern void LCD_DMAReset(void); + +extern void LCD_DecodeRGB( + unsigned char *file, + unsigned char *bufferLCD, + unsigned int width, + unsigned int height, + unsigned char bpp); + +#endif //#ifndef LCD_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/mci/mci.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/mci/mci.c new file mode 100644 index 000000000..6ec35d477 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/mci/mci.c @@ -0,0 +1,580 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "mci.h" +#include +#include + +//------------------------------------------------------------------------------ +// Local constants +//------------------------------------------------------------------------------ + +/// Bit mask for status register errors. +#define STATUS_ERRORS (AT91C_MCI_UNRE \ + | AT91C_MCI_OVRE \ + | AT91C_MCI_DTOE \ + | AT91C_MCI_DCRCE \ + | AT91C_MCI_RTOE \ + | AT91C_MCI_RENDE \ + | AT91C_MCI_RCRCE \ + | AT91C_MCI_RDIRE \ + | AT91C_MCI_RINDE) + +/// MCI data timeout configuration with 1048576 MCK cycles between 2 data transfers. +#define DTOR_1MEGA_CYCLES (AT91C_MCI_DTOCYC | AT91C_MCI_DTOMUL) + +/// MCI MR: disable MCI Clock when FIFO is full +#ifndef AT91C_MCI_WRPROOF + #define AT91C_MCI_WRPROOF 0 +#endif +#ifndef AT91C_MCI_RDPROOF + #define AT91C_MCI_RDPROOF 0 +#endif + +#define SDCARD_APP_OP_COND_CMD (41 | AT91C_MCI_SPCMD_NONE | AT91C_MCI_RSPTYP_48 | AT91C_MCI_TRCMD_NO ) +#define MMC_SEND_OP_COND_CMD (1 | AT91C_MCI_TRCMD_NO | AT91C_MCI_SPCMD_NONE | AT91C_MCI_RSPTYP_48 | AT91C_MCI_OPDCMD) + + +#define DISABLE 0 // Disable MCI interface +#define ENABLE 1 // Enable MCI interface + + +//------------------------------------------------------------------------------ +// Local macros +//------------------------------------------------------------------------------ + +/// Used to write in PMC registers. +#define WRITE_PMC(pPmc, regName, value) pPmc->regName = (value) + +/// Used to write in MCI registers. +#define WRITE_MCI(pMci, regName, value) pMci->regName = (value) + +/// Used to read from MCI registers. +#define READ_MCI(pMci, regName) (pMci->regName) + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Enable/disable a MCI driver instance. +/// \param pMci Pointer to a MCI driver instance. +/// \param enb 0 for disable MCI and 1 for enable MCI. +//------------------------------------------------------------------------------ +void MCI_Enable(Mci *pMci, unsigned char enb) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMci->pMciHw); + + // Set the Control Register: Enable/Disable MCI interface clock + if(enb == DISABLE) { + WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_MCIDIS); + } + else { + WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_MCIEN); + } +} + +//------------------------------------------------------------------------------ +/// Initializes a MCI driver instance and the underlying peripheral. +/// \param pMci Pointer to a MCI driver instance. +/// \param pMciHw Pointer to a MCI peripheral. +/// \param mciId MCI peripheral identifier. +/// \param mode Slot and type of connected card. +//------------------------------------------------------------------------------ +void MCI_Init( + Mci *pMci, + AT91S_MCI *pMciHw, + unsigned char mciId, + unsigned int mode) +{ + unsigned short clkDiv; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMciHw); + SANITY_CHECK((mode == MCI_MMC_SLOTA) || (mode == MCI_MMC_SLOTB) + || (mode == MCI_SD_SLOTA) || (mode == MCI_SD_SLOTB)); + + // Initialize the MCI driver structure + pMci->pMciHw = pMciHw; + pMci->mciId = mciId; + pMci->semaphore = 1; + pMci->pCommand = 0; + + // Enable the MCI clock + WRITE_PMC(AT91C_BASE_PMC, PMC_PCER, (1 << mciId)); + + // Reset the MCI + WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_SWRST); + + // Disable the MCI + WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_MCIDIS | AT91C_MCI_PWSDIS); + + // Disable all the interrupts + WRITE_MCI(pMciHw, MCI_IDR, 0xFFFFFFFF); + + // Set the Data Timeout Register + WRITE_MCI(pMciHw, MCI_DTOR, DTOR_1MEGA_CYCLES); + + // Set the Mode Register: 400KHz for MCK = 48MHz (CLKDIV = 58) + clkDiv = (BOARD_MCK / (400000 * 2)) - 1; + WRITE_MCI(pMciHw, MCI_MR, (clkDiv | (AT91C_MCI_PWSDIV & (0x7 << 8)))); + + // Set the SDCard Register + WRITE_MCI(pMciHw, MCI_SDCR, mode); + + // Enable the MCI and the Power Saving + WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_MCIEN); + + // Disable the MCI peripheral clock. + WRITE_PMC(AT91C_BASE_PMC, PMC_PCDR, (1 << mciId)); +} + +//------------------------------------------------------------------------------ +/// Close a MCI driver instance and the underlying peripheral. +/// \param pMci Pointer to a MCI driver instance. +/// \param pMciHw Pointer to a MCI peripheral. +/// \param mciId MCI peripheral identifier. +//------------------------------------------------------------------------------ +void MCI_Close(Mci *pMci) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMciHw); + + // Initialize the MCI driver structure + pMci->semaphore = 1; + pMci->pCommand = 0; + + // Disable the MCI peripheral clock. + WRITE_PMC(AT91C_BASE_PMC, PMC_PCDR, (1 << pMci->mciId)); + + // Disable the MCI + WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_MCIDIS); + + // Disable all the interrupts + WRITE_MCI(pMciHw, MCI_IDR, 0xFFFFFFFF); +} + +//------------------------------------------------------------------------------ +/// Configure the MCI CLKDIV in the MCI_MR register. The max. for MCI clock is +/// MCK/2 and corresponds to CLKDIV = 0 +/// \param pMci Pointer to the low level MCI driver. +/// \param mciSpeed MCI clock speed in Hz. +//------------------------------------------------------------------------------ +void MCI_SetSpeed(Mci *pMci, unsigned int mciSpeed) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + unsigned int mciMr; + unsigned int clkdiv; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMci->pMciHw); + + // Set the Mode Register: 400KHz for MCK = 48MHz (CLKDIV = 58) + mciMr = READ_MCI(pMciHw, MCI_MR) & (~AT91C_MCI_CLKDIV); + + // Multimedia Card Interface clock (MCCK or MCI_CK) is Master Clock (MCK) + // divided by (2*(CLKDIV+1)) + if (mciSpeed > 0) { + + clkdiv = (BOARD_MCK / (mciSpeed * 2)); + if (clkdiv > 0) { + + clkdiv -= 1; + } + ASSERT( (clkdiv & 0xFFFFFF00) == 0, "mciSpeed too small"); + } + else { + + clkdiv = 0; + } + + WRITE_MCI(pMciHw, MCI_MR, mciMr | clkdiv); +} + +//------------------------------------------------------------------------------ +/// Configure the MCI SDCBUS in the MCI_SDCR register. Only two modes available +/// +/// \param pMci Pointer to the low level MCI driver. +/// \param busWidth MCI bus width mode. +//------------------------------------------------------------------------------ +void MCI_SetBusWidth(Mci *pMci, unsigned char busWidth) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + unsigned int mciSdcr; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMci->pMciHw); + + mciSdcr = (READ_MCI(pMciHw, MCI_SDCR) & ~(AT91C_MCI_SCDBUS)); + + WRITE_MCI(pMciHw, MCI_SDCR, mciSdcr | busWidth); +} + +//------------------------------------------------------------------------------ +/// Starts a MCI transfer. This is a non blocking function. It will return +/// as soon as the transfer is started. +/// Return 0 if successful; otherwise returns MCI_ERROR_LOCK if the driver is +/// already in use. +/// \param pMci Pointer to an MCI driver instance. +/// \param pCommand Pointer to the command to execute. +//------------------------------------------------------------------------------ +unsigned char MCI_SendCommand(Mci *pMci, MciCmd *pCommand) +{ + AT91PS_MCI pMciHw = pMci->pMciHw; + unsigned int mciIer, mciMr; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMciHw); + SANITY_CHECK(pCommand); + + // Try to acquire the MCI semaphore + if (pMci->semaphore == 0) { + + return MCI_ERROR_LOCK; + } + pMci->semaphore--; + // TRACE_DEBUG("MCI_SendCommand %x %d\n\r", READ_MCI(pMciHw, MCI_SR), pCommand->cmd & 0x3f); + + // Command is now being executed + pMci->pCommand = pCommand; + pCommand->status = MCI_STATUS_PENDING; + + // Enable the MCI clock + WRITE_PMC(AT91C_BASE_PMC, PMC_PCER, (1 << pMci->mciId)); + + //Disable MCI clock, for multi-block data transfer + MCI_Enable(pMci, DISABLE); + + // Set PDC data transfer direction + if(pCommand->blockSize > 0) { + if(pCommand->isRead) { + WRITE_MCI(pMciHw, MCI_PTCR, AT91C_PDC_RXTEN); + } + else { + WRITE_MCI(pMciHw, MCI_PTCR, AT91C_PDC_TXTEN); + } + } + // Disable transmitter and receiver + WRITE_MCI(pMciHw, MCI_PTCR, AT91C_PDC_RXTDIS | AT91C_PDC_TXTDIS); + + mciMr = READ_MCI(pMciHw, MCI_MR) & (~(AT91C_MCI_WRPROOF|AT91C_MCI_RDPROOF|AT91C_MCI_BLKLEN | AT91C_MCI_PDCMODE)); + + // Command with DATA stage + if (pCommand->blockSize > 0) { + // Enable PDC mode and set block size + if(pCommand->conTrans != MCI_CONTINUE_TRANSFER) { + + WRITE_MCI(pMciHw, MCI_MR, mciMr | AT91C_MCI_PDCMODE |AT91C_MCI_RDPROOF|AT91C_MCI_WRPROOF|(pCommand->blockSize << 16)); + } + + // DATA transfer from card to host + if (pCommand->isRead) { + WRITE_MCI(pMciHw, MCI_RPR, (int) pCommand->pData); + + // Sanity check + if (pCommand->nbBlock == 0) + pCommand->nbBlock = 1; + //////// + if ((pCommand->blockSize & 0x3) != 0) { + WRITE_MCI(pMciHw, MCI_RCR, (pCommand->nbBlock * pCommand->blockSize) / 4 + 1); + } + else { + WRITE_MCI(pMciHw, MCI_RCR, (pCommand->nbBlock * pCommand->blockSize) / 4); + } + + WRITE_MCI(pMciHw, MCI_PTCR, AT91C_PDC_RXTEN); + mciIer = AT91C_MCI_ENDRX | STATUS_ERRORS; + // mciIer = AT91C_MCI_RXBUFF | STATUS_ERRORS; + } + + // DATA transfer from host to card + else { + // Sanity check + if (pCommand->nbBlock == 0) + pCommand->nbBlock = 1; + WRITE_MCI(pMciHw, MCI_TPR, (int) pCommand->pData); + // Update the PDC counter + if ((pCommand->blockSize & 0x3) != 0) { + WRITE_MCI(pMciHw, MCI_TCR, (pCommand->nbBlock * pCommand->blockSize) / 4 + 1); + } + else { + WRITE_MCI(pMciHw, MCI_TCR, (pCommand->nbBlock * pCommand->blockSize) / 4); + } + // MCI_BLKE notifies the end of Multiblock command + mciIer = AT91C_MCI_BLKE | STATUS_ERRORS; + } + } + // No data transfer: stop at the end of the command + else { + WRITE_MCI(pMciHw, MCI_MR, mciMr); + mciIer = AT91C_MCI_CMDRDY | STATUS_ERRORS; + } + // Enable MCI clock + MCI_Enable(pMci, ENABLE); + + // Send the command + if((pCommand->conTrans != MCI_CONTINUE_TRANSFER) + || (pCommand->blockSize == 0)) { + + WRITE_MCI(pMciHw, MCI_ARGR, pCommand->arg); + WRITE_MCI(pMciHw, MCI_CMDR, pCommand->cmd); + } + + // In case of transmit, the PDC shall be enabled after sending the command + if ((pCommand->blockSize > 0) && !(pCommand->isRead)) { + WRITE_MCI(pMciHw, MCI_PTCR, AT91C_PDC_TXTEN); + } + + // Ignore data error + mciIer &= ~(AT91C_MCI_UNRE | AT91C_MCI_OVRE \ + | AT91C_MCI_DTOE | AT91C_MCI_DCRCE); + + // Interrupt enable shall be done after PDC TXTEN and RXTEN + WRITE_MCI(pMciHw, MCI_IER, mciIer); + + return 0; +} + +//------------------------------------------------------------------------------ +/// Check NOTBUSY and DTIP bits of status register on the given MCI driver. +/// Return value, 0 for bus ready, 1 for bus busy +/// \param pMci Pointer to a MCI driver instance. +//------------------------------------------------------------------------------ +unsigned char MCI_CheckBusy(Mci *pMci) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + unsigned int status; + + // Enable MCI clock + MCI_Enable(pMci, ENABLE); + + status = READ_MCI(pMciHw, MCI_SR); + // TRACE_DEBUG("status %x\n\r",status); + + + if(((status & AT91C_MCI_NOTBUSY)!=0) + && ((status & AT91C_MCI_DTIP)==0)) { + + // Disable MCI clock + MCI_Enable(pMci, DISABLE); + + return 0; + } + else { + return 1; + } +} + +//------------------------------------------------------------------------------ +/// Check BLKE bit of status register on the given MCI driver. +/// \param pMci Pointer to a MCI driver instance. +//------------------------------------------------------------------------------ +unsigned char MCI_CheckBlke(Mci *pMci) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + unsigned int status; + + status = READ_MCI(pMciHw, MCI_SR); + // TRACE_DEBUG("status %x\n\r",status); + + if((status & AT91C_MCI_BLKE)!=0) { + return 0; + } + else { + return 1; + } +} + +//------------------------------------------------------------------------------ +/// Processes pending events on the given MCI driver. +/// \param pMci Pointer to a MCI driver instance. +//------------------------------------------------------------------------------ +void MCI_Handler(Mci *pMci) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + MciCmd *pCommand = pMci->pCommand; + unsigned int status; + unsigned char i; + #if defined(at91rm9200) + unsigned int mciCr, mciSdcr, mciMr, mciDtor; + #endif + + SANITY_CHECK(pMci); + SANITY_CHECK(pMciHw); + SANITY_CHECK(pCommand); + + // Read the status register + status = READ_MCI(pMciHw, MCI_SR) & READ_MCI(pMciHw, MCI_IMR); + // TRACE_DEBUG("status %x\n\r", status); + + // Check if an error has occured + if ((status & STATUS_ERRORS) != 0) { + + // Check error code + if ((status & STATUS_ERRORS) == AT91C_MCI_RTOE) { + + pCommand->status = MCI_STATUS_NORESPONSE; + } + // if the command is SEND_OP_COND the CRC error flag is always present + // (cf : R3 response) + else if (((status & STATUS_ERRORS) != AT91C_MCI_RCRCE) + || ((pCommand->cmd != SDCARD_APP_OP_COND_CMD) + && (pCommand->cmd != MMC_SEND_OP_COND_CMD))) { + + pCommand->status = MCI_STATUS_ERROR; + } + } + + // Check if a transfer has been completed + if (((status & AT91C_MCI_CMDRDY) != 0) + || ((status & AT91C_MCI_ENDRX) != 0) + || ((status & AT91C_MCI_RXBUFF) != 0) + || ((status & AT91C_MCI_ENDTX) != 0) + || ((status & AT91C_MCI_BLKE) != 0) + || ((status & AT91C_MCI_RTOE) != 0)) { + + if (((status & AT91C_MCI_ENDRX) != 0) + || ((status & AT91C_MCI_RXBUFF) != 0) + || ((status & AT91C_MCI_ENDTX) != 0)) { + + MCI_Enable(pMci, DISABLE); + } + + /// On AT91RM9200-EK, if stop transmission, software reset MCI. + #if defined(at91rm9200) + if ((pCommand->cmd & AT91C_MCI_TRCMD_STOP) != 0) { + mciMr = READ_MCI(pMciHw, MCI_MR); + mciSdcr = READ_MCI(pMciHw, MCI_SDCR); + mciDtor = READ_MCI(pMciHw, MCI_DTOR); + WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_SWRST); + // TRACE_DEBUG("reset MCI\n\r"); + + WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_MCIDIS | AT91C_MCI_PWSDIS); + WRITE_MCI(pMciHw, MCI_MR, mciMr); + WRITE_MCI(pMciHw, MCI_SDCR, mciSdcr); + WRITE_MCI(pMciHw, MCI_DTOR, mciDtor); + } + #endif + + // If no error occured, the transfer is successful + if (pCommand->status == MCI_STATUS_PENDING) { + pCommand->status = 0; + } +#if 0 + if ((status & AT91C_MCI_CMDRDY) != 0) + TRACE_DEBUG_WP("."); + if ((status & AT91C_MCI_ENDRX) != 0) + TRACE_DEBUG_WP("<"); + if ((status & AT91C_MCI_ENDTX) != 0) + TRACE_DEBUG_WP("-"); + if ((status & AT91C_MCI_BLKE) != 0) + TRACE_DEBUG_WP(">"); + TRACE_DEBUG_WP("\n\r"); +#endif + // Store the card response in the provided buffer + if (pCommand->pResp) { + unsigned char resSize; + + switch (pCommand->resType) { + case 1: + resSize = 1; + break; + + case 2: + resSize = 4; + break; + + case 3: + resSize = 1; + break; + + case 4: + resSize = 1; + break; + + case 5: + resSize = 1; + break; + + case 6: + resSize = 1; + break; + + case 7: + resSize = 1; + break; + + default: + resSize = 0; + break; + } + for (i=0; i < resSize; i++) { + + pCommand->pResp[i] = READ_MCI(pMciHw, MCI_RSPR[0]); + } + } + + // Disable interrupts + WRITE_MCI(pMciHw, MCI_IDR, READ_MCI(pMciHw, MCI_IMR)); + + // Release the semaphore + pMci->semaphore++; + + // Invoke the callback associated with the current command (if any) + if (pCommand->callback) { + (pCommand->callback)(pCommand->status, pCommand); + } + } +} + +//------------------------------------------------------------------------------ +/// Returns 1 if the given MCI transfer is complete; otherwise returns 0. +/// \param pCommand Pointer to a MciCmd instance. +//------------------------------------------------------------------------------ +unsigned char MCI_IsTxComplete(MciCmd *pCommand) +{ + if (pCommand->status != MCI_STATUS_PENDING) { + if (pCommand->status != 0) { + TRACE_DEBUG("MCI_IsTxComplete %d\n\r", pCommand->status); + } + return 1; + } + else { + return 0; + } +} diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/mci/mci.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/mci/mci.h new file mode 100644 index 000000000..a9721841e --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/mci/mci.h @@ -0,0 +1,172 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \page "mci" +/// +/// !Purpose +/// +/// mci-interface driver +/// +/// !Usage +/// +/// -# MCI_Init: Initializes a MCI driver instance and the underlying peripheral. +/// -# MCI_SetSpeed : Configure the MCI CLKDIV in the MCI_MR register. +/// -# MCI_SendCommand: Starts a MCI transfer. +/// -# MCI_Handler : Interrupt handler which is called by ISR handler. +/// -# MCI_SetBusWidth : Configure the MCI SDCBUS in the MCI_SDCR register. +//------------------------------------------------------------------------------ + + +#ifndef MCI_H +#define MCI_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +//------------------------------------------------------------------------------ +// Constants +//------------------------------------------------------------------------------ + +/// Transfer is pending. +#define MCI_STATUS_PENDING 1 +/// Transfer has been aborted because an error occured. +#define MCI_STATUS_ERROR 2 +/// Card did not answer command. +#define MCI_STATUS_NORESPONSE 3 + +/// MCI driver is currently in use. +#define MCI_ERROR_LOCK 1 + +/// MCI configuration with 1-bit data bus on slot A (for MMC cards). +#define MCI_MMC_SLOTA 0 +/// MCI configuration with 1-bit data bus on slot B (for MMC cards). +#define MCI_MMC_SLOTB 1 +/// MCI configuration with 4-bit data bus on slot A (for SD cards). +#define MCI_SD_SLOTA AT91C_MCI_SCDBUS +/// MCI configuration with 4-bit data bus on slot B (for SD cards). +#define MCI_SD_SLOTB (AT91C_MCI_SCDBUS | 1) + +/// Start new data transfer +#define MCI_NEW_TRANSFER 0 +/// Continue data transfer +#define MCI_CONTINUE_TRANSFER 1 + +/// MCI SD Bus Width 1-bit +#define MCI_SDCBUS_1BIT (0 << 7) +/// MCI SD Bus Width 4-bit +#define MCI_SDCBUS_4BIT (1 << 7) + +//------------------------------------------------------------------------------ +// Types +//------------------------------------------------------------------------------ + +/// MCI end-of-transfer callback function. +typedef void (*MciCallback)(unsigned char status, void *pCommand); + +//------------------------------------------------------------------------------ +/// MCI Transfer Request prepared by the application upper layer. This structure +/// is sent to the MCI_SendCommand function to start the transfer. At the end of +/// the transfer, the callback is invoked by the interrupt handler. +//------------------------------------------------------------------------------ +typedef struct _MciCmd { + + /// Command status. + volatile char status; + /// Command code. + unsigned int cmd; + /// Command argument. + unsigned int arg; + /// Data buffer. + unsigned char *pData; + /// Size of data buffer in bytes. + unsigned short blockSize; + /// Number of blocks to be transfered + unsigned short nbBlock; + /// Indicate if continue to transfer data + unsigned char conTrans; + /// Indicates if the command is a read operation. + unsigned char isRead; + /// Response buffer. + unsigned int *pResp; + /// SD card response type. + unsigned char resType; + /// Optional user-provided callback function. + MciCallback callback; + /// Optional argument to the callback function. + void *pArg; + +} MciCmd; + +//------------------------------------------------------------------------------ +/// MCI driver structure. Holds the internal state of the MCI driver and +/// prevents parallel access to a MCI peripheral. +//------------------------------------------------------------------------------ +typedef struct { + + /// Pointer to a MCI peripheral. + AT91S_MCI *pMciHw; + /// MCI peripheral identifier. + unsigned char mciId; + /// Pointer to currently executing command. + MciCmd *pCommand; + /// Mutex. + volatile char semaphore; + +} Mci; + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void MCI_Init( + Mci *pMci, + AT91PS_MCI pMciHw, + unsigned char mciId, + unsigned int mode); + +extern void MCI_SetSpeed(Mci *pMci, unsigned int mciSpeed); + +extern unsigned char MCI_SendCommand(Mci *pMci, MciCmd *pMciCmd); + +extern void MCI_Handler(Mci *pMci); + +extern unsigned char MCI_IsTxComplete(MciCmd *pMciCmd); + +extern unsigned char MCI_CheckBusy(Mci *pMci); + +extern void MCI_Close(Mci *pMci); + +extern void MCI_SetBusWidth(Mci *pMci, unsigned char busWidth); + +#endif //#ifndef MCI_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/mci/mci_hs.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/mci/mci_hs.c new file mode 100644 index 000000000..04ce94ded --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/mci/mci_hs.c @@ -0,0 +1,1027 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "mci_hs.h" +#include +#include + +#include +#include + +//------------------------------------------------------------------------------ +// Local constants +//------------------------------------------------------------------------------ + +/// Bit mask for status register errors. +#define STATUS_ERRORS (AT91C_MCI_UNRE \ + | AT91C_MCI_OVRE \ + | AT91C_MCI_BLKOVRE \ + | AT91C_MCI_CSTOE \ + | AT91C_MCI_DTOE \ + | AT91C_MCI_DCRCE \ + | AT91C_MCI_RTOE \ + | AT91C_MCI_RENDE \ + | AT91C_MCI_RCRCE \ + | AT91C_MCI_RDIRE \ + | AT91C_MCI_RINDE) + +#define STATUS_ERRORS_RESP (AT91C_MCI_CSTOE \ + | AT91C_MCI_RTOE \ + | AT91C_MCI_RENDE \ + | AT91C_MCI_RCRCE \ + | AT91C_MCI_RDIRE \ + | AT91C_MCI_RINDE) + +#define STATUS_ERRORS_DATA (AT91C_MCI_UNRE \ + | AT91C_MCI_OVRE \ + | AT91C_MCI_BLKOVRE \ + | AT91C_MCI_CSTOE \ + | AT91C_MCI_DTOE \ + | AT91C_MCI_DCRCE) + + +/// MCI data timeout configuration with 1048576 MCK cycles between 2 data transfers. +#define DTOR_1MEGA_CYCLES (AT91C_MCI_DTOCYC | AT91C_MCI_DTOMUL) + +/// MCI MR: disable MCI Clock when FIFO is full +#ifndef AT91C_MCI_WRPROOF + #define AT91C_MCI_WRPROOF 0 +#endif +#ifndef AT91C_MCI_RDPROOF + #define AT91C_MCI_RDPROOF 0 +#endif + +#define SDCARD_APP_OP_COND_CMD (41 | AT91C_MCI_SPCMD_NONE | AT91C_MCI_RSPTYP_48 | AT91C_MCI_TRCMD_NO ) +#define MMC_SEND_OP_COND_CMD (1 | AT91C_MCI_TRCMD_NO | AT91C_MCI_SPCMD_NONE | AT91C_MCI_RSPTYP_48 | AT91C_MCI_OPDCMD) + + +#define DISABLE 0 // Disable MCI interface +#define ENABLE 1 // Enable MCI interface + + +//------------------------------------------------------------------------------ +// Local macros +//------------------------------------------------------------------------------ + +/// Used to write in PMC registers. +#define WRITE_PMC(pPmc, regName, value) pPmc->regName = (value) + +/// Used to write in MCI registers. +#define WRITE_MCI(pMci, regName, value) pMci->regName = (value) + +/// Used to read from MCI registers. +#define READ_MCI(pMci, regName) (pMci->regName) + +/// Enable MCI Clock +#define MCICK_ENABLE(pMciHw) WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_MCIEN) + +/// Disable MCI Clock +#define MCICK_DISABLE(pMciHw) WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_MCIDIS) + + +//------------------------------------------------------------------------------ +// Local variables +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Internal Functions +//------------------------------------------------------------------------------ +#if defined(MCI_DMA_ENABLE) +#define FIFO_SIZE (0x4000 - 0x200) +static DmaLinkList LLI_CH [4]; +#define LAST_ROW 0x100 +static void AT91F_Prepare_Multiple_Transfer(unsigned int Channel, + unsigned int LLI_rownumber, + unsigned int LLI_Last_Row, + unsigned int From_add, + unsigned int To_add, + unsigned int Ctrla, + unsigned int Ctrlb) +{ + LLI_CH[LLI_rownumber].sourceAddress = From_add; + LLI_CH[LLI_rownumber].destAddress = To_add; + LLI_CH[LLI_rownumber].controlA = Ctrla; + LLI_CH[LLI_rownumber].controlB = Ctrlb; + if (LLI_Last_Row != LAST_ROW) + LLI_CH[LLI_rownumber].descriptor = + (unsigned int)&LLI_CH[LLI_rownumber + 1] + 0; + else + LLI_CH[LLI_rownumber].descriptor = 0; +} + +static unsigned int DMACH_MCI_P2M(unsigned int channel_index, + unsigned int* src_addr, + unsigned int* dest_addr, + unsigned int trans_size, + unsigned char fifoForP) +{ + unsigned int srcAddress; + unsigned int destAddress; + unsigned int buffSize; + unsigned int LLI_rownumber = 0; + unsigned int srcAddressMode = fifoForP ? + (AT91C_HDMA_SRC_ADDRESS_MODE_INCR) + : (AT91C_HDMA_SRC_ADDRESS_MODE_FIXED); + + // Disable dma channel + DMA_DisableChannel(channel_index); + + // DMA channel configuration + srcAddress = (unsigned int)src_addr; // Set the data start address + destAddress = (unsigned int)dest_addr; //(unsigned int)SSC_THR_ADD; + buffSize = trans_size; + + if(buffSize >= 0x10000){ + buffSize = 0xffff; + } + + // Set DMA channel source address + DMA_SetSourceAddr(channel_index, srcAddress); + + // Set DMA channel destination address + DMA_SetDestinationAddr(channel_index,destAddress); + + // Set DMA channel DSCR + DMA_SetDescriptorAddr(channel_index, (unsigned int)&LLI_CH[0]); + + // Set DMA channel control A + DMA_SetSourceBufferSize(channel_index, buffSize, + (AT91C_HDMA_SRC_WIDTH_WORD >> 24), + (AT91C_HDMA_DST_WIDTH_WORD >> 28), 0); + + //Set DMA channel control B + DMA_SetSourceBufferMode(channel_index, DMA_TRANSFER_LLI, + srcAddressMode >> 24); + DMA_SetDestBufferMode(channel_index, DMA_TRANSFER_LLI, + (AT91C_HDMA_DST_ADDRESS_MODE_INCR >> 28)); + + // Set DMA channel config + DMA_SetConfiguration(channel_index, BOARD_SD_DMA_HW_SRC_REQ_ID \ + | BOARD_SD_DMA_HW_DEST_REQ_ID \ + | AT91C_HDMA_SRC_REP_CONTIGUOUS_ADDR \ + | AT91C_HDMA_SRC_H2SEL_HW \ + | AT91C_HDMA_DST_REP_CONTIGUOUS_ADDR \ + | AT91C_HDMA_DST_H2SEL_SW \ + | AT91C_HDMA_SOD_DISABLE \ + | AT91C_HDMA_FIFOCFG_LARGESTBURST); + + // Set link list + while(destAddress < ((unsigned int)(dest_addr + buffSize))) { + if(((unsigned int)(dest_addr + buffSize)) - destAddress <= (4*0xFFF) ) + { + AT91F_Prepare_Multiple_Transfer(channel_index, LLI_rownumber, LAST_ROW, + srcAddress, + destAddress, + (((((unsigned int)(dest_addr + buffSize)) + - destAddress)/4) + | AT91C_HDMA_SRC_WIDTH_WORD + | AT91C_HDMA_DST_WIDTH_WORD), + ( AT91C_HDMA_SIF_0 + | AT91C_HDMA_DIF_0 + | AT91C_HDMA_DST_DSCR_FETCH_FROM_MEM + //| AT91C_HDMA_DST_DSCR_FETCH_DISABLE + | AT91C_HDMA_DST_ADDRESS_MODE_INCR + //| AT91C_HDMA_SRC_DSCR_FETCH_FROM_MEM + | AT91C_HDMA_SRC_DSCR_FETCH_DISABLE + | srcAddressMode + | AT91C_HDMA_AUTO_DISABLE + | AT91C_HDMA_FC_PER2MEM)); + } + else + { + AT91F_Prepare_Multiple_Transfer(channel_index, LLI_rownumber, 0, + srcAddress, + destAddress, + ( 0xFFF + | AT91C_HDMA_SRC_WIDTH_WORD + | AT91C_HDMA_DST_WIDTH_WORD), + (AT91C_HDMA_SIF_0 + | AT91C_HDMA_DIF_0 + | AT91C_HDMA_DST_DSCR_FETCH_FROM_MEM + //| AT91C_HDMA_DST_DSCR_FETCH_DISABLE + | AT91C_HDMA_DST_ADDRESS_MODE_INCR + //| AT91C_HDMA_SRC_DSCR_FETCH_FROM_MEM + | AT91C_HDMA_SRC_DSCR_FETCH_DISABLE + | srcAddressMode + | AT91C_HDMA_AUTO_DISABLE + | AT91C_HDMA_FC_PER2MEM)); + + } + + destAddress += 4*0xFFF; + + LLI_rownumber++; + } + + return 0; +} + + +static unsigned int DMACH_MCI_M2P(unsigned int channel_index, + unsigned int* src_addr, + unsigned int* dest_addr, + unsigned int trans_size, + unsigned char fifoForP) +{ + unsigned int srcAddress; + unsigned int destAddress; + unsigned int buffSize; + unsigned int LLI_rownumber = 0; + unsigned int dstAddressMode = fifoForP ? + (AT91C_HDMA_DST_ADDRESS_MODE_INCR) + : (AT91C_HDMA_DST_ADDRESS_MODE_FIXED); + + // Disable dma channel + DMA_DisableChannel(channel_index); + + buffSize = trans_size; + if(buffSize >= 0x10000){ + buffSize = 0xffff; + } + + // DMA channel configuration + srcAddress = (unsigned int)src_addr; // Set the data start address + destAddress = (unsigned int)dest_addr; + + // Set DMA channel source address + DMA_SetSourceAddr(channel_index, srcAddress); + + // Set DMA channel destination address + DMA_SetDestinationAddr(channel_index,destAddress); + + // Set DMA channel DSCR + DMA_SetDescriptorAddr(channel_index, (unsigned int)&LLI_CH[0]); + + // Set DMA channel control A + DMA_SetSourceBufferSize(channel_index, buffSize, + (AT91C_HDMA_SRC_WIDTH_WORD >> 24), + (AT91C_HDMA_DST_WIDTH_WORD >> 28), 0); + + //Set DMA channel control B + DMA_SetSourceBufferMode(channel_index, + DMA_TRANSFER_LLI, + (AT91C_HDMA_SRC_ADDRESS_MODE_INCR >> 24)); + DMA_SetDestBufferMode(channel_index, + DMA_TRANSFER_LLI, + dstAddressMode >> 28); + + // Set DMA channel config + DMA_SetConfiguration(channel_index, BOARD_SD_DMA_HW_SRC_REQ_ID \ + | BOARD_SD_DMA_HW_DEST_REQ_ID \ + | AT91C_HDMA_SRC_REP_CONTIGUOUS_ADDR \ + | AT91C_HDMA_SRC_H2SEL_SW \ + | AT91C_HDMA_DST_REP_CONTIGUOUS_ADDR \ + | AT91C_HDMA_DST_H2SEL_HW \ + | AT91C_HDMA_SOD_DISABLE \ + | AT91C_HDMA_FIFOCFG_LARGESTBURST); + + // Set link list + while(srcAddress < ((unsigned int)(src_addr + buffSize))) + { + if(((unsigned int)(src_addr + buffSize)) - srcAddress <= (4*0xFFF) ) + { + AT91F_Prepare_Multiple_Transfer(channel_index, LLI_rownumber, LAST_ROW, + srcAddress, + destAddress, + (((((unsigned int)(src_addr + buffSize)) + - srcAddress)/4) + | AT91C_HDMA_SRC_WIDTH_WORD + | AT91C_HDMA_DST_WIDTH_WORD), + ( AT91C_HDMA_SIF_0 + | AT91C_HDMA_DIF_0 + //| AT91C_HDMA_DST_DSCR_FETCH_FROM_MEM + | AT91C_HDMA_DST_DSCR_FETCH_DISABLE + | dstAddressMode + //| AT91C_HDMA_SRC_DSCR_FETCH_FROM_MEM + | AT91C_HDMA_SRC_DSCR_FETCH_DISABLE + | AT91C_HDMA_SRC_ADDRESS_MODE_INCR + | AT91C_HDMA_AUTO_DISABLE + | AT91C_HDMA_FC_MEM2PER)); + } + else + { + AT91F_Prepare_Multiple_Transfer(channel_index, LLI_rownumber, 0, + srcAddress, + destAddress, + ( 0xFFF + | AT91C_HDMA_SRC_WIDTH_WORD + | AT91C_HDMA_DST_WIDTH_WORD), + ( AT91C_HDMA_SIF_0 + | AT91C_HDMA_DIF_0 + //| AT91C_HDMA_DST_DSCR_FETCH_FROM_MEM + | AT91C_HDMA_DST_DSCR_FETCH_DISABLE + | dstAddressMode + | AT91C_HDMA_SRC_DSCR_FETCH_FROM_MEM + //| AT91C_HDMA_SRC_DSCR_FETCH_DISABLE + | AT91C_HDMA_SRC_ADDRESS_MODE_INCR + | AT91C_HDMA_AUTO_DISABLE + | AT91C_HDMA_FC_MEM2PER)); + + } + + srcAddress += 4*0xFFF; + + + LLI_rownumber++; + } + + return 0; +} + +static inline void DMACH_EnableIt(AT91S_MCI *pMciHw, + unsigned int channel) +{ + unsigned int intFlag; + + intFlag = DMA_GetInterruptMask(); + intFlag |= (AT91C_HDMA_BTC0 << channel); + DMA_EnableIt(intFlag); +} +#endif + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Enable/disable a MCI driver instance. +/// \param pMci Pointer to a MCI driver instance. +/// \param enb 0 for disable MCI and 1 for enable MCI. +//------------------------------------------------------------------------------ +void MCI_Enable(Mci *pMci, unsigned char enb) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMci->pMciHw); + + // Set the Control Register: Enable/Disable MCI interface clock + if(enb == DISABLE) { + MCICK_DISABLE(pMciHw); + } + else { + MCICK_ENABLE(pMciHw); + } +} + +//------------------------------------------------------------------------------ +/// Initializes a MCI driver instance and the underlying peripheral. +/// \param pMci Pointer to a MCI driver instance. +/// \param pMciHw Pointer to a MCI peripheral. +/// \param mciId MCI peripheral identifier. +/// \param mode Slot and type of supported card (max bus width). +//------------------------------------------------------------------------------ +void MCI_Init( + Mci *pMci, + AT91S_MCI *pMciHw, + unsigned char mciId, + unsigned int mode) +{ + unsigned short clkDiv; + unsigned int mciCfg = 0; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMciHw); + SANITY_CHECK( (mode == MCI_MMC_SLOTA) || (mode == MCI_SD_SLOTA) + || (mode == MCI_MMC_SLOTB) || (mode == MCI_SD_SLOTB) + || (mode == MCI_MMC4_SLOTA) || (mode == MCI_MMC4_SLOTB)); + + // Initialize the MCI driver structure + pMci->pMciHw = pMciHw; + pMci->mciId = mciId; + pMci->mciMode = mode; + pMci->semaphore = 1; + pMci->pCommand = 0; + + // Enable the MCI clock + WRITE_PMC(AT91C_BASE_PMC, PMC_PCER, (1 << mciId)); + + // Reset the MCI + WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_SWRST); + + // Disable the MCI + WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_MCIDIS | AT91C_MCI_PWSDIS); + + // Disable all the interrupts + WRITE_MCI(pMciHw, MCI_IDR, 0xFFFFFFFF); + + // Set the Data Timeout Register + WRITE_MCI(pMciHw, MCI_DTOR, DTOR_1MEGA_CYCLES); + + // Set the Mode Register: 400KHz for MCK = 48MHz (CLKDIV = 58) + clkDiv = (BOARD_MCK / (MCI_INITIAL_SPEED * 2)) - 1; + WRITE_MCI(pMciHw, MCI_MR, (clkDiv | (AT91C_MCI_PWSDIV & (0x7 << 8)))); + + // Set the SDCard Register + WRITE_MCI(pMciHw, MCI_SDCR, mode); + + // Enable the MCI and the Power Saving + WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_MCIEN); + + // Disable the DMA interface + WRITE_MCI(pMciHw, MCI_DMA, AT91C_MCI_DMAEN_DISABLE); + + // Configure MCI + //mciCfg = AT91C_MCI_FIFOMODE_AMOUNTDATA | AT91C_MCI_FERRCTRL_RWCMD; + mciCfg = AT91C_MCI_FIFOMODE_ONEDATA | AT91C_MCI_FERRCTRL_RWCMD; + + WRITE_MCI(pMciHw, MCI_CFG, mciCfg); + + // Disable the MCI peripheral clock. + WRITE_PMC(AT91C_BASE_PMC, PMC_PCDR, (1 << mciId)); +} + +//------------------------------------------------------------------------------ +/// Close a MCI driver instance and the underlying peripheral. +/// \param pMci Pointer to a MCI driver instance. +/// \param pMciHw Pointer to a MCI peripheral. +/// \param mciId MCI peripheral identifier. +//------------------------------------------------------------------------------ +void MCI_Close(Mci *pMci) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMciHw); + + // Initialize the MCI driver structure + pMci->semaphore = 1; + pMci->pCommand = 0; + + // Disable the MCI peripheral clock. + WRITE_PMC(AT91C_BASE_PMC, PMC_PCDR, (1 << pMci->mciId)); + + // Disable the MCI + WRITE_MCI(pMciHw, MCI_CR, AT91C_MCI_MCIDIS); + + // Disable all the interrupts + WRITE_MCI(pMciHw, MCI_IDR, 0xFFFFFFFF); +} + +//------------------------------------------------------------------------------ +/// Get the MCI CLKDIV in the MCI_MR register. The max. for MCI clock is +/// MCK/2 and corresponds to CLKDIV = 0 +/// \param pMci Pointer to the low level MCI driver. +/// \param mciSpeed MCI clock speed in Hz. +//------------------------------------------------------------------------------ +unsigned int MCI_GetSpeed(Mci *pMci, unsigned int *mciDiv) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + unsigned int mciMr; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMci->pMciHw); + + // Get the Mode Register + mciMr = READ_MCI(pMciHw, MCI_MR); + mciMr &= AT91C_MCI_CLKDIV; + if (mciDiv) *mciDiv = mciMr; + return (BOARD_MCK / 2 / (mciMr + 1)); +} + +//------------------------------------------------------------------------------ +/// Configure the MCI CLKDIV in the MCI_MR register. The max. for MCI clock is +/// MCK/2 and corresponds to CLKDIV = 0 +/// \param pMci Pointer to the low level MCI driver. +/// \param mciSpeed MCI clock speed in Hz. +/// \param mciLimit MCI clock limit in Hz, if not limit, set mciLimit to zero. +/// \return The actual speed used, 0 for fail. +//------------------------------------------------------------------------------ +unsigned int MCI_SetSpeed(Mci *pMci, + unsigned int mciSpeed, + unsigned int mciLimit) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + unsigned int mciMr; + unsigned int clkdiv; + unsigned int divLimit = 0; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMci->pMciHw); + + mciMr = READ_MCI(pMciHw, MCI_MR) & (~AT91C_MCI_CLKDIV); + + // Multimedia Card Interface clock (MCCK or MCI_CK) is Master Clock (MCK) + // divided by (2*(CLKDIV+1)) + // mciSpeed = MCK / (2*(CLKDIV+1)) + if (mciLimit) divLimit = (BOARD_MCK / 2 / mciLimit); + if (mciSpeed > 0) { + clkdiv = (BOARD_MCK / 2 / mciSpeed); + if (mciLimit && clkdiv < divLimit) + clkdiv = divLimit; + if (clkdiv > 0) + clkdiv -= 1; + ASSERT( (clkdiv & 0xFFFFFF00) == 0, "mciSpeed too small"); + } + else clkdiv = 0; + + WRITE_MCI(pMciHw, MCI_MR, mciMr | clkdiv); + return (BOARD_MCK / 2 / (clkdiv + 1)); +} + +//------------------------------------------------------------------------------ +/// Configure the MCI_CFG to enable the HS mode +/// \param pMci Pointer to the low level MCI driver. +/// \param hsEnable 1 to enable, 0 to disable HS mode. +//------------------------------------------------------------------------------ +void MCI_EnableHsMode(Mci *pMci, unsigned char hsEnable) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + unsigned int cfgr; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMci->pMciHw); + + cfgr = READ_MCI(pMciHw, MCI_CFG); + if (hsEnable) cfgr |= AT91C_MCI_HSMODE_ENABLE; + else cfgr &= ~AT91C_MCI_HSMODE_ENABLE; +} + +//------------------------------------------------------------------------------ +/// Configure the MCI SDCBUS in the MCI_SDCR register. Only two modes available +/// +/// \param pMci Pointer to the low level MCI driver. +/// \param busWidth MCI bus width mode. +//------------------------------------------------------------------------------ +void MCI_SetBusWidth(Mci *pMci, unsigned char busWidth) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + unsigned int mciSdcr; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMci->pMciHw); + + mciSdcr = (READ_MCI(pMciHw, MCI_SDCR) & ~(AT91C_MCI_SCDBUS)); + + WRITE_MCI(pMciHw, MCI_SDCR, mciSdcr | busWidth); +} + +//------------------------------------------------------------------------------ +/// Starts a MCI transfer. This is a non blocking function. It will return +/// as soon as the transfer is started. +/// Return 0 if successful; otherwise returns MCI_ERROR_LOCK if the driver is +/// already in use. +/// \param pMci Pointer to an MCI driver instance. +/// \param pCommand Pointer to the command to execute. +//------------------------------------------------------------------------------ +unsigned char MCI_SendCommand(Mci *pMci, MciCmd *pCommand) +{ + AT91PS_MCI pMciHw = pMci->pMciHw; + unsigned int mciIer, mciMr; + unsigned int transSize; + unsigned int mciBlkr; + + #if defined(MCI_DMA_ENABLE) + unsigned int mciDma; + #endif + + SANITY_CHECK(pMci); + SANITY_CHECK(pMciHw); + SANITY_CHECK(pCommand); + + // Try to acquire the MCI semaphore + if (pMci->semaphore == 0) { + + return MCI_ERROR_LOCK; + } + pMci->semaphore--; + + // Command is now being executed + pMci->pCommand = pCommand; + pCommand->status = MCI_STATUS_PENDING; + + // Enable the MCI peripheral clock + WRITE_PMC(AT91C_BASE_PMC, PMC_PCER, (1 << pMci->mciId)); + + // Disable MCI clock, for multi-block data transfer + MCICK_DISABLE(pMciHw); + + // Set Default Mode register value + mciMr = READ_MCI(pMciHw, MCI_MR) & (~( AT91C_MCI_WRPROOF + |AT91C_MCI_RDPROOF + |AT91C_MCI_BLKLEN)); + // Command with DATA stage + if (pCommand->blockSize && pCommand->nbBlock) { + // Enable dma + #if defined(MCI_DMA_ENABLE) + mciDma = READ_MCI(pMciHw, MCI_DMA) | AT91C_MCI_DMAEN_ENABLE; + WRITE_MCI(pMciHw, MCI_DMA, mciDma); + #endif + + // New transfer + if(pCommand->tranType == MCI_NEW_TRANSFER) { + + // Set block size + WRITE_MCI(pMciHw, MCI_MR, mciMr | AT91C_MCI_RDPROOF + | AT91C_MCI_WRPROOF + |(pCommand->blockSize << 16)); + + mciBlkr = READ_MCI(pMciHw, MCI_BLKR) & (~AT91C_MCI_BCNT); + WRITE_MCI(pMciHw, MCI_BLKR, mciBlkr | pCommand->nbBlock); + } + + transSize = (pCommand->nbBlock * pCommand->blockSize) / 4; + if ((pCommand->blockSize & 0x3) != 0) + transSize++; + + // DATA transfer from card to host + if (pCommand->isRead) { + + #if defined(MCI_DMA_ENABLE) + DMACH_MCI_P2M(BOARD_MCI_DMA_CHANNEL, + (unsigned int*)&pMciHw->MCI_FIFO, + (unsigned int*) pCommand->pData, + transSize, 1); + DMACH_EnableIt(pMciHw, BOARD_MCI_DMA_CHANNEL); + DMA_EnableChannel(BOARD_MCI_DMA_CHANNEL); + mciIer = AT91C_MCI_DMADONE | STATUS_ERRORS; + #else + mciIer = AT91C_MCI_CMDRDY | STATUS_ERRORS; + #endif + } + // DATA transfer from host to card + else { + + #if defined(MCI_DMA_ENABLE) + DMACH_MCI_M2P(BOARD_MCI_DMA_CHANNEL, + (unsigned int*) pCommand->pData, + (unsigned int*)&pMciHw->MCI_FIFO, + transSize, 1); + DMACH_EnableIt(pMciHw, BOARD_MCI_DMA_CHANNEL); + DMA_EnableChannel(BOARD_MCI_DMA_CHANNEL); + mciIer = AT91C_MCI_DMADONE | STATUS_ERRORS; + #else + mciIer = AT91C_MCI_CMDRDY | STATUS_ERRORS; + #endif + } + } + // Start an infinite block transfer (but no data in current command) + else if (pCommand->dataTran) { + // Set block size + WRITE_MCI(pMciHw, MCI_MR, mciMr | AT91C_MCI_RDPROOF + | AT91C_MCI_WRPROOF + |(pCommand->blockSize << 16)); + // Set data length: 0 + mciBlkr = READ_MCI(pMciHw, MCI_BLKR) & (~AT91C_MCI_BCNT); + WRITE_MCI(pMciHw, MCI_BLKR, mciBlkr); + mciIer = AT91C_MCI_CMDRDY | STATUS_ERRORS; + } + // No data transfer: stop at the end of the command + else{ + WRITE_MCI(pMciHw, MCI_MR, mciMr); + mciIer = AT91C_MCI_CMDRDY | STATUS_ERRORS; + } + + // Enable MCI clock + MCICK_ENABLE(pMciHw); + + // Send the command + if((pCommand->tranType != MCI_CONTINUE_TRANSFER) + || (pCommand->blockSize == 0)) { + + WRITE_MCI(pMciHw, MCI_ARGR, pCommand->arg); + WRITE_MCI(pMciHw, MCI_CMDR, pCommand->cmd); + } + + // Ignore data error + mciIer &= ~( AT91C_MCI_UNRE + | AT91C_MCI_OVRE + | AT91C_MCI_DTOE + | AT91C_MCI_DCRCE + | AT91C_MCI_BLKOVRE + | AT91C_MCI_CSTOE); + + // Interrupt enable shall be done after PDC TXTEN and RXTEN + WRITE_MCI(pMciHw, MCI_IER, mciIer); + + return 0; +} + +//------------------------------------------------------------------------------ +/// Check NOTBUSY and DTIP bits of status register on the given MCI driver. +/// Return value, 0 for bus ready, 1 for bus busy +/// \param pMci Pointer to a MCI driver instance. +//------------------------------------------------------------------------------ +unsigned char MCI_CheckBusy(Mci *pMci) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + volatile unsigned int status; + + // Enable MCI clock + MCICK_ENABLE(pMciHw); + + status = READ_MCI(pMciHw, MCI_SR); + + if( ((status & AT91C_MCI_NOTBUSY)!=0) + && ((status & AT91C_MCI_DTIP)==0) + ) { + + // Disable MCI clock + MCICK_DISABLE(pMciHw); + + return 0; + } + else { + return 1; + } +} + +//------------------------------------------------------------------------------ +/// Check BLKE bit of status register on the given MCI driver. +/// \param pMci Pointer to a MCI driver instance. +//------------------------------------------------------------------------------ +unsigned char MCI_CheckBlke(Mci *pMci) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + unsigned int status; + + status = READ_MCI(pMciHw, MCI_SR); + // TRACE_DEBUG("status %x\n\r",status); + + if((status & AT91C_MCI_BLKE)!=0) { + return 0; + } + else { + return 1; + } +} + +//------------------------------------------------------------------------------ +/// Processes pending events on the given MCI driver. +/// \param pMci Pointer to a MCI driver instance. +//------------------------------------------------------------------------------ +void MCI_Handler(Mci *pMci) +{ + AT91S_MCI *pMciHw = pMci->pMciHw; + volatile MciCmd *pCommand = pMci->pCommand; + volatile unsigned int status, status0, mask; + unsigned char i; + + SANITY_CHECK(pMci); + SANITY_CHECK(pMciHw); + SANITY_CHECK(pCommand); + + // Read the status register + status0 = READ_MCI(pMciHw, MCI_SR); + mask = READ_MCI(pMciHw, MCI_IMR); + //TRACE_INFO("iST %x\n\r", status); + status = status0 & mask; + //TRACE_INFO("iSM %x\n\r", status); + + // Check if an error has occured + if ((status & STATUS_ERRORS) != 0) { + + // Check error code + if ((status & STATUS_ERRORS) == AT91C_MCI_RTOE) { + + pCommand->status = MCI_STATUS_NORESPONSE; + } + // if the command is SEND_OP_COND the CRC error flag is always present + // (cf : R3 response) + else if (( (status & STATUS_ERRORS) != AT91C_MCI_RCRCE) + || ( (pCommand->cmd != SDCARD_APP_OP_COND_CMD) + && (pCommand->cmd != MMC_SEND_OP_COND_CMD))) { + + pCommand->status = MCI_STATUS_ERROR; + } + // printf("iErr%x\n\r", (status & STATUS_ERRORS)); + } + mask &= ~STATUS_ERRORS; + + // Check if a command has been completed + if (status & AT91C_MCI_CMDRDY) { + + WRITE_MCI(pMciHw, MCI_IDR, AT91C_MCI_CMDRDY); + if (pCommand->isRead == 0 && + pCommand->tranType == MCI_STOP_TRANSFER) { + if (status0 & AT91C_MCI_XFRDONE) { + MCICK_DISABLE(pMciHw); + } + else { + WRITE_MCI(pMciHw, MCI_IER, AT91C_MCI_XFRDONE); + } + } + else { + mask &= ~AT91C_MCI_CMDRDY; + if (pCommand->dataTran == 0) { + MCICK_DISABLE(pMciHw); + } + } + } + + // Check if transfer stopped + if (status & AT91C_MCI_XFRDONE) { + mask &= ~AT91C_MCI_XFRDONE; + MCICK_DISABLE(pMciHw); + } + +#if defined(MCI_DMA_ENABLE) + + // Check FIFOEMPTY + if (status & AT91C_MCI_FIFOEMPTY) { + mask &= ~AT91C_MCI_FIFOEMPTY; + MCICK_DISABLE(pMciHw); + } + + // Check if a DMA transfer has been completed + if (status & AT91C_MCI_DMADONE) { + + unsigned int intFlag; + intFlag = DMA_GetInterruptMask(); + intFlag = ~intFlag; + intFlag |= (AT91C_HDMA_BTC0 << BOARD_MCI_DMA_CHANNEL); + DMA_DisableIt(intFlag); + + WRITE_MCI(pMciHw, MCI_IDR, AT91C_MCI_DMADONE); + if ( pCommand->isRead == 0 && + (status0 & AT91C_MCI_FIFOEMPTY) == 0 ) { + WRITE_MCI(pMciHw, MCI_IER, AT91C_MCI_FIFOEMPTY); + } + else { + MCICK_DISABLE(pMciHw); + mask &= ~AT91C_MCI_DMADONE; + } + } +#endif + + // All non-error mask done, complete the command + if (!mask || pCommand->status != MCI_STATUS_PENDING) { + + // Store the card response in the provided buffer + if (pCommand->pResp) { + unsigned char resSize; + switch (pCommand->resType) { + case 1: case 3: case 4: case 5: case 6: case 7: + resSize = 1; break; + case 2: resSize = 4; break; + default: resSize = 0; break; + } + for (i=0; i < resSize; i++) { + pCommand->pResp[i] = READ_MCI(pMciHw, MCI_RSPR[0]); + } + } + + // If no error occured, the transfer is successful + if (pCommand->status == MCI_STATUS_PENDING) + pCommand->status = 0; + + // Disable interrupts + WRITE_MCI(pMciHw, MCI_IDR, READ_MCI(pMciHw, MCI_IMR)); + + // Release the semaphore + pMci->semaphore++; + + // Invoke the callback associated with the current command (if any) + if (pCommand->callback) { + (pCommand->callback)(pCommand->status, (void*)pCommand); + } + } +} + +//------------------------------------------------------------------------------ +/// Returns 1 if the given MCI transfer is complete; otherwise returns 0. +/// \param pCommand Pointer to a MciCmd instance. +//------------------------------------------------------------------------------ +unsigned char MCI_IsTxComplete(MciCmd *pCommand) +{ + if (pCommand->status != MCI_STATUS_PENDING) { + if (pCommand->status != 0) { + TRACE_DEBUG("MCI_IsTxComplete %d\n\r", pCommand->status); + } + return 1; + } + else { + return 0; + } +} + +//------------------------------------------------------------------------------ +/// Check whether the MCI is using the FIFO transfer mode +/// \param pMci Pointer to a Mci instance. +/// \param pCommand Pointer to a MciCmd instance. +//------------------------------------------------------------------------------ +unsigned int MCI_FifoTransfer(Mci *pMci, MciCmd *pCommand) +{ + unsigned int status=0; + unsigned int nbTransfer=0; + unsigned int i; + AT91S_MCI *pMciHw = pMci->pMciHw; + unsigned int *pMem; + + SANITY_CHECK(pMci); + SANITY_CHECK(pCommand); + + // If using DMA mode, return +#if defined(MCI_DMA_ENABLE) + return 0; +#endif + + TRACE_DEBUG("MCIFifo:%d,%d\n\r", pCommand->isRead, pCommand->nbBlock); + + if (pCommand->nbBlock == 0 || pCommand->blockSize == 0) + return 0; + + pMem = (unsigned int*)pCommand->pData; + + // Get transfer size + nbTransfer = (pCommand->blockSize) * (pCommand->nbBlock) / 4; + if((pCommand->blockSize) * (pCommand->nbBlock) % 4) { + nbTransfer++; + } + + if (pCommand->isRead) { + + // Read RDR loop + for(i=0; i %x", status); + } + } + TRACE_DEBUG_WP("\n\r"); + TRACE_DEBUG(" DPIT 0 stat %x\n\r", status); + while((status & (AT91C_MCI_FIFOEMPTY + | AT91C_MCI_BLKE + | AT91C_MCI_XFRDONE)) == 0) { + status = READ_MCI(pMciHw, MCI_SR); + } + TRACE_DEBUG(" FIFO EMPTY stat %x\n\r", status); + } + #endif + + return status; +} diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/mci/mci_hs.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/mci/mci_hs.h new file mode 100644 index 000000000..bab27940f --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/mci/mci_hs.h @@ -0,0 +1,205 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \page "mci" +/// +/// !Purpose +/// +/// mci-interface driver +/// +/// !Usage +/// +/// -# MCI_Init: Initializes a MCI driver instance and the underlying peripheral. +/// -# MCI_SetSpeed : Configure the MCI CLKDIV in the MCI_MR register. +/// -# MCI_SendCommand: Starts a MCI transfer. +/// -# MCI_Handler : Interrupt handler which is called by ISR handler. +/// -# MCI_SetBusWidth : Configure the MCI SDCBUS in the MCI_SDCR register. +//------------------------------------------------------------------------------ + + +#ifndef MCI_HS_H +#define MCI_HS_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +//------------------------------------------------------------------------------ +// Constants +//------------------------------------------------------------------------------ + +/// Transfer is pending. +#define MCI_STATUS_PENDING 1 +/// Transfer has been aborted because an error occured. +#define MCI_STATUS_ERROR 2 +/// Card did not answer command. +#define MCI_STATUS_NORESPONSE 3 + +/// MCI driver is currently in use. +#define MCI_ERROR_LOCK 1 + +/// MCI configuration with 1-bit data bus on slot A (for MMC cards). +#define MCI_MMC_SLOTA (AT91C_MCI_SCDSEL_SLOTA | AT91C_MCI_SCDBUS_1BIT) +/// MCI configuration with 4-bit data bus on slot A (for SD cards). +#define MCI_SD_SLOTA (AT91C_MCI_SCDSEL_SLOTA | AT91C_MCI_SCDBUS_4BITS) +#ifdef AT91C_MCI_SCDBUS_8BITS +/// MCI configuration with 1-bit data bus on slot A (for MMC cards). +#define MCI_MMC4_SLOTA (AT91C_MCI_SCDSEL_SLOTA | AT91C_MCI_SCDBUS_8BITS) +#endif +#ifdef AT91C_MCI_SCDSEL_SLOTB +/// MCI configuration with 1-bit data bus on slot B (for MMC cards). +#define MCI_MMC_SLOTB (AT91C_MCI_SCDSEL_SLOTB | AT91C_MCI_SCDBUS_1BIT) +/// MCI configuration with 4-bit data bus on slot B (for SD cards). +#define MCI_SD_SLOTB (AT91C_MCI_SCDSEL_SLOTB | AT91C_MCI_SCDBUS_4BITS) +#ifdef AT91C_MCI_SCDBUS_8BITS +/// MCI configuration with 1-bit data bus on slot A (for MMC cards). +#define MCI_MMC4_SLOTB (AT91C_MCI_SCDSEL_SLOTB | AT91C_MCI_SCDBUS_8BITS) +#endif +#else +#define MCI_MMC_SLOTB MCI_MMC_SLOTA +#define MCI_SD_SLOTB MCI_SD_SLOTA +#endif + +/// Start new data transfer +#define MCI_NEW_TRANSFER 0 +/// Continue data transfer +#define MCI_CONTINUE_TRANSFER 1 +/// Stop data transfer +#define MCI_STOP_TRANSFER 2 + +/// MCI SD Bus Width 1-bit +#define MCI_SDCBUS_1BIT (0 << 7) +/// MCI SD Bus Width 4-bit +#define MCI_SDCBUS_4BIT (1 << 7) +/// MCI SD Bus Width 8-bit +#define MCI_SDCBUS_8BIT (3 << 6) + +/// The MCI Clock Speed after initialize (400K) +#define MCI_INITIAL_SPEED 400000 + +/// MCI using DMA? +#define MCI_DMA_ENABLE 1 + +//------------------------------------------------------------------------------ +// Types +//------------------------------------------------------------------------------ + +/// MCI end-of-transfer callback function. +typedef void (*MciCallback)(unsigned char status, void *pCommand); + +//------------------------------------------------------------------------------ +/// MCI Transfer Request prepared by the application upper layer. This structure +/// is sent to the MCI_SendCommand function to start the transfer. At the end of +/// the transfer, the callback is invoked by the interrupt handler. +//------------------------------------------------------------------------------ +typedef struct _MciCmd { + + /// Command code. + unsigned int cmd; + /// Command argument. + unsigned int arg; + /// Data buffer. + unsigned char *pData; + /// Size of data block in bytes. + unsigned short blockSize; + /// Number of blocks to be transfered + unsigned short nbBlock; + /// Response buffer. + unsigned int *pResp; + /// Optional user-provided callback function. + MciCallback callback; + /// Optional argument to the callback function. + void *pArg; + /// SD card response type. + unsigned char resType; + /// Indicate if there is data transfer + unsigned char dataTran; + /// Indicate if continue to transfer data + unsigned char tranType; + /// Indicates if the command is a read operation. + unsigned char isRead; + + /// Command status. + volatile int status; +} MciCmd; + +//------------------------------------------------------------------------------ +/// MCI driver structure. Holds the internal state of the MCI driver and +/// prevents parallel access to a MCI peripheral. +//------------------------------------------------------------------------------ +typedef struct { + + /// Pointer to a MCI peripheral. + AT91S_MCI *pMciHw; + /// Pointer to currently executing command. + MciCmd *pCommand; + /// MCI peripheral identifier. + unsigned char mciId; + /// MCI HW mode + unsigned char mciMode; + /// Mutex. + volatile char semaphore; +} Mci; + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void MCI_Init( + Mci *pMci, + AT91PS_MCI pMciHw, + unsigned char mciId, + unsigned int mode); +extern unsigned int MCI_GetSpeed(Mci *pMci, unsigned int *mciDiv); + +extern unsigned int MCI_SetSpeed(Mci *pMci, + unsigned int mciSpeed, + unsigned int mciLimit); + +extern unsigned char MCI_SendCommand(Mci *pMci, MciCmd *pMciCmd); + +extern void MCI_Handler(Mci *pMci); + +extern unsigned char MCI_IsTxComplete(MciCmd *pMciCmd); + +extern unsigned char MCI_CheckBusy(Mci *pMci); + +extern void MCI_Close(Mci *pMci); + +extern void MCI_EnableHsMode(Mci * pMci, unsigned char hsEnable); + +extern void MCI_SetBusWidth(Mci *pMci, unsigned char busWidth); + +extern unsigned int MCI_FifoTransfer(Mci * pMci, MciCmd * pCommand); + +#endif //#ifndef MCI_HS_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pio/pio.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pio/pio.c new file mode 100644 index 000000000..288e6bbed --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pio/pio.c @@ -0,0 +1,382 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "pio.h" +#include + +//------------------------------------------------------------------------------ +// Local Functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Configures one or more pin(s) of a PIO controller as being controlled by +/// peripheral A. Optionally, the corresponding internal pull-up(s) can be +/// enabled. +/// \param pio Pointer to a PIO controller. +/// \param mask Bitmask of one or more pin(s) to configure. +/// \param enablePullUp Indicates if the pin(s) internal pull-up shall be +/// configured. +//------------------------------------------------------------------------------ +static void PIO_SetPeripheralA( + AT91S_PIO *pio, + unsigned int mask, + unsigned char enablePullUp) +{ +#if !defined(AT91C_PIOA_ASR) + unsigned int abmr; +#endif + + // Disable interrupts on the pin(s) + pio->PIO_IDR = mask; + + // Enable the pull-up(s) if necessary + if (enablePullUp) { + + pio->PIO_PPUER = mask; + } + else { + + pio->PIO_PPUDR = mask; + } + + // Configure pin +#if defined(AT91C_PIOA_ASR) + pio->PIO_ASR = mask; +#else + abmr = pio->PIO_ABSR; + pio->PIO_ABSR &= (~mask & abmr); +#endif + pio->PIO_PDR = mask; +} + +//------------------------------------------------------------------------------ +/// Configures one or more pin(s) of a PIO controller as being controlled by +/// peripheral B. Optionally, the corresponding internal pull-up(s) can be +/// enabled. +/// \param pio Pointer to a PIO controller. +/// \param mask Bitmask of one or more pin(s) to configure. +/// \param enablePullUp Indicates if the pin(s) internal pull-up shall be +/// configured. +//------------------------------------------------------------------------------ +static void PIO_SetPeripheralB( + AT91S_PIO *pio, + unsigned int mask, + unsigned char enablePullUp) +{ +#if !defined(AT91C_PIOA_BSR) + unsigned int abmr; +#endif + + // Disable interrupts on the pin(s) + pio->PIO_IDR = mask; + + // Enable the pull-up(s) if necessary + if (enablePullUp) { + + pio->PIO_PPUER = mask; + } + else { + + pio->PIO_PPUDR = mask; + } + + // Configure pin +#if defined(AT91C_PIOA_BSR) + pio->PIO_BSR = mask; +#else + abmr = pio->PIO_ABSR; + pio->PIO_ABSR = mask | abmr; +#endif + pio->PIO_PDR = mask; +} + +#if defined(AT91C_PIOA_IFDGSR) //Glitch or Debouncing filter selection supported +//------------------------------------------------------------------------------ +/// Configures Glitch or Debouncing filter for input +/// \param pio Pointer to a PIO controller. +/// \param mask Bitmask for filter selection. +/// each of 32 bit field, 0 is Glitch, 1 is Debouncing +/// \param clkDiv Clock divider if Debouncing select, using the lowest 14 bits +/// common for all PIO line of selecting deboucing filter +//------------------------------------------------------------------------------ +static void PIO_SetFilter( + AT91S_PIO *pio, + unsigned int filterSel, + unsigned int clkDiv) +{ + pio->PIO_DIFSR = filterSel;//set Debouncing, 0 bit field no effect + pio->PIO_SCIFSR = ~filterSel;//set Glitch, 0 bit field no effect + + pio->PIO_SCDR = clkDiv & 0x3FFF;//the lowest 14 bits work +} +#endif + +//------------------------------------------------------------------------------ +/// Configures one or more pin(s) or a PIO controller as inputs. Optionally, +/// the corresponding internal pull-up(s) and glitch filter(s) can be +/// enabled. +/// \param pio Pointer to a PIO controller. +/// \param mask Bitmask indicating which pin(s) to configure as input(s). +/// \param enablePullUp Indicates if the internal pull-up(s) must be enabled. +/// \param enableFilter Indicates if the glitch filter(s) must be enabled. +//------------------------------------------------------------------------------ +static void PIO_SetInput( + AT91S_PIO *pio, + unsigned int mask, + unsigned char enablePullUp, + unsigned char enableFilter) +{ + // Disable interrupts + pio->PIO_IDR = mask; + + // Enable pull-up(s) if necessary + if (enablePullUp) { + + pio->PIO_PPUER = mask; + } + else { + + pio->PIO_PPUDR = mask; + } + + // Enable filter(s) if necessary + if (enableFilter) { + + pio->PIO_IFER = mask; + } + else { + + pio->PIO_IFDR = mask; + } + + // Configure pin as input + pio->PIO_ODR = mask; + pio->PIO_PER = mask; +} + +//------------------------------------------------------------------------------ +/// Configures one or more pin(s) of a PIO controller as outputs, with the +/// given default value. Optionally, the multi-drive feature can be enabled +/// on the pin(s). +/// \param pio Pointer to a PIO controller. +/// \param mask Bitmask indicating which pin(s) to configure. +/// \param defaultValue Default level on the pin(s). +/// \param enableMultiDrive Indicates if the pin(s) shall be configured as +/// open-drain. +/// \param enablePullUp Indicates if the pin shall have its pull-up activated. +//------------------------------------------------------------------------------ +static void PIO_SetOutput( + AT91S_PIO *pio, + unsigned int mask, + unsigned char defaultValue, + unsigned char enableMultiDrive, + unsigned char enablePullUp) +{ + // Disable interrupts + pio->PIO_IDR = mask; + + // Enable pull-up(s) if necessary + if (enablePullUp) { + + pio->PIO_PPUER = mask; + } + else { + + pio->PIO_PPUDR = mask; + } + + // Enable multi-drive if necessary + if (enableMultiDrive) { + + pio->PIO_MDER = mask; + } + else { + + pio->PIO_MDDR = mask; + } + + // Set default value + if (defaultValue) { + + pio->PIO_SODR = mask; + } + else { + + pio->PIO_CODR = mask; + } + + // Configure pin(s) as output(s) + pio->PIO_OER = mask; + pio->PIO_PER = mask; +} + +//------------------------------------------------------------------------------ +// Global Functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Configures a list of Pin instances, each of which can either hold a single +/// pin or a group of pins, depending on the mask value; all pins are configured +/// by this function. The size of the array must also be provided and is easily +/// computed using PIO_LISTSIZE whenever its length is not known in advance. +/// \param list Pointer to a list of Pin instances. +/// \param size Size of the Pin list (calculated using PIO_LISTSIZE). +/// \return 1 if the pins have been configured properly; otherwise 0. +//------------------------------------------------------------------------------ +unsigned char PIO_Configure(const Pin *list, unsigned int size) +{ + // Configure pins + while (size > 0) { + + switch (list->type) { + + case PIO_PERIPH_A: + PIO_SetPeripheralA(list->pio, + list->mask, + (list->attribute & PIO_PULLUP) ? 1 : 0); + break; + + case PIO_PERIPH_B: + PIO_SetPeripheralB(list->pio, + list->mask, + (list->attribute & PIO_PULLUP) ? 1 : 0); + break; + + case PIO_INPUT: + AT91C_BASE_PMC->PMC_PCER = 1 << list->id; + PIO_SetInput(list->pio, + list->mask, + (list->attribute & PIO_PULLUP) ? 1 : 0, + (list->attribute & PIO_DEGLITCH)? 1 : 0); + + #if defined(AT91C_PIOA_IFDGSR) //PIO3 with Glitch or Debouncing selection + //if glitch input filter enabled, set it + if(list->attribute & PIO_DEGLITCH)//Glitch input filter enabled + PIO_SetFilter(list->pio, + list->inFilter.filterSel, + list->inFilter.clkDivider); + #endif + break; + + case PIO_OUTPUT_0: + case PIO_OUTPUT_1: + PIO_SetOutput(list->pio, + list->mask, + (list->type == PIO_OUTPUT_1), + (list->attribute & PIO_OPENDRAIN) ? 1 : 0, + (list->attribute & PIO_PULLUP) ? 1 : 0); + break; + + default: return 0; + } + + list++; + size--; + } + + return 1; +} + +//------------------------------------------------------------------------------ +/// Sets a high output level on all the PIOs defined in the given Pin instance. +/// This has no immediate effects on PIOs that are not output, but the PIO +/// controller will memorize the value they are changed to outputs. +/// \param pin Pointer to a Pin instance describing one or more pins. +//------------------------------------------------------------------------------ +void PIO_Set(const Pin *pin) +{ + pin->pio->PIO_SODR = pin->mask; +} + +//------------------------------------------------------------------------------ +/// Sets a low output level on all the PIOs defined in the given Pin instance. +/// This has no immediate effects on PIOs that are not output, but the PIO +/// controller will memorize the value they are changed to outputs. +/// \param pin Pointer to a Pin instance describing one or more pins. +//------------------------------------------------------------------------------ +void PIO_Clear(const Pin *pin) +{ + pin->pio->PIO_CODR = pin->mask; +} + +//------------------------------------------------------------------------------ +/// Returns 1 if one or more PIO of the given Pin instance currently have a high +/// level; otherwise returns 0. This method returns the actual value that is +/// being read on the pin. To return the supposed output value of a pin, use +/// PIO_GetOutputDataStatus() instead. +/// \param pin Pointer to a Pin instance describing one or more pins. +/// \return 1 if the Pin instance contains at least one PIO that currently has +/// a high level; otherwise 0. +//------------------------------------------------------------------------------ +unsigned char PIO_Get(const Pin *pin) +{ + unsigned int reg; + if ((pin->type == PIO_OUTPUT_0) || (pin->type == PIO_OUTPUT_1)) { + + reg = pin->pio->PIO_ODSR; + } + else { + + reg = pin->pio->PIO_PDSR; + } + + if ((reg & pin->mask) == 0) { + + return 0; + } + else { + + return 1; + } +} + + +//------------------------------------------------------------------------------ +/// Returns 1 if one or more PIO of the given Pin are configured to output a +/// high level (even if they are not output). +/// To get the actual value of the pin, use PIO_Get() instead. +/// \param pin Pointer to a Pin instance describing one or more pins. +/// \return 1 if the Pin instance contains at least one PIO that is configured +/// to output a high level; otherwise 0. +//------------------------------------------------------------------------------ +unsigned char PIO_GetOutputDataStatus(const Pin *pin) +{ + if ((pin->pio->PIO_ODSR & pin->mask) == 0) { + + return 0; + } + else { + + return 1; + } +} diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pio/pio.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pio/pio.h new file mode 100644 index 000000000..2c78d731b --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pio/pio.h @@ -0,0 +1,225 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// This file provides a basic API for PIO configuration and usage of +/// user-controlled pins. Please refer to the board.h file for a list of +/// available pin definitions. +/// +/// !!!Usage +/// +/// -# Define a constant pin description array such as the following one, using +/// the existing definitions provided by the board.h file if possible: +/// \code +/// const Pin pPins[] = {PIN_USART0_TXD, PIN_USART0_RXD}; +/// \endcode +/// Alternatively, it is possible to add new pins by provided the full Pin +/// structure: +/// \code +/// // Pin instance to configure PA10 & PA11 as inputs with the internal +/// // pull-up enabled. +/// const Pin pPins = { +/// (1 << 10) | (1 << 11), +/// AT91C_BASE_PIOA, +/// AT91C_ID_PIOA, +/// PIO_INPUT, +/// PIO_PULLUP +/// }; +/// \endcode +/// -# Configure a pin array by calling PIO_Configure() with a pointer to the +/// array and its size (which is computed using the PIO_LISTSIZE macro). +/// -# Change and get the value of a user-controlled pin using the PIO_Set, +/// PIO_Clear and PIO_Get methods. +/// -# Get the level being currently output by a user-controlled pin configured +/// as an output using PIO_GetOutputDataStatus(). +//------------------------------------------------------------------------------ + +#ifndef PIO_H +#define PIO_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +//------------------------------------------------------------------------------ +// Global Definitions +//------------------------------------------------------------------------------ + +/// The pin is controlled by the associated signal of peripheral A. +#define PIO_PERIPH_A 0 +/// The pin is controlled by the associated signal of peripheral B. +#define PIO_PERIPH_B 1 +/// The pin is an input. +#define PIO_INPUT 2 +/// The pin is an output and has a default level of 0. +#define PIO_OUTPUT_0 3 +/// The pin is an output and has a default level of 1. +#define PIO_OUTPUT_1 4 + +/// Default pin configuration (no attribute). +#define PIO_DEFAULT (0 << 0) +/// The internal pin pull-up is active. +#define PIO_PULLUP (1 << 0) +/// The internal glitch filter is active. +#define PIO_DEGLITCH (1 << 1) +/// The pin is open-drain. +#define PIO_OPENDRAIN (1 << 2) + +//------------------------------------------------------------------------------ +// Global Macros +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Calculates the size of an array of Pin instances. The array must be defined +/// locally (i.e. not a pointer), otherwise the computation will not be correct. +/// \param pPins Local array of Pin instances. +/// \return Number of elements in array. +//------------------------------------------------------------------------------ +#define PIO_LISTSIZE(pPins) (sizeof(pPins) / sizeof(Pin)) + +//------------------------------------------------------------------------------ +// Global Types +//------------------------------------------------------------------------------ +typedef struct _ExtIntMode { + ///indicate which pin to enable/disable additional Interrupt mode + ///each of 32 bit field represents one PIO line. + unsigned int itMask; + ///select Edge or level interrupt detection source + ///each of 32 bit field represents one PIO line, 0 is Edge, 1 is Level + unsigned int edgeLvlSel; + ///select rising/high or falling/low detection event + ///each of 32 bit field represents one PIO line: + ///0 is Falling Edge detection event (if selected Edge interrupt + /// detection source, or Low Level detection (if selected + /// Level interrupt detection source; + ///1 is Rising Edge detection(if selected Edge interrupt + /// source, or Low Level detection event(if selected Level + /// interrupt detection source. + unsigned int lowFallOrRiseHighSel; + +} ExtIntMode; + +typedef struct _GlitchDeBounceFilter { + ///Select Glitch/Debounce filtering for PIO input + ///each of 32 bit field represents one PIO line + ///0 is Glitch, 1 is Debouncing + unsigned int filterSel; + ///slow clock divider selection for Debouncing filter + unsigned int clkDivider:14; + +} GlitchDebounceFilter; + +//------------------------------------------------------------------------------ +/// Describes the type and attribute of one PIO pin or a group of similar pins. +/// The #type# field can have the following values: +/// - PIO_PERIPH_A +/// - PIO_PERIPH_B +/// - PIO_OUTPUT_0 +/// - PIO_OUTPUT_1 +/// - PIO_INPUT +/// +/// The #attribute# field is a bitmask that can either be set to PIO_DEFAULt, +/// or combine (using bitwise OR '|') any number of the following constants: +/// - PIO_PULLUP +/// - PIO_DEGLITCH +/// - PIO_OPENDRAIN +//------------------------------------------------------------------------------ +typedef struct { + + /// Bitmask indicating which pin(s) to configure. + unsigned int mask; + /// Pointer to the PIO controller which has the pin(s). + AT91S_PIO *pio; + /// Peripheral ID of the PIO controller which has the pin(s). + unsigned char id; + /// Pin type. + unsigned char type; + /// Pin attribute. + unsigned char attribute; +#if defined(AT91C_PIOA_AIMMR) + ///Additional Interrupt Mode + ExtIntMode itMode; +#endif + +#if defined(AT91C_PIOA_IFDGSR) + ///Glitch/Debouncing filter + GlitchDebounceFilter inFilter; +#endif + +} Pin; + +//------------------------------------------------------------------------------ +// Global Access Macros +//------------------------------------------------------------------------------ + +//Get Glitch input filter enable/disable status +#define PIO_GetIFSR(pPin) ((pPin)->pio->PIO_IFSR) + +//Get Glitch/Deboucing selection status +#define PIO_GetIFDGSR(pPin) ((pPin)->pio->PIO_IFDGSR) + +//Get Additional PIO interrupt mode mask status +#define PIO_GetAIMMR(pPin) ((pPin)->pio->PIO_AIMMR) + +//Get Interrupt status +#define PIO_GetISR(pPin) ((pPin)->pio->PIO_ISR) + +//Get Edge or Level selection status +#define PIO_GetELSR(pPin) ((pPin)->pio->PIO_ELSR) + +//Get Fall/Rise or Low/High selection status +#define PIO_GetFRLHSR(pPin) ((pPin)->pio->PIO_FRLHSR) + +//Get PIO Lock Status +#define PIO_GetLockStatus(pPin) ((pPin)->pio->PIO_LOCKSR) + +//------------------------------------------------------------------------------ +// Global Functions +//------------------------------------------------------------------------------ + +extern unsigned char PIO_Configure(const Pin *list, unsigned int size); + +extern void PIO_Set(const Pin *pin); + +extern void PIO_Clear(const Pin *pin); + +extern unsigned char PIO_Get(const Pin *pin); + +//extern unsigned int PIO_GetISR(const Pin *pin); + +extern unsigned char PIO_GetOutputDataStatus(const Pin *pin); + +#endif //#ifndef PIO_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pio/pio_it.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pio/pio_it.c new file mode 100644 index 000000000..cdd8a0bb8 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pio/pio_it.c @@ -0,0 +1,461 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +/// Disable traces for this file +#undef TRACE_LEVEL +#define TRACE_LEVEL 0 + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "pio_it.h" +#include "pio.h" +#include +#include +#include +#include + +//------------------------------------------------------------------------------ +// Local definitions +//------------------------------------------------------------------------------ + +/// \exclude +/// Maximum number of interrupt sources that can be defined. This +/// constant can be increased, but the current value is the smallest possible +/// that will be compatible with all existing projects. +#define MAX_INTERRUPT_SOURCES 7 + +//------------------------------------------------------------------------------ +// Local types +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \exclude +/// Describes a PIO interrupt source, including the PIO instance triggering the +/// interrupt and the associated interrupt handler. +//------------------------------------------------------------------------------ +typedef struct { + + /// Pointer to the source pin instance. + const Pin *pPin; + + /// Interrupt handler. + void (*handler)(const Pin *); + +} InterruptSource; + +//------------------------------------------------------------------------------ +// Local variables +//------------------------------------------------------------------------------ + +/// List of interrupt sources. +static InterruptSource pSources[MAX_INTERRUPT_SOURCES]; + +/// Number of currently defined interrupt sources. +static unsigned int numSources; + +//------------------------------------------------------------------------------ +// Local functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Handles all interrupts on the given PIO controller. +/// \param id PIO controller ID. +/// \param pPio PIO controller base address. +//------------------------------------------------------------------------------ +static void PioInterruptHandler(unsigned int id, AT91S_PIO *pPio) +{ + unsigned int status; + unsigned int i; + + // Read PIO controller status + status = pPio->PIO_ISR; + status &= pPio->PIO_IMR; + + // Check pending events + if (status != 0) { + + TRACE_DEBUG("PIO interrupt on PIO controller #%d\n\r", id); + + // Find triggering source + i = 0; + while (status != 0) { + + // There cannot be an unconfigured source enabled. + SANITY_CHECK(i < numSources); + + // Source is configured on the same controller + if (pSources[i].pPin->id == id) { + + // Source has PIOs whose statuses have changed + if ((status & pSources[i].pPin->mask) != 0) { + + TRACE_DEBUG("Interrupt source #%d triggered\n\r", i); + + pSources[i].handler(pSources[i].pPin); + status &= ~(pSources[i].pPin->mask); + } + } + i++; + } + } +} + +//------------------------------------------------------------------------------ +/// Generic PIO interrupt handler. Single entry point for interrupts coming +/// from any PIO controller (PIO A, B, C ...). Dispatches the interrupt to +/// the user-configured handlers. +//------------------------------------------------------------------------------ +void PIO_IT_InterruptHandler(void) +{ +#if defined(AT91C_ID_PIOA) + // Treat PIOA interrupts + PioInterruptHandler(AT91C_ID_PIOA, AT91C_BASE_PIOA); +#endif + +#if defined(AT91C_ID_PIOB) + // Treat PIOB interrupts + PioInterruptHandler(AT91C_ID_PIOB, AT91C_BASE_PIOB); +#endif + +#if defined(AT91C_ID_PIOC) + // Treat PIOC interrupts + PioInterruptHandler(AT91C_ID_PIOC, AT91C_BASE_PIOC); +#endif + +#if defined(AT91C_ID_PIOD) + // Treat PIOD interrupts + PioInterruptHandler(AT91C_ID_PIOD, AT91C_BASE_PIOD); +#endif + +#if defined(AT91C_ID_PIOE) + // Treat PIOE interrupts + PioInterruptHandler(AT91C_ID_PIOE, AT91C_BASE_PIOE); +#endif + +#if defined(AT91C_ID_PIOABCD) + // Treat PIOABCD interrupts + #if !defined(AT91C_ID_PIOA) + PioInterruptHandler(AT91C_ID_PIOABCD, AT91C_BASE_PIOA); + #endif + #if !defined(AT91C_ID_PIOB) + PioInterruptHandler(AT91C_ID_PIOABCD, AT91C_BASE_PIOB); + #endif + #if !defined(AT91C_ID_PIOC) + PioInterruptHandler(AT91C_ID_PIOABCD, AT91C_BASE_PIOC); + #endif + #if !defined(AT91C_ID_PIOD) + PioInterruptHandler(AT91C_ID_PIOABCD, AT91C_BASE_PIOD); + #endif +#endif + +#if defined(AT91C_ID_PIOABCDE) + // Treat PIOABCDE interrupts + #if !defined(AT91C_ID_PIOA) + PioInterruptHandler(AT91C_ID_PIOABCDE, AT91C_BASE_PIOA); + #endif + #if !defined(AT91C_ID_PIOB) + PioInterruptHandler(AT91C_ID_PIOABCDE, AT91C_BASE_PIOB); + #endif + #if !defined(AT91C_ID_PIOC) + PioInterruptHandler(AT91C_ID_PIOABCDE, AT91C_BASE_PIOC); + #endif + #if !defined(AT91C_ID_PIOD) + PioInterruptHandler(AT91C_ID_PIOABCDE, AT91C_BASE_PIOD); + #endif + #if !defined(AT91C_ID_PIOE) + PioInterruptHandler(AT91C_ID_PIOABCDE, AT91C_BASE_PIOE); + #endif +#endif + +#if defined(AT91C_ID_PIOCDE) + // Treat PIOCDE interrupts + #if !defined(AT91C_ID_PIOC) + PioInterruptHandler(AT91C_ID_PIOCDE, AT91C_BASE_PIOC); + #endif + #if !defined(AT91C_ID_PIOD) + PioInterruptHandler(AT91C_ID_PIOCDE, AT91C_BASE_PIOD); + #endif + #if !defined(AT91C_ID_PIOE) + PioInterruptHandler(AT91C_ID_PIOCDE, AT91C_BASE_PIOE); + #endif +#endif +} + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Initializes the PIO interrupt management logic. The desired priority of PIO +/// interrupts must be provided. Calling this function multiple times result in +/// the reset of currently configured interrupts. +/// \param priority PIO controller interrupts priority. +//------------------------------------------------------------------------------ +void PIO_InitializeInterrupts(unsigned int priority) +{ + TRACE_DEBUG("PIO_Initialize()\n\r"); + +// SANITY_CHECK((priority & ~AT91C_AIC_PRIOR) == 0); + + // Reset sources + numSources = 0; + +#ifdef AT91C_ID_PIOA + // Configure PIO interrupt sources + TRACE_DEBUG("PIO_Initialize: Configuring PIOA\n\r"); + AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA; + AT91C_BASE_PIOA->PIO_ISR; + AT91C_BASE_PIOA->PIO_IDR = 0xFFFFFFFF; + IRQ_ConfigureIT(AT91C_ID_PIOA, priority, PIO_IT_InterruptHandler); + IRQ_EnableIT(AT91C_ID_PIOA); +#endif + +#ifdef AT91C_ID_PIOB + TRACE_DEBUG("PIO_Initialize: Configuring PIOB\n\r"); + AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB; + AT91C_BASE_PIOB->PIO_ISR; + AT91C_BASE_PIOB->PIO_IDR = 0xFFFFFFFF; + IRQ_ConfigureIT(AT91C_ID_PIOB, priority, PIO_IT_InterruptHandler); + IRQ_EnableIT(AT91C_ID_PIOB); +#endif + +#ifdef AT91C_ID_PIOC + TRACE_DEBUG("PIO_Initialize: Configuring PIOC\n\r"); + AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOC; + AT91C_BASE_PIOC->PIO_ISR; + AT91C_BASE_PIOC->PIO_IDR = 0xFFFFFFFF; + IRQ_ConfigureIT(AT91C_ID_PIOC, priority, PIO_IT_InterruptHandler); + IRQ_EnableIT(AT91C_ID_PIOC); +#endif + +#ifdef AT91C_ID_PIOD + TRACE_DEBUG("PIO_Initialize: Configuring PIOD\n\r"); + AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOD; + AT91C_BASE_PIOC->PIO_ISR; + AT91C_BASE_PIOC->PIO_IDR = 0xFFFFFFFF; + IRQ_ConfigureIT(AT91C_ID_PIOD, priority, PIO_IT_InterruptHandler); + IRQ_EnableIT(AT91C_ID_PIOD); +#endif + +#ifdef AT91C_ID_PIOE + TRACE_DEBUG("PIO_Initialize: Configuring PIOE\n\r"); + AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOE; + AT91C_BASE_PIOC->PIO_ISR; + AT91C_BASE_PIOC->PIO_IDR = 0xFFFFFFFF; + IRQ_ConfigureIT(AT91C_ID_PIOE, priority, PIO_IT_InterruptHandler); + IRQ_EnableIT(AT91C_ID_PIOE); +#endif + +#if defined(AT91C_ID_PIOABCD) + // Treat PIOABCD interrupts + #if !defined(AT91C_ID_PIOA) \ + && !defined(AT91C_ID_PIOB) \ + && !defined(AT91C_ID_PIOC) \ + && !defined(AT91C_ID_PIOD) + + TRACE_DEBUG("PIO_Initialize: Configuring PIOABCD\n\r"); + AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOABCD; + AT91C_BASE_PIOA->PIO_ISR; + AT91C_BASE_PIOA->PIO_IDR = 0xFFFFFFFF; + IRQ_ConfigureIT(AT91C_ID_PIOABCD, priority, PIO_IT_InterruptHandler); + IRQ_EnableIT(AT91C_ID_PIOABCD); + #endif +#endif + +#if defined(AT91C_ID_PIOABCDE) + // Treat PIOABCDE interrupts + #if !defined(AT91C_ID_PIOA) \ + && !defined(AT91C_ID_PIOB) \ + && !defined(AT91C_ID_PIOC) \ + && !defined(AT91C_ID_PIOD) \ + && !defined(AT91C_ID_PIOE) + + TRACE_DEBUG("PIO_Initialize: Configuring PIOABCDE\n\r"); + AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOABCDE; + AT91C_BASE_PIOA->PIO_ISR; + AT91C_BASE_PIOA->PIO_IDR = 0xFFFFFFFF; + IRQ_ConfigureIT(AT91C_ID_PIOABCDE, priority, PIO_IT_InterruptHandler); + IRQ_EnableIT(AT91C_ID_PIOABCDE); + #endif +#endif + +#if defined(AT91C_ID_PIOCDE) + // Treat PIOCDE interrupts + #if !defined(AT91C_ID_PIOC) \ + && !defined(AT91C_ID_PIOD) \ + && !defined(AT91C_ID_PIOE) + + TRACE_DEBUG("PIO_Initialize: Configuring PIOC\n\r"); + AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOCDE; + AT91C_BASE_PIOC->PIO_ISR; + AT91C_BASE_PIOC->PIO_IDR = 0xFFFFFFFF; + IRQ_ConfigureIT(AT91C_ID_PIOCDE, priority, PIO_IT_InterruptHandler); + IRQ_EnableIT(AT91C_ID_PIOCDE); + #endif +#endif +} + +//------------------------------------------------------------------------------ +/// Configures a PIO or a group of PIO to generate an interrupt on status +/// change. The provided interrupt handler will be called with the triggering +/// pin as its parameter (enabling different pin instances to share the same +/// handler). +/// \param pPin Pointer to a Pin instance. +/// \param handler Interrupt handler function pointer. +//------------------------------------------------------------------------------ +void PIO_ConfigureIt(const Pin *pPin, void (*handler)(const Pin *)) +{ + InterruptSource *pSource; + + TRACE_DEBUG("PIO_ConfigureIt()\n\r"); + + SANITY_CHECK(pPin); + ASSERT(numSources < MAX_INTERRUPT_SOURCES, + "-F- PIO_ConfigureIt: Increase MAX_INTERRUPT_SOURCES\n\r"); + + // Define new source + TRACE_DEBUG("PIO_ConfigureIt: Defining new source #%d.\n\r", numSources); + + pSource = &(pSources[numSources]); + pSource->pPin = pPin; + pSource->handler = handler; + numSources++; +} + +//------------------------------------------------------------------------------ +/// Enables the given interrupt source if it has been configured. The status +/// register of the corresponding PIO controller is cleared prior to enabling +/// the interrupt. +/// \param pPin Interrupt source to enable. +//------------------------------------------------------------------------------ +void PIO_EnableIt(const Pin *pPin) +{ + TRACE_DEBUG("PIO_EnableIt()\n\r"); + + SANITY_CHECK(pPin); + +#ifndef NOASSERT + unsigned int i = 0; + unsigned char found = 0; + while ((i < numSources) && !found) { + + if (pSources[i].pPin == pPin) { + + found = 1; + } + i++; + } + ASSERT(found, "-F- PIO_EnableIt: Interrupt source has not been configured\n\r"); +#endif + + pPin->pio->PIO_ISR; + pPin->pio->PIO_IER = pPin->mask; + + +#if defined(AT91C_PIOA_AIMMR) + //PIO3 with additional interrupt support + //configure additional interrupt mode registers + if(pPin->mask&pPin->itMode.itMask) { + + //enable additional interrupt mode + pPin->pio->PIO_AIMER = pPin->itMode.itMask; + + if(pPin->mask&pPin->itMode.edgeLvlSel) + //if bit field of selected pin is 1, set as Level detection source + pPin->pio->PIO_LSR = pPin->itMode.edgeLvlSel; + else + //if bit field of selected pin is 0, set as Edge detection source + pPin->pio->PIO_ESR = ~(pPin->itMode.edgeLvlSel); + + if(pPin->mask&pPin->itMode.lowFallOrRiseHighSel) + //if bit field of selected pin is 1, set as Rising Edge/High level detection event + pPin->pio->PIO_REHLSR = pPin->itMode.lowFallOrRiseHighSel; + else + //if bit field of selected pin is 0, set as Falling Edge/Low level detection event + pPin->pio->PIO_FELLSR = ~(pPin->itMode.lowFallOrRiseHighSel); + } + +#endif +} + +//------------------------------------------------------------------------------ +/// Disables a given interrupt source, with no added side effects. +/// \param pPin Interrupt source to disable. +//------------------------------------------------------------------------------ +void PIO_DisableIt(const Pin *pPin) +{ + SANITY_CHECK(pPin); + + TRACE_DEBUG("PIO_DisableIt()\n\r"); + + pPin->pio->PIO_IDR = pPin->mask; +#if defined(AT91C_PIOA_AIMMR) + if(pPin->mask & pPin->itMode.itMask) + //disable additional interrupt mode + pPin->pio->PIO_AIMDR = pPin->mask & pPin->itMode.itMask; +#endif + +} + +#if defined(cortexm3) +//------------------------------------------------------------------------------ +/// Override cortex-m3's default PIOA irq handler +//------------------------------------------------------------------------------ +void PIOA_IrqHandler(void) +{ + #if defined(AT91C_ID_PIOA) + // Treat PIOA interrupts + PioInterruptHandler(AT91C_ID_PIOA, AT91C_BASE_PIOA); + #endif +} + +//------------------------------------------------------------------------------ +/// Override cortex-m3's default PIOB irq handler +//------------------------------------------------------------------------------ +void PIOB_IrqHandler(void) +{ + #if defined(AT91C_ID_PIOB) + // Treat PIOA interrupts + PioInterruptHandler(AT91C_ID_PIOB, AT91C_BASE_PIOB); + #endif +} + +//------------------------------------------------------------------------------ +/// Override cortex-m3's default PIOC irq handler +//------------------------------------------------------------------------------ +void PIOC_IrqHandler(void) +{ + #if defined(AT91C_ID_PIOC) + // Treat PIOA interrupts + PioInterruptHandler(AT91C_ID_PIOC, AT91C_BASE_PIOC); + #endif +} +#endif diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pio/pio_it.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pio/pio_it.h new file mode 100644 index 000000000..782e911a7 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pio/pio_it.h @@ -0,0 +1,85 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Configuration and handling of interrupts on PIO status changes. The API +/// provided here have several advantages over the traditional PIO interrupt +/// configuration approach: +/// - It is highly portable +/// - It automatically demultiplexes interrupts when multiples pins have been +/// configured on a single PIO controller +/// - It allows a group of pins to share the same interrupt +/// +/// However, it also has several minor drawbacks that may prevent from using it +/// in particular applications: +/// - It enables the clocks of all PIO controllers +/// - PIO controllers all share the same interrupt handler, which does the +/// demultiplexing and can be slower than direct configuration +/// - It reserves space for a fixed number of interrupts, which can be +/// increased by modifying the appropriate constant in pio_it.c. +/// +/// !!!Usage +/// +/// -# Initialize the PIO interrupt mechanism using PIO_InitializeInterrupts() +/// with the desired priority (0 ... 7). +/// -# Configure a status change interrupt on one or more pin(s) with +/// PIO_ConfigureIt(). +/// -# Enable & disable interrupts on pins using PIO_EnableIt() and +/// PIO_DisableIt(). +//------------------------------------------------------------------------------ + +#ifndef PIO_IT_H +#define PIO_IT_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "pio.h" + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void PIO_InitializeInterrupts(unsigned int priority); + +extern void PIO_ConfigureIt(const Pin *pPin, void (*handler)(const Pin *)); + +extern void PIO_EnableIt(const Pin *pPin); + +extern void PIO_DisableIt(const Pin *pPin); + +extern void PIO_IT_InterruptHandler(void); + +#endif //#ifndef PIO_IT_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pit/pit.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pit/pit.c new file mode 100644 index 000000000..f15610cfe --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pit/pit.c @@ -0,0 +1,122 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "pit.h" +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Initialize the Periodic Interval Timer to generate a tick at the specified +/// period, given the current master clock frequency. +/// \param period Period in µsecond. +/// \param pit_frequency Master clock frequency in MHz. +//------------------------------------------------------------------------------ +void PIT_Init(unsigned int period, unsigned int pit_frequency) +{ + AT91C_BASE_PITC->PITC_PIMR = period? (period * pit_frequency + 8) >> 4 : 0; + AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN; +} + +//------------------------------------------------------------------------------ +/// Set the Periodic Interval Value of the PIT. +/// \param piv PIV value to set. +//------------------------------------------------------------------------------ +void PIT_SetPIV(unsigned int piv) +{ + AT91C_BASE_PITC->PITC_PIMR = (AT91C_BASE_PITC->PITC_PIMR & AT91C_PITC_PIV) + | piv; +} + +//------------------------------------------------------------------------------ +/// Enables the PIT if this is not already the case. +//------------------------------------------------------------------------------ +void PIT_Enable(void) +{ + AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN; +} + +//---------------------------------------------------------------------------- +/// Enable the PIT periodic interrupt. +//---------------------------------------------------------------------------- +void PIT_EnableIT(void) +{ + AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITIEN; +} + +//------------------------------------------------------------------------------ +/// Disables the PIT periodic interrupt. +//------------------------------------------------------------------------------ +void PIT_DisableIT(void) +{ + AT91C_BASE_PITC->PITC_PIMR &= ~AT91C_PITC_PITIEN; +} + +//------------------------------------------------------------------------------ +/// Returns the value of the PIT mode register. +/// \return PIT_MR value. +//------------------------------------------------------------------------------ +unsigned int PIT_GetMode(void) +{ + return AT91C_BASE_PITC->PITC_PIMR; +} + +//------------------------------------------------------------------------------ +/// Returns the value of the PIT status register, clearing it as a side effect. +/// \return PIT_SR value. +//------------------------------------------------------------------------------ +unsigned int PIT_GetStatus(void) +{ + return AT91C_BASE_PITC->PITC_PISR; +} + +//------------------------------------------------------------------------------ +/// Returns the value of the PIT Image Register, to read PICNT and CPIV without +/// clearing the current values. +/// \return PIT_PIIR value. +//------------------------------------------------------------------------------ +unsigned int PIT_GetPIIR(void) +{ + return AT91C_BASE_PITC->PITC_PIIR; +} + +//------------------------------------------------------------------------------ +/// Returns the value of the PIT Value Register, clearing it as a side effect. +/// \return PIT_PIVR value. +//------------------------------------------------------------------------------ +unsigned int PIT_GetPIVR(void) +{ + return AT91C_BASE_PITC->PITC_PIVR; +} diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pit/pit.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pit/pit.h new file mode 100644 index 000000000..12aad317c --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pit/pit.h @@ -0,0 +1,77 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Interface for configuration the Periodic Interval Timer (PIT) peripheral. +/// +/// !Usage +/// +/// -# Initialize the PIT with the desired period using PIT_Init(). +/// Alternatively, the Periodic Interval Value (PIV) can be configured +/// manually using PIT_SetPIV(). +/// -# Start the PIT counting using PIT_Enable(). +/// -# Enable & disable the PIT interrupt using PIT_EnableIT() and +/// PIT_DisableIT(). +/// -# Retrieve the current status of the PIT using PIT_GetStatus(). +/// -# To get the current value of the internal counter and the number of ticks +/// that have occurred, use either PIT_GetPIVR() or PIT_GetPIIR() depending +/// on whether you want the values to be cleared or not. +//------------------------------------------------------------------------------ + +#ifndef PIT_H +#define PIT_H + +//------------------------------------------------------------------------------ +// Global Functions +//------------------------------------------------------------------------------ + +extern void PIT_Init(unsigned int period, unsigned int pit_frequency); + +extern void PIT_SetPIV(unsigned int piv); + +extern void PIT_Enable(void); + +extern void PIT_EnableIT(void); + +extern void PIT_DisableIT(void); + +extern unsigned int PIT_GetMode(void); + +extern unsigned int PIT_GetStatus(void); + +extern unsigned int PIT_GetPIIR(void); + +extern unsigned int PIT_GetPIVR(void); + +#endif //#ifndef PIT_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pmc/pmc.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pmc/pmc.c new file mode 100644 index 000000000..d464d5184 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pmc/pmc.c @@ -0,0 +1,188 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "pmc.h" +#include +#include +#include + +#ifdef CP15_PRESENT +#include +#endif + +#define MASK_STATUS 0x3FFFFFFC + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +#if defined(at91sam7l64) || defined(at91sam7l128) +//------------------------------------------------------------------------------ +/// Sets the fast wake-up inputs that can get the device out of Wait mode. +/// \param inputs Fast wake-up inputs to enable. +//------------------------------------------------------------------------------ +void PMC_SetFastWakeUpInputs(unsigned int inputs) +{ + SANITY_CHECK((inputs & ~0xFF) == 0); + AT91C_BASE_PMC->PMC_FSMR = inputs; +} + +#if !defined(__ICCARM__) +__attribute__ ((section (".ramfunc"))) // GCC +#endif +//------------------------------------------------------------------------------ +/// Disables the main oscillator, making the device enter Wait mode. +//------------------------------------------------------------------------------ +void PMC_DisableMainOscillatorForWaitMode(void) +{ + AT91C_BASE_PMC->PMC_MOR = 0x37 << 16; + while ((AT91C_BASE_PMC->PMC_MOR & AT91C_PMC_MAINSELS) != AT91C_PMC_MAINSELS); +} + +#endif + +#if defined(at91sam7l) +//------------------------------------------------------------------------------ +/// Disables the main oscillator when NOT running on it. +//------------------------------------------------------------------------------ +void PMC_DisableMainOscillator(void) +{ + AT91C_BASE_PMC->PMC_MOR = 0x37 << 16; + while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MAINSELS) == AT91C_PMC_MAINSELS); +} +#endif + +//------------------------------------------------------------------------------ +/// Disables the processor clock +//------------------------------------------------------------------------------ +void PMC_DisableProcessorClock(void) +{ + AT91C_BASE_PMC->PMC_SCDR = AT91C_PMC_PCK; + while ((AT91C_BASE_PMC->PMC_SCSR & AT91C_PMC_PCK) != AT91C_PMC_PCK); +} + +//------------------------------------------------------------------------------ +/// Enables the clock of a peripheral. The peripheral ID (AT91C_ID_xxx) is used +/// to identify which peripheral is targetted. +/// Note that the ID must NOT be shifted (i.e. 1 << AT91C_ID_xxx). +/// \param id Peripheral ID (AT91C_ID_xxx). +//------------------------------------------------------------------------------ +void PMC_EnablePeripheral(unsigned int id) +{ + SANITY_CHECK(id < 32); + + if ((AT91C_BASE_PMC->PMC_PCSR & (1 << id)) == (1 << id)) { + + TRACE_INFO("PMC_EnablePeripheral: clock of peripheral" + " %u is already enabled\n\r", + id); + } + else { + + AT91C_BASE_PMC->PMC_PCER = 1 << id; + } +} + +//------------------------------------------------------------------------------ +/// Disables the clock of a peripheral. The peripheral ID (AT91C_ID_xxx) is used +/// to identify which peripheral is targetted. +/// Note that the ID must NOT be shifted (i.e. 1 << AT91C_ID_xxx). +/// \param id Peripheral ID (AT91C_ID_xxx). +//------------------------------------------------------------------------------ +void PMC_DisablePeripheral(unsigned int id) +{ + SANITY_CHECK(id < 32); + + if ((AT91C_BASE_PMC->PMC_PCSR & (1 << id)) != (1 << id)) { + + TRACE_INFO("PMC_DisablePeripheral: clock of peripheral" + " %u is not enabled\n\r", + id); + } + else { + + AT91C_BASE_PMC->PMC_PCDR = 1 << id; + } +} + +//------------------------------------------------------------------------------ +/// Enable all the periph clock via PMC +/// (Becareful of the last 2 bits, it is not periph clock) +//------------------------------------------------------------------------------ +void PMC_EnableAllPeripherals(void) +{ + AT91C_BASE_PMC->PMC_PCER = MASK_STATUS; + while( (AT91C_BASE_PMC->PMC_PCSR & MASK_STATUS) != MASK_STATUS); + TRACE_INFO("Enable all periph clocks\n\r"); +} + +//------------------------------------------------------------------------------ +/// Disable all the periph clock via PMC +/// (Becareful of the last 2 bits, it is not periph clock) +//------------------------------------------------------------------------------ +void PMC_DisableAllPeripherals(void) +{ + AT91C_BASE_PMC->PMC_PCDR = MASK_STATUS; + while((AT91C_BASE_PMC->PMC_PCSR & MASK_STATUS) != 0); + TRACE_INFO("Disable all periph clocks\n\r"); +} + +//----------------------------------------------------------------------------- +/// Get Periph Status +//----------------------------------------------------------------------------- +unsigned int PMC_IsAllPeriphEnabled(void) +{ + return (AT91C_BASE_PMC->PMC_PCSR == MASK_STATUS); +} + +//----------------------------------------------------------------------------- +/// Get Periph Status +//----------------------------------------------------------------------------- +unsigned int PMC_IsPeriphEnabled(unsigned int id) +{ + return (AT91C_BASE_PMC->PMC_PCSR & (1 << id)); +} +//------------------------------------------------------------------------------ +/// Put the CPU in Idle Mode for lower consumption +//------------------------------------------------------------------------------ +void PMC_CPUInIdleMode(void) +{ +#ifndef CP15_PRESENT + PMC_DisableProcessorClock(); +#else + AT91C_BASE_PMC->PMC_SCDR = AT91C_PMC_PCK; + CP15_WaitForInterrupt(); +#endif +} + + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pmc/pmc.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pmc/pmc.h new file mode 100644 index 000000000..a53b36561 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pmc/pmc.h @@ -0,0 +1,62 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef PMC_H +#define PMC_H + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +#if defined(at91sam7l64) || defined(at91sam7l128) +extern void PMC_SetFastWakeUpInputs(unsigned int inputs); +extern void PMC_DisableMainOscillator(void); +extern +#ifdef __ICCARM__ +__ramfunc +#endif //__ICCARM__ +void PMC_DisableMainOscillatorForWaitMode(void); +#endif // at91sam7l64 at91sam7l128 + +extern void PMC_DisableProcessorClock(void); +extern void PMC_EnablePeripheral(unsigned int id); +extern void PMC_DisablePeripheral(unsigned int id); +extern void PMC_CPUInIdleMode(void); + + +extern void PMC_EnableAllPeripherals(void); + +extern void PMC_DisableAllPeripherals(void); + +extern unsigned int PMC_IsAllPeriphEnabled(void); + +extern unsigned int PMC_IsPeriphEnabled(unsigned int id); + +#endif //#ifndef PMC_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pwmc/pwmc.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pwmc/pwmc.c new file mode 100644 index 000000000..98ca5cf42 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pwmc/pwmc.c @@ -0,0 +1,245 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "pwmc.h" +#include +#include +#include + +//------------------------------------------------------------------------------ +// Local functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Finds a prescaler/divisor couple to generate the desired frequency from +/// MCK. +/// Returns the value to enter in PWMC_MR or 0 if the configuration cannot be +/// met. +/// \param frequency Desired frequency in Hz. +/// \param mck Master clock frequency in Hz. +//------------------------------------------------------------------------------ +static unsigned short FindClockConfiguration( + unsigned int frequency, + unsigned int mck) +{ + unsigned int divisors[11] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}; + unsigned char divisor = 0; + unsigned int prescaler; + + SANITY_CHECK(frequency < mck); + + // Find prescaler and divisor values + prescaler = (mck / divisors[divisor]) / frequency; + while ((prescaler > 255) && (divisor < 11)) { + + divisor++; + prescaler = (mck / divisors[divisor]) / frequency; + } + + // Return result + if (divisor < 11) { + + TRACE_DEBUG("Found divisor=%u and prescaler=%u for freq=%uHz\n\r", + divisors[divisor], prescaler, frequency); + return prescaler | (divisor << 8); + } + else { + + return 0; + } +} + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Configures PWM a channel with the given parameters. +/// The PWM controller must have been clocked in the PMC prior to calling this +/// function. +/// Beware: this function disables the channel. It waits until disable is effective. +/// \param channel Channel number. +/// \param prescaler Channel prescaler. +/// \param alignment Channel alignment. +/// \param polarity Channel polarity. +//------------------------------------------------------------------------------ +void PWMC_ConfigureChannel( + unsigned char channel, + unsigned int prescaler, + unsigned int alignment, + unsigned int polarity) +{ + SANITY_CHECK(prescaler < AT91C_PWMC_CPRE_MCKB); + SANITY_CHECK((alignment & ~AT91C_PWMC_CALG) == 0); + SANITY_CHECK((polarity & ~AT91C_PWMC_CPOL) == 0); + + // Disable channel (effective at the end of the current period) + if ((AT91C_BASE_PWMC->PWMC_SR & (1 << channel)) != 0) { + AT91C_BASE_PWMC->PWMC_DIS = 1 << channel; + while ((AT91C_BASE_PWMC->PWMC_SR & (1 << channel)) != 0); + } + + // Configure channel + AT91C_BASE_PWMC->PWMC_CH[channel].PWMC_CMR = prescaler | alignment | polarity; +} + +//------------------------------------------------------------------------------ +/// Configures PWM clocks A & B to run at the given frequencies. This function +/// finds the best MCK divisor and prescaler values automatically. +/// \param clka Desired clock A frequency (0 if not used). +/// \param clkb Desired clock B frequency (0 if not used). +/// \param mck Master clock frequency. +//------------------------------------------------------------------------------ +void PWMC_ConfigureClocks(unsigned int clka, unsigned int clkb, unsigned int mck) +{ + unsigned int mode = 0; + unsigned int result; + + // Clock A + if (clka != 0) { + + result = FindClockConfiguration(clka, mck); + ASSERT(result != 0, "-F- Could not generate the desired PWM frequency (%uHz)\n\r", clka); + mode |= result; + } + + // Clock B + if (clkb != 0) { + + result = FindClockConfiguration(clkb, mck); + ASSERT(result != 0, "-F- Could not generate the desired PWM frequency (%uHz)\n\r", clkb); + mode |= (result << 16); + } + + // Configure clocks + TRACE_DEBUG("Setting PWMC_MR = 0x%08X\n\r", mode); + AT91C_BASE_PWMC->PWMC_MR = mode; +} + +//------------------------------------------------------------------------------ +/// Sets the period value used by a PWM channel. This function writes directly +/// to the CPRD register if the channel is disabled; otherwise, it uses the +/// update register CUPD. +/// \param channel Channel number. +/// \param period Period value. +//------------------------------------------------------------------------------ +void PWMC_SetPeriod(unsigned char channel, unsigned short period) +{ + // If channel is disabled, write to CPRD + if ((AT91C_BASE_PWMC->PWMC_SR & (1 << channel)) == 0) { + + AT91C_BASE_PWMC->PWMC_CH[channel].PWMC_CPRDR = period; + } + // Otherwise use update register + else { + + AT91C_BASE_PWMC->PWMC_CH[channel].PWMC_CMR |= AT91C_PWMC_CPD; + AT91C_BASE_PWMC->PWMC_CH[channel].PWMC_CUPDR = period; + } +} + +//------------------------------------------------------------------------------ +/// Sets the duty cycle used by a PWM channel. This function writes directly to +/// the CDTY register if the channel is disabled; otherwise it uses the +/// update register CUPD. +/// Note that the duty cycle must always be inferior or equal to the channel +/// period. +/// \param channel Channel number. +/// \param duty Duty cycle value. +//------------------------------------------------------------------------------ +void PWMC_SetDutyCycle(unsigned char channel, unsigned short duty) +{ + SANITY_CHECK(duty <= AT91C_BASE_PWMC->PWMC_CH[channel].PWMC_CPRDR); + + // SAM7S errata +#if defined(at91sam7s16) || defined(at91sam7s161) || defined(at91sam7s32) \ + || defined(at91sam7s321) || defined(at91sam7s64) || defined(at91sam7s128) \ + || defined(at91sam7s256) || defined(at91sam7s512) + ASSERT(duty > 0, "-F- Duty cycle value 0 is not permitted on SAM7S chips.\n\r"); + ASSERT((duty > 1) || (AT91C_BASE_PWMC->PWMC_CH[channel].PWMC_CMR & AT91C_PWMC_CALG), + "-F- Duty cycle value 1 is not permitted in left-aligned mode on SAM7S chips.\n\r"); +#endif + + // If channel is disabled, write to CDTY + if ((AT91C_BASE_PWMC->PWMC_SR & (1 << channel)) == 0) { + + AT91C_BASE_PWMC->PWMC_CH[channel].PWMC_CDTYR = duty; + } + // Otherwise use update register + else { + + AT91C_BASE_PWMC->PWMC_CH[channel].PWMC_CMR &= ~AT91C_PWMC_CPD; + AT91C_BASE_PWMC->PWMC_CH[channel].PWMC_CUPDR = duty; + } +} + +//------------------------------------------------------------------------------ +/// Enables the given PWM channel. This does NOT enable the corresponding pin; +/// this must be done in the user code. +/// \param channel Channel number. +//------------------------------------------------------------------------------ +void PWMC_EnableChannel(unsigned char channel) +{ + AT91C_BASE_PWMC->PWMC_ENA = 1 << channel; +} + +//------------------------------------------------------------------------------ +/// Disables the given PWM channel. +/// Beware, channel will be effectively disabled at the end of the current period. +/// Application can check channel is disabled using the following wait loop: +/// while ((AT91C_BASE_PWMC->PWMC_SR & (1 << channel)) != 0); +/// \param channel Channel number. +//------------------------------------------------------------------------------ +void PWMC_DisableChannel(unsigned char channel) +{ + AT91C_BASE_PWMC->PWMC_DIS = 1 << channel; +} + +//------------------------------------------------------------------------------ +/// Enables the period interrupt for the given PWM channel. +/// \param channel Channel number. +//------------------------------------------------------------------------------ +void PWMC_EnableChannelIt(unsigned char channel) +{ + AT91C_BASE_PWMC->PWMC_IER = 1 << channel; +} + +//------------------------------------------------------------------------------ +/// Disables the period interrupt for the given PWM channel. +/// \param channel Channel number. +//------------------------------------------------------------------------------ +void PWMC_DisableChannelIt(unsigned char channel) +{ + AT91C_BASE_PWMC->PWMC_IDR = 1 << channel; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pwmc/pwmc.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pwmc/pwmc.h new file mode 100644 index 000000000..fe2b44063 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/pwmc/pwmc.h @@ -0,0 +1,83 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Interface for configuration the Pulse Width Modulation Controller (PWM) peripheral. +/// +/// !Usage +/// +/// -# Configures PWM clocks A & B to run at the given frequencies using +/// PWMC_ConfigureClocks(). +/// -# Configure PWMC channel using PWMC_ConfigureChannel(), PWMC_SetPeriod() +/// and PWMC_SetDutyCycle(). +/// -# Enable & disable channel using PWMC_EnableChannel() and +/// PWMC_DisableChannel(). +/// -# Enable & disable the period interrupt for the given PWM channel using +/// PWMC_EnableChannelIt() and PWMC_DisableChannelIt(). +/// +/// Please refer to the list of functions in the #Overview# tab of this unit +/// for more detailed information. +//------------------------------------------------------------------------------ + +#ifndef PWMC_H +#define PWMC_H + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void PWMC_ConfigureChannel( + unsigned char channel, + unsigned int prescaler, + unsigned int alignment, + unsigned int polarity); + +extern void PWMC_ConfigureClocks + (unsigned int clka, + unsigned int clkb, + unsigned int mck); + +extern void PWMC_SetPeriod(unsigned char channel, unsigned short period); + +extern void PWMC_SetDutyCycle(unsigned char channel, unsigned short duty); + +extern void PWMC_EnableChannel(unsigned char channel); + +extern void PWMC_DisableChannel(unsigned char channel); + +extern void PWMC_EnableChannelIt(unsigned char channel); + +extern void PWMC_DisableChannelIt(unsigned char channel); + +#endif //#ifndef PWMC_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rstc/rstc.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rstc/rstc.c new file mode 100644 index 000000000..7f6ceca4d --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rstc/rstc.c @@ -0,0 +1,176 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- + +#include + +//----------------------------------------------------------------------------- +// Defines +//----------------------------------------------------------------------------- + +/// Keywords to write to the reset registers +#define RSTC_KEY_PASSWORD (0xA5 << 24) + +//----------------------------------------------------------------------------- +// Exported functions +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +/// Configure the mode of the RSTC peripheral. +/// The configuration is computed by the lib (AT91C_RSTC_*). +/// \param rmr Desired mode configuration. +//----------------------------------------------------------------------------- +void RSTC_ConfigureMode(unsigned int rmr) +{ + rmr &= ~AT91C_RSTC_KEY; + AT91C_BASE_RSTC->RSTC_RMR = rmr | RSTC_KEY_PASSWORD; +} + +//----------------------------------------------------------------------------- +/// Enable/Disable the detection of a low level on the pin NRST as User Reset +/// \param enable 1 to enable & 0 to disable. +//----------------------------------------------------------------------------- +void RSTC_SetUserResetEnable(unsigned char enable) +{ + unsigned int rmr = AT91C_BASE_RSTC->RSTC_RMR & (~AT91C_RSTC_KEY); + if (enable) { + + rmr |= AT91C_RSTC_URSTEN; + } + else { + + rmr &= ~AT91C_RSTC_URSTEN; + } + AT91C_BASE_RSTC->RSTC_RMR = rmr | RSTC_KEY_PASSWORD; +} + +//----------------------------------------------------------------------------- +/// Enable/Disable the interrupt of a User Reset (USRTS bit in RSTC_RST). +/// \param enable 1 to enable & 0 to disable. +//----------------------------------------------------------------------------- +void RSTC_SetUserResetInterruptEnable(unsigned char enable) +{ + unsigned int rmr = AT91C_BASE_RSTC->RSTC_RMR & (~AT91C_RSTC_KEY); + if (enable) { + + rmr |= AT91C_RSTC_URSTIEN; + } + else { + + rmr &= ~AT91C_RSTC_URSTIEN; + } + AT91C_BASE_RSTC->RSTC_RMR = rmr | RSTC_KEY_PASSWORD; +} + +//----------------------------------------------------------------------------- +/// Setup the external reset length. The length is asserted during a time of +/// pow(2, powl+1) Slow Clock(32KHz). The duration is between 60us and 2s. +/// \param powl Power length defined. +//----------------------------------------------------------------------------- +void RSTC_SetExtResetLength(unsigned char powl) +{ + unsigned int rmr = AT91C_BASE_RSTC->RSTC_RMR; + rmr &= ~(AT91C_RSTC_KEY | AT91C_RSTC_ERSTL); + rmr |= (powl << 8) & AT91C_RSTC_ERSTL; + AT91C_BASE_RSTC->RSTC_RMR = rmr | RSTC_KEY_PASSWORD; +} + + +//----------------------------------------------------------------------------- +/// Resets the processor. +//----------------------------------------------------------------------------- +void RSTC_ProcessorReset(void) +{ + AT91C_BASE_RSTC->RSTC_RCR = AT91C_RSTC_PROCRST | RSTC_KEY_PASSWORD; +} + +//----------------------------------------------------------------------------- +/// Resets the peripherals. +//----------------------------------------------------------------------------- +void RSTC_PeripheralReset(void) +{ + AT91C_BASE_RSTC->RSTC_RCR = AT91C_RSTC_PERRST | RSTC_KEY_PASSWORD; +} + +//----------------------------------------------------------------------------- +/// Asserts the NRST pin for external resets. +//----------------------------------------------------------------------------- +void RSTC_ExtReset(void) +{ + AT91C_BASE_RSTC->RSTC_RCR = AT91C_RSTC_EXTRST | RSTC_KEY_PASSWORD; +} + +//----------------------------------------------------------------------------- +/// Return NRST pin level ( 1 or 0 ). +//----------------------------------------------------------------------------- +unsigned char RSTC_GetNrstLevel(void) +{ + if (AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_NRSTL) { + + return 1; + } + return 0; +} + +//----------------------------------------------------------------------------- +/// Returns 1 if at least one high-to-low transition of NRST (User Reset) has +/// been detected since the last read of RSTC_RSR. +//----------------------------------------------------------------------------- +unsigned char RSTC_IsUserResetDetected(void) +{ + if (AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_URSTS) { + + return 1; + } + return 0; +} + +//----------------------------------------------------------------------------- +/// Return 1 if a software reset command is being performed by the reset +/// controller. The reset controller is busy. +//----------------------------------------------------------------------------- +unsigned char RSTC_IsBusy(void) +{ + if (AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_SRCMP) { + + return 1; + } + return 0; +} + +//----------------------------------------------------------------------------- +/// Get the status +//----------------------------------------------------------------------------- +unsigned char RSTC_GetStatus(void) +{ + return (AT91C_BASE_RSTC->RSTC_RSR); +} diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rstc/rstc.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rstc/rstc.h new file mode 100644 index 000000000..d3dbb1652 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rstc/rstc.h @@ -0,0 +1,58 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef _RSTC_H +#define _RSTC_H + +//----------------------------------------------------------------------------- +// Exported functions +//----------------------------------------------------------------------------- + +extern void RSTC_ConfigureMode(unsigned int rmr); + +extern void RSTC_SetUserResetEnable(unsigned char enable); + +extern void RSTC_SetUserResetInterruptEnable(unsigned char enable); + +extern void RSTC_SetExtResetLength(unsigned char powl); + +extern void RSTC_ProcessorReset(void); + +extern void RSTC_PeripheralReset(void); + +extern void RSTC_ExtReset(void); + +extern unsigned char RSTC_GetNrstLevel(void); + +extern unsigned char RSTC_IsUserResetDetected(void); + +extern unsigned char RSTC_IsBusy(void); + + +#endif // #ifndef _RSTC_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rtc/rtc.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rtc/rtc.c new file mode 100644 index 000000000..189c6d520 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rtc/rtc.c @@ -0,0 +1,403 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "rtc.h" +#include +#include +#include + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Sets the RTC in either 12- or 24-hour mode. +/// \param mode Hour mode. +//------------------------------------------------------------------------------ +void RTC_SetHourMode(unsigned int mode) +{ + SANITY_CHECK((mode & 0xFFFFFFFE) == 0); + + TRACE_DEBUG("RTC_SetHourMode()\n\r"); + + AT91C_BASE_RTC->RTC_MR = mode; +} + +//------------------------------------------------------------------------------ +/// Gets the RTC mode. +/// \return Hour mode. +//------------------------------------------------------------------------------ +unsigned int RTC_GetHourMode() +{ + unsigned int hmode; + + TRACE_DEBUG("RTC_SetHourMode()\n\r"); + + hmode = AT91C_BASE_RTC->RTC_MR; + hmode &= 0xFFFFFFFE; + + return hmode; +} + +//------------------------------------------------------------------------------ +/// Enables the selected interrupt sources of the RTC. +/// \param sources Interrupt sources to enable. +//------------------------------------------------------------------------------ +void RTC_EnableIt(unsigned int sources) +{ + SANITY_CHECK((sources & ~0x1F) == 0); + + TRACE_DEBUG("RTC_EnableIt()\n\r"); + + AT91C_BASE_RTC->RTC_IER = sources; +} + +//------------------------------------------------------------------------------ +/// Disables the selected interrupt sources of the RTC. +/// \param sources Interrupt sources to disable. +//------------------------------------------------------------------------------ +void RTC_DisableIt(unsigned int sources) +{ + SANITY_CHECK((sources & ~0x1F) == 0); + + TRACE_DEBUG("RTC_DisableIt()\n\r"); + + AT91C_BASE_RTC->RTC_IDR = sources; +} + +//------------------------------------------------------------------------------ +/// Sets the current time in the RTC. +/// \param hour Current hour in 24 hour mode. +/// \param minute Current minute. +/// \param second Current second. +/// \return 0 sucess, 1 fail to set +//------------------------------------------------------------------------------ +int RTC_SetTime(unsigned char hour, unsigned char minute, unsigned char second) +{ + unsigned int time=0; + unsigned char hour_bcd; + unsigned char min_bcd; + unsigned char sec_bcd; + + TRACE_DEBUG("RTC_SetTime(%02d:%02d:%02d)\n\r", hour, minute, second); + + // if 12-hour mode, set AMPM bit + if ((AT91C_BASE_RTC->RTC_MR & AT91C_RTC_HRMOD) == AT91C_RTC_HRMOD) { + + if (hour > 12) { + + hour -= 12; + time |= AT91C_RTC_AMPM; + } + } + hour_bcd = (hour%10) | ((hour/10)<<4); + min_bcd = (minute%10) | ((minute/10)<<4); + sec_bcd = (second%10) | ((second/10)<<4); + + //value overflow + if((hour_bcd & (unsigned char)(~RTC_HOUR_BIT_LEN_MASK)) | + (min_bcd & (unsigned char)(~RTC_MIN_BIT_LEN_MASK)) | + (sec_bcd & (unsigned char)(~RTC_SEC_BIT_LEN_MASK))) + return 1; + + time = sec_bcd | (min_bcd << 8) | (hour_bcd<<16); + +// time |= ((hour % 10) << 16) | ((hour / 10) << 20); + + // Set time + //if((AT91C_BASE_RTC->RTC_SR & AT91C_RTC_SECEV) != AT91C_RTC_SECEV) return 1; + while ((AT91C_BASE_RTC->RTC_SR & AT91C_RTC_SECEV) != AT91C_RTC_SECEV);//wait from previous set + AT91C_BASE_RTC->RTC_CR |= AT91C_RTC_UPDTIM; + while ((AT91C_BASE_RTC->RTC_SR & AT91C_RTC_ACKUPD) != AT91C_RTC_ACKUPD); + AT91C_BASE_RTC->RTC_SCCR = AT91C_RTC_ACKUPD; + AT91C_BASE_RTC->RTC_TIMR = time; + AT91C_BASE_RTC->RTC_CR &= ~AT91C_RTC_UPDTIM; + AT91C_BASE_RTC->RTC_SCCR |= AT91C_RTC_SECEV;//clear SECENV in SCCR + + return (int)(AT91C_BASE_RTC->RTC_VER & AT91C_RTC_NVTIM); +} + +//------------------------------------------------------------------------------ +/// Retrieves the current time as stored in the RTC in several variables. +/// \param pHour If not null, current hour is stored in this variable. +/// \param pMinute If not null, current minute is stored in this variable. +/// \param pSecond If not null, current second is stored in this variable. +//------------------------------------------------------------------------------ +void RTC_GetTime( + unsigned char *pHour, + unsigned char *pMinute, + unsigned char *pSecond) +{ + unsigned int time; + + TRACE_DEBUG("RTC_GetTime()\n\r"); + + // Get current RTC time + time = AT91C_BASE_RTC->RTC_TIMR; + while (time != AT91C_BASE_RTC->RTC_TIMR) { + + time = AT91C_BASE_RTC->RTC_TIMR; + } + + // Hour + if (pHour) { + + *pHour = ((time & 0x00300000) >> 20) * 10 + + ((time & 0x000F0000) >> 16); + if ((time & AT91C_RTC_AMPM) == AT91C_RTC_AMPM) { + + *pHour += 12; + } + } + + // Minute + if (pMinute) { + + *pMinute = ((time & 0x00007000) >> 12) * 10 + + ((time & 0x00000F00) >> 8); + } + + // Second + if (pSecond) { + + *pSecond = ((time & 0x00000070) >> 4) * 10 + + (time & 0x0000000F); + } +} + +//------------------------------------------------------------------------------ +/// Sets a time alarm on the RTC. The match is performed only on the provided +/// variables; setting all pointers to 0 disables the time alarm. +/// Note: in AM/PM mode, the hour value must have bit #7 set for PM, cleared for +/// AM (as expected in the time registers). +/// \param pHour If not null, the time alarm will hour-match this value. +/// \param pMinute If not null, the time alarm will minute-match this value. +/// \param pSecond If not null, the time alarm will second-match this value. +/// \return 0 success, 1 fail to set +//------------------------------------------------------------------------------ +int RTC_SetTimeAlarm( + unsigned char *pHour, + unsigned char *pMinute, + unsigned char *pSecond) +{ + unsigned int alarm = 0; + + TRACE_DEBUG("RTC_SetTimeAlarm()\n\r"); + + // Hour + if (pHour) { + + alarm |= AT91C_RTC_HOUREN | ((*pHour / 10) << 20) | ((*pHour % 10) << 16); + } + + // Minute + if (pMinute) { + + alarm |= AT91C_RTC_MINEN | ((*pMinute / 10) << 12) | ((*pMinute % 10) << 8); + } + + // Second + if (pSecond) { + + alarm |= AT91C_RTC_SECEN | ((*pSecond / 10) << 4) | (*pSecond % 10); + } + + AT91C_BASE_RTC->RTC_TIMALR = alarm; + + return (int)(AT91C_BASE_RTC->RTC_VER & AT91C_RTC_NVTIMALR); +} + +//------------------------------------------------------------------------------ +/// Retrieves the current year, month and day from the RTC. Month, day and week +/// values are numbered starting at 1. +/// \param pYear Current year (optional). +/// \param pMonth Current month (optional). +/// \param pDay Current day (optional). +/// \param pWeek Current day in current week (optional). +//------------------------------------------------------------------------------ +void RTC_GetDate( + unsigned short *pYear, + unsigned char *pMonth, + unsigned char *pDay, + unsigned char *pWeek) +{ + unsigned int date; + + // Get current date (multiple reads are necessary to insure a stable value) + do { + + date = AT91C_BASE_RTC->RTC_CALR; + } + while (date != AT91C_BASE_RTC->RTC_CALR); + + // Retrieve year + if (pYear) { + + *pYear = (((date >> 4) & 0x7) * 1000) + + ((date & 0xF) * 100) + + (((date >> 12) & 0xF) * 10) + + ((date >> 8) & 0xF); + } + + // Retrieve month + if (pMonth) { + + *pMonth = (((date >> 20) & 1) * 10) + ((date >> 16) & 0xF); + } + + // Retrieve day + if (pDay) { + + *pDay = (((date >> 28) & 0x3) * 10) + ((date >> 24) & 0xF); + } + + // Retrieve week + if (pWeek) { + + *pWeek = ((date >> 21) & 0x7); + } +} + +//------------------------------------------------------------------------------ +/// Sets the current year, month and day in the RTC. Month, day and week values +/// must be numbered starting from 1. +/// \param year Current year. +/// \param month Current month. +/// \param day Current day. +/// \param week Day number in current week. +/// \return 0 success, 1 fail to set +//------------------------------------------------------------------------------ +int RTC_SetDate( + unsigned short year, + unsigned char month, + unsigned char day, + unsigned char week) +{ + unsigned int date; + unsigned char cent_bcd; + unsigned char year_bcd; + unsigned char month_bcd; + unsigned char day_bcd; + unsigned char week_bcd; + + cent_bcd = ((year/100)%10) | ((year/1000)<<4); + year_bcd = (year%10) | ((year/10)%10); + month_bcd = ((month%10) | (month/10)<<4); + day_bcd = ((day%10) | (day/10)<<4); + week_bcd = ((week%10) | (week/10)<<4); + + //value over flow + if((cent_bcd & (unsigned char)(~RTC_CENT_BIT_LEN_MASK)) | + (year_bcd & (unsigned char)(~RTC_YEAR_BIT_LEN_MASK)) | + (month_bcd & (unsigned char)(~RTC_MONTH_BIT_LEN_MASK)) | + (week_bcd & (unsigned char)(~RTC_WEEK_BIT_LEN_MASK)) | + (day_bcd & (unsigned char)(~RTC_DATE_BIT_LEN_MASK))) + return 1; + + + // Convert values to date register value + date = cent_bcd | + (year_bcd << 8) | + (month_bcd << 16) | + (week_bcd << 21) | + (day_bcd << 24); + + + // Update calendar register + //if((AT91C_BASE_RTC->RTC_SR & AT91C_RTC_SECEV) != AT91C_RTC_SECEV) return 1; + while ((AT91C_BASE_RTC->RTC_SR & AT91C_RTC_SECEV) != AT91C_RTC_SECEV);//wait from previous set + AT91C_BASE_RTC->RTC_CR |= AT91C_RTC_UPDCAL; + while ((AT91C_BASE_RTC->RTC_SR & AT91C_RTC_ACKUPD) != AT91C_RTC_ACKUPD); + AT91C_BASE_RTC->RTC_SCCR = AT91C_RTC_ACKUPD; + AT91C_BASE_RTC->RTC_CALR = date; + AT91C_BASE_RTC->RTC_CR &= ~AT91C_RTC_UPDCAL; + AT91C_BASE_RTC->RTC_SCCR |= AT91C_RTC_SECEV;//clear SECENV in SCCR + + return (int)(AT91C_BASE_RTC->RTC_VER & AT91C_RTC_NVCAL); +} + +//------------------------------------------------------------------------------ +/// Sets a date alarm in the RTC. The alarm will match only the provided values; +/// passing a null-pointer disables the corresponding field match. +/// \param pMonth If not null, the RTC alarm will month-match this value. +/// \param pDay If not null, the RTC alarm will day-match this value. +/// \return 0 success, 1 fail to set +//------------------------------------------------------------------------------ +int RTC_SetDateAlarm(unsigned char *pMonth, unsigned char *pDay) +{ + unsigned int alarm = 0x01010000; + + TRACE_DEBUG("RTC_SetDateAlarm()\n\r"); + + // Compute alarm field value + if (pMonth) { + + alarm |= AT91C_RTC_MONTHEN | ((*pMonth / 10) << 20) | ((*pMonth % 10) << 16); + } + if (pDay) { + + alarm |= AT91C_RTC_DATEEN | ((*pDay / 10) << 28) | ((*pDay % 10) << 24); + } + + // Set alarm + AT91C_BASE_RTC->RTC_CALALR = alarm; + + return (int)(AT91C_BASE_RTC->RTC_VER & AT91C_RTC_NVCALALR); +} + +//------------------------------------------------------------------------------ +/// Clear flag bits of status clear command register in the RTC. +/// \param mask Bits mask of cleared events +//------------------------------------------------------------------------------ +void RTC_ClearSCCR(unsigned int mask) +{ + // Clear all flag bits in status clear command register + mask &= AT91C_RTC_ACKUPD | AT91C_RTC_ALARM | AT91C_RTC_SECEV | \ + AT91C_RTC_TIMEV | AT91C_RTC_CALEV; + + AT91C_BASE_RTC->RTC_SCCR = mask; +} + +//------------------------------------------------------------------------------ +/// Get flag bits of status register in the RTC. +/// \param mask Bits mask of Status Register +/// \return Status register & mask +//------------------------------------------------------------------------------ +unsigned int RTC_GetSR(unsigned int mask) +{ + unsigned int event; + + event = AT91C_BASE_RTC->RTC_SR; + + return (event & mask); +} diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rtc/rtc.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rtc/rtc.h new file mode 100644 index 000000000..e98890fdc --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rtc/rtc.h @@ -0,0 +1,90 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef RTC_H +#define RTC_H + +//------------------------------------------------------------------------------ +// Macro used +//------------------------------------------------------------------------------ +#define RTC_HOUR_BIT_LEN_MASK 0x3F +#define RTC_MIN_BIT_LEN_MASK 0x7F +#define RTC_SEC_BIT_LEN_MASK 0x7F +#define RTC_CENT_BIT_LEN_MASK 0x7F +#define RTC_YEAR_BIT_LEN_MASK 0xFF +#define RTC_MONTH_BIT_LEN_MASK 0x1F +#define RTC_DATE_BIT_LEN_MASK 0x3F +#define RTC_WEEK_BIT_LEN_MASK 0x07 + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +extern void RTC_SetHourMode(unsigned int mode); + +extern unsigned int RTC_GetHourMode(); + +extern void RTC_EnableIt(unsigned int sources); + +extern void RTC_DisableIt(unsigned int sources); + +extern int RTC_SetTime( + unsigned char hour, + unsigned char minute, + unsigned char second); + +extern void RTC_GetTime( + unsigned char *pHour, + unsigned char *pMinute, + unsigned char *pSecond); + +extern int RTC_SetTimeAlarm( + unsigned char *pHour, + unsigned char *pMinute, + unsigned char *pSecond); + +void RTC_GetDate( + unsigned short *pYear, + unsigned char *pMonth, + unsigned char *pDay, + unsigned char *pWeek); + +extern int RTC_SetDate( + unsigned short year, + unsigned char month, + unsigned char day, + unsigned char week); + +extern int RTC_SetDateAlarm(unsigned char *pMonth, unsigned char *pDay); + +extern void RTC_ClearSCCR(unsigned int mask); + +extern unsigned int RTC_GetSR(unsigned int mask); +#endif //#ifndef RTC_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rtt/rtt.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rtt/rtt.c new file mode 100644 index 000000000..5322108b4 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rtt/rtt.c @@ -0,0 +1,93 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "rtt.h" +#include + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Changes the prescaler value of the given RTT and restarts it. This function +/// disables RTT interrupt sources. +/// \param rtt Pointer to a AT91S_RTTC instance. +/// \param prescaler Prescaler value for the RTT. +//------------------------------------------------------------------------------ +void RTT_SetPrescaler(AT91S_RTTC *rtt, unsigned short prescaler) +{ + rtt->RTTC_RTMR = (prescaler | AT91C_RTTC_RTTRST); +} + +//------------------------------------------------------------------------------ +/// Returns the current value of the RTT timer value. +/// \param rtt Pointer to a AT91S_RTTC instance. +//------------------------------------------------------------------------------ +unsigned int RTT_GetTime(AT91S_RTTC *rtt) +{ + return rtt->RTTC_RTVR; +} + +//------------------------------------------------------------------------------ +/// Enables the specified RTT interrupt sources. +/// \param rtt Pointer to a AT91S_RTTC instance. +/// \param sources Bitmask of interrupts to enable. +//------------------------------------------------------------------------------ +void RTT_EnableIT(AT91S_RTTC *rtt, unsigned int sources) +{ + ASSERT((sources & 0x0004FFFF) == 0, + "RTT_EnableIT: Wrong sources value.\n\r"); + rtt->RTTC_RTMR |= sources; +} + +//------------------------------------------------------------------------------ +/// Returns the status register value of the given RTT. +/// \param rtt Pointer to an AT91S_RTTC instance. +//------------------------------------------------------------------------------ +unsigned int RTT_GetStatus(AT91S_RTTC *rtt) +{ + return rtt->RTTC_RTSR; +} + +//------------------------------------------------------------------------------ +/// Configures the RTT to generate an alarm at the given time. +/// \param pRtt Pointer to an AT91S_RTTC instance. +/// \param time Alarm time. +//------------------------------------------------------------------------------ +void RTT_SetAlarm(AT91S_RTTC *pRtt, unsigned int time) +{ + SANITY_CHECK(time > 0); + + pRtt->RTTC_RTAR = time - 1; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rtt/rtt.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rtt/rtt.h new file mode 100644 index 000000000..54843c421 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/rtt/rtt.h @@ -0,0 +1,76 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//----------------------------------------------------------------------------- +/// \unit +/// +/// !Purpose +/// +/// Implementation of RTT Real Time Timer controller. +/// +/// !Contents +/// +/// Please refer to the list of functions in the #Overview# tab of this unit +/// for more detailed information. +//----------------------------------------------------------------------------- + + +#ifndef RTT_H +#define RTT_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +#ifndef AT91C_BASE_RTTC + #define AT91C_BASE_RTTC AT91C_BASE_RTTC0 +#endif + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +extern void RTT_SetPrescaler(AT91S_RTTC *rtt, unsigned short prescaler); + +extern unsigned int RTT_GetTime(AT91S_RTTC *rtt); + +extern void RTT_EnableIT(AT91S_RTTC *rtt, unsigned int sources); + +extern unsigned int RTT_GetStatus(AT91S_RTTC *rtt); + +extern void RTT_SetAlarm(AT91S_RTTC *pRtt, unsigned int time); + +#endif //#ifndef RTT_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/shdwc/shdwc.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/shdwc/shdwc.c new file mode 100644 index 000000000..09875c4c2 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/shdwc/shdwc.c @@ -0,0 +1,68 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "shdwc.h" +#include +#include +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Configure the Shut Down and do it +/// \param rtt_enable +/// \param wk0_mode +/// \param wk0_debounce +//------------------------------------------------------------------------------ +void SHDWC_DoShutDown( + unsigned char rtt_enable, + unsigned char wk0_mode, + unsigned char wk0_debounce + ) +{ + AT91C_BASE_SHDWC->SHDWC_SHMR = (rtt_enable << 16) | + wk0_mode | ( (wk0_debounce & 0xF) << 4); + + AT91C_BASE_SHDWC->SHDWC_SHCR = (0xA5 << 24) | 1; +} + +//------------------------------------------------------------------------------ +/// Get Status +//------------------------------------------------------------------------------ +unsigned int SHDWC_GetStatus(void) +{ + return AT91C_BASE_SHDWC->SHDWC_SHSR; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/shdwc/shdwc.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/shdwc/shdwc.h new file mode 100644 index 000000000..f89f6e11d --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/shdwc/shdwc.h @@ -0,0 +1,43 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef SHDWC_H +#define SHDWC_H + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void SHDWC_DoShutDown(unsigned char rtt_enable, + unsigned char wk0_mode, + unsigned char wk0_debounce); + +unsigned int SHDWC_GetStatus(void); + +#endif //#ifndef SHDWC_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/slcdc/slcdc.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/slcdc/slcdc.c new file mode 100644 index 000000000..59fc2384f --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/slcdc/slcdc.c @@ -0,0 +1,192 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "slcdc.h" +#include +#include + +#include + +//------------------------------------------------------------------------------ +// Local definitions +//------------------------------------------------------------------------------ + +/// Size of SLCDC buffer in bytes. +#define BUFFER_SIZE 320 + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Initializes the Segment LCD controller. +/// \param commons Number of commons used by the display. +/// \param segments Number of segments used by the display. +/// \param bias Bias value. +/// \param timeSetting Buffer timing value. +//------------------------------------------------------------------------------ +void SLCDC_Configure( + unsigned int commons, + unsigned int segments, + unsigned int bias, + unsigned int timeSetting) +{ + SANITY_CHECK((commons > 0) && (commons <= 10)); + SANITY_CHECK((segments > 0) && (segments <= 40)); + SANITY_CHECK((bias & ~AT91C_SLCDC_BIAS) == 0); + SANITY_CHECK((timeSetting & ~(0xF << 16)) == 0); + SANITY_CHECK((timeSetting >> 16) < 0x0A); + + // Enable peripheral clock + AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_SLCD; + AT91C_BASE_SLCDC->SLCDC_MR = (commons - 1) | ((segments - 1) << 8) | bias | timeSetting; +} + +//------------------------------------------------------------------------------ +/// Clears the SLCD display buffer. +//------------------------------------------------------------------------------ +void SLCDC_Clear(void) +{ + memset((void *) AT91C_BASE_SLCDC->SLCDC_MEM, 0, BUFFER_SIZE); +} + +//------------------------------------------------------------------------------ +/// Enables the SLCD controller. +//------------------------------------------------------------------------------ +void SLCDC_Enable(void) +{ + AT91C_BASE_SLCDC->SLCDC_CR = AT91C_SLCDC_LCDEN; + while (AT91C_BASE_SLCDC -> SLCDC_SR != AT91C_SLCDC_ENA); +} + +//------------------------------------------------------------------------------ +/// Disables the SLCD controller. +//------------------------------------------------------------------------------ +void SLCDC_Disable(void) +{ + AT91C_BASE_SLCDC->SLCDC_CR = AT91C_SLCDC_LCDDIS; +} + +//------------------------------------------------------------------------------ +/// Enables the SLCD low power mode. +//------------------------------------------------------------------------------ +void SLCDC_EnableLowPowerMode(void) +{ + unsigned int value; + + value = AT91C_BASE_SLCDC->SLCDC_MR; + value &= ~AT91C_SLCDC_LPMODE; + value |=AT91C_SLCDC_LPMODE; + AT91C_BASE_SLCDC->SLCDC_MR = value; +} + +//------------------------------------------------------------------------------ +/// Disables the SLCD low power mode +//------------------------------------------------------------------------------ +void SLCDC_DisableLowPowerMode(void) +{ + unsigned int value; + + value = AT91C_BASE_SLCDC->SLCDC_MR; + value &= ~AT91C_SLCDC_LPMODE; + AT91C_BASE_SLCDC->SLCDC_MR = value; +} + +//------------------------------------------------------------------------------ +/// Adjusts the frame frequency. Frequency = FsCLK / (prescaler * divider . NCOM) +/// \param prescalerValue Prescaler value +/// \param dividerValue Divider value +//------------------------------------------------------------------------------ +void SLCDC_SetFrameFreq(unsigned int prescalerValue, unsigned int dividerValue) +{ + SANITY_CHECK((prescalerValue & ~AT91C_SLCDC_PRESC) == 0); + SANITY_CHECK((dividerValue & (~(0x07 << 8))) == 0); + + AT91C_BASE_SLCDC->SLCDC_FRR = prescalerValue | dividerValue; +} + +//------------------------------------------------------------------------------ +/// Sets the display mode (normal/force off/force on/blinking). +/// \param mode Display mode to be set +//------------------------------------------------------------------------------ +void SLCDC_SetDisplayMode(unsigned int mode) +{ + unsigned int value; + + SANITY_CHECK(mode < 8); + + value = AT91C_BASE_SLCDC->SLCDC_DR; + value &= ~AT91C_SLCDC_DISPMODE; + value |= mode; + AT91C_BASE_SLCDC->SLCDC_DR = value; +} + +//------------------------------------------------------------------------------ +/// Adjusts the display blinking frequency. +/// Blinking frequency = Frame Frequency / LCDBLKFREQ. +/// \param frequency Frequency value. +//------------------------------------------------------------------------------ +void SLCDC_SetBlinkFreq(unsigned int frequency) +{ + unsigned int value; + + SANITY_CHECK((frequency & ~(0xFF << 8)) == 0); + + value = AT91C_BASE_SLCDC->SLCDC_DR; + value &= ~AT91C_SLCDC_BLKFREQ; + value |= frequency; + AT91C_BASE_SLCDC->SLCDC_DR = frequency; +} + +//------------------------------------------------------------------------------ +/// Enables the selected SLCDC interrupt sources. +/// \param sources Interrupt sources to enable. +//------------------------------------------------------------------------------ +void SLCDC_EnableInterrupts(unsigned int sources) +{ + SANITY_CHECK((sources & 0xFFFFFFFA) == 0); + + AT91C_BASE_SLCDC->SLCDC_IER = sources; +} + +//------------------------------------------------------------------------------ +/// Disables the selected SLCDC interrupt sources. +/// \param sources Interrupt sources to disable. +//------------------------------------------------------------------------------ +void SLCDC_DisableInterrupts(unsigned int sources) +{ + SANITY_CHECK((sources & 0xFFFFFFFA) == 0); + + AT91C_BASE_SLCDC->SLCDC_IDR = sources; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/slcdc/slcdc.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/slcdc/slcdc.h new file mode 100644 index 000000000..2b18960ed --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/slcdc/slcdc.h @@ -0,0 +1,93 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Interface for configuration the Segment LCD Controller (SLCDC) peripheral. +/// +/// !Usage +/// +/// -# Initializes the Segment LCD controller using SLCDC_Configure(). +/// -# Clears the SLCD display buffer using SLCDC_Clear(). +/// -# Enable & disable SLCD controller using SLCDC_Enable() and SLCDC_Disable(). +/// -# Enables & disable the SLCD low power mode using SLCDC_EnableLowPowerMode () +/// and SLCDC_DisableLowPowerMode(). +/// -# Adjusts the frame frequency using SLCDC_SetFrameFreq(). +/// -# Sets the display mode (normal/force off/force on/blinking) using +/// SLCDC_SetDisplayMode(). +/// -# Adjusts the display blinking frequency using SLCDC_SetBlinkFreq(). +/// -# Enables & disable the selected SLCDC interrupt sources using +/// SLCDC_EnableInterrupts() and SLCDC_DisableInterrupts(). +//------------------------------------------------------------------------------ + +#ifndef SLCDC_H +#define SLCDC_H + +//------------------------------------------------------------------------------ +// Global definitions +//------------------------------------------------------------------------------ + +/// Number of segments in SLCD. +#define S7LEKLCD_NUM_SEGMENTS 40 +/// Number of commons in SLCD. +#define S7LEKLCD_NUM_COMMONS 10 + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void SLCDC_Configure( + unsigned int commons, + unsigned int segments, + unsigned int bias, + unsigned int timeSetting); + +extern void SLCDC_Clear(void); + +extern void SLCDC_Enable(void); + +extern void SLCDC_Disable(void); + +extern void SLCDC_SetFrameFreq( + unsigned int prescalerValue, + unsigned int dividerValue); + +extern void SLCDC_SetDisplayMode(unsigned int mode); + +extern void SLCDC_SetBlinkFreq(unsigned int frequency); + +extern void SLCDC_EnableInterrupts(unsigned int sources); + +extern void SLCDC_DisableInterrupts(unsigned int sources); + +#endif //#ifndef SLCDC_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/slck/slck.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/slck/slck.c new file mode 100644 index 000000000..bb530ad90 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/slck/slck.c @@ -0,0 +1,251 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#if defined(at91cap9) +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "slck.h" +#include +#include +#include + +//------------------------------------------------------------------------------ +// Local definitions +//------------------------------------------------------------------------------ + +/// Start Up Time Slow Clock 32K Oscillator // see DC characteritics in Datasheet +#define T_ST_SLCK_32K_IN_MS 1200 + +/// Start Up Time Slow Clock RC Oscillator // see DC characteritics in Datasheet +#define T_ST_SLCK_RC_IN_US 75 + +#define FREQ_SLCK_32K 32768 // see DC characteritics in Datasheet +#define MIN_FREQ_SLCK_RC 20000 // see DC characteritics in Datasheet + +#define TIME_5_CYCLES_32K_IN_US ((2 * 5 * 1000000) / FREQ_SLCK_32K) +#define TIME_5_CYCLES_RC_IN_US ((2 * 5 * 1000000) / MIN_FREQ_SLCK_RC) + +//------------------------------------------------------------------------------ +// Local functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Wait time in ms +//------------------------------------------------------------------------------ +// not precise, depends on the compiler and on the options +static void WaitTimeInMs(unsigned int pck, unsigned int time_ms) +{ + register unsigned int i = 0; + i = (pck / 1000) * time_ms; + i = i / 4; + while(i--); +} + +//------------------------------------------------------------------------------ +/// Wait time in us +//------------------------------------------------------------------------------ +// not precise, depends on the compiler and on the options +static void WaitTimeInUs(unsigned int pck, unsigned int time_us) +{ + volatile unsigned int i = 0; + i = (pck / 1000000) * time_us; + i = i / 4; + while(i--); +} + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Return 1 if the slow clock is 32k +//------------------------------------------------------------------------------ +unsigned char SLCK_Is32k(void) +{ + return ((*AT91C_SYS_SLCKSEL & AT91C_SLCKSEL_OSCSEL) != 0); +} + +//------------------------------------------------------------------------------ +/// Configure the 32kHz oscillator for the slow clock +//------------------------------------------------------------------------------ +void SLCK_RCto32k(void) +{ + // Check that the master clock has a different source than slow clock. If no, + if( (AT91C_BASE_PMC->PMC_MCKR & AT91C_PMC_CSS) == 0) + { + TRACE_WARNING("The master clock use the slow clock. " \ + "Not possible to change Slow clock\n\r"); + return; + } + + // Check that the slow clock source is RC + if( SLCK_Is32k() ) + { + TRACE_WARNING("The slow clock is already the external 32.768kHz crystal\n\r"); + return; + } + + // Enable the 32,768 Hz oscillator by setting the bit OSC32EN to 1. + *AT91C_SYS_SLCKSEL |= AT91C_SLCKSEL_OSC32EN; + + // Wait 32,768 Hz Startup Time for clock stabilization (software loop). + WaitTimeInMs(BOARD_MCK*2, T_ST_SLCK_32K_IN_MS); + + // Switch from internal RC to 32,768 Hz oscillator by setting the bit OSCSEL to 1. + *AT91C_SYS_SLCKSEL |= AT91C_SLCKSEL_OSCSEL; + + // Wait 5 slow clock cycles for internal resynchronization. + WaitTimeInUs(BOARD_MCK*2, TIME_5_CYCLES_32K_IN_US); + + // Disable the RC oscillator by setting the bit RCEN to 0. + *AT91C_SYS_SLCKSEL &= (0xFFFFFFFF ^ AT91C_SLCKSEL_RCEN); + + TRACE_INFO("The slow clock is now the external 32.768kHz crystal\n\r"); +} + + +//------------------------------------------------------------------------------ +/// Configure the RC oscillator for the slow clock +//------------------------------------------------------------------------------ +void SLCK_32ktoRC(void) +{ + // Check that the master clock has a different source than slow clock. + if( (AT91C_BASE_PMC->PMC_MCKR & AT91C_PMC_CSS) == 0) + { + TRACE_WARNING("The master clock use the slow clock. " \ + "Not possible to change Slow clock\n\r"); + return; + } + + // Check that the slow clock source is RC + if( !SLCK_Is32k() ) + { + TRACE_WARNING("The slow clock is already the internal RC oscillator\n\r"); + return; + } + + // Enable the internal RC oscillator by setting the bit RCEN to 1 + *AT91C_SYS_SLCKSEL |= AT91C_SLCKSEL_RCEN; + + // Wait internal RC Startup Time for clock stabilization (software loop). + WaitTimeInUs(BOARD_MCK*2, T_ST_SLCK_RC_IN_US); + + // Switch from 32768 Hz oscillator to internal RC by setting the bit OSCSEL to 0. + *AT91C_SYS_SLCKSEL &= (0xFFFFFFFF ^ AT91C_SLCKSEL_OSCSEL); + + // Wait 5 slow clock cycles for internal resynchronization. + WaitTimeInUs(BOARD_MCK*2, TIME_5_CYCLES_RC_IN_US); + + // Disable the 32768 Hz oscillator by setting the bit OSC32EN to 0. + *AT91C_SYS_SLCKSEL &= (0xFFFFFFFF ^ AT91C_SLCKSEL_OSC32EN); + + TRACE_INFO("The slow clock is now the internal RC oscillator\n\r"); +} + +//------------------------------------------------------------------------------ +/// by pass the 32kHz oscillator +//------------------------------------------------------------------------------ +void SLCK_bypass32Kosc(void) +{ + // Enable the bypass path OSC32BYP bit set to 1 + *AT91C_SYS_SLCKSEL |= AT91C_SLCKSEL_OSC32BYP; + + // Disable the 32,768 Hz oscillator by setting the bit OSC32EN to 0 + *AT91C_SYS_SLCKSEL &= (0xFFFFFFFF ^ AT91C_SLCKSEL_OSC32EN); +} + +//------------------------------------------------------------------------------ +/// set Slow Clock Mode +//------------------------------------------------------------------------------ +#define TIMEOUT 10000000 +void SLCK_UtilSetSlowClockMode(unsigned int timeInSlowClockMode) +{ + unsigned int oldPll; + unsigned int oldMck; + unsigned int timeout = 0; + + // Save previous values for PLL A and Master Clock configuration + oldPll = AT91C_BASE_CKGR->CKGR_PLLAR; + oldMck = AT91C_BASE_PMC->PMC_MCKR; + + // Slow clock is selected for Master Clock + // 32kKz / 64 = 500Hz + // PCK = 500Hz, MCK = 250 MHz + AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_SLOW_CLK | AT91C_PMC_PRES_CLK_64 | AT91C_PMC_MDIV_2; + timeout = 0; + while ( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) && timeout++ < TIMEOUT); + + // Stop PLL A + // MULA: PLL A Multiplier 0 = The PLL A is deactivated. + AT91C_BASE_CKGR->CKGR_PLLAR = 0x00003f00; + + // Stop Main Oscillator + AT91C_BASE_CKGR->CKGR_MOR = AT91C_BASE_CKGR->CKGR_MOR & (~AT91C_CKGR_MOSCEN); + + // Wait a while. The clock is at 500Hz... + while( timeInSlowClockMode-- ); + // End ! + + // Restart Main Oscillator + AT91C_BASE_CKGR->CKGR_MOR = AT91C_BASE_CKGR->CKGR_MOR | (AT91C_CKGR_OSCOUNT & (0x32<<8) ); + AT91C_BASE_CKGR->CKGR_MOR = AT91C_BASE_CKGR->CKGR_MOR | (AT91C_CKGR_MOSCEN); + + // Restart PLL A + AT91C_BASE_CKGR->CKGR_PLLAR = oldPll; + timeout = 0; + while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCKA) && timeout++ < TIMEOUT); + + // Selection of Master Clock MCK (so Processor Clock PCK) + AT91C_BASE_PMC->PMC_MCKR = oldMck; + timeout = 0; + while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) && timeout++ < TIMEOUT); + + // Reconfigure DBGU + TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK); +} + +//------------------------------------------------------------------------------ +/// get the slow clock frequency +//------------------------------------------------------------------------------ +unsigned int SLCK_UtilGetFreq(void) +{ + unsigned int freq = 0; + + SLCK_UtilSetSlowClockMode(0); + + if(AT91C_BASE_PMC->PMC_MCFR & (1<<16)) { + freq = BOARD_MAINOSC / (AT91C_BASE_PMC->PMC_MCFR & 0x0000FFFF); + freq *= 16; + } + return freq; +} + +#endif //#if defined(at91cap9) \ No newline at end of file diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/slck/slck.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/slck/slck.h new file mode 100644 index 000000000..5814492b3 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/slck/slck.h @@ -0,0 +1,49 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef SLCK_H +#define SLCK_H + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern unsigned char SLCK_Is32k(void); + +extern void SLCK_RCto32k(void); + +extern void SLCK_32ktoRC(void); + +extern void SLCK_bypass32Kosc(void); + +extern void SLCK_UtilSetSlowClockMode(unsigned int timeInSlowClockMode); + +extern unsigned int SLCK_UtilGetFreq(void); + +#endif //#ifndef SLCK_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/spi/spi.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/spi/spi.c new file mode 100644 index 000000000..98b9e9deb --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/spi/spi.c @@ -0,0 +1,192 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "spi.h" + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +/// Enables a SPI peripheral +/// \param spi Pointer to an AT91S_SPI instance. +//------------------------------------------------------------------------------ +void SPI_Enable(AT91S_SPI *spi) +{ + spi->SPI_CR = AT91C_SPI_SPIEN; +} + +//------------------------------------------------------------------------------ +/// Disables a SPI peripheral. +/// \param spi Pointer to an AT91S_SPI instance. +//------------------------------------------------------------------------------ +void SPI_Disable(AT91S_SPI *spi) +{ + spi->SPI_CR = AT91C_SPI_SPIDIS; +} + +//------------------------------------------------------------------------------ +/// Configures a SPI peripheral as specified. The configuration can be computed +/// using several macros (see "SPI configuration macros") and the constants +/// defined in LibV3 (AT91C_SPI_*). +/// \param spi Pointer to an AT91S_SPI instance. +/// \param id Peripheral ID of the SPI. +/// \param configuration Value of the SPI configuration register. +//------------------------------------------------------------------------------ +void SPI_Configure(AT91S_SPI *spi, + unsigned int id, + unsigned int configuration) +{ + AT91C_BASE_PMC->PMC_PCER = 1 << id; + spi->SPI_CR = AT91C_SPI_SPIDIS; + // Execute a software reset of the SPI twice + spi->SPI_CR = AT91C_SPI_SWRST; + spi->SPI_CR = AT91C_SPI_SWRST; + spi->SPI_MR = configuration; +} + +//------------------------------------------------------------------------------ +/// Configures a chip select of a SPI peripheral. The chip select configuration +/// is computed using the definition provided by the LibV3 (AT91C_SPI_*). +/// \param spi Pointer to an AT91S_SPI instance. +/// \param npcs Chip select to configure (1, 2, 3 or 4). +/// \param configuration Desired chip select configuration. +//------------------------------------------------------------------------------ +void SPI_ConfigureNPCS(AT91S_SPI *spi, + unsigned int npcs, + unsigned int configuration) +{ + spi->SPI_CSR[npcs] = configuration; +} + +//------------------------------------------------------------------------------ +/// Sends data through a SPI peripheral. If the SPI is configured to use a fixed +/// peripheral select, the npcs value is meaningless. Otherwise, it identifies +/// the component which shall be addressed. +/// \param spi Pointer to an AT91S_SPI instance. +/// \param npcs Chip select of the component to address (1, 2, 3 or 4). +/// \param data Word of data to send. +//------------------------------------------------------------------------------ +void SPI_Write(AT91S_SPI *spi, unsigned int npcs, unsigned short data) +{ + // Discard contents of RDR register + //volatile unsigned int discard = spi->SPI_RDR; + + // Send data + while ((spi->SPI_SR & AT91C_SPI_TXEMPTY) == 0); + spi->SPI_TDR = data | SPI_PCS(npcs); + while ((spi->SPI_SR & AT91C_SPI_TDRE) == 0); +} + +//------------------------------------------------------------------------------ +/// Sends the contents of buffer through a SPI peripheral, using the PDC to +/// take care of the transfer. +/// \param spi Pointer to an AT91S_SPI instance. +/// \param buffer Data buffer to send. +/// \param length Length of the data buffer. +//------------------------------------------------------------------------------ +unsigned char SPI_WriteBuffer(AT91S_SPI *spi, + void *buffer, + unsigned int length) +{ + // Check if first bank is free + if (spi->SPI_TCR == 0) { + + spi->SPI_TPR = (unsigned int) buffer; + spi->SPI_TCR = length; + spi->SPI_PTCR = AT91C_PDC_TXTEN; + return 1; + } + // Check if second bank is free + else if (spi->SPI_TNCR == 0) { + + spi->SPI_TNPR = (unsigned int) buffer; + spi->SPI_TNCR = length; + return 1; + } + + // No free banks + return 0; +} + +//------------------------------------------------------------------------------ +/// Returns 1 if there is no pending write operation on the SPI; otherwise +/// returns 0. +/// \param pSpi Pointer to an AT91S_SPI instance. +//------------------------------------------------------------------------------ +unsigned char SPI_IsFinished(AT91S_SPI *pSpi) +{ + return ((pSpi->SPI_SR & AT91C_SPI_TXEMPTY) != 0); +} + +//------------------------------------------------------------------------------ +/// Reads and returns the last word of data received by a SPI peripheral. This +/// method must be called after a successful SPI_Write call. +/// \param spi Pointer to an AT91S_SPI instance. +//------------------------------------------------------------------------------ +unsigned short SPI_Read(AT91S_SPI *spi) +{ + while ((spi->SPI_SR & AT91C_SPI_RDRF) == 0); + return spi->SPI_RDR & 0xFFFF; +} + +//------------------------------------------------------------------------------ +/// Reads data from a SPI peripheral until the provided buffer is filled. This +/// method does NOT need to be called after SPI_Write or SPI_WriteBuffer. +/// \param spi Pointer to an AT91S_SPI instance. +/// \param buffer Data buffer to store incoming bytes. +/// \param length Length in bytes of the data buffer. +//------------------------------------------------------------------------------ +unsigned char SPI_ReadBuffer(AT91S_SPI *spi, + void *buffer, + unsigned int length) +{ + // Check if the first bank is free + if (spi->SPI_RCR == 0) { + + spi->SPI_RPR = (unsigned int) buffer; + spi->SPI_RCR = length; + spi->SPI_PTCR = AT91C_PDC_RXTEN; + return 1; + } + // Check if second bank is free + else if (spi->SPI_RNCR == 0) { + + spi->SPI_RNPR = (unsigned int) buffer; + spi->SPI_RNCR = length; + return 1; + } + + // No free bank + return 0; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/spi/spi.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/spi/spi.h new file mode 100644 index 000000000..f4e255770 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/spi/spi.h @@ -0,0 +1,114 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// !Purpose +/// +/// Definitions for SPI peripheral usage. +/// +/// !Usage +/// +/// -# Enable the SPI pins required by the application (see pio.h). +/// -# Configure the SPI using the SPI_Configure function. This enables the +/// peripheral clock. The mode register is loaded with the given value. +/// -# Configure all the necessary chip selects with SPI_ConfigureNPCS. +/// -# Enable the SPI by calling SPI_Enable. +/// -# Send/receive data using SPI_Write and SPI_Read. Note that SPI_Read +/// must be called after SPI_Write to retrieve the last value read. +/// -# Send/receive data using the PDC with the SPI_WriteBuffer and +/// SPI_ReadBuffer functions. +/// -# Disable the SPI by calling SPI_Disable. +//------------------------------------------------------------------------------ + +#ifndef SPI_H +#define SPI_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "SPI configuration macros" +/// This page lists several macros which should be used when configuring a SPI +/// peripheral. +/// +/// !Macros +/// - SPI_PCS +/// - SPI_SCBR +/// - SPI_DLYBS +/// - SPI_DLYBCT + +/// Calculate the PCS field value given the chip select NPCS value +#define SPI_PCS(npcs) ((~(1 << npcs) & 0xF) << 16) + +/// Calculates the value of the CSR SCBR field given the baudrate and MCK. +#define SPI_SCBR(baudrate, masterClock) \ + ((unsigned int) (masterClock / baudrate) << 8) + +/// Calculates the value of the CSR DLYBS field given the desired delay (in ns) +#define SPI_DLYBS(delay, masterClock) \ + ((unsigned int) (((masterClock / 1000000) * delay) / 1000) << 16) + +/// Calculates the value of the CSR DLYBCT field given the desired delay (in ns) +#define SPI_DLYBCT(delay, masterClock) \ + ((unsigned int) (((masterClock / 1000000) * delay) / 32000) << 24) +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +extern void SPI_Enable(AT91S_SPI *spi); +extern void SPI_Disable(AT91S_SPI *spi); +extern void SPI_Configure(AT91S_SPI *spi, + unsigned int id, + unsigned int configuration); +extern void SPI_ConfigureNPCS(AT91S_SPI *spi, + unsigned int npcs, + unsigned int configuration); +extern void SPI_Write(AT91S_SPI *spi, unsigned int npcs, unsigned short data); +extern unsigned char SPI_WriteBuffer(AT91S_SPI *spi, + void *buffer, + unsigned int length); + +extern unsigned char SPI_IsFinished(AT91S_SPI *pSpi); + +extern unsigned short SPI_Read(AT91S_SPI *spi); +extern unsigned char SPI_ReadBuffer(AT91S_SPI *spi, + void *buffer, + unsigned int length); + +#endif //#ifndef SPI_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ssc/ssc.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ssc/ssc.c new file mode 100644 index 000000000..c0cb00011 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ssc/ssc.c @@ -0,0 +1,243 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "ssc.h" +#include + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +/// Configures a SSC peripheral. If the divided clock is not used, the master +/// clock frequency can be set to 0. +/// \note The emitter and transmitter are disabled by this function. +/// \param ssc Pointer to an AT91S_SSC instance. +/// \param id Peripheral ID of the SSC. +//------------------------------------------------------------------------------ +void SSC_Configure(AT91S_SSC *ssc, + unsigned int id, + unsigned int bitRate, + unsigned int masterClock) +{ + // Enable SSC peripheral clock + AT91C_BASE_PMC->PMC_PCER = 1 << id; + + // Reset, disable receiver & transmitter + ssc->SSC_CR = AT91C_SSC_RXDIS | AT91C_SSC_TXDIS | AT91C_SSC_SWRST; + ssc->SSC_PTCR = AT91C_PDC_RXTDIS | AT91C_PDC_TXTDIS; + + // Configure clock frequency + if (bitRate != 0) { + + ssc->SSC_CMR = masterClock / (2 * bitRate); + } + else { + + ssc->SSC_CMR = 0; + } +} + +//------------------------------------------------------------------------------ +/// Configures the transmitter of a SSC peripheral. Several macros can be used +/// to compute the values of the Transmit Clock Mode Register (TCMR) and the +/// Transmit Frame Mode Register (TFMR) (see "SSC configuration macros"). +/// \param ssc Pointer to a AT91S_SSC instance. +/// \param tcmr Transmit Clock Mode Register value. +/// \param tfmr Transmit Frame Mode Register value. +//------------------------------------------------------------------------------ +void SSC_ConfigureTransmitter(AT91S_SSC *ssc, + unsigned int tcmr, + unsigned int tfmr) +{ + ssc->SSC_TCMR = tcmr; + ssc->SSC_TFMR = tfmr; +} + +//------------------------------------------------------------------------------ +/// Configures the receiver of a SSC peripheral. Several macros can be used +/// to compute the values of the Receive Clock Mode Register (TCMR) and the +/// Receive Frame Mode Register (TFMR) (see "SSC configuration macros"). +/// \param ssc Pointer to a AT91S_SSC instance. +/// \param rcmr Receive Clock Mode Register value. +/// \param rfmr Receive Frame Mode Register value. +//------------------------------------------------------------------------------ +void SSC_ConfigureReceiver(AT91S_SSC *ssc, + unsigned int rcmr, + unsigned int rfmr) +{ + ssc->SSC_RCMR = rcmr; + ssc->SSC_RFMR = rfmr; +} + +//------------------------------------------------------------------------------ +/// Enables the transmitter of a SSC peripheral. +/// \param ssc Pointer to an AT91S_SSC instance. +//------------------------------------------------------------------------------ +void SSC_EnableTransmitter(AT91S_SSC *ssc) +{ + ssc->SSC_CR = AT91C_SSC_TXEN; +} + +//------------------------------------------------------------------------------ +/// Disables the transmitter of a SSC peripheral. +/// \param ssc Pointer to an AT91S_SSC instance. +//------------------------------------------------------------------------------ +void SSC_DisableTransmitter(AT91S_SSC *ssc) +{ + ssc->SSC_CR = AT91C_SSC_TXDIS; +} + +//------------------------------------------------------------------------------ +/// Enables the receiver of a SSC peripheral. +/// \param ssc Pointer to an AT91S_SSC instance. +//------------------------------------------------------------------------------ +void SSC_EnableReceiver(AT91S_SSC *ssc) +{ + ssc->SSC_CR = AT91C_SSC_RXEN; +} + +//------------------------------------------------------------------------------ +/// Disables the receiver of a SSC peripheral. +/// \param ssc Pointer to an AT91S_SSC instance. +//------------------------------------------------------------------------------ +void SSC_DisableReceiver(AT91S_SSC *ssc) +{ + ssc->SSC_CR = AT91C_SSC_RXDIS; +} + +//------------------------------------------------------------------------------ +/// Enables one or more interrupt sources of a SSC peripheral. +/// \param ssc Pointer to an AT91S_SSC instance. +/// \param sources Interrupt sources to enable. +//------------------------------------------------------------------------------ +void SSC_EnableInterrupts(AT91S_SSC *ssc, unsigned int sources) +{ + ssc->SSC_IER = sources; +} + +//------------------------------------------------------------------------------ +/// Disables one or more interrupt sources of a SSC peripheral. +/// \param ssc Pointer to an AT91S_SSC instance. +/// \param sources Interrupt source to disable. +//------------------------------------------------------------------------------ +void SSC_DisableInterrupts(AT91S_SSC *ssc, unsigned int sources) +{ + ssc->SSC_IDR = sources; +} + +//------------------------------------------------------------------------------ +/// Sends one data frame through a SSC peripheral. If another frame is currently +/// being sent, this function waits for the previous transfer to complete. +/// \param ssc Pointer to an AT91S_SSC instance. +/// \param frame Data frame to send. +//------------------------------------------------------------------------------ +void SSC_Write(AT91S_SSC *ssc, unsigned int frame) +{ + while ((ssc->SSC_SR & AT91C_SSC_TXRDY) == 0); + ssc->SSC_THR = frame; +} + +//------------------------------------------------------------------------------ +/// Sends the contents of a data buffer a SSC peripheral, using the PDC. Returns +/// true if the buffer has been queued for transmission; otherwise returns +/// false. +/// \param ssc Pointer to an AT91S_SSC instance. +/// \param buffer Data buffer to send. +/// \param length Size of the data buffer. +//------------------------------------------------------------------------------ +unsigned char SSC_WriteBuffer(AT91S_SSC *ssc, + void *buffer, + unsigned int length) +{ + // Check if first bank is free + if (ssc->SSC_TCR == 0) { + + ssc->SSC_TPR = (unsigned int) buffer; + ssc->SSC_TCR = length; + ssc->SSC_PTCR = AT91C_PDC_TXTEN; + return 1; + } + // Check if second bank is free + else if (ssc->SSC_TNCR == 0) { + + ssc->SSC_TNPR = (unsigned int) buffer; + ssc->SSC_TNCR = length; + return 1; + } + + // No free banks + return 0; +} + +//------------------------------------------------------------------------------ +/// Waits until one frame is received on a SSC peripheral, and returns it. +/// \param ssc Pointer to an AT91S_SSC instance. +//------------------------------------------------------------------------------ +unsigned int SSC_Read(AT91S_SSC *ssc) +{ + while ((ssc->SSC_SR & AT91C_SSC_RXRDY) == 0); + return ssc->SSC_RHR; +} + +//------------------------------------------------------------------------------ +/// Reads data coming from a SSC peripheral receiver and stores it into the +/// provided buffer. Returns true if the buffer has been queued for reception; +/// otherwise returns false. +/// \param ssc Pointer to an AT91S_SSC instance. +/// \param buffer Data buffer used for reception. +/// \param length Size in bytes of the data buffer. +//------------------------------------------------------------------------------ +unsigned char SSC_ReadBuffer(AT91S_SSC *ssc, + void *buffer, + unsigned int length) +{ + // Check if the first bank is free + if (ssc->SSC_RCR == 0) { + + ssc->SSC_RPR = (unsigned int) buffer; + ssc->SSC_RCR = length; + ssc->SSC_PTCR = AT91C_PDC_RXTEN; + return 1; + } + // Check if second bank is free + else if (ssc->SSC_RNCR == 0) { + + ssc->SSC_RNPR = (unsigned int) buffer; + ssc->SSC_RNCR = length; + return 1; + } + + // No free bank + return 0; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ssc/ssc.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ssc/ssc.h new file mode 100644 index 000000000..330fa18a1 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ssc/ssc.h @@ -0,0 +1,132 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// !Purpose +/// +/// Set of functions and definition for using a SSC peripheral. +/// +/// !Usage +/// +/// -# Enable the SSC interface pins (see pio & board.h). +/// -# Configure the SSC to operate at a specific frequency by calling +/// SSC_Configure(). This function enables the peripheral clock of the SSC, +/// but not its PIOs. +/// -# Configure the transmitter and/or the receiver using the +/// SSC_ConfigureTransmitter() and SSC_ConfigureEmitter() functions. +/// -# Enable the PIOs or the transmitter and/or the received. +/// -# Enable the transmitter and/or the receiver using SSC_EnableTransmitter() +/// and SSC_EnableReceiver() +/// -# Send data through the transmitter using SSC_Write() and SSC_WriteBuffer() +/// -# Receive data from the receiver using SSC_Read() and SSC_ReadBuffer() +/// -# Disable the transmitter and/or the receiver using SSC_DisableTransmitter() +/// and SSC_DisableReceiver() +//------------------------------------------------------------------------------ + +#ifndef SSC_H +#define SSC_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "SSC configuration macros" +/// This page lists several macros which are used when configuring a SSC +/// peripheral. +/// +/// !Macros +/// - SSC_STTDLY +/// - SSC_PERIOD +/// - SSC_DATLEN +/// - SSC_DATNB +/// - SSC_FSLEN + +/// Calculates the value of the STTDLY field given the number of clock cycles +/// before the first bit of a new frame is transmitted. +#define SSC_STTDLY(bits) (bits << 16) + +/// Calculates the value of the PERIOD field of the Transmit Clock Mode Register +/// of an SSC interface, given the desired clock divider. +#define SSC_PERIOD(divider) (((divider / 2) - 1) << 24) + +/// Calculates the value of the DATLEN field of the Transmit Frame Mode Register +/// of an SSC interface, given the number of bits in one sample. +#define SSC_DATLEN(bits) (bits - 1) + +/// Calculates the value of the DATNB field of the Transmit Frame Mode Register +/// of an SSC interface, given the number of samples in one frame. +#define SSC_DATNB(samples) ((samples -1) << 8) + +/// Calculates the value of the FSLEN field of the Transmit Frame Mode Register +/// of an SSC interface, given the number of transmit clock periods that the +/// frame sync signal should take. +#define SSC_FSLEN(periods) ((periods - 1) << 16) +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +extern void SSC_Configure(AT91S_SSC *ssc, + unsigned int id, + unsigned int bitRate, + unsigned int masterClock); +extern void SSC_ConfigureTransmitter(AT91S_SSC *ssc, + unsigned int tcmr, + unsigned int tfmr); +extern void SSC_ConfigureReceiver(AT91S_SSC *ssc, + unsigned int rcmr, + unsigned int rfmr); + +extern void SSC_EnableTransmitter(AT91S_SSC *ssc); +extern void SSC_DisableTransmitter(AT91S_SSC *ssc); +extern void SSC_EnableReceiver(AT91S_SSC *ssc); +extern void SSC_DisableReceiver(AT91S_SSC *ssc); + +extern void SSC_EnableInterrupts(AT91S_SSC *ssc, unsigned int sources); +extern void SSC_DisableInterrupts(AT91S_SSC *ssc, unsigned int sources); + +extern void SSC_Write(AT91S_SSC *ssc, unsigned int frame); +extern unsigned char SSC_WriteBuffer(AT91S_SSC *ssc, + void *buffer, + unsigned int length); +extern unsigned int SSC_Read(AT91S_SSC *ssc); +extern unsigned char SSC_ReadBuffer(AT91S_SSC *ssc, + void *buffer, + unsigned int length); + +#endif //#ifndef SSC_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/supc/supc.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/supc/supc.c new file mode 100644 index 000000000..b63194c4f --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/supc/supc.c @@ -0,0 +1,223 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "supc.h" +#include +#include + +//------------------------------------------------------------------------------ +// Local definitions +//------------------------------------------------------------------------------ + +/// Key value for the SUPC_MR register. +#define SUPC_KEY ((unsigned int) (0xA5 << 24)) + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Enables the SLCD power supply. +/// \param internal If 1, the power supply is configured as internal; otherwise +/// it is set at external. +//------------------------------------------------------------------------------ +void SUPC_EnableSlcd(unsigned char internal) +{ + if (internal) { + + AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_LCDMODE) | AT91C_SUPC_LCDMODE_INTERNAL; + } + else { + + AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_LCDMODE) | AT91C_SUPC_LCDMODE_EXTERNAL; + } + while ((AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_LCDS) != AT91C_SUPC_LCDS); +} + +//------------------------------------------------------------------------------ +/// Disables the SLCD power supply. +//------------------------------------------------------------------------------ +void SUPC_DisableSlcd(void) +{ + AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_LCDMODE); + while ((AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_LCDS) == AT91C_SUPC_LCDS); +} + +//------------------------------------------------------------------------------ +/// Sets the output voltage of the SLCD charge pump. +/// \param voltage Output voltage. +//------------------------------------------------------------------------------ +void SUPC_SetSlcdVoltage(unsigned int voltage) +{ + SANITY_CHECK((voltage & ~AT91C_SUPC_LCDOUT) == 0); + AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_LCDOUT) | voltage; +} + +#if !defined(__ICCARM__) +__attribute__ ((section (".ramfunc"))) // GCC +#endif +//------------------------------------------------------------------------------ +/// Enables the flash power supply with the given wake-up setting. +/// \param time Wake-up time. +//------------------------------------------------------------------------------ +void SUPC_EnableFlash(unsigned int time) +{ + AT91C_BASE_SUPC->SUPC_FWUTR = time; + AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | AT91C_BASE_SUPC->SUPC_MR | AT91C_SUPC_FLASHON; + while ((AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_FLASHS) != AT91C_SUPC_FLASHS); +} + +#if !defined(__ICCARM__) +__attribute__ ((section (".ramfunc"))) // GCC +#endif +//------------------------------------------------------------------------------ +/// Disables the flash power supply. +//------------------------------------------------------------------------------ +void SUPC_DisableFlash(void) +{ + AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_FLASHON); + while ((AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_FLASHS) == AT91C_SUPC_FLASHS); +} + +//------------------------------------------------------------------------------ +/// Sets the voltage regulator output voltage. +/// \param voltage Voltage to set. +//------------------------------------------------------------------------------ +void SUPC_SetVoltageOutput(unsigned int voltage) +{ + SANITY_CHECK((voltage & ~AT91C_SUPC_VRVDD) == 0); + AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_VRVDD) | voltage; +} + +//------------------------------------------------------------------------------ +/// Puts the voltage regulator in deep mode. +//------------------------------------------------------------------------------ +void SUPC_EnableDeepMode(void) +{ + AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | AT91C_BASE_SUPC->SUPC_MR | AT91C_SUPC_VRDEEP; +} + +//------------------------------------------------------------------------------ +/// Puts the voltage regulator in normal mode. +//------------------------------------------------------------------------------ +void SUPC_DisableDeepMode(void) +{ + AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_VRDEEP); +} + +//----------------------------------------------------------------------------- +/// Enables the backup SRAM power supply, so its data is saved while the device +/// is in backup mode. +//----------------------------------------------------------------------------- +void SUPC_EnableSram(void) +{ + AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | AT91C_BASE_SUPC->SUPC_MR | AT91C_SUPC_SRAMON; +} + +//----------------------------------------------------------------------------- +/// Disables the backup SRAM power supply. +//----------------------------------------------------------------------------- +void SUPC_DisableSram(void) +{ + AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_SRAMON); +} + +//----------------------------------------------------------------------------- +/// Enables the RTC power supply. +//----------------------------------------------------------------------------- +void SUPC_EnableRtc(void) +{ + AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | AT91C_BASE_SUPC->SUPC_MR | AT91C_SUPC_RTCON; + while ((AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_RTS) != AT91C_SUPC_RTS); +} + +//----------------------------------------------------------------------------- +/// Disables the RTC power supply. +//----------------------------------------------------------------------------- +void SUPC_DisableRtc(void) +{ + AT91C_BASE_SUPC->SUPC_MR = SUPC_KEY | (AT91C_BASE_SUPC->SUPC_MR & ~AT91C_SUPC_RTCON); + while ((AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_RTS) == AT91C_SUPC_RTS); +} + +//----------------------------------------------------------------------------- +/// Sets the BOD sampling mode (or disables it). +/// \param mode BOD sampling mode. +//----------------------------------------------------------------------------- +void SUPC_SetBodSampling(unsigned int mode) +{ + SANITY_CHECK((mode & ~AT91C_SUPC_BODSMPL) == 0); + AT91C_BASE_SUPC->SUPC_BOMR &= ~AT91C_SUPC_BODSMPL; + AT91C_BASE_SUPC->SUPC_BOMR |= mode; +} + +//------------------------------------------------------------------------------ +/// Disables the voltage regulator, which makes the device enter backup mode. +//------------------------------------------------------------------------------ +void SUPC_DisableVoltageRegulator(void) +{ + AT91C_BASE_SUPC->SUPC_CR = SUPC_KEY | AT91C_SUPC_VROFF; + while (1); +} + +//------------------------------------------------------------------------------ +/// Shuts the device down so it enters Off mode. +//------------------------------------------------------------------------------ +void SUPC_Shutdown(void) +{ + AT91C_BASE_SUPC->SUPC_CR = SUPC_KEY | AT91C_SUPC_SHDW; + while (1); +} + +//------------------------------------------------------------------------------ +/// Sets the wake-up sources when in backup mode. +/// \param sources Wake-up sources to enable. +//------------------------------------------------------------------------------ +void SUPC_SetWakeUpSources(unsigned int sources) +{ + SANITY_CHECK((sources & ~0x0000000B) == 0); + AT91C_BASE_SUPC->SUPC_WUMR &= ~0x0000000B; + AT91C_BASE_SUPC->SUPC_WUMR |= sources; +} + +//------------------------------------------------------------------------------ +/// Sets the wake-up inputs when in backup mode. +/// \param inputs Wake up inputs to enable. +//------------------------------------------------------------------------------ +void SUPC_SetWakeUpInputs(unsigned int inputs) +{ + SANITY_CHECK((inputs & ~0xFFFF) == 0); + AT91C_BASE_SUPC->SUPC_WUIR &= ~0xFFFF; + AT91C_BASE_SUPC->SUPC_WUIR |= inputs; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/supc/supc.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/supc/supc.h new file mode 100644 index 000000000..f90df9321 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/supc/supc.h @@ -0,0 +1,80 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef SUPC_H +#define SUPC_H + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void SUPC_EnableSlcd(unsigned char internal); + +extern void SUPC_DisableSlcd(void); + +extern void SUPC_SetSlcdVoltage(unsigned int voltage); + +extern +#ifdef __ICCARM__ +__ramfunc // IAR +#endif +void SUPC_EnableFlash(unsigned int time); + +extern +#ifdef __ICCARM__ +__ramfunc // IAR +#endif +void SUPC_DisableFlash(void); + +extern void SUPC_SetVoltageOutput(unsigned int voltage); + +extern void SUPC_EnableDeepMode(void); + +extern void SUPC_EnableSram(void); + +extern void SUPC_DisableSram(void); + +extern void SUPC_EnableRtc(void); + +extern void SUPC_DisableRtc(void); + +extern void SUPC_SetBodSampling(unsigned int mode); + +extern void SUPC_DisableDeepMode(void); + +extern void SUPC_DisableVoltageRegulator(void); + +extern void SUPC_Shutdown(void); + +extern void SUPC_SetWakeUpSources(unsigned int sources); + +extern void SUPC_SetWakeUpInputs(unsigned int inputs); + +#endif //#ifndef SUPC_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/systick/systick.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/systick/systick.c new file mode 100644 index 000000000..ffd9fbf76 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/systick/systick.c @@ -0,0 +1,63 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "systick.h" + +//------------------------------------------------------------------------------ +/// Configures the SysTick in . +/// \param countEnable Enable SysTick counting. +/// \param reloadValue Value used for tick counter to reload. +/// \param handler Interrupt handler function, 0 to disable interrupt. +//------------------------------------------------------------------------------ +void SysTick_Configure(unsigned char countEnable, + unsigned int reloadValue, + void( *handler )( void )) +{ + unsigned int intEnable = handler ? AT91C_NVIC_STICKINT : 0; + + // Disable the SysTick & using core source + AT91C_BASE_NVIC->NVIC_STICKCSR = AT91C_NVIC_STICKCLKSOURCE; + + // Reset the current value + AT91C_BASE_NVIC->NVIC_STICKCVR &= ~AT91C_NVIC_STICKCURRENT; + + // Setup the reload value + AT91C_BASE_NVIC->NVIC_STICKRVR = reloadValue; + + // Enable the SysTick + AT91C_BASE_NVIC->NVIC_STICKCSR = AT91C_NVIC_STICKCLKSOURCE + | AT91C_NVIC_STICKENABLE + | intEnable; + +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/systick/systick.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/systick/systick.h new file mode 100644 index 000000000..e3d8439dc --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/systick/systick.h @@ -0,0 +1,68 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Methods and definitions for configuring System Tick in Cortex-M3. +/// +/// !Usage +/// +/// -# Configure the System Tick with SysTick_Configure +/// +//------------------------------------------------------------------------------ + +#ifndef SYSTICK_H +#define SYSTICK_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +/// Vendor define it's own SysTickConfig function +#define __Vendor_SysTickConfig 1 + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void SysTick_Configure(unsigned char countEnable, + unsigned int reloadValue, + void( *handler )( void )); + +#endif //#ifndef SYSTICK_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tc/tc.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tc/tc.c new file mode 100644 index 000000000..00e85fbe5 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tc/tc.c @@ -0,0 +1,143 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "tc.h" + +//------------------------------------------------------------------------------ +// Global Functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Configures a Timer Counter to operate in the given mode. Timer is stopped +/// after configuration and must be restarted with TC_Start(). All the +/// interrupts of the timer are also disabled. +/// \param pTc Pointer to an AT91S_TC instance. +/// \param mode Operating mode (TC_CMR value). +//------------------------------------------------------------------------------ +void TC_Configure(AT91S_TC *pTc, unsigned int mode) +{ + // Disable TC clock + pTc->TC_CCR = AT91C_TC_CLKDIS; + + // Disable interrupts + pTc->TC_IDR = 0xFFFFFFFF; + + // Clear status register + pTc->TC_SR; + + // Set mode + pTc->TC_CMR = mode; +} + +//------------------------------------------------------------------------------ +/// Enables the timer clock and performs a software reset to start the counting. +/// \param pTc Pointer to an AT91S_TC instance. +//------------------------------------------------------------------------------ +void TC_Start(AT91S_TC *pTc) +{ + pTc->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; +} + +//------------------------------------------------------------------------------ +/// Disables the timer clock, stopping the counting. +/// \param pTc Pointer to an AT91S_TC instance. +//------------------------------------------------------------------------------ +void TC_Stop(AT91S_TC *pTc) +{ + pTc->TC_CCR = AT91C_TC_CLKDIS; +} + +//------------------------------------------------------------------------------ +/// Finds the best MCK divisor given the timer frequency and MCK. The result +/// is guaranteed to satisfy the following equation: +/// \pre +/// (MCK / (DIV * 65536)) <= freq <= (MCK / DIV) +/// \endpre +/// with DIV being the highest possible value. +/// \param freq Desired timer frequency. +/// \param mck Master clock frequency. +/// \param div Divisor value. +/// \param tcclks TCCLKS field value for divisor. +/// \return 1 if a proper divisor has been found; otherwise 0. +//------------------------------------------------------------------------------ +unsigned char TC_FindMckDivisor( + unsigned int freq, + unsigned int mck, + unsigned int *div, + unsigned int *tcclks) +{ + const unsigned int divisors[5] = {2, 8, 32, 128, +#if defined(at91sam9260) || defined(at91sam9261) || defined(at91sam9263) \ + || defined(at91sam9xe) || defined(at91sam9rl64) || defined(at91cap9) \ + || defined(at91sam9m10) || defined(at91sam9m11) + BOARD_MCK / 32768}; +#else + 1024}; +#endif + unsigned int index = 0; + + // Satisfy lower bound + while (freq < ((mck / divisors[index]) / 65536)) { + + index++; + + // If no divisor can be found, return 0 + if (index == 5) { + + return 0; + } + } + + // Try to maximise DIV while satisfying upper bound + while (index < 4) { + + if (freq > (mck / divisors[index + 1])) { + + break; + } + index++; + } + + // Store results + if (div) { + + *div = divisors[index]; + } + if (tcclks) { + + *tcclks = index; + } + + return 1; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tc/tc.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tc/tc.h new file mode 100644 index 000000000..ea71d5411 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tc/tc.h @@ -0,0 +1,80 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// API for configuring and using Timer Counter (TC) peripherals. +/// +/// !Usage +/// -# Optionally, use TC_FindMckDivisor() to let the program find the best +/// TCCLKS field value automatically. +/// -# Configure a Timer Counter in the desired mode using TC_Configure(). +/// -# Start or stop the timer clock using TC_Start() and TC_Stop(). +//------------------------------------------------------------------------------ + +#ifndef TC_H +#define TC_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +#if defined(AT91C_ID_TC0) + // nothing to do +#elif defined(AT91C_ID_TC012) + #define AT91C_ID_TC0 AT91C_ID_TC012 +#elif defined(AT91C_ID_TC) + #define AT91C_ID_TC0 AT91C_ID_TC +#else + #error Pb define ID_TC +#endif + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void TC_Configure(AT91S_TC *pTc, unsigned int mode); + +extern void TC_Start(AT91S_TC *pTc); + +extern void TC_Stop(AT91S_TC *pTc); + +extern unsigned char TC_FindMckDivisor( + unsigned int freq, + unsigned int mck, + unsigned int *div, + unsigned int *tcclks); + +#endif //#ifndef TC_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tdes/tdes.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tdes/tdes.c new file mode 100644 index 000000000..4d78e1aca --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tdes/tdes.c @@ -0,0 +1,228 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "tdes.h" +#include +#include +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Configures the triple-DES peripheral to cipher/decipher, use single-DES or +/// triple-DES, use two or three keys (when in triple-DES mode), start manually, +/// automatically or via the PDC and use the given operating mode (ECB, CBC, +/// CFB or OFB). +/// \param cipher Encrypts if 1, decrypts if 0. +/// \param tdesmod Single- or triple-DES mode. +/// \param keymod Use two or three keys (must be 0 in single-DES mode). +/// \param smod Start mode. +/// \param opmod Encryption/decryption mode. +//------------------------------------------------------------------------------ +void TDES_Configure( + unsigned char cipher, + unsigned int tdesmod, + unsigned int keymod, + unsigned int smod, + unsigned int opmod) +{ + TRACE_DEBUG("TDES_Configure()\n\r"); + SANITY_CHECK((cipher & 0xFFFFFFFE) == 0); + SANITY_CHECK((tdesmod & 0xFFFFFFFD) == 0); + SANITY_CHECK((keymod & 0xFFFFFFEF) == 0); + SANITY_CHECK((smod & 0xFFFFFCFF) == 0); + SANITY_CHECK((opmod & 0xFFFFCFFF) == 0); + + // Reset peripheral + AT91C_BASE_TDES->TDES_CR = AT91C_TDES_SWRST; + + // Configure mode register + AT91C_BASE_TDES->TDES_MR = cipher | tdesmod | keymod | smod | opmod; +} + +//------------------------------------------------------------------------------ +/// Starts the encryption or decryption process if the TDES peripheral is +/// configured in manual or PDC mode. +//------------------------------------------------------------------------------ +void TDES_Start(void) +{ + TRACE_DEBUG("TDES_Start()\n\r"); + SANITY_CHECK(((AT91C_BASE_TDES->TDES_MR & AT91C_TDES_SMOD) == AT91C_TDES_SMOD_MANUAL) + || ((AT91C_BASE_TDES->TDES_MR & AT91C_TDES_SMOD) == AT91C_TDES_SMOD_PDC)); + + // Manual mode + if ((AT91C_BASE_TDES->TDES_MR & AT91C_TDES_SMOD) == AT91C_TDES_SMOD_MANUAL) { + + AT91C_BASE_TDES->TDES_CR = AT91C_TDES_START; + } + // PDC mode + else { + + AT91C_BASE_TDES->TDES_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTEN; + } +} + +//------------------------------------------------------------------------------ +/// Returns the current status register value of the TDES peripheral. +//------------------------------------------------------------------------------ +unsigned int TDES_GetStatus(void) +{ + TRACE_DEBUG("TDES_GetStatus()\n\r"); + + return AT91C_BASE_TDES->TDES_ISR; +} + +//------------------------------------------------------------------------------ +/// Sets the 64-bits keys (one, two or three depending on the configuration) +/// that shall be used by the TDES algorithm. +/// \param pKey1 Pointer to key #1. +/// \param pKey2 Pointer to key #2 (shall be 0 in single-DES mode). +/// \param pKey3 Pointer to key #3 (shall be 0 when using two keys). +//------------------------------------------------------------------------------ +void TDES_SetKeys( + const unsigned int *pKey1, + const unsigned int *pKey2, + const unsigned int *pKey3) +{ + TRACE_DEBUG("TDES_SetKeys()\n\r"); + SANITY_CHECK(pKey1); + SANITY_CHECK((pKey2 && ((AT91C_BASE_TDES->TDES_MR & AT91C_TDES_TDESMOD) == AT91C_TDES_TDESMOD)) + || (!pKey2 && ((AT91C_BASE_TDES->TDES_MR & AT91C_TDES_TDESMOD) == 0))); + SANITY_CHECK((pKey3 + && ((AT91C_BASE_TDES->TDES_MR & AT91C_TDES_TDESMOD) == AT91C_TDES_TDESMOD) + && ((AT91C_BASE_TDES->TDES_MR & AT91C_TDES_KEYMOD) == 0)) + || + (!pKey3 + && ((AT91C_BASE_TDES->TDES_MR & AT91C_TDES_TDESMOD) == AT91C_TDES_TDESMOD) + && ((AT91C_BASE_TDES->TDES_MR & AT91C_TDES_KEYMOD) == AT91C_TDES_KEYMOD)) + || + (!pKey3 + && ((AT91C_BASE_TDES->TDES_MR & AT91C_TDES_TDESMOD) == 0) + && ((AT91C_BASE_TDES->TDES_MR & AT91C_TDES_KEYMOD) == 0))); + + // Write key #1 + if (pKey1) { + + AT91C_BASE_TDES->TDES_KEY1WxR[0] = pKey1[0]; + AT91C_BASE_TDES->TDES_KEY1WxR[1] = pKey1[1]; + } + + // Write key #2 + if (pKey1) { + + AT91C_BASE_TDES->TDES_KEY2WxR[0] = pKey2[0]; + AT91C_BASE_TDES->TDES_KEY2WxR[1] = pKey2[1]; + } + + // Write key #2 + if (pKey1) { + + AT91C_BASE_TDES->TDES_KEY3WxR[0] = pKey3[0]; + AT91C_BASE_TDES->TDES_KEY3WxR[1] = pKey3[1]; + } +} + +//------------------------------------------------------------------------------ +/// Sets the input data to encrypt/decrypt using TDES. +/// \param pInput Pointer to the 64-bits input data. +//------------------------------------------------------------------------------ +void TDES_SetInputData(const unsigned int *pInput) +{ + TRACE_DEBUG("TDES_SetInputData()\n\r"); + SANITY_CHECK(pInput); + + AT91C_BASE_TDES->TDES_IDATAxR[0] = pInput[0]; + AT91C_BASE_TDES->TDES_IDATAxR[1] = pInput[1]; +} + +//------------------------------------------------------------------------------ +/// Sets the input data buffer to encrypt/decrypt when in PDC mode. +/// \param pInput Pointer to the input data. +/// \param size Size of buffer in bytes. +//------------------------------------------------------------------------------ +void TDES_SetInputBuffer(const unsigned int *pInput, unsigned int size) +{ + TRACE_DEBUG("TDES_SetInputBuffer()\n\r"); + SANITY_CHECK(pInput); + SANITY_CHECK((size > 0) && ((size % 8) == 0)); + + AT91C_BASE_TDES->TDES_TPR = (unsigned int) pInput; + AT91C_BASE_TDES->TDES_TCR = size / 4; +} + +//------------------------------------------------------------------------------ +/// Stores the output data from the last TDES operation into the given 64-bits +/// buffers. +/// \param pOutput Pointer to a 64-bits output buffer. +//------------------------------------------------------------------------------ +void TDES_GetOutputData(unsigned int *pOutput) +{ + TRACE_DEBUG("TDES_GetOutputData()\n\r"); + SANITY_CHECK(pOutput); + + pOutput[0] = AT91C_BASE_TDES->TDES_ODATAxR[0]; + pOutput[1] = AT91C_BASE_TDES->TDES_ODATAxR[1]; +} + +//------------------------------------------------------------------------------ +/// Sets the output buffer which will receive the encrypted/decrypted data when +/// using the PDC. +/// \param pOutput Pointer to the output data. +/// \param size Size of buffer in bytes. +//------------------------------------------------------------------------------ +void TDES_SetOutputBuffer(unsigned int *pOutput, unsigned int size) +{ + TRACE_DEBUG("TDES_SetOutputBuffer()\n\r"); + SANITY_CHECK(pOutput); + SANITY_CHECK((size > 0) && ((size % 8) == 0)); + + AT91C_BASE_TDES->TDES_RPR = (unsigned int) pOutput; + AT91C_BASE_TDES->TDES_RCR = size / 4; +} + +//------------------------------------------------------------------------------ +/// Sets the initialization vector to use when the TDES algorithm is configured +/// in a chained block mode (CBC, CFB or OFB). +/// \param pVector Pointer to the 64-bits vector. +//------------------------------------------------------------------------------ +void TDES_SetVector(const unsigned int *pVector) +{ + TRACE_DEBUG("TDES_SetVector()\n\r"); + SANITY_CHECK(pVector); + + AT91C_BASE_TDES->TDES_IVxR[0] = pVector[0]; + AT91C_BASE_TDES->TDES_IVxR[1] = pVector[1]; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tdes/tdes.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tdes/tdes.h new file mode 100644 index 000000000..cc0b9f6b7 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tdes/tdes.h @@ -0,0 +1,80 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef TDES_H +#define TDES_H + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Methods to manage the Triple DES (3DES) +/// +/// !Usage +/// +/// -# Configure TDES +/// -# Sets the key used by the TDES algorithm +/// -# Sets the input data of the TDES algorithm +/// -# Starts the encryption/decryption process +/// -# Stores the result of the last TDES operation +/// +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void TDES_Configure( + unsigned char cipher, + unsigned int tdesmod, + unsigned int keymod, + unsigned int smod, + unsigned int opmod); + +extern void TDES_Start(void); + +extern unsigned int TDES_GetStatus(void); + +extern void TDES_SetKeys( + const unsigned int *pKey1, + const unsigned int *pKey2, + const unsigned int *pKey3); + +extern void TDES_SetInputData(const unsigned int *pInput); + +extern void TDES_SetInputBuffer(const unsigned int *pInput, unsigned int size); + +extern void TDES_GetOutputData(unsigned int *pOutput); + +extern void TDES_SetOutputBuffer(unsigned int *pOutput, unsigned int size); + +extern void TDES_SetVector(const unsigned int *pVector); + +#endif //#ifndef TDES_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tsadcc/tsadcc.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tsadcc/tsadcc.c new file mode 100644 index 000000000..86b5680ba --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tsadcc/tsadcc.c @@ -0,0 +1,324 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +#ifdef AT91C_BASE_TSADC + +#include +#include + +//------------------------------------------------------------------------------ +// Local variables +//------------------------------------------------------------------------------ + +/// TSADC clock frequency in Hz. +static unsigned int lAdcclk = 0; + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Sets the operating mode of the TSADCC peripheral. The mode value can be +/// one of the following: +/// - AT91C_TSADC_TSAMOD_ADC_ONLY_MODE +/// - AT91C_TSADC_TSAMOD_TS_ONLY_MODE +/// \param mode Desired mode for the TSADCC. +//------------------------------------------------------------------------------ +void TSADCC_SetOperatingMode(unsigned int mode) +{ + SANITY_CHECK( (mode == AT91C_TSADC_TSAMOD_ADC_ONLY_MODE) + | (mode == AT91C_TSADC_TSAMOD_TS_ONLY_MODE)); + + AT91C_BASE_TSADC->TSADC_MR = (AT91C_BASE_TSADC->TSADC_MR + & ~AT91C_TSADC_TSAMOD) + | mode; +} + +//------------------------------------------------------------------------------ +/// Enables or disables the low resolution precision on the TSADC. +/// \param enable If true, low resolution (8 bit) is used; otherwise the TSADC +/// will use a 10-bit resolution. +//------------------------------------------------------------------------------ +void TSADCC_SetLowResolution(unsigned char enable) +{ + if (enable) { + + AT91C_BASE_TSADC->TSADC_MR |= AT91C_TSADC_LOWRES; + } + else { + + AT91C_BASE_TSADC->TSADC_MR &= ~AT91C_TSADC_LOWRES; + } +} + +//------------------------------------------------------------------------------ +/// Enables or disable SLEEP mode on the TSADC. +/// \param enable If true, the TSADC is put into sleep mode; in normal mode +/// otherwise. +//------------------------------------------------------------------------------ +void TSADCC_SetSleepMode(unsigned char enable) +{ + if (enable) { + + AT91C_BASE_TSADC->TSADC_MR |= AT91C_TSADC_SLEEP; + } + else { + + AT91C_BASE_TSADC->TSADC_MR &= ~AT91C_TSADC_SLEEP; + } +} + +//------------------------------------------------------------------------------ +/// Enables or disables pen detection on the TSADC. +/// \param enable If true, pen detection is enabled; otherwise it is disabled. +//------------------------------------------------------------------------------ +void TSADCC_SetPenDetect(unsigned char enable) +{ + if (enable) { + + AT91C_BASE_TSADC->TSADC_MR |= AT91C_TSADC_PENDET; + } + else { + + AT91C_BASE_TSADC->TSADC_MR &= ~AT91C_TSADC_PENDET; + } +} + +//------------------------------------------------------------------------------ +/// Sets the TSADC clock to the desired frequency. The prescaler is calculated +/// by this function so the resulting frequency is equal or inferior to the +/// desired one. +/// \param adcclk Desired ADC clock frequency in Hz. +/// \param mck Master clock frequency in Hz. +//------------------------------------------------------------------------------ +void TSADCC_SetAdcFrequency(unsigned int adcclk, unsigned int mck) +{ + unsigned int prescal; + + // Formula for PRESCAL is: + // PRESCAL = (MCK / (2 * ADCCLK)) + 1 + // First, we do the division, multiplied by 10 to get higher precision + // If the last digit is not zero, we round up to avoid generating a higher + // than required frequency. + prescal = (mck * 5) / adcclk; + if ((prescal % 10) > 0) { + + prescal = (prescal / 10); + } + else { + + SANITY_CHECK((prescal / 10) != 0); + prescal = (prescal / 10) - 1; + } + SANITY_CHECK((prescal & ~0x3F) == 0); + + AT91C_BASE_TSADC->TSADC_MR = ( AT91C_BASE_TSADC->TSADC_MR + & ~AT91C_TSADC_PRESCAL) + | (prescal << 8); + + // Save clock frequency for further timing calculations + lAdcclk = adcclk; +} + +//------------------------------------------------------------------------------ +/// Sets the TSADC startup time. This function relies on the ADCCLK frequency +/// that has been set using TSADCC_SetAdcFrequency(), so it must have been +/// called first. +/// \param time Startup time in µseconds. +//------------------------------------------------------------------------------ +void TSADCC_SetStartupTime(unsigned int time) +{ + unsigned int startup; + + SANITY_CHECK(lAdcclk != 0); + + // Formula for STARTUP is: + // STARTUP = (time x ADCCLK) / (1000000 x 8) - 1 + // Division multiplied by 10 for higher precision + startup = (time * lAdcclk) / (800000); + if ((startup % 10) > 0) { + + startup /= 10; + } + else { + + startup /= 10; + if (startup > 0) { + + startup--; + } + } + + SANITY_CHECK((startup & ~0x7F) == 0); + AT91C_BASE_TSADC->TSADC_MR = ( AT91C_BASE_TSADC->TSADC_MR + & ~AT91C_TSADC_STARTUP) + | (startup << 16); +} + +//------------------------------------------------------------------------------ +/// Sets the TSADC track and hold time. This function relies on the ADCCLK +/// frequency that has been set with TSADCC_SetAdcFrequency(), to it must be +/// called first. +/// This function also sets the track and hold time in the TSADC_TSR register. +/// \param time Track and hold time in nanoseconds. +//------------------------------------------------------------------------------ +void TSADCC_SetTrackAndHoldTime(unsigned int time) +{ + unsigned int shtim; + + SANITY_CHECK(lAdcclk != 0); + + // Formula for SHTIM: + // SHTIM = (time x ADCCLK) / 1000000000 - 1 + // Since 1 billion is close to the maximum value for an integer, we first + // divide ADCCLK by 1000 to avoid an overflow + shtim = (time * (lAdcclk / 1000)) / 100000; + if ((shtim % 10) > 0) { + + shtim /= 10; + } + else { + + shtim /= 10; + if (shtim > 0) shtim--; + } + + SANITY_CHECK((shtim & ~0xF) == 0); + AT91C_BASE_TSADC->TSADC_MR = ( AT91C_BASE_TSADC->TSADC_MR + & ~AT91C_TSADC_SHTIM) + | (shtim << 24); + AT91C_BASE_TSADC->TSADC_TSR = shtim << 24; +} + +//------------------------------------------------------------------------------ +/// Sets the TSADC debounce time. This function relies on the ADCCLK +/// frequency that has been set with TSADCC_SetAdcFrequency(), to it must be +/// called first. +/// \param time Debounce time in nanoseconds (cannot be 0). +//------------------------------------------------------------------------------ +void TSADCC_SetDebounceTime(unsigned int time) +{ + unsigned int divisor = 1000000000; + unsigned int clock = lAdcclk; + unsigned int pendbc = 0; + unsigned int targetValue; + unsigned int currentValue; + + SANITY_CHECK(lAdcclk != 0); + SANITY_CHECK(time != 0); + + // Divide time & ADCCLK first to avoid overflows + while ((divisor > 1) && ((time % 10) == 0)) { + + time /= 10; + divisor /= 10; + } + while ((divisor > 1) && ((clock % 10) == 0)) { + + clock /= 10; + divisor /= 10; + } + + // Compute PENDBC value + targetValue = time * clock / divisor; + currentValue = 1; + while (currentValue < targetValue) { + + pendbc++; + currentValue *= 2; + } + + SANITY_CHECK((pendbc & ~0xF) == 0); + AT91C_BASE_TSADC->TSADC_MR = ( AT91C_BASE_TSADC->TSADC_MR + & ~AT91C_TSADC_PENDBC) + | (pendbc << 28); +} + +//------------------------------------------------------------------------------ +/// Sets the trigger mode of the TSADCC to one of the following values: +/// - AT91C_TSADC_TRGMOD_NO_TRIGGER +/// - AT91C_TSADC_TRGMOD_EXTERNAL_TRIGGER_RE +/// - AT91C_TSADC_TRGMOD_EXTERNAL_TRIGGER_FE +/// - AT91C_TSADC_TRGMOD_EXTERNAL_TRIGGER_AE +/// - AT91C_TSADC_TRGMOD_PENDET_TRIGGER +/// - AT91C_TSADC_TRGMOD_PERIODIC_TRIGGER +/// - AT91C_TSADC_TRGMOD_CONT_TRIGGER +/// \param mode Trigger mode. +//------------------------------------------------------------------------------ +void TSADCC_SetTriggerMode(unsigned int mode) +{ + SANITY_CHECK(((mode & ~AT91C_TSADC_TRGMOD) == 0) + | ((mode & AT91C_TSADC_TRGMOD) != 0x7)); + + AT91C_BASE_TSADC->TSADC_TRGR = (AT91C_BASE_TSADC->TSADC_TRGR + & ~AT91C_TSADC_TRGMOD) + | mode; +} + +//------------------------------------------------------------------------------ +/// Sets the trigger period when using the TSADCC in periodic trigger mode. +/// As usual, this function requires TSADCC_SetAdcFrequency() to be called +/// before it. +/// \param period Trigger period in nanoseconds. +//------------------------------------------------------------------------------ +void TSADCC_SetTriggerPeriod(unsigned int period) +{ + unsigned int trgper; + unsigned int divisor = 100000000; + + while ((period >= 10) && (divisor >= 10)) { + + period /= 10; + divisor /= 10; + } + + trgper = (period * lAdcclk) / divisor; + if ((trgper % 10) > 0) { + + trgper /= 10; + } + else { + + trgper /= 10; + if (trgper > 0) trgper--; + } + + SANITY_CHECK((trgper & ~0xFFFF) == 0); + AT91C_BASE_TSADC->TSADC_TRGR = (AT91C_BASE_TSADC->TSADC_TRGR + & ~AT91C_TSADC_TRGPER) + | (trgper << 16); +} + +#endif //#ifdef AT91C_BASE_TSADC diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tsadcc/tsadcc.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tsadcc/tsadcc.h new file mode 100644 index 000000000..57dde4d7e --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/tsadcc/tsadcc.h @@ -0,0 +1,60 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef TSADCC_H +#define TSADCC_H + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +#ifdef AT91C_BASE_TSADC + +extern void TSADCC_SetOperatingMode(unsigned int mode); + +extern void TSADCC_SetLowResolution(unsigned char enable); + +extern void TSADCC_SetSleepMode(unsigned char enable); + +extern void TSADCC_SetPenDetect(unsigned char enable); + +extern void TSADCC_SetAdcFrequency(unsigned int adcclk, unsigned int mck); + +extern void TSADCC_SetStartupTime(unsigned int time); + +extern void TSADCC_SetTrackAndHoldTime(unsigned int time); + +extern void TSADCC_SetDebounceTime(unsigned int time); + +extern void TSADCC_SetTriggerMode(unsigned int mode); + +extern void TSADCC_SetTriggerPeriod(unsigned int period); + +#endif //#ifdef AT91C_BASE_TSADC +#endif //#ifndef TSADCC_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/twi/twi.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/twi/twi.c new file mode 100644 index 000000000..6437b73fe --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/twi/twi.c @@ -0,0 +1,372 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Interface for configuration the Two Wire Interface (TWI) peripheral. +/// +/// !Usage +/// +/// -# Configures a TWI peripheral to operate in master mode, at the given +/// frequency (in Hz) using TWI_Configure(). +/// -# Sends a STOP condition on the TWI using TWI_Stop(). +/// -# Starts a read operation on the TWI bus with the specified slave using +/// TWI_StartRead(). Data must then be read using TWI_ReadByte() whenever +/// a byte is available (poll using TWI_ByteReceived()). +/// -# Starts a write operation on the TWI to access the selected slave using +/// TWI_StartWrite(). A byte of data must be provided to start the write; +/// other bytes are written next. +/// -# Sends a byte of data to one of the TWI slaves on the bus using TWI_WriteByte(). +/// This function must be called once before TWI_StartWrite() with the first byte of data +/// to send, then it shall be called repeatedly after that to send the remaining bytes. +/// -# Check if a byte has been received and can be read on the given TWI +/// peripheral using TWI_ByteReceived(). +/// Check if a byte has been sent using TWI_ByteSent(). +/// -# Check if the current transmission is complete (the STOP has been sent) +/// using TWI_TransferComplete(). +/// -# Enables & disable the selected interrupts sources on a TWI peripheral +/// using TWI_EnableIt() and TWI_DisableIt(). +/// -# Get current status register of the given TWI peripheral using +/// TWI_GetStatus(). Get current status register of the given TWI peripheral, but +/// masking interrupt sources which are not currently enabled using +/// TWI_GetMaskedStatus(). +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "twi.h" +#include +#include +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Configures a TWI peripheral to operate in master mode, at the given +/// frequency (in Hz). The duty cycle of the TWI clock is set to 50%. +/// \param pTwi Pointer to an AT91S_TWI instance. +/// \param twck Desired TWI clock frequency. +/// \param mck Master clock frequency. +//------------------------------------------------------------------------------ +void TWI_ConfigureMaster(AT91S_TWI *pTwi, unsigned int twck, unsigned int mck) +{ + unsigned int ckdiv = 0; + unsigned int cldiv; + unsigned char ok = 0; + + TRACE_DEBUG("TWI_ConfigureMaster()\n\r"); + SANITY_CHECK(pTwi); + +#ifdef AT91C_TWI_SVEN // TWI slave + // SVEN: TWI Slave Mode Enabled + pTwi->TWI_CR = AT91C_TWI_SVEN; +#endif + // Reset the TWI + pTwi->TWI_CR = AT91C_TWI_SWRST; + pTwi->TWI_RHR; + + // TWI Slave Mode Disabled, TWI Master Mode Disabled +#ifdef AT91C_TWI_SVEN // TWI slave + pTwi->TWI_CR = AT91C_TWI_SVDIS; +#endif + pTwi->TWI_CR = AT91C_TWI_MSDIS; + + // Set master mode + pTwi->TWI_CR = AT91C_TWI_MSEN; + + // Configure clock + while (!ok) { + cldiv = ((mck / (2 * twck)) - 3) / power(2, ckdiv); + if (cldiv <= 255) { + + ok = 1; + } + else { + + ckdiv++; + } + } + + ASSERT(ckdiv < 8, "-F- Cannot find valid TWI clock parameters\n\r"); + TRACE_DEBUG("Using CKDIV = %u and CLDIV/CHDIV = %u\n\r", ckdiv, cldiv); + pTwi->TWI_CWGR = 0; + pTwi->TWI_CWGR = (ckdiv << 16) | (cldiv << 8) | cldiv; +} + + + +#ifdef AT91C_TWI_SVEN // TWI slave +//------------------------------------------------------------------------------ +/// Configures a TWI peripheral to operate in slave mode +/// \param pTwi Pointer to an AT91S_TWI instance. +//------------------------------------------------------------------------------ +void TWI_ConfigureSlave(AT91S_TWI *pTwi, unsigned char slaveAddress) +{ + unsigned int i; + + // TWI software reset + pTwi->TWI_CR = AT91C_TWI_SWRST; + pTwi->TWI_RHR; + + // Wait at least 10 ms + for (i=0; i < 1000000; i++); + + // TWI Slave Mode Disabled, TWI Master Mode Disabled + pTwi->TWI_CR = AT91C_TWI_SVDIS | AT91C_TWI_MSDIS; + + // Slave Address + pTwi->TWI_SMR = 0; + pTwi->TWI_SMR = (slaveAddress << 16) & AT91C_TWI_SADR; + + // SVEN: TWI Slave Mode Enabled + pTwi->TWI_CR = AT91C_TWI_SVEN; + + // Wait at least 10 ms + for (i=0; i < 1000000; i++); + ASSERT( (pTwi->TWI_CR & AT91C_TWI_SVDIS)!=AT91C_TWI_SVDIS, "Problem slave mode"); +} +#endif + +//------------------------------------------------------------------------------ +/// Sends a STOP condition on the TWI. +/// \param pTwi Pointer to an AT91S_TWI instance. +//------------------------------------------------------------------------------ +void TWI_Stop(AT91S_TWI *pTwi) +{ + SANITY_CHECK(pTwi); + + pTwi->TWI_CR = AT91C_TWI_STOP; +} + +//------------------------------------------------------------------------------ +/// Starts a read operation on the TWI bus with the specified slave, and returns +/// immediately. Data must then be read using TWI_ReadByte() whenever a byte is +/// available (poll using TWI_ByteReceived()). +/// \param pTwi Pointer to an AT91S_TWI instance. +/// \param address Slave address on the bus. +/// \param iaddress Optional internal address bytes. +/// \param isize Number of internal address bytes. +//----------------------------------------------------------------------------- +void TWI_StartRead( + AT91S_TWI *pTwi, + unsigned char address, + unsigned int iaddress, + unsigned char isize) +{ + //TRACE_DEBUG("TWI_StartRead()\n\r"); + SANITY_CHECK(pTwi); + SANITY_CHECK((address & 0x80) == 0); + SANITY_CHECK((iaddress & 0xFF000000) == 0); + SANITY_CHECK(isize < 4); + + // Set slave address and number of internal address bytes + pTwi->TWI_MMR = 0; + pTwi->TWI_MMR = (isize << 8) | AT91C_TWI_MREAD | (address << 16); + + // Set internal address bytes + pTwi->TWI_IADR = 0; + pTwi->TWI_IADR = iaddress; + + // Send START condition + pTwi->TWI_CR = AT91C_TWI_START; +} + +//----------------------------------------------------------------------------- +/// Reads a byte from the TWI bus. The read operation must have been started +/// using TWI_StartRead() and a byte must be available (check with +/// TWI_ByteReceived()). +/// Returns the byte read. +/// \param pTwi Pointer to an AT91S_TWI instance. +//----------------------------------------------------------------------------- +unsigned char TWI_ReadByte(AT91S_TWI *pTwi) +{ + SANITY_CHECK(pTwi); + + return pTwi->TWI_RHR; +} + +//----------------------------------------------------------------------------- +/// Sends a byte of data to one of the TWI slaves on the bus. This function +/// must be called once before TWI_StartWrite() with the first byte of data +/// to send, then it shall be called repeatedly after that to send the +/// remaining bytes. +/// \param pTwi Pointer to an AT91S_TWI instance. +/// \param byte Byte to send. +//----------------------------------------------------------------------------- +void TWI_WriteByte(AT91S_TWI *pTwi, unsigned char byte) +{ + SANITY_CHECK(pTwi); + + pTwi->TWI_THR = byte; +} + +//----------------------------------------------------------------------------- +/// Starts a write operation on the TWI to access the selected slave, then +/// returns immediately. A byte of data must be provided to start the write; +/// other bytes are written next. +/// \param pTwi Pointer to an AT91S_TWI instance. +/// \param address Address of slave to acccess on the bus. +/// \param iaddress Optional slave internal address. +/// \param isize Number of internal address bytes. +/// \param byte First byte to send. +//----------------------------------------------------------------------------- +void TWI_StartWrite( + AT91S_TWI *pTwi, + unsigned char address, + unsigned int iaddress, + unsigned char isize, + unsigned char byte) +{ + //TRACE_DEBUG("TWI_StartWrite()\n\r"); + SANITY_CHECK(pTwi); + SANITY_CHECK((address & 0x80) == 0); + SANITY_CHECK((iaddress & 0xFF000000) == 0); + SANITY_CHECK(isize < 4); + + // Set slave address and number of internal address bytes + pTwi->TWI_MMR = 0; + pTwi->TWI_MMR = (isize << 8) | (address << 16); + + // Set internal address bytes + pTwi->TWI_IADR = 0; + pTwi->TWI_IADR = iaddress; + + // Write first byte to send + TWI_WriteByte(pTwi, byte); +} + +//----------------------------------------------------------------------------- +/// Returns 1 if a byte has been received and can be read on the given TWI +/// peripheral; otherwise, returns 0. This function resets the status register +/// of the TWI. +/// \param pTwi Pointer to an AT91S_TWI instance. +//----------------------------------------------------------------------------- +unsigned char TWI_ByteReceived(AT91S_TWI *pTwi) +{ + return ((pTwi->TWI_SR & AT91C_TWI_RXRDY) == AT91C_TWI_RXRDY); +} + +//----------------------------------------------------------------------------- +/// Returns 1 if a byte has been sent, so another one can be stored for +/// transmission; otherwise returns 0. This function clears the status register +/// of the TWI. +/// \param pTwi Pointer to an AT91S_TWI instance. +//----------------------------------------------------------------------------- +unsigned char TWI_ByteSent(AT91S_TWI *pTwi) +{ + return ((pTwi->TWI_SR & AT91C_TWI_TXRDY) == AT91C_TWI_TXRDY); +} + +//----------------------------------------------------------------------------- +/// Returns 1 if the current transmission is complete (the STOP has been sent); +/// otherwise returns 0. +/// \param pTwi Pointer to an AT91S_TWI instance. +//----------------------------------------------------------------------------- +unsigned char TWI_TransferComplete(AT91S_TWI *pTwi) +{ + return ((pTwi->TWI_SR & AT91C_TWI_TXCOMP) == AT91C_TWI_TXCOMP); +} + +//----------------------------------------------------------------------------- +/// Enables the selected interrupts sources on a TWI peripheral. +/// \param pTwi Pointer to an AT91S_TWI instance. +/// \param sources Bitwise OR of selected interrupt sources. +//----------------------------------------------------------------------------- +void TWI_EnableIt(AT91S_TWI *pTwi, unsigned int sources) +{ + SANITY_CHECK(pTwi); + SANITY_CHECK((sources & 0xFFFFF088) == 0); + + pTwi->TWI_IER = sources; +} + +//----------------------------------------------------------------------------- +/// Disables the selected interrupts sources on a TWI peripheral. +/// \param pTwi Pointer to an AT91S_TWI instance. +/// \param sources Bitwise OR of selected interrupt sources. +//----------------------------------------------------------------------------- +void TWI_DisableIt(AT91S_TWI *pTwi, unsigned int sources) +{ + SANITY_CHECK(pTwi); + SANITY_CHECK((sources & 0xFFFFF088) == 0); + + pTwi->TWI_IDR = sources; +} + +//----------------------------------------------------------------------------- +/// Returns the current status register of the given TWI peripheral. This +/// resets the internal value of the status register, so further read may yield +/// different values. +/// \param pTwi Pointer to an AT91S_TWI instance. +//----------------------------------------------------------------------------- +unsigned int TWI_GetStatus(AT91S_TWI *pTwi) +{ + SANITY_CHECK(pTwi); + + return pTwi->TWI_SR; +} + +//----------------------------------------------------------------------------- +/// Returns the current status register of the given TWI peripheral, but +/// masking interrupt sources which are not currently enabled. +/// This resets the internal value of the status register, so further read may +/// yield different values. +/// \param pTwi Pointer to an AT91S_TWI instance. +//----------------------------------------------------------------------------- +unsigned int TWI_GetMaskedStatus(AT91S_TWI *pTwi) +{ + unsigned int status; + + SANITY_CHECK(pTwi); + + status = pTwi->TWI_SR; + status &= pTwi->TWI_IMR; + + return status; +} +//----------------------------------------------------------------------------- +/// Sends a STOP condition. STOP Condition is sent just after completing +/// the current byte transmission in master read mode. +/// \param pTwi Pointer to an AT91S_TWI instance. +//----------------------------------------------------------------------------- +void TWI_SendSTOPCondition(AT91S_TWI *pTwi) +{ + SANITY_CHECK(pTwi); + + pTwi->TWI_CR |= AT91C_TWI_STOP; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/twi/twi.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/twi/twi.h new file mode 100644 index 000000000..721b7c5ec --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/twi/twi.h @@ -0,0 +1,150 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Interface for configuration the Two Wire Interface (TWI) peripheral. +/// +/// !Usage +/// +/// -# Configures a TWI peripheral to operate in master mode, at the given +/// frequency (in Hz) using TWI_ConfigureMaster(). +/// -# or if hardware possible, configures a TWI peripheral to operate in +/// slave mode, at the given frequency (in Hz) using TWI_ConfigureSlave(). +/// -# Sends a STOP condition on the TWI using TWI_Stop(). +/// -# Starts a read operation on the TWI bus with the specified slave using +/// TWI_StartRead(). Data must then be read using TWI_ReadByte() whenever +/// a byte is available (poll using TWI_ByteReceived()). +/// -# Starts a write operation on the TWI to access the selected slave using +/// TWI_StartWrite(). A byte of data must be provided to start the write; +/// other bytes are written next. +/// -# Sends a byte of data to one of the TWI slaves on the bus using TWI_WriteByte(). +/// This function must be called once before TWI_StartWrite() with the first byte of data +/// to send, then it shall be called repeatedly after that to send the remaining bytes. +/// -# Check if a byte has been received and can be read on the given TWI +/// peripheral using TWI_ByteReceived(). +/// Check if a byte has been sent using TWI_ByteSent(). +/// -# Check if the current transmission is complete (the STOP has been sent) +/// using TWI_TransferComplete(). +/// -# Enables & disable the selected interrupts sources on a TWI peripheral +/// using TWI_EnableIt() and TWI_DisableIt(). +/// -# Get current status register of the given TWI peripheral using +/// TWI_GetStatus(). Get current status register of the given TWI peripheral, but +/// masking interrupt sources which are not currently enabled using +/// TWI_GetMaskedStatus(). +//------------------------------------------------------------------------------ + +#ifndef TWI_H +#define TWI_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +//------------------------------------------------------------------------------ +// Global definitions +//------------------------------------------------------------------------------ + +// Missing AT91C_TWI_TXRDY definition. +#ifndef AT91C_TWI_TXRDY + #define AT91C_TWI_TXRDY AT91C_TWI_TXRDY_MASTER +#endif + +// Missing AT91C_TWI_TXCOMP definition. +#ifndef AT91C_TWI_TXCOMP + #define AT91C_TWI_TXCOMP AT91C_TWI_TXCOMP_MASTER +#endif + +//------------------------------------------------------------------------------ +// Global macros +//------------------------------------------------------------------------------ + +/// Returns 1 if the TXRDY bit (ready to transmit data) is set in the given +/// status register value. +#define TWI_STATUS_TXRDY(status) ((status & AT91C_TWI_TXRDY) == AT91C_TWI_TXRDY) + +/// Returns 1 if the RXRDY bit (ready to receive data) is set in the given +/// status register value. +#define TWI_STATUS_RXRDY(status) ((status & AT91C_TWI_RXRDY) == AT91C_TWI_RXRDY) + +/// Returns 1 if the TXCOMP bit (transfer complete) is set in the given +/// status register value. +#define TWI_STATUS_TXCOMP(status) ((status & AT91C_TWI_TXCOMP) == AT91C_TWI_TXCOMP) + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void TWI_ConfigureMaster(AT91S_TWI *pTwi, unsigned int twck, unsigned int mck); + +#ifdef AT91C_TWI_SVEN // TWI slave +extern void TWI_ConfigureSlave(AT91S_TWI *pTwi, unsigned char slaveAddress); +#endif + +extern void TWI_Stop(AT91S_TWI *pTwi); + +extern void TWI_StartRead( + AT91S_TWI *pTwi, + unsigned char address, + unsigned int iaddress, + unsigned char isize); + +extern unsigned char TWI_ReadByte(AT91S_TWI *pTwi); + +extern void TWI_WriteByte(AT91S_TWI *pTwi, unsigned char byte); + +extern void TWI_StartWrite( + AT91S_TWI *pTwi, + unsigned char address, + unsigned int iaddress, + unsigned char isize, + unsigned char byte); + +extern unsigned char TWI_ByteReceived(AT91S_TWI *pTwi); + +extern unsigned char TWI_ByteSent(AT91S_TWI *pTwi); + +extern unsigned char TWI_TransferComplete(AT91S_TWI *pTwi); + +extern void TWI_EnableIt(AT91S_TWI *pTwi, unsigned int sources); + +extern void TWI_DisableIt(AT91S_TWI *pTwi, unsigned int sources); + +extern unsigned int TWI_GetStatus(AT91S_TWI *pTwi); + +extern unsigned int TWI_GetMaskedStatus(AT91S_TWI *pTwi); + +extern void TWI_SendSTOPCondition(AT91S_TWI *pTwi); + +#endif //#ifndef TWI_H diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/usart/usart.c b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/usart/usart.c new file mode 100644 index 000000000..3f6d0e30a --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/usart/usart.c @@ -0,0 +1,272 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "usart.h" +#include +#include + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +/// Configures an USART peripheral with the specified parameters. +/// \param usart Pointer to the USART peripheral to configure. +/// \param mode Desired value for the USART mode register (see the datasheet). +/// \param baudrate Baudrate at which the USART should operate (in Hz). +/// \param masterClock Frequency of the system master clock (in Hz). +//------------------------------------------------------------------------------ +void USART_Configure(AT91S_USART *usart, + unsigned int mode, + unsigned int baudrate, + unsigned int masterClock) +{ + // Reset and disable receiver & transmitter + usart->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX + | AT91C_US_RXDIS | AT91C_US_TXDIS; + + // Configure mode + usart->US_MR = mode; + + // Configure baudrate + // Asynchronous, no oversampling + if (((mode & AT91C_US_SYNC) == 0) + && ((mode & AT91C_US_OVER) == 0)) { + + usart->US_BRGR = (masterClock / baudrate) / 16; + } + // TODO other modes +} + +//------------------------------------------------------------------------------ +/// Enables or disables the transmitter of an USART peripheral. +/// \param usart Pointer to an USART peripheral +/// \param enabled If true, the transmitter is enabled; otherwise it is +/// disabled. +//------------------------------------------------------------------------------ +void USART_SetTransmitterEnabled(AT91S_USART *usart, + unsigned char enabled) +{ + if (enabled) { + + usart->US_CR = AT91C_US_TXEN; + } + else { + + usart->US_CR = AT91C_US_TXDIS; + } +} + +//------------------------------------------------------------------------------ +/// Enables or disables the receiver of an USART peripheral +/// \param usart Pointer to an USART peripheral +/// \param enabled If true, the receiver is enabled; otherwise it is disabled. +//------------------------------------------------------------------------------ +void USART_SetReceiverEnabled(AT91S_USART *usart, + unsigned char enabled) +{ + if (enabled) { + + usart->US_CR = AT91C_US_RXEN; + } + else { + + usart->US_CR = AT91C_US_RXDIS; + } +} + +//------------------------------------------------------------------------------ +/// Sends one packet of data through the specified USART peripheral. This +/// function operates synchronously, so it only returns when the data has been +/// actually sent. +/// \param usart Pointer to an USART peripheral. +/// \param data Data to send including 9nth bit and sync field if necessary (in +/// the same format as the US_THR register in the datasheet). +/// \param timeOut Time out value (0 = no timeout). +//------------------------------------------------------------------------------ +void USART_Write( + AT91S_USART *usart, + unsigned short data, + volatile unsigned int timeOut) +{ + if (timeOut == 0) { + + while ((usart->US_CSR & AT91C_US_TXEMPTY) == 0); + } + else { + + while ((usart->US_CSR & AT91C_US_TXEMPTY) == 0) { + + if (timeOut == 0) { + + TRACE_ERROR("USART_Write: Timed out.\n\r"); + return; + } + timeOut--; + } + } + + usart->US_THR = data; +} + +//------------------------------------------------------------------------------ +/// Sends the contents of a data buffer through the specified USART peripheral. +/// This function returns immediately (1 if the buffer has been queued, 0 +/// otherwise); poll the ENDTX and TXBUFE bits of the USART status register +/// to check for the transfer completion. +/// \param usart Pointer to an USART peripheral. +/// \param buffer Pointer to the data buffer to send. +/// \param size Size of the data buffer (in bytes). +//------------------------------------------------------------------------------ +unsigned char USART_WriteBuffer( + AT91S_USART *usart, + void *buffer, + unsigned int size) +{ + // Check if the first PDC bank is free + if ((usart->US_TCR == 0) && (usart->US_TNCR == 0)) { + + usart->US_TPR = (unsigned int) buffer; + usart->US_TCR = size; + usart->US_PTCR = AT91C_PDC_TXTEN; + + return 1; + } + // Check if the second PDC bank is free + else if (usart->US_TNCR == 0) { + + usart->US_TNPR = (unsigned int) buffer; + usart->US_TNCR = size; + + return 1; + } + else { + + return 0; + } +} + +//------------------------------------------------------------------------------ +/// Reads and return a packet of data on the specified USART peripheral. This +/// function operates asynchronously, so it waits until some data has been +/// received. +/// \param usart Pointer to an USART peripheral. +/// \param timeOut Time out value (0 -> no timeout). +//------------------------------------------------------------------------------ +unsigned short USART_Read( + AT91S_USART *usart, + volatile unsigned int timeOut) +{ + if (timeOut == 0) { + + while ((usart->US_CSR & AT91C_US_RXRDY) == 0); + } + else { + + while ((usart->US_CSR & AT91C_US_RXRDY) == 0) { + + if (timeOut == 0) { + + TRACE_ERROR("USART_Read: Timed out.\n\r"); + return 0; + } + timeOut--; + } + } + + return usart->US_RHR; +} + +//------------------------------------------------------------------------------ +/// Reads data from an USART peripheral, filling the provided buffer until it +/// becomes full. This function returns immediately with 1 if the buffer has +/// been queued for transmission; otherwise 0. +/// \param usart Pointer to an USART peripheral. +/// \param buffer Pointer to the buffer where the received data will be stored. +/// \param size Size of the data buffer (in bytes). +//------------------------------------------------------------------------------ +unsigned char USART_ReadBuffer(AT91S_USART *usart, + void *buffer, + unsigned int size) +{ + // Check if the first PDC bank is free + if ((usart->US_RCR == 0) && (usart->US_RNCR == 0)) { + + usart->US_RPR = (unsigned int) buffer; + usart->US_RCR = size; + usart->US_PTCR = AT91C_PDC_RXTEN; + + return 1; + } + // Check if the second PDC bank is free + else if (usart->US_RNCR == 0) { + + usart->US_RNPR = (unsigned int) buffer; + usart->US_RNCR = size; + + return 1; + } + else { + + return 0; + } +} + +//------------------------------------------------------------------------------ +/// Returns 1 if some data has been received and can be read from an USART; +/// otherwise returns 0. +/// \param usart Pointer to an AT91S_USART instance. +//------------------------------------------------------------------------------ +unsigned char USART_IsDataAvailable(AT91S_USART *usart) +{ + if ((usart->US_CSR & AT91C_US_RXRDY) != 0) { + + return 1; + } + else { + + return 0; + } +} + +//------------------------------------------------------------------------------ +/// Sets the filter value for the IRDA demodulator. +/// \param pUsart Pointer to an AT91S_USART instance. +/// \param filter Filter value. +//------------------------------------------------------------------------------ +void USART_SetIrdaFilter(AT91S_USART *pUsart, unsigned char filter) +{ + SANITY_CHECK(pUsart); + + pUsart->US_IF = filter; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/usart/usart.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/usart/usart.h new file mode 100644 index 000000000..84a633c44 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/usart/usart.h @@ -0,0 +1,118 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// !Purpose +/// +/// This module provides several definitions and methods for using an USART +/// peripheral. +/// +/// !Usage +/// -# Enable the USART peripheral clock in the PMC. +/// -# Enable the required USART PIOs (see pio.h). +/// -# Configure the UART by calling USART_Configure. +/// -# Enable the transmitter and/or the receiver of the USART using +/// USART_SetTransmitterEnabled and USART_SetReceiverEnabled. +/// -# Send data through the USART using the USART_Write and +/// USART_WriteBuffer methods. +/// -# Receive data from the USART using the USART_Read and +/// USART_ReadBuffer functions; the availability of data can be polled +/// with USART_IsDataAvailable. +/// -# Disable the transmitter and/or the receiver of the USART with +/// USART_SetTransmitterEnabled and USART_SetReceiverEnabled. +//------------------------------------------------------------------------------ + +#ifndef USART_H +#define USART_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "USART modes" +/// This page lists several common operating modes for an USART peripheral. +/// +/// !Modes +/// - USART_MODE_ASYNCHRONOUS +/// - USART_MODE_IRDA + +/// Basic asynchronous mode, i.e. 8 bits no parity. +#define USART_MODE_ASYNCHRONOUS (AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE) + +/// IRDA mode +#define USART_MODE_IRDA (AT91C_US_USMODE_IRDA | AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_FILTER) +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +extern void USART_Configure( + AT91S_USART *usart, + unsigned int mode, + unsigned int baudrate, + unsigned int masterClock); + +extern void USART_SetTransmitterEnabled(AT91S_USART *usart, unsigned char enabled); + +extern void USART_SetReceiverEnabled(AT91S_USART *usart, unsigned char enabled); + +extern void USART_Write( + AT91S_USART *usart, + unsigned short data, + volatile unsigned int timeOut); + +extern unsigned char USART_WriteBuffer( + AT91S_USART *usart, + void *buffer, + unsigned int size); + +extern unsigned short USART_Read( + AT91S_USART *usart, + volatile unsigned int timeOut); + +extern unsigned char USART_ReadBuffer( + AT91S_USART *usart, + void *buffer, + unsigned int size); + +extern unsigned char USART_IsDataAvailable(AT91S_USART *usart); + +extern void USART_SetIrdaFilter(AT91S_USART *pUsart, unsigned char filter); + +#endif //#ifndef USART_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/utility/assert.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/utility/assert.h new file mode 100644 index 000000000..5cccb6193 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/utility/assert.h @@ -0,0 +1,114 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Definition of the ASSERT() and SANITY_CHECK() macros, which are used for +/// runtime condition & parameter verifying. +/// +/// !Usage +/// +/// -# Use ASSERT() in your code to check the value of function parameters, +/// return values, etc. *Warning:* the ASSERT() condition must not have +/// any side-effect; otherwise, the program may not work properly +/// anymore when assertions are disabled. +/// -# Use SANITY_CHECK() to perform checks with a default error message +/// (outputs the file and line number where the error occured). This +/// reduces memory overhead caused by assertion error strings. +/// -# Initialize the dbgu to see failed assertions at run-time. +/// -# Assertions can be entirely disabled by defining the NOASSERT symbol +/// at compilation time. +//------------------------------------------------------------------------------ + +#ifndef ASSERT_H +#define ASSERT_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include +#include "trace.h" + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ +#if defined(NOASSERT) + #define ASSERT(...) + #define SANITY_CHECK(...) +#else + + #if (TRACE_LEVEL == 0) + /// Checks that the given condition is true, + /// otherwise stops the program execution. + /// \param condition Condition to verify. + #define ASSERT(condition, ...) { \ + if (!(condition)) { \ + while (1); \ + } \ + } + + /// Performs the same duty as the ASSERT() macro + /// \param condition Condition to verify. + #define SANITY_CHECK(condition) ASSERT(condition, ...) + + #else + /// Checks that the given condition is true, otherwise displays an error + /// message and stops the program execution. + /// \param condition Condition to verify. + #define ASSERT(condition, ...) { \ + if (!(condition)) { \ + printf("-F- ASSERT: "); \ + printf(__VA_ARGS__); \ + while (1); \ + } \ + } + #define SANITY_ERROR "Sanity check failed at %s:%d\n\r" + + /// Performs the same duty as the ASSERT() macro, except a default error + /// message is output if the condition is false. + /// \param condition Condition to verify. + #define SANITY_CHECK(condition) ASSERT(condition, SANITY_ERROR, __FILE__, __LINE__) + #endif +#endif + + + + + + + + + + +#endif //#ifndef ASSERT_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/utility/trace.h b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/utility/trace.h new file mode 100644 index 000000000..921ac97d7 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/utility/trace.h @@ -0,0 +1,238 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Standard output methods for reporting debug information, warnings and +/// errors, which can be easily be turned on/off. +/// +/// !Usage +/// -# Initialize the DBGU using TRACE_CONFIGURE() if you intend to eventually +/// disable ALL traces; otherwise use DBGU_Configure(). +/// -# Uses the TRACE_DEBUG(), TRACE_INFO(), TRACE_WARNING(), TRACE_ERROR() +/// TRACE_FATAL() macros to output traces throughout the program. +/// -# Each type of trace has a level : Debug 5, Info 4, Warning 3, Error 2 +/// and Fatal 1. Disable a group of traces by changing the value of +/// TRACE_LEVEL during compilation; traces with a level bigger than TRACE_LEVEL +/// are not generated. To generate no trace, use the reserved value 0. +/// -# Trace disabling can be static or dynamic. If dynamic disabling is selected +/// the trace level can be modified in runtime. If static disabling is selected +/// the disabled traces are not compiled. +/// +/// !Trace level description +/// -# TRACE_DEBUG (5): Traces whose only purpose is for debugging the program, +/// and which do not produce meaningful information otherwise. +/// -# TRACE_INFO (4): Informational trace about the program execution. Should +/// enable the user to see the execution flow. +/// -# TRACE_WARNING (3): Indicates that a minor error has happened. In most case +/// it can be discarded safely; it may even be expected. +/// -# TRACE_ERROR (2): Indicates an error which may not stop the program execution, +/// but which indicates there is a problem with the code. +/// -# TRACE_FATAL (1): Indicates a major error which prevents the program from going +/// any further. + +//------------------------------------------------------------------------------ + +#ifndef TRACE_H +#define TRACE_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include +#include +#include +#include + +//------------------------------------------------------------------------------ +// Global Definitions +//------------------------------------------------------------------------------ + +/// Softpack Version +#define SOFTPACK_VERSION "1.6RC1" + +#define TRACE_LEVEL_DEBUG 5 +#define TRACE_LEVEL_INFO 4 +#define TRACE_LEVEL_WARNING 3 +#define TRACE_LEVEL_ERROR 2 +#define TRACE_LEVEL_FATAL 1 +#define TRACE_LEVEL_NO_TRACE 0 + +// By default, all traces are output except the debug one. +#if !defined(TRACE_LEVEL) +#define TRACE_LEVEL TRACE_LEVEL_INFO +#endif + +// By default, trace level is static (not dynamic) +#if !defined(DYN_TRACES) +#define DYN_TRACES 0 +#endif + +#if defined(NOTRACE) +#error "Error: NOTRACE has to be not defined !" +#endif + +#undef NOTRACE +#if (DYN_TRACES==0) + #if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE) + #define NOTRACE + #endif +#endif + + + +//------------------------------------------------------------------------------ +// Global Macros +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Initializes the DBGU +/// \param mode DBGU mode. +/// \param baudrate DBGU baudrate. +/// \param mck Master clock frequency. +//------------------------------------------------------------------------------ +#define TRACE_CONFIGURE(mode, baudrate, mck) { \ + const Pin pinsDbgu[] = {PINS_DBGU}; \ + PIO_Configure(pinsDbgu, PIO_LISTSIZE(pinsDbgu)); \ + DBGU_Configure(mode, baudrate, mck); \ + } + +//------------------------------------------------------------------------------ +/// Initializes the DBGU for ISP project +/// \param mode DBGU mode. +/// \param baudrate DBGU baudrate. +/// \param mck Master clock frequency. +//------------------------------------------------------------------------------ +#if (TRACE_LEVEL==0) && (DYNTRACE==0) +#define TRACE_CONFIGURE_ISP(mode, baudrate, mck) {} +#else +#define TRACE_CONFIGURE_ISP(mode, baudrate, mck) { \ + const Pin pinsDbgu[] = {PINS_DBGU}; \ + PIO_Configure(pinsDbgu, PIO_LISTSIZE(pinsDbgu)); \ + DBGU_Configure(mode, baudrate, mck); \ + } +#endif + +//------------------------------------------------------------------------------ +/// Outputs a formatted string using if the log level is high +/// enough. Can be disabled by defining TRACE_LEVEL=0 during compilation. +/// \param format Formatted string to output. +/// \param ... Additional parameters depending on formatted string. +//------------------------------------------------------------------------------ +#if defined(NOTRACE) + +// Empty macro +#define TRACE_DEBUG(...) { } +#define TRACE_INFO(...) { } +#define TRACE_WARNING(...) { } +#define TRACE_ERROR(...) { } +#define TRACE_FATAL(...) { while(1); } + +#define TRACE_DEBUG_WP(...) { } +#define TRACE_INFO_WP(...) { } +#define TRACE_WARNING_WP(...) { } +#define TRACE_ERROR_WP(...) { } +#define TRACE_FATAL_WP(...) { while(1); } + +#elif (DYN_TRACES == 1) + +// Trace output depends on traceLevel value +#define TRACE_DEBUG(...) { if (traceLevel >= TRACE_LEVEL_DEBUG) { printf("-D- " __VA_ARGS__); } } +#define TRACE_INFO(...) { if (traceLevel >= TRACE_LEVEL_INFO) { printf("-I- " __VA_ARGS__); } } +#define TRACE_WARNING(...) { if (traceLevel >= TRACE_LEVEL_WARNING) { printf("-W- " __VA_ARGS__); } } +#define TRACE_ERROR(...) { if (traceLevel >= TRACE_LEVEL_ERROR) { printf("-E- " __VA_ARGS__); } } +#define TRACE_FATAL(...) { if (traceLevel >= TRACE_LEVEL_FATAL) { printf("-F- " __VA_ARGS__); while(1); } } + +#define TRACE_DEBUG_WP(...) { if (traceLevel >= TRACE_LEVEL_DEBUG) { printf(__VA_ARGS__); } } +#define TRACE_INFO_WP(...) { if (traceLevel >= TRACE_LEVEL_INFO) { printf(__VA_ARGS__); } } +#define TRACE_WARNING_WP(...) { if (traceLevel >= TRACE_LEVEL_WARNING) { printf(__VA_ARGS__); } } +#define TRACE_ERROR_WP(...) { if (traceLevel >= TRACE_LEVEL_ERROR) { printf(__VA_ARGS__); } } +#define TRACE_FATAL_WP(...) { if (traceLevel >= TRACE_LEVEL_FATAL) { printf(__VA_ARGS__); while(1); } } + +#else + +// Trace compilation depends on TRACE_LEVEL value +#if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG) +#define TRACE_DEBUG(...) { printf("-D- " __VA_ARGS__); } +#define TRACE_DEBUG_WP(...) { printf(__VA_ARGS__); } +#else +#define TRACE_DEBUG(...) { } +#define TRACE_DEBUG_WP(...) { } +#endif + +#if (TRACE_LEVEL >= TRACE_LEVEL_INFO) +#define TRACE_INFO(...) { printf("-I- " __VA_ARGS__); } +#define TRACE_INFO_WP(...) { printf(__VA_ARGS__); } +#else +#define TRACE_INFO(...) { } +#define TRACE_INFO_WP(...) { } +#endif + +#if (TRACE_LEVEL >= TRACE_LEVEL_WARNING) +#define TRACE_WARNING(...) { printf("-W- " __VA_ARGS__); } +#define TRACE_WARNING_WP(...) { printf(__VA_ARGS__); } +#else +#define TRACE_WARNING(...) { } +#define TRACE_WARNING_WP(...) { } +#endif + +#if (TRACE_LEVEL >= TRACE_LEVEL_ERROR) +#define TRACE_ERROR(...) { printf("-E- " __VA_ARGS__); } +#define TRACE_ERROR_WP(...) { printf(__VA_ARGS__); } +#else +#define TRACE_ERROR(...) { } +#define TRACE_ERROR_WP(...) { } +#endif + +#if (TRACE_LEVEL >= TRACE_LEVEL_FATAL) +#define TRACE_FATAL(...) { printf("-F- " __VA_ARGS__); while(1); } +#define TRACE_FATAL_WP(...) { printf(__VA_ARGS__); while(1); } +#else +#define TRACE_FATAL(...) { while(1); } +#define TRACE_FATAL_WP(...) { while(1); } +#endif + +#endif + + +//------------------------------------------------------------------------------ +// Exported variables +//------------------------------------------------------------------------------ +// Depending on DYN_TRACES, traceLevel is a modifable runtime variable +// or a define +#if !defined(NOTRACE) && (DYN_TRACES == 1) + extern unsigned int traceLevel; +#endif + +#endif //#ifndef TRACE_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/FreeRTOSConfig.h b/Demo/CORTEX_AT91SAM3U256_IAR/FreeRTOSConfig.h new file mode 100644 index 000000000..9d5ea6379 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/FreeRTOSConfig.h @@ -0,0 +1,105 @@ +/* + FreeRTOS.org V5.3.0 - Copyright (C) 2003-2009 Richard Barry. + + This file is part of the FreeRTOS.org distribution. + + FreeRTOS.org is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License (version 2) as published + by the Free Software Foundation and modified by the FreeRTOS exception. + **NOTE** The exception to the GPL is included to allow you to distribute a + combined work that includes FreeRTOS.org without being obliged to provide + the source code for any proprietary components. Alternative commercial + license and support terms are also available upon request. See the + licensing section of http://www.FreeRTOS.org for full details. + + FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along + with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 + Temple Place, Suite 330, Boston, MA 02111-1307 USA. + + + *************************************************************************** + * * + * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation * + * * + * This is a concise, step by step, 'hands on' guide that describes both * + * general multitasking concepts and FreeRTOS specifics. It presents and * + * explains numerous examples that are written using the FreeRTOS API. * + * Full source code for all the examples is provided in an accompanying * + * .zip file. * + * * + *************************************************************************** + + 1 tab == 4 spaces! + + Please ensure to read the configuration and relevant port sections of the + online documentation. + + http://www.FreeRTOS.org - Documentation, latest information, license and + contact details. + + http://www.SafeRTOS.com - A version that is certified for use in safety + critical systems. + + http://www.OpenRTOS.com - Commercial support, development, porting, + licensing and training services. +*/ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 1 +#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 48000000 ) +#define configTICK_RATE_HZ ( ( portTickType ) 1000 ) +#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 70 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 24000 ) ) +#define configMAX_TASK_NAME_LEN ( 12 ) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 0 +#define configUSE_CO_ROUTINES 0 +#define configUSE_MUTEXES 1 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configCHECK_FOR_STACK_OVERFLOW 2 + +#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 ) +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) +#define configQUEUE_REGISTRY_SIZE 10 + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ + +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 1 + + + +#define configKERNEL_INTERRUPT_PRIORITY ( 0x0f << 4 ) /* Priority 15, or 255 as only the top four bits are implemented. This is the lowest priority. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( 5 << 4 ) /* Priority 5, or 80 as only the top four bits are implemented. */ + + +#endif /* FREERTOS_CONFIG_H */ diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/ParTest/ParTest.c b/Demo/CORTEX_AT91SAM3U256_IAR/ParTest/ParTest.c new file mode 100644 index 000000000..91e2bd9c3 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/ParTest/ParTest.c @@ -0,0 +1,140 @@ +/* + FreeRTOS.org V5.3.0 - Copyright (C) 2003-2009 Richard Barry. + + This file is part of the FreeRTOS.org distribution. + + FreeRTOS.org is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License (version 2) as published + by the Free Software Foundation and modified by the FreeRTOS exception. + **NOTE** The exception to the GPL is included to allow you to distribute a + combined work that includes FreeRTOS.org without being obliged to provide + the source code for any proprietary components. Alternative commercial + license and support terms are also available upon request. See the + licensing section of http://www.FreeRTOS.org for full details. + + FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along + with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 + Temple Place, Suite 330, Boston, MA 02111-1307 USA. + + + *************************************************************************** + * * + * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation * + * * + * This is a concise, step by step, 'hands on' guide that describes both * + * general multitasking concepts and FreeRTOS specifics. It presents and * + * explains numerous examples that are written using the FreeRTOS API. * + * Full source code for all the examples is provided in an accompanying * + * .zip file. * + * * + *************************************************************************** + + 1 tab == 4 spaces! + + Please ensure to read the configuration and relevant port sections of the + online documentation. + + http://www.FreeRTOS.org - Documentation, latest information, license and + contact details. + + http://www.SafeRTOS.com - A version that is certified for use in safety + critical systems. + + http://www.OpenRTOS.com - Commercial support, development, porting, + licensing and training services. +*/ + +/*----------------------------------------------------------- + * Simple IO routines to control the LEDs. + *-----------------------------------------------------------*/ + +/* Scheduler includes. */ +#include "FreeRTOS.h" +#include "task.h" + +/* Demo includes. */ +#include "partest.h" + +/* Library includes. */ +#include +#include + +#define partestNUM_LEDS ( sizeof( xLEDPins ) / sizeof( Pin ) ) + +static const Pin xLEDPins[] = { PINS_LEDS }; + +/*-----------------------------------------------------------*/ + +void vParTestInitialise( void ) +{ +long l; + + for( l = 0; l < partestNUM_LEDS; l++ ) + { + PIO_Configure( &( xLEDPins[ l ] ), pdTRUE ); + } +} +/*-----------------------------------------------------------*/ + +void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue ) +{ + if( uxLED < partestNUM_LEDS ) + { + if( xValue ) + { + /* Turn the LED on. */ + portENTER_CRITICAL(); + { + if( xLEDPins[ uxLED ].type == PIO_OUTPUT_0 ) + { + PIO_Set( &( xLEDPins[ uxLED ]) ); + } + else + { + PIO_Clear( &( xLEDPins[ uxLED ] ) ); + } + } + portEXIT_CRITICAL(); + } + else + { + /* Turn the LED off. */ + portENTER_CRITICAL(); + { + if( xLEDPins[ uxLED ].type == PIO_OUTPUT_0 ) + { + PIO_Clear( &( xLEDPins[ uxLED ] ) ); + } + else + { + PIO_Set( &( xLEDPins[ uxLED ] ) ); + } + } + portEXIT_CRITICAL(); + } + } +} +/*-----------------------------------------------------------*/ + +void vParTestToggleLED( unsigned portBASE_TYPE uxLED ) +{ + if( uxLED < partestNUM_LEDS ) + { + if( PIO_GetOutputDataStatus( &( xLEDPins[ uxLED ] ) ) ) + { + PIO_Clear( &( xLEDPins[ uxLED ] ) ); + } + else + { + PIO_Set( &( xLEDPins[ uxLED ] ) ); + } + } +} + + + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/RTOSDemo.ewd b/Demo/CORTEX_AT91SAM3U256_IAR/RTOSDemo.ewd new file mode 100644 index 000000000..9cf6a6107 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/RTOSDemo.ewd @@ -0,0 +1,1307 @@ + + + + 2 + + Debug + + ARM + + 1 + + C-SPY + 2 + + 18 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ARMSIM_ID + 2 + + 1 + 1 + 1 + + + + + + + + ANGEL_ID + 2 + + 0 + 1 + 1 + + + + + + + + + + + + GDBSERVER_ID + 2 + + 0 + 1 + 1 + + + + + + + + + + + IARROM_ID + 2 + + 0 + 1 + 1 + + + + + + + + + + JLINK_ID + 2 + + 10 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LMIFTDI_ID + 2 + + 1 + 1 + 1 + + + + + + + + MACRAIGOR_ID + 2 + + 3 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + RDI_ID + 2 + + 1 + 1 + 1 + + + + + + + + + + + + + + + + + STLINK_ID + 2 + + 0 + 1 + 1 + + + + + THIRDPARTY_ID + 2 + + 0 + 1 + 1 + + + + + + + + + $TOOLKIT_DIR$\plugins\rtos\CMX\CmxArmPlugin.ENU.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\CMX\CmxTinyArmPlugin.ENU.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\embOS\embOSPlugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\OSE\OseEpsilonPlugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\PowerPac\PowerPacRTOS.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\ThreadX\ThreadXArmPlugin.ENU.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\uCOS-II\uCOS-II-KA-CSpy.ewplugin + 0 + + + $EW_DIR$\common\plugins\CodeCoverage\CodeCoverage.ENU.ewplugin + 1 + + + $EW_DIR$\common\plugins\FreeRTOS\FreeRTOSPlugin.ewplugin + 0 + + + $EW_DIR$\common\plugins\Orti\Orti.ENU.ewplugin + 0 + + + $EW_DIR$\common\plugins\Profiling\Profiling.ENU.ewplugin + 1 + + + $EW_DIR$\common\plugins\Stack\Stack.ENU.ewplugin + 1 + + + $EW_DIR$\common\plugins\SymList\SymList.ENU.ewplugin + 1 + + + + + Release + + ARM + + 1 + + C-SPY + 2 + + 18 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ARMSIM_ID + 2 + + 1 + 1 + 1 + + + + + + + + ANGEL_ID + 2 + + 0 + 1 + 1 + + + + + + + + + + + + GDBSERVER_ID + 2 + + 0 + 1 + 1 + + + + + + + + + + + IARROM_ID + 2 + + 0 + 1 + 1 + + + + + + + + + + JLINK_ID + 2 + + 10 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LMIFTDI_ID + 2 + + 1 + 1 + 1 + + + + + + + + MACRAIGOR_ID + 2 + + 3 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + RDI_ID + 2 + + 1 + 1 + 1 + + + + + + + + + + + + + + + + + STLINK_ID + 2 + + 0 + 1 + 1 + + + + + THIRDPARTY_ID + 2 + + 0 + 1 + 1 + + + + + + + + + $TOOLKIT_DIR$\plugins\rtos\CMX\CmxArmPlugin.ENU.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\CMX\CmxTinyArmPlugin.ENU.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\embOS\embOSPlugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\OSE\OseEpsilonPlugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\PowerPac\PowerPacRTOS.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\ThreadX\ThreadXArmPlugin.ENU.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\uCOS-II\uCOS-II-KA-CSpy.ewplugin + 0 + + + $EW_DIR$\common\plugins\CodeCoverage\CodeCoverage.ENU.ewplugin + 1 + + + $EW_DIR$\common\plugins\FreeRTOS\FreeRTOSPlugin.ewplugin + 0 + + + $EW_DIR$\common\plugins\Orti\Orti.ENU.ewplugin + 0 + + + $EW_DIR$\common\plugins\Profiling\Profiling.ENU.ewplugin + 1 + + + $EW_DIR$\common\plugins\Stack\Stack.ENU.ewplugin + 1 + + + $EW_DIR$\common\plugins\SymList\SymList.ENU.ewplugin + 1 + + + + + + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/RTOSDemo.ewp b/Demo/CORTEX_AT91SAM3U256_IAR/RTOSDemo.ewp new file mode 100644 index 000000000..5687e0d24 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/RTOSDemo.ewp @@ -0,0 +1,1712 @@ + + + + 2 + + Debug + + ARM + + 1 + + General + 3 + + 17 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ICCARM + 2 + + 21 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AARM + 2 + + 7 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OBJCOPY + 0 + + 1 + 1 + 1 + + + + + + + + + CUSTOM + 3 + + + + + + + BICOMP + 0 + + + + BUILDACTION + 1 + + + + + + + ILINK + 0 + + 7 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IARCHIVE + 0 + + 0 + 1 + 1 + + + + + + + BILINK + 0 + + + + + Release + + ARM + + 1 + + General + 3 + + 17 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ICCARM + 2 + + 21 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AARM + 2 + + 7 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OBJCOPY + 0 + + 1 + 1 + 1 + + + + + + + + + CUSTOM + 3 + + + + + + + BICOMP + 0 + + + + BUILDACTION + 1 + + + + + + + ILINK + 0 + + 7 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IARCHIVE + 0 + + 0 + 1 + 1 + + + + + + + BILINK + 0 + + + + + AT91Lib + + $PROJ_DIR$\AT91Lib\drivers\lcd\draw_hx8347.c + + + $PROJ_DIR$\AT91Lib\drivers\lcd\font.c + + + $PROJ_DIR$\AT91Lib\components\hx8347\hx8347.c + + + $PROJ_DIR$\AT91Lib\peripherals\lcd\lcd.c + + + $PROJ_DIR$\AT91Lib\drivers\lcd\lcdd_hx8347.c + + + $PROJ_DIR$\AT91Lib\peripherals\irq\nvic.c + + + $PROJ_DIR$\AT91Lib\peripherals\pio\pio.c + + + $PROJ_DIR$\AT91Lib\peripherals\pmc\pmc.c + + + $PROJ_DIR$\AT91Lib\peripherals\usart\usart.c + + + + Common Demo Source + + $PROJ_DIR$\..\Common\Minimal\BlockQ.c + + + $PROJ_DIR$\..\Common\Minimal\blocktim.c + + + $PROJ_DIR$\..\Common\Minimal\comtest.c + + + $PROJ_DIR$\..\Common\Minimal\flash.c + + + $PROJ_DIR$\..\Common\Minimal\GenQTest.c + + + $PROJ_DIR$\..\Common\Minimal\integer.c + + + $PROJ_DIR$\..\Common\Minimal\PollQ.c + + + $PROJ_DIR$\..\Common\Minimal\QPeek.c + + + $PROJ_DIR$\..\Common\Minimal\recmutex.c + + + $PROJ_DIR$\..\Common\Minimal\semtest.c + + + + FreeRTOS Source + + port layer + + $PROJ_DIR$\..\..\Source\portable\IAR\ARM_CM3\port.c + + + $PROJ_DIR$\..\..\Source\portable\IAR\ARM_CM3\portasm.s + + + + $PROJ_DIR$\..\..\Source\portable\MemMang\heap_2.c + + + $PROJ_DIR$\..\..\Source\list.c + + + $PROJ_DIR$\..\..\Source\queue.c + + + $PROJ_DIR$\serial\serial.c + + + $PROJ_DIR$\..\..\Source\tasks.c + + + + System + + $PROJ_DIR$\system\board_cstartup_iar.c + + + $PROJ_DIR$\system\board_lowlevel.c + + + $PROJ_DIR$\system\board_memories.c + + + $PROJ_DIR$\system\exceptions.c + + + + $PROJ_DIR$\main.c + + + $PROJ_DIR$\ParTest\ParTest.c + + + + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/RTOSDemo.eww b/Demo/CORTEX_AT91SAM3U256_IAR/RTOSDemo.eww new file mode 100644 index 000000000..239a9381e --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/RTOSDemo.eww @@ -0,0 +1,10 @@ + + + + + $WS_DIR$\RTOSDemo.ewp + + + + + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/Release/Exe/RTOSDemo.sim b/Demo/CORTEX_AT91SAM3U256_IAR/Release/Exe/RTOSDemo.sim new file mode 100644 index 000000000..0aef29ccd Binary files /dev/null and b/Demo/CORTEX_AT91SAM3U256_IAR/Release/Exe/RTOSDemo.sim differ diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/Release/Exe/RTOSDemo.sim._1 b/Demo/CORTEX_AT91SAM3U256_IAR/Release/Exe/RTOSDemo.sim._1 new file mode 100644 index 000000000..0aef29ccd Binary files /dev/null and b/Demo/CORTEX_AT91SAM3U256_IAR/Release/Exe/RTOSDemo.sim._1 differ diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/Release/Obj/RTOSDemo.pbd b/Demo/CORTEX_AT91SAM3U256_IAR/Release/Obj/RTOSDemo.pbd new file mode 100644 index 000000000..c8d765a8d --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/Release/Obj/RTOSDemo.pbd @@ -0,0 +1,33 @@ +This is an internal working file generated by the Source Browser. +13:26 47s +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\BlockQ.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\GenQTest.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\ParTest.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\PollQ.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\QPeek.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\blocktim.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\board_cstartup_iar.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\board_lowlevel.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\board_memories.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\comtest.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\draw_hx8347.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\exceptions.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\flash.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\font.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\heap_2.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\hx8347.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\integer.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\lcd.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\lcdd_hx8347.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\list.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\main.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\nvic.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\pio.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\pmc.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\port.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\queue.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\recmutex.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\semtest.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\serial.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\tasks.pbi +C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\Release\Obj\usart.pbi diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/lcd_message.h b/Demo/CORTEX_AT91SAM3U256_IAR/lcd_message.h new file mode 100644 index 000000000..d9b521082 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/lcd_message.h @@ -0,0 +1,60 @@ +/* + FreeRTOS.org V5.3.0 - Copyright (C) 2003-2009 Richard Barry. + + This file is part of the FreeRTOS.org distribution. + + FreeRTOS.org is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License (version 2) as published + by the Free Software Foundation and modified by the FreeRTOS exception. + **NOTE** The exception to the GPL is included to allow you to distribute a + combined work that includes FreeRTOS.org without being obliged to provide + the source code for any proprietary components. Alternative commercial + license and support terms are also available upon request. See the + licensing section of http://www.FreeRTOS.org for full details. + + FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along + with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 + Temple Place, Suite 330, Boston, MA 02111-1307 USA. + + + *************************************************************************** + * * + * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation * + * * + * This is a concise, step by step, 'hands on' guide that describes both * + * general multitasking concepts and FreeRTOS specifics. It presents and * + * explains numerous examples that are written using the FreeRTOS API. * + * Full source code for all the examples is provided in an accompanying * + * .zip file. * + * * + *************************************************************************** + + 1 tab == 4 spaces! + + Please ensure to read the configuration and relevant port sections of the + online documentation. + + http://www.FreeRTOS.org - Documentation, latest information, license and + contact details. + + http://www.SafeRTOS.com - A version that is certified for use in safety + critical systems. + + http://www.OpenRTOS.com - Commercial support, development, porting, + licensing and training services. +*/ + +#ifndef LCD_MESSAGE_H +#define LCD_MESSAGE_H + +typedef struct +{ + char const *pcMessage; +} xLCDMessage; + +#endif /* LCD_MESSAGE_H */ diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/main.c b/Demo/CORTEX_AT91SAM3U256_IAR/main.c new file mode 100644 index 000000000..6a8095d21 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/main.c @@ -0,0 +1,317 @@ +/* + FreeRTOS.org V5.3.0 - Copyright (C) 2003-2009 Richard Barry. + + This file is part of the FreeRTOS.org distribution. + + FreeRTOS.org is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License (version 2) as published + by the Free Software Foundation and modified by the FreeRTOS exception. + **NOTE** The exception to the GPL is included to allow you to distribute a + combined work that includes FreeRTOS.org without being obliged to provide + the source code for any proprietary components. Alternative commercial + license and support terms are also available upon request. See the + licensing section of http://www.FreeRTOS.org for full details. + + FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along + with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 + Temple Place, Suite 330, Boston, MA 02111-1307 USA. + + + *************************************************************************** + * * + * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation * + * * + * This is a concise, step by step, 'hands on' guide that describes both * + * general multitasking concepts and FreeRTOS specifics. It presents and * + * explains numerous examples that are written using the FreeRTOS API. * + * Full source code for all the examples is provided in an accompanying * + * .zip file. * + * * + *************************************************************************** + + 1 tab == 4 spaces! + + Please ensure to read the configuration and relevant port sections of the + online documentation. + + http://www.FreeRTOS.org - Documentation, latest information, license and + contact details. + + http://www.SafeRTOS.com - A version that is certified for use in safety + critical systems. + + http://www.OpenRTOS.com - Commercial support, development, porting, + licensing and training services. +*/ + +/* + * Creates all the demo application tasks, then starts the scheduler. The WEB + * documentation provides more details of the standard demo application tasks + * (which just exist to test the kernel port and provide an example of how to use + * each FreeRTOS API function). + * + * In addition to the standard demo tasks, the following tasks and tests are + * defined and/or created within this file: + * + * "LCD" task - the LCD task is a 'gatekeeper' task. It is the only task that + * is permitted to access the display directly. Other tasks wishing to write a + * message to the LCD send the message on a queue to the LCD task instead of + * accessing the LCD themselves. The LCD task just blocks on the queue waiting + * for messages - waking and displaying the messages as they arrive. The use + * of a gatekeeper in this manner permits both tasks and interrupts to write to + * the LCD without worrying about mutual exclusion. This is demonstrated by the + * check hook (see below) which sends messages to the display even though it + * executes from an interrupt context. + * + * "Check" hook - This only executes fully every five seconds from the tick + * hook. Its main function is to check that all the standard demo tasks are + * still operational. Should any unexpected behaviour be discovered within a + * demo task then the tick hook will write an error to the LCD (via the LCD task). + * If all the demo tasks are executing with their expected behaviour then the + * check task writes PASS to the LCD (again via the LCD task), as described above. + * + */ + +/* Scheduler includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "semphr.h" + +/* Demo app includes. */ +#include "BlockQ.h" +#include "integer.h" +#include "blocktim.h" +#include "flash.h" +#include "partest.h" +#include "semtest.h" +#include "PollQ.h" +#include "lcd_message.h" +#include "GenQTest.h" +#include "QPeek.h" +#include "recmutex.h" +#include "flash.h" +#include "comtest2.h" + +/* Atmel library includes. */ +#include +#include +#include +#include + + +/*-----------------------------------------------------------*/ + +/* The time between cycles of the 'check' functionality (defined within the +tick hook). */ +#define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS ) + +/* The LCD task uses the sprintf function so requires a little more stack too. */ +#define mainLCD_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 ) + +/* Task priorities. */ +#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 ) +#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 ) +#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 ) +#define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 ) +#define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 ) +#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY ) +#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY ) + +/* The maximum number of message that can be waiting for display at any one +time. */ +#define mainLCD_QUEUE_SIZE ( 3 ) + +/* Constants used by the comtest tasks. There isn't a spare LED so an invalid +LED is specified. */ +#define mainBAUD_RATE ( 115200 ) +#define mainCOM_TEST_LED ( 10 ) + +/*-----------------------------------------------------------*/ + +/* + * Configure the hardware for the demo. + */ +static void prvSetupHardware( void ); + +/* + * The LCD gatekeeper task. Tasks wishing to write to the LCD do not access + * the LCD directly, but instead send the message to the LCD gatekeeper task. + */ +static void prvLCDTask( void *pvParameters ); + +/* + * Hook functions that can get called by the kernel. The 'check' functionality + * is implemented within the tick hook. + */ +void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName ); + +/* + * The tick hook function as described in the comments at the top of this file. + * The tick hook is used to monitor all the standard demo tasks to look for + * errors. The tick hook is also used to demonstrate how the LCD gatekeeper + * task can be used to allow interrupts to write to the LCD. + */ +void vApplicationTickHook( void ); + + +/*-----------------------------------------------------------*/ + +/* The queue used to send messages to the LCD task. */ +static xQueueHandle xLCDQueue; + +/*-----------------------------------------------------------*/ + +int main( void ) +{ + /* Prepare the hardware. */ + prvSetupHardware(); + + /* Create the queue used by the LCD task. Messages for display on the LCD + are received via this queue. */ + xLCDQueue = xQueueCreate( mainLCD_QUEUE_SIZE, sizeof( xLCDMessage ) ); + + /* Start the standard demo tasks. These do nothing other than test the + port and provide some APU usage examples. */ + vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY ); + vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY ); + vStartRecursiveMutexTasks(); + vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY ); + vCreateBlockTimeTasks(); + vStartSemaphoreTasks( mainSEM_TEST_PRIORITY ); + vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY ); + vStartQueuePeekTasks(); + vStartLEDFlashTasks( mainLED_TASK_PRIORITY ); + vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainBAUD_RATE, mainCOM_TEST_LED ); + + /* Start the tasks defined within this file/specific to this demo. */ + xTaskCreate( prvLCDTask, ( signed char * ) "LCD", mainLCD_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); + + /* Start the scheduler. */ + vTaskStartScheduler(); + + /* Will only get here if there was insufficient memory to create the idle + task. */ + return 0; +} +/*-----------------------------------------------------------*/ + +void prvSetupHardware( void ) +{ + /* Initialise the port used for the LED outputs. */ + vParTestInitialise(); +} +/*-----------------------------------------------------------*/ + +void vApplicationTickHook( void ) +{ +static xLCDMessage xMessage = { "PASS" }; +static unsigned portLONG ulTicksSinceLastDisplay = 0; +portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; + + /* Called from every tick interrupt. Have enough ticks passed to make it + time to perform our health status check again? */ + ulTicksSinceLastDisplay++; + if( ulTicksSinceLastDisplay >= mainCHECK_DELAY ) + { + ulTicksSinceLastDisplay = 0; + + /* Has an error been found in any task? */ + if( xAreGenericQueueTasksStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN GEN Q"; + } + if( xAreIntegerMathsTaskStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN MATH"; + } + else if( xAreBlockingQueuesStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN BLOCK Q"; + } + else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN BLOCK TIME"; + } + else if( xAreSemaphoreTasksStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN SEMAPHORE"; + } + else if( xArePollingQueuesStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN POLL Q"; + } + else if( xAreQueuePeekTasksStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN PEEK Q"; + } + else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN REC MUTEX"; + } + else if( xAreComTestTasksStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN COMTEST"; + } + + /* Send the message to the LCD gatekeeper for display. */ + xHigherPriorityTaskWoken = pdFALSE; + xQueueSendFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken ); + } +} +/*-----------------------------------------------------------*/ + +void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ) +{ + ( void ) pxTask; + ( void ) pcTaskName; + + /* If the parameters have been corrupted then inspect pxCurrentTCB to + identify which task has overflowed its stack. */ + for( ;; ); +} +/*-----------------------------------------------------------*/ + +static void prvLCDTask( void *pvParameters ) +{ +xLCDMessage xMessage; +unsigned long ulY = 0; +const unsigned long ulX = 5; +const unsigned long ulMaxY = 250, ulYIncrement = 22, ulWidth = 250, ulHeight = 20;; + + /* Initialize LCD. */ + LCDD_Initialize(); + LCDD_Start(); + LCDD_Fill( ( void * ) BOARD_LCD_BASE, COLOR_WHITE ); + LCDD_DrawString( ( void * ) BOARD_LCD_BASE, 1, ulY + 3, " www.FreeRTOS.org", COLOR_BLACK ); + + for( ;; ) + { + /* Wait for a message from the check function (which is executed in + the tick hook). */ + xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ); + + /* Clear the space where the old message was. */ + LCDD_DrawRectangle( ( void * ) BOARD_LCD_BASE, 0, ulY, ulWidth, ulHeight, COLOR_WHITE ); + + /* Increment to the next drawing position. */ + ulY += ulYIncrement; + + /* Have the Y position moved past the end of the LCD? */ + if( ulY >= ulMaxY ) + { + ulY = 0; + } + + /* Draw a new rectangle, in which the message will be written. */ + LCDD_DrawRectangle( ( void * ) BOARD_LCD_BASE, 0, ulY, ulWidth, ulHeight, COLOR_GREEN ); + + /* Write the message. */ + LCDD_DrawString( ( void * ) BOARD_LCD_BASE, ulX, ulY + 3, xMessage.pcMessage, COLOR_BLACK ); + } +} diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/printf-stdarg.c b/Demo/CORTEX_AT91SAM3U256_IAR/printf-stdarg.c new file mode 100644 index 000000000..f6139dc80 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/printf-stdarg.c @@ -0,0 +1,293 @@ +/* + Copyright 2001, 2002 Georges Menie (www.menie.org) + stdarg version contributed by Christian Ettinger + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + putchar is the only external dependency for this file, + if you have a working putchar, leave it commented out. + If not, uncomment the define below and + replace outbyte(c) by your own function call. + +*/ + +#define putchar(c) c + +#include + +static void printchar(char **str, int c) +{ + //extern int putchar(int c); + + if (str) { + **str = (char)c; + ++(*str); + } + else + { + (void)putchar(c); + } +} + +#define PAD_RIGHT 1 +#define PAD_ZERO 2 + +static int prints(char **out, const char *string, int width, int pad) +{ + register int pc = 0, padchar = ' '; + + if (width > 0) { + register int len = 0; + register const char *ptr; + for (ptr = string; *ptr; ++ptr) ++len; + if (len >= width) width = 0; + else width -= len; + if (pad & PAD_ZERO) padchar = '0'; + } + if (!(pad & PAD_RIGHT)) { + for ( ; width > 0; --width) { + printchar (out, padchar); + ++pc; + } + } + for ( ; *string ; ++string) { + printchar (out, *string); + ++pc; + } + for ( ; width > 0; --width) { + printchar (out, padchar); + ++pc; + } + + return pc; +} + +/* the following should be enough for 32 bit int */ +#define PRINT_BUF_LEN 12 + +static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase) +{ + char print_buf[PRINT_BUF_LEN]; + register char *s; + register int t, neg = 0, pc = 0; + register unsigned int u = (unsigned int)i; + + if (i == 0) { + print_buf[0] = '0'; + print_buf[1] = '\0'; + return prints (out, print_buf, width, pad); + } + + if (sg && b == 10 && i < 0) { + neg = 1; + u = (unsigned int)-i; + } + + s = print_buf + PRINT_BUF_LEN-1; + *s = '\0'; + + while (u) { + t = (int)u % b; + if( t >= 10 ) + t += letbase - '0' - 10; + *--s = (char)(t + '0'); + u /= b; + } + + if (neg) { + if( width && (pad & PAD_ZERO) ) { + printchar (out, '-'); + ++pc; + --width; + } + else { + *--s = '-'; + } + } + + return pc + prints (out, s, width, pad); +} + +static int print( char **out, const char *format, va_list args ) +{ + register int width, pad; + register int pc = 0; + char scr[2]; + + for (; *format != 0; ++format) { + if (*format == '%') { + ++format; + width = pad = 0; + if (*format == '\0') break; + if (*format == '%') goto out; + if (*format == '-') { + ++format; + pad = PAD_RIGHT; + } + while (*format == '0') { + ++format; + pad |= PAD_ZERO; + } + for ( ; *format >= '0' && *format <= '9'; ++format) { + width *= 10; + width += *format - '0'; + } + if( *format == 's' ) { + register char *s = (char *)va_arg( args, int ); + pc += prints (out, s?s:"(null)", width, pad); + continue; + } + if( *format == 'd' ) { + pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a'); + continue; + } + if( *format == 'x' ) { + pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a'); + continue; + } + if( *format == 'X' ) { + pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A'); + continue; + } + if( *format == 'u' ) { + pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a'); + continue; + } + if( *format == 'c' ) { + /* char are converted to int then pushed on the stack */ + scr[0] = (char)va_arg( args, int ); + scr[1] = '\0'; + pc += prints (out, scr, width, pad); + continue; + } + } + else { + out: + printchar (out, *format); + ++pc; + } + } + if (out) **out = '\0'; + va_end( args ); + return pc; +} + +int printf(const char *format, ...) +{ + va_list args; + + va_start( args, format ); + return print( 0, format, args ); +} + +int sprintf(char *out, const char *format, ...) +{ + va_list args; + + va_start( args, format ); + return print( &out, format, args ); +} + + +int snprintf( char *buf, unsigned int count, const char *format, ... ) +{ + va_list args; + + ( void ) count; + + va_start( args, format ); + return print( &buf, format, args ); +} + + +#ifdef TEST_PRINTF +int main(void) +{ + char *ptr = "Hello world!"; + char *np = 0; + int i = 5; + unsigned int bs = sizeof(int)*8; + int mi; + char buf[80]; + + mi = (1 << (bs-1)) + 1; + printf("%s\n", ptr); + printf("printf test\n"); + printf("%s is null pointer\n", np); + printf("%d = 5\n", i); + printf("%d = - max int\n", mi); + printf("char %c = 'a'\n", 'a'); + printf("hex %x = ff\n", 0xff); + printf("hex %02x = 00\n", 0); + printf("signed %d = unsigned %u = hex %x\n", -3, -3, -3); + printf("%d %s(s)%", 0, "message"); + printf("\n"); + printf("%d %s(s) with %%\n", 0, "message"); + sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf); + sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf); + sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf); + sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf); + sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf); + sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf); + sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf); + sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf); + + return 0; +} + +/* + * if you compile this file with + * gcc -Wall $(YOUR_C_OPTIONS) -DTEST_PRINTF -c printf.c + * you will get a normal warning: + * printf.c:214: warning: spurious trailing `%' in format + * this line is testing an invalid % at the end of the format string. + * + * this should display (on 32bit int machine) : + * + * Hello world! + * printf test + * (null) is null pointer + * 5 = 5 + * -2147483647 = - max int + * char a = 'a' + * hex ff = ff + * hex 00 = 00 + * signed -3 = unsigned 4294967293 = hex fffffffd + * 0 message(s) + * 0 message(s) with % + * justif: "left " + * justif: " right" + * 3: 0003 zero padded + * 3: 3 left justif. + * 3: 3 right justif. + * -3: -003 zero padded + * -3: -3 left justif. + * -3: -3 right justif. + */ + +#endif + + +/* To keep linker happy. */ +int write( int i, char* c, int n) +{ + (void)i; + (void)n; + (void)c; + return 0; +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/serial/serial.c b/Demo/CORTEX_AT91SAM3U256_IAR/serial/serial.c new file mode 100644 index 000000000..0bd73fb0e --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/serial/serial.c @@ -0,0 +1,259 @@ +/* + FreeRTOS.org V5.3.0 - Copyright (C) 2003-2009 Richard Barry. + + This file is part of the FreeRTOS.org distribution. + + FreeRTOS.org is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License (version 2) as published + by the Free Software Foundation and modified by the FreeRTOS exception. + **NOTE** The exception to the GPL is included to allow you to distribute a + combined work that includes FreeRTOS.org without being obliged to provide + the source code for any proprietary components. Alternative commercial + license and support terms are also available upon request. See the + licensing section of http://www.FreeRTOS.org for full details. + + FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along + with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 + Temple Place, Suite 330, Boston, MA 02111-1307 USA. + + + *************************************************************************** + * * + * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation * + * * + * This is a concise, step by step, 'hands on' guide that describes both * + * general multitasking concepts and FreeRTOS specifics. It presents and * + * explains numerous examples that are written using the FreeRTOS API. * + * Full source code for all the examples is provided in an accompanying * + * .zip file. * + * * + *************************************************************************** + + 1 tab == 4 spaces! + + Please ensure to read the configuration and relevant port sections of the + online documentation. + + http://www.FreeRTOS.org - Documentation, latest information, license and + contact details. + + http://www.SafeRTOS.com - A version that is certified for use in safety + critical systems. + + http://www.OpenRTOS.com - Commercial support, development, porting, + licensing and training services. +*/ + +/* + BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR UART0. +*/ + +/* Standard includes. */ +#include + +/* Scheduler includes. */ +#include "FreeRTOS.h" +#include "queue.h" + +/* Demo application includes. */ +#include "serial.h" + +/* Library includes. */ +#include "usart/usart.h" +#include "pmc/pmc.h" +#include "irq/irq.h" +#include "pio/pio.h" + +/*-----------------------------------------------------------*/ + +/* Interrupt control macros. */ +#define serINTERRUPT_LEVEL ( 5 ) +#define vInterruptOn() BOARD_USART_BASE->US_IER = ( AT91C_US_TXRDY | AT91C_US_RXRDY ) +#define vInterruptOff() BOARD_USART_BASE->US_IDR = AT91C_US_TXRDY + +/* Misc constants. */ +#define serINVALID_QUEUE ( ( xQueueHandle ) 0 ) +#define serHANDLE ( ( xComPortHandle ) 1 ) +#define serNO_BLOCK ( ( portTickType ) 0 ) +#define serNO_TIMEGUARD ( ( unsigned portLONG ) 0 ) +#define serNO_PERIPHERAL_B_SETUP ( ( unsigned portLONG ) 0 ) + + +/* Queues used to hold received characters, and characters waiting to be +transmitted. */ +static xQueueHandle xRxedChars; +static xQueueHandle xCharsForTx; + +/*-----------------------------------------------------------*/ + +/* The interrupt service routine - called from the assembly entry point. */ +void vSerialISR( void ); + +/*-----------------------------------------------------------*/ + +/* + * See the serial2.h header file. + */ +xComPortHandle xSerialPortInitMinimal( unsigned portLONG ulWantedBaud, unsigned portBASE_TYPE uxQueueLength ) +{ +xComPortHandle xReturn = serHANDLE; +extern void ( vUART_ISR )( void ); +const Pin xUSART_Pins[] = { BOARD_PIN_USART_RXD, BOARD_PIN_USART_TXD }; + + + /* Create the queues used to hold Rx and Tx characters. */ + xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) ); + xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) ); + + /* If the queues were created correctly then setup the serial port + hardware. */ + if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) ) + { + portENTER_CRITICAL(); + { + /* Enable the peripheral clock in the PMC. */ + PMC_EnablePeripheral( BOARD_ID_USART ); + + /* Configure the USART. */ + USART_Configure( BOARD_USART_BASE, AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT, ulWantedBaud, configCPU_CLOCK_HZ ); + + /* Configure the interrupt. Note the pre-emption priority is set + in bits [8:15] of the priority value passed as the parameter. */ + IRQ_ConfigureIT( BOARD_ID_USART, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 8 ), vSerialISR ); + IRQ_EnableIT( BOARD_ID_USART ); + + /* Enable receiver & transmitter. */ + USART_SetTransmitterEnabled( BOARD_USART_BASE, pdTRUE ); + USART_SetReceiverEnabled( BOARD_USART_BASE, pdTRUE ); + + /* Configure IO for USART use. */ + PIO_Configure( xUSART_Pins, PIO_LISTSIZE( xUSART_Pins ) ); + } + portEXIT_CRITICAL(); + } + else + { + xReturn = ( xComPortHandle ) 0; + } + + /* This demo file only supports a single port but we have to return + something to comply with the standard demo header file. */ + return xReturn; +} +/*-----------------------------------------------------------*/ + +signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed portCHAR *pcRxedChar, portTickType xBlockTime ) +{ + /* The port handle is not required as this driver only supports one port. */ + ( void ) pxPort; + + /* Get the next character from the buffer. Return false if no characters + are available, or arrive before xBlockTime expires. */ + if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) ) + { + return pdTRUE; + } + else + { + return pdFALSE; + } +} +/*-----------------------------------------------------------*/ + +void vSerialPutString( xComPortHandle pxPort, const signed portCHAR * const pcString, unsigned portSHORT usStringLength ) +{ +signed portCHAR *pxNext; + + /* A couple of parameters that this port does not use. */ + ( void ) usStringLength; + ( void ) pxPort; + + /* NOTE: This implementation does not handle the queue being full as no + block time is used! */ + + /* The port handle is not required as this driver only supports UART0. */ + ( void ) pxPort; + + /* Send each character in the string, one at a time. */ + pxNext = ( signed portCHAR * ) pcString; + while( *pxNext ) + { + xSerialPutChar( pxPort, *pxNext, serNO_BLOCK ); + pxNext++; + } +} +/*-----------------------------------------------------------*/ + +signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed portCHAR cOutChar, portTickType xBlockTime ) +{ + /* Place the character in the queue of characters to be transmitted. */ + if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS ) + { + return pdFAIL; + } + + /* Turn on the Tx interrupt so the ISR will remove the character from the + queue and send it. This does not need to be in a critical section as + if the interrupt has already removed the character the next interrupt + will simply turn off the Tx interrupt again. */ + vInterruptOn(); + + return pdPASS; +} +/*-----------------------------------------------------------*/ + +void vSerialClose( xComPortHandle xPort ) +{ + /* Not supported as not required by the demo application. */ +} +/*-----------------------------------------------------------*/ + +void vSerialISR( void ) +{ +unsigned portLONG ulStatus; +signed portCHAR cChar; +portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; + + /* What caused the interrupt? */ + ulStatus = BOARD_USART_BASE->US_CSR &= BOARD_USART_BASE->US_IMR; + + if( ulStatus & AT91C_US_TXRDY ) + { + /* The interrupt was caused by the THR becoming empty. Are there any + more characters to transmit? */ + if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE ) + { + /* A character was retrieved from the queue so can be sent to the + THR now. */ + BOARD_USART_BASE->US_THR = cChar; + } + else + { + /* Queue empty, nothing to send so turn off the Tx interrupt. */ + vInterruptOff(); + } + } + + if( ulStatus & AT91C_US_RXRDY ) + { + /* The interrupt was caused by a character being received. Grab the + character from the RHR and place it in the queue or received + characters. */ + cChar = BOARD_USART_BASE->US_RHR; + xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken ); + } + + /* If a task was woken by either a character being received or a character + being transmitted then we may need to switch to another task. */ + portEND_SWITCHING_ISR( xHigherPriorityTaskWoken ); +} + + + + + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo.cspy.bat b/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo.cspy.bat new file mode 100644 index 000000000..a63a3a284 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo.cspy.bat @@ -0,0 +1,33 @@ +@REM This bat file has been generated by the IAR Embeddded Workbench +@REM C-SPY interactive debugger,as an aid to preparing a command +@REM line for running the cspybat command line utility with the +@REM appropriate settings. +@REM +@REM After making some adjustments to this file, you can launch cspybat +@REM by typing the name of this file followed by the name of the debug +@REM file (usually an ubrof file). Note that this file is generated +@REM every time a new debug session is initialized, so you may want to +@REM move or rename the file before making changes. +@REM +@REM Note: some command line arguments cannot be properly generated +@REM by this process. Specifically, the plugin which is responsible +@REM for the Terminal I/O window (and other C runtime functionality) +@REM comes in a special version for cspybat, and the name of that +@REM plugin dll is not known when generating this file. It resides in +@REM the $TOOLKIT_DIR$\bin folder and is usually called XXXbat.dll or +@REM XXXlibsupportbat.dll, where XXX is the name of the corresponding +@REM tool chain. Replace the '' parameter +@REM below with the appropriate file name. Other plugins loaded by +@REM C-SPY are usually not needed by, or will not work in, cspybat +@REM but they are listed at the end of this file for reference. + + +"C:\devtools\IAR Systems\Embedded Workbench 5.4\common\bin\cspybat" "C:\devtools\IAR Systems\Embedded Workbench 5.4\arm\bin\armproc.dll" "C:\devtools\IAR Systems\Embedded Workbench 5.4\arm\bin\armjlink.dll" %1 --plugin "C:\devtools\IAR Systems\Embedded Workbench 5.4\arm\bin\" --macro "C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\system\at91sam3u-ek-flash.mac" --backend -B "--endian=little" "--cpu=Cortex-M3" "--fpu=None" "-p" "C:\devtools\IAR Systems\Embedded Workbench 5.4\arm\CONFIG\debugger\Atmel\ioAT91SAM3U4.ddf" "--drv_verify_download" "--semihosting" "--device=AT91SAM3U4" "-d" "jlink" "--drv_communication=USB0" "--jlink_speed=auto" "--jlink_initial_speed=32" "--jlink_reset_strategy=0,0" "--jlink_interface=SWD" + + +@REM Loaded plugins: +@REM C:\devtools\IAR Systems\Embedded Workbench 5.4\arm\bin\armlibsupport.dll +@REM C:\devtools\IAR Systems\Embedded Workbench 5.4\common\plugins\CodeCoverage\CodeCoverage.dll +@REM C:\devtools\IAR Systems\Embedded Workbench 5.4\common\plugins\Profiling\Profiling.dll +@REM C:\devtools\IAR Systems\Embedded Workbench 5.4\common\plugins\stack\stack.dll +@REM C:\devtools\IAR Systems\Embedded Workbench 5.4\common\plugins\SymList\SymList.dll diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo.dbgdt b/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo.dbgdt new file mode 100644 index 000000000..357584ca3 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo.dbgdt @@ -0,0 +1,68 @@ + + + + + + + + + 300201622 + + 20 + 1216 + 324 + 81 + 300Debug-Log + + + + + + + 263272727 + + + + + + + + 200 + + + + 100 + 300200100100100100100100100150300200100100100100100100200125150100100200300Debug-Log + + + + + + + TabID-16062-16922 + Workspace + Workspace + + + RTOSDemoRTOSDemo/Output + + + + 0TabID-27988-1208Debug LogDebug-Log0 + + + + + + TextEditorC:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\main.c014866476647TextEditorC:\E\Dev\FreeRTOS\WorkingCopy3\Source\portable\IAR\ARM_CM3\port.c01556219621910100000010000001 + + + + + + + iaridepm.enu1debuggergui.enu1-2-2742337-2-2167200119286203252242143756098-2-21981402-2-214042001002857203252142857203252 + + + + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo.dni b/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo.dni new file mode 100644 index 000000000..959ff6ced --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo.dni @@ -0,0 +1,87 @@ +[DebugChecksum] +Checksum=1342314454 +[DisAssemblyWindow] +NumStates=_ 1 +State 1=_ 1 +[InstructionProfiling] +Enabled=_ 0 +[CodeCoverage] +Enabled=_ 0 +[Profiling] +Enabled=0 +[StackPlugin] +Enabled=0 +OverflowWarningsEnabled=1 +WarningThreshold=90 +SpWarningsEnabled=0 +WarnHow=0 +UseTrigger=1 +TriggerName=main +LimitSize=0 +ByteLimit=50 +[Interrupts] +Enabled=1 +[MemoryMap] +Enabled=0 +Base=0 +UseAuto=0 +TypeViolation=1 +UnspecRange=1 +ActionState=1 +[TraceHelper] +Enabled=0 +ShowSource=1 +[JLinkDriver] +SWOInfo_CpuClock=0x044AA200 +SWOInfo_SWOClockAutoDetect=0 +SWOInfo_JtagSpeed=0x001E8480 +SWOInfo_SWOPrescaler=0x00000024 +SWOInfo_SWOClockWanted=0x001E8480 +SWOInfo_HWTraceEnabled=0 +SWOInfo_TimestampsEnabled=0 +SWOInfo_TimestampsPrescalerIndex=0x00000000 +SWOInfo_TimestampsPrescalerData=0x00000000 +SWOInfo_PCSamplingEnabled=0 +SWOInfo_PCSamplingCYCTAP=0x00000001 +SWOInfo_PCSamplingPOSTCNT=0x0000000F +SWOInfo_DataLogMode=0x00000000 +SWOInfo_CPIEnabled=0 +SWOInfo_EXCEnabled=0 +SWOInfo_SLEEPEnabled=0 +SWOInfo_LSUEnabled=0 +SWOInfo_FOLDEnabled=0 +SWOInfo_EXCTRCEnabled=0 +SWOInfo_ITMPortsEnabled=0x00000001 +SWOInfo_ITMPortsTermIO=0x00000001 +SWOInfo_ITMPortsLogFile=0x00000000 +SWOInfo_ITMLogFile=$PROJ_DIR$\ITM.log +[DataLog] +LogEnabled=0 +SumEnabled=0 +ShowTimeLog=1 +ShowTimeSum=1 +[InterruptLog] +LogEnabled=0 +SumEnabled=0 +GraphEnabled=0 +ShowTimeLog=1 +ShowTimeSum=1 +SumSortOrder=0 +[TraceHelperExtra] +Enabled=0 +ShowSource=1 +[DriverProfiling] +Enabled=0 +Source=4 +Graph=0 +[Disassemble mode] +mode=0 +[Breakpoints] +Count=0 +[Log file] +LoggingEnabled=_ 0 +LogFile=_ "" +Category=_ 0 +[TermIOLog] +LoggingEnabled=_ 0 +LogFile=_ "" diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo.wsdt b/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo.wsdt new file mode 100644 index 000000000..9e4e0b253 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo.wsdt @@ -0,0 +1,49 @@ + + + + + + RTOSDemo/Debug + + + + + + + + + 202272727 + + 2012163248120162258082994 + + + + + + TabID-16570-17725 + Workspace + Workspace + + + RTOSDemoRTOSDemo/Atmel_and_system + + + + 0TabID-13247-26794BuildBuildTabID-4179-11901Debug LogDebug-LogTabID-30005-19605Find in FilesFind-in-FilesTabID-6552-24144BreakpointsBreakpoints1 + + + + + + TextEditorC:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_AT91SAM3U256_IAR\main.c0466647664700100000010000001 + + + + + + + iaridepm.enu1-2-2671276-2-2200200142857203252198571683943-2-22691402-2-214042711002857275407142857203252 + + + + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo_Debug.jlink b/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo_Debug.jlink new file mode 100644 index 000000000..e97aaa4ea --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo_Debug.jlink @@ -0,0 +1,12 @@ +[FLASH] +SkipProgOnCRCMatch = 1 +VerifyDownload = 1 +AllowCaching = 1 +EnableFlashDL = 2 +Override = 0 +Device="ADUC7020X62" +[BREAKPOINTS] +ShowInfoWin = 1 +EnableFlashBP = 2 +[CPU] +AllowSimulation = 1 diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo_Release.jlink b/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo_Release.jlink new file mode 100644 index 000000000..e97aaa4ea --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/settings/RTOSDemo_Release.jlink @@ -0,0 +1,12 @@ +[FLASH] +SkipProgOnCRCMatch = 1 +VerifyDownload = 1 +AllowCaching = 1 +EnableFlashDL = 2 +Override = 0 +Device="ADUC7020X62" +[BREAKPOINTS] +ShowInfoWin = 1 +EnableFlashBP = 2 +[CPU] +AllowSimulation = 1 diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/AT91SAM3U4.h b/Demo/CORTEX_AT91SAM3U256_IAR/system/AT91SAM3U4.h new file mode 100644 index 000000000..a7cb9a6a5 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/AT91SAM3U4.h @@ -0,0 +1,6517 @@ +// ---------------------------------------------------------------------------- +// ATMEL Microcontroller Software Support - ROUSSET - +// ---------------------------------------------------------------------------- +// Copyright (c) 2008, Atmel Corporation +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the disclaimer below. +// +// Atmel's name may not be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE +// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// ---------------------------------------------------------------------------- +// File Name : AT91SAM3U4.h +// Object : AT91SAM3U4 definitions +// Generated : AT91 SW Application Group 03/09/2009 (11:49:34) +// +// CVS Reference : /AT91SAM3U4.pl/1.32/Mon Feb 9 14:20:58 2009// +// CVS Reference : /SYS_SAM3U4.pl/1.4/Fri Oct 17 13:27:57 2008// +// CVS Reference : /HMATRIX2_SAM3U4.pl/1.3/Mon Mar 2 10:12:07 2009// +// CVS Reference : /PMC_SAM3U4.pl/1.7/Fri Oct 17 13:27:54 2008// +// CVS Reference : /EBI_SAM9260.pl/1.1/Fri Sep 30 12:12:14 2005// +// CVS Reference : /EFC2_SAM3U4.pl/1.3/Mon Mar 2 10:12:06 2009// +// CVS Reference : /HSDRAMC1_6100A.pl/1.2/Mon Aug 9 10:52:25 2004// +// CVS Reference : /HSMC4_xxxx.pl/1.9/Fri Oct 17 13:27:56 2008// +// CVS Reference : /HECC_6143A.pl/1.1/Wed Feb 9 17:16:57 2005// +// CVS Reference : /CORTEX_M3_NVIC.pl/1.7/Tue Jan 27 16:16:24 2009// +// CVS Reference : /CORTEX_M3_MPU.pl/1.3/Fri Oct 17 13:27:48 2008// +// CVS Reference : /CORTEX_M3.pl/1.1/Mon Sep 15 15:22:06 2008// +// CVS Reference : /PDC_6074C.pl/1.2/Thu Feb 3 09:02:11 2005// +// CVS Reference : /DBGU_SAM3U4.pl/1.2/Fri Oct 17 13:27:49 2008// +// CVS Reference : /PIO3_xxxx.pl/1.6/Mon Mar 9 10:43:37 2009// +// CVS Reference : /RSTC_6098A.pl/1.4/Fri Oct 17 13:27:55 2008// +// CVS Reference : /SHDWC_6122A.pl/1.3/Wed Oct 6 14:16:58 2004// +// CVS Reference : /SUPC_SAM3U4.pl/1.2/Thu Jun 5 15:27:27 2008// +// CVS Reference : /RTTC_6081A.pl/1.2/Thu Nov 4 13:57:22 2004// +// CVS Reference : /PITC_6079A.pl/1.2/Thu Nov 4 13:56:22 2004// +// CVS Reference : /WDTC_6080A.pl/1.3/Thu Nov 4 13:58:52 2004// +// CVS Reference : /TC_6082A.pl/1.8/Fri Oct 17 13:27:58 2008// +// CVS Reference : /MCI_6101F.pl/1.3/Fri Jan 23 09:15:32 2009// +// CVS Reference : /TWI_6061B.pl/1.3/Fri Oct 17 13:27:59 2008// +// CVS Reference : /US_6089J.pl/1.3/Fri Oct 17 13:27:59 2008// +// CVS Reference : /SSC_6078B.pl/1.3/Fri Oct 17 13:27:57 2008// +// CVS Reference : /SPI2.pl/1.4/Mon Mar 9 08:56:28 2009// +// CVS Reference : /PWM_6343B_V400.pl/1.3/Fri Oct 17 13:27:54 2008// +// CVS Reference : /HDMA_SAM3U4.pl/1.3/Fri Oct 17 13:27:51 2008// +// CVS Reference : /UDPHS_SAM9_7ept6dma4iso.pl/1.4/Tue Jun 24 13:05:14 2008// +// CVS Reference : /ADC_SAM3UE.pl/1.4/Fri Feb 20 12:19:18 2009// +// CVS Reference : /RTC_1245D.pl/1.3/Fri Sep 17 14:01:31 2004// +// ---------------------------------------------------------------------------- + +#ifndef AT91SAM3U4_H +#define AT91SAM3U4_H + +#ifndef __ASSEMBLY__ +typedef volatile unsigned int AT91_REG;// Hardware register definition +#define AT91_CAST(a) (a) +#else +#define AT91_CAST(a) +#endif + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR System Peripherals +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_SYS { + AT91_REG HSMC4_CFG; // Configuration Register + AT91_REG HSMC4_CTRL; // Control Register + AT91_REG HSMC4_SR; // Status Register + AT91_REG HSMC4_IER; // Interrupt Enable Register + AT91_REG HSMC4_IDR; // Interrupt Disable Register + AT91_REG HSMC4_IMR; // Interrupt Mask Register + AT91_REG HSMC4_ADDR; // Address Cycle Zero Register + AT91_REG HSMC4_BANK; // Bank Register + AT91_REG HSMC4_ECCCR; // ECC reset register + AT91_REG HSMC4_ECCCMD; // ECC Page size register + AT91_REG HSMC4_ECCSR1; // ECC Status register 1 + AT91_REG HSMC4_ECCPR0; // ECC Parity register 0 + AT91_REG HSMC4_ECCPR1; // ECC Parity register 1 + AT91_REG HSMC4_ECCSR2; // ECC Status register 2 + AT91_REG HSMC4_ECCPR2; // ECC Parity register 2 + AT91_REG HSMC4_ECCPR3; // ECC Parity register 3 + AT91_REG HSMC4_ECCPR4; // ECC Parity register 4 + AT91_REG HSMC4_ECCPR5; // ECC Parity register 5 + AT91_REG HSMC4_ECCPR6; // ECC Parity register 6 + AT91_REG HSMC4_ECCPR7; // ECC Parity register 7 + AT91_REG HSMC4_ECCPR8; // ECC Parity register 8 + AT91_REG HSMC4_ECCPR9; // ECC Parity register 9 + AT91_REG HSMC4_ECCPR10; // ECC Parity register 10 + AT91_REG HSMC4_ECCPR11; // ECC Parity register 11 + AT91_REG HSMC4_ECCPR12; // ECC Parity register 12 + AT91_REG HSMC4_ECCPR13; // ECC Parity register 13 + AT91_REG HSMC4_ECCPR14; // ECC Parity register 14 + AT91_REG HSMC4_Eccpr15; // ECC Parity register 15 + AT91_REG Reserved0[40]; // + AT91_REG HSMC4_OCMS; // OCMS MODE register + AT91_REG HSMC4_KEY1; // KEY1 Register + AT91_REG HSMC4_KEY2; // KEY2 Register + AT91_REG Reserved1[50]; // + AT91_REG HSMC4_WPCR; // Write Protection Control register + AT91_REG HSMC4_WPSR; // Write Protection Status Register + AT91_REG HSMC4_ADDRSIZE; // Write Protection Status Register + AT91_REG HSMC4_IPNAME1; // Write Protection Status Register + AT91_REG HSMC4_IPNAME2; // Write Protection Status Register + AT91_REG HSMC4_FEATURES; // Write Protection Status Register + AT91_REG HSMC4_VER; // HSMC4 Version Register + AT91_REG HMATRIX_MCFG0; // Master Configuration Register 0 : ARM I and D + AT91_REG HMATRIX_MCFG1; // Master Configuration Register 1 : ARM S + AT91_REG HMATRIX_MCFG2; // Master Configuration Register 2 + AT91_REG HMATRIX_MCFG3; // Master Configuration Register 3 + AT91_REG HMATRIX_MCFG4; // Master Configuration Register 4 + AT91_REG HMATRIX_MCFG5; // Master Configuration Register 5 + AT91_REG HMATRIX_MCFG6; // Master Configuration Register 6 + AT91_REG HMATRIX_MCFG7; // Master Configuration Register 7 + AT91_REG Reserved2[8]; // + AT91_REG HMATRIX_SCFG0; // Slave Configuration Register 0 + AT91_REG HMATRIX_SCFG1; // Slave Configuration Register 1 + AT91_REG HMATRIX_SCFG2; // Slave Configuration Register 2 + AT91_REG HMATRIX_SCFG3; // Slave Configuration Register 3 + AT91_REG HMATRIX_SCFG4; // Slave Configuration Register 4 + AT91_REG HMATRIX_SCFG5; // Slave Configuration Register 5 + AT91_REG HMATRIX_SCFG6; // Slave Configuration Register 6 + AT91_REG HMATRIX_SCFG7; // Slave Configuration Register 5 + AT91_REG HMATRIX_SCFG8; // Slave Configuration Register 8 + AT91_REG Reserved3[43]; // + AT91_REG HMATRIX_SFR0 ; // Special Function Register 0 + AT91_REG HMATRIX_SFR1 ; // Special Function Register 1 + AT91_REG HMATRIX_SFR2 ; // Special Function Register 2 + AT91_REG HMATRIX_SFR3 ; // Special Function Register 3 + AT91_REG HMATRIX_SFR4 ; // Special Function Register 4 + AT91_REG HMATRIX_SFR5 ; // Special Function Register 5 + AT91_REG HMATRIX_SFR6 ; // Special Function Register 6 + AT91_REG HMATRIX_SFR7 ; // Special Function Register 7 + AT91_REG HMATRIX_SFR8 ; // Special Function Register 8 + AT91_REG HMATRIX_SFR9 ; // Special Function Register 9 + AT91_REG HMATRIX_SFR10; // Special Function Register 10 + AT91_REG HMATRIX_SFR11; // Special Function Register 11 + AT91_REG HMATRIX_SFR12; // Special Function Register 12 + AT91_REG HMATRIX_SFR13; // Special Function Register 13 + AT91_REG HMATRIX_SFR14; // Special Function Register 14 + AT91_REG HMATRIX_SFR15; // Special Function Register 15 + AT91_REG Reserved4[39]; // + AT91_REG HMATRIX_ADDRSIZE; // HMATRIX2 ADDRSIZE REGISTER + AT91_REG HMATRIX_IPNAME1; // HMATRIX2 IPNAME1 REGISTER + AT91_REG HMATRIX_IPNAME2; // HMATRIX2 IPNAME2 REGISTER + AT91_REG HMATRIX_FEATURES; // HMATRIX2 FEATURES REGISTER + AT91_REG HMATRIX_VER; // HMATRIX2 VERSION REGISTER + AT91_REG PMC_SCER; // System Clock Enable Register + AT91_REG PMC_SCDR; // System Clock Disable Register + AT91_REG PMC_SCSR; // System Clock Status Register + AT91_REG Reserved5[1]; // + AT91_REG PMC_PCER; // Peripheral Clock Enable Register + AT91_REG PMC_PCDR; // Peripheral Clock Disable Register + AT91_REG PMC_PCSR; // Peripheral Clock Status Register + AT91_REG PMC_UCKR; // UTMI Clock Configuration Register + AT91_REG PMC_MOR; // Main Oscillator Register + AT91_REG PMC_MCFR; // Main Clock Frequency Register + AT91_REG PMC_PLLAR; // PLL Register + AT91_REG Reserved6[1]; // + AT91_REG PMC_MCKR; // Master Clock Register + AT91_REG Reserved7[3]; // + AT91_REG PMC_PCKR[8]; // Programmable Clock Register + AT91_REG PMC_IER; // Interrupt Enable Register + AT91_REG PMC_IDR; // Interrupt Disable Register + AT91_REG PMC_SR; // Status Register + AT91_REG PMC_IMR; // Interrupt Mask Register + AT91_REG PMC_FSMR; // Fast Startup Mode Register + AT91_REG PMC_FSPR; // Fast Startup Polarity Register + AT91_REG PMC_FOCR; // Fault Output Clear Register + AT91_REG Reserved8[28]; // + AT91_REG PMC_ADDRSIZE; // PMC ADDRSIZE REGISTER + AT91_REG PMC_IPNAME1; // PMC IPNAME1 REGISTER + AT91_REG PMC_IPNAME2; // PMC IPNAME2 REGISTER + AT91_REG PMC_FEATURES; // PMC FEATURES REGISTER + AT91_REG PMC_VER; // APMC VERSION REGISTER + AT91_REG Reserved9[64]; // + AT91_REG DBGU_CR; // Control Register + AT91_REG DBGU_MR; // Mode Register + AT91_REG DBGU_IER; // Interrupt Enable Register + AT91_REG DBGU_IDR; // Interrupt Disable Register + AT91_REG DBGU_IMR; // Interrupt Mask Register + AT91_REG DBGU_CSR; // Channel Status Register + AT91_REG DBGU_RHR; // Receiver Holding Register + AT91_REG DBGU_THR; // Transmitter Holding Register + AT91_REG DBGU_BRGR; // Baud Rate Generator Register + AT91_REG Reserved10[9]; // + AT91_REG DBGU_FNTR; // Force NTRST Register + AT91_REG Reserved11[40]; // + AT91_REG DBGU_ADDRSIZE; // DBGU ADDRSIZE REGISTER + AT91_REG DBGU_IPNAME1; // DBGU IPNAME1 REGISTER + AT91_REG DBGU_IPNAME2; // DBGU IPNAME2 REGISTER + AT91_REG DBGU_FEATURES; // DBGU FEATURES REGISTER + AT91_REG DBGU_VER; // DBGU VERSION REGISTER + AT91_REG DBGU_RPR; // Receive Pointer Register + AT91_REG DBGU_RCR; // Receive Counter Register + AT91_REG DBGU_TPR; // Transmit Pointer Register + AT91_REG DBGU_TCR; // Transmit Counter Register + AT91_REG DBGU_RNPR; // Receive Next Pointer Register + AT91_REG DBGU_RNCR; // Receive Next Counter Register + AT91_REG DBGU_TNPR; // Transmit Next Pointer Register + AT91_REG DBGU_TNCR; // Transmit Next Counter Register + AT91_REG DBGU_PTCR; // PDC Transfer Control Register + AT91_REG DBGU_PTSR; // PDC Transfer Status Register + AT91_REG Reserved12[6]; // + AT91_REG DBGU_CIDR; // Chip ID Register + AT91_REG DBGU_EXID; // Chip ID Extension Register + AT91_REG Reserved13[46]; // + AT91_REG EFC0_FMR; // EFC Flash Mode Register + AT91_REG EFC0_FCR; // EFC Flash Command Register + AT91_REG EFC0_FSR; // EFC Flash Status Register + AT91_REG EFC0_FRR; // EFC Flash Result Register + AT91_REG Reserved14[1]; // + AT91_REG EFC0_FVR; // EFC Flash Version Register + AT91_REG Reserved15[122]; // + AT91_REG EFC1_FMR; // EFC Flash Mode Register + AT91_REG EFC1_FCR; // EFC Flash Command Register + AT91_REG EFC1_FSR; // EFC Flash Status Register + AT91_REG EFC1_FRR; // EFC Flash Result Register + AT91_REG Reserved16[1]; // + AT91_REG EFC1_FVR; // EFC Flash Version Register + AT91_REG Reserved17[122]; // + AT91_REG PIOA_PER; // PIO Enable Register + AT91_REG PIOA_PDR; // PIO Disable Register + AT91_REG PIOA_PSR; // PIO Status Register + AT91_REG Reserved18[1]; // + AT91_REG PIOA_OER; // Output Enable Register + AT91_REG PIOA_ODR; // Output Disable Registerr + AT91_REG PIOA_OSR; // Output Status Register + AT91_REG Reserved19[1]; // + AT91_REG PIOA_IFER; // Input Filter Enable Register + AT91_REG PIOA_IFDR; // Input Filter Disable Register + AT91_REG PIOA_IFSR; // Input Filter Status Register + AT91_REG Reserved20[1]; // + AT91_REG PIOA_SODR; // Set Output Data Register + AT91_REG PIOA_CODR; // Clear Output Data Register + AT91_REG PIOA_ODSR; // Output Data Status Register + AT91_REG PIOA_PDSR; // Pin Data Status Register + AT91_REG PIOA_IER; // Interrupt Enable Register + AT91_REG PIOA_IDR; // Interrupt Disable Register + AT91_REG PIOA_IMR; // Interrupt Mask Register + AT91_REG PIOA_ISR; // Interrupt Status Register + AT91_REG PIOA_MDER; // Multi-driver Enable Register + AT91_REG PIOA_MDDR; // Multi-driver Disable Register + AT91_REG PIOA_MDSR; // Multi-driver Status Register + AT91_REG Reserved21[1]; // + AT91_REG PIOA_PPUDR; // Pull-up Disable Register + AT91_REG PIOA_PPUER; // Pull-up Enable Register + AT91_REG PIOA_PPUSR; // Pull-up Status Register + AT91_REG Reserved22[1]; // + AT91_REG PIOA_ABSR; // Peripheral AB Select Register + AT91_REG Reserved23[3]; // + AT91_REG PIOA_SCIFSR; // System Clock Glitch Input Filter Select Register + AT91_REG PIOA_DIFSR; // Debouncing Input Filter Select Register + AT91_REG PIOA_IFDGSR; // Glitch or Debouncing Input Filter Clock Selection Status Register + AT91_REG PIOA_SCDR; // Slow Clock Divider Debouncing Register + AT91_REG Reserved24[4]; // + AT91_REG PIOA_OWER; // Output Write Enable Register + AT91_REG PIOA_OWDR; // Output Write Disable Register + AT91_REG PIOA_OWSR; // Output Write Status Register + AT91_REG Reserved25[1]; // + AT91_REG PIOA_AIMER; // Additional Interrupt Modes Enable Register + AT91_REG PIOA_AIMDR; // Additional Interrupt Modes Disables Register + AT91_REG PIOA_AIMMR; // Additional Interrupt Modes Mask Register + AT91_REG Reserved26[1]; // + AT91_REG PIOA_ESR; // Edge Select Register + AT91_REG PIOA_LSR; // Level Select Register + AT91_REG PIOA_ELSR; // Edge/Level Status Register + AT91_REG Reserved27[1]; // + AT91_REG PIOA_FELLSR; // Falling Edge/Low Level Select Register + AT91_REG PIOA_REHLSR; // Rising Edge/ High Level Select Register + AT91_REG PIOA_FRLHSR; // Fall/Rise - Low/High Status Register + AT91_REG Reserved28[1]; // + AT91_REG PIOA_LOCKSR; // Lock Status Register + AT91_REG Reserved29[6]; // + AT91_REG PIOA_VER; // PIO VERSION REGISTER + AT91_REG Reserved30[8]; // + AT91_REG PIOA_KER; // Keypad Controller Enable Register + AT91_REG PIOA_KRCR; // Keypad Controller Row Column Register + AT91_REG PIOA_KDR; // Keypad Controller Debouncing Register + AT91_REG Reserved31[1]; // + AT91_REG PIOA_KIER; // Keypad Controller Interrupt Enable Register + AT91_REG PIOA_KIDR; // Keypad Controller Interrupt Disable Register + AT91_REG PIOA_KIMR; // Keypad Controller Interrupt Mask Register + AT91_REG PIOA_KSR; // Keypad Controller Status Register + AT91_REG PIOA_KKPR; // Keypad Controller Key Press Register + AT91_REG PIOA_KKRR; // Keypad Controller Key Release Register + AT91_REG Reserved32[46]; // + AT91_REG PIOB_PER; // PIO Enable Register + AT91_REG PIOB_PDR; // PIO Disable Register + AT91_REG PIOB_PSR; // PIO Status Register + AT91_REG Reserved33[1]; // + AT91_REG PIOB_OER; // Output Enable Register + AT91_REG PIOB_ODR; // Output Disable Registerr + AT91_REG PIOB_OSR; // Output Status Register + AT91_REG Reserved34[1]; // + AT91_REG PIOB_IFER; // Input Filter Enable Register + AT91_REG PIOB_IFDR; // Input Filter Disable Register + AT91_REG PIOB_IFSR; // Input Filter Status Register + AT91_REG Reserved35[1]; // + AT91_REG PIOB_SODR; // Set Output Data Register + AT91_REG PIOB_CODR; // Clear Output Data Register + AT91_REG PIOB_ODSR; // Output Data Status Register + AT91_REG PIOB_PDSR; // Pin Data Status Register + AT91_REG PIOB_IER; // Interrupt Enable Register + AT91_REG PIOB_IDR; // Interrupt Disable Register + AT91_REG PIOB_IMR; // Interrupt Mask Register + AT91_REG PIOB_ISR; // Interrupt Status Register + AT91_REG PIOB_MDER; // Multi-driver Enable Register + AT91_REG PIOB_MDDR; // Multi-driver Disable Register + AT91_REG PIOB_MDSR; // Multi-driver Status Register + AT91_REG Reserved36[1]; // + AT91_REG PIOB_PPUDR; // Pull-up Disable Register + AT91_REG PIOB_PPUER; // Pull-up Enable Register + AT91_REG PIOB_PPUSR; // Pull-up Status Register + AT91_REG Reserved37[1]; // + AT91_REG PIOB_ABSR; // Peripheral AB Select Register + AT91_REG Reserved38[3]; // + AT91_REG PIOB_SCIFSR; // System Clock Glitch Input Filter Select Register + AT91_REG PIOB_DIFSR; // Debouncing Input Filter Select Register + AT91_REG PIOB_IFDGSR; // Glitch or Debouncing Input Filter Clock Selection Status Register + AT91_REG PIOB_SCDR; // Slow Clock Divider Debouncing Register + AT91_REG Reserved39[4]; // + AT91_REG PIOB_OWER; // Output Write Enable Register + AT91_REG PIOB_OWDR; // Output Write Disable Register + AT91_REG PIOB_OWSR; // Output Write Status Register + AT91_REG Reserved40[1]; // + AT91_REG PIOB_AIMER; // Additional Interrupt Modes Enable Register + AT91_REG PIOB_AIMDR; // Additional Interrupt Modes Disables Register + AT91_REG PIOB_AIMMR; // Additional Interrupt Modes Mask Register + AT91_REG Reserved41[1]; // + AT91_REG PIOB_ESR; // Edge Select Register + AT91_REG PIOB_LSR; // Level Select Register + AT91_REG PIOB_ELSR; // Edge/Level Status Register + AT91_REG Reserved42[1]; // + AT91_REG PIOB_FELLSR; // Falling Edge/Low Level Select Register + AT91_REG PIOB_REHLSR; // Rising Edge/ High Level Select Register + AT91_REG PIOB_FRLHSR; // Fall/Rise - Low/High Status Register + AT91_REG Reserved43[1]; // + AT91_REG PIOB_LOCKSR; // Lock Status Register + AT91_REG Reserved44[6]; // + AT91_REG PIOB_VER; // PIO VERSION REGISTER + AT91_REG Reserved45[8]; // + AT91_REG PIOB_KER; // Keypad Controller Enable Register + AT91_REG PIOB_KRCR; // Keypad Controller Row Column Register + AT91_REG PIOB_KDR; // Keypad Controller Debouncing Register + AT91_REG Reserved46[1]; // + AT91_REG PIOB_KIER; // Keypad Controller Interrupt Enable Register + AT91_REG PIOB_KIDR; // Keypad Controller Interrupt Disable Register + AT91_REG PIOB_KIMR; // Keypad Controller Interrupt Mask Register + AT91_REG PIOB_KSR; // Keypad Controller Status Register + AT91_REG PIOB_KKPR; // Keypad Controller Key Press Register + AT91_REG PIOB_KKRR; // Keypad Controller Key Release Register + AT91_REG Reserved47[46]; // + AT91_REG PIOC_PER; // PIO Enable Register + AT91_REG PIOC_PDR; // PIO Disable Register + AT91_REG PIOC_PSR; // PIO Status Register + AT91_REG Reserved48[1]; // + AT91_REG PIOC_OER; // Output Enable Register + AT91_REG PIOC_ODR; // Output Disable Registerr + AT91_REG PIOC_OSR; // Output Status Register + AT91_REG Reserved49[1]; // + AT91_REG PIOC_IFER; // Input Filter Enable Register + AT91_REG PIOC_IFDR; // Input Filter Disable Register + AT91_REG PIOC_IFSR; // Input Filter Status Register + AT91_REG Reserved50[1]; // + AT91_REG PIOC_SODR; // Set Output Data Register + AT91_REG PIOC_CODR; // Clear Output Data Register + AT91_REG PIOC_ODSR; // Output Data Status Register + AT91_REG PIOC_PDSR; // Pin Data Status Register + AT91_REG PIOC_IER; // Interrupt Enable Register + AT91_REG PIOC_IDR; // Interrupt Disable Register + AT91_REG PIOC_IMR; // Interrupt Mask Register + AT91_REG PIOC_ISR; // Interrupt Status Register + AT91_REG PIOC_MDER; // Multi-driver Enable Register + AT91_REG PIOC_MDDR; // Multi-driver Disable Register + AT91_REG PIOC_MDSR; // Multi-driver Status Register + AT91_REG Reserved51[1]; // + AT91_REG PIOC_PPUDR; // Pull-up Disable Register + AT91_REG PIOC_PPUER; // Pull-up Enable Register + AT91_REG PIOC_PPUSR; // Pull-up Status Register + AT91_REG Reserved52[1]; // + AT91_REG PIOC_ABSR; // Peripheral AB Select Register + AT91_REG Reserved53[3]; // + AT91_REG PIOC_SCIFSR; // System Clock Glitch Input Filter Select Register + AT91_REG PIOC_DIFSR; // Debouncing Input Filter Select Register + AT91_REG PIOC_IFDGSR; // Glitch or Debouncing Input Filter Clock Selection Status Register + AT91_REG PIOC_SCDR; // Slow Clock Divider Debouncing Register + AT91_REG Reserved54[4]; // + AT91_REG PIOC_OWER; // Output Write Enable Register + AT91_REG PIOC_OWDR; // Output Write Disable Register + AT91_REG PIOC_OWSR; // Output Write Status Register + AT91_REG Reserved55[1]; // + AT91_REG PIOC_AIMER; // Additional Interrupt Modes Enable Register + AT91_REG PIOC_AIMDR; // Additional Interrupt Modes Disables Register + AT91_REG PIOC_AIMMR; // Additional Interrupt Modes Mask Register + AT91_REG Reserved56[1]; // + AT91_REG PIOC_ESR; // Edge Select Register + AT91_REG PIOC_LSR; // Level Select Register + AT91_REG PIOC_ELSR; // Edge/Level Status Register + AT91_REG Reserved57[1]; // + AT91_REG PIOC_FELLSR; // Falling Edge/Low Level Select Register + AT91_REG PIOC_REHLSR; // Rising Edge/ High Level Select Register + AT91_REG PIOC_FRLHSR; // Fall/Rise - Low/High Status Register + AT91_REG Reserved58[1]; // + AT91_REG PIOC_LOCKSR; // Lock Status Register + AT91_REG Reserved59[6]; // + AT91_REG PIOC_VER; // PIO VERSION REGISTER + AT91_REG Reserved60[8]; // + AT91_REG PIOC_KER; // Keypad Controller Enable Register + AT91_REG PIOC_KRCR; // Keypad Controller Row Column Register + AT91_REG PIOC_KDR; // Keypad Controller Debouncing Register + AT91_REG Reserved61[1]; // + AT91_REG PIOC_KIER; // Keypad Controller Interrupt Enable Register + AT91_REG PIOC_KIDR; // Keypad Controller Interrupt Disable Register + AT91_REG PIOC_KIMR; // Keypad Controller Interrupt Mask Register + AT91_REG PIOC_KSR; // Keypad Controller Status Register + AT91_REG PIOC_KKPR; // Keypad Controller Key Press Register + AT91_REG PIOC_KKRR; // Keypad Controller Key Release Register + AT91_REG Reserved62[46]; // + AT91_REG RSTC_RCR; // Reset Control Register + AT91_REG RSTC_RSR; // Reset Status Register + AT91_REG RSTC_RMR; // Reset Mode Register + AT91_REG Reserved63[1]; // + AT91_REG SUPC_CR; // Control Register + AT91_REG SUPC_BOMR; // Brown Out Mode Register + AT91_REG SUPC_MR; // Mode Register + AT91_REG SUPC_WUMR; // Wake Up Mode Register + AT91_REG SUPC_WUIR; // Wake Up Inputs Register + AT91_REG SUPC_SR; // Status Register + AT91_REG SUPC_FWUTR; // Flash Wake-up Timer Register + AT91_REG Reserved64[1]; // + AT91_REG RTTC_RTMR; // Real-time Mode Register + AT91_REG RTTC_RTAR; // Real-time Alarm Register + AT91_REG RTTC_RTVR; // Real-time Value Register + AT91_REG RTTC_RTSR; // Real-time Status Register + AT91_REG Reserved65[4]; // + AT91_REG WDTC_WDCR; // Watchdog Control Register + AT91_REG WDTC_WDMR; // Watchdog Mode Register + AT91_REG WDTC_WDSR; // Watchdog Status Register + AT91_REG Reserved66[1]; // + AT91_REG RTC_CR; // Control Register + AT91_REG RTC_MR; // Mode Register + AT91_REG RTC_TIMR; // Time Register + AT91_REG RTC_CALR; // Calendar Register + AT91_REG RTC_TIMALR; // Time Alarm Register + AT91_REG RTC_CALALR; // Calendar Alarm Register + AT91_REG RTC_SR; // Status Register + AT91_REG RTC_SCCR; // Status Clear Command Register + AT91_REG RTC_IER; // Interrupt Enable Register + AT91_REG RTC_IDR; // Interrupt Disable Register + AT91_REG RTC_IMR; // Interrupt Mask Register + AT91_REG RTC_VER; // Valid Entry Register + AT91_REG SYS_GPBR[8]; // General Purpose Register + AT91_REG Reserved67[19]; // + AT91_REG RSTC_VER; // Version Register +} AT91S_SYS, *AT91PS_SYS; +#else +#define GPBR (AT91_CAST(AT91_REG *) 0x00001290) // (GPBR) General Purpose Register + +#endif +// -------- GPBR : (SYS Offset: 0x1290) GPBR General Purpose Register -------- +#define AT91C_GPBR_GPRV (0x0 << 0) // (SYS) General Purpose Register Value + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR HSMC4 Chip Select interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_HSMC4_CS { + AT91_REG HSMC4_SETUP; // Setup Register + AT91_REG HSMC4_PULSE; // Pulse Register + AT91_REG HSMC4_CYCLE; // Cycle Register + AT91_REG HSMC4_TIMINGS; // Timmings Register + AT91_REG HSMC4_MODE; // Mode Register +} AT91S_HSMC4_CS, *AT91PS_HSMC4_CS; +#else +#define HSMC4_SETUP (AT91_CAST(AT91_REG *) 0x00000000) // (HSMC4_SETUP) Setup Register +#define HSMC4_PULSE (AT91_CAST(AT91_REG *) 0x00000004) // (HSMC4_PULSE) Pulse Register +#define HSMC4_CYCLE (AT91_CAST(AT91_REG *) 0x00000008) // (HSMC4_CYCLE) Cycle Register +#define HSMC4_TIMINGS (AT91_CAST(AT91_REG *) 0x0000000C) // (HSMC4_TIMINGS) Timmings Register +#define HSMC4_MODE (AT91_CAST(AT91_REG *) 0x00000010) // (HSMC4_MODE) Mode Register + +#endif +// -------- HSMC4_SETUP : (HSMC4_CS Offset: 0x0) HSMC4 SETUP -------- +#define AT91C_HSMC4_NWE_SETUP (0x3F << 0) // (HSMC4_CS) NWE Setup length +#define AT91C_HSMC4_NCS_WR_SETUP (0x3F << 8) // (HSMC4_CS) NCS Setup length in Write access +#define AT91C_HSMC4_NRD_SETUP (0x3F << 16) // (HSMC4_CS) NRD Setup length +#define AT91C_HSMC4_NCS_RD_SETUP (0x3F << 24) // (HSMC4_CS) NCS Setup legnth in Read access +// -------- HSMC4_PULSE : (HSMC4_CS Offset: 0x4) HSMC4 PULSE -------- +#define AT91C_HSMC4_NWE_PULSE (0x3F << 0) // (HSMC4_CS) NWE Pulse Length +#define AT91C_HSMC4_NCS_WR_PULSE (0x3F << 8) // (HSMC4_CS) NCS Pulse length in WRITE access +#define AT91C_HSMC4_NRD_PULSE (0x3F << 16) // (HSMC4_CS) NRD Pulse length +#define AT91C_HSMC4_NCS_RD_PULSE (0x3F << 24) // (HSMC4_CS) NCS Pulse length in READ access +// -------- HSMC4_CYCLE : (HSMC4_CS Offset: 0x8) HSMC4 CYCLE -------- +#define AT91C_HSMC4_NWE_CYCLE (0x1FF << 0) // (HSMC4_CS) Total Write Cycle Length +#define AT91C_HSMC4_NRD_CYCLE (0x1FF << 16) // (HSMC4_CS) Total Read Cycle Length +// -------- HSMC4_TIMINGS : (HSMC4_CS Offset: 0xc) HSMC4 TIMINGS -------- +#define AT91C_HSMC4_TCLR (0xF << 0) // (HSMC4_CS) CLE to REN low delay +#define AT91C_HSMC4_TADL (0xF << 4) // (HSMC4_CS) ALE to data start +#define AT91C_HSMC4_TAR (0xF << 8) // (HSMC4_CS) ALE to REN low delay +#define AT91C_HSMC4_OCMSEN (0x1 << 12) // (HSMC4_CS) Off Chip Memory Scrambling Enable +#define AT91C_HSMC4_TRR (0xF << 16) // (HSMC4_CS) Ready to REN low delay +#define AT91C_HSMC4_TWB (0xF << 24) // (HSMC4_CS) WEN high to REN to busy +#define AT91C_HSMC4_RBNSEL (0x7 << 28) // (HSMC4_CS) Ready/Busy Line Selection +#define AT91C_HSMC4_NFSEL (0x1 << 31) // (HSMC4_CS) Nand Flash Selection +// -------- HSMC4_MODE : (HSMC4_CS Offset: 0x10) HSMC4 MODE -------- +#define AT91C_HSMC4_READ_MODE (0x1 << 0) // (HSMC4_CS) Read Mode +#define AT91C_HSMC4_WRITE_MODE (0x1 << 1) // (HSMC4_CS) Write Mode +#define AT91C_HSMC4_EXNW_MODE (0x3 << 4) // (HSMC4_CS) NWAIT Mode +#define AT91C_HSMC4_EXNW_MODE_NWAIT_DISABLE (0x0 << 4) // (HSMC4_CS) External NWAIT disabled. +#define AT91C_HSMC4_EXNW_MODE_NWAIT_ENABLE_FROZEN (0x2 << 4) // (HSMC4_CS) External NWAIT enabled in frozen mode. +#define AT91C_HSMC4_EXNW_MODE_NWAIT_ENABLE_READY (0x3 << 4) // (HSMC4_CS) External NWAIT enabled in ready mode. +#define AT91C_HSMC4_BAT (0x1 << 8) // (HSMC4_CS) Byte Access Type +#define AT91C_HSMC4_BAT_BYTE_SELECT (0x0 << 8) // (HSMC4_CS) Write controled by ncs, nbs0, nbs1, nbs2, nbs3. Read controled by ncs, nrd, nbs0, nbs1, nbs2, nbs3. +#define AT91C_HSMC4_BAT_BYTE_WRITE (0x1 << 8) // (HSMC4_CS) Write controled by ncs, nwe0, nwe1, nwe2, nwe3. Read controled by ncs and nrd. +#define AT91C_HSMC4_DBW (0x3 << 12) // (HSMC4_CS) Data Bus Width +#define AT91C_HSMC4_DBW_WIDTH_EIGTH_BITS (0x0 << 12) // (HSMC4_CS) 8 bits. +#define AT91C_HSMC4_DBW_WIDTH_SIXTEEN_BITS (0x1 << 12) // (HSMC4_CS) 16 bits. +#define AT91C_HSMC4_DBW_WIDTH_THIRTY_TWO_BITS (0x2 << 12) // (HSMC4_CS) 32 bits. +#define AT91C_HSMC4_TDF_CYCLES (0xF << 16) // (HSMC4_CS) Data Float Time. +#define AT91C_HSMC4_TDF_MODE (0x1 << 20) // (HSMC4_CS) TDF Enabled. +#define AT91C_HSMC4_PMEN (0x1 << 24) // (HSMC4_CS) Page Mode Enabled. +#define AT91C_HSMC4_PS (0x3 << 28) // (HSMC4_CS) Page Size +#define AT91C_HSMC4_PS_SIZE_FOUR_BYTES (0x0 << 28) // (HSMC4_CS) 4 bytes. +#define AT91C_HSMC4_PS_SIZE_EIGHT_BYTES (0x1 << 28) // (HSMC4_CS) 8 bytes. +#define AT91C_HSMC4_PS_SIZE_SIXTEEN_BYTES (0x2 << 28) // (HSMC4_CS) 16 bytes. +#define AT91C_HSMC4_PS_SIZE_THIRTY_TWO_BYTES (0x3 << 28) // (HSMC4_CS) 32 bytes. + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR AHB Static Memory Controller 4 Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_HSMC4 { + AT91_REG HSMC4_CFG; // Configuration Register + AT91_REG HSMC4_CTRL; // Control Register + AT91_REG HSMC4_SR; // Status Register + AT91_REG HSMC4_IER; // Interrupt Enable Register + AT91_REG HSMC4_IDR; // Interrupt Disable Register + AT91_REG HSMC4_IMR; // Interrupt Mask Register + AT91_REG HSMC4_ADDR; // Address Cycle Zero Register + AT91_REG HSMC4_BANK; // Bank Register + AT91_REG HSMC4_ECCCR; // ECC reset register + AT91_REG HSMC4_ECCCMD; // ECC Page size register + AT91_REG HSMC4_ECCSR1; // ECC Status register 1 + AT91_REG HSMC4_ECCPR0; // ECC Parity register 0 + AT91_REG HSMC4_ECCPR1; // ECC Parity register 1 + AT91_REG HSMC4_ECCSR2; // ECC Status register 2 + AT91_REG HSMC4_ECCPR2; // ECC Parity register 2 + AT91_REG HSMC4_ECCPR3; // ECC Parity register 3 + AT91_REG HSMC4_ECCPR4; // ECC Parity register 4 + AT91_REG HSMC4_ECCPR5; // ECC Parity register 5 + AT91_REG HSMC4_ECCPR6; // ECC Parity register 6 + AT91_REG HSMC4_ECCPR7; // ECC Parity register 7 + AT91_REG HSMC4_ECCPR8; // ECC Parity register 8 + AT91_REG HSMC4_ECCPR9; // ECC Parity register 9 + AT91_REG HSMC4_ECCPR10; // ECC Parity register 10 + AT91_REG HSMC4_ECCPR11; // ECC Parity register 11 + AT91_REG HSMC4_ECCPR12; // ECC Parity register 12 + AT91_REG HSMC4_ECCPR13; // ECC Parity register 13 + AT91_REG HSMC4_ECCPR14; // ECC Parity register 14 + AT91_REG HSMC4_Eccpr15; // ECC Parity register 15 + AT91_REG Reserved0[40]; // + AT91_REG HSMC4_OCMS; // OCMS MODE register + AT91_REG HSMC4_KEY1; // KEY1 Register + AT91_REG HSMC4_KEY2; // KEY2 Register + AT91_REG Reserved1[50]; // + AT91_REG HSMC4_WPCR; // Write Protection Control register + AT91_REG HSMC4_WPSR; // Write Protection Status Register + AT91_REG HSMC4_ADDRSIZE; // Write Protection Status Register + AT91_REG HSMC4_IPNAME1; // Write Protection Status Register + AT91_REG HSMC4_IPNAME2; // Write Protection Status Register + AT91_REG HSMC4_FEATURES; // Write Protection Status Register + AT91_REG HSMC4_VER; // HSMC4 Version Register + AT91_REG HSMC4_DUMMY; // This rtegister was created only ti have AHB constants +} AT91S_HSMC4, *AT91PS_HSMC4; +#else +#define HSMC4_CFG (AT91_CAST(AT91_REG *) 0x00000000) // (HSMC4_CFG) Configuration Register +#define HSMC4_CTRL (AT91_CAST(AT91_REG *) 0x00000004) // (HSMC4_CTRL) Control Register +#define HSMC4_SR (AT91_CAST(AT91_REG *) 0x00000008) // (HSMC4_SR) Status Register +#define HSMC4_IER (AT91_CAST(AT91_REG *) 0x0000000C) // (HSMC4_IER) Interrupt Enable Register +#define HSMC4_IDR (AT91_CAST(AT91_REG *) 0x00000010) // (HSMC4_IDR) Interrupt Disable Register +#define HSMC4_IMR (AT91_CAST(AT91_REG *) 0x00000014) // (HSMC4_IMR) Interrupt Mask Register +#define HSMC4_ADDR (AT91_CAST(AT91_REG *) 0x00000018) // (HSMC4_ADDR) Address Cycle Zero Register +#define HSMC4_BANK (AT91_CAST(AT91_REG *) 0x0000001C) // (HSMC4_BANK) Bank Register +#define HSMC4_ECCCR (AT91_CAST(AT91_REG *) 0x00000020) // (HSMC4_ECCCR) ECC reset register +#define HSMC4_ECCCMD (AT91_CAST(AT91_REG *) 0x00000024) // (HSMC4_ECCCMD) ECC Page size register +#define HSMC4_ECCSR1 (AT91_CAST(AT91_REG *) 0x00000028) // (HSMC4_ECCSR1) ECC Status register 1 +#define HSMC4_ECCPR0 (AT91_CAST(AT91_REG *) 0x0000002C) // (HSMC4_ECCPR0) ECC Parity register 0 +#define HSMC4_ECCPR1 (AT91_CAST(AT91_REG *) 0x00000030) // (HSMC4_ECCPR1) ECC Parity register 1 +#define HSMC4_ECCSR2 (AT91_CAST(AT91_REG *) 0x00000034) // (HSMC4_ECCSR2) ECC Status register 2 +#define HSMC4_ECCPR2 (AT91_CAST(AT91_REG *) 0x00000038) // (HSMC4_ECCPR2) ECC Parity register 2 +#define HSMC4_ECCPR3 (AT91_CAST(AT91_REG *) 0x0000003C) // (HSMC4_ECCPR3) ECC Parity register 3 +#define HSMC4_ECCPR4 (AT91_CAST(AT91_REG *) 0x00000040) // (HSMC4_ECCPR4) ECC Parity register 4 +#define HSMC4_ECCPR5 (AT91_CAST(AT91_REG *) 0x00000044) // (HSMC4_ECCPR5) ECC Parity register 5 +#define HSMC4_ECCPR6 (AT91_CAST(AT91_REG *) 0x00000048) // (HSMC4_ECCPR6) ECC Parity register 6 +#define HSMC4_ECCPR7 (AT91_CAST(AT91_REG *) 0x0000004C) // (HSMC4_ECCPR7) ECC Parity register 7 +#define HSMC4_ECCPR8 (AT91_CAST(AT91_REG *) 0x00000050) // (HSMC4_ECCPR8) ECC Parity register 8 +#define HSMC4_ECCPR9 (AT91_CAST(AT91_REG *) 0x00000054) // (HSMC4_ECCPR9) ECC Parity register 9 +#define HSMC4_ECCPR10 (AT91_CAST(AT91_REG *) 0x00000058) // (HSMC4_ECCPR10) ECC Parity register 10 +#define HSMC4_ECCPR11 (AT91_CAST(AT91_REG *) 0x0000005C) // (HSMC4_ECCPR11) ECC Parity register 11 +#define HSMC4_ECCPR12 (AT91_CAST(AT91_REG *) 0x00000060) // (HSMC4_ECCPR12) ECC Parity register 12 +#define HSMC4_ECCPR13 (AT91_CAST(AT91_REG *) 0x00000064) // (HSMC4_ECCPR13) ECC Parity register 13 +#define HSMC4_ECCPR14 (AT91_CAST(AT91_REG *) 0x00000068) // (HSMC4_ECCPR14) ECC Parity register 14 +#define Hsmc4_Eccpr15 (AT91_CAST(AT91_REG *) 0x0000006C) // (Hsmc4_Eccpr15) ECC Parity register 15 +#define HSMC4_OCMS (AT91_CAST(AT91_REG *) 0x00000110) // (HSMC4_OCMS) OCMS MODE register +#define HSMC4_KEY1 (AT91_CAST(AT91_REG *) 0x00000114) // (HSMC4_KEY1) KEY1 Register +#define HSMC4_KEY2 (AT91_CAST(AT91_REG *) 0x00000118) // (HSMC4_KEY2) KEY2 Register +#define HSMC4_WPCR (AT91_CAST(AT91_REG *) 0x000001E4) // (HSMC4_WPCR) Write Protection Control register +#define HSMC4_WPSR (AT91_CAST(AT91_REG *) 0x000001E8) // (HSMC4_WPSR) Write Protection Status Register +#define HSMC4_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000001EC) // (HSMC4_ADDRSIZE) Write Protection Status Register +#define HSMC4_IPNAME1 (AT91_CAST(AT91_REG *) 0x000001F0) // (HSMC4_IPNAME1) Write Protection Status Register +#define HSMC4_IPNAME2 (AT91_CAST(AT91_REG *) 0x000001F4) // (HSMC4_IPNAME2) Write Protection Status Register +#define HSMC4_FEATURES (AT91_CAST(AT91_REG *) 0x000001F8) // (HSMC4_FEATURES) Write Protection Status Register +#define HSMC4_VER (AT91_CAST(AT91_REG *) 0x000001FC) // (HSMC4_VER) HSMC4 Version Register +#define HSMC4_DUMMY (AT91_CAST(AT91_REG *) 0x00000200) // (HSMC4_DUMMY) This rtegister was created only ti have AHB constants + +#endif +// -------- HSMC4_CFG : (HSMC4 Offset: 0x0) Configuration Register -------- +#define AT91C_HSMC4_PAGESIZE (0x3 << 0) // (HSMC4) PAGESIZE field description +#define AT91C_HSMC4_PAGESIZE_528_Bytes (0x0) // (HSMC4) 512 bytes plus 16 bytes page size +#define AT91C_HSMC4_PAGESIZE_1056_Bytes (0x1) // (HSMC4) 1024 bytes plus 32 bytes page size +#define AT91C_HSMC4_PAGESIZE_2112_Bytes (0x2) // (HSMC4) 2048 bytes plus 64 bytes page size +#define AT91C_HSMC4_PAGESIZE_4224_Bytes (0x3) // (HSMC4) 4096 bytes plus 128 bytes page size +#define AT91C_HSMC4_WSPARE (0x1 << 8) // (HSMC4) Spare area access in Write Mode +#define AT91C_HSMC4_RSPARE (0x1 << 9) // (HSMC4) Spare area access in Read Mode +#define AT91C_HSMC4_EDGECTRL (0x1 << 12) // (HSMC4) Rising/Falling Edge Detection Control +#define AT91C_HSMC4_RBEDGE (0x1 << 13) // (HSMC4) Ready/Busy Signal edge Detection +#define AT91C_HSMC4_DTOCYC (0xF << 16) // (HSMC4) Data Timeout Cycle Number +#define AT91C_HSMC4_DTOMUL (0x7 << 20) // (HSMC4) Data Timeout Multiplier +#define AT91C_HSMC4_DTOMUL_1 (0x0 << 20) // (HSMC4) DTOCYC x 1 +#define AT91C_HSMC4_DTOMUL_16 (0x1 << 20) // (HSMC4) DTOCYC x 16 +#define AT91C_HSMC4_DTOMUL_128 (0x2 << 20) // (HSMC4) DTOCYC x 128 +#define AT91C_HSMC4_DTOMUL_256 (0x3 << 20) // (HSMC4) DTOCYC x 256 +#define AT91C_HSMC4_DTOMUL_1024 (0x4 << 20) // (HSMC4) DTOCYC x 1024 +#define AT91C_HSMC4_DTOMUL_4096 (0x5 << 20) // (HSMC4) DTOCYC x 4096 +#define AT91C_HSMC4_DTOMUL_65536 (0x6 << 20) // (HSMC4) DTOCYC x 65536 +#define AT91C_HSMC4_DTOMUL_1048576 (0x7 << 20) // (HSMC4) DTOCYC x 1048576 +// -------- HSMC4_CTRL : (HSMC4 Offset: 0x4) Control Register -------- +#define AT91C_HSMC4_NFCEN (0x1 << 0) // (HSMC4) Nand Flash Controller Host Enable +#define AT91C_HSMC4_NFCDIS (0x1 << 1) // (HSMC4) Nand Flash Controller Host Disable +#define AT91C_HSMC4_HOSTEN (0x1 << 8) // (HSMC4) If set to one, the Host controller is activated and perform a data transfer phase. +#define AT91C_HSMC4_HOSTWR (0x1 << 11) // (HSMC4) If this field is set to one, the host transfers data from the internal SRAM to the Memory Device. +#define AT91C_HSMC4_HOSTCSID (0x7 << 12) // (HSMC4) Host Controller Chip select Id +#define AT91C_HSMC4_HOSTCSID_0 (0x0 << 12) // (HSMC4) CS0 +#define AT91C_HSMC4_HOSTCSID_1 (0x1 << 12) // (HSMC4) CS1 +#define AT91C_HSMC4_HOSTCSID_2 (0x2 << 12) // (HSMC4) CS2 +#define AT91C_HSMC4_HOSTCSID_3 (0x3 << 12) // (HSMC4) CS3 +#define AT91C_HSMC4_HOSTCSID_4 (0x4 << 12) // (HSMC4) CS4 +#define AT91C_HSMC4_HOSTCSID_5 (0x5 << 12) // (HSMC4) CS5 +#define AT91C_HSMC4_HOSTCSID_6 (0x6 << 12) // (HSMC4) CS6 +#define AT91C_HSMC4_HOSTCSID_7 (0x7 << 12) // (HSMC4) CS7 +#define AT91C_HSMC4_VALID (0x1 << 15) // (HSMC4) When set to 1, a write operation modifies both HOSTCSID and HOSTWR fields. +// -------- HSMC4_SR : (HSMC4 Offset: 0x8) HSMC4 Status Register -------- +#define AT91C_HSMC4_NFCSTS (0x1 << 0) // (HSMC4) Nand Flash Controller status +#define AT91C_HSMC4_RBRISE (0x1 << 4) // (HSMC4) Selected Ready Busy Rising Edge Detected flag +#define AT91C_HSMC4_RBFALL (0x1 << 5) // (HSMC4) Selected Ready Busy Falling Edge Detected flag +#define AT91C_HSMC4_HOSTBUSY (0x1 << 8) // (HSMC4) Host Busy +#define AT91C_HSMC4_HOSTW (0x1 << 11) // (HSMC4) Host Write/Read Operation +#define AT91C_HSMC4_HOSTCS (0x7 << 12) // (HSMC4) Host Controller Chip select Id +#define AT91C_HSMC4_HOSTCS_0 (0x0 << 12) // (HSMC4) CS0 +#define AT91C_HSMC4_HOSTCS_1 (0x1 << 12) // (HSMC4) CS1 +#define AT91C_HSMC4_HOSTCS_2 (0x2 << 12) // (HSMC4) CS2 +#define AT91C_HSMC4_HOSTCS_3 (0x3 << 12) // (HSMC4) CS3 +#define AT91C_HSMC4_HOSTCS_4 (0x4 << 12) // (HSMC4) CS4 +#define AT91C_HSMC4_HOSTCS_5 (0x5 << 12) // (HSMC4) CS5 +#define AT91C_HSMC4_HOSTCS_6 (0x6 << 12) // (HSMC4) CS6 +#define AT91C_HSMC4_HOSTCS_7 (0x7 << 12) // (HSMC4) CS7 +#define AT91C_HSMC4_XFRDONE (0x1 << 16) // (HSMC4) Host Data Transfer Terminated +#define AT91C_HSMC4_CMDDONE (0x1 << 17) // (HSMC4) Command Done +#define AT91C_HSMC4_ECCRDY (0x1 << 18) // (HSMC4) ECC ready +#define AT91C_HSMC4_DTOE (0x1 << 20) // (HSMC4) Data timeout Error +#define AT91C_HSMC4_UNDEF (0x1 << 21) // (HSMC4) Undefined Area Error +#define AT91C_HSMC4_AWB (0x1 << 22) // (HSMC4) Accessing While Busy Error +#define AT91C_HSMC4_HASE (0x1 << 23) // (HSMC4) Host Controller Access Size Error +#define AT91C_HSMC4_RBEDGE0 (0x1 << 24) // (HSMC4) Ready Busy line 0 Edge detected +#define AT91C_HSMC4_RBEDGE1 (0x1 << 25) // (HSMC4) Ready Busy line 1 Edge detected +#define AT91C_HSMC4_RBEDGE2 (0x1 << 26) // (HSMC4) Ready Busy line 2 Edge detected +#define AT91C_HSMC4_RBEDGE3 (0x1 << 27) // (HSMC4) Ready Busy line 3 Edge detected +#define AT91C_HSMC4_RBEDGE4 (0x1 << 28) // (HSMC4) Ready Busy line 4 Edge detected +#define AT91C_HSMC4_RBEDGE5 (0x1 << 29) // (HSMC4) Ready Busy line 5 Edge detected +#define AT91C_HSMC4_RBEDGE6 (0x1 << 30) // (HSMC4) Ready Busy line 6 Edge detected +#define AT91C_HSMC4_RBEDGE7 (0x1 << 31) // (HSMC4) Ready Busy line 7 Edge detected +// -------- HSMC4_IER : (HSMC4 Offset: 0xc) HSMC4 Interrupt Enable Register -------- +// -------- HSMC4_IDR : (HSMC4 Offset: 0x10) HSMC4 Interrupt Disable Register -------- +// -------- HSMC4_IMR : (HSMC4 Offset: 0x14) HSMC4 Interrupt Mask Register -------- +// -------- HSMC4_ADDR : (HSMC4 Offset: 0x18) Address Cycle Zero Register -------- +#define AT91C_HSMC4_ADDRCYCLE0 (0xFF << 0) // (HSMC4) Nand Flash Array Address cycle 0 +// -------- HSMC4_BANK : (HSMC4 Offset: 0x1c) Bank Register -------- +#define AT91C_BANK (0x7 << 0) // (HSMC4) Bank identifier +#define AT91C_BANK_0 (0x0) // (HSMC4) BANK0 +#define AT91C_BANK_1 (0x1) // (HSMC4) BANK1 +#define AT91C_BANK_2 (0x2) // (HSMC4) BANK2 +#define AT91C_BANK_3 (0x3) // (HSMC4) BANK3 +#define AT91C_BANK_4 (0x4) // (HSMC4) BANK4 +#define AT91C_BANK_5 (0x5) // (HSMC4) BANK5 +#define AT91C_BANK_6 (0x6) // (HSMC4) BANK6 +#define AT91C_BANK_7 (0x7) // (HSMC4) BANK7 +// -------- HSMC4_ECCCR : (HSMC4 Offset: 0x20) ECC Control Register -------- +#define AT91C_HSMC4_ECCRESET (0x1 << 0) // (HSMC4) Reset ECC +// -------- HSMC4_ECCCMD : (HSMC4 Offset: 0x24) ECC mode register -------- +#define AT91C_ECC_PAGE_SIZE (0x3 << 0) // (HSMC4) Nand Flash page size +#define AT91C_ECC_TYPCORRECT (0x3 << 4) // (HSMC4) Nand Flash page size +#define AT91C_ECC_TYPCORRECT_ONE_PER_PAGE (0x0 << 4) // (HSMC4) +#define AT91C_ECC_TYPCORRECT_ONE_EVERY_256_BYTES (0x1 << 4) // (HSMC4) +#define AT91C_ECC_TYPCORRECT_ONE_EVERY_512_BYTES (0x2 << 4) // (HSMC4) +// -------- HSMC4_ECCSR1 : (HSMC4 Offset: 0x28) ECC Status Register 1 -------- +#define AT91C_HSMC4_ECC_RECERR0 (0x1 << 0) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR0 (0x1 << 1) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR0 (0x1 << 2) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR1 (0x1 << 4) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR1 (0x1 << 5) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR1 (0x1 << 6) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR2 (0x1 << 8) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR2 (0x1 << 9) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR2 (0x1 << 10) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR3 (0x1 << 12) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR3 (0x1 << 13) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR3 (0x1 << 14) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR4 (0x1 << 16) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR4 (0x1 << 17) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR4 (0x1 << 18) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR5 (0x1 << 20) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR5 (0x1 << 21) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR5 (0x1 << 22) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR6 (0x1 << 24) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR6 (0x1 << 25) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR6 (0x1 << 26) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR7 (0x1 << 28) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR7 (0x1 << 29) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR7 (0x1 << 30) // (HSMC4) Multiple Error +// -------- HSMC4_ECCPR0 : (HSMC4 Offset: 0x2c) HSMC4 ECC parity Register 0 -------- +#define AT91C_HSMC4_ECC_BITADDR (0x7 << 0) // (HSMC4) Corrupted Bit Address in the page +#define AT91C_HSMC4_ECC_WORDADDR (0xFF << 3) // (HSMC4) Corrupted Word Address in the page +#define AT91C_HSMC4_ECC_NPARITY (0x7FF << 12) // (HSMC4) Parity N +// -------- HSMC4_ECCPR1 : (HSMC4 Offset: 0x30) HSMC4 ECC parity Register 1 -------- +// -------- HSMC4_ECCSR2 : (HSMC4 Offset: 0x34) ECC Status Register 2 -------- +#define AT91C_HSMC4_ECC_RECERR8 (0x1 << 0) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR8 (0x1 << 1) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR8 (0x1 << 2) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR9 (0x1 << 4) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR9 (0x1 << 5) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR9 (0x1 << 6) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR10 (0x1 << 8) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR10 (0x1 << 9) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR10 (0x1 << 10) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR11 (0x1 << 12) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR11 (0x1 << 13) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR11 (0x1 << 14) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR12 (0x1 << 16) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR12 (0x1 << 17) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR12 (0x1 << 18) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR13 (0x1 << 20) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR13 (0x1 << 21) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR13 (0x1 << 22) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR14 (0x1 << 24) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR14 (0x1 << 25) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR14 (0x1 << 26) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR15 (0x1 << 28) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR15 (0x1 << 29) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR15 (0x1 << 30) // (HSMC4) Multiple Error +// -------- HSMC4_ECCPR2 : (HSMC4 Offset: 0x38) HSMC4 ECC parity Register 2 -------- +// -------- HSMC4_ECCPR3 : (HSMC4 Offset: 0x3c) HSMC4 ECC parity Register 3 -------- +// -------- HSMC4_ECCPR4 : (HSMC4 Offset: 0x40) HSMC4 ECC parity Register 4 -------- +// -------- HSMC4_ECCPR5 : (HSMC4 Offset: 0x44) HSMC4 ECC parity Register 5 -------- +// -------- HSMC4_ECCPR6 : (HSMC4 Offset: 0x48) HSMC4 ECC parity Register 6 -------- +// -------- HSMC4_ECCPR7 : (HSMC4 Offset: 0x4c) HSMC4 ECC parity Register 7 -------- +// -------- HSMC4_ECCPR8 : (HSMC4 Offset: 0x50) HSMC4 ECC parity Register 8 -------- +// -------- HSMC4_ECCPR9 : (HSMC4 Offset: 0x54) HSMC4 ECC parity Register 9 -------- +// -------- HSMC4_ECCPR10 : (HSMC4 Offset: 0x58) HSMC4 ECC parity Register 10 -------- +// -------- HSMC4_ECCPR11 : (HSMC4 Offset: 0x5c) HSMC4 ECC parity Register 11 -------- +// -------- HSMC4_ECCPR12 : (HSMC4 Offset: 0x60) HSMC4 ECC parity Register 12 -------- +// -------- HSMC4_ECCPR13 : (HSMC4 Offset: 0x64) HSMC4 ECC parity Register 13 -------- +// -------- HSMC4_ECCPR14 : (HSMC4 Offset: 0x68) HSMC4 ECC parity Register 14 -------- +// -------- HSMC4_ECCPR15 : (HSMC4 Offset: 0x6c) HSMC4 ECC parity Register 15 -------- +// -------- HSMC4_OCMS : (HSMC4 Offset: 0x110) HSMC4 OCMS Register -------- +#define AT91C_HSMC4_OCMS_SRSE (0x1 << 0) // (HSMC4) Static Memory Controller Scrambling Enable +#define AT91C_HSMC4_OCMS_SMSE (0x1 << 1) // (HSMC4) SRAM Scramling Enable +// -------- HSMC4_KEY1 : (HSMC4 Offset: 0x114) HSMC4 OCMS KEY1 Register -------- +#define AT91C_HSMC4_OCMS_KEY1 (0x0 << 0) // (HSMC4) OCMS Key 2 +// -------- HSMC4_OCMS_KEY2 : (HSMC4 Offset: 0x118) HSMC4 OCMS KEY2 Register -------- +#define AT91C_HSMC4_OCMS_KEY2 (0x0 << 0) // (HSMC4) OCMS Key 2 +// -------- HSMC4_WPCR : (HSMC4 Offset: 0x1e4) HSMC4 Witre Protection Control Register -------- +#define AT91C_HSMC4_WP_EN (0x1 << 0) // (HSMC4) Write Protection Enable +#define AT91C_HSMC4_WP_KEY (0xFFFFFF << 8) // (HSMC4) Protection Password +// -------- HSMC4_WPSR : (HSMC4 Offset: 0x1e8) HSMC4 WPSR Register -------- +#define AT91C_HSMC4_WP_VS (0xF << 0) // (HSMC4) Write Protection Violation Status +#define AT91C_HSMC4_WP_VS_WP_VS0 (0x0) // (HSMC4) No write protection violation since the last read of this register +#define AT91C_HSMC4_WP_VS_WP_VS1 (0x1) // (HSMC4) write protection detected unauthorized attempt to write a control register had occured (since the last read) +#define AT91C_HSMC4_WP_VS_WP_VS2 (0x2) // (HSMC4) Software reset had been performed while write protection was enabled (since the last read) +#define AT91C_HSMC4_WP_VS_WP_VS3 (0x3) // (HSMC4) Both write protection violation and software reset with write protection enabled had occured since the last read +#define AT91C_ (0x0 << 8) // (HSMC4) +// -------- HSMC4_VER : (HSMC4 Offset: 0x1fc) HSMC4 VERSION Register -------- +// -------- HSMC4_DUMMY : (HSMC4 Offset: 0x200) HSMC4 DUMMY REGISTER -------- +#define AT91C_HSMC4_CMD1 (0xFF << 2) // (HSMC4) Command Register Value for Cycle 1 +#define AT91C_HSMC4_CMD2 (0xFF << 10) // (HSMC4) Command Register Value for Cycle 2 +#define AT91C_HSMC4_VCMD2 (0x1 << 18) // (HSMC4) Valid Cycle 2 Command +#define AT91C_HSMC4_ACYCLE (0x7 << 19) // (HSMC4) Number of Address required for the current command +#define AT91C_HSMC4_ACYCLE_HSMC4_ACYCLE_NONE (0x0 << 19) // (HSMC4) No address cycle +#define AT91C_HSMC4_ACYCLE_HSMC4_ACYCLE_ONE (0x1 << 19) // (HSMC4) One address cycle +#define AT91C_HSMC4_ACYCLE_HSMC4_ACYCLE_TWO (0x2 << 19) // (HSMC4) Two address cycles +#define AT91C_HSMC4_ACYCLE_HSMC4_ACYCLE_THREE (0x3 << 19) // (HSMC4) Three address cycles +#define AT91C_HSMC4_ACYCLE_HSMC4_ACYCLE_FOUR (0x4 << 19) // (HSMC4) Four address cycles +#define AT91C_HSMC4_ACYCLE_HSMC4_ACYCLE_FIVE (0x5 << 19) // (HSMC4) Five address cycles +#define AT91C_HSMC4_CSID (0x7 << 22) // (HSMC4) Chip Select Identifier +#define AT91C_HSMC4_CSID_0 (0x0 << 22) // (HSMC4) CS0 +#define AT91C_HSMC4_CSID_1 (0x1 << 22) // (HSMC4) CS1 +#define AT91C_HSMC4_CSID_2 (0x2 << 22) // (HSMC4) CS2 +#define AT91C_HSMC4_CSID_3 (0x3 << 22) // (HSMC4) CS3 +#define AT91C_HSMC4_CSID_4 (0x4 << 22) // (HSMC4) CS4 +#define AT91C_HSMC4_CSID_5 (0x5 << 22) // (HSMC4) CS5 +#define AT91C_HSMC4_CSID_6 (0x6 << 22) // (HSMC4) CS6 +#define AT91C_HSMC4_CSID_7 (0x7 << 22) // (HSMC4) CS7 +#define AT91C_HSMC4_HOST_EN (0x1 << 25) // (HSMC4) Host Main Controller Enable +#define AT91C_HSMC4_HOST_WR (0x1 << 26) // (HSMC4) HOSTWR : Host Main Controller Write Enable +#define AT91C_HSMC4_HOSTCMD (0x1 << 27) // (HSMC4) Host Command Enable + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR AHB Matrix2 Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_HMATRIX2 { + AT91_REG HMATRIX2_MCFG0; // Master Configuration Register 0 : ARM I and D + AT91_REG HMATRIX2_MCFG1; // Master Configuration Register 1 : ARM S + AT91_REG HMATRIX2_MCFG2; // Master Configuration Register 2 + AT91_REG HMATRIX2_MCFG3; // Master Configuration Register 3 + AT91_REG HMATRIX2_MCFG4; // Master Configuration Register 4 + AT91_REG HMATRIX2_MCFG5; // Master Configuration Register 5 + AT91_REG HMATRIX2_MCFG6; // Master Configuration Register 6 + AT91_REG HMATRIX2_MCFG7; // Master Configuration Register 7 + AT91_REG Reserved0[8]; // + AT91_REG HMATRIX2_SCFG0; // Slave Configuration Register 0 + AT91_REG HMATRIX2_SCFG1; // Slave Configuration Register 1 + AT91_REG HMATRIX2_SCFG2; // Slave Configuration Register 2 + AT91_REG HMATRIX2_SCFG3; // Slave Configuration Register 3 + AT91_REG HMATRIX2_SCFG4; // Slave Configuration Register 4 + AT91_REG HMATRIX2_SCFG5; // Slave Configuration Register 5 + AT91_REG HMATRIX2_SCFG6; // Slave Configuration Register 6 + AT91_REG HMATRIX2_SCFG7; // Slave Configuration Register 5 + AT91_REG HMATRIX2_SCFG8; // Slave Configuration Register 8 + AT91_REG Reserved1[43]; // + AT91_REG HMATRIX2_SFR0 ; // Special Function Register 0 + AT91_REG HMATRIX2_SFR1 ; // Special Function Register 1 + AT91_REG HMATRIX2_SFR2 ; // Special Function Register 2 + AT91_REG HMATRIX2_SFR3 ; // Special Function Register 3 + AT91_REG HMATRIX2_SFR4 ; // Special Function Register 4 + AT91_REG HMATRIX2_SFR5 ; // Special Function Register 5 + AT91_REG HMATRIX2_SFR6 ; // Special Function Register 6 + AT91_REG HMATRIX2_SFR7 ; // Special Function Register 7 + AT91_REG HMATRIX2_SFR8 ; // Special Function Register 8 + AT91_REG HMATRIX2_SFR9 ; // Special Function Register 9 + AT91_REG HMATRIX2_SFR10; // Special Function Register 10 + AT91_REG HMATRIX2_SFR11; // Special Function Register 11 + AT91_REG HMATRIX2_SFR12; // Special Function Register 12 + AT91_REG HMATRIX2_SFR13; // Special Function Register 13 + AT91_REG HMATRIX2_SFR14; // Special Function Register 14 + AT91_REG HMATRIX2_SFR15; // Special Function Register 15 + AT91_REG Reserved2[39]; // + AT91_REG HMATRIX2_ADDRSIZE; // HMATRIX2 ADDRSIZE REGISTER + AT91_REG HMATRIX2_IPNAME1; // HMATRIX2 IPNAME1 REGISTER + AT91_REG HMATRIX2_IPNAME2; // HMATRIX2 IPNAME2 REGISTER + AT91_REG HMATRIX2_FEATURES; // HMATRIX2 FEATURES REGISTER + AT91_REG HMATRIX2_VER; // HMATRIX2 VERSION REGISTER +} AT91S_HMATRIX2, *AT91PS_HMATRIX2; +#else +#define MATRIX_MCFG0 (AT91_CAST(AT91_REG *) 0x00000000) // (MATRIX_MCFG0) Master Configuration Register 0 : ARM I and D +#define MATRIX_MCFG1 (AT91_CAST(AT91_REG *) 0x00000004) // (MATRIX_MCFG1) Master Configuration Register 1 : ARM S +#define MATRIX_MCFG2 (AT91_CAST(AT91_REG *) 0x00000008) // (MATRIX_MCFG2) Master Configuration Register 2 +#define MATRIX_MCFG3 (AT91_CAST(AT91_REG *) 0x0000000C) // (MATRIX_MCFG3) Master Configuration Register 3 +#define MATRIX_MCFG4 (AT91_CAST(AT91_REG *) 0x00000010) // (MATRIX_MCFG4) Master Configuration Register 4 +#define MATRIX_MCFG5 (AT91_CAST(AT91_REG *) 0x00000014) // (MATRIX_MCFG5) Master Configuration Register 5 +#define MATRIX_MCFG6 (AT91_CAST(AT91_REG *) 0x00000018) // (MATRIX_MCFG6) Master Configuration Register 6 +#define MATRIX_MCFG7 (AT91_CAST(AT91_REG *) 0x0000001C) // (MATRIX_MCFG7) Master Configuration Register 7 +#define MATRIX_SCFG0 (AT91_CAST(AT91_REG *) 0x00000040) // (MATRIX_SCFG0) Slave Configuration Register 0 +#define MATRIX_SCFG1 (AT91_CAST(AT91_REG *) 0x00000044) // (MATRIX_SCFG1) Slave Configuration Register 1 +#define MATRIX_SCFG2 (AT91_CAST(AT91_REG *) 0x00000048) // (MATRIX_SCFG2) Slave Configuration Register 2 +#define MATRIX_SCFG3 (AT91_CAST(AT91_REG *) 0x0000004C) // (MATRIX_SCFG3) Slave Configuration Register 3 +#define MATRIX_SCFG4 (AT91_CAST(AT91_REG *) 0x00000050) // (MATRIX_SCFG4) Slave Configuration Register 4 +#define MATRIX_SCFG5 (AT91_CAST(AT91_REG *) 0x00000054) // (MATRIX_SCFG5) Slave Configuration Register 5 +#define MATRIX_SCFG6 (AT91_CAST(AT91_REG *) 0x00000058) // (MATRIX_SCFG6) Slave Configuration Register 6 +#define MATRIX_SCFG7 (AT91_CAST(AT91_REG *) 0x0000005C) // (MATRIX_SCFG7) Slave Configuration Register 5 +#define MATRIX_SCFG8 (AT91_CAST(AT91_REG *) 0x00000060) // (MATRIX_SCFG8) Slave Configuration Register 8 +#define MATRIX_SFR0 (AT91_CAST(AT91_REG *) 0x00000110) // (MATRIX_SFR0 ) Special Function Register 0 +#define MATRIX_SFR1 (AT91_CAST(AT91_REG *) 0x00000114) // (MATRIX_SFR1 ) Special Function Register 1 +#define MATRIX_SFR2 (AT91_CAST(AT91_REG *) 0x00000118) // (MATRIX_SFR2 ) Special Function Register 2 +#define MATRIX_SFR3 (AT91_CAST(AT91_REG *) 0x0000011C) // (MATRIX_SFR3 ) Special Function Register 3 +#define MATRIX_SFR4 (AT91_CAST(AT91_REG *) 0x00000120) // (MATRIX_SFR4 ) Special Function Register 4 +#define MATRIX_SFR5 (AT91_CAST(AT91_REG *) 0x00000124) // (MATRIX_SFR5 ) Special Function Register 5 +#define MATRIX_SFR6 (AT91_CAST(AT91_REG *) 0x00000128) // (MATRIX_SFR6 ) Special Function Register 6 +#define MATRIX_SFR7 (AT91_CAST(AT91_REG *) 0x0000012C) // (MATRIX_SFR7 ) Special Function Register 7 +#define MATRIX_SFR8 (AT91_CAST(AT91_REG *) 0x00000130) // (MATRIX_SFR8 ) Special Function Register 8 +#define MATRIX_SFR9 (AT91_CAST(AT91_REG *) 0x00000134) // (MATRIX_SFR9 ) Special Function Register 9 +#define MATRIX_SFR10 (AT91_CAST(AT91_REG *) 0x00000138) // (MATRIX_SFR10) Special Function Register 10 +#define MATRIX_SFR11 (AT91_CAST(AT91_REG *) 0x0000013C) // (MATRIX_SFR11) Special Function Register 11 +#define MATRIX_SFR12 (AT91_CAST(AT91_REG *) 0x00000140) // (MATRIX_SFR12) Special Function Register 12 +#define MATRIX_SFR13 (AT91_CAST(AT91_REG *) 0x00000144) // (MATRIX_SFR13) Special Function Register 13 +#define MATRIX_SFR14 (AT91_CAST(AT91_REG *) 0x00000148) // (MATRIX_SFR14) Special Function Register 14 +#define MATRIX_SFR15 (AT91_CAST(AT91_REG *) 0x0000014C) // (MATRIX_SFR15) Special Function Register 15 +#define HMATRIX2_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000001EC) // (HMATRIX2_ADDRSIZE) HMATRIX2 ADDRSIZE REGISTER +#define HMATRIX2_IPNAME1 (AT91_CAST(AT91_REG *) 0x000001F0) // (HMATRIX2_IPNAME1) HMATRIX2 IPNAME1 REGISTER +#define HMATRIX2_IPNAME2 (AT91_CAST(AT91_REG *) 0x000001F4) // (HMATRIX2_IPNAME2) HMATRIX2 IPNAME2 REGISTER +#define HMATRIX2_FEATURES (AT91_CAST(AT91_REG *) 0x000001F8) // (HMATRIX2_FEATURES) HMATRIX2 FEATURES REGISTER +#define HMATRIX2_VER (AT91_CAST(AT91_REG *) 0x000001FC) // (HMATRIX2_VER) HMATRIX2 VERSION REGISTER + +#endif +// -------- MATRIX_MCFG0 : (HMATRIX2 Offset: 0x0) Master Configuration Register ARM bus I and D -------- +#define AT91C_MATRIX_ULBT (0x7 << 0) // (HMATRIX2) Undefined Length Burst Type +#define AT91C_MATRIX_ULBT_INFINIT_LENGTH (0x0) // (HMATRIX2) infinite length burst +#define AT91C_MATRIX_ULBT_SINGLE_ACCESS (0x1) // (HMATRIX2) Single Access +#define AT91C_MATRIX_ULBT_4_BEAT (0x2) // (HMATRIX2) 4 Beat Burst +#define AT91C_MATRIX_ULBT_8_BEAT (0x3) // (HMATRIX2) 8 Beat Burst +#define AT91C_MATRIX_ULBT_16_BEAT (0x4) // (HMATRIX2) 16 Beat Burst +#define AT91C_MATRIX_ULBT_32_BEAT (0x5) // (HMATRIX2) 32 Beat Burst +#define AT91C_MATRIX_ULBT_64_BEAT (0x6) // (HMATRIX2) 64 Beat Burst +#define AT91C_MATRIX_ULBT_128_BEAT (0x7) // (HMATRIX2) 128 Beat Burst +// -------- MATRIX_MCFG1 : (HMATRIX2 Offset: 0x4) Master Configuration Register ARM bus S -------- +// -------- MATRIX_MCFG2 : (HMATRIX2 Offset: 0x8) Master Configuration Register -------- +// -------- MATRIX_MCFG3 : (HMATRIX2 Offset: 0xc) Master Configuration Register -------- +// -------- MATRIX_MCFG4 : (HMATRIX2 Offset: 0x10) Master Configuration Register -------- +// -------- MATRIX_MCFG5 : (HMATRIX2 Offset: 0x14) Master Configuration Register -------- +// -------- MATRIX_MCFG6 : (HMATRIX2 Offset: 0x18) Master Configuration Register -------- +// -------- MATRIX_MCFG7 : (HMATRIX2 Offset: 0x1c) Master Configuration Register -------- +// -------- MATRIX_SCFG0 : (HMATRIX2 Offset: 0x40) Slave Configuration Register 0 -------- +#define AT91C_MATRIX_SLOT_CYCLE (0xFF << 0) // (HMATRIX2) Maximum Number of Allowed Cycles for a Burst +#define AT91C_MATRIX_DEFMSTR_TYPE (0x3 << 16) // (HMATRIX2) Default Master Type +#define AT91C_MATRIX_DEFMSTR_TYPE_NO_DEFMSTR (0x0 << 16) // (HMATRIX2) No Default Master. At the end of current slave access, if no other master request is pending, the slave is deconnected from all masters. This results in having a one cycle latency for the first transfer of a burst. +#define AT91C_MATRIX_DEFMSTR_TYPE_LAST_DEFMSTR (0x1 << 16) // (HMATRIX2) Last Default Master. At the end of current slave access, if no other master request is pending, the slave stay connected with the last master having accessed it. This results in not having the one cycle latency when the last master re-trying access on the slave. +#define AT91C_MATRIX_DEFMSTR_TYPE_FIXED_DEFMSTR (0x2 << 16) // (HMATRIX2) Fixed Default Master. At the end of current slave access, if no other master request is pending, the slave connects with fixed which number is in FIXED_DEFMSTR field. This results in not having the one cycle latency when the fixed master re-trying access on the slave. +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG0 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG0_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG1 : (HMATRIX2 Offset: 0x44) Slave Configuration Register 1 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG1 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG1_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG2 : (HMATRIX2 Offset: 0x48) Slave Configuration Register 2 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG2 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG2_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG3 : (HMATRIX2 Offset: 0x4c) Slave Configuration Register 3 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG3 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG3_ARMC (0x0 << 18) // (HMATRIX2) ARMC is Default Master +// -------- MATRIX_SCFG4 : (HMATRIX2 Offset: 0x50) Slave Configuration Register 4 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG4 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG4_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG5 : (HMATRIX2 Offset: 0x54) Slave Configuration Register 5 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG5 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG5_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG6 : (HMATRIX2 Offset: 0x58) Slave Configuration Register 6 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG6 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG6_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG7 : (HMATRIX2 Offset: 0x5c) Slave Configuration Register 7 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG7 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG7_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG8 : (HMATRIX2 Offset: 0x60) Slave Configuration Register 8 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG8 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG8_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG8_HDMA (0x4 << 18) // (HMATRIX2) HDMA is Default Master +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x110) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x114) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x118) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x11c) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x120) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x124) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x128) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x12c) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x130) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x134) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x138) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x13c) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x140) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x144) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x148) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x14c) Special Function Register 0 -------- +// -------- HMATRIX2_VER : (HMATRIX2 Offset: 0x1fc) VERSION Register -------- +#define AT91C_HMATRIX2_VER (0xF << 0) // (HMATRIX2) VERSION Register + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR NESTED vector Interrupt Controller +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_NVIC { + AT91_REG Reserved0[1]; // + AT91_REG NVIC_ICTR; // Interrupt Control Type Register + AT91_REG Reserved1[2]; // + AT91_REG NVIC_STICKCSR; // SysTick Control and Status Register + AT91_REG NVIC_STICKRVR; // SysTick Reload Value Register + AT91_REG NVIC_STICKCVR; // SysTick Current Value Register + AT91_REG NVIC_STICKCALVR; // SysTick Calibration Value Register + AT91_REG Reserved2[56]; // + AT91_REG NVIC_ISER[8]; // Set Enable Register + AT91_REG Reserved3[24]; // + AT91_REG NVIC_ICER[8]; // Clear enable Register + AT91_REG Reserved4[24]; // + AT91_REG NVIC_ISPR[8]; // Set Pending Register + AT91_REG Reserved5[24]; // + AT91_REG NVIC_ICPR[8]; // Clear Pending Register + AT91_REG Reserved6[24]; // + AT91_REG NVIC_ABR[8]; // Active Bit Register + AT91_REG Reserved7[56]; // + AT91_REG NVIC_IPR[60]; // Interrupt Mask Register + AT91_REG Reserved8[516]; // + AT91_REG NVIC_CPUID; // CPUID Base Register + AT91_REG NVIC_ICSR; // Interrupt Control State Register + AT91_REG NVIC_VTOFFR; // Vector Table Offset Register + AT91_REG NVIC_AIRCR; // Application Interrupt/Reset Control Reg + AT91_REG NVIC_SCR; // System Control Register + AT91_REG NVIC_CCR; // Configuration Control Register + AT91_REG NVIC_HAND4PR; // System Handlers 4-7 Priority Register + AT91_REG NVIC_HAND8PR; // System Handlers 8-11 Priority Register + AT91_REG NVIC_HAND12PR; // System Handlers 12-15 Priority Register + AT91_REG NVIC_HANDCSR; // System Handler Control and State Register + AT91_REG NVIC_CFSR; // Configurable Fault Status Register + AT91_REG NVIC_HFSR; // Hard Fault Status Register + AT91_REG NVIC_DFSR; // Debug Fault Status Register + AT91_REG NVIC_MMAR; // Mem Manage Address Register + AT91_REG NVIC_BFAR; // Bus Fault Address Register + AT91_REG NVIC_AFSR; // Auxiliary Fault Status Register + AT91_REG NVIC_PFR0; // Processor Feature register0 + AT91_REG NVIC_PFR1; // Processor Feature register1 + AT91_REG NVIC_DFR0; // Debug Feature register0 + AT91_REG NVIC_AFR0; // Auxiliary Feature register0 + AT91_REG NVIC_MMFR0; // Memory Model Feature register0 + AT91_REG NVIC_MMFR1; // Memory Model Feature register1 + AT91_REG NVIC_MMFR2; // Memory Model Feature register2 + AT91_REG NVIC_MMFR3; // Memory Model Feature register3 + AT91_REG NVIC_ISAR0; // ISA Feature register0 + AT91_REG NVIC_ISAR1; // ISA Feature register1 + AT91_REG NVIC_ISAR2; // ISA Feature register2 + AT91_REG NVIC_ISAR3; // ISA Feature register3 + AT91_REG NVIC_ISAR4; // ISA Feature register4 + AT91_REG Reserved9[99]; // + AT91_REG NVIC_STIR; // Software Trigger Interrupt Register + AT91_REG Reserved10[51]; // + AT91_REG NVIC_PID4; // Peripheral identification register + AT91_REG NVIC_PID5; // Peripheral identification register + AT91_REG NVIC_PID6; // Peripheral identification register + AT91_REG NVIC_PID7; // Peripheral identification register + AT91_REG NVIC_PID0; // Peripheral identification register b7:0 + AT91_REG NVIC_PID1; // Peripheral identification register b15:8 + AT91_REG NVIC_PID2; // Peripheral identification register b23:16 + AT91_REG NVIC_PID3; // Peripheral identification register b31:24 + AT91_REG NVIC_CID0; // Component identification register b7:0 + AT91_REG NVIC_CID1; // Component identification register b15:8 + AT91_REG NVIC_CID2; // Component identification register b23:16 + AT91_REG NVIC_CID3; // Component identification register b31:24 +} AT91S_NVIC, *AT91PS_NVIC; +#else +#define NVIC_ICTR (AT91_CAST(AT91_REG *) 0x00000004) // (NVIC_ICTR) Interrupt Control Type Register +#define NVIC_STICKCSR (AT91_CAST(AT91_REG *) 0x00000010) // (NVIC_STICKCSR) SysTick Control and Status Register +#define NVIC_STICKRVR (AT91_CAST(AT91_REG *) 0x00000014) // (NVIC_STICKRVR) SysTick Reload Value Register +#define NVIC_STICKCVR (AT91_CAST(AT91_REG *) 0x00000018) // (NVIC_STICKCVR) SysTick Current Value Register +#define NVIC_STICKCALVR (AT91_CAST(AT91_REG *) 0x0000001C) // (NVIC_STICKCALVR) SysTick Calibration Value Register +#define NVIC_ISER (AT91_CAST(AT91_REG *) 0x00000100) // (NVIC_ISER) Set Enable Register +#define NVIC_ICER (AT91_CAST(AT91_REG *) 0x00000180) // (NVIC_ICER) Clear enable Register +#define NVIC_ISPR (AT91_CAST(AT91_REG *) 0x00000200) // (NVIC_ISPR) Set Pending Register +#define NVIC_ICPR (AT91_CAST(AT91_REG *) 0x00000280) // (NVIC_ICPR) Clear Pending Register +#define NVIC_IABR (AT91_CAST(AT91_REG *) 0x00000300) // (NVIC_IABR) Active Bit Register +#define NVIC_IPR (AT91_CAST(AT91_REG *) 0x00000400) // (NVIC_IPR) Interrupt Mask Register +#define NVIC_CPUID (AT91_CAST(AT91_REG *) 0x00000D00) // (NVIC_CPUID) CPUID Base Register +#define NVIC_ICSR (AT91_CAST(AT91_REG *) 0x00000D04) // (NVIC_ICSR) Interrupt Control State Register +#define NVIC_VTOFFR (AT91_CAST(AT91_REG *) 0x00000D08) // (NVIC_VTOFFR) Vector Table Offset Register +#define NVIC_AIRCR (AT91_CAST(AT91_REG *) 0x00000D0C) // (NVIC_AIRCR) Application Interrupt/Reset Control Reg +#define NVIC_SCR (AT91_CAST(AT91_REG *) 0x00000D10) // (NVIC_SCR) System Control Register +#define NVIC_CCR (AT91_CAST(AT91_REG *) 0x00000D14) // (NVIC_CCR) Configuration Control Register +#define NVIC_HAND4PR (AT91_CAST(AT91_REG *) 0x00000D18) // (NVIC_HAND4PR) System Handlers 4-7 Priority Register +#define NVIC_HAND8PR (AT91_CAST(AT91_REG *) 0x00000D1C) // (NVIC_HAND8PR) System Handlers 8-11 Priority Register +#define NVIC_HAND12PR (AT91_CAST(AT91_REG *) 0x00000D20) // (NVIC_HAND12PR) System Handlers 12-15 Priority Register +#define NVIC_HANDCSR (AT91_CAST(AT91_REG *) 0x00000D24) // (NVIC_HANDCSR) System Handler Control and State Register +#define NVIC_CFSR (AT91_CAST(AT91_REG *) 0x00000D28) // (NVIC_CFSR) Configurable Fault Status Register +#define NVIC_HFSR (AT91_CAST(AT91_REG *) 0x00000D2C) // (NVIC_HFSR) Hard Fault Status Register +#define NVIC_DFSR (AT91_CAST(AT91_REG *) 0x00000D30) // (NVIC_DFSR) Debug Fault Status Register +#define NVIC_MMAR (AT91_CAST(AT91_REG *) 0x00000D34) // (NVIC_MMAR) Mem Manage Address Register +#define NVIC_BFAR (AT91_CAST(AT91_REG *) 0x00000D38) // (NVIC_BFAR) Bus Fault Address Register +#define NVIC_AFSR (AT91_CAST(AT91_REG *) 0x00000D3C) // (NVIC_AFSR) Auxiliary Fault Status Register +#define NVIC_PFR0 (AT91_CAST(AT91_REG *) 0x00000D40) // (NVIC_PFR0) Processor Feature register0 +#define NVIC_PFR1 (AT91_CAST(AT91_REG *) 0x00000D44) // (NVIC_PFR1) Processor Feature register1 +#define NVIC_DFR0 (AT91_CAST(AT91_REG *) 0x00000D48) // (NVIC_DFR0) Debug Feature register0 +#define NVIC_AFR0 (AT91_CAST(AT91_REG *) 0x00000D4C) // (NVIC_AFR0) Auxiliary Feature register0 +#define NVIC_MMFR0 (AT91_CAST(AT91_REG *) 0x00000D50) // (NVIC_MMFR0) Memory Model Feature register0 +#define NVIC_MMFR1 (AT91_CAST(AT91_REG *) 0x00000D54) // (NVIC_MMFR1) Memory Model Feature register1 +#define NVIC_MMFR2 (AT91_CAST(AT91_REG *) 0x00000D58) // (NVIC_MMFR2) Memory Model Feature register2 +#define NVIC_MMFR3 (AT91_CAST(AT91_REG *) 0x00000D5C) // (NVIC_MMFR3) Memory Model Feature register3 +#define NVIC_ISAR0 (AT91_CAST(AT91_REG *) 0x00000D60) // (NVIC_ISAR0) ISA Feature register0 +#define NVIC_ISAR1 (AT91_CAST(AT91_REG *) 0x00000D64) // (NVIC_ISAR1) ISA Feature register1 +#define NVIC_ISAR2 (AT91_CAST(AT91_REG *) 0x00000D68) // (NVIC_ISAR2) ISA Feature register2 +#define NVIC_ISAR3 (AT91_CAST(AT91_REG *) 0x00000D6C) // (NVIC_ISAR3) ISA Feature register3 +#define NVIC_ISAR4 (AT91_CAST(AT91_REG *) 0x00000D70) // (NVIC_ISAR4) ISA Feature register4 +#define NVIC_STIR (AT91_CAST(AT91_REG *) 0x00000F00) // (NVIC_STIR) Software Trigger Interrupt Register +#define NVIC_PID4 (AT91_CAST(AT91_REG *) 0x00000FD0) // (NVIC_PID4) Peripheral identification register +#define NVIC_PID5 (AT91_CAST(AT91_REG *) 0x00000FD4) // (NVIC_PID5) Peripheral identification register +#define NVIC_PID6 (AT91_CAST(AT91_REG *) 0x00000FD8) // (NVIC_PID6) Peripheral identification register +#define NVIC_PID7 (AT91_CAST(AT91_REG *) 0x00000FDC) // (NVIC_PID7) Peripheral identification register +#define NVIC_PID0 (AT91_CAST(AT91_REG *) 0x00000FE0) // (NVIC_PID0) Peripheral identification register b7:0 +#define NVIC_PID1 (AT91_CAST(AT91_REG *) 0x00000FE4) // (NVIC_PID1) Peripheral identification register b15:8 +#define NVIC_PID2 (AT91_CAST(AT91_REG *) 0x00000FE8) // (NVIC_PID2) Peripheral identification register b23:16 +#define NVIC_PID3 (AT91_CAST(AT91_REG *) 0x00000FEC) // (NVIC_PID3) Peripheral identification register b31:24 +#define NVIC_CID0 (AT91_CAST(AT91_REG *) 0x00000FF0) // (NVIC_CID0) Component identification register b7:0 +#define NVIC_CID1 (AT91_CAST(AT91_REG *) 0x00000FF4) // (NVIC_CID1) Component identification register b15:8 +#define NVIC_CID2 (AT91_CAST(AT91_REG *) 0x00000FF8) // (NVIC_CID2) Component identification register b23:16 +#define NVIC_CID3 (AT91_CAST(AT91_REG *) 0x00000FFC) // (NVIC_CID3) Component identification register b31:24 + +#endif +// -------- NVIC_ICTR : (NVIC Offset: 0x4) Interrupt Controller Type Register -------- +#define AT91C_NVIC_INTLINESNUM (0xF << 0) // (NVIC) Total number of interrupt lines +#define AT91C_NVIC_INTLINESNUM_32 (0x0) // (NVIC) up to 32 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_64 (0x1) // (NVIC) up to 64 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_96 (0x2) // (NVIC) up to 96 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_128 (0x3) // (NVIC) up to 128 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_160 (0x4) // (NVIC) up to 160 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_192 (0x5) // (NVIC) up to 192 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_224 (0x6) // (NVIC) up to 224 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_256 (0x7) // (NVIC) up to 256 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_288 (0x8) // (NVIC) up to 288 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_320 (0x9) // (NVIC) up to 320 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_352 (0xA) // (NVIC) up to 352 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_384 (0xB) // (NVIC) up to 384 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_416 (0xC) // (NVIC) up to 416 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_448 (0xD) // (NVIC) up to 448 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_480 (0xE) // (NVIC) up to 480 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_496 (0xF) // (NVIC) up to 496 interrupt lines supported) +// -------- NVIC_STICKCSR : (NVIC Offset: 0x10) SysTick Control and Status Register -------- +#define AT91C_NVIC_STICKENABLE (0x1 << 0) // (NVIC) SysTick counter enable. +#define AT91C_NVIC_STICKINT (0x1 << 1) // (NVIC) SysTick interrupt enable. +#define AT91C_NVIC_STICKCLKSOURCE (0x1 << 2) // (NVIC) Reference clock selection. +#define AT91C_NVIC_STICKCOUNTFLAG (0x1 << 16) // (NVIC) Return 1 if timer counted to 0 since last read. +// -------- NVIC_STICKRVR : (NVIC Offset: 0x14) SysTick Reload Value Register -------- +#define AT91C_NVIC_STICKRELOAD (0xFFFFFF << 0) // (NVIC) SysTick reload value. +// -------- NVIC_STICKCVR : (NVIC Offset: 0x18) SysTick Current Value Register -------- +#define AT91C_NVIC_STICKCURRENT (0x7FFFFFFF << 0) // (NVIC) SysTick current value. +// -------- NVIC_STICKCALVR : (NVIC Offset: 0x1c) SysTick Calibration Value Register -------- +#define AT91C_NVIC_STICKTENMS (0xFFFFFF << 0) // (NVIC) Reload value to use for 10ms timing. +#define AT91C_NVIC_STICKSKEW (0x1 << 30) // (NVIC) Read as 1 if the calibration value is not exactly 10ms because of clock frequency. +#define AT91C_NVIC_STICKNOREF (0x1 << 31) // (NVIC) Read as 1 if the reference clock is not provided. +// -------- NVIC_IPR : (NVIC Offset: 0x400) Interrupt Priority Registers -------- +#define AT91C_NVIC_PRI_N (0xFF << 0) // (NVIC) Priority of interrupt N (0, 4, 8, etc) +#define AT91C_NVIC_PRI_N1 (0xFF << 8) // (NVIC) Priority of interrupt N+1 (1, 5, 9, etc) +#define AT91C_NVIC_PRI_N2 (0xFF << 16) // (NVIC) Priority of interrupt N+2 (2, 6, 10, etc) +#define AT91C_NVIC_PRI_N3 (0xFF << 24) // (NVIC) Priority of interrupt N+3 (3, 7, 11, etc) +// -------- NVIC_CPUID : (NVIC Offset: 0xd00) CPU ID Base Register -------- +#define AT91C_NVIC_REVISION (0xF << 0) // (NVIC) Implementation defined revision number. +#define AT91C_NVIC_PARTNO (0xFFF << 4) // (NVIC) Number of processor within family +#define AT91C_NVIC_CONSTANT (0xF << 16) // (NVIC) Reads as 0xF +#define AT91C_NVIC_VARIANT (0xF << 20) // (NVIC) Implementation defined variant number. +#define AT91C_NVIC_IMPLEMENTER (0xFF << 24) // (NVIC) Implementer code. ARM is 0x41 +// -------- NVIC_ICSR : (NVIC Offset: 0xd04) Interrupt Control State Register -------- +#define AT91C_NVIC_VECTACTIVE (0x1FF << 0) // (NVIC) Read-only Active ISR number field +#define AT91C_NVIC_RETTOBASE (0x1 << 11) // (NVIC) Read-only +#define AT91C_NVIC_VECTPENDING (0x1FF << 12) // (NVIC) Read-only Pending ISR number field +#define AT91C_NVIC_ISRPENDING (0x1 << 22) // (NVIC) Read-only Interrupt pending flag. +#define AT91C_NVIC_ISRPREEMPT (0x1 << 23) // (NVIC) Read-only You must only use this at debug time +#define AT91C_NVIC_PENDSTCLR (0x1 << 25) // (NVIC) Write-only Clear pending SysTick bit +#define AT91C_NVIC_PENDSTSET (0x1 << 26) // (NVIC) Read/write Set a pending SysTick bit +#define AT91C_NVIC_PENDSVCLR (0x1 << 27) // (NVIC) Write-only Clear pending pendSV bit +#define AT91C_NVIC_PENDSVSET (0x1 << 28) // (NVIC) Read/write Set pending pendSV bit +#define AT91C_NVIC_NMIPENDSET (0x1 << 31) // (NVIC) Read/write Set pending NMI +// -------- NVIC_VTOFFR : (NVIC Offset: 0xd08) Vector Table Offset Register -------- +#define AT91C_NVIC_TBLOFF (0x3FFFFF << 7) // (NVIC) Vector table base offset field +#define AT91C_NVIC_TBLBASE (0x1 << 29) // (NVIC) Table base is in Code (0) or RAM (1) +#define AT91C_NVIC_TBLBASE_CODE (0x0 << 29) // (NVIC) Table base is in CODE +#define AT91C_NVIC_TBLBASE_RAM (0x1 << 29) // (NVIC) Table base is in RAM +// -------- NVIC_AIRCR : (NVIC Offset: 0xd0c) Application Interrupt and Reset Control Register -------- +#define AT91C_NVIC_VECTRESET (0x1 << 0) // (NVIC) System Reset bit +#define AT91C_NVIC_VECTCLRACTIVE (0x1 << 1) // (NVIC) Clear active vector bit +#define AT91C_NVIC_SYSRESETREQ (0x1 << 2) // (NVIC) Causes a signal to be asserted to the outer system that indicates a reset is requested +#define AT91C_NVIC_PRIGROUP (0x7 << 8) // (NVIC) Interrupt priority grouping field +#define AT91C_NVIC_PRIGROUP_0 (0x0 << 8) // (NVIC) indicates seven bits of pre-emption priority, one bit of subpriority +#define AT91C_NVIC_PRIGROUP_1 (0x1 << 8) // (NVIC) indicates six bits of pre-emption priority, two bits of subpriority +#define AT91C_NVIC_PRIGROUP_2 (0x2 << 8) // (NVIC) indicates five bits of pre-emption priority, three bits of subpriority +#define AT91C_NVIC_PRIGROUP_3 (0x3 << 8) // (NVIC) indicates four bits of pre-emption priority, four bits of subpriority +#define AT91C_NVIC_PRIGROUP_4 (0x4 << 8) // (NVIC) indicates three bits of pre-emption priority, five bits of subpriority +#define AT91C_NVIC_PRIGROUP_5 (0x5 << 8) // (NVIC) indicates two bits of pre-emption priority, six bits of subpriority +#define AT91C_NVIC_PRIGROUP_6 (0x6 << 8) // (NVIC) indicates one bit of pre-emption priority, seven bits of subpriority +#define AT91C_NVIC_PRIGROUP_7 (0x7 << 8) // (NVIC) indicates no pre-emption priority, eight bits of subpriority +#define AT91C_NVIC_ENDIANESS (0x1 << 15) // (NVIC) Data endianness bit +#define AT91C_NVIC_VECTKEY (0xFFFF << 16) // (NVIC) Register key +// -------- NVIC_SCR : (NVIC Offset: 0xd10) System Control Register -------- +#define AT91C_NVIC_SLEEPONEXIT (0x1 << 1) // (NVIC) Sleep on exit when returning from Handler mode to Thread mode +#define AT91C_NVIC_SLEEPDEEP (0x1 << 2) // (NVIC) Sleep deep bit +#define AT91C_NVIC_SEVONPEND (0x1 << 4) // (NVIC) When enabled, this causes WFE to wake up when an interrupt moves from inactive to pended +// -------- NVIC_CCR : (NVIC Offset: 0xd14) Configuration Control Register -------- +#define AT91C_NVIC_NONEBASETHRDENA (0x1 << 0) // (NVIC) When 0, default, It is only possible to enter Thread mode when returning from the last exception +#define AT91C_NVIC_USERSETMPEND (0x1 << 1) // (NVIC) +#define AT91C_NVIC_UNALIGN_TRP (0x1 << 3) // (NVIC) Trap for unaligned access +#define AT91C_NVIC_DIV_0_TRP (0x1 << 4) // (NVIC) Trap on Divide by 0 +#define AT91C_NVIC_BFHFNMIGN (0x1 << 8) // (NVIC) +#define AT91C_NVIC_STKALIGN (0x1 << 9) // (NVIC) +// -------- NVIC_HAND4PR : (NVIC Offset: 0xd18) System Handlers 4-7 Priority Register -------- +#define AT91C_NVIC_PRI_4 (0xFF << 0) // (NVIC) +#define AT91C_NVIC_PRI_5 (0xFF << 8) // (NVIC) +#define AT91C_NVIC_PRI_6 (0xFF << 16) // (NVIC) +#define AT91C_NVIC_PRI_7 (0xFF << 24) // (NVIC) +// -------- NVIC_HAND8PR : (NVIC Offset: 0xd1c) System Handlers 8-11 Priority Register -------- +#define AT91C_NVIC_PRI_8 (0xFF << 0) // (NVIC) +#define AT91C_NVIC_PRI_9 (0xFF << 8) // (NVIC) +#define AT91C_NVIC_PRI_10 (0xFF << 16) // (NVIC) +#define AT91C_NVIC_PRI_11 (0xFF << 24) // (NVIC) +// -------- NVIC_HAND12PR : (NVIC Offset: 0xd20) System Handlers 12-15 Priority Register -------- +#define AT91C_NVIC_PRI_12 (0xFF << 0) // (NVIC) +#define AT91C_NVIC_PRI_13 (0xFF << 8) // (NVIC) +#define AT91C_NVIC_PRI_14 (0xFF << 16) // (NVIC) +#define AT91C_NVIC_PRI_15 (0xFF << 24) // (NVIC) +// -------- NVIC_HANDCSR : (NVIC Offset: 0xd24) System Handler Control and State Register -------- +#define AT91C_NVIC_MEMFAULTACT (0x1 << 0) // (NVIC) +#define AT91C_NVIC_BUSFAULTACT (0x1 << 1) // (NVIC) +#define AT91C_NVIC_USGFAULTACT (0x1 << 3) // (NVIC) +#define AT91C_NVIC_SVCALLACT (0x1 << 7) // (NVIC) +#define AT91C_NVIC_MONITORACT (0x1 << 8) // (NVIC) +#define AT91C_NVIC_PENDSVACT (0x1 << 10) // (NVIC) +#define AT91C_NVIC_SYSTICKACT (0x1 << 11) // (NVIC) +#define AT91C_NVIC_USGFAULTPENDED (0x1 << 12) // (NVIC) +#define AT91C_NVIC_MEMFAULTPENDED (0x1 << 13) // (NVIC) +#define AT91C_NVIC_BUSFAULTPENDED (0x1 << 14) // (NVIC) +#define AT91C_NVIC_SVCALLPENDED (0x1 << 15) // (NVIC) +#define AT91C_NVIC_MEMFAULTENA (0x1 << 16) // (NVIC) +#define AT91C_NVIC_BUSFAULTENA (0x1 << 17) // (NVIC) +#define AT91C_NVIC_USGFAULTENA (0x1 << 18) // (NVIC) +// -------- NVIC_CFSR : (NVIC Offset: 0xd28) Configurable Fault Status Registers -------- +#define AT91C_NVIC_MEMMANAGE (0xFF << 0) // (NVIC) +#define AT91C_NVIC_BUSFAULT (0xFF << 8) // (NVIC) +#define AT91C_NVIC_USAGEFAULT (0xFF << 16) // (NVIC) +// -------- NVIC_BFAR : (NVIC Offset: 0xd38) Bus Fault Address Register -------- +#define AT91C_NVIC_IBUSERR (0x1 << 0) // (NVIC) This bit indicates a bus fault on an instruction prefetch +#define AT91C_NVIC_PRECISERR (0x1 << 1) // (NVIC) Precise data access error. The BFAR is written with the faulting address +#define AT91C_NVIC_IMPRECISERR (0x1 << 2) // (NVIC) Imprecise data access error +#define AT91C_NVIC_UNSTKERR (0x1 << 3) // (NVIC) This bit indicates a derived bus fault has occurred on exception return +#define AT91C_NVIC_STKERR (0x1 << 4) // (NVIC) This bit indicates a derived bus fault has occurred on exception entry +#define AT91C_NVIC_BFARVALID (0x1 << 7) // (NVIC) This bit is set if the BFAR register has valid contents +// -------- NVIC_PFR0 : (NVIC Offset: 0xd40) Processor Feature register0 (ID_PFR0) -------- +#define AT91C_NVIC_ID_PFR0_0 (0xF << 0) // (NVIC) State0 (T-bit == 0) +#define AT91C_NVIC_ID_PRF0_1 (0xF << 4) // (NVIC) State1 (T-bit == 1) +// -------- NVIC_PFR1 : (NVIC Offset: 0xd44) Processor Feature register1 (ID_PFR1) -------- +#define AT91C_NVIC_ID_PRF1_MODEL (0xF << 8) // (NVIC) Microcontroller programmer’s model +// -------- NVIC_DFR0 : (NVIC Offset: 0xd48) Debug Feature register0 (ID_DFR0) -------- +#define AT91C_NVIC_ID_DFR0_MODEL (0xF << 20) // (NVIC) Microcontroller Debug Model – memory mapped +// -------- NVIC_MMFR0 : (NVIC Offset: 0xd50) Memory Model Feature register0 (ID_MMFR0) -------- +#define AT91C_NVIC_ID_MMFR0_PMSA (0xF << 4) // (NVIC) Microcontroller Debug Model – memory mapped +#define AT91C_NVIC_ID_MMFR0_CACHE (0xF << 8) // (NVIC) Microcontroller Debug Model – memory mapped + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR NESTED vector Interrupt Controller +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_MPU { + AT91_REG MPU_TYPE; // MPU Type Register + AT91_REG MPU_CTRL; // MPU Control Register + AT91_REG MPU_REG_NB; // MPU Region Number Register + AT91_REG MPU_REG_BASE_ADDR; // MPU Region Base Address Register + AT91_REG MPU_ATTR_SIZE; // MPU Attribute and Size Register + AT91_REG MPU_REG_BASE_ADDR1; // MPU Region Base Address Register alias 1 + AT91_REG MPU_ATTR_SIZE1; // MPU Attribute and Size Register alias 1 + AT91_REG MPU_REG_BASE_ADDR2; // MPU Region Base Address Register alias 2 + AT91_REG MPU_ATTR_SIZE2; // MPU Attribute and Size Register alias 2 + AT91_REG MPU_REG_BASE_ADDR3; // MPU Region Base Address Register alias 3 + AT91_REG MPU_ATTR_SIZE3; // MPU Attribute and Size Register alias 3 +} AT91S_MPU, *AT91PS_MPU; +#else +#define MPU_TYPE (AT91_CAST(AT91_REG *) 0x00000000) // (MPU_TYPE) MPU Type Register +#define MPU_CTRL (AT91_CAST(AT91_REG *) 0x00000004) // (MPU_CTRL) MPU Control Register +#define MPU_REG_NB (AT91_CAST(AT91_REG *) 0x00000008) // (MPU_REG_NB) MPU Region Number Register +#define MPU_REG_BASE_ADDR (AT91_CAST(AT91_REG *) 0x0000000C) // (MPU_REG_BASE_ADDR) MPU Region Base Address Register +#define MPU_ATTR_SIZE (AT91_CAST(AT91_REG *) 0x00000010) // (MPU_ATTR_SIZE) MPU Attribute and Size Register +#define MPU_REG_BASE_ADDR1 (AT91_CAST(AT91_REG *) 0x00000014) // (MPU_REG_BASE_ADDR1) MPU Region Base Address Register alias 1 +#define MPU_ATTR_SIZE1 (AT91_CAST(AT91_REG *) 0x00000018) // (MPU_ATTR_SIZE1) MPU Attribute and Size Register alias 1 +#define MPU_REG_BASE_ADDR2 (AT91_CAST(AT91_REG *) 0x0000001C) // (MPU_REG_BASE_ADDR2) MPU Region Base Address Register alias 2 +#define MPU_ATTR_SIZE2 (AT91_CAST(AT91_REG *) 0x00000020) // (MPU_ATTR_SIZE2) MPU Attribute and Size Register alias 2 +#define MPU_REG_BASE_ADDR3 (AT91_CAST(AT91_REG *) 0x00000024) // (MPU_REG_BASE_ADDR3) MPU Region Base Address Register alias 3 +#define MPU_ATTR_SIZE3 (AT91_CAST(AT91_REG *) 0x00000028) // (MPU_ATTR_SIZE3) MPU Attribute and Size Register alias 3 + +#endif +// -------- MPU_TYPE : (MPU Offset: 0x0) -------- +#define AT91C_MPU_SEPARATE (0x1 << 0) // (MPU) +#define AT91C_MPU_DREGION (0xFF << 8) // (MPU) +#define AT91C_MPU_IREGION (0xFF << 16) // (MPU) +// -------- MPU_CTRL : (MPU Offset: 0x4) -------- +#define AT91C_MPU_ENABLE (0x1 << 0) // (MPU) +#define AT91C_MPU_HFNMIENA (0x1 << 1) // (MPU) +#define AT91C_MPU_PRIVDEFENA (0x1 << 2) // (MPU) +// -------- MPU_REG_NB : (MPU Offset: 0x8) -------- +#define AT91C_MPU_REGION (0xFF << 0) // (MPU) +// -------- MPU_REG_BASE_ADDR : (MPU Offset: 0xc) -------- +#define AT91C_MPU_REG (0xF << 0) // (MPU) +#define AT91C_MPU_VALID (0x1 << 4) // (MPU) +#define AT91C_MPU_ADDR (0x3FFFFFF << 5) // (MPU) +// -------- MPU_ATTR_SIZE : (MPU Offset: 0x10) -------- +#define AT91C_MPU_ENA (0x1 << 0) // (MPU) +#define AT91C_MPU_SIZE (0xF << 1) // (MPU) +#define AT91C_MPU_SRD (0xFF << 8) // (MPU) +#define AT91C_MPU_B (0x1 << 16) // (MPU) +#define AT91C_MPU_C (0x1 << 17) // (MPU) +#define AT91C_MPU_S (0x1 << 18) // (MPU) +#define AT91C_MPU_TEX (0x7 << 19) // (MPU) +#define AT91C_MPU_AP (0x7 << 24) // (MPU) +#define AT91C_MPU_XN (0x7 << 28) // (MPU) + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR CORTEX_M3 Registers +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_CM3 { + AT91_REG CM3_CPUID; // CPU ID Base Register + AT91_REG CM3_ICSR; // Interrupt Control State Register + AT91_REG CM3_VTOR; // Vector Table Offset Register + AT91_REG CM3_AIRCR; // Application Interrupt and Reset Control Register + AT91_REG CM3_SCR; // System Controller Register + AT91_REG CM3_CCR; // Configuration Control Register + AT91_REG CM3_SHPR[3]; // System Handler Priority Register + AT91_REG CM3_SHCSR; // System Handler Control and State Register +} AT91S_CM3, *AT91PS_CM3; +#else +#define CM3_CPUID (AT91_CAST(AT91_REG *) 0x00000000) // (CM3_CPUID) CPU ID Base Register +#define CM3_ICSR (AT91_CAST(AT91_REG *) 0x00000004) // (CM3_ICSR) Interrupt Control State Register +#define CM3_VTOR (AT91_CAST(AT91_REG *) 0x00000008) // (CM3_VTOR) Vector Table Offset Register +#define CM3_AIRCR (AT91_CAST(AT91_REG *) 0x0000000C) // (CM3_AIRCR) Application Interrupt and Reset Control Register +#define CM3_SCR (AT91_CAST(AT91_REG *) 0x00000010) // (CM3_SCR) System Controller Register +#define CM3_CCR (AT91_CAST(AT91_REG *) 0x00000014) // (CM3_CCR) Configuration Control Register +#define CM3_SHPR (AT91_CAST(AT91_REG *) 0x00000018) // (CM3_SHPR) System Handler Priority Register +#define CM3_SHCSR (AT91_CAST(AT91_REG *) 0x00000024) // (CM3_SHCSR) System Handler Control and State Register + +#endif +// -------- CM3_CPUID : (CM3 Offset: 0x0) -------- +// -------- CM3_AIRCR : (CM3 Offset: 0xc) -------- +#define AT91C_CM3_SYSRESETREQ (0x1 << 2) // (CM3) A reset is requested by the processor. +// -------- CM3_SCR : (CM3 Offset: 0x10) -------- +#define AT91C_CM3_SLEEPONEXIT (0x1 << 1) // (CM3) Sleep on exit when returning from Handler mode to Thread mode. Enables interrupt driven applications to avoid returning to empty main application. +#define AT91C_CM3_SLEEPDEEP (0x1 << 2) // (CM3) Sleep deep bit. +#define AT91C_CM3_SEVONPEND (0x1 << 4) // (CM3) When enabled, this causes WFE to wake up when an interrupt moves from inactive to pended. +// -------- CM3_SHCSR : (CM3 Offset: 0x24) -------- +#define AT91C_CM3_SYSTICKACT (0x1 << 11) // (CM3) Reads as 1 if SysTick is active. + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Peripheral DMA Controller +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_PDC { + AT91_REG PDC_RPR; // Receive Pointer Register + AT91_REG PDC_RCR; // Receive Counter Register + AT91_REG PDC_TPR; // Transmit Pointer Register + AT91_REG PDC_TCR; // Transmit Counter Register + AT91_REG PDC_RNPR; // Receive Next Pointer Register + AT91_REG PDC_RNCR; // Receive Next Counter Register + AT91_REG PDC_TNPR; // Transmit Next Pointer Register + AT91_REG PDC_TNCR; // Transmit Next Counter Register + AT91_REG PDC_PTCR; // PDC Transfer Control Register + AT91_REG PDC_PTSR; // PDC Transfer Status Register +} AT91S_PDC, *AT91PS_PDC; +#else +#define PDC_RPR (AT91_CAST(AT91_REG *) 0x00000000) // (PDC_RPR) Receive Pointer Register +#define PDC_RCR (AT91_CAST(AT91_REG *) 0x00000004) // (PDC_RCR) Receive Counter Register +#define PDC_TPR (AT91_CAST(AT91_REG *) 0x00000008) // (PDC_TPR) Transmit Pointer Register +#define PDC_TCR (AT91_CAST(AT91_REG *) 0x0000000C) // (PDC_TCR) Transmit Counter Register +#define PDC_RNPR (AT91_CAST(AT91_REG *) 0x00000010) // (PDC_RNPR) Receive Next Pointer Register +#define PDC_RNCR (AT91_CAST(AT91_REG *) 0x00000014) // (PDC_RNCR) Receive Next Counter Register +#define PDC_TNPR (AT91_CAST(AT91_REG *) 0x00000018) // (PDC_TNPR) Transmit Next Pointer Register +#define PDC_TNCR (AT91_CAST(AT91_REG *) 0x0000001C) // (PDC_TNCR) Transmit Next Counter Register +#define PDC_PTCR (AT91_CAST(AT91_REG *) 0x00000020) // (PDC_PTCR) PDC Transfer Control Register +#define PDC_PTSR (AT91_CAST(AT91_REG *) 0x00000024) // (PDC_PTSR) PDC Transfer Status Register + +#endif +// -------- PDC_PTCR : (PDC Offset: 0x20) PDC Transfer Control Register -------- +#define AT91C_PDC_RXTEN (0x1 << 0) // (PDC) Receiver Transfer Enable +#define AT91C_PDC_RXTDIS (0x1 << 1) // (PDC) Receiver Transfer Disable +#define AT91C_PDC_TXTEN (0x1 << 8) // (PDC) Transmitter Transfer Enable +#define AT91C_PDC_TXTDIS (0x1 << 9) // (PDC) Transmitter Transfer Disable +// -------- PDC_PTSR : (PDC Offset: 0x24) PDC Transfer Status Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Debug Unit +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_DBGU { + AT91_REG DBGU_CR; // Control Register + AT91_REG DBGU_MR; // Mode Register + AT91_REG DBGU_IER; // Interrupt Enable Register + AT91_REG DBGU_IDR; // Interrupt Disable Register + AT91_REG DBGU_IMR; // Interrupt Mask Register + AT91_REG DBGU_CSR; // Channel Status Register + AT91_REG DBGU_RHR; // Receiver Holding Register + AT91_REG DBGU_THR; // Transmitter Holding Register + AT91_REG DBGU_BRGR; // Baud Rate Generator Register + AT91_REG Reserved0[9]; // + AT91_REG DBGU_FNTR; // Force NTRST Register + AT91_REG Reserved1[40]; // + AT91_REG DBGU_ADDRSIZE; // DBGU ADDRSIZE REGISTER + AT91_REG DBGU_IPNAME1; // DBGU IPNAME1 REGISTER + AT91_REG DBGU_IPNAME2; // DBGU IPNAME2 REGISTER + AT91_REG DBGU_FEATURES; // DBGU FEATURES REGISTER + AT91_REG DBGU_VER; // DBGU VERSION REGISTER + AT91_REG DBGU_RPR; // Receive Pointer Register + AT91_REG DBGU_RCR; // Receive Counter Register + AT91_REG DBGU_TPR; // Transmit Pointer Register + AT91_REG DBGU_TCR; // Transmit Counter Register + AT91_REG DBGU_RNPR; // Receive Next Pointer Register + AT91_REG DBGU_RNCR; // Receive Next Counter Register + AT91_REG DBGU_TNPR; // Transmit Next Pointer Register + AT91_REG DBGU_TNCR; // Transmit Next Counter Register + AT91_REG DBGU_PTCR; // PDC Transfer Control Register + AT91_REG DBGU_PTSR; // PDC Transfer Status Register + AT91_REG Reserved2[6]; // + AT91_REG DBGU_CIDR; // Chip ID Register + AT91_REG DBGU_EXID; // Chip ID Extension Register +} AT91S_DBGU, *AT91PS_DBGU; +#else +#define DBGU_CR (AT91_CAST(AT91_REG *) 0x00000000) // (DBGU_CR) Control Register +#define DBGU_MR (AT91_CAST(AT91_REG *) 0x00000004) // (DBGU_MR) Mode Register +#define DBGU_IER (AT91_CAST(AT91_REG *) 0x00000008) // (DBGU_IER) Interrupt Enable Register +#define DBGU_IDR (AT91_CAST(AT91_REG *) 0x0000000C) // (DBGU_IDR) Interrupt Disable Register +#define DBGU_IMR (AT91_CAST(AT91_REG *) 0x00000010) // (DBGU_IMR) Interrupt Mask Register +#define DBGU_CSR (AT91_CAST(AT91_REG *) 0x00000014) // (DBGU_CSR) Channel Status Register +#define DBGU_RHR (AT91_CAST(AT91_REG *) 0x00000018) // (DBGU_RHR) Receiver Holding Register +#define DBGU_THR (AT91_CAST(AT91_REG *) 0x0000001C) // (DBGU_THR) Transmitter Holding Register +#define DBGU_BRGR (AT91_CAST(AT91_REG *) 0x00000020) // (DBGU_BRGR) Baud Rate Generator Register +#define DBGU_FNTR (AT91_CAST(AT91_REG *) 0x00000048) // (DBGU_FNTR) Force NTRST Register +#define DBGU_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (DBGU_ADDRSIZE) DBGU ADDRSIZE REGISTER +#define DBGU_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (DBGU_IPNAME1) DBGU IPNAME1 REGISTER +#define DBGU_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (DBGU_IPNAME2) DBGU IPNAME2 REGISTER +#define DBGU_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (DBGU_FEATURES) DBGU FEATURES REGISTER +#define DBGU_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (DBGU_VER) DBGU VERSION REGISTER +#define DBGU_CIDR (AT91_CAST(AT91_REG *) 0x00000140) // (DBGU_CIDR) Chip ID Register +#define DBGU_EXID (AT91_CAST(AT91_REG *) 0x00000144) // (DBGU_EXID) Chip ID Extension Register + +#endif +// -------- DBGU_CR : (DBGU Offset: 0x0) Debug Unit Control Register -------- +#define AT91C_US_RSTRX (0x1 << 2) // (DBGU) Reset Receiver +#define AT91C_US_RSTTX (0x1 << 3) // (DBGU) Reset Transmitter +#define AT91C_US_RXEN (0x1 << 4) // (DBGU) Receiver Enable +#define AT91C_US_RXDIS (0x1 << 5) // (DBGU) Receiver Disable +#define AT91C_US_TXEN (0x1 << 6) // (DBGU) Transmitter Enable +#define AT91C_US_TXDIS (0x1 << 7) // (DBGU) Transmitter Disable +#define AT91C_US_RSTSTA (0x1 << 8) // (DBGU) Reset Status Bits +// -------- DBGU_MR : (DBGU Offset: 0x4) Debug Unit Mode Register -------- +#define AT91C_US_PAR (0x7 << 9) // (DBGU) Parity type +#define AT91C_US_PAR_EVEN (0x0 << 9) // (DBGU) Even Parity +#define AT91C_US_PAR_ODD (0x1 << 9) // (DBGU) Odd Parity +#define AT91C_US_PAR_SPACE (0x2 << 9) // (DBGU) Parity forced to 0 (Space) +#define AT91C_US_PAR_MARK (0x3 << 9) // (DBGU) Parity forced to 1 (Mark) +#define AT91C_US_PAR_NONE (0x4 << 9) // (DBGU) No Parity +#define AT91C_US_PAR_MULTI_DROP (0x6 << 9) // (DBGU) Multi-drop mode +#define AT91C_US_CHMODE (0x3 << 14) // (DBGU) Channel Mode +#define AT91C_US_CHMODE_NORMAL (0x0 << 14) // (DBGU) Normal Mode: The USART channel operates as an RX/TX USART. +#define AT91C_US_CHMODE_AUTO (0x1 << 14) // (DBGU) Automatic Echo: Receiver Data Input is connected to the TXD pin. +#define AT91C_US_CHMODE_LOCAL (0x2 << 14) // (DBGU) Local Loopback: Transmitter Output Signal is connected to Receiver Input Signal. +#define AT91C_US_CHMODE_REMOTE (0x3 << 14) // (DBGU) Remote Loopback: RXD pin is internally connected to TXD pin. +// -------- DBGU_IER : (DBGU Offset: 0x8) Debug Unit Interrupt Enable Register -------- +#define AT91C_US_RXRDY (0x1 << 0) // (DBGU) RXRDY Interrupt +#define AT91C_US_TXRDY (0x1 << 1) // (DBGU) TXRDY Interrupt +#define AT91C_US_ENDRX (0x1 << 3) // (DBGU) End of Receive Transfer Interrupt +#define AT91C_US_ENDTX (0x1 << 4) // (DBGU) End of Transmit Interrupt +#define AT91C_US_OVRE (0x1 << 5) // (DBGU) Overrun Interrupt +#define AT91C_US_FRAME (0x1 << 6) // (DBGU) Framing Error Interrupt +#define AT91C_US_PARE (0x1 << 7) // (DBGU) Parity Error Interrupt +#define AT91C_US_TXEMPTY (0x1 << 9) // (DBGU) TXEMPTY Interrupt +#define AT91C_US_TXBUFE (0x1 << 11) // (DBGU) TXBUFE Interrupt +#define AT91C_US_RXBUFF (0x1 << 12) // (DBGU) RXBUFF Interrupt +#define AT91C_US_COMM_TX (0x1 << 30) // (DBGU) COMM_TX Interrupt +#define AT91C_US_COMM_RX (0x1 << 31) // (DBGU) COMM_RX Interrupt +// -------- DBGU_IDR : (DBGU Offset: 0xc) Debug Unit Interrupt Disable Register -------- +// -------- DBGU_IMR : (DBGU Offset: 0x10) Debug Unit Interrupt Mask Register -------- +// -------- DBGU_CSR : (DBGU Offset: 0x14) Debug Unit Channel Status Register -------- +// -------- DBGU_FNTR : (DBGU Offset: 0x48) Debug Unit FORCE_NTRST Register -------- +#define AT91C_US_FORCE_NTRST (0x1 << 0) // (DBGU) Force NTRST in JTAG + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Parallel Input Output Controler +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_PIO { + AT91_REG PIO_PER; // PIO Enable Register + AT91_REG PIO_PDR; // PIO Disable Register + AT91_REG PIO_PSR; // PIO Status Register + AT91_REG Reserved0[1]; // + AT91_REG PIO_OER; // Output Enable Register + AT91_REG PIO_ODR; // Output Disable Registerr + AT91_REG PIO_OSR; // Output Status Register + AT91_REG Reserved1[1]; // + AT91_REG PIO_IFER; // Input Filter Enable Register + AT91_REG PIO_IFDR; // Input Filter Disable Register + AT91_REG PIO_IFSR; // Input Filter Status Register + AT91_REG Reserved2[1]; // + AT91_REG PIO_SODR; // Set Output Data Register + AT91_REG PIO_CODR; // Clear Output Data Register + AT91_REG PIO_ODSR; // Output Data Status Register + AT91_REG PIO_PDSR; // Pin Data Status Register + AT91_REG PIO_IER; // Interrupt Enable Register + AT91_REG PIO_IDR; // Interrupt Disable Register + AT91_REG PIO_IMR; // Interrupt Mask Register + AT91_REG PIO_ISR; // Interrupt Status Register + AT91_REG PIO_MDER; // Multi-driver Enable Register + AT91_REG PIO_MDDR; // Multi-driver Disable Register + AT91_REG PIO_MDSR; // Multi-driver Status Register + AT91_REG Reserved3[1]; // + AT91_REG PIO_PPUDR; // Pull-up Disable Register + AT91_REG PIO_PPUER; // Pull-up Enable Register + AT91_REG PIO_PPUSR; // Pull-up Status Register + AT91_REG Reserved4[1]; // + AT91_REG PIO_ABSR; // Peripheral AB Select Register + AT91_REG Reserved5[3]; // + AT91_REG PIO_SCIFSR; // System Clock Glitch Input Filter Select Register + AT91_REG PIO_DIFSR; // Debouncing Input Filter Select Register + AT91_REG PIO_IFDGSR; // Glitch or Debouncing Input Filter Clock Selection Status Register + AT91_REG PIO_SCDR; // Slow Clock Divider Debouncing Register + AT91_REG Reserved6[4]; // + AT91_REG PIO_OWER; // Output Write Enable Register + AT91_REG PIO_OWDR; // Output Write Disable Register + AT91_REG PIO_OWSR; // Output Write Status Register + AT91_REG Reserved7[1]; // + AT91_REG PIO_AIMER; // Additional Interrupt Modes Enable Register + AT91_REG PIO_AIMDR; // Additional Interrupt Modes Disables Register + AT91_REG PIO_AIMMR; // Additional Interrupt Modes Mask Register + AT91_REG Reserved8[1]; // + AT91_REG PIO_ESR; // Edge Select Register + AT91_REG PIO_LSR; // Level Select Register + AT91_REG PIO_ELSR; // Edge/Level Status Register + AT91_REG Reserved9[1]; // + AT91_REG PIO_FELLSR; // Falling Edge/Low Level Select Register + AT91_REG PIO_REHLSR; // Rising Edge/ High Level Select Register + AT91_REG PIO_FRLHSR; // Fall/Rise - Low/High Status Register + AT91_REG Reserved10[1]; // + AT91_REG PIO_LOCKSR; // Lock Status Register + AT91_REG Reserved11[6]; // + AT91_REG PIO_VER; // PIO VERSION REGISTER + AT91_REG Reserved12[8]; // + AT91_REG PIO_KER; // Keypad Controller Enable Register + AT91_REG PIO_KRCR; // Keypad Controller Row Column Register + AT91_REG PIO_KDR; // Keypad Controller Debouncing Register + AT91_REG Reserved13[1]; // + AT91_REG PIO_KIER; // Keypad Controller Interrupt Enable Register + AT91_REG PIO_KIDR; // Keypad Controller Interrupt Disable Register + AT91_REG PIO_KIMR; // Keypad Controller Interrupt Mask Register + AT91_REG PIO_KSR; // Keypad Controller Status Register + AT91_REG PIO_KKPR; // Keypad Controller Key Press Register + AT91_REG PIO_KKRR; // Keypad Controller Key Release Register +} AT91S_PIO, *AT91PS_PIO; +#else +#define PIO_PER (AT91_CAST(AT91_REG *) 0x00000000) // (PIO_PER) PIO Enable Register +#define PIO_PDR (AT91_CAST(AT91_REG *) 0x00000004) // (PIO_PDR) PIO Disable Register +#define PIO_PSR (AT91_CAST(AT91_REG *) 0x00000008) // (PIO_PSR) PIO Status Register +#define PIO_OER (AT91_CAST(AT91_REG *) 0x00000010) // (PIO_OER) Output Enable Register +#define PIO_ODR (AT91_CAST(AT91_REG *) 0x00000014) // (PIO_ODR) Output Disable Registerr +#define PIO_OSR (AT91_CAST(AT91_REG *) 0x00000018) // (PIO_OSR) Output Status Register +#define PIO_IFER (AT91_CAST(AT91_REG *) 0x00000020) // (PIO_IFER) Input Filter Enable Register +#define PIO_IFDR (AT91_CAST(AT91_REG *) 0x00000024) // (PIO_IFDR) Input Filter Disable Register +#define PIO_IFSR (AT91_CAST(AT91_REG *) 0x00000028) // (PIO_IFSR) Input Filter Status Register +#define PIO_SODR (AT91_CAST(AT91_REG *) 0x00000030) // (PIO_SODR) Set Output Data Register +#define PIO_CODR (AT91_CAST(AT91_REG *) 0x00000034) // (PIO_CODR) Clear Output Data Register +#define PIO_ODSR (AT91_CAST(AT91_REG *) 0x00000038) // (PIO_ODSR) Output Data Status Register +#define PIO_PDSR (AT91_CAST(AT91_REG *) 0x0000003C) // (PIO_PDSR) Pin Data Status Register +#define PIO_IER (AT91_CAST(AT91_REG *) 0x00000040) // (PIO_IER) Interrupt Enable Register +#define PIO_IDR (AT91_CAST(AT91_REG *) 0x00000044) // (PIO_IDR) Interrupt Disable Register +#define PIO_IMR (AT91_CAST(AT91_REG *) 0x00000048) // (PIO_IMR) Interrupt Mask Register +#define PIO_ISR (AT91_CAST(AT91_REG *) 0x0000004C) // (PIO_ISR) Interrupt Status Register +#define PIO_MDER (AT91_CAST(AT91_REG *) 0x00000050) // (PIO_MDER) Multi-driver Enable Register +#define PIO_MDDR (AT91_CAST(AT91_REG *) 0x00000054) // (PIO_MDDR) Multi-driver Disable Register +#define PIO_MDSR (AT91_CAST(AT91_REG *) 0x00000058) // (PIO_MDSR) Multi-driver Status Register +#define PIO_PPUDR (AT91_CAST(AT91_REG *) 0x00000060) // (PIO_PPUDR) Pull-up Disable Register +#define PIO_PPUER (AT91_CAST(AT91_REG *) 0x00000064) // (PIO_PPUER) Pull-up Enable Register +#define PIO_PPUSR (AT91_CAST(AT91_REG *) 0x00000068) // (PIO_PPUSR) Pull-up Status Register +#define PIO_ABSR (AT91_CAST(AT91_REG *) 0x00000070) // (PIO_ABSR) Peripheral AB Select Register +#define PIO_SCIFSR (AT91_CAST(AT91_REG *) 0x00000080) // (PIO_SCIFSR) System Clock Glitch Input Filter Select Register +#define PIO_DIFSR (AT91_CAST(AT91_REG *) 0x00000084) // (PIO_DIFSR) Debouncing Input Filter Select Register +#define PIO_IFDGSR (AT91_CAST(AT91_REG *) 0x00000088) // (PIO_IFDGSR) Glitch or Debouncing Input Filter Clock Selection Status Register +#define PIO_SCDR (AT91_CAST(AT91_REG *) 0x0000008C) // (PIO_SCDR) Slow Clock Divider Debouncing Register +#define PIO_OWER (AT91_CAST(AT91_REG *) 0x000000A0) // (PIO_OWER) Output Write Enable Register +#define PIO_OWDR (AT91_CAST(AT91_REG *) 0x000000A4) // (PIO_OWDR) Output Write Disable Register +#define PIO_OWSR (AT91_CAST(AT91_REG *) 0x000000A8) // (PIO_OWSR) Output Write Status Register +#define PIO_AIMER (AT91_CAST(AT91_REG *) 0x000000B0) // (PIO_AIMER) Additional Interrupt Modes Enable Register +#define PIO_AIMDR (AT91_CAST(AT91_REG *) 0x000000B4) // (PIO_AIMDR) Additional Interrupt Modes Disables Register +#define PIO_AIMMR (AT91_CAST(AT91_REG *) 0x000000B8) // (PIO_AIMMR) Additional Interrupt Modes Mask Register +#define PIO_ESR (AT91_CAST(AT91_REG *) 0x000000C0) // (PIO_ESR) Edge Select Register +#define PIO_LSR (AT91_CAST(AT91_REG *) 0x000000C4) // (PIO_LSR) Level Select Register +#define PIO_ELSR (AT91_CAST(AT91_REG *) 0x000000C8) // (PIO_ELSR) Edge/Level Status Register +#define PIO_FELLSR (AT91_CAST(AT91_REG *) 0x000000D0) // (PIO_FELLSR) Falling Edge/Low Level Select Register +#define PIO_REHLSR (AT91_CAST(AT91_REG *) 0x000000D4) // (PIO_REHLSR) Rising Edge/ High Level Select Register +#define PIO_FRLHSR (AT91_CAST(AT91_REG *) 0x000000D8) // (PIO_FRLHSR) Fall/Rise - Low/High Status Register +#define PIO_LOCKSR (AT91_CAST(AT91_REG *) 0x000000E0) // (PIO_LOCKSR) Lock Status Register +#define PIO_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (PIO_VER) PIO VERSION REGISTER +#define PIO_KER (AT91_CAST(AT91_REG *) 0x00000120) // (PIO_KER) Keypad Controller Enable Register +#define PIO_KRCR (AT91_CAST(AT91_REG *) 0x00000124) // (PIO_KRCR) Keypad Controller Row Column Register +#define PIO_KDR (AT91_CAST(AT91_REG *) 0x00000128) // (PIO_KDR) Keypad Controller Debouncing Register +#define PIO_KIER (AT91_CAST(AT91_REG *) 0x00000130) // (PIO_KIER) Keypad Controller Interrupt Enable Register +#define PIO_KIDR (AT91_CAST(AT91_REG *) 0x00000134) // (PIO_KIDR) Keypad Controller Interrupt Disable Register +#define PIO_KIMR (AT91_CAST(AT91_REG *) 0x00000138) // (PIO_KIMR) Keypad Controller Interrupt Mask Register +#define PIO_KSR (AT91_CAST(AT91_REG *) 0x0000013C) // (PIO_KSR) Keypad Controller Status Register +#define PIO_KKPR (AT91_CAST(AT91_REG *) 0x00000140) // (PIO_KKPR) Keypad Controller Key Press Register +#define PIO_KKRR (AT91_CAST(AT91_REG *) 0x00000144) // (PIO_KKRR) Keypad Controller Key Release Register + +#endif +// -------- PIO_KER : (PIO Offset: 0x120) Keypad Controller Enable Register -------- +#define AT91C_PIO_KCE (0x1 << 0) // (PIO) Keypad Controller Enable +// -------- PIO_KRCR : (PIO Offset: 0x124) Keypad Controller Row Column Register -------- +#define AT91C_PIO_NBR (0x7 << 0) // (PIO) Number of Columns of the Keypad Matrix +#define AT91C_PIO_NBC (0x7 << 8) // (PIO) Number of Rows of the Keypad Matrix +// -------- PIO_KDR : (PIO Offset: 0x128) Keypad Controller Debouncing Register -------- +#define AT91C_PIO_DBC (0x3FF << 0) // (PIO) Debouncing Value +// -------- PIO_KIER : (PIO Offset: 0x130) Keypad Controller Interrupt Enable Register -------- +#define AT91C_PIO_KPR (0x1 << 0) // (PIO) Key Press Interrupt Enable +#define AT91C_PIO_KRL (0x1 << 1) // (PIO) Key Release Interrupt Enable +// -------- PIO_KIDR : (PIO Offset: 0x134) Keypad Controller Interrupt Disable Register -------- +// -------- PIO_KIMR : (PIO Offset: 0x138) Keypad Controller Interrupt Mask Register -------- +// -------- PIO_KSR : (PIO Offset: 0x13c) Keypad Controller Status Register -------- +#define AT91C_PIO_NBKPR (0x3 << 8) // (PIO) Number of Simultaneous Key Presses +#define AT91C_PIO_NBKRL (0x3 << 16) // (PIO) Number of Simultaneous Key Releases +// -------- PIO_KKPR : (PIO Offset: 0x140) Keypad Controller Key Press Register -------- +#define AT91C_KEY0ROW (0x7 << 0) // (PIO) Row index of the first detected Key Press +#define AT91C_KEY0COL (0x7 << 4) // (PIO) Column index of the first detected Key Press +#define AT91C_KEY1ROW (0x7 << 8) // (PIO) Row index of the second detected Key Press +#define AT91C_KEY1COL (0x7 << 12) // (PIO) Column index of the second detected Key Press +#define AT91C_KEY2ROW (0x7 << 16) // (PIO) Row index of the third detected Key Press +#define AT91C_KEY2COL (0x7 << 20) // (PIO) Column index of the third detected Key Press +#define AT91C_KEY3ROW (0x7 << 24) // (PIO) Row index of the fourth detected Key Press +#define AT91C_KEY3COL (0x7 << 28) // (PIO) Column index of the fourth detected Key Press +// -------- PIO_KKRR : (PIO Offset: 0x144) Keypad Controller Key Release Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Power Management Controler +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_PMC { + AT91_REG PMC_SCER; // System Clock Enable Register + AT91_REG PMC_SCDR; // System Clock Disable Register + AT91_REG PMC_SCSR; // System Clock Status Register + AT91_REG Reserved0[1]; // + AT91_REG PMC_PCER; // Peripheral Clock Enable Register + AT91_REG PMC_PCDR; // Peripheral Clock Disable Register + AT91_REG PMC_PCSR; // Peripheral Clock Status Register + AT91_REG PMC_UCKR; // UTMI Clock Configuration Register + AT91_REG PMC_MOR; // Main Oscillator Register + AT91_REG PMC_MCFR; // Main Clock Frequency Register + AT91_REG PMC_PLLAR; // PLL Register + AT91_REG Reserved1[1]; // + AT91_REG PMC_MCKR; // Master Clock Register + AT91_REG Reserved2[3]; // + AT91_REG PMC_PCKR[8]; // Programmable Clock Register + AT91_REG PMC_IER; // Interrupt Enable Register + AT91_REG PMC_IDR; // Interrupt Disable Register + AT91_REG PMC_SR; // Status Register + AT91_REG PMC_IMR; // Interrupt Mask Register + AT91_REG PMC_FSMR; // Fast Startup Mode Register + AT91_REG PMC_FSPR; // Fast Startup Polarity Register + AT91_REG PMC_FOCR; // Fault Output Clear Register + AT91_REG Reserved3[28]; // + AT91_REG PMC_ADDRSIZE; // PMC ADDRSIZE REGISTER + AT91_REG PMC_IPNAME1; // PMC IPNAME1 REGISTER + AT91_REG PMC_IPNAME2; // PMC IPNAME2 REGISTER + AT91_REG PMC_FEATURES; // PMC FEATURES REGISTER + AT91_REG PMC_VER; // APMC VERSION REGISTER +} AT91S_PMC, *AT91PS_PMC; +#else +#define PMC_SCER (AT91_CAST(AT91_REG *) 0x00000000) // (PMC_SCER) System Clock Enable Register +#define PMC_SCDR (AT91_CAST(AT91_REG *) 0x00000004) // (PMC_SCDR) System Clock Disable Register +#define PMC_SCSR (AT91_CAST(AT91_REG *) 0x00000008) // (PMC_SCSR) System Clock Status Register +#define PMC_PCER (AT91_CAST(AT91_REG *) 0x00000010) // (PMC_PCER) Peripheral Clock Enable Register +#define PMC_PCDR (AT91_CAST(AT91_REG *) 0x00000014) // (PMC_PCDR) Peripheral Clock Disable Register +#define PMC_PCSR (AT91_CAST(AT91_REG *) 0x00000018) // (PMC_PCSR) Peripheral Clock Status Register +#define CKGR_UCKR (AT91_CAST(AT91_REG *) 0x0000001C) // (CKGR_UCKR) UTMI Clock Configuration Register +#define CKGR_MOR (AT91_CAST(AT91_REG *) 0x00000020) // (CKGR_MOR) Main Oscillator Register +#define CKGR_MCFR (AT91_CAST(AT91_REG *) 0x00000024) // (CKGR_MCFR) Main Clock Frequency Register +#define CKGR_PLLAR (AT91_CAST(AT91_REG *) 0x00000028) // (CKGR_PLLAR) PLL Register +#define PMC_MCKR (AT91_CAST(AT91_REG *) 0x00000030) // (PMC_MCKR) Master Clock Register +#define PMC_PCKR (AT91_CAST(AT91_REG *) 0x00000040) // (PMC_PCKR) Programmable Clock Register +#define PMC_IER (AT91_CAST(AT91_REG *) 0x00000060) // (PMC_IER) Interrupt Enable Register +#define PMC_IDR (AT91_CAST(AT91_REG *) 0x00000064) // (PMC_IDR) Interrupt Disable Register +#define PMC_SR (AT91_CAST(AT91_REG *) 0x00000068) // (PMC_SR) Status Register +#define PMC_IMR (AT91_CAST(AT91_REG *) 0x0000006C) // (PMC_IMR) Interrupt Mask Register +#define PMC_FSMR (AT91_CAST(AT91_REG *) 0x00000070) // (PMC_FSMR) Fast Startup Mode Register +#define PMC_FSPR (AT91_CAST(AT91_REG *) 0x00000074) // (PMC_FSPR) Fast Startup Polarity Register +#define PMC_FOCR (AT91_CAST(AT91_REG *) 0x00000078) // (PMC_FOCR) Fault Output Clear Register +#define PMC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (PMC_ADDRSIZE) PMC ADDRSIZE REGISTER +#define PMC_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (PMC_IPNAME1) PMC IPNAME1 REGISTER +#define PMC_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (PMC_IPNAME2) PMC IPNAME2 REGISTER +#define PMC_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (PMC_FEATURES) PMC FEATURES REGISTER +#define PMC_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (PMC_VER) APMC VERSION REGISTER + +#endif +// -------- PMC_SCER : (PMC Offset: 0x0) System Clock Enable Register -------- +#define AT91C_PMC_PCK (0x1 << 0) // (PMC) Processor Clock +#define AT91C_PMC_PCK0 (0x1 << 8) // (PMC) Programmable Clock Output +#define AT91C_PMC_PCK1 (0x1 << 9) // (PMC) Programmable Clock Output +#define AT91C_PMC_PCK2 (0x1 << 10) // (PMC) Programmable Clock Output +// -------- PMC_SCDR : (PMC Offset: 0x4) System Clock Disable Register -------- +// -------- PMC_SCSR : (PMC Offset: 0x8) System Clock Status Register -------- +// -------- CKGR_UCKR : (PMC Offset: 0x1c) UTMI Clock Configuration Register -------- +#define AT91C_CKGR_UPLLEN (0x1 << 16) // (PMC) UTMI PLL Enable +#define AT91C_CKGR_UPLLEN_DISABLED (0x0 << 16) // (PMC) The UTMI PLL is disabled +#define AT91C_CKGR_UPLLEN_ENABLED (0x1 << 16) // (PMC) The UTMI PLL is enabled +#define AT91C_CKGR_UPLLCOUNT (0xF << 20) // (PMC) UTMI Oscillator Start-up Time +#define AT91C_CKGR_BIASEN (0x1 << 24) // (PMC) UTMI BIAS Enable +#define AT91C_CKGR_BIASEN_DISABLED (0x0 << 24) // (PMC) The UTMI BIAS is disabled +#define AT91C_CKGR_BIASEN_ENABLED (0x1 << 24) // (PMC) The UTMI BIAS is enabled +#define AT91C_CKGR_BIASCOUNT (0xF << 28) // (PMC) UTMI BIAS Start-up Time +// -------- CKGR_MOR : (PMC Offset: 0x20) Main Oscillator Register -------- +#define AT91C_CKGR_MOSCXTEN (0x1 << 0) // (PMC) Main Crystal Oscillator Enable +#define AT91C_CKGR_MOSCXTBY (0x1 << 1) // (PMC) Main Crystal Oscillator Bypass +#define AT91C_CKGR_WAITMODE (0x1 << 2) // (PMC) Main Crystal Oscillator Bypass +#define AT91C_CKGR_MOSCRCEN (0x1 << 3) // (PMC) Main On-Chip RC Oscillator Enable +#define AT91C_CKGR_MOSCRCF (0x7 << 4) // (PMC) Main On-Chip RC Oscillator Frequency Selection +#define AT91C_CKGR_MOSCXTST (0xFF << 8) // (PMC) Main Crystal Oscillator Start-up Time +#define AT91C_CKGR_KEY (0xFF << 16) // (PMC) Clock Generator Controller Writing Protection Key +#define AT91C_CKGR_MOSCSEL (0x1 << 24) // (PMC) Main Oscillator Selection +#define AT91C_CKGR_CFDEN (0x1 << 25) // (PMC) Clock Failure Detector Enable +// -------- CKGR_MCFR : (PMC Offset: 0x24) Main Clock Frequency Register -------- +#define AT91C_CKGR_MAINF (0xFFFF << 0) // (PMC) Main Clock Frequency +#define AT91C_CKGR_MAINRDY (0x1 << 16) // (PMC) Main Clock Ready +// -------- CKGR_PLLAR : (PMC Offset: 0x28) PLL A Register -------- +#define AT91C_CKGR_DIVA (0xFF << 0) // (PMC) Divider Selected +#define AT91C_CKGR_DIVA_0 (0x0) // (PMC) Divider output is 0 +#define AT91C_CKGR_DIVA_BYPASS (0x1) // (PMC) Divider is bypassed +#define AT91C_CKGR_PLLACOUNT (0x3F << 8) // (PMC) PLLA Counter +#define AT91C_CKGR_STMODE (0x3 << 14) // (PMC) Start Mode +#define AT91C_CKGR_STMODE_0 (0x0 << 14) // (PMC) Fast startup +#define AT91C_CKGR_STMODE_1 (0x1 << 14) // (PMC) Reserved +#define AT91C_CKGR_STMODE_2 (0x2 << 14) // (PMC) Normal startup +#define AT91C_CKGR_STMODE_3 (0x3 << 14) // (PMC) Reserved +#define AT91C_CKGR_MULA (0x7FF << 16) // (PMC) PLL Multiplier +#define AT91C_CKGR_SRC (0x1 << 29) // (PMC) +// -------- PMC_MCKR : (PMC Offset: 0x30) Master Clock Register -------- +#define AT91C_PMC_CSS (0x7 << 0) // (PMC) Programmable Clock Selection +#define AT91C_PMC_CSS_SLOW_CLK (0x0) // (PMC) Slow Clock is selected +#define AT91C_PMC_CSS_MAIN_CLK (0x1) // (PMC) Main Clock is selected +#define AT91C_PMC_CSS_PLLA_CLK (0x2) // (PMC) Clock from PLL A is selected +#define AT91C_PMC_CSS_UPLL_CLK (0x3) // (PMC) Clock from UPLL is selected +#define AT91C_PMC_CSS_SYS_CLK (0x4) // (PMC) System clock is selected +#define AT91C_PMC_PRES (0x7 << 4) // (PMC) Programmable Clock Prescaler +#define AT91C_PMC_PRES_CLK (0x0 << 4) // (PMC) Selected clock +#define AT91C_PMC_PRES_CLK_2 (0x1 << 4) // (PMC) Selected clock divided by 2 +#define AT91C_PMC_PRES_CLK_4 (0x2 << 4) // (PMC) Selected clock divided by 4 +#define AT91C_PMC_PRES_CLK_8 (0x3 << 4) // (PMC) Selected clock divided by 8 +#define AT91C_PMC_PRES_CLK_16 (0x4 << 4) // (PMC) Selected clock divided by 16 +#define AT91C_PMC_PRES_CLK_32 (0x5 << 4) // (PMC) Selected clock divided by 32 +#define AT91C_PMC_PRES_CLK_64 (0x6 << 4) // (PMC) Selected clock divided by 64 +#define AT91C_PMC_PRES_CLK_6 (0x7 << 4) // (PMC) Selected clock divided by 6 +// -------- PMC_PCKR : (PMC Offset: 0x40) Programmable Clock Register -------- +// -------- PMC_IER : (PMC Offset: 0x60) PMC Interrupt Enable Register -------- +#define AT91C_PMC_MOSCXTS (0x1 << 0) // (PMC) Main Crystal Oscillator Status/Enable/Disable/Mask +#define AT91C_PMC_LOCKA (0x1 << 1) // (PMC) PLL A Status/Enable/Disable/Mask +#define AT91C_PMC_MCKRDY (0x1 << 3) // (PMC) Master Clock Status/Enable/Disable/Mask +#define AT91C_PMC_LOCKU (0x1 << 6) // (PMC) PLL UTMI Status/Enable/Disable/Mask +#define AT91C_PMC_PCKRDY0 (0x1 << 8) // (PMC) PCK0_RDY Status/Enable/Disable/Mask +#define AT91C_PMC_PCKRDY1 (0x1 << 9) // (PMC) PCK1_RDY Status/Enable/Disable/Mask +#define AT91C_PMC_PCKRDY2 (0x1 << 10) // (PMC) PCK2_RDY Status/Enable/Disable/Mask +#define AT91C_PMC_MOSCSELS (0x1 << 16) // (PMC) Main Oscillator Selection Status +#define AT91C_PMC_MOSCRCS (0x1 << 17) // (PMC) Main On-Chip RC Oscillator Status +#define AT91C_PMC_CFDEV (0x1 << 18) // (PMC) Clock Failure Detector Event +// -------- PMC_IDR : (PMC Offset: 0x64) PMC Interrupt Disable Register -------- +// -------- PMC_SR : (PMC Offset: 0x68) PMC Status Register -------- +#define AT91C_PMC_OSCSELS (0x1 << 7) // (PMC) Slow Clock Oscillator Selection +#define AT91C_PMC_CFDS (0x1 << 19) // (PMC) Clock Failure Detector Status +#define AT91C_PMC_FOS (0x1 << 20) // (PMC) Clock Failure Detector Fault Output Status +// -------- PMC_IMR : (PMC Offset: 0x6c) PMC Interrupt Mask Register -------- +// -------- PMC_FSMR : (PMC Offset: 0x70) Fast Startup Mode Register -------- +#define AT91C_PMC_FSTT (0xFFFF << 0) // (PMC) Fast Start-up Input Enable 0 to 15 +#define AT91C_PMC_RTTAL (0x1 << 16) // (PMC) RTT Alarm Enable +#define AT91C_PMC_RTCAL (0x1 << 17) // (PMC) RTC Alarm Enable +#define AT91C_PMC_USBAL (0x1 << 18) // (PMC) USB Alarm Enable +#define AT91C_PMC_LPM (0x1 << 20) // (PMC) Low Power Mode +// -------- PMC_FSPR : (PMC Offset: 0x74) Fast Startup Polarity Register -------- +#define AT91C_PMC_FSTP (0xFFFF << 0) // (PMC) Fast Start-up Input Polarity 0 to 15 +// -------- PMC_FOCR : (PMC Offset: 0x78) Fault Output Clear Register -------- +#define AT91C_PMC_FOCLR (0x1 << 0) // (PMC) Fault Output Clear + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Clock Generator Controler +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_CKGR { + AT91_REG CKGR_UCKR; // UTMI Clock Configuration Register + AT91_REG CKGR_MOR; // Main Oscillator Register + AT91_REG CKGR_MCFR; // Main Clock Frequency Register + AT91_REG CKGR_PLLAR; // PLL Register +} AT91S_CKGR, *AT91PS_CKGR; +#else + +#endif +// -------- CKGR_UCKR : (CKGR Offset: 0x0) UTMI Clock Configuration Register -------- +// -------- CKGR_MOR : (CKGR Offset: 0x4) Main Oscillator Register -------- +// -------- CKGR_MCFR : (CKGR Offset: 0x8) Main Clock Frequency Register -------- +// -------- CKGR_PLLAR : (CKGR Offset: 0xc) PLL A Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Reset Controller Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_RSTC { + AT91_REG RSTC_RCR; // Reset Control Register + AT91_REG RSTC_RSR; // Reset Status Register + AT91_REG RSTC_RMR; // Reset Mode Register + AT91_REG Reserved0[60]; // + AT91_REG RSTC_VER; // Version Register +} AT91S_RSTC, *AT91PS_RSTC; +#else +#define RSTC_RCR (AT91_CAST(AT91_REG *) 0x00000000) // (RSTC_RCR) Reset Control Register +#define RSTC_RSR (AT91_CAST(AT91_REG *) 0x00000004) // (RSTC_RSR) Reset Status Register +#define RSTC_RMR (AT91_CAST(AT91_REG *) 0x00000008) // (RSTC_RMR) Reset Mode Register +#define RSTC_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (RSTC_VER) Version Register + +#endif +// -------- RSTC_RCR : (RSTC Offset: 0x0) Reset Control Register -------- +#define AT91C_RSTC_PROCRST (0x1 << 0) // (RSTC) Processor Reset +#define AT91C_RSTC_ICERST (0x1 << 1) // (RSTC) ICE Interface Reset +#define AT91C_RSTC_PERRST (0x1 << 2) // (RSTC) Peripheral Reset +#define AT91C_RSTC_EXTRST (0x1 << 3) // (RSTC) External Reset +#define AT91C_RSTC_KEY (0xFF << 24) // (RSTC) Password +// -------- RSTC_RSR : (RSTC Offset: 0x4) Reset Status Register -------- +#define AT91C_RSTC_URSTS (0x1 << 0) // (RSTC) User Reset Status +#define AT91C_RSTC_RSTTYP (0x7 << 8) // (RSTC) Reset Type +#define AT91C_RSTC_RSTTYP_GENERAL (0x0 << 8) // (RSTC) General reset. Both VDDCORE and VDDBU rising. +#define AT91C_RSTC_RSTTYP_WAKEUP (0x1 << 8) // (RSTC) WakeUp Reset. VDDCORE rising. +#define AT91C_RSTC_RSTTYP_WATCHDOG (0x2 << 8) // (RSTC) Watchdog Reset. Watchdog overflow occured. +#define AT91C_RSTC_RSTTYP_SOFTWARE (0x3 << 8) // (RSTC) Software Reset. Processor reset required by the software. +#define AT91C_RSTC_RSTTYP_USER (0x4 << 8) // (RSTC) User Reset. NRST pin detected low. +#define AT91C_RSTC_NRSTL (0x1 << 16) // (RSTC) NRST pin level +#define AT91C_RSTC_SRCMP (0x1 << 17) // (RSTC) Software Reset Command in Progress. +// -------- RSTC_RMR : (RSTC Offset: 0x8) Reset Mode Register -------- +#define AT91C_RSTC_URSTEN (0x1 << 0) // (RSTC) User Reset Enable +#define AT91C_RSTC_URSTIEN (0x1 << 4) // (RSTC) User Reset Interrupt Enable +#define AT91C_RSTC_ERSTL (0xF << 8) // (RSTC) User Reset Enable + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Supply Controller Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_SUPC { + AT91_REG SUPC_CR; // Control Register + AT91_REG SUPC_BOMR; // Brown Out Mode Register + AT91_REG SUPC_MR; // Mode Register + AT91_REG SUPC_WUMR; // Wake Up Mode Register + AT91_REG SUPC_WUIR; // Wake Up Inputs Register + AT91_REG SUPC_SR; // Status Register + AT91_REG SUPC_FWUTR; // Flash Wake-up Timer Register +} AT91S_SUPC, *AT91PS_SUPC; +#else +#define SUPC_CR (AT91_CAST(AT91_REG *) 0x00000000) // (SUPC_CR) Control Register +#define SUPC_BOMR (AT91_CAST(AT91_REG *) 0x00000004) // (SUPC_BOMR) Brown Out Mode Register +#define SUPC_MR (AT91_CAST(AT91_REG *) 0x00000008) // (SUPC_MR) Mode Register +#define SUPC_WUMR (AT91_CAST(AT91_REG *) 0x0000000C) // (SUPC_WUMR) Wake Up Mode Register +#define SUPC_WUIR (AT91_CAST(AT91_REG *) 0x00000010) // (SUPC_WUIR) Wake Up Inputs Register +#define SUPC_SR (AT91_CAST(AT91_REG *) 0x00000014) // (SUPC_SR) Status Register +#define SUPC_FWUTR (AT91_CAST(AT91_REG *) 0x00000018) // (SUPC_FWUTR) Flash Wake-up Timer Register + +#endif +// -------- SUPC_CR : (SUPC Offset: 0x0) Control Register -------- +#define AT91C_SUPC_SHDW (0x1 << 0) // (SUPC) Shut Down Command +#define AT91C_SUPC_SHDWEOF (0x1 << 1) // (SUPC) Shut Down after End Of Frame +#define AT91C_SUPC_VROFF (0x1 << 2) // (SUPC) Voltage Regulator Off +#define AT91C_SUPC_XTALSEL (0x1 << 3) // (SUPC) Crystal Oscillator Select +#define AT91C_SUPC_KEY (0xFF << 24) // (SUPC) Supply Controller Writing Protection Key +// -------- SUPC_BOMR : (SUPC Offset: 0x4) Brown Out Mode Register -------- +#define AT91C_SUPC_BODTH (0xF << 0) // (SUPC) Brown Out Threshold +#define AT91C_SUPC_BODSMPL (0x7 << 8) // (SUPC) Brown Out Sampling Period +#define AT91C_SUPC_BODSMPL_DISABLED (0x0 << 8) // (SUPC) Brown Out Detector disabled +#define AT91C_SUPC_BODSMPL_CONTINUOUS (0x1 << 8) // (SUPC) Continuous Brown Out Detector +#define AT91C_SUPC_BODSMPL_32_SLCK (0x2 << 8) // (SUPC) Brown Out Detector enabled one SLCK period every 32 SLCK periods +#define AT91C_SUPC_BODSMPL_256_SLCK (0x3 << 8) // (SUPC) Brown Out Detector enabled one SLCK period every 256 SLCK periods +#define AT91C_SUPC_BODSMPL_2048_SLCK (0x4 << 8) // (SUPC) Brown Out Detector enabled one SLCK period every 2048 SLCK periods +#define AT91C_SUPC_BODRSTEN (0x1 << 12) // (SUPC) Brownout Reset Enable +// -------- SUPC_MR : (SUPC Offset: 0x8) Supply Controller Mode Register -------- +#define AT91C_SUPC_LCDOUT (0xF << 0) // (SUPC) LCD Charge Pump Output Voltage Selection +#define AT91C_SUPC_LCDMODE (0x3 << 4) // (SUPC) Segment LCD Supply Mode +#define AT91C_SUPC_LCDMODE_OFF (0x0 << 4) // (SUPC) The internal and external supply sources are both deselected and the on-chip charge pump is turned off +#define AT91C_SUPC_LCDMODE_OFF_AFTER_EOF (0x1 << 4) // (SUPC) At the End Of Frame from LCD controller, the internal and external supply sources are both deselected and the on-chip charge pump is turned off +#define AT91C_SUPC_LCDMODE_EXTERNAL (0x2 << 4) // (SUPC) The external supply source is selected +#define AT91C_SUPC_LCDMODE_INTERNAL (0x3 << 4) // (SUPC) The internal supply source is selected and the on-chip charge pump is turned on +#define AT91C_SUPC_VRDEEP (0x1 << 8) // (SUPC) Voltage Regulator Deep Mode +#define AT91C_SUPC_VRVDD (0x7 << 9) // (SUPC) Voltage Regulator Output Voltage Selection +#define AT91C_SUPC_VRRSTEN (0x1 << 12) // (SUPC) Voltage Regulation Loss Reset Enable +#define AT91C_SUPC_GPBRON (0x1 << 16) // (SUPC) GPBR ON +#define AT91C_SUPC_SRAMON (0x1 << 17) // (SUPC) SRAM ON +#define AT91C_SUPC_RTCON (0x1 << 18) // (SUPC) Real Time Clock Power switch ON +#define AT91C_SUPC_FLASHON (0x1 << 19) // (SUPC) Flash Power switch On +#define AT91C_SUPC_BYPASS (0x1 << 20) // (SUPC) 32kHz oscillator bypass +#define AT91C_SUPC_MKEY (0xFF << 24) // (SUPC) Supply Controller Writing Protection Key +// -------- SUPC_WUMR : (SUPC Offset: 0xc) Wake Up Mode Register -------- +#define AT91C_SUPC_FWUPEN (0x1 << 0) // (SUPC) Force Wake Up Enable +#define AT91C_SUPC_BODEN (0x1 << 1) // (SUPC) Brown Out Wake Up Enable +#define AT91C_SUPC_RTTEN (0x1 << 2) // (SUPC) Real Time Timer Wake Up Enable +#define AT91C_SUPC_RTCEN (0x1 << 3) // (SUPC) Real Time Clock Wake Up Enable +#define AT91C_SUPC_FWUPDBC (0x7 << 8) // (SUPC) Force Wake Up debouncer +#define AT91C_SUPC_FWUPDBC_IMMEDIATE (0x0 << 8) // (SUPC) Immediate, No debouncing, detected active at least one Slow clock edge +#define AT91C_SUPC_FWUPDBC_3_SLCK (0x1 << 8) // (SUPC) An enabled Wake Up input shall be low for at least 3 SLCK periods +#define AT91C_SUPC_FWUPDBC_32_SLCK (0x2 << 8) // (SUPC) An enabled Wake Up input shall be low for at least 32 SLCK periods +#define AT91C_SUPC_FWUPDBC_512_SLCK (0x3 << 8) // (SUPC) An enabled Wake Up input shall be low for at least 512 SLCK periods +#define AT91C_SUPC_FWUPDBC_4096_SLCK (0x4 << 8) // (SUPC) An enabled Wake Up input shall be low for at least 4096 SLCK periods +#define AT91C_SUPC_FWUPDBC_32768_SLCK (0x5 << 8) // (SUPC) An enabled Wake Up input shall be low for at least 32768 SLCK periods +#define AT91C_SUPC_WKUPDBC (0x7 << 12) // (SUPC) Force Wake Up debouncer +#define AT91C_SUPC_WKUPDBC_IMMEDIATE (0x0 << 12) // (SUPC) Immediate, No debouncing, detected active at least one Slow clock edge +#define AT91C_SUPC_WKUPDBC_3_SLCK (0x1 << 12) // (SUPC) FWUP shall be low for at least 3 SLCK periods +#define AT91C_SUPC_WKUPDBC_32_SLCK (0x2 << 12) // (SUPC) FWUP shall be low for at least 32 SLCK periods +#define AT91C_SUPC_WKUPDBC_512_SLCK (0x3 << 12) // (SUPC) FWUP shall be low for at least 512 SLCK periods +#define AT91C_SUPC_WKUPDBC_4096_SLCK (0x4 << 12) // (SUPC) FWUP shall be low for at least 4096 SLCK periods +#define AT91C_SUPC_WKUPDBC_32768_SLCK (0x5 << 12) // (SUPC) FWUP shall be low for at least 32768 SLCK periods +// -------- SUPC_WUIR : (SUPC Offset: 0x10) Wake Up Inputs Register -------- +#define AT91C_SUPC_WKUPEN0 (0x1 << 0) // (SUPC) Wake Up Input Enable 0 +#define AT91C_SUPC_WKUPEN1 (0x1 << 1) // (SUPC) Wake Up Input Enable 1 +#define AT91C_SUPC_WKUPEN2 (0x1 << 2) // (SUPC) Wake Up Input Enable 2 +#define AT91C_SUPC_WKUPEN3 (0x1 << 3) // (SUPC) Wake Up Input Enable 3 +#define AT91C_SUPC_WKUPEN4 (0x1 << 4) // (SUPC) Wake Up Input Enable 4 +#define AT91C_SUPC_WKUPEN5 (0x1 << 5) // (SUPC) Wake Up Input Enable 5 +#define AT91C_SUPC_WKUPEN6 (0x1 << 6) // (SUPC) Wake Up Input Enable 6 +#define AT91C_SUPC_WKUPEN7 (0x1 << 7) // (SUPC) Wake Up Input Enable 7 +#define AT91C_SUPC_WKUPEN8 (0x1 << 8) // (SUPC) Wake Up Input Enable 8 +#define AT91C_SUPC_WKUPEN9 (0x1 << 9) // (SUPC) Wake Up Input Enable 9 +#define AT91C_SUPC_WKUPEN10 (0x1 << 10) // (SUPC) Wake Up Input Enable 10 +#define AT91C_SUPC_WKUPEN11 (0x1 << 11) // (SUPC) Wake Up Input Enable 11 +#define AT91C_SUPC_WKUPEN12 (0x1 << 12) // (SUPC) Wake Up Input Enable 12 +#define AT91C_SUPC_WKUPEN13 (0x1 << 13) // (SUPC) Wake Up Input Enable 13 +#define AT91C_SUPC_WKUPEN14 (0x1 << 14) // (SUPC) Wake Up Input Enable 14 +#define AT91C_SUPC_WKUPEN15 (0x1 << 15) // (SUPC) Wake Up Input Enable 15 +#define AT91C_SUPC_WKUPT0 (0x1 << 16) // (SUPC) Wake Up Input Transition 0 +#define AT91C_SUPC_WKUPT1 (0x1 << 17) // (SUPC) Wake Up Input Transition 1 +#define AT91C_SUPC_WKUPT2 (0x1 << 18) // (SUPC) Wake Up Input Transition 2 +#define AT91C_SUPC_WKUPT3 (0x1 << 19) // (SUPC) Wake Up Input Transition 3 +#define AT91C_SUPC_WKUPT4 (0x1 << 20) // (SUPC) Wake Up Input Transition 4 +#define AT91C_SUPC_WKUPT5 (0x1 << 21) // (SUPC) Wake Up Input Transition 5 +#define AT91C_SUPC_WKUPT6 (0x1 << 22) // (SUPC) Wake Up Input Transition 6 +#define AT91C_SUPC_WKUPT7 (0x1 << 23) // (SUPC) Wake Up Input Transition 7 +#define AT91C_SUPC_WKUPT8 (0x1 << 24) // (SUPC) Wake Up Input Transition 8 +#define AT91C_SUPC_WKUPT9 (0x1 << 25) // (SUPC) Wake Up Input Transition 9 +#define AT91C_SUPC_WKUPT10 (0x1 << 26) // (SUPC) Wake Up Input Transition 10 +#define AT91C_SUPC_WKUPT11 (0x1 << 27) // (SUPC) Wake Up Input Transition 11 +#define AT91C_SUPC_WKUPT12 (0x1 << 28) // (SUPC) Wake Up Input Transition 12 +#define AT91C_SUPC_WKUPT13 (0x1 << 29) // (SUPC) Wake Up Input Transition 13 +#define AT91C_SUPC_WKUPT14 (0x1 << 30) // (SUPC) Wake Up Input Transition 14 +#define AT91C_SUPC_WKUPT15 (0x1 << 31) // (SUPC) Wake Up Input Transition 15 +// -------- SUPC_SR : (SUPC Offset: 0x14) Status Register -------- +#define AT91C_SUPC_FWUPS (0x1 << 0) // (SUPC) Force Wake Up Status +#define AT91C_SUPC_WKUPS (0x1 << 1) // (SUPC) Wake Up Status +#define AT91C_SUPC_BODWS (0x1 << 2) // (SUPC) BOD Detection Wake Up Status +#define AT91C_SUPC_VRRSTS (0x1 << 3) // (SUPC) Voltage regulation Loss Reset Status +#define AT91C_SUPC_BODRSTS (0x1 << 4) // (SUPC) BOD detection Reset Status +#define AT91C_SUPC_BODS (0x1 << 5) // (SUPC) BOD Status +#define AT91C_SUPC_BROWNOUT (0x1 << 6) // (SUPC) BOD Output Status +#define AT91C_SUPC_OSCSEL (0x1 << 7) // (SUPC) 32kHz Oscillator Selection Status +#define AT91C_SUPC_LCDS (0x1 << 8) // (SUPC) LCD Status +#define AT91C_SUPC_GPBRS (0x1 << 9) // (SUPC) General Purpose Back-up registers Status +#define AT91C_SUPC_RTS (0x1 << 10) // (SUPC) Clock Status +#define AT91C_SUPC_FLASHS (0x1 << 11) // (SUPC) FLASH Memory Status +#define AT91C_SUPC_FWUPIS (0x1 << 12) // (SUPC) WKUP Input Status +#define AT91C_SUPC_WKUPIS0 (0x1 << 16) // (SUPC) WKUP Input 0 Status +#define AT91C_SUPC_WKUPIS1 (0x1 << 17) // (SUPC) WKUP Input 1 Status +#define AT91C_SUPC_WKUPIS2 (0x1 << 18) // (SUPC) WKUP Input 2 Status +#define AT91C_SUPC_WKUPIS3 (0x1 << 19) // (SUPC) WKUP Input 3 Status +#define AT91C_SUPC_WKUPIS4 (0x1 << 20) // (SUPC) WKUP Input 4 Status +#define AT91C_SUPC_WKUPIS5 (0x1 << 21) // (SUPC) WKUP Input 5 Status +#define AT91C_SUPC_WKUPIS6 (0x1 << 22) // (SUPC) WKUP Input 6 Status +#define AT91C_SUPC_WKUPIS7 (0x1 << 23) // (SUPC) WKUP Input 7 Status +#define AT91C_SUPC_WKUPIS8 (0x1 << 24) // (SUPC) WKUP Input 8 Status +#define AT91C_SUPC_WKUPIS9 (0x1 << 25) // (SUPC) WKUP Input 9 Status +#define AT91C_SUPC_WKUPIS10 (0x1 << 26) // (SUPC) WKUP Input 10 Status +#define AT91C_SUPC_WKUPIS11 (0x1 << 27) // (SUPC) WKUP Input 11 Status +#define AT91C_SUPC_WKUPIS12 (0x1 << 28) // (SUPC) WKUP Input 12 Status +#define AT91C_SUPC_WKUPIS13 (0x1 << 29) // (SUPC) WKUP Input 13 Status +#define AT91C_SUPC_WKUPIS14 (0x1 << 30) // (SUPC) WKUP Input 14 Status +#define AT91C_SUPC_WKUPIS15 (0x1 << 31) // (SUPC) WKUP Input 15 Status +// -------- SUPC_FWUTR : (SUPC Offset: 0x18) Flash Wake Up Timer Register -------- +#define AT91C_SUPC_FWUT (0x3FF << 0) // (SUPC) Flash Wake Up Timer + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Real Time Timer Controller Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_RTTC { + AT91_REG RTTC_RTMR; // Real-time Mode Register + AT91_REG RTTC_RTAR; // Real-time Alarm Register + AT91_REG RTTC_RTVR; // Real-time Value Register + AT91_REG RTTC_RTSR; // Real-time Status Register +} AT91S_RTTC, *AT91PS_RTTC; +#else +#define RTTC_RTMR (AT91_CAST(AT91_REG *) 0x00000000) // (RTTC_RTMR) Real-time Mode Register +#define RTTC_RTAR (AT91_CAST(AT91_REG *) 0x00000004) // (RTTC_RTAR) Real-time Alarm Register +#define RTTC_RTVR (AT91_CAST(AT91_REG *) 0x00000008) // (RTTC_RTVR) Real-time Value Register +#define RTTC_RTSR (AT91_CAST(AT91_REG *) 0x0000000C) // (RTTC_RTSR) Real-time Status Register + +#endif +// -------- RTTC_RTMR : (RTTC Offset: 0x0) Real-time Mode Register -------- +#define AT91C_RTTC_RTPRES (0xFFFF << 0) // (RTTC) Real-time Timer Prescaler Value +#define AT91C_RTTC_ALMIEN (0x1 << 16) // (RTTC) Alarm Interrupt Enable +#define AT91C_RTTC_RTTINCIEN (0x1 << 17) // (RTTC) Real Time Timer Increment Interrupt Enable +#define AT91C_RTTC_RTTRST (0x1 << 18) // (RTTC) Real Time Timer Restart +// -------- RTTC_RTAR : (RTTC Offset: 0x4) Real-time Alarm Register -------- +#define AT91C_RTTC_ALMV (0x0 << 0) // (RTTC) Alarm Value +// -------- RTTC_RTVR : (RTTC Offset: 0x8) Current Real-time Value Register -------- +#define AT91C_RTTC_CRTV (0x0 << 0) // (RTTC) Current Real-time Value +// -------- RTTC_RTSR : (RTTC Offset: 0xc) Real-time Status Register -------- +#define AT91C_RTTC_ALMS (0x1 << 0) // (RTTC) Real-time Alarm Status +#define AT91C_RTTC_RTTINC (0x1 << 1) // (RTTC) Real-time Timer Increment + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Watchdog Timer Controller Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_WDTC { + AT91_REG WDTC_WDCR; // Watchdog Control Register + AT91_REG WDTC_WDMR; // Watchdog Mode Register + AT91_REG WDTC_WDSR; // Watchdog Status Register +} AT91S_WDTC, *AT91PS_WDTC; +#else +#define WDTC_WDCR (AT91_CAST(AT91_REG *) 0x00000000) // (WDTC_WDCR) Watchdog Control Register +#define WDTC_WDMR (AT91_CAST(AT91_REG *) 0x00000004) // (WDTC_WDMR) Watchdog Mode Register +#define WDTC_WDSR (AT91_CAST(AT91_REG *) 0x00000008) // (WDTC_WDSR) Watchdog Status Register + +#endif +// -------- WDTC_WDCR : (WDTC Offset: 0x0) Periodic Interval Image Register -------- +#define AT91C_WDTC_WDRSTT (0x1 << 0) // (WDTC) Watchdog Restart +#define AT91C_WDTC_KEY (0xFF << 24) // (WDTC) Watchdog KEY Password +// -------- WDTC_WDMR : (WDTC Offset: 0x4) Watchdog Mode Register -------- +#define AT91C_WDTC_WDV (0xFFF << 0) // (WDTC) Watchdog Timer Restart +#define AT91C_WDTC_WDFIEN (0x1 << 12) // (WDTC) Watchdog Fault Interrupt Enable +#define AT91C_WDTC_WDRSTEN (0x1 << 13) // (WDTC) Watchdog Reset Enable +#define AT91C_WDTC_WDRPROC (0x1 << 14) // (WDTC) Watchdog Timer Restart +#define AT91C_WDTC_WDDIS (0x1 << 15) // (WDTC) Watchdog Disable +#define AT91C_WDTC_WDD (0xFFF << 16) // (WDTC) Watchdog Delta Value +#define AT91C_WDTC_WDDBGHLT (0x1 << 28) // (WDTC) Watchdog Debug Halt +#define AT91C_WDTC_WDIDLEHLT (0x1 << 29) // (WDTC) Watchdog Idle Halt +// -------- WDTC_WDSR : (WDTC Offset: 0x8) Watchdog Status Register -------- +#define AT91C_WDTC_WDUNF (0x1 << 0) // (WDTC) Watchdog Underflow +#define AT91C_WDTC_WDERR (0x1 << 1) // (WDTC) Watchdog Error + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Real-time Clock Alarm and Parallel Load Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_RTC { + AT91_REG RTC_CR; // Control Register + AT91_REG RTC_MR; // Mode Register + AT91_REG RTC_TIMR; // Time Register + AT91_REG RTC_CALR; // Calendar Register + AT91_REG RTC_TIMALR; // Time Alarm Register + AT91_REG RTC_CALALR; // Calendar Alarm Register + AT91_REG RTC_SR; // Status Register + AT91_REG RTC_SCCR; // Status Clear Command Register + AT91_REG RTC_IER; // Interrupt Enable Register + AT91_REG RTC_IDR; // Interrupt Disable Register + AT91_REG RTC_IMR; // Interrupt Mask Register + AT91_REG RTC_VER; // Valid Entry Register +} AT91S_RTC, *AT91PS_RTC; +#else +#define RTC_CR (AT91_CAST(AT91_REG *) 0x00000000) // (RTC_CR) Control Register +#define RTC_MR (AT91_CAST(AT91_REG *) 0x00000004) // (RTC_MR) Mode Register +#define RTC_TIMR (AT91_CAST(AT91_REG *) 0x00000008) // (RTC_TIMR) Time Register +#define RTC_CALR (AT91_CAST(AT91_REG *) 0x0000000C) // (RTC_CALR) Calendar Register +#define RTC_TIMALR (AT91_CAST(AT91_REG *) 0x00000010) // (RTC_TIMALR) Time Alarm Register +#define RTC_CALALR (AT91_CAST(AT91_REG *) 0x00000014) // (RTC_CALALR) Calendar Alarm Register +#define RTC_SR (AT91_CAST(AT91_REG *) 0x00000018) // (RTC_SR) Status Register +#define RTC_SCCR (AT91_CAST(AT91_REG *) 0x0000001C) // (RTC_SCCR) Status Clear Command Register +#define RTC_IER (AT91_CAST(AT91_REG *) 0x00000020) // (RTC_IER) Interrupt Enable Register +#define RTC_IDR (AT91_CAST(AT91_REG *) 0x00000024) // (RTC_IDR) Interrupt Disable Register +#define RTC_IMR (AT91_CAST(AT91_REG *) 0x00000028) // (RTC_IMR) Interrupt Mask Register +#define RTC_VER (AT91_CAST(AT91_REG *) 0x0000002C) // (RTC_VER) Valid Entry Register + +#endif +// -------- RTC_CR : (RTC Offset: 0x0) RTC Control Register -------- +#define AT91C_RTC_UPDTIM (0x1 << 0) // (RTC) Update Request Time Register +#define AT91C_RTC_UPDCAL (0x1 << 1) // (RTC) Update Request Calendar Register +#define AT91C_RTC_TIMEVSEL (0x3 << 8) // (RTC) Time Event Selection +#define AT91C_RTC_TIMEVSEL_MINUTE (0x0 << 8) // (RTC) Minute change. +#define AT91C_RTC_TIMEVSEL_HOUR (0x1 << 8) // (RTC) Hour change. +#define AT91C_RTC_TIMEVSEL_DAY24 (0x2 << 8) // (RTC) Every day at midnight. +#define AT91C_RTC_TIMEVSEL_DAY12 (0x3 << 8) // (RTC) Every day at noon. +#define AT91C_RTC_CALEVSEL (0x3 << 16) // (RTC) Calendar Event Selection +#define AT91C_RTC_CALEVSEL_WEEK (0x0 << 16) // (RTC) Week change (every Monday at time 00:00:00). +#define AT91C_RTC_CALEVSEL_MONTH (0x1 << 16) // (RTC) Month change (every 01 of each month at time 00:00:00). +#define AT91C_RTC_CALEVSEL_YEAR (0x2 << 16) // (RTC) Year change (every January 1 at time 00:00:00). +// -------- RTC_MR : (RTC Offset: 0x4) RTC Mode Register -------- +#define AT91C_RTC_HRMOD (0x1 << 0) // (RTC) 12-24 hour Mode +// -------- RTC_TIMR : (RTC Offset: 0x8) RTC Time Register -------- +#define AT91C_RTC_SEC (0x7F << 0) // (RTC) Current Second +#define AT91C_RTC_MIN (0x7F << 8) // (RTC) Current Minute +#define AT91C_RTC_HOUR (0x3F << 16) // (RTC) Current Hour +#define AT91C_RTC_AMPM (0x1 << 22) // (RTC) Ante Meridiem, Post Meridiem Indicator +// -------- RTC_CALR : (RTC Offset: 0xc) RTC Calendar Register -------- +#define AT91C_RTC_CENT (0x3F << 0) // (RTC) Current Century +#define AT91C_RTC_YEAR (0xFF << 8) // (RTC) Current Year +#define AT91C_RTC_MONTH (0x1F << 16) // (RTC) Current Month +#define AT91C_RTC_DAY (0x7 << 21) // (RTC) Current Day +#define AT91C_RTC_DATE (0x3F << 24) // (RTC) Current Date +// -------- RTC_TIMALR : (RTC Offset: 0x10) RTC Time Alarm Register -------- +#define AT91C_RTC_SECEN (0x1 << 7) // (RTC) Second Alarm Enable +#define AT91C_RTC_MINEN (0x1 << 15) // (RTC) Minute Alarm +#define AT91C_RTC_HOUREN (0x1 << 23) // (RTC) Current Hour +// -------- RTC_CALALR : (RTC Offset: 0x14) RTC Calendar Alarm Register -------- +#define AT91C_RTC_MONTHEN (0x1 << 23) // (RTC) Month Alarm Enable +#define AT91C_RTC_DATEEN (0x1 << 31) // (RTC) Date Alarm Enable +// -------- RTC_SR : (RTC Offset: 0x18) RTC Status Register -------- +#define AT91C_RTC_ACKUPD (0x1 << 0) // (RTC) Acknowledge for Update +#define AT91C_RTC_ALARM (0x1 << 1) // (RTC) Alarm Flag +#define AT91C_RTC_SECEV (0x1 << 2) // (RTC) Second Event +#define AT91C_RTC_TIMEV (0x1 << 3) // (RTC) Time Event +#define AT91C_RTC_CALEV (0x1 << 4) // (RTC) Calendar event +// -------- RTC_SCCR : (RTC Offset: 0x1c) RTC Status Clear Command Register -------- +// -------- RTC_IER : (RTC Offset: 0x20) RTC Interrupt Enable Register -------- +// -------- RTC_IDR : (RTC Offset: 0x24) RTC Interrupt Disable Register -------- +// -------- RTC_IMR : (RTC Offset: 0x28) RTC Interrupt Mask Register -------- +// -------- RTC_VER : (RTC Offset: 0x2c) RTC Valid Entry Register -------- +#define AT91C_RTC_NVTIM (0x1 << 0) // (RTC) Non valid Time +#define AT91C_RTC_NVCAL (0x1 << 1) // (RTC) Non valid Calendar +#define AT91C_RTC_NVTIMALR (0x1 << 2) // (RTC) Non valid time Alarm +#define AT91C_RTC_NVCALALR (0x1 << 3) // (RTC) Nonvalid Calendar Alarm + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Analog to Digital Convertor +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_ADC { + AT91_REG ADC_CR; // ADC Control Register + AT91_REG ADC_MR; // ADC Mode Register + AT91_REG Reserved0[2]; // + AT91_REG ADC_CHER; // ADC Channel Enable Register + AT91_REG ADC_CHDR; // ADC Channel Disable Register + AT91_REG ADC_CHSR; // ADC Channel Status Register + AT91_REG ADC_SR; // ADC Status Register + AT91_REG ADC_LCDR; // ADC Last Converted Data Register + AT91_REG ADC_IER; // ADC Interrupt Enable Register + AT91_REG ADC_IDR; // ADC Interrupt Disable Register + AT91_REG ADC_IMR; // ADC Interrupt Mask Register + AT91_REG ADC_CDR0; // ADC Channel Data Register 0 + AT91_REG ADC_CDR1; // ADC Channel Data Register 1 + AT91_REG ADC_CDR2; // ADC Channel Data Register 2 + AT91_REG ADC_CDR3; // ADC Channel Data Register 3 + AT91_REG ADC_CDR4; // ADC Channel Data Register 4 + AT91_REG ADC_CDR5; // ADC Channel Data Register 5 + AT91_REG ADC_CDR6; // ADC Channel Data Register 6 + AT91_REG ADC_CDR7; // ADC Channel Data Register 7 + AT91_REG Reserved1[5]; // + AT91_REG ADC_ACR; // Analog Control Register + AT91_REG ADC_EMR; // Extended Mode Register + AT91_REG Reserved2[32]; // + AT91_REG ADC_ADDRSIZE; // ADC ADDRSIZE REGISTER + AT91_REG ADC_IPNAME1; // ADC IPNAME1 REGISTER + AT91_REG ADC_IPNAME2; // ADC IPNAME2 REGISTER + AT91_REG ADC_FEATURES; // ADC FEATURES REGISTER + AT91_REG ADC_VER; // ADC VERSION REGISTER + AT91_REG ADC_RPR; // Receive Pointer Register + AT91_REG ADC_RCR; // Receive Counter Register + AT91_REG ADC_TPR; // Transmit Pointer Register + AT91_REG ADC_TCR; // Transmit Counter Register + AT91_REG ADC_RNPR; // Receive Next Pointer Register + AT91_REG ADC_RNCR; // Receive Next Counter Register + AT91_REG ADC_TNPR; // Transmit Next Pointer Register + AT91_REG ADC_TNCR; // Transmit Next Counter Register + AT91_REG ADC_PTCR; // PDC Transfer Control Register + AT91_REG ADC_PTSR; // PDC Transfer Status Register +} AT91S_ADC, *AT91PS_ADC; +#else +#define ADC_CR (AT91_CAST(AT91_REG *) 0x00000000) // (ADC_CR) ADC Control Register +#define ADC_MR (AT91_CAST(AT91_REG *) 0x00000004) // (ADC_MR) ADC Mode Register +#define ADC_CHER (AT91_CAST(AT91_REG *) 0x00000010) // (ADC_CHER) ADC Channel Enable Register +#define ADC_CHDR (AT91_CAST(AT91_REG *) 0x00000014) // (ADC_CHDR) ADC Channel Disable Register +#define ADC_CHSR (AT91_CAST(AT91_REG *) 0x00000018) // (ADC_CHSR) ADC Channel Status Register +#define ADC_SR (AT91_CAST(AT91_REG *) 0x0000001C) // (ADC_SR) ADC Status Register +#define ADC_LCDR (AT91_CAST(AT91_REG *) 0x00000020) // (ADC_LCDR) ADC Last Converted Data Register +#define ADC_IER (AT91_CAST(AT91_REG *) 0x00000024) // (ADC_IER) ADC Interrupt Enable Register +#define ADC_IDR (AT91_CAST(AT91_REG *) 0x00000028) // (ADC_IDR) ADC Interrupt Disable Register +#define ADC_IMR (AT91_CAST(AT91_REG *) 0x0000002C) // (ADC_IMR) ADC Interrupt Mask Register +#define ADC_CDR0 (AT91_CAST(AT91_REG *) 0x00000030) // (ADC_CDR0) ADC Channel Data Register 0 +#define ADC_CDR1 (AT91_CAST(AT91_REG *) 0x00000034) // (ADC_CDR1) ADC Channel Data Register 1 +#define ADC_CDR2 (AT91_CAST(AT91_REG *) 0x00000038) // (ADC_CDR2) ADC Channel Data Register 2 +#define ADC_CDR3 (AT91_CAST(AT91_REG *) 0x0000003C) // (ADC_CDR3) ADC Channel Data Register 3 +#define ADC_CDR4 (AT91_CAST(AT91_REG *) 0x00000040) // (ADC_CDR4) ADC Channel Data Register 4 +#define ADC_CDR5 (AT91_CAST(AT91_REG *) 0x00000044) // (ADC_CDR5) ADC Channel Data Register 5 +#define ADC_CDR6 (AT91_CAST(AT91_REG *) 0x00000048) // (ADC_CDR6) ADC Channel Data Register 6 +#define ADC_CDR7 (AT91_CAST(AT91_REG *) 0x0000004C) // (ADC_CDR7) ADC Channel Data Register 7 +#define ADC_ACR (AT91_CAST(AT91_REG *) 0x00000064) // (ADC_ACR) Analog Control Register +#define ADC_EMR (AT91_CAST(AT91_REG *) 0x00000068) // (ADC_EMR) Extended Mode Register +#define ADC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (ADC_ADDRSIZE) ADC ADDRSIZE REGISTER +#define ADC_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (ADC_IPNAME1) ADC IPNAME1 REGISTER +#define ADC_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (ADC_IPNAME2) ADC IPNAME2 REGISTER +#define ADC_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (ADC_FEATURES) ADC FEATURES REGISTER +#define ADC_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (ADC_VER) ADC VERSION REGISTER + +#endif +// -------- ADC_CR : (ADC Offset: 0x0) ADC Control Register -------- +#define AT91C_ADC_SWRST (0x1 << 0) // (ADC) Software Reset +#define AT91C_ADC_START (0x1 << 1) // (ADC) Start Conversion +// -------- ADC_MR : (ADC Offset: 0x4) ADC Mode Register -------- +#define AT91C_ADC_TRGEN (0x1 << 0) // (ADC) Trigger Enable +#define AT91C_ADC_TRGEN_DIS (0x0) // (ADC) Hradware triggers are disabled. Starting a conversion is only possible by software +#define AT91C_ADC_TRGEN_EN (0x1) // (ADC) Hardware trigger selected by TRGSEL field is enabled. +#define AT91C_ADC_TRGSEL (0x7 << 1) // (ADC) Trigger Selection +#define AT91C_ADC_TRGSEL_EXT (0x0 << 1) // (ADC) Selected TRGSEL = External Trigger +#define AT91C_ADC_TRGSEL_TIOA0 (0x1 << 1) // (ADC) Selected TRGSEL = TIAO0 +#define AT91C_ADC_TRGSEL_TIOA1 (0x2 << 1) // (ADC) Selected TRGSEL = TIAO1 +#define AT91C_ADC_TRGSEL_TIOA2 (0x3 << 1) // (ADC) Selected TRGSEL = TIAO2 +#define AT91C_ADC_TRGSEL_PWM0_TRIG (0x4 << 1) // (ADC) Selected TRGSEL = PWM trigger +#define AT91C_ADC_TRGSEL_PWM1_TRIG (0x5 << 1) // (ADC) Selected TRGSEL = PWM Trigger +#define AT91C_ADC_TRGSEL_RESERVED (0x6 << 1) // (ADC) Selected TRGSEL = Reserved +#define AT91C_ADC_LOWRES (0x1 << 4) // (ADC) Resolution. +#define AT91C_ADC_LOWRES_10_BIT (0x0 << 4) // (ADC) 10-bit resolution +#define AT91C_ADC_LOWRES_8_BIT (0x1 << 4) // (ADC) 8-bit resolution +#define AT91C_ADC_SLEEP (0x1 << 5) // (ADC) Sleep Mode +#define AT91C_ADC_SLEEP_NORMAL_MODE (0x0 << 5) // (ADC) Normal Mode +#define AT91C_ADC_SLEEP_MODE (0x1 << 5) // (ADC) Sleep Mode +#define AT91C_ADC_PRESCAL (0x3F << 8) // (ADC) Prescaler rate selection +#define AT91C_ADC_STARTUP (0x1F << 16) // (ADC) Startup Time +#define AT91C_ADC_SHTIM (0xF << 24) // (ADC) Sample & Hold Time +// -------- ADC_CHER : (ADC Offset: 0x10) ADC Channel Enable Register -------- +#define AT91C_ADC_CH0 (0x1 << 0) // (ADC) Channel 0 +#define AT91C_ADC_CH1 (0x1 << 1) // (ADC) Channel 1 +#define AT91C_ADC_CH2 (0x1 << 2) // (ADC) Channel 2 +#define AT91C_ADC_CH3 (0x1 << 3) // (ADC) Channel 3 +#define AT91C_ADC_CH4 (0x1 << 4) // (ADC) Channel 4 +#define AT91C_ADC_CH5 (0x1 << 5) // (ADC) Channel 5 +#define AT91C_ADC_CH6 (0x1 << 6) // (ADC) Channel 6 +#define AT91C_ADC_CH7 (0x1 << 7) // (ADC) Channel 7 +// -------- ADC_CHDR : (ADC Offset: 0x14) ADC Channel Disable Register -------- +// -------- ADC_CHSR : (ADC Offset: 0x18) ADC Channel Status Register -------- +// -------- ADC_SR : (ADC Offset: 0x1c) ADC Status Register -------- +#define AT91C_ADC_EOC0 (0x1 << 0) // (ADC) End of Conversion +#define AT91C_ADC_EOC1 (0x1 << 1) // (ADC) End of Conversion +#define AT91C_ADC_EOC2 (0x1 << 2) // (ADC) End of Conversion +#define AT91C_ADC_EOC3 (0x1 << 3) // (ADC) End of Conversion +#define AT91C_ADC_EOC4 (0x1 << 4) // (ADC) End of Conversion +#define AT91C_ADC_EOC5 (0x1 << 5) // (ADC) End of Conversion +#define AT91C_ADC_EOC6 (0x1 << 6) // (ADC) End of Conversion +#define AT91C_ADC_EOC7 (0x1 << 7) // (ADC) End of Conversion +#define AT91C_ADC_OVRE0 (0x1 << 8) // (ADC) Overrun Error +#define AT91C_ADC_OVRE1 (0x1 << 9) // (ADC) Overrun Error +#define AT91C_ADC_OVRE2 (0x1 << 10) // (ADC) Overrun Error +#define AT91C_ADC_OVRE3 (0x1 << 11) // (ADC) Overrun Error +#define AT91C_ADC_OVRE4 (0x1 << 12) // (ADC) Overrun Error +#define AT91C_ADC_OVRE5 (0x1 << 13) // (ADC) Overrun Error +#define AT91C_ADC_OVRE6 (0x1 << 14) // (ADC) Overrun Error +#define AT91C_ADC_OVRE7 (0x1 << 15) // (ADC) Overrun Error +#define AT91C_ADC_DRDY (0x1 << 16) // (ADC) Data Ready +#define AT91C_ADC_GOVRE (0x1 << 17) // (ADC) General Overrun +#define AT91C_ADC_ENDRX (0x1 << 18) // (ADC) End of Receiver Transfer +#define AT91C_ADC_RXBUFF (0x1 << 19) // (ADC) RXBUFF Interrupt +// -------- ADC_LCDR : (ADC Offset: 0x20) ADC Last Converted Data Register -------- +#define AT91C_ADC_LDATA (0x3FF << 0) // (ADC) Last Data Converted +// -------- ADC_IER : (ADC Offset: 0x24) ADC Interrupt Enable Register -------- +// -------- ADC_IDR : (ADC Offset: 0x28) ADC Interrupt Disable Register -------- +// -------- ADC_IMR : (ADC Offset: 0x2c) ADC Interrupt Mask Register -------- +// -------- ADC_CDR0 : (ADC Offset: 0x30) ADC Channel Data Register 0 -------- +#define AT91C_ADC_DATA (0x3FF << 0) // (ADC) Converted Data +// -------- ADC_CDR1 : (ADC Offset: 0x34) ADC Channel Data Register 1 -------- +// -------- ADC_CDR2 : (ADC Offset: 0x38) ADC Channel Data Register 2 -------- +// -------- ADC_CDR3 : (ADC Offset: 0x3c) ADC Channel Data Register 3 -------- +// -------- ADC_CDR4 : (ADC Offset: 0x40) ADC Channel Data Register 4 -------- +// -------- ADC_CDR5 : (ADC Offset: 0x44) ADC Channel Data Register 5 -------- +// -------- ADC_CDR6 : (ADC Offset: 0x48) ADC Channel Data Register 6 -------- +// -------- ADC_CDR7 : (ADC Offset: 0x4c) ADC Channel Data Register 7 -------- +// -------- ADC_ACR : (ADC Offset: 0x64) ADC Analog Controler Register -------- +#define AT91C_ADC_GAIN (0x3 << 0) // (ADC) Input Gain +#define AT91C_ADC_IBCTL (0x3 << 6) // (ADC) Bias Current Control +#define AT91C_ADC_IBCTL_00 (0x0 << 6) // (ADC) typ - 20% +#define AT91C_ADC_IBCTL_01 (0x1 << 6) // (ADC) typ +#define AT91C_ADC_IBCTL_10 (0x2 << 6) // (ADC) typ + 20% +#define AT91C_ADC_IBCTL_11 (0x3 << 6) // (ADC) typ + 40% +#define AT91C_ADC_DIFF (0x1 << 16) // (ADC) Differential Mode +#define AT91C_ADC_OFFSET (0x1 << 17) // (ADC) Input OFFSET +// -------- ADC_EMR : (ADC Offset: 0x68) ADC Extended Mode Register -------- +#define AT91C_OFFMODES (0x1 << 0) // (ADC) Off Mode if +#define AT91C_OFF_MODE_STARTUP_TIME (0x1 << 16) // (ADC) Startup Time +// -------- ADC_VER : (ADC Offset: 0xfc) ADC VER -------- +#define AT91C_ADC_VER (0xF << 0) // (ADC) ADC VER + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Timer Counter Channel Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_TC { + AT91_REG TC_CCR; // Channel Control Register + AT91_REG TC_CMR; // Channel Mode Register (Capture Mode / Waveform Mode) + AT91_REG Reserved0[2]; // + AT91_REG TC_CV; // Counter Value + AT91_REG TC_RA; // Register A + AT91_REG TC_RB; // Register B + AT91_REG TC_RC; // Register C + AT91_REG TC_SR; // Status Register + AT91_REG TC_IER; // Interrupt Enable Register + AT91_REG TC_IDR; // Interrupt Disable Register + AT91_REG TC_IMR; // Interrupt Mask Register +} AT91S_TC, *AT91PS_TC; +#else +#define TC_CCR (AT91_CAST(AT91_REG *) 0x00000000) // (TC_CCR) Channel Control Register +#define TC_CMR (AT91_CAST(AT91_REG *) 0x00000004) // (TC_CMR) Channel Mode Register (Capture Mode / Waveform Mode) +#define TC_CV (AT91_CAST(AT91_REG *) 0x00000010) // (TC_CV) Counter Value +#define TC_RA (AT91_CAST(AT91_REG *) 0x00000014) // (TC_RA) Register A +#define TC_RB (AT91_CAST(AT91_REG *) 0x00000018) // (TC_RB) Register B +#define TC_RC (AT91_CAST(AT91_REG *) 0x0000001C) // (TC_RC) Register C +#define TC_SR (AT91_CAST(AT91_REG *) 0x00000020) // (TC_SR) Status Register +#define TC_IER (AT91_CAST(AT91_REG *) 0x00000024) // (TC_IER) Interrupt Enable Register +#define TC_IDR (AT91_CAST(AT91_REG *) 0x00000028) // (TC_IDR) Interrupt Disable Register +#define TC_IMR (AT91_CAST(AT91_REG *) 0x0000002C) // (TC_IMR) Interrupt Mask Register + +#endif +// -------- TC_CCR : (TC Offset: 0x0) TC Channel Control Register -------- +#define AT91C_TC_CLKEN (0x1 << 0) // (TC) Counter Clock Enable Command +#define AT91C_TC_CLKDIS (0x1 << 1) // (TC) Counter Clock Disable Command +#define AT91C_TC_SWTRG (0x1 << 2) // (TC) Software Trigger Command +// -------- TC_CMR : (TC Offset: 0x4) TC Channel Mode Register: Capture Mode / Waveform Mode -------- +#define AT91C_TC_CLKS (0x7 << 0) // (TC) Clock Selection +#define AT91C_TC_CLKS_TIMER_DIV1_CLOCK (0x0) // (TC) Clock selected: TIMER_DIV1_CLOCK +#define AT91C_TC_CLKS_TIMER_DIV2_CLOCK (0x1) // (TC) Clock selected: TIMER_DIV2_CLOCK +#define AT91C_TC_CLKS_TIMER_DIV3_CLOCK (0x2) // (TC) Clock selected: TIMER_DIV3_CLOCK +#define AT91C_TC_CLKS_TIMER_DIV4_CLOCK (0x3) // (TC) Clock selected: TIMER_DIV4_CLOCK +#define AT91C_TC_CLKS_TIMER_DIV5_CLOCK (0x4) // (TC) Clock selected: TIMER_DIV5_CLOCK +#define AT91C_TC_CLKS_XC0 (0x5) // (TC) Clock selected: XC0 +#define AT91C_TC_CLKS_XC1 (0x6) // (TC) Clock selected: XC1 +#define AT91C_TC_CLKS_XC2 (0x7) // (TC) Clock selected: XC2 +#define AT91C_TC_CLKI (0x1 << 3) // (TC) Clock Invert +#define AT91C_TC_BURST (0x3 << 4) // (TC) Burst Signal Selection +#define AT91C_TC_BURST_NONE (0x0 << 4) // (TC) The clock is not gated by an external signal +#define AT91C_TC_BURST_XC0 (0x1 << 4) // (TC) XC0 is ANDed with the selected clock +#define AT91C_TC_BURST_XC1 (0x2 << 4) // (TC) XC1 is ANDed with the selected clock +#define AT91C_TC_BURST_XC2 (0x3 << 4) // (TC) XC2 is ANDed with the selected clock +#define AT91C_TC_CPCSTOP (0x1 << 6) // (TC) Counter Clock Stopped with RC Compare +#define AT91C_TC_LDBSTOP (0x1 << 6) // (TC) Counter Clock Stopped with RB Loading +#define AT91C_TC_CPCDIS (0x1 << 7) // (TC) Counter Clock Disable with RC Compare +#define AT91C_TC_LDBDIS (0x1 << 7) // (TC) Counter Clock Disabled with RB Loading +#define AT91C_TC_ETRGEDG (0x3 << 8) // (TC) External Trigger Edge Selection +#define AT91C_TC_ETRGEDG_NONE (0x0 << 8) // (TC) Edge: None +#define AT91C_TC_ETRGEDG_RISING (0x1 << 8) // (TC) Edge: rising edge +#define AT91C_TC_ETRGEDG_FALLING (0x2 << 8) // (TC) Edge: falling edge +#define AT91C_TC_ETRGEDG_BOTH (0x3 << 8) // (TC) Edge: each edge +#define AT91C_TC_EEVTEDG (0x3 << 8) // (TC) External Event Edge Selection +#define AT91C_TC_EEVTEDG_NONE (0x0 << 8) // (TC) Edge: None +#define AT91C_TC_EEVTEDG_RISING (0x1 << 8) // (TC) Edge: rising edge +#define AT91C_TC_EEVTEDG_FALLING (0x2 << 8) // (TC) Edge: falling edge +#define AT91C_TC_EEVTEDG_BOTH (0x3 << 8) // (TC) Edge: each edge +#define AT91C_TC_EEVT (0x3 << 10) // (TC) External Event Selection +#define AT91C_TC_EEVT_TIOB (0x0 << 10) // (TC) Signal selected as external event: TIOB TIOB direction: input +#define AT91C_TC_EEVT_XC0 (0x1 << 10) // (TC) Signal selected as external event: XC0 TIOB direction: output +#define AT91C_TC_EEVT_XC1 (0x2 << 10) // (TC) Signal selected as external event: XC1 TIOB direction: output +#define AT91C_TC_EEVT_XC2 (0x3 << 10) // (TC) Signal selected as external event: XC2 TIOB direction: output +#define AT91C_TC_ABETRG (0x1 << 10) // (TC) TIOA or TIOB External Trigger Selection +#define AT91C_TC_ENETRG (0x1 << 12) // (TC) External Event Trigger enable +#define AT91C_TC_WAVESEL (0x3 << 13) // (TC) Waveform Selection +#define AT91C_TC_WAVESEL_UP (0x0 << 13) // (TC) UP mode without atomatic trigger on RC Compare +#define AT91C_TC_WAVESEL_UPDOWN (0x1 << 13) // (TC) UPDOWN mode without automatic trigger on RC Compare +#define AT91C_TC_WAVESEL_UP_AUTO (0x2 << 13) // (TC) UP mode with automatic trigger on RC Compare +#define AT91C_TC_WAVESEL_UPDOWN_AUTO (0x3 << 13) // (TC) UPDOWN mode with automatic trigger on RC Compare +#define AT91C_TC_CPCTRG (0x1 << 14) // (TC) RC Compare Trigger Enable +#define AT91C_TC_WAVE (0x1 << 15) // (TC) +#define AT91C_TC_ACPA (0x3 << 16) // (TC) RA Compare Effect on TIOA +#define AT91C_TC_ACPA_NONE (0x0 << 16) // (TC) Effect: none +#define AT91C_TC_ACPA_SET (0x1 << 16) // (TC) Effect: set +#define AT91C_TC_ACPA_CLEAR (0x2 << 16) // (TC) Effect: clear +#define AT91C_TC_ACPA_TOGGLE (0x3 << 16) // (TC) Effect: toggle +#define AT91C_TC_LDRA (0x3 << 16) // (TC) RA Loading Selection +#define AT91C_TC_LDRA_NONE (0x0 << 16) // (TC) Edge: None +#define AT91C_TC_LDRA_RISING (0x1 << 16) // (TC) Edge: rising edge of TIOA +#define AT91C_TC_LDRA_FALLING (0x2 << 16) // (TC) Edge: falling edge of TIOA +#define AT91C_TC_LDRA_BOTH (0x3 << 16) // (TC) Edge: each edge of TIOA +#define AT91C_TC_ACPC (0x3 << 18) // (TC) RC Compare Effect on TIOA +#define AT91C_TC_ACPC_NONE (0x0 << 18) // (TC) Effect: none +#define AT91C_TC_ACPC_SET (0x1 << 18) // (TC) Effect: set +#define AT91C_TC_ACPC_CLEAR (0x2 << 18) // (TC) Effect: clear +#define AT91C_TC_ACPC_TOGGLE (0x3 << 18) // (TC) Effect: toggle +#define AT91C_TC_LDRB (0x3 << 18) // (TC) RB Loading Selection +#define AT91C_TC_LDRB_NONE (0x0 << 18) // (TC) Edge: None +#define AT91C_TC_LDRB_RISING (0x1 << 18) // (TC) Edge: rising edge of TIOA +#define AT91C_TC_LDRB_FALLING (0x2 << 18) // (TC) Edge: falling edge of TIOA +#define AT91C_TC_LDRB_BOTH (0x3 << 18) // (TC) Edge: each edge of TIOA +#define AT91C_TC_AEEVT (0x3 << 20) // (TC) External Event Effect on TIOA +#define AT91C_TC_AEEVT_NONE (0x0 << 20) // (TC) Effect: none +#define AT91C_TC_AEEVT_SET (0x1 << 20) // (TC) Effect: set +#define AT91C_TC_AEEVT_CLEAR (0x2 << 20) // (TC) Effect: clear +#define AT91C_TC_AEEVT_TOGGLE (0x3 << 20) // (TC) Effect: toggle +#define AT91C_TC_ASWTRG (0x3 << 22) // (TC) Software Trigger Effect on TIOA +#define AT91C_TC_ASWTRG_NONE (0x0 << 22) // (TC) Effect: none +#define AT91C_TC_ASWTRG_SET (0x1 << 22) // (TC) Effect: set +#define AT91C_TC_ASWTRG_CLEAR (0x2 << 22) // (TC) Effect: clear +#define AT91C_TC_ASWTRG_TOGGLE (0x3 << 22) // (TC) Effect: toggle +#define AT91C_TC_BCPB (0x3 << 24) // (TC) RB Compare Effect on TIOB +#define AT91C_TC_BCPB_NONE (0x0 << 24) // (TC) Effect: none +#define AT91C_TC_BCPB_SET (0x1 << 24) // (TC) Effect: set +#define AT91C_TC_BCPB_CLEAR (0x2 << 24) // (TC) Effect: clear +#define AT91C_TC_BCPB_TOGGLE (0x3 << 24) // (TC) Effect: toggle +#define AT91C_TC_BCPC (0x3 << 26) // (TC) RC Compare Effect on TIOB +#define AT91C_TC_BCPC_NONE (0x0 << 26) // (TC) Effect: none +#define AT91C_TC_BCPC_SET (0x1 << 26) // (TC) Effect: set +#define AT91C_TC_BCPC_CLEAR (0x2 << 26) // (TC) Effect: clear +#define AT91C_TC_BCPC_TOGGLE (0x3 << 26) // (TC) Effect: toggle +#define AT91C_TC_BEEVT (0x3 << 28) // (TC) External Event Effect on TIOB +#define AT91C_TC_BEEVT_NONE (0x0 << 28) // (TC) Effect: none +#define AT91C_TC_BEEVT_SET (0x1 << 28) // (TC) Effect: set +#define AT91C_TC_BEEVT_CLEAR (0x2 << 28) // (TC) Effect: clear +#define AT91C_TC_BEEVT_TOGGLE (0x3 << 28) // (TC) Effect: toggle +#define AT91C_TC_BSWTRG (0x3 << 30) // (TC) Software Trigger Effect on TIOB +#define AT91C_TC_BSWTRG_NONE (0x0 << 30) // (TC) Effect: none +#define AT91C_TC_BSWTRG_SET (0x1 << 30) // (TC) Effect: set +#define AT91C_TC_BSWTRG_CLEAR (0x2 << 30) // (TC) Effect: clear +#define AT91C_TC_BSWTRG_TOGGLE (0x3 << 30) // (TC) Effect: toggle +// -------- TC_SR : (TC Offset: 0x20) TC Channel Status Register -------- +#define AT91C_TC_COVFS (0x1 << 0) // (TC) Counter Overflow +#define AT91C_TC_LOVRS (0x1 << 1) // (TC) Load Overrun +#define AT91C_TC_CPAS (0x1 << 2) // (TC) RA Compare +#define AT91C_TC_CPBS (0x1 << 3) // (TC) RB Compare +#define AT91C_TC_CPCS (0x1 << 4) // (TC) RC Compare +#define AT91C_TC_LDRAS (0x1 << 5) // (TC) RA Loading +#define AT91C_TC_LDRBS (0x1 << 6) // (TC) RB Loading +#define AT91C_TC_ETRGS (0x1 << 7) // (TC) External Trigger +#define AT91C_TC_CLKSTA (0x1 << 16) // (TC) Clock Enabling +#define AT91C_TC_MTIOA (0x1 << 17) // (TC) TIOA Mirror +#define AT91C_TC_MTIOB (0x1 << 18) // (TC) TIOA Mirror +// -------- TC_IER : (TC Offset: 0x24) TC Channel Interrupt Enable Register -------- +// -------- TC_IDR : (TC Offset: 0x28) TC Channel Interrupt Disable Register -------- +// -------- TC_IMR : (TC Offset: 0x2c) TC Channel Interrupt Mask Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Timer Counter Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_TCB { + AT91S_TC TCB_TC0; // TC Channel 0 + AT91_REG Reserved0[4]; // + AT91S_TC TCB_TC1; // TC Channel 1 + AT91_REG Reserved1[4]; // + AT91S_TC TCB_TC2; // TC Channel 2 + AT91_REG Reserved2[4]; // + AT91_REG TCB_BCR; // TC Block Control Register + AT91_REG TCB_BMR; // TC Block Mode Register + AT91_REG Reserved3[9]; // + AT91_REG TCB_ADDRSIZE; // TC ADDRSIZE REGISTER + AT91_REG TCB_IPNAME1; // TC IPNAME1 REGISTER + AT91_REG TCB_IPNAME2; // TC IPNAME2 REGISTER + AT91_REG TCB_FEATURES; // TC FEATURES REGISTER + AT91_REG TCB_VER; // Version Register +} AT91S_TCB, *AT91PS_TCB; +#else +#define TCB_BCR (AT91_CAST(AT91_REG *) 0x000000C0) // (TCB_BCR) TC Block Control Register +#define TCB_BMR (AT91_CAST(AT91_REG *) 0x000000C4) // (TCB_BMR) TC Block Mode Register +#define TC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (TC_ADDRSIZE) TC ADDRSIZE REGISTER +#define TC_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (TC_IPNAME1) TC IPNAME1 REGISTER +#define TC_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (TC_IPNAME2) TC IPNAME2 REGISTER +#define TC_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (TC_FEATURES) TC FEATURES REGISTER +#define TC_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (TC_VER) Version Register + +#endif +// -------- TCB_BCR : (TCB Offset: 0xc0) TC Block Control Register -------- +#define AT91C_TCB_SYNC (0x1 << 0) // (TCB) Synchro Command +// -------- TCB_BMR : (TCB Offset: 0xc4) TC Block Mode Register -------- +#define AT91C_TCB_TC0XC0S (0x3 << 0) // (TCB) External Clock Signal 0 Selection +#define AT91C_TCB_TC0XC0S_TCLK0 (0x0) // (TCB) TCLK0 connected to XC0 +#define AT91C_TCB_TC0XC0S_NONE (0x1) // (TCB) None signal connected to XC0 +#define AT91C_TCB_TC0XC0S_TIOA1 (0x2) // (TCB) TIOA1 connected to XC0 +#define AT91C_TCB_TC0XC0S_TIOA2 (0x3) // (TCB) TIOA2 connected to XC0 +#define AT91C_TCB_TC1XC1S (0x3 << 2) // (TCB) External Clock Signal 1 Selection +#define AT91C_TCB_TC1XC1S_TCLK1 (0x0 << 2) // (TCB) TCLK1 connected to XC1 +#define AT91C_TCB_TC1XC1S_NONE (0x1 << 2) // (TCB) None signal connected to XC1 +#define AT91C_TCB_TC1XC1S_TIOA0 (0x2 << 2) // (TCB) TIOA0 connected to XC1 +#define AT91C_TCB_TC1XC1S_TIOA2 (0x3 << 2) // (TCB) TIOA2 connected to XC1 +#define AT91C_TCB_TC2XC2S (0x3 << 4) // (TCB) External Clock Signal 2 Selection +#define AT91C_TCB_TC2XC2S_TCLK2 (0x0 << 4) // (TCB) TCLK2 connected to XC2 +#define AT91C_TCB_TC2XC2S_NONE (0x1 << 4) // (TCB) None signal connected to XC2 +#define AT91C_TCB_TC2XC2S_TIOA0 (0x2 << 4) // (TCB) TIOA0 connected to XC2 +#define AT91C_TCB_TC2XC2S_TIOA1 (0x3 << 4) // (TCB) TIOA2 connected to XC2 + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Embedded Flash Controller 2.0 +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_EFC { + AT91_REG EFC_FMR; // EFC Flash Mode Register + AT91_REG EFC_FCR; // EFC Flash Command Register + AT91_REG EFC_FSR; // EFC Flash Status Register + AT91_REG EFC_FRR; // EFC Flash Result Register + AT91_REG Reserved0[1]; // + AT91_REG EFC_FVR; // EFC Flash Version Register +} AT91S_EFC, *AT91PS_EFC; +#else +#define EFC_FMR (AT91_CAST(AT91_REG *) 0x00000000) // (EFC_FMR) EFC Flash Mode Register +#define EFC_FCR (AT91_CAST(AT91_REG *) 0x00000004) // (EFC_FCR) EFC Flash Command Register +#define EFC_FSR (AT91_CAST(AT91_REG *) 0x00000008) // (EFC_FSR) EFC Flash Status Register +#define EFC_FRR (AT91_CAST(AT91_REG *) 0x0000000C) // (EFC_FRR) EFC Flash Result Register +#define EFC_FVR (AT91_CAST(AT91_REG *) 0x00000014) // (EFC_FVR) EFC Flash Version Register + +#endif +// -------- EFC_FMR : (EFC Offset: 0x0) EFC Flash Mode Register -------- +#define AT91C_EFC_FRDY (0x1 << 0) // (EFC) Ready Interrupt Enable +#define AT91C_EFC_FWS (0xF << 8) // (EFC) Flash Wait State. +#define AT91C_EFC_FWS_0WS (0x0 << 8) // (EFC) 0 Wait State +#define AT91C_EFC_FWS_1WS (0x1 << 8) // (EFC) 1 Wait State +#define AT91C_EFC_FWS_2WS (0x2 << 8) // (EFC) 2 Wait States +#define AT91C_EFC_FWS_3WS (0x3 << 8) // (EFC) 3 Wait States +// -------- EFC_FCR : (EFC Offset: 0x4) EFC Flash Command Register -------- +#define AT91C_EFC_FCMD (0xFF << 0) // (EFC) Flash Command +#define AT91C_EFC_FCMD_GETD (0x0) // (EFC) Get Flash Descriptor +#define AT91C_EFC_FCMD_WP (0x1) // (EFC) Write Page +#define AT91C_EFC_FCMD_WPL (0x2) // (EFC) Write Page and Lock +#define AT91C_EFC_FCMD_EWP (0x3) // (EFC) Erase Page and Write Page +#define AT91C_EFC_FCMD_EWPL (0x4) // (EFC) Erase Page and Write Page then Lock +#define AT91C_EFC_FCMD_EA (0x5) // (EFC) Erase All +#define AT91C_EFC_FCMD_EPL (0x6) // (EFC) Erase Plane +#define AT91C_EFC_FCMD_EPA (0x7) // (EFC) Erase Pages +#define AT91C_EFC_FCMD_SLB (0x8) // (EFC) Set Lock Bit +#define AT91C_EFC_FCMD_CLB (0x9) // (EFC) Clear Lock Bit +#define AT91C_EFC_FCMD_GLB (0xA) // (EFC) Get Lock Bit +#define AT91C_EFC_FCMD_SFB (0xB) // (EFC) Set Fuse Bit +#define AT91C_EFC_FCMD_CFB (0xC) // (EFC) Clear Fuse Bit +#define AT91C_EFC_FCMD_GFB (0xD) // (EFC) Get Fuse Bit +#define AT91C_EFC_FCMD_STUI (0xE) // (EFC) Start Read Unique ID +#define AT91C_EFC_FCMD_SPUI (0xF) // (EFC) Stop Read Unique ID +#define AT91C_EFC_FARG (0xFFFF << 8) // (EFC) Flash Command Argument +#define AT91C_EFC_FKEY (0xFF << 24) // (EFC) Flash Writing Protection Key +// -------- EFC_FSR : (EFC Offset: 0x8) EFC Flash Status Register -------- +#define AT91C_EFC_FRDY_S (0x1 << 0) // (EFC) Flash Ready Status +#define AT91C_EFC_FCMDE (0x1 << 1) // (EFC) Flash Command Error Status +#define AT91C_EFC_LOCKE (0x1 << 2) // (EFC) Flash Lock Error Status +// -------- EFC_FRR : (EFC Offset: 0xc) EFC Flash Result Register -------- +#define AT91C_EFC_FVALUE (0x0 << 0) // (EFC) Flash Result Value + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Multimedia Card Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_MCI { + AT91_REG MCI_CR; // MCI Control Register + AT91_REG MCI_MR; // MCI Mode Register + AT91_REG MCI_DTOR; // MCI Data Timeout Register + AT91_REG MCI_SDCR; // MCI SD/SDIO Card Register + AT91_REG MCI_ARGR; // MCI Argument Register + AT91_REG MCI_CMDR; // MCI Command Register + AT91_REG MCI_BLKR; // MCI Block Register + AT91_REG MCI_CSTOR; // MCI Completion Signal Timeout Register + AT91_REG MCI_RSPR[4]; // MCI Response Register + AT91_REG MCI_RDR; // MCI Receive Data Register + AT91_REG MCI_TDR; // MCI Transmit Data Register + AT91_REG Reserved0[2]; // + AT91_REG MCI_SR; // MCI Status Register + AT91_REG MCI_IER; // MCI Interrupt Enable Register + AT91_REG MCI_IDR; // MCI Interrupt Disable Register + AT91_REG MCI_IMR; // MCI Interrupt Mask Register + AT91_REG MCI_DMA; // MCI DMA Configuration Register + AT91_REG MCI_CFG; // MCI Configuration Register + AT91_REG Reserved1[35]; // + AT91_REG MCI_WPCR; // MCI Write Protection Control Register + AT91_REG MCI_WPSR; // MCI Write Protection Status Register + AT91_REG MCI_ADDRSIZE; // MCI ADDRSIZE REGISTER + AT91_REG MCI_IPNAME1; // MCI IPNAME1 REGISTER + AT91_REG MCI_IPNAME2; // MCI IPNAME2 REGISTER + AT91_REG MCI_FEATURES; // MCI FEATURES REGISTER + AT91_REG MCI_VER; // MCI VERSION REGISTER + AT91_REG MCI_RPR; // Receive Pointer Register + AT91_REG MCI_RCR; // Receive Counter Register + AT91_REG MCI_TPR; // Transmit Pointer Register + AT91_REG MCI_TCR; // Transmit Counter Register + AT91_REG MCI_RNPR; // Receive Next Pointer Register + AT91_REG MCI_RNCR; // Receive Next Counter Register + AT91_REG MCI_TNPR; // Transmit Next Pointer Register + AT91_REG MCI_TNCR; // Transmit Next Counter Register + AT91_REG MCI_PTCR; // PDC Transfer Control Register + AT91_REG MCI_PTSR; // PDC Transfer Status Register + AT91_REG Reserved2[54]; // + AT91_REG MCI_FIFO; // MCI FIFO Aperture Register +} AT91S_MCI, *AT91PS_MCI; +#else +#define MCI_CR (AT91_CAST(AT91_REG *) 0x00000000) // (MCI_CR) MCI Control Register +#define MCI_MR (AT91_CAST(AT91_REG *) 0x00000004) // (MCI_MR) MCI Mode Register +#define MCI_DTOR (AT91_CAST(AT91_REG *) 0x00000008) // (MCI_DTOR) MCI Data Timeout Register +#define MCI_SDCR (AT91_CAST(AT91_REG *) 0x0000000C) // (MCI_SDCR) MCI SD/SDIO Card Register +#define MCI_ARGR (AT91_CAST(AT91_REG *) 0x00000010) // (MCI_ARGR) MCI Argument Register +#define MCI_CMDR (AT91_CAST(AT91_REG *) 0x00000014) // (MCI_CMDR) MCI Command Register +#define MCI_BLKR (AT91_CAST(AT91_REG *) 0x00000018) // (MCI_BLKR) MCI Block Register +#define MCI_CSTOR (AT91_CAST(AT91_REG *) 0x0000001C) // (MCI_CSTOR) MCI Completion Signal Timeout Register +#define MCI_RSPR (AT91_CAST(AT91_REG *) 0x00000020) // (MCI_RSPR) MCI Response Register +#define MCI_RDR (AT91_CAST(AT91_REG *) 0x00000030) // (MCI_RDR) MCI Receive Data Register +#define MCI_TDR (AT91_CAST(AT91_REG *) 0x00000034) // (MCI_TDR) MCI Transmit Data Register +#define MCI_SR (AT91_CAST(AT91_REG *) 0x00000040) // (MCI_SR) MCI Status Register +#define MCI_IER (AT91_CAST(AT91_REG *) 0x00000044) // (MCI_IER) MCI Interrupt Enable Register +#define MCI_IDR (AT91_CAST(AT91_REG *) 0x00000048) // (MCI_IDR) MCI Interrupt Disable Register +#define MCI_IMR (AT91_CAST(AT91_REG *) 0x0000004C) // (MCI_IMR) MCI Interrupt Mask Register +#define MCI_DMA (AT91_CAST(AT91_REG *) 0x00000050) // (MCI_DMA) MCI DMA Configuration Register +#define MCI_CFG (AT91_CAST(AT91_REG *) 0x00000054) // (MCI_CFG) MCI Configuration Register +#define MCI_WPCR (AT91_CAST(AT91_REG *) 0x000000E4) // (MCI_WPCR) MCI Write Protection Control Register +#define MCI_WPSR (AT91_CAST(AT91_REG *) 0x000000E8) // (MCI_WPSR) MCI Write Protection Status Register +#define MCI_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (MCI_ADDRSIZE) MCI ADDRSIZE REGISTER +#define MCI_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (MCI_IPNAME1) MCI IPNAME1 REGISTER +#define MCI_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (MCI_IPNAME2) MCI IPNAME2 REGISTER +#define MCI_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (MCI_FEATURES) MCI FEATURES REGISTER +#define MCI_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (MCI_VER) MCI VERSION REGISTER +#define MCI_FIFO (AT91_CAST(AT91_REG *) 0x00000200) // (MCI_FIFO) MCI FIFO Aperture Register + +#endif +// -------- MCI_CR : (MCI Offset: 0x0) MCI Control Register -------- +#define AT91C_MCI_MCIEN (0x1 << 0) // (MCI) Multimedia Interface Enable +#define AT91C_MCI_MCIEN_0 (0x0) // (MCI) No effect +#define AT91C_MCI_MCIEN_1 (0x1) // (MCI) Enable the MultiMedia Interface if MCIDIS is 0 +#define AT91C_MCI_MCIDIS (0x1 << 1) // (MCI) Multimedia Interface Disable +#define AT91C_MCI_MCIDIS_0 (0x0 << 1) // (MCI) No effect +#define AT91C_MCI_MCIDIS_1 (0x1 << 1) // (MCI) Disable the MultiMedia Interface +#define AT91C_MCI_PWSEN (0x1 << 2) // (MCI) Power Save Mode Enable +#define AT91C_MCI_PWSEN_0 (0x0 << 2) // (MCI) No effect +#define AT91C_MCI_PWSEN_1 (0x1 << 2) // (MCI) Enable the Power-saving mode if PWSDIS is 0. +#define AT91C_MCI_PWSDIS (0x1 << 3) // (MCI) Power Save Mode Disable +#define AT91C_MCI_PWSDIS_0 (0x0 << 3) // (MCI) No effect +#define AT91C_MCI_PWSDIS_1 (0x1 << 3) // (MCI) Disable the Power-saving mode. +#define AT91C_MCI_IOWAITEN (0x1 << 4) // (MCI) SDIO Read Wait Enable +#define AT91C_MCI_IOWAITEN_0 (0x0 << 4) // (MCI) No effect +#define AT91C_MCI_IOWAITEN_1 (0x1 << 4) // (MCI) Enables the SDIO Read Wait Operation. +#define AT91C_MCI_IOWAITDIS (0x1 << 5) // (MCI) SDIO Read Wait Disable +#define AT91C_MCI_IOWAITDIS_0 (0x0 << 5) // (MCI) No effect +#define AT91C_MCI_IOWAITDIS_1 (0x1 << 5) // (MCI) Disables the SDIO Read Wait Operation. +#define AT91C_MCI_SWRST (0x1 << 7) // (MCI) MCI Software reset +#define AT91C_MCI_SWRST_0 (0x0 << 7) // (MCI) No effect +#define AT91C_MCI_SWRST_1 (0x1 << 7) // (MCI) Resets the MCI +// -------- MCI_MR : (MCI Offset: 0x4) MCI Mode Register -------- +#define AT91C_MCI_CLKDIV (0xFF << 0) // (MCI) Clock Divider +#define AT91C_MCI_PWSDIV (0x7 << 8) // (MCI) Power Saving Divider +#define AT91C_MCI_RDPROOF (0x1 << 11) // (MCI) Read Proof Enable +#define AT91C_MCI_RDPROOF_DISABLE (0x0 << 11) // (MCI) Disables Read Proof +#define AT91C_MCI_RDPROOF_ENABLE (0x1 << 11) // (MCI) Enables Read Proof +#define AT91C_MCI_WRPROOF (0x1 << 12) // (MCI) Write Proof Enable +#define AT91C_MCI_WRPROOF_DISABLE (0x0 << 12) // (MCI) Disables Write Proof +#define AT91C_MCI_WRPROOF_ENABLE (0x1 << 12) // (MCI) Enables Write Proof +#define AT91C_MCI_PDCFBYTE (0x1 << 13) // (MCI) PDC Force Byte Transfer +#define AT91C_MCI_PDCFBYTE_DISABLE (0x0 << 13) // (MCI) Disables PDC Force Byte Transfer +#define AT91C_MCI_PDCFBYTE_ENABLE (0x1 << 13) // (MCI) Enables PDC Force Byte Transfer +#define AT91C_MCI_PDCPADV (0x1 << 14) // (MCI) PDC Padding Value +#define AT91C_MCI_PDCMODE (0x1 << 15) // (MCI) PDC Oriented Mode +#define AT91C_MCI_PDCMODE_DISABLE (0x0 << 15) // (MCI) Disables PDC Transfer +#define AT91C_MCI_PDCMODE_ENABLE (0x1 << 15) // (MCI) Enables PDC Transfer +#define AT91C_MCI_BLKLEN (0xFFFF << 16) // (MCI) Data Block Length +// -------- MCI_DTOR : (MCI Offset: 0x8) MCI Data Timeout Register -------- +#define AT91C_MCI_DTOCYC (0xF << 0) // (MCI) Data Timeout Cycle Number +#define AT91C_MCI_DTOMUL (0x7 << 4) // (MCI) Data Timeout Multiplier +#define AT91C_MCI_DTOMUL_1 (0x0 << 4) // (MCI) DTOCYC x 1 +#define AT91C_MCI_DTOMUL_16 (0x1 << 4) // (MCI) DTOCYC x 16 +#define AT91C_MCI_DTOMUL_128 (0x2 << 4) // (MCI) DTOCYC x 128 +#define AT91C_MCI_DTOMUL_256 (0x3 << 4) // (MCI) DTOCYC x 256 +#define AT91C_MCI_DTOMUL_1024 (0x4 << 4) // (MCI) DTOCYC x 1024 +#define AT91C_MCI_DTOMUL_4096 (0x5 << 4) // (MCI) DTOCYC x 4096 +#define AT91C_MCI_DTOMUL_65536 (0x6 << 4) // (MCI) DTOCYC x 65536 +#define AT91C_MCI_DTOMUL_1048576 (0x7 << 4) // (MCI) DTOCYC x 1048576 +// -------- MCI_SDCR : (MCI Offset: 0xc) MCI SD Card Register -------- +#define AT91C_MCI_SCDSEL (0x3 << 0) // (MCI) SD Card/SDIO Selector +#define AT91C_MCI_SCDSEL_SLOTA (0x0) // (MCI) Slot A selected +#define AT91C_MCI_SCDSEL_SLOTB (0x1) // (MCI) Slot B selected +#define AT91C_MCI_SCDSEL_SLOTC (0x2) // (MCI) Slot C selected +#define AT91C_MCI_SCDSEL_SLOTD (0x3) // (MCI) Slot D selected +#define AT91C_MCI_SCDBUS (0x3 << 6) // (MCI) SDCard/SDIO Bus Width +#define AT91C_MCI_SCDBUS_1BIT (0x0 << 6) // (MCI) 1-bit data bus +#define AT91C_MCI_SCDBUS_4BITS (0x2 << 6) // (MCI) 4-bits data bus +#define AT91C_MCI_SCDBUS_8BITS (0x3 << 6) // (MCI) 8-bits data bus +// -------- MCI_CMDR : (MCI Offset: 0x14) MCI Command Register -------- +#define AT91C_MCI_CMDNB (0x3F << 0) // (MCI) Command Number +#define AT91C_MCI_RSPTYP (0x3 << 6) // (MCI) Response Type +#define AT91C_MCI_RSPTYP_NO (0x0 << 6) // (MCI) No response +#define AT91C_MCI_RSPTYP_48 (0x1 << 6) // (MCI) 48-bit response +#define AT91C_MCI_RSPTYP_136 (0x2 << 6) // (MCI) 136-bit response +#define AT91C_MCI_RSPTYP_R1B (0x3 << 6) // (MCI) R1b response +#define AT91C_MCI_SPCMD (0x7 << 8) // (MCI) Special CMD +#define AT91C_MCI_SPCMD_NONE (0x0 << 8) // (MCI) Not a special CMD +#define AT91C_MCI_SPCMD_INIT (0x1 << 8) // (MCI) Initialization CMD +#define AT91C_MCI_SPCMD_SYNC (0x2 << 8) // (MCI) Synchronized CMD +#define AT91C_MCI_SPCMD_CE_ATA (0x3 << 8) // (MCI) CE-ATA Completion Signal disable CMD +#define AT91C_MCI_SPCMD_IT_CMD (0x4 << 8) // (MCI) Interrupt command +#define AT91C_MCI_SPCMD_IT_REP (0x5 << 8) // (MCI) Interrupt response +#define AT91C_MCI_SPCMD_BOOTREQ (0x6 << 8) // (MCI) Boot Operation Request +#define AT91C_MCI_SPCMD_BOOTEND (0x7 << 8) // (MCI) End Boot Operation +#define AT91C_MCI_OPDCMD (0x1 << 11) // (MCI) Open Drain Command +#define AT91C_MCI_OPDCMD_PUSHPULL (0x0 << 11) // (MCI) Push/pull command +#define AT91C_MCI_OPDCMD_OPENDRAIN (0x1 << 11) // (MCI) Open drain command +#define AT91C_MCI_MAXLAT (0x1 << 12) // (MCI) Maximum Latency for Command to respond +#define AT91C_MCI_MAXLAT_5 (0x0 << 12) // (MCI) 5 cycles maximum latency +#define AT91C_MCI_MAXLAT_64 (0x1 << 12) // (MCI) 64 cycles maximum latency +#define AT91C_MCI_TRCMD (0x3 << 16) // (MCI) Transfer CMD +#define AT91C_MCI_TRCMD_NO (0x0 << 16) // (MCI) No transfer +#define AT91C_MCI_TRCMD_START (0x1 << 16) // (MCI) Start transfer +#define AT91C_MCI_TRCMD_STOP (0x2 << 16) // (MCI) Stop transfer +#define AT91C_MCI_TRDIR (0x1 << 18) // (MCI) Transfer Direction +#define AT91C_MCI_TRDIR_WRITE (0x0 << 18) // (MCI) Write +#define AT91C_MCI_TRDIR_READ (0x1 << 18) // (MCI) Read +#define AT91C_MCI_TRTYP (0x7 << 19) // (MCI) Transfer Type +#define AT91C_MCI_TRTYP_BLOCK (0x0 << 19) // (MCI) MMC/SDCard Single Block Transfer type +#define AT91C_MCI_TRTYP_MULTIPLE (0x1 << 19) // (MCI) MMC/SDCard Multiple Block transfer type +#define AT91C_MCI_TRTYP_STREAM (0x2 << 19) // (MCI) MMC Stream transfer type +#define AT91C_MCI_TRTYP_SDIO_BYTE (0x4 << 19) // (MCI) SDIO Byte transfer type +#define AT91C_MCI_TRTYP_SDIO_BLOCK (0x5 << 19) // (MCI) SDIO Block transfer type +#define AT91C_MCI_IOSPCMD (0x3 << 24) // (MCI) SDIO Special Command +#define AT91C_MCI_IOSPCMD_NONE (0x0 << 24) // (MCI) NOT a special command +#define AT91C_MCI_IOSPCMD_SUSPEND (0x1 << 24) // (MCI) SDIO Suspend Command +#define AT91C_MCI_IOSPCMD_RESUME (0x2 << 24) // (MCI) SDIO Resume Command +#define AT91C_MCI_ATACS (0x1 << 26) // (MCI) ATA with command completion signal +#define AT91C_MCI_ATACS_NORMAL (0x0 << 26) // (MCI) normal operation mode +#define AT91C_MCI_ATACS_COMPLETION (0x1 << 26) // (MCI) completion signal is expected within MCI_CSTOR +#define AT91C_MCI_BOOTACK (0x1 << 27) // (MCI) Boot Operation Acknowledge +#define AT91C_MCI_BOOTACK_DISABLE (0x0 << 27) // (MCI) Boot Operation Acknowledge Disabled +#define AT91C_MCI_BOOTACK_ENABLE (0x1 << 27) // (MCI) Boot Operation Acknowledge Enabled +// -------- MCI_BLKR : (MCI Offset: 0x18) MCI Block Register -------- +#define AT91C_MCI_BCNT (0xFFFF << 0) // (MCI) MMC/SDIO Block Count / SDIO Byte Count +// -------- MCI_CSTOR : (MCI Offset: 0x1c) MCI Completion Signal Timeout Register -------- +#define AT91C_MCI_CSTOCYC (0xF << 0) // (MCI) Completion Signal Timeout Cycle Number +#define AT91C_MCI_CSTOMUL (0x7 << 4) // (MCI) Completion Signal Timeout Multiplier +#define AT91C_MCI_CSTOMUL_1 (0x0 << 4) // (MCI) CSTOCYC x 1 +#define AT91C_MCI_CSTOMUL_16 (0x1 << 4) // (MCI) CSTOCYC x 16 +#define AT91C_MCI_CSTOMUL_128 (0x2 << 4) // (MCI) CSTOCYC x 128 +#define AT91C_MCI_CSTOMUL_256 (0x3 << 4) // (MCI) CSTOCYC x 256 +#define AT91C_MCI_CSTOMUL_1024 (0x4 << 4) // (MCI) CSTOCYC x 1024 +#define AT91C_MCI_CSTOMUL_4096 (0x5 << 4) // (MCI) CSTOCYC x 4096 +#define AT91C_MCI_CSTOMUL_65536 (0x6 << 4) // (MCI) CSTOCYC x 65536 +#define AT91C_MCI_CSTOMUL_1048576 (0x7 << 4) // (MCI) CSTOCYC x 1048576 +// -------- MCI_SR : (MCI Offset: 0x40) MCI Status Register -------- +#define AT91C_MCI_CMDRDY (0x1 << 0) // (MCI) Command Ready flag +#define AT91C_MCI_RXRDY (0x1 << 1) // (MCI) RX Ready flag +#define AT91C_MCI_TXRDY (0x1 << 2) // (MCI) TX Ready flag +#define AT91C_MCI_BLKE (0x1 << 3) // (MCI) Data Block Transfer Ended flag +#define AT91C_MCI_DTIP (0x1 << 4) // (MCI) Data Transfer in Progress flag +#define AT91C_MCI_NOTBUSY (0x1 << 5) // (MCI) Data Line Not Busy flag +#define AT91C_MCI_ENDRX (0x1 << 6) // (MCI) End of RX Buffer flag +#define AT91C_MCI_ENDTX (0x1 << 7) // (MCI) End of TX Buffer flag +#define AT91C_MCI_SDIOIRQA (0x1 << 8) // (MCI) SDIO Interrupt for Slot A +#define AT91C_MCI_SDIOIRQB (0x1 << 9) // (MCI) SDIO Interrupt for Slot B +#define AT91C_MCI_SDIOIRQC (0x1 << 10) // (MCI) SDIO Interrupt for Slot C +#define AT91C_MCI_SDIOIRQD (0x1 << 11) // (MCI) SDIO Interrupt for Slot D +#define AT91C_MCI_SDIOWAIT (0x1 << 12) // (MCI) SDIO Read Wait operation flag +#define AT91C_MCI_CSRCV (0x1 << 13) // (MCI) CE-ATA Completion Signal flag +#define AT91C_MCI_RXBUFF (0x1 << 14) // (MCI) RX Buffer Full flag +#define AT91C_MCI_TXBUFE (0x1 << 15) // (MCI) TX Buffer Empty flag +#define AT91C_MCI_RINDE (0x1 << 16) // (MCI) Response Index Error flag +#define AT91C_MCI_RDIRE (0x1 << 17) // (MCI) Response Direction Error flag +#define AT91C_MCI_RCRCE (0x1 << 18) // (MCI) Response CRC Error flag +#define AT91C_MCI_RENDE (0x1 << 19) // (MCI) Response End Bit Error flag +#define AT91C_MCI_RTOE (0x1 << 20) // (MCI) Response Time-out Error flag +#define AT91C_MCI_DCRCE (0x1 << 21) // (MCI) data CRC Error flag +#define AT91C_MCI_DTOE (0x1 << 22) // (MCI) Data timeout Error flag +#define AT91C_MCI_CSTOE (0x1 << 23) // (MCI) Completion Signal timeout Error flag +#define AT91C_MCI_BLKOVRE (0x1 << 24) // (MCI) DMA Block Overrun Error flag +#define AT91C_MCI_DMADONE (0x1 << 25) // (MCI) DMA Transfer Done flag +#define AT91C_MCI_FIFOEMPTY (0x1 << 26) // (MCI) FIFO Empty flag +#define AT91C_MCI_XFRDONE (0x1 << 27) // (MCI) Transfer Done flag +#define AT91C_MCI_OVRE (0x1 << 30) // (MCI) Overrun flag +#define AT91C_MCI_UNRE (0x1 << 31) // (MCI) Underrun flag +// -------- MCI_IER : (MCI Offset: 0x44) MCI Interrupt Enable Register -------- +// -------- MCI_IDR : (MCI Offset: 0x48) MCI Interrupt Disable Register -------- +// -------- MCI_IMR : (MCI Offset: 0x4c) MCI Interrupt Mask Register -------- +// -------- MCI_DMA : (MCI Offset: 0x50) MCI DMA Configuration Register -------- +#define AT91C_MCI_OFFSET (0x3 << 0) // (MCI) DMA Write Buffer Offset +#define AT91C_MCI_CHKSIZE (0x7 << 4) // (MCI) DMA Channel Read/Write Chunk Size +#define AT91C_MCI_CHKSIZE_1 (0x0 << 4) // (MCI) Number of data transferred is 1 +#define AT91C_MCI_CHKSIZE_4 (0x1 << 4) // (MCI) Number of data transferred is 4 +#define AT91C_MCI_CHKSIZE_8 (0x2 << 4) // (MCI) Number of data transferred is 8 +#define AT91C_MCI_CHKSIZE_16 (0x3 << 4) // (MCI) Number of data transferred is 16 +#define AT91C_MCI_CHKSIZE_32 (0x4 << 4) // (MCI) Number of data transferred is 32 +#define AT91C_MCI_DMAEN (0x1 << 8) // (MCI) DMA Hardware Handshaking Enable +#define AT91C_MCI_DMAEN_DISABLE (0x0 << 8) // (MCI) DMA interface is disabled +#define AT91C_MCI_DMAEN_ENABLE (0x1 << 8) // (MCI) DMA interface is enabled +// -------- MCI_CFG : (MCI Offset: 0x54) MCI Configuration Register -------- +#define AT91C_MCI_FIFOMODE (0x1 << 0) // (MCI) MCI Internal FIFO Control Mode +#define AT91C_MCI_FIFOMODE_AMOUNTDATA (0x0) // (MCI) A write transfer starts when a sufficient amount of datas is written into the FIFO +#define AT91C_MCI_FIFOMODE_ONEDATA (0x1) // (MCI) A write transfer starts as soon as one data is written into the FIFO +#define AT91C_MCI_FERRCTRL (0x1 << 4) // (MCI) Flow Error Flag Reset Control Mode +#define AT91C_MCI_FERRCTRL_RWCMD (0x0 << 4) // (MCI) When an underflow/overflow condition flag is set, a new Write/Read command is needed to reset the flag +#define AT91C_MCI_FERRCTRL_READSR (0x1 << 4) // (MCI) When an underflow/overflow condition flag is set, a read status resets the flag +#define AT91C_MCI_HSMODE (0x1 << 8) // (MCI) High Speed Mode +#define AT91C_MCI_HSMODE_DISABLE (0x0 << 8) // (MCI) Default Bus Timing Mode +#define AT91C_MCI_HSMODE_ENABLE (0x1 << 8) // (MCI) High Speed Mode +#define AT91C_MCI_LSYNC (0x1 << 12) // (MCI) Synchronize on last block +#define AT91C_MCI_LSYNC_CURRENT (0x0 << 12) // (MCI) Pending command sent at end of current data block +#define AT91C_MCI_LSYNC_INFINITE (0x1 << 12) // (MCI) Pending command sent at end of block transfer when transfer length is not infinite +// -------- MCI_WPCR : (MCI Offset: 0xe4) Write Protection Control Register -------- +#define AT91C_MCI_WP_EN (0x1 << 0) // (MCI) Write Protection Enable +#define AT91C_MCI_WP_EN_DISABLE (0x0) // (MCI) Write Operation is disabled (if WP_KEY corresponds) +#define AT91C_MCI_WP_EN_ENABLE (0x1) // (MCI) Write Operation is enabled (if WP_KEY corresponds) +#define AT91C_MCI_WP_KEY (0xFFFFFF << 8) // (MCI) Write Protection Key +// -------- MCI_WPSR : (MCI Offset: 0xe8) Write Protection Status Register -------- +#define AT91C_MCI_WP_VS (0xF << 0) // (MCI) Write Protection Violation Status +#define AT91C_MCI_WP_VS_NO_VIOLATION (0x0) // (MCI) No Write Protection Violation detected since last read +#define AT91C_MCI_WP_VS_ON_WRITE (0x1) // (MCI) Write Protection Violation detected since last read +#define AT91C_MCI_WP_VS_ON_RESET (0x2) // (MCI) Software Reset Violation detected since last read +#define AT91C_MCI_WP_VS_ON_BOTH (0x3) // (MCI) Write Protection and Software Reset Violation detected since last read +#define AT91C_MCI_WP_VSRC (0xF << 8) // (MCI) Write Protection Violation Source +#define AT91C_MCI_WP_VSRC_NO_VIOLATION (0x0 << 8) // (MCI) No Write Protection Violation detected since last read +#define AT91C_MCI_WP_VSRC_MCI_MR (0x1 << 8) // (MCI) Write Protection Violation detected on MCI_MR since last read +#define AT91C_MCI_WP_VSRC_MCI_DTOR (0x2 << 8) // (MCI) Write Protection Violation detected on MCI_DTOR since last read +#define AT91C_MCI_WP_VSRC_MCI_SDCR (0x3 << 8) // (MCI) Write Protection Violation detected on MCI_SDCR since last read +#define AT91C_MCI_WP_VSRC_MCI_CSTOR (0x4 << 8) // (MCI) Write Protection Violation detected on MCI_CSTOR since last read +#define AT91C_MCI_WP_VSRC_MCI_DMA (0x5 << 8) // (MCI) Write Protection Violation detected on MCI_DMA since last read +#define AT91C_MCI_WP_VSRC_MCI_CFG (0x6 << 8) // (MCI) Write Protection Violation detected on MCI_CFG since last read +#define AT91C_MCI_WP_VSRC_MCI_DEL (0x7 << 8) // (MCI) Write Protection Violation detected on MCI_DEL since last read +// -------- MCI_VER : (MCI Offset: 0xfc) VERSION Register -------- +#define AT91C_MCI_VER (0xF << 0) // (MCI) VERSION Register + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Two-wire Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_TWI { + AT91_REG TWI_CR; // Control Register + AT91_REG TWI_MMR; // Master Mode Register + AT91_REG TWI_SMR; // Slave Mode Register + AT91_REG TWI_IADR; // Internal Address Register + AT91_REG TWI_CWGR; // Clock Waveform Generator Register + AT91_REG Reserved0[3]; // + AT91_REG TWI_SR; // Status Register + AT91_REG TWI_IER; // Interrupt Enable Register + AT91_REG TWI_IDR; // Interrupt Disable Register + AT91_REG TWI_IMR; // Interrupt Mask Register + AT91_REG TWI_RHR; // Receive Holding Register + AT91_REG TWI_THR; // Transmit Holding Register + AT91_REG Reserved1[45]; // + AT91_REG TWI_ADDRSIZE; // TWI ADDRSIZE REGISTER + AT91_REG TWI_IPNAME1; // TWI IPNAME1 REGISTER + AT91_REG TWI_IPNAME2; // TWI IPNAME2 REGISTER + AT91_REG TWI_FEATURES; // TWI FEATURES REGISTER + AT91_REG TWI_VER; // Version Register + AT91_REG TWI_RPR; // Receive Pointer Register + AT91_REG TWI_RCR; // Receive Counter Register + AT91_REG TWI_TPR; // Transmit Pointer Register + AT91_REG TWI_TCR; // Transmit Counter Register + AT91_REG TWI_RNPR; // Receive Next Pointer Register + AT91_REG TWI_RNCR; // Receive Next Counter Register + AT91_REG TWI_TNPR; // Transmit Next Pointer Register + AT91_REG TWI_TNCR; // Transmit Next Counter Register + AT91_REG TWI_PTCR; // PDC Transfer Control Register + AT91_REG TWI_PTSR; // PDC Transfer Status Register +} AT91S_TWI, *AT91PS_TWI; +#else +#define TWI_CR (AT91_CAST(AT91_REG *) 0x00000000) // (TWI_CR) Control Register +#define TWI_MMR (AT91_CAST(AT91_REG *) 0x00000004) // (TWI_MMR) Master Mode Register +#define TWI_SMR (AT91_CAST(AT91_REG *) 0x00000008) // (TWI_SMR) Slave Mode Register +#define TWI_IADR (AT91_CAST(AT91_REG *) 0x0000000C) // (TWI_IADR) Internal Address Register +#define TWI_CWGR (AT91_CAST(AT91_REG *) 0x00000010) // (TWI_CWGR) Clock Waveform Generator Register +#define TWI_SR (AT91_CAST(AT91_REG *) 0x00000020) // (TWI_SR) Status Register +#define TWI_IER (AT91_CAST(AT91_REG *) 0x00000024) // (TWI_IER) Interrupt Enable Register +#define TWI_IDR (AT91_CAST(AT91_REG *) 0x00000028) // (TWI_IDR) Interrupt Disable Register +#define TWI_IMR (AT91_CAST(AT91_REG *) 0x0000002C) // (TWI_IMR) Interrupt Mask Register +#define TWI_RHR (AT91_CAST(AT91_REG *) 0x00000030) // (TWI_RHR) Receive Holding Register +#define TWI_THR (AT91_CAST(AT91_REG *) 0x00000034) // (TWI_THR) Transmit Holding Register +#define TWI_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (TWI_ADDRSIZE) TWI ADDRSIZE REGISTER +#define TWI_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (TWI_IPNAME1) TWI IPNAME1 REGISTER +#define TWI_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (TWI_IPNAME2) TWI IPNAME2 REGISTER +#define TWI_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (TWI_FEATURES) TWI FEATURES REGISTER +#define TWI_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (TWI_VER) Version Register + +#endif +// -------- TWI_CR : (TWI Offset: 0x0) TWI Control Register -------- +#define AT91C_TWI_START (0x1 << 0) // (TWI) Send a START Condition +#define AT91C_TWI_STOP (0x1 << 1) // (TWI) Send a STOP Condition +#define AT91C_TWI_MSEN (0x1 << 2) // (TWI) TWI Master Transfer Enabled +#define AT91C_TWI_MSDIS (0x1 << 3) // (TWI) TWI Master Transfer Disabled +#define AT91C_TWI_SVEN (0x1 << 4) // (TWI) TWI Slave mode Enabled +#define AT91C_TWI_SVDIS (0x1 << 5) // (TWI) TWI Slave mode Disabled +#define AT91C_TWI_SWRST (0x1 << 7) // (TWI) Software Reset +// -------- TWI_MMR : (TWI Offset: 0x4) TWI Master Mode Register -------- +#define AT91C_TWI_IADRSZ (0x3 << 8) // (TWI) Internal Device Address Size +#define AT91C_TWI_IADRSZ_NO (0x0 << 8) // (TWI) No internal device address +#define AT91C_TWI_IADRSZ_1_BYTE (0x1 << 8) // (TWI) One-byte internal device address +#define AT91C_TWI_IADRSZ_2_BYTE (0x2 << 8) // (TWI) Two-byte internal device address +#define AT91C_TWI_IADRSZ_3_BYTE (0x3 << 8) // (TWI) Three-byte internal device address +#define AT91C_TWI_MREAD (0x1 << 12) // (TWI) Master Read Direction +#define AT91C_TWI_DADR (0x7F << 16) // (TWI) Device Address +// -------- TWI_SMR : (TWI Offset: 0x8) TWI Slave Mode Register -------- +#define AT91C_TWI_SADR (0x7F << 16) // (TWI) Slave Address +// -------- TWI_CWGR : (TWI Offset: 0x10) TWI Clock Waveform Generator Register -------- +#define AT91C_TWI_CLDIV (0xFF << 0) // (TWI) Clock Low Divider +#define AT91C_TWI_CHDIV (0xFF << 8) // (TWI) Clock High Divider +#define AT91C_TWI_CKDIV (0x7 << 16) // (TWI) Clock Divider +// -------- TWI_SR : (TWI Offset: 0x20) TWI Status Register -------- +#define AT91C_TWI_TXCOMP_SLAVE (0x1 << 0) // (TWI) Transmission Completed +#define AT91C_TWI_TXCOMP_MASTER (0x1 << 0) // (TWI) Transmission Completed +#define AT91C_TWI_RXRDY (0x1 << 1) // (TWI) Receive holding register ReaDY +#define AT91C_TWI_TXRDY_MASTER (0x1 << 2) // (TWI) Transmit holding register ReaDY +#define AT91C_TWI_TXRDY_SLAVE (0x1 << 2) // (TWI) Transmit holding register ReaDY +#define AT91C_TWI_SVREAD (0x1 << 3) // (TWI) Slave READ (used only in Slave mode) +#define AT91C_TWI_SVACC (0x1 << 4) // (TWI) Slave ACCess (used only in Slave mode) +#define AT91C_TWI_GACC (0x1 << 5) // (TWI) General Call ACcess (used only in Slave mode) +#define AT91C_TWI_OVRE (0x1 << 6) // (TWI) Overrun Error (used only in Master and Multi-master mode) +#define AT91C_TWI_NACK_SLAVE (0x1 << 8) // (TWI) Not Acknowledged +#define AT91C_TWI_NACK_MASTER (0x1 << 8) // (TWI) Not Acknowledged +#define AT91C_TWI_ARBLST_MULTI_MASTER (0x1 << 9) // (TWI) Arbitration Lost (used only in Multimaster mode) +#define AT91C_TWI_SCLWS (0x1 << 10) // (TWI) Clock Wait State (used only in Slave mode) +#define AT91C_TWI_EOSACC (0x1 << 11) // (TWI) End Of Slave ACCess (used only in Slave mode) +#define AT91C_TWI_ENDRX (0x1 << 12) // (TWI) End of Receiver Transfer +#define AT91C_TWI_ENDTX (0x1 << 13) // (TWI) End of Receiver Transfer +#define AT91C_TWI_RXBUFF (0x1 << 14) // (TWI) RXBUFF Interrupt +#define AT91C_TWI_TXBUFE (0x1 << 15) // (TWI) TXBUFE Interrupt +// -------- TWI_IER : (TWI Offset: 0x24) TWI Interrupt Enable Register -------- +// -------- TWI_IDR : (TWI Offset: 0x28) TWI Interrupt Disable Register -------- +// -------- TWI_IMR : (TWI Offset: 0x2c) TWI Interrupt Mask Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Usart +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_USART { + AT91_REG US_CR; // Control Register + AT91_REG US_MR; // Mode Register + AT91_REG US_IER; // Interrupt Enable Register + AT91_REG US_IDR; // Interrupt Disable Register + AT91_REG US_IMR; // Interrupt Mask Register + AT91_REG US_CSR; // Channel Status Register + AT91_REG US_RHR; // Receiver Holding Register + AT91_REG US_THR; // Transmitter Holding Register + AT91_REG US_BRGR; // Baud Rate Generator Register + AT91_REG US_RTOR; // Receiver Time-out Register + AT91_REG US_TTGR; // Transmitter Time-guard Register + AT91_REG Reserved0[5]; // + AT91_REG US_FIDI; // FI_DI_Ratio Register + AT91_REG US_NER; // Nb Errors Register + AT91_REG Reserved1[1]; // + AT91_REG US_IF; // IRDA_FILTER Register + AT91_REG US_MAN; // Manchester Encoder Decoder Register + AT91_REG Reserved2[38]; // + AT91_REG US_ADDRSIZE; // US ADDRSIZE REGISTER + AT91_REG US_IPNAME1; // US IPNAME1 REGISTER + AT91_REG US_IPNAME2; // US IPNAME2 REGISTER + AT91_REG US_FEATURES; // US FEATURES REGISTER + AT91_REG US_VER; // VERSION Register + AT91_REG US_RPR; // Receive Pointer Register + AT91_REG US_RCR; // Receive Counter Register + AT91_REG US_TPR; // Transmit Pointer Register + AT91_REG US_TCR; // Transmit Counter Register + AT91_REG US_RNPR; // Receive Next Pointer Register + AT91_REG US_RNCR; // Receive Next Counter Register + AT91_REG US_TNPR; // Transmit Next Pointer Register + AT91_REG US_TNCR; // Transmit Next Counter Register + AT91_REG US_PTCR; // PDC Transfer Control Register + AT91_REG US_PTSR; // PDC Transfer Status Register +} AT91S_USART, *AT91PS_USART; +#else +#define US_CR (AT91_CAST(AT91_REG *) 0x00000000) // (US_CR) Control Register +#define US_MR (AT91_CAST(AT91_REG *) 0x00000004) // (US_MR) Mode Register +#define US_IER (AT91_CAST(AT91_REG *) 0x00000008) // (US_IER) Interrupt Enable Register +#define US_IDR (AT91_CAST(AT91_REG *) 0x0000000C) // (US_IDR) Interrupt Disable Register +#define US_IMR (AT91_CAST(AT91_REG *) 0x00000010) // (US_IMR) Interrupt Mask Register +#define US_CSR (AT91_CAST(AT91_REG *) 0x00000014) // (US_CSR) Channel Status Register +#define US_RHR (AT91_CAST(AT91_REG *) 0x00000018) // (US_RHR) Receiver Holding Register +#define US_THR (AT91_CAST(AT91_REG *) 0x0000001C) // (US_THR) Transmitter Holding Register +#define US_BRGR (AT91_CAST(AT91_REG *) 0x00000020) // (US_BRGR) Baud Rate Generator Register +#define US_RTOR (AT91_CAST(AT91_REG *) 0x00000024) // (US_RTOR) Receiver Time-out Register +#define US_TTGR (AT91_CAST(AT91_REG *) 0x00000028) // (US_TTGR) Transmitter Time-guard Register +#define US_FIDI (AT91_CAST(AT91_REG *) 0x00000040) // (US_FIDI) FI_DI_Ratio Register +#define US_NER (AT91_CAST(AT91_REG *) 0x00000044) // (US_NER) Nb Errors Register +#define US_IF (AT91_CAST(AT91_REG *) 0x0000004C) // (US_IF) IRDA_FILTER Register +#define US_MAN (AT91_CAST(AT91_REG *) 0x00000050) // (US_MAN) Manchester Encoder Decoder Register +#define US_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (US_ADDRSIZE) US ADDRSIZE REGISTER +#define US_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (US_IPNAME1) US IPNAME1 REGISTER +#define US_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (US_IPNAME2) US IPNAME2 REGISTER +#define US_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (US_FEATURES) US FEATURES REGISTER +#define US_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (US_VER) VERSION Register + +#endif +// -------- US_CR : (USART Offset: 0x0) Control Register -------- +#define AT91C_US_STTBRK (0x1 << 9) // (USART) Start Break +#define AT91C_US_STPBRK (0x1 << 10) // (USART) Stop Break +#define AT91C_US_STTTO (0x1 << 11) // (USART) Start Time-out +#define AT91C_US_SENDA (0x1 << 12) // (USART) Send Address +#define AT91C_US_RSTIT (0x1 << 13) // (USART) Reset Iterations +#define AT91C_US_RSTNACK (0x1 << 14) // (USART) Reset Non Acknowledge +#define AT91C_US_RETTO (0x1 << 15) // (USART) Rearm Time-out +#define AT91C_US_DTREN (0x1 << 16) // (USART) Data Terminal ready Enable +#define AT91C_US_DTRDIS (0x1 << 17) // (USART) Data Terminal ready Disable +#define AT91C_US_RTSEN (0x1 << 18) // (USART) Request to Send enable +#define AT91C_US_RTSDIS (0x1 << 19) // (USART) Request to Send Disable +// -------- US_MR : (USART Offset: 0x4) Mode Register -------- +#define AT91C_US_USMODE (0xF << 0) // (USART) Usart mode +#define AT91C_US_USMODE_NORMAL (0x0) // (USART) Normal +#define AT91C_US_USMODE_RS485 (0x1) // (USART) RS485 +#define AT91C_US_USMODE_HWHSH (0x2) // (USART) Hardware Handshaking +#define AT91C_US_USMODE_MODEM (0x3) // (USART) Modem +#define AT91C_US_USMODE_ISO7816_0 (0x4) // (USART) ISO7816 protocol: T = 0 +#define AT91C_US_USMODE_ISO7816_1 (0x6) // (USART) ISO7816 protocol: T = 1 +#define AT91C_US_USMODE_IRDA (0x8) // (USART) IrDA +#define AT91C_US_USMODE_SWHSH (0xC) // (USART) Software Handshaking +#define AT91C_US_CLKS (0x3 << 4) // (USART) Clock Selection (Baud Rate generator Input Clock +#define AT91C_US_CLKS_CLOCK (0x0 << 4) // (USART) Clock +#define AT91C_US_CLKS_FDIV1 (0x1 << 4) // (USART) fdiv1 +#define AT91C_US_CLKS_SLOW (0x2 << 4) // (USART) slow_clock (ARM) +#define AT91C_US_CLKS_EXT (0x3 << 4) // (USART) External (SCK) +#define AT91C_US_CHRL (0x3 << 6) // (USART) Clock Selection (Baud Rate generator Input Clock +#define AT91C_US_CHRL_5_BITS (0x0 << 6) // (USART) Character Length: 5 bits +#define AT91C_US_CHRL_6_BITS (0x1 << 6) // (USART) Character Length: 6 bits +#define AT91C_US_CHRL_7_BITS (0x2 << 6) // (USART) Character Length: 7 bits +#define AT91C_US_CHRL_8_BITS (0x3 << 6) // (USART) Character Length: 8 bits +#define AT91C_US_SYNC (0x1 << 8) // (USART) Synchronous Mode Select +#define AT91C_US_NBSTOP (0x3 << 12) // (USART) Number of Stop bits +#define AT91C_US_NBSTOP_1_BIT (0x0 << 12) // (USART) 1 stop bit +#define AT91C_US_NBSTOP_15_BIT (0x1 << 12) // (USART) Asynchronous (SYNC=0) 2 stop bits Synchronous (SYNC=1) 2 stop bits +#define AT91C_US_NBSTOP_2_BIT (0x2 << 12) // (USART) 2 stop bits +#define AT91C_US_MSBF (0x1 << 16) // (USART) Bit Order +#define AT91C_US_MODE9 (0x1 << 17) // (USART) 9-bit Character length +#define AT91C_US_CKLO (0x1 << 18) // (USART) Clock Output Select +#define AT91C_US_OVER (0x1 << 19) // (USART) Over Sampling Mode +#define AT91C_US_INACK (0x1 << 20) // (USART) Inhibit Non Acknowledge +#define AT91C_US_DSNACK (0x1 << 21) // (USART) Disable Successive NACK +#define AT91C_US_VAR_SYNC (0x1 << 22) // (USART) Variable synchronization of command/data sync Start Frame Delimiter +#define AT91C_US_MAX_ITER (0x1 << 24) // (USART) Number of Repetitions +#define AT91C_US_FILTER (0x1 << 28) // (USART) Receive Line Filter +#define AT91C_US_MANMODE (0x1 << 29) // (USART) Manchester Encoder/Decoder Enable +#define AT91C_US_MODSYNC (0x1 << 30) // (USART) Manchester Synchronization mode +#define AT91C_US_ONEBIT (0x1 << 31) // (USART) Start Frame Delimiter selector +// -------- US_IER : (USART Offset: 0x8) Interrupt Enable Register -------- +#define AT91C_US_RXBRK (0x1 << 2) // (USART) Break Received/End of Break +#define AT91C_US_TIMEOUT (0x1 << 8) // (USART) Receiver Time-out +#define AT91C_US_ITERATION (0x1 << 10) // (USART) Max number of Repetitions Reached +#define AT91C_US_NACK (0x1 << 13) // (USART) Non Acknowledge +#define AT91C_US_RIIC (0x1 << 16) // (USART) Ring INdicator Input Change Flag +#define AT91C_US_DSRIC (0x1 << 17) // (USART) Data Set Ready Input Change Flag +#define AT91C_US_DCDIC (0x1 << 18) // (USART) Data Carrier Flag +#define AT91C_US_CTSIC (0x1 << 19) // (USART) Clear To Send Input Change Flag +#define AT91C_US_MANE (0x1 << 20) // (USART) Manchester Error Interrupt +// -------- US_IDR : (USART Offset: 0xc) Interrupt Disable Register -------- +// -------- US_IMR : (USART Offset: 0x10) Interrupt Mask Register -------- +// -------- US_CSR : (USART Offset: 0x14) Channel Status Register -------- +#define AT91C_US_RI (0x1 << 20) // (USART) Image of RI Input +#define AT91C_US_DSR (0x1 << 21) // (USART) Image of DSR Input +#define AT91C_US_DCD (0x1 << 22) // (USART) Image of DCD Input +#define AT91C_US_CTS (0x1 << 23) // (USART) Image of CTS Input +#define AT91C_US_MANERR (0x1 << 24) // (USART) Manchester Error +// -------- US_MAN : (USART Offset: 0x50) Manchester Encoder Decoder Register -------- +#define AT91C_US_TX_PL (0xF << 0) // (USART) Transmitter Preamble Length +#define AT91C_US_TX_PP (0x3 << 8) // (USART) Transmitter Preamble Pattern +#define AT91C_US_TX_PP_ALL_ONE (0x0 << 8) // (USART) ALL_ONE +#define AT91C_US_TX_PP_ALL_ZERO (0x1 << 8) // (USART) ALL_ZERO +#define AT91C_US_TX_PP_ZERO_ONE (0x2 << 8) // (USART) ZERO_ONE +#define AT91C_US_TX_PP_ONE_ZERO (0x3 << 8) // (USART) ONE_ZERO +#define AT91C_US_TX_MPOL (0x1 << 12) // (USART) Transmitter Manchester Polarity +#define AT91C_US_RX_PL (0xF << 16) // (USART) Receiver Preamble Length +#define AT91C_US_RX_PP (0x3 << 24) // (USART) Receiver Preamble Pattern detected +#define AT91C_US_RX_PP_ALL_ONE (0x0 << 24) // (USART) ALL_ONE +#define AT91C_US_RX_PP_ALL_ZERO (0x1 << 24) // (USART) ALL_ZERO +#define AT91C_US_RX_PP_ZERO_ONE (0x2 << 24) // (USART) ZERO_ONE +#define AT91C_US_RX_PP_ONE_ZERO (0x3 << 24) // (USART) ONE_ZERO +#define AT91C_US_RX_MPOL (0x1 << 28) // (USART) Receiver Manchester Polarity +#define AT91C_US_DRIFT (0x1 << 30) // (USART) Drift compensation + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Synchronous Serial Controller Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_SSC { + AT91_REG SSC_CR; // Control Register + AT91_REG SSC_CMR; // Clock Mode Register + AT91_REG Reserved0[2]; // + AT91_REG SSC_RCMR; // Receive Clock ModeRegister + AT91_REG SSC_RFMR; // Receive Frame Mode Register + AT91_REG SSC_TCMR; // Transmit Clock Mode Register + AT91_REG SSC_TFMR; // Transmit Frame Mode Register + AT91_REG SSC_RHR; // Receive Holding Register + AT91_REG SSC_THR; // Transmit Holding Register + AT91_REG Reserved1[2]; // + AT91_REG SSC_RSHR; // Receive Sync Holding Register + AT91_REG SSC_TSHR; // Transmit Sync Holding Register + AT91_REG Reserved2[2]; // + AT91_REG SSC_SR; // Status Register + AT91_REG SSC_IER; // Interrupt Enable Register + AT91_REG SSC_IDR; // Interrupt Disable Register + AT91_REG SSC_IMR; // Interrupt Mask Register + AT91_REG Reserved3[39]; // + AT91_REG SSC_ADDRSIZE; // SSC ADDRSIZE REGISTER + AT91_REG SSC_IPNAME1; // SSC IPNAME1 REGISTER + AT91_REG SSC_IPNAME2; // SSC IPNAME2 REGISTER + AT91_REG SSC_FEATURES; // SSC FEATURES REGISTER + AT91_REG SSC_VER; // Version Register + AT91_REG SSC_RPR; // Receive Pointer Register + AT91_REG SSC_RCR; // Receive Counter Register + AT91_REG SSC_TPR; // Transmit Pointer Register + AT91_REG SSC_TCR; // Transmit Counter Register + AT91_REG SSC_RNPR; // Receive Next Pointer Register + AT91_REG SSC_RNCR; // Receive Next Counter Register + AT91_REG SSC_TNPR; // Transmit Next Pointer Register + AT91_REG SSC_TNCR; // Transmit Next Counter Register + AT91_REG SSC_PTCR; // PDC Transfer Control Register + AT91_REG SSC_PTSR; // PDC Transfer Status Register +} AT91S_SSC, *AT91PS_SSC; +#else +#define SSC_CR (AT91_CAST(AT91_REG *) 0x00000000) // (SSC_CR) Control Register +#define SSC_CMR (AT91_CAST(AT91_REG *) 0x00000004) // (SSC_CMR) Clock Mode Register +#define SSC_RCMR (AT91_CAST(AT91_REG *) 0x00000010) // (SSC_RCMR) Receive Clock ModeRegister +#define SSC_RFMR (AT91_CAST(AT91_REG *) 0x00000014) // (SSC_RFMR) Receive Frame Mode Register +#define SSC_TCMR (AT91_CAST(AT91_REG *) 0x00000018) // (SSC_TCMR) Transmit Clock Mode Register +#define SSC_TFMR (AT91_CAST(AT91_REG *) 0x0000001C) // (SSC_TFMR) Transmit Frame Mode Register +#define SSC_RHR (AT91_CAST(AT91_REG *) 0x00000020) // (SSC_RHR) Receive Holding Register +#define SSC_THR (AT91_CAST(AT91_REG *) 0x00000024) // (SSC_THR) Transmit Holding Register +#define SSC_RSHR (AT91_CAST(AT91_REG *) 0x00000030) // (SSC_RSHR) Receive Sync Holding Register +#define SSC_TSHR (AT91_CAST(AT91_REG *) 0x00000034) // (SSC_TSHR) Transmit Sync Holding Register +#define SSC_SR (AT91_CAST(AT91_REG *) 0x00000040) // (SSC_SR) Status Register +#define SSC_IER (AT91_CAST(AT91_REG *) 0x00000044) // (SSC_IER) Interrupt Enable Register +#define SSC_IDR (AT91_CAST(AT91_REG *) 0x00000048) // (SSC_IDR) Interrupt Disable Register +#define SSC_IMR (AT91_CAST(AT91_REG *) 0x0000004C) // (SSC_IMR) Interrupt Mask Register +#define SSC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (SSC_ADDRSIZE) SSC ADDRSIZE REGISTER +#define SSC_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (SSC_IPNAME1) SSC IPNAME1 REGISTER +#define SSC_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (SSC_IPNAME2) SSC IPNAME2 REGISTER +#define SSC_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (SSC_FEATURES) SSC FEATURES REGISTER +#define SSC_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (SSC_VER) Version Register + +#endif +// -------- SSC_CR : (SSC Offset: 0x0) SSC Control Register -------- +#define AT91C_SSC_RXEN (0x1 << 0) // (SSC) Receive Enable +#define AT91C_SSC_RXDIS (0x1 << 1) // (SSC) Receive Disable +#define AT91C_SSC_TXEN (0x1 << 8) // (SSC) Transmit Enable +#define AT91C_SSC_TXDIS (0x1 << 9) // (SSC) Transmit Disable +#define AT91C_SSC_SWRST (0x1 << 15) // (SSC) Software Reset +// -------- SSC_RCMR : (SSC Offset: 0x10) SSC Receive Clock Mode Register -------- +#define AT91C_SSC_CKS (0x3 << 0) // (SSC) Receive/Transmit Clock Selection +#define AT91C_SSC_CKS_DIV (0x0) // (SSC) Divided Clock +#define AT91C_SSC_CKS_TK (0x1) // (SSC) TK Clock signal +#define AT91C_SSC_CKS_RK (0x2) // (SSC) RK pin +#define AT91C_SSC_CKO (0x7 << 2) // (SSC) Receive/Transmit Clock Output Mode Selection +#define AT91C_SSC_CKO_NONE (0x0 << 2) // (SSC) Receive/Transmit Clock Output Mode: None RK pin: Input-only +#define AT91C_SSC_CKO_CONTINOUS (0x1 << 2) // (SSC) Continuous Receive/Transmit Clock RK pin: Output +#define AT91C_SSC_CKO_DATA_TX (0x2 << 2) // (SSC) Receive/Transmit Clock only during data transfers RK pin: Output +#define AT91C_SSC_CKI (0x1 << 5) // (SSC) Receive/Transmit Clock Inversion +#define AT91C_SSC_CKG (0x3 << 6) // (SSC) Receive/Transmit Clock Gating Selection +#define AT91C_SSC_CKG_NONE (0x0 << 6) // (SSC) Receive/Transmit Clock Gating: None, continuous clock +#define AT91C_SSC_CKG_LOW (0x1 << 6) // (SSC) Receive/Transmit Clock enabled only if RF Low +#define AT91C_SSC_CKG_HIGH (0x2 << 6) // (SSC) Receive/Transmit Clock enabled only if RF High +#define AT91C_SSC_START (0xF << 8) // (SSC) Receive/Transmit Start Selection +#define AT91C_SSC_START_CONTINOUS (0x0 << 8) // (SSC) Continuous, as soon as the receiver is enabled, and immediately after the end of transfer of the previous data. +#define AT91C_SSC_START_TX (0x1 << 8) // (SSC) Transmit/Receive start +#define AT91C_SSC_START_LOW_RF (0x2 << 8) // (SSC) Detection of a low level on RF input +#define AT91C_SSC_START_HIGH_RF (0x3 << 8) // (SSC) Detection of a high level on RF input +#define AT91C_SSC_START_FALL_RF (0x4 << 8) // (SSC) Detection of a falling edge on RF input +#define AT91C_SSC_START_RISE_RF (0x5 << 8) // (SSC) Detection of a rising edge on RF input +#define AT91C_SSC_START_LEVEL_RF (0x6 << 8) // (SSC) Detection of any level change on RF input +#define AT91C_SSC_START_EDGE_RF (0x7 << 8) // (SSC) Detection of any edge on RF input +#define AT91C_SSC_START_0 (0x8 << 8) // (SSC) Compare 0 +#define AT91C_SSC_STOP (0x1 << 12) // (SSC) Receive Stop Selection +#define AT91C_SSC_STTDLY (0xFF << 16) // (SSC) Receive/Transmit Start Delay +#define AT91C_SSC_PERIOD (0xFF << 24) // (SSC) Receive/Transmit Period Divider Selection +// -------- SSC_RFMR : (SSC Offset: 0x14) SSC Receive Frame Mode Register -------- +#define AT91C_SSC_DATLEN (0x1F << 0) // (SSC) Data Length +#define AT91C_SSC_LOOP (0x1 << 5) // (SSC) Loop Mode +#define AT91C_SSC_MSBF (0x1 << 7) // (SSC) Most Significant Bit First +#define AT91C_SSC_DATNB (0xF << 8) // (SSC) Data Number per Frame +#define AT91C_SSC_FSLEN (0xF << 16) // (SSC) Receive/Transmit Frame Sync length +#define AT91C_SSC_FSOS (0x7 << 20) // (SSC) Receive/Transmit Frame Sync Output Selection +#define AT91C_SSC_FSOS_NONE (0x0 << 20) // (SSC) Selected Receive/Transmit Frame Sync Signal: None RK pin Input-only +#define AT91C_SSC_FSOS_NEGATIVE (0x1 << 20) // (SSC) Selected Receive/Transmit Frame Sync Signal: Negative Pulse +#define AT91C_SSC_FSOS_POSITIVE (0x2 << 20) // (SSC) Selected Receive/Transmit Frame Sync Signal: Positive Pulse +#define AT91C_SSC_FSOS_LOW (0x3 << 20) // (SSC) Selected Receive/Transmit Frame Sync Signal: Driver Low during data transfer +#define AT91C_SSC_FSOS_HIGH (0x4 << 20) // (SSC) Selected Receive/Transmit Frame Sync Signal: Driver High during data transfer +#define AT91C_SSC_FSOS_TOGGLE (0x5 << 20) // (SSC) Selected Receive/Transmit Frame Sync Signal: Toggling at each start of data transfer +#define AT91C_SSC_FSEDGE (0x1 << 24) // (SSC) Frame Sync Edge Detection +// -------- SSC_TCMR : (SSC Offset: 0x18) SSC Transmit Clock Mode Register -------- +// -------- SSC_TFMR : (SSC Offset: 0x1c) SSC Transmit Frame Mode Register -------- +#define AT91C_SSC_DATDEF (0x1 << 5) // (SSC) Data Default Value +#define AT91C_SSC_FSDEN (0x1 << 23) // (SSC) Frame Sync Data Enable +// -------- SSC_SR : (SSC Offset: 0x40) SSC Status Register -------- +#define AT91C_SSC_TXRDY (0x1 << 0) // (SSC) Transmit Ready +#define AT91C_SSC_TXEMPTY (0x1 << 1) // (SSC) Transmit Empty +#define AT91C_SSC_ENDTX (0x1 << 2) // (SSC) End Of Transmission +#define AT91C_SSC_TXBUFE (0x1 << 3) // (SSC) Transmit Buffer Empty +#define AT91C_SSC_RXRDY (0x1 << 4) // (SSC) Receive Ready +#define AT91C_SSC_OVRUN (0x1 << 5) // (SSC) Receive Overrun +#define AT91C_SSC_ENDRX (0x1 << 6) // (SSC) End of Reception +#define AT91C_SSC_RXBUFF (0x1 << 7) // (SSC) Receive Buffer Full +#define AT91C_SSC_CP0 (0x1 << 8) // (SSC) Compare 0 +#define AT91C_SSC_CP1 (0x1 << 9) // (SSC) Compare 1 +#define AT91C_SSC_TXSYN (0x1 << 10) // (SSC) Transmit Sync +#define AT91C_SSC_RXSYN (0x1 << 11) // (SSC) Receive Sync +#define AT91C_SSC_TXENA (0x1 << 16) // (SSC) Transmit Enable +#define AT91C_SSC_RXENA (0x1 << 17) // (SSC) Receive Enable +// -------- SSC_IER : (SSC Offset: 0x44) SSC Interrupt Enable Register -------- +// -------- SSC_IDR : (SSC Offset: 0x48) SSC Interrupt Disable Register -------- +// -------- SSC_IMR : (SSC Offset: 0x4c) SSC Interrupt Mask Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR PWMC Channel Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_PWMC_CH { + AT91_REG PWMC_CMR; // Channel Mode Register + AT91_REG PWMC_CDTYR; // Channel Duty Cycle Register + AT91_REG PWMC_CDTYUPDR; // Channel Duty Cycle Update Register + AT91_REG PWMC_CPRDR; // Channel Period Register + AT91_REG PWMC_CPRDUPDR; // Channel Period Update Register + AT91_REG PWMC_CCNTR; // Channel Counter Register + AT91_REG PWMC_DTR; // Channel Dead Time Value Register + AT91_REG PWMC_DTUPDR; // Channel Dead Time Update Value Register +} AT91S_PWMC_CH, *AT91PS_PWMC_CH; +#else +#define PWMC_CMR (AT91_CAST(AT91_REG *) 0x00000000) // (PWMC_CMR) Channel Mode Register +#define PWMC_CDTYR (AT91_CAST(AT91_REG *) 0x00000004) // (PWMC_CDTYR) Channel Duty Cycle Register +#define PWMC_CDTYUPDR (AT91_CAST(AT91_REG *) 0x00000008) // (PWMC_CDTYUPDR) Channel Duty Cycle Update Register +#define PWMC_CPRDR (AT91_CAST(AT91_REG *) 0x0000000C) // (PWMC_CPRDR) Channel Period Register +#define PWMC_CPRDUPDR (AT91_CAST(AT91_REG *) 0x00000010) // (PWMC_CPRDUPDR) Channel Period Update Register +#define PWMC_CCNTR (AT91_CAST(AT91_REG *) 0x00000014) // (PWMC_CCNTR) Channel Counter Register +#define PWMC_DTR (AT91_CAST(AT91_REG *) 0x00000018) // (PWMC_DTR) Channel Dead Time Value Register +#define PWMC_DTUPDR (AT91_CAST(AT91_REG *) 0x0000001C) // (PWMC_DTUPDR) Channel Dead Time Update Value Register + +#endif +// -------- PWMC_CMR : (PWMC_CH Offset: 0x0) PWMC Channel Mode Register -------- +#define AT91C_PWMC_CPRE (0xF << 0) // (PWMC_CH) Channel Pre-scaler : PWMC_CLKx +#define AT91C_PWMC_CPRE_MCK (0x0) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_2 (0x1) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_4 (0x2) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_8 (0x3) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_16 (0x4) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_32 (0x5) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_64 (0x6) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_128 (0x7) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_256 (0x8) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_512 (0x9) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_1024 (0xA) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCKA (0xB) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCKB (0xC) // (PWMC_CH) +#define AT91C_PWMC_CALG (0x1 << 8) // (PWMC_CH) Channel Alignment +#define AT91C_PWMC_CPOL (0x1 << 9) // (PWMC_CH) Channel Polarity +#define AT91C_PWMC_CES (0x1 << 10) // (PWMC_CH) Counter Event Selection +#define AT91C_PWMC_DTE (0x1 << 16) // (PWMC_CH) Dead Time Genrator Enable +#define AT91C_PWMC_DTHI (0x1 << 17) // (PWMC_CH) Dead Time PWMHx Output Inverted +#define AT91C_PWMC_DTLI (0x1 << 18) // (PWMC_CH) Dead Time PWMLx Output Inverted +// -------- PWMC_CDTYR : (PWMC_CH Offset: 0x4) PWMC Channel Duty Cycle Register -------- +#define AT91C_PWMC_CDTY (0xFFFFFF << 0) // (PWMC_CH) Channel Duty Cycle +// -------- PWMC_CDTYUPDR : (PWMC_CH Offset: 0x8) PWMC Channel Duty Cycle Update Register -------- +#define AT91C_PWMC_CDTYUPD (0xFFFFFF << 0) // (PWMC_CH) Channel Duty Cycle Update +// -------- PWMC_CPRDR : (PWMC_CH Offset: 0xc) PWMC Channel Period Register -------- +#define AT91C_PWMC_CPRD (0xFFFFFF << 0) // (PWMC_CH) Channel Period +// -------- PWMC_CPRDUPDR : (PWMC_CH Offset: 0x10) PWMC Channel Period Update Register -------- +#define AT91C_PWMC_CPRDUPD (0xFFFFFF << 0) // (PWMC_CH) Channel Period Update +// -------- PWMC_CCNTR : (PWMC_CH Offset: 0x14) PWMC Channel Counter Register -------- +#define AT91C_PWMC_CCNT (0xFFFFFF << 0) // (PWMC_CH) Channel Counter +// -------- PWMC_DTR : (PWMC_CH Offset: 0x18) Channel Dead Time Value Register -------- +#define AT91C_PWMC_DTL (0xFFFF << 0) // (PWMC_CH) Channel Dead Time for PWML +#define AT91C_PWMC_DTH (0xFFFF << 16) // (PWMC_CH) Channel Dead Time for PWMH +// -------- PWMC_DTUPDR : (PWMC_CH Offset: 0x1c) Channel Dead Time Value Register -------- +#define AT91C_PWMC_DTLUPD (0xFFFF << 0) // (PWMC_CH) Channel Dead Time Update for PWML. +#define AT91C_PWMC_DTHUPD (0xFFFF << 16) // (PWMC_CH) Channel Dead Time Update for PWMH. + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Pulse Width Modulation Controller Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_PWMC { + AT91_REG PWMC_MR; // PWMC Mode Register + AT91_REG PWMC_ENA; // PWMC Enable Register + AT91_REG PWMC_DIS; // PWMC Disable Register + AT91_REG PWMC_SR; // PWMC Status Register + AT91_REG PWMC_IER1; // PWMC Interrupt Enable Register 1 + AT91_REG PWMC_IDR1; // PWMC Interrupt Disable Register 1 + AT91_REG PWMC_IMR1; // PWMC Interrupt Mask Register 1 + AT91_REG PWMC_ISR1; // PWMC Interrupt Status Register 1 + AT91_REG PWMC_SYNC; // PWM Synchronized Channels Register + AT91_REG Reserved0[1]; // + AT91_REG PWMC_UPCR; // PWM Update Control Register + AT91_REG PWMC_SCUP; // PWM Update Period Register + AT91_REG PWMC_SCUPUPD; // PWM Update Period Update Register + AT91_REG PWMC_IER2; // PWMC Interrupt Enable Register 2 + AT91_REG PWMC_IDR2; // PWMC Interrupt Disable Register 2 + AT91_REG PWMC_IMR2; // PWMC Interrupt Mask Register 2 + AT91_REG PWMC_ISR2; // PWMC Interrupt Status Register 2 + AT91_REG PWMC_OOV; // PWM Output Override Value Register + AT91_REG PWMC_OS; // PWM Output Selection Register + AT91_REG PWMC_OSS; // PWM Output Selection Set Register + AT91_REG PWMC_OSC; // PWM Output Selection Clear Register + AT91_REG PWMC_OSSUPD; // PWM Output Selection Set Update Register + AT91_REG PWMC_OSCUPD; // PWM Output Selection Clear Update Register + AT91_REG PWMC_FMR; // PWM Fault Mode Register + AT91_REG PWMC_FSR; // PWM Fault Mode Status Register + AT91_REG PWMC_FCR; // PWM Fault Mode Clear Register + AT91_REG PWMC_FPV; // PWM Fault Protection Value Register + AT91_REG PWMC_FPER1; // PWM Fault Protection Enable Register 1 + AT91_REG PWMC_FPER2; // PWM Fault Protection Enable Register 2 + AT91_REG PWMC_FPER3; // PWM Fault Protection Enable Register 3 + AT91_REG PWMC_FPER4; // PWM Fault Protection Enable Register 4 + AT91_REG PWMC_EL0MR; // PWM Event Line 0 Mode Register + AT91_REG PWMC_EL1MR; // PWM Event Line 1 Mode Register + AT91_REG PWMC_EL2MR; // PWM Event Line 2 Mode Register + AT91_REG PWMC_EL3MR; // PWM Event Line 3 Mode Register + AT91_REG PWMC_EL4MR; // PWM Event Line 4 Mode Register + AT91_REG PWMC_EL5MR; // PWM Event Line 5 Mode Register + AT91_REG PWMC_EL6MR; // PWM Event Line 6 Mode Register + AT91_REG PWMC_EL7MR; // PWM Event Line 7 Mode Register + AT91_REG Reserved1[18]; // + AT91_REG PWMC_WPCR; // PWM Write Protection Enable Register + AT91_REG PWMC_WPSR; // PWM Write Protection Status Register + AT91_REG PWMC_ADDRSIZE; // PWMC ADDRSIZE REGISTER + AT91_REG PWMC_IPNAME1; // PWMC IPNAME1 REGISTER + AT91_REG PWMC_IPNAME2; // PWMC IPNAME2 REGISTER + AT91_REG PWMC_FEATURES; // PWMC FEATURES REGISTER + AT91_REG PWMC_VER; // PWMC Version Register + AT91_REG PWMC_RPR; // Receive Pointer Register + AT91_REG PWMC_RCR; // Receive Counter Register + AT91_REG PWMC_TPR; // Transmit Pointer Register + AT91_REG PWMC_TCR; // Transmit Counter Register + AT91_REG PWMC_RNPR; // Receive Next Pointer Register + AT91_REG PWMC_RNCR; // Receive Next Counter Register + AT91_REG PWMC_TNPR; // Transmit Next Pointer Register + AT91_REG PWMC_TNCR; // Transmit Next Counter Register + AT91_REG PWMC_PTCR; // PDC Transfer Control Register + AT91_REG PWMC_PTSR; // PDC Transfer Status Register + AT91_REG Reserved2[2]; // + AT91_REG PWMC_CMP0V; // PWM Comparison Value 0 Register + AT91_REG PWMC_CMP0VUPD; // PWM Comparison Value 0 Update Register + AT91_REG PWMC_CMP0M; // PWM Comparison Mode 0 Register + AT91_REG PWMC_CMP0MUPD; // PWM Comparison Mode 0 Update Register + AT91_REG PWMC_CMP1V; // PWM Comparison Value 1 Register + AT91_REG PWMC_CMP1VUPD; // PWM Comparison Value 1 Update Register + AT91_REG PWMC_CMP1M; // PWM Comparison Mode 1 Register + AT91_REG PWMC_CMP1MUPD; // PWM Comparison Mode 1 Update Register + AT91_REG PWMC_CMP2V; // PWM Comparison Value 2 Register + AT91_REG PWMC_CMP2VUPD; // PWM Comparison Value 2 Update Register + AT91_REG PWMC_CMP2M; // PWM Comparison Mode 2 Register + AT91_REG PWMC_CMP2MUPD; // PWM Comparison Mode 2 Update Register + AT91_REG PWMC_CMP3V; // PWM Comparison Value 3 Register + AT91_REG PWMC_CMP3VUPD; // PWM Comparison Value 3 Update Register + AT91_REG PWMC_CMP3M; // PWM Comparison Mode 3 Register + AT91_REG PWMC_CMP3MUPD; // PWM Comparison Mode 3 Update Register + AT91_REG PWMC_CMP4V; // PWM Comparison Value 4 Register + AT91_REG PWMC_CMP4VUPD; // PWM Comparison Value 4 Update Register + AT91_REG PWMC_CMP4M; // PWM Comparison Mode 4 Register + AT91_REG PWMC_CMP4MUPD; // PWM Comparison Mode 4 Update Register + AT91_REG PWMC_CMP5V; // PWM Comparison Value 5 Register + AT91_REG PWMC_CMP5VUPD; // PWM Comparison Value 5 Update Register + AT91_REG PWMC_CMP5M; // PWM Comparison Mode 5 Register + AT91_REG PWMC_CMP5MUPD; // PWM Comparison Mode 5 Update Register + AT91_REG PWMC_CMP6V; // PWM Comparison Value 6 Register + AT91_REG PWMC_CMP6VUPD; // PWM Comparison Value 6 Update Register + AT91_REG PWMC_CMP6M; // PWM Comparison Mode 6 Register + AT91_REG PWMC_CMP6MUPD; // PWM Comparison Mode 6 Update Register + AT91_REG PWMC_CMP7V; // PWM Comparison Value 7 Register + AT91_REG PWMC_CMP7VUPD; // PWM Comparison Value 7 Update Register + AT91_REG PWMC_CMP7M; // PWM Comparison Mode 7 Register + AT91_REG PWMC_CMP7MUPD; // PWM Comparison Mode 7 Update Register + AT91_REG Reserved3[20]; // + AT91S_PWMC_CH PWMC_CH[8]; // PWMC Channel 0 +} AT91S_PWMC, *AT91PS_PWMC; +#else +#define PWMC_MR (AT91_CAST(AT91_REG *) 0x00000000) // (PWMC_MR) PWMC Mode Register +#define PWMC_ENA (AT91_CAST(AT91_REG *) 0x00000004) // (PWMC_ENA) PWMC Enable Register +#define PWMC_DIS (AT91_CAST(AT91_REG *) 0x00000008) // (PWMC_DIS) PWMC Disable Register +#define PWMC_SR (AT91_CAST(AT91_REG *) 0x0000000C) // (PWMC_SR) PWMC Status Register +#define PWMC_IER1 (AT91_CAST(AT91_REG *) 0x00000010) // (PWMC_IER1) PWMC Interrupt Enable Register 1 +#define PWMC_IDR1 (AT91_CAST(AT91_REG *) 0x00000014) // (PWMC_IDR1) PWMC Interrupt Disable Register 1 +#define PWMC_IMR1 (AT91_CAST(AT91_REG *) 0x00000018) // (PWMC_IMR1) PWMC Interrupt Mask Register 1 +#define PWMC_ISR1 (AT91_CAST(AT91_REG *) 0x0000001C) // (PWMC_ISR1) PWMC Interrupt Status Register 1 +#define PWMC_SYNC (AT91_CAST(AT91_REG *) 0x00000020) // (PWMC_SYNC) PWM Synchronized Channels Register +#define PWMC_UPCR (AT91_CAST(AT91_REG *) 0x00000028) // (PWMC_UPCR) PWM Update Control Register +#define PWMC_SCUP (AT91_CAST(AT91_REG *) 0x0000002C) // (PWMC_SCUP) PWM Update Period Register +#define PWMC_SCUPUPD (AT91_CAST(AT91_REG *) 0x00000030) // (PWMC_SCUPUPD) PWM Update Period Update Register +#define PWMC_IER2 (AT91_CAST(AT91_REG *) 0x00000034) // (PWMC_IER2) PWMC Interrupt Enable Register 2 +#define PWMC_IDR2 (AT91_CAST(AT91_REG *) 0x00000038) // (PWMC_IDR2) PWMC Interrupt Disable Register 2 +#define PWMC_IMR2 (AT91_CAST(AT91_REG *) 0x0000003C) // (PWMC_IMR2) PWMC Interrupt Mask Register 2 +#define PWMC_ISR2 (AT91_CAST(AT91_REG *) 0x00000040) // (PWMC_ISR2) PWMC Interrupt Status Register 2 +#define PWMC_OOV (AT91_CAST(AT91_REG *) 0x00000044) // (PWMC_OOV) PWM Output Override Value Register +#define PWMC_OS (AT91_CAST(AT91_REG *) 0x00000048) // (PWMC_OS) PWM Output Selection Register +#define PWMC_OSS (AT91_CAST(AT91_REG *) 0x0000004C) // (PWMC_OSS) PWM Output Selection Set Register +#define PWMC_OSC (AT91_CAST(AT91_REG *) 0x00000050) // (PWMC_OSC) PWM Output Selection Clear Register +#define PWMC_OSSUPD (AT91_CAST(AT91_REG *) 0x00000054) // (PWMC_OSSUPD) PWM Output Selection Set Update Register +#define PWMC_OSCUPD (AT91_CAST(AT91_REG *) 0x00000058) // (PWMC_OSCUPD) PWM Output Selection Clear Update Register +#define PWMC_FMR (AT91_CAST(AT91_REG *) 0x0000005C) // (PWMC_FMR) PWM Fault Mode Register +#define PWMC_FSR (AT91_CAST(AT91_REG *) 0x00000060) // (PWMC_FSR) PWM Fault Mode Status Register +#define PWMC_FCR (AT91_CAST(AT91_REG *) 0x00000064) // (PWMC_FCR) PWM Fault Mode Clear Register +#define PWMC_FPV (AT91_CAST(AT91_REG *) 0x00000068) // (PWMC_FPV) PWM Fault Protection Value Register +#define PWMC_FPER1 (AT91_CAST(AT91_REG *) 0x0000006C) // (PWMC_FPER1) PWM Fault Protection Enable Register 1 +#define PWMC_FPER2 (AT91_CAST(AT91_REG *) 0x00000070) // (PWMC_FPER2) PWM Fault Protection Enable Register 2 +#define PWMC_FPER3 (AT91_CAST(AT91_REG *) 0x00000074) // (PWMC_FPER3) PWM Fault Protection Enable Register 3 +#define PWMC_FPER4 (AT91_CAST(AT91_REG *) 0x00000078) // (PWMC_FPER4) PWM Fault Protection Enable Register 4 +#define PWMC_EL0MR (AT91_CAST(AT91_REG *) 0x0000007C) // (PWMC_EL0MR) PWM Event Line 0 Mode Register +#define PWMC_EL1MR (AT91_CAST(AT91_REG *) 0x00000080) // (PWMC_EL1MR) PWM Event Line 1 Mode Register +#define PWMC_EL2MR (AT91_CAST(AT91_REG *) 0x00000084) // (PWMC_EL2MR) PWM Event Line 2 Mode Register +#define PWMC_EL3MR (AT91_CAST(AT91_REG *) 0x00000088) // (PWMC_EL3MR) PWM Event Line 3 Mode Register +#define PWMC_EL4MR (AT91_CAST(AT91_REG *) 0x0000008C) // (PWMC_EL4MR) PWM Event Line 4 Mode Register +#define PWMC_EL5MR (AT91_CAST(AT91_REG *) 0x00000090) // (PWMC_EL5MR) PWM Event Line 5 Mode Register +#define PWMC_EL6MR (AT91_CAST(AT91_REG *) 0x00000094) // (PWMC_EL6MR) PWM Event Line 6 Mode Register +#define PWMC_EL7MR (AT91_CAST(AT91_REG *) 0x00000098) // (PWMC_EL7MR) PWM Event Line 7 Mode Register +#define PWMC_WPCR (AT91_CAST(AT91_REG *) 0x000000E4) // (PWMC_WPCR) PWM Write Protection Enable Register +#define PWMC_WPSR (AT91_CAST(AT91_REG *) 0x000000E8) // (PWMC_WPSR) PWM Write Protection Status Register +#define PWMC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (PWMC_ADDRSIZE) PWMC ADDRSIZE REGISTER +#define PWMC_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (PWMC_IPNAME1) PWMC IPNAME1 REGISTER +#define PWMC_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (PWMC_IPNAME2) PWMC IPNAME2 REGISTER +#define PWMC_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (PWMC_FEATURES) PWMC FEATURES REGISTER +#define PWMC_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (PWMC_VER) PWMC Version Register +#define PWMC_CMP0V (AT91_CAST(AT91_REG *) 0x00000130) // (PWMC_CMP0V) PWM Comparison Value 0 Register +#define PWMC_CMP0VUPD (AT91_CAST(AT91_REG *) 0x00000134) // (PWMC_CMP0VUPD) PWM Comparison Value 0 Update Register +#define PWMC_CMP0M (AT91_CAST(AT91_REG *) 0x00000138) // (PWMC_CMP0M) PWM Comparison Mode 0 Register +#define PWMC_CMP0MUPD (AT91_CAST(AT91_REG *) 0x0000013C) // (PWMC_CMP0MUPD) PWM Comparison Mode 0 Update Register +#define PWMC_CMP1V (AT91_CAST(AT91_REG *) 0x00000140) // (PWMC_CMP1V) PWM Comparison Value 1 Register +#define PWMC_CMP1VUPD (AT91_CAST(AT91_REG *) 0x00000144) // (PWMC_CMP1VUPD) PWM Comparison Value 1 Update Register +#define PWMC_CMP1M (AT91_CAST(AT91_REG *) 0x00000148) // (PWMC_CMP1M) PWM Comparison Mode 1 Register +#define PWMC_CMP1MUPD (AT91_CAST(AT91_REG *) 0x0000014C) // (PWMC_CMP1MUPD) PWM Comparison Mode 1 Update Register +#define PWMC_CMP2V (AT91_CAST(AT91_REG *) 0x00000150) // (PWMC_CMP2V) PWM Comparison Value 2 Register +#define PWMC_CMP2VUPD (AT91_CAST(AT91_REG *) 0x00000154) // (PWMC_CMP2VUPD) PWM Comparison Value 2 Update Register +#define PWMC_CMP2M (AT91_CAST(AT91_REG *) 0x00000158) // (PWMC_CMP2M) PWM Comparison Mode 2 Register +#define PWMC_CMP2MUPD (AT91_CAST(AT91_REG *) 0x0000015C) // (PWMC_CMP2MUPD) PWM Comparison Mode 2 Update Register +#define PWMC_CMP3V (AT91_CAST(AT91_REG *) 0x00000160) // (PWMC_CMP3V) PWM Comparison Value 3 Register +#define PWMC_CMP3VUPD (AT91_CAST(AT91_REG *) 0x00000164) // (PWMC_CMP3VUPD) PWM Comparison Value 3 Update Register +#define PWMC_CMP3M (AT91_CAST(AT91_REG *) 0x00000168) // (PWMC_CMP3M) PWM Comparison Mode 3 Register +#define PWMC_CMP3MUPD (AT91_CAST(AT91_REG *) 0x0000016C) // (PWMC_CMP3MUPD) PWM Comparison Mode 3 Update Register +#define PWMC_CMP4V (AT91_CAST(AT91_REG *) 0x00000170) // (PWMC_CMP4V) PWM Comparison Value 4 Register +#define PWMC_CMP4VUPD (AT91_CAST(AT91_REG *) 0x00000174) // (PWMC_CMP4VUPD) PWM Comparison Value 4 Update Register +#define PWMC_CMP4M (AT91_CAST(AT91_REG *) 0x00000178) // (PWMC_CMP4M) PWM Comparison Mode 4 Register +#define PWMC_CMP4MUPD (AT91_CAST(AT91_REG *) 0x0000017C) // (PWMC_CMP4MUPD) PWM Comparison Mode 4 Update Register +#define PWMC_CMP5V (AT91_CAST(AT91_REG *) 0x00000180) // (PWMC_CMP5V) PWM Comparison Value 5 Register +#define PWMC_CMP5VUPD (AT91_CAST(AT91_REG *) 0x00000184) // (PWMC_CMP5VUPD) PWM Comparison Value 5 Update Register +#define PWMC_CMP5M (AT91_CAST(AT91_REG *) 0x00000188) // (PWMC_CMP5M) PWM Comparison Mode 5 Register +#define PWMC_CMP5MUPD (AT91_CAST(AT91_REG *) 0x0000018C) // (PWMC_CMP5MUPD) PWM Comparison Mode 5 Update Register +#define PWMC_CMP6V (AT91_CAST(AT91_REG *) 0x00000190) // (PWMC_CMP6V) PWM Comparison Value 6 Register +#define PWMC_CMP6VUPD (AT91_CAST(AT91_REG *) 0x00000194) // (PWMC_CMP6VUPD) PWM Comparison Value 6 Update Register +#define PWMC_CMP6M (AT91_CAST(AT91_REG *) 0x00000198) // (PWMC_CMP6M) PWM Comparison Mode 6 Register +#define PWMC_CMP6MUPD (AT91_CAST(AT91_REG *) 0x0000019C) // (PWMC_CMP6MUPD) PWM Comparison Mode 6 Update Register +#define PWMC_CMP7V (AT91_CAST(AT91_REG *) 0x000001A0) // (PWMC_CMP7V) PWM Comparison Value 7 Register +#define PWMC_CMP7VUPD (AT91_CAST(AT91_REG *) 0x000001A4) // (PWMC_CMP7VUPD) PWM Comparison Value 7 Update Register +#define PWMC_CMP7M (AT91_CAST(AT91_REG *) 0x000001A8) // (PWMC_CMP7M) PWM Comparison Mode 7 Register +#define PWMC_CMP7MUPD (AT91_CAST(AT91_REG *) 0x000001AC) // (PWMC_CMP7MUPD) PWM Comparison Mode 7 Update Register + +#endif +// -------- PWMC_MR : (PWMC Offset: 0x0) PWMC Mode Register -------- +#define AT91C_PWMC_DIVA (0xFF << 0) // (PWMC) CLKA divide factor. +#define AT91C_PWMC_PREA (0xF << 8) // (PWMC) Divider Input Clock Prescaler A +#define AT91C_PWMC_PREA_MCK (0x0 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_2 (0x1 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_4 (0x2 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_8 (0x3 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_16 (0x4 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_32 (0x5 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_64 (0x6 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_128 (0x7 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_256 (0x8 << 8) // (PWMC) +#define AT91C_PWMC_DIVB (0xFF << 16) // (PWMC) CLKB divide factor. +#define AT91C_PWMC_PREB (0xF << 24) // (PWMC) Divider Input Clock Prescaler B +#define AT91C_PWMC_PREB_MCK (0x0 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_2 (0x1 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_4 (0x2 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_8 (0x3 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_16 (0x4 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_32 (0x5 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_64 (0x6 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_128 (0x7 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_256 (0x8 << 24) // (PWMC) +#define AT91C_PWMC_CLKSEL (0x1 << 31) // (PWMC) CCK Source Clock Selection +// -------- PWMC_ENA : (PWMC Offset: 0x4) PWMC Enable Register -------- +#define AT91C_PWMC_CHID0 (0x1 << 0) // (PWMC) Channel ID 0 +#define AT91C_PWMC_CHID1 (0x1 << 1) // (PWMC) Channel ID 1 +#define AT91C_PWMC_CHID2 (0x1 << 2) // (PWMC) Channel ID 2 +#define AT91C_PWMC_CHID3 (0x1 << 3) // (PWMC) Channel ID 3 +#define AT91C_PWMC_CHID4 (0x1 << 4) // (PWMC) Channel ID 4 +#define AT91C_PWMC_CHID5 (0x1 << 5) // (PWMC) Channel ID 5 +#define AT91C_PWMC_CHID6 (0x1 << 6) // (PWMC) Channel ID 6 +#define AT91C_PWMC_CHID7 (0x1 << 7) // (PWMC) Channel ID 7 +#define AT91C_PWMC_CHID8 (0x1 << 8) // (PWMC) Channel ID 8 +#define AT91C_PWMC_CHID9 (0x1 << 9) // (PWMC) Channel ID 9 +#define AT91C_PWMC_CHID10 (0x1 << 10) // (PWMC) Channel ID 10 +#define AT91C_PWMC_CHID11 (0x1 << 11) // (PWMC) Channel ID 11 +#define AT91C_PWMC_CHID12 (0x1 << 12) // (PWMC) Channel ID 12 +#define AT91C_PWMC_CHID13 (0x1 << 13) // (PWMC) Channel ID 13 +#define AT91C_PWMC_CHID14 (0x1 << 14) // (PWMC) Channel ID 14 +#define AT91C_PWMC_CHID15 (0x1 << 15) // (PWMC) Channel ID 15 +// -------- PWMC_DIS : (PWMC Offset: 0x8) PWMC Disable Register -------- +// -------- PWMC_SR : (PWMC Offset: 0xc) PWMC Status Register -------- +// -------- PWMC_IER1 : (PWMC Offset: 0x10) PWMC Interrupt Enable Register -------- +#define AT91C_PWMC_FCHID0 (0x1 << 16) // (PWMC) Fault Event Channel ID 0 +#define AT91C_PWMC_FCHID1 (0x1 << 17) // (PWMC) Fault Event Channel ID 1 +#define AT91C_PWMC_FCHID2 (0x1 << 18) // (PWMC) Fault Event Channel ID 2 +#define AT91C_PWMC_FCHID3 (0x1 << 19) // (PWMC) Fault Event Channel ID 3 +#define AT91C_PWMC_FCHID4 (0x1 << 20) // (PWMC) Fault Event Channel ID 4 +#define AT91C_PWMC_FCHID5 (0x1 << 21) // (PWMC) Fault Event Channel ID 5 +#define AT91C_PWMC_FCHID6 (0x1 << 22) // (PWMC) Fault Event Channel ID 6 +#define AT91C_PWMC_FCHID7 (0x1 << 23) // (PWMC) Fault Event Channel ID 7 +#define AT91C_PWMC_FCHID8 (0x1 << 24) // (PWMC) Fault Event Channel ID 8 +#define AT91C_PWMC_FCHID9 (0x1 << 25) // (PWMC) Fault Event Channel ID 9 +#define AT91C_PWMC_FCHID10 (0x1 << 26) // (PWMC) Fault Event Channel ID 10 +#define AT91C_PWMC_FCHID11 (0x1 << 27) // (PWMC) Fault Event Channel ID 11 +#define AT91C_PWMC_FCHID12 (0x1 << 28) // (PWMC) Fault Event Channel ID 12 +#define AT91C_PWMC_FCHID13 (0x1 << 29) // (PWMC) Fault Event Channel ID 13 +#define AT91C_PWMC_FCHID14 (0x1 << 30) // (PWMC) Fault Event Channel ID 14 +#define AT91C_PWMC_FCHID15 (0x1 << 31) // (PWMC) Fault Event Channel ID 15 +// -------- PWMC_IDR1 : (PWMC Offset: 0x14) PWMC Interrupt Disable Register -------- +// -------- PWMC_IMR1 : (PWMC Offset: 0x18) PWMC Interrupt Mask Register -------- +// -------- PWMC_ISR1 : (PWMC Offset: 0x1c) PWMC Interrupt Status Register -------- +// -------- PWMC_SYNC : (PWMC Offset: 0x20) PWMC Synchronous Channels Register -------- +#define AT91C_PWMC_SYNC0 (0x1 << 0) // (PWMC) Synchronous Channel ID 0 +#define AT91C_PWMC_SYNC1 (0x1 << 1) // (PWMC) Synchronous Channel ID 1 +#define AT91C_PWMC_SYNC2 (0x1 << 2) // (PWMC) Synchronous Channel ID 2 +#define AT91C_PWMC_SYNC3 (0x1 << 3) // (PWMC) Synchronous Channel ID 3 +#define AT91C_PWMC_SYNC4 (0x1 << 4) // (PWMC) Synchronous Channel ID 4 +#define AT91C_PWMC_SYNC5 (0x1 << 5) // (PWMC) Synchronous Channel ID 5 +#define AT91C_PWMC_SYNC6 (0x1 << 6) // (PWMC) Synchronous Channel ID 6 +#define AT91C_PWMC_SYNC7 (0x1 << 7) // (PWMC) Synchronous Channel ID 7 +#define AT91C_PWMC_SYNC8 (0x1 << 8) // (PWMC) Synchronous Channel ID 8 +#define AT91C_PWMC_SYNC9 (0x1 << 9) // (PWMC) Synchronous Channel ID 9 +#define AT91C_PWMC_SYNC10 (0x1 << 10) // (PWMC) Synchronous Channel ID 10 +#define AT91C_PWMC_SYNC11 (0x1 << 11) // (PWMC) Synchronous Channel ID 11 +#define AT91C_PWMC_SYNC12 (0x1 << 12) // (PWMC) Synchronous Channel ID 12 +#define AT91C_PWMC_SYNC13 (0x1 << 13) // (PWMC) Synchronous Channel ID 13 +#define AT91C_PWMC_SYNC14 (0x1 << 14) // (PWMC) Synchronous Channel ID 14 +#define AT91C_PWMC_SYNC15 (0x1 << 15) // (PWMC) Synchronous Channel ID 15 +#define AT91C_PWMC_UPDM (0x3 << 16) // (PWMC) Synchronous Channels Update mode +#define AT91C_PWMC_UPDM_MODE0 (0x0 << 16) // (PWMC) Manual write of data and manual trigger of the update +#define AT91C_PWMC_UPDM_MODE1 (0x1 << 16) // (PWMC) Manual write of data and automatic trigger of the update +#define AT91C_PWMC_UPDM_MODE2 (0x2 << 16) // (PWMC) Automatic write of data and automatic trigger of the update +// -------- PWMC_UPCR : (PWMC Offset: 0x28) PWMC Update Control Register -------- +#define AT91C_PWMC_UPDULOCK (0x1 << 0) // (PWMC) Synchronized Channels Duty Cycle Update Unlock +// -------- PWMC_SCUP : (PWMC Offset: 0x2c) PWM Update Period Register -------- +#define AT91C_PWMC_UPR (0xF << 0) // (PWMC) PWM Update Period. +#define AT91C_PWMC_UPRCNT (0xF << 4) // (PWMC) PWM Update Period Counter. +// -------- PWMC_SCUPUPD : (PWMC Offset: 0x30) PWM Update Period Update Register -------- +#define AT91C_PWMC_UPVUPDAL (0xF << 0) // (PWMC) PWM Update Period Update. +// -------- PWMC_IER2 : (PWMC Offset: 0x34) PWMC Interrupt Enable Register -------- +#define AT91C_PWMC_WRDY (0x1 << 0) // (PWMC) PDC Write Ready +#define AT91C_PWMC_ENDTX (0x1 << 1) // (PWMC) PDC End of TX Buffer +#define AT91C_PWMC_TXBUFE (0x1 << 2) // (PWMC) PDC End of TX Buffer +#define AT91C_PWMC_UNRE (0x1 << 3) // (PWMC) PDC End of TX Buffer +// -------- PWMC_IDR2 : (PWMC Offset: 0x38) PWMC Interrupt Disable Register -------- +// -------- PWMC_IMR2 : (PWMC Offset: 0x3c) PWMC Interrupt Mask Register -------- +// -------- PWMC_ISR2 : (PWMC Offset: 0x40) PWMC Interrupt Status Register -------- +#define AT91C_PWMC_CMPM0 (0x1 << 8) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM1 (0x1 << 9) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM2 (0x1 << 10) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM3 (0x1 << 11) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM4 (0x1 << 12) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM5 (0x1 << 13) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM6 (0x1 << 14) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM7 (0x1 << 15) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPU0 (0x1 << 16) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU1 (0x1 << 17) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU2 (0x1 << 18) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU3 (0x1 << 19) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU4 (0x1 << 20) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU5 (0x1 << 21) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU6 (0x1 << 22) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU7 (0x1 << 23) // (PWMC) Comparison x Update +// -------- PWMC_OOV : (PWMC Offset: 0x44) PWM Output Override Value Register -------- +#define AT91C_PWMC_OOVH0 (0x1 << 0) // (PWMC) Output Override Value for PWMH output of the channel 0 +#define AT91C_PWMC_OOVH1 (0x1 << 1) // (PWMC) Output Override Value for PWMH output of the channel 1 +#define AT91C_PWMC_OOVH2 (0x1 << 2) // (PWMC) Output Override Value for PWMH output of the channel 2 +#define AT91C_PWMC_OOVH3 (0x1 << 3) // (PWMC) Output Override Value for PWMH output of the channel 3 +#define AT91C_PWMC_OOVH4 (0x1 << 4) // (PWMC) Output Override Value for PWMH output of the channel 4 +#define AT91C_PWMC_OOVH5 (0x1 << 5) // (PWMC) Output Override Value for PWMH output of the channel 5 +#define AT91C_PWMC_OOVH6 (0x1 << 6) // (PWMC) Output Override Value for PWMH output of the channel 6 +#define AT91C_PWMC_OOVH7 (0x1 << 7) // (PWMC) Output Override Value for PWMH output of the channel 7 +#define AT91C_PWMC_OOVH8 (0x1 << 8) // (PWMC) Output Override Value for PWMH output of the channel 8 +#define AT91C_PWMC_OOVH9 (0x1 << 9) // (PWMC) Output Override Value for PWMH output of the channel 9 +#define AT91C_PWMC_OOVH10 (0x1 << 10) // (PWMC) Output Override Value for PWMH output of the channel 10 +#define AT91C_PWMC_OOVH11 (0x1 << 11) // (PWMC) Output Override Value for PWMH output of the channel 11 +#define AT91C_PWMC_OOVH12 (0x1 << 12) // (PWMC) Output Override Value for PWMH output of the channel 12 +#define AT91C_PWMC_OOVH13 (0x1 << 13) // (PWMC) Output Override Value for PWMH output of the channel 13 +#define AT91C_PWMC_OOVH14 (0x1 << 14) // (PWMC) Output Override Value for PWMH output of the channel 14 +#define AT91C_PWMC_OOVH15 (0x1 << 15) // (PWMC) Output Override Value for PWMH output of the channel 15 +#define AT91C_PWMC_OOVL0 (0x1 << 16) // (PWMC) Output Override Value for PWML output of the channel 0 +#define AT91C_PWMC_OOVL1 (0x1 << 17) // (PWMC) Output Override Value for PWML output of the channel 1 +#define AT91C_PWMC_OOVL2 (0x1 << 18) // (PWMC) Output Override Value for PWML output of the channel 2 +#define AT91C_PWMC_OOVL3 (0x1 << 19) // (PWMC) Output Override Value for PWML output of the channel 3 +#define AT91C_PWMC_OOVL4 (0x1 << 20) // (PWMC) Output Override Value for PWML output of the channel 4 +#define AT91C_PWMC_OOVL5 (0x1 << 21) // (PWMC) Output Override Value for PWML output of the channel 5 +#define AT91C_PWMC_OOVL6 (0x1 << 22) // (PWMC) Output Override Value for PWML output of the channel 6 +#define AT91C_PWMC_OOVL7 (0x1 << 23) // (PWMC) Output Override Value for PWML output of the channel 7 +#define AT91C_PWMC_OOVL8 (0x1 << 24) // (PWMC) Output Override Value for PWML output of the channel 8 +#define AT91C_PWMC_OOVL9 (0x1 << 25) // (PWMC) Output Override Value for PWML output of the channel 9 +#define AT91C_PWMC_OOVL10 (0x1 << 26) // (PWMC) Output Override Value for PWML output of the channel 10 +#define AT91C_PWMC_OOVL11 (0x1 << 27) // (PWMC) Output Override Value for PWML output of the channel 11 +#define AT91C_PWMC_OOVL12 (0x1 << 28) // (PWMC) Output Override Value for PWML output of the channel 12 +#define AT91C_PWMC_OOVL13 (0x1 << 29) // (PWMC) Output Override Value for PWML output of the channel 13 +#define AT91C_PWMC_OOVL14 (0x1 << 30) // (PWMC) Output Override Value for PWML output of the channel 14 +#define AT91C_PWMC_OOVL15 (0x1 << 31) // (PWMC) Output Override Value for PWML output of the channel 15 +// -------- PWMC_OS : (PWMC Offset: 0x48) PWM Output Selection Register -------- +#define AT91C_PWMC_OSH0 (0x1 << 0) // (PWMC) Output Selection for PWMH output of the channel 0 +#define AT91C_PWMC_OSH1 (0x1 << 1) // (PWMC) Output Selection for PWMH output of the channel 1 +#define AT91C_PWMC_OSH2 (0x1 << 2) // (PWMC) Output Selection for PWMH output of the channel 2 +#define AT91C_PWMC_OSH3 (0x1 << 3) // (PWMC) Output Selection for PWMH output of the channel 3 +#define AT91C_PWMC_OSH4 (0x1 << 4) // (PWMC) Output Selection for PWMH output of the channel 4 +#define AT91C_PWMC_OSH5 (0x1 << 5) // (PWMC) Output Selection for PWMH output of the channel 5 +#define AT91C_PWMC_OSH6 (0x1 << 6) // (PWMC) Output Selection for PWMH output of the channel 6 +#define AT91C_PWMC_OSH7 (0x1 << 7) // (PWMC) Output Selection for PWMH output of the channel 7 +#define AT91C_PWMC_OSH8 (0x1 << 8) // (PWMC) Output Selection for PWMH output of the channel 8 +#define AT91C_PWMC_OSH9 (0x1 << 9) // (PWMC) Output Selection for PWMH output of the channel 9 +#define AT91C_PWMC_OSH10 (0x1 << 10) // (PWMC) Output Selection for PWMH output of the channel 10 +#define AT91C_PWMC_OSH11 (0x1 << 11) // (PWMC) Output Selection for PWMH output of the channel 11 +#define AT91C_PWMC_OSH12 (0x1 << 12) // (PWMC) Output Selection for PWMH output of the channel 12 +#define AT91C_PWMC_OSH13 (0x1 << 13) // (PWMC) Output Selection for PWMH output of the channel 13 +#define AT91C_PWMC_OSH14 (0x1 << 14) // (PWMC) Output Selection for PWMH output of the channel 14 +#define AT91C_PWMC_OSH15 (0x1 << 15) // (PWMC) Output Selection for PWMH output of the channel 15 +#define AT91C_PWMC_OSL0 (0x1 << 16) // (PWMC) Output Selection for PWML output of the channel 0 +#define AT91C_PWMC_OSL1 (0x1 << 17) // (PWMC) Output Selection for PWML output of the channel 1 +#define AT91C_PWMC_OSL2 (0x1 << 18) // (PWMC) Output Selection for PWML output of the channel 2 +#define AT91C_PWMC_OSL3 (0x1 << 19) // (PWMC) Output Selection for PWML output of the channel 3 +#define AT91C_PWMC_OSL4 (0x1 << 20) // (PWMC) Output Selection for PWML output of the channel 4 +#define AT91C_PWMC_OSL5 (0x1 << 21) // (PWMC) Output Selection for PWML output of the channel 5 +#define AT91C_PWMC_OSL6 (0x1 << 22) // (PWMC) Output Selection for PWML output of the channel 6 +#define AT91C_PWMC_OSL7 (0x1 << 23) // (PWMC) Output Selection for PWML output of the channel 7 +#define AT91C_PWMC_OSL8 (0x1 << 24) // (PWMC) Output Selection for PWML output of the channel 8 +#define AT91C_PWMC_OSL9 (0x1 << 25) // (PWMC) Output Selection for PWML output of the channel 9 +#define AT91C_PWMC_OSL10 (0x1 << 26) // (PWMC) Output Selection for PWML output of the channel 10 +#define AT91C_PWMC_OSL11 (0x1 << 27) // (PWMC) Output Selection for PWML output of the channel 11 +#define AT91C_PWMC_OSL12 (0x1 << 28) // (PWMC) Output Selection for PWML output of the channel 12 +#define AT91C_PWMC_OSL13 (0x1 << 29) // (PWMC) Output Selection for PWML output of the channel 13 +#define AT91C_PWMC_OSL14 (0x1 << 30) // (PWMC) Output Selection for PWML output of the channel 14 +#define AT91C_PWMC_OSL15 (0x1 << 31) // (PWMC) Output Selection for PWML output of the channel 15 +// -------- PWMC_OSS : (PWMC Offset: 0x4c) PWM Output Selection Set Register -------- +#define AT91C_PWMC_OSSH0 (0x1 << 0) // (PWMC) Output Selection Set for PWMH output of the channel 0 +#define AT91C_PWMC_OSSH1 (0x1 << 1) // (PWMC) Output Selection Set for PWMH output of the channel 1 +#define AT91C_PWMC_OSSH2 (0x1 << 2) // (PWMC) Output Selection Set for PWMH output of the channel 2 +#define AT91C_PWMC_OSSH3 (0x1 << 3) // (PWMC) Output Selection Set for PWMH output of the channel 3 +#define AT91C_PWMC_OSSH4 (0x1 << 4) // (PWMC) Output Selection Set for PWMH output of the channel 4 +#define AT91C_PWMC_OSSH5 (0x1 << 5) // (PWMC) Output Selection Set for PWMH output of the channel 5 +#define AT91C_PWMC_OSSH6 (0x1 << 6) // (PWMC) Output Selection Set for PWMH output of the channel 6 +#define AT91C_PWMC_OSSH7 (0x1 << 7) // (PWMC) Output Selection Set for PWMH output of the channel 7 +#define AT91C_PWMC_OSSH8 (0x1 << 8) // (PWMC) Output Selection Set for PWMH output of the channel 8 +#define AT91C_PWMC_OSSH9 (0x1 << 9) // (PWMC) Output Selection Set for PWMH output of the channel 9 +#define AT91C_PWMC_OSSH10 (0x1 << 10) // (PWMC) Output Selection Set for PWMH output of the channel 10 +#define AT91C_PWMC_OSSH11 (0x1 << 11) // (PWMC) Output Selection Set for PWMH output of the channel 11 +#define AT91C_PWMC_OSSH12 (0x1 << 12) // (PWMC) Output Selection Set for PWMH output of the channel 12 +#define AT91C_PWMC_OSSH13 (0x1 << 13) // (PWMC) Output Selection Set for PWMH output of the channel 13 +#define AT91C_PWMC_OSSH14 (0x1 << 14) // (PWMC) Output Selection Set for PWMH output of the channel 14 +#define AT91C_PWMC_OSSH15 (0x1 << 15) // (PWMC) Output Selection Set for PWMH output of the channel 15 +#define AT91C_PWMC_OSSL0 (0x1 << 16) // (PWMC) Output Selection Set for PWML output of the channel 0 +#define AT91C_PWMC_OSSL1 (0x1 << 17) // (PWMC) Output Selection Set for PWML output of the channel 1 +#define AT91C_PWMC_OSSL2 (0x1 << 18) // (PWMC) Output Selection Set for PWML output of the channel 2 +#define AT91C_PWMC_OSSL3 (0x1 << 19) // (PWMC) Output Selection Set for PWML output of the channel 3 +#define AT91C_PWMC_OSSL4 (0x1 << 20) // (PWMC) Output Selection Set for PWML output of the channel 4 +#define AT91C_PWMC_OSSL5 (0x1 << 21) // (PWMC) Output Selection Set for PWML output of the channel 5 +#define AT91C_PWMC_OSSL6 (0x1 << 22) // (PWMC) Output Selection Set for PWML output of the channel 6 +#define AT91C_PWMC_OSSL7 (0x1 << 23) // (PWMC) Output Selection Set for PWML output of the channel 7 +#define AT91C_PWMC_OSSL8 (0x1 << 24) // (PWMC) Output Selection Set for PWML output of the channel 8 +#define AT91C_PWMC_OSSL9 (0x1 << 25) // (PWMC) Output Selection Set for PWML output of the channel 9 +#define AT91C_PWMC_OSSL10 (0x1 << 26) // (PWMC) Output Selection Set for PWML output of the channel 10 +#define AT91C_PWMC_OSSL11 (0x1 << 27) // (PWMC) Output Selection Set for PWML output of the channel 11 +#define AT91C_PWMC_OSSL12 (0x1 << 28) // (PWMC) Output Selection Set for PWML output of the channel 12 +#define AT91C_PWMC_OSSL13 (0x1 << 29) // (PWMC) Output Selection Set for PWML output of the channel 13 +#define AT91C_PWMC_OSSL14 (0x1 << 30) // (PWMC) Output Selection Set for PWML output of the channel 14 +#define AT91C_PWMC_OSSL15 (0x1 << 31) // (PWMC) Output Selection Set for PWML output of the channel 15 +// -------- PWMC_OSC : (PWMC Offset: 0x50) PWM Output Selection Clear Register -------- +#define AT91C_PWMC_OSCH0 (0x1 << 0) // (PWMC) Output Selection Clear for PWMH output of the channel 0 +#define AT91C_PWMC_OSCH1 (0x1 << 1) // (PWMC) Output Selection Clear for PWMH output of the channel 1 +#define AT91C_PWMC_OSCH2 (0x1 << 2) // (PWMC) Output Selection Clear for PWMH output of the channel 2 +#define AT91C_PWMC_OSCH3 (0x1 << 3) // (PWMC) Output Selection Clear for PWMH output of the channel 3 +#define AT91C_PWMC_OSCH4 (0x1 << 4) // (PWMC) Output Selection Clear for PWMH output of the channel 4 +#define AT91C_PWMC_OSCH5 (0x1 << 5) // (PWMC) Output Selection Clear for PWMH output of the channel 5 +#define AT91C_PWMC_OSCH6 (0x1 << 6) // (PWMC) Output Selection Clear for PWMH output of the channel 6 +#define AT91C_PWMC_OSCH7 (0x1 << 7) // (PWMC) Output Selection Clear for PWMH output of the channel 7 +#define AT91C_PWMC_OSCH8 (0x1 << 8) // (PWMC) Output Selection Clear for PWMH output of the channel 8 +#define AT91C_PWMC_OSCH9 (0x1 << 9) // (PWMC) Output Selection Clear for PWMH output of the channel 9 +#define AT91C_PWMC_OSCH10 (0x1 << 10) // (PWMC) Output Selection Clear for PWMH output of the channel 10 +#define AT91C_PWMC_OSCH11 (0x1 << 11) // (PWMC) Output Selection Clear for PWMH output of the channel 11 +#define AT91C_PWMC_OSCH12 (0x1 << 12) // (PWMC) Output Selection Clear for PWMH output of the channel 12 +#define AT91C_PWMC_OSCH13 (0x1 << 13) // (PWMC) Output Selection Clear for PWMH output of the channel 13 +#define AT91C_PWMC_OSCH14 (0x1 << 14) // (PWMC) Output Selection Clear for PWMH output of the channel 14 +#define AT91C_PWMC_OSCH15 (0x1 << 15) // (PWMC) Output Selection Clear for PWMH output of the channel 15 +#define AT91C_PWMC_OSCL0 (0x1 << 16) // (PWMC) Output Selection Clear for PWML output of the channel 0 +#define AT91C_PWMC_OSCL1 (0x1 << 17) // (PWMC) Output Selection Clear for PWML output of the channel 1 +#define AT91C_PWMC_OSCL2 (0x1 << 18) // (PWMC) Output Selection Clear for PWML output of the channel 2 +#define AT91C_PWMC_OSCL3 (0x1 << 19) // (PWMC) Output Selection Clear for PWML output of the channel 3 +#define AT91C_PWMC_OSCL4 (0x1 << 20) // (PWMC) Output Selection Clear for PWML output of the channel 4 +#define AT91C_PWMC_OSCL5 (0x1 << 21) // (PWMC) Output Selection Clear for PWML output of the channel 5 +#define AT91C_PWMC_OSCL6 (0x1 << 22) // (PWMC) Output Selection Clear for PWML output of the channel 6 +#define AT91C_PWMC_OSCL7 (0x1 << 23) // (PWMC) Output Selection Clear for PWML output of the channel 7 +#define AT91C_PWMC_OSCL8 (0x1 << 24) // (PWMC) Output Selection Clear for PWML output of the channel 8 +#define AT91C_PWMC_OSCL9 (0x1 << 25) // (PWMC) Output Selection Clear for PWML output of the channel 9 +#define AT91C_PWMC_OSCL10 (0x1 << 26) // (PWMC) Output Selection Clear for PWML output of the channel 10 +#define AT91C_PWMC_OSCL11 (0x1 << 27) // (PWMC) Output Selection Clear for PWML output of the channel 11 +#define AT91C_PWMC_OSCL12 (0x1 << 28) // (PWMC) Output Selection Clear for PWML output of the channel 12 +#define AT91C_PWMC_OSCL13 (0x1 << 29) // (PWMC) Output Selection Clear for PWML output of the channel 13 +#define AT91C_PWMC_OSCL14 (0x1 << 30) // (PWMC) Output Selection Clear for PWML output of the channel 14 +#define AT91C_PWMC_OSCL15 (0x1 << 31) // (PWMC) Output Selection Clear for PWML output of the channel 15 +// -------- PWMC_OSSUPD : (PWMC Offset: 0x54) Output Selection Set for PWMH / PWML output of the channel x -------- +#define AT91C_PWMC_OSSUPDH0 (0x1 << 0) // (PWMC) Output Selection Set for PWMH output of the channel 0 +#define AT91C_PWMC_OSSUPDH1 (0x1 << 1) // (PWMC) Output Selection Set for PWMH output of the channel 1 +#define AT91C_PWMC_OSSUPDH2 (0x1 << 2) // (PWMC) Output Selection Set for PWMH output of the channel 2 +#define AT91C_PWMC_OSSUPDH3 (0x1 << 3) // (PWMC) Output Selection Set for PWMH output of the channel 3 +#define AT91C_PWMC_OSSUPDH4 (0x1 << 4) // (PWMC) Output Selection Set for PWMH output of the channel 4 +#define AT91C_PWMC_OSSUPDH5 (0x1 << 5) // (PWMC) Output Selection Set for PWMH output of the channel 5 +#define AT91C_PWMC_OSSUPDH6 (0x1 << 6) // (PWMC) Output Selection Set for PWMH output of the channel 6 +#define AT91C_PWMC_OSSUPDH7 (0x1 << 7) // (PWMC) Output Selection Set for PWMH output of the channel 7 +#define AT91C_PWMC_OSSUPDH8 (0x1 << 8) // (PWMC) Output Selection Set for PWMH output of the channel 8 +#define AT91C_PWMC_OSSUPDH9 (0x1 << 9) // (PWMC) Output Selection Set for PWMH output of the channel 9 +#define AT91C_PWMC_OSSUPDH10 (0x1 << 10) // (PWMC) Output Selection Set for PWMH output of the channel 10 +#define AT91C_PWMC_OSSUPDH11 (0x1 << 11) // (PWMC) Output Selection Set for PWMH output of the channel 11 +#define AT91C_PWMC_OSSUPDH12 (0x1 << 12) // (PWMC) Output Selection Set for PWMH output of the channel 12 +#define AT91C_PWMC_OSSUPDH13 (0x1 << 13) // (PWMC) Output Selection Set for PWMH output of the channel 13 +#define AT91C_PWMC_OSSUPDH14 (0x1 << 14) // (PWMC) Output Selection Set for PWMH output of the channel 14 +#define AT91C_PWMC_OSSUPDH15 (0x1 << 15) // (PWMC) Output Selection Set for PWMH output of the channel 15 +#define AT91C_PWMC_OSSUPDL0 (0x1 << 16) // (PWMC) Output Selection Set for PWML output of the channel 0 +#define AT91C_PWMC_OSSUPDL1 (0x1 << 17) // (PWMC) Output Selection Set for PWML output of the channel 1 +#define AT91C_PWMC_OSSUPDL2 (0x1 << 18) // (PWMC) Output Selection Set for PWML output of the channel 2 +#define AT91C_PWMC_OSSUPDL3 (0x1 << 19) // (PWMC) Output Selection Set for PWML output of the channel 3 +#define AT91C_PWMC_OSSUPDL4 (0x1 << 20) // (PWMC) Output Selection Set for PWML output of the channel 4 +#define AT91C_PWMC_OSSUPDL5 (0x1 << 21) // (PWMC) Output Selection Set for PWML output of the channel 5 +#define AT91C_PWMC_OSSUPDL6 (0x1 << 22) // (PWMC) Output Selection Set for PWML output of the channel 6 +#define AT91C_PWMC_OSSUPDL7 (0x1 << 23) // (PWMC) Output Selection Set for PWML output of the channel 7 +#define AT91C_PWMC_OSSUPDL8 (0x1 << 24) // (PWMC) Output Selection Set for PWML output of the channel 8 +#define AT91C_PWMC_OSSUPDL9 (0x1 << 25) // (PWMC) Output Selection Set for PWML output of the channel 9 +#define AT91C_PWMC_OSSUPDL10 (0x1 << 26) // (PWMC) Output Selection Set for PWML output of the channel 10 +#define AT91C_PWMC_OSSUPDL11 (0x1 << 27) // (PWMC) Output Selection Set for PWML output of the channel 11 +#define AT91C_PWMC_OSSUPDL12 (0x1 << 28) // (PWMC) Output Selection Set for PWML output of the channel 12 +#define AT91C_PWMC_OSSUPDL13 (0x1 << 29) // (PWMC) Output Selection Set for PWML output of the channel 13 +#define AT91C_PWMC_OSSUPDL14 (0x1 << 30) // (PWMC) Output Selection Set for PWML output of the channel 14 +#define AT91C_PWMC_OSSUPDL15 (0x1 << 31) // (PWMC) Output Selection Set for PWML output of the channel 15 +// -------- PWMC_OSCUPD : (PWMC Offset: 0x58) Output Selection Clear for PWMH / PWML output of the channel x -------- +#define AT91C_PWMC_OSCUPDH0 (0x1 << 0) // (PWMC) Output Selection Clear for PWMH output of the channel 0 +#define AT91C_PWMC_OSCUPDH1 (0x1 << 1) // (PWMC) Output Selection Clear for PWMH output of the channel 1 +#define AT91C_PWMC_OSCUPDH2 (0x1 << 2) // (PWMC) Output Selection Clear for PWMH output of the channel 2 +#define AT91C_PWMC_OSCUPDH3 (0x1 << 3) // (PWMC) Output Selection Clear for PWMH output of the channel 3 +#define AT91C_PWMC_OSCUPDH4 (0x1 << 4) // (PWMC) Output Selection Clear for PWMH output of the channel 4 +#define AT91C_PWMC_OSCUPDH5 (0x1 << 5) // (PWMC) Output Selection Clear for PWMH output of the channel 5 +#define AT91C_PWMC_OSCUPDH6 (0x1 << 6) // (PWMC) Output Selection Clear for PWMH output of the channel 6 +#define AT91C_PWMC_OSCUPDH7 (0x1 << 7) // (PWMC) Output Selection Clear for PWMH output of the channel 7 +#define AT91C_PWMC_OSCUPDH8 (0x1 << 8) // (PWMC) Output Selection Clear for PWMH output of the channel 8 +#define AT91C_PWMC_OSCUPDH9 (0x1 << 9) // (PWMC) Output Selection Clear for PWMH output of the channel 9 +#define AT91C_PWMC_OSCUPDH10 (0x1 << 10) // (PWMC) Output Selection Clear for PWMH output of the channel 10 +#define AT91C_PWMC_OSCUPDH11 (0x1 << 11) // (PWMC) Output Selection Clear for PWMH output of the channel 11 +#define AT91C_PWMC_OSCUPDH12 (0x1 << 12) // (PWMC) Output Selection Clear for PWMH output of the channel 12 +#define AT91C_PWMC_OSCUPDH13 (0x1 << 13) // (PWMC) Output Selection Clear for PWMH output of the channel 13 +#define AT91C_PWMC_OSCUPDH14 (0x1 << 14) // (PWMC) Output Selection Clear for PWMH output of the channel 14 +#define AT91C_PWMC_OSCUPDH15 (0x1 << 15) // (PWMC) Output Selection Clear for PWMH output of the channel 15 +#define AT91C_PWMC_OSCUPDL0 (0x1 << 16) // (PWMC) Output Selection Clear for PWML output of the channel 0 +#define AT91C_PWMC_OSCUPDL1 (0x1 << 17) // (PWMC) Output Selection Clear for PWML output of the channel 1 +#define AT91C_PWMC_OSCUPDL2 (0x1 << 18) // (PWMC) Output Selection Clear for PWML output of the channel 2 +#define AT91C_PWMC_OSCUPDL3 (0x1 << 19) // (PWMC) Output Selection Clear for PWML output of the channel 3 +#define AT91C_PWMC_OSCUPDL4 (0x1 << 20) // (PWMC) Output Selection Clear for PWML output of the channel 4 +#define AT91C_PWMC_OSCUPDL5 (0x1 << 21) // (PWMC) Output Selection Clear for PWML output of the channel 5 +#define AT91C_PWMC_OSCUPDL6 (0x1 << 22) // (PWMC) Output Selection Clear for PWML output of the channel 6 +#define AT91C_PWMC_OSCUPDL7 (0x1 << 23) // (PWMC) Output Selection Clear for PWML output of the channel 7 +#define AT91C_PWMC_OSCUPDL8 (0x1 << 24) // (PWMC) Output Selection Clear for PWML output of the channel 8 +#define AT91C_PWMC_OSCUPDL9 (0x1 << 25) // (PWMC) Output Selection Clear for PWML output of the channel 9 +#define AT91C_PWMC_OSCUPDL10 (0x1 << 26) // (PWMC) Output Selection Clear for PWML output of the channel 10 +#define AT91C_PWMC_OSCUPDL11 (0x1 << 27) // (PWMC) Output Selection Clear for PWML output of the channel 11 +#define AT91C_PWMC_OSCUPDL12 (0x1 << 28) // (PWMC) Output Selection Clear for PWML output of the channel 12 +#define AT91C_PWMC_OSCUPDL13 (0x1 << 29) // (PWMC) Output Selection Clear for PWML output of the channel 13 +#define AT91C_PWMC_OSCUPDL14 (0x1 << 30) // (PWMC) Output Selection Clear for PWML output of the channel 14 +#define AT91C_PWMC_OSCUPDL15 (0x1 << 31) // (PWMC) Output Selection Clear for PWML output of the channel 15 +// -------- PWMC_FMR : (PWMC Offset: 0x5c) PWM Fault Mode Register -------- +#define AT91C_PWMC_FPOL0 (0x1 << 0) // (PWMC) Fault Polarity on fault input 0 +#define AT91C_PWMC_FPOL1 (0x1 << 1) // (PWMC) Fault Polarity on fault input 1 +#define AT91C_PWMC_FPOL2 (0x1 << 2) // (PWMC) Fault Polarity on fault input 2 +#define AT91C_PWMC_FPOL3 (0x1 << 3) // (PWMC) Fault Polarity on fault input 3 +#define AT91C_PWMC_FPOL4 (0x1 << 4) // (PWMC) Fault Polarity on fault input 4 +#define AT91C_PWMC_FPOL5 (0x1 << 5) // (PWMC) Fault Polarity on fault input 5 +#define AT91C_PWMC_FPOL6 (0x1 << 6) // (PWMC) Fault Polarity on fault input 6 +#define AT91C_PWMC_FPOL7 (0x1 << 7) // (PWMC) Fault Polarity on fault input 7 +#define AT91C_PWMC_FMOD0 (0x1 << 8) // (PWMC) Fault Activation Mode on fault input 0 +#define AT91C_PWMC_FMOD1 (0x1 << 9) // (PWMC) Fault Activation Mode on fault input 1 +#define AT91C_PWMC_FMOD2 (0x1 << 10) // (PWMC) Fault Activation Mode on fault input 2 +#define AT91C_PWMC_FMOD3 (0x1 << 11) // (PWMC) Fault Activation Mode on fault input 3 +#define AT91C_PWMC_FMOD4 (0x1 << 12) // (PWMC) Fault Activation Mode on fault input 4 +#define AT91C_PWMC_FMOD5 (0x1 << 13) // (PWMC) Fault Activation Mode on fault input 5 +#define AT91C_PWMC_FMOD6 (0x1 << 14) // (PWMC) Fault Activation Mode on fault input 6 +#define AT91C_PWMC_FMOD7 (0x1 << 15) // (PWMC) Fault Activation Mode on fault input 7 +#define AT91C_PWMC_FFIL00 (0x1 << 16) // (PWMC) Fault Filtering on fault input 0 +#define AT91C_PWMC_FFIL01 (0x1 << 17) // (PWMC) Fault Filtering on fault input 1 +#define AT91C_PWMC_FFIL02 (0x1 << 18) // (PWMC) Fault Filtering on fault input 2 +#define AT91C_PWMC_FFIL03 (0x1 << 19) // (PWMC) Fault Filtering on fault input 3 +#define AT91C_PWMC_FFIL04 (0x1 << 20) // (PWMC) Fault Filtering on fault input 4 +#define AT91C_PWMC_FFIL05 (0x1 << 21) // (PWMC) Fault Filtering on fault input 5 +#define AT91C_PWMC_FFIL06 (0x1 << 22) // (PWMC) Fault Filtering on fault input 6 +#define AT91C_PWMC_FFIL07 (0x1 << 23) // (PWMC) Fault Filtering on fault input 7 +// -------- PWMC_FSR : (PWMC Offset: 0x60) Fault Input x Value -------- +#define AT91C_PWMC_FIV0 (0x1 << 0) // (PWMC) Fault Input 0 Value +#define AT91C_PWMC_FIV1 (0x1 << 1) // (PWMC) Fault Input 1 Value +#define AT91C_PWMC_FIV2 (0x1 << 2) // (PWMC) Fault Input 2 Value +#define AT91C_PWMC_FIV3 (0x1 << 3) // (PWMC) Fault Input 3 Value +#define AT91C_PWMC_FIV4 (0x1 << 4) // (PWMC) Fault Input 4 Value +#define AT91C_PWMC_FIV5 (0x1 << 5) // (PWMC) Fault Input 5 Value +#define AT91C_PWMC_FIV6 (0x1 << 6) // (PWMC) Fault Input 6 Value +#define AT91C_PWMC_FIV7 (0x1 << 7) // (PWMC) Fault Input 7 Value +#define AT91C_PWMC_FS0 (0x1 << 8) // (PWMC) Fault 0 Status +#define AT91C_PWMC_FS1 (0x1 << 9) // (PWMC) Fault 1 Status +#define AT91C_PWMC_FS2 (0x1 << 10) // (PWMC) Fault 2 Status +#define AT91C_PWMC_FS3 (0x1 << 11) // (PWMC) Fault 3 Status +#define AT91C_PWMC_FS4 (0x1 << 12) // (PWMC) Fault 4 Status +#define AT91C_PWMC_FS5 (0x1 << 13) // (PWMC) Fault 5 Status +#define AT91C_PWMC_FS6 (0x1 << 14) // (PWMC) Fault 6 Status +#define AT91C_PWMC_FS7 (0x1 << 15) // (PWMC) Fault 7 Status +// -------- PWMC_FCR : (PWMC Offset: 0x64) Fault y Clear -------- +#define AT91C_PWMC_FCLR0 (0x1 << 0) // (PWMC) Fault 0 Clear +#define AT91C_PWMC_FCLR1 (0x1 << 1) // (PWMC) Fault 1 Clear +#define AT91C_PWMC_FCLR2 (0x1 << 2) // (PWMC) Fault 2 Clear +#define AT91C_PWMC_FCLR3 (0x1 << 3) // (PWMC) Fault 3 Clear +#define AT91C_PWMC_FCLR4 (0x1 << 4) // (PWMC) Fault 4 Clear +#define AT91C_PWMC_FCLR5 (0x1 << 5) // (PWMC) Fault 5 Clear +#define AT91C_PWMC_FCLR6 (0x1 << 6) // (PWMC) Fault 6 Clear +#define AT91C_PWMC_FCLR7 (0x1 << 7) // (PWMC) Fault 7 Clear +// -------- PWMC_FPV : (PWMC Offset: 0x68) PWM Fault Protection Value -------- +#define AT91C_PWMC_FPVH0 (0x1 << 0) // (PWMC) Fault Protection Value for PWMH output on channel 0 +#define AT91C_PWMC_FPVH1 (0x1 << 1) // (PWMC) Fault Protection Value for PWMH output on channel 1 +#define AT91C_PWMC_FPVH2 (0x1 << 2) // (PWMC) Fault Protection Value for PWMH output on channel 2 +#define AT91C_PWMC_FPVH3 (0x1 << 3) // (PWMC) Fault Protection Value for PWMH output on channel 3 +#define AT91C_PWMC_FPVH4 (0x1 << 4) // (PWMC) Fault Protection Value for PWMH output on channel 4 +#define AT91C_PWMC_FPVH5 (0x1 << 5) // (PWMC) Fault Protection Value for PWMH output on channel 5 +#define AT91C_PWMC_FPVH6 (0x1 << 6) // (PWMC) Fault Protection Value for PWMH output on channel 6 +#define AT91C_PWMC_FPVH7 (0x1 << 7) // (PWMC) Fault Protection Value for PWMH output on channel 7 +#define AT91C_PWMC_FPVL0 (0x1 << 16) // (PWMC) Fault Protection Value for PWML output on channel 0 +#define AT91C_PWMC_FPVL1 (0x1 << 17) // (PWMC) Fault Protection Value for PWML output on channel 1 +#define AT91C_PWMC_FPVL2 (0x1 << 18) // (PWMC) Fault Protection Value for PWML output on channel 2 +#define AT91C_PWMC_FPVL3 (0x1 << 19) // (PWMC) Fault Protection Value for PWML output on channel 3 +#define AT91C_PWMC_FPVL4 (0x1 << 20) // (PWMC) Fault Protection Value for PWML output on channel 4 +#define AT91C_PWMC_FPVL5 (0x1 << 21) // (PWMC) Fault Protection Value for PWML output on channel 5 +#define AT91C_PWMC_FPVL6 (0x1 << 22) // (PWMC) Fault Protection Value for PWML output on channel 6 +#define AT91C_PWMC_FPVL7 (0x1 << 23) // (PWMC) Fault Protection Value for PWML output on channel 7 +// -------- PWMC_FPER1 : (PWMC Offset: 0x6c) PWM Fault Protection Enable Register 1 -------- +#define AT91C_PWMC_FPE0 (0xFF << 0) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 0 +#define AT91C_PWMC_FPE1 (0xFF << 8) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 1 +#define AT91C_PWMC_FPE2 (0xFF << 16) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 2 +#define AT91C_PWMC_FPE3 (0xFF << 24) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 3 +// -------- PWMC_FPER2 : (PWMC Offset: 0x70) PWM Fault Protection Enable Register 2 -------- +#define AT91C_PWMC_FPE4 (0xFF << 0) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 4 +#define AT91C_PWMC_FPE5 (0xFF << 8) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 5 +#define AT91C_PWMC_FPE6 (0xFF << 16) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 6 +#define AT91C_PWMC_FPE7 (0xFF << 24) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 7 +// -------- PWMC_FPER3 : (PWMC Offset: 0x74) PWM Fault Protection Enable Register 3 -------- +#define AT91C_PWMC_FPE8 (0xFF << 0) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 8 +#define AT91C_PWMC_FPE9 (0xFF << 8) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 9 +#define AT91C_PWMC_FPE10 (0xFF << 16) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 10 +#define AT91C_PWMC_FPE11 (0xFF << 24) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 11 +// -------- PWMC_FPER4 : (PWMC Offset: 0x78) PWM Fault Protection Enable Register 4 -------- +#define AT91C_PWMC_FPE12 (0xFF << 0) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 12 +#define AT91C_PWMC_FPE13 (0xFF << 8) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 13 +#define AT91C_PWMC_FPE14 (0xFF << 16) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 14 +#define AT91C_PWMC_FPE15 (0xFF << 24) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 15 +// -------- PWMC_EL0MR : (PWMC Offset: 0x7c) PWM Event Line 0 Mode Register -------- +#define AT91C_PWMC_L0CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L0CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L0CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L0CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L0CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L0CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L0CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L0CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL1MR : (PWMC Offset: 0x80) PWM Event Line 1 Mode Register -------- +#define AT91C_PWMC_L1CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L1CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L1CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L1CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L1CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L1CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L1CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L1CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL2MR : (PWMC Offset: 0x84) PWM Event line 2 Mode Register -------- +#define AT91C_PWMC_L2CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L2CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L2CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L2CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L2CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L2CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L2CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L2CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL3MR : (PWMC Offset: 0x88) PWM Event line 3 Mode Register -------- +#define AT91C_PWMC_L3CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L3CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L3CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L3CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L3CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L3CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L3CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L3CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL4MR : (PWMC Offset: 0x8c) PWM Event line 4 Mode Register -------- +#define AT91C_PWMC_L4CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L4CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L4CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L4CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L4CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L4CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L4CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L4CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL5MR : (PWMC Offset: 0x90) PWM Event line 5 Mode Register -------- +#define AT91C_PWMC_L5CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L5CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L5CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L5CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L5CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L5CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L5CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L5CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL6MR : (PWMC Offset: 0x94) PWM Event line 6 Mode Register -------- +#define AT91C_PWMC_L6CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L6CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L6CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L6CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L6CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L6CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L6CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L6CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL7MR : (PWMC Offset: 0x98) PWM Event line 7 Mode Register -------- +#define AT91C_PWMC_L7CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L7CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L7CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L7CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L7CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L7CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L7CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L7CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_WPCR : (PWMC Offset: 0xe4) PWM Write Protection Control Register -------- +#define AT91C_PWMC_WPCMD (0x3 << 0) // (PWMC) Write Protection Command +#define AT91C_PWMC_WPRG0 (0x1 << 2) // (PWMC) Write Protect Register Group 0 +#define AT91C_PWMC_WPRG1 (0x1 << 3) // (PWMC) Write Protect Register Group 1 +#define AT91C_PWMC_WPRG2 (0x1 << 4) // (PWMC) Write Protect Register Group 2 +#define AT91C_PWMC_WPRG3 (0x1 << 5) // (PWMC) Write Protect Register Group 3 +#define AT91C_PWMC_WPRG4 (0x1 << 6) // (PWMC) Write Protect Register Group 4 +#define AT91C_PWMC_WPRG5 (0x1 << 7) // (PWMC) Write Protect Register Group 5 +#define AT91C_PWMC_WPKEY (0xFFFFFF << 8) // (PWMC) Protection Password +// -------- PWMC_WPVS : (PWMC Offset: 0xe8) Write Protection Status Register -------- +#define AT91C_PWMC_WPSWS0 (0x1 << 0) // (PWMC) Write Protect SW Group 0 Status +#define AT91C_PWMC_WPSWS1 (0x1 << 1) // (PWMC) Write Protect SW Group 1 Status +#define AT91C_PWMC_WPSWS2 (0x1 << 2) // (PWMC) Write Protect SW Group 2 Status +#define AT91C_PWMC_WPSWS3 (0x1 << 3) // (PWMC) Write Protect SW Group 3 Status +#define AT91C_PWMC_WPSWS4 (0x1 << 4) // (PWMC) Write Protect SW Group 4 Status +#define AT91C_PWMC_WPSWS5 (0x1 << 5) // (PWMC) Write Protect SW Group 5 Status +#define AT91C_PWMC_WPVS (0x1 << 7) // (PWMC) Write Protection Enable +#define AT91C_PWMC_WPHWS0 (0x1 << 8) // (PWMC) Write Protect HW Group 0 Status +#define AT91C_PWMC_WPHWS1 (0x1 << 9) // (PWMC) Write Protect HW Group 1 Status +#define AT91C_PWMC_WPHWS2 (0x1 << 10) // (PWMC) Write Protect HW Group 2 Status +#define AT91C_PWMC_WPHWS3 (0x1 << 11) // (PWMC) Write Protect HW Group 3 Status +#define AT91C_PWMC_WPHWS4 (0x1 << 12) // (PWMC) Write Protect HW Group 4 Status +#define AT91C_PWMC_WPHWS5 (0x1 << 13) // (PWMC) Write Protect HW Group 5 Status +#define AT91C_PWMC_WPVSRC (0xFFFF << 16) // (PWMC) Write Protection Violation Source +// -------- PWMC_CMP0V : (PWMC Offset: 0x130) PWM Comparison Value 0 Register -------- +#define AT91C_PWMC_CV (0xFFFFFF << 0) // (PWMC) PWM Comparison Value 0. +#define AT91C_PWMC_CVM (0x1 << 24) // (PWMC) Comparison Value 0 Mode. +// -------- PWMC_CMP0VUPD : (PWMC Offset: 0x134) PWM Comparison Value 0 Update Register -------- +#define AT91C_PWMC_CVUPD (0xFFFFFF << 0) // (PWMC) PWM Comparison Value Update. +#define AT91C_PWMC_CVMUPD (0x1 << 24) // (PWMC) Comparison Value Update Mode. +// -------- PWMC_CMP0M : (PWMC Offset: 0x138) PWM Comparison 0 Mode Register -------- +#define AT91C_PWMC_CEN (0x1 << 0) // (PWMC) Comparison Enable. +#define AT91C_PWMC_CTR (0xF << 4) // (PWMC) PWM Comparison Trigger. +#define AT91C_PWMC_CPR (0xF << 8) // (PWMC) PWM Comparison Period. +#define AT91C_PWMC_CPRCNT (0xF << 12) // (PWMC) PWM Comparison Period Counter. +#define AT91C_PWMC_CUPR (0xF << 16) // (PWMC) PWM Comparison Update Period. +#define AT91C_PWMC_CUPRCNT (0xF << 20) // (PWMC) PWM Comparison Update Period Counter. +// -------- PWMC_CMP0MUPD : (PWMC Offset: 0x13c) PWM Comparison 0 Mode Update Register -------- +#define AT91C_PWMC_CENUPD (0x1 << 0) // (PWMC) Comparison Enable Update. +#define AT91C_PWMC_CTRUPD (0xF << 4) // (PWMC) PWM Comparison Trigger Update. +#define AT91C_PWMC_CPRUPD (0xF << 8) // (PWMC) PWM Comparison Period Update. +#define AT91C_PWMC_CUPRUPD (0xF << 16) // (PWMC) PWM Comparison Update Period Update. +// -------- PWMC_CMP1V : (PWMC Offset: 0x140) PWM Comparison Value 1 Register -------- +// -------- PWMC_CMP1VUPD : (PWMC Offset: 0x144) PWM Comparison Value 1 Update Register -------- +// -------- PWMC_CMP1M : (PWMC Offset: 0x148) PWM Comparison 1 Mode Register -------- +// -------- PWMC_CMP1MUPD : (PWMC Offset: 0x14c) PWM Comparison 1 Mode Update Register -------- +// -------- PWMC_CMP2V : (PWMC Offset: 0x150) PWM Comparison Value 2 Register -------- +// -------- PWMC_CMP2VUPD : (PWMC Offset: 0x154) PWM Comparison Value 2 Update Register -------- +// -------- PWMC_CMP2M : (PWMC Offset: 0x158) PWM Comparison 2 Mode Register -------- +// -------- PWMC_CMP2MUPD : (PWMC Offset: 0x15c) PWM Comparison 2 Mode Update Register -------- +// -------- PWMC_CMP3V : (PWMC Offset: 0x160) PWM Comparison Value 3 Register -------- +// -------- PWMC_CMP3VUPD : (PWMC Offset: 0x164) PWM Comparison Value 3 Update Register -------- +// -------- PWMC_CMP3M : (PWMC Offset: 0x168) PWM Comparison 3 Mode Register -------- +// -------- PWMC_CMP3MUPD : (PWMC Offset: 0x16c) PWM Comparison 3 Mode Update Register -------- +// -------- PWMC_CMP4V : (PWMC Offset: 0x170) PWM Comparison Value 4 Register -------- +// -------- PWMC_CMP4VUPD : (PWMC Offset: 0x174) PWM Comparison Value 4 Update Register -------- +// -------- PWMC_CMP4M : (PWMC Offset: 0x178) PWM Comparison 4 Mode Register -------- +// -------- PWMC_CMP4MUPD : (PWMC Offset: 0x17c) PWM Comparison 4 Mode Update Register -------- +// -------- PWMC_CMP5V : (PWMC Offset: 0x180) PWM Comparison Value 5 Register -------- +// -------- PWMC_CMP5VUPD : (PWMC Offset: 0x184) PWM Comparison Value 5 Update Register -------- +// -------- PWMC_CMP5M : (PWMC Offset: 0x188) PWM Comparison 5 Mode Register -------- +// -------- PWMC_CMP5MUPD : (PWMC Offset: 0x18c) PWM Comparison 5 Mode Update Register -------- +// -------- PWMC_CMP6V : (PWMC Offset: 0x190) PWM Comparison Value 6 Register -------- +// -------- PWMC_CMP6VUPD : (PWMC Offset: 0x194) PWM Comparison Value 6 Update Register -------- +// -------- PWMC_CMP6M : (PWMC Offset: 0x198) PWM Comparison 6 Mode Register -------- +// -------- PWMC_CMP6MUPD : (PWMC Offset: 0x19c) PWM Comparison 6 Mode Update Register -------- +// -------- PWMC_CMP7V : (PWMC Offset: 0x1a0) PWM Comparison Value 7 Register -------- +// -------- PWMC_CMP7VUPD : (PWMC Offset: 0x1a4) PWM Comparison Value 7 Update Register -------- +// -------- PWMC_CMP7M : (PWMC Offset: 0x1a8) PWM Comparison 7 Mode Register -------- +// -------- PWMC_CMP7MUPD : (PWMC Offset: 0x1ac) PWM Comparison 7 Mode Update Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Serial Parallel Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_SPI { + AT91_REG SPI_CR; // Control Register + AT91_REG SPI_MR; // Mode Register + AT91_REG SPI_RDR; // Receive Data Register + AT91_REG SPI_TDR; // Transmit Data Register + AT91_REG SPI_SR; // Status Register + AT91_REG SPI_IER; // Interrupt Enable Register + AT91_REG SPI_IDR; // Interrupt Disable Register + AT91_REG SPI_IMR; // Interrupt Mask Register + AT91_REG Reserved0[4]; // + AT91_REG SPI_CSR[4]; // Chip Select Register + AT91_REG Reserved1[43]; // + AT91_REG SPI_ADDRSIZE; // SPI ADDRSIZE REGISTER + AT91_REG SPI_IPNAME1; // SPI IPNAME1 REGISTER + AT91_REG SPI_IPNAME2; // SPI IPNAME2 REGISTER + AT91_REG SPI_FEATURES; // SPI FEATURES REGISTER + AT91_REG SPI_VER; // Version Register + AT91_REG SPI_RPR; // Receive Pointer Register + AT91_REG SPI_RCR; // Receive Counter Register + AT91_REG SPI_TPR; // Transmit Pointer Register + AT91_REG SPI_TCR; // Transmit Counter Register + AT91_REG SPI_RNPR; // Receive Next Pointer Register + AT91_REG SPI_RNCR; // Receive Next Counter Register + AT91_REG SPI_TNPR; // Transmit Next Pointer Register + AT91_REG SPI_TNCR; // Transmit Next Counter Register + AT91_REG SPI_PTCR; // PDC Transfer Control Register + AT91_REG SPI_PTSR; // PDC Transfer Status Register +} AT91S_SPI, *AT91PS_SPI; +#else +#define SPI_CR (AT91_CAST(AT91_REG *) 0x00000000) // (SPI_CR) Control Register +#define SPI_MR (AT91_CAST(AT91_REG *) 0x00000004) // (SPI_MR) Mode Register +#define SPI_RDR (AT91_CAST(AT91_REG *) 0x00000008) // (SPI_RDR) Receive Data Register +#define SPI_TDR (AT91_CAST(AT91_REG *) 0x0000000C) // (SPI_TDR) Transmit Data Register +#define SPI_SR (AT91_CAST(AT91_REG *) 0x00000010) // (SPI_SR) Status Register +#define SPI_IER (AT91_CAST(AT91_REG *) 0x00000014) // (SPI_IER) Interrupt Enable Register +#define SPI_IDR (AT91_CAST(AT91_REG *) 0x00000018) // (SPI_IDR) Interrupt Disable Register +#define SPI_IMR (AT91_CAST(AT91_REG *) 0x0000001C) // (SPI_IMR) Interrupt Mask Register +#define SPI_CSR (AT91_CAST(AT91_REG *) 0x00000030) // (SPI_CSR) Chip Select Register +#define SPI_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (SPI_ADDRSIZE) SPI ADDRSIZE REGISTER +#define SPI_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (SPI_IPNAME1) SPI IPNAME1 REGISTER +#define SPI_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (SPI_IPNAME2) SPI IPNAME2 REGISTER +#define SPI_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (SPI_FEATURES) SPI FEATURES REGISTER +#define SPI_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (SPI_VER) Version Register + +#endif +// -------- SPI_CR : (SPI Offset: 0x0) SPI Control Register -------- +#define AT91C_SPI_SPIEN (0x1 << 0) // (SPI) SPI Enable +#define AT91C_SPI_SPIDIS (0x1 << 1) // (SPI) SPI Disable +#define AT91C_SPI_SWRST (0x1 << 7) // (SPI) SPI Software reset +#define AT91C_SPI_LASTXFER (0x1 << 24) // (SPI) SPI Last Transfer +// -------- SPI_MR : (SPI Offset: 0x4) SPI Mode Register -------- +#define AT91C_SPI_MSTR (0x1 << 0) // (SPI) Master/Slave Mode +#define AT91C_SPI_PS (0x1 << 1) // (SPI) Peripheral Select +#define AT91C_SPI_PS_FIXED (0x0 << 1) // (SPI) Fixed Peripheral Select +#define AT91C_SPI_PS_VARIABLE (0x1 << 1) // (SPI) Variable Peripheral Select +#define AT91C_SPI_PCSDEC (0x1 << 2) // (SPI) Chip Select Decode +#define AT91C_SPI_FDIV (0x1 << 3) // (SPI) Clock Selection +#define AT91C_SPI_MODFDIS (0x1 << 4) // (SPI) Mode Fault Detection +#define AT91C_SPI_LLB (0x1 << 7) // (SPI) Clock Selection +#define AT91C_SPI_PCS (0xF << 16) // (SPI) Peripheral Chip Select +#define AT91C_SPI_DLYBCS (0xFF << 24) // (SPI) Delay Between Chip Selects +// -------- SPI_RDR : (SPI Offset: 0x8) Receive Data Register -------- +#define AT91C_SPI_RD (0xFFFF << 0) // (SPI) Receive Data +#define AT91C_SPI_RPCS (0xF << 16) // (SPI) Peripheral Chip Select Status +// -------- SPI_TDR : (SPI Offset: 0xc) Transmit Data Register -------- +#define AT91C_SPI_TD (0xFFFF << 0) // (SPI) Transmit Data +#define AT91C_SPI_TPCS (0xF << 16) // (SPI) Peripheral Chip Select Status +// -------- SPI_SR : (SPI Offset: 0x10) Status Register -------- +#define AT91C_SPI_RDRF (0x1 << 0) // (SPI) Receive Data Register Full +#define AT91C_SPI_TDRE (0x1 << 1) // (SPI) Transmit Data Register Empty +#define AT91C_SPI_MODF (0x1 << 2) // (SPI) Mode Fault Error +#define AT91C_SPI_OVRES (0x1 << 3) // (SPI) Overrun Error Status +#define AT91C_SPI_ENDRX (0x1 << 4) // (SPI) End of Receiver Transfer +#define AT91C_SPI_ENDTX (0x1 << 5) // (SPI) End of Receiver Transfer +#define AT91C_SPI_RXBUFF (0x1 << 6) // (SPI) RXBUFF Interrupt +#define AT91C_SPI_TXBUFE (0x1 << 7) // (SPI) TXBUFE Interrupt +#define AT91C_SPI_NSSR (0x1 << 8) // (SPI) NSSR Interrupt +#define AT91C_SPI_TXEMPTY (0x1 << 9) // (SPI) TXEMPTY Interrupt +#define AT91C_SPI_SPIENS (0x1 << 16) // (SPI) Enable Status +// -------- SPI_IER : (SPI Offset: 0x14) Interrupt Enable Register -------- +// -------- SPI_IDR : (SPI Offset: 0x18) Interrupt Disable Register -------- +// -------- SPI_IMR : (SPI Offset: 0x1c) Interrupt Mask Register -------- +// -------- SPI_CSR : (SPI Offset: 0x30) Chip Select Register -------- +#define AT91C_SPI_CPOL (0x1 << 0) // (SPI) Clock Polarity +#define AT91C_SPI_NCPHA (0x1 << 1) // (SPI) Clock Phase +#define AT91C_SPI_CSNAAT (0x1 << 2) // (SPI) Chip Select Not Active After Transfer (Ignored if CSAAT = 1) +#define AT91C_SPI_CSAAT (0x1 << 3) // (SPI) Chip Select Active After Transfer +#define AT91C_SPI_BITS (0xF << 4) // (SPI) Bits Per Transfer +#define AT91C_SPI_BITS_8 (0x0 << 4) // (SPI) 8 Bits Per transfer +#define AT91C_SPI_BITS_9 (0x1 << 4) // (SPI) 9 Bits Per transfer +#define AT91C_SPI_BITS_10 (0x2 << 4) // (SPI) 10 Bits Per transfer +#define AT91C_SPI_BITS_11 (0x3 << 4) // (SPI) 11 Bits Per transfer +#define AT91C_SPI_BITS_12 (0x4 << 4) // (SPI) 12 Bits Per transfer +#define AT91C_SPI_BITS_13 (0x5 << 4) // (SPI) 13 Bits Per transfer +#define AT91C_SPI_BITS_14 (0x6 << 4) // (SPI) 14 Bits Per transfer +#define AT91C_SPI_BITS_15 (0x7 << 4) // (SPI) 15 Bits Per transfer +#define AT91C_SPI_BITS_16 (0x8 << 4) // (SPI) 16 Bits Per transfer +#define AT91C_SPI_SCBR (0xFF << 8) // (SPI) Serial Clock Baud Rate +#define AT91C_SPI_DLYBS (0xFF << 16) // (SPI) Serial Clock Baud Rate +#define AT91C_SPI_DLYBCT (0xFF << 24) // (SPI) Delay Between Consecutive Transfers + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR UDPHS Enpoint FIFO data register +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_UDPHS_EPTFIFO { + AT91_REG UDPHS_READEPT0[16384]; // FIFO Endpoint Data Register 0 + AT91_REG UDPHS_READEPT1[16384]; // FIFO Endpoint Data Register 1 + AT91_REG UDPHS_READEPT2[16384]; // FIFO Endpoint Data Register 2 + AT91_REG UDPHS_READEPT3[16384]; // FIFO Endpoint Data Register 3 + AT91_REG UDPHS_READEPT4[16384]; // FIFO Endpoint Data Register 4 + AT91_REG UDPHS_READEPT5[16384]; // FIFO Endpoint Data Register 5 + AT91_REG UDPHS_READEPT6[16384]; // FIFO Endpoint Data Register 6 +} AT91S_UDPHS_EPTFIFO, *AT91PS_UDPHS_EPTFIFO; +#else +#define UDPHS_READEPT0 (AT91_CAST(AT91_REG *) 0x00000000) // (UDPHS_READEPT0) FIFO Endpoint Data Register 0 +#define UDPHS_READEPT1 (AT91_CAST(AT91_REG *) 0x00010000) // (UDPHS_READEPT1) FIFO Endpoint Data Register 1 +#define UDPHS_READEPT2 (AT91_CAST(AT91_REG *) 0x00020000) // (UDPHS_READEPT2) FIFO Endpoint Data Register 2 +#define UDPHS_READEPT3 (AT91_CAST(AT91_REG *) 0x00030000) // (UDPHS_READEPT3) FIFO Endpoint Data Register 3 +#define UDPHS_READEPT4 (AT91_CAST(AT91_REG *) 0x00040000) // (UDPHS_READEPT4) FIFO Endpoint Data Register 4 +#define UDPHS_READEPT5 (AT91_CAST(AT91_REG *) 0x00050000) // (UDPHS_READEPT5) FIFO Endpoint Data Register 5 +#define UDPHS_READEPT6 (AT91_CAST(AT91_REG *) 0x00060000) // (UDPHS_READEPT6) FIFO Endpoint Data Register 6 + +#endif + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR UDPHS Endpoint struct +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_UDPHS_EPT { + AT91_REG UDPHS_EPTCFG; // UDPHS Endpoint Config Register + AT91_REG UDPHS_EPTCTLENB; // UDPHS Endpoint Control Enable Register + AT91_REG UDPHS_EPTCTLDIS; // UDPHS Endpoint Control Disable Register + AT91_REG UDPHS_EPTCTL; // UDPHS Endpoint Control Register + AT91_REG Reserved0[1]; // + AT91_REG UDPHS_EPTSETSTA; // UDPHS Endpoint Set Status Register + AT91_REG UDPHS_EPTCLRSTA; // UDPHS Endpoint Clear Status Register + AT91_REG UDPHS_EPTSTA; // UDPHS Endpoint Status Register +} AT91S_UDPHS_EPT, *AT91PS_UDPHS_EPT; +#else +#define UDPHS_EPTCFG (AT91_CAST(AT91_REG *) 0x00000000) // (UDPHS_EPTCFG) UDPHS Endpoint Config Register +#define UDPHS_EPTCTLENB (AT91_CAST(AT91_REG *) 0x00000004) // (UDPHS_EPTCTLENB) UDPHS Endpoint Control Enable Register +#define UDPHS_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x00000008) // (UDPHS_EPTCTLDIS) UDPHS Endpoint Control Disable Register +#define UDPHS_EPTCTL (AT91_CAST(AT91_REG *) 0x0000000C) // (UDPHS_EPTCTL) UDPHS Endpoint Control Register +#define UDPHS_EPTSETSTA (AT91_CAST(AT91_REG *) 0x00000014) // (UDPHS_EPTSETSTA) UDPHS Endpoint Set Status Register +#define UDPHS_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x00000018) // (UDPHS_EPTCLRSTA) UDPHS Endpoint Clear Status Register +#define UDPHS_EPTSTA (AT91_CAST(AT91_REG *) 0x0000001C) // (UDPHS_EPTSTA) UDPHS Endpoint Status Register + +#endif +// -------- UDPHS_EPTCFG : (UDPHS_EPT Offset: 0x0) UDPHS Endpoint Config Register -------- +#define AT91C_UDPHS_EPT_SIZE (0x7 << 0) // (UDPHS_EPT) Endpoint Size +#define AT91C_UDPHS_EPT_SIZE_8 (0x0) // (UDPHS_EPT) 8 bytes +#define AT91C_UDPHS_EPT_SIZE_16 (0x1) // (UDPHS_EPT) 16 bytes +#define AT91C_UDPHS_EPT_SIZE_32 (0x2) // (UDPHS_EPT) 32 bytes +#define AT91C_UDPHS_EPT_SIZE_64 (0x3) // (UDPHS_EPT) 64 bytes +#define AT91C_UDPHS_EPT_SIZE_128 (0x4) // (UDPHS_EPT) 128 bytes +#define AT91C_UDPHS_EPT_SIZE_256 (0x5) // (UDPHS_EPT) 256 bytes (if possible) +#define AT91C_UDPHS_EPT_SIZE_512 (0x6) // (UDPHS_EPT) 512 bytes (if possible) +#define AT91C_UDPHS_EPT_SIZE_1024 (0x7) // (UDPHS_EPT) 1024 bytes (if possible) +#define AT91C_UDPHS_EPT_DIR (0x1 << 3) // (UDPHS_EPT) Endpoint Direction 0:OUT, 1:IN +#define AT91C_UDPHS_EPT_DIR_OUT (0x0 << 3) // (UDPHS_EPT) Direction OUT +#define AT91C_UDPHS_EPT_DIR_IN (0x1 << 3) // (UDPHS_EPT) Direction IN +#define AT91C_UDPHS_EPT_TYPE (0x3 << 4) // (UDPHS_EPT) Endpoint Type +#define AT91C_UDPHS_EPT_TYPE_CTL_EPT (0x0 << 4) // (UDPHS_EPT) Control endpoint +#define AT91C_UDPHS_EPT_TYPE_ISO_EPT (0x1 << 4) // (UDPHS_EPT) Isochronous endpoint +#define AT91C_UDPHS_EPT_TYPE_BUL_EPT (0x2 << 4) // (UDPHS_EPT) Bulk endpoint +#define AT91C_UDPHS_EPT_TYPE_INT_EPT (0x3 << 4) // (UDPHS_EPT) Interrupt endpoint +#define AT91C_UDPHS_BK_NUMBER (0x3 << 6) // (UDPHS_EPT) Number of Banks +#define AT91C_UDPHS_BK_NUMBER_0 (0x0 << 6) // (UDPHS_EPT) Zero Bank, the EndPoint is not mapped in memory +#define AT91C_UDPHS_BK_NUMBER_1 (0x1 << 6) // (UDPHS_EPT) One Bank (Bank0) +#define AT91C_UDPHS_BK_NUMBER_2 (0x2 << 6) // (UDPHS_EPT) Double bank (Ping-Pong : Bank0 / Bank1) +#define AT91C_UDPHS_BK_NUMBER_3 (0x3 << 6) // (UDPHS_EPT) Triple Bank (Bank0 / Bank1 / Bank2) (if possible) +#define AT91C_UDPHS_NB_TRANS (0x3 << 8) // (UDPHS_EPT) Number Of Transaction per Micro-Frame (High-Bandwidth iso only) +#define AT91C_UDPHS_EPT_MAPD (0x1 << 31) // (UDPHS_EPT) Endpoint Mapped (read only +// -------- UDPHS_EPTCTLENB : (UDPHS_EPT Offset: 0x4) UDPHS Endpoint Control Enable Register -------- +#define AT91C_UDPHS_EPT_ENABL (0x1 << 0) // (UDPHS_EPT) Endpoint Enable +#define AT91C_UDPHS_AUTO_VALID (0x1 << 1) // (UDPHS_EPT) Packet Auto-Valid Enable/Disable +#define AT91C_UDPHS_INTDIS_DMA (0x1 << 3) // (UDPHS_EPT) Endpoint Interrupts DMA Request Enable/Disable +#define AT91C_UDPHS_NYET_DIS (0x1 << 4) // (UDPHS_EPT) NYET Enable/Disable +#define AT91C_UDPHS_DATAX_RX (0x1 << 6) // (UDPHS_EPT) DATAx Interrupt Enable/Disable +#define AT91C_UDPHS_MDATA_RX (0x1 << 7) // (UDPHS_EPT) MDATA Interrupt Enabled/Disable +#define AT91C_UDPHS_ERR_OVFLW (0x1 << 8) // (UDPHS_EPT) OverFlow Error Interrupt Enable/Disable/Status +#define AT91C_UDPHS_RX_BK_RDY (0x1 << 9) // (UDPHS_EPT) Received OUT Data +#define AT91C_UDPHS_TX_COMPLT (0x1 << 10) // (UDPHS_EPT) Transmitted IN Data Complete Interrupt Enable/Disable or Transmitted IN Data Complete (clear) +#define AT91C_UDPHS_ERR_TRANS (0x1 << 11) // (UDPHS_EPT) Transaction Error Interrupt Enable/Disable +#define AT91C_UDPHS_TX_PK_RDY (0x1 << 11) // (UDPHS_EPT) TX Packet Ready Interrupt Enable/Disable +#define AT91C_UDPHS_RX_SETUP (0x1 << 12) // (UDPHS_EPT) Received SETUP Interrupt Enable/Disable +#define AT91C_UDPHS_ERR_FL_ISO (0x1 << 12) // (UDPHS_EPT) Error Flow Clear/Interrupt Enable/Disable +#define AT91C_UDPHS_STALL_SNT (0x1 << 13) // (UDPHS_EPT) Stall Sent Clear +#define AT91C_UDPHS_ERR_CRISO (0x1 << 13) // (UDPHS_EPT) CRC error / Error NB Trans / Interrupt Enable/Disable +#define AT91C_UDPHS_NAK_IN (0x1 << 14) // (UDPHS_EPT) NAKIN ERROR FLUSH / Clear / Interrupt Enable/Disable +#define AT91C_UDPHS_NAK_OUT (0x1 << 15) // (UDPHS_EPT) NAKOUT / Clear / Interrupt Enable/Disable +#define AT91C_UDPHS_BUSY_BANK (0x1 << 18) // (UDPHS_EPT) Busy Bank Interrupt Enable/Disable +#define AT91C_UDPHS_SHRT_PCKT (0x1 << 31) // (UDPHS_EPT) Short Packet / Interrupt Enable/Disable +// -------- UDPHS_EPTCTLDIS : (UDPHS_EPT Offset: 0x8) UDPHS Endpoint Control Disable Register -------- +#define AT91C_UDPHS_EPT_DISABL (0x1 << 0) // (UDPHS_EPT) Endpoint Disable +// -------- UDPHS_EPTCTL : (UDPHS_EPT Offset: 0xc) UDPHS Endpoint Control Register -------- +// -------- UDPHS_EPTSETSTA : (UDPHS_EPT Offset: 0x14) UDPHS Endpoint Set Status Register -------- +#define AT91C_UDPHS_FRCESTALL (0x1 << 5) // (UDPHS_EPT) Stall Handshake Request Set/Clear/Status +#define AT91C_UDPHS_KILL_BANK (0x1 << 9) // (UDPHS_EPT) KILL Bank +// -------- UDPHS_EPTCLRSTA : (UDPHS_EPT Offset: 0x18) UDPHS Endpoint Clear Status Register -------- +#define AT91C_UDPHS_TOGGLESQ (0x1 << 6) // (UDPHS_EPT) Data Toggle Clear +// -------- UDPHS_EPTSTA : (UDPHS_EPT Offset: 0x1c) UDPHS Endpoint Status Register -------- +#define AT91C_UDPHS_TOGGLESQ_STA (0x3 << 6) // (UDPHS_EPT) Toggle Sequencing +#define AT91C_UDPHS_TOGGLESQ_STA_00 (0x0 << 6) // (UDPHS_EPT) Data0 +#define AT91C_UDPHS_TOGGLESQ_STA_01 (0x1 << 6) // (UDPHS_EPT) Data1 +#define AT91C_UDPHS_TOGGLESQ_STA_10 (0x2 << 6) // (UDPHS_EPT) Data2 (only for High-Bandwidth Isochronous EndPoint) +#define AT91C_UDPHS_TOGGLESQ_STA_11 (0x3 << 6) // (UDPHS_EPT) MData (only for High-Bandwidth Isochronous EndPoint) +#define AT91C_UDPHS_CONTROL_DIR (0x3 << 16) // (UDPHS_EPT) +#define AT91C_UDPHS_CONTROL_DIR_00 (0x0 << 16) // (UDPHS_EPT) Bank 0 +#define AT91C_UDPHS_CONTROL_DIR_01 (0x1 << 16) // (UDPHS_EPT) Bank 1 +#define AT91C_UDPHS_CONTROL_DIR_10 (0x2 << 16) // (UDPHS_EPT) Bank 2 +#define AT91C_UDPHS_CONTROL_DIR_11 (0x3 << 16) // (UDPHS_EPT) Invalid +#define AT91C_UDPHS_CURRENT_BANK (0x3 << 16) // (UDPHS_EPT) +#define AT91C_UDPHS_CURRENT_BANK_00 (0x0 << 16) // (UDPHS_EPT) Bank 0 +#define AT91C_UDPHS_CURRENT_BANK_01 (0x1 << 16) // (UDPHS_EPT) Bank 1 +#define AT91C_UDPHS_CURRENT_BANK_10 (0x2 << 16) // (UDPHS_EPT) Bank 2 +#define AT91C_UDPHS_CURRENT_BANK_11 (0x3 << 16) // (UDPHS_EPT) Invalid +#define AT91C_UDPHS_BUSY_BANK_STA (0x3 << 18) // (UDPHS_EPT) Busy Bank Number +#define AT91C_UDPHS_BUSY_BANK_STA_00 (0x0 << 18) // (UDPHS_EPT) All banks are free +#define AT91C_UDPHS_BUSY_BANK_STA_01 (0x1 << 18) // (UDPHS_EPT) 1 busy bank +#define AT91C_UDPHS_BUSY_BANK_STA_10 (0x2 << 18) // (UDPHS_EPT) 2 busy banks +#define AT91C_UDPHS_BUSY_BANK_STA_11 (0x3 << 18) // (UDPHS_EPT) 3 busy banks (if possible) +#define AT91C_UDPHS_BYTE_COUNT (0x7FF << 20) // (UDPHS_EPT) UDPHS Byte Count + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR UDPHS DMA struct +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_UDPHS_DMA { + AT91_REG UDPHS_DMANXTDSC; // UDPHS DMA Channel Next Descriptor Address + AT91_REG UDPHS_DMAADDRESS; // UDPHS DMA Channel Address Register + AT91_REG UDPHS_DMACONTROL; // UDPHS DMA Channel Control Register + AT91_REG UDPHS_DMASTATUS; // UDPHS DMA Channel Status Register +} AT91S_UDPHS_DMA, *AT91PS_UDPHS_DMA; +#else +#define UDPHS_DMANXTDSC (AT91_CAST(AT91_REG *) 0x00000000) // (UDPHS_DMANXTDSC) UDPHS DMA Channel Next Descriptor Address +#define UDPHS_DMAADDRESS (AT91_CAST(AT91_REG *) 0x00000004) // (UDPHS_DMAADDRESS) UDPHS DMA Channel Address Register +#define UDPHS_DMACONTROL (AT91_CAST(AT91_REG *) 0x00000008) // (UDPHS_DMACONTROL) UDPHS DMA Channel Control Register +#define UDPHS_DMASTATUS (AT91_CAST(AT91_REG *) 0x0000000C) // (UDPHS_DMASTATUS) UDPHS DMA Channel Status Register + +#endif +// -------- UDPHS_DMANXTDSC : (UDPHS_DMA Offset: 0x0) UDPHS DMA Next Descriptor Address Register -------- +#define AT91C_UDPHS_NXT_DSC_ADD (0xFFFFFFF << 4) // (UDPHS_DMA) next Channel Descriptor +// -------- UDPHS_DMAADDRESS : (UDPHS_DMA Offset: 0x4) UDPHS DMA Channel Address Register -------- +#define AT91C_UDPHS_BUFF_ADD (0x0 << 0) // (UDPHS_DMA) starting address of a DMA Channel transfer +// -------- UDPHS_DMACONTROL : (UDPHS_DMA Offset: 0x8) UDPHS DMA Channel Control Register -------- +#define AT91C_UDPHS_CHANN_ENB (0x1 << 0) // (UDPHS_DMA) Channel Enabled +#define AT91C_UDPHS_LDNXT_DSC (0x1 << 1) // (UDPHS_DMA) Load Next Channel Transfer Descriptor Enable +#define AT91C_UDPHS_END_TR_EN (0x1 << 2) // (UDPHS_DMA) Buffer Close Input Enable +#define AT91C_UDPHS_END_B_EN (0x1 << 3) // (UDPHS_DMA) End of DMA Buffer Packet Validation +#define AT91C_UDPHS_END_TR_IT (0x1 << 4) // (UDPHS_DMA) End Of Transfer Interrupt Enable +#define AT91C_UDPHS_END_BUFFIT (0x1 << 5) // (UDPHS_DMA) End Of Channel Buffer Interrupt Enable +#define AT91C_UDPHS_DESC_LD_IT (0x1 << 6) // (UDPHS_DMA) Descriptor Loaded Interrupt Enable +#define AT91C_UDPHS_BURST_LCK (0x1 << 7) // (UDPHS_DMA) Burst Lock Enable +#define AT91C_UDPHS_BUFF_LENGTH (0xFFFF << 16) // (UDPHS_DMA) Buffer Byte Length (write only) +// -------- UDPHS_DMASTATUS : (UDPHS_DMA Offset: 0xc) UDPHS DMA Channelx Status Register -------- +#define AT91C_UDPHS_CHANN_ACT (0x1 << 1) // (UDPHS_DMA) +#define AT91C_UDPHS_END_TR_ST (0x1 << 4) // (UDPHS_DMA) +#define AT91C_UDPHS_END_BF_ST (0x1 << 5) // (UDPHS_DMA) +#define AT91C_UDPHS_DESC_LDST (0x1 << 6) // (UDPHS_DMA) +#define AT91C_UDPHS_BUFF_COUNT (0xFFFF << 16) // (UDPHS_DMA) + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR UDPHS High Speed Device Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_UDPHS { + AT91_REG UDPHS_CTRL; // UDPHS Control Register + AT91_REG UDPHS_FNUM; // UDPHS Frame Number Register + AT91_REG Reserved0[2]; // + AT91_REG UDPHS_IEN; // UDPHS Interrupt Enable Register + AT91_REG UDPHS_INTSTA; // UDPHS Interrupt Status Register + AT91_REG UDPHS_CLRINT; // UDPHS Clear Interrupt Register + AT91_REG UDPHS_EPTRST; // UDPHS Endpoints Reset Register + AT91_REG Reserved1[44]; // + AT91_REG UDPHS_TSTSOFCNT; // UDPHS Test SOF Counter Register + AT91_REG UDPHS_TSTCNTA; // UDPHS Test A Counter Register + AT91_REG UDPHS_TSTCNTB; // UDPHS Test B Counter Register + AT91_REG UDPHS_TSTMODREG; // UDPHS Test Mode Register + AT91_REG UDPHS_TST; // UDPHS Test Register + AT91_REG Reserved2[2]; // + AT91_REG UDPHS_RIPPADDRSIZE; // UDPHS PADDRSIZE Register + AT91_REG UDPHS_RIPNAME1; // UDPHS Name1 Register + AT91_REG UDPHS_RIPNAME2; // UDPHS Name2 Register + AT91_REG UDPHS_IPFEATURES; // UDPHS Features Register + AT91_REG UDPHS_IPVERSION; // UDPHS Version Register + AT91S_UDPHS_EPT UDPHS_EPT[7]; // UDPHS Endpoint struct + AT91_REG Reserved3[72]; // + AT91S_UDPHS_DMA UDPHS_DMA[6]; // UDPHS DMA channel struct (not use [0]) +} AT91S_UDPHS, *AT91PS_UDPHS; +#else +#define UDPHS_CTRL (AT91_CAST(AT91_REG *) 0x00000000) // (UDPHS_CTRL) UDPHS Control Register +#define UDPHS_FNUM (AT91_CAST(AT91_REG *) 0x00000004) // (UDPHS_FNUM) UDPHS Frame Number Register +#define UDPHS_IEN (AT91_CAST(AT91_REG *) 0x00000010) // (UDPHS_IEN) UDPHS Interrupt Enable Register +#define UDPHS_INTSTA (AT91_CAST(AT91_REG *) 0x00000014) // (UDPHS_INTSTA) UDPHS Interrupt Status Register +#define UDPHS_CLRINT (AT91_CAST(AT91_REG *) 0x00000018) // (UDPHS_CLRINT) UDPHS Clear Interrupt Register +#define UDPHS_EPTRST (AT91_CAST(AT91_REG *) 0x0000001C) // (UDPHS_EPTRST) UDPHS Endpoints Reset Register +#define UDPHS_TSTSOFCNT (AT91_CAST(AT91_REG *) 0x000000D0) // (UDPHS_TSTSOFCNT) UDPHS Test SOF Counter Register +#define UDPHS_TSTCNTA (AT91_CAST(AT91_REG *) 0x000000D4) // (UDPHS_TSTCNTA) UDPHS Test A Counter Register +#define UDPHS_TSTCNTB (AT91_CAST(AT91_REG *) 0x000000D8) // (UDPHS_TSTCNTB) UDPHS Test B Counter Register +#define UDPHS_TSTMODREG (AT91_CAST(AT91_REG *) 0x000000DC) // (UDPHS_TSTMODREG) UDPHS Test Mode Register +#define UDPHS_TST (AT91_CAST(AT91_REG *) 0x000000E0) // (UDPHS_TST) UDPHS Test Register +#define UDPHS_RIPPADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (UDPHS_RIPPADDRSIZE) UDPHS PADDRSIZE Register +#define UDPHS_RIPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (UDPHS_RIPNAME1) UDPHS Name1 Register +#define UDPHS_RIPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (UDPHS_RIPNAME2) UDPHS Name2 Register +#define UDPHS_IPFEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (UDPHS_IPFEATURES) UDPHS Features Register +#define UDPHS_IPVERSION (AT91_CAST(AT91_REG *) 0x000000FC) // (UDPHS_IPVERSION) UDPHS Version Register + +#endif +// -------- UDPHS_CTRL : (UDPHS Offset: 0x0) UDPHS Control Register -------- +#define AT91C_UDPHS_DEV_ADDR (0x7F << 0) // (UDPHS) UDPHS Address +#define AT91C_UDPHS_FADDR_EN (0x1 << 7) // (UDPHS) Function Address Enable +#define AT91C_UDPHS_EN_UDPHS (0x1 << 8) // (UDPHS) UDPHS Enable +#define AT91C_UDPHS_DETACH (0x1 << 9) // (UDPHS) Detach Command +#define AT91C_UDPHS_REWAKEUP (0x1 << 10) // (UDPHS) Send Remote Wake Up +#define AT91C_UDPHS_PULLD_DIS (0x1 << 11) // (UDPHS) PullDown Disable +// -------- UDPHS_FNUM : (UDPHS Offset: 0x4) UDPHS Frame Number Register -------- +#define AT91C_UDPHS_MICRO_FRAME_NUM (0x7 << 0) // (UDPHS) Micro Frame Number +#define AT91C_UDPHS_FRAME_NUMBER (0x7FF << 3) // (UDPHS) Frame Number as defined in the Packet Field Formats +#define AT91C_UDPHS_FNUM_ERR (0x1 << 31) // (UDPHS) Frame Number CRC Error +// -------- UDPHS_IEN : (UDPHS Offset: 0x10) UDPHS Interrupt Enable Register -------- +#define AT91C_UDPHS_DET_SUSPD (0x1 << 1) // (UDPHS) Suspend Interrupt Enable/Clear/Status +#define AT91C_UDPHS_MICRO_SOF (0x1 << 2) // (UDPHS) Micro-SOF Interrupt Enable/Clear/Status +#define AT91C_UDPHS_IEN_SOF (0x1 << 3) // (UDPHS) SOF Interrupt Enable/Clear/Status +#define AT91C_UDPHS_ENDRESET (0x1 << 4) // (UDPHS) End Of Reset Interrupt Enable/Clear/Status +#define AT91C_UDPHS_WAKE_UP (0x1 << 5) // (UDPHS) Wake Up CPU Interrupt Enable/Clear/Status +#define AT91C_UDPHS_ENDOFRSM (0x1 << 6) // (UDPHS) End Of Resume Interrupt Enable/Clear/Status +#define AT91C_UDPHS_UPSTR_RES (0x1 << 7) // (UDPHS) Upstream Resume Interrupt Enable/Clear/Status +#define AT91C_UDPHS_EPT_INT_0 (0x1 << 8) // (UDPHS) Endpoint 0 Interrupt Enable/Status +#define AT91C_UDPHS_EPT_INT_1 (0x1 << 9) // (UDPHS) Endpoint 1 Interrupt Enable/Status +#define AT91C_UDPHS_EPT_INT_2 (0x1 << 10) // (UDPHS) Endpoint 2 Interrupt Enable/Status +#define AT91C_UDPHS_EPT_INT_3 (0x1 << 11) // (UDPHS) Endpoint 3 Interrupt Enable/Status +#define AT91C_UDPHS_EPT_INT_4 (0x1 << 12) // (UDPHS) Endpoint 4 Interrupt Enable/Status +#define AT91C_UDPHS_EPT_INT_5 (0x1 << 13) // (UDPHS) Endpoint 5 Interrupt Enable/Status +#define AT91C_UDPHS_EPT_INT_6 (0x1 << 14) // (UDPHS) Endpoint 6 Interrupt Enable/Status +#define AT91C_UDPHS_DMA_INT_1 (0x1 << 25) // (UDPHS) DMA Channel 1 Interrupt Enable/Status +#define AT91C_UDPHS_DMA_INT_2 (0x1 << 26) // (UDPHS) DMA Channel 2 Interrupt Enable/Status +#define AT91C_UDPHS_DMA_INT_3 (0x1 << 27) // (UDPHS) DMA Channel 3 Interrupt Enable/Status +#define AT91C_UDPHS_DMA_INT_4 (0x1 << 28) // (UDPHS) DMA Channel 4 Interrupt Enable/Status +#define AT91C_UDPHS_DMA_INT_5 (0x1 << 29) // (UDPHS) DMA Channel 5 Interrupt Enable/Status +#define AT91C_UDPHS_DMA_INT_6 (0x1 << 30) // (UDPHS) DMA Channel 6 Interrupt Enable/Status +// -------- UDPHS_INTSTA : (UDPHS Offset: 0x14) UDPHS Interrupt Status Register -------- +#define AT91C_UDPHS_SPEED (0x1 << 0) // (UDPHS) Speed Status +// -------- UDPHS_CLRINT : (UDPHS Offset: 0x18) UDPHS Clear Interrupt Register -------- +// -------- UDPHS_EPTRST : (UDPHS Offset: 0x1c) UDPHS Endpoints Reset Register -------- +#define AT91C_UDPHS_RST_EPT_0 (0x1 << 0) // (UDPHS) Endpoint Reset 0 +#define AT91C_UDPHS_RST_EPT_1 (0x1 << 1) // (UDPHS) Endpoint Reset 1 +#define AT91C_UDPHS_RST_EPT_2 (0x1 << 2) // (UDPHS) Endpoint Reset 2 +#define AT91C_UDPHS_RST_EPT_3 (0x1 << 3) // (UDPHS) Endpoint Reset 3 +#define AT91C_UDPHS_RST_EPT_4 (0x1 << 4) // (UDPHS) Endpoint Reset 4 +#define AT91C_UDPHS_RST_EPT_5 (0x1 << 5) // (UDPHS) Endpoint Reset 5 +#define AT91C_UDPHS_RST_EPT_6 (0x1 << 6) // (UDPHS) Endpoint Reset 6 +// -------- UDPHS_TSTSOFCNT : (UDPHS Offset: 0xd0) UDPHS Test SOF Counter Register -------- +#define AT91C_UDPHS_SOFCNTMAX (0x3 << 0) // (UDPHS) SOF Counter Max Value +#define AT91C_UDPHS_SOFCTLOAD (0x1 << 7) // (UDPHS) SOF Counter Load +// -------- UDPHS_TSTCNTA : (UDPHS Offset: 0xd4) UDPHS Test A Counter Register -------- +#define AT91C_UDPHS_CNTAMAX (0x7FFF << 0) // (UDPHS) A Counter Max Value +#define AT91C_UDPHS_CNTALOAD (0x1 << 15) // (UDPHS) A Counter Load +// -------- UDPHS_TSTCNTB : (UDPHS Offset: 0xd8) UDPHS Test B Counter Register -------- +#define AT91C_UDPHS_CNTBMAX (0x7FFF << 0) // (UDPHS) B Counter Max Value +#define AT91C_UDPHS_CNTBLOAD (0x1 << 15) // (UDPHS) B Counter Load +// -------- UDPHS_TSTMODREG : (UDPHS Offset: 0xdc) UDPHS Test Mode Register -------- +#define AT91C_UDPHS_TSTMODE (0x1F << 1) // (UDPHS) UDPHS Core TestModeReg +// -------- UDPHS_TST : (UDPHS Offset: 0xe0) UDPHS Test Register -------- +#define AT91C_UDPHS_SPEED_CFG (0x3 << 0) // (UDPHS) Speed Configuration +#define AT91C_UDPHS_SPEED_CFG_NM (0x0) // (UDPHS) Normal Mode +#define AT91C_UDPHS_SPEED_CFG_RS (0x1) // (UDPHS) Reserved +#define AT91C_UDPHS_SPEED_CFG_HS (0x2) // (UDPHS) Force High Speed +#define AT91C_UDPHS_SPEED_CFG_FS (0x3) // (UDPHS) Force Full-Speed +#define AT91C_UDPHS_TST_J (0x1 << 2) // (UDPHS) TestJMode +#define AT91C_UDPHS_TST_K (0x1 << 3) // (UDPHS) TestKMode +#define AT91C_UDPHS_TST_PKT (0x1 << 4) // (UDPHS) TestPacketMode +#define AT91C_UDPHS_OPMODE2 (0x1 << 5) // (UDPHS) OpMode2 +// -------- UDPHS_RIPPADDRSIZE : (UDPHS Offset: 0xec) UDPHS PADDRSIZE Register -------- +#define AT91C_UDPHS_IPPADDRSIZE (0x0 << 0) // (UDPHS) 2^UDPHSDEV_PADDR_SIZE +// -------- UDPHS_RIPNAME1 : (UDPHS Offset: 0xf0) UDPHS Name Register -------- +#define AT91C_UDPHS_IPNAME1 (0x0 << 0) // (UDPHS) ASCII string HUSB +// -------- UDPHS_RIPNAME2 : (UDPHS Offset: 0xf4) UDPHS Name Register -------- +#define AT91C_UDPHS_IPNAME2 (0x0 << 0) // (UDPHS) ASCII string 2DEV +// -------- UDPHS_IPFEATURES : (UDPHS Offset: 0xf8) UDPHS Features Register -------- +#define AT91C_UDPHS_EPT_NBR_MAX (0xF << 0) // (UDPHS) Max Number of Endpoints +#define AT91C_UDPHS_DMA_CHANNEL_NBR (0x7 << 4) // (UDPHS) Number of DMA Channels +#define AT91C_UDPHS_DMA_B_SIZ (0x1 << 7) // (UDPHS) DMA Buffer Size +#define AT91C_UDPHS_DMA_FIFO_WORD_DEPTH (0xF << 8) // (UDPHS) DMA FIFO Depth in words +#define AT91C_UDPHS_FIFO_MAX_SIZE (0x7 << 12) // (UDPHS) DPRAM size +#define AT91C_UDPHS_BW_DPRAM (0x1 << 15) // (UDPHS) DPRAM byte write capability +#define AT91C_UDPHS_DATAB16_8 (0x1 << 16) // (UDPHS) UTMI DataBus16_8 +#define AT91C_UDPHS_ISO_EPT_1 (0x1 << 17) // (UDPHS) Endpoint 1 High Bandwidth Isochronous Capability +#define AT91C_UDPHS_ISO_EPT_2 (0x1 << 18) // (UDPHS) Endpoint 2 High Bandwidth Isochronous Capability +#define AT91C_UDPHS_ISO_EPT_5 (0x1 << 21) // (UDPHS) Endpoint 5 High Bandwidth Isochronous Capability +#define AT91C_UDPHS_ISO_EPT_6 (0x1 << 22) // (UDPHS) Endpoint 6 High Bandwidth Isochronous Capability +// -------- UDPHS_IPVERSION : (UDPHS Offset: 0xfc) UDPHS Version Register -------- +#define AT91C_UDPHS_VERSION_NUM (0xFFFF << 0) // (UDPHS) Give the IP version +#define AT91C_UDPHS_METAL_FIX_NUM (0x7 << 16) // (UDPHS) Give the number of metal fixes + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR HDMA Channel structure +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_HDMA_CH { + AT91_REG HDMA_SADDR; // HDMA Channel Source Address Register + AT91_REG HDMA_DADDR; // HDMA Channel Destination Address Register + AT91_REG HDMA_DSCR; // HDMA Channel Descriptor Address Register + AT91_REG HDMA_CTRLA; // HDMA Channel Control A Register + AT91_REG HDMA_CTRLB; // HDMA Channel Control B Register + AT91_REG HDMA_CFG; // HDMA Channel Configuration Register + AT91_REG HDMA_SPIP; // HDMA Channel Source Picture in Picture Configuration Register + AT91_REG HDMA_DPIP; // HDMA Channel Destination Picture in Picture Configuration Register + AT91_REG HDMA_BDSCR; // HDMA Reserved + AT91_REG HDMA_CADDR; // HDMA Reserved +} AT91S_HDMA_CH, *AT91PS_HDMA_CH; +#else +#define HDMA_SADDR (AT91_CAST(AT91_REG *) 0x00000000) // (HDMA_SADDR) HDMA Channel Source Address Register +#define HDMA_DADDR (AT91_CAST(AT91_REG *) 0x00000004) // (HDMA_DADDR) HDMA Channel Destination Address Register +#define HDMA_DSCR (AT91_CAST(AT91_REG *) 0x00000008) // (HDMA_DSCR) HDMA Channel Descriptor Address Register +#define HDMA_CTRLA (AT91_CAST(AT91_REG *) 0x0000000C) // (HDMA_CTRLA) HDMA Channel Control A Register +#define HDMA_CTRLB (AT91_CAST(AT91_REG *) 0x00000010) // (HDMA_CTRLB) HDMA Channel Control B Register +#define HDMA_CFG (AT91_CAST(AT91_REG *) 0x00000014) // (HDMA_CFG) HDMA Channel Configuration Register +#define HDMA_SPIP (AT91_CAST(AT91_REG *) 0x00000018) // (HDMA_SPIP) HDMA Channel Source Picture in Picture Configuration Register +#define HDMA_DPIP (AT91_CAST(AT91_REG *) 0x0000001C) // (HDMA_DPIP) HDMA Channel Destination Picture in Picture Configuration Register +#define HDMA_BDSCR (AT91_CAST(AT91_REG *) 0x00000020) // (HDMA_BDSCR) HDMA Reserved +#define HDMA_CADDR (AT91_CAST(AT91_REG *) 0x00000024) // (HDMA_CADDR) HDMA Reserved + +#endif +// -------- HDMA_SADDR : (HDMA_CH Offset: 0x0) -------- +#define AT91C_SADDR (0x0 << 0) // (HDMA_CH) +// -------- HDMA_DADDR : (HDMA_CH Offset: 0x4) -------- +#define AT91C_DADDR (0x0 << 0) // (HDMA_CH) +// -------- HDMA_DSCR : (HDMA_CH Offset: 0x8) -------- +#define AT91C_HDMA_DSCR_IF (0x3 << 0) // (HDMA_CH) Select AHB-Lite Interface for current channel +#define AT91C_HDMA_DSCR_IF_0 (0x0) // (HDMA_CH) The Buffer Transfer descriptor is fetched via AHB-Lite Interface 0. +#define AT91C_HDMA_DSCR_IF_1 (0x1) // (HDMA_CH) The Buffer Transfer descriptor is fetched via AHB-Lite Interface 1. +#define AT91C_HDMA_DSCR_IF_2 (0x2) // (HDMA_CH) The Buffer Transfer descriptor is fetched via AHB-Lite Interface 2. +#define AT91C_HDMA_DSCR_IF_3 (0x3) // (HDMA_CH) The Buffer Transfer descriptor is fetched via AHB-Lite Interface 3. +#define AT91C_HDMA_DSCR (0x3FFFFFFF << 2) // (HDMA_CH) Buffer Transfer descriptor address. This address is word aligned. +// -------- HDMA_CTRLA : (HDMA_CH Offset: 0xc) -------- +#define AT91C_HDMA_BTSIZE (0xFFFF << 0) // (HDMA_CH) Buffer Transfer Size. +#define AT91C_HDMA_SCSIZE (0x7 << 16) // (HDMA_CH) Source Chunk Transfer Size. +#define AT91C_HDMA_SCSIZE_1 (0x0 << 16) // (HDMA_CH) 1. +#define AT91C_HDMA_SCSIZE_4 (0x1 << 16) // (HDMA_CH) 4. +#define AT91C_HDMA_SCSIZE_8 (0x2 << 16) // (HDMA_CH) 8. +#define AT91C_HDMA_SCSIZE_16 (0x3 << 16) // (HDMA_CH) 16. +#define AT91C_HDMA_SCSIZE_32 (0x4 << 16) // (HDMA_CH) 32. +#define AT91C_HDMA_SCSIZE_64 (0x5 << 16) // (HDMA_CH) 64. +#define AT91C_HDMA_SCSIZE_128 (0x6 << 16) // (HDMA_CH) 128. +#define AT91C_HDMA_SCSIZE_256 (0x7 << 16) // (HDMA_CH) 256. +#define AT91C_HDMA_DCSIZE (0x7 << 20) // (HDMA_CH) Destination Chunk Transfer Size +#define AT91C_HDMA_DCSIZE_1 (0x0 << 20) // (HDMA_CH) 1. +#define AT91C_HDMA_DCSIZE_4 (0x1 << 20) // (HDMA_CH) 4. +#define AT91C_HDMA_DCSIZE_8 (0x2 << 20) // (HDMA_CH) 8. +#define AT91C_HDMA_DCSIZE_16 (0x3 << 20) // (HDMA_CH) 16. +#define AT91C_HDMA_DCSIZE_32 (0x4 << 20) // (HDMA_CH) 32. +#define AT91C_HDMA_DCSIZE_64 (0x5 << 20) // (HDMA_CH) 64. +#define AT91C_HDMA_DCSIZE_128 (0x6 << 20) // (HDMA_CH) 128. +#define AT91C_HDMA_DCSIZE_256 (0x7 << 20) // (HDMA_CH) 256. +#define AT91C_HDMA_SRC_WIDTH (0x3 << 24) // (HDMA_CH) Source Single Transfer Size +#define AT91C_HDMA_SRC_WIDTH_BYTE (0x0 << 24) // (HDMA_CH) BYTE. +#define AT91C_HDMA_SRC_WIDTH_HALFWORD (0x1 << 24) // (HDMA_CH) HALF-WORD. +#define AT91C_HDMA_SRC_WIDTH_WORD (0x2 << 24) // (HDMA_CH) WORD. +#define AT91C_HDMA_DST_WIDTH (0x3 << 28) // (HDMA_CH) Destination Single Transfer Size +#define AT91C_HDMA_DST_WIDTH_BYTE (0x0 << 28) // (HDMA_CH) BYTE. +#define AT91C_HDMA_DST_WIDTH_HALFWORD (0x1 << 28) // (HDMA_CH) HALF-WORD. +#define AT91C_HDMA_DST_WIDTH_WORD (0x2 << 28) // (HDMA_CH) WORD. +#define AT91C_HDMA_DONE (0x1 << 31) // (HDMA_CH) +// -------- HDMA_CTRLB : (HDMA_CH Offset: 0x10) -------- +#define AT91C_HDMA_SIF (0x3 << 0) // (HDMA_CH) Source Interface Selection Field. +#define AT91C_HDMA_SIF_0 (0x0) // (HDMA_CH) The Source Transfer is done via AHB-Lite Interface 0. +#define AT91C_HDMA_SIF_1 (0x1) // (HDMA_CH) The Source Transfer is done via AHB-Lite Interface 1. +#define AT91C_HDMA_SIF_2 (0x2) // (HDMA_CH) The Source Transfer is done via AHB-Lite Interface 2. +#define AT91C_HDMA_SIF_3 (0x3) // (HDMA_CH) The Source Transfer is done via AHB-Lite Interface 3. +#define AT91C_HDMA_DIF (0x3 << 4) // (HDMA_CH) Destination Interface Selection Field. +#define AT91C_HDMA_DIF_0 (0x0 << 4) // (HDMA_CH) The Destination Transfer is done via AHB-Lite Interface 0. +#define AT91C_HDMA_DIF_1 (0x1 << 4) // (HDMA_CH) The Destination Transfer is done via AHB-Lite Interface 1. +#define AT91C_HDMA_DIF_2 (0x2 << 4) // (HDMA_CH) The Destination Transfer is done via AHB-Lite Interface 2. +#define AT91C_HDMA_DIF_3 (0x3 << 4) // (HDMA_CH) The Destination Transfer is done via AHB-Lite Interface 3. +#define AT91C_HDMA_SRC_PIP (0x1 << 8) // (HDMA_CH) Source Picture-in-Picture Mode +#define AT91C_HDMA_SRC_PIP_DISABLE (0x0 << 8) // (HDMA_CH) Source Picture-in-Picture mode is disabled. +#define AT91C_HDMA_SRC_PIP_ENABLE (0x1 << 8) // (HDMA_CH) Source Picture-in-Picture mode is enabled. +#define AT91C_HDMA_DST_PIP (0x1 << 12) // (HDMA_CH) Destination Picture-in-Picture Mode +#define AT91C_HDMA_DST_PIP_DISABLE (0x0 << 12) // (HDMA_CH) Destination Picture-in-Picture mode is disabled. +#define AT91C_HDMA_DST_PIP_ENABLE (0x1 << 12) // (HDMA_CH) Destination Picture-in-Picture mode is enabled. +#define AT91C_HDMA_SRC_DSCR (0x1 << 16) // (HDMA_CH) Source Buffer Descriptor Fetch operation +#define AT91C_HDMA_SRC_DSCR_FETCH_FROM_MEM (0x0 << 16) // (HDMA_CH) Source address is updated when the descriptor is fetched from the memory. +#define AT91C_HDMA_SRC_DSCR_FETCH_DISABLE (0x1 << 16) // (HDMA_CH) Buffer Descriptor Fetch operation is disabled for the Source. +#define AT91C_HDMA_DST_DSCR (0x1 << 20) // (HDMA_CH) Destination Buffer Descriptor operation +#define AT91C_HDMA_DST_DSCR_FETCH_FROM_MEM (0x0 << 20) // (HDMA_CH) Destination address is updated when the descriptor is fetched from the memory. +#define AT91C_HDMA_DST_DSCR_FETCH_DISABLE (0x1 << 20) // (HDMA_CH) Buffer Descriptor Fetch operation is disabled for the destination. +#define AT91C_HDMA_FC (0x7 << 21) // (HDMA_CH) This field defines which devices controls the size of the buffer transfer, also referred as to the Flow Controller. +#define AT91C_HDMA_FC_MEM2MEM (0x0 << 21) // (HDMA_CH) Memory-to-Memory (DMA Controller). +#define AT91C_HDMA_FC_MEM2PER (0x1 << 21) // (HDMA_CH) Memory-to-Peripheral (DMA Controller). +#define AT91C_HDMA_FC_PER2MEM (0x2 << 21) // (HDMA_CH) Peripheral-to-Memory (DMA Controller). +#define AT91C_HDMA_FC_PER2PER (0x3 << 21) // (HDMA_CH) Peripheral-to-Peripheral (DMA Controller). +#define AT91C_HDMA_FC_PER2MEM_PER (0x4 << 21) // (HDMA_CH) Peripheral-to-Memory (Peripheral). +#define AT91C_HDMA_FC_MEM2PER_PER (0x5 << 21) // (HDMA_CH) Memory-to-Peripheral (Peripheral). +#define AT91C_HDMA_FC_PER2PER_PER (0x6 << 21) // (HDMA_CH) Peripheral-to-Peripheral (Source Peripheral). +#define AT91C_HDMA_SRC_ADDRESS_MODE (0x3 << 24) // (HDMA_CH) Type of addressing mode +#define AT91C_HDMA_SRC_ADDRESS_MODE_INCR (0x0 << 24) // (HDMA_CH) Incrementing Mode. +#define AT91C_HDMA_SRC_ADDRESS_MODE_DECR (0x1 << 24) // (HDMA_CH) Decrementing Mode. +#define AT91C_HDMA_SRC_ADDRESS_MODE_FIXED (0x2 << 24) // (HDMA_CH) Fixed Mode. +#define AT91C_HDMA_DST_ADDRESS_MODE (0x3 << 28) // (HDMA_CH) Type of addressing mode +#define AT91C_HDMA_DST_ADDRESS_MODE_INCR (0x0 << 28) // (HDMA_CH) Incrementing Mode. +#define AT91C_HDMA_DST_ADDRESS_MODE_DECR (0x1 << 28) // (HDMA_CH) Decrementing Mode. +#define AT91C_HDMA_DST_ADDRESS_MODE_FIXED (0x2 << 28) // (HDMA_CH) Fixed Mode. +#define AT91C_HDMA_AUTO (0x1 << 31) // (HDMA_CH) Automatic multiple buffer transfer enable +#define AT91C_HDMA_AUTO_DISABLE (0x0 << 31) // (HDMA_CH) Automatic multiple buffer transfer is disabled. +#define AT91C_HDMA_AUTO_ENABLE (0x1 << 31) // (HDMA_CH) Automatic multiple buffer transfer is enabled. This enables replay mode or contiguous mode when several buffers are transferred. +// -------- HDMA_CFG : (HDMA_CH Offset: 0x14) -------- +#define AT91C_HDMA_SRC_PER (0xF << 0) // (HDMA_CH) Channel Source Request is associated with peripheral identifier coded SRC_PER handshaking interface. +#define AT91C_HDMA_SRC_PER_0 (0x0) // (HDMA_CH) HW Handshaking Interface number 0. +#define AT91C_HDMA_SRC_PER_1 (0x1) // (HDMA_CH) HW Handshaking Interface number 1. +#define AT91C_HDMA_SRC_PER_2 (0x2) // (HDMA_CH) HW Handshaking Interface number 2. +#define AT91C_HDMA_SRC_PER_3 (0x3) // (HDMA_CH) HW Handshaking Interface number 3. +#define AT91C_HDMA_SRC_PER_4 (0x4) // (HDMA_CH) HW Handshaking Interface number 4. +#define AT91C_HDMA_SRC_PER_5 (0x5) // (HDMA_CH) HW Handshaking Interface number 5. +#define AT91C_HDMA_SRC_PER_6 (0x6) // (HDMA_CH) HW Handshaking Interface number 6. +#define AT91C_HDMA_SRC_PER_7 (0x7) // (HDMA_CH) HW Handshaking Interface number 7. +#define AT91C_HDMA_SRC_PER_8 (0x8) // (HDMA_CH) HW Handshaking Interface number 8. +#define AT91C_HDMA_SRC_PER_9 (0x9) // (HDMA_CH) HW Handshaking Interface number 9. +#define AT91C_HDMA_SRC_PER_10 (0xA) // (HDMA_CH) HW Handshaking Interface number 10. +#define AT91C_HDMA_SRC_PER_11 (0xB) // (HDMA_CH) HW Handshaking Interface number 11. +#define AT91C_HDMA_SRC_PER_12 (0xC) // (HDMA_CH) HW Handshaking Interface number 12. +#define AT91C_HDMA_SRC_PER_13 (0xD) // (HDMA_CH) HW Handshaking Interface number 13. +#define AT91C_HDMA_SRC_PER_14 (0xE) // (HDMA_CH) HW Handshaking Interface number 14. +#define AT91C_HDMA_SRC_PER_15 (0xF) // (HDMA_CH) HW Handshaking Interface number 15. +#define AT91C_HDMA_DST_PER (0xF << 4) // (HDMA_CH) Channel Destination Request is associated with peripheral identifier coded DST_PER handshaking interface. +#define AT91C_HDMA_DST_PER_0 (0x0 << 4) // (HDMA_CH) HW Handshaking Interface number 0. +#define AT91C_HDMA_DST_PER_1 (0x1 << 4) // (HDMA_CH) HW Handshaking Interface number 1. +#define AT91C_HDMA_DST_PER_2 (0x2 << 4) // (HDMA_CH) HW Handshaking Interface number 2. +#define AT91C_HDMA_DST_PER_3 (0x3 << 4) // (HDMA_CH) HW Handshaking Interface number 3. +#define AT91C_HDMA_DST_PER_4 (0x4 << 4) // (HDMA_CH) HW Handshaking Interface number 4. +#define AT91C_HDMA_DST_PER_5 (0x5 << 4) // (HDMA_CH) HW Handshaking Interface number 5. +#define AT91C_HDMA_DST_PER_6 (0x6 << 4) // (HDMA_CH) HW Handshaking Interface number 6. +#define AT91C_HDMA_DST_PER_7 (0x7 << 4) // (HDMA_CH) HW Handshaking Interface number 7. +#define AT91C_HDMA_DST_PER_8 (0x8 << 4) // (HDMA_CH) HW Handshaking Interface number 8. +#define AT91C_HDMA_DST_PER_9 (0x9 << 4) // (HDMA_CH) HW Handshaking Interface number 9. +#define AT91C_HDMA_DST_PER_10 (0xA << 4) // (HDMA_CH) HW Handshaking Interface number 10. +#define AT91C_HDMA_DST_PER_11 (0xB << 4) // (HDMA_CH) HW Handshaking Interface number 11. +#define AT91C_HDMA_DST_PER_12 (0xC << 4) // (HDMA_CH) HW Handshaking Interface number 12. +#define AT91C_HDMA_DST_PER_13 (0xD << 4) // (HDMA_CH) HW Handshaking Interface number 13. +#define AT91C_HDMA_DST_PER_14 (0xE << 4) // (HDMA_CH) HW Handshaking Interface number 14. +#define AT91C_HDMA_DST_PER_15 (0xF << 4) // (HDMA_CH) HW Handshaking Interface number 15. +#define AT91C_HDMA_SRC_REP (0x1 << 8) // (HDMA_CH) Source Replay Mode +#define AT91C_HDMA_SRC_REP_CONTIGUOUS_ADDR (0x0 << 8) // (HDMA_CH) When automatic mode is activated, source address is contiguous between two buffers. +#define AT91C_HDMA_SRC_REP_RELOAD_ADDR (0x1 << 8) // (HDMA_CH) When automatic mode is activated, the source address and the control register are reloaded from previous transfer.. +#define AT91C_HDMA_SRC_H2SEL (0x1 << 9) // (HDMA_CH) Source Handshaking Mode +#define AT91C_HDMA_SRC_H2SEL_SW (0x0 << 9) // (HDMA_CH) Software handshaking interface is used to trigger a transfer request. +#define AT91C_HDMA_SRC_H2SEL_HW (0x1 << 9) // (HDMA_CH) Hardware handshaking interface is used to trigger a transfer request. +#define AT91C_HDMA_DST_REP (0x1 << 12) // (HDMA_CH) Destination Replay Mode +#define AT91C_HDMA_DST_REP_CONTIGUOUS_ADDR (0x0 << 12) // (HDMA_CH) When automatic mode is activated, destination address is contiguous between two buffers. +#define AT91C_HDMA_DST_REP_RELOAD_ADDR (0x1 << 12) // (HDMA_CH) When automatic mode is activated, the destination address and the control register are reloaded from previous transfer.. +#define AT91C_HDMA_DST_H2SEL (0x1 << 13) // (HDMA_CH) Destination Handshaking Mode +#define AT91C_HDMA_DST_H2SEL_SW (0x0 << 13) // (HDMA_CH) Software handshaking interface is used to trigger a transfer request. +#define AT91C_HDMA_DST_H2SEL_HW (0x1 << 13) // (HDMA_CH) Hardware handshaking interface is used to trigger a transfer request. +#define AT91C_HDMA_SOD (0x1 << 16) // (HDMA_CH) STOP ON DONE +#define AT91C_HDMA_SOD_DISABLE (0x0 << 16) // (HDMA_CH) STOP ON DONE disabled, the descriptor fetch operation ignores DONE Field of CTRLA register. +#define AT91C_HDMA_SOD_ENABLE (0x1 << 16) // (HDMA_CH) STOP ON DONE activated, the DMAC module is automatically disabled if DONE FIELD is set to 1. +#define AT91C_HDMA_LOCK_IF (0x1 << 20) // (HDMA_CH) Interface Lock +#define AT91C_HDMA_LOCK_IF_DISABLE (0x0 << 20) // (HDMA_CH) Interface Lock capability is disabled. +#define AT91C_HDMA_LOCK_IF_ENABLE (0x1 << 20) // (HDMA_CH) Interface Lock capability is enabled. +#define AT91C_HDMA_LOCK_B (0x1 << 21) // (HDMA_CH) AHB Bus Lock +#define AT91C_HDMA_LOCK_B_DISABLE (0x0 << 21) // (HDMA_CH) AHB Bus Locking capability is disabled. +#define AT91C_HDMA_LOCK_B_ENABLE (0x1 << 21) // (HDMA_CH) AHB Bus Locking capability is enabled. +#define AT91C_HDMA_LOCK_IF_L (0x1 << 22) // (HDMA_CH) Master Interface Arbiter Lock +#define AT91C_HDMA_LOCK_IF_L_CHUNK (0x0 << 22) // (HDMA_CH) The Master Interface Arbiter is locked by the channel x for a chunk transfer. +#define AT91C_HDMA_LOCK_IF_L_BUFFER (0x1 << 22) // (HDMA_CH) The Master Interface Arbiter is locked by the channel x for a buffer transfer. +#define AT91C_HDMA_AHB_PROT (0x7 << 24) // (HDMA_CH) AHB Prot +#define AT91C_HDMA_FIFOCFG (0x3 << 28) // (HDMA_CH) FIFO Request Configuration +#define AT91C_HDMA_FIFOCFG_LARGESTBURST (0x0 << 28) // (HDMA_CH) The largest defined length AHB burst is performed on the destination AHB interface. +#define AT91C_HDMA_FIFOCFG_HALFFIFO (0x1 << 28) // (HDMA_CH) When half fifo size is available/filled a source/destination request is serviced. +#define AT91C_HDMA_FIFOCFG_ENOUGHSPACE (0x2 << 28) // (HDMA_CH) When there is enough space/data available to perfom a single AHB access then the request is serviced. +// -------- HDMA_SPIP : (HDMA_CH Offset: 0x18) -------- +#define AT91C_SPIP_HOLE (0xFFFF << 0) // (HDMA_CH) This field indicates the value to add to the address when the programmable boundary has been reached. +#define AT91C_SPIP_BOUNDARY (0x3FF << 16) // (HDMA_CH) This field indicates the number of source transfers to perform before the automatic address increment operation. +// -------- HDMA_DPIP : (HDMA_CH Offset: 0x1c) -------- +#define AT91C_DPIP_HOLE (0xFFFF << 0) // (HDMA_CH) This field indicates the value to add to the address when the programmable boundary has been reached. +#define AT91C_DPIP_BOUNDARY (0x3FF << 16) // (HDMA_CH) This field indicates the number of source transfers to perform before the automatic address increment operation. +// -------- HDMA_BDSCR : (HDMA_CH Offset: 0x20) -------- +// -------- HDMA_CADDR : (HDMA_CH Offset: 0x24) -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR HDMA controller +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_HDMA { + AT91_REG HDMA_GCFG; // HDMA Global Configuration Register + AT91_REG HDMA_EN; // HDMA Controller Enable Register + AT91_REG HDMA_SREQ; // HDMA Software Single Request Register + AT91_REG HDMA_CREQ; // HDMA Software Chunk Transfer Request Register + AT91_REG HDMA_LAST; // HDMA Software Last Transfer Flag Register + AT91_REG HDMA_SYNC; // HDMA Request Synchronization Register + AT91_REG HDMA_EBCIER; // HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Interrupt Enable register + AT91_REG HDMA_EBCIDR; // HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Interrupt Disable register + AT91_REG HDMA_EBCIMR; // HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Mask Register + AT91_REG HDMA_EBCISR; // HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Status Register + AT91_REG HDMA_CHER; // HDMA Channel Handler Enable Register + AT91_REG HDMA_CHDR; // HDMA Channel Handler Disable Register + AT91_REG HDMA_CHSR; // HDMA Channel Handler Status Register + AT91_REG HDMA_RSVD0; // HDMA Reserved + AT91_REG HDMA_RSVD1; // HDMA Reserved + AT91S_HDMA_CH HDMA_CH[4]; // HDMA Channel structure + AT91_REG Reserved0[68]; // + AT91_REG HDMA_ADDRSIZE; // HDMA ADDRSIZE REGISTER + AT91_REG HDMA_IPNAME1; // HDMA IPNAME1 REGISTER + AT91_REG HDMA_IPNAME2; // HDMA IPNAME2 REGISTER + AT91_REG HDMA_FEATURES; // HDMA FEATURES REGISTER + AT91_REG HDMA_VER; // HDMA VERSION REGISTER +} AT91S_HDMA, *AT91PS_HDMA; +#else +#define HDMA_GCFG (AT91_CAST(AT91_REG *) 0x00000000) // (HDMA_GCFG) HDMA Global Configuration Register +#define HDMA_EN (AT91_CAST(AT91_REG *) 0x00000004) // (HDMA_EN) HDMA Controller Enable Register +#define HDMA_SREQ (AT91_CAST(AT91_REG *) 0x00000008) // (HDMA_SREQ) HDMA Software Single Request Register +#define HDMA_CREQ (AT91_CAST(AT91_REG *) 0x0000000C) // (HDMA_CREQ) HDMA Software Chunk Transfer Request Register +#define HDMA_LAST (AT91_CAST(AT91_REG *) 0x00000010) // (HDMA_LAST) HDMA Software Last Transfer Flag Register +#define HDMA_SYNC (AT91_CAST(AT91_REG *) 0x00000014) // (HDMA_SYNC) HDMA Request Synchronization Register +#define HDMA_EBCIER (AT91_CAST(AT91_REG *) 0x00000018) // (HDMA_EBCIER) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Interrupt Enable register +#define HDMA_EBCIDR (AT91_CAST(AT91_REG *) 0x0000001C) // (HDMA_EBCIDR) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Interrupt Disable register +#define HDMA_EBCIMR (AT91_CAST(AT91_REG *) 0x00000020) // (HDMA_EBCIMR) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Mask Register +#define HDMA_EBCISR (AT91_CAST(AT91_REG *) 0x00000024) // (HDMA_EBCISR) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Status Register +#define HDMA_CHER (AT91_CAST(AT91_REG *) 0x00000028) // (HDMA_CHER) HDMA Channel Handler Enable Register +#define HDMA_CHDR (AT91_CAST(AT91_REG *) 0x0000002C) // (HDMA_CHDR) HDMA Channel Handler Disable Register +#define HDMA_CHSR (AT91_CAST(AT91_REG *) 0x00000030) // (HDMA_CHSR) HDMA Channel Handler Status Register +#define HDMA_RSVD0 (AT91_CAST(AT91_REG *) 0x00000034) // (HDMA_RSVD0) HDMA Reserved +#define HDMA_RSVD1 (AT91_CAST(AT91_REG *) 0x00000038) // (HDMA_RSVD1) HDMA Reserved +#define HDMA_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000001EC) // (HDMA_ADDRSIZE) HDMA ADDRSIZE REGISTER +#define HDMA_IPNAME1 (AT91_CAST(AT91_REG *) 0x000001F0) // (HDMA_IPNAME1) HDMA IPNAME1 REGISTER +#define HDMA_IPNAME2 (AT91_CAST(AT91_REG *) 0x000001F4) // (HDMA_IPNAME2) HDMA IPNAME2 REGISTER +#define HDMA_FEATURES (AT91_CAST(AT91_REG *) 0x000001F8) // (HDMA_FEATURES) HDMA FEATURES REGISTER +#define HDMA_VER (AT91_CAST(AT91_REG *) 0x000001FC) // (HDMA_VER) HDMA VERSION REGISTER + +#endif +// -------- HDMA_GCFG : (HDMA Offset: 0x0) -------- +#define AT91C_HDMA_IF0_BIGEND (0x1 << 0) // (HDMA) AHB-Lite Interface 0 endian mode. +#define AT91C_HDMA_IF0_BIGEND_IS_LITTLE_ENDIAN (0x0) // (HDMA) AHB-Lite Interface 0 is little endian. +#define AT91C_HDMA_IF0_BIGEND_IS_BIG_ENDIAN (0x1) // (HDMA) AHB-Lite Interface 0 is big endian. +#define AT91C_HDMA_IF1_BIGEND (0x1 << 1) // (HDMA) AHB-Lite Interface 1 endian mode. +#define AT91C_HDMA_IF1_BIGEND_IS_LITTLE_ENDIAN (0x0 << 1) // (HDMA) AHB-Lite Interface 1 is little endian. +#define AT91C_HDMA_IF1_BIGEND_IS_BIG_ENDIAN (0x1 << 1) // (HDMA) AHB-Lite Interface 1 is big endian. +#define AT91C_HDMA_IF2_BIGEND (0x1 << 2) // (HDMA) AHB-Lite Interface 2 endian mode. +#define AT91C_HDMA_IF2_BIGEND_IS_LITTLE_ENDIAN (0x0 << 2) // (HDMA) AHB-Lite Interface 2 is little endian. +#define AT91C_HDMA_IF2_BIGEND_IS_BIG_ENDIAN (0x1 << 2) // (HDMA) AHB-Lite Interface 2 is big endian. +#define AT91C_HDMA_IF3_BIGEND (0x1 << 3) // (HDMA) AHB-Lite Interface 3 endian mode. +#define AT91C_HDMA_IF3_BIGEND_IS_LITTLE_ENDIAN (0x0 << 3) // (HDMA) AHB-Lite Interface 3 is little endian. +#define AT91C_HDMA_IF3_BIGEND_IS_BIG_ENDIAN (0x1 << 3) // (HDMA) AHB-Lite Interface 3 is big endian. +#define AT91C_HDMA_ARB_CFG (0x1 << 4) // (HDMA) Arbiter mode. +#define AT91C_HDMA_ARB_CFG_FIXED (0x0 << 4) // (HDMA) Fixed priority arbiter. +#define AT91C_HDMA_ARB_CFG_ROUND_ROBIN (0x1 << 4) // (HDMA) Modified round robin arbiter. +// -------- HDMA_EN : (HDMA Offset: 0x4) -------- +#define AT91C_HDMA_ENABLE (0x1 << 0) // (HDMA) +#define AT91C_HDMA_ENABLE_DISABLE (0x0) // (HDMA) Disables HDMA. +#define AT91C_HDMA_ENABLE_ENABLE (0x1) // (HDMA) Enables HDMA. +// -------- HDMA_SREQ : (HDMA Offset: 0x8) -------- +#define AT91C_HDMA_SSREQ0 (0x1 << 0) // (HDMA) Request a source single transfer on channel 0 +#define AT91C_HDMA_SSREQ0_0 (0x0) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ0_1 (0x1) // (HDMA) Request a source single transfer on channel 0. +#define AT91C_HDMA_DSREQ0 (0x1 << 1) // (HDMA) Request a destination single transfer on channel 0 +#define AT91C_HDMA_DSREQ0_0 (0x0 << 1) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ0_1 (0x1 << 1) // (HDMA) Request a destination single transfer on channel 0. +#define AT91C_HDMA_SSREQ1 (0x1 << 2) // (HDMA) Request a source single transfer on channel 1 +#define AT91C_HDMA_SSREQ1_0 (0x0 << 2) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ1_1 (0x1 << 2) // (HDMA) Request a source single transfer on channel 1. +#define AT91C_HDMA_DSREQ1 (0x1 << 3) // (HDMA) Request a destination single transfer on channel 1 +#define AT91C_HDMA_DSREQ1_0 (0x0 << 3) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ1_1 (0x1 << 3) // (HDMA) Request a destination single transfer on channel 1. +#define AT91C_HDMA_SSREQ2 (0x1 << 4) // (HDMA) Request a source single transfer on channel 2 +#define AT91C_HDMA_SSREQ2_0 (0x0 << 4) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ2_1 (0x1 << 4) // (HDMA) Request a source single transfer on channel 2. +#define AT91C_HDMA_DSREQ2 (0x1 << 5) // (HDMA) Request a destination single transfer on channel 2 +#define AT91C_HDMA_DSREQ2_0 (0x0 << 5) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ2_1 (0x1 << 5) // (HDMA) Request a destination single transfer on channel 2. +#define AT91C_HDMA_SSREQ3 (0x1 << 6) // (HDMA) Request a source single transfer on channel 3 +#define AT91C_HDMA_SSREQ3_0 (0x0 << 6) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ3_1 (0x1 << 6) // (HDMA) Request a source single transfer on channel 3. +#define AT91C_HDMA_DSREQ3 (0x1 << 7) // (HDMA) Request a destination single transfer on channel 3 +#define AT91C_HDMA_DSREQ3_0 (0x0 << 7) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ3_1 (0x1 << 7) // (HDMA) Request a destination single transfer on channel 3. +#define AT91C_HDMA_SSREQ4 (0x1 << 8) // (HDMA) Request a source single transfer on channel 4 +#define AT91C_HDMA_SSREQ4_0 (0x0 << 8) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ4_1 (0x1 << 8) // (HDMA) Request a source single transfer on channel 4. +#define AT91C_HDMA_DSREQ4 (0x1 << 9) // (HDMA) Request a destination single transfer on channel 4 +#define AT91C_HDMA_DSREQ4_0 (0x0 << 9) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ4_1 (0x1 << 9) // (HDMA) Request a destination single transfer on channel 4. +#define AT91C_HDMA_SSREQ5 (0x1 << 10) // (HDMA) Request a source single transfer on channel 5 +#define AT91C_HDMA_SSREQ5_0 (0x0 << 10) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ5_1 (0x1 << 10) // (HDMA) Request a source single transfer on channel 5. +#define AT91C_HDMA_DSREQ6 (0x1 << 11) // (HDMA) Request a destination single transfer on channel 5 +#define AT91C_HDMA_DSREQ6_0 (0x0 << 11) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ6_1 (0x1 << 11) // (HDMA) Request a destination single transfer on channel 5. +#define AT91C_HDMA_SSREQ6 (0x1 << 12) // (HDMA) Request a source single transfer on channel 6 +#define AT91C_HDMA_SSREQ6_0 (0x0 << 12) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ6_1 (0x1 << 12) // (HDMA) Request a source single transfer on channel 6. +#define AT91C_HDMA_SSREQ7 (0x1 << 14) // (HDMA) Request a source single transfer on channel 7 +#define AT91C_HDMA_SSREQ7_0 (0x0 << 14) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ7_1 (0x1 << 14) // (HDMA) Request a source single transfer on channel 7. +#define AT91C_HDMA_DSREQ7 (0x1 << 15) // (HDMA) Request a destination single transfer on channel 7 +#define AT91C_HDMA_DSREQ7_0 (0x0 << 15) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ7_1 (0x1 << 15) // (HDMA) Request a destination single transfer on channel 7. +// -------- HDMA_CREQ : (HDMA Offset: 0xc) -------- +#define AT91C_HDMA_SCREQ0 (0x1 << 0) // (HDMA) Request a source chunk transfer on channel 0 +#define AT91C_HDMA_SCREQ0_0 (0x0) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ0_1 (0x1) // (HDMA) Request a source chunk transfer on channel 0. +#define AT91C_HDMA_DCREQ0 (0x1 << 1) // (HDMA) Request a destination chunk transfer on channel 0 +#define AT91C_HDMA_DCREQ0_0 (0x0 << 1) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ0_1 (0x1 << 1) // (HDMA) Request a destination chunk transfer on channel 0. +#define AT91C_HDMA_SCREQ1 (0x1 << 2) // (HDMA) Request a source chunk transfer on channel 1 +#define AT91C_HDMA_SCREQ1_0 (0x0 << 2) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ1_1 (0x1 << 2) // (HDMA) Request a source chunk transfer on channel 1. +#define AT91C_HDMA_DCREQ1 (0x1 << 3) // (HDMA) Request a destination chunk transfer on channel 1 +#define AT91C_HDMA_DCREQ1_0 (0x0 << 3) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ1_1 (0x1 << 3) // (HDMA) Request a destination chunk transfer on channel 1. +#define AT91C_HDMA_SCREQ2 (0x1 << 4) // (HDMA) Request a source chunk transfer on channel 2 +#define AT91C_HDMA_SCREQ2_0 (0x0 << 4) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ2_1 (0x1 << 4) // (HDMA) Request a source chunk transfer on channel 2. +#define AT91C_HDMA_DCREQ2 (0x1 << 5) // (HDMA) Request a destination chunk transfer on channel 2 +#define AT91C_HDMA_DCREQ2_0 (0x0 << 5) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ2_1 (0x1 << 5) // (HDMA) Request a destination chunk transfer on channel 2. +#define AT91C_HDMA_SCREQ3 (0x1 << 6) // (HDMA) Request a source chunk transfer on channel 3 +#define AT91C_HDMA_SCREQ3_0 (0x0 << 6) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ3_1 (0x1 << 6) // (HDMA) Request a source chunk transfer on channel 3. +#define AT91C_HDMA_DCREQ3 (0x1 << 7) // (HDMA) Request a destination chunk transfer on channel 3 +#define AT91C_HDMA_DCREQ3_0 (0x0 << 7) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ3_1 (0x1 << 7) // (HDMA) Request a destination chunk transfer on channel 3. +#define AT91C_HDMA_SCREQ4 (0x1 << 8) // (HDMA) Request a source chunk transfer on channel 4 +#define AT91C_HDMA_SCREQ4_0 (0x0 << 8) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ4_1 (0x1 << 8) // (HDMA) Request a source chunk transfer on channel 4. +#define AT91C_HDMA_DCREQ4 (0x1 << 9) // (HDMA) Request a destination chunk transfer on channel 4 +#define AT91C_HDMA_DCREQ4_0 (0x0 << 9) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ4_1 (0x1 << 9) // (HDMA) Request a destination chunk transfer on channel 4. +#define AT91C_HDMA_SCREQ5 (0x1 << 10) // (HDMA) Request a source chunk transfer on channel 5 +#define AT91C_HDMA_SCREQ5_0 (0x0 << 10) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ5_1 (0x1 << 10) // (HDMA) Request a source chunk transfer on channel 5. +#define AT91C_HDMA_DCREQ6 (0x1 << 11) // (HDMA) Request a destination chunk transfer on channel 5 +#define AT91C_HDMA_DCREQ6_0 (0x0 << 11) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ6_1 (0x1 << 11) // (HDMA) Request a destination chunk transfer on channel 5. +#define AT91C_HDMA_SCREQ6 (0x1 << 12) // (HDMA) Request a source chunk transfer on channel 6 +#define AT91C_HDMA_SCREQ6_0 (0x0 << 12) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ6_1 (0x1 << 12) // (HDMA) Request a source chunk transfer on channel 6. +#define AT91C_HDMA_SCREQ7 (0x1 << 14) // (HDMA) Request a source chunk transfer on channel 7 +#define AT91C_HDMA_SCREQ7_0 (0x0 << 14) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ7_1 (0x1 << 14) // (HDMA) Request a source chunk transfer on channel 7. +#define AT91C_HDMA_DCREQ7 (0x1 << 15) // (HDMA) Request a destination chunk transfer on channel 7 +#define AT91C_HDMA_DCREQ7_0 (0x0 << 15) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ7_1 (0x1 << 15) // (HDMA) Request a destination chunk transfer on channel 7. +// -------- HDMA_LAST : (HDMA Offset: 0x10) -------- +#define AT91C_HDMA_SLAST0 (0x1 << 0) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 0 +#define AT91C_HDMA_SLAST0_0 (0x0) // (HDMA) No effect. +#define AT91C_HDMA_SLAST0_1 (0x1) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 0. +#define AT91C_HDMA_DLAST0 (0x1 << 1) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 0 +#define AT91C_HDMA_DLAST0_0 (0x0 << 1) // (HDMA) No effect. +#define AT91C_HDMA_DLAST0_1 (0x1 << 1) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 0. +#define AT91C_HDMA_SLAST1 (0x1 << 2) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 1 +#define AT91C_HDMA_SLAST1_0 (0x0 << 2) // (HDMA) No effect. +#define AT91C_HDMA_SLAST1_1 (0x1 << 2) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 1. +#define AT91C_HDMA_DLAST1 (0x1 << 3) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 1 +#define AT91C_HDMA_DLAST1_0 (0x0 << 3) // (HDMA) No effect. +#define AT91C_HDMA_DLAST1_1 (0x1 << 3) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 1. +#define AT91C_HDMA_SLAST2 (0x1 << 4) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 2 +#define AT91C_HDMA_SLAST2_0 (0x0 << 4) // (HDMA) No effect. +#define AT91C_HDMA_SLAST2_1 (0x1 << 4) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 2. +#define AT91C_HDMA_DLAST2 (0x1 << 5) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 2 +#define AT91C_HDMA_DLAST2_0 (0x0 << 5) // (HDMA) No effect. +#define AT91C_HDMA_DLAST2_1 (0x1 << 5) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 2. +#define AT91C_HDMA_SLAST3 (0x1 << 6) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 3 +#define AT91C_HDMA_SLAST3_0 (0x0 << 6) // (HDMA) No effect. +#define AT91C_HDMA_SLAST3_1 (0x1 << 6) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 3. +#define AT91C_HDMA_DLAST3 (0x1 << 7) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 3 +#define AT91C_HDMA_DLAST3_0 (0x0 << 7) // (HDMA) No effect. +#define AT91C_HDMA_DLAST3_1 (0x1 << 7) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 3. +#define AT91C_HDMA_SLAST4 (0x1 << 8) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 4 +#define AT91C_HDMA_SLAST4_0 (0x0 << 8) // (HDMA) No effect. +#define AT91C_HDMA_SLAST4_1 (0x1 << 8) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 4. +#define AT91C_HDMA_DLAST4 (0x1 << 9) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 4 +#define AT91C_HDMA_DLAST4_0 (0x0 << 9) // (HDMA) No effect. +#define AT91C_HDMA_DLAST4_1 (0x1 << 9) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 4. +#define AT91C_HDMA_SLAST5 (0x1 << 10) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 5 +#define AT91C_HDMA_SLAST5_0 (0x0 << 10) // (HDMA) No effect. +#define AT91C_HDMA_SLAST5_1 (0x1 << 10) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 5. +#define AT91C_HDMA_DLAST6 (0x1 << 11) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 5 +#define AT91C_HDMA_DLAST6_0 (0x0 << 11) // (HDMA) No effect. +#define AT91C_HDMA_DLAST6_1 (0x1 << 11) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 5. +#define AT91C_HDMA_SLAST6 (0x1 << 12) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 6 +#define AT91C_HDMA_SLAST6_0 (0x0 << 12) // (HDMA) No effect. +#define AT91C_HDMA_SLAST6_1 (0x1 << 12) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 6. +#define AT91C_HDMA_SLAST7 (0x1 << 14) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 7 +#define AT91C_HDMA_SLAST7_0 (0x0 << 14) // (HDMA) No effect. +#define AT91C_HDMA_SLAST7_1 (0x1 << 14) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 7. +#define AT91C_HDMA_DLAST7 (0x1 << 15) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 7 +#define AT91C_HDMA_DLAST7_0 (0x0 << 15) // (HDMA) No effect. +#define AT91C_HDMA_DLAST7_1 (0x1 << 15) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 7. +// -------- HDMA_SYNC : (HDMA Offset: 0x14) -------- +#define AT91C_SYNC_REQ (0xFFFF << 0) // (HDMA) +// -------- HDMA_EBCIER : (HDMA Offset: 0x18) Buffer Transfer Completed/Chained Buffer Transfer Completed/Access Error Interrupt Enable Register -------- +#define AT91C_HDMA_BTC0 (0x1 << 0) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC1 (0x1 << 1) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC2 (0x1 << 2) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC3 (0x1 << 3) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC4 (0x1 << 4) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC5 (0x1 << 5) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC6 (0x1 << 6) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC7 (0x1 << 7) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC0 (0x1 << 8) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC1 (0x1 << 9) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC2 (0x1 << 10) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC3 (0x1 << 11) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC4 (0x1 << 12) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC5 (0x1 << 13) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC6 (0x1 << 14) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC7 (0x1 << 15) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR0 (0x1 << 16) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR1 (0x1 << 17) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR2 (0x1 << 18) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR3 (0x1 << 19) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR4 (0x1 << 20) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR5 (0x1 << 21) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR6 (0x1 << 22) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR7 (0x1 << 23) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +// -------- HDMA_EBCIDR : (HDMA Offset: 0x1c) -------- +// -------- HDMA_EBCIMR : (HDMA Offset: 0x20) -------- +// -------- HDMA_EBCISR : (HDMA Offset: 0x24) -------- +// -------- HDMA_CHER : (HDMA Offset: 0x28) -------- +#define AT91C_HDMA_ENA0 (0x1 << 0) // (HDMA) When set, channel 0 enabled. +#define AT91C_HDMA_ENA0_0 (0x0) // (HDMA) No effect. +#define AT91C_HDMA_ENA0_1 (0x1) // (HDMA) Channel 0 enabled. +#define AT91C_HDMA_ENA1 (0x1 << 1) // (HDMA) When set, channel 1 enabled. +#define AT91C_HDMA_ENA1_0 (0x0 << 1) // (HDMA) No effect. +#define AT91C_HDMA_ENA1_1 (0x1 << 1) // (HDMA) Channel 1 enabled. +#define AT91C_HDMA_ENA2 (0x1 << 2) // (HDMA) When set, channel 2 enabled. +#define AT91C_HDMA_ENA2_0 (0x0 << 2) // (HDMA) No effect. +#define AT91C_HDMA_ENA2_1 (0x1 << 2) // (HDMA) Channel 2 enabled. +#define AT91C_HDMA_ENA3 (0x1 << 3) // (HDMA) When set, channel 3 enabled. +#define AT91C_HDMA_ENA3_0 (0x0 << 3) // (HDMA) No effect. +#define AT91C_HDMA_ENA3_1 (0x1 << 3) // (HDMA) Channel 3 enabled. +#define AT91C_HDMA_ENA4 (0x1 << 4) // (HDMA) When set, channel 4 enabled. +#define AT91C_HDMA_ENA4_0 (0x0 << 4) // (HDMA) No effect. +#define AT91C_HDMA_ENA4_1 (0x1 << 4) // (HDMA) Channel 4 enabled. +#define AT91C_HDMA_ENA5 (0x1 << 5) // (HDMA) When set, channel 5 enabled. +#define AT91C_HDMA_ENA5_0 (0x0 << 5) // (HDMA) No effect. +#define AT91C_HDMA_ENA5_1 (0x1 << 5) // (HDMA) Channel 5 enabled. +#define AT91C_HDMA_ENA6 (0x1 << 6) // (HDMA) When set, channel 6 enabled. +#define AT91C_HDMA_ENA6_0 (0x0 << 6) // (HDMA) No effect. +#define AT91C_HDMA_ENA6_1 (0x1 << 6) // (HDMA) Channel 6 enabled. +#define AT91C_HDMA_ENA7 (0x1 << 7) // (HDMA) When set, channel 7 enabled. +#define AT91C_HDMA_ENA7_0 (0x0 << 7) // (HDMA) No effect. +#define AT91C_HDMA_ENA7_1 (0x1 << 7) // (HDMA) Channel 7 enabled. +#define AT91C_HDMA_SUSP0 (0x1 << 8) // (HDMA) When set, channel 0 freezed and its current context. +#define AT91C_HDMA_SUSP0_0 (0x0 << 8) // (HDMA) No effect. +#define AT91C_HDMA_SUSP0_1 (0x1 << 8) // (HDMA) Channel 0 freezed. +#define AT91C_HDMA_SUSP1 (0x1 << 9) // (HDMA) When set, channel 1 freezed and its current context. +#define AT91C_HDMA_SUSP1_0 (0x0 << 9) // (HDMA) No effect. +#define AT91C_HDMA_SUSP1_1 (0x1 << 9) // (HDMA) Channel 1 freezed. +#define AT91C_HDMA_SUSP2 (0x1 << 10) // (HDMA) When set, channel 2 freezed and its current context. +#define AT91C_HDMA_SUSP2_0 (0x0 << 10) // (HDMA) No effect. +#define AT91C_HDMA_SUSP2_1 (0x1 << 10) // (HDMA) Channel 2 freezed. +#define AT91C_HDMA_SUSP3 (0x1 << 11) // (HDMA) When set, channel 3 freezed and its current context. +#define AT91C_HDMA_SUSP3_0 (0x0 << 11) // (HDMA) No effect. +#define AT91C_HDMA_SUSP3_1 (0x1 << 11) // (HDMA) Channel 3 freezed. +#define AT91C_HDMA_SUSP4 (0x1 << 12) // (HDMA) When set, channel 4 freezed and its current context. +#define AT91C_HDMA_SUSP4_0 (0x0 << 12) // (HDMA) No effect. +#define AT91C_HDMA_SUSP4_1 (0x1 << 12) // (HDMA) Channel 4 freezed. +#define AT91C_HDMA_SUSP5 (0x1 << 13) // (HDMA) When set, channel 5 freezed and its current context. +#define AT91C_HDMA_SUSP5_0 (0x0 << 13) // (HDMA) No effect. +#define AT91C_HDMA_SUSP5_1 (0x1 << 13) // (HDMA) Channel 5 freezed. +#define AT91C_HDMA_SUSP6 (0x1 << 14) // (HDMA) When set, channel 6 freezed and its current context. +#define AT91C_HDMA_SUSP6_0 (0x0 << 14) // (HDMA) No effect. +#define AT91C_HDMA_SUSP6_1 (0x1 << 14) // (HDMA) Channel 6 freezed. +#define AT91C_HDMA_SUSP7 (0x1 << 15) // (HDMA) When set, channel 7 freezed and its current context. +#define AT91C_HDMA_SUSP7_0 (0x0 << 15) // (HDMA) No effect. +#define AT91C_HDMA_SUSP7_1 (0x1 << 15) // (HDMA) Channel 7 freezed. +#define AT91C_HDMA_KEEP0 (0x1 << 24) // (HDMA) When set, it resumes the channel 0 from an automatic stall state. +#define AT91C_HDMA_KEEP0_0 (0x0 << 24) // (HDMA) No effect. +#define AT91C_HDMA_KEEP0_1 (0x1 << 24) // (HDMA) Resumes the channel 0. +#define AT91C_HDMA_KEEP1 (0x1 << 25) // (HDMA) When set, it resumes the channel 1 from an automatic stall state. +#define AT91C_HDMA_KEEP1_0 (0x0 << 25) // (HDMA) No effect. +#define AT91C_HDMA_KEEP1_1 (0x1 << 25) // (HDMA) Resumes the channel 1. +#define AT91C_HDMA_KEEP2 (0x1 << 26) // (HDMA) When set, it resumes the channel 2 from an automatic stall state. +#define AT91C_HDMA_KEEP2_0 (0x0 << 26) // (HDMA) No effect. +#define AT91C_HDMA_KEEP2_1 (0x1 << 26) // (HDMA) Resumes the channel 2. +#define AT91C_HDMA_KEEP3 (0x1 << 27) // (HDMA) When set, it resumes the channel 3 from an automatic stall state. +#define AT91C_HDMA_KEEP3_0 (0x0 << 27) // (HDMA) No effect. +#define AT91C_HDMA_KEEP3_1 (0x1 << 27) // (HDMA) Resumes the channel 3. +#define AT91C_HDMA_KEEP4 (0x1 << 28) // (HDMA) When set, it resumes the channel 4 from an automatic stall state. +#define AT91C_HDMA_KEEP4_0 (0x0 << 28) // (HDMA) No effect. +#define AT91C_HDMA_KEEP4_1 (0x1 << 28) // (HDMA) Resumes the channel 4. +#define AT91C_HDMA_KEEP5 (0x1 << 29) // (HDMA) When set, it resumes the channel 5 from an automatic stall state. +#define AT91C_HDMA_KEEP5_0 (0x0 << 29) // (HDMA) No effect. +#define AT91C_HDMA_KEEP5_1 (0x1 << 29) // (HDMA) Resumes the channel 5. +#define AT91C_HDMA_KEEP6 (0x1 << 30) // (HDMA) When set, it resumes the channel 6 from an automatic stall state. +#define AT91C_HDMA_KEEP6_0 (0x0 << 30) // (HDMA) No effect. +#define AT91C_HDMA_KEEP6_1 (0x1 << 30) // (HDMA) Resumes the channel 6. +#define AT91C_HDMA_KEEP7 (0x1 << 31) // (HDMA) When set, it resumes the channel 7 from an automatic stall state. +#define AT91C_HDMA_KEEP7_0 (0x0 << 31) // (HDMA) No effect. +#define AT91C_HDMA_KEEP7_1 (0x1 << 31) // (HDMA) Resumes the channel 7. +// -------- HDMA_CHDR : (HDMA Offset: 0x2c) -------- +#define AT91C_HDMA_DIS0 (0x1 << 0) // (HDMA) Write one to this field to disable the channel 0. +#define AT91C_HDMA_DIS0_0 (0x0) // (HDMA) No effect. +#define AT91C_HDMA_DIS0_1 (0x1) // (HDMA) Disables the channel 0. +#define AT91C_HDMA_DIS1 (0x1 << 1) // (HDMA) Write one to this field to disable the channel 1. +#define AT91C_HDMA_DIS1_0 (0x0 << 1) // (HDMA) No effect. +#define AT91C_HDMA_DIS1_1 (0x1 << 1) // (HDMA) Disables the channel 1. +#define AT91C_HDMA_DIS2 (0x1 << 2) // (HDMA) Write one to this field to disable the channel 2. +#define AT91C_HDMA_DIS2_0 (0x0 << 2) // (HDMA) No effect. +#define AT91C_HDMA_DIS2_1 (0x1 << 2) // (HDMA) Disables the channel 2. +#define AT91C_HDMA_DIS3 (0x1 << 3) // (HDMA) Write one to this field to disable the channel 3. +#define AT91C_HDMA_DIS3_0 (0x0 << 3) // (HDMA) No effect. +#define AT91C_HDMA_DIS3_1 (0x1 << 3) // (HDMA) Disables the channel 3. +#define AT91C_HDMA_DIS4 (0x1 << 4) // (HDMA) Write one to this field to disable the channel 4. +#define AT91C_HDMA_DIS4_0 (0x0 << 4) // (HDMA) No effect. +#define AT91C_HDMA_DIS4_1 (0x1 << 4) // (HDMA) Disables the channel 4. +#define AT91C_HDMA_DIS5 (0x1 << 5) // (HDMA) Write one to this field to disable the channel 5. +#define AT91C_HDMA_DIS5_0 (0x0 << 5) // (HDMA) No effect. +#define AT91C_HDMA_DIS5_1 (0x1 << 5) // (HDMA) Disables the channel 5. +#define AT91C_HDMA_DIS6 (0x1 << 6) // (HDMA) Write one to this field to disable the channel 6. +#define AT91C_HDMA_DIS6_0 (0x0 << 6) // (HDMA) No effect. +#define AT91C_HDMA_DIS6_1 (0x1 << 6) // (HDMA) Disables the channel 6. +#define AT91C_HDMA_DIS7 (0x1 << 7) // (HDMA) Write one to this field to disable the channel 7. +#define AT91C_HDMA_DIS7_0 (0x0 << 7) // (HDMA) No effect. +#define AT91C_HDMA_DIS7_1 (0x1 << 7) // (HDMA) Disables the channel 7. +#define AT91C_HDMA_RES0 (0x1 << 8) // (HDMA) Write one to this field to resume the channel 0 transfer restoring its context. +#define AT91C_HDMA_RES0_0 (0x0 << 8) // (HDMA) No effect. +#define AT91C_HDMA_RES0_1 (0x1 << 8) // (HDMA) Resumes the channel 0. +#define AT91C_HDMA_RES1 (0x1 << 9) // (HDMA) Write one to this field to resume the channel 1 transfer restoring its context. +#define AT91C_HDMA_RES1_0 (0x0 << 9) // (HDMA) No effect. +#define AT91C_HDMA_RES1_1 (0x1 << 9) // (HDMA) Resumes the channel 1. +#define AT91C_HDMA_RES2 (0x1 << 10) // (HDMA) Write one to this field to resume the channel 2 transfer restoring its context. +#define AT91C_HDMA_RES2_0 (0x0 << 10) // (HDMA) No effect. +#define AT91C_HDMA_RES2_1 (0x1 << 10) // (HDMA) Resumes the channel 2. +#define AT91C_HDMA_RES3 (0x1 << 11) // (HDMA) Write one to this field to resume the channel 3 transfer restoring its context. +#define AT91C_HDMA_RES3_0 (0x0 << 11) // (HDMA) No effect. +#define AT91C_HDMA_RES3_1 (0x1 << 11) // (HDMA) Resumes the channel 3. +#define AT91C_HDMA_RES4 (0x1 << 12) // (HDMA) Write one to this field to resume the channel 4 transfer restoring its context. +#define AT91C_HDMA_RES4_0 (0x0 << 12) // (HDMA) No effect. +#define AT91C_HDMA_RES4_1 (0x1 << 12) // (HDMA) Resumes the channel 4. +#define AT91C_HDMA_RES5 (0x1 << 13) // (HDMA) Write one to this field to resume the channel 5 transfer restoring its context. +#define AT91C_HDMA_RES5_0 (0x0 << 13) // (HDMA) No effect. +#define AT91C_HDMA_RES5_1 (0x1 << 13) // (HDMA) Resumes the channel 5. +#define AT91C_HDMA_RES6 (0x1 << 14) // (HDMA) Write one to this field to resume the channel 6 transfer restoring its context. +#define AT91C_HDMA_RES6_0 (0x0 << 14) // (HDMA) No effect. +#define AT91C_HDMA_RES6_1 (0x1 << 14) // (HDMA) Resumes the channel 6. +#define AT91C_HDMA_RES7 (0x1 << 15) // (HDMA) Write one to this field to resume the channel 7 transfer restoring its context. +#define AT91C_HDMA_RES7_0 (0x0 << 15) // (HDMA) No effect. +#define AT91C_HDMA_RES7_1 (0x1 << 15) // (HDMA) Resumes the channel 7. +// -------- HDMA_CHSR : (HDMA Offset: 0x30) -------- +#define AT91C_HDMA_EMPT0 (0x1 << 16) // (HDMA) When set, channel 0 is empty. +#define AT91C_HDMA_EMPT0_0 (0x0 << 16) // (HDMA) No effect. +#define AT91C_HDMA_EMPT0_1 (0x1 << 16) // (HDMA) Channel 0 empty. +#define AT91C_HDMA_EMPT1 (0x1 << 17) // (HDMA) When set, channel 1 is empty. +#define AT91C_HDMA_EMPT1_0 (0x0 << 17) // (HDMA) No effect. +#define AT91C_HDMA_EMPT1_1 (0x1 << 17) // (HDMA) Channel 1 empty. +#define AT91C_HDMA_EMPT2 (0x1 << 18) // (HDMA) When set, channel 2 is empty. +#define AT91C_HDMA_EMPT2_0 (0x0 << 18) // (HDMA) No effect. +#define AT91C_HDMA_EMPT2_1 (0x1 << 18) // (HDMA) Channel 2 empty. +#define AT91C_HDMA_EMPT3 (0x1 << 19) // (HDMA) When set, channel 3 is empty. +#define AT91C_HDMA_EMPT3_0 (0x0 << 19) // (HDMA) No effect. +#define AT91C_HDMA_EMPT3_1 (0x1 << 19) // (HDMA) Channel 3 empty. +#define AT91C_HDMA_EMPT4 (0x1 << 20) // (HDMA) When set, channel 4 is empty. +#define AT91C_HDMA_EMPT4_0 (0x0 << 20) // (HDMA) No effect. +#define AT91C_HDMA_EMPT4_1 (0x1 << 20) // (HDMA) Channel 4 empty. +#define AT91C_HDMA_EMPT5 (0x1 << 21) // (HDMA) When set, channel 5 is empty. +#define AT91C_HDMA_EMPT5_0 (0x0 << 21) // (HDMA) No effect. +#define AT91C_HDMA_EMPT5_1 (0x1 << 21) // (HDMA) Channel 5 empty. +#define AT91C_HDMA_EMPT6 (0x1 << 22) // (HDMA) When set, channel 6 is empty. +#define AT91C_HDMA_EMPT6_0 (0x0 << 22) // (HDMA) No effect. +#define AT91C_HDMA_EMPT6_1 (0x1 << 22) // (HDMA) Channel 6 empty. +#define AT91C_HDMA_EMPT7 (0x1 << 23) // (HDMA) When set, channel 7 is empty. +#define AT91C_HDMA_EMPT7_0 (0x0 << 23) // (HDMA) No effect. +#define AT91C_HDMA_EMPT7_1 (0x1 << 23) // (HDMA) Channel 7 empty. +#define AT91C_HDMA_STAL0 (0x1 << 24) // (HDMA) When set, channel 0 is stalled. +#define AT91C_HDMA_STAL0_0 (0x0 << 24) // (HDMA) No effect. +#define AT91C_HDMA_STAL0_1 (0x1 << 24) // (HDMA) Channel 0 stalled. +#define AT91C_HDMA_STAL1 (0x1 << 25) // (HDMA) When set, channel 1 is stalled. +#define AT91C_HDMA_STAL1_0 (0x0 << 25) // (HDMA) No effect. +#define AT91C_HDMA_STAL1_1 (0x1 << 25) // (HDMA) Channel 1 stalled. +#define AT91C_HDMA_STAL2 (0x1 << 26) // (HDMA) When set, channel 2 is stalled. +#define AT91C_HDMA_STAL2_0 (0x0 << 26) // (HDMA) No effect. +#define AT91C_HDMA_STAL2_1 (0x1 << 26) // (HDMA) Channel 2 stalled. +#define AT91C_HDMA_STAL3 (0x1 << 27) // (HDMA) When set, channel 3 is stalled. +#define AT91C_HDMA_STAL3_0 (0x0 << 27) // (HDMA) No effect. +#define AT91C_HDMA_STAL3_1 (0x1 << 27) // (HDMA) Channel 3 stalled. +#define AT91C_HDMA_STAL4 (0x1 << 28) // (HDMA) When set, channel 4 is stalled. +#define AT91C_HDMA_STAL4_0 (0x0 << 28) // (HDMA) No effect. +#define AT91C_HDMA_STAL4_1 (0x1 << 28) // (HDMA) Channel 4 stalled. +#define AT91C_HDMA_STAL5 (0x1 << 29) // (HDMA) When set, channel 5 is stalled. +#define AT91C_HDMA_STAL5_0 (0x0 << 29) // (HDMA) No effect. +#define AT91C_HDMA_STAL5_1 (0x1 << 29) // (HDMA) Channel 5 stalled. +#define AT91C_HDMA_STAL6 (0x1 << 30) // (HDMA) When set, channel 6 is stalled. +#define AT91C_HDMA_STAL6_0 (0x0 << 30) // (HDMA) No effect. +#define AT91C_HDMA_STAL6_1 (0x1 << 30) // (HDMA) Channel 6 stalled. +#define AT91C_HDMA_STAL7 (0x1 << 31) // (HDMA) When set, channel 7 is stalled. +#define AT91C_HDMA_STAL7_0 (0x0 << 31) // (HDMA) No effect. +#define AT91C_HDMA_STAL7_1 (0x1 << 31) // (HDMA) Channel 7 stalled. +// -------- HDMA_RSVD : (HDMA Offset: 0x34) -------- +// -------- HDMA_RSVD : (HDMA Offset: 0x38) -------- +// -------- HDMA_VER : (HDMA Offset: 0x1fc) -------- + +// ***************************************************************************** +// REGISTER ADDRESS DEFINITION FOR AT91SAM3U4 +// ***************************************************************************** +// ========== Register definition for SYS peripheral ========== +#define AT91C_SYS_GPBR (AT91_CAST(AT91_REG *) 0x400E1290) // (SYS) General Purpose Register +// ========== Register definition for HSMC4_CS0 peripheral ========== +#define AT91C_CS0_MODE (AT91_CAST(AT91_REG *) 0x400E0080) // (HSMC4_CS0) Mode Register +#define AT91C_CS0_PULSE (AT91_CAST(AT91_REG *) 0x400E0074) // (HSMC4_CS0) Pulse Register +#define AT91C_CS0_CYCLE (AT91_CAST(AT91_REG *) 0x400E0078) // (HSMC4_CS0) Cycle Register +#define AT91C_CS0_TIMINGS (AT91_CAST(AT91_REG *) 0x400E007C) // (HSMC4_CS0) Timmings Register +#define AT91C_CS0_SETUP (AT91_CAST(AT91_REG *) 0x400E0070) // (HSMC4_CS0) Setup Register +// ========== Register definition for HSMC4_CS1 peripheral ========== +#define AT91C_CS1_CYCLE (AT91_CAST(AT91_REG *) 0x400E008C) // (HSMC4_CS1) Cycle Register +#define AT91C_CS1_PULSE (AT91_CAST(AT91_REG *) 0x400E0088) // (HSMC4_CS1) Pulse Register +#define AT91C_CS1_MODE (AT91_CAST(AT91_REG *) 0x400E0094) // (HSMC4_CS1) Mode Register +#define AT91C_CS1_SETUP (AT91_CAST(AT91_REG *) 0x400E0084) // (HSMC4_CS1) Setup Register +#define AT91C_CS1_TIMINGS (AT91_CAST(AT91_REG *) 0x400E0090) // (HSMC4_CS1) Timmings Register +// ========== Register definition for HSMC4_CS2 peripheral ========== +#define AT91C_CS2_PULSE (AT91_CAST(AT91_REG *) 0x400E009C) // (HSMC4_CS2) Pulse Register +#define AT91C_CS2_TIMINGS (AT91_CAST(AT91_REG *) 0x400E00A4) // (HSMC4_CS2) Timmings Register +#define AT91C_CS2_CYCLE (AT91_CAST(AT91_REG *) 0x400E00A0) // (HSMC4_CS2) Cycle Register +#define AT91C_CS2_MODE (AT91_CAST(AT91_REG *) 0x400E00A8) // (HSMC4_CS2) Mode Register +#define AT91C_CS2_SETUP (AT91_CAST(AT91_REG *) 0x400E0098) // (HSMC4_CS2) Setup Register +// ========== Register definition for HSMC4_CS3 peripheral ========== +#define AT91C_CS3_MODE (AT91_CAST(AT91_REG *) 0x400E00BC) // (HSMC4_CS3) Mode Register +#define AT91C_CS3_TIMINGS (AT91_CAST(AT91_REG *) 0x400E00B8) // (HSMC4_CS3) Timmings Register +#define AT91C_CS3_SETUP (AT91_CAST(AT91_REG *) 0x400E00AC) // (HSMC4_CS3) Setup Register +#define AT91C_CS3_CYCLE (AT91_CAST(AT91_REG *) 0x400E00B4) // (HSMC4_CS3) Cycle Register +#define AT91C_CS3_PULSE (AT91_CAST(AT91_REG *) 0x400E00B0) // (HSMC4_CS3) Pulse Register +// ========== Register definition for HSMC4_NFC peripheral ========== +#define AT91C_NFC_MODE (AT91_CAST(AT91_REG *) 0x400E010C) // (HSMC4_NFC) Mode Register +#define AT91C_NFC_CYCLE (AT91_CAST(AT91_REG *) 0x400E0104) // (HSMC4_NFC) Cycle Register +#define AT91C_NFC_PULSE (AT91_CAST(AT91_REG *) 0x400E0100) // (HSMC4_NFC) Pulse Register +#define AT91C_NFC_SETUP (AT91_CAST(AT91_REG *) 0x400E00FC) // (HSMC4_NFC) Setup Register +#define AT91C_NFC_TIMINGS (AT91_CAST(AT91_REG *) 0x400E0108) // (HSMC4_NFC) Timmings Register +// ========== Register definition for HSMC4 peripheral ========== +#define AT91C_HSMC4_IPNAME1 (AT91_CAST(AT91_REG *) 0x400E01F0) // (HSMC4) Write Protection Status Register +#define AT91C_HSMC4_ECCPR6 (AT91_CAST(AT91_REG *) 0x400E0048) // (HSMC4) ECC Parity register 6 +#define AT91C_HSMC4_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400E01EC) // (HSMC4) Write Protection Status Register +#define AT91C_HSMC4_ECCPR11 (AT91_CAST(AT91_REG *) 0x400E005C) // (HSMC4) ECC Parity register 11 +#define AT91C_HSMC4_SR (AT91_CAST(AT91_REG *) 0x400E0008) // (HSMC4) Status Register +#define AT91C_HSMC4_IMR (AT91_CAST(AT91_REG *) 0x400E0014) // (HSMC4) Interrupt Mask Register +#define AT91C_HSMC4_WPSR (AT91_CAST(AT91_REG *) 0x400E01E8) // (HSMC4) Write Protection Status Register +#define AT91C_HSMC4_BANK (AT91_CAST(AT91_REG *) 0x400E001C) // (HSMC4) Bank Register +#define AT91C_HSMC4_ECCPR8 (AT91_CAST(AT91_REG *) 0x400E0050) // (HSMC4) ECC Parity register 8 +#define AT91C_HSMC4_WPCR (AT91_CAST(AT91_REG *) 0x400E01E4) // (HSMC4) Write Protection Control register +#define AT91C_HSMC4_ECCPR2 (AT91_CAST(AT91_REG *) 0x400E0038) // (HSMC4) ECC Parity register 2 +#define AT91C_HSMC4_ECCPR1 (AT91_CAST(AT91_REG *) 0x400E0030) // (HSMC4) ECC Parity register 1 +#define AT91C_HSMC4_ECCSR2 (AT91_CAST(AT91_REG *) 0x400E0034) // (HSMC4) ECC Status register 2 +#define AT91C_HSMC4_OCMS (AT91_CAST(AT91_REG *) 0x400E0110) // (HSMC4) OCMS MODE register +#define AT91C_HSMC4_ECCPR9 (AT91_CAST(AT91_REG *) 0x400E0054) // (HSMC4) ECC Parity register 9 +#define AT91C_HSMC4_DUMMY (AT91_CAST(AT91_REG *) 0x400E0200) // (HSMC4) This rtegister was created only ti have AHB constants +#define AT91C_HSMC4_ECCPR5 (AT91_CAST(AT91_REG *) 0x400E0044) // (HSMC4) ECC Parity register 5 +#define AT91C_HSMC4_ECCCR (AT91_CAST(AT91_REG *) 0x400E0020) // (HSMC4) ECC reset register +#define AT91C_HSMC4_KEY2 (AT91_CAST(AT91_REG *) 0x400E0118) // (HSMC4) KEY2 Register +#define AT91C_HSMC4_IER (AT91_CAST(AT91_REG *) 0x400E000C) // (HSMC4) Interrupt Enable Register +#define AT91C_HSMC4_ECCSR1 (AT91_CAST(AT91_REG *) 0x400E0028) // (HSMC4) ECC Status register 1 +#define AT91C_HSMC4_IDR (AT91_CAST(AT91_REG *) 0x400E0010) // (HSMC4) Interrupt Disable Register +#define AT91C_HSMC4_ECCPR0 (AT91_CAST(AT91_REG *) 0x400E002C) // (HSMC4) ECC Parity register 0 +#define AT91C_HSMC4_FEATURES (AT91_CAST(AT91_REG *) 0x400E01F8) // (HSMC4) Write Protection Status Register +#define AT91C_HSMC4_ECCPR7 (AT91_CAST(AT91_REG *) 0x400E004C) // (HSMC4) ECC Parity register 7 +#define AT91C_HSMC4_ECCPR12 (AT91_CAST(AT91_REG *) 0x400E0060) // (HSMC4) ECC Parity register 12 +#define AT91C_HSMC4_ECCPR10 (AT91_CAST(AT91_REG *) 0x400E0058) // (HSMC4) ECC Parity register 10 +#define AT91C_HSMC4_KEY1 (AT91_CAST(AT91_REG *) 0x400E0114) // (HSMC4) KEY1 Register +#define AT91C_HSMC4_VER (AT91_CAST(AT91_REG *) 0x400E01FC) // (HSMC4) HSMC4 Version Register +#define AT91C_HSMC4_Eccpr15 (AT91_CAST(AT91_REG *) 0x400E006C) // (HSMC4) ECC Parity register 15 +#define AT91C_HSMC4_ECCPR4 (AT91_CAST(AT91_REG *) 0x400E0040) // (HSMC4) ECC Parity register 4 +#define AT91C_HSMC4_IPNAME2 (AT91_CAST(AT91_REG *) 0x400E01F4) // (HSMC4) Write Protection Status Register +#define AT91C_HSMC4_ECCCMD (AT91_CAST(AT91_REG *) 0x400E0024) // (HSMC4) ECC Page size register +#define AT91C_HSMC4_ADDR (AT91_CAST(AT91_REG *) 0x400E0018) // (HSMC4) Address Cycle Zero Register +#define AT91C_HSMC4_ECCPR3 (AT91_CAST(AT91_REG *) 0x400E003C) // (HSMC4) ECC Parity register 3 +#define AT91C_HSMC4_CFG (AT91_CAST(AT91_REG *) 0x400E0000) // (HSMC4) Configuration Register +#define AT91C_HSMC4_CTRL (AT91_CAST(AT91_REG *) 0x400E0004) // (HSMC4) Control Register +#define AT91C_HSMC4_ECCPR13 (AT91_CAST(AT91_REG *) 0x400E0064) // (HSMC4) ECC Parity register 13 +#define AT91C_HSMC4_ECCPR14 (AT91_CAST(AT91_REG *) 0x400E0068) // (HSMC4) ECC Parity register 14 +// ========== Register definition for MATRIX peripheral ========== +#define AT91C_MATRIX_SFR2 (AT91_CAST(AT91_REG *) 0x400E0318) // (MATRIX) Special Function Register 2 +#define AT91C_MATRIX_SFR3 (AT91_CAST(AT91_REG *) 0x400E031C) // (MATRIX) Special Function Register 3 +#define AT91C_MATRIX_SCFG8 (AT91_CAST(AT91_REG *) 0x400E0260) // (MATRIX) Slave Configuration Register 8 +#define AT91C_MATRIX_MCFG2 (AT91_CAST(AT91_REG *) 0x400E0208) // (MATRIX) Master Configuration Register 2 +#define AT91C_MATRIX_MCFG7 (AT91_CAST(AT91_REG *) 0x400E021C) // (MATRIX) Master Configuration Register 7 +#define AT91C_MATRIX_SCFG3 (AT91_CAST(AT91_REG *) 0x400E024C) // (MATRIX) Slave Configuration Register 3 +#define AT91C_MATRIX_SCFG0 (AT91_CAST(AT91_REG *) 0x400E0240) // (MATRIX) Slave Configuration Register 0 +#define AT91C_MATRIX_SFR12 (AT91_CAST(AT91_REG *) 0x400E0340) // (MATRIX) Special Function Register 12 +#define AT91C_MATRIX_SCFG1 (AT91_CAST(AT91_REG *) 0x400E0244) // (MATRIX) Slave Configuration Register 1 +#define AT91C_MATRIX_SFR8 (AT91_CAST(AT91_REG *) 0x400E0330) // (MATRIX) Special Function Register 8 +#define AT91C_MATRIX_VER (AT91_CAST(AT91_REG *) 0x400E03FC) // (MATRIX) HMATRIX2 VERSION REGISTER +#define AT91C_MATRIX_SFR13 (AT91_CAST(AT91_REG *) 0x400E0344) // (MATRIX) Special Function Register 13 +#define AT91C_MATRIX_SFR5 (AT91_CAST(AT91_REG *) 0x400E0324) // (MATRIX) Special Function Register 5 +#define AT91C_MATRIX_MCFG0 (AT91_CAST(AT91_REG *) 0x400E0200) // (MATRIX) Master Configuration Register 0 : ARM I and D +#define AT91C_MATRIX_SCFG6 (AT91_CAST(AT91_REG *) 0x400E0258) // (MATRIX) Slave Configuration Register 6 +#define AT91C_MATRIX_SFR1 (AT91_CAST(AT91_REG *) 0x400E0314) // (MATRIX) Special Function Register 1 +#define AT91C_MATRIX_SFR14 (AT91_CAST(AT91_REG *) 0x400E0348) // (MATRIX) Special Function Register 14 +#define AT91C_MATRIX_SFR15 (AT91_CAST(AT91_REG *) 0x400E034C) // (MATRIX) Special Function Register 15 +#define AT91C_MATRIX_SFR6 (AT91_CAST(AT91_REG *) 0x400E0328) // (MATRIX) Special Function Register 6 +#define AT91C_MATRIX_SFR11 (AT91_CAST(AT91_REG *) 0x400E033C) // (MATRIX) Special Function Register 11 +#define AT91C_MATRIX_IPNAME2 (AT91_CAST(AT91_REG *) 0x400E03F4) // (MATRIX) HMATRIX2 IPNAME2 REGISTER +#define AT91C_MATRIX_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400E03EC) // (MATRIX) HMATRIX2 ADDRSIZE REGISTER +#define AT91C_MATRIX_MCFG5 (AT91_CAST(AT91_REG *) 0x400E0214) // (MATRIX) Master Configuration Register 5 +#define AT91C_MATRIX_SFR9 (AT91_CAST(AT91_REG *) 0x400E0334) // (MATRIX) Special Function Register 9 +#define AT91C_MATRIX_MCFG3 (AT91_CAST(AT91_REG *) 0x400E020C) // (MATRIX) Master Configuration Register 3 +#define AT91C_MATRIX_SCFG4 (AT91_CAST(AT91_REG *) 0x400E0250) // (MATRIX) Slave Configuration Register 4 +#define AT91C_MATRIX_MCFG1 (AT91_CAST(AT91_REG *) 0x400E0204) // (MATRIX) Master Configuration Register 1 : ARM S +#define AT91C_MATRIX_SCFG7 (AT91_CAST(AT91_REG *) 0x400E025C) // (MATRIX) Slave Configuration Register 5 +#define AT91C_MATRIX_SFR10 (AT91_CAST(AT91_REG *) 0x400E0338) // (MATRIX) Special Function Register 10 +#define AT91C_MATRIX_SCFG2 (AT91_CAST(AT91_REG *) 0x400E0248) // (MATRIX) Slave Configuration Register 2 +#define AT91C_MATRIX_SFR7 (AT91_CAST(AT91_REG *) 0x400E032C) // (MATRIX) Special Function Register 7 +#define AT91C_MATRIX_IPNAME1 (AT91_CAST(AT91_REG *) 0x400E03F0) // (MATRIX) HMATRIX2 IPNAME1 REGISTER +#define AT91C_MATRIX_MCFG4 (AT91_CAST(AT91_REG *) 0x400E0210) // (MATRIX) Master Configuration Register 4 +#define AT91C_MATRIX_SFR0 (AT91_CAST(AT91_REG *) 0x400E0310) // (MATRIX) Special Function Register 0 +#define AT91C_MATRIX_FEATURES (AT91_CAST(AT91_REG *) 0x400E03F8) // (MATRIX) HMATRIX2 FEATURES REGISTER +#define AT91C_MATRIX_SCFG5 (AT91_CAST(AT91_REG *) 0x400E0254) // (MATRIX) Slave Configuration Register 5 +#define AT91C_MATRIX_MCFG6 (AT91_CAST(AT91_REG *) 0x400E0218) // (MATRIX) Master Configuration Register 6 +#define AT91C_MATRIX_SFR4 (AT91_CAST(AT91_REG *) 0x400E0320) // (MATRIX) Special Function Register 4 +// ========== Register definition for NVIC peripheral ========== +#define AT91C_NVIC_MMAR (AT91_CAST(AT91_REG *) 0xE000ED34) // (NVIC) Mem Manage Address Register +#define AT91C_NVIC_STIR (AT91_CAST(AT91_REG *) 0xE000EF00) // (NVIC) Software Trigger Interrupt Register +#define AT91C_NVIC_MMFR2 (AT91_CAST(AT91_REG *) 0xE000ED58) // (NVIC) Memory Model Feature register2 +#define AT91C_NVIC_CPUID (AT91_CAST(AT91_REG *) 0xE000ED00) // (NVIC) CPUID Base Register +#define AT91C_NVIC_DFSR (AT91_CAST(AT91_REG *) 0xE000ED30) // (NVIC) Debug Fault Status Register +#define AT91C_NVIC_HAND4PR (AT91_CAST(AT91_REG *) 0xE000ED18) // (NVIC) System Handlers 4-7 Priority Register +#define AT91C_NVIC_HFSR (AT91_CAST(AT91_REG *) 0xE000ED2C) // (NVIC) Hard Fault Status Register +#define AT91C_NVIC_PID6 (AT91_CAST(AT91_REG *) 0xE000EFD8) // (NVIC) Peripheral identification register +#define AT91C_NVIC_PFR0 (AT91_CAST(AT91_REG *) 0xE000ED40) // (NVIC) Processor Feature register0 +#define AT91C_NVIC_VTOFFR (AT91_CAST(AT91_REG *) 0xE000ED08) // (NVIC) Vector Table Offset Register +#define AT91C_NVIC_ISPR (AT91_CAST(AT91_REG *) 0xE000E200) // (NVIC) Set Pending Register +#define AT91C_NVIC_PID0 (AT91_CAST(AT91_REG *) 0xE000EFE0) // (NVIC) Peripheral identification register b7:0 +#define AT91C_NVIC_PID7 (AT91_CAST(AT91_REG *) 0xE000EFDC) // (NVIC) Peripheral identification register +#define AT91C_NVIC_STICKRVR (AT91_CAST(AT91_REG *) 0xE000E014) // (NVIC) SysTick Reload Value Register +#define AT91C_NVIC_PID2 (AT91_CAST(AT91_REG *) 0xE000EFE8) // (NVIC) Peripheral identification register b23:16 +#define AT91C_NVIC_ISAR0 (AT91_CAST(AT91_REG *) 0xE000ED60) // (NVIC) ISA Feature register0 +#define AT91C_NVIC_SCR (AT91_CAST(AT91_REG *) 0xE000ED10) // (NVIC) System Control Register +#define AT91C_NVIC_PID4 (AT91_CAST(AT91_REG *) 0xE000EFD0) // (NVIC) Peripheral identification register +#define AT91C_NVIC_ISAR2 (AT91_CAST(AT91_REG *) 0xE000ED68) // (NVIC) ISA Feature register2 +#define AT91C_NVIC_ISER (AT91_CAST(AT91_REG *) 0xE000E100) // (NVIC) Set Enable Register +#define AT91C_NVIC_IPR (AT91_CAST(AT91_REG *) 0xE000E400) // (NVIC) Interrupt Mask Register +#define AT91C_NVIC_AIRCR (AT91_CAST(AT91_REG *) 0xE000ED0C) // (NVIC) Application Interrupt/Reset Control Reg +#define AT91C_NVIC_CID2 (AT91_CAST(AT91_REG *) 0xE000EFF8) // (NVIC) Component identification register b23:16 +#define AT91C_NVIC_ICPR (AT91_CAST(AT91_REG *) 0xE000E280) // (NVIC) Clear Pending Register +#define AT91C_NVIC_CID3 (AT91_CAST(AT91_REG *) 0xE000EFFC) // (NVIC) Component identification register b31:24 +#define AT91C_NVIC_CFSR (AT91_CAST(AT91_REG *) 0xE000ED28) // (NVIC) Configurable Fault Status Register +#define AT91C_NVIC_AFR0 (AT91_CAST(AT91_REG *) 0xE000ED4C) // (NVIC) Auxiliary Feature register0 +#define AT91C_NVIC_ICSR (AT91_CAST(AT91_REG *) 0xE000ED04) // (NVIC) Interrupt Control State Register +#define AT91C_NVIC_CCR (AT91_CAST(AT91_REG *) 0xE000ED14) // (NVIC) Configuration Control Register +#define AT91C_NVIC_CID0 (AT91_CAST(AT91_REG *) 0xE000EFF0) // (NVIC) Component identification register b7:0 +#define AT91C_NVIC_ISAR1 (AT91_CAST(AT91_REG *) 0xE000ED64) // (NVIC) ISA Feature register1 +#define AT91C_NVIC_STICKCVR (AT91_CAST(AT91_REG *) 0xE000E018) // (NVIC) SysTick Current Value Register +#define AT91C_NVIC_STICKCSR (AT91_CAST(AT91_REG *) 0xE000E010) // (NVIC) SysTick Control and Status Register +#define AT91C_NVIC_CID1 (AT91_CAST(AT91_REG *) 0xE000EFF4) // (NVIC) Component identification register b15:8 +#define AT91C_NVIC_DFR0 (AT91_CAST(AT91_REG *) 0xE000ED48) // (NVIC) Debug Feature register0 +#define AT91C_NVIC_MMFR3 (AT91_CAST(AT91_REG *) 0xE000ED5C) // (NVIC) Memory Model Feature register3 +#define AT91C_NVIC_MMFR0 (AT91_CAST(AT91_REG *) 0xE000ED50) // (NVIC) Memory Model Feature register0 +#define AT91C_NVIC_STICKCALVR (AT91_CAST(AT91_REG *) 0xE000E01C) // (NVIC) SysTick Calibration Value Register +#define AT91C_NVIC_PID1 (AT91_CAST(AT91_REG *) 0xE000EFE4) // (NVIC) Peripheral identification register b15:8 +#define AT91C_NVIC_HAND12PR (AT91_CAST(AT91_REG *) 0xE000ED20) // (NVIC) System Handlers 12-15 Priority Register +#define AT91C_NVIC_MMFR1 (AT91_CAST(AT91_REG *) 0xE000ED54) // (NVIC) Memory Model Feature register1 +#define AT91C_NVIC_AFSR (AT91_CAST(AT91_REG *) 0xE000ED3C) // (NVIC) Auxiliary Fault Status Register +#define AT91C_NVIC_HANDCSR (AT91_CAST(AT91_REG *) 0xE000ED24) // (NVIC) System Handler Control and State Register +#define AT91C_NVIC_ISAR4 (AT91_CAST(AT91_REG *) 0xE000ED70) // (NVIC) ISA Feature register4 +#define AT91C_NVIC_ABR (AT91_CAST(AT91_REG *) 0xE000E300) // (NVIC) Active Bit Register +#define AT91C_NVIC_PFR1 (AT91_CAST(AT91_REG *) 0xE000ED44) // (NVIC) Processor Feature register1 +#define AT91C_NVIC_PID5 (AT91_CAST(AT91_REG *) 0xE000EFD4) // (NVIC) Peripheral identification register +#define AT91C_NVIC_ICTR (AT91_CAST(AT91_REG *) 0xE000E004) // (NVIC) Interrupt Control Type Register +#define AT91C_NVIC_ICER (AT91_CAST(AT91_REG *) 0xE000E180) // (NVIC) Clear enable Register +#define AT91C_NVIC_PID3 (AT91_CAST(AT91_REG *) 0xE000EFEC) // (NVIC) Peripheral identification register b31:24 +#define AT91C_NVIC_ISAR3 (AT91_CAST(AT91_REG *) 0xE000ED6C) // (NVIC) ISA Feature register3 +#define AT91C_NVIC_HAND8PR (AT91_CAST(AT91_REG *) 0xE000ED1C) // (NVIC) System Handlers 8-11 Priority Register +#define AT91C_NVIC_BFAR (AT91_CAST(AT91_REG *) 0xE000ED38) // (NVIC) Bus Fault Address Register +// ========== Register definition for MPU peripheral ========== +#define AT91C_MPU_REG_BASE_ADDR3 (AT91_CAST(AT91_REG *) 0xE000EDB4) // (MPU) MPU Region Base Address Register alias 3 +#define AT91C_MPU_REG_NB (AT91_CAST(AT91_REG *) 0xE000ED98) // (MPU) MPU Region Number Register +#define AT91C_MPU_ATTR_SIZE1 (AT91_CAST(AT91_REG *) 0xE000EDA8) // (MPU) MPU Attribute and Size Register alias 1 +#define AT91C_MPU_REG_BASE_ADDR1 (AT91_CAST(AT91_REG *) 0xE000EDA4) // (MPU) MPU Region Base Address Register alias 1 +#define AT91C_MPU_ATTR_SIZE3 (AT91_CAST(AT91_REG *) 0xE000EDB8) // (MPU) MPU Attribute and Size Register alias 3 +#define AT91C_MPU_CTRL (AT91_CAST(AT91_REG *) 0xE000ED94) // (MPU) MPU Control Register +#define AT91C_MPU_ATTR_SIZE2 (AT91_CAST(AT91_REG *) 0xE000EDB0) // (MPU) MPU Attribute and Size Register alias 2 +#define AT91C_MPU_REG_BASE_ADDR (AT91_CAST(AT91_REG *) 0xE000ED9C) // (MPU) MPU Region Base Address Register +#define AT91C_MPU_REG_BASE_ADDR2 (AT91_CAST(AT91_REG *) 0xE000EDAC) // (MPU) MPU Region Base Address Register alias 2 +#define AT91C_MPU_ATTR_SIZE (AT91_CAST(AT91_REG *) 0xE000EDA0) // (MPU) MPU Attribute and Size Register +#define AT91C_MPU_TYPE (AT91_CAST(AT91_REG *) 0xE000ED90) // (MPU) MPU Type Register +// ========== Register definition for CM3 peripheral ========== +#define AT91C_CM3_SHCSR (AT91_CAST(AT91_REG *) 0xE000ED24) // (CM3) System Handler Control and State Register +#define AT91C_CM3_CCR (AT91_CAST(AT91_REG *) 0xE000ED14) // (CM3) Configuration Control Register +#define AT91C_CM3_ICSR (AT91_CAST(AT91_REG *) 0xE000ED04) // (CM3) Interrupt Control State Register +#define AT91C_CM3_CPUID (AT91_CAST(AT91_REG *) 0xE000ED00) // (CM3) CPU ID Base Register +#define AT91C_CM3_SCR (AT91_CAST(AT91_REG *) 0xE000ED10) // (CM3) System Controller Register +#define AT91C_CM3_AIRCR (AT91_CAST(AT91_REG *) 0xE000ED0C) // (CM3) Application Interrupt and Reset Control Register +#define AT91C_CM3_SHPR (AT91_CAST(AT91_REG *) 0xE000ED18) // (CM3) System Handler Priority Register +#define AT91C_CM3_VTOR (AT91_CAST(AT91_REG *) 0xE000ED08) // (CM3) Vector Table Offset Register +// ========== Register definition for PDC_DBGU peripheral ========== +#define AT91C_DBGU_TPR (AT91_CAST(AT91_REG *) 0x400E0708) // (PDC_DBGU) Transmit Pointer Register +#define AT91C_DBGU_PTCR (AT91_CAST(AT91_REG *) 0x400E0720) // (PDC_DBGU) PDC Transfer Control Register +#define AT91C_DBGU_TNCR (AT91_CAST(AT91_REG *) 0x400E071C) // (PDC_DBGU) Transmit Next Counter Register +#define AT91C_DBGU_PTSR (AT91_CAST(AT91_REG *) 0x400E0724) // (PDC_DBGU) PDC Transfer Status Register +#define AT91C_DBGU_RNCR (AT91_CAST(AT91_REG *) 0x400E0714) // (PDC_DBGU) Receive Next Counter Register +#define AT91C_DBGU_RPR (AT91_CAST(AT91_REG *) 0x400E0700) // (PDC_DBGU) Receive Pointer Register +#define AT91C_DBGU_TCR (AT91_CAST(AT91_REG *) 0x400E070C) // (PDC_DBGU) Transmit Counter Register +#define AT91C_DBGU_RNPR (AT91_CAST(AT91_REG *) 0x400E0710) // (PDC_DBGU) Receive Next Pointer Register +#define AT91C_DBGU_TNPR (AT91_CAST(AT91_REG *) 0x400E0718) // (PDC_DBGU) Transmit Next Pointer Register +#define AT91C_DBGU_RCR (AT91_CAST(AT91_REG *) 0x400E0704) // (PDC_DBGU) Receive Counter Register +// ========== Register definition for DBGU peripheral ========== +#define AT91C_DBGU_CR (AT91_CAST(AT91_REG *) 0x400E0600) // (DBGU) Control Register +#define AT91C_DBGU_IDR (AT91_CAST(AT91_REG *) 0x400E060C) // (DBGU) Interrupt Disable Register +#define AT91C_DBGU_CIDR (AT91_CAST(AT91_REG *) 0x400E0740) // (DBGU) Chip ID Register +#define AT91C_DBGU_IPNAME2 (AT91_CAST(AT91_REG *) 0x400E06F4) // (DBGU) DBGU IPNAME2 REGISTER +#define AT91C_DBGU_FEATURES (AT91_CAST(AT91_REG *) 0x400E06F8) // (DBGU) DBGU FEATURES REGISTER +#define AT91C_DBGU_FNTR (AT91_CAST(AT91_REG *) 0x400E0648) // (DBGU) Force NTRST Register +#define AT91C_DBGU_RHR (AT91_CAST(AT91_REG *) 0x400E0618) // (DBGU) Receiver Holding Register +#define AT91C_DBGU_THR (AT91_CAST(AT91_REG *) 0x400E061C) // (DBGU) Transmitter Holding Register +#define AT91C_DBGU_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400E06EC) // (DBGU) DBGU ADDRSIZE REGISTER +#define AT91C_DBGU_MR (AT91_CAST(AT91_REG *) 0x400E0604) // (DBGU) Mode Register +#define AT91C_DBGU_IER (AT91_CAST(AT91_REG *) 0x400E0608) // (DBGU) Interrupt Enable Register +#define AT91C_DBGU_BRGR (AT91_CAST(AT91_REG *) 0x400E0620) // (DBGU) Baud Rate Generator Register +#define AT91C_DBGU_CSR (AT91_CAST(AT91_REG *) 0x400E0614) // (DBGU) Channel Status Register +#define AT91C_DBGU_VER (AT91_CAST(AT91_REG *) 0x400E06FC) // (DBGU) DBGU VERSION REGISTER +#define AT91C_DBGU_IMR (AT91_CAST(AT91_REG *) 0x400E0610) // (DBGU) Interrupt Mask Register +#define AT91C_DBGU_IPNAME1 (AT91_CAST(AT91_REG *) 0x400E06F0) // (DBGU) DBGU IPNAME1 REGISTER +#define AT91C_DBGU_EXID (AT91_CAST(AT91_REG *) 0x400E0744) // (DBGU) Chip ID Extension Register +// ========== Register definition for PIOA peripheral ========== +#define AT91C_PIOA_PDR (AT91_CAST(AT91_REG *) 0x400E0C04) // (PIOA) PIO Disable Register +#define AT91C_PIOA_FRLHSR (AT91_CAST(AT91_REG *) 0x400E0CD8) // (PIOA) Fall/Rise - Low/High Status Register +#define AT91C_PIOA_KIMR (AT91_CAST(AT91_REG *) 0x400E0D38) // (PIOA) Keypad Controller Interrupt Mask Register +#define AT91C_PIOA_LSR (AT91_CAST(AT91_REG *) 0x400E0CC4) // (PIOA) Level Select Register +#define AT91C_PIOA_IFSR (AT91_CAST(AT91_REG *) 0x400E0C28) // (PIOA) Input Filter Status Register +#define AT91C_PIOA_KKRR (AT91_CAST(AT91_REG *) 0x400E0D44) // (PIOA) Keypad Controller Key Release Register +#define AT91C_PIOA_ODR (AT91_CAST(AT91_REG *) 0x400E0C14) // (PIOA) Output Disable Registerr +#define AT91C_PIOA_SCIFSR (AT91_CAST(AT91_REG *) 0x400E0C80) // (PIOA) System Clock Glitch Input Filter Select Register +#define AT91C_PIOA_PER (AT91_CAST(AT91_REG *) 0x400E0C00) // (PIOA) PIO Enable Register +#define AT91C_PIOA_VER (AT91_CAST(AT91_REG *) 0x400E0CFC) // (PIOA) PIO VERSION REGISTER +#define AT91C_PIOA_OWSR (AT91_CAST(AT91_REG *) 0x400E0CA8) // (PIOA) Output Write Status Register +#define AT91C_PIOA_KSR (AT91_CAST(AT91_REG *) 0x400E0D3C) // (PIOA) Keypad Controller Status Register +#define AT91C_PIOA_IMR (AT91_CAST(AT91_REG *) 0x400E0C48) // (PIOA) Interrupt Mask Register +#define AT91C_PIOA_OWDR (AT91_CAST(AT91_REG *) 0x400E0CA4) // (PIOA) Output Write Disable Register +#define AT91C_PIOA_MDSR (AT91_CAST(AT91_REG *) 0x400E0C58) // (PIOA) Multi-driver Status Register +#define AT91C_PIOA_IFDR (AT91_CAST(AT91_REG *) 0x400E0C24) // (PIOA) Input Filter Disable Register +#define AT91C_PIOA_AIMDR (AT91_CAST(AT91_REG *) 0x400E0CB4) // (PIOA) Additional Interrupt Modes Disables Register +#define AT91C_PIOA_CODR (AT91_CAST(AT91_REG *) 0x400E0C34) // (PIOA) Clear Output Data Register +#define AT91C_PIOA_SCDR (AT91_CAST(AT91_REG *) 0x400E0C8C) // (PIOA) Slow Clock Divider Debouncing Register +#define AT91C_PIOA_KIER (AT91_CAST(AT91_REG *) 0x400E0D30) // (PIOA) Keypad Controller Interrupt Enable Register +#define AT91C_PIOA_REHLSR (AT91_CAST(AT91_REG *) 0x400E0CD4) // (PIOA) Rising Edge/ High Level Select Register +#define AT91C_PIOA_ISR (AT91_CAST(AT91_REG *) 0x400E0C4C) // (PIOA) Interrupt Status Register +#define AT91C_PIOA_ESR (AT91_CAST(AT91_REG *) 0x400E0CC0) // (PIOA) Edge Select Register +#define AT91C_PIOA_PPUDR (AT91_CAST(AT91_REG *) 0x400E0C60) // (PIOA) Pull-up Disable Register +#define AT91C_PIOA_MDDR (AT91_CAST(AT91_REG *) 0x400E0C54) // (PIOA) Multi-driver Disable Register +#define AT91C_PIOA_PSR (AT91_CAST(AT91_REG *) 0x400E0C08) // (PIOA) PIO Status Register +#define AT91C_PIOA_PDSR (AT91_CAST(AT91_REG *) 0x400E0C3C) // (PIOA) Pin Data Status Register +#define AT91C_PIOA_IFDGSR (AT91_CAST(AT91_REG *) 0x400E0C88) // (PIOA) Glitch or Debouncing Input Filter Clock Selection Status Register +#define AT91C_PIOA_FELLSR (AT91_CAST(AT91_REG *) 0x400E0CD0) // (PIOA) Falling Edge/Low Level Select Register +#define AT91C_PIOA_PPUSR (AT91_CAST(AT91_REG *) 0x400E0C68) // (PIOA) Pull-up Status Register +#define AT91C_PIOA_OER (AT91_CAST(AT91_REG *) 0x400E0C10) // (PIOA) Output Enable Register +#define AT91C_PIOA_OSR (AT91_CAST(AT91_REG *) 0x400E0C18) // (PIOA) Output Status Register +#define AT91C_PIOA_KKPR (AT91_CAST(AT91_REG *) 0x400E0D40) // (PIOA) Keypad Controller Key Press Register +#define AT91C_PIOA_AIMMR (AT91_CAST(AT91_REG *) 0x400E0CB8) // (PIOA) Additional Interrupt Modes Mask Register +#define AT91C_PIOA_KRCR (AT91_CAST(AT91_REG *) 0x400E0D24) // (PIOA) Keypad Controller Row Column Register +#define AT91C_PIOA_IER (AT91_CAST(AT91_REG *) 0x400E0C40) // (PIOA) Interrupt Enable Register +#define AT91C_PIOA_KER (AT91_CAST(AT91_REG *) 0x400E0D20) // (PIOA) Keypad Controller Enable Register +#define AT91C_PIOA_PPUER (AT91_CAST(AT91_REG *) 0x400E0C64) // (PIOA) Pull-up Enable Register +#define AT91C_PIOA_KIDR (AT91_CAST(AT91_REG *) 0x400E0D34) // (PIOA) Keypad Controller Interrupt Disable Register +#define AT91C_PIOA_ABSR (AT91_CAST(AT91_REG *) 0x400E0C70) // (PIOA) Peripheral AB Select Register +#define AT91C_PIOA_LOCKSR (AT91_CAST(AT91_REG *) 0x400E0CE0) // (PIOA) Lock Status Register +#define AT91C_PIOA_DIFSR (AT91_CAST(AT91_REG *) 0x400E0C84) // (PIOA) Debouncing Input Filter Select Register +#define AT91C_PIOA_MDER (AT91_CAST(AT91_REG *) 0x400E0C50) // (PIOA) Multi-driver Enable Register +#define AT91C_PIOA_AIMER (AT91_CAST(AT91_REG *) 0x400E0CB0) // (PIOA) Additional Interrupt Modes Enable Register +#define AT91C_PIOA_ELSR (AT91_CAST(AT91_REG *) 0x400E0CC8) // (PIOA) Edge/Level Status Register +#define AT91C_PIOA_IFER (AT91_CAST(AT91_REG *) 0x400E0C20) // (PIOA) Input Filter Enable Register +#define AT91C_PIOA_KDR (AT91_CAST(AT91_REG *) 0x400E0D28) // (PIOA) Keypad Controller Debouncing Register +#define AT91C_PIOA_IDR (AT91_CAST(AT91_REG *) 0x400E0C44) // (PIOA) Interrupt Disable Register +#define AT91C_PIOA_OWER (AT91_CAST(AT91_REG *) 0x400E0CA0) // (PIOA) Output Write Enable Register +#define AT91C_PIOA_ODSR (AT91_CAST(AT91_REG *) 0x400E0C38) // (PIOA) Output Data Status Register +#define AT91C_PIOA_SODR (AT91_CAST(AT91_REG *) 0x400E0C30) // (PIOA) Set Output Data Register +// ========== Register definition for PIOB peripheral ========== +#define AT91C_PIOB_KIDR (AT91_CAST(AT91_REG *) 0x400E0F34) // (PIOB) Keypad Controller Interrupt Disable Register +#define AT91C_PIOB_OWSR (AT91_CAST(AT91_REG *) 0x400E0EA8) // (PIOB) Output Write Status Register +#define AT91C_PIOB_PSR (AT91_CAST(AT91_REG *) 0x400E0E08) // (PIOB) PIO Status Register +#define AT91C_PIOB_MDER (AT91_CAST(AT91_REG *) 0x400E0E50) // (PIOB) Multi-driver Enable Register +#define AT91C_PIOB_ODR (AT91_CAST(AT91_REG *) 0x400E0E14) // (PIOB) Output Disable Registerr +#define AT91C_PIOB_IDR (AT91_CAST(AT91_REG *) 0x400E0E44) // (PIOB) Interrupt Disable Register +#define AT91C_PIOB_AIMER (AT91_CAST(AT91_REG *) 0x400E0EB0) // (PIOB) Additional Interrupt Modes Enable Register +#define AT91C_PIOB_DIFSR (AT91_CAST(AT91_REG *) 0x400E0E84) // (PIOB) Debouncing Input Filter Select Register +#define AT91C_PIOB_PDR (AT91_CAST(AT91_REG *) 0x400E0E04) // (PIOB) PIO Disable Register +#define AT91C_PIOB_REHLSR (AT91_CAST(AT91_REG *) 0x400E0ED4) // (PIOB) Rising Edge/ High Level Select Register +#define AT91C_PIOB_PDSR (AT91_CAST(AT91_REG *) 0x400E0E3C) // (PIOB) Pin Data Status Register +#define AT91C_PIOB_PPUDR (AT91_CAST(AT91_REG *) 0x400E0E60) // (PIOB) Pull-up Disable Register +#define AT91C_PIOB_LSR (AT91_CAST(AT91_REG *) 0x400E0EC4) // (PIOB) Level Select Register +#define AT91C_PIOB_OWDR (AT91_CAST(AT91_REG *) 0x400E0EA4) // (PIOB) Output Write Disable Register +#define AT91C_PIOB_FELLSR (AT91_CAST(AT91_REG *) 0x400E0ED0) // (PIOB) Falling Edge/Low Level Select Register +#define AT91C_PIOB_IFER (AT91_CAST(AT91_REG *) 0x400E0E20) // (PIOB) Input Filter Enable Register +#define AT91C_PIOB_ABSR (AT91_CAST(AT91_REG *) 0x400E0E70) // (PIOB) Peripheral AB Select Register +#define AT91C_PIOB_KIMR (AT91_CAST(AT91_REG *) 0x400E0F38) // (PIOB) Keypad Controller Interrupt Mask Register +#define AT91C_PIOB_KKPR (AT91_CAST(AT91_REG *) 0x400E0F40) // (PIOB) Keypad Controller Key Press Register +#define AT91C_PIOB_FRLHSR (AT91_CAST(AT91_REG *) 0x400E0ED8) // (PIOB) Fall/Rise - Low/High Status Register +#define AT91C_PIOB_AIMDR (AT91_CAST(AT91_REG *) 0x400E0EB4) // (PIOB) Additional Interrupt Modes Disables Register +#define AT91C_PIOB_SCIFSR (AT91_CAST(AT91_REG *) 0x400E0E80) // (PIOB) System Clock Glitch Input Filter Select Register +#define AT91C_PIOB_VER (AT91_CAST(AT91_REG *) 0x400E0EFC) // (PIOB) PIO VERSION REGISTER +#define AT91C_PIOB_PER (AT91_CAST(AT91_REG *) 0x400E0E00) // (PIOB) PIO Enable Register +#define AT91C_PIOB_ELSR (AT91_CAST(AT91_REG *) 0x400E0EC8) // (PIOB) Edge/Level Status Register +#define AT91C_PIOB_IMR (AT91_CAST(AT91_REG *) 0x400E0E48) // (PIOB) Interrupt Mask Register +#define AT91C_PIOB_PPUSR (AT91_CAST(AT91_REG *) 0x400E0E68) // (PIOB) Pull-up Status Register +#define AT91C_PIOB_SCDR (AT91_CAST(AT91_REG *) 0x400E0E8C) // (PIOB) Slow Clock Divider Debouncing Register +#define AT91C_PIOB_KSR (AT91_CAST(AT91_REG *) 0x400E0F3C) // (PIOB) Keypad Controller Status Register +#define AT91C_PIOB_IFDGSR (AT91_CAST(AT91_REG *) 0x400E0E88) // (PIOB) Glitch or Debouncing Input Filter Clock Selection Status Register +#define AT91C_PIOB_ESR (AT91_CAST(AT91_REG *) 0x400E0EC0) // (PIOB) Edge Select Register +#define AT91C_PIOB_ODSR (AT91_CAST(AT91_REG *) 0x400E0E38) // (PIOB) Output Data Status Register +#define AT91C_PIOB_IFDR (AT91_CAST(AT91_REG *) 0x400E0E24) // (PIOB) Input Filter Disable Register +#define AT91C_PIOB_SODR (AT91_CAST(AT91_REG *) 0x400E0E30) // (PIOB) Set Output Data Register +#define AT91C_PIOB_IER (AT91_CAST(AT91_REG *) 0x400E0E40) // (PIOB) Interrupt Enable Register +#define AT91C_PIOB_MDSR (AT91_CAST(AT91_REG *) 0x400E0E58) // (PIOB) Multi-driver Status Register +#define AT91C_PIOB_ISR (AT91_CAST(AT91_REG *) 0x400E0E4C) // (PIOB) Interrupt Status Register +#define AT91C_PIOB_IFSR (AT91_CAST(AT91_REG *) 0x400E0E28) // (PIOB) Input Filter Status Register +#define AT91C_PIOB_KER (AT91_CAST(AT91_REG *) 0x400E0F20) // (PIOB) Keypad Controller Enable Register +#define AT91C_PIOB_KKRR (AT91_CAST(AT91_REG *) 0x400E0F44) // (PIOB) Keypad Controller Key Release Register +#define AT91C_PIOB_PPUER (AT91_CAST(AT91_REG *) 0x400E0E64) // (PIOB) Pull-up Enable Register +#define AT91C_PIOB_LOCKSR (AT91_CAST(AT91_REG *) 0x400E0EE0) // (PIOB) Lock Status Register +#define AT91C_PIOB_OWER (AT91_CAST(AT91_REG *) 0x400E0EA0) // (PIOB) Output Write Enable Register +#define AT91C_PIOB_KIER (AT91_CAST(AT91_REG *) 0x400E0F30) // (PIOB) Keypad Controller Interrupt Enable Register +#define AT91C_PIOB_MDDR (AT91_CAST(AT91_REG *) 0x400E0E54) // (PIOB) Multi-driver Disable Register +#define AT91C_PIOB_KRCR (AT91_CAST(AT91_REG *) 0x400E0F24) // (PIOB) Keypad Controller Row Column Register +#define AT91C_PIOB_CODR (AT91_CAST(AT91_REG *) 0x400E0E34) // (PIOB) Clear Output Data Register +#define AT91C_PIOB_KDR (AT91_CAST(AT91_REG *) 0x400E0F28) // (PIOB) Keypad Controller Debouncing Register +#define AT91C_PIOB_AIMMR (AT91_CAST(AT91_REG *) 0x400E0EB8) // (PIOB) Additional Interrupt Modes Mask Register +#define AT91C_PIOB_OER (AT91_CAST(AT91_REG *) 0x400E0E10) // (PIOB) Output Enable Register +#define AT91C_PIOB_OSR (AT91_CAST(AT91_REG *) 0x400E0E18) // (PIOB) Output Status Register +// ========== Register definition for PIOC peripheral ========== +#define AT91C_PIOC_FELLSR (AT91_CAST(AT91_REG *) 0x400E10D0) // (PIOC) Falling Edge/Low Level Select Register +#define AT91C_PIOC_FRLHSR (AT91_CAST(AT91_REG *) 0x400E10D8) // (PIOC) Fall/Rise - Low/High Status Register +#define AT91C_PIOC_MDDR (AT91_CAST(AT91_REG *) 0x400E1054) // (PIOC) Multi-driver Disable Register +#define AT91C_PIOC_IFDGSR (AT91_CAST(AT91_REG *) 0x400E1088) // (PIOC) Glitch or Debouncing Input Filter Clock Selection Status Register +#define AT91C_PIOC_ABSR (AT91_CAST(AT91_REG *) 0x400E1070) // (PIOC) Peripheral AB Select Register +#define AT91C_PIOC_KIMR (AT91_CAST(AT91_REG *) 0x400E1138) // (PIOC) Keypad Controller Interrupt Mask Register +#define AT91C_PIOC_KRCR (AT91_CAST(AT91_REG *) 0x400E1124) // (PIOC) Keypad Controller Row Column Register +#define AT91C_PIOC_ODSR (AT91_CAST(AT91_REG *) 0x400E1038) // (PIOC) Output Data Status Register +#define AT91C_PIOC_OSR (AT91_CAST(AT91_REG *) 0x400E1018) // (PIOC) Output Status Register +#define AT91C_PIOC_IFER (AT91_CAST(AT91_REG *) 0x400E1020) // (PIOC) Input Filter Enable Register +#define AT91C_PIOC_KKPR (AT91_CAST(AT91_REG *) 0x400E1140) // (PIOC) Keypad Controller Key Press Register +#define AT91C_PIOC_MDSR (AT91_CAST(AT91_REG *) 0x400E1058) // (PIOC) Multi-driver Status Register +#define AT91C_PIOC_IFDR (AT91_CAST(AT91_REG *) 0x400E1024) // (PIOC) Input Filter Disable Register +#define AT91C_PIOC_MDER (AT91_CAST(AT91_REG *) 0x400E1050) // (PIOC) Multi-driver Enable Register +#define AT91C_PIOC_SCDR (AT91_CAST(AT91_REG *) 0x400E108C) // (PIOC) Slow Clock Divider Debouncing Register +#define AT91C_PIOC_SCIFSR (AT91_CAST(AT91_REG *) 0x400E1080) // (PIOC) System Clock Glitch Input Filter Select Register +#define AT91C_PIOC_IER (AT91_CAST(AT91_REG *) 0x400E1040) // (PIOC) Interrupt Enable Register +#define AT91C_PIOC_KDR (AT91_CAST(AT91_REG *) 0x400E1128) // (PIOC) Keypad Controller Debouncing Register +#define AT91C_PIOC_OWDR (AT91_CAST(AT91_REG *) 0x400E10A4) // (PIOC) Output Write Disable Register +#define AT91C_PIOC_IFSR (AT91_CAST(AT91_REG *) 0x400E1028) // (PIOC) Input Filter Status Register +#define AT91C_PIOC_ISR (AT91_CAST(AT91_REG *) 0x400E104C) // (PIOC) Interrupt Status Register +#define AT91C_PIOC_PPUDR (AT91_CAST(AT91_REG *) 0x400E1060) // (PIOC) Pull-up Disable Register +#define AT91C_PIOC_PDSR (AT91_CAST(AT91_REG *) 0x400E103C) // (PIOC) Pin Data Status Register +#define AT91C_PIOC_KKRR (AT91_CAST(AT91_REG *) 0x400E1144) // (PIOC) Keypad Controller Key Release Register +#define AT91C_PIOC_AIMDR (AT91_CAST(AT91_REG *) 0x400E10B4) // (PIOC) Additional Interrupt Modes Disables Register +#define AT91C_PIOC_LSR (AT91_CAST(AT91_REG *) 0x400E10C4) // (PIOC) Level Select Register +#define AT91C_PIOC_PPUER (AT91_CAST(AT91_REG *) 0x400E1064) // (PIOC) Pull-up Enable Register +#define AT91C_PIOC_AIMER (AT91_CAST(AT91_REG *) 0x400E10B0) // (PIOC) Additional Interrupt Modes Enable Register +#define AT91C_PIOC_OER (AT91_CAST(AT91_REG *) 0x400E1010) // (PIOC) Output Enable Register +#define AT91C_PIOC_CODR (AT91_CAST(AT91_REG *) 0x400E1034) // (PIOC) Clear Output Data Register +#define AT91C_PIOC_AIMMR (AT91_CAST(AT91_REG *) 0x400E10B8) // (PIOC) Additional Interrupt Modes Mask Register +#define AT91C_PIOC_OWER (AT91_CAST(AT91_REG *) 0x400E10A0) // (PIOC) Output Write Enable Register +#define AT91C_PIOC_VER (AT91_CAST(AT91_REG *) 0x400E10FC) // (PIOC) PIO VERSION REGISTER +#define AT91C_PIOC_IMR (AT91_CAST(AT91_REG *) 0x400E1048) // (PIOC) Interrupt Mask Register +#define AT91C_PIOC_PPUSR (AT91_CAST(AT91_REG *) 0x400E1068) // (PIOC) Pull-up Status Register +#define AT91C_PIOC_IDR (AT91_CAST(AT91_REG *) 0x400E1044) // (PIOC) Interrupt Disable Register +#define AT91C_PIOC_DIFSR (AT91_CAST(AT91_REG *) 0x400E1084) // (PIOC) Debouncing Input Filter Select Register +#define AT91C_PIOC_KIDR (AT91_CAST(AT91_REG *) 0x400E1134) // (PIOC) Keypad Controller Interrupt Disable Register +#define AT91C_PIOC_KSR (AT91_CAST(AT91_REG *) 0x400E113C) // (PIOC) Keypad Controller Status Register +#define AT91C_PIOC_REHLSR (AT91_CAST(AT91_REG *) 0x400E10D4) // (PIOC) Rising Edge/ High Level Select Register +#define AT91C_PIOC_ESR (AT91_CAST(AT91_REG *) 0x400E10C0) // (PIOC) Edge Select Register +#define AT91C_PIOC_KIER (AT91_CAST(AT91_REG *) 0x400E1130) // (PIOC) Keypad Controller Interrupt Enable Register +#define AT91C_PIOC_ELSR (AT91_CAST(AT91_REG *) 0x400E10C8) // (PIOC) Edge/Level Status Register +#define AT91C_PIOC_SODR (AT91_CAST(AT91_REG *) 0x400E1030) // (PIOC) Set Output Data Register +#define AT91C_PIOC_PSR (AT91_CAST(AT91_REG *) 0x400E1008) // (PIOC) PIO Status Register +#define AT91C_PIOC_KER (AT91_CAST(AT91_REG *) 0x400E1120) // (PIOC) Keypad Controller Enable Register +#define AT91C_PIOC_ODR (AT91_CAST(AT91_REG *) 0x400E1014) // (PIOC) Output Disable Registerr +#define AT91C_PIOC_OWSR (AT91_CAST(AT91_REG *) 0x400E10A8) // (PIOC) Output Write Status Register +#define AT91C_PIOC_PDR (AT91_CAST(AT91_REG *) 0x400E1004) // (PIOC) PIO Disable Register +#define AT91C_PIOC_LOCKSR (AT91_CAST(AT91_REG *) 0x400E10E0) // (PIOC) Lock Status Register +#define AT91C_PIOC_PER (AT91_CAST(AT91_REG *) 0x400E1000) // (PIOC) PIO Enable Register +// ========== Register definition for PMC peripheral ========== +#define AT91C_PMC_PLLAR (AT91_CAST(AT91_REG *) 0x400E0428) // (PMC) PLL Register +#define AT91C_PMC_UCKR (AT91_CAST(AT91_REG *) 0x400E041C) // (PMC) UTMI Clock Configuration Register +#define AT91C_PMC_FSMR (AT91_CAST(AT91_REG *) 0x400E0470) // (PMC) Fast Startup Mode Register +#define AT91C_PMC_MCKR (AT91_CAST(AT91_REG *) 0x400E0430) // (PMC) Master Clock Register +#define AT91C_PMC_SCER (AT91_CAST(AT91_REG *) 0x400E0400) // (PMC) System Clock Enable Register +#define AT91C_PMC_PCSR (AT91_CAST(AT91_REG *) 0x400E0418) // (PMC) Peripheral Clock Status Register +#define AT91C_PMC_MCFR (AT91_CAST(AT91_REG *) 0x400E0424) // (PMC) Main Clock Frequency Register +#define AT91C_PMC_FOCR (AT91_CAST(AT91_REG *) 0x400E0478) // (PMC) Fault Output Clear Register +#define AT91C_PMC_FSPR (AT91_CAST(AT91_REG *) 0x400E0474) // (PMC) Fast Startup Polarity Register +#define AT91C_PMC_SCSR (AT91_CAST(AT91_REG *) 0x400E0408) // (PMC) System Clock Status Register +#define AT91C_PMC_IDR (AT91_CAST(AT91_REG *) 0x400E0464) // (PMC) Interrupt Disable Register +#define AT91C_PMC_VER (AT91_CAST(AT91_REG *) 0x400E04FC) // (PMC) APMC VERSION REGISTER +#define AT91C_PMC_IMR (AT91_CAST(AT91_REG *) 0x400E046C) // (PMC) Interrupt Mask Register +#define AT91C_PMC_IPNAME2 (AT91_CAST(AT91_REG *) 0x400E04F4) // (PMC) PMC IPNAME2 REGISTER +#define AT91C_PMC_SCDR (AT91_CAST(AT91_REG *) 0x400E0404) // (PMC) System Clock Disable Register +#define AT91C_PMC_PCKR (AT91_CAST(AT91_REG *) 0x400E0440) // (PMC) Programmable Clock Register +#define AT91C_PMC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400E04EC) // (PMC) PMC ADDRSIZE REGISTER +#define AT91C_PMC_PCDR (AT91_CAST(AT91_REG *) 0x400E0414) // (PMC) Peripheral Clock Disable Register +#define AT91C_PMC_MOR (AT91_CAST(AT91_REG *) 0x400E0420) // (PMC) Main Oscillator Register +#define AT91C_PMC_SR (AT91_CAST(AT91_REG *) 0x400E0468) // (PMC) Status Register +#define AT91C_PMC_IER (AT91_CAST(AT91_REG *) 0x400E0460) // (PMC) Interrupt Enable Register +#define AT91C_PMC_IPNAME1 (AT91_CAST(AT91_REG *) 0x400E04F0) // (PMC) PMC IPNAME1 REGISTER +#define AT91C_PMC_PCER (AT91_CAST(AT91_REG *) 0x400E0410) // (PMC) Peripheral Clock Enable Register +#define AT91C_PMC_FEATURES (AT91_CAST(AT91_REG *) 0x400E04F8) // (PMC) PMC FEATURES REGISTER +// ========== Register definition for CKGR peripheral ========== +#define AT91C_CKGR_PLLAR (AT91_CAST(AT91_REG *) 0x400E0428) // (CKGR) PLL Register +#define AT91C_CKGR_UCKR (AT91_CAST(AT91_REG *) 0x400E041C) // (CKGR) UTMI Clock Configuration Register +#define AT91C_CKGR_MOR (AT91_CAST(AT91_REG *) 0x400E0420) // (CKGR) Main Oscillator Register +#define AT91C_CKGR_MCFR (AT91_CAST(AT91_REG *) 0x400E0424) // (CKGR) Main Clock Frequency Register +// ========== Register definition for RSTC peripheral ========== +#define AT91C_RSTC_VER (AT91_CAST(AT91_REG *) 0x400E12FC) // (RSTC) Version Register +#define AT91C_RSTC_RCR (AT91_CAST(AT91_REG *) 0x400E1200) // (RSTC) Reset Control Register +#define AT91C_RSTC_RMR (AT91_CAST(AT91_REG *) 0x400E1208) // (RSTC) Reset Mode Register +#define AT91C_RSTC_RSR (AT91_CAST(AT91_REG *) 0x400E1204) // (RSTC) Reset Status Register +// ========== Register definition for SUPC peripheral ========== +#define AT91C_SUPC_WUIR (AT91_CAST(AT91_REG *) 0x400E1220) // (SUPC) Wake Up Inputs Register +#define AT91C_SUPC_CR (AT91_CAST(AT91_REG *) 0x400E1210) // (SUPC) Control Register +#define AT91C_SUPC_MR (AT91_CAST(AT91_REG *) 0x400E1218) // (SUPC) Mode Register +#define AT91C_SUPC_FWUTR (AT91_CAST(AT91_REG *) 0x400E1228) // (SUPC) Flash Wake-up Timer Register +#define AT91C_SUPC_SR (AT91_CAST(AT91_REG *) 0x400E1224) // (SUPC) Status Register +#define AT91C_SUPC_WUMR (AT91_CAST(AT91_REG *) 0x400E121C) // (SUPC) Wake Up Mode Register +#define AT91C_SUPC_BOMR (AT91_CAST(AT91_REG *) 0x400E1214) // (SUPC) Brown Out Mode Register +// ========== Register definition for RTTC peripheral ========== +#define AT91C_RTTC_RTVR (AT91_CAST(AT91_REG *) 0x400E1238) // (RTTC) Real-time Value Register +#define AT91C_RTTC_RTAR (AT91_CAST(AT91_REG *) 0x400E1234) // (RTTC) Real-time Alarm Register +#define AT91C_RTTC_RTMR (AT91_CAST(AT91_REG *) 0x400E1230) // (RTTC) Real-time Mode Register +#define AT91C_RTTC_RTSR (AT91_CAST(AT91_REG *) 0x400E123C) // (RTTC) Real-time Status Register +// ========== Register definition for WDTC peripheral ========== +#define AT91C_WDTC_WDSR (AT91_CAST(AT91_REG *) 0x400E1258) // (WDTC) Watchdog Status Register +#define AT91C_WDTC_WDMR (AT91_CAST(AT91_REG *) 0x400E1254) // (WDTC) Watchdog Mode Register +#define AT91C_WDTC_WDCR (AT91_CAST(AT91_REG *) 0x400E1250) // (WDTC) Watchdog Control Register +// ========== Register definition for RTC peripheral ========== +#define AT91C_RTC_IMR (AT91_CAST(AT91_REG *) 0x400E1288) // (RTC) Interrupt Mask Register +#define AT91C_RTC_SCCR (AT91_CAST(AT91_REG *) 0x400E127C) // (RTC) Status Clear Command Register +#define AT91C_RTC_CALR (AT91_CAST(AT91_REG *) 0x400E126C) // (RTC) Calendar Register +#define AT91C_RTC_MR (AT91_CAST(AT91_REG *) 0x400E1264) // (RTC) Mode Register +#define AT91C_RTC_TIMR (AT91_CAST(AT91_REG *) 0x400E1268) // (RTC) Time Register +#define AT91C_RTC_CALALR (AT91_CAST(AT91_REG *) 0x400E1274) // (RTC) Calendar Alarm Register +#define AT91C_RTC_VER (AT91_CAST(AT91_REG *) 0x400E128C) // (RTC) Valid Entry Register +#define AT91C_RTC_CR (AT91_CAST(AT91_REG *) 0x400E1260) // (RTC) Control Register +#define AT91C_RTC_IDR (AT91_CAST(AT91_REG *) 0x400E1284) // (RTC) Interrupt Disable Register +#define AT91C_RTC_TIMALR (AT91_CAST(AT91_REG *) 0x400E1270) // (RTC) Time Alarm Register +#define AT91C_RTC_IER (AT91_CAST(AT91_REG *) 0x400E1280) // (RTC) Interrupt Enable Register +#define AT91C_RTC_SR (AT91_CAST(AT91_REG *) 0x400E1278) // (RTC) Status Register +// ========== Register definition for ADC0 peripheral ========== +#define AT91C_ADC0_CDR4 (AT91_CAST(AT91_REG *) 0x400A8040) // (ADC0) ADC Channel Data Register 4 +#define AT91C_ADC0_CDR2 (AT91_CAST(AT91_REG *) 0x400A8038) // (ADC0) ADC Channel Data Register 2 +#define AT91C_ADC0_CHER (AT91_CAST(AT91_REG *) 0x400A8010) // (ADC0) ADC Channel Enable Register +#define AT91C_ADC0_SR (AT91_CAST(AT91_REG *) 0x400A801C) // (ADC0) ADC Status Register +#define AT91C_ADC0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400A80F0) // (ADC0) ADC IPNAME1 REGISTER +#define AT91C_ADC0_IER (AT91_CAST(AT91_REG *) 0x400A8024) // (ADC0) ADC Interrupt Enable Register +#define AT91C_ADC0_CR (AT91_CAST(AT91_REG *) 0x400A8000) // (ADC0) ADC Control Register +#define AT91C_ADC0_CDR6 (AT91_CAST(AT91_REG *) 0x400A8048) // (ADC0) ADC Channel Data Register 6 +#define AT91C_ADC0_CHDR (AT91_CAST(AT91_REG *) 0x400A8014) // (ADC0) ADC Channel Disable Register +#define AT91C_ADC0_CDR3 (AT91_CAST(AT91_REG *) 0x400A803C) // (ADC0) ADC Channel Data Register 3 +#define AT91C_ADC0_ACR (AT91_CAST(AT91_REG *) 0x400A8064) // (ADC0) Analog Control Register +#define AT91C_ADC0_IDR (AT91_CAST(AT91_REG *) 0x400A8028) // (ADC0) ADC Interrupt Disable Register +#define AT91C_ADC0_VER (AT91_CAST(AT91_REG *) 0x400A80FC) // (ADC0) ADC VERSION REGISTER +#define AT91C_ADC0_CDR7 (AT91_CAST(AT91_REG *) 0x400A804C) // (ADC0) ADC Channel Data Register 7 +#define AT91C_ADC0_CHSR (AT91_CAST(AT91_REG *) 0x400A8018) // (ADC0) ADC Channel Status Register +#define AT91C_ADC0_CDR5 (AT91_CAST(AT91_REG *) 0x400A8044) // (ADC0) ADC Channel Data Register 5 +#define AT91C_ADC0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400A80F4) // (ADC0) ADC IPNAME2 REGISTER +#define AT91C_ADC0_MR (AT91_CAST(AT91_REG *) 0x400A8004) // (ADC0) ADC Mode Register +#define AT91C_ADC0_FEATURES (AT91_CAST(AT91_REG *) 0x400A80F8) // (ADC0) ADC FEATURES REGISTER +#define AT91C_ADC0_EMR (AT91_CAST(AT91_REG *) 0x400A8068) // (ADC0) Extended Mode Register +#define AT91C_ADC0_CDR0 (AT91_CAST(AT91_REG *) 0x400A8030) // (ADC0) ADC Channel Data Register 0 +#define AT91C_ADC0_LCDR (AT91_CAST(AT91_REG *) 0x400A8020) // (ADC0) ADC Last Converted Data Register +#define AT91C_ADC0_IMR (AT91_CAST(AT91_REG *) 0x400A802C) // (ADC0) ADC Interrupt Mask Register +#define AT91C_ADC0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400A80EC) // (ADC0) ADC ADDRSIZE REGISTER +#define AT91C_ADC0_CDR1 (AT91_CAST(AT91_REG *) 0x400A8034) // (ADC0) ADC Channel Data Register 1 +// ========== Register definition for ADC1 peripheral ========== +#define AT91C_ADC1_IPNAME2 (AT91_CAST(AT91_REG *) 0x400AC0F4) // (ADC1) ADC IPNAME2 REGISTER +#define AT91C_ADC1_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400AC0EC) // (ADC1) ADC ADDRSIZE REGISTER +#define AT91C_ADC1_IDR (AT91_CAST(AT91_REG *) 0x400AC028) // (ADC1) ADC Interrupt Disable Register +#define AT91C_ADC1_CHSR (AT91_CAST(AT91_REG *) 0x400AC018) // (ADC1) ADC Channel Status Register +#define AT91C_ADC1_FEATURES (AT91_CAST(AT91_REG *) 0x400AC0F8) // (ADC1) ADC FEATURES REGISTER +#define AT91C_ADC1_CDR0 (AT91_CAST(AT91_REG *) 0x400AC030) // (ADC1) ADC Channel Data Register 0 +#define AT91C_ADC1_LCDR (AT91_CAST(AT91_REG *) 0x400AC020) // (ADC1) ADC Last Converted Data Register +#define AT91C_ADC1_EMR (AT91_CAST(AT91_REG *) 0x400AC068) // (ADC1) Extended Mode Register +#define AT91C_ADC1_CDR3 (AT91_CAST(AT91_REG *) 0x400AC03C) // (ADC1) ADC Channel Data Register 3 +#define AT91C_ADC1_CDR7 (AT91_CAST(AT91_REG *) 0x400AC04C) // (ADC1) ADC Channel Data Register 7 +#define AT91C_ADC1_SR (AT91_CAST(AT91_REG *) 0x400AC01C) // (ADC1) ADC Status Register +#define AT91C_ADC1_ACR (AT91_CAST(AT91_REG *) 0x400AC064) // (ADC1) Analog Control Register +#define AT91C_ADC1_CDR5 (AT91_CAST(AT91_REG *) 0x400AC044) // (ADC1) ADC Channel Data Register 5 +#define AT91C_ADC1_IPNAME1 (AT91_CAST(AT91_REG *) 0x400AC0F0) // (ADC1) ADC IPNAME1 REGISTER +#define AT91C_ADC1_CDR6 (AT91_CAST(AT91_REG *) 0x400AC048) // (ADC1) ADC Channel Data Register 6 +#define AT91C_ADC1_MR (AT91_CAST(AT91_REG *) 0x400AC004) // (ADC1) ADC Mode Register +#define AT91C_ADC1_CDR1 (AT91_CAST(AT91_REG *) 0x400AC034) // (ADC1) ADC Channel Data Register 1 +#define AT91C_ADC1_CDR2 (AT91_CAST(AT91_REG *) 0x400AC038) // (ADC1) ADC Channel Data Register 2 +#define AT91C_ADC1_CDR4 (AT91_CAST(AT91_REG *) 0x400AC040) // (ADC1) ADC Channel Data Register 4 +#define AT91C_ADC1_CHER (AT91_CAST(AT91_REG *) 0x400AC010) // (ADC1) ADC Channel Enable Register +#define AT91C_ADC1_VER (AT91_CAST(AT91_REG *) 0x400AC0FC) // (ADC1) ADC VERSION REGISTER +#define AT91C_ADC1_CHDR (AT91_CAST(AT91_REG *) 0x400AC014) // (ADC1) ADC Channel Disable Register +#define AT91C_ADC1_CR (AT91_CAST(AT91_REG *) 0x400AC000) // (ADC1) ADC Control Register +#define AT91C_ADC1_IMR (AT91_CAST(AT91_REG *) 0x400AC02C) // (ADC1) ADC Interrupt Mask Register +#define AT91C_ADC1_IER (AT91_CAST(AT91_REG *) 0x400AC024) // (ADC1) ADC Interrupt Enable Register +// ========== Register definition for TC0 peripheral ========== +#define AT91C_TC0_IER (AT91_CAST(AT91_REG *) 0x40080024) // (TC0) Interrupt Enable Register +#define AT91C_TC0_CV (AT91_CAST(AT91_REG *) 0x40080010) // (TC0) Counter Value +#define AT91C_TC0_RA (AT91_CAST(AT91_REG *) 0x40080014) // (TC0) Register A +#define AT91C_TC0_RB (AT91_CAST(AT91_REG *) 0x40080018) // (TC0) Register B +#define AT91C_TC0_IDR (AT91_CAST(AT91_REG *) 0x40080028) // (TC0) Interrupt Disable Register +#define AT91C_TC0_SR (AT91_CAST(AT91_REG *) 0x40080020) // (TC0) Status Register +#define AT91C_TC0_IMR (AT91_CAST(AT91_REG *) 0x4008002C) // (TC0) Interrupt Mask Register +#define AT91C_TC0_CMR (AT91_CAST(AT91_REG *) 0x40080004) // (TC0) Channel Mode Register (Capture Mode / Waveform Mode) +#define AT91C_TC0_RC (AT91_CAST(AT91_REG *) 0x4008001C) // (TC0) Register C +#define AT91C_TC0_CCR (AT91_CAST(AT91_REG *) 0x40080000) // (TC0) Channel Control Register +// ========== Register definition for TC1 peripheral ========== +#define AT91C_TC1_SR (AT91_CAST(AT91_REG *) 0x40080060) // (TC1) Status Register +#define AT91C_TC1_RA (AT91_CAST(AT91_REG *) 0x40080054) // (TC1) Register A +#define AT91C_TC1_IER (AT91_CAST(AT91_REG *) 0x40080064) // (TC1) Interrupt Enable Register +#define AT91C_TC1_RB (AT91_CAST(AT91_REG *) 0x40080058) // (TC1) Register B +#define AT91C_TC1_IDR (AT91_CAST(AT91_REG *) 0x40080068) // (TC1) Interrupt Disable Register +#define AT91C_TC1_CCR (AT91_CAST(AT91_REG *) 0x40080040) // (TC1) Channel Control Register +#define AT91C_TC1_IMR (AT91_CAST(AT91_REG *) 0x4008006C) // (TC1) Interrupt Mask Register +#define AT91C_TC1_RC (AT91_CAST(AT91_REG *) 0x4008005C) // (TC1) Register C +#define AT91C_TC1_CMR (AT91_CAST(AT91_REG *) 0x40080044) // (TC1) Channel Mode Register (Capture Mode / Waveform Mode) +#define AT91C_TC1_CV (AT91_CAST(AT91_REG *) 0x40080050) // (TC1) Counter Value +// ========== Register definition for TC2 peripheral ========== +#define AT91C_TC2_RA (AT91_CAST(AT91_REG *) 0x40080094) // (TC2) Register A +#define AT91C_TC2_RB (AT91_CAST(AT91_REG *) 0x40080098) // (TC2) Register B +#define AT91C_TC2_CMR (AT91_CAST(AT91_REG *) 0x40080084) // (TC2) Channel Mode Register (Capture Mode / Waveform Mode) +#define AT91C_TC2_SR (AT91_CAST(AT91_REG *) 0x400800A0) // (TC2) Status Register +#define AT91C_TC2_CCR (AT91_CAST(AT91_REG *) 0x40080080) // (TC2) Channel Control Register +#define AT91C_TC2_IMR (AT91_CAST(AT91_REG *) 0x400800AC) // (TC2) Interrupt Mask Register +#define AT91C_TC2_CV (AT91_CAST(AT91_REG *) 0x40080090) // (TC2) Counter Value +#define AT91C_TC2_RC (AT91_CAST(AT91_REG *) 0x4008009C) // (TC2) Register C +#define AT91C_TC2_IER (AT91_CAST(AT91_REG *) 0x400800A4) // (TC2) Interrupt Enable Register +#define AT91C_TC2_IDR (AT91_CAST(AT91_REG *) 0x400800A8) // (TC2) Interrupt Disable Register +// ========== Register definition for TCB0 peripheral ========== +#define AT91C_TCB0_BCR (AT91_CAST(AT91_REG *) 0x400800C0) // (TCB0) TC Block Control Register +#define AT91C_TCB0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400800F4) // (TCB0) TC IPNAME2 REGISTER +#define AT91C_TCB0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400800F0) // (TCB0) TC IPNAME1 REGISTER +#define AT91C_TCB0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400800EC) // (TCB0) TC ADDRSIZE REGISTER +#define AT91C_TCB0_FEATURES (AT91_CAST(AT91_REG *) 0x400800F8) // (TCB0) TC FEATURES REGISTER +#define AT91C_TCB0_BMR (AT91_CAST(AT91_REG *) 0x400800C4) // (TCB0) TC Block Mode Register +#define AT91C_TCB0_VER (AT91_CAST(AT91_REG *) 0x400800FC) // (TCB0) Version Register +// ========== Register definition for TCB1 peripheral ========== +#define AT91C_TCB1_BCR (AT91_CAST(AT91_REG *) 0x40080100) // (TCB1) TC Block Control Register +#define AT91C_TCB1_VER (AT91_CAST(AT91_REG *) 0x4008013C) // (TCB1) Version Register +#define AT91C_TCB1_FEATURES (AT91_CAST(AT91_REG *) 0x40080138) // (TCB1) TC FEATURES REGISTER +#define AT91C_TCB1_IPNAME2 (AT91_CAST(AT91_REG *) 0x40080134) // (TCB1) TC IPNAME2 REGISTER +#define AT91C_TCB1_BMR (AT91_CAST(AT91_REG *) 0x40080104) // (TCB1) TC Block Mode Register +#define AT91C_TCB1_ADDRSIZE (AT91_CAST(AT91_REG *) 0x4008012C) // (TCB1) TC ADDRSIZE REGISTER +#define AT91C_TCB1_IPNAME1 (AT91_CAST(AT91_REG *) 0x40080130) // (TCB1) TC IPNAME1 REGISTER +// ========== Register definition for TCB2 peripheral ========== +#define AT91C_TCB2_FEATURES (AT91_CAST(AT91_REG *) 0x40080178) // (TCB2) TC FEATURES REGISTER +#define AT91C_TCB2_VER (AT91_CAST(AT91_REG *) 0x4008017C) // (TCB2) Version Register +#define AT91C_TCB2_ADDRSIZE (AT91_CAST(AT91_REG *) 0x4008016C) // (TCB2) TC ADDRSIZE REGISTER +#define AT91C_TCB2_IPNAME1 (AT91_CAST(AT91_REG *) 0x40080170) // (TCB2) TC IPNAME1 REGISTER +#define AT91C_TCB2_IPNAME2 (AT91_CAST(AT91_REG *) 0x40080174) // (TCB2) TC IPNAME2 REGISTER +#define AT91C_TCB2_BMR (AT91_CAST(AT91_REG *) 0x40080144) // (TCB2) TC Block Mode Register +#define AT91C_TCB2_BCR (AT91_CAST(AT91_REG *) 0x40080140) // (TCB2) TC Block Control Register +// ========== Register definition for EFC0 peripheral ========== +#define AT91C_EFC0_FCR (AT91_CAST(AT91_REG *) 0x400E0804) // (EFC0) EFC Flash Command Register +#define AT91C_EFC0_FRR (AT91_CAST(AT91_REG *) 0x400E080C) // (EFC0) EFC Flash Result Register +#define AT91C_EFC0_FMR (AT91_CAST(AT91_REG *) 0x400E0800) // (EFC0) EFC Flash Mode Register +#define AT91C_EFC0_FSR (AT91_CAST(AT91_REG *) 0x400E0808) // (EFC0) EFC Flash Status Register +#define AT91C_EFC0_FVR (AT91_CAST(AT91_REG *) 0x400E0814) // (EFC0) EFC Flash Version Register +// ========== Register definition for EFC1 peripheral ========== +#define AT91C_EFC1_FMR (AT91_CAST(AT91_REG *) 0x400E0A00) // (EFC1) EFC Flash Mode Register +#define AT91C_EFC1_FVR (AT91_CAST(AT91_REG *) 0x400E0A14) // (EFC1) EFC Flash Version Register +#define AT91C_EFC1_FSR (AT91_CAST(AT91_REG *) 0x400E0A08) // (EFC1) EFC Flash Status Register +#define AT91C_EFC1_FCR (AT91_CAST(AT91_REG *) 0x400E0A04) // (EFC1) EFC Flash Command Register +#define AT91C_EFC1_FRR (AT91_CAST(AT91_REG *) 0x400E0A0C) // (EFC1) EFC Flash Result Register +// ========== Register definition for MCI0 peripheral ========== +#define AT91C_MCI0_DMA (AT91_CAST(AT91_REG *) 0x40000050) // (MCI0) MCI DMA Configuration Register +#define AT91C_MCI0_SDCR (AT91_CAST(AT91_REG *) 0x4000000C) // (MCI0) MCI SD/SDIO Card Register +#define AT91C_MCI0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400000F0) // (MCI0) MCI IPNAME1 REGISTER +#define AT91C_MCI0_CSTOR (AT91_CAST(AT91_REG *) 0x4000001C) // (MCI0) MCI Completion Signal Timeout Register +#define AT91C_MCI0_RDR (AT91_CAST(AT91_REG *) 0x40000030) // (MCI0) MCI Receive Data Register +#define AT91C_MCI0_CMDR (AT91_CAST(AT91_REG *) 0x40000014) // (MCI0) MCI Command Register +#define AT91C_MCI0_IDR (AT91_CAST(AT91_REG *) 0x40000048) // (MCI0) MCI Interrupt Disable Register +#define AT91C_MCI0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400000EC) // (MCI0) MCI ADDRSIZE REGISTER +#define AT91C_MCI0_WPCR (AT91_CAST(AT91_REG *) 0x400000E4) // (MCI0) MCI Write Protection Control Register +#define AT91C_MCI0_RSPR (AT91_CAST(AT91_REG *) 0x40000020) // (MCI0) MCI Response Register +#define AT91C_MCI0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400000F4) // (MCI0) MCI IPNAME2 REGISTER +#define AT91C_MCI0_CR (AT91_CAST(AT91_REG *) 0x40000000) // (MCI0) MCI Control Register +#define AT91C_MCI0_IMR (AT91_CAST(AT91_REG *) 0x4000004C) // (MCI0) MCI Interrupt Mask Register +#define AT91C_MCI0_WPSR (AT91_CAST(AT91_REG *) 0x400000E8) // (MCI0) MCI Write Protection Status Register +#define AT91C_MCI0_DTOR (AT91_CAST(AT91_REG *) 0x40000008) // (MCI0) MCI Data Timeout Register +#define AT91C_MCI0_MR (AT91_CAST(AT91_REG *) 0x40000004) // (MCI0) MCI Mode Register +#define AT91C_MCI0_SR (AT91_CAST(AT91_REG *) 0x40000040) // (MCI0) MCI Status Register +#define AT91C_MCI0_IER (AT91_CAST(AT91_REG *) 0x40000044) // (MCI0) MCI Interrupt Enable Register +#define AT91C_MCI0_VER (AT91_CAST(AT91_REG *) 0x400000FC) // (MCI0) MCI VERSION REGISTER +#define AT91C_MCI0_FEATURES (AT91_CAST(AT91_REG *) 0x400000F8) // (MCI0) MCI FEATURES REGISTER +#define AT91C_MCI0_BLKR (AT91_CAST(AT91_REG *) 0x40000018) // (MCI0) MCI Block Register +#define AT91C_MCI0_ARGR (AT91_CAST(AT91_REG *) 0x40000010) // (MCI0) MCI Argument Register +#define AT91C_MCI0_FIFO (AT91_CAST(AT91_REG *) 0x40000200) // (MCI0) MCI FIFO Aperture Register +#define AT91C_MCI0_TDR (AT91_CAST(AT91_REG *) 0x40000034) // (MCI0) MCI Transmit Data Register +#define AT91C_MCI0_CFG (AT91_CAST(AT91_REG *) 0x40000054) // (MCI0) MCI Configuration Register +// ========== Register definition for PDC_TWI0 peripheral ========== +#define AT91C_TWI0_TNCR (AT91_CAST(AT91_REG *) 0x4008411C) // (PDC_TWI0) Transmit Next Counter Register +#define AT91C_TWI0_PTCR (AT91_CAST(AT91_REG *) 0x40084120) // (PDC_TWI0) PDC Transfer Control Register +#define AT91C_TWI0_PTSR (AT91_CAST(AT91_REG *) 0x40084124) // (PDC_TWI0) PDC Transfer Status Register +#define AT91C_TWI0_RCR (AT91_CAST(AT91_REG *) 0x40084104) // (PDC_TWI0) Receive Counter Register +#define AT91C_TWI0_TNPR (AT91_CAST(AT91_REG *) 0x40084118) // (PDC_TWI0) Transmit Next Pointer Register +#define AT91C_TWI0_RNPR (AT91_CAST(AT91_REG *) 0x40084110) // (PDC_TWI0) Receive Next Pointer Register +#define AT91C_TWI0_RPR (AT91_CAST(AT91_REG *) 0x40084100) // (PDC_TWI0) Receive Pointer Register +#define AT91C_TWI0_RNCR (AT91_CAST(AT91_REG *) 0x40084114) // (PDC_TWI0) Receive Next Counter Register +#define AT91C_TWI0_TPR (AT91_CAST(AT91_REG *) 0x40084108) // (PDC_TWI0) Transmit Pointer Register +#define AT91C_TWI0_TCR (AT91_CAST(AT91_REG *) 0x4008410C) // (PDC_TWI0) Transmit Counter Register +// ========== Register definition for PDC_TWI1 peripheral ========== +#define AT91C_TWI1_TNCR (AT91_CAST(AT91_REG *) 0x4008811C) // (PDC_TWI1) Transmit Next Counter Register +#define AT91C_TWI1_PTCR (AT91_CAST(AT91_REG *) 0x40088120) // (PDC_TWI1) PDC Transfer Control Register +#define AT91C_TWI1_RNCR (AT91_CAST(AT91_REG *) 0x40088114) // (PDC_TWI1) Receive Next Counter Register +#define AT91C_TWI1_RCR (AT91_CAST(AT91_REG *) 0x40088104) // (PDC_TWI1) Receive Counter Register +#define AT91C_TWI1_RPR (AT91_CAST(AT91_REG *) 0x40088100) // (PDC_TWI1) Receive Pointer Register +#define AT91C_TWI1_TNPR (AT91_CAST(AT91_REG *) 0x40088118) // (PDC_TWI1) Transmit Next Pointer Register +#define AT91C_TWI1_RNPR (AT91_CAST(AT91_REG *) 0x40088110) // (PDC_TWI1) Receive Next Pointer Register +#define AT91C_TWI1_TCR (AT91_CAST(AT91_REG *) 0x4008810C) // (PDC_TWI1) Transmit Counter Register +#define AT91C_TWI1_TPR (AT91_CAST(AT91_REG *) 0x40088108) // (PDC_TWI1) Transmit Pointer Register +#define AT91C_TWI1_PTSR (AT91_CAST(AT91_REG *) 0x40088124) // (PDC_TWI1) PDC Transfer Status Register +// ========== Register definition for TWI0 peripheral ========== +#define AT91C_TWI0_FEATURES (AT91_CAST(AT91_REG *) 0x400840F8) // (TWI0) TWI FEATURES REGISTER +#define AT91C_TWI0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400840F0) // (TWI0) TWI IPNAME1 REGISTER +#define AT91C_TWI0_SMR (AT91_CAST(AT91_REG *) 0x40084008) // (TWI0) Slave Mode Register +#define AT91C_TWI0_MMR (AT91_CAST(AT91_REG *) 0x40084004) // (TWI0) Master Mode Register +#define AT91C_TWI0_SR (AT91_CAST(AT91_REG *) 0x40084020) // (TWI0) Status Register +#define AT91C_TWI0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400840F4) // (TWI0) TWI IPNAME2 REGISTER +#define AT91C_TWI0_CR (AT91_CAST(AT91_REG *) 0x40084000) // (TWI0) Control Register +#define AT91C_TWI0_IER (AT91_CAST(AT91_REG *) 0x40084024) // (TWI0) Interrupt Enable Register +#define AT91C_TWI0_RHR (AT91_CAST(AT91_REG *) 0x40084030) // (TWI0) Receive Holding Register +#define AT91C_TWI0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400840EC) // (TWI0) TWI ADDRSIZE REGISTER +#define AT91C_TWI0_THR (AT91_CAST(AT91_REG *) 0x40084034) // (TWI0) Transmit Holding Register +#define AT91C_TWI0_VER (AT91_CAST(AT91_REG *) 0x400840FC) // (TWI0) Version Register +#define AT91C_TWI0_IADR (AT91_CAST(AT91_REG *) 0x4008400C) // (TWI0) Internal Address Register +#define AT91C_TWI0_IMR (AT91_CAST(AT91_REG *) 0x4008402C) // (TWI0) Interrupt Mask Register +#define AT91C_TWI0_CWGR (AT91_CAST(AT91_REG *) 0x40084010) // (TWI0) Clock Waveform Generator Register +#define AT91C_TWI0_IDR (AT91_CAST(AT91_REG *) 0x40084028) // (TWI0) Interrupt Disable Register +// ========== Register definition for TWI1 peripheral ========== +#define AT91C_TWI1_VER (AT91_CAST(AT91_REG *) 0x400880FC) // (TWI1) Version Register +#define AT91C_TWI1_IDR (AT91_CAST(AT91_REG *) 0x40088028) // (TWI1) Interrupt Disable Register +#define AT91C_TWI1_IPNAME2 (AT91_CAST(AT91_REG *) 0x400880F4) // (TWI1) TWI IPNAME2 REGISTER +#define AT91C_TWI1_CWGR (AT91_CAST(AT91_REG *) 0x40088010) // (TWI1) Clock Waveform Generator Register +#define AT91C_TWI1_CR (AT91_CAST(AT91_REG *) 0x40088000) // (TWI1) Control Register +#define AT91C_TWI1_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400880EC) // (TWI1) TWI ADDRSIZE REGISTER +#define AT91C_TWI1_IADR (AT91_CAST(AT91_REG *) 0x4008800C) // (TWI1) Internal Address Register +#define AT91C_TWI1_IER (AT91_CAST(AT91_REG *) 0x40088024) // (TWI1) Interrupt Enable Register +#define AT91C_TWI1_SMR (AT91_CAST(AT91_REG *) 0x40088008) // (TWI1) Slave Mode Register +#define AT91C_TWI1_RHR (AT91_CAST(AT91_REG *) 0x40088030) // (TWI1) Receive Holding Register +#define AT91C_TWI1_FEATURES (AT91_CAST(AT91_REG *) 0x400880F8) // (TWI1) TWI FEATURES REGISTER +#define AT91C_TWI1_IMR (AT91_CAST(AT91_REG *) 0x4008802C) // (TWI1) Interrupt Mask Register +#define AT91C_TWI1_SR (AT91_CAST(AT91_REG *) 0x40088020) // (TWI1) Status Register +#define AT91C_TWI1_THR (AT91_CAST(AT91_REG *) 0x40088034) // (TWI1) Transmit Holding Register +#define AT91C_TWI1_MMR (AT91_CAST(AT91_REG *) 0x40088004) // (TWI1) Master Mode Register +#define AT91C_TWI1_IPNAME1 (AT91_CAST(AT91_REG *) 0x400880F0) // (TWI1) TWI IPNAME1 REGISTER +// ========== Register definition for PDC_US0 peripheral ========== +#define AT91C_US0_RNCR (AT91_CAST(AT91_REG *) 0x40090114) // (PDC_US0) Receive Next Counter Register +#define AT91C_US0_TNPR (AT91_CAST(AT91_REG *) 0x40090118) // (PDC_US0) Transmit Next Pointer Register +#define AT91C_US0_TPR (AT91_CAST(AT91_REG *) 0x40090108) // (PDC_US0) Transmit Pointer Register +#define AT91C_US0_RCR (AT91_CAST(AT91_REG *) 0x40090104) // (PDC_US0) Receive Counter Register +#define AT91C_US0_RNPR (AT91_CAST(AT91_REG *) 0x40090110) // (PDC_US0) Receive Next Pointer Register +#define AT91C_US0_TNCR (AT91_CAST(AT91_REG *) 0x4009011C) // (PDC_US0) Transmit Next Counter Register +#define AT91C_US0_PTSR (AT91_CAST(AT91_REG *) 0x40090124) // (PDC_US0) PDC Transfer Status Register +#define AT91C_US0_RPR (AT91_CAST(AT91_REG *) 0x40090100) // (PDC_US0) Receive Pointer Register +#define AT91C_US0_PTCR (AT91_CAST(AT91_REG *) 0x40090120) // (PDC_US0) PDC Transfer Control Register +#define AT91C_US0_TCR (AT91_CAST(AT91_REG *) 0x4009010C) // (PDC_US0) Transmit Counter Register +// ========== Register definition for US0 peripheral ========== +#define AT91C_US0_NER (AT91_CAST(AT91_REG *) 0x40090044) // (US0) Nb Errors Register +#define AT91C_US0_RHR (AT91_CAST(AT91_REG *) 0x40090018) // (US0) Receiver Holding Register +#define AT91C_US0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400900F0) // (US0) US IPNAME1 REGISTER +#define AT91C_US0_MR (AT91_CAST(AT91_REG *) 0x40090004) // (US0) Mode Register +#define AT91C_US0_RTOR (AT91_CAST(AT91_REG *) 0x40090024) // (US0) Receiver Time-out Register +#define AT91C_US0_IF (AT91_CAST(AT91_REG *) 0x4009004C) // (US0) IRDA_FILTER Register +#define AT91C_US0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400900EC) // (US0) US ADDRSIZE REGISTER +#define AT91C_US0_IDR (AT91_CAST(AT91_REG *) 0x4009000C) // (US0) Interrupt Disable Register +#define AT91C_US0_IMR (AT91_CAST(AT91_REG *) 0x40090010) // (US0) Interrupt Mask Register +#define AT91C_US0_IER (AT91_CAST(AT91_REG *) 0x40090008) // (US0) Interrupt Enable Register +#define AT91C_US0_TTGR (AT91_CAST(AT91_REG *) 0x40090028) // (US0) Transmitter Time-guard Register +#define AT91C_US0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400900F4) // (US0) US IPNAME2 REGISTER +#define AT91C_US0_FIDI (AT91_CAST(AT91_REG *) 0x40090040) // (US0) FI_DI_Ratio Register +#define AT91C_US0_CR (AT91_CAST(AT91_REG *) 0x40090000) // (US0) Control Register +#define AT91C_US0_BRGR (AT91_CAST(AT91_REG *) 0x40090020) // (US0) Baud Rate Generator Register +#define AT91C_US0_MAN (AT91_CAST(AT91_REG *) 0x40090050) // (US0) Manchester Encoder Decoder Register +#define AT91C_US0_VER (AT91_CAST(AT91_REG *) 0x400900FC) // (US0) VERSION Register +#define AT91C_US0_FEATURES (AT91_CAST(AT91_REG *) 0x400900F8) // (US0) US FEATURES REGISTER +#define AT91C_US0_CSR (AT91_CAST(AT91_REG *) 0x40090014) // (US0) Channel Status Register +#define AT91C_US0_THR (AT91_CAST(AT91_REG *) 0x4009001C) // (US0) Transmitter Holding Register +// ========== Register definition for PDC_US1 peripheral ========== +#define AT91C_US1_TNPR (AT91_CAST(AT91_REG *) 0x40094118) // (PDC_US1) Transmit Next Pointer Register +#define AT91C_US1_TPR (AT91_CAST(AT91_REG *) 0x40094108) // (PDC_US1) Transmit Pointer Register +#define AT91C_US1_RNCR (AT91_CAST(AT91_REG *) 0x40094114) // (PDC_US1) Receive Next Counter Register +#define AT91C_US1_TNCR (AT91_CAST(AT91_REG *) 0x4009411C) // (PDC_US1) Transmit Next Counter Register +#define AT91C_US1_RNPR (AT91_CAST(AT91_REG *) 0x40094110) // (PDC_US1) Receive Next Pointer Register +#define AT91C_US1_TCR (AT91_CAST(AT91_REG *) 0x4009410C) // (PDC_US1) Transmit Counter Register +#define AT91C_US1_PTSR (AT91_CAST(AT91_REG *) 0x40094124) // (PDC_US1) PDC Transfer Status Register +#define AT91C_US1_RCR (AT91_CAST(AT91_REG *) 0x40094104) // (PDC_US1) Receive Counter Register +#define AT91C_US1_RPR (AT91_CAST(AT91_REG *) 0x40094100) // (PDC_US1) Receive Pointer Register +#define AT91C_US1_PTCR (AT91_CAST(AT91_REG *) 0x40094120) // (PDC_US1) PDC Transfer Control Register +// ========== Register definition for US1 peripheral ========== +#define AT91C_US1_IMR (AT91_CAST(AT91_REG *) 0x40094010) // (US1) Interrupt Mask Register +#define AT91C_US1_RTOR (AT91_CAST(AT91_REG *) 0x40094024) // (US1) Receiver Time-out Register +#define AT91C_US1_RHR (AT91_CAST(AT91_REG *) 0x40094018) // (US1) Receiver Holding Register +#define AT91C_US1_IPNAME1 (AT91_CAST(AT91_REG *) 0x400940F0) // (US1) US IPNAME1 REGISTER +#define AT91C_US1_VER (AT91_CAST(AT91_REG *) 0x400940FC) // (US1) VERSION Register +#define AT91C_US1_MR (AT91_CAST(AT91_REG *) 0x40094004) // (US1) Mode Register +#define AT91C_US1_FEATURES (AT91_CAST(AT91_REG *) 0x400940F8) // (US1) US FEATURES REGISTER +#define AT91C_US1_NER (AT91_CAST(AT91_REG *) 0x40094044) // (US1) Nb Errors Register +#define AT91C_US1_IPNAME2 (AT91_CAST(AT91_REG *) 0x400940F4) // (US1) US IPNAME2 REGISTER +#define AT91C_US1_CR (AT91_CAST(AT91_REG *) 0x40094000) // (US1) Control Register +#define AT91C_US1_BRGR (AT91_CAST(AT91_REG *) 0x40094020) // (US1) Baud Rate Generator Register +#define AT91C_US1_IF (AT91_CAST(AT91_REG *) 0x4009404C) // (US1) IRDA_FILTER Register +#define AT91C_US1_IER (AT91_CAST(AT91_REG *) 0x40094008) // (US1) Interrupt Enable Register +#define AT91C_US1_TTGR (AT91_CAST(AT91_REG *) 0x40094028) // (US1) Transmitter Time-guard Register +#define AT91C_US1_FIDI (AT91_CAST(AT91_REG *) 0x40094040) // (US1) FI_DI_Ratio Register +#define AT91C_US1_MAN (AT91_CAST(AT91_REG *) 0x40094050) // (US1) Manchester Encoder Decoder Register +#define AT91C_US1_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400940EC) // (US1) US ADDRSIZE REGISTER +#define AT91C_US1_CSR (AT91_CAST(AT91_REG *) 0x40094014) // (US1) Channel Status Register +#define AT91C_US1_THR (AT91_CAST(AT91_REG *) 0x4009401C) // (US1) Transmitter Holding Register +#define AT91C_US1_IDR (AT91_CAST(AT91_REG *) 0x4009400C) // (US1) Interrupt Disable Register +// ========== Register definition for PDC_US2 peripheral ========== +#define AT91C_US2_RPR (AT91_CAST(AT91_REG *) 0x40098100) // (PDC_US2) Receive Pointer Register +#define AT91C_US2_TPR (AT91_CAST(AT91_REG *) 0x40098108) // (PDC_US2) Transmit Pointer Register +#define AT91C_US2_TCR (AT91_CAST(AT91_REG *) 0x4009810C) // (PDC_US2) Transmit Counter Register +#define AT91C_US2_PTSR (AT91_CAST(AT91_REG *) 0x40098124) // (PDC_US2) PDC Transfer Status Register +#define AT91C_US2_PTCR (AT91_CAST(AT91_REG *) 0x40098120) // (PDC_US2) PDC Transfer Control Register +#define AT91C_US2_RNPR (AT91_CAST(AT91_REG *) 0x40098110) // (PDC_US2) Receive Next Pointer Register +#define AT91C_US2_TNCR (AT91_CAST(AT91_REG *) 0x4009811C) // (PDC_US2) Transmit Next Counter Register +#define AT91C_US2_RNCR (AT91_CAST(AT91_REG *) 0x40098114) // (PDC_US2) Receive Next Counter Register +#define AT91C_US2_TNPR (AT91_CAST(AT91_REG *) 0x40098118) // (PDC_US2) Transmit Next Pointer Register +#define AT91C_US2_RCR (AT91_CAST(AT91_REG *) 0x40098104) // (PDC_US2) Receive Counter Register +// ========== Register definition for US2 peripheral ========== +#define AT91C_US2_MAN (AT91_CAST(AT91_REG *) 0x40098050) // (US2) Manchester Encoder Decoder Register +#define AT91C_US2_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400980EC) // (US2) US ADDRSIZE REGISTER +#define AT91C_US2_MR (AT91_CAST(AT91_REG *) 0x40098004) // (US2) Mode Register +#define AT91C_US2_IPNAME1 (AT91_CAST(AT91_REG *) 0x400980F0) // (US2) US IPNAME1 REGISTER +#define AT91C_US2_IF (AT91_CAST(AT91_REG *) 0x4009804C) // (US2) IRDA_FILTER Register +#define AT91C_US2_BRGR (AT91_CAST(AT91_REG *) 0x40098020) // (US2) Baud Rate Generator Register +#define AT91C_US2_FIDI (AT91_CAST(AT91_REG *) 0x40098040) // (US2) FI_DI_Ratio Register +#define AT91C_US2_IER (AT91_CAST(AT91_REG *) 0x40098008) // (US2) Interrupt Enable Register +#define AT91C_US2_RTOR (AT91_CAST(AT91_REG *) 0x40098024) // (US2) Receiver Time-out Register +#define AT91C_US2_CR (AT91_CAST(AT91_REG *) 0x40098000) // (US2) Control Register +#define AT91C_US2_THR (AT91_CAST(AT91_REG *) 0x4009801C) // (US2) Transmitter Holding Register +#define AT91C_US2_CSR (AT91_CAST(AT91_REG *) 0x40098014) // (US2) Channel Status Register +#define AT91C_US2_VER (AT91_CAST(AT91_REG *) 0x400980FC) // (US2) VERSION Register +#define AT91C_US2_FEATURES (AT91_CAST(AT91_REG *) 0x400980F8) // (US2) US FEATURES REGISTER +#define AT91C_US2_IDR (AT91_CAST(AT91_REG *) 0x4009800C) // (US2) Interrupt Disable Register +#define AT91C_US2_TTGR (AT91_CAST(AT91_REG *) 0x40098028) // (US2) Transmitter Time-guard Register +#define AT91C_US2_IPNAME2 (AT91_CAST(AT91_REG *) 0x400980F4) // (US2) US IPNAME2 REGISTER +#define AT91C_US2_RHR (AT91_CAST(AT91_REG *) 0x40098018) // (US2) Receiver Holding Register +#define AT91C_US2_NER (AT91_CAST(AT91_REG *) 0x40098044) // (US2) Nb Errors Register +#define AT91C_US2_IMR (AT91_CAST(AT91_REG *) 0x40098010) // (US2) Interrupt Mask Register +// ========== Register definition for PDC_US3 peripheral ========== +#define AT91C_US3_TPR (AT91_CAST(AT91_REG *) 0x4009C108) // (PDC_US3) Transmit Pointer Register +#define AT91C_US3_PTCR (AT91_CAST(AT91_REG *) 0x4009C120) // (PDC_US3) PDC Transfer Control Register +#define AT91C_US3_TCR (AT91_CAST(AT91_REG *) 0x4009C10C) // (PDC_US3) Transmit Counter Register +#define AT91C_US3_RCR (AT91_CAST(AT91_REG *) 0x4009C104) // (PDC_US3) Receive Counter Register +#define AT91C_US3_RNCR (AT91_CAST(AT91_REG *) 0x4009C114) // (PDC_US3) Receive Next Counter Register +#define AT91C_US3_RNPR (AT91_CAST(AT91_REG *) 0x4009C110) // (PDC_US3) Receive Next Pointer Register +#define AT91C_US3_RPR (AT91_CAST(AT91_REG *) 0x4009C100) // (PDC_US3) Receive Pointer Register +#define AT91C_US3_PTSR (AT91_CAST(AT91_REG *) 0x4009C124) // (PDC_US3) PDC Transfer Status Register +#define AT91C_US3_TNCR (AT91_CAST(AT91_REG *) 0x4009C11C) // (PDC_US3) Transmit Next Counter Register +#define AT91C_US3_TNPR (AT91_CAST(AT91_REG *) 0x4009C118) // (PDC_US3) Transmit Next Pointer Register +// ========== Register definition for US3 peripheral ========== +#define AT91C_US3_MAN (AT91_CAST(AT91_REG *) 0x4009C050) // (US3) Manchester Encoder Decoder Register +#define AT91C_US3_CSR (AT91_CAST(AT91_REG *) 0x4009C014) // (US3) Channel Status Register +#define AT91C_US3_BRGR (AT91_CAST(AT91_REG *) 0x4009C020) // (US3) Baud Rate Generator Register +#define AT91C_US3_IPNAME2 (AT91_CAST(AT91_REG *) 0x4009C0F4) // (US3) US IPNAME2 REGISTER +#define AT91C_US3_RTOR (AT91_CAST(AT91_REG *) 0x4009C024) // (US3) Receiver Time-out Register +#define AT91C_US3_ADDRSIZE (AT91_CAST(AT91_REG *) 0x4009C0EC) // (US3) US ADDRSIZE REGISTER +#define AT91C_US3_CR (AT91_CAST(AT91_REG *) 0x4009C000) // (US3) Control Register +#define AT91C_US3_IF (AT91_CAST(AT91_REG *) 0x4009C04C) // (US3) IRDA_FILTER Register +#define AT91C_US3_FEATURES (AT91_CAST(AT91_REG *) 0x4009C0F8) // (US3) US FEATURES REGISTER +#define AT91C_US3_VER (AT91_CAST(AT91_REG *) 0x4009C0FC) // (US3) VERSION Register +#define AT91C_US3_RHR (AT91_CAST(AT91_REG *) 0x4009C018) // (US3) Receiver Holding Register +#define AT91C_US3_TTGR (AT91_CAST(AT91_REG *) 0x4009C028) // (US3) Transmitter Time-guard Register +#define AT91C_US3_NER (AT91_CAST(AT91_REG *) 0x4009C044) // (US3) Nb Errors Register +#define AT91C_US3_IMR (AT91_CAST(AT91_REG *) 0x4009C010) // (US3) Interrupt Mask Register +#define AT91C_US3_THR (AT91_CAST(AT91_REG *) 0x4009C01C) // (US3) Transmitter Holding Register +#define AT91C_US3_IDR (AT91_CAST(AT91_REG *) 0x4009C00C) // (US3) Interrupt Disable Register +#define AT91C_US3_MR (AT91_CAST(AT91_REG *) 0x4009C004) // (US3) Mode Register +#define AT91C_US3_IER (AT91_CAST(AT91_REG *) 0x4009C008) // (US3) Interrupt Enable Register +#define AT91C_US3_FIDI (AT91_CAST(AT91_REG *) 0x4009C040) // (US3) FI_DI_Ratio Register +#define AT91C_US3_IPNAME1 (AT91_CAST(AT91_REG *) 0x4009C0F0) // (US3) US IPNAME1 REGISTER +// ========== Register definition for PDC_SSC0 peripheral ========== +#define AT91C_SSC0_RNCR (AT91_CAST(AT91_REG *) 0x40004114) // (PDC_SSC0) Receive Next Counter Register +#define AT91C_SSC0_TPR (AT91_CAST(AT91_REG *) 0x40004108) // (PDC_SSC0) Transmit Pointer Register +#define AT91C_SSC0_TCR (AT91_CAST(AT91_REG *) 0x4000410C) // (PDC_SSC0) Transmit Counter Register +#define AT91C_SSC0_PTCR (AT91_CAST(AT91_REG *) 0x40004120) // (PDC_SSC0) PDC Transfer Control Register +#define AT91C_SSC0_TNPR (AT91_CAST(AT91_REG *) 0x40004118) // (PDC_SSC0) Transmit Next Pointer Register +#define AT91C_SSC0_RPR (AT91_CAST(AT91_REG *) 0x40004100) // (PDC_SSC0) Receive Pointer Register +#define AT91C_SSC0_TNCR (AT91_CAST(AT91_REG *) 0x4000411C) // (PDC_SSC0) Transmit Next Counter Register +#define AT91C_SSC0_RNPR (AT91_CAST(AT91_REG *) 0x40004110) // (PDC_SSC0) Receive Next Pointer Register +#define AT91C_SSC0_RCR (AT91_CAST(AT91_REG *) 0x40004104) // (PDC_SSC0) Receive Counter Register +#define AT91C_SSC0_PTSR (AT91_CAST(AT91_REG *) 0x40004124) // (PDC_SSC0) PDC Transfer Status Register +// ========== Register definition for SSC0 peripheral ========== +#define AT91C_SSC0_FEATURES (AT91_CAST(AT91_REG *) 0x400040F8) // (SSC0) SSC FEATURES REGISTER +#define AT91C_SSC0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400040F0) // (SSC0) SSC IPNAME1 REGISTER +#define AT91C_SSC0_CR (AT91_CAST(AT91_REG *) 0x40004000) // (SSC0) Control Register +#define AT91C_SSC0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400040EC) // (SSC0) SSC ADDRSIZE REGISTER +#define AT91C_SSC0_RHR (AT91_CAST(AT91_REG *) 0x40004020) // (SSC0) Receive Holding Register +#define AT91C_SSC0_VER (AT91_CAST(AT91_REG *) 0x400040FC) // (SSC0) Version Register +#define AT91C_SSC0_TSHR (AT91_CAST(AT91_REG *) 0x40004034) // (SSC0) Transmit Sync Holding Register +#define AT91C_SSC0_RFMR (AT91_CAST(AT91_REG *) 0x40004014) // (SSC0) Receive Frame Mode Register +#define AT91C_SSC0_IDR (AT91_CAST(AT91_REG *) 0x40004048) // (SSC0) Interrupt Disable Register +#define AT91C_SSC0_TFMR (AT91_CAST(AT91_REG *) 0x4000401C) // (SSC0) Transmit Frame Mode Register +#define AT91C_SSC0_RSHR (AT91_CAST(AT91_REG *) 0x40004030) // (SSC0) Receive Sync Holding Register +#define AT91C_SSC0_TCMR (AT91_CAST(AT91_REG *) 0x40004018) // (SSC0) Transmit Clock Mode Register +#define AT91C_SSC0_RCMR (AT91_CAST(AT91_REG *) 0x40004010) // (SSC0) Receive Clock ModeRegister +#define AT91C_SSC0_SR (AT91_CAST(AT91_REG *) 0x40004040) // (SSC0) Status Register +#define AT91C_SSC0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400040F4) // (SSC0) SSC IPNAME2 REGISTER +#define AT91C_SSC0_THR (AT91_CAST(AT91_REG *) 0x40004024) // (SSC0) Transmit Holding Register +#define AT91C_SSC0_CMR (AT91_CAST(AT91_REG *) 0x40004004) // (SSC0) Clock Mode Register +#define AT91C_SSC0_IER (AT91_CAST(AT91_REG *) 0x40004044) // (SSC0) Interrupt Enable Register +#define AT91C_SSC0_IMR (AT91_CAST(AT91_REG *) 0x4000404C) // (SSC0) Interrupt Mask Register +// ========== Register definition for PDC_PWMC peripheral ========== +#define AT91C_PWMC_TNCR (AT91_CAST(AT91_REG *) 0x4008C11C) // (PDC_PWMC) Transmit Next Counter Register +#define AT91C_PWMC_TPR (AT91_CAST(AT91_REG *) 0x4008C108) // (PDC_PWMC) Transmit Pointer Register +#define AT91C_PWMC_RPR (AT91_CAST(AT91_REG *) 0x4008C100) // (PDC_PWMC) Receive Pointer Register +#define AT91C_PWMC_TCR (AT91_CAST(AT91_REG *) 0x4008C10C) // (PDC_PWMC) Transmit Counter Register +#define AT91C_PWMC_PTSR (AT91_CAST(AT91_REG *) 0x4008C124) // (PDC_PWMC) PDC Transfer Status Register +#define AT91C_PWMC_RNPR (AT91_CAST(AT91_REG *) 0x4008C110) // (PDC_PWMC) Receive Next Pointer Register +#define AT91C_PWMC_RCR (AT91_CAST(AT91_REG *) 0x4008C104) // (PDC_PWMC) Receive Counter Register +#define AT91C_PWMC_RNCR (AT91_CAST(AT91_REG *) 0x4008C114) // (PDC_PWMC) Receive Next Counter Register +#define AT91C_PWMC_PTCR (AT91_CAST(AT91_REG *) 0x4008C120) // (PDC_PWMC) PDC Transfer Control Register +#define AT91C_PWMC_TNPR (AT91_CAST(AT91_REG *) 0x4008C118) // (PDC_PWMC) Transmit Next Pointer Register +// ========== Register definition for PWMC_CH0 peripheral ========== +#define AT91C_PWMC_CH0_DTR (AT91_CAST(AT91_REG *) 0x4008C218) // (PWMC_CH0) Channel Dead Time Value Register +#define AT91C_PWMC_CH0_CMR (AT91_CAST(AT91_REG *) 0x4008C200) // (PWMC_CH0) Channel Mode Register +#define AT91C_PWMC_CH0_CCNTR (AT91_CAST(AT91_REG *) 0x4008C214) // (PWMC_CH0) Channel Counter Register +#define AT91C_PWMC_CH0_CPRDR (AT91_CAST(AT91_REG *) 0x4008C20C) // (PWMC_CH0) Channel Period Register +#define AT91C_PWMC_CH0_DTUPDR (AT91_CAST(AT91_REG *) 0x4008C21C) // (PWMC_CH0) Channel Dead Time Update Value Register +#define AT91C_PWMC_CH0_CPRDUPDR (AT91_CAST(AT91_REG *) 0x4008C210) // (PWMC_CH0) Channel Period Update Register +#define AT91C_PWMC_CH0_CDTYUPDR (AT91_CAST(AT91_REG *) 0x4008C208) // (PWMC_CH0) Channel Duty Cycle Update Register +#define AT91C_PWMC_CH0_CDTYR (AT91_CAST(AT91_REG *) 0x4008C204) // (PWMC_CH0) Channel Duty Cycle Register +// ========== Register definition for PWMC_CH1 peripheral ========== +#define AT91C_PWMC_CH1_CCNTR (AT91_CAST(AT91_REG *) 0x4008C234) // (PWMC_CH1) Channel Counter Register +#define AT91C_PWMC_CH1_DTR (AT91_CAST(AT91_REG *) 0x4008C238) // (PWMC_CH1) Channel Dead Time Value Register +#define AT91C_PWMC_CH1_CDTYUPDR (AT91_CAST(AT91_REG *) 0x4008C228) // (PWMC_CH1) Channel Duty Cycle Update Register +#define AT91C_PWMC_CH1_DTUPDR (AT91_CAST(AT91_REG *) 0x4008C23C) // (PWMC_CH1) Channel Dead Time Update Value Register +#define AT91C_PWMC_CH1_CDTYR (AT91_CAST(AT91_REG *) 0x4008C224) // (PWMC_CH1) Channel Duty Cycle Register +#define AT91C_PWMC_CH1_CPRDR (AT91_CAST(AT91_REG *) 0x4008C22C) // (PWMC_CH1) Channel Period Register +#define AT91C_PWMC_CH1_CPRDUPDR (AT91_CAST(AT91_REG *) 0x4008C230) // (PWMC_CH1) Channel Period Update Register +#define AT91C_PWMC_CH1_CMR (AT91_CAST(AT91_REG *) 0x4008C220) // (PWMC_CH1) Channel Mode Register +// ========== Register definition for PWMC_CH2 peripheral ========== +#define AT91C_PWMC_CH2_CDTYR (AT91_CAST(AT91_REG *) 0x4008C244) // (PWMC_CH2) Channel Duty Cycle Register +#define AT91C_PWMC_CH2_DTUPDR (AT91_CAST(AT91_REG *) 0x4008C25C) // (PWMC_CH2) Channel Dead Time Update Value Register +#define AT91C_PWMC_CH2_CCNTR (AT91_CAST(AT91_REG *) 0x4008C254) // (PWMC_CH2) Channel Counter Register +#define AT91C_PWMC_CH2_CMR (AT91_CAST(AT91_REG *) 0x4008C240) // (PWMC_CH2) Channel Mode Register +#define AT91C_PWMC_CH2_CPRDR (AT91_CAST(AT91_REG *) 0x4008C24C) // (PWMC_CH2) Channel Period Register +#define AT91C_PWMC_CH2_CPRDUPDR (AT91_CAST(AT91_REG *) 0x4008C250) // (PWMC_CH2) Channel Period Update Register +#define AT91C_PWMC_CH2_CDTYUPDR (AT91_CAST(AT91_REG *) 0x4008C248) // (PWMC_CH2) Channel Duty Cycle Update Register +#define AT91C_PWMC_CH2_DTR (AT91_CAST(AT91_REG *) 0x4008C258) // (PWMC_CH2) Channel Dead Time Value Register +// ========== Register definition for PWMC_CH3 peripheral ========== +#define AT91C_PWMC_CH3_CPRDUPDR (AT91_CAST(AT91_REG *) 0x4008C270) // (PWMC_CH3) Channel Period Update Register +#define AT91C_PWMC_CH3_DTR (AT91_CAST(AT91_REG *) 0x4008C278) // (PWMC_CH3) Channel Dead Time Value Register +#define AT91C_PWMC_CH3_CDTYR (AT91_CAST(AT91_REG *) 0x4008C264) // (PWMC_CH3) Channel Duty Cycle Register +#define AT91C_PWMC_CH3_DTUPDR (AT91_CAST(AT91_REG *) 0x4008C27C) // (PWMC_CH3) Channel Dead Time Update Value Register +#define AT91C_PWMC_CH3_CDTYUPDR (AT91_CAST(AT91_REG *) 0x4008C268) // (PWMC_CH3) Channel Duty Cycle Update Register +#define AT91C_PWMC_CH3_CCNTR (AT91_CAST(AT91_REG *) 0x4008C274) // (PWMC_CH3) Channel Counter Register +#define AT91C_PWMC_CH3_CMR (AT91_CAST(AT91_REG *) 0x4008C260) // (PWMC_CH3) Channel Mode Register +#define AT91C_PWMC_CH3_CPRDR (AT91_CAST(AT91_REG *) 0x4008C26C) // (PWMC_CH3) Channel Period Register +// ========== Register definition for PWMC peripheral ========== +#define AT91C_PWMC_CMP6MUPD (AT91_CAST(AT91_REG *) 0x4008C19C) // (PWMC) PWM Comparison Mode 6 Update Register +#define AT91C_PWMC_ISR1 (AT91_CAST(AT91_REG *) 0x4008C01C) // (PWMC) PWMC Interrupt Status Register 1 +#define AT91C_PWMC_CMP5V (AT91_CAST(AT91_REG *) 0x4008C180) // (PWMC) PWM Comparison Value 5 Register +#define AT91C_PWMC_CMP4MUPD (AT91_CAST(AT91_REG *) 0x4008C17C) // (PWMC) PWM Comparison Mode 4 Update Register +#define AT91C_PWMC_FMR (AT91_CAST(AT91_REG *) 0x4008C05C) // (PWMC) PWM Fault Mode Register +#define AT91C_PWMC_CMP6V (AT91_CAST(AT91_REG *) 0x4008C190) // (PWMC) PWM Comparison Value 6 Register +#define AT91C_PWMC_EL4MR (AT91_CAST(AT91_REG *) 0x4008C08C) // (PWMC) PWM Event Line 4 Mode Register +#define AT91C_PWMC_UPCR (AT91_CAST(AT91_REG *) 0x4008C028) // (PWMC) PWM Update Control Register +#define AT91C_PWMC_CMP1VUPD (AT91_CAST(AT91_REG *) 0x4008C144) // (PWMC) PWM Comparison Value 1 Update Register +#define AT91C_PWMC_CMP0M (AT91_CAST(AT91_REG *) 0x4008C138) // (PWMC) PWM Comparison Mode 0 Register +#define AT91C_PWMC_CMP5VUPD (AT91_CAST(AT91_REG *) 0x4008C184) // (PWMC) PWM Comparison Value 5 Update Register +#define AT91C_PWMC_FPER3 (AT91_CAST(AT91_REG *) 0x4008C074) // (PWMC) PWM Fault Protection Enable Register 3 +#define AT91C_PWMC_OSCUPD (AT91_CAST(AT91_REG *) 0x4008C058) // (PWMC) PWM Output Selection Clear Update Register +#define AT91C_PWMC_FPER1 (AT91_CAST(AT91_REG *) 0x4008C06C) // (PWMC) PWM Fault Protection Enable Register 1 +#define AT91C_PWMC_SCUPUPD (AT91_CAST(AT91_REG *) 0x4008C030) // (PWMC) PWM Update Period Update Register +#define AT91C_PWMC_DIS (AT91_CAST(AT91_REG *) 0x4008C008) // (PWMC) PWMC Disable Register +#define AT91C_PWMC_IER1 (AT91_CAST(AT91_REG *) 0x4008C010) // (PWMC) PWMC Interrupt Enable Register 1 +#define AT91C_PWMC_IMR2 (AT91_CAST(AT91_REG *) 0x4008C03C) // (PWMC) PWMC Interrupt Mask Register 2 +#define AT91C_PWMC_CMP0V (AT91_CAST(AT91_REG *) 0x4008C130) // (PWMC) PWM Comparison Value 0 Register +#define AT91C_PWMC_SR (AT91_CAST(AT91_REG *) 0x4008C00C) // (PWMC) PWMC Status Register +#define AT91C_PWMC_CMP4M (AT91_CAST(AT91_REG *) 0x4008C178) // (PWMC) PWM Comparison Mode 4 Register +#define AT91C_PWMC_CMP3M (AT91_CAST(AT91_REG *) 0x4008C168) // (PWMC) PWM Comparison Mode 3 Register +#define AT91C_PWMC_IER2 (AT91_CAST(AT91_REG *) 0x4008C034) // (PWMC) PWMC Interrupt Enable Register 2 +#define AT91C_PWMC_CMP3VUPD (AT91_CAST(AT91_REG *) 0x4008C164) // (PWMC) PWM Comparison Value 3 Update Register +#define AT91C_PWMC_CMP2M (AT91_CAST(AT91_REG *) 0x4008C158) // (PWMC) PWM Comparison Mode 2 Register +#define AT91C_PWMC_IDR2 (AT91_CAST(AT91_REG *) 0x4008C038) // (PWMC) PWMC Interrupt Disable Register 2 +#define AT91C_PWMC_EL2MR (AT91_CAST(AT91_REG *) 0x4008C084) // (PWMC) PWM Event Line 2 Mode Register +#define AT91C_PWMC_CMP7V (AT91_CAST(AT91_REG *) 0x4008C1A0) // (PWMC) PWM Comparison Value 7 Register +#define AT91C_PWMC_CMP1M (AT91_CAST(AT91_REG *) 0x4008C148) // (PWMC) PWM Comparison Mode 1 Register +#define AT91C_PWMC_CMP0VUPD (AT91_CAST(AT91_REG *) 0x4008C134) // (PWMC) PWM Comparison Value 0 Update Register +#define AT91C_PWMC_WPSR (AT91_CAST(AT91_REG *) 0x4008C0E8) // (PWMC) PWM Write Protection Status Register +#define AT91C_PWMC_CMP6VUPD (AT91_CAST(AT91_REG *) 0x4008C194) // (PWMC) PWM Comparison Value 6 Update Register +#define AT91C_PWMC_CMP1MUPD (AT91_CAST(AT91_REG *) 0x4008C14C) // (PWMC) PWM Comparison Mode 1 Update Register +#define AT91C_PWMC_CMP1V (AT91_CAST(AT91_REG *) 0x4008C140) // (PWMC) PWM Comparison Value 1 Register +#define AT91C_PWMC_FCR (AT91_CAST(AT91_REG *) 0x4008C064) // (PWMC) PWM Fault Mode Clear Register +#define AT91C_PWMC_VER (AT91_CAST(AT91_REG *) 0x4008C0FC) // (PWMC) PWMC Version Register +#define AT91C_PWMC_EL1MR (AT91_CAST(AT91_REG *) 0x4008C080) // (PWMC) PWM Event Line 1 Mode Register +#define AT91C_PWMC_EL6MR (AT91_CAST(AT91_REG *) 0x4008C094) // (PWMC) PWM Event Line 6 Mode Register +#define AT91C_PWMC_ISR2 (AT91_CAST(AT91_REG *) 0x4008C040) // (PWMC) PWMC Interrupt Status Register 2 +#define AT91C_PWMC_CMP4VUPD (AT91_CAST(AT91_REG *) 0x4008C174) // (PWMC) PWM Comparison Value 4 Update Register +#define AT91C_PWMC_CMP5MUPD (AT91_CAST(AT91_REG *) 0x4008C18C) // (PWMC) PWM Comparison Mode 5 Update Register +#define AT91C_PWMC_OS (AT91_CAST(AT91_REG *) 0x4008C048) // (PWMC) PWM Output Selection Register +#define AT91C_PWMC_FPV (AT91_CAST(AT91_REG *) 0x4008C068) // (PWMC) PWM Fault Protection Value Register +#define AT91C_PWMC_FPER2 (AT91_CAST(AT91_REG *) 0x4008C070) // (PWMC) PWM Fault Protection Enable Register 2 +#define AT91C_PWMC_EL7MR (AT91_CAST(AT91_REG *) 0x4008C098) // (PWMC) PWM Event Line 7 Mode Register +#define AT91C_PWMC_OSSUPD (AT91_CAST(AT91_REG *) 0x4008C054) // (PWMC) PWM Output Selection Set Update Register +#define AT91C_PWMC_FEATURES (AT91_CAST(AT91_REG *) 0x4008C0F8) // (PWMC) PWMC FEATURES REGISTER +#define AT91C_PWMC_CMP2V (AT91_CAST(AT91_REG *) 0x4008C150) // (PWMC) PWM Comparison Value 2 Register +#define AT91C_PWMC_FSR (AT91_CAST(AT91_REG *) 0x4008C060) // (PWMC) PWM Fault Mode Status Register +#define AT91C_PWMC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x4008C0EC) // (PWMC) PWMC ADDRSIZE REGISTER +#define AT91C_PWMC_OSC (AT91_CAST(AT91_REG *) 0x4008C050) // (PWMC) PWM Output Selection Clear Register +#define AT91C_PWMC_SCUP (AT91_CAST(AT91_REG *) 0x4008C02C) // (PWMC) PWM Update Period Register +#define AT91C_PWMC_CMP7MUPD (AT91_CAST(AT91_REG *) 0x4008C1AC) // (PWMC) PWM Comparison Mode 7 Update Register +#define AT91C_PWMC_CMP2VUPD (AT91_CAST(AT91_REG *) 0x4008C154) // (PWMC) PWM Comparison Value 2 Update Register +#define AT91C_PWMC_FPER4 (AT91_CAST(AT91_REG *) 0x4008C078) // (PWMC) PWM Fault Protection Enable Register 4 +#define AT91C_PWMC_IMR1 (AT91_CAST(AT91_REG *) 0x4008C018) // (PWMC) PWMC Interrupt Mask Register 1 +#define AT91C_PWMC_EL3MR (AT91_CAST(AT91_REG *) 0x4008C088) // (PWMC) PWM Event Line 3 Mode Register +#define AT91C_PWMC_CMP3V (AT91_CAST(AT91_REG *) 0x4008C160) // (PWMC) PWM Comparison Value 3 Register +#define AT91C_PWMC_IPNAME1 (AT91_CAST(AT91_REG *) 0x4008C0F0) // (PWMC) PWMC IPNAME1 REGISTER +#define AT91C_PWMC_OSS (AT91_CAST(AT91_REG *) 0x4008C04C) // (PWMC) PWM Output Selection Set Register +#define AT91C_PWMC_CMP0MUPD (AT91_CAST(AT91_REG *) 0x4008C13C) // (PWMC) PWM Comparison Mode 0 Update Register +#define AT91C_PWMC_CMP2MUPD (AT91_CAST(AT91_REG *) 0x4008C15C) // (PWMC) PWM Comparison Mode 2 Update Register +#define AT91C_PWMC_CMP4V (AT91_CAST(AT91_REG *) 0x4008C170) // (PWMC) PWM Comparison Value 4 Register +#define AT91C_PWMC_ENA (AT91_CAST(AT91_REG *) 0x4008C004) // (PWMC) PWMC Enable Register +#define AT91C_PWMC_CMP3MUPD (AT91_CAST(AT91_REG *) 0x4008C16C) // (PWMC) PWM Comparison Mode 3 Update Register +#define AT91C_PWMC_EL0MR (AT91_CAST(AT91_REG *) 0x4008C07C) // (PWMC) PWM Event Line 0 Mode Register +#define AT91C_PWMC_OOV (AT91_CAST(AT91_REG *) 0x4008C044) // (PWMC) PWM Output Override Value Register +#define AT91C_PWMC_WPCR (AT91_CAST(AT91_REG *) 0x4008C0E4) // (PWMC) PWM Write Protection Enable Register +#define AT91C_PWMC_CMP7M (AT91_CAST(AT91_REG *) 0x4008C1A8) // (PWMC) PWM Comparison Mode 7 Register +#define AT91C_PWMC_CMP6M (AT91_CAST(AT91_REG *) 0x4008C198) // (PWMC) PWM Comparison Mode 6 Register +#define AT91C_PWMC_CMP5M (AT91_CAST(AT91_REG *) 0x4008C188) // (PWMC) PWM Comparison Mode 5 Register +#define AT91C_PWMC_IPNAME2 (AT91_CAST(AT91_REG *) 0x4008C0F4) // (PWMC) PWMC IPNAME2 REGISTER +#define AT91C_PWMC_CMP7VUPD (AT91_CAST(AT91_REG *) 0x4008C1A4) // (PWMC) PWM Comparison Value 7 Update Register +#define AT91C_PWMC_SYNC (AT91_CAST(AT91_REG *) 0x4008C020) // (PWMC) PWM Synchronized Channels Register +#define AT91C_PWMC_MR (AT91_CAST(AT91_REG *) 0x4008C000) // (PWMC) PWMC Mode Register +#define AT91C_PWMC_IDR1 (AT91_CAST(AT91_REG *) 0x4008C014) // (PWMC) PWMC Interrupt Disable Register 1 +#define AT91C_PWMC_EL5MR (AT91_CAST(AT91_REG *) 0x4008C090) // (PWMC) PWM Event Line 5 Mode Register +// ========== Register definition for SPI0 peripheral ========== +#define AT91C_SPI0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400080EC) // (SPI0) SPI ADDRSIZE REGISTER +#define AT91C_SPI0_RDR (AT91_CAST(AT91_REG *) 0x40008008) // (SPI0) Receive Data Register +#define AT91C_SPI0_FEATURES (AT91_CAST(AT91_REG *) 0x400080F8) // (SPI0) SPI FEATURES REGISTER +#define AT91C_SPI0_CR (AT91_CAST(AT91_REG *) 0x40008000) // (SPI0) Control Register +#define AT91C_SPI0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400080F0) // (SPI0) SPI IPNAME1 REGISTER +#define AT91C_SPI0_VER (AT91_CAST(AT91_REG *) 0x400080FC) // (SPI0) Version Register +#define AT91C_SPI0_IDR (AT91_CAST(AT91_REG *) 0x40008018) // (SPI0) Interrupt Disable Register +#define AT91C_SPI0_TDR (AT91_CAST(AT91_REG *) 0x4000800C) // (SPI0) Transmit Data Register +#define AT91C_SPI0_MR (AT91_CAST(AT91_REG *) 0x40008004) // (SPI0) Mode Register +#define AT91C_SPI0_IER (AT91_CAST(AT91_REG *) 0x40008014) // (SPI0) Interrupt Enable Register +#define AT91C_SPI0_IMR (AT91_CAST(AT91_REG *) 0x4000801C) // (SPI0) Interrupt Mask Register +#define AT91C_SPI0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400080F4) // (SPI0) SPI IPNAME2 REGISTER +#define AT91C_SPI0_CSR (AT91_CAST(AT91_REG *) 0x40008030) // (SPI0) Chip Select Register +#define AT91C_SPI0_SR (AT91_CAST(AT91_REG *) 0x40008010) // (SPI0) Status Register +// ========== Register definition for UDPHS_EPTFIFO peripheral ========== +#define AT91C_UDPHS_EPTFIFO_READEPT6 (AT91_CAST(AT91_REG *) 0x201E0000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 6 +#define AT91C_UDPHS_EPTFIFO_READEPT2 (AT91_CAST(AT91_REG *) 0x201A0000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 2 +#define AT91C_UDPHS_EPTFIFO_READEPT1 (AT91_CAST(AT91_REG *) 0x20190000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 1 +#define AT91C_UDPHS_EPTFIFO_READEPT0 (AT91_CAST(AT91_REG *) 0x20180000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 0 +#define AT91C_UDPHS_EPTFIFO_READEPT5 (AT91_CAST(AT91_REG *) 0x201D0000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 5 +#define AT91C_UDPHS_EPTFIFO_READEPT4 (AT91_CAST(AT91_REG *) 0x201C0000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 4 +#define AT91C_UDPHS_EPTFIFO_READEPT3 (AT91_CAST(AT91_REG *) 0x201B0000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 3 +// ========== Register definition for UDPHS_EPT_0 peripheral ========== +#define AT91C_UDPHS_EPT_0_EPTCTL (AT91_CAST(AT91_REG *) 0x400A410C) // (UDPHS_EPT_0) UDPHS Endpoint Control Register +#define AT91C_UDPHS_EPT_0_EPTSTA (AT91_CAST(AT91_REG *) 0x400A411C) // (UDPHS_EPT_0) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_0_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A4118) // (UDPHS_EPT_0) UDPHS Endpoint Clear Status Register +#define AT91C_UDPHS_EPT_0_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A4108) // (UDPHS_EPT_0) UDPHS Endpoint Control Disable Register +#define AT91C_UDPHS_EPT_0_EPTCFG (AT91_CAST(AT91_REG *) 0x400A4100) // (UDPHS_EPT_0) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_0_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A4114) // (UDPHS_EPT_0) UDPHS Endpoint Set Status Register +#define AT91C_UDPHS_EPT_0_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A4104) // (UDPHS_EPT_0) UDPHS Endpoint Control Enable Register +// ========== Register definition for UDPHS_EPT_1 peripheral ========== +#define AT91C_UDPHS_EPT_1_EPTSTA (AT91_CAST(AT91_REG *) 0x400A413C) // (UDPHS_EPT_1) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_1_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A4134) // (UDPHS_EPT_1) UDPHS Endpoint Set Status Register +#define AT91C_UDPHS_EPT_1_EPTCTL (AT91_CAST(AT91_REG *) 0x400A412C) // (UDPHS_EPT_1) UDPHS Endpoint Control Register +#define AT91C_UDPHS_EPT_1_EPTCFG (AT91_CAST(AT91_REG *) 0x400A4120) // (UDPHS_EPT_1) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_1_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A4128) // (UDPHS_EPT_1) UDPHS Endpoint Control Disable Register +#define AT91C_UDPHS_EPT_1_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A4138) // (UDPHS_EPT_1) UDPHS Endpoint Clear Status Register +#define AT91C_UDPHS_EPT_1_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A4124) // (UDPHS_EPT_1) UDPHS Endpoint Control Enable Register +// ========== Register definition for UDPHS_EPT_2 peripheral ========== +#define AT91C_UDPHS_EPT_2_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A4144) // (UDPHS_EPT_2) UDPHS Endpoint Control Enable Register +#define AT91C_UDPHS_EPT_2_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A4158) // (UDPHS_EPT_2) UDPHS Endpoint Clear Status Register +#define AT91C_UDPHS_EPT_2_EPTCFG (AT91_CAST(AT91_REG *) 0x400A4140) // (UDPHS_EPT_2) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_2_EPTCTL (AT91_CAST(AT91_REG *) 0x400A414C) // (UDPHS_EPT_2) UDPHS Endpoint Control Register +#define AT91C_UDPHS_EPT_2_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A4154) // (UDPHS_EPT_2) UDPHS Endpoint Set Status Register +#define AT91C_UDPHS_EPT_2_EPTSTA (AT91_CAST(AT91_REG *) 0x400A415C) // (UDPHS_EPT_2) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_2_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A4148) // (UDPHS_EPT_2) UDPHS Endpoint Control Disable Register +// ========== Register definition for UDPHS_EPT_3 peripheral ========== +#define AT91C_UDPHS_EPT_3_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A4168) // (UDPHS_EPT_3) UDPHS Endpoint Control Disable Register +#define AT91C_UDPHS_EPT_3_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A4164) // (UDPHS_EPT_3) UDPHS Endpoint Control Enable Register +#define AT91C_UDPHS_EPT_3_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A4174) // (UDPHS_EPT_3) UDPHS Endpoint Set Status Register +#define AT91C_UDPHS_EPT_3_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A4178) // (UDPHS_EPT_3) UDPHS Endpoint Clear Status Register +#define AT91C_UDPHS_EPT_3_EPTCFG (AT91_CAST(AT91_REG *) 0x400A4160) // (UDPHS_EPT_3) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_3_EPTSTA (AT91_CAST(AT91_REG *) 0x400A417C) // (UDPHS_EPT_3) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_3_EPTCTL (AT91_CAST(AT91_REG *) 0x400A416C) // (UDPHS_EPT_3) UDPHS Endpoint Control Register +// ========== Register definition for UDPHS_EPT_4 peripheral ========== +#define AT91C_UDPHS_EPT_4_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A4194) // (UDPHS_EPT_4) UDPHS Endpoint Set Status Register +#define AT91C_UDPHS_EPT_4_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A4188) // (UDPHS_EPT_4) UDPHS Endpoint Control Disable Register +#define AT91C_UDPHS_EPT_4_EPTCTL (AT91_CAST(AT91_REG *) 0x400A418C) // (UDPHS_EPT_4) UDPHS Endpoint Control Register +#define AT91C_UDPHS_EPT_4_EPTCFG (AT91_CAST(AT91_REG *) 0x400A4180) // (UDPHS_EPT_4) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_4_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A4184) // (UDPHS_EPT_4) UDPHS Endpoint Control Enable Register +#define AT91C_UDPHS_EPT_4_EPTSTA (AT91_CAST(AT91_REG *) 0x400A419C) // (UDPHS_EPT_4) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_4_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A4198) // (UDPHS_EPT_4) UDPHS Endpoint Clear Status Register +// ========== Register definition for UDPHS_EPT_5 peripheral ========== +#define AT91C_UDPHS_EPT_5_EPTCFG (AT91_CAST(AT91_REG *) 0x400A41A0) // (UDPHS_EPT_5) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_5_EPTCTL (AT91_CAST(AT91_REG *) 0x400A41AC) // (UDPHS_EPT_5) UDPHS Endpoint Control Register +#define AT91C_UDPHS_EPT_5_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A41A4) // (UDPHS_EPT_5) UDPHS Endpoint Control Enable Register +#define AT91C_UDPHS_EPT_5_EPTSTA (AT91_CAST(AT91_REG *) 0x400A41BC) // (UDPHS_EPT_5) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_5_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A41B4) // (UDPHS_EPT_5) UDPHS Endpoint Set Status Register +#define AT91C_UDPHS_EPT_5_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A41A8) // (UDPHS_EPT_5) UDPHS Endpoint Control Disable Register +#define AT91C_UDPHS_EPT_5_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A41B8) // (UDPHS_EPT_5) UDPHS Endpoint Clear Status Register +// ========== Register definition for UDPHS_EPT_6 peripheral ========== +#define AT91C_UDPHS_EPT_6_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A41D8) // (UDPHS_EPT_6) UDPHS Endpoint Clear Status Register +#define AT91C_UDPHS_EPT_6_EPTCTL (AT91_CAST(AT91_REG *) 0x400A41CC) // (UDPHS_EPT_6) UDPHS Endpoint Control Register +#define AT91C_UDPHS_EPT_6_EPTCFG (AT91_CAST(AT91_REG *) 0x400A41C0) // (UDPHS_EPT_6) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_6_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A41C8) // (UDPHS_EPT_6) UDPHS Endpoint Control Disable Register +#define AT91C_UDPHS_EPT_6_EPTSTA (AT91_CAST(AT91_REG *) 0x400A41DC) // (UDPHS_EPT_6) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_6_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A41C4) // (UDPHS_EPT_6) UDPHS Endpoint Control Enable Register +#define AT91C_UDPHS_EPT_6_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A41D4) // (UDPHS_EPT_6) UDPHS Endpoint Set Status Register +// ========== Register definition for UDPHS_DMA_1 peripheral ========== +#define AT91C_UDPHS_DMA_1_DMASTATUS (AT91_CAST(AT91_REG *) 0x400A431C) // (UDPHS_DMA_1) UDPHS DMA Channel Status Register +#define AT91C_UDPHS_DMA_1_DMACONTROL (AT91_CAST(AT91_REG *) 0x400A4318) // (UDPHS_DMA_1) UDPHS DMA Channel Control Register +#define AT91C_UDPHS_DMA_1_DMANXTDSC (AT91_CAST(AT91_REG *) 0x400A4310) // (UDPHS_DMA_1) UDPHS DMA Channel Next Descriptor Address +#define AT91C_UDPHS_DMA_1_DMAADDRESS (AT91_CAST(AT91_REG *) 0x400A4314) // (UDPHS_DMA_1) UDPHS DMA Channel Address Register +// ========== Register definition for UDPHS_DMA_2 peripheral ========== +#define AT91C_UDPHS_DMA_2_DMASTATUS (AT91_CAST(AT91_REG *) 0x400A432C) // (UDPHS_DMA_2) UDPHS DMA Channel Status Register +#define AT91C_UDPHS_DMA_2_DMANXTDSC (AT91_CAST(AT91_REG *) 0x400A4320) // (UDPHS_DMA_2) UDPHS DMA Channel Next Descriptor Address +#define AT91C_UDPHS_DMA_2_DMACONTROL (AT91_CAST(AT91_REG *) 0x400A4328) // (UDPHS_DMA_2) UDPHS DMA Channel Control Register +#define AT91C_UDPHS_DMA_2_DMAADDRESS (AT91_CAST(AT91_REG *) 0x400A4324) // (UDPHS_DMA_2) UDPHS DMA Channel Address Register +// ========== Register definition for UDPHS_DMA_3 peripheral ========== +#define AT91C_UDPHS_DMA_3_DMACONTROL (AT91_CAST(AT91_REG *) 0x400A4338) // (UDPHS_DMA_3) UDPHS DMA Channel Control Register +#define AT91C_UDPHS_DMA_3_DMANXTDSC (AT91_CAST(AT91_REG *) 0x400A4330) // (UDPHS_DMA_3) UDPHS DMA Channel Next Descriptor Address +#define AT91C_UDPHS_DMA_3_DMASTATUS (AT91_CAST(AT91_REG *) 0x400A433C) // (UDPHS_DMA_3) UDPHS DMA Channel Status Register +#define AT91C_UDPHS_DMA_3_DMAADDRESS (AT91_CAST(AT91_REG *) 0x400A4334) // (UDPHS_DMA_3) UDPHS DMA Channel Address Register +// ========== Register definition for UDPHS_DMA_4 peripheral ========== +#define AT91C_UDPHS_DMA_4_DMAADDRESS (AT91_CAST(AT91_REG *) 0x400A4344) // (UDPHS_DMA_4) UDPHS DMA Channel Address Register +#define AT91C_UDPHS_DMA_4_DMANXTDSC (AT91_CAST(AT91_REG *) 0x400A4340) // (UDPHS_DMA_4) UDPHS DMA Channel Next Descriptor Address +#define AT91C_UDPHS_DMA_4_DMASTATUS (AT91_CAST(AT91_REG *) 0x400A434C) // (UDPHS_DMA_4) UDPHS DMA Channel Status Register +#define AT91C_UDPHS_DMA_4_DMACONTROL (AT91_CAST(AT91_REG *) 0x400A4348) // (UDPHS_DMA_4) UDPHS DMA Channel Control Register +// ========== Register definition for UDPHS_DMA_5 peripheral ========== +#define AT91C_UDPHS_DMA_5_DMACONTROL (AT91_CAST(AT91_REG *) 0x400A4358) // (UDPHS_DMA_5) UDPHS DMA Channel Control Register +#define AT91C_UDPHS_DMA_5_DMAADDRESS (AT91_CAST(AT91_REG *) 0x400A4354) // (UDPHS_DMA_5) UDPHS DMA Channel Address Register +#define AT91C_UDPHS_DMA_5_DMANXTDSC (AT91_CAST(AT91_REG *) 0x400A4350) // (UDPHS_DMA_5) UDPHS DMA Channel Next Descriptor Address +#define AT91C_UDPHS_DMA_5_DMASTATUS (AT91_CAST(AT91_REG *) 0x400A435C) // (UDPHS_DMA_5) UDPHS DMA Channel Status Register +// ========== Register definition for UDPHS_DMA_6 peripheral ========== +#define AT91C_UDPHS_DMA_6_DMASTATUS (AT91_CAST(AT91_REG *) 0x400A436C) // (UDPHS_DMA_6) UDPHS DMA Channel Status Register +#define AT91C_UDPHS_DMA_6_DMACONTROL (AT91_CAST(AT91_REG *) 0x400A4368) // (UDPHS_DMA_6) UDPHS DMA Channel Control Register +#define AT91C_UDPHS_DMA_6_DMANXTDSC (AT91_CAST(AT91_REG *) 0x400A4360) // (UDPHS_DMA_6) UDPHS DMA Channel Next Descriptor Address +#define AT91C_UDPHS_DMA_6_DMAADDRESS (AT91_CAST(AT91_REG *) 0x400A4364) // (UDPHS_DMA_6) UDPHS DMA Channel Address Register +// ========== Register definition for UDPHS peripheral ========== +#define AT91C_UDPHS_EPTRST (AT91_CAST(AT91_REG *) 0x400A401C) // (UDPHS) UDPHS Endpoints Reset Register +#define AT91C_UDPHS_IEN (AT91_CAST(AT91_REG *) 0x400A4010) // (UDPHS) UDPHS Interrupt Enable Register +#define AT91C_UDPHS_TSTCNTB (AT91_CAST(AT91_REG *) 0x400A40D8) // (UDPHS) UDPHS Test B Counter Register +#define AT91C_UDPHS_RIPNAME2 (AT91_CAST(AT91_REG *) 0x400A40F4) // (UDPHS) UDPHS Name2 Register +#define AT91C_UDPHS_RIPPADDRSIZE (AT91_CAST(AT91_REG *) 0x400A40EC) // (UDPHS) UDPHS PADDRSIZE Register +#define AT91C_UDPHS_TSTMODREG (AT91_CAST(AT91_REG *) 0x400A40DC) // (UDPHS) UDPHS Test Mode Register +#define AT91C_UDPHS_TST (AT91_CAST(AT91_REG *) 0x400A40E0) // (UDPHS) UDPHS Test Register +#define AT91C_UDPHS_TSTSOFCNT (AT91_CAST(AT91_REG *) 0x400A40D0) // (UDPHS) UDPHS Test SOF Counter Register +#define AT91C_UDPHS_FNUM (AT91_CAST(AT91_REG *) 0x400A4004) // (UDPHS) UDPHS Frame Number Register +#define AT91C_UDPHS_TSTCNTA (AT91_CAST(AT91_REG *) 0x400A40D4) // (UDPHS) UDPHS Test A Counter Register +#define AT91C_UDPHS_INTSTA (AT91_CAST(AT91_REG *) 0x400A4014) // (UDPHS) UDPHS Interrupt Status Register +#define AT91C_UDPHS_IPFEATURES (AT91_CAST(AT91_REG *) 0x400A40F8) // (UDPHS) UDPHS Features Register +#define AT91C_UDPHS_CLRINT (AT91_CAST(AT91_REG *) 0x400A4018) // (UDPHS) UDPHS Clear Interrupt Register +#define AT91C_UDPHS_RIPNAME1 (AT91_CAST(AT91_REG *) 0x400A40F0) // (UDPHS) UDPHS Name1 Register +#define AT91C_UDPHS_CTRL (AT91_CAST(AT91_REG *) 0x400A4000) // (UDPHS) UDPHS Control Register +#define AT91C_UDPHS_IPVERSION (AT91_CAST(AT91_REG *) 0x400A40FC) // (UDPHS) UDPHS Version Register +// ========== Register definition for HDMA_CH_0 peripheral ========== +#define AT91C_HDMA_CH_0_CADDR (AT91_CAST(AT91_REG *) 0x400B0060) // (HDMA_CH_0) HDMA Reserved +#define AT91C_HDMA_CH_0_DADDR (AT91_CAST(AT91_REG *) 0x400B0040) // (HDMA_CH_0) HDMA Channel Destination Address Register +#define AT91C_HDMA_CH_0_BDSCR (AT91_CAST(AT91_REG *) 0x400B005C) // (HDMA_CH_0) HDMA Reserved +#define AT91C_HDMA_CH_0_CFG (AT91_CAST(AT91_REG *) 0x400B0050) // (HDMA_CH_0) HDMA Channel Configuration Register +#define AT91C_HDMA_CH_0_CTRLB (AT91_CAST(AT91_REG *) 0x400B004C) // (HDMA_CH_0) HDMA Channel Control B Register +#define AT91C_HDMA_CH_0_CTRLA (AT91_CAST(AT91_REG *) 0x400B0048) // (HDMA_CH_0) HDMA Channel Control A Register +#define AT91C_HDMA_CH_0_DSCR (AT91_CAST(AT91_REG *) 0x400B0044) // (HDMA_CH_0) HDMA Channel Descriptor Address Register +#define AT91C_HDMA_CH_0_SADDR (AT91_CAST(AT91_REG *) 0x400B003C) // (HDMA_CH_0) HDMA Channel Source Address Register +#define AT91C_HDMA_CH_0_DPIP (AT91_CAST(AT91_REG *) 0x400B0058) // (HDMA_CH_0) HDMA Channel Destination Picture in Picture Configuration Register +#define AT91C_HDMA_CH_0_SPIP (AT91_CAST(AT91_REG *) 0x400B0054) // (HDMA_CH_0) HDMA Channel Source Picture in Picture Configuration Register +// ========== Register definition for HDMA_CH_1 peripheral ========== +#define AT91C_HDMA_CH_1_DSCR (AT91_CAST(AT91_REG *) 0x400B006C) // (HDMA_CH_1) HDMA Channel Descriptor Address Register +#define AT91C_HDMA_CH_1_BDSCR (AT91_CAST(AT91_REG *) 0x400B0084) // (HDMA_CH_1) HDMA Reserved +#define AT91C_HDMA_CH_1_CTRLB (AT91_CAST(AT91_REG *) 0x400B0074) // (HDMA_CH_1) HDMA Channel Control B Register +#define AT91C_HDMA_CH_1_SPIP (AT91_CAST(AT91_REG *) 0x400B007C) // (HDMA_CH_1) HDMA Channel Source Picture in Picture Configuration Register +#define AT91C_HDMA_CH_1_SADDR (AT91_CAST(AT91_REG *) 0x400B0064) // (HDMA_CH_1) HDMA Channel Source Address Register +#define AT91C_HDMA_CH_1_DPIP (AT91_CAST(AT91_REG *) 0x400B0080) // (HDMA_CH_1) HDMA Channel Destination Picture in Picture Configuration Register +#define AT91C_HDMA_CH_1_CFG (AT91_CAST(AT91_REG *) 0x400B0078) // (HDMA_CH_1) HDMA Channel Configuration Register +#define AT91C_HDMA_CH_1_DADDR (AT91_CAST(AT91_REG *) 0x400B0068) // (HDMA_CH_1) HDMA Channel Destination Address Register +#define AT91C_HDMA_CH_1_CADDR (AT91_CAST(AT91_REG *) 0x400B0088) // (HDMA_CH_1) HDMA Reserved +#define AT91C_HDMA_CH_1_CTRLA (AT91_CAST(AT91_REG *) 0x400B0070) // (HDMA_CH_1) HDMA Channel Control A Register +// ========== Register definition for HDMA_CH_2 peripheral ========== +#define AT91C_HDMA_CH_2_BDSCR (AT91_CAST(AT91_REG *) 0x400B00AC) // (HDMA_CH_2) HDMA Reserved +#define AT91C_HDMA_CH_2_CTRLB (AT91_CAST(AT91_REG *) 0x400B009C) // (HDMA_CH_2) HDMA Channel Control B Register +#define AT91C_HDMA_CH_2_CADDR (AT91_CAST(AT91_REG *) 0x400B00B0) // (HDMA_CH_2) HDMA Reserved +#define AT91C_HDMA_CH_2_CFG (AT91_CAST(AT91_REG *) 0x400B00A0) // (HDMA_CH_2) HDMA Channel Configuration Register +#define AT91C_HDMA_CH_2_CTRLA (AT91_CAST(AT91_REG *) 0x400B0098) // (HDMA_CH_2) HDMA Channel Control A Register +#define AT91C_HDMA_CH_2_SADDR (AT91_CAST(AT91_REG *) 0x400B008C) // (HDMA_CH_2) HDMA Channel Source Address Register +#define AT91C_HDMA_CH_2_DPIP (AT91_CAST(AT91_REG *) 0x400B00A8) // (HDMA_CH_2) HDMA Channel Destination Picture in Picture Configuration Register +#define AT91C_HDMA_CH_2_DADDR (AT91_CAST(AT91_REG *) 0x400B0090) // (HDMA_CH_2) HDMA Channel Destination Address Register +#define AT91C_HDMA_CH_2_SPIP (AT91_CAST(AT91_REG *) 0x400B00A4) // (HDMA_CH_2) HDMA Channel Source Picture in Picture Configuration Register +#define AT91C_HDMA_CH_2_DSCR (AT91_CAST(AT91_REG *) 0x400B0094) // (HDMA_CH_2) HDMA Channel Descriptor Address Register +// ========== Register definition for HDMA_CH_3 peripheral ========== +#define AT91C_HDMA_CH_3_DSCR (AT91_CAST(AT91_REG *) 0x400B00BC) // (HDMA_CH_3) HDMA Channel Descriptor Address Register +#define AT91C_HDMA_CH_3_SADDR (AT91_CAST(AT91_REG *) 0x400B00B4) // (HDMA_CH_3) HDMA Channel Source Address Register +#define AT91C_HDMA_CH_3_BDSCR (AT91_CAST(AT91_REG *) 0x400B00D4) // (HDMA_CH_3) HDMA Reserved +#define AT91C_HDMA_CH_3_CTRLA (AT91_CAST(AT91_REG *) 0x400B00C0) // (HDMA_CH_3) HDMA Channel Control A Register +#define AT91C_HDMA_CH_3_DPIP (AT91_CAST(AT91_REG *) 0x400B00D0) // (HDMA_CH_3) HDMA Channel Destination Picture in Picture Configuration Register +#define AT91C_HDMA_CH_3_CTRLB (AT91_CAST(AT91_REG *) 0x400B00C4) // (HDMA_CH_3) HDMA Channel Control B Register +#define AT91C_HDMA_CH_3_SPIP (AT91_CAST(AT91_REG *) 0x400B00CC) // (HDMA_CH_3) HDMA Channel Source Picture in Picture Configuration Register +#define AT91C_HDMA_CH_3_CFG (AT91_CAST(AT91_REG *) 0x400B00C8) // (HDMA_CH_3) HDMA Channel Configuration Register +#define AT91C_HDMA_CH_3_CADDR (AT91_CAST(AT91_REG *) 0x400B00D8) // (HDMA_CH_3) HDMA Reserved +#define AT91C_HDMA_CH_3_DADDR (AT91_CAST(AT91_REG *) 0x400B00B8) // (HDMA_CH_3) HDMA Channel Destination Address Register +// ========== Register definition for HDMA peripheral ========== +#define AT91C_HDMA_SYNC (AT91_CAST(AT91_REG *) 0x400B0014) // (HDMA) HDMA Request Synchronization Register +#define AT91C_HDMA_VER (AT91_CAST(AT91_REG *) 0x400B01FC) // (HDMA) HDMA VERSION REGISTER +#define AT91C_HDMA_RSVD0 (AT91_CAST(AT91_REG *) 0x400B0034) // (HDMA) HDMA Reserved +#define AT91C_HDMA_CHSR (AT91_CAST(AT91_REG *) 0x400B0030) // (HDMA) HDMA Channel Handler Status Register +#define AT91C_HDMA_IPNAME2 (AT91_CAST(AT91_REG *) 0x400B01F4) // (HDMA) HDMA IPNAME2 REGISTER +#define AT91C_HDMA_EBCIMR (AT91_CAST(AT91_REG *) 0x400B0020) // (HDMA) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Mask Register +#define AT91C_HDMA_CHDR (AT91_CAST(AT91_REG *) 0x400B002C) // (HDMA) HDMA Channel Handler Disable Register +#define AT91C_HDMA_EN (AT91_CAST(AT91_REG *) 0x400B0004) // (HDMA) HDMA Controller Enable Register +#define AT91C_HDMA_GCFG (AT91_CAST(AT91_REG *) 0x400B0000) // (HDMA) HDMA Global Configuration Register +#define AT91C_HDMA_IPNAME1 (AT91_CAST(AT91_REG *) 0x400B01F0) // (HDMA) HDMA IPNAME1 REGISTER +#define AT91C_HDMA_LAST (AT91_CAST(AT91_REG *) 0x400B0010) // (HDMA) HDMA Software Last Transfer Flag Register +#define AT91C_HDMA_FEATURES (AT91_CAST(AT91_REG *) 0x400B01F8) // (HDMA) HDMA FEATURES REGISTER +#define AT91C_HDMA_CREQ (AT91_CAST(AT91_REG *) 0x400B000C) // (HDMA) HDMA Software Chunk Transfer Request Register +#define AT91C_HDMA_EBCIER (AT91_CAST(AT91_REG *) 0x400B0018) // (HDMA) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Interrupt Enable register +#define AT91C_HDMA_CHER (AT91_CAST(AT91_REG *) 0x400B0028) // (HDMA) HDMA Channel Handler Enable Register +#define AT91C_HDMA_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400B01EC) // (HDMA) HDMA ADDRSIZE REGISTER +#define AT91C_HDMA_EBCISR (AT91_CAST(AT91_REG *) 0x400B0024) // (HDMA) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Status Register +#define AT91C_HDMA_SREQ (AT91_CAST(AT91_REG *) 0x400B0008) // (HDMA) HDMA Software Single Request Register +#define AT91C_HDMA_EBCIDR (AT91_CAST(AT91_REG *) 0x400B001C) // (HDMA) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Interrupt Disable register +#define AT91C_HDMA_RSVD1 (AT91_CAST(AT91_REG *) 0x400B0038) // (HDMA) HDMA Reserved + +// ***************************************************************************** +// PIO DEFINITIONS FOR AT91SAM3U4 +// ***************************************************************************** +#define AT91C_PIO_PA0 (1 << 0) // Pin Controlled by PA0 +#define AT91C_PA0_TIOB0 (AT91C_PIO_PA0) // +#define AT91C_PA0_SPI0_NPCS1 (AT91C_PIO_PA0) // +#define AT91C_PIO_PA1 (1 << 1) // Pin Controlled by PA1 +#define AT91C_PA1_TIOA0 (AT91C_PIO_PA1) // +#define AT91C_PA1_SPI0_NPCS2 (AT91C_PIO_PA1) // +#define AT91C_PIO_PA10 (1 << 10) // Pin Controlled by PA10 +#define AT91C_PA10_TWCK0 (AT91C_PIO_PA10) // +#define AT91C_PA10_PWML3 (AT91C_PIO_PA10) // +#define AT91C_PIO_PA11 (1 << 11) // Pin Controlled by PA11 +#define AT91C_PA11_DRXD (AT91C_PIO_PA11) // +#define AT91C_PIO_PA12 (1 << 12) // Pin Controlled by PA12 +#define AT91C_PA12_DTXD (AT91C_PIO_PA12) // +#define AT91C_PIO_PA13 (1 << 13) // Pin Controlled by PA13 +#define AT91C_PA13_SPI0_MISO (AT91C_PIO_PA13) // +#define AT91C_PIO_PA14 (1 << 14) // Pin Controlled by PA14 +#define AT91C_PA14_SPI0_MOSI (AT91C_PIO_PA14) // +#define AT91C_PIO_PA15 (1 << 15) // Pin Controlled by PA15 +#define AT91C_PA15_SPI0_SPCK (AT91C_PIO_PA15) // +#define AT91C_PA15_PWMH2 (AT91C_PIO_PA15) // +#define AT91C_PIO_PA16 (1 << 16) // Pin Controlled by PA16 +#define AT91C_PA16_SPI0_NPCS0 (AT91C_PIO_PA16) // +#define AT91C_PA16_NCS1 (AT91C_PIO_PA16) // +#define AT91C_PIO_PA17 (1 << 17) // Pin Controlled by PA17 +#define AT91C_PA17_SCK0 (AT91C_PIO_PA17) // +#define AT91C_PA17_ADTRG0 (AT91C_PIO_PA17) // +#define AT91C_PIO_PA18 (1 << 18) // Pin Controlled by PA18 +#define AT91C_PA18_TXD0 (AT91C_PIO_PA18) // +#define AT91C_PIO_PA19 (1 << 19) // Pin Controlled by PA19 +#define AT91C_PA19_RXD0 (AT91C_PIO_PA19) // +#define AT91C_PA19_SPI0_NPCS3 (AT91C_PIO_PA19) // +#define AT91C_PIO_PA2 (1 << 2) // Pin Controlled by PA2 +#define AT91C_PA2_TCLK0 (AT91C_PIO_PA2) // +#define AT91C_PA2_ADTRG1 (AT91C_PIO_PA2) // +#define AT91C_PIO_PA20 (1 << 20) // Pin Controlled by PA20 +#define AT91C_PA20_TXD1 (AT91C_PIO_PA20) // +#define AT91C_PA20_PWMH3 (AT91C_PIO_PA20) // +#define AT91C_PIO_PA21 (1 << 21) // Pin Controlled by PA21 +#define AT91C_PA21_RXD1 (AT91C_PIO_PA21) // +#define AT91C_PA21_PCK0 (AT91C_PIO_PA21) // +#define AT91C_PIO_PA22 (1 << 22) // Pin Controlled by PA22 +#define AT91C_PA22_TXD2 (AT91C_PIO_PA22) // +#define AT91C_PA22_RTS1 (AT91C_PIO_PA22) // +#define AT91C_PIO_PA23 (1 << 23) // Pin Controlled by PA23 +#define AT91C_PA23_RXD2 (AT91C_PIO_PA23) // +#define AT91C_PA23_CTS1 (AT91C_PIO_PA23) // +#define AT91C_PIO_PA24 (1 << 24) // Pin Controlled by PA24 +#define AT91C_PA24_TWD1 (AT91C_PIO_PA24) // +#define AT91C_PA24_SCK1 (AT91C_PIO_PA24) // +#define AT91C_PIO_PA25 (1 << 25) // Pin Controlled by PA25 +#define AT91C_PA25_TWCK1 (AT91C_PIO_PA25) // +#define AT91C_PA25_SCK2 (AT91C_PIO_PA25) // +#define AT91C_PIO_PA26 (1 << 26) // Pin Controlled by PA26 +#define AT91C_PA26_TD0 (AT91C_PIO_PA26) // +#define AT91C_PA26_TCLK2 (AT91C_PIO_PA26) // +#define AT91C_PIO_PA27 (1 << 27) // Pin Controlled by PA27 +#define AT91C_PA27_RD0 (AT91C_PIO_PA27) // +#define AT91C_PA27_PCK0 (AT91C_PIO_PA27) // +#define AT91C_PIO_PA28 (1 << 28) // Pin Controlled by PA28 +#define AT91C_PA28_TK0 (AT91C_PIO_PA28) // +#define AT91C_PA28_PWMH0 (AT91C_PIO_PA28) // +#define AT91C_PIO_PA29 (1 << 29) // Pin Controlled by PA29 +#define AT91C_PA29_RK0 (AT91C_PIO_PA29) // +#define AT91C_PA29_PWMH1 (AT91C_PIO_PA29) // +#define AT91C_PIO_PA3 (1 << 3) // Pin Controlled by PA3 +#define AT91C_PA3_MCI0_CK (AT91C_PIO_PA3) // +#define AT91C_PA3_PCK1 (AT91C_PIO_PA3) // +#define AT91C_PIO_PA30 (1 << 30) // Pin Controlled by PA30 +#define AT91C_PA30_TF0 (AT91C_PIO_PA30) // +#define AT91C_PA30_TIOA2 (AT91C_PIO_PA30) // +#define AT91C_PIO_PA31 (1 << 31) // Pin Controlled by PA31 +#define AT91C_PA31_RF0 (AT91C_PIO_PA31) // +#define AT91C_PA31_TIOB2 (AT91C_PIO_PA31) // +#define AT91C_PIO_PA4 (1 << 4) // Pin Controlled by PA4 +#define AT91C_PA4_MCI0_CDA (AT91C_PIO_PA4) // +#define AT91C_PA4_PWMH0 (AT91C_PIO_PA4) // +#define AT91C_PIO_PA5 (1 << 5) // Pin Controlled by PA5 +#define AT91C_PA5_MCI0_DA0 (AT91C_PIO_PA5) // +#define AT91C_PA5_PWMH1 (AT91C_PIO_PA5) // +#define AT91C_PIO_PA6 (1 << 6) // Pin Controlled by PA6 +#define AT91C_PA6_MCI0_DA1 (AT91C_PIO_PA6) // +#define AT91C_PA6_PWMH2 (AT91C_PIO_PA6) // +#define AT91C_PIO_PA7 (1 << 7) // Pin Controlled by PA7 +#define AT91C_PA7_MCI0_DA2 (AT91C_PIO_PA7) // +#define AT91C_PA7_PWML0 (AT91C_PIO_PA7) // +#define AT91C_PIO_PA8 (1 << 8) // Pin Controlled by PA8 +#define AT91C_PA8_MCI0_DA3 (AT91C_PIO_PA8) // +#define AT91C_PA8_PWML1 (AT91C_PIO_PA8) // +#define AT91C_PIO_PA9 (1 << 9) // Pin Controlled by PA9 +#define AT91C_PA9_TWD0 (AT91C_PIO_PA9) // +#define AT91C_PA9_PWML2 (AT91C_PIO_PA9) // +#define AT91C_PIO_PB0 (1 << 0) // Pin Controlled by PB0 +#define AT91C_PB0_PWMH0 (AT91C_PIO_PB0) // +#define AT91C_PB0_A2 (AT91C_PIO_PB0) // +#define AT91C_PIO_PB1 (1 << 1) // Pin Controlled by PB1 +#define AT91C_PB1_PWMH1 (AT91C_PIO_PB1) // +#define AT91C_PB1_A3 (AT91C_PIO_PB1) // +#define AT91C_PIO_PB10 (1 << 10) // Pin Controlled by PB10 +#define AT91C_PB10_D1 (AT91C_PIO_PB10) // +#define AT91C_PB10_DSR0 (AT91C_PIO_PB10) // +#define AT91C_PIO_PB11 (1 << 11) // Pin Controlled by PB11 +#define AT91C_PB11_D2 (AT91C_PIO_PB11) // +#define AT91C_PB11_DCD0 (AT91C_PIO_PB11) // +#define AT91C_PIO_PB12 (1 << 12) // Pin Controlled by PB12 +#define AT91C_PB12_D3 (AT91C_PIO_PB12) // +#define AT91C_PB12_RI0 (AT91C_PIO_PB12) // +#define AT91C_PIO_PB13 (1 << 13) // Pin Controlled by PB13 +#define AT91C_PB13_D4 (AT91C_PIO_PB13) // +#define AT91C_PB13_PWMH0 (AT91C_PIO_PB13) // +#define AT91C_PIO_PB14 (1 << 14) // Pin Controlled by PB14 +#define AT91C_PB14_D5 (AT91C_PIO_PB14) // +#define AT91C_PB14_PWMH1 (AT91C_PIO_PB14) // +#define AT91C_PIO_PB15 (1 << 15) // Pin Controlled by PB15 +#define AT91C_PB15_D6 (AT91C_PIO_PB15) // +#define AT91C_PB15_PWMH2 (AT91C_PIO_PB15) // +#define AT91C_PIO_PB16 (1 << 16) // Pin Controlled by PB16 +#define AT91C_PB16_D7 (AT91C_PIO_PB16) // +#define AT91C_PB16_PWMH3 (AT91C_PIO_PB16) // +#define AT91C_PIO_PB17 (1 << 17) // Pin Controlled by PB17 +#define AT91C_PB17_NANDOE (AT91C_PIO_PB17) // +#define AT91C_PB17_PWML0 (AT91C_PIO_PB17) // +#define AT91C_PIO_PB18 (1 << 18) // Pin Controlled by PB18 +#define AT91C_PB18_NANDWE (AT91C_PIO_PB18) // +#define AT91C_PB18_PWML1 (AT91C_PIO_PB18) // +#define AT91C_PIO_PB19 (1 << 19) // Pin Controlled by PB19 +#define AT91C_PB19_NRD (AT91C_PIO_PB19) // +#define AT91C_PB19_PWML2 (AT91C_PIO_PB19) // +#define AT91C_PIO_PB2 (1 << 2) // Pin Controlled by PB2 +#define AT91C_PB2_PWMH2 (AT91C_PIO_PB2) // +#define AT91C_PB2_A4 (AT91C_PIO_PB2) // +#define AT91C_PIO_PB20 (1 << 20) // Pin Controlled by PB20 +#define AT91C_PB20_NCS0 (AT91C_PIO_PB20) // +#define AT91C_PB20_PWML3 (AT91C_PIO_PB20) // +#define AT91C_PIO_PB21 (1 << 21) // Pin Controlled by PB21 +#define AT91C_PB21_A21_NANDALE (AT91C_PIO_PB21) // +#define AT91C_PB21_RTS2 (AT91C_PIO_PB21) // +#define AT91C_PIO_PB22 (1 << 22) // Pin Controlled by PB22 +#define AT91C_PB22_A22_NANDCLE (AT91C_PIO_PB22) // +#define AT91C_PB22_CTS2 (AT91C_PIO_PB22) // +#define AT91C_PIO_PB23 (1 << 23) // Pin Controlled by PB23 +#define AT91C_PB23_NWR0_NWE (AT91C_PIO_PB23) // +#define AT91C_PB23_PCK2 (AT91C_PIO_PB23) // +#define AT91C_PIO_PB24 (1 << 24) // Pin Controlled by PB24 +#define AT91C_PB24_NANDRDY (AT91C_PIO_PB24) // +#define AT91C_PB24_PCK1 (AT91C_PIO_PB24) // +#define AT91C_PIO_PB25 (1 << 25) // Pin Controlled by PB25 +#define AT91C_PB25_D8 (AT91C_PIO_PB25) // +#define AT91C_PB25_PWML0 (AT91C_PIO_PB25) // +#define AT91C_PIO_PB26 (1 << 26) // Pin Controlled by PB26 +#define AT91C_PB26_D9 (AT91C_PIO_PB26) // +#define AT91C_PB26_PWML1 (AT91C_PIO_PB26) // +#define AT91C_PIO_PB27 (1 << 27) // Pin Controlled by PB27 +#define AT91C_PB27_D10 (AT91C_PIO_PB27) // +#define AT91C_PB27_PWML2 (AT91C_PIO_PB27) // +#define AT91C_PIO_PB28 (1 << 28) // Pin Controlled by PB28 +#define AT91C_PB28_D11 (AT91C_PIO_PB28) // +#define AT91C_PB28_PWML3 (AT91C_PIO_PB28) // +#define AT91C_PIO_PB29 (1 << 29) // Pin Controlled by PB29 +#define AT91C_PB29_D12 (AT91C_PIO_PB29) // +#define AT91C_PIO_PB3 (1 << 3) // Pin Controlled by PB3 +#define AT91C_PB3_PWMH3 (AT91C_PIO_PB3) // +#define AT91C_PB3_A5 (AT91C_PIO_PB3) // +#define AT91C_PIO_PB30 (1 << 30) // Pin Controlled by PB30 +#define AT91C_PB30_D13 (AT91C_PIO_PB30) // +#define AT91C_PIO_PB31 (1 << 31) // Pin Controlled by PB31 +#define AT91C_PB31_D14 (AT91C_PIO_PB31) // +#define AT91C_PIO_PB4 (1 << 4) // Pin Controlled by PB4 +#define AT91C_PB4_TCLK1 (AT91C_PIO_PB4) // +#define AT91C_PB4_A6 (AT91C_PIO_PB4) // +#define AT91C_PIO_PB5 (1 << 5) // Pin Controlled by PB5 +#define AT91C_PB5_TIOA1 (AT91C_PIO_PB5) // +#define AT91C_PB5_A7 (AT91C_PIO_PB5) // +#define AT91C_PIO_PB6 (1 << 6) // Pin Controlled by PB6 +#define AT91C_PB6_TIOB1 (AT91C_PIO_PB6) // +#define AT91C_PB6_D15 (AT91C_PIO_PB6) // +#define AT91C_PIO_PB7 (1 << 7) // Pin Controlled by PB7 +#define AT91C_PB7_RTS0 (AT91C_PIO_PB7) // +#define AT91C_PB7_A0_NBS0 (AT91C_PIO_PB7) // +#define AT91C_PIO_PB8 (1 << 8) // Pin Controlled by PB8 +#define AT91C_PB8_CTS0 (AT91C_PIO_PB8) // +#define AT91C_PB8_A1 (AT91C_PIO_PB8) // +#define AT91C_PIO_PB9 (1 << 9) // Pin Controlled by PB9 +#define AT91C_PB9_D0 (AT91C_PIO_PB9) // +#define AT91C_PB9_DTR0 (AT91C_PIO_PB9) // +#define AT91C_PIO_PC0 (1 << 0) // Pin Controlled by PC0 +#define AT91C_PC0_A2 (AT91C_PIO_PC0) // +#define AT91C_PIO_PC1 (1 << 1) // Pin Controlled by PC1 +#define AT91C_PC1_A3 (AT91C_PIO_PC1) // +#define AT91C_PIO_PC10 (1 << 10) // Pin Controlled by PC10 +#define AT91C_PC10_A12 (AT91C_PIO_PC10) // +#define AT91C_PC10_CTS3 (AT91C_PIO_PC10) // +#define AT91C_PIO_PC11 (1 << 11) // Pin Controlled by PC11 +#define AT91C_PC11_A13 (AT91C_PIO_PC11) // +#define AT91C_PC11_RTS3 (AT91C_PIO_PC11) // +#define AT91C_PIO_PC12 (1 << 12) // Pin Controlled by PC12 +#define AT91C_PC12_NCS1 (AT91C_PIO_PC12) // +#define AT91C_PC12_TXD3 (AT91C_PIO_PC12) // +#define AT91C_PIO_PC13 (1 << 13) // Pin Controlled by PC13 +#define AT91C_PC13_A2 (AT91C_PIO_PC13) // +#define AT91C_PC13_RXD3 (AT91C_PIO_PC13) // +#define AT91C_PIO_PC14 (1 << 14) // Pin Controlled by PC14 +#define AT91C_PC14_A3 (AT91C_PIO_PC14) // +#define AT91C_PC14_SPI0_NPCS2 (AT91C_PIO_PC14) // +#define AT91C_PIO_PC15 (1 << 15) // Pin Controlled by PC15 +#define AT91C_PC15_NWR1_NBS1 (AT91C_PIO_PC15) // +#define AT91C_PIO_PC16 (1 << 16) // Pin Controlled by PC16 +#define AT91C_PC16_NCS2 (AT91C_PIO_PC16) // +#define AT91C_PC16_PWML3 (AT91C_PIO_PC16) // +#define AT91C_PIO_PC17 (1 << 17) // Pin Controlled by PC17 +#define AT91C_PC17_NCS3 (AT91C_PIO_PC17) // +#define AT91C_PC17_A24 (AT91C_PIO_PC17) // +#define AT91C_PIO_PC18 (1 << 18) // Pin Controlled by PC18 +#define AT91C_PC18_NWAIT (AT91C_PIO_PC18) // +#define AT91C_PIO_PC19 (1 << 19) // Pin Controlled by PC19 +#define AT91C_PC19_SCK3 (AT91C_PIO_PC19) // +#define AT91C_PC19_NPCS1 (AT91C_PIO_PC19) // +#define AT91C_PIO_PC2 (1 << 2) // Pin Controlled by PC2 +#define AT91C_PC2_A4 (AT91C_PIO_PC2) // +#define AT91C_PIO_PC20 (1 << 20) // Pin Controlled by PC20 +#define AT91C_PC20_A14 (AT91C_PIO_PC20) // +#define AT91C_PIO_PC21 (1 << 21) // Pin Controlled by PC21 +#define AT91C_PC21_A15 (AT91C_PIO_PC21) // +#define AT91C_PIO_PC22 (1 << 22) // Pin Controlled by PC22 +#define AT91C_PC22_A16 (AT91C_PIO_PC22) // +#define AT91C_PIO_PC23 (1 << 23) // Pin Controlled by PC23 +#define AT91C_PC23_A17 (AT91C_PIO_PC23) // +#define AT91C_PIO_PC24 (1 << 24) // Pin Controlled by PC24 +#define AT91C_PC24_A18 (AT91C_PIO_PC24) // +#define AT91C_PC24_PWMH0 (AT91C_PIO_PC24) // +#define AT91C_PIO_PC25 (1 << 25) // Pin Controlled by PC25 +#define AT91C_PC25_A19 (AT91C_PIO_PC25) // +#define AT91C_PC25_PWMH1 (AT91C_PIO_PC25) // +#define AT91C_PIO_PC26 (1 << 26) // Pin Controlled by PC26 +#define AT91C_PC26_A20 (AT91C_PIO_PC26) // +#define AT91C_PC26_PWMH2 (AT91C_PIO_PC26) // +#define AT91C_PIO_PC27 (1 << 27) // Pin Controlled by PC27 +#define AT91C_PC27_A23 (AT91C_PIO_PC27) // +#define AT91C_PC27_PWMH3 (AT91C_PIO_PC27) // +#define AT91C_PIO_PC28 (1 << 28) // Pin Controlled by PC28 +#define AT91C_PC28_A24 (AT91C_PIO_PC28) // +#define AT91C_PC28_MCI0_DA4 (AT91C_PIO_PC28) // +#define AT91C_PIO_PC29 (1 << 29) // Pin Controlled by PC29 +#define AT91C_PC29_PWML0 (AT91C_PIO_PC29) // +#define AT91C_PC29_MCI0_DA5 (AT91C_PIO_PC29) // +#define AT91C_PIO_PC3 (1 << 3) // Pin Controlled by PC3 +#define AT91C_PC3_A5 (AT91C_PIO_PC3) // +#define AT91C_PC3_SPI0_NPCS1 (AT91C_PIO_PC3) // +#define AT91C_PIO_PC30 (1 << 30) // Pin Controlled by PC30 +#define AT91C_PC30_PWML1 (AT91C_PIO_PC30) // +#define AT91C_PC30_MCI0_DA6 (AT91C_PIO_PC30) // +#define AT91C_PIO_PC31 (1 << 31) // Pin Controlled by PC31 +#define AT91C_PC31_PWML2 (AT91C_PIO_PC31) // +#define AT91C_PC31_MCI0_DA7 (AT91C_PIO_PC31) // +#define AT91C_PIO_PC4 (1 << 4) // Pin Controlled by PC4 +#define AT91C_PC4_A6 (AT91C_PIO_PC4) // +#define AT91C_PC4_SPI0_NPCS2 (AT91C_PIO_PC4) // +#define AT91C_PIO_PC5 (1 << 5) // Pin Controlled by PC5 +#define AT91C_PC5_A7 (AT91C_PIO_PC5) // +#define AT91C_PC5_SPI0_NPCS3 (AT91C_PIO_PC5) // +#define AT91C_PIO_PC6 (1 << 6) // Pin Controlled by PC6 +#define AT91C_PC6_A8 (AT91C_PIO_PC6) // +#define AT91C_PC6_PWML0 (AT91C_PIO_PC6) // +#define AT91C_PIO_PC7 (1 << 7) // Pin Controlled by PC7 +#define AT91C_PC7_A9 (AT91C_PIO_PC7) // +#define AT91C_PC7_PWML1 (AT91C_PIO_PC7) // +#define AT91C_PIO_PC8 (1 << 8) // Pin Controlled by PC8 +#define AT91C_PC8_A10 (AT91C_PIO_PC8) // +#define AT91C_PC8_PWML2 (AT91C_PIO_PC8) // +#define AT91C_PIO_PC9 (1 << 9) // Pin Controlled by PC9 +#define AT91C_PC9_A11 (AT91C_PIO_PC9) // +#define AT91C_PC9_PWML3 (AT91C_PIO_PC9) // + +// ***************************************************************************** +// PERIPHERAL ID DEFINITIONS FOR AT91SAM3U4 +// ***************************************************************************** +#define AT91C_ID_SUPC ( 0) // SUPPLY CONTROLLER +#define AT91C_ID_RSTC ( 1) // RESET CONTROLLER +#define AT91C_ID_RTC ( 2) // REAL TIME CLOCK +#define AT91C_ID_RTT ( 3) // REAL TIME TIMER +#define AT91C_ID_WDG ( 4) // WATCHDOG TIMER +#define AT91C_ID_PMC ( 5) // PMC +#define AT91C_ID_EFC0 ( 6) // EFC0 +#define AT91C_ID_EFC1 ( 7) // EFC1 +#define AT91C_ID_DBGU ( 8) // DBGU +#define AT91C_ID_HSMC4 ( 9) // HSMC4 +#define AT91C_ID_PIOA (10) // Parallel IO Controller A +#define AT91C_ID_PIOB (11) // Parallel IO Controller B +#define AT91C_ID_PIOC (12) // Parallel IO Controller C +#define AT91C_ID_US0 (13) // USART 0 +#define AT91C_ID_US1 (14) // USART 1 +#define AT91C_ID_US2 (15) // USART 2 +#define AT91C_ID_US3 (16) // USART 3 +#define AT91C_ID_MCI0 (17) // Multimedia Card Interface +#define AT91C_ID_TWI0 (18) // TWI 0 +#define AT91C_ID_TWI1 (19) // TWI 1 +#define AT91C_ID_SPI0 (20) // Serial Peripheral Interface +#define AT91C_ID_SSC0 (21) // Serial Synchronous Controller 0 +#define AT91C_ID_TC0 (22) // Timer Counter 0 +#define AT91C_ID_TC1 (23) // Timer Counter 1 +#define AT91C_ID_TC2 (24) // Timer Counter 2 +#define AT91C_ID_PWMC (25) // Pulse Width Modulation Controller +#define AT91C_ID_ADCC0 (26) // ADC controller0 +#define AT91C_ID_ADCC1 (27) // ADC controller1 +#define AT91C_ID_HDMA (28) // HDMA +#define AT91C_ID_UDPHS (29) // USB Device High Speed +#define AT91C_ALL_INT (0x3FFFFFFF) // ALL VALID INTERRUPTS + +// ***************************************************************************** +// BASE ADDRESS DEFINITIONS FOR AT91SAM3U4 +// ***************************************************************************** +#define AT91C_BASE_SYS (AT91_CAST(AT91PS_SYS) 0x400E0000) // (SYS) Base Address +#define AT91C_BASE_HSMC4_CS0 (AT91_CAST(AT91PS_HSMC4_CS) 0x400E0070) // (HSMC4_CS0) Base Address +#define AT91C_BASE_HSMC4_CS1 (AT91_CAST(AT91PS_HSMC4_CS) 0x400E0084) // (HSMC4_CS1) Base Address +#define AT91C_BASE_HSMC4_CS2 (AT91_CAST(AT91PS_HSMC4_CS) 0x400E0098) // (HSMC4_CS2) Base Address +#define AT91C_BASE_HSMC4_CS3 (AT91_CAST(AT91PS_HSMC4_CS) 0x400E00AC) // (HSMC4_CS3) Base Address +#define AT91C_BASE_HSMC4_NFC (AT91_CAST(AT91PS_HSMC4_CS) 0x400E00FC) // (HSMC4_NFC) Base Address +#define AT91C_BASE_HSMC4 (AT91_CAST(AT91PS_HSMC4) 0x400E0000) // (HSMC4) Base Address +#define AT91C_BASE_MATRIX (AT91_CAST(AT91PS_HMATRIX2) 0x400E0200) // (MATRIX) Base Address +#define AT91C_BASE_NVIC (AT91_CAST(AT91PS_NVIC) 0xE000E000) // (NVIC) Base Address +#define AT91C_BASE_MPU (AT91_CAST(AT91PS_MPU) 0xE000ED90) // (MPU) Base Address +#define AT91C_BASE_CM3 (AT91_CAST(AT91PS_CM3) 0xE000ED00) // (CM3) Base Address +#define AT91C_BASE_PDC_DBGU (AT91_CAST(AT91PS_PDC) 0x400E0700) // (PDC_DBGU) Base Address +#define AT91C_BASE_DBGU (AT91_CAST(AT91PS_DBGU) 0x400E0600) // (DBGU) Base Address +#define AT91C_BASE_PIOA (AT91_CAST(AT91PS_PIO) 0x400E0C00) // (PIOA) Base Address +#define AT91C_BASE_PIOB (AT91_CAST(AT91PS_PIO) 0x400E0E00) // (PIOB) Base Address +#define AT91C_BASE_PIOC (AT91_CAST(AT91PS_PIO) 0x400E1000) // (PIOC) Base Address +#define AT91C_BASE_PMC (AT91_CAST(AT91PS_PMC) 0x400E0400) // (PMC) Base Address +#define AT91C_BASE_CKGR (AT91_CAST(AT91PS_CKGR) 0x400E041C) // (CKGR) Base Address +#define AT91C_BASE_RSTC (AT91_CAST(AT91PS_RSTC) 0x400E1200) // (RSTC) Base Address +#define AT91C_BASE_SUPC (AT91_CAST(AT91PS_SUPC) 0x400E1210) // (SUPC) Base Address +#define AT91C_BASE_RTTC (AT91_CAST(AT91PS_RTTC) 0x400E1230) // (RTTC) Base Address +#define AT91C_BASE_WDTC (AT91_CAST(AT91PS_WDTC) 0x400E1250) // (WDTC) Base Address +#define AT91C_BASE_RTC (AT91_CAST(AT91PS_RTC) 0x400E1260) // (RTC) Base Address +#define AT91C_BASE_ADC0 (AT91_CAST(AT91PS_ADC) 0x400A8000) // (ADC0) Base Address +#define AT91C_BASE_ADC1 (AT91_CAST(AT91PS_ADC) 0x400AC000) // (ADC1) Base Address +#define AT91C_BASE_TC0 (AT91_CAST(AT91PS_TC) 0x40080000) // (TC0) Base Address +#define AT91C_BASE_TC1 (AT91_CAST(AT91PS_TC) 0x40080040) // (TC1) Base Address +#define AT91C_BASE_TC2 (AT91_CAST(AT91PS_TC) 0x40080080) // (TC2) Base Address +#define AT91C_BASE_TCB0 (AT91_CAST(AT91PS_TCB) 0x40080000) // (TCB0) Base Address +#define AT91C_BASE_TCB1 (AT91_CAST(AT91PS_TCB) 0x40080040) // (TCB1) Base Address +#define AT91C_BASE_TCB2 (AT91_CAST(AT91PS_TCB) 0x40080080) // (TCB2) Base Address +#define AT91C_BASE_EFC0 (AT91_CAST(AT91PS_EFC) 0x400E0800) // (EFC0) Base Address +#define AT91C_BASE_EFC1 (AT91_CAST(AT91PS_EFC) 0x400E0A00) // (EFC1) Base Address +#define AT91C_BASE_MCI0 (AT91_CAST(AT91PS_MCI) 0x40000000) // (MCI0) Base Address +#define AT91C_BASE_PDC_TWI0 (AT91_CAST(AT91PS_PDC) 0x40084100) // (PDC_TWI0) Base Address +#define AT91C_BASE_PDC_TWI1 (AT91_CAST(AT91PS_PDC) 0x40088100) // (PDC_TWI1) Base Address +#define AT91C_BASE_TWI0 (AT91_CAST(AT91PS_TWI) 0x40084000) // (TWI0) Base Address +#define AT91C_BASE_TWI1 (AT91_CAST(AT91PS_TWI) 0x40088000) // (TWI1) Base Address +#define AT91C_BASE_PDC_US0 (AT91_CAST(AT91PS_PDC) 0x40090100) // (PDC_US0) Base Address +#define AT91C_BASE_US0 (AT91_CAST(AT91PS_USART) 0x40090000) // (US0) Base Address +#define AT91C_BASE_PDC_US1 (AT91_CAST(AT91PS_PDC) 0x40094100) // (PDC_US1) Base Address +#define AT91C_BASE_US1 (AT91_CAST(AT91PS_USART) 0x40094000) // (US1) Base Address +#define AT91C_BASE_PDC_US2 (AT91_CAST(AT91PS_PDC) 0x40098100) // (PDC_US2) Base Address +#define AT91C_BASE_US2 (AT91_CAST(AT91PS_USART) 0x40098000) // (US2) Base Address +#define AT91C_BASE_PDC_US3 (AT91_CAST(AT91PS_PDC) 0x4009C100) // (PDC_US3) Base Address +#define AT91C_BASE_US3 (AT91_CAST(AT91PS_USART) 0x4009C000) // (US3) Base Address +#define AT91C_BASE_PDC_SSC0 (AT91_CAST(AT91PS_PDC) 0x40004100) // (PDC_SSC0) Base Address +#define AT91C_BASE_SSC0 (AT91_CAST(AT91PS_SSC) 0x40004000) // (SSC0) Base Address +#define AT91C_BASE_PDC_PWMC (AT91_CAST(AT91PS_PDC) 0x4008C100) // (PDC_PWMC) Base Address +#define AT91C_BASE_PWMC_CH0 (AT91_CAST(AT91PS_PWMC_CH) 0x4008C200) // (PWMC_CH0) Base Address +#define AT91C_BASE_PWMC_CH1 (AT91_CAST(AT91PS_PWMC_CH) 0x4008C220) // (PWMC_CH1) Base Address +#define AT91C_BASE_PWMC_CH2 (AT91_CAST(AT91PS_PWMC_CH) 0x4008C240) // (PWMC_CH2) Base Address +#define AT91C_BASE_PWMC_CH3 (AT91_CAST(AT91PS_PWMC_CH) 0x4008C260) // (PWMC_CH3) Base Address +#define AT91C_BASE_PWMC (AT91_CAST(AT91PS_PWMC) 0x4008C000) // (PWMC) Base Address +#define AT91C_BASE_SPI0 (AT91_CAST(AT91PS_SPI) 0x40008000) // (SPI0) Base Address +#define AT91C_BASE_UDPHS_EPTFIFO (AT91_CAST(AT91PS_UDPHS_EPTFIFO) 0x20180000) // (UDPHS_EPTFIFO) Base Address +#define AT91C_BASE_UDPHS_EPT_0 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A4100) // (UDPHS_EPT_0) Base Address +#define AT91C_BASE_UDPHS_EPT_1 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A4120) // (UDPHS_EPT_1) Base Address +#define AT91C_BASE_UDPHS_EPT_2 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A4140) // (UDPHS_EPT_2) Base Address +#define AT91C_BASE_UDPHS_EPT_3 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A4160) // (UDPHS_EPT_3) Base Address +#define AT91C_BASE_UDPHS_EPT_4 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A4180) // (UDPHS_EPT_4) Base Address +#define AT91C_BASE_UDPHS_EPT_5 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A41A0) // (UDPHS_EPT_5) Base Address +#define AT91C_BASE_UDPHS_EPT_6 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A41C0) // (UDPHS_EPT_6) Base Address +#define AT91C_BASE_UDPHS_DMA_1 (AT91_CAST(AT91PS_UDPHS_DMA) 0x400A4310) // (UDPHS_DMA_1) Base Address +#define AT91C_BASE_UDPHS_DMA_2 (AT91_CAST(AT91PS_UDPHS_DMA) 0x400A4320) // (UDPHS_DMA_2) Base Address +#define AT91C_BASE_UDPHS_DMA_3 (AT91_CAST(AT91PS_UDPHS_DMA) 0x400A4330) // (UDPHS_DMA_3) Base Address +#define AT91C_BASE_UDPHS_DMA_4 (AT91_CAST(AT91PS_UDPHS_DMA) 0x400A4340) // (UDPHS_DMA_4) Base Address +#define AT91C_BASE_UDPHS_DMA_5 (AT91_CAST(AT91PS_UDPHS_DMA) 0x400A4350) // (UDPHS_DMA_5) Base Address +#define AT91C_BASE_UDPHS_DMA_6 (AT91_CAST(AT91PS_UDPHS_DMA) 0x400A4360) // (UDPHS_DMA_6) Base Address +#define AT91C_BASE_UDPHS (AT91_CAST(AT91PS_UDPHS) 0x400A4000) // (UDPHS) Base Address +#define AT91C_BASE_HDMA_CH_0 (AT91_CAST(AT91PS_HDMA_CH) 0x400B003C) // (HDMA_CH_0) Base Address +#define AT91C_BASE_HDMA_CH_1 (AT91_CAST(AT91PS_HDMA_CH) 0x400B0064) // (HDMA_CH_1) Base Address +#define AT91C_BASE_HDMA_CH_2 (AT91_CAST(AT91PS_HDMA_CH) 0x400B008C) // (HDMA_CH_2) Base Address +#define AT91C_BASE_HDMA_CH_3 (AT91_CAST(AT91PS_HDMA_CH) 0x400B00B4) // (HDMA_CH_3) Base Address +#define AT91C_BASE_HDMA (AT91_CAST(AT91PS_HDMA) 0x400B0000) // (HDMA) Base Address + +// ***************************************************************************** +// MEMORY MAPPING DEFINITIONS FOR AT91SAM3U4 +// ***************************************************************************** +// ITCM +#define AT91C_ITCM (0x00100000) // Maximum ITCM Area base address +#define AT91C_ITCM_SIZE (0x00010000) // Maximum ITCM Area size in byte (64 Kbytes) +// DTCM +#define AT91C_DTCM (0x00200000) // Maximum DTCM Area base address +#define AT91C_DTCM_SIZE (0x00010000) // Maximum DTCM Area size in byte (64 Kbytes) +// IRAM +#define AT91C_IRAM (0x20000000) // Maximum Internal SRAM base address +#define AT91C_IRAM_SIZE (0x00010000) // Maximum Internal SRAM size in byte (64 Kbytes) +// IRAM_MIN +#define AT91C_IRAM_MIN (0x00300000) // Minimum Internal RAM base address +#define AT91C_IRAM_MIN_SIZE (0x00004000) // Minimum Internal RAM size in byte (16 Kbytes) +// IROM +#define AT91C_IROM (0x00180000) // Internal ROM base address +#define AT91C_IROM_SIZE (0x00008000) // Internal ROM size in byte (32 Kbytes) +// IFLASH0 +#define AT91C_IFLASH0 (0x00080000) // Maximum IFLASH Area : 128Kbyte base address +#define AT91C_IFLASH0_SIZE (0x00020000) // Maximum IFLASH Area : 128Kbyte size in byte (128 Kbytes) +#define AT91C_IFLASH0_PAGE_SIZE (256) // Maximum IFLASH Area : 128Kbyte Page Size: 256 bytes +#define AT91C_IFLASH0_LOCK_REGION_SIZE (8192) // Maximum IFLASH Area : 128Kbyte Lock Region Size: 8 Kbytes +#define AT91C_IFLASH0_NB_OF_PAGES (512) // Maximum IFLASH Area : 128Kbyte Number of Pages: 512 bytes +#define AT91C_IFLASH0_NB_OF_LOCK_BITS (16) // Maximum IFLASH Area : 128Kbyte Number of Lock Bits: 32 bytes +// IFLASH1 +#define AT91C_IFLASH1 (0x0100000) // Maximum IFLASH Area : 128Kbyte base address +#define AT91C_IFLASH1_SIZE (0x00020000) // Maximum IFLASH Area : 128Kbyte size in byte (128 Kbytes) +#define AT91C_IFLASH1_PAGE_SIZE (256) // Maximum IFLASH Area : 128Kbyte Page Size: 256 bytes +#define AT91C_IFLASH1_LOCK_REGION_SIZE (8192) // Maximum IFLASH Area : 128Kbyte Lock Region Size: 8 Kbytes +#define AT91C_IFLASH1_NB_OF_PAGES (512) // Maximum IFLASH Area : 128Kbyte Number of Pages: 512 bytes +#define AT91C_IFLASH1_NB_OF_LOCK_BITS (16) // Maximum IFLASH Area : 128Kbyte Number of Lock Bits: 32 bytes +// EBI_CS0 +#define AT91C_EBI_CS0 (0x10000000) // EBI Chip Select 0 base address +#define AT91C_EBI_CS0_SIZE (0x10000000) // EBI Chip Select 0 size in byte (262144 Kbytes) +// EBI_CS1 +#define AT91C_EBI_CS1 (0x20000000) // EBI Chip Select 1 base address +#define AT91C_EBI_CS1_SIZE (0x10000000) // EBI Chip Select 1 size in byte (262144 Kbytes) +// EBI_SDRAM +#define AT91C_EBI_SDRAM (0x20000000) // SDRAM on EBI Chip Select 1 base address +#define AT91C_EBI_SDRAM_SIZE (0x10000000) // SDRAM on EBI Chip Select 1 size in byte (262144 Kbytes) +// EBI_SDRAM_16BIT +#define AT91C_EBI_SDRAM_16BIT (0x20000000) // SDRAM on EBI Chip Select 1 base address +#define AT91C_EBI_SDRAM_16BIT_SIZE (0x02000000) // SDRAM on EBI Chip Select 1 size in byte (32768 Kbytes) +// EBI_SDRAM_32BIT +#define AT91C_EBI_SDRAM_32BIT (0x20000000) // SDRAM on EBI Chip Select 1 base address +#define AT91C_EBI_SDRAM_32BIT_SIZE (0x04000000) // SDRAM on EBI Chip Select 1 size in byte (65536 Kbytes) +// EBI_CS2 +#define AT91C_EBI_CS2 (0x30000000) // EBI Chip Select 2 base address +#define AT91C_EBI_CS2_SIZE (0x10000000) // EBI Chip Select 2 size in byte (262144 Kbytes) +// EBI_CS3 +#define AT91C_EBI_CS3 (0x40000000) // EBI Chip Select 3 base address +#define AT91C_EBI_CS3_SIZE (0x10000000) // EBI Chip Select 3 size in byte (262144 Kbytes) +// EBI_SM +#define AT91C_EBI_SM (0x40000000) // NANDFLASH on EBI Chip Select 3 base address +#define AT91C_EBI_SM_SIZE (0x10000000) // NANDFLASH on EBI Chip Select 3 size in byte (262144 Kbytes) +// EBI_CS4 +#define AT91C_EBI_CS4 (0x50000000) // EBI Chip Select 4 base address +#define AT91C_EBI_CS4_SIZE (0x10000000) // EBI Chip Select 4 size in byte (262144 Kbytes) +// EBI_CF0 +#define AT91C_EBI_CF0 (0x50000000) // CompactFlash 0 on EBI Chip Select 4 base address +#define AT91C_EBI_CF0_SIZE (0x10000000) // CompactFlash 0 on EBI Chip Select 4 size in byte (262144 Kbytes) +// EBI_CS5 +#define AT91C_EBI_CS5 (0x60000000) // EBI Chip Select 5 base address +#define AT91C_EBI_CS5_SIZE (0x10000000) // EBI Chip Select 5 size in byte (262144 Kbytes) +// EBI_CF1 +#define AT91C_EBI_CF1 (0x60000000) // CompactFlash 1 on EBIChip Select 5 base address +#define AT91C_EBI_CF1_SIZE (0x10000000) // CompactFlash 1 on EBIChip Select 5 size in byte (262144 Kbytes) + +#endif diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u-ek-flash.mac b/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u-ek-flash.mac new file mode 100644 index 000000000..0fec0a062 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u-ek-flash.mac @@ -0,0 +1,35 @@ +// --------------------------------------------------------- +// ATMEL Microcontroller Software Support - ROUSSET - +// --------------------------------------------------------- +// The software is delivered "AS IS" without warranty or +// condition of any kind, either express, implied or +// statutory. This includes without limitation any warranty +// or condition with respect to merchantability or fitness +// for any particular purpose, or against the infringements of +// intellectual property rights of others. +// --------------------------------------------------------- +// File: at91sam3u-ek-flash.mac +// User setup file for CSPY debugger. +// --------------------------------------------------------- +__var __mac_i; +__var __mac_pt; + +/********************************************************************* +* +* execUserReset() +*/ +execUserReset() +{ + __message "------------------------------ execUserReset ---------------------------------"; + __message "-------------------------------Set PC Reset ----------------------------------"; +} + +/********************************************************************* +* +* execUserPreload() +*/ +execUserPreload() +{ + __message "------------------------------ execUserPreload ---------------------------------"; + __hwReset(0); //* Hardware Reset: CPU is automatically halted after the reset +} diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u4/AT91SAM3U4.h b/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u4/AT91SAM3U4.h new file mode 100644 index 000000000..a7cb9a6a5 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u4/AT91SAM3U4.h @@ -0,0 +1,6517 @@ +// ---------------------------------------------------------------------------- +// ATMEL Microcontroller Software Support - ROUSSET - +// ---------------------------------------------------------------------------- +// Copyright (c) 2008, Atmel Corporation +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the disclaimer below. +// +// Atmel's name may not be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE +// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// ---------------------------------------------------------------------------- +// File Name : AT91SAM3U4.h +// Object : AT91SAM3U4 definitions +// Generated : AT91 SW Application Group 03/09/2009 (11:49:34) +// +// CVS Reference : /AT91SAM3U4.pl/1.32/Mon Feb 9 14:20:58 2009// +// CVS Reference : /SYS_SAM3U4.pl/1.4/Fri Oct 17 13:27:57 2008// +// CVS Reference : /HMATRIX2_SAM3U4.pl/1.3/Mon Mar 2 10:12:07 2009// +// CVS Reference : /PMC_SAM3U4.pl/1.7/Fri Oct 17 13:27:54 2008// +// CVS Reference : /EBI_SAM9260.pl/1.1/Fri Sep 30 12:12:14 2005// +// CVS Reference : /EFC2_SAM3U4.pl/1.3/Mon Mar 2 10:12:06 2009// +// CVS Reference : /HSDRAMC1_6100A.pl/1.2/Mon Aug 9 10:52:25 2004// +// CVS Reference : /HSMC4_xxxx.pl/1.9/Fri Oct 17 13:27:56 2008// +// CVS Reference : /HECC_6143A.pl/1.1/Wed Feb 9 17:16:57 2005// +// CVS Reference : /CORTEX_M3_NVIC.pl/1.7/Tue Jan 27 16:16:24 2009// +// CVS Reference : /CORTEX_M3_MPU.pl/1.3/Fri Oct 17 13:27:48 2008// +// CVS Reference : /CORTEX_M3.pl/1.1/Mon Sep 15 15:22:06 2008// +// CVS Reference : /PDC_6074C.pl/1.2/Thu Feb 3 09:02:11 2005// +// CVS Reference : /DBGU_SAM3U4.pl/1.2/Fri Oct 17 13:27:49 2008// +// CVS Reference : /PIO3_xxxx.pl/1.6/Mon Mar 9 10:43:37 2009// +// CVS Reference : /RSTC_6098A.pl/1.4/Fri Oct 17 13:27:55 2008// +// CVS Reference : /SHDWC_6122A.pl/1.3/Wed Oct 6 14:16:58 2004// +// CVS Reference : /SUPC_SAM3U4.pl/1.2/Thu Jun 5 15:27:27 2008// +// CVS Reference : /RTTC_6081A.pl/1.2/Thu Nov 4 13:57:22 2004// +// CVS Reference : /PITC_6079A.pl/1.2/Thu Nov 4 13:56:22 2004// +// CVS Reference : /WDTC_6080A.pl/1.3/Thu Nov 4 13:58:52 2004// +// CVS Reference : /TC_6082A.pl/1.8/Fri Oct 17 13:27:58 2008// +// CVS Reference : /MCI_6101F.pl/1.3/Fri Jan 23 09:15:32 2009// +// CVS Reference : /TWI_6061B.pl/1.3/Fri Oct 17 13:27:59 2008// +// CVS Reference : /US_6089J.pl/1.3/Fri Oct 17 13:27:59 2008// +// CVS Reference : /SSC_6078B.pl/1.3/Fri Oct 17 13:27:57 2008// +// CVS Reference : /SPI2.pl/1.4/Mon Mar 9 08:56:28 2009// +// CVS Reference : /PWM_6343B_V400.pl/1.3/Fri Oct 17 13:27:54 2008// +// CVS Reference : /HDMA_SAM3U4.pl/1.3/Fri Oct 17 13:27:51 2008// +// CVS Reference : /UDPHS_SAM9_7ept6dma4iso.pl/1.4/Tue Jun 24 13:05:14 2008// +// CVS Reference : /ADC_SAM3UE.pl/1.4/Fri Feb 20 12:19:18 2009// +// CVS Reference : /RTC_1245D.pl/1.3/Fri Sep 17 14:01:31 2004// +// ---------------------------------------------------------------------------- + +#ifndef AT91SAM3U4_H +#define AT91SAM3U4_H + +#ifndef __ASSEMBLY__ +typedef volatile unsigned int AT91_REG;// Hardware register definition +#define AT91_CAST(a) (a) +#else +#define AT91_CAST(a) +#endif + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR System Peripherals +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_SYS { + AT91_REG HSMC4_CFG; // Configuration Register + AT91_REG HSMC4_CTRL; // Control Register + AT91_REG HSMC4_SR; // Status Register + AT91_REG HSMC4_IER; // Interrupt Enable Register + AT91_REG HSMC4_IDR; // Interrupt Disable Register + AT91_REG HSMC4_IMR; // Interrupt Mask Register + AT91_REG HSMC4_ADDR; // Address Cycle Zero Register + AT91_REG HSMC4_BANK; // Bank Register + AT91_REG HSMC4_ECCCR; // ECC reset register + AT91_REG HSMC4_ECCCMD; // ECC Page size register + AT91_REG HSMC4_ECCSR1; // ECC Status register 1 + AT91_REG HSMC4_ECCPR0; // ECC Parity register 0 + AT91_REG HSMC4_ECCPR1; // ECC Parity register 1 + AT91_REG HSMC4_ECCSR2; // ECC Status register 2 + AT91_REG HSMC4_ECCPR2; // ECC Parity register 2 + AT91_REG HSMC4_ECCPR3; // ECC Parity register 3 + AT91_REG HSMC4_ECCPR4; // ECC Parity register 4 + AT91_REG HSMC4_ECCPR5; // ECC Parity register 5 + AT91_REG HSMC4_ECCPR6; // ECC Parity register 6 + AT91_REG HSMC4_ECCPR7; // ECC Parity register 7 + AT91_REG HSMC4_ECCPR8; // ECC Parity register 8 + AT91_REG HSMC4_ECCPR9; // ECC Parity register 9 + AT91_REG HSMC4_ECCPR10; // ECC Parity register 10 + AT91_REG HSMC4_ECCPR11; // ECC Parity register 11 + AT91_REG HSMC4_ECCPR12; // ECC Parity register 12 + AT91_REG HSMC4_ECCPR13; // ECC Parity register 13 + AT91_REG HSMC4_ECCPR14; // ECC Parity register 14 + AT91_REG HSMC4_Eccpr15; // ECC Parity register 15 + AT91_REG Reserved0[40]; // + AT91_REG HSMC4_OCMS; // OCMS MODE register + AT91_REG HSMC4_KEY1; // KEY1 Register + AT91_REG HSMC4_KEY2; // KEY2 Register + AT91_REG Reserved1[50]; // + AT91_REG HSMC4_WPCR; // Write Protection Control register + AT91_REG HSMC4_WPSR; // Write Protection Status Register + AT91_REG HSMC4_ADDRSIZE; // Write Protection Status Register + AT91_REG HSMC4_IPNAME1; // Write Protection Status Register + AT91_REG HSMC4_IPNAME2; // Write Protection Status Register + AT91_REG HSMC4_FEATURES; // Write Protection Status Register + AT91_REG HSMC4_VER; // HSMC4 Version Register + AT91_REG HMATRIX_MCFG0; // Master Configuration Register 0 : ARM I and D + AT91_REG HMATRIX_MCFG1; // Master Configuration Register 1 : ARM S + AT91_REG HMATRIX_MCFG2; // Master Configuration Register 2 + AT91_REG HMATRIX_MCFG3; // Master Configuration Register 3 + AT91_REG HMATRIX_MCFG4; // Master Configuration Register 4 + AT91_REG HMATRIX_MCFG5; // Master Configuration Register 5 + AT91_REG HMATRIX_MCFG6; // Master Configuration Register 6 + AT91_REG HMATRIX_MCFG7; // Master Configuration Register 7 + AT91_REG Reserved2[8]; // + AT91_REG HMATRIX_SCFG0; // Slave Configuration Register 0 + AT91_REG HMATRIX_SCFG1; // Slave Configuration Register 1 + AT91_REG HMATRIX_SCFG2; // Slave Configuration Register 2 + AT91_REG HMATRIX_SCFG3; // Slave Configuration Register 3 + AT91_REG HMATRIX_SCFG4; // Slave Configuration Register 4 + AT91_REG HMATRIX_SCFG5; // Slave Configuration Register 5 + AT91_REG HMATRIX_SCFG6; // Slave Configuration Register 6 + AT91_REG HMATRIX_SCFG7; // Slave Configuration Register 5 + AT91_REG HMATRIX_SCFG8; // Slave Configuration Register 8 + AT91_REG Reserved3[43]; // + AT91_REG HMATRIX_SFR0 ; // Special Function Register 0 + AT91_REG HMATRIX_SFR1 ; // Special Function Register 1 + AT91_REG HMATRIX_SFR2 ; // Special Function Register 2 + AT91_REG HMATRIX_SFR3 ; // Special Function Register 3 + AT91_REG HMATRIX_SFR4 ; // Special Function Register 4 + AT91_REG HMATRIX_SFR5 ; // Special Function Register 5 + AT91_REG HMATRIX_SFR6 ; // Special Function Register 6 + AT91_REG HMATRIX_SFR7 ; // Special Function Register 7 + AT91_REG HMATRIX_SFR8 ; // Special Function Register 8 + AT91_REG HMATRIX_SFR9 ; // Special Function Register 9 + AT91_REG HMATRIX_SFR10; // Special Function Register 10 + AT91_REG HMATRIX_SFR11; // Special Function Register 11 + AT91_REG HMATRIX_SFR12; // Special Function Register 12 + AT91_REG HMATRIX_SFR13; // Special Function Register 13 + AT91_REG HMATRIX_SFR14; // Special Function Register 14 + AT91_REG HMATRIX_SFR15; // Special Function Register 15 + AT91_REG Reserved4[39]; // + AT91_REG HMATRIX_ADDRSIZE; // HMATRIX2 ADDRSIZE REGISTER + AT91_REG HMATRIX_IPNAME1; // HMATRIX2 IPNAME1 REGISTER + AT91_REG HMATRIX_IPNAME2; // HMATRIX2 IPNAME2 REGISTER + AT91_REG HMATRIX_FEATURES; // HMATRIX2 FEATURES REGISTER + AT91_REG HMATRIX_VER; // HMATRIX2 VERSION REGISTER + AT91_REG PMC_SCER; // System Clock Enable Register + AT91_REG PMC_SCDR; // System Clock Disable Register + AT91_REG PMC_SCSR; // System Clock Status Register + AT91_REG Reserved5[1]; // + AT91_REG PMC_PCER; // Peripheral Clock Enable Register + AT91_REG PMC_PCDR; // Peripheral Clock Disable Register + AT91_REG PMC_PCSR; // Peripheral Clock Status Register + AT91_REG PMC_UCKR; // UTMI Clock Configuration Register + AT91_REG PMC_MOR; // Main Oscillator Register + AT91_REG PMC_MCFR; // Main Clock Frequency Register + AT91_REG PMC_PLLAR; // PLL Register + AT91_REG Reserved6[1]; // + AT91_REG PMC_MCKR; // Master Clock Register + AT91_REG Reserved7[3]; // + AT91_REG PMC_PCKR[8]; // Programmable Clock Register + AT91_REG PMC_IER; // Interrupt Enable Register + AT91_REG PMC_IDR; // Interrupt Disable Register + AT91_REG PMC_SR; // Status Register + AT91_REG PMC_IMR; // Interrupt Mask Register + AT91_REG PMC_FSMR; // Fast Startup Mode Register + AT91_REG PMC_FSPR; // Fast Startup Polarity Register + AT91_REG PMC_FOCR; // Fault Output Clear Register + AT91_REG Reserved8[28]; // + AT91_REG PMC_ADDRSIZE; // PMC ADDRSIZE REGISTER + AT91_REG PMC_IPNAME1; // PMC IPNAME1 REGISTER + AT91_REG PMC_IPNAME2; // PMC IPNAME2 REGISTER + AT91_REG PMC_FEATURES; // PMC FEATURES REGISTER + AT91_REG PMC_VER; // APMC VERSION REGISTER + AT91_REG Reserved9[64]; // + AT91_REG DBGU_CR; // Control Register + AT91_REG DBGU_MR; // Mode Register + AT91_REG DBGU_IER; // Interrupt Enable Register + AT91_REG DBGU_IDR; // Interrupt Disable Register + AT91_REG DBGU_IMR; // Interrupt Mask Register + AT91_REG DBGU_CSR; // Channel Status Register + AT91_REG DBGU_RHR; // Receiver Holding Register + AT91_REG DBGU_THR; // Transmitter Holding Register + AT91_REG DBGU_BRGR; // Baud Rate Generator Register + AT91_REG Reserved10[9]; // + AT91_REG DBGU_FNTR; // Force NTRST Register + AT91_REG Reserved11[40]; // + AT91_REG DBGU_ADDRSIZE; // DBGU ADDRSIZE REGISTER + AT91_REG DBGU_IPNAME1; // DBGU IPNAME1 REGISTER + AT91_REG DBGU_IPNAME2; // DBGU IPNAME2 REGISTER + AT91_REG DBGU_FEATURES; // DBGU FEATURES REGISTER + AT91_REG DBGU_VER; // DBGU VERSION REGISTER + AT91_REG DBGU_RPR; // Receive Pointer Register + AT91_REG DBGU_RCR; // Receive Counter Register + AT91_REG DBGU_TPR; // Transmit Pointer Register + AT91_REG DBGU_TCR; // Transmit Counter Register + AT91_REG DBGU_RNPR; // Receive Next Pointer Register + AT91_REG DBGU_RNCR; // Receive Next Counter Register + AT91_REG DBGU_TNPR; // Transmit Next Pointer Register + AT91_REG DBGU_TNCR; // Transmit Next Counter Register + AT91_REG DBGU_PTCR; // PDC Transfer Control Register + AT91_REG DBGU_PTSR; // PDC Transfer Status Register + AT91_REG Reserved12[6]; // + AT91_REG DBGU_CIDR; // Chip ID Register + AT91_REG DBGU_EXID; // Chip ID Extension Register + AT91_REG Reserved13[46]; // + AT91_REG EFC0_FMR; // EFC Flash Mode Register + AT91_REG EFC0_FCR; // EFC Flash Command Register + AT91_REG EFC0_FSR; // EFC Flash Status Register + AT91_REG EFC0_FRR; // EFC Flash Result Register + AT91_REG Reserved14[1]; // + AT91_REG EFC0_FVR; // EFC Flash Version Register + AT91_REG Reserved15[122]; // + AT91_REG EFC1_FMR; // EFC Flash Mode Register + AT91_REG EFC1_FCR; // EFC Flash Command Register + AT91_REG EFC1_FSR; // EFC Flash Status Register + AT91_REG EFC1_FRR; // EFC Flash Result Register + AT91_REG Reserved16[1]; // + AT91_REG EFC1_FVR; // EFC Flash Version Register + AT91_REG Reserved17[122]; // + AT91_REG PIOA_PER; // PIO Enable Register + AT91_REG PIOA_PDR; // PIO Disable Register + AT91_REG PIOA_PSR; // PIO Status Register + AT91_REG Reserved18[1]; // + AT91_REG PIOA_OER; // Output Enable Register + AT91_REG PIOA_ODR; // Output Disable Registerr + AT91_REG PIOA_OSR; // Output Status Register + AT91_REG Reserved19[1]; // + AT91_REG PIOA_IFER; // Input Filter Enable Register + AT91_REG PIOA_IFDR; // Input Filter Disable Register + AT91_REG PIOA_IFSR; // Input Filter Status Register + AT91_REG Reserved20[1]; // + AT91_REG PIOA_SODR; // Set Output Data Register + AT91_REG PIOA_CODR; // Clear Output Data Register + AT91_REG PIOA_ODSR; // Output Data Status Register + AT91_REG PIOA_PDSR; // Pin Data Status Register + AT91_REG PIOA_IER; // Interrupt Enable Register + AT91_REG PIOA_IDR; // Interrupt Disable Register + AT91_REG PIOA_IMR; // Interrupt Mask Register + AT91_REG PIOA_ISR; // Interrupt Status Register + AT91_REG PIOA_MDER; // Multi-driver Enable Register + AT91_REG PIOA_MDDR; // Multi-driver Disable Register + AT91_REG PIOA_MDSR; // Multi-driver Status Register + AT91_REG Reserved21[1]; // + AT91_REG PIOA_PPUDR; // Pull-up Disable Register + AT91_REG PIOA_PPUER; // Pull-up Enable Register + AT91_REG PIOA_PPUSR; // Pull-up Status Register + AT91_REG Reserved22[1]; // + AT91_REG PIOA_ABSR; // Peripheral AB Select Register + AT91_REG Reserved23[3]; // + AT91_REG PIOA_SCIFSR; // System Clock Glitch Input Filter Select Register + AT91_REG PIOA_DIFSR; // Debouncing Input Filter Select Register + AT91_REG PIOA_IFDGSR; // Glitch or Debouncing Input Filter Clock Selection Status Register + AT91_REG PIOA_SCDR; // Slow Clock Divider Debouncing Register + AT91_REG Reserved24[4]; // + AT91_REG PIOA_OWER; // Output Write Enable Register + AT91_REG PIOA_OWDR; // Output Write Disable Register + AT91_REG PIOA_OWSR; // Output Write Status Register + AT91_REG Reserved25[1]; // + AT91_REG PIOA_AIMER; // Additional Interrupt Modes Enable Register + AT91_REG PIOA_AIMDR; // Additional Interrupt Modes Disables Register + AT91_REG PIOA_AIMMR; // Additional Interrupt Modes Mask Register + AT91_REG Reserved26[1]; // + AT91_REG PIOA_ESR; // Edge Select Register + AT91_REG PIOA_LSR; // Level Select Register + AT91_REG PIOA_ELSR; // Edge/Level Status Register + AT91_REG Reserved27[1]; // + AT91_REG PIOA_FELLSR; // Falling Edge/Low Level Select Register + AT91_REG PIOA_REHLSR; // Rising Edge/ High Level Select Register + AT91_REG PIOA_FRLHSR; // Fall/Rise - Low/High Status Register + AT91_REG Reserved28[1]; // + AT91_REG PIOA_LOCKSR; // Lock Status Register + AT91_REG Reserved29[6]; // + AT91_REG PIOA_VER; // PIO VERSION REGISTER + AT91_REG Reserved30[8]; // + AT91_REG PIOA_KER; // Keypad Controller Enable Register + AT91_REG PIOA_KRCR; // Keypad Controller Row Column Register + AT91_REG PIOA_KDR; // Keypad Controller Debouncing Register + AT91_REG Reserved31[1]; // + AT91_REG PIOA_KIER; // Keypad Controller Interrupt Enable Register + AT91_REG PIOA_KIDR; // Keypad Controller Interrupt Disable Register + AT91_REG PIOA_KIMR; // Keypad Controller Interrupt Mask Register + AT91_REG PIOA_KSR; // Keypad Controller Status Register + AT91_REG PIOA_KKPR; // Keypad Controller Key Press Register + AT91_REG PIOA_KKRR; // Keypad Controller Key Release Register + AT91_REG Reserved32[46]; // + AT91_REG PIOB_PER; // PIO Enable Register + AT91_REG PIOB_PDR; // PIO Disable Register + AT91_REG PIOB_PSR; // PIO Status Register + AT91_REG Reserved33[1]; // + AT91_REG PIOB_OER; // Output Enable Register + AT91_REG PIOB_ODR; // Output Disable Registerr + AT91_REG PIOB_OSR; // Output Status Register + AT91_REG Reserved34[1]; // + AT91_REG PIOB_IFER; // Input Filter Enable Register + AT91_REG PIOB_IFDR; // Input Filter Disable Register + AT91_REG PIOB_IFSR; // Input Filter Status Register + AT91_REG Reserved35[1]; // + AT91_REG PIOB_SODR; // Set Output Data Register + AT91_REG PIOB_CODR; // Clear Output Data Register + AT91_REG PIOB_ODSR; // Output Data Status Register + AT91_REG PIOB_PDSR; // Pin Data Status Register + AT91_REG PIOB_IER; // Interrupt Enable Register + AT91_REG PIOB_IDR; // Interrupt Disable Register + AT91_REG PIOB_IMR; // Interrupt Mask Register + AT91_REG PIOB_ISR; // Interrupt Status Register + AT91_REG PIOB_MDER; // Multi-driver Enable Register + AT91_REG PIOB_MDDR; // Multi-driver Disable Register + AT91_REG PIOB_MDSR; // Multi-driver Status Register + AT91_REG Reserved36[1]; // + AT91_REG PIOB_PPUDR; // Pull-up Disable Register + AT91_REG PIOB_PPUER; // Pull-up Enable Register + AT91_REG PIOB_PPUSR; // Pull-up Status Register + AT91_REG Reserved37[1]; // + AT91_REG PIOB_ABSR; // Peripheral AB Select Register + AT91_REG Reserved38[3]; // + AT91_REG PIOB_SCIFSR; // System Clock Glitch Input Filter Select Register + AT91_REG PIOB_DIFSR; // Debouncing Input Filter Select Register + AT91_REG PIOB_IFDGSR; // Glitch or Debouncing Input Filter Clock Selection Status Register + AT91_REG PIOB_SCDR; // Slow Clock Divider Debouncing Register + AT91_REG Reserved39[4]; // + AT91_REG PIOB_OWER; // Output Write Enable Register + AT91_REG PIOB_OWDR; // Output Write Disable Register + AT91_REG PIOB_OWSR; // Output Write Status Register + AT91_REG Reserved40[1]; // + AT91_REG PIOB_AIMER; // Additional Interrupt Modes Enable Register + AT91_REG PIOB_AIMDR; // Additional Interrupt Modes Disables Register + AT91_REG PIOB_AIMMR; // Additional Interrupt Modes Mask Register + AT91_REG Reserved41[1]; // + AT91_REG PIOB_ESR; // Edge Select Register + AT91_REG PIOB_LSR; // Level Select Register + AT91_REG PIOB_ELSR; // Edge/Level Status Register + AT91_REG Reserved42[1]; // + AT91_REG PIOB_FELLSR; // Falling Edge/Low Level Select Register + AT91_REG PIOB_REHLSR; // Rising Edge/ High Level Select Register + AT91_REG PIOB_FRLHSR; // Fall/Rise - Low/High Status Register + AT91_REG Reserved43[1]; // + AT91_REG PIOB_LOCKSR; // Lock Status Register + AT91_REG Reserved44[6]; // + AT91_REG PIOB_VER; // PIO VERSION REGISTER + AT91_REG Reserved45[8]; // + AT91_REG PIOB_KER; // Keypad Controller Enable Register + AT91_REG PIOB_KRCR; // Keypad Controller Row Column Register + AT91_REG PIOB_KDR; // Keypad Controller Debouncing Register + AT91_REG Reserved46[1]; // + AT91_REG PIOB_KIER; // Keypad Controller Interrupt Enable Register + AT91_REG PIOB_KIDR; // Keypad Controller Interrupt Disable Register + AT91_REG PIOB_KIMR; // Keypad Controller Interrupt Mask Register + AT91_REG PIOB_KSR; // Keypad Controller Status Register + AT91_REG PIOB_KKPR; // Keypad Controller Key Press Register + AT91_REG PIOB_KKRR; // Keypad Controller Key Release Register + AT91_REG Reserved47[46]; // + AT91_REG PIOC_PER; // PIO Enable Register + AT91_REG PIOC_PDR; // PIO Disable Register + AT91_REG PIOC_PSR; // PIO Status Register + AT91_REG Reserved48[1]; // + AT91_REG PIOC_OER; // Output Enable Register + AT91_REG PIOC_ODR; // Output Disable Registerr + AT91_REG PIOC_OSR; // Output Status Register + AT91_REG Reserved49[1]; // + AT91_REG PIOC_IFER; // Input Filter Enable Register + AT91_REG PIOC_IFDR; // Input Filter Disable Register + AT91_REG PIOC_IFSR; // Input Filter Status Register + AT91_REG Reserved50[1]; // + AT91_REG PIOC_SODR; // Set Output Data Register + AT91_REG PIOC_CODR; // Clear Output Data Register + AT91_REG PIOC_ODSR; // Output Data Status Register + AT91_REG PIOC_PDSR; // Pin Data Status Register + AT91_REG PIOC_IER; // Interrupt Enable Register + AT91_REG PIOC_IDR; // Interrupt Disable Register + AT91_REG PIOC_IMR; // Interrupt Mask Register + AT91_REG PIOC_ISR; // Interrupt Status Register + AT91_REG PIOC_MDER; // Multi-driver Enable Register + AT91_REG PIOC_MDDR; // Multi-driver Disable Register + AT91_REG PIOC_MDSR; // Multi-driver Status Register + AT91_REG Reserved51[1]; // + AT91_REG PIOC_PPUDR; // Pull-up Disable Register + AT91_REG PIOC_PPUER; // Pull-up Enable Register + AT91_REG PIOC_PPUSR; // Pull-up Status Register + AT91_REG Reserved52[1]; // + AT91_REG PIOC_ABSR; // Peripheral AB Select Register + AT91_REG Reserved53[3]; // + AT91_REG PIOC_SCIFSR; // System Clock Glitch Input Filter Select Register + AT91_REG PIOC_DIFSR; // Debouncing Input Filter Select Register + AT91_REG PIOC_IFDGSR; // Glitch or Debouncing Input Filter Clock Selection Status Register + AT91_REG PIOC_SCDR; // Slow Clock Divider Debouncing Register + AT91_REG Reserved54[4]; // + AT91_REG PIOC_OWER; // Output Write Enable Register + AT91_REG PIOC_OWDR; // Output Write Disable Register + AT91_REG PIOC_OWSR; // Output Write Status Register + AT91_REG Reserved55[1]; // + AT91_REG PIOC_AIMER; // Additional Interrupt Modes Enable Register + AT91_REG PIOC_AIMDR; // Additional Interrupt Modes Disables Register + AT91_REG PIOC_AIMMR; // Additional Interrupt Modes Mask Register + AT91_REG Reserved56[1]; // + AT91_REG PIOC_ESR; // Edge Select Register + AT91_REG PIOC_LSR; // Level Select Register + AT91_REG PIOC_ELSR; // Edge/Level Status Register + AT91_REG Reserved57[1]; // + AT91_REG PIOC_FELLSR; // Falling Edge/Low Level Select Register + AT91_REG PIOC_REHLSR; // Rising Edge/ High Level Select Register + AT91_REG PIOC_FRLHSR; // Fall/Rise - Low/High Status Register + AT91_REG Reserved58[1]; // + AT91_REG PIOC_LOCKSR; // Lock Status Register + AT91_REG Reserved59[6]; // + AT91_REG PIOC_VER; // PIO VERSION REGISTER + AT91_REG Reserved60[8]; // + AT91_REG PIOC_KER; // Keypad Controller Enable Register + AT91_REG PIOC_KRCR; // Keypad Controller Row Column Register + AT91_REG PIOC_KDR; // Keypad Controller Debouncing Register + AT91_REG Reserved61[1]; // + AT91_REG PIOC_KIER; // Keypad Controller Interrupt Enable Register + AT91_REG PIOC_KIDR; // Keypad Controller Interrupt Disable Register + AT91_REG PIOC_KIMR; // Keypad Controller Interrupt Mask Register + AT91_REG PIOC_KSR; // Keypad Controller Status Register + AT91_REG PIOC_KKPR; // Keypad Controller Key Press Register + AT91_REG PIOC_KKRR; // Keypad Controller Key Release Register + AT91_REG Reserved62[46]; // + AT91_REG RSTC_RCR; // Reset Control Register + AT91_REG RSTC_RSR; // Reset Status Register + AT91_REG RSTC_RMR; // Reset Mode Register + AT91_REG Reserved63[1]; // + AT91_REG SUPC_CR; // Control Register + AT91_REG SUPC_BOMR; // Brown Out Mode Register + AT91_REG SUPC_MR; // Mode Register + AT91_REG SUPC_WUMR; // Wake Up Mode Register + AT91_REG SUPC_WUIR; // Wake Up Inputs Register + AT91_REG SUPC_SR; // Status Register + AT91_REG SUPC_FWUTR; // Flash Wake-up Timer Register + AT91_REG Reserved64[1]; // + AT91_REG RTTC_RTMR; // Real-time Mode Register + AT91_REG RTTC_RTAR; // Real-time Alarm Register + AT91_REG RTTC_RTVR; // Real-time Value Register + AT91_REG RTTC_RTSR; // Real-time Status Register + AT91_REG Reserved65[4]; // + AT91_REG WDTC_WDCR; // Watchdog Control Register + AT91_REG WDTC_WDMR; // Watchdog Mode Register + AT91_REG WDTC_WDSR; // Watchdog Status Register + AT91_REG Reserved66[1]; // + AT91_REG RTC_CR; // Control Register + AT91_REG RTC_MR; // Mode Register + AT91_REG RTC_TIMR; // Time Register + AT91_REG RTC_CALR; // Calendar Register + AT91_REG RTC_TIMALR; // Time Alarm Register + AT91_REG RTC_CALALR; // Calendar Alarm Register + AT91_REG RTC_SR; // Status Register + AT91_REG RTC_SCCR; // Status Clear Command Register + AT91_REG RTC_IER; // Interrupt Enable Register + AT91_REG RTC_IDR; // Interrupt Disable Register + AT91_REG RTC_IMR; // Interrupt Mask Register + AT91_REG RTC_VER; // Valid Entry Register + AT91_REG SYS_GPBR[8]; // General Purpose Register + AT91_REG Reserved67[19]; // + AT91_REG RSTC_VER; // Version Register +} AT91S_SYS, *AT91PS_SYS; +#else +#define GPBR (AT91_CAST(AT91_REG *) 0x00001290) // (GPBR) General Purpose Register + +#endif +// -------- GPBR : (SYS Offset: 0x1290) GPBR General Purpose Register -------- +#define AT91C_GPBR_GPRV (0x0 << 0) // (SYS) General Purpose Register Value + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR HSMC4 Chip Select interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_HSMC4_CS { + AT91_REG HSMC4_SETUP; // Setup Register + AT91_REG HSMC4_PULSE; // Pulse Register + AT91_REG HSMC4_CYCLE; // Cycle Register + AT91_REG HSMC4_TIMINGS; // Timmings Register + AT91_REG HSMC4_MODE; // Mode Register +} AT91S_HSMC4_CS, *AT91PS_HSMC4_CS; +#else +#define HSMC4_SETUP (AT91_CAST(AT91_REG *) 0x00000000) // (HSMC4_SETUP) Setup Register +#define HSMC4_PULSE (AT91_CAST(AT91_REG *) 0x00000004) // (HSMC4_PULSE) Pulse Register +#define HSMC4_CYCLE (AT91_CAST(AT91_REG *) 0x00000008) // (HSMC4_CYCLE) Cycle Register +#define HSMC4_TIMINGS (AT91_CAST(AT91_REG *) 0x0000000C) // (HSMC4_TIMINGS) Timmings Register +#define HSMC4_MODE (AT91_CAST(AT91_REG *) 0x00000010) // (HSMC4_MODE) Mode Register + +#endif +// -------- HSMC4_SETUP : (HSMC4_CS Offset: 0x0) HSMC4 SETUP -------- +#define AT91C_HSMC4_NWE_SETUP (0x3F << 0) // (HSMC4_CS) NWE Setup length +#define AT91C_HSMC4_NCS_WR_SETUP (0x3F << 8) // (HSMC4_CS) NCS Setup length in Write access +#define AT91C_HSMC4_NRD_SETUP (0x3F << 16) // (HSMC4_CS) NRD Setup length +#define AT91C_HSMC4_NCS_RD_SETUP (0x3F << 24) // (HSMC4_CS) NCS Setup legnth in Read access +// -------- HSMC4_PULSE : (HSMC4_CS Offset: 0x4) HSMC4 PULSE -------- +#define AT91C_HSMC4_NWE_PULSE (0x3F << 0) // (HSMC4_CS) NWE Pulse Length +#define AT91C_HSMC4_NCS_WR_PULSE (0x3F << 8) // (HSMC4_CS) NCS Pulse length in WRITE access +#define AT91C_HSMC4_NRD_PULSE (0x3F << 16) // (HSMC4_CS) NRD Pulse length +#define AT91C_HSMC4_NCS_RD_PULSE (0x3F << 24) // (HSMC4_CS) NCS Pulse length in READ access +// -------- HSMC4_CYCLE : (HSMC4_CS Offset: 0x8) HSMC4 CYCLE -------- +#define AT91C_HSMC4_NWE_CYCLE (0x1FF << 0) // (HSMC4_CS) Total Write Cycle Length +#define AT91C_HSMC4_NRD_CYCLE (0x1FF << 16) // (HSMC4_CS) Total Read Cycle Length +// -------- HSMC4_TIMINGS : (HSMC4_CS Offset: 0xc) HSMC4 TIMINGS -------- +#define AT91C_HSMC4_TCLR (0xF << 0) // (HSMC4_CS) CLE to REN low delay +#define AT91C_HSMC4_TADL (0xF << 4) // (HSMC4_CS) ALE to data start +#define AT91C_HSMC4_TAR (0xF << 8) // (HSMC4_CS) ALE to REN low delay +#define AT91C_HSMC4_OCMSEN (0x1 << 12) // (HSMC4_CS) Off Chip Memory Scrambling Enable +#define AT91C_HSMC4_TRR (0xF << 16) // (HSMC4_CS) Ready to REN low delay +#define AT91C_HSMC4_TWB (0xF << 24) // (HSMC4_CS) WEN high to REN to busy +#define AT91C_HSMC4_RBNSEL (0x7 << 28) // (HSMC4_CS) Ready/Busy Line Selection +#define AT91C_HSMC4_NFSEL (0x1 << 31) // (HSMC4_CS) Nand Flash Selection +// -------- HSMC4_MODE : (HSMC4_CS Offset: 0x10) HSMC4 MODE -------- +#define AT91C_HSMC4_READ_MODE (0x1 << 0) // (HSMC4_CS) Read Mode +#define AT91C_HSMC4_WRITE_MODE (0x1 << 1) // (HSMC4_CS) Write Mode +#define AT91C_HSMC4_EXNW_MODE (0x3 << 4) // (HSMC4_CS) NWAIT Mode +#define AT91C_HSMC4_EXNW_MODE_NWAIT_DISABLE (0x0 << 4) // (HSMC4_CS) External NWAIT disabled. +#define AT91C_HSMC4_EXNW_MODE_NWAIT_ENABLE_FROZEN (0x2 << 4) // (HSMC4_CS) External NWAIT enabled in frozen mode. +#define AT91C_HSMC4_EXNW_MODE_NWAIT_ENABLE_READY (0x3 << 4) // (HSMC4_CS) External NWAIT enabled in ready mode. +#define AT91C_HSMC4_BAT (0x1 << 8) // (HSMC4_CS) Byte Access Type +#define AT91C_HSMC4_BAT_BYTE_SELECT (0x0 << 8) // (HSMC4_CS) Write controled by ncs, nbs0, nbs1, nbs2, nbs3. Read controled by ncs, nrd, nbs0, nbs1, nbs2, nbs3. +#define AT91C_HSMC4_BAT_BYTE_WRITE (0x1 << 8) // (HSMC4_CS) Write controled by ncs, nwe0, nwe1, nwe2, nwe3. Read controled by ncs and nrd. +#define AT91C_HSMC4_DBW (0x3 << 12) // (HSMC4_CS) Data Bus Width +#define AT91C_HSMC4_DBW_WIDTH_EIGTH_BITS (0x0 << 12) // (HSMC4_CS) 8 bits. +#define AT91C_HSMC4_DBW_WIDTH_SIXTEEN_BITS (0x1 << 12) // (HSMC4_CS) 16 bits. +#define AT91C_HSMC4_DBW_WIDTH_THIRTY_TWO_BITS (0x2 << 12) // (HSMC4_CS) 32 bits. +#define AT91C_HSMC4_TDF_CYCLES (0xF << 16) // (HSMC4_CS) Data Float Time. +#define AT91C_HSMC4_TDF_MODE (0x1 << 20) // (HSMC4_CS) TDF Enabled. +#define AT91C_HSMC4_PMEN (0x1 << 24) // (HSMC4_CS) Page Mode Enabled. +#define AT91C_HSMC4_PS (0x3 << 28) // (HSMC4_CS) Page Size +#define AT91C_HSMC4_PS_SIZE_FOUR_BYTES (0x0 << 28) // (HSMC4_CS) 4 bytes. +#define AT91C_HSMC4_PS_SIZE_EIGHT_BYTES (0x1 << 28) // (HSMC4_CS) 8 bytes. +#define AT91C_HSMC4_PS_SIZE_SIXTEEN_BYTES (0x2 << 28) // (HSMC4_CS) 16 bytes. +#define AT91C_HSMC4_PS_SIZE_THIRTY_TWO_BYTES (0x3 << 28) // (HSMC4_CS) 32 bytes. + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR AHB Static Memory Controller 4 Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_HSMC4 { + AT91_REG HSMC4_CFG; // Configuration Register + AT91_REG HSMC4_CTRL; // Control Register + AT91_REG HSMC4_SR; // Status Register + AT91_REG HSMC4_IER; // Interrupt Enable Register + AT91_REG HSMC4_IDR; // Interrupt Disable Register + AT91_REG HSMC4_IMR; // Interrupt Mask Register + AT91_REG HSMC4_ADDR; // Address Cycle Zero Register + AT91_REG HSMC4_BANK; // Bank Register + AT91_REG HSMC4_ECCCR; // ECC reset register + AT91_REG HSMC4_ECCCMD; // ECC Page size register + AT91_REG HSMC4_ECCSR1; // ECC Status register 1 + AT91_REG HSMC4_ECCPR0; // ECC Parity register 0 + AT91_REG HSMC4_ECCPR1; // ECC Parity register 1 + AT91_REG HSMC4_ECCSR2; // ECC Status register 2 + AT91_REG HSMC4_ECCPR2; // ECC Parity register 2 + AT91_REG HSMC4_ECCPR3; // ECC Parity register 3 + AT91_REG HSMC4_ECCPR4; // ECC Parity register 4 + AT91_REG HSMC4_ECCPR5; // ECC Parity register 5 + AT91_REG HSMC4_ECCPR6; // ECC Parity register 6 + AT91_REG HSMC4_ECCPR7; // ECC Parity register 7 + AT91_REG HSMC4_ECCPR8; // ECC Parity register 8 + AT91_REG HSMC4_ECCPR9; // ECC Parity register 9 + AT91_REG HSMC4_ECCPR10; // ECC Parity register 10 + AT91_REG HSMC4_ECCPR11; // ECC Parity register 11 + AT91_REG HSMC4_ECCPR12; // ECC Parity register 12 + AT91_REG HSMC4_ECCPR13; // ECC Parity register 13 + AT91_REG HSMC4_ECCPR14; // ECC Parity register 14 + AT91_REG HSMC4_Eccpr15; // ECC Parity register 15 + AT91_REG Reserved0[40]; // + AT91_REG HSMC4_OCMS; // OCMS MODE register + AT91_REG HSMC4_KEY1; // KEY1 Register + AT91_REG HSMC4_KEY2; // KEY2 Register + AT91_REG Reserved1[50]; // + AT91_REG HSMC4_WPCR; // Write Protection Control register + AT91_REG HSMC4_WPSR; // Write Protection Status Register + AT91_REG HSMC4_ADDRSIZE; // Write Protection Status Register + AT91_REG HSMC4_IPNAME1; // Write Protection Status Register + AT91_REG HSMC4_IPNAME2; // Write Protection Status Register + AT91_REG HSMC4_FEATURES; // Write Protection Status Register + AT91_REG HSMC4_VER; // HSMC4 Version Register + AT91_REG HSMC4_DUMMY; // This rtegister was created only ti have AHB constants +} AT91S_HSMC4, *AT91PS_HSMC4; +#else +#define HSMC4_CFG (AT91_CAST(AT91_REG *) 0x00000000) // (HSMC4_CFG) Configuration Register +#define HSMC4_CTRL (AT91_CAST(AT91_REG *) 0x00000004) // (HSMC4_CTRL) Control Register +#define HSMC4_SR (AT91_CAST(AT91_REG *) 0x00000008) // (HSMC4_SR) Status Register +#define HSMC4_IER (AT91_CAST(AT91_REG *) 0x0000000C) // (HSMC4_IER) Interrupt Enable Register +#define HSMC4_IDR (AT91_CAST(AT91_REG *) 0x00000010) // (HSMC4_IDR) Interrupt Disable Register +#define HSMC4_IMR (AT91_CAST(AT91_REG *) 0x00000014) // (HSMC4_IMR) Interrupt Mask Register +#define HSMC4_ADDR (AT91_CAST(AT91_REG *) 0x00000018) // (HSMC4_ADDR) Address Cycle Zero Register +#define HSMC4_BANK (AT91_CAST(AT91_REG *) 0x0000001C) // (HSMC4_BANK) Bank Register +#define HSMC4_ECCCR (AT91_CAST(AT91_REG *) 0x00000020) // (HSMC4_ECCCR) ECC reset register +#define HSMC4_ECCCMD (AT91_CAST(AT91_REG *) 0x00000024) // (HSMC4_ECCCMD) ECC Page size register +#define HSMC4_ECCSR1 (AT91_CAST(AT91_REG *) 0x00000028) // (HSMC4_ECCSR1) ECC Status register 1 +#define HSMC4_ECCPR0 (AT91_CAST(AT91_REG *) 0x0000002C) // (HSMC4_ECCPR0) ECC Parity register 0 +#define HSMC4_ECCPR1 (AT91_CAST(AT91_REG *) 0x00000030) // (HSMC4_ECCPR1) ECC Parity register 1 +#define HSMC4_ECCSR2 (AT91_CAST(AT91_REG *) 0x00000034) // (HSMC4_ECCSR2) ECC Status register 2 +#define HSMC4_ECCPR2 (AT91_CAST(AT91_REG *) 0x00000038) // (HSMC4_ECCPR2) ECC Parity register 2 +#define HSMC4_ECCPR3 (AT91_CAST(AT91_REG *) 0x0000003C) // (HSMC4_ECCPR3) ECC Parity register 3 +#define HSMC4_ECCPR4 (AT91_CAST(AT91_REG *) 0x00000040) // (HSMC4_ECCPR4) ECC Parity register 4 +#define HSMC4_ECCPR5 (AT91_CAST(AT91_REG *) 0x00000044) // (HSMC4_ECCPR5) ECC Parity register 5 +#define HSMC4_ECCPR6 (AT91_CAST(AT91_REG *) 0x00000048) // (HSMC4_ECCPR6) ECC Parity register 6 +#define HSMC4_ECCPR7 (AT91_CAST(AT91_REG *) 0x0000004C) // (HSMC4_ECCPR7) ECC Parity register 7 +#define HSMC4_ECCPR8 (AT91_CAST(AT91_REG *) 0x00000050) // (HSMC4_ECCPR8) ECC Parity register 8 +#define HSMC4_ECCPR9 (AT91_CAST(AT91_REG *) 0x00000054) // (HSMC4_ECCPR9) ECC Parity register 9 +#define HSMC4_ECCPR10 (AT91_CAST(AT91_REG *) 0x00000058) // (HSMC4_ECCPR10) ECC Parity register 10 +#define HSMC4_ECCPR11 (AT91_CAST(AT91_REG *) 0x0000005C) // (HSMC4_ECCPR11) ECC Parity register 11 +#define HSMC4_ECCPR12 (AT91_CAST(AT91_REG *) 0x00000060) // (HSMC4_ECCPR12) ECC Parity register 12 +#define HSMC4_ECCPR13 (AT91_CAST(AT91_REG *) 0x00000064) // (HSMC4_ECCPR13) ECC Parity register 13 +#define HSMC4_ECCPR14 (AT91_CAST(AT91_REG *) 0x00000068) // (HSMC4_ECCPR14) ECC Parity register 14 +#define Hsmc4_Eccpr15 (AT91_CAST(AT91_REG *) 0x0000006C) // (Hsmc4_Eccpr15) ECC Parity register 15 +#define HSMC4_OCMS (AT91_CAST(AT91_REG *) 0x00000110) // (HSMC4_OCMS) OCMS MODE register +#define HSMC4_KEY1 (AT91_CAST(AT91_REG *) 0x00000114) // (HSMC4_KEY1) KEY1 Register +#define HSMC4_KEY2 (AT91_CAST(AT91_REG *) 0x00000118) // (HSMC4_KEY2) KEY2 Register +#define HSMC4_WPCR (AT91_CAST(AT91_REG *) 0x000001E4) // (HSMC4_WPCR) Write Protection Control register +#define HSMC4_WPSR (AT91_CAST(AT91_REG *) 0x000001E8) // (HSMC4_WPSR) Write Protection Status Register +#define HSMC4_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000001EC) // (HSMC4_ADDRSIZE) Write Protection Status Register +#define HSMC4_IPNAME1 (AT91_CAST(AT91_REG *) 0x000001F0) // (HSMC4_IPNAME1) Write Protection Status Register +#define HSMC4_IPNAME2 (AT91_CAST(AT91_REG *) 0x000001F4) // (HSMC4_IPNAME2) Write Protection Status Register +#define HSMC4_FEATURES (AT91_CAST(AT91_REG *) 0x000001F8) // (HSMC4_FEATURES) Write Protection Status Register +#define HSMC4_VER (AT91_CAST(AT91_REG *) 0x000001FC) // (HSMC4_VER) HSMC4 Version Register +#define HSMC4_DUMMY (AT91_CAST(AT91_REG *) 0x00000200) // (HSMC4_DUMMY) This rtegister was created only ti have AHB constants + +#endif +// -------- HSMC4_CFG : (HSMC4 Offset: 0x0) Configuration Register -------- +#define AT91C_HSMC4_PAGESIZE (0x3 << 0) // (HSMC4) PAGESIZE field description +#define AT91C_HSMC4_PAGESIZE_528_Bytes (0x0) // (HSMC4) 512 bytes plus 16 bytes page size +#define AT91C_HSMC4_PAGESIZE_1056_Bytes (0x1) // (HSMC4) 1024 bytes plus 32 bytes page size +#define AT91C_HSMC4_PAGESIZE_2112_Bytes (0x2) // (HSMC4) 2048 bytes plus 64 bytes page size +#define AT91C_HSMC4_PAGESIZE_4224_Bytes (0x3) // (HSMC4) 4096 bytes plus 128 bytes page size +#define AT91C_HSMC4_WSPARE (0x1 << 8) // (HSMC4) Spare area access in Write Mode +#define AT91C_HSMC4_RSPARE (0x1 << 9) // (HSMC4) Spare area access in Read Mode +#define AT91C_HSMC4_EDGECTRL (0x1 << 12) // (HSMC4) Rising/Falling Edge Detection Control +#define AT91C_HSMC4_RBEDGE (0x1 << 13) // (HSMC4) Ready/Busy Signal edge Detection +#define AT91C_HSMC4_DTOCYC (0xF << 16) // (HSMC4) Data Timeout Cycle Number +#define AT91C_HSMC4_DTOMUL (0x7 << 20) // (HSMC4) Data Timeout Multiplier +#define AT91C_HSMC4_DTOMUL_1 (0x0 << 20) // (HSMC4) DTOCYC x 1 +#define AT91C_HSMC4_DTOMUL_16 (0x1 << 20) // (HSMC4) DTOCYC x 16 +#define AT91C_HSMC4_DTOMUL_128 (0x2 << 20) // (HSMC4) DTOCYC x 128 +#define AT91C_HSMC4_DTOMUL_256 (0x3 << 20) // (HSMC4) DTOCYC x 256 +#define AT91C_HSMC4_DTOMUL_1024 (0x4 << 20) // (HSMC4) DTOCYC x 1024 +#define AT91C_HSMC4_DTOMUL_4096 (0x5 << 20) // (HSMC4) DTOCYC x 4096 +#define AT91C_HSMC4_DTOMUL_65536 (0x6 << 20) // (HSMC4) DTOCYC x 65536 +#define AT91C_HSMC4_DTOMUL_1048576 (0x7 << 20) // (HSMC4) DTOCYC x 1048576 +// -------- HSMC4_CTRL : (HSMC4 Offset: 0x4) Control Register -------- +#define AT91C_HSMC4_NFCEN (0x1 << 0) // (HSMC4) Nand Flash Controller Host Enable +#define AT91C_HSMC4_NFCDIS (0x1 << 1) // (HSMC4) Nand Flash Controller Host Disable +#define AT91C_HSMC4_HOSTEN (0x1 << 8) // (HSMC4) If set to one, the Host controller is activated and perform a data transfer phase. +#define AT91C_HSMC4_HOSTWR (0x1 << 11) // (HSMC4) If this field is set to one, the host transfers data from the internal SRAM to the Memory Device. +#define AT91C_HSMC4_HOSTCSID (0x7 << 12) // (HSMC4) Host Controller Chip select Id +#define AT91C_HSMC4_HOSTCSID_0 (0x0 << 12) // (HSMC4) CS0 +#define AT91C_HSMC4_HOSTCSID_1 (0x1 << 12) // (HSMC4) CS1 +#define AT91C_HSMC4_HOSTCSID_2 (0x2 << 12) // (HSMC4) CS2 +#define AT91C_HSMC4_HOSTCSID_3 (0x3 << 12) // (HSMC4) CS3 +#define AT91C_HSMC4_HOSTCSID_4 (0x4 << 12) // (HSMC4) CS4 +#define AT91C_HSMC4_HOSTCSID_5 (0x5 << 12) // (HSMC4) CS5 +#define AT91C_HSMC4_HOSTCSID_6 (0x6 << 12) // (HSMC4) CS6 +#define AT91C_HSMC4_HOSTCSID_7 (0x7 << 12) // (HSMC4) CS7 +#define AT91C_HSMC4_VALID (0x1 << 15) // (HSMC4) When set to 1, a write operation modifies both HOSTCSID and HOSTWR fields. +// -------- HSMC4_SR : (HSMC4 Offset: 0x8) HSMC4 Status Register -------- +#define AT91C_HSMC4_NFCSTS (0x1 << 0) // (HSMC4) Nand Flash Controller status +#define AT91C_HSMC4_RBRISE (0x1 << 4) // (HSMC4) Selected Ready Busy Rising Edge Detected flag +#define AT91C_HSMC4_RBFALL (0x1 << 5) // (HSMC4) Selected Ready Busy Falling Edge Detected flag +#define AT91C_HSMC4_HOSTBUSY (0x1 << 8) // (HSMC4) Host Busy +#define AT91C_HSMC4_HOSTW (0x1 << 11) // (HSMC4) Host Write/Read Operation +#define AT91C_HSMC4_HOSTCS (0x7 << 12) // (HSMC4) Host Controller Chip select Id +#define AT91C_HSMC4_HOSTCS_0 (0x0 << 12) // (HSMC4) CS0 +#define AT91C_HSMC4_HOSTCS_1 (0x1 << 12) // (HSMC4) CS1 +#define AT91C_HSMC4_HOSTCS_2 (0x2 << 12) // (HSMC4) CS2 +#define AT91C_HSMC4_HOSTCS_3 (0x3 << 12) // (HSMC4) CS3 +#define AT91C_HSMC4_HOSTCS_4 (0x4 << 12) // (HSMC4) CS4 +#define AT91C_HSMC4_HOSTCS_5 (0x5 << 12) // (HSMC4) CS5 +#define AT91C_HSMC4_HOSTCS_6 (0x6 << 12) // (HSMC4) CS6 +#define AT91C_HSMC4_HOSTCS_7 (0x7 << 12) // (HSMC4) CS7 +#define AT91C_HSMC4_XFRDONE (0x1 << 16) // (HSMC4) Host Data Transfer Terminated +#define AT91C_HSMC4_CMDDONE (0x1 << 17) // (HSMC4) Command Done +#define AT91C_HSMC4_ECCRDY (0x1 << 18) // (HSMC4) ECC ready +#define AT91C_HSMC4_DTOE (0x1 << 20) // (HSMC4) Data timeout Error +#define AT91C_HSMC4_UNDEF (0x1 << 21) // (HSMC4) Undefined Area Error +#define AT91C_HSMC4_AWB (0x1 << 22) // (HSMC4) Accessing While Busy Error +#define AT91C_HSMC4_HASE (0x1 << 23) // (HSMC4) Host Controller Access Size Error +#define AT91C_HSMC4_RBEDGE0 (0x1 << 24) // (HSMC4) Ready Busy line 0 Edge detected +#define AT91C_HSMC4_RBEDGE1 (0x1 << 25) // (HSMC4) Ready Busy line 1 Edge detected +#define AT91C_HSMC4_RBEDGE2 (0x1 << 26) // (HSMC4) Ready Busy line 2 Edge detected +#define AT91C_HSMC4_RBEDGE3 (0x1 << 27) // (HSMC4) Ready Busy line 3 Edge detected +#define AT91C_HSMC4_RBEDGE4 (0x1 << 28) // (HSMC4) Ready Busy line 4 Edge detected +#define AT91C_HSMC4_RBEDGE5 (0x1 << 29) // (HSMC4) Ready Busy line 5 Edge detected +#define AT91C_HSMC4_RBEDGE6 (0x1 << 30) // (HSMC4) Ready Busy line 6 Edge detected +#define AT91C_HSMC4_RBEDGE7 (0x1 << 31) // (HSMC4) Ready Busy line 7 Edge detected +// -------- HSMC4_IER : (HSMC4 Offset: 0xc) HSMC4 Interrupt Enable Register -------- +// -------- HSMC4_IDR : (HSMC4 Offset: 0x10) HSMC4 Interrupt Disable Register -------- +// -------- HSMC4_IMR : (HSMC4 Offset: 0x14) HSMC4 Interrupt Mask Register -------- +// -------- HSMC4_ADDR : (HSMC4 Offset: 0x18) Address Cycle Zero Register -------- +#define AT91C_HSMC4_ADDRCYCLE0 (0xFF << 0) // (HSMC4) Nand Flash Array Address cycle 0 +// -------- HSMC4_BANK : (HSMC4 Offset: 0x1c) Bank Register -------- +#define AT91C_BANK (0x7 << 0) // (HSMC4) Bank identifier +#define AT91C_BANK_0 (0x0) // (HSMC4) BANK0 +#define AT91C_BANK_1 (0x1) // (HSMC4) BANK1 +#define AT91C_BANK_2 (0x2) // (HSMC4) BANK2 +#define AT91C_BANK_3 (0x3) // (HSMC4) BANK3 +#define AT91C_BANK_4 (0x4) // (HSMC4) BANK4 +#define AT91C_BANK_5 (0x5) // (HSMC4) BANK5 +#define AT91C_BANK_6 (0x6) // (HSMC4) BANK6 +#define AT91C_BANK_7 (0x7) // (HSMC4) BANK7 +// -------- HSMC4_ECCCR : (HSMC4 Offset: 0x20) ECC Control Register -------- +#define AT91C_HSMC4_ECCRESET (0x1 << 0) // (HSMC4) Reset ECC +// -------- HSMC4_ECCCMD : (HSMC4 Offset: 0x24) ECC mode register -------- +#define AT91C_ECC_PAGE_SIZE (0x3 << 0) // (HSMC4) Nand Flash page size +#define AT91C_ECC_TYPCORRECT (0x3 << 4) // (HSMC4) Nand Flash page size +#define AT91C_ECC_TYPCORRECT_ONE_PER_PAGE (0x0 << 4) // (HSMC4) +#define AT91C_ECC_TYPCORRECT_ONE_EVERY_256_BYTES (0x1 << 4) // (HSMC4) +#define AT91C_ECC_TYPCORRECT_ONE_EVERY_512_BYTES (0x2 << 4) // (HSMC4) +// -------- HSMC4_ECCSR1 : (HSMC4 Offset: 0x28) ECC Status Register 1 -------- +#define AT91C_HSMC4_ECC_RECERR0 (0x1 << 0) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR0 (0x1 << 1) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR0 (0x1 << 2) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR1 (0x1 << 4) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR1 (0x1 << 5) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR1 (0x1 << 6) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR2 (0x1 << 8) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR2 (0x1 << 9) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR2 (0x1 << 10) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR3 (0x1 << 12) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR3 (0x1 << 13) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR3 (0x1 << 14) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR4 (0x1 << 16) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR4 (0x1 << 17) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR4 (0x1 << 18) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR5 (0x1 << 20) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR5 (0x1 << 21) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR5 (0x1 << 22) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR6 (0x1 << 24) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR6 (0x1 << 25) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR6 (0x1 << 26) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR7 (0x1 << 28) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR7 (0x1 << 29) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR7 (0x1 << 30) // (HSMC4) Multiple Error +// -------- HSMC4_ECCPR0 : (HSMC4 Offset: 0x2c) HSMC4 ECC parity Register 0 -------- +#define AT91C_HSMC4_ECC_BITADDR (0x7 << 0) // (HSMC4) Corrupted Bit Address in the page +#define AT91C_HSMC4_ECC_WORDADDR (0xFF << 3) // (HSMC4) Corrupted Word Address in the page +#define AT91C_HSMC4_ECC_NPARITY (0x7FF << 12) // (HSMC4) Parity N +// -------- HSMC4_ECCPR1 : (HSMC4 Offset: 0x30) HSMC4 ECC parity Register 1 -------- +// -------- HSMC4_ECCSR2 : (HSMC4 Offset: 0x34) ECC Status Register 2 -------- +#define AT91C_HSMC4_ECC_RECERR8 (0x1 << 0) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR8 (0x1 << 1) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR8 (0x1 << 2) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR9 (0x1 << 4) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR9 (0x1 << 5) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR9 (0x1 << 6) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR10 (0x1 << 8) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR10 (0x1 << 9) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR10 (0x1 << 10) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR11 (0x1 << 12) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR11 (0x1 << 13) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR11 (0x1 << 14) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR12 (0x1 << 16) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR12 (0x1 << 17) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR12 (0x1 << 18) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR13 (0x1 << 20) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR13 (0x1 << 21) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR13 (0x1 << 22) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR14 (0x1 << 24) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR14 (0x1 << 25) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR14 (0x1 << 26) // (HSMC4) Multiple Error +#define AT91C_HSMC4_ECC_RECERR15 (0x1 << 28) // (HSMC4) Recoverable Error +#define AT91C_HSMC4_ECC_ECCERR15 (0x1 << 29) // (HSMC4) ECC Error +#define AT91C_HSMC4_ECC_MULERR15 (0x1 << 30) // (HSMC4) Multiple Error +// -------- HSMC4_ECCPR2 : (HSMC4 Offset: 0x38) HSMC4 ECC parity Register 2 -------- +// -------- HSMC4_ECCPR3 : (HSMC4 Offset: 0x3c) HSMC4 ECC parity Register 3 -------- +// -------- HSMC4_ECCPR4 : (HSMC4 Offset: 0x40) HSMC4 ECC parity Register 4 -------- +// -------- HSMC4_ECCPR5 : (HSMC4 Offset: 0x44) HSMC4 ECC parity Register 5 -------- +// -------- HSMC4_ECCPR6 : (HSMC4 Offset: 0x48) HSMC4 ECC parity Register 6 -------- +// -------- HSMC4_ECCPR7 : (HSMC4 Offset: 0x4c) HSMC4 ECC parity Register 7 -------- +// -------- HSMC4_ECCPR8 : (HSMC4 Offset: 0x50) HSMC4 ECC parity Register 8 -------- +// -------- HSMC4_ECCPR9 : (HSMC4 Offset: 0x54) HSMC4 ECC parity Register 9 -------- +// -------- HSMC4_ECCPR10 : (HSMC4 Offset: 0x58) HSMC4 ECC parity Register 10 -------- +// -------- HSMC4_ECCPR11 : (HSMC4 Offset: 0x5c) HSMC4 ECC parity Register 11 -------- +// -------- HSMC4_ECCPR12 : (HSMC4 Offset: 0x60) HSMC4 ECC parity Register 12 -------- +// -------- HSMC4_ECCPR13 : (HSMC4 Offset: 0x64) HSMC4 ECC parity Register 13 -------- +// -------- HSMC4_ECCPR14 : (HSMC4 Offset: 0x68) HSMC4 ECC parity Register 14 -------- +// -------- HSMC4_ECCPR15 : (HSMC4 Offset: 0x6c) HSMC4 ECC parity Register 15 -------- +// -------- HSMC4_OCMS : (HSMC4 Offset: 0x110) HSMC4 OCMS Register -------- +#define AT91C_HSMC4_OCMS_SRSE (0x1 << 0) // (HSMC4) Static Memory Controller Scrambling Enable +#define AT91C_HSMC4_OCMS_SMSE (0x1 << 1) // (HSMC4) SRAM Scramling Enable +// -------- HSMC4_KEY1 : (HSMC4 Offset: 0x114) HSMC4 OCMS KEY1 Register -------- +#define AT91C_HSMC4_OCMS_KEY1 (0x0 << 0) // (HSMC4) OCMS Key 2 +// -------- HSMC4_OCMS_KEY2 : (HSMC4 Offset: 0x118) HSMC4 OCMS KEY2 Register -------- +#define AT91C_HSMC4_OCMS_KEY2 (0x0 << 0) // (HSMC4) OCMS Key 2 +// -------- HSMC4_WPCR : (HSMC4 Offset: 0x1e4) HSMC4 Witre Protection Control Register -------- +#define AT91C_HSMC4_WP_EN (0x1 << 0) // (HSMC4) Write Protection Enable +#define AT91C_HSMC4_WP_KEY (0xFFFFFF << 8) // (HSMC4) Protection Password +// -------- HSMC4_WPSR : (HSMC4 Offset: 0x1e8) HSMC4 WPSR Register -------- +#define AT91C_HSMC4_WP_VS (0xF << 0) // (HSMC4) Write Protection Violation Status +#define AT91C_HSMC4_WP_VS_WP_VS0 (0x0) // (HSMC4) No write protection violation since the last read of this register +#define AT91C_HSMC4_WP_VS_WP_VS1 (0x1) // (HSMC4) write protection detected unauthorized attempt to write a control register had occured (since the last read) +#define AT91C_HSMC4_WP_VS_WP_VS2 (0x2) // (HSMC4) Software reset had been performed while write protection was enabled (since the last read) +#define AT91C_HSMC4_WP_VS_WP_VS3 (0x3) // (HSMC4) Both write protection violation and software reset with write protection enabled had occured since the last read +#define AT91C_ (0x0 << 8) // (HSMC4) +// -------- HSMC4_VER : (HSMC4 Offset: 0x1fc) HSMC4 VERSION Register -------- +// -------- HSMC4_DUMMY : (HSMC4 Offset: 0x200) HSMC4 DUMMY REGISTER -------- +#define AT91C_HSMC4_CMD1 (0xFF << 2) // (HSMC4) Command Register Value for Cycle 1 +#define AT91C_HSMC4_CMD2 (0xFF << 10) // (HSMC4) Command Register Value for Cycle 2 +#define AT91C_HSMC4_VCMD2 (0x1 << 18) // (HSMC4) Valid Cycle 2 Command +#define AT91C_HSMC4_ACYCLE (0x7 << 19) // (HSMC4) Number of Address required for the current command +#define AT91C_HSMC4_ACYCLE_HSMC4_ACYCLE_NONE (0x0 << 19) // (HSMC4) No address cycle +#define AT91C_HSMC4_ACYCLE_HSMC4_ACYCLE_ONE (0x1 << 19) // (HSMC4) One address cycle +#define AT91C_HSMC4_ACYCLE_HSMC4_ACYCLE_TWO (0x2 << 19) // (HSMC4) Two address cycles +#define AT91C_HSMC4_ACYCLE_HSMC4_ACYCLE_THREE (0x3 << 19) // (HSMC4) Three address cycles +#define AT91C_HSMC4_ACYCLE_HSMC4_ACYCLE_FOUR (0x4 << 19) // (HSMC4) Four address cycles +#define AT91C_HSMC4_ACYCLE_HSMC4_ACYCLE_FIVE (0x5 << 19) // (HSMC4) Five address cycles +#define AT91C_HSMC4_CSID (0x7 << 22) // (HSMC4) Chip Select Identifier +#define AT91C_HSMC4_CSID_0 (0x0 << 22) // (HSMC4) CS0 +#define AT91C_HSMC4_CSID_1 (0x1 << 22) // (HSMC4) CS1 +#define AT91C_HSMC4_CSID_2 (0x2 << 22) // (HSMC4) CS2 +#define AT91C_HSMC4_CSID_3 (0x3 << 22) // (HSMC4) CS3 +#define AT91C_HSMC4_CSID_4 (0x4 << 22) // (HSMC4) CS4 +#define AT91C_HSMC4_CSID_5 (0x5 << 22) // (HSMC4) CS5 +#define AT91C_HSMC4_CSID_6 (0x6 << 22) // (HSMC4) CS6 +#define AT91C_HSMC4_CSID_7 (0x7 << 22) // (HSMC4) CS7 +#define AT91C_HSMC4_HOST_EN (0x1 << 25) // (HSMC4) Host Main Controller Enable +#define AT91C_HSMC4_HOST_WR (0x1 << 26) // (HSMC4) HOSTWR : Host Main Controller Write Enable +#define AT91C_HSMC4_HOSTCMD (0x1 << 27) // (HSMC4) Host Command Enable + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR AHB Matrix2 Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_HMATRIX2 { + AT91_REG HMATRIX2_MCFG0; // Master Configuration Register 0 : ARM I and D + AT91_REG HMATRIX2_MCFG1; // Master Configuration Register 1 : ARM S + AT91_REG HMATRIX2_MCFG2; // Master Configuration Register 2 + AT91_REG HMATRIX2_MCFG3; // Master Configuration Register 3 + AT91_REG HMATRIX2_MCFG4; // Master Configuration Register 4 + AT91_REG HMATRIX2_MCFG5; // Master Configuration Register 5 + AT91_REG HMATRIX2_MCFG6; // Master Configuration Register 6 + AT91_REG HMATRIX2_MCFG7; // Master Configuration Register 7 + AT91_REG Reserved0[8]; // + AT91_REG HMATRIX2_SCFG0; // Slave Configuration Register 0 + AT91_REG HMATRIX2_SCFG1; // Slave Configuration Register 1 + AT91_REG HMATRIX2_SCFG2; // Slave Configuration Register 2 + AT91_REG HMATRIX2_SCFG3; // Slave Configuration Register 3 + AT91_REG HMATRIX2_SCFG4; // Slave Configuration Register 4 + AT91_REG HMATRIX2_SCFG5; // Slave Configuration Register 5 + AT91_REG HMATRIX2_SCFG6; // Slave Configuration Register 6 + AT91_REG HMATRIX2_SCFG7; // Slave Configuration Register 5 + AT91_REG HMATRIX2_SCFG8; // Slave Configuration Register 8 + AT91_REG Reserved1[43]; // + AT91_REG HMATRIX2_SFR0 ; // Special Function Register 0 + AT91_REG HMATRIX2_SFR1 ; // Special Function Register 1 + AT91_REG HMATRIX2_SFR2 ; // Special Function Register 2 + AT91_REG HMATRIX2_SFR3 ; // Special Function Register 3 + AT91_REG HMATRIX2_SFR4 ; // Special Function Register 4 + AT91_REG HMATRIX2_SFR5 ; // Special Function Register 5 + AT91_REG HMATRIX2_SFR6 ; // Special Function Register 6 + AT91_REG HMATRIX2_SFR7 ; // Special Function Register 7 + AT91_REG HMATRIX2_SFR8 ; // Special Function Register 8 + AT91_REG HMATRIX2_SFR9 ; // Special Function Register 9 + AT91_REG HMATRIX2_SFR10; // Special Function Register 10 + AT91_REG HMATRIX2_SFR11; // Special Function Register 11 + AT91_REG HMATRIX2_SFR12; // Special Function Register 12 + AT91_REG HMATRIX2_SFR13; // Special Function Register 13 + AT91_REG HMATRIX2_SFR14; // Special Function Register 14 + AT91_REG HMATRIX2_SFR15; // Special Function Register 15 + AT91_REG Reserved2[39]; // + AT91_REG HMATRIX2_ADDRSIZE; // HMATRIX2 ADDRSIZE REGISTER + AT91_REG HMATRIX2_IPNAME1; // HMATRIX2 IPNAME1 REGISTER + AT91_REG HMATRIX2_IPNAME2; // HMATRIX2 IPNAME2 REGISTER + AT91_REG HMATRIX2_FEATURES; // HMATRIX2 FEATURES REGISTER + AT91_REG HMATRIX2_VER; // HMATRIX2 VERSION REGISTER +} AT91S_HMATRIX2, *AT91PS_HMATRIX2; +#else +#define MATRIX_MCFG0 (AT91_CAST(AT91_REG *) 0x00000000) // (MATRIX_MCFG0) Master Configuration Register 0 : ARM I and D +#define MATRIX_MCFG1 (AT91_CAST(AT91_REG *) 0x00000004) // (MATRIX_MCFG1) Master Configuration Register 1 : ARM S +#define MATRIX_MCFG2 (AT91_CAST(AT91_REG *) 0x00000008) // (MATRIX_MCFG2) Master Configuration Register 2 +#define MATRIX_MCFG3 (AT91_CAST(AT91_REG *) 0x0000000C) // (MATRIX_MCFG3) Master Configuration Register 3 +#define MATRIX_MCFG4 (AT91_CAST(AT91_REG *) 0x00000010) // (MATRIX_MCFG4) Master Configuration Register 4 +#define MATRIX_MCFG5 (AT91_CAST(AT91_REG *) 0x00000014) // (MATRIX_MCFG5) Master Configuration Register 5 +#define MATRIX_MCFG6 (AT91_CAST(AT91_REG *) 0x00000018) // (MATRIX_MCFG6) Master Configuration Register 6 +#define MATRIX_MCFG7 (AT91_CAST(AT91_REG *) 0x0000001C) // (MATRIX_MCFG7) Master Configuration Register 7 +#define MATRIX_SCFG0 (AT91_CAST(AT91_REG *) 0x00000040) // (MATRIX_SCFG0) Slave Configuration Register 0 +#define MATRIX_SCFG1 (AT91_CAST(AT91_REG *) 0x00000044) // (MATRIX_SCFG1) Slave Configuration Register 1 +#define MATRIX_SCFG2 (AT91_CAST(AT91_REG *) 0x00000048) // (MATRIX_SCFG2) Slave Configuration Register 2 +#define MATRIX_SCFG3 (AT91_CAST(AT91_REG *) 0x0000004C) // (MATRIX_SCFG3) Slave Configuration Register 3 +#define MATRIX_SCFG4 (AT91_CAST(AT91_REG *) 0x00000050) // (MATRIX_SCFG4) Slave Configuration Register 4 +#define MATRIX_SCFG5 (AT91_CAST(AT91_REG *) 0x00000054) // (MATRIX_SCFG5) Slave Configuration Register 5 +#define MATRIX_SCFG6 (AT91_CAST(AT91_REG *) 0x00000058) // (MATRIX_SCFG6) Slave Configuration Register 6 +#define MATRIX_SCFG7 (AT91_CAST(AT91_REG *) 0x0000005C) // (MATRIX_SCFG7) Slave Configuration Register 5 +#define MATRIX_SCFG8 (AT91_CAST(AT91_REG *) 0x00000060) // (MATRIX_SCFG8) Slave Configuration Register 8 +#define MATRIX_SFR0 (AT91_CAST(AT91_REG *) 0x00000110) // (MATRIX_SFR0 ) Special Function Register 0 +#define MATRIX_SFR1 (AT91_CAST(AT91_REG *) 0x00000114) // (MATRIX_SFR1 ) Special Function Register 1 +#define MATRIX_SFR2 (AT91_CAST(AT91_REG *) 0x00000118) // (MATRIX_SFR2 ) Special Function Register 2 +#define MATRIX_SFR3 (AT91_CAST(AT91_REG *) 0x0000011C) // (MATRIX_SFR3 ) Special Function Register 3 +#define MATRIX_SFR4 (AT91_CAST(AT91_REG *) 0x00000120) // (MATRIX_SFR4 ) Special Function Register 4 +#define MATRIX_SFR5 (AT91_CAST(AT91_REG *) 0x00000124) // (MATRIX_SFR5 ) Special Function Register 5 +#define MATRIX_SFR6 (AT91_CAST(AT91_REG *) 0x00000128) // (MATRIX_SFR6 ) Special Function Register 6 +#define MATRIX_SFR7 (AT91_CAST(AT91_REG *) 0x0000012C) // (MATRIX_SFR7 ) Special Function Register 7 +#define MATRIX_SFR8 (AT91_CAST(AT91_REG *) 0x00000130) // (MATRIX_SFR8 ) Special Function Register 8 +#define MATRIX_SFR9 (AT91_CAST(AT91_REG *) 0x00000134) // (MATRIX_SFR9 ) Special Function Register 9 +#define MATRIX_SFR10 (AT91_CAST(AT91_REG *) 0x00000138) // (MATRIX_SFR10) Special Function Register 10 +#define MATRIX_SFR11 (AT91_CAST(AT91_REG *) 0x0000013C) // (MATRIX_SFR11) Special Function Register 11 +#define MATRIX_SFR12 (AT91_CAST(AT91_REG *) 0x00000140) // (MATRIX_SFR12) Special Function Register 12 +#define MATRIX_SFR13 (AT91_CAST(AT91_REG *) 0x00000144) // (MATRIX_SFR13) Special Function Register 13 +#define MATRIX_SFR14 (AT91_CAST(AT91_REG *) 0x00000148) // (MATRIX_SFR14) Special Function Register 14 +#define MATRIX_SFR15 (AT91_CAST(AT91_REG *) 0x0000014C) // (MATRIX_SFR15) Special Function Register 15 +#define HMATRIX2_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000001EC) // (HMATRIX2_ADDRSIZE) HMATRIX2 ADDRSIZE REGISTER +#define HMATRIX2_IPNAME1 (AT91_CAST(AT91_REG *) 0x000001F0) // (HMATRIX2_IPNAME1) HMATRIX2 IPNAME1 REGISTER +#define HMATRIX2_IPNAME2 (AT91_CAST(AT91_REG *) 0x000001F4) // (HMATRIX2_IPNAME2) HMATRIX2 IPNAME2 REGISTER +#define HMATRIX2_FEATURES (AT91_CAST(AT91_REG *) 0x000001F8) // (HMATRIX2_FEATURES) HMATRIX2 FEATURES REGISTER +#define HMATRIX2_VER (AT91_CAST(AT91_REG *) 0x000001FC) // (HMATRIX2_VER) HMATRIX2 VERSION REGISTER + +#endif +// -------- MATRIX_MCFG0 : (HMATRIX2 Offset: 0x0) Master Configuration Register ARM bus I and D -------- +#define AT91C_MATRIX_ULBT (0x7 << 0) // (HMATRIX2) Undefined Length Burst Type +#define AT91C_MATRIX_ULBT_INFINIT_LENGTH (0x0) // (HMATRIX2) infinite length burst +#define AT91C_MATRIX_ULBT_SINGLE_ACCESS (0x1) // (HMATRIX2) Single Access +#define AT91C_MATRIX_ULBT_4_BEAT (0x2) // (HMATRIX2) 4 Beat Burst +#define AT91C_MATRIX_ULBT_8_BEAT (0x3) // (HMATRIX2) 8 Beat Burst +#define AT91C_MATRIX_ULBT_16_BEAT (0x4) // (HMATRIX2) 16 Beat Burst +#define AT91C_MATRIX_ULBT_32_BEAT (0x5) // (HMATRIX2) 32 Beat Burst +#define AT91C_MATRIX_ULBT_64_BEAT (0x6) // (HMATRIX2) 64 Beat Burst +#define AT91C_MATRIX_ULBT_128_BEAT (0x7) // (HMATRIX2) 128 Beat Burst +// -------- MATRIX_MCFG1 : (HMATRIX2 Offset: 0x4) Master Configuration Register ARM bus S -------- +// -------- MATRIX_MCFG2 : (HMATRIX2 Offset: 0x8) Master Configuration Register -------- +// -------- MATRIX_MCFG3 : (HMATRIX2 Offset: 0xc) Master Configuration Register -------- +// -------- MATRIX_MCFG4 : (HMATRIX2 Offset: 0x10) Master Configuration Register -------- +// -------- MATRIX_MCFG5 : (HMATRIX2 Offset: 0x14) Master Configuration Register -------- +// -------- MATRIX_MCFG6 : (HMATRIX2 Offset: 0x18) Master Configuration Register -------- +// -------- MATRIX_MCFG7 : (HMATRIX2 Offset: 0x1c) Master Configuration Register -------- +// -------- MATRIX_SCFG0 : (HMATRIX2 Offset: 0x40) Slave Configuration Register 0 -------- +#define AT91C_MATRIX_SLOT_CYCLE (0xFF << 0) // (HMATRIX2) Maximum Number of Allowed Cycles for a Burst +#define AT91C_MATRIX_DEFMSTR_TYPE (0x3 << 16) // (HMATRIX2) Default Master Type +#define AT91C_MATRIX_DEFMSTR_TYPE_NO_DEFMSTR (0x0 << 16) // (HMATRIX2) No Default Master. At the end of current slave access, if no other master request is pending, the slave is deconnected from all masters. This results in having a one cycle latency for the first transfer of a burst. +#define AT91C_MATRIX_DEFMSTR_TYPE_LAST_DEFMSTR (0x1 << 16) // (HMATRIX2) Last Default Master. At the end of current slave access, if no other master request is pending, the slave stay connected with the last master having accessed it. This results in not having the one cycle latency when the last master re-trying access on the slave. +#define AT91C_MATRIX_DEFMSTR_TYPE_FIXED_DEFMSTR (0x2 << 16) // (HMATRIX2) Fixed Default Master. At the end of current slave access, if no other master request is pending, the slave connects with fixed which number is in FIXED_DEFMSTR field. This results in not having the one cycle latency when the fixed master re-trying access on the slave. +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG0 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG0_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG1 : (HMATRIX2 Offset: 0x44) Slave Configuration Register 1 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG1 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG1_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG2 : (HMATRIX2 Offset: 0x48) Slave Configuration Register 2 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG2 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG2_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG3 : (HMATRIX2 Offset: 0x4c) Slave Configuration Register 3 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG3 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG3_ARMC (0x0 << 18) // (HMATRIX2) ARMC is Default Master +// -------- MATRIX_SCFG4 : (HMATRIX2 Offset: 0x50) Slave Configuration Register 4 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG4 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG4_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG5 : (HMATRIX2 Offset: 0x54) Slave Configuration Register 5 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG5 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG5_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG6 : (HMATRIX2 Offset: 0x58) Slave Configuration Register 6 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG6 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG6_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG7 : (HMATRIX2 Offset: 0x5c) Slave Configuration Register 7 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG7 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG7_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +// -------- MATRIX_SCFG8 : (HMATRIX2 Offset: 0x60) Slave Configuration Register 8 -------- +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG8 (0x7 << 18) // (HMATRIX2) Fixed Index of Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG8_ARMS (0x1 << 18) // (HMATRIX2) ARMS is Default Master +#define AT91C_MATRIX_FIXED_DEFMSTR_SCFG8_HDMA (0x4 << 18) // (HMATRIX2) HDMA is Default Master +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x110) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x114) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x118) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x11c) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x120) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x124) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x128) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x12c) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x130) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x134) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x138) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x13c) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x140) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x144) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x148) Special Function Register 0 -------- +// -------- MATRIX_SFR0 : (HMATRIX2 Offset: 0x14c) Special Function Register 0 -------- +// -------- HMATRIX2_VER : (HMATRIX2 Offset: 0x1fc) VERSION Register -------- +#define AT91C_HMATRIX2_VER (0xF << 0) // (HMATRIX2) VERSION Register + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR NESTED vector Interrupt Controller +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_NVIC { + AT91_REG Reserved0[1]; // + AT91_REG NVIC_ICTR; // Interrupt Control Type Register + AT91_REG Reserved1[2]; // + AT91_REG NVIC_STICKCSR; // SysTick Control and Status Register + AT91_REG NVIC_STICKRVR; // SysTick Reload Value Register + AT91_REG NVIC_STICKCVR; // SysTick Current Value Register + AT91_REG NVIC_STICKCALVR; // SysTick Calibration Value Register + AT91_REG Reserved2[56]; // + AT91_REG NVIC_ISER[8]; // Set Enable Register + AT91_REG Reserved3[24]; // + AT91_REG NVIC_ICER[8]; // Clear enable Register + AT91_REG Reserved4[24]; // + AT91_REG NVIC_ISPR[8]; // Set Pending Register + AT91_REG Reserved5[24]; // + AT91_REG NVIC_ICPR[8]; // Clear Pending Register + AT91_REG Reserved6[24]; // + AT91_REG NVIC_ABR[8]; // Active Bit Register + AT91_REG Reserved7[56]; // + AT91_REG NVIC_IPR[60]; // Interrupt Mask Register + AT91_REG Reserved8[516]; // + AT91_REG NVIC_CPUID; // CPUID Base Register + AT91_REG NVIC_ICSR; // Interrupt Control State Register + AT91_REG NVIC_VTOFFR; // Vector Table Offset Register + AT91_REG NVIC_AIRCR; // Application Interrupt/Reset Control Reg + AT91_REG NVIC_SCR; // System Control Register + AT91_REG NVIC_CCR; // Configuration Control Register + AT91_REG NVIC_HAND4PR; // System Handlers 4-7 Priority Register + AT91_REG NVIC_HAND8PR; // System Handlers 8-11 Priority Register + AT91_REG NVIC_HAND12PR; // System Handlers 12-15 Priority Register + AT91_REG NVIC_HANDCSR; // System Handler Control and State Register + AT91_REG NVIC_CFSR; // Configurable Fault Status Register + AT91_REG NVIC_HFSR; // Hard Fault Status Register + AT91_REG NVIC_DFSR; // Debug Fault Status Register + AT91_REG NVIC_MMAR; // Mem Manage Address Register + AT91_REG NVIC_BFAR; // Bus Fault Address Register + AT91_REG NVIC_AFSR; // Auxiliary Fault Status Register + AT91_REG NVIC_PFR0; // Processor Feature register0 + AT91_REG NVIC_PFR1; // Processor Feature register1 + AT91_REG NVIC_DFR0; // Debug Feature register0 + AT91_REG NVIC_AFR0; // Auxiliary Feature register0 + AT91_REG NVIC_MMFR0; // Memory Model Feature register0 + AT91_REG NVIC_MMFR1; // Memory Model Feature register1 + AT91_REG NVIC_MMFR2; // Memory Model Feature register2 + AT91_REG NVIC_MMFR3; // Memory Model Feature register3 + AT91_REG NVIC_ISAR0; // ISA Feature register0 + AT91_REG NVIC_ISAR1; // ISA Feature register1 + AT91_REG NVIC_ISAR2; // ISA Feature register2 + AT91_REG NVIC_ISAR3; // ISA Feature register3 + AT91_REG NVIC_ISAR4; // ISA Feature register4 + AT91_REG Reserved9[99]; // + AT91_REG NVIC_STIR; // Software Trigger Interrupt Register + AT91_REG Reserved10[51]; // + AT91_REG NVIC_PID4; // Peripheral identification register + AT91_REG NVIC_PID5; // Peripheral identification register + AT91_REG NVIC_PID6; // Peripheral identification register + AT91_REG NVIC_PID7; // Peripheral identification register + AT91_REG NVIC_PID0; // Peripheral identification register b7:0 + AT91_REG NVIC_PID1; // Peripheral identification register b15:8 + AT91_REG NVIC_PID2; // Peripheral identification register b23:16 + AT91_REG NVIC_PID3; // Peripheral identification register b31:24 + AT91_REG NVIC_CID0; // Component identification register b7:0 + AT91_REG NVIC_CID1; // Component identification register b15:8 + AT91_REG NVIC_CID2; // Component identification register b23:16 + AT91_REG NVIC_CID3; // Component identification register b31:24 +} AT91S_NVIC, *AT91PS_NVIC; +#else +#define NVIC_ICTR (AT91_CAST(AT91_REG *) 0x00000004) // (NVIC_ICTR) Interrupt Control Type Register +#define NVIC_STICKCSR (AT91_CAST(AT91_REG *) 0x00000010) // (NVIC_STICKCSR) SysTick Control and Status Register +#define NVIC_STICKRVR (AT91_CAST(AT91_REG *) 0x00000014) // (NVIC_STICKRVR) SysTick Reload Value Register +#define NVIC_STICKCVR (AT91_CAST(AT91_REG *) 0x00000018) // (NVIC_STICKCVR) SysTick Current Value Register +#define NVIC_STICKCALVR (AT91_CAST(AT91_REG *) 0x0000001C) // (NVIC_STICKCALVR) SysTick Calibration Value Register +#define NVIC_ISER (AT91_CAST(AT91_REG *) 0x00000100) // (NVIC_ISER) Set Enable Register +#define NVIC_ICER (AT91_CAST(AT91_REG *) 0x00000180) // (NVIC_ICER) Clear enable Register +#define NVIC_ISPR (AT91_CAST(AT91_REG *) 0x00000200) // (NVIC_ISPR) Set Pending Register +#define NVIC_ICPR (AT91_CAST(AT91_REG *) 0x00000280) // (NVIC_ICPR) Clear Pending Register +#define NVIC_IABR (AT91_CAST(AT91_REG *) 0x00000300) // (NVIC_IABR) Active Bit Register +#define NVIC_IPR (AT91_CAST(AT91_REG *) 0x00000400) // (NVIC_IPR) Interrupt Mask Register +#define NVIC_CPUID (AT91_CAST(AT91_REG *) 0x00000D00) // (NVIC_CPUID) CPUID Base Register +#define NVIC_ICSR (AT91_CAST(AT91_REG *) 0x00000D04) // (NVIC_ICSR) Interrupt Control State Register +#define NVIC_VTOFFR (AT91_CAST(AT91_REG *) 0x00000D08) // (NVIC_VTOFFR) Vector Table Offset Register +#define NVIC_AIRCR (AT91_CAST(AT91_REG *) 0x00000D0C) // (NVIC_AIRCR) Application Interrupt/Reset Control Reg +#define NVIC_SCR (AT91_CAST(AT91_REG *) 0x00000D10) // (NVIC_SCR) System Control Register +#define NVIC_CCR (AT91_CAST(AT91_REG *) 0x00000D14) // (NVIC_CCR) Configuration Control Register +#define NVIC_HAND4PR (AT91_CAST(AT91_REG *) 0x00000D18) // (NVIC_HAND4PR) System Handlers 4-7 Priority Register +#define NVIC_HAND8PR (AT91_CAST(AT91_REG *) 0x00000D1C) // (NVIC_HAND8PR) System Handlers 8-11 Priority Register +#define NVIC_HAND12PR (AT91_CAST(AT91_REG *) 0x00000D20) // (NVIC_HAND12PR) System Handlers 12-15 Priority Register +#define NVIC_HANDCSR (AT91_CAST(AT91_REG *) 0x00000D24) // (NVIC_HANDCSR) System Handler Control and State Register +#define NVIC_CFSR (AT91_CAST(AT91_REG *) 0x00000D28) // (NVIC_CFSR) Configurable Fault Status Register +#define NVIC_HFSR (AT91_CAST(AT91_REG *) 0x00000D2C) // (NVIC_HFSR) Hard Fault Status Register +#define NVIC_DFSR (AT91_CAST(AT91_REG *) 0x00000D30) // (NVIC_DFSR) Debug Fault Status Register +#define NVIC_MMAR (AT91_CAST(AT91_REG *) 0x00000D34) // (NVIC_MMAR) Mem Manage Address Register +#define NVIC_BFAR (AT91_CAST(AT91_REG *) 0x00000D38) // (NVIC_BFAR) Bus Fault Address Register +#define NVIC_AFSR (AT91_CAST(AT91_REG *) 0x00000D3C) // (NVIC_AFSR) Auxiliary Fault Status Register +#define NVIC_PFR0 (AT91_CAST(AT91_REG *) 0x00000D40) // (NVIC_PFR0) Processor Feature register0 +#define NVIC_PFR1 (AT91_CAST(AT91_REG *) 0x00000D44) // (NVIC_PFR1) Processor Feature register1 +#define NVIC_DFR0 (AT91_CAST(AT91_REG *) 0x00000D48) // (NVIC_DFR0) Debug Feature register0 +#define NVIC_AFR0 (AT91_CAST(AT91_REG *) 0x00000D4C) // (NVIC_AFR0) Auxiliary Feature register0 +#define NVIC_MMFR0 (AT91_CAST(AT91_REG *) 0x00000D50) // (NVIC_MMFR0) Memory Model Feature register0 +#define NVIC_MMFR1 (AT91_CAST(AT91_REG *) 0x00000D54) // (NVIC_MMFR1) Memory Model Feature register1 +#define NVIC_MMFR2 (AT91_CAST(AT91_REG *) 0x00000D58) // (NVIC_MMFR2) Memory Model Feature register2 +#define NVIC_MMFR3 (AT91_CAST(AT91_REG *) 0x00000D5C) // (NVIC_MMFR3) Memory Model Feature register3 +#define NVIC_ISAR0 (AT91_CAST(AT91_REG *) 0x00000D60) // (NVIC_ISAR0) ISA Feature register0 +#define NVIC_ISAR1 (AT91_CAST(AT91_REG *) 0x00000D64) // (NVIC_ISAR1) ISA Feature register1 +#define NVIC_ISAR2 (AT91_CAST(AT91_REG *) 0x00000D68) // (NVIC_ISAR2) ISA Feature register2 +#define NVIC_ISAR3 (AT91_CAST(AT91_REG *) 0x00000D6C) // (NVIC_ISAR3) ISA Feature register3 +#define NVIC_ISAR4 (AT91_CAST(AT91_REG *) 0x00000D70) // (NVIC_ISAR4) ISA Feature register4 +#define NVIC_STIR (AT91_CAST(AT91_REG *) 0x00000F00) // (NVIC_STIR) Software Trigger Interrupt Register +#define NVIC_PID4 (AT91_CAST(AT91_REG *) 0x00000FD0) // (NVIC_PID4) Peripheral identification register +#define NVIC_PID5 (AT91_CAST(AT91_REG *) 0x00000FD4) // (NVIC_PID5) Peripheral identification register +#define NVIC_PID6 (AT91_CAST(AT91_REG *) 0x00000FD8) // (NVIC_PID6) Peripheral identification register +#define NVIC_PID7 (AT91_CAST(AT91_REG *) 0x00000FDC) // (NVIC_PID7) Peripheral identification register +#define NVIC_PID0 (AT91_CAST(AT91_REG *) 0x00000FE0) // (NVIC_PID0) Peripheral identification register b7:0 +#define NVIC_PID1 (AT91_CAST(AT91_REG *) 0x00000FE4) // (NVIC_PID1) Peripheral identification register b15:8 +#define NVIC_PID2 (AT91_CAST(AT91_REG *) 0x00000FE8) // (NVIC_PID2) Peripheral identification register b23:16 +#define NVIC_PID3 (AT91_CAST(AT91_REG *) 0x00000FEC) // (NVIC_PID3) Peripheral identification register b31:24 +#define NVIC_CID0 (AT91_CAST(AT91_REG *) 0x00000FF0) // (NVIC_CID0) Component identification register b7:0 +#define NVIC_CID1 (AT91_CAST(AT91_REG *) 0x00000FF4) // (NVIC_CID1) Component identification register b15:8 +#define NVIC_CID2 (AT91_CAST(AT91_REG *) 0x00000FF8) // (NVIC_CID2) Component identification register b23:16 +#define NVIC_CID3 (AT91_CAST(AT91_REG *) 0x00000FFC) // (NVIC_CID3) Component identification register b31:24 + +#endif +// -------- NVIC_ICTR : (NVIC Offset: 0x4) Interrupt Controller Type Register -------- +#define AT91C_NVIC_INTLINESNUM (0xF << 0) // (NVIC) Total number of interrupt lines +#define AT91C_NVIC_INTLINESNUM_32 (0x0) // (NVIC) up to 32 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_64 (0x1) // (NVIC) up to 64 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_96 (0x2) // (NVIC) up to 96 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_128 (0x3) // (NVIC) up to 128 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_160 (0x4) // (NVIC) up to 160 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_192 (0x5) // (NVIC) up to 192 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_224 (0x6) // (NVIC) up to 224 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_256 (0x7) // (NVIC) up to 256 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_288 (0x8) // (NVIC) up to 288 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_320 (0x9) // (NVIC) up to 320 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_352 (0xA) // (NVIC) up to 352 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_384 (0xB) // (NVIC) up to 384 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_416 (0xC) // (NVIC) up to 416 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_448 (0xD) // (NVIC) up to 448 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_480 (0xE) // (NVIC) up to 480 interrupt lines supported +#define AT91C_NVIC_INTLINESNUM_496 (0xF) // (NVIC) up to 496 interrupt lines supported) +// -------- NVIC_STICKCSR : (NVIC Offset: 0x10) SysTick Control and Status Register -------- +#define AT91C_NVIC_STICKENABLE (0x1 << 0) // (NVIC) SysTick counter enable. +#define AT91C_NVIC_STICKINT (0x1 << 1) // (NVIC) SysTick interrupt enable. +#define AT91C_NVIC_STICKCLKSOURCE (0x1 << 2) // (NVIC) Reference clock selection. +#define AT91C_NVIC_STICKCOUNTFLAG (0x1 << 16) // (NVIC) Return 1 if timer counted to 0 since last read. +// -------- NVIC_STICKRVR : (NVIC Offset: 0x14) SysTick Reload Value Register -------- +#define AT91C_NVIC_STICKRELOAD (0xFFFFFF << 0) // (NVIC) SysTick reload value. +// -------- NVIC_STICKCVR : (NVIC Offset: 0x18) SysTick Current Value Register -------- +#define AT91C_NVIC_STICKCURRENT (0x7FFFFFFF << 0) // (NVIC) SysTick current value. +// -------- NVIC_STICKCALVR : (NVIC Offset: 0x1c) SysTick Calibration Value Register -------- +#define AT91C_NVIC_STICKTENMS (0xFFFFFF << 0) // (NVIC) Reload value to use for 10ms timing. +#define AT91C_NVIC_STICKSKEW (0x1 << 30) // (NVIC) Read as 1 if the calibration value is not exactly 10ms because of clock frequency. +#define AT91C_NVIC_STICKNOREF (0x1 << 31) // (NVIC) Read as 1 if the reference clock is not provided. +// -------- NVIC_IPR : (NVIC Offset: 0x400) Interrupt Priority Registers -------- +#define AT91C_NVIC_PRI_N (0xFF << 0) // (NVIC) Priority of interrupt N (0, 4, 8, etc) +#define AT91C_NVIC_PRI_N1 (0xFF << 8) // (NVIC) Priority of interrupt N+1 (1, 5, 9, etc) +#define AT91C_NVIC_PRI_N2 (0xFF << 16) // (NVIC) Priority of interrupt N+2 (2, 6, 10, etc) +#define AT91C_NVIC_PRI_N3 (0xFF << 24) // (NVIC) Priority of interrupt N+3 (3, 7, 11, etc) +// -------- NVIC_CPUID : (NVIC Offset: 0xd00) CPU ID Base Register -------- +#define AT91C_NVIC_REVISION (0xF << 0) // (NVIC) Implementation defined revision number. +#define AT91C_NVIC_PARTNO (0xFFF << 4) // (NVIC) Number of processor within family +#define AT91C_NVIC_CONSTANT (0xF << 16) // (NVIC) Reads as 0xF +#define AT91C_NVIC_VARIANT (0xF << 20) // (NVIC) Implementation defined variant number. +#define AT91C_NVIC_IMPLEMENTER (0xFF << 24) // (NVIC) Implementer code. ARM is 0x41 +// -------- NVIC_ICSR : (NVIC Offset: 0xd04) Interrupt Control State Register -------- +#define AT91C_NVIC_VECTACTIVE (0x1FF << 0) // (NVIC) Read-only Active ISR number field +#define AT91C_NVIC_RETTOBASE (0x1 << 11) // (NVIC) Read-only +#define AT91C_NVIC_VECTPENDING (0x1FF << 12) // (NVIC) Read-only Pending ISR number field +#define AT91C_NVIC_ISRPENDING (0x1 << 22) // (NVIC) Read-only Interrupt pending flag. +#define AT91C_NVIC_ISRPREEMPT (0x1 << 23) // (NVIC) Read-only You must only use this at debug time +#define AT91C_NVIC_PENDSTCLR (0x1 << 25) // (NVIC) Write-only Clear pending SysTick bit +#define AT91C_NVIC_PENDSTSET (0x1 << 26) // (NVIC) Read/write Set a pending SysTick bit +#define AT91C_NVIC_PENDSVCLR (0x1 << 27) // (NVIC) Write-only Clear pending pendSV bit +#define AT91C_NVIC_PENDSVSET (0x1 << 28) // (NVIC) Read/write Set pending pendSV bit +#define AT91C_NVIC_NMIPENDSET (0x1 << 31) // (NVIC) Read/write Set pending NMI +// -------- NVIC_VTOFFR : (NVIC Offset: 0xd08) Vector Table Offset Register -------- +#define AT91C_NVIC_TBLOFF (0x3FFFFF << 7) // (NVIC) Vector table base offset field +#define AT91C_NVIC_TBLBASE (0x1 << 29) // (NVIC) Table base is in Code (0) or RAM (1) +#define AT91C_NVIC_TBLBASE_CODE (0x0 << 29) // (NVIC) Table base is in CODE +#define AT91C_NVIC_TBLBASE_RAM (0x1 << 29) // (NVIC) Table base is in RAM +// -------- NVIC_AIRCR : (NVIC Offset: 0xd0c) Application Interrupt and Reset Control Register -------- +#define AT91C_NVIC_VECTRESET (0x1 << 0) // (NVIC) System Reset bit +#define AT91C_NVIC_VECTCLRACTIVE (0x1 << 1) // (NVIC) Clear active vector bit +#define AT91C_NVIC_SYSRESETREQ (0x1 << 2) // (NVIC) Causes a signal to be asserted to the outer system that indicates a reset is requested +#define AT91C_NVIC_PRIGROUP (0x7 << 8) // (NVIC) Interrupt priority grouping field +#define AT91C_NVIC_PRIGROUP_0 (0x0 << 8) // (NVIC) indicates seven bits of pre-emption priority, one bit of subpriority +#define AT91C_NVIC_PRIGROUP_1 (0x1 << 8) // (NVIC) indicates six bits of pre-emption priority, two bits of subpriority +#define AT91C_NVIC_PRIGROUP_2 (0x2 << 8) // (NVIC) indicates five bits of pre-emption priority, three bits of subpriority +#define AT91C_NVIC_PRIGROUP_3 (0x3 << 8) // (NVIC) indicates four bits of pre-emption priority, four bits of subpriority +#define AT91C_NVIC_PRIGROUP_4 (0x4 << 8) // (NVIC) indicates three bits of pre-emption priority, five bits of subpriority +#define AT91C_NVIC_PRIGROUP_5 (0x5 << 8) // (NVIC) indicates two bits of pre-emption priority, six bits of subpriority +#define AT91C_NVIC_PRIGROUP_6 (0x6 << 8) // (NVIC) indicates one bit of pre-emption priority, seven bits of subpriority +#define AT91C_NVIC_PRIGROUP_7 (0x7 << 8) // (NVIC) indicates no pre-emption priority, eight bits of subpriority +#define AT91C_NVIC_ENDIANESS (0x1 << 15) // (NVIC) Data endianness bit +#define AT91C_NVIC_VECTKEY (0xFFFF << 16) // (NVIC) Register key +// -------- NVIC_SCR : (NVIC Offset: 0xd10) System Control Register -------- +#define AT91C_NVIC_SLEEPONEXIT (0x1 << 1) // (NVIC) Sleep on exit when returning from Handler mode to Thread mode +#define AT91C_NVIC_SLEEPDEEP (0x1 << 2) // (NVIC) Sleep deep bit +#define AT91C_NVIC_SEVONPEND (0x1 << 4) // (NVIC) When enabled, this causes WFE to wake up when an interrupt moves from inactive to pended +// -------- NVIC_CCR : (NVIC Offset: 0xd14) Configuration Control Register -------- +#define AT91C_NVIC_NONEBASETHRDENA (0x1 << 0) // (NVIC) When 0, default, It is only possible to enter Thread mode when returning from the last exception +#define AT91C_NVIC_USERSETMPEND (0x1 << 1) // (NVIC) +#define AT91C_NVIC_UNALIGN_TRP (0x1 << 3) // (NVIC) Trap for unaligned access +#define AT91C_NVIC_DIV_0_TRP (0x1 << 4) // (NVIC) Trap on Divide by 0 +#define AT91C_NVIC_BFHFNMIGN (0x1 << 8) // (NVIC) +#define AT91C_NVIC_STKALIGN (0x1 << 9) // (NVIC) +// -------- NVIC_HAND4PR : (NVIC Offset: 0xd18) System Handlers 4-7 Priority Register -------- +#define AT91C_NVIC_PRI_4 (0xFF << 0) // (NVIC) +#define AT91C_NVIC_PRI_5 (0xFF << 8) // (NVIC) +#define AT91C_NVIC_PRI_6 (0xFF << 16) // (NVIC) +#define AT91C_NVIC_PRI_7 (0xFF << 24) // (NVIC) +// -------- NVIC_HAND8PR : (NVIC Offset: 0xd1c) System Handlers 8-11 Priority Register -------- +#define AT91C_NVIC_PRI_8 (0xFF << 0) // (NVIC) +#define AT91C_NVIC_PRI_9 (0xFF << 8) // (NVIC) +#define AT91C_NVIC_PRI_10 (0xFF << 16) // (NVIC) +#define AT91C_NVIC_PRI_11 (0xFF << 24) // (NVIC) +// -------- NVIC_HAND12PR : (NVIC Offset: 0xd20) System Handlers 12-15 Priority Register -------- +#define AT91C_NVIC_PRI_12 (0xFF << 0) // (NVIC) +#define AT91C_NVIC_PRI_13 (0xFF << 8) // (NVIC) +#define AT91C_NVIC_PRI_14 (0xFF << 16) // (NVIC) +#define AT91C_NVIC_PRI_15 (0xFF << 24) // (NVIC) +// -------- NVIC_HANDCSR : (NVIC Offset: 0xd24) System Handler Control and State Register -------- +#define AT91C_NVIC_MEMFAULTACT (0x1 << 0) // (NVIC) +#define AT91C_NVIC_BUSFAULTACT (0x1 << 1) // (NVIC) +#define AT91C_NVIC_USGFAULTACT (0x1 << 3) // (NVIC) +#define AT91C_NVIC_SVCALLACT (0x1 << 7) // (NVIC) +#define AT91C_NVIC_MONITORACT (0x1 << 8) // (NVIC) +#define AT91C_NVIC_PENDSVACT (0x1 << 10) // (NVIC) +#define AT91C_NVIC_SYSTICKACT (0x1 << 11) // (NVIC) +#define AT91C_NVIC_USGFAULTPENDED (0x1 << 12) // (NVIC) +#define AT91C_NVIC_MEMFAULTPENDED (0x1 << 13) // (NVIC) +#define AT91C_NVIC_BUSFAULTPENDED (0x1 << 14) // (NVIC) +#define AT91C_NVIC_SVCALLPENDED (0x1 << 15) // (NVIC) +#define AT91C_NVIC_MEMFAULTENA (0x1 << 16) // (NVIC) +#define AT91C_NVIC_BUSFAULTENA (0x1 << 17) // (NVIC) +#define AT91C_NVIC_USGFAULTENA (0x1 << 18) // (NVIC) +// -------- NVIC_CFSR : (NVIC Offset: 0xd28) Configurable Fault Status Registers -------- +#define AT91C_NVIC_MEMMANAGE (0xFF << 0) // (NVIC) +#define AT91C_NVIC_BUSFAULT (0xFF << 8) // (NVIC) +#define AT91C_NVIC_USAGEFAULT (0xFF << 16) // (NVIC) +// -------- NVIC_BFAR : (NVIC Offset: 0xd38) Bus Fault Address Register -------- +#define AT91C_NVIC_IBUSERR (0x1 << 0) // (NVIC) This bit indicates a bus fault on an instruction prefetch +#define AT91C_NVIC_PRECISERR (0x1 << 1) // (NVIC) Precise data access error. The BFAR is written with the faulting address +#define AT91C_NVIC_IMPRECISERR (0x1 << 2) // (NVIC) Imprecise data access error +#define AT91C_NVIC_UNSTKERR (0x1 << 3) // (NVIC) This bit indicates a derived bus fault has occurred on exception return +#define AT91C_NVIC_STKERR (0x1 << 4) // (NVIC) This bit indicates a derived bus fault has occurred on exception entry +#define AT91C_NVIC_BFARVALID (0x1 << 7) // (NVIC) This bit is set if the BFAR register has valid contents +// -------- NVIC_PFR0 : (NVIC Offset: 0xd40) Processor Feature register0 (ID_PFR0) -------- +#define AT91C_NVIC_ID_PFR0_0 (0xF << 0) // (NVIC) State0 (T-bit == 0) +#define AT91C_NVIC_ID_PRF0_1 (0xF << 4) // (NVIC) State1 (T-bit == 1) +// -------- NVIC_PFR1 : (NVIC Offset: 0xd44) Processor Feature register1 (ID_PFR1) -------- +#define AT91C_NVIC_ID_PRF1_MODEL (0xF << 8) // (NVIC) Microcontroller programmer’s model +// -------- NVIC_DFR0 : (NVIC Offset: 0xd48) Debug Feature register0 (ID_DFR0) -------- +#define AT91C_NVIC_ID_DFR0_MODEL (0xF << 20) // (NVIC) Microcontroller Debug Model – memory mapped +// -------- NVIC_MMFR0 : (NVIC Offset: 0xd50) Memory Model Feature register0 (ID_MMFR0) -------- +#define AT91C_NVIC_ID_MMFR0_PMSA (0xF << 4) // (NVIC) Microcontroller Debug Model – memory mapped +#define AT91C_NVIC_ID_MMFR0_CACHE (0xF << 8) // (NVIC) Microcontroller Debug Model – memory mapped + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR NESTED vector Interrupt Controller +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_MPU { + AT91_REG MPU_TYPE; // MPU Type Register + AT91_REG MPU_CTRL; // MPU Control Register + AT91_REG MPU_REG_NB; // MPU Region Number Register + AT91_REG MPU_REG_BASE_ADDR; // MPU Region Base Address Register + AT91_REG MPU_ATTR_SIZE; // MPU Attribute and Size Register + AT91_REG MPU_REG_BASE_ADDR1; // MPU Region Base Address Register alias 1 + AT91_REG MPU_ATTR_SIZE1; // MPU Attribute and Size Register alias 1 + AT91_REG MPU_REG_BASE_ADDR2; // MPU Region Base Address Register alias 2 + AT91_REG MPU_ATTR_SIZE2; // MPU Attribute and Size Register alias 2 + AT91_REG MPU_REG_BASE_ADDR3; // MPU Region Base Address Register alias 3 + AT91_REG MPU_ATTR_SIZE3; // MPU Attribute and Size Register alias 3 +} AT91S_MPU, *AT91PS_MPU; +#else +#define MPU_TYPE (AT91_CAST(AT91_REG *) 0x00000000) // (MPU_TYPE) MPU Type Register +#define MPU_CTRL (AT91_CAST(AT91_REG *) 0x00000004) // (MPU_CTRL) MPU Control Register +#define MPU_REG_NB (AT91_CAST(AT91_REG *) 0x00000008) // (MPU_REG_NB) MPU Region Number Register +#define MPU_REG_BASE_ADDR (AT91_CAST(AT91_REG *) 0x0000000C) // (MPU_REG_BASE_ADDR) MPU Region Base Address Register +#define MPU_ATTR_SIZE (AT91_CAST(AT91_REG *) 0x00000010) // (MPU_ATTR_SIZE) MPU Attribute and Size Register +#define MPU_REG_BASE_ADDR1 (AT91_CAST(AT91_REG *) 0x00000014) // (MPU_REG_BASE_ADDR1) MPU Region Base Address Register alias 1 +#define MPU_ATTR_SIZE1 (AT91_CAST(AT91_REG *) 0x00000018) // (MPU_ATTR_SIZE1) MPU Attribute and Size Register alias 1 +#define MPU_REG_BASE_ADDR2 (AT91_CAST(AT91_REG *) 0x0000001C) // (MPU_REG_BASE_ADDR2) MPU Region Base Address Register alias 2 +#define MPU_ATTR_SIZE2 (AT91_CAST(AT91_REG *) 0x00000020) // (MPU_ATTR_SIZE2) MPU Attribute and Size Register alias 2 +#define MPU_REG_BASE_ADDR3 (AT91_CAST(AT91_REG *) 0x00000024) // (MPU_REG_BASE_ADDR3) MPU Region Base Address Register alias 3 +#define MPU_ATTR_SIZE3 (AT91_CAST(AT91_REG *) 0x00000028) // (MPU_ATTR_SIZE3) MPU Attribute and Size Register alias 3 + +#endif +// -------- MPU_TYPE : (MPU Offset: 0x0) -------- +#define AT91C_MPU_SEPARATE (0x1 << 0) // (MPU) +#define AT91C_MPU_DREGION (0xFF << 8) // (MPU) +#define AT91C_MPU_IREGION (0xFF << 16) // (MPU) +// -------- MPU_CTRL : (MPU Offset: 0x4) -------- +#define AT91C_MPU_ENABLE (0x1 << 0) // (MPU) +#define AT91C_MPU_HFNMIENA (0x1 << 1) // (MPU) +#define AT91C_MPU_PRIVDEFENA (0x1 << 2) // (MPU) +// -------- MPU_REG_NB : (MPU Offset: 0x8) -------- +#define AT91C_MPU_REGION (0xFF << 0) // (MPU) +// -------- MPU_REG_BASE_ADDR : (MPU Offset: 0xc) -------- +#define AT91C_MPU_REG (0xF << 0) // (MPU) +#define AT91C_MPU_VALID (0x1 << 4) // (MPU) +#define AT91C_MPU_ADDR (0x3FFFFFF << 5) // (MPU) +// -------- MPU_ATTR_SIZE : (MPU Offset: 0x10) -------- +#define AT91C_MPU_ENA (0x1 << 0) // (MPU) +#define AT91C_MPU_SIZE (0xF << 1) // (MPU) +#define AT91C_MPU_SRD (0xFF << 8) // (MPU) +#define AT91C_MPU_B (0x1 << 16) // (MPU) +#define AT91C_MPU_C (0x1 << 17) // (MPU) +#define AT91C_MPU_S (0x1 << 18) // (MPU) +#define AT91C_MPU_TEX (0x7 << 19) // (MPU) +#define AT91C_MPU_AP (0x7 << 24) // (MPU) +#define AT91C_MPU_XN (0x7 << 28) // (MPU) + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR CORTEX_M3 Registers +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_CM3 { + AT91_REG CM3_CPUID; // CPU ID Base Register + AT91_REG CM3_ICSR; // Interrupt Control State Register + AT91_REG CM3_VTOR; // Vector Table Offset Register + AT91_REG CM3_AIRCR; // Application Interrupt and Reset Control Register + AT91_REG CM3_SCR; // System Controller Register + AT91_REG CM3_CCR; // Configuration Control Register + AT91_REG CM3_SHPR[3]; // System Handler Priority Register + AT91_REG CM3_SHCSR; // System Handler Control and State Register +} AT91S_CM3, *AT91PS_CM3; +#else +#define CM3_CPUID (AT91_CAST(AT91_REG *) 0x00000000) // (CM3_CPUID) CPU ID Base Register +#define CM3_ICSR (AT91_CAST(AT91_REG *) 0x00000004) // (CM3_ICSR) Interrupt Control State Register +#define CM3_VTOR (AT91_CAST(AT91_REG *) 0x00000008) // (CM3_VTOR) Vector Table Offset Register +#define CM3_AIRCR (AT91_CAST(AT91_REG *) 0x0000000C) // (CM3_AIRCR) Application Interrupt and Reset Control Register +#define CM3_SCR (AT91_CAST(AT91_REG *) 0x00000010) // (CM3_SCR) System Controller Register +#define CM3_CCR (AT91_CAST(AT91_REG *) 0x00000014) // (CM3_CCR) Configuration Control Register +#define CM3_SHPR (AT91_CAST(AT91_REG *) 0x00000018) // (CM3_SHPR) System Handler Priority Register +#define CM3_SHCSR (AT91_CAST(AT91_REG *) 0x00000024) // (CM3_SHCSR) System Handler Control and State Register + +#endif +// -------- CM3_CPUID : (CM3 Offset: 0x0) -------- +// -------- CM3_AIRCR : (CM3 Offset: 0xc) -------- +#define AT91C_CM3_SYSRESETREQ (0x1 << 2) // (CM3) A reset is requested by the processor. +// -------- CM3_SCR : (CM3 Offset: 0x10) -------- +#define AT91C_CM3_SLEEPONEXIT (0x1 << 1) // (CM3) Sleep on exit when returning from Handler mode to Thread mode. Enables interrupt driven applications to avoid returning to empty main application. +#define AT91C_CM3_SLEEPDEEP (0x1 << 2) // (CM3) Sleep deep bit. +#define AT91C_CM3_SEVONPEND (0x1 << 4) // (CM3) When enabled, this causes WFE to wake up when an interrupt moves from inactive to pended. +// -------- CM3_SHCSR : (CM3 Offset: 0x24) -------- +#define AT91C_CM3_SYSTICKACT (0x1 << 11) // (CM3) Reads as 1 if SysTick is active. + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Peripheral DMA Controller +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_PDC { + AT91_REG PDC_RPR; // Receive Pointer Register + AT91_REG PDC_RCR; // Receive Counter Register + AT91_REG PDC_TPR; // Transmit Pointer Register + AT91_REG PDC_TCR; // Transmit Counter Register + AT91_REG PDC_RNPR; // Receive Next Pointer Register + AT91_REG PDC_RNCR; // Receive Next Counter Register + AT91_REG PDC_TNPR; // Transmit Next Pointer Register + AT91_REG PDC_TNCR; // Transmit Next Counter Register + AT91_REG PDC_PTCR; // PDC Transfer Control Register + AT91_REG PDC_PTSR; // PDC Transfer Status Register +} AT91S_PDC, *AT91PS_PDC; +#else +#define PDC_RPR (AT91_CAST(AT91_REG *) 0x00000000) // (PDC_RPR) Receive Pointer Register +#define PDC_RCR (AT91_CAST(AT91_REG *) 0x00000004) // (PDC_RCR) Receive Counter Register +#define PDC_TPR (AT91_CAST(AT91_REG *) 0x00000008) // (PDC_TPR) Transmit Pointer Register +#define PDC_TCR (AT91_CAST(AT91_REG *) 0x0000000C) // (PDC_TCR) Transmit Counter Register +#define PDC_RNPR (AT91_CAST(AT91_REG *) 0x00000010) // (PDC_RNPR) Receive Next Pointer Register +#define PDC_RNCR (AT91_CAST(AT91_REG *) 0x00000014) // (PDC_RNCR) Receive Next Counter Register +#define PDC_TNPR (AT91_CAST(AT91_REG *) 0x00000018) // (PDC_TNPR) Transmit Next Pointer Register +#define PDC_TNCR (AT91_CAST(AT91_REG *) 0x0000001C) // (PDC_TNCR) Transmit Next Counter Register +#define PDC_PTCR (AT91_CAST(AT91_REG *) 0x00000020) // (PDC_PTCR) PDC Transfer Control Register +#define PDC_PTSR (AT91_CAST(AT91_REG *) 0x00000024) // (PDC_PTSR) PDC Transfer Status Register + +#endif +// -------- PDC_PTCR : (PDC Offset: 0x20) PDC Transfer Control Register -------- +#define AT91C_PDC_RXTEN (0x1 << 0) // (PDC) Receiver Transfer Enable +#define AT91C_PDC_RXTDIS (0x1 << 1) // (PDC) Receiver Transfer Disable +#define AT91C_PDC_TXTEN (0x1 << 8) // (PDC) Transmitter Transfer Enable +#define AT91C_PDC_TXTDIS (0x1 << 9) // (PDC) Transmitter Transfer Disable +// -------- PDC_PTSR : (PDC Offset: 0x24) PDC Transfer Status Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Debug Unit +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_DBGU { + AT91_REG DBGU_CR; // Control Register + AT91_REG DBGU_MR; // Mode Register + AT91_REG DBGU_IER; // Interrupt Enable Register + AT91_REG DBGU_IDR; // Interrupt Disable Register + AT91_REG DBGU_IMR; // Interrupt Mask Register + AT91_REG DBGU_CSR; // Channel Status Register + AT91_REG DBGU_RHR; // Receiver Holding Register + AT91_REG DBGU_THR; // Transmitter Holding Register + AT91_REG DBGU_BRGR; // Baud Rate Generator Register + AT91_REG Reserved0[9]; // + AT91_REG DBGU_FNTR; // Force NTRST Register + AT91_REG Reserved1[40]; // + AT91_REG DBGU_ADDRSIZE; // DBGU ADDRSIZE REGISTER + AT91_REG DBGU_IPNAME1; // DBGU IPNAME1 REGISTER + AT91_REG DBGU_IPNAME2; // DBGU IPNAME2 REGISTER + AT91_REG DBGU_FEATURES; // DBGU FEATURES REGISTER + AT91_REG DBGU_VER; // DBGU VERSION REGISTER + AT91_REG DBGU_RPR; // Receive Pointer Register + AT91_REG DBGU_RCR; // Receive Counter Register + AT91_REG DBGU_TPR; // Transmit Pointer Register + AT91_REG DBGU_TCR; // Transmit Counter Register + AT91_REG DBGU_RNPR; // Receive Next Pointer Register + AT91_REG DBGU_RNCR; // Receive Next Counter Register + AT91_REG DBGU_TNPR; // Transmit Next Pointer Register + AT91_REG DBGU_TNCR; // Transmit Next Counter Register + AT91_REG DBGU_PTCR; // PDC Transfer Control Register + AT91_REG DBGU_PTSR; // PDC Transfer Status Register + AT91_REG Reserved2[6]; // + AT91_REG DBGU_CIDR; // Chip ID Register + AT91_REG DBGU_EXID; // Chip ID Extension Register +} AT91S_DBGU, *AT91PS_DBGU; +#else +#define DBGU_CR (AT91_CAST(AT91_REG *) 0x00000000) // (DBGU_CR) Control Register +#define DBGU_MR (AT91_CAST(AT91_REG *) 0x00000004) // (DBGU_MR) Mode Register +#define DBGU_IER (AT91_CAST(AT91_REG *) 0x00000008) // (DBGU_IER) Interrupt Enable Register +#define DBGU_IDR (AT91_CAST(AT91_REG *) 0x0000000C) // (DBGU_IDR) Interrupt Disable Register +#define DBGU_IMR (AT91_CAST(AT91_REG *) 0x00000010) // (DBGU_IMR) Interrupt Mask Register +#define DBGU_CSR (AT91_CAST(AT91_REG *) 0x00000014) // (DBGU_CSR) Channel Status Register +#define DBGU_RHR (AT91_CAST(AT91_REG *) 0x00000018) // (DBGU_RHR) Receiver Holding Register +#define DBGU_THR (AT91_CAST(AT91_REG *) 0x0000001C) // (DBGU_THR) Transmitter Holding Register +#define DBGU_BRGR (AT91_CAST(AT91_REG *) 0x00000020) // (DBGU_BRGR) Baud Rate Generator Register +#define DBGU_FNTR (AT91_CAST(AT91_REG *) 0x00000048) // (DBGU_FNTR) Force NTRST Register +#define DBGU_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (DBGU_ADDRSIZE) DBGU ADDRSIZE REGISTER +#define DBGU_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (DBGU_IPNAME1) DBGU IPNAME1 REGISTER +#define DBGU_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (DBGU_IPNAME2) DBGU IPNAME2 REGISTER +#define DBGU_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (DBGU_FEATURES) DBGU FEATURES REGISTER +#define DBGU_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (DBGU_VER) DBGU VERSION REGISTER +#define DBGU_CIDR (AT91_CAST(AT91_REG *) 0x00000140) // (DBGU_CIDR) Chip ID Register +#define DBGU_EXID (AT91_CAST(AT91_REG *) 0x00000144) // (DBGU_EXID) Chip ID Extension Register + +#endif +// -------- DBGU_CR : (DBGU Offset: 0x0) Debug Unit Control Register -------- +#define AT91C_US_RSTRX (0x1 << 2) // (DBGU) Reset Receiver +#define AT91C_US_RSTTX (0x1 << 3) // (DBGU) Reset Transmitter +#define AT91C_US_RXEN (0x1 << 4) // (DBGU) Receiver Enable +#define AT91C_US_RXDIS (0x1 << 5) // (DBGU) Receiver Disable +#define AT91C_US_TXEN (0x1 << 6) // (DBGU) Transmitter Enable +#define AT91C_US_TXDIS (0x1 << 7) // (DBGU) Transmitter Disable +#define AT91C_US_RSTSTA (0x1 << 8) // (DBGU) Reset Status Bits +// -------- DBGU_MR : (DBGU Offset: 0x4) Debug Unit Mode Register -------- +#define AT91C_US_PAR (0x7 << 9) // (DBGU) Parity type +#define AT91C_US_PAR_EVEN (0x0 << 9) // (DBGU) Even Parity +#define AT91C_US_PAR_ODD (0x1 << 9) // (DBGU) Odd Parity +#define AT91C_US_PAR_SPACE (0x2 << 9) // (DBGU) Parity forced to 0 (Space) +#define AT91C_US_PAR_MARK (0x3 << 9) // (DBGU) Parity forced to 1 (Mark) +#define AT91C_US_PAR_NONE (0x4 << 9) // (DBGU) No Parity +#define AT91C_US_PAR_MULTI_DROP (0x6 << 9) // (DBGU) Multi-drop mode +#define AT91C_US_CHMODE (0x3 << 14) // (DBGU) Channel Mode +#define AT91C_US_CHMODE_NORMAL (0x0 << 14) // (DBGU) Normal Mode: The USART channel operates as an RX/TX USART. +#define AT91C_US_CHMODE_AUTO (0x1 << 14) // (DBGU) Automatic Echo: Receiver Data Input is connected to the TXD pin. +#define AT91C_US_CHMODE_LOCAL (0x2 << 14) // (DBGU) Local Loopback: Transmitter Output Signal is connected to Receiver Input Signal. +#define AT91C_US_CHMODE_REMOTE (0x3 << 14) // (DBGU) Remote Loopback: RXD pin is internally connected to TXD pin. +// -------- DBGU_IER : (DBGU Offset: 0x8) Debug Unit Interrupt Enable Register -------- +#define AT91C_US_RXRDY (0x1 << 0) // (DBGU) RXRDY Interrupt +#define AT91C_US_TXRDY (0x1 << 1) // (DBGU) TXRDY Interrupt +#define AT91C_US_ENDRX (0x1 << 3) // (DBGU) End of Receive Transfer Interrupt +#define AT91C_US_ENDTX (0x1 << 4) // (DBGU) End of Transmit Interrupt +#define AT91C_US_OVRE (0x1 << 5) // (DBGU) Overrun Interrupt +#define AT91C_US_FRAME (0x1 << 6) // (DBGU) Framing Error Interrupt +#define AT91C_US_PARE (0x1 << 7) // (DBGU) Parity Error Interrupt +#define AT91C_US_TXEMPTY (0x1 << 9) // (DBGU) TXEMPTY Interrupt +#define AT91C_US_TXBUFE (0x1 << 11) // (DBGU) TXBUFE Interrupt +#define AT91C_US_RXBUFF (0x1 << 12) // (DBGU) RXBUFF Interrupt +#define AT91C_US_COMM_TX (0x1 << 30) // (DBGU) COMM_TX Interrupt +#define AT91C_US_COMM_RX (0x1 << 31) // (DBGU) COMM_RX Interrupt +// -------- DBGU_IDR : (DBGU Offset: 0xc) Debug Unit Interrupt Disable Register -------- +// -------- DBGU_IMR : (DBGU Offset: 0x10) Debug Unit Interrupt Mask Register -------- +// -------- DBGU_CSR : (DBGU Offset: 0x14) Debug Unit Channel Status Register -------- +// -------- DBGU_FNTR : (DBGU Offset: 0x48) Debug Unit FORCE_NTRST Register -------- +#define AT91C_US_FORCE_NTRST (0x1 << 0) // (DBGU) Force NTRST in JTAG + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Parallel Input Output Controler +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_PIO { + AT91_REG PIO_PER; // PIO Enable Register + AT91_REG PIO_PDR; // PIO Disable Register + AT91_REG PIO_PSR; // PIO Status Register + AT91_REG Reserved0[1]; // + AT91_REG PIO_OER; // Output Enable Register + AT91_REG PIO_ODR; // Output Disable Registerr + AT91_REG PIO_OSR; // Output Status Register + AT91_REG Reserved1[1]; // + AT91_REG PIO_IFER; // Input Filter Enable Register + AT91_REG PIO_IFDR; // Input Filter Disable Register + AT91_REG PIO_IFSR; // Input Filter Status Register + AT91_REG Reserved2[1]; // + AT91_REG PIO_SODR; // Set Output Data Register + AT91_REG PIO_CODR; // Clear Output Data Register + AT91_REG PIO_ODSR; // Output Data Status Register + AT91_REG PIO_PDSR; // Pin Data Status Register + AT91_REG PIO_IER; // Interrupt Enable Register + AT91_REG PIO_IDR; // Interrupt Disable Register + AT91_REG PIO_IMR; // Interrupt Mask Register + AT91_REG PIO_ISR; // Interrupt Status Register + AT91_REG PIO_MDER; // Multi-driver Enable Register + AT91_REG PIO_MDDR; // Multi-driver Disable Register + AT91_REG PIO_MDSR; // Multi-driver Status Register + AT91_REG Reserved3[1]; // + AT91_REG PIO_PPUDR; // Pull-up Disable Register + AT91_REG PIO_PPUER; // Pull-up Enable Register + AT91_REG PIO_PPUSR; // Pull-up Status Register + AT91_REG Reserved4[1]; // + AT91_REG PIO_ABSR; // Peripheral AB Select Register + AT91_REG Reserved5[3]; // + AT91_REG PIO_SCIFSR; // System Clock Glitch Input Filter Select Register + AT91_REG PIO_DIFSR; // Debouncing Input Filter Select Register + AT91_REG PIO_IFDGSR; // Glitch or Debouncing Input Filter Clock Selection Status Register + AT91_REG PIO_SCDR; // Slow Clock Divider Debouncing Register + AT91_REG Reserved6[4]; // + AT91_REG PIO_OWER; // Output Write Enable Register + AT91_REG PIO_OWDR; // Output Write Disable Register + AT91_REG PIO_OWSR; // Output Write Status Register + AT91_REG Reserved7[1]; // + AT91_REG PIO_AIMER; // Additional Interrupt Modes Enable Register + AT91_REG PIO_AIMDR; // Additional Interrupt Modes Disables Register + AT91_REG PIO_AIMMR; // Additional Interrupt Modes Mask Register + AT91_REG Reserved8[1]; // + AT91_REG PIO_ESR; // Edge Select Register + AT91_REG PIO_LSR; // Level Select Register + AT91_REG PIO_ELSR; // Edge/Level Status Register + AT91_REG Reserved9[1]; // + AT91_REG PIO_FELLSR; // Falling Edge/Low Level Select Register + AT91_REG PIO_REHLSR; // Rising Edge/ High Level Select Register + AT91_REG PIO_FRLHSR; // Fall/Rise - Low/High Status Register + AT91_REG Reserved10[1]; // + AT91_REG PIO_LOCKSR; // Lock Status Register + AT91_REG Reserved11[6]; // + AT91_REG PIO_VER; // PIO VERSION REGISTER + AT91_REG Reserved12[8]; // + AT91_REG PIO_KER; // Keypad Controller Enable Register + AT91_REG PIO_KRCR; // Keypad Controller Row Column Register + AT91_REG PIO_KDR; // Keypad Controller Debouncing Register + AT91_REG Reserved13[1]; // + AT91_REG PIO_KIER; // Keypad Controller Interrupt Enable Register + AT91_REG PIO_KIDR; // Keypad Controller Interrupt Disable Register + AT91_REG PIO_KIMR; // Keypad Controller Interrupt Mask Register + AT91_REG PIO_KSR; // Keypad Controller Status Register + AT91_REG PIO_KKPR; // Keypad Controller Key Press Register + AT91_REG PIO_KKRR; // Keypad Controller Key Release Register +} AT91S_PIO, *AT91PS_PIO; +#else +#define PIO_PER (AT91_CAST(AT91_REG *) 0x00000000) // (PIO_PER) PIO Enable Register +#define PIO_PDR (AT91_CAST(AT91_REG *) 0x00000004) // (PIO_PDR) PIO Disable Register +#define PIO_PSR (AT91_CAST(AT91_REG *) 0x00000008) // (PIO_PSR) PIO Status Register +#define PIO_OER (AT91_CAST(AT91_REG *) 0x00000010) // (PIO_OER) Output Enable Register +#define PIO_ODR (AT91_CAST(AT91_REG *) 0x00000014) // (PIO_ODR) Output Disable Registerr +#define PIO_OSR (AT91_CAST(AT91_REG *) 0x00000018) // (PIO_OSR) Output Status Register +#define PIO_IFER (AT91_CAST(AT91_REG *) 0x00000020) // (PIO_IFER) Input Filter Enable Register +#define PIO_IFDR (AT91_CAST(AT91_REG *) 0x00000024) // (PIO_IFDR) Input Filter Disable Register +#define PIO_IFSR (AT91_CAST(AT91_REG *) 0x00000028) // (PIO_IFSR) Input Filter Status Register +#define PIO_SODR (AT91_CAST(AT91_REG *) 0x00000030) // (PIO_SODR) Set Output Data Register +#define PIO_CODR (AT91_CAST(AT91_REG *) 0x00000034) // (PIO_CODR) Clear Output Data Register +#define PIO_ODSR (AT91_CAST(AT91_REG *) 0x00000038) // (PIO_ODSR) Output Data Status Register +#define PIO_PDSR (AT91_CAST(AT91_REG *) 0x0000003C) // (PIO_PDSR) Pin Data Status Register +#define PIO_IER (AT91_CAST(AT91_REG *) 0x00000040) // (PIO_IER) Interrupt Enable Register +#define PIO_IDR (AT91_CAST(AT91_REG *) 0x00000044) // (PIO_IDR) Interrupt Disable Register +#define PIO_IMR (AT91_CAST(AT91_REG *) 0x00000048) // (PIO_IMR) Interrupt Mask Register +#define PIO_ISR (AT91_CAST(AT91_REG *) 0x0000004C) // (PIO_ISR) Interrupt Status Register +#define PIO_MDER (AT91_CAST(AT91_REG *) 0x00000050) // (PIO_MDER) Multi-driver Enable Register +#define PIO_MDDR (AT91_CAST(AT91_REG *) 0x00000054) // (PIO_MDDR) Multi-driver Disable Register +#define PIO_MDSR (AT91_CAST(AT91_REG *) 0x00000058) // (PIO_MDSR) Multi-driver Status Register +#define PIO_PPUDR (AT91_CAST(AT91_REG *) 0x00000060) // (PIO_PPUDR) Pull-up Disable Register +#define PIO_PPUER (AT91_CAST(AT91_REG *) 0x00000064) // (PIO_PPUER) Pull-up Enable Register +#define PIO_PPUSR (AT91_CAST(AT91_REG *) 0x00000068) // (PIO_PPUSR) Pull-up Status Register +#define PIO_ABSR (AT91_CAST(AT91_REG *) 0x00000070) // (PIO_ABSR) Peripheral AB Select Register +#define PIO_SCIFSR (AT91_CAST(AT91_REG *) 0x00000080) // (PIO_SCIFSR) System Clock Glitch Input Filter Select Register +#define PIO_DIFSR (AT91_CAST(AT91_REG *) 0x00000084) // (PIO_DIFSR) Debouncing Input Filter Select Register +#define PIO_IFDGSR (AT91_CAST(AT91_REG *) 0x00000088) // (PIO_IFDGSR) Glitch or Debouncing Input Filter Clock Selection Status Register +#define PIO_SCDR (AT91_CAST(AT91_REG *) 0x0000008C) // (PIO_SCDR) Slow Clock Divider Debouncing Register +#define PIO_OWER (AT91_CAST(AT91_REG *) 0x000000A0) // (PIO_OWER) Output Write Enable Register +#define PIO_OWDR (AT91_CAST(AT91_REG *) 0x000000A4) // (PIO_OWDR) Output Write Disable Register +#define PIO_OWSR (AT91_CAST(AT91_REG *) 0x000000A8) // (PIO_OWSR) Output Write Status Register +#define PIO_AIMER (AT91_CAST(AT91_REG *) 0x000000B0) // (PIO_AIMER) Additional Interrupt Modes Enable Register +#define PIO_AIMDR (AT91_CAST(AT91_REG *) 0x000000B4) // (PIO_AIMDR) Additional Interrupt Modes Disables Register +#define PIO_AIMMR (AT91_CAST(AT91_REG *) 0x000000B8) // (PIO_AIMMR) Additional Interrupt Modes Mask Register +#define PIO_ESR (AT91_CAST(AT91_REG *) 0x000000C0) // (PIO_ESR) Edge Select Register +#define PIO_LSR (AT91_CAST(AT91_REG *) 0x000000C4) // (PIO_LSR) Level Select Register +#define PIO_ELSR (AT91_CAST(AT91_REG *) 0x000000C8) // (PIO_ELSR) Edge/Level Status Register +#define PIO_FELLSR (AT91_CAST(AT91_REG *) 0x000000D0) // (PIO_FELLSR) Falling Edge/Low Level Select Register +#define PIO_REHLSR (AT91_CAST(AT91_REG *) 0x000000D4) // (PIO_REHLSR) Rising Edge/ High Level Select Register +#define PIO_FRLHSR (AT91_CAST(AT91_REG *) 0x000000D8) // (PIO_FRLHSR) Fall/Rise - Low/High Status Register +#define PIO_LOCKSR (AT91_CAST(AT91_REG *) 0x000000E0) // (PIO_LOCKSR) Lock Status Register +#define PIO_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (PIO_VER) PIO VERSION REGISTER +#define PIO_KER (AT91_CAST(AT91_REG *) 0x00000120) // (PIO_KER) Keypad Controller Enable Register +#define PIO_KRCR (AT91_CAST(AT91_REG *) 0x00000124) // (PIO_KRCR) Keypad Controller Row Column Register +#define PIO_KDR (AT91_CAST(AT91_REG *) 0x00000128) // (PIO_KDR) Keypad Controller Debouncing Register +#define PIO_KIER (AT91_CAST(AT91_REG *) 0x00000130) // (PIO_KIER) Keypad Controller Interrupt Enable Register +#define PIO_KIDR (AT91_CAST(AT91_REG *) 0x00000134) // (PIO_KIDR) Keypad Controller Interrupt Disable Register +#define PIO_KIMR (AT91_CAST(AT91_REG *) 0x00000138) // (PIO_KIMR) Keypad Controller Interrupt Mask Register +#define PIO_KSR (AT91_CAST(AT91_REG *) 0x0000013C) // (PIO_KSR) Keypad Controller Status Register +#define PIO_KKPR (AT91_CAST(AT91_REG *) 0x00000140) // (PIO_KKPR) Keypad Controller Key Press Register +#define PIO_KKRR (AT91_CAST(AT91_REG *) 0x00000144) // (PIO_KKRR) Keypad Controller Key Release Register + +#endif +// -------- PIO_KER : (PIO Offset: 0x120) Keypad Controller Enable Register -------- +#define AT91C_PIO_KCE (0x1 << 0) // (PIO) Keypad Controller Enable +// -------- PIO_KRCR : (PIO Offset: 0x124) Keypad Controller Row Column Register -------- +#define AT91C_PIO_NBR (0x7 << 0) // (PIO) Number of Columns of the Keypad Matrix +#define AT91C_PIO_NBC (0x7 << 8) // (PIO) Number of Rows of the Keypad Matrix +// -------- PIO_KDR : (PIO Offset: 0x128) Keypad Controller Debouncing Register -------- +#define AT91C_PIO_DBC (0x3FF << 0) // (PIO) Debouncing Value +// -------- PIO_KIER : (PIO Offset: 0x130) Keypad Controller Interrupt Enable Register -------- +#define AT91C_PIO_KPR (0x1 << 0) // (PIO) Key Press Interrupt Enable +#define AT91C_PIO_KRL (0x1 << 1) // (PIO) Key Release Interrupt Enable +// -------- PIO_KIDR : (PIO Offset: 0x134) Keypad Controller Interrupt Disable Register -------- +// -------- PIO_KIMR : (PIO Offset: 0x138) Keypad Controller Interrupt Mask Register -------- +// -------- PIO_KSR : (PIO Offset: 0x13c) Keypad Controller Status Register -------- +#define AT91C_PIO_NBKPR (0x3 << 8) // (PIO) Number of Simultaneous Key Presses +#define AT91C_PIO_NBKRL (0x3 << 16) // (PIO) Number of Simultaneous Key Releases +// -------- PIO_KKPR : (PIO Offset: 0x140) Keypad Controller Key Press Register -------- +#define AT91C_KEY0ROW (0x7 << 0) // (PIO) Row index of the first detected Key Press +#define AT91C_KEY0COL (0x7 << 4) // (PIO) Column index of the first detected Key Press +#define AT91C_KEY1ROW (0x7 << 8) // (PIO) Row index of the second detected Key Press +#define AT91C_KEY1COL (0x7 << 12) // (PIO) Column index of the second detected Key Press +#define AT91C_KEY2ROW (0x7 << 16) // (PIO) Row index of the third detected Key Press +#define AT91C_KEY2COL (0x7 << 20) // (PIO) Column index of the third detected Key Press +#define AT91C_KEY3ROW (0x7 << 24) // (PIO) Row index of the fourth detected Key Press +#define AT91C_KEY3COL (0x7 << 28) // (PIO) Column index of the fourth detected Key Press +// -------- PIO_KKRR : (PIO Offset: 0x144) Keypad Controller Key Release Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Power Management Controler +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_PMC { + AT91_REG PMC_SCER; // System Clock Enable Register + AT91_REG PMC_SCDR; // System Clock Disable Register + AT91_REG PMC_SCSR; // System Clock Status Register + AT91_REG Reserved0[1]; // + AT91_REG PMC_PCER; // Peripheral Clock Enable Register + AT91_REG PMC_PCDR; // Peripheral Clock Disable Register + AT91_REG PMC_PCSR; // Peripheral Clock Status Register + AT91_REG PMC_UCKR; // UTMI Clock Configuration Register + AT91_REG PMC_MOR; // Main Oscillator Register + AT91_REG PMC_MCFR; // Main Clock Frequency Register + AT91_REG PMC_PLLAR; // PLL Register + AT91_REG Reserved1[1]; // + AT91_REG PMC_MCKR; // Master Clock Register + AT91_REG Reserved2[3]; // + AT91_REG PMC_PCKR[8]; // Programmable Clock Register + AT91_REG PMC_IER; // Interrupt Enable Register + AT91_REG PMC_IDR; // Interrupt Disable Register + AT91_REG PMC_SR; // Status Register + AT91_REG PMC_IMR; // Interrupt Mask Register + AT91_REG PMC_FSMR; // Fast Startup Mode Register + AT91_REG PMC_FSPR; // Fast Startup Polarity Register + AT91_REG PMC_FOCR; // Fault Output Clear Register + AT91_REG Reserved3[28]; // + AT91_REG PMC_ADDRSIZE; // PMC ADDRSIZE REGISTER + AT91_REG PMC_IPNAME1; // PMC IPNAME1 REGISTER + AT91_REG PMC_IPNAME2; // PMC IPNAME2 REGISTER + AT91_REG PMC_FEATURES; // PMC FEATURES REGISTER + AT91_REG PMC_VER; // APMC VERSION REGISTER +} AT91S_PMC, *AT91PS_PMC; +#else +#define PMC_SCER (AT91_CAST(AT91_REG *) 0x00000000) // (PMC_SCER) System Clock Enable Register +#define PMC_SCDR (AT91_CAST(AT91_REG *) 0x00000004) // (PMC_SCDR) System Clock Disable Register +#define PMC_SCSR (AT91_CAST(AT91_REG *) 0x00000008) // (PMC_SCSR) System Clock Status Register +#define PMC_PCER (AT91_CAST(AT91_REG *) 0x00000010) // (PMC_PCER) Peripheral Clock Enable Register +#define PMC_PCDR (AT91_CAST(AT91_REG *) 0x00000014) // (PMC_PCDR) Peripheral Clock Disable Register +#define PMC_PCSR (AT91_CAST(AT91_REG *) 0x00000018) // (PMC_PCSR) Peripheral Clock Status Register +#define CKGR_UCKR (AT91_CAST(AT91_REG *) 0x0000001C) // (CKGR_UCKR) UTMI Clock Configuration Register +#define CKGR_MOR (AT91_CAST(AT91_REG *) 0x00000020) // (CKGR_MOR) Main Oscillator Register +#define CKGR_MCFR (AT91_CAST(AT91_REG *) 0x00000024) // (CKGR_MCFR) Main Clock Frequency Register +#define CKGR_PLLAR (AT91_CAST(AT91_REG *) 0x00000028) // (CKGR_PLLAR) PLL Register +#define PMC_MCKR (AT91_CAST(AT91_REG *) 0x00000030) // (PMC_MCKR) Master Clock Register +#define PMC_PCKR (AT91_CAST(AT91_REG *) 0x00000040) // (PMC_PCKR) Programmable Clock Register +#define PMC_IER (AT91_CAST(AT91_REG *) 0x00000060) // (PMC_IER) Interrupt Enable Register +#define PMC_IDR (AT91_CAST(AT91_REG *) 0x00000064) // (PMC_IDR) Interrupt Disable Register +#define PMC_SR (AT91_CAST(AT91_REG *) 0x00000068) // (PMC_SR) Status Register +#define PMC_IMR (AT91_CAST(AT91_REG *) 0x0000006C) // (PMC_IMR) Interrupt Mask Register +#define PMC_FSMR (AT91_CAST(AT91_REG *) 0x00000070) // (PMC_FSMR) Fast Startup Mode Register +#define PMC_FSPR (AT91_CAST(AT91_REG *) 0x00000074) // (PMC_FSPR) Fast Startup Polarity Register +#define PMC_FOCR (AT91_CAST(AT91_REG *) 0x00000078) // (PMC_FOCR) Fault Output Clear Register +#define PMC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (PMC_ADDRSIZE) PMC ADDRSIZE REGISTER +#define PMC_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (PMC_IPNAME1) PMC IPNAME1 REGISTER +#define PMC_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (PMC_IPNAME2) PMC IPNAME2 REGISTER +#define PMC_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (PMC_FEATURES) PMC FEATURES REGISTER +#define PMC_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (PMC_VER) APMC VERSION REGISTER + +#endif +// -------- PMC_SCER : (PMC Offset: 0x0) System Clock Enable Register -------- +#define AT91C_PMC_PCK (0x1 << 0) // (PMC) Processor Clock +#define AT91C_PMC_PCK0 (0x1 << 8) // (PMC) Programmable Clock Output +#define AT91C_PMC_PCK1 (0x1 << 9) // (PMC) Programmable Clock Output +#define AT91C_PMC_PCK2 (0x1 << 10) // (PMC) Programmable Clock Output +// -------- PMC_SCDR : (PMC Offset: 0x4) System Clock Disable Register -------- +// -------- PMC_SCSR : (PMC Offset: 0x8) System Clock Status Register -------- +// -------- CKGR_UCKR : (PMC Offset: 0x1c) UTMI Clock Configuration Register -------- +#define AT91C_CKGR_UPLLEN (0x1 << 16) // (PMC) UTMI PLL Enable +#define AT91C_CKGR_UPLLEN_DISABLED (0x0 << 16) // (PMC) The UTMI PLL is disabled +#define AT91C_CKGR_UPLLEN_ENABLED (0x1 << 16) // (PMC) The UTMI PLL is enabled +#define AT91C_CKGR_UPLLCOUNT (0xF << 20) // (PMC) UTMI Oscillator Start-up Time +#define AT91C_CKGR_BIASEN (0x1 << 24) // (PMC) UTMI BIAS Enable +#define AT91C_CKGR_BIASEN_DISABLED (0x0 << 24) // (PMC) The UTMI BIAS is disabled +#define AT91C_CKGR_BIASEN_ENABLED (0x1 << 24) // (PMC) The UTMI BIAS is enabled +#define AT91C_CKGR_BIASCOUNT (0xF << 28) // (PMC) UTMI BIAS Start-up Time +// -------- CKGR_MOR : (PMC Offset: 0x20) Main Oscillator Register -------- +#define AT91C_CKGR_MOSCXTEN (0x1 << 0) // (PMC) Main Crystal Oscillator Enable +#define AT91C_CKGR_MOSCXTBY (0x1 << 1) // (PMC) Main Crystal Oscillator Bypass +#define AT91C_CKGR_WAITMODE (0x1 << 2) // (PMC) Main Crystal Oscillator Bypass +#define AT91C_CKGR_MOSCRCEN (0x1 << 3) // (PMC) Main On-Chip RC Oscillator Enable +#define AT91C_CKGR_MOSCRCF (0x7 << 4) // (PMC) Main On-Chip RC Oscillator Frequency Selection +#define AT91C_CKGR_MOSCXTST (0xFF << 8) // (PMC) Main Crystal Oscillator Start-up Time +#define AT91C_CKGR_KEY (0xFF << 16) // (PMC) Clock Generator Controller Writing Protection Key +#define AT91C_CKGR_MOSCSEL (0x1 << 24) // (PMC) Main Oscillator Selection +#define AT91C_CKGR_CFDEN (0x1 << 25) // (PMC) Clock Failure Detector Enable +// -------- CKGR_MCFR : (PMC Offset: 0x24) Main Clock Frequency Register -------- +#define AT91C_CKGR_MAINF (0xFFFF << 0) // (PMC) Main Clock Frequency +#define AT91C_CKGR_MAINRDY (0x1 << 16) // (PMC) Main Clock Ready +// -------- CKGR_PLLAR : (PMC Offset: 0x28) PLL A Register -------- +#define AT91C_CKGR_DIVA (0xFF << 0) // (PMC) Divider Selected +#define AT91C_CKGR_DIVA_0 (0x0) // (PMC) Divider output is 0 +#define AT91C_CKGR_DIVA_BYPASS (0x1) // (PMC) Divider is bypassed +#define AT91C_CKGR_PLLACOUNT (0x3F << 8) // (PMC) PLLA Counter +#define AT91C_CKGR_STMODE (0x3 << 14) // (PMC) Start Mode +#define AT91C_CKGR_STMODE_0 (0x0 << 14) // (PMC) Fast startup +#define AT91C_CKGR_STMODE_1 (0x1 << 14) // (PMC) Reserved +#define AT91C_CKGR_STMODE_2 (0x2 << 14) // (PMC) Normal startup +#define AT91C_CKGR_STMODE_3 (0x3 << 14) // (PMC) Reserved +#define AT91C_CKGR_MULA (0x7FF << 16) // (PMC) PLL Multiplier +#define AT91C_CKGR_SRC (0x1 << 29) // (PMC) +// -------- PMC_MCKR : (PMC Offset: 0x30) Master Clock Register -------- +#define AT91C_PMC_CSS (0x7 << 0) // (PMC) Programmable Clock Selection +#define AT91C_PMC_CSS_SLOW_CLK (0x0) // (PMC) Slow Clock is selected +#define AT91C_PMC_CSS_MAIN_CLK (0x1) // (PMC) Main Clock is selected +#define AT91C_PMC_CSS_PLLA_CLK (0x2) // (PMC) Clock from PLL A is selected +#define AT91C_PMC_CSS_UPLL_CLK (0x3) // (PMC) Clock from UPLL is selected +#define AT91C_PMC_CSS_SYS_CLK (0x4) // (PMC) System clock is selected +#define AT91C_PMC_PRES (0x7 << 4) // (PMC) Programmable Clock Prescaler +#define AT91C_PMC_PRES_CLK (0x0 << 4) // (PMC) Selected clock +#define AT91C_PMC_PRES_CLK_2 (0x1 << 4) // (PMC) Selected clock divided by 2 +#define AT91C_PMC_PRES_CLK_4 (0x2 << 4) // (PMC) Selected clock divided by 4 +#define AT91C_PMC_PRES_CLK_8 (0x3 << 4) // (PMC) Selected clock divided by 8 +#define AT91C_PMC_PRES_CLK_16 (0x4 << 4) // (PMC) Selected clock divided by 16 +#define AT91C_PMC_PRES_CLK_32 (0x5 << 4) // (PMC) Selected clock divided by 32 +#define AT91C_PMC_PRES_CLK_64 (0x6 << 4) // (PMC) Selected clock divided by 64 +#define AT91C_PMC_PRES_CLK_6 (0x7 << 4) // (PMC) Selected clock divided by 6 +// -------- PMC_PCKR : (PMC Offset: 0x40) Programmable Clock Register -------- +// -------- PMC_IER : (PMC Offset: 0x60) PMC Interrupt Enable Register -------- +#define AT91C_PMC_MOSCXTS (0x1 << 0) // (PMC) Main Crystal Oscillator Status/Enable/Disable/Mask +#define AT91C_PMC_LOCKA (0x1 << 1) // (PMC) PLL A Status/Enable/Disable/Mask +#define AT91C_PMC_MCKRDY (0x1 << 3) // (PMC) Master Clock Status/Enable/Disable/Mask +#define AT91C_PMC_LOCKU (0x1 << 6) // (PMC) PLL UTMI Status/Enable/Disable/Mask +#define AT91C_PMC_PCKRDY0 (0x1 << 8) // (PMC) PCK0_RDY Status/Enable/Disable/Mask +#define AT91C_PMC_PCKRDY1 (0x1 << 9) // (PMC) PCK1_RDY Status/Enable/Disable/Mask +#define AT91C_PMC_PCKRDY2 (0x1 << 10) // (PMC) PCK2_RDY Status/Enable/Disable/Mask +#define AT91C_PMC_MOSCSELS (0x1 << 16) // (PMC) Main Oscillator Selection Status +#define AT91C_PMC_MOSCRCS (0x1 << 17) // (PMC) Main On-Chip RC Oscillator Status +#define AT91C_PMC_CFDEV (0x1 << 18) // (PMC) Clock Failure Detector Event +// -------- PMC_IDR : (PMC Offset: 0x64) PMC Interrupt Disable Register -------- +// -------- PMC_SR : (PMC Offset: 0x68) PMC Status Register -------- +#define AT91C_PMC_OSCSELS (0x1 << 7) // (PMC) Slow Clock Oscillator Selection +#define AT91C_PMC_CFDS (0x1 << 19) // (PMC) Clock Failure Detector Status +#define AT91C_PMC_FOS (0x1 << 20) // (PMC) Clock Failure Detector Fault Output Status +// -------- PMC_IMR : (PMC Offset: 0x6c) PMC Interrupt Mask Register -------- +// -------- PMC_FSMR : (PMC Offset: 0x70) Fast Startup Mode Register -------- +#define AT91C_PMC_FSTT (0xFFFF << 0) // (PMC) Fast Start-up Input Enable 0 to 15 +#define AT91C_PMC_RTTAL (0x1 << 16) // (PMC) RTT Alarm Enable +#define AT91C_PMC_RTCAL (0x1 << 17) // (PMC) RTC Alarm Enable +#define AT91C_PMC_USBAL (0x1 << 18) // (PMC) USB Alarm Enable +#define AT91C_PMC_LPM (0x1 << 20) // (PMC) Low Power Mode +// -------- PMC_FSPR : (PMC Offset: 0x74) Fast Startup Polarity Register -------- +#define AT91C_PMC_FSTP (0xFFFF << 0) // (PMC) Fast Start-up Input Polarity 0 to 15 +// -------- PMC_FOCR : (PMC Offset: 0x78) Fault Output Clear Register -------- +#define AT91C_PMC_FOCLR (0x1 << 0) // (PMC) Fault Output Clear + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Clock Generator Controler +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_CKGR { + AT91_REG CKGR_UCKR; // UTMI Clock Configuration Register + AT91_REG CKGR_MOR; // Main Oscillator Register + AT91_REG CKGR_MCFR; // Main Clock Frequency Register + AT91_REG CKGR_PLLAR; // PLL Register +} AT91S_CKGR, *AT91PS_CKGR; +#else + +#endif +// -------- CKGR_UCKR : (CKGR Offset: 0x0) UTMI Clock Configuration Register -------- +// -------- CKGR_MOR : (CKGR Offset: 0x4) Main Oscillator Register -------- +// -------- CKGR_MCFR : (CKGR Offset: 0x8) Main Clock Frequency Register -------- +// -------- CKGR_PLLAR : (CKGR Offset: 0xc) PLL A Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Reset Controller Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_RSTC { + AT91_REG RSTC_RCR; // Reset Control Register + AT91_REG RSTC_RSR; // Reset Status Register + AT91_REG RSTC_RMR; // Reset Mode Register + AT91_REG Reserved0[60]; // + AT91_REG RSTC_VER; // Version Register +} AT91S_RSTC, *AT91PS_RSTC; +#else +#define RSTC_RCR (AT91_CAST(AT91_REG *) 0x00000000) // (RSTC_RCR) Reset Control Register +#define RSTC_RSR (AT91_CAST(AT91_REG *) 0x00000004) // (RSTC_RSR) Reset Status Register +#define RSTC_RMR (AT91_CAST(AT91_REG *) 0x00000008) // (RSTC_RMR) Reset Mode Register +#define RSTC_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (RSTC_VER) Version Register + +#endif +// -------- RSTC_RCR : (RSTC Offset: 0x0) Reset Control Register -------- +#define AT91C_RSTC_PROCRST (0x1 << 0) // (RSTC) Processor Reset +#define AT91C_RSTC_ICERST (0x1 << 1) // (RSTC) ICE Interface Reset +#define AT91C_RSTC_PERRST (0x1 << 2) // (RSTC) Peripheral Reset +#define AT91C_RSTC_EXTRST (0x1 << 3) // (RSTC) External Reset +#define AT91C_RSTC_KEY (0xFF << 24) // (RSTC) Password +// -------- RSTC_RSR : (RSTC Offset: 0x4) Reset Status Register -------- +#define AT91C_RSTC_URSTS (0x1 << 0) // (RSTC) User Reset Status +#define AT91C_RSTC_RSTTYP (0x7 << 8) // (RSTC) Reset Type +#define AT91C_RSTC_RSTTYP_GENERAL (0x0 << 8) // (RSTC) General reset. Both VDDCORE and VDDBU rising. +#define AT91C_RSTC_RSTTYP_WAKEUP (0x1 << 8) // (RSTC) WakeUp Reset. VDDCORE rising. +#define AT91C_RSTC_RSTTYP_WATCHDOG (0x2 << 8) // (RSTC) Watchdog Reset. Watchdog overflow occured. +#define AT91C_RSTC_RSTTYP_SOFTWARE (0x3 << 8) // (RSTC) Software Reset. Processor reset required by the software. +#define AT91C_RSTC_RSTTYP_USER (0x4 << 8) // (RSTC) User Reset. NRST pin detected low. +#define AT91C_RSTC_NRSTL (0x1 << 16) // (RSTC) NRST pin level +#define AT91C_RSTC_SRCMP (0x1 << 17) // (RSTC) Software Reset Command in Progress. +// -------- RSTC_RMR : (RSTC Offset: 0x8) Reset Mode Register -------- +#define AT91C_RSTC_URSTEN (0x1 << 0) // (RSTC) User Reset Enable +#define AT91C_RSTC_URSTIEN (0x1 << 4) // (RSTC) User Reset Interrupt Enable +#define AT91C_RSTC_ERSTL (0xF << 8) // (RSTC) User Reset Enable + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Supply Controller Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_SUPC { + AT91_REG SUPC_CR; // Control Register + AT91_REG SUPC_BOMR; // Brown Out Mode Register + AT91_REG SUPC_MR; // Mode Register + AT91_REG SUPC_WUMR; // Wake Up Mode Register + AT91_REG SUPC_WUIR; // Wake Up Inputs Register + AT91_REG SUPC_SR; // Status Register + AT91_REG SUPC_FWUTR; // Flash Wake-up Timer Register +} AT91S_SUPC, *AT91PS_SUPC; +#else +#define SUPC_CR (AT91_CAST(AT91_REG *) 0x00000000) // (SUPC_CR) Control Register +#define SUPC_BOMR (AT91_CAST(AT91_REG *) 0x00000004) // (SUPC_BOMR) Brown Out Mode Register +#define SUPC_MR (AT91_CAST(AT91_REG *) 0x00000008) // (SUPC_MR) Mode Register +#define SUPC_WUMR (AT91_CAST(AT91_REG *) 0x0000000C) // (SUPC_WUMR) Wake Up Mode Register +#define SUPC_WUIR (AT91_CAST(AT91_REG *) 0x00000010) // (SUPC_WUIR) Wake Up Inputs Register +#define SUPC_SR (AT91_CAST(AT91_REG *) 0x00000014) // (SUPC_SR) Status Register +#define SUPC_FWUTR (AT91_CAST(AT91_REG *) 0x00000018) // (SUPC_FWUTR) Flash Wake-up Timer Register + +#endif +// -------- SUPC_CR : (SUPC Offset: 0x0) Control Register -------- +#define AT91C_SUPC_SHDW (0x1 << 0) // (SUPC) Shut Down Command +#define AT91C_SUPC_SHDWEOF (0x1 << 1) // (SUPC) Shut Down after End Of Frame +#define AT91C_SUPC_VROFF (0x1 << 2) // (SUPC) Voltage Regulator Off +#define AT91C_SUPC_XTALSEL (0x1 << 3) // (SUPC) Crystal Oscillator Select +#define AT91C_SUPC_KEY (0xFF << 24) // (SUPC) Supply Controller Writing Protection Key +// -------- SUPC_BOMR : (SUPC Offset: 0x4) Brown Out Mode Register -------- +#define AT91C_SUPC_BODTH (0xF << 0) // (SUPC) Brown Out Threshold +#define AT91C_SUPC_BODSMPL (0x7 << 8) // (SUPC) Brown Out Sampling Period +#define AT91C_SUPC_BODSMPL_DISABLED (0x0 << 8) // (SUPC) Brown Out Detector disabled +#define AT91C_SUPC_BODSMPL_CONTINUOUS (0x1 << 8) // (SUPC) Continuous Brown Out Detector +#define AT91C_SUPC_BODSMPL_32_SLCK (0x2 << 8) // (SUPC) Brown Out Detector enabled one SLCK period every 32 SLCK periods +#define AT91C_SUPC_BODSMPL_256_SLCK (0x3 << 8) // (SUPC) Brown Out Detector enabled one SLCK period every 256 SLCK periods +#define AT91C_SUPC_BODSMPL_2048_SLCK (0x4 << 8) // (SUPC) Brown Out Detector enabled one SLCK period every 2048 SLCK periods +#define AT91C_SUPC_BODRSTEN (0x1 << 12) // (SUPC) Brownout Reset Enable +// -------- SUPC_MR : (SUPC Offset: 0x8) Supply Controller Mode Register -------- +#define AT91C_SUPC_LCDOUT (0xF << 0) // (SUPC) LCD Charge Pump Output Voltage Selection +#define AT91C_SUPC_LCDMODE (0x3 << 4) // (SUPC) Segment LCD Supply Mode +#define AT91C_SUPC_LCDMODE_OFF (0x0 << 4) // (SUPC) The internal and external supply sources are both deselected and the on-chip charge pump is turned off +#define AT91C_SUPC_LCDMODE_OFF_AFTER_EOF (0x1 << 4) // (SUPC) At the End Of Frame from LCD controller, the internal and external supply sources are both deselected and the on-chip charge pump is turned off +#define AT91C_SUPC_LCDMODE_EXTERNAL (0x2 << 4) // (SUPC) The external supply source is selected +#define AT91C_SUPC_LCDMODE_INTERNAL (0x3 << 4) // (SUPC) The internal supply source is selected and the on-chip charge pump is turned on +#define AT91C_SUPC_VRDEEP (0x1 << 8) // (SUPC) Voltage Regulator Deep Mode +#define AT91C_SUPC_VRVDD (0x7 << 9) // (SUPC) Voltage Regulator Output Voltage Selection +#define AT91C_SUPC_VRRSTEN (0x1 << 12) // (SUPC) Voltage Regulation Loss Reset Enable +#define AT91C_SUPC_GPBRON (0x1 << 16) // (SUPC) GPBR ON +#define AT91C_SUPC_SRAMON (0x1 << 17) // (SUPC) SRAM ON +#define AT91C_SUPC_RTCON (0x1 << 18) // (SUPC) Real Time Clock Power switch ON +#define AT91C_SUPC_FLASHON (0x1 << 19) // (SUPC) Flash Power switch On +#define AT91C_SUPC_BYPASS (0x1 << 20) // (SUPC) 32kHz oscillator bypass +#define AT91C_SUPC_MKEY (0xFF << 24) // (SUPC) Supply Controller Writing Protection Key +// -------- SUPC_WUMR : (SUPC Offset: 0xc) Wake Up Mode Register -------- +#define AT91C_SUPC_FWUPEN (0x1 << 0) // (SUPC) Force Wake Up Enable +#define AT91C_SUPC_BODEN (0x1 << 1) // (SUPC) Brown Out Wake Up Enable +#define AT91C_SUPC_RTTEN (0x1 << 2) // (SUPC) Real Time Timer Wake Up Enable +#define AT91C_SUPC_RTCEN (0x1 << 3) // (SUPC) Real Time Clock Wake Up Enable +#define AT91C_SUPC_FWUPDBC (0x7 << 8) // (SUPC) Force Wake Up debouncer +#define AT91C_SUPC_FWUPDBC_IMMEDIATE (0x0 << 8) // (SUPC) Immediate, No debouncing, detected active at least one Slow clock edge +#define AT91C_SUPC_FWUPDBC_3_SLCK (0x1 << 8) // (SUPC) An enabled Wake Up input shall be low for at least 3 SLCK periods +#define AT91C_SUPC_FWUPDBC_32_SLCK (0x2 << 8) // (SUPC) An enabled Wake Up input shall be low for at least 32 SLCK periods +#define AT91C_SUPC_FWUPDBC_512_SLCK (0x3 << 8) // (SUPC) An enabled Wake Up input shall be low for at least 512 SLCK periods +#define AT91C_SUPC_FWUPDBC_4096_SLCK (0x4 << 8) // (SUPC) An enabled Wake Up input shall be low for at least 4096 SLCK periods +#define AT91C_SUPC_FWUPDBC_32768_SLCK (0x5 << 8) // (SUPC) An enabled Wake Up input shall be low for at least 32768 SLCK periods +#define AT91C_SUPC_WKUPDBC (0x7 << 12) // (SUPC) Force Wake Up debouncer +#define AT91C_SUPC_WKUPDBC_IMMEDIATE (0x0 << 12) // (SUPC) Immediate, No debouncing, detected active at least one Slow clock edge +#define AT91C_SUPC_WKUPDBC_3_SLCK (0x1 << 12) // (SUPC) FWUP shall be low for at least 3 SLCK periods +#define AT91C_SUPC_WKUPDBC_32_SLCK (0x2 << 12) // (SUPC) FWUP shall be low for at least 32 SLCK periods +#define AT91C_SUPC_WKUPDBC_512_SLCK (0x3 << 12) // (SUPC) FWUP shall be low for at least 512 SLCK periods +#define AT91C_SUPC_WKUPDBC_4096_SLCK (0x4 << 12) // (SUPC) FWUP shall be low for at least 4096 SLCK periods +#define AT91C_SUPC_WKUPDBC_32768_SLCK (0x5 << 12) // (SUPC) FWUP shall be low for at least 32768 SLCK periods +// -------- SUPC_WUIR : (SUPC Offset: 0x10) Wake Up Inputs Register -------- +#define AT91C_SUPC_WKUPEN0 (0x1 << 0) // (SUPC) Wake Up Input Enable 0 +#define AT91C_SUPC_WKUPEN1 (0x1 << 1) // (SUPC) Wake Up Input Enable 1 +#define AT91C_SUPC_WKUPEN2 (0x1 << 2) // (SUPC) Wake Up Input Enable 2 +#define AT91C_SUPC_WKUPEN3 (0x1 << 3) // (SUPC) Wake Up Input Enable 3 +#define AT91C_SUPC_WKUPEN4 (0x1 << 4) // (SUPC) Wake Up Input Enable 4 +#define AT91C_SUPC_WKUPEN5 (0x1 << 5) // (SUPC) Wake Up Input Enable 5 +#define AT91C_SUPC_WKUPEN6 (0x1 << 6) // (SUPC) Wake Up Input Enable 6 +#define AT91C_SUPC_WKUPEN7 (0x1 << 7) // (SUPC) Wake Up Input Enable 7 +#define AT91C_SUPC_WKUPEN8 (0x1 << 8) // (SUPC) Wake Up Input Enable 8 +#define AT91C_SUPC_WKUPEN9 (0x1 << 9) // (SUPC) Wake Up Input Enable 9 +#define AT91C_SUPC_WKUPEN10 (0x1 << 10) // (SUPC) Wake Up Input Enable 10 +#define AT91C_SUPC_WKUPEN11 (0x1 << 11) // (SUPC) Wake Up Input Enable 11 +#define AT91C_SUPC_WKUPEN12 (0x1 << 12) // (SUPC) Wake Up Input Enable 12 +#define AT91C_SUPC_WKUPEN13 (0x1 << 13) // (SUPC) Wake Up Input Enable 13 +#define AT91C_SUPC_WKUPEN14 (0x1 << 14) // (SUPC) Wake Up Input Enable 14 +#define AT91C_SUPC_WKUPEN15 (0x1 << 15) // (SUPC) Wake Up Input Enable 15 +#define AT91C_SUPC_WKUPT0 (0x1 << 16) // (SUPC) Wake Up Input Transition 0 +#define AT91C_SUPC_WKUPT1 (0x1 << 17) // (SUPC) Wake Up Input Transition 1 +#define AT91C_SUPC_WKUPT2 (0x1 << 18) // (SUPC) Wake Up Input Transition 2 +#define AT91C_SUPC_WKUPT3 (0x1 << 19) // (SUPC) Wake Up Input Transition 3 +#define AT91C_SUPC_WKUPT4 (0x1 << 20) // (SUPC) Wake Up Input Transition 4 +#define AT91C_SUPC_WKUPT5 (0x1 << 21) // (SUPC) Wake Up Input Transition 5 +#define AT91C_SUPC_WKUPT6 (0x1 << 22) // (SUPC) Wake Up Input Transition 6 +#define AT91C_SUPC_WKUPT7 (0x1 << 23) // (SUPC) Wake Up Input Transition 7 +#define AT91C_SUPC_WKUPT8 (0x1 << 24) // (SUPC) Wake Up Input Transition 8 +#define AT91C_SUPC_WKUPT9 (0x1 << 25) // (SUPC) Wake Up Input Transition 9 +#define AT91C_SUPC_WKUPT10 (0x1 << 26) // (SUPC) Wake Up Input Transition 10 +#define AT91C_SUPC_WKUPT11 (0x1 << 27) // (SUPC) Wake Up Input Transition 11 +#define AT91C_SUPC_WKUPT12 (0x1 << 28) // (SUPC) Wake Up Input Transition 12 +#define AT91C_SUPC_WKUPT13 (0x1 << 29) // (SUPC) Wake Up Input Transition 13 +#define AT91C_SUPC_WKUPT14 (0x1 << 30) // (SUPC) Wake Up Input Transition 14 +#define AT91C_SUPC_WKUPT15 (0x1 << 31) // (SUPC) Wake Up Input Transition 15 +// -------- SUPC_SR : (SUPC Offset: 0x14) Status Register -------- +#define AT91C_SUPC_FWUPS (0x1 << 0) // (SUPC) Force Wake Up Status +#define AT91C_SUPC_WKUPS (0x1 << 1) // (SUPC) Wake Up Status +#define AT91C_SUPC_BODWS (0x1 << 2) // (SUPC) BOD Detection Wake Up Status +#define AT91C_SUPC_VRRSTS (0x1 << 3) // (SUPC) Voltage regulation Loss Reset Status +#define AT91C_SUPC_BODRSTS (0x1 << 4) // (SUPC) BOD detection Reset Status +#define AT91C_SUPC_BODS (0x1 << 5) // (SUPC) BOD Status +#define AT91C_SUPC_BROWNOUT (0x1 << 6) // (SUPC) BOD Output Status +#define AT91C_SUPC_OSCSEL (0x1 << 7) // (SUPC) 32kHz Oscillator Selection Status +#define AT91C_SUPC_LCDS (0x1 << 8) // (SUPC) LCD Status +#define AT91C_SUPC_GPBRS (0x1 << 9) // (SUPC) General Purpose Back-up registers Status +#define AT91C_SUPC_RTS (0x1 << 10) // (SUPC) Clock Status +#define AT91C_SUPC_FLASHS (0x1 << 11) // (SUPC) FLASH Memory Status +#define AT91C_SUPC_FWUPIS (0x1 << 12) // (SUPC) WKUP Input Status +#define AT91C_SUPC_WKUPIS0 (0x1 << 16) // (SUPC) WKUP Input 0 Status +#define AT91C_SUPC_WKUPIS1 (0x1 << 17) // (SUPC) WKUP Input 1 Status +#define AT91C_SUPC_WKUPIS2 (0x1 << 18) // (SUPC) WKUP Input 2 Status +#define AT91C_SUPC_WKUPIS3 (0x1 << 19) // (SUPC) WKUP Input 3 Status +#define AT91C_SUPC_WKUPIS4 (0x1 << 20) // (SUPC) WKUP Input 4 Status +#define AT91C_SUPC_WKUPIS5 (0x1 << 21) // (SUPC) WKUP Input 5 Status +#define AT91C_SUPC_WKUPIS6 (0x1 << 22) // (SUPC) WKUP Input 6 Status +#define AT91C_SUPC_WKUPIS7 (0x1 << 23) // (SUPC) WKUP Input 7 Status +#define AT91C_SUPC_WKUPIS8 (0x1 << 24) // (SUPC) WKUP Input 8 Status +#define AT91C_SUPC_WKUPIS9 (0x1 << 25) // (SUPC) WKUP Input 9 Status +#define AT91C_SUPC_WKUPIS10 (0x1 << 26) // (SUPC) WKUP Input 10 Status +#define AT91C_SUPC_WKUPIS11 (0x1 << 27) // (SUPC) WKUP Input 11 Status +#define AT91C_SUPC_WKUPIS12 (0x1 << 28) // (SUPC) WKUP Input 12 Status +#define AT91C_SUPC_WKUPIS13 (0x1 << 29) // (SUPC) WKUP Input 13 Status +#define AT91C_SUPC_WKUPIS14 (0x1 << 30) // (SUPC) WKUP Input 14 Status +#define AT91C_SUPC_WKUPIS15 (0x1 << 31) // (SUPC) WKUP Input 15 Status +// -------- SUPC_FWUTR : (SUPC Offset: 0x18) Flash Wake Up Timer Register -------- +#define AT91C_SUPC_FWUT (0x3FF << 0) // (SUPC) Flash Wake Up Timer + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Real Time Timer Controller Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_RTTC { + AT91_REG RTTC_RTMR; // Real-time Mode Register + AT91_REG RTTC_RTAR; // Real-time Alarm Register + AT91_REG RTTC_RTVR; // Real-time Value Register + AT91_REG RTTC_RTSR; // Real-time Status Register +} AT91S_RTTC, *AT91PS_RTTC; +#else +#define RTTC_RTMR (AT91_CAST(AT91_REG *) 0x00000000) // (RTTC_RTMR) Real-time Mode Register +#define RTTC_RTAR (AT91_CAST(AT91_REG *) 0x00000004) // (RTTC_RTAR) Real-time Alarm Register +#define RTTC_RTVR (AT91_CAST(AT91_REG *) 0x00000008) // (RTTC_RTVR) Real-time Value Register +#define RTTC_RTSR (AT91_CAST(AT91_REG *) 0x0000000C) // (RTTC_RTSR) Real-time Status Register + +#endif +// -------- RTTC_RTMR : (RTTC Offset: 0x0) Real-time Mode Register -------- +#define AT91C_RTTC_RTPRES (0xFFFF << 0) // (RTTC) Real-time Timer Prescaler Value +#define AT91C_RTTC_ALMIEN (0x1 << 16) // (RTTC) Alarm Interrupt Enable +#define AT91C_RTTC_RTTINCIEN (0x1 << 17) // (RTTC) Real Time Timer Increment Interrupt Enable +#define AT91C_RTTC_RTTRST (0x1 << 18) // (RTTC) Real Time Timer Restart +// -------- RTTC_RTAR : (RTTC Offset: 0x4) Real-time Alarm Register -------- +#define AT91C_RTTC_ALMV (0x0 << 0) // (RTTC) Alarm Value +// -------- RTTC_RTVR : (RTTC Offset: 0x8) Current Real-time Value Register -------- +#define AT91C_RTTC_CRTV (0x0 << 0) // (RTTC) Current Real-time Value +// -------- RTTC_RTSR : (RTTC Offset: 0xc) Real-time Status Register -------- +#define AT91C_RTTC_ALMS (0x1 << 0) // (RTTC) Real-time Alarm Status +#define AT91C_RTTC_RTTINC (0x1 << 1) // (RTTC) Real-time Timer Increment + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Watchdog Timer Controller Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_WDTC { + AT91_REG WDTC_WDCR; // Watchdog Control Register + AT91_REG WDTC_WDMR; // Watchdog Mode Register + AT91_REG WDTC_WDSR; // Watchdog Status Register +} AT91S_WDTC, *AT91PS_WDTC; +#else +#define WDTC_WDCR (AT91_CAST(AT91_REG *) 0x00000000) // (WDTC_WDCR) Watchdog Control Register +#define WDTC_WDMR (AT91_CAST(AT91_REG *) 0x00000004) // (WDTC_WDMR) Watchdog Mode Register +#define WDTC_WDSR (AT91_CAST(AT91_REG *) 0x00000008) // (WDTC_WDSR) Watchdog Status Register + +#endif +// -------- WDTC_WDCR : (WDTC Offset: 0x0) Periodic Interval Image Register -------- +#define AT91C_WDTC_WDRSTT (0x1 << 0) // (WDTC) Watchdog Restart +#define AT91C_WDTC_KEY (0xFF << 24) // (WDTC) Watchdog KEY Password +// -------- WDTC_WDMR : (WDTC Offset: 0x4) Watchdog Mode Register -------- +#define AT91C_WDTC_WDV (0xFFF << 0) // (WDTC) Watchdog Timer Restart +#define AT91C_WDTC_WDFIEN (0x1 << 12) // (WDTC) Watchdog Fault Interrupt Enable +#define AT91C_WDTC_WDRSTEN (0x1 << 13) // (WDTC) Watchdog Reset Enable +#define AT91C_WDTC_WDRPROC (0x1 << 14) // (WDTC) Watchdog Timer Restart +#define AT91C_WDTC_WDDIS (0x1 << 15) // (WDTC) Watchdog Disable +#define AT91C_WDTC_WDD (0xFFF << 16) // (WDTC) Watchdog Delta Value +#define AT91C_WDTC_WDDBGHLT (0x1 << 28) // (WDTC) Watchdog Debug Halt +#define AT91C_WDTC_WDIDLEHLT (0x1 << 29) // (WDTC) Watchdog Idle Halt +// -------- WDTC_WDSR : (WDTC Offset: 0x8) Watchdog Status Register -------- +#define AT91C_WDTC_WDUNF (0x1 << 0) // (WDTC) Watchdog Underflow +#define AT91C_WDTC_WDERR (0x1 << 1) // (WDTC) Watchdog Error + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Real-time Clock Alarm and Parallel Load Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_RTC { + AT91_REG RTC_CR; // Control Register + AT91_REG RTC_MR; // Mode Register + AT91_REG RTC_TIMR; // Time Register + AT91_REG RTC_CALR; // Calendar Register + AT91_REG RTC_TIMALR; // Time Alarm Register + AT91_REG RTC_CALALR; // Calendar Alarm Register + AT91_REG RTC_SR; // Status Register + AT91_REG RTC_SCCR; // Status Clear Command Register + AT91_REG RTC_IER; // Interrupt Enable Register + AT91_REG RTC_IDR; // Interrupt Disable Register + AT91_REG RTC_IMR; // Interrupt Mask Register + AT91_REG RTC_VER; // Valid Entry Register +} AT91S_RTC, *AT91PS_RTC; +#else +#define RTC_CR (AT91_CAST(AT91_REG *) 0x00000000) // (RTC_CR) Control Register +#define RTC_MR (AT91_CAST(AT91_REG *) 0x00000004) // (RTC_MR) Mode Register +#define RTC_TIMR (AT91_CAST(AT91_REG *) 0x00000008) // (RTC_TIMR) Time Register +#define RTC_CALR (AT91_CAST(AT91_REG *) 0x0000000C) // (RTC_CALR) Calendar Register +#define RTC_TIMALR (AT91_CAST(AT91_REG *) 0x00000010) // (RTC_TIMALR) Time Alarm Register +#define RTC_CALALR (AT91_CAST(AT91_REG *) 0x00000014) // (RTC_CALALR) Calendar Alarm Register +#define RTC_SR (AT91_CAST(AT91_REG *) 0x00000018) // (RTC_SR) Status Register +#define RTC_SCCR (AT91_CAST(AT91_REG *) 0x0000001C) // (RTC_SCCR) Status Clear Command Register +#define RTC_IER (AT91_CAST(AT91_REG *) 0x00000020) // (RTC_IER) Interrupt Enable Register +#define RTC_IDR (AT91_CAST(AT91_REG *) 0x00000024) // (RTC_IDR) Interrupt Disable Register +#define RTC_IMR (AT91_CAST(AT91_REG *) 0x00000028) // (RTC_IMR) Interrupt Mask Register +#define RTC_VER (AT91_CAST(AT91_REG *) 0x0000002C) // (RTC_VER) Valid Entry Register + +#endif +// -------- RTC_CR : (RTC Offset: 0x0) RTC Control Register -------- +#define AT91C_RTC_UPDTIM (0x1 << 0) // (RTC) Update Request Time Register +#define AT91C_RTC_UPDCAL (0x1 << 1) // (RTC) Update Request Calendar Register +#define AT91C_RTC_TIMEVSEL (0x3 << 8) // (RTC) Time Event Selection +#define AT91C_RTC_TIMEVSEL_MINUTE (0x0 << 8) // (RTC) Minute change. +#define AT91C_RTC_TIMEVSEL_HOUR (0x1 << 8) // (RTC) Hour change. +#define AT91C_RTC_TIMEVSEL_DAY24 (0x2 << 8) // (RTC) Every day at midnight. +#define AT91C_RTC_TIMEVSEL_DAY12 (0x3 << 8) // (RTC) Every day at noon. +#define AT91C_RTC_CALEVSEL (0x3 << 16) // (RTC) Calendar Event Selection +#define AT91C_RTC_CALEVSEL_WEEK (0x0 << 16) // (RTC) Week change (every Monday at time 00:00:00). +#define AT91C_RTC_CALEVSEL_MONTH (0x1 << 16) // (RTC) Month change (every 01 of each month at time 00:00:00). +#define AT91C_RTC_CALEVSEL_YEAR (0x2 << 16) // (RTC) Year change (every January 1 at time 00:00:00). +// -------- RTC_MR : (RTC Offset: 0x4) RTC Mode Register -------- +#define AT91C_RTC_HRMOD (0x1 << 0) // (RTC) 12-24 hour Mode +// -------- RTC_TIMR : (RTC Offset: 0x8) RTC Time Register -------- +#define AT91C_RTC_SEC (0x7F << 0) // (RTC) Current Second +#define AT91C_RTC_MIN (0x7F << 8) // (RTC) Current Minute +#define AT91C_RTC_HOUR (0x3F << 16) // (RTC) Current Hour +#define AT91C_RTC_AMPM (0x1 << 22) // (RTC) Ante Meridiem, Post Meridiem Indicator +// -------- RTC_CALR : (RTC Offset: 0xc) RTC Calendar Register -------- +#define AT91C_RTC_CENT (0x3F << 0) // (RTC) Current Century +#define AT91C_RTC_YEAR (0xFF << 8) // (RTC) Current Year +#define AT91C_RTC_MONTH (0x1F << 16) // (RTC) Current Month +#define AT91C_RTC_DAY (0x7 << 21) // (RTC) Current Day +#define AT91C_RTC_DATE (0x3F << 24) // (RTC) Current Date +// -------- RTC_TIMALR : (RTC Offset: 0x10) RTC Time Alarm Register -------- +#define AT91C_RTC_SECEN (0x1 << 7) // (RTC) Second Alarm Enable +#define AT91C_RTC_MINEN (0x1 << 15) // (RTC) Minute Alarm +#define AT91C_RTC_HOUREN (0x1 << 23) // (RTC) Current Hour +// -------- RTC_CALALR : (RTC Offset: 0x14) RTC Calendar Alarm Register -------- +#define AT91C_RTC_MONTHEN (0x1 << 23) // (RTC) Month Alarm Enable +#define AT91C_RTC_DATEEN (0x1 << 31) // (RTC) Date Alarm Enable +// -------- RTC_SR : (RTC Offset: 0x18) RTC Status Register -------- +#define AT91C_RTC_ACKUPD (0x1 << 0) // (RTC) Acknowledge for Update +#define AT91C_RTC_ALARM (0x1 << 1) // (RTC) Alarm Flag +#define AT91C_RTC_SECEV (0x1 << 2) // (RTC) Second Event +#define AT91C_RTC_TIMEV (0x1 << 3) // (RTC) Time Event +#define AT91C_RTC_CALEV (0x1 << 4) // (RTC) Calendar event +// -------- RTC_SCCR : (RTC Offset: 0x1c) RTC Status Clear Command Register -------- +// -------- RTC_IER : (RTC Offset: 0x20) RTC Interrupt Enable Register -------- +// -------- RTC_IDR : (RTC Offset: 0x24) RTC Interrupt Disable Register -------- +// -------- RTC_IMR : (RTC Offset: 0x28) RTC Interrupt Mask Register -------- +// -------- RTC_VER : (RTC Offset: 0x2c) RTC Valid Entry Register -------- +#define AT91C_RTC_NVTIM (0x1 << 0) // (RTC) Non valid Time +#define AT91C_RTC_NVCAL (0x1 << 1) // (RTC) Non valid Calendar +#define AT91C_RTC_NVTIMALR (0x1 << 2) // (RTC) Non valid time Alarm +#define AT91C_RTC_NVCALALR (0x1 << 3) // (RTC) Nonvalid Calendar Alarm + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Analog to Digital Convertor +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_ADC { + AT91_REG ADC_CR; // ADC Control Register + AT91_REG ADC_MR; // ADC Mode Register + AT91_REG Reserved0[2]; // + AT91_REG ADC_CHER; // ADC Channel Enable Register + AT91_REG ADC_CHDR; // ADC Channel Disable Register + AT91_REG ADC_CHSR; // ADC Channel Status Register + AT91_REG ADC_SR; // ADC Status Register + AT91_REG ADC_LCDR; // ADC Last Converted Data Register + AT91_REG ADC_IER; // ADC Interrupt Enable Register + AT91_REG ADC_IDR; // ADC Interrupt Disable Register + AT91_REG ADC_IMR; // ADC Interrupt Mask Register + AT91_REG ADC_CDR0; // ADC Channel Data Register 0 + AT91_REG ADC_CDR1; // ADC Channel Data Register 1 + AT91_REG ADC_CDR2; // ADC Channel Data Register 2 + AT91_REG ADC_CDR3; // ADC Channel Data Register 3 + AT91_REG ADC_CDR4; // ADC Channel Data Register 4 + AT91_REG ADC_CDR5; // ADC Channel Data Register 5 + AT91_REG ADC_CDR6; // ADC Channel Data Register 6 + AT91_REG ADC_CDR7; // ADC Channel Data Register 7 + AT91_REG Reserved1[5]; // + AT91_REG ADC_ACR; // Analog Control Register + AT91_REG ADC_EMR; // Extended Mode Register + AT91_REG Reserved2[32]; // + AT91_REG ADC_ADDRSIZE; // ADC ADDRSIZE REGISTER + AT91_REG ADC_IPNAME1; // ADC IPNAME1 REGISTER + AT91_REG ADC_IPNAME2; // ADC IPNAME2 REGISTER + AT91_REG ADC_FEATURES; // ADC FEATURES REGISTER + AT91_REG ADC_VER; // ADC VERSION REGISTER + AT91_REG ADC_RPR; // Receive Pointer Register + AT91_REG ADC_RCR; // Receive Counter Register + AT91_REG ADC_TPR; // Transmit Pointer Register + AT91_REG ADC_TCR; // Transmit Counter Register + AT91_REG ADC_RNPR; // Receive Next Pointer Register + AT91_REG ADC_RNCR; // Receive Next Counter Register + AT91_REG ADC_TNPR; // Transmit Next Pointer Register + AT91_REG ADC_TNCR; // Transmit Next Counter Register + AT91_REG ADC_PTCR; // PDC Transfer Control Register + AT91_REG ADC_PTSR; // PDC Transfer Status Register +} AT91S_ADC, *AT91PS_ADC; +#else +#define ADC_CR (AT91_CAST(AT91_REG *) 0x00000000) // (ADC_CR) ADC Control Register +#define ADC_MR (AT91_CAST(AT91_REG *) 0x00000004) // (ADC_MR) ADC Mode Register +#define ADC_CHER (AT91_CAST(AT91_REG *) 0x00000010) // (ADC_CHER) ADC Channel Enable Register +#define ADC_CHDR (AT91_CAST(AT91_REG *) 0x00000014) // (ADC_CHDR) ADC Channel Disable Register +#define ADC_CHSR (AT91_CAST(AT91_REG *) 0x00000018) // (ADC_CHSR) ADC Channel Status Register +#define ADC_SR (AT91_CAST(AT91_REG *) 0x0000001C) // (ADC_SR) ADC Status Register +#define ADC_LCDR (AT91_CAST(AT91_REG *) 0x00000020) // (ADC_LCDR) ADC Last Converted Data Register +#define ADC_IER (AT91_CAST(AT91_REG *) 0x00000024) // (ADC_IER) ADC Interrupt Enable Register +#define ADC_IDR (AT91_CAST(AT91_REG *) 0x00000028) // (ADC_IDR) ADC Interrupt Disable Register +#define ADC_IMR (AT91_CAST(AT91_REG *) 0x0000002C) // (ADC_IMR) ADC Interrupt Mask Register +#define ADC_CDR0 (AT91_CAST(AT91_REG *) 0x00000030) // (ADC_CDR0) ADC Channel Data Register 0 +#define ADC_CDR1 (AT91_CAST(AT91_REG *) 0x00000034) // (ADC_CDR1) ADC Channel Data Register 1 +#define ADC_CDR2 (AT91_CAST(AT91_REG *) 0x00000038) // (ADC_CDR2) ADC Channel Data Register 2 +#define ADC_CDR3 (AT91_CAST(AT91_REG *) 0x0000003C) // (ADC_CDR3) ADC Channel Data Register 3 +#define ADC_CDR4 (AT91_CAST(AT91_REG *) 0x00000040) // (ADC_CDR4) ADC Channel Data Register 4 +#define ADC_CDR5 (AT91_CAST(AT91_REG *) 0x00000044) // (ADC_CDR5) ADC Channel Data Register 5 +#define ADC_CDR6 (AT91_CAST(AT91_REG *) 0x00000048) // (ADC_CDR6) ADC Channel Data Register 6 +#define ADC_CDR7 (AT91_CAST(AT91_REG *) 0x0000004C) // (ADC_CDR7) ADC Channel Data Register 7 +#define ADC_ACR (AT91_CAST(AT91_REG *) 0x00000064) // (ADC_ACR) Analog Control Register +#define ADC_EMR (AT91_CAST(AT91_REG *) 0x00000068) // (ADC_EMR) Extended Mode Register +#define ADC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (ADC_ADDRSIZE) ADC ADDRSIZE REGISTER +#define ADC_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (ADC_IPNAME1) ADC IPNAME1 REGISTER +#define ADC_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (ADC_IPNAME2) ADC IPNAME2 REGISTER +#define ADC_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (ADC_FEATURES) ADC FEATURES REGISTER +#define ADC_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (ADC_VER) ADC VERSION REGISTER + +#endif +// -------- ADC_CR : (ADC Offset: 0x0) ADC Control Register -------- +#define AT91C_ADC_SWRST (0x1 << 0) // (ADC) Software Reset +#define AT91C_ADC_START (0x1 << 1) // (ADC) Start Conversion +// -------- ADC_MR : (ADC Offset: 0x4) ADC Mode Register -------- +#define AT91C_ADC_TRGEN (0x1 << 0) // (ADC) Trigger Enable +#define AT91C_ADC_TRGEN_DIS (0x0) // (ADC) Hradware triggers are disabled. Starting a conversion is only possible by software +#define AT91C_ADC_TRGEN_EN (0x1) // (ADC) Hardware trigger selected by TRGSEL field is enabled. +#define AT91C_ADC_TRGSEL (0x7 << 1) // (ADC) Trigger Selection +#define AT91C_ADC_TRGSEL_EXT (0x0 << 1) // (ADC) Selected TRGSEL = External Trigger +#define AT91C_ADC_TRGSEL_TIOA0 (0x1 << 1) // (ADC) Selected TRGSEL = TIAO0 +#define AT91C_ADC_TRGSEL_TIOA1 (0x2 << 1) // (ADC) Selected TRGSEL = TIAO1 +#define AT91C_ADC_TRGSEL_TIOA2 (0x3 << 1) // (ADC) Selected TRGSEL = TIAO2 +#define AT91C_ADC_TRGSEL_PWM0_TRIG (0x4 << 1) // (ADC) Selected TRGSEL = PWM trigger +#define AT91C_ADC_TRGSEL_PWM1_TRIG (0x5 << 1) // (ADC) Selected TRGSEL = PWM Trigger +#define AT91C_ADC_TRGSEL_RESERVED (0x6 << 1) // (ADC) Selected TRGSEL = Reserved +#define AT91C_ADC_LOWRES (0x1 << 4) // (ADC) Resolution. +#define AT91C_ADC_LOWRES_10_BIT (0x0 << 4) // (ADC) 10-bit resolution +#define AT91C_ADC_LOWRES_8_BIT (0x1 << 4) // (ADC) 8-bit resolution +#define AT91C_ADC_SLEEP (0x1 << 5) // (ADC) Sleep Mode +#define AT91C_ADC_SLEEP_NORMAL_MODE (0x0 << 5) // (ADC) Normal Mode +#define AT91C_ADC_SLEEP_MODE (0x1 << 5) // (ADC) Sleep Mode +#define AT91C_ADC_PRESCAL (0x3F << 8) // (ADC) Prescaler rate selection +#define AT91C_ADC_STARTUP (0x1F << 16) // (ADC) Startup Time +#define AT91C_ADC_SHTIM (0xF << 24) // (ADC) Sample & Hold Time +// -------- ADC_CHER : (ADC Offset: 0x10) ADC Channel Enable Register -------- +#define AT91C_ADC_CH0 (0x1 << 0) // (ADC) Channel 0 +#define AT91C_ADC_CH1 (0x1 << 1) // (ADC) Channel 1 +#define AT91C_ADC_CH2 (0x1 << 2) // (ADC) Channel 2 +#define AT91C_ADC_CH3 (0x1 << 3) // (ADC) Channel 3 +#define AT91C_ADC_CH4 (0x1 << 4) // (ADC) Channel 4 +#define AT91C_ADC_CH5 (0x1 << 5) // (ADC) Channel 5 +#define AT91C_ADC_CH6 (0x1 << 6) // (ADC) Channel 6 +#define AT91C_ADC_CH7 (0x1 << 7) // (ADC) Channel 7 +// -------- ADC_CHDR : (ADC Offset: 0x14) ADC Channel Disable Register -------- +// -------- ADC_CHSR : (ADC Offset: 0x18) ADC Channel Status Register -------- +// -------- ADC_SR : (ADC Offset: 0x1c) ADC Status Register -------- +#define AT91C_ADC_EOC0 (0x1 << 0) // (ADC) End of Conversion +#define AT91C_ADC_EOC1 (0x1 << 1) // (ADC) End of Conversion +#define AT91C_ADC_EOC2 (0x1 << 2) // (ADC) End of Conversion +#define AT91C_ADC_EOC3 (0x1 << 3) // (ADC) End of Conversion +#define AT91C_ADC_EOC4 (0x1 << 4) // (ADC) End of Conversion +#define AT91C_ADC_EOC5 (0x1 << 5) // (ADC) End of Conversion +#define AT91C_ADC_EOC6 (0x1 << 6) // (ADC) End of Conversion +#define AT91C_ADC_EOC7 (0x1 << 7) // (ADC) End of Conversion +#define AT91C_ADC_OVRE0 (0x1 << 8) // (ADC) Overrun Error +#define AT91C_ADC_OVRE1 (0x1 << 9) // (ADC) Overrun Error +#define AT91C_ADC_OVRE2 (0x1 << 10) // (ADC) Overrun Error +#define AT91C_ADC_OVRE3 (0x1 << 11) // (ADC) Overrun Error +#define AT91C_ADC_OVRE4 (0x1 << 12) // (ADC) Overrun Error +#define AT91C_ADC_OVRE5 (0x1 << 13) // (ADC) Overrun Error +#define AT91C_ADC_OVRE6 (0x1 << 14) // (ADC) Overrun Error +#define AT91C_ADC_OVRE7 (0x1 << 15) // (ADC) Overrun Error +#define AT91C_ADC_DRDY (0x1 << 16) // (ADC) Data Ready +#define AT91C_ADC_GOVRE (0x1 << 17) // (ADC) General Overrun +#define AT91C_ADC_ENDRX (0x1 << 18) // (ADC) End of Receiver Transfer +#define AT91C_ADC_RXBUFF (0x1 << 19) // (ADC) RXBUFF Interrupt +// -------- ADC_LCDR : (ADC Offset: 0x20) ADC Last Converted Data Register -------- +#define AT91C_ADC_LDATA (0x3FF << 0) // (ADC) Last Data Converted +// -------- ADC_IER : (ADC Offset: 0x24) ADC Interrupt Enable Register -------- +// -------- ADC_IDR : (ADC Offset: 0x28) ADC Interrupt Disable Register -------- +// -------- ADC_IMR : (ADC Offset: 0x2c) ADC Interrupt Mask Register -------- +// -------- ADC_CDR0 : (ADC Offset: 0x30) ADC Channel Data Register 0 -------- +#define AT91C_ADC_DATA (0x3FF << 0) // (ADC) Converted Data +// -------- ADC_CDR1 : (ADC Offset: 0x34) ADC Channel Data Register 1 -------- +// -------- ADC_CDR2 : (ADC Offset: 0x38) ADC Channel Data Register 2 -------- +// -------- ADC_CDR3 : (ADC Offset: 0x3c) ADC Channel Data Register 3 -------- +// -------- ADC_CDR4 : (ADC Offset: 0x40) ADC Channel Data Register 4 -------- +// -------- ADC_CDR5 : (ADC Offset: 0x44) ADC Channel Data Register 5 -------- +// -------- ADC_CDR6 : (ADC Offset: 0x48) ADC Channel Data Register 6 -------- +// -------- ADC_CDR7 : (ADC Offset: 0x4c) ADC Channel Data Register 7 -------- +// -------- ADC_ACR : (ADC Offset: 0x64) ADC Analog Controler Register -------- +#define AT91C_ADC_GAIN (0x3 << 0) // (ADC) Input Gain +#define AT91C_ADC_IBCTL (0x3 << 6) // (ADC) Bias Current Control +#define AT91C_ADC_IBCTL_00 (0x0 << 6) // (ADC) typ - 20% +#define AT91C_ADC_IBCTL_01 (0x1 << 6) // (ADC) typ +#define AT91C_ADC_IBCTL_10 (0x2 << 6) // (ADC) typ + 20% +#define AT91C_ADC_IBCTL_11 (0x3 << 6) // (ADC) typ + 40% +#define AT91C_ADC_DIFF (0x1 << 16) // (ADC) Differential Mode +#define AT91C_ADC_OFFSET (0x1 << 17) // (ADC) Input OFFSET +// -------- ADC_EMR : (ADC Offset: 0x68) ADC Extended Mode Register -------- +#define AT91C_OFFMODES (0x1 << 0) // (ADC) Off Mode if +#define AT91C_OFF_MODE_STARTUP_TIME (0x1 << 16) // (ADC) Startup Time +// -------- ADC_VER : (ADC Offset: 0xfc) ADC VER -------- +#define AT91C_ADC_VER (0xF << 0) // (ADC) ADC VER + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Timer Counter Channel Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_TC { + AT91_REG TC_CCR; // Channel Control Register + AT91_REG TC_CMR; // Channel Mode Register (Capture Mode / Waveform Mode) + AT91_REG Reserved0[2]; // + AT91_REG TC_CV; // Counter Value + AT91_REG TC_RA; // Register A + AT91_REG TC_RB; // Register B + AT91_REG TC_RC; // Register C + AT91_REG TC_SR; // Status Register + AT91_REG TC_IER; // Interrupt Enable Register + AT91_REG TC_IDR; // Interrupt Disable Register + AT91_REG TC_IMR; // Interrupt Mask Register +} AT91S_TC, *AT91PS_TC; +#else +#define TC_CCR (AT91_CAST(AT91_REG *) 0x00000000) // (TC_CCR) Channel Control Register +#define TC_CMR (AT91_CAST(AT91_REG *) 0x00000004) // (TC_CMR) Channel Mode Register (Capture Mode / Waveform Mode) +#define TC_CV (AT91_CAST(AT91_REG *) 0x00000010) // (TC_CV) Counter Value +#define TC_RA (AT91_CAST(AT91_REG *) 0x00000014) // (TC_RA) Register A +#define TC_RB (AT91_CAST(AT91_REG *) 0x00000018) // (TC_RB) Register B +#define TC_RC (AT91_CAST(AT91_REG *) 0x0000001C) // (TC_RC) Register C +#define TC_SR (AT91_CAST(AT91_REG *) 0x00000020) // (TC_SR) Status Register +#define TC_IER (AT91_CAST(AT91_REG *) 0x00000024) // (TC_IER) Interrupt Enable Register +#define TC_IDR (AT91_CAST(AT91_REG *) 0x00000028) // (TC_IDR) Interrupt Disable Register +#define TC_IMR (AT91_CAST(AT91_REG *) 0x0000002C) // (TC_IMR) Interrupt Mask Register + +#endif +// -------- TC_CCR : (TC Offset: 0x0) TC Channel Control Register -------- +#define AT91C_TC_CLKEN (0x1 << 0) // (TC) Counter Clock Enable Command +#define AT91C_TC_CLKDIS (0x1 << 1) // (TC) Counter Clock Disable Command +#define AT91C_TC_SWTRG (0x1 << 2) // (TC) Software Trigger Command +// -------- TC_CMR : (TC Offset: 0x4) TC Channel Mode Register: Capture Mode / Waveform Mode -------- +#define AT91C_TC_CLKS (0x7 << 0) // (TC) Clock Selection +#define AT91C_TC_CLKS_TIMER_DIV1_CLOCK (0x0) // (TC) Clock selected: TIMER_DIV1_CLOCK +#define AT91C_TC_CLKS_TIMER_DIV2_CLOCK (0x1) // (TC) Clock selected: TIMER_DIV2_CLOCK +#define AT91C_TC_CLKS_TIMER_DIV3_CLOCK (0x2) // (TC) Clock selected: TIMER_DIV3_CLOCK +#define AT91C_TC_CLKS_TIMER_DIV4_CLOCK (0x3) // (TC) Clock selected: TIMER_DIV4_CLOCK +#define AT91C_TC_CLKS_TIMER_DIV5_CLOCK (0x4) // (TC) Clock selected: TIMER_DIV5_CLOCK +#define AT91C_TC_CLKS_XC0 (0x5) // (TC) Clock selected: XC0 +#define AT91C_TC_CLKS_XC1 (0x6) // (TC) Clock selected: XC1 +#define AT91C_TC_CLKS_XC2 (0x7) // (TC) Clock selected: XC2 +#define AT91C_TC_CLKI (0x1 << 3) // (TC) Clock Invert +#define AT91C_TC_BURST (0x3 << 4) // (TC) Burst Signal Selection +#define AT91C_TC_BURST_NONE (0x0 << 4) // (TC) The clock is not gated by an external signal +#define AT91C_TC_BURST_XC0 (0x1 << 4) // (TC) XC0 is ANDed with the selected clock +#define AT91C_TC_BURST_XC1 (0x2 << 4) // (TC) XC1 is ANDed with the selected clock +#define AT91C_TC_BURST_XC2 (0x3 << 4) // (TC) XC2 is ANDed with the selected clock +#define AT91C_TC_CPCSTOP (0x1 << 6) // (TC) Counter Clock Stopped with RC Compare +#define AT91C_TC_LDBSTOP (0x1 << 6) // (TC) Counter Clock Stopped with RB Loading +#define AT91C_TC_CPCDIS (0x1 << 7) // (TC) Counter Clock Disable with RC Compare +#define AT91C_TC_LDBDIS (0x1 << 7) // (TC) Counter Clock Disabled with RB Loading +#define AT91C_TC_ETRGEDG (0x3 << 8) // (TC) External Trigger Edge Selection +#define AT91C_TC_ETRGEDG_NONE (0x0 << 8) // (TC) Edge: None +#define AT91C_TC_ETRGEDG_RISING (0x1 << 8) // (TC) Edge: rising edge +#define AT91C_TC_ETRGEDG_FALLING (0x2 << 8) // (TC) Edge: falling edge +#define AT91C_TC_ETRGEDG_BOTH (0x3 << 8) // (TC) Edge: each edge +#define AT91C_TC_EEVTEDG (0x3 << 8) // (TC) External Event Edge Selection +#define AT91C_TC_EEVTEDG_NONE (0x0 << 8) // (TC) Edge: None +#define AT91C_TC_EEVTEDG_RISING (0x1 << 8) // (TC) Edge: rising edge +#define AT91C_TC_EEVTEDG_FALLING (0x2 << 8) // (TC) Edge: falling edge +#define AT91C_TC_EEVTEDG_BOTH (0x3 << 8) // (TC) Edge: each edge +#define AT91C_TC_EEVT (0x3 << 10) // (TC) External Event Selection +#define AT91C_TC_EEVT_TIOB (0x0 << 10) // (TC) Signal selected as external event: TIOB TIOB direction: input +#define AT91C_TC_EEVT_XC0 (0x1 << 10) // (TC) Signal selected as external event: XC0 TIOB direction: output +#define AT91C_TC_EEVT_XC1 (0x2 << 10) // (TC) Signal selected as external event: XC1 TIOB direction: output +#define AT91C_TC_EEVT_XC2 (0x3 << 10) // (TC) Signal selected as external event: XC2 TIOB direction: output +#define AT91C_TC_ABETRG (0x1 << 10) // (TC) TIOA or TIOB External Trigger Selection +#define AT91C_TC_ENETRG (0x1 << 12) // (TC) External Event Trigger enable +#define AT91C_TC_WAVESEL (0x3 << 13) // (TC) Waveform Selection +#define AT91C_TC_WAVESEL_UP (0x0 << 13) // (TC) UP mode without atomatic trigger on RC Compare +#define AT91C_TC_WAVESEL_UPDOWN (0x1 << 13) // (TC) UPDOWN mode without automatic trigger on RC Compare +#define AT91C_TC_WAVESEL_UP_AUTO (0x2 << 13) // (TC) UP mode with automatic trigger on RC Compare +#define AT91C_TC_WAVESEL_UPDOWN_AUTO (0x3 << 13) // (TC) UPDOWN mode with automatic trigger on RC Compare +#define AT91C_TC_CPCTRG (0x1 << 14) // (TC) RC Compare Trigger Enable +#define AT91C_TC_WAVE (0x1 << 15) // (TC) +#define AT91C_TC_ACPA (0x3 << 16) // (TC) RA Compare Effect on TIOA +#define AT91C_TC_ACPA_NONE (0x0 << 16) // (TC) Effect: none +#define AT91C_TC_ACPA_SET (0x1 << 16) // (TC) Effect: set +#define AT91C_TC_ACPA_CLEAR (0x2 << 16) // (TC) Effect: clear +#define AT91C_TC_ACPA_TOGGLE (0x3 << 16) // (TC) Effect: toggle +#define AT91C_TC_LDRA (0x3 << 16) // (TC) RA Loading Selection +#define AT91C_TC_LDRA_NONE (0x0 << 16) // (TC) Edge: None +#define AT91C_TC_LDRA_RISING (0x1 << 16) // (TC) Edge: rising edge of TIOA +#define AT91C_TC_LDRA_FALLING (0x2 << 16) // (TC) Edge: falling edge of TIOA +#define AT91C_TC_LDRA_BOTH (0x3 << 16) // (TC) Edge: each edge of TIOA +#define AT91C_TC_ACPC (0x3 << 18) // (TC) RC Compare Effect on TIOA +#define AT91C_TC_ACPC_NONE (0x0 << 18) // (TC) Effect: none +#define AT91C_TC_ACPC_SET (0x1 << 18) // (TC) Effect: set +#define AT91C_TC_ACPC_CLEAR (0x2 << 18) // (TC) Effect: clear +#define AT91C_TC_ACPC_TOGGLE (0x3 << 18) // (TC) Effect: toggle +#define AT91C_TC_LDRB (0x3 << 18) // (TC) RB Loading Selection +#define AT91C_TC_LDRB_NONE (0x0 << 18) // (TC) Edge: None +#define AT91C_TC_LDRB_RISING (0x1 << 18) // (TC) Edge: rising edge of TIOA +#define AT91C_TC_LDRB_FALLING (0x2 << 18) // (TC) Edge: falling edge of TIOA +#define AT91C_TC_LDRB_BOTH (0x3 << 18) // (TC) Edge: each edge of TIOA +#define AT91C_TC_AEEVT (0x3 << 20) // (TC) External Event Effect on TIOA +#define AT91C_TC_AEEVT_NONE (0x0 << 20) // (TC) Effect: none +#define AT91C_TC_AEEVT_SET (0x1 << 20) // (TC) Effect: set +#define AT91C_TC_AEEVT_CLEAR (0x2 << 20) // (TC) Effect: clear +#define AT91C_TC_AEEVT_TOGGLE (0x3 << 20) // (TC) Effect: toggle +#define AT91C_TC_ASWTRG (0x3 << 22) // (TC) Software Trigger Effect on TIOA +#define AT91C_TC_ASWTRG_NONE (0x0 << 22) // (TC) Effect: none +#define AT91C_TC_ASWTRG_SET (0x1 << 22) // (TC) Effect: set +#define AT91C_TC_ASWTRG_CLEAR (0x2 << 22) // (TC) Effect: clear +#define AT91C_TC_ASWTRG_TOGGLE (0x3 << 22) // (TC) Effect: toggle +#define AT91C_TC_BCPB (0x3 << 24) // (TC) RB Compare Effect on TIOB +#define AT91C_TC_BCPB_NONE (0x0 << 24) // (TC) Effect: none +#define AT91C_TC_BCPB_SET (0x1 << 24) // (TC) Effect: set +#define AT91C_TC_BCPB_CLEAR (0x2 << 24) // (TC) Effect: clear +#define AT91C_TC_BCPB_TOGGLE (0x3 << 24) // (TC) Effect: toggle +#define AT91C_TC_BCPC (0x3 << 26) // (TC) RC Compare Effect on TIOB +#define AT91C_TC_BCPC_NONE (0x0 << 26) // (TC) Effect: none +#define AT91C_TC_BCPC_SET (0x1 << 26) // (TC) Effect: set +#define AT91C_TC_BCPC_CLEAR (0x2 << 26) // (TC) Effect: clear +#define AT91C_TC_BCPC_TOGGLE (0x3 << 26) // (TC) Effect: toggle +#define AT91C_TC_BEEVT (0x3 << 28) // (TC) External Event Effect on TIOB +#define AT91C_TC_BEEVT_NONE (0x0 << 28) // (TC) Effect: none +#define AT91C_TC_BEEVT_SET (0x1 << 28) // (TC) Effect: set +#define AT91C_TC_BEEVT_CLEAR (0x2 << 28) // (TC) Effect: clear +#define AT91C_TC_BEEVT_TOGGLE (0x3 << 28) // (TC) Effect: toggle +#define AT91C_TC_BSWTRG (0x3 << 30) // (TC) Software Trigger Effect on TIOB +#define AT91C_TC_BSWTRG_NONE (0x0 << 30) // (TC) Effect: none +#define AT91C_TC_BSWTRG_SET (0x1 << 30) // (TC) Effect: set +#define AT91C_TC_BSWTRG_CLEAR (0x2 << 30) // (TC) Effect: clear +#define AT91C_TC_BSWTRG_TOGGLE (0x3 << 30) // (TC) Effect: toggle +// -------- TC_SR : (TC Offset: 0x20) TC Channel Status Register -------- +#define AT91C_TC_COVFS (0x1 << 0) // (TC) Counter Overflow +#define AT91C_TC_LOVRS (0x1 << 1) // (TC) Load Overrun +#define AT91C_TC_CPAS (0x1 << 2) // (TC) RA Compare +#define AT91C_TC_CPBS (0x1 << 3) // (TC) RB Compare +#define AT91C_TC_CPCS (0x1 << 4) // (TC) RC Compare +#define AT91C_TC_LDRAS (0x1 << 5) // (TC) RA Loading +#define AT91C_TC_LDRBS (0x1 << 6) // (TC) RB Loading +#define AT91C_TC_ETRGS (0x1 << 7) // (TC) External Trigger +#define AT91C_TC_CLKSTA (0x1 << 16) // (TC) Clock Enabling +#define AT91C_TC_MTIOA (0x1 << 17) // (TC) TIOA Mirror +#define AT91C_TC_MTIOB (0x1 << 18) // (TC) TIOA Mirror +// -------- TC_IER : (TC Offset: 0x24) TC Channel Interrupt Enable Register -------- +// -------- TC_IDR : (TC Offset: 0x28) TC Channel Interrupt Disable Register -------- +// -------- TC_IMR : (TC Offset: 0x2c) TC Channel Interrupt Mask Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Timer Counter Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_TCB { + AT91S_TC TCB_TC0; // TC Channel 0 + AT91_REG Reserved0[4]; // + AT91S_TC TCB_TC1; // TC Channel 1 + AT91_REG Reserved1[4]; // + AT91S_TC TCB_TC2; // TC Channel 2 + AT91_REG Reserved2[4]; // + AT91_REG TCB_BCR; // TC Block Control Register + AT91_REG TCB_BMR; // TC Block Mode Register + AT91_REG Reserved3[9]; // + AT91_REG TCB_ADDRSIZE; // TC ADDRSIZE REGISTER + AT91_REG TCB_IPNAME1; // TC IPNAME1 REGISTER + AT91_REG TCB_IPNAME2; // TC IPNAME2 REGISTER + AT91_REG TCB_FEATURES; // TC FEATURES REGISTER + AT91_REG TCB_VER; // Version Register +} AT91S_TCB, *AT91PS_TCB; +#else +#define TCB_BCR (AT91_CAST(AT91_REG *) 0x000000C0) // (TCB_BCR) TC Block Control Register +#define TCB_BMR (AT91_CAST(AT91_REG *) 0x000000C4) // (TCB_BMR) TC Block Mode Register +#define TC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (TC_ADDRSIZE) TC ADDRSIZE REGISTER +#define TC_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (TC_IPNAME1) TC IPNAME1 REGISTER +#define TC_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (TC_IPNAME2) TC IPNAME2 REGISTER +#define TC_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (TC_FEATURES) TC FEATURES REGISTER +#define TC_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (TC_VER) Version Register + +#endif +// -------- TCB_BCR : (TCB Offset: 0xc0) TC Block Control Register -------- +#define AT91C_TCB_SYNC (0x1 << 0) // (TCB) Synchro Command +// -------- TCB_BMR : (TCB Offset: 0xc4) TC Block Mode Register -------- +#define AT91C_TCB_TC0XC0S (0x3 << 0) // (TCB) External Clock Signal 0 Selection +#define AT91C_TCB_TC0XC0S_TCLK0 (0x0) // (TCB) TCLK0 connected to XC0 +#define AT91C_TCB_TC0XC0S_NONE (0x1) // (TCB) None signal connected to XC0 +#define AT91C_TCB_TC0XC0S_TIOA1 (0x2) // (TCB) TIOA1 connected to XC0 +#define AT91C_TCB_TC0XC0S_TIOA2 (0x3) // (TCB) TIOA2 connected to XC0 +#define AT91C_TCB_TC1XC1S (0x3 << 2) // (TCB) External Clock Signal 1 Selection +#define AT91C_TCB_TC1XC1S_TCLK1 (0x0 << 2) // (TCB) TCLK1 connected to XC1 +#define AT91C_TCB_TC1XC1S_NONE (0x1 << 2) // (TCB) None signal connected to XC1 +#define AT91C_TCB_TC1XC1S_TIOA0 (0x2 << 2) // (TCB) TIOA0 connected to XC1 +#define AT91C_TCB_TC1XC1S_TIOA2 (0x3 << 2) // (TCB) TIOA2 connected to XC1 +#define AT91C_TCB_TC2XC2S (0x3 << 4) // (TCB) External Clock Signal 2 Selection +#define AT91C_TCB_TC2XC2S_TCLK2 (0x0 << 4) // (TCB) TCLK2 connected to XC2 +#define AT91C_TCB_TC2XC2S_NONE (0x1 << 4) // (TCB) None signal connected to XC2 +#define AT91C_TCB_TC2XC2S_TIOA0 (0x2 << 4) // (TCB) TIOA0 connected to XC2 +#define AT91C_TCB_TC2XC2S_TIOA1 (0x3 << 4) // (TCB) TIOA2 connected to XC2 + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Embedded Flash Controller 2.0 +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_EFC { + AT91_REG EFC_FMR; // EFC Flash Mode Register + AT91_REG EFC_FCR; // EFC Flash Command Register + AT91_REG EFC_FSR; // EFC Flash Status Register + AT91_REG EFC_FRR; // EFC Flash Result Register + AT91_REG Reserved0[1]; // + AT91_REG EFC_FVR; // EFC Flash Version Register +} AT91S_EFC, *AT91PS_EFC; +#else +#define EFC_FMR (AT91_CAST(AT91_REG *) 0x00000000) // (EFC_FMR) EFC Flash Mode Register +#define EFC_FCR (AT91_CAST(AT91_REG *) 0x00000004) // (EFC_FCR) EFC Flash Command Register +#define EFC_FSR (AT91_CAST(AT91_REG *) 0x00000008) // (EFC_FSR) EFC Flash Status Register +#define EFC_FRR (AT91_CAST(AT91_REG *) 0x0000000C) // (EFC_FRR) EFC Flash Result Register +#define EFC_FVR (AT91_CAST(AT91_REG *) 0x00000014) // (EFC_FVR) EFC Flash Version Register + +#endif +// -------- EFC_FMR : (EFC Offset: 0x0) EFC Flash Mode Register -------- +#define AT91C_EFC_FRDY (0x1 << 0) // (EFC) Ready Interrupt Enable +#define AT91C_EFC_FWS (0xF << 8) // (EFC) Flash Wait State. +#define AT91C_EFC_FWS_0WS (0x0 << 8) // (EFC) 0 Wait State +#define AT91C_EFC_FWS_1WS (0x1 << 8) // (EFC) 1 Wait State +#define AT91C_EFC_FWS_2WS (0x2 << 8) // (EFC) 2 Wait States +#define AT91C_EFC_FWS_3WS (0x3 << 8) // (EFC) 3 Wait States +// -------- EFC_FCR : (EFC Offset: 0x4) EFC Flash Command Register -------- +#define AT91C_EFC_FCMD (0xFF << 0) // (EFC) Flash Command +#define AT91C_EFC_FCMD_GETD (0x0) // (EFC) Get Flash Descriptor +#define AT91C_EFC_FCMD_WP (0x1) // (EFC) Write Page +#define AT91C_EFC_FCMD_WPL (0x2) // (EFC) Write Page and Lock +#define AT91C_EFC_FCMD_EWP (0x3) // (EFC) Erase Page and Write Page +#define AT91C_EFC_FCMD_EWPL (0x4) // (EFC) Erase Page and Write Page then Lock +#define AT91C_EFC_FCMD_EA (0x5) // (EFC) Erase All +#define AT91C_EFC_FCMD_EPL (0x6) // (EFC) Erase Plane +#define AT91C_EFC_FCMD_EPA (0x7) // (EFC) Erase Pages +#define AT91C_EFC_FCMD_SLB (0x8) // (EFC) Set Lock Bit +#define AT91C_EFC_FCMD_CLB (0x9) // (EFC) Clear Lock Bit +#define AT91C_EFC_FCMD_GLB (0xA) // (EFC) Get Lock Bit +#define AT91C_EFC_FCMD_SFB (0xB) // (EFC) Set Fuse Bit +#define AT91C_EFC_FCMD_CFB (0xC) // (EFC) Clear Fuse Bit +#define AT91C_EFC_FCMD_GFB (0xD) // (EFC) Get Fuse Bit +#define AT91C_EFC_FCMD_STUI (0xE) // (EFC) Start Read Unique ID +#define AT91C_EFC_FCMD_SPUI (0xF) // (EFC) Stop Read Unique ID +#define AT91C_EFC_FARG (0xFFFF << 8) // (EFC) Flash Command Argument +#define AT91C_EFC_FKEY (0xFF << 24) // (EFC) Flash Writing Protection Key +// -------- EFC_FSR : (EFC Offset: 0x8) EFC Flash Status Register -------- +#define AT91C_EFC_FRDY_S (0x1 << 0) // (EFC) Flash Ready Status +#define AT91C_EFC_FCMDE (0x1 << 1) // (EFC) Flash Command Error Status +#define AT91C_EFC_LOCKE (0x1 << 2) // (EFC) Flash Lock Error Status +// -------- EFC_FRR : (EFC Offset: 0xc) EFC Flash Result Register -------- +#define AT91C_EFC_FVALUE (0x0 << 0) // (EFC) Flash Result Value + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Multimedia Card Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_MCI { + AT91_REG MCI_CR; // MCI Control Register + AT91_REG MCI_MR; // MCI Mode Register + AT91_REG MCI_DTOR; // MCI Data Timeout Register + AT91_REG MCI_SDCR; // MCI SD/SDIO Card Register + AT91_REG MCI_ARGR; // MCI Argument Register + AT91_REG MCI_CMDR; // MCI Command Register + AT91_REG MCI_BLKR; // MCI Block Register + AT91_REG MCI_CSTOR; // MCI Completion Signal Timeout Register + AT91_REG MCI_RSPR[4]; // MCI Response Register + AT91_REG MCI_RDR; // MCI Receive Data Register + AT91_REG MCI_TDR; // MCI Transmit Data Register + AT91_REG Reserved0[2]; // + AT91_REG MCI_SR; // MCI Status Register + AT91_REG MCI_IER; // MCI Interrupt Enable Register + AT91_REG MCI_IDR; // MCI Interrupt Disable Register + AT91_REG MCI_IMR; // MCI Interrupt Mask Register + AT91_REG MCI_DMA; // MCI DMA Configuration Register + AT91_REG MCI_CFG; // MCI Configuration Register + AT91_REG Reserved1[35]; // + AT91_REG MCI_WPCR; // MCI Write Protection Control Register + AT91_REG MCI_WPSR; // MCI Write Protection Status Register + AT91_REG MCI_ADDRSIZE; // MCI ADDRSIZE REGISTER + AT91_REG MCI_IPNAME1; // MCI IPNAME1 REGISTER + AT91_REG MCI_IPNAME2; // MCI IPNAME2 REGISTER + AT91_REG MCI_FEATURES; // MCI FEATURES REGISTER + AT91_REG MCI_VER; // MCI VERSION REGISTER + AT91_REG MCI_RPR; // Receive Pointer Register + AT91_REG MCI_RCR; // Receive Counter Register + AT91_REG MCI_TPR; // Transmit Pointer Register + AT91_REG MCI_TCR; // Transmit Counter Register + AT91_REG MCI_RNPR; // Receive Next Pointer Register + AT91_REG MCI_RNCR; // Receive Next Counter Register + AT91_REG MCI_TNPR; // Transmit Next Pointer Register + AT91_REG MCI_TNCR; // Transmit Next Counter Register + AT91_REG MCI_PTCR; // PDC Transfer Control Register + AT91_REG MCI_PTSR; // PDC Transfer Status Register + AT91_REG Reserved2[54]; // + AT91_REG MCI_FIFO; // MCI FIFO Aperture Register +} AT91S_MCI, *AT91PS_MCI; +#else +#define MCI_CR (AT91_CAST(AT91_REG *) 0x00000000) // (MCI_CR) MCI Control Register +#define MCI_MR (AT91_CAST(AT91_REG *) 0x00000004) // (MCI_MR) MCI Mode Register +#define MCI_DTOR (AT91_CAST(AT91_REG *) 0x00000008) // (MCI_DTOR) MCI Data Timeout Register +#define MCI_SDCR (AT91_CAST(AT91_REG *) 0x0000000C) // (MCI_SDCR) MCI SD/SDIO Card Register +#define MCI_ARGR (AT91_CAST(AT91_REG *) 0x00000010) // (MCI_ARGR) MCI Argument Register +#define MCI_CMDR (AT91_CAST(AT91_REG *) 0x00000014) // (MCI_CMDR) MCI Command Register +#define MCI_BLKR (AT91_CAST(AT91_REG *) 0x00000018) // (MCI_BLKR) MCI Block Register +#define MCI_CSTOR (AT91_CAST(AT91_REG *) 0x0000001C) // (MCI_CSTOR) MCI Completion Signal Timeout Register +#define MCI_RSPR (AT91_CAST(AT91_REG *) 0x00000020) // (MCI_RSPR) MCI Response Register +#define MCI_RDR (AT91_CAST(AT91_REG *) 0x00000030) // (MCI_RDR) MCI Receive Data Register +#define MCI_TDR (AT91_CAST(AT91_REG *) 0x00000034) // (MCI_TDR) MCI Transmit Data Register +#define MCI_SR (AT91_CAST(AT91_REG *) 0x00000040) // (MCI_SR) MCI Status Register +#define MCI_IER (AT91_CAST(AT91_REG *) 0x00000044) // (MCI_IER) MCI Interrupt Enable Register +#define MCI_IDR (AT91_CAST(AT91_REG *) 0x00000048) // (MCI_IDR) MCI Interrupt Disable Register +#define MCI_IMR (AT91_CAST(AT91_REG *) 0x0000004C) // (MCI_IMR) MCI Interrupt Mask Register +#define MCI_DMA (AT91_CAST(AT91_REG *) 0x00000050) // (MCI_DMA) MCI DMA Configuration Register +#define MCI_CFG (AT91_CAST(AT91_REG *) 0x00000054) // (MCI_CFG) MCI Configuration Register +#define MCI_WPCR (AT91_CAST(AT91_REG *) 0x000000E4) // (MCI_WPCR) MCI Write Protection Control Register +#define MCI_WPSR (AT91_CAST(AT91_REG *) 0x000000E8) // (MCI_WPSR) MCI Write Protection Status Register +#define MCI_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (MCI_ADDRSIZE) MCI ADDRSIZE REGISTER +#define MCI_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (MCI_IPNAME1) MCI IPNAME1 REGISTER +#define MCI_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (MCI_IPNAME2) MCI IPNAME2 REGISTER +#define MCI_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (MCI_FEATURES) MCI FEATURES REGISTER +#define MCI_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (MCI_VER) MCI VERSION REGISTER +#define MCI_FIFO (AT91_CAST(AT91_REG *) 0x00000200) // (MCI_FIFO) MCI FIFO Aperture Register + +#endif +// -------- MCI_CR : (MCI Offset: 0x0) MCI Control Register -------- +#define AT91C_MCI_MCIEN (0x1 << 0) // (MCI) Multimedia Interface Enable +#define AT91C_MCI_MCIEN_0 (0x0) // (MCI) No effect +#define AT91C_MCI_MCIEN_1 (0x1) // (MCI) Enable the MultiMedia Interface if MCIDIS is 0 +#define AT91C_MCI_MCIDIS (0x1 << 1) // (MCI) Multimedia Interface Disable +#define AT91C_MCI_MCIDIS_0 (0x0 << 1) // (MCI) No effect +#define AT91C_MCI_MCIDIS_1 (0x1 << 1) // (MCI) Disable the MultiMedia Interface +#define AT91C_MCI_PWSEN (0x1 << 2) // (MCI) Power Save Mode Enable +#define AT91C_MCI_PWSEN_0 (0x0 << 2) // (MCI) No effect +#define AT91C_MCI_PWSEN_1 (0x1 << 2) // (MCI) Enable the Power-saving mode if PWSDIS is 0. +#define AT91C_MCI_PWSDIS (0x1 << 3) // (MCI) Power Save Mode Disable +#define AT91C_MCI_PWSDIS_0 (0x0 << 3) // (MCI) No effect +#define AT91C_MCI_PWSDIS_1 (0x1 << 3) // (MCI) Disable the Power-saving mode. +#define AT91C_MCI_IOWAITEN (0x1 << 4) // (MCI) SDIO Read Wait Enable +#define AT91C_MCI_IOWAITEN_0 (0x0 << 4) // (MCI) No effect +#define AT91C_MCI_IOWAITEN_1 (0x1 << 4) // (MCI) Enables the SDIO Read Wait Operation. +#define AT91C_MCI_IOWAITDIS (0x1 << 5) // (MCI) SDIO Read Wait Disable +#define AT91C_MCI_IOWAITDIS_0 (0x0 << 5) // (MCI) No effect +#define AT91C_MCI_IOWAITDIS_1 (0x1 << 5) // (MCI) Disables the SDIO Read Wait Operation. +#define AT91C_MCI_SWRST (0x1 << 7) // (MCI) MCI Software reset +#define AT91C_MCI_SWRST_0 (0x0 << 7) // (MCI) No effect +#define AT91C_MCI_SWRST_1 (0x1 << 7) // (MCI) Resets the MCI +// -------- MCI_MR : (MCI Offset: 0x4) MCI Mode Register -------- +#define AT91C_MCI_CLKDIV (0xFF << 0) // (MCI) Clock Divider +#define AT91C_MCI_PWSDIV (0x7 << 8) // (MCI) Power Saving Divider +#define AT91C_MCI_RDPROOF (0x1 << 11) // (MCI) Read Proof Enable +#define AT91C_MCI_RDPROOF_DISABLE (0x0 << 11) // (MCI) Disables Read Proof +#define AT91C_MCI_RDPROOF_ENABLE (0x1 << 11) // (MCI) Enables Read Proof +#define AT91C_MCI_WRPROOF (0x1 << 12) // (MCI) Write Proof Enable +#define AT91C_MCI_WRPROOF_DISABLE (0x0 << 12) // (MCI) Disables Write Proof +#define AT91C_MCI_WRPROOF_ENABLE (0x1 << 12) // (MCI) Enables Write Proof +#define AT91C_MCI_PDCFBYTE (0x1 << 13) // (MCI) PDC Force Byte Transfer +#define AT91C_MCI_PDCFBYTE_DISABLE (0x0 << 13) // (MCI) Disables PDC Force Byte Transfer +#define AT91C_MCI_PDCFBYTE_ENABLE (0x1 << 13) // (MCI) Enables PDC Force Byte Transfer +#define AT91C_MCI_PDCPADV (0x1 << 14) // (MCI) PDC Padding Value +#define AT91C_MCI_PDCMODE (0x1 << 15) // (MCI) PDC Oriented Mode +#define AT91C_MCI_PDCMODE_DISABLE (0x0 << 15) // (MCI) Disables PDC Transfer +#define AT91C_MCI_PDCMODE_ENABLE (0x1 << 15) // (MCI) Enables PDC Transfer +#define AT91C_MCI_BLKLEN (0xFFFF << 16) // (MCI) Data Block Length +// -------- MCI_DTOR : (MCI Offset: 0x8) MCI Data Timeout Register -------- +#define AT91C_MCI_DTOCYC (0xF << 0) // (MCI) Data Timeout Cycle Number +#define AT91C_MCI_DTOMUL (0x7 << 4) // (MCI) Data Timeout Multiplier +#define AT91C_MCI_DTOMUL_1 (0x0 << 4) // (MCI) DTOCYC x 1 +#define AT91C_MCI_DTOMUL_16 (0x1 << 4) // (MCI) DTOCYC x 16 +#define AT91C_MCI_DTOMUL_128 (0x2 << 4) // (MCI) DTOCYC x 128 +#define AT91C_MCI_DTOMUL_256 (0x3 << 4) // (MCI) DTOCYC x 256 +#define AT91C_MCI_DTOMUL_1024 (0x4 << 4) // (MCI) DTOCYC x 1024 +#define AT91C_MCI_DTOMUL_4096 (0x5 << 4) // (MCI) DTOCYC x 4096 +#define AT91C_MCI_DTOMUL_65536 (0x6 << 4) // (MCI) DTOCYC x 65536 +#define AT91C_MCI_DTOMUL_1048576 (0x7 << 4) // (MCI) DTOCYC x 1048576 +// -------- MCI_SDCR : (MCI Offset: 0xc) MCI SD Card Register -------- +#define AT91C_MCI_SCDSEL (0x3 << 0) // (MCI) SD Card/SDIO Selector +#define AT91C_MCI_SCDSEL_SLOTA (0x0) // (MCI) Slot A selected +#define AT91C_MCI_SCDSEL_SLOTB (0x1) // (MCI) Slot B selected +#define AT91C_MCI_SCDSEL_SLOTC (0x2) // (MCI) Slot C selected +#define AT91C_MCI_SCDSEL_SLOTD (0x3) // (MCI) Slot D selected +#define AT91C_MCI_SCDBUS (0x3 << 6) // (MCI) SDCard/SDIO Bus Width +#define AT91C_MCI_SCDBUS_1BIT (0x0 << 6) // (MCI) 1-bit data bus +#define AT91C_MCI_SCDBUS_4BITS (0x2 << 6) // (MCI) 4-bits data bus +#define AT91C_MCI_SCDBUS_8BITS (0x3 << 6) // (MCI) 8-bits data bus +// -------- MCI_CMDR : (MCI Offset: 0x14) MCI Command Register -------- +#define AT91C_MCI_CMDNB (0x3F << 0) // (MCI) Command Number +#define AT91C_MCI_RSPTYP (0x3 << 6) // (MCI) Response Type +#define AT91C_MCI_RSPTYP_NO (0x0 << 6) // (MCI) No response +#define AT91C_MCI_RSPTYP_48 (0x1 << 6) // (MCI) 48-bit response +#define AT91C_MCI_RSPTYP_136 (0x2 << 6) // (MCI) 136-bit response +#define AT91C_MCI_RSPTYP_R1B (0x3 << 6) // (MCI) R1b response +#define AT91C_MCI_SPCMD (0x7 << 8) // (MCI) Special CMD +#define AT91C_MCI_SPCMD_NONE (0x0 << 8) // (MCI) Not a special CMD +#define AT91C_MCI_SPCMD_INIT (0x1 << 8) // (MCI) Initialization CMD +#define AT91C_MCI_SPCMD_SYNC (0x2 << 8) // (MCI) Synchronized CMD +#define AT91C_MCI_SPCMD_CE_ATA (0x3 << 8) // (MCI) CE-ATA Completion Signal disable CMD +#define AT91C_MCI_SPCMD_IT_CMD (0x4 << 8) // (MCI) Interrupt command +#define AT91C_MCI_SPCMD_IT_REP (0x5 << 8) // (MCI) Interrupt response +#define AT91C_MCI_SPCMD_BOOTREQ (0x6 << 8) // (MCI) Boot Operation Request +#define AT91C_MCI_SPCMD_BOOTEND (0x7 << 8) // (MCI) End Boot Operation +#define AT91C_MCI_OPDCMD (0x1 << 11) // (MCI) Open Drain Command +#define AT91C_MCI_OPDCMD_PUSHPULL (0x0 << 11) // (MCI) Push/pull command +#define AT91C_MCI_OPDCMD_OPENDRAIN (0x1 << 11) // (MCI) Open drain command +#define AT91C_MCI_MAXLAT (0x1 << 12) // (MCI) Maximum Latency for Command to respond +#define AT91C_MCI_MAXLAT_5 (0x0 << 12) // (MCI) 5 cycles maximum latency +#define AT91C_MCI_MAXLAT_64 (0x1 << 12) // (MCI) 64 cycles maximum latency +#define AT91C_MCI_TRCMD (0x3 << 16) // (MCI) Transfer CMD +#define AT91C_MCI_TRCMD_NO (0x0 << 16) // (MCI) No transfer +#define AT91C_MCI_TRCMD_START (0x1 << 16) // (MCI) Start transfer +#define AT91C_MCI_TRCMD_STOP (0x2 << 16) // (MCI) Stop transfer +#define AT91C_MCI_TRDIR (0x1 << 18) // (MCI) Transfer Direction +#define AT91C_MCI_TRDIR_WRITE (0x0 << 18) // (MCI) Write +#define AT91C_MCI_TRDIR_READ (0x1 << 18) // (MCI) Read +#define AT91C_MCI_TRTYP (0x7 << 19) // (MCI) Transfer Type +#define AT91C_MCI_TRTYP_BLOCK (0x0 << 19) // (MCI) MMC/SDCard Single Block Transfer type +#define AT91C_MCI_TRTYP_MULTIPLE (0x1 << 19) // (MCI) MMC/SDCard Multiple Block transfer type +#define AT91C_MCI_TRTYP_STREAM (0x2 << 19) // (MCI) MMC Stream transfer type +#define AT91C_MCI_TRTYP_SDIO_BYTE (0x4 << 19) // (MCI) SDIO Byte transfer type +#define AT91C_MCI_TRTYP_SDIO_BLOCK (0x5 << 19) // (MCI) SDIO Block transfer type +#define AT91C_MCI_IOSPCMD (0x3 << 24) // (MCI) SDIO Special Command +#define AT91C_MCI_IOSPCMD_NONE (0x0 << 24) // (MCI) NOT a special command +#define AT91C_MCI_IOSPCMD_SUSPEND (0x1 << 24) // (MCI) SDIO Suspend Command +#define AT91C_MCI_IOSPCMD_RESUME (0x2 << 24) // (MCI) SDIO Resume Command +#define AT91C_MCI_ATACS (0x1 << 26) // (MCI) ATA with command completion signal +#define AT91C_MCI_ATACS_NORMAL (0x0 << 26) // (MCI) normal operation mode +#define AT91C_MCI_ATACS_COMPLETION (0x1 << 26) // (MCI) completion signal is expected within MCI_CSTOR +#define AT91C_MCI_BOOTACK (0x1 << 27) // (MCI) Boot Operation Acknowledge +#define AT91C_MCI_BOOTACK_DISABLE (0x0 << 27) // (MCI) Boot Operation Acknowledge Disabled +#define AT91C_MCI_BOOTACK_ENABLE (0x1 << 27) // (MCI) Boot Operation Acknowledge Enabled +// -------- MCI_BLKR : (MCI Offset: 0x18) MCI Block Register -------- +#define AT91C_MCI_BCNT (0xFFFF << 0) // (MCI) MMC/SDIO Block Count / SDIO Byte Count +// -------- MCI_CSTOR : (MCI Offset: 0x1c) MCI Completion Signal Timeout Register -------- +#define AT91C_MCI_CSTOCYC (0xF << 0) // (MCI) Completion Signal Timeout Cycle Number +#define AT91C_MCI_CSTOMUL (0x7 << 4) // (MCI) Completion Signal Timeout Multiplier +#define AT91C_MCI_CSTOMUL_1 (0x0 << 4) // (MCI) CSTOCYC x 1 +#define AT91C_MCI_CSTOMUL_16 (0x1 << 4) // (MCI) CSTOCYC x 16 +#define AT91C_MCI_CSTOMUL_128 (0x2 << 4) // (MCI) CSTOCYC x 128 +#define AT91C_MCI_CSTOMUL_256 (0x3 << 4) // (MCI) CSTOCYC x 256 +#define AT91C_MCI_CSTOMUL_1024 (0x4 << 4) // (MCI) CSTOCYC x 1024 +#define AT91C_MCI_CSTOMUL_4096 (0x5 << 4) // (MCI) CSTOCYC x 4096 +#define AT91C_MCI_CSTOMUL_65536 (0x6 << 4) // (MCI) CSTOCYC x 65536 +#define AT91C_MCI_CSTOMUL_1048576 (0x7 << 4) // (MCI) CSTOCYC x 1048576 +// -------- MCI_SR : (MCI Offset: 0x40) MCI Status Register -------- +#define AT91C_MCI_CMDRDY (0x1 << 0) // (MCI) Command Ready flag +#define AT91C_MCI_RXRDY (0x1 << 1) // (MCI) RX Ready flag +#define AT91C_MCI_TXRDY (0x1 << 2) // (MCI) TX Ready flag +#define AT91C_MCI_BLKE (0x1 << 3) // (MCI) Data Block Transfer Ended flag +#define AT91C_MCI_DTIP (0x1 << 4) // (MCI) Data Transfer in Progress flag +#define AT91C_MCI_NOTBUSY (0x1 << 5) // (MCI) Data Line Not Busy flag +#define AT91C_MCI_ENDRX (0x1 << 6) // (MCI) End of RX Buffer flag +#define AT91C_MCI_ENDTX (0x1 << 7) // (MCI) End of TX Buffer flag +#define AT91C_MCI_SDIOIRQA (0x1 << 8) // (MCI) SDIO Interrupt for Slot A +#define AT91C_MCI_SDIOIRQB (0x1 << 9) // (MCI) SDIO Interrupt for Slot B +#define AT91C_MCI_SDIOIRQC (0x1 << 10) // (MCI) SDIO Interrupt for Slot C +#define AT91C_MCI_SDIOIRQD (0x1 << 11) // (MCI) SDIO Interrupt for Slot D +#define AT91C_MCI_SDIOWAIT (0x1 << 12) // (MCI) SDIO Read Wait operation flag +#define AT91C_MCI_CSRCV (0x1 << 13) // (MCI) CE-ATA Completion Signal flag +#define AT91C_MCI_RXBUFF (0x1 << 14) // (MCI) RX Buffer Full flag +#define AT91C_MCI_TXBUFE (0x1 << 15) // (MCI) TX Buffer Empty flag +#define AT91C_MCI_RINDE (0x1 << 16) // (MCI) Response Index Error flag +#define AT91C_MCI_RDIRE (0x1 << 17) // (MCI) Response Direction Error flag +#define AT91C_MCI_RCRCE (0x1 << 18) // (MCI) Response CRC Error flag +#define AT91C_MCI_RENDE (0x1 << 19) // (MCI) Response End Bit Error flag +#define AT91C_MCI_RTOE (0x1 << 20) // (MCI) Response Time-out Error flag +#define AT91C_MCI_DCRCE (0x1 << 21) // (MCI) data CRC Error flag +#define AT91C_MCI_DTOE (0x1 << 22) // (MCI) Data timeout Error flag +#define AT91C_MCI_CSTOE (0x1 << 23) // (MCI) Completion Signal timeout Error flag +#define AT91C_MCI_BLKOVRE (0x1 << 24) // (MCI) DMA Block Overrun Error flag +#define AT91C_MCI_DMADONE (0x1 << 25) // (MCI) DMA Transfer Done flag +#define AT91C_MCI_FIFOEMPTY (0x1 << 26) // (MCI) FIFO Empty flag +#define AT91C_MCI_XFRDONE (0x1 << 27) // (MCI) Transfer Done flag +#define AT91C_MCI_OVRE (0x1 << 30) // (MCI) Overrun flag +#define AT91C_MCI_UNRE (0x1 << 31) // (MCI) Underrun flag +// -------- MCI_IER : (MCI Offset: 0x44) MCI Interrupt Enable Register -------- +// -------- MCI_IDR : (MCI Offset: 0x48) MCI Interrupt Disable Register -------- +// -------- MCI_IMR : (MCI Offset: 0x4c) MCI Interrupt Mask Register -------- +// -------- MCI_DMA : (MCI Offset: 0x50) MCI DMA Configuration Register -------- +#define AT91C_MCI_OFFSET (0x3 << 0) // (MCI) DMA Write Buffer Offset +#define AT91C_MCI_CHKSIZE (0x7 << 4) // (MCI) DMA Channel Read/Write Chunk Size +#define AT91C_MCI_CHKSIZE_1 (0x0 << 4) // (MCI) Number of data transferred is 1 +#define AT91C_MCI_CHKSIZE_4 (0x1 << 4) // (MCI) Number of data transferred is 4 +#define AT91C_MCI_CHKSIZE_8 (0x2 << 4) // (MCI) Number of data transferred is 8 +#define AT91C_MCI_CHKSIZE_16 (0x3 << 4) // (MCI) Number of data transferred is 16 +#define AT91C_MCI_CHKSIZE_32 (0x4 << 4) // (MCI) Number of data transferred is 32 +#define AT91C_MCI_DMAEN (0x1 << 8) // (MCI) DMA Hardware Handshaking Enable +#define AT91C_MCI_DMAEN_DISABLE (0x0 << 8) // (MCI) DMA interface is disabled +#define AT91C_MCI_DMAEN_ENABLE (0x1 << 8) // (MCI) DMA interface is enabled +// -------- MCI_CFG : (MCI Offset: 0x54) MCI Configuration Register -------- +#define AT91C_MCI_FIFOMODE (0x1 << 0) // (MCI) MCI Internal FIFO Control Mode +#define AT91C_MCI_FIFOMODE_AMOUNTDATA (0x0) // (MCI) A write transfer starts when a sufficient amount of datas is written into the FIFO +#define AT91C_MCI_FIFOMODE_ONEDATA (0x1) // (MCI) A write transfer starts as soon as one data is written into the FIFO +#define AT91C_MCI_FERRCTRL (0x1 << 4) // (MCI) Flow Error Flag Reset Control Mode +#define AT91C_MCI_FERRCTRL_RWCMD (0x0 << 4) // (MCI) When an underflow/overflow condition flag is set, a new Write/Read command is needed to reset the flag +#define AT91C_MCI_FERRCTRL_READSR (0x1 << 4) // (MCI) When an underflow/overflow condition flag is set, a read status resets the flag +#define AT91C_MCI_HSMODE (0x1 << 8) // (MCI) High Speed Mode +#define AT91C_MCI_HSMODE_DISABLE (0x0 << 8) // (MCI) Default Bus Timing Mode +#define AT91C_MCI_HSMODE_ENABLE (0x1 << 8) // (MCI) High Speed Mode +#define AT91C_MCI_LSYNC (0x1 << 12) // (MCI) Synchronize on last block +#define AT91C_MCI_LSYNC_CURRENT (0x0 << 12) // (MCI) Pending command sent at end of current data block +#define AT91C_MCI_LSYNC_INFINITE (0x1 << 12) // (MCI) Pending command sent at end of block transfer when transfer length is not infinite +// -------- MCI_WPCR : (MCI Offset: 0xe4) Write Protection Control Register -------- +#define AT91C_MCI_WP_EN (0x1 << 0) // (MCI) Write Protection Enable +#define AT91C_MCI_WP_EN_DISABLE (0x0) // (MCI) Write Operation is disabled (if WP_KEY corresponds) +#define AT91C_MCI_WP_EN_ENABLE (0x1) // (MCI) Write Operation is enabled (if WP_KEY corresponds) +#define AT91C_MCI_WP_KEY (0xFFFFFF << 8) // (MCI) Write Protection Key +// -------- MCI_WPSR : (MCI Offset: 0xe8) Write Protection Status Register -------- +#define AT91C_MCI_WP_VS (0xF << 0) // (MCI) Write Protection Violation Status +#define AT91C_MCI_WP_VS_NO_VIOLATION (0x0) // (MCI) No Write Protection Violation detected since last read +#define AT91C_MCI_WP_VS_ON_WRITE (0x1) // (MCI) Write Protection Violation detected since last read +#define AT91C_MCI_WP_VS_ON_RESET (0x2) // (MCI) Software Reset Violation detected since last read +#define AT91C_MCI_WP_VS_ON_BOTH (0x3) // (MCI) Write Protection and Software Reset Violation detected since last read +#define AT91C_MCI_WP_VSRC (0xF << 8) // (MCI) Write Protection Violation Source +#define AT91C_MCI_WP_VSRC_NO_VIOLATION (0x0 << 8) // (MCI) No Write Protection Violation detected since last read +#define AT91C_MCI_WP_VSRC_MCI_MR (0x1 << 8) // (MCI) Write Protection Violation detected on MCI_MR since last read +#define AT91C_MCI_WP_VSRC_MCI_DTOR (0x2 << 8) // (MCI) Write Protection Violation detected on MCI_DTOR since last read +#define AT91C_MCI_WP_VSRC_MCI_SDCR (0x3 << 8) // (MCI) Write Protection Violation detected on MCI_SDCR since last read +#define AT91C_MCI_WP_VSRC_MCI_CSTOR (0x4 << 8) // (MCI) Write Protection Violation detected on MCI_CSTOR since last read +#define AT91C_MCI_WP_VSRC_MCI_DMA (0x5 << 8) // (MCI) Write Protection Violation detected on MCI_DMA since last read +#define AT91C_MCI_WP_VSRC_MCI_CFG (0x6 << 8) // (MCI) Write Protection Violation detected on MCI_CFG since last read +#define AT91C_MCI_WP_VSRC_MCI_DEL (0x7 << 8) // (MCI) Write Protection Violation detected on MCI_DEL since last read +// -------- MCI_VER : (MCI Offset: 0xfc) VERSION Register -------- +#define AT91C_MCI_VER (0xF << 0) // (MCI) VERSION Register + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Two-wire Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_TWI { + AT91_REG TWI_CR; // Control Register + AT91_REG TWI_MMR; // Master Mode Register + AT91_REG TWI_SMR; // Slave Mode Register + AT91_REG TWI_IADR; // Internal Address Register + AT91_REG TWI_CWGR; // Clock Waveform Generator Register + AT91_REG Reserved0[3]; // + AT91_REG TWI_SR; // Status Register + AT91_REG TWI_IER; // Interrupt Enable Register + AT91_REG TWI_IDR; // Interrupt Disable Register + AT91_REG TWI_IMR; // Interrupt Mask Register + AT91_REG TWI_RHR; // Receive Holding Register + AT91_REG TWI_THR; // Transmit Holding Register + AT91_REG Reserved1[45]; // + AT91_REG TWI_ADDRSIZE; // TWI ADDRSIZE REGISTER + AT91_REG TWI_IPNAME1; // TWI IPNAME1 REGISTER + AT91_REG TWI_IPNAME2; // TWI IPNAME2 REGISTER + AT91_REG TWI_FEATURES; // TWI FEATURES REGISTER + AT91_REG TWI_VER; // Version Register + AT91_REG TWI_RPR; // Receive Pointer Register + AT91_REG TWI_RCR; // Receive Counter Register + AT91_REG TWI_TPR; // Transmit Pointer Register + AT91_REG TWI_TCR; // Transmit Counter Register + AT91_REG TWI_RNPR; // Receive Next Pointer Register + AT91_REG TWI_RNCR; // Receive Next Counter Register + AT91_REG TWI_TNPR; // Transmit Next Pointer Register + AT91_REG TWI_TNCR; // Transmit Next Counter Register + AT91_REG TWI_PTCR; // PDC Transfer Control Register + AT91_REG TWI_PTSR; // PDC Transfer Status Register +} AT91S_TWI, *AT91PS_TWI; +#else +#define TWI_CR (AT91_CAST(AT91_REG *) 0x00000000) // (TWI_CR) Control Register +#define TWI_MMR (AT91_CAST(AT91_REG *) 0x00000004) // (TWI_MMR) Master Mode Register +#define TWI_SMR (AT91_CAST(AT91_REG *) 0x00000008) // (TWI_SMR) Slave Mode Register +#define TWI_IADR (AT91_CAST(AT91_REG *) 0x0000000C) // (TWI_IADR) Internal Address Register +#define TWI_CWGR (AT91_CAST(AT91_REG *) 0x00000010) // (TWI_CWGR) Clock Waveform Generator Register +#define TWI_SR (AT91_CAST(AT91_REG *) 0x00000020) // (TWI_SR) Status Register +#define TWI_IER (AT91_CAST(AT91_REG *) 0x00000024) // (TWI_IER) Interrupt Enable Register +#define TWI_IDR (AT91_CAST(AT91_REG *) 0x00000028) // (TWI_IDR) Interrupt Disable Register +#define TWI_IMR (AT91_CAST(AT91_REG *) 0x0000002C) // (TWI_IMR) Interrupt Mask Register +#define TWI_RHR (AT91_CAST(AT91_REG *) 0x00000030) // (TWI_RHR) Receive Holding Register +#define TWI_THR (AT91_CAST(AT91_REG *) 0x00000034) // (TWI_THR) Transmit Holding Register +#define TWI_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (TWI_ADDRSIZE) TWI ADDRSIZE REGISTER +#define TWI_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (TWI_IPNAME1) TWI IPNAME1 REGISTER +#define TWI_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (TWI_IPNAME2) TWI IPNAME2 REGISTER +#define TWI_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (TWI_FEATURES) TWI FEATURES REGISTER +#define TWI_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (TWI_VER) Version Register + +#endif +// -------- TWI_CR : (TWI Offset: 0x0) TWI Control Register -------- +#define AT91C_TWI_START (0x1 << 0) // (TWI) Send a START Condition +#define AT91C_TWI_STOP (0x1 << 1) // (TWI) Send a STOP Condition +#define AT91C_TWI_MSEN (0x1 << 2) // (TWI) TWI Master Transfer Enabled +#define AT91C_TWI_MSDIS (0x1 << 3) // (TWI) TWI Master Transfer Disabled +#define AT91C_TWI_SVEN (0x1 << 4) // (TWI) TWI Slave mode Enabled +#define AT91C_TWI_SVDIS (0x1 << 5) // (TWI) TWI Slave mode Disabled +#define AT91C_TWI_SWRST (0x1 << 7) // (TWI) Software Reset +// -------- TWI_MMR : (TWI Offset: 0x4) TWI Master Mode Register -------- +#define AT91C_TWI_IADRSZ (0x3 << 8) // (TWI) Internal Device Address Size +#define AT91C_TWI_IADRSZ_NO (0x0 << 8) // (TWI) No internal device address +#define AT91C_TWI_IADRSZ_1_BYTE (0x1 << 8) // (TWI) One-byte internal device address +#define AT91C_TWI_IADRSZ_2_BYTE (0x2 << 8) // (TWI) Two-byte internal device address +#define AT91C_TWI_IADRSZ_3_BYTE (0x3 << 8) // (TWI) Three-byte internal device address +#define AT91C_TWI_MREAD (0x1 << 12) // (TWI) Master Read Direction +#define AT91C_TWI_DADR (0x7F << 16) // (TWI) Device Address +// -------- TWI_SMR : (TWI Offset: 0x8) TWI Slave Mode Register -------- +#define AT91C_TWI_SADR (0x7F << 16) // (TWI) Slave Address +// -------- TWI_CWGR : (TWI Offset: 0x10) TWI Clock Waveform Generator Register -------- +#define AT91C_TWI_CLDIV (0xFF << 0) // (TWI) Clock Low Divider +#define AT91C_TWI_CHDIV (0xFF << 8) // (TWI) Clock High Divider +#define AT91C_TWI_CKDIV (0x7 << 16) // (TWI) Clock Divider +// -------- TWI_SR : (TWI Offset: 0x20) TWI Status Register -------- +#define AT91C_TWI_TXCOMP_SLAVE (0x1 << 0) // (TWI) Transmission Completed +#define AT91C_TWI_TXCOMP_MASTER (0x1 << 0) // (TWI) Transmission Completed +#define AT91C_TWI_RXRDY (0x1 << 1) // (TWI) Receive holding register ReaDY +#define AT91C_TWI_TXRDY_MASTER (0x1 << 2) // (TWI) Transmit holding register ReaDY +#define AT91C_TWI_TXRDY_SLAVE (0x1 << 2) // (TWI) Transmit holding register ReaDY +#define AT91C_TWI_SVREAD (0x1 << 3) // (TWI) Slave READ (used only in Slave mode) +#define AT91C_TWI_SVACC (0x1 << 4) // (TWI) Slave ACCess (used only in Slave mode) +#define AT91C_TWI_GACC (0x1 << 5) // (TWI) General Call ACcess (used only in Slave mode) +#define AT91C_TWI_OVRE (0x1 << 6) // (TWI) Overrun Error (used only in Master and Multi-master mode) +#define AT91C_TWI_NACK_SLAVE (0x1 << 8) // (TWI) Not Acknowledged +#define AT91C_TWI_NACK_MASTER (0x1 << 8) // (TWI) Not Acknowledged +#define AT91C_TWI_ARBLST_MULTI_MASTER (0x1 << 9) // (TWI) Arbitration Lost (used only in Multimaster mode) +#define AT91C_TWI_SCLWS (0x1 << 10) // (TWI) Clock Wait State (used only in Slave mode) +#define AT91C_TWI_EOSACC (0x1 << 11) // (TWI) End Of Slave ACCess (used only in Slave mode) +#define AT91C_TWI_ENDRX (0x1 << 12) // (TWI) End of Receiver Transfer +#define AT91C_TWI_ENDTX (0x1 << 13) // (TWI) End of Receiver Transfer +#define AT91C_TWI_RXBUFF (0x1 << 14) // (TWI) RXBUFF Interrupt +#define AT91C_TWI_TXBUFE (0x1 << 15) // (TWI) TXBUFE Interrupt +// -------- TWI_IER : (TWI Offset: 0x24) TWI Interrupt Enable Register -------- +// -------- TWI_IDR : (TWI Offset: 0x28) TWI Interrupt Disable Register -------- +// -------- TWI_IMR : (TWI Offset: 0x2c) TWI Interrupt Mask Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Usart +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_USART { + AT91_REG US_CR; // Control Register + AT91_REG US_MR; // Mode Register + AT91_REG US_IER; // Interrupt Enable Register + AT91_REG US_IDR; // Interrupt Disable Register + AT91_REG US_IMR; // Interrupt Mask Register + AT91_REG US_CSR; // Channel Status Register + AT91_REG US_RHR; // Receiver Holding Register + AT91_REG US_THR; // Transmitter Holding Register + AT91_REG US_BRGR; // Baud Rate Generator Register + AT91_REG US_RTOR; // Receiver Time-out Register + AT91_REG US_TTGR; // Transmitter Time-guard Register + AT91_REG Reserved0[5]; // + AT91_REG US_FIDI; // FI_DI_Ratio Register + AT91_REG US_NER; // Nb Errors Register + AT91_REG Reserved1[1]; // + AT91_REG US_IF; // IRDA_FILTER Register + AT91_REG US_MAN; // Manchester Encoder Decoder Register + AT91_REG Reserved2[38]; // + AT91_REG US_ADDRSIZE; // US ADDRSIZE REGISTER + AT91_REG US_IPNAME1; // US IPNAME1 REGISTER + AT91_REG US_IPNAME2; // US IPNAME2 REGISTER + AT91_REG US_FEATURES; // US FEATURES REGISTER + AT91_REG US_VER; // VERSION Register + AT91_REG US_RPR; // Receive Pointer Register + AT91_REG US_RCR; // Receive Counter Register + AT91_REG US_TPR; // Transmit Pointer Register + AT91_REG US_TCR; // Transmit Counter Register + AT91_REG US_RNPR; // Receive Next Pointer Register + AT91_REG US_RNCR; // Receive Next Counter Register + AT91_REG US_TNPR; // Transmit Next Pointer Register + AT91_REG US_TNCR; // Transmit Next Counter Register + AT91_REG US_PTCR; // PDC Transfer Control Register + AT91_REG US_PTSR; // PDC Transfer Status Register +} AT91S_USART, *AT91PS_USART; +#else +#define US_CR (AT91_CAST(AT91_REG *) 0x00000000) // (US_CR) Control Register +#define US_MR (AT91_CAST(AT91_REG *) 0x00000004) // (US_MR) Mode Register +#define US_IER (AT91_CAST(AT91_REG *) 0x00000008) // (US_IER) Interrupt Enable Register +#define US_IDR (AT91_CAST(AT91_REG *) 0x0000000C) // (US_IDR) Interrupt Disable Register +#define US_IMR (AT91_CAST(AT91_REG *) 0x00000010) // (US_IMR) Interrupt Mask Register +#define US_CSR (AT91_CAST(AT91_REG *) 0x00000014) // (US_CSR) Channel Status Register +#define US_RHR (AT91_CAST(AT91_REG *) 0x00000018) // (US_RHR) Receiver Holding Register +#define US_THR (AT91_CAST(AT91_REG *) 0x0000001C) // (US_THR) Transmitter Holding Register +#define US_BRGR (AT91_CAST(AT91_REG *) 0x00000020) // (US_BRGR) Baud Rate Generator Register +#define US_RTOR (AT91_CAST(AT91_REG *) 0x00000024) // (US_RTOR) Receiver Time-out Register +#define US_TTGR (AT91_CAST(AT91_REG *) 0x00000028) // (US_TTGR) Transmitter Time-guard Register +#define US_FIDI (AT91_CAST(AT91_REG *) 0x00000040) // (US_FIDI) FI_DI_Ratio Register +#define US_NER (AT91_CAST(AT91_REG *) 0x00000044) // (US_NER) Nb Errors Register +#define US_IF (AT91_CAST(AT91_REG *) 0x0000004C) // (US_IF) IRDA_FILTER Register +#define US_MAN (AT91_CAST(AT91_REG *) 0x00000050) // (US_MAN) Manchester Encoder Decoder Register +#define US_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (US_ADDRSIZE) US ADDRSIZE REGISTER +#define US_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (US_IPNAME1) US IPNAME1 REGISTER +#define US_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (US_IPNAME2) US IPNAME2 REGISTER +#define US_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (US_FEATURES) US FEATURES REGISTER +#define US_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (US_VER) VERSION Register + +#endif +// -------- US_CR : (USART Offset: 0x0) Control Register -------- +#define AT91C_US_STTBRK (0x1 << 9) // (USART) Start Break +#define AT91C_US_STPBRK (0x1 << 10) // (USART) Stop Break +#define AT91C_US_STTTO (0x1 << 11) // (USART) Start Time-out +#define AT91C_US_SENDA (0x1 << 12) // (USART) Send Address +#define AT91C_US_RSTIT (0x1 << 13) // (USART) Reset Iterations +#define AT91C_US_RSTNACK (0x1 << 14) // (USART) Reset Non Acknowledge +#define AT91C_US_RETTO (0x1 << 15) // (USART) Rearm Time-out +#define AT91C_US_DTREN (0x1 << 16) // (USART) Data Terminal ready Enable +#define AT91C_US_DTRDIS (0x1 << 17) // (USART) Data Terminal ready Disable +#define AT91C_US_RTSEN (0x1 << 18) // (USART) Request to Send enable +#define AT91C_US_RTSDIS (0x1 << 19) // (USART) Request to Send Disable +// -------- US_MR : (USART Offset: 0x4) Mode Register -------- +#define AT91C_US_USMODE (0xF << 0) // (USART) Usart mode +#define AT91C_US_USMODE_NORMAL (0x0) // (USART) Normal +#define AT91C_US_USMODE_RS485 (0x1) // (USART) RS485 +#define AT91C_US_USMODE_HWHSH (0x2) // (USART) Hardware Handshaking +#define AT91C_US_USMODE_MODEM (0x3) // (USART) Modem +#define AT91C_US_USMODE_ISO7816_0 (0x4) // (USART) ISO7816 protocol: T = 0 +#define AT91C_US_USMODE_ISO7816_1 (0x6) // (USART) ISO7816 protocol: T = 1 +#define AT91C_US_USMODE_IRDA (0x8) // (USART) IrDA +#define AT91C_US_USMODE_SWHSH (0xC) // (USART) Software Handshaking +#define AT91C_US_CLKS (0x3 << 4) // (USART) Clock Selection (Baud Rate generator Input Clock +#define AT91C_US_CLKS_CLOCK (0x0 << 4) // (USART) Clock +#define AT91C_US_CLKS_FDIV1 (0x1 << 4) // (USART) fdiv1 +#define AT91C_US_CLKS_SLOW (0x2 << 4) // (USART) slow_clock (ARM) +#define AT91C_US_CLKS_EXT (0x3 << 4) // (USART) External (SCK) +#define AT91C_US_CHRL (0x3 << 6) // (USART) Clock Selection (Baud Rate generator Input Clock +#define AT91C_US_CHRL_5_BITS (0x0 << 6) // (USART) Character Length: 5 bits +#define AT91C_US_CHRL_6_BITS (0x1 << 6) // (USART) Character Length: 6 bits +#define AT91C_US_CHRL_7_BITS (0x2 << 6) // (USART) Character Length: 7 bits +#define AT91C_US_CHRL_8_BITS (0x3 << 6) // (USART) Character Length: 8 bits +#define AT91C_US_SYNC (0x1 << 8) // (USART) Synchronous Mode Select +#define AT91C_US_NBSTOP (0x3 << 12) // (USART) Number of Stop bits +#define AT91C_US_NBSTOP_1_BIT (0x0 << 12) // (USART) 1 stop bit +#define AT91C_US_NBSTOP_15_BIT (0x1 << 12) // (USART) Asynchronous (SYNC=0) 2 stop bits Synchronous (SYNC=1) 2 stop bits +#define AT91C_US_NBSTOP_2_BIT (0x2 << 12) // (USART) 2 stop bits +#define AT91C_US_MSBF (0x1 << 16) // (USART) Bit Order +#define AT91C_US_MODE9 (0x1 << 17) // (USART) 9-bit Character length +#define AT91C_US_CKLO (0x1 << 18) // (USART) Clock Output Select +#define AT91C_US_OVER (0x1 << 19) // (USART) Over Sampling Mode +#define AT91C_US_INACK (0x1 << 20) // (USART) Inhibit Non Acknowledge +#define AT91C_US_DSNACK (0x1 << 21) // (USART) Disable Successive NACK +#define AT91C_US_VAR_SYNC (0x1 << 22) // (USART) Variable synchronization of command/data sync Start Frame Delimiter +#define AT91C_US_MAX_ITER (0x1 << 24) // (USART) Number of Repetitions +#define AT91C_US_FILTER (0x1 << 28) // (USART) Receive Line Filter +#define AT91C_US_MANMODE (0x1 << 29) // (USART) Manchester Encoder/Decoder Enable +#define AT91C_US_MODSYNC (0x1 << 30) // (USART) Manchester Synchronization mode +#define AT91C_US_ONEBIT (0x1 << 31) // (USART) Start Frame Delimiter selector +// -------- US_IER : (USART Offset: 0x8) Interrupt Enable Register -------- +#define AT91C_US_RXBRK (0x1 << 2) // (USART) Break Received/End of Break +#define AT91C_US_TIMEOUT (0x1 << 8) // (USART) Receiver Time-out +#define AT91C_US_ITERATION (0x1 << 10) // (USART) Max number of Repetitions Reached +#define AT91C_US_NACK (0x1 << 13) // (USART) Non Acknowledge +#define AT91C_US_RIIC (0x1 << 16) // (USART) Ring INdicator Input Change Flag +#define AT91C_US_DSRIC (0x1 << 17) // (USART) Data Set Ready Input Change Flag +#define AT91C_US_DCDIC (0x1 << 18) // (USART) Data Carrier Flag +#define AT91C_US_CTSIC (0x1 << 19) // (USART) Clear To Send Input Change Flag +#define AT91C_US_MANE (0x1 << 20) // (USART) Manchester Error Interrupt +// -------- US_IDR : (USART Offset: 0xc) Interrupt Disable Register -------- +// -------- US_IMR : (USART Offset: 0x10) Interrupt Mask Register -------- +// -------- US_CSR : (USART Offset: 0x14) Channel Status Register -------- +#define AT91C_US_RI (0x1 << 20) // (USART) Image of RI Input +#define AT91C_US_DSR (0x1 << 21) // (USART) Image of DSR Input +#define AT91C_US_DCD (0x1 << 22) // (USART) Image of DCD Input +#define AT91C_US_CTS (0x1 << 23) // (USART) Image of CTS Input +#define AT91C_US_MANERR (0x1 << 24) // (USART) Manchester Error +// -------- US_MAN : (USART Offset: 0x50) Manchester Encoder Decoder Register -------- +#define AT91C_US_TX_PL (0xF << 0) // (USART) Transmitter Preamble Length +#define AT91C_US_TX_PP (0x3 << 8) // (USART) Transmitter Preamble Pattern +#define AT91C_US_TX_PP_ALL_ONE (0x0 << 8) // (USART) ALL_ONE +#define AT91C_US_TX_PP_ALL_ZERO (0x1 << 8) // (USART) ALL_ZERO +#define AT91C_US_TX_PP_ZERO_ONE (0x2 << 8) // (USART) ZERO_ONE +#define AT91C_US_TX_PP_ONE_ZERO (0x3 << 8) // (USART) ONE_ZERO +#define AT91C_US_TX_MPOL (0x1 << 12) // (USART) Transmitter Manchester Polarity +#define AT91C_US_RX_PL (0xF << 16) // (USART) Receiver Preamble Length +#define AT91C_US_RX_PP (0x3 << 24) // (USART) Receiver Preamble Pattern detected +#define AT91C_US_RX_PP_ALL_ONE (0x0 << 24) // (USART) ALL_ONE +#define AT91C_US_RX_PP_ALL_ZERO (0x1 << 24) // (USART) ALL_ZERO +#define AT91C_US_RX_PP_ZERO_ONE (0x2 << 24) // (USART) ZERO_ONE +#define AT91C_US_RX_PP_ONE_ZERO (0x3 << 24) // (USART) ONE_ZERO +#define AT91C_US_RX_MPOL (0x1 << 28) // (USART) Receiver Manchester Polarity +#define AT91C_US_DRIFT (0x1 << 30) // (USART) Drift compensation + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Synchronous Serial Controller Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_SSC { + AT91_REG SSC_CR; // Control Register + AT91_REG SSC_CMR; // Clock Mode Register + AT91_REG Reserved0[2]; // + AT91_REG SSC_RCMR; // Receive Clock ModeRegister + AT91_REG SSC_RFMR; // Receive Frame Mode Register + AT91_REG SSC_TCMR; // Transmit Clock Mode Register + AT91_REG SSC_TFMR; // Transmit Frame Mode Register + AT91_REG SSC_RHR; // Receive Holding Register + AT91_REG SSC_THR; // Transmit Holding Register + AT91_REG Reserved1[2]; // + AT91_REG SSC_RSHR; // Receive Sync Holding Register + AT91_REG SSC_TSHR; // Transmit Sync Holding Register + AT91_REG Reserved2[2]; // + AT91_REG SSC_SR; // Status Register + AT91_REG SSC_IER; // Interrupt Enable Register + AT91_REG SSC_IDR; // Interrupt Disable Register + AT91_REG SSC_IMR; // Interrupt Mask Register + AT91_REG Reserved3[39]; // + AT91_REG SSC_ADDRSIZE; // SSC ADDRSIZE REGISTER + AT91_REG SSC_IPNAME1; // SSC IPNAME1 REGISTER + AT91_REG SSC_IPNAME2; // SSC IPNAME2 REGISTER + AT91_REG SSC_FEATURES; // SSC FEATURES REGISTER + AT91_REG SSC_VER; // Version Register + AT91_REG SSC_RPR; // Receive Pointer Register + AT91_REG SSC_RCR; // Receive Counter Register + AT91_REG SSC_TPR; // Transmit Pointer Register + AT91_REG SSC_TCR; // Transmit Counter Register + AT91_REG SSC_RNPR; // Receive Next Pointer Register + AT91_REG SSC_RNCR; // Receive Next Counter Register + AT91_REG SSC_TNPR; // Transmit Next Pointer Register + AT91_REG SSC_TNCR; // Transmit Next Counter Register + AT91_REG SSC_PTCR; // PDC Transfer Control Register + AT91_REG SSC_PTSR; // PDC Transfer Status Register +} AT91S_SSC, *AT91PS_SSC; +#else +#define SSC_CR (AT91_CAST(AT91_REG *) 0x00000000) // (SSC_CR) Control Register +#define SSC_CMR (AT91_CAST(AT91_REG *) 0x00000004) // (SSC_CMR) Clock Mode Register +#define SSC_RCMR (AT91_CAST(AT91_REG *) 0x00000010) // (SSC_RCMR) Receive Clock ModeRegister +#define SSC_RFMR (AT91_CAST(AT91_REG *) 0x00000014) // (SSC_RFMR) Receive Frame Mode Register +#define SSC_TCMR (AT91_CAST(AT91_REG *) 0x00000018) // (SSC_TCMR) Transmit Clock Mode Register +#define SSC_TFMR (AT91_CAST(AT91_REG *) 0x0000001C) // (SSC_TFMR) Transmit Frame Mode Register +#define SSC_RHR (AT91_CAST(AT91_REG *) 0x00000020) // (SSC_RHR) Receive Holding Register +#define SSC_THR (AT91_CAST(AT91_REG *) 0x00000024) // (SSC_THR) Transmit Holding Register +#define SSC_RSHR (AT91_CAST(AT91_REG *) 0x00000030) // (SSC_RSHR) Receive Sync Holding Register +#define SSC_TSHR (AT91_CAST(AT91_REG *) 0x00000034) // (SSC_TSHR) Transmit Sync Holding Register +#define SSC_SR (AT91_CAST(AT91_REG *) 0x00000040) // (SSC_SR) Status Register +#define SSC_IER (AT91_CAST(AT91_REG *) 0x00000044) // (SSC_IER) Interrupt Enable Register +#define SSC_IDR (AT91_CAST(AT91_REG *) 0x00000048) // (SSC_IDR) Interrupt Disable Register +#define SSC_IMR (AT91_CAST(AT91_REG *) 0x0000004C) // (SSC_IMR) Interrupt Mask Register +#define SSC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (SSC_ADDRSIZE) SSC ADDRSIZE REGISTER +#define SSC_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (SSC_IPNAME1) SSC IPNAME1 REGISTER +#define SSC_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (SSC_IPNAME2) SSC IPNAME2 REGISTER +#define SSC_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (SSC_FEATURES) SSC FEATURES REGISTER +#define SSC_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (SSC_VER) Version Register + +#endif +// -------- SSC_CR : (SSC Offset: 0x0) SSC Control Register -------- +#define AT91C_SSC_RXEN (0x1 << 0) // (SSC) Receive Enable +#define AT91C_SSC_RXDIS (0x1 << 1) // (SSC) Receive Disable +#define AT91C_SSC_TXEN (0x1 << 8) // (SSC) Transmit Enable +#define AT91C_SSC_TXDIS (0x1 << 9) // (SSC) Transmit Disable +#define AT91C_SSC_SWRST (0x1 << 15) // (SSC) Software Reset +// -------- SSC_RCMR : (SSC Offset: 0x10) SSC Receive Clock Mode Register -------- +#define AT91C_SSC_CKS (0x3 << 0) // (SSC) Receive/Transmit Clock Selection +#define AT91C_SSC_CKS_DIV (0x0) // (SSC) Divided Clock +#define AT91C_SSC_CKS_TK (0x1) // (SSC) TK Clock signal +#define AT91C_SSC_CKS_RK (0x2) // (SSC) RK pin +#define AT91C_SSC_CKO (0x7 << 2) // (SSC) Receive/Transmit Clock Output Mode Selection +#define AT91C_SSC_CKO_NONE (0x0 << 2) // (SSC) Receive/Transmit Clock Output Mode: None RK pin: Input-only +#define AT91C_SSC_CKO_CONTINOUS (0x1 << 2) // (SSC) Continuous Receive/Transmit Clock RK pin: Output +#define AT91C_SSC_CKO_DATA_TX (0x2 << 2) // (SSC) Receive/Transmit Clock only during data transfers RK pin: Output +#define AT91C_SSC_CKI (0x1 << 5) // (SSC) Receive/Transmit Clock Inversion +#define AT91C_SSC_CKG (0x3 << 6) // (SSC) Receive/Transmit Clock Gating Selection +#define AT91C_SSC_CKG_NONE (0x0 << 6) // (SSC) Receive/Transmit Clock Gating: None, continuous clock +#define AT91C_SSC_CKG_LOW (0x1 << 6) // (SSC) Receive/Transmit Clock enabled only if RF Low +#define AT91C_SSC_CKG_HIGH (0x2 << 6) // (SSC) Receive/Transmit Clock enabled only if RF High +#define AT91C_SSC_START (0xF << 8) // (SSC) Receive/Transmit Start Selection +#define AT91C_SSC_START_CONTINOUS (0x0 << 8) // (SSC) Continuous, as soon as the receiver is enabled, and immediately after the end of transfer of the previous data. +#define AT91C_SSC_START_TX (0x1 << 8) // (SSC) Transmit/Receive start +#define AT91C_SSC_START_LOW_RF (0x2 << 8) // (SSC) Detection of a low level on RF input +#define AT91C_SSC_START_HIGH_RF (0x3 << 8) // (SSC) Detection of a high level on RF input +#define AT91C_SSC_START_FALL_RF (0x4 << 8) // (SSC) Detection of a falling edge on RF input +#define AT91C_SSC_START_RISE_RF (0x5 << 8) // (SSC) Detection of a rising edge on RF input +#define AT91C_SSC_START_LEVEL_RF (0x6 << 8) // (SSC) Detection of any level change on RF input +#define AT91C_SSC_START_EDGE_RF (0x7 << 8) // (SSC) Detection of any edge on RF input +#define AT91C_SSC_START_0 (0x8 << 8) // (SSC) Compare 0 +#define AT91C_SSC_STOP (0x1 << 12) // (SSC) Receive Stop Selection +#define AT91C_SSC_STTDLY (0xFF << 16) // (SSC) Receive/Transmit Start Delay +#define AT91C_SSC_PERIOD (0xFF << 24) // (SSC) Receive/Transmit Period Divider Selection +// -------- SSC_RFMR : (SSC Offset: 0x14) SSC Receive Frame Mode Register -------- +#define AT91C_SSC_DATLEN (0x1F << 0) // (SSC) Data Length +#define AT91C_SSC_LOOP (0x1 << 5) // (SSC) Loop Mode +#define AT91C_SSC_MSBF (0x1 << 7) // (SSC) Most Significant Bit First +#define AT91C_SSC_DATNB (0xF << 8) // (SSC) Data Number per Frame +#define AT91C_SSC_FSLEN (0xF << 16) // (SSC) Receive/Transmit Frame Sync length +#define AT91C_SSC_FSOS (0x7 << 20) // (SSC) Receive/Transmit Frame Sync Output Selection +#define AT91C_SSC_FSOS_NONE (0x0 << 20) // (SSC) Selected Receive/Transmit Frame Sync Signal: None RK pin Input-only +#define AT91C_SSC_FSOS_NEGATIVE (0x1 << 20) // (SSC) Selected Receive/Transmit Frame Sync Signal: Negative Pulse +#define AT91C_SSC_FSOS_POSITIVE (0x2 << 20) // (SSC) Selected Receive/Transmit Frame Sync Signal: Positive Pulse +#define AT91C_SSC_FSOS_LOW (0x3 << 20) // (SSC) Selected Receive/Transmit Frame Sync Signal: Driver Low during data transfer +#define AT91C_SSC_FSOS_HIGH (0x4 << 20) // (SSC) Selected Receive/Transmit Frame Sync Signal: Driver High during data transfer +#define AT91C_SSC_FSOS_TOGGLE (0x5 << 20) // (SSC) Selected Receive/Transmit Frame Sync Signal: Toggling at each start of data transfer +#define AT91C_SSC_FSEDGE (0x1 << 24) // (SSC) Frame Sync Edge Detection +// -------- SSC_TCMR : (SSC Offset: 0x18) SSC Transmit Clock Mode Register -------- +// -------- SSC_TFMR : (SSC Offset: 0x1c) SSC Transmit Frame Mode Register -------- +#define AT91C_SSC_DATDEF (0x1 << 5) // (SSC) Data Default Value +#define AT91C_SSC_FSDEN (0x1 << 23) // (SSC) Frame Sync Data Enable +// -------- SSC_SR : (SSC Offset: 0x40) SSC Status Register -------- +#define AT91C_SSC_TXRDY (0x1 << 0) // (SSC) Transmit Ready +#define AT91C_SSC_TXEMPTY (0x1 << 1) // (SSC) Transmit Empty +#define AT91C_SSC_ENDTX (0x1 << 2) // (SSC) End Of Transmission +#define AT91C_SSC_TXBUFE (0x1 << 3) // (SSC) Transmit Buffer Empty +#define AT91C_SSC_RXRDY (0x1 << 4) // (SSC) Receive Ready +#define AT91C_SSC_OVRUN (0x1 << 5) // (SSC) Receive Overrun +#define AT91C_SSC_ENDRX (0x1 << 6) // (SSC) End of Reception +#define AT91C_SSC_RXBUFF (0x1 << 7) // (SSC) Receive Buffer Full +#define AT91C_SSC_CP0 (0x1 << 8) // (SSC) Compare 0 +#define AT91C_SSC_CP1 (0x1 << 9) // (SSC) Compare 1 +#define AT91C_SSC_TXSYN (0x1 << 10) // (SSC) Transmit Sync +#define AT91C_SSC_RXSYN (0x1 << 11) // (SSC) Receive Sync +#define AT91C_SSC_TXENA (0x1 << 16) // (SSC) Transmit Enable +#define AT91C_SSC_RXENA (0x1 << 17) // (SSC) Receive Enable +// -------- SSC_IER : (SSC Offset: 0x44) SSC Interrupt Enable Register -------- +// -------- SSC_IDR : (SSC Offset: 0x48) SSC Interrupt Disable Register -------- +// -------- SSC_IMR : (SSC Offset: 0x4c) SSC Interrupt Mask Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR PWMC Channel Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_PWMC_CH { + AT91_REG PWMC_CMR; // Channel Mode Register + AT91_REG PWMC_CDTYR; // Channel Duty Cycle Register + AT91_REG PWMC_CDTYUPDR; // Channel Duty Cycle Update Register + AT91_REG PWMC_CPRDR; // Channel Period Register + AT91_REG PWMC_CPRDUPDR; // Channel Period Update Register + AT91_REG PWMC_CCNTR; // Channel Counter Register + AT91_REG PWMC_DTR; // Channel Dead Time Value Register + AT91_REG PWMC_DTUPDR; // Channel Dead Time Update Value Register +} AT91S_PWMC_CH, *AT91PS_PWMC_CH; +#else +#define PWMC_CMR (AT91_CAST(AT91_REG *) 0x00000000) // (PWMC_CMR) Channel Mode Register +#define PWMC_CDTYR (AT91_CAST(AT91_REG *) 0x00000004) // (PWMC_CDTYR) Channel Duty Cycle Register +#define PWMC_CDTYUPDR (AT91_CAST(AT91_REG *) 0x00000008) // (PWMC_CDTYUPDR) Channel Duty Cycle Update Register +#define PWMC_CPRDR (AT91_CAST(AT91_REG *) 0x0000000C) // (PWMC_CPRDR) Channel Period Register +#define PWMC_CPRDUPDR (AT91_CAST(AT91_REG *) 0x00000010) // (PWMC_CPRDUPDR) Channel Period Update Register +#define PWMC_CCNTR (AT91_CAST(AT91_REG *) 0x00000014) // (PWMC_CCNTR) Channel Counter Register +#define PWMC_DTR (AT91_CAST(AT91_REG *) 0x00000018) // (PWMC_DTR) Channel Dead Time Value Register +#define PWMC_DTUPDR (AT91_CAST(AT91_REG *) 0x0000001C) // (PWMC_DTUPDR) Channel Dead Time Update Value Register + +#endif +// -------- PWMC_CMR : (PWMC_CH Offset: 0x0) PWMC Channel Mode Register -------- +#define AT91C_PWMC_CPRE (0xF << 0) // (PWMC_CH) Channel Pre-scaler : PWMC_CLKx +#define AT91C_PWMC_CPRE_MCK (0x0) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_2 (0x1) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_4 (0x2) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_8 (0x3) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_16 (0x4) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_32 (0x5) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_64 (0x6) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_128 (0x7) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_256 (0x8) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_512 (0x9) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCK_DIV_1024 (0xA) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCKA (0xB) // (PWMC_CH) +#define AT91C_PWMC_CPRE_MCKB (0xC) // (PWMC_CH) +#define AT91C_PWMC_CALG (0x1 << 8) // (PWMC_CH) Channel Alignment +#define AT91C_PWMC_CPOL (0x1 << 9) // (PWMC_CH) Channel Polarity +#define AT91C_PWMC_CES (0x1 << 10) // (PWMC_CH) Counter Event Selection +#define AT91C_PWMC_DTE (0x1 << 16) // (PWMC_CH) Dead Time Genrator Enable +#define AT91C_PWMC_DTHI (0x1 << 17) // (PWMC_CH) Dead Time PWMHx Output Inverted +#define AT91C_PWMC_DTLI (0x1 << 18) // (PWMC_CH) Dead Time PWMLx Output Inverted +// -------- PWMC_CDTYR : (PWMC_CH Offset: 0x4) PWMC Channel Duty Cycle Register -------- +#define AT91C_PWMC_CDTY (0xFFFFFF << 0) // (PWMC_CH) Channel Duty Cycle +// -------- PWMC_CDTYUPDR : (PWMC_CH Offset: 0x8) PWMC Channel Duty Cycle Update Register -------- +#define AT91C_PWMC_CDTYUPD (0xFFFFFF << 0) // (PWMC_CH) Channel Duty Cycle Update +// -------- PWMC_CPRDR : (PWMC_CH Offset: 0xc) PWMC Channel Period Register -------- +#define AT91C_PWMC_CPRD (0xFFFFFF << 0) // (PWMC_CH) Channel Period +// -------- PWMC_CPRDUPDR : (PWMC_CH Offset: 0x10) PWMC Channel Period Update Register -------- +#define AT91C_PWMC_CPRDUPD (0xFFFFFF << 0) // (PWMC_CH) Channel Period Update +// -------- PWMC_CCNTR : (PWMC_CH Offset: 0x14) PWMC Channel Counter Register -------- +#define AT91C_PWMC_CCNT (0xFFFFFF << 0) // (PWMC_CH) Channel Counter +// -------- PWMC_DTR : (PWMC_CH Offset: 0x18) Channel Dead Time Value Register -------- +#define AT91C_PWMC_DTL (0xFFFF << 0) // (PWMC_CH) Channel Dead Time for PWML +#define AT91C_PWMC_DTH (0xFFFF << 16) // (PWMC_CH) Channel Dead Time for PWMH +// -------- PWMC_DTUPDR : (PWMC_CH Offset: 0x1c) Channel Dead Time Value Register -------- +#define AT91C_PWMC_DTLUPD (0xFFFF << 0) // (PWMC_CH) Channel Dead Time Update for PWML. +#define AT91C_PWMC_DTHUPD (0xFFFF << 16) // (PWMC_CH) Channel Dead Time Update for PWMH. + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Pulse Width Modulation Controller Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_PWMC { + AT91_REG PWMC_MR; // PWMC Mode Register + AT91_REG PWMC_ENA; // PWMC Enable Register + AT91_REG PWMC_DIS; // PWMC Disable Register + AT91_REG PWMC_SR; // PWMC Status Register + AT91_REG PWMC_IER1; // PWMC Interrupt Enable Register 1 + AT91_REG PWMC_IDR1; // PWMC Interrupt Disable Register 1 + AT91_REG PWMC_IMR1; // PWMC Interrupt Mask Register 1 + AT91_REG PWMC_ISR1; // PWMC Interrupt Status Register 1 + AT91_REG PWMC_SYNC; // PWM Synchronized Channels Register + AT91_REG Reserved0[1]; // + AT91_REG PWMC_UPCR; // PWM Update Control Register + AT91_REG PWMC_SCUP; // PWM Update Period Register + AT91_REG PWMC_SCUPUPD; // PWM Update Period Update Register + AT91_REG PWMC_IER2; // PWMC Interrupt Enable Register 2 + AT91_REG PWMC_IDR2; // PWMC Interrupt Disable Register 2 + AT91_REG PWMC_IMR2; // PWMC Interrupt Mask Register 2 + AT91_REG PWMC_ISR2; // PWMC Interrupt Status Register 2 + AT91_REG PWMC_OOV; // PWM Output Override Value Register + AT91_REG PWMC_OS; // PWM Output Selection Register + AT91_REG PWMC_OSS; // PWM Output Selection Set Register + AT91_REG PWMC_OSC; // PWM Output Selection Clear Register + AT91_REG PWMC_OSSUPD; // PWM Output Selection Set Update Register + AT91_REG PWMC_OSCUPD; // PWM Output Selection Clear Update Register + AT91_REG PWMC_FMR; // PWM Fault Mode Register + AT91_REG PWMC_FSR; // PWM Fault Mode Status Register + AT91_REG PWMC_FCR; // PWM Fault Mode Clear Register + AT91_REG PWMC_FPV; // PWM Fault Protection Value Register + AT91_REG PWMC_FPER1; // PWM Fault Protection Enable Register 1 + AT91_REG PWMC_FPER2; // PWM Fault Protection Enable Register 2 + AT91_REG PWMC_FPER3; // PWM Fault Protection Enable Register 3 + AT91_REG PWMC_FPER4; // PWM Fault Protection Enable Register 4 + AT91_REG PWMC_EL0MR; // PWM Event Line 0 Mode Register + AT91_REG PWMC_EL1MR; // PWM Event Line 1 Mode Register + AT91_REG PWMC_EL2MR; // PWM Event Line 2 Mode Register + AT91_REG PWMC_EL3MR; // PWM Event Line 3 Mode Register + AT91_REG PWMC_EL4MR; // PWM Event Line 4 Mode Register + AT91_REG PWMC_EL5MR; // PWM Event Line 5 Mode Register + AT91_REG PWMC_EL6MR; // PWM Event Line 6 Mode Register + AT91_REG PWMC_EL7MR; // PWM Event Line 7 Mode Register + AT91_REG Reserved1[18]; // + AT91_REG PWMC_WPCR; // PWM Write Protection Enable Register + AT91_REG PWMC_WPSR; // PWM Write Protection Status Register + AT91_REG PWMC_ADDRSIZE; // PWMC ADDRSIZE REGISTER + AT91_REG PWMC_IPNAME1; // PWMC IPNAME1 REGISTER + AT91_REG PWMC_IPNAME2; // PWMC IPNAME2 REGISTER + AT91_REG PWMC_FEATURES; // PWMC FEATURES REGISTER + AT91_REG PWMC_VER; // PWMC Version Register + AT91_REG PWMC_RPR; // Receive Pointer Register + AT91_REG PWMC_RCR; // Receive Counter Register + AT91_REG PWMC_TPR; // Transmit Pointer Register + AT91_REG PWMC_TCR; // Transmit Counter Register + AT91_REG PWMC_RNPR; // Receive Next Pointer Register + AT91_REG PWMC_RNCR; // Receive Next Counter Register + AT91_REG PWMC_TNPR; // Transmit Next Pointer Register + AT91_REG PWMC_TNCR; // Transmit Next Counter Register + AT91_REG PWMC_PTCR; // PDC Transfer Control Register + AT91_REG PWMC_PTSR; // PDC Transfer Status Register + AT91_REG Reserved2[2]; // + AT91_REG PWMC_CMP0V; // PWM Comparison Value 0 Register + AT91_REG PWMC_CMP0VUPD; // PWM Comparison Value 0 Update Register + AT91_REG PWMC_CMP0M; // PWM Comparison Mode 0 Register + AT91_REG PWMC_CMP0MUPD; // PWM Comparison Mode 0 Update Register + AT91_REG PWMC_CMP1V; // PWM Comparison Value 1 Register + AT91_REG PWMC_CMP1VUPD; // PWM Comparison Value 1 Update Register + AT91_REG PWMC_CMP1M; // PWM Comparison Mode 1 Register + AT91_REG PWMC_CMP1MUPD; // PWM Comparison Mode 1 Update Register + AT91_REG PWMC_CMP2V; // PWM Comparison Value 2 Register + AT91_REG PWMC_CMP2VUPD; // PWM Comparison Value 2 Update Register + AT91_REG PWMC_CMP2M; // PWM Comparison Mode 2 Register + AT91_REG PWMC_CMP2MUPD; // PWM Comparison Mode 2 Update Register + AT91_REG PWMC_CMP3V; // PWM Comparison Value 3 Register + AT91_REG PWMC_CMP3VUPD; // PWM Comparison Value 3 Update Register + AT91_REG PWMC_CMP3M; // PWM Comparison Mode 3 Register + AT91_REG PWMC_CMP3MUPD; // PWM Comparison Mode 3 Update Register + AT91_REG PWMC_CMP4V; // PWM Comparison Value 4 Register + AT91_REG PWMC_CMP4VUPD; // PWM Comparison Value 4 Update Register + AT91_REG PWMC_CMP4M; // PWM Comparison Mode 4 Register + AT91_REG PWMC_CMP4MUPD; // PWM Comparison Mode 4 Update Register + AT91_REG PWMC_CMP5V; // PWM Comparison Value 5 Register + AT91_REG PWMC_CMP5VUPD; // PWM Comparison Value 5 Update Register + AT91_REG PWMC_CMP5M; // PWM Comparison Mode 5 Register + AT91_REG PWMC_CMP5MUPD; // PWM Comparison Mode 5 Update Register + AT91_REG PWMC_CMP6V; // PWM Comparison Value 6 Register + AT91_REG PWMC_CMP6VUPD; // PWM Comparison Value 6 Update Register + AT91_REG PWMC_CMP6M; // PWM Comparison Mode 6 Register + AT91_REG PWMC_CMP6MUPD; // PWM Comparison Mode 6 Update Register + AT91_REG PWMC_CMP7V; // PWM Comparison Value 7 Register + AT91_REG PWMC_CMP7VUPD; // PWM Comparison Value 7 Update Register + AT91_REG PWMC_CMP7M; // PWM Comparison Mode 7 Register + AT91_REG PWMC_CMP7MUPD; // PWM Comparison Mode 7 Update Register + AT91_REG Reserved3[20]; // + AT91S_PWMC_CH PWMC_CH[8]; // PWMC Channel 0 +} AT91S_PWMC, *AT91PS_PWMC; +#else +#define PWMC_MR (AT91_CAST(AT91_REG *) 0x00000000) // (PWMC_MR) PWMC Mode Register +#define PWMC_ENA (AT91_CAST(AT91_REG *) 0x00000004) // (PWMC_ENA) PWMC Enable Register +#define PWMC_DIS (AT91_CAST(AT91_REG *) 0x00000008) // (PWMC_DIS) PWMC Disable Register +#define PWMC_SR (AT91_CAST(AT91_REG *) 0x0000000C) // (PWMC_SR) PWMC Status Register +#define PWMC_IER1 (AT91_CAST(AT91_REG *) 0x00000010) // (PWMC_IER1) PWMC Interrupt Enable Register 1 +#define PWMC_IDR1 (AT91_CAST(AT91_REG *) 0x00000014) // (PWMC_IDR1) PWMC Interrupt Disable Register 1 +#define PWMC_IMR1 (AT91_CAST(AT91_REG *) 0x00000018) // (PWMC_IMR1) PWMC Interrupt Mask Register 1 +#define PWMC_ISR1 (AT91_CAST(AT91_REG *) 0x0000001C) // (PWMC_ISR1) PWMC Interrupt Status Register 1 +#define PWMC_SYNC (AT91_CAST(AT91_REG *) 0x00000020) // (PWMC_SYNC) PWM Synchronized Channels Register +#define PWMC_UPCR (AT91_CAST(AT91_REG *) 0x00000028) // (PWMC_UPCR) PWM Update Control Register +#define PWMC_SCUP (AT91_CAST(AT91_REG *) 0x0000002C) // (PWMC_SCUP) PWM Update Period Register +#define PWMC_SCUPUPD (AT91_CAST(AT91_REG *) 0x00000030) // (PWMC_SCUPUPD) PWM Update Period Update Register +#define PWMC_IER2 (AT91_CAST(AT91_REG *) 0x00000034) // (PWMC_IER2) PWMC Interrupt Enable Register 2 +#define PWMC_IDR2 (AT91_CAST(AT91_REG *) 0x00000038) // (PWMC_IDR2) PWMC Interrupt Disable Register 2 +#define PWMC_IMR2 (AT91_CAST(AT91_REG *) 0x0000003C) // (PWMC_IMR2) PWMC Interrupt Mask Register 2 +#define PWMC_ISR2 (AT91_CAST(AT91_REG *) 0x00000040) // (PWMC_ISR2) PWMC Interrupt Status Register 2 +#define PWMC_OOV (AT91_CAST(AT91_REG *) 0x00000044) // (PWMC_OOV) PWM Output Override Value Register +#define PWMC_OS (AT91_CAST(AT91_REG *) 0x00000048) // (PWMC_OS) PWM Output Selection Register +#define PWMC_OSS (AT91_CAST(AT91_REG *) 0x0000004C) // (PWMC_OSS) PWM Output Selection Set Register +#define PWMC_OSC (AT91_CAST(AT91_REG *) 0x00000050) // (PWMC_OSC) PWM Output Selection Clear Register +#define PWMC_OSSUPD (AT91_CAST(AT91_REG *) 0x00000054) // (PWMC_OSSUPD) PWM Output Selection Set Update Register +#define PWMC_OSCUPD (AT91_CAST(AT91_REG *) 0x00000058) // (PWMC_OSCUPD) PWM Output Selection Clear Update Register +#define PWMC_FMR (AT91_CAST(AT91_REG *) 0x0000005C) // (PWMC_FMR) PWM Fault Mode Register +#define PWMC_FSR (AT91_CAST(AT91_REG *) 0x00000060) // (PWMC_FSR) PWM Fault Mode Status Register +#define PWMC_FCR (AT91_CAST(AT91_REG *) 0x00000064) // (PWMC_FCR) PWM Fault Mode Clear Register +#define PWMC_FPV (AT91_CAST(AT91_REG *) 0x00000068) // (PWMC_FPV) PWM Fault Protection Value Register +#define PWMC_FPER1 (AT91_CAST(AT91_REG *) 0x0000006C) // (PWMC_FPER1) PWM Fault Protection Enable Register 1 +#define PWMC_FPER2 (AT91_CAST(AT91_REG *) 0x00000070) // (PWMC_FPER2) PWM Fault Protection Enable Register 2 +#define PWMC_FPER3 (AT91_CAST(AT91_REG *) 0x00000074) // (PWMC_FPER3) PWM Fault Protection Enable Register 3 +#define PWMC_FPER4 (AT91_CAST(AT91_REG *) 0x00000078) // (PWMC_FPER4) PWM Fault Protection Enable Register 4 +#define PWMC_EL0MR (AT91_CAST(AT91_REG *) 0x0000007C) // (PWMC_EL0MR) PWM Event Line 0 Mode Register +#define PWMC_EL1MR (AT91_CAST(AT91_REG *) 0x00000080) // (PWMC_EL1MR) PWM Event Line 1 Mode Register +#define PWMC_EL2MR (AT91_CAST(AT91_REG *) 0x00000084) // (PWMC_EL2MR) PWM Event Line 2 Mode Register +#define PWMC_EL3MR (AT91_CAST(AT91_REG *) 0x00000088) // (PWMC_EL3MR) PWM Event Line 3 Mode Register +#define PWMC_EL4MR (AT91_CAST(AT91_REG *) 0x0000008C) // (PWMC_EL4MR) PWM Event Line 4 Mode Register +#define PWMC_EL5MR (AT91_CAST(AT91_REG *) 0x00000090) // (PWMC_EL5MR) PWM Event Line 5 Mode Register +#define PWMC_EL6MR (AT91_CAST(AT91_REG *) 0x00000094) // (PWMC_EL6MR) PWM Event Line 6 Mode Register +#define PWMC_EL7MR (AT91_CAST(AT91_REG *) 0x00000098) // (PWMC_EL7MR) PWM Event Line 7 Mode Register +#define PWMC_WPCR (AT91_CAST(AT91_REG *) 0x000000E4) // (PWMC_WPCR) PWM Write Protection Enable Register +#define PWMC_WPSR (AT91_CAST(AT91_REG *) 0x000000E8) // (PWMC_WPSR) PWM Write Protection Status Register +#define PWMC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (PWMC_ADDRSIZE) PWMC ADDRSIZE REGISTER +#define PWMC_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (PWMC_IPNAME1) PWMC IPNAME1 REGISTER +#define PWMC_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (PWMC_IPNAME2) PWMC IPNAME2 REGISTER +#define PWMC_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (PWMC_FEATURES) PWMC FEATURES REGISTER +#define PWMC_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (PWMC_VER) PWMC Version Register +#define PWMC_CMP0V (AT91_CAST(AT91_REG *) 0x00000130) // (PWMC_CMP0V) PWM Comparison Value 0 Register +#define PWMC_CMP0VUPD (AT91_CAST(AT91_REG *) 0x00000134) // (PWMC_CMP0VUPD) PWM Comparison Value 0 Update Register +#define PWMC_CMP0M (AT91_CAST(AT91_REG *) 0x00000138) // (PWMC_CMP0M) PWM Comparison Mode 0 Register +#define PWMC_CMP0MUPD (AT91_CAST(AT91_REG *) 0x0000013C) // (PWMC_CMP0MUPD) PWM Comparison Mode 0 Update Register +#define PWMC_CMP1V (AT91_CAST(AT91_REG *) 0x00000140) // (PWMC_CMP1V) PWM Comparison Value 1 Register +#define PWMC_CMP1VUPD (AT91_CAST(AT91_REG *) 0x00000144) // (PWMC_CMP1VUPD) PWM Comparison Value 1 Update Register +#define PWMC_CMP1M (AT91_CAST(AT91_REG *) 0x00000148) // (PWMC_CMP1M) PWM Comparison Mode 1 Register +#define PWMC_CMP1MUPD (AT91_CAST(AT91_REG *) 0x0000014C) // (PWMC_CMP1MUPD) PWM Comparison Mode 1 Update Register +#define PWMC_CMP2V (AT91_CAST(AT91_REG *) 0x00000150) // (PWMC_CMP2V) PWM Comparison Value 2 Register +#define PWMC_CMP2VUPD (AT91_CAST(AT91_REG *) 0x00000154) // (PWMC_CMP2VUPD) PWM Comparison Value 2 Update Register +#define PWMC_CMP2M (AT91_CAST(AT91_REG *) 0x00000158) // (PWMC_CMP2M) PWM Comparison Mode 2 Register +#define PWMC_CMP2MUPD (AT91_CAST(AT91_REG *) 0x0000015C) // (PWMC_CMP2MUPD) PWM Comparison Mode 2 Update Register +#define PWMC_CMP3V (AT91_CAST(AT91_REG *) 0x00000160) // (PWMC_CMP3V) PWM Comparison Value 3 Register +#define PWMC_CMP3VUPD (AT91_CAST(AT91_REG *) 0x00000164) // (PWMC_CMP3VUPD) PWM Comparison Value 3 Update Register +#define PWMC_CMP3M (AT91_CAST(AT91_REG *) 0x00000168) // (PWMC_CMP3M) PWM Comparison Mode 3 Register +#define PWMC_CMP3MUPD (AT91_CAST(AT91_REG *) 0x0000016C) // (PWMC_CMP3MUPD) PWM Comparison Mode 3 Update Register +#define PWMC_CMP4V (AT91_CAST(AT91_REG *) 0x00000170) // (PWMC_CMP4V) PWM Comparison Value 4 Register +#define PWMC_CMP4VUPD (AT91_CAST(AT91_REG *) 0x00000174) // (PWMC_CMP4VUPD) PWM Comparison Value 4 Update Register +#define PWMC_CMP4M (AT91_CAST(AT91_REG *) 0x00000178) // (PWMC_CMP4M) PWM Comparison Mode 4 Register +#define PWMC_CMP4MUPD (AT91_CAST(AT91_REG *) 0x0000017C) // (PWMC_CMP4MUPD) PWM Comparison Mode 4 Update Register +#define PWMC_CMP5V (AT91_CAST(AT91_REG *) 0x00000180) // (PWMC_CMP5V) PWM Comparison Value 5 Register +#define PWMC_CMP5VUPD (AT91_CAST(AT91_REG *) 0x00000184) // (PWMC_CMP5VUPD) PWM Comparison Value 5 Update Register +#define PWMC_CMP5M (AT91_CAST(AT91_REG *) 0x00000188) // (PWMC_CMP5M) PWM Comparison Mode 5 Register +#define PWMC_CMP5MUPD (AT91_CAST(AT91_REG *) 0x0000018C) // (PWMC_CMP5MUPD) PWM Comparison Mode 5 Update Register +#define PWMC_CMP6V (AT91_CAST(AT91_REG *) 0x00000190) // (PWMC_CMP6V) PWM Comparison Value 6 Register +#define PWMC_CMP6VUPD (AT91_CAST(AT91_REG *) 0x00000194) // (PWMC_CMP6VUPD) PWM Comparison Value 6 Update Register +#define PWMC_CMP6M (AT91_CAST(AT91_REG *) 0x00000198) // (PWMC_CMP6M) PWM Comparison Mode 6 Register +#define PWMC_CMP6MUPD (AT91_CAST(AT91_REG *) 0x0000019C) // (PWMC_CMP6MUPD) PWM Comparison Mode 6 Update Register +#define PWMC_CMP7V (AT91_CAST(AT91_REG *) 0x000001A0) // (PWMC_CMP7V) PWM Comparison Value 7 Register +#define PWMC_CMP7VUPD (AT91_CAST(AT91_REG *) 0x000001A4) // (PWMC_CMP7VUPD) PWM Comparison Value 7 Update Register +#define PWMC_CMP7M (AT91_CAST(AT91_REG *) 0x000001A8) // (PWMC_CMP7M) PWM Comparison Mode 7 Register +#define PWMC_CMP7MUPD (AT91_CAST(AT91_REG *) 0x000001AC) // (PWMC_CMP7MUPD) PWM Comparison Mode 7 Update Register + +#endif +// -------- PWMC_MR : (PWMC Offset: 0x0) PWMC Mode Register -------- +#define AT91C_PWMC_DIVA (0xFF << 0) // (PWMC) CLKA divide factor. +#define AT91C_PWMC_PREA (0xF << 8) // (PWMC) Divider Input Clock Prescaler A +#define AT91C_PWMC_PREA_MCK (0x0 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_2 (0x1 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_4 (0x2 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_8 (0x3 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_16 (0x4 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_32 (0x5 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_64 (0x6 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_128 (0x7 << 8) // (PWMC) +#define AT91C_PWMC_PREA_MCK_DIV_256 (0x8 << 8) // (PWMC) +#define AT91C_PWMC_DIVB (0xFF << 16) // (PWMC) CLKB divide factor. +#define AT91C_PWMC_PREB (0xF << 24) // (PWMC) Divider Input Clock Prescaler B +#define AT91C_PWMC_PREB_MCK (0x0 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_2 (0x1 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_4 (0x2 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_8 (0x3 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_16 (0x4 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_32 (0x5 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_64 (0x6 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_128 (0x7 << 24) // (PWMC) +#define AT91C_PWMC_PREB_MCK_DIV_256 (0x8 << 24) // (PWMC) +#define AT91C_PWMC_CLKSEL (0x1 << 31) // (PWMC) CCK Source Clock Selection +// -------- PWMC_ENA : (PWMC Offset: 0x4) PWMC Enable Register -------- +#define AT91C_PWMC_CHID0 (0x1 << 0) // (PWMC) Channel ID 0 +#define AT91C_PWMC_CHID1 (0x1 << 1) // (PWMC) Channel ID 1 +#define AT91C_PWMC_CHID2 (0x1 << 2) // (PWMC) Channel ID 2 +#define AT91C_PWMC_CHID3 (0x1 << 3) // (PWMC) Channel ID 3 +#define AT91C_PWMC_CHID4 (0x1 << 4) // (PWMC) Channel ID 4 +#define AT91C_PWMC_CHID5 (0x1 << 5) // (PWMC) Channel ID 5 +#define AT91C_PWMC_CHID6 (0x1 << 6) // (PWMC) Channel ID 6 +#define AT91C_PWMC_CHID7 (0x1 << 7) // (PWMC) Channel ID 7 +#define AT91C_PWMC_CHID8 (0x1 << 8) // (PWMC) Channel ID 8 +#define AT91C_PWMC_CHID9 (0x1 << 9) // (PWMC) Channel ID 9 +#define AT91C_PWMC_CHID10 (0x1 << 10) // (PWMC) Channel ID 10 +#define AT91C_PWMC_CHID11 (0x1 << 11) // (PWMC) Channel ID 11 +#define AT91C_PWMC_CHID12 (0x1 << 12) // (PWMC) Channel ID 12 +#define AT91C_PWMC_CHID13 (0x1 << 13) // (PWMC) Channel ID 13 +#define AT91C_PWMC_CHID14 (0x1 << 14) // (PWMC) Channel ID 14 +#define AT91C_PWMC_CHID15 (0x1 << 15) // (PWMC) Channel ID 15 +// -------- PWMC_DIS : (PWMC Offset: 0x8) PWMC Disable Register -------- +// -------- PWMC_SR : (PWMC Offset: 0xc) PWMC Status Register -------- +// -------- PWMC_IER1 : (PWMC Offset: 0x10) PWMC Interrupt Enable Register -------- +#define AT91C_PWMC_FCHID0 (0x1 << 16) // (PWMC) Fault Event Channel ID 0 +#define AT91C_PWMC_FCHID1 (0x1 << 17) // (PWMC) Fault Event Channel ID 1 +#define AT91C_PWMC_FCHID2 (0x1 << 18) // (PWMC) Fault Event Channel ID 2 +#define AT91C_PWMC_FCHID3 (0x1 << 19) // (PWMC) Fault Event Channel ID 3 +#define AT91C_PWMC_FCHID4 (0x1 << 20) // (PWMC) Fault Event Channel ID 4 +#define AT91C_PWMC_FCHID5 (0x1 << 21) // (PWMC) Fault Event Channel ID 5 +#define AT91C_PWMC_FCHID6 (0x1 << 22) // (PWMC) Fault Event Channel ID 6 +#define AT91C_PWMC_FCHID7 (0x1 << 23) // (PWMC) Fault Event Channel ID 7 +#define AT91C_PWMC_FCHID8 (0x1 << 24) // (PWMC) Fault Event Channel ID 8 +#define AT91C_PWMC_FCHID9 (0x1 << 25) // (PWMC) Fault Event Channel ID 9 +#define AT91C_PWMC_FCHID10 (0x1 << 26) // (PWMC) Fault Event Channel ID 10 +#define AT91C_PWMC_FCHID11 (0x1 << 27) // (PWMC) Fault Event Channel ID 11 +#define AT91C_PWMC_FCHID12 (0x1 << 28) // (PWMC) Fault Event Channel ID 12 +#define AT91C_PWMC_FCHID13 (0x1 << 29) // (PWMC) Fault Event Channel ID 13 +#define AT91C_PWMC_FCHID14 (0x1 << 30) // (PWMC) Fault Event Channel ID 14 +#define AT91C_PWMC_FCHID15 (0x1 << 31) // (PWMC) Fault Event Channel ID 15 +// -------- PWMC_IDR1 : (PWMC Offset: 0x14) PWMC Interrupt Disable Register -------- +// -------- PWMC_IMR1 : (PWMC Offset: 0x18) PWMC Interrupt Mask Register -------- +// -------- PWMC_ISR1 : (PWMC Offset: 0x1c) PWMC Interrupt Status Register -------- +// -------- PWMC_SYNC : (PWMC Offset: 0x20) PWMC Synchronous Channels Register -------- +#define AT91C_PWMC_SYNC0 (0x1 << 0) // (PWMC) Synchronous Channel ID 0 +#define AT91C_PWMC_SYNC1 (0x1 << 1) // (PWMC) Synchronous Channel ID 1 +#define AT91C_PWMC_SYNC2 (0x1 << 2) // (PWMC) Synchronous Channel ID 2 +#define AT91C_PWMC_SYNC3 (0x1 << 3) // (PWMC) Synchronous Channel ID 3 +#define AT91C_PWMC_SYNC4 (0x1 << 4) // (PWMC) Synchronous Channel ID 4 +#define AT91C_PWMC_SYNC5 (0x1 << 5) // (PWMC) Synchronous Channel ID 5 +#define AT91C_PWMC_SYNC6 (0x1 << 6) // (PWMC) Synchronous Channel ID 6 +#define AT91C_PWMC_SYNC7 (0x1 << 7) // (PWMC) Synchronous Channel ID 7 +#define AT91C_PWMC_SYNC8 (0x1 << 8) // (PWMC) Synchronous Channel ID 8 +#define AT91C_PWMC_SYNC9 (0x1 << 9) // (PWMC) Synchronous Channel ID 9 +#define AT91C_PWMC_SYNC10 (0x1 << 10) // (PWMC) Synchronous Channel ID 10 +#define AT91C_PWMC_SYNC11 (0x1 << 11) // (PWMC) Synchronous Channel ID 11 +#define AT91C_PWMC_SYNC12 (0x1 << 12) // (PWMC) Synchronous Channel ID 12 +#define AT91C_PWMC_SYNC13 (0x1 << 13) // (PWMC) Synchronous Channel ID 13 +#define AT91C_PWMC_SYNC14 (0x1 << 14) // (PWMC) Synchronous Channel ID 14 +#define AT91C_PWMC_SYNC15 (0x1 << 15) // (PWMC) Synchronous Channel ID 15 +#define AT91C_PWMC_UPDM (0x3 << 16) // (PWMC) Synchronous Channels Update mode +#define AT91C_PWMC_UPDM_MODE0 (0x0 << 16) // (PWMC) Manual write of data and manual trigger of the update +#define AT91C_PWMC_UPDM_MODE1 (0x1 << 16) // (PWMC) Manual write of data and automatic trigger of the update +#define AT91C_PWMC_UPDM_MODE2 (0x2 << 16) // (PWMC) Automatic write of data and automatic trigger of the update +// -------- PWMC_UPCR : (PWMC Offset: 0x28) PWMC Update Control Register -------- +#define AT91C_PWMC_UPDULOCK (0x1 << 0) // (PWMC) Synchronized Channels Duty Cycle Update Unlock +// -------- PWMC_SCUP : (PWMC Offset: 0x2c) PWM Update Period Register -------- +#define AT91C_PWMC_UPR (0xF << 0) // (PWMC) PWM Update Period. +#define AT91C_PWMC_UPRCNT (0xF << 4) // (PWMC) PWM Update Period Counter. +// -------- PWMC_SCUPUPD : (PWMC Offset: 0x30) PWM Update Period Update Register -------- +#define AT91C_PWMC_UPVUPDAL (0xF << 0) // (PWMC) PWM Update Period Update. +// -------- PWMC_IER2 : (PWMC Offset: 0x34) PWMC Interrupt Enable Register -------- +#define AT91C_PWMC_WRDY (0x1 << 0) // (PWMC) PDC Write Ready +#define AT91C_PWMC_ENDTX (0x1 << 1) // (PWMC) PDC End of TX Buffer +#define AT91C_PWMC_TXBUFE (0x1 << 2) // (PWMC) PDC End of TX Buffer +#define AT91C_PWMC_UNRE (0x1 << 3) // (PWMC) PDC End of TX Buffer +// -------- PWMC_IDR2 : (PWMC Offset: 0x38) PWMC Interrupt Disable Register -------- +// -------- PWMC_IMR2 : (PWMC Offset: 0x3c) PWMC Interrupt Mask Register -------- +// -------- PWMC_ISR2 : (PWMC Offset: 0x40) PWMC Interrupt Status Register -------- +#define AT91C_PWMC_CMPM0 (0x1 << 8) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM1 (0x1 << 9) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM2 (0x1 << 10) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM3 (0x1 << 11) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM4 (0x1 << 12) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM5 (0x1 << 13) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM6 (0x1 << 14) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPM7 (0x1 << 15) // (PWMC) Comparison x Match +#define AT91C_PWMC_CMPU0 (0x1 << 16) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU1 (0x1 << 17) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU2 (0x1 << 18) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU3 (0x1 << 19) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU4 (0x1 << 20) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU5 (0x1 << 21) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU6 (0x1 << 22) // (PWMC) Comparison x Update +#define AT91C_PWMC_CMPU7 (0x1 << 23) // (PWMC) Comparison x Update +// -------- PWMC_OOV : (PWMC Offset: 0x44) PWM Output Override Value Register -------- +#define AT91C_PWMC_OOVH0 (0x1 << 0) // (PWMC) Output Override Value for PWMH output of the channel 0 +#define AT91C_PWMC_OOVH1 (0x1 << 1) // (PWMC) Output Override Value for PWMH output of the channel 1 +#define AT91C_PWMC_OOVH2 (0x1 << 2) // (PWMC) Output Override Value for PWMH output of the channel 2 +#define AT91C_PWMC_OOVH3 (0x1 << 3) // (PWMC) Output Override Value for PWMH output of the channel 3 +#define AT91C_PWMC_OOVH4 (0x1 << 4) // (PWMC) Output Override Value for PWMH output of the channel 4 +#define AT91C_PWMC_OOVH5 (0x1 << 5) // (PWMC) Output Override Value for PWMH output of the channel 5 +#define AT91C_PWMC_OOVH6 (0x1 << 6) // (PWMC) Output Override Value for PWMH output of the channel 6 +#define AT91C_PWMC_OOVH7 (0x1 << 7) // (PWMC) Output Override Value for PWMH output of the channel 7 +#define AT91C_PWMC_OOVH8 (0x1 << 8) // (PWMC) Output Override Value for PWMH output of the channel 8 +#define AT91C_PWMC_OOVH9 (0x1 << 9) // (PWMC) Output Override Value for PWMH output of the channel 9 +#define AT91C_PWMC_OOVH10 (0x1 << 10) // (PWMC) Output Override Value for PWMH output of the channel 10 +#define AT91C_PWMC_OOVH11 (0x1 << 11) // (PWMC) Output Override Value for PWMH output of the channel 11 +#define AT91C_PWMC_OOVH12 (0x1 << 12) // (PWMC) Output Override Value for PWMH output of the channel 12 +#define AT91C_PWMC_OOVH13 (0x1 << 13) // (PWMC) Output Override Value for PWMH output of the channel 13 +#define AT91C_PWMC_OOVH14 (0x1 << 14) // (PWMC) Output Override Value for PWMH output of the channel 14 +#define AT91C_PWMC_OOVH15 (0x1 << 15) // (PWMC) Output Override Value for PWMH output of the channel 15 +#define AT91C_PWMC_OOVL0 (0x1 << 16) // (PWMC) Output Override Value for PWML output of the channel 0 +#define AT91C_PWMC_OOVL1 (0x1 << 17) // (PWMC) Output Override Value for PWML output of the channel 1 +#define AT91C_PWMC_OOVL2 (0x1 << 18) // (PWMC) Output Override Value for PWML output of the channel 2 +#define AT91C_PWMC_OOVL3 (0x1 << 19) // (PWMC) Output Override Value for PWML output of the channel 3 +#define AT91C_PWMC_OOVL4 (0x1 << 20) // (PWMC) Output Override Value for PWML output of the channel 4 +#define AT91C_PWMC_OOVL5 (0x1 << 21) // (PWMC) Output Override Value for PWML output of the channel 5 +#define AT91C_PWMC_OOVL6 (0x1 << 22) // (PWMC) Output Override Value for PWML output of the channel 6 +#define AT91C_PWMC_OOVL7 (0x1 << 23) // (PWMC) Output Override Value for PWML output of the channel 7 +#define AT91C_PWMC_OOVL8 (0x1 << 24) // (PWMC) Output Override Value for PWML output of the channel 8 +#define AT91C_PWMC_OOVL9 (0x1 << 25) // (PWMC) Output Override Value for PWML output of the channel 9 +#define AT91C_PWMC_OOVL10 (0x1 << 26) // (PWMC) Output Override Value for PWML output of the channel 10 +#define AT91C_PWMC_OOVL11 (0x1 << 27) // (PWMC) Output Override Value for PWML output of the channel 11 +#define AT91C_PWMC_OOVL12 (0x1 << 28) // (PWMC) Output Override Value for PWML output of the channel 12 +#define AT91C_PWMC_OOVL13 (0x1 << 29) // (PWMC) Output Override Value for PWML output of the channel 13 +#define AT91C_PWMC_OOVL14 (0x1 << 30) // (PWMC) Output Override Value for PWML output of the channel 14 +#define AT91C_PWMC_OOVL15 (0x1 << 31) // (PWMC) Output Override Value for PWML output of the channel 15 +// -------- PWMC_OS : (PWMC Offset: 0x48) PWM Output Selection Register -------- +#define AT91C_PWMC_OSH0 (0x1 << 0) // (PWMC) Output Selection for PWMH output of the channel 0 +#define AT91C_PWMC_OSH1 (0x1 << 1) // (PWMC) Output Selection for PWMH output of the channel 1 +#define AT91C_PWMC_OSH2 (0x1 << 2) // (PWMC) Output Selection for PWMH output of the channel 2 +#define AT91C_PWMC_OSH3 (0x1 << 3) // (PWMC) Output Selection for PWMH output of the channel 3 +#define AT91C_PWMC_OSH4 (0x1 << 4) // (PWMC) Output Selection for PWMH output of the channel 4 +#define AT91C_PWMC_OSH5 (0x1 << 5) // (PWMC) Output Selection for PWMH output of the channel 5 +#define AT91C_PWMC_OSH6 (0x1 << 6) // (PWMC) Output Selection for PWMH output of the channel 6 +#define AT91C_PWMC_OSH7 (0x1 << 7) // (PWMC) Output Selection for PWMH output of the channel 7 +#define AT91C_PWMC_OSH8 (0x1 << 8) // (PWMC) Output Selection for PWMH output of the channel 8 +#define AT91C_PWMC_OSH9 (0x1 << 9) // (PWMC) Output Selection for PWMH output of the channel 9 +#define AT91C_PWMC_OSH10 (0x1 << 10) // (PWMC) Output Selection for PWMH output of the channel 10 +#define AT91C_PWMC_OSH11 (0x1 << 11) // (PWMC) Output Selection for PWMH output of the channel 11 +#define AT91C_PWMC_OSH12 (0x1 << 12) // (PWMC) Output Selection for PWMH output of the channel 12 +#define AT91C_PWMC_OSH13 (0x1 << 13) // (PWMC) Output Selection for PWMH output of the channel 13 +#define AT91C_PWMC_OSH14 (0x1 << 14) // (PWMC) Output Selection for PWMH output of the channel 14 +#define AT91C_PWMC_OSH15 (0x1 << 15) // (PWMC) Output Selection for PWMH output of the channel 15 +#define AT91C_PWMC_OSL0 (0x1 << 16) // (PWMC) Output Selection for PWML output of the channel 0 +#define AT91C_PWMC_OSL1 (0x1 << 17) // (PWMC) Output Selection for PWML output of the channel 1 +#define AT91C_PWMC_OSL2 (0x1 << 18) // (PWMC) Output Selection for PWML output of the channel 2 +#define AT91C_PWMC_OSL3 (0x1 << 19) // (PWMC) Output Selection for PWML output of the channel 3 +#define AT91C_PWMC_OSL4 (0x1 << 20) // (PWMC) Output Selection for PWML output of the channel 4 +#define AT91C_PWMC_OSL5 (0x1 << 21) // (PWMC) Output Selection for PWML output of the channel 5 +#define AT91C_PWMC_OSL6 (0x1 << 22) // (PWMC) Output Selection for PWML output of the channel 6 +#define AT91C_PWMC_OSL7 (0x1 << 23) // (PWMC) Output Selection for PWML output of the channel 7 +#define AT91C_PWMC_OSL8 (0x1 << 24) // (PWMC) Output Selection for PWML output of the channel 8 +#define AT91C_PWMC_OSL9 (0x1 << 25) // (PWMC) Output Selection for PWML output of the channel 9 +#define AT91C_PWMC_OSL10 (0x1 << 26) // (PWMC) Output Selection for PWML output of the channel 10 +#define AT91C_PWMC_OSL11 (0x1 << 27) // (PWMC) Output Selection for PWML output of the channel 11 +#define AT91C_PWMC_OSL12 (0x1 << 28) // (PWMC) Output Selection for PWML output of the channel 12 +#define AT91C_PWMC_OSL13 (0x1 << 29) // (PWMC) Output Selection for PWML output of the channel 13 +#define AT91C_PWMC_OSL14 (0x1 << 30) // (PWMC) Output Selection for PWML output of the channel 14 +#define AT91C_PWMC_OSL15 (0x1 << 31) // (PWMC) Output Selection for PWML output of the channel 15 +// -------- PWMC_OSS : (PWMC Offset: 0x4c) PWM Output Selection Set Register -------- +#define AT91C_PWMC_OSSH0 (0x1 << 0) // (PWMC) Output Selection Set for PWMH output of the channel 0 +#define AT91C_PWMC_OSSH1 (0x1 << 1) // (PWMC) Output Selection Set for PWMH output of the channel 1 +#define AT91C_PWMC_OSSH2 (0x1 << 2) // (PWMC) Output Selection Set for PWMH output of the channel 2 +#define AT91C_PWMC_OSSH3 (0x1 << 3) // (PWMC) Output Selection Set for PWMH output of the channel 3 +#define AT91C_PWMC_OSSH4 (0x1 << 4) // (PWMC) Output Selection Set for PWMH output of the channel 4 +#define AT91C_PWMC_OSSH5 (0x1 << 5) // (PWMC) Output Selection Set for PWMH output of the channel 5 +#define AT91C_PWMC_OSSH6 (0x1 << 6) // (PWMC) Output Selection Set for PWMH output of the channel 6 +#define AT91C_PWMC_OSSH7 (0x1 << 7) // (PWMC) Output Selection Set for PWMH output of the channel 7 +#define AT91C_PWMC_OSSH8 (0x1 << 8) // (PWMC) Output Selection Set for PWMH output of the channel 8 +#define AT91C_PWMC_OSSH9 (0x1 << 9) // (PWMC) Output Selection Set for PWMH output of the channel 9 +#define AT91C_PWMC_OSSH10 (0x1 << 10) // (PWMC) Output Selection Set for PWMH output of the channel 10 +#define AT91C_PWMC_OSSH11 (0x1 << 11) // (PWMC) Output Selection Set for PWMH output of the channel 11 +#define AT91C_PWMC_OSSH12 (0x1 << 12) // (PWMC) Output Selection Set for PWMH output of the channel 12 +#define AT91C_PWMC_OSSH13 (0x1 << 13) // (PWMC) Output Selection Set for PWMH output of the channel 13 +#define AT91C_PWMC_OSSH14 (0x1 << 14) // (PWMC) Output Selection Set for PWMH output of the channel 14 +#define AT91C_PWMC_OSSH15 (0x1 << 15) // (PWMC) Output Selection Set for PWMH output of the channel 15 +#define AT91C_PWMC_OSSL0 (0x1 << 16) // (PWMC) Output Selection Set for PWML output of the channel 0 +#define AT91C_PWMC_OSSL1 (0x1 << 17) // (PWMC) Output Selection Set for PWML output of the channel 1 +#define AT91C_PWMC_OSSL2 (0x1 << 18) // (PWMC) Output Selection Set for PWML output of the channel 2 +#define AT91C_PWMC_OSSL3 (0x1 << 19) // (PWMC) Output Selection Set for PWML output of the channel 3 +#define AT91C_PWMC_OSSL4 (0x1 << 20) // (PWMC) Output Selection Set for PWML output of the channel 4 +#define AT91C_PWMC_OSSL5 (0x1 << 21) // (PWMC) Output Selection Set for PWML output of the channel 5 +#define AT91C_PWMC_OSSL6 (0x1 << 22) // (PWMC) Output Selection Set for PWML output of the channel 6 +#define AT91C_PWMC_OSSL7 (0x1 << 23) // (PWMC) Output Selection Set for PWML output of the channel 7 +#define AT91C_PWMC_OSSL8 (0x1 << 24) // (PWMC) Output Selection Set for PWML output of the channel 8 +#define AT91C_PWMC_OSSL9 (0x1 << 25) // (PWMC) Output Selection Set for PWML output of the channel 9 +#define AT91C_PWMC_OSSL10 (0x1 << 26) // (PWMC) Output Selection Set for PWML output of the channel 10 +#define AT91C_PWMC_OSSL11 (0x1 << 27) // (PWMC) Output Selection Set for PWML output of the channel 11 +#define AT91C_PWMC_OSSL12 (0x1 << 28) // (PWMC) Output Selection Set for PWML output of the channel 12 +#define AT91C_PWMC_OSSL13 (0x1 << 29) // (PWMC) Output Selection Set for PWML output of the channel 13 +#define AT91C_PWMC_OSSL14 (0x1 << 30) // (PWMC) Output Selection Set for PWML output of the channel 14 +#define AT91C_PWMC_OSSL15 (0x1 << 31) // (PWMC) Output Selection Set for PWML output of the channel 15 +// -------- PWMC_OSC : (PWMC Offset: 0x50) PWM Output Selection Clear Register -------- +#define AT91C_PWMC_OSCH0 (0x1 << 0) // (PWMC) Output Selection Clear for PWMH output of the channel 0 +#define AT91C_PWMC_OSCH1 (0x1 << 1) // (PWMC) Output Selection Clear for PWMH output of the channel 1 +#define AT91C_PWMC_OSCH2 (0x1 << 2) // (PWMC) Output Selection Clear for PWMH output of the channel 2 +#define AT91C_PWMC_OSCH3 (0x1 << 3) // (PWMC) Output Selection Clear for PWMH output of the channel 3 +#define AT91C_PWMC_OSCH4 (0x1 << 4) // (PWMC) Output Selection Clear for PWMH output of the channel 4 +#define AT91C_PWMC_OSCH5 (0x1 << 5) // (PWMC) Output Selection Clear for PWMH output of the channel 5 +#define AT91C_PWMC_OSCH6 (0x1 << 6) // (PWMC) Output Selection Clear for PWMH output of the channel 6 +#define AT91C_PWMC_OSCH7 (0x1 << 7) // (PWMC) Output Selection Clear for PWMH output of the channel 7 +#define AT91C_PWMC_OSCH8 (0x1 << 8) // (PWMC) Output Selection Clear for PWMH output of the channel 8 +#define AT91C_PWMC_OSCH9 (0x1 << 9) // (PWMC) Output Selection Clear for PWMH output of the channel 9 +#define AT91C_PWMC_OSCH10 (0x1 << 10) // (PWMC) Output Selection Clear for PWMH output of the channel 10 +#define AT91C_PWMC_OSCH11 (0x1 << 11) // (PWMC) Output Selection Clear for PWMH output of the channel 11 +#define AT91C_PWMC_OSCH12 (0x1 << 12) // (PWMC) Output Selection Clear for PWMH output of the channel 12 +#define AT91C_PWMC_OSCH13 (0x1 << 13) // (PWMC) Output Selection Clear for PWMH output of the channel 13 +#define AT91C_PWMC_OSCH14 (0x1 << 14) // (PWMC) Output Selection Clear for PWMH output of the channel 14 +#define AT91C_PWMC_OSCH15 (0x1 << 15) // (PWMC) Output Selection Clear for PWMH output of the channel 15 +#define AT91C_PWMC_OSCL0 (0x1 << 16) // (PWMC) Output Selection Clear for PWML output of the channel 0 +#define AT91C_PWMC_OSCL1 (0x1 << 17) // (PWMC) Output Selection Clear for PWML output of the channel 1 +#define AT91C_PWMC_OSCL2 (0x1 << 18) // (PWMC) Output Selection Clear for PWML output of the channel 2 +#define AT91C_PWMC_OSCL3 (0x1 << 19) // (PWMC) Output Selection Clear for PWML output of the channel 3 +#define AT91C_PWMC_OSCL4 (0x1 << 20) // (PWMC) Output Selection Clear for PWML output of the channel 4 +#define AT91C_PWMC_OSCL5 (0x1 << 21) // (PWMC) Output Selection Clear for PWML output of the channel 5 +#define AT91C_PWMC_OSCL6 (0x1 << 22) // (PWMC) Output Selection Clear for PWML output of the channel 6 +#define AT91C_PWMC_OSCL7 (0x1 << 23) // (PWMC) Output Selection Clear for PWML output of the channel 7 +#define AT91C_PWMC_OSCL8 (0x1 << 24) // (PWMC) Output Selection Clear for PWML output of the channel 8 +#define AT91C_PWMC_OSCL9 (0x1 << 25) // (PWMC) Output Selection Clear for PWML output of the channel 9 +#define AT91C_PWMC_OSCL10 (0x1 << 26) // (PWMC) Output Selection Clear for PWML output of the channel 10 +#define AT91C_PWMC_OSCL11 (0x1 << 27) // (PWMC) Output Selection Clear for PWML output of the channel 11 +#define AT91C_PWMC_OSCL12 (0x1 << 28) // (PWMC) Output Selection Clear for PWML output of the channel 12 +#define AT91C_PWMC_OSCL13 (0x1 << 29) // (PWMC) Output Selection Clear for PWML output of the channel 13 +#define AT91C_PWMC_OSCL14 (0x1 << 30) // (PWMC) Output Selection Clear for PWML output of the channel 14 +#define AT91C_PWMC_OSCL15 (0x1 << 31) // (PWMC) Output Selection Clear for PWML output of the channel 15 +// -------- PWMC_OSSUPD : (PWMC Offset: 0x54) Output Selection Set for PWMH / PWML output of the channel x -------- +#define AT91C_PWMC_OSSUPDH0 (0x1 << 0) // (PWMC) Output Selection Set for PWMH output of the channel 0 +#define AT91C_PWMC_OSSUPDH1 (0x1 << 1) // (PWMC) Output Selection Set for PWMH output of the channel 1 +#define AT91C_PWMC_OSSUPDH2 (0x1 << 2) // (PWMC) Output Selection Set for PWMH output of the channel 2 +#define AT91C_PWMC_OSSUPDH3 (0x1 << 3) // (PWMC) Output Selection Set for PWMH output of the channel 3 +#define AT91C_PWMC_OSSUPDH4 (0x1 << 4) // (PWMC) Output Selection Set for PWMH output of the channel 4 +#define AT91C_PWMC_OSSUPDH5 (0x1 << 5) // (PWMC) Output Selection Set for PWMH output of the channel 5 +#define AT91C_PWMC_OSSUPDH6 (0x1 << 6) // (PWMC) Output Selection Set for PWMH output of the channel 6 +#define AT91C_PWMC_OSSUPDH7 (0x1 << 7) // (PWMC) Output Selection Set for PWMH output of the channel 7 +#define AT91C_PWMC_OSSUPDH8 (0x1 << 8) // (PWMC) Output Selection Set for PWMH output of the channel 8 +#define AT91C_PWMC_OSSUPDH9 (0x1 << 9) // (PWMC) Output Selection Set for PWMH output of the channel 9 +#define AT91C_PWMC_OSSUPDH10 (0x1 << 10) // (PWMC) Output Selection Set for PWMH output of the channel 10 +#define AT91C_PWMC_OSSUPDH11 (0x1 << 11) // (PWMC) Output Selection Set for PWMH output of the channel 11 +#define AT91C_PWMC_OSSUPDH12 (0x1 << 12) // (PWMC) Output Selection Set for PWMH output of the channel 12 +#define AT91C_PWMC_OSSUPDH13 (0x1 << 13) // (PWMC) Output Selection Set for PWMH output of the channel 13 +#define AT91C_PWMC_OSSUPDH14 (0x1 << 14) // (PWMC) Output Selection Set for PWMH output of the channel 14 +#define AT91C_PWMC_OSSUPDH15 (0x1 << 15) // (PWMC) Output Selection Set for PWMH output of the channel 15 +#define AT91C_PWMC_OSSUPDL0 (0x1 << 16) // (PWMC) Output Selection Set for PWML output of the channel 0 +#define AT91C_PWMC_OSSUPDL1 (0x1 << 17) // (PWMC) Output Selection Set for PWML output of the channel 1 +#define AT91C_PWMC_OSSUPDL2 (0x1 << 18) // (PWMC) Output Selection Set for PWML output of the channel 2 +#define AT91C_PWMC_OSSUPDL3 (0x1 << 19) // (PWMC) Output Selection Set for PWML output of the channel 3 +#define AT91C_PWMC_OSSUPDL4 (0x1 << 20) // (PWMC) Output Selection Set for PWML output of the channel 4 +#define AT91C_PWMC_OSSUPDL5 (0x1 << 21) // (PWMC) Output Selection Set for PWML output of the channel 5 +#define AT91C_PWMC_OSSUPDL6 (0x1 << 22) // (PWMC) Output Selection Set for PWML output of the channel 6 +#define AT91C_PWMC_OSSUPDL7 (0x1 << 23) // (PWMC) Output Selection Set for PWML output of the channel 7 +#define AT91C_PWMC_OSSUPDL8 (0x1 << 24) // (PWMC) Output Selection Set for PWML output of the channel 8 +#define AT91C_PWMC_OSSUPDL9 (0x1 << 25) // (PWMC) Output Selection Set for PWML output of the channel 9 +#define AT91C_PWMC_OSSUPDL10 (0x1 << 26) // (PWMC) Output Selection Set for PWML output of the channel 10 +#define AT91C_PWMC_OSSUPDL11 (0x1 << 27) // (PWMC) Output Selection Set for PWML output of the channel 11 +#define AT91C_PWMC_OSSUPDL12 (0x1 << 28) // (PWMC) Output Selection Set for PWML output of the channel 12 +#define AT91C_PWMC_OSSUPDL13 (0x1 << 29) // (PWMC) Output Selection Set for PWML output of the channel 13 +#define AT91C_PWMC_OSSUPDL14 (0x1 << 30) // (PWMC) Output Selection Set for PWML output of the channel 14 +#define AT91C_PWMC_OSSUPDL15 (0x1 << 31) // (PWMC) Output Selection Set for PWML output of the channel 15 +// -------- PWMC_OSCUPD : (PWMC Offset: 0x58) Output Selection Clear for PWMH / PWML output of the channel x -------- +#define AT91C_PWMC_OSCUPDH0 (0x1 << 0) // (PWMC) Output Selection Clear for PWMH output of the channel 0 +#define AT91C_PWMC_OSCUPDH1 (0x1 << 1) // (PWMC) Output Selection Clear for PWMH output of the channel 1 +#define AT91C_PWMC_OSCUPDH2 (0x1 << 2) // (PWMC) Output Selection Clear for PWMH output of the channel 2 +#define AT91C_PWMC_OSCUPDH3 (0x1 << 3) // (PWMC) Output Selection Clear for PWMH output of the channel 3 +#define AT91C_PWMC_OSCUPDH4 (0x1 << 4) // (PWMC) Output Selection Clear for PWMH output of the channel 4 +#define AT91C_PWMC_OSCUPDH5 (0x1 << 5) // (PWMC) Output Selection Clear for PWMH output of the channel 5 +#define AT91C_PWMC_OSCUPDH6 (0x1 << 6) // (PWMC) Output Selection Clear for PWMH output of the channel 6 +#define AT91C_PWMC_OSCUPDH7 (0x1 << 7) // (PWMC) Output Selection Clear for PWMH output of the channel 7 +#define AT91C_PWMC_OSCUPDH8 (0x1 << 8) // (PWMC) Output Selection Clear for PWMH output of the channel 8 +#define AT91C_PWMC_OSCUPDH9 (0x1 << 9) // (PWMC) Output Selection Clear for PWMH output of the channel 9 +#define AT91C_PWMC_OSCUPDH10 (0x1 << 10) // (PWMC) Output Selection Clear for PWMH output of the channel 10 +#define AT91C_PWMC_OSCUPDH11 (0x1 << 11) // (PWMC) Output Selection Clear for PWMH output of the channel 11 +#define AT91C_PWMC_OSCUPDH12 (0x1 << 12) // (PWMC) Output Selection Clear for PWMH output of the channel 12 +#define AT91C_PWMC_OSCUPDH13 (0x1 << 13) // (PWMC) Output Selection Clear for PWMH output of the channel 13 +#define AT91C_PWMC_OSCUPDH14 (0x1 << 14) // (PWMC) Output Selection Clear for PWMH output of the channel 14 +#define AT91C_PWMC_OSCUPDH15 (0x1 << 15) // (PWMC) Output Selection Clear for PWMH output of the channel 15 +#define AT91C_PWMC_OSCUPDL0 (0x1 << 16) // (PWMC) Output Selection Clear for PWML output of the channel 0 +#define AT91C_PWMC_OSCUPDL1 (0x1 << 17) // (PWMC) Output Selection Clear for PWML output of the channel 1 +#define AT91C_PWMC_OSCUPDL2 (0x1 << 18) // (PWMC) Output Selection Clear for PWML output of the channel 2 +#define AT91C_PWMC_OSCUPDL3 (0x1 << 19) // (PWMC) Output Selection Clear for PWML output of the channel 3 +#define AT91C_PWMC_OSCUPDL4 (0x1 << 20) // (PWMC) Output Selection Clear for PWML output of the channel 4 +#define AT91C_PWMC_OSCUPDL5 (0x1 << 21) // (PWMC) Output Selection Clear for PWML output of the channel 5 +#define AT91C_PWMC_OSCUPDL6 (0x1 << 22) // (PWMC) Output Selection Clear for PWML output of the channel 6 +#define AT91C_PWMC_OSCUPDL7 (0x1 << 23) // (PWMC) Output Selection Clear for PWML output of the channel 7 +#define AT91C_PWMC_OSCUPDL8 (0x1 << 24) // (PWMC) Output Selection Clear for PWML output of the channel 8 +#define AT91C_PWMC_OSCUPDL9 (0x1 << 25) // (PWMC) Output Selection Clear for PWML output of the channel 9 +#define AT91C_PWMC_OSCUPDL10 (0x1 << 26) // (PWMC) Output Selection Clear for PWML output of the channel 10 +#define AT91C_PWMC_OSCUPDL11 (0x1 << 27) // (PWMC) Output Selection Clear for PWML output of the channel 11 +#define AT91C_PWMC_OSCUPDL12 (0x1 << 28) // (PWMC) Output Selection Clear for PWML output of the channel 12 +#define AT91C_PWMC_OSCUPDL13 (0x1 << 29) // (PWMC) Output Selection Clear for PWML output of the channel 13 +#define AT91C_PWMC_OSCUPDL14 (0x1 << 30) // (PWMC) Output Selection Clear for PWML output of the channel 14 +#define AT91C_PWMC_OSCUPDL15 (0x1 << 31) // (PWMC) Output Selection Clear for PWML output of the channel 15 +// -------- PWMC_FMR : (PWMC Offset: 0x5c) PWM Fault Mode Register -------- +#define AT91C_PWMC_FPOL0 (0x1 << 0) // (PWMC) Fault Polarity on fault input 0 +#define AT91C_PWMC_FPOL1 (0x1 << 1) // (PWMC) Fault Polarity on fault input 1 +#define AT91C_PWMC_FPOL2 (0x1 << 2) // (PWMC) Fault Polarity on fault input 2 +#define AT91C_PWMC_FPOL3 (0x1 << 3) // (PWMC) Fault Polarity on fault input 3 +#define AT91C_PWMC_FPOL4 (0x1 << 4) // (PWMC) Fault Polarity on fault input 4 +#define AT91C_PWMC_FPOL5 (0x1 << 5) // (PWMC) Fault Polarity on fault input 5 +#define AT91C_PWMC_FPOL6 (0x1 << 6) // (PWMC) Fault Polarity on fault input 6 +#define AT91C_PWMC_FPOL7 (0x1 << 7) // (PWMC) Fault Polarity on fault input 7 +#define AT91C_PWMC_FMOD0 (0x1 << 8) // (PWMC) Fault Activation Mode on fault input 0 +#define AT91C_PWMC_FMOD1 (0x1 << 9) // (PWMC) Fault Activation Mode on fault input 1 +#define AT91C_PWMC_FMOD2 (0x1 << 10) // (PWMC) Fault Activation Mode on fault input 2 +#define AT91C_PWMC_FMOD3 (0x1 << 11) // (PWMC) Fault Activation Mode on fault input 3 +#define AT91C_PWMC_FMOD4 (0x1 << 12) // (PWMC) Fault Activation Mode on fault input 4 +#define AT91C_PWMC_FMOD5 (0x1 << 13) // (PWMC) Fault Activation Mode on fault input 5 +#define AT91C_PWMC_FMOD6 (0x1 << 14) // (PWMC) Fault Activation Mode on fault input 6 +#define AT91C_PWMC_FMOD7 (0x1 << 15) // (PWMC) Fault Activation Mode on fault input 7 +#define AT91C_PWMC_FFIL00 (0x1 << 16) // (PWMC) Fault Filtering on fault input 0 +#define AT91C_PWMC_FFIL01 (0x1 << 17) // (PWMC) Fault Filtering on fault input 1 +#define AT91C_PWMC_FFIL02 (0x1 << 18) // (PWMC) Fault Filtering on fault input 2 +#define AT91C_PWMC_FFIL03 (0x1 << 19) // (PWMC) Fault Filtering on fault input 3 +#define AT91C_PWMC_FFIL04 (0x1 << 20) // (PWMC) Fault Filtering on fault input 4 +#define AT91C_PWMC_FFIL05 (0x1 << 21) // (PWMC) Fault Filtering on fault input 5 +#define AT91C_PWMC_FFIL06 (0x1 << 22) // (PWMC) Fault Filtering on fault input 6 +#define AT91C_PWMC_FFIL07 (0x1 << 23) // (PWMC) Fault Filtering on fault input 7 +// -------- PWMC_FSR : (PWMC Offset: 0x60) Fault Input x Value -------- +#define AT91C_PWMC_FIV0 (0x1 << 0) // (PWMC) Fault Input 0 Value +#define AT91C_PWMC_FIV1 (0x1 << 1) // (PWMC) Fault Input 1 Value +#define AT91C_PWMC_FIV2 (0x1 << 2) // (PWMC) Fault Input 2 Value +#define AT91C_PWMC_FIV3 (0x1 << 3) // (PWMC) Fault Input 3 Value +#define AT91C_PWMC_FIV4 (0x1 << 4) // (PWMC) Fault Input 4 Value +#define AT91C_PWMC_FIV5 (0x1 << 5) // (PWMC) Fault Input 5 Value +#define AT91C_PWMC_FIV6 (0x1 << 6) // (PWMC) Fault Input 6 Value +#define AT91C_PWMC_FIV7 (0x1 << 7) // (PWMC) Fault Input 7 Value +#define AT91C_PWMC_FS0 (0x1 << 8) // (PWMC) Fault 0 Status +#define AT91C_PWMC_FS1 (0x1 << 9) // (PWMC) Fault 1 Status +#define AT91C_PWMC_FS2 (0x1 << 10) // (PWMC) Fault 2 Status +#define AT91C_PWMC_FS3 (0x1 << 11) // (PWMC) Fault 3 Status +#define AT91C_PWMC_FS4 (0x1 << 12) // (PWMC) Fault 4 Status +#define AT91C_PWMC_FS5 (0x1 << 13) // (PWMC) Fault 5 Status +#define AT91C_PWMC_FS6 (0x1 << 14) // (PWMC) Fault 6 Status +#define AT91C_PWMC_FS7 (0x1 << 15) // (PWMC) Fault 7 Status +// -------- PWMC_FCR : (PWMC Offset: 0x64) Fault y Clear -------- +#define AT91C_PWMC_FCLR0 (0x1 << 0) // (PWMC) Fault 0 Clear +#define AT91C_PWMC_FCLR1 (0x1 << 1) // (PWMC) Fault 1 Clear +#define AT91C_PWMC_FCLR2 (0x1 << 2) // (PWMC) Fault 2 Clear +#define AT91C_PWMC_FCLR3 (0x1 << 3) // (PWMC) Fault 3 Clear +#define AT91C_PWMC_FCLR4 (0x1 << 4) // (PWMC) Fault 4 Clear +#define AT91C_PWMC_FCLR5 (0x1 << 5) // (PWMC) Fault 5 Clear +#define AT91C_PWMC_FCLR6 (0x1 << 6) // (PWMC) Fault 6 Clear +#define AT91C_PWMC_FCLR7 (0x1 << 7) // (PWMC) Fault 7 Clear +// -------- PWMC_FPV : (PWMC Offset: 0x68) PWM Fault Protection Value -------- +#define AT91C_PWMC_FPVH0 (0x1 << 0) // (PWMC) Fault Protection Value for PWMH output on channel 0 +#define AT91C_PWMC_FPVH1 (0x1 << 1) // (PWMC) Fault Protection Value for PWMH output on channel 1 +#define AT91C_PWMC_FPVH2 (0x1 << 2) // (PWMC) Fault Protection Value for PWMH output on channel 2 +#define AT91C_PWMC_FPVH3 (0x1 << 3) // (PWMC) Fault Protection Value for PWMH output on channel 3 +#define AT91C_PWMC_FPVH4 (0x1 << 4) // (PWMC) Fault Protection Value for PWMH output on channel 4 +#define AT91C_PWMC_FPVH5 (0x1 << 5) // (PWMC) Fault Protection Value for PWMH output on channel 5 +#define AT91C_PWMC_FPVH6 (0x1 << 6) // (PWMC) Fault Protection Value for PWMH output on channel 6 +#define AT91C_PWMC_FPVH7 (0x1 << 7) // (PWMC) Fault Protection Value for PWMH output on channel 7 +#define AT91C_PWMC_FPVL0 (0x1 << 16) // (PWMC) Fault Protection Value for PWML output on channel 0 +#define AT91C_PWMC_FPVL1 (0x1 << 17) // (PWMC) Fault Protection Value for PWML output on channel 1 +#define AT91C_PWMC_FPVL2 (0x1 << 18) // (PWMC) Fault Protection Value for PWML output on channel 2 +#define AT91C_PWMC_FPVL3 (0x1 << 19) // (PWMC) Fault Protection Value for PWML output on channel 3 +#define AT91C_PWMC_FPVL4 (0x1 << 20) // (PWMC) Fault Protection Value for PWML output on channel 4 +#define AT91C_PWMC_FPVL5 (0x1 << 21) // (PWMC) Fault Protection Value for PWML output on channel 5 +#define AT91C_PWMC_FPVL6 (0x1 << 22) // (PWMC) Fault Protection Value for PWML output on channel 6 +#define AT91C_PWMC_FPVL7 (0x1 << 23) // (PWMC) Fault Protection Value for PWML output on channel 7 +// -------- PWMC_FPER1 : (PWMC Offset: 0x6c) PWM Fault Protection Enable Register 1 -------- +#define AT91C_PWMC_FPE0 (0xFF << 0) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 0 +#define AT91C_PWMC_FPE1 (0xFF << 8) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 1 +#define AT91C_PWMC_FPE2 (0xFF << 16) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 2 +#define AT91C_PWMC_FPE3 (0xFF << 24) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 3 +// -------- PWMC_FPER2 : (PWMC Offset: 0x70) PWM Fault Protection Enable Register 2 -------- +#define AT91C_PWMC_FPE4 (0xFF << 0) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 4 +#define AT91C_PWMC_FPE5 (0xFF << 8) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 5 +#define AT91C_PWMC_FPE6 (0xFF << 16) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 6 +#define AT91C_PWMC_FPE7 (0xFF << 24) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 7 +// -------- PWMC_FPER3 : (PWMC Offset: 0x74) PWM Fault Protection Enable Register 3 -------- +#define AT91C_PWMC_FPE8 (0xFF << 0) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 8 +#define AT91C_PWMC_FPE9 (0xFF << 8) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 9 +#define AT91C_PWMC_FPE10 (0xFF << 16) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 10 +#define AT91C_PWMC_FPE11 (0xFF << 24) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 11 +// -------- PWMC_FPER4 : (PWMC Offset: 0x78) PWM Fault Protection Enable Register 4 -------- +#define AT91C_PWMC_FPE12 (0xFF << 0) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 12 +#define AT91C_PWMC_FPE13 (0xFF << 8) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 13 +#define AT91C_PWMC_FPE14 (0xFF << 16) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 14 +#define AT91C_PWMC_FPE15 (0xFF << 24) // (PWMC) Fault Protection Enable with Fault Input y for PWM channel 15 +// -------- PWMC_EL0MR : (PWMC Offset: 0x7c) PWM Event Line 0 Mode Register -------- +#define AT91C_PWMC_L0CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L0CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L0CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L0CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L0CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L0CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L0CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L0CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL1MR : (PWMC Offset: 0x80) PWM Event Line 1 Mode Register -------- +#define AT91C_PWMC_L1CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L1CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L1CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L1CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L1CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L1CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L1CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L1CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL2MR : (PWMC Offset: 0x84) PWM Event line 2 Mode Register -------- +#define AT91C_PWMC_L2CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L2CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L2CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L2CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L2CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L2CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L2CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L2CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL3MR : (PWMC Offset: 0x88) PWM Event line 3 Mode Register -------- +#define AT91C_PWMC_L3CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L3CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L3CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L3CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L3CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L3CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L3CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L3CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL4MR : (PWMC Offset: 0x8c) PWM Event line 4 Mode Register -------- +#define AT91C_PWMC_L4CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L4CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L4CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L4CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L4CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L4CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L4CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L4CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL5MR : (PWMC Offset: 0x90) PWM Event line 5 Mode Register -------- +#define AT91C_PWMC_L5CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L5CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L5CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L5CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L5CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L5CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L5CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L5CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL6MR : (PWMC Offset: 0x94) PWM Event line 6 Mode Register -------- +#define AT91C_PWMC_L6CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L6CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L6CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L6CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L6CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L6CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L6CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L6CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_EL7MR : (PWMC Offset: 0x98) PWM Event line 7 Mode Register -------- +#define AT91C_PWMC_L7CSEL0 (0x1 << 0) // (PWMC) Comparison 0 Selection +#define AT91C_PWMC_L7CSEL1 (0x1 << 1) // (PWMC) Comparison 1 Selection +#define AT91C_PWMC_L7CSEL2 (0x1 << 2) // (PWMC) Comparison 2 Selection +#define AT91C_PWMC_L7CSEL3 (0x1 << 3) // (PWMC) Comparison 3 Selection +#define AT91C_PWMC_L7CSEL4 (0x1 << 4) // (PWMC) Comparison 4 Selection +#define AT91C_PWMC_L7CSEL5 (0x1 << 5) // (PWMC) Comparison 5 Selection +#define AT91C_PWMC_L7CSEL6 (0x1 << 6) // (PWMC) Comparison 6 Selection +#define AT91C_PWMC_L7CSEL7 (0x1 << 7) // (PWMC) Comparison 7 Selection +// -------- PWMC_WPCR : (PWMC Offset: 0xe4) PWM Write Protection Control Register -------- +#define AT91C_PWMC_WPCMD (0x3 << 0) // (PWMC) Write Protection Command +#define AT91C_PWMC_WPRG0 (0x1 << 2) // (PWMC) Write Protect Register Group 0 +#define AT91C_PWMC_WPRG1 (0x1 << 3) // (PWMC) Write Protect Register Group 1 +#define AT91C_PWMC_WPRG2 (0x1 << 4) // (PWMC) Write Protect Register Group 2 +#define AT91C_PWMC_WPRG3 (0x1 << 5) // (PWMC) Write Protect Register Group 3 +#define AT91C_PWMC_WPRG4 (0x1 << 6) // (PWMC) Write Protect Register Group 4 +#define AT91C_PWMC_WPRG5 (0x1 << 7) // (PWMC) Write Protect Register Group 5 +#define AT91C_PWMC_WPKEY (0xFFFFFF << 8) // (PWMC) Protection Password +// -------- PWMC_WPVS : (PWMC Offset: 0xe8) Write Protection Status Register -------- +#define AT91C_PWMC_WPSWS0 (0x1 << 0) // (PWMC) Write Protect SW Group 0 Status +#define AT91C_PWMC_WPSWS1 (0x1 << 1) // (PWMC) Write Protect SW Group 1 Status +#define AT91C_PWMC_WPSWS2 (0x1 << 2) // (PWMC) Write Protect SW Group 2 Status +#define AT91C_PWMC_WPSWS3 (0x1 << 3) // (PWMC) Write Protect SW Group 3 Status +#define AT91C_PWMC_WPSWS4 (0x1 << 4) // (PWMC) Write Protect SW Group 4 Status +#define AT91C_PWMC_WPSWS5 (0x1 << 5) // (PWMC) Write Protect SW Group 5 Status +#define AT91C_PWMC_WPVS (0x1 << 7) // (PWMC) Write Protection Enable +#define AT91C_PWMC_WPHWS0 (0x1 << 8) // (PWMC) Write Protect HW Group 0 Status +#define AT91C_PWMC_WPHWS1 (0x1 << 9) // (PWMC) Write Protect HW Group 1 Status +#define AT91C_PWMC_WPHWS2 (0x1 << 10) // (PWMC) Write Protect HW Group 2 Status +#define AT91C_PWMC_WPHWS3 (0x1 << 11) // (PWMC) Write Protect HW Group 3 Status +#define AT91C_PWMC_WPHWS4 (0x1 << 12) // (PWMC) Write Protect HW Group 4 Status +#define AT91C_PWMC_WPHWS5 (0x1 << 13) // (PWMC) Write Protect HW Group 5 Status +#define AT91C_PWMC_WPVSRC (0xFFFF << 16) // (PWMC) Write Protection Violation Source +// -------- PWMC_CMP0V : (PWMC Offset: 0x130) PWM Comparison Value 0 Register -------- +#define AT91C_PWMC_CV (0xFFFFFF << 0) // (PWMC) PWM Comparison Value 0. +#define AT91C_PWMC_CVM (0x1 << 24) // (PWMC) Comparison Value 0 Mode. +// -------- PWMC_CMP0VUPD : (PWMC Offset: 0x134) PWM Comparison Value 0 Update Register -------- +#define AT91C_PWMC_CVUPD (0xFFFFFF << 0) // (PWMC) PWM Comparison Value Update. +#define AT91C_PWMC_CVMUPD (0x1 << 24) // (PWMC) Comparison Value Update Mode. +// -------- PWMC_CMP0M : (PWMC Offset: 0x138) PWM Comparison 0 Mode Register -------- +#define AT91C_PWMC_CEN (0x1 << 0) // (PWMC) Comparison Enable. +#define AT91C_PWMC_CTR (0xF << 4) // (PWMC) PWM Comparison Trigger. +#define AT91C_PWMC_CPR (0xF << 8) // (PWMC) PWM Comparison Period. +#define AT91C_PWMC_CPRCNT (0xF << 12) // (PWMC) PWM Comparison Period Counter. +#define AT91C_PWMC_CUPR (0xF << 16) // (PWMC) PWM Comparison Update Period. +#define AT91C_PWMC_CUPRCNT (0xF << 20) // (PWMC) PWM Comparison Update Period Counter. +// -------- PWMC_CMP0MUPD : (PWMC Offset: 0x13c) PWM Comparison 0 Mode Update Register -------- +#define AT91C_PWMC_CENUPD (0x1 << 0) // (PWMC) Comparison Enable Update. +#define AT91C_PWMC_CTRUPD (0xF << 4) // (PWMC) PWM Comparison Trigger Update. +#define AT91C_PWMC_CPRUPD (0xF << 8) // (PWMC) PWM Comparison Period Update. +#define AT91C_PWMC_CUPRUPD (0xF << 16) // (PWMC) PWM Comparison Update Period Update. +// -------- PWMC_CMP1V : (PWMC Offset: 0x140) PWM Comparison Value 1 Register -------- +// -------- PWMC_CMP1VUPD : (PWMC Offset: 0x144) PWM Comparison Value 1 Update Register -------- +// -------- PWMC_CMP1M : (PWMC Offset: 0x148) PWM Comparison 1 Mode Register -------- +// -------- PWMC_CMP1MUPD : (PWMC Offset: 0x14c) PWM Comparison 1 Mode Update Register -------- +// -------- PWMC_CMP2V : (PWMC Offset: 0x150) PWM Comparison Value 2 Register -------- +// -------- PWMC_CMP2VUPD : (PWMC Offset: 0x154) PWM Comparison Value 2 Update Register -------- +// -------- PWMC_CMP2M : (PWMC Offset: 0x158) PWM Comparison 2 Mode Register -------- +// -------- PWMC_CMP2MUPD : (PWMC Offset: 0x15c) PWM Comparison 2 Mode Update Register -------- +// -------- PWMC_CMP3V : (PWMC Offset: 0x160) PWM Comparison Value 3 Register -------- +// -------- PWMC_CMP3VUPD : (PWMC Offset: 0x164) PWM Comparison Value 3 Update Register -------- +// -------- PWMC_CMP3M : (PWMC Offset: 0x168) PWM Comparison 3 Mode Register -------- +// -------- PWMC_CMP3MUPD : (PWMC Offset: 0x16c) PWM Comparison 3 Mode Update Register -------- +// -------- PWMC_CMP4V : (PWMC Offset: 0x170) PWM Comparison Value 4 Register -------- +// -------- PWMC_CMP4VUPD : (PWMC Offset: 0x174) PWM Comparison Value 4 Update Register -------- +// -------- PWMC_CMP4M : (PWMC Offset: 0x178) PWM Comparison 4 Mode Register -------- +// -------- PWMC_CMP4MUPD : (PWMC Offset: 0x17c) PWM Comparison 4 Mode Update Register -------- +// -------- PWMC_CMP5V : (PWMC Offset: 0x180) PWM Comparison Value 5 Register -------- +// -------- PWMC_CMP5VUPD : (PWMC Offset: 0x184) PWM Comparison Value 5 Update Register -------- +// -------- PWMC_CMP5M : (PWMC Offset: 0x188) PWM Comparison 5 Mode Register -------- +// -------- PWMC_CMP5MUPD : (PWMC Offset: 0x18c) PWM Comparison 5 Mode Update Register -------- +// -------- PWMC_CMP6V : (PWMC Offset: 0x190) PWM Comparison Value 6 Register -------- +// -------- PWMC_CMP6VUPD : (PWMC Offset: 0x194) PWM Comparison Value 6 Update Register -------- +// -------- PWMC_CMP6M : (PWMC Offset: 0x198) PWM Comparison 6 Mode Register -------- +// -------- PWMC_CMP6MUPD : (PWMC Offset: 0x19c) PWM Comparison 6 Mode Update Register -------- +// -------- PWMC_CMP7V : (PWMC Offset: 0x1a0) PWM Comparison Value 7 Register -------- +// -------- PWMC_CMP7VUPD : (PWMC Offset: 0x1a4) PWM Comparison Value 7 Update Register -------- +// -------- PWMC_CMP7M : (PWMC Offset: 0x1a8) PWM Comparison 7 Mode Register -------- +// -------- PWMC_CMP7MUPD : (PWMC Offset: 0x1ac) PWM Comparison 7 Mode Update Register -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR Serial Parallel Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_SPI { + AT91_REG SPI_CR; // Control Register + AT91_REG SPI_MR; // Mode Register + AT91_REG SPI_RDR; // Receive Data Register + AT91_REG SPI_TDR; // Transmit Data Register + AT91_REG SPI_SR; // Status Register + AT91_REG SPI_IER; // Interrupt Enable Register + AT91_REG SPI_IDR; // Interrupt Disable Register + AT91_REG SPI_IMR; // Interrupt Mask Register + AT91_REG Reserved0[4]; // + AT91_REG SPI_CSR[4]; // Chip Select Register + AT91_REG Reserved1[43]; // + AT91_REG SPI_ADDRSIZE; // SPI ADDRSIZE REGISTER + AT91_REG SPI_IPNAME1; // SPI IPNAME1 REGISTER + AT91_REG SPI_IPNAME2; // SPI IPNAME2 REGISTER + AT91_REG SPI_FEATURES; // SPI FEATURES REGISTER + AT91_REG SPI_VER; // Version Register + AT91_REG SPI_RPR; // Receive Pointer Register + AT91_REG SPI_RCR; // Receive Counter Register + AT91_REG SPI_TPR; // Transmit Pointer Register + AT91_REG SPI_TCR; // Transmit Counter Register + AT91_REG SPI_RNPR; // Receive Next Pointer Register + AT91_REG SPI_RNCR; // Receive Next Counter Register + AT91_REG SPI_TNPR; // Transmit Next Pointer Register + AT91_REG SPI_TNCR; // Transmit Next Counter Register + AT91_REG SPI_PTCR; // PDC Transfer Control Register + AT91_REG SPI_PTSR; // PDC Transfer Status Register +} AT91S_SPI, *AT91PS_SPI; +#else +#define SPI_CR (AT91_CAST(AT91_REG *) 0x00000000) // (SPI_CR) Control Register +#define SPI_MR (AT91_CAST(AT91_REG *) 0x00000004) // (SPI_MR) Mode Register +#define SPI_RDR (AT91_CAST(AT91_REG *) 0x00000008) // (SPI_RDR) Receive Data Register +#define SPI_TDR (AT91_CAST(AT91_REG *) 0x0000000C) // (SPI_TDR) Transmit Data Register +#define SPI_SR (AT91_CAST(AT91_REG *) 0x00000010) // (SPI_SR) Status Register +#define SPI_IER (AT91_CAST(AT91_REG *) 0x00000014) // (SPI_IER) Interrupt Enable Register +#define SPI_IDR (AT91_CAST(AT91_REG *) 0x00000018) // (SPI_IDR) Interrupt Disable Register +#define SPI_IMR (AT91_CAST(AT91_REG *) 0x0000001C) // (SPI_IMR) Interrupt Mask Register +#define SPI_CSR (AT91_CAST(AT91_REG *) 0x00000030) // (SPI_CSR) Chip Select Register +#define SPI_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (SPI_ADDRSIZE) SPI ADDRSIZE REGISTER +#define SPI_IPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (SPI_IPNAME1) SPI IPNAME1 REGISTER +#define SPI_IPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (SPI_IPNAME2) SPI IPNAME2 REGISTER +#define SPI_FEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (SPI_FEATURES) SPI FEATURES REGISTER +#define SPI_VER (AT91_CAST(AT91_REG *) 0x000000FC) // (SPI_VER) Version Register + +#endif +// -------- SPI_CR : (SPI Offset: 0x0) SPI Control Register -------- +#define AT91C_SPI_SPIEN (0x1 << 0) // (SPI) SPI Enable +#define AT91C_SPI_SPIDIS (0x1 << 1) // (SPI) SPI Disable +#define AT91C_SPI_SWRST (0x1 << 7) // (SPI) SPI Software reset +#define AT91C_SPI_LASTXFER (0x1 << 24) // (SPI) SPI Last Transfer +// -------- SPI_MR : (SPI Offset: 0x4) SPI Mode Register -------- +#define AT91C_SPI_MSTR (0x1 << 0) // (SPI) Master/Slave Mode +#define AT91C_SPI_PS (0x1 << 1) // (SPI) Peripheral Select +#define AT91C_SPI_PS_FIXED (0x0 << 1) // (SPI) Fixed Peripheral Select +#define AT91C_SPI_PS_VARIABLE (0x1 << 1) // (SPI) Variable Peripheral Select +#define AT91C_SPI_PCSDEC (0x1 << 2) // (SPI) Chip Select Decode +#define AT91C_SPI_FDIV (0x1 << 3) // (SPI) Clock Selection +#define AT91C_SPI_MODFDIS (0x1 << 4) // (SPI) Mode Fault Detection +#define AT91C_SPI_LLB (0x1 << 7) // (SPI) Clock Selection +#define AT91C_SPI_PCS (0xF << 16) // (SPI) Peripheral Chip Select +#define AT91C_SPI_DLYBCS (0xFF << 24) // (SPI) Delay Between Chip Selects +// -------- SPI_RDR : (SPI Offset: 0x8) Receive Data Register -------- +#define AT91C_SPI_RD (0xFFFF << 0) // (SPI) Receive Data +#define AT91C_SPI_RPCS (0xF << 16) // (SPI) Peripheral Chip Select Status +// -------- SPI_TDR : (SPI Offset: 0xc) Transmit Data Register -------- +#define AT91C_SPI_TD (0xFFFF << 0) // (SPI) Transmit Data +#define AT91C_SPI_TPCS (0xF << 16) // (SPI) Peripheral Chip Select Status +// -------- SPI_SR : (SPI Offset: 0x10) Status Register -------- +#define AT91C_SPI_RDRF (0x1 << 0) // (SPI) Receive Data Register Full +#define AT91C_SPI_TDRE (0x1 << 1) // (SPI) Transmit Data Register Empty +#define AT91C_SPI_MODF (0x1 << 2) // (SPI) Mode Fault Error +#define AT91C_SPI_OVRES (0x1 << 3) // (SPI) Overrun Error Status +#define AT91C_SPI_ENDRX (0x1 << 4) // (SPI) End of Receiver Transfer +#define AT91C_SPI_ENDTX (0x1 << 5) // (SPI) End of Receiver Transfer +#define AT91C_SPI_RXBUFF (0x1 << 6) // (SPI) RXBUFF Interrupt +#define AT91C_SPI_TXBUFE (0x1 << 7) // (SPI) TXBUFE Interrupt +#define AT91C_SPI_NSSR (0x1 << 8) // (SPI) NSSR Interrupt +#define AT91C_SPI_TXEMPTY (0x1 << 9) // (SPI) TXEMPTY Interrupt +#define AT91C_SPI_SPIENS (0x1 << 16) // (SPI) Enable Status +// -------- SPI_IER : (SPI Offset: 0x14) Interrupt Enable Register -------- +// -------- SPI_IDR : (SPI Offset: 0x18) Interrupt Disable Register -------- +// -------- SPI_IMR : (SPI Offset: 0x1c) Interrupt Mask Register -------- +// -------- SPI_CSR : (SPI Offset: 0x30) Chip Select Register -------- +#define AT91C_SPI_CPOL (0x1 << 0) // (SPI) Clock Polarity +#define AT91C_SPI_NCPHA (0x1 << 1) // (SPI) Clock Phase +#define AT91C_SPI_CSNAAT (0x1 << 2) // (SPI) Chip Select Not Active After Transfer (Ignored if CSAAT = 1) +#define AT91C_SPI_CSAAT (0x1 << 3) // (SPI) Chip Select Active After Transfer +#define AT91C_SPI_BITS (0xF << 4) // (SPI) Bits Per Transfer +#define AT91C_SPI_BITS_8 (0x0 << 4) // (SPI) 8 Bits Per transfer +#define AT91C_SPI_BITS_9 (0x1 << 4) // (SPI) 9 Bits Per transfer +#define AT91C_SPI_BITS_10 (0x2 << 4) // (SPI) 10 Bits Per transfer +#define AT91C_SPI_BITS_11 (0x3 << 4) // (SPI) 11 Bits Per transfer +#define AT91C_SPI_BITS_12 (0x4 << 4) // (SPI) 12 Bits Per transfer +#define AT91C_SPI_BITS_13 (0x5 << 4) // (SPI) 13 Bits Per transfer +#define AT91C_SPI_BITS_14 (0x6 << 4) // (SPI) 14 Bits Per transfer +#define AT91C_SPI_BITS_15 (0x7 << 4) // (SPI) 15 Bits Per transfer +#define AT91C_SPI_BITS_16 (0x8 << 4) // (SPI) 16 Bits Per transfer +#define AT91C_SPI_SCBR (0xFF << 8) // (SPI) Serial Clock Baud Rate +#define AT91C_SPI_DLYBS (0xFF << 16) // (SPI) Serial Clock Baud Rate +#define AT91C_SPI_DLYBCT (0xFF << 24) // (SPI) Delay Between Consecutive Transfers + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR UDPHS Enpoint FIFO data register +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_UDPHS_EPTFIFO { + AT91_REG UDPHS_READEPT0[16384]; // FIFO Endpoint Data Register 0 + AT91_REG UDPHS_READEPT1[16384]; // FIFO Endpoint Data Register 1 + AT91_REG UDPHS_READEPT2[16384]; // FIFO Endpoint Data Register 2 + AT91_REG UDPHS_READEPT3[16384]; // FIFO Endpoint Data Register 3 + AT91_REG UDPHS_READEPT4[16384]; // FIFO Endpoint Data Register 4 + AT91_REG UDPHS_READEPT5[16384]; // FIFO Endpoint Data Register 5 + AT91_REG UDPHS_READEPT6[16384]; // FIFO Endpoint Data Register 6 +} AT91S_UDPHS_EPTFIFO, *AT91PS_UDPHS_EPTFIFO; +#else +#define UDPHS_READEPT0 (AT91_CAST(AT91_REG *) 0x00000000) // (UDPHS_READEPT0) FIFO Endpoint Data Register 0 +#define UDPHS_READEPT1 (AT91_CAST(AT91_REG *) 0x00010000) // (UDPHS_READEPT1) FIFO Endpoint Data Register 1 +#define UDPHS_READEPT2 (AT91_CAST(AT91_REG *) 0x00020000) // (UDPHS_READEPT2) FIFO Endpoint Data Register 2 +#define UDPHS_READEPT3 (AT91_CAST(AT91_REG *) 0x00030000) // (UDPHS_READEPT3) FIFO Endpoint Data Register 3 +#define UDPHS_READEPT4 (AT91_CAST(AT91_REG *) 0x00040000) // (UDPHS_READEPT4) FIFO Endpoint Data Register 4 +#define UDPHS_READEPT5 (AT91_CAST(AT91_REG *) 0x00050000) // (UDPHS_READEPT5) FIFO Endpoint Data Register 5 +#define UDPHS_READEPT6 (AT91_CAST(AT91_REG *) 0x00060000) // (UDPHS_READEPT6) FIFO Endpoint Data Register 6 + +#endif + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR UDPHS Endpoint struct +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_UDPHS_EPT { + AT91_REG UDPHS_EPTCFG; // UDPHS Endpoint Config Register + AT91_REG UDPHS_EPTCTLENB; // UDPHS Endpoint Control Enable Register + AT91_REG UDPHS_EPTCTLDIS; // UDPHS Endpoint Control Disable Register + AT91_REG UDPHS_EPTCTL; // UDPHS Endpoint Control Register + AT91_REG Reserved0[1]; // + AT91_REG UDPHS_EPTSETSTA; // UDPHS Endpoint Set Status Register + AT91_REG UDPHS_EPTCLRSTA; // UDPHS Endpoint Clear Status Register + AT91_REG UDPHS_EPTSTA; // UDPHS Endpoint Status Register +} AT91S_UDPHS_EPT, *AT91PS_UDPHS_EPT; +#else +#define UDPHS_EPTCFG (AT91_CAST(AT91_REG *) 0x00000000) // (UDPHS_EPTCFG) UDPHS Endpoint Config Register +#define UDPHS_EPTCTLENB (AT91_CAST(AT91_REG *) 0x00000004) // (UDPHS_EPTCTLENB) UDPHS Endpoint Control Enable Register +#define UDPHS_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x00000008) // (UDPHS_EPTCTLDIS) UDPHS Endpoint Control Disable Register +#define UDPHS_EPTCTL (AT91_CAST(AT91_REG *) 0x0000000C) // (UDPHS_EPTCTL) UDPHS Endpoint Control Register +#define UDPHS_EPTSETSTA (AT91_CAST(AT91_REG *) 0x00000014) // (UDPHS_EPTSETSTA) UDPHS Endpoint Set Status Register +#define UDPHS_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x00000018) // (UDPHS_EPTCLRSTA) UDPHS Endpoint Clear Status Register +#define UDPHS_EPTSTA (AT91_CAST(AT91_REG *) 0x0000001C) // (UDPHS_EPTSTA) UDPHS Endpoint Status Register + +#endif +// -------- UDPHS_EPTCFG : (UDPHS_EPT Offset: 0x0) UDPHS Endpoint Config Register -------- +#define AT91C_UDPHS_EPT_SIZE (0x7 << 0) // (UDPHS_EPT) Endpoint Size +#define AT91C_UDPHS_EPT_SIZE_8 (0x0) // (UDPHS_EPT) 8 bytes +#define AT91C_UDPHS_EPT_SIZE_16 (0x1) // (UDPHS_EPT) 16 bytes +#define AT91C_UDPHS_EPT_SIZE_32 (0x2) // (UDPHS_EPT) 32 bytes +#define AT91C_UDPHS_EPT_SIZE_64 (0x3) // (UDPHS_EPT) 64 bytes +#define AT91C_UDPHS_EPT_SIZE_128 (0x4) // (UDPHS_EPT) 128 bytes +#define AT91C_UDPHS_EPT_SIZE_256 (0x5) // (UDPHS_EPT) 256 bytes (if possible) +#define AT91C_UDPHS_EPT_SIZE_512 (0x6) // (UDPHS_EPT) 512 bytes (if possible) +#define AT91C_UDPHS_EPT_SIZE_1024 (0x7) // (UDPHS_EPT) 1024 bytes (if possible) +#define AT91C_UDPHS_EPT_DIR (0x1 << 3) // (UDPHS_EPT) Endpoint Direction 0:OUT, 1:IN +#define AT91C_UDPHS_EPT_DIR_OUT (0x0 << 3) // (UDPHS_EPT) Direction OUT +#define AT91C_UDPHS_EPT_DIR_IN (0x1 << 3) // (UDPHS_EPT) Direction IN +#define AT91C_UDPHS_EPT_TYPE (0x3 << 4) // (UDPHS_EPT) Endpoint Type +#define AT91C_UDPHS_EPT_TYPE_CTL_EPT (0x0 << 4) // (UDPHS_EPT) Control endpoint +#define AT91C_UDPHS_EPT_TYPE_ISO_EPT (0x1 << 4) // (UDPHS_EPT) Isochronous endpoint +#define AT91C_UDPHS_EPT_TYPE_BUL_EPT (0x2 << 4) // (UDPHS_EPT) Bulk endpoint +#define AT91C_UDPHS_EPT_TYPE_INT_EPT (0x3 << 4) // (UDPHS_EPT) Interrupt endpoint +#define AT91C_UDPHS_BK_NUMBER (0x3 << 6) // (UDPHS_EPT) Number of Banks +#define AT91C_UDPHS_BK_NUMBER_0 (0x0 << 6) // (UDPHS_EPT) Zero Bank, the EndPoint is not mapped in memory +#define AT91C_UDPHS_BK_NUMBER_1 (0x1 << 6) // (UDPHS_EPT) One Bank (Bank0) +#define AT91C_UDPHS_BK_NUMBER_2 (0x2 << 6) // (UDPHS_EPT) Double bank (Ping-Pong : Bank0 / Bank1) +#define AT91C_UDPHS_BK_NUMBER_3 (0x3 << 6) // (UDPHS_EPT) Triple Bank (Bank0 / Bank1 / Bank2) (if possible) +#define AT91C_UDPHS_NB_TRANS (0x3 << 8) // (UDPHS_EPT) Number Of Transaction per Micro-Frame (High-Bandwidth iso only) +#define AT91C_UDPHS_EPT_MAPD (0x1 << 31) // (UDPHS_EPT) Endpoint Mapped (read only +// -------- UDPHS_EPTCTLENB : (UDPHS_EPT Offset: 0x4) UDPHS Endpoint Control Enable Register -------- +#define AT91C_UDPHS_EPT_ENABL (0x1 << 0) // (UDPHS_EPT) Endpoint Enable +#define AT91C_UDPHS_AUTO_VALID (0x1 << 1) // (UDPHS_EPT) Packet Auto-Valid Enable/Disable +#define AT91C_UDPHS_INTDIS_DMA (0x1 << 3) // (UDPHS_EPT) Endpoint Interrupts DMA Request Enable/Disable +#define AT91C_UDPHS_NYET_DIS (0x1 << 4) // (UDPHS_EPT) NYET Enable/Disable +#define AT91C_UDPHS_DATAX_RX (0x1 << 6) // (UDPHS_EPT) DATAx Interrupt Enable/Disable +#define AT91C_UDPHS_MDATA_RX (0x1 << 7) // (UDPHS_EPT) MDATA Interrupt Enabled/Disable +#define AT91C_UDPHS_ERR_OVFLW (0x1 << 8) // (UDPHS_EPT) OverFlow Error Interrupt Enable/Disable/Status +#define AT91C_UDPHS_RX_BK_RDY (0x1 << 9) // (UDPHS_EPT) Received OUT Data +#define AT91C_UDPHS_TX_COMPLT (0x1 << 10) // (UDPHS_EPT) Transmitted IN Data Complete Interrupt Enable/Disable or Transmitted IN Data Complete (clear) +#define AT91C_UDPHS_ERR_TRANS (0x1 << 11) // (UDPHS_EPT) Transaction Error Interrupt Enable/Disable +#define AT91C_UDPHS_TX_PK_RDY (0x1 << 11) // (UDPHS_EPT) TX Packet Ready Interrupt Enable/Disable +#define AT91C_UDPHS_RX_SETUP (0x1 << 12) // (UDPHS_EPT) Received SETUP Interrupt Enable/Disable +#define AT91C_UDPHS_ERR_FL_ISO (0x1 << 12) // (UDPHS_EPT) Error Flow Clear/Interrupt Enable/Disable +#define AT91C_UDPHS_STALL_SNT (0x1 << 13) // (UDPHS_EPT) Stall Sent Clear +#define AT91C_UDPHS_ERR_CRISO (0x1 << 13) // (UDPHS_EPT) CRC error / Error NB Trans / Interrupt Enable/Disable +#define AT91C_UDPHS_NAK_IN (0x1 << 14) // (UDPHS_EPT) NAKIN ERROR FLUSH / Clear / Interrupt Enable/Disable +#define AT91C_UDPHS_NAK_OUT (0x1 << 15) // (UDPHS_EPT) NAKOUT / Clear / Interrupt Enable/Disable +#define AT91C_UDPHS_BUSY_BANK (0x1 << 18) // (UDPHS_EPT) Busy Bank Interrupt Enable/Disable +#define AT91C_UDPHS_SHRT_PCKT (0x1 << 31) // (UDPHS_EPT) Short Packet / Interrupt Enable/Disable +// -------- UDPHS_EPTCTLDIS : (UDPHS_EPT Offset: 0x8) UDPHS Endpoint Control Disable Register -------- +#define AT91C_UDPHS_EPT_DISABL (0x1 << 0) // (UDPHS_EPT) Endpoint Disable +// -------- UDPHS_EPTCTL : (UDPHS_EPT Offset: 0xc) UDPHS Endpoint Control Register -------- +// -------- UDPHS_EPTSETSTA : (UDPHS_EPT Offset: 0x14) UDPHS Endpoint Set Status Register -------- +#define AT91C_UDPHS_FRCESTALL (0x1 << 5) // (UDPHS_EPT) Stall Handshake Request Set/Clear/Status +#define AT91C_UDPHS_KILL_BANK (0x1 << 9) // (UDPHS_EPT) KILL Bank +// -------- UDPHS_EPTCLRSTA : (UDPHS_EPT Offset: 0x18) UDPHS Endpoint Clear Status Register -------- +#define AT91C_UDPHS_TOGGLESQ (0x1 << 6) // (UDPHS_EPT) Data Toggle Clear +// -------- UDPHS_EPTSTA : (UDPHS_EPT Offset: 0x1c) UDPHS Endpoint Status Register -------- +#define AT91C_UDPHS_TOGGLESQ_STA (0x3 << 6) // (UDPHS_EPT) Toggle Sequencing +#define AT91C_UDPHS_TOGGLESQ_STA_00 (0x0 << 6) // (UDPHS_EPT) Data0 +#define AT91C_UDPHS_TOGGLESQ_STA_01 (0x1 << 6) // (UDPHS_EPT) Data1 +#define AT91C_UDPHS_TOGGLESQ_STA_10 (0x2 << 6) // (UDPHS_EPT) Data2 (only for High-Bandwidth Isochronous EndPoint) +#define AT91C_UDPHS_TOGGLESQ_STA_11 (0x3 << 6) // (UDPHS_EPT) MData (only for High-Bandwidth Isochronous EndPoint) +#define AT91C_UDPHS_CONTROL_DIR (0x3 << 16) // (UDPHS_EPT) +#define AT91C_UDPHS_CONTROL_DIR_00 (0x0 << 16) // (UDPHS_EPT) Bank 0 +#define AT91C_UDPHS_CONTROL_DIR_01 (0x1 << 16) // (UDPHS_EPT) Bank 1 +#define AT91C_UDPHS_CONTROL_DIR_10 (0x2 << 16) // (UDPHS_EPT) Bank 2 +#define AT91C_UDPHS_CONTROL_DIR_11 (0x3 << 16) // (UDPHS_EPT) Invalid +#define AT91C_UDPHS_CURRENT_BANK (0x3 << 16) // (UDPHS_EPT) +#define AT91C_UDPHS_CURRENT_BANK_00 (0x0 << 16) // (UDPHS_EPT) Bank 0 +#define AT91C_UDPHS_CURRENT_BANK_01 (0x1 << 16) // (UDPHS_EPT) Bank 1 +#define AT91C_UDPHS_CURRENT_BANK_10 (0x2 << 16) // (UDPHS_EPT) Bank 2 +#define AT91C_UDPHS_CURRENT_BANK_11 (0x3 << 16) // (UDPHS_EPT) Invalid +#define AT91C_UDPHS_BUSY_BANK_STA (0x3 << 18) // (UDPHS_EPT) Busy Bank Number +#define AT91C_UDPHS_BUSY_BANK_STA_00 (0x0 << 18) // (UDPHS_EPT) All banks are free +#define AT91C_UDPHS_BUSY_BANK_STA_01 (0x1 << 18) // (UDPHS_EPT) 1 busy bank +#define AT91C_UDPHS_BUSY_BANK_STA_10 (0x2 << 18) // (UDPHS_EPT) 2 busy banks +#define AT91C_UDPHS_BUSY_BANK_STA_11 (0x3 << 18) // (UDPHS_EPT) 3 busy banks (if possible) +#define AT91C_UDPHS_BYTE_COUNT (0x7FF << 20) // (UDPHS_EPT) UDPHS Byte Count + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR UDPHS DMA struct +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_UDPHS_DMA { + AT91_REG UDPHS_DMANXTDSC; // UDPHS DMA Channel Next Descriptor Address + AT91_REG UDPHS_DMAADDRESS; // UDPHS DMA Channel Address Register + AT91_REG UDPHS_DMACONTROL; // UDPHS DMA Channel Control Register + AT91_REG UDPHS_DMASTATUS; // UDPHS DMA Channel Status Register +} AT91S_UDPHS_DMA, *AT91PS_UDPHS_DMA; +#else +#define UDPHS_DMANXTDSC (AT91_CAST(AT91_REG *) 0x00000000) // (UDPHS_DMANXTDSC) UDPHS DMA Channel Next Descriptor Address +#define UDPHS_DMAADDRESS (AT91_CAST(AT91_REG *) 0x00000004) // (UDPHS_DMAADDRESS) UDPHS DMA Channel Address Register +#define UDPHS_DMACONTROL (AT91_CAST(AT91_REG *) 0x00000008) // (UDPHS_DMACONTROL) UDPHS DMA Channel Control Register +#define UDPHS_DMASTATUS (AT91_CAST(AT91_REG *) 0x0000000C) // (UDPHS_DMASTATUS) UDPHS DMA Channel Status Register + +#endif +// -------- UDPHS_DMANXTDSC : (UDPHS_DMA Offset: 0x0) UDPHS DMA Next Descriptor Address Register -------- +#define AT91C_UDPHS_NXT_DSC_ADD (0xFFFFFFF << 4) // (UDPHS_DMA) next Channel Descriptor +// -------- UDPHS_DMAADDRESS : (UDPHS_DMA Offset: 0x4) UDPHS DMA Channel Address Register -------- +#define AT91C_UDPHS_BUFF_ADD (0x0 << 0) // (UDPHS_DMA) starting address of a DMA Channel transfer +// -------- UDPHS_DMACONTROL : (UDPHS_DMA Offset: 0x8) UDPHS DMA Channel Control Register -------- +#define AT91C_UDPHS_CHANN_ENB (0x1 << 0) // (UDPHS_DMA) Channel Enabled +#define AT91C_UDPHS_LDNXT_DSC (0x1 << 1) // (UDPHS_DMA) Load Next Channel Transfer Descriptor Enable +#define AT91C_UDPHS_END_TR_EN (0x1 << 2) // (UDPHS_DMA) Buffer Close Input Enable +#define AT91C_UDPHS_END_B_EN (0x1 << 3) // (UDPHS_DMA) End of DMA Buffer Packet Validation +#define AT91C_UDPHS_END_TR_IT (0x1 << 4) // (UDPHS_DMA) End Of Transfer Interrupt Enable +#define AT91C_UDPHS_END_BUFFIT (0x1 << 5) // (UDPHS_DMA) End Of Channel Buffer Interrupt Enable +#define AT91C_UDPHS_DESC_LD_IT (0x1 << 6) // (UDPHS_DMA) Descriptor Loaded Interrupt Enable +#define AT91C_UDPHS_BURST_LCK (0x1 << 7) // (UDPHS_DMA) Burst Lock Enable +#define AT91C_UDPHS_BUFF_LENGTH (0xFFFF << 16) // (UDPHS_DMA) Buffer Byte Length (write only) +// -------- UDPHS_DMASTATUS : (UDPHS_DMA Offset: 0xc) UDPHS DMA Channelx Status Register -------- +#define AT91C_UDPHS_CHANN_ACT (0x1 << 1) // (UDPHS_DMA) +#define AT91C_UDPHS_END_TR_ST (0x1 << 4) // (UDPHS_DMA) +#define AT91C_UDPHS_END_BF_ST (0x1 << 5) // (UDPHS_DMA) +#define AT91C_UDPHS_DESC_LDST (0x1 << 6) // (UDPHS_DMA) +#define AT91C_UDPHS_BUFF_COUNT (0xFFFF << 16) // (UDPHS_DMA) + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR UDPHS High Speed Device Interface +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_UDPHS { + AT91_REG UDPHS_CTRL; // UDPHS Control Register + AT91_REG UDPHS_FNUM; // UDPHS Frame Number Register + AT91_REG Reserved0[2]; // + AT91_REG UDPHS_IEN; // UDPHS Interrupt Enable Register + AT91_REG UDPHS_INTSTA; // UDPHS Interrupt Status Register + AT91_REG UDPHS_CLRINT; // UDPHS Clear Interrupt Register + AT91_REG UDPHS_EPTRST; // UDPHS Endpoints Reset Register + AT91_REG Reserved1[44]; // + AT91_REG UDPHS_TSTSOFCNT; // UDPHS Test SOF Counter Register + AT91_REG UDPHS_TSTCNTA; // UDPHS Test A Counter Register + AT91_REG UDPHS_TSTCNTB; // UDPHS Test B Counter Register + AT91_REG UDPHS_TSTMODREG; // UDPHS Test Mode Register + AT91_REG UDPHS_TST; // UDPHS Test Register + AT91_REG Reserved2[2]; // + AT91_REG UDPHS_RIPPADDRSIZE; // UDPHS PADDRSIZE Register + AT91_REG UDPHS_RIPNAME1; // UDPHS Name1 Register + AT91_REG UDPHS_RIPNAME2; // UDPHS Name2 Register + AT91_REG UDPHS_IPFEATURES; // UDPHS Features Register + AT91_REG UDPHS_IPVERSION; // UDPHS Version Register + AT91S_UDPHS_EPT UDPHS_EPT[7]; // UDPHS Endpoint struct + AT91_REG Reserved3[72]; // + AT91S_UDPHS_DMA UDPHS_DMA[6]; // UDPHS DMA channel struct (not use [0]) +} AT91S_UDPHS, *AT91PS_UDPHS; +#else +#define UDPHS_CTRL (AT91_CAST(AT91_REG *) 0x00000000) // (UDPHS_CTRL) UDPHS Control Register +#define UDPHS_FNUM (AT91_CAST(AT91_REG *) 0x00000004) // (UDPHS_FNUM) UDPHS Frame Number Register +#define UDPHS_IEN (AT91_CAST(AT91_REG *) 0x00000010) // (UDPHS_IEN) UDPHS Interrupt Enable Register +#define UDPHS_INTSTA (AT91_CAST(AT91_REG *) 0x00000014) // (UDPHS_INTSTA) UDPHS Interrupt Status Register +#define UDPHS_CLRINT (AT91_CAST(AT91_REG *) 0x00000018) // (UDPHS_CLRINT) UDPHS Clear Interrupt Register +#define UDPHS_EPTRST (AT91_CAST(AT91_REG *) 0x0000001C) // (UDPHS_EPTRST) UDPHS Endpoints Reset Register +#define UDPHS_TSTSOFCNT (AT91_CAST(AT91_REG *) 0x000000D0) // (UDPHS_TSTSOFCNT) UDPHS Test SOF Counter Register +#define UDPHS_TSTCNTA (AT91_CAST(AT91_REG *) 0x000000D4) // (UDPHS_TSTCNTA) UDPHS Test A Counter Register +#define UDPHS_TSTCNTB (AT91_CAST(AT91_REG *) 0x000000D8) // (UDPHS_TSTCNTB) UDPHS Test B Counter Register +#define UDPHS_TSTMODREG (AT91_CAST(AT91_REG *) 0x000000DC) // (UDPHS_TSTMODREG) UDPHS Test Mode Register +#define UDPHS_TST (AT91_CAST(AT91_REG *) 0x000000E0) // (UDPHS_TST) UDPHS Test Register +#define UDPHS_RIPPADDRSIZE (AT91_CAST(AT91_REG *) 0x000000EC) // (UDPHS_RIPPADDRSIZE) UDPHS PADDRSIZE Register +#define UDPHS_RIPNAME1 (AT91_CAST(AT91_REG *) 0x000000F0) // (UDPHS_RIPNAME1) UDPHS Name1 Register +#define UDPHS_RIPNAME2 (AT91_CAST(AT91_REG *) 0x000000F4) // (UDPHS_RIPNAME2) UDPHS Name2 Register +#define UDPHS_IPFEATURES (AT91_CAST(AT91_REG *) 0x000000F8) // (UDPHS_IPFEATURES) UDPHS Features Register +#define UDPHS_IPVERSION (AT91_CAST(AT91_REG *) 0x000000FC) // (UDPHS_IPVERSION) UDPHS Version Register + +#endif +// -------- UDPHS_CTRL : (UDPHS Offset: 0x0) UDPHS Control Register -------- +#define AT91C_UDPHS_DEV_ADDR (0x7F << 0) // (UDPHS) UDPHS Address +#define AT91C_UDPHS_FADDR_EN (0x1 << 7) // (UDPHS) Function Address Enable +#define AT91C_UDPHS_EN_UDPHS (0x1 << 8) // (UDPHS) UDPHS Enable +#define AT91C_UDPHS_DETACH (0x1 << 9) // (UDPHS) Detach Command +#define AT91C_UDPHS_REWAKEUP (0x1 << 10) // (UDPHS) Send Remote Wake Up +#define AT91C_UDPHS_PULLD_DIS (0x1 << 11) // (UDPHS) PullDown Disable +// -------- UDPHS_FNUM : (UDPHS Offset: 0x4) UDPHS Frame Number Register -------- +#define AT91C_UDPHS_MICRO_FRAME_NUM (0x7 << 0) // (UDPHS) Micro Frame Number +#define AT91C_UDPHS_FRAME_NUMBER (0x7FF << 3) // (UDPHS) Frame Number as defined in the Packet Field Formats +#define AT91C_UDPHS_FNUM_ERR (0x1 << 31) // (UDPHS) Frame Number CRC Error +// -------- UDPHS_IEN : (UDPHS Offset: 0x10) UDPHS Interrupt Enable Register -------- +#define AT91C_UDPHS_DET_SUSPD (0x1 << 1) // (UDPHS) Suspend Interrupt Enable/Clear/Status +#define AT91C_UDPHS_MICRO_SOF (0x1 << 2) // (UDPHS) Micro-SOF Interrupt Enable/Clear/Status +#define AT91C_UDPHS_IEN_SOF (0x1 << 3) // (UDPHS) SOF Interrupt Enable/Clear/Status +#define AT91C_UDPHS_ENDRESET (0x1 << 4) // (UDPHS) End Of Reset Interrupt Enable/Clear/Status +#define AT91C_UDPHS_WAKE_UP (0x1 << 5) // (UDPHS) Wake Up CPU Interrupt Enable/Clear/Status +#define AT91C_UDPHS_ENDOFRSM (0x1 << 6) // (UDPHS) End Of Resume Interrupt Enable/Clear/Status +#define AT91C_UDPHS_UPSTR_RES (0x1 << 7) // (UDPHS) Upstream Resume Interrupt Enable/Clear/Status +#define AT91C_UDPHS_EPT_INT_0 (0x1 << 8) // (UDPHS) Endpoint 0 Interrupt Enable/Status +#define AT91C_UDPHS_EPT_INT_1 (0x1 << 9) // (UDPHS) Endpoint 1 Interrupt Enable/Status +#define AT91C_UDPHS_EPT_INT_2 (0x1 << 10) // (UDPHS) Endpoint 2 Interrupt Enable/Status +#define AT91C_UDPHS_EPT_INT_3 (0x1 << 11) // (UDPHS) Endpoint 3 Interrupt Enable/Status +#define AT91C_UDPHS_EPT_INT_4 (0x1 << 12) // (UDPHS) Endpoint 4 Interrupt Enable/Status +#define AT91C_UDPHS_EPT_INT_5 (0x1 << 13) // (UDPHS) Endpoint 5 Interrupt Enable/Status +#define AT91C_UDPHS_EPT_INT_6 (0x1 << 14) // (UDPHS) Endpoint 6 Interrupt Enable/Status +#define AT91C_UDPHS_DMA_INT_1 (0x1 << 25) // (UDPHS) DMA Channel 1 Interrupt Enable/Status +#define AT91C_UDPHS_DMA_INT_2 (0x1 << 26) // (UDPHS) DMA Channel 2 Interrupt Enable/Status +#define AT91C_UDPHS_DMA_INT_3 (0x1 << 27) // (UDPHS) DMA Channel 3 Interrupt Enable/Status +#define AT91C_UDPHS_DMA_INT_4 (0x1 << 28) // (UDPHS) DMA Channel 4 Interrupt Enable/Status +#define AT91C_UDPHS_DMA_INT_5 (0x1 << 29) // (UDPHS) DMA Channel 5 Interrupt Enable/Status +#define AT91C_UDPHS_DMA_INT_6 (0x1 << 30) // (UDPHS) DMA Channel 6 Interrupt Enable/Status +// -------- UDPHS_INTSTA : (UDPHS Offset: 0x14) UDPHS Interrupt Status Register -------- +#define AT91C_UDPHS_SPEED (0x1 << 0) // (UDPHS) Speed Status +// -------- UDPHS_CLRINT : (UDPHS Offset: 0x18) UDPHS Clear Interrupt Register -------- +// -------- UDPHS_EPTRST : (UDPHS Offset: 0x1c) UDPHS Endpoints Reset Register -------- +#define AT91C_UDPHS_RST_EPT_0 (0x1 << 0) // (UDPHS) Endpoint Reset 0 +#define AT91C_UDPHS_RST_EPT_1 (0x1 << 1) // (UDPHS) Endpoint Reset 1 +#define AT91C_UDPHS_RST_EPT_2 (0x1 << 2) // (UDPHS) Endpoint Reset 2 +#define AT91C_UDPHS_RST_EPT_3 (0x1 << 3) // (UDPHS) Endpoint Reset 3 +#define AT91C_UDPHS_RST_EPT_4 (0x1 << 4) // (UDPHS) Endpoint Reset 4 +#define AT91C_UDPHS_RST_EPT_5 (0x1 << 5) // (UDPHS) Endpoint Reset 5 +#define AT91C_UDPHS_RST_EPT_6 (0x1 << 6) // (UDPHS) Endpoint Reset 6 +// -------- UDPHS_TSTSOFCNT : (UDPHS Offset: 0xd0) UDPHS Test SOF Counter Register -------- +#define AT91C_UDPHS_SOFCNTMAX (0x3 << 0) // (UDPHS) SOF Counter Max Value +#define AT91C_UDPHS_SOFCTLOAD (0x1 << 7) // (UDPHS) SOF Counter Load +// -------- UDPHS_TSTCNTA : (UDPHS Offset: 0xd4) UDPHS Test A Counter Register -------- +#define AT91C_UDPHS_CNTAMAX (0x7FFF << 0) // (UDPHS) A Counter Max Value +#define AT91C_UDPHS_CNTALOAD (0x1 << 15) // (UDPHS) A Counter Load +// -------- UDPHS_TSTCNTB : (UDPHS Offset: 0xd8) UDPHS Test B Counter Register -------- +#define AT91C_UDPHS_CNTBMAX (0x7FFF << 0) // (UDPHS) B Counter Max Value +#define AT91C_UDPHS_CNTBLOAD (0x1 << 15) // (UDPHS) B Counter Load +// -------- UDPHS_TSTMODREG : (UDPHS Offset: 0xdc) UDPHS Test Mode Register -------- +#define AT91C_UDPHS_TSTMODE (0x1F << 1) // (UDPHS) UDPHS Core TestModeReg +// -------- UDPHS_TST : (UDPHS Offset: 0xe0) UDPHS Test Register -------- +#define AT91C_UDPHS_SPEED_CFG (0x3 << 0) // (UDPHS) Speed Configuration +#define AT91C_UDPHS_SPEED_CFG_NM (0x0) // (UDPHS) Normal Mode +#define AT91C_UDPHS_SPEED_CFG_RS (0x1) // (UDPHS) Reserved +#define AT91C_UDPHS_SPEED_CFG_HS (0x2) // (UDPHS) Force High Speed +#define AT91C_UDPHS_SPEED_CFG_FS (0x3) // (UDPHS) Force Full-Speed +#define AT91C_UDPHS_TST_J (0x1 << 2) // (UDPHS) TestJMode +#define AT91C_UDPHS_TST_K (0x1 << 3) // (UDPHS) TestKMode +#define AT91C_UDPHS_TST_PKT (0x1 << 4) // (UDPHS) TestPacketMode +#define AT91C_UDPHS_OPMODE2 (0x1 << 5) // (UDPHS) OpMode2 +// -------- UDPHS_RIPPADDRSIZE : (UDPHS Offset: 0xec) UDPHS PADDRSIZE Register -------- +#define AT91C_UDPHS_IPPADDRSIZE (0x0 << 0) // (UDPHS) 2^UDPHSDEV_PADDR_SIZE +// -------- UDPHS_RIPNAME1 : (UDPHS Offset: 0xf0) UDPHS Name Register -------- +#define AT91C_UDPHS_IPNAME1 (0x0 << 0) // (UDPHS) ASCII string HUSB +// -------- UDPHS_RIPNAME2 : (UDPHS Offset: 0xf4) UDPHS Name Register -------- +#define AT91C_UDPHS_IPNAME2 (0x0 << 0) // (UDPHS) ASCII string 2DEV +// -------- UDPHS_IPFEATURES : (UDPHS Offset: 0xf8) UDPHS Features Register -------- +#define AT91C_UDPHS_EPT_NBR_MAX (0xF << 0) // (UDPHS) Max Number of Endpoints +#define AT91C_UDPHS_DMA_CHANNEL_NBR (0x7 << 4) // (UDPHS) Number of DMA Channels +#define AT91C_UDPHS_DMA_B_SIZ (0x1 << 7) // (UDPHS) DMA Buffer Size +#define AT91C_UDPHS_DMA_FIFO_WORD_DEPTH (0xF << 8) // (UDPHS) DMA FIFO Depth in words +#define AT91C_UDPHS_FIFO_MAX_SIZE (0x7 << 12) // (UDPHS) DPRAM size +#define AT91C_UDPHS_BW_DPRAM (0x1 << 15) // (UDPHS) DPRAM byte write capability +#define AT91C_UDPHS_DATAB16_8 (0x1 << 16) // (UDPHS) UTMI DataBus16_8 +#define AT91C_UDPHS_ISO_EPT_1 (0x1 << 17) // (UDPHS) Endpoint 1 High Bandwidth Isochronous Capability +#define AT91C_UDPHS_ISO_EPT_2 (0x1 << 18) // (UDPHS) Endpoint 2 High Bandwidth Isochronous Capability +#define AT91C_UDPHS_ISO_EPT_5 (0x1 << 21) // (UDPHS) Endpoint 5 High Bandwidth Isochronous Capability +#define AT91C_UDPHS_ISO_EPT_6 (0x1 << 22) // (UDPHS) Endpoint 6 High Bandwidth Isochronous Capability +// -------- UDPHS_IPVERSION : (UDPHS Offset: 0xfc) UDPHS Version Register -------- +#define AT91C_UDPHS_VERSION_NUM (0xFFFF << 0) // (UDPHS) Give the IP version +#define AT91C_UDPHS_METAL_FIX_NUM (0x7 << 16) // (UDPHS) Give the number of metal fixes + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR HDMA Channel structure +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_HDMA_CH { + AT91_REG HDMA_SADDR; // HDMA Channel Source Address Register + AT91_REG HDMA_DADDR; // HDMA Channel Destination Address Register + AT91_REG HDMA_DSCR; // HDMA Channel Descriptor Address Register + AT91_REG HDMA_CTRLA; // HDMA Channel Control A Register + AT91_REG HDMA_CTRLB; // HDMA Channel Control B Register + AT91_REG HDMA_CFG; // HDMA Channel Configuration Register + AT91_REG HDMA_SPIP; // HDMA Channel Source Picture in Picture Configuration Register + AT91_REG HDMA_DPIP; // HDMA Channel Destination Picture in Picture Configuration Register + AT91_REG HDMA_BDSCR; // HDMA Reserved + AT91_REG HDMA_CADDR; // HDMA Reserved +} AT91S_HDMA_CH, *AT91PS_HDMA_CH; +#else +#define HDMA_SADDR (AT91_CAST(AT91_REG *) 0x00000000) // (HDMA_SADDR) HDMA Channel Source Address Register +#define HDMA_DADDR (AT91_CAST(AT91_REG *) 0x00000004) // (HDMA_DADDR) HDMA Channel Destination Address Register +#define HDMA_DSCR (AT91_CAST(AT91_REG *) 0x00000008) // (HDMA_DSCR) HDMA Channel Descriptor Address Register +#define HDMA_CTRLA (AT91_CAST(AT91_REG *) 0x0000000C) // (HDMA_CTRLA) HDMA Channel Control A Register +#define HDMA_CTRLB (AT91_CAST(AT91_REG *) 0x00000010) // (HDMA_CTRLB) HDMA Channel Control B Register +#define HDMA_CFG (AT91_CAST(AT91_REG *) 0x00000014) // (HDMA_CFG) HDMA Channel Configuration Register +#define HDMA_SPIP (AT91_CAST(AT91_REG *) 0x00000018) // (HDMA_SPIP) HDMA Channel Source Picture in Picture Configuration Register +#define HDMA_DPIP (AT91_CAST(AT91_REG *) 0x0000001C) // (HDMA_DPIP) HDMA Channel Destination Picture in Picture Configuration Register +#define HDMA_BDSCR (AT91_CAST(AT91_REG *) 0x00000020) // (HDMA_BDSCR) HDMA Reserved +#define HDMA_CADDR (AT91_CAST(AT91_REG *) 0x00000024) // (HDMA_CADDR) HDMA Reserved + +#endif +// -------- HDMA_SADDR : (HDMA_CH Offset: 0x0) -------- +#define AT91C_SADDR (0x0 << 0) // (HDMA_CH) +// -------- HDMA_DADDR : (HDMA_CH Offset: 0x4) -------- +#define AT91C_DADDR (0x0 << 0) // (HDMA_CH) +// -------- HDMA_DSCR : (HDMA_CH Offset: 0x8) -------- +#define AT91C_HDMA_DSCR_IF (0x3 << 0) // (HDMA_CH) Select AHB-Lite Interface for current channel +#define AT91C_HDMA_DSCR_IF_0 (0x0) // (HDMA_CH) The Buffer Transfer descriptor is fetched via AHB-Lite Interface 0. +#define AT91C_HDMA_DSCR_IF_1 (0x1) // (HDMA_CH) The Buffer Transfer descriptor is fetched via AHB-Lite Interface 1. +#define AT91C_HDMA_DSCR_IF_2 (0x2) // (HDMA_CH) The Buffer Transfer descriptor is fetched via AHB-Lite Interface 2. +#define AT91C_HDMA_DSCR_IF_3 (0x3) // (HDMA_CH) The Buffer Transfer descriptor is fetched via AHB-Lite Interface 3. +#define AT91C_HDMA_DSCR (0x3FFFFFFF << 2) // (HDMA_CH) Buffer Transfer descriptor address. This address is word aligned. +// -------- HDMA_CTRLA : (HDMA_CH Offset: 0xc) -------- +#define AT91C_HDMA_BTSIZE (0xFFFF << 0) // (HDMA_CH) Buffer Transfer Size. +#define AT91C_HDMA_SCSIZE (0x7 << 16) // (HDMA_CH) Source Chunk Transfer Size. +#define AT91C_HDMA_SCSIZE_1 (0x0 << 16) // (HDMA_CH) 1. +#define AT91C_HDMA_SCSIZE_4 (0x1 << 16) // (HDMA_CH) 4. +#define AT91C_HDMA_SCSIZE_8 (0x2 << 16) // (HDMA_CH) 8. +#define AT91C_HDMA_SCSIZE_16 (0x3 << 16) // (HDMA_CH) 16. +#define AT91C_HDMA_SCSIZE_32 (0x4 << 16) // (HDMA_CH) 32. +#define AT91C_HDMA_SCSIZE_64 (0x5 << 16) // (HDMA_CH) 64. +#define AT91C_HDMA_SCSIZE_128 (0x6 << 16) // (HDMA_CH) 128. +#define AT91C_HDMA_SCSIZE_256 (0x7 << 16) // (HDMA_CH) 256. +#define AT91C_HDMA_DCSIZE (0x7 << 20) // (HDMA_CH) Destination Chunk Transfer Size +#define AT91C_HDMA_DCSIZE_1 (0x0 << 20) // (HDMA_CH) 1. +#define AT91C_HDMA_DCSIZE_4 (0x1 << 20) // (HDMA_CH) 4. +#define AT91C_HDMA_DCSIZE_8 (0x2 << 20) // (HDMA_CH) 8. +#define AT91C_HDMA_DCSIZE_16 (0x3 << 20) // (HDMA_CH) 16. +#define AT91C_HDMA_DCSIZE_32 (0x4 << 20) // (HDMA_CH) 32. +#define AT91C_HDMA_DCSIZE_64 (0x5 << 20) // (HDMA_CH) 64. +#define AT91C_HDMA_DCSIZE_128 (0x6 << 20) // (HDMA_CH) 128. +#define AT91C_HDMA_DCSIZE_256 (0x7 << 20) // (HDMA_CH) 256. +#define AT91C_HDMA_SRC_WIDTH (0x3 << 24) // (HDMA_CH) Source Single Transfer Size +#define AT91C_HDMA_SRC_WIDTH_BYTE (0x0 << 24) // (HDMA_CH) BYTE. +#define AT91C_HDMA_SRC_WIDTH_HALFWORD (0x1 << 24) // (HDMA_CH) HALF-WORD. +#define AT91C_HDMA_SRC_WIDTH_WORD (0x2 << 24) // (HDMA_CH) WORD. +#define AT91C_HDMA_DST_WIDTH (0x3 << 28) // (HDMA_CH) Destination Single Transfer Size +#define AT91C_HDMA_DST_WIDTH_BYTE (0x0 << 28) // (HDMA_CH) BYTE. +#define AT91C_HDMA_DST_WIDTH_HALFWORD (0x1 << 28) // (HDMA_CH) HALF-WORD. +#define AT91C_HDMA_DST_WIDTH_WORD (0x2 << 28) // (HDMA_CH) WORD. +#define AT91C_HDMA_DONE (0x1 << 31) // (HDMA_CH) +// -------- HDMA_CTRLB : (HDMA_CH Offset: 0x10) -------- +#define AT91C_HDMA_SIF (0x3 << 0) // (HDMA_CH) Source Interface Selection Field. +#define AT91C_HDMA_SIF_0 (0x0) // (HDMA_CH) The Source Transfer is done via AHB-Lite Interface 0. +#define AT91C_HDMA_SIF_1 (0x1) // (HDMA_CH) The Source Transfer is done via AHB-Lite Interface 1. +#define AT91C_HDMA_SIF_2 (0x2) // (HDMA_CH) The Source Transfer is done via AHB-Lite Interface 2. +#define AT91C_HDMA_SIF_3 (0x3) // (HDMA_CH) The Source Transfer is done via AHB-Lite Interface 3. +#define AT91C_HDMA_DIF (0x3 << 4) // (HDMA_CH) Destination Interface Selection Field. +#define AT91C_HDMA_DIF_0 (0x0 << 4) // (HDMA_CH) The Destination Transfer is done via AHB-Lite Interface 0. +#define AT91C_HDMA_DIF_1 (0x1 << 4) // (HDMA_CH) The Destination Transfer is done via AHB-Lite Interface 1. +#define AT91C_HDMA_DIF_2 (0x2 << 4) // (HDMA_CH) The Destination Transfer is done via AHB-Lite Interface 2. +#define AT91C_HDMA_DIF_3 (0x3 << 4) // (HDMA_CH) The Destination Transfer is done via AHB-Lite Interface 3. +#define AT91C_HDMA_SRC_PIP (0x1 << 8) // (HDMA_CH) Source Picture-in-Picture Mode +#define AT91C_HDMA_SRC_PIP_DISABLE (0x0 << 8) // (HDMA_CH) Source Picture-in-Picture mode is disabled. +#define AT91C_HDMA_SRC_PIP_ENABLE (0x1 << 8) // (HDMA_CH) Source Picture-in-Picture mode is enabled. +#define AT91C_HDMA_DST_PIP (0x1 << 12) // (HDMA_CH) Destination Picture-in-Picture Mode +#define AT91C_HDMA_DST_PIP_DISABLE (0x0 << 12) // (HDMA_CH) Destination Picture-in-Picture mode is disabled. +#define AT91C_HDMA_DST_PIP_ENABLE (0x1 << 12) // (HDMA_CH) Destination Picture-in-Picture mode is enabled. +#define AT91C_HDMA_SRC_DSCR (0x1 << 16) // (HDMA_CH) Source Buffer Descriptor Fetch operation +#define AT91C_HDMA_SRC_DSCR_FETCH_FROM_MEM (0x0 << 16) // (HDMA_CH) Source address is updated when the descriptor is fetched from the memory. +#define AT91C_HDMA_SRC_DSCR_FETCH_DISABLE (0x1 << 16) // (HDMA_CH) Buffer Descriptor Fetch operation is disabled for the Source. +#define AT91C_HDMA_DST_DSCR (0x1 << 20) // (HDMA_CH) Destination Buffer Descriptor operation +#define AT91C_HDMA_DST_DSCR_FETCH_FROM_MEM (0x0 << 20) // (HDMA_CH) Destination address is updated when the descriptor is fetched from the memory. +#define AT91C_HDMA_DST_DSCR_FETCH_DISABLE (0x1 << 20) // (HDMA_CH) Buffer Descriptor Fetch operation is disabled for the destination. +#define AT91C_HDMA_FC (0x7 << 21) // (HDMA_CH) This field defines which devices controls the size of the buffer transfer, also referred as to the Flow Controller. +#define AT91C_HDMA_FC_MEM2MEM (0x0 << 21) // (HDMA_CH) Memory-to-Memory (DMA Controller). +#define AT91C_HDMA_FC_MEM2PER (0x1 << 21) // (HDMA_CH) Memory-to-Peripheral (DMA Controller). +#define AT91C_HDMA_FC_PER2MEM (0x2 << 21) // (HDMA_CH) Peripheral-to-Memory (DMA Controller). +#define AT91C_HDMA_FC_PER2PER (0x3 << 21) // (HDMA_CH) Peripheral-to-Peripheral (DMA Controller). +#define AT91C_HDMA_FC_PER2MEM_PER (0x4 << 21) // (HDMA_CH) Peripheral-to-Memory (Peripheral). +#define AT91C_HDMA_FC_MEM2PER_PER (0x5 << 21) // (HDMA_CH) Memory-to-Peripheral (Peripheral). +#define AT91C_HDMA_FC_PER2PER_PER (0x6 << 21) // (HDMA_CH) Peripheral-to-Peripheral (Source Peripheral). +#define AT91C_HDMA_SRC_ADDRESS_MODE (0x3 << 24) // (HDMA_CH) Type of addressing mode +#define AT91C_HDMA_SRC_ADDRESS_MODE_INCR (0x0 << 24) // (HDMA_CH) Incrementing Mode. +#define AT91C_HDMA_SRC_ADDRESS_MODE_DECR (0x1 << 24) // (HDMA_CH) Decrementing Mode. +#define AT91C_HDMA_SRC_ADDRESS_MODE_FIXED (0x2 << 24) // (HDMA_CH) Fixed Mode. +#define AT91C_HDMA_DST_ADDRESS_MODE (0x3 << 28) // (HDMA_CH) Type of addressing mode +#define AT91C_HDMA_DST_ADDRESS_MODE_INCR (0x0 << 28) // (HDMA_CH) Incrementing Mode. +#define AT91C_HDMA_DST_ADDRESS_MODE_DECR (0x1 << 28) // (HDMA_CH) Decrementing Mode. +#define AT91C_HDMA_DST_ADDRESS_MODE_FIXED (0x2 << 28) // (HDMA_CH) Fixed Mode. +#define AT91C_HDMA_AUTO (0x1 << 31) // (HDMA_CH) Automatic multiple buffer transfer enable +#define AT91C_HDMA_AUTO_DISABLE (0x0 << 31) // (HDMA_CH) Automatic multiple buffer transfer is disabled. +#define AT91C_HDMA_AUTO_ENABLE (0x1 << 31) // (HDMA_CH) Automatic multiple buffer transfer is enabled. This enables replay mode or contiguous mode when several buffers are transferred. +// -------- HDMA_CFG : (HDMA_CH Offset: 0x14) -------- +#define AT91C_HDMA_SRC_PER (0xF << 0) // (HDMA_CH) Channel Source Request is associated with peripheral identifier coded SRC_PER handshaking interface. +#define AT91C_HDMA_SRC_PER_0 (0x0) // (HDMA_CH) HW Handshaking Interface number 0. +#define AT91C_HDMA_SRC_PER_1 (0x1) // (HDMA_CH) HW Handshaking Interface number 1. +#define AT91C_HDMA_SRC_PER_2 (0x2) // (HDMA_CH) HW Handshaking Interface number 2. +#define AT91C_HDMA_SRC_PER_3 (0x3) // (HDMA_CH) HW Handshaking Interface number 3. +#define AT91C_HDMA_SRC_PER_4 (0x4) // (HDMA_CH) HW Handshaking Interface number 4. +#define AT91C_HDMA_SRC_PER_5 (0x5) // (HDMA_CH) HW Handshaking Interface number 5. +#define AT91C_HDMA_SRC_PER_6 (0x6) // (HDMA_CH) HW Handshaking Interface number 6. +#define AT91C_HDMA_SRC_PER_7 (0x7) // (HDMA_CH) HW Handshaking Interface number 7. +#define AT91C_HDMA_SRC_PER_8 (0x8) // (HDMA_CH) HW Handshaking Interface number 8. +#define AT91C_HDMA_SRC_PER_9 (0x9) // (HDMA_CH) HW Handshaking Interface number 9. +#define AT91C_HDMA_SRC_PER_10 (0xA) // (HDMA_CH) HW Handshaking Interface number 10. +#define AT91C_HDMA_SRC_PER_11 (0xB) // (HDMA_CH) HW Handshaking Interface number 11. +#define AT91C_HDMA_SRC_PER_12 (0xC) // (HDMA_CH) HW Handshaking Interface number 12. +#define AT91C_HDMA_SRC_PER_13 (0xD) // (HDMA_CH) HW Handshaking Interface number 13. +#define AT91C_HDMA_SRC_PER_14 (0xE) // (HDMA_CH) HW Handshaking Interface number 14. +#define AT91C_HDMA_SRC_PER_15 (0xF) // (HDMA_CH) HW Handshaking Interface number 15. +#define AT91C_HDMA_DST_PER (0xF << 4) // (HDMA_CH) Channel Destination Request is associated with peripheral identifier coded DST_PER handshaking interface. +#define AT91C_HDMA_DST_PER_0 (0x0 << 4) // (HDMA_CH) HW Handshaking Interface number 0. +#define AT91C_HDMA_DST_PER_1 (0x1 << 4) // (HDMA_CH) HW Handshaking Interface number 1. +#define AT91C_HDMA_DST_PER_2 (0x2 << 4) // (HDMA_CH) HW Handshaking Interface number 2. +#define AT91C_HDMA_DST_PER_3 (0x3 << 4) // (HDMA_CH) HW Handshaking Interface number 3. +#define AT91C_HDMA_DST_PER_4 (0x4 << 4) // (HDMA_CH) HW Handshaking Interface number 4. +#define AT91C_HDMA_DST_PER_5 (0x5 << 4) // (HDMA_CH) HW Handshaking Interface number 5. +#define AT91C_HDMA_DST_PER_6 (0x6 << 4) // (HDMA_CH) HW Handshaking Interface number 6. +#define AT91C_HDMA_DST_PER_7 (0x7 << 4) // (HDMA_CH) HW Handshaking Interface number 7. +#define AT91C_HDMA_DST_PER_8 (0x8 << 4) // (HDMA_CH) HW Handshaking Interface number 8. +#define AT91C_HDMA_DST_PER_9 (0x9 << 4) // (HDMA_CH) HW Handshaking Interface number 9. +#define AT91C_HDMA_DST_PER_10 (0xA << 4) // (HDMA_CH) HW Handshaking Interface number 10. +#define AT91C_HDMA_DST_PER_11 (0xB << 4) // (HDMA_CH) HW Handshaking Interface number 11. +#define AT91C_HDMA_DST_PER_12 (0xC << 4) // (HDMA_CH) HW Handshaking Interface number 12. +#define AT91C_HDMA_DST_PER_13 (0xD << 4) // (HDMA_CH) HW Handshaking Interface number 13. +#define AT91C_HDMA_DST_PER_14 (0xE << 4) // (HDMA_CH) HW Handshaking Interface number 14. +#define AT91C_HDMA_DST_PER_15 (0xF << 4) // (HDMA_CH) HW Handshaking Interface number 15. +#define AT91C_HDMA_SRC_REP (0x1 << 8) // (HDMA_CH) Source Replay Mode +#define AT91C_HDMA_SRC_REP_CONTIGUOUS_ADDR (0x0 << 8) // (HDMA_CH) When automatic mode is activated, source address is contiguous between two buffers. +#define AT91C_HDMA_SRC_REP_RELOAD_ADDR (0x1 << 8) // (HDMA_CH) When automatic mode is activated, the source address and the control register are reloaded from previous transfer.. +#define AT91C_HDMA_SRC_H2SEL (0x1 << 9) // (HDMA_CH) Source Handshaking Mode +#define AT91C_HDMA_SRC_H2SEL_SW (0x0 << 9) // (HDMA_CH) Software handshaking interface is used to trigger a transfer request. +#define AT91C_HDMA_SRC_H2SEL_HW (0x1 << 9) // (HDMA_CH) Hardware handshaking interface is used to trigger a transfer request. +#define AT91C_HDMA_DST_REP (0x1 << 12) // (HDMA_CH) Destination Replay Mode +#define AT91C_HDMA_DST_REP_CONTIGUOUS_ADDR (0x0 << 12) // (HDMA_CH) When automatic mode is activated, destination address is contiguous between two buffers. +#define AT91C_HDMA_DST_REP_RELOAD_ADDR (0x1 << 12) // (HDMA_CH) When automatic mode is activated, the destination address and the control register are reloaded from previous transfer.. +#define AT91C_HDMA_DST_H2SEL (0x1 << 13) // (HDMA_CH) Destination Handshaking Mode +#define AT91C_HDMA_DST_H2SEL_SW (0x0 << 13) // (HDMA_CH) Software handshaking interface is used to trigger a transfer request. +#define AT91C_HDMA_DST_H2SEL_HW (0x1 << 13) // (HDMA_CH) Hardware handshaking interface is used to trigger a transfer request. +#define AT91C_HDMA_SOD (0x1 << 16) // (HDMA_CH) STOP ON DONE +#define AT91C_HDMA_SOD_DISABLE (0x0 << 16) // (HDMA_CH) STOP ON DONE disabled, the descriptor fetch operation ignores DONE Field of CTRLA register. +#define AT91C_HDMA_SOD_ENABLE (0x1 << 16) // (HDMA_CH) STOP ON DONE activated, the DMAC module is automatically disabled if DONE FIELD is set to 1. +#define AT91C_HDMA_LOCK_IF (0x1 << 20) // (HDMA_CH) Interface Lock +#define AT91C_HDMA_LOCK_IF_DISABLE (0x0 << 20) // (HDMA_CH) Interface Lock capability is disabled. +#define AT91C_HDMA_LOCK_IF_ENABLE (0x1 << 20) // (HDMA_CH) Interface Lock capability is enabled. +#define AT91C_HDMA_LOCK_B (0x1 << 21) // (HDMA_CH) AHB Bus Lock +#define AT91C_HDMA_LOCK_B_DISABLE (0x0 << 21) // (HDMA_CH) AHB Bus Locking capability is disabled. +#define AT91C_HDMA_LOCK_B_ENABLE (0x1 << 21) // (HDMA_CH) AHB Bus Locking capability is enabled. +#define AT91C_HDMA_LOCK_IF_L (0x1 << 22) // (HDMA_CH) Master Interface Arbiter Lock +#define AT91C_HDMA_LOCK_IF_L_CHUNK (0x0 << 22) // (HDMA_CH) The Master Interface Arbiter is locked by the channel x for a chunk transfer. +#define AT91C_HDMA_LOCK_IF_L_BUFFER (0x1 << 22) // (HDMA_CH) The Master Interface Arbiter is locked by the channel x for a buffer transfer. +#define AT91C_HDMA_AHB_PROT (0x7 << 24) // (HDMA_CH) AHB Prot +#define AT91C_HDMA_FIFOCFG (0x3 << 28) // (HDMA_CH) FIFO Request Configuration +#define AT91C_HDMA_FIFOCFG_LARGESTBURST (0x0 << 28) // (HDMA_CH) The largest defined length AHB burst is performed on the destination AHB interface. +#define AT91C_HDMA_FIFOCFG_HALFFIFO (0x1 << 28) // (HDMA_CH) When half fifo size is available/filled a source/destination request is serviced. +#define AT91C_HDMA_FIFOCFG_ENOUGHSPACE (0x2 << 28) // (HDMA_CH) When there is enough space/data available to perfom a single AHB access then the request is serviced. +// -------- HDMA_SPIP : (HDMA_CH Offset: 0x18) -------- +#define AT91C_SPIP_HOLE (0xFFFF << 0) // (HDMA_CH) This field indicates the value to add to the address when the programmable boundary has been reached. +#define AT91C_SPIP_BOUNDARY (0x3FF << 16) // (HDMA_CH) This field indicates the number of source transfers to perform before the automatic address increment operation. +// -------- HDMA_DPIP : (HDMA_CH Offset: 0x1c) -------- +#define AT91C_DPIP_HOLE (0xFFFF << 0) // (HDMA_CH) This field indicates the value to add to the address when the programmable boundary has been reached. +#define AT91C_DPIP_BOUNDARY (0x3FF << 16) // (HDMA_CH) This field indicates the number of source transfers to perform before the automatic address increment operation. +// -------- HDMA_BDSCR : (HDMA_CH Offset: 0x20) -------- +// -------- HDMA_CADDR : (HDMA_CH Offset: 0x24) -------- + +// ***************************************************************************** +// SOFTWARE API DEFINITION FOR HDMA controller +// ***************************************************************************** +#ifndef __ASSEMBLY__ +typedef struct _AT91S_HDMA { + AT91_REG HDMA_GCFG; // HDMA Global Configuration Register + AT91_REG HDMA_EN; // HDMA Controller Enable Register + AT91_REG HDMA_SREQ; // HDMA Software Single Request Register + AT91_REG HDMA_CREQ; // HDMA Software Chunk Transfer Request Register + AT91_REG HDMA_LAST; // HDMA Software Last Transfer Flag Register + AT91_REG HDMA_SYNC; // HDMA Request Synchronization Register + AT91_REG HDMA_EBCIER; // HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Interrupt Enable register + AT91_REG HDMA_EBCIDR; // HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Interrupt Disable register + AT91_REG HDMA_EBCIMR; // HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Mask Register + AT91_REG HDMA_EBCISR; // HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Status Register + AT91_REG HDMA_CHER; // HDMA Channel Handler Enable Register + AT91_REG HDMA_CHDR; // HDMA Channel Handler Disable Register + AT91_REG HDMA_CHSR; // HDMA Channel Handler Status Register + AT91_REG HDMA_RSVD0; // HDMA Reserved + AT91_REG HDMA_RSVD1; // HDMA Reserved + AT91S_HDMA_CH HDMA_CH[4]; // HDMA Channel structure + AT91_REG Reserved0[68]; // + AT91_REG HDMA_ADDRSIZE; // HDMA ADDRSIZE REGISTER + AT91_REG HDMA_IPNAME1; // HDMA IPNAME1 REGISTER + AT91_REG HDMA_IPNAME2; // HDMA IPNAME2 REGISTER + AT91_REG HDMA_FEATURES; // HDMA FEATURES REGISTER + AT91_REG HDMA_VER; // HDMA VERSION REGISTER +} AT91S_HDMA, *AT91PS_HDMA; +#else +#define HDMA_GCFG (AT91_CAST(AT91_REG *) 0x00000000) // (HDMA_GCFG) HDMA Global Configuration Register +#define HDMA_EN (AT91_CAST(AT91_REG *) 0x00000004) // (HDMA_EN) HDMA Controller Enable Register +#define HDMA_SREQ (AT91_CAST(AT91_REG *) 0x00000008) // (HDMA_SREQ) HDMA Software Single Request Register +#define HDMA_CREQ (AT91_CAST(AT91_REG *) 0x0000000C) // (HDMA_CREQ) HDMA Software Chunk Transfer Request Register +#define HDMA_LAST (AT91_CAST(AT91_REG *) 0x00000010) // (HDMA_LAST) HDMA Software Last Transfer Flag Register +#define HDMA_SYNC (AT91_CAST(AT91_REG *) 0x00000014) // (HDMA_SYNC) HDMA Request Synchronization Register +#define HDMA_EBCIER (AT91_CAST(AT91_REG *) 0x00000018) // (HDMA_EBCIER) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Interrupt Enable register +#define HDMA_EBCIDR (AT91_CAST(AT91_REG *) 0x0000001C) // (HDMA_EBCIDR) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Interrupt Disable register +#define HDMA_EBCIMR (AT91_CAST(AT91_REG *) 0x00000020) // (HDMA_EBCIMR) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Mask Register +#define HDMA_EBCISR (AT91_CAST(AT91_REG *) 0x00000024) // (HDMA_EBCISR) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Status Register +#define HDMA_CHER (AT91_CAST(AT91_REG *) 0x00000028) // (HDMA_CHER) HDMA Channel Handler Enable Register +#define HDMA_CHDR (AT91_CAST(AT91_REG *) 0x0000002C) // (HDMA_CHDR) HDMA Channel Handler Disable Register +#define HDMA_CHSR (AT91_CAST(AT91_REG *) 0x00000030) // (HDMA_CHSR) HDMA Channel Handler Status Register +#define HDMA_RSVD0 (AT91_CAST(AT91_REG *) 0x00000034) // (HDMA_RSVD0) HDMA Reserved +#define HDMA_RSVD1 (AT91_CAST(AT91_REG *) 0x00000038) // (HDMA_RSVD1) HDMA Reserved +#define HDMA_ADDRSIZE (AT91_CAST(AT91_REG *) 0x000001EC) // (HDMA_ADDRSIZE) HDMA ADDRSIZE REGISTER +#define HDMA_IPNAME1 (AT91_CAST(AT91_REG *) 0x000001F0) // (HDMA_IPNAME1) HDMA IPNAME1 REGISTER +#define HDMA_IPNAME2 (AT91_CAST(AT91_REG *) 0x000001F4) // (HDMA_IPNAME2) HDMA IPNAME2 REGISTER +#define HDMA_FEATURES (AT91_CAST(AT91_REG *) 0x000001F8) // (HDMA_FEATURES) HDMA FEATURES REGISTER +#define HDMA_VER (AT91_CAST(AT91_REG *) 0x000001FC) // (HDMA_VER) HDMA VERSION REGISTER + +#endif +// -------- HDMA_GCFG : (HDMA Offset: 0x0) -------- +#define AT91C_HDMA_IF0_BIGEND (0x1 << 0) // (HDMA) AHB-Lite Interface 0 endian mode. +#define AT91C_HDMA_IF0_BIGEND_IS_LITTLE_ENDIAN (0x0) // (HDMA) AHB-Lite Interface 0 is little endian. +#define AT91C_HDMA_IF0_BIGEND_IS_BIG_ENDIAN (0x1) // (HDMA) AHB-Lite Interface 0 is big endian. +#define AT91C_HDMA_IF1_BIGEND (0x1 << 1) // (HDMA) AHB-Lite Interface 1 endian mode. +#define AT91C_HDMA_IF1_BIGEND_IS_LITTLE_ENDIAN (0x0 << 1) // (HDMA) AHB-Lite Interface 1 is little endian. +#define AT91C_HDMA_IF1_BIGEND_IS_BIG_ENDIAN (0x1 << 1) // (HDMA) AHB-Lite Interface 1 is big endian. +#define AT91C_HDMA_IF2_BIGEND (0x1 << 2) // (HDMA) AHB-Lite Interface 2 endian mode. +#define AT91C_HDMA_IF2_BIGEND_IS_LITTLE_ENDIAN (0x0 << 2) // (HDMA) AHB-Lite Interface 2 is little endian. +#define AT91C_HDMA_IF2_BIGEND_IS_BIG_ENDIAN (0x1 << 2) // (HDMA) AHB-Lite Interface 2 is big endian. +#define AT91C_HDMA_IF3_BIGEND (0x1 << 3) // (HDMA) AHB-Lite Interface 3 endian mode. +#define AT91C_HDMA_IF3_BIGEND_IS_LITTLE_ENDIAN (0x0 << 3) // (HDMA) AHB-Lite Interface 3 is little endian. +#define AT91C_HDMA_IF3_BIGEND_IS_BIG_ENDIAN (0x1 << 3) // (HDMA) AHB-Lite Interface 3 is big endian. +#define AT91C_HDMA_ARB_CFG (0x1 << 4) // (HDMA) Arbiter mode. +#define AT91C_HDMA_ARB_CFG_FIXED (0x0 << 4) // (HDMA) Fixed priority arbiter. +#define AT91C_HDMA_ARB_CFG_ROUND_ROBIN (0x1 << 4) // (HDMA) Modified round robin arbiter. +// -------- HDMA_EN : (HDMA Offset: 0x4) -------- +#define AT91C_HDMA_ENABLE (0x1 << 0) // (HDMA) +#define AT91C_HDMA_ENABLE_DISABLE (0x0) // (HDMA) Disables HDMA. +#define AT91C_HDMA_ENABLE_ENABLE (0x1) // (HDMA) Enables HDMA. +// -------- HDMA_SREQ : (HDMA Offset: 0x8) -------- +#define AT91C_HDMA_SSREQ0 (0x1 << 0) // (HDMA) Request a source single transfer on channel 0 +#define AT91C_HDMA_SSREQ0_0 (0x0) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ0_1 (0x1) // (HDMA) Request a source single transfer on channel 0. +#define AT91C_HDMA_DSREQ0 (0x1 << 1) // (HDMA) Request a destination single transfer on channel 0 +#define AT91C_HDMA_DSREQ0_0 (0x0 << 1) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ0_1 (0x1 << 1) // (HDMA) Request a destination single transfer on channel 0. +#define AT91C_HDMA_SSREQ1 (0x1 << 2) // (HDMA) Request a source single transfer on channel 1 +#define AT91C_HDMA_SSREQ1_0 (0x0 << 2) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ1_1 (0x1 << 2) // (HDMA) Request a source single transfer on channel 1. +#define AT91C_HDMA_DSREQ1 (0x1 << 3) // (HDMA) Request a destination single transfer on channel 1 +#define AT91C_HDMA_DSREQ1_0 (0x0 << 3) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ1_1 (0x1 << 3) // (HDMA) Request a destination single transfer on channel 1. +#define AT91C_HDMA_SSREQ2 (0x1 << 4) // (HDMA) Request a source single transfer on channel 2 +#define AT91C_HDMA_SSREQ2_0 (0x0 << 4) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ2_1 (0x1 << 4) // (HDMA) Request a source single transfer on channel 2. +#define AT91C_HDMA_DSREQ2 (0x1 << 5) // (HDMA) Request a destination single transfer on channel 2 +#define AT91C_HDMA_DSREQ2_0 (0x0 << 5) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ2_1 (0x1 << 5) // (HDMA) Request a destination single transfer on channel 2. +#define AT91C_HDMA_SSREQ3 (0x1 << 6) // (HDMA) Request a source single transfer on channel 3 +#define AT91C_HDMA_SSREQ3_0 (0x0 << 6) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ3_1 (0x1 << 6) // (HDMA) Request a source single transfer on channel 3. +#define AT91C_HDMA_DSREQ3 (0x1 << 7) // (HDMA) Request a destination single transfer on channel 3 +#define AT91C_HDMA_DSREQ3_0 (0x0 << 7) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ3_1 (0x1 << 7) // (HDMA) Request a destination single transfer on channel 3. +#define AT91C_HDMA_SSREQ4 (0x1 << 8) // (HDMA) Request a source single transfer on channel 4 +#define AT91C_HDMA_SSREQ4_0 (0x0 << 8) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ4_1 (0x1 << 8) // (HDMA) Request a source single transfer on channel 4. +#define AT91C_HDMA_DSREQ4 (0x1 << 9) // (HDMA) Request a destination single transfer on channel 4 +#define AT91C_HDMA_DSREQ4_0 (0x0 << 9) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ4_1 (0x1 << 9) // (HDMA) Request a destination single transfer on channel 4. +#define AT91C_HDMA_SSREQ5 (0x1 << 10) // (HDMA) Request a source single transfer on channel 5 +#define AT91C_HDMA_SSREQ5_0 (0x0 << 10) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ5_1 (0x1 << 10) // (HDMA) Request a source single transfer on channel 5. +#define AT91C_HDMA_DSREQ6 (0x1 << 11) // (HDMA) Request a destination single transfer on channel 5 +#define AT91C_HDMA_DSREQ6_0 (0x0 << 11) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ6_1 (0x1 << 11) // (HDMA) Request a destination single transfer on channel 5. +#define AT91C_HDMA_SSREQ6 (0x1 << 12) // (HDMA) Request a source single transfer on channel 6 +#define AT91C_HDMA_SSREQ6_0 (0x0 << 12) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ6_1 (0x1 << 12) // (HDMA) Request a source single transfer on channel 6. +#define AT91C_HDMA_SSREQ7 (0x1 << 14) // (HDMA) Request a source single transfer on channel 7 +#define AT91C_HDMA_SSREQ7_0 (0x0 << 14) // (HDMA) No effect. +#define AT91C_HDMA_SSREQ7_1 (0x1 << 14) // (HDMA) Request a source single transfer on channel 7. +#define AT91C_HDMA_DSREQ7 (0x1 << 15) // (HDMA) Request a destination single transfer on channel 7 +#define AT91C_HDMA_DSREQ7_0 (0x0 << 15) // (HDMA) No effect. +#define AT91C_HDMA_DSREQ7_1 (0x1 << 15) // (HDMA) Request a destination single transfer on channel 7. +// -------- HDMA_CREQ : (HDMA Offset: 0xc) -------- +#define AT91C_HDMA_SCREQ0 (0x1 << 0) // (HDMA) Request a source chunk transfer on channel 0 +#define AT91C_HDMA_SCREQ0_0 (0x0) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ0_1 (0x1) // (HDMA) Request a source chunk transfer on channel 0. +#define AT91C_HDMA_DCREQ0 (0x1 << 1) // (HDMA) Request a destination chunk transfer on channel 0 +#define AT91C_HDMA_DCREQ0_0 (0x0 << 1) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ0_1 (0x1 << 1) // (HDMA) Request a destination chunk transfer on channel 0. +#define AT91C_HDMA_SCREQ1 (0x1 << 2) // (HDMA) Request a source chunk transfer on channel 1 +#define AT91C_HDMA_SCREQ1_0 (0x0 << 2) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ1_1 (0x1 << 2) // (HDMA) Request a source chunk transfer on channel 1. +#define AT91C_HDMA_DCREQ1 (0x1 << 3) // (HDMA) Request a destination chunk transfer on channel 1 +#define AT91C_HDMA_DCREQ1_0 (0x0 << 3) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ1_1 (0x1 << 3) // (HDMA) Request a destination chunk transfer on channel 1. +#define AT91C_HDMA_SCREQ2 (0x1 << 4) // (HDMA) Request a source chunk transfer on channel 2 +#define AT91C_HDMA_SCREQ2_0 (0x0 << 4) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ2_1 (0x1 << 4) // (HDMA) Request a source chunk transfer on channel 2. +#define AT91C_HDMA_DCREQ2 (0x1 << 5) // (HDMA) Request a destination chunk transfer on channel 2 +#define AT91C_HDMA_DCREQ2_0 (0x0 << 5) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ2_1 (0x1 << 5) // (HDMA) Request a destination chunk transfer on channel 2. +#define AT91C_HDMA_SCREQ3 (0x1 << 6) // (HDMA) Request a source chunk transfer on channel 3 +#define AT91C_HDMA_SCREQ3_0 (0x0 << 6) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ3_1 (0x1 << 6) // (HDMA) Request a source chunk transfer on channel 3. +#define AT91C_HDMA_DCREQ3 (0x1 << 7) // (HDMA) Request a destination chunk transfer on channel 3 +#define AT91C_HDMA_DCREQ3_0 (0x0 << 7) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ3_1 (0x1 << 7) // (HDMA) Request a destination chunk transfer on channel 3. +#define AT91C_HDMA_SCREQ4 (0x1 << 8) // (HDMA) Request a source chunk transfer on channel 4 +#define AT91C_HDMA_SCREQ4_0 (0x0 << 8) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ4_1 (0x1 << 8) // (HDMA) Request a source chunk transfer on channel 4. +#define AT91C_HDMA_DCREQ4 (0x1 << 9) // (HDMA) Request a destination chunk transfer on channel 4 +#define AT91C_HDMA_DCREQ4_0 (0x0 << 9) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ4_1 (0x1 << 9) // (HDMA) Request a destination chunk transfer on channel 4. +#define AT91C_HDMA_SCREQ5 (0x1 << 10) // (HDMA) Request a source chunk transfer on channel 5 +#define AT91C_HDMA_SCREQ5_0 (0x0 << 10) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ5_1 (0x1 << 10) // (HDMA) Request a source chunk transfer on channel 5. +#define AT91C_HDMA_DCREQ6 (0x1 << 11) // (HDMA) Request a destination chunk transfer on channel 5 +#define AT91C_HDMA_DCREQ6_0 (0x0 << 11) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ6_1 (0x1 << 11) // (HDMA) Request a destination chunk transfer on channel 5. +#define AT91C_HDMA_SCREQ6 (0x1 << 12) // (HDMA) Request a source chunk transfer on channel 6 +#define AT91C_HDMA_SCREQ6_0 (0x0 << 12) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ6_1 (0x1 << 12) // (HDMA) Request a source chunk transfer on channel 6. +#define AT91C_HDMA_SCREQ7 (0x1 << 14) // (HDMA) Request a source chunk transfer on channel 7 +#define AT91C_HDMA_SCREQ7_0 (0x0 << 14) // (HDMA) No effect. +#define AT91C_HDMA_SCREQ7_1 (0x1 << 14) // (HDMA) Request a source chunk transfer on channel 7. +#define AT91C_HDMA_DCREQ7 (0x1 << 15) // (HDMA) Request a destination chunk transfer on channel 7 +#define AT91C_HDMA_DCREQ7_0 (0x0 << 15) // (HDMA) No effect. +#define AT91C_HDMA_DCREQ7_1 (0x1 << 15) // (HDMA) Request a destination chunk transfer on channel 7. +// -------- HDMA_LAST : (HDMA Offset: 0x10) -------- +#define AT91C_HDMA_SLAST0 (0x1 << 0) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 0 +#define AT91C_HDMA_SLAST0_0 (0x0) // (HDMA) No effect. +#define AT91C_HDMA_SLAST0_1 (0x1) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 0. +#define AT91C_HDMA_DLAST0 (0x1 << 1) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 0 +#define AT91C_HDMA_DLAST0_0 (0x0 << 1) // (HDMA) No effect. +#define AT91C_HDMA_DLAST0_1 (0x1 << 1) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 0. +#define AT91C_HDMA_SLAST1 (0x1 << 2) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 1 +#define AT91C_HDMA_SLAST1_0 (0x0 << 2) // (HDMA) No effect. +#define AT91C_HDMA_SLAST1_1 (0x1 << 2) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 1. +#define AT91C_HDMA_DLAST1 (0x1 << 3) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 1 +#define AT91C_HDMA_DLAST1_0 (0x0 << 3) // (HDMA) No effect. +#define AT91C_HDMA_DLAST1_1 (0x1 << 3) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 1. +#define AT91C_HDMA_SLAST2 (0x1 << 4) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 2 +#define AT91C_HDMA_SLAST2_0 (0x0 << 4) // (HDMA) No effect. +#define AT91C_HDMA_SLAST2_1 (0x1 << 4) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 2. +#define AT91C_HDMA_DLAST2 (0x1 << 5) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 2 +#define AT91C_HDMA_DLAST2_0 (0x0 << 5) // (HDMA) No effect. +#define AT91C_HDMA_DLAST2_1 (0x1 << 5) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 2. +#define AT91C_HDMA_SLAST3 (0x1 << 6) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 3 +#define AT91C_HDMA_SLAST3_0 (0x0 << 6) // (HDMA) No effect. +#define AT91C_HDMA_SLAST3_1 (0x1 << 6) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 3. +#define AT91C_HDMA_DLAST3 (0x1 << 7) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 3 +#define AT91C_HDMA_DLAST3_0 (0x0 << 7) // (HDMA) No effect. +#define AT91C_HDMA_DLAST3_1 (0x1 << 7) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 3. +#define AT91C_HDMA_SLAST4 (0x1 << 8) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 4 +#define AT91C_HDMA_SLAST4_0 (0x0 << 8) // (HDMA) No effect. +#define AT91C_HDMA_SLAST4_1 (0x1 << 8) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 4. +#define AT91C_HDMA_DLAST4 (0x1 << 9) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 4 +#define AT91C_HDMA_DLAST4_0 (0x0 << 9) // (HDMA) No effect. +#define AT91C_HDMA_DLAST4_1 (0x1 << 9) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 4. +#define AT91C_HDMA_SLAST5 (0x1 << 10) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 5 +#define AT91C_HDMA_SLAST5_0 (0x0 << 10) // (HDMA) No effect. +#define AT91C_HDMA_SLAST5_1 (0x1 << 10) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 5. +#define AT91C_HDMA_DLAST6 (0x1 << 11) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 5 +#define AT91C_HDMA_DLAST6_0 (0x0 << 11) // (HDMA) No effect. +#define AT91C_HDMA_DLAST6_1 (0x1 << 11) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 5. +#define AT91C_HDMA_SLAST6 (0x1 << 12) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 6 +#define AT91C_HDMA_SLAST6_0 (0x0 << 12) // (HDMA) No effect. +#define AT91C_HDMA_SLAST6_1 (0x1 << 12) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 6. +#define AT91C_HDMA_SLAST7 (0x1 << 14) // (HDMA) Indicates that this source request is the last transfer of the buffer on channel 7 +#define AT91C_HDMA_SLAST7_0 (0x0 << 14) // (HDMA) No effect. +#define AT91C_HDMA_SLAST7_1 (0x1 << 14) // (HDMA) Writing one to SLASTx prior to writing one to SSREQx or SCREQx indicates that this source request is the last transfer of the buffer on channel 7. +#define AT91C_HDMA_DLAST7 (0x1 << 15) // (HDMA) Indicates that this destination request is the last transfer of the buffer on channel 7 +#define AT91C_HDMA_DLAST7_0 (0x0 << 15) // (HDMA) No effect. +#define AT91C_HDMA_DLAST7_1 (0x1 << 15) // (HDMA) Writing one to DLASTx prior to writing one to DSREQx or DCREQx indicates that this destination request is the last transfer of the buffer on channel 7. +// -------- HDMA_SYNC : (HDMA Offset: 0x14) -------- +#define AT91C_SYNC_REQ (0xFFFF << 0) // (HDMA) +// -------- HDMA_EBCIER : (HDMA Offset: 0x18) Buffer Transfer Completed/Chained Buffer Transfer Completed/Access Error Interrupt Enable Register -------- +#define AT91C_HDMA_BTC0 (0x1 << 0) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC1 (0x1 << 1) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC2 (0x1 << 2) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC3 (0x1 << 3) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC4 (0x1 << 4) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC5 (0x1 << 5) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC6 (0x1 << 6) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_BTC7 (0x1 << 7) // (HDMA) Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC0 (0x1 << 8) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC1 (0x1 << 9) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC2 (0x1 << 10) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC3 (0x1 << 11) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC4 (0x1 << 12) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC5 (0x1 << 13) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC6 (0x1 << 14) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_CBTC7 (0x1 << 15) // (HDMA) Chained Buffer Transfer Completed Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR0 (0x1 << 16) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR1 (0x1 << 17) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR2 (0x1 << 18) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR3 (0x1 << 19) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR4 (0x1 << 20) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR5 (0x1 << 21) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR6 (0x1 << 22) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +#define AT91C_HDMA_ERR7 (0x1 << 23) // (HDMA) Access HDMA_Error Interrupt Enable/Disable/Status Register +// -------- HDMA_EBCIDR : (HDMA Offset: 0x1c) -------- +// -------- HDMA_EBCIMR : (HDMA Offset: 0x20) -------- +// -------- HDMA_EBCISR : (HDMA Offset: 0x24) -------- +// -------- HDMA_CHER : (HDMA Offset: 0x28) -------- +#define AT91C_HDMA_ENA0 (0x1 << 0) // (HDMA) When set, channel 0 enabled. +#define AT91C_HDMA_ENA0_0 (0x0) // (HDMA) No effect. +#define AT91C_HDMA_ENA0_1 (0x1) // (HDMA) Channel 0 enabled. +#define AT91C_HDMA_ENA1 (0x1 << 1) // (HDMA) When set, channel 1 enabled. +#define AT91C_HDMA_ENA1_0 (0x0 << 1) // (HDMA) No effect. +#define AT91C_HDMA_ENA1_1 (0x1 << 1) // (HDMA) Channel 1 enabled. +#define AT91C_HDMA_ENA2 (0x1 << 2) // (HDMA) When set, channel 2 enabled. +#define AT91C_HDMA_ENA2_0 (0x0 << 2) // (HDMA) No effect. +#define AT91C_HDMA_ENA2_1 (0x1 << 2) // (HDMA) Channel 2 enabled. +#define AT91C_HDMA_ENA3 (0x1 << 3) // (HDMA) When set, channel 3 enabled. +#define AT91C_HDMA_ENA3_0 (0x0 << 3) // (HDMA) No effect. +#define AT91C_HDMA_ENA3_1 (0x1 << 3) // (HDMA) Channel 3 enabled. +#define AT91C_HDMA_ENA4 (0x1 << 4) // (HDMA) When set, channel 4 enabled. +#define AT91C_HDMA_ENA4_0 (0x0 << 4) // (HDMA) No effect. +#define AT91C_HDMA_ENA4_1 (0x1 << 4) // (HDMA) Channel 4 enabled. +#define AT91C_HDMA_ENA5 (0x1 << 5) // (HDMA) When set, channel 5 enabled. +#define AT91C_HDMA_ENA5_0 (0x0 << 5) // (HDMA) No effect. +#define AT91C_HDMA_ENA5_1 (0x1 << 5) // (HDMA) Channel 5 enabled. +#define AT91C_HDMA_ENA6 (0x1 << 6) // (HDMA) When set, channel 6 enabled. +#define AT91C_HDMA_ENA6_0 (0x0 << 6) // (HDMA) No effect. +#define AT91C_HDMA_ENA6_1 (0x1 << 6) // (HDMA) Channel 6 enabled. +#define AT91C_HDMA_ENA7 (0x1 << 7) // (HDMA) When set, channel 7 enabled. +#define AT91C_HDMA_ENA7_0 (0x0 << 7) // (HDMA) No effect. +#define AT91C_HDMA_ENA7_1 (0x1 << 7) // (HDMA) Channel 7 enabled. +#define AT91C_HDMA_SUSP0 (0x1 << 8) // (HDMA) When set, channel 0 freezed and its current context. +#define AT91C_HDMA_SUSP0_0 (0x0 << 8) // (HDMA) No effect. +#define AT91C_HDMA_SUSP0_1 (0x1 << 8) // (HDMA) Channel 0 freezed. +#define AT91C_HDMA_SUSP1 (0x1 << 9) // (HDMA) When set, channel 1 freezed and its current context. +#define AT91C_HDMA_SUSP1_0 (0x0 << 9) // (HDMA) No effect. +#define AT91C_HDMA_SUSP1_1 (0x1 << 9) // (HDMA) Channel 1 freezed. +#define AT91C_HDMA_SUSP2 (0x1 << 10) // (HDMA) When set, channel 2 freezed and its current context. +#define AT91C_HDMA_SUSP2_0 (0x0 << 10) // (HDMA) No effect. +#define AT91C_HDMA_SUSP2_1 (0x1 << 10) // (HDMA) Channel 2 freezed. +#define AT91C_HDMA_SUSP3 (0x1 << 11) // (HDMA) When set, channel 3 freezed and its current context. +#define AT91C_HDMA_SUSP3_0 (0x0 << 11) // (HDMA) No effect. +#define AT91C_HDMA_SUSP3_1 (0x1 << 11) // (HDMA) Channel 3 freezed. +#define AT91C_HDMA_SUSP4 (0x1 << 12) // (HDMA) When set, channel 4 freezed and its current context. +#define AT91C_HDMA_SUSP4_0 (0x0 << 12) // (HDMA) No effect. +#define AT91C_HDMA_SUSP4_1 (0x1 << 12) // (HDMA) Channel 4 freezed. +#define AT91C_HDMA_SUSP5 (0x1 << 13) // (HDMA) When set, channel 5 freezed and its current context. +#define AT91C_HDMA_SUSP5_0 (0x0 << 13) // (HDMA) No effect. +#define AT91C_HDMA_SUSP5_1 (0x1 << 13) // (HDMA) Channel 5 freezed. +#define AT91C_HDMA_SUSP6 (0x1 << 14) // (HDMA) When set, channel 6 freezed and its current context. +#define AT91C_HDMA_SUSP6_0 (0x0 << 14) // (HDMA) No effect. +#define AT91C_HDMA_SUSP6_1 (0x1 << 14) // (HDMA) Channel 6 freezed. +#define AT91C_HDMA_SUSP7 (0x1 << 15) // (HDMA) When set, channel 7 freezed and its current context. +#define AT91C_HDMA_SUSP7_0 (0x0 << 15) // (HDMA) No effect. +#define AT91C_HDMA_SUSP7_1 (0x1 << 15) // (HDMA) Channel 7 freezed. +#define AT91C_HDMA_KEEP0 (0x1 << 24) // (HDMA) When set, it resumes the channel 0 from an automatic stall state. +#define AT91C_HDMA_KEEP0_0 (0x0 << 24) // (HDMA) No effect. +#define AT91C_HDMA_KEEP0_1 (0x1 << 24) // (HDMA) Resumes the channel 0. +#define AT91C_HDMA_KEEP1 (0x1 << 25) // (HDMA) When set, it resumes the channel 1 from an automatic stall state. +#define AT91C_HDMA_KEEP1_0 (0x0 << 25) // (HDMA) No effect. +#define AT91C_HDMA_KEEP1_1 (0x1 << 25) // (HDMA) Resumes the channel 1. +#define AT91C_HDMA_KEEP2 (0x1 << 26) // (HDMA) When set, it resumes the channel 2 from an automatic stall state. +#define AT91C_HDMA_KEEP2_0 (0x0 << 26) // (HDMA) No effect. +#define AT91C_HDMA_KEEP2_1 (0x1 << 26) // (HDMA) Resumes the channel 2. +#define AT91C_HDMA_KEEP3 (0x1 << 27) // (HDMA) When set, it resumes the channel 3 from an automatic stall state. +#define AT91C_HDMA_KEEP3_0 (0x0 << 27) // (HDMA) No effect. +#define AT91C_HDMA_KEEP3_1 (0x1 << 27) // (HDMA) Resumes the channel 3. +#define AT91C_HDMA_KEEP4 (0x1 << 28) // (HDMA) When set, it resumes the channel 4 from an automatic stall state. +#define AT91C_HDMA_KEEP4_0 (0x0 << 28) // (HDMA) No effect. +#define AT91C_HDMA_KEEP4_1 (0x1 << 28) // (HDMA) Resumes the channel 4. +#define AT91C_HDMA_KEEP5 (0x1 << 29) // (HDMA) When set, it resumes the channel 5 from an automatic stall state. +#define AT91C_HDMA_KEEP5_0 (0x0 << 29) // (HDMA) No effect. +#define AT91C_HDMA_KEEP5_1 (0x1 << 29) // (HDMA) Resumes the channel 5. +#define AT91C_HDMA_KEEP6 (0x1 << 30) // (HDMA) When set, it resumes the channel 6 from an automatic stall state. +#define AT91C_HDMA_KEEP6_0 (0x0 << 30) // (HDMA) No effect. +#define AT91C_HDMA_KEEP6_1 (0x1 << 30) // (HDMA) Resumes the channel 6. +#define AT91C_HDMA_KEEP7 (0x1 << 31) // (HDMA) When set, it resumes the channel 7 from an automatic stall state. +#define AT91C_HDMA_KEEP7_0 (0x0 << 31) // (HDMA) No effect. +#define AT91C_HDMA_KEEP7_1 (0x1 << 31) // (HDMA) Resumes the channel 7. +// -------- HDMA_CHDR : (HDMA Offset: 0x2c) -------- +#define AT91C_HDMA_DIS0 (0x1 << 0) // (HDMA) Write one to this field to disable the channel 0. +#define AT91C_HDMA_DIS0_0 (0x0) // (HDMA) No effect. +#define AT91C_HDMA_DIS0_1 (0x1) // (HDMA) Disables the channel 0. +#define AT91C_HDMA_DIS1 (0x1 << 1) // (HDMA) Write one to this field to disable the channel 1. +#define AT91C_HDMA_DIS1_0 (0x0 << 1) // (HDMA) No effect. +#define AT91C_HDMA_DIS1_1 (0x1 << 1) // (HDMA) Disables the channel 1. +#define AT91C_HDMA_DIS2 (0x1 << 2) // (HDMA) Write one to this field to disable the channel 2. +#define AT91C_HDMA_DIS2_0 (0x0 << 2) // (HDMA) No effect. +#define AT91C_HDMA_DIS2_1 (0x1 << 2) // (HDMA) Disables the channel 2. +#define AT91C_HDMA_DIS3 (0x1 << 3) // (HDMA) Write one to this field to disable the channel 3. +#define AT91C_HDMA_DIS3_0 (0x0 << 3) // (HDMA) No effect. +#define AT91C_HDMA_DIS3_1 (0x1 << 3) // (HDMA) Disables the channel 3. +#define AT91C_HDMA_DIS4 (0x1 << 4) // (HDMA) Write one to this field to disable the channel 4. +#define AT91C_HDMA_DIS4_0 (0x0 << 4) // (HDMA) No effect. +#define AT91C_HDMA_DIS4_1 (0x1 << 4) // (HDMA) Disables the channel 4. +#define AT91C_HDMA_DIS5 (0x1 << 5) // (HDMA) Write one to this field to disable the channel 5. +#define AT91C_HDMA_DIS5_0 (0x0 << 5) // (HDMA) No effect. +#define AT91C_HDMA_DIS5_1 (0x1 << 5) // (HDMA) Disables the channel 5. +#define AT91C_HDMA_DIS6 (0x1 << 6) // (HDMA) Write one to this field to disable the channel 6. +#define AT91C_HDMA_DIS6_0 (0x0 << 6) // (HDMA) No effect. +#define AT91C_HDMA_DIS6_1 (0x1 << 6) // (HDMA) Disables the channel 6. +#define AT91C_HDMA_DIS7 (0x1 << 7) // (HDMA) Write one to this field to disable the channel 7. +#define AT91C_HDMA_DIS7_0 (0x0 << 7) // (HDMA) No effect. +#define AT91C_HDMA_DIS7_1 (0x1 << 7) // (HDMA) Disables the channel 7. +#define AT91C_HDMA_RES0 (0x1 << 8) // (HDMA) Write one to this field to resume the channel 0 transfer restoring its context. +#define AT91C_HDMA_RES0_0 (0x0 << 8) // (HDMA) No effect. +#define AT91C_HDMA_RES0_1 (0x1 << 8) // (HDMA) Resumes the channel 0. +#define AT91C_HDMA_RES1 (0x1 << 9) // (HDMA) Write one to this field to resume the channel 1 transfer restoring its context. +#define AT91C_HDMA_RES1_0 (0x0 << 9) // (HDMA) No effect. +#define AT91C_HDMA_RES1_1 (0x1 << 9) // (HDMA) Resumes the channel 1. +#define AT91C_HDMA_RES2 (0x1 << 10) // (HDMA) Write one to this field to resume the channel 2 transfer restoring its context. +#define AT91C_HDMA_RES2_0 (0x0 << 10) // (HDMA) No effect. +#define AT91C_HDMA_RES2_1 (0x1 << 10) // (HDMA) Resumes the channel 2. +#define AT91C_HDMA_RES3 (0x1 << 11) // (HDMA) Write one to this field to resume the channel 3 transfer restoring its context. +#define AT91C_HDMA_RES3_0 (0x0 << 11) // (HDMA) No effect. +#define AT91C_HDMA_RES3_1 (0x1 << 11) // (HDMA) Resumes the channel 3. +#define AT91C_HDMA_RES4 (0x1 << 12) // (HDMA) Write one to this field to resume the channel 4 transfer restoring its context. +#define AT91C_HDMA_RES4_0 (0x0 << 12) // (HDMA) No effect. +#define AT91C_HDMA_RES4_1 (0x1 << 12) // (HDMA) Resumes the channel 4. +#define AT91C_HDMA_RES5 (0x1 << 13) // (HDMA) Write one to this field to resume the channel 5 transfer restoring its context. +#define AT91C_HDMA_RES5_0 (0x0 << 13) // (HDMA) No effect. +#define AT91C_HDMA_RES5_1 (0x1 << 13) // (HDMA) Resumes the channel 5. +#define AT91C_HDMA_RES6 (0x1 << 14) // (HDMA) Write one to this field to resume the channel 6 transfer restoring its context. +#define AT91C_HDMA_RES6_0 (0x0 << 14) // (HDMA) No effect. +#define AT91C_HDMA_RES6_1 (0x1 << 14) // (HDMA) Resumes the channel 6. +#define AT91C_HDMA_RES7 (0x1 << 15) // (HDMA) Write one to this field to resume the channel 7 transfer restoring its context. +#define AT91C_HDMA_RES7_0 (0x0 << 15) // (HDMA) No effect. +#define AT91C_HDMA_RES7_1 (0x1 << 15) // (HDMA) Resumes the channel 7. +// -------- HDMA_CHSR : (HDMA Offset: 0x30) -------- +#define AT91C_HDMA_EMPT0 (0x1 << 16) // (HDMA) When set, channel 0 is empty. +#define AT91C_HDMA_EMPT0_0 (0x0 << 16) // (HDMA) No effect. +#define AT91C_HDMA_EMPT0_1 (0x1 << 16) // (HDMA) Channel 0 empty. +#define AT91C_HDMA_EMPT1 (0x1 << 17) // (HDMA) When set, channel 1 is empty. +#define AT91C_HDMA_EMPT1_0 (0x0 << 17) // (HDMA) No effect. +#define AT91C_HDMA_EMPT1_1 (0x1 << 17) // (HDMA) Channel 1 empty. +#define AT91C_HDMA_EMPT2 (0x1 << 18) // (HDMA) When set, channel 2 is empty. +#define AT91C_HDMA_EMPT2_0 (0x0 << 18) // (HDMA) No effect. +#define AT91C_HDMA_EMPT2_1 (0x1 << 18) // (HDMA) Channel 2 empty. +#define AT91C_HDMA_EMPT3 (0x1 << 19) // (HDMA) When set, channel 3 is empty. +#define AT91C_HDMA_EMPT3_0 (0x0 << 19) // (HDMA) No effect. +#define AT91C_HDMA_EMPT3_1 (0x1 << 19) // (HDMA) Channel 3 empty. +#define AT91C_HDMA_EMPT4 (0x1 << 20) // (HDMA) When set, channel 4 is empty. +#define AT91C_HDMA_EMPT4_0 (0x0 << 20) // (HDMA) No effect. +#define AT91C_HDMA_EMPT4_1 (0x1 << 20) // (HDMA) Channel 4 empty. +#define AT91C_HDMA_EMPT5 (0x1 << 21) // (HDMA) When set, channel 5 is empty. +#define AT91C_HDMA_EMPT5_0 (0x0 << 21) // (HDMA) No effect. +#define AT91C_HDMA_EMPT5_1 (0x1 << 21) // (HDMA) Channel 5 empty. +#define AT91C_HDMA_EMPT6 (0x1 << 22) // (HDMA) When set, channel 6 is empty. +#define AT91C_HDMA_EMPT6_0 (0x0 << 22) // (HDMA) No effect. +#define AT91C_HDMA_EMPT6_1 (0x1 << 22) // (HDMA) Channel 6 empty. +#define AT91C_HDMA_EMPT7 (0x1 << 23) // (HDMA) When set, channel 7 is empty. +#define AT91C_HDMA_EMPT7_0 (0x0 << 23) // (HDMA) No effect. +#define AT91C_HDMA_EMPT7_1 (0x1 << 23) // (HDMA) Channel 7 empty. +#define AT91C_HDMA_STAL0 (0x1 << 24) // (HDMA) When set, channel 0 is stalled. +#define AT91C_HDMA_STAL0_0 (0x0 << 24) // (HDMA) No effect. +#define AT91C_HDMA_STAL0_1 (0x1 << 24) // (HDMA) Channel 0 stalled. +#define AT91C_HDMA_STAL1 (0x1 << 25) // (HDMA) When set, channel 1 is stalled. +#define AT91C_HDMA_STAL1_0 (0x0 << 25) // (HDMA) No effect. +#define AT91C_HDMA_STAL1_1 (0x1 << 25) // (HDMA) Channel 1 stalled. +#define AT91C_HDMA_STAL2 (0x1 << 26) // (HDMA) When set, channel 2 is stalled. +#define AT91C_HDMA_STAL2_0 (0x0 << 26) // (HDMA) No effect. +#define AT91C_HDMA_STAL2_1 (0x1 << 26) // (HDMA) Channel 2 stalled. +#define AT91C_HDMA_STAL3 (0x1 << 27) // (HDMA) When set, channel 3 is stalled. +#define AT91C_HDMA_STAL3_0 (0x0 << 27) // (HDMA) No effect. +#define AT91C_HDMA_STAL3_1 (0x1 << 27) // (HDMA) Channel 3 stalled. +#define AT91C_HDMA_STAL4 (0x1 << 28) // (HDMA) When set, channel 4 is stalled. +#define AT91C_HDMA_STAL4_0 (0x0 << 28) // (HDMA) No effect. +#define AT91C_HDMA_STAL4_1 (0x1 << 28) // (HDMA) Channel 4 stalled. +#define AT91C_HDMA_STAL5 (0x1 << 29) // (HDMA) When set, channel 5 is stalled. +#define AT91C_HDMA_STAL5_0 (0x0 << 29) // (HDMA) No effect. +#define AT91C_HDMA_STAL5_1 (0x1 << 29) // (HDMA) Channel 5 stalled. +#define AT91C_HDMA_STAL6 (0x1 << 30) // (HDMA) When set, channel 6 is stalled. +#define AT91C_HDMA_STAL6_0 (0x0 << 30) // (HDMA) No effect. +#define AT91C_HDMA_STAL6_1 (0x1 << 30) // (HDMA) Channel 6 stalled. +#define AT91C_HDMA_STAL7 (0x1 << 31) // (HDMA) When set, channel 7 is stalled. +#define AT91C_HDMA_STAL7_0 (0x0 << 31) // (HDMA) No effect. +#define AT91C_HDMA_STAL7_1 (0x1 << 31) // (HDMA) Channel 7 stalled. +// -------- HDMA_RSVD : (HDMA Offset: 0x34) -------- +// -------- HDMA_RSVD : (HDMA Offset: 0x38) -------- +// -------- HDMA_VER : (HDMA Offset: 0x1fc) -------- + +// ***************************************************************************** +// REGISTER ADDRESS DEFINITION FOR AT91SAM3U4 +// ***************************************************************************** +// ========== Register definition for SYS peripheral ========== +#define AT91C_SYS_GPBR (AT91_CAST(AT91_REG *) 0x400E1290) // (SYS) General Purpose Register +// ========== Register definition for HSMC4_CS0 peripheral ========== +#define AT91C_CS0_MODE (AT91_CAST(AT91_REG *) 0x400E0080) // (HSMC4_CS0) Mode Register +#define AT91C_CS0_PULSE (AT91_CAST(AT91_REG *) 0x400E0074) // (HSMC4_CS0) Pulse Register +#define AT91C_CS0_CYCLE (AT91_CAST(AT91_REG *) 0x400E0078) // (HSMC4_CS0) Cycle Register +#define AT91C_CS0_TIMINGS (AT91_CAST(AT91_REG *) 0x400E007C) // (HSMC4_CS0) Timmings Register +#define AT91C_CS0_SETUP (AT91_CAST(AT91_REG *) 0x400E0070) // (HSMC4_CS0) Setup Register +// ========== Register definition for HSMC4_CS1 peripheral ========== +#define AT91C_CS1_CYCLE (AT91_CAST(AT91_REG *) 0x400E008C) // (HSMC4_CS1) Cycle Register +#define AT91C_CS1_PULSE (AT91_CAST(AT91_REG *) 0x400E0088) // (HSMC4_CS1) Pulse Register +#define AT91C_CS1_MODE (AT91_CAST(AT91_REG *) 0x400E0094) // (HSMC4_CS1) Mode Register +#define AT91C_CS1_SETUP (AT91_CAST(AT91_REG *) 0x400E0084) // (HSMC4_CS1) Setup Register +#define AT91C_CS1_TIMINGS (AT91_CAST(AT91_REG *) 0x400E0090) // (HSMC4_CS1) Timmings Register +// ========== Register definition for HSMC4_CS2 peripheral ========== +#define AT91C_CS2_PULSE (AT91_CAST(AT91_REG *) 0x400E009C) // (HSMC4_CS2) Pulse Register +#define AT91C_CS2_TIMINGS (AT91_CAST(AT91_REG *) 0x400E00A4) // (HSMC4_CS2) Timmings Register +#define AT91C_CS2_CYCLE (AT91_CAST(AT91_REG *) 0x400E00A0) // (HSMC4_CS2) Cycle Register +#define AT91C_CS2_MODE (AT91_CAST(AT91_REG *) 0x400E00A8) // (HSMC4_CS2) Mode Register +#define AT91C_CS2_SETUP (AT91_CAST(AT91_REG *) 0x400E0098) // (HSMC4_CS2) Setup Register +// ========== Register definition for HSMC4_CS3 peripheral ========== +#define AT91C_CS3_MODE (AT91_CAST(AT91_REG *) 0x400E00BC) // (HSMC4_CS3) Mode Register +#define AT91C_CS3_TIMINGS (AT91_CAST(AT91_REG *) 0x400E00B8) // (HSMC4_CS3) Timmings Register +#define AT91C_CS3_SETUP (AT91_CAST(AT91_REG *) 0x400E00AC) // (HSMC4_CS3) Setup Register +#define AT91C_CS3_CYCLE (AT91_CAST(AT91_REG *) 0x400E00B4) // (HSMC4_CS3) Cycle Register +#define AT91C_CS3_PULSE (AT91_CAST(AT91_REG *) 0x400E00B0) // (HSMC4_CS3) Pulse Register +// ========== Register definition for HSMC4_NFC peripheral ========== +#define AT91C_NFC_MODE (AT91_CAST(AT91_REG *) 0x400E010C) // (HSMC4_NFC) Mode Register +#define AT91C_NFC_CYCLE (AT91_CAST(AT91_REG *) 0x400E0104) // (HSMC4_NFC) Cycle Register +#define AT91C_NFC_PULSE (AT91_CAST(AT91_REG *) 0x400E0100) // (HSMC4_NFC) Pulse Register +#define AT91C_NFC_SETUP (AT91_CAST(AT91_REG *) 0x400E00FC) // (HSMC4_NFC) Setup Register +#define AT91C_NFC_TIMINGS (AT91_CAST(AT91_REG *) 0x400E0108) // (HSMC4_NFC) Timmings Register +// ========== Register definition for HSMC4 peripheral ========== +#define AT91C_HSMC4_IPNAME1 (AT91_CAST(AT91_REG *) 0x400E01F0) // (HSMC4) Write Protection Status Register +#define AT91C_HSMC4_ECCPR6 (AT91_CAST(AT91_REG *) 0x400E0048) // (HSMC4) ECC Parity register 6 +#define AT91C_HSMC4_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400E01EC) // (HSMC4) Write Protection Status Register +#define AT91C_HSMC4_ECCPR11 (AT91_CAST(AT91_REG *) 0x400E005C) // (HSMC4) ECC Parity register 11 +#define AT91C_HSMC4_SR (AT91_CAST(AT91_REG *) 0x400E0008) // (HSMC4) Status Register +#define AT91C_HSMC4_IMR (AT91_CAST(AT91_REG *) 0x400E0014) // (HSMC4) Interrupt Mask Register +#define AT91C_HSMC4_WPSR (AT91_CAST(AT91_REG *) 0x400E01E8) // (HSMC4) Write Protection Status Register +#define AT91C_HSMC4_BANK (AT91_CAST(AT91_REG *) 0x400E001C) // (HSMC4) Bank Register +#define AT91C_HSMC4_ECCPR8 (AT91_CAST(AT91_REG *) 0x400E0050) // (HSMC4) ECC Parity register 8 +#define AT91C_HSMC4_WPCR (AT91_CAST(AT91_REG *) 0x400E01E4) // (HSMC4) Write Protection Control register +#define AT91C_HSMC4_ECCPR2 (AT91_CAST(AT91_REG *) 0x400E0038) // (HSMC4) ECC Parity register 2 +#define AT91C_HSMC4_ECCPR1 (AT91_CAST(AT91_REG *) 0x400E0030) // (HSMC4) ECC Parity register 1 +#define AT91C_HSMC4_ECCSR2 (AT91_CAST(AT91_REG *) 0x400E0034) // (HSMC4) ECC Status register 2 +#define AT91C_HSMC4_OCMS (AT91_CAST(AT91_REG *) 0x400E0110) // (HSMC4) OCMS MODE register +#define AT91C_HSMC4_ECCPR9 (AT91_CAST(AT91_REG *) 0x400E0054) // (HSMC4) ECC Parity register 9 +#define AT91C_HSMC4_DUMMY (AT91_CAST(AT91_REG *) 0x400E0200) // (HSMC4) This rtegister was created only ti have AHB constants +#define AT91C_HSMC4_ECCPR5 (AT91_CAST(AT91_REG *) 0x400E0044) // (HSMC4) ECC Parity register 5 +#define AT91C_HSMC4_ECCCR (AT91_CAST(AT91_REG *) 0x400E0020) // (HSMC4) ECC reset register +#define AT91C_HSMC4_KEY2 (AT91_CAST(AT91_REG *) 0x400E0118) // (HSMC4) KEY2 Register +#define AT91C_HSMC4_IER (AT91_CAST(AT91_REG *) 0x400E000C) // (HSMC4) Interrupt Enable Register +#define AT91C_HSMC4_ECCSR1 (AT91_CAST(AT91_REG *) 0x400E0028) // (HSMC4) ECC Status register 1 +#define AT91C_HSMC4_IDR (AT91_CAST(AT91_REG *) 0x400E0010) // (HSMC4) Interrupt Disable Register +#define AT91C_HSMC4_ECCPR0 (AT91_CAST(AT91_REG *) 0x400E002C) // (HSMC4) ECC Parity register 0 +#define AT91C_HSMC4_FEATURES (AT91_CAST(AT91_REG *) 0x400E01F8) // (HSMC4) Write Protection Status Register +#define AT91C_HSMC4_ECCPR7 (AT91_CAST(AT91_REG *) 0x400E004C) // (HSMC4) ECC Parity register 7 +#define AT91C_HSMC4_ECCPR12 (AT91_CAST(AT91_REG *) 0x400E0060) // (HSMC4) ECC Parity register 12 +#define AT91C_HSMC4_ECCPR10 (AT91_CAST(AT91_REG *) 0x400E0058) // (HSMC4) ECC Parity register 10 +#define AT91C_HSMC4_KEY1 (AT91_CAST(AT91_REG *) 0x400E0114) // (HSMC4) KEY1 Register +#define AT91C_HSMC4_VER (AT91_CAST(AT91_REG *) 0x400E01FC) // (HSMC4) HSMC4 Version Register +#define AT91C_HSMC4_Eccpr15 (AT91_CAST(AT91_REG *) 0x400E006C) // (HSMC4) ECC Parity register 15 +#define AT91C_HSMC4_ECCPR4 (AT91_CAST(AT91_REG *) 0x400E0040) // (HSMC4) ECC Parity register 4 +#define AT91C_HSMC4_IPNAME2 (AT91_CAST(AT91_REG *) 0x400E01F4) // (HSMC4) Write Protection Status Register +#define AT91C_HSMC4_ECCCMD (AT91_CAST(AT91_REG *) 0x400E0024) // (HSMC4) ECC Page size register +#define AT91C_HSMC4_ADDR (AT91_CAST(AT91_REG *) 0x400E0018) // (HSMC4) Address Cycle Zero Register +#define AT91C_HSMC4_ECCPR3 (AT91_CAST(AT91_REG *) 0x400E003C) // (HSMC4) ECC Parity register 3 +#define AT91C_HSMC4_CFG (AT91_CAST(AT91_REG *) 0x400E0000) // (HSMC4) Configuration Register +#define AT91C_HSMC4_CTRL (AT91_CAST(AT91_REG *) 0x400E0004) // (HSMC4) Control Register +#define AT91C_HSMC4_ECCPR13 (AT91_CAST(AT91_REG *) 0x400E0064) // (HSMC4) ECC Parity register 13 +#define AT91C_HSMC4_ECCPR14 (AT91_CAST(AT91_REG *) 0x400E0068) // (HSMC4) ECC Parity register 14 +// ========== Register definition for MATRIX peripheral ========== +#define AT91C_MATRIX_SFR2 (AT91_CAST(AT91_REG *) 0x400E0318) // (MATRIX) Special Function Register 2 +#define AT91C_MATRIX_SFR3 (AT91_CAST(AT91_REG *) 0x400E031C) // (MATRIX) Special Function Register 3 +#define AT91C_MATRIX_SCFG8 (AT91_CAST(AT91_REG *) 0x400E0260) // (MATRIX) Slave Configuration Register 8 +#define AT91C_MATRIX_MCFG2 (AT91_CAST(AT91_REG *) 0x400E0208) // (MATRIX) Master Configuration Register 2 +#define AT91C_MATRIX_MCFG7 (AT91_CAST(AT91_REG *) 0x400E021C) // (MATRIX) Master Configuration Register 7 +#define AT91C_MATRIX_SCFG3 (AT91_CAST(AT91_REG *) 0x400E024C) // (MATRIX) Slave Configuration Register 3 +#define AT91C_MATRIX_SCFG0 (AT91_CAST(AT91_REG *) 0x400E0240) // (MATRIX) Slave Configuration Register 0 +#define AT91C_MATRIX_SFR12 (AT91_CAST(AT91_REG *) 0x400E0340) // (MATRIX) Special Function Register 12 +#define AT91C_MATRIX_SCFG1 (AT91_CAST(AT91_REG *) 0x400E0244) // (MATRIX) Slave Configuration Register 1 +#define AT91C_MATRIX_SFR8 (AT91_CAST(AT91_REG *) 0x400E0330) // (MATRIX) Special Function Register 8 +#define AT91C_MATRIX_VER (AT91_CAST(AT91_REG *) 0x400E03FC) // (MATRIX) HMATRIX2 VERSION REGISTER +#define AT91C_MATRIX_SFR13 (AT91_CAST(AT91_REG *) 0x400E0344) // (MATRIX) Special Function Register 13 +#define AT91C_MATRIX_SFR5 (AT91_CAST(AT91_REG *) 0x400E0324) // (MATRIX) Special Function Register 5 +#define AT91C_MATRIX_MCFG0 (AT91_CAST(AT91_REG *) 0x400E0200) // (MATRIX) Master Configuration Register 0 : ARM I and D +#define AT91C_MATRIX_SCFG6 (AT91_CAST(AT91_REG *) 0x400E0258) // (MATRIX) Slave Configuration Register 6 +#define AT91C_MATRIX_SFR1 (AT91_CAST(AT91_REG *) 0x400E0314) // (MATRIX) Special Function Register 1 +#define AT91C_MATRIX_SFR14 (AT91_CAST(AT91_REG *) 0x400E0348) // (MATRIX) Special Function Register 14 +#define AT91C_MATRIX_SFR15 (AT91_CAST(AT91_REG *) 0x400E034C) // (MATRIX) Special Function Register 15 +#define AT91C_MATRIX_SFR6 (AT91_CAST(AT91_REG *) 0x400E0328) // (MATRIX) Special Function Register 6 +#define AT91C_MATRIX_SFR11 (AT91_CAST(AT91_REG *) 0x400E033C) // (MATRIX) Special Function Register 11 +#define AT91C_MATRIX_IPNAME2 (AT91_CAST(AT91_REG *) 0x400E03F4) // (MATRIX) HMATRIX2 IPNAME2 REGISTER +#define AT91C_MATRIX_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400E03EC) // (MATRIX) HMATRIX2 ADDRSIZE REGISTER +#define AT91C_MATRIX_MCFG5 (AT91_CAST(AT91_REG *) 0x400E0214) // (MATRIX) Master Configuration Register 5 +#define AT91C_MATRIX_SFR9 (AT91_CAST(AT91_REG *) 0x400E0334) // (MATRIX) Special Function Register 9 +#define AT91C_MATRIX_MCFG3 (AT91_CAST(AT91_REG *) 0x400E020C) // (MATRIX) Master Configuration Register 3 +#define AT91C_MATRIX_SCFG4 (AT91_CAST(AT91_REG *) 0x400E0250) // (MATRIX) Slave Configuration Register 4 +#define AT91C_MATRIX_MCFG1 (AT91_CAST(AT91_REG *) 0x400E0204) // (MATRIX) Master Configuration Register 1 : ARM S +#define AT91C_MATRIX_SCFG7 (AT91_CAST(AT91_REG *) 0x400E025C) // (MATRIX) Slave Configuration Register 5 +#define AT91C_MATRIX_SFR10 (AT91_CAST(AT91_REG *) 0x400E0338) // (MATRIX) Special Function Register 10 +#define AT91C_MATRIX_SCFG2 (AT91_CAST(AT91_REG *) 0x400E0248) // (MATRIX) Slave Configuration Register 2 +#define AT91C_MATRIX_SFR7 (AT91_CAST(AT91_REG *) 0x400E032C) // (MATRIX) Special Function Register 7 +#define AT91C_MATRIX_IPNAME1 (AT91_CAST(AT91_REG *) 0x400E03F0) // (MATRIX) HMATRIX2 IPNAME1 REGISTER +#define AT91C_MATRIX_MCFG4 (AT91_CAST(AT91_REG *) 0x400E0210) // (MATRIX) Master Configuration Register 4 +#define AT91C_MATRIX_SFR0 (AT91_CAST(AT91_REG *) 0x400E0310) // (MATRIX) Special Function Register 0 +#define AT91C_MATRIX_FEATURES (AT91_CAST(AT91_REG *) 0x400E03F8) // (MATRIX) HMATRIX2 FEATURES REGISTER +#define AT91C_MATRIX_SCFG5 (AT91_CAST(AT91_REG *) 0x400E0254) // (MATRIX) Slave Configuration Register 5 +#define AT91C_MATRIX_MCFG6 (AT91_CAST(AT91_REG *) 0x400E0218) // (MATRIX) Master Configuration Register 6 +#define AT91C_MATRIX_SFR4 (AT91_CAST(AT91_REG *) 0x400E0320) // (MATRIX) Special Function Register 4 +// ========== Register definition for NVIC peripheral ========== +#define AT91C_NVIC_MMAR (AT91_CAST(AT91_REG *) 0xE000ED34) // (NVIC) Mem Manage Address Register +#define AT91C_NVIC_STIR (AT91_CAST(AT91_REG *) 0xE000EF00) // (NVIC) Software Trigger Interrupt Register +#define AT91C_NVIC_MMFR2 (AT91_CAST(AT91_REG *) 0xE000ED58) // (NVIC) Memory Model Feature register2 +#define AT91C_NVIC_CPUID (AT91_CAST(AT91_REG *) 0xE000ED00) // (NVIC) CPUID Base Register +#define AT91C_NVIC_DFSR (AT91_CAST(AT91_REG *) 0xE000ED30) // (NVIC) Debug Fault Status Register +#define AT91C_NVIC_HAND4PR (AT91_CAST(AT91_REG *) 0xE000ED18) // (NVIC) System Handlers 4-7 Priority Register +#define AT91C_NVIC_HFSR (AT91_CAST(AT91_REG *) 0xE000ED2C) // (NVIC) Hard Fault Status Register +#define AT91C_NVIC_PID6 (AT91_CAST(AT91_REG *) 0xE000EFD8) // (NVIC) Peripheral identification register +#define AT91C_NVIC_PFR0 (AT91_CAST(AT91_REG *) 0xE000ED40) // (NVIC) Processor Feature register0 +#define AT91C_NVIC_VTOFFR (AT91_CAST(AT91_REG *) 0xE000ED08) // (NVIC) Vector Table Offset Register +#define AT91C_NVIC_ISPR (AT91_CAST(AT91_REG *) 0xE000E200) // (NVIC) Set Pending Register +#define AT91C_NVIC_PID0 (AT91_CAST(AT91_REG *) 0xE000EFE0) // (NVIC) Peripheral identification register b7:0 +#define AT91C_NVIC_PID7 (AT91_CAST(AT91_REG *) 0xE000EFDC) // (NVIC) Peripheral identification register +#define AT91C_NVIC_STICKRVR (AT91_CAST(AT91_REG *) 0xE000E014) // (NVIC) SysTick Reload Value Register +#define AT91C_NVIC_PID2 (AT91_CAST(AT91_REG *) 0xE000EFE8) // (NVIC) Peripheral identification register b23:16 +#define AT91C_NVIC_ISAR0 (AT91_CAST(AT91_REG *) 0xE000ED60) // (NVIC) ISA Feature register0 +#define AT91C_NVIC_SCR (AT91_CAST(AT91_REG *) 0xE000ED10) // (NVIC) System Control Register +#define AT91C_NVIC_PID4 (AT91_CAST(AT91_REG *) 0xE000EFD0) // (NVIC) Peripheral identification register +#define AT91C_NVIC_ISAR2 (AT91_CAST(AT91_REG *) 0xE000ED68) // (NVIC) ISA Feature register2 +#define AT91C_NVIC_ISER (AT91_CAST(AT91_REG *) 0xE000E100) // (NVIC) Set Enable Register +#define AT91C_NVIC_IPR (AT91_CAST(AT91_REG *) 0xE000E400) // (NVIC) Interrupt Mask Register +#define AT91C_NVIC_AIRCR (AT91_CAST(AT91_REG *) 0xE000ED0C) // (NVIC) Application Interrupt/Reset Control Reg +#define AT91C_NVIC_CID2 (AT91_CAST(AT91_REG *) 0xE000EFF8) // (NVIC) Component identification register b23:16 +#define AT91C_NVIC_ICPR (AT91_CAST(AT91_REG *) 0xE000E280) // (NVIC) Clear Pending Register +#define AT91C_NVIC_CID3 (AT91_CAST(AT91_REG *) 0xE000EFFC) // (NVIC) Component identification register b31:24 +#define AT91C_NVIC_CFSR (AT91_CAST(AT91_REG *) 0xE000ED28) // (NVIC) Configurable Fault Status Register +#define AT91C_NVIC_AFR0 (AT91_CAST(AT91_REG *) 0xE000ED4C) // (NVIC) Auxiliary Feature register0 +#define AT91C_NVIC_ICSR (AT91_CAST(AT91_REG *) 0xE000ED04) // (NVIC) Interrupt Control State Register +#define AT91C_NVIC_CCR (AT91_CAST(AT91_REG *) 0xE000ED14) // (NVIC) Configuration Control Register +#define AT91C_NVIC_CID0 (AT91_CAST(AT91_REG *) 0xE000EFF0) // (NVIC) Component identification register b7:0 +#define AT91C_NVIC_ISAR1 (AT91_CAST(AT91_REG *) 0xE000ED64) // (NVIC) ISA Feature register1 +#define AT91C_NVIC_STICKCVR (AT91_CAST(AT91_REG *) 0xE000E018) // (NVIC) SysTick Current Value Register +#define AT91C_NVIC_STICKCSR (AT91_CAST(AT91_REG *) 0xE000E010) // (NVIC) SysTick Control and Status Register +#define AT91C_NVIC_CID1 (AT91_CAST(AT91_REG *) 0xE000EFF4) // (NVIC) Component identification register b15:8 +#define AT91C_NVIC_DFR0 (AT91_CAST(AT91_REG *) 0xE000ED48) // (NVIC) Debug Feature register0 +#define AT91C_NVIC_MMFR3 (AT91_CAST(AT91_REG *) 0xE000ED5C) // (NVIC) Memory Model Feature register3 +#define AT91C_NVIC_MMFR0 (AT91_CAST(AT91_REG *) 0xE000ED50) // (NVIC) Memory Model Feature register0 +#define AT91C_NVIC_STICKCALVR (AT91_CAST(AT91_REG *) 0xE000E01C) // (NVIC) SysTick Calibration Value Register +#define AT91C_NVIC_PID1 (AT91_CAST(AT91_REG *) 0xE000EFE4) // (NVIC) Peripheral identification register b15:8 +#define AT91C_NVIC_HAND12PR (AT91_CAST(AT91_REG *) 0xE000ED20) // (NVIC) System Handlers 12-15 Priority Register +#define AT91C_NVIC_MMFR1 (AT91_CAST(AT91_REG *) 0xE000ED54) // (NVIC) Memory Model Feature register1 +#define AT91C_NVIC_AFSR (AT91_CAST(AT91_REG *) 0xE000ED3C) // (NVIC) Auxiliary Fault Status Register +#define AT91C_NVIC_HANDCSR (AT91_CAST(AT91_REG *) 0xE000ED24) // (NVIC) System Handler Control and State Register +#define AT91C_NVIC_ISAR4 (AT91_CAST(AT91_REG *) 0xE000ED70) // (NVIC) ISA Feature register4 +#define AT91C_NVIC_ABR (AT91_CAST(AT91_REG *) 0xE000E300) // (NVIC) Active Bit Register +#define AT91C_NVIC_PFR1 (AT91_CAST(AT91_REG *) 0xE000ED44) // (NVIC) Processor Feature register1 +#define AT91C_NVIC_PID5 (AT91_CAST(AT91_REG *) 0xE000EFD4) // (NVIC) Peripheral identification register +#define AT91C_NVIC_ICTR (AT91_CAST(AT91_REG *) 0xE000E004) // (NVIC) Interrupt Control Type Register +#define AT91C_NVIC_ICER (AT91_CAST(AT91_REG *) 0xE000E180) // (NVIC) Clear enable Register +#define AT91C_NVIC_PID3 (AT91_CAST(AT91_REG *) 0xE000EFEC) // (NVIC) Peripheral identification register b31:24 +#define AT91C_NVIC_ISAR3 (AT91_CAST(AT91_REG *) 0xE000ED6C) // (NVIC) ISA Feature register3 +#define AT91C_NVIC_HAND8PR (AT91_CAST(AT91_REG *) 0xE000ED1C) // (NVIC) System Handlers 8-11 Priority Register +#define AT91C_NVIC_BFAR (AT91_CAST(AT91_REG *) 0xE000ED38) // (NVIC) Bus Fault Address Register +// ========== Register definition for MPU peripheral ========== +#define AT91C_MPU_REG_BASE_ADDR3 (AT91_CAST(AT91_REG *) 0xE000EDB4) // (MPU) MPU Region Base Address Register alias 3 +#define AT91C_MPU_REG_NB (AT91_CAST(AT91_REG *) 0xE000ED98) // (MPU) MPU Region Number Register +#define AT91C_MPU_ATTR_SIZE1 (AT91_CAST(AT91_REG *) 0xE000EDA8) // (MPU) MPU Attribute and Size Register alias 1 +#define AT91C_MPU_REG_BASE_ADDR1 (AT91_CAST(AT91_REG *) 0xE000EDA4) // (MPU) MPU Region Base Address Register alias 1 +#define AT91C_MPU_ATTR_SIZE3 (AT91_CAST(AT91_REG *) 0xE000EDB8) // (MPU) MPU Attribute and Size Register alias 3 +#define AT91C_MPU_CTRL (AT91_CAST(AT91_REG *) 0xE000ED94) // (MPU) MPU Control Register +#define AT91C_MPU_ATTR_SIZE2 (AT91_CAST(AT91_REG *) 0xE000EDB0) // (MPU) MPU Attribute and Size Register alias 2 +#define AT91C_MPU_REG_BASE_ADDR (AT91_CAST(AT91_REG *) 0xE000ED9C) // (MPU) MPU Region Base Address Register +#define AT91C_MPU_REG_BASE_ADDR2 (AT91_CAST(AT91_REG *) 0xE000EDAC) // (MPU) MPU Region Base Address Register alias 2 +#define AT91C_MPU_ATTR_SIZE (AT91_CAST(AT91_REG *) 0xE000EDA0) // (MPU) MPU Attribute and Size Register +#define AT91C_MPU_TYPE (AT91_CAST(AT91_REG *) 0xE000ED90) // (MPU) MPU Type Register +// ========== Register definition for CM3 peripheral ========== +#define AT91C_CM3_SHCSR (AT91_CAST(AT91_REG *) 0xE000ED24) // (CM3) System Handler Control and State Register +#define AT91C_CM3_CCR (AT91_CAST(AT91_REG *) 0xE000ED14) // (CM3) Configuration Control Register +#define AT91C_CM3_ICSR (AT91_CAST(AT91_REG *) 0xE000ED04) // (CM3) Interrupt Control State Register +#define AT91C_CM3_CPUID (AT91_CAST(AT91_REG *) 0xE000ED00) // (CM3) CPU ID Base Register +#define AT91C_CM3_SCR (AT91_CAST(AT91_REG *) 0xE000ED10) // (CM3) System Controller Register +#define AT91C_CM3_AIRCR (AT91_CAST(AT91_REG *) 0xE000ED0C) // (CM3) Application Interrupt and Reset Control Register +#define AT91C_CM3_SHPR (AT91_CAST(AT91_REG *) 0xE000ED18) // (CM3) System Handler Priority Register +#define AT91C_CM3_VTOR (AT91_CAST(AT91_REG *) 0xE000ED08) // (CM3) Vector Table Offset Register +// ========== Register definition for PDC_DBGU peripheral ========== +#define AT91C_DBGU_TPR (AT91_CAST(AT91_REG *) 0x400E0708) // (PDC_DBGU) Transmit Pointer Register +#define AT91C_DBGU_PTCR (AT91_CAST(AT91_REG *) 0x400E0720) // (PDC_DBGU) PDC Transfer Control Register +#define AT91C_DBGU_TNCR (AT91_CAST(AT91_REG *) 0x400E071C) // (PDC_DBGU) Transmit Next Counter Register +#define AT91C_DBGU_PTSR (AT91_CAST(AT91_REG *) 0x400E0724) // (PDC_DBGU) PDC Transfer Status Register +#define AT91C_DBGU_RNCR (AT91_CAST(AT91_REG *) 0x400E0714) // (PDC_DBGU) Receive Next Counter Register +#define AT91C_DBGU_RPR (AT91_CAST(AT91_REG *) 0x400E0700) // (PDC_DBGU) Receive Pointer Register +#define AT91C_DBGU_TCR (AT91_CAST(AT91_REG *) 0x400E070C) // (PDC_DBGU) Transmit Counter Register +#define AT91C_DBGU_RNPR (AT91_CAST(AT91_REG *) 0x400E0710) // (PDC_DBGU) Receive Next Pointer Register +#define AT91C_DBGU_TNPR (AT91_CAST(AT91_REG *) 0x400E0718) // (PDC_DBGU) Transmit Next Pointer Register +#define AT91C_DBGU_RCR (AT91_CAST(AT91_REG *) 0x400E0704) // (PDC_DBGU) Receive Counter Register +// ========== Register definition for DBGU peripheral ========== +#define AT91C_DBGU_CR (AT91_CAST(AT91_REG *) 0x400E0600) // (DBGU) Control Register +#define AT91C_DBGU_IDR (AT91_CAST(AT91_REG *) 0x400E060C) // (DBGU) Interrupt Disable Register +#define AT91C_DBGU_CIDR (AT91_CAST(AT91_REG *) 0x400E0740) // (DBGU) Chip ID Register +#define AT91C_DBGU_IPNAME2 (AT91_CAST(AT91_REG *) 0x400E06F4) // (DBGU) DBGU IPNAME2 REGISTER +#define AT91C_DBGU_FEATURES (AT91_CAST(AT91_REG *) 0x400E06F8) // (DBGU) DBGU FEATURES REGISTER +#define AT91C_DBGU_FNTR (AT91_CAST(AT91_REG *) 0x400E0648) // (DBGU) Force NTRST Register +#define AT91C_DBGU_RHR (AT91_CAST(AT91_REG *) 0x400E0618) // (DBGU) Receiver Holding Register +#define AT91C_DBGU_THR (AT91_CAST(AT91_REG *) 0x400E061C) // (DBGU) Transmitter Holding Register +#define AT91C_DBGU_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400E06EC) // (DBGU) DBGU ADDRSIZE REGISTER +#define AT91C_DBGU_MR (AT91_CAST(AT91_REG *) 0x400E0604) // (DBGU) Mode Register +#define AT91C_DBGU_IER (AT91_CAST(AT91_REG *) 0x400E0608) // (DBGU) Interrupt Enable Register +#define AT91C_DBGU_BRGR (AT91_CAST(AT91_REG *) 0x400E0620) // (DBGU) Baud Rate Generator Register +#define AT91C_DBGU_CSR (AT91_CAST(AT91_REG *) 0x400E0614) // (DBGU) Channel Status Register +#define AT91C_DBGU_VER (AT91_CAST(AT91_REG *) 0x400E06FC) // (DBGU) DBGU VERSION REGISTER +#define AT91C_DBGU_IMR (AT91_CAST(AT91_REG *) 0x400E0610) // (DBGU) Interrupt Mask Register +#define AT91C_DBGU_IPNAME1 (AT91_CAST(AT91_REG *) 0x400E06F0) // (DBGU) DBGU IPNAME1 REGISTER +#define AT91C_DBGU_EXID (AT91_CAST(AT91_REG *) 0x400E0744) // (DBGU) Chip ID Extension Register +// ========== Register definition for PIOA peripheral ========== +#define AT91C_PIOA_PDR (AT91_CAST(AT91_REG *) 0x400E0C04) // (PIOA) PIO Disable Register +#define AT91C_PIOA_FRLHSR (AT91_CAST(AT91_REG *) 0x400E0CD8) // (PIOA) Fall/Rise - Low/High Status Register +#define AT91C_PIOA_KIMR (AT91_CAST(AT91_REG *) 0x400E0D38) // (PIOA) Keypad Controller Interrupt Mask Register +#define AT91C_PIOA_LSR (AT91_CAST(AT91_REG *) 0x400E0CC4) // (PIOA) Level Select Register +#define AT91C_PIOA_IFSR (AT91_CAST(AT91_REG *) 0x400E0C28) // (PIOA) Input Filter Status Register +#define AT91C_PIOA_KKRR (AT91_CAST(AT91_REG *) 0x400E0D44) // (PIOA) Keypad Controller Key Release Register +#define AT91C_PIOA_ODR (AT91_CAST(AT91_REG *) 0x400E0C14) // (PIOA) Output Disable Registerr +#define AT91C_PIOA_SCIFSR (AT91_CAST(AT91_REG *) 0x400E0C80) // (PIOA) System Clock Glitch Input Filter Select Register +#define AT91C_PIOA_PER (AT91_CAST(AT91_REG *) 0x400E0C00) // (PIOA) PIO Enable Register +#define AT91C_PIOA_VER (AT91_CAST(AT91_REG *) 0x400E0CFC) // (PIOA) PIO VERSION REGISTER +#define AT91C_PIOA_OWSR (AT91_CAST(AT91_REG *) 0x400E0CA8) // (PIOA) Output Write Status Register +#define AT91C_PIOA_KSR (AT91_CAST(AT91_REG *) 0x400E0D3C) // (PIOA) Keypad Controller Status Register +#define AT91C_PIOA_IMR (AT91_CAST(AT91_REG *) 0x400E0C48) // (PIOA) Interrupt Mask Register +#define AT91C_PIOA_OWDR (AT91_CAST(AT91_REG *) 0x400E0CA4) // (PIOA) Output Write Disable Register +#define AT91C_PIOA_MDSR (AT91_CAST(AT91_REG *) 0x400E0C58) // (PIOA) Multi-driver Status Register +#define AT91C_PIOA_IFDR (AT91_CAST(AT91_REG *) 0x400E0C24) // (PIOA) Input Filter Disable Register +#define AT91C_PIOA_AIMDR (AT91_CAST(AT91_REG *) 0x400E0CB4) // (PIOA) Additional Interrupt Modes Disables Register +#define AT91C_PIOA_CODR (AT91_CAST(AT91_REG *) 0x400E0C34) // (PIOA) Clear Output Data Register +#define AT91C_PIOA_SCDR (AT91_CAST(AT91_REG *) 0x400E0C8C) // (PIOA) Slow Clock Divider Debouncing Register +#define AT91C_PIOA_KIER (AT91_CAST(AT91_REG *) 0x400E0D30) // (PIOA) Keypad Controller Interrupt Enable Register +#define AT91C_PIOA_REHLSR (AT91_CAST(AT91_REG *) 0x400E0CD4) // (PIOA) Rising Edge/ High Level Select Register +#define AT91C_PIOA_ISR (AT91_CAST(AT91_REG *) 0x400E0C4C) // (PIOA) Interrupt Status Register +#define AT91C_PIOA_ESR (AT91_CAST(AT91_REG *) 0x400E0CC0) // (PIOA) Edge Select Register +#define AT91C_PIOA_PPUDR (AT91_CAST(AT91_REG *) 0x400E0C60) // (PIOA) Pull-up Disable Register +#define AT91C_PIOA_MDDR (AT91_CAST(AT91_REG *) 0x400E0C54) // (PIOA) Multi-driver Disable Register +#define AT91C_PIOA_PSR (AT91_CAST(AT91_REG *) 0x400E0C08) // (PIOA) PIO Status Register +#define AT91C_PIOA_PDSR (AT91_CAST(AT91_REG *) 0x400E0C3C) // (PIOA) Pin Data Status Register +#define AT91C_PIOA_IFDGSR (AT91_CAST(AT91_REG *) 0x400E0C88) // (PIOA) Glitch or Debouncing Input Filter Clock Selection Status Register +#define AT91C_PIOA_FELLSR (AT91_CAST(AT91_REG *) 0x400E0CD0) // (PIOA) Falling Edge/Low Level Select Register +#define AT91C_PIOA_PPUSR (AT91_CAST(AT91_REG *) 0x400E0C68) // (PIOA) Pull-up Status Register +#define AT91C_PIOA_OER (AT91_CAST(AT91_REG *) 0x400E0C10) // (PIOA) Output Enable Register +#define AT91C_PIOA_OSR (AT91_CAST(AT91_REG *) 0x400E0C18) // (PIOA) Output Status Register +#define AT91C_PIOA_KKPR (AT91_CAST(AT91_REG *) 0x400E0D40) // (PIOA) Keypad Controller Key Press Register +#define AT91C_PIOA_AIMMR (AT91_CAST(AT91_REG *) 0x400E0CB8) // (PIOA) Additional Interrupt Modes Mask Register +#define AT91C_PIOA_KRCR (AT91_CAST(AT91_REG *) 0x400E0D24) // (PIOA) Keypad Controller Row Column Register +#define AT91C_PIOA_IER (AT91_CAST(AT91_REG *) 0x400E0C40) // (PIOA) Interrupt Enable Register +#define AT91C_PIOA_KER (AT91_CAST(AT91_REG *) 0x400E0D20) // (PIOA) Keypad Controller Enable Register +#define AT91C_PIOA_PPUER (AT91_CAST(AT91_REG *) 0x400E0C64) // (PIOA) Pull-up Enable Register +#define AT91C_PIOA_KIDR (AT91_CAST(AT91_REG *) 0x400E0D34) // (PIOA) Keypad Controller Interrupt Disable Register +#define AT91C_PIOA_ABSR (AT91_CAST(AT91_REG *) 0x400E0C70) // (PIOA) Peripheral AB Select Register +#define AT91C_PIOA_LOCKSR (AT91_CAST(AT91_REG *) 0x400E0CE0) // (PIOA) Lock Status Register +#define AT91C_PIOA_DIFSR (AT91_CAST(AT91_REG *) 0x400E0C84) // (PIOA) Debouncing Input Filter Select Register +#define AT91C_PIOA_MDER (AT91_CAST(AT91_REG *) 0x400E0C50) // (PIOA) Multi-driver Enable Register +#define AT91C_PIOA_AIMER (AT91_CAST(AT91_REG *) 0x400E0CB0) // (PIOA) Additional Interrupt Modes Enable Register +#define AT91C_PIOA_ELSR (AT91_CAST(AT91_REG *) 0x400E0CC8) // (PIOA) Edge/Level Status Register +#define AT91C_PIOA_IFER (AT91_CAST(AT91_REG *) 0x400E0C20) // (PIOA) Input Filter Enable Register +#define AT91C_PIOA_KDR (AT91_CAST(AT91_REG *) 0x400E0D28) // (PIOA) Keypad Controller Debouncing Register +#define AT91C_PIOA_IDR (AT91_CAST(AT91_REG *) 0x400E0C44) // (PIOA) Interrupt Disable Register +#define AT91C_PIOA_OWER (AT91_CAST(AT91_REG *) 0x400E0CA0) // (PIOA) Output Write Enable Register +#define AT91C_PIOA_ODSR (AT91_CAST(AT91_REG *) 0x400E0C38) // (PIOA) Output Data Status Register +#define AT91C_PIOA_SODR (AT91_CAST(AT91_REG *) 0x400E0C30) // (PIOA) Set Output Data Register +// ========== Register definition for PIOB peripheral ========== +#define AT91C_PIOB_KIDR (AT91_CAST(AT91_REG *) 0x400E0F34) // (PIOB) Keypad Controller Interrupt Disable Register +#define AT91C_PIOB_OWSR (AT91_CAST(AT91_REG *) 0x400E0EA8) // (PIOB) Output Write Status Register +#define AT91C_PIOB_PSR (AT91_CAST(AT91_REG *) 0x400E0E08) // (PIOB) PIO Status Register +#define AT91C_PIOB_MDER (AT91_CAST(AT91_REG *) 0x400E0E50) // (PIOB) Multi-driver Enable Register +#define AT91C_PIOB_ODR (AT91_CAST(AT91_REG *) 0x400E0E14) // (PIOB) Output Disable Registerr +#define AT91C_PIOB_IDR (AT91_CAST(AT91_REG *) 0x400E0E44) // (PIOB) Interrupt Disable Register +#define AT91C_PIOB_AIMER (AT91_CAST(AT91_REG *) 0x400E0EB0) // (PIOB) Additional Interrupt Modes Enable Register +#define AT91C_PIOB_DIFSR (AT91_CAST(AT91_REG *) 0x400E0E84) // (PIOB) Debouncing Input Filter Select Register +#define AT91C_PIOB_PDR (AT91_CAST(AT91_REG *) 0x400E0E04) // (PIOB) PIO Disable Register +#define AT91C_PIOB_REHLSR (AT91_CAST(AT91_REG *) 0x400E0ED4) // (PIOB) Rising Edge/ High Level Select Register +#define AT91C_PIOB_PDSR (AT91_CAST(AT91_REG *) 0x400E0E3C) // (PIOB) Pin Data Status Register +#define AT91C_PIOB_PPUDR (AT91_CAST(AT91_REG *) 0x400E0E60) // (PIOB) Pull-up Disable Register +#define AT91C_PIOB_LSR (AT91_CAST(AT91_REG *) 0x400E0EC4) // (PIOB) Level Select Register +#define AT91C_PIOB_OWDR (AT91_CAST(AT91_REG *) 0x400E0EA4) // (PIOB) Output Write Disable Register +#define AT91C_PIOB_FELLSR (AT91_CAST(AT91_REG *) 0x400E0ED0) // (PIOB) Falling Edge/Low Level Select Register +#define AT91C_PIOB_IFER (AT91_CAST(AT91_REG *) 0x400E0E20) // (PIOB) Input Filter Enable Register +#define AT91C_PIOB_ABSR (AT91_CAST(AT91_REG *) 0x400E0E70) // (PIOB) Peripheral AB Select Register +#define AT91C_PIOB_KIMR (AT91_CAST(AT91_REG *) 0x400E0F38) // (PIOB) Keypad Controller Interrupt Mask Register +#define AT91C_PIOB_KKPR (AT91_CAST(AT91_REG *) 0x400E0F40) // (PIOB) Keypad Controller Key Press Register +#define AT91C_PIOB_FRLHSR (AT91_CAST(AT91_REG *) 0x400E0ED8) // (PIOB) Fall/Rise - Low/High Status Register +#define AT91C_PIOB_AIMDR (AT91_CAST(AT91_REG *) 0x400E0EB4) // (PIOB) Additional Interrupt Modes Disables Register +#define AT91C_PIOB_SCIFSR (AT91_CAST(AT91_REG *) 0x400E0E80) // (PIOB) System Clock Glitch Input Filter Select Register +#define AT91C_PIOB_VER (AT91_CAST(AT91_REG *) 0x400E0EFC) // (PIOB) PIO VERSION REGISTER +#define AT91C_PIOB_PER (AT91_CAST(AT91_REG *) 0x400E0E00) // (PIOB) PIO Enable Register +#define AT91C_PIOB_ELSR (AT91_CAST(AT91_REG *) 0x400E0EC8) // (PIOB) Edge/Level Status Register +#define AT91C_PIOB_IMR (AT91_CAST(AT91_REG *) 0x400E0E48) // (PIOB) Interrupt Mask Register +#define AT91C_PIOB_PPUSR (AT91_CAST(AT91_REG *) 0x400E0E68) // (PIOB) Pull-up Status Register +#define AT91C_PIOB_SCDR (AT91_CAST(AT91_REG *) 0x400E0E8C) // (PIOB) Slow Clock Divider Debouncing Register +#define AT91C_PIOB_KSR (AT91_CAST(AT91_REG *) 0x400E0F3C) // (PIOB) Keypad Controller Status Register +#define AT91C_PIOB_IFDGSR (AT91_CAST(AT91_REG *) 0x400E0E88) // (PIOB) Glitch or Debouncing Input Filter Clock Selection Status Register +#define AT91C_PIOB_ESR (AT91_CAST(AT91_REG *) 0x400E0EC0) // (PIOB) Edge Select Register +#define AT91C_PIOB_ODSR (AT91_CAST(AT91_REG *) 0x400E0E38) // (PIOB) Output Data Status Register +#define AT91C_PIOB_IFDR (AT91_CAST(AT91_REG *) 0x400E0E24) // (PIOB) Input Filter Disable Register +#define AT91C_PIOB_SODR (AT91_CAST(AT91_REG *) 0x400E0E30) // (PIOB) Set Output Data Register +#define AT91C_PIOB_IER (AT91_CAST(AT91_REG *) 0x400E0E40) // (PIOB) Interrupt Enable Register +#define AT91C_PIOB_MDSR (AT91_CAST(AT91_REG *) 0x400E0E58) // (PIOB) Multi-driver Status Register +#define AT91C_PIOB_ISR (AT91_CAST(AT91_REG *) 0x400E0E4C) // (PIOB) Interrupt Status Register +#define AT91C_PIOB_IFSR (AT91_CAST(AT91_REG *) 0x400E0E28) // (PIOB) Input Filter Status Register +#define AT91C_PIOB_KER (AT91_CAST(AT91_REG *) 0x400E0F20) // (PIOB) Keypad Controller Enable Register +#define AT91C_PIOB_KKRR (AT91_CAST(AT91_REG *) 0x400E0F44) // (PIOB) Keypad Controller Key Release Register +#define AT91C_PIOB_PPUER (AT91_CAST(AT91_REG *) 0x400E0E64) // (PIOB) Pull-up Enable Register +#define AT91C_PIOB_LOCKSR (AT91_CAST(AT91_REG *) 0x400E0EE0) // (PIOB) Lock Status Register +#define AT91C_PIOB_OWER (AT91_CAST(AT91_REG *) 0x400E0EA0) // (PIOB) Output Write Enable Register +#define AT91C_PIOB_KIER (AT91_CAST(AT91_REG *) 0x400E0F30) // (PIOB) Keypad Controller Interrupt Enable Register +#define AT91C_PIOB_MDDR (AT91_CAST(AT91_REG *) 0x400E0E54) // (PIOB) Multi-driver Disable Register +#define AT91C_PIOB_KRCR (AT91_CAST(AT91_REG *) 0x400E0F24) // (PIOB) Keypad Controller Row Column Register +#define AT91C_PIOB_CODR (AT91_CAST(AT91_REG *) 0x400E0E34) // (PIOB) Clear Output Data Register +#define AT91C_PIOB_KDR (AT91_CAST(AT91_REG *) 0x400E0F28) // (PIOB) Keypad Controller Debouncing Register +#define AT91C_PIOB_AIMMR (AT91_CAST(AT91_REG *) 0x400E0EB8) // (PIOB) Additional Interrupt Modes Mask Register +#define AT91C_PIOB_OER (AT91_CAST(AT91_REG *) 0x400E0E10) // (PIOB) Output Enable Register +#define AT91C_PIOB_OSR (AT91_CAST(AT91_REG *) 0x400E0E18) // (PIOB) Output Status Register +// ========== Register definition for PIOC peripheral ========== +#define AT91C_PIOC_FELLSR (AT91_CAST(AT91_REG *) 0x400E10D0) // (PIOC) Falling Edge/Low Level Select Register +#define AT91C_PIOC_FRLHSR (AT91_CAST(AT91_REG *) 0x400E10D8) // (PIOC) Fall/Rise - Low/High Status Register +#define AT91C_PIOC_MDDR (AT91_CAST(AT91_REG *) 0x400E1054) // (PIOC) Multi-driver Disable Register +#define AT91C_PIOC_IFDGSR (AT91_CAST(AT91_REG *) 0x400E1088) // (PIOC) Glitch or Debouncing Input Filter Clock Selection Status Register +#define AT91C_PIOC_ABSR (AT91_CAST(AT91_REG *) 0x400E1070) // (PIOC) Peripheral AB Select Register +#define AT91C_PIOC_KIMR (AT91_CAST(AT91_REG *) 0x400E1138) // (PIOC) Keypad Controller Interrupt Mask Register +#define AT91C_PIOC_KRCR (AT91_CAST(AT91_REG *) 0x400E1124) // (PIOC) Keypad Controller Row Column Register +#define AT91C_PIOC_ODSR (AT91_CAST(AT91_REG *) 0x400E1038) // (PIOC) Output Data Status Register +#define AT91C_PIOC_OSR (AT91_CAST(AT91_REG *) 0x400E1018) // (PIOC) Output Status Register +#define AT91C_PIOC_IFER (AT91_CAST(AT91_REG *) 0x400E1020) // (PIOC) Input Filter Enable Register +#define AT91C_PIOC_KKPR (AT91_CAST(AT91_REG *) 0x400E1140) // (PIOC) Keypad Controller Key Press Register +#define AT91C_PIOC_MDSR (AT91_CAST(AT91_REG *) 0x400E1058) // (PIOC) Multi-driver Status Register +#define AT91C_PIOC_IFDR (AT91_CAST(AT91_REG *) 0x400E1024) // (PIOC) Input Filter Disable Register +#define AT91C_PIOC_MDER (AT91_CAST(AT91_REG *) 0x400E1050) // (PIOC) Multi-driver Enable Register +#define AT91C_PIOC_SCDR (AT91_CAST(AT91_REG *) 0x400E108C) // (PIOC) Slow Clock Divider Debouncing Register +#define AT91C_PIOC_SCIFSR (AT91_CAST(AT91_REG *) 0x400E1080) // (PIOC) System Clock Glitch Input Filter Select Register +#define AT91C_PIOC_IER (AT91_CAST(AT91_REG *) 0x400E1040) // (PIOC) Interrupt Enable Register +#define AT91C_PIOC_KDR (AT91_CAST(AT91_REG *) 0x400E1128) // (PIOC) Keypad Controller Debouncing Register +#define AT91C_PIOC_OWDR (AT91_CAST(AT91_REG *) 0x400E10A4) // (PIOC) Output Write Disable Register +#define AT91C_PIOC_IFSR (AT91_CAST(AT91_REG *) 0x400E1028) // (PIOC) Input Filter Status Register +#define AT91C_PIOC_ISR (AT91_CAST(AT91_REG *) 0x400E104C) // (PIOC) Interrupt Status Register +#define AT91C_PIOC_PPUDR (AT91_CAST(AT91_REG *) 0x400E1060) // (PIOC) Pull-up Disable Register +#define AT91C_PIOC_PDSR (AT91_CAST(AT91_REG *) 0x400E103C) // (PIOC) Pin Data Status Register +#define AT91C_PIOC_KKRR (AT91_CAST(AT91_REG *) 0x400E1144) // (PIOC) Keypad Controller Key Release Register +#define AT91C_PIOC_AIMDR (AT91_CAST(AT91_REG *) 0x400E10B4) // (PIOC) Additional Interrupt Modes Disables Register +#define AT91C_PIOC_LSR (AT91_CAST(AT91_REG *) 0x400E10C4) // (PIOC) Level Select Register +#define AT91C_PIOC_PPUER (AT91_CAST(AT91_REG *) 0x400E1064) // (PIOC) Pull-up Enable Register +#define AT91C_PIOC_AIMER (AT91_CAST(AT91_REG *) 0x400E10B0) // (PIOC) Additional Interrupt Modes Enable Register +#define AT91C_PIOC_OER (AT91_CAST(AT91_REG *) 0x400E1010) // (PIOC) Output Enable Register +#define AT91C_PIOC_CODR (AT91_CAST(AT91_REG *) 0x400E1034) // (PIOC) Clear Output Data Register +#define AT91C_PIOC_AIMMR (AT91_CAST(AT91_REG *) 0x400E10B8) // (PIOC) Additional Interrupt Modes Mask Register +#define AT91C_PIOC_OWER (AT91_CAST(AT91_REG *) 0x400E10A0) // (PIOC) Output Write Enable Register +#define AT91C_PIOC_VER (AT91_CAST(AT91_REG *) 0x400E10FC) // (PIOC) PIO VERSION REGISTER +#define AT91C_PIOC_IMR (AT91_CAST(AT91_REG *) 0x400E1048) // (PIOC) Interrupt Mask Register +#define AT91C_PIOC_PPUSR (AT91_CAST(AT91_REG *) 0x400E1068) // (PIOC) Pull-up Status Register +#define AT91C_PIOC_IDR (AT91_CAST(AT91_REG *) 0x400E1044) // (PIOC) Interrupt Disable Register +#define AT91C_PIOC_DIFSR (AT91_CAST(AT91_REG *) 0x400E1084) // (PIOC) Debouncing Input Filter Select Register +#define AT91C_PIOC_KIDR (AT91_CAST(AT91_REG *) 0x400E1134) // (PIOC) Keypad Controller Interrupt Disable Register +#define AT91C_PIOC_KSR (AT91_CAST(AT91_REG *) 0x400E113C) // (PIOC) Keypad Controller Status Register +#define AT91C_PIOC_REHLSR (AT91_CAST(AT91_REG *) 0x400E10D4) // (PIOC) Rising Edge/ High Level Select Register +#define AT91C_PIOC_ESR (AT91_CAST(AT91_REG *) 0x400E10C0) // (PIOC) Edge Select Register +#define AT91C_PIOC_KIER (AT91_CAST(AT91_REG *) 0x400E1130) // (PIOC) Keypad Controller Interrupt Enable Register +#define AT91C_PIOC_ELSR (AT91_CAST(AT91_REG *) 0x400E10C8) // (PIOC) Edge/Level Status Register +#define AT91C_PIOC_SODR (AT91_CAST(AT91_REG *) 0x400E1030) // (PIOC) Set Output Data Register +#define AT91C_PIOC_PSR (AT91_CAST(AT91_REG *) 0x400E1008) // (PIOC) PIO Status Register +#define AT91C_PIOC_KER (AT91_CAST(AT91_REG *) 0x400E1120) // (PIOC) Keypad Controller Enable Register +#define AT91C_PIOC_ODR (AT91_CAST(AT91_REG *) 0x400E1014) // (PIOC) Output Disable Registerr +#define AT91C_PIOC_OWSR (AT91_CAST(AT91_REG *) 0x400E10A8) // (PIOC) Output Write Status Register +#define AT91C_PIOC_PDR (AT91_CAST(AT91_REG *) 0x400E1004) // (PIOC) PIO Disable Register +#define AT91C_PIOC_LOCKSR (AT91_CAST(AT91_REG *) 0x400E10E0) // (PIOC) Lock Status Register +#define AT91C_PIOC_PER (AT91_CAST(AT91_REG *) 0x400E1000) // (PIOC) PIO Enable Register +// ========== Register definition for PMC peripheral ========== +#define AT91C_PMC_PLLAR (AT91_CAST(AT91_REG *) 0x400E0428) // (PMC) PLL Register +#define AT91C_PMC_UCKR (AT91_CAST(AT91_REG *) 0x400E041C) // (PMC) UTMI Clock Configuration Register +#define AT91C_PMC_FSMR (AT91_CAST(AT91_REG *) 0x400E0470) // (PMC) Fast Startup Mode Register +#define AT91C_PMC_MCKR (AT91_CAST(AT91_REG *) 0x400E0430) // (PMC) Master Clock Register +#define AT91C_PMC_SCER (AT91_CAST(AT91_REG *) 0x400E0400) // (PMC) System Clock Enable Register +#define AT91C_PMC_PCSR (AT91_CAST(AT91_REG *) 0x400E0418) // (PMC) Peripheral Clock Status Register +#define AT91C_PMC_MCFR (AT91_CAST(AT91_REG *) 0x400E0424) // (PMC) Main Clock Frequency Register +#define AT91C_PMC_FOCR (AT91_CAST(AT91_REG *) 0x400E0478) // (PMC) Fault Output Clear Register +#define AT91C_PMC_FSPR (AT91_CAST(AT91_REG *) 0x400E0474) // (PMC) Fast Startup Polarity Register +#define AT91C_PMC_SCSR (AT91_CAST(AT91_REG *) 0x400E0408) // (PMC) System Clock Status Register +#define AT91C_PMC_IDR (AT91_CAST(AT91_REG *) 0x400E0464) // (PMC) Interrupt Disable Register +#define AT91C_PMC_VER (AT91_CAST(AT91_REG *) 0x400E04FC) // (PMC) APMC VERSION REGISTER +#define AT91C_PMC_IMR (AT91_CAST(AT91_REG *) 0x400E046C) // (PMC) Interrupt Mask Register +#define AT91C_PMC_IPNAME2 (AT91_CAST(AT91_REG *) 0x400E04F4) // (PMC) PMC IPNAME2 REGISTER +#define AT91C_PMC_SCDR (AT91_CAST(AT91_REG *) 0x400E0404) // (PMC) System Clock Disable Register +#define AT91C_PMC_PCKR (AT91_CAST(AT91_REG *) 0x400E0440) // (PMC) Programmable Clock Register +#define AT91C_PMC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400E04EC) // (PMC) PMC ADDRSIZE REGISTER +#define AT91C_PMC_PCDR (AT91_CAST(AT91_REG *) 0x400E0414) // (PMC) Peripheral Clock Disable Register +#define AT91C_PMC_MOR (AT91_CAST(AT91_REG *) 0x400E0420) // (PMC) Main Oscillator Register +#define AT91C_PMC_SR (AT91_CAST(AT91_REG *) 0x400E0468) // (PMC) Status Register +#define AT91C_PMC_IER (AT91_CAST(AT91_REG *) 0x400E0460) // (PMC) Interrupt Enable Register +#define AT91C_PMC_IPNAME1 (AT91_CAST(AT91_REG *) 0x400E04F0) // (PMC) PMC IPNAME1 REGISTER +#define AT91C_PMC_PCER (AT91_CAST(AT91_REG *) 0x400E0410) // (PMC) Peripheral Clock Enable Register +#define AT91C_PMC_FEATURES (AT91_CAST(AT91_REG *) 0x400E04F8) // (PMC) PMC FEATURES REGISTER +// ========== Register definition for CKGR peripheral ========== +#define AT91C_CKGR_PLLAR (AT91_CAST(AT91_REG *) 0x400E0428) // (CKGR) PLL Register +#define AT91C_CKGR_UCKR (AT91_CAST(AT91_REG *) 0x400E041C) // (CKGR) UTMI Clock Configuration Register +#define AT91C_CKGR_MOR (AT91_CAST(AT91_REG *) 0x400E0420) // (CKGR) Main Oscillator Register +#define AT91C_CKGR_MCFR (AT91_CAST(AT91_REG *) 0x400E0424) // (CKGR) Main Clock Frequency Register +// ========== Register definition for RSTC peripheral ========== +#define AT91C_RSTC_VER (AT91_CAST(AT91_REG *) 0x400E12FC) // (RSTC) Version Register +#define AT91C_RSTC_RCR (AT91_CAST(AT91_REG *) 0x400E1200) // (RSTC) Reset Control Register +#define AT91C_RSTC_RMR (AT91_CAST(AT91_REG *) 0x400E1208) // (RSTC) Reset Mode Register +#define AT91C_RSTC_RSR (AT91_CAST(AT91_REG *) 0x400E1204) // (RSTC) Reset Status Register +// ========== Register definition for SUPC peripheral ========== +#define AT91C_SUPC_WUIR (AT91_CAST(AT91_REG *) 0x400E1220) // (SUPC) Wake Up Inputs Register +#define AT91C_SUPC_CR (AT91_CAST(AT91_REG *) 0x400E1210) // (SUPC) Control Register +#define AT91C_SUPC_MR (AT91_CAST(AT91_REG *) 0x400E1218) // (SUPC) Mode Register +#define AT91C_SUPC_FWUTR (AT91_CAST(AT91_REG *) 0x400E1228) // (SUPC) Flash Wake-up Timer Register +#define AT91C_SUPC_SR (AT91_CAST(AT91_REG *) 0x400E1224) // (SUPC) Status Register +#define AT91C_SUPC_WUMR (AT91_CAST(AT91_REG *) 0x400E121C) // (SUPC) Wake Up Mode Register +#define AT91C_SUPC_BOMR (AT91_CAST(AT91_REG *) 0x400E1214) // (SUPC) Brown Out Mode Register +// ========== Register definition for RTTC peripheral ========== +#define AT91C_RTTC_RTVR (AT91_CAST(AT91_REG *) 0x400E1238) // (RTTC) Real-time Value Register +#define AT91C_RTTC_RTAR (AT91_CAST(AT91_REG *) 0x400E1234) // (RTTC) Real-time Alarm Register +#define AT91C_RTTC_RTMR (AT91_CAST(AT91_REG *) 0x400E1230) // (RTTC) Real-time Mode Register +#define AT91C_RTTC_RTSR (AT91_CAST(AT91_REG *) 0x400E123C) // (RTTC) Real-time Status Register +// ========== Register definition for WDTC peripheral ========== +#define AT91C_WDTC_WDSR (AT91_CAST(AT91_REG *) 0x400E1258) // (WDTC) Watchdog Status Register +#define AT91C_WDTC_WDMR (AT91_CAST(AT91_REG *) 0x400E1254) // (WDTC) Watchdog Mode Register +#define AT91C_WDTC_WDCR (AT91_CAST(AT91_REG *) 0x400E1250) // (WDTC) Watchdog Control Register +// ========== Register definition for RTC peripheral ========== +#define AT91C_RTC_IMR (AT91_CAST(AT91_REG *) 0x400E1288) // (RTC) Interrupt Mask Register +#define AT91C_RTC_SCCR (AT91_CAST(AT91_REG *) 0x400E127C) // (RTC) Status Clear Command Register +#define AT91C_RTC_CALR (AT91_CAST(AT91_REG *) 0x400E126C) // (RTC) Calendar Register +#define AT91C_RTC_MR (AT91_CAST(AT91_REG *) 0x400E1264) // (RTC) Mode Register +#define AT91C_RTC_TIMR (AT91_CAST(AT91_REG *) 0x400E1268) // (RTC) Time Register +#define AT91C_RTC_CALALR (AT91_CAST(AT91_REG *) 0x400E1274) // (RTC) Calendar Alarm Register +#define AT91C_RTC_VER (AT91_CAST(AT91_REG *) 0x400E128C) // (RTC) Valid Entry Register +#define AT91C_RTC_CR (AT91_CAST(AT91_REG *) 0x400E1260) // (RTC) Control Register +#define AT91C_RTC_IDR (AT91_CAST(AT91_REG *) 0x400E1284) // (RTC) Interrupt Disable Register +#define AT91C_RTC_TIMALR (AT91_CAST(AT91_REG *) 0x400E1270) // (RTC) Time Alarm Register +#define AT91C_RTC_IER (AT91_CAST(AT91_REG *) 0x400E1280) // (RTC) Interrupt Enable Register +#define AT91C_RTC_SR (AT91_CAST(AT91_REG *) 0x400E1278) // (RTC) Status Register +// ========== Register definition for ADC0 peripheral ========== +#define AT91C_ADC0_CDR4 (AT91_CAST(AT91_REG *) 0x400A8040) // (ADC0) ADC Channel Data Register 4 +#define AT91C_ADC0_CDR2 (AT91_CAST(AT91_REG *) 0x400A8038) // (ADC0) ADC Channel Data Register 2 +#define AT91C_ADC0_CHER (AT91_CAST(AT91_REG *) 0x400A8010) // (ADC0) ADC Channel Enable Register +#define AT91C_ADC0_SR (AT91_CAST(AT91_REG *) 0x400A801C) // (ADC0) ADC Status Register +#define AT91C_ADC0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400A80F0) // (ADC0) ADC IPNAME1 REGISTER +#define AT91C_ADC0_IER (AT91_CAST(AT91_REG *) 0x400A8024) // (ADC0) ADC Interrupt Enable Register +#define AT91C_ADC0_CR (AT91_CAST(AT91_REG *) 0x400A8000) // (ADC0) ADC Control Register +#define AT91C_ADC0_CDR6 (AT91_CAST(AT91_REG *) 0x400A8048) // (ADC0) ADC Channel Data Register 6 +#define AT91C_ADC0_CHDR (AT91_CAST(AT91_REG *) 0x400A8014) // (ADC0) ADC Channel Disable Register +#define AT91C_ADC0_CDR3 (AT91_CAST(AT91_REG *) 0x400A803C) // (ADC0) ADC Channel Data Register 3 +#define AT91C_ADC0_ACR (AT91_CAST(AT91_REG *) 0x400A8064) // (ADC0) Analog Control Register +#define AT91C_ADC0_IDR (AT91_CAST(AT91_REG *) 0x400A8028) // (ADC0) ADC Interrupt Disable Register +#define AT91C_ADC0_VER (AT91_CAST(AT91_REG *) 0x400A80FC) // (ADC0) ADC VERSION REGISTER +#define AT91C_ADC0_CDR7 (AT91_CAST(AT91_REG *) 0x400A804C) // (ADC0) ADC Channel Data Register 7 +#define AT91C_ADC0_CHSR (AT91_CAST(AT91_REG *) 0x400A8018) // (ADC0) ADC Channel Status Register +#define AT91C_ADC0_CDR5 (AT91_CAST(AT91_REG *) 0x400A8044) // (ADC0) ADC Channel Data Register 5 +#define AT91C_ADC0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400A80F4) // (ADC0) ADC IPNAME2 REGISTER +#define AT91C_ADC0_MR (AT91_CAST(AT91_REG *) 0x400A8004) // (ADC0) ADC Mode Register +#define AT91C_ADC0_FEATURES (AT91_CAST(AT91_REG *) 0x400A80F8) // (ADC0) ADC FEATURES REGISTER +#define AT91C_ADC0_EMR (AT91_CAST(AT91_REG *) 0x400A8068) // (ADC0) Extended Mode Register +#define AT91C_ADC0_CDR0 (AT91_CAST(AT91_REG *) 0x400A8030) // (ADC0) ADC Channel Data Register 0 +#define AT91C_ADC0_LCDR (AT91_CAST(AT91_REG *) 0x400A8020) // (ADC0) ADC Last Converted Data Register +#define AT91C_ADC0_IMR (AT91_CAST(AT91_REG *) 0x400A802C) // (ADC0) ADC Interrupt Mask Register +#define AT91C_ADC0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400A80EC) // (ADC0) ADC ADDRSIZE REGISTER +#define AT91C_ADC0_CDR1 (AT91_CAST(AT91_REG *) 0x400A8034) // (ADC0) ADC Channel Data Register 1 +// ========== Register definition for ADC1 peripheral ========== +#define AT91C_ADC1_IPNAME2 (AT91_CAST(AT91_REG *) 0x400AC0F4) // (ADC1) ADC IPNAME2 REGISTER +#define AT91C_ADC1_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400AC0EC) // (ADC1) ADC ADDRSIZE REGISTER +#define AT91C_ADC1_IDR (AT91_CAST(AT91_REG *) 0x400AC028) // (ADC1) ADC Interrupt Disable Register +#define AT91C_ADC1_CHSR (AT91_CAST(AT91_REG *) 0x400AC018) // (ADC1) ADC Channel Status Register +#define AT91C_ADC1_FEATURES (AT91_CAST(AT91_REG *) 0x400AC0F8) // (ADC1) ADC FEATURES REGISTER +#define AT91C_ADC1_CDR0 (AT91_CAST(AT91_REG *) 0x400AC030) // (ADC1) ADC Channel Data Register 0 +#define AT91C_ADC1_LCDR (AT91_CAST(AT91_REG *) 0x400AC020) // (ADC1) ADC Last Converted Data Register +#define AT91C_ADC1_EMR (AT91_CAST(AT91_REG *) 0x400AC068) // (ADC1) Extended Mode Register +#define AT91C_ADC1_CDR3 (AT91_CAST(AT91_REG *) 0x400AC03C) // (ADC1) ADC Channel Data Register 3 +#define AT91C_ADC1_CDR7 (AT91_CAST(AT91_REG *) 0x400AC04C) // (ADC1) ADC Channel Data Register 7 +#define AT91C_ADC1_SR (AT91_CAST(AT91_REG *) 0x400AC01C) // (ADC1) ADC Status Register +#define AT91C_ADC1_ACR (AT91_CAST(AT91_REG *) 0x400AC064) // (ADC1) Analog Control Register +#define AT91C_ADC1_CDR5 (AT91_CAST(AT91_REG *) 0x400AC044) // (ADC1) ADC Channel Data Register 5 +#define AT91C_ADC1_IPNAME1 (AT91_CAST(AT91_REG *) 0x400AC0F0) // (ADC1) ADC IPNAME1 REGISTER +#define AT91C_ADC1_CDR6 (AT91_CAST(AT91_REG *) 0x400AC048) // (ADC1) ADC Channel Data Register 6 +#define AT91C_ADC1_MR (AT91_CAST(AT91_REG *) 0x400AC004) // (ADC1) ADC Mode Register +#define AT91C_ADC1_CDR1 (AT91_CAST(AT91_REG *) 0x400AC034) // (ADC1) ADC Channel Data Register 1 +#define AT91C_ADC1_CDR2 (AT91_CAST(AT91_REG *) 0x400AC038) // (ADC1) ADC Channel Data Register 2 +#define AT91C_ADC1_CDR4 (AT91_CAST(AT91_REG *) 0x400AC040) // (ADC1) ADC Channel Data Register 4 +#define AT91C_ADC1_CHER (AT91_CAST(AT91_REG *) 0x400AC010) // (ADC1) ADC Channel Enable Register +#define AT91C_ADC1_VER (AT91_CAST(AT91_REG *) 0x400AC0FC) // (ADC1) ADC VERSION REGISTER +#define AT91C_ADC1_CHDR (AT91_CAST(AT91_REG *) 0x400AC014) // (ADC1) ADC Channel Disable Register +#define AT91C_ADC1_CR (AT91_CAST(AT91_REG *) 0x400AC000) // (ADC1) ADC Control Register +#define AT91C_ADC1_IMR (AT91_CAST(AT91_REG *) 0x400AC02C) // (ADC1) ADC Interrupt Mask Register +#define AT91C_ADC1_IER (AT91_CAST(AT91_REG *) 0x400AC024) // (ADC1) ADC Interrupt Enable Register +// ========== Register definition for TC0 peripheral ========== +#define AT91C_TC0_IER (AT91_CAST(AT91_REG *) 0x40080024) // (TC0) Interrupt Enable Register +#define AT91C_TC0_CV (AT91_CAST(AT91_REG *) 0x40080010) // (TC0) Counter Value +#define AT91C_TC0_RA (AT91_CAST(AT91_REG *) 0x40080014) // (TC0) Register A +#define AT91C_TC0_RB (AT91_CAST(AT91_REG *) 0x40080018) // (TC0) Register B +#define AT91C_TC0_IDR (AT91_CAST(AT91_REG *) 0x40080028) // (TC0) Interrupt Disable Register +#define AT91C_TC0_SR (AT91_CAST(AT91_REG *) 0x40080020) // (TC0) Status Register +#define AT91C_TC0_IMR (AT91_CAST(AT91_REG *) 0x4008002C) // (TC0) Interrupt Mask Register +#define AT91C_TC0_CMR (AT91_CAST(AT91_REG *) 0x40080004) // (TC0) Channel Mode Register (Capture Mode / Waveform Mode) +#define AT91C_TC0_RC (AT91_CAST(AT91_REG *) 0x4008001C) // (TC0) Register C +#define AT91C_TC0_CCR (AT91_CAST(AT91_REG *) 0x40080000) // (TC0) Channel Control Register +// ========== Register definition for TC1 peripheral ========== +#define AT91C_TC1_SR (AT91_CAST(AT91_REG *) 0x40080060) // (TC1) Status Register +#define AT91C_TC1_RA (AT91_CAST(AT91_REG *) 0x40080054) // (TC1) Register A +#define AT91C_TC1_IER (AT91_CAST(AT91_REG *) 0x40080064) // (TC1) Interrupt Enable Register +#define AT91C_TC1_RB (AT91_CAST(AT91_REG *) 0x40080058) // (TC1) Register B +#define AT91C_TC1_IDR (AT91_CAST(AT91_REG *) 0x40080068) // (TC1) Interrupt Disable Register +#define AT91C_TC1_CCR (AT91_CAST(AT91_REG *) 0x40080040) // (TC1) Channel Control Register +#define AT91C_TC1_IMR (AT91_CAST(AT91_REG *) 0x4008006C) // (TC1) Interrupt Mask Register +#define AT91C_TC1_RC (AT91_CAST(AT91_REG *) 0x4008005C) // (TC1) Register C +#define AT91C_TC1_CMR (AT91_CAST(AT91_REG *) 0x40080044) // (TC1) Channel Mode Register (Capture Mode / Waveform Mode) +#define AT91C_TC1_CV (AT91_CAST(AT91_REG *) 0x40080050) // (TC1) Counter Value +// ========== Register definition for TC2 peripheral ========== +#define AT91C_TC2_RA (AT91_CAST(AT91_REG *) 0x40080094) // (TC2) Register A +#define AT91C_TC2_RB (AT91_CAST(AT91_REG *) 0x40080098) // (TC2) Register B +#define AT91C_TC2_CMR (AT91_CAST(AT91_REG *) 0x40080084) // (TC2) Channel Mode Register (Capture Mode / Waveform Mode) +#define AT91C_TC2_SR (AT91_CAST(AT91_REG *) 0x400800A0) // (TC2) Status Register +#define AT91C_TC2_CCR (AT91_CAST(AT91_REG *) 0x40080080) // (TC2) Channel Control Register +#define AT91C_TC2_IMR (AT91_CAST(AT91_REG *) 0x400800AC) // (TC2) Interrupt Mask Register +#define AT91C_TC2_CV (AT91_CAST(AT91_REG *) 0x40080090) // (TC2) Counter Value +#define AT91C_TC2_RC (AT91_CAST(AT91_REG *) 0x4008009C) // (TC2) Register C +#define AT91C_TC2_IER (AT91_CAST(AT91_REG *) 0x400800A4) // (TC2) Interrupt Enable Register +#define AT91C_TC2_IDR (AT91_CAST(AT91_REG *) 0x400800A8) // (TC2) Interrupt Disable Register +// ========== Register definition for TCB0 peripheral ========== +#define AT91C_TCB0_BCR (AT91_CAST(AT91_REG *) 0x400800C0) // (TCB0) TC Block Control Register +#define AT91C_TCB0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400800F4) // (TCB0) TC IPNAME2 REGISTER +#define AT91C_TCB0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400800F0) // (TCB0) TC IPNAME1 REGISTER +#define AT91C_TCB0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400800EC) // (TCB0) TC ADDRSIZE REGISTER +#define AT91C_TCB0_FEATURES (AT91_CAST(AT91_REG *) 0x400800F8) // (TCB0) TC FEATURES REGISTER +#define AT91C_TCB0_BMR (AT91_CAST(AT91_REG *) 0x400800C4) // (TCB0) TC Block Mode Register +#define AT91C_TCB0_VER (AT91_CAST(AT91_REG *) 0x400800FC) // (TCB0) Version Register +// ========== Register definition for TCB1 peripheral ========== +#define AT91C_TCB1_BCR (AT91_CAST(AT91_REG *) 0x40080100) // (TCB1) TC Block Control Register +#define AT91C_TCB1_VER (AT91_CAST(AT91_REG *) 0x4008013C) // (TCB1) Version Register +#define AT91C_TCB1_FEATURES (AT91_CAST(AT91_REG *) 0x40080138) // (TCB1) TC FEATURES REGISTER +#define AT91C_TCB1_IPNAME2 (AT91_CAST(AT91_REG *) 0x40080134) // (TCB1) TC IPNAME2 REGISTER +#define AT91C_TCB1_BMR (AT91_CAST(AT91_REG *) 0x40080104) // (TCB1) TC Block Mode Register +#define AT91C_TCB1_ADDRSIZE (AT91_CAST(AT91_REG *) 0x4008012C) // (TCB1) TC ADDRSIZE REGISTER +#define AT91C_TCB1_IPNAME1 (AT91_CAST(AT91_REG *) 0x40080130) // (TCB1) TC IPNAME1 REGISTER +// ========== Register definition for TCB2 peripheral ========== +#define AT91C_TCB2_FEATURES (AT91_CAST(AT91_REG *) 0x40080178) // (TCB2) TC FEATURES REGISTER +#define AT91C_TCB2_VER (AT91_CAST(AT91_REG *) 0x4008017C) // (TCB2) Version Register +#define AT91C_TCB2_ADDRSIZE (AT91_CAST(AT91_REG *) 0x4008016C) // (TCB2) TC ADDRSIZE REGISTER +#define AT91C_TCB2_IPNAME1 (AT91_CAST(AT91_REG *) 0x40080170) // (TCB2) TC IPNAME1 REGISTER +#define AT91C_TCB2_IPNAME2 (AT91_CAST(AT91_REG *) 0x40080174) // (TCB2) TC IPNAME2 REGISTER +#define AT91C_TCB2_BMR (AT91_CAST(AT91_REG *) 0x40080144) // (TCB2) TC Block Mode Register +#define AT91C_TCB2_BCR (AT91_CAST(AT91_REG *) 0x40080140) // (TCB2) TC Block Control Register +// ========== Register definition for EFC0 peripheral ========== +#define AT91C_EFC0_FCR (AT91_CAST(AT91_REG *) 0x400E0804) // (EFC0) EFC Flash Command Register +#define AT91C_EFC0_FRR (AT91_CAST(AT91_REG *) 0x400E080C) // (EFC0) EFC Flash Result Register +#define AT91C_EFC0_FMR (AT91_CAST(AT91_REG *) 0x400E0800) // (EFC0) EFC Flash Mode Register +#define AT91C_EFC0_FSR (AT91_CAST(AT91_REG *) 0x400E0808) // (EFC0) EFC Flash Status Register +#define AT91C_EFC0_FVR (AT91_CAST(AT91_REG *) 0x400E0814) // (EFC0) EFC Flash Version Register +// ========== Register definition for EFC1 peripheral ========== +#define AT91C_EFC1_FMR (AT91_CAST(AT91_REG *) 0x400E0A00) // (EFC1) EFC Flash Mode Register +#define AT91C_EFC1_FVR (AT91_CAST(AT91_REG *) 0x400E0A14) // (EFC1) EFC Flash Version Register +#define AT91C_EFC1_FSR (AT91_CAST(AT91_REG *) 0x400E0A08) // (EFC1) EFC Flash Status Register +#define AT91C_EFC1_FCR (AT91_CAST(AT91_REG *) 0x400E0A04) // (EFC1) EFC Flash Command Register +#define AT91C_EFC1_FRR (AT91_CAST(AT91_REG *) 0x400E0A0C) // (EFC1) EFC Flash Result Register +// ========== Register definition for MCI0 peripheral ========== +#define AT91C_MCI0_DMA (AT91_CAST(AT91_REG *) 0x40000050) // (MCI0) MCI DMA Configuration Register +#define AT91C_MCI0_SDCR (AT91_CAST(AT91_REG *) 0x4000000C) // (MCI0) MCI SD/SDIO Card Register +#define AT91C_MCI0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400000F0) // (MCI0) MCI IPNAME1 REGISTER +#define AT91C_MCI0_CSTOR (AT91_CAST(AT91_REG *) 0x4000001C) // (MCI0) MCI Completion Signal Timeout Register +#define AT91C_MCI0_RDR (AT91_CAST(AT91_REG *) 0x40000030) // (MCI0) MCI Receive Data Register +#define AT91C_MCI0_CMDR (AT91_CAST(AT91_REG *) 0x40000014) // (MCI0) MCI Command Register +#define AT91C_MCI0_IDR (AT91_CAST(AT91_REG *) 0x40000048) // (MCI0) MCI Interrupt Disable Register +#define AT91C_MCI0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400000EC) // (MCI0) MCI ADDRSIZE REGISTER +#define AT91C_MCI0_WPCR (AT91_CAST(AT91_REG *) 0x400000E4) // (MCI0) MCI Write Protection Control Register +#define AT91C_MCI0_RSPR (AT91_CAST(AT91_REG *) 0x40000020) // (MCI0) MCI Response Register +#define AT91C_MCI0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400000F4) // (MCI0) MCI IPNAME2 REGISTER +#define AT91C_MCI0_CR (AT91_CAST(AT91_REG *) 0x40000000) // (MCI0) MCI Control Register +#define AT91C_MCI0_IMR (AT91_CAST(AT91_REG *) 0x4000004C) // (MCI0) MCI Interrupt Mask Register +#define AT91C_MCI0_WPSR (AT91_CAST(AT91_REG *) 0x400000E8) // (MCI0) MCI Write Protection Status Register +#define AT91C_MCI0_DTOR (AT91_CAST(AT91_REG *) 0x40000008) // (MCI0) MCI Data Timeout Register +#define AT91C_MCI0_MR (AT91_CAST(AT91_REG *) 0x40000004) // (MCI0) MCI Mode Register +#define AT91C_MCI0_SR (AT91_CAST(AT91_REG *) 0x40000040) // (MCI0) MCI Status Register +#define AT91C_MCI0_IER (AT91_CAST(AT91_REG *) 0x40000044) // (MCI0) MCI Interrupt Enable Register +#define AT91C_MCI0_VER (AT91_CAST(AT91_REG *) 0x400000FC) // (MCI0) MCI VERSION REGISTER +#define AT91C_MCI0_FEATURES (AT91_CAST(AT91_REG *) 0x400000F8) // (MCI0) MCI FEATURES REGISTER +#define AT91C_MCI0_BLKR (AT91_CAST(AT91_REG *) 0x40000018) // (MCI0) MCI Block Register +#define AT91C_MCI0_ARGR (AT91_CAST(AT91_REG *) 0x40000010) // (MCI0) MCI Argument Register +#define AT91C_MCI0_FIFO (AT91_CAST(AT91_REG *) 0x40000200) // (MCI0) MCI FIFO Aperture Register +#define AT91C_MCI0_TDR (AT91_CAST(AT91_REG *) 0x40000034) // (MCI0) MCI Transmit Data Register +#define AT91C_MCI0_CFG (AT91_CAST(AT91_REG *) 0x40000054) // (MCI0) MCI Configuration Register +// ========== Register definition for PDC_TWI0 peripheral ========== +#define AT91C_TWI0_TNCR (AT91_CAST(AT91_REG *) 0x4008411C) // (PDC_TWI0) Transmit Next Counter Register +#define AT91C_TWI0_PTCR (AT91_CAST(AT91_REG *) 0x40084120) // (PDC_TWI0) PDC Transfer Control Register +#define AT91C_TWI0_PTSR (AT91_CAST(AT91_REG *) 0x40084124) // (PDC_TWI0) PDC Transfer Status Register +#define AT91C_TWI0_RCR (AT91_CAST(AT91_REG *) 0x40084104) // (PDC_TWI0) Receive Counter Register +#define AT91C_TWI0_TNPR (AT91_CAST(AT91_REG *) 0x40084118) // (PDC_TWI0) Transmit Next Pointer Register +#define AT91C_TWI0_RNPR (AT91_CAST(AT91_REG *) 0x40084110) // (PDC_TWI0) Receive Next Pointer Register +#define AT91C_TWI0_RPR (AT91_CAST(AT91_REG *) 0x40084100) // (PDC_TWI0) Receive Pointer Register +#define AT91C_TWI0_RNCR (AT91_CAST(AT91_REG *) 0x40084114) // (PDC_TWI0) Receive Next Counter Register +#define AT91C_TWI0_TPR (AT91_CAST(AT91_REG *) 0x40084108) // (PDC_TWI0) Transmit Pointer Register +#define AT91C_TWI0_TCR (AT91_CAST(AT91_REG *) 0x4008410C) // (PDC_TWI0) Transmit Counter Register +// ========== Register definition for PDC_TWI1 peripheral ========== +#define AT91C_TWI1_TNCR (AT91_CAST(AT91_REG *) 0x4008811C) // (PDC_TWI1) Transmit Next Counter Register +#define AT91C_TWI1_PTCR (AT91_CAST(AT91_REG *) 0x40088120) // (PDC_TWI1) PDC Transfer Control Register +#define AT91C_TWI1_RNCR (AT91_CAST(AT91_REG *) 0x40088114) // (PDC_TWI1) Receive Next Counter Register +#define AT91C_TWI1_RCR (AT91_CAST(AT91_REG *) 0x40088104) // (PDC_TWI1) Receive Counter Register +#define AT91C_TWI1_RPR (AT91_CAST(AT91_REG *) 0x40088100) // (PDC_TWI1) Receive Pointer Register +#define AT91C_TWI1_TNPR (AT91_CAST(AT91_REG *) 0x40088118) // (PDC_TWI1) Transmit Next Pointer Register +#define AT91C_TWI1_RNPR (AT91_CAST(AT91_REG *) 0x40088110) // (PDC_TWI1) Receive Next Pointer Register +#define AT91C_TWI1_TCR (AT91_CAST(AT91_REG *) 0x4008810C) // (PDC_TWI1) Transmit Counter Register +#define AT91C_TWI1_TPR (AT91_CAST(AT91_REG *) 0x40088108) // (PDC_TWI1) Transmit Pointer Register +#define AT91C_TWI1_PTSR (AT91_CAST(AT91_REG *) 0x40088124) // (PDC_TWI1) PDC Transfer Status Register +// ========== Register definition for TWI0 peripheral ========== +#define AT91C_TWI0_FEATURES (AT91_CAST(AT91_REG *) 0x400840F8) // (TWI0) TWI FEATURES REGISTER +#define AT91C_TWI0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400840F0) // (TWI0) TWI IPNAME1 REGISTER +#define AT91C_TWI0_SMR (AT91_CAST(AT91_REG *) 0x40084008) // (TWI0) Slave Mode Register +#define AT91C_TWI0_MMR (AT91_CAST(AT91_REG *) 0x40084004) // (TWI0) Master Mode Register +#define AT91C_TWI0_SR (AT91_CAST(AT91_REG *) 0x40084020) // (TWI0) Status Register +#define AT91C_TWI0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400840F4) // (TWI0) TWI IPNAME2 REGISTER +#define AT91C_TWI0_CR (AT91_CAST(AT91_REG *) 0x40084000) // (TWI0) Control Register +#define AT91C_TWI0_IER (AT91_CAST(AT91_REG *) 0x40084024) // (TWI0) Interrupt Enable Register +#define AT91C_TWI0_RHR (AT91_CAST(AT91_REG *) 0x40084030) // (TWI0) Receive Holding Register +#define AT91C_TWI0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400840EC) // (TWI0) TWI ADDRSIZE REGISTER +#define AT91C_TWI0_THR (AT91_CAST(AT91_REG *) 0x40084034) // (TWI0) Transmit Holding Register +#define AT91C_TWI0_VER (AT91_CAST(AT91_REG *) 0x400840FC) // (TWI0) Version Register +#define AT91C_TWI0_IADR (AT91_CAST(AT91_REG *) 0x4008400C) // (TWI0) Internal Address Register +#define AT91C_TWI0_IMR (AT91_CAST(AT91_REG *) 0x4008402C) // (TWI0) Interrupt Mask Register +#define AT91C_TWI0_CWGR (AT91_CAST(AT91_REG *) 0x40084010) // (TWI0) Clock Waveform Generator Register +#define AT91C_TWI0_IDR (AT91_CAST(AT91_REG *) 0x40084028) // (TWI0) Interrupt Disable Register +// ========== Register definition for TWI1 peripheral ========== +#define AT91C_TWI1_VER (AT91_CAST(AT91_REG *) 0x400880FC) // (TWI1) Version Register +#define AT91C_TWI1_IDR (AT91_CAST(AT91_REG *) 0x40088028) // (TWI1) Interrupt Disable Register +#define AT91C_TWI1_IPNAME2 (AT91_CAST(AT91_REG *) 0x400880F4) // (TWI1) TWI IPNAME2 REGISTER +#define AT91C_TWI1_CWGR (AT91_CAST(AT91_REG *) 0x40088010) // (TWI1) Clock Waveform Generator Register +#define AT91C_TWI1_CR (AT91_CAST(AT91_REG *) 0x40088000) // (TWI1) Control Register +#define AT91C_TWI1_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400880EC) // (TWI1) TWI ADDRSIZE REGISTER +#define AT91C_TWI1_IADR (AT91_CAST(AT91_REG *) 0x4008800C) // (TWI1) Internal Address Register +#define AT91C_TWI1_IER (AT91_CAST(AT91_REG *) 0x40088024) // (TWI1) Interrupt Enable Register +#define AT91C_TWI1_SMR (AT91_CAST(AT91_REG *) 0x40088008) // (TWI1) Slave Mode Register +#define AT91C_TWI1_RHR (AT91_CAST(AT91_REG *) 0x40088030) // (TWI1) Receive Holding Register +#define AT91C_TWI1_FEATURES (AT91_CAST(AT91_REG *) 0x400880F8) // (TWI1) TWI FEATURES REGISTER +#define AT91C_TWI1_IMR (AT91_CAST(AT91_REG *) 0x4008802C) // (TWI1) Interrupt Mask Register +#define AT91C_TWI1_SR (AT91_CAST(AT91_REG *) 0x40088020) // (TWI1) Status Register +#define AT91C_TWI1_THR (AT91_CAST(AT91_REG *) 0x40088034) // (TWI1) Transmit Holding Register +#define AT91C_TWI1_MMR (AT91_CAST(AT91_REG *) 0x40088004) // (TWI1) Master Mode Register +#define AT91C_TWI1_IPNAME1 (AT91_CAST(AT91_REG *) 0x400880F0) // (TWI1) TWI IPNAME1 REGISTER +// ========== Register definition for PDC_US0 peripheral ========== +#define AT91C_US0_RNCR (AT91_CAST(AT91_REG *) 0x40090114) // (PDC_US0) Receive Next Counter Register +#define AT91C_US0_TNPR (AT91_CAST(AT91_REG *) 0x40090118) // (PDC_US0) Transmit Next Pointer Register +#define AT91C_US0_TPR (AT91_CAST(AT91_REG *) 0x40090108) // (PDC_US0) Transmit Pointer Register +#define AT91C_US0_RCR (AT91_CAST(AT91_REG *) 0x40090104) // (PDC_US0) Receive Counter Register +#define AT91C_US0_RNPR (AT91_CAST(AT91_REG *) 0x40090110) // (PDC_US0) Receive Next Pointer Register +#define AT91C_US0_TNCR (AT91_CAST(AT91_REG *) 0x4009011C) // (PDC_US0) Transmit Next Counter Register +#define AT91C_US0_PTSR (AT91_CAST(AT91_REG *) 0x40090124) // (PDC_US0) PDC Transfer Status Register +#define AT91C_US0_RPR (AT91_CAST(AT91_REG *) 0x40090100) // (PDC_US0) Receive Pointer Register +#define AT91C_US0_PTCR (AT91_CAST(AT91_REG *) 0x40090120) // (PDC_US0) PDC Transfer Control Register +#define AT91C_US0_TCR (AT91_CAST(AT91_REG *) 0x4009010C) // (PDC_US0) Transmit Counter Register +// ========== Register definition for US0 peripheral ========== +#define AT91C_US0_NER (AT91_CAST(AT91_REG *) 0x40090044) // (US0) Nb Errors Register +#define AT91C_US0_RHR (AT91_CAST(AT91_REG *) 0x40090018) // (US0) Receiver Holding Register +#define AT91C_US0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400900F0) // (US0) US IPNAME1 REGISTER +#define AT91C_US0_MR (AT91_CAST(AT91_REG *) 0x40090004) // (US0) Mode Register +#define AT91C_US0_RTOR (AT91_CAST(AT91_REG *) 0x40090024) // (US0) Receiver Time-out Register +#define AT91C_US0_IF (AT91_CAST(AT91_REG *) 0x4009004C) // (US0) IRDA_FILTER Register +#define AT91C_US0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400900EC) // (US0) US ADDRSIZE REGISTER +#define AT91C_US0_IDR (AT91_CAST(AT91_REG *) 0x4009000C) // (US0) Interrupt Disable Register +#define AT91C_US0_IMR (AT91_CAST(AT91_REG *) 0x40090010) // (US0) Interrupt Mask Register +#define AT91C_US0_IER (AT91_CAST(AT91_REG *) 0x40090008) // (US0) Interrupt Enable Register +#define AT91C_US0_TTGR (AT91_CAST(AT91_REG *) 0x40090028) // (US0) Transmitter Time-guard Register +#define AT91C_US0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400900F4) // (US0) US IPNAME2 REGISTER +#define AT91C_US0_FIDI (AT91_CAST(AT91_REG *) 0x40090040) // (US0) FI_DI_Ratio Register +#define AT91C_US0_CR (AT91_CAST(AT91_REG *) 0x40090000) // (US0) Control Register +#define AT91C_US0_BRGR (AT91_CAST(AT91_REG *) 0x40090020) // (US0) Baud Rate Generator Register +#define AT91C_US0_MAN (AT91_CAST(AT91_REG *) 0x40090050) // (US0) Manchester Encoder Decoder Register +#define AT91C_US0_VER (AT91_CAST(AT91_REG *) 0x400900FC) // (US0) VERSION Register +#define AT91C_US0_FEATURES (AT91_CAST(AT91_REG *) 0x400900F8) // (US0) US FEATURES REGISTER +#define AT91C_US0_CSR (AT91_CAST(AT91_REG *) 0x40090014) // (US0) Channel Status Register +#define AT91C_US0_THR (AT91_CAST(AT91_REG *) 0x4009001C) // (US0) Transmitter Holding Register +// ========== Register definition for PDC_US1 peripheral ========== +#define AT91C_US1_TNPR (AT91_CAST(AT91_REG *) 0x40094118) // (PDC_US1) Transmit Next Pointer Register +#define AT91C_US1_TPR (AT91_CAST(AT91_REG *) 0x40094108) // (PDC_US1) Transmit Pointer Register +#define AT91C_US1_RNCR (AT91_CAST(AT91_REG *) 0x40094114) // (PDC_US1) Receive Next Counter Register +#define AT91C_US1_TNCR (AT91_CAST(AT91_REG *) 0x4009411C) // (PDC_US1) Transmit Next Counter Register +#define AT91C_US1_RNPR (AT91_CAST(AT91_REG *) 0x40094110) // (PDC_US1) Receive Next Pointer Register +#define AT91C_US1_TCR (AT91_CAST(AT91_REG *) 0x4009410C) // (PDC_US1) Transmit Counter Register +#define AT91C_US1_PTSR (AT91_CAST(AT91_REG *) 0x40094124) // (PDC_US1) PDC Transfer Status Register +#define AT91C_US1_RCR (AT91_CAST(AT91_REG *) 0x40094104) // (PDC_US1) Receive Counter Register +#define AT91C_US1_RPR (AT91_CAST(AT91_REG *) 0x40094100) // (PDC_US1) Receive Pointer Register +#define AT91C_US1_PTCR (AT91_CAST(AT91_REG *) 0x40094120) // (PDC_US1) PDC Transfer Control Register +// ========== Register definition for US1 peripheral ========== +#define AT91C_US1_IMR (AT91_CAST(AT91_REG *) 0x40094010) // (US1) Interrupt Mask Register +#define AT91C_US1_RTOR (AT91_CAST(AT91_REG *) 0x40094024) // (US1) Receiver Time-out Register +#define AT91C_US1_RHR (AT91_CAST(AT91_REG *) 0x40094018) // (US1) Receiver Holding Register +#define AT91C_US1_IPNAME1 (AT91_CAST(AT91_REG *) 0x400940F0) // (US1) US IPNAME1 REGISTER +#define AT91C_US1_VER (AT91_CAST(AT91_REG *) 0x400940FC) // (US1) VERSION Register +#define AT91C_US1_MR (AT91_CAST(AT91_REG *) 0x40094004) // (US1) Mode Register +#define AT91C_US1_FEATURES (AT91_CAST(AT91_REG *) 0x400940F8) // (US1) US FEATURES REGISTER +#define AT91C_US1_NER (AT91_CAST(AT91_REG *) 0x40094044) // (US1) Nb Errors Register +#define AT91C_US1_IPNAME2 (AT91_CAST(AT91_REG *) 0x400940F4) // (US1) US IPNAME2 REGISTER +#define AT91C_US1_CR (AT91_CAST(AT91_REG *) 0x40094000) // (US1) Control Register +#define AT91C_US1_BRGR (AT91_CAST(AT91_REG *) 0x40094020) // (US1) Baud Rate Generator Register +#define AT91C_US1_IF (AT91_CAST(AT91_REG *) 0x4009404C) // (US1) IRDA_FILTER Register +#define AT91C_US1_IER (AT91_CAST(AT91_REG *) 0x40094008) // (US1) Interrupt Enable Register +#define AT91C_US1_TTGR (AT91_CAST(AT91_REG *) 0x40094028) // (US1) Transmitter Time-guard Register +#define AT91C_US1_FIDI (AT91_CAST(AT91_REG *) 0x40094040) // (US1) FI_DI_Ratio Register +#define AT91C_US1_MAN (AT91_CAST(AT91_REG *) 0x40094050) // (US1) Manchester Encoder Decoder Register +#define AT91C_US1_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400940EC) // (US1) US ADDRSIZE REGISTER +#define AT91C_US1_CSR (AT91_CAST(AT91_REG *) 0x40094014) // (US1) Channel Status Register +#define AT91C_US1_THR (AT91_CAST(AT91_REG *) 0x4009401C) // (US1) Transmitter Holding Register +#define AT91C_US1_IDR (AT91_CAST(AT91_REG *) 0x4009400C) // (US1) Interrupt Disable Register +// ========== Register definition for PDC_US2 peripheral ========== +#define AT91C_US2_RPR (AT91_CAST(AT91_REG *) 0x40098100) // (PDC_US2) Receive Pointer Register +#define AT91C_US2_TPR (AT91_CAST(AT91_REG *) 0x40098108) // (PDC_US2) Transmit Pointer Register +#define AT91C_US2_TCR (AT91_CAST(AT91_REG *) 0x4009810C) // (PDC_US2) Transmit Counter Register +#define AT91C_US2_PTSR (AT91_CAST(AT91_REG *) 0x40098124) // (PDC_US2) PDC Transfer Status Register +#define AT91C_US2_PTCR (AT91_CAST(AT91_REG *) 0x40098120) // (PDC_US2) PDC Transfer Control Register +#define AT91C_US2_RNPR (AT91_CAST(AT91_REG *) 0x40098110) // (PDC_US2) Receive Next Pointer Register +#define AT91C_US2_TNCR (AT91_CAST(AT91_REG *) 0x4009811C) // (PDC_US2) Transmit Next Counter Register +#define AT91C_US2_RNCR (AT91_CAST(AT91_REG *) 0x40098114) // (PDC_US2) Receive Next Counter Register +#define AT91C_US2_TNPR (AT91_CAST(AT91_REG *) 0x40098118) // (PDC_US2) Transmit Next Pointer Register +#define AT91C_US2_RCR (AT91_CAST(AT91_REG *) 0x40098104) // (PDC_US2) Receive Counter Register +// ========== Register definition for US2 peripheral ========== +#define AT91C_US2_MAN (AT91_CAST(AT91_REG *) 0x40098050) // (US2) Manchester Encoder Decoder Register +#define AT91C_US2_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400980EC) // (US2) US ADDRSIZE REGISTER +#define AT91C_US2_MR (AT91_CAST(AT91_REG *) 0x40098004) // (US2) Mode Register +#define AT91C_US2_IPNAME1 (AT91_CAST(AT91_REG *) 0x400980F0) // (US2) US IPNAME1 REGISTER +#define AT91C_US2_IF (AT91_CAST(AT91_REG *) 0x4009804C) // (US2) IRDA_FILTER Register +#define AT91C_US2_BRGR (AT91_CAST(AT91_REG *) 0x40098020) // (US2) Baud Rate Generator Register +#define AT91C_US2_FIDI (AT91_CAST(AT91_REG *) 0x40098040) // (US2) FI_DI_Ratio Register +#define AT91C_US2_IER (AT91_CAST(AT91_REG *) 0x40098008) // (US2) Interrupt Enable Register +#define AT91C_US2_RTOR (AT91_CAST(AT91_REG *) 0x40098024) // (US2) Receiver Time-out Register +#define AT91C_US2_CR (AT91_CAST(AT91_REG *) 0x40098000) // (US2) Control Register +#define AT91C_US2_THR (AT91_CAST(AT91_REG *) 0x4009801C) // (US2) Transmitter Holding Register +#define AT91C_US2_CSR (AT91_CAST(AT91_REG *) 0x40098014) // (US2) Channel Status Register +#define AT91C_US2_VER (AT91_CAST(AT91_REG *) 0x400980FC) // (US2) VERSION Register +#define AT91C_US2_FEATURES (AT91_CAST(AT91_REG *) 0x400980F8) // (US2) US FEATURES REGISTER +#define AT91C_US2_IDR (AT91_CAST(AT91_REG *) 0x4009800C) // (US2) Interrupt Disable Register +#define AT91C_US2_TTGR (AT91_CAST(AT91_REG *) 0x40098028) // (US2) Transmitter Time-guard Register +#define AT91C_US2_IPNAME2 (AT91_CAST(AT91_REG *) 0x400980F4) // (US2) US IPNAME2 REGISTER +#define AT91C_US2_RHR (AT91_CAST(AT91_REG *) 0x40098018) // (US2) Receiver Holding Register +#define AT91C_US2_NER (AT91_CAST(AT91_REG *) 0x40098044) // (US2) Nb Errors Register +#define AT91C_US2_IMR (AT91_CAST(AT91_REG *) 0x40098010) // (US2) Interrupt Mask Register +// ========== Register definition for PDC_US3 peripheral ========== +#define AT91C_US3_TPR (AT91_CAST(AT91_REG *) 0x4009C108) // (PDC_US3) Transmit Pointer Register +#define AT91C_US3_PTCR (AT91_CAST(AT91_REG *) 0x4009C120) // (PDC_US3) PDC Transfer Control Register +#define AT91C_US3_TCR (AT91_CAST(AT91_REG *) 0x4009C10C) // (PDC_US3) Transmit Counter Register +#define AT91C_US3_RCR (AT91_CAST(AT91_REG *) 0x4009C104) // (PDC_US3) Receive Counter Register +#define AT91C_US3_RNCR (AT91_CAST(AT91_REG *) 0x4009C114) // (PDC_US3) Receive Next Counter Register +#define AT91C_US3_RNPR (AT91_CAST(AT91_REG *) 0x4009C110) // (PDC_US3) Receive Next Pointer Register +#define AT91C_US3_RPR (AT91_CAST(AT91_REG *) 0x4009C100) // (PDC_US3) Receive Pointer Register +#define AT91C_US3_PTSR (AT91_CAST(AT91_REG *) 0x4009C124) // (PDC_US3) PDC Transfer Status Register +#define AT91C_US3_TNCR (AT91_CAST(AT91_REG *) 0x4009C11C) // (PDC_US3) Transmit Next Counter Register +#define AT91C_US3_TNPR (AT91_CAST(AT91_REG *) 0x4009C118) // (PDC_US3) Transmit Next Pointer Register +// ========== Register definition for US3 peripheral ========== +#define AT91C_US3_MAN (AT91_CAST(AT91_REG *) 0x4009C050) // (US3) Manchester Encoder Decoder Register +#define AT91C_US3_CSR (AT91_CAST(AT91_REG *) 0x4009C014) // (US3) Channel Status Register +#define AT91C_US3_BRGR (AT91_CAST(AT91_REG *) 0x4009C020) // (US3) Baud Rate Generator Register +#define AT91C_US3_IPNAME2 (AT91_CAST(AT91_REG *) 0x4009C0F4) // (US3) US IPNAME2 REGISTER +#define AT91C_US3_RTOR (AT91_CAST(AT91_REG *) 0x4009C024) // (US3) Receiver Time-out Register +#define AT91C_US3_ADDRSIZE (AT91_CAST(AT91_REG *) 0x4009C0EC) // (US3) US ADDRSIZE REGISTER +#define AT91C_US3_CR (AT91_CAST(AT91_REG *) 0x4009C000) // (US3) Control Register +#define AT91C_US3_IF (AT91_CAST(AT91_REG *) 0x4009C04C) // (US3) IRDA_FILTER Register +#define AT91C_US3_FEATURES (AT91_CAST(AT91_REG *) 0x4009C0F8) // (US3) US FEATURES REGISTER +#define AT91C_US3_VER (AT91_CAST(AT91_REG *) 0x4009C0FC) // (US3) VERSION Register +#define AT91C_US3_RHR (AT91_CAST(AT91_REG *) 0x4009C018) // (US3) Receiver Holding Register +#define AT91C_US3_TTGR (AT91_CAST(AT91_REG *) 0x4009C028) // (US3) Transmitter Time-guard Register +#define AT91C_US3_NER (AT91_CAST(AT91_REG *) 0x4009C044) // (US3) Nb Errors Register +#define AT91C_US3_IMR (AT91_CAST(AT91_REG *) 0x4009C010) // (US3) Interrupt Mask Register +#define AT91C_US3_THR (AT91_CAST(AT91_REG *) 0x4009C01C) // (US3) Transmitter Holding Register +#define AT91C_US3_IDR (AT91_CAST(AT91_REG *) 0x4009C00C) // (US3) Interrupt Disable Register +#define AT91C_US3_MR (AT91_CAST(AT91_REG *) 0x4009C004) // (US3) Mode Register +#define AT91C_US3_IER (AT91_CAST(AT91_REG *) 0x4009C008) // (US3) Interrupt Enable Register +#define AT91C_US3_FIDI (AT91_CAST(AT91_REG *) 0x4009C040) // (US3) FI_DI_Ratio Register +#define AT91C_US3_IPNAME1 (AT91_CAST(AT91_REG *) 0x4009C0F0) // (US3) US IPNAME1 REGISTER +// ========== Register definition for PDC_SSC0 peripheral ========== +#define AT91C_SSC0_RNCR (AT91_CAST(AT91_REG *) 0x40004114) // (PDC_SSC0) Receive Next Counter Register +#define AT91C_SSC0_TPR (AT91_CAST(AT91_REG *) 0x40004108) // (PDC_SSC0) Transmit Pointer Register +#define AT91C_SSC0_TCR (AT91_CAST(AT91_REG *) 0x4000410C) // (PDC_SSC0) Transmit Counter Register +#define AT91C_SSC0_PTCR (AT91_CAST(AT91_REG *) 0x40004120) // (PDC_SSC0) PDC Transfer Control Register +#define AT91C_SSC0_TNPR (AT91_CAST(AT91_REG *) 0x40004118) // (PDC_SSC0) Transmit Next Pointer Register +#define AT91C_SSC0_RPR (AT91_CAST(AT91_REG *) 0x40004100) // (PDC_SSC0) Receive Pointer Register +#define AT91C_SSC0_TNCR (AT91_CAST(AT91_REG *) 0x4000411C) // (PDC_SSC0) Transmit Next Counter Register +#define AT91C_SSC0_RNPR (AT91_CAST(AT91_REG *) 0x40004110) // (PDC_SSC0) Receive Next Pointer Register +#define AT91C_SSC0_RCR (AT91_CAST(AT91_REG *) 0x40004104) // (PDC_SSC0) Receive Counter Register +#define AT91C_SSC0_PTSR (AT91_CAST(AT91_REG *) 0x40004124) // (PDC_SSC0) PDC Transfer Status Register +// ========== Register definition for SSC0 peripheral ========== +#define AT91C_SSC0_FEATURES (AT91_CAST(AT91_REG *) 0x400040F8) // (SSC0) SSC FEATURES REGISTER +#define AT91C_SSC0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400040F0) // (SSC0) SSC IPNAME1 REGISTER +#define AT91C_SSC0_CR (AT91_CAST(AT91_REG *) 0x40004000) // (SSC0) Control Register +#define AT91C_SSC0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400040EC) // (SSC0) SSC ADDRSIZE REGISTER +#define AT91C_SSC0_RHR (AT91_CAST(AT91_REG *) 0x40004020) // (SSC0) Receive Holding Register +#define AT91C_SSC0_VER (AT91_CAST(AT91_REG *) 0x400040FC) // (SSC0) Version Register +#define AT91C_SSC0_TSHR (AT91_CAST(AT91_REG *) 0x40004034) // (SSC0) Transmit Sync Holding Register +#define AT91C_SSC0_RFMR (AT91_CAST(AT91_REG *) 0x40004014) // (SSC0) Receive Frame Mode Register +#define AT91C_SSC0_IDR (AT91_CAST(AT91_REG *) 0x40004048) // (SSC0) Interrupt Disable Register +#define AT91C_SSC0_TFMR (AT91_CAST(AT91_REG *) 0x4000401C) // (SSC0) Transmit Frame Mode Register +#define AT91C_SSC0_RSHR (AT91_CAST(AT91_REG *) 0x40004030) // (SSC0) Receive Sync Holding Register +#define AT91C_SSC0_TCMR (AT91_CAST(AT91_REG *) 0x40004018) // (SSC0) Transmit Clock Mode Register +#define AT91C_SSC0_RCMR (AT91_CAST(AT91_REG *) 0x40004010) // (SSC0) Receive Clock ModeRegister +#define AT91C_SSC0_SR (AT91_CAST(AT91_REG *) 0x40004040) // (SSC0) Status Register +#define AT91C_SSC0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400040F4) // (SSC0) SSC IPNAME2 REGISTER +#define AT91C_SSC0_THR (AT91_CAST(AT91_REG *) 0x40004024) // (SSC0) Transmit Holding Register +#define AT91C_SSC0_CMR (AT91_CAST(AT91_REG *) 0x40004004) // (SSC0) Clock Mode Register +#define AT91C_SSC0_IER (AT91_CAST(AT91_REG *) 0x40004044) // (SSC0) Interrupt Enable Register +#define AT91C_SSC0_IMR (AT91_CAST(AT91_REG *) 0x4000404C) // (SSC0) Interrupt Mask Register +// ========== Register definition for PDC_PWMC peripheral ========== +#define AT91C_PWMC_TNCR (AT91_CAST(AT91_REG *) 0x4008C11C) // (PDC_PWMC) Transmit Next Counter Register +#define AT91C_PWMC_TPR (AT91_CAST(AT91_REG *) 0x4008C108) // (PDC_PWMC) Transmit Pointer Register +#define AT91C_PWMC_RPR (AT91_CAST(AT91_REG *) 0x4008C100) // (PDC_PWMC) Receive Pointer Register +#define AT91C_PWMC_TCR (AT91_CAST(AT91_REG *) 0x4008C10C) // (PDC_PWMC) Transmit Counter Register +#define AT91C_PWMC_PTSR (AT91_CAST(AT91_REG *) 0x4008C124) // (PDC_PWMC) PDC Transfer Status Register +#define AT91C_PWMC_RNPR (AT91_CAST(AT91_REG *) 0x4008C110) // (PDC_PWMC) Receive Next Pointer Register +#define AT91C_PWMC_RCR (AT91_CAST(AT91_REG *) 0x4008C104) // (PDC_PWMC) Receive Counter Register +#define AT91C_PWMC_RNCR (AT91_CAST(AT91_REG *) 0x4008C114) // (PDC_PWMC) Receive Next Counter Register +#define AT91C_PWMC_PTCR (AT91_CAST(AT91_REG *) 0x4008C120) // (PDC_PWMC) PDC Transfer Control Register +#define AT91C_PWMC_TNPR (AT91_CAST(AT91_REG *) 0x4008C118) // (PDC_PWMC) Transmit Next Pointer Register +// ========== Register definition for PWMC_CH0 peripheral ========== +#define AT91C_PWMC_CH0_DTR (AT91_CAST(AT91_REG *) 0x4008C218) // (PWMC_CH0) Channel Dead Time Value Register +#define AT91C_PWMC_CH0_CMR (AT91_CAST(AT91_REG *) 0x4008C200) // (PWMC_CH0) Channel Mode Register +#define AT91C_PWMC_CH0_CCNTR (AT91_CAST(AT91_REG *) 0x4008C214) // (PWMC_CH0) Channel Counter Register +#define AT91C_PWMC_CH0_CPRDR (AT91_CAST(AT91_REG *) 0x4008C20C) // (PWMC_CH0) Channel Period Register +#define AT91C_PWMC_CH0_DTUPDR (AT91_CAST(AT91_REG *) 0x4008C21C) // (PWMC_CH0) Channel Dead Time Update Value Register +#define AT91C_PWMC_CH0_CPRDUPDR (AT91_CAST(AT91_REG *) 0x4008C210) // (PWMC_CH0) Channel Period Update Register +#define AT91C_PWMC_CH0_CDTYUPDR (AT91_CAST(AT91_REG *) 0x4008C208) // (PWMC_CH0) Channel Duty Cycle Update Register +#define AT91C_PWMC_CH0_CDTYR (AT91_CAST(AT91_REG *) 0x4008C204) // (PWMC_CH0) Channel Duty Cycle Register +// ========== Register definition for PWMC_CH1 peripheral ========== +#define AT91C_PWMC_CH1_CCNTR (AT91_CAST(AT91_REG *) 0x4008C234) // (PWMC_CH1) Channel Counter Register +#define AT91C_PWMC_CH1_DTR (AT91_CAST(AT91_REG *) 0x4008C238) // (PWMC_CH1) Channel Dead Time Value Register +#define AT91C_PWMC_CH1_CDTYUPDR (AT91_CAST(AT91_REG *) 0x4008C228) // (PWMC_CH1) Channel Duty Cycle Update Register +#define AT91C_PWMC_CH1_DTUPDR (AT91_CAST(AT91_REG *) 0x4008C23C) // (PWMC_CH1) Channel Dead Time Update Value Register +#define AT91C_PWMC_CH1_CDTYR (AT91_CAST(AT91_REG *) 0x4008C224) // (PWMC_CH1) Channel Duty Cycle Register +#define AT91C_PWMC_CH1_CPRDR (AT91_CAST(AT91_REG *) 0x4008C22C) // (PWMC_CH1) Channel Period Register +#define AT91C_PWMC_CH1_CPRDUPDR (AT91_CAST(AT91_REG *) 0x4008C230) // (PWMC_CH1) Channel Period Update Register +#define AT91C_PWMC_CH1_CMR (AT91_CAST(AT91_REG *) 0x4008C220) // (PWMC_CH1) Channel Mode Register +// ========== Register definition for PWMC_CH2 peripheral ========== +#define AT91C_PWMC_CH2_CDTYR (AT91_CAST(AT91_REG *) 0x4008C244) // (PWMC_CH2) Channel Duty Cycle Register +#define AT91C_PWMC_CH2_DTUPDR (AT91_CAST(AT91_REG *) 0x4008C25C) // (PWMC_CH2) Channel Dead Time Update Value Register +#define AT91C_PWMC_CH2_CCNTR (AT91_CAST(AT91_REG *) 0x4008C254) // (PWMC_CH2) Channel Counter Register +#define AT91C_PWMC_CH2_CMR (AT91_CAST(AT91_REG *) 0x4008C240) // (PWMC_CH2) Channel Mode Register +#define AT91C_PWMC_CH2_CPRDR (AT91_CAST(AT91_REG *) 0x4008C24C) // (PWMC_CH2) Channel Period Register +#define AT91C_PWMC_CH2_CPRDUPDR (AT91_CAST(AT91_REG *) 0x4008C250) // (PWMC_CH2) Channel Period Update Register +#define AT91C_PWMC_CH2_CDTYUPDR (AT91_CAST(AT91_REG *) 0x4008C248) // (PWMC_CH2) Channel Duty Cycle Update Register +#define AT91C_PWMC_CH2_DTR (AT91_CAST(AT91_REG *) 0x4008C258) // (PWMC_CH2) Channel Dead Time Value Register +// ========== Register definition for PWMC_CH3 peripheral ========== +#define AT91C_PWMC_CH3_CPRDUPDR (AT91_CAST(AT91_REG *) 0x4008C270) // (PWMC_CH3) Channel Period Update Register +#define AT91C_PWMC_CH3_DTR (AT91_CAST(AT91_REG *) 0x4008C278) // (PWMC_CH3) Channel Dead Time Value Register +#define AT91C_PWMC_CH3_CDTYR (AT91_CAST(AT91_REG *) 0x4008C264) // (PWMC_CH3) Channel Duty Cycle Register +#define AT91C_PWMC_CH3_DTUPDR (AT91_CAST(AT91_REG *) 0x4008C27C) // (PWMC_CH3) Channel Dead Time Update Value Register +#define AT91C_PWMC_CH3_CDTYUPDR (AT91_CAST(AT91_REG *) 0x4008C268) // (PWMC_CH3) Channel Duty Cycle Update Register +#define AT91C_PWMC_CH3_CCNTR (AT91_CAST(AT91_REG *) 0x4008C274) // (PWMC_CH3) Channel Counter Register +#define AT91C_PWMC_CH3_CMR (AT91_CAST(AT91_REG *) 0x4008C260) // (PWMC_CH3) Channel Mode Register +#define AT91C_PWMC_CH3_CPRDR (AT91_CAST(AT91_REG *) 0x4008C26C) // (PWMC_CH3) Channel Period Register +// ========== Register definition for PWMC peripheral ========== +#define AT91C_PWMC_CMP6MUPD (AT91_CAST(AT91_REG *) 0x4008C19C) // (PWMC) PWM Comparison Mode 6 Update Register +#define AT91C_PWMC_ISR1 (AT91_CAST(AT91_REG *) 0x4008C01C) // (PWMC) PWMC Interrupt Status Register 1 +#define AT91C_PWMC_CMP5V (AT91_CAST(AT91_REG *) 0x4008C180) // (PWMC) PWM Comparison Value 5 Register +#define AT91C_PWMC_CMP4MUPD (AT91_CAST(AT91_REG *) 0x4008C17C) // (PWMC) PWM Comparison Mode 4 Update Register +#define AT91C_PWMC_FMR (AT91_CAST(AT91_REG *) 0x4008C05C) // (PWMC) PWM Fault Mode Register +#define AT91C_PWMC_CMP6V (AT91_CAST(AT91_REG *) 0x4008C190) // (PWMC) PWM Comparison Value 6 Register +#define AT91C_PWMC_EL4MR (AT91_CAST(AT91_REG *) 0x4008C08C) // (PWMC) PWM Event Line 4 Mode Register +#define AT91C_PWMC_UPCR (AT91_CAST(AT91_REG *) 0x4008C028) // (PWMC) PWM Update Control Register +#define AT91C_PWMC_CMP1VUPD (AT91_CAST(AT91_REG *) 0x4008C144) // (PWMC) PWM Comparison Value 1 Update Register +#define AT91C_PWMC_CMP0M (AT91_CAST(AT91_REG *) 0x4008C138) // (PWMC) PWM Comparison Mode 0 Register +#define AT91C_PWMC_CMP5VUPD (AT91_CAST(AT91_REG *) 0x4008C184) // (PWMC) PWM Comparison Value 5 Update Register +#define AT91C_PWMC_FPER3 (AT91_CAST(AT91_REG *) 0x4008C074) // (PWMC) PWM Fault Protection Enable Register 3 +#define AT91C_PWMC_OSCUPD (AT91_CAST(AT91_REG *) 0x4008C058) // (PWMC) PWM Output Selection Clear Update Register +#define AT91C_PWMC_FPER1 (AT91_CAST(AT91_REG *) 0x4008C06C) // (PWMC) PWM Fault Protection Enable Register 1 +#define AT91C_PWMC_SCUPUPD (AT91_CAST(AT91_REG *) 0x4008C030) // (PWMC) PWM Update Period Update Register +#define AT91C_PWMC_DIS (AT91_CAST(AT91_REG *) 0x4008C008) // (PWMC) PWMC Disable Register +#define AT91C_PWMC_IER1 (AT91_CAST(AT91_REG *) 0x4008C010) // (PWMC) PWMC Interrupt Enable Register 1 +#define AT91C_PWMC_IMR2 (AT91_CAST(AT91_REG *) 0x4008C03C) // (PWMC) PWMC Interrupt Mask Register 2 +#define AT91C_PWMC_CMP0V (AT91_CAST(AT91_REG *) 0x4008C130) // (PWMC) PWM Comparison Value 0 Register +#define AT91C_PWMC_SR (AT91_CAST(AT91_REG *) 0x4008C00C) // (PWMC) PWMC Status Register +#define AT91C_PWMC_CMP4M (AT91_CAST(AT91_REG *) 0x4008C178) // (PWMC) PWM Comparison Mode 4 Register +#define AT91C_PWMC_CMP3M (AT91_CAST(AT91_REG *) 0x4008C168) // (PWMC) PWM Comparison Mode 3 Register +#define AT91C_PWMC_IER2 (AT91_CAST(AT91_REG *) 0x4008C034) // (PWMC) PWMC Interrupt Enable Register 2 +#define AT91C_PWMC_CMP3VUPD (AT91_CAST(AT91_REG *) 0x4008C164) // (PWMC) PWM Comparison Value 3 Update Register +#define AT91C_PWMC_CMP2M (AT91_CAST(AT91_REG *) 0x4008C158) // (PWMC) PWM Comparison Mode 2 Register +#define AT91C_PWMC_IDR2 (AT91_CAST(AT91_REG *) 0x4008C038) // (PWMC) PWMC Interrupt Disable Register 2 +#define AT91C_PWMC_EL2MR (AT91_CAST(AT91_REG *) 0x4008C084) // (PWMC) PWM Event Line 2 Mode Register +#define AT91C_PWMC_CMP7V (AT91_CAST(AT91_REG *) 0x4008C1A0) // (PWMC) PWM Comparison Value 7 Register +#define AT91C_PWMC_CMP1M (AT91_CAST(AT91_REG *) 0x4008C148) // (PWMC) PWM Comparison Mode 1 Register +#define AT91C_PWMC_CMP0VUPD (AT91_CAST(AT91_REG *) 0x4008C134) // (PWMC) PWM Comparison Value 0 Update Register +#define AT91C_PWMC_WPSR (AT91_CAST(AT91_REG *) 0x4008C0E8) // (PWMC) PWM Write Protection Status Register +#define AT91C_PWMC_CMP6VUPD (AT91_CAST(AT91_REG *) 0x4008C194) // (PWMC) PWM Comparison Value 6 Update Register +#define AT91C_PWMC_CMP1MUPD (AT91_CAST(AT91_REG *) 0x4008C14C) // (PWMC) PWM Comparison Mode 1 Update Register +#define AT91C_PWMC_CMP1V (AT91_CAST(AT91_REG *) 0x4008C140) // (PWMC) PWM Comparison Value 1 Register +#define AT91C_PWMC_FCR (AT91_CAST(AT91_REG *) 0x4008C064) // (PWMC) PWM Fault Mode Clear Register +#define AT91C_PWMC_VER (AT91_CAST(AT91_REG *) 0x4008C0FC) // (PWMC) PWMC Version Register +#define AT91C_PWMC_EL1MR (AT91_CAST(AT91_REG *) 0x4008C080) // (PWMC) PWM Event Line 1 Mode Register +#define AT91C_PWMC_EL6MR (AT91_CAST(AT91_REG *) 0x4008C094) // (PWMC) PWM Event Line 6 Mode Register +#define AT91C_PWMC_ISR2 (AT91_CAST(AT91_REG *) 0x4008C040) // (PWMC) PWMC Interrupt Status Register 2 +#define AT91C_PWMC_CMP4VUPD (AT91_CAST(AT91_REG *) 0x4008C174) // (PWMC) PWM Comparison Value 4 Update Register +#define AT91C_PWMC_CMP5MUPD (AT91_CAST(AT91_REG *) 0x4008C18C) // (PWMC) PWM Comparison Mode 5 Update Register +#define AT91C_PWMC_OS (AT91_CAST(AT91_REG *) 0x4008C048) // (PWMC) PWM Output Selection Register +#define AT91C_PWMC_FPV (AT91_CAST(AT91_REG *) 0x4008C068) // (PWMC) PWM Fault Protection Value Register +#define AT91C_PWMC_FPER2 (AT91_CAST(AT91_REG *) 0x4008C070) // (PWMC) PWM Fault Protection Enable Register 2 +#define AT91C_PWMC_EL7MR (AT91_CAST(AT91_REG *) 0x4008C098) // (PWMC) PWM Event Line 7 Mode Register +#define AT91C_PWMC_OSSUPD (AT91_CAST(AT91_REG *) 0x4008C054) // (PWMC) PWM Output Selection Set Update Register +#define AT91C_PWMC_FEATURES (AT91_CAST(AT91_REG *) 0x4008C0F8) // (PWMC) PWMC FEATURES REGISTER +#define AT91C_PWMC_CMP2V (AT91_CAST(AT91_REG *) 0x4008C150) // (PWMC) PWM Comparison Value 2 Register +#define AT91C_PWMC_FSR (AT91_CAST(AT91_REG *) 0x4008C060) // (PWMC) PWM Fault Mode Status Register +#define AT91C_PWMC_ADDRSIZE (AT91_CAST(AT91_REG *) 0x4008C0EC) // (PWMC) PWMC ADDRSIZE REGISTER +#define AT91C_PWMC_OSC (AT91_CAST(AT91_REG *) 0x4008C050) // (PWMC) PWM Output Selection Clear Register +#define AT91C_PWMC_SCUP (AT91_CAST(AT91_REG *) 0x4008C02C) // (PWMC) PWM Update Period Register +#define AT91C_PWMC_CMP7MUPD (AT91_CAST(AT91_REG *) 0x4008C1AC) // (PWMC) PWM Comparison Mode 7 Update Register +#define AT91C_PWMC_CMP2VUPD (AT91_CAST(AT91_REG *) 0x4008C154) // (PWMC) PWM Comparison Value 2 Update Register +#define AT91C_PWMC_FPER4 (AT91_CAST(AT91_REG *) 0x4008C078) // (PWMC) PWM Fault Protection Enable Register 4 +#define AT91C_PWMC_IMR1 (AT91_CAST(AT91_REG *) 0x4008C018) // (PWMC) PWMC Interrupt Mask Register 1 +#define AT91C_PWMC_EL3MR (AT91_CAST(AT91_REG *) 0x4008C088) // (PWMC) PWM Event Line 3 Mode Register +#define AT91C_PWMC_CMP3V (AT91_CAST(AT91_REG *) 0x4008C160) // (PWMC) PWM Comparison Value 3 Register +#define AT91C_PWMC_IPNAME1 (AT91_CAST(AT91_REG *) 0x4008C0F0) // (PWMC) PWMC IPNAME1 REGISTER +#define AT91C_PWMC_OSS (AT91_CAST(AT91_REG *) 0x4008C04C) // (PWMC) PWM Output Selection Set Register +#define AT91C_PWMC_CMP0MUPD (AT91_CAST(AT91_REG *) 0x4008C13C) // (PWMC) PWM Comparison Mode 0 Update Register +#define AT91C_PWMC_CMP2MUPD (AT91_CAST(AT91_REG *) 0x4008C15C) // (PWMC) PWM Comparison Mode 2 Update Register +#define AT91C_PWMC_CMP4V (AT91_CAST(AT91_REG *) 0x4008C170) // (PWMC) PWM Comparison Value 4 Register +#define AT91C_PWMC_ENA (AT91_CAST(AT91_REG *) 0x4008C004) // (PWMC) PWMC Enable Register +#define AT91C_PWMC_CMP3MUPD (AT91_CAST(AT91_REG *) 0x4008C16C) // (PWMC) PWM Comparison Mode 3 Update Register +#define AT91C_PWMC_EL0MR (AT91_CAST(AT91_REG *) 0x4008C07C) // (PWMC) PWM Event Line 0 Mode Register +#define AT91C_PWMC_OOV (AT91_CAST(AT91_REG *) 0x4008C044) // (PWMC) PWM Output Override Value Register +#define AT91C_PWMC_WPCR (AT91_CAST(AT91_REG *) 0x4008C0E4) // (PWMC) PWM Write Protection Enable Register +#define AT91C_PWMC_CMP7M (AT91_CAST(AT91_REG *) 0x4008C1A8) // (PWMC) PWM Comparison Mode 7 Register +#define AT91C_PWMC_CMP6M (AT91_CAST(AT91_REG *) 0x4008C198) // (PWMC) PWM Comparison Mode 6 Register +#define AT91C_PWMC_CMP5M (AT91_CAST(AT91_REG *) 0x4008C188) // (PWMC) PWM Comparison Mode 5 Register +#define AT91C_PWMC_IPNAME2 (AT91_CAST(AT91_REG *) 0x4008C0F4) // (PWMC) PWMC IPNAME2 REGISTER +#define AT91C_PWMC_CMP7VUPD (AT91_CAST(AT91_REG *) 0x4008C1A4) // (PWMC) PWM Comparison Value 7 Update Register +#define AT91C_PWMC_SYNC (AT91_CAST(AT91_REG *) 0x4008C020) // (PWMC) PWM Synchronized Channels Register +#define AT91C_PWMC_MR (AT91_CAST(AT91_REG *) 0x4008C000) // (PWMC) PWMC Mode Register +#define AT91C_PWMC_IDR1 (AT91_CAST(AT91_REG *) 0x4008C014) // (PWMC) PWMC Interrupt Disable Register 1 +#define AT91C_PWMC_EL5MR (AT91_CAST(AT91_REG *) 0x4008C090) // (PWMC) PWM Event Line 5 Mode Register +// ========== Register definition for SPI0 peripheral ========== +#define AT91C_SPI0_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400080EC) // (SPI0) SPI ADDRSIZE REGISTER +#define AT91C_SPI0_RDR (AT91_CAST(AT91_REG *) 0x40008008) // (SPI0) Receive Data Register +#define AT91C_SPI0_FEATURES (AT91_CAST(AT91_REG *) 0x400080F8) // (SPI0) SPI FEATURES REGISTER +#define AT91C_SPI0_CR (AT91_CAST(AT91_REG *) 0x40008000) // (SPI0) Control Register +#define AT91C_SPI0_IPNAME1 (AT91_CAST(AT91_REG *) 0x400080F0) // (SPI0) SPI IPNAME1 REGISTER +#define AT91C_SPI0_VER (AT91_CAST(AT91_REG *) 0x400080FC) // (SPI0) Version Register +#define AT91C_SPI0_IDR (AT91_CAST(AT91_REG *) 0x40008018) // (SPI0) Interrupt Disable Register +#define AT91C_SPI0_TDR (AT91_CAST(AT91_REG *) 0x4000800C) // (SPI0) Transmit Data Register +#define AT91C_SPI0_MR (AT91_CAST(AT91_REG *) 0x40008004) // (SPI0) Mode Register +#define AT91C_SPI0_IER (AT91_CAST(AT91_REG *) 0x40008014) // (SPI0) Interrupt Enable Register +#define AT91C_SPI0_IMR (AT91_CAST(AT91_REG *) 0x4000801C) // (SPI0) Interrupt Mask Register +#define AT91C_SPI0_IPNAME2 (AT91_CAST(AT91_REG *) 0x400080F4) // (SPI0) SPI IPNAME2 REGISTER +#define AT91C_SPI0_CSR (AT91_CAST(AT91_REG *) 0x40008030) // (SPI0) Chip Select Register +#define AT91C_SPI0_SR (AT91_CAST(AT91_REG *) 0x40008010) // (SPI0) Status Register +// ========== Register definition for UDPHS_EPTFIFO peripheral ========== +#define AT91C_UDPHS_EPTFIFO_READEPT6 (AT91_CAST(AT91_REG *) 0x201E0000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 6 +#define AT91C_UDPHS_EPTFIFO_READEPT2 (AT91_CAST(AT91_REG *) 0x201A0000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 2 +#define AT91C_UDPHS_EPTFIFO_READEPT1 (AT91_CAST(AT91_REG *) 0x20190000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 1 +#define AT91C_UDPHS_EPTFIFO_READEPT0 (AT91_CAST(AT91_REG *) 0x20180000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 0 +#define AT91C_UDPHS_EPTFIFO_READEPT5 (AT91_CAST(AT91_REG *) 0x201D0000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 5 +#define AT91C_UDPHS_EPTFIFO_READEPT4 (AT91_CAST(AT91_REG *) 0x201C0000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 4 +#define AT91C_UDPHS_EPTFIFO_READEPT3 (AT91_CAST(AT91_REG *) 0x201B0000) // (UDPHS_EPTFIFO) FIFO Endpoint Data Register 3 +// ========== Register definition for UDPHS_EPT_0 peripheral ========== +#define AT91C_UDPHS_EPT_0_EPTCTL (AT91_CAST(AT91_REG *) 0x400A410C) // (UDPHS_EPT_0) UDPHS Endpoint Control Register +#define AT91C_UDPHS_EPT_0_EPTSTA (AT91_CAST(AT91_REG *) 0x400A411C) // (UDPHS_EPT_0) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_0_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A4118) // (UDPHS_EPT_0) UDPHS Endpoint Clear Status Register +#define AT91C_UDPHS_EPT_0_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A4108) // (UDPHS_EPT_0) UDPHS Endpoint Control Disable Register +#define AT91C_UDPHS_EPT_0_EPTCFG (AT91_CAST(AT91_REG *) 0x400A4100) // (UDPHS_EPT_0) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_0_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A4114) // (UDPHS_EPT_0) UDPHS Endpoint Set Status Register +#define AT91C_UDPHS_EPT_0_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A4104) // (UDPHS_EPT_0) UDPHS Endpoint Control Enable Register +// ========== Register definition for UDPHS_EPT_1 peripheral ========== +#define AT91C_UDPHS_EPT_1_EPTSTA (AT91_CAST(AT91_REG *) 0x400A413C) // (UDPHS_EPT_1) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_1_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A4134) // (UDPHS_EPT_1) UDPHS Endpoint Set Status Register +#define AT91C_UDPHS_EPT_1_EPTCTL (AT91_CAST(AT91_REG *) 0x400A412C) // (UDPHS_EPT_1) UDPHS Endpoint Control Register +#define AT91C_UDPHS_EPT_1_EPTCFG (AT91_CAST(AT91_REG *) 0x400A4120) // (UDPHS_EPT_1) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_1_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A4128) // (UDPHS_EPT_1) UDPHS Endpoint Control Disable Register +#define AT91C_UDPHS_EPT_1_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A4138) // (UDPHS_EPT_1) UDPHS Endpoint Clear Status Register +#define AT91C_UDPHS_EPT_1_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A4124) // (UDPHS_EPT_1) UDPHS Endpoint Control Enable Register +// ========== Register definition for UDPHS_EPT_2 peripheral ========== +#define AT91C_UDPHS_EPT_2_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A4144) // (UDPHS_EPT_2) UDPHS Endpoint Control Enable Register +#define AT91C_UDPHS_EPT_2_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A4158) // (UDPHS_EPT_2) UDPHS Endpoint Clear Status Register +#define AT91C_UDPHS_EPT_2_EPTCFG (AT91_CAST(AT91_REG *) 0x400A4140) // (UDPHS_EPT_2) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_2_EPTCTL (AT91_CAST(AT91_REG *) 0x400A414C) // (UDPHS_EPT_2) UDPHS Endpoint Control Register +#define AT91C_UDPHS_EPT_2_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A4154) // (UDPHS_EPT_2) UDPHS Endpoint Set Status Register +#define AT91C_UDPHS_EPT_2_EPTSTA (AT91_CAST(AT91_REG *) 0x400A415C) // (UDPHS_EPT_2) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_2_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A4148) // (UDPHS_EPT_2) UDPHS Endpoint Control Disable Register +// ========== Register definition for UDPHS_EPT_3 peripheral ========== +#define AT91C_UDPHS_EPT_3_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A4168) // (UDPHS_EPT_3) UDPHS Endpoint Control Disable Register +#define AT91C_UDPHS_EPT_3_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A4164) // (UDPHS_EPT_3) UDPHS Endpoint Control Enable Register +#define AT91C_UDPHS_EPT_3_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A4174) // (UDPHS_EPT_3) UDPHS Endpoint Set Status Register +#define AT91C_UDPHS_EPT_3_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A4178) // (UDPHS_EPT_3) UDPHS Endpoint Clear Status Register +#define AT91C_UDPHS_EPT_3_EPTCFG (AT91_CAST(AT91_REG *) 0x400A4160) // (UDPHS_EPT_3) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_3_EPTSTA (AT91_CAST(AT91_REG *) 0x400A417C) // (UDPHS_EPT_3) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_3_EPTCTL (AT91_CAST(AT91_REG *) 0x400A416C) // (UDPHS_EPT_3) UDPHS Endpoint Control Register +// ========== Register definition for UDPHS_EPT_4 peripheral ========== +#define AT91C_UDPHS_EPT_4_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A4194) // (UDPHS_EPT_4) UDPHS Endpoint Set Status Register +#define AT91C_UDPHS_EPT_4_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A4188) // (UDPHS_EPT_4) UDPHS Endpoint Control Disable Register +#define AT91C_UDPHS_EPT_4_EPTCTL (AT91_CAST(AT91_REG *) 0x400A418C) // (UDPHS_EPT_4) UDPHS Endpoint Control Register +#define AT91C_UDPHS_EPT_4_EPTCFG (AT91_CAST(AT91_REG *) 0x400A4180) // (UDPHS_EPT_4) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_4_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A4184) // (UDPHS_EPT_4) UDPHS Endpoint Control Enable Register +#define AT91C_UDPHS_EPT_4_EPTSTA (AT91_CAST(AT91_REG *) 0x400A419C) // (UDPHS_EPT_4) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_4_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A4198) // (UDPHS_EPT_4) UDPHS Endpoint Clear Status Register +// ========== Register definition for UDPHS_EPT_5 peripheral ========== +#define AT91C_UDPHS_EPT_5_EPTCFG (AT91_CAST(AT91_REG *) 0x400A41A0) // (UDPHS_EPT_5) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_5_EPTCTL (AT91_CAST(AT91_REG *) 0x400A41AC) // (UDPHS_EPT_5) UDPHS Endpoint Control Register +#define AT91C_UDPHS_EPT_5_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A41A4) // (UDPHS_EPT_5) UDPHS Endpoint Control Enable Register +#define AT91C_UDPHS_EPT_5_EPTSTA (AT91_CAST(AT91_REG *) 0x400A41BC) // (UDPHS_EPT_5) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_5_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A41B4) // (UDPHS_EPT_5) UDPHS Endpoint Set Status Register +#define AT91C_UDPHS_EPT_5_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A41A8) // (UDPHS_EPT_5) UDPHS Endpoint Control Disable Register +#define AT91C_UDPHS_EPT_5_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A41B8) // (UDPHS_EPT_5) UDPHS Endpoint Clear Status Register +// ========== Register definition for UDPHS_EPT_6 peripheral ========== +#define AT91C_UDPHS_EPT_6_EPTCLRSTA (AT91_CAST(AT91_REG *) 0x400A41D8) // (UDPHS_EPT_6) UDPHS Endpoint Clear Status Register +#define AT91C_UDPHS_EPT_6_EPTCTL (AT91_CAST(AT91_REG *) 0x400A41CC) // (UDPHS_EPT_6) UDPHS Endpoint Control Register +#define AT91C_UDPHS_EPT_6_EPTCFG (AT91_CAST(AT91_REG *) 0x400A41C0) // (UDPHS_EPT_6) UDPHS Endpoint Config Register +#define AT91C_UDPHS_EPT_6_EPTCTLDIS (AT91_CAST(AT91_REG *) 0x400A41C8) // (UDPHS_EPT_6) UDPHS Endpoint Control Disable Register +#define AT91C_UDPHS_EPT_6_EPTSTA (AT91_CAST(AT91_REG *) 0x400A41DC) // (UDPHS_EPT_6) UDPHS Endpoint Status Register +#define AT91C_UDPHS_EPT_6_EPTCTLENB (AT91_CAST(AT91_REG *) 0x400A41C4) // (UDPHS_EPT_6) UDPHS Endpoint Control Enable Register +#define AT91C_UDPHS_EPT_6_EPTSETSTA (AT91_CAST(AT91_REG *) 0x400A41D4) // (UDPHS_EPT_6) UDPHS Endpoint Set Status Register +// ========== Register definition for UDPHS_DMA_1 peripheral ========== +#define AT91C_UDPHS_DMA_1_DMASTATUS (AT91_CAST(AT91_REG *) 0x400A431C) // (UDPHS_DMA_1) UDPHS DMA Channel Status Register +#define AT91C_UDPHS_DMA_1_DMACONTROL (AT91_CAST(AT91_REG *) 0x400A4318) // (UDPHS_DMA_1) UDPHS DMA Channel Control Register +#define AT91C_UDPHS_DMA_1_DMANXTDSC (AT91_CAST(AT91_REG *) 0x400A4310) // (UDPHS_DMA_1) UDPHS DMA Channel Next Descriptor Address +#define AT91C_UDPHS_DMA_1_DMAADDRESS (AT91_CAST(AT91_REG *) 0x400A4314) // (UDPHS_DMA_1) UDPHS DMA Channel Address Register +// ========== Register definition for UDPHS_DMA_2 peripheral ========== +#define AT91C_UDPHS_DMA_2_DMASTATUS (AT91_CAST(AT91_REG *) 0x400A432C) // (UDPHS_DMA_2) UDPHS DMA Channel Status Register +#define AT91C_UDPHS_DMA_2_DMANXTDSC (AT91_CAST(AT91_REG *) 0x400A4320) // (UDPHS_DMA_2) UDPHS DMA Channel Next Descriptor Address +#define AT91C_UDPHS_DMA_2_DMACONTROL (AT91_CAST(AT91_REG *) 0x400A4328) // (UDPHS_DMA_2) UDPHS DMA Channel Control Register +#define AT91C_UDPHS_DMA_2_DMAADDRESS (AT91_CAST(AT91_REG *) 0x400A4324) // (UDPHS_DMA_2) UDPHS DMA Channel Address Register +// ========== Register definition for UDPHS_DMA_3 peripheral ========== +#define AT91C_UDPHS_DMA_3_DMACONTROL (AT91_CAST(AT91_REG *) 0x400A4338) // (UDPHS_DMA_3) UDPHS DMA Channel Control Register +#define AT91C_UDPHS_DMA_3_DMANXTDSC (AT91_CAST(AT91_REG *) 0x400A4330) // (UDPHS_DMA_3) UDPHS DMA Channel Next Descriptor Address +#define AT91C_UDPHS_DMA_3_DMASTATUS (AT91_CAST(AT91_REG *) 0x400A433C) // (UDPHS_DMA_3) UDPHS DMA Channel Status Register +#define AT91C_UDPHS_DMA_3_DMAADDRESS (AT91_CAST(AT91_REG *) 0x400A4334) // (UDPHS_DMA_3) UDPHS DMA Channel Address Register +// ========== Register definition for UDPHS_DMA_4 peripheral ========== +#define AT91C_UDPHS_DMA_4_DMAADDRESS (AT91_CAST(AT91_REG *) 0x400A4344) // (UDPHS_DMA_4) UDPHS DMA Channel Address Register +#define AT91C_UDPHS_DMA_4_DMANXTDSC (AT91_CAST(AT91_REG *) 0x400A4340) // (UDPHS_DMA_4) UDPHS DMA Channel Next Descriptor Address +#define AT91C_UDPHS_DMA_4_DMASTATUS (AT91_CAST(AT91_REG *) 0x400A434C) // (UDPHS_DMA_4) UDPHS DMA Channel Status Register +#define AT91C_UDPHS_DMA_4_DMACONTROL (AT91_CAST(AT91_REG *) 0x400A4348) // (UDPHS_DMA_4) UDPHS DMA Channel Control Register +// ========== Register definition for UDPHS_DMA_5 peripheral ========== +#define AT91C_UDPHS_DMA_5_DMACONTROL (AT91_CAST(AT91_REG *) 0x400A4358) // (UDPHS_DMA_5) UDPHS DMA Channel Control Register +#define AT91C_UDPHS_DMA_5_DMAADDRESS (AT91_CAST(AT91_REG *) 0x400A4354) // (UDPHS_DMA_5) UDPHS DMA Channel Address Register +#define AT91C_UDPHS_DMA_5_DMANXTDSC (AT91_CAST(AT91_REG *) 0x400A4350) // (UDPHS_DMA_5) UDPHS DMA Channel Next Descriptor Address +#define AT91C_UDPHS_DMA_5_DMASTATUS (AT91_CAST(AT91_REG *) 0x400A435C) // (UDPHS_DMA_5) UDPHS DMA Channel Status Register +// ========== Register definition for UDPHS_DMA_6 peripheral ========== +#define AT91C_UDPHS_DMA_6_DMASTATUS (AT91_CAST(AT91_REG *) 0x400A436C) // (UDPHS_DMA_6) UDPHS DMA Channel Status Register +#define AT91C_UDPHS_DMA_6_DMACONTROL (AT91_CAST(AT91_REG *) 0x400A4368) // (UDPHS_DMA_6) UDPHS DMA Channel Control Register +#define AT91C_UDPHS_DMA_6_DMANXTDSC (AT91_CAST(AT91_REG *) 0x400A4360) // (UDPHS_DMA_6) UDPHS DMA Channel Next Descriptor Address +#define AT91C_UDPHS_DMA_6_DMAADDRESS (AT91_CAST(AT91_REG *) 0x400A4364) // (UDPHS_DMA_6) UDPHS DMA Channel Address Register +// ========== Register definition for UDPHS peripheral ========== +#define AT91C_UDPHS_EPTRST (AT91_CAST(AT91_REG *) 0x400A401C) // (UDPHS) UDPHS Endpoints Reset Register +#define AT91C_UDPHS_IEN (AT91_CAST(AT91_REG *) 0x400A4010) // (UDPHS) UDPHS Interrupt Enable Register +#define AT91C_UDPHS_TSTCNTB (AT91_CAST(AT91_REG *) 0x400A40D8) // (UDPHS) UDPHS Test B Counter Register +#define AT91C_UDPHS_RIPNAME2 (AT91_CAST(AT91_REG *) 0x400A40F4) // (UDPHS) UDPHS Name2 Register +#define AT91C_UDPHS_RIPPADDRSIZE (AT91_CAST(AT91_REG *) 0x400A40EC) // (UDPHS) UDPHS PADDRSIZE Register +#define AT91C_UDPHS_TSTMODREG (AT91_CAST(AT91_REG *) 0x400A40DC) // (UDPHS) UDPHS Test Mode Register +#define AT91C_UDPHS_TST (AT91_CAST(AT91_REG *) 0x400A40E0) // (UDPHS) UDPHS Test Register +#define AT91C_UDPHS_TSTSOFCNT (AT91_CAST(AT91_REG *) 0x400A40D0) // (UDPHS) UDPHS Test SOF Counter Register +#define AT91C_UDPHS_FNUM (AT91_CAST(AT91_REG *) 0x400A4004) // (UDPHS) UDPHS Frame Number Register +#define AT91C_UDPHS_TSTCNTA (AT91_CAST(AT91_REG *) 0x400A40D4) // (UDPHS) UDPHS Test A Counter Register +#define AT91C_UDPHS_INTSTA (AT91_CAST(AT91_REG *) 0x400A4014) // (UDPHS) UDPHS Interrupt Status Register +#define AT91C_UDPHS_IPFEATURES (AT91_CAST(AT91_REG *) 0x400A40F8) // (UDPHS) UDPHS Features Register +#define AT91C_UDPHS_CLRINT (AT91_CAST(AT91_REG *) 0x400A4018) // (UDPHS) UDPHS Clear Interrupt Register +#define AT91C_UDPHS_RIPNAME1 (AT91_CAST(AT91_REG *) 0x400A40F0) // (UDPHS) UDPHS Name1 Register +#define AT91C_UDPHS_CTRL (AT91_CAST(AT91_REG *) 0x400A4000) // (UDPHS) UDPHS Control Register +#define AT91C_UDPHS_IPVERSION (AT91_CAST(AT91_REG *) 0x400A40FC) // (UDPHS) UDPHS Version Register +// ========== Register definition for HDMA_CH_0 peripheral ========== +#define AT91C_HDMA_CH_0_CADDR (AT91_CAST(AT91_REG *) 0x400B0060) // (HDMA_CH_0) HDMA Reserved +#define AT91C_HDMA_CH_0_DADDR (AT91_CAST(AT91_REG *) 0x400B0040) // (HDMA_CH_0) HDMA Channel Destination Address Register +#define AT91C_HDMA_CH_0_BDSCR (AT91_CAST(AT91_REG *) 0x400B005C) // (HDMA_CH_0) HDMA Reserved +#define AT91C_HDMA_CH_0_CFG (AT91_CAST(AT91_REG *) 0x400B0050) // (HDMA_CH_0) HDMA Channel Configuration Register +#define AT91C_HDMA_CH_0_CTRLB (AT91_CAST(AT91_REG *) 0x400B004C) // (HDMA_CH_0) HDMA Channel Control B Register +#define AT91C_HDMA_CH_0_CTRLA (AT91_CAST(AT91_REG *) 0x400B0048) // (HDMA_CH_0) HDMA Channel Control A Register +#define AT91C_HDMA_CH_0_DSCR (AT91_CAST(AT91_REG *) 0x400B0044) // (HDMA_CH_0) HDMA Channel Descriptor Address Register +#define AT91C_HDMA_CH_0_SADDR (AT91_CAST(AT91_REG *) 0x400B003C) // (HDMA_CH_0) HDMA Channel Source Address Register +#define AT91C_HDMA_CH_0_DPIP (AT91_CAST(AT91_REG *) 0x400B0058) // (HDMA_CH_0) HDMA Channel Destination Picture in Picture Configuration Register +#define AT91C_HDMA_CH_0_SPIP (AT91_CAST(AT91_REG *) 0x400B0054) // (HDMA_CH_0) HDMA Channel Source Picture in Picture Configuration Register +// ========== Register definition for HDMA_CH_1 peripheral ========== +#define AT91C_HDMA_CH_1_DSCR (AT91_CAST(AT91_REG *) 0x400B006C) // (HDMA_CH_1) HDMA Channel Descriptor Address Register +#define AT91C_HDMA_CH_1_BDSCR (AT91_CAST(AT91_REG *) 0x400B0084) // (HDMA_CH_1) HDMA Reserved +#define AT91C_HDMA_CH_1_CTRLB (AT91_CAST(AT91_REG *) 0x400B0074) // (HDMA_CH_1) HDMA Channel Control B Register +#define AT91C_HDMA_CH_1_SPIP (AT91_CAST(AT91_REG *) 0x400B007C) // (HDMA_CH_1) HDMA Channel Source Picture in Picture Configuration Register +#define AT91C_HDMA_CH_1_SADDR (AT91_CAST(AT91_REG *) 0x400B0064) // (HDMA_CH_1) HDMA Channel Source Address Register +#define AT91C_HDMA_CH_1_DPIP (AT91_CAST(AT91_REG *) 0x400B0080) // (HDMA_CH_1) HDMA Channel Destination Picture in Picture Configuration Register +#define AT91C_HDMA_CH_1_CFG (AT91_CAST(AT91_REG *) 0x400B0078) // (HDMA_CH_1) HDMA Channel Configuration Register +#define AT91C_HDMA_CH_1_DADDR (AT91_CAST(AT91_REG *) 0x400B0068) // (HDMA_CH_1) HDMA Channel Destination Address Register +#define AT91C_HDMA_CH_1_CADDR (AT91_CAST(AT91_REG *) 0x400B0088) // (HDMA_CH_1) HDMA Reserved +#define AT91C_HDMA_CH_1_CTRLA (AT91_CAST(AT91_REG *) 0x400B0070) // (HDMA_CH_1) HDMA Channel Control A Register +// ========== Register definition for HDMA_CH_2 peripheral ========== +#define AT91C_HDMA_CH_2_BDSCR (AT91_CAST(AT91_REG *) 0x400B00AC) // (HDMA_CH_2) HDMA Reserved +#define AT91C_HDMA_CH_2_CTRLB (AT91_CAST(AT91_REG *) 0x400B009C) // (HDMA_CH_2) HDMA Channel Control B Register +#define AT91C_HDMA_CH_2_CADDR (AT91_CAST(AT91_REG *) 0x400B00B0) // (HDMA_CH_2) HDMA Reserved +#define AT91C_HDMA_CH_2_CFG (AT91_CAST(AT91_REG *) 0x400B00A0) // (HDMA_CH_2) HDMA Channel Configuration Register +#define AT91C_HDMA_CH_2_CTRLA (AT91_CAST(AT91_REG *) 0x400B0098) // (HDMA_CH_2) HDMA Channel Control A Register +#define AT91C_HDMA_CH_2_SADDR (AT91_CAST(AT91_REG *) 0x400B008C) // (HDMA_CH_2) HDMA Channel Source Address Register +#define AT91C_HDMA_CH_2_DPIP (AT91_CAST(AT91_REG *) 0x400B00A8) // (HDMA_CH_2) HDMA Channel Destination Picture in Picture Configuration Register +#define AT91C_HDMA_CH_2_DADDR (AT91_CAST(AT91_REG *) 0x400B0090) // (HDMA_CH_2) HDMA Channel Destination Address Register +#define AT91C_HDMA_CH_2_SPIP (AT91_CAST(AT91_REG *) 0x400B00A4) // (HDMA_CH_2) HDMA Channel Source Picture in Picture Configuration Register +#define AT91C_HDMA_CH_2_DSCR (AT91_CAST(AT91_REG *) 0x400B0094) // (HDMA_CH_2) HDMA Channel Descriptor Address Register +// ========== Register definition for HDMA_CH_3 peripheral ========== +#define AT91C_HDMA_CH_3_DSCR (AT91_CAST(AT91_REG *) 0x400B00BC) // (HDMA_CH_3) HDMA Channel Descriptor Address Register +#define AT91C_HDMA_CH_3_SADDR (AT91_CAST(AT91_REG *) 0x400B00B4) // (HDMA_CH_3) HDMA Channel Source Address Register +#define AT91C_HDMA_CH_3_BDSCR (AT91_CAST(AT91_REG *) 0x400B00D4) // (HDMA_CH_3) HDMA Reserved +#define AT91C_HDMA_CH_3_CTRLA (AT91_CAST(AT91_REG *) 0x400B00C0) // (HDMA_CH_3) HDMA Channel Control A Register +#define AT91C_HDMA_CH_3_DPIP (AT91_CAST(AT91_REG *) 0x400B00D0) // (HDMA_CH_3) HDMA Channel Destination Picture in Picture Configuration Register +#define AT91C_HDMA_CH_3_CTRLB (AT91_CAST(AT91_REG *) 0x400B00C4) // (HDMA_CH_3) HDMA Channel Control B Register +#define AT91C_HDMA_CH_3_SPIP (AT91_CAST(AT91_REG *) 0x400B00CC) // (HDMA_CH_3) HDMA Channel Source Picture in Picture Configuration Register +#define AT91C_HDMA_CH_3_CFG (AT91_CAST(AT91_REG *) 0x400B00C8) // (HDMA_CH_3) HDMA Channel Configuration Register +#define AT91C_HDMA_CH_3_CADDR (AT91_CAST(AT91_REG *) 0x400B00D8) // (HDMA_CH_3) HDMA Reserved +#define AT91C_HDMA_CH_3_DADDR (AT91_CAST(AT91_REG *) 0x400B00B8) // (HDMA_CH_3) HDMA Channel Destination Address Register +// ========== Register definition for HDMA peripheral ========== +#define AT91C_HDMA_SYNC (AT91_CAST(AT91_REG *) 0x400B0014) // (HDMA) HDMA Request Synchronization Register +#define AT91C_HDMA_VER (AT91_CAST(AT91_REG *) 0x400B01FC) // (HDMA) HDMA VERSION REGISTER +#define AT91C_HDMA_RSVD0 (AT91_CAST(AT91_REG *) 0x400B0034) // (HDMA) HDMA Reserved +#define AT91C_HDMA_CHSR (AT91_CAST(AT91_REG *) 0x400B0030) // (HDMA) HDMA Channel Handler Status Register +#define AT91C_HDMA_IPNAME2 (AT91_CAST(AT91_REG *) 0x400B01F4) // (HDMA) HDMA IPNAME2 REGISTER +#define AT91C_HDMA_EBCIMR (AT91_CAST(AT91_REG *) 0x400B0020) // (HDMA) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Mask Register +#define AT91C_HDMA_CHDR (AT91_CAST(AT91_REG *) 0x400B002C) // (HDMA) HDMA Channel Handler Disable Register +#define AT91C_HDMA_EN (AT91_CAST(AT91_REG *) 0x400B0004) // (HDMA) HDMA Controller Enable Register +#define AT91C_HDMA_GCFG (AT91_CAST(AT91_REG *) 0x400B0000) // (HDMA) HDMA Global Configuration Register +#define AT91C_HDMA_IPNAME1 (AT91_CAST(AT91_REG *) 0x400B01F0) // (HDMA) HDMA IPNAME1 REGISTER +#define AT91C_HDMA_LAST (AT91_CAST(AT91_REG *) 0x400B0010) // (HDMA) HDMA Software Last Transfer Flag Register +#define AT91C_HDMA_FEATURES (AT91_CAST(AT91_REG *) 0x400B01F8) // (HDMA) HDMA FEATURES REGISTER +#define AT91C_HDMA_CREQ (AT91_CAST(AT91_REG *) 0x400B000C) // (HDMA) HDMA Software Chunk Transfer Request Register +#define AT91C_HDMA_EBCIER (AT91_CAST(AT91_REG *) 0x400B0018) // (HDMA) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Interrupt Enable register +#define AT91C_HDMA_CHER (AT91_CAST(AT91_REG *) 0x400B0028) // (HDMA) HDMA Channel Handler Enable Register +#define AT91C_HDMA_ADDRSIZE (AT91_CAST(AT91_REG *) 0x400B01EC) // (HDMA) HDMA ADDRSIZE REGISTER +#define AT91C_HDMA_EBCISR (AT91_CAST(AT91_REG *) 0x400B0024) // (HDMA) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Status Register +#define AT91C_HDMA_SREQ (AT91_CAST(AT91_REG *) 0x400B0008) // (HDMA) HDMA Software Single Request Register +#define AT91C_HDMA_EBCIDR (AT91_CAST(AT91_REG *) 0x400B001C) // (HDMA) HDMA Error, Chained Buffer transfer completed and Buffer transfer completed Interrupt Disable register +#define AT91C_HDMA_RSVD1 (AT91_CAST(AT91_REG *) 0x400B0038) // (HDMA) HDMA Reserved + +// ***************************************************************************** +// PIO DEFINITIONS FOR AT91SAM3U4 +// ***************************************************************************** +#define AT91C_PIO_PA0 (1 << 0) // Pin Controlled by PA0 +#define AT91C_PA0_TIOB0 (AT91C_PIO_PA0) // +#define AT91C_PA0_SPI0_NPCS1 (AT91C_PIO_PA0) // +#define AT91C_PIO_PA1 (1 << 1) // Pin Controlled by PA1 +#define AT91C_PA1_TIOA0 (AT91C_PIO_PA1) // +#define AT91C_PA1_SPI0_NPCS2 (AT91C_PIO_PA1) // +#define AT91C_PIO_PA10 (1 << 10) // Pin Controlled by PA10 +#define AT91C_PA10_TWCK0 (AT91C_PIO_PA10) // +#define AT91C_PA10_PWML3 (AT91C_PIO_PA10) // +#define AT91C_PIO_PA11 (1 << 11) // Pin Controlled by PA11 +#define AT91C_PA11_DRXD (AT91C_PIO_PA11) // +#define AT91C_PIO_PA12 (1 << 12) // Pin Controlled by PA12 +#define AT91C_PA12_DTXD (AT91C_PIO_PA12) // +#define AT91C_PIO_PA13 (1 << 13) // Pin Controlled by PA13 +#define AT91C_PA13_SPI0_MISO (AT91C_PIO_PA13) // +#define AT91C_PIO_PA14 (1 << 14) // Pin Controlled by PA14 +#define AT91C_PA14_SPI0_MOSI (AT91C_PIO_PA14) // +#define AT91C_PIO_PA15 (1 << 15) // Pin Controlled by PA15 +#define AT91C_PA15_SPI0_SPCK (AT91C_PIO_PA15) // +#define AT91C_PA15_PWMH2 (AT91C_PIO_PA15) // +#define AT91C_PIO_PA16 (1 << 16) // Pin Controlled by PA16 +#define AT91C_PA16_SPI0_NPCS0 (AT91C_PIO_PA16) // +#define AT91C_PA16_NCS1 (AT91C_PIO_PA16) // +#define AT91C_PIO_PA17 (1 << 17) // Pin Controlled by PA17 +#define AT91C_PA17_SCK0 (AT91C_PIO_PA17) // +#define AT91C_PA17_ADTRG0 (AT91C_PIO_PA17) // +#define AT91C_PIO_PA18 (1 << 18) // Pin Controlled by PA18 +#define AT91C_PA18_TXD0 (AT91C_PIO_PA18) // +#define AT91C_PIO_PA19 (1 << 19) // Pin Controlled by PA19 +#define AT91C_PA19_RXD0 (AT91C_PIO_PA19) // +#define AT91C_PA19_SPI0_NPCS3 (AT91C_PIO_PA19) // +#define AT91C_PIO_PA2 (1 << 2) // Pin Controlled by PA2 +#define AT91C_PA2_TCLK0 (AT91C_PIO_PA2) // +#define AT91C_PA2_ADTRG1 (AT91C_PIO_PA2) // +#define AT91C_PIO_PA20 (1 << 20) // Pin Controlled by PA20 +#define AT91C_PA20_TXD1 (AT91C_PIO_PA20) // +#define AT91C_PA20_PWMH3 (AT91C_PIO_PA20) // +#define AT91C_PIO_PA21 (1 << 21) // Pin Controlled by PA21 +#define AT91C_PA21_RXD1 (AT91C_PIO_PA21) // +#define AT91C_PA21_PCK0 (AT91C_PIO_PA21) // +#define AT91C_PIO_PA22 (1 << 22) // Pin Controlled by PA22 +#define AT91C_PA22_TXD2 (AT91C_PIO_PA22) // +#define AT91C_PA22_RTS1 (AT91C_PIO_PA22) // +#define AT91C_PIO_PA23 (1 << 23) // Pin Controlled by PA23 +#define AT91C_PA23_RXD2 (AT91C_PIO_PA23) // +#define AT91C_PA23_CTS1 (AT91C_PIO_PA23) // +#define AT91C_PIO_PA24 (1 << 24) // Pin Controlled by PA24 +#define AT91C_PA24_TWD1 (AT91C_PIO_PA24) // +#define AT91C_PA24_SCK1 (AT91C_PIO_PA24) // +#define AT91C_PIO_PA25 (1 << 25) // Pin Controlled by PA25 +#define AT91C_PA25_TWCK1 (AT91C_PIO_PA25) // +#define AT91C_PA25_SCK2 (AT91C_PIO_PA25) // +#define AT91C_PIO_PA26 (1 << 26) // Pin Controlled by PA26 +#define AT91C_PA26_TD0 (AT91C_PIO_PA26) // +#define AT91C_PA26_TCLK2 (AT91C_PIO_PA26) // +#define AT91C_PIO_PA27 (1 << 27) // Pin Controlled by PA27 +#define AT91C_PA27_RD0 (AT91C_PIO_PA27) // +#define AT91C_PA27_PCK0 (AT91C_PIO_PA27) // +#define AT91C_PIO_PA28 (1 << 28) // Pin Controlled by PA28 +#define AT91C_PA28_TK0 (AT91C_PIO_PA28) // +#define AT91C_PA28_PWMH0 (AT91C_PIO_PA28) // +#define AT91C_PIO_PA29 (1 << 29) // Pin Controlled by PA29 +#define AT91C_PA29_RK0 (AT91C_PIO_PA29) // +#define AT91C_PA29_PWMH1 (AT91C_PIO_PA29) // +#define AT91C_PIO_PA3 (1 << 3) // Pin Controlled by PA3 +#define AT91C_PA3_MCI0_CK (AT91C_PIO_PA3) // +#define AT91C_PA3_PCK1 (AT91C_PIO_PA3) // +#define AT91C_PIO_PA30 (1 << 30) // Pin Controlled by PA30 +#define AT91C_PA30_TF0 (AT91C_PIO_PA30) // +#define AT91C_PA30_TIOA2 (AT91C_PIO_PA30) // +#define AT91C_PIO_PA31 (1 << 31) // Pin Controlled by PA31 +#define AT91C_PA31_RF0 (AT91C_PIO_PA31) // +#define AT91C_PA31_TIOB2 (AT91C_PIO_PA31) // +#define AT91C_PIO_PA4 (1 << 4) // Pin Controlled by PA4 +#define AT91C_PA4_MCI0_CDA (AT91C_PIO_PA4) // +#define AT91C_PA4_PWMH0 (AT91C_PIO_PA4) // +#define AT91C_PIO_PA5 (1 << 5) // Pin Controlled by PA5 +#define AT91C_PA5_MCI0_DA0 (AT91C_PIO_PA5) // +#define AT91C_PA5_PWMH1 (AT91C_PIO_PA5) // +#define AT91C_PIO_PA6 (1 << 6) // Pin Controlled by PA6 +#define AT91C_PA6_MCI0_DA1 (AT91C_PIO_PA6) // +#define AT91C_PA6_PWMH2 (AT91C_PIO_PA6) // +#define AT91C_PIO_PA7 (1 << 7) // Pin Controlled by PA7 +#define AT91C_PA7_MCI0_DA2 (AT91C_PIO_PA7) // +#define AT91C_PA7_PWML0 (AT91C_PIO_PA7) // +#define AT91C_PIO_PA8 (1 << 8) // Pin Controlled by PA8 +#define AT91C_PA8_MCI0_DA3 (AT91C_PIO_PA8) // +#define AT91C_PA8_PWML1 (AT91C_PIO_PA8) // +#define AT91C_PIO_PA9 (1 << 9) // Pin Controlled by PA9 +#define AT91C_PA9_TWD0 (AT91C_PIO_PA9) // +#define AT91C_PA9_PWML2 (AT91C_PIO_PA9) // +#define AT91C_PIO_PB0 (1 << 0) // Pin Controlled by PB0 +#define AT91C_PB0_PWMH0 (AT91C_PIO_PB0) // +#define AT91C_PB0_A2 (AT91C_PIO_PB0) // +#define AT91C_PIO_PB1 (1 << 1) // Pin Controlled by PB1 +#define AT91C_PB1_PWMH1 (AT91C_PIO_PB1) // +#define AT91C_PB1_A3 (AT91C_PIO_PB1) // +#define AT91C_PIO_PB10 (1 << 10) // Pin Controlled by PB10 +#define AT91C_PB10_D1 (AT91C_PIO_PB10) // +#define AT91C_PB10_DSR0 (AT91C_PIO_PB10) // +#define AT91C_PIO_PB11 (1 << 11) // Pin Controlled by PB11 +#define AT91C_PB11_D2 (AT91C_PIO_PB11) // +#define AT91C_PB11_DCD0 (AT91C_PIO_PB11) // +#define AT91C_PIO_PB12 (1 << 12) // Pin Controlled by PB12 +#define AT91C_PB12_D3 (AT91C_PIO_PB12) // +#define AT91C_PB12_RI0 (AT91C_PIO_PB12) // +#define AT91C_PIO_PB13 (1 << 13) // Pin Controlled by PB13 +#define AT91C_PB13_D4 (AT91C_PIO_PB13) // +#define AT91C_PB13_PWMH0 (AT91C_PIO_PB13) // +#define AT91C_PIO_PB14 (1 << 14) // Pin Controlled by PB14 +#define AT91C_PB14_D5 (AT91C_PIO_PB14) // +#define AT91C_PB14_PWMH1 (AT91C_PIO_PB14) // +#define AT91C_PIO_PB15 (1 << 15) // Pin Controlled by PB15 +#define AT91C_PB15_D6 (AT91C_PIO_PB15) // +#define AT91C_PB15_PWMH2 (AT91C_PIO_PB15) // +#define AT91C_PIO_PB16 (1 << 16) // Pin Controlled by PB16 +#define AT91C_PB16_D7 (AT91C_PIO_PB16) // +#define AT91C_PB16_PWMH3 (AT91C_PIO_PB16) // +#define AT91C_PIO_PB17 (1 << 17) // Pin Controlled by PB17 +#define AT91C_PB17_NANDOE (AT91C_PIO_PB17) // +#define AT91C_PB17_PWML0 (AT91C_PIO_PB17) // +#define AT91C_PIO_PB18 (1 << 18) // Pin Controlled by PB18 +#define AT91C_PB18_NANDWE (AT91C_PIO_PB18) // +#define AT91C_PB18_PWML1 (AT91C_PIO_PB18) // +#define AT91C_PIO_PB19 (1 << 19) // Pin Controlled by PB19 +#define AT91C_PB19_NRD (AT91C_PIO_PB19) // +#define AT91C_PB19_PWML2 (AT91C_PIO_PB19) // +#define AT91C_PIO_PB2 (1 << 2) // Pin Controlled by PB2 +#define AT91C_PB2_PWMH2 (AT91C_PIO_PB2) // +#define AT91C_PB2_A4 (AT91C_PIO_PB2) // +#define AT91C_PIO_PB20 (1 << 20) // Pin Controlled by PB20 +#define AT91C_PB20_NCS0 (AT91C_PIO_PB20) // +#define AT91C_PB20_PWML3 (AT91C_PIO_PB20) // +#define AT91C_PIO_PB21 (1 << 21) // Pin Controlled by PB21 +#define AT91C_PB21_A21_NANDALE (AT91C_PIO_PB21) // +#define AT91C_PB21_RTS2 (AT91C_PIO_PB21) // +#define AT91C_PIO_PB22 (1 << 22) // Pin Controlled by PB22 +#define AT91C_PB22_A22_NANDCLE (AT91C_PIO_PB22) // +#define AT91C_PB22_CTS2 (AT91C_PIO_PB22) // +#define AT91C_PIO_PB23 (1 << 23) // Pin Controlled by PB23 +#define AT91C_PB23_NWR0_NWE (AT91C_PIO_PB23) // +#define AT91C_PB23_PCK2 (AT91C_PIO_PB23) // +#define AT91C_PIO_PB24 (1 << 24) // Pin Controlled by PB24 +#define AT91C_PB24_NANDRDY (AT91C_PIO_PB24) // +#define AT91C_PB24_PCK1 (AT91C_PIO_PB24) // +#define AT91C_PIO_PB25 (1 << 25) // Pin Controlled by PB25 +#define AT91C_PB25_D8 (AT91C_PIO_PB25) // +#define AT91C_PB25_PWML0 (AT91C_PIO_PB25) // +#define AT91C_PIO_PB26 (1 << 26) // Pin Controlled by PB26 +#define AT91C_PB26_D9 (AT91C_PIO_PB26) // +#define AT91C_PB26_PWML1 (AT91C_PIO_PB26) // +#define AT91C_PIO_PB27 (1 << 27) // Pin Controlled by PB27 +#define AT91C_PB27_D10 (AT91C_PIO_PB27) // +#define AT91C_PB27_PWML2 (AT91C_PIO_PB27) // +#define AT91C_PIO_PB28 (1 << 28) // Pin Controlled by PB28 +#define AT91C_PB28_D11 (AT91C_PIO_PB28) // +#define AT91C_PB28_PWML3 (AT91C_PIO_PB28) // +#define AT91C_PIO_PB29 (1 << 29) // Pin Controlled by PB29 +#define AT91C_PB29_D12 (AT91C_PIO_PB29) // +#define AT91C_PIO_PB3 (1 << 3) // Pin Controlled by PB3 +#define AT91C_PB3_PWMH3 (AT91C_PIO_PB3) // +#define AT91C_PB3_A5 (AT91C_PIO_PB3) // +#define AT91C_PIO_PB30 (1 << 30) // Pin Controlled by PB30 +#define AT91C_PB30_D13 (AT91C_PIO_PB30) // +#define AT91C_PIO_PB31 (1 << 31) // Pin Controlled by PB31 +#define AT91C_PB31_D14 (AT91C_PIO_PB31) // +#define AT91C_PIO_PB4 (1 << 4) // Pin Controlled by PB4 +#define AT91C_PB4_TCLK1 (AT91C_PIO_PB4) // +#define AT91C_PB4_A6 (AT91C_PIO_PB4) // +#define AT91C_PIO_PB5 (1 << 5) // Pin Controlled by PB5 +#define AT91C_PB5_TIOA1 (AT91C_PIO_PB5) // +#define AT91C_PB5_A7 (AT91C_PIO_PB5) // +#define AT91C_PIO_PB6 (1 << 6) // Pin Controlled by PB6 +#define AT91C_PB6_TIOB1 (AT91C_PIO_PB6) // +#define AT91C_PB6_D15 (AT91C_PIO_PB6) // +#define AT91C_PIO_PB7 (1 << 7) // Pin Controlled by PB7 +#define AT91C_PB7_RTS0 (AT91C_PIO_PB7) // +#define AT91C_PB7_A0_NBS0 (AT91C_PIO_PB7) // +#define AT91C_PIO_PB8 (1 << 8) // Pin Controlled by PB8 +#define AT91C_PB8_CTS0 (AT91C_PIO_PB8) // +#define AT91C_PB8_A1 (AT91C_PIO_PB8) // +#define AT91C_PIO_PB9 (1 << 9) // Pin Controlled by PB9 +#define AT91C_PB9_D0 (AT91C_PIO_PB9) // +#define AT91C_PB9_DTR0 (AT91C_PIO_PB9) // +#define AT91C_PIO_PC0 (1 << 0) // Pin Controlled by PC0 +#define AT91C_PC0_A2 (AT91C_PIO_PC0) // +#define AT91C_PIO_PC1 (1 << 1) // Pin Controlled by PC1 +#define AT91C_PC1_A3 (AT91C_PIO_PC1) // +#define AT91C_PIO_PC10 (1 << 10) // Pin Controlled by PC10 +#define AT91C_PC10_A12 (AT91C_PIO_PC10) // +#define AT91C_PC10_CTS3 (AT91C_PIO_PC10) // +#define AT91C_PIO_PC11 (1 << 11) // Pin Controlled by PC11 +#define AT91C_PC11_A13 (AT91C_PIO_PC11) // +#define AT91C_PC11_RTS3 (AT91C_PIO_PC11) // +#define AT91C_PIO_PC12 (1 << 12) // Pin Controlled by PC12 +#define AT91C_PC12_NCS1 (AT91C_PIO_PC12) // +#define AT91C_PC12_TXD3 (AT91C_PIO_PC12) // +#define AT91C_PIO_PC13 (1 << 13) // Pin Controlled by PC13 +#define AT91C_PC13_A2 (AT91C_PIO_PC13) // +#define AT91C_PC13_RXD3 (AT91C_PIO_PC13) // +#define AT91C_PIO_PC14 (1 << 14) // Pin Controlled by PC14 +#define AT91C_PC14_A3 (AT91C_PIO_PC14) // +#define AT91C_PC14_SPI0_NPCS2 (AT91C_PIO_PC14) // +#define AT91C_PIO_PC15 (1 << 15) // Pin Controlled by PC15 +#define AT91C_PC15_NWR1_NBS1 (AT91C_PIO_PC15) // +#define AT91C_PIO_PC16 (1 << 16) // Pin Controlled by PC16 +#define AT91C_PC16_NCS2 (AT91C_PIO_PC16) // +#define AT91C_PC16_PWML3 (AT91C_PIO_PC16) // +#define AT91C_PIO_PC17 (1 << 17) // Pin Controlled by PC17 +#define AT91C_PC17_NCS3 (AT91C_PIO_PC17) // +#define AT91C_PC17_A24 (AT91C_PIO_PC17) // +#define AT91C_PIO_PC18 (1 << 18) // Pin Controlled by PC18 +#define AT91C_PC18_NWAIT (AT91C_PIO_PC18) // +#define AT91C_PIO_PC19 (1 << 19) // Pin Controlled by PC19 +#define AT91C_PC19_SCK3 (AT91C_PIO_PC19) // +#define AT91C_PC19_NPCS1 (AT91C_PIO_PC19) // +#define AT91C_PIO_PC2 (1 << 2) // Pin Controlled by PC2 +#define AT91C_PC2_A4 (AT91C_PIO_PC2) // +#define AT91C_PIO_PC20 (1 << 20) // Pin Controlled by PC20 +#define AT91C_PC20_A14 (AT91C_PIO_PC20) // +#define AT91C_PIO_PC21 (1 << 21) // Pin Controlled by PC21 +#define AT91C_PC21_A15 (AT91C_PIO_PC21) // +#define AT91C_PIO_PC22 (1 << 22) // Pin Controlled by PC22 +#define AT91C_PC22_A16 (AT91C_PIO_PC22) // +#define AT91C_PIO_PC23 (1 << 23) // Pin Controlled by PC23 +#define AT91C_PC23_A17 (AT91C_PIO_PC23) // +#define AT91C_PIO_PC24 (1 << 24) // Pin Controlled by PC24 +#define AT91C_PC24_A18 (AT91C_PIO_PC24) // +#define AT91C_PC24_PWMH0 (AT91C_PIO_PC24) // +#define AT91C_PIO_PC25 (1 << 25) // Pin Controlled by PC25 +#define AT91C_PC25_A19 (AT91C_PIO_PC25) // +#define AT91C_PC25_PWMH1 (AT91C_PIO_PC25) // +#define AT91C_PIO_PC26 (1 << 26) // Pin Controlled by PC26 +#define AT91C_PC26_A20 (AT91C_PIO_PC26) // +#define AT91C_PC26_PWMH2 (AT91C_PIO_PC26) // +#define AT91C_PIO_PC27 (1 << 27) // Pin Controlled by PC27 +#define AT91C_PC27_A23 (AT91C_PIO_PC27) // +#define AT91C_PC27_PWMH3 (AT91C_PIO_PC27) // +#define AT91C_PIO_PC28 (1 << 28) // Pin Controlled by PC28 +#define AT91C_PC28_A24 (AT91C_PIO_PC28) // +#define AT91C_PC28_MCI0_DA4 (AT91C_PIO_PC28) // +#define AT91C_PIO_PC29 (1 << 29) // Pin Controlled by PC29 +#define AT91C_PC29_PWML0 (AT91C_PIO_PC29) // +#define AT91C_PC29_MCI0_DA5 (AT91C_PIO_PC29) // +#define AT91C_PIO_PC3 (1 << 3) // Pin Controlled by PC3 +#define AT91C_PC3_A5 (AT91C_PIO_PC3) // +#define AT91C_PC3_SPI0_NPCS1 (AT91C_PIO_PC3) // +#define AT91C_PIO_PC30 (1 << 30) // Pin Controlled by PC30 +#define AT91C_PC30_PWML1 (AT91C_PIO_PC30) // +#define AT91C_PC30_MCI0_DA6 (AT91C_PIO_PC30) // +#define AT91C_PIO_PC31 (1 << 31) // Pin Controlled by PC31 +#define AT91C_PC31_PWML2 (AT91C_PIO_PC31) // +#define AT91C_PC31_MCI0_DA7 (AT91C_PIO_PC31) // +#define AT91C_PIO_PC4 (1 << 4) // Pin Controlled by PC4 +#define AT91C_PC4_A6 (AT91C_PIO_PC4) // +#define AT91C_PC4_SPI0_NPCS2 (AT91C_PIO_PC4) // +#define AT91C_PIO_PC5 (1 << 5) // Pin Controlled by PC5 +#define AT91C_PC5_A7 (AT91C_PIO_PC5) // +#define AT91C_PC5_SPI0_NPCS3 (AT91C_PIO_PC5) // +#define AT91C_PIO_PC6 (1 << 6) // Pin Controlled by PC6 +#define AT91C_PC6_A8 (AT91C_PIO_PC6) // +#define AT91C_PC6_PWML0 (AT91C_PIO_PC6) // +#define AT91C_PIO_PC7 (1 << 7) // Pin Controlled by PC7 +#define AT91C_PC7_A9 (AT91C_PIO_PC7) // +#define AT91C_PC7_PWML1 (AT91C_PIO_PC7) // +#define AT91C_PIO_PC8 (1 << 8) // Pin Controlled by PC8 +#define AT91C_PC8_A10 (AT91C_PIO_PC8) // +#define AT91C_PC8_PWML2 (AT91C_PIO_PC8) // +#define AT91C_PIO_PC9 (1 << 9) // Pin Controlled by PC9 +#define AT91C_PC9_A11 (AT91C_PIO_PC9) // +#define AT91C_PC9_PWML3 (AT91C_PIO_PC9) // + +// ***************************************************************************** +// PERIPHERAL ID DEFINITIONS FOR AT91SAM3U4 +// ***************************************************************************** +#define AT91C_ID_SUPC ( 0) // SUPPLY CONTROLLER +#define AT91C_ID_RSTC ( 1) // RESET CONTROLLER +#define AT91C_ID_RTC ( 2) // REAL TIME CLOCK +#define AT91C_ID_RTT ( 3) // REAL TIME TIMER +#define AT91C_ID_WDG ( 4) // WATCHDOG TIMER +#define AT91C_ID_PMC ( 5) // PMC +#define AT91C_ID_EFC0 ( 6) // EFC0 +#define AT91C_ID_EFC1 ( 7) // EFC1 +#define AT91C_ID_DBGU ( 8) // DBGU +#define AT91C_ID_HSMC4 ( 9) // HSMC4 +#define AT91C_ID_PIOA (10) // Parallel IO Controller A +#define AT91C_ID_PIOB (11) // Parallel IO Controller B +#define AT91C_ID_PIOC (12) // Parallel IO Controller C +#define AT91C_ID_US0 (13) // USART 0 +#define AT91C_ID_US1 (14) // USART 1 +#define AT91C_ID_US2 (15) // USART 2 +#define AT91C_ID_US3 (16) // USART 3 +#define AT91C_ID_MCI0 (17) // Multimedia Card Interface +#define AT91C_ID_TWI0 (18) // TWI 0 +#define AT91C_ID_TWI1 (19) // TWI 1 +#define AT91C_ID_SPI0 (20) // Serial Peripheral Interface +#define AT91C_ID_SSC0 (21) // Serial Synchronous Controller 0 +#define AT91C_ID_TC0 (22) // Timer Counter 0 +#define AT91C_ID_TC1 (23) // Timer Counter 1 +#define AT91C_ID_TC2 (24) // Timer Counter 2 +#define AT91C_ID_PWMC (25) // Pulse Width Modulation Controller +#define AT91C_ID_ADCC0 (26) // ADC controller0 +#define AT91C_ID_ADCC1 (27) // ADC controller1 +#define AT91C_ID_HDMA (28) // HDMA +#define AT91C_ID_UDPHS (29) // USB Device High Speed +#define AT91C_ALL_INT (0x3FFFFFFF) // ALL VALID INTERRUPTS + +// ***************************************************************************** +// BASE ADDRESS DEFINITIONS FOR AT91SAM3U4 +// ***************************************************************************** +#define AT91C_BASE_SYS (AT91_CAST(AT91PS_SYS) 0x400E0000) // (SYS) Base Address +#define AT91C_BASE_HSMC4_CS0 (AT91_CAST(AT91PS_HSMC4_CS) 0x400E0070) // (HSMC4_CS0) Base Address +#define AT91C_BASE_HSMC4_CS1 (AT91_CAST(AT91PS_HSMC4_CS) 0x400E0084) // (HSMC4_CS1) Base Address +#define AT91C_BASE_HSMC4_CS2 (AT91_CAST(AT91PS_HSMC4_CS) 0x400E0098) // (HSMC4_CS2) Base Address +#define AT91C_BASE_HSMC4_CS3 (AT91_CAST(AT91PS_HSMC4_CS) 0x400E00AC) // (HSMC4_CS3) Base Address +#define AT91C_BASE_HSMC4_NFC (AT91_CAST(AT91PS_HSMC4_CS) 0x400E00FC) // (HSMC4_NFC) Base Address +#define AT91C_BASE_HSMC4 (AT91_CAST(AT91PS_HSMC4) 0x400E0000) // (HSMC4) Base Address +#define AT91C_BASE_MATRIX (AT91_CAST(AT91PS_HMATRIX2) 0x400E0200) // (MATRIX) Base Address +#define AT91C_BASE_NVIC (AT91_CAST(AT91PS_NVIC) 0xE000E000) // (NVIC) Base Address +#define AT91C_BASE_MPU (AT91_CAST(AT91PS_MPU) 0xE000ED90) // (MPU) Base Address +#define AT91C_BASE_CM3 (AT91_CAST(AT91PS_CM3) 0xE000ED00) // (CM3) Base Address +#define AT91C_BASE_PDC_DBGU (AT91_CAST(AT91PS_PDC) 0x400E0700) // (PDC_DBGU) Base Address +#define AT91C_BASE_DBGU (AT91_CAST(AT91PS_DBGU) 0x400E0600) // (DBGU) Base Address +#define AT91C_BASE_PIOA (AT91_CAST(AT91PS_PIO) 0x400E0C00) // (PIOA) Base Address +#define AT91C_BASE_PIOB (AT91_CAST(AT91PS_PIO) 0x400E0E00) // (PIOB) Base Address +#define AT91C_BASE_PIOC (AT91_CAST(AT91PS_PIO) 0x400E1000) // (PIOC) Base Address +#define AT91C_BASE_PMC (AT91_CAST(AT91PS_PMC) 0x400E0400) // (PMC) Base Address +#define AT91C_BASE_CKGR (AT91_CAST(AT91PS_CKGR) 0x400E041C) // (CKGR) Base Address +#define AT91C_BASE_RSTC (AT91_CAST(AT91PS_RSTC) 0x400E1200) // (RSTC) Base Address +#define AT91C_BASE_SUPC (AT91_CAST(AT91PS_SUPC) 0x400E1210) // (SUPC) Base Address +#define AT91C_BASE_RTTC (AT91_CAST(AT91PS_RTTC) 0x400E1230) // (RTTC) Base Address +#define AT91C_BASE_WDTC (AT91_CAST(AT91PS_WDTC) 0x400E1250) // (WDTC) Base Address +#define AT91C_BASE_RTC (AT91_CAST(AT91PS_RTC) 0x400E1260) // (RTC) Base Address +#define AT91C_BASE_ADC0 (AT91_CAST(AT91PS_ADC) 0x400A8000) // (ADC0) Base Address +#define AT91C_BASE_ADC1 (AT91_CAST(AT91PS_ADC) 0x400AC000) // (ADC1) Base Address +#define AT91C_BASE_TC0 (AT91_CAST(AT91PS_TC) 0x40080000) // (TC0) Base Address +#define AT91C_BASE_TC1 (AT91_CAST(AT91PS_TC) 0x40080040) // (TC1) Base Address +#define AT91C_BASE_TC2 (AT91_CAST(AT91PS_TC) 0x40080080) // (TC2) Base Address +#define AT91C_BASE_TCB0 (AT91_CAST(AT91PS_TCB) 0x40080000) // (TCB0) Base Address +#define AT91C_BASE_TCB1 (AT91_CAST(AT91PS_TCB) 0x40080040) // (TCB1) Base Address +#define AT91C_BASE_TCB2 (AT91_CAST(AT91PS_TCB) 0x40080080) // (TCB2) Base Address +#define AT91C_BASE_EFC0 (AT91_CAST(AT91PS_EFC) 0x400E0800) // (EFC0) Base Address +#define AT91C_BASE_EFC1 (AT91_CAST(AT91PS_EFC) 0x400E0A00) // (EFC1) Base Address +#define AT91C_BASE_MCI0 (AT91_CAST(AT91PS_MCI) 0x40000000) // (MCI0) Base Address +#define AT91C_BASE_PDC_TWI0 (AT91_CAST(AT91PS_PDC) 0x40084100) // (PDC_TWI0) Base Address +#define AT91C_BASE_PDC_TWI1 (AT91_CAST(AT91PS_PDC) 0x40088100) // (PDC_TWI1) Base Address +#define AT91C_BASE_TWI0 (AT91_CAST(AT91PS_TWI) 0x40084000) // (TWI0) Base Address +#define AT91C_BASE_TWI1 (AT91_CAST(AT91PS_TWI) 0x40088000) // (TWI1) Base Address +#define AT91C_BASE_PDC_US0 (AT91_CAST(AT91PS_PDC) 0x40090100) // (PDC_US0) Base Address +#define AT91C_BASE_US0 (AT91_CAST(AT91PS_USART) 0x40090000) // (US0) Base Address +#define AT91C_BASE_PDC_US1 (AT91_CAST(AT91PS_PDC) 0x40094100) // (PDC_US1) Base Address +#define AT91C_BASE_US1 (AT91_CAST(AT91PS_USART) 0x40094000) // (US1) Base Address +#define AT91C_BASE_PDC_US2 (AT91_CAST(AT91PS_PDC) 0x40098100) // (PDC_US2) Base Address +#define AT91C_BASE_US2 (AT91_CAST(AT91PS_USART) 0x40098000) // (US2) Base Address +#define AT91C_BASE_PDC_US3 (AT91_CAST(AT91PS_PDC) 0x4009C100) // (PDC_US3) Base Address +#define AT91C_BASE_US3 (AT91_CAST(AT91PS_USART) 0x4009C000) // (US3) Base Address +#define AT91C_BASE_PDC_SSC0 (AT91_CAST(AT91PS_PDC) 0x40004100) // (PDC_SSC0) Base Address +#define AT91C_BASE_SSC0 (AT91_CAST(AT91PS_SSC) 0x40004000) // (SSC0) Base Address +#define AT91C_BASE_PDC_PWMC (AT91_CAST(AT91PS_PDC) 0x4008C100) // (PDC_PWMC) Base Address +#define AT91C_BASE_PWMC_CH0 (AT91_CAST(AT91PS_PWMC_CH) 0x4008C200) // (PWMC_CH0) Base Address +#define AT91C_BASE_PWMC_CH1 (AT91_CAST(AT91PS_PWMC_CH) 0x4008C220) // (PWMC_CH1) Base Address +#define AT91C_BASE_PWMC_CH2 (AT91_CAST(AT91PS_PWMC_CH) 0x4008C240) // (PWMC_CH2) Base Address +#define AT91C_BASE_PWMC_CH3 (AT91_CAST(AT91PS_PWMC_CH) 0x4008C260) // (PWMC_CH3) Base Address +#define AT91C_BASE_PWMC (AT91_CAST(AT91PS_PWMC) 0x4008C000) // (PWMC) Base Address +#define AT91C_BASE_SPI0 (AT91_CAST(AT91PS_SPI) 0x40008000) // (SPI0) Base Address +#define AT91C_BASE_UDPHS_EPTFIFO (AT91_CAST(AT91PS_UDPHS_EPTFIFO) 0x20180000) // (UDPHS_EPTFIFO) Base Address +#define AT91C_BASE_UDPHS_EPT_0 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A4100) // (UDPHS_EPT_0) Base Address +#define AT91C_BASE_UDPHS_EPT_1 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A4120) // (UDPHS_EPT_1) Base Address +#define AT91C_BASE_UDPHS_EPT_2 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A4140) // (UDPHS_EPT_2) Base Address +#define AT91C_BASE_UDPHS_EPT_3 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A4160) // (UDPHS_EPT_3) Base Address +#define AT91C_BASE_UDPHS_EPT_4 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A4180) // (UDPHS_EPT_4) Base Address +#define AT91C_BASE_UDPHS_EPT_5 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A41A0) // (UDPHS_EPT_5) Base Address +#define AT91C_BASE_UDPHS_EPT_6 (AT91_CAST(AT91PS_UDPHS_EPT) 0x400A41C0) // (UDPHS_EPT_6) Base Address +#define AT91C_BASE_UDPHS_DMA_1 (AT91_CAST(AT91PS_UDPHS_DMA) 0x400A4310) // (UDPHS_DMA_1) Base Address +#define AT91C_BASE_UDPHS_DMA_2 (AT91_CAST(AT91PS_UDPHS_DMA) 0x400A4320) // (UDPHS_DMA_2) Base Address +#define AT91C_BASE_UDPHS_DMA_3 (AT91_CAST(AT91PS_UDPHS_DMA) 0x400A4330) // (UDPHS_DMA_3) Base Address +#define AT91C_BASE_UDPHS_DMA_4 (AT91_CAST(AT91PS_UDPHS_DMA) 0x400A4340) // (UDPHS_DMA_4) Base Address +#define AT91C_BASE_UDPHS_DMA_5 (AT91_CAST(AT91PS_UDPHS_DMA) 0x400A4350) // (UDPHS_DMA_5) Base Address +#define AT91C_BASE_UDPHS_DMA_6 (AT91_CAST(AT91PS_UDPHS_DMA) 0x400A4360) // (UDPHS_DMA_6) Base Address +#define AT91C_BASE_UDPHS (AT91_CAST(AT91PS_UDPHS) 0x400A4000) // (UDPHS) Base Address +#define AT91C_BASE_HDMA_CH_0 (AT91_CAST(AT91PS_HDMA_CH) 0x400B003C) // (HDMA_CH_0) Base Address +#define AT91C_BASE_HDMA_CH_1 (AT91_CAST(AT91PS_HDMA_CH) 0x400B0064) // (HDMA_CH_1) Base Address +#define AT91C_BASE_HDMA_CH_2 (AT91_CAST(AT91PS_HDMA_CH) 0x400B008C) // (HDMA_CH_2) Base Address +#define AT91C_BASE_HDMA_CH_3 (AT91_CAST(AT91PS_HDMA_CH) 0x400B00B4) // (HDMA_CH_3) Base Address +#define AT91C_BASE_HDMA (AT91_CAST(AT91PS_HDMA) 0x400B0000) // (HDMA) Base Address + +// ***************************************************************************** +// MEMORY MAPPING DEFINITIONS FOR AT91SAM3U4 +// ***************************************************************************** +// ITCM +#define AT91C_ITCM (0x00100000) // Maximum ITCM Area base address +#define AT91C_ITCM_SIZE (0x00010000) // Maximum ITCM Area size in byte (64 Kbytes) +// DTCM +#define AT91C_DTCM (0x00200000) // Maximum DTCM Area base address +#define AT91C_DTCM_SIZE (0x00010000) // Maximum DTCM Area size in byte (64 Kbytes) +// IRAM +#define AT91C_IRAM (0x20000000) // Maximum Internal SRAM base address +#define AT91C_IRAM_SIZE (0x00010000) // Maximum Internal SRAM size in byte (64 Kbytes) +// IRAM_MIN +#define AT91C_IRAM_MIN (0x00300000) // Minimum Internal RAM base address +#define AT91C_IRAM_MIN_SIZE (0x00004000) // Minimum Internal RAM size in byte (16 Kbytes) +// IROM +#define AT91C_IROM (0x00180000) // Internal ROM base address +#define AT91C_IROM_SIZE (0x00008000) // Internal ROM size in byte (32 Kbytes) +// IFLASH0 +#define AT91C_IFLASH0 (0x00080000) // Maximum IFLASH Area : 128Kbyte base address +#define AT91C_IFLASH0_SIZE (0x00020000) // Maximum IFLASH Area : 128Kbyte size in byte (128 Kbytes) +#define AT91C_IFLASH0_PAGE_SIZE (256) // Maximum IFLASH Area : 128Kbyte Page Size: 256 bytes +#define AT91C_IFLASH0_LOCK_REGION_SIZE (8192) // Maximum IFLASH Area : 128Kbyte Lock Region Size: 8 Kbytes +#define AT91C_IFLASH0_NB_OF_PAGES (512) // Maximum IFLASH Area : 128Kbyte Number of Pages: 512 bytes +#define AT91C_IFLASH0_NB_OF_LOCK_BITS (16) // Maximum IFLASH Area : 128Kbyte Number of Lock Bits: 32 bytes +// IFLASH1 +#define AT91C_IFLASH1 (0x0100000) // Maximum IFLASH Area : 128Kbyte base address +#define AT91C_IFLASH1_SIZE (0x00020000) // Maximum IFLASH Area : 128Kbyte size in byte (128 Kbytes) +#define AT91C_IFLASH1_PAGE_SIZE (256) // Maximum IFLASH Area : 128Kbyte Page Size: 256 bytes +#define AT91C_IFLASH1_LOCK_REGION_SIZE (8192) // Maximum IFLASH Area : 128Kbyte Lock Region Size: 8 Kbytes +#define AT91C_IFLASH1_NB_OF_PAGES (512) // Maximum IFLASH Area : 128Kbyte Number of Pages: 512 bytes +#define AT91C_IFLASH1_NB_OF_LOCK_BITS (16) // Maximum IFLASH Area : 128Kbyte Number of Lock Bits: 32 bytes +// EBI_CS0 +#define AT91C_EBI_CS0 (0x10000000) // EBI Chip Select 0 base address +#define AT91C_EBI_CS0_SIZE (0x10000000) // EBI Chip Select 0 size in byte (262144 Kbytes) +// EBI_CS1 +#define AT91C_EBI_CS1 (0x20000000) // EBI Chip Select 1 base address +#define AT91C_EBI_CS1_SIZE (0x10000000) // EBI Chip Select 1 size in byte (262144 Kbytes) +// EBI_SDRAM +#define AT91C_EBI_SDRAM (0x20000000) // SDRAM on EBI Chip Select 1 base address +#define AT91C_EBI_SDRAM_SIZE (0x10000000) // SDRAM on EBI Chip Select 1 size in byte (262144 Kbytes) +// EBI_SDRAM_16BIT +#define AT91C_EBI_SDRAM_16BIT (0x20000000) // SDRAM on EBI Chip Select 1 base address +#define AT91C_EBI_SDRAM_16BIT_SIZE (0x02000000) // SDRAM on EBI Chip Select 1 size in byte (32768 Kbytes) +// EBI_SDRAM_32BIT +#define AT91C_EBI_SDRAM_32BIT (0x20000000) // SDRAM on EBI Chip Select 1 base address +#define AT91C_EBI_SDRAM_32BIT_SIZE (0x04000000) // SDRAM on EBI Chip Select 1 size in byte (65536 Kbytes) +// EBI_CS2 +#define AT91C_EBI_CS2 (0x30000000) // EBI Chip Select 2 base address +#define AT91C_EBI_CS2_SIZE (0x10000000) // EBI Chip Select 2 size in byte (262144 Kbytes) +// EBI_CS3 +#define AT91C_EBI_CS3 (0x40000000) // EBI Chip Select 3 base address +#define AT91C_EBI_CS3_SIZE (0x10000000) // EBI Chip Select 3 size in byte (262144 Kbytes) +// EBI_SM +#define AT91C_EBI_SM (0x40000000) // NANDFLASH on EBI Chip Select 3 base address +#define AT91C_EBI_SM_SIZE (0x10000000) // NANDFLASH on EBI Chip Select 3 size in byte (262144 Kbytes) +// EBI_CS4 +#define AT91C_EBI_CS4 (0x50000000) // EBI Chip Select 4 base address +#define AT91C_EBI_CS4_SIZE (0x10000000) // EBI Chip Select 4 size in byte (262144 Kbytes) +// EBI_CF0 +#define AT91C_EBI_CF0 (0x50000000) // CompactFlash 0 on EBI Chip Select 4 base address +#define AT91C_EBI_CF0_SIZE (0x10000000) // CompactFlash 0 on EBI Chip Select 4 size in byte (262144 Kbytes) +// EBI_CS5 +#define AT91C_EBI_CS5 (0x60000000) // EBI Chip Select 5 base address +#define AT91C_EBI_CS5_SIZE (0x10000000) // EBI Chip Select 5 size in byte (262144 Kbytes) +// EBI_CF1 +#define AT91C_EBI_CF1 (0x60000000) // CompactFlash 1 on EBIChip Select 5 base address +#define AT91C_EBI_CF1_SIZE (0x10000000) // CompactFlash 1 on EBIChip Select 5 size in byte (262144 Kbytes) + +#endif diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u4/chip.h b/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u4/chip.h new file mode 100644 index 000000000..59f048a00 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u4/chip.h @@ -0,0 +1,99 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// !Purpose +/// +/// Definition of AT91SAM3U4 characteristics and features +/// +/// !Usage +/// -# For ARM core feature, see "AT91SAM3U4 - ARM core features". +/// -# For IP features, see "AT91SAM3U4 - IP features". +/// -# For misc, see "AT91SAM3U4 - Misc". +//------------------------------------------------------------------------------ + +#ifndef CHIP_H +#define CHIP_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "AT91SAM3U4 - ARM core features" +/// This page lists several characteristics related to the ARM core +/// + +//ARM core features + +/// ARM core definition. +#define cortexm3 + +/// family definition. +#define at91sam3u + +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "AT91SAM3U4 - IP features" +/// This page lists several characteristics related to the embedded IP +/// + +//IP FEATURES + +// EFC GPNVM number +#define CHIP_EFC_NUM_GPNVMS 3 + +/// Indicates chip has an Enhanced EFC. +#define CHIP_FLASH_EEFC + +// DMA channels number +#define CHIP_DMA_CHANNEL_NUM 4 + +// Indicate chip has a nandflash controller. +#define CHIP_NAND_CTRL + +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "AT91SAM3U4 - Misc " +/// This page lists misc features +/// + +//Misc + +//------------------------------------------------------------------------------ + +#endif //#ifndef CHIP_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u4/flash.icf b/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u4/flash.icf new file mode 100644 index 000000000..a7b3a9301 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u4/flash.icf @@ -0,0 +1,47 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\a_v1_0.xml" */ +/*-Vector table start*/ +define symbol __ICFEDIT_vector_start__ = 0x00080000; /*Add for CMSIS*/ +/*-Memory Regions-*/ +define symbol __ICFEDIT_region_RAM0_start__ = 0x20000000; +define symbol __ICFEDIT_region_RAM0_end__ = 0x20007FFF; +define symbol __ICFEDIT_region_RAM1_start__ = 0x20080000; +define symbol __ICFEDIT_region_RAM1_end__ = 0x20083FFF; +define symbol __ICFEDIT_region_ROM0_start__ = 0x00080000; +define symbol __ICFEDIT_region_ROM0_end__ = 0x0009FFFF; +define symbol __ICFEDIT_region_ROM1_start__ = 0x00100000; +define symbol __ICFEDIT_region_ROM1_end__ = 0x0011FFFF; +/*-Sizes-*/ +define symbol __ICFEDIT_size_cstack__ = 0x800; +define symbol __ICFEDIT_size_heap__ = 0x200; +/*-Specials-*/ +/*define symbol __ICFEDIT_region_RAM_VECT_start__ = __ICFEDIT_region_RAM0_start__;*/ /*Referenced for CMSIS*/ +/*define symbol __ICFEDIT_size_vectors__ = 0x100;*/ /*Referenced for CMSIS*/ +/*-Exports-*/ +/*export symbol __ICFEDIT_region_RAM_VECT_start__;*/ +export symbol __ICFEDIT_vector_start__; /*Add for CMSIS*/ +/**** End of ICF editor section. ###ICF###*/ + +define memory mem with size = 4G; +/*define region RAM_VECT_region = mem:[from __ICFEDIT_region_RAM_VECT_start__ size __ICFEDIT_size_vectors__];*/ /*Referenced for CMSIS*/ +/*define region RAM0_region = mem:[from __ICFEDIT_region_RAM0_start__+__ICFEDIT_size_vectors__ to __ICFEDIT_region_RAM0_end__];*/ /*Referenced for CMSIS*/ +define region RAM0_region = mem:[from __ICFEDIT_region_RAM0_start__ to __ICFEDIT_region_RAM0_end__]; +define region RAM1_region = mem:[from __ICFEDIT_region_RAM1_start__ to __ICFEDIT_region_RAM1_end__]; +/*define region RAM_region = mem:[from __ICFEDIT_region_RAM0_start__+__ICFEDIT_size_vectors__ to __ICFEDIT_region_RAM0_end__] | + mem:[from __ICFEDIT_region_RAM1_start__ to __ICFEDIT_region_RAM1_end__];*/ /*Referenced for CMSIS*/ +define region ROM0_region = mem:[from __ICFEDIT_region_ROM0_start__ to __ICFEDIT_region_ROM0_end__]; +define region ROM1_region = mem:[from __ICFEDIT_region_ROM1_start__ to __ICFEDIT_region_ROM1_end__]; + +/*define block RamVect with alignment = 8, size = __ICFEDIT_size_vectors__ { };*/ +define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; +define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +/*place at start of ROM0_region { readonly section .vectors };*/ /*Referenced for CMSIS*/ +place at address mem:__ICFEDIT_vector_start__ { readonly section .vectors }; /*Add for CMSIS*/ +place in ROM0_region { readonly }; +place in RAM0_region { readwrite, block CSTACK, block HEAP }; +/*place in RAM_VECT_region { block RamVect };*/ /*Referenced for CMSIS*/ \ No newline at end of file diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u4/sram.icf b/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u4/sram.icf new file mode 100644 index 000000000..4290bf582 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/at91sam3u4/sram.icf @@ -0,0 +1,33 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\a_v1_0.xml" */ +/*-Vector table start*/ +define symbol __ICFEDIT_vector_start__ = 0x20000000; +/*-Memory Regions-*/ +define symbol __ICFEDIT_region_RAM0_start__ = 0x20000000; +define symbol __ICFEDIT_region_RAM0_end__ = 0x20007FFF; +define symbol __ICFEDIT_region_RAM1_start__ = 0x20080000; +define symbol __ICFEDIT_region_RAM1_end__ = 0x20083FFF; +/*-Sizes-*/ +define symbol __ICFEDIT_size_cstack__ = 0x400; +define symbol __ICFEDIT_size_heap__ = 0x200; +/*-Exports-*/ +export symbol __ICFEDIT_vector_start__; +/**** End of ICF editor section. ###ICF###*/ + +define memory mem with size = 4G; +define region RAM0_region = mem:[from __ICFEDIT_region_RAM0_start__ to __ICFEDIT_region_RAM0_end__]; +define region RAM1_region = mem:[from __ICFEDIT_region_RAM1_start__ to __ICFEDIT_region_RAM1_end__]; +/*define region RAM_region = mem:[from __ICFEDIT_region_RAM0_start__+__ICFEDIT_size_vectors__ to __ICFEDIT_region_RAM0_end__] | + mem:[from __ICFEDIT_region_RAM1_start__ to __ICFEDIT_region_RAM1_end__];*/ + +/* define block RamVect with alignment = 8, size = __ICFEDIT_size_vectors__ { }; */ +define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; +define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +place at address mem:__ICFEDIT_vector_start__ { readonly section .vectors }; +place in RAM0_region { readonly }; +place in RAM1_region { readwrite, block CSTACK, block HEAP }; diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/board.h b/Demo/CORTEX_AT91SAM3U256_IAR/system/board.h new file mode 100644 index 000000000..694e00373 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/board.h @@ -0,0 +1,747 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// !Purpose +/// +/// Definition and functions for using AT91SAM3UE-related features, such +/// has PIO pins, memories, etc. +/// +/// !Usage +/// -# The code for booting the board is provided by board_cstartup.S and +/// board_lowlevel.c. +/// -# For using board PIOs, board characteristics (clock, etc.) and external +/// components, see board.h. +/// -# For manipulating memories (remapping, SDRAM, etc.), see board_memories.h. +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \unit +/// !Purpose +/// +/// Definition of AT91SAM3UE-EK characteristics, AT91SAM3UE-dependant PIOs and +/// external components interfacing. +/// +/// !Usage +/// -# For operating frequency information, see "SAM3UE-EK - Operating frequencies". +/// -# For using portable PIO definitions, see "SAM3UE-EK - PIO definitions". +/// -# Several USB definitions are included here (see "SAM3UE-EK - USB device"). +//------------------------------------------------------------------------------ + +#ifndef BOARD_H +#define BOARD_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#if defined(at91sam3u4) + #include "at91sam3u4/chip.h" + #include "at91sam3u4/AT91SAM3U4.h" +#else + #error Board does not support the specified chip. +#endif + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "SAM3UE-EK - Board Description" +/// This page lists several definition related to the board description. +/// +/// !Definitions +/// - BOARD_NAME + +/// Name of the board. +#define BOARD_NAME "AT91SAM3U-EK" +/// Board definition. +#define at91sam3uek +/// Family definition (already defined). +#define at91sam3u +/// Core definition +#define cortexm3 +// Chip type +//#define fpgasimulation +//------------------------------------------------------------------------------ + +#if defined(fpgasimulation) +#define PMC_BY_HARD +#endif + +//------------------------------------------------------------------------------ +/// \page "SAM3UE-EK - Operating frequencies" +/// This page lists several definition related to the board operating frequency +/// (when using the initialization done by board_lowlevel.c). +/// +/// !Definitions +/// - BOARD_MAINOSC +/// - BOARD_MCK + +/// Frequency of the board main oscillator. +#define BOARD_MAINOSC 12000000 + +/// Master clock frequency (when using board_lowlevel.c). +#if !defined(fpgasimulation) +#define BOARD_MCK 48000000 +#else +#define BOARD_MCK 22579200 +#endif + +#if defined (fpgasimulation) +//#define BOARD_ConfigureSdram(...) { } +#endif // fpgasimulation + +//------------------------------------------------------------------------------ +// ADC +//------------------------------------------------------------------------------ +/// ADC clock frequency, at 10-bit resolution (in Hz) +#define ADC_MAX_CK_10BIT 5000000 +/// Startup time max, return from Idle mode (in µs) +#define ADC_STARTUP_TIME_MAX 15 +/// Track and hold Acquisition Time min (in ns) +#define ADC_TRACK_HOLD_TIME_MIN 1200 + +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "SAM3UE-EK - USB device" +/// This page lists constants describing several characteristics (controller +/// type, D+ pull-up type, etc.) of the USB device controller of the chip/board. +/// +/// !Constants +/// - BOARD_USB_UDP +/// - BOARD_USB_PULLUP_EXTERNAL +/// - BOARD_USB_NUMENDPOINTS +/// - BOARD_USB_ENDPOINTS_MAXPACKETSIZE +/// - BOARD_USB_ENDPOINTS_BANKS + +/// Chip has a UDP controller. +#define BOARD_USB_UDPHS + +/// Indicates the D+ pull-up is external. +#define BOARD_USB_PULLUP_INTERNAL + +/// Number of endpoints in the USB controller. +#define BOARD_USB_NUMENDPOINTS 7 + +/// Returns the maximum packet size of the given endpoint. +#define BOARD_USB_ENDPOINTS_MAXPACKETSIZE(i) (((i == 0)||(i == 3)||(i == 4)) ? 64 :\ + (((i == 1) || (i == 2)) ? 512 : 1024)) + +/// Returns the number of FIFO banks for the given endpoint. +#define BOARD_USB_ENDPOINTS_BANKS(i) ((i == 0) ? 1 : ((i == 1) || (i == 2)) ? 2 : 3) + +/// USB attributes configuration descriptor (bus or self powered, remote wakeup) +#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_RWAKEUP +//#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "SAM3UE-EK - PIO definitions" +/// This pages lists all the pio definitions contained in board.h. The constants +/// are named using the following convention: PIN_* for a constant which defines +/// a single Pin instance (but may include several PIOs sharing the same +/// controller), and PINS_* for a list of Pin instances. +/// +/// !ADC +/// - PIN_ADC0_AD0 +/// - PIN_ADC0_AD1 +/// - PIN_ADC0_AD2 +/// - PIN_ADC0_AD3 +/// - PIN_ADC0_AD4 +/// - PIN_ADC0_AD5 +/// - PIN_ADC0_AD6 +/// - PIN_ADC0_AD7 +/// - PINS_ADC0 +/// +/// !CAN +/// - PIN_CAN_TRANSCEIVER_RS +/// - PIN_CAN1_TRANSCEIVER_TXD +/// - PIN_CAN1_TRANSCEIVER_RXD +/// - PIN_CAN2_TRANSCEIVER_TXD +/// - PIN_CAN2_TRANSCEIVER_RXD +/// - PINS_CAN_TRANSCEIVER_TXD +/// - PINS_CAN_TRANSCEIVER_RXD +/// +/// !DBGU +/// - PINS_DBGU +/// +/// !Joystick buttons +/// - PIN_JOYSTICK_UP +/// - PIN_JOYSTICK_DOWN +/// - PIN_JOYSTICK_LEFT +/// - PIN_JOYSTICK_RIGHT +/// - PIN_JOYSTICK_LCLIC, PIN_JOYSTICK_PUSH +/// - PINS_JOYSTICK_MOVE, PINS_JOYSTICK_CLIC, PINS_JOYSTICK +/// - JOYSTICK_UP +/// - JOYSTICK_DOWN +/// - JOYSTICK_LEFT +/// - JOYSTICK_RIGHT +/// - JOYSTICK_LCLIC, JOYSTICK_PUSH +/// +/// !EBI +/// - PIN_EBI_DATA_BUS +/// - PIN_EBI_NCS0 +/// - PIN_EBI_NRD +/// - PIN_EBI_NWE +/// - PIN_EBI_ADDR_BUS +/// - PIN_EBI_PSRAM_NBS +/// - PIN_EBI_A1 +/// - PIN_EBI_LCD_RS +/// +/// !LEDs +/// - PIN_LED_DS1 +/// - PIN_LED_DS2 +/// - PIN_LED_DS3 +/// - PIN_LED_DS4 +/// - PINS_LEDS +/// - LED_DS1 +/// - LED_DS2 +/// - LED_DS3 +/// - LED_DS4 +/// +/// !MCI +/// - PINS_MCI +/// +/// !Push buttons +/// - PIN_PUSHBUTTON_1 +/// - PIN_PUSHBUTTON_2 +/// - PIN_PUSHBUTTON_3 +/// - PIN_PUSHBUTTON_4 +/// - PINS_PUSHBUTTONS +/// - PUSHBUTTON_BP1 +/// - PUSHBUTTON_BP2 +/// - PUSHBUTTON_BP3 +/// - PUSHBUTTON_BP4 +/// +/// !PWMC +/// - PIN_PWMC_PWM0 +/// - PIN_PWMC_PWM1 +/// - PIN_PWMC_PWM2 +/// - PIN_PWMC_PWM3 +/// - PIN_PWMC_PWM4 +/// - PIN_PWMC_PWM5 +/// - PIN_PWMC_PWM6 +/// - PIN_PWMC_PWM7 +/// - PIN_PWM_LED0 +/// - PIN_PWM_LED1 +/// - CHANNEL_PWM_LED0 +/// - CHANNEL_PWM_LED1 +/// +/// !SPI0 +/// - PIN_SPI0_MISO +/// - PIN_SPI0_MOSI +/// - PIN_SPI0_SPCK +/// - PINS_SPI0 +/// - PIN_SPI0_NPCS3 +/// +/// !SPI1 +/// - PIN_SPI1_MISO +/// - PIN_SPI1_MOSI +/// - PIN_SPI1_SPCK +/// - PINS_SPI1 +/// - PIN_SPI1_NPCS3 +/// +/// ! SSC +/// - PIN_SSC_TD +/// - PIN_SSC_TK +/// - PIN_SSC_TF +/// - PINS_SSC_CODEC +/// +/// ! PCK0 +/// - PIN_PCK0 +/// +/// !TWI +/// - PIN_TWI_TWD0 +/// - PIN_TWI_TWCK0 +/// - PINS_TWI +/// +/// !USART0 +/// - PIN_USART0_RXD +/// - PIN_USART0_TXD +/// - PIN_USART0_CTS +/// - PIN_USART0_RTS +/// - PIN_USART0_SCK +/// +/// !USB +/// - PIN_USB_PULLUP +/// + +/// ADC_AD0 pin definition. +#define PIN_ADC0_AD0 {1 << 21, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEFAULT} +/// ADC_AD1 pin definition. +#define PIN_ADC0_AD1 {1 << 30, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEFAULT} +/// ADC_AD2 pin definition. +#define PIN_ADC0_AD2 {1 << 3, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_INPUT, PIO_DEFAULT} +/// ADC_AD3 pin definition. +#define PIN_ADC0_AD3 {1 << 4, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_INPUT, PIO_DEFAULT} +/// ADC_AD4 pin definition. +#define PIN_ADC0_AD4 {1 << 15, AT91C_BASE_PIOC, AT91C_ID_PIOC, PIO_INPUT, PIO_DEFAULT} +/// ADC_AD5 pin definition. +#define PIN_ADC0_AD5 {1 << 16, AT91C_BASE_PIOC, AT91C_ID_PIOC, PIO_INPUT, PIO_DEFAULT} +/// ADC_AD6 pin definition. +#define PIN_ADC0_AD6 {1 << 17, AT91C_BASE_PIOC, AT91C_ID_PIOC, PIO_INPUT, PIO_DEFAULT} +/// ADC_AD7 pin definition. +#define PIN_ADC0_AD7 {1 << 18, AT91C_BASE_PIOC, AT91C_ID_PIOC, PIO_INPUT, PIO_DEFAULT} + +/// Pins ADC +#define PINS_ADC PIN_ADC0_AD0, PIN_ADC0_AD1, PIN_ADC0_AD2, PIN_ADC0_AD3, PIN_ADC0_AD4, PIN_ADC0_AD5, PIN_ADC0_AD6, PIN_ADC0_AD7 + +/// CAN Definition +/// RS: Select input for high speed mode or silent mode +//#define PIN_CAN_TRANSCEIVER_RS {1<<23, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} +// +///// TXD: Transmit data input +//#define PIN_CAN1_TRANSCEIVER_TXD {1<<27, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +///// RXD: Receive data output +//#define PIN_CAN1_TRANSCEIVER_RXD {1<<26, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +/// TXD: Transmit data input +//#define PIN_CAN2_TRANSCEIVER_TXD {1<<29, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +///// RXD: Receive data output +//#define PIN_CAN2_TRANSCEIVER_RXD {1<<28, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +///// TXD pins +//#define PINS_CAN_TRANSCEIVER_TXD PIN_CAN1_TRANSCEIVER_TXD, PIN_CAN2_TRANSCEIVER_TXD +///// RXD pins +//#define PINS_CAN_TRANSCEIVER_RXD PIN_CAN1_TRANSCEIVER_RXD, PIN_CAN2_TRANSCEIVER_RXD + +/// DBGU pins (DTXD and DRXD) definitions, PA11,12. +#define PINS_DBGU {0x00001800, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} + +/// EBI +#define PIN_EBI_DATA_BUS {0xfe01fe00, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_A, PIO_PULLUP}, \ + {1 << 6, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_B, PIO_PULLUP} +#define PIN_EBI_NCS0 {1 << 20, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_A, PIO_PULLUP} +#define PIN_EBI_NRD {1 << 19, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_A, PIO_PULLUP} +#define PIN_EBI_NWE {1 << 23, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_A, PIO_PULLUP} +#define PIN_EBI_PSRAM_ADDR_BUS {0x3f00fff, AT91C_BASE_PIOC, AT91C_ID_PIOC, PIO_PERIPH_A, PIO_PULLUP} +#define PIN_EBI_PSRAM_NBS {1 << 7, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_B, PIO_PULLUP}, \ + {1 << 15, AT91C_BASE_PIOC, AT91C_ID_PIOC, PIO_PERIPH_A, PIO_PULLUP} +#define PIN_EBI_A1 {1 << 8, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_B, PIO_PULLUP} + +#define PIN_EBI_NCS2 {1 << 16, AT91C_BASE_PIOC, AT91C_ID_PIOC, PIO_PERIPH_A, PIO_PULLUP} +#define PIN_EBI_LCD_RS {1 << 8, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_B, PIO_PULLUP} + + +/// LED #0 pin definition. +#define PIN_LED_0 {1 << 0, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_OUTPUT_0, PIO_DEFAULT} +/// LED #1 pin definition. +#define PIN_LED_1 {1 << 2, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_OUTPUT_1, PIO_DEFAULT} +/// LED #2 pin definition. +#define PIN_LED_2 {1 << 1, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_OUTPUT_1, PIO_DEFAULT} +/// List of all LEDs definitions. +#define PINS_LEDS PIN_LED_0, PIN_LED_1, PIN_LED_2 + +///// MCI pins definition. +#define PINS_MCI {0x1f8, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_PULLUP}, \ + {1 << 3, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} + +/// MCI pin Card Detect +#define PIN_MCI_CD \ + {AT91C_PIO_PA25, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_PULLUP} + +/// Push button #0 definition. +#define PIN_PUSHBUTTON_1 {1 << 18, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEGLITCH | PIO_PULLUP} +/// Push button #1 definition. +#define PIN_PUSHBUTTON_2 {1 << 19, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEGLITCH | PIO_PULLUP} +/// Push button #2 definition +/// List of all push button definitions. +#define PINS_PUSHBUTTONS PIN_PUSHBUTTON_1, PIN_PUSHBUTTON_2 + +/// Push button #1 index. +#define PUSHBUTTON_BP1 0 +/// Push button #2 index. +#define PUSHBUTTON_BP2 1 + +/// Simulated joystick LEFT index. +#define JOYSTICK_LEFT 0 +/// Simulated joystick RIGHT index. +#define JOYSTICK_RIGHT 1 + +/// SPI0 MISO pin definition. +#define PIN_SPI0_MISO {1 << 13, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +/// SPI0 MOSI pin definition. +#define PIN_SPI0_MOSI {1 << 14, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +/// SPI0 SPCK pin definition. +#define PIN_SPI0_SPCK {1 << 15, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +/// SPI0 chip select 2 pin definition. +//#define PIN_SPI0_NPCS2_PC14 {1 << 14, AT91C_BASE_PIOC, AT91C_ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT} +#define PIN_SPI0_NPCS2_PC14 {1 << 14, AT91C_BASE_PIOC, AT91C_ID_PIOC, PIO_OUTPUT_0, PIO_PULLUP} +/// List of SPI0 pin definitions (MISO, MOSI & SPCK). +#define PINS_SPI0 PIN_SPI0_MISO, PIN_SPI0_MOSI, PIN_SPI0_SPCK + +/// SSC pins definition. +#define PIN_SSC_TD {0x1 << 26, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +#define PIN_SSC_TK {0x1 << 28, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +#define PIN_SSC_TF {0x1 << 30, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +#define PINS_SSC_CODEC PIN_SSC_TD, PIN_SSC_TK, PIN_SSC_TF + +/// PCK0 +#define PIN_PCK0 {0x1 << 21, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT} + +/// TWI pins definition. +#define TWI_V3XX +#define PIN_TWI_TWD0 {0x1 << 9, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +#define PIN_TWI_TWCK0 {0x1 << 10, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +#define PINS_TWI0 PIN_TWI_TWD0, PIN_TWI_TWCK0 +#define PIN_TWI_TWD1 {0x1 << 24, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +#define PIN_TWI_TWCK1 {0x1 << 25, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +#define PINS_TWI1 PIN_TWI_TWD1, PIN_TWI_TWCK1 + +/// USART0 +#define PIN_USART0_RXD {0x1 << 19, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +#define PIN_USART0_TXD {0x1 << 18, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +#define PIN_USART0_CTS {0x1 << 8, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT} +#define PIN_USART0_RTS {0x1 << 7, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT} +#define PIN_USART0_SCK {0x1 << 17, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} + +/// USART1 +#define PIN_USART1_RXD {0x1 << 21, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +#define PIN_USART1_TXD {0x1 << 20, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +#define PIN_USART1_CTS {0x1 << 23, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT} +#define PIN_USART1_RTS {0x1 << 22, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT} +#define PIN_USART1_SCK {0x1 << 24, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT} + +/// USB VBus monitoring pin definition. +#define PIN_USB_VBUS {1 << 31, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_PULLUP} + +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "SAM3UE-EK - External components" +/// This page lists the definitions related to external on-board components +/// located in the board.h file for the AT91SAM3UE-EK. +/// +/// !AT45 Dataflash Card +/// - BOARD_AT45_A_SPI_BASE +/// - BOARD_AT45_A_SPI_ID +/// - BOARD_AT45_A_SPI_PINS +/// - BOARD_AT45_A_SPI +/// - BOARD_AT45_A_NPCS +/// - BOARD_AT45_A_NPCS_PIN +/// +/// !AT45 Dataflash (serial onboard DataFlash) +/// - BOARD_AT45_B_SPI_BASE +/// - BOARD_AT45_B_SPI_ID +/// - BOARD_AT45_B_SPI_PINS +/// - BOARD_AT45_B_SPI +/// - BOARD_AT45_B_NPCS +/// - BOARD_AT45_B_NPCS_PIN +/// +/// !AT26 Serial Flash +/// - BOARD_AT26_A_SPI_BASE +/// - BOARD_AT26_A_SPI_ID +/// - BOARD_AT26_A_SPI_PINS +/// - BOARD_AT26_A_SPI +/// - BOARD_AT26_A_NPCS +/// - BOARD_AT26_A_NPCS_PIN +/// +/// !SD Card +/// - MCI2_INTERFACE +/// - BOARD_SD_MCI_BASE +/// - BOARD_SD_MCI_ID +/// - BOARD_SD_PINS +/// - BOARD_SD_SLOT +/// +/// !PSRAM +/// - BOARD_PSRAM_PINS +/// - BOARD_LCD_PINS + +/// Base address of SPI peripheral connected to the dataflash. +//#define BOARD_AT45_A_SPI_BASE AT91C_BASE_SPI0 +///// Identifier of SPI peripheral connected to the dataflash. +//#define BOARD_AT45_A_SPI_ID AT91C_ID_SPI0 +///// Pins of the SPI peripheral connected to the dataflash. +//#define BOARD_AT45_A_SPI_PINS PINS_SPI0 +///// Dataflahs SPI number. +//#define BOARD_AT45_A_SPI 0 +///// Chip select connected to the dataflash. +//#define BOARD_AT45_A_NPCS 3 +///// Chip select pin connected to the dataflash. +//#define BOARD_AT45_A_NPCS_PIN PIN_SPI0_NPCS3 + +/// Base address of SPI peripheral connected to the dataflash. +//#define BOARD_AT45_B_SPI_BASE AT91C_BASE_SPI1 +///// Identifier of SPI peripheral connected to the dataflash. +//#define BOARD_AT45_B_SPI_ID AT91C_ID_SPI1 +///// Pins of the SPI peripheral connected to the dataflash. +//#define BOARD_AT45_B_SPI_PINS PINS_SPI1 +///// Dataflahs SPI number. +//#define BOARD_AT45_B_SPI 1 +///// Chip select connected to the dataflash. +//#define BOARD_AT45_B_NPCS 3 +///// Chip select pin connected to the dataflash. +//#define BOARD_AT45_B_NPCS_PIN PIN_SPI1_NPCS3 + +/// Base address of SPI peripheral connected to the serialflash. +//#define BOARD_AT26_A_SPI_BASE AT91C_BASE_SPI0 +///// Identifier of SPI peripheral connected to the serialflash. +//#define BOARD_AT26_A_SPI_ID AT91C_ID_SPI0 +///// Pins of the SPI peripheral connected to the serialflash. +//#define BOARD_AT26_A_SPI_PINS PINS_SPI0 +///// Serialflash SPI number. +//#define BOARD_AT26_A_SPI 0 +///// Chip select connected to the serialflash. +//#define BOARD_AT26_A_NPCS 3 +///// Chip select pin connected to the serialflash. +//#define BOARD_AT26_A_NPCS_PIN PIN_SPI0_NPCS3 + +/// HS MCI interface +#define MCI2_INTERFACE +/// Base address of the MCI peripheral connected to the SD card. +#define BOARD_SD_MCI_BASE AT91C_BASE_MCI0//AT91C_BASE_MCI +///// Peripheral identifier of the MCI connected to the SD card. +#define BOARD_SD_MCI_ID AT91C_ID_MCI0 //AT91C_ID_MCI +///// MCI pins that shall be configured to access the SD card. +#define BOARD_SD_PINS PINS_MCI +///// MCI slot to which the SD card is connected to. +#define BOARD_SD_SLOT MCI_SD_SLOTA +///// MCI Card Detect pin. +#define BOARD_SD_PIN_CD PIN_MCI_CD + +#define BOARD_PSRAM_PINS PIN_EBI_DATA_BUS, PIN_EBI_NCS0, PIN_EBI_NRD, PIN_EBI_NWE, \ + PIN_EBI_PSRAM_ADDR_BUS, PIN_EBI_PSRAM_NBS, PIN_EBI_A1 + +/// Indicates board has an HX8347 external component to manage LCD. +#define BOARD_LCD_HX8347 + +/// LCD pins definition. +#define BOARD_LCD_PINS PIN_EBI_DATA_BUS, PIN_EBI_LCD_RS, PIN_EBI_NRD, PIN_EBI_NWE, \ + PIN_EBI_NCS2 +/// Backlight pin definition. +#define BOARD_BACKLIGHT_PIN {1 << 19, AT91C_BASE_PIOC, AT91C_ID_PIOC, \ + PIO_OUTPUT_0, PIO_DEFAULT} +/// Define HX8347 base address. +#define BOARD_LCD_BASE 0x62000000 +/// Define HX8347 register select signal. +#define BOARD_LCD_RS (1 << 1) +/// Display width in pixels. +#define BOARD_LCD_WIDTH 240 +/// Display height in pixels. +#define BOARD_LCD_HEIGHT 320 + +/// Indicates board has an ADS7843 external component to manage Touch Screen +#define BOARD_TSC_ADS7843 + +/// Touchscreen controller IRQ pin definition. +#define PIN_TCS_IRQ {AT91C_PIO_PA24, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_PULLUP} +/// Touchscreen controller Busy pin definition. +#define PIN_TCS_BUSY {AT91C_PIO_PA2, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_PULLUP} + +/// Base address of SPI peripheral connected to the touchscreen controller. +#define BOARD_TSC_SPI_BASE AT91C_BASE_SPI0 +/// Identifier of SPI peripheral connected to the touchscreen controller. +#define BOARD_TSC_SPI_ID AT91C_ID_SPI0 +/// Pins of the SPI peripheral connected to the touchscreen controller. +#define BOARD_TSC_SPI_PINS PINS_SPI0 +/// Chip select connected to the touchscreen controller. +#define BOARD_TSC_NPCS 2//2 +/// Chip select pin connected to the touchscreen controller. +#define BOARD_TSC_NPCS_PIN PIN_SPI0_NPCS2_PC14 + +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "SAM3UE-EK - Memories" +/// This page lists definitions related to internal & external on-board memories. +/// +/// !Embedded Flash +/// - BOARD_FLASH_EFC + +/// Internal SRAM address +#define AT91C_ISRAM AT91C_IRAM +#define AT91C_ISRAM_SIZE AT91C_IRAM_SIZE + +#define AT91C_IFLASH (0x80000) +#define AT91C_IFLASH_SIZE (0x20000) +#define AT91C_IFLASH_PAGE_SIZE (256) // Internal FLASH 0 Page Size: 256 bytes +#define AT91C_IFLASH_NB_OF_PAGES (512) // Internal FLASH 0 Number of Pages: 512 +#define AT91C_IFLASH_LOCK_REGION_SIZE (8192) // Internal FLASH 0 Lock Region Size: 8 Kbytes +#define AT91C_IFLASH_NB_OF_LOCK_BITS (16) // Internal FLASH 0 Number of Lock Bits: 32 +#if 0 +#define AT91C_IFLASH1 (0x100000) +#define AT91C_IFLASH1_SIZE (0x20000) +#define AT91C_IFLASH1_PAGE_SIZE (256) // Internal FLASH 1 Page Size: 256 bytes +#define AT91C_IFLASH1_NB_OF_PAGES (512) // Internal FLASH 1 Number of Pages: 512 +#define AT91C_IFLASH1_LOCK_REGION_SIZE (8192) // Internal FLASH 1 Lock Region Size: 8 Kbytes +#define AT91C_IFLASH1_NB_OF_LOCK_BITS (16) // Internal FLASH 1 Number of Lock Bits: 32 +#endif +/// Indicates chip has an EFC. +#define AT91C_BASE_EFC AT91C_BASE_EFC0 +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +/// \page "SAM3UE-EK - External components" +/// This page lists the definitions related to external on-board components +/// located in the board.h file for the SAM3UE-EK. +/// +/// !ISO7816 +/// - PIN_SMARTCARD_CONNECT +/// - PIN_ISO7816_RSTMC +/// - PINS_ISO7816 + +/// Smartcard detection pin +//#define PIN_SMARTCARD_CONNECT {1 << 5, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_INPUT, PIO_DEFAULT} +/// PIN used for reset the smartcard +//#define PIN_ISO7816_RSTMC {1 << 7, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} +/// Pins used for connect the smartcard +//#define PINS_ISO7816 PIN_USART0_TXD, PIN_USART0_SCK, PIN_ISO7816_RSTMC + +/// Dma channel number +#define BOARD_MCI_DMA_CHANNEL 0 +/// MCI0 DMA hardware handshaking ID +#define DMA_HW_SRC_REQ_ID_MCI0 AT91C_HDMA_SRC_PER_0 +#define DMA_HW_DEST_REQ_ID_MCI0 AT91C_HDMA_DST_PER_0 +/// MCI1 DMA hardware handshaking ID +#define DMA_HW_SRC_REQ_ID_MCI1 AT91C_HDMA_SRC_PER_13 +#define DMA_HW_DEST_REQ_ID_MCI1 AT91C_HDMA_DST_PER_13 +/// SD DMA hardware handshaking ID +#define BOARD_SD_DMA_HW_SRC_REQ_ID DMA_HW_SRC_REQ_ID_MCI0 +#define BOARD_SD_DMA_HW_DEST_REQ_ID DMA_HW_DEST_REQ_ID_MCI0 +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "SAM3UE-EK - Individual chip definition" +/// This page lists the definitions related to different chip's definition +/// located in the board.h file for the SAM3UE-EK. + +/// DBGU +#define BOARD_DBGU_ID AT91C_ID_DBGU + +/// Rtc +#define BOARD_RTC_ID AT91C_ID_RTC + +/// Twi eeprom +#define BOARD_ID_TWI_EEPROM AT91C_ID_TWI1 +#define BOARD_BASE_TWI_EEPROM AT91C_BASE_TWI1 +#define BOARD_PINS_TWI_EEPROM PINS_TWI1 + +/// USART +#define BOARD_PIN_USART_RXD PIN_USART1_RXD +#define BOARD_PIN_USART_TXD PIN_USART1_TXD +#define BOARD_PIN_USART_CTS PIN_USART1_CTS +#define BOARD_PIN_USART_RTS PIN_USART1_RTS +#define BOARD_USART_BASE AT91C_BASE_US1 +#define BOARD_ID_USART AT91C_ID_US1 + +/// Interrupt source +typedef enum IRQn +{ +/****** Cortex-M3 Processor Exceptions Numbers ***************************************************/ + NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */ + MemoryManagement_IRQn = -12, /*!< 4 Cortex-M3 Memory Management Interrupt */ + BusFault_IRQn = -11, /*!< 5 Cortex-M3 Bus Fault Interrupt */ + UsageFault_IRQn = -10, /*!< 6 Cortex-M3 Usage Fault Interrupt */ + SVCall_IRQn = -5, /*!< 11 Cortex-M3 SV Call Interrupt */ + DebugMonitor_IRQn = -4, /*!< 12 Cortex-M3 Debug Monitor Interrupt */ + PendSV_IRQn = -2, /*!< 14 Cortex-M3 Pend SV Interrupt */ + SysTick_IRQn = -1, /*!< 15 Cortex-M3 System Tick Interrupt */ + +/****** AT91SAM3U4 specific Interrupt Numbers *********************************************************/ + IROn_SUPC = AT91C_ID_SUPC , // SUPPLY CONTROLLER + IROn_RSTC = AT91C_ID_RSTC , // RESET CONTROLLER + IROn_RTC = AT91C_ID_RTC , // REAL TIME CLOCK + IROn_RTT = AT91C_ID_RTT , // REAL TIME TIMER + IROn_WDG = AT91C_ID_WDG , // WATCHDOG TIMER + IROn_PMC = AT91C_ID_PMC , // PMC + IROn_EFC0 = AT91C_ID_EFC0 , // EFC0 + IROn_EFC1 = AT91C_ID_EFC1 , // EFC1 + IROn_DBGU = AT91C_ID_DBGU , // DBGU + IROn_HSMC4 = AT91C_ID_HSMC4, // HSMC4 + IROn_PIOA = AT91C_ID_PIOA , // Parallel IO Controller A + IROn_PIOB = AT91C_ID_PIOB , // Parallel IO Controller B + IROn_PIOC = AT91C_ID_PIOC , // Parallel IO Controller C + IROn_US0 = AT91C_ID_US0 , // USART 0 + IROn_US1 = AT91C_ID_US1 , // USART 1 + IROn_US2 = AT91C_ID_US2 , // USART 2 + IROn_US3 = AT91C_ID_US3 , // USART 3 + IROn_MCI0 = AT91C_ID_MCI0 , // Multimedia Card Interface + IROn_TWI0 = AT91C_ID_TWI0 , // TWI 0 + IROn_TWI1 = AT91C_ID_TWI1 , // TWI 1 + IROn_SPI0 = AT91C_ID_SPI0 , // Serial Peripheral Interface + IROn_SSC0 = AT91C_ID_SSC0 , // Serial Synchronous Controller 0 + IROn_TC0 = AT91C_ID_TC0 , // Timer Counter 0 + IROn_TC1 = AT91C_ID_TC1 , // Timer Counter 1 + IROn_TC2 = AT91C_ID_TC2 , // Timer Counter 2 + IROn_PWMC = AT91C_ID_PWMC , // Pulse Width Modulation Controller + IROn_ADCC0 = AT91C_ID_ADCC0, // ADC controller0 + IROn_ADCC1 = AT91C_ID_ADCC1, // ADC controller1 + IROn_HDMA = AT91C_ID_HDMA , // HDMA + IROn_UDPHS = AT91C_ID_UDPHS // USB Device High Speed +} IRQn_Type; + +/// Dummy define SDRAM bus width +#define BOARD_SDRAM_BUSWIDTH 32 + +//------------------------------------------------------------------------------ + + +#define PIN_EBI_NANDOE {1 << 17, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_A, PIO_PULLUP} +#define PIN_EBI_NANDWE {1 << 18, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_A, PIO_PULLUP} +#define PIN_EBI_NANDCLE {1 << 22, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_A, PIO_PULLUP} +#define PIN_EBI_NANDALE {1 << 21, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_A, PIO_PULLUP} + +#ifdef CHIP_NAND_CTRL +/// Nandflash chip enable pin definition. +#define BOARD_NF_CE_PIN {1 << 12, AT91C_BASE_PIOC, AT91C_ID_PIOC, PIO_PERIPH_A, PIO_PULLUP} +/// Nandflash ready/busy pin definition. +#define BOARD_NF_RB_PIN {1 << 24, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_PERIPH_A, PIO_PULLUP} + +/// Nandflash controller peripheral pins definition. +#define PINS_NANDFLASH BOARD_NF_CE_PIN, BOARD_NF_RB_PIN, PIN_EBI_NANDOE, PIN_EBI_NANDWE,\ + PIN_EBI_NANDCLE, PIN_EBI_NANDALE, PIN_EBI_DATA_BUS + +/// Address for transferring command bytes to the nandflash. +#define BOARD_NF_COMMAND_ADDR 0x60000000 +/// Address for transferring address bytes to the nandflash. +#define BOARD_NF_ADDRESS_ADDR 0x61200000 +/// Address for transferring data bytes to the nandflash. +#define BOARD_NF_DATA_ADDR 0x61000000 + +#else +/// Nandflash controller peripheral pins definition. +#define PINS_NANDFLASH BOARD_NF_CE_PIN, BOARD_NF_RB_PIN, PIN_EBI_NANDOE, PIN_EBI_NANDWE,\ + PIN_EBI_NANDCLE, PIN_EBI_NANDALE +/// Nandflash chip enable pin definition. +#define BOARD_NF_CE_PIN {1 << 12, AT91C_BASE_PIOC, AT91C_ID_PIOC, PIO_OUTPUT_1, PIO_DEFAULT} +/// Nandflash ready/busy pin definition. +#define BOARD_NF_RB_PIN {1 << 24, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_INPUT, PIO_PULLUP} +/// Address for transferring command bytes to the nandflash. +#define BOARD_NF_COMMAND_ADDR 0x61400000 +/// Address for transferring address bytes to the nandflash. +#define BOARD_NF_ADDRESS_ADDR 0x61200000 +/// Address for transferring data bytes to the nandflash. +#define BOARD_NF_DATA_ADDR 0x61000000 + +#endif + +#endif //#ifndef BOARD_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/board_cstartup_iar.c b/Demo/CORTEX_AT91SAM3U256_IAR/system/board_cstartup_iar.c new file mode 100644 index 000000000..ebe76500b --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/board_cstartup_iar.c @@ -0,0 +1,140 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ +#include "board.h" +#include "exceptions.h" +#include "board_lowlevel.h" + +//------------------------------------------------------------------------------ +// Types +//------------------------------------------------------------------------------ +typedef union { IntFunc __fun; void * __ptr; } IntVector; + +//------------------------------------------------------------------------------ +// ProtoTypes +//------------------------------------------------------------------------------ + +extern void __iar_program_start( void ); +extern void xPortPendSVHandler(void); +extern void xPortSysTickHandler(void); +extern void vPortSVCHandler(void); +extern void vSerialISR( void ); + +int __low_level_init( void ); + +//------------------------------------------------------------------------------ +// Variables +//------------------------------------------------------------------------------ +extern unsigned int __ICFEDIT_vector_start__; + +//------------------------------------------------------------------------------ +// Exception Table +//------------------------------------------------------------------------------ + +#pragma language=extended +#pragma segment="CSTACK" + +// The name "__vector_table" has special meaning for C-SPY: +// it is where the SP start value is found, and the NVIC vector +// table register (VTOR) is initialized to this address if != 0. + +#pragma section = ".vectors" +#pragma location = ".vectors" +const IntVector __vector_table[] = +{ + { .__ptr = __sfe( "CSTACK" ) }, + __iar_program_start, + + NMI_Handler, + HardFault_Handler, + MemManage_Handler, + BusFault_Handler, + UsageFault_Handler, + 0, 0, 0, 0, // Reserved + vPortSVCHandler, // SVCall handler + DebugMon_Handler, + 0, // Reserved + xPortPendSVHandler, // The PendSV handler + xPortSysTickHandler, // The SysTick handler + + // Configurable interrupts + SUPC_IrqHandler, // 0 SUPPLY CONTROLLER + RSTC_IrqHandler, // 1 RESET CONTROLLER + RTC_IrqHandler, // 2 REAL TIME CLOCK + RTT_IrqHandler, // 3 REAL TIME TIMER + WDT_IrqHandler, // 4 WATCHDOG TIMER + PMC_IrqHandler, // 5 PMC + EFC0_IrqHandler, // 6 EFC0 + EFC1_IrqHandler, // 7 EFC1 + DBGU_IrqHandler, // 8 DBGU + HSMC4_IrqHandler, // 9 HSMC4 + PIOA_IrqHandler, // 10 Parallel IO Controller A + PIOB_IrqHandler, // 11 Parallel IO Controller B + PIOC_IrqHandler, // 12 Parallel IO Controller C + USART0_IrqHandler, // 13 USART 0 + vSerialISR, // 14 USART 1 + USART2_IrqHandler, // 15 USART 2 + USART3_IrqHandler, // 16 USART 3 + MCI0_IrqHandler, // 17 Multimedia Card Interface + TWI0_IrqHandler, // 18 TWI 0 + TWI1_IrqHandler, // 19 TWI 1 + SPI0_IrqHandler, // 20 Serial Peripheral Interface + SSC0_IrqHandler, // 21 Serial Synchronous Controller 0 + TC0_IrqHandler, // 22 Timer Counter 0 + TC1_IrqHandler, // 23 Timer Counter 1 + TC2_IrqHandler, // 24 Timer Counter 2 + PWM_IrqHandler, // 25 Pulse Width Modulation Controller + ADCC0_IrqHandler, // 26 ADC controller0 + ADCC1_IrqHandler, // 27 ADC controller1 + HDMA_IrqHandler, // 28 HDMA + UDPD_IrqHandler, // 29 USB Device High Speed UDP_HS + IrqHandlerNotUsed // 30 not used +}; + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// This is the code that gets called on processor reset. To initialize the +/// device. +//------------------------------------------------------------------------------ +int __low_level_init( void ) +{ + unsigned int * src = __section_begin(".vectors"); + + LowLevelInit(); + + AT91C_BASE_NVIC->NVIC_VTOFFR = ((unsigned int)(src)) | (0x0 << 7); + + return 1; // if return 0, the data sections will not be initialized. +} diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/board_lowlevel.c b/Demo/CORTEX_AT91SAM3U256_IAR/system/board_lowlevel.c new file mode 100644 index 000000000..fd4adf732 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/board_lowlevel.c @@ -0,0 +1,209 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Provides the low-level initialization function that gets called on chip +/// startup. +/// +/// !Usage +/// +/// LowLevelInit() is called in #board_cstartup_xxx.c#. +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "board.h" +#include "board_memories.h" +#include "board_lowlevel.h" +#include + +//------------------------------------------------------------------------------ +// Local definitions +//------------------------------------------------------------------------------ +// Settings at 48/48MHz +#define AT91C_CKGR_MUL_SHIFT 16 +#define AT91C_CKGR_OUT_SHIFT 14 +#define AT91C_CKGR_PLLCOUNT_SHIFT 8 +#define AT91C_CKGR_DIV_SHIFT 0 + +#define BOARD_OSCOUNT (AT91C_CKGR_MOSCXTST & (0x3F << 8)) +#define BOARD_PLLR ((1 << 29) | (0x7 << AT91C_CKGR_MUL_SHIFT) \ + | (0x0 << AT91C_CKGR_OUT_SHIFT) |(0x3f << AT91C_CKGR_PLLCOUNT_SHIFT) \ + | (0x1 << AT91C_CKGR_DIV_SHIFT)) +#define BOARD_MCKR ( AT91C_PMC_PRES_CLK_2 | AT91C_PMC_CSS_PLLA_CLK) + +// Define clock timeout +#define CLOCK_TIMEOUT 0xFFFFFFFF + +#define AT91C_SUPC_SR_OSCSEL_CRYST 0x80UL +#define AT91C_SUPC_CR_XTALSEL_CRYSTAL_SEL 0x08UL + +void SetDefaultMaster(unsigned char enable); + +//------------------------------------------------------------------------------ +// Local variables +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Local functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// After POR, at91sam3u device is running on 4MHz internal RC +/// At the end of the LowLevelInit procedure MCK = 48MHz PLLA = 96 CPU=48MHz +/// Performs the low-level initialization of the chip. This includes EFC, master +/// clock, IRQ & watchdog configuration. +//------------------------------------------------------------------------------ +void LowLevelInit(void) +{ + unsigned int timeout = 0; + + /* Set 2 WS for Embedded Flash Access + ************************************/ + AT91C_BASE_EFC0->EFC_FMR = AT91C_EFC_FWS_2WS; + AT91C_BASE_EFC1->EFC_FMR = AT91C_EFC_FWS_2WS; + + /* Watchdog initialization + *************************/ + AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS; + + /* Select external slow clock + ****************************/ + if ((AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_SR_OSCSEL_CRYST) != AT91C_SUPC_SR_OSCSEL_CRYST) { + AT91C_BASE_SUPC->SUPC_CR = AT91C_SUPC_CR_XTALSEL_CRYSTAL_SEL | (0xA5UL << 24UL); + timeout = 0; + while (!(AT91C_BASE_SUPC->SUPC_SR & AT91C_SUPC_SR_OSCSEL_CRYST) && (timeout++ < CLOCK_TIMEOUT)); + } + + /* Initialize main oscillator + ****************************/ + if(!(AT91C_BASE_PMC->PMC_MOR & AT91C_CKGR_MOSCSEL)) + { + AT91C_BASE_PMC->PMC_MOR = (0x37 << 16) | BOARD_OSCOUNT | AT91C_CKGR_MOSCRCEN | AT91C_CKGR_MOSCXTEN; + timeout = 0; + while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCXTS) && (timeout++ < CLOCK_TIMEOUT)); + } + +// AT91C_BASE_PIOB->PIO_CODR = 1 << 1; +// AT91C_BASE_PIOB->PIO_OER = 1 << 1; +// AT91C_BASE_PIOB->PIO_PER = 1 << 1; + + /* Switch to moscsel */ + AT91C_BASE_PMC->PMC_MOR = (0x37 << 16) | BOARD_OSCOUNT | AT91C_CKGR_MOSCRCEN | AT91C_CKGR_MOSCXTEN | AT91C_CKGR_MOSCSEL; + timeout = 0; + while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCSELS) && (timeout++ < CLOCK_TIMEOUT)); + AT91C_BASE_PMC->PMC_MCKR = (AT91C_BASE_PMC->PMC_MCKR & ~AT91C_PMC_CSS) | AT91C_PMC_CSS_MAIN_CLK; + timeout = 0; + while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) && (timeout++ < CLOCK_TIMEOUT)); + + /* Initialize PLLA */ + AT91C_BASE_PMC->PMC_PLLAR = BOARD_PLLR; + timeout = 0; + while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCKA) && (timeout++ < CLOCK_TIMEOUT)); + + /* Initialize UTMI for USB usage */ + AT91C_BASE_CKGR->CKGR_UCKR |= (AT91C_CKGR_UPLLCOUNT & (3 << 20)) | AT91C_CKGR_UPLLEN; + timeout = 0; + while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCKU) && (timeout++ < CLOCK_TIMEOUT)); + + /* Switch to fast clock + **********************/ + AT91C_BASE_PMC->PMC_MCKR = (BOARD_MCKR & ~AT91C_PMC_CSS) | AT91C_PMC_CSS_MAIN_CLK; + timeout = 0; + while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) && (timeout++ < CLOCK_TIMEOUT)); + + AT91C_BASE_PMC->PMC_MCKR = BOARD_MCKR; + timeout = 0; + while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) && (timeout++ < CLOCK_TIMEOUT)); + + /* Enable clock for UART + ************************/ + AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_DBGU); + + /* Optimize CPU setting for speed */ + SetDefaultMaster(1); + +} + +//------------------------------------------------------------------------------ +/// Enable or disable default master access +/// \param enalbe 1 enable defaultMaster settings, 0 disable it. +//------------------------------------------------------------------------------ +void SetDefaultMaster(unsigned char enable) +{ + AT91PS_HMATRIX2 pMatrix = AT91C_BASE_MATRIX; + + // Set default master + if (enable == 1) { + + // Set default master: SRAM0 -> Cortex-M3 System + pMatrix->HMATRIX2_SCFG0 |= AT91C_MATRIX_FIXED_DEFMSTR_SCFG0_ARMS | + AT91C_MATRIX_DEFMSTR_TYPE_FIXED_DEFMSTR; + + // Set default master: SRAM1 -> Cortex-M3 System + pMatrix->HMATRIX2_SCFG1 |= AT91C_MATRIX_FIXED_DEFMSTR_SCFG1_ARMS | + AT91C_MATRIX_DEFMSTR_TYPE_FIXED_DEFMSTR; + + // Set default master: Internal flash0 -> Cortex-M3 Instruction/Data + pMatrix->HMATRIX2_SCFG3 |= AT91C_MATRIX_FIXED_DEFMSTR_SCFG3_ARMC | + AT91C_MATRIX_DEFMSTR_TYPE_FIXED_DEFMSTR; + } else { + + // Clear default master: SRAM0 -> Cortex-M3 System + pMatrix->HMATRIX2_SCFG0 &= (~AT91C_MATRIX_DEFMSTR_TYPE); + + // Clear default master: SRAM1 -> Cortex-M3 System + pMatrix->HMATRIX2_SCFG1 &= (~AT91C_MATRIX_DEFMSTR_TYPE); + + // Clear default master: Internal flash0 -> Cortex-M3 Instruction/Data + pMatrix->HMATRIX2_SCFG3 &= (~AT91C_MATRIX_DEFMSTR_TYPE); + } +} + +//------------------------------------------------------------------------------ +/// Set flash wait state +/// \param ws Value of flash wait state +//------------------------------------------------------------------------------ +void SetFlashWaitState(unsigned char ws) +{ + // Set Wait State for Embedded Flash Access + AT91C_BASE_EFC0->EFC_FMR = ((ws << 8) & AT91C_EFC_FWS); + AT91C_BASE_EFC1->EFC_FMR = ((ws << 8) & AT91C_EFC_FWS); +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/board_lowlevel.h b/Demo/CORTEX_AT91SAM3U256_IAR/system/board_lowlevel.h new file mode 100644 index 000000000..665449b1d --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/board_lowlevel.h @@ -0,0 +1,49 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Collection of methods for lowlevel. +/// +//------------------------------------------------------------------------------ + +#ifndef BOARD_LOWLEVEL_H +#define BOARD_LOWLEVEL_H + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +extern void LowLevelInit(void); +extern void OptimizeCpuSpeed(void); + +#endif // BOARD_LOWLEVEL_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/board_memories.c b/Demo/CORTEX_AT91SAM3U256_IAR/system/board_memories.c new file mode 100644 index 000000000..e029a99a8 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/board_memories.c @@ -0,0 +1,101 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2009, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +/* + Title: Memories implementation +*/ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +/// Dummy function to initialize and configure the SDRAM +//------------------------------------------------------------------------------ +void BOARD_ConfigureSdram(unsigned char busWidth) +{ +} + +//------------------------------------------------------------------------------ +/// Configures the EBI for NandFlash access. Pins must be configured after or +/// before calling this function. +//------------------------------------------------------------------------------ +void BOARD_ConfigureNandFlash(unsigned char busWidth) +{ + AT91PS_HSMC4 pHSMC4 = AT91C_BASE_HSMC4; + AT91PS_HSMC4_CS pSMC = AT91C_BASE_HSMC4_CS1; + + // Open EBI clock + AT91C_BASE_PMC->PMC_PCER = (1<< AT91C_ID_HSMC4); + +#ifdef CHIP_NAND_CTRL + // Enable the Nand Flash Controller + pHSMC4 ->HSMC4_CTRL = AT91C_HSMC4_NFCEN; +#endif + + pSMC->HSMC4_SETUP = 0 + | ((0 << 0) & AT91C_HSMC4_NWE_SETUP) + | ((1 << 8) & AT91C_HSMC4_NCS_WR_SETUP) + | ((0 << 16) & AT91C_HSMC4_NRD_SETUP) + | ((1 << 24) & AT91C_HSMC4_NCS_RD_SETUP); + + pSMC->HSMC4_PULSE = 0 + | ((2 << 0) & AT91C_HSMC4_NWE_PULSE) + | ((3 << 8) & AT91C_HSMC4_NCS_WR_PULSE) + | ((3 << 16) & AT91C_HSMC4_NRD_PULSE) + | ((4 << 24) & AT91C_HSMC4_NCS_RD_PULSE); + + pSMC->HSMC4_CYCLE = 0 + | ((4 << 0) & AT91C_HSMC4_NWE_CYCLE) + | ((7 << 16) & AT91C_HSMC4_NRD_CYCLE); + + pSMC->HSMC4_TIMINGS = 0 + | ((1 << 0) & AT91C_HSMC4_TCLR) // CLE to REN + | ((2 << 4) & AT91C_HSMC4_TADL) // ALE to Data + | ((1 << 8) & AT91C_HSMC4_TAR) // ALE to REN + | ((1 << 16) & AT91C_HSMC4_TRR) // Ready to REN + | ((2 << 24) & AT91C_HSMC4_TWB) // WEN to REN + | (7<<28) + |(AT91C_HSMC4_NFSEL) // Nand Flash Timing + ; + + + if (busWidth == 8) { + pSMC->HSMC4_MODE = AT91C_HSMC4_DBW_WIDTH_EIGTH_BITS | AT91C_HSMC4_READ_MODE | AT91C_HSMC4_WRITE_MODE; + } + else if (busWidth == 16) { + pSMC->HSMC4_MODE = AT91C_HSMC4_DBW_WIDTH_SIXTEEN_BITS | AT91C_HSMC4_READ_MODE | AT91C_HSMC4_WRITE_MODE; + } +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/board_memories.h b/Demo/CORTEX_AT91SAM3U256_IAR/system/board_memories.h new file mode 100644 index 000000000..776788463 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/board_memories.h @@ -0,0 +1,51 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// !Purpose +/// +/// +/// !Usage +/// +//------------------------------------------------------------------------------ + +#ifndef BOARD_MEMORIES_H +#define BOARD_MEMORIES_H + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +extern void BOARD_ConfigureSdram(unsigned char busWidth); + +extern void BOARD_ConfigureNandFlash(unsigned char busWidth); + +#endif //#ifndef BOARD_MEMORIES_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/chip.h b/Demo/CORTEX_AT91SAM3U256_IAR/system/chip.h new file mode 100644 index 000000000..59f048a00 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/chip.h @@ -0,0 +1,99 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// !Purpose +/// +/// Definition of AT91SAM3U4 characteristics and features +/// +/// !Usage +/// -# For ARM core feature, see "AT91SAM3U4 - ARM core features". +/// -# For IP features, see "AT91SAM3U4 - IP features". +/// -# For misc, see "AT91SAM3U4 - Misc". +//------------------------------------------------------------------------------ + +#ifndef CHIP_H +#define CHIP_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "AT91SAM3U4 - ARM core features" +/// This page lists several characteristics related to the ARM core +/// + +//ARM core features + +/// ARM core definition. +#define cortexm3 + +/// family definition. +#define at91sam3u + +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "AT91SAM3U4 - IP features" +/// This page lists several characteristics related to the embedded IP +/// + +//IP FEATURES + +// EFC GPNVM number +#define CHIP_EFC_NUM_GPNVMS 3 + +/// Indicates chip has an Enhanced EFC. +#define CHIP_FLASH_EEFC + +// DMA channels number +#define CHIP_DMA_CHANNEL_NUM 4 + +// Indicate chip has a nandflash controller. +#define CHIP_NAND_CTRL + +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "AT91SAM3U4 - Misc " +/// This page lists misc features +/// + +//Misc + +//------------------------------------------------------------------------------ + +#endif //#ifndef CHIP_H + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/exceptions.c b/Demo/CORTEX_AT91SAM3U256_IAR/system/exceptions.c new file mode 100644 index 000000000..9f4c76ee9 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/exceptions.c @@ -0,0 +1,378 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +/* +** This file contains the default exception handlers +** and exception table. +*/ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "exceptions.h" + +//------------------------------------------------------------------------------ +// Types +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Exception Handlers +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +// Default irq handler +//------------------------------------------------------------------------------ +void IrqHandlerNotUsed(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// Provide weak aliases for each Exception handler to the IrqHandlerNotUsed. +// As they are weak aliases, any function with the same name will override +// this definition. +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// System interrupt +//------------------------------------------------------------------------------ +WEAK void NMI_Handler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +WEAK void HardFault_Handler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +WEAK void MemManage_Handler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +WEAK void BusFault_Handler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +WEAK void UsageFault_Handler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +WEAK void SVC_Handler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +WEAK void DebugMon_Handler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +WEAK void PendSV_Handler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// for Cortex M3 +//------------------------------------------------------------------------------ +WEAK void SysTick_Handler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// External interrupt +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// for SAM7/9 +//------------------------------------------------------------------------------ +void SYS_IrqHandler( void ) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// SUPPLY CONTROLLER +//------------------------------------------------------------------------------ +WEAK void SUPC_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// RESET CONTROLLER +//------------------------------------------------------------------------------ +WEAK void RSTC_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// REAL TIME CLOCK +//------------------------------------------------------------------------------ +WEAK void RTC_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// REAL TIME TIMER +//------------------------------------------------------------------------------ +WEAK void RTT_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// WATCHDOG TIMER +//------------------------------------------------------------------------------ +WEAK void WDT_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// PMC +//------------------------------------------------------------------------------ +WEAK void PMC_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// EFC0 +//------------------------------------------------------------------------------ +WEAK void EFC0_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// EFC1 +//------------------------------------------------------------------------------ +WEAK void EFC1_IrqHandler(void) +{ + while(1); +} +//------------------------------------------------------------------------------ +// DBGU +//------------------------------------------------------------------------------ +WEAK void DBGU_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// HSMC4 +//------------------------------------------------------------------------------ +WEAK void HSMC4_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// Parallel IO Controller A +//------------------------------------------------------------------------------ +WEAK void PIOA_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// Parallel IO Controller B +//------------------------------------------------------------------------------ +WEAK void PIOB_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// Parallel IO Controller C +//------------------------------------------------------------------------------ +WEAK void PIOC_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// USART 0 +//------------------------------------------------------------------------------ +WEAK void USART0_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// USART 1 +//------------------------------------------------------------------------------ +WEAK void USART1_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// USART 2 +//------------------------------------------------------------------------------ +WEAK void USART2_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// USART 3 +//------------------------------------------------------------------------------ +WEAK void USART3_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// Multimedia Card Interface +//------------------------------------------------------------------------------ +WEAK void MCI0_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// TWI 0 +//------------------------------------------------------------------------------ +WEAK void TWI0_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// TWI 1 +//------------------------------------------------------------------------------ +WEAK void TWI1_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// Serial Peripheral Interface 0 +//------------------------------------------------------------------------------ +WEAK void SPI0_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// Serial Synchronous Controller 0 +//------------------------------------------------------------------------------ +WEAK void SSC0_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// Timer Counter 0 +//------------------------------------------------------------------------------ +WEAK void TC0_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// Timer Counter 1 +//------------------------------------------------------------------------------ +WEAK void TC1_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// Timer Counter 2 +//------------------------------------------------------------------------------ +WEAK void TC2_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// PWM Controller +//------------------------------------------------------------------------------ +WEAK void PWM_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// ADC controller0 +//------------------------------------------------------------------------------ +WEAK void ADCC0_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// ADC controller1 +//------------------------------------------------------------------------------ +WEAK void ADCC1_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// HDMA +//------------------------------------------------------------------------------ +WEAK void HDMA_IrqHandler(void) +{ + while(1); +} + +//------------------------------------------------------------------------------ +// USB Device High Speed UDP_HS +//------------------------------------------------------------------------------ +WEAK void UDPD_IrqHandler(void) +{ + while(1); +} diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/exceptions.h b/Demo/CORTEX_AT91SAM3U256_IAR/system/exceptions.h new file mode 100644 index 000000000..3e16df0ba --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/exceptions.h @@ -0,0 +1,135 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +/* +** This file contains the default exception handlers +** and exception table. +*/ + +//------------------------------------------------------------------------------ +// Types +//------------------------------------------------------------------------------ + +/// Function prototype for exception table items - interrupt handler. +//typedef void( *IrqHandler )( void ); +typedef void( *IntFunc )( void ); + +/// Weak attribute + +#if defined ( __CC_ARM ) + #define WEAK __attribute__ ((weak)) +#elif defined ( __ICCARM__ ) + #define WEAK __weak +#elif defined ( __GNUC__ ) + #define WEAK __attribute__ ((weak)) +#endif + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Exception Handlers +//------------------------------------------------------------------------------ + +extern WEAK void NMI_Handler( void ); +extern WEAK void HardFault_Handler( void ); +extern WEAK void MemManage_Handler( void ); +extern WEAK void BusFault_Handler( void ); +extern WEAK void UsageFault_Handler( void ); +extern WEAK void SVC_Handler( void ); +extern WEAK void DebugMon_Handler( void ); +extern WEAK void PendSV_Handler( void ); +extern WEAK void SysTick_Handler( void ); +void IrqHandlerNotUsed(void); + + +// System Controller +extern void SYS_IrqHandler(void); +// SUPPLY CONTROLLER +extern WEAK void SUPC_IrqHandler(void); +// RESET CONTROLLER +extern WEAK void RSTC_IrqHandler(void); +// REAL TIME CLOCK +extern WEAK void RTC_IrqHandler(void); +// REAL TIME TIMER +extern WEAK void RTT_IrqHandler(void); +// WATCHDOG TIMER +extern WEAK void WDT_IrqHandler(void); +// PMC +extern WEAK void PMC_IrqHandler(void); +// EFC0 +extern WEAK void EFC0_IrqHandler(void); +// EFC1 +extern WEAK void EFC1_IrqHandler(void); +// DBGU +extern WEAK void DBGU_IrqHandler(void); +// HSMC4 +extern WEAK void HSMC4_IrqHandler(void); +// Parallel IO Controller A +extern WEAK void PIOA_IrqHandler(void); +// Parallel IO Controller B +extern WEAK void PIOB_IrqHandler(void); +// Parallel IO Controller C +extern WEAK void PIOC_IrqHandler(void); +// USART 0 +extern WEAK void USART0_IrqHandler(void); +// USART 1 +extern WEAK void USART1_IrqHandler(void); +// USART 2 +extern WEAK void USART2_IrqHandler(void); +// USART 3 +extern WEAK void USART3_IrqHandler(void); +// Multimedia Card Interface +extern WEAK void MCI0_IrqHandler(void); +// TWI 0 +extern WEAK void TWI0_IrqHandler(void); +// TWI 1 +extern WEAK void TWI1_IrqHandler(void); +// Serial Peripheral Interface 0 +extern WEAK void SPI0_IrqHandler(void); +// Serial Synchronous Controller 0 +extern WEAK void SSC0_IrqHandler(void); +// Timer Counter 0 +extern WEAK void TC0_IrqHandler(void); +// Timer Counter 1 +extern WEAK void TC1_IrqHandler(void); +// Timer Counter 2 +extern WEAK void TC2_IrqHandler(void); +// PWM Controller +extern WEAK void PWM_IrqHandler(void); +// ADC controller0 +extern WEAK void ADCC0_IrqHandler(void); +// ADC controller1 +extern WEAK void ADCC1_IrqHandler(void); +// HDMA +extern WEAK void HDMA_IrqHandler(void); +// USB Device High Speed UDP_HS +extern WEAK void UDPD_IrqHandler(void); + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/flash.icf b/Demo/CORTEX_AT91SAM3U256_IAR/system/flash.icf new file mode 100644 index 000000000..a7b3a9301 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/flash.icf @@ -0,0 +1,47 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\a_v1_0.xml" */ +/*-Vector table start*/ +define symbol __ICFEDIT_vector_start__ = 0x00080000; /*Add for CMSIS*/ +/*-Memory Regions-*/ +define symbol __ICFEDIT_region_RAM0_start__ = 0x20000000; +define symbol __ICFEDIT_region_RAM0_end__ = 0x20007FFF; +define symbol __ICFEDIT_region_RAM1_start__ = 0x20080000; +define symbol __ICFEDIT_region_RAM1_end__ = 0x20083FFF; +define symbol __ICFEDIT_region_ROM0_start__ = 0x00080000; +define symbol __ICFEDIT_region_ROM0_end__ = 0x0009FFFF; +define symbol __ICFEDIT_region_ROM1_start__ = 0x00100000; +define symbol __ICFEDIT_region_ROM1_end__ = 0x0011FFFF; +/*-Sizes-*/ +define symbol __ICFEDIT_size_cstack__ = 0x800; +define symbol __ICFEDIT_size_heap__ = 0x200; +/*-Specials-*/ +/*define symbol __ICFEDIT_region_RAM_VECT_start__ = __ICFEDIT_region_RAM0_start__;*/ /*Referenced for CMSIS*/ +/*define symbol __ICFEDIT_size_vectors__ = 0x100;*/ /*Referenced for CMSIS*/ +/*-Exports-*/ +/*export symbol __ICFEDIT_region_RAM_VECT_start__;*/ +export symbol __ICFEDIT_vector_start__; /*Add for CMSIS*/ +/**** End of ICF editor section. ###ICF###*/ + +define memory mem with size = 4G; +/*define region RAM_VECT_region = mem:[from __ICFEDIT_region_RAM_VECT_start__ size __ICFEDIT_size_vectors__];*/ /*Referenced for CMSIS*/ +/*define region RAM0_region = mem:[from __ICFEDIT_region_RAM0_start__+__ICFEDIT_size_vectors__ to __ICFEDIT_region_RAM0_end__];*/ /*Referenced for CMSIS*/ +define region RAM0_region = mem:[from __ICFEDIT_region_RAM0_start__ to __ICFEDIT_region_RAM0_end__]; +define region RAM1_region = mem:[from __ICFEDIT_region_RAM1_start__ to __ICFEDIT_region_RAM1_end__]; +/*define region RAM_region = mem:[from __ICFEDIT_region_RAM0_start__+__ICFEDIT_size_vectors__ to __ICFEDIT_region_RAM0_end__] | + mem:[from __ICFEDIT_region_RAM1_start__ to __ICFEDIT_region_RAM1_end__];*/ /*Referenced for CMSIS*/ +define region ROM0_region = mem:[from __ICFEDIT_region_ROM0_start__ to __ICFEDIT_region_ROM0_end__]; +define region ROM1_region = mem:[from __ICFEDIT_region_ROM1_start__ to __ICFEDIT_region_ROM1_end__]; + +/*define block RamVect with alignment = 8, size = __ICFEDIT_size_vectors__ { };*/ +define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; +define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +/*place at start of ROM0_region { readonly section .vectors };*/ /*Referenced for CMSIS*/ +place at address mem:__ICFEDIT_vector_start__ { readonly section .vectors }; /*Add for CMSIS*/ +place in ROM0_region { readonly }; +place in RAM0_region { readwrite, block CSTACK, block HEAP }; +/*place in RAM_VECT_region { block RamVect };*/ /*Referenced for CMSIS*/ \ No newline at end of file diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/led.c b/Demo/CORTEX_AT91SAM3U256_IAR/system/led.c new file mode 100644 index 000000000..7048b2a56 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/led.c @@ -0,0 +1,162 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "led.h" +#include +#include + +//------------------------------------------------------------------------------ +// Local Variables +//------------------------------------------------------------------------------ + +#ifdef PINS_LEDS +static const Pin pinsLeds[] = {PINS_LEDS}; +static const unsigned int numLeds = PIO_LISTSIZE(pinsLeds); +#endif + +//------------------------------------------------------------------------------ +// Global Functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Configures the pin associated with the given LED number. If the LED does +/// not exist on the board, the function does nothing. +/// \param led Number of the LED to configure. +/// \return 1 if the LED exists and has been configured; otherwise 0. +//------------------------------------------------------------------------------ +unsigned char LED_Configure(unsigned int led) +{ +#ifdef PINS_LEDS + // Check that LED exists + if (led >= numLeds) { + + return 0; + } + + // Configure LED + return (PIO_Configure(&pinsLeds[led], 1)); +#else + return 0; +#endif +} + +//------------------------------------------------------------------------------ +/// Turns the given LED on if it exists; otherwise does nothing. +/// \param led Number of the LED to turn on. +/// \return 1 if the LED has been turned on; 0 otherwise. +//------------------------------------------------------------------------------ +unsigned char LED_Set(unsigned int led) +{ +#ifdef PINS_LEDS + // Check if LED exists + if (led >= numLeds) { + + return 0; + } + + // Turn LED on + if (pinsLeds[led].type == PIO_OUTPUT_0) { + + PIO_Set(&pinsLeds[led]); + } + else { + + PIO_Clear(&pinsLeds[led]); + } + + return 1; +#else + return 0; +#endif +} + +//------------------------------------------------------------------------------ +/// Turns a LED off. +/// \param led Number of the LED to turn off. +/// \param 1 if the LED has been turned off; 0 otherwise. +//------------------------------------------------------------------------------ +unsigned char LED_Clear(unsigned int led) +{ +#ifdef PINS_LEDS + // Check if LED exists + if (led >= numLeds) { + + return 0; + } + + // Turn LED off + if (pinsLeds[led].type == PIO_OUTPUT_0) { + + PIO_Clear(&pinsLeds[led]); + } + else { + + PIO_Set(&pinsLeds[led]); + } + + return 1; +#else + return 0; +#endif +} + +//------------------------------------------------------------------------------ +/// Toggles the current state of a LED. +/// \param led Number of the LED to toggle. +/// \return 1 if the LED has been toggled; otherwise 0. +//------------------------------------------------------------------------------ +unsigned char LED_Toggle(unsigned int led) +{ +#ifdef PINS_LEDS + // Check if LED exists + if (led >= numLeds) { + + return 0; + } + + // Toggle LED + if (PIO_GetOutputDataStatus(&pinsLeds[led])) { + + PIO_Clear(&pinsLeds[led]); + } + else { + + PIO_Set(&pinsLeds[led]); + } + + return 1; +#else + return 0; +#endif +} + diff --git a/Demo/CORTEX_AT91SAM3U256_IAR/system/led.h b/Demo/CORTEX_AT91SAM3U256_IAR/system/led.h new file mode 100644 index 000000000..3f4878f55 --- /dev/null +++ b/Demo/CORTEX_AT91SAM3U256_IAR/system/led.h @@ -0,0 +1,70 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Small set of functions for simple and portable LED usage. +/// +/// !Usage +/// +/// -# Configure one or more LEDs using LED_Configure and +/// LED_ConfigureAll. +/// -# Set, clear and toggle LEDs using LED_Set, LED_Clear and +/// LED_Toggle. +/// +/// LEDs are numbered starting from 0; the number of LEDs depend on the +/// board being used. All the functions defined here will compile properly +/// regardless of whether the LED is defined or not; they will simply +/// return 0 when a LED which does not exist is given as an argument. +/// Also, these functions take into account how each LED is connected on to +/// board; thus, might change the level on the corresponding pin +/// to 0 or 1, but it will always light the LED on; same thing for the other +/// methods. +//------------------------------------------------------------------------------ + +#ifndef LED_H +#define LED_H + +//------------------------------------------------------------------------------ +// Global Functions +//------------------------------------------------------------------------------ + +extern unsigned char LED_Configure(unsigned int led); + +extern unsigned char LED_Set(unsigned int led); + +extern unsigned char LED_Clear(unsigned int led); + +extern unsigned char LED_Toggle(unsigned int led); + +#endif //#ifndef LED_H +