APPLICATION NOTE. AT6486: Using DIVAS on SAMC Microcontroller. SMART ARM-Based Microcontroller. Introduction. Features

Similar documents
AT03975: Getting Started with SAM L21. Descripton. Features. SMART ARM-Based Microcontroller APPLICATION NOTE

AVR42789: Writing to Flash on the New tinyavr Platform Using Assembly

AT60142H/HT. Rad-Hard 512Kx8 Very Low Power CMOS SRAM ERRATA-SHEET. Active Errata List. Errata History. Abbreviations. 1.

AT09381: SAM D - Debugging Watchdog Timer Reset. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

AT06467: Getting started with SAM D09/D10/D11. Features. Description. SMART ARM-based Microcontrollers APPLICATION NOTE

ATAES132A Firmware Development Library. Introduction. Features. Atmel CryptoAuthentication USER GUIDE

AT11512: SAM L Brown Out Detector (BOD) Driver. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

This user guide describes how to run the Atmel ATWINC3400 Bluetooth Low Energy (BLE) Provisioning demo from out-of-box conditions.

AT03262: SAM D/R/L/C System Pin Multiplexer (SYSTEM PINMUX) Driver. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

USER GUIDE. Atmel QT6 Xplained Pro. Preface

EDBG. Description. Programmers and Debuggers USER GUIDE

QT3 Xplained Pro. Preface. Atmel QTouch USER GUIDE

AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Features. Introduction. AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE. AT05567: TC Capture on External Interrupt with the Event System on SAM D20. Preface ASF PROJECT DOCUMENTATION

AT10942: SAM Configurable Custom Logic (CCL) Driver. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

SAMA5D2 Quad SPI (QSPI) Performance. Introduction. SMART ARM-based Microprocessor APPLICATION NOTE

Ethernet1 Xplained Pro

Smart RF Device Family - Getting Started Guide. Features. Description. References ATAN0115 APPLICATION NOTE

APPLICATION NOTE. Generating Random Secrets. ATSHA204A, ATECC108A, and ATECC508A. Description. Topics

QT2 Xplained Pro. Preface. Atmel QTouch USER GUIDE

DGILib USER GUIDE Atmel-42771A-DGILib_User Guide-09/2016

APPLICATION NOTE. 3-lead CONTACT Package Usage. ATSHA204A, ATECC108A, and ATECC508A. Introduction. 3-lead CONTACT Package

ATECC108/ATSHA204 USER GUIDE. Atmel Firmware Library. Features. Introduction

SAM4 Reset Controller (RSTC)

AT21CS Series Reset and Discovery. Introduction. Serial EEPROM APPLICATION NOTE

AVR42772: Data Logger Demo Application on XMEGA A1U Xplained Pro. Introduction. Features. AVR XMEGA Microcontrollers APPLICATION NOTE

APPLICATION NOTE. Atmel QT4 Xplained Pro User Guide ATAN0114. Preface

ATECC508A Public Key Validation. Introduction. Atmel CryptoAuthentication APPLICATION NOTE

USER GUIDE. ATWINC1500 Xplained Pro. Preface

APPLICATION NOTE. Atmel AT03261: SAM D20 System Interrupt Driver (SYSTEM INTERRUPT) SAM D20 System Interrupt Driver (SYSTEM INTERRUPT)

Native route discovery algorithm

Hardware Prerequisites Atmel Xplained Pro Evaluation Kit Atmel WINC1500 extension USB Micro Cable (TypeA / MicroB)

USER GUIDE. Atmel QT1 Xplained Pro. Preface

ATtiny817 QTouch Moisture Demo User Guide. Description. Features. AVR 8-bit Microcontrollers USER GUIDE

APPLICATION NOTE. AT04470: Differences between SAM D21 Variants A, B, and L. 32-bit Microcontroller. Introduction

APPLICATION NOTE. How to Securely Switch Atmel s LIN Transceiver ATA6662/ATA6662C to Sleep Mode ATA6662/ATA6662C. Concerning Atmel ATA6662

OLED display with pixels resolution Ambient light sensor CPU load Analog filter Quadrature Encoder with push button Digital I/O

APPLICATION NOTE. CryptoAuthentication Personalization Guide. ATSHA204A and ATECC508A. Introduction. Features

APPLICATION NOTE. Atmel AVR1638: XMEGA RTC Calibration. 8-bit Atmel Microcontrollers. Features. Introduction

APPLICATION NOTE. AT11008: Migration from ATxmega16D4/32D4 Revision E to Revision I. Atmel AVR XMEGA. Introduction. Features

USER GUIDE EDBG. Description

ATtiny104 Xplained Nano. Preface. AVR 8-bit Microcontrollers USER GUIDE

USER GUIDE. Atmel Segment LCD1 Xplained Pro. Preface

AT88CK101 HARDWARE USER GUIDE. Atmel CryptoAuthentication Development Kit. Atmel CryptoAuthentication AT88CK101 Daughterboard

APPLICATION NOTE. Atmel AT03304: SAM D20 I 2 C Slave Bootloader SAM D20. Description. Features

APPLICATION NOTE. Atmel AT03160: Migrating Bootloader from ATxmega128A1 to other Atmel XMEGA Devices. Atmel AVR XMEGA. Features.

APPLICATION NOTE. Scope. Reference Documents. Software Ethernet Bridge on SAMA5D3/D4. Atmel SMART SAMA5D3/D4 Series

AVR1503: Xplain training - XMEGA Programmable Multi Interrupt Controller 8-bit Microcontrollers Application Note Prerequisites

Atmel AVR1619: XMEGA-B1 Xplained Demonstration. 8-bit Atmel Microcontrollers. Application Note. Features. 1 Introduction

USER GUIDE. Atmel OLED1 Xplained Pro. Preface

APPLICATION NOTE. Atmel AT02260: Driving AT42QT1085. Atmel QTouch. Features. Description

AT07942: SAM4L Asynchronous Timer (AST) Driver. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

I/O1 Xplained Pro. Preface. Atmel MCUs USER GUIDE

AVR1315: Accessing the XMEGA EEPROM. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

USER GUIDE. ZigBit USB Stick User Guide. Introduction

APPLICATION NOTE. Atmel AVR3009: Driving QTouch Device with I 2 C Interface. Atmel QTouch. Introduction

AVR1518: XMEGA-A1 Xplained Training - XMEGA Clock System. 8-bit Atmel Microcontrollers. Application Note. Prerequisites.

APPLICATION NOTE. AT06863: SAM4L Peripheral Event Controller (PEVC) SAM4L Peripheral Event Controller (PEVC) ASF PROGRAMMERS MANUAL

AVR1303: Use and configuration of IR communication module. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

USER GUIDE. Atmel maxtouch Xplained Pro. Preface

APPLICATION NOTE. AT03324: Atmel REB212BSMA-EK Quick Start Guide. Atmel MCU Wireless. Introduction

APPLICATION NOTE. AT07216: SAM G55 Schematic Checklist. Atmel SMART SAM G55. Introduction

AVR1501: Xplain training XMEGA Timer/Counter 8-bit Microcontrollers Application Note Prerequisites 1 Introduction

a clock signal and a bi-directional data signal (SCL, SDA)

SMART ARM-based Microcontrollers ATSAMD21E16LMOTOR USER GUIDE

USER GUIDE. Wireless Production Test Reference Protocol Specification Document. Atmel MCU Wireless. Description

ATZB-SAMR21-XPRO. Preface. SmartConnect USER GUIDE

Atmel AVR1926: XMEGA-B1 Xplained Getting Started Guide. 8-bit Atmel Microcontrollers. Application Note. Features. 1 Introduction

AVR32752: Using the AVR32 UC3 Static Memory Controller. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

RELEASE NOTES. GNU Toolchain for Atmel ARM Embedded Processors. Introduction

APPLICATION NOTE. Atmel AT03782: Using Low Power Modes in SAM4N Microcontroller. Atmel 32-bit Microcontroller. Features.

Atmel AVR32847: Migration from/to the UC3L0 64/32/16 from/to the UC3L0 256/ bit Atmel Microcontrollers. Application Note.

AT03664: Getting Started with FreeRTOS on SAM D20/D21/R21/L21/L22. Introduction. Features. SMART ARM-based Microcontrollers APPLICATION NOTE

64K (8K x 8) Battery-Voltage Parallel EEPROM with Page Write and Software Data Protection AT28BV64B

Atmel QT600 Quick Start Guide Touch Solutions

MySonicWall Secure Upgrade Plus

Atmel AVR ATxmega384C3 microcontroller OLED display with 128x32 pixels resolution Analog sensors. Ambient light sensor Temperature sensor

USER GUIDE. Atmel PROTO1 Xplained Pro. Preface

AVR4018: Inertial Two (ATAVRSBIN2) Hardware User's Guide. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Atmel LF-RFID Kit Comparison Chart. Application Note. Atmel LF-RFID Kit Comparison Chart. 1. Description

APPLICATION NOTE. Atmel AT01080: XMEGA E Schematic Checklist. Atmel AVR XMEGA E. Features. Introduction

AT88RF04C. CryptoRF EEPROM Memory 13.56MHz, 4 Kilobits SUMMARY DATASHEET. Features

AT88SC3216CRF. CryptoRF EEPROM Memory 13.56MHz, 32 Kilobits SUMMARY DATASHEET. Features

AVR1508: Xplain training - XMEGA DAC 8-bit Microcontrollers Application Note Features 1 Introduction

APPLICATION NOTE. Atmel AVR2131: Lightweight Mesh Getting Started Guide. Atmel MCU Wireless. Features. Description

OLED display Sensors readout. Light sensor Temperature sensor

Atmel and the use of Verilator to create uc Device Models

AN2667 Application note

Application Note Using the ATV750, ATV750B, and ATF750C Erasable Programmable Logic Device Introduction 1.1 Device Names and Pin/Node Assignments

APPLICATION NOTE. Atmel AVR057: Internal RC Oscillator Calibration for ATtiny4/5/9/10/20/40. 8-bit Atmel Microcontrollers. Features.

Atmel ATtiny1634 MCU Atmel ATA SBC LIN transceiver with integrated voltage regulator Touch. Three Atmel QTouch buttons One Atmel QTouch slider

AVR32401: AVR32 AP7 Linux Interfacing DataFlash. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. Atmel AVR116: Wear Leveling on DataFlash. 32-bit Atmel Microcontrollers. Features. Description. Wear leveling

USER GUIDE. ATmega168 Xplained Mini User Guide. Introduction

SAM4L Asynchronous Timer (AST)

AVR1922: Xplain Board Controller Firmware 8-bit Microcontrollers Application Note Features 1 Introduction

Section 5 SERCOM. Tasks SPI. In this section you will learn:

Atmel ATMXT143E touchscreen controller Capacitive touch ITO 320 x 240 pixel LCD display with SPI interface LED backlight

SonicWall Mobile Connect for Chrome OS

AN4113 Application note

Transcription:

APPLICATION NOTE AT6486: Using DIVAS on SAMC Microcontroller SMART ARM-Based Microcontroller Introduction DIVAS stands for Division and Square Root Accelerator. DIVAS is a brand new peripheral introduced in SAMC family of microcontrollers. SAMC family is mainly targeted towards home appliance and industrial applications market. Such applications mostly require more involved mathematical operations for algorithms and automation calculations. In most languages, including C, division is performed using intrinsic operators. Quotient and division modulus are represented by / and % operators respectively. For controllers without hardware divider (like Cortex M0+), compiler replaces these operators with library code. This library code adds hundreds of bytes and consumes anywhere from 50 to 400 clock cycles depending on the size of operands. For square root, an additional library has to be included in the project (math.h). DIVAS addresses these issues by providing square root and division support in hardware and requires minimal code and clock cycles (2-16 cycles). This application note discusses the APIs (application programming interfaces) available in Atmel Studio Framework (ASF) that make DIVAS easy to use. It also explains how compiler division operators ( % and / ) can be overloaded to use DIVAS as backend for calculations. Features Division and square root accelerator for Cortex M0+ systems Signed and unsigned division Unsigned 32-bit square root Result includes quotient/square root and remainder

Table of Contents 1 Overview... 3 1.1 Description... 3 1.2 Register Interface... 3 2 Functional Description... 4 2.1 Basic Operation... 4 2.1.1 Initialization... 4 2.1.2 Clocks... 4 2.1.3 Performing Division... 4 2.1.4 Signed Division... 4 2.1.5 Divide by Zero... 4 2.1.6 Leading Zero Optimization... 5 2.1.7 Unsigned Square Root... 5 2.2 Usage Summary... 5 3 Firmware Implementation... 5 3.1 Peripheral APIs... 5 3.2 Compiler Operator Overloading... 6 3.3 DIVAS Example... 6 3.3.1 Requirements... 6 3.3.2 Description... 6 4 Revision History... 7 2

1 Overview 1.1 Description The Divide and Square Root Accelerator (DIVAS) is a programmable 32-bit signed or unsigned hardware divider and a 32-bit unsigned square root hardware engine. The DIVAS is connected to the high-speed bus matrix and may also be accessed using the low-latency CPU local bus (IOBUS; ARM single-cycle I/O port). The DIVAS takes dividend and divisor values and returns the quotient and remainder when it is used as divider. The DIVAS takes unsigned input value and returns its square root and remainder when it is used as square root function. Figure 1-1. DIVAS Block Diagram 1.2 Register Interface DIVAS peripheral has seven registers. These registers are: CTRLA Control register to disable leading zero optimization and enable signed division STATUS Status register to detect divide by zero error and busy bit When BUSY bit is set, CTRLA, DIVIDEND, DIVISOR, and SQRNUM registers are write protected DIVIDEND Holds the 32-bit dividend for the divide operation If CTRLA.SIGNED bit is set, DIVIDEND is signed 2's complement DIVISOR Holds the 32-bit divisor for the divide operation If CTRLA.SIGNED bit is set, DIVISOR is signed 2's complement Writing DIVISOR register starts the divide function RESULT Holds the 32-bit result. For division it is the quotient, for square root operation, it is the square root In case of division, if CTRLA.SIGNED bit is set, quotient is signed 2's complement REMAINDER Holds the 32-bit remainder for divide or square root operation In case of division, if CTRLA.SIGNED bit is set, remainder is signed 2's complement SQRNUM Holds the 32-bit unsinged input for the square root operation Writing SQRNUM register starts the square root operation 3

2 Functional Description The Divide and Square Root Accelerator (DIVAS) supports signed or unsigned hardware division of 32-bit values and unsigned square root of 32-bit value. It is accessible from the CPU via both the AHB bus and IOBUS. When the dividend and divide registers are programmed, the division starts and the result will be stored in the Result and Remainder registers. The Busy and Divide-by-zero status can be read from STATUS register. 2.1 Basic Operation 2.1.1 Initialization THE DIVAS configuration cannot be modified while a divide operation is ongoing. The following bits must be written prior to starting a division. Sign selection bit in Control A register Sign bit enables the signed division. Signed division is explained in Section 2.1.4 Signed Division. 2.1.2 Clocks Disable leading zero optimization bit in Control A Leading zero optimization is explained in Section 2.1.6 Leading Zero Optimization. The DIVAS bus clock (CLK_DIVAS_AHB) can be enabled or disabled in the power manager. This clock has to be enabled before using DIVAS. 2.1.3 Performing Division First write the dividend to DIVIDEND register. Writing the divisor to DIVISOR register starts the division and sets the busy bit in the Status register (STATUS.BUSY). When the division has completed, the STATUS.BUSY bit is cleared and the result will be stored in RESULT and REMAINDER registers. The RESULT and REMAINDER registers can be read directly via the high-speed bus without checking first STATUS.BUSY. Wait states will be inserted on the high-speed bus until the operation is complete. The IOBUS does not support wait states. For accesses via the IOBUS, the STATUS.BUSY bit must be polled before reading the result from the RESULT and REMAINDER registers. 2.1.4 Signed Division When CTRLA.SIGNED is one, both the input and the result will be in 2 s complement format. The results of signed division are such that the remainder and dividend have the same sign and the quotient is negative if the dividend and divisor have opposite signs. 16-bit results are sign extended to 32-bits. Note: 2.1.5 Divide by Zero When the maximum negative number is divided by the minimum negative number, the resulting quotient overflows the signed integer range and will return the maximum negative number with no indication of the overflow. This occurs for 0x80000000 / 0xFFFFFFFF in 32-bit operation and 0x8000 / 0xFFFF in 16-bit operation. A divide by zero fault occurs if the DIVISOR is programmed to zero. QUOTIENT will be zero and the REMAINDER is equal to DIVIDEND. Divide by zero sets the Divide-by-zero bit in the Status register (STATUS.DBZ) to one. STATUS.DBZ must be cleared by writing a one to it. 4

2.1.6 Leading Zero Optimization Leading zero optimization can reduce the time it takes to complete a division by skipping leading zeros in the DIVIDEND (or leading ones in signed mode). Leading zero optimization is enabled by default and can be disabled by the Disable Leading Zero bit in the Control A register (CTRLA.DLZ). When CTRLA.DLZ is zero, 16- bit division completes in 2-8 cycles and 32-bit division completes in 2-16 cycles, depending on the dividend value. If deterministic timing is required, setting CTRLA.DLZ to one forces 16-bit division to always take eight cycles and 32-bit division to always take 16 cycles. 2.1.7 Unsigned Square Root When the square root input register (SQRNUM) is programmed, the square root function starts and the result will be stored in the Result and Remainder registers. The Busy status can be read from STATUS register. 2.2 Usage Summary For division: Set sign bit in CTRLA register Set leading zero mode bit in CTRLA register Write to dividend register Write to divisor register (start division) Wait for STATUS.BUSY bit to be cleared Read the RESULT and REMAINDER registers through AHB or IOBUS For square root: Write to SQRNUM register Wait for STATUS.BUSY bit to be cleared Read the RESULT and REMAINDER registers through AHB or IOBUS 3 Firmware Implementation DIVAS drivers are a part of Atmel Studio Framework. Easy to use APIs have been provided to use DIVAS. There are two ways to use DIVAS in firmware; Peripheral APIs and operator overloading. Both these implementations are demonstrated in the application example accompanying this application note. 3.1 Peripheral APIs DIVAS can be accessed by application program interfaces like any other peripheral. The ASF drivers provide APIs to set/reset each bit. The list of APIs provided by the driver are: int32_t divas_idiv(int32_t numerator, int32_t denominator); uint32_t divas_uidiv(uint32_t numerator, uint32_t denominator); int32_t divas_idivmod(int32_t numerator, int32_t denominator); uint32_t divas_uidivmod(uint32_t numerator, uint32_t denominator); uint32_t divas_sqrt(uint32_t radicand); static inline void divas_enable_dlz(void); static inline void divas_disable_dlz(void); void _system_divas_init(void); 5

3.2 Compiler Operator Overloading A simpler way of using DIVAS is making it invisible to the programmer. This can be achieved by replacing the backend for compiler intrinsic operators / and %. When compiler compiles the statements containing these operators, it uses DIVAS APIs instead of library generated code automatically. Unfortunately, it is not possible for square root because square root does not have a C intrinsic operator. DIVAS driver provided with ASF provides code for overloading division operators for both Atmel Studio and IAR. The ASF example provided with this application note can be compiled to use overloaded operators by setting the following #define to true in project symbols. It is explained in Section 3.3.2 Description. #define USE_OVERLOAD_OPERATORS true 3.3 DIVAS Example This application note comes with an application example firmware. This application has been developed using Atmel Studio but the code is compatible with IAR as well. 3.3.1 Requirements 3.3.2 Description Atmel Studio with SAM C21 support SAM C21 Xplained Pro board The application should build without any errors on Atmel Studio. The application has test vectors in the form of arrays. If the firmware passes the tests, the LED will turn on. If the tests fail, the LED will start blinking. The application, by default is set to use DIVAS APIs. Overloaded operators can be enabled by defining USE_OVERLOAD_OPERATORS as true in the project symbols as shown in Figure 3-1. By default, it is set to false. Figure 3-1. Project Properties 6

4 Revision History Doc Rev. Date Comments 42465A 06/2015 Initial document release. 7

8 Atmel Corporation 1600 Technology Drive, San Jose, CA 95110 USA T: (+1)(408) 441.0311 F: (+1)(408) 436.4200 www.atmel.com 2015 Atmel Corporation. / Rev.:. Atmel, Atmel logo and combinations thereof, Enabling Unlimited Possibilities, and others are registered trademarks or trademarks of Atmel Corporation in U.S. and other countries. ARM, ARM Connected logo, Cortex, and others are the registered trademarks or trademarks of ARM Ltd. Other terms and product names may be trademarks of others. DISCLAIMER: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual prop erty right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, 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 LI MITATION, DAMAGES FOR LOSS AND 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. Atmel makes no representations or warranties with respect to the accurac y or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice. Atmel does n ot 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 products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. SAFETY-CRITICAL, MILITARY, AND AUTOMOTIVE APPLICATIONS DISCLAIMER: Atmel products are not designed for and will not be used in connection with any applications where the failure of such products would reasonably be expected to result in significant personal injury or death ( Safety-Critical Applications ) without an Atmel officer's specific written consent. Safety-Critical Applications include, without limitation, life support devices and systems, equipment or systems for the operation o f nuclear facilities and weapons systems. Atmel products are AT6486: not designed Using nor intended DIVAS for use on in military SAMC or aerospace Microcontroller applications or environments [APPLICATION unless specifically NOTE] designated by Atmel as military -grade. Atmel products are not designed nor intended for use automotive applications unless specifically designated by Atmel as aut omotive-grade.