mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
Merge pull request #833 from geniusgogo/samd21
[BSP] add atmel SAM D21 bsp support
This commit is contained in:
commit
794835dde2
797 files changed
+286501
No files matched your search
@@ -0,0 +1,5 @@
|
||||
使用SAMD21-Xplained-Pro开发板
|
||||
scons:
|
||||
scons
|
||||
scons --target=mdk5
|
||||
demo代码演示了串口、外部中断、RTC低功耗唤醒
|
||||
@@ -0,0 +1,15 @@
|
||||
; *************************************************************
|
||||
; *** Scatter-Loading Description File generated by uVision ***
|
||||
; *************************************************************
|
||||
|
||||
LR_IROM1 0x00000000 0x00040000 { ; load region size_region
|
||||
ER_IROM1 0x00000000 0x00040000 { ; load address = execution address
|
||||
*.o (RESET, +First)
|
||||
*(InRoot$$Sections)
|
||||
.ANY (+RO)
|
||||
}
|
||||
RW_IRAM1 0x20000000 0x00008000 { ; RW data
|
||||
.ANY (+RW +ZI)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
# for module compiling
|
||||
import os
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(d, 'SConscript'))
|
||||
|
||||
Return('objs')
|
||||
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
import sys
|
||||
import rtconfig
|
||||
|
||||
if os.getenv('RTT_ROOT'):
|
||||
RTT_ROOT = os.getenv('RTT_ROOT')
|
||||
else:
|
||||
RTT_ROOT = os.path.normpath(os.getcwd() + '/../..')
|
||||
|
||||
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
|
||||
from building import *
|
||||
|
||||
TARGET = 'SAM_D2X_RTT.' + rtconfig.TARGET_EXT
|
||||
|
||||
env = Environment(tools = ['mingw'],
|
||||
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
|
||||
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
|
||||
AR = rtconfig.AR, ARFLAGS = '-rc',
|
||||
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
|
||||
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
|
||||
|
||||
if rtconfig.PLATFORM == 'iar':
|
||||
env.Replace(CCCOM = ['$CC $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -o $TARGET $SOURCES'])
|
||||
env.Replace(ARFLAGS = [''])
|
||||
env.Replace(LINKCOM = ['$LINK $SOURCES $LINKFLAGS -o $TARGET --map project.map'])
|
||||
|
||||
Export('RTT_ROOT')
|
||||
Export('rtconfig')
|
||||
|
||||
# prepare building environment
|
||||
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
|
||||
|
||||
# make a building
|
||||
DoBuilding(TARGET, objs)
|
||||
@@ -0,0 +1,14 @@
|
||||
Import('RTT_ROOT')
|
||||
Import('rtconfig')
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
CPPPATH = [cwd, str(Dir('#'))]
|
||||
|
||||
#remove other no use files
|
||||
#SrcRemove(src, '*.c')
|
||||
|
||||
group = DefineGroup('Application', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
@@ -0,0 +1,119 @@
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#include "port.h"
|
||||
#include "extint.h"
|
||||
|
||||
#include "sleep_timer.h"
|
||||
|
||||
void LED_Init(void)
|
||||
{
|
||||
struct port_config config_port_pin;
|
||||
|
||||
port_get_config_defaults(&config_port_pin);
|
||||
config_port_pin.direction = PORT_PIN_DIR_INPUT;
|
||||
config_port_pin.input_pull = PORT_PIN_PULL_UP;
|
||||
port_pin_set_config(PIN_PA15, &config_port_pin);
|
||||
|
||||
config_port_pin.direction = PORT_PIN_DIR_OUTPUT;
|
||||
port_pin_set_config(PIN_PB30, &config_port_pin);
|
||||
}
|
||||
|
||||
void LED_ON(void)
|
||||
{
|
||||
port_pin_set_output_level(PIN_PB30, false);
|
||||
}
|
||||
|
||||
void LED_OFF(void)
|
||||
{
|
||||
port_pin_set_output_level(PIN_PB30, true);
|
||||
}
|
||||
|
||||
void extint_detection_callback(void);
|
||||
|
||||
void configure_extint_channel(void)
|
||||
{
|
||||
//! [setup_1]
|
||||
struct extint_chan_conf config_extint_chan;
|
||||
//! [setup_1]
|
||||
//! [setup_2]
|
||||
extint_chan_get_config_defaults(&config_extint_chan);
|
||||
//! [setup_2]
|
||||
|
||||
//! [setup_3]
|
||||
config_extint_chan.gpio_pin = PIN_PA15A_EIC_EXTINT15;
|
||||
config_extint_chan.gpio_pin_mux = MUX_PA15A_EIC_EXTINT15;
|
||||
config_extint_chan.gpio_pin_pull = EXTINT_PULL_UP;
|
||||
config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;
|
||||
//! [setup_3]
|
||||
//! [setup_4]
|
||||
extint_chan_set_config(15, &config_extint_chan);
|
||||
//! [setup_4]
|
||||
}
|
||||
|
||||
void configure_extint_callbacks(void)
|
||||
{
|
||||
//! [setup_5]
|
||||
extint_register_callback(extint_detection_callback, 15, EXTINT_CALLBACK_TYPE_DETECT);
|
||||
//! [setup_5]
|
||||
//! [setup_6]
|
||||
extint_chan_enable_callback(15, EXTINT_CALLBACK_TYPE_DETECT);
|
||||
//! [setup_6]
|
||||
}
|
||||
|
||||
//! [setup_7]
|
||||
void extint_detection_callback(void)
|
||||
{
|
||||
bool pin_state = port_pin_get_input_level(PIN_PA15);
|
||||
port_pin_set_output_level(PIN_PB30, pin_state);
|
||||
}
|
||||
|
||||
static struct rt_semaphore _rx_sem;
|
||||
|
||||
static rt_err_t _rx_ind(rt_device_t dev, rt_size_t size)
|
||||
{
|
||||
return rt_sem_release(&_rx_sem);
|
||||
}
|
||||
|
||||
void rt_init_thread_entry(void* parameter)
|
||||
{
|
||||
rt_thread_t thread;
|
||||
rt_device_t dev;
|
||||
|
||||
rt_kprintf("SYSTEM running at %uhz\n", SystemCoreClock);
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
/* init finsh */
|
||||
finsh_system_init();
|
||||
finsh_set_device("uart1");
|
||||
#endif
|
||||
|
||||
LED_Init();
|
||||
configure_extint_channel();
|
||||
configure_extint_callbacks();
|
||||
|
||||
sleep_timer_init();
|
||||
// sleep_timer_start(1500);
|
||||
|
||||
while (1)
|
||||
{
|
||||
rt_kprintf("init thread running tick:%u\n", rt_tick_get());
|
||||
rt_thread_delay(2*RT_TICK_PER_SECOND);
|
||||
}
|
||||
}
|
||||
|
||||
int rt_application_init(void)
|
||||
{
|
||||
rt_thread_t tid;
|
||||
|
||||
tid = rt_thread_create("init", rt_init_thread_entry, RT_NULL,
|
||||
512, RT_THREAD_PRIORITY_MAX / 3, 20);
|
||||
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* File : startup.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006, RT-Thread Develop Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://openlab.rt-thread.com/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2006-08-31 Bernard first implementation
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "board.h"
|
||||
|
||||
/**
|
||||
* @addtogroup STM32
|
||||
*/
|
||||
|
||||
/*@{*/
|
||||
|
||||
extern int rt_application_init(void);
|
||||
#ifdef RT_USING_FINSH
|
||||
extern void finsh_system_init(void);
|
||||
extern void finsh_set_device(const char* device);
|
||||
#endif
|
||||
|
||||
#ifdef __CC_ARM
|
||||
extern int Image$$RW_IRAM1$$ZI$$Limit;
|
||||
#elif __ICCARM__
|
||||
#pragma section="HEAP"
|
||||
#else
|
||||
extern int __bss_end;
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
/*******************************************************************************
|
||||
* Function Name : assert_failed
|
||||
* Description : Reports the name of the source file and the source line number
|
||||
* where the assert error has occurred.
|
||||
* Input : - file: pointer to the source file name
|
||||
* - line: assert error line source number
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void assert_failed(uint8_t* file, uint32_t line)
|
||||
{
|
||||
rt_kprintf("\n\r Wrong parameter value detected on\r\n");
|
||||
rt_kprintf(" file %s\r\n", file);
|
||||
rt_kprintf(" line %d\r\n", line);
|
||||
|
||||
while (1) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function will startup RT-Thread RTOS.
|
||||
*/
|
||||
void rtthread_startup(void)
|
||||
{
|
||||
/* init board */
|
||||
rt_board_init();
|
||||
|
||||
/* show version */
|
||||
rt_show_version();
|
||||
|
||||
/* init tick */
|
||||
rt_system_tick_init();
|
||||
|
||||
/* init kernel object */
|
||||
rt_system_object_init();
|
||||
|
||||
/* init timer system */
|
||||
rt_system_timer_init();
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
#ifdef __CC_ARM
|
||||
rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)CHIP_SRAM_END);
|
||||
#elif __ICCARM__
|
||||
rt_system_heap_init(__segment_end("HEAP"), (void*)CHIP_SRAM_END);
|
||||
#else
|
||||
/* init memory system */
|
||||
rt_system_heap_init((void*)&__bss_end, (void*)CHIP_SRAM_END);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* init scheduler system */
|
||||
rt_system_scheduler_init();
|
||||
|
||||
/* init application */
|
||||
rt_application_init();
|
||||
|
||||
/* init timer thread */
|
||||
rt_system_timer_thread_init();
|
||||
|
||||
/* init idle thread */
|
||||
rt_thread_idle_init();
|
||||
|
||||
/* start scheduler */
|
||||
rt_system_scheduler_start();
|
||||
|
||||
/* never reach here */
|
||||
return ;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* disable interrupt first */
|
||||
rt_hw_interrupt_disable();
|
||||
|
||||
/* startup RT-Thread RTOS */
|
||||
rtthread_startup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*@}*/
|
||||
@@ -0,0 +1,170 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief SAM D20 Clock configuration
|
||||
*
|
||||
* Copyright (C) 2012-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#include <clock.h>
|
||||
|
||||
#ifndef CONF_CLOCKS_H_INCLUDED
|
||||
# define CONF_CLOCKS_H_INCLUDED
|
||||
|
||||
/* System clock bus configuration */
|
||||
# define CONF_CLOCK_FLASH_WAIT_STATES 0
|
||||
# define CONF_CLOCK_CPU_DIVIDER SYSTEM_MAIN_CLOCK_DIV_1
|
||||
# define CONF_CLOCK_APBA_DIVIDER SYSTEM_MAIN_CLOCK_DIV_1
|
||||
# define CONF_CLOCK_APBB_DIVIDER SYSTEM_MAIN_CLOCK_DIV_1
|
||||
# define CONF_CLOCK_APBC_DIVIDER SYSTEM_MAIN_CLOCK_DIV_1
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_OSC8M configuration - Internal 8MHz oscillator */
|
||||
# define CONF_CLOCK_OSC8M_PRESCALER SYSTEM_OSC8M_DIV_1
|
||||
# define CONF_CLOCK_OSC8M_ON_DEMAND true
|
||||
# define CONF_CLOCK_OSC8M_RUN_IN_STANDBY false
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_XOSC configuration - External clock/oscillator */
|
||||
# define CONF_CLOCK_XOSC_ENABLE false
|
||||
# define CONF_CLOCK_XOSC_EXTERNAL_CRYSTAL SYSTEM_CLOCK_EXTERNAL_CRYSTAL
|
||||
# define CONF_CLOCK_XOSC_EXTERNAL_FREQUENCY 12000000UL
|
||||
# define CONF_CLOCK_XOSC_STARTUP_TIME SYSTEM_XOSC_STARTUP_32768
|
||||
# define CONF_CLOCK_XOSC_AUTO_GAIN_CONTROL true
|
||||
# define CONF_CLOCK_XOSC_ON_DEMAND true
|
||||
# define CONF_CLOCK_XOSC_RUN_IN_STANDBY false
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_XOSC32K configuration - External 32KHz crystal/clock oscillator */
|
||||
# define CONF_CLOCK_XOSC32K_ENABLE false
|
||||
# define CONF_CLOCK_XOSC32K_EXTERNAL_CRYSTAL SYSTEM_CLOCK_EXTERNAL_CRYSTAL
|
||||
# define CONF_CLOCK_XOSC32K_STARTUP_TIME SYSTEM_XOSC32K_STARTUP_65536
|
||||
# define CONF_CLOCK_XOSC32K_AUTO_AMPLITUDE_CONTROL false
|
||||
# define CONF_CLOCK_XOSC32K_ENABLE_1KHZ_OUPUT false
|
||||
# define CONF_CLOCK_XOSC32K_ENABLE_32KHZ_OUTPUT true
|
||||
# define CONF_CLOCK_XOSC32K_ON_DEMAND true
|
||||
# define CONF_CLOCK_XOSC32K_RUN_IN_STANDBY false
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_OSC32K configuration - Internal 32KHz oscillator */
|
||||
# define CONF_CLOCK_OSC32K_ENABLE false
|
||||
# define CONF_CLOCK_OSC32K_STARTUP_TIME SYSTEM_OSC32K_STARTUP_130
|
||||
# define CONF_CLOCK_OSC32K_ENABLE_1KHZ_OUTPUT true
|
||||
# define CONF_CLOCK_OSC32K_ENABLE_32KHZ_OUTPUT true
|
||||
# define CONF_CLOCK_OSC32K_ON_DEMAND true
|
||||
# define CONF_CLOCK_OSC32K_RUN_IN_STANDBY false
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_DFLL configuration - Digital Frequency Locked Loop */
|
||||
# define CONF_CLOCK_DFLL_ENABLE false
|
||||
# define CONF_CLOCK_DFLL_LOOP_MODE SYSTEM_CLOCK_DFLL_LOOP_MODE_OPEN
|
||||
# define CONF_CLOCK_DFLL_ON_DEMAND false
|
||||
|
||||
/* DFLL open loop mode configuration */
|
||||
# define CONF_CLOCK_DFLL_FINE_VALUE (512)
|
||||
|
||||
/* DFLL closed loop mode configuration */
|
||||
# define CONF_CLOCK_DFLL_SOURCE_GCLK_GENERATOR GCLK_GENERATOR_1
|
||||
# define CONF_CLOCK_DFLL_MULTIPLY_FACTOR 1465 /* (48000000 / 32768) */
|
||||
# define CONF_CLOCK_DFLL_QUICK_LOCK true
|
||||
# define CONF_CLOCK_DFLL_TRACK_AFTER_FINE_LOCK true
|
||||
# define CONF_CLOCK_DFLL_KEEP_LOCK_ON_WAKEUP true
|
||||
# define CONF_CLOCK_DFLL_ENABLE_CHILL_CYCLE true
|
||||
# define CONF_CLOCK_DFLL_MAX_COARSE_STEP_SIZE (0x1f / 4)
|
||||
# define CONF_CLOCK_DFLL_MAX_FINE_STEP_SIZE (0xff / 4)
|
||||
|
||||
|
||||
/* Set this to true to configure the GCLK when running clocks_init. If set to
|
||||
* false, none of the GCLK generators will be configured in clocks_init(). */
|
||||
# define CONF_CLOCK_CONFIGURE_GCLK true
|
||||
|
||||
/* Configure GCLK generator 0 (Main Clock) */
|
||||
# define CONF_CLOCK_GCLK_0_ENABLE true
|
||||
# define CONF_CLOCK_GCLK_0_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_0_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
# define CONF_CLOCK_GCLK_0_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_0_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 1 */
|
||||
# define CONF_CLOCK_GCLK_1_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_1_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_1_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_XOSC32K
|
||||
# define CONF_CLOCK_GCLK_1_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_1_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 2 (RTC) */
|
||||
# define CONF_CLOCK_GCLK_2_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_2_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_2_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC32K
|
||||
# define CONF_CLOCK_GCLK_2_PRESCALER 32
|
||||
# define CONF_CLOCK_GCLK_2_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 3 */
|
||||
# define CONF_CLOCK_GCLK_3_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_3_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_3_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
# define CONF_CLOCK_GCLK_3_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_3_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 4 */
|
||||
# define CONF_CLOCK_GCLK_4_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_4_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_4_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
# define CONF_CLOCK_GCLK_4_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_4_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 5 */
|
||||
# define CONF_CLOCK_GCLK_5_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_5_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_5_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
# define CONF_CLOCK_GCLK_5_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_5_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 6 */
|
||||
# define CONF_CLOCK_GCLK_6_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_6_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_6_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
# define CONF_CLOCK_GCLK_6_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_6_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 7 */
|
||||
# define CONF_CLOCK_GCLK_7_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_7_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_7_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
# define CONF_CLOCK_GCLK_7_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_7_OUTPUT_ENABLE false
|
||||
|
||||
#endif /* CONF_CLOCKS_H_INCLUDED */
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief SAM D21/R21/DA/HA Clock configuration
|
||||
*
|
||||
* Copyright (C) 2013-2016 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#include <clock.h>
|
||||
|
||||
#ifndef CONF_CLOCKS_H_INCLUDED
|
||||
# define CONF_CLOCKS_H_INCLUDED
|
||||
|
||||
/* System clock bus configuration */
|
||||
# define CONF_CLOCK_CPU_CLOCK_FAILURE_DETECT false
|
||||
# define CONF_CLOCK_FLASH_WAIT_STATES 1
|
||||
# define CONF_CLOCK_CPU_DIVIDER SYSTEM_MAIN_CLOCK_DIV_1
|
||||
# define CONF_CLOCK_APBA_DIVIDER SYSTEM_MAIN_CLOCK_DIV_1
|
||||
# define CONF_CLOCK_APBB_DIVIDER SYSTEM_MAIN_CLOCK_DIV_1
|
||||
# define CONF_CLOCK_APBC_DIVIDER SYSTEM_MAIN_CLOCK_DIV_1
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_OSC8M configuration - Internal 8MHz oscillator */
|
||||
# define CONF_CLOCK_OSC8M_PRESCALER SYSTEM_OSC8M_DIV_1
|
||||
# define CONF_CLOCK_OSC8M_ON_DEMAND true
|
||||
# define CONF_CLOCK_OSC8M_RUN_IN_STANDBY false
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_XOSC configuration - External clock/oscillator */
|
||||
# define CONF_CLOCK_XOSC_ENABLE false
|
||||
# define CONF_CLOCK_XOSC_EXTERNAL_CRYSTAL SYSTEM_CLOCK_EXTERNAL_CRYSTAL
|
||||
# define CONF_CLOCK_XOSC_EXTERNAL_FREQUENCY 12000000UL
|
||||
# define CONF_CLOCK_XOSC_STARTUP_TIME SYSTEM_XOSC_STARTUP_32768
|
||||
# define CONF_CLOCK_XOSC_AUTO_GAIN_CONTROL true
|
||||
# define CONF_CLOCK_XOSC_ON_DEMAND true
|
||||
# define CONF_CLOCK_XOSC_RUN_IN_STANDBY false
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_XOSC32K configuration - External 32KHz crystal/clock oscillator */
|
||||
# define CONF_CLOCK_XOSC32K_ENABLE true
|
||||
# define CONF_CLOCK_XOSC32K_EXTERNAL_CRYSTAL SYSTEM_CLOCK_EXTERNAL_CRYSTAL
|
||||
# define CONF_CLOCK_XOSC32K_STARTUP_TIME SYSTEM_XOSC32K_STARTUP_2048
|
||||
# define CONF_CLOCK_XOSC32K_AUTO_AMPLITUDE_CONTROL true
|
||||
# define CONF_CLOCK_XOSC32K_ENABLE_1KHZ_OUPUT false
|
||||
# define CONF_CLOCK_XOSC32K_ENABLE_32KHZ_OUTPUT true
|
||||
# define CONF_CLOCK_XOSC32K_ON_DEMAND false
|
||||
# define CONF_CLOCK_XOSC32K_RUN_IN_STANDBY true
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_OSC32K configuration - Internal 32KHz oscillator */
|
||||
# define CONF_CLOCK_OSC32K_ENABLE false
|
||||
# define CONF_CLOCK_OSC32K_STARTUP_TIME SYSTEM_OSC32K_STARTUP_130
|
||||
# define CONF_CLOCK_OSC32K_ENABLE_1KHZ_OUTPUT true
|
||||
# define CONF_CLOCK_OSC32K_ENABLE_32KHZ_OUTPUT true
|
||||
# define CONF_CLOCK_OSC32K_ON_DEMAND true
|
||||
# define CONF_CLOCK_OSC32K_RUN_IN_STANDBY false
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_DFLL configuration - Digital Frequency Locked Loop */
|
||||
# define CONF_CLOCK_DFLL_ENABLE true
|
||||
# define CONF_CLOCK_DFLL_LOOP_MODE SYSTEM_CLOCK_DFLL_LOOP_MODE_OPEN
|
||||
# define CONF_CLOCK_DFLL_ON_DEMAND true
|
||||
|
||||
/* DFLL open loop mode configuration */
|
||||
# define CONF_CLOCK_DFLL_FINE_VALUE ((*((uint32_t*)(0x806020 + 8))) & 0x3FF)/*(512)*/
|
||||
|
||||
/* DFLL closed loop mode configuration */
|
||||
# define CONF_CLOCK_DFLL_SOURCE_GCLK_GENERATOR GCLK_GENERATOR_2
|
||||
# define CONF_CLOCK_DFLL_MULTIPLY_FACTOR (48000000 / 32768)
|
||||
# define CONF_CLOCK_DFLL_QUICK_LOCK true
|
||||
# define CONF_CLOCK_DFLL_TRACK_AFTER_FINE_LOCK true
|
||||
# define CONF_CLOCK_DFLL_KEEP_LOCK_ON_WAKEUP true
|
||||
# define CONF_CLOCK_DFLL_ENABLE_CHILL_CYCLE true
|
||||
# define CONF_CLOCK_DFLL_MAX_COARSE_STEP_SIZE ((*((uint8_t*)(0x806020 + 7))) >> 2)/*(0x1f / 4)*/
|
||||
# define CONF_CLOCK_DFLL_MAX_FINE_STEP_SIZE ((*((uint32_t*)(0x806020 + 8))) & 0x3FF)/*(0xff / 4)*/
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_DPLL configuration - Digital Phase-Locked Loop */
|
||||
# define CONF_CLOCK_DPLL_ENABLE false
|
||||
# define CONF_CLOCK_DPLL_ON_DEMAND true
|
||||
# define CONF_CLOCK_DPLL_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_DPLL_LOCK_BYPASS false
|
||||
# define CONF_CLOCK_DPLL_WAKE_UP_FAST false
|
||||
# define CONF_CLOCK_DPLL_LOW_POWER_ENABLE false
|
||||
|
||||
# define CONF_CLOCK_DPLL_LOCK_TIME SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_DEFAULT
|
||||
# define CONF_CLOCK_DPLL_REFERENCE_CLOCK SYSTEM_CLOCK_SOURCE_DPLL_REFERENCE_CLOCK_XOSC32K
|
||||
# define CONF_CLOCK_DPLL_FILTER SYSTEM_CLOCK_SOURCE_DPLL_FILTER_DEFAULT
|
||||
|
||||
# define CONF_CLOCK_DPLL_REFERENCE_FREQUENCY 32768
|
||||
# define CONF_CLOCK_DPLL_REFERENCE_DIVIDER 1
|
||||
# define CONF_CLOCK_DPLL_OUTPUT_FREQUENCY 48000000
|
||||
|
||||
/* DPLL GCLK reference configuration */
|
||||
# define CONF_CLOCK_DPLL_REFERENCE_GCLK_GENERATOR GCLK_GENERATOR_1
|
||||
/* DPLL GCLK lock timer configuration */
|
||||
# define CONF_CLOCK_DPLL_LOCK_GCLK_GENERATOR GCLK_GENERATOR_1
|
||||
|
||||
/* Set this to true to configure the GCLK when running clocks_init. If set to
|
||||
* false, none of the GCLK generators will be configured in clocks_init(). */
|
||||
# define CONF_CLOCK_CONFIGURE_GCLK true
|
||||
|
||||
/* Configure GCLK generator 0 (Main Clock) */
|
||||
# define CONF_CLOCK_GCLK_0_ENABLE true
|
||||
# define CONF_CLOCK_GCLK_0_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_0_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_DFLL
|
||||
# define CONF_CLOCK_GCLK_0_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_0_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 1 */
|
||||
# define CONF_CLOCK_GCLK_1_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_1_RUN_IN_STANDBY true
|
||||
# define CONF_CLOCK_GCLK_1_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_XOSC32K
|
||||
# define CONF_CLOCK_GCLK_1_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_1_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 2 (RTC) */
|
||||
# define CONF_CLOCK_GCLK_2_ENABLE true
|
||||
# define CONF_CLOCK_GCLK_2_RUN_IN_STANDBY true
|
||||
# define CONF_CLOCK_GCLK_2_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_XOSC32K
|
||||
# define CONF_CLOCK_GCLK_2_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_2_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 3 */
|
||||
# define CONF_CLOCK_GCLK_3_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_3_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_3_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
# define CONF_CLOCK_GCLK_3_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_3_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 4 */
|
||||
# define CONF_CLOCK_GCLK_4_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_4_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_4_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
# define CONF_CLOCK_GCLK_4_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_4_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 5 */
|
||||
# define CONF_CLOCK_GCLK_5_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_5_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_5_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
# define CONF_CLOCK_GCLK_5_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_5_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 6 */
|
||||
# define CONF_CLOCK_GCLK_6_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_6_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_6_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
# define CONF_CLOCK_GCLK_6_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_6_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 7 */
|
||||
# define CONF_CLOCK_GCLK_7_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_7_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_7_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
# define CONF_CLOCK_GCLK_7_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_7_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 8 */
|
||||
# define CONF_CLOCK_GCLK_8_ENABLE false
|
||||
# define CONF_CLOCK_GCLK_8_RUN_IN_STANDBY false
|
||||
# define CONF_CLOCK_GCLK_8_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
# define CONF_CLOCK_GCLK_8_PRESCALER 1
|
||||
# define CONF_CLOCK_GCLK_8_OUTPUT_ENABLE false
|
||||
|
||||
#endif /* CONF_CLOCKS_H_INCLUDED */
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief SAM D21 External Interrupt Driver Configuration Header
|
||||
*
|
||||
* Copyright (C) 2013-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef CONF_EXTINT_H_INCLUDED
|
||||
#define CONF_EXTINT_H_INCLUDED
|
||||
|
||||
# define EXTINT_CLOCK_SOURCE GCLK_GENERATOR_2
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
Import('RTT_ROOT')
|
||||
Import('rtconfig')
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
path = [cwd]
|
||||
|
||||
#remove other no use files
|
||||
#SrcRemove(src, 'i2c_iomaster.c')
|
||||
#SrcRemove(src, 'delay.c')
|
||||
|
||||
if rtconfig.DEVICE_SERIES == 'SAMD20':
|
||||
path += [cwd + '/../asflib_config', cwd + '/../asflib_config/clock_samd20']
|
||||
elif rtconfig.DEVICE_SERIES == 'SAMD21':
|
||||
path += [cwd + '/../asflib_config', cwd + '/../asflib_config/clock_samd21_r21_da_ha1']
|
||||
|
||||
group = DefineGroup('Board', src, depend = [''], CPPPATH = path)
|
||||
|
||||
Return('group')
|
||||
@@ -0,0 +1,102 @@
|
||||
#include "board.h"
|
||||
#include <clock.h>
|
||||
#include <gclk.h>
|
||||
#include <system.h>
|
||||
#include <rtthread.h>
|
||||
/**
|
||||
* This is the timer interrupt service routine.
|
||||
*
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
/* enter interrupt */
|
||||
rt_interrupt_enter();
|
||||
|
||||
rt_tick_increase();
|
||||
|
||||
/* leave interrupt */
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
|
||||
void configure_extosc32k(void);
|
||||
void configure_dfll_open_loop(void);
|
||||
|
||||
//! [setup]
|
||||
//! [config_extosc32k]
|
||||
void configure_extosc32k(void)
|
||||
{
|
||||
//! [config_extosc32k_config]
|
||||
struct system_clock_source_xosc32k_config config_ext32k;
|
||||
//! [config_extosc32k_config]
|
||||
//! [config_extosc32k_get_defaults]
|
||||
system_clock_source_xosc32k_get_config_defaults(&config_ext32k);
|
||||
//! [config_extosc32k_get_defaults]
|
||||
|
||||
//! [config_extosc32k_change_defaults]
|
||||
config_ext32k.startup_time = SYSTEM_XOSC32K_STARTUP_4096;
|
||||
config_ext32k.on_demand = false;
|
||||
//! [config_extosc32k_change_defaults]
|
||||
|
||||
//! [config_extosc32k_set_config]
|
||||
system_clock_source_xosc32k_set_config(&config_ext32k);
|
||||
//! [config_extosc32k_set_config]
|
||||
system_clock_source_enable(SYSTEM_CLOCK_SOURCE_XOSC32K);
|
||||
while(!system_clock_source_is_ready(SYSTEM_CLOCK_SOURCE_XOSC32K));
|
||||
}
|
||||
//! [config_extosc32k]
|
||||
|
||||
#if (!SAMC21)
|
||||
//! [config_dfll]
|
||||
void configure_dfll_open_loop(void)
|
||||
{
|
||||
//! [config_dfll_config]
|
||||
struct system_clock_source_dfll_config config_dfll;
|
||||
//! [config_dfll_config]
|
||||
//! [config_dfll_get_defaults]
|
||||
system_clock_source_dfll_get_config_defaults(&config_dfll);
|
||||
//! [config_dfll_get_defaults]
|
||||
config_dfll.coarse_value = (*((uint8_t*)(0x806020 + 7))) >> 2;// 0x1f / 4; /* Midpoint */
|
||||
config_dfll.fine_value = (*((uint32_t*)(0x806020 + 8))) & 0x3FF;//0xff / 4; /* Midpoint */
|
||||
//! [config_dfll_set_config]
|
||||
system_clock_source_dfll_set_config(&config_dfll);
|
||||
//! [config_dfll_set_config]
|
||||
|
||||
//! [enable_dfll_main]
|
||||
system_clock_source_enable(SYSTEM_CLOCK_SOURCE_DFLL);
|
||||
// while(!system_clock_source_is_ready(SYSTEM_CLOCK_SOURCE_DFLL));
|
||||
|
||||
//! [enable_dfll_main]
|
||||
/* Configure flash wait states before switching to high frequency clock */
|
||||
//! [set_sys_wait_states]
|
||||
system_flash_set_waitstates(2);
|
||||
//! [set_sys_wait_states]
|
||||
|
||||
/* Change system clock to DFLL */
|
||||
//! [set_sys_clk_src]
|
||||
struct system_gclk_gen_config config_gclock_gen;
|
||||
system_gclk_gen_get_config_defaults(&config_gclock_gen);
|
||||
config_gclock_gen.source_clock = SYSTEM_CLOCK_SOURCE_DFLL;
|
||||
config_gclock_gen.division_factor = 1;
|
||||
system_gclk_gen_set_config(GCLK_GENERATOR_0, &config_gclock_gen);
|
||||
//! [set_sys_clk_src]
|
||||
}
|
||||
//! [config_dfll]
|
||||
#endif
|
||||
|
||||
void rt_board_init(void)
|
||||
{
|
||||
extern void uart_init(void);
|
||||
|
||||
// configure_extosc32k();
|
||||
|
||||
// configure_dfll_open_loop();
|
||||
system_init();
|
||||
|
||||
/* initialize systick */
|
||||
SystemCoreClock = system_gclk_gen_get_hz(0);
|
||||
SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
|
||||
|
||||
uart_init();
|
||||
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/* This is a template file for board configuration created by MCUXpresso Project Generator. Enjoy! */
|
||||
|
||||
#ifndef _BOARD_H_
|
||||
#define _BOARD_H_
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
#include <stdint.h>
|
||||
#include "samd21.h"
|
||||
#include "system_samd21.h"
|
||||
#include "core_cm0plus.h" /* Core Peripheral Access Layer */
|
||||
|
||||
/* The board name */
|
||||
#define BOARD_NAME "###-not-specified-###"
|
||||
|
||||
#define CHIP_SRAM_END (0x20000000 + 32*1024)
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*!
|
||||
* @brief initialize debug console to enable printf for this demo/example
|
||||
*/
|
||||
void rt_board_init(void);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _BOARD_H_ */
|
||||
@@ -0,0 +1,126 @@
|
||||
// From module: RTC - Real Time Counter in Count Mode (Polled APIs)
|
||||
#include <rtc_count.h>
|
||||
#include <rtc_count_interrupt.h>
|
||||
// #include <rtc_tamper.h>
|
||||
#include <power.h>
|
||||
#include <port.h>
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/* RTC module instance */
|
||||
static struct rtc_module rtc_instance;
|
||||
|
||||
static void _rtc_timer_int_cb(void)
|
||||
{
|
||||
port_pin_toggle_output_level(PIN_PB30);
|
||||
}
|
||||
|
||||
/* Init RTC as ADC sample timer */
|
||||
static void _rtc_timer_init(void)
|
||||
{
|
||||
struct rtc_count_config conf;
|
||||
|
||||
rtc_count_get_config_defaults(&conf);
|
||||
|
||||
conf.prescaler = RTC_COUNT_PRESCALER_DIV_1;
|
||||
conf.mode = RTC_COUNT_MODE_32BIT;
|
||||
conf.clear_on_match = false;
|
||||
conf.compare_values[0] = 0;
|
||||
|
||||
// struct rtc_count_events evconfig;
|
||||
// evconfig.generate_event_on_compare[0] = true;
|
||||
|
||||
rtc_count_init(&rtc_instance, RTC, &conf);
|
||||
// rtc_count_enable_events(&rtc_instance, &evconfig);
|
||||
// rtc_count_enable(&rtc_instance);
|
||||
rtc_count_set_count(&rtc_instance, 0);
|
||||
rtc_count_register_callback(&rtc_instance, _rtc_timer_int_cb, RTC_COUNT_CALLBACK_COMPARE_0);
|
||||
// rtc_count_enable_callback(&rtc_instance, RTC_COUNT_CALLBACK_COMPARE_0);
|
||||
}
|
||||
|
||||
static void _rtc_timer_start(uint32_t ms)
|
||||
{
|
||||
uint32_t compare = 0;
|
||||
|
||||
compare = (uint32_t)(32.768 * ms);
|
||||
|
||||
// rtc_count_register_callback(&rtc_instance, _rtc_timer_int_cb, RTC_COUNT_CALLBACK_COMPARE_0);
|
||||
rtc_count_enable_callback(&rtc_instance, RTC_COUNT_CALLBACK_COMPARE_0);
|
||||
|
||||
rtc_count_set_count(&rtc_instance, 0);
|
||||
rtc_count_set_compare(&rtc_instance, compare, RTC_COUNT_COMPARE_0);
|
||||
rtc_count_enable(&rtc_instance);
|
||||
}
|
||||
|
||||
static void sleep_tick_adjust(uint32_t ms)
|
||||
{
|
||||
uint32_t diff;
|
||||
|
||||
diff = rt_tick_from_millisecond(ms);
|
||||
|
||||
rt_tick_set(rt_tick_get() + diff);
|
||||
{
|
||||
struct rt_thread *thread;
|
||||
|
||||
/* check time slice */
|
||||
thread = rt_thread_self();
|
||||
|
||||
if (thread->remaining_tick <= diff)
|
||||
{
|
||||
/* change to initialized tick */
|
||||
thread->remaining_tick = thread->init_tick;
|
||||
|
||||
/* yield */
|
||||
rt_thread_yield();
|
||||
}
|
||||
else
|
||||
{
|
||||
thread->remaining_tick -= diff;
|
||||
}
|
||||
|
||||
/* check timer */
|
||||
rt_timer_check();
|
||||
}
|
||||
}
|
||||
|
||||
static void _sleep_entry(void)
|
||||
{
|
||||
rt_tick_t timeout;
|
||||
rt_uint32_t ms;
|
||||
rt_uint32_t count;
|
||||
|
||||
system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY);
|
||||
timeout = rt_timer_next_timeout_tick() - rt_tick_get();
|
||||
|
||||
ms = timeout * (1000 / RT_TICK_PER_SECOND);
|
||||
rt_kprintf("os tick:%u entry sleep:%u tick\r\n", rt_tick_get(), timeout);
|
||||
|
||||
_rtc_timer_start(ms);
|
||||
|
||||
system_sleep();
|
||||
|
||||
rt_enter_critical();
|
||||
count = rtc_count_get_count(&rtc_instance);
|
||||
ms = (count + 32) / 32.768;
|
||||
rtc_count_disable(&rtc_instance);
|
||||
sleep_tick_adjust(ms);
|
||||
timeout = rt_tick_get();
|
||||
rt_exit_critical();
|
||||
rt_kprintf("sleep exited, os tick:%u\n", timeout);
|
||||
}
|
||||
|
||||
void sleep_timer_init(void)
|
||||
{
|
||||
_rtc_timer_init();
|
||||
rt_thread_idle_sethook(_sleep_entry);
|
||||
}
|
||||
|
||||
void sleep_timer_start(uint32_t ms)
|
||||
{
|
||||
_rtc_timer_start(ms);
|
||||
}
|
||||
|
||||
void sleep_timer_stop(void)
|
||||
{
|
||||
rtc_count_disable(&rtc_instance);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef _SLEEP_TIMER_H_
|
||||
#define _SLEEP_TIMER_H_
|
||||
|
||||
void sleep_timer_init(void);
|
||||
|
||||
void sleep_timer_start(uint32_t ms);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,94 @@
|
||||
/* RT-Thread config file */
|
||||
#ifndef __RTTHREAD_CFG_H__
|
||||
#define __RTTHREAD_CFG_H__
|
||||
|
||||
/* RT_NAME_MAX*/
|
||||
#define RT_NAME_MAX 6
|
||||
|
||||
/* RT_ALIGN_SIZE*/
|
||||
#define RT_ALIGN_SIZE 4
|
||||
|
||||
/* PRIORITY_MAX */
|
||||
#define RT_THREAD_PRIORITY_MAX 8
|
||||
|
||||
/* Tick per Second */
|
||||
#define RT_TICK_PER_SECOND 200
|
||||
|
||||
/* SECTION: RT_DEBUG */
|
||||
/* Thread Debug */
|
||||
#define RT_DEBUG
|
||||
//#define RT_DEBUG_INIT 1
|
||||
#define RT_USING_OVERFLOW_CHECK
|
||||
|
||||
/* Using Hook */
|
||||
#define RT_USING_HOOK
|
||||
|
||||
#define IDLE_THREAD_STACK_SIZE 512
|
||||
|
||||
/* Using Software Timer */
|
||||
/* #define RT_USING_TIMER_SOFT */
|
||||
#define RT_TIMER_THREAD_PRIO 4
|
||||
#define RT_TIMER_THREAD_STACK_SIZE 512
|
||||
#define RT_TIMER_TICK_PER_SECOND 100
|
||||
|
||||
/* SECTION: IPC */
|
||||
/* Using Semaphore*/
|
||||
#define RT_USING_SEMAPHORE
|
||||
|
||||
/* Using Mutex */
|
||||
#define RT_USING_MUTEX
|
||||
|
||||
/* Using Event */
|
||||
#define RT_USING_EVENT
|
||||
|
||||
/* Using MailBox */
|
||||
/* #define RT_USING_MAILBOX */
|
||||
|
||||
/* Using Message Queue */
|
||||
/* #define RT_USING_MESSAGEQUEUE */
|
||||
|
||||
/* SECTION: Memory Management */
|
||||
/* Using Memory Pool Management*/
|
||||
/* #define RT_USING_MEMPOOL */
|
||||
|
||||
/* Using Dynamic Heap Management */
|
||||
#define RT_USING_HEAP
|
||||
|
||||
/* Using Small MM */
|
||||
#define RT_USING_SMALL_MEM
|
||||
#define RT_USING_TINY_SIZE
|
||||
|
||||
// <bool name="RT_USING_COMPONENTS_INIT" description="Using RT-Thread components initialization" default="true" />
|
||||
//#define RT_USING_COMPONENTS_INIT
|
||||
|
||||
/* SECTION: Device System */
|
||||
/* Using Device System */
|
||||
#define RT_USING_DEVICE
|
||||
// <bool name="RT_USING_DEVICE_IPC" description="Using device communication" default="true" />
|
||||
#define RT_USING_DEVICE_IPC
|
||||
// <bool name="RT_USING_SERIAL" description="Using Serial" default="true" />
|
||||
#define RT_USING_SERIAL
|
||||
|
||||
/* SECTION: Console options */
|
||||
#define RT_USING_CONSOLE
|
||||
/* the buffer size of console*/
|
||||
#define RT_CONSOLEBUF_SIZE 128
|
||||
// <string name="RT_CONSOLE_DEVICE_NAME" description="The device name for console" default="uart1" />
|
||||
#define RT_CONSOLE_DEVICE_NAME "uart3"
|
||||
|
||||
// #define RT_USING_SPI
|
||||
|
||||
/* SECTION: finsh, a C-Express shell */
|
||||
// #define RT_USING_FINSH
|
||||
/* configure finsh parameters */
|
||||
#define FINSH_THREAD_PRIORITY 6
|
||||
#define FINSH_THREAD_STACK_SIZE 512
|
||||
#define FINSH_HISTORY_LINES 1
|
||||
/* Using symbol table */
|
||||
// #define FINSH_USING_SYMTAB
|
||||
// #define FINSH_USING_DESCRIPTION
|
||||
|
||||
// #define FINSH_USING_MSH
|
||||
// #define FINSH_USING_MSH_ONLY
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,88 @@
|
||||
import os
|
||||
|
||||
# toolchains options
|
||||
ARCH='arm'
|
||||
CPU='cortex-m0'
|
||||
CROSS_TOOL='keil'
|
||||
|
||||
if os.getenv('RTT_CC'):
|
||||
CROSS_TOOL = os.getenv('RTT_CC')
|
||||
|
||||
#DEVICE_SERIES = 'SAMD20'
|
||||
DEVICE_SERIES = 'SAMD21'
|
||||
#DEVICE_TYPE = '__SAMD20G18A__'
|
||||
DEVICE_TYPE = '__SAMD21J18A__'
|
||||
|
||||
# cross_tool provides the cross compiler
|
||||
# EXEC_PATH is the compiler execute path, for example, CodeSourcery, Keil MDK, IAR
|
||||
if CROSS_TOOL == 'gcc':
|
||||
PLATFORM = 'gcc'
|
||||
EXEC_PATH = 'C:/Program Files/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin'
|
||||
elif CROSS_TOOL == 'keil':
|
||||
PLATFORM = 'armcc'
|
||||
EXEC_PATH = 'C:/Keil'
|
||||
elif CROSS_TOOL == 'iar':
|
||||
print '================ERROR============================'
|
||||
print 'Not support iar yet!'
|
||||
print '================================================='
|
||||
exit(0)
|
||||
|
||||
if os.getenv('RTT_EXEC_PATH'):
|
||||
EXEC_PATH = os.getenv('RTT_EXEC_PATH')
|
||||
|
||||
BUILD = 'debug'
|
||||
|
||||
if PLATFORM == 'gcc':
|
||||
# toolchains
|
||||
PREFIX = 'arm-none-eabi-'
|
||||
CC = PREFIX + 'gcc'
|
||||
AS = PREFIX + 'gcc'
|
||||
AR = PREFIX + 'ar'
|
||||
LINK = PREFIX + 'gcc'
|
||||
TARGET_EXT = 'axf'
|
||||
SIZE = PREFIX + 'size'
|
||||
OBJDUMP = PREFIX + 'objdump'
|
||||
OBJCPY = PREFIX + 'objcopy'
|
||||
|
||||
DEVICE = ' -mcpu=cortex-m0+ -mthumb -ffunction-sections -fdata-sections'
|
||||
CFLAGS = DEVICE
|
||||
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
|
||||
LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-MKL15Z128.map,-cref,-u,Reset_Handler -T MKL15Z128_FLASH.ld'
|
||||
|
||||
CPATH = ''
|
||||
LPATH = ''
|
||||
|
||||
if BUILD == 'debug':
|
||||
CFLAGS += ' -O0 -gdwarf-2'
|
||||
AFLAGS += ' -gdwarf-2'
|
||||
else:
|
||||
CFLAGS += ' -O2'
|
||||
|
||||
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n'
|
||||
|
||||
elif PLATFORM == 'armcc':
|
||||
# toolchains
|
||||
CC = 'armcc'
|
||||
AS = 'armasm'
|
||||
AR = 'armar'
|
||||
LINK = 'armlink'
|
||||
TARGET_EXT = 'axf'
|
||||
|
||||
DEVICE = ' --device DARMSTM'
|
||||
CFLAGS = DEVICE + ' --apcs=interwork'
|
||||
AFLAGS = DEVICE
|
||||
LFLAGS = DEVICE + ' --info sizes --info totals --info unused --info veneers --list rtthread-SAM_D2x.map --strict --scatter SAM_D2X_RTT.sct'
|
||||
|
||||
CFLAGS += ' --c99'
|
||||
CFLAGS += ' -I' + EXEC_PATH + '/ARM/RV31/INC'
|
||||
LFLAGS += ' --libpath ' + EXEC_PATH + '/ARM/RV31/LIB'
|
||||
|
||||
EXEC_PATH += '/arm/bin40/'
|
||||
|
||||
if BUILD == 'debug':
|
||||
CFLAGS += ' -g -O0'
|
||||
AFLAGS += ' -g'
|
||||
else:
|
||||
CFLAGS += ' -O2'
|
||||
|
||||
POST_ACTION = 'fromelf --bin $TARGET --output rtthread.bin \nfromelf -z $TARGET'
|
||||
@@ -0,0 +1,136 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
* Copyright (C) 2010-2014 ARM Limited. All rights reserved.
|
||||
*
|
||||
* $Date: 31. July 2014
|
||||
* $Revision: V1.4.4
|
||||
*
|
||||
* Project: CMSIS DSP Library
|
||||
* Title: arm_common_tables.h
|
||||
*
|
||||
* Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions
|
||||
*
|
||||
* Target Processor: Cortex-M4/Cortex-M3
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM LIMITED nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _ARM_COMMON_TABLES_H
|
||||
#define _ARM_COMMON_TABLES_H
|
||||
|
||||
#include "arm_math.h"
|
||||
|
||||
extern const uint16_t armBitRevTable[1024];
|
||||
extern const q15_t armRecipTableQ15[64];
|
||||
extern const q31_t armRecipTableQ31[64];
|
||||
//extern const q31_t realCoefAQ31[1024];
|
||||
//extern const q31_t realCoefBQ31[1024];
|
||||
extern const float32_t twiddleCoef_16[32];
|
||||
extern const float32_t twiddleCoef_32[64];
|
||||
extern const float32_t twiddleCoef_64[128];
|
||||
extern const float32_t twiddleCoef_128[256];
|
||||
extern const float32_t twiddleCoef_256[512];
|
||||
extern const float32_t twiddleCoef_512[1024];
|
||||
extern const float32_t twiddleCoef_1024[2048];
|
||||
extern const float32_t twiddleCoef_2048[4096];
|
||||
extern const float32_t twiddleCoef_4096[8192];
|
||||
#define twiddleCoef twiddleCoef_4096
|
||||
extern const q31_t twiddleCoef_16_q31[24];
|
||||
extern const q31_t twiddleCoef_32_q31[48];
|
||||
extern const q31_t twiddleCoef_64_q31[96];
|
||||
extern const q31_t twiddleCoef_128_q31[192];
|
||||
extern const q31_t twiddleCoef_256_q31[384];
|
||||
extern const q31_t twiddleCoef_512_q31[768];
|
||||
extern const q31_t twiddleCoef_1024_q31[1536];
|
||||
extern const q31_t twiddleCoef_2048_q31[3072];
|
||||
extern const q31_t twiddleCoef_4096_q31[6144];
|
||||
extern const q15_t twiddleCoef_16_q15[24];
|
||||
extern const q15_t twiddleCoef_32_q15[48];
|
||||
extern const q15_t twiddleCoef_64_q15[96];
|
||||
extern const q15_t twiddleCoef_128_q15[192];
|
||||
extern const q15_t twiddleCoef_256_q15[384];
|
||||
extern const q15_t twiddleCoef_512_q15[768];
|
||||
extern const q15_t twiddleCoef_1024_q15[1536];
|
||||
extern const q15_t twiddleCoef_2048_q15[3072];
|
||||
extern const q15_t twiddleCoef_4096_q15[6144];
|
||||
extern const float32_t twiddleCoef_rfft_32[32];
|
||||
extern const float32_t twiddleCoef_rfft_64[64];
|
||||
extern const float32_t twiddleCoef_rfft_128[128];
|
||||
extern const float32_t twiddleCoef_rfft_256[256];
|
||||
extern const float32_t twiddleCoef_rfft_512[512];
|
||||
extern const float32_t twiddleCoef_rfft_1024[1024];
|
||||
extern const float32_t twiddleCoef_rfft_2048[2048];
|
||||
extern const float32_t twiddleCoef_rfft_4096[4096];
|
||||
|
||||
|
||||
/* floating-point bit reversal tables */
|
||||
#define ARMBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20 )
|
||||
#define ARMBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48 )
|
||||
#define ARMBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56 )
|
||||
#define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 )
|
||||
#define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 )
|
||||
#define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 )
|
||||
#define ARMBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800)
|
||||
#define ARMBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808)
|
||||
#define ARMBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032)
|
||||
|
||||
extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE__16_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE__32_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE__64_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE1024_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE2048_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE4096_TABLE_LENGTH];
|
||||
|
||||
/* fixed-point bit reversal tables */
|
||||
#define ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH ((uint16_t)12 )
|
||||
#define ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH ((uint16_t)24 )
|
||||
#define ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH ((uint16_t)56 )
|
||||
#define ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH ((uint16_t)112 )
|
||||
#define ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH ((uint16_t)240 )
|
||||
#define ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH ((uint16_t)480 )
|
||||
#define ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 )
|
||||
#define ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984)
|
||||
#define ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032)
|
||||
|
||||
extern const uint16_t armBitRevIndexTable_fixed_16[ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable_fixed_32[ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable_fixed_64[ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable_fixed_128[ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable_fixed_256[ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable_fixed_512[ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable_fixed_1024[ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable_fixed_2048[ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH];
|
||||
extern const uint16_t armBitRevIndexTable_fixed_4096[ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH];
|
||||
|
||||
/* Tables for Fast Math Sine and Cosine */
|
||||
extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1];
|
||||
extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1];
|
||||
extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1];
|
||||
|
||||
#endif /* ARM_COMMON_TABLES_H */
|
||||
@@ -0,0 +1,79 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
* Copyright (C) 2010-2014 ARM Limited. All rights reserved.
|
||||
*
|
||||
* $Date: 31. July 2014
|
||||
* $Revision: V1.4.4
|
||||
*
|
||||
* Project: CMSIS DSP Library
|
||||
* Title: arm_const_structs.h
|
||||
*
|
||||
* Description: This file has constant structs that are initialized for
|
||||
* user convenience. For example, some can be given as
|
||||
* arguments to the arm_cfft_f32() function.
|
||||
*
|
||||
* Target Processor: Cortex-M4/Cortex-M3
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM LIMITED nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _ARM_CONST_STRUCTS_H
|
||||
#define _ARM_CONST_STRUCTS_H
|
||||
|
||||
#include "arm_math.h"
|
||||
#include "arm_common_tables.h"
|
||||
|
||||
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16;
|
||||
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32;
|
||||
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64;
|
||||
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128;
|
||||
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256;
|
||||
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512;
|
||||
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024;
|
||||
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048;
|
||||
extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096;
|
||||
|
||||
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len16;
|
||||
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len32;
|
||||
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len64;
|
||||
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len128;
|
||||
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len256;
|
||||
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len512;
|
||||
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len1024;
|
||||
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len2048;
|
||||
extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096;
|
||||
|
||||
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len16;
|
||||
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len32;
|
||||
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len64;
|
||||
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len128;
|
||||
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len256;
|
||||
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len512;
|
||||
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len1024;
|
||||
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len2048;
|
||||
extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len4096;
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,92 @@
|
||||
Import('RTT_ROOT')
|
||||
Import('rtconfig')
|
||||
from building import *
|
||||
|
||||
# get current directory
|
||||
cwd = GetCurrentDir()
|
||||
|
||||
#var defined
|
||||
CPPDEFINES = []
|
||||
src = []
|
||||
path = []
|
||||
|
||||
#common lib define
|
||||
CPPDEFINES += [rtconfig.DEVICE_TYPE, 'DEBUG']
|
||||
|
||||
#CMSIS/Include/ common/ common2/service/delay
|
||||
path += [cwd + '/CMSIS/Include/']
|
||||
path += [cwd + '/common/utils/', cwd + '/common/utils/interrupt/']
|
||||
path += [cwd + '/common/boards/']
|
||||
path += [cwd + '/common2/services/delay/', cwd + '/common2/services/delay/sam0/']
|
||||
src += Glob('./common/utils/interrupt/interrupt_sam_nvic.c')
|
||||
|
||||
#sam0/ sam0/utils/
|
||||
path += [cwd + '/sam0/', cwd + '/sam0/utils/']
|
||||
path += [cwd + '/sam0/utils/preprocessor']
|
||||
path += [cwd + '/sam0/utils/header_files']
|
||||
|
||||
#sam0/utils/cmsis/
|
||||
if rtconfig.DEVICE_SERIES == 'SAMD20':
|
||||
#D20
|
||||
path += [cwd + '/sam0/', cwd + '/sam0/utils/cmsis/samd20/include/']
|
||||
path += [cwd + '/sam0/utils/cmsis/samd20/source/']
|
||||
src += Glob('./sam0/utils/cmsis/samd20/source/*.c')
|
||||
src += Glob('./sam0/utils/cmsis/samd20/source/arm/*.s')
|
||||
elif rtconfig.DEVICE_SERIES == 'SAMD21':
|
||||
#D21
|
||||
path += [cwd + '/sam0/utils/cmsis/samd21/include/']
|
||||
path += [cwd + '/sam0/utils/cmsis/samd21/source/']
|
||||
src += Glob('./sam0/utils/cmsis/samd21/source/*.c')
|
||||
src += Glob('./sam0/utils/cmsis/samd21/source/arm/*.s')
|
||||
|
||||
#sam0/drivers/system
|
||||
path += [cwd + '/sam0/drivers/system/']
|
||||
src += Glob('./sam0/drivers/system/system.c')
|
||||
path += [cwd + '/sam0/drivers/system/pinmux']
|
||||
src += Glob('./sam0/drivers/system/pinmux/*.c')
|
||||
path += [cwd + '/sam0/drivers/system/power/power_sam_d_r_h']
|
||||
path += [cwd + '/sam0/drivers/system/reset/reset_sam_d_r_h']
|
||||
path += [cwd + '/sam0/drivers/system/clock']
|
||||
path += [cwd + '/sam0/drivers/system/interrupt/']
|
||||
src += Glob('./sam0/drivers/system/interrupt/*.c')
|
||||
if rtconfig.DEVICE_SERIES == 'SAMD20':
|
||||
path += [cwd + '/sam0/drivers/system/interrupt/system_interrupt_samd20/']
|
||||
elif rtconfig.DEVICE_SERIES == 'SAMD21':
|
||||
path += [cwd + '/sam0/drivers/system/interrupt/system_interrupt_samd21/']
|
||||
|
||||
#sam0/drivers/system/clock
|
||||
if rtconfig.DEVICE_SERIES == 'SAMD20':
|
||||
path += [cwd + '/sam0/drivers/system/clock/clock_samd20']
|
||||
#path += [cwd + '/sam0/drivers/system/clock/clock_samd20/module_config']
|
||||
src += Glob('./sam0/drivers/system/clock/clock_samd20/*.c')
|
||||
elif rtconfig.DEVICE_SERIES == 'SAMD21':
|
||||
#path += [cwd + '/sam0/drivers/system/clock/clock_samd21_r21_da_ha1/module_config']
|
||||
path += [cwd + '/sam0/drivers/system/clock/clock_samd21_r21_da_ha1']
|
||||
src += Glob('./sam0/drivers/system/clock/clock_samd21_r21_da_ha1/*.c')
|
||||
|
||||
#sam0/drivers/sercom
|
||||
path += [cwd + '/sam0/drivers/sercom', cwd + '/sam0/drivers/sercom/usart']
|
||||
src += Glob('./sam0/drivers/sercom/*.c')
|
||||
src += Glob('./sam0/drivers/sercom/usart/*.c')
|
||||
SrcRemove(src, 'sercom_interrupt.c')
|
||||
SrcRemove(src, 'usart_interrupt.c')
|
||||
CPPDEFINES += ['USART_CALLBACK_MODE=false']
|
||||
|
||||
#sam0/drivers/port
|
||||
path += [cwd + '/sam0/drivers/port']
|
||||
src += Glob('./sam0/drivers/port/port.c')
|
||||
|
||||
#sam0/drivers/rtc
|
||||
path += [cwd + '/sam0/drivers/rtc']
|
||||
src += Glob('./sam0/drivers/rtc/rtc_sam_d_r_h/rtc_count*.c')
|
||||
CPPDEFINES += ['RTC_COUNT_ASYNC=true']
|
||||
|
||||
#sam0/drivers/extint
|
||||
path += [cwd + '/sam0/drivers/extint', cwd + '/sam0/drivers/extint/extint_sam_d_r_h']
|
||||
src += Glob('./sam0/drivers/extint/extint_callback.c')
|
||||
src += Glob('./sam0/drivers/extint/extint_sam_d_r_h/extint.c')
|
||||
CPPDEFINES += ['EXTINT_CALLBACK_MODE=true']
|
||||
|
||||
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)
|
||||
|
||||
Return('group')
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief SECURITY_XPLAINED extension board adaptation.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2011-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
|
||||
#include "security_xplained.h"
|
||||
#include "sha204_physical.h"
|
||||
#include "conf_atsha204.h"
|
||||
|
||||
|
||||
//! TWI address used at SHA204 library startup
|
||||
#define SHA204_I2C_DEFAULT_ADDRESS (0xCA)
|
||||
|
||||
|
||||
/** \brief This function initializes peripherals needed to communicate with
|
||||
* the I2C security devices (ATSHA204 and ATAES132).
|
||||
*/
|
||||
void security_board_init(void)
|
||||
{
|
||||
sha204p_init();
|
||||
}
|
||||
|
||||
|
||||
/** \brief This function returns the I2C address of a chosen SHA204 device.
|
||||
* \param[in] index the selected device on the Security Xplained board
|
||||
* \return I2C address of chosen device
|
||||
*/
|
||||
uint8_t sha204_i2c_address(uint8_t index)
|
||||
{
|
||||
static uint8_t i2c_addresses[SHA204_DEVICE_COUNT] = {SHA204_I2C_DEFAULT_ADDRESS, 0xCC, 0xCE, 0xF8};
|
||||
return i2c_addresses[index % SHA204_DEVICE_COUNT];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief SECURITY_XPLAINED_BOARD board header file.
|
||||
*
|
||||
* This file contains definitions and services related to the features of the
|
||||
* SECURITY_XPLAINED Xplained board.
|
||||
*
|
||||
* To use the board, define EXT_BOARD=SECURITY_XPLAINED.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2011-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef SECURITY_XPLAINED_H_
|
||||
# define SECURITY_XPLAINED_H_
|
||||
|
||||
#include <compiler.h>
|
||||
|
||||
//! number of ATSHA204 I2C devices on Security Xplained extension board
|
||||
#define SHA204_DEVICE_COUNT (4)
|
||||
|
||||
void security_board_init(void);
|
||||
uint8_t sha204_i2c_address(uint8_t index);
|
||||
|
||||
#endif /* SECURITY_XPLAINED_H_ */
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief User board configuration template
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef CONF_BOARD_H
|
||||
#define CONF_BOARD_H
|
||||
|
||||
#endif // CONF_BOARD_H
|
||||
@@ -0,0 +1 @@
|
||||
# This file needs to be customized to your MCU and is intentionally left blank
|
||||
@@ -0,0 +1,3 @@
|
||||
// This file needs to be customized to your MCU and is intentionally left blank /**
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
@@ -0,0 +1 @@
|
||||
# This file needs to be customized to your MCU and is intentionally left blank
|
||||
@@ -0,0 +1,3 @@
|
||||
// This file needs to be customized to your MCU and is intentionally left blank /**
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief User board initialization template
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#include <asf.h>
|
||||
#include <board.h>
|
||||
#include <conf_board.h>
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
/* This function is meant to contain board-specific initialization code
|
||||
* for, e.g., the I/O pins. The initialization can rely on application-
|
||||
* specific board configuration, found in conf_board.h.
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief User board definition template
|
||||
*
|
||||
*/
|
||||
|
||||
/* This file is intended to contain definitions and configuration details for
|
||||
* features and devices that are available on the board, e.g., frequency and
|
||||
* startup time for an external crystal, external memory devices, LED and USART
|
||||
* pins.
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef USER_BOARD_H
|
||||
#define USER_BOARD_H
|
||||
|
||||
#include <conf_board.h>
|
||||
|
||||
// External oscillator settings.
|
||||
// Uncomment and set correct values if external oscillator is used.
|
||||
|
||||
// External oscillator frequency
|
||||
//#define BOARD_XOSC_HZ 8000000
|
||||
|
||||
// External oscillator type.
|
||||
//!< External clock signal
|
||||
//#define BOARD_XOSC_TYPE XOSC_TYPE_EXTERNAL
|
||||
//!< 32.768 kHz resonator on TOSC
|
||||
//#define BOARD_XOSC_TYPE XOSC_TYPE_32KHZ
|
||||
//!< 0.4 to 16 MHz resonator on XTALS
|
||||
//#define BOARD_XOSC_TYPE XOSC_TYPE_XTAL
|
||||
|
||||
// External oscillator startup time
|
||||
//#define BOARD_XOSC_STARTUP_US 500000
|
||||
|
||||
|
||||
#endif // USER_BOARD_H
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ATSHA204 CryptoAuth driver configuration file
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2011-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef CONF_ATSHA204_H_INCLUDED
|
||||
#define CONF_ATSHA204_H_INCLUDED
|
||||
|
||||
#include <board.h>
|
||||
|
||||
#if BOARD == XMEGA_A1_XPLAINED
|
||||
// Interface configuration for XMEGA-A1 Xplained
|
||||
# define ATSHA204_TWI_PORT (&TWIC)
|
||||
|
||||
#else
|
||||
// Interface configuration for other boards
|
||||
# warning ATSHA204 TWI port is not set for your board. Please see conf_atsha204.h.
|
||||
# define ATSHA204_TWI_PORT (&TWIC)
|
||||
#endif // BOARD
|
||||
|
||||
// Xplain board independent configuration
|
||||
#define ATSHA204_TWI_SPEED (400000)
|
||||
|
||||
//! TWI address used at SHA204 library startup
|
||||
#define SHA204_I2C_DEFAULT_ADDRESS (0xCA)
|
||||
|
||||
#endif /* CONF_ATSHA204_H_INCLUDED */
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* \file
|
||||
*
|
||||
* \brief ATSHA204 header file for the communication layer for the device
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2011-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef SHA204_COMM_H
|
||||
# define SHA204_COMM_H
|
||||
|
||||
#include <compiler.h> //!< compiler dependent definitions
|
||||
|
||||
#include "sha204_physical.h" //!< declarations that are common to all interface implementations
|
||||
|
||||
//! maximum command delay
|
||||
#define SHA204_COMMAND_EXEC_MAX (69)
|
||||
|
||||
//! minimum number of bytes in command (from count byte to second CRC byte)
|
||||
#define SHA204_CMD_SIZE_MIN ((uint8_t) 7)
|
||||
|
||||
//! maximum size of command packet (CheckMac)
|
||||
#define SHA204_CMD_SIZE_MAX ((uint8_t) 84)
|
||||
|
||||
//! number of CRC bytes
|
||||
#define SHA204_CRC_SIZE ((uint8_t) 2)
|
||||
|
||||
//! buffer index of status byte in status response
|
||||
#define SHA204_BUFFER_POS_STATUS (1)
|
||||
|
||||
//! buffer index of first data byte in data response
|
||||
#define SHA204_BUFFER_POS_DATA (1)
|
||||
|
||||
//! status byte after wake-up
|
||||
#define SHA204_STATUS_BYTE_WAKEUP ((uint8_t) 0x11)
|
||||
|
||||
//! command parse error
|
||||
#define SHA204_STATUS_BYTE_PARSE ((uint8_t) 0x03)
|
||||
|
||||
//! command execution error
|
||||
#define SHA204_STATUS_BYTE_EXEC ((uint8_t) 0x0F)
|
||||
|
||||
//! communication error
|
||||
#define SHA204_STATUS_BYTE_COMM ((uint8_t) 0xFF)
|
||||
|
||||
/**
|
||||
* \brief This structure contains the parameters for the \ref sha204c_send_and_receive function.
|
||||
*/
|
||||
struct sha204_send_and_receive_parameters {
|
||||
uint8_t *tx_buffer; //!< pointer to send buffer
|
||||
uint8_t rx_size; //!< size of receive buffer
|
||||
uint8_t *rx_buffer; //!< pointer to receive buffer
|
||||
uint8_t poll_delay; //!< how long to wait before polling for response-ready
|
||||
uint8_t poll_timeout; //!< how long to poll before timing out
|
||||
};
|
||||
|
||||
/**
|
||||
* \defgroup sha204_communication_group SHA204 Service - hardware independent communication functions
|
||||
* @{
|
||||
*/
|
||||
void sha204c_calculate_crc(uint8_t length, uint8_t *data, uint8_t *crc);
|
||||
uint8_t sha204c_wakeup(uint8_t *response);
|
||||
uint8_t sha204c_send_and_receive(struct sha204_send_and_receive_parameters *args);
|
||||
//! @}
|
||||
|
||||
#endif
|
||||
+755
File diff suppressed because it is too large.
Load diff
+539
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* \file
|
||||
*
|
||||
* \brief Definitions for Configurable Values of the ATSHA204 Library
|
||||
*
|
||||
* This file contains configurations for the ATSHA204 modules.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2011-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef SHA204_CONFIG_H
|
||||
# define SHA204_CONFIG_H
|
||||
|
||||
/** \brief number of command / response retries
|
||||
*
|
||||
* If communication is lost, re-synchronization includes waiting for the
|
||||
* longest possible execution time of a command.
|
||||
* This adds a #SHA204_COMMAND_EXEC_MAX delay to every retry.
|
||||
* Every increment of the number of retries increases the time
|
||||
* the library is spending in the retry loop by #SHA204_COMMAND_EXEC_MAX.
|
||||
*/
|
||||
#define SHA204_RETRY_COUNT (1)
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* \file
|
||||
*
|
||||
* \brief ATSHA204 library return codes
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2011-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef SHA204_LIB_RETURN_CODES_H
|
||||
# define SHA204_LIB_RETURN_CODES_H
|
||||
|
||||
#include <compiler.h> //!< compiler dependent definitions
|
||||
|
||||
#define SHA204_SUCCESS ((uint8_t) 0x00) //!< Function succeeded.
|
||||
#define SHA204_PARSE_ERROR ((uint8_t) 0xD2) //!< response status byte indicates parsing error
|
||||
#define SHA204_CMD_FAIL ((uint8_t) 0xD3) //!< response status byte indicates command execution error
|
||||
#define SHA204_STATUS_CRC ((uint8_t) 0xD4) //!< response status byte indicates CRC error
|
||||
#define SHA204_FUNC_FAIL ((uint8_t) 0xE0) //!< Function could not execute due to incorrect condition / state.
|
||||
#define SHA204_BAD_PARAM ((uint8_t) 0xE2) //!< bad argument (out of range, null pointer, etc.)
|
||||
#define SHA204_INVALID_SIZE ((uint8_t) 0xE4) //!< Count value is out of range or greater than buffer size.
|
||||
#define SHA204_BAD_CRC ((uint8_t) 0xE5) //!< incorrect CRC received
|
||||
#define SHA204_RX_FAIL ((uint8_t) 0xE6) //!< Timed out while waiting for response. Number of bytes received is > 0.
|
||||
#define SHA204_RX_NO_RESPONSE ((uint8_t) 0xE7) //!< Not an error while the Command layer is polling for a command response.
|
||||
#define SHA204_RESYNC_WITH_WAKEUP ((uint8_t) 0xE8) //!< re-synchronization succeeded, but only after generating a Wake-up
|
||||
|
||||
#define SHA204_COMM_FAIL ((uint8_t) 0xF0) //!< Communication with device failed. Same as in hardware dependent modules.
|
||||
#define SHA204_TIMEOUT ((uint8_t) 0xF1) //!< Timed out while waiting for response. Number of bytes received is 0.
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* \file
|
||||
*
|
||||
* \brief ATSHA204 header file for the I2C layer for the device
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2011-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef SHA204_PHYSICAL_H
|
||||
# define SHA204_PHYSICAL_H
|
||||
|
||||
#include "sha204_config.h" //!< configuration values
|
||||
|
||||
#define SHA204_RSP_SIZE_MIN ((uint8_t) 4) //!< minimum number of bytes in response
|
||||
#define SHA204_RSP_SIZE_MAX ((uint8_t) 35) //!< maximum size of response packet
|
||||
|
||||
#define SHA204_BUFFER_POS_COUNT (0) //!< buffer index of count byte in command or response
|
||||
#define SHA204_BUFFER_POS_DATA (1) //!< buffer index of data in response
|
||||
|
||||
//! delay between Wakeup pulse and communication in ms
|
||||
#define SHA204_WAKEUP_DELAY (3)
|
||||
/**
|
||||
* \defgroup sha204_communication_physical_group SHA204 Service - hardware dependent communication functions
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
void sha204p_init(void);
|
||||
void sha204p_set_device_id(uint8_t id);
|
||||
uint8_t sha204p_send_command(uint8_t count, uint8_t *command);
|
||||
uint8_t sha204p_receive_response(uint8_t size, uint8_t *response);
|
||||
uint8_t sha204p_wakeup(void);
|
||||
uint8_t sha204p_idle(void);
|
||||
uint8_t sha204p_sleep(void);
|
||||
uint8_t sha204p_reset_io(void);
|
||||
uint8_t sha204p_resync(uint8_t size, uint8_t *response);
|
||||
//! @}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Non volatile memories management for SAM devices
|
||||
*
|
||||
* Copyright (c) 2014-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef CONF_NVM_H_INCLUDED
|
||||
#define CONF_NVM_H_INCLUDED
|
||||
|
||||
#endif /* CONF_NVM_H_INCLUDED */
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ADP interface header file
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef ADP_INTERFACE_H_INCLUDED
|
||||
#define ADP_INTERFACE_H_INCLUDED
|
||||
|
||||
/* Prototypes of communication functions used to setup, send and receive data */
|
||||
enum status_code adp_interface_init(void);
|
||||
void adp_interface_transceive_procotol(uint8_t* tx_buf, uint16_t length, uint8_t* rx_buf);
|
||||
enum status_code adp_interface_read_response(uint8_t* rx_buf, uint16_t length);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ADP SPI interface implementation
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#include <compiler.h>
|
||||
#include <asf.h>
|
||||
#include "adp_interface.h"
|
||||
|
||||
//! \name Embedded debugger SPI interface definitions
|
||||
//@{
|
||||
#define EDBG_SPI_MODULE SPI
|
||||
//@}
|
||||
|
||||
#define SPI_CHIP_SEL SPI_NPCS3_PA5_GPIO
|
||||
|
||||
#define SPI_DEVICE_ID 3
|
||||
#define SPI_BAUDRATE 1500000
|
||||
|
||||
struct spi_device SPI_DEVICE = {
|
||||
/** Board specific select id */
|
||||
.id = SPI_DEVICE_ID
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Send SPI start condition
|
||||
*
|
||||
*/
|
||||
static void adp_interface_send_start(void)
|
||||
{
|
||||
spi_select_device(EDBG_SPI_MODULE, &SPI_DEVICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Send SPI stop condition
|
||||
*
|
||||
*/
|
||||
static void adp_interface_send_stop(void)
|
||||
{
|
||||
spi_deselect_device(EDBG_SPI_MODULE, &SPI_DEVICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sends and reads data byte on SPI
|
||||
*
|
||||
* \param[in] data Data byte to send
|
||||
* \param[in] tx_data SPI character to transmit
|
||||
* \param[out] rx_data Pointer to store the received SPI character
|
||||
*/
|
||||
static void adp_interface_transceive(uint8_t *tx_data, uint8_t *rx_data, uint16_t length)
|
||||
{
|
||||
spi_transceive_packet(EDBG_SPI_MODULE, tx_data, rx_data, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Initialize EDBG SPI communication for SAM
|
||||
*
|
||||
*/
|
||||
enum status_code adp_interface_init(void)
|
||||
{
|
||||
sysclk_init();
|
||||
|
||||
/* Configure the SPI interface */
|
||||
spi_master_init(EDBG_SPI_MODULE);
|
||||
spi_master_setup_device(EDBG_SPI_MODULE, &SPI_DEVICE, SPI_MODE_0,
|
||||
SPI_BAUDRATE, 0);
|
||||
spi_enable(EDBG_SPI_MODULE);
|
||||
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sends and reads protocol packet data byte on SPI
|
||||
*
|
||||
* \param[in] tx_buf Pointer to send the protocol packet data
|
||||
* \param[in] length The length of the send protocol packet data
|
||||
* \param[out] rx_buf Pointer to store the received SPI character
|
||||
*/
|
||||
void adp_interface_transceive_procotol(uint8_t* tx_buf, uint16_t length, uint8_t* rx_buf)
|
||||
{
|
||||
/* Send SPI start condition */
|
||||
adp_interface_send_start();
|
||||
|
||||
adp_interface_transceive(tx_buf, rx_buf, length);
|
||||
|
||||
/* Send SPI end condition */
|
||||
adp_interface_send_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Read response on SPI from PC
|
||||
*
|
||||
* return Status
|
||||
* \param[in] rx_buf Pointer to receive the data
|
||||
* \param[in] length The length of the read data
|
||||
* \param[out] rx_buf Pointer to store the received SPI character
|
||||
*/
|
||||
enum status_code adp_interface_read_response(uint8_t* rx_buf, uint16_t length)
|
||||
{
|
||||
enum status_code status;
|
||||
|
||||
/* Send SPI start condition */
|
||||
adp_interface_send_start();
|
||||
status = spi_read_packet(EDBG_SPI_MODULE, rx_buf, length);
|
||||
/* Send SPI end condition */
|
||||
adp_interface_send_stop();
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ADP service implementation
|
||||
*
|
||||
* Copyright (C) 2015 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 <compiler.h>
|
||||
#include <asf.h>
|
||||
#include "adp_interface.h"
|
||||
|
||||
//! \name Embedded debugger TWI interface definitions
|
||||
//@{
|
||||
#define EDBG_TWI_MODULE TWI0
|
||||
//@}
|
||||
|
||||
#define TWI_EDBG_SLAVE_ADDR 0x28
|
||||
#define TIMEOUT 1000
|
||||
|
||||
/**
|
||||
* \brief Initialize EDBG TWI interface for SAM4S
|
||||
*
|
||||
*/
|
||||
enum status_code adp_interface_init(void)
|
||||
{
|
||||
sysclk_init();
|
||||
|
||||
/* Configure the TWI interface */
|
||||
twi_master_options_t opt = {
|
||||
.speed = 100000,
|
||||
.chip = TWI_EDBG_SLAVE_ADDR
|
||||
};
|
||||
return twi_master_setup(EDBG_TWI_MODULE, &opt);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Send data on TWI
|
||||
*
|
||||
* \param[in] data Pointer to data to send
|
||||
* \param[in] length Number of bytes to send
|
||||
*/
|
||||
static enum status_code adp_interface_send(uint8_t* tx_buf, uint16_t length)
|
||||
{
|
||||
twi_package_t packet_write = {
|
||||
.chip = TWI_EDBG_SLAVE_ADDR, /* TWI slave bus address */
|
||||
.buffer = tx_buf, /* transfer data source buffer */
|
||||
.length = length /* transfer data size (bytes) */
|
||||
};
|
||||
return twi_master_write(EDBG_TWI_MODULE, &packet_write);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Read data on TWI
|
||||
*
|
||||
* \param[out] data Pointer to place received data
|
||||
* \param[in] length Number of bytes to receive
|
||||
*/
|
||||
enum status_code adp_interface_read_response(uint8_t *data, uint16_t length)
|
||||
{
|
||||
enum status_code status = ERR_IO_ERROR;
|
||||
uint8_t data_len = 0;
|
||||
|
||||
twi_package_t packet_read = {
|
||||
.chip = TWI_EDBG_SLAVE_ADDR, // TWI slave bus address
|
||||
.buffer = &data_len, // transfer data destination buffer
|
||||
.length = 1 // transfer data size (bytes)
|
||||
};
|
||||
twi_master_read(EDBG_TWI_MODULE, &packet_read);
|
||||
|
||||
if(data_len != 0){
|
||||
packet_read.length = data_len;
|
||||
packet_read.buffer = data;
|
||||
status = twi_master_read(EDBG_TWI_MODULE, &packet_read);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sends and reads protocol packet data byte on I2C
|
||||
*
|
||||
* \param[in] tx_buf Pointer to send the protocol packet data
|
||||
* \param[in] length The length of the send protocol packet data
|
||||
* \param[out] rx_buf Pointer to store the received I2C character
|
||||
*/
|
||||
void adp_interface_transceive_procotol(uint8_t* tx_buf, uint16_t length, uint8_t* rx_buf)
|
||||
{
|
||||
adp_interface_send(tx_buf, length);
|
||||
adp_interface_read_response(rx_buf, length);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ADP service implementation
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#include <compiler.h>
|
||||
#include <system.h>
|
||||
|
||||
#include <asf.h>
|
||||
#include "adp_interface.h"
|
||||
|
||||
struct spi_module edbg_spi;
|
||||
struct spi_slave_inst slave;
|
||||
|
||||
/**
|
||||
* \brief Send SPI start condition
|
||||
*
|
||||
*/
|
||||
static void adp_interface_send_start(void)
|
||||
{
|
||||
spi_select_slave(&edbg_spi, &slave, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Send SPI stop condition
|
||||
*
|
||||
*/
|
||||
static void adp_interface_send_stop(void)
|
||||
{
|
||||
spi_select_slave(&edbg_spi, &slave, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sends and reads data byte on SPI
|
||||
*
|
||||
* \param[in] data Data byte to send
|
||||
* \param[in] tx_data SPI character to transmit
|
||||
* \param[out] rx_data Pointer to store the received SPI character
|
||||
*/
|
||||
static void adp_interface_transceive(uint8_t *tx_data, uint8_t *rx_data, uint16_t length)
|
||||
{
|
||||
spi_transceive_buffer_wait(&edbg_spi, tx_data, rx_data, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Initialize EDBG SPI communication for SAM0
|
||||
*
|
||||
*/
|
||||
enum status_code adp_interface_init(void)
|
||||
{
|
||||
enum status_code return_value;
|
||||
|
||||
system_init();
|
||||
|
||||
struct spi_slave_inst_config slave_dev_config;
|
||||
|
||||
struct spi_config config;
|
||||
|
||||
spi_slave_inst_get_config_defaults(&slave_dev_config);
|
||||
slave_dev_config.ss_pin = (EDBG_SPI_SERCOM_PINMUX_PAD1 >> 16) & 0xFF;
|
||||
spi_attach_slave(&slave, &slave_dev_config);
|
||||
|
||||
spi_get_config_defaults(&config);
|
||||
config.mode_specific.master.baudrate = 1000000;
|
||||
config.mux_setting = EDBG_SPI_SERCOM_MUX_SETTING;
|
||||
config.pinmux_pad0 = EDBG_SPI_SERCOM_PINMUX_PAD0;
|
||||
config.pinmux_pad1 = PINMUX_UNUSED;
|
||||
config.pinmux_pad2 = EDBG_SPI_SERCOM_PINMUX_PAD2;
|
||||
config.pinmux_pad3 = EDBG_SPI_SERCOM_PINMUX_PAD3;
|
||||
|
||||
return_value = spi_init(&edbg_spi, EDBG_SPI_MODULE, &config);
|
||||
|
||||
spi_enable(&edbg_spi);
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sends and reads protocol packet data byte on SPI
|
||||
*
|
||||
* \param[in] tx_buf Pointer to send the protocol packet data
|
||||
* \param[in] length The length of the send protocol packet data
|
||||
* \param[out] rx_buf Pointer to store the received SPI character
|
||||
*/
|
||||
void adp_interface_transceive_procotol(uint8_t* tx_buf, uint16_t length, uint8_t* rx_buf)
|
||||
{
|
||||
/* Send SPI start condition */
|
||||
adp_interface_send_start();
|
||||
|
||||
adp_interface_transceive(tx_buf, rx_buf, length);
|
||||
|
||||
/* Send SPI end condition */
|
||||
adp_interface_send_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Read response on SPI from PC
|
||||
*
|
||||
* return Status
|
||||
* \param[in] rx_buf Pointer to receive the data
|
||||
* \param[in] length The length of the read data
|
||||
* \param[out] rx_buf Pointer to store the received SPI character
|
||||
*/
|
||||
enum status_code adp_interface_read_response(uint8_t* rx_buf, uint16_t length)
|
||||
{
|
||||
bool status;
|
||||
|
||||
/* Send SPI start condition */
|
||||
adp_interface_send_start();
|
||||
status = spi_read_buffer_wait(&edbg_spi, rx_buf, length, 0xFF);
|
||||
/* Send SPI end condition */
|
||||
adp_interface_send_stop();
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ADP service implementation
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#include <compiler.h>
|
||||
#include <system.h>
|
||||
|
||||
#include <asf.h>
|
||||
#include <adp_interface.h>
|
||||
|
||||
#define EDBG_TWI EDBG_I2C_MODULE
|
||||
#define TWI_EDBG_SLAVE_ADDR 0x28
|
||||
#define TIMEOUT 1000
|
||||
|
||||
struct i2c_master_module i2c_master_instance;
|
||||
|
||||
/**
|
||||
* \brief Initialize EDBG I2C communication for SAM0
|
||||
*
|
||||
*/
|
||||
enum status_code adp_interface_init(void)
|
||||
{
|
||||
enum status_code return_value;
|
||||
|
||||
system_init();
|
||||
|
||||
struct i2c_master_config config_i2c_master;
|
||||
i2c_master_get_config_defaults(&config_i2c_master);
|
||||
config_i2c_master.buffer_timeout = 10000;
|
||||
return_value = i2c_master_init(&i2c_master_instance, EDBG_TWI, &config_i2c_master);
|
||||
i2c_master_enable(&i2c_master_instance);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static enum status_code adp_interface_send(uint8_t* tx_buf, uint16_t length)
|
||||
{
|
||||
enum status_code status;
|
||||
|
||||
struct i2c_master_packet packet = {
|
||||
.address = TWI_EDBG_SLAVE_ADDR,
|
||||
.data_length = length,
|
||||
.data = tx_buf,
|
||||
};
|
||||
/* Send data to PC */
|
||||
status = i2c_master_write_packet_wait(&i2c_master_instance, &packet);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Read response on I2C from PC
|
||||
*
|
||||
* return Status
|
||||
* \param[in] rx_buf Pointer to receive the data
|
||||
* \param[in] length The length of the read data
|
||||
* \param[out] rx_buf Pointer to store the received SPI character
|
||||
*/
|
||||
enum status_code adp_interface_read_response(uint8_t* rx_buf, uint16_t length)
|
||||
{
|
||||
enum status_code status = STATUS_ERR_IO;
|
||||
uint8_t data_len = 0;
|
||||
|
||||
struct i2c_master_packet packet = {
|
||||
.address = TWI_EDBG_SLAVE_ADDR,
|
||||
.data_length = 1,
|
||||
.data = &data_len,
|
||||
};
|
||||
i2c_master_read_packet_wait(&i2c_master_instance, &packet);
|
||||
|
||||
if (data_len != 0)
|
||||
{
|
||||
packet.data_length = data_len;
|
||||
packet.data = rx_buf;
|
||||
status = i2c_master_read_packet_wait(&i2c_master_instance, &packet);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sends and reads protocol packet data byte on I2C
|
||||
*
|
||||
* \param[in] tx_buf Pointer to send the protocol packet data
|
||||
* \param[in] length The length of the send protocol packet data
|
||||
* \param[out] rx_buf Pointer to store the received I2C character
|
||||
*/
|
||||
void adp_interface_transceive_procotol(uint8_t* tx_buf, uint16_t length, uint8_t* rx_buf)
|
||||
{
|
||||
adp_interface_send(tx_buf, length);
|
||||
adp_interface_read_response(rx_buf, length);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,199 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Generic clock management
|
||||
*
|
||||
* Copyright (c) 2010-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef CLK_GENCLK_H_INCLUDED
|
||||
#define CLK_GENCLK_H_INCLUDED
|
||||
|
||||
#include "parts.h"
|
||||
|
||||
#if SAM3S
|
||||
# include "sam3s/genclk.h"
|
||||
#elif SAM3U
|
||||
# include "sam3u/genclk.h"
|
||||
#elif SAM3N
|
||||
# include "sam3n/genclk.h"
|
||||
#elif SAM3XA
|
||||
# include "sam3x/genclk.h"
|
||||
#elif SAM4S
|
||||
# include "sam4s/genclk.h"
|
||||
#elif SAM4L
|
||||
# include "sam4l/genclk.h"
|
||||
#elif SAM4E
|
||||
# include "sam4e/genclk.h"
|
||||
#elif SAM4N
|
||||
# include "sam4n/genclk.h"
|
||||
#elif SAM4C
|
||||
# include "sam4c/genclk.h"
|
||||
#elif SAM4CM
|
||||
# include "sam4cm/genclk.h"
|
||||
#elif SAM4CP
|
||||
# include "sam4cp/genclk.h"
|
||||
#elif SAMG
|
||||
# include "samg/genclk.h"
|
||||
#elif SAMV71
|
||||
# include "samv71/genclk.h"
|
||||
#elif SAMV70
|
||||
# include "samv70/genclk.h"
|
||||
#elif SAME70
|
||||
# include "same70/genclk.h"
|
||||
#elif SAMS70
|
||||
# include "sams70/genclk.h"
|
||||
#elif (UC3A0 || UC3A1)
|
||||
# include "uc3a0_a1/genclk.h"
|
||||
#elif UC3A3
|
||||
# include "uc3a3_a4/genclk.h"
|
||||
#elif UC3B
|
||||
# include "uc3b0_b1/genclk.h"
|
||||
#elif UC3C
|
||||
# include "uc3c/genclk.h"
|
||||
#elif UC3D
|
||||
# include "uc3d/genclk.h"
|
||||
#elif UC3L
|
||||
# include "uc3l/genclk.h"
|
||||
#else
|
||||
# error Unsupported chip type
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \ingroup clk_group
|
||||
* \defgroup genclk_group Generic Clock Management
|
||||
*
|
||||
* Generic clocks are configurable clocks which run outside the system
|
||||
* clock domain. They are often connected to peripherals which have an
|
||||
* asynchronous component running independently of the bus clock, e.g.
|
||||
* USB controllers, low-power timers and RTCs, etc.
|
||||
*
|
||||
* Note that not all platforms have support for generic clocks; on such
|
||||
* platforms, this API will not be available.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \def GENCLK_DIV_MAX
|
||||
* \brief Maximum divider supported by the generic clock implementation
|
||||
*/
|
||||
/**
|
||||
* \enum genclk_source
|
||||
* \brief Generic clock source ID
|
||||
*
|
||||
* Each generic clock may be generated from a different clock source.
|
||||
* These are the available alternatives provided by the chip.
|
||||
*/
|
||||
|
||||
//! \name Generic clock configuration
|
||||
//@{
|
||||
/**
|
||||
* \struct genclk_config
|
||||
* \brief Hardware representation of a set of generic clock parameters
|
||||
*/
|
||||
/**
|
||||
* \fn void genclk_config_defaults(struct genclk_config *cfg,
|
||||
* unsigned int id)
|
||||
* \brief Initialize \a cfg to the default configuration for the clock
|
||||
* identified by \a id.
|
||||
*/
|
||||
/**
|
||||
* \fn void genclk_config_read(struct genclk_config *cfg, unsigned int id)
|
||||
* \brief Read the currently active configuration of the clock
|
||||
* identified by \a id into \a cfg.
|
||||
*/
|
||||
/**
|
||||
* \fn void genclk_config_write(const struct genclk_config *cfg,
|
||||
* unsigned int id)
|
||||
* \brief Activate the configuration \a cfg on the clock identified by
|
||||
* \a id.
|
||||
*/
|
||||
/**
|
||||
* \fn void genclk_config_set_source(struct genclk_config *cfg,
|
||||
* enum genclk_source src)
|
||||
* \brief Select a new source clock \a src in configuration \a cfg.
|
||||
*/
|
||||
/**
|
||||
* \fn void genclk_config_set_divider(struct genclk_config *cfg,
|
||||
* unsigned int divider)
|
||||
* \brief Set a new \a divider in configuration \a cfg.
|
||||
*/
|
||||
/**
|
||||
* \fn void genclk_enable_source(enum genclk_source src)
|
||||
* \brief Enable the source clock \a src used by a generic clock.
|
||||
*/
|
||||
//@}
|
||||
|
||||
//! \name Enabling and disabling Generic Clocks
|
||||
//@{
|
||||
/**
|
||||
* \fn void genclk_enable(const struct genclk_config *cfg, unsigned int id)
|
||||
* \brief Activate the configuration \a cfg on the clock identified by
|
||||
* \a id and enable it.
|
||||
*/
|
||||
/**
|
||||
* \fn void genclk_disable(unsigned int id)
|
||||
* \brief Disable the generic clock identified by \a id.
|
||||
*/
|
||||
//@}
|
||||
|
||||
/**
|
||||
* \brief Enable the configuration defined by \a src and \a divider
|
||||
* for the generic clock identified by \a id.
|
||||
*
|
||||
* \param id The ID of the generic clock.
|
||||
* \param src The source clock of the generic clock.
|
||||
* \param divider The divider used to generate the generic clock.
|
||||
*/
|
||||
static inline void genclk_enable_config(unsigned int id, enum genclk_source src, unsigned int divider)
|
||||
{
|
||||
struct genclk_config gcfg;
|
||||
|
||||
genclk_config_defaults(&gcfg, id);
|
||||
genclk_enable_source(src);
|
||||
genclk_config_set_source(&gcfg, src);
|
||||
genclk_config_set_divider(&gcfg, divider);
|
||||
genclk_enable(&gcfg, id);
|
||||
}
|
||||
|
||||
//! @}
|
||||
|
||||
#endif /* CLK_GENCLK_H_INCLUDED */
|
||||
@@ -0,0 +1,185 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Oscillator management
|
||||
*
|
||||
* Copyright (c) 2010-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef OSC_H_INCLUDED
|
||||
#define OSC_H_INCLUDED
|
||||
|
||||
#include "parts.h"
|
||||
#include "conf_clock.h"
|
||||
|
||||
#if SAM3S
|
||||
# include "sam3s/osc.h"
|
||||
#elif SAM3XA
|
||||
# include "sam3x/osc.h"
|
||||
#elif SAM3U
|
||||
# include "sam3u/osc.h"
|
||||
#elif SAM3N
|
||||
# include "sam3n/osc.h"
|
||||
#elif SAM4S
|
||||
# include "sam4s/osc.h"
|
||||
#elif SAM4E
|
||||
# include "sam4e/osc.h"
|
||||
#elif SAM4C
|
||||
# include "sam4c/osc.h"
|
||||
#elif SAM4CM
|
||||
# include "sam4cm/osc.h"
|
||||
#elif SAM4CP
|
||||
# include "sam4cp/osc.h"
|
||||
#elif SAM4L
|
||||
# include "sam4l/osc.h"
|
||||
#elif SAM4N
|
||||
# include "sam4n/osc.h"
|
||||
#elif SAMG
|
||||
# include "samg/osc.h"
|
||||
#elif SAMV71
|
||||
# include "samv71/osc.h"
|
||||
#elif SAMV70
|
||||
# include "samv70/osc.h"
|
||||
#elif SAME70
|
||||
# include "same70/osc.h"
|
||||
#elif SAMS70
|
||||
# include "sams70/osc.h"
|
||||
#elif (UC3A0 || UC3A1)
|
||||
# include "uc3a0_a1/osc.h"
|
||||
#elif UC3A3
|
||||
# include "uc3a3_a4/osc.h"
|
||||
#elif UC3B
|
||||
# include "uc3b0_b1/osc.h"
|
||||
#elif UC3C
|
||||
# include "uc3c/osc.h"
|
||||
#elif UC3D
|
||||
# include "uc3d/osc.h"
|
||||
#elif UC3L
|
||||
# include "uc3l/osc.h"
|
||||
#elif XMEGA
|
||||
# include "xmega/osc.h"
|
||||
#else
|
||||
# error Unsupported chip type
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \ingroup clk_group
|
||||
* \defgroup osc_group Oscillator Management
|
||||
*
|
||||
* This group contains functions and definitions related to configuring
|
||||
* and enabling/disabling on-chip oscillators. Internal RC-oscillators,
|
||||
* external crystal oscillators and external clock generators are
|
||||
* supported by this module. What all of these have in common is that
|
||||
* they swing at a fixed, nominal frequency which is normally not
|
||||
* adjustable.
|
||||
*
|
||||
* \par Example: Enabling an oscillator
|
||||
*
|
||||
* The following example demonstrates how to enable the external
|
||||
* oscillator on XMEGA A and wait for it to be ready to use. The
|
||||
* oscillator identifiers are platform-specific, so while the same
|
||||
* procedure is used on all platforms, the parameter to osc_enable()
|
||||
* will be different from device to device.
|
||||
* \code
|
||||
osc_enable(OSC_ID_XOSC);
|
||||
osc_wait_ready(OSC_ID_XOSC); \endcode
|
||||
*
|
||||
* \section osc_group_board Board-specific Definitions
|
||||
* If external oscillators are used, the board code must provide the
|
||||
* following definitions for each of those:
|
||||
* - \b BOARD_<osc name>_HZ: The nominal frequency of the oscillator.
|
||||
* - \b BOARD_<osc name>_STARTUP_US: The startup time of the
|
||||
* oscillator in microseconds.
|
||||
* - \b BOARD_<osc name>_TYPE: The type of oscillator connected, i.e.
|
||||
* whether it's a crystal or external clock, and sometimes what kind
|
||||
* of crystal it is. The meaning of this value is platform-specific.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
//! \name Oscillator Management
|
||||
//@{
|
||||
/**
|
||||
* \fn void osc_enable(uint8_t id)
|
||||
* \brief Enable oscillator \a id
|
||||
*
|
||||
* The startup time and mode value is automatically determined based on
|
||||
* definitions in the board code.
|
||||
*/
|
||||
/**
|
||||
* \fn void osc_disable(uint8_t id)
|
||||
* \brief Disable oscillator \a id
|
||||
*/
|
||||
/**
|
||||
* \fn osc_is_ready(uint8_t id)
|
||||
* \brief Determine whether oscillator \a id is ready.
|
||||
* \retval true Oscillator \a id is running and ready to use as a clock
|
||||
* source.
|
||||
* \retval false Oscillator \a id is not running.
|
||||
*/
|
||||
/**
|
||||
* \fn uint32_t osc_get_rate(uint8_t id)
|
||||
* \brief Return the frequency of oscillator \a id in Hz
|
||||
*/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/**
|
||||
* \brief Wait until the oscillator identified by \a id is ready
|
||||
*
|
||||
* This function will busy-wait for the oscillator identified by \a id
|
||||
* to become stable and ready to use as a clock source.
|
||||
*
|
||||
* \param id A number identifying the oscillator to wait for.
|
||||
*/
|
||||
static inline void osc_wait_ready(uint8_t id)
|
||||
{
|
||||
while (!osc_is_ready(id)) {
|
||||
/* Do nothing */
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
|
||||
//@}
|
||||
|
||||
//! @}
|
||||
|
||||
#endif /* OSC_H_INCLUDED */
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,194 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief System clock management
|
||||
*
|
||||
* Copyright (c) 2010-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef SYSCLK_H_INCLUDED
|
||||
#define SYSCLK_H_INCLUDED
|
||||
|
||||
#include "parts.h"
|
||||
#include "conf_clock.h"
|
||||
|
||||
#if SAM3S
|
||||
# include "sam3s/sysclk.h"
|
||||
#elif SAM3U
|
||||
# include "sam3u/sysclk.h"
|
||||
#elif SAM3N
|
||||
# include "sam3n/sysclk.h"
|
||||
#elif SAM3XA
|
||||
# include "sam3x/sysclk.h"
|
||||
#elif SAM4S
|
||||
# include "sam4s/sysclk.h"
|
||||
#elif SAM4E
|
||||
# include "sam4e/sysclk.h"
|
||||
#elif SAM4C
|
||||
# include "sam4c/sysclk.h"
|
||||
#elif SAM4CM
|
||||
# include "sam4cm/sysclk.h"
|
||||
#elif SAM4CP
|
||||
# include "sam4cp/sysclk.h"
|
||||
#elif SAM4L
|
||||
# include "sam4l/sysclk.h"
|
||||
#elif SAM4N
|
||||
# include "sam4n/sysclk.h"
|
||||
#elif SAMG
|
||||
# include "samg/sysclk.h"
|
||||
#elif SAMV71
|
||||
# include "samv71/sysclk.h"
|
||||
#elif SAMV70
|
||||
# include "samv70/sysclk.h"
|
||||
#elif SAME70
|
||||
# include "same70/sysclk.h"
|
||||
#elif SAMS70
|
||||
# include "sams70/sysclk.h"
|
||||
#elif (UC3A0 || UC3A1)
|
||||
# include "uc3a0_a1/sysclk.h"
|
||||
#elif UC3A3
|
||||
# include "uc3a3_a4/sysclk.h"
|
||||
#elif UC3B
|
||||
# include "uc3b0_b1/sysclk.h"
|
||||
#elif UC3C
|
||||
# include "uc3c/sysclk.h"
|
||||
#elif UC3D
|
||||
# include "uc3d/sysclk.h"
|
||||
#elif UC3L
|
||||
# include "uc3l/sysclk.h"
|
||||
#elif XMEGA
|
||||
# include "xmega/sysclk.h"
|
||||
#elif MEGA
|
||||
# include "mega/sysclk.h"
|
||||
#else
|
||||
# error Unsupported chip type
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \defgroup clk_group Clock Management
|
||||
*/
|
||||
|
||||
/**
|
||||
* \ingroup clk_group
|
||||
* \defgroup sysclk_group System Clock Management
|
||||
*
|
||||
* See \ref sysclk_quickstart.
|
||||
*
|
||||
* The <em>sysclk</em> API covers the <em>system clock</em> and all
|
||||
* clocks derived from it. The system clock is a chip-internal clock on
|
||||
* which all <em>synchronous clocks</em>, i.e. CPU and bus/peripheral
|
||||
* clocks, are based. The system clock is typically generated from one
|
||||
* of a variety of sources, which may include crystal and RC oscillators
|
||||
* as well as PLLs. The clocks derived from the system clock are
|
||||
* sometimes also known as <em>synchronous clocks</em>, since they
|
||||
* always run synchronously with respect to each other, as opposed to
|
||||
* <em>generic clocks</em> which may run from different oscillators or
|
||||
* PLLs.
|
||||
*
|
||||
* Most applications should simply call sysclk_init() to initialize
|
||||
* everything related to the system clock and its source (oscillator,
|
||||
* PLL or DFLL), and leave it at that. More advanced applications, and
|
||||
* platform-specific drivers, may require additional services from the
|
||||
* clock system, some of which may be platform-specific.
|
||||
*
|
||||
* \section sysclk_group_platform Platform Dependencies
|
||||
*
|
||||
* The sysclk API is partially chip- or platform-specific. While all
|
||||
* platforms provide mostly the same functionality, there are some
|
||||
* variations around how different bus types and clock tree structures
|
||||
* are handled.
|
||||
*
|
||||
* The following functions are available on all platforms with the same
|
||||
* parameters and functionality. These functions may be called freely by
|
||||
* portable applications, drivers and services:
|
||||
* - sysclk_init()
|
||||
* - sysclk_set_source()
|
||||
* - sysclk_get_main_hz()
|
||||
* - sysclk_get_cpu_hz()
|
||||
* - sysclk_get_peripheral_bus_hz()
|
||||
*
|
||||
* The following functions are available on all platforms, but there may
|
||||
* be variations in the function signature (i.e. parameters) and
|
||||
* behavior. These functions are typically called by platform-specific
|
||||
* parts of drivers, and applications that aren't intended to be
|
||||
* portable:
|
||||
* - sysclk_enable_peripheral_clock()
|
||||
* - sysclk_disable_peripheral_clock()
|
||||
* - sysclk_enable_module()
|
||||
* - sysclk_disable_module()
|
||||
* - sysclk_module_is_enabled()
|
||||
* - sysclk_set_prescalers()
|
||||
*
|
||||
* All other functions should be considered platform-specific.
|
||||
* Enabling/disabling clocks to specific peripherals as well as
|
||||
* determining the speed of these clocks should be done by calling
|
||||
* functions provided by the driver for that peripheral.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
//! \name System Clock Initialization
|
||||
//@{
|
||||
/**
|
||||
* \fn void sysclk_init(void)
|
||||
* \brief Initialize the synchronous clock system.
|
||||
*
|
||||
* This function will initialize the system clock and its source. This
|
||||
* includes:
|
||||
* - Mask all synchronous clocks except for any clocks which are
|
||||
* essential for normal operation (for example internal memory
|
||||
* clocks).
|
||||
* - Set up the system clock prescalers as specified by the
|
||||
* application's configuration file.
|
||||
* - Enable the clock source specified by the application's
|
||||
* configuration file (oscillator or PLL) and wait for it to become
|
||||
* stable.
|
||||
* - Set the main system clock source to the clock specified by the
|
||||
* application's configuration file.
|
||||
*
|
||||
* Since all non-essential peripheral clocks are initially disabled, it
|
||||
* is the responsibility of the peripheral driver to re-enable any
|
||||
* clocks that are needed for normal operation.
|
||||
*/
|
||||
//@}
|
||||
|
||||
//! @}
|
||||
|
||||
#endif /* SYSCLK_H_INCLUDED */
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief 32-bit CRC implementation.
|
||||
*
|
||||
* Copyright (C) 2014-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#include "crc32.h"
|
||||
#include <status_codes.h>
|
||||
|
||||
|
||||
/**
|
||||
* Convenience typedef for words.
|
||||
*
|
||||
* \note This type has an architecture dependent size, and is used to optimize
|
||||
* the CRC algorithm with regards to the number of databus accesses.
|
||||
*/
|
||||
typedef unsigned int word_t;
|
||||
|
||||
/** Polynomial for 32-bit CRC in IEEE 802.3. */
|
||||
#define CRC32_POLYNOMIAL 0xEDB88320UL
|
||||
|
||||
/** Convenience macro for inverting the CRC. */
|
||||
#define COMPLEMENT_CRC(c) ((c) ^ 0xffffffffUL)
|
||||
|
||||
/** Convenience macro for size of a word. */
|
||||
#define WORD_SIZE (sizeof(word_t))
|
||||
|
||||
/** Bitmask for word-aligning an address. */
|
||||
#define WORD_ALIGNMENT_MASK ~((uintptr_t)WORD_SIZE - 1)
|
||||
|
||||
|
||||
/**
|
||||
* \internal
|
||||
* \brief Recalculate 32-bit CRC for bytes within a word
|
||||
*
|
||||
* \param[in] data Data to recalculate for.
|
||||
* \param[in] crc Initial/current CRC value.
|
||||
* \param[in] bytes Number of data bytes in word.
|
||||
*
|
||||
* \return New CRC value.
|
||||
*
|
||||
* \attention This implementation assumes a little-endian architecture.
|
||||
*/
|
||||
static inline crc32_t _crc32_recalculate_bytes_helper(word_t data,
|
||||
crc32_t crc, uint_fast8_t bytes)
|
||||
{
|
||||
uint_fast8_t bit;
|
||||
|
||||
crc ^= data;
|
||||
|
||||
for (bit = 8 * bytes; bit > 0; bit--) {
|
||||
if (crc & 1) {
|
||||
crc = (crc >> 1) ^ CRC32_POLYNOMIAL;
|
||||
} else {
|
||||
crc >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Recalculate 32-bit CRC for another block
|
||||
*
|
||||
* This function recalculates the CRC according to the polynomial
|
||||
* \ref CRC32_POLYNOMIAL for the specified data block and initial CRC value.
|
||||
*
|
||||
* To reduce the number of databus accesses and thus speed up the calculation,
|
||||
* the algorithm is tuned to work with words as much as possible.
|
||||
*
|
||||
* \param[in] data Address of data.
|
||||
* \param[in] length Length of data.
|
||||
* \param[in,out] crc Address of variable containing current CRC, and to store
|
||||
* recalculated CRC in.
|
||||
*
|
||||
* \return Status of calculation.
|
||||
* \retval STATUS_OK if calculation succeeded.
|
||||
* \retval <other> if calculation failed or could not be started.
|
||||
*
|
||||
* \note To calculate the CRC of multiple blocks, use \ref crc32_calculate()
|
||||
* first, then this function for the following blocks.
|
||||
*
|
||||
* \attention This implementation assumes a little-endian architecture.
|
||||
*/
|
||||
enum status_code crc32_recalculate(const void *data, size_t length, crc32_t *crc)
|
||||
{
|
||||
const word_t *word_ptr =
|
||||
(word_t *)((uintptr_t)data & WORD_ALIGNMENT_MASK);
|
||||
size_t temp_length;
|
||||
crc32_t temp_crc = COMPLEMENT_CRC(*crc);
|
||||
word_t word;
|
||||
|
||||
// Calculate for initial bytes to get word-aligned
|
||||
if (length < WORD_SIZE) {
|
||||
temp_length = length;
|
||||
} else {
|
||||
temp_length = ~WORD_ALIGNMENT_MASK & (WORD_SIZE - (uintptr_t)data);
|
||||
}
|
||||
|
||||
if (temp_length) {
|
||||
length -= temp_length;
|
||||
|
||||
word = *(word_ptr++);
|
||||
word >>= 8 * (WORD_SIZE - temp_length);
|
||||
temp_crc = _crc32_recalculate_bytes_helper(word, temp_crc, temp_length);
|
||||
}
|
||||
|
||||
// Calculate for whole words, if any
|
||||
temp_length = length & WORD_ALIGNMENT_MASK;
|
||||
|
||||
if (temp_length) {
|
||||
length -= temp_length;
|
||||
temp_length /= WORD_SIZE;
|
||||
|
||||
while (temp_length--) {
|
||||
word = *(word_ptr++);
|
||||
temp_crc = _crc32_recalculate_bytes_helper(word, temp_crc, WORD_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate for tailing bytes
|
||||
if (length) {
|
||||
word = *word_ptr;
|
||||
word &= 0xffffffffUL >> (8 * (WORD_SIZE - length));
|
||||
temp_crc = _crc32_recalculate_bytes_helper(word, temp_crc, length);
|
||||
}
|
||||
|
||||
*crc = COMPLEMENT_CRC(temp_crc);
|
||||
|
||||
return STATUS_OK;
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief 32-bit CRC header.
|
||||
*
|
||||
* Copyright (C) 2013-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef CRC32_H
|
||||
#define CRC32_H
|
||||
|
||||
|
||||
#include <compiler.h>
|
||||
|
||||
|
||||
/**
|
||||
* \defgroup common_services_crc32 CRC-32 calculation service
|
||||
*
|
||||
* See \ref common_services_crc32_quickstart.
|
||||
*
|
||||
* This service enables the user to calculate 32-bit CRC using the polynomial
|
||||
* defined in the IEEE 802.3 standard, with support for multiple data blocks
|
||||
* of arbitrary sizes, and any alignment in memory.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
//! Type to contain 32-bit CRC.
|
||||
typedef uint32_t crc32_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum status_code crc32_recalculate(const void *data, size_t length, crc32_t *crc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* \brief Calculate 32-bit CRC for initial block
|
||||
*
|
||||
* This function calculates the CRC for the specified data block, which may be
|
||||
* first of an arbitrary number of blocks.
|
||||
*
|
||||
* The actual calculation is done in \ref crc32_recalculate(), while this
|
||||
* function just sets up the initial CRC value.
|
||||
*
|
||||
* \param[in] data Address of data.
|
||||
* \param[in] length Length of data.
|
||||
* \param[out] crc Address of variable to store the calculated CRC in.
|
||||
*
|
||||
* \return Status of calculation.
|
||||
* \retval STATUS_OK if calculation succeeded.
|
||||
* \retval <other> if calculation failed somehow.
|
||||
*
|
||||
* \note To calculate the CRC of multiple blocks, use this function first, then
|
||||
* \ref crc32_recalculate() for the following blocks.
|
||||
*/
|
||||
static inline enum status_code crc32_calculate(const void *data, size_t length,
|
||||
crc32_t *crc)
|
||||
{
|
||||
*crc = 0;
|
||||
|
||||
return crc32_recalculate(data, length, crc);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \page common_services_crc32_quickstart Quick Start Guide for CRC-32
|
||||
*
|
||||
* To use this service, the user must supply a \ref crc32_t "container" variable
|
||||
* for the CRC and call \ref crc32_calculate() with the parameters for the first
|
||||
* block in the dataset. For subsequent blocks, \ref crc32_recalculate() must be
|
||||
* used.
|
||||
*
|
||||
* \note The user may also initialize the container with a known CRC value and
|
||||
* use that as the "seed" for \ref crc32_recalculate().
|
||||
*
|
||||
*
|
||||
* \section common_services_crc32_quickstart_code Example Code
|
||||
*
|
||||
\code
|
||||
uint8_t block1[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
uint8_t block2[6] = {0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
|
||||
|
||||
crc32_t my_crc;
|
||||
|
||||
crc32_calculate(block1, sizeof(block1), &my_crc);
|
||||
crc32_recalculate(block2, sizeof(block2), &my_crc);
|
||||
\endcode
|
||||
*
|
||||
*/
|
||||
|
||||
#endif // CRC32_H
|
||||
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Common Delay Service
|
||||
*
|
||||
* Copyright (c) 2014-2016 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef _DELAY_H_
|
||||
#define _DELAY_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <sysclk.h>
|
||||
|
||||
#if UC3
|
||||
# include <cycle_counter.h>
|
||||
#elif XMEGA
|
||||
# include "xmega/cycle_counter.h"
|
||||
#elif MEGA
|
||||
# include "mega/cycle_counter.h"
|
||||
#elif SAM
|
||||
# include "sam/cycle_counter.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup group_common_services_delay Busy-Wait Delay Routines
|
||||
*
|
||||
* This module provides simple loop-based delay routines for those
|
||||
* applications requiring a brief wait during execution. Common API
|
||||
* for UC3, XMEGA, and AVR MEGA.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @def F_CPU
|
||||
* @brief MCU Clock Frequency (Hertz)
|
||||
*
|
||||
* @deprecated
|
||||
* The \ref F_CPU configuration constant is used for compatibility with the
|
||||
* \ref group_common_services_delay routines. The common loop-based delay
|
||||
* routines are designed to use the \ref clk_group modules while anticipating
|
||||
* support for legacy applications assuming a statically defined clock
|
||||
* frequency. Applications using a statically configured MCU clock frequency
|
||||
* can define \ref F_CPU (Hertz), in which case the common delay routines will
|
||||
* use this value rather than calling sysclk_get_cpu_hz() to get the current
|
||||
* MCU clock frequency.
|
||||
*/
|
||||
#ifndef F_CPU
|
||||
# define F_CPU sysclk_get_cpu_hz()
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def delay_init
|
||||
*
|
||||
* @brief Initialize the delay driver.
|
||||
* @param fcpu_hz CPU frequency in Hz
|
||||
*
|
||||
* @deprecated
|
||||
* This function is provided for compatibility with ASF applications that
|
||||
* may not have been updated to configure the system clock via the common
|
||||
* clock service; e.g. sysclk_init() and a configuration header file are
|
||||
* used to configure clocks.
|
||||
*
|
||||
* The functions in this module call \ref sysclk_get_cpu_hz() function to
|
||||
* obtain the system clock frequency.
|
||||
*/
|
||||
#define delay_init(fcpu_hz)
|
||||
|
||||
/**
|
||||
* @def delay_s
|
||||
* @brief Delay in seconds.
|
||||
* @param delay Delay in seconds
|
||||
*/
|
||||
#define delay_s(delay) ((delay) ? cpu_delay_ms(1000 * delay, F_CPU) : cpu_delay_us(1, F_CPU))
|
||||
|
||||
/**
|
||||
* @def delay_ms
|
||||
* @brief Delay in milliseconds.
|
||||
* @param delay Delay in milliseconds
|
||||
*/
|
||||
#define delay_ms(delay) ((delay) ? cpu_delay_ms(delay, F_CPU) : cpu_delay_us(1, F_CPU))
|
||||
|
||||
/**
|
||||
* @def delay_us
|
||||
* @brief Delay in microseconds.
|
||||
* @param delay Delay in microseconds
|
||||
*/
|
||||
#define delay_us(delay) ((delay) ? cpu_delay_us(delay, F_CPU) : cpu_delay_us(1, F_CPU))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* _DELAY_H_ */
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ARM functions for busy-wait delay loops
|
||||
*
|
||||
* Copyright (c) 2012-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#include "cycle_counter.h"
|
||||
|
||||
// Delay loop is put to SRAM so that FWS will not affect delay time
|
||||
OPTIMIZE_HIGH
|
||||
RAMFUNC
|
||||
void portable_delay_cycles(unsigned long n)
|
||||
{
|
||||
UNUSED(n);
|
||||
|
||||
__asm (
|
||||
"loop: DMB \n"
|
||||
"SUBS R0, R0, #1 \n"
|
||||
"BNE.N loop "
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ARM functions for busy-wait delay loops
|
||||
*
|
||||
* Copyright (c) 2014-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef _cycle_counter_h_
|
||||
#define _cycle_counter_h_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include <compiler.h>
|
||||
|
||||
/**
|
||||
* @name Convenience functions for busy-wait delay loops
|
||||
*
|
||||
* @def delay_cycles
|
||||
* @brief Delay program execution for a specified number of CPU cycles.
|
||||
* @param n number of CPU cycles to wait
|
||||
*
|
||||
* @def cpu_delay_ms
|
||||
* @brief Delay program execution for a specified number of milliseconds.
|
||||
* @param delay number of milliseconds to wait
|
||||
* @param f_cpu CPU frequency in Hertz
|
||||
*
|
||||
* @def cpu_delay_us
|
||||
* @brief Delay program execution for a specified number of microseconds.
|
||||
* @param delay number of microseconds to wait
|
||||
* @param f_cpu CPU frequency in Hertz
|
||||
*
|
||||
* @def cpu_ms_2_cy
|
||||
* @brief Convert milli-seconds into CPU cycles.
|
||||
* @param ms number of milliseconds
|
||||
* @param f_cpu CPU frequency in Hertz
|
||||
* @return the converted number of CPU cycles
|
||||
*
|
||||
* @def cpu_us_2_cy
|
||||
* @brief Convert micro-seconds into CPU cycles.
|
||||
* @param ms number of microseconds
|
||||
* @param f_cpu CPU frequency in Hertz
|
||||
* @return the converted number of CPU cycles
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Delay loop to delay n number of cycles
|
||||
*
|
||||
* \note The function runs in internal RAM so that flash wait states
|
||||
* will not affect the delay time.
|
||||
*
|
||||
* \param n Number of cycles
|
||||
*/
|
||||
void portable_delay_cycles(unsigned long n);
|
||||
|
||||
/* Cortex-M7 is faster than Cortex-M3/M4/M0+ */
|
||||
#ifdef __CM7_REV
|
||||
|
||||
# define cpu_ms_2_cy(ms, f_cpu) \
|
||||
(((uint64_t)(ms) * (f_cpu) + (uint64_t)(5.932e3 - 1ul)) / (uint64_t)5.932e3)
|
||||
# define cpu_us_2_cy(us, f_cpu) \
|
||||
(((uint64_t)(us) * (f_cpu) + (uint64_t)(5.932e6 - 1ul)) / (uint64_t)5.932e6)
|
||||
|
||||
#else
|
||||
|
||||
# define cpu_ms_2_cy(ms, f_cpu) \
|
||||
(((uint64_t)(ms) * (f_cpu) + (uint64_t)(14e3 - 1ul)) / (uint64_t)14e3)
|
||||
# define cpu_us_2_cy(us, f_cpu) \
|
||||
(((uint64_t)(us) * (f_cpu) + (uint64_t)(14e6 - 1ul)) / (uint64_t)14e6)
|
||||
|
||||
#endif
|
||||
|
||||
#define delay_cycles portable_delay_cycles
|
||||
|
||||
#define cpu_delay_ms(delay, f_cpu) delay_cycles(cpu_ms_2_cy(delay, f_cpu))
|
||||
#define cpu_delay_us(delay, f_cpu) delay_cycles(cpu_us_2_cy(delay, f_cpu))
|
||||
//! @}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _cycle_counter_h_ */
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief This file controls the software FIFO management.
|
||||
*
|
||||
* These functions manages FIFOs thanks to simple a API. The FIFO can
|
||||
* be 100% full thanks to a double-index range implementation. For example,
|
||||
* a FIFO of 4 elements can be implemented: the FIFO can really hold up to 4
|
||||
* elements.
|
||||
* This is particularly well suited for any kind of application needing a lot of
|
||||
* small FIFO.
|
||||
*
|
||||
* Copyright (c) 2010-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#include "fifo.h"
|
||||
|
||||
int fifo_init(fifo_desc_t *fifo_desc, void *buffer, uint8_t size)
|
||||
{
|
||||
// Check the size parameter. It must be not null...
|
||||
Assert (size);
|
||||
|
||||
// ... must be a 2-power ...
|
||||
Assert (!(size & (size - 1)));
|
||||
|
||||
// ... and must fit in a uint8_t. Since the read and write indexes are using a
|
||||
// double-index range implementation, the max FIFO size is thus 128 items.
|
||||
Assert (size <= 128);
|
||||
|
||||
// Fifo starts empty.
|
||||
fifo_desc->read_index = 0;
|
||||
fifo_desc->write_index = 0;
|
||||
|
||||
// Save the size parameter.
|
||||
fifo_desc->size = size;
|
||||
|
||||
// Create a mask to speed up the FIFO management (index swapping).
|
||||
fifo_desc->mask = (2 * (uint16_t)size) - 1;
|
||||
|
||||
// Save the buffer pointer.
|
||||
fifo_desc->buffer.u8ptr = buffer;
|
||||
|
||||
return FIFO_OK;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Common GPIO API.
|
||||
*
|
||||
* Copyright (c) 2010-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef _GPIO_H_
|
||||
#define _GPIO_H_
|
||||
|
||||
#include <parts.h>
|
||||
|
||||
#if (SAM3S || SAM3U || SAM3N || SAM3XA || SAM4S || SAM4E || SAM4N || SAM4C || SAMG || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70)
|
||||
# include "sam_gpio/sam_gpio.h"
|
||||
#elif XMEGA
|
||||
# include "xmega_gpio/xmega_gpio.h"
|
||||
#elif MEGA || MEGA_RF
|
||||
# include "mega_gpio/mega_gpio.h"
|
||||
#else
|
||||
# error Unsupported chip type
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \defgroup gpio_group General Purpose Input/Output
|
||||
*
|
||||
* This is the common API for GPIO. Additional features are available
|
||||
* in the documentation of the specific modules.
|
||||
*
|
||||
* \section io_group_platform Platform Dependencies
|
||||
*
|
||||
* The following functions are available on all platforms, but there may
|
||||
* be variations in the function signature (i.e. parameters) and
|
||||
* behaviour. These functions are typically called by platform-specific
|
||||
* parts of drivers, and applications that aren't intended to be
|
||||
* portable:
|
||||
* - gpio_pin_is_low()
|
||||
* - gpio_pin_is_high()
|
||||
* - gpio_set_pin_high()
|
||||
* - gpio_set_pin_group_high()
|
||||
* - gpio_set_pin_low()
|
||||
* - gpio_set_pin_group_low()
|
||||
* - gpio_toggle_pin()
|
||||
* - gpio_toggle_pin_group()
|
||||
* - gpio_configure_pin()
|
||||
* - gpio_configure_group()
|
||||
*/
|
||||
|
||||
#endif /* _GPIO_H_ */
|
||||
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief GPIO service for SAM.
|
||||
*
|
||||
* Copyright (c) 2011-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef SAM_GPIO_H_INCLUDED
|
||||
#define SAM_GPIO_H_INCLUDED
|
||||
|
||||
#include "compiler.h"
|
||||
#include "pio.h"
|
||||
|
||||
#define gpio_pin_is_low(io_id) \
|
||||
(pio_get_pin_value(io_id) ? 0 : 1)
|
||||
|
||||
#define gpio_pin_is_high(io_id) \
|
||||
(pio_get_pin_value(io_id) ? 1 : 0)
|
||||
|
||||
#define gpio_set_pin_high(io_id) \
|
||||
pio_set_pin_high(io_id)
|
||||
|
||||
#define gpio_set_pin_low(io_id) \
|
||||
pio_set_pin_low(io_id)
|
||||
|
||||
#define gpio_toggle_pin(io_id) \
|
||||
pio_toggle_pin(io_id)
|
||||
|
||||
#define gpio_configure_pin(io_id,io_flags) \
|
||||
pio_configure_pin(io_id,io_flags)
|
||||
|
||||
#define gpio_configure_group(port_id,port_mask,io_flags) \
|
||||
pio_configure_pin_group(port_id,port_mask,io_flags)
|
||||
|
||||
#define gpio_set_pin_group_high(port_id,mask) \
|
||||
pio_set_pin_group_high(port_id,mask)
|
||||
|
||||
#define gpio_set_pin_group_low(port_id,mask) \
|
||||
pio_set_pin_group_low(port_id,mask)
|
||||
|
||||
#define gpio_toggle_pin_group(port_id,mask) \
|
||||
pio_toggle_pin_group(port_id,mask)
|
||||
|
||||
#endif /* SAM_GPIO_H_INCLUDED */
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Generic implementation of huge data memory access
|
||||
*
|
||||
* Copyright (c) 2010-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef GENERIC_HUGEMEM_H_INCLUDED
|
||||
#define GENERIC_HUGEMEM_H_INCLUDED
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* \weakgroup hugemem_group
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \internal
|
||||
* \defgroup hugemem_generic_group Generic hugemem implementation.
|
||||
*
|
||||
* These functions are needed for code compatibility between 8- and 32-bit AVR,
|
||||
* as well as a different application configurations on 8-bit AVR, i.e., if huge
|
||||
* data memory is optional.
|
||||
*/
|
||||
|
||||
typedef void * hugemem_ptr_t;
|
||||
|
||||
#define HUGEMEM_NULL NULL
|
||||
|
||||
static inline uint8_t hugemem_read8(const hugemem_ptr_t from)
|
||||
{
|
||||
return *(uint8_t *)from;
|
||||
}
|
||||
|
||||
static inline uint16_t hugemem_read16(const hugemem_ptr_t from)
|
||||
{
|
||||
return *(uint16_t *)from;
|
||||
}
|
||||
|
||||
static inline uint32_t hugemem_read32(const hugemem_ptr_t from)
|
||||
{
|
||||
return *(uint32_t *)from;
|
||||
}
|
||||
|
||||
static inline void hugemem_read_block(void *to, const hugemem_ptr_t from,
|
||||
size_t size)
|
||||
{
|
||||
memcpy(to, from, size);
|
||||
}
|
||||
|
||||
static inline void hugemem_write8(hugemem_ptr_t to, uint8_t val)
|
||||
{
|
||||
*(uint8_t *)to = val;
|
||||
}
|
||||
|
||||
static inline void hugemem_write16(hugemem_ptr_t to, uint16_t val)
|
||||
{
|
||||
*(uint16_t *)to = val;
|
||||
}
|
||||
|
||||
|
||||
static inline void hugemem_write32(hugemem_ptr_t to, uint32_t val)
|
||||
{
|
||||
*(uint32_t *)to = val;
|
||||
}
|
||||
|
||||
static inline void hugemem_write_block(hugemem_ptr_t to, const void *from,
|
||||
size_t size)
|
||||
{
|
||||
memcpy(to, from, size);
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
#endif /* GENERIC_HUGEMEM_H */
|
||||
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Huge data memory space access
|
||||
*
|
||||
* Copyright (c) 2009-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef HUGEMEM_H_INCLUDED
|
||||
#define HUGEMEM_H_INCLUDED
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(__AVR32__) || defined(__ICCAVR32__)
|
||||
# include <generic/hugemem.h>
|
||||
#elif defined(__AVR__) || defined (__ICCAVR__)
|
||||
# include <avr8/hugemem.h>
|
||||
#else
|
||||
# error Unknown architecture passed to hugemem interface.
|
||||
# error Expected __AVR32__ or __AVR__.
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \defgroup hugemem_group Data in Huge Data Memory Space
|
||||
*
|
||||
* Due to shortcomings of the GCC compiler for 8-bit AVR, custom functions are
|
||||
* needed for access to data beyond the 64 kB boundary, i.e., addresses that
|
||||
* are larger than 16-bit.
|
||||
*
|
||||
* The definition of huge memory space can differ between architectures, so the
|
||||
* implementation is architecture specific.
|
||||
*
|
||||
* This module supplies functions for copying a number of bytes between huge
|
||||
* and 64 kB data memory space, and is needed solely for code compatibility
|
||||
* across compilers.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \typedef hugemem_ptr_t
|
||||
*
|
||||
* \brief Type to use for pointers to huge memory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \def HUGEMEM_NULL
|
||||
*
|
||||
* \brief Hugemem null pointer, similar to NULL, but works across different
|
||||
* platforms.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn uint_fast8_t hugemem_read8(const hugemem_ptr_t from)
|
||||
*
|
||||
* \brief Read 8-bit value stored at huge memory address \a from.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn uint_fast16_t hugemem_read16(const hugemem_ptr_t from)
|
||||
*
|
||||
* \brief Read 16-bit value stored at huge memory address \a from.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn void hugemem_read_block(void *to, const hugemem_ptr_t from, size_t size)
|
||||
*
|
||||
* \brief Read \a size bytes from huge memory address \a from into buffer at
|
||||
* address \a to.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn uint_fast32_t hugemem_read32(const hugemem_ptr_t from)
|
||||
*
|
||||
* \brief Read 32-bit value stored at huge memory address \a from.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn void hugemem_write8(hugemem_ptr_t to, uint_fast8_t val)
|
||||
*
|
||||
* \brief Write 8-bit value \a val to huge memory address \a to.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn void hugemem_write16(hugemem_ptr_t to, uint_fast16_t val)
|
||||
*
|
||||
* \brief Write 16-bit value \a val to huge memory address \a to.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn void hugemem_write32(hugemem_ptr_t to, uint_fast32_t val)
|
||||
*
|
||||
* \brief Write 32-bit value \a val to huge memory address \a to.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn void hugemem_write_block(hugemem_ptr_t to, const void *from, size_t size)
|
||||
*
|
||||
* \brief Write \a size bytes from buffer at address \a from to huge memory
|
||||
* address \a to.
|
||||
*/
|
||||
|
||||
//@}
|
||||
|
||||
#endif /* HUGEMEM_H_INCLUDED */
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief ISP configuration file template.
|
||||
*
|
||||
* Copyright (c) 2014-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef _CONF_ISP_H_
|
||||
#define _CONF_ISP_H_
|
||||
|
||||
// Bootloader Versions
|
||||
// Example: Version 0x00 gives 1.0.0 on batchisp log
|
||||
// Example: Version 0x03 gives 1.0.3 on batchisp log
|
||||
// Example: Version 0x25 gives 1.2.5 on batchisp log
|
||||
//
|
||||
// Note: a specific UC3 rule is defined:
|
||||
// - 1.0.X for USB bootloaders that follow the AVR32784 application note
|
||||
// specification
|
||||
// - 1.1.X for USB bootloaders that follow the AVR32806 application note
|
||||
// specification
|
||||
//
|
||||
#define BOOTLOADER_VERSION 0x00 // 1.0.0
|
||||
|
||||
// If all memories (flash,eeprom,...) do not exceed 64KB.
|
||||
// then the ISP interface can be optimized to save CODE.
|
||||
#define ISP_SMALL_MEMORY_SIZE
|
||||
|
||||
// Definition of hardware condition to enter in ISP mode on AVR Xmega devices
|
||||
#define ISP_PORT_DIR PORTX_DIR
|
||||
#define ISP_PORT_PINCTRL PORTX_PIN5CTRL
|
||||
#define ISP_PORT_IN PORTX_IN
|
||||
#define ISP_PORT_PIN 0 to 7
|
||||
|
||||
#endif // _CONF_ISP_H_
|
||||
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief USART Serial wrapper service for the SAM D/L/C/R devices.
|
||||
*
|
||||
* Copyright (c) 2009-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef _USART_SERIAL_H_
|
||||
#define _USART_SERIAL_H_
|
||||
|
||||
#include "compiler.h"
|
||||
#include "status_codes.h"
|
||||
#include "usart.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \name Serial Management Configuration */
|
||||
|
||||
typedef Sercom * usart_inst_t;
|
||||
|
||||
//struct usart_module usart;
|
||||
|
||||
/*! \brief Initializes the Usart in serial mode.
|
||||
*
|
||||
* \param[in,out] module Software instance of the USART to initialize.
|
||||
* \param[in] hw Base address of the hardware USART.
|
||||
* \param[in] config Configuration settings for the USART.
|
||||
*
|
||||
* \retval true if the initialization was successful
|
||||
* \retval false if initialization failed (error in baud rate calculation)
|
||||
*/
|
||||
static inline bool usart_serial_init(
|
||||
struct usart_module *const module,
|
||||
usart_inst_t const hw,
|
||||
const struct usart_config *const config)
|
||||
{
|
||||
if (usart_init(module, hw, config) == STATUS_OK) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** \brief Sends a character with the USART.
|
||||
*
|
||||
* \param[in,out] module Software instance of the USART.
|
||||
* \param[in] c Character to write.
|
||||
*
|
||||
* \return Status code
|
||||
*/
|
||||
static inline enum status_code usart_serial_putchar(
|
||||
struct usart_module *const module,
|
||||
uint8_t c)
|
||||
{
|
||||
while(STATUS_OK !=usart_write_wait(module, c));
|
||||
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
/** \brief Waits until a character is received, and returns it.
|
||||
*
|
||||
* \param[in,out] module Software instance of the USART.
|
||||
* \param[out] c Destination for the read character.
|
||||
*/
|
||||
static inline void usart_serial_getchar(
|
||||
struct usart_module *const module,
|
||||
uint8_t *c)
|
||||
{
|
||||
uint16_t temp = 0;
|
||||
|
||||
while(STATUS_OK != usart_read_wait(module, &temp));
|
||||
|
||||
*c = temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Send a sequence of bytes to USART device
|
||||
*
|
||||
* \param[in,out] module Software instance of the USART.
|
||||
* \param[in] tx_data Data buffer to read the data to write from.
|
||||
* \param[in] length Length of data to write.
|
||||
*/
|
||||
static inline enum status_code usart_serial_write_packet(
|
||||
struct usart_module *const module,
|
||||
const uint8_t *tx_data,
|
||||
uint16_t length)
|
||||
{
|
||||
return usart_write_buffer_wait(module, tx_data, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Receive a sequence of bytes from USART device
|
||||
*
|
||||
* \param[in,out] module Software instance of the USART.
|
||||
* \param[out] rx_data Data buffer to store the read data into.
|
||||
* \param[in] length Length of data to read.
|
||||
*/
|
||||
static inline enum status_code usart_serial_read_packet(
|
||||
struct usart_module *const module,
|
||||
uint8_t *rx_data,
|
||||
uint16_t length)
|
||||
{
|
||||
return usart_read_buffer_wait(module, rx_data, length);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _USART_SERIAL_H_
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Serial USART service configuration.
|
||||
*
|
||||
* Copyright (c) 2011-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef CONF_USART_SERIAL_H
|
||||
#define CONF_USART_SERIAL_H
|
||||
|
||||
/* A reference setting for UART */
|
||||
/** UART Interface */
|
||||
//#define CONF_UART CONSOLE_UART
|
||||
/** Baudrate setting */
|
||||
//#define CONF_UART_BAUDRATE 115200
|
||||
/** Parity setting */
|
||||
//#define CONF_UART_PARITY UART_MR_PAR_NO
|
||||
|
||||
|
||||
/* A reference setting for USART */
|
||||
/** USART Interface */
|
||||
//#define CONF_UART USART1
|
||||
/** Baudrate setting */
|
||||
//#define CONF_UART_BAUDRATE 115200
|
||||
/** Character length setting */
|
||||
//#define CONF_UART_CHAR_LENGTH US_MR_CHRL_8_BIT
|
||||
/** Parity setting */
|
||||
//#define CONF_UART_PARITY US_MR_PAR_NO
|
||||
/** Stop bits setting */
|
||||
//#define CONF_UART_STOP_BITS US_MR_NBSTOP_1_BIT
|
||||
|
||||
#endif/* CONF_USART_SERIAL_H_INCLUDED */
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
*
|
||||
* \file
|
||||
*
|
||||
* \brief USART Serial driver functions.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2010-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#include "serial.h"
|
||||
|
||||
/**
|
||||
* \brief Send a sequence of bytes to USART device
|
||||
*
|
||||
* \param usart Base address of the USART instance.
|
||||
* \param data Data buffer to read
|
||||
* \param len Length of data
|
||||
*
|
||||
*/
|
||||
status_code_t usart_serial_write_packet(usart_if usart, const uint8_t *data,
|
||||
size_t len)
|
||||
{
|
||||
while (len) {
|
||||
usart_serial_putchar(usart, *data);
|
||||
len--;
|
||||
data++;
|
||||
}
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Receive a sequence of bytes from USART device
|
||||
*
|
||||
* \param usart Base address of the USART instance.
|
||||
* \param data Data buffer to write
|
||||
* \param len Length of data
|
||||
*
|
||||
*/
|
||||
status_code_t usart_serial_read_packet(usart_if usart, uint8_t *data,
|
||||
size_t len)
|
||||
{
|
||||
while (len) {
|
||||
usart_serial_getchar(usart, data);
|
||||
len--;
|
||||
data++;
|
||||
}
|
||||
return STATUS_OK;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Chip-specific sleep manager configuration
|
||||
*
|
||||
* Copyright (c) 2012-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef CONF_SLEEPMGR_H
|
||||
#define CONF_SLEEPMGR_H
|
||||
|
||||
// Sleep manager options
|
||||
#define CONFIG_SLEEPMGR_ENABLE
|
||||
|
||||
#endif /* CONF_SLEEPMGR_H */
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief SAM3/SAM4 Sleep manager implementation.
|
||||
*
|
||||
* Copyright (c) 2012-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#include <compiler.h>
|
||||
#include <sleepmgr.h>
|
||||
|
||||
#if defined(CONFIG_SLEEPMGR_ENABLE) || defined(__DOXYGEN__)
|
||||
|
||||
uint8_t sleepmgr_locks[SLEEPMGR_NR_OF_MODES];
|
||||
|
||||
#endif /* CONFIG_SLEEPMGR_ENABLE */
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief SAM3/SAM4 Sleep manager implementation.
|
||||
*
|
||||
* Copyright (c) 2012-2016 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef SAM_SLEEPMGR_INCLUDED
|
||||
#define SAM_SLEEPMGR_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <compiler.h>
|
||||
#include <conf_sleepmgr.h>
|
||||
#include <sleep.h>
|
||||
#include <interrupt.h>
|
||||
|
||||
/**
|
||||
* \weakgroup sleepmgr_group
|
||||
* @{
|
||||
*/
|
||||
enum sleepmgr_mode {
|
||||
//! Active mode.
|
||||
SLEEPMGR_ACTIVE = 0,
|
||||
/*! WFE sleep mode.
|
||||
* Potential Wake Up sources:
|
||||
* fast startup events (USB, RTC, RTT, WKUPs),
|
||||
* interrupt, and events. */
|
||||
SLEEPMGR_SLEEP_WFE,
|
||||
/*! WFI sleep mode.
|
||||
* Potential Wake Up sources: fast startup events and interrupt. */
|
||||
SLEEPMGR_SLEEP_WFI,
|
||||
/*! Wait mode, wakeup fast (in 3ms).
|
||||
* XTAL is not disabled when sleep.
|
||||
* Potential Wake Up sources: fast startup events */
|
||||
SLEEPMGR_WAIT_FAST,
|
||||
/*! Wait mode.
|
||||
* Potential Wake Up sources: fast startup events */
|
||||
SLEEPMGR_WAIT,
|
||||
#if (!(SAMG51 || SAMG53 || SAMG54))
|
||||
//! Backup mode. Potential Wake Up sources: WKUPs, SM, RTT, RTC.
|
||||
SLEEPMGR_BACKUP,
|
||||
#endif
|
||||
SLEEPMGR_NR_OF_MODES,
|
||||
};
|
||||
|
||||
/**
|
||||
* \internal
|
||||
* \name Internal arrays
|
||||
* @{
|
||||
*/
|
||||
#if defined(CONFIG_SLEEPMGR_ENABLE) || defined(__DOXYGEN__)
|
||||
//! Sleep mode lock counters
|
||||
extern uint8_t sleepmgr_locks[];
|
||||
#endif /* CONFIG_SLEEPMGR_ENABLE */
|
||||
//! @}
|
||||
|
||||
|
||||
static inline void sleepmgr_sleep(const enum sleepmgr_mode sleep_mode)
|
||||
{
|
||||
Assert(sleep_mode != SLEEPMGR_ACTIVE);
|
||||
#ifdef CONFIG_SLEEPMGR_ENABLE
|
||||
cpu_irq_disable();
|
||||
|
||||
// Atomically enable the global interrupts and enter the sleep mode.
|
||||
pmc_sleep(sleep_mode);
|
||||
#else
|
||||
UNUSED(sleep_mode);
|
||||
cpu_irq_enable();
|
||||
#endif /* CONFIG_SLEEPMGR_ENABLE */
|
||||
|
||||
}
|
||||
|
||||
//! @}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SAM_SLEEPMGR_INCLUDED */
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Chip-specific sleep manager configuration
|
||||
*
|
||||
* Copyright (c) 2014-2015 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef CONF_SLEEPMGR_INCLUDED
|
||||
#define CONF_SLEEPMGR_INCLUDED
|
||||
|
||||
// Sleep manager options
|
||||
#define CONFIG_SLEEPMGR_ENABLE
|
||||
|
||||
#endif /* CONF_SLEEPMGR_INCLUDED */
|
||||
Loaded 100 of 797 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user