0
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心
发布
  • 发文章

  • 发资料

  • 发帖

  • 提问

  • 发视频

创作活动
AT91C140_05

AT91C140_05

  • 厂商:

    ATMEL(爱特梅尔)

  • 封装:

  • 描述:

    AT91C140_05 - AT91 ARM Thumb Microcontrollers - ATMEL Corporation

  • 数据手册
  • 价格&库存
AT91C140_05 数据手册
Features • ARM7TDMI® ARM® Thumb® Processor Core – In-Circuit Emulator, 36 MHz Operation • Ethernet Bridge – Dual Ethernet 10/100 Mbps MAC Interface – 16-Kbyte Frame Buffer 1 K-Byte Boot ROM, Embedding a Boot Program – Enable Application Download from DataFlash® External Bus Interface – On-chip 16-bit SDRAM Controller – 4-Chip Select Static Memory Controller Multi-level Priority, Individually Maskable, Vectored Interrupt Controller Three 16-bit Timer/Counters Two UARTs with Modem Control Lines Serial Peripheral Interface (SPI) Two PIO Controllers, Managing up to 48 General-purpose I/O Pins Available in a 208-lead PQFP Package Power Supplies – VDDIO 3.3V nominal – VDDCORE and VDDOSC 1.8V nominal -40°C to + 85°C Operating Temperature Range • • • • • • • • • AT91 ARM® Thumb® Microcontrollers AT91C140 • 1. Description The AT91C140 is a member of the Atmel AT91 16- and 32-bit microcontroller family based on the ARM7TDMI processor core. This processor has a high performance 32-bit RISC architecture with a high density 16-bit instruction set and very low power consumption. In addition, the AT91C140 integrates a double Ethernet 10/100 base-T MAC capable of operating as an Ethernet bridge, thus making it ideally suited for networking applications. It supports a wide range of memory devices such as SDRAM, SRAM and Flash and embeds an extensive array of peripherals. The device is manufactured using Atmel’s high-density CMOS technology. By combining the ARM7TDMI processor core with an expansive assortment of peripheral functions and low-power oscillators and PLL on a monolithic chip, the Atmel AT91C140 is a powerful microcontroller that provides a highly flexible and cost effective solution to many networking applications. 6069C–ATARM–15-Sep-05 2. Block Diagram Figure 2-1. AT91C140 Block Diagram JTAG Debug Interface ICE ARM7TDMI Processor Boot ROM External Bus Interface MII PHY Interface Ethernet 10/100 Mbps MAC Interface ASB/ASB Bridge SDRAMC 16-bit Data Memory Bus SMC MII PHY Interface Ethernet 10/100 Mbps MAC Interface 32k Bytes SRAM Peripheral Data Controller Peripheral Bridge OSC PLL Interrupt and Fast Interrupt Advanced Interrupt Controller USART A Serial Port System Controller SPI Serial Peripherals Boot DataFlash USART B I/O Lines PIO Controller A Timer/Counter 0 I/O Lines PIO Controller B Timer/Counter 1 Timer/Counter 2 Serial Port PWM Signals PWM Signals PWM Signals 2 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 3. Pinout Table 3-1. Pin Number 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 Pinout for 208-lead PQFP Package Signal Name GND GND VDDIO GND NC(1) GND NTRST MA_COL MA_CRS MA_TXER MA_TXD0 MA_TXD1 MA_TXD2 MA_TXD3 MA_TXEN VDDIO MA_TXCLK GND MA_RXD0 MA_RXD1 MA_RXD2 MA_RXD3 MA_RXER MA_RXCLK GND VDDCORE MA_RXDV MA_MDC MA_MDIO MA_LINK MB_COL MB_CRS GND VDDCORE VDDIO MB_TXER Pin Number 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 Signal Name MB_TXD0 MB_TXD1 MB_TXD2 GND MB_TXD3 MB_TXEN MB_TXCLK MB_RXD0 MB_RXD1 MB_RXD2 MB_RXD3 MB_RXER MB_RXCLK MB_RXDV MB_MDC VDDIO GND MB_MDIO MB_LINK A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 VDDIO GND A13 A14 Pin Number 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 Signal Name A15 A16 A17 A18 A19B/A0 A20/BA1 A21 D0 D1 D2 D3 GND D4 VDDIO D5 D6 D7 D8 D9 D10 D11 D12 D13 D14 VDDCORE GND D15 VDDIO GND VDDIO NC(1) VDDIO GND SDCK SDCS SDA10 Pin Number 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 Signal Name RAS CAS NC(1) WE DQM0 DQM1 NC(1) GND NC(1) VDDCORE GND VDDOSC PLLRC GND GND XTALOUT XTALIN VDDCORE NCE0 NCE1 NCE2 VDDIO NCE3 NWE0 NWE1 NC(1) VDDIO GND NC(1) NWR NSOE GND VDDCORE VDDIO MISO MOSI 3 6069C–ATARM–15-Sep-05 Table 3-1. Pin Number 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 Pinout for 208-lead PQFP Package (Continued) Signal Name SPCK PA22 VDDIO GND NRST FIQ IRQ0 TST GND VDDCORE NC (1) Pin Number 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 Signal Name TMS TCK PA19 VDDCORE GND PA12 GND VDDIO PA11 PA10 PA9 PA8 PA7 PA6 VDDIO NC (1) Pin Number 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 Signal Name PA5 PA4 PA3 PA2 PA1 PA0 GND RXDA TXDA NRSTA NCTSA NDTRA NDSRA NDCDA RXDB TXDB Pin Number 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 Signal Name GND PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7 PB8 PB9 VDDIO GND GND GND VDDIO VDDIO GND VDDIO TDO TDI Note: 1. NC leads should be left unconnected. 3.1 Mechanical Overview of the 208-lead PQFP Package Figure 3-1 below shows the orientation of the 208-lead PQFP package. For a detailed mechanical description, see ”Mechanical Characteristics and Packaging” on page 165. Figure 3-1. 208-lead PQFP Package Orientation (Top View) 156 157 105 104 208 1 52 53 4 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 4. Peripheral Multiplexing on PIO Lines The AT91C140 features two PIO Controllers, PIOA and PIOB, multiplexing I/O lines of the peripheral set. The PIO Controller A manages 15 I/O lines, PA0 to PA12, PA19 and PA22. The PIO Controller B manages only 10 I/O lines, PB0 to PB9. Each I/O line of a PIO Controller can be multiplexed with a peripheral I/O. Multiplexing of the PIO Controller A is given in Table 4-1 on page 6. Multiplexing of the PIO Controller B is given in Table 4-2 on page 6. 5 6069C–ATARM–15-Sep-05 4.1 PIO Controller A Multiplexing Multiplexing on PIO Controller A Peripheral Signal Name Description Type Table 4-1. I/O Line Name PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7 PA8 PA9 PA10 PA11 PA12 PA19 PA22 TCLK0 TIOA0 TIOB0 SCKA NPCS1 ACLKO NPCS0 Timer Counter Clock Input 0 Timer Counter I/O LIne A 0 Timer Counter I/O LIne B 0 UART A Serial Clock Serial Peripehral Chip Select 1 ARM System Clock Serial Peripheral Chip Select 0 Input I/O I/O I/O Output Output I/O 4.2 PIO Controller B Multiplexing Multiplexing on PIO Controller B Peripheral Signal Name TCLK1 TIOA1 TIOB1 Description Timer Counter Clock Input 1 Timer Counter I/O LIne A 1 Timer Counter I/O LIne B 1 Type Input I/O I/O Table 4-2. I/O Line Name PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7 PB8 PB9 NRIA UART A Ring Indicator Input 6 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 5. Signal Description Table 5-1. Block Signal Description Signal Name VDDIO VDDCORE Function I/O Lines Power Supply Device Core Power Supply PLL and Oscillator Power Supply Ground Address Bus Data Bus SDRAM Clock SDRAM Byte Masks SDRAM Chip Select SDRAM Address Line 10 Row Address Strobes Column Address Strobes Write Enable Bank Address Line Chip Selects Byte Select/Write Enable Output Enable Memory Block Write Enable PIO Controller A I/O Lines PIO Controller B I/O Lines Timer Counter Clock 0 to 2 Timer Counter I/O Line A 0 to 2 Timer Counter I/O Line B 0 to 2 Master In/Slave Out Master Out/Slave In Serial Clock Peripheral Chip Select 0/Slave Select Peripheral Chip Select 1 to 3 Output Input/Output Output Output Output Output Output Output Output Output Output Output Output Output Input/Output Input/Output Input Input/Output Input/Output Input/Output Input/Output Input/Output Input/Output Output Type Power Supplies VDDOSC GND A0-A23 External Bus Interface D0-D15 SDCK DQM0-DQM1 SDCS Synchronous Dynamic Memory Controller SDA10 RAS CAS WE BA0-BA1 NCE0-NCE3 NWE0-NWE1 Static Memory Controller NSOE NWR PIO Controller A PIO Controller B PA0-PA12, PA19, PA22 PB0-PB9 TCLK0-TCLK2 Timer Counter TIOA0-TIOA2 TIOB0-TIOA2 MISO MOSI Serial Peripheral Interface SPCK NPCS0/NSS NPCS1-NPCS3 7 6069C–ATARM–15-Sep-05 Table 5-1. Block Signal Description (Continued) Signal Name RXDA-RXDB TXDA-TXDB NRTSA-NRSTB NCTSA-NCTSB Function Receive Data Transmit Data Ready to Send Clear to Send Data Terminal Ready Data Set Ready Data Carrier Detect Ring Indicator UART Serial Clock MAC A Collision Detect MAC A Carrier Sense MAC A Transmit Error MAC A Transmit Data Bus MAC A Transmit Enable MAC A Transmit Clock MAC A Receive Data Bus MAC A Receive Error MAC A Receive Clock MAC A Receive Data Valid MAC A Management Data Clock MAC A Management Data Bus MAC A Link Interrupt MAC B Collision Detect MAC B Carrier Sense MAC B Transmit Error MAC B Transmit Data Bus MAC B Transmit Enable MAC B Transmit Clock MAC B Receive Data Bus MAC B Receive Error MAC B Receive Clock MAC B Receive Data Valid MAC B Management Data Clock MAC B Management Data Bus MAC B Link Interrupt Type Input Output Output Input Output Input Input Input I/O Input Input Output Output Output Input Input Input Input Output Output Input/Output Input Input Input Output Output Output Input Input Input Input Output Output Input/Output Input UART A and UART B NDTRA-NDTRB NDSRA-NDSRB NDCDA-NDCDB NRIA-NRIB SCKA MA_COL MA_CRS MA_TXER MA_TXD0-MA_TXD3 MA_TXEN MA_TXCLK MAC A Interface MA_RXD0-MA_RXD3 MA_RXER MA_RXCLK MA_RXDV MA_MDC MA_MDIO MA_LINK MB_COL MB_CRS MB_TXER MB_TXD0-MB_TXD3 MB_TXEN MB_TXCLK MAC B Interface MB_RXD0-MB_RXD3 MB_RXER MB_RXCLK MB_RXDV MB_MDC MB_MDIO MB_LINK 8 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 Table 5-1. Block Signal Description (Continued) Signal Name NTRST TCK Function Test Reset Test Clock Test Mode Select Test Data Input Test Data Output Reset Fast Interrupt Interrupt Lines PLL RC Filter Crystal Input External Crystal Test Mode ARM Clock Output Type Input Input Input Input Output Input Input Input Analog Analog Analog Input Output In-Circuit Emulator TMS TDI TDO NRST FIQ IRQ0-IRQ1 PLLRC Miscellaneous XTALIN XTALOUT TST ACLKO 9 6069C–ATARM–15-Sep-05 6. ARM7TDMI Core The ARM7TDMI is a three-stage pipeline, 32-bit RISC processor. The processor architecture is Von Neumann load/store architecture, characterized by a single data and address bus for instructions and data. The CPU has two instruction sets: the ARM and the Thumb instruction set. The ARM instruction set has 32-bit wide instructions and provides maximum performance. Thumb instructions are 16-bit wide and give maximum code density. Instructions operate on 8-bit, 16-bit and 32-bit data types. The CPU has seven operating modes. Each operating mode has dedicated banked registers for fast exception handling. The processor has a total of 37 32-bit registers, including six status registers. 7. Power Supplies The AT91C140 has three types of power supply pins: • VDDCORE pins power the core, including the ARM7TDMI processor, the memories and the peripherals; voltage is between 1.65V and 1.95V, 1.8V nominal. • VDDIO pins power the I/O lines, including those of the External Bus Interface and those of the peripherals; voltage is between 3V and 3.6V, 3.3V nominal. • VDDOSC pins power the PLL and oscillator cells; voltage is between 1.65V and 1.95V, 1.8V nominal. Ground pins are common to all power supplies. 10 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 8. System Controller The AT91C140 features a System Controller that takes care of and controls: • the Test Mode • the Reset • the System Clocks • the Chip Identifier The System Controller manages the reset of all the system and integrates a clock generator, made up of an oscillator and a PLL. 8.1 Test The AT91C140 features a test pin (TST). This pin must be tied low for normal operations. Using the AT91C140 with the TST pin at a high level might lead to unpredictable results. 8.2 8.2.1 Reset Controller NRST Pin The AT91C140 is reset by asserting the NRST pin low. It should be asserted for a time adequate to ensure the startup of the oscillator on a power on, and at least 1 ACLK cycle for a warm reset. As the ACLK switches on the 31,25kHz (assuming the crystal is at 16 MHz) as soon as the reset is asserted, it must remain low for at least 32 µs. The first instruction fetch happens 10 ACLK cycles after the reset releases. 8.2.2 System Reset A reset initializes the user interface registers to their default states as defined in the peripheral sections of this datasheet and forces the ARM7TDMI to perform the next instruction fetch from address zero. Except for the program counter and the Current Program Status Register, the ARM processor registers do not have defined reset states. When NRST is active, the inputs of the AT91C140 must be held at valid logic levels to reduce the power consumption to a minimum. 8.2.3 Boot Memory and Remap Command When NRST is released, the PA0 pin is sampled to determine if the ARM processor should boot from internal ROM or from external memory connected to NCE0. The details of the boot operations are described in ”Memory Controller (MC)” on page 16. The Boot Program is described in ”Boot Program” on page 24. After a reset, the RM bit in the Mode Register reflects the state of the PA0 pin. Then, writing this bit at 1 removes the ROM from the address 0. Writing it at 0 remaps the ROM at address 0x0. 8.3 Clock Generator The AT91C140 features a Clock Generator based on a 16 MHz oscillator and a PLL. It provides all the clocks of the system, including a clock signal named ACLK, to the ARM processor, to the memory controller and to the External Bus Interface and to all the embedded peripherals The ACLK signal is also provided on the ACLKO pin, through PIO Controller A. Figure 8-1 below shows the architecture of the Clock Generator. 11 6069C–ATARM–15-Sep-05 Figure 8-1. Clock Generator LP LPCS Counter and Control Logic DIV SA DIV7 1 0 1 RDY XTALIN 16 MHz Crystal XTALOUT ACLK 16MHz Oscillator LP DIV6 0 ACLKO PLLRC PLL x15 240 MHz After the reset, the ACLK clock is running at 31.25 kHz. The user can program the LPCS field to speed the boot sequence. The ACLKST (ARM Clock Status) bit reflects the clock being used for the ARM. When read at 0, ACLK is 40 MHz if SA is 0 and 34.3 MHz if SA is 1. When read at 1, ACLK is at a frequency according to the value programmed in the LPCS field in the System Mode Register (SYS_MR). 8.4 Chip ID The System Controller features a Chip ID Register that reads a value of 0x00010221 12 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 8.5 System Controller User Interface System Controller Register Mapping Register Name SYS_MD SYS_ID Reserved SYS_CLKF System Clock Status Register Read-only 0x0000001 Register Description System Mode Register System ID Register Access Read/Write Read-only Reset Value 0x0000 034x 0x0001 0221 Base Address: 0xFF00 0000. Table 8-1. Offset 0x0 0x4 0x8 0xC 13 6069C–ATARM–15-Sep-05 8.5.1 System Mode Register SYS_MD Read/Write 30 – 22 – 14 0 6 LP 29 – 21 – 13 – 5 – 28 – 20 – 12 0 4 – 27 – 19 – 11 – 3 0 26 – 18 – 10 – 2 – 25 – 17 – 9 LPCS 1 0 0 RM 24 – 16 – 8 Register Name: Access: 31 – 23 – 15 – 7 SA • RM: Remap 0 =The ROM is mapped only at its normal address. 1 =The ROM is mapped at its address and at address 0x0. • LP: Low Power Mode 0 =The PLL is enabled and ACLK is the output of the PLL divided by 6 or 7. 1 =The PLL is disabled and ACLK is defined by LPCS. • SA: Slow ARM 0 =The ARM divider is 6. 1 =The ARM divider is 7. • LPCS: Low Power Clock Select LPCS 0 0 1 1 0 1 0 1 Divisor 2 16 64 512 ACLK 8 MHz 1 MHz 250 kHz 31,25 kHz 14 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 8.5.2 System ID Register SYS_ID Read-only 30 0 22 0 14 0 6 0 29 0 21 0 13 0 5 1 28 0 20 0 12 0 4 0 27 0 19 0 11 0 3 0 26 0 18 0 10 0 2 0 25 0 17 0 9 1 1 0 24 0 16 1 8 0 0 1 Register Name: Access: 31 0 23 0 15 0 7 0 8.5.3 System Clock Status Register SYS_CLKF Read-only 30 – 22 – 14 – 6 – 29 – 21 – 13 – 5 – 28 – 20 – 12 – 4 – 27 – 19 – 11 – 3 – 26 – 18 – 10 – 2 – 25 – 17 – 9 – 1 – 24 – 16 – 8 – 0 ACLKST Register Name: Access: 31 – 23 – 15 – 7 – • ACLKST: ARM Clock Status 0 = ARM Clock currently using the 240 MHz source (PLL). 1 = ARM Clock currently using the 16 MHz source (oscillator). 15 6069C–ATARM–15-Sep-05 9. Memory Controller (MC) 9.1 Architecture The AT91C140 architecture is made up of two Advanced System Buses, the ARM ASB and the MAC ASB. Both handle a single memory space. The ARM ASB handles the access requests of the ARM7TDMI and the PDC. It also handles the access requests coming from the MAC ASB. It connects with the External Bus Interface, the Peripheral Bridge and the Internal Memories. It also connects with the MAC ASB. The MAC ASB handles the access requests of the DMAs of both Ethernet MACs. It also handles the access requests coming from the the ARM ASB. It connects essentially with the Frame Buffer, but also connects with the ARM ASB. The major advantage of this double-ASB architecture is that the Ethernet traffic does not occupy the main ASB bandwidth, ensuring that the ARM7TDMI can perform at its maximum speed while the Ethernet traffic goes through the Frame Buffer. The AT91C140 architecture is shown in Figure 9-1. Figure 9-1. AT91C140 Memory Controller Architecture PA0 Memory Controller ARM ASB ARM7TDMI Processor Internal ROM Main Bus Arbiter External Bus Interface ASB-ASB Bridge Peripheral Data Controller From Master to Slave MACA DMA Secondary Bus Arbiter MACB DMA MAC ASB Peripheral Bridge APB Frame Buffer 16 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 9.2 Memory Map The AT91C140 memory map is divided into regions of 256 megabytes. The top memory region (0xF000_0000) is reserved and subdivided for the internal memories and shared memory and the embedded peripherals. The device can define up to five other active external memory regions by means of the static memory controller and SDRAM memory controller. The memory map is divided between both ASBs, as shown in Figure 9-1. All regions except the 16 megabytes between 0xFC00 0000 and 0xFCFF FFFF are located on the Main ASB. Accesses to locations between 0xFC00 0000 and 0xFCFF FFFF are routed to the MAC ASB. The memory map assumes default values on reset. External memory regions can be reprogrammed to other base addresses in the Static Memory Controller or in the SDRAM Controller. Note that the internal memory regions have fixed locations that cannot be reprogrammed. There are no hardware locks to prevent incorrect programming of the regions. Programming two or more regions to have the same base address or overlapping two memory regions results in undefined behavior. The ARM processor reset vector at address 0x00000000 is mapped into the internal ROM or external memory connected on NCE0. This selection depends on the PA0 signal pin. After booting, the ROM region can be disabled and any external memory can be mapped to the bottom of the memory map by programming SMC_CSRx or SDRAMC_ADDR. Figure 9-2. AT91C140 Memory Map 256M bytes 256M bytes 256M bytes 256M bytes 0x0000 0000 0x0FFF FFFF External Static Memory connected on NCE0 External Static Memory connected on NCE1 External Static Memory connected on NCE2 External Static Memory connected on NCE3 External Static Memory connected on SDCS SDRAMC 0x1000 0000 0x1FFF FFFF 0x2000 0000 0x2FFF FFFF SMC 0x3000 0000 0x3FFF FFFF 0x4000 0000 256M bytes 0x4FFF FFFF 0x5000 0000 10 x 256M bytes Unused 0xEFFF FFFF 256M bytes 0xF000 0000 0xFFFF FFFF Internal Memories and Peripherals 17 6069C–ATARM–15-Sep-05 F igure 9-3 below shows the mapping of the internal memories and the address space reserved for the Peripheral Bridge. Figure 9-3. Internal Memory Mapping Actual Size 0xFF00 0000 144M bytes 0xF8FF FFFF Reserved 0xF900 0000 0xF9FF FFFF 0xFA00 0000 16M bytes 16M bytes ROM Reserved 1K byte 512 bytes 0xFAFF FFFF 0xFB00 0000 16M bytes 0xFBFF FFFF Reserved 0xFC00 0000 Frame Buffer Reserved 0xFDFF FFFF 0xFD00 0000 16M bytes 16M bytes 16M bytes 16M bytes 16K bytes 64K bytes 0xFCFF FFFF 0xFD00 0000 Unused 0xEFFF FFFF 0xFF00 0000 0xFFFF FFFF Peripherals 9.3 ARM ASB Arbitration The ARM ASB is arbitrated with the following priorities: • The PDC has the highest priority. • The Bridge from the MAC ASB has the middle priority. • The ARM processor has the lowest priority. 9.4 MAC ASB Arbitration The MAC ASB is arbitrated with the following priorities: • The Bridge from the ARM ASB has the highest priority. • The MAC A has the middle priority. • The MAC B has the lowest priority. 9.5 ASB-ASB Bridge Arbitration The MAC ASB has two priority levels; the two MACs share low priority access and the ASBASB Bridge has high priority. The MACs do not burst more than four words per access and release the bus request between accesses so the MACs share a priority level with a simple round-robin arbitration scheme. The ARM is likely to be the only master accessing the MAC bus via the bridge and should not perform more than a couple of cycles before releasing the MAC bus. Care should be taken to prevent other masters on the ARM bus holding the MAC bus for more than a few cycles. Otherwise, the MACs drop frames due to FIFO overflow or underflow. When a master on one bus accesses a slave on the other bus, the following operations occur: 18 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 • The local bus arbiter arbitrates the master’s request for the local ASB bus if it does not already have access to the bus. • When the local bus arbiter grants the local bus to the master, the master initiates a cycle with an address corresponding to a slave on the remote bus. • The bridge is selected as the slave on the local bus and responds by inserting wait cycles. The bridge also requests the remote bus from the remote bus arbiter. • When the bridge is granted the remote bus, the two ASB buses are coupled and the transfer completes. The ASB performs pipelined arbitration. The ASB-ASB Bridge can only request the bus when the address of the slave is available. For this reason, the ASB-ASB Bridge inserts a wait cycle during the arbitration cycle on the remote bus because it cannot request the bus early. 9.6 Boot Mode The AT91C140 has an integrated 1-Kbyte ROM to support the boot software. When the device is released from reset, the pin PA0 is sampled by the Memory Controller. If sampled low, the internal ROM becomes accessible from the address 0x0, so that the ARM processor starts execution of the Boot Program. Note that the ROM remains accessible at its normal address. If the pin PA0 is sampled high at reset, the mapping does not change and the external memory connected on NCE0 should contain a valid boot sequence. The level of the pin PA0 at resets is indicated by the RM flag in the System Mode Register (SYS_MD). Then, the RM bit can be written at any value to map to or remove the ROM from address 0x0. If PA0 is asserted on reset, the Boot Program in ROM is executed. The Boot Program is described in ”Boot Program” on page 24. Figure 9-4 below shows the mapping of the ROM depending on the Boot Mode. Figure 9-4. ROM Mapping Depending on the Boot Mode RM = 0 1K byte 0x0000 0000 0x0000 03FF RM = 1 ROM 0x0000 0400 256M bytes External Memory Connected on NCE0 External Memory Connected on NCE0 0x0FFF FFFF 19 6069C–ATARM–15-Sep-05 9.7 Endianness The AT91C140 Memory Controller operates in little-endian mode only. The user has to make sure that the data structures used by the ARM7TDMI, the Ethernet DMAs and the PDC are compliant with this mode of byte arrangement. 20 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 10. Peripherals The Peripheral Bridge allows access to the embedded peripheral user interfaces. It is optimized for low power consumption, as it is built without usage of any clock. However, any access on the peripheral is performed in two cycles. The AT91C140 peripherals are designed to be programmed with a minimum number of instructions. Each peripheral has 16K bytes of address space allocated in the upper part of the address space. 10.1 Peripheral Registers All of the peripheral registers are 32-bits wide and support only aligned accesses. When a misaligned access is performed within the peripheral address space, the access is automatically performed at the lower aligned address. All undefined or unused register bits (marked “-”) read 0. It is recommended to write them at 0 for software upward compatibility. 21 6069C–ATARM–15-Sep-05 10.2 Peripheral Memory Map Figure 10-1 below gives the mapping of the peripherals integrated in the AT91C140. Figure 10-1. Peripheral Memory Map Peripheral Name 0xFF00 0000 SYSC 0xFF00 3FFF Size System Controller 16K bytes 0xFF00 4000 SMC 0xFF00 7FFF Static Memory Controller 16K bytes 0xFF00 8000 0xFF00 BFFF SDRAMC SDRAM Controller 16K bytes 0xFF00 C000 0xFF00 FFFF PIOA Parallel I/O Controller A 16K bytes 0xFF01 0000 0xFF01 3FFF PIOB Parallel I/O Controller B 16K bytes 0xFF01 4000 0xFF01 7FFF TC0, TC1, TC2 Timer Counter Channel 0, 1 and 2 16K bytes 0xFF01 8000 0xFF01 BFFF UART A Universal Asynchronous Receiver Transmitter A Universal Asynchronous Receiver Transmitter B Serial Peripheral Interface 16K bytes 0xFF01 C000 0xFF01 FFFF UART B 16K bytes 0xFF02 0000 0xFF02 3FFF 0xFF02 4000 SPI 16K bytes Reserved 0xFF02 FFFF 0xFF03 0000 0xFF03 3FFF AIC Advanced Interrupt Controller 16K bytes 0xFF03 4000 0xFF03 7FFF MACA Ethernet MAC A 16K bytes AIC is mapped at both addresses 0xFF03 8000 0xFF03 BFFF 0xFF03 C000 MACB Reserved Ethernet MAC B 16K bytes 0xFFFF EFFF 0xFFFF F000 0xFFFF FFFF AIC Advanced Interrupt Controller 16K bytes 22 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 11. Peripheral Data Controller (PDC) 11.1 PDC Overview The AT91C140 features a six-channel Peripheral Data Controller (PDC) dedicated to the two on-chip UARTs and the SPI. One PDC channel is connected to the receiving channel and one to the transmitting channel of each UART and of the SPI. Each PDC channel operates as DMA (Direct Memory Access). The User Interface of a PDC channel is integrated in the memory space of each peripheral. It contains a 32-bit address pointer register and a 16-bit count register. When the programmed number of bytes is transferred, an end-of-transfer signal is sent to the peripheral and is visible in the peripheral status register. This status bit might trigger an interrupt. 11.2 PDC Channel Priority The transfer requests from the peripherals are treated in the order they happen. When several transfer requests happen in the same cycle, the following priority order is applied: • the UART A receiver • the UART A transmitter • the UART B receiver • the UART B transmitter • the SPI receiver • the SPI transmitter 23 6069C–ATARM–15-Sep-05 12. Boot Program The AT91C140 can boot in several ways as explained below. When the ARM7TDMI processor is released from reset it basically attempts a fetch from address 0x00000000. Depending on an hardware configuration, the memory mapping can be altered and thus modify how the system boots. 12.1 Boot Mode When the master reset is released, the pin PA0 is latched. Its state defines how the system boots. When PA0 is latched at 1, the AT91C140 is said to be configured in external boot mode. The initial state of the EBI maps the 1-Mbyte address range starting from 0x00000000 in the external device selected by NCE0. In this boot mode, NCE0 is assumed to be connected to an external memory device containing the suitable boot code. When PA0 is latched at 0, the AT91C140 is said to be configured in internal boot mode. The internal boot ROM normally located at base address 0xf9000000 is aliased at address 0x00000000. In this boot mode, the ARM Processor executes the first instructions out of the internal boot ROM. The boot mode is reflected by the RM bit in register SYS_MD. Reading RM at 0 indicates that the boot ROM is aliased at base address 0x00000000, eventually overlapping the memory layout defined by the SMC and the SDRAMC registers. Reading RM at 1 indicates that the boot ROM can be accessed only from base address 0xf9000000. Writing RM allows to select the mapping of the boot ROM under software control. 12.2 Hardware Connection of the DataFlash The internal boot software provides the AT91C140 with the capability of booting from an external serial DataFlash connected on the on-chip SPI interface as described above. When the internal boot software is used in conjunction with DataFlash, the latter must be connected to the AT91C140 as shown below in Figure 12-1. Figure 12-1. DataFlash Connection AT91C140 NPCS0/PA22 MOSI MISO SPCK DataFlash CS SI SO CK 12.3 Internal Boot Software The internal boot code goes through the following steps in sequence: • The processor enters the supervisor mode and all the interrupts are masked. • A branch is executed into the ROM alias based from 0xf9000000. • The ROM alias based at 0x00000000 is removed by writing the RM bit at 1. • The clock is programmed at the highest frequency achievable without using the on-chip PLL (i.e. the frequency of the crystal divided by 2). 24 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 • The on-chip SPI interface is setup to prepare for communications with DataFlash. • A bunch of data is downloaded from the DataFlash. This data is expected to contain a formatted header describing the contents of the DataFlash. • This header is analyzed to verify whether a DataFlash is actually present and contains valid executable code. • If the DataFlash is there and contains valid executable code, this code is downloaded into a location specified by the header, and an absolute branch to this code is performed. • If the DataFlash is missing, or if the header is not valid, an absolute branch to address 0x00000000 is performed. A suitable memory device should be mapped at this address and contain the expected code. 12.4 DataFlash Header Details To ensure correct operation of the boot out of DataFlash, the DataFlash must contain a valid header. This header contains several fields which define how the application software residing further must be handled. The structure of the DataFlash header is illustrated below in Table 12-1. Table 12-1. (1) Header Structure Field Name MAGIC DSRC DDST DSIZE ENTRY Field Length 4 bytes 4 bytes 4 bytes 4 bytes 4 bytes Field Address 0x00 0x04 0x08 0x0c 0x10 Note: 1. The field address is respective to the DataFlash space. 0x00 corresponds to the first location of the DataFlash. The MAGIC field contains a predefined magic number which allows identification of the suitability of the DataFlash. The value of this field must be 0x0075C221 to allow the boot routine to proceed. If another value is read, the boot code gives up the download and branches to 0x0000 0000 where the real application code is expected. The DSRC field contains the address where the code to be downloaded resides in DataFlash. This address is respective to the DataFlash address space (not the ARM Processor address space) and follows the non-linear addressing scheme defined in the documentation of the DataFlash. Note that all bits are not necessarily significant, depending on the specific DataFlash device. The DDST field contains the destination address where the downloaded code will be copied. This address is respective to the ARM Processor address space. Typically, this address should point into some internal RAM. The DSIZE field contains the number of bytes to be downloaded. This value is exclusive of the header. It must be even. The ENTRY field contains the address where the boot routine must branch when the download is complete. It is the entry point of the newly downloaded software. Although this is not required, the ENTRY field equals the DDST field in most cases. 25 6069C–ATARM–15-Sep-05 12.5 Reserved Resources The internal boot code needs some resources to operate correctly, especially as it programs some on-chip peripherals. These must not be assumed to be in their reset state when the control is given to the application code. The concerned peripherals are: • the clock management system • the SPI interface • the PIO pin PA22 • the RM bit The internal boot code also uses some internal RAM locations to store temporary data. These reside in the first 64 bytes of RAM, i.e. from 0xFD00 FFC0 to 0xFD00 FFFF. The DDST, DSIZE fields of the DataFlash header must not define a memory area overlapping the locations used by the internal boot routine. The ENTRY field must not point into this area. 26 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 13. External Bus Interface (EBI) The External Bus Interface (EBI) generates the signals that control access to external memories or peripheral devices. It contains two controllers, the SDRAM Controller and the Static Memory Controller and manages the sharing of data and address busses between both of these controllers. 13.1 Signal Multiplexing Signal Description and Multiplexing Description Data Bus Address Lines 0 to 9 Address Line 10 SDRAM Controller Address Line 10 Address Lines 11 to 12 Address Lines 13 to 18 Address Line 19 or Bank Address 0 Address Line 20 or Bank Address 1 Address Lines 21 to 23 SDRAM Clock SDRAM Controller Chip Select SDRAM Row Signal SDRAM Column Signal SDRAM Write Enable SDRAM Data Mask Enable Signals Active low chip enable Active low byte select/write strobe signals Active low write strobe signals Active low read enable signal NCE0-NCE3 NWE0-NWE1 NWR NSOE [A12:11] [A18:13] A19 A20 [A23:21] SDCK SDCS RAS CAS WE DQM0-DQM1 BA0 BA1 Controlled by SMC [D15:0] [A9:0] A10 A10 [A12:11] Controlled by SDRAMC [D15:0] [A9:0] Table 13-1. Name [D15:0] [A9:0] A10 SDA10 [A12:11] [A18:13] A19/BA0 A20/BA1 [A23:21] SDCK SDCS RAS CAS WE DQM0-DQM1 NCE0-NCE3 NWE0-NWE1 NWR NSOE 27 6069C–ATARM–15-Sep-05 14. SDRAM Controller (SDRAMC) 14.1 Description The SDRAM Controller (SDRAMC) extends the memory capabilities of a chip by providing the interface to an external 16-bit SDRAM device. The page size supports ranges from 2048 to 8192 and the number of columns from 256 to 2048. It supports byte (8-bit), half-word (16-bit) and word (32-bit) accesses. The maximum addressable SDRAM size is 256M bytes. The SDRAM Controller supports a read or write burst length of one location. It keeps track of the active row in each bank, thus maximizing SDRAM performance, e.g., the application may be placed in one bank and data in the other banks. So as to optimize performance, it is advisable to avoid accessing different rows in the same bank. 14.2 Block Diagram Figure 14-1. SDRAM Controller Block Diagram SDRAMC SDCK Memory Controller SDRAMC Chip Select SDCS BA[1:0] RAS CAS System Controller ACLK WE DQM[1:0] A[12:11, 9:0] SDA10 D[15:0] User Interface APB 28 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 14.3 I/O Lines Description I/O Line Description Description SDRAM Clock SDRAM Controller Chip Select Bank Select Signals Row Signal Column Signal SDRAM Write Enable Data Mask Enable Signals Address Bus Data Bus Type Output Output Output Output Output Output Output Output I/O Low High Low Low Low Low Active Level Table 14-1. Name SDCK SDCS BA[1:0] RAS CAS WE DQM[1:0] A [12:11] SDA10 A[9:0] D[15:0] 14.4 14.4.1 Application Example Hardware Interface Figure 14-2 shows an example of an SDRAM device connection by using a 16-bit data bus width. Figure 14-2. SDRAM Controller Connections to SDRAM Devices: 16-bit Data Bus Width D0-D31 RAS CAS SDCK WE DQM0 DQM1 D0-D7 2M x 8 SDRAM D0-D7 D8-D15 2M x 8 SDRAM D0-D7 CS VDD CKE CLK SDWE WE RAS CAS DQM DQM0 A0--A11 BA0 BA1 A0-A11 BA0 BA1 CS VDD CKE CLK SDWE WE RAS CAS DQM DQM1 A0-A11 BA0 BA1 A0- A11 BA0 BA1 A0-A11 A0-A9, SDA10, A11 A19/BA0 A20/BA1 SDRAM Controller SDCS 14.4.2 Software Interface The SDRAM Controller’s function is to make the SDRAM device access protocol transparent to the user. Table 14-2 to Table 14-4 illustrate the SDRAM device memory mapping therefore seen by the user in correlation with the device structure. Various configurations are illustrated. 29 6069C–ATARM–15-Sep-05 16-bit Memory Data Bus Width Table 14-2. 27 26 25 SDRAM Configuration Mapping: 2K Rows, 256/512/1024/2048 Columns CPU Address Line 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Bk[1:0] Bk[1:0] Bk[1:0] Row[10:0] Row[10:0] Row[10:0] Column[7:0] Column[8:0] Column[9:0] M0 M0 M0 Table 14-3. 27 26 25 SDRAM Configuration Mapping: 4K Rows, 256/512/1024/2048 Columns CPU Address Line 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Bk[1:0] Bk[1:0] Row[11:0] Row[11:0] Column[7:0] Column[8:0] M0 M0 Table 14-4. 27 26 25 SDRAM Configuration Mapping: 8K Rows, 256/512/1024/2048 Columns CPU Address Line 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Bk[1:0] Row[12:0] Column[7:0] M0 30 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 14.5 SDRAM Device Initialization The initialization sequence is generated by software. The SDRAM devices are initialized by the following sequence: 1. A minimum pause of 200 µs is provided to precede any signal toggle. 2. An All Banks Precharge command is issued to the SDRAM devices. 3. Eight auto-refresh (CBR) cycles are provided. 4. A mode register set (MRS) cycle is issued to program the parameters of the SDRAM devices, in particular CAS latency and burst length. 5. A Normal Mode command is provided, 3 clocks after tMRD is met. 6. Perform a dummy access in the SDRAM Memory Space to initialize the state machine. 7. Write refresh rate into the count field in the SDRAMC Refresh Timer register. (Refresh rate = delay between refresh cycles). After these six steps, the SDRAM devices are fully functional. The commands (NOP, MRS, CBR, normal mode) are generated by programming the command field in the SDRAMC Mode register. Figure 14-3. SDRAM Device Initialization Sequence tRP SDCK tRC tMRD A[9:0] SDA10 A[12:11] SDCS RAS CAS WE NBS Inputs Stable for 200 µsec Precharge All Banks 1st Auto-refresh 8th Auto-refresh MRS Command Valid Command 31 6069C–ATARM–15-Sep-05 14.6 SDRAM Controller Write Cycle The SDRAM Controller allows burst access or single access. To initiate a burst access, the SDRAM Controller uses the transfer type signal provided by the master requesting the access. If the next access is a sequential write access, writing to the SDRAM device is carried out. If the next access is a write-sequential access, but the current access is to a boundary page, or if the next access is in another row, then the SDRAM Controller generates a precharge command, activates the new row and initiates a write command. To comply with SDRAM timing parameters, additional clock cycles are inserted between precharge/active (tRP) commands and active/write (tRCD) commands. For a definition of these timing parameters, refer to the ”SDRAMC Configuration Register” on page 39. This is described in Figure 14-4 below. Figure 14-4. Write Burst, 16-bit SDRAM Access tRCD = 3 SDCS SDCK A[12:0] Row n col a col b col c col d col e col f col g col h col i col j col k col l RAS CAS WE D[15:0] D na Dnb Dnc Dnd Dne Dnf Dng Dnh Dni Dnj Dnk Dnl 32 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 14.7 SDRAM Controller Read Cycle The SDRAM Controller allows burst access or single access. To initiate a burst access, the SDRAM Controller uses the transfer type signal provided by the master requesting the access. If the next access is a sequential read access, reading to the SDRAM device is carried out. If the next access is a sequential read access, but the current access is to a boundary page, or if the next access is in another row, then the SDRAM Controller generates a precharge command, activates the new row and initiates a read command. To comply with SDRAM timing parameters, an additional clock cycle is inserted between the precharge/active (tRP) command and the active/read (tRCD) command, After a read command, additional wait states are generated to comply with cas latency. The SDRAM Controller supports a cas latency of two. For definition of these timing parameters, refer to ”SDRAMC Configuration Register” on page 39. This is described in Figure 14-5 below. Figure 14-5. Read Burst, 16-bit SDRAM access tRCD = 3 SDCS CAS = 2 SDCK A[12:0] Row n col a col b col c col d col e col f RAS CAS WE D[15:0] (Input) Dna Dnb Dnc Dnd Dne Dnf 33 6069C–ATARM–15-Sep-05 14.8 Border Management When the memory row boundary has been reached, an automatic page break is inserted. In this case, the SDRAM controller generates a precharge command, activates the new row and initiates a read or write command. To comply with SDRAM timing parameters, an additional clock cycle is inserted between the precharge/active (tRP) command and the active/read (tRCD) command. This is described in Figure 14-6 below. Figure 14-6. Read Burst with Boundary Row Access TRP = 3 SDCS TRCD = 3 CAS = 3 SDCK Row n A[12:0] col a c ol b col c col d Row m col a col b col c col d col e RAS CAS WE D[15:0] Dna Dnb Dnc Dnd Dma Dmb Dmc Dmd Dme 34 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 14.9 SDRAM Controller Refresh Cycles An auto-refresh command is used to refresh the SDRAM device. Refresh addresses are generated internally by the SDRAM device and incremented after each auto-refresh automatically. The SDRAM Controller generates these auto-refresh commands periodically. A timer is loaded with the value in the register SDRAMC_TR that indicates the number of clock cycles between refresh cycles. When the SDRAM Controller initiates a refresh of the SDRAM device, internal memory accesses are not delayed. However, if the ARM tries to access the SDRAM, it is held until the refresh cycle has completed. See Figure 14-7 below. Figure 14-7. Refresh Cycle Followed by a Read Access tRP = 3 SDCS tRC = 8 tRCD = 3 CAS = 2 SDCK Row n col c col d A[12:0] R ow m col a RAS CAS WE D[15:0] (input) Dnb Dnc Dnd Dma 35 6069C–ATARM–15-Sep-05 14.10 SDRAM User Interface Base Address: 0xFF00 8000 Table 14-5. Offset 0x00 0x04 0x08 0x0C 0x10 SDRAM Controller Register Mapping Register Name SDRAMC_MR SDRAMC_TR SDRAMC_CR SDRAM_16BIT SDRAMC_ADDR Register Description SDRAMC Mode Register SDRAMC Refresh Timer Register SDRAMC Configuration Register SDRAM 16-bit configuration Base address for SDCS Access Read/Write Read/Write Read/Write Read/Write Read/Write Reset State 0x00000000 0x00000800 0x0299C140 0x00000001 0x00000040 36 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 14.10.1 SDRAMC Mode Register SDRAMC_MR Read/Write 0x00000010 30 – 22 – 14 – 6 MODE 29 – 21 – 13 – 5 – 28 – 20 – 12 – 4 – 27 – 19 – 11 – 3 – 26 – 18 – 10 – 2 – 25 – 17 – 9 – 1 – 24 – 16 – 8 MODE 0 – Register Name: Access Type: Reset Value: 31 – 23 – 15 – 7 • MODE: SDRAMC Command Mode This field defines the command issued by the SDRAM Controller when the SDRAM device is accessed. MODE 0 0 0 0 0 1 0 1 0 Description Normal mode. Any access to the SDRAM is decoded normally. The SDRAM Controller issues a NOP command when the SDRAM device is accessed regardless of the cycle. The SDRAM Controller issues an “All Banks Precharge” command when the SDRAM device is accessed regardless of the cycle. The SDRAM Controller issues a “Load Mode Register” command when the SDRAM device is accessed regardless of the cycle. The address offset with respect to the SDRAM device base address is used to program the Mode Register. For instance, when this mode is activated, an access to the “SDRAM_Base + offset” address generates a “Load Mode Register” command with the value “offset” written to the SDRAM device Mode Register. The SDRAM Controller issues a “Refresh” Command when the SDRAM device is accessed regardless of the cycle. Prior to this, an “All Banks Precharge” command must be issued. Reserved 0 1 1 1 0 Others 0 37 6069C–ATARM–15-Sep-05 14.10.2 SDRAMC Refresh Timer Register SDRAMC_TR Read/Write 0x00000800 30 – 22 – 14 – 6 29 – 21 – 13 – 5 28 – 20 – 12 – 4 COUNT 27 – 19 – 11 26 – 18 – 10 COUNT 3 2 1 0 25 – 17 – 9 24 – 16 – 8 Register Name: Access Type: Reset Value: 31 – 23 – 15 – 7 • COUNT: SDRAMC Refresh Timer Count This 12-bit field is loaded into a timer that generates the refresh pulse. Each time the refresh pulse is generated, a refresh burst is initiated. The value to be loaded depends on the SDRAMC clock frequency (MCK: Master Clock), the refresh rate of the SDRAM device and the refresh burst length where 15.6 µs per row is a typical value for a burst of one length. To refresh the SDRAM device even if the reset value is not equal to 0, this 12-bit field must be written. If this condition is not satisfied, no refresh command is issued and no refresh of the SDRAM device is carried out. 38 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 14.10.3 SDRAMC Configuration Register SDRAMC_CR Read/Write 0x0299C140 30 – 22 29 – 21 TRCD 14 13 TRC 6 1 5 0 Register Name: Access Type: Reset Value: 31 – 23 TRAS 15 TRP 7 TWR 28 – 20 27 – 19 26 25 TRAS 17 TRP 9 TWR 1 NC 24 18 16 12 11 10 8 4 NB 3 NR 2 0 • NC: Number of Column Bits Reset value is 8 column bits. NC 0 0 1 1 0 1 0 1 Column Bits 8 9 10 11 • NR: Number of Row Bits Reset value is 11 row bits. NR 0 0 1 1 0 1 0 1 Row Bits 11 12 13 Reserved • NB: Number of Banks Reset value is two banks. NB 0 1 Number of Banks 2 4 • TWR: Write Recovery Delay Reset value is two cycles. This field defines the Write Recovery Time in number of cycles. Number of cycles is between 2 and 15. If TWR is less than or equal to 2, two clock periods are inserted by default. 39 6069C–ATARM–15-Sep-05 • TRC: Row Cycle Delay Reset value is eight cycles. This field defines the delay between a Refresh and an Activate Command in number of cycles. Number of cycles is between 2 and 15. If TRC is less than or equal to 2, two clock periods are inserted by default. • TRP: Row Precharge Delay Reset value is three cycles. This field defines the delay between a Precharge Command and another Command in number of cycles. Number of cycles is between 2 and 15. If TRP is less than or equal to 2, two clock periods are inserted by default. • TRCD: Row to Column Delay Reset value is three cycles. This field defines the delay between an Activate Command and a Read/Write Command in number of cycles. Number of cycles is between 2 and 15. If TRCD is less than or equal to 2, two clock periods are inserted by default. • TRAS: Active to Precharge Delay Reset value is five cycles. This field defines the delay between an Activate Command and a Precharge Command in number of cycles. Number of cycles is between 2 and 15. If TRAS is less than or equal to 2, two clock periods are inserted by default. 40 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 14.10.4 SDRAMC Address Register SDRAMC_ADDR Read/Write 30 – 22 – 14 – 6 29 – 21 – 13 – 5 28 – 20 – 12 – 4 SDCS_ADDR 27 – 19 – 11 – 3 26 – 18 – 10 – 2 25 – 17 – 9 – 1 24 – 16 – 8 – 0 Register Name: Access Type: 31 – 23 – 15 – 7 • SDCS_ADDR This field defines the eight most significant bits of the base address of the SDRAMC. 41 6069C–ATARM–15-Sep-05 15. Static Memory Controller (SMC) The AT91C140 features a Static Memory Controller (SMC), that enables interfacing with a wide range of external static memory on peripheral devices, including Flash, ROM, static RAM, and parallel peripherals. The SMC provides a glueless memory interface to external memory using common address, data bus and dedicated control signals. The SMC is highly programmable and has up to 24 bits of address bus, a 16-bit data bus and up to four chip select lines. The SMC supports different access protocols allowing single clock-cycle accesses. The SMC is programmed as an internal peripheral that has a standard APB bus interface and a set of memory-mapped registers. It shares the external address and data buses with the SDRAMC and any external bus master. 15.1 External Memory Mapping The memory map associates the internal 32-bit address space with the external 24-bit address bus. The memory map is defined by programming the base address and page size of the external memories. Only address bits A1 to A23 are significant for 16-bit memories. If the physical memory-mapped device is smaller than the programmed page size, it wraps around and appears to be repeated within the page. The SMC correctly handles any valid access to the memory device within the page. In the event of an access request to an address outside any programmed page, an abort signal is generated by the internal decoder. Two types of abort are possible: instruction prefetch abort and data abort. The corresponding exception vector addresses are 0x0000000C and 0x00000010. It is up to the system programmer to program the exception handling routine used in case of an abort. 15.2 Pin Description Table 15-1 below lists the pins used by the SMC to control external memories. Table 15-1. FPDRAM [A23:0] [D15:0] NCE0-NCE3 NWE0-NWE1 NWR NSOE SMC Pin Description Description Address bus Data bus Active low chip enable Active low byte select/write strobe signals Active low write strobe signals Active low read enable signal Type Output I/O Output Output Output Output 15.3 Byte Write or Byte Select Mode Each chip select can be individually programmed to operate in Byte Write or Byte Select Mode. • The Byte Write Mode supports byte write signals and a single read signal. • The Byte Select Mode selects the appropriate byte using two byte-select lines and separate read and write signals. 42 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 This option is controlled by the BAT bit in the Chip Select Register (SMC_CSR0 to SMC_CSR3). The Byte Write Mode is used to connect two 8-bit devices on a 16-bit bus. • The NWE0 signal is used as the write enable signal for byte 0. • The NWE1 signal is used as the write enable signal for byte 1. • The NSOE signal enables memory reads to all memory blocks. The Byte Select Mode is used to connect one 16-bit device on a 16-bit data bus. • The NWE0 signal is used to select byte 0 for read and write operations. • The NWE1 signal is used to select byte 1 for read and write operations. • The NWR signal is used as the write enable signal for the memory block. • The NSOE signal enables memory reads to the memory block. 15.4 Read Protocols The SMC provides two alternative protocols for external memory read access; standard and early read. The difference between the two protocols lies in the timing of the NSOE (read cycle) waveform. The protocol is selected by the DRP field in the Memory Control Register (SMC_MCR) and is valid for all memory devices. Standard read protocol is the default protocol after reset. 15.4.1 Standard Read Protocol Standard read protocol implements a read cycle in which NSOE and the write strobes are similar. Both are active during the second half of the clock cycle. The first half of the clock cycle allows time to ensure completion of the previous access, as well as the output of address and NCE before the read cycle begins. During a standard read protocol external memory access, the chip enable signal NCE0 to NCE3 are set low and the address lines are valid at the beginning of the access, whereas NSOE goes low only in the second half of the master clock cycle to avoid bus conflict. The write strobes are the same in both protocols. The write strobes always go low in the second half of the master clock cycle. 15.4.2 Early Read Protocol Early read protocol provides more time for a read access from the memory by asserting NSOE at the beginning of the clock cycle. In the case of successive read cycles in the same memory, NSOE remains active continuously. Since a read cycle normally limits the speed of operation of the external memory system, early read protocol allows a faster clock frequency to be used. However, an extra wait state is required in some cases to avoid contention on the external bus. In early read protocol, an early read wait state is automatically inserted when an external write cycle is followed by a read cycle to allow time for the write cycle to end before the subsequent read cycle begins. This wait state is generated in addition to any other programmed wait states (i.e., data float wait). No wait state is added when a read cycle is followed by a write cycle, between consecutive accesses of the same type or between external and internal memory accesses. 43 6069C–ATARM–15-Sep-05 15.5 Write Protocol During a write cycle, the data becomes valid after the falling edge of the write strobe signal and remains valid after the rising edge of the write strobe. The external write strobe waveform on the appropriate write strobe pin is used to control the output data timing to guarantee this operation. Thus, it is necessary to avoid excessive loading of the write strobe pins, which could delay the write signal too long and cause a contention with a subsequent read cycle in standard protocol. In early read protocol, the data can remain valid longer than in standard read protocol due to the additional wait cycle that follows a write access. 15.6 Wait States The SMC can automatically insert wait states. The different types of wait states are: • Standard wait states • Data float wait states • Chip select change wait states • Early read wait states, as described in “Early Read Protocol” above. 15.6.1 Standard Wait States Each chip select can be programmed to insert one or more wait states during an access on the corresponding device. This is done by setting the WSE field in the corresponding SMC_CSR. The number of cycles to insert is programmed in the NWS field in the same register. When no wait state is programmed (WSE = 0), the NWE signal lasts only one-half cycle. If at least one wait state is programmed, the NWE signal lasts an integer number of cycles, accordingly to the number of wait states programmed. 15.6.2 Data Float Wait States Some memory devices are slow to release the external bus. For such devices it is necessary to add wait states (data float waits) after a read access before starting a write access or a read access to a different external memory. The Data Float Output Time (TDF) for each external memory device is programmed in the TDF field of the SMC_CSR register for the corresponding chip select. The value (0 - 7 clock cycles) indicates the number of data float waits to be inserted and represents the time allowed for the data output to go to high impedance after the memory is disabled. The SMC keeps track of the programmed external data float time even when it makes internal accesses to ensure that the external memory system is not accessed while it is still busy. Internal memory accesses and consecutive accesses to the same external memory do not insert added data float wait states. When data float wait states are being used, the SMC prevents the SDRAM Controller from accessing the external data bus. 15.6.3 Chip Select Change Wait States A chip select wait state is automatically inserted when consecutive accesses are made to two different external memories (if no wait states have already been inserted). If any wait states have already been inserted (e.g., data float wait), then none are added. 44 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 15.7 SMC User Interface The memory control register (SMC_MCR) is used to program the number of active chip selects and data read protocol. Four chip select registers (SMC_CSR0 to SMC_CSR3) are used to program the parameters for the individual external memories. Each SMC_CSR must be programmed with a different base address, even for unused chip selects. During the boot sequence, the Chip Select Registers must be programmed as required depending on the devices connected on the external bus. The chip select addresses that are programmed take effect immediately. Wait states also take effect immediately when they are programmed to optimize boot program execution. Table 15-2. Offset 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C 0x20 0x24 SMC Register Mapping Register Name SMC_CSR0 SMC_CSR1 SMC_CSR2 SMC_CSR3 – – – – – SMC_MCR Register Description Chip Select Register Chip Select Register Chip Select Register Chip Select Register Reserved Reserved Reserved Reserved Reserved Memory Control Register Access Read/Write Read/Write Read/Write Read/Write – – – – – Read/ Write Reset Value 0x0000203D 0x10000000 0x20000000 0x30000000 – – – – – 0x0 45 6069C–ATARM–15-Sep-05 15.7.1 SMC Chip Select Register SMC_CSR0..SMC_CSR3 Read/Write 30 29 28 BA 23 22 BA 15 – 14 – 6 MWS 13 CSEN 5 WSE 12 BAT 4 21 20 19 – 11 18 – 10 TDF 2 17 – 9 16 – 8 PAGES 0 DBW 27 26 25 24 Register Name: Access: 31 7 PAGES 3 NWS 1 • DBW: Data Bus Width DBW 0 0 1 1 0 1 0 1 Data Bus Width Reserved 16-bit external bus Reserved Reserved • NWS: Number of Wait States • WSE: Wait State Enable • MWS: Multiply Wait States NWS WSE MWS = 0 X 0 0 0 0 1 1 1 1 X 0 0 1 1 0 0 1 1 X 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 0 1 2 3 4 5 6 7 8 Wait States Number MWS = 1 0 8 16 24 32 40 48 56 64 46 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 • PAGES: Page Size PAGES 0 0 1 1 0 1 0 1 Page Size 1M byte 4M bytes 16M bytes Reserved Base Address BA20-BA31 BA22-BA31 BA24-BA31 – • TDF: Data Float Output Time TDF 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 Cycles after Transfer 0 1 2 3 4 5 6 7 • BAT: Byte Access Mode 0 = Byte Write Mode 1= Byte Select Mode • CSEN: Chip Select Enable 0 = Chip Select is disabled 1 = Chip Select is enabled • BA: Base Address This field contains the high-order bits of the base address. If the page size is larger than 1M byte, then the unused bits of the base address are ignored by the SMC decoder. 47 6069C–ATARM–15-Sep-05 15.7.2 SMC Memory Control Register SMC_MCR Read/Write 30 – 22 – 14 – 6 – 29 – 21 – 13 – 5 – 28 – 20 – 12 – 4 DRP 27 – 19 – 11 – 3 – 26 – 18 – 10 – 2 – 25 – 17 – 9 – 1 – 24 – 16 – 8 – 0 – Register Name: Access Type: 31 – 23 – 15 – 7 – • DRP: Data Read Protocol 0 =Standard Read Mode 1 =Early Read Mode 48 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 16. Ethernet MAC (EMAC) The AT91C140 features two identical Ethernet MACs, both of which feature the following: • Compatible with IEEE Standard 802.3 • 10 and 100 Mbits per Second Data Throughput Capability • Full- and Half-duplex Operation • Media Independent Interface to the Physical Layer • Register Interface to Address, Status and Control Registers • DMA Interface • Interrupt Generation to Signal Receive and Transmit Completion • 28-byte Transmit and 28-byte Receive FIFOs • Automatic Pad and CRC Generation on Transmitted Frames • Address Checking Logic to Recognize Four 48-bit Addresses • Supports Promiscuous Mode Where All Valid Frames are Copied to Memory • Supports Physical Layer Management through MDIO Interface The Ethernet MAC is the hardware implementation of the MAC sub-layer OSI reference model between the physical layer (PHY) and the logical link layer (LLC). It controls the data exchange between a host and a PHY layer according to Ethernet IEEE 802.3 data frame format. The Ethernet MAC contains the required logic and transmit and receive FIFOs for DMA management. In addition, it is interfaced through MDIO/MDC pins for PHY layer management. The Ethernet MAC transfers data in media-independent interface (MII). 16.1 Block Diagram Figure 16-1. Block Diagram MAC ASB DMA Mx_TXCLK, Mx_RXCLK Mx_TXEN, Mx_TXER APB Bridge Mx_CRS, Mx_COL Mx_RXER, Mx_RXDV APB Ethernet MAC Mx_RXD[3:0] Mx_TXD[3:0] Mx_MDC ACLK Interrupt Control Mx_MDIO EMAC IRQ 49 6069C–ATARM–15-Sep-05 16.2 Media Independent Interface Pin Configuration Signal Name ETXCK ECRS ECOL ERXDV ERX0-ERX3 ERXER ERXCK ETXEN ETX0-ETX3 ETXER Pin Name EMAC A MA_TXCLK MA_CRS MA_COL MA_RXDV MA_RXD[0:3] MA_RXER MA_RXCLK MA_TXEN MA_TXD[0:3] MA_TXER Pin Name EMAC B MB_TXCLK MB_CRS MB_COL MB_RXDV MB_RXD[0:3] MB_RXER MB_RXCLK MB_TXEN MB_TXD[0:3] MB_TXER Table 16-1. MII Signal Transmit Clock Carrier Sense Collision Detect Receive Data Valid 4-bit Receive Data Receive Error Receive Clock Transmit Enable 4-bit Transmit Data Transmit Error 16.3 Transmit/Receive Operation A standard IEEE 802.3 packet consists of the following fields: preamble, start of frame delimiter (SFD), destination address (DA), source address (SA), length, data (Logical Link Control Data) and frame check sequence CRC32 (FCS). Table 16-2. Packet Format Preamble Frame(1) SFD 1 byte DA 6 bytes SA 6 bytes Length/type 2 bytes LLC Data PAD FCS 4 bytes Alternating 1s/0s Up to 7 bytes Note: 1. Frame Length between 64 bytes and 1518 bytes. The packets are Manchester-encoded and -decoded and transferred serially using NRZ data with a clock. All fields are of fixed length except for the data field. The MAC generates and appends the preamble, SFD and CRC fields during transmission. The preamble and SFD fields are stripped during reception. 16.3.1 Preamble and Start of Frame Delimiter (SFD) The preamble field is used to acquire bit synchronization with an incoming packet. When transmitted, each packet contains 62 bits of alternating 1,0 preamble. Some of this preamble is lost as the packet travels through the network. Byte alignment is performed with the Start of Frame Delimiter (SFD) pattern that consists of two consecutive 1's. Destination Address (DA) The destination address (DA) indicates the destination of the packet on the network and is used to filter unwanted packets. There are three types of address formats: physical, multicast and broadcast. The physical address is a unique address that corresponds only to a single node. All physical addresses have an MSB of 0. Multicast addresses begin with an MSB of 1. The MAC filters multicast addresses using a standard hashing algorithm that maps all multicast addresses into a 6-bit value. This 6-bit 16.3.2 50 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 value indexes a 64-bit array that filters the value. If the address consists of all ones, it is a broadcast address, indicating that the packet is intended for all nodes. 16.3.3 Source Address (SA) The source address (SA) is the physical address of the node that sent the packet. Source addresses cannot be multicast or broadcast addresses. This field is passed to buffer memory. Length/Type If the value of this field is less than or equal to 1500, then the Length/Type field indicates the number of bytes in the subsequent LLC Data field. If the value of this field is greater than or equal to 1536, then the Length/Type field indicates the nature of the MAC client protocol (protocol type). 16.3.5 LLC Data The data field consists of anywhere from 46 to 1500 bytes. Messages longer than 1500 bytes need to be broken into multiple packets. Messages shorter than 46 bytes require appending a pad to bring the data field to the minimum length of 46 bytes. If the data field is padded, the number of valid data bytes is indicated in the length field. 16.3.6 Frame Check Sequence Field (FCS) The Frame Check Sequence (FCS) is a 32-bit CRC field, calculated and appended to a packet during transmission to allow detection of errors when a packet is received. During reception, error free packets result in a specific pattern in the CRC generator. Packets with improper CRC will be rejected. Frame Format Extensions The original Ethernet standards define the minimum frame size as 64 bytes and the maximum as 1518 bytes. These numbers include all bytes from the Destination MAC Address field through the Frame Check Sequence field. The Preamble and Start Frame Delimiter fields are not included when quoting the size of a frame. The IEEE 802.3ac standard extended the maximum allowable frame size to 1522 bytes to allow a VLAN tag to be inserted into the Ethernet frame format. The BIG bit defined in the ETH_CFG register processes packets with a VLAN tag. The VLAN protocol permits insertion of an identifier, or tag, into the Ethernet frame format to identify the VLAN to which the frame belongs. It allows frames from stations to be assigned to logical groups. This provides various benefits, such as easing network administration, allowing formation of work groups, enhancing network security, and providing a means of limiting broadcast domains (refer to IEEE standard 802.1Q for definition of the VLAN protocol). The 802.3ac standard defines only the implementation details of the VLAN protocol that are specific to Ethernet. If present, the 4-byte VLAN tag is inserted into the Ethernet frame between the Source MAC Address field and the Length field. The first 2 bytes of the VLAN tag consist of the “802.1Q Tag Type” and are always set to a value of 0x8100. The 0x8100 value is a reserved Length/Type field assignment that indicates the presence of the VLAN tag, and signals that the traditional Length/Type field can be found at an offset of four bytes further into the frame. The last two bytes of the VLAN tag contain the following information. • The first three bits are a User Priority Field that may be used to assign a priority level to the Ethernet frame. 16.3.4 16.3.7 51 6069C–ATARM–15-Sep-05 • The following one bit is a Canonical Format Indicator (CFI) used in Ethernet frames to indicate the presence of a Routing Information Field (RIF). • The last twelve bits are the VLAN Identifier (VID) that uniquely identifies the VLAN to which the Ethernet frame belongs. With the addition of VLAN tagging, the 802.3ac standard permits the maximum length of an Ethernet frame to be extended from 1518 bytes to 1522 bytes. Table 16-3 on page 52 illustrates the format of an Ethernet frame that has been “tagged” with a VLAN identifier according to the IEEE 802.3ac standard. Table 16-3. Preamble Start Frame Delimiter Dest. MAC Address Source MAC Address Length/Type = 802.1Q Tag Type Tag Control Information Length / Type MAC Client Data Pad Frame Check Sequence Ethernet Frame with VLAN Tagging 7 bytes 1 byte 6 bytes 6 bytes 2 byte 2 bytes 2 bytes 0 - n bytes 0 - p bytes 4 bytes 16.4 DMA Operations Frame data is transferred to and from the Ethernet MAC via the DMA interface. All transfers are 32-bit words and may be single accesses or bursts of two, three or four words. Burst accesses do not cross 16-byte boundaries. The DMA controller performs four types of operations on the ASB bus. In order of priority, these operations are receive buffer manager read, receive buffer manager write, transmit data DMA read and receive data DMA write. 16.4.1 Transmitter Mode Transmit frame data needs to be stored in contiguous memory locations. It does not need to be word-aligned. The transmit address register is written with the address of the first byte to be transmitted. Transmit is initiated by writing the number of bytes to transfer (length) to the transmit control register. The transmit channel then reads data from memory 32 bits at a time and places them in the transmit FIFO. The transmit block starts frame transmission when three words have been loaded into the FIFO. The transmit address register must be written before the transmit control register. While a frame is being transmitted, it is possible to set up one other frame for transmission by writing new values to the transmit address and control registers. Reading the transmit address register returns the address of the buffer currently being accessed by the transmit FIFO. 52 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 Reading the transmit control register returns the total number of bytes to be transmitted. The BNQ bit in the Transmit Status Register indicates whether another buffer can be safely queued. An interrupt is generated whenever this bit is set. Frame assembly starts by adding preamble and the start frame delimiter. Data is taken from the transmit FIFO word-by-word. If necessary, padding is added to make the frame length 60 bytes. The CRC is calculated as a 32-bit polynomial. This is inverted and appended to the end of the frame, making the frame length a minimum of 64 bytes. The CRC is not appended if the NCRC bit is set in the transmit control register. In full-duplex mode, frames are transmitted immediately. Back-to-back frames are transmitted at least 96 bit times apart to guarantee the inter-frame gap. In half-duplex mode, the transmitter checks carrier sense. If asserted, it waits for it to de-assert and then starts transmission after the inter-frame gap of 96 bit-times. If the collision signal is asserted during transmission, the transmitter transmits a jam sequence of 32 bits taken from the data register and then retries transmission after the backoff time has elapsed. An error is indicated and any further attempts aborted if 16 attempts cause collisions. If transmit DMA underruns, bad CRC is automatically appended using the same mechanism as jam insertion. Underrun also causes TXER to be asserted. 16.4.2 Receiver Mode When a packet is received, it is checked for valid preamble, CRC, alignment, length and address. If all these criteria are met, the packet is stored successfully in a receive buffer. If at the end of reception the CRC is bad, then the received buffer is recovered. Each received frame including CRC is written to a single receive buffer. Receive buffers are word-aligned and are capable of containing 1518 or 1522 bytes (BIG = 1 in ETH_CFG) of data (the maximum length of an Ethernet frame). The start location for each received frame is stored in memory in a list of receive buffer descriptors at a location pointed to by the receive buffer queue pointer register. Each entry in the list consists of two words. The first word is the address of the received buffer; the second is the receive status. Table 16-4 defines an entry in the received buffer descriptor list. To receive frames, the buffer queue must be initialized by writing an appropriate address to bits [31:2] in the first word of each list entry. Bit zero of word zero must be written with zero. After a frame is received, bit zero becomes set and the second word indicates what caused the frame to be copied to memory. The start location of the received buffer descriptor list should be written to the received buffer queue pointer register before receive is enabled (by setting the receive enable bit in the network control register). As soon as the received block starts writing received frame data to the receive FIFO, the received buffer manager reads the first receive buffer location pointed to by the received buffer queue pointer register. If the filter block is active, the frame should be copied to memory; the receive data DMA operation starts writing data into the receive buffer. If an error occurs, the buffer is recovered. If the frame is received without error, the queue entry is updated. The buffer pointer is rewritten to memory with its low-order bit set to indicate successful frame reception and a used buffer. The next word is written with the length of the frame and how the destination address was recognized. The next receive buffer location is then read from the following word or, if the current buffer pointer had its wrap bit set, the beginning of the table. The maximum number of buffer pointers before a wrap bit is seen is 1024. If a wrap bit is not seen by then, a wrap bit is assumed in that 53 6069C–ATARM–15-Sep-05 entry. The received buffer queue pointer register must be written with zero in its lower-order bit positions to enable the wrap function to work correctly. If bit zero is set when the receive buffer manager reads the location of the receive buffer, then the buffer has already been used and cannot be used again until software has processed the frame and cleared bit zero. In this case, the DMA block sets the buffer unavailable bit in the received status register and triggers an interrupt. The frame is discarded and the queue entry is reread on reception of the next frame to see if the buffer is now available. Each discarded frame increments a statistics register that is cleared on being read. When there is network congestion, it is possible for the MAC to be programmed to apply back pressure. This is when half-duplex mode collisions are forced on all received frames by transmitting 64 bits of data (a default pattern). Reading the received buffer queue register returns the location of the queue entry currently being accessed. The queue wraps around to the start after either 1024 entries (i.e., 2048 words) or when the wrap bit is found to be set in bit 1 of the first word of an entry. Table 16-4. Bit Word 0 31:2 1 Received Buffer Descriptor List Function Base address of receive buffer Wrap bit. If this bit is set, the counter that is ORed with the received buffer queue pointer register to give the pointer to entries in this table is cleared after the buffer is used. Ownership bit. 1 indicates software owns the pointer, 0 indicates that the DMA owns the buffer. If this bit is not zero when the entry is read by the receiver, the buffer unavailable bit is set in the received status register and the receiver goes inactive. 0 Word 1 31 30 29 28 27 26 25 24 23 22:11 10:0 Global all ones broadcast address detected Multicast hash match Unicast hash match External address Unknown source address (reserved for future use) Local address match (Specific address 1 match) Local address match (Specific address 2 match) Local address match (Specific address 3 match) Local address match (Specific address 4 match) Reserved; written to 0 Length of frame including FCS 54 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 16.5 Address Checking Whether or not a frame is stored depends on what is enabled in the network configuration register, the contents of the specific address and hash registers and the frame destination address. In this implementation of the MAC the frame source address is not checked. A frame is not copied to memory if the MAC is transmitting in half-duplex mode at the time a destination address is received. The hash register is 64 bits long and takes up two locations in the memory map. There are four 48-bit specific address registers, each taking up two memory locations. The first location contains the first four bytes of the address; the second location contains the last two bytes of the address stored in its least significant byte positions. The addresses stored can be specific, group, local or universal. Ethernet frames are transmitted a byte at a time, LSB first. The first bit (i.e., the LSB of the first byte) of the destination address is the group/individual bit and is set one for multicast addresses and zero for unicast. This bit corresponds to bit 24 of the first word of the specific address register. The MSB of the first byte of the destination address corresponds to bit 31 of the specific address register. The specific address registers are compared to the destination address of received frames once they have been activated. Addresses are deactivated at reset or when the first byte [47:40] is written and activated or when the last byte [7:0] is written. If a receive frame address matches an active address, the local match signal is set and the store frame pulse signal is sent to the DMA block via the ACLK synchronization block. A frame can also be copied if a unicast or multicast hash match occurs, it has the broadcast address of all ones, or the copy all frames bit in the network configuration register is set. The broadcast address of 0xFFFFFFFF is recognized if the no broadcast bit in the network configuration register is zero. This sets the broadcast match signal and triggers the store frame signal. The unicast hash enable and the multicast hash enable bits in the network configuration register enable the reception of hash matched frames. So all multicast frames can be received by setting all bits in the hash register. The CRC algorithm reduces the destination address to a 6-bit index into a 64-bit hash register.If the equivalent bit in the register is set, the frame is matched depending on whether the frame is multicast or unicast and the appropriate match signals are sent to the DMA block. If the copy all frames bit is set in the network configuration register, the store frame pulse is always sent to the DMA block as soon as any destination address is received. 55 6069C–ATARM–15-Sep-05 16.6 EMAC User Interface MACA Memory Address: 0xFF034000 MACB Memory Address: 0xFF038000 Table 16-5. Offset 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C 0x20 0x24 0x28 0x2C 0x30 0x34 Ethernet MAC Register Mapping Register Name ETH_CTL ETH_CFG ETH_SR ETH_TAR ETH_TCR ETH_TSR ETH_RBQP – ETH_RSR ETH_ISR ETH_IER ETH_IDR ETH_IMR ETH_MAN Register Description Network Control Register Network Configuration Register Network Status Register Transmit Address Register Transmit Control Register Transmit Status Register Receive Buffer Queue Pointer Reserved Receive Status Register Interrupt Status Register Interrupt Enable Register Interrupt Disable Register Interrupt Mask Register PHY Maintenance Register Statistics Registers (1) Read/Write Read/Write Read/Write Read-only Read/Write Read/Write Read/Write Read/Write Read-only Read/Write Read/Write Write-only Write-only Read-only Read/Write Reset 0x0 0x800 0x6 0x0 0x0 0x18 0x0 0x0 0x0 0x0 – – 0xFFF 0x0 0x40 0x44 0x48 0x4C 0x50 0x54 0x58 0x5C 0x60 0x64 0x68 0x6C 0x70 0x74 0x78 0x7C 0x80 ETH_FRA ETH_SCOL ETH_MCOL ETH_OK ETH_SEQE ETH_ALE ETH_DTE ETH_LCOL ETH_ECOL ETH_CSE ETH_TUE ETH_CDE ETH_ELR ETH_RJB ETH_USF ETH_SQEE ETH_DRFC Frames Transmitted OK Register Single Collision Frame Register Multiple Collision Frame Register Frames Received OK Register Frame Check Sequence Error Register Alignment Error Register Deferred Transmission Frame Register Late Collision Register Excessive Collision Register Carrier Sense Error Register Transmit Underrun Error Register Code Error Register Excessive Length Error Register Receive Jabber Register Undersize Frame Register SQE Test Error Register Discarded RX Frame Register Address Registers Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 56 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 Table 16-5. Offset 0x90 0x94 0x98 0x9C 0xA0 0xA4 0xA8 0xAC 0xB0 0xB4 Note: Ethernet MAC Register Mapping (Continued) Register Name ETH_HSH ETH_HSL ETH_SA1L ETH_SA1H ETH_SA2L ETH_SA2H ETH_SA3L ETH_SA3H ETH_SA4L ETH_SA4H Register Description Hash Address High [63:32] Hash Address Low [31:0] Specific Address 1 Low, First 4 Bytes Specific Address 1 High, Last 2 Bytes Specific Address 2 Low, First 4 Bytes Specific Address 2 High, Last 2 Bytes Specific Address 3 Low, First 4 Bytes Specific Address 3 High, Last 2 Bytes Specific Address 4 Low, First 4 Bytes Specific Address 4 High, Last 2 Bytes Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Reset 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 1. For further details on the statistics registers, see Table 16-6, “Statistics Register Block,” on page 71. 57 6069C–ATARM–15-Sep-05 16.6.1 EMAC Control Register ETH_CTL Read/Write 30 29 28 27 26 25 24 Register Name: Access Type: 31 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 – 7 – 6 – 5 – 4 – 3 – 2 – 1 BP 0 WES ISR CSR MPE TE RE LBL LB • LB: Loopback . When set, loopback signal is at high level. • LBL: Loopback Local When set, connects ETX[3:0] to ERX[3:0], ETXEN to ERXDV, forces full duplex and drives ERXCK and ETXCK_REFCK with ACK divided by 4. • RE: Receive Enable When set, enables the Ethernet MAC to receive data. • TE: Transmit Enable When set, enables the Ethernet transmitter to send data. • MPE: Management Port Enable Set to one to enable the management port. When zero, forces MDIO to high impedance state. • CSR: Clear Statistics Registers This bit is write-only. Writing a one clears the statistics registers. • ISR: Increment Statistics Registers This bit is write-only. Writing a one increments all the statistics registers by one for test purposes. • WES: Write Enable for Statistics Registers Setting this bit to one makes the statistics registers writable for functional test purposes. • BP: Back Pressure If this field is set, then in half-duplex mode collisions are forced on all received frames by transmitting 64 bits of data (default pattern). 58 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 16.6.2 EMAC Mode Register ETH_CFG Read/Write 30 29 28 27 26 25 24 Name: Access Type: 31 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 – 7 – 6 – 5 RTY 4 3 CLK 2 EAE 1 BIG 0 UNI MTI NBC CAF – BR FD SPD • SPD: Speed Set to 1 to indicate 100 Mbit/sec, 0 for 10 Mbit/sec. Has no other functional effect. • FD: Full Duplex If set to 1, the transmit block ignores the state of collision and carrier sense and allows receive while transmitting. • BR: Bit Rate • CAF: Copy All Frames When set to 1, all valid frames are received. • NBC: No Broadcast When set to 1, frames addressed to the broadcast address of all ones are not received. • MTI: Multicast Hash Enable When set multicast frames are received when six bits of the CRC of the destination address point to a bit that is set in the hash register. • UNI: Unicast Hash Enable When set, unicast frames are received when six bits of the CRC of the destination address point to a bit that is set in the hash register. • BIG: Receive 1522 Bytes When set, the MAC receives up to 1522 bytes. Normally the MAC receives frames up to 1518 bytes in length. This bit allows to receive extended Ethernet frame with “VLAN tag” (IEEE 802.3ac) • EAE: External Address Match Enable • CLK The ARM clock is divided down to generate MDC (the clock for the MDIO). To conform with IEEE standard 802.3 MDC must not exceed 2.5 MHz. At reset this field is set to 10 so that ACK is divided by 32. CLK 00 01 10 11 MDC ACK divided by 8 ACK divided by 16 ACK divided by 32 ACK divided by 64 • RTY: Retry Test When set, the time between frames is always one time slot. For test purposes only. Must be cleared for normal operation. 59 6069C–ATARM–15-Sep-05 16.6.3 EMAC Status Register ETH_SR Read-only 30 29 28 27 26 25 24 Name: Access Type: 31 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 – 7 – 6 – 5 – 4 – 3 – 2 – 1 – 0 – – – – – IDLE MDIO LINK • LINK 0 = LINK is at 0. 1 = LINK is at 1. • MDIO 0 = MDIO pin not set. 1 = MDIO pin set. • IDLE 0 = PHY logic is idle. 1 = PHY logic is running. 60 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 16.6.4 EMAC Transmit Address Register ETH_TAR Read/Write 30 29 28 27 26 25 24 Name: Access Type: 31 ADDRESS 23 22 21 20 19 18 17 16 ADDRESS 15 14 13 12 11 10 9 8 ADDRESS 7 6 5 4 3 2 1 0 ADDRESS • ADDRESS: Transmit Address Register Written with the address of the frame to be transmitted, read as the base address of the buffer being accessed by the transmit FIFO. Note that if the two least significant bits are not zero, transmit starts at the byte indicated. 16.6.5 EMAC Transmit Control Register ETH_TCR Read/Write 30 29 28 27 26 25 24 Name: Access Type: 31 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 NCRC 7 – 6 – 5 – 4 – 3 2 LEN 1 0 LEN • LEN: Transmit Frame Length This register is written to the number of bytes to be transmitted excluding the four CRC bytes unless the no CRC bit is asserted. Writing these bits to any non-zero value initiates a transmission. If the value is greater than 1514 (1518 if no CRC is being generated), an oversize frame is transmitted. This field is buffered so that a new frame can be queued while the previous frame is still being transmitted. Must always be written in address-then-length order. Reads as the total number of bytes to be transmitted (i.e., this value does not change as the frame is transmitted.) Frame transmission does not start until two 32-bit words have been loaded into the transmit FIFO. The length must be great enough to ensure two words are loaded. • NCRC: No CRC If this bit is set, it is assumed that the CRC is included in the length being written in the low-order bits and the MAC does not append CRC to the transmitted frame. If the buffer is not at least 64 bytes long, a short frame is sent. This field is buffered so that a new frame can be queued while the previous frame is still being transmitted. Reads as the value of the frame currently being transmitted. 61 6069C–ATARM–15-Sep-05 16.6.6 EMAC Transmit Status Register ETH_TSR Read/Write 30 29 28 27 26 25 24 Name: Access Type: 31 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 – 7 – 6 – 5 – 4 – 3 – 2 – 1 – 0 – UND COMP BNQ IDLE RLE COL OVR • OVR: Ethernet Transmit Buffer Overrun Software has written to the Transmit Address Register (ETH_TAR) or Transmit Control Register (ETH_TCR) when bit BNQ was not set. Cleared by writing a one to this bit. • COL: Collision Occurred Set by the assertion of a collision. Cleared by writing a one to this bit. • RLE: Retry Limit Exceeded Cleared by writing a one to this bit. • IDLE: Transmitter Idle Asserted when the transmitter has no frame to transmit. Cleared when a length is written to transmit frame length portion of the Transmit Control register. This bit is read-only. • BNQ: Ethernet Transmit Buffer not Queued Software may write a new buffer address and length to the transmit DMA controller when set. Cleared by having one frame ready to transmit and another in the process of being transmitted. This bit is read-only. • COMP: Transmit Complete Set when a frame has been transmitted. Cleared by writing a one to this bit. • UND: Transmit Underrun Set when transmit DMA was not able to read data from memory in time. If this happens, the transmitter forces bad CRC. Cleared by writing a one to this bit. 62 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 16.6.7 EMAC Receive Buffer Queue Pointer Register ETH_RBQP Read/Write 30 29 28 27 26 25 24 Name: Access Type: 31 ADDRESS 23 22 21 20 19 18 17 16 ADDRESS 15 14 13 12 11 10 9 8 ADDRESS 7 6 5 4 3 2 1 0 ADDRESS • ADDRESS: Receive Buffer Queue Pointer Written with the address of the start of the receive queue, reads as a pointer to the current buffer being used. The receive buffer is forced to word alignment. 16.6.8 EMAC Receive Status Register ETH_RSR Read/Write 30 29 28 27 26 25 24 Name: Access Type: 31 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 – 7 – 6 – 5 – 4 – 3 – 2 – 1 – 0 – – – – – OVR REC BNA • BNA: Buffer Not Available An attempt was made to get a new buffer and the pointer indicated that it was owned by the processor. The DMA rereads the pointer each time a new frame starts until a valid pointer is found. This bit is set at each attempt that fails even if it has not had a successful pointer read since it has been cleared. Cleared by writing a one to this bit. • REC: Frame Received One or more frames have been received and placed in memory. Cleared by writing a one to this bit. • OVR: RX Overrun The DMA block was unable to store the receive frame to memory, either because the MAC ASB bus was not granted in time or because an abort occurred. The buffer is recovered if this happens. Cleared by writing a one to this bit. 63 6069C–ATARM–15-Sep-05 16.6.9 EMAC Interrupt Status Register ETH_ISR Read/Write 30 29 28 27 26 25 24 Name: Access Type: 31 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 – 7 – 6 – 5 – 4 ABT 3 ROVR 2 LINK 1 TIDLE 0 TCOM TBRE RTRY TUND TOVR RBNA RCOM DONE • DONE: Management Done The PHY maintenance register has completed its operation. Cleared on read. • RCOM: Receive Complete A frame has been stored in memory. Cleared on read. • RBNA: Receive Buffer Not Available Cleared on read. • TOVR: Transmit Buffer Overrun Software has written to the Transmit Address Register (ETH_TAR) or Transmit Control Register (ETH_TCR) when BNQ of the Transmit Status Register (ETH_TSR) was not set. Cleared on read. • TUND: Transmit Buffer Underrun Ethernet transmit buffer underrun. The transmit DMA did not complete fetch frame data in time for it to be transmitted. Cleared on read. • RTRY: Retry Limit Retry limit exceeded. Cleared on read. • TBRE: Transmit Buffer Register Empty Software may write a new buffer address and length to the transmit DMA controller. Cleared by having one frame ready to transmit and another in the process of being transmitted. Cleared on read. • TCOM: Transmit Complete Set when a frame has been transmitted. Cleared on read. • TIDLE: Transmit Idle Set when all frames have been transmitted. Cleared on read. • LINK Set when LINK pin changes value. • ROVR: RX Overrun Set when the RX overrun status bit is set. Cleared on read. • ABT: Abort Set when the DMA generates an Abort. Cleared on read. 64 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 16.6.10 EMAC Interrupt Enable Register ETH_IER Write-only 30 29 28 27 26 25 24 Name: Access Type: 31 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 – 7 – 6 – 5 – 4 ABT 3 ROVR 2 LINK 1 TIDLE 0 TCOM TBRE RTRY TUND TOVR RBNA RCOM DONE • DONE: Management Done Interrupt Enable • RCOM: Receive Complete Interrupt Enable • RBNA: Receive Buffer Not Available Interrupt Enable • TOVR: Transmit Buffer Overrun Interrupt Enable • TUND: Transmit Buffer Underrun Interrupt Enable • RTRY: Retry Limit Interrupt Enable • TBRE: Transmit Buffer Register Empty Interrupt Enable • TCOM: Transmit Complete Interrupt Enable • TIDLE: Transmit Idle Interrupt Enable • LINK: LINK Interrupt Enable • ROVR: RX Overrun Interrupt Enable • ABT: Abort Interrupt Enable 0 =No effect. 1 =Enables the corresponding interrupt. 65 6069C–ATARM–15-Sep-05 16.6.11 EMAC Interrupt Disable Register ETH_IDR Write-only 30 29 28 27 26 25 24 Name: Access Type: 31 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 – 7 – 6 – 5 – 4 ABT 3 ROVR 2 LINK 1 TIDLE 0 TCOM TBRE RTRY TUND TOVR RBNA RCOM DONE • DONE: Management Done Interrupt Disable • RCOM: Receive Complete Interrupt Disable • RBNA: Receive Buffer Not Available Interrupt Disable • TOVR: Transmit Buffer Overrun Interrupt Disable • TUND: Transmit Buffer Underrun Interrupt Disable • RTRY: Retry Limit Interrupt Disable • TBRE: Transmit Buffer Register Empty Interrupt Disable • TCOM: Transmit Complete Interrupt Disable • TIDLE: Transmit Idle Interrupt Disable • LINK: LINK Interrupt Disable • ROVR: RX Overrun Interrupt Disable • ABT: Abort Interrupt Disable 0 =No effect. 1 =Disables the corresponding interrupt. 66 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 16.6.12 EMAC Interrupt Mask Register ETH_IMR Read-only 30 29 28 27 26 25 24 Name: Access Type: 31 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 – 7 – 6 – 5 – 4 ABT 3 ROVR 2 LINK 1 TIDLE 0 TCOM TBRE RTRY TUND TOVR RBNA RCOM DONE • DONE: Management Done Interrupt Mask • RCOM: Receive Complete Interrupt Mask • RBNA: Receive Buffer Not Available Interrupt Mask • TOVR: Transmit Buffer Overrun Interrupt Mask • TUND: Transmit Buffer Underrun Interrupt Mask • RTRY: Retry Limit Interrupt Mask • TBRE: Transmit Buffer Register Empty Interrupt Mask • TCOM: Transmit Complete Interrupt Mask • TIDLE: Transmit Idle Interrupt Mask • LINK: LINK Interrupt Mask • ROVR: RX Overrun Interrupt Mask • ABT: Abort Interrupt Mask 0 =The corresponding interrupt is enabled. 1 =The corresponding interrupt is not enabled. Important Note: The interrupt is disabled when the corresponding bit is set. This is non-standard with other peripherals of the product, as generally a mask bit set enables the interrupt. 67 6069C–ATARM–15-Sep-05 16.6.13 EMAC PHY Maintenance Register ETH_MAN Read/Write 30 29 28 27 26 25 24 Name: Access Type: 31 LOW 23 HIGH 22 21 RW 20 19 18 PHYA 17 16 PHYA 15 14 13 REGA 12 11 10 9 CODE 8 DATA 7 6 5 4 3 2 1 0 DATA Writing to this register starts the shift register that controls the serial connection to the PHY. On each shift cycle the MDIO pin becomes equal to the MSB of the shift register and LSB of the shift register becomes equal to the value of the MDIO pin. When the shifting is complete an interrupt is generated and the IDLE field is set in the Network Status register. When read, gives current shifted value. • DATA For a write operation this is written with the data to be written to the PHY. After a read operation this contains the data read from the PHY. • CODE Must be written to 10 in accordance with IEEE standard 802.3. Reads as written. • REGA Register address. Specifies the register in the PHY to access. • PHYA PHY address. Normally is 0. • RW Read/Write Operation. 10 is read. 01 is write. Any other value is an invalid PHY management frame. • HIGH Must be written with 1 to make a valid PHY management frame. Conforms with IEEE standard 802.3. • LOW Must be written with 0 to make a valid PHY management frame. Conforms with IEEE standard 802.3. 68 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 16.6.14 EMAC Hash Address High Register ETH_HSH Read/Write 30 29 28 27 26 25 24 Register Name: Access Type: 31 ADDR 23 22 21 20 19 18 17 16 ADDR 15 14 13 12 11 10 9 8 ADDR 7 6 5 4 3 2 1 0 ADDR • ADDR Hash address bits 63 to 32. 16.6.15 EMAC Hash Address Low Register ETH_HSL Read/Write 30 29 28 27 26 25 24 Register Name: Access Type: 31 ADDR 23 22 21 20 19 18 17 16 ADDR 15 14 13 12 11 10 9 8 ADDR 7 6 5 4 3 2 1 0 ADDR • ADDR Hash address bits 31 to 0. 69 6069C–ATARM–15-Sep-05 16.6.16 EMAC Specific Address (1, 2, 3 and 4) High Register ETH_SA1H,...ETH_SA4H Read/Write 30 29 28 27 26 25 24 Register Name: Access Type: 31 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 ADDR 7 6 5 4 3 2 1 0 ADDR • ADDR Unicast addresses (1, 2, 3 and 4), Bits 47:32. 16.6.17 EMAC Specific Address (1, 2, 3 and 4) Low Register ETH_SA1L,...ETH_SA4L Read/Write 30 29 28 27 26 25 24 Register Name: Access Type: 31 ADDR 23 22 21 20 19 18 17 16 ADDR 15 14 13 12 11 10 9 8 ADDR 7 6 5 4 3 2 1 0 ADDR • ADDR Unicast addresses (1, 2, 3 and 4), Bits 31:0. 70 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 16.7 EMAC Statistics Register Block Registers These registers reset to zero on a read and remain at all ones when they count to their maximum value. They should be read frequently enough to prevent loss of data. The statistics register block contains the registers found in Table 16-5, “Ethernet MAC Register Mapping,” on page 56. Table 16-6. Register Frames Transmitted OK Register Single Collision Frame Register Multiple Collision Frame Register Statistics Register Block Register Name ETH_FRA ETH_SCOL Description A 24-bit register counting the number of frames successfully transmitted. A 16-bit register counting the number of frames experiencing a single collision before being transmitted and experiencing no carrier loss nor underrun. A 16-bit register counting the number of frames experiencing between two and fifteen collisions prior to being transmitted (62 - 1518 bytes, no carrier loss, no underrun). A 24-bit register counting the number of good frames received, i.e., address recognized. A good frame is of length 64 to 1518 bytes and has no FCS, alignment or code errors. An 8-bit register counting address-recognized frames that are an integral number of bytes long, that have bad CRC and that are 64 to 1518 bytes long. An 8-bit register counting frames that: - are address-recognized, - are not an integral number of bytes long, - have bad CRC when their length is truncated to an integral number of bytes, - are between 64 and 1518 bytes long. A 16-bit register counting the number of frames experiencing deferral due to carrier sense active on their first attempt at transmission (no underrun or collision). An 8-bit register counting the number of frames that experience a collision after the slot time (512 bits) has expired. No carrier loss or underrun. A late collision is counted twice, i.e., both as a collision and a late collision. An 8-bit register counting the number of frames that failed to be transmitted because they experienced 16 collisions (64 - 1518 bytes, no carrier loss or underrun). An 8-bit register counting the number of frames for which carrier sense was not detected and that were maintained in half-duplex mode one slot time (512 bits) after the start of transmission (no excessive collision). An 8-bit register counting the number of frames not transmitted due to a transmit DMA underrun. If this register is incremented, then no other register is incremented. An 8-bit register counting the number of frames that are address-recognized, had RXER asserted during reception. If this counter is incremented, then no other counters are incremented. An 8-bit register counting the number of frames received exceeding 1518 bytes in length but that do not have either a CRC error, an alignment error or a code error. An 8-bit register counting the number of frames received exceeding 1518 bytes in length and having either a CRC error, an alignment error or a code error. ETH_MCOL Frames Received OK Register Frame Check Sequence Error Register ETH_OK ETH_SEQE Alignment Error Register ETH_ALE Deferred Transmission Frame Register ETH_DTE Late Collision Register ETH_LCOL Excessive Collision Register ETH_ECOL Carrier Sense Error Register ETH_CSE Transmit Underrun Error Register ETH_TUE Code Error Register ETH_CDE Excessive Length Error Register Receive Jabber Register ETH_ELR ETH_RJB 71 6069C–ATARM–15-Sep-05 Table 16-6. Register Statistics Register Block (Continued) Register Name ETH_USF Description An 8-bit register counting the number of frames received that are less than 64 bytes in length but that do not have either a CRC error, an alignment error or a code error. An 8-bit register counting the number of frames where pin ECOL was not asserted within a slot time of pin ETXEN being deasserted. This 16-bit counter is incremented every time an address-recognized frame is received but cannot be copied to memory because the receive buffer is available. Undersize Frame Register SQE Test Error Register Discarded RX Frame Register ETH_SQEE ETH_DRFC 72 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 17. Advanced Interrupt Controller (AIC) The AT91C140 integrates the Atmel advanced interrupt controller (AIC). The interrupt controller is connected to the fast interrupt request (nFIQ) and the standard interrupt request (NIRQ) inputs of the ARM7TDMI processor. The processor’s nFIQ line can only be asserted by the external fast interrupt request input (FIQ). The nIRQ line can be asserted by the interrupts generated by the on-chip peripherals and the two external interrupt request lines, IRQ0 to IRQ1. An 8-level priority encoder allows the user to define the priority between the different interrupt sources. Internal sources are programmed to be level-sensitive or edge-triggered. External sources can be programmed to be positive- or negative-edge triggered or high- or low-level sensitive. Figure 17-1. Advanced Interrupt Controller Block Diagram FIQ Source Memorization NFIQ Manager NFIQ Advanced Peripheral Bus (APB) Control Logic ARM7TDMI Core Internal Interrupt Sources External Interrupt Sources Memorization Prioritization Controller NIRQ Manager NIRQ Table 17-1. Interrupt Sources Interrupt Name FIQ -SWI UARTA TC0 TC1 TC2 PIOA MACA SPI IRQ0 Software Interrupt UART A Interrupt Timer Channel 0 Interrupt Timer Channel 1 Interrupt Timer Channel 2 Interrupt PIO A Interrupt MAC A Interrupt Serial Peripheral Interface External Interrupt Interrupt Description Fast Interrupt (LOWP) Interrupt Source 0 1 2 3 4 5 6 7 8 9 10 73 6069C–ATARM–15-Sep-05 Table 17-1. Interrupt Sources (Continued) Interrupt Name IRQ1 Reserved MACB UARTB PIOB Reserved MAC B Interrupt UART B Interrupt PIO B Interrupt Interrupt Description External Interrupt Interrupt Source 11 12 13 14 15 16 - 31 17.1 Priority Controller The nIRQ line is controlled by an 8-level priority encoder. Each source has a programmable priority level of 7 to 0. Level 7 is the highest priority and level 0 the lowest. When the AIC receives more than one unmasked interrupt at a time, the interrupt with the highest priority is serviced first. If both interrupts have equal priority, the interrupt with the lowest interrupt source number is serviced first. The current priority level is defined as the priority level of the current interrupt at the time the register AIC_IVR is read (the interrupt which will be serviced). In the case when a higher priority unmasked interrupt occurs while an interrupt already exists, there are two possible outcomes depending on whether the AIC_IVR has been read. 1. If the nIRQ line has been asserted but the AIC_IVR has not been read, then the processor will read the new higher priority interrupt handler number in the AIC_IVR register and the current interrupt level is updated. 2. If the processor has already read the AIC_IVR, then the nIRQ line is reasserted. When the processor has authorized nested interrupts to occur and reads the AIC_IVR again, it reads the new, higher priority interrupt handler address. At the same time the current priority value is pushed onto a first-in last-out stack and the current priority is updated to the higher priority. When the End of Interrupt Command Register (AIC_EOICR) is written, the current interrupt level is updated with the current interrupt level from the stack (if any). Hence, at the end of a higher priority interrupt, the AIC returns to the previous state corresponding to the preceding lower priority interrupt which had been interrupted. 17.2 Interrupt Handling The interrupt handler must read the AIC_IVR as soon as possible. This deasserts the nIRQ request to the processor and clears the interrupt in case it is programmed to be edge-triggered. This permits the AIC to assert the nIRQ line again when a higher priority unmasked interrupt occurs. At the end of the interrupt service routine, the End of Interrupt Command Register (AIC_EOICR) must be written. This allows pending interrupts to be serviced. 17.2.1 Interrupt Masking Each interrupt source, including FIQ, can be enabled or disabled using the command registers AIC_IECR and AIC_IDCR. The interrupt mask can be read in the read only register AIC_IMR. A disabled interrupt does not affect the servicing of other interrupts. 74 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 17.2.2 Interrupt Clearing and Setting All interrupt sources which are programmed to be edge-triggered (including FIQ) can be individually set or cleared by respectively writing to the registers AIC_ISCR and AIC_ICCR. This function of the interrupt controller is available for auto-test or software debug purposes. 17.3 Standard Interrupt Sequence It is assumed that: • The advanced interrupt controller has been programmed, AIC_SVR registers are loaded with corresponding interrupt service routine addresses and interrupts are enabled. When nIRQ is asserted and if the I bit of CPSR is 0, the sequence is as follows: 1. The CPSR is stored in SPSR_irq, the current value of the Program Counter is loaded in the IRQ link register (R14_IRQ) and the Program Counter (R15) is loaded with 0x18. In the following cycle during fetch at address 0x1C, the ARM core adjusts R14_IRQ, decrementing it by 4. 2. The ARM core enters IRQ mode if it is not already. 3. When the instruction at 0x18 is executed, the Program Counter is loaded with the value read in the AIC_IVR. Reading the AIC_IVR has the following effects: Sets the current interrupt to be the pending one with the highest priority. The current level is the priority level of the current interrupt. De-asserts the nIRQ line on the processor (even if vectoring is not used, AIC_IVR must be read in order to de-assert nIRQ). Automatically clears the interrupt if it has been programmed to be edge-triggered. Pushes the current level on to the stack. Returns the AIC_SVR corresponding to the current interrupt. 4. The previous step establishes a connection to the corresponding ISR. This begins by saving the link register (R14_IRQ) and the SPSR (SPSR_IRQ). Note that the link register must be decremented by 4 when it is saved if it is to be restored directly into the Program Counter at the end of the interrupt. 5. Further interrupts can then be unmasked by clearing the I bit in the CPSR, allowing re-assertion of the nIRQ to be taken into account by the core. This can occur if an interrupt with a higher priority than the current one occurs. 6. The interrupt handler then proceeds as required, saving the registers which are used and restoring them at the end. During this phase, an interrupt of priority higher than the current level will restart the sequence from step 1. Note that if the interrupt is programmed to be level-sensitive, the source of the interrupt must be cleared during this phase. 7. The I bit in the CPSR must be set in order to mask interrupts before exiting to ensure that the interrupt is completed in an orderly manner. 8. The service routine should then connect to the common exit routine. 9. The End Of Interrupt Command Register (AIC_EOICR) must be written in order to indicate to the AIC that the current interrupt is finished. This causes the current level to be popped from the stack, restoring the previous current level if one exists. If another interrupt with lower or equal priority than the old current level is pending, the nIRQ line is re-asserted but the interrupt sequence does not immediately start because the I bit is set in the core. 75 6069C–ATARM–15-Sep-05 10. The SPSR (SPSR_IRQ) is restored. Finally, the saved value of the Link Register is restored directly into the PC. This has the effect of returning from the interrupt to the step previously executed, of loading the CPSR with the stored SPSR and of masking or unmasking the interrupts depending on the state saved in the SPSR (the previous state of the ARM core). Note: The I bit in the SPSR is significant. If it is set, it indicates that the ARM core was just about to mask IRQ interrupts when the mask instruction was interrupted. Hence, when the SPSR is restored, the mask instruction is completed (IRQ is masked). 17.4 Fast Interrupt The external FIQ line is the only source which can raise a fast interrupt request to the processor. Therefore it has no priority controller. It can be programmed to be positive- or negativeedge triggered or high- or low-level sensitive in the AIC_SMR0 register. The fast interrupt handler address can be stored in the AIC_SVR0 register. The value written into this register is available by reading the AIC_FVR register when an FIQ interrupt is raised. By storing the following instruction at address 0x0000001C, the processor will load the program counter with the interrupt handler address stored in the AIC_FVR register. LDR PC, [PC, #-&F20] Alternatively, the interrupt handler can be stored starting from address 0x0000001C as described in the ARM7TDMI datasheet. 17.4.1 Fast Interrupt Sequence It is assumed that: • The advanced interrupt controller has been programmed, AIC_SVR[0] is loaded with the fast interrupt service routine address and the fast interrupt is enabled. • Nested fast interrupts are not needed by the user. When nFIQ is asserted, if the F bit of CPSR is 0, the sequence is: 1. The CPSR is stored in SPSR_fiq, the current value of the Program Counter is loaded in the FIQ link register (R14_FIQ) and the Program Counter (R15) is loaded with 0x1C. In the following cycle, during fetch at address 0x20, the ARM core adjusts R14_FIQ, decrementing it by 4. 2. The ARM core enters FIQ mode. 3. When the instruction loaded at address 0x1C is executed, the Program Counter is loaded with the value read in AIC_FVR. Reading the AIC_FVR has the effect of clearing the fast interrupt (source 0 connected to the FIQ line) if it has been programmed to be edge-triggered. In this case only, it de-asserts the nFIQ line on the processor. 4. The previous step establishes a connection to the corresponding interrupt service routine. It is not necessary to save the Link Register (R14_FIQ) and the SPSR (SPSR_FIQ) if nested fast interrupts are not needed. 5. The interrupt handler can then proceed as required. It is not necessary to save registers R8 to R13 because FIQ mode has its own dedicated registers and the user R8 to R13 are banked. The other registers, R0 to R7, must be saved before being used and restored at the end (before the next step). Note that if the fast interrupt is programmed to be level- sensitive, the source of the interrupt must be cleared during this phase in order to de-assert the nFIQ line. 6. Finally, the Link Register (R14_FIQ) is restored into the PC after decrementing it by 4 (e.g., with instruction SUB PC, LR, #4). This has the effect of returning from the inter- 76 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 rupt to the step previously executed, of loading the CPSR with the SPSR and of masking or unmasking the fast interrupt depending on the state saved in the SPSR. Note: The F bit in the SPSR is significant. If it is set, it indicates that the ARM core was just about to mask FIQ interrupts when the mask instruction was interrupted. Hence, when the SPSR is restored, the interrupted instruction is completed (FIQ is masked). 17.5 Software Interrupt Any interrupt source of the AIC can be a software interrupt. It must be programmed to be edge-triggered in order to set or clear it by writing to the AIC_ISCR and AIC_ICCR. This is totally independent of the SWI instruction of the ARM7TDMI processor. 17.6 Spurious Interrupt A spurious interrupt is a signal of very short duration on one of the interrupt input lines. A spurious interrupt also arises when an interrupt is triggered and masked in the same cycle. 17.6.1 Spurious Interrupt Sequence A spurious interrupt is handled by the following sequence of actions. 1. When an interrupt is active, the AIC asserts the nIRQ (or nFIQ) line and the ARM7TDMI enters IRQ (or FIQ) mode. At this moment, if the interrupt source disappears, the nIRQ (or nFIQ) line is de-asserted but the ARM7TDMI continues with the interrupt handler. 2. If the IRQ Vector Register (AIC_IVR) is read when the nIRQ is not asserted, the AIC_IVR is read with the contents of the Spurious Interrupt Vector Register. 3. If the FIQ Vector Register (AIC_FVR) is read when the nFIQ is not asserted, the AIC_FVR is read with the contents of the Spurious Interrupt Vector Register. 4. The Spurious ISR must write an End of Interrupt command as a minimum, however, it is sufficient to write to the End of Interrupt Command Register (AIC_EOICR). Until the AIC_EOICR write is received by the interrupt controller, the nIRQ (or nFIQ) line is not re-asserted. 5. This causes the ARM7TDMI to jump into the Spurious Interrupt Routine. 6. During a spurious ISR, the AIC_ISR reads 0. 77 6069C–ATARM–15-Sep-05 17.7 AIC User Interface AIC Register Mapping Register Source Mode Register 0 Source Mode Register 1 – Source Mode Register 31 Source Vector Register 0 Source Vector Register 1 – Source Vector Register 31 IRQ Vector Register FIQ Vector Register Interrupt Status Register Interrupt Pending Register Interrupt Mask Register Core Interrupt Status Register Reserved Reserved Interrupt Enable Command Register Interrupt Disable Command Register Interrupt Clear Command Register Interrupt Set Command Register End-of-interrupt Command Register Spurious Interrupt Vector Register Register Name AIC_SMR0 AIC_SMR1 – AIC_SMR31 AIC_SVR0 AIC_SVR1 – AIC_SVR31 AIC_IVR AIC_FVR AIC_ISR AIC_IPR AIC_IMR AIC_CISR – – AIC_IECR AIC_IDCR AIC_ICCR AIC_ISCR AIC_EOICR AIC_SPU Access Read/Write Read/Write – Read/Write Read/Write Read/Write – Read/Write Read-only Read-only Read-only Read-only Read-only Read-only – – Write-only Write-only Write-only Write-only Write-only Read/Write Reset State 0 0 – 0 0 0 – 0 0 0 0 (1) Base Address: 0xFF030000 with double mapping at address 0xFFFF F000 Table 17-2. Offset 0x000 0x004 – 0x07C 0x080 0x084 – 0xFC0 0x100 0x104 0x108 0x10C 0x110 0x114 0x118 0x11C 0x120 0x124 0x128 0x12C 0x130 0x134 Note: 0 0 – – – – – – – 0 1. The reset value of this register depends on the level of the external IRQ lines. All other sources are cleared at reset. 78 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 17.7.1 AIC Source Mode Register AIC_SMR0...AIC_SMR31 Read/Write 30 – 22 – 14 – 6 SRCTYPE 29 – 21 – 13 – 5 28 – 20 – 12 – 4 – 27 – 19 – 11 – 3 – 26 – 18 – 10 – 2 25 – 17 – 9 – 1 PRIOR 24 – 16 – 8 – 0 Register Name: Access Type: 31 – 23 – 15 – 7 – • PRIOR: Priority Level Programs the priority level for all sources except source 0 (FIQ). The priority level can be between 0 (lowest) and 7 (highest). The priority level is not used for the FIQ in the SMR0. • SRCTYPE: Interrupt Source Type Programs the input to be positive- or negative-edge triggered or positive- or negative-level sensitive. The active level or edge is not programmable for the internal sources. SRCTYPE 0 0 1 1 0 1 0 1 Internal Sources Level-sensitive Edge-triggered Level-sensitive Edge-triggered External Sources Low-level sensitive Negative-edge triggered High-level sensitive Positive-edge triggered 79 6069C–ATARM–15-Sep-05 17.7.2 AIC Source Vector Registers AIC_SVR0...AIC_SVR31 Read/Write 30 29 28 Vector 23 22 21 20 Vector 15 14 13 12 Vector 7 6 5 4 Vector 3 2 1 0 11 10 9 8 19 18 17 16 27 26 25 24 Register Name: Access Type: 31 • Vector In these registers, the user may store the addresses of the corresponding handler for each interrupt source. 17.7.3 AIC Interrupt Vector Registers AIC_IVR Read-only 0 30 29 28 IRQV 23 22 21 20 IRQV 15 14 13 12 IRQV 7 6 5 4 IRQV 3 2 1 0 11 10 9 8 19 18 17 16 27 26 25 24 Register Name: Access Type: Reset Value: 31 • IRQV The IRQ Vector Register contains the vector programmed by the user in the Source Vector Register corresponding to the current interrupt. The SVR Register (1 to 31) is indexed by the current interrupt number when the IVR register is read. When there is no interrupt, the IRQ register reads 0. 80 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 17.7.4 AIC FIQ Vector Register AIC_FVR Read-only 0 30 29 28 FIQV 23 22 21 20 FIQV 15 14 13 12 FIQV 7 6 5 4 FIQV 3 2 1 0 11 10 9 8 19 18 17 16 27 26 25 24 Register Name: Access Type: Reset Value: 31 • FIQ The vector register contains the vector programmed by the user in SVR Register 0 which corresponds to FIQ. 81 6069C–ATARM–15-Sep-05 17.7.5 AIC Interrupt Status Register AIC_ISR Read-only 30 – 22 – 14 – 6 – 29 – 21 – 13 – 5 – 28 – 20 – 12 – 4 27 – 19 – 11 – 3 26 – 18 – 10 – 2 IRQID 25 – 17 – 9 – 1 24 – 16 – 8 – 0 Register Name: Access Type: 31 – 23 – 15 – 7 – • IRQID The interrupt status register returns the current interrupt source register. 17.7.6 AIC Interrupt Pending Register Register Name:AIC_IPR Access Type:Read-only 31 0 23 0 15 PIOB 7 PIOA 30 0 22 0 14 UARTB 6 TC2 29 0 21 0 13 MACB 5 TC1 28 0 20 0 12 0 4 TC0 27 0 19 0 11 IRQ1 3 UARTA 26 0 18 0 10 IRQ0 2 SWI 25 0 17 0 9 SPI 1 0 24 0 16 0 8 MACA 0 FIQ • Interrupt Pending 0 = Corresponding interrupt is not pending. 1 = Corresponding interrupt is pending. 82 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 17.7.7 AIC Interrupt Mask Register AIC_IMR Read-only 30 0 22 0 14 UARTB 6 TC2 29 0 21 0 13 MACB 5 TC1 28 0 20 0 12 0 4 TC0 27 0 19 0 11 IRQ1(1) 3 UARTA 26 0 18 0 10 IRQ0 2 SWI 25 0 17 0 9 SPI 1 0 24 0 16 0 8 MACA 0 FIQ Register Name: Access Type: 31 0 23 0 15 PIOB 7 PIOA • Interrupt Mask 0 = Corresponding interrupt is disabled. 1 = Corresponding interrupt is enabled. 17.7.8 AIC Core Interrupt Status Register AIC_CISR Read-only 30 – 22 – 14 – 6 – 29 – 21 – 13 – 5 – 28 – 20 – 12 – 4 – 27 – 19 – 11 – 3 – 26 – 18 – 10 – 2 – 25 – 17 – 9 – 1 NIRQ 24 – 16 – 8 – 0 nFIQ Register Name: Access Type: 31 – 23 – 15 – 7 – • nFIQ: nFIQ Status 0 = nFIQ line inactive. 1 = nFIQ line active. • NIRQ: nIRQ Status 0 = nIRQ line inactive. 1 = nIRQ line active. 83 6069C–ATARM–15-Sep-05 17.7.9 AIC Interrupt Enable Command Register AIC_IECR Write-only 30 0 22 0 14 UARTB 6 TC2 29 0 21 0 13 MACB 5 TC1 28 0 20 0 12 0 4 TC0 27 0 19 0 11 IRQ1 3 UARTA 26 0 18 0 10 IRQ0 2 SWI 25 0 17 0 9 SPI 1 0 24 0 16 0 8 MACA 0 FIQ Register Name: Access Type: 31 0 23 0 15 PIOB 7 PIOA • Interrupt Enable 0 = No effect. 1 = Enables the corresponding interrupt. 17.7.10 AIC Interrupt Disable Command Register AIC_IDCR Write-only 30 0 22 0 14 UARTB 6 TC2 29 0 21 0 13 MACB 5 TC1 28 0 20 0 12 0 4 TC0 27 0 19 0 11 IRQ1 3 UARTA 26 0 18 0 10 IRQ0 2 SWI 25 0 17 0 9 SPI 1 0 24 0 16 0 8 MACA 0 FIQ Register Name: Access Type: 31 0 23 0 15 PIOB 7 PIOA • Interrupt Disable 0 = No effect. 1 = Disables the corresponding interrupt. 84 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 17.7.11 AIC Interrupt Clear Command Register AIC_ICCR Write-only 30 0 22 0 14 UARTB 6 TC2 29 0 21 0 13 MACB 5 TC1 28 0 20 0 12 0 4 TC0 27 0 19 0 11 IRQ1 3 UARTA 26 0 18 0 10 IRQ0 2 SWI 25 0 17 0 9 SPI 1 0 24 0 16 0 8 MACA 0 FIQ Register Name: Access Type: 31 0 23 0 15 PIOB 7 PIOA • Interrupt Clear 0 = No effect. 1 = Clears the corresponding interrupt. 17.7.12 AIC Interrupt Set Command Register AIC_ISCR Write-only 30 0 22 0 14 UARTB 6 TC2 29 0 21 0 13 MACB 5 TC1 28 0 20 0 12 0 4 TC0 27 0 19 0 11 IRQ1 3 UARTA 26 0 18 0 10 IRQ0 2 SWI 25 0 17 0 9 SPI 1 0 24 0 16 0 8 MACA 0 FIQ Register Name: Access Type: 31 0 23 0 15 PIOB 7 PIOA • Interrupt Set 0 = No effect. 1 = Sets the corresponding interrupt. 85 6069C–ATARM–15-Sep-05 17.7.13 AIC End of Interrupt Command Register AIC_EOICR Write-only 30 – 22 – 14 – 6 – 29 – 21 – 13 – 5 – 28 – 20 – 12 – 4 – 27 – 19 – 11 – 3 – 26 – 18 – 10 – 2 – 25 – 17 – 9 – 1 – 24 – 16 – 8 – 0 – Register Name: Access Type: 31 – 23 – 15 – 7 – The End of Interrupt Command Register is used by the interrupt routine to indicate that the interrupt treatment is complete. Any value can be written as it is only necessary to make a write to this register location to signal the end of interrupt treatment. 17.7.14 AIC Spurious Interrupt Vector Register AIC_SPU Read/Write 30 29 28 SIQV 23 22 21 20 SIQV 15 14 13 12 SIQV 7 6 5 4 SIQV 3 2 1 0 11 10 9 8 19 18 17 16 27 26 25 24 Register Name: Access Type: 31 • SIQV This register contains the 32-bit address of an interrupt routine which is used to treat cases of spurious interrupts. The programmed address is read in the AIC_IVR if it is read when the nIRQ line is not asserted. The programmed address is read in the AIC_FVR if it is read when the nFIQ line is not asserted. 86 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 18. Parallel I/O Controller (PIO) The AT91C140 integrates two PIO controllers, PIOA and PIOB. PIOA controls 15 I/O lines and PIOB controls 10 I/O lines. Each I/O line can be programmed as an input or an output and can generate an interrupt on level change. These pins are used for several functions: • External I/O for Internal Peripherals • Keypad Controller Function • General Purpose I/O 18.1 Output Selection The user can enable each individual I/O signal as an output with the PIO_OER and PIO_ODR registers. The output status of the I/O signals can be read in the PIO_OSR register. The direction defined has an effect only if the pin is configured to be controlled by the PIO controller. 18.2 I/O Levels Each pin can be configured to be driven high or low. The level is defined in four different ways, according to the following conditions: • If a pin is controlled by the PIO controller and is defined as an output, the level is programmed using the PIO_SODR and PIO_CODR registers. In this case, the programmed value can be read in the PIO_ODSR register. • If a pin is controlled by the PIO controller and is not defined as an output, the level is determined by the external circuit. • If a pin is not controlled by the PIO controller, the state of the pin is defined by the peripheral. In all cases, the level on the pin can be read in the register PIO_PDSR. 18.3 Interrupts Each parallel I/O can be programmed to generate an interrupt when a level change occurs. This is controlled by the PIO_IER and PIO_IDR registers which enable/disable the I/O interrupt by setting/clearing the corresponding bit in PIO_IMR. When a change in level occurs, the corresponding bit in PIO_ISR is set depending on whether the pin is used as a PIO or a peripheral, and whether it is defined as input or output. If the corresponding interrupt in PIO_IMR is enabled, the PIO interrupt is asserted. When PIO_ISR is read, the register is automatically cleared. 87 6069C–ATARM–15-Sep-05 18.4 I/O Line Control Figure 18-1. I/O Line Block Diagram PIO_OSR Pad Output Enable 1 0 Peripheral Output Enable PIO_PSR PIO_ODSR Pad Output 1 0 Pad Peripheral Output Pad Input 0 Peripheral Input 1 PIO_PSR PIO_PDSR Event Detection PIO_ISR PIO_IMR PIOIRQ 88 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 18.5 Parallel I/O Controller (PIO) User Interface Each individual I/O is associated with a bit position in the parallel I/O user interface registers. Each of these registers is 32 bits wide. If a parallel I/O line is not defined, writing to the corresponding bits has no effect. Undefined bits read as zero. Table 18-1. Offset 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C 0x20 0x24 0x28 0x2C 0x30 0x34 0x38 0x3C 0x40 0x44 0x48 0x4C Notes: PIO Controller Memory Map Register Name PIO_PER PIO_PDR PIO_PSR – PIO_OER PIO_ODR PIO_OSR – – – – – PIO_SODR PIO_CODR PIO_ODSR PIO_PDSR PIO_IER PIO_IDR PIO_IMR PIO_ISR (2) (1) Description PIO Enable Register PIO Disable Register PIO Status Register Reserved Output Enable Register Output Disable Register Output Status Register Reserved Reserved Reserved Reserved Reserved Set Output Data Register Clear Output Data Register Output Data Status Register Pin Data Status Register Interrupt Enable Register Interrupt Disable Register Interrupt Mask Register Interrupt Status Register Access Write-only Write-only Read-only – Write-only Write-only Read-only – – – – – Write-only Write-only Read-only Read-only Write-only Write-only Read-only Read-only Reset Value – – – – – – 0x0 – – – 0x0 – – – 0x0 See Note 1 – – – See Note 2 1. The reset value of this register depends on the level of the external pins at reset. 2. This register is cleared at reset. However, the first read of the register can give a value not equal to zero if any changes have occurred on any pins between the reset and the read. 89 6069C–ATARM–15-Sep-05 18.5.1 PIO Enable Register Register Name: PIO_PER Access Type: Write-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register is used to enable individual pins to be controlled by the PIO controller instead of the associated peripheral. When the PIO is enabled, the associated peripheral (if any) is held at logic zero. 1 = Enables the PIO to control the corresponding pin (disables peripheral control of the pin). 0 = No effect. 18.5.2 PIO Disable Register Register Name: PIO_PDR Access Type: Write-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register is used to disable PIO control of individual pins. When the PIO control is disabled, the normal peripheral function is enabled on the corresponding pin. 1 = Disables PIO control (enables peripheral control) on the corresponding pin. 0 = No effect. 90 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 18.5.3 PIO Status Register Register Name: PIO_PSR Access Type: Read-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register indicates which pins are enabled for PIO control. This register is updated when PIO lines are enabled or disabled. 1 = PIO is active on the corresponding line (peripheral is inactive). 0 = PIO is inactive on the corresponding line (peripheral is active). 18.5.4 PIO Output Enable Register Register Name: PIO_OER Access Type: Write-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register is used to enable PIO output drivers. If the pin is driven by a peripheral, there is no effect on the pin but the information is stored. The register is programmed as follows: 1 = Enables the PIO output on the corresponding pin. 0 = No effect. 91 6069C–ATARM–15-Sep-05 18.5.5 PIO Output Disable Register Register Name: PIO_ODR Access Type: Write-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register is used to disable PIO output drivers. If the pin is driven by the peripheral, there is no effect on the pin, but the information is stored. The register is programmed as follows: 1 = Disables the PIO output on the corresponding pin. 0 = No effect. 18.5.6 PIO Output Status Register Register Name: PIO_OSR Access Type: Read-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register shows the PIO pin control (output enable) status which is programmed in PIO_OER and PIO ODR. The defined value is effective only if the pin is controlled by the PIO. The register reads as follows: 1 = The corresponding PIO is output on this line. 0 = The corresponding PIO is input on this line. 92 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 18.5.7 PIO Set Output Data Register Register Name: PIO_SODR Access Type: Write-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register is used to set PIO output data. It affects the pin only if the corresponding PIO output line is enabled and if the pin is controlled by the PIO. Otherwise, the information is stored. 1 = PIO output data on the corresponding pin is set. 0 = No effect. 18.5.8 PIO Clear Output Data Register Register Name: PIO_CODR Access Type: Write-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register is used to clear PIO output data. It affects the pin only if the corresponding PIO output line is enabled and if the pin is controlled by the PIO. Otherwise, the information is stored. 1 = PIO output data on the corresponding pin is cleared. 0 = No effect. 93 6069C–ATARM–15-Sep-05 18.5.9 PIO Output Data Status Register Register Name: PIO_ODSR Access Type: Read-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register shows the output data status which is programmed in PIO_SODR or PIO_CODR. The defined value is effective only if the pin is controlled by the PIO Controller and only if the pin is defined as an output. 1 = The output data for the corresponding line is programmed to 1. 0 = The output data for the corresponding line is programmed to 0. 18.5.10 PIO Pin Data Status Register Register Name: PIO_PDSR Access Type: Read-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register shows the state of the physical pin of the chip. The pin values are always valid, regardless of whether the pins are enabled as PIO, peripheral, input or output. The register reads as follows: 1 = The corresponding pin is at logic 1. 0 = The corresponding pin is at logic 0. 94 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 18.5.11 PIO Interrupt Enable Register Register Name: PIO_IER Access Type: Write-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register is used to enable PIO interrupts on the corresponding pin. It has an effect whether PIO is enabled or not. 1 = Enables an interrupt when a change of logic level is detected on the corresponding pin. 0 = No effect. 18.5.12 PIO Interrupt Disable Register Register Name: PIO_IDR Access Type: Write-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register is used to disable PIO interrupts on the corresponding pin. It has an effect whether the PIO is enabled or not. 1 = Disables the interrupt on the corresponding pin. Logic level changes are still detected. 0 = No effect. 95 6069C–ATARM–15-Sep-05 18.5.13 PIO Interrupt Mask Register Register Name: PIO_IMR Access Type: Read-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register shows which pins have interrupts enabled. It is updated when interrupts are enabled or disabled by writing to PIO_IER or PIO_IDR. 1 = Interrupt is enabled on the corresponding pin. 0 = Interrupt is not enabled on the corresponding pin. 18.5.14 PIO Interrupt Status Register Register Name: PIO_ISR Access Type: Read-only 31 P31 23 P23 15 P15 7 P7 30 P30 22 P22 14 P14 6 P6 29 P29 21 P21 13 P13 5 P5 28 P28 20 P20 12 P12 4 P4 27 P27 19 P19 11 P11 3 P3 26 P26 18 P18 10 P10 2 P2 25 P25 17 P17 9 P9 1 P1 24 P24 16 P16 8 P8 0 P0 This register indicates for each pin when a logic value change has been detected (rising or falling edge). This is valid whether the PIO is selected for the pin or not and whether the pin is an input or an output. The register is reset to zero following a read and at reset. 1 = At least one input change has been detected on the corresponding pin since the register was last read. 0 = No input change has been detected on the corresponding pin since the register was last read. 96 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 19. Universal Asynchronous Receiver Transmitter (UART) The AT91C140 provides two identical full-duplex Universal Asynchronous Receiver Transmitters, UART A and UART B. These peripherals sit on the APB bus but are also connected to the ASB bus (and hence external memory) via a dedicated PDC. The main features are: • Programmable Baud Rate Generator • Parity, Framing and Overrun Error Detection • Line Break Generation and Detection • Automatic Echo, Local Loopback and Remote Loopback Channel Modes • Interrupt Generation • Two Dedicated Peripheral Data Controller Channels • 6-, 7- and 8-bit Character Length • Modem Control Signals 19.1 Block Diagram Figure 19-1. UART Block Diagram ARM ASB Peripheral Data Controller Peripheral Bridge Receive Channel Transmit Channel UART APB Control Logic Receiver RXD PIO UART Interrupt Interrupt Control ACLK Baud Rate Generator ACLK/8 Baud Rate Clock Transmitter TXD SCK NRTS Modem Control NCTS NRI NDTR NDSR NDCD 97 6069C–ATARM–15-Sep-05 19.2 Pin Description UART Pins Description UART Serial Clock. Can be configured as input or output. See US_MR Transmit Serial Data Receive Serial Data Request to Send Clear to Send Data Terminal Ready Data Set Ready Data Carrier Detect Ring Indicator Type I/O Output Input Output Input Output Input Input Input Each UART channel has external signals as defined in Table 19-1. Table 19-1. Signal Name SCK TXD RXD NRTS NCTS NDTR NDSR NDCD NRI 19.3 Baud Rate Generator The baud rate generator provides the bit period clock (the baud rate clock) to both the receiver and the transmitter. The baud rate generator can select between external and internal clock sources. The external clock source is SCK. The internal clock sources can be either the ARM Clock (ACLK) or the ARM Clock divided by 8 (ACLK/8). Note: In all cases, if an external clock is used, the duration of each of its levels must be longer than the system clock (ACLK) period. The external clock frequency must be at least 2.5 times lower than the system clock. The selected clock is divided by 16 times the value (CD) written in US_BRGR (Baud Rate Generator Register). If US_BRGR is set to 0, the baud rate clock is disabled. Baud Rate = Selected Clock 16 x CD Table 19-2. Clock Generator Table with Crystal Frequency of 16 MHz CD 260.42 130.21 65.10 43.41 21.70 Actual CD 260 130 65 43 22 Actual Baud Rate (bps) 9615.385 19230.77 38461.54 58139.53 113636.40 Error (bps) 15,38 30.77 61.54 539.53 -1163.64 % Error 0.16 0.16 0.16 0.94 -1.36 Required Baud Rate (bps) 9600 19200 38400 57600 115200 98 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 Figure 19-2. Baud Rate Generator USCLKS [0] CD CD ACLK ACLK/8 0 1 CLK 16-bit Counter OUT >1 1 0 0 Divide by 16 Baud Rate Clock 19.4 Receiver Operations The UART detects the start of a received character by sampling the RXD signal until it detects a valid start bit. A low level (space) on RXD is interpreted as a valid start bit if it is detected for more than seven cycles of the sampling clock, which is 16 times the baud rate. Hence, a space which is longer than 7/16 of the bit period is detected as a valid start bit. A space which is 7/16 of a bit period or shorter is ignored and the receiver continues to wait for a valid start bit. When a valid start bit has been detected, the receiver samples the RXD at the theoretical midpoint of each bit. It is assumed that each bit lasts 16 cycles of the sampling clock (1-bit period) so the sampling point is eight cycles (0.5-bit periods) after the start of the bit. The first sampling point is therefore 24 cycles (1.5-bit periods) after the falling edge of the start bit was detected. Each subsequent bit is sampled 16 cycles (1-bit period) after the previous one. Figure 19-3. Start Bit Detection 16 x Baud Rate Clock RXD Sampling True Start Detection D0 Figure 19-4. Character Reception Example: 8-bit, parity enabled 1 stop 0.5-bit periods 1-bit period RXD Sampling D0 D1 True Start Detection D2 D3 D4 D5 D6 D7 Parity Bit Stop Bit 99 6069C–ATARM–15-Sep-05 19.4.1 Receiver Ready When a complete character is received, it is transferred to the US_RHR and the RXRDY status bit in US_CSR is set. If US_RHR has not been read since the last transfer, the OVRE status bit in US_CSR is set. 19.4.2 Parity Error Each time a character is received, the receiver calculates the parity of the received data bits in accordance with the field PAR in US_MR. It then compares the result with the received parity bit. If different, the parity error bit PARE in US_CSR is set. 19.4.3 Framing Error If a character is received with a stop bit at low level and with at least one data bit at high level, a framing error is generated. This sets FRAME in US_CSR. 19.4.4 Time-out This function allows an idle condition on the RXD line to be detected. The maximum delay for which the UART should wait for a new character to arrive while the RXD line is inactive (high level) is programmed in US_RTOR. When this register is set to 0, no time-out is detected. Otherwise, the receiver waits for a first character and then initializes a counter which is decremented at each bit period and reloaded at each byte reception. When the counter reaches 0, the TIMEOUT bit in US_CSR is set. The user can restart the wait for a first character with the STTTO (Start Time-out) bit in US_CR. Calculation of time-out duration: Duration = Value × 4 × Bit Period 19.5 Transmitter Start bit, data bits, parity bit and stop bits are serially shifted, lowest significant bit first, on the falling edge of the serial clock. The number of data bits is selected in the CHRL field in US_MR. The parity bit is set according to the PAR field in US_MR. The number of stop bits is selected in the NBSTOP field in US_MR. When a character is written to US_THR, it is transferred to the Shift Register as soon as it is empty. When the transfer occurs, the TXRDY bit in US_CSR is set until a new character is written to US_THR. If the Transmit Shift Register and US_THR are both empty, the TXEMPTY bit in US_CSR is set. Figure 19-5. Character Transmission Example: 8-bit, parity enabled 1 stop Baud Rate Clock TXD Start Bit D0 D1 D2 D3 D4 D5 D6 D7 Parity Bit Stop Bit 100 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 19.5.1 Time-guard The time-guard function allows the transmitter to insert an idle state on the TXD line between two characters. The duration of the idle state is programmed in US_TTGR. When this register is set to zero, no time-guard is generated. Otherwise, the transmitter holds a high level on TXD after each transmitted byte during the number of bit periods programmed in US_TTGR. Idle state duration between two characters = Time-guard value x Bit period 19.6 Channel Modes The UART can be programmed to operate in three different test modes using the field CHMODE in US_MR. Automatic echo mode allows bit-by-bit re-transmission. When a bit is received on the RXD line, it is sent to the TXD line. Programming the transmitter has no effect. Local loopback mode allows the transmitted characters to be received. TXD and RXD pins are not used and the output of the transmitter is internally connected to the input of the receiver. The RXD pin level has no effect and the TXD pin is held high, as in idle state. Remote loopback mode directly connects the RXD pin to the TXD pin. The transmitter and the receiver are disabled and have no effect. This mode allows bit-by-bit re-transmission. Figure 19-6. Channel Modes Automatic Echo Receiver RXD Transmitter Disabled TXD Local Loopback Receiver Disabled RXD VDD Transmitter Disabled TXD Remote Loopback Receiver VDD Disabled RXD Transmitter Disabled TXD 101 6069C–ATARM–15-Sep-05 19.7 Peripheral Data Controller Each UART channel is closely connected to a corresponding peripheral data controller channel. One is dedicated to the receiver, the other is dedicated to the transmitter. The PDC channel is programmed using US_TPR and US_TCR for the transmitter and US_RPR and US_RCR for the receiver. The status of the PDC is given in US_CSR by the ENDTX bit for the transmitter and by the ENDRX bit for the receiver. The pointer registers US_TPR and US_RPR are used to store the address of the transmit or receive buffers. The counter registers US_TCR and US_RCR are used to store the size of these buffers. The receiver data transfer is triggered by the RXRDY bit and the transmitter data transfer is triggered by TXRDY. When a transfer is performed, the counter is decremented and the pointer is incremented. When the counter reaches 0, the status bit is set (ENDRX for the receiver, ENDTX for the transmitter in US_CSR) and can be programmed to generate an interrupt. Transfers are then disabled until a new non-zero counter value is programmed. 19.8 19.8.1 Modem Control and Status Signals NCTS: Clear to Send When low, this indicates that the modem or data set is ready to exchange data. The NCTS signal is a modem status input; its conditions can be tested by the CPU reading bit 4 (CTS) of the Modem Status Register. Bit 4 is the complement of the NCTS signal. Bit 0 (DCTS) of the Modem Status Register indicates whether the NCTS input has changed state since the previous read of the Modem Status Register. NCTS has no effect on the transmitter. NDCD: Data Carrier Detect When low, this indicates that the data carrier has been detected by the modem or data set. The NDCD signal is a modem status input; its condition can be tested by the CPU reading bit 7 (DCD) of the Modem Status Register. Bit 7 is the complement of the NDCD signal. Bit 3 (DDCD) of the Modem Status Register indicates whether the NDCD input pin has changed since the previous reading of the Modem Status Register. NDCD has no effect on the receiver. NDSR: Data Set Ready When low, this informs the modem or data set that the UART is ready to communicate. The NDSR signal is a modem status input; its condition can be tested by the CPU reading bit 5 (DSR) of the Modem Status Register. Bit 5 is the complement of the NDSR signal. Bit 1 (DDSR of the Modem Status Register) indicates whether the NDSR input has changed state since the previous read of the Modem Status Register. NDTR: Data Terminal Ready When low, this informs the modem or data set that the UART is ready to communicate. The NDTR output signal can be set to active low by programming bit 0 (DTR) of the Modem Control Register to a high level. A master reset operation sets this signal to its inactive (high) state. Loop mode operation holds this signal in its inactive state. NRI: Ring Indicator When low, this indicates that a telephone ringing signal has been received by the modem or data set. The NRI signal is a modem status input; its condition can be tested by the CPU reading bit 6 (RI) of the Modem Status Register. Bit 6 is the complement of the NRI signal. Bit 2 19.8.2 19.8.3 19.8.4 19.8.5 102 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 (TERI) of the Modem Status Register indicates whether the NRI input signal has changed from a low to a high state since the previous read of the Modem Status Register. 19.8.6 NRTS: Request to Send When low, this informs the modem or data set that the UART is ready to exchange data. The NRTS output signal can be set to an active low by programming bit 1 (RTS) of the Modem Control Register. A master reset operation sets this signal to its inactive (high) state. 103 6069C–ATARM–15-Sep-05 19.9 Universal Asynchronous Receiver/Transmitter (UART) User Interface UART Memory Map Register Name US_CR US_MR US_IER US_IDR US_IMR US_CSR US_RHR US_THR US_BRGR US_RTOR US_TTGR – US_RPR US_RCR US_TPR US_TCR US_MC US_MS Description Control Register Mode Register Interrupt Enable Register Interrupt Disable Register Interrupt Mask Register Channel Status Register Receiver Holding Register Transmitter Holding Register Baud Rate Generator Register Receiver Time-out Register Transmitter Time-guard Register Reserved Receive Pointer Register Receive Counter Register Transmit Pointer Register Transmit Counter Register Modem Control Register Modem Status Register Access Write-only Read/Write Write-only Write-only Read-only Read-only Read-only Write-only Read/Write Read/Write Read/Write – Read/Write Read/Write Read/Write Read/Write Write-only Read-only Reset Value – 0 – – 0 0x18 0 – 0 0 0 – 0 0 0 0 – Table 19-3. Offset 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C 0x20 0x24 0x28 0x2C 0x30 0x34 0x38 0x3C 0x40 0x44 104 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 19.9.1 UART Control Register Name: US_CR Access Type: Write-only 31 – 23 – 15 – 7 TXDIS 30 – 22 – 14 – 6 TXEN 29 – 21 – 13 – 5 RXDIS 28 – 20 – 12 – 4 RXEN 27 – 19 – 11 – 3 RSTTX 26 – 18 – 10 – 2 RSTRX 25 – 17 – 9 – 1 – 24 – 16 – 8 RSTSTA 0 – • RSTRX: Reset Receiver 0 = No effect. 1 = The receiver logic is reset. • RSTTX: Reset Transmitter 0 = No effect. 1 = The transmitter logic is reset. • RXEN: Receiver Enable 0 = No effect. 1 = The receiver is enabled if RXDIS is 0. • RXDIS: Receiver Disable 0 = No effect. 1 = The receiver is disabled. • TXEN: Transmitter Enable 0 = No effect. 1 = The transmitter is enabled if TXDIS is 0. • TXDIS: Transmitter Disable 0 = No effect. 1 = The transmitter is disabled. • RSTSTA: Reset Status Bits 0 = No effect. 1 = Resets the status bits PARE, FRAME, OVRE and RXBRK in the US_CSR. 105 6069C–ATARM–15-Sep-05 19.9.2 UART Mode Register Name: US_MR Access Type: Read/Write 31 – 23 – 15 CHMODE 7 CHRL 6 5 USCLKS 30 – 22 – 14 29 – 21 – 13 NBSTOP 4 3 – 28 – 20 – 12 27 – 19 – 11 26 – 18 – 10 PAR 2 – 1 – 25 – 17 – 9 24 – 16 – 8 – 0 – • USCLKS: Clock Selection USCLKS 0 0 1 0 1 X Selected Clock ACLK ACLK/8 External (SCK) • CHRL: Character Length CHRL 0 0 1 1 0 1 0 1 Character Length Five bits Six bits Seven bits Eight bits • PAR: Parity Type PAR 0 0 0 0 1 0 0 1 1 0 0 1 0 1 x Parity Type Even parity Odd parity Parity forced to 0 (space) Parity forced to 1 (mark) No parity • NBSTOP: Number of Stop Bits NBSTOP 0 0 1 1 0 1 0 1 1 stop bit 1.5 stop bits 2 stop bits Reserved 106 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 • CHMODE: Channel Mode CHMODE 0 0 Mode Description Normal Mode The UART channel operates as an Rx/Tx UART. Automatic Echo Receiver data input is connected to TXD pin. Local Loopback Transmitter output signal is connected to receiver input signal. Remote Loopback RXD pin is internally connected to TXD pin. 0 1 1 0 1 1 107 6069C–ATARM–15-Sep-05 19.9.3 UART Interrupt Enable Register Name: US_IER Access Type: Write-only 31 – 23 – 15 – 7 PARE 30 – 22 – 14 – 6 FRAME 29 – 21 – 13 – 5 OVRE 28 – 20 – 12 – 4 ENDTX 27 – 19 – 11 – 3 ENDRX 26 – 18 – 10 DMSI 2 – 25 – 17 – 9 TXEMPTY 1 TXRDY 24 – 16 – 8 – 0 RXRDY • RXRDY: Enable RXRDY Interrupt • TXRDY: Enable TXRDY Interrupt • ENDRX: Enable End of Receive Transfer Interrupt • ENDTX: Enable End of Transmit Transfer Interrupt • OVRE: Enable Overrun Error Interrupt • FRAME: Enable Framing Error Interrupt • PARE: Enable Parity Error Interrupt • TXEMPTY: Enable TXEMPTY Interrupt • DMSI: Delta Modem Interrupt 0 = No effect. 1 = Enables the corresponding interrupt. 108 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 19.10 UART Interrupt Disable Register Name: Access Type: 31 – 23 – 15 – 7 PARE 30 – 22 – 14 – 6 FRAME US_IDR Write-only 29 – 21 – 13 – 5 OVRE 28 – 20 – 12 – 4 ENDTX 27 – 19 – 11 – 3 ENDRX 26 – 18 – 10 DMSI 2 – 25 – 17 – 9 TXEMPTY 1 TXRDY 24 – 16 – 8 – 0 RXRDY • RXRDY: Disable RXRDY Interrupt • TXRDY: Disable TXRDY Interrupt • ENDRX: Disable End of Receive Transfer Interrupt • ENDTX: Disable End of Transmit Transfer Interrupt • OVRE: Disable Overrun Error Interrupt • FRAME: Disable Framing Error Interrupt • PARE: Disable Parity Error Interrupt • TXEMPTY: Disable TXEMPTY Interrupt • DMSI: Disable Delta Modem Interrupt 0 = No effect. 1 = Disables the corresponding interrupt. 109 6069C–ATARM–15-Sep-05 19.11 UART Interrupt Mask Register Name: Access Type: 31 – 23 – 15 – 7 PARE 30 – 22 – 14 – 6 FRAME US_IMR Read-only 29 – 21 – 13 – 5 OVRE 28 – 20 – 12 – 4 ENDTX 27 – 19 – 11 – 3 ENDRX 26 – 18 – 10 DMSI 2 RXBRK 25 – 17 – 9 TXEMPTY 1 – 24 – 16 – 8 – 0 RXRDY • RXRDY: RXRDY Interrupt Mask • TXRDY: TXRDY Interrupt Mask • ENDRX: End of Receive Transfer Interrupt Mask • ENDTX: End of Transmit Transfer Interrupt Mask • OVRE: Overrun Error Interrupt Mask • FRAME: Framing Error Interrupt Mask • PARE: Parity Error Interrupt Mask • TXEMPTY: TXEMPTY Interrupt Mask • DMSI: Delta Modem Status Indication Interrupt Mask 0 = The corresponding interrupt is disabled. 1 = The corresponding interrupt is enabled. 110 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 19.11.1 UART Channel Status Register Name: US_CSR Access Type: Read-only 31 – 23 – 15 – 7 PARE 30 – 22 – 14 – 6 FRAME 29 – 21 – 13 – 5 OVRE 28 – 20 – 12 – 4 ENDTX 27 – 19 – 11 – 3 ENDRX 26 – 18 – 10 DMSI 2 – 25 – 17 – 9 TXEMPTY 1 TXRDY 24 – 16 – 8 – 0 RXRDY • RXRDY: Receiver Ready 0 = No complete character has been received since the last read of the US_RHR or the receiver is disabled. 1 = At least one complete character has been received and the US_RHR has not yet been read. • TXRDY: Transmitter Ready 0 = US_THR contains a character waiting to be transferred to the Transmit Shift Register. 1 = US_THR is empty and there is no break request pending TSR availability. Equal to zero when the UART is disabled or at reset. Transmitter enable command (in US_CR) sets this bit to one. • ENDRX: End-of-receive Transfer 0 = The end-of-transfer signal from the PDC channel dedicated to the receiver is inactive. 1 = The end-of-transfer signal from the PDC channel dedicated to the receiver is active. • ENDTX: End-of-transmit Transfer 0 = The end-of-transfer signal from the PDC channel dedicated to the transmitter is inactive. 1 = The end-of-transfer signal from the PDC channel dedicated to the transmitter is active. • OVRE: Overrun Error 0 = No byte has been transferred from the Receive Shift Register to the US_RHR when RxRDY was asserted since the last reset status bits command. 1 = At least one byte has been transferred from the Receive Shift Register to the US_RHR when RxRDY was asserted since the last reset status bits command. • FRAME: Framing Error 0 = No stop bit has been detected low since the last reset status bits command. 1 = At least one stop bit has been detected low since the last reset status bits command. • PARE: Parity Error 1 = At least one parity bit has been detected false (or a parity bit high in multi-drop mode) since the last reset status bit” command. 0 = No parity bit has been detected false (or a parity bit high in multi-drop mode) since the last reset status bits command. • TXEMPTY: Transmitter Empty 0 = There are characters in either US_THR or the Transmit Shift Register or a break is being transmitted. 1 = There are no characters in US_THR and the Transmit Shift Register and break is not active. Equal to zero when the UART is disabled or at reset. Transmitter enable command (in US_CR) sets this bit to one. • DMSI: Delta Modem Status Indication Interrupt 0 = No effect. 1 = There has been a change in the modem status delta bits since the last reset status bits command. 111 6069C–ATARM–15-Sep-05 19.11.2 UART Receiver Holding Register Name: US_RHR Access Type: Read-only 31 – 23 – 15 – 7 30 – 22 – 14 – 6 29 – 21 – 13 – 5 28 – 20 – 12 – 4 RXCHR 27 – 19 – 11 – 3 26 – 18 – 10 – 2 25 – 17 – 9 – 1 24 – 16 – 8 – 0 • RXCHR: Received Character Last character received if RXRDY is set. When number of data bits is less than eight, the bits are right-aligned. 19.11.3 UART Transmitter Holding Register Name: US_THR Access Type: Write-only 31 – 23 – 15 – 7 30 – 22 – 14 – 6 29 – 21 – 13 – 5 28 – 20 – 12 – 4 TXCHR 27 – 19 – 11 – 3 26 – 18 – 10 – 2 25 – 17 – 9 – 1 24 – 16 – 8 – 0 • TXCHR: Character to be Transmitted Next character to be transmitted after the current character if TXRDY is not set. When number of data bits is less than eight, the bits are right-aligned. 112 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 19.11.4 UART Baud Rate Generator Register Name: US_BRGR Access Type: Read/Write 31 – 23 – 15 30 – 22 – 14 29 – 21 – 13 28 – 20 – 12 CD 7 6 5 4 CD 3 2 1 0 27 – 19 – 11 26 – 18 – 10 25 – 17 – 9 24 – 16 – 8 • CD: Clock Divisor This register has no effect if synchronous mode is selected with an external clock. CD 0 1 2 to 65535 Effect Disables clock Clock divisor bypass Baud rate = Selected clock/(16 x CD) 113 6069C–ATARM–15-Sep-05 19.11.5 UART Receive Pointer Register Name: US_RPR Access Type: Read/Write 31 30 29 28 RXPTR 23 22 21 20 RXPTR 15 14 13 12 RXPTR 7 6 5 4 RXPTR 3 2 1 0 11 10 9 8 19 18 17 16 27 26 25 24 • RXPTR: Receive Pointer RXPTR must be loaded with the address of the receive buffer. 19.11.6 UART Receive Counter Register Name: US_RCR Access Type: Read/Write Reset Value: 0x0 31 – 23 – 15 30 – 22 – 14 29 – 21 – 13 28 – 20 – 12 RXCTR 7 6 5 4 RXCTR 3 2 1 0 27 – 19 – 11 26 – 18 – 10 25 – 17 – 9 24 – 16 – 8 • RXCTR: Receive Counter RXCTR must be loaded with the size of the receive buffer. 0 =Stop peripheral data transfer dedicated to the receiver. 1 - 65535: Start peripheral data transfer if RXRDY is active. 114 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 19.11.7 UART Transmit Pointer Register Name: US_TPR Access Type: Read/Write Reset Value: 0x0 31 30 29 28 TXPTR 23 22 21 20 TXPTR 15 14 13 12 TXPTR 7 6 5 4 TXPTR 3 2 1 0 11 10 9 8 19 18 17 16 27 26 25 24 • TXPTR: Transmit Pointer TXPTR must be loaded with the address of the transmit buffer. 19.11.8 UART Transmit Counter Register Name: US_TCR Access Type: Read/Write Reset Value: 0x0 31 – 23 – 15 30 – 22 – 14 29 – 21 – 13 28 – 20 – 12 TXCTR 7 6 5 4 TXCTR 3 2 1 0 27 – 19 – 11 26 – 18 – 10 25 – 17 – 9 24 – 16 – 8 • TXCTR: Transmit Counter TXCTR must be loaded with the size of the transmit buffer. 0 =Stop peripheral data transfer dedicated to the transmitter. 1 - 65535: Start peripheral data transfer if TXRDY is active. 115 6069C–ATARM–15-Sep-05 19.11.9 Modem Control Register Register Name: US_MC Access Type: Write-only Reset Value: Undefined 31 – 23 – 15 – 7 – 30 – 22 – 14 – 6 – 29 – 21 – 13 – 5 – 28 – 20 – 12 – 4 – 27 – 19 – 11 – 3 – 26 – 18 – 10 – 2 – 25 – 17 – 9 – 1 RTS 24 – 16 – 8 – 0 DTR This register controls the interface with the modem or data set (or a peripheral device emulating a modem). The contents of the Control Register are indicated below. • DTR: Data Terminal Ready This bit controls the NDTR output. When bit 0 is set to a logic 1, the NDTR output is forced to a logic 0. When bit 0 is reset to a logic 0, the NDTR output is forced to a logic 1. The NDTR output of the UART can be applied to an EIA inverting line driver to obtain proper polarity input at the succeeding modem or data set. • RTS: Request to Send This bit controls the NRTS output. Bit 1 affects the NRTS output in a manner identical to that described above for bit 0. 116 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 19.11.10 Modem Status Register Register Name: US_MS Access Type: Read-only 31 – 23 – 15 – 7 DCD 30 – 22 – 14 – 6 RI 29 – 21 – 13 – 5 DSR 28 – 20 – 12 – 4 CTS 27 – 19 – 11 – 3 DDCD 26 – 18 – 10 – 2 TERI 25 – 17 – 9 – 1 DDSR 24 – 16 – 8 – 0 DCTS This register provides the current state of the control lines from the modem (or peripheral device) to the CPU. In addition to this current-state information, four bits of the Modem Status Register provide change information. These bits are set to a logic 1 whenever a control input from the modem changes state. They are reset to logic 0 whenever the CPU reads the Modem Status Register. • DCTS: Delta Clear to Send Bit 0 indicates that the NCTS input to the chip has changed state since the last time it was read by the CPU. • DDSR: Delta Data Set Ready Bit 1 indicates that the NDSR input to the chip has changed state since the last time it was read by the CPU. • TERI: Trailing Edge Ring Indicator Bit 2 indicates that the NRI input to the chip has changed from a low to a high state. • DDCD: Delta Data Carrier Detect Bit 3 indicates that the NDCD input has changed state. Note that whenever bit 0, 1, 2, or 3 is set to logic 1, a modem status interrupt is generated. This is reflected in the modem status register. • CTS: Clear to Send This bit is the complement of the Clear to Send (NCTS) input. • DSR: Data Set Ready This bit is the complement of the Data Set Ready (NDSR) input. • RI: Ring Indicator This bit is the complement of the Ring Indicator (NRI) input. • DCD: Data Carrier Detect This bit is the complement of the Data Carrier Detect (NDCD) input. 117 6069C–ATARM–15-Sep-05 20. Timer/Counter (TC) The AT91C140 features a timer/counter block that includes three identical 16-bit timer/counter channels. Each channel can be independently programmed to perform a wide range of functions including frequency measurement, event counting, interval measurement, pulse generation, delay timing and pulse-width modulation. Each timer/counter channel has three external clock inputs, five internal clock inputs, and two multi-purpose input/output signals that can be configured by the user. Each channel drives an internal interrupt signal that can be programmed to generate processor interrupts via the AIC. The timer/counter block has two global registers which act upon all three TC channels. The Block Control Register allows the three channels to be started simultaneously with the same instruction. The Block Mode Register defines the external clock inputs for each timer/counter channel, allowing them to be chained. 20.1 Block Diagram Figure 20-1. Timer/Counter Block Diagram ACLK/2 ACLK/8 ACLK/32 ACLK/128 ACLK/1024 Parallel I/O Controller TCLK0 TIOA1 TIOA2 TCLK1 TCLK2 XC0 XC1 XC2 TC0XC0S SYNC TCLK0 TCLK1 TCLK2 TIOA0 TIOB0 Timer/Counter Channel 0 TIOA TIOA0 TIOB TIOB0 INT TCLK0 TCLK1 TIOA0 TIOA2 TCLK2 XC0 XC1 XC2 TC1XC1S SYNC Timer/Counter Channel 1 TIOA TIOA1 TIOB TIOB1 INT TIOA1 TIOB1 TCLK0 TCLK1 TCLK2 TIOA0 TIOA1 XC0 XC1 XC2 TC2XC2S Timer/Counter Channel 2 TIOA TIOA2 TIOB TIOB2 SYNC TIOA2 TIOB2 INT Timer/Counter Block Advanced Interrupt Controller 118 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 20.2 Signal Name Description Timer Counter Signal Description Description External clock inputs Capture mode: General-purpose input Waveform mode: General-purpose output Capture mode: General-purpose input Waveform mode: General-purpose input/output Interrupt signal output Synchronization input signal Type I I O I O O I Table 20-1. Channel Signal XC0, XC1, XC2 TIOA TIOB INT SYNC Block Signal TCLK0, TCLK1, TCLK2 TIOA0 TIOB0 TIOA1 TIOB1 TIOA2 TIOB2 Note: External clock inputs TIOA signal for Channel 0 TIOB signal for Channel 0 TIOA signal for Channel 1 TIOB signal for Channel 1 TIOA signal for Channel 2 TIOB signal for Channel 2 I I/O I/O I/O I/O I/O I/O After a hardware reset, the timer/counter block pins are controlled by the PIO controller. They must be configured to be controlled by the peripheral before being used. 20.3 Description The three timer/counter channels are independent and identical in operation. 20.3.1 Counter Each timer/counter channel is organized around a 16-bit counter. The value of the counter is incremented at each positive edge of the selected clock. When the counter has reached the value 0xFFFF and passes to 0x0000, an overflow occurs and the COVFS bit in TC_SR (Status Register) is set. The current value of the counter is accessible in real time by reading TC_CV. The counter can be reset by a trigger. In this case, the counter value passes to 0x0000 on the next valid edge of the selected clock. 20.3.2 Clock Selection At block level, input clock signals of each channel can either be connected to the external inputs TCLK0, TCLK1 or TCLK2, or be connected to the configurable I/O signals TIOA0, TIOA1 or TIOA2 for chaining by programming the TC_BMR (Block Mode). Each channel can independently select an internal or external clock source for its counter: • Internal clock signals: ACLK/2, ACLK/8, ACLK/32, ACLK/128, ACLK/1024 • External clock signals: XC0, XC1 or XC2 119 6069C–ATARM–15-Sep-05 The selected clock can be inverted with the CLKI bit in TC_CMR (Channel Mode). This allows counting on the opposite edges of the clock. The burst function allows the clock to be validated when an external signal is high. The BURST parameter in the Mode Register defines this signal (none, XC0, XC1, XC2). Note: In all cases, if an external clock is used, the duration of each of its levels must be longer than the system clock (ACLK) period. The external clock frequency must be at least 2.5 times lower than the system clock (ACLK). Figure 20-2. Clock Selection CLKS CLKI ACLK/2 ACLK/8 ACLK/32 ACLK/128 ACLK/1024 XC0 XC1 XC2 Selected Clock BURST 1 20.3.3 Clock Control The clock of each counter can be controlled in two different ways: it can be enabled/disabled and started/stopped. 1. The clock can be enabled or disabled by the user with the CLKEN and the CLKDIS commands in the Control Register. In capture mode, it can be disabled by an RB load event if LDBDIS is set to 1 in TC_CMR. In waveform mode, it can be disabled by an RC Compare event if CPCDIS is set to 1 in TC_CMR. When disabled, the start or the stop actions have no effect: only a CLKEN command in the Control Register can reenable the clock. When the clock is enabled, the CLKSTA bit is set in the Status Register. 2. The clock can also be started or stopped: a trigger (software, synchro, external or compare) always starts the clock. The clock can be stopped by an RB load event in capture mode (LDBSTOP = 1 in TC_CMR) or a RC compare event in waveform mode (CPCSTOP = 1 in TC_CMR). The start and the stop commands have an effect only if the clock is enabled. 20.3.4 Timer/Counter Operating Modes Each timer/counter channel can operate independently in two different modes: 1. Capture mode allows measurement on signals 2. Waveform mode allows wave generation 120 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 The timer/counter operating mode is programmed with the WAVE bit in the TC Mode Register. In capture mode, TIOA and TIOB are configured as inputs. In waveform mode, TIOA is always configured to be an output and TIOB is an output if it is not selected to be the external trigger. Figure 20-3. Clock Control Selected Clock Trigger CLKSTA CLKEN CLKDIS Q Q S R S R Counter Clock Stop Event Disable Event 20.3.5 Trigger A trigger resets the counter and starts the counter clock. Three types of triggers are common to both modes, and a fourth external trigger is available to each mode. The following triggers are common to both modes: 1. Software trigger: Each channel has a software trigger, available by setting SWTRG in TC_CCR. 2. SYNC: Each channel has a synchronization signal, SYNC. When asserted, this signal has the same effect as a software trigger. The SYNC signals of all channels are asserted simultaneously by writing TC_BCR (Block Control) with SYNC set. 3. Compare RC trigger: RC is implemented in each channel and can provide a trigger when the counter value matches the RC value if CPCTRG is set in TC_CMR. The timer/counter channel can also be configured to have an external trigger. In capture mode, the external trigger signal can be selected between TIOA and TIOB. In waveform mode, an external event can be programmed on one of the following signals: TIOB, XC0, XC1 or XC2. This external event can then be programmed to perform a trigger by setting ENETRG in TC_CMR. If an external trigger is used, the duration of the pulses must be longer than the system clock (ACLK) period in order to be detected. Whatever the trigger used, it will be taken into account at the following active edge of the selected clock. This means that the counter value may not read zero just after a trigger, especially when a low-frequency signal is selected as the clock. 121 6069C–ATARM–15-Sep-05 20.4 Capture Operating Mode This mode is entered by clearing the WAVE parameter in TC_CMR (Channel Mode Register). Capture mode allows the TC Channel to perform measurements such as pulse timing, frequency, period, duty cycle and phase on TIOA and TIOB signals which are inputs. Figure 20-4 shows the configuration of the TC Channel when programmed in capture mode. 20.4.1 Capture Registers A and B (RA and RB) Registers A and B are used as capture registers; thus, they can be loaded with the counter value when a programmable event occurs on the TIOA signal. The parameter LDRA in TC_CMR defines the TIOA edge for the loading of Register A, and the parameter LDRB defines the TIOA edge for the loading of Register B. RA is loaded only if it has not been loaded since the last trigger or if RB has been loaded since the last loading of RA. RB is loaded only if RA has been loaded since the last trigger or the last loading of RB. Loading RA or RB before the read of the last value loaded sets the Overrun Error Flag (LOVRS) in TC_SR (Status Register). In this case, the old value is overwritten. 20.4.2 Trigger Conditions In addition to the SYNC signal, the software trigger and the RC compare trigger, an external trigger can be defined. Bit ABETRG in TC_CMR selects input signal TIOA or TIOB as an external trigger. Parameter ETRGEDG defines the edge (rising, falling or both) detected to generate an external trigger. If ETRGEDG = 0 (none), the external trigger is disabled. 20.4.3 Status Register The following bits in the status register are significant in capture operating mode. • CPCS: RC Compare Status There has been an RC Compare match at least once since the last read of the status. • COVFS: Counter Overflow Status The counter has attempted to count past $FFFF since the last read of the status. • LOVRS: Load Overrun Status RA or RB has been loaded at least twice without any read of the corresponding register since the last read of the status. • LDRAS: Load RA Status RA has been loaded at least once without any read since the last read of the status. • LDRBS: Load RB Status RB has been loaded at least once without any read since the last read of the status. • ETRGS: External Trigger Status An external trigger on TIOA or TIOB has been detected since the last read of the status. 122 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 Figure 20-4. Capture Mode TCCLKS CLKI ACLK/2 ACLK/8 ACLK/32 ACLK/128 ACLK/1024 XC0 XC1 XC2 LDBSTOP BURST Register C Capture Register A 16-bit Counter CLK OVF RESET CLKSTA CLKEN CLKDIS Q Q S R S R LDBDIS 1 Capture Register B Compare RC = SWTRG SYNC ABETRG ETRGEDG MTIOB Edge Detector LDRA Edge Detector Trig CPCTRG TIOB LDRB Edge Detector If RA is loaded ETRGS COVFS LOVRS LDRAS LDRBS TC_SR CPCS MTIOA If RA is not loaded or RB is loaded TIOA TC_IMR Timer/Counter Channel INT 20.5 Waveform Operating Mode This mode is entered by setting the WAVE parameter in TC_CMR (Channel Mode Register). Waveform operating mode allows the TC channel to generate 1 or 2 PWM signals with the same frequency and independently programmable duty cycles, or to generate different types of one-shot or repetitive pulses. In this mode, TIOA is configured as output and TIOB is defined as output if it is not used as an external event (EEVT parameter in TC_CMR). Figure 20-5 on page 126 shows the configuration of the TC channel when programmed in waveform operating mode. 20.5.1 Compare Register A, B and C (RA, RB, and RC) In waveform operating mode, RA, RB and RC are all used as compare registers. RA Compare is used to control the TIOA output. RB Compare is used to control the TIOB (if configured as output). RC Compare can be programmed to control TIOA and/or TIOB outputs. 123 6069C–ATARM–15-Sep-05 RC Compare can also stop the counter clock (CPCSTOP = 1 in TC_CMR) and/or disable the counter clock (CPCDIS = 1 in TC_CMR). As in capture mode, RC Compare can also generate a trigger if CPCTRG = 1. A trigger resets the counter so RC can control the period of PWM waveforms. 20.5.2 External Event/Trigger Conditions An external event can be programmed to be detected on one of the clock sources (XC0, XC1, XC2) or TIOB. The external event selected can then be used as a trigger. The parameter EEVT in TC_CMR selects the external trigger. The parameter EEVTEDG defines the trigger edge for each of the possible external triggers (rising, falling or both). If EEVTEDG is cleared (none), no external event is defined. If TIOB is defined as an external event signal (EEVT = 0), TIOB is no longer used as output and the TC channel can only generate a waveform on TIOA. When an external event is defined, it can be used as a trigger by setting bit ENETRG in TC_CMR. As in capture mode, the SYNC signal, the software trigger and the RC compare trigger are also available as triggers. 20.5.3 Output Controller The output controller defines the output level changes on TIOA and TIOB following an event. TIOB control is used only if TIOB is defined as output (not as an external event). The following events control TIOA and TIOB: software trigger, external event and RC compare. RA compare controls TIOA and RB compare controls TIOB. Each of these events can be programmed to set, clear or toggle the output as defined in the corresponding parameter in TC_CMR. Table 20-2 and Table 20-3 show which parameter in TC_CMR is used to define the effect of each event. Table 20-2. Parameter ASWTRG AEEVT ACPC ACPA TIOA Events TIOA Event Software trigger External event RC compare RA compare Table 20-3. Parameter BSWTRG BEEVT BCPC BCPB TIOB Events TIOB Event Software trigger External event RC compare RB compare 124 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 If two or more events occur at the same time, the priority level is defined as follows: 1. Software trigger 2. External event 3. RC compare 4. RA or RB compare 20.5.4 Status The following bits in the status register are significant in waveform mode: • CPAS: RA Compare Status There has been a RA Compare match at least once since the last read of the status • CPBS: RB Compare Status There has been a RB Compare match at least once since the last read of the status • CPCS: RC Compare Status There has been a RC Compare match at least once since the last read of the status • COVFS: Counter Overflow Counter has attempted to count past $FFFF since the last read of the status • ETRGS: External Trigger External trigger has been detected since the last read of the status 125 6069C–ATARM–15-Sep-05 Figure 20-5. Waveform Mode BURST Register A Register B Register C ASWTRG Compare RA = Compare RC = 16-bit Counter CLK RESET OVF 1 Compare RB = SWTRG BCPC Trig BCPB CPCTRG MTIOB SYNC EEVT BEEVT EEVTEDG ENETRG ETRGS COVFS TC_SR Edge Detector TC_IMR CPCS CPAS CPBS Output Controller BSWTRG TIOB Timer/Counter Channel 6069C–ATARM–15-Sep-05 INT Output Controller 126 CLKSTA ACPC CLKI CLKEN CLKDIS TCCLKS ACLK/2 ACLK/8 AT91C140 Q CPCDIS ACLK/32 S R ACPA MTIOA ACLK/128 ACLK/1024 Q R CPCSTOP AEEVT S XC0 XC1 TIOA XC2 TIOB AT91C140 20.6 Timer/Counter (TC) User Interface TC Global Memory Map Register Name Channel/Register TC Channel 0 TC Channel 1 TC Channel 2 TC_BCR TC_BMR TC Block Control Register TC Block Mode Register Access Reset Value Table 20-4. Offset 0x00 0x40 0x80 0xC0 0xC4 See Table 20-5 See Table 20-5 See Table 20-5 Write-only Read/Write – 0 TC_BCR (Block Control Register) and TC_BMR (Block Mode Register) control the whole TC block. TC channels are controlled by the registers listed in Table 20-5. The offset of each of the channel registers in Table 20-5 is in relation to the offset of the corresponding channel as specified in Table 20-4. Table 20-5. Offset 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C 0x20 0x24 0x28 Note: TC_CVR TC_RA TC_RB TC_RC TC_SR TC_IER TC_IDR TC Channel Memory Map Register Name TC_CCR TC_CMR Description Channel Control Register Channel Mode Register Reserved Reserved Counter Value Register Register A Register B Register C Status Register Interrupt Enable Register Interrupt Disable Register Interrupt Mask Register Read/Write Read/Write(1) Read/Write (1) Access Write-only Read/Write Reset Value – 0 – – 0 0 0 0 – – – 0 Read/Write Read-only Write-only Write-only Read-only 0x2C TC_IMR 1. Read only if WAVE = 0. 127 6069C–ATARM–15-Sep-05 20.6.1 TC Block Control Register Register Name: TC_BCR Access Type: Write-only 31 – 23 – 15 – 7 – 30 – 22 – 14 – 6 – 29 – 21 – 13 – 5 – 28 – 20 – 12 – 4 – 27 – 19 – 11 – 3 – 26 – 18 – 10 – 2 – 25 – 17 – 9 – 1 – 24 – 16 – 8 – 0 SYNC • SYNC: Synchro Command 0 = No effect. 1 = Asserts the SYNC signal which generates a software trigger simultaneously for each of the channels. 128 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 20.6.2 TC Block Mode Register Register Name: TC_BMR Access Type: Read/Write 31 – 23 – 15 – 7 – 30 – 22 – 14 – 6 – 29 – 21 – 13 – 5 TC2XC2S 28 – 20 – 12 – 4 27 – 19 – 11 – 3 TC1XC1S 26 – 18 – 10 – 2 25 – 17 – 9 – 1 TC0XC0S 24 – 16 – 8 – 0 • TC0XC0S: External Clock Signal 0 Selection TC0XC0S 0 0 1 1 0 1 0 1 Signal Connected to XC0 TCLK0 None TIOA1 TIOA2 • TC1XC1S: External Clock Signal 1 Selection TC1XC1S 0 0 1 1 0 1 0 1 Signal Connected to XC1 TCLK1 none TIOA0 TIOA2 • TC2XC2S: External Clock Signal 2 Selection TC2XC2S 0 0 1 1 0 1 0 1 Signal Connected to XC2 TCLK2 none TIOA0 TIOA1 129 6069C–ATARM–15-Sep-05 20.6.3 TC Channel Control Register Register Name: TC_CCR Access Type: Write-only 31 – 23 – 15 – 7 – 30 – 22 – 14 – 6 – 29 – 21 – 13 – 5 – 28 – 20 – 12 – 4 – 27 – 19 – 11 – 3 – 26 – 18 – 10 – 2 SWTRG 25 – 17 – 9 – 1 CLKDIS 24 – 16 – 8 – 0 CLKEN • CLKEN: Counter Clock Enable Command 0 = No effect. 1 = Enables the clock if CLKDIS is not 1. • CLKDIS: Counter Clock Disable Command 0 = No effect. 1 = Disables the clock. • SWTRG: Software Trigger Command 0 = No effect. 1 = A software trigger is performed: the counter is reset and clock is started. 130 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 20.6.4 TC Channel Mode Register: Capture Mode Register Name: TC_CMR Access Type: Read/Write 31 – 23 – 15 WAVE 7 LDBDIS 30 – 22 – 14 CPCTRG 6 LDBSTOP 29 – 21 – 13 – 5 BURST 28 – 20 – 12 – 4 11 – 3 CLKI 27 – 19 LDRB 10 ABETRG 2 1 TCCLKS 9 ETRGEDG 0 26 – 18 25 – 17 LDRA 8 24 – 16 • TCCLKS: Clock Selection TCCLKS 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 Clock Selected ACLK/2 ACLK/8 ACLK/32 ACLK/128 ACLK/1024 XC0 XC1 XC2 • CLKI: Clock Invert 0 = Counter is incremented on rising edge of the clock. 1 = Counter is incremented on falling edge of the clock. • BURST: Burst Signal Selection BURST 0 0 1 1 0 1 0 1 The clock is not gated by an external signal. XC0 is ANDed with the selected clock. XC1 is ANDed with the selected clock. XC2 is ANDed with the selected clock. • LDBSTOP: Counter Clock Stopped with RB Loading 0 = Counter clock is not stopped when RB loading occurs. 1 = Counter clock is stopped when RB loading occurs. • LDBDIS: Counter Clock Disable with RB Loading 0 = Counter clock is not disabled when RB loading occurs. 1 = Counter clock is disabled when RB loading occurs. 131 6069C–ATARM–15-Sep-05 • ETRGEDG: External Trigger Edge Selection ETRGEDG 0 0 1 1 0 1 0 1 Edge None Rising edge Falling edge Each edge • ABETRG: TIOA or TIOB External Trigger Selection 0 = TIOB is used as an external trigger. 1 = TIOA is used as an external trigger. • CPCTRG: RC Compare Trigger Enable 0 = RC Compare has no effect on the counter and its clock. 1 = RC Compare resets the counter and starts the counter clock. • WAVE 0 = Capture mode is enabled. 1 = Capture mode is disabled (waveform mode is enabled). • LDRA: RA Loading Selection LDRA 0 0 1 1 0 1 0 1 Edge None Rising edge of TIOA Falling edge of TIOA Each edge of TIOA • LDRB: RB Loading Selection LDRB 0 0 1 1 0 1 0 1 Edge None Rising edge of TIOA Falling edge of TIOA Each edge of TIOA 132 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 20.6.5 TC Channel Mode Register: Waveform Mode Register Name: TC_CMR Access Type: Read/Write 31 BSWTRG 23 ASWTRG 15 WAVE 7 CPCDIS 14 CPCTRG 6 CPCSTOP 13 – 5 BURST 22 21 AEEVT 12 ENETRG 4 3 CLKI 11 EEVT 2 1 TCCLKS 30 29 BEEVT 20 19 ACPC 10 9 EEVTEDG 0 28 27 BCPC 18 17 ACPA 8 26 25 BCPB 16 24 • TCCLKS: Clock Selection TCCLKS 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 Clock Selected ACLK/2 ACLK/8 ACLK/32 ACLK/128 ACLK/1024 XC0 XC1 XC2 • CLKI: Clock Invert 0 = Counter is incremented on rising edge of the clock. 1 = Counter is incremented on falling edge of the clock. • BURST: Burst Signal Selection BURST 0 0 1 1 0 1 0 1 The clock is not gated by an external signal. XC0 is ANDed with the selected clock. XC1 is ANDed with the selected clock. XC2 is ANDed with the selected clock. • CPCSTOP: Counter Clock Stopped with RC Compare 0 = Counter clock is not stopped when counter reaches RC. 1 = Counter clock is stopped when counter reaches RC. • CPCDIS: Counter Clock Disable with RC Compare 0 = Counter clock is not disabled when counter reaches RC. 1 = Counter clock is disabled when counter reaches RC. 133 6069C–ATARM–15-Sep-05 • EEVTEDG: External Event Edge Selection EEVTEDG 0 0 1 1 0 1 0 1 Edge None Rising edge Falling edge Each edge • EEVT: External Event Selection Signal Selected as External Event 0 1 0 1 TIOB XC0 XC1 XC2 TIOB Direction Input(1) Output Output Output EEVT 0 0 1 1 Note: If TIOB is chosen as the external event signal, it is configured as an input and no longer generates waveforms. • ENETRG: External Event Trigger Enable 0 = The external event has no effect on the counter and its clock. In this case, the selected external event only controls the TIOA output. 1 = The external event resets the counter and starts the counter clock. • CPCTRG: RC Compare Trigger Enable 0 = RC Compare has no effect on the counter and its clock. 1 = RC Compare resets the counter and starts the counter clock. • WAVE 0 = Waveform mode is disabled (Capture mode is enabled). 1 = Waveform mode is enabled. • ACPA: RA Compare Effect on TIOA ACPA 0 0 1 1 0 1 0 1 Effect None Set Clear Toggle • ACPC: RC Compare Effect on TIOA ACPC 0 0 1 1 0 1 0 1 Effect None Set Clear Toggle 134 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 • AEEVT: External Event Effect on TIOA AEEVT 0 0 1 1 0 1 0 1 Effect None Set Clear Toggle • ASWTRG: Software Trigger Effect on TIOA ASWTRG 0 0 1 1 0 1 0 1 Effect None Set Clear Toggle • BCPB: RB Compare Effect on TIOB BCPB 0 0 1 1 0 1 0 1 Effect None Set Clear Toggle • BCPC: RC Compare Effect on TIOB BCPC 0 0 1 1 0 1 0 1 Effect None Set Clear Toggle • BEEVT: External Event Effect on TIOB BEEVT 0 0 1 1 0 1 0 1 Effect None Set Clear Toggle 135 6069C–ATARM–15-Sep-05 • BSWTRG: Software Trigger Effect on TIOB BSWTRG 0 0 1 1 0 1 0 1 Effect None Set Clear Toggle 136 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 20.6.6 TC Counter Value Register Register Name: TC_CVR Access Type: Read-only 31 – 23 – 15 30 – 22 – 14 29 – 21 – 13 28 – 20 – 12 CV 7 6 5 4 CV 3 2 1 0 27 – 19 – 11 26 – 18 – 10 25 – 17 – 9 24 – 16 – 8 • CV: Counter Value CV contains the counter value in real-time. 20.6.7 TC Register A Register Name: TC_RA Access Type: Read-only if WAVE = 0, Read/Write if WAVE = 1 31 – 23 – 15 30 – 22 – 14 29 – 21 – 13 28 – 20 – 12 RA 7 6 5 4 RA 3 2 1 0 27 – 19 – 11 26 – 18 – 10 25 – 17 – 9 24 – 16 – 8 • RA: Register A RA contains the Register A value in real-time. 20.6.8 TC Register B Register Name: TC_RB Access Type: Read-only if WAVE = 0, Read/Write if WAVE = 1 31 – 23 – 15 30 – 22 – 14 29 – 21 – 13 28 – 20 – 12 RB 7 6 5 4 RB 3 2 1 0 27 – 19 – 11 26 – 18 – 10 25 – 17 – 9 24 – 16 – 8 • RB: Register B RB contains the Register B value in real-time. 137 6069C–ATARM–15-Sep-05 20.6.9 TC Register C Register Name: TC_RC Access Type: Read/Write 31 – 23 – 15 30 – 22 – 14 29 – 21 – 13 28 – 20 – 12 RC 7 6 5 4 RC 3 2 1 0 27 – 19 – 11 26 – 18 – 10 25 – 17 – 9 24 – 16 – 8 • RC: Register C RC contains the Register C value in real-time. 20.6.10 TC Status Register Register Name: TC_SR Access Type: Read-only 31 – 23 – 15 – 7 ETRGS 30 – 22 – 14 – 6 LDRBS 29 – 21 – 13 – 5 LDRAS 28 – 20 – 12 – 4 CPCS 27 – 19 – 11 – 3 CPBS 26 – 18 MTIOB 10 – 2 CPAS 25 – 17 MTIOA 9 – 1 LOVRS 24 – 16 CLKSTA 8 – 0 COVFS • COVFS: Counter Overflow Status 0 = No counter overflow has occurred since the last read of the Status Register. 1 = A counter overflow has occurred since the last read of the Status Register. • LOVRS: Load Overrun Status 0 = Load overrun has not occurred since the last read of the Status Register or WAVE = 1. 1 = RA or RB have been loaded at least twice without any read of the corresponding register since the last read of the Status Register if WAVE = 0. • CPAS: RA Compare Status 0 = RA compare has not occurred since the last read of the Status Register or WAVE = 0. 1 = RA compare has occurred since the last read of the Status Register if WAVE = 1. • CPBS: RB Compare Status 0 = RB compare has not occurred since the last read of the Status Register or WAVE = 0. 1 = RB compare has occurred since the last read of the Status Register if WAVE = 1. • CPCS: RC Compare Status 0 = RC compare has not occurred since the last read of the Status Register. 1 = RC compare has occurred since the last read of the Status Register. • LDRAS: RA Loading Status 0 = RA Load has not occurred since the last read of the Status Register or WAVE = 1. 1 = RA Load has occurred since the last read of the Status Register, if WAVE = 0. 138 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 • LDRBS: RB Loading Status 0 = RB load has not occurred since the last read of the Status Register or WAVE = 1. 1 = RB load has occurred since the last read of the Status Register if WAVE = 0. • ETRGS: External Trigger Status 0 = External trigger has not occurred since the last read of the Status Register. 1 = External trigger has occurred since the last read of the Status Register. • CLKSTA: Clock Enabling Status 0 = Clock is disabled. 1 = Clock is enabled. • MTIOA: TIOA Mirror 0 = TIOA is low. If WAVE = 0, then TIOA pin is low. If WAVE = 1, then TIOA is driven low. 1 = TIOA is high. If WAVE = 0, then TIOA pin is high. If WAVE = 1, then TIOA is driven high. • MTIOB: TIOB Mirror 0 = TIOB is low. If WAVE = 0, then TIOB pin is low. If WAVE = 1, then TIOB is driven low. 1 = TIOB is high. If WAVE = 0, then TIOB pin is high. If WAVE = 1, then TIOB is driven high. 139 6069C–ATARM–15-Sep-05 20.6.11 TC Interrupt Enable Register Register Name: TC_IER Access Type: Write-only 31 – 23 – 15 – 7 ETRGS 30 – 22 – 14 – 6 LDRBS 29 – 21 – 13 – 5 LDRAS 28 – 20 – 12 – 4 CPCS 27 – 19 – 11 – 3 CPBS 26 – 18 – 10 – 2 CPAS 25 – 17 – 9 – 1 LOVRS 24 – 16 – 8 – 0 COVFS • COVFS: Counter Overflow • LOVRS: Load Overrun • CPAS: RA Compare • CPBS: RB Compare • CPCS: RC Compare • LDRAS: RA Loading • LDRBS: RB Loading • ETRGS: External Trigger 0 = No effect. 1 = Enables the corresponding interrupt. 20.6.12 TC Interrupt Disable Register Register Name: TC_IDR Access Type: Write-only 31 – 23 – 15 – 7 ETRGS 30 – 22 – 14 – 6 LDRBS 29 – 21 – 13 – 5 LDRAS 28 – 20 – 12 – 4 CPCS 27 – 19 – 11 – 3 CPBS 26 – 18 – 10 – 2 CPAS 25 – 17 – 9 – 1 LOVRS 24 – 16 – 8 – 0 COVFS • COVFS: Counter Overflow • LOVRS: Load Overrun • CPAS: RA Compare • CPBS: RB Compare • CPCS: RC Compare • LDRAS: RA Loading • LDRBS: RB Loading • ETRGS: External Trigger 0 = No effect. 1 = Disables the corresponding interrupt. 140 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 20.6.13 TC Interrupt Mask Register Register Name: TC_IMR Access Type: Read-only 31 – 23 – 15 – 7 ETRGS 30 – 22 – 14 – 6 LDRBS 29 – 21 – 13 – 5 LDRAS 28 – 20 – 12 – 4 CPCS 27 – 19 – 11 – 3 CPBS 26 – 18 – 10 – 2 CPAS 25 – 17 – 9 – 1 LOVRS 24 – 16 – 8 – 0 COVFS • COVFS: Counter Overflow • LOVRS: Load Overrun • CPAS: RA Compare • CPBS: RB Compare • CPCS: RC Compare • LDRAS: RA Loading • LDRBS: RB Loading • ETRGS: External Trigger 0 = The corresponding interrupt is disabled. 1 = The corresponding interrupt is enabled. 141 6069C–ATARM–15-Sep-05 21. Serial Peripheral Interface (SPI) The AT91C140 embeds a Serial Peripheral Interface featuring: • Four Chip Selects with External Decoder Support Allowing Communication with Up to 15 Peripherals • Serial Memories, such as DataFlash and 3-wire EEPROMS • Serial Peripherals, such as ADCS, DACS, LCD Controllers, CAN Controllers And Sensors • External Co-processors • Master or Slave Serial Peripheral Bus Interface • 8- to 16-bit Programmable Data Length Per Chip Select • Programmable Phase and Polarity Per Chip Select • Programmable Transfer Delays Between Consecutive Transfers and Between Clock and Data Per Chip Select • Programmable Delay Between Consecutive Transfers • Selectable Mode Fault Detection • Connection to PDC Channel Capabilities Optimizes Data Transfers • One Channel for the Receiver, One Channel for the Transmitter 21.1 Overview The Serial Peripheral Interface (SPI) circuit is a synchronous serial data link that provides communication with external devices in Master or Slave Mode. It also allows communication between processors if an external processor is connected to the system. The Serial Peripheral Interface is a shift register that serially transmits data bits to other SPIs. During a data transfer, one SPI system acts as the “master”' that controls the data flow, while the other system acts as the “slave'' that has data shifted into and out of it by the master. Different CPUs can take turn being masters (Multiple Master Protocol versus Single Master Protocol, where one CPU is always the master while all of the others are always slaves), and one master may simultaneously shift data into multiple slaves. However, only one slave may drive its output to write data back to the master at any given time. A slave device is selected when the master asserts its NSS signal. If multiple slave devices exist, the master generates a separate slave select signal for each slave (NPCS). The SPI system consists of two data lines and two control lines: Master Out Slave In (MOSI): This data line supplies the output data from the master shifted into the input(s) of the slave(s). Master In Slave Out (MISO): This data line supplies the output data from a slave to the input of the master. There may be no more than one slave transmitting data during any particular transfer. Serial Clock (SPCK): This control line is driven by the master and regulates the flow of the data bits. The master may transmit data at a variety of baud rates; the SPCK line cycles once for each bit that is transmitted. Slave Select (NSS): This control line allows slaves to be turned on and off by hardware. 142 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 21.2 Block Diagram Figure 21-1. Block Diagram ASB APB Bridge PDC APB SPCK MISO MOSI SPI Interface PIO NPCS0/NSS NPCS1 NPCS2 Interrupt Control NPCS3 ACK ACK/32 SPI Interrupt 143 6069C–ATARM–15-Sep-05 21.3 Connections Figure 21-2. Application Block Diagram: Single Master/Multiple Slave Implementation SPCK MISO MOSI SPI Master NPCS0 NPCS1 NPCS2 NPCS3 NC SPCK MISO Slave 0 MOSI NSS SPCK MISO Slave 1 MOSI NSS SPCK MISO Slave 2 MOSI NSS 21.4 Pin Name List I/O Lines Description Pin Description Master In Slave Out Master Out Slave In Serial Clock Peripheral Chip Selects Peripheral Chip Select/Slave Select Type I/O I/O I/O Input I/O Mode Master Slave Master Slave Master Slave Master Master Master Slave Comments Serial data input to SPI Serial data output from SPI Serial data output from SPI Serial data input to SPI Clock output from SPI Clock input to SPI Select peripherals Output: Selects peripheral Input: low causes mode fault Input: chip select for SPI Table 21-1. Pin Name MISO MOSI SPCK NPCS1-NPCS3 NPCS0/NSS 21.5 Master Mode Operations When configured in Master Mode, the Serial Peripheral Interface controls data transfers to and from the slave(s) connected to the SPI bus. The SPI drives the chip select(s) to the slave(s) and the serial clock (SPCK). After enabling the SPI, a data transfer begins when the core writes to the SPI_TDR (Transmit Data Register). Transmit and Receive buffers maintain the data flow at a constant rate with a reduced requirement for high-priority interrupt servicing. When new data is available in the SPI_TDR, the SPI 144 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 continues to transfer data. If the SPI_RDR (Receive Data Register) has not been read before new data is received, the Overrun Error (OVRES) flag is set. Note: As long as this flag is set, no data is loaded in the SPI_RDR. The user has to read the status register to clear it. The delay between the activation of the chip select and the start of the data transfer (DLYBS), as well as the delay between each data transfer (DLYBCT), can be programmed for each of the four external chip selects. All data transfer characteristics, including the two timing values, are programmed in registers SPI_CSR0 to SPI_CSR3 (Chip Select Registers). In Master Mode, the peripheral selection can be defined in two different ways: • Fixed Peripheral Select: SPI exchanges data with only one peripheral • Variable Peripheral Select: Data can be exchanged with more than one peripheral Figure 21-6 and Figure 21-7 show the operation of the SPI in Master Mode. For details concerning the flag and control bits in these diagrams, see ”SPI Chip Select Register” on page 161. 21.5.1 Fixed Peripheral Select This mode is used for transferring memory blocks without the extra overhead in the transmit data register to determine the peripheral. Fixed Peripheral Select is activated by setting bit PS to zero in SPI_MR (Mode Register). The peripheral is defined by the PCS field in SPI_MR. This option is only available when the SPI is programmed in Master Mode. 21.5.2 Variable Peripheral Select Variable Peripheral Select is activated by setting the PS bit to one. The PCS field in SPI_TDR is used to select the destination peripheral. The data transfer characteristics are changed when the selected peripheral changes, depending on the associated chip select register. The PCS field in the SPI_MR has no effect. This option is available only when the SPI is programmed in Master Mode. 21.5.3 Chip Selects The Chip Select lines are driven by the SPI only if it is programmed in Master Mode. These lines are used to select the destination peripheral. The PCSDEC field in SPI_MR (Mode Register) selects one to four peripherals (PCSDEC = 0) or up to 15 peripherals (PCSDEC = 1). If Variable Peripheral Select is active, the chip select signals are defined for each transfer in the PCS field in SPI_TDR. Chip select signals can thus be defined independently for each transfer. If Fixed Peripheral Select is active, Chip Select signals are defined for all transfers by the field PCS in SPI_MR. If a transfer with a new peripheral is necessary, the software must wait until the current transfer is completed, then change the value of PCS in SPI_MR before writing new data in SPI_TDR. The value on the NPCS pins at the end of each transfer can be read in the SPI_RDR (Receive Data Register). By default, all NPCS signals are high (equal to one) before and after each transfer. 145 6069C–ATARM–15-Sep-05 21.5.4 Mode Fault Detection A mode fault is detected when the SPI is programmed in Master Mode and a low level is driven by an external master on the NPCS[0]/NSS signal. When a mode fault is detected, the MODF bit in the SPI_SR is set until the SPI_SR is read and the SPI is disabled until re-enabled by bit SPIEN in the SPI_CR (Control Register). By default, Mode Fault Detection is enabled. It is disabled by setting the MODFDIS bit in the SPI Mode Register. 146 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 21.5.5 Master Mode Flow Diagram Figure 21-3. Master Mode Flow Diagram SPI Enable 1 TDRE 0 0 PS 1 Variable peripheral NPCS = SPI_MR(PCS) Fixed peripheral NPCS = SPI_TDR(PCS) Delay DLYBS Serializer = SPI_TDR(TD) TDRE = 1 Data Transfer SPI_RDR(RD) = Serializer RDRF = 1 Delay DLYBCT TDRE 0 1 NPCS = 0xF PS 1 0 Fixed peripheral Variable peripheral Same peripheral Delay DLYBCS SPI_TDR(PCS) New peripheral NPCS = 0xF Delay DLYBCS NPCS = SPI_TDR(PCS) 147 6069C–ATARM–15-Sep-05 21.5.6 Master Mode Block Diagram Figure 21-4. Master Mode Block Diagram SPI_MR(DIV32) ACK 0 1 SPI Master Clock SPCK Clock Generator SPI_CSRx[15:0] SPCK ACK/32 SPIDIS SPIEN S Q R SPI_RDR PCS LSB MISO RD MSB MOSI Serializer SPI_TDR PCS TD NPCS3 NPCS2 SPI_MR(PS) NPCS1 NPCS0 1 SPI_MR(PCS) 0 SPI_MR(MSTR) SPI_SR M O D F T D R E R D R F O V R E S P I E N S SPI_IER SPI_IDR SPI_IMR SPI Interrupt 148 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 21.6 SPI Slave Mode In Slave Mode, the SPI waits for NSS to go active low before receiving the serial clock from an external master. In Slave Mode, CPOL, NCPHA and BITS fields of SPI_CSR0 are used to define the transfer characteristics. The other Chip Select Registers are not used in Slave Mode. Figure 21-5. Slave Mode Block Diagram SPCK NSS SPIDIS SPIEN S Q R SPI_RDR RD LSB MOSI MSB MISO Serializer SPI_TDR TD SPI_SR S P I E N S T D R E R D R F O V R E SPI_IER SPI_IDR SPI_IMR SPI Interrupt 21.7 Data Transfers Four modes are used for data transfers. These modes correspond to combinations of a pair of parameters called clock polarity (CPOL) and clock phase (CPHA) that determine the edges of 149 6069C–ATARM–15-Sep-05 the clock signal on which the data are driven and sampled. Each of the two parameters has two possible states, resulting in four possible combinations that are incompatible with one another. Thus a master/slave pair must use the same parameter pair values to communicate. If multiple slaves are used and fixed in different configurations, the master must reconfigure itself each time it needs to communicate with a different slave. Table 21-2 shows the four modes and corresponding parameter settings. Table 21-2. SPI Bus Protocol Mode SPI Mode 0 1 2 3 CPOL 0 0 1 1 CPHA 0 1 0 1 Figure 21-6 and Figure 21-7 show examples of data transfers. Figure 21-6. SPI Transfer Format (NCPHA = 1, 8 bits per transfer SPCK cycle (for reference) SPCK (CPOL=0) 1 2 3 4 5 6 7 8 SPCK (CPOL=1) MOSI (from master) MSB 6 5 4 3 2 1 LSB MISO (from slave) MSB 6 5 4 3 2 1 LSB * NSS (to slave) * Not defined, but normally MSB of previous character received. 150 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 Figure 21-7. SPI Transfer Format (NCPHA = 0, 8 bits per transfer) SPCK cycle (for reference) SPCK (CPOL=0) 1 2 3 4 5 6 7 8 SPCK (CPOL=1) MOSI (from master) MSB 6 5 4 3 2 1 LSB MISO (from slave) * MSB 6 5 4 3 2 1 LSB NSS (to slave) * Not defined but normally LSB of previous character transmitted. 21.8 Clock Generation In Master Mode, the SPI Master Clock is either CLOCK or FDIV, as defined by the DIV32 field of SPI_MR. The SPI baud rate clock is generated by dividing the SPI Master Clock by a value between 4 and 510. The divisor is defined in the SCBR field in each Chip Select Register. The transfer speed can thus be defined independently for each chip select signal. CPOL and NCPHA in the Chip Select Registers define the clock/data relationship between master and slave devices. CPOL defines the inactive value of the SPCK. NCPHA defines which edge causes data to change and which edge causes data to be captured. In Slave Mode, the input clock low and high pulse duration must be longer than two system clock (CLOCK) periods. 151 6069C–ATARM–15-Sep-05 21.9 Serial Peripheral Interface (SPI) User Interface SPI Memory Map Register Control Register Mode Register Receive Data Register Transmit Data Register Status Register Interrupt Enable Register Interrupt Disable Register Interrupt Mask Register Receive Pointer Register Receive Counter Register Transmit Pointer Register Transmit Counter Register Chip Select Register 0 Chip Select Register 1 Chip Select Register 2 Chip Select Register 3 Register Name SPI_CR SPI_MR SPI_RDR SPI_TDR SPI_SR SPI_IER SPI_IDR SPI_IMR SPI_RPR SPI_RCR SPI_TPR SPI_TCR SPI_CSR0 SPI_CSR1 SPI_CSR2 SPI_CSR3 Access Write-only Read/Write Read-only Write-only Read-only Write-only Write-only Read-only Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Reset --0x0 0x0 --0x000000F0 ----0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 Table 21-3. Offset 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C 0x20 0x24 0x28 0x2C 0x30 0x34 0x38 0x3C 152 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 21.9.1 Name: Access Type: 31 SPI Control Register SPI_CR Write-only 30 29 28 27 26 25 24 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 – 7 – 6 – 5 – 4 – 3 – 2 – 1 – 0 SWRST – – – – – SPIDIS SPIEN • SPIEN: SPI Enable 0 = No effect. 1 = Enables the SPI to transfer and receive data. • SPIDIS: SPI Disable 0 = No effect. 1 = Disables the SPI. All pins are set in input mode and no data is received or transmitted. If a transfer is in progress, the transfer is finished before the SPI is disabled. If both SPIEN and SPIDIS are equal to one when the control register is written, the SPI is disabled • SWRST: SPI Software Reset 0 = No effect. 1 = Resets the SPI. A software-triggered hardware reset of the SPI interface is performed. 153 6069C–ATARM–15-Sep-05 21.9.2 SPI Mode Register Name: SPI_MR Access Type: Read/Write 31 30 29 28 27 26 25 24 DLYBCS 23 22 21 20 19 18 17 16 – 15 – 14 – 13 – 12 11 10 PCS 9 8 – 7 – 6 – 5 – 4 – 3 – 2 – 1 – 0 LLB – – MODFDIS DIV32 PCSDEC PS MSTR • MSTR: Master/Slave Mode 0 = SPI is in Slave mode. 1 = SPI is in Master mode. • PS: Peripheral Select 0 = Fixed Peripheral Select. 1 = Variable Peripheral Select. • PCSDEC: Chip Select Decode 0 = The chip selects are directly connected to a peripheral device. 1 = The four chip select lines are connected to a 4- to 16-bit decoder. When PCSDEC equals one, up to 16 Chip Select signals can be generated with the four lines using an external 4- to 16-bit decoder. The Chip Select Registers define the characteristics of the 16 chip selects according to the following rules: SPI_CSR0 defines peripheral chip select signals 0 to 3. SPI_CSR1 defines peripheral chip select signals 4 to 7. SPI_CSR2 defines peripheral chip select signals 8 to 11. SPI_CSR3 defines peripheral chip select signals 12 to 15*. *Note: The 16th state corresponds to a state in which all chip selects are inactive. This allows a different clock configuration to be defined by each chip select register. • DIV32: Clock Selection 0 = SPI Master Clock equals ACK. 1 = SPI Master Clock equals ACK/32. • MODFDIS: Mode Fault Detection 0 = Mode fault detection is enabled. 1 = Mode fault detection is disabled. • LLB: Local Loopback Enable 0 = Local loopback path disabled 1 = Local loopback path enabled LLB controls the local loopback on the data serializer for testing in Master Mode only. 154 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 • PCS: Peripheral Chip Select This field is only used if Fixed Peripheral Select is active (PS = 0). If PCSDEC = 0: PCS = xxx0 PCS = xx01 PCS = x011 PCS = 0111 PCS = 1111 (x = don’t care) If PCSDEC = 1: NPCS[3:0] output signals = PCS • DLYBCS: Delay Between Chip Selects This field defines the delay from NPCS inactive to the activation of another NPCS. The DLYBCS time guarantees non-overlapping chip selects and solves bus contentions in case of peripherals having long data float times. If DLYBCS is less than or equal to six, six SPI Master Clock periods will be inserted by default. Otherwise, the following equation determines the delay: NPCS_to_SCK_Delay = DLYBCS * SPI_Master_Clock_period NPCS[3:0] = 1110 NPCS[3:0] = 1101 NPCS[3:0] = 1011 NPCS[3:0] = 0111 forbidden (no peripheral is selected) 155 6069C–ATARM–15-Sep-05 21.9.3 SPI Receive Data Register Name: SPI_RDR Access Type: Read-only 31 30 29 28 27 26 25 24 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 11 10 PCS 9 8 RD 7 6 5 4 3 2 1 0 RD • RD: Receive Data Data received by the SPI Interface is stored in this register right-justified. Unused bits read zero. • PCS: Peripheral Chip Select In Master Mode only, these bits indicate the value on the NPCS pins at the end of a transfer. Otherwise, these bits read zero. 156 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 21.9.4 SPI Transmit Data Register Name: SPI_TDR Access Type: Write-only 31 30 29 28 27 26 25 24 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 11 10 PCS 9 8 TD 7 6 5 4 3 2 1 0 TD • TD: Transmit Data Data to be transmitted by the SPI is stored in this register. Information to be transmitted must be written to the transmit data register in a right-justified format. PCS: Peripheral Chip Select This field is only used if Variable Peripheral Select is active (PS = 1). If PCSDEC = 0: PCS = xxx0 PCS = xx01 PCS = x011 PCS = 0111 PCS = 1111 (x = don’t care) If PCSDEC = 1: NPCS[3:0] output signals = PCS NPCS[3:0] = 1110 NPCS[3:0] = 1101 NPCS[3:0] = 1011 NPCS[3:0] = 0111 forbidden (no peripheral is selected) 157 6069C–ATARM–15-Sep-05 21.9.5 Name: SPI Status Register SPI_SR Read-only 30 29 28 27 26 25 24 Access Type: 31 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 SPIENS 8 – 7 – 6 – 5 – 4 – 3 – 2 – 1 – 0 – – ENDTX ENDRX OVRES MODF TDRE RDRF • RDRF: Receive Data Register Full 0 = No data has been received since the last read of SPI_RDR 1 = Data has been received and the received data has been transferred from the serializer to SPI_RDR since the last read of SPI_RDR. • TDRE: Transmit Data Register Empty 0 = Data has been written to SPI_TDR and not yet transferred to the serializer. 1 = The last data written in the Transmit Data Register has been transferred to the serializer. TDRE equals zero when the SPI is disabled or at reset. The SPI enable command sets this bit to one. • MODF: Mode Fault Error 0 = No Mode Fault has been detected since the last read of SPI_SR. 1 = A Mode Fault occurred since the last read of the SPI_SR. • OVRES: Overrun Error Status 0 = No overrun has been detected since the last read of SPI_SR. 1 = An overrun has occurred since the last read of SPI_SR. An overrun occurs when SPI_RDR is loaded at least twice from the serializer since the last read of the SPI_RDR. • ENDRX: End of RX buffer 0 = The Receive Counter Register has not reached 0 since the last write in SPI_RCR. 1 = The Receive Counter Register has reached 0 since the last write in SPI_RCR. • ENDTX: End of TX buffer 0 = The Transmit Counter Register has not reached 0 since the last write in SPI_TCR. 1 = The Transmit Counter Register has reached 0 since the last write in SPI_TCR. • SPIENS: SPI Enable Status 0 = SPI is disabled. 1 = SPI is enabled. 158 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 21.9.6 SPI Interrupt Enable Register Name: SPI_IER Access Type: Write-only 31 30 29 28 27 26 25 24 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 – 7 – 6 – 5 – 4 – 3 – 2 – 1 – 0 – – ENDTX ENDRX OVRES MODF TDRE RDRF • RDRF: Receive Data Register Full Interrupt Enable • TDRE: SPI Transmit Data Register Empty Interrupt Enable • MODF: Mode Fault Error Interrupt Enable • OVRES: Overrun Error Interrupt Enable • ENDRX: End of Receive Buffer Interrupt Enable • ENDTX: End of Transmit Buffer Interrupt Enable 0 = No effect. 1 = Enables the corresponding interrupt. 21.9.7 SPI Interrupt Disable Register Name: SPI_IDR Access Type: Write-only 31 30 29 28 27 26 25 24 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 – 7 – 6 – 5 – 4 – 3 – 2 – 1 – 0 – – ENDTX ENDRX OVRES MODF TDRE RDRF • RDRF: Receive Data Register Full Interrupt Disable • TDRE: SPI Transmit Data Register Empty Interrupt Disable • MODF: Mode Fault Error Interrupt Disable • OVRES: Overrun Error Interrupt Disable • ENDRX: End of Receive Buffer Interrupt Disable • ENDTX: End of Transmit Buffer Interrupt Disable 0 = No effect. 1 = Disables the corresponding interrupt. 159 6069C–ATARM–15-Sep-05 21.9.8 SPI Interrupt Mask Register Name: SPI_IMR Access Type: Read-only 31 30 29 28 27 26 25 24 – 23 – 22 – 21 – 20 – 19 – 18 – 17 – 16 – 15 – 14 – 13 – 12 – 11 – 10 – 9 – 8 – 7 – 6 – 5 – 4 – 3 – 2 – 1 – 0 – – ENDTX ENDRX OVRES MODF TDRE RDRF • RDRF: Receive Data Register Full Interrupt Mask • TDRE: SPI Transmit Data Register Empty Interrupt Mask • MODF: Mode Fault Error Interrupt Mask • OVRES: Overrun Error Interrupt Mask • ENDRX: End of Receive Buffer Interrupt Mask • ENDTX: End of Transmit Buffer Interrupt Mask 0 = The corresponding interrupt is not enabled. 1 = The corresponding interrupt is enabled. 160 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 21.9.9 SPI Chip Select Register Name: SPI_CSR0... SPI_CSR3 Access Type: Read/Write 31 30 29 28 27 26 25 24 DLYBCT 23 22 21 20 19 18 17 16 DLYBS 15 14 13 12 11 10 9 8 SCBR 7 6 5 4 3 2 1 0 BITS – – NCPHA CPOL • CPOL: Clock Polarity 0 = The inactive state value of SCK is logic level zero. 1 = The inactive state value of SCK is logic level one. CPOL is used to determine the inactive state value of the serial clock (SCK). It is used with NCPHA to produce the required clock/data relationship between master and slave devices. • NCPHA: Clock Phase 0 = Data is changed on the leading edge of SCK and captured on the following edge of SCK. 1 = Data is captured on the leading edge of SCK and changed on the following edge of SCK. NCPHA determines which edge of SCK causes data to change and which edge causes data to be captured. NCPHA is used with CPOL to produce the required clock/data relationship between master and slave devices. • BITS: Bits Per Transfer The BITS field determines the number of data bits transferred. Reserved values should not be used. BITS[3:0] 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Bits Per Transfer 8 9 10 11 12 13 14 15 16 Reserved Reserved Reserved Reserved Reserved Reserved Reserved 161 6069C–ATARM–15-Sep-05 • SCBR: Serial Clock Baud Rate In Master Mode, the SPI Interface uses a modulus counter to derive the SPCK baud rate from the SPI Master Clock (selected between CLOCK and FDIV). The Baud rate is selected by writing a value from 2 to 255 in the field SCBR. The following equation determines the SPCK baud rate: SPCK Baudrate = SPI_Master_Clock / (2 * SCBR) Giving SCBR a value of zero or one disables the baud rate generator. SPCK is disabled and assumes its inactive state value. No serial transfers may occur. At reset, baud rate is disabled. • DLYBS: Delay Before SCK This field defines the delay from NPCS valid to the first valid SCK transition. When DLYBS equals zero, the NPCS valid to SCK transition is 1/2 the SCK clock period. Otherwise, the following equation determines the delay: NPCS_to_SCK_Delay = DLYBS * SPI_Master_Clock_period • DLYBCT: Delay Between Consecutive Transfers This field defines the delay between two consecutive transfers with the same peripheral without removing the chip select. The delay is always inserted after each transfer and before removing the chip select if needed. When DLYBCT equals zero, a delay of four SPI Master Clock periods are inserted. Otherwise, the following equation determines the delay: Delay_After_Transfer = 32 * DLYBCT * SPI_Master_Clock_period. 162 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 21.9.10 SPI Receive Pointer Register Register Name: SPI_RPR Access Type: Read/Write 31 30 29 28 RXPTR 23 22 21 20 RXPTR 15 14 13 12 RXPTR 7 6 5 4 RXPTR 3 2 1 0 11 10 9 8 19 18 17 16 27 26 25 24 • RXPTR: Receive Pointer RXPTR must be loaded with the address of the receive buffer. 21.9.11 SPI Receive Counter Register Register Name: SPI_RCR Access Type: Read/Write 31 -23 -15 30 -22 -14 29 -21 -13 28 -20 -12 RXCTR 7 6 5 4 RXCTR 3 2 1 0 27 -19 -11 26 -18 -10 25 -17 -9 24 -16 -8 • RXCTR: Receive Counter Register RXCTR must be loaded with the size of the receive buffer. 0 = Stops peripheral data transfer 1 - 65535 = Start peripheral data transfer if RDRF is active. 163 6069C–ATARM–15-Sep-05 21.9.12 SPI Transmit Pointer Register Register Name: SP_TPR Access Type: Read/Write 31 30 29 28 TXPTR 23 22 21 20 TXPTR 15 14 13 12 TXPTR 7 6 5 4 TXPTR 3 2 1 0 11 10 9 8 19 18 17 16 27 26 25 24 • TXPTR: Transmit Pointer Register TXPTR must be loaded with the address of the transmit buffer. 21.9.13 SPI Transmit Counter Register Register Name: SP_TCR Access Type: Read/Write 31 -23 -15 30 -22 -14 29 -21 -13 28 -20 -12 TXCTR 7 6 5 4 TXCTR 3 2 1 0 27 -19 -11 26 -18 -10 25 -17 -9 24 -16 -8 • TXCTR: Transmit Counter Register TXCTR must be loaded with the size of the receive buffer. 0 = Stops peripheral data transfer 1 - 65535 = Start peripheral data transfer if TDRE is active. 164 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 22. Mechanical Characteristics and Packaging 22.1 PQFP Packaging Information Figure 22-1. AT91C140 PQFP Package For PQFP package data, see Table 22-1 on page 166, 165 6069C–ATARM–15-Sep-05 22.2 PQFP Package Data Table 22-1. Package Dimensions for 208-lead PQFP Package (in mm) Min Nom Max 4.10 0.25 3.20 3.32 3.60 Symbol A A1 A2 D D1 E E1 R2 R1 Q Q1 Q2 Q3 c L L1 S b e D2 E2 0.20 0.17 0.11 0.73 0.13 0.13 0° 0° 31.20 BASIC 28.00 BASIC 31.20 BASIC 28.00 BASIC 0.30 7° 8° Ref 8° Ref 0.15 0.88 1.60 REF 0.23 1.03 0.20 0.50 BSC 25.50 25.50 0.27 Tolerances of form and position aaa bbb ccc 0.25 0.20 0.08 0.010 0.008 0.003 166 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 23. Ordering Information Table 23-1. Ordering Information Package PQFP208 Package Type Green Temperature Operating Range -40°C to +85°C Ordering Code AT91C140-QU-001 167 6069C–ATARM–15-Sep-05 168 AT91C140 6069C–ATARM–15-Sep-05 AT91C140 Table of Contents Features1 1 2 3 Description ............................................................................................. 1 Block Diagram ....................................................................................... 2 Pinout .................................................................................................... 3 3.1Mechanical Overview of the 208-lead PQFP Package ..........................................4 4 Peripheral Multiplexing on PIO Lines .................................................. 5 4.1PIO Controller A Multiplexing ................................................................................6 4.2PIO Controller B Multiplexing ................................................................................6 5 6 7 8 Signal Description ................................................................................ 7 ARM7TDMI Core .................................................................................. 10 Power Supplies .................................................................................... 10 System Controller ............................................................................... 11 8.1Test ......................................................................................................................11 8.2Reset Controller ...................................................................................................11 8.3Clock Generator ...................................................................................................11 8.4Chip ID .................................................................................................................12 8.5System Controller User Interface .........................................................................13 9 Memory Controller (MC) ..................................................................... 16 9.1Architecture ..........................................................................................................16 9.2Memory Map ........................................................................................................17 9.3ARM ASB Arbitration ............................................................................................18 9.4MAC ASB Arbitration ............................................................................................18 9.5ASB-ASB Bridge Arbitration .................................................................................18 9.6Boot Mode ............................................................................................................19 9.7Endianness ..........................................................................................................20 10 Peripherals ........................................................................................... 21 10.1Peripheral Registers ...........................................................................................21 10.2Peripheral Memory Map .....................................................................................22 11 Peripheral Data Controller (PDC) ....................................................... 23 11.1PDC Overview ....................................................................................................23 11.2PDC Channel Priority .........................................................................................23 i 6069C–ATARM–15-Sep-05 12 Boot Program ...................................................................................... 24 12.1Boot Mode ..........................................................................................................24 12.2Hardware Connection of the DataFlash .............................................................24 12.3Internal Boot Software ........................................................................................24 12.4DataFlash Header Details ..................................................................................25 12.5Reserved Resources ..........................................................................................26 13 External Bus Interface (EBI) ............................................................... 27 13.1Signal Multiplexing ............................................................................................27 14 SDRAM Controller (SDRAMC) ............................................................ 28 14.1Description .........................................................................................................28 14.2Block Diagram ....................................................................................................28 14.3I/O Lines Description .........................................................................................29 14.4Application Example ...........................................................................................29 14.5SDRAM Device Initialization ..............................................................................31 14.6SDRAM Controller Write Cycle ..........................................................................32 14.7SDRAM Controller Read Cycle ..........................................................................33 14.8Border Management ..........................................................................................34 14.9SDRAM Controller Refresh Cycles ....................................................................35 14.10SDRAM User Interface .....................................................................................36 15 Static Memory Controller (SMC) ........................................................ 42 15.1External Memory Mapping .................................................................................42 15.2Pin Description ...................................................................................................42 15.3Byte Write or Byte Select Mode .........................................................................42 15.4Read Protocols ...................................................................................................43 15.5Write Protocol .....................................................................................................44 15.6Wait States .........................................................................................................44 15.7SMC User Interface ............................................................................................45 16 Ethernet MAC (EMAC) ......................................................................... 49 16.1Block Diagram ....................................................................................................49 16.2Media Independent Interface ............................................................................50 16.3Transmit/Receive Operation ..............................................................................50 16.4DMA Operations .................................................................................................52 16.5Address Checking ..............................................................................................55 16.6EMAC User Interface .........................................................................................56 16.7EMAC Statistics Register Block Registers .........................................................71 ii AT91C140 6069C–ATARM–15-Sep-05 AT91C140 17 Advanced Interrupt Controller (AIC) .................................................. 73 17.1Priority Controller ...............................................................................................74 17.2Interrupt Handling ...............................................................................................74 17.3Standard Interrupt Sequence .............................................................................75 17.4Fast Interrupt ......................................................................................................76 17.5Software Interrupt ...............................................................................................77 17.6Spurious Interrupt ...............................................................................................77 17.7AIC User Interface ..............................................................................................78 18 Parallel I/O Controller (PIO) ................................................................ 87 18.1Output Selection .................................................................................................87 18.2I/O Levels ...........................................................................................................87 18.3Interrupts ............................................................................................................87 18.4I/O Line Control ..................................................................................................88 18.5Parallel I/O Controller (PIO) User Interface ........................................................89 19 Universal Asynchronous Receiver Transmitter (UART) .................. 97 19.1Block Diagram ....................................................................................................97 19.2Pin Description ...................................................................................................98 19.3Baud Rate Generator .........................................................................................98 19.4Receiver Operations ..........................................................................................99 19.5Transmitter .......................................................................................................100 19.6Channel Modes ................................................................................................101 19.7Peripheral Data Controller ................................................................................102 19.8Modem Control and Status Signals ..................................................................102 19.9Universal Asynchronous Receiver/Transmitter (UART) User Interface ...........104 19.10UART Interrupt Disable Register ....................................................................109 19.11UART Interrupt Mask Register .......................................................................110 20 Timer/Counter (TC) ............................................................................ 118 20.1Block Diagram ..................................................................................................118 20.2Signal Name Description ..................................................................................119 20.3Description .......................................................................................................119 20.4Capture Operating Mode ..................................................................................122 20.5Waveform Operating Mode ..............................................................................123 20.6Timer/Counter (TC) User Interface ..................................................................127 21 Serial Peripheral Interface (SPI) ....................................................... 142 21.1Overview ..........................................................................................................142 iii 6069C–ATARM–15-Sep-05 21.2Block Diagram ..................................................................................................143 21.3Connections .....................................................................................................144 21.4Pin Name List ..................................................................................................144 21.5Master Mode Operations ..................................................................................144 21.6SPI Slave Mode ...............................................................................................149 21.7Data Transfers .................................................................................................149 21.8Clock Generation .............................................................................................151 21.9Serial Peripheral Interface (SPI) User Interface ...............................................152 22 Ordering Information ........................................................................ 165 23 Mechanical Characteristics and Packaging .................................... 166 23.1PQFP Packaging Information ...........................................................................166 23.2PQFP Package Data ........................................................................................167 Table of Contentsi Revision Historyv iv AT91C140 6069C–ATARM–15-Sep-05 AT91C140 Revision History Doc. Rev. 6069A 6069B Date 21-May-04 16-May-05 Comments First issue. Changed package to PQFP208. Updated ordering information. Global, External Bus Interface references to 32-bit changed to 16-bit or removed. Table 3-1, “Pinout for 208-lead PQFP Package,” DBW32 and BO256 changed to GND Table 5-1, “Signal Description,” DBW32 removed Global all instances of the following changed DQM0-DQM3 changed to DQM0-DQM1 NWE0-NWE3 changed to NWE0-NWE1 Signal Waveforms section removed Data Bus Width section removed Table 3-1, “Pinout for 208-lead PQFP Package,” Replaced SCLKA, FSA, STXA, SRXA by GND or NC Table 5-1, “Signal Description,” SCKA added to UART description, PIO descriptions changed. CSR 04-420, 05-156 CSR 05-403 Change Request Ref. 6069C 01-Sep-05 CSR 05-409 HIi v 6069C–ATARM–15-Sep-05 A tmel Corporation 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Atmel Operations Memory 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 RF/Automotive Theresienstrasse 2 Postfach 3535 74025 Heilbronn, Germany Tel: (49) 71-31-67-0 Fax: (49) 71-31-67-2340 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Regional Headquarters Europe Atmel Sarl Route des Arsenaux 41 Case Postale 80 CH-1705 Fribourg Switzerland Tel: (41) 26-426-5555 Fax: (41) 26-426-5500 Microcontrollers 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 La Chantrerie BP 70602 44306 Nantes Cedex 3, France Tel: (33) 2-40-18-18-18 Fax: (33) 2-40-18-19-60 Biometrics/Imaging/Hi-Rel MPU/ High Speed Converters/RF Datacom Avenue de Rochepleine BP 123 38521 Saint-Egreve Cedex, France Tel: (33) 4-76-58-30-00 Fax: (33) 4-76-58-34-80 Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 ASIC/ASSP/Smart Cards Zone Industrielle 13106 Rousset Cedex, France Tel: (33) 4-42-53-60-00 Fax: (33) 4-42-53-60-01 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Scottish Enterprise Technology Park Maxwell Building East Kilbride G75 0QR, Scotland Tel: (44) 1355-803-000 Fax: (44) 1355-242-743 Japan 9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581 Literature Requests www.atmel.com/literature Disclaimer: T he information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL’S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. A tmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel’s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. © Atmel Corporation 2005. A ll rights reserved. A tmel®, logo and combinations thereof, Everywhere You Are® and others, are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. ARM®, the ARM Powered logo and others, are registered trademarks or trademarks of ARM Limited. Other terms and product names may be trademarks of others. Printed on recycled paper. 6069C–ATARM–15-Sep-05
AT91C140_05 价格&库存

很抱歉,暂时无法提供与“AT91C140_05”相匹配的价格&库存,您可以联系我们找货

免费人工找货