MPAE-15126 Uploaded images, modified Readme and meatdata files

master
Amey Panse 2023-01-06 10:00:49 +05:30
rodzic 11ddb53bf0
commit 3d62ef1866
48 zmienionych plików z 4887 dodań i 36 usunięć

Wyświetl plik

@ -4,13 +4,13 @@
"content": {
"metaDataVersion": "1.3.0",
"name": "com.microchip.mcu8.mplabx.project.avr128db48-using-crystal-osc-as-clock-for-rtc-in-sleep-mplab",
"version": " ",
"displayName": "",
"version": "1.0.0",
"displayName": "Configure external 32.768kHz crystal as a RTC clock source in sleep using AVR128DB48",
"projectName": "avr128db48-using-crystal-osc-as-clock-for-rtc-in-sleep-mplab",
"shortDescription": "This code example demonstrates usage of AVR128DB48 microcontroller for configuring external crystal as clock source in sleep. In this code example, external crystal as peripheral clock source in sleep is exemplified using Real-Time Counter (RTC).",
"ide": {
"name": "MPLAB X",
"semverRange": ">=6.0.0"
"semverRange": ">=6.05.0"
},
"compiler": [
{
@ -19,12 +19,12 @@
}
],
"dfp": {
"name": "",
"semverRange": ""
"name": "AVR-Dx_DFP",
"semverRange": "^2.3.272"
},
"configurator": {
"name": "",
"semverRange": ""
"name": "MCC",
"semverRange": ">=5.2.2"
},
"device": {
"metaDataVersion": "1.0.0",
@ -37,8 +37,8 @@
}
},
"author": "Amey Panse",
"peripherals": [],
"keywords": [],
"peripherals": ["RTC", "SLPCTRL"],
"keywords": ["Deep Sleep", "Sleep Controller", "32.768 kHz Crystal Oscillator", "Crystal Oscillator"],
"additionalData": {
"longDescription": {
"metaDataVersion": "1.0.0",

195
README.md
Wyświetl plik

@ -2,44 +2,185 @@
[![MCHP](images/microchip.png)](https://www.microchip.com)
# Update the title for avr128db48-using-crystal-osc-as-clock-for-rtc-in-sleep-mplab here
# Configure external 32.768kHz crystal as a RTC clock source in sleep using AVR128DB48
<!-- This is where the introduction to the example goes, including mentioning the peripherals used -->
This code example demonstrates how to configure an external 32.768kHz crystal as a clock source to the Real-Time Counter (RTC) module of AVR microcontrollers. In this code example, RTC module of AVR128DB48 microcontroller is Supplied with an external 32.768kHz crystal clock source while the microcontroller is in sleep mode (power down mode).
## Related Documentation
## Introduction
<!-- Any information about an application note or tech brief can be linked here. Use unbreakable links!
In addition a link to the device family landing page and relevant peripheral pages as well:
- [AN3381 - Brushless DC Fan Speed Control Using Temperature Input and Tachometer Feedback](https://microchip.com/00003381/)
- [PIC18F-Q10 Family Product Page](https://www.microchip.com/design-centers/8-bit/pic-mcus/device-selection/pic18f-q10-product-family) -->
In many of real world applications which are battery operated, the microcontroller is dependent on methodical sleep mode techniques that shuts down some or all peripheral operations to reduce power consumption, enabling it to work for longer time on limited resources. The AVR128DB48 microcontrollers of the AVR® DB family of microcontrollers family uses the latest technologies from Microchip with a flexible and low-power architecture. The AVR128DB48 simplified set of features. It includes Real-Time Counter (RTC), which offers two timing functionalities in form of RTC and Periodic Interrupt Timer (PIT). The PIT functionality uses the same clock source as RTC but can be enabled independently. The objective of this example is to showcase the working of RTC in sleep mode (power down mode) using external crystal as clock source. It will show the power consumption by the device in sleep mode and how external crystal as clock is accurate and consumes less power than the internal HF oscillator.
## Software Used
## Useful Links
<!-- All software used in this example must be listed here. Use unbreakable links!
- MPLAB® X IDE 5.30 or newer [(microchip.com/mplab/mplab-x-ide)](http://www.microchip.com/mplab/mplab-x-ide)
- MPLAB® XC8 2.10 or a newer compiler [(microchip.com/mplab/compilers)](http://www.microchip.com/mplab/compilers)
- MPLAB® Code Configurator (MCC) 3.95.0 or newer [(microchip.com/mplab/mplab-code-configurator)](https://www.microchip.com/mplab/mplab-code-configurator)
- MPLAB® Code Configurator (MCC) Device Libraries PIC10 / PIC12 / PIC16 / PIC18 MCUs [(microchip.com/mplab/mplab-code-configurator)](https://www.microchip.com/mplab/mplab-code-configurator)
- Microchip PIC18F-Q Series Device Support (1.4.109) or newer [(packs.download.microchip.com/)](https://packs.download.microchip.com/) -->
- [Microchip University Courses](https://mu.microchip.com/page/all-courses)
- [AVR128DB48 Product Page](https://www.microchip.com/en-us/product/AVR128DB48)
- MPLAB® X IDE 6.0.0 or newer [(MPLAB® X IDE 6.0)](https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-x-ide?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_MMTCha_MPAE_Examples&utm_content=avr128db48-using-crystal-osc-as-clock-for-rtc-in-sleep-mplab-github)
- MPLAB® XC8 2.40.0 or newer compiler [(MPLAB® XC8 2.40)](https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-xc-compilers?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_MMTCha_MPAE_Examples&utm_content=avr128db48-using-crystal-osc-as-clock-for-rtc-in-sleep-mplab-github)
## Description
## Hardware Used
The objective of this code example is to enable low-power power-down mode in the microcontroller and configure the RTC module to operate in periodic interrupt timer (PIT) mode using an external 32.768kHz crystal oscillator, and completely shut down the microcontroller system clock and peripherals. Thereby, the microcontroller wakes up from sleep to a PIT periodic interrupt. This implementation helps to minimize the microcontroller average power consumption. For the demonstration purpose the switch event is used to switch to external crystal oscillator as the clock source and let the microcontroller enter sleep mode. After the RTC period elapse, the PIT interrupt occurs and the clock source for the microcontroller switches back to internal HF oscillator and is in active mode.
<!-- All hardware used in this example must be listed here. Use unbreakable links!
- PIC18F47Q10 Curiosity Nano [(DM182029)](https://www.microchip.com/Developmenttools/ProductDetails/DM182029)
- Curiosity Nano Base for Click boards™ [(AC164162)](https://www.microchip.com/Developmenttools/ProductDetails/AC164162)
- POT Click board™ [(MIKROE-3402)](https://www.mikroe.com/pot-click) -->
<p align="center">
<img width=600 height=auto src="images/blk_diag.png">
<br>Figure 1: System Block Diagram<br>
</p>
## Setup
## Software Tools
Microchips free IDE, compiler and graphical code generators are used throughout the application firmware development. Following are the tools used for this demo application:
<!-- Explain how to connect hardware and set up software. Depending on complexity, step-by-step instructions and/or tables and/or images can be used -->
* MPLAB® X IDE [v6.05.0 or newer](https://www.microchip.com/mplab/mplab-x-ide)
* XC8 Compiler [v2.40.0 or newer](https://www.microchip.com/mplab/compilers)
* MPLAB Data Visualizer [v1.3.1160]( https://www.microchip.com/en-us/tools-resources/debug/mplab-data-visualizer)
* Microchip AVR-Dx_DFP Series Device Support Pack [2.3.272 or newer](https://packs.download.microchip.com/#collapse-Microchip-AVR-Dx-DFP-pdsc)
* MPLAB® Code Configurator [v5.2.2 or newer](https://www.microchip.com/mplab/mplab-code-configurator)
* RTC 4.2.4
* SLPCTRL 3.0.4
## Operation
***Note: For running the demo, the installed tool versions should be the same or later. This example is not tested with the previous versions.***
<!-- Explain how to operate the example. Depending on complexity, step-by-step instructions and/or tables and/or images can be used -->
## Hardware Tools
## Summary
* [AVR128DB48 Curiosity Nano](https://www.microchip.com/en-us/development-tool/EV35L43A)
* [Power Debugger](https://www.microchip.com/en-us/development-tool/atpowerdebugger)
<!-- Summarize what the example has shown -->
## Application Firmware
The example firmware uses RTC peripheral to showcase the working of microcontroller in sleep mode by using 32.768kHz external crystal oscillator as its clock source. During the active period the system works of the 4MHz internal oscillator. The sleep control system peripheral is configured in power down mode with the performance mode being set to auto. Here, in Power-Down sleep mode, only the Periodic Interrupt Timer (PIT) functionality is available. The PIT uses the same clock source as RTC functionality. The RTC period is configured for 30s. If a switch press event is detected, the RTC peripheral gets enabled, and the system enters the power down mode. The RTC flag is monitored to check if the RTC period is completed via interrupt service routine. After RTC period of 30s is completed, the device wakes up from sleep. As soon as it wakes up, the RTC peripheral gets disabled and the MCU continues to stay in active mode until a new switch press event is detected.
<p align="center">
<img width=600 height=auto src="images/flowchart.png">
<br>Figure 2: Application Firmware Flowchart<br>
</p>
## Appendix
MCC – MPLAB® Code Configurator is a graphical programming environment that generates seamless, easy to understand C code to give a head start to the project, saving the designers time to initialize and configure all the modules, and to go through the datasheets. Using an instructive interface, it enables and configures all peripherals and functions specific to the application requirements.
**Start by creating a new Project and open MCC**
* Open MPLAB X IDE
* Go to File > New Project
* Select Microchip Embedded > Standalone Project
* Enter the device name. In this case, select AVR128DB48 device
* Name the project
* Launch MCC tool by navigating to **“Tools -> Embedded -> MPLAB Code Configurator v4: Open/Close”**. Alternatively, click the MCC icon to launch the MCC tool.
## System configuration
* **System Clock**
Open **Clock Control** setup present under **System** dropdown menu in **Project Resources** tab.
* Clock Selection : **Internal high-frequency Osc**
* Internal Osc. Freq. : **1-32MHz internal Osc**
* Enable System Clock Out
* Enable Run Standby 32.768kHz crystal oscillator
* Enable Low Power Mode
The following figure shows the system configuration setting in MCC tool.
<p align="center">
<img width=600 height=auto src="images/system_config.png">
<br>Figure 3: System Configuration<br>
</p>
* **SLPCTRL**
Open **SLPCTRL** setup present under **System** dropdown menu in **Project Resources** tab.
* Enable Sleep
* Sleep Mode : **PDOWN**
* Performance Mode : **AUTO**
<p align="center">
<img width=600 height=auto src="images/sleep_config.png">
<br>Figure 4: Sleep Control Configuration<br>
</p>
* **RTC**
Open **RTC** setup present under **Driver** dropdown menu in **Project Resources** tab.
* Enable RTC
* RTC Clock Source : **32.768kHz from XOSC32K**
* Pre-scaling Factor : **RTC Clock/32768**
* Compare (s) : **30**
* Enable Compare Match Interrupt
<p align="center">
<img width=600 height=auto src="images/rtc_config.png">
<br>Figure 5: RTC Configuration<br>
</p>
## Pin Mapping
The following images informs about the pin usage in the project.
<p align="center">
<img width=600 height=auto src="images/pin_config.png">
<br>Figure 6: Pin Mapping (List View)<br>
</p>
<p align="center">
<img width=600 height=auto src="images/pin_config1.png">
<br>Figure 7: Pin Mapping (Navigation View)<br>
</p>
## Hardware Setup
The following figure consists of AVR128DB48 Curiosity Nano Evaluation kit along with Power Debugger. Connect the power debugger to the MCU using connecting cables.
<p align="center">
<img width=600 height=auto src="images/setup.png">
<br>Figure 8: Hardware Setup<br>
</p>
## Data Visualizer
* The Data Gateway Interface is available on the Microchip evaluation kits with an embedded programmer and debugger (EDBG) . These evaluation kits can communicate with the data visualizer through DGI. The figure below shows the DGI control panel of data visualizer. All detected DGI devices are listed in the drop-down list with the kit name and serial number. Using the **Connect** button will connect to the selected DGI device and query for available interfaces.
<p align="center">
<img width=600 height=auto src="images/pwr_debug1.png">
<br>Figure 9: DGI Window<br>
</p>
* The available interfaces will be listed under Interfaces. To enable an interface, check the box next to the name. When an interface is enabled, the sources and sinks can be connected to other endpoints. The Gear button is used to configure the interface. See the interface-specific sections for an explanation of the configuration fields (In this case Power).
<p align="center">
<img width=600 height=auto src="images/pwr_debug2.png">
<br>Figure 10: Interfaces and Settings<br>
</p>
* To start polling data from the interfaces, click the **Start** button. The Reset MCU check box will cause the MCU to be held in Reset during start. The **Power Analysis** module is made specifically for analyzing power consumption over time.
<p align="center">
<img width=600 height=auto src="images/pwr_debug3.png">
<br>Figure 11: Power Analysis Window<br>
</p>
* Drag the Channel A Current and Channel A Voltage pins to Channel A Current and Voltage pins of power analysis window, and then measure the current consumption of the microcontroller.
<p align="center">
<img width=600 height=auto src="images/pwr_debug4.png">
<br>Figure 12: Power Analysis Channel Settings<br>
</p>
## Demo Operation
* Make the hardware connections as shown in the hardware setup. Power up the Curiosity Nano board using micro-USB cable.
* Download the firmware available from the GitHub code example page.
* Build the project using latest version of tools as mentioned in the Software Tools section and flash the generated file on the AVR128DB48 microcontroller.
* Observe the device current consumption on the Data Visualizer Window in the active mode.
<p align="center">
<img width=600 height=auto src="images/active_current.png">
<br>Figure 13: Active Current<br>
</p>
* Press the on-board switch. It will switch the clock source to external crystal.
<p align="center">
<img width=600 height=auto src="images/sleep_current.png">
<br>Figure 14: Sleep Current<br>
</p>
* Observe the device current consumption in the sleep mode.
* Wait for 30secs or any further switch press to determine the current consumption in active mode
## Conclusion
The power consumption of microcontroller plays an important role in the battery powered applications. Hence, it is important to keep the microcontroller power consumption as minimum as possible for longer battery life. This code example demonstrates low-power sleep implementation using RTC and external crystal oscillator of AVR128DB48 microcontroller, as the external crystal oscillator provides a better overall performance compared to the internal oscillator and also minimizes the overall power consumptions of the microcontroller.

Wyświetl plik

@ -0,0 +1,113 @@
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
# build
build: .build-post
.build-pre:
# Add your pre 'build' code here...
.build-post: .build-impl
# Add your post 'build' code here...
# clean
clean: .clean-post
.clean-pre:
# Add your pre 'clean' code here...
# WARNING: the IDE does not call this target since it takes a long time to
# simply run make. Instead, the IDE removes the configuration directories
# under build and dist directly without calling make.
# This target is left here so people can do a clean when running a clean
# outside the IDE.
.clean-post: .clean-impl
# Add your post 'clean' code here...
# clobber
clobber: .clobber-post
.clobber-pre:
# Add your pre 'clobber' code here...
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
# all
all: .all-post
.all-pre:
# Add your pre 'all' code here...
.all-post: .all-impl
# Add your post 'all' code here...
# help
help: .help-post
.help-pre:
# Add your pre 'help' code here...
.help-post: .help-impl
# Add your post 'help' code here...
# include project implementation makefile
include nbproject/Makefile-impl.mk
# include project make variables
include nbproject/Makefile-variables.mk

Wyświetl plik

@ -0,0 +1,82 @@
#include "application.h"
#include "mcc_generated_files/system/system.h"
#include "util/delay.h"
/**
* **********************************************************
* File Global variables
* **********************************************************
**/
volatile uint8_t switchPressed = CLEAR;
/*******************************************************************************
* void SwitchPress_InterruptHandler(void)
*
* API to handle switch press interrupt
*
*
* @param void
* @return void
******************************************************************************/
void SwitchPress_InterruptHandler(void)
{
switchPressed = SET;
}
/*******************************************************************************
* void RTC_Compare_InterruptHandler(void)
*
* API to handle RTC Compare interrupt handler, which will generate
* interrupt for every 30 sec
*
*
* @param void
* @return void
******************************************************************************/
void RTC_Compare_InterruptHandler(void)
{
LED_ON();
_delay_ms(10);
LED_OFF();
}
/*******************************************************************************
* void External_Crystal_init(void)
*
* API to initialize the external crystal 32.768KHz
*
*
* @param void
* @return void
******************************************************************************/
void External_Crystal_init(void)
{
uint8_t buffer;
/* Initialize 32.768kHz Oscillator: */
/* Disable oscillator: */
buffer = CLKCTRL.XOSC32KCTRLA;
buffer &= ~CLKCTRL_ENABLE_bm;
/* Writing to protected register */
ccp_write_io((void*)&CLKCTRL.XOSC32KCTRLA, buffer);
while(CLKCTRL.MCLKSTATUS & CLKCTRL_XOSC32KS_bm)
{
; /* Wait until XOSC32KS becomes 0 */
}
/* SEL = 0 (Use External Crystal): */
buffer = CLKCTRL.XOSC32KCTRLA;
buffer &= ~CLKCTRL_SEL_bm;
/* Writing to protected register */
ccp_write_io((void*)&CLKCTRL.XOSC32KCTRLA, buffer);
/* Enable oscillator: */
buffer = CLKCTRL.XOSC32KCTRLA;
buffer |= CLKCTRL_ENABLE_bm;
/* Writing to protected register */
ccp_write_io((void*)&CLKCTRL.XOSC32KCTRLA, buffer);
}

Wyświetl plik

@ -0,0 +1,77 @@
/* Microchip Technology Inc. and its subsidiaries. You may use this software
* and any derivatives exclusively with Microchip products.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
* PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
* WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
*
* IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
* INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
* WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
* BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
* FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS
* IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF
* ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
* TERMS.
*/
/*
* File:
* Author:
* Comments:
* Revision history:
*/
// This is a guard condition so that contents of this file are not included
// more than once.
#ifndef APPLICATION_H
#define APPLICATION_H
#include <xc.h> // include processor files - each processor file is guarded.
/**
* **********************************************************
* Macros functions
* **********************************************************
**/
#define LED_OFF() Led_SetHigh();
#define LED_ON() Led_SetLow();
/**
* **********************************************************
* Macros definitions
* **********************************************************
**/
#define SET 5
#define CLEAR 0
#define RTC_COUNT 10
/**
* **********************************************************
* Function declarations
* **********************************************************
**/
void SwitchPress_InterruptHandler(void);
void RTC_Compare_InterruptHandler(void);
void External_Crystal_init(void);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// TODO If C++ is being used, regular C code needs function names to have C
// linkage so the functions can be used by the c code.
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* XC_HEADER_TEMPLATE_H */

Wyświetl plik

@ -0,0 +1,77 @@
/*
* MAIN Generated Driver File
*
* @file main.c
*
* @defgroup main MAIN
*
* @brief This is the generated driver implementation file for the MAIN driver.
*
* @version MAIN Driver Version 1.0.0
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#include "mcc_generated_files/system/system.h"
#include "application.h"
#include "util/delay.h"
#include "avr/sleep.h"
extern volatile uint8_t switchPressed;
/*
Main application
*/
int main(void)
{
SYSTEM_Initialize();
/*Disable RTC Peripheral*/
RTC_Stop();
/*External crystal 32.768KHz is initialized*/
External_Crystal_init();
/*Switch Interrupt Handler*/
PB2_SetInterruptHandler(SwitchPress_InterruptHandler);
/*RTC Compare Interrupt Handler*/
RTC_SetCMPIsrCallback(RTC_Compare_InterruptHandler);
while(1)
{
if(switchPressed == SET)
{
/*Enable RTC peripheral*/
RTC_Start();
/*Enter sleep mode*/
sleep_cpu();
/*Clear switch pressed flag*/
switchPressed = CLEAR;
/*Disable RTC peripheral*/
RTC_Stop();
}
}
}

Wyświetl plik

@ -0,0 +1,80 @@
/**
@Company
Microchip Technology Inc.
@Description
This Source file provides APIs.
Generation Information :
Driver Version : 1.0.0
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef CPU_CCP_H
#define CPU_CCP_H
#include "../system/utils/compiler.h"
#include "../system/protected_io.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief Write to a CCP-protected 8-bit I/O register
*
* \param addr Address of the I/O register
* \param value Value to be written
*
* \note Using IAR Embedded workbench, the choice of memory model has an impact
* on calling convention. The memory model is not visible to the
* preprocessor, so it must be defined in the Assembler preprocessor directives.
*/
static inline void ccp_write_io(void *addr, uint8_t value)
{
protected_write_io(addr, CCP_IOREG_gc, value);
}
/** @} */
/**
* \brief Write to CCP-protected 8-bit SPM register
*
* \param addr Address of the SPM register
* \param value Value to be written
*
* \note Using IAR Embedded workbench, the choice of memory model has an impact
* on calling convention. The memory model is not visible to the
* preprocessor, so it must be defined in the Assembler preprocessor directives.
*/
static inline void ccp_write_spm(void *addr, uint8_t value)
{
protected_write_io(addr, CCP_SPM_gc, value);
}
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* CPU_CCP_H */

Wyświetl plik

@ -0,0 +1,69 @@
/**
* CLKCTRL Generated Driver API Header File
*
* @file clkctrl.h
*
* @defgroup clkctrl CLKCTRL
*
* @brief This header file provides APIs for the CLKCTRL driver.
*
* @version CLKCTRL Driver Version 1.0.2
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef CLOCK_H
#define CLOCK_H
#ifndef F_CPU
#define F_CPU 32768UL
#endif
#include "ccp.h"
#define CLKCTRL_TIMEBASE_VALUE ((uint8_t)ceil(F_CPU * 0.000001))
/**
* @ingroup clkctrl
* @brief Initialize CLKCTRL module
* @param none
* @return none
*/
void CLOCK_Initialize(void);
/**
* @ingroup clkctrl
* @brief Enable Clock Failure Detection on main clock
* @param CLKCTRL_CFDSRC_t cfd_source - main clock source for CFD
* @return none
*/
void CFD_Enable(CLKCTRL_CFDSRC_t cfd_source);
/**
* @ingroup clkctrl
* @brief Disable Clock Failure Detection on main clock
* @param none
* @return none
*/
void CFD_Disable();
#endif // CLOCK_H

Wyświetl plik

@ -0,0 +1,57 @@
/**
* Interrupt Manager Generated Driver API Header File.
*
* @file interrupt.h
*
* @defgroup interrupt INTERRUPT
*
* @brief This file contains the API prototype for the Interrupt Manager.
*
* @version Interrupt Manager Driver Version 1.0.0
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef INTERRUPT_H
#define INTERRUPT_H
#include "../system/utils/compiler.h"
#include "ccp.h"
#include "../system/utils/atomic.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @ingroup interrupt
* @brief Initializes the Interrupt module.
* @retval 0 - Initialization is successful.
*/
int8_t CPUINT_Initialize();
#ifdef __cplusplus
}
#endif
#endif /* INTERRUPT_H */

Wyświetl plik

@ -0,0 +1,165 @@
/**
* Generated Pins header File
*
* @file pins.h
*
* @defgroup pinsdriver Pins Driver
*
* @brief This is generated driver header for pins.
* This header file provides APIs for all pins selected in the GUI.
*
* @version Driver Version 1.0.1
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef PINS_H_INCLUDED
#define PINS_H_INCLUDED
#include <avr/io.h>
#include "./port.h"
//get/set Switch aliases
#define Switch_SetHigh() do { PORTB_OUTSET = 0x4; } while(0)
#define Switch_SetLow() do { PORTB_OUTCLR = 0x4; } while(0)
#define Switch_Toggle() do { PORTB_OUTTGL = 0x4; } while(0)
#define Switch_GetValue() (VPORTB.IN & (0x1 << 2))
#define Switch_SetDigitalInput() do { PORTB_DIRCLR = 0x4; } while(0)
#define Switch_SetDigitalOutput() do { PORTB_DIRSET = 0x4; } while(0)
#define Switch_SetPullUp() do { PORTB_PIN2CTRL |= PORT_PULLUPEN_bm; } while(0)
#define Switch_ResetPullUp() do { PORTB_PIN2CTRL &= ~PORT_PULLUPEN_bm; } while(0)
#define Switch_SetInverted() do { PORTB_PIN2CTRL |= PORT_INVEN_bm; } while(0)
#define Switch_ResetInverted() do { PORTB_PIN2CTRL &= ~PORT_INVEN_bm; } while(0)
#define Switch_DisableInterruptOnChange() do { PORTB.PIN2CTRL = (PORTB.PIN2CTRL & ~PORT_ISC_gm) | 0x0 ; } while(0)
#define Switch_EnableInterruptForBothEdges() do { PORTB.PIN2CTRL = (PORTB.PIN2CTRL & ~PORT_ISC_gm) | 0x1 ; } while(0)
#define Switch_EnableInterruptForRisingEdge() do { PORTB.PIN2CTRL = (PORTB.PIN2CTRL & ~PORT_ISC_gm) | 0x2 ; } while(0)
#define Switch_EnableInterruptForFallingEdge() do { PORTB.PIN2CTRL = (PORTB.PIN2CTRL & ~PORT_ISC_gm) | 0x3 ; } while(0)
#define Switch_DisableDigitalInputBuffer() do { PORTB.PIN2CTRL = (PORTB.PIN2CTRL & ~PORT_ISC_gm) | 0x4 ; } while(0)
#define Switch_EnableInterruptForLowLevelSensing() do { PORTB.PIN2CTRL = (PORTB.PIN2CTRL & ~PORT_ISC_gm) | 0x5 ; } while(0)
//get/set IO_PF6 aliases
#define IO_PF6_SetHigh() do { PORTF_OUTSET = 0x40; } while(0)
#define IO_PF6_SetLow() do { PORTF_OUTCLR = 0x40; } while(0)
#define IO_PF6_Toggle() do { PORTF_OUTTGL = 0x40; } while(0)
#define IO_PF6_GetValue() (VPORTF.IN & (0x1 << 6))
#define IO_PF6_SetDigitalInput() do { PORTF_DIRCLR = 0x40; } while(0)
#define IO_PF6_SetDigitalOutput() do { PORTF_DIRSET = 0x40; } while(0)
#define IO_PF6_SetPullUp() do { PORTF_PIN6CTRL |= PORT_PULLUPEN_bm; } while(0)
#define IO_PF6_ResetPullUp() do { PORTF_PIN6CTRL &= ~PORT_PULLUPEN_bm; } while(0)
#define IO_PF6_SetInverted() do { PORTF_PIN6CTRL |= PORT_INVEN_bm; } while(0)
#define IO_PF6_ResetInverted() do { PORTF_PIN6CTRL &= ~PORT_INVEN_bm; } while(0)
#define IO_PF6_DisableInterruptOnChange() do { PORTF.PIN6CTRL = (PORTF.PIN6CTRL & ~PORT_ISC_gm) | 0x0 ; } while(0)
#define IO_PF6_EnableInterruptForBothEdges() do { PORTF.PIN6CTRL = (PORTF.PIN6CTRL & ~PORT_ISC_gm) | 0x1 ; } while(0)
#define IO_PF6_EnableInterruptForRisingEdge() do { PORTF.PIN6CTRL = (PORTF.PIN6CTRL & ~PORT_ISC_gm) | 0x2 ; } while(0)
#define IO_PF6_EnableInterruptForFallingEdge() do { PORTF.PIN6CTRL = (PORTF.PIN6CTRL & ~PORT_ISC_gm) | 0x3 ; } while(0)
#define IO_PF6_DisableDigitalInputBuffer() do { PORTF.PIN6CTRL = (PORTF.PIN6CTRL & ~PORT_ISC_gm) | 0x4 ; } while(0)
#define IO_PF6_EnableInterruptForLowLevelSensing() do { PORTF.PIN6CTRL = (PORTF.PIN6CTRL & ~PORT_ISC_gm) | 0x5 ; } while(0)
//get/set Led aliases
#define Led_SetHigh() do { PORTB_OUTSET = 0x8; } while(0)
#define Led_SetLow() do { PORTB_OUTCLR = 0x8; } while(0)
#define Led_Toggle() do { PORTB_OUTTGL = 0x8; } while(0)
#define Led_GetValue() (VPORTB.IN & (0x1 << 3))
#define Led_SetDigitalInput() do { PORTB_DIRCLR = 0x8; } while(0)
#define Led_SetDigitalOutput() do { PORTB_DIRSET = 0x8; } while(0)
#define Led_SetPullUp() do { PORTB_PIN3CTRL |= PORT_PULLUPEN_bm; } while(0)
#define Led_ResetPullUp() do { PORTB_PIN3CTRL &= ~PORT_PULLUPEN_bm; } while(0)
#define Led_SetInverted() do { PORTB_PIN3CTRL |= PORT_INVEN_bm; } while(0)
#define Led_ResetInverted() do { PORTB_PIN3CTRL &= ~PORT_INVEN_bm; } while(0)
#define Led_DisableInterruptOnChange() do { PORTB.PIN3CTRL = (PORTB.PIN3CTRL & ~PORT_ISC_gm) | 0x0 ; } while(0)
#define Led_EnableInterruptForBothEdges() do { PORTB.PIN3CTRL = (PORTB.PIN3CTRL & ~PORT_ISC_gm) | 0x1 ; } while(0)
#define Led_EnableInterruptForRisingEdge() do { PORTB.PIN3CTRL = (PORTB.PIN3CTRL & ~PORT_ISC_gm) | 0x2 ; } while(0)
#define Led_EnableInterruptForFallingEdge() do { PORTB.PIN3CTRL = (PORTB.PIN3CTRL & ~PORT_ISC_gm) | 0x3 ; } while(0)
#define Led_DisableDigitalInputBuffer() do { PORTB.PIN3CTRL = (PORTB.PIN3CTRL & ~PORT_ISC_gm) | 0x4 ; } while(0)
#define Led_EnableInterruptForLowLevelSensing() do { PORTB.PIN3CTRL = (PORTB.PIN3CTRL & ~PORT_ISC_gm) | 0x5 ; } while(0)
/**
* @ingroup pinsdriver
* @brief GPIO and peripheral I/O initialization
* @param none
* @return none
*/
void PIN_MANAGER_Initialize();
/**
* @ingroup pinsdriver
* @brief Default Interrupt Handler for PB2 pin.
* This is a predefined interrupt handler to be used together with the PB2_SetInterruptHandler() method.
* This handler is called every time the PB2 ISR is executed.
* @pre PIN_MANAGER_Initialize() has been called at least once
* @param none
* @return none
*/
void PB2_DefaultInterruptHandler(void);
/**
* @ingroup pinsdriver
* @brief Interrupt Handler Setter for PB2 pin input-sense-config functionality.
* Allows selecting an interrupt handler for PB2 at application runtime
* @pre PIN_MANAGER_Initialize() has been called at least once
* @param InterruptHandler function pointer.
* @return none
*/
void PB2_SetInterruptHandler(void (* interruptHandler)(void)) ;
/**
* @ingroup pinsdriver
* @brief Default Interrupt Handler for PF6 pin.
* This is a predefined interrupt handler to be used together with the PF6_SetInterruptHandler() method.
* This handler is called every time the PF6 ISR is executed.
* @pre PIN_MANAGER_Initialize() has been called at least once
* @param none
* @return none
*/
void PF6_DefaultInterruptHandler(void);
/**
* @ingroup pinsdriver
* @brief Interrupt Handler Setter for PF6 pin input-sense-config functionality.
* Allows selecting an interrupt handler for PF6 at application runtime
* @pre PIN_MANAGER_Initialize() has been called at least once
* @param InterruptHandler function pointer.
* @return none
*/
void PF6_SetInterruptHandler(void (* interruptHandler)(void)) ;
/**
* @ingroup pinsdriver
* @brief Default Interrupt Handler for PB3 pin.
* This is a predefined interrupt handler to be used together with the PB3_SetInterruptHandler() method.
* This handler is called every time the PB3 ISR is executed.
* @pre PIN_MANAGER_Initialize() has been called at least once
* @param none
* @return none
*/
void PB3_DefaultInterruptHandler(void);
/**
* @ingroup pinsdriver
* @brief Interrupt Handler Setter for PB3 pin input-sense-config functionality.
* Allows selecting an interrupt handler for PB3 at application runtime
* @pre PIN_MANAGER_Initialize() has been called at least once
* @param InterruptHandler function pointer.
* @return none
*/
void PB3_SetInterruptHandler(void (* interruptHandler)(void)) ;
#endif /* PINS_H_INCLUDED */

Wyświetl plik

@ -0,0 +1,93 @@
/**
@Company
Microchip Technology Inc.
@Description
This Source file provides APIs.
Generation Information :
Driver Version : 1.0.0
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
/**
* \defgroup doc_driver_system_protected_io Protected IO
* \ingroup doc_driver_system
*
* \section doc_driver_protected_io_rev Revision History
* - v0.0.0.1 Initial Commit
*
*@{
*/
#ifndef PROTECTED_IO_H
#define PROTECTED_IO_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__DOXYGEN__)
//! \name IAR Memory Model defines.
//@{
/**
* \def CONFIG_MEMORY_MODEL_TINY
* \brief Configuration symbol to enable 8 bit pointers.
*
*/
#define CONFIG_MEMORY_MODEL_TINY
/**
* \def CONFIG_MEMORY_MODEL_SMALL
* \brief Configuration symbol to enable 16 bit pointers.
* \note If no memory model is defined, SMALL is default.
*
*/
#define CONFIG_MEMORY_MODEL_SMALL
/**
* \def CONFIG_MEMORY_MODEL_LARGE
* \brief Configuration symbol to enable 24 bit pointers.
*
*/
#define CONFIG_MEMORY_MODEL_LARGE
//@}
#endif
/**
* \brief Write to am 8-bit I/O register protected by CCP or a protection bit
*
* \param addr Address of the I/O register
* \param magic CCP magic value or Mask for protection bit
* \param value Value to be written
*
* \note Using IAR Embedded workbench, the choice of memory model has an impact
* on calling convention. The memory model is not visible to the
* preprocessor, so it must be defined in the Assembler preprocessor directives.
*/
extern void protected_write_io(void *addr, uint8_t magic, uint8_t value);
/** @} */
#endif /* PROTECTED_IO_H */

Wyświetl plik

@ -0,0 +1,99 @@
/**
* CLKCTRL Generated Driver File
*
* @file clkctrl.c
*
* @ingroup clkctrl
*
* @brief This file contains the driver code for CLKCTRL module.
*
* version CLKCTRL Driver Version 1.1.3
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#include "../clock.h"
void CLOCK_Initialize(void)
{
// Set the CLKCTRL module to the options selected in the user interface.
//CLKOUT enabled; CLKSEL Internal high-frequency oscillator;
ccp_write_io((void*)&(CLKCTRL.MCLKCTRLA),0x80);
//PDIV 2X; PEN disabled;
ccp_write_io((void*)&(CLKCTRL.MCLKCTRLB),0x0);
//EXTS disabled; OSC32KS disabled; OSCHFS disabled; PLLS disabled; SOSC disabled; XOSC32KS disabled;
ccp_write_io((void*)&(CLKCTRL.MCLKSTATUS),0x0);
//RUNSTDBY disabled;
ccp_write_io((void*)&(CLKCTRL.OSC32KCTRLA),0x0);
//AUTOTUNE disabled; FRQSEL 4 MHz system clock (default); RUNSTDBY disabled;
ccp_write_io((void*)&(CLKCTRL.OSCHFCTRLA),0xC);
//TUNE 0x0;
ccp_write_io((void*)&(CLKCTRL.OSCHFTUNE),0x0);
//MULFAC PLL is disabled; RUNSTDBY disabled; SOURCE OSCHF;
ccp_write_io((void*)&(CLKCTRL.PLLCTRLA),0x0);
//CSUT 1k cycles; ENABLE disabled; LPMODE enabled; RUNSTDBY enabled; SEL disabled;
ccp_write_io((void*)&(CLKCTRL.XOSC32KCTRLA),0x82);
//CFDEN disabled; CFDSRC CLKMAIN; CFDTST disabled;
ccp_write_io((void*)&(CLKCTRL.MCLKCTRLC),0x0);
//CFD disabled; INTTYPE INT;
ccp_write_io((void*)&(CLKCTRL.MCLKINTCTRL),0x0);
//CFD disabled;
ccp_write_io((void*)&(CLKCTRL.MCLKINTFLAGS),0x0);
//CSUTHF 256; ENABLE disabled; FRQRANGE 8M; RUNSTBY disabled; SELHF XTAL;
ccp_write_io((void*)&(CLKCTRL.XOSCHFCTRLA),0x0);
// System clock stability check by polling the status register.
while(!(CLKCTRL.MCLKSTATUS & CLKCTRL_OSCHFS_bm));
// System clock stability check by polling the PLL status.
}
void CFD_Enable(CLKCTRL_CFDSRC_t cfd_source)
{
/* Enable Clock Failure Detection on main clock */
ccp_write_io((uint8_t *) & CLKCTRL.MCLKCTRLC, cfd_source | CLKCTRL_CFDEN_bm);
}
void CFD_Disable()
{
/* Disable Clock Failure Detection on main clock */
ccp_write_io((uint8_t *) & CLKCTRL.MCLKCTRLC, CLKCTRL.MCLKCTRLC & ~CLKCTRL_CFDEN_bm);
}
/**
End of File
*/

Wyświetl plik

@ -0,0 +1,51 @@
/**
* CONFIGURATION BITS Generated Driver Source File
*
* @file config_bits.c
*
* @ingroup config_bitsdriver
*
* @brief This is the generated Device Configuration Bits file.
*
* @version Driver Version 1.0.1
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
/**
Section: Included Files
*/
#include <avr/io.h>
/**
* Configures Fuse bits
*/
FUSES =
{
.BODCFG = ACTIVE_DISABLE_gc | LVL_BODLEVEL0_gc | SAMPFREQ_32Hz_gc | SLEEP_DISABLE_gc,
.BOOTSIZE = 0x0,
.CODESIZE = 0x0,
.OSCCFG = CLKSEL_OSC32K_gc,
.SYSCFG0 = CRCSEL_CRC16_gc | CRCSRC_NOCRC_gc | RSTPINCFG_RST_gc,
.SYSCFG1 = MVSYSCFG_DUAL_gc | SUT_0MS_gc,
.WDTCFG = PERIOD_OFF_gc | WINDOW_OFF_gc,
};

Wyświetl plik

@ -0,0 +1,53 @@
/**
* Interrupt Manager Generated Driver File.
*
* @file interrupt.c
*
* @ingroup interrupt
*
* @brief This file contains the API implementation for the Interrupt Manager.
*
* @version Interrupt Manager Driver Version 1.0.0
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#include "../interrupt.h"
int8_t CPUINT_Initialize()
{
/* IVSEL and CVT are Configuration Change Protected */
//CVT disabled; IVSEL disabled; LVL0RR disabled;
ccp_write_io((void*)&(CPUINT.CTRLA),0x0);
//LVL0PRI 0;
CPUINT.LVL0PRI = 0x0;
//LVL1VEC 0;
CPUINT.LVL1VEC = 0x0;
ENABLE_INTERRUPTS();
return 0;
}

Wyświetl plik

@ -0,0 +1,219 @@
/**
* Generated Driver File
*
* @file pins.c
*
* @ingroup pinsdriver
*
* @brief This is generated driver implementation for pins.
* This file provides implementations for pin APIs for all pins selected in the GUI.
*
* @version Driver Version 1.0.1
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#include "../pins.h"
static void (*PB2_InterruptHandler)(void);
static void (*PF6_InterruptHandler)(void);
static void (*PB3_InterruptHandler)(void);
void PIN_MANAGER_Initialize()
{
/* DIR Registers Initialization */
PORTA.DIR = 0x0;
PORTB.DIR = 0x8;
PORTC.DIR = 0x0;
PORTD.DIR = 0x0;
PORTE.DIR = 0x0;
PORTF.DIR = 0x0;
/* OUT Registers Initialization */
PORTA.OUT = 0x0;
PORTB.OUT = 0x8;
PORTC.OUT = 0x0;
PORTD.OUT = 0x0;
PORTE.OUT = 0x0;
PORTF.OUT = 0x0;
/* PINxCTRL registers Initialization */
PORTA.PIN0CTRL = 0x0;
PORTA.PIN1CTRL = 0x0;
PORTA.PIN2CTRL = 0x0;
PORTA.PIN3CTRL = 0x0;
PORTA.PIN4CTRL = 0x0;
PORTA.PIN5CTRL = 0x0;
PORTA.PIN6CTRL = 0x0;
PORTA.PIN7CTRL = 0x0;
PORTB.PIN0CTRL = 0x0;
PORTB.PIN1CTRL = 0x0;
PORTB.PIN2CTRL = 0xA;
PORTB.PIN3CTRL = 0x0;
PORTB.PIN4CTRL = 0x0;
PORTB.PIN5CTRL = 0x0;
PORTB.PIN6CTRL = 0x0;
PORTB.PIN7CTRL = 0x0;
PORTC.PIN0CTRL = 0x0;
PORTC.PIN1CTRL = 0x0;
PORTC.PIN2CTRL = 0x0;
PORTC.PIN3CTRL = 0x0;
PORTC.PIN4CTRL = 0x0;
PORTC.PIN5CTRL = 0x0;
PORTC.PIN6CTRL = 0x0;
PORTC.PIN7CTRL = 0x0;
PORTD.PIN0CTRL = 0x0;
PORTD.PIN1CTRL = 0x0;
PORTD.PIN2CTRL = 0x0;
PORTD.PIN3CTRL = 0x0;
PORTD.PIN4CTRL = 0x0;
PORTD.PIN5CTRL = 0x0;
PORTD.PIN6CTRL = 0x0;
PORTD.PIN7CTRL = 0x0;
PORTE.PIN0CTRL = 0x0;
PORTE.PIN1CTRL = 0x0;
PORTE.PIN2CTRL = 0x0;
PORTE.PIN3CTRL = 0x0;
PORTE.PIN4CTRL = 0x0;
PORTE.PIN5CTRL = 0x0;
PORTE.PIN6CTRL = 0x0;
PORTE.PIN7CTRL = 0x0;
PORTF.PIN0CTRL = 0x0;
PORTF.PIN1CTRL = 0x0;
PORTF.PIN2CTRL = 0x0;
PORTF.PIN3CTRL = 0x0;
PORTF.PIN4CTRL = 0x0;
PORTF.PIN5CTRL = 0x0;
PORTF.PIN6CTRL = 0x0;
PORTF.PIN7CTRL = 0x0;
/* PORTMUX Initialization */
PORTMUX.ACROUTEA = 0x0;
PORTMUX.CCLROUTEA = 0x0;
PORTMUX.EVSYSROUTEA = 0x0;
PORTMUX.SPIROUTEA = 0x0;
PORTMUX.TCAROUTEA = 0x0;
PORTMUX.TCBROUTEA = 0x0;
PORTMUX.TCDROUTEA = 0x0;
PORTMUX.TWIROUTEA = 0x0;
PORTMUX.USARTROUTEA = 0x0;
PORTMUX.USARTROUTEB = 0x0;
PORTMUX.ZCDROUTEA = 0x0;
// register default ISC callback functions at runtime; use these methods to register a custom function
PB2_SetInterruptHandler(PB2_DefaultInterruptHandler);
PF6_SetInterruptHandler(PF6_DefaultInterruptHandler);
PB3_SetInterruptHandler(PB3_DefaultInterruptHandler);
}
/**
Allows selecting an interrupt handler for PB2 at application runtime
*/
void PB2_SetInterruptHandler(void (* interruptHandler)(void))
{
PB2_InterruptHandler = interruptHandler;
}
void PB2_DefaultInterruptHandler(void)
{
// add your PB2 interrupt custom code
// or set custom function using PB2_SetInterruptHandler()
}
/**
Allows selecting an interrupt handler for PF6 at application runtime
*/
void PF6_SetInterruptHandler(void (* interruptHandler)(void))
{
PF6_InterruptHandler = interruptHandler;
}
void PF6_DefaultInterruptHandler(void)
{
// add your PF6 interrupt custom code
// or set custom function using PF6_SetInterruptHandler()
}
/**
Allows selecting an interrupt handler for PB3 at application runtime
*/
void PB3_SetInterruptHandler(void (* interruptHandler)(void))
{
PB3_InterruptHandler = interruptHandler;
}
void PB3_DefaultInterruptHandler(void)
{
// add your PB3 interrupt custom code
// or set custom function using PB3_SetInterruptHandler()
}
ISR(PORTA_PORT_vect)
{
/* Clear interrupt flags */
VPORTA.INTFLAGS = 0xff;
}
ISR(PORTB_PORT_vect)
{
// Call the interrupt handler for the callback registered at runtime
if(VPORTB.INTFLAGS & PORT_INT2_bm)
{
PB2_InterruptHandler();
}
if(VPORTB.INTFLAGS & PORT_INT3_bm)
{
PB3_InterruptHandler();
}
/* Clear interrupt flags */
VPORTB.INTFLAGS = 0xff;
}
ISR(PORTC_PORT_vect)
{
/* Clear interrupt flags */
VPORTC.INTFLAGS = 0xff;
}
ISR(PORTD_PORT_vect)
{
/* Clear interrupt flags */
VPORTD.INTFLAGS = 0xff;
}
ISR(PORTE_PORT_vect)
{
/* Clear interrupt flags */
VPORTE.INTFLAGS = 0xff;
}
ISR(PORTF_PORT_vect)
{
// Call the interrupt handler for the callback registered at runtime
if(VPORTF.INTFLAGS & PORT_INT6_bm)
{
PF6_InterruptHandler();
}
/* Clear interrupt flags */
VPORTF.INTFLAGS = 0xff;
}
/**
End of File
*/

Wyświetl plik

@ -0,0 +1,88 @@
/**
@Company
Microchip Technology Inc.
@Description
This Source file provides APIs.
Generation Information :
Driver Version : 1.0.0
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#include "../utils/assembler.h"
/*
* GNU and IAR use different calling conventions. Since this is
* a very small and simple function to begin with, it's easier
* to implement it twice than to deal with the differences
* within a single implementation.
*/
PUBLIC_FUNCTION(protected_write_io)
#if defined(__GNUC__)
#ifdef RAMPZ
out _SFR_IO_ADDR(RAMPZ), r1 // Clear bits 23:16 of Z
#endif
movw r30, r24 // Load addr into Z
out CCP, r22 // Start CCP handshake
st Z, r20 // Write value to I/O register
ret // Return to caller
#elif defined(__IAR_SYSTEMS_ASM__)
# if !defined(CONFIG_MEMORY_MODEL_TINY) && !defined(CONFIG_MEMORY_MODEL_SMALL) \
&& !defined(CONFIG_MEMORY_MODEL_LARGE)
# define CONFIG_MEMORY_MODEL_SMALL
# endif
# if defined(CONFIG_MEMORY_MODEL_LARGE)
ldi r20, 0
out RAMPZ, r20 // Reset bits 23:16 of Z
movw r30, r16 // Load addr into Z
# elif defined(CONFIG_MEMORY_MODEL_TINY)
ldi r31, 0 // Reset bits 8:15 of Z
mov r30, r16 // Load addr into Z
# else
movw r30, r16 // Load addr into Z
# endif
# if defined(CONFIG_MEMORY_MODEL_TINY)
out CCP, r17 // Start CCP handshake
st Z, r18 // Write value to I/O register
# elif defined(CONFIG_MEMORY_MODEL_SMALL)
out CCP, r18 // Start CCP handshake
st Z, r19 // Write value to I/O register
# elif defined(CONFIG_MEMORY_MODEL_LARGE)
out CCP, r19 // Start CCP handshake
st Z, r20 // Write value to I/O register
# else
# error Unknown memory model in use, no idea how registers should be accessed
# endif
ret
#else
# error Unknown assembler
#endif
END_FUNC(protected_write_io)
END_FILE()

Wyświetl plik

@ -0,0 +1,65 @@
/**
* System Driver Source File
*
* @file system.c
*
* @ingroup systemdriver
*
* @brief This is the generated driver implementation file for the System Driver.
*
* @version Driver Version 1.0.1
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
/**
Section: Included Files
*/
#include "../system.h"
/**
* Initializes MCU, drivers and middleware in the project
**/
int8_t SLPCTRL_Initialize();
void SYSTEM_Initialize(void)
{
PIN_MANAGER_Initialize();
CLOCK_Initialize();
RTC_Initialize();
SLPCTRL_Initialize();
CPUINT_Initialize();
}
int8_t SLPCTRL_Initialize()
{
//SEN enabled; SMODE PDOWN;
ccp_write_io((void*)&(SLPCTRL.CTRLA),0x5);
//PMODE AUTO;
ccp_write_io((void*)&(SLPCTRL.VREGCTRL),0x0);
return 0;
}

Wyświetl plik

@ -0,0 +1,65 @@
/**
* System Driver Header File
*
* @file system.h
*
* @defgroup systemdriver System Driver
*
* @brief This is the generated header file for the System Driver.
*
* @version Driver Version 1.0.1
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef MCC_H
#define MCC_H
#ifdef __cplusplus
extern "C" {
#endif
/**
Section: Included Files
*/
#include "../system/utils/compiler.h"
#include "../system/clock.h"
#include "../system/pins.h"
#include "../system/clock.h"
#include "../timer/rtc.h"
#include "../system/interrupt.h"
/**
* @ingroup systemdriver
* @brief This initializes the system module and must be called before any other API is called.
* This routine should only be called once during system initialization.
* @param None
* @return None
*/
void SYSTEM_Initialize(void);
#ifdef __cplusplus
}
#endif
#endif /* MCC_H */
/**
End of File
*/

Wyświetl plik

@ -0,0 +1,47 @@
/**
@Company
Microchip Technology Inc.
@Description
This Source file provides APIs.
Generation Information :
Driver Version : 1.0.0
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef ASSEMBLER_H_INCLUDED
#define ASSEMBLER_H_INCLUDED
#if !defined(__ASSEMBLER__) && !defined(__IAR_SYSTEMS_ASM__) && !defined(__DOXYGEN__)
#error This file may only be included from assembly files
#endif
#if defined(__ASSEMBLER__)
#include "assembler/gas.h"
#include <avr/io.h>
#elif defined(__IAR_SYSTEMS_ASM__)
#include "assembler/iar.h"
#include <ioavr.h>
#endif
#endif /* ASSEMBLER_H_INCLUDED */

Wyświetl plik

@ -0,0 +1,118 @@
/**
@Company
Microchip Technology Inc.
@Description
This Source file provides APIs.
Generation Information :
Driver Version : 1.0.0
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef ASSEMBLER_GAS_H_INCLUDED
#define ASSEMBLER_GAS_H_INCLUDED
#ifndef __DOXYGEN__
/* clang-format off */
/* IAR doesn't accept dots in macro names */
.macro ld_addr, reg, sym
lda.w \reg, \sym
.endm
/* Define a function \a name that is either globally visible or only
* file-local.
*/
.macro gas_begin_func name, is_public
.if \is_public
.global \name
.endif
#ifdef __XC8
.section .text.\name, code
#else
.section .text.\name, "ax", @progbits
#endif
.type \name, @function
\name :
.endm
/* Define a function \a name that is either globally visible or only
* file-local in a given segment.
*/
.macro gas_begin_func_segm name, is_public, segment
.if \is_public
.global \name
.endif
.section .\segment, "ax", @progbits
.type \name, @function
\name :
.endm
/* Define \a name as a weak alias for the function \a strong_name */
.macro gas_weak_function_alias name, strong_name
.global \name
.weak \name
.type \name, @function
.set \name, \strong_name
.endm
/* Define a weak function called \a name */
.macro gas_weak_function name
.weak \name
gas_begin_func \name 1
.endm
#define REPEAT(count) .rept count
#define END_REPEAT() .endr
#define FILL_BYTES(count) .fill count
#define SET_LOC(offset) .org offset
#define L(name) .L##name
#define EXTERN_SYMBOL(name)
#define TEXT_SECTION(name) \
.section name, "ax", @progbits
#define RODATA_SECTION(name) \
.section name, "a", @progbits
#define DATA_SECTION(name) \
.section name, "aw", @progbits
#define BSS_SECTION(name) \
.section name, "aw", @nobits
#define FUNCTION(name) gas_begin_func name 0
#define PUBLIC_FUNCTION(name) gas_begin_func name 1
#define PUBLIC_FUNCTION_SEGMENT(name, segment) \
gas_begin_func_segm name 1 segment
#define WEAK_FUNCTION(name) gas_weak_function name
#define WEAK_FUNCTION_ALIAS(name, strong_name) \
gas_weak_function_alias name strong_name
#define END_FUNC(name) \
.size name, . - name
#define END_FILE()
/* clang-format on */
#endif /* __DOXYGEN__ */
#endif /* ASSEMBLER_GAS_H_INCLUDED */

Wyświetl plik

@ -0,0 +1,102 @@
/**
@Company
Microchip Technology Inc.
@Description
This Source file provides APIs.
Generation Information :
Driver Version : 1.0.0
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef ASSEMBLER_IAR_H_INCLUDED
#define ASSEMBLER_IAR_H_INCLUDED
/* clang-format off */
ld_addr MACRO reg, sym
mov reg, LWRD sym
orh reg, HWRD sym
ENDM
call MACRO sym
rcall sym
ENDM
iar_begin_func MACRO name, sect, is_public, is_weak
MODULE name
RSEG CODE:CODE:NOROOT(1)
IF is_weak == 1
PUBWEAK name
ELSEIF is_public
PUBLIC name
ENDIF
name:
ENDM
iar_begin_func_segm MACRO name, sect, is_public, is_weak, segment
MODULE name
RSEG segment:CODE:NOROOT(1)
IF is_weak == 1
PUBWEAK name
ELSEIF is_public
PUBLIC name
ENDIF
name:
ENDM
iar_weak_alias MACRO name, strong_name
PUBWEAK name
name:
rjmp strong_name
ENDM
#define lo(x) LWRD x
#define hi(x) HWRD x
#define REPEAT(count) REPT count
#define END_REPEAT() ENDR
#define SET_LOC(offset) ORG offset
#define END_FILE() END
#define FILL_BYTES(count) DS8 count
#define L(name) name
#define EXTERN_SYMBOL(name) EXTERN name
#define FUNCTION(name) iar_begin_func name, text_##name, 0, 0
#define PUBLIC_FUNCTION(name) iar_begin_func name, text_##name, 1, 0
#define PUBLIC_FUNCTION_SEGMENT(name, segment) \
iar_begin_func_segm name, text_##name, 1, 0, segment
#define WEAK_FUNCTION(name) iar_begin_func name, text_##name, 1, 1
#define WEAK_FUNCTION_ALIAS(name, strong_name) \
iar_weak_alias name, strong_name
#define END_FUNC(name) ENDMOD
#define TEXT_SECTION(name) RSEG name:CODE:NOROOT
#define RODATA_SECTION(name) RSEG name:CONST:NOROOT
#define DATA_SECTION(name) RSEG name:DATA:NOROOT
#define BSS_SECTION(name) RSEG name:DATA:NOROOT
/* clang-format on */
#endif /* ASSEMBLER_IAR_H_INCLUDED */

Wyświetl plik

@ -0,0 +1,111 @@
/**
@Company
Microchip Technology Inc.
@Description
This Source file provides APIs.
Generation Information :
Driver Version : 1.0.0
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef ATOMIC_H
#define ATOMIC_H
/**
* \defgroup doc_driver_utils_atomic Atomic memory access and critical sections
* \ingroup doc_driver_utils
*
* Atomic memory access and critical sections
*
* \{
*/
/* clang-format off */
#if defined(__GNUC__) || defined (__DOXYGEN__)
/**
* \brief Enter a critical region
*
* Saves the contents of the status register, including the Global
* Interrupt Enable bit, so that it can be restored upon leaving the
* critical region. Thereafter, clears the Global Interrupt Enable Bit.
* This macro takes a parameter P that is unused for the GCC compiler,
* but necessary for code compatibility with the IAR compiler. The IAR
* compiler declares a variable with the name of the parameter for
* holding the SREG value. Since a variable is declared in the macro,
* this variable must have a name that is unique within the scope
* that the critical region is declared within, otherwise compilation
* will fail.
*
* \param[in] UNUSED(GCC)/P(IAR) Name of variable storing SREG
*
*/
#define ENTER_CRITICAL(UNUSED) __asm__ __volatile__ ( \
"in __tmp_reg__, __SREG__" "\n\t" \
"cli" "\n\t" \
"push __tmp_reg__" "\n\t" \
::: "memory" \
)
/**
* \brief Exit a critical region
*
* Restores the contents of the status register, including the Global
* Interrupt Enable bit, as it was when entering the critical region.
* This macro takes a parameter P that is unused for the GCC compiler,
* but necessary for code compatibility with the IAR compiler. The IAR
* compiler uses this parameter as the name of a variable that holds
* the SREG value. The parameter must be identical to the parameter
* used in the corresponding ENTER_CRITICAL().
*
* \param[in] UNUSED(GCC)/P(IAR) Name of variable storing SREG
*
*/
#define EXIT_CRITICAL(UNUSED) __asm__ __volatile__ ( \
"pop __tmp_reg__" "\n\t" \
"out __SREG__, __tmp_reg__" "\n\t" \
::: "memory" \
)
#define DISABLE_INTERRUPTS() __asm__ __volatile__ ( "cli" ::: "memory")
#define ENABLE_INTERRUPTS() __asm__ __volatile__ ( "sei" ::: "memory")
#elif defined(__ICCAVR__)
#define ENTER_CRITICAL(P) unsigned char P = __save_interrupt();__disable_interrupt();
#define EXIT_CRITICAL(P) __restore_interrupt(P);
#define DISABLE_INTERRUPTS() __disable_interrupt();
#define ENABLE_INTERRUPTS() __enable_interrupt();
#else
# error Unsupported compiler.
#endif
/* clang-format on */
#endif /* ATOMIC_H */

Wyświetl plik

@ -0,0 +1,81 @@
/**
@Company
Microchip Technology Inc.
@Description
This Source file provides APIs.
Generation Information :
Driver Version : 1.0.1
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef UTILS_COMPILER_H
#define UTILS_COMPILER_H
/**
* \defgroup doc_driver_utils_compiler Compiler abstraction
* \ingroup doc_driver_utils
*
* Compiler abstraction layer and code utilities for 8-bit AVR.
* This module provides various abstraction layers and utilities
* to make code compatible between different compilers.
*
* \{
*/
#if defined(__GNUC__)
#include <avr/io.h>
#include <avr/builtins.h>
#if defined(__XC8__)
#include <xc.h>
#endif
#elif defined(__ICCAVR__)
#define ENABLE_BIT_DEFINITIONS 1
#include <ioavr.h>
#include <intrinsics.h>
#ifndef CCP_IOREG_gc
#define CCP_IOREG_gc 0xD8 /* CPU_CCP_IOREG_gc */
#endif
#ifndef CCP_SPM_gc
#define CCP_SPM_gc 0x9D /* CPU_CCP_SPM_gc */
#endif
#else
#error Unsupported compiler.
#endif
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include "interrupt_avr8.h"
/**
* \def UNUSED
* \brief Marking \a v as a unused parameter or value.
*/
#define UNUSED(v) (void)(v)
#endif /* UTILS_COMPILER_H */

Wyświetl plik

@ -0,0 +1,98 @@
/**
@Company
Microchip Technology Inc.
@Description
This Source file provides APIs.
Generation Information :
Driver Version : 1.0.0
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
/**
* \defgroup doc_driver_utils_interrupts ISR abstraction
* \ingroup doc_driver_utils
*
* Interrupt-related functionality.
*
* \{
*/
#ifndef UTILS_INTERRUPT_AVR8_H
#define UTILS_INTERRUPT_AVR8_H
/**
* \weakgroup interrupt_group
*
* @{
*/
#ifdef ISR_CUSTOM_H
#include ISR_CUSTOM_H
#else
/**
* \def ISR
* \brief Define service routine for specified interrupt vector
*
* Usage:
* \code
ISR(FOO_vect)
{
...
}
\endcode
*
* \param vect Interrupt vector name as found in the device header files.
*/
#if defined(__DOXYGEN__)
#define ISR(vect)
#elif defined(__GNUC__)
#include <avr/interrupt.h>
#elif defined(__ICCAVR__)
#define __ISR(x) _Pragma(#x)
#define ISR(vect) __ISR(vector = vect) __interrupt void handler_##vect(void)
#endif
#endif // ISR_CUSTOM_H
#ifdef __GNUC__
#define cpu_irq_enable() sei()
#define cpu_irq_disable() cli()
#else
#define cpu_irq_enable() __enable_interrupt()
#define cpu_irq_disable() __disable_interrupt()
#endif
//! @}
/**
* \weakgroup interrupt_deprecated_group
* @{
*/
// Deprecated definitions.
#define Enable_global_interrupt() cpu_irq_enable()
#define Disable_global_interrupt() cpu_irq_disable()
#define Is_global_interrupt_enabled() cpu_irq_is_enabled()
//! @}
#endif /* UTILS_INTERRUPT_AVR8_H */

Wyświetl plik

@ -0,0 +1,59 @@
/**
@Company
Microchip Technology Inc.
@Description
This Source file provides APIs.
Generation Information :
Driver Version : 1.0.0
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
/**
* \defgroup doc_driver_utils AVR Code utility functions
*
* Compiler abstraction layer and code utilities for AVR.
* This module provides various abstraction layers and utilities
* to make code compatible between different compilers.
*
* \{
*/
#ifndef UTILS_H_INCLUDED
#define UTILS_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief Retrieve array size
*/
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* UTILS_H_INCLUDED */

Wyświetl plik

@ -0,0 +1,70 @@
/**
@Company
Microchip Technology Inc.
@Description
This Source file provides APIs.
Generation Information :
Driver Version : 1.0.0
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
/**
* \defgroup doc_driver_utils_assert Functionality for assert.
* \ingroup doc_driver_utils
*
* \{
*/
#ifndef _ASSERT_H_INCLUDED
#define _ASSERT_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
/**
* \brief Assert macro
*
* This macro is used to throw asserts. It can be mapped to different function
* based on debug level.
*
* \param[in] condition A condition to be checked;
* assert is thrown if the given condition is false
*/
#ifdef DEBUG
#define ASSERT(condition) \
if (!(condition)) \
while (true) \
;
#else
#define ASSERT(condition) ((void)0)
#endif
#ifdef __cplusplus
}
#endif
#endif /* _ASSERT_H_INCLUDED */

Wyświetl plik

@ -0,0 +1,178 @@
/**
* RTC Generated Driver API Header File
*
* @file rtc.h
*
* defgroup rtc RTC
*
* @brief This header file provides APIs for the RTC driver.
*
* @version RTC Driver Version 2.0.2
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#ifndef RTCDRIVER_H
#define RTCDRIVER_H
#include "../system/utils/compiler.h"
#include <stdint.h>
#include <stdbool.h>
/**
* @ingroup rtc
* @typedef void RTC_cb_t
* @brief Function pointer to callback function called by RTC. NULL=default value: No callback function is to be used.
*/
typedef void (*RTC_cb_t)(void);
/**
* @ingroup rtc
* @brief Isr callback function to be called if overflow interrupt flag is set.
* @param RTC_cb_t cb - call back value for overflow.
* @return none
*/
void RTC_SetOVFIsrCallback(RTC_cb_t cb);
/**
* @ingroup rtc
* @brief Isr callback function to be called if Compare match interrupt flag is set.
* @param RTC_cb_t cb - call back value for compare.
* @return none
*/
void RTC_SetCMPIsrCallback(RTC_cb_t cb);
/**
* @ingroup rtc
* @brief Isr callback function to be called if PIT interrupt flag is set.
* @param RTC_cb_t cb - call back value for PIT.
* @return none
*/
void RTC_SetPITIsrCallback(RTC_cb_t cb);
/**
* @ingroup rtc
* @brief Initialize RTC interface.
* @param none
* @retval 0 - the RTC init was successful
* @retval 1 - the RTC init was not successful
*/
int8_t RTC_Initialize(void);
/**
* @ingroup rtc
* @brief API to start the counter register for RTC interface
* @param none
* @return none
*/
void RTC_Start(void);
/**
* @ingroup rtc
* @brief API to stop the counter register for RTC interface
* @param none
* @return none
*/
void RTC_Stop(void);
/**
* @ingroup rtc
* @brief API to write the counter value for RTC.
* @param uint16_t timerVal - Loading the counter value to write for RTC.
* @return none
*/
void RTC_WriteCounter(uint16_t timerVal);
/**
* @ingroup rtc
* @brief API to write the counter value to load for RTC.
* @param uint16_t timerVal - Loading the write period to determine overflow period in RTC.
* @return none
*/
void RTC_WritePeriod(uint16_t timerVal);
/**
* @ingroup rtc
* @brief API to read the counter clock cycle value from counter register.
* @param none
* @return uint16_t - Counter values returns from the RTC interface.
*/
uint16_t RTC_ReadCounter(void);
/**
* @ingroup rtc
* @brief API to read the overflow value in period register.
* @param none
* @return uint16_t - Period values returns from the RTC interface.
*/
uint16_t RTC_ReadPeriod(void);
/**
* @ingroup rtc
* @brief Enable the CMP interrupt to set the flag, if match value between counter register and compare register.
* @param none
* @return none
*/
void RTC_EnableCMPInterrupt(void);
/**
* @ingroup rtc
* @brief Disable the CMP interrupt for RTC interface.
* @param none
* @return none
*/
void RTC_DisableCMPInterrupt(void);
/**
* @ingroup rtc
* @brief Enable the overflow interrupt set the OVF flag, if the counter reached value from the period register and wrapped to zero.
* @param none
* @return none
*/
void RTC_EnableOVFInterrupt(void);
/**
* @ingroup rtc
* @brief Disable the Overflow interrupt for RTC interface.
* @param none
* @return none
*/
void RTC_DisableOVFInterrupt(void);
/**
* @ingroup rtc
* @brief Enable the Period Interrupt Timer to set the flag, if a time period has passed as configured in period bit field.
* @param none
* @return none
*/
void RTC_EnablePITInterrupt(void);
/**
* @ingroup rtc
* @brief Disable the PIT interrupt for RTC interface.
* @param none
* @return none
*/
void RTC_DisablePITInterrupt(void);
/**
* @ingroup rtc
* @brief Clearing the Overflow interrupt flag after the overflow flag set.
* @param none
* @return none
*/
void RTC_ClearOVFInterruptFlag(void);
/**
* @ingroup rtc
* @brief Enable the Overflow interrupt to set overflow flag, when overflow occur.
* @param none
* @return none
*/
bool RTC_IsOVFInterruptEnabled(void);
#endif /* RTCDRIVER_H */
/** @}*/

Wyświetl plik

@ -0,0 +1,185 @@
/**
* RTC Generated Driver File
*
* @file rtc.c
*
* @ingroup rtc
*
* @brief This file contains the driver code for RTC module.
*
* version RTC Driver Version 2.0.2
*/
/*
© [2023] Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip
software and any derivatives exclusively with Microchip products.
You are responsible for complying with 3rd party license terms
applicable to your use of 3rd party software (including open source
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
THIS SOFTWARE.
*/
#include "../rtc.h"
void (*RTC_OVF_isr_cb)(void) = NULL;
void (*RTC_CMP_isr_cb)(void) = NULL;
void (*RTC_PIT_isr_cb)(void) = NULL;
int8_t RTC_Initialize(void)
{
while (RTC.STATUS > 0) { /* Wait for all register to be synchronized */
}
//Compare
RTC.CMP = 0x1D;
//Count
RTC.CNT = 0x0;
//Period
RTC.PER = 0x1D;
//Clock selection
RTC.CLKSEL = 0x2;
// CMP enabled; OVF disabled;
RTC.INTCTRL = 0x2;
// CORREN disabled; PRESCALER RTC Clock / 32768; RTCEN enabled; RUNSTDBY disabled;
RTC.CTRLA = 0x79;
while (RTC.PITSTATUS > 0) { /* Wait for all register to be synchronized */
}
// PI disabled;
RTC.PITINTCTRL = 0x0;
return 0;
}
void RTC_Start(void)
{
RTC.CTRLA |= RTC_RTCEN_bm;
}
void RTC_Stop(void)
{
RTC.CTRLA &= ~RTC_RTCEN_bm;
}
void RTC_SetOVFIsrCallback(RTC_cb_t cb)
{
RTC_OVF_isr_cb = cb;
}
void RTC_SetCMPIsrCallback(RTC_cb_t cb)
{
RTC_CMP_isr_cb = cb;
}
void RTC_SetPITIsrCallback(RTC_cb_t cb)
{
RTC_PIT_isr_cb = cb;
}
ISR(RTC_CNT_vect)
{
if (RTC.INTFLAGS & RTC_OVF_bm )
{
if (RTC_OVF_isr_cb != NULL)
{
(*RTC_OVF_isr_cb)();
}
}
if (RTC.INTFLAGS & RTC_CMP_bm )
{
if (RTC_CMP_isr_cb != NULL)
{
(*RTC_CMP_isr_cb)();
}
}
RTC.INTFLAGS = (RTC_OVF_bm | RTC_CMP_bm);
}
ISR(RTC_PIT_vect)
{
if (RTC_PIT_isr_cb != NULL)
{
(*RTC_PIT_isr_cb)();
}
RTC.PITINTFLAGS = RTC_PI_bm;
}
inline void RTC_WriteCounter(uint16_t timerVal)
{
while (RTC.STATUS & RTC_CNTBUSY_bm);
RTC.CNT = timerVal;
}
inline uint16_t RTC_ReadCounter(void)
{
return RTC.CNT;
}
inline void RTC_WritePeriod(uint16_t timerVal)
{
while (RTC.STATUS & RTC_PERBUSY_bm);
RTC.PER = timerVal;
}
inline uint16_t RTC_ReadPeriod(void)
{
return RTC.PER;
}
inline void RTC_EnableCMPInterrupt(void)
{
RTC.INTCTRL |= RTC_CMP_bm;
}
inline void RTC_DisableCMPInterrupt(void)
{
RTC.INTCTRL &= ~RTC_CMP_bm;
}
inline void RTC_EnableOVFInterrupt(void)
{
RTC.INTCTRL |= RTC_OVF_bm;
}
inline void RTC_DisableOVFInterrupt(void)
{
RTC.INTCTRL &= ~RTC_OVF_bm;
}
inline void RTC_EnablePITInterrupt(void)
{
RTC.PITINTCTRL |= RTC_PI_bm;
}
inline void RTC_DisablePITInterrupt(void)
{
RTC.PITINTCTRL &= ~RTC_PI_bm;
}
inline void RTC_ClearOVFInterruptFlag(void)
{
RTC.INTFLAGS = RTC_OVF_bm;
}
inline bool RTC_IsOVFInterruptEnabled(void)
{
return ((RTC.INTCTRL & RTC_OVF_bm) > 0);
}

Wyświetl plik

@ -0,0 +1,233 @@
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="65">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<logicalFolder name="MCC Generated Files"
displayName="MCC Generated Files"
projectFiles="true">
<logicalFolder name="system" displayName="system" projectFiles="true">
<logicalFolder name="utils" displayName="utils" projectFiles="true">
<logicalFolder name="assembler" displayName="assembler" projectFiles="true">
<itemPath>mcc_generated_files/system/utils/assembler/iar.h</itemPath>
<itemPath>mcc_generated_files/system/utils/assembler/gas.h</itemPath>
</logicalFolder>
<itemPath>mcc_generated_files/system/utils/utils_assert.h</itemPath>
<itemPath>mcc_generated_files/system/utils/interrupt_avr8.h</itemPath>
<itemPath>mcc_generated_files/system/utils/assembler.h</itemPath>
<itemPath>mcc_generated_files/system/utils/atomic.h</itemPath>
<itemPath>mcc_generated_files/system/utils/compiler.h</itemPath>
<itemPath>mcc_generated_files/system/utils/utils.h</itemPath>
</logicalFolder>
<itemPath>mcc_generated_files/system/clock.h</itemPath>
<itemPath>mcc_generated_files/system/system.h</itemPath>
<itemPath>mcc_generated_files/system/pins.h</itemPath>
<itemPath>mcc_generated_files/system/protected_io.h</itemPath>
<itemPath>mcc_generated_files/system/port.h</itemPath>
<itemPath>mcc_generated_files/system/ccp.h</itemPath>
<itemPath>mcc_generated_files/system/interrupt.h</itemPath>
</logicalFolder>
<logicalFolder name="timer" displayName="timer" projectFiles="true">
<itemPath>mcc_generated_files/timer/rtc.h</itemPath>
</logicalFolder>
</logicalFolder>
<itemPath>application.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<logicalFolder name="MCC Generated Files"
displayName="MCC Generated Files"
projectFiles="true">
<logicalFolder name="system" displayName="system" projectFiles="true">
<logicalFolder name="src" displayName="src" projectFiles="true">
<itemPath>mcc_generated_files/system/src/system.c</itemPath>
<itemPath>mcc_generated_files/system/src/protected_io.S</itemPath>
<itemPath>mcc_generated_files/system/src/config_bits.c</itemPath>
<itemPath>mcc_generated_files/system/src/interrupt.c</itemPath>
<itemPath>mcc_generated_files/system/src/clock.c</itemPath>
<itemPath>mcc_generated_files/system/src/pins.c</itemPath>
</logicalFolder>
</logicalFolder>
<logicalFolder name="timer" displayName="timer" projectFiles="true">
<logicalFolder name="src" displayName="src" projectFiles="true">
<itemPath>mcc_generated_files/timer/src/rtc.c</itemPath>
</logicalFolder>
</logicalFolder>
</logicalFolder>
<itemPath>main.c</itemPath>
<itemPath>application.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
<itemPath>avr128db48-clock-switching-hf-to-lf.mc3</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>AVR128DB48</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>noID</platformTool>
<languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>2.40</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<packs>
<pack name="AVR-Dx_DFP" vendor="Microchip" version="2.2.159"/>
</packs>
<ScriptingSettings>
</ScriptingSettings>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<archiverTool>
</archiverTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<parseOnProdLoad>false</parseOnProdLoad>
<alternateLoadableFile></alternateLoadableFile>
</loading>
<subordinates>
</subordinates>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeUseCleanTarget>false</makeUseCleanTarget>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<HI-TECH-COMP>
<property key="additional-warnings" value="true"/>
<property key="asmlist" value="true"/>
<property key="call-prologues" value="false"/>
<property key="default-bitfield-type" value="true"/>
<property key="default-char-type" value="true"/>
<property key="define-macros" value=""/>
<property key="disable-optimizations" value="false"/>
<property key="extra-include-directories" value=""/>
<property key="favor-optimization-for" value="-speed,+space"/>
<property key="garbage-collect-data" value="true"/>
<property key="garbage-collect-functions" value="true"/>
<property key="identifier-length" value="255"/>
<property key="local-generation" value="false"/>
<property key="operation-mode"
value="${opt-xc8-compiler-operation_mode.license}"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="false"/>
<property key="optimization-debug" value="false"/>
<property key="optimization-invariant-enable" value="false"/>
<property key="optimization-invariant-value" value="16"/>
<property key="optimization-level" value="${optimization-level.default}"/>
<property key="optimization-speed" value="false"/>
<property key="optimization-stable-enable" value="false"/>
<property key="preprocess-assembler" value="true"/>
<property key="short-enums" value="true"/>
<property key="tentative-definitions" value="${tentative.default}"/>
<property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="-3"/>
<property key="what-to-do" value="ignore"/>
</HI-TECH-COMP>
<HI-TECH-LINK>
<property key="additional-options-checksum" value=""/>
<property key="additional-options-code-offset" value=""/>
<property key="additional-options-command-line" value=""/>
<property key="additional-options-errata" value=""/>
<property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/>
<property key="additional-options-use-response-files" value="false"/>
<property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="false"/>
<property key="calibrate-oscillator-value" value="0x3400"/>
<property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-double-gcc" value="short-double"/>
<property key="data-model-size-of-float" value="24"/>
<property key="data-model-size-of-float-gcc" value="short-float"/>
<property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/>
<property key="extra-lib-directories" value=""/>
<property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/>
<property key="input-libraries" value="libm"/>
<property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/>
<property key="link-in-c-library-gcc" value=""/>
<property key="link-in-peripheral-library" value="false"/>
<property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="true"/>
<property key="remove-unused-sections" value="true"/>
</HI-TECH-LINK>
<Tool>
<property key="debugoptions.useswbreakpoints" value="true"/>
<property key="memories.programmemory.ranges" value="0-ffff"/>
<property key="programmerToGoFilePath"
value="C:/Users/i62418/Desktop/avr128db48-external-crystal.X/debug/default/avr128db48-external-crystal_ptg"/>
</Tool>
<XC8-CO>
<property key="coverage-enable" value=""/>
<property key="stack-guidance" value="false"/>
</XC8-CO>
<XC8-config-global>
<property key="advanced-elf" value="true"/>
<property key="constdata-progmem" value="true"/>
<property key="gcc-opt-driver-new" value="false"/>
<property key="gcc-opt-std" value="${gcc-opt-std.default}"/>
<property key="gcc-output-file-format" value="dwarf-3"/>
<property key="mapped-progmem" value="false"/>
<property key="omit-pack-options" value="false"/>
<property key="omit-pack-options-new" value="1"/>
<property key="output-file-format" value="-mcof,+elf"/>
<property key="smart-io-format" value=""/>
<property key="stack-size-high" value="auto"/>
<property key="stack-size-low" value="auto"/>
<property key="stack-size-main" value="auto"/>
<property key="stack-type" value="compiled"/>
<property key="user-pack-device-support" value=""/>
<property key="wpo-lto" value="false"/>
</XC8-config-global>
<nEdbgTool>
<property key="debugoptions.useswbreakpoints" value="true"/>
<property key="memories.programmemory.ranges" value="0-ffff"/>
<property key="programmerToGoFilePath"
value="C:/Users/i62418/Desktop/avr128db48-external-crystal.X/debug/default/avr128db48-external-crystal_ptg"/>
</nEdbgTool>
</conf>
</confs>
</configurationDescriptor>

Wyświetl plik

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>com.microchip.mplab.nbide.embedded.makeproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/make-project/1">
<name>avr128db48-using-crystal-osc-as-clock-for-rtc-in-sleep-mplab</name>
<creation-uuid>b90c9ea0-ef56-4771-9538-c02225a2ee78</creation-uuid>
<make-project-type>0</make-project-type>
<c-extensions>c</c-extensions>
<cpp-extensions/>
<header-extensions>h</header-extensions>
<asminc-extensions/>
<sourceEncoding>ISO-8859-1</sourceEncoding>
<make-dep-projects/>
<sourceRootList/>
<confList>
<confElem>
<name>default</name>
<type>2</type>
</confElem>
</confList>
<formatting>
<project-formatting-style>false</project-formatting-style>
</formatting>
</data>
</configuration>
</project>

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 253 KiB

BIN
images/blk_diag.png 100644

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 72 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 52 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 18 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 27 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 181 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 264 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 310 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 337 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 48 KiB

BIN
images/setup.png 100644

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 573 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 12 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 403 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 73 KiB