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

Similar documents
SAM4L Asynchronous Timer (AST)

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

SAM4 Reset Controller (RSTC)

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

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

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

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

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

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

SAM4L Liquid Crystal Display (LCDCA)

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

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

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

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

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

EDBG. Description. Programmers and Debuggers USER GUIDE

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

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

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

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

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

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

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

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

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

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

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

Ethernet1 Xplained Pro

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

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

USER GUIDE. Atmel QT6 Xplained Pro. Preface

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

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

USER GUIDE EDBG. Description

QT3 Xplained Pro. Preface. Atmel QTouch USER GUIDE

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

ATECC508A Public Key Validation. Introduction. Atmel CryptoAuthentication APPLICATION NOTE

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

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

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

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

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

USER GUIDE. ATWINC1500 Xplained Pro. Preface

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

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

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

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

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

QT2 Xplained Pro. Preface. Atmel QTouch USER GUIDE

Native route discovery algorithm

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

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

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

AVR32917: picopower Board getting started. 32-bit Microcontrollers. Application Note. Preliminary. Features. 1 Introduction

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

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

Open Source Used In TSP

APPLICATION NOTE. Atmel AVR536: Migration from ATmega644 to ATmega644A. 8-bit Atmel Microcontrollers. Introduction

USER GUIDE. Atmel QT1 Xplained Pro. Preface

Documentation Roadmap for Cisco Prime LAN Management Solution 4.2

Intel Stress Bitstreams and Encoder (Intel SBE) 2017 AVS2 Release Notes (Version 2.3)

M3H Group(2) Application Note 12-bit Analog to Digital Converter (ADC-A)

USER GUIDE. Atmel Segment LCD1 Xplained Pro. Preface

M3H Group(2) Application Note Asynchronous Serial Communication Circuit (UART-C)

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

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

OLED display Sensors readout. Light sensor Temperature sensor

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

AT03255: SAM D/R/L/C Serial Peripheral Interface (SERCOM SPI) Driver. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

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

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

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

AVR532: Migration from ATmega48/88/168 to ATmega48A/88A/168A. 8-bit Microcontrollers. Application Note. 1 Introduction

USER GUIDE. Atmel OLED1 Xplained Pro. Preface

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

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

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

Base Timer Channel (BT) Features. General Description. When to Use a PDL_BT Component 1.0

HALCoGen TMS570LS31x Help: example_sci_uart_9600.c

Getting Started with the SAM4L-EK Demo

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

End User License Agreement

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

USER GUIDE. Atmel maxtouch Xplained Pro. Preface

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

Atmel QT600 Quick Start Guide Touch Solutions

AVR097: Migration between ATmega128 and ATmega1281/ATmega bit Microcontrollers. Application Note. Features. 1 Introduction

Multifunction Serial Interface (PDL_MFS) Features. General Description. When to Use a PDL_MFS Component. Quick Start 1.0

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

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

MagicInfo Express Content Creator

AVR32 UC3 Software Framework... User Manual

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

SBAT90USB162 Atmel. SBAT90USB162 Development Board User s Manual

MySonicWall Secure Upgrade Plus

ATZB-SAMR21-XPRO. Preface. SmartConnect USER GUIDE

LBAT90USB162 Atmel. LBAT90USB162 Development Board User s Manual

Transcription:

SMART ARM-based Microcontrollers AT07942: SAM4L Asynchronous Timer (AST) Driver APPLICATION NOTE Introduction This driver for Atmel SMART ARM -based microcontrollers provides an interface for the configuration and management of the device's Asynchronous Timer functionality. The Asynchronous Timer can generate periodic interrupts and peripheral events from output from the prescaler, as well as alarm interrupts and peripheral events, which can trigger at any counter value. Devices from the following series can use this module: Atmel SMART SAM4L The outline of this documentation is as follows: Prerequisites Module Overview Special Considerations Extra Information Examples API Overview

Table of Contents Introduction...1 1. Software License... 5 2. Prerequisites...6 3. Module Overview...7 3.1. Alarm Interrupt...7 3.2. Periodic Events...7 3.3. Digital Tuner... 8 4. Special Considerations...9 4.1. Crystal Selection...9 4.2. Year Limit...9 5. Extra Information... 10 6. Examples... 11 7. API Overview...12 7.1. Variable and Type Definitions...12 7.1.1. Type ast_callback_t... 12 7.1.2. Type ast_event_source_t...12 7.1.3. Type ast_interrupt_source_t... 12 7.1.4. Type ast_mode_t... 12 7.1.5. Type ast_oscillator_type_t... 12 7.1.6. Type ast_wakeup_source_t... 12 7.2. Structure Definitions... 13 7.2.1. Struct ast_calendar...13 7.2.2. Union ast_calendar. unnamed... 13 7.2.3. Struct ast_calv... 13 7.2.4. Struct ast_config... 13 7.3. Macro Definitions...14 7.3.1. Predefined PSEL Values...14 7.3.2. Macro AST_POLL_TIMEOUT... 14 7.4. Function Definitions...14 7.4.1. Function ast_clear_interrupt_flag()... 14 7.4.2. Function ast_clear_prescalar()... 14 7.4.3. Function ast_configure_digital_tuner()... 14 7.4.4. Function ast_disable()... 15 7.4.5. Function ast_disable_digital_tuner()...15 7.4.6. Function ast_disable_event()...15 7.4.7. Function ast_disable_interrupt()... 16 7.4.8. Function ast_disable_wakeup()... 16 7.4.9. Function ast_enable()... 16 7.4.10. Function ast_enable_counter_clear_on_alarm()... 16 2

7.4.11. Function ast_enable_event()... 17 7.4.12. Function ast_enable_interrupt()...17 7.4.13. Function ast_enable_wakeup()...17 7.4.14. Function ast_init_digital_tuner()...18 7.4.15. Function ast_is_busy()...18 7.4.16. Function ast_is_clkbusy()... 18 7.4.17. Function ast_is_enabled()... 19 7.4.18. Function ast_read_calendar_value()... 19 7.4.19. Function ast_read_counter_value()... 20 7.4.20. Function ast_read_interrupt_mask()...20 7.4.21. Function ast_read_status()... 20 7.4.22. Function ast_set_callback()... 20 7.4.23. Function ast_set_config()... 21 7.4.24. Function ast_start()...21 7.4.25. Function ast_stop()... 22 7.4.26. Function ast_write_alarm0_value()...22 7.4.27. Function ast_write_calendar_value()...22 7.4.28. Function ast_write_counter_value()...22 7.4.29. Function ast_write_periodic0_value()... 23 7.5. Enumeration Definitions... 23 7.5.1. Enum ast_event_source... 23 7.5.2. Enum ast_interrupt_source...23 7.5.3. Enum ast_mode...24 7.5.4. Enum ast_oscillator_type...24 7.5.5. Enum ast_wakeup_source... 24 8. Extra Information for Asynchronous Timer Driver...25 8.1. Acronyms...25 8.2. Dependencies...25 8.3. Errata...25 8.4. Module History...25 9. Examples for Asynchronous Timer Driver... 26 9.1. Quick Start Guide for the AST driver...26 9.1.1. Use Cases... 26 9.1.2. AST Basic Usage...26 9.1.3. Setup Steps... 26 9.1.4. Usage Steps... 27 9.2. Asynchronous Timer (AST) - Example 1 Calendar Mode... 27 9.2.1. Purpose... 27 9.2.2. Requirements... 27 9.2.3. Description...27 9.2.4. Main Files... 27 9.2.5. Compilation Information...28 9.2.6. Usage... 28 9.3. Asynchronous Timer (AST) - Example 2 Alarm Wakeup...28 9.3.1. Purpose... 28 9.3.2. Requirements... 28 9.3.3. Description...28 3

9.3.4. Main Files... 28 9.3.5. Compilation Information...29 9.3.6. Usage... 29 10. Document Revision History... 30 4

1. Software License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of Atmel may not be used to endorse or promote products derived from this software without specific prior written permission. 4. This software may only be redistributed and used in connection with an Atmel microcontroller product. THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5

2. Prerequisites There are no prerequisites for this module. 6

3. Module Overview The AST module in the SAM4L devices is a 32-bit counter, with a 32-bit programmable prescaler. Typically, the AST clock is run continuously, including in the device's low-power sleep modes, to track the current time and date information. The AST can also wake-up the system from backup mode using either the alarm wakeup, periodic wakeup, or overflow wake-up mechanisms. The AST has been designed to meet the system tick and Real-Time Clock requirements of most embedded operating systems. In this driver, the AST is operated in Calendar Mode. This allows for an easy integration of a Real-Time Clock and calendar into a user application to track the passing of time and/or perform scheduled tasks. Whilst operating in Calendar Mode, the AST features: Time tracking in seconds, minutes, and hours in 24 hour format Date tracking in day, month, and year Automatic leap year correction 3.1. Alarm Interrupt The AST has a device dependent number of independent hardware alarms that can be configured by the user application. These alarms will be triggered on a match with the current clock value, and can be set up to trigger an interrupt, event, or both. The AST can also be configured to clear the clock value on alarm match which will generate an overflow interrupt. Note: Refer to module configuration at the end of the AST section of the device datasheet for the number of alarms supported. Whilst in Calendar Mode and using a nominal 1Hz input clock frequency, a register overflow will occur after 64 years. 3.2. Periodic Events The AST can generate events at periodic intervals, allowing for direct peripheral actions without CPU intervention. The periodic events can be generated on an AST prescaler match, and will be generated on the rising edge transition of the specified bit. The resulting periodic frequency can be calculated by the following formula: = 2 + 1 Where refers to the asynchronous clock set up in the AST module configuration. Note: The connection of events between modules requires the use of the SAM4L Peripheral Event Controller (PEVC) to route an output event of one module to the the input event of another. For more information on event routing, refer to the event driver documentation. 7

3.3. Digital Tuner The AST module contains Digital Tuner logic to compensate for inaccurate source clock frequencies, which would otherwise result in skewed time measurements. 8

4. Special Considerations 4.1. Crystal Selection The external crystal selection used by the AST module in the final system design must take into account: Current consumption to achieve the best power savings in low power operating modes Frequency drift (due to temperature effects on the circuit) for the best time accuracy 4.2. Year Limit The AST module has a year range of 63 years from the starting year configured when the module is initialized. Dates outside the start to end year range described below will need software adjustment:, + 64 9

5. Extra Information For extra information, see Extra Information for Asynchronous Timer Driver. This includes: Acronyms Dependencies Errata Module History 10

6. Examples For a list of examples related to this driver, see Examples for Asynchronous Timer Driver. 11

7. API Overview 7.1. Variable and Type Definitions 7.1.1. Type ast_callback_t typedef void(* ast_callback_t )(void) AST interrupt callback. 7.1.2. Type ast_event_source_t typedef enum ast_event_source ast_event_source_t AST event source. 7.1.3. Type ast_interrupt_source_t typedef enum ast_interrupt_source ast_interrupt_source_t AST interrupt source. 7.1.4. Type ast_mode_t typedef enum ast_mode ast_mode_t AST Calendar Mode. 7.1.5. Type ast_oscillator_type_t typedef enum ast_oscillator_type ast_oscillator_type_t AST Oscillator type. 7.1.6. Type ast_wakeup_source_t typedef enum ast_wakeup_source ast_wakeup_source_t AST wake-up source. 12

7.2. Structure Definitions 7.2.1. Struct ast_calendar Table 7-1 Members Type Name Description union ast_calendar.@1 @1 7.2.2. Union ast_calendar. unnamed Table 7-2 Members Type Name Description uint32_t field struct ast_calv FIELD Calendar 7.2.3. Struct ast_calv Description for Calendar Field. Table 7-3 Members Type Name Description uint32_t day Day in the range 1 to 31 uint32_t hour Hours in the range 0 to 23 uint32_t min Minutes in the range range 0 to 59 uint32_t month Month in the range 1 to 12 uint32_t sec Seconds in the range 0 to 59 uint32_t year Year in the range 0 to 63 7.2.4. Struct ast_config AST configuration. Table 7-4 Members Type Name Description struct ast_calendar calendar Initial calendar Value uint32_t counter Initial counter Value ast_mode_t mode Mode: Calendar Mode: AST_CALENDAR_MODE or Counter Mode: AST_COUNTER_MODE ast_oscillator_type_t osc_type Oscillator type uint8_t psel Prescaler Value 13

7.3. Macro Definitions 7.3.1. Predefined PSEL Values 7.3.1.1. Macro AST_PSEL_32KHZ_1HZ #define AST_PSEL_32KHZ_1HZ 7.3.1.2. Macro AST_PSEL_RC_1_76HZ #define AST_PSEL_RC_1_76HZ 7.3.2. Macro AST_POLL_TIMEOUT #define AST_POLL_TIMEOUT Timeout to prevent code hang in clock initialization. 7.4. Function Definitions 7.4.1. Function ast_clear_interrupt_flag() Clear an AST interrupt status flag. void ast_clear_interrupt_flag( ast_interrupt_source_t source) Table 7-5 Parameters [in] source AST interrupt source for which the status is to be cleared 7.4.2. Function ast_clear_prescalar() Clear the AST periodic prescaler counter to zero. void ast_clear_prescalar( Ast * ast) Table 7-6 Parameters 7.4.3. Function ast_configure_digital_tuner() Tune the AST prescaler frequency to the desired frequency. uint32_t ast_configure_digital_tuner( 14

uint32_t input_freq, uint32_t tuned_freq) Note: Refer to the section entitled "digital tuner" in the ast chapter of the device-specific datasheet for more information. Table 7-7 Parameters [in] input_freq Prescaled AST Clock Frequency [in] tuned_freq Desired AST frequency 7.4.4. Function ast_disable() Disable the AST counter and module. void ast_disable( Ast * ast) Table 7-8 Parameters 7.4.5. Function ast_disable_digital_tuner() Disable the AST digital tuner. void ast_disable_digital_tuner( Ast * ast) Table 7-9 Parameters 7.4.6. Function ast_disable_event() Disable an AST event. void ast_disable_event( ast_event_source_t source) Table 7-10 Parameters [in] source AST event source to be disabled 15

7.4.7. Function ast_disable_interrupt() Disable an AST interrupt. void ast_disable_interrupt( ast_interrupt_source_t source) Table 7-11 Parameters [in] source AST interrupt source to be disabled 7.4.8. Function ast_disable_wakeup() Disable an AST asynchronous wake-up source. void ast_disable_wakeup( ast_wakeup_source_t source) Table 7-12 Parameters [in] source AST wake-up source to be disabled 7.4.9. Function ast_enable() Enable the AST module. void ast_enable( Ast * ast) Table 7-13 Parameters [in] ast Module hardware register base address pointer 7.4.10. Function ast_enable_counter_clear_on_alarm() Enable the option to clear the counter on an AST alarm. void ast_enable_counter_clear_on_alarm( uint8_t alarm_channel) 16

Table 7-14 Parameters [in] alarm_channel AST Alarm Channel 7.4.11. Function ast_enable_event() Enable an AST event. void ast_enable_event( ast_event_source_t source) Table 7-15 Parameters [in] source AST event source to be enabled 7.4.12. Function ast_enable_interrupt() Enable an AST interrupt. void ast_enable_interrupt( ast_interrupt_source_t source) Table 7-16 Parameters [in] source AST interrupt source to be enabled 7.4.13. Function ast_enable_wakeup() Enable an AST asynchronous wake-up source. void ast_enable_wakeup( ast_wakeup_source_t source) Table 7-17 Parameters [in] source AST wake-up source to be enabled 17

7.4.14. Function ast_init_digital_tuner() Initialize the AST digital tuner. void ast_init_digital_tuner( bool add, uint8_t value, uint8_t exp) Table 7-18 Parameters [in] add Set to true if the frequency needs to be increased, false if it has to be decreased. [in] value Parameter used in the formula [in] exp Parameter used in the formula 7.4.15. Function ast_is_busy() Check the busy status of AST. bool ast_is_busy( Ast * ast) Table 7-19 Parameters [in] ast Module hardware register base address pointer Returns AST busy status. Table 7-20 Return Values Return value false true Description AST is not busy AST is busy 7.4.16. Function ast_is_clkbusy() Check the busy status of the AST clock. bool ast_is_clkbusy( Ast * ast) 18

Table 7-21 Parameters [in] ast Module hardware register base address pointer Returns AST clock busy status. Table 7-22 Return Values Return value false true Description AST clock is not busy AST clock is busy 7.4.17. Function ast_is_enabled() Check the status of the AST module. bool ast_is_enabled( Ast * ast) Table 7-23 Parameters Table 7-24 Return Values Return value false true Description AST is not enabled AST is enabled 7.4.18. Function ast_read_calendar_value() Get the AST current calendar value. struct ast_calendar ast_read_calendar_value( Ast * ast) Note: There maybe a compiler warning about returning a structure type value, however it is safe because ast_calendar is actually uint32_t type. Table 7-25 Parameters [in] ast Module hardware register base address pointer Returns The AST current calendar value. 19

7.4.19. Function ast_read_counter_value() Get the AST current counter value. uint32_t ast_read_counter_value( Ast * ast) Table 7-26 Parameters [in] ast Module hardware register base address pointer Returns AST current counter value. 7.4.20. Function ast_read_interrupt_mask() Get the AST interrupt mask value. uint32_t ast_read_interrupt_mask( Ast * ast) Table 7-27 Parameters [in] ast Module hardware register base address pointer Returns AST Interrupt mask value. 7.4.21. Function ast_read_status() Get the status of AST. uint32_t ast_read_status( Ast * ast) Table 7-28 Parameters [in] ast Module hardware register base address pointer Returns AST status. 7.4.22. Function ast_set_callback() Set callback for AST interrupts. void ast_set_callback( ast_interrupt_source_t source, ast_callback_t callback, 20

Table 7-29 Parameters uint8_t irq_line, uint8_t irq_level) [in] source AST interrupt source [in] callback Callback function pointer [in] irq_line Interrupt line [in] irq_level Interrupt level 7.4.23. Function ast_set_config() Initialize and enable the AST module in Calendar Mode or Counter Mode. uint32_t ast_set_config( struct ast_config * ast_conf) Note: If you use the 32kHz oscillator it will be enabled by this function. Table 7-30 Parameters [in] ast_conf AST configuration structure pointer Returns Initialization result. Table 7-31 Return Values Return value Description 0 Initialization failed due to a software timeout 1 Initialization succeeded 7.4.24. Function ast_start() Start the AST counter. void ast_start( Ast * ast) Table 7-32 Parameters 21

7.4.25. Function ast_stop() Stop the AST counter. void ast_stop( Ast * ast) Table 7-33 Parameters 7.4.26. Function ast_write_alarm0_value() Set the AST alarm0 value. void ast_write_alarm0_value( uint32_t alarm_value) Table 7-34 Parameters [in] alarm_value AST alarm0 value 7.4.27. Function ast_write_calendar_value() Set the AST current calendar value. void ast_write_calendar_value( struct ast_calendar calendar) Table 7-35 Parameters [in] calendar Startup date structure 7.4.28. Function ast_write_counter_value() Set the AST current counter value. void ast_write_counter_value( uint32_t ast_counter) 22

Table 7-36 Parameters [in] ast_counter Startup counter value 7.4.29. Function ast_write_periodic0_value() Set the AST periodic0 value. void ast_write_periodic0_value( uint32_t pir) Table 7-37 Parameters [in] pir AST periodic0 7.5. Enumeration Definitions 7.5.1. Enum ast_event_source AST event source. Table 7-38 Members Enum value AST_EVENT_ALARM AST_EVENT_PER AST_EVENT_OVF Description Alarm event generation Peripheral event generation Counter overflow event generation 7.5.2. Enum ast_interrupt_source AST interrupt source. Table 7-39 Members Enum value AST_INTERRUPT_ALARM AST_INTERRUPT_PER AST_INTERRUPT_OVF AST_INTERRUPT_READY AST_INTERRUPT_CLKREADY Description Alarm interrupt Periodic interrupt Overflow interrupt Synchronization complete interrupt Clock synchronization complete interrupt 23

7.5.3. Enum ast_mode AST Calendar Mode. Table 7-40 Members Enum value AST_COUNTER_MODE AST_CALENDAR_MODE Description Counter Mode Calendar Mode 7.5.4. Enum ast_oscillator_type AST Oscillator type. Table 7-41 Members Enum value AST_OSC_RC AST_OSC_32KHZ AST_OSC_PB AST_OSC_GCLK AST_OSC_1KHZ Description System RC oscillator (RCSYS) 32kHz oscillator (OSC32 or RC32) APB clock Generic clock (GCLK) 1kHz clock from the 32kHz oscillator or 32kHz RC oscillator (CLK_1K) 7.5.5. Enum ast_wakeup_source AST wake-up source. Table 7-42 Members Enum value AST_WAKEUP_ALARM AST_WAKEUP_PER AST_WAKEUP_OVF Description Alarm wake-up source Peripheral interrupt wake-up source Counter overflow wake-up source 24

8. Extra Information for Asynchronous Timer Driver 8.1. Acronyms Below is a table listing the acronyms used in this module, along with their intended meanings. Acronym BPM QSG Definition Backup Power Manager Quick Start Guide 8.2. Dependencies This driver has the following dependencies: None 8.3. Errata There are no errata related to this driver. 8.4. Module History An overview of the module history is presented in the table below, with details on the enhancements and fixes made to the module since its first release. The current version of this corresponds to the newest version in the table. Changelog Initial document release 25

9. Examples for Asynchronous Timer Driver This is a list of the available Quick Start Guides (QSGs) and example applications for SAM4L Asynchronous Timer (AST) Driver. QSGs are simple examples with step-by-step instructions to configure and use this driver in a selection of use cases. Note that a QSG can be compiled as a standalone application or be added to the user application. Quick Start Guide for the AST driver Asynchronous Timer (AST) - Example 1 Calendar Mode Asynchronous Timer (AST) - Example 2 Alarm Wakeup 9.1. Quick Start Guide for the AST driver This is the quick start guide for the SAM4L Asynchronous Timer (AST) Driver, with step-by-step instructions on how to configure and use the driver for a specific use case.the code examples can be copied into the main application loop or any other function that will need to control the AST module. 9.1.1. Use Cases AST Basic Usage 9.1.2. AST Basic Usage This use case will demonstrate how to initialize the AST module to calendar or counter mode. 9.1.3. Setup Steps 9.1.3.1. Prerequisites This module requires the following service: 9.1.3.2. Setup Code System Clock Management (sysclock) Add this to the main loop or a setup function: osc_priv_enable_osc32(); 9.1.3.3. Workflow 1. Enable the AST module: ast_enable(ast); 2. Initialize the AST to counter mode: * struct ast_config ast_conf; * ast_conf.mode = AST_COUNTER_MODE; * ast_conf.osc_type = AST_OSC_32KHZ; * ast_conf.psel = AST_PSEL_32KHZ_1HZ; * ast_conf.counter = 0; * ast_set_config(ast, &ast_conf); * 3. Or initialize the AST to calendar mode: * struct ast_calendar calendar; * struct ast_config ast_conf; 26

9.1.4. Usage Steps 9.1.4.1. Usage Code * calendar.field.sec = 0; * calendar.field.min = 15; * calendar.field.hour = 12; * calendar.field.day = 20; * calendar.field.month = 9; * calendar.field.year = 12; * struct ast_config ast_conf; * ast_conf.mode = AST_CALENDAR_MODE; * ast_conf.osc_type = AST_OSC_32KHZ; * ast_conf.psel = AST_PSEL_32KHZ_1HZ; * ast_conf.calendar = calendar; * ast_set_config(ast, &ast_conf) Note: We need to set the clock after prescaler to 1Hz. We can get the calendar value by: calendar = ast_read_calendar_value(ast); Or we can get the counter value by: ast_counter = ast_read_counter_value(ast); We can set the alarm interrupt by: * ast_write_alarm0_value(ast, calendar.field + 1); * ast_set_callback(ast, ast_interrupt_alarm, ast_alarm_callback, * AST_ALARM_IRQn, 1); And we can set the periodic interrupt by: * ast_write_periodic0_value(ast, AST_PSEL_32KHZ_1HZ - 4); * ast_set_callback(ast, ast_interrupt_per, ast_per_callback, * AST_PER_IRQn, 1); 9.2. Asynchronous Timer (AST) - Example 1 Calendar Mode 9.2.1. Purpose This example demonstrates how to use the AST driver with the 32kHz oscillator crystal. 9.2.2. Requirements This example can be used with SAM4L evaluation kits. 9.2.3. Description Upon startup, the program uses the USART driver to display a real time counter incremented every second. The display is triggered by the interrupt controller module. 9.2.4. Main Files ast.c: Asynchronous Timer driver 27

ast.h: Asynchronous Timer driver header file ast_example1.c: Asynchronous Timer example application 9.2.5. Compilation Information This software is written for GNU GCC and IAR Embedded Workbench for Atmel. Other compilers may or may not work. 9.2.6. Usage 1. Build the program and download it into the evaluation board. 2. On the computer, open, and configure a terminal application (e.g., HyperTerminal on Microsoft Windows ) with these settings: 115200 baud 8 bits of data No parity 1 stop bit No flow control 3. Start the application. 4. In the terminal window, the following text should appear: * -- AST Example 1 in Calendar Mode -- * -- xxxxxx-xx * -- Compiled: xxx xx xxxx xx:xx:xx -- * * Config AST with 32 KHz oscillator. * * Calendar: Year:XX Month:XX Day:XX, XXhXXmXXs 5. Approximately every second the time should increment. 9.3. Asynchronous Timer (AST) - Example 2 Alarm Wakeup 9.3.1. Purpose This example demonstrates how to use the AST driver with the 32kHz oscillator crystal and to also setup an alarm to wake-up the device from its low power modes. 9.3.2. Requirements This example can be used with SAM4L evaluation kits. 9.3.3. Description Upon startup, the program uses the USART driver to display a menu that lets the user select the low power mode from which the device will wake-up when the AST Alarm triggers. 9.3.4. Main Files ast.c: Asynchronous Timer driver ast.h: Asynchronous Timer driver header file ast_example2.c: Asynchronous Timer example application using AST wakeup and BPM sleep function. 28

9.3.5. Compilation Information 9.3.6. Usage This software is written for GNU GCC and IAR Embedded Workbench for Atmel. Other compilers may or may not work. 1. Build the program and download it into the evaluation board. 2. On the computer, open, and configure a terminal application (e.g., HyperTerminal on Microsoft Windows ) with these settings: 115200 baud 8 bits of data No parity 1 stop bit No flow control 3. Start the application. 4. In the terminal window, the following text should appear: * -- -- AST Example 2 in Counter Mode -- * -- xxxxxx-xx * -- Compiled: xxx xx xxxx xx:xx:xx -- * * Config AST with 32kHz oscillator. * Use alarm0 to wakeup from low power mode. * * Menu : * -- Select low power mode: * 1: Sleep mode 0 * 2: Sleep mode 1 * 3: Sleep mode 2 * 4: Sleep mode 3 * 5: Wait mode * 6: Retention mode * 7: Backup mode 29

10. Document Revision History Doc. Rev. Date Comments 42283B 07/2015 Updated title of application note and added list of supported devices 42283A 05/2014 Initial document release 30

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, and others are registered trademarks of ARM Ltd. Windows is a registered trademark of Microsoft Corporation in U.S. and or other countries. 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 property 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 LIMITATION, 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 accuracy 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 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 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 of nuclear facilities and weapons systems. Atmel products are not designed nor intended for use in military or aerospace applications or environments unless specifically designated by Atmel as military-grade. Atmel products are not designed nor intended for use in automotive applications unless specifically designated by Atmel as automotive-grade.