adjust root folder
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Configuration Change Protection write functions
|
||||
*
|
||||
* Copyright (c) 2010-2012 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an
|
||||
* Atmel microcontroller product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
#ifndef CPU_CCP_H
|
||||
#define CPU_CCP_H
|
||||
#include <compiler.h>
|
||||
|
||||
/**
|
||||
* \defgroup ccp_group Configuration Change Protection
|
||||
*
|
||||
* See \ref xmega_ccp_quickstart.
|
||||
*
|
||||
* Function for writing to protected IO registers.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#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 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.
|
||||
*/
|
||||
extern void ccp_write_io (void *addr, uint8_t value);
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \page xmega_ccp_quickstart Quick start guide for CCP driver
|
||||
*
|
||||
* This is the quick start guide for the \ref ccp_group
|
||||
* "Configuration Change Protection (CCP) driver", with step-by-step
|
||||
* instructions on how to use the driver.
|
||||
*
|
||||
* The use case contains a code fragment, and this can be copied into, e.g.,
|
||||
* the main application function.
|
||||
*
|
||||
* \section ccp_basic_use_case Basic use case
|
||||
* In this use case, the CCP is used to write to the protected XMEGA Clock
|
||||
* Control register.
|
||||
*
|
||||
* \subsection ccp_basic_use_case_setup_flow Workflow
|
||||
* -# call CCP write io to change system clock selection:
|
||||
* - \code ccp_write_io((uint8_t *)&CLK.CTRL, CLK_SCLKSEL_RC32M_gc); \endcode
|
||||
*/
|
||||
|
||||
#endif /* CPU_CCP_H */
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Configuration Change Protection
|
||||
*
|
||||
* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an
|
||||
* Atmel microcontroller product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
#include <assembler.h>
|
||||
|
||||
//! Value to write to CCP for access to protected IO registers.
|
||||
#define CCP_IOREG 0xd8
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* Interrupts are disabled by hardware during the timed
|
||||
* sequence, so there's no need to save/restore interrupt state.
|
||||
*/
|
||||
|
||||
PUBLIC_FUNCTION(ccp_write_io)
|
||||
|
||||
#if defined(__GNUC__)
|
||||
|
||||
out RAMPZ, r1 // Reset bits 23:16 of Z
|
||||
movw r30, r24 // Load addr into Z
|
||||
ldi r18, CCP_IOREG // Load magic CCP value
|
||||
out CCP, r18 // Start CCP handshake
|
||||
st Z, r22 // 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
|
||||
ldi r20, 0
|
||||
out RAMPZ, r20 // Reset bits 23:16 of Z
|
||||
# if defined(CONFIG_MEMORY_MODEL_TINY)
|
||||
mov r31, r20 // Reset bits 8:15 of Z
|
||||
mov r30, r16 // Load addr into Z
|
||||
# else
|
||||
movw r30, r16 // Load addr into Z
|
||||
# endif
|
||||
ldi r21, CCP_IOREG // Load magic CCP value
|
||||
out CCP, r21 // Start CCP handshake
|
||||
# if defined(CONFIG_MEMORY_MODEL_TINY)
|
||||
st Z, r17 // Write value to I/O register
|
||||
# elif defined(CONFIG_MEMORY_MODEL_SMALL)
|
||||
st Z, r18 // Write value to I/O register
|
||||
# elif defined(CONFIG_MEMORY_MODEL_LARGE)
|
||||
st Z, r19 // 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(ccp_write_io)
|
||||
END_FILE()
|
||||
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Chip-specific reset cause functions
|
||||
*
|
||||
* Copyright (c) 2010-2012 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an
|
||||
* Atmel microcontroller product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
#ifndef XMEGA_DRIVERS_CPU_RESET_CAUSE_H
|
||||
#define XMEGA_DRIVERS_CPU_RESET_CAUSE_H
|
||||
|
||||
#include "compiler.h"
|
||||
#include "ccp.h"
|
||||
|
||||
/**
|
||||
* \ingroup reset_cause_group
|
||||
* \defgroup xmega_reset_cause_group XMEGA reset cause
|
||||
*
|
||||
* See \ref reset_cause_quickstart
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Chip-specific reset cause type capable of holding all chip reset
|
||||
* causes. Typically reflects the size of the reset cause register.
|
||||
*/
|
||||
typedef uint8_t reset_cause_t;
|
||||
|
||||
//! \internal \name Chip-specific reset causes
|
||||
//@{
|
||||
//! \internal External reset cause
|
||||
#define CHIP_RESET_CAUSE_EXTRST RST_EXTRF_bm
|
||||
//! \internal brown-out detected reset cause, same as for CPU
|
||||
#define CHIP_RESET_CAUSE_BOD_IO RST_BORF_bm
|
||||
//! \internal Brown-out detected reset cause, same as for I/O
|
||||
#define CHIP_RESET_CAUSE_BOD_CPU RST_BORF_bm
|
||||
//! \internal On-chip debug system reset cause
|
||||
#define CHIP_RESET_CAUSE_OCD RST_PDIRF_bm
|
||||
//! \internal Power-on-reset reset cause
|
||||
#define CHIP_RESET_CAUSE_POR RST_PORF_bm
|
||||
//! \internal Software reset reset cause
|
||||
#define CHIP_RESET_CAUSE_SOFT RST_SRF_bm
|
||||
//! \internal Spike detected reset cause
|
||||
#define CHIP_RESET_CAUSE_SPIKE RST_SDRF_bm
|
||||
//! \internal Watchdog timeout reset cause
|
||||
#define CHIP_RESET_CAUSE_WDT RST_WDRF_bm
|
||||
//@}
|
||||
|
||||
static inline reset_cause_t
|
||||
reset_cause_get_causes (void)
|
||||
{
|
||||
return (reset_cause_t) RST.STATUS;
|
||||
}
|
||||
|
||||
static inline void
|
||||
reset_cause_clear_causes (reset_cause_t causes)
|
||||
{
|
||||
RST.STATUS = causes;
|
||||
}
|
||||
|
||||
static inline void
|
||||
reset_do_soft_reset (void)
|
||||
{
|
||||
ccp_write_io ((void *) &RST.CTRL, RST_SWRST_bm);
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* Intentionally empty. */
|
||||
}
|
||||
}
|
||||
|
||||
//! @}
|
||||
|
||||
#endif /* XMEGA_DRIVERS_CPU_RESET_CAUSE_H */
|
||||
Reference in New Issue
Block a user