Compare commits
3 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de8d500c96 | ||
|
|
7dd07c370f | ||
|
|
e6a0cd667d |
100 changed files with 11187 additions and 441 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -1,3 +1,8 @@
|
||||||
*.bz2
|
*.bz2
|
||||||
|
*~
|
||||||
|
.o
|
||||||
|
.d
|
||||||
|
.elf
|
||||||
|
.lss
|
||||||
|
|
||||||
bootloaders/*/build/
|
bootloaders/*/build/
|
||||||
|
|
|
||||||
72
boards.txt
72
boards.txt
|
|
@ -42,32 +42,52 @@ adafruit_feather_m0.build.pid=0x800B
|
||||||
adafruit_feather_m0.bootloader.tool=openocd
|
adafruit_feather_m0.bootloader.tool=openocd
|
||||||
adafruit_feather_m0.bootloader.file=feather/samd21_sam_ba.bin
|
adafruit_feather_m0.bootloader.file=feather/samd21_sam_ba.bin
|
||||||
|
|
||||||
adafruit_radio_m0.name=Adafruit M0 Radio (Native USB Port)
|
adafruit_samd10.name=Adafruit SAMD10
|
||||||
adafruit_radio_m0.vid.0=0x239A
|
adafruit_samd10.upload.tool=bossac
|
||||||
adafruit_radio_m0.pid.0=0x8014
|
adafruit_samd10.upload.protocol=sam-ba
|
||||||
adafruit_radio_m0.vid.1=0x239A
|
adafruit_samd10.upload.maximum_size=15360
|
||||||
adafruit_radio_m0.pid.1=0x0014
|
adafruit_samd10.upload.use_1200bps_touch=false
|
||||||
adafruit_radio_m0.upload.tool=bossac
|
adafruit_samd10.upload.wait_for_upload_port=false
|
||||||
adafruit_radio_m0.upload.protocol=sam-ba
|
adafruit_samd10.upload.native_usb=false
|
||||||
adafruit_radio_m0.upload.maximum_size=262144
|
adafruit_samd10.build.mcu=cortex-m0plus
|
||||||
adafruit_radio_m0.upload.use_1200bps_touch=true
|
adafruit_samd10.build.f_cpu=48000000L
|
||||||
adafruit_radio_m0.upload.wait_for_upload_port=true
|
adafruit_samd10.build.board=SAMD_SAMD10
|
||||||
adafruit_radio_m0.upload.native_usb=true
|
adafruit_samd10.build.core=samd10
|
||||||
adafruit_radio_m0.build.mcu=cortex-m0plus
|
adafruit_samd10.build.extra_flags=-D__SAMD10D14AM__ {build.usb_flags}
|
||||||
adafruit_radio_m0.build.f_cpu=48000000L
|
adafruit_samd10.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
|
||||||
adafruit_radio_m0.build.usb_product="Radio M0"
|
adafruit_samd10.build.openocdscript=openocd_scripts/arduino_zero.cfg
|
||||||
adafruit_radio_m0.build.usb_manufacturer="Adafruit"
|
adafruit_samd10.build.variant=adafruit_samd10
|
||||||
adafruit_radio_m0.build.board=SAMD_ZERO
|
adafruit_samd10.build.variant_system_lib=
|
||||||
adafruit_radio_m0.build.core=arduino
|
adafruit_samd10.bootloader.tool=openocd
|
||||||
adafruit_radio_m0.build.extra_flags=-D__SAMR21G18A__ {build.usb_flags}
|
adafruit_samd10.bootloader.file=feather/samd21_sam_ba.bin
|
||||||
adafruit_radio_m0.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
|
|
||||||
adafruit_radio_m0.build.openocdscript=openocd_scripts/arduino_zero.cfg
|
|
||||||
adafruit_radio_m0.build.variant=zero_radio
|
#adafruit_radio_m0.name=Adafruit M0 Radio (Native USB Port)
|
||||||
adafruit_radio_m0.build.variant_system_lib=
|
#adafruit_radio_m0.vid.0=0x239A
|
||||||
adafruit_radio_m0.build.vid=0x239A
|
#adafruit_radio_m0.pid.0=0x8014
|
||||||
adafruit_radio_m0.build.pid=0x8014
|
#adafruit_radio_m0.vid.1=0x239A
|
||||||
adafruit_radio_m0.bootloader.tool=openocd
|
#adafruit_radio_m0.pid.1=0x0014
|
||||||
adafruit_radio_m0.bootloader.file=feather/samr21_sam_ba.bin
|
#adafruit_radio_m0.upload.tool=bossac
|
||||||
|
#adafruit_radio_m0.upload.protocol=sam-ba
|
||||||
|
#adafruit_radio_m0.upload.maximum_size=262144
|
||||||
|
#adafruit_radio_m0.upload.use_1200bps_touch=true
|
||||||
|
#adafruit_radio_m0.upload.wait_for_upload_port=true
|
||||||
|
#adafruit_radio_m0.upload.native_usb=true
|
||||||
|
#adafruit_radio_m0.build.mcu=cortex-m0plus
|
||||||
|
#adafruit_radio_m0.build.f_cpu=48000000L
|
||||||
|
#adafruit_radio_m0.build.usb_product="Radio M0"
|
||||||
|
#adafruit_radio_m0.build.usb_manufacturer="Adafruit"
|
||||||
|
#adafruit_radio_m0.build.board=SAMD_ZERO
|
||||||
|
#adafruit_radio_m0.build.core=arduino
|
||||||
|
#adafruit_radio_m0.build.extra_flags=-D__SAMR21G18A__ {build.usb_flags}
|
||||||
|
#adafruit_radio_m0.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
|
||||||
|
#adafruit_radio_m0.build.openocdscript=openocd_scripts/arduino_zero.cfg
|
||||||
|
#adafruit_radio_m0.build.variant=zero_radio
|
||||||
|
#adafruit_radio_m0.build.variant_system_lib=
|
||||||
|
#adafruit_radio_m0.build.vid=0x239A
|
||||||
|
#adafruit_radio_m0.build.pid=0x8014
|
||||||
|
#adafruit_radio_m0.bootloader.tool=openocd
|
||||||
|
#adafruit_radio_m0.bootloader.file=feather/samr21_sam_ba.bin
|
||||||
|
|
||||||
#adafruit_metro_m0.name=Adafruit Metro M0 (Native USB Port)
|
#adafruit_metro_m0.name=Adafruit Metro M0 (Native USB Port)
|
||||||
#adafruit_metro_m0.vid.0=0x239A
|
#adafruit_metro_m0.vid.0=0x239A
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,10 @@ endif
|
||||||
# Adafruit Feather Zero (0x239A 0x000B)
|
# Adafruit Feather Zero (0x239A 0x000B)
|
||||||
#CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x0B -DUSB_VID_LOW=0x9A -DUSB_VID_HIGH=0x23
|
#CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x0B -DUSB_VID_LOW=0x9A -DUSB_VID_HIGH=0x23
|
||||||
# Adafruit Feather SAMR (0x239A 0x0014)
|
# Adafruit Feather SAMR (0x239A 0x0014)
|
||||||
CFLAGS_EXTRA?=-D__SAMR21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x14 -DUSB_VID_LOW=0x9A -DUSB_VID_HIGH=0x23
|
#CFLAGS_EXTRA?=-D__SAMR21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x14 -DUSB_VID_LOW=0x9A -DUSB_VID_HIGH=0x23
|
||||||
|
# Adafruit SAMD10
|
||||||
|
CFLAGS_EXTRA?=-D__SAMD10D14AM__ -DSAM_BA_INTERFACE=SAM_BA_UART_ONLY -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x00 -DUSB_VID_LOW=0x9A -DUSB_VID_HIGH=0x23
|
||||||
|
|
||||||
# Arduino Zero (PID == 0x004D)
|
# Arduino Zero (PID == 0x004D)
|
||||||
# CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x4D -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23
|
# CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x4D -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23
|
||||||
# Genuino Zero (PID == 0x024D)
|
# Genuino Zero (PID == 0x024D)
|
||||||
|
|
@ -82,7 +85,7 @@ CFLAGS_EXTRA?=-D__SAMR21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x14 -DUSB_VID_
|
||||||
# CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x02 -DUSB_PID_LOW=0x4E -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23
|
# CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x02 -DUSB_PID_LOW=0x4E -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23
|
||||||
|
|
||||||
# samd or samr
|
# samd or samr
|
||||||
NAME=samr21_sam_ba
|
NAME=samd10_sam_ba
|
||||||
|
|
||||||
INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/Device/ATMEL/"
|
INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/Device/ATMEL/"
|
||||||
|
|
||||||
|
|
|
||||||
72
bootloaders/feather/board_def_d10.h
Normal file
72
bootloaders/feather/board_def_d10.h
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
Copyright (c) 2015 Atmel Corporation/Thibaut VIARD. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _BOARD_DEF_D10_H_
|
||||||
|
#define _BOARD_DEF_D10_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If BOOT_DOUBLE_TAP_ADDRESS is defined the bootloader is started by
|
||||||
|
* quickly tapping two times on the reset button.
|
||||||
|
* BOOT_DOUBLE_TAP_ADDRESS must point to a free SRAM cell that must not
|
||||||
|
* be touched from the loaded application.
|
||||||
|
*/
|
||||||
|
#define BOOT_DOUBLE_TAP_ADDRESS (0x20007FFCul)
|
||||||
|
#define BOOT_DOUBLE_TAP_DATA (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If BOOT_LOAD_PIN is defined the bootloader is started if the selected
|
||||||
|
* pin is tied LOW.
|
||||||
|
*/
|
||||||
|
//#define BOOT_LOAD_PIN PIN_PA21 // Pin 7
|
||||||
|
//#define BOOT_LOAD_PIN PIN_PA15 // Pin 5
|
||||||
|
#define BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1f))
|
||||||
|
|
||||||
|
#define CPU_FREQUENCY (48000000ul)
|
||||||
|
|
||||||
|
#define BOOT_USART_MODULE SERCOM0
|
||||||
|
#define BOOT_USART_BUS_CLOCK_INDEX PM_APBCMASK_SERCOM0
|
||||||
|
#define BOOT_USART_PER_CLOCK_INDEX GCLK_ID_SERCOM0_CORE
|
||||||
|
#define BOOT_USART_PAD_SETTINGS UART_RX_PAD3_TX_PAD2
|
||||||
|
#define BOOT_USART_PAD3 PINMUX_PA11C_SERCOM0_PAD3
|
||||||
|
#define BOOT_USART_PAD2 PINMUX_PA10C_SERCOM0_PAD2
|
||||||
|
#define BOOT_USART_PAD1 PINMUX_UNUSED
|
||||||
|
#define BOOT_USART_PAD0 PINMUX_UNUSED
|
||||||
|
|
||||||
|
/* Frequency of the board main oscillator */
|
||||||
|
#define VARIANT_MAINOSC (32768ul)
|
||||||
|
|
||||||
|
/* Master clock frequency */
|
||||||
|
#define VARIANT_MCK CPU_FREQUENCY
|
||||||
|
|
||||||
|
#define NVM_SW_CALIB_DFLL48M_COARSE_VAL (58)
|
||||||
|
#define NVM_SW_CALIB_DFLL48M_FINE_VAL (64)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* LEDs definitions
|
||||||
|
*/
|
||||||
|
#define BOARD_LED_PORT (0)
|
||||||
|
#define BOARD_LED_PIN (9)
|
||||||
|
|
||||||
|
#define BOARD_LEDRX_PORT (0)
|
||||||
|
#define BOARD_LEDRX_PIN (9)
|
||||||
|
|
||||||
|
#define BOARD_LEDTX_PORT (0)
|
||||||
|
#define BOARD_LEDTX_PIN (9)
|
||||||
|
|
||||||
|
#endif // _BOARD_DEFINITIONS_H_
|
||||||
72
bootloaders/feather/board_def_feather.h
Normal file
72
bootloaders/feather/board_def_feather.h
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
Copyright (c) 2015 Atmel Corporation/Thibaut VIARD. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _BOARD_DEF_FEATHER_H_
|
||||||
|
#define _BOARD_DEF_FEATHER_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If BOOT_DOUBLE_TAP_ADDRESS is defined the bootloader is started by
|
||||||
|
* quickly tapping two times on the reset button.
|
||||||
|
* BOOT_DOUBLE_TAP_ADDRESS must point to a free SRAM cell that must not
|
||||||
|
* be touched from the loaded application.
|
||||||
|
*/
|
||||||
|
#define BOOT_DOUBLE_TAP_ADDRESS (0x20007FFCul)
|
||||||
|
#define BOOT_DOUBLE_TAP_DATA (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If BOOT_LOAD_PIN is defined the bootloader is started if the selected
|
||||||
|
* pin is tied LOW.
|
||||||
|
*/
|
||||||
|
//#define BOOT_LOAD_PIN PIN_PA21 // Pin 7
|
||||||
|
//#define BOOT_LOAD_PIN PIN_PA15 // Pin 5
|
||||||
|
#define BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1f))
|
||||||
|
|
||||||
|
#define CPU_FREQUENCY (48000000ul)
|
||||||
|
|
||||||
|
#define BOOT_USART_MODULE SERCOM0
|
||||||
|
#define BOOT_USART_BUS_CLOCK_INDEX PM_APBCMASK_SERCOM0
|
||||||
|
#define BOOT_USART_PER_CLOCK_INDEX GCLK_ID_SERCOM0_CORE
|
||||||
|
#define BOOT_USART_PAD_SETTINGS UART_RX_PAD3_TX_PAD2
|
||||||
|
#define BOOT_USART_PAD3 PINMUX_PA11C_SERCOM0_PAD3
|
||||||
|
#define BOOT_USART_PAD2 PINMUX_PA10C_SERCOM0_PAD2
|
||||||
|
#define BOOT_USART_PAD1 PINMUX_UNUSED
|
||||||
|
#define BOOT_USART_PAD0 PINMUX_UNUSED
|
||||||
|
|
||||||
|
/* Frequency of the board main oscillator */
|
||||||
|
#define VARIANT_MAINOSC (32768ul)
|
||||||
|
|
||||||
|
/* Master clock frequency */
|
||||||
|
#define VARIANT_MCK CPU_FREQUENCY
|
||||||
|
|
||||||
|
#define NVM_SW_CALIB_DFLL48M_COARSE_VAL (58)
|
||||||
|
#define NVM_SW_CALIB_DFLL48M_FINE_VAL (64)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* LEDs definitions
|
||||||
|
*/
|
||||||
|
#define BOARD_LED_PORT (0)
|
||||||
|
#define BOARD_LED_PIN (17)
|
||||||
|
|
||||||
|
#define BOARD_LEDRX_PORT (1)
|
||||||
|
#define BOARD_LEDRX_PIN (3)
|
||||||
|
|
||||||
|
#define BOARD_LEDTX_PORT (0)
|
||||||
|
#define BOARD_LEDTX_PIN (27)
|
||||||
|
|
||||||
|
#endif // _BOARD_DEFINITIONS_H_
|
||||||
|
|
@ -20,53 +20,13 @@
|
||||||
#ifndef _BOARD_DEFINITIONS_H_
|
#ifndef _BOARD_DEFINITIONS_H_
|
||||||
#define _BOARD_DEFINITIONS_H_
|
#define _BOARD_DEFINITIONS_H_
|
||||||
|
|
||||||
/*
|
#if defined(__SAMR21G18A__) || defined(__SAMD21G18A__)
|
||||||
* If BOOT_DOUBLE_TAP_ADDRESS is defined the bootloader is started by
|
#include "board_def_feather.h"
|
||||||
* quickly tapping two times on the reset button.
|
#endif
|
||||||
* BOOT_DOUBLE_TAP_ADDRESS must point to a free SRAM cell that must not
|
|
||||||
* be touched from the loaded application.
|
|
||||||
*/
|
|
||||||
#define BOOT_DOUBLE_TAP_ADDRESS (0x20007FFCul)
|
|
||||||
#define BOOT_DOUBLE_TAP_DATA (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))
|
|
||||||
|
|
||||||
/*
|
#if defined(__SAMD10D14AM__)
|
||||||
* If BOOT_LOAD_PIN is defined the bootloader is started if the selected
|
#include "board_def_d10.h"
|
||||||
* pin is tied LOW.
|
#endif
|
||||||
*/
|
|
||||||
//#define BOOT_LOAD_PIN PIN_PA21 // Pin 7
|
|
||||||
//#define BOOT_LOAD_PIN PIN_PA15 // Pin 5
|
|
||||||
#define BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1f))
|
|
||||||
|
|
||||||
#define CPU_FREQUENCY (48000000ul)
|
|
||||||
|
|
||||||
#define BOOT_USART_MODULE SERCOM0
|
|
||||||
#define BOOT_USART_BUS_CLOCK_INDEX PM_APBCMASK_SERCOM0
|
|
||||||
#define BOOT_USART_PER_CLOCK_INDEX GCLK_ID_SERCOM0_CORE
|
|
||||||
#define BOOT_USART_PAD_SETTINGS UART_RX_PAD3_TX_PAD2
|
|
||||||
#define BOOT_USART_PAD3 PINMUX_PA11C_SERCOM0_PAD3
|
|
||||||
#define BOOT_USART_PAD2 PINMUX_PA10C_SERCOM0_PAD2
|
|
||||||
#define BOOT_USART_PAD1 PINMUX_UNUSED
|
|
||||||
#define BOOT_USART_PAD0 PINMUX_UNUSED
|
|
||||||
|
|
||||||
/* Frequency of the board main oscillator */
|
|
||||||
#define VARIANT_MAINOSC (32768ul)
|
|
||||||
|
|
||||||
/* Master clock frequency */
|
|
||||||
#define VARIANT_MCK CPU_FREQUENCY
|
|
||||||
|
|
||||||
#define NVM_SW_CALIB_DFLL48M_COARSE_VAL (58)
|
|
||||||
#define NVM_SW_CALIB_DFLL48M_FINE_VAL (64)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* LEDs definitions
|
|
||||||
*/
|
|
||||||
#define BOARD_LED_PORT (0)
|
|
||||||
#define BOARD_LED_PIN (17)
|
|
||||||
|
|
||||||
#define BOARD_LEDRX_PORT (1)
|
|
||||||
#define BOARD_LEDRX_PIN (3)
|
|
||||||
|
|
||||||
#define BOARD_LEDTX_PORT (0)
|
|
||||||
#define BOARD_LEDTX_PIN (27)
|
|
||||||
|
|
||||||
#endif // _BOARD_DEFINITIONS_H_
|
#endif // _BOARD_DEFINITIONS_H_
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if (SAM_BA_INTERFACE != SAM_BA_UART_ONLY)
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "board_driver_usb.h"
|
#include "board_driver_usb.h"
|
||||||
#include "sam_ba_usb.h"
|
#include "sam_ba_usb.h"
|
||||||
|
|
@ -400,3 +402,5 @@ void USB_Configure(Usb *pUsb)
|
||||||
usb_endpoint_table[USB_EP_COMM].DeviceDescBank[1].PCKSIZE.bit.SIZE = 0;
|
usb_endpoint_table[USB_EP_COMM].DeviceDescBank[1].PCKSIZE.bit.SIZE = 0;
|
||||||
pUsb->DEVICE.DeviceEndpoint[USB_EP_COMM].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK1RDY;
|
pUsb->DEVICE.DeviceEndpoint[USB_EP_COMM].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK1RDY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@
|
||||||
#ifndef _BOARD_DRIVER_USB_H_
|
#ifndef _BOARD_DRIVER_USB_H_
|
||||||
#define _BOARD_DRIVER_USB_H_
|
#define _BOARD_DRIVER_USB_H_
|
||||||
|
|
||||||
|
#if (SAM_BA_INTERFACE != SAM_BA_UART_ONLY)
|
||||||
|
|
||||||
#include "sam_ba_cdc.h"
|
#include "sam_ba_cdc.h"
|
||||||
|
|
||||||
extern UsbDeviceDescriptor usb_endpoint_table[MAX_EP];
|
extern UsbDeviceDescriptor usb_endpoint_table[MAX_EP];
|
||||||
|
|
@ -42,4 +44,5 @@ void USB_SendZlp(Usb *pUsb);
|
||||||
void USB_SetAddress(Usb *pUsb, uint16_t wValue);
|
void USB_SetAddress(Usb *pUsb, uint16_t wValue);
|
||||||
void USB_Configure(Usb *pUsb);
|
void USB_Configure(Usb *pUsb);
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif // _BOARD_DRIVER_USB_H_
|
#endif // _BOARD_DRIVER_USB_H_
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if (SAM_BA_INTERFACE != SAM_BA_UART_ONLY)
|
||||||
|
|
||||||
#include "sam_ba_cdc.h"
|
#include "sam_ba_cdc.h"
|
||||||
#include "board_driver_usb.h"
|
#include "board_driver_usb.h"
|
||||||
|
|
||||||
|
|
@ -100,3 +102,5 @@ uint32_t cdc_read_buf_xmd(/*P_USB_CDC pCdc,*/ void* data, uint32_t length)
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@
|
||||||
#ifndef _SAM_BA_USB_CDC_H_
|
#ifndef _SAM_BA_USB_CDC_H_
|
||||||
#define _SAM_BA_USB_CDC_H_
|
#define _SAM_BA_USB_CDC_H_
|
||||||
|
|
||||||
|
#if (SAM_BA_INTERFACE != SAM_BA_UART_ONLY)
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "sam_ba_usb.h"
|
#include "sam_ba_usb.h"
|
||||||
|
|
||||||
|
|
@ -88,4 +90,6 @@ uint32_t cdc_read_buf(/*P_USB_CDC pCdc,*/ void* data, uint32_t length);
|
||||||
*/
|
*/
|
||||||
uint32_t cdc_read_buf_xmd(/*P_USB_CDC pCdc,*/ void* data, uint32_t length);
|
uint32_t cdc_read_buf_xmd(/*P_USB_CDC pCdc,*/ void* data, uint32_t length);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _SAM_BA_USB_CDC_H_
|
#endif // _SAM_BA_USB_CDC_H_
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if (SAM_BA_INTERFACE != SAM_BA_UART_ONLY)
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "sam_ba_usb.h"
|
#include "sam_ba_usb.h"
|
||||||
|
|
@ -485,4 +487,6 @@ uint32_t USB_SendString(Usb *pUsb, const char* ascii_string, uint8_t length, uin
|
||||||
|
|
||||||
return USB_Write(pUsb, (const char*)unicode_string, resulting_length, USB_EP_CTRL);
|
return USB_Write(pUsb, (const char*)unicode_string, resulting_length, USB_EP_CTRL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif // 0
|
#endif // 0
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@
|
||||||
#ifndef CDC_ENUMERATE_H
|
#ifndef CDC_ENUMERATE_H
|
||||||
#define CDC_ENUMERATE_H
|
#define CDC_ENUMERATE_H
|
||||||
|
|
||||||
|
#if (SAM_BA_INTERFACE != SAM_BA_UART_ONLY)
|
||||||
|
|
||||||
#include <sam.h>
|
#include <sam.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|
@ -102,6 +104,6 @@ uint32_t USB_SendString(Usb *pUsb, const char* ascii_string, uint8_t length, uin
|
||||||
|
|
||||||
extern USB_CDC sam_ba_cdc;
|
extern USB_CDC sam_ba_cdc;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // CDC_ENUMERATE_H
|
#endif // CDC_ENUMERATE_H
|
||||||
|
|
|
||||||
BIN
bootloaders/feather/samd10_sam_ba.bin
Normal file
BIN
bootloaders/feather/samd10_sam_ba.bin
Normal file
Binary file not shown.
249
bootloaders/feather/samd10_sam_ba.hex
Normal file
249
bootloaders/feather/samd10_sam_ba.hex
Normal file
|
|
@ -0,0 +1,249 @@
|
||||||
|
:10000000FC7F00204D020000390200003D0200008C
|
||||||
|
:1000100000000000000000000000000000000000E0
|
||||||
|
:10002000000000000000000000000000410200008D
|
||||||
|
:10003000000000000000000045020000490200002E
|
||||||
|
:1000400010B5064C2378002B07D1054B002B02D0AE
|
||||||
|
:10005000044800E000BF0123237010BD1000002001
|
||||||
|
:1000600000000000580F000008B5084B002B03D01B
|
||||||
|
:100070000748084900E000BF07480368002B03D089
|
||||||
|
:10008000064B002B00D0984708BDC046000000007A
|
||||||
|
:10009000580F0000140000200C0000200000000099
|
||||||
|
:1000A00010B5C3699C07FCD403680224A343036012
|
||||||
|
:1000B000C46901231C42FBD1046823430360036825
|
||||||
|
:1000C000DC07FCD4C46901231C42FBD1C469DC40B9
|
||||||
|
:1000D0001C42F7D1084B1A430260C3695A07FCD48B
|
||||||
|
:1000E000C0239B0243608181C3699C07FCD40368E1
|
||||||
|
:1000F00002221343036010BD04000040037EDA07B0
|
||||||
|
:10010000FCD5018570470000027E01235107FBD515
|
||||||
|
:10011000428B1A4207D1428BDA401A4203D1428BFA
|
||||||
|
:1001200092081A4202D0034B01221A70008DC0B20D
|
||||||
|
:100130007047C0462C00002030B5364A1E23516857
|
||||||
|
:100140000820994302231943516033498A690243C5
|
||||||
|
:100150008A613248324A9082908A03439382D368FC
|
||||||
|
:100160009807FCD52F4B012018701878C40704D5C8
|
||||||
|
:100170002C48407840B20028F7DB0120986058787E
|
||||||
|
:1001800040B20028FBDB284C26484460587840B237
|
||||||
|
:100190000028FBDB82242348E4014480587840B2E5
|
||||||
|
:1001A0000028FBDB908C8024A0439084D068C50697
|
||||||
|
:1001B000FCD51E4C1A48C462D4681948E506FBD524
|
||||||
|
:1001C000848C1B4D2C438484D4681548E506FBD5EC
|
||||||
|
:1001D000848C02252C438484D0680406FCD5104806
|
||||||
|
:1001E000C0684506F8D5D068C406FCD500229A60E0
|
||||||
|
:1001F0005A7852B2002AFBDB0E480A4A50605A78FD
|
||||||
|
:1002000052B2002AFBDB00230B724B728B72CB7253
|
||||||
|
:1002100030BDC04600400041000400400C06000014
|
||||||
|
:1002200000080040000C004001050100B805FF7DFA
|
||||||
|
:10023000040A0000000703000EBEFEE70DBEFEE745
|
||||||
|
:1002400005BEFEE702BEFEE701BEFEE70E4A0F480E
|
||||||
|
:1002500038B5824204D10E4A0E4B93420ED10AE0C9
|
||||||
|
:100260000D4C9442F7D00023D1188842F3D9E558B9
|
||||||
|
:1002700004330D60F8E700F04DF804E09342FAD241
|
||||||
|
:10028000002102C3FAE7FEE7000000201000002072
|
||||||
|
:10029000BC010020100000205C0F0000194A10B5BE
|
||||||
|
:1002A0001188FA24013189B2174BA400A14201D070
|
||||||
|
:1002B00011801CE000211180144900240C57604378
|
||||||
|
:1002C0001C88001980B204B2FF2C01DC188002E007
|
||||||
|
:1002D000FF20188008700024185F002803DA00202F
|
||||||
|
:1002E00018800120087080200949800088611288E8
|
||||||
|
:1002F00000215B5E9A4203D18022054B92005A6135
|
||||||
|
:1003000010BDC0462E00002030000020000000205C
|
||||||
|
:100310000044004110B5234B802292009A605A613C
|
||||||
|
:10032000214A1C1C117801221140204B0022002977
|
||||||
|
:100330000AD118681E4A904201D1196018E01A606B
|
||||||
|
:100340001C4A013A002AFCD11A601B4B1A68191C7E
|
||||||
|
:10035000501C0DD0D8B200280AD180208000A061A6
|
||||||
|
:1003600082F30888FF229343144A93604B6818472E
|
||||||
|
:10037000FFF7E2FE62B600F0CBFA80239B00A36198
|
||||||
|
:100380000320FFF78BFF0E4B1B78002BF8D100F0FA
|
||||||
|
:1003900033FB0028F4D0012000F014F800F068F8D6
|
||||||
|
:1003A000FCE7C0460044004138040040FC7F0020C8
|
||||||
|
:1003B0003581730748E801000020000000ED00E0EF
|
||||||
|
:1003C00032000020012804D1024B034A1A60034B7B
|
||||||
|
:1003D00018707047A0000020000D000039000020B8
|
||||||
|
:1003E00030B51A4B85B01B78002B29D0042901D1D8
|
||||||
|
:1003F000026804E0022901D1028800E00278490085
|
||||||
|
:1004000004A843180B3B5C1AA3420BD00F201040EA
|
||||||
|
:10041000092802D83025284300E037301870120927
|
||||||
|
:10042000013BF1E701A830230370782343700A22CF
|
||||||
|
:1004300043189A700D22DA70054B04311B6801E0F5
|
||||||
|
:10044000034B1B68DB68984705B030BD38000020BF
|
||||||
|
:10045000A000002072B6EFF30883044A136003681B
|
||||||
|
:1004600083F30888436818477047C046A4000020FB
|
||||||
|
:10047000F0B58FB006A9CE4A0B1C31CA31C351CAA0
|
||||||
|
:1004800051C360CA60C3CB4CCB48A3687A255B03D9
|
||||||
|
:100490005B0F9B005B58C9490360A26892B253434B
|
||||||
|
:1004A0000A60C749C74A0B6000231360C64B1D7022
|
||||||
|
:1004B0000320FFF7F3FEC54BC54D1B68281C1B69C5
|
||||||
|
:1004C00040219847C34B00221860C34B1D60C34BAB
|
||||||
|
:1004D000C24DC04F1A60286839688842E8D2BE4BC6
|
||||||
|
:1004E0001B681A78FF2A00D1F6E1232A00D0CDE15B
|
||||||
|
:1004F000BB4E3378002B05D0B44BBA481B680221A1
|
||||||
|
:10050000DB689847B04B1B78532B38D13B682A687F
|
||||||
|
:1005100093421ED9B04801322A609A1AB24B016840
|
||||||
|
:100520001B6801310160B14E9A4201D2326000E095
|
||||||
|
:100530003360A44832680068029000F0BBFB336867
|
||||||
|
:1005400029685A182A60A44A1668F1181160A84A46
|
||||||
|
:1005500013702B68013B2B609F4B1A68013A1A609D
|
||||||
|
:10056000A34BA14A1B7811688B4206D2974A954843
|
||||||
|
:1005700012680068C91A92699047C04675E1522B0B
|
||||||
|
:1005800007D1904A914B10681B68974A5B691168C4
|
||||||
|
:100590006AE14F2B05D18B4B934A1B6812681A7086
|
||||||
|
:1005A00063E1482B05D1874B8F4A1B6812681A807C
|
||||||
|
:1005B0005BE1572B05D1834B8B4A1B6812681A608D
|
||||||
|
:1005C00053E16F2B03D17F4B0121186807E0682BA3
|
||||||
|
:1005D00008D17C4B84481B6802211B880360FFF70D
|
||||||
|
:1005E000FFFE42E1772B06D1764B7F481B68042142
|
||||||
|
:1005F0001B680360F3E7472B13D17B4B1868FFF7A9
|
||||||
|
:1006000029FF7C4B1B6883F3088862B67A4B1B7802
|
||||||
|
:10061000002B00D129E16D4B06201B681B68984711
|
||||||
|
:1006200023E1542B04D101233370684B1B685CE039
|
||||||
|
:100630004E2B0BD13378002B05D1644B69481B68D6
|
||||||
|
:100640000221DB689847002333700EE1562B50D10E
|
||||||
|
:100650005E4D01212B686948DB6898472B680321B0
|
||||||
|
:10066000DB6867489847674E2B68301CDB680121C0
|
||||||
|
:1006700098472B680D21DB68634898472B68301C2E
|
||||||
|
:10068000DB6801219847544F604B544E3B60002378
|
||||||
|
:1006900033603A1C311C1368581C10601B7803939C
|
||||||
|
:1006A000002B03D00B6801330B60F4E72B68316833
|
||||||
|
:1006B000DB68564898472B685248DB680121984709
|
||||||
|
:1006C0000398306052483860434A1368591C1160DF
|
||||||
|
:1006D0001A78424B002A03D01A6801321A60F3E7F5
|
||||||
|
:1006E0002A681968D36898472B68DB683D4802215F
|
||||||
|
:1006F000BAE03D4A582B15D12F4E314D366813685C
|
||||||
|
:100700002A68B100934208D25808E061414820802D
|
||||||
|
:10071000207DC507FCD55B18F4E72C4B3E481B68D1
|
||||||
|
:10072000DB68A0E0592B33D11268264B3B49002AE5
|
||||||
|
:1007300002D11B680B6026E0086819686368802591
|
||||||
|
:10074000AB4392086360002A1DD0354B2380237D84
|
||||||
|
:10075000DE07FCD50023184D2D680095AD08AB428F
|
||||||
|
:1007600002D3304D258006E09342FAD09D004659D1
|
||||||
|
:1007700001334E51EFE7257DEE07FCD59D00491969
|
||||||
|
:100780004019D21ADFE7114B27481B68DB686AE083
|
||||||
|
:100790005A2B6AD10B4B17681D680026EF19BD4212
|
||||||
|
:1007A00044D02878311C00F049F90135061CF6E7E1
|
||||||
|
:1007B000E00C0000004000415800002050000020E4
|
||||||
|
:1007C0004C0000209C00002048000020A0000020D9
|
||||||
|
:1007D0005C00002040000020440000205400002065
|
||||||
|
:1007E00038000020400D0000A8000020AC000020D0
|
||||||
|
:1007F0003C000020A4000020390000201C0D000057
|
||||||
|
:10080000450D00001E0D0000490D0000200D0000E8
|
||||||
|
:100810002C0D000002A5FFFF350D00003400002064
|
||||||
|
:1008200044A5FFFF04A5FFFF390D00002E4D2F4802
|
||||||
|
:100830002B680121DB68984707230F223240111CE7
|
||||||
|
:1008400036093031092A00DD07311020C0186A4608
|
||||||
|
:100850008154013BF1D22B6804A8DB68082198473A
|
||||||
|
:100860002B682348DB6803219847224D7A232B709D
|
||||||
|
:10087000214B00221A60214B1B7893422CD01A4B3B
|
||||||
|
:1008800001211B681E48DB68984725E0111C3039A0
|
||||||
|
:10089000C8B2194B092804D81E68320111431960E7
|
||||||
|
:1008A0001AE0111C4139052903D81868373A0101AB
|
||||||
|
:1008B00006E0111C6139052904D81D68573A290141
|
||||||
|
:1008C0000A4308E02C2A03D10E4A1E68166001E094
|
||||||
|
:1008D00008490A7000221A600B4B1A6801321A602C
|
||||||
|
:1008E0000A4B1A680132F3E5A00000203D0D00001C
|
||||||
|
:1008F0003F0D000048000020A80000203800002024
|
||||||
|
:10090000430D00009C000020540000204400002003
|
||||||
|
:1009100010B51C4B01201A78022402431A701A4B9E
|
||||||
|
:100920000F221978914319701978214319701749CA
|
||||||
|
:100930000C782043087019780A401A701A78202120
|
||||||
|
:100940000A431A70124B04211A6A0A431A62114BA5
|
||||||
|
:10095000114A5A805A7852B2002AFBDBC4220F484F
|
||||||
|
:100960000F499203FFF79CFB0E4A002313700E4AB7
|
||||||
|
:1009700013700E4A13700E4A13700E4A13700E4A0B
|
||||||
|
:10098000137010BD4A440041354400414B440041BE
|
||||||
|
:1009900000040040000C0040144000000008004229
|
||||||
|
:1009A0002AF60000B000002037010020B10000202E
|
||||||
|
:1009B000B4000020380100203501002008B5C1B284
|
||||||
|
:1009C0000248FFF79BFB012008BDC046000800421B
|
||||||
|
:1009D000024B187E4007C00F7047C0460008004217
|
||||||
|
:1009E00008B5FFF7F5FF0028FBD00248FFF78CFBA6
|
||||||
|
:1009F00008BDC0460008004208B5FFF7E9FF002324
|
||||||
|
:100A0000984205D0FFF7ECFF031C233B5A425341A9
|
||||||
|
:100A1000181C08BD70B5041C0D1C4618B44204D047
|
||||||
|
:100A20002078FFF7CBFF0134F8E7281C70BD10B524
|
||||||
|
:100A3000041CFFF7D5FF2070012010BD0B0A5840A1
|
||||||
|
:100A4000034B4000C05A0902484080B27047C0467C
|
||||||
|
:100A5000580D0000F7B50024051C0F1C261CBC42D5
|
||||||
|
:100A600020D0FFF7BDFF114BC0B21B780190002BC7
|
||||||
|
:100A70001AD1311CFFF7E2FF0D4B061C1A88002A21
|
||||||
|
:100A800004D10C4A11782A1C002907D001996A1C4C
|
||||||
|
:100A90002970802F02D11988013919800134A4B23C
|
||||||
|
:100AA000151CDCE7301C00E00120FEBD35010020F4
|
||||||
|
:100AB000B200002036010020F0B53E4E85B0002285
|
||||||
|
:100AC00003900C1C32703C4B914201D1012201E099
|
||||||
|
:100AD0003A490C801A707F231C4201D080349C4319
|
||||||
|
:100AE000FFF77EFF3378C0B2002B07D000253570AA
|
||||||
|
:100AF000FFF776FF3378C0B2AB4236D1432803D03C
|
||||||
|
:100B0000712853D01528EBD1012300930120FFF762
|
||||||
|
:100B100055FF0098FFF752FF00998025C843C0B2E7
|
||||||
|
:100B2000FFF74CFF039B00270293244A1388002BF6
|
||||||
|
:100B30001DD1214901930978002918D10198FFF7A7
|
||||||
|
:100B40003DFF391C0198FFF779FF013D071C002D7F
|
||||||
|
:100B5000EBD1000AC0B2FFF731FFF8B2FFF72EFF6A
|
||||||
|
:100B6000FFF73EFF3378002B0AD035701FE0029963
|
||||||
|
:100B7000013B09781380029B019101330293DDE769
|
||||||
|
:100B8000C0B2062807D1009B03990133DBB2803144
|
||||||
|
:100B90000093803C0391002CB8D10420FFF70EFF96
|
||||||
|
:100BA000FFF71EFF044B01251C7000E00025281CE8
|
||||||
|
:100BB00005B0F0BD3501002036010020B200002054
|
||||||
|
:100BC000F0B5384C87B0002301902370994201D1D1
|
||||||
|
:100BD000012301E0344A1180344A64261370432013
|
||||||
|
:100BE000FFF7ECFE324FFFF7F3FE002803D1002F92
|
||||||
|
:100BF00003D0013FF7E7002F03D1013E002EEED1D5
|
||||||
|
:100C00004DE00125FFF7ECFE2378002B38D1C0B270
|
||||||
|
:100C10000290012805D004283DD10620FFF7CEFE22
|
||||||
|
:100C200039E005AE0221301CFFF714FF0198802146
|
||||||
|
:100C3000FFF710FF23780390002B18D1FFF7D0FEA9
|
||||||
|
:100C40000702FFF7CDFEBFB223783F18BFB2012BDA
|
||||||
|
:100C50000DD0039B9F4207D13378AB4204D1EB43C5
|
||||||
|
:100C60007278DBB29A4204D01820FFF7A7FE002367
|
||||||
|
:100C700003E00620FFF7A2FE029B2278002A02D0A2
|
||||||
|
:100C8000002626700BE0012B05D1019A6B1C8032E7
|
||||||
|
:100C9000DDB20192B6E7054A002313700126301C2D
|
||||||
|
:100CA00007B0F0BD35010020B20000203601002061
|
||||||
|
:100CB00000350C0010B50023934203D0CC5CC45423
|
||||||
|
:100CC0000133F9E710BD0000F8B5C046F8BC08BC18
|
||||||
|
:100CD0009E467047F8B5C046F8BC08BC9E467047B3
|
||||||
|
:100CE000080000001000000020000000400000008C
|
||||||
|
:100CF000800000000001000000020000000400006D
|
||||||
|
:100D0000BD090000E1090000D1090000150A00003A
|
||||||
|
:100D10002F0A0000B90A0000C10B00007600200075
|
||||||
|
:100D20004D617920323620323031360032313A345A
|
||||||
|
:100D3000333A313100580A0D00590A0D005A002388
|
||||||
|
:100D40000A0D003E00322E30005B41726475696E00
|
||||||
|
:100D50006F3A58595A5D000000002110422063305C
|
||||||
|
:100D60008440A550C660E770088129914AA16BB103
|
||||||
|
:100D70008CC1ADD1CEE1EFF13112100273325222AB
|
||||||
|
:100D8000B5529442F772D662399318837BB35AA353
|
||||||
|
:100D9000BDD39CC3FFF3DEE362244334200401147B
|
||||||
|
:100DA000E664C774A44485546AA54BB528850995A3
|
||||||
|
:100DB000EEE5CFF5ACC58DD553367226111630064B
|
||||||
|
:100DC000D776F6669556B4465BB77AA719973887F3
|
||||||
|
:100DD000DFF7FEE79DD7BCC7C448E5588668A7780B
|
||||||
|
:100DE0004008611802282338CCC9EDD98EE9AFF943
|
||||||
|
:100DF000488969990AA92BB9F55AD44AB77A966AEB
|
||||||
|
:100E0000711A500A333A122AFDDBDCCBBFFB9EEB92
|
||||||
|
:100E1000799B588B3BBB1AABA66C877CE44CC55CBA
|
||||||
|
:100E2000222C033C600C411CAEED8FFDECCDCDDDE2
|
||||||
|
:100E30002AAD0BBD688D499D977EB66ED55EF44E8A
|
||||||
|
:100E4000133E322E511E700E9FFFBEEFDDDFFCCF32
|
||||||
|
:100E50001BBF3AAF599F788F8891A981CAB1EBA186
|
||||||
|
:100E60000CD12DC14EF16FE18010A100C230E32002
|
||||||
|
:100E70000450254046706760B9839893FBA3DAB3AA
|
||||||
|
:100E80003DC31CD37FE35EF3B1029012F322D23252
|
||||||
|
:100E90003542145277625672EAB5CBA5A89589857A
|
||||||
|
:100EA0006EF54FE52CD50DC5E234C324A0148104A2
|
||||||
|
:100EB0006674476424540544DBA7FAB79987B8974A
|
||||||
|
:100EC0005FE77EF71DC73CD7D326F2369106B016F2
|
||||||
|
:100ED00057667676154634564CD96DC90EF92FE90A
|
||||||
|
:100EE000C899E9898AB9ABA9445865480678276842
|
||||||
|
:100EF000C018E1088238A3287DCB5CDB3FEB1EFBEA
|
||||||
|
:100F0000F98BD89BBBAB9ABB754A545A376A167A91
|
||||||
|
:100F1000F10AD01AB32A923A2EFD0FED6CDD4DCDB9
|
||||||
|
:100F2000AABD8BADE89DC98D267C076C645C454CE1
|
||||||
|
:100F3000A23C832CE01CC10C1FEF3EFF5DCF7CDF89
|
||||||
|
:100F40009BAFBABFD98FF89F176E367E554E745E31
|
||||||
|
:0C0F5000932EB23ED10EF01E00000000F7
|
||||||
|
:100F5C0001000000690000004100000000000000DA
|
||||||
|
:040000030000024DAA
|
||||||
|
:00000001FF
|
||||||
Binary file not shown.
|
|
@ -1,13 +1,13 @@
|
||||||
:10000000FC7F0020BD050000A9050000AD05000033
|
:10000000FC7F00204D020000390200003D0200008C
|
||||||
:1000100000000000000000000000000000000000E0
|
:1000100000000000000000000000000000000000E0
|
||||||
:10002000000000000000000000000000B10500001A
|
:10002000000000000000000000000000410200008D
|
||||||
:100030000000000000000000B5050000B905000048
|
:10003000000000000000000045020000490200002E
|
||||||
:1000400010B5064C2378002B07D1054B002B02D0AE
|
:1000400010B5064C2378002B07D1054B002B02D0AE
|
||||||
:10005000044800E000BF0123237010BD5C000020B5
|
:10005000044800E000BF0123237010BD1000002001
|
||||||
:10006000000000003C17000008B5084B002B03D02F
|
:1000600000000000580F000008B5084B002B03D01B
|
||||||
:100070000748084900E000BF07480368002B03D089
|
:100070000748084900E000BF07480368002B03D089
|
||||||
:10008000064B002B00D0984708BDC046000000007A
|
:10008000064B002B00D0984708BDC046000000007A
|
||||||
:100090003C17000060000020580000200000000015
|
:10009000580F0000140000200C0000200000000099
|
||||||
:1000A00010B5C3699C07FCD403680224A343036012
|
:1000A00010B5C3699C07FCD403680224A343036012
|
||||||
:1000B000C46901231C42FBD1046823430360036825
|
:1000B000C46901231C42FBD1046823430360036825
|
||||||
:1000C000DC07FCD4C46901231C42FBD1C469DC40B9
|
:1000C000DC07FCD4C46901231C42FBD1C469DC40B9
|
||||||
|
|
@ -17,364 +17,233 @@
|
||||||
:10010000FCD5018570470000027E01235107FBD515
|
:10010000FCD5018570470000027E01235107FBD515
|
||||||
:10011000428B1A4207D1428BDA401A4203D1428BFA
|
:10011000428B1A4207D1428BDA401A4203D1428BFA
|
||||||
:1001200092081A4202D0034B01221A70008DC0B20D
|
:1001200092081A4202D0034B01221A70008DC0B20D
|
||||||
:100130007047C0467800002070B50368041C988B97
|
:100130007047C0462C00002030B5364A1E23516857
|
||||||
:100140001A1C0821FF32084228D0988B174D014312
|
:100140000820994302231943516033498A690243C5
|
||||||
:10015000802099839872112353704021144B917120
|
:100150008A613248324A9082908A03439382D368FC
|
||||||
:1001600050715E68C0202E40800506435E605E6967
|
:100160009807FCD52F4B012018701878C40704D5C8
|
||||||
:100170003540284358610F4818600F4818615D6882
|
:100170002C48407840B20028F7DB0120986058787E
|
||||||
:100180000E4828408025AD02284358605868800BEF
|
:1001800040B20028FBDB284C26484460587840B237
|
||||||
:100190008003586000235171237105E0137ADA0659
|
:100190000028FBDB82242348E4014480587840B2E5
|
||||||
:1001A00002D5201C00F0D8FA207970BDFFFFFF8F28
|
:1001A0000028FBDB908C8024A0439084D068C50697
|
||||||
:1001B000940100209400002014010020FF3F00F073
|
:1001B000FCD51E4C1A48C462D4681948E506FBD524
|
||||||
:1001C000002303714371044B016083600B780222AA
|
:1001C000848C1B4D2C438484D4681548E506FBD5EC
|
||||||
:1001D00013430B707047C0463901000038B5364BE9
|
:1001D000848C02252C438484D0680406FCD5104806
|
||||||
:1001E0002021DA6901200A43DA61344B06241A78A7
|
:1001E000C0684506F8D5D068C406FCD500229A60E0
|
||||||
:1001F00002431A70324B0F22197891431970197803
|
:1001F0005A7852B2002AFBDB0E480A4A50605A78FD
|
||||||
:10020000214319702F490C782043087019780A404F
|
:1002000052B2002AFBDB00230B724B728B72CB7253
|
||||||
:100210001A701A7860210A431A702B4B2B4A5A80A5
|
:1002100030BDC04600400041000400400C06000014
|
||||||
:100220005A7852B2002AFBDB294B01211A780A4383
|
:1002200000080040000C004001050100B805FF7DFA
|
||||||
:100230001A709A78D107FCD426480268510B1F2205
|
:10023000040A0000000703000EBEFEE70DBEFEE745
|
||||||
:100240001140914200D1052111408C011D8D2249A0
|
:1002400005BEFEE702BEFEE701BEFEE70E4A0F480E
|
||||||
:100250002940214319850468A10C0A401F2A00D1B6
|
:1002500038B5824204D10E4A0E4B93420ED10AE0C9
|
||||||
:100260001D221C8D1F210A408C4322431A850268DF
|
:100260000D4C9442F7D00023D1188842F3D9E558B9
|
||||||
:100270000721D20D0A408A4200D103220A40188D7C
|
:1002700004330D60F8E700F04DF804E09342FAD241
|
||||||
:100280001103164A02400A431A8519787F220A4050
|
:10028000002102C3FAE7FEE7000000201000002072
|
||||||
:100290001A701A78042112480A431A7058621A898F
|
:10029000BC010020100000205C0F0000194A10B5BE
|
||||||
:1002A0000C218A431A811A8901218A431A8100216B
|
:1002A0001188FA24013189B2174BA400A14201D070
|
||||||
:1002B000802201F0D8F838BD0004004058440041C5
|
:1002B00011801CE000211180144900240C57604378
|
||||||
:1002C0003C44004159440041000C004006400000FD
|
:1002C0001C88001980B204B2FF2C01DC188002E007
|
||||||
:1002D00000500041246080003FF8FFFFFF8FFFFFC8
|
:1002D000FF20188008700024185F002803DA00202F
|
||||||
:1002E00094010020F7B5141C204A5F0101971D1CE2
|
:1002E00018800120087080200949800288611288E6
|
||||||
:1002F000D319061C5869271C4000400F03301033E7
|
:1002F00000215B5E9A4203D18022054B92025A6133
|
||||||
:10030000C74006D00F1C8022596812060A435A6063
|
:1003000010BDC0462E00002030000020000000205C
|
||||||
:1003100009E02F1C7B1E9F41154BBF01FF18381CA5
|
:100310000044004110B5234B802292029A605A613A
|
||||||
:10032000221C01F097F8019910480835421817610E
|
:10032000214A1C1C117801221140204B0022002977
|
||||||
:10033000131C5269A104920B890C92030A435A615F
|
:100330000AD118681E4A904201D1196018E01A606B
|
||||||
:1003400059690C4A0A405A616B01F318DA790221A3
|
:100340001C4A013A002AFCD11A601B4B1A68191C7E
|
||||||
:100350000A43DA715979802252420A435A716B0179
|
:10035000501C0DD0D8B200280AD180208002A061A4
|
||||||
:10036000F318DB799A07FAD5201CFEBD9401002012
|
:1003600082F30888FF229343144A93604B6818472E
|
||||||
:1003700014010020FF3F00F0F8B51B4E051C337838
|
:10037000FFF7E2FE62B600F0CBFA80239B02A36196
|
||||||
:10038000141C002B12D1194B194A1A645A6C920B87
|
:100380000320FFF78BFF0E4B1B78002BF8D100F0FA
|
||||||
:1003900092035A64586C174A02405A64A2235B00C5
|
:1003900033FB0028F4D0012000F014F800F068F8D6
|
||||||
:1003A000EA5C40200243EA54012333704827FF37B8
|
:1003A000FCE7C0460044004138040040FC7F0020C8
|
||||||
:1003B000EA5D0123134014D00C4B5A6C9204920C4A
|
:1003B0003581730748E801000020000000ED00E0EF
|
||||||
:1003C000A24202D25C6CA404A40C081C221C0849A2
|
:1003C00032000020012804D1024B034A1A60034B7B
|
||||||
:1003D00001F040F8EB5D01221343EB55002333702D
|
:1003D00018707047A0000020000D000039000020B8
|
||||||
:1003E00000E01C1C201CF8BD7900002094010020B6
|
:1003E00030B51A4B85B01B78002B29D0042901D1D8
|
||||||
:1003F000D4000020FF3F00F0FF302023002900D16F
|
:1003F000026804E0022901D1028800E00278490085
|
||||||
:100400001023837170470000094BFF305A69920B2B
|
:1004000004A843180B3B5C1AA3420BD00F201040EA
|
||||||
:1004100092035A61037A0222134303728279802382
|
:10041000092802D83025284300E037301870120927
|
||||||
:100420005B4213438371037A9A07FCD57047C04639
|
:10042000013BF1E701A830230370782343700A22CF
|
||||||
:100430009401002080235B421943C9B28172704746
|
:1004300043189A700D22DA70054B04311B6801E0F5
|
||||||
:1004400070B5A02303225B00C254134B134A5C6CAB
|
:10044000034B1B68DB68984705B030BD38000020BF
|
||||||
:10045000C021144089050C4346255C64FF354024C7
|
:10045000A000002072B6EFF30883044A136003681B
|
||||||
:1004600044550F4D30261D6490256D0046555D6B3B
|
:1004600083F30888436818477047C046A4000020FB
|
||||||
:1004700015402943922559636D0080214155094D4E
|
:10047000F0B58FB006A9CE4A0B1C31CA31C351CAA0
|
||||||
:100480001D63B0256D0044555C6F22405A67B2234E
|
:1004800051C360CA60C3CB4CCB48A3687A255B03D9
|
||||||
:100490005B00C15470BDC04694010020FFFFFF8F78
|
:100490005B0F9B005B58C9490360A26892B253434B
|
||||||
:1004A000D40000205401002030B5364A1E23516884
|
:1004A0000A60C749C74A0B6000231360C64B1D7022
|
||||||
:1004B0000820994302231943516033498A69024352
|
:1004B0000320FFF7F3FEC54BC54D1B68281C1B69C5
|
||||||
:1004C0008A613248324A9082908A03439382D36889
|
:1004C00040219847C34B00221860C34B1D60C34BAB
|
||||||
:1004D0009807FCD52F4B012018701878C40704D555
|
:1004D000C24DC04F1A60286839688842E8D2BE4BC6
|
||||||
:1004E0002C48407840B20028F7DB0120986058780B
|
:1004E0001B681A78FF2A00D1F6E1232A00D0CDE15B
|
||||||
:1004F00040B20028FBDB284C26484460587840B2C4
|
:1004F000BB4E3378002B05D0B44BBA481B680221A1
|
||||||
:100500000028FBDB82242348E4014480587840B271
|
:10050000DB689847B04B1B78532B38D13B682A687F
|
||||||
:100510000028FBDB908C8024A0439084D068C50623
|
:1005100093421ED9B04801322A609A1AB24B016840
|
||||||
:10052000FCD51E4C1A48C462D4681948E506FBD5B0
|
:100520001B6801310160B14E9A4201D2326000E095
|
||||||
:10053000848C1B4D2C438484D4681548E506FBD578
|
:100530003360A44832680068029000F0BBFB336867
|
||||||
:10054000848C02252C438484D0680406FCD5104892
|
:1005400029685A182A60A44A1668F1181160A84A46
|
||||||
:10055000C0684506F8D5D068C406FCD500229A606C
|
:1005500013702B68013B2B609F4B1A68013A1A609D
|
||||||
:100560005A7852B2002AFBDB0E480A4A50605A7889
|
:10056000A34BA14A1B7811688B4206D2974A954843
|
||||||
:1005700052B2002AFBDB00230B724B728B72CB72E0
|
:1005700012680068C91A92699047C04675E1522B0B
|
||||||
:1005800030BDC04600400041000400400C060000A1
|
:1005800007D1904A914B10681B68974A5B691168C4
|
||||||
:1005900000080040000C004001050100B805FF7D87
|
:100590006AE14F2B05D18B4B934A1B6812681A7086
|
||||||
:1005A000040A0000000703000EBEFEE70DBEFEE7D2
|
:1005A00063E1482B05D1874B8F4A1B6812681A807C
|
||||||
:1005B00005BEFEE702BEFEE701BEFEE70E4A0F489B
|
:1005B0005BE1572B05D1834B8B4A1B6812681A608D
|
||||||
:1005C00038B5824204D10E4A0E4B93420ED10AE056
|
:1005C00053E16F2B03D17F4B0121186807E0682BA3
|
||||||
:1005D0000D4C9442F7D00023D1188842F3D9E55846
|
:1005D00008D17C4B84481B6802211B880360FFF70D
|
||||||
:1005E00004330D60F8E700F04DF804E09342FAD2CE
|
:1005E000FFFE42E1772B06D1764B7F481B68042142
|
||||||
:1005F000002102C3FAE7FEE7000000205C000020B3
|
:1005F0001B680360F3E7472B13D17B4B1868FFF7A9
|
||||||
:10060000A00300205C00002040170000194A10B52C
|
:1006000029FF7C4B1B6883F3088862B67A4B1B7802
|
||||||
:100610001188FA24013189B2174BA400A14201D0FC
|
:10061000002B00D129E16D4B06201B681B68984711
|
||||||
:1006200011801CE000211180144900240C57604304
|
:1006200023E1542B04D101233370684B1B685CE039
|
||||||
:100630001C88001980B204B2FF2C01DC188002E093
|
:100630004E2B0BD13378002B05D1644B69481B68D6
|
||||||
:10064000FF20188008700024185F002803DA0020BB
|
:100640000221DB689847002333700EE1562B50D10E
|
||||||
:100650001880012008708020094980028861128872
|
:100650005E4D01212B686948DB6898472B680321B0
|
||||||
:1006600000215B5E9A4203D18022054B92025A61BF
|
:10066000DB6867489847674E2B68301CDB680121C0
|
||||||
:1006700010BDC0467A0000207C0000200000002051
|
:1006700098472B680D21DB68634898472B68301C2E
|
||||||
:100680000044004138B580222B4B92029A605A6197
|
:10068000DB6801219847544F604B544E3B60002378
|
||||||
:100690002A4A1C1C117801221140294B00220029F2
|
:1006900033603A1C311C1368581C10601B7803939C
|
||||||
:1006A0000AD11868274A904201D1196018E01A60EF
|
:1006A000002B03D00B6801330B60F4E72B68316833
|
||||||
:1006B000254A013A002AFCD11A60244B1A68191CF9
|
:1006B000DB68564898472B685248DB680121984709
|
||||||
:1006C000501C0DD0D8B200280AD180208002A06131
|
:1006C0000398306052483860434A1368591C1160DF
|
||||||
:1006D00082F30888FF2293431D4A93604B681847B2
|
:1006D0001A78424B002A03D01A6801321A60F3E7F5
|
||||||
:1006E000FFF7E2FE62B600F0E3FC00F0B7F980230A
|
:1006E0002A681968D36898472B68DB683D4802215F
|
||||||
:1006F0009B02051CA3610320FFF788FFAB68281C41
|
:1006F000BAE03D4A582B15D12F4E314D366813685C
|
||||||
:100700009847144B002801D001221A701A78002A49
|
:100700002A68B100934208D25808E061414820802D
|
||||||
:1007100005D0002000F01EFA00F07AFAFCE71B7802
|
:10071000207DC507FCD55B18F4E72C4B3E481B68D1
|
||||||
:10072000002BE8D100F038FD0028E4D0012000F0D3
|
:10072000DB68A0E0592B33D11268264B3B49002AE5
|
||||||
:1007300011FA00F06DFAFCE7004400413804004073
|
:1007300002D11B680B6026E0086819686368802591
|
||||||
:10074000FC7F00203581730748E80100002000008D
|
:10074000AB4392086360002A1DD0354B2380237D84
|
||||||
:1007500000ED00E07E000020F8B50468051C201CB8
|
:10075000DE07FCD50023184D2D680095AD08AB428F
|
||||||
:10076000FF30037AAD4A10210B430372AC4F13786C
|
:1007600002D3304D258006E09342FAD09D004659D1
|
||||||
:10077000AC493B705378AC4E0B7093783380D17892
|
:1007700001334E51EFE7257DEE07FCD59D00491969
|
||||||
:10078000338809020B4333801179A84B19805179C2
|
:100780004019D21ADFE7114B27481B68DB686AE083
|
||||||
:100790001F8809020F431F809779A5490F80D279DE
|
:100790005A2B6AD10B4B17681D680026EF19BD4212
|
||||||
:1007A0000F8812023A430A80402242719D489C4FB2
|
:1007A00044D02878311C00F049F90135061CF6E7E1
|
||||||
:1007B000027838789F4F12020243181CBA4200D1C7
|
:1007B000E00C0000004000415800002050000020E4
|
||||||
:1007C00099E01EDC802149008A4200D121E107DC4A
|
:1007C0004C0000209C00002048000020A0000020D9
|
||||||
:1007D000812A6AD0822A6ED0802A00D019E164E092
|
:1007D0005C00002040000020440000205400002065
|
||||||
:1007E00081235B009A4200D1A8E000DA0DE1C0232A
|
:1007E00038000020400D0000A8000020AC000020D0
|
||||||
:1007F0009B009A4200D10CE18F4B9A4200D104E158
|
:1007F0003C000020A4000020390000201C0D000057
|
||||||
:1008000007E190231B019A4242D015DCD023DB0084
|
:10080000450D00001E0D0000490D0000200D0000E8
|
||||||
:100810009A4222D088231B019A4242D0A023DB00B7
|
:100810002C0D000002A5FFFF350D00003400002064
|
||||||
:100820009A4200D0F5E0201CFFF7EEFD31882868E1
|
:1008200044A5FFFF04A5FFFF390D00002E4D2F4802
|
||||||
:1008300089B2FFF7FFFDF0E0804B9A4200D1E4E07F
|
:100830002B680121DB68984707230F223240111CE7
|
||||||
:1008400000DCE6E07E4B9A4200D1D2E07D4B9A423A
|
:1008400036093031092A00DD07311020C0186A4608
|
||||||
:1008500000D0DEE033886B71D7E033881B0A012BB0
|
:100850008154013BF1D22B6804A8DB68082198473A
|
||||||
:1008600008D10B8812222868934201D80A8892B2D4
|
:100860002B682348DB6803219847224D7A232B709D
|
||||||
:100870007549C6E033881B0A022B00D0C9E00B88FB
|
:10087000214B00221A60214B1B7893422CD01A4B3B
|
||||||
:1008800043222868934201D80A8892B26F49B8E09F
|
:1008800001211B681E48DB68984725E0111C3039A0
|
||||||
:100890003388201C2B71FFF7B7FD201CFFF7D0FD1C
|
:10089000C8B2194B092804D81E68320111431960E7
|
||||||
:1008A000BBE0291C01C90122ABE0694900230B8090
|
:1008A0001AE0111C4139052903D81868373A0101AB
|
||||||
:1008B00028680222A6E0664900220A801888502291
|
:1008B00006E0111C6139052904D81D68573A290141
|
||||||
:1008C0001040644A10701E880F203040188018882D
|
:1008C0000A4308E02C2A03D10E4A1E68166001E094
|
||||||
:1008D000032800D99DE012781B8808335B01E418D7
|
:1008D00008490A7000221A600B4B1A6801321A602C
|
||||||
:1008E000A379002A01D09B0600E0DB06DB0F0B801A
|
:1008E0000A4B1A680132F3E5A00000203D0D00001C
|
||||||
:1008F0002868022285E019887F229143554AC9B2AF
|
:1008F0003F0D000048000020A80000203800002024
|
||||||
:10090000117018880F21014019803188002900D00A
|
:10090000430D00009C000020540000204400002003
|
||||||
:100910007FE01988002900D17BE01988032900D9DC
|
:1009100010B51C4B01201A78022402431A701A4B9E
|
||||||
:1009200077E012781B8808335B01E318002A02D0B5
|
:100920000F221978914319701978214319701749CA
|
||||||
:1009300020225A7169E01020587166E002887F23F6
|
:100930000C782043087019780A401A701A78202120
|
||||||
:100940009A43444BD2B21A7001880F220A400280A7
|
:100940000A431A70124B04211A6A0A431A62114BA5
|
||||||
:100950003288002A5DD10288002A5AD00288032AF0
|
:10095000114A5A805A7852B2002AFBDBC4220F484F
|
||||||
:1009600057D81B78002B21D0038808335B01E3188C
|
:100960000F499203FFF79CFB0E4A002313700E4AB7
|
||||||
:100970009B79990649D50388202208335B01E31847
|
:1009700013700E4A13700E4A13700E4A13700E4A0B
|
||||||
:100980001A71038808335B01E318DB795A063CD5FA
|
:10098000137010BD4A440041354400414B440041BE
|
||||||
:100990000388402108335B01E318DA790A43DA71EE
|
:1009900000040040000C0040144000000008004229
|
||||||
:1009A0000388022208335B01E31820E00388083340
|
:1009A0002AF60000B000002037010020B10000202E
|
||||||
:1009B0005B01E3189B79DF0627D5038810220833F3
|
:1009B000B4000020380100203501002008B5C1B284
|
||||||
:1009C0005B01E3181A71038808335B01E318DB79D4
|
:1009C0000248FFF79BFB012008BDC046000800421B
|
||||||
:1009D00099061AD50388202108335B01E318DA79D8
|
:1009D000024B187E4007C00F7047C0460008004217
|
||||||
:1009E0000A43DA710388012208335B01E3181A71A4
|
:1009E00008B5FFF7F5FF0028FBD00248FFF78CFBA6
|
||||||
:1009F0000BE00B8808222868934201D80A8892B23B
|
:1009F00008BDC0460008004208B5FFF7E9FF002324
|
||||||
:100A000015490023FFF76EFC07E0201CFFF7FCFCF4
|
:100A0000984205D0FFF7ECFF031C233B5A425341A9
|
||||||
:100A100003E0201C0121FFF7EFFCF8BD940000204B
|
:100A1000181C08BD70B5041C0D1C4618B44204D047
|
||||||
:100A2000890000207F000020800000208600002038
|
:100A20002078FFF7CBFF0134F8E7281C70BD10B524
|
||||||
:100A300084000020020300000103000021200000C8
|
:100A3000041CFFF7D5FF2070012010BD0B0A5840A1
|
||||||
:100A4000A1210000212200009014000004000020D9
|
:100A4000034B4000C05A0902484080B27047C0467C
|
||||||
:100A500082000020880000204800002010B5054BCF
|
:100A5000580D0000F7B50024051C0F1C261CBC42D5
|
||||||
:100A6000054C2360FFF7BAFB201C2168FFF7A8FBA9
|
:100A600020D0FFF7BDFF114BC0B21B780190002BC7
|
||||||
:100A7000201C10BD005000411402002007B5054B9A
|
:100A70001AD1311CFFF7E2FF0D4B061C1A88002A21
|
||||||
:100A80000122019001A91868131CFFF72BFC01201B
|
:100A800004D10C4A11782A1C002907D001996A1C4C
|
||||||
:100A90000EBDC0461402002013B5054B6C4607344A
|
:100A90002970802F02D11988013919800134A4B23C
|
||||||
:100AA0001868211C0122FFF767FC207816BDC0469C
|
:100AA000151CDCE7301C00E00120FEBD35010020F4
|
||||||
:100AB0001402002010B5074C201CFFF73DFB031C5F
|
:100AB000B200002036010020F0B53E4E85B0002285
|
||||||
:100AC0000020834205D022684823FF33D05C0123F5
|
:100AC00003900C1C32703C4B914201D1012201E099
|
||||||
:100AD000184010BD1402002010B5054A0C1C031C60
|
:100AD0003A490C801A707F231C4201D080349C4319
|
||||||
:100AE000191C10680123221CFFF7FCFB201C10BD01
|
:100AE000FFF77EFF3378C0B2002B07D000253570AA
|
||||||
:100AF0001402002070B5084C061C201C0D1CFFF7CA
|
:100AF000FFF776FF3378C0B2AB4236D1432803D03C
|
||||||
:100B00001BFB0023984205D02068311C2A1CFFF7EC
|
:100B0000712853D01528EBD1012300930120FFF762
|
||||||
:100B100033FC031C181C70BD14020020F8B50C4CEB
|
:100B100055FF0098FFF752FF00998025C843C0B2E7
|
||||||
:100B2000051C201C0E1CFFF707FB0023271C341C90
|
:100B2000FFF74CFF039B00270293244A1388002BF6
|
||||||
:100B300098420AD0002C07D0291C221C3868FFF7E5
|
:100B30001DD1214901930978002918D10198FFF7A7
|
||||||
:100B40001BFC241A2D18F5E7331C181CF8BDC046F1
|
:100B40003DFF391C0198FFF779FF013D071C002D7F
|
||||||
:100B500014020020012805D1054B064A1A60064BF5
|
:100B5000EBD1000AC0B2FFF731FFF8B2FFF72EFF6A
|
||||||
:100B6000187004E0002802D1044A014B1A60704753
|
:100B6000FFF73EFF3378002B0AD035701FE0029963
|
||||||
:100B700084020020C4140000910000201015000021
|
:100B7000013B09781380029B019101330293DDE769
|
||||||
:100B800030B51A4B85B01B78002B29D0042901D130
|
:100B8000C0B2062807D1009B03990133DBB2803144
|
||||||
:100B9000026804E0022901D1028800E002784900DD
|
:100B90000093803C0391002CB8D10420FFF70EFF96
|
||||||
:100BA00004A843180B3B5C1AA3420BD00F20104043
|
:100BA000FFF71EFF044B01251C7000E00025281CE8
|
||||||
:100BB000092802D83025284300E037301870120980
|
:100BB00005B0F0BD3501002036010020B200002054
|
||||||
:100BC000013BF1E701A830230370782343700A2228
|
:100BC000F0B5384C87B0002301902370994201D1D1
|
||||||
:100BD00043189A700D22DA70054B04311B6801E04E
|
:100BD000012301E0344A1180344A64261370432013
|
||||||
:100BE000034B1B68DB68984705B030BD90000020C0
|
:100BE000FFF7ECFE324FFFF7F3FE002803D1002F92
|
||||||
:100BF0008402002072B6EFF30883044A136003688E
|
:100BF00003D0013FF7E7002F03D1013E002EEED1D5
|
||||||
:100C000083F30888436818477047C046880200206D
|
:100C00004DE00125FFF7ECFE2378002B38D1C0B270
|
||||||
:100C1000F0B58FB006A9CE4A0B1C31CA31C351CAF8
|
:100C10000290012805D004283DD10620FFF7CEFE22
|
||||||
:100C200051C360CA60C3CB4CCB48A3687A255B0331
|
:100C200039E005AE0221301CFFF714FF0198802146
|
||||||
:100C30005B0F9B005B58C9490360A26892B25343A3
|
:100C3000FFF710FF23780390002B18D1FFF7D0FEA9
|
||||||
:100C40000A60C749C74A0B6000231360C64B1D707A
|
:100C40000702FFF7CDFEBFB223783F18BFB2012BDA
|
||||||
:100C50000320FFF7DBFCC54BC54D1B68281C1B6937
|
:100C50000DD0039B9F4207D13378AB4204D1EB43C5
|
||||||
:100C600040219847C34B00221860C34B1D60C34B03
|
:100C60007278DBB29A4204D01820FFF7A7FE002367
|
||||||
:100C7000C24DC04F1A60286839688842E8D2BE4B1E
|
:100C700003E00620FFF7A2FE029B2278002A02D0A2
|
||||||
:100C80001B681A78FF2A00D1F6E1232A00D0CDE1B3
|
:100C8000002626700BE0012B05D1019A6B1C8032E7
|
||||||
:100C9000BB4E3378002B05D0B44BBA481B680221F9
|
:100C9000DDB20192B6E7054A002313700126301C2D
|
||||||
:100CA000DB689847B04B1B78532B38D13B682A68D8
|
:100CA00007B0F0BD35010020B20000203601002061
|
||||||
:100CB00093421ED9B04801322A609A1AB24B016899
|
:100CB00000350C0010B50023934203D0CC5CC45423
|
||||||
:100CC0001B6801310160B14E9A4201D2326000E0EE
|
:100CC0000133F9E710BD0000F8B5C046F8BC08BC18
|
||||||
:100CD0003360A44832680068029000F0BBFB3368C0
|
:100CD0009E467047F8B5C046F8BC08BC9E467047B3
|
||||||
:100CE00029685A182A60A44A1668F1181160A84A9F
|
:100CE000080000001000000020000000400000008C
|
||||||
:100CF00013702B68013B2B609F4B1A68013A1A60F6
|
:100CF000800000000001000000020000000400006D
|
||||||
:100D0000A34BA14A1B7811688B4206D2974A95489B
|
:100D0000BD090000E1090000D1090000150A00003A
|
||||||
:100D100012680068C91A92699047C04675E1522B63
|
:100D10002F0A0000B90A0000C10B00007600200075
|
||||||
:100D200007D1904A914B10681B68974A5B6911681C
|
:100D20004D617920323620323031360032303A355A
|
||||||
:100D30006AE14F2B05D18B4B934A1B6812681A70DE
|
:100D3000393A323000580A0D00590A0D005A002382
|
||||||
:100D400063E1482B05D1874B8F4A1B6812681A80D4
|
:100D40000A0D003E00322E30005B41726475696E00
|
||||||
:100D50005BE1572B05D1834B8B4A1B6812681A60E5
|
:100D50006F3A58595A5D000000002110422063305C
|
||||||
:100D600053E16F2B03D17F4B0121186807E0682BFB
|
:100D60008440A550C660E770088129914AA16BB103
|
||||||
:100D700008D17C4B84481B6802211B880360FFF765
|
:100D70008CC1ADD1CEE1EFF13112100273325222AB
|
||||||
:100D8000FFFE42E1772B06D1764B7F481B6804219A
|
:100D8000B5529442F772D662399318837BB35AA353
|
||||||
:100D90001B680360F3E7472B13D17B4B1868FFF701
|
:100D9000BDD39CC3FFF3DEE362244334200401147B
|
||||||
:100DA00029FF7C4B1B6883F3088862B67A4B1B785B
|
:100DA000E664C774A44485546AA54BB528850995A3
|
||||||
:100DB000002B00D129E16D4B06201B681B6898476A
|
:100DB000EEE5CFF5ACC58DD553367226111630064B
|
||||||
:100DC00023E1542B04D101233370684B1B685CE092
|
:100DC000D776F6669556B4465BB77AA719973887F3
|
||||||
:100DD0004E2B0BD13378002B05D1644B69481B682F
|
:100DD000DFF7FEE79DD7BCC7C448E5588668A7780B
|
||||||
:100DE0000221DB689847002333700EE1562B50D167
|
:100DE0004008611802282338CCC9EDD98EE9AFF943
|
||||||
:100DF0005E4D01212B686948DB6898472B68032109
|
:100DF000488969990AA92BB9F55AD44AB77A966AEB
|
||||||
:100E0000DB6867489847674E2B68301CDB68012118
|
:100E0000711A500A333A122AFDDBDCCBBFFB9EEB92
|
||||||
:100E100098472B680D21DB68634898472B68301C86
|
:100E1000799B588B3BBB1AABA66C877CE44CC55CBA
|
||||||
:100E2000DB6801219847544F604B544E3B600023D0
|
:100E2000222C033C600C411CAEED8FFDECCDCDDDE2
|
||||||
:100E300033603A1C311C1368581C10601B780393F4
|
:100E30002AAD0BBD688D499D977EB66ED55EF44E8A
|
||||||
:100E4000002B03D00B6801330B60F4E72B6831688B
|
:100E4000133E322E511E700E9FFFBEEFDDDFFCCF32
|
||||||
:100E5000DB68564898472B685248DB680121984761
|
:100E50001BBF3AAF599F788F8891A981CAB1EBA186
|
||||||
:100E60000398306052483860434A1368591C116037
|
:100E60000CD12DC14EF16FE18010A100C230E32002
|
||||||
:100E70001A78424B002A03D01A6801321A60F3E74D
|
:100E70000450254046706760B9839893FBA3DAB3AA
|
||||||
:100E80002A681968D36898472B68DB683D480221B7
|
:100E80003DC31CD37FE35EF3B1029012F322D23252
|
||||||
:100E9000BAE03D4A582B15D12F4E314D36681368B4
|
:100E90003542145277625672EAB5CBA5A89589857A
|
||||||
:100EA0002A68B100934208D25808E0614148208086
|
:100EA0006EF54FE52CD50DC5E234C324A0148104A2
|
||||||
:100EB000207DC507FCD55B18F4E72C4B3E481B682A
|
:100EB0006674476424540544DBA7FAB79987B8974A
|
||||||
:100EC000DB68A0E0592B33D11268264B3B49002A3E
|
:100EC0005FE77EF71DC73CD7D326F2369106B016F2
|
||||||
:100ED00002D11B680B6026E00868196863688025EA
|
:100ED00057667676154634564CD96DC90EF92FE90A
|
||||||
:100EE000AB4392086360002A1DD0354B2380237DDD
|
:100EE000C899E9898AB9ABA9445865480678276842
|
||||||
:100EF000DE07FCD50023184D2D680095AD08AB42E8
|
:100EF000C018E1088238A3287DCB5CDB3FEB1EFBEA
|
||||||
:100F000002D3304D258006E09342FAD09D00465929
|
:100F0000F98BD89BBBAB9ABB754A545A376A167A91
|
||||||
:100F100001334E51EFE7257DEE07FCD59D004919C1
|
:100F1000F10AD01AB32A923A2EFD0FED6CDD4DCDB9
|
||||||
:100F20004019D21ADFE7114B27481B68DB686AE0DB
|
:100F2000AABD8BADE89DC98D267C076C645C454CE1
|
||||||
:100F30005A2B6AD10B4B17681D680026EF19BD426A
|
:100F3000A23C832CE01CC10C1FEF3EFF5DCF7CDF89
|
||||||
:100F400044D02878311C00F049F90135061CF6E739
|
:100F40009BAFBABFD98FF89F176E367E554E745E31
|
||||||
:100F5000A4140000004000413C02002034020020A4
|
:0C0F5000932EB23ED10EF01E00000000F7
|
||||||
:100F600030020020800200202C0200208402002099
|
:100F5C0001000000690000004100000000000000DA
|
||||||
:100F70004002002024020020280200203802002025
|
:040000030000024DAA
|
||||||
:100F800090000020041500008C0200209002002038
|
|
||||||
:100F9000200200208802002091000020E0140000C0
|
|
||||||
:100FA00009150000E21400002C150000E4140000F4
|
|
||||||
:100FB000F014000002A5FFFFF91400008C000020CF
|
|
||||||
:100FC00044A5FFFF04A5FFFFFD1400002E4D2F4890
|
|
||||||
:100FD0002B680121DB68984707230F223240111C40
|
|
||||||
:100FE00036093031092A00DD07311020C0186A4661
|
|
||||||
:100FF0008154013BF1D22B6804A8DB680821984793
|
|
||||||
:101000002B682348DB6803219847224D7A232B70F5
|
|
||||||
:10101000214B00221A60214B1B7893422CD01A4B93
|
|
||||||
:1010200001211B681E48DB68984725E0111C3039F8
|
|
||||||
:10103000C8B2194B092804D81E683201114319603F
|
|
||||||
:101040001AE0111C4139052903D81868373A010103
|
|
||||||
:1010500006E0111C6139052904D81D68573A290199
|
|
||||||
:101060000A4308E02C2A03D10E4A1E68166001E0EC
|
|
||||||
:1010700008490A7000221A600B4B1A6801321A6084
|
|
||||||
:101080000A4B1A680132F3E58402002001150000C2
|
|
||||||
:10109000031500002C0200208C020020900000208C
|
|
||||||
:1010A00007150000800200203802002028020020DE
|
|
||||||
:1010B00010B51C4B01201A78022402431A701A4BF7
|
|
||||||
:1010C0000F22197891431970197821431970174923
|
|
||||||
:1010D0000C782043087019780A401A701A78202179
|
|
||||||
:1010E0000A431A70124B04211A6A0A431A62114BFE
|
|
||||||
:1010F000114A5A805A7852B2002AFBDBC4220F48A8
|
|
||||||
:101100000F499203FEF7CCFF0E4A002313700E4ADC
|
|
||||||
:1011100013700E4A13700E4A13700E4A13700E4A63
|
|
||||||
:10112000137010BD4A440041354400414B44004116
|
|
||||||
:1011300000040040000C0040144000000008004281
|
|
||||||
:101140002AF60000940200201B03002095020020D4
|
|
||||||
:10115000980200201C0300201903002008B5C1B22A
|
|
||||||
:101160000248FEF7CBFF012008BDC0460008004240
|
|
||||||
:10117000024B187E4007C00F7047C046000800426F
|
|
||||||
:1011800008B5FFF7F5FF0028FBD00248FEF7BCFFCB
|
|
||||||
:1011900008BDC0460008004208B5FFF7E9FF00237C
|
|
||||||
:1011A000984205D0FFF7ECFF031C233B5A42534102
|
|
||||||
:1011B000181C08BD70B5041C0D1C4618B44204D0A0
|
|
||||||
:1011C0002078FFF7CBFF0134F8E7281C70BD10B57D
|
|
||||||
:1011D000041CFFF7D5FF2070012010BD0B0A5840FA
|
|
||||||
:1011E000034B4000C05A0902484080B27047C046D5
|
|
||||||
:1011F0003A150000F7B50024051C0F1C261CBC4244
|
|
||||||
:1012000020D0FFF7BDFF114BC0B21B780190002B1F
|
|
||||||
:101210001AD1311CFFF7E2FF0D4B061C1A88002A79
|
|
||||||
:1012200004D10C4A11782A1C002907D001996A1CA4
|
|
||||||
:101230002970802F02D11988013919800134A4B294
|
|
||||||
:10124000151CDCE7301C00E00120FEBD1903002066
|
|
||||||
:10125000960200201A030020F0B53E4E85B0002211
|
|
||||||
:1012600003900C1C32703C4B914201D1012201E0F1
|
|
||||||
:101270003A490C801A707F231C4201D080349C4371
|
|
||||||
:10128000FFF77EFF3378C0B2002B07D00025357002
|
|
||||||
:10129000FFF776FF3378C0B2AB4236D1432803D094
|
|
||||||
:1012A000712853D01528EBD1012300930120FFF7BB
|
|
||||||
:1012B00055FF0098FFF752FF00998025C843C0B240
|
|
||||||
:1012C000FFF74CFF039B00270293244A1388002B4F
|
|
||||||
:1012D0001DD1214901930978002918D10198FFF700
|
|
||||||
:1012E0003DFF391C0198FFF779FF013D071C002DD8
|
|
||||||
:1012F000EBD1000AC0B2FFF731FFF8B2FFF72EFFC3
|
|
||||||
:10130000FFF73EFF3378002B0AD035701FE00299BB
|
|
||||||
:10131000013B09781380029B019101330293DDE7C1
|
|
||||||
:10132000C0B2062807D1009B03990133DBB280319C
|
|
||||||
:101330000093803C0391002CB8D10420FFF70EFFEE
|
|
||||||
:10134000FFF71EFF044B01251C7000E00025281C40
|
|
||||||
:1013500005B0F0BD190300201A03002096020020FA
|
|
||||||
:10136000F0B5384C87B0002301902370994201D129
|
|
||||||
:10137000012301E0344A1180344A6426137043206B
|
|
||||||
:10138000FFF7ECFE324FFFF7F3FE002803D1002FEA
|
|
||||||
:1013900003D0013FF7E7002F03D1013E002EEED12D
|
|
||||||
:1013A0004DE00125FFF7ECFE2378002B38D1C0B2C9
|
|
||||||
:1013B0000290012805D004283DD10620FFF7CEFE7B
|
|
||||||
:1013C00039E005AE0221301CFFF714FF019880219F
|
|
||||||
:1013D000FFF710FF23780390002B18D1FFF7D0FE02
|
|
||||||
:1013E0000702FFF7CDFEBFB223783F18BFB2012B33
|
|
||||||
:1013F0000DD0039B9F4207D13378AB4204D1EB431E
|
|
||||||
:101400007278DBB29A4204D01820FFF7A7FE0023BF
|
|
||||||
:1014100003E00620FFF7A2FE029B2278002A02D0FA
|
|
||||||
:10142000002626700BE0012B05D1019A6B1C80323F
|
|
||||||
:10143000DDB20192B6E7054A002313700126301C85
|
|
||||||
:1014400007B0F0BD19030020960200201A03002007
|
|
||||||
:1014500000350C0010B50023934203D0CC5CC4547B
|
|
||||||
:101460000133F9E710BD031C8218934202D01970B2
|
|
||||||
:101470000133FAE770470000F8B5C046F8BC08BC75
|
|
||||||
:101480009E467047F8B5C046F8BC08BC9E467047FB
|
|
||||||
:1014900012010002020000409A2314000002000022
|
|
||||||
:1014A0000001000008000000100000002000000003
|
|
||||||
:1014B0004000000080000000000100000002000069
|
|
||||||
:1014C000000400005D110000811100007111000096
|
|
||||||
:1014D000B5110000CF110000591200006113000087
|
|
||||||
:1014E00076002000417072203137203230313600D2
|
|
||||||
:1014F00032323A34393A313900580A0D00590A0D5E
|
|
||||||
:10150000005A00230A0D003E00322E300000000079
|
|
||||||
:101510007D0A0000990A0000B50A0000D90A0000FF
|
|
||||||
:10152000F50A0000D90A00001D0B00005B4172643F
|
|
||||||
:1015300075696E6F3A58595A5D00000021104220BB
|
|
||||||
:1015400063308440A550C660E770088129914AA1A4
|
|
||||||
:101550006BB18CC1ADD1CEE1EFF13112100273321B
|
|
||||||
:101560005222B5529442F772D662399318837BB3F4
|
|
||||||
:101570005AA3BDD39CC3FFF3DEE3622443342004AB
|
|
||||||
:101580000114E664C774A44485546AA54BB5288544
|
|
||||||
:101590000995EEE5CFF5ACC58DD5533672261116FB
|
|
||||||
:1015A0003006D776F6669556B4465BB77AA7199794
|
|
||||||
:1015B0003887DFF7FEE79DD7BCC7C448E558866883
|
|
||||||
:1015C000A7784008611802282338CCC9EDD98EE9E4
|
|
||||||
:1015D000AFF9488969990AA92BB9F55AD44AB77A5B
|
|
||||||
:1015E000966A711A500A333A122AFDDBDCCBBFFB34
|
|
||||||
:1015F0009EEB799B588B3BBB1AABA66C877CE44C6B
|
|
||||||
:10160000C55C222C033C600C411CAEED8FFDECCD83
|
|
||||||
:10161000CDDD2AAD0BBD688D499D977EB66ED55E3A
|
|
||||||
:10162000F44E133E322E511E700E9FFFBEEFDDDFD3
|
|
||||||
:10163000FCCF1BBF3AAF599F788F8891A981CAB15F
|
|
||||||
:10164000EBA10CD12DC14EF16FE18010A100C23091
|
|
||||||
:10165000E3200450254046706760B9839893FBA34C
|
|
||||||
:10166000DAB33DC31CD37FE35EF3B1029012F322E1
|
|
||||||
:10167000D2323542145277625672EAB5CBA5A8959C
|
|
||||||
:1016800089856EF54FE52CD50DC5E234C324A01431
|
|
||||||
:1016900081046674476424540544DBA7FAB799872C
|
|
||||||
:1016A000B8975FE77EF71DC73CD7D326F236910681
|
|
||||||
:1016B000B01657667676154634564CD96DC90EF974
|
|
||||||
:1016C0002FE9C899E9898AB9ABA9445865480678D1
|
|
||||||
:1016D0002768C018E1088238A3287DCB5CDB3FEB8C
|
|
||||||
:1016E0001EFBF98BD89BBBAB9ABB754A545A376A21
|
|
||||||
:1016F000167AF10AD01AB32A923A2EFD0FED6CDD5C
|
|
||||||
:101700004DCDAABD8BADE89DC98D267C076C645C70
|
|
||||||
:10171000454CA23C832CE01CC10C1FEF3EFF5DCF6B
|
|
||||||
:101720007CDF9BAFBABFD98FF89F176E367E554EC0
|
|
||||||
:10173000745E932EB23ED10EF01E00000000000039
|
|
||||||
:101740000100000009024300020100803209040088
|
|
||||||
:10175000000102020000052400100104240200051B
|
|
||||||
:10176000240600010524010001070583030800FF8A
|
|
||||||
:1017700009040100020A0000000705810240000080
|
|
||||||
:10178000070502024000000000C20100000008003E
|
|
||||||
:0C179000690000004100000000000000A3
|
|
||||||
:04000003000005BD37
|
|
||||||
:00000001FF
|
:00000001FF
|
||||||
|
|
|
||||||
BIN
bootloaders/samd10/.vs/UART_Bootloader/v14/.atsuo
Normal file
BIN
bootloaders/samd10/.vs/UART_Bootloader/v14/.atsuo
Normal file
Binary file not shown.
7
bootloaders/samd10/Python_Installer_Links.txt
Normal file
7
bootloaders/samd10/Python_Installer_Links.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
Python 2.7.10:
|
||||||
|
|
||||||
|
https://www.python.org/downloads/release/python-2710/
|
||||||
|
|
||||||
|
Pyserial:
|
||||||
|
|
||||||
|
https://pypi.python.org/pypi/pyserial
|
||||||
42
bootloaders/samd10/Readme.txt
Normal file
42
bootloaders/samd10/Readme.txt
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
A low footprint SERCOM UART based bootloader can be found in this attachment.
|
||||||
|
This bootloader is compiled with ARMGCC compiler using Atmel Studio 7 and
|
||||||
|
occupies only 1008 bytes.
|
||||||
|
|
||||||
|
Following are the steps to execute the bootloader.
|
||||||
|
|
||||||
|
1. Unzip the attachment to a folder and open the 'UART_Bootloader.atsln' project in
|
||||||
|
Atmel Studio 7.
|
||||||
|
|
||||||
|
2. The default settings are for SAM D11 Xplained Pro board.
|
||||||
|
|
||||||
|
SERCOM2 with 115200 baud is used and PA10 (PAD2) is used as TXD and PA11 (PAD3) is used as RXD.
|
||||||
|
Push button connected to pin PA14 is used for boot mode entry.
|
||||||
|
Change the SERCOM module and boot mode entry pins in the main.c file if needed for custom boards.
|
||||||
|
|
||||||
|
3. Build the project and flash the target SAM D11 device with the bootloader hex file.
|
||||||
|
|
||||||
|
4. Enter into bootloader mode by performing the following sequence in SAM D11 Xplained Pro board.
|
||||||
|
|
||||||
|
a. Press and hold the RESET button as well as the user push button SW0.
|
||||||
|
b. First release the RESET button and then release the SW0 push button.
|
||||||
|
|
||||||
|
5. A python script file (uart_bootloader.py) which acts as the bootloader frontend is
|
||||||
|
available in the attachment.
|
||||||
|
|
||||||
|
6. Open a command prompt and navigate to the script file path. Place your target
|
||||||
|
application .bin file in the same path.
|
||||||
|
|
||||||
|
7. Execute the following command line which will program the input binary file.
|
||||||
|
python.exe uart_bootloader.py -c COM1 -b 115200 -i input_file.bin
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
1. Python has to be installed to run the bootloader script file.
|
||||||
|
Python version 2.7.1 and pyserial 2.7 win32 has been used for testing.
|
||||||
|
Other versions may or may not work.
|
||||||
|
|
||||||
|
2. The project in the attachment has been tested on SAM D11 Xplained Pro boards and
|
||||||
|
can be easily ported to custom hardware.
|
||||||
|
|
||||||
|
3. The flash programming algorithm is common for all SAM D MCUs and hence the bootloader
|
||||||
|
can be easily ported and run in MCUs like SAM D20 / SAM D21 / SAM D10 and SAM D11 devices.
|
||||||
BIN
bootloaders/samd10/SAMD11_LED_Toggle.bin
Normal file
BIN
bootloaders/samd10/SAMD11_LED_Toggle.bin
Normal file
Binary file not shown.
22
bootloaders/samd10/UART_Bootloader.atsln
Normal file
22
bootloaders/samd10/UART_Bootloader.atsln
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Atmel Studio Solution File, Format Version 11.00
|
||||||
|
VisualStudioVersion = 14.0.23107.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "UART_Bootloader", "UART_Bootloader\UART_Bootloader.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|ARM = Debug|ARM
|
||||||
|
Release|ARM = Release|ARM
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|ARM.ActiveCfg = Debug|ARM
|
||||||
|
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|ARM.Build.0 = Debug|ARM
|
||||||
|
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|ARM.ActiveCfg = Release|ARM
|
||||||
|
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|ARM.Build.0 = Release|ARM
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Binary file not shown.
154
bootloaders/samd10/UART_Bootloader/Debug/Makefile
Normal file
154
bootloaders/samd10/UART_Bootloader/Debug/Makefile
Normal file
|
|
@ -0,0 +1,154 @@
|
||||||
|
################################################################################
|
||||||
|
# Automatically-generated file. Do not edit!
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
SHELL := cmd.exe
|
||||||
|
RM := rm -rf
|
||||||
|
|
||||||
|
USER_OBJS :=
|
||||||
|
|
||||||
|
LIBS :=
|
||||||
|
PROJ :=
|
||||||
|
|
||||||
|
O_SRCS :=
|
||||||
|
C_SRCS :=
|
||||||
|
S_SRCS :=
|
||||||
|
S_UPPER_SRCS :=
|
||||||
|
OBJ_SRCS :=
|
||||||
|
ASM_SRCS :=
|
||||||
|
PREPROCESSING_SRCS :=
|
||||||
|
OBJS :=
|
||||||
|
OBJS_AS_ARGS :=
|
||||||
|
C_DEPS :=
|
||||||
|
C_DEPS_AS_ARGS :=
|
||||||
|
EXECUTABLES :=
|
||||||
|
OUTPUT_FILE_PATH :=
|
||||||
|
OUTPUT_FILE_PATH_AS_ARGS :=
|
||||||
|
AVR_APP_PATH :=$$$AVR_APP_PATH$$$
|
||||||
|
QUOTE := "
|
||||||
|
ADDITIONAL_DEPENDENCIES:=
|
||||||
|
OUTPUT_FILE_DEP:=
|
||||||
|
LIB_DEP:=
|
||||||
|
LINKER_SCRIPT_DEP:=
|
||||||
|
|
||||||
|
# Every subdirectory with source files must be described here
|
||||||
|
SUBDIRS := \
|
||||||
|
../Device_Startup/
|
||||||
|
|
||||||
|
|
||||||
|
# Add inputs and outputs from these tool invocations to the build variables
|
||||||
|
C_SRCS += \
|
||||||
|
../Device_Startup/startup_samd10.c \
|
||||||
|
../Device_Startup/system_samd10.c \
|
||||||
|
../main.c
|
||||||
|
|
||||||
|
|
||||||
|
PREPROCESSING_SRCS +=
|
||||||
|
|
||||||
|
|
||||||
|
ASM_SRCS +=
|
||||||
|
|
||||||
|
|
||||||
|
OBJS += \
|
||||||
|
Device_Startup/startup_samd10.o \
|
||||||
|
Device_Startup/system_samd10.o \
|
||||||
|
main.o
|
||||||
|
|
||||||
|
OBJS_AS_ARGS += \
|
||||||
|
Device_Startup/startup_samd10.o \
|
||||||
|
Device_Startup/system_samd10.o \
|
||||||
|
main.o
|
||||||
|
|
||||||
|
C_DEPS += \
|
||||||
|
Device_Startup/startup_samd10.d \
|
||||||
|
Device_Startup/system_samd10.d \
|
||||||
|
main.d
|
||||||
|
|
||||||
|
C_DEPS_AS_ARGS += \
|
||||||
|
Device_Startup/startup_samd10.d \
|
||||||
|
Device_Startup/system_samd10.d \
|
||||||
|
main.d
|
||||||
|
|
||||||
|
OUTPUT_FILE_PATH +=UART_Bootloader.elf
|
||||||
|
|
||||||
|
OUTPUT_FILE_PATH_AS_ARGS +=UART_Bootloader.elf
|
||||||
|
|
||||||
|
ADDITIONAL_DEPENDENCIES:=
|
||||||
|
|
||||||
|
OUTPUT_FILE_DEP:= ./makedep.mk
|
||||||
|
|
||||||
|
LIB_DEP+=
|
||||||
|
|
||||||
|
LINKER_SCRIPT_DEP+= \
|
||||||
|
../Device_Startup/samd10d14am_flash.ld \
|
||||||
|
../Device_Startup/samd10d14am_sram.ld
|
||||||
|
|
||||||
|
|
||||||
|
# AVR32/GNU C Compiler
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Device_Startup/%.o: ../Device_Startup/%.c
|
||||||
|
@echo Building file: $<
|
||||||
|
@echo Invoking: ARM/GNU C Compiler : 4.9.3
|
||||||
|
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-gcc.exe$(QUOTE) -x c -mthumb -D__SAMD10D14AM__ -DDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAMD10_DFP\1.0.31\include" -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\arm\cmsis\4.2.0\CMSIS\Include" -Os -ffunction-sections -fdata-sections -mlong-calls -g3 -Wall -mcpu=cortex-m0plus -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
|
||||||
|
@echo Finished building: $<
|
||||||
|
|
||||||
|
|
||||||
|
./%.o: .././%.c
|
||||||
|
@echo Building file: $<
|
||||||
|
@echo Invoking: ARM/GNU C Compiler : 4.9.3
|
||||||
|
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-gcc.exe$(QUOTE) -x c -mthumb -D__SAMD10D14AM__ -DDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAMD10_DFP\1.0.31\include" -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\arm\cmsis\4.2.0\CMSIS\Include" -Os -ffunction-sections -fdata-sections -mlong-calls -g3 -Wall -mcpu=cortex-m0plus -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
|
||||||
|
@echo Finished building: $<
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# AVR32/GNU Preprocessing Assembler
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# AVR32/GNU Assembler
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ifneq ($(MAKECMDGOALS),clean)
|
||||||
|
ifneq ($(strip $(C_DEPS)),)
|
||||||
|
-include $(C_DEPS)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Add inputs and outputs from these tool invocations to the build variables
|
||||||
|
|
||||||
|
# All Target
|
||||||
|
all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES)
|
||||||
|
|
||||||
|
$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP) $(LINKER_SCRIPT_DEP)
|
||||||
|
@echo Building target: $@
|
||||||
|
@echo Invoking: ARM/GNU Linker : 4.9.3
|
||||||
|
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-gcc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -mthumb -Wl,-Map="UART_Bootloader.map" --specs=nano.specs -Wl,--start-group -lm -Wl,--end-group -L"..\\Device_Startup" -Wl,--gc-sections -mcpu=cortex-m0plus -Tsamd10d14am_flash.ld
|
||||||
|
@echo Finished building target: $@
|
||||||
|
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-objcopy.exe" -O binary "UART_Bootloader.elf" "UART_Bootloader.bin"
|
||||||
|
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature "UART_Bootloader.elf" "UART_Bootloader.hex"
|
||||||
|
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O binary "UART_Bootloader.elf" "UART_Bootloader.eep" || exit 0
|
||||||
|
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-objdump.exe" -h -S "UART_Bootloader.elf" > "UART_Bootloader.lss"
|
||||||
|
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature "UART_Bootloader.elf" "UART_Bootloader.srec"
|
||||||
|
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-size.exe" "UART_Bootloader.elf"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Other Targets
|
||||||
|
clean:
|
||||||
|
-$(RM) $(OBJS_AS_ARGS) $(EXECUTABLES)
|
||||||
|
-$(RM) $(C_DEPS_AS_ARGS)
|
||||||
|
rm -rf "UART_Bootloader.elf" "UART_Bootloader.a" "UART_Bootloader.hex" "UART_Bootloader.bin" "UART_Bootloader.lss" "UART_Bootloader.eep" "UART_Bootloader.map" "UART_Bootloader.srec"
|
||||||
|
|
||||||
BIN
bootloaders/samd10/UART_Bootloader/Debug/UART_Bootloader.bin
Normal file
BIN
bootloaders/samd10/UART_Bootloader/Debug/UART_Bootloader.bin
Normal file
Binary file not shown.
75
bootloaders/samd10/UART_Bootloader/Debug/UART_Bootloader.hex
Normal file
75
bootloaders/samd10/UART_Bootloader/Debug/UART_Bootloader.hex
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
:1000000078040020F1000000ED000000ED00000089
|
||||||
|
:1000100000000000000000000000000000000000E0
|
||||||
|
:10002000000000000000000000000000ED000000E3
|
||||||
|
:100030000000000000000000ED000000ED000000E6
|
||||||
|
:10004000ED000000ED000000ED000000ED000000FC
|
||||||
|
:10005000ED000000ED000000ED00000000000000D9
|
||||||
|
:10006000ED000000ED000000ED000000ED000000DC
|
||||||
|
:10007000ED000000ED000000ED000000ED000000CC
|
||||||
|
:10008000ED000000ED000000ED00000010B5064C92
|
||||||
|
:100090002378002B07D1054B002B02D0044800E049
|
||||||
|
:1000A00000BF0123237010BD0400002000000000E9
|
||||||
|
:1000B0008C04000008B5084B002B03D00748084902
|
||||||
|
:1000C00000E000BF07480368002B00D108BD064BC5
|
||||||
|
:1000D000002BFBD09847F9E7000000008C040000DB
|
||||||
|
:1000E000080000208C04000000000000FEE7000073
|
||||||
|
:1000F0001C481D4910B50023884201D11B4B07E065
|
||||||
|
:100100001B4CCA18A242F9D2C45804331460F7E752
|
||||||
|
:10011000184A934202D2002204C3F9E7FF210220C9
|
||||||
|
:10012000154B164A8B4393603022154B5862154B82
|
||||||
|
:10013000997B9143103A11439973997B143A9143F7
|
||||||
|
:10014000043A1143997303219A7B8A4302439A73B9
|
||||||
|
:100150000D4A7D3153680B4353600C4B98470C4B51
|
||||||
|
:100160009847FEE78C0400000000002004000020F7
|
||||||
|
:1001700004000020740000200000000000ED00E0FA
|
||||||
|
:10018000FC70004100480041004000412104000093
|
||||||
|
:10019000A502000010B510240E4A0F4B9A620F4AB8
|
||||||
|
:1001A000136A234313620E4A0E4B5A80C0220E4B31
|
||||||
|
:1001B000920219430D4B19605A60D9690B4A4907DD
|
||||||
|
:1001C000FBD490810220116801431160DA69920723
|
||||||
|
:1001D000FCD410BD000C0153004400410004004059
|
||||||
|
:1001E00010400000000C00400400004000100042DD
|
||||||
|
:1001F000034B1A7ED207FBD580B218857047C046E4
|
||||||
|
:1002000000100042034B1A7E5207FBD5188DC0B276
|
||||||
|
:100210007047C04600100042084B1A7DD207FBD53C
|
||||||
|
:10022000198B074A80080A401A83064A4000D861A1
|
||||||
|
:100230001A801A7DD207FCD57047C04600400041A5
|
||||||
|
:10024000E0FEFFFF02A5FFFFF0B5134B1C7DE407A6
|
||||||
|
:10025000FBD5124C1C801C7D0F4DE407FBD52E8B6B
|
||||||
|
:100260000F4C400834402C8300244000A5B2954236
|
||||||
|
:100270000ED2A5B2571E4E5DBD4201DBB5B203E002
|
||||||
|
:100280004D196D782D023543261835800234EDE77F
|
||||||
|
:100290001A7DD207FCD5F0BD0040004144A5FFFF08
|
||||||
|
:1002A000E0FEFFFFF7B58022494B92009A60802262
|
||||||
|
:1002B0000620484992049A610870196A11420BD0CD
|
||||||
|
:1002C000454A464912680A608021C900086880F3DF
|
||||||
|
:1002D0000888434881601047802292009A61414A11
|
||||||
|
:1002E000414B116A41480B4080211362404AC902C8
|
||||||
|
:1002F00053680B43C421536089033E4B98473E4DDE
|
||||||
|
:10030000A8473E4B1870232805D150303C4CA047DD
|
||||||
|
:100310000F20A047F3E7652816D18023394CDB0076
|
||||||
|
:1003200023602068384B984205D8384B984723689B
|
||||||
|
:100330000133FF33F4E78023354ADB001360354A8D
|
||||||
|
:10034000732013602E4B1DE070281DD12C4E0330FE
|
||||||
|
:10035000B04700232B4C0196236027682E4E3F2F79
|
||||||
|
:1003600005D8A8472368F05501332360F5E7284CEA
|
||||||
|
:100370002A4B2068311C4022984773202368403361
|
||||||
|
:100380002360019B9847BAE77628B8D103381C4C04
|
||||||
|
:10039000A04700231B4D2B602B680F2BAFD81D4FA0
|
||||||
|
:1003A0000E4E3B6818683060C0B2A0473368180A28
|
||||||
|
:1003B000C0B2A0473368180CC0B2A0473068000E26
|
||||||
|
:1003C000A0473B6804333B602B680133E3E7C0463A
|
||||||
|
:1003D0000044004159440041040400006C00002026
|
||||||
|
:1003E00000ED00E000080040FFFCFFFF04C5000036
|
||||||
|
:1003F00000400041950100000502000000000020BF
|
||||||
|
:10040000F101000024000020FF3F0000190200005D
|
||||||
|
:1004100020000020280000202C00002049020000BD
|
||||||
|
:100420000E4B70B500251E1C0D4CE41AA410A542FD
|
||||||
|
:1004300004D0AB00F35898470135F8E700F016F800
|
||||||
|
:10044000084B00251E1C084CE41AA410A54204D039
|
||||||
|
:10045000AB00F35898470135F8E770BD7804000009
|
||||||
|
:1004600078040000780400007C040000F8B5C04661
|
||||||
|
:10047000F8BC08BC9E467047B5000000F8B5C04601
|
||||||
|
:0C048000F8BC08BC9E4670478D000000D0
|
||||||
|
:04048C00010000006B
|
||||||
|
:00000001FF
|
||||||
10
bootloaders/samd10/UART_Bootloader/Debug/makedep.mk
Normal file
10
bootloaders/samd10/UART_Bootloader/Debug/makedep.mk
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
################################################################################
|
||||||
|
# Automatically-generated file. Do not edit or delete the file
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
Device_Startup\startup_samd10.c
|
||||||
|
|
||||||
|
Device_Startup\system_samd10.c
|
||||||
|
|
||||||
|
main.c
|
||||||
|
|
||||||
|
|
@ -0,0 +1,157 @@
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief Linker script for running in internal FLASH on the SAMD10D14AM
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||||
|
OUTPUT_ARCH(arm)
|
||||||
|
SEARCH_DIR(.)
|
||||||
|
|
||||||
|
/* Memory Spaces Definitions */
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00004000
|
||||||
|
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00001000
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The stack size used by the application. NOTE: you need to adjust according to your application. */
|
||||||
|
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 0x400;
|
||||||
|
|
||||||
|
/* Section Definitions */
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
.text :
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
_sfixed = .;
|
||||||
|
KEEP(*(.vectors .vectors.*))
|
||||||
|
*(.text .text.* .gnu.linkonce.t.*)
|
||||||
|
*(.glue_7t) *(.glue_7)
|
||||||
|
*(.rodata .rodata* .gnu.linkonce.r.*)
|
||||||
|
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||||
|
|
||||||
|
/* Support C constructors, and C destructors in both user code
|
||||||
|
and the C library. This also provides support for C++ code. */
|
||||||
|
. = ALIGN(4);
|
||||||
|
KEEP(*(.init))
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
KEEP (*crtbegin.o(.ctors))
|
||||||
|
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||||
|
KEEP (*(SORT(.ctors.*)))
|
||||||
|
KEEP (*crtend.o(.ctors))
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
KEEP(*(.fini))
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
|
||||||
|
KEEP (*crtbegin.o(.dtors))
|
||||||
|
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||||
|
KEEP (*(SORT(.dtors.*)))
|
||||||
|
KEEP (*crtend.o(.dtors))
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
_efixed = .; /* End of text section */
|
||||||
|
} > rom
|
||||||
|
|
||||||
|
/* .ARM.exidx is sorted, so has to go in its own output section. */
|
||||||
|
PROVIDE_HIDDEN (__exidx_start = .);
|
||||||
|
.ARM.exidx :
|
||||||
|
{
|
||||||
|
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||||
|
} > rom
|
||||||
|
PROVIDE_HIDDEN (__exidx_end = .);
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
_etext = .;
|
||||||
|
|
||||||
|
.relocate : AT (_etext)
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
_srelocate = .;
|
||||||
|
*(.ramfunc .ramfunc.*);
|
||||||
|
*(.data .data.*);
|
||||||
|
. = ALIGN(4);
|
||||||
|
_erelocate = .;
|
||||||
|
} > ram
|
||||||
|
|
||||||
|
/* .bss section which is used for uninitialized data */
|
||||||
|
.bss (NOLOAD) :
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
_sbss = . ;
|
||||||
|
_szero = .;
|
||||||
|
*(.bss .bss.*)
|
||||||
|
*(COMMON)
|
||||||
|
. = ALIGN(4);
|
||||||
|
_ebss = . ;
|
||||||
|
_ezero = .;
|
||||||
|
} > ram
|
||||||
|
|
||||||
|
/* stack section */
|
||||||
|
.stack (NOLOAD):
|
||||||
|
{
|
||||||
|
. = ALIGN(8);
|
||||||
|
_sstack = .;
|
||||||
|
. = . + STACK_SIZE;
|
||||||
|
. = ALIGN(8);
|
||||||
|
_estack = .;
|
||||||
|
} > ram
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
_end = . ;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,156 @@
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief Linker script for running in internal SRAM on the SAMD10D14AM
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||||
|
OUTPUT_ARCH(arm)
|
||||||
|
SEARCH_DIR(.)
|
||||||
|
|
||||||
|
/* Memory Spaces Definitions */
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00001000
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The stack size used by the application. NOTE: you need to adjust according to your application. */
|
||||||
|
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 0x400;
|
||||||
|
|
||||||
|
/* Section Definitions */
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
.text :
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
_sfixed = .;
|
||||||
|
KEEP(*(.vectors .vectors.*))
|
||||||
|
*(.text .text.* .gnu.linkonce.t.*)
|
||||||
|
*(.glue_7t) *(.glue_7)
|
||||||
|
*(.rodata .rodata* .gnu.linkonce.r.*)
|
||||||
|
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||||
|
|
||||||
|
/* Support C constructors, and C destructors in both user code
|
||||||
|
and the C library. This also provides support for C++ code. */
|
||||||
|
. = ALIGN(4);
|
||||||
|
KEEP(*(.init))
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
KEEP (*crtbegin.o(.ctors))
|
||||||
|
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||||
|
KEEP (*(SORT(.ctors.*)))
|
||||||
|
KEEP (*crtend.o(.ctors))
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
KEEP(*(.fini))
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
|
||||||
|
KEEP (*crtbegin.o(.dtors))
|
||||||
|
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||||
|
KEEP (*(SORT(.dtors.*)))
|
||||||
|
KEEP (*crtend.o(.dtors))
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
_efixed = .; /* End of text section */
|
||||||
|
} > ram
|
||||||
|
|
||||||
|
/* .ARM.exidx is sorted, so has to go in its own output section. */
|
||||||
|
PROVIDE_HIDDEN (__exidx_start = .);
|
||||||
|
.ARM.exidx :
|
||||||
|
{
|
||||||
|
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||||
|
} > ram
|
||||||
|
PROVIDE_HIDDEN (__exidx_end = .);
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
_etext = .;
|
||||||
|
|
||||||
|
.relocate : AT (_etext)
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
_srelocate = .;
|
||||||
|
*(.ramfunc .ramfunc.*);
|
||||||
|
*(.data .data.*);
|
||||||
|
. = ALIGN(4);
|
||||||
|
_erelocate = .;
|
||||||
|
} > ram
|
||||||
|
|
||||||
|
/* .bss section which is used for uninitialized data */
|
||||||
|
.bss (NOLOAD) :
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
_sbss = . ;
|
||||||
|
_szero = .;
|
||||||
|
*(.bss .bss.*)
|
||||||
|
*(COMMON)
|
||||||
|
. = ALIGN(4);
|
||||||
|
_ebss = . ;
|
||||||
|
_ezero = .;
|
||||||
|
} > ram
|
||||||
|
|
||||||
|
/* stack section */
|
||||||
|
.stack (NOLOAD):
|
||||||
|
{
|
||||||
|
. = ALIGN(8);
|
||||||
|
_sstack = .;
|
||||||
|
. = . + STACK_SIZE;
|
||||||
|
. = ALIGN(8);
|
||||||
|
_estack = .;
|
||||||
|
} > ram
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
_end = . ;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,214 @@
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief gcc starttup file for SAMD10
|
||||||
|
*
|
||||||
|
* 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 "samd10.h"
|
||||||
|
|
||||||
|
/* Initialize segments */
|
||||||
|
extern uint32_t _sfixed;
|
||||||
|
extern uint32_t _efixed;
|
||||||
|
extern uint32_t _etext;
|
||||||
|
extern uint32_t _srelocate;
|
||||||
|
extern uint32_t _erelocate;
|
||||||
|
extern uint32_t _szero;
|
||||||
|
extern uint32_t _ezero;
|
||||||
|
extern uint32_t _sstack;
|
||||||
|
extern uint32_t _estack;
|
||||||
|
|
||||||
|
/** \cond DOXYGEN_SHOULD_SKIP_THIS */
|
||||||
|
int main(void);
|
||||||
|
/** \endcond */
|
||||||
|
|
||||||
|
void __libc_init_array(void);
|
||||||
|
|
||||||
|
/* Default empty handler */
|
||||||
|
void Dummy_Handler(void);
|
||||||
|
|
||||||
|
/* Cortex-M0+ core handlers */
|
||||||
|
void NMI_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void HardFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SVC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void PendSV_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SysTick_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
|
||||||
|
/* Peripherals handlers */
|
||||||
|
void PM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SYSCTRL_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void WDT_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void RTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void EIC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void NVMCTRL_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void DMAC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
#ifdef ID_USB
|
||||||
|
void USB_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
#endif
|
||||||
|
void EVSYS_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SERCOM0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SERCOM1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
#ifdef ID_SERCOM2
|
||||||
|
void SERCOM2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
#endif
|
||||||
|
void TCC0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void TC1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void TC2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void ADC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void AC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
#ifdef ID_DAC
|
||||||
|
void DAC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
#endif
|
||||||
|
void PTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
|
||||||
|
/* Exception Table */
|
||||||
|
__attribute__ ((section(".vectors")))
|
||||||
|
const DeviceVectors exception_table = {
|
||||||
|
|
||||||
|
/* Configure Initial Stack Pointer, using linker-generated symbols */
|
||||||
|
(void*) (&_estack),
|
||||||
|
|
||||||
|
(void*) Reset_Handler,
|
||||||
|
(void*) NMI_Handler,
|
||||||
|
(void*) HardFault_Handler,
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) SVC_Handler,
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) PendSV_Handler,
|
||||||
|
(void*) SysTick_Handler,
|
||||||
|
|
||||||
|
/* Configurable interrupts */
|
||||||
|
(void*) PM_Handler, /* 0 Power Manager */
|
||||||
|
(void*) SYSCTRL_Handler, /* 1 System Control */
|
||||||
|
(void*) WDT_Handler, /* 2 Watchdog Timer */
|
||||||
|
(void*) RTC_Handler, /* 3 Real-Time Counter */
|
||||||
|
(void*) EIC_Handler, /* 4 External Interrupt Controller */
|
||||||
|
(void*) NVMCTRL_Handler, /* 5 Non-Volatile Memory Controller */
|
||||||
|
(void*) DMAC_Handler, /* 6 Direct Memory Access Controller */
|
||||||
|
#ifdef ID_USB
|
||||||
|
(void*) USB_Handler, /* 7 Universal Serial Bus */
|
||||||
|
#else
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
#endif
|
||||||
|
(void*) EVSYS_Handler, /* 8 Event System Interface */
|
||||||
|
(void*) SERCOM0_Handler, /* 9 Serial Communication Interface 0 */
|
||||||
|
(void*) SERCOM1_Handler, /* 10 Serial Communication Interface 1 */
|
||||||
|
#ifdef ID_SERCOM2
|
||||||
|
(void*) SERCOM2_Handler, /* 11 Serial Communication Interface 2 */
|
||||||
|
#else
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
#endif
|
||||||
|
(void*) TCC0_Handler, /* 12 Timer Counter Control */
|
||||||
|
(void*) TC1_Handler, /* 13 Basic Timer Counter 0 */
|
||||||
|
(void*) TC2_Handler, /* 14 Basic Timer Counter 1 */
|
||||||
|
(void*) ADC_Handler, /* 15 Analog Digital Converter */
|
||||||
|
(void*) AC_Handler, /* 16 Analog Comparators */
|
||||||
|
#ifdef ID_DAC
|
||||||
|
(void*) DAC_Handler, /* 17 Digital Analog Converter */
|
||||||
|
#else
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
#endif
|
||||||
|
(void*) PTC_Handler /* 18 Peripheral Touch Controller */
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief This is the code that gets called on processor reset.
|
||||||
|
* To initialize the device, and call the main() routine.
|
||||||
|
*/
|
||||||
|
void Reset_Handler(void)
|
||||||
|
{
|
||||||
|
uint32_t *pSrc, *pDest;
|
||||||
|
|
||||||
|
/* Initialize the relocate segment */
|
||||||
|
pSrc = &_etext;
|
||||||
|
pDest = &_srelocate;
|
||||||
|
|
||||||
|
if (pSrc != pDest) {
|
||||||
|
for (; pDest < &_erelocate;) {
|
||||||
|
*pDest++ = *pSrc++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clear the zero segment */
|
||||||
|
for (pDest = &_szero; pDest < &_ezero;) {
|
||||||
|
*pDest++ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the vector table base address */
|
||||||
|
pSrc = (uint32_t *) & _sfixed;
|
||||||
|
SCB->VTOR = ((uint32_t) pSrc & SCB_VTOR_TBLOFF_Msk);
|
||||||
|
|
||||||
|
/* Change default QOS values to have the best performance and correct USB behaviour */
|
||||||
|
SBMATRIX->SFR[SBMATRIX_SLAVE_HMCRAMC0].reg = 2;
|
||||||
|
#if defined(ID_USB)
|
||||||
|
USB->DEVICE.QOSCTRL.bit.CQOS = 2;
|
||||||
|
USB->DEVICE.QOSCTRL.bit.DQOS = 2;
|
||||||
|
#endif
|
||||||
|
DMAC->QOSCTRL.bit.DQOS = 2;
|
||||||
|
DMAC->QOSCTRL.bit.FQOS = 2;
|
||||||
|
DMAC->QOSCTRL.bit.WRBQOS = 2;
|
||||||
|
|
||||||
|
/* Overwriting the default value of the NVMCTRL.CTRLB.MANW bit (errata reference 13134) */
|
||||||
|
NVMCTRL->CTRLB.bit.MANW = 1;
|
||||||
|
|
||||||
|
/* Initialize the C library */
|
||||||
|
__libc_init_array();
|
||||||
|
|
||||||
|
/* Branch to main function */
|
||||||
|
main();
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Default interrupt handler for unused IRQs.
|
||||||
|
*/
|
||||||
|
void Dummy_Handler(void)
|
||||||
|
{
|
||||||
|
while (1) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,214 @@
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief gcc starttup file for SAMD11
|
||||||
|
*
|
||||||
|
* 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 "samd11.h"
|
||||||
|
|
||||||
|
/* Initialize segments */
|
||||||
|
extern uint32_t _sfixed;
|
||||||
|
extern uint32_t _efixed;
|
||||||
|
extern uint32_t _etext;
|
||||||
|
extern uint32_t _srelocate;
|
||||||
|
extern uint32_t _erelocate;
|
||||||
|
extern uint32_t _szero;
|
||||||
|
extern uint32_t _ezero;
|
||||||
|
extern uint32_t _sstack;
|
||||||
|
extern uint32_t _estack;
|
||||||
|
|
||||||
|
/** \cond DOXYGEN_SHOULD_SKIP_THIS */
|
||||||
|
int main(void);
|
||||||
|
/** \endcond */
|
||||||
|
|
||||||
|
void __libc_init_array(void);
|
||||||
|
|
||||||
|
/* Default empty handler */
|
||||||
|
void Dummy_Handler(void);
|
||||||
|
|
||||||
|
/* Cortex-M0+ core handlers */
|
||||||
|
void NMI_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void HardFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SVC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void PendSV_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SysTick_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
|
||||||
|
/* Peripherals handlers */
|
||||||
|
void PM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SYSCTRL_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void WDT_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void RTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void EIC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void NVMCTRL_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void DMAC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
#ifdef ID_USB
|
||||||
|
void USB_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
#endif
|
||||||
|
void EVSYS_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SERCOM0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SERCOM1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
#ifdef ID_SERCOM2
|
||||||
|
void SERCOM2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
#endif
|
||||||
|
void TCC0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void TC1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void TC2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void ADC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void AC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
#ifdef ID_DAC
|
||||||
|
void DAC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
#endif
|
||||||
|
void PTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
|
||||||
|
/* Exception Table */
|
||||||
|
__attribute__ ((section(".vectors")))
|
||||||
|
const DeviceVectors exception_table = {
|
||||||
|
|
||||||
|
/* Configure Initial Stack Pointer, using linker-generated symbols */
|
||||||
|
(void*) (&_estack),
|
||||||
|
|
||||||
|
(void*) Reset_Handler,
|
||||||
|
(void*) NMI_Handler,
|
||||||
|
(void*) HardFault_Handler,
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) SVC_Handler,
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) PendSV_Handler,
|
||||||
|
(void*) SysTick_Handler,
|
||||||
|
|
||||||
|
/* Configurable interrupts */
|
||||||
|
(void*) PM_Handler, /* 0 Power Manager */
|
||||||
|
(void*) SYSCTRL_Handler, /* 1 System Control */
|
||||||
|
(void*) WDT_Handler, /* 2 Watchdog Timer */
|
||||||
|
(void*) RTC_Handler, /* 3 Real-Time Counter */
|
||||||
|
(void*) EIC_Handler, /* 4 External Interrupt Controller */
|
||||||
|
(void*) NVMCTRL_Handler, /* 5 Non-Volatile Memory Controller */
|
||||||
|
(void*) DMAC_Handler, /* 6 Direct Memory Access Controller */
|
||||||
|
#ifdef ID_USB
|
||||||
|
(void*) USB_Handler, /* 7 Universal Serial Bus */
|
||||||
|
#else
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
#endif
|
||||||
|
(void*) EVSYS_Handler, /* 8 Event System Interface */
|
||||||
|
(void*) SERCOM0_Handler, /* 9 Serial Communication Interface 0 */
|
||||||
|
(void*) SERCOM1_Handler, /* 10 Serial Communication Interface 1 */
|
||||||
|
#ifdef ID_SERCOM2
|
||||||
|
(void*) SERCOM2_Handler, /* 11 Serial Communication Interface 2 */
|
||||||
|
#else
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
#endif
|
||||||
|
(void*) TCC0_Handler, /* 12 Timer Counter Control */
|
||||||
|
(void*) TC1_Handler, /* 13 Basic Timer Counter 0 */
|
||||||
|
(void*) TC2_Handler, /* 14 Basic Timer Counter 1 */
|
||||||
|
(void*) ADC_Handler, /* 15 Analog Digital Converter */
|
||||||
|
(void*) AC_Handler, /* 16 Analog Comparators */
|
||||||
|
#ifdef ID_DAC
|
||||||
|
(void*) DAC_Handler, /* 17 Digital Analog Converter */
|
||||||
|
#else
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
#endif
|
||||||
|
(void*) PTC_Handler /* 18 Peripheral Touch Controller */
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief This is the code that gets called on processor reset.
|
||||||
|
* To initialize the device, and call the main() routine.
|
||||||
|
*/
|
||||||
|
void Reset_Handler(void)
|
||||||
|
{
|
||||||
|
uint32_t *pSrc, *pDest;
|
||||||
|
|
||||||
|
/* Initialize the relocate segment */
|
||||||
|
pSrc = &_etext;
|
||||||
|
pDest = &_srelocate;
|
||||||
|
|
||||||
|
if (pSrc != pDest) {
|
||||||
|
for (; pDest < &_erelocate;) {
|
||||||
|
*pDest++ = *pSrc++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clear the zero segment */
|
||||||
|
for (pDest = &_szero; pDest < &_ezero;) {
|
||||||
|
*pDest++ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the vector table base address */
|
||||||
|
pSrc = (uint32_t *) & _sfixed;
|
||||||
|
SCB->VTOR = ((uint32_t) pSrc & SCB_VTOR_TBLOFF_Msk);
|
||||||
|
|
||||||
|
///* Change default QOS values to have the best performance and correct USB behaviour */
|
||||||
|
//SBMATRIX->SFR[SBMATRIX_SLAVE_HMCRAMC0].reg = 2;
|
||||||
|
//#if defined(ID_USB)
|
||||||
|
//USB->DEVICE.QOSCTRL.bit.CQOS = 2;
|
||||||
|
//USB->DEVICE.QOSCTRL.bit.DQOS = 2;
|
||||||
|
//#endif
|
||||||
|
//DMAC->QOSCTRL.bit.DQOS = 2;
|
||||||
|
//DMAC->QOSCTRL.bit.FQOS = 2;
|
||||||
|
//DMAC->QOSCTRL.bit.WRBQOS = 2;
|
||||||
|
//
|
||||||
|
///* Overwriting the default value of the NVMCTRL.CTRLB.MANW bit (errata reference 13134) */
|
||||||
|
//NVMCTRL->CTRLB.bit.MANW = 1;
|
||||||
|
|
||||||
|
/* Initialize the C library */
|
||||||
|
//__libc_init_array();
|
||||||
|
|
||||||
|
/* Branch to main function */
|
||||||
|
main();
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Default interrupt handler for unused IRQs.
|
||||||
|
*/
|
||||||
|
void Dummy_Handler(void)
|
||||||
|
{
|
||||||
|
while (1) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,78 @@
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief Low-level initialization functions called upon chip startup.
|
||||||
|
*
|
||||||
|
* 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 "samd10.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initial system clock frequency. The System RC Oscillator (RCSYS) provides
|
||||||
|
* the source for the main clock at chip startup.
|
||||||
|
*/
|
||||||
|
#define __SYSTEM_CLOCK (1000000)
|
||||||
|
|
||||||
|
uint32_t SystemCoreClock = __SYSTEM_CLOCK;/*!< System Clock Frequency (Core Clock)*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the system
|
||||||
|
*
|
||||||
|
* @brief Setup the microcontroller system.
|
||||||
|
* Initialize the System and update the SystemCoreClock variable.
|
||||||
|
*/
|
||||||
|
void SystemInit(void)
|
||||||
|
{
|
||||||
|
// Keep the default device state after reset
|
||||||
|
SystemCoreClock = __SYSTEM_CLOCK;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update SystemCoreClock variable
|
||||||
|
*
|
||||||
|
* @brief Updates the SystemCoreClock with current core Clock
|
||||||
|
* retrieved from cpu registers.
|
||||||
|
*/
|
||||||
|
void SystemCoreClockUpdate(void)
|
||||||
|
{
|
||||||
|
// Not implemented
|
||||||
|
SystemCoreClock = __SYSTEM_CLOCK;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,171 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Store xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="AtmelPackComponentManagement">
|
||||||
|
<ProjectComponents>
|
||||||
|
<ProjectComponent z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
|
||||||
|
<CApiVersion></CApiVersion>
|
||||||
|
<CBundle></CBundle>
|
||||||
|
<CClass>CMSIS</CClass>
|
||||||
|
<CGroup>CORE</CGroup>
|
||||||
|
<CSub></CSub>
|
||||||
|
<CVariant></CVariant>
|
||||||
|
<CVendor>ARM</CVendor>
|
||||||
|
<CVersion>3.40.0</CVersion>
|
||||||
|
<DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
|
||||||
|
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||||
|
<d4p1:anyType z:Id="i2" i:type="ProjectComponent">
|
||||||
|
<CApiVersion></CApiVersion>
|
||||||
|
<CBundle></CBundle>
|
||||||
|
<CClass>Device</CClass>
|
||||||
|
<CGroup>Startup</CGroup>
|
||||||
|
<CSub></CSub>
|
||||||
|
<CVariant></CVariant>
|
||||||
|
<CVendor>Atmel</CVendor>
|
||||||
|
<CVersion>1.0.0</CVersion>
|
||||||
|
<DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
|
||||||
|
<DependentComponents>
|
||||||
|
<d4p1:anyType z:Ref="i1" />
|
||||||
|
</DependentComponents>
|
||||||
|
<Description></Description>
|
||||||
|
<Files>
|
||||||
|
<d4p1:anyType i:type="FileInfo">
|
||||||
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAMD11_DFP\1.0.30\include</AbsolutePath>
|
||||||
|
<Attribute></Attribute>
|
||||||
|
<Category>include</Category>
|
||||||
|
<Condition>C</Condition>
|
||||||
|
<FileContentHash i:nil="true" />
|
||||||
|
<FileVersion></FileVersion>
|
||||||
|
<Name>include</Name>
|
||||||
|
<SelectString></SelectString>
|
||||||
|
<SourcePath></SourcePath>
|
||||||
|
</d4p1:anyType>
|
||||||
|
<d4p1:anyType i:type="FileInfo">
|
||||||
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAMD11_DFP\1.0.30\include\sam.h</AbsolutePath>
|
||||||
|
<Attribute></Attribute>
|
||||||
|
<Category>header</Category>
|
||||||
|
<Condition>C</Condition>
|
||||||
|
<FileContentHash>QqcKUfcXj4IuopNrqBMw+A==</FileContentHash>
|
||||||
|
<FileVersion></FileVersion>
|
||||||
|
<Name>include/sam.h</Name>
|
||||||
|
<SelectString></SelectString>
|
||||||
|
<SourcePath></SourcePath>
|
||||||
|
</d4p1:anyType>
|
||||||
|
<d4p1:anyType i:type="FileInfo">
|
||||||
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAMD11_DFP\1.0.30\templates\main.c</AbsolutePath>
|
||||||
|
<Attribute>template</Attribute>
|
||||||
|
<Category>source</Category>
|
||||||
|
<Condition>C Exe</Condition>
|
||||||
|
<FileContentHash>o0ncidL5gR0Z0YwWJ1YroQ==</FileContentHash>
|
||||||
|
<FileVersion></FileVersion>
|
||||||
|
<Name>templates/main.c</Name>
|
||||||
|
<SelectString>Main file (.c)</SelectString>
|
||||||
|
<SourcePath></SourcePath>
|
||||||
|
</d4p1:anyType>
|
||||||
|
<d4p1:anyType i:type="FileInfo">
|
||||||
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAMD11_DFP\1.0.30\templates\main.cpp</AbsolutePath>
|
||||||
|
<Attribute>template</Attribute>
|
||||||
|
<Category>source</Category>
|
||||||
|
<Condition>C Exe</Condition>
|
||||||
|
<FileContentHash>nU+WlKcYaWh0AWBBS+WVpA==</FileContentHash>
|
||||||
|
<FileVersion></FileVersion>
|
||||||
|
<Name>templates/main.cpp</Name>
|
||||||
|
<SelectString>Main file (.cpp)</SelectString>
|
||||||
|
<SourcePath></SourcePath>
|
||||||
|
</d4p1:anyType>
|
||||||
|
<d4p1:anyType i:type="FileInfo">
|
||||||
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAMD11_DFP\1.0.30\gcc\system_samd11.c</AbsolutePath>
|
||||||
|
<Attribute>config</Attribute>
|
||||||
|
<Category>source</Category>
|
||||||
|
<Condition>GCC Exe</Condition>
|
||||||
|
<FileContentHash>SChOoQqgr7a/S70IzUIS8w==</FileContentHash>
|
||||||
|
<FileVersion></FileVersion>
|
||||||
|
<Name>gcc/system_samd11.c</Name>
|
||||||
|
<SelectString></SelectString>
|
||||||
|
<SourcePath></SourcePath>
|
||||||
|
</d4p1:anyType>
|
||||||
|
<d4p1:anyType i:type="FileInfo">
|
||||||
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAMD11_DFP\1.0.30\gcc\gcc\startup_samd11.c</AbsolutePath>
|
||||||
|
<Attribute>config</Attribute>
|
||||||
|
<Category>source</Category>
|
||||||
|
<Condition>GCC Exe</Condition>
|
||||||
|
<FileContentHash>F7+HygHlJ8K8IcAPkmCO9Q==</FileContentHash>
|
||||||
|
<FileVersion></FileVersion>
|
||||||
|
<Name>gcc/gcc/startup_samd11.c</Name>
|
||||||
|
<SelectString></SelectString>
|
||||||
|
<SourcePath></SourcePath>
|
||||||
|
</d4p1:anyType>
|
||||||
|
<d4p1:anyType i:type="FileInfo">
|
||||||
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAMD11_DFP\1.0.30\gcc\gcc\samd11d14am_flash.ld</AbsolutePath>
|
||||||
|
<Attribute>config</Attribute>
|
||||||
|
<Category>linkerScript</Category>
|
||||||
|
<Condition>GCC Exe</Condition>
|
||||||
|
<FileContentHash>QMooFSicJpFAQSEW1ngZzw==</FileContentHash>
|
||||||
|
<FileVersion></FileVersion>
|
||||||
|
<Name>gcc/gcc/samd11d14am_flash.ld</Name>
|
||||||
|
<SelectString></SelectString>
|
||||||
|
<SourcePath></SourcePath>
|
||||||
|
</d4p1:anyType>
|
||||||
|
<d4p1:anyType i:type="FileInfo">
|
||||||
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAMD11_DFP\1.0.30\gcc\gcc\samd11d14am_sram.ld</AbsolutePath>
|
||||||
|
<Attribute>config</Attribute>
|
||||||
|
<Category>other</Category>
|
||||||
|
<Condition>GCC Exe</Condition>
|
||||||
|
<FileContentHash>n9lyF/Qb5SPULQS5Ymr1Xw==</FileContentHash>
|
||||||
|
<FileVersion></FileVersion>
|
||||||
|
<Name>gcc/gcc/samd11d14am_sram.ld</Name>
|
||||||
|
<SelectString></SelectString>
|
||||||
|
<SourcePath></SourcePath>
|
||||||
|
</d4p1:anyType>
|
||||||
|
</Files>
|
||||||
|
<PackName>SAMD11_DFP</PackName>
|
||||||
|
<PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/SAMD11_DFP/1.0.30/Atmel.SAMD11_DFP.pdsc</PackPath>
|
||||||
|
<PackVersion>1.0.30</PackVersion>
|
||||||
|
<PresentInProject>true</PresentInProject>
|
||||||
|
<ReferenceConditionId>ATSAMD11D14AM</ReferenceConditionId>
|
||||||
|
<RteComponents>
|
||||||
|
<d4p1:string></d4p1:string>
|
||||||
|
</RteComponents>
|
||||||
|
<Status>Resolved</Status>
|
||||||
|
<VersionMode>Fixed</VersionMode>
|
||||||
|
<IsComponentInAtProject>true</IsComponentInAtProject>
|
||||||
|
</d4p1:anyType>
|
||||||
|
</DependentComponents>
|
||||||
|
<Description></Description>
|
||||||
|
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||||
|
<d4p1:anyType i:type="FileInfo">
|
||||||
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\arm\cmsis\4.2.0\CMSIS\Documentation\Core\html\index.html</AbsolutePath>
|
||||||
|
<Attribute></Attribute>
|
||||||
|
<Category>doc</Category>
|
||||||
|
<Condition></Condition>
|
||||||
|
<FileContentHash>Fm1Ae7doPh4708FZQAIEpw==</FileContentHash>
|
||||||
|
<FileVersion></FileVersion>
|
||||||
|
<Name>CMSIS\Documentation\Core\html\index.html</Name>
|
||||||
|
<SelectString></SelectString>
|
||||||
|
<SourcePath></SourcePath>
|
||||||
|
</d4p1:anyType>
|
||||||
|
<d4p1:anyType i:type="FileInfo">
|
||||||
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\arm\cmsis\4.2.0\CMSIS\Include\</AbsolutePath>
|
||||||
|
<Attribute></Attribute>
|
||||||
|
<Category>include</Category>
|
||||||
|
<Condition></Condition>
|
||||||
|
<FileContentHash i:nil="true" />
|
||||||
|
<FileVersion></FileVersion>
|
||||||
|
<Name>CMSIS\Include\</Name>
|
||||||
|
<SelectString></SelectString>
|
||||||
|
<SourcePath></SourcePath>
|
||||||
|
</d4p1:anyType>
|
||||||
|
</Files>
|
||||||
|
<PackName>CMSIS</PackName>
|
||||||
|
<PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/arm/cmsis/4.2.0/ARM.CMSIS.pdsc</PackPath>
|
||||||
|
<PackVersion>4.2.0</PackVersion>
|
||||||
|
<PresentInProject>true</PresentInProject>
|
||||||
|
<ReferenceConditionId>CMSIS Core</ReferenceConditionId>
|
||||||
|
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||||
|
<d4p1:string></d4p1:string>
|
||||||
|
</RteComponents>
|
||||||
|
<Status>Resolved</Status>
|
||||||
|
<VersionMode>Fixed</VersionMode>
|
||||||
|
<IsComponentInAtProject>true</IsComponentInAtProject>
|
||||||
|
</ProjectComponent>
|
||||||
|
<ProjectComponent z:Ref="i2" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" />
|
||||||
|
</ProjectComponents>
|
||||||
|
</Store>
|
||||||
208
bootloaders/samd10/UART_Bootloader/UART_Bootloader.cproj
Normal file
208
bootloaders/samd10/UART_Bootloader/UART_Bootloader.cproj
Normal file
|
|
@ -0,0 +1,208 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
|
||||||
|
<PropertyGroup>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectVersion>7.0</ProjectVersion>
|
||||||
|
<ToolchainName>com.Atmel.ARMGCC.C</ToolchainName>
|
||||||
|
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
|
||||||
|
<avrdevice>ATSAMD10D14AM</avrdevice>
|
||||||
|
<avrdeviceseries>none</avrdeviceseries>
|
||||||
|
<OutputType>Executable</OutputType>
|
||||||
|
<Language>C</Language>
|
||||||
|
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
|
||||||
|
<OutputFileExtension>.elf</OutputFileExtension>
|
||||||
|
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
||||||
|
<AssemblyName>UART_Bootloader</AssemblyName>
|
||||||
|
<Name>UART_Bootloader</Name>
|
||||||
|
<RootNamespace>UART_Bootloader</RootNamespace>
|
||||||
|
<ToolchainFlavour>Native</ToolchainFlavour>
|
||||||
|
<KeepTimersRunning>true</KeepTimersRunning>
|
||||||
|
<OverrideVtor>false</OverrideVtor>
|
||||||
|
<CacheFlash>true</CacheFlash>
|
||||||
|
<ProgFlashFromRam>true</ProgFlashFromRam>
|
||||||
|
<RamSnippetAddress>0x20000000</RamSnippetAddress>
|
||||||
|
<UncachedRange />
|
||||||
|
<preserveEEPROM>true</preserveEEPROM>
|
||||||
|
<OverrideVtorValue>exception_table</OverrideVtorValue>
|
||||||
|
<BootSegment>2</BootSegment>
|
||||||
|
<eraseonlaunchrule>0</eraseonlaunchrule>
|
||||||
|
<ExternalProgrammingToolCommand />
|
||||||
|
<AsfFrameworkConfig>
|
||||||
|
<framework-data xmlns="">
|
||||||
|
<options />
|
||||||
|
<configurations />
|
||||||
|
<files />
|
||||||
|
<documentation help="" />
|
||||||
|
<offline-documentation help="" />
|
||||||
|
<dependencies>
|
||||||
|
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.27.0" />
|
||||||
|
</dependencies>
|
||||||
|
</framework-data>
|
||||||
|
</AsfFrameworkConfig>
|
||||||
|
<avrtool>com.atmel.avrdbg.tool.medbg</avrtool>
|
||||||
|
<avrtoolserialnumber>ATML2378020200002155</avrtoolserialnumber>
|
||||||
|
<avrdeviceexpectedsignature>0x10020000</avrdeviceexpectedsignature>
|
||||||
|
<avrtoolinterface>SWD</avrtoolinterface>
|
||||||
|
<com_atmel_avrdbg_tool_edbg>
|
||||||
|
<ToolOptions>
|
||||||
|
<InterfaceProperties>
|
||||||
|
<SwdClock>0</SwdClock>
|
||||||
|
</InterfaceProperties>
|
||||||
|
<InterfaceName>SWD</InterfaceName>
|
||||||
|
</ToolOptions>
|
||||||
|
<ToolType>com.atmel.avrdbg.tool.edbg</ToolType>
|
||||||
|
<ToolNumber>ATML2178031800000047</ToolNumber>
|
||||||
|
<ToolName>EDBG</ToolName>
|
||||||
|
</com_atmel_avrdbg_tool_edbg>
|
||||||
|
<avrtoolinterfaceclock>2000000</avrtoolinterfaceclock>
|
||||||
|
<custom>
|
||||||
|
<ToolOptions xmlns="">
|
||||||
|
<InterfaceProperties>
|
||||||
|
</InterfaceProperties>
|
||||||
|
<InterfaceName>SWD</InterfaceName>
|
||||||
|
</ToolOptions>
|
||||||
|
<ToolType xmlns="">custom</ToolType>
|
||||||
|
<ToolNumber xmlns="">
|
||||||
|
</ToolNumber>
|
||||||
|
<ToolName xmlns="">Custom Programming Tool</ToolName>
|
||||||
|
</custom>
|
||||||
|
<com_atmel_avrdbg_tool_medbg>
|
||||||
|
<ToolOptions>
|
||||||
|
<InterfaceProperties>
|
||||||
|
<SwdClock>2000000</SwdClock>
|
||||||
|
</InterfaceProperties>
|
||||||
|
<InterfaceName>SWD</InterfaceName>
|
||||||
|
</ToolOptions>
|
||||||
|
<ToolType>com.atmel.avrdbg.tool.medbg</ToolType>
|
||||||
|
<ToolNumber>ATML2378020200002155</ToolNumber>
|
||||||
|
<ToolName>mEDBG</ToolName>
|
||||||
|
</com_atmel_avrdbg_tool_medbg>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
|
<ToolchainSettings>
|
||||||
|
<ArmGcc>
|
||||||
|
<armgcc.common.outputfiles.hex>True</armgcc.common.outputfiles.hex>
|
||||||
|
<armgcc.common.outputfiles.lss>True</armgcc.common.outputfiles.lss>
|
||||||
|
<armgcc.common.outputfiles.eep>True</armgcc.common.outputfiles.eep>
|
||||||
|
<armgcc.common.outputfiles.bin>True</armgcc.common.outputfiles.bin>
|
||||||
|
<armgcc.common.outputfiles.srec>True</armgcc.common.outputfiles.srec>
|
||||||
|
<armgcc.compiler.symbols.DefSymbols>
|
||||||
|
<ListValues>
|
||||||
|
<Value>NDEBUG</Value>
|
||||||
|
</ListValues>
|
||||||
|
</armgcc.compiler.symbols.DefSymbols>
|
||||||
|
<armgcc.compiler.directories.IncludePaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(PackRepoDir)\atmel\SAMD10_DFP\1.0.31\include</Value>
|
||||||
|
<Value>%24(PackRepoDir)\arm\cmsis\4.2.0\CMSIS\Include\</Value>
|
||||||
|
</ListValues>
|
||||||
|
</armgcc.compiler.directories.IncludePaths>
|
||||||
|
<armgcc.compiler.optimization.level>Optimize for size (-Os)</armgcc.compiler.optimization.level>
|
||||||
|
<armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
|
||||||
|
<armgcc.compiler.warnings.AllWarnings>True</armgcc.compiler.warnings.AllWarnings>
|
||||||
|
<armgcc.linker.libraries.Libraries>
|
||||||
|
<ListValues>
|
||||||
|
<Value>libm</Value>
|
||||||
|
</ListValues>
|
||||||
|
</armgcc.linker.libraries.Libraries>
|
||||||
|
<armgcc.linker.libraries.LibrarySearchPaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(ProjectDir)\Device_Startup</Value>
|
||||||
|
</ListValues>
|
||||||
|
</armgcc.linker.libraries.LibrarySearchPaths>
|
||||||
|
<armgcc.linker.optimization.GarbageCollectUnusedSections>True</armgcc.linker.optimization.GarbageCollectUnusedSections>
|
||||||
|
<armgcc.linker.miscellaneous.LinkerFlags>-Tsamd10d14am_flash.ld</armgcc.linker.miscellaneous.LinkerFlags>
|
||||||
|
<armgcc.assembler.general.IncludePaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(PackRepoDir)\atmel\SAMD10_DFP\1.0.31\include</Value>
|
||||||
|
<Value>%24(PackRepoDir)\arm\cmsis\4.2.0\CMSIS\Include\</Value>
|
||||||
|
</ListValues>
|
||||||
|
</armgcc.assembler.general.IncludePaths>
|
||||||
|
<armgcc.preprocessingassembler.general.IncludePaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(PackRepoDir)\atmel\SAMD10_DFP\1.0.31\include</Value>
|
||||||
|
<Value>%24(PackRepoDir)\arm\cmsis\4.2.0\CMSIS\Include\</Value>
|
||||||
|
</ListValues>
|
||||||
|
</armgcc.preprocessingassembler.general.IncludePaths>
|
||||||
|
</ArmGcc>
|
||||||
|
</ToolchainSettings>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
|
<ToolchainSettings>
|
||||||
|
<ArmGcc>
|
||||||
|
<armgcc.common.outputfiles.hex>True</armgcc.common.outputfiles.hex>
|
||||||
|
<armgcc.common.outputfiles.lss>True</armgcc.common.outputfiles.lss>
|
||||||
|
<armgcc.common.outputfiles.eep>True</armgcc.common.outputfiles.eep>
|
||||||
|
<armgcc.common.outputfiles.bin>True</armgcc.common.outputfiles.bin>
|
||||||
|
<armgcc.common.outputfiles.srec>True</armgcc.common.outputfiles.srec>
|
||||||
|
<armgcc.compiler.symbols.DefSymbols>
|
||||||
|
<ListValues>
|
||||||
|
<Value>DEBUG</Value>
|
||||||
|
</ListValues>
|
||||||
|
</armgcc.compiler.symbols.DefSymbols>
|
||||||
|
<armgcc.compiler.directories.IncludePaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(PackRepoDir)\atmel\SAMD10_DFP\1.0.31\include</Value>
|
||||||
|
<Value>%24(PackRepoDir)\arm\cmsis\4.2.0\CMSIS\Include\</Value>
|
||||||
|
</ListValues>
|
||||||
|
</armgcc.compiler.directories.IncludePaths>
|
||||||
|
<armgcc.compiler.optimization.level>Optimize for size (-Os)</armgcc.compiler.optimization.level>
|
||||||
|
<armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
|
||||||
|
<armgcc.compiler.optimization.PrepareDataForGarbageCollection>True</armgcc.compiler.optimization.PrepareDataForGarbageCollection>
|
||||||
|
<armgcc.compiler.optimization.DebugLevel>Maximum (-g3)</armgcc.compiler.optimization.DebugLevel>
|
||||||
|
<armgcc.compiler.warnings.AllWarnings>True</armgcc.compiler.warnings.AllWarnings>
|
||||||
|
<armgcc.linker.general.UseNewlibNano>True</armgcc.linker.general.UseNewlibNano>
|
||||||
|
<armgcc.linker.libraries.Libraries>
|
||||||
|
<ListValues>
|
||||||
|
<Value>libm</Value>
|
||||||
|
</ListValues>
|
||||||
|
</armgcc.linker.libraries.Libraries>
|
||||||
|
<armgcc.linker.libraries.LibrarySearchPaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(ProjectDir)\Device_Startup</Value>
|
||||||
|
</ListValues>
|
||||||
|
</armgcc.linker.libraries.LibrarySearchPaths>
|
||||||
|
<armgcc.linker.optimization.GarbageCollectUnusedSections>True</armgcc.linker.optimization.GarbageCollectUnusedSections>
|
||||||
|
<armgcc.linker.memorysettings.ExternalRAM />
|
||||||
|
<armgcc.linker.miscellaneous.LinkerFlags>-Tsamd10d14am_flash.ld</armgcc.linker.miscellaneous.LinkerFlags>
|
||||||
|
<armgcc.assembler.general.IncludePaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(PackRepoDir)\atmel\SAMD10_DFP\1.0.31\include</Value>
|
||||||
|
<Value>%24(PackRepoDir)\arm\cmsis\4.2.0\CMSIS\Include\</Value>
|
||||||
|
</ListValues>
|
||||||
|
</armgcc.assembler.general.IncludePaths>
|
||||||
|
<armgcc.assembler.debugging.DebugLevel>Default (-g)</armgcc.assembler.debugging.DebugLevel>
|
||||||
|
<armgcc.preprocessingassembler.general.IncludePaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(PackRepoDir)\atmel\SAMD10_DFP\1.0.31\include</Value>
|
||||||
|
<Value>%24(PackRepoDir)\arm\cmsis\4.2.0\CMSIS\Include\</Value>
|
||||||
|
</ListValues>
|
||||||
|
</armgcc.preprocessingassembler.general.IncludePaths>
|
||||||
|
<armgcc.preprocessingassembler.debugging.DebugLevel>Default (-Wa,-g)</armgcc.preprocessingassembler.debugging.DebugLevel>
|
||||||
|
</ArmGcc>
|
||||||
|
</ToolchainSettings>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Device_Startup\startup_samd10.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Device_Startup\system_samd10.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="main.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Device_Startup\" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="Device_Startup\samd10d14am_flash.ld">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</None>
|
||||||
|
<None Include="Device_Startup\samd10d14am_sram.ld">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||||
|
</Project>
|
||||||
199
bootloaders/samd10/UART_Bootloader/main.c
Normal file
199
bootloaders/samd10/UART_Bootloader/main.c
Normal file
|
|
@ -0,0 +1,199 @@
|
||||||
|
/*
|
||||||
|
* UART_Bootloader.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "sam.h"
|
||||||
|
|
||||||
|
#define PORTA 0
|
||||||
|
#define PORTB 1
|
||||||
|
|
||||||
|
/* Application starts from 1kB memory - Bootloader size is 1kB */
|
||||||
|
/* Change the address if higher boot size is needed */
|
||||||
|
#define APP_START 0x00000400
|
||||||
|
|
||||||
|
/* Target application size can be 15kB */
|
||||||
|
/* APP_SIZE is the application section size in kB */
|
||||||
|
/* Change as per APP_START */
|
||||||
|
#define APP_SIZE 15
|
||||||
|
|
||||||
|
/* Flash page size is 64 bytes */
|
||||||
|
#define PAGE_SIZE 64
|
||||||
|
/* Memory pointer for flash memory */
|
||||||
|
#define NVM_MEMORY ((volatile uint16_t *)FLASH_ADDR)
|
||||||
|
|
||||||
|
/* Change the following if different SERCOM and boot pins are used */
|
||||||
|
#define BOOT_SERCOM SERCOM2
|
||||||
|
#define BOOT_SERCOM_BAUD 115200
|
||||||
|
#define BOOT_PORT PORTA
|
||||||
|
#define BOOT_PIN 25
|
||||||
|
#define LED_PORT PORTA
|
||||||
|
#define LED_PIN 9
|
||||||
|
|
||||||
|
/* SERCOM USART GCLK Frequency */
|
||||||
|
#define SERCOM_GCLK 8000000UL
|
||||||
|
#define BAUD_VAL (65536.0*(1.0-((float)(16.0*(float)BOOT_SERCOM_BAUD)/(float)SERCOM_GCLK)))
|
||||||
|
|
||||||
|
uint8_t data_8 = 1;
|
||||||
|
uint32_t file_size, i, dest_addr, app_start_address;
|
||||||
|
uint8_t page_buffer[PAGE_SIZE];
|
||||||
|
uint32_t *flash_ptr;
|
||||||
|
|
||||||
|
enum uart_pad_settings {
|
||||||
|
UART_RX_PAD0_TX_PAD2 = SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO(1),
|
||||||
|
UART_RX_PAD1_TX_PAD2 = SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO(1),
|
||||||
|
UART_RX_PAD2_TX_PAD0 = SERCOM_USART_CTRLA_RXPO(2),
|
||||||
|
UART_RX_PAD3_TX_PAD0 = SERCOM_USART_CTRLA_RXPO(3),
|
||||||
|
UART_RX_PAD1_TX_PAD0 = SERCOM_USART_CTRLA_RXPO(1),
|
||||||
|
UART_RX_PAD3_TX_PAD2 = SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(1),
|
||||||
|
};
|
||||||
|
|
||||||
|
void uart_init(uint16_t baud_val, enum uart_pad_settings pad_conf)
|
||||||
|
{
|
||||||
|
/* Enable & configure alternate function D for pins PA10 & PA11 */
|
||||||
|
/* Change following 3 lines if different SERCOM/SERCOM pins are used */
|
||||||
|
PORT->Group[0].WRCONFIG.reg = 0x53010C00;
|
||||||
|
PM->APBCMASK.reg |= (1u << 4);
|
||||||
|
GCLK->CLKCTRL.reg = 0x4010;
|
||||||
|
|
||||||
|
BOOT_SERCOM->USART.CTRLA.reg = pad_conf | SERCOM_USART_CTRLA_MODE(1) | SERCOM_USART_CTRLA_DORD;
|
||||||
|
BOOT_SERCOM->USART.CTRLB.reg = SERCOM_USART_CTRLB_RXEN | SERCOM_USART_CTRLB_TXEN | SERCOM_USART_CTRLB_CHSIZE(0);
|
||||||
|
while(BOOT_SERCOM->USART.SYNCBUSY.bit.CTRLB);
|
||||||
|
BOOT_SERCOM->USART.BAUD.reg = baud_val;
|
||||||
|
BOOT_SERCOM->USART.CTRLA.bit.ENABLE = 1;
|
||||||
|
while(BOOT_SERCOM->USART.SYNCBUSY.bit.ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart_write_byte(uint8_t data)
|
||||||
|
{
|
||||||
|
while(!BOOT_SERCOM->USART.INTFLAG.bit.DRE);
|
||||||
|
BOOT_SERCOM->USART.DATA.reg = (uint16_t)data;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t uart_read_byte(void)
|
||||||
|
{
|
||||||
|
while(!BOOT_SERCOM->USART.INTFLAG.bit.RXC);
|
||||||
|
return((uint8_t)(BOOT_SERCOM->USART.DATA.reg & 0x00FF));
|
||||||
|
}
|
||||||
|
|
||||||
|
void nvm_erase_row(const uint32_t row_address)
|
||||||
|
{
|
||||||
|
/* Check if the module is busy */
|
||||||
|
while(!NVMCTRL->INTFLAG.bit.READY);
|
||||||
|
/* Clear error flags */
|
||||||
|
NVMCTRL->STATUS.reg &= ~NVMCTRL_STATUS_MASK;
|
||||||
|
/* Set address and command */
|
||||||
|
NVMCTRL->ADDR.reg = (uintptr_t)&NVM_MEMORY[row_address / 4];
|
||||||
|
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMD_ER | NVMCTRL_CTRLA_CMDEX_KEY;
|
||||||
|
while(!NVMCTRL->INTFLAG.bit.READY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nvm_write_buffer(const uint32_t destination_address, const uint8_t *buffer, uint16_t length)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Check if the module is busy */
|
||||||
|
while(!NVMCTRL->INTFLAG.bit.READY);
|
||||||
|
|
||||||
|
/* Erase the page buffer before buffering new data */
|
||||||
|
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMD_PBC | NVMCTRL_CTRLA_CMDEX_KEY;
|
||||||
|
|
||||||
|
/* Check if the module is busy */
|
||||||
|
while(!NVMCTRL->INTFLAG.bit.READY);
|
||||||
|
|
||||||
|
/* Clear error flags */
|
||||||
|
NVMCTRL->STATUS.reg &= ~NVMCTRL_STATUS_MASK;
|
||||||
|
|
||||||
|
uint32_t nvm_address = destination_address / 2;
|
||||||
|
|
||||||
|
/* NVM _must_ be accessed as a series of 16-bit words, perform manual copy
|
||||||
|
* to ensure alignment */
|
||||||
|
for (uint16_t k = 0; k < length; k += 2)
|
||||||
|
{
|
||||||
|
uint16_t data;
|
||||||
|
/* Copy first byte of the 16-bit chunk to the temporary buffer */
|
||||||
|
data = buffer[k];
|
||||||
|
/* If we are not at the end of a write request with an odd byte count,
|
||||||
|
* store the next byte of data as well */
|
||||||
|
if (k < (length - 1)) {
|
||||||
|
data |= (buffer[k + 1] << 8);
|
||||||
|
}
|
||||||
|
/* Store next 16-bit chunk to the NVM memory space */
|
||||||
|
NVM_MEMORY[nvm_address++] = data;
|
||||||
|
}
|
||||||
|
while(!NVMCTRL->INTFLAG.bit.READY);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
PORT->Group[LED_PORT].DIRSET.reg = (1 << LED_PIN);
|
||||||
|
|
||||||
|
/* Check if boot pin is held low - Jump to application if boot pin is high */
|
||||||
|
PORT->Group[BOOT_PORT].OUTSET.reg = (1u << BOOT_PIN);
|
||||||
|
PORT->Group[BOOT_PORT].PINCFG[BOOT_PIN].reg = PORT_PINCFG_INEN | PORT_PINCFG_PULLEN;
|
||||||
|
if ((PORT->Group[BOOT_PORT].IN.reg & (1u << BOOT_PIN)))
|
||||||
|
{
|
||||||
|
app_start_address = *(uint32_t *)(APP_START + 4);
|
||||||
|
/* Rebase the Stack Pointer */
|
||||||
|
__set_MSP(*(uint32_t *) APP_START);
|
||||||
|
|
||||||
|
/* Rebase the vector table base address */
|
||||||
|
SCB->VTOR = ((uint32_t) APP_START & SCB_VTOR_TBLOFF_Msk);
|
||||||
|
|
||||||
|
/* Jump to application Reset Handler in the application */
|
||||||
|
asm("bx %0"::"r"(app_start_address));
|
||||||
|
}
|
||||||
|
|
||||||
|
PORT->Group[LED_PORT].OUTSET.reg = (1 << LED_PIN);
|
||||||
|
|
||||||
|
|
||||||
|
/* Make CPU to run at 8MHz by clearing prescalar bits */
|
||||||
|
SYSCTRL->OSC8M.bit.PRESC = 0;
|
||||||
|
NVMCTRL->CTRLB.bit.CACHEDIS = 1;
|
||||||
|
/* Change pad_conf argument if different pad settings is used */
|
||||||
|
uart_init(BAUD_VAL, UART_RX_PAD3_TX_PAD2);
|
||||||
|
//uart_init(64278, UART_RX_PAD3_TX_PAD2);
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
data_8 = uart_read_byte();
|
||||||
|
if (data_8 == '#')
|
||||||
|
{
|
||||||
|
uart_write_byte('s');
|
||||||
|
uart_write_byte((uint8_t)APP_SIZE);
|
||||||
|
}
|
||||||
|
else if (data_8 == 'e')
|
||||||
|
{
|
||||||
|
for(i = APP_START; i < FLASH_SIZE; i = i + 256)
|
||||||
|
{
|
||||||
|
nvm_erase_row(i);
|
||||||
|
}
|
||||||
|
dest_addr = APP_START;
|
||||||
|
flash_ptr = APP_START;
|
||||||
|
uart_write_byte('s');
|
||||||
|
}
|
||||||
|
else if (data_8 == 'p')
|
||||||
|
{
|
||||||
|
uart_write_byte('s');
|
||||||
|
for (i = 0; i < PAGE_SIZE; i++)
|
||||||
|
{
|
||||||
|
page_buffer[i] = uart_read_byte();
|
||||||
|
}
|
||||||
|
nvm_write_buffer(dest_addr, page_buffer, PAGE_SIZE);
|
||||||
|
dest_addr += PAGE_SIZE;
|
||||||
|
uart_write_byte('s');
|
||||||
|
}
|
||||||
|
else if (data_8 == 'v')
|
||||||
|
{
|
||||||
|
uart_write_byte('s');
|
||||||
|
for (i = 0; i < (PAGE_SIZE/4); i++)
|
||||||
|
{
|
||||||
|
app_start_address = *flash_ptr;
|
||||||
|
uart_write_byte((uint8_t)app_start_address);
|
||||||
|
uart_write_byte((uint8_t)(app_start_address >> 8));
|
||||||
|
uart_write_byte((uint8_t)(app_start_address >> 16));
|
||||||
|
uart_write_byte((uint8_t)(app_start_address >> 24));
|
||||||
|
flash_ptr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
198
bootloaders/samd10/uart_bootloader.py
Normal file
198
bootloaders/samd10/uart_bootloader.py
Normal file
|
|
@ -0,0 +1,198 @@
|
||||||
|
import time
|
||||||
|
import serial
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import string
|
||||||
|
import argparse
|
||||||
|
import zlib
|
||||||
|
import binascii
|
||||||
|
|
||||||
|
# Parsing the arguments
|
||||||
|
parser = argparse.ArgumentParser(description = 'SAMD Bootloader script')
|
||||||
|
parser.add_argument('-c','--port', help='COM port name',required=True)
|
||||||
|
parser.add_argument('-b','--baud', help='COM port Baudrate',required=True)
|
||||||
|
parser.add_argument('-i','--inputfile', help='Input file name (.bin file)',required=True)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
page_size = 64;
|
||||||
|
|
||||||
|
# Opening COM port
|
||||||
|
ser = serial.Serial(
|
||||||
|
port = args.port,
|
||||||
|
baudrate = args.baud,
|
||||||
|
parity = serial.PARITY_NONE,
|
||||||
|
stopbits = serial.STOPBITS_ONE,
|
||||||
|
bytesize = serial.EIGHTBITS,
|
||||||
|
timeout = 1
|
||||||
|
)
|
||||||
|
print ("Port %s opened" % ser.port)
|
||||||
|
|
||||||
|
# Check whether any boot device is available
|
||||||
|
length = ser.write('#')
|
||||||
|
while ser.inWaiting == 0:
|
||||||
|
pass
|
||||||
|
read = ''
|
||||||
|
read += ser.read(1)
|
||||||
|
if read != 's':
|
||||||
|
print ("No response from device: "+ read)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Read the application flash size
|
||||||
|
while ser.inWaiting == 0:
|
||||||
|
pass
|
||||||
|
temp_app_size = ''
|
||||||
|
temp_app_size = ser.read(1)
|
||||||
|
app_size = ord(temp_app_size)
|
||||||
|
app_size = app_size * 1024
|
||||||
|
print ("Found boot media with %d Bytes application flash size!" %app_size)
|
||||||
|
|
||||||
|
# Read file size of input
|
||||||
|
len = os.path.getsize(args.inputfile)
|
||||||
|
|
||||||
|
# Check whether file size fits the device memory
|
||||||
|
if len > app_size:
|
||||||
|
print ("Input file size does not fit target memory! \n")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Erase application flash region of the device
|
||||||
|
print ("Erasing flash...")
|
||||||
|
length = ser.write('e')
|
||||||
|
while ser.inWaiting == 0:
|
||||||
|
pass
|
||||||
|
read = ''
|
||||||
|
read += ser.read(1)
|
||||||
|
if read != 's':
|
||||||
|
print ("No response from device \n")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
print ("Erase Complete!")
|
||||||
|
|
||||||
|
# Open input file
|
||||||
|
out = 0
|
||||||
|
len = os.path.getsize(args.inputfile)
|
||||||
|
input_file = open(args.inputfile, 'rb')
|
||||||
|
block_len = 64;
|
||||||
|
nb_blocks = len / block_len
|
||||||
|
rem_data = len % block_len
|
||||||
|
|
||||||
|
# Start programming flash
|
||||||
|
print ("Programming flash...")
|
||||||
|
|
||||||
|
# Program all pages except last one
|
||||||
|
out = ''
|
||||||
|
for x in range(0, nb_blocks):
|
||||||
|
print ("Programming page %d" % x)
|
||||||
|
length = ser.write('p')
|
||||||
|
while ser.inWaiting == 0:
|
||||||
|
pass
|
||||||
|
read = ''
|
||||||
|
read += ser.read(1)
|
||||||
|
if read != 's':
|
||||||
|
print ("No response from device \n")
|
||||||
|
sys.exit()
|
||||||
|
for y in range(0, block_len):
|
||||||
|
#print ("Data %d" % y)
|
||||||
|
out = ''
|
||||||
|
out += input_file.read(1)
|
||||||
|
length = ser.write(out)
|
||||||
|
#time.sleep(0.001)
|
||||||
|
|
||||||
|
#print (".")
|
||||||
|
while ser.inWaiting == 0:
|
||||||
|
pass
|
||||||
|
read = ''
|
||||||
|
read += ser.read(1)
|
||||||
|
if read != 's':
|
||||||
|
print ("No response from device \n")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Program last page
|
||||||
|
print ("Programming page %d" % nb_blocks)
|
||||||
|
length = ser.write('p')
|
||||||
|
while ser.inWaiting == 0:
|
||||||
|
pass
|
||||||
|
read = ''
|
||||||
|
read += ser.read(1)
|
||||||
|
if read != 's':
|
||||||
|
print ("No response from device \n")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
for x in xrange(0, rem_data):
|
||||||
|
length = ser.write(input_file.read(1))
|
||||||
|
#time.sleep(0.001)
|
||||||
|
|
||||||
|
for x in xrange(0, (page_size - rem_data)):
|
||||||
|
length = ser.write(chr(0xFF))
|
||||||
|
#time.sleep(0.001)
|
||||||
|
|
||||||
|
while ser.inWaiting == 0:
|
||||||
|
pass
|
||||||
|
read = ''
|
||||||
|
read += ser.read(1)
|
||||||
|
if read != 's':
|
||||||
|
print ("No response from device \n")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Close file
|
||||||
|
input_file.close()
|
||||||
|
print ("\n")
|
||||||
|
|
||||||
|
# Open input file for verifying flash
|
||||||
|
input_file = open(args.inputfile, 'rb')
|
||||||
|
print ("Verifying flash...")
|
||||||
|
|
||||||
|
# Verify all pages except last one
|
||||||
|
for x in xrange(0, nb_blocks):
|
||||||
|
print ("Verifying page %d" % x)
|
||||||
|
length = ser.write('v')
|
||||||
|
while ser.inWaiting == 0:
|
||||||
|
pass
|
||||||
|
read = ''
|
||||||
|
read += ser.read(1)
|
||||||
|
if read != 's':
|
||||||
|
print ("No response from device \n")
|
||||||
|
sys.exit()
|
||||||
|
for y in xrange(0, block_len):
|
||||||
|
while ser.inWaiting == 0:
|
||||||
|
pass
|
||||||
|
read = ''
|
||||||
|
read += ser.read(1)
|
||||||
|
out = ''
|
||||||
|
out += input_file.read(1)
|
||||||
|
if read != out:
|
||||||
|
print("\nVerification Failed at address %d!", ((x*64)+y))
|
||||||
|
sys.exit()
|
||||||
|
# print (".")
|
||||||
|
|
||||||
|
# Verify last page
|
||||||
|
print ("Verifying page %d" % nb_blocks)
|
||||||
|
length = ser.write('v')
|
||||||
|
while ser.inWaiting == 0:
|
||||||
|
pass
|
||||||
|
read = ''
|
||||||
|
read += ser.read(1)
|
||||||
|
if read != 's':
|
||||||
|
print ("No response from device \n")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
for x in xrange(0, rem_data):
|
||||||
|
while ser.inWaiting == 0:
|
||||||
|
pass
|
||||||
|
read = ''
|
||||||
|
read += ser.read(1)
|
||||||
|
out = ''
|
||||||
|
out += input_file.read(1)
|
||||||
|
if read != out:
|
||||||
|
print("\nVerification Failed at address %d!", ((nb_blocks*64)+x))
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
for x in xrange(0, (page_size - rem_data)):
|
||||||
|
while ser.inWaiting == 0:
|
||||||
|
pass
|
||||||
|
read = ''
|
||||||
|
read += ser.read(1)
|
||||||
|
|
||||||
|
print ("\nVerification complete!")
|
||||||
|
# Close file
|
||||||
|
input_file.close()
|
||||||
|
sys.exit()
|
||||||
130
cores/samd10/Arduino.h
Normal file
130
cores/samd10/Arduino.h
Normal file
|
|
@ -0,0 +1,130 @@
|
||||||
|
/*
|
||||||
|
Arduino.h - Main include file for the Arduino SDK
|
||||||
|
Copyright (c) 2014 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Arduino_h
|
||||||
|
#define Arduino_h
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
typedef bool boolean;
|
||||||
|
typedef uint8_t byte;
|
||||||
|
typedef uint16_t word;
|
||||||
|
|
||||||
|
// some libraries and sketches depend on this AVR stuff,
|
||||||
|
// assuming Arduino.h or WProgram.h automatically includes it...
|
||||||
|
//
|
||||||
|
#include "avr/pgmspace.h"
|
||||||
|
#include "avr/interrupt.h"
|
||||||
|
|
||||||
|
#include "binary.h"
|
||||||
|
#include "itoa.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"{
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
// Include Atmel headers
|
||||||
|
#include "sam.h"
|
||||||
|
|
||||||
|
#include "wiring_constants.h"
|
||||||
|
|
||||||
|
#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L )
|
||||||
|
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) )
|
||||||
|
#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) )
|
||||||
|
|
||||||
|
void yield( void ) ;
|
||||||
|
|
||||||
|
/* sketch */
|
||||||
|
void setup( void ) ;
|
||||||
|
void loop( void ) ;
|
||||||
|
|
||||||
|
#include "WVariant.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// The following headers are for C++ only compilation
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#include "WCharacter.h"
|
||||||
|
#include "WString.h"
|
||||||
|
#include "Tone.h"
|
||||||
|
#include "WMath.h"
|
||||||
|
#include "HardwareSerial.h"
|
||||||
|
#include "pulse.h"
|
||||||
|
#endif
|
||||||
|
#include "delay.h"
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#include "Uart.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Include board variant
|
||||||
|
#include "variant.h"
|
||||||
|
|
||||||
|
#include "wiring.h"
|
||||||
|
#include "wiring_digital.h"
|
||||||
|
#include "wiring_analog.h"
|
||||||
|
#include "wiring_shift.h"
|
||||||
|
#include "WInterrupts.h"
|
||||||
|
|
||||||
|
// undefine stdlib's abs if encountered
|
||||||
|
#ifdef abs
|
||||||
|
#undef abs
|
||||||
|
#endif // abs
|
||||||
|
|
||||||
|
#define min(a,b) ((a)<(b)?(a):(b))
|
||||||
|
#define max(a,b) ((a)>(b)?(a):(b))
|
||||||
|
#define abs(x) ((x)>0?(x):-(x))
|
||||||
|
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||||
|
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||||
|
#define radians(deg) ((deg)*DEG_TO_RAD)
|
||||||
|
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
||||||
|
#define sq(x) ((x)*(x))
|
||||||
|
|
||||||
|
#define interrupts() __enable_irq()
|
||||||
|
#define noInterrupts() __disable_irq()
|
||||||
|
|
||||||
|
#define lowByte(w) ((uint8_t) ((w) & 0xff))
|
||||||
|
#define highByte(w) ((uint8_t) ((w) >> 8))
|
||||||
|
|
||||||
|
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
||||||
|
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
|
||||||
|
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
|
||||||
|
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
|
||||||
|
|
||||||
|
#define bit(b) (1UL << (b))
|
||||||
|
|
||||||
|
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||||
|
// Interrupts
|
||||||
|
#define digitalPinToInterrupt(P) ( P )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// USB Device
|
||||||
|
#if !defined(__SAMD10D14AM__)
|
||||||
|
#include "USB/USBDesc.h"
|
||||||
|
#include "USB/USBCore.h"
|
||||||
|
#include "USB/USBAPI.h"
|
||||||
|
#include "USB/USB_host.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // Arduino_h
|
||||||
45
cores/samd10/Client.h
Normal file
45
cores/samd10/Client.h
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
Client.h - Base class that provides Client
|
||||||
|
Copyright (c) 2011 Adrian McEwen. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef client_h
|
||||||
|
#define client_h
|
||||||
|
#include "Print.h"
|
||||||
|
#include "Stream.h"
|
||||||
|
#include "IPAddress.h"
|
||||||
|
|
||||||
|
class Client : public Stream {
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual int connect(IPAddress ip, uint16_t port) =0;
|
||||||
|
virtual int connect(const char *host, uint16_t port) =0;
|
||||||
|
virtual size_t write(uint8_t) =0;
|
||||||
|
virtual size_t write(const uint8_t *buf, size_t size) =0;
|
||||||
|
virtual int available() = 0;
|
||||||
|
virtual int read() = 0;
|
||||||
|
virtual int read(uint8_t *buf, size_t size) = 0;
|
||||||
|
virtual int peek() = 0;
|
||||||
|
virtual void flush() = 0;
|
||||||
|
virtual void stop() = 0;
|
||||||
|
virtual uint8_t connected() = 0;
|
||||||
|
virtual operator bool() = 0;
|
||||||
|
protected:
|
||||||
|
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
84
cores/samd10/HardwareSerial.h
Normal file
84
cores/samd10/HardwareSerial.h
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HardwareSerial_h
|
||||||
|
#define HardwareSerial_h
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#include "Stream.h"
|
||||||
|
|
||||||
|
#define HARDSER_PARITY_EVEN (0x1ul)
|
||||||
|
#define HARDSER_PARITY_ODD (0x2ul)
|
||||||
|
#define HARDSER_PARITY_NONE (0x3ul)
|
||||||
|
#define HARDSER_PARITY_MASK (0xFul)
|
||||||
|
|
||||||
|
#define HARDSER_STOP_BIT_1 (0x10ul)
|
||||||
|
#define HARDSER_STOP_BIT_1_5 (0x20ul)
|
||||||
|
#define HARDSER_STOP_BIT_2 (0x30ul)
|
||||||
|
#define HARDSER_STOP_BIT_MASK (0xF0ul)
|
||||||
|
|
||||||
|
#define HARDSER_DATA_5 (0x100ul)
|
||||||
|
#define HARDSER_DATA_6 (0x200ul)
|
||||||
|
#define HARDSER_DATA_7 (0x300ul)
|
||||||
|
#define HARDSER_DATA_8 (0x400ul)
|
||||||
|
#define HARDSER_DATA_MASK (0xF00ul)
|
||||||
|
|
||||||
|
#define SERIAL_5N1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_NONE | HARDSER_DATA_5)
|
||||||
|
#define SERIAL_6N1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_NONE | HARDSER_DATA_6)
|
||||||
|
#define SERIAL_7N1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_NONE | HARDSER_DATA_7)
|
||||||
|
#define SERIAL_8N1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_NONE | HARDSER_DATA_8)
|
||||||
|
#define SERIAL_5N2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_NONE | HARDSER_DATA_5)
|
||||||
|
#define SERIAL_6N2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_NONE | HARDSER_DATA_6)
|
||||||
|
#define SERIAL_7N2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_NONE | HARDSER_DATA_7)
|
||||||
|
#define SERIAL_8N2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_NONE | HARDSER_DATA_8)
|
||||||
|
#define SERIAL_5E1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_EVEN | HARDSER_DATA_5)
|
||||||
|
#define SERIAL_6E1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_EVEN | HARDSER_DATA_6)
|
||||||
|
#define SERIAL_7E1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_EVEN | HARDSER_DATA_7)
|
||||||
|
#define SERIAL_8E1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_EVEN | HARDSER_DATA_8)
|
||||||
|
#define SERIAL_5E2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_EVEN | HARDSER_DATA_5)
|
||||||
|
#define SERIAL_6E2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_EVEN | HARDSER_DATA_6)
|
||||||
|
#define SERIAL_7E2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_EVEN | HARDSER_DATA_7)
|
||||||
|
#define SERIAL_8E2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_EVEN | HARDSER_DATA_8)
|
||||||
|
#define SERIAL_5O1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_ODD | HARDSER_DATA_5)
|
||||||
|
#define SERIAL_6O1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_ODD | HARDSER_DATA_6)
|
||||||
|
#define SERIAL_7O1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_ODD | HARDSER_DATA_7)
|
||||||
|
#define SERIAL_8O1 (HARDSER_STOP_BIT_1 | HARDSER_PARITY_ODD | HARDSER_DATA_8)
|
||||||
|
#define SERIAL_5O2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_ODD | HARDSER_DATA_5)
|
||||||
|
#define SERIAL_6O2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_ODD | HARDSER_DATA_6)
|
||||||
|
#define SERIAL_7O2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_ODD | HARDSER_DATA_7)
|
||||||
|
#define SERIAL_8O2 (HARDSER_STOP_BIT_2 | HARDSER_PARITY_ODD | HARDSER_DATA_8)
|
||||||
|
|
||||||
|
class HardwareSerial : public Stream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void begin(unsigned long);
|
||||||
|
virtual void begin(unsigned long baudrate, uint16_t config);
|
||||||
|
virtual void end();
|
||||||
|
virtual int available(void) = 0;
|
||||||
|
virtual int peek(void) = 0;
|
||||||
|
virtual int read(void) = 0;
|
||||||
|
virtual void flush(void) = 0;
|
||||||
|
virtual size_t write(uint8_t) = 0;
|
||||||
|
using Print::write; // pull in write(str) and write(buf, size) from Print
|
||||||
|
virtual operator bool() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void serialEventRun(void) __attribute__((weak));
|
||||||
|
|
||||||
|
#endif
|
||||||
116
cores/samd10/IPAddress.cpp
Normal file
116
cores/samd10/IPAddress.cpp
Normal file
|
|
@ -0,0 +1,116 @@
|
||||||
|
/*
|
||||||
|
IPAddress.cpp - Base class that provides IPAddress
|
||||||
|
Copyright (c) 2011 Adrian McEwen. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <IPAddress.h>
|
||||||
|
|
||||||
|
IPAddress::IPAddress()
|
||||||
|
{
|
||||||
|
_address.dword = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet)
|
||||||
|
{
|
||||||
|
_address.bytes[0] = first_octet;
|
||||||
|
_address.bytes[1] = second_octet;
|
||||||
|
_address.bytes[2] = third_octet;
|
||||||
|
_address.bytes[3] = fourth_octet;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPAddress::IPAddress(uint32_t address)
|
||||||
|
{
|
||||||
|
_address.dword = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPAddress::IPAddress(const uint8_t *address)
|
||||||
|
{
|
||||||
|
memcpy(_address.bytes, address, sizeof(_address.bytes));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPAddress::fromString(const char *address)
|
||||||
|
{
|
||||||
|
// TODO: add support for "a", "a.b", "a.b.c" formats
|
||||||
|
|
||||||
|
uint16_t acc = 0; // Accumulator
|
||||||
|
uint8_t dots = 0;
|
||||||
|
|
||||||
|
while (*address)
|
||||||
|
{
|
||||||
|
char c = *address++;
|
||||||
|
if (c >= '0' && c <= '9')
|
||||||
|
{
|
||||||
|
acc = acc * 10 + (c - '0');
|
||||||
|
if (acc > 255) {
|
||||||
|
// Value out of [0..255] range
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == '.')
|
||||||
|
{
|
||||||
|
if (dots == 3) {
|
||||||
|
// Too much dots (there must be 3 dots)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_address.bytes[dots++] = acc;
|
||||||
|
acc = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Invalid char
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dots != 3) {
|
||||||
|
// Too few dots (there must be 3 dots)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_address.bytes[3] = acc;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPAddress& IPAddress::operator=(const uint8_t *address)
|
||||||
|
{
|
||||||
|
memcpy(_address.bytes, address, sizeof(_address.bytes));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPAddress& IPAddress::operator=(uint32_t address)
|
||||||
|
{
|
||||||
|
_address.dword = address;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPAddress::operator==(const uint8_t* addr) const
|
||||||
|
{
|
||||||
|
return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t IPAddress::printTo(Print& p) const
|
||||||
|
{
|
||||||
|
size_t n = 0;
|
||||||
|
for (int i =0; i < 3; i++)
|
||||||
|
{
|
||||||
|
n += p.print(_address.bytes[i], DEC);
|
||||||
|
n += p.print('.');
|
||||||
|
}
|
||||||
|
n += p.print(_address.bytes[3], DEC);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
78
cores/samd10/IPAddress.h
Normal file
78
cores/samd10/IPAddress.h
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
IPAddress.h - Base class that provides IPAddress
|
||||||
|
Copyright (c) 2011 Adrian McEwen. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef IPAddress_h
|
||||||
|
#define IPAddress_h
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "Printable.h"
|
||||||
|
#include "WString.h"
|
||||||
|
|
||||||
|
// A class to make it easier to handle and pass around IP addresses
|
||||||
|
|
||||||
|
class IPAddress : public Printable {
|
||||||
|
private:
|
||||||
|
union {
|
||||||
|
uint8_t bytes[4]; // IPv4 address
|
||||||
|
uint32_t dword;
|
||||||
|
} _address;
|
||||||
|
|
||||||
|
// Access the raw byte array containing the address. Because this returns a pointer
|
||||||
|
// to the internal structure rather than a copy of the address this function should only
|
||||||
|
// be used when you know that the usage of the returned uint8_t* will be transient and not
|
||||||
|
// stored.
|
||||||
|
uint8_t* raw_address() { return _address.bytes; };
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructors
|
||||||
|
IPAddress();
|
||||||
|
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
|
||||||
|
IPAddress(uint32_t address);
|
||||||
|
IPAddress(const uint8_t *address);
|
||||||
|
|
||||||
|
bool fromString(const char *address);
|
||||||
|
bool fromString(const String &address) { return fromString(address.c_str()); }
|
||||||
|
|
||||||
|
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
|
||||||
|
// to a four-byte uint8_t array is expected
|
||||||
|
operator uint32_t() const { return _address.dword; };
|
||||||
|
bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; };
|
||||||
|
bool operator==(const uint8_t* addr) const;
|
||||||
|
|
||||||
|
// Overloaded index operator to allow getting and setting individual octets of the address
|
||||||
|
uint8_t operator[](int index) const { return _address.bytes[index]; };
|
||||||
|
uint8_t& operator[](int index) { return _address.bytes[index]; };
|
||||||
|
|
||||||
|
// Overloaded copy operators to allow initialisation of IPAddress objects from other types
|
||||||
|
IPAddress& operator=(const uint8_t *address);
|
||||||
|
IPAddress& operator=(uint32_t address);
|
||||||
|
|
||||||
|
virtual size_t printTo(Print& p) const;
|
||||||
|
|
||||||
|
friend class EthernetClass;
|
||||||
|
friend class UDP;
|
||||||
|
friend class Client;
|
||||||
|
friend class Server;
|
||||||
|
friend class DhcpClass;
|
||||||
|
friend class DNSClient;
|
||||||
|
};
|
||||||
|
|
||||||
|
const IPAddress INADDR_NONE(0,0,0,0);
|
||||||
|
|
||||||
|
#endif
|
||||||
254
cores/samd10/Print.cpp
Normal file
254
cores/samd10/Print.cpp
Normal file
|
|
@ -0,0 +1,254 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
#include "Print.h"
|
||||||
|
|
||||||
|
// Public Methods //////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/* default implementation: may be overridden */
|
||||||
|
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||||
|
{
|
||||||
|
size_t n = 0;
|
||||||
|
while (size--) {
|
||||||
|
if (write(*buffer++)) n++;
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::print(const __FlashStringHelper *ifsh)
|
||||||
|
{
|
||||||
|
return print(reinterpret_cast<const char *>(ifsh));
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::print(const String &s)
|
||||||
|
{
|
||||||
|
return write(s.c_str(), s.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::print(const char str[])
|
||||||
|
{
|
||||||
|
return write(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::print(char c)
|
||||||
|
{
|
||||||
|
return write(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::print(unsigned char b, int base)
|
||||||
|
{
|
||||||
|
return print((unsigned long) b, base);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::print(int n, int base)
|
||||||
|
{
|
||||||
|
return print((long) n, base);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::print(unsigned int n, int base)
|
||||||
|
{
|
||||||
|
return print((unsigned long) n, base);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::print(long n, int base)
|
||||||
|
{
|
||||||
|
if (base == 0) {
|
||||||
|
return write(n);
|
||||||
|
} else if (base == 10) {
|
||||||
|
if (n < 0) {
|
||||||
|
int t = print('-');
|
||||||
|
n = -n;
|
||||||
|
return printNumber(n, 10) + t;
|
||||||
|
}
|
||||||
|
return printNumber(n, 10);
|
||||||
|
} else {
|
||||||
|
return printNumber(n, base);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::print(unsigned long n, int base)
|
||||||
|
{
|
||||||
|
if (base == 0) return write(n);
|
||||||
|
else return printNumber(n, base);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::print(double n, int digits)
|
||||||
|
{
|
||||||
|
return printFloat(n, digits);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::println(const __FlashStringHelper *ifsh)
|
||||||
|
{
|
||||||
|
size_t n = print(ifsh);
|
||||||
|
n += println();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::print(const Printable& x)
|
||||||
|
{
|
||||||
|
return x.printTo(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::println(void)
|
||||||
|
{
|
||||||
|
return write("\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::println(const String &s)
|
||||||
|
{
|
||||||
|
size_t n = print(s);
|
||||||
|
n += println();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::println(const char c[])
|
||||||
|
{
|
||||||
|
size_t n = print(c);
|
||||||
|
n += println();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::println(char c)
|
||||||
|
{
|
||||||
|
size_t n = print(c);
|
||||||
|
n += println();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::println(unsigned char b, int base)
|
||||||
|
{
|
||||||
|
size_t n = print(b, base);
|
||||||
|
n += println();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::println(int num, int base)
|
||||||
|
{
|
||||||
|
size_t n = print(num, base);
|
||||||
|
n += println();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::println(unsigned int num, int base)
|
||||||
|
{
|
||||||
|
size_t n = print(num, base);
|
||||||
|
n += println();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::println(long num, int base)
|
||||||
|
{
|
||||||
|
size_t n = print(num, base);
|
||||||
|
n += println();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::println(unsigned long num, int base)
|
||||||
|
{
|
||||||
|
size_t n = print(num, base);
|
||||||
|
n += println();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::println(double num, int digits)
|
||||||
|
{
|
||||||
|
size_t n = print(num, digits);
|
||||||
|
n += println();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::println(const Printable& x)
|
||||||
|
{
|
||||||
|
size_t n = print(x);
|
||||||
|
n += println();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Private Methods /////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||||
|
{
|
||||||
|
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
|
*str = '\0';
|
||||||
|
|
||||||
|
// prevent crash if called with base == 1
|
||||||
|
if (base < 2) base = 10;
|
||||||
|
|
||||||
|
do {
|
||||||
|
char c = n % base;
|
||||||
|
n /= base;
|
||||||
|
|
||||||
|
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||||
|
} while(n);
|
||||||
|
|
||||||
|
return write(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Print::printFloat(double number, uint8_t digits)
|
||||||
|
{
|
||||||
|
size_t n = 0;
|
||||||
|
|
||||||
|
if (isnan(number)) return print("nan");
|
||||||
|
if (isinf(number)) return print("inf");
|
||||||
|
if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
|
||||||
|
if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
|
// Handle negative numbers
|
||||||
|
if (number < 0.0)
|
||||||
|
{
|
||||||
|
n += print('-');
|
||||||
|
number = -number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||||
|
double rounding = 0.5;
|
||||||
|
for (uint8_t i=0; i<digits; ++i)
|
||||||
|
rounding /= 10.0;
|
||||||
|
|
||||||
|
number += rounding;
|
||||||
|
|
||||||
|
// Extract the integer part of the number and print it
|
||||||
|
unsigned long int_part = (unsigned long)number;
|
||||||
|
double remainder = number - (double)int_part;
|
||||||
|
n += print(int_part);
|
||||||
|
|
||||||
|
// Print the decimal point, but only if there are digits beyond
|
||||||
|
if (digits > 0) {
|
||||||
|
n += print(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract digits from the remainder one at a time
|
||||||
|
while (digits-- > 0)
|
||||||
|
{
|
||||||
|
remainder *= 10.0;
|
||||||
|
int toPrint = int(remainder);
|
||||||
|
n += print(toPrint);
|
||||||
|
remainder -= toPrint;
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
83
cores/samd10/Print.h
Normal file
83
cores/samd10/Print.h
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Print_h
|
||||||
|
#define Print_h
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h> // for size_t
|
||||||
|
|
||||||
|
#include "WString.h"
|
||||||
|
#include "Printable.h"
|
||||||
|
|
||||||
|
#define DEC 10
|
||||||
|
#define HEX 16
|
||||||
|
#define OCT 8
|
||||||
|
#define BIN 2
|
||||||
|
|
||||||
|
class Print
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
int write_error;
|
||||||
|
size_t printNumber(unsigned long, uint8_t);
|
||||||
|
size_t printFloat(double, uint8_t);
|
||||||
|
protected:
|
||||||
|
void setWriteError(int err = 1) { write_error = err; }
|
||||||
|
public:
|
||||||
|
Print() : write_error(0) {}
|
||||||
|
|
||||||
|
int getWriteError() { return write_error; }
|
||||||
|
void clearWriteError() { setWriteError(0); }
|
||||||
|
|
||||||
|
virtual size_t write(uint8_t) = 0;
|
||||||
|
size_t write(const char *str) {
|
||||||
|
if (str == NULL) return 0;
|
||||||
|
return write((const uint8_t *)str, strlen(str));
|
||||||
|
}
|
||||||
|
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||||
|
size_t write(const char *buffer, size_t size) {
|
||||||
|
return write((const uint8_t *)buffer, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t print(const __FlashStringHelper *);
|
||||||
|
size_t print(const String &);
|
||||||
|
size_t print(const char[]);
|
||||||
|
size_t print(char);
|
||||||
|
size_t print(unsigned char, int = DEC);
|
||||||
|
size_t print(int, int = DEC);
|
||||||
|
size_t print(unsigned int, int = DEC);
|
||||||
|
size_t print(long, int = DEC);
|
||||||
|
size_t print(unsigned long, int = DEC);
|
||||||
|
size_t print(double, int = 2);
|
||||||
|
size_t print(const Printable&);
|
||||||
|
|
||||||
|
size_t println(const __FlashStringHelper *);
|
||||||
|
size_t println(const String &s);
|
||||||
|
size_t println(const char[]);
|
||||||
|
size_t println(char);
|
||||||
|
size_t println(unsigned char, int = DEC);
|
||||||
|
size_t println(int, int = DEC);
|
||||||
|
size_t println(unsigned int, int = DEC);
|
||||||
|
size_t println(long, int = DEC);
|
||||||
|
size_t println(unsigned long, int = DEC);
|
||||||
|
size_t println(double, int = 2);
|
||||||
|
size_t println(const Printable&);
|
||||||
|
size_t println(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
39
cores/samd10/Printable.h
Normal file
39
cores/samd10/Printable.h
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Printable_h
|
||||||
|
#define Printable_h
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
class Print;
|
||||||
|
|
||||||
|
/** The Printable class provides a way for new classes to allow themselves to be printed.
|
||||||
|
By deriving from Printable and implementing the printTo method, it will then be possible
|
||||||
|
for users to print out instances of this class by passing them into the usual
|
||||||
|
Print::print and Print::println methods.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Printable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual size_t printTo(Print& p) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
73
cores/samd10/Reset.cpp
Normal file
73
cores/samd10/Reset.cpp
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "Reset.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define NVM_MEMORY ((volatile uint16_t *)0x000000)
|
||||||
|
#define APP_START 0x00002004
|
||||||
|
|
||||||
|
static inline bool nvmReady(void) {
|
||||||
|
return NVMCTRL->INTFLAG.reg & NVMCTRL_INTFLAG_READY;
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((long_call, section (".ramfunc")))
|
||||||
|
static void banzai() {
|
||||||
|
// Disable all interrupts
|
||||||
|
__disable_irq();
|
||||||
|
|
||||||
|
// Erase application
|
||||||
|
while (!nvmReady())
|
||||||
|
;
|
||||||
|
NVMCTRL->STATUS.reg |= NVMCTRL_STATUS_MASK;
|
||||||
|
NVMCTRL->ADDR.reg = (uintptr_t)&NVM_MEMORY[APP_START / 4];
|
||||||
|
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMD_ER | NVMCTRL_CTRLA_CMDEX_KEY;
|
||||||
|
while (!nvmReady())
|
||||||
|
;
|
||||||
|
|
||||||
|
// Reset the device
|
||||||
|
NVIC_SystemReset() ;
|
||||||
|
|
||||||
|
while (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ticks = -1;
|
||||||
|
|
||||||
|
void initiateReset(int _ticks) {
|
||||||
|
ticks = _ticks;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cancelReset() {
|
||||||
|
ticks = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tickReset() {
|
||||||
|
if (ticks == -1)
|
||||||
|
return;
|
||||||
|
ticks--;
|
||||||
|
if (ticks == 0)
|
||||||
|
banzai();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
31
cores/samd10/Reset.h
Normal file
31
cores/samd10/Reset.h
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void initiateReset(int ms);
|
||||||
|
void tickReset();
|
||||||
|
void cancelReset();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
86
cores/samd10/RingBuffer.cpp
Normal file
86
cores/samd10/RingBuffer.cpp
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "RingBuffer.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
RingBuffer::RingBuffer( void )
|
||||||
|
{
|
||||||
|
memset( _aucBuffer, 0, SERIAL_BUFFER_SIZE ) ;
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RingBuffer::store_char( uint8_t c )
|
||||||
|
{
|
||||||
|
int i = nextIndex(_iHead);
|
||||||
|
|
||||||
|
// if we should be storing the received character into the location
|
||||||
|
// just before the tail (meaning that the head would advance to the
|
||||||
|
// current location of the tail), we're about to overflow the buffer
|
||||||
|
// and so we don't write the character or advance the head.
|
||||||
|
if ( i != _iTail )
|
||||||
|
{
|
||||||
|
_aucBuffer[_iHead] = c ;
|
||||||
|
_iHead = i ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RingBuffer::clear()
|
||||||
|
{
|
||||||
|
_iHead = 0;
|
||||||
|
_iTail = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int RingBuffer::read_char()
|
||||||
|
{
|
||||||
|
if(_iTail == _iHead)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
uint8_t value = _aucBuffer[_iTail];
|
||||||
|
_iTail = nextIndex(_iTail);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int RingBuffer::available()
|
||||||
|
{
|
||||||
|
int delta = _iHead - _iTail;
|
||||||
|
|
||||||
|
if(delta < 0)
|
||||||
|
return SERIAL_BUFFER_SIZE + delta;
|
||||||
|
else
|
||||||
|
return delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
int RingBuffer::peek()
|
||||||
|
{
|
||||||
|
if(_iTail == _iHead)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return _aucBuffer[_iTail];
|
||||||
|
}
|
||||||
|
|
||||||
|
int RingBuffer::nextIndex(int index)
|
||||||
|
{
|
||||||
|
return (uint32_t)(index + 1) % SERIAL_BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RingBuffer::isFull()
|
||||||
|
{
|
||||||
|
return (nextIndex(_iHead) == _iTail);
|
||||||
|
}
|
||||||
50
cores/samd10/RingBuffer.h
Normal file
50
cores/samd10/RingBuffer.h
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _RING_BUFFER_
|
||||||
|
#define _RING_BUFFER_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// Define constants and variables for buffering incoming serial data. We're
|
||||||
|
// using a ring buffer (I think), in which head is the index of the location
|
||||||
|
// to which to write the next incoming character and tail is the index of the
|
||||||
|
// location from which to read.
|
||||||
|
#define SERIAL_BUFFER_SIZE 64
|
||||||
|
|
||||||
|
class RingBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
uint8_t _aucBuffer[SERIAL_BUFFER_SIZE] ;
|
||||||
|
int _iHead ;
|
||||||
|
int _iTail ;
|
||||||
|
|
||||||
|
public:
|
||||||
|
RingBuffer( void ) ;
|
||||||
|
void store_char( uint8_t c ) ;
|
||||||
|
void clear();
|
||||||
|
int read_char();
|
||||||
|
int available();
|
||||||
|
int peek();
|
||||||
|
bool isFull();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int nextIndex(int index);
|
||||||
|
} ;
|
||||||
|
|
||||||
|
#endif /* _RING_BUFFER_ */
|
||||||
700
cores/samd10/SERCOM.cpp
Normal file
700
cores/samd10/SERCOM.cpp
Normal file
|
|
@ -0,0 +1,700 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "SERCOM.h"
|
||||||
|
#include "variant.h"
|
||||||
|
|
||||||
|
SERCOM::SERCOM(Sercom* s)
|
||||||
|
{
|
||||||
|
sercom = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
* ===== Sercom UART
|
||||||
|
* =========================
|
||||||
|
*/
|
||||||
|
void SERCOM::initUART(SercomUartMode mode, SercomUartSampleRate sampleRate, uint32_t baudrate)
|
||||||
|
{
|
||||||
|
initClockNVIC();
|
||||||
|
resetUART();
|
||||||
|
|
||||||
|
//Setting the CTRLA register
|
||||||
|
sercom->USART.CTRLA.reg = SERCOM_USART_CTRLA_MODE(mode) |
|
||||||
|
SERCOM_USART_CTRLA_SAMPR(sampleRate);
|
||||||
|
|
||||||
|
//Setting the Interrupt register
|
||||||
|
sercom->USART.INTENSET.reg = SERCOM_USART_INTENSET_RXC | //Received complete
|
||||||
|
SERCOM_USART_INTENSET_ERROR; //All others errors
|
||||||
|
|
||||||
|
if ( mode == UART_INT_CLOCK )
|
||||||
|
{
|
||||||
|
uint16_t sampleRateValue;
|
||||||
|
|
||||||
|
if (sampleRate == SAMPLE_RATE_x16) {
|
||||||
|
sampleRateValue = 16;
|
||||||
|
} else {
|
||||||
|
sampleRateValue = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asynchronous fractional mode (Table 24-2 in datasheet)
|
||||||
|
// BAUD = fref / (sampleRateValue * fbaud)
|
||||||
|
// (multiply by 8, to calculate fractional piece)
|
||||||
|
uint32_t baudTimes8 = (SystemCoreClock * 8) / (sampleRateValue * baudrate);
|
||||||
|
|
||||||
|
sercom->USART.BAUD.FRAC.FP = (baudTimes8 % 8);
|
||||||
|
sercom->USART.BAUD.FRAC.BAUD = (baudTimes8 / 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void SERCOM::initFrame(SercomUartCharSize charSize, SercomDataOrder dataOrder, SercomParityMode parityMode, SercomNumberStopBit nbStopBits)
|
||||||
|
{
|
||||||
|
//Setting the CTRLA register
|
||||||
|
sercom->USART.CTRLA.reg |= SERCOM_USART_CTRLA_FORM( (parityMode == SERCOM_NO_PARITY ? 0 : 1) ) |
|
||||||
|
dataOrder << SERCOM_USART_CTRLA_DORD_Pos;
|
||||||
|
|
||||||
|
//Setting the CTRLB register
|
||||||
|
sercom->USART.CTRLB.reg |= SERCOM_USART_CTRLB_CHSIZE(charSize) |
|
||||||
|
nbStopBits << SERCOM_USART_CTRLB_SBMODE_Pos |
|
||||||
|
(parityMode == SERCOM_NO_PARITY ? 0 : parityMode) << SERCOM_USART_CTRLB_PMODE_Pos; //If no parity use default value
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::initPads(SercomUartTXPad txPad, SercomRXPad rxPad)
|
||||||
|
{
|
||||||
|
//Setting the CTRLA register
|
||||||
|
sercom->USART.CTRLA.reg |= SERCOM_USART_CTRLA_TXPO(txPad) |
|
||||||
|
SERCOM_USART_CTRLA_RXPO(rxPad);
|
||||||
|
|
||||||
|
// Enable Transceiver and Receiver
|
||||||
|
sercom->USART.CTRLB.reg |= SERCOM_USART_CTRLB_TXEN | SERCOM_USART_CTRLB_RXEN ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::resetUART()
|
||||||
|
{
|
||||||
|
// Start the Software Reset
|
||||||
|
sercom->USART.CTRLA.bit.SWRST = 1 ;
|
||||||
|
|
||||||
|
while ( sercom->USART.CTRLA.bit.SWRST || sercom->USART.SYNCBUSY.bit.SWRST )
|
||||||
|
{
|
||||||
|
// Wait for both bits Software Reset from CTRLA and SYNCBUSY coming back to 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::enableUART()
|
||||||
|
{
|
||||||
|
//Setting the enable bit to 1
|
||||||
|
sercom->USART.CTRLA.bit.ENABLE = 0x1u;
|
||||||
|
|
||||||
|
//Wait for then enable bit from SYNCBUSY is equal to 0;
|
||||||
|
while(sercom->USART.SYNCBUSY.bit.ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::flushUART()
|
||||||
|
{
|
||||||
|
// Wait for transmission to complete
|
||||||
|
while(!sercom->USART.INTFLAG.bit.TXC);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::clearStatusUART()
|
||||||
|
{
|
||||||
|
//Reset (with 0) the STATUS register
|
||||||
|
sercom->USART.STATUS.reg = SERCOM_USART_STATUS_RESETVALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::availableDataUART()
|
||||||
|
{
|
||||||
|
//RXC : Receive Complete
|
||||||
|
return sercom->USART.INTFLAG.bit.RXC;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isUARTError()
|
||||||
|
{
|
||||||
|
return sercom->USART.INTFLAG.bit.ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::acknowledgeUARTError()
|
||||||
|
{
|
||||||
|
sercom->USART.INTFLAG.bit.ERROR = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isBufferOverflowErrorUART()
|
||||||
|
{
|
||||||
|
//BUFOVF : Buffer Overflow
|
||||||
|
return sercom->USART.STATUS.bit.BUFOVF;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isFrameErrorUART()
|
||||||
|
{
|
||||||
|
//FERR : Frame Error
|
||||||
|
return sercom->USART.STATUS.bit.FERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isParityErrorUART()
|
||||||
|
{
|
||||||
|
//PERR : Parity Error
|
||||||
|
return sercom->USART.STATUS.bit.PERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isDataRegisterEmptyUART()
|
||||||
|
{
|
||||||
|
//DRE : Data Register Empty
|
||||||
|
return sercom->USART.INTFLAG.bit.DRE;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t SERCOM::readDataUART()
|
||||||
|
{
|
||||||
|
return sercom->USART.DATA.bit.DATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SERCOM::writeDataUART(uint8_t data)
|
||||||
|
{
|
||||||
|
// Wait for data register to be empty
|
||||||
|
while(!isDataRegisterEmptyUART());
|
||||||
|
|
||||||
|
//Put data into DATA register
|
||||||
|
sercom->USART.DATA.reg = (uint16_t)data;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
* ===== Sercom SPI
|
||||||
|
* =========================
|
||||||
|
*/
|
||||||
|
void SERCOM::initSPI(SercomSpiTXPad mosi, SercomRXPad miso, SercomSpiCharSize charSize, SercomDataOrder dataOrder)
|
||||||
|
{
|
||||||
|
resetSPI();
|
||||||
|
initClockNVIC();
|
||||||
|
|
||||||
|
//Setting the CTRLA register
|
||||||
|
sercom->SPI.CTRLA.reg = SERCOM_SPI_CTRLA_MODE_SPI_MASTER |
|
||||||
|
SERCOM_SPI_CTRLA_DOPO(mosi) |
|
||||||
|
SERCOM_SPI_CTRLA_DIPO(miso) |
|
||||||
|
dataOrder << SERCOM_SPI_CTRLA_DORD_Pos;
|
||||||
|
|
||||||
|
//Setting the CTRLB register
|
||||||
|
sercom->SPI.CTRLB.reg = SERCOM_SPI_CTRLB_CHSIZE(charSize) |
|
||||||
|
SERCOM_SPI_CTRLB_RXEN; //Active the SPI receiver.
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::initSPIClock(SercomSpiClockMode clockMode, uint32_t baudrate)
|
||||||
|
{
|
||||||
|
//Extract data from clockMode
|
||||||
|
int cpha, cpol;
|
||||||
|
|
||||||
|
if((clockMode & (0x1ul)) == 0 )
|
||||||
|
cpha = 0;
|
||||||
|
else
|
||||||
|
cpha = 1;
|
||||||
|
|
||||||
|
if((clockMode & (0x2ul)) == 0)
|
||||||
|
cpol = 0;
|
||||||
|
else
|
||||||
|
cpol = 1;
|
||||||
|
|
||||||
|
//Setting the CTRLA register
|
||||||
|
sercom->SPI.CTRLA.reg |= ( cpha << SERCOM_SPI_CTRLA_CPHA_Pos ) |
|
||||||
|
( cpol << SERCOM_SPI_CTRLA_CPOL_Pos );
|
||||||
|
|
||||||
|
//Synchronous arithmetic
|
||||||
|
sercom->SPI.BAUD.reg = calculateBaudrateSynchronous(baudrate);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::resetSPI()
|
||||||
|
{
|
||||||
|
//Setting the Software Reset bit to 1
|
||||||
|
sercom->SPI.CTRLA.bit.SWRST = 1;
|
||||||
|
|
||||||
|
//Wait both bits Software Reset from CTRLA and SYNCBUSY are equal to 0
|
||||||
|
while(sercom->SPI.CTRLA.bit.SWRST || sercom->SPI.SYNCBUSY.bit.SWRST);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::enableSPI()
|
||||||
|
{
|
||||||
|
//Setting the enable bit to 1
|
||||||
|
sercom->SPI.CTRLA.bit.ENABLE = 1;
|
||||||
|
|
||||||
|
while(sercom->SPI.SYNCBUSY.bit.ENABLE)
|
||||||
|
{
|
||||||
|
//Waiting then enable bit from SYNCBUSY is equal to 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::disableSPI()
|
||||||
|
{
|
||||||
|
//Setting the enable bit to 0
|
||||||
|
sercom->SPI.CTRLA.bit.ENABLE = 0;
|
||||||
|
|
||||||
|
while(sercom->SPI.SYNCBUSY.bit.ENABLE)
|
||||||
|
{
|
||||||
|
//Waiting then enable bit from SYNCBUSY is equal to 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::setDataOrderSPI(SercomDataOrder dataOrder)
|
||||||
|
{
|
||||||
|
//Register enable-protected
|
||||||
|
disableSPI();
|
||||||
|
|
||||||
|
sercom->SPI.CTRLA.bit.DORD = dataOrder;
|
||||||
|
|
||||||
|
enableSPI();
|
||||||
|
}
|
||||||
|
|
||||||
|
SercomDataOrder SERCOM::getDataOrderSPI()
|
||||||
|
{
|
||||||
|
return (sercom->SPI.CTRLA.bit.DORD ? LSB_FIRST : MSB_FIRST);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::setBaudrateSPI(uint8_t divider)
|
||||||
|
{
|
||||||
|
//Can't divide by 0
|
||||||
|
if(divider == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//Register enable-protected
|
||||||
|
disableSPI();
|
||||||
|
|
||||||
|
sercom->SPI.BAUD.reg = calculateBaudrateSynchronous( SERCOM_FREQ_REF / divider );
|
||||||
|
|
||||||
|
enableSPI();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::setClockModeSPI(SercomSpiClockMode clockMode)
|
||||||
|
{
|
||||||
|
int cpha, cpol;
|
||||||
|
if((clockMode & (0x1ul)) == 0)
|
||||||
|
cpha = 0;
|
||||||
|
else
|
||||||
|
cpha = 1;
|
||||||
|
|
||||||
|
if((clockMode & (0x2ul)) == 0)
|
||||||
|
cpol = 0;
|
||||||
|
else
|
||||||
|
cpol = 1;
|
||||||
|
|
||||||
|
//Register enable-protected
|
||||||
|
disableSPI();
|
||||||
|
|
||||||
|
sercom->SPI.CTRLA.bit.CPOL = cpol;
|
||||||
|
sercom->SPI.CTRLA.bit.CPHA = cpha;
|
||||||
|
|
||||||
|
enableSPI();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::writeDataSPI(uint8_t data)
|
||||||
|
{
|
||||||
|
while( sercom->SPI.INTFLAG.bit.DRE == 0 )
|
||||||
|
{
|
||||||
|
// Waiting Data Registry Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
sercom->SPI.DATA.bit.DATA = data; // Writing data into Data register
|
||||||
|
|
||||||
|
while( sercom->SPI.INTFLAG.bit.TXC == 0 || sercom->SPI.INTFLAG.bit.DRE == 0 )
|
||||||
|
{
|
||||||
|
// Waiting Complete Transmission
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t SERCOM::readDataSPI()
|
||||||
|
{
|
||||||
|
while( sercom->SPI.INTFLAG.bit.DRE == 0 || sercom->SPI.INTFLAG.bit.RXC == 0 )
|
||||||
|
{
|
||||||
|
// Waiting Complete Reception
|
||||||
|
}
|
||||||
|
|
||||||
|
return sercom->SPI.DATA.bit.DATA; // Reading data
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isBufferOverflowErrorSPI()
|
||||||
|
{
|
||||||
|
return sercom->SPI.STATUS.bit.BUFOVF;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isDataRegisterEmptySPI()
|
||||||
|
{
|
||||||
|
//DRE : Data Register Empty
|
||||||
|
return sercom->SPI.INTFLAG.bit.DRE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//bool SERCOM::isTransmitCompleteSPI()
|
||||||
|
//{
|
||||||
|
// //TXC : Transmit complete
|
||||||
|
// return sercom->SPI.INTFLAG.bit.TXC;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//bool SERCOM::isReceiveCompleteSPI()
|
||||||
|
//{
|
||||||
|
// //RXC : Receive complete
|
||||||
|
// return sercom->SPI.INTFLAG.bit.RXC;
|
||||||
|
//}
|
||||||
|
|
||||||
|
uint8_t SERCOM::calculateBaudrateSynchronous(uint32_t baudrate)
|
||||||
|
{
|
||||||
|
return SERCOM_FREQ_REF / (2 * baudrate) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
* ===== Sercom WIRE
|
||||||
|
* =========================
|
||||||
|
*/
|
||||||
|
void SERCOM::resetWIRE()
|
||||||
|
{
|
||||||
|
//I2CM OR I2CS, no matter SWRST is the same bit.
|
||||||
|
|
||||||
|
//Setting the Software bit to 1
|
||||||
|
sercom->I2CM.CTRLA.bit.SWRST = 1;
|
||||||
|
|
||||||
|
//Wait both bits Software Reset from CTRLA and SYNCBUSY are equal to 0
|
||||||
|
while(sercom->I2CM.CTRLA.bit.SWRST || sercom->I2CM.SYNCBUSY.bit.SWRST);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::enableWIRE()
|
||||||
|
{
|
||||||
|
// I2C Master and Slave modes share the ENABLE bit function.
|
||||||
|
|
||||||
|
// Enable the I²C master mode
|
||||||
|
sercom->I2CM.CTRLA.bit.ENABLE = 1 ;
|
||||||
|
|
||||||
|
while ( sercom->I2CM.SYNCBUSY.bit.ENABLE != 0 )
|
||||||
|
{
|
||||||
|
// Waiting the enable bit from SYNCBUSY is equal to 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setting bus idle mode
|
||||||
|
sercom->I2CM.STATUS.bit.BUSSTATE = 1 ;
|
||||||
|
|
||||||
|
while ( sercom->I2CM.SYNCBUSY.bit.SYSOP != 0 )
|
||||||
|
{
|
||||||
|
// Wait the SYSOP bit from SYNCBUSY coming back to 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::disableWIRE()
|
||||||
|
{
|
||||||
|
// I2C Master and Slave modes share the ENABLE bit function.
|
||||||
|
|
||||||
|
// Enable the I²C master mode
|
||||||
|
sercom->I2CM.CTRLA.bit.ENABLE = 0 ;
|
||||||
|
|
||||||
|
while ( sercom->I2CM.SYNCBUSY.bit.ENABLE != 0 )
|
||||||
|
{
|
||||||
|
// Waiting the enable bit from SYNCBUSY is equal to 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::initSlaveWIRE( uint8_t ucAddress )
|
||||||
|
{
|
||||||
|
// Initialize the peripheral clock and interruption
|
||||||
|
initClockNVIC() ;
|
||||||
|
resetWIRE() ;
|
||||||
|
|
||||||
|
// Set slave mode
|
||||||
|
sercom->I2CS.CTRLA.bit.MODE = I2C_SLAVE_OPERATION ;
|
||||||
|
|
||||||
|
sercom->I2CS.ADDR.reg = SERCOM_I2CS_ADDR_ADDR( ucAddress & 0x7Ful ) | // 0x7F, select only 7 bits
|
||||||
|
SERCOM_I2CS_ADDR_ADDRMASK( 0x00ul ) ; // 0x00, only match exact address
|
||||||
|
|
||||||
|
// Set the interrupt register
|
||||||
|
sercom->I2CS.INTENSET.reg = SERCOM_I2CS_INTENSET_PREC | // Stop
|
||||||
|
SERCOM_I2CS_INTENSET_AMATCH | // Address Match
|
||||||
|
SERCOM_I2CS_INTENSET_DRDY ; // Data Ready
|
||||||
|
|
||||||
|
while ( sercom->I2CM.SYNCBUSY.bit.SYSOP != 0 )
|
||||||
|
{
|
||||||
|
// Wait the SYSOP bit from SYNCBUSY to come back to 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::initMasterWIRE( uint32_t baudrate )
|
||||||
|
{
|
||||||
|
// Initialize the peripheral clock and interruption
|
||||||
|
initClockNVIC() ;
|
||||||
|
|
||||||
|
resetWIRE() ;
|
||||||
|
|
||||||
|
// Set master mode and enable SCL Clock Stretch mode (stretch after ACK bit)
|
||||||
|
sercom->I2CM.CTRLA.reg = SERCOM_I2CM_CTRLA_MODE( I2C_MASTER_OPERATION )/* |
|
||||||
|
SERCOM_I2CM_CTRLA_SCLSM*/ ;
|
||||||
|
|
||||||
|
// Enable Smart mode and Quick Command
|
||||||
|
//sercom->I2CM.CTRLB.reg = SERCOM_I2CM_CTRLB_SMEN /*| SERCOM_I2CM_CTRLB_QCEN*/ ;
|
||||||
|
|
||||||
|
|
||||||
|
// Enable all interrupts
|
||||||
|
// sercom->I2CM.INTENSET.reg = SERCOM_I2CM_INTENSET_MB | SERCOM_I2CM_INTENSET_SB | SERCOM_I2CM_INTENSET_ERROR ;
|
||||||
|
|
||||||
|
// Synchronous arithmetic baudrate
|
||||||
|
sercom->I2CM.BAUD.bit.BAUD = SystemCoreClock / ( 2 * baudrate) - 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::prepareNackBitWIRE( void )
|
||||||
|
{
|
||||||
|
if(isMasterWIRE()) {
|
||||||
|
// Send a NACK
|
||||||
|
sercom->I2CM.CTRLB.bit.ACKACT = 1;
|
||||||
|
} else {
|
||||||
|
sercom->I2CS.CTRLB.bit.ACKACT = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::prepareAckBitWIRE( void )
|
||||||
|
{
|
||||||
|
if(isMasterWIRE()) {
|
||||||
|
// Send an ACK
|
||||||
|
sercom->I2CM.CTRLB.bit.ACKACT = 0;
|
||||||
|
} else {
|
||||||
|
sercom->I2CS.CTRLB.bit.ACKACT = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SERCOM::prepareCommandBitsWire(uint8_t cmd)
|
||||||
|
{
|
||||||
|
if(isMasterWIRE()) {
|
||||||
|
sercom->I2CM.CTRLB.bit.CMD = cmd;
|
||||||
|
|
||||||
|
while(sercom->I2CM.SYNCBUSY.bit.SYSOP)
|
||||||
|
{
|
||||||
|
// Waiting for synchronization
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sercom->I2CS.CTRLB.bit.CMD = cmd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::startTransmissionWIRE(uint8_t address, SercomWireReadWriteFlag flag)
|
||||||
|
{
|
||||||
|
// 7-bits address + 1-bits R/W
|
||||||
|
address = (address << 0x1ul) | flag;
|
||||||
|
|
||||||
|
// Wait idle or owner bus mode
|
||||||
|
while ( !isBusIdleWIRE() && !isBusOwnerWIRE() );
|
||||||
|
|
||||||
|
// Send start and address
|
||||||
|
sercom->I2CM.ADDR.bit.ADDR = address;
|
||||||
|
|
||||||
|
// Address Transmitted
|
||||||
|
if ( flag == WIRE_WRITE_FLAG ) // Write mode
|
||||||
|
{
|
||||||
|
while( !sercom->I2CM.INTFLAG.bit.MB )
|
||||||
|
{
|
||||||
|
// Wait transmission complete
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // Read mode
|
||||||
|
{
|
||||||
|
while( !sercom->I2CM.INTFLAG.bit.SB )
|
||||||
|
{
|
||||||
|
// If the slave NACKS the address, the MB bit will be set.
|
||||||
|
// In that case, send a stop condition and return false.
|
||||||
|
if (sercom->I2CM.INTFLAG.bit.MB) {
|
||||||
|
sercom->I2CM.CTRLB.bit.CMD = 3; // Stop condition
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Wait transmission complete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean the 'Slave on Bus' flag, for further usage.
|
||||||
|
//sercom->I2CM.INTFLAG.bit.SB = 0x1ul;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//ACK received (0: ACK, 1: NACK)
|
||||||
|
if(sercom->I2CM.STATUS.bit.RXNACK)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::sendDataMasterWIRE(uint8_t data)
|
||||||
|
{
|
||||||
|
//Send data
|
||||||
|
sercom->I2CM.DATA.bit.DATA = data;
|
||||||
|
|
||||||
|
//Wait transmission successful
|
||||||
|
while(!sercom->I2CM.INTFLAG.bit.MB) {
|
||||||
|
|
||||||
|
// If a bus error occurs, the MB bit may never be set.
|
||||||
|
// Check the bus error bit and bail if it's set.
|
||||||
|
if (sercom->I2CM.STATUS.bit.BUSERR) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Problems on line? nack received?
|
||||||
|
if(sercom->I2CM.STATUS.bit.RXNACK)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::sendDataSlaveWIRE(uint8_t data)
|
||||||
|
{
|
||||||
|
//Send data
|
||||||
|
sercom->I2CS.DATA.bit.DATA = data;
|
||||||
|
|
||||||
|
//Wait data transmission successful
|
||||||
|
while(!sercom->I2CS.INTFLAG.bit.DRDY);
|
||||||
|
|
||||||
|
//Problems on line? nack received?
|
||||||
|
if(sercom->I2CS.STATUS.bit.RXNACK)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isMasterWIRE( void )
|
||||||
|
{
|
||||||
|
return sercom->I2CS.CTRLA.bit.MODE == I2C_MASTER_OPERATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isSlaveWIRE( void )
|
||||||
|
{
|
||||||
|
return sercom->I2CS.CTRLA.bit.MODE == I2C_SLAVE_OPERATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isBusIdleWIRE( void )
|
||||||
|
{
|
||||||
|
return sercom->I2CM.STATUS.bit.BUSSTATE == WIRE_IDLE_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isBusOwnerWIRE( void )
|
||||||
|
{
|
||||||
|
return sercom->I2CM.STATUS.bit.BUSSTATE == WIRE_OWNER_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isDataReadyWIRE( void )
|
||||||
|
{
|
||||||
|
return sercom->I2CS.INTFLAG.bit.DRDY;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isStopDetectedWIRE( void )
|
||||||
|
{
|
||||||
|
return sercom->I2CS.INTFLAG.bit.PREC;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isRestartDetectedWIRE( void )
|
||||||
|
{
|
||||||
|
return sercom->I2CS.STATUS.bit.SR;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isAddressMatch( void )
|
||||||
|
{
|
||||||
|
return sercom->I2CS.INTFLAG.bit.AMATCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isMasterReadOperationWIRE( void )
|
||||||
|
{
|
||||||
|
return sercom->I2CS.STATUS.bit.DIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SERCOM::isRXNackReceivedWIRE( void )
|
||||||
|
{
|
||||||
|
return sercom->I2CM.STATUS.bit.RXNACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SERCOM::availableWIRE( void )
|
||||||
|
{
|
||||||
|
if(isMasterWIRE())
|
||||||
|
return sercom->I2CM.INTFLAG.bit.SB;
|
||||||
|
else
|
||||||
|
return sercom->I2CS.INTFLAG.bit.DRDY;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t SERCOM::readDataWIRE( void )
|
||||||
|
{
|
||||||
|
if(isMasterWIRE())
|
||||||
|
{
|
||||||
|
while( sercom->I2CM.INTFLAG.bit.SB == 0 )
|
||||||
|
{
|
||||||
|
// Waiting complete receive
|
||||||
|
}
|
||||||
|
|
||||||
|
return sercom->I2CM.DATA.bit.DATA ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return sercom->I2CS.DATA.reg ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SERCOM::initClockNVIC( void )
|
||||||
|
{
|
||||||
|
uint8_t clockId = 0;
|
||||||
|
IRQn_Type IdNvic=PendSV_IRQn ; // Dummy init to intercept potential error later
|
||||||
|
|
||||||
|
if(sercom == SERCOM0)
|
||||||
|
{
|
||||||
|
clockId = GCM_SERCOM0_CORE;
|
||||||
|
IdNvic = SERCOM0_IRQn;
|
||||||
|
}
|
||||||
|
else if(sercom == SERCOM1)
|
||||||
|
{
|
||||||
|
clockId = GCM_SERCOM1_CORE;
|
||||||
|
IdNvic = SERCOM1_IRQn;
|
||||||
|
}
|
||||||
|
else if(sercom == SERCOM2)
|
||||||
|
{
|
||||||
|
clockId = GCM_SERCOM2_CORE;
|
||||||
|
IdNvic = SERCOM2_IRQn;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(__SAMD10D14AM__)
|
||||||
|
else if(sercom == SERCOM3)
|
||||||
|
{
|
||||||
|
clockId = GCM_SERCOM3_CORE;
|
||||||
|
IdNvic = SERCOM3_IRQn;
|
||||||
|
}
|
||||||
|
else if(sercom == SERCOM4)
|
||||||
|
{
|
||||||
|
clockId = GCM_SERCOM4_CORE;
|
||||||
|
IdNvic = SERCOM4_IRQn;
|
||||||
|
}
|
||||||
|
else if(sercom == SERCOM5)
|
||||||
|
{
|
||||||
|
clockId = GCM_SERCOM5_CORE;
|
||||||
|
IdNvic = SERCOM5_IRQn;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ( IdNvic == PendSV_IRQn )
|
||||||
|
{
|
||||||
|
// We got a problem here
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setting NVIC
|
||||||
|
NVIC_EnableIRQ(IdNvic);
|
||||||
|
NVIC_SetPriority (IdNvic, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority */
|
||||||
|
|
||||||
|
//Setting clock
|
||||||
|
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID( clockId ) | // Generic Clock 0 (SERCOMx)
|
||||||
|
GCLK_CLKCTRL_GEN_GCLK0 | // Generic Clock Generator 0 is source
|
||||||
|
GCLK_CLKCTRL_CLKEN ;
|
||||||
|
|
||||||
|
while ( GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY )
|
||||||
|
{
|
||||||
|
/* Wait for synchronization */
|
||||||
|
}
|
||||||
|
}
|
||||||
218
cores/samd10/SERCOM.h
Normal file
218
cores/samd10/SERCOM.h
Normal file
|
|
@ -0,0 +1,218 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SERCOM_CLASS_
|
||||||
|
#define _SERCOM_CLASS_
|
||||||
|
|
||||||
|
#include "sam.h"
|
||||||
|
|
||||||
|
#define SERCOM_FREQ_REF 48000000
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
UART_EXT_CLOCK = 0,
|
||||||
|
UART_INT_CLOCK = 0x1u
|
||||||
|
} SercomUartMode;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
SPI_SLAVE_OPERATION = 0x2u,
|
||||||
|
SPI_MASTER_OPERATION = 0x3u
|
||||||
|
} SercomSpiMode;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
I2C_SLAVE_OPERATION = 0x4u,
|
||||||
|
I2C_MASTER_OPERATION = 0x5u
|
||||||
|
} SercomI2CMode;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
SERCOM_EVEN_PARITY = 0,
|
||||||
|
SERCOM_ODD_PARITY,
|
||||||
|
SERCOM_NO_PARITY
|
||||||
|
} SercomParityMode;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
SERCOM_STOP_BIT_1 = 0,
|
||||||
|
SERCOM_STOP_BITS_2
|
||||||
|
} SercomNumberStopBit;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
MSB_FIRST = 0,
|
||||||
|
LSB_FIRST
|
||||||
|
} SercomDataOrder;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
UART_CHAR_SIZE_8_BITS = 0,
|
||||||
|
UART_CHAR_SIZE_9_BITS,
|
||||||
|
UART_CHAR_SIZE_5_BITS = 0x5u,
|
||||||
|
UART_CHAR_SIZE_6_BITS,
|
||||||
|
UART_CHAR_SIZE_7_BITS
|
||||||
|
} SercomUartCharSize;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
SERCOM_RX_PAD_0 = 0,
|
||||||
|
SERCOM_RX_PAD_1,
|
||||||
|
SERCOM_RX_PAD_2,
|
||||||
|
SERCOM_RX_PAD_3
|
||||||
|
} SercomRXPad;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
UART_TX_PAD_0 = 0x0ul, // Only for UART
|
||||||
|
UART_TX_PAD_2 = 0x1ul, // Only for UART
|
||||||
|
UART_TX_RTS_CTS_PAD_0_2_3 = 0x2ul, // Only for UART with TX on PAD0, RTS on PAD2 and CTS on PAD3
|
||||||
|
} SercomUartTXPad;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
SAMPLE_RATE_x16 = 0x1, //Fractional
|
||||||
|
SAMPLE_RATE_x8 = 0x3, //Fractional
|
||||||
|
} SercomUartSampleRate;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
SERCOM_SPI_MODE_0 = 0, // CPOL : 0 | CPHA : 0
|
||||||
|
SERCOM_SPI_MODE_1, // CPOL : 0 | CPHA : 1
|
||||||
|
SERCOM_SPI_MODE_2, // CPOL : 1 | CPHA : 0
|
||||||
|
SERCOM_SPI_MODE_3 // CPOL : 1 | CPHA : 1
|
||||||
|
} SercomSpiClockMode;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
SPI_PAD_0_SCK_1 = 0,
|
||||||
|
SPI_PAD_2_SCK_3,
|
||||||
|
SPI_PAD_3_SCK_1,
|
||||||
|
SPI_PAD_0_SCK_3
|
||||||
|
} SercomSpiTXPad;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
SPI_CHAR_SIZE_8_BITS = 0x0ul,
|
||||||
|
SPI_CHAR_SIZE_9_BITS
|
||||||
|
} SercomSpiCharSize;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
WIRE_UNKNOWN_STATE = 0x0ul,
|
||||||
|
WIRE_IDLE_STATE,
|
||||||
|
WIRE_OWNER_STATE,
|
||||||
|
WIRE_BUSY_STATE
|
||||||
|
} SercomWireBusState;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
WIRE_WRITE_FLAG = 0x0ul,
|
||||||
|
WIRE_READ_FLAG
|
||||||
|
} SercomWireReadWriteFlag;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
WIRE_MASTER_ACT_NO_ACTION = 0,
|
||||||
|
WIRE_MASTER_ACT_REPEAT_START,
|
||||||
|
WIRE_MASTER_ACT_READ,
|
||||||
|
WIRE_MASTER_ACT_STOP
|
||||||
|
} SercomMasterCommandWire;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
WIRE_MASTER_ACK_ACTION = 0,
|
||||||
|
WIRE_MASTER_NACK_ACTION
|
||||||
|
} SercomMasterAckActionWire;
|
||||||
|
|
||||||
|
class SERCOM
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SERCOM(Sercom* s) ;
|
||||||
|
|
||||||
|
/* ========== UART ========== */
|
||||||
|
void initUART(SercomUartMode mode, SercomUartSampleRate sampleRate, uint32_t baudrate=0) ;
|
||||||
|
void initFrame(SercomUartCharSize charSize, SercomDataOrder dataOrder, SercomParityMode parityMode, SercomNumberStopBit nbStopBits) ;
|
||||||
|
void initPads(SercomUartTXPad txPad, SercomRXPad rxPad) ;
|
||||||
|
|
||||||
|
void resetUART( void ) ;
|
||||||
|
void enableUART( void ) ;
|
||||||
|
void flushUART( void ) ;
|
||||||
|
void clearStatusUART( void ) ;
|
||||||
|
bool availableDataUART( void ) ;
|
||||||
|
bool isBufferOverflowErrorUART( void ) ;
|
||||||
|
bool isFrameErrorUART( void ) ;
|
||||||
|
bool isParityErrorUART( void ) ;
|
||||||
|
bool isDataRegisterEmptyUART( void ) ;
|
||||||
|
uint8_t readDataUART( void ) ;
|
||||||
|
int writeDataUART(uint8_t data) ;
|
||||||
|
bool isUARTError() ;
|
||||||
|
void acknowledgeUARTError() ;
|
||||||
|
|
||||||
|
/* ========== SPI ========== */
|
||||||
|
void initSPI(SercomSpiTXPad mosi, SercomRXPad miso, SercomSpiCharSize charSize, SercomDataOrder dataOrder) ;
|
||||||
|
void initSPIClock(SercomSpiClockMode clockMode, uint32_t baudrate) ;
|
||||||
|
|
||||||
|
void resetSPI( void ) ;
|
||||||
|
void enableSPI( void ) ;
|
||||||
|
void disableSPI( void ) ;
|
||||||
|
void setDataOrderSPI(SercomDataOrder dataOrder) ;
|
||||||
|
SercomDataOrder getDataOrderSPI( void ) ;
|
||||||
|
void setBaudrateSPI(uint8_t divider) ;
|
||||||
|
void setClockModeSPI(SercomSpiClockMode clockMode) ;
|
||||||
|
void writeDataSPI(uint8_t data) ;
|
||||||
|
uint16_t readDataSPI( void ) ;
|
||||||
|
bool isBufferOverflowErrorSPI( void ) ;
|
||||||
|
bool isDataRegisterEmptySPI( void ) ;
|
||||||
|
bool isTransmitCompleteSPI( void ) ;
|
||||||
|
bool isReceiveCompleteSPI( void ) ;
|
||||||
|
|
||||||
|
/* ========== WIRE ========== */
|
||||||
|
void initSlaveWIRE(uint8_t address) ;
|
||||||
|
void initMasterWIRE(uint32_t baudrate) ;
|
||||||
|
|
||||||
|
void resetWIRE( void ) ;
|
||||||
|
void enableWIRE( void ) ;
|
||||||
|
void disableWIRE( void );
|
||||||
|
void prepareNackBitWIRE( void ) ;
|
||||||
|
void prepareAckBitWIRE( void ) ;
|
||||||
|
void prepareCommandBitsWire(uint8_t cmd);
|
||||||
|
bool startTransmissionWIRE(uint8_t address, SercomWireReadWriteFlag flag) ;
|
||||||
|
bool sendDataMasterWIRE(uint8_t data) ;
|
||||||
|
bool sendDataSlaveWIRE(uint8_t data) ;
|
||||||
|
bool isMasterWIRE( void ) ;
|
||||||
|
bool isSlaveWIRE( void ) ;
|
||||||
|
bool isBusIdleWIRE( void ) ;
|
||||||
|
bool isBusOwnerWIRE( void ) ;
|
||||||
|
bool isDataReadyWIRE( void ) ;
|
||||||
|
bool isStopDetectedWIRE( void ) ;
|
||||||
|
bool isRestartDetectedWIRE( void ) ;
|
||||||
|
bool isAddressMatch( void ) ;
|
||||||
|
bool isMasterReadOperationWIRE( void ) ;
|
||||||
|
bool isRXNackReceivedWIRE( void ) ;
|
||||||
|
int availableWIRE( void ) ;
|
||||||
|
uint8_t readDataWIRE( void ) ;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Sercom* sercom;
|
||||||
|
uint8_t calculateBaudrateSynchronous(uint32_t baudrate) ;
|
||||||
|
uint32_t division(uint32_t dividend, uint32_t divisor) ;
|
||||||
|
void initClockNVIC( void ) ;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
30
cores/samd10/Server.h
Normal file
30
cores/samd10/Server.h
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
Server.h - Base class that provides Server
|
||||||
|
Copyright (c) 2011 Adrian McEwen. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef server_h
|
||||||
|
#define server_h
|
||||||
|
|
||||||
|
#include "Print.h"
|
||||||
|
|
||||||
|
class Server : public Print {
|
||||||
|
public:
|
||||||
|
virtual void begin() =0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
319
cores/samd10/Stream.cpp
Normal file
319
cores/samd10/Stream.cpp
Normal file
|
|
@ -0,0 +1,319 @@
|
||||||
|
/*
|
||||||
|
Stream.cpp - adds parsing methods to Stream class
|
||||||
|
Copyright (c) 2008 David A. Mellis. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Created July 2011
|
||||||
|
parsing functions based on TextFinder library by Michael Margolis
|
||||||
|
|
||||||
|
findMulti/findUntil routines written by Jim Leonard/Xuth
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Stream.h"
|
||||||
|
|
||||||
|
#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait
|
||||||
|
|
||||||
|
// private method to read stream with timeout
|
||||||
|
int Stream::timedRead()
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
_startMillis = millis();
|
||||||
|
do {
|
||||||
|
c = read();
|
||||||
|
if (c >= 0) return c;
|
||||||
|
} while(millis() - _startMillis < _timeout);
|
||||||
|
return -1; // -1 indicates timeout
|
||||||
|
}
|
||||||
|
|
||||||
|
// private method to peek stream with timeout
|
||||||
|
int Stream::timedPeek()
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
_startMillis = millis();
|
||||||
|
do {
|
||||||
|
c = peek();
|
||||||
|
if (c >= 0) return c;
|
||||||
|
} while(millis() - _startMillis < _timeout);
|
||||||
|
return -1; // -1 indicates timeout
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns peek of the next digit in the stream or -1 if timeout
|
||||||
|
// discards non-numeric characters
|
||||||
|
int Stream::peekNextDigit(LookaheadMode lookahead, bool detectDecimal)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
while (1) {
|
||||||
|
c = timedPeek();
|
||||||
|
|
||||||
|
if( c < 0 ||
|
||||||
|
c == '-' ||
|
||||||
|
(c >= '0' && c <= '9') ||
|
||||||
|
(detectDecimal && c == '.')) return c;
|
||||||
|
|
||||||
|
switch( lookahead ){
|
||||||
|
case SKIP_NONE: return -1; // Fail code.
|
||||||
|
case SKIP_WHITESPACE:
|
||||||
|
switch( c ){
|
||||||
|
case ' ':
|
||||||
|
case '\t':
|
||||||
|
case '\r':
|
||||||
|
case '\n': break;
|
||||||
|
default: return -1; // Fail code.
|
||||||
|
}
|
||||||
|
case SKIP_ALL:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
read(); // discard non-numeric
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Public Methods
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
|
||||||
|
{
|
||||||
|
_timeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find returns true if the target string is found
|
||||||
|
bool Stream::find(char *target)
|
||||||
|
{
|
||||||
|
return findUntil(target, strlen(target), NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// reads data from the stream until the target string of given length is found
|
||||||
|
// returns true if target string is found, false if timed out
|
||||||
|
bool Stream::find(char *target, size_t length)
|
||||||
|
{
|
||||||
|
return findUntil(target, length, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// as find but search ends if the terminator string is found
|
||||||
|
bool Stream::findUntil(char *target, char *terminator)
|
||||||
|
{
|
||||||
|
return findUntil(target, strlen(target), terminator, strlen(terminator));
|
||||||
|
}
|
||||||
|
|
||||||
|
// reads data from the stream until the target string of the given length is found
|
||||||
|
// search terminated if the terminator string is found
|
||||||
|
// returns true if target string is found, false if terminated or timed out
|
||||||
|
bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen)
|
||||||
|
{
|
||||||
|
if (terminator == NULL) {
|
||||||
|
MultiTarget t[1] = {{target, targetLen, 0}};
|
||||||
|
return findMulti(t, 1) == 0 ? true : false;
|
||||||
|
} else {
|
||||||
|
MultiTarget t[2] = {{target, targetLen, 0}, {terminator, termLen, 0}};
|
||||||
|
return findMulti(t, 2) == 0 ? true : false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the first valid (long) integer value from the current position.
|
||||||
|
// lookahead determines how parseInt looks ahead in the stream.
|
||||||
|
// See LookaheadMode enumeration at the top of the file.
|
||||||
|
// Lookahead is terminated by the first character that is not a valid part of an integer.
|
||||||
|
// Once parsing commences, 'ignore' will be skipped in the stream.
|
||||||
|
long Stream::parseInt(LookaheadMode lookahead, char ignore)
|
||||||
|
{
|
||||||
|
bool isNegative = false;
|
||||||
|
long value = 0;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
c = peekNextDigit(lookahead, false);
|
||||||
|
// ignore non numeric leading characters
|
||||||
|
if(c < 0)
|
||||||
|
return 0; // zero returned if timeout
|
||||||
|
|
||||||
|
do{
|
||||||
|
if(c == ignore)
|
||||||
|
; // ignore this character
|
||||||
|
else if(c == '-')
|
||||||
|
isNegative = true;
|
||||||
|
else if(c >= '0' && c <= '9') // is c a digit?
|
||||||
|
value = value * 10 + c - '0';
|
||||||
|
read(); // consume the character we got with peek
|
||||||
|
c = timedPeek();
|
||||||
|
}
|
||||||
|
while( (c >= '0' && c <= '9') || c == ignore );
|
||||||
|
|
||||||
|
if(isNegative)
|
||||||
|
value = -value;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// as parseInt but returns a floating point value
|
||||||
|
float Stream::parseFloat(LookaheadMode lookahead, char ignore)
|
||||||
|
{
|
||||||
|
bool isNegative = false;
|
||||||
|
bool isFraction = false;
|
||||||
|
long value = 0;
|
||||||
|
int c;
|
||||||
|
float fraction = 1.0;
|
||||||
|
|
||||||
|
c = peekNextDigit(lookahead, true);
|
||||||
|
// ignore non numeric leading characters
|
||||||
|
if(c < 0)
|
||||||
|
return 0; // zero returned if timeout
|
||||||
|
|
||||||
|
do{
|
||||||
|
if(c == ignore)
|
||||||
|
; // ignore
|
||||||
|
else if(c == '-')
|
||||||
|
isNegative = true;
|
||||||
|
else if (c == '.')
|
||||||
|
isFraction = true;
|
||||||
|
else if(c >= '0' && c <= '9') { // is c a digit?
|
||||||
|
value = value * 10 + c - '0';
|
||||||
|
if(isFraction)
|
||||||
|
fraction *= 0.1;
|
||||||
|
}
|
||||||
|
read(); // consume the character we got with peek
|
||||||
|
c = timedPeek();
|
||||||
|
}
|
||||||
|
while( (c >= '0' && c <= '9') || (c == '.' && !isFraction) || c == ignore );
|
||||||
|
|
||||||
|
if(isNegative)
|
||||||
|
value = -value;
|
||||||
|
if(isFraction)
|
||||||
|
return value * fraction;
|
||||||
|
else
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read characters from stream into buffer
|
||||||
|
// terminates if length characters have been read, or timeout (see setTimeout)
|
||||||
|
// returns the number of characters placed in the buffer
|
||||||
|
// the buffer is NOT null terminated.
|
||||||
|
//
|
||||||
|
size_t Stream::readBytes(char *buffer, size_t length)
|
||||||
|
{
|
||||||
|
size_t count = 0;
|
||||||
|
while (count < length) {
|
||||||
|
int c = timedRead();
|
||||||
|
if (c < 0) break;
|
||||||
|
*buffer++ = (char)c;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// as readBytes with terminator character
|
||||||
|
// terminates if length characters have been read, timeout, or if the terminator character detected
|
||||||
|
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||||
|
|
||||||
|
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
||||||
|
{
|
||||||
|
if (length < 1) return 0;
|
||||||
|
size_t index = 0;
|
||||||
|
while (index < length) {
|
||||||
|
int c = timedRead();
|
||||||
|
if (c < 0 || c == terminator) break;
|
||||||
|
*buffer++ = (char)c;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return index; // return number of characters, not including null terminator
|
||||||
|
}
|
||||||
|
|
||||||
|
String Stream::readString()
|
||||||
|
{
|
||||||
|
String ret;
|
||||||
|
int c = timedRead();
|
||||||
|
while (c >= 0)
|
||||||
|
{
|
||||||
|
ret += (char)c;
|
||||||
|
c = timedRead();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
String Stream::readStringUntil(char terminator)
|
||||||
|
{
|
||||||
|
String ret;
|
||||||
|
int c = timedRead();
|
||||||
|
while (c >= 0 && c != terminator)
|
||||||
|
{
|
||||||
|
ret += (char)c;
|
||||||
|
c = timedRead();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) {
|
||||||
|
// any zero length target string automatically matches and would make
|
||||||
|
// a mess of the rest of the algorithm.
|
||||||
|
for (struct MultiTarget *t = targets; t < targets+tCount; ++t) {
|
||||||
|
if (t->len <= 0)
|
||||||
|
return t - targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
int c = timedRead();
|
||||||
|
if (c < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (struct MultiTarget *t = targets; t < targets+tCount; ++t) {
|
||||||
|
// the simple case is if we match, deal with that first.
|
||||||
|
if (c == t->str[t->index]) {
|
||||||
|
if (++t->index == t->len)
|
||||||
|
return t - targets;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if not we need to walk back and see if we could have matched further
|
||||||
|
// down the stream (ie '1112' doesn't match the first position in '11112'
|
||||||
|
// but it will match the second position so we can't just reset the current
|
||||||
|
// index to 0 when we find a mismatch.
|
||||||
|
if (t->index == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int origIndex = t->index;
|
||||||
|
do {
|
||||||
|
--t->index;
|
||||||
|
// first check if current char works against the new current index
|
||||||
|
if (c != t->str[t->index])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// if it's the only char then we're good, nothing more to check
|
||||||
|
if (t->index == 0) {
|
||||||
|
t->index++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise we need to check the rest of the found string
|
||||||
|
int diff = origIndex - t->index;
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < t->index; ++i) {
|
||||||
|
if (t->str[i] != t->str[i + diff])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we successfully got through the previous loop then our current
|
||||||
|
// index is good.
|
||||||
|
if (i == t->index) {
|
||||||
|
t->index++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise we just try the next index
|
||||||
|
} while (t->index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// unreachable
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
129
cores/samd10/Stream.h
Normal file
129
cores/samd10/Stream.h
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
/*
|
||||||
|
Stream.h - base class for character-based streams.
|
||||||
|
Copyright (c) 2010 David A. Mellis. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
parsing functions based on TextFinder library by Michael Margolis
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Stream_h
|
||||||
|
#define Stream_h
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include "Print.h"
|
||||||
|
|
||||||
|
// compatability macros for testing
|
||||||
|
/*
|
||||||
|
#define getInt() parseInt()
|
||||||
|
#define getInt(ignore) parseInt(ignore)
|
||||||
|
#define getFloat() parseFloat()
|
||||||
|
#define getFloat(ignore) parseFloat(ignore)
|
||||||
|
#define getString( pre_string, post_string, buffer, length)
|
||||||
|
readBytesBetween( pre_string, terminator, buffer, length)
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This enumeration provides the lookahead options for parseInt(), parseFloat()
|
||||||
|
// The rules set out here are used until either the first valid character is found
|
||||||
|
// or a time out occurs due to lack of input.
|
||||||
|
enum LookaheadMode{
|
||||||
|
SKIP_ALL, // All invalid characters are ignored.
|
||||||
|
SKIP_NONE, // Nothing is skipped, and the stream is not touched unless the first waiting character is valid.
|
||||||
|
SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped.
|
||||||
|
};
|
||||||
|
|
||||||
|
#define NO_IGNORE_CHAR '\x01' // a char not found in a valid ASCII numeric field
|
||||||
|
|
||||||
|
class Stream : public Print
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
|
||||||
|
unsigned long _startMillis; // used for timeout measurement
|
||||||
|
int timedRead(); // private method to read stream with timeout
|
||||||
|
int timedPeek(); // private method to peek stream with timeout
|
||||||
|
int peekNextDigit(LookaheadMode lookahead, bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual int available() = 0;
|
||||||
|
virtual int read() = 0;
|
||||||
|
virtual int peek() = 0;
|
||||||
|
virtual void flush() = 0;
|
||||||
|
|
||||||
|
Stream() {_timeout=1000;}
|
||||||
|
|
||||||
|
// parsing methods
|
||||||
|
|
||||||
|
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
||||||
|
|
||||||
|
bool find(char *target); // reads data from the stream until the target string is found
|
||||||
|
bool find(uint8_t *target) { return find ((char *)target); }
|
||||||
|
// returns true if target string is found, false if timed out (see setTimeout)
|
||||||
|
|
||||||
|
bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
|
||||||
|
bool find(uint8_t *target, size_t length) { return find ((char *)target, length); }
|
||||||
|
// returns true if target string is found, false if timed out
|
||||||
|
|
||||||
|
bool find(char target) { return find (&target, 1); }
|
||||||
|
|
||||||
|
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
|
||||||
|
bool findUntil(uint8_t *target, char *terminator) { return findUntil((char *)target, terminator); }
|
||||||
|
|
||||||
|
bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
|
||||||
|
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); }
|
||||||
|
|
||||||
|
long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||||
|
// returns the first valid (long) integer value from the current position.
|
||||||
|
// lookahead determines how parseInt looks ahead in the stream.
|
||||||
|
// See LookaheadMode enumeration at the top of the file.
|
||||||
|
// Lookahead is terminated by the first character that is not a valid part of an integer.
|
||||||
|
// Once parsing commences, 'ignore' will be skipped in the stream.
|
||||||
|
|
||||||
|
float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||||
|
// float version of parseInt
|
||||||
|
|
||||||
|
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
|
||||||
|
size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
|
||||||
|
// terminates if length characters have been read or timeout (see setTimeout)
|
||||||
|
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||||
|
|
||||||
|
size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
|
||||||
|
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); }
|
||||||
|
// terminates if length characters have been read, timeout, or if the terminator character detected
|
||||||
|
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||||
|
|
||||||
|
// Arduino String functions to be added here
|
||||||
|
String readString();
|
||||||
|
String readStringUntil(char terminator);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
long parseInt(char ignore) { return parseInt(SKIP_ALL, ignore); }
|
||||||
|
float parseFloat(char ignore) { return parseFloat(SKIP_ALL, ignore); }
|
||||||
|
// These overload exists for compatibility with any class that has derived
|
||||||
|
// Stream and used parseFloat/Int with a custom ignore character. To keep
|
||||||
|
// the public API simple, these overload remains protected.
|
||||||
|
|
||||||
|
struct MultiTarget {
|
||||||
|
const char *str; // string you're searching for
|
||||||
|
size_t len; // length of string you're searching for
|
||||||
|
size_t index; // index used by the search routine.
|
||||||
|
};
|
||||||
|
|
||||||
|
// This allows you to search for an arbitrary number of strings.
|
||||||
|
// Returns index of the target that is found first or -1 if timeout occurs.
|
||||||
|
int findMulti(struct MultiTarget *targets, int tCount);
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef NO_IGNORE_CHAR
|
||||||
|
#endif
|
||||||
28
cores/samd10/Tone.h
Normal file
28
cores/samd10/Tone.h
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
void tone(uint32_t _pin, uint32_t frequency, uint32_t duration = 0);
|
||||||
|
void noTone(uint32_t _pin);
|
||||||
|
|
||||||
|
#endif
|
||||||
143
cores/samd10/Uart.cpp
Normal file
143
cores/samd10/Uart.cpp
Normal file
|
|
@ -0,0 +1,143 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Uart.h"
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "wiring_private.h"
|
||||||
|
|
||||||
|
Uart::Uart(SERCOM *_s, uint8_t _pinRX, uint8_t _pinTX, SercomRXPad _padRX, SercomUartTXPad _padTX)
|
||||||
|
{
|
||||||
|
sercom = _s;
|
||||||
|
uc_pinRX = _pinRX;
|
||||||
|
uc_pinTX = _pinTX;
|
||||||
|
uc_padRX=_padRX ;
|
||||||
|
uc_padTX=_padTX;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Uart::begin(unsigned long baudrate)
|
||||||
|
{
|
||||||
|
begin(baudrate, (uint8_t)SERIAL_8N1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Uart::begin(unsigned long baudrate, uint16_t config)
|
||||||
|
{
|
||||||
|
pinPeripheral(uc_pinRX, g_APinDescription[uc_pinRX].ulPinType);
|
||||||
|
pinPeripheral(uc_pinTX, g_APinDescription[uc_pinTX].ulPinType);
|
||||||
|
|
||||||
|
sercom->initUART(UART_INT_CLOCK, SAMPLE_RATE_x16, baudrate);
|
||||||
|
sercom->initFrame(extractCharSize(config), LSB_FIRST, extractParity(config), extractNbStopBit(config));
|
||||||
|
sercom->initPads(uc_padTX, uc_padRX);
|
||||||
|
|
||||||
|
sercom->enableUART();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Uart::end()
|
||||||
|
{
|
||||||
|
sercom->resetUART();
|
||||||
|
rxBuffer.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Uart::flush()
|
||||||
|
{
|
||||||
|
sercom->flushUART();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Uart::IrqHandler()
|
||||||
|
{
|
||||||
|
if (sercom->availableDataUART()) {
|
||||||
|
rxBuffer.store_char(sercom->readDataUART());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sercom->isUARTError()) {
|
||||||
|
sercom->acknowledgeUARTError();
|
||||||
|
// TODO: if (sercom->isBufferOverflowErrorUART()) ....
|
||||||
|
// TODO: if (sercom->isFrameErrorUART()) ....
|
||||||
|
// TODO: if (sercom->isParityErrorUART()) ....
|
||||||
|
sercom->clearStatusUART();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int Uart::available()
|
||||||
|
{
|
||||||
|
return rxBuffer.available();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Uart::peek()
|
||||||
|
{
|
||||||
|
return rxBuffer.peek();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Uart::read()
|
||||||
|
{
|
||||||
|
return rxBuffer.read_char();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Uart::write(const uint8_t data)
|
||||||
|
{
|
||||||
|
sercom->writeDataUART(data);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SercomNumberStopBit Uart::extractNbStopBit(uint16_t config)
|
||||||
|
{
|
||||||
|
switch(config & HARDSER_STOP_BIT_MASK)
|
||||||
|
{
|
||||||
|
case HARDSER_STOP_BIT_1:
|
||||||
|
default:
|
||||||
|
return SERCOM_STOP_BIT_1;
|
||||||
|
|
||||||
|
case HARDSER_STOP_BIT_2:
|
||||||
|
return SERCOM_STOP_BITS_2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SercomUartCharSize Uart::extractCharSize(uint16_t config)
|
||||||
|
{
|
||||||
|
switch(config & HARDSER_DATA_MASK)
|
||||||
|
{
|
||||||
|
case HARDSER_DATA_5:
|
||||||
|
return UART_CHAR_SIZE_5_BITS;
|
||||||
|
|
||||||
|
case HARDSER_DATA_6:
|
||||||
|
return UART_CHAR_SIZE_6_BITS;
|
||||||
|
|
||||||
|
case HARDSER_DATA_7:
|
||||||
|
return UART_CHAR_SIZE_7_BITS;
|
||||||
|
|
||||||
|
case HARDSER_DATA_8:
|
||||||
|
default:
|
||||||
|
return UART_CHAR_SIZE_8_BITS;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SercomParityMode Uart::extractParity(uint16_t config)
|
||||||
|
{
|
||||||
|
switch(config & HARDSER_PARITY_MASK)
|
||||||
|
{
|
||||||
|
case HARDSER_PARITY_NONE:
|
||||||
|
default:
|
||||||
|
return SERCOM_NO_PARITY;
|
||||||
|
|
||||||
|
case HARDSER_PARITY_EVEN:
|
||||||
|
return SERCOM_EVEN_PARITY;
|
||||||
|
|
||||||
|
case HARDSER_PARITY_ODD:
|
||||||
|
return SERCOM_ODD_PARITY;
|
||||||
|
}
|
||||||
|
}
|
||||||
57
cores/samd10/Uart.h
Normal file
57
cores/samd10/Uart.h
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "HardwareSerial.h"
|
||||||
|
#include "SERCOM.h"
|
||||||
|
#include "RingBuffer.h"
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
class Uart : public HardwareSerial
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Uart(SERCOM *_s, uint8_t _pinRX, uint8_t _pinTX, SercomRXPad _padRX, SercomUartTXPad _padTX);
|
||||||
|
void begin(unsigned long baudRate);
|
||||||
|
void begin(unsigned long baudrate, uint16_t config);
|
||||||
|
void end();
|
||||||
|
int available();
|
||||||
|
int peek();
|
||||||
|
int read();
|
||||||
|
void flush();
|
||||||
|
size_t write(const uint8_t data);
|
||||||
|
using Print::write; // pull in write(str) and write(buf, size) from Print
|
||||||
|
|
||||||
|
void IrqHandler();
|
||||||
|
|
||||||
|
operator bool() { return true; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
SERCOM *sercom;
|
||||||
|
RingBuffer rxBuffer;
|
||||||
|
|
||||||
|
uint8_t uc_pinRX;
|
||||||
|
uint8_t uc_pinTX;
|
||||||
|
SercomRXPad uc_padRX;
|
||||||
|
SercomUartTXPad uc_padTX;
|
||||||
|
|
||||||
|
SercomNumberStopBit extractNbStopBit(uint16_t config);
|
||||||
|
SercomUartCharSize extractCharSize(uint16_t config);
|
||||||
|
SercomParityMode extractParity(uint16_t config);
|
||||||
|
};
|
||||||
88
cores/samd10/Udp.h
Normal file
88
cores/samd10/Udp.h
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* Udp.cpp: Library to send/receive UDP packets.
|
||||||
|
*
|
||||||
|
* NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
|
||||||
|
* 1) UDP does not guarantee the order in which assembled UDP packets are received. This
|
||||||
|
* might not happen often in practice, but in larger network topologies, a UDP
|
||||||
|
* packet can be received out of sequence.
|
||||||
|
* 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
|
||||||
|
* aware of it. Again, this may not be a concern in practice on small local networks.
|
||||||
|
* For more information, see http://www.cafeaulait.org/course/week12/35.html
|
||||||
|
*
|
||||||
|
* MIT License:
|
||||||
|
* Copyright (c) 2008 Bjoern Hartmann
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* bjoern@cs.stanford.edu 12/30/2008
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef udp_h
|
||||||
|
#define udp_h
|
||||||
|
|
||||||
|
#include <Stream.h>
|
||||||
|
#include <IPAddress.h>
|
||||||
|
|
||||||
|
class UDP : public Stream {
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||||
|
virtual void stop() =0; // Finish with the UDP socket
|
||||||
|
|
||||||
|
// Sending UDP packets
|
||||||
|
|
||||||
|
// Start building up a packet to send to the remote host specific in ip and port
|
||||||
|
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
|
||||||
|
virtual int beginPacket(IPAddress ip, uint16_t port) =0;
|
||||||
|
// Start building up a packet to send to the remote host specific in host and port
|
||||||
|
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
|
||||||
|
virtual int beginPacket(const char *host, uint16_t port) =0;
|
||||||
|
// Finish off this packet and send it
|
||||||
|
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||||
|
virtual int endPacket() =0;
|
||||||
|
// Write a single byte into the packet
|
||||||
|
virtual size_t write(uint8_t) =0;
|
||||||
|
// Write size bytes from buffer into the packet
|
||||||
|
virtual size_t write(const uint8_t *buffer, size_t size) =0;
|
||||||
|
|
||||||
|
// Start processing the next available incoming packet
|
||||||
|
// Returns the size of the packet in bytes, or 0 if no packets are available
|
||||||
|
virtual int parsePacket() =0;
|
||||||
|
// Number of bytes remaining in the current packet
|
||||||
|
virtual int available() =0;
|
||||||
|
// Read a single byte from the current packet
|
||||||
|
virtual int read() =0;
|
||||||
|
// Read up to len bytes from the current packet and place them into buffer
|
||||||
|
// Returns the number of bytes read, or 0 if none are available
|
||||||
|
virtual int read(unsigned char* buffer, size_t len) =0;
|
||||||
|
// Read up to len characters from the current packet and place them into buffer
|
||||||
|
// Returns the number of characters read, or 0 if none are available
|
||||||
|
virtual int read(char* buffer, size_t len) =0;
|
||||||
|
// Return the next byte from the current packet without moving on to the next byte
|
||||||
|
virtual int peek() =0;
|
||||||
|
virtual void flush() =0; // Finish reading the current packet
|
||||||
|
|
||||||
|
// Return the IP address of the host who sent the current incoming packet
|
||||||
|
virtual IPAddress remoteIP() =0;
|
||||||
|
// Return the port of the host who sent the current incoming packet
|
||||||
|
virtual uint16_t remotePort() =0;
|
||||||
|
protected:
|
||||||
|
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
179
cores/samd10/WCharacter.h
Normal file
179
cores/samd10/WCharacter.h
Normal file
|
|
@ -0,0 +1,179 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Character_h
|
||||||
|
#define Character_h
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// WCharacter.h prototypes
|
||||||
|
#if defined ( __GNUC__ )
|
||||||
|
inline boolean isAlphaNumeric(int c) __attribute__((always_inline));
|
||||||
|
inline boolean isAlpha(int c) __attribute__((always_inline));
|
||||||
|
inline boolean isAscii(int c) __attribute__((always_inline));
|
||||||
|
inline boolean isWhitespace(int c) __attribute__((always_inline));
|
||||||
|
inline boolean isControl(int c) __attribute__((always_inline));
|
||||||
|
inline boolean isDigit(int c) __attribute__((always_inline));
|
||||||
|
inline boolean isGraph(int c) __attribute__((always_inline));
|
||||||
|
inline boolean isLowerCase(int c) __attribute__((always_inline));
|
||||||
|
inline boolean isPrintable(int c) __attribute__((always_inline));
|
||||||
|
inline boolean isPunct(int c) __attribute__((always_inline));
|
||||||
|
inline boolean isSpace(int c) __attribute__((always_inline));
|
||||||
|
inline boolean isUpperCase(int c) __attribute__((always_inline));
|
||||||
|
inline boolean isHexadecimalDigit(int c) __attribute__((always_inline));
|
||||||
|
inline int toAscii(int c) __attribute__((always_inline));
|
||||||
|
inline int toLowerCase(int c) __attribute__((always_inline));
|
||||||
|
inline int toUpperCase(int c)__attribute__((always_inline));
|
||||||
|
#elif defined ( __ICCARM__ )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Checks for an alphanumeric character.
|
||||||
|
// It is equivalent to (isalpha(c) || isdigit(c)).
|
||||||
|
inline boolean isAlphaNumeric(int c)
|
||||||
|
{
|
||||||
|
return ( isalnum(c) == 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks for an alphabetic character.
|
||||||
|
// It is equivalent to (isupper(c) || islower(c)).
|
||||||
|
inline boolean isAlpha(int c)
|
||||||
|
{
|
||||||
|
return ( isalpha(c) == 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks whether c is a 7-bit unsigned char value
|
||||||
|
// that fits into the ASCII character set.
|
||||||
|
inline boolean isAscii(int c)
|
||||||
|
{
|
||||||
|
/* return ( isascii(c) == 0 ? false : true); */
|
||||||
|
return ( (c & ~0x7f) != 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks for a blank character, that is, a space or a tab.
|
||||||
|
inline boolean isWhitespace(int c)
|
||||||
|
{
|
||||||
|
return ( isblank (c) == 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks for a control character.
|
||||||
|
inline boolean isControl(int c)
|
||||||
|
{
|
||||||
|
return ( iscntrl (c) == 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks for a digit (0 through 9).
|
||||||
|
inline boolean isDigit(int c)
|
||||||
|
{
|
||||||
|
return ( isdigit (c) == 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks for any printable character except space.
|
||||||
|
inline boolean isGraph(int c)
|
||||||
|
{
|
||||||
|
return ( isgraph (c) == 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks for a lower-case character.
|
||||||
|
inline boolean isLowerCase(int c)
|
||||||
|
{
|
||||||
|
return (islower (c) == 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks for any printable character including space.
|
||||||
|
inline boolean isPrintable(int c)
|
||||||
|
{
|
||||||
|
return ( isprint (c) == 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks for any printable character which is not a space
|
||||||
|
// or an alphanumeric character.
|
||||||
|
inline boolean isPunct(int c)
|
||||||
|
{
|
||||||
|
return ( ispunct (c) == 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks for white-space characters. For the avr-libc library,
|
||||||
|
// these are: space, formfeed ('\f'), newline ('\n'), carriage
|
||||||
|
// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
|
||||||
|
inline boolean isSpace(int c)
|
||||||
|
{
|
||||||
|
return ( isspace (c) == 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks for an uppercase letter.
|
||||||
|
inline boolean isUpperCase(int c)
|
||||||
|
{
|
||||||
|
return ( isupper (c) == 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7
|
||||||
|
// 8 9 a b c d e f A B C D E F.
|
||||||
|
inline boolean isHexadecimalDigit(int c)
|
||||||
|
{
|
||||||
|
return ( isxdigit (c) == 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Converts c to a 7-bit unsigned char value that fits into the
|
||||||
|
// ASCII character set, by clearing the high-order bits.
|
||||||
|
inline int toAscii(int c)
|
||||||
|
{
|
||||||
|
/* return toascii (c); */
|
||||||
|
return (c & 0x7f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Warning:
|
||||||
|
// Many people will be unhappy if you use this function.
|
||||||
|
// This function will convert accented letters into random
|
||||||
|
// characters.
|
||||||
|
|
||||||
|
// Converts the letter c to lower case, if possible.
|
||||||
|
inline int toLowerCase(int c)
|
||||||
|
{
|
||||||
|
return tolower (c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Converts the letter c to upper case, if possible.
|
||||||
|
inline int toUpperCase(int c)
|
||||||
|
{
|
||||||
|
return toupper (c);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
156
cores/samd10/WInterrupts.c
Normal file
156
cores/samd10/WInterrupts.c
Normal file
|
|
@ -0,0 +1,156 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "wiring_private.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static voidFuncPtr callbacksInt[EXTERNAL_NUM_INTERRUPTS];
|
||||||
|
|
||||||
|
/* Configure I/O interrupt sources */
|
||||||
|
static void __initialize()
|
||||||
|
{
|
||||||
|
memset(callbacksInt, 0, sizeof(callbacksInt));
|
||||||
|
|
||||||
|
NVIC_DisableIRQ(EIC_IRQn);
|
||||||
|
NVIC_ClearPendingIRQ(EIC_IRQn);
|
||||||
|
NVIC_SetPriority(EIC_IRQn, 0);
|
||||||
|
NVIC_EnableIRQ(EIC_IRQn);
|
||||||
|
|
||||||
|
// Enable GCLK for IEC (External Interrupt Controller)
|
||||||
|
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID(GCM_EIC));
|
||||||
|
|
||||||
|
/* Shall we do that?
|
||||||
|
// Do a software reset on EIC
|
||||||
|
EIC->CTRL.SWRST.bit = 1 ;
|
||||||
|
while ((EIC->CTRL.SWRST.bit == 1) && (EIC->STATUS.SYNCBUSY.bit == 1)) { }
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Enable EIC
|
||||||
|
EIC->CTRL.bit.ENABLE = 1;
|
||||||
|
while (EIC->STATUS.bit.SYNCBUSY == 1) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs.
|
||||||
|
* Replaces any previous function that was attached to the interrupt.
|
||||||
|
*/
|
||||||
|
void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
|
||||||
|
{
|
||||||
|
static int enabled = 0;
|
||||||
|
uint32_t config;
|
||||||
|
uint32_t pos;
|
||||||
|
|
||||||
|
#if ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606
|
||||||
|
EExt_Interrupts in = g_APinDescription[pin].ulExtInt;
|
||||||
|
#else
|
||||||
|
EExt_Interrupts in = digitalPinToInterrupt(pin);
|
||||||
|
#endif
|
||||||
|
if (in == NOT_AN_INTERRUPT || in == EXTERNAL_INT_NMI)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!enabled) {
|
||||||
|
__initialize();
|
||||||
|
enabled = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable wakeup capability on pin in case being used during sleep
|
||||||
|
EIC->WAKEUP.reg |= (1 << in);
|
||||||
|
|
||||||
|
// Assign pin to EIC
|
||||||
|
pinPeripheral(pin, PIO_EXTINT);
|
||||||
|
|
||||||
|
// Assign callback to interrupt
|
||||||
|
callbacksInt[in] = callback;
|
||||||
|
|
||||||
|
// Look for right CONFIG register to be addressed
|
||||||
|
if (in > EXTERNAL_INT_7) {
|
||||||
|
config = 1;
|
||||||
|
} else {
|
||||||
|
config = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure the interrupt mode
|
||||||
|
pos = (in - (8 * config)) << 2;
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case LOW:
|
||||||
|
EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_LOW_Val << pos;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HIGH:
|
||||||
|
EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_HIGH_Val << pos;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CHANGE:
|
||||||
|
EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_BOTH_Val << pos;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FALLING:
|
||||||
|
EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_FALL_Val << pos;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RISING:
|
||||||
|
EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_RISE_Val << pos;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable the interrupt
|
||||||
|
EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1 << in);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Turns off the given interrupt.
|
||||||
|
*/
|
||||||
|
void detachInterrupt(uint32_t pin)
|
||||||
|
{
|
||||||
|
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||||
|
EExt_Interrupts in = g_APinDescription[pin].ulExtInt;
|
||||||
|
#else
|
||||||
|
EExt_Interrupts in = digitalPinToInterrupt(pin);
|
||||||
|
#endif
|
||||||
|
if (in == NOT_AN_INTERRUPT || in == EXTERNAL_INT_NMI)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT(1 << in);
|
||||||
|
|
||||||
|
// Disable wakeup capability on pin during sleep
|
||||||
|
EIC->WAKEUP.reg &= ~(1 << in);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* External Interrupt Controller NVIC Interrupt Handler
|
||||||
|
*/
|
||||||
|
void EIC_Handler(void)
|
||||||
|
{
|
||||||
|
// Test the 16 normal interrupts
|
||||||
|
for (uint32_t i=EXTERNAL_INT_0; i<=EXTERNAL_INT_15; i++)
|
||||||
|
{
|
||||||
|
if ((EIC->INTFLAG.reg & (1 << i)) != 0)
|
||||||
|
{
|
||||||
|
// Call the callback function if assigned
|
||||||
|
if (callbacksInt[i]) {
|
||||||
|
callbacksInt[i]();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the interrupt
|
||||||
|
EIC->INTFLAG.reg = 1 << i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
54
cores/samd10/WInterrupts.h
Normal file
54
cores/samd10/WInterrupts.h
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _WIRING_INTERRUPTS_
|
||||||
|
#define _WIRING_INTERRUPTS_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// LOW 0
|
||||||
|
// HIGH 1
|
||||||
|
#define CHANGE 2
|
||||||
|
#define FALLING 3
|
||||||
|
#define RISING 4
|
||||||
|
|
||||||
|
#define DEFAULT 1
|
||||||
|
#define EXTERNAL 0
|
||||||
|
|
||||||
|
typedef void (*voidFuncPtr)(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs.
|
||||||
|
* Replaces any previous function that was attached to the interrupt.
|
||||||
|
*/
|
||||||
|
void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Turns off the given interrupt.
|
||||||
|
*/
|
||||||
|
void detachInterrupt(uint32_t pin);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
68
cores/samd10/WMath.cpp
Normal file
68
cores/samd10/WMath.cpp
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "stdlib.h"
|
||||||
|
#include "stdint.h"
|
||||||
|
}
|
||||||
|
#include "WMath.h"
|
||||||
|
|
||||||
|
extern void randomSeed( uint32_t dwSeed )
|
||||||
|
{
|
||||||
|
if ( dwSeed != 0 )
|
||||||
|
{
|
||||||
|
srand( dwSeed ) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern long random( long howbig )
|
||||||
|
{
|
||||||
|
if ( howbig == 0 )
|
||||||
|
{
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rand() % howbig;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern long random( long howsmall, long howbig )
|
||||||
|
{
|
||||||
|
if (howsmall >= howbig)
|
||||||
|
{
|
||||||
|
return howsmall;
|
||||||
|
}
|
||||||
|
|
||||||
|
long diff = howbig - howsmall;
|
||||||
|
|
||||||
|
return random(diff) + howsmall;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern long map(long x, long in_min, long in_max, long out_min, long out_max)
|
||||||
|
{
|
||||||
|
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern uint16_t makeWord( uint16_t w )
|
||||||
|
{
|
||||||
|
return w ;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern uint16_t makeWord( uint8_t h, uint8_t l )
|
||||||
|
{
|
||||||
|
return (h << 8) | l ;
|
||||||
|
}
|
||||||
33
cores/samd10/WMath.h
Normal file
33
cores/samd10/WMath.h
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _WIRING_MATH_
|
||||||
|
#define _WIRING_MATH_
|
||||||
|
|
||||||
|
extern long random( long ) ;
|
||||||
|
extern long random( long, long ) ;
|
||||||
|
extern void randomSeed( uint32_t dwSeed ) ;
|
||||||
|
extern long map( long, long, long, long, long ) ;
|
||||||
|
|
||||||
|
extern uint16_t makeWord( uint16_t w ) ;
|
||||||
|
extern uint16_t makeWord( uint8_t h, uint8_t l ) ;
|
||||||
|
|
||||||
|
#define word(...) makeWord(__VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _WIRING_MATH_ */
|
||||||
747
cores/samd10/WString.cpp
Normal file
747
cores/samd10/WString.cpp
Normal file
|
|
@ -0,0 +1,747 @@
|
||||||
|
/*
|
||||||
|
WString.cpp - String library for Wiring & Arduino
|
||||||
|
...mostly rewritten by Paul Stoffregen...
|
||||||
|
Copyright (c) 2009-10 Hernando Barragan. All rights reserved.
|
||||||
|
Copyright 2011, Paul Stoffregen, paul@pjrc.com
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "WString.h"
|
||||||
|
#include "itoa.h"
|
||||||
|
#include "avr/dtostrf.h"
|
||||||
|
|
||||||
|
/*********************************************/
|
||||||
|
/* Constructors */
|
||||||
|
/*********************************************/
|
||||||
|
|
||||||
|
String::String(const char *cstr)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
if (cstr) copy(cstr, strlen(cstr));
|
||||||
|
}
|
||||||
|
|
||||||
|
String::String(const String &value)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
*this = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
String::String(const __FlashStringHelper *pstr)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
*this = pstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||||
|
String::String(String &&rval)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
move(rval);
|
||||||
|
}
|
||||||
|
String::String(StringSumHelper &&rval)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
move(rval);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
String::String(char c)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
char buf[2];
|
||||||
|
buf[0] = c;
|
||||||
|
buf[1] = 0;
|
||||||
|
*this = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
String::String(unsigned char value, unsigned char base)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
char buf[1 + 8 * sizeof(unsigned char)];
|
||||||
|
utoa(value, buf, base);
|
||||||
|
*this = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
String::String(int value, unsigned char base)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
char buf[2 + 8 * sizeof(int)];
|
||||||
|
itoa(value, buf, base);
|
||||||
|
*this = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
String::String(unsigned int value, unsigned char base)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
char buf[1 + 8 * sizeof(unsigned int)];
|
||||||
|
utoa(value, buf, base);
|
||||||
|
*this = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
String::String(long value, unsigned char base)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
char buf[2 + 8 * sizeof(long)];
|
||||||
|
ltoa(value, buf, base);
|
||||||
|
*this = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
String::String(unsigned long value, unsigned char base)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
char buf[1 + 8 * sizeof(unsigned long)];
|
||||||
|
ultoa(value, buf, base);
|
||||||
|
*this = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
String::String(float value, unsigned char decimalPlaces)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
char buf[33];
|
||||||
|
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
String::String(double value, unsigned char decimalPlaces)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
char buf[33];
|
||||||
|
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
String::~String()
|
||||||
|
{
|
||||||
|
free(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************/
|
||||||
|
/* Memory Management */
|
||||||
|
/*********************************************/
|
||||||
|
|
||||||
|
inline void String::init(void)
|
||||||
|
{
|
||||||
|
buffer = NULL;
|
||||||
|
capacity = 0;
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void String::invalidate(void)
|
||||||
|
{
|
||||||
|
if (buffer) free(buffer);
|
||||||
|
buffer = NULL;
|
||||||
|
capacity = len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::reserve(unsigned int size)
|
||||||
|
{
|
||||||
|
if (buffer && capacity >= size) return 1;
|
||||||
|
if (changeBuffer(size)) {
|
||||||
|
if (len == 0) buffer[0] = 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::changeBuffer(unsigned int maxStrLen)
|
||||||
|
{
|
||||||
|
char *newbuffer = (char *)realloc(buffer, maxStrLen + 1);
|
||||||
|
if (newbuffer) {
|
||||||
|
buffer = newbuffer;
|
||||||
|
capacity = maxStrLen;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************/
|
||||||
|
/* Copy and Move */
|
||||||
|
/*********************************************/
|
||||||
|
|
||||||
|
String & String::copy(const char *cstr, unsigned int length)
|
||||||
|
{
|
||||||
|
if (!reserve(length)) {
|
||||||
|
invalidate();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
len = length;
|
||||||
|
strcpy(buffer, cstr);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
String & String::copy(const __FlashStringHelper *pstr, unsigned int length)
|
||||||
|
{
|
||||||
|
if (!reserve(length)) {
|
||||||
|
invalidate();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
len = length;
|
||||||
|
strcpy_P(buffer, (PGM_P)pstr);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||||
|
void String::move(String &rhs)
|
||||||
|
{
|
||||||
|
if (buffer) {
|
||||||
|
if (capacity >= rhs.len) {
|
||||||
|
strcpy(buffer, rhs.buffer);
|
||||||
|
len = rhs.len;
|
||||||
|
rhs.len = 0;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
free(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buffer = rhs.buffer;
|
||||||
|
capacity = rhs.capacity;
|
||||||
|
len = rhs.len;
|
||||||
|
rhs.buffer = NULL;
|
||||||
|
rhs.capacity = 0;
|
||||||
|
rhs.len = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
String & String::operator = (const String &rhs)
|
||||||
|
{
|
||||||
|
if (this == &rhs) return *this;
|
||||||
|
|
||||||
|
if (rhs.buffer) copy(rhs.buffer, rhs.len);
|
||||||
|
else invalidate();
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||||
|
String & String::operator = (String &&rval)
|
||||||
|
{
|
||||||
|
if (this != &rval) move(rval);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
String & String::operator = (StringSumHelper &&rval)
|
||||||
|
{
|
||||||
|
if (this != &rval) move(rval);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
String & String::operator = (const char *cstr)
|
||||||
|
{
|
||||||
|
if (cstr) copy(cstr, strlen(cstr));
|
||||||
|
else invalidate();
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
String & String::operator = (const __FlashStringHelper *pstr)
|
||||||
|
{
|
||||||
|
if (pstr) copy(pstr, strlen_P((PGM_P)pstr));
|
||||||
|
else invalidate();
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************/
|
||||||
|
/* concat */
|
||||||
|
/*********************************************/
|
||||||
|
|
||||||
|
unsigned char String::concat(const String &s)
|
||||||
|
{
|
||||||
|
return concat(s.buffer, s.len);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::concat(const char *cstr, unsigned int length)
|
||||||
|
{
|
||||||
|
unsigned int newlen = len + length;
|
||||||
|
if (!cstr) return 0;
|
||||||
|
if (length == 0) return 1;
|
||||||
|
if (!reserve(newlen)) return 0;
|
||||||
|
strcpy(buffer + len, cstr);
|
||||||
|
len = newlen;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::concat(const char *cstr)
|
||||||
|
{
|
||||||
|
if (!cstr) return 0;
|
||||||
|
return concat(cstr, strlen(cstr));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::concat(char c)
|
||||||
|
{
|
||||||
|
char buf[2];
|
||||||
|
buf[0] = c;
|
||||||
|
buf[1] = 0;
|
||||||
|
return concat(buf, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::concat(unsigned char num)
|
||||||
|
{
|
||||||
|
char buf[1 + 3 * sizeof(unsigned char)];
|
||||||
|
itoa(num, buf, 10);
|
||||||
|
return concat(buf, strlen(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::concat(int num)
|
||||||
|
{
|
||||||
|
char buf[2 + 3 * sizeof(int)];
|
||||||
|
itoa(num, buf, 10);
|
||||||
|
return concat(buf, strlen(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::concat(unsigned int num)
|
||||||
|
{
|
||||||
|
char buf[1 + 3 * sizeof(unsigned int)];
|
||||||
|
utoa(num, buf, 10);
|
||||||
|
return concat(buf, strlen(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::concat(long num)
|
||||||
|
{
|
||||||
|
char buf[2 + 3 * sizeof(long)];
|
||||||
|
ltoa(num, buf, 10);
|
||||||
|
return concat(buf, strlen(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::concat(unsigned long num)
|
||||||
|
{
|
||||||
|
char buf[1 + 3 * sizeof(unsigned long)];
|
||||||
|
ultoa(num, buf, 10);
|
||||||
|
return concat(buf, strlen(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::concat(float num)
|
||||||
|
{
|
||||||
|
char buf[20];
|
||||||
|
char* string = dtostrf(num, 4, 2, buf);
|
||||||
|
return concat(string, strlen(string));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::concat(double num)
|
||||||
|
{
|
||||||
|
char buf[20];
|
||||||
|
char* string = dtostrf(num, 4, 2, buf);
|
||||||
|
return concat(string, strlen(string));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::concat(const __FlashStringHelper * str)
|
||||||
|
{
|
||||||
|
if (!str) return 0;
|
||||||
|
int length = strlen_P((const char *) str);
|
||||||
|
if (length == 0) return 1;
|
||||||
|
unsigned int newlen = len + length;
|
||||||
|
if (!reserve(newlen)) return 0;
|
||||||
|
strcpy_P(buffer + len, (const char *) str);
|
||||||
|
len = newlen;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************/
|
||||||
|
/* Concatenate */
|
||||||
|
/*********************************************/
|
||||||
|
|
||||||
|
StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs)
|
||||||
|
{
|
||||||
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
|
if (!a.concat(rhs.buffer, rhs.len)) a.invalidate();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr)
|
||||||
|
{
|
||||||
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
|
if (!cstr || !a.concat(cstr, strlen(cstr))) a.invalidate();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringSumHelper & operator + (const StringSumHelper &lhs, char c)
|
||||||
|
{
|
||||||
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
|
if (!a.concat(c)) a.invalidate();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num)
|
||||||
|
{
|
||||||
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
|
if (!a.concat(num)) a.invalidate();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringSumHelper & operator + (const StringSumHelper &lhs, int num)
|
||||||
|
{
|
||||||
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
|
if (!a.concat(num)) a.invalidate();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num)
|
||||||
|
{
|
||||||
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
|
if (!a.concat(num)) a.invalidate();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringSumHelper & operator + (const StringSumHelper &lhs, long num)
|
||||||
|
{
|
||||||
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
|
if (!a.concat(num)) a.invalidate();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num)
|
||||||
|
{
|
||||||
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
|
if (!a.concat(num)) a.invalidate();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringSumHelper & operator + (const StringSumHelper &lhs, float num)
|
||||||
|
{
|
||||||
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
|
if (!a.concat(num)) a.invalidate();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringSumHelper & operator + (const StringSumHelper &lhs, double num)
|
||||||
|
{
|
||||||
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
|
if (!a.concat(num)) a.invalidate();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs)
|
||||||
|
{
|
||||||
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
|
if (!a.concat(rhs)) a.invalidate();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************/
|
||||||
|
/* Comparison */
|
||||||
|
/*********************************************/
|
||||||
|
|
||||||
|
int String::compareTo(const String &s) const
|
||||||
|
{
|
||||||
|
if (!buffer || !s.buffer) {
|
||||||
|
if (s.buffer && s.len > 0) return 0 - *(unsigned char *)s.buffer;
|
||||||
|
if (buffer && len > 0) return *(unsigned char *)buffer;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return strcmp(buffer, s.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::equals(const String &s2) const
|
||||||
|
{
|
||||||
|
return (len == s2.len && compareTo(s2) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::equals(const char *cstr) const
|
||||||
|
{
|
||||||
|
if (len == 0) return (cstr == NULL || *cstr == 0);
|
||||||
|
if (cstr == NULL) return buffer[0] == 0;
|
||||||
|
return strcmp(buffer, cstr) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::operator<(const String &rhs) const
|
||||||
|
{
|
||||||
|
return compareTo(rhs) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::operator>(const String &rhs) const
|
||||||
|
{
|
||||||
|
return compareTo(rhs) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::operator<=(const String &rhs) const
|
||||||
|
{
|
||||||
|
return compareTo(rhs) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::operator>=(const String &rhs) const
|
||||||
|
{
|
||||||
|
return compareTo(rhs) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::equalsIgnoreCase( const String &s2 ) const
|
||||||
|
{
|
||||||
|
if (this == &s2) return 1;
|
||||||
|
if (len != s2.len) return 0;
|
||||||
|
if (len == 0) return 1;
|
||||||
|
const char *p1 = buffer;
|
||||||
|
const char *p2 = s2.buffer;
|
||||||
|
while (*p1) {
|
||||||
|
if (tolower(*p1++) != tolower(*p2++)) return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::startsWith( const String &s2 ) const
|
||||||
|
{
|
||||||
|
if (len < s2.len) return 0;
|
||||||
|
return startsWith(s2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::startsWith( const String &s2, unsigned int offset ) const
|
||||||
|
{
|
||||||
|
if (offset > len - s2.len || !buffer || !s2.buffer) return 0;
|
||||||
|
return strncmp( &buffer[offset], s2.buffer, s2.len ) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char String::endsWith( const String &s2 ) const
|
||||||
|
{
|
||||||
|
if ( len < s2.len || !buffer || !s2.buffer) return 0;
|
||||||
|
return strcmp(&buffer[len - s2.len], s2.buffer) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************/
|
||||||
|
/* Character Access */
|
||||||
|
/*********************************************/
|
||||||
|
|
||||||
|
char String::charAt(unsigned int loc) const
|
||||||
|
{
|
||||||
|
return operator[](loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void String::setCharAt(unsigned int loc, char c)
|
||||||
|
{
|
||||||
|
if (loc < len) buffer[loc] = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
char & String::operator[](unsigned int index)
|
||||||
|
{
|
||||||
|
static char dummy_writable_char;
|
||||||
|
if (index >= len || !buffer) {
|
||||||
|
dummy_writable_char = 0;
|
||||||
|
return dummy_writable_char;
|
||||||
|
}
|
||||||
|
return buffer[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
char String::operator[]( unsigned int index ) const
|
||||||
|
{
|
||||||
|
if (index >= len || !buffer) return 0;
|
||||||
|
return buffer[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const
|
||||||
|
{
|
||||||
|
if (!bufsize || !buf) return;
|
||||||
|
if (index >= len) {
|
||||||
|
buf[0] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
unsigned int n = bufsize - 1;
|
||||||
|
if (n > len - index) n = len - index;
|
||||||
|
strncpy((char *)buf, buffer + index, n);
|
||||||
|
buf[n] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************/
|
||||||
|
/* Search */
|
||||||
|
/*********************************************/
|
||||||
|
|
||||||
|
int String::indexOf(char c) const
|
||||||
|
{
|
||||||
|
return indexOf(c, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int String::indexOf( char ch, unsigned int fromIndex ) const
|
||||||
|
{
|
||||||
|
if (fromIndex >= len) return -1;
|
||||||
|
const char* temp = strchr(buffer + fromIndex, ch);
|
||||||
|
if (temp == NULL) return -1;
|
||||||
|
return temp - buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
int String::indexOf(const String &s2) const
|
||||||
|
{
|
||||||
|
return indexOf(s2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int String::indexOf(const String &s2, unsigned int fromIndex) const
|
||||||
|
{
|
||||||
|
if (fromIndex >= len) return -1;
|
||||||
|
const char *found = strstr(buffer + fromIndex, s2.buffer);
|
||||||
|
if (found == NULL) return -1;
|
||||||
|
return found - buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
int String::lastIndexOf( char theChar ) const
|
||||||
|
{
|
||||||
|
return lastIndexOf(theChar, len - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int String::lastIndexOf(char ch, unsigned int fromIndex) const
|
||||||
|
{
|
||||||
|
if (fromIndex >= len) return -1;
|
||||||
|
char tempchar = buffer[fromIndex + 1];
|
||||||
|
buffer[fromIndex + 1] = '\0';
|
||||||
|
char* temp = strrchr( buffer, ch );
|
||||||
|
buffer[fromIndex + 1] = tempchar;
|
||||||
|
if (temp == NULL) return -1;
|
||||||
|
return temp - buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
int String::lastIndexOf(const String &s2) const
|
||||||
|
{
|
||||||
|
return lastIndexOf(s2, len - s2.len);
|
||||||
|
}
|
||||||
|
|
||||||
|
int String::lastIndexOf(const String &s2, unsigned int fromIndex) const
|
||||||
|
{
|
||||||
|
if (s2.len == 0 || len == 0 || s2.len > len) return -1;
|
||||||
|
if (fromIndex >= len) fromIndex = len - 1;
|
||||||
|
int found = -1;
|
||||||
|
for (char *p = buffer; p <= buffer + fromIndex; p++) {
|
||||||
|
p = strstr(p, s2.buffer);
|
||||||
|
if (!p) break;
|
||||||
|
if ((unsigned int)(p - buffer) <= fromIndex) found = p - buffer;
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
String String::substring(unsigned int left, unsigned int right) const
|
||||||
|
{
|
||||||
|
if (left > right) {
|
||||||
|
unsigned int temp = right;
|
||||||
|
right = left;
|
||||||
|
left = temp;
|
||||||
|
}
|
||||||
|
String out;
|
||||||
|
if (left >= len) return out;
|
||||||
|
if (right > len) right = len;
|
||||||
|
char temp = buffer[right]; // save the replaced character
|
||||||
|
buffer[right] = '\0';
|
||||||
|
out = buffer + left; // pointer arithmetic
|
||||||
|
buffer[right] = temp; //restore character
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************/
|
||||||
|
/* Modification */
|
||||||
|
/*********************************************/
|
||||||
|
|
||||||
|
void String::replace(char find, char replace)
|
||||||
|
{
|
||||||
|
if (!buffer) return;
|
||||||
|
for (char *p = buffer; *p; p++) {
|
||||||
|
if (*p == find) *p = replace;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void String::replace(const String& find, const String& replace)
|
||||||
|
{
|
||||||
|
if (len == 0 || find.len == 0) return;
|
||||||
|
int diff = replace.len - find.len;
|
||||||
|
char *readFrom = buffer;
|
||||||
|
char *foundAt;
|
||||||
|
if (diff == 0) {
|
||||||
|
while ((foundAt = strstr(readFrom, find.buffer)) != NULL) {
|
||||||
|
memcpy(foundAt, replace.buffer, replace.len);
|
||||||
|
readFrom = foundAt + replace.len;
|
||||||
|
}
|
||||||
|
} else if (diff < 0) {
|
||||||
|
char *writeTo = buffer;
|
||||||
|
while ((foundAt = strstr(readFrom, find.buffer)) != NULL) {
|
||||||
|
unsigned int n = foundAt - readFrom;
|
||||||
|
memcpy(writeTo, readFrom, n);
|
||||||
|
writeTo += n;
|
||||||
|
memcpy(writeTo, replace.buffer, replace.len);
|
||||||
|
writeTo += replace.len;
|
||||||
|
readFrom = foundAt + find.len;
|
||||||
|
len += diff;
|
||||||
|
}
|
||||||
|
strcpy(writeTo, readFrom);
|
||||||
|
} else {
|
||||||
|
unsigned int size = len; // compute size needed for result
|
||||||
|
while ((foundAt = strstr(readFrom, find.buffer)) != NULL) {
|
||||||
|
readFrom = foundAt + find.len;
|
||||||
|
size += diff;
|
||||||
|
}
|
||||||
|
if (size == len) return;
|
||||||
|
if (size > capacity && !changeBuffer(size)) return; // XXX: tell user!
|
||||||
|
int index = len - 1;
|
||||||
|
while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) {
|
||||||
|
readFrom = buffer + index + find.len;
|
||||||
|
memmove(readFrom + diff, readFrom, len - (readFrom - buffer));
|
||||||
|
len += diff;
|
||||||
|
buffer[len] = 0;
|
||||||
|
memcpy(buffer + index, replace.buffer, replace.len);
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void String::remove(unsigned int index){
|
||||||
|
// Pass the biggest integer as the count. The remove method
|
||||||
|
// below will take care of truncating it at the end of the
|
||||||
|
// string.
|
||||||
|
remove(index, (unsigned int)-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void String::remove(unsigned int index, unsigned int count){
|
||||||
|
if (index >= len) { return; }
|
||||||
|
if (count <= 0) { return; }
|
||||||
|
if (count > len - index) { count = len - index; }
|
||||||
|
char *writeTo = buffer + index;
|
||||||
|
len = len - count;
|
||||||
|
strncpy(writeTo, buffer + index + count,len - index);
|
||||||
|
buffer[len] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void String::toLowerCase(void)
|
||||||
|
{
|
||||||
|
if (!buffer) return;
|
||||||
|
for (char *p = buffer; *p; p++) {
|
||||||
|
*p = tolower(*p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void String::toUpperCase(void)
|
||||||
|
{
|
||||||
|
if (!buffer) return;
|
||||||
|
for (char *p = buffer; *p; p++) {
|
||||||
|
*p = toupper(*p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void String::trim(void)
|
||||||
|
{
|
||||||
|
if (!buffer || len == 0) return;
|
||||||
|
char *begin = buffer;
|
||||||
|
while (isspace(*begin)) begin++;
|
||||||
|
char *end = buffer + len - 1;
|
||||||
|
while (isspace(*end) && end >= begin) end--;
|
||||||
|
len = end + 1 - begin;
|
||||||
|
if (begin > buffer) memcpy(buffer, begin, len);
|
||||||
|
buffer[len] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************/
|
||||||
|
/* Parsing / Conversion */
|
||||||
|
/*********************************************/
|
||||||
|
|
||||||
|
long String::toInt(void) const
|
||||||
|
{
|
||||||
|
if (buffer) return atol(buffer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float String::toFloat(void) const
|
||||||
|
{
|
||||||
|
if (buffer) return float(atof(buffer));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
226
cores/samd10/WString.h
Normal file
226
cores/samd10/WString.h
Normal file
|
|
@ -0,0 +1,226 @@
|
||||||
|
/*
|
||||||
|
WString.h - String library for Wiring & Arduino
|
||||||
|
...mostly rewritten by Paul Stoffregen...
|
||||||
|
Copyright (c) 2009-10 Hernando Barragan. All right reserved.
|
||||||
|
Copyright 2011, Paul Stoffregen, paul@pjrc.com
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef String_class_h
|
||||||
|
#define String_class_h
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
// When compiling programs with this class, the following gcc parameters
|
||||||
|
// dramatically increase performance and memory (RAM) efficiency, typically
|
||||||
|
// with little or no increase in code size.
|
||||||
|
// -felide-constructors
|
||||||
|
// -std=c++0x
|
||||||
|
|
||||||
|
class __FlashStringHelper;
|
||||||
|
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
|
||||||
|
|
||||||
|
// An inherited class for holding the result of a concatenation. These
|
||||||
|
// result objects are assumed to be writable by subsequent concatenations.
|
||||||
|
class StringSumHelper;
|
||||||
|
|
||||||
|
// The string class
|
||||||
|
class String
|
||||||
|
{
|
||||||
|
// use a function pointer to allow for "if (s)" without the
|
||||||
|
// complications of an operator bool(). for more information, see:
|
||||||
|
// http://www.artima.com/cppsource/safebool.html
|
||||||
|
typedef void (String::*StringIfHelperType)() const;
|
||||||
|
void StringIfHelper() const {}
|
||||||
|
|
||||||
|
public:
|
||||||
|
// constructors
|
||||||
|
// creates a copy of the initial value.
|
||||||
|
// if the initial value is null or invalid, or if memory allocation
|
||||||
|
// fails, the string will be marked as invalid (i.e. "if (s)" will
|
||||||
|
// be false).
|
||||||
|
String(const char *cstr = "");
|
||||||
|
String(const String &str);
|
||||||
|
String(const __FlashStringHelper *str);
|
||||||
|
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||||
|
String(String &&rval);
|
||||||
|
String(StringSumHelper &&rval);
|
||||||
|
#endif
|
||||||
|
explicit String(char c);
|
||||||
|
explicit String(unsigned char, unsigned char base=10);
|
||||||
|
explicit String(int, unsigned char base=10);
|
||||||
|
explicit String(unsigned int, unsigned char base=10);
|
||||||
|
explicit String(long, unsigned char base=10);
|
||||||
|
explicit String(unsigned long, unsigned char base=10);
|
||||||
|
explicit String(float, unsigned char decimalPlaces=2);
|
||||||
|
explicit String(double, unsigned char decimalPlaces=2);
|
||||||
|
~String(void);
|
||||||
|
|
||||||
|
// memory management
|
||||||
|
// return true on success, false on failure (in which case, the string
|
||||||
|
// is left unchanged). reserve(0), if successful, will validate an
|
||||||
|
// invalid string (i.e., "if (s)" will be true afterwards)
|
||||||
|
unsigned char reserve(unsigned int size);
|
||||||
|
inline unsigned int length(void) const {return len;}
|
||||||
|
|
||||||
|
// creates a copy of the assigned value. if the value is null or
|
||||||
|
// invalid, or if the memory allocation fails, the string will be
|
||||||
|
// marked as invalid ("if (s)" will be false).
|
||||||
|
String & operator = (const String &rhs);
|
||||||
|
String & operator = (const char *cstr);
|
||||||
|
String & operator = (const __FlashStringHelper *str);
|
||||||
|
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||||
|
String & operator = (String &&rval);
|
||||||
|
String & operator = (StringSumHelper &&rval);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// concatenate (works w/ built-in types)
|
||||||
|
|
||||||
|
// returns true on success, false on failure (in which case, the string
|
||||||
|
// is left unchanged). if the argument is null or invalid, the
|
||||||
|
// concatenation is considered unsucessful.
|
||||||
|
unsigned char concat(const String &str);
|
||||||
|
unsigned char concat(const char *cstr);
|
||||||
|
unsigned char concat(char c);
|
||||||
|
unsigned char concat(unsigned char c);
|
||||||
|
unsigned char concat(int num);
|
||||||
|
unsigned char concat(unsigned int num);
|
||||||
|
unsigned char concat(long num);
|
||||||
|
unsigned char concat(unsigned long num);
|
||||||
|
unsigned char concat(float num);
|
||||||
|
unsigned char concat(double num);
|
||||||
|
unsigned char concat(const __FlashStringHelper * str);
|
||||||
|
|
||||||
|
// if there's not enough memory for the concatenated value, the string
|
||||||
|
// will be left unchanged (but this isn't signalled in any way)
|
||||||
|
String & operator += (const String &rhs) {concat(rhs); return (*this);}
|
||||||
|
String & operator += (const char *cstr) {concat(cstr); return (*this);}
|
||||||
|
String & operator += (char c) {concat(c); return (*this);}
|
||||||
|
String & operator += (unsigned char num) {concat(num); return (*this);}
|
||||||
|
String & operator += (int num) {concat(num); return (*this);}
|
||||||
|
String & operator += (unsigned int num) {concat(num); return (*this);}
|
||||||
|
String & operator += (long num) {concat(num); return (*this);}
|
||||||
|
String & operator += (unsigned long num) {concat(num); return (*this);}
|
||||||
|
String & operator += (float num) {concat(num); return (*this);}
|
||||||
|
String & operator += (double num) {concat(num); return (*this);}
|
||||||
|
String & operator += (const __FlashStringHelper *str){concat(str); return (*this);}
|
||||||
|
|
||||||
|
friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
|
||||||
|
friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
|
||||||
|
friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
|
||||||
|
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num);
|
||||||
|
friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
|
||||||
|
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num);
|
||||||
|
friend StringSumHelper & operator + (const StringSumHelper &lhs, long num);
|
||||||
|
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num);
|
||||||
|
friend StringSumHelper & operator + (const StringSumHelper &lhs, float num);
|
||||||
|
friend StringSumHelper & operator + (const StringSumHelper &lhs, double num);
|
||||||
|
friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs);
|
||||||
|
|
||||||
|
// comparison (only works w/ Strings and "strings")
|
||||||
|
operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; }
|
||||||
|
int compareTo(const String &s) const;
|
||||||
|
unsigned char equals(const String &s) const;
|
||||||
|
unsigned char equals(const char *cstr) const;
|
||||||
|
unsigned char operator == (const String &rhs) const {return equals(rhs);}
|
||||||
|
unsigned char operator == (const char *cstr) const {return equals(cstr);}
|
||||||
|
unsigned char operator != (const String &rhs) const {return !equals(rhs);}
|
||||||
|
unsigned char operator != (const char *cstr) const {return !equals(cstr);}
|
||||||
|
unsigned char operator < (const String &rhs) const;
|
||||||
|
unsigned char operator > (const String &rhs) const;
|
||||||
|
unsigned char operator <= (const String &rhs) const;
|
||||||
|
unsigned char operator >= (const String &rhs) const;
|
||||||
|
unsigned char equalsIgnoreCase(const String &s) const;
|
||||||
|
unsigned char startsWith( const String &prefix) const;
|
||||||
|
unsigned char startsWith(const String &prefix, unsigned int offset) const;
|
||||||
|
unsigned char endsWith(const String &suffix) const;
|
||||||
|
|
||||||
|
// character acccess
|
||||||
|
char charAt(unsigned int index) const;
|
||||||
|
void setCharAt(unsigned int index, char c);
|
||||||
|
char operator [] (unsigned int index) const;
|
||||||
|
char& operator [] (unsigned int index);
|
||||||
|
void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const;
|
||||||
|
void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
|
||||||
|
{getBytes((unsigned char *)buf, bufsize, index);}
|
||||||
|
const char * c_str() const { return buffer; }
|
||||||
|
const char* begin() { return c_str(); }
|
||||||
|
const char* end() { return c_str() + length(); }
|
||||||
|
|
||||||
|
// search
|
||||||
|
int indexOf( char ch ) const;
|
||||||
|
int indexOf( char ch, unsigned int fromIndex ) const;
|
||||||
|
int indexOf( const String &str ) const;
|
||||||
|
int indexOf( const String &str, unsigned int fromIndex ) const;
|
||||||
|
int lastIndexOf( char ch ) const;
|
||||||
|
int lastIndexOf( char ch, unsigned int fromIndex ) const;
|
||||||
|
int lastIndexOf( const String &str ) const;
|
||||||
|
int lastIndexOf( const String &str, unsigned int fromIndex ) const;
|
||||||
|
String substring( unsigned int beginIndex ) const { return substring(beginIndex, len); };
|
||||||
|
String substring( unsigned int beginIndex, unsigned int endIndex ) const;
|
||||||
|
|
||||||
|
// modification
|
||||||
|
void replace(char find, char replace);
|
||||||
|
void replace(const String& find, const String& replace);
|
||||||
|
void remove(unsigned int index);
|
||||||
|
void remove(unsigned int index, unsigned int count);
|
||||||
|
void toLowerCase(void);
|
||||||
|
void toUpperCase(void);
|
||||||
|
void trim(void);
|
||||||
|
|
||||||
|
// parsing/conversion
|
||||||
|
long toInt(void) const;
|
||||||
|
float toFloat(void) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
char *buffer; // the actual char array
|
||||||
|
unsigned int capacity; // the array length minus one (for the '\0')
|
||||||
|
unsigned int len; // the String length (not counting the '\0')
|
||||||
|
protected:
|
||||||
|
void init(void);
|
||||||
|
void invalidate(void);
|
||||||
|
unsigned char changeBuffer(unsigned int maxStrLen);
|
||||||
|
unsigned char concat(const char *cstr, unsigned int length);
|
||||||
|
|
||||||
|
// copy and move
|
||||||
|
String & copy(const char *cstr, unsigned int length);
|
||||||
|
String & copy(const __FlashStringHelper *pstr, unsigned int length);
|
||||||
|
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||||
|
void move(String &rhs);
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
class StringSumHelper : public String
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
StringSumHelper(const String &s) : String(s) {}
|
||||||
|
StringSumHelper(const char *p) : String(p) {}
|
||||||
|
StringSumHelper(char c) : String(c) {}
|
||||||
|
StringSumHelper(unsigned char num) : String(num) {}
|
||||||
|
StringSumHelper(int num) : String(num) {}
|
||||||
|
StringSumHelper(unsigned int num) : String(num) {}
|
||||||
|
StringSumHelper(long num) : String(num) {}
|
||||||
|
StringSumHelper(unsigned long num) : String(num) {}
|
||||||
|
StringSumHelper(float num) : String(num) {}
|
||||||
|
StringSumHelper(double num) : String(num) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // __cplusplus
|
||||||
|
#endif // String_class_h
|
||||||
257
cores/samd10/WVariant.h
Normal file
257
cores/samd10/WVariant.h
Normal file
|
|
@ -0,0 +1,257 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "sam.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Definitions and types for pins */
|
||||||
|
typedef enum _EAnalogChannel
|
||||||
|
{
|
||||||
|
No_ADC_Channel=-1,
|
||||||
|
ADC_Channel0=0,
|
||||||
|
ADC_Channel1=1,
|
||||||
|
ADC_Channel2=2,
|
||||||
|
ADC_Channel3=3,
|
||||||
|
ADC_Channel4=4,
|
||||||
|
ADC_Channel5=5,
|
||||||
|
ADC_Channel6=6,
|
||||||
|
ADC_Channel7=7,
|
||||||
|
#if defined __SAMD21J18A__
|
||||||
|
ADC_Channel8=8,
|
||||||
|
ADC_Channel9=9,
|
||||||
|
#endif // __SAMD21J18A__
|
||||||
|
ADC_Channel10=10,
|
||||||
|
ADC_Channel11=11,
|
||||||
|
#if defined __SAMD21J18A__
|
||||||
|
ADC_Channel12=12,
|
||||||
|
ADC_Channel13=13,
|
||||||
|
ADC_Channel14=14,
|
||||||
|
ADC_Channel15=15,
|
||||||
|
#endif // __SAMD21J18A__
|
||||||
|
ADC_Channel16=16,
|
||||||
|
ADC_Channel17=17,
|
||||||
|
ADC_Channel18=18,
|
||||||
|
ADC_Channel19=19,
|
||||||
|
DAC_Channel0,
|
||||||
|
} EAnalogChannel ;
|
||||||
|
|
||||||
|
// Definitions for TC channels
|
||||||
|
typedef enum _ETCChannel
|
||||||
|
{
|
||||||
|
NOT_ON_TIMER=-1,
|
||||||
|
TCC0_CH0 = (0<<8)|(0),
|
||||||
|
TCC0_CH1 = (0<<8)|(1),
|
||||||
|
TCC0_CH2 = (0<<8)|(2),
|
||||||
|
TCC0_CH3 = (0<<8)|(3),
|
||||||
|
TCC0_CH4 = (0<<8)|(0), // Channel 4 is 0!
|
||||||
|
TCC0_CH5 = (0<<8)|(1), // Channel 5 is 1!
|
||||||
|
TCC0_CH6 = (0<<8)|(2), // Channel 6 is 2!
|
||||||
|
TCC0_CH7 = (0<<8)|(3), // Channel 7 is 3!
|
||||||
|
TCC1_CH0 = (1<<8)|(0),
|
||||||
|
TCC1_CH1 = (1<<8)|(1),
|
||||||
|
TCC1_CH2 = (1<<8)|(0), // Channel 2 is 0!
|
||||||
|
TCC1_CH3 = (1<<8)|(1), // Channel 3 is 1!
|
||||||
|
TCC2_CH0 = (2<<8)|(0),
|
||||||
|
TCC2_CH1 = (2<<8)|(1),
|
||||||
|
TCC2_CH2 = (2<<8)|(0), // Channel 2 is 0!
|
||||||
|
TCC2_CH3 = (2<<8)|(1), // Channel 3 is 1!
|
||||||
|
TC3_CH0 = (3<<8)|(0),
|
||||||
|
TC3_CH1 = (3<<8)|(1),
|
||||||
|
TC4_CH0 = (4<<8)|(0),
|
||||||
|
TC4_CH1 = (4<<8)|(1),
|
||||||
|
TC5_CH0 = (5<<8)|(0),
|
||||||
|
TC5_CH1 = (5<<8)|(1),
|
||||||
|
#if defined __SAMD21J18A__
|
||||||
|
TC6_CH0 = (6<<8)|(0),
|
||||||
|
TC6_CH1 = (6<<8)|(1),
|
||||||
|
TC7_CH0 = (7<<8)|(0),
|
||||||
|
TC7_CH1 = (7<<8)|(1),
|
||||||
|
#endif // __SAMD21J18A__
|
||||||
|
} ETCChannel ;
|
||||||
|
|
||||||
|
extern const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM] ;
|
||||||
|
|
||||||
|
#define GetTCNumber( x ) ( (x) >> 8 )
|
||||||
|
#define GetTCChannelNumber( x ) ( (x) & 0xff )
|
||||||
|
#define GetTC( x ) ( g_apTCInstances[(x) >> 8] )
|
||||||
|
|
||||||
|
// Definitions for PWM channels
|
||||||
|
typedef enum _EPWMChannel
|
||||||
|
{
|
||||||
|
NOT_ON_PWM=-1,
|
||||||
|
PWM0_CH0=TCC0_CH0,
|
||||||
|
PWM0_CH1=TCC0_CH1,
|
||||||
|
PWM0_CH2=TCC0_CH2,
|
||||||
|
PWM0_CH3=TCC0_CH3,
|
||||||
|
PWM0_CH4=TCC0_CH4,
|
||||||
|
PWM0_CH5=TCC0_CH5,
|
||||||
|
PWM0_CH6=TCC0_CH6,
|
||||||
|
PWM0_CH7=TCC0_CH7,
|
||||||
|
PWM1_CH0=TCC1_CH0,
|
||||||
|
PWM1_CH1=TCC1_CH1,
|
||||||
|
PWM1_CH2=TCC1_CH2,
|
||||||
|
PWM1_CH3=TCC1_CH3,
|
||||||
|
PWM2_CH0=TCC2_CH0,
|
||||||
|
PWM2_CH1=TCC2_CH1,
|
||||||
|
PWM2_CH2=TCC2_CH2,
|
||||||
|
PWM2_CH3=TCC2_CH3,
|
||||||
|
PWM3_CH0=TC3_CH0,
|
||||||
|
PWM3_CH1=TC3_CH1,
|
||||||
|
PWM4_CH0=TC4_CH0,
|
||||||
|
PWM4_CH1=TC4_CH1,
|
||||||
|
PWM5_CH0=TC5_CH0,
|
||||||
|
PWM5_CH1=TC5_CH1,
|
||||||
|
#if defined __SAMD21J18A__
|
||||||
|
PWM6_CH0=TC6_CH0,
|
||||||
|
PWM6_CH1=TC6_CH1,
|
||||||
|
PWM7_CH0=TC7_CH0,
|
||||||
|
PWM7_CH1=TC7_CH1,
|
||||||
|
#endif // __SAMD21J18A__
|
||||||
|
} EPWMChannel ;
|
||||||
|
|
||||||
|
typedef enum _EPortType
|
||||||
|
{
|
||||||
|
NOT_A_PORT=-1,
|
||||||
|
PORTA=0,
|
||||||
|
PORTB=1,
|
||||||
|
PORTC=2,
|
||||||
|
} EPortType ;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
EXTERNAL_INT_0 = 0,
|
||||||
|
EXTERNAL_INT_1,
|
||||||
|
EXTERNAL_INT_2,
|
||||||
|
EXTERNAL_INT_3,
|
||||||
|
EXTERNAL_INT_4,
|
||||||
|
EXTERNAL_INT_5,
|
||||||
|
EXTERNAL_INT_6,
|
||||||
|
EXTERNAL_INT_7,
|
||||||
|
EXTERNAL_INT_8,
|
||||||
|
EXTERNAL_INT_9,
|
||||||
|
EXTERNAL_INT_10,
|
||||||
|
EXTERNAL_INT_11,
|
||||||
|
EXTERNAL_INT_12,
|
||||||
|
EXTERNAL_INT_13,
|
||||||
|
EXTERNAL_INT_14,
|
||||||
|
EXTERNAL_INT_15,
|
||||||
|
EXTERNAL_INT_NMI,
|
||||||
|
EXTERNAL_NUM_INTERRUPTS,
|
||||||
|
NOT_AN_INTERRUPT = -1,
|
||||||
|
EXTERNAL_INT_NONE = NOT_AN_INTERRUPT,
|
||||||
|
} EExt_Interrupts ;
|
||||||
|
|
||||||
|
//A B C D E F G H
|
||||||
|
//EIC REF ADC AC PTC DAC SERCOM SERCOM_ALT TC/TCC TCC COM AC/GCLK
|
||||||
|
|
||||||
|
typedef enum _EPioType
|
||||||
|
{
|
||||||
|
PIO_NOT_A_PIN=-1, /* Not under control of a peripheral. */
|
||||||
|
PIO_EXTINT=0, /* The pin is controlled by the associated signal of peripheral A. */
|
||||||
|
PIO_ANALOG, /* The pin is controlled by the associated signal of peripheral B. */
|
||||||
|
PIO_SERCOM, /* The pin is controlled by the associated signal of peripheral C. */
|
||||||
|
PIO_SERCOM_ALT, /* The pin is controlled by the associated signal of peripheral D. */
|
||||||
|
PIO_TIMER, /* The pin is controlled by the associated signal of peripheral E. */
|
||||||
|
PIO_TIMER_ALT, /* The pin is controlled by the associated signal of peripheral F. */
|
||||||
|
PIO_COM, /* The pin is controlled by the associated signal of peripheral G. */
|
||||||
|
PIO_AC_CLK, /* The pin is controlled by the associated signal of peripheral H. */
|
||||||
|
PIO_DIGITAL, /* The pin is controlled by PORT. */
|
||||||
|
PIO_INPUT, /* The pin is controlled by PORT and is an input. */
|
||||||
|
PIO_INPUT_PULLUP, /* The pin is controlled by PORT and is an input with internal pull-up resistor enabled. */
|
||||||
|
PIO_OUTPUT, /* The pin is controlled by PORT and is an output. */
|
||||||
|
|
||||||
|
PIO_PWM=PIO_TIMER,
|
||||||
|
PIO_PWM_ALT=PIO_TIMER_ALT,
|
||||||
|
} EPioType ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pin Attributes to be OR-ed
|
||||||
|
*/
|
||||||
|
#define PIN_ATTR_NONE (0UL<<0)
|
||||||
|
#define PIN_ATTR_COMBO (1UL<<0)
|
||||||
|
#define PIN_ATTR_ANALOG (1UL<<1)
|
||||||
|
#define PIN_ATTR_DIGITAL (1UL<<2)
|
||||||
|
#define PIN_ATTR_PWM (1UL<<3)
|
||||||
|
#define PIN_ATTR_TIMER (1UL<<4)
|
||||||
|
#define PIN_ATTR_TIMER_ALT (1UL<<5)
|
||||||
|
#define PIN_ATTR_EXTINT (1UL<<6)
|
||||||
|
|
||||||
|
/* Types used for the table below */
|
||||||
|
typedef struct _PinDescription
|
||||||
|
{
|
||||||
|
EPortType ulPort ;
|
||||||
|
uint32_t ulPin ;
|
||||||
|
EPioType ulPinType ;
|
||||||
|
uint32_t ulPinAttribute ;
|
||||||
|
EAnalogChannel ulADCChannelNumber ; /* ADC Channel number in the SAM device */
|
||||||
|
EPWMChannel ulPWMChannel ;
|
||||||
|
ETCChannel ulTCChannel ;
|
||||||
|
EExt_Interrupts ulExtInt ;
|
||||||
|
} PinDescription ;
|
||||||
|
|
||||||
|
/* Pins table to be instantiated into variant.cpp */
|
||||||
|
extern const PinDescription g_APinDescription[] ;
|
||||||
|
|
||||||
|
/* Generic Clock Multiplexer IDs */
|
||||||
|
#define GCM_DFLL48M_REF (0x00U)
|
||||||
|
#define GCM_FDPLL96M_INPUT (0x01U)
|
||||||
|
#define GCM_FDPLL96M_32K (0x02U)
|
||||||
|
#define GCM_WDT (0x03U)
|
||||||
|
#define GCM_RTC (0x04U)
|
||||||
|
#define GCM_EIC (0x05U)
|
||||||
|
#define GCM_USB (0x06U)
|
||||||
|
#define GCM_EVSYS_CHANNEL_0 (0x07U)
|
||||||
|
#define GCM_EVSYS_CHANNEL_1 (0x08U)
|
||||||
|
#define GCM_EVSYS_CHANNEL_2 (0x09U)
|
||||||
|
#define GCM_EVSYS_CHANNEL_3 (0x0AU)
|
||||||
|
#define GCM_EVSYS_CHANNEL_4 (0x0BU)
|
||||||
|
#define GCM_EVSYS_CHANNEL_5 (0x0CU)
|
||||||
|
#define GCM_EVSYS_CHANNEL_6 (0x0DU)
|
||||||
|
#define GCM_EVSYS_CHANNEL_7 (0x0EU)
|
||||||
|
#define GCM_EVSYS_CHANNEL_8 (0x0FU)
|
||||||
|
#define GCM_EVSYS_CHANNEL_9 (0x10U)
|
||||||
|
#define GCM_EVSYS_CHANNEL_10 (0x11U)
|
||||||
|
#define GCM_EVSYS_CHANNEL_11 (0x12U)
|
||||||
|
#define GCM_SERCOMx_SLOW (0x13U)
|
||||||
|
#define GCM_SERCOM0_CORE (0x14U)
|
||||||
|
#define GCM_SERCOM1_CORE (0x15U)
|
||||||
|
#define GCM_SERCOM2_CORE (0x16U)
|
||||||
|
#define GCM_SERCOM3_CORE (0x17U)
|
||||||
|
#define GCM_SERCOM4_CORE (0x18U)
|
||||||
|
#define GCM_SERCOM5_CORE (0x19U)
|
||||||
|
#define GCM_TCC0_TCC1 (0x1AU)
|
||||||
|
#define GCM_TCC2_TC3 (0x1BU)
|
||||||
|
#define GCM_TC4_TC5 (0x1CU)
|
||||||
|
#define GCM_TC6_TC7 (0x1DU)
|
||||||
|
#define GCM_ADC (0x1EU)
|
||||||
|
#define GCM_AC_DIG (0x1FU)
|
||||||
|
#define GCM_AC_ANA (0x20U)
|
||||||
|
#define GCM_DAC (0x21U)
|
||||||
|
#define GCM_PTC (0x22U)
|
||||||
|
#define GCM_I2S_0 (0x23U)
|
||||||
|
#define GCM_I2S_1 (0x24U)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
37
cores/samd10/abi.cpp
Normal file
37
cores/samd10/abi.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
|
||||||
|
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
|
||||||
|
|
||||||
|
void __cxa_pure_virtual(void) {
|
||||||
|
// We might want to write some diagnostics to uart in this case
|
||||||
|
//std::terminate();
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
void __cxa_deleted_virtual(void) {
|
||||||
|
// We might want to write some diagnostics to uart in this case
|
||||||
|
//std::terminate();
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
30
cores/samd10/avr/dtostrf.c
Normal file
30
cores/samd10/avr/dtostrf.c
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
dtostrf - Emulation for dtostrf function from avr-libc
|
||||||
|
Copyright (c) 2015 Arduino LLC. All rights reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
|
||||||
|
asm(".global _printf_float");
|
||||||
|
|
||||||
|
char fmt[20];
|
||||||
|
sprintf(fmt, "%%%d.%df", width, prec);
|
||||||
|
sprintf(sout, fmt, val);
|
||||||
|
return sout;
|
||||||
|
}
|
||||||
|
|
||||||
30
cores/samd10/avr/dtostrf.h
Normal file
30
cores/samd10/avr/dtostrf.h
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
dtostrf - Emulation for dtostrf function from avr-libc
|
||||||
|
Copyright (c) 2015 Arduino LLC. All rights reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char *dtostrf(double val, signed char width, unsigned char prec, char *sout);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
23
cores/samd10/avr/interrupt.h
Normal file
23
cores/samd10/avr/interrupt.h
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LCC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Empty file.
|
||||||
|
This file is here to allow compatibility with sketches (made for AVR)
|
||||||
|
that includes <AVR/interrupt.h>
|
||||||
|
*/
|
||||||
121
cores/samd10/avr/pgmspace.h
Normal file
121
cores/samd10/avr/pgmspace.h
Normal file
|
|
@ -0,0 +1,121 @@
|
||||||
|
/*
|
||||||
|
pgmspace.h - Definitions for compatibility with AVR pgmspace macros
|
||||||
|
|
||||||
|
Copyright (c) 2015 Arduino LLC
|
||||||
|
|
||||||
|
Based on work of Paul Stoffregen on Teensy 3 (http://pjrc.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PGMSPACE_H_
|
||||||
|
#define __PGMSPACE_H_ 1
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#define PROGMEM
|
||||||
|
#define PGM_P const char *
|
||||||
|
#define PSTR(str) (str)
|
||||||
|
|
||||||
|
#define _SFR_BYTE(n) (n)
|
||||||
|
|
||||||
|
typedef void prog_void;
|
||||||
|
typedef char prog_char;
|
||||||
|
typedef unsigned char prog_uchar;
|
||||||
|
typedef int8_t prog_int8_t;
|
||||||
|
typedef uint8_t prog_uint8_t;
|
||||||
|
typedef int16_t prog_int16_t;
|
||||||
|
typedef uint16_t prog_uint16_t;
|
||||||
|
typedef int32_t prog_int32_t;
|
||||||
|
typedef uint32_t prog_uint32_t;
|
||||||
|
typedef int64_t prog_int64_t;
|
||||||
|
typedef uint64_t prog_uint64_t;
|
||||||
|
|
||||||
|
typedef const void* int_farptr_t;
|
||||||
|
typedef const void* uint_farptr_t;
|
||||||
|
|
||||||
|
#define memchr_P(s, c, n) memchr((s), (c), (n))
|
||||||
|
#define memcmp_P(s1, s2, n) memcmp((s1), (s2), (n))
|
||||||
|
#define memccpy_P(dest, src, c, n) memccpy((dest), (src), (c), (n))
|
||||||
|
#define memcpy_P(dest, src, n) memcpy((dest), (src), (n))
|
||||||
|
#define memmem_P(haystack, haystacklen, needle, needlelen) memmem((haystack), (haystacklen), (needle), (needlelen))
|
||||||
|
#define memrchr_P(s, c, n) memrchr((s), (c), (n))
|
||||||
|
#define strcat_P(dest, src) strcat((dest), (src))
|
||||||
|
#define strchr_P(s, c) strchr((s), (c))
|
||||||
|
#define strchrnul_P(s, c) strchrnul((s), (c))
|
||||||
|
#define strcmp_P(a, b) strcmp((a), (b))
|
||||||
|
#define strcpy_P(dest, src) strcpy((dest), (src))
|
||||||
|
#define strcasecmp_P(s1, s2) strcasecmp((s1), (s2))
|
||||||
|
#define strcasestr_P(haystack, needle) strcasestr((haystack), (needle))
|
||||||
|
#define strcspn_P(s, accept) strcspn((s), (accept))
|
||||||
|
#define strlcat_P(s1, s2, n) strlcat((s1), (s2), (n))
|
||||||
|
#define strlcpy_P(s1, s2, n) strlcpy((s1), (s2), (n))
|
||||||
|
#define strlen_P(a) strlen((a))
|
||||||
|
#define strnlen_P(s, n) strnlen((s), (n))
|
||||||
|
#define strncmp_P(s1, s2, n) strncmp((s1), (s2), (n))
|
||||||
|
#define strncasecmp_P(s1, s2, n) strncasecmp((s1), (s2), (n))
|
||||||
|
#define strncat_P(s1, s2, n) strncat((s1), (s2), (n))
|
||||||
|
#define strncpy_P(s1, s2, n) strncpy((s1), (s2), (n))
|
||||||
|
#define strpbrk_P(s, accept) strpbrk((s), (accept))
|
||||||
|
#define strrchr_P(s, c) strrchr((s), (c))
|
||||||
|
#define strsep_P(sp, delim) strsep((sp), (delim))
|
||||||
|
#define strspn_P(s, accept) strspn((s), (accept))
|
||||||
|
#define strstr_P(a, b) strstr((a), (b))
|
||||||
|
#define strtok_P(s, delim) strtok((s), (delim))
|
||||||
|
#define strtok_rP(s, delim, last) strtok((s), (delim), (last))
|
||||||
|
|
||||||
|
#define strlen_PF(a) strlen((a))
|
||||||
|
#define strnlen_PF(src, len) strnlen((src), (len))
|
||||||
|
#define memcpy_PF(dest, src, len) memcpy((dest), (src), (len))
|
||||||
|
#define strcpy_PF(dest, src) strcpy((dest), (src))
|
||||||
|
#define strncpy_PF(dest, src, len) strncpy((dest), (src), (len))
|
||||||
|
#define strcat_PF(dest, src) strcat((dest), (src))
|
||||||
|
#define strlcat_PF(dest, src, len) strlcat((dest), (src), (len))
|
||||||
|
#define strncat_PF(dest, src, len) strncat((dest), (src), (len))
|
||||||
|
#define strcmp_PF(s1, s2) strcmp((s1), (s2))
|
||||||
|
#define strncmp_PF(s1, s2, n) strncmp((s1), (s2), (n))
|
||||||
|
#define strcasecmp_PF(s1, s2) strcasecmp((s1), (s2))
|
||||||
|
#define strncasecmp_PF(s1, s2, n) strncasecmp((s1), (s2), (n))
|
||||||
|
#define strstr_PF(s1, s2) strstr((s1), (s2))
|
||||||
|
#define strlcpy_PF(dest, src, n) strlcpy((dest), (src), (n))
|
||||||
|
#define memcmp_PF(s1, s2, n) memcmp((s1), (s2), (n))
|
||||||
|
|
||||||
|
#define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__)
|
||||||
|
|
||||||
|
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
|
||||||
|
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
|
||||||
|
#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
|
||||||
|
#define pgm_read_float(addr) (*(const float *)(addr))
|
||||||
|
#define pgm_read_ptr(addr) (*(const void *)(addr))
|
||||||
|
|
||||||
|
#define pgm_read_byte_near(addr) pgm_read_byte(addr)
|
||||||
|
#define pgm_read_word_near(addr) pgm_read_word(addr)
|
||||||
|
#define pgm_read_dword_near(addr) pgm_read_dword(addr)
|
||||||
|
#define pgm_read_float_near(addr) pgm_read_float(addr)
|
||||||
|
#define pgm_read_ptr_near(addr) pgm_read_ptr(addr)
|
||||||
|
|
||||||
|
#define pgm_read_byte_far(addr) pgm_read_byte(addr)
|
||||||
|
#define pgm_read_word_far(addr) pgm_read_word(addr)
|
||||||
|
#define pgm_read_dword_far(addr) pgm_read_dword(addr)
|
||||||
|
#define pgm_read_float_far(addr) pgm_read_float(addr)
|
||||||
|
#define pgm_read_ptr_far(addr) pgm_read_ptr(addr)
|
||||||
|
|
||||||
|
#define pgm_get_far_address(addr) (&(addr))
|
||||||
|
|
||||||
|
#endif
|
||||||
534
cores/samd10/binary.h
Normal file
534
cores/samd10/binary.h
Normal file
|
|
@ -0,0 +1,534 @@
|
||||||
|
/*
|
||||||
|
binary.h - Definitions for binary constants
|
||||||
|
Copyright (c) 2006 David A. Mellis. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Binary_h
|
||||||
|
#define Binary_h
|
||||||
|
|
||||||
|
#define B0 0
|
||||||
|
#define B00 0
|
||||||
|
#define B000 0
|
||||||
|
#define B0000 0
|
||||||
|
#define B00000 0
|
||||||
|
#define B000000 0
|
||||||
|
#define B0000000 0
|
||||||
|
#define B00000000 0
|
||||||
|
#define B1 1
|
||||||
|
#define B01 1
|
||||||
|
#define B001 1
|
||||||
|
#define B0001 1
|
||||||
|
#define B00001 1
|
||||||
|
#define B000001 1
|
||||||
|
#define B0000001 1
|
||||||
|
#define B00000001 1
|
||||||
|
#define B10 2
|
||||||
|
#define B010 2
|
||||||
|
#define B0010 2
|
||||||
|
#define B00010 2
|
||||||
|
#define B000010 2
|
||||||
|
#define B0000010 2
|
||||||
|
#define B00000010 2
|
||||||
|
#define B11 3
|
||||||
|
#define B011 3
|
||||||
|
#define B0011 3
|
||||||
|
#define B00011 3
|
||||||
|
#define B000011 3
|
||||||
|
#define B0000011 3
|
||||||
|
#define B00000011 3
|
||||||
|
#define B100 4
|
||||||
|
#define B0100 4
|
||||||
|
#define B00100 4
|
||||||
|
#define B000100 4
|
||||||
|
#define B0000100 4
|
||||||
|
#define B00000100 4
|
||||||
|
#define B101 5
|
||||||
|
#define B0101 5
|
||||||
|
#define B00101 5
|
||||||
|
#define B000101 5
|
||||||
|
#define B0000101 5
|
||||||
|
#define B00000101 5
|
||||||
|
#define B110 6
|
||||||
|
#define B0110 6
|
||||||
|
#define B00110 6
|
||||||
|
#define B000110 6
|
||||||
|
#define B0000110 6
|
||||||
|
#define B00000110 6
|
||||||
|
#define B111 7
|
||||||
|
#define B0111 7
|
||||||
|
#define B00111 7
|
||||||
|
#define B000111 7
|
||||||
|
#define B0000111 7
|
||||||
|
#define B00000111 7
|
||||||
|
#define B1000 8
|
||||||
|
#define B01000 8
|
||||||
|
#define B001000 8
|
||||||
|
#define B0001000 8
|
||||||
|
#define B00001000 8
|
||||||
|
#define B1001 9
|
||||||
|
#define B01001 9
|
||||||
|
#define B001001 9
|
||||||
|
#define B0001001 9
|
||||||
|
#define B00001001 9
|
||||||
|
#define B1010 10
|
||||||
|
#define B01010 10
|
||||||
|
#define B001010 10
|
||||||
|
#define B0001010 10
|
||||||
|
#define B00001010 10
|
||||||
|
#define B1011 11
|
||||||
|
#define B01011 11
|
||||||
|
#define B001011 11
|
||||||
|
#define B0001011 11
|
||||||
|
#define B00001011 11
|
||||||
|
#define B1100 12
|
||||||
|
#define B01100 12
|
||||||
|
#define B001100 12
|
||||||
|
#define B0001100 12
|
||||||
|
#define B00001100 12
|
||||||
|
#define B1101 13
|
||||||
|
#define B01101 13
|
||||||
|
#define B001101 13
|
||||||
|
#define B0001101 13
|
||||||
|
#define B00001101 13
|
||||||
|
#define B1110 14
|
||||||
|
#define B01110 14
|
||||||
|
#define B001110 14
|
||||||
|
#define B0001110 14
|
||||||
|
#define B00001110 14
|
||||||
|
#define B1111 15
|
||||||
|
#define B01111 15
|
||||||
|
#define B001111 15
|
||||||
|
#define B0001111 15
|
||||||
|
#define B00001111 15
|
||||||
|
#define B10000 16
|
||||||
|
#define B010000 16
|
||||||
|
#define B0010000 16
|
||||||
|
#define B00010000 16
|
||||||
|
#define B10001 17
|
||||||
|
#define B010001 17
|
||||||
|
#define B0010001 17
|
||||||
|
#define B00010001 17
|
||||||
|
#define B10010 18
|
||||||
|
#define B010010 18
|
||||||
|
#define B0010010 18
|
||||||
|
#define B00010010 18
|
||||||
|
#define B10011 19
|
||||||
|
#define B010011 19
|
||||||
|
#define B0010011 19
|
||||||
|
#define B00010011 19
|
||||||
|
#define B10100 20
|
||||||
|
#define B010100 20
|
||||||
|
#define B0010100 20
|
||||||
|
#define B00010100 20
|
||||||
|
#define B10101 21
|
||||||
|
#define B010101 21
|
||||||
|
#define B0010101 21
|
||||||
|
#define B00010101 21
|
||||||
|
#define B10110 22
|
||||||
|
#define B010110 22
|
||||||
|
#define B0010110 22
|
||||||
|
#define B00010110 22
|
||||||
|
#define B10111 23
|
||||||
|
#define B010111 23
|
||||||
|
#define B0010111 23
|
||||||
|
#define B00010111 23
|
||||||
|
#define B11000 24
|
||||||
|
#define B011000 24
|
||||||
|
#define B0011000 24
|
||||||
|
#define B00011000 24
|
||||||
|
#define B11001 25
|
||||||
|
#define B011001 25
|
||||||
|
#define B0011001 25
|
||||||
|
#define B00011001 25
|
||||||
|
#define B11010 26
|
||||||
|
#define B011010 26
|
||||||
|
#define B0011010 26
|
||||||
|
#define B00011010 26
|
||||||
|
#define B11011 27
|
||||||
|
#define B011011 27
|
||||||
|
#define B0011011 27
|
||||||
|
#define B00011011 27
|
||||||
|
#define B11100 28
|
||||||
|
#define B011100 28
|
||||||
|
#define B0011100 28
|
||||||
|
#define B00011100 28
|
||||||
|
#define B11101 29
|
||||||
|
#define B011101 29
|
||||||
|
#define B0011101 29
|
||||||
|
#define B00011101 29
|
||||||
|
#define B11110 30
|
||||||
|
#define B011110 30
|
||||||
|
#define B0011110 30
|
||||||
|
#define B00011110 30
|
||||||
|
#define B11111 31
|
||||||
|
#define B011111 31
|
||||||
|
#define B0011111 31
|
||||||
|
#define B00011111 31
|
||||||
|
#define B100000 32
|
||||||
|
#define B0100000 32
|
||||||
|
#define B00100000 32
|
||||||
|
#define B100001 33
|
||||||
|
#define B0100001 33
|
||||||
|
#define B00100001 33
|
||||||
|
#define B100010 34
|
||||||
|
#define B0100010 34
|
||||||
|
#define B00100010 34
|
||||||
|
#define B100011 35
|
||||||
|
#define B0100011 35
|
||||||
|
#define B00100011 35
|
||||||
|
#define B100100 36
|
||||||
|
#define B0100100 36
|
||||||
|
#define B00100100 36
|
||||||
|
#define B100101 37
|
||||||
|
#define B0100101 37
|
||||||
|
#define B00100101 37
|
||||||
|
#define B100110 38
|
||||||
|
#define B0100110 38
|
||||||
|
#define B00100110 38
|
||||||
|
#define B100111 39
|
||||||
|
#define B0100111 39
|
||||||
|
#define B00100111 39
|
||||||
|
#define B101000 40
|
||||||
|
#define B0101000 40
|
||||||
|
#define B00101000 40
|
||||||
|
#define B101001 41
|
||||||
|
#define B0101001 41
|
||||||
|
#define B00101001 41
|
||||||
|
#define B101010 42
|
||||||
|
#define B0101010 42
|
||||||
|
#define B00101010 42
|
||||||
|
#define B101011 43
|
||||||
|
#define B0101011 43
|
||||||
|
#define B00101011 43
|
||||||
|
#define B101100 44
|
||||||
|
#define B0101100 44
|
||||||
|
#define B00101100 44
|
||||||
|
#define B101101 45
|
||||||
|
#define B0101101 45
|
||||||
|
#define B00101101 45
|
||||||
|
#define B101110 46
|
||||||
|
#define B0101110 46
|
||||||
|
#define B00101110 46
|
||||||
|
#define B101111 47
|
||||||
|
#define B0101111 47
|
||||||
|
#define B00101111 47
|
||||||
|
#define B110000 48
|
||||||
|
#define B0110000 48
|
||||||
|
#define B00110000 48
|
||||||
|
#define B110001 49
|
||||||
|
#define B0110001 49
|
||||||
|
#define B00110001 49
|
||||||
|
#define B110010 50
|
||||||
|
#define B0110010 50
|
||||||
|
#define B00110010 50
|
||||||
|
#define B110011 51
|
||||||
|
#define B0110011 51
|
||||||
|
#define B00110011 51
|
||||||
|
#define B110100 52
|
||||||
|
#define B0110100 52
|
||||||
|
#define B00110100 52
|
||||||
|
#define B110101 53
|
||||||
|
#define B0110101 53
|
||||||
|
#define B00110101 53
|
||||||
|
#define B110110 54
|
||||||
|
#define B0110110 54
|
||||||
|
#define B00110110 54
|
||||||
|
#define B110111 55
|
||||||
|
#define B0110111 55
|
||||||
|
#define B00110111 55
|
||||||
|
#define B111000 56
|
||||||
|
#define B0111000 56
|
||||||
|
#define B00111000 56
|
||||||
|
#define B111001 57
|
||||||
|
#define B0111001 57
|
||||||
|
#define B00111001 57
|
||||||
|
#define B111010 58
|
||||||
|
#define B0111010 58
|
||||||
|
#define B00111010 58
|
||||||
|
#define B111011 59
|
||||||
|
#define B0111011 59
|
||||||
|
#define B00111011 59
|
||||||
|
#define B111100 60
|
||||||
|
#define B0111100 60
|
||||||
|
#define B00111100 60
|
||||||
|
#define B111101 61
|
||||||
|
#define B0111101 61
|
||||||
|
#define B00111101 61
|
||||||
|
#define B111110 62
|
||||||
|
#define B0111110 62
|
||||||
|
#define B00111110 62
|
||||||
|
#define B111111 63
|
||||||
|
#define B0111111 63
|
||||||
|
#define B00111111 63
|
||||||
|
#define B1000000 64
|
||||||
|
#define B01000000 64
|
||||||
|
#define B1000001 65
|
||||||
|
#define B01000001 65
|
||||||
|
#define B1000010 66
|
||||||
|
#define B01000010 66
|
||||||
|
#define B1000011 67
|
||||||
|
#define B01000011 67
|
||||||
|
#define B1000100 68
|
||||||
|
#define B01000100 68
|
||||||
|
#define B1000101 69
|
||||||
|
#define B01000101 69
|
||||||
|
#define B1000110 70
|
||||||
|
#define B01000110 70
|
||||||
|
#define B1000111 71
|
||||||
|
#define B01000111 71
|
||||||
|
#define B1001000 72
|
||||||
|
#define B01001000 72
|
||||||
|
#define B1001001 73
|
||||||
|
#define B01001001 73
|
||||||
|
#define B1001010 74
|
||||||
|
#define B01001010 74
|
||||||
|
#define B1001011 75
|
||||||
|
#define B01001011 75
|
||||||
|
#define B1001100 76
|
||||||
|
#define B01001100 76
|
||||||
|
#define B1001101 77
|
||||||
|
#define B01001101 77
|
||||||
|
#define B1001110 78
|
||||||
|
#define B01001110 78
|
||||||
|
#define B1001111 79
|
||||||
|
#define B01001111 79
|
||||||
|
#define B1010000 80
|
||||||
|
#define B01010000 80
|
||||||
|
#define B1010001 81
|
||||||
|
#define B01010001 81
|
||||||
|
#define B1010010 82
|
||||||
|
#define B01010010 82
|
||||||
|
#define B1010011 83
|
||||||
|
#define B01010011 83
|
||||||
|
#define B1010100 84
|
||||||
|
#define B01010100 84
|
||||||
|
#define B1010101 85
|
||||||
|
#define B01010101 85
|
||||||
|
#define B1010110 86
|
||||||
|
#define B01010110 86
|
||||||
|
#define B1010111 87
|
||||||
|
#define B01010111 87
|
||||||
|
#define B1011000 88
|
||||||
|
#define B01011000 88
|
||||||
|
#define B1011001 89
|
||||||
|
#define B01011001 89
|
||||||
|
#define B1011010 90
|
||||||
|
#define B01011010 90
|
||||||
|
#define B1011011 91
|
||||||
|
#define B01011011 91
|
||||||
|
#define B1011100 92
|
||||||
|
#define B01011100 92
|
||||||
|
#define B1011101 93
|
||||||
|
#define B01011101 93
|
||||||
|
#define B1011110 94
|
||||||
|
#define B01011110 94
|
||||||
|
#define B1011111 95
|
||||||
|
#define B01011111 95
|
||||||
|
#define B1100000 96
|
||||||
|
#define B01100000 96
|
||||||
|
#define B1100001 97
|
||||||
|
#define B01100001 97
|
||||||
|
#define B1100010 98
|
||||||
|
#define B01100010 98
|
||||||
|
#define B1100011 99
|
||||||
|
#define B01100011 99
|
||||||
|
#define B1100100 100
|
||||||
|
#define B01100100 100
|
||||||
|
#define B1100101 101
|
||||||
|
#define B01100101 101
|
||||||
|
#define B1100110 102
|
||||||
|
#define B01100110 102
|
||||||
|
#define B1100111 103
|
||||||
|
#define B01100111 103
|
||||||
|
#define B1101000 104
|
||||||
|
#define B01101000 104
|
||||||
|
#define B1101001 105
|
||||||
|
#define B01101001 105
|
||||||
|
#define B1101010 106
|
||||||
|
#define B01101010 106
|
||||||
|
#define B1101011 107
|
||||||
|
#define B01101011 107
|
||||||
|
#define B1101100 108
|
||||||
|
#define B01101100 108
|
||||||
|
#define B1101101 109
|
||||||
|
#define B01101101 109
|
||||||
|
#define B1101110 110
|
||||||
|
#define B01101110 110
|
||||||
|
#define B1101111 111
|
||||||
|
#define B01101111 111
|
||||||
|
#define B1110000 112
|
||||||
|
#define B01110000 112
|
||||||
|
#define B1110001 113
|
||||||
|
#define B01110001 113
|
||||||
|
#define B1110010 114
|
||||||
|
#define B01110010 114
|
||||||
|
#define B1110011 115
|
||||||
|
#define B01110011 115
|
||||||
|
#define B1110100 116
|
||||||
|
#define B01110100 116
|
||||||
|
#define B1110101 117
|
||||||
|
#define B01110101 117
|
||||||
|
#define B1110110 118
|
||||||
|
#define B01110110 118
|
||||||
|
#define B1110111 119
|
||||||
|
#define B01110111 119
|
||||||
|
#define B1111000 120
|
||||||
|
#define B01111000 120
|
||||||
|
#define B1111001 121
|
||||||
|
#define B01111001 121
|
||||||
|
#define B1111010 122
|
||||||
|
#define B01111010 122
|
||||||
|
#define B1111011 123
|
||||||
|
#define B01111011 123
|
||||||
|
#define B1111100 124
|
||||||
|
#define B01111100 124
|
||||||
|
#define B1111101 125
|
||||||
|
#define B01111101 125
|
||||||
|
#define B1111110 126
|
||||||
|
#define B01111110 126
|
||||||
|
#define B1111111 127
|
||||||
|
#define B01111111 127
|
||||||
|
#define B10000000 128
|
||||||
|
#define B10000001 129
|
||||||
|
#define B10000010 130
|
||||||
|
#define B10000011 131
|
||||||
|
#define B10000100 132
|
||||||
|
#define B10000101 133
|
||||||
|
#define B10000110 134
|
||||||
|
#define B10000111 135
|
||||||
|
#define B10001000 136
|
||||||
|
#define B10001001 137
|
||||||
|
#define B10001010 138
|
||||||
|
#define B10001011 139
|
||||||
|
#define B10001100 140
|
||||||
|
#define B10001101 141
|
||||||
|
#define B10001110 142
|
||||||
|
#define B10001111 143
|
||||||
|
#define B10010000 144
|
||||||
|
#define B10010001 145
|
||||||
|
#define B10010010 146
|
||||||
|
#define B10010011 147
|
||||||
|
#define B10010100 148
|
||||||
|
#define B10010101 149
|
||||||
|
#define B10010110 150
|
||||||
|
#define B10010111 151
|
||||||
|
#define B10011000 152
|
||||||
|
#define B10011001 153
|
||||||
|
#define B10011010 154
|
||||||
|
#define B10011011 155
|
||||||
|
#define B10011100 156
|
||||||
|
#define B10011101 157
|
||||||
|
#define B10011110 158
|
||||||
|
#define B10011111 159
|
||||||
|
#define B10100000 160
|
||||||
|
#define B10100001 161
|
||||||
|
#define B10100010 162
|
||||||
|
#define B10100011 163
|
||||||
|
#define B10100100 164
|
||||||
|
#define B10100101 165
|
||||||
|
#define B10100110 166
|
||||||
|
#define B10100111 167
|
||||||
|
#define B10101000 168
|
||||||
|
#define B10101001 169
|
||||||
|
#define B10101010 170
|
||||||
|
#define B10101011 171
|
||||||
|
#define B10101100 172
|
||||||
|
#define B10101101 173
|
||||||
|
#define B10101110 174
|
||||||
|
#define B10101111 175
|
||||||
|
#define B10110000 176
|
||||||
|
#define B10110001 177
|
||||||
|
#define B10110010 178
|
||||||
|
#define B10110011 179
|
||||||
|
#define B10110100 180
|
||||||
|
#define B10110101 181
|
||||||
|
#define B10110110 182
|
||||||
|
#define B10110111 183
|
||||||
|
#define B10111000 184
|
||||||
|
#define B10111001 185
|
||||||
|
#define B10111010 186
|
||||||
|
#define B10111011 187
|
||||||
|
#define B10111100 188
|
||||||
|
#define B10111101 189
|
||||||
|
#define B10111110 190
|
||||||
|
#define B10111111 191
|
||||||
|
#define B11000000 192
|
||||||
|
#define B11000001 193
|
||||||
|
#define B11000010 194
|
||||||
|
#define B11000011 195
|
||||||
|
#define B11000100 196
|
||||||
|
#define B11000101 197
|
||||||
|
#define B11000110 198
|
||||||
|
#define B11000111 199
|
||||||
|
#define B11001000 200
|
||||||
|
#define B11001001 201
|
||||||
|
#define B11001010 202
|
||||||
|
#define B11001011 203
|
||||||
|
#define B11001100 204
|
||||||
|
#define B11001101 205
|
||||||
|
#define B11001110 206
|
||||||
|
#define B11001111 207
|
||||||
|
#define B11010000 208
|
||||||
|
#define B11010001 209
|
||||||
|
#define B11010010 210
|
||||||
|
#define B11010011 211
|
||||||
|
#define B11010100 212
|
||||||
|
#define B11010101 213
|
||||||
|
#define B11010110 214
|
||||||
|
#define B11010111 215
|
||||||
|
#define B11011000 216
|
||||||
|
#define B11011001 217
|
||||||
|
#define B11011010 218
|
||||||
|
#define B11011011 219
|
||||||
|
#define B11011100 220
|
||||||
|
#define B11011101 221
|
||||||
|
#define B11011110 222
|
||||||
|
#define B11011111 223
|
||||||
|
#define B11100000 224
|
||||||
|
#define B11100001 225
|
||||||
|
#define B11100010 226
|
||||||
|
#define B11100011 227
|
||||||
|
#define B11100100 228
|
||||||
|
#define B11100101 229
|
||||||
|
#define B11100110 230
|
||||||
|
#define B11100111 231
|
||||||
|
#define B11101000 232
|
||||||
|
#define B11101001 233
|
||||||
|
#define B11101010 234
|
||||||
|
#define B11101011 235
|
||||||
|
#define B11101100 236
|
||||||
|
#define B11101101 237
|
||||||
|
#define B11101110 238
|
||||||
|
#define B11101111 239
|
||||||
|
#define B11110000 240
|
||||||
|
#define B11110001 241
|
||||||
|
#define B11110010 242
|
||||||
|
#define B11110011 243
|
||||||
|
#define B11110100 244
|
||||||
|
#define B11110101 245
|
||||||
|
#define B11110110 246
|
||||||
|
#define B11110111 247
|
||||||
|
#define B11111000 248
|
||||||
|
#define B11111001 249
|
||||||
|
#define B11111010 250
|
||||||
|
#define B11111011 251
|
||||||
|
#define B11111100 252
|
||||||
|
#define B11111101 253
|
||||||
|
#define B11111110 254
|
||||||
|
#define B11111111 255
|
||||||
|
|
||||||
|
#endif
|
||||||
191
cores/samd10/cortex_handlers.c
Normal file
191
cores/samd10/cortex_handlers.c
Normal file
|
|
@ -0,0 +1,191 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sam.h>
|
||||||
|
#include <variant.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* RTOS Hooks */
|
||||||
|
extern void svcHook(void);
|
||||||
|
extern void pendSVHook(void);
|
||||||
|
extern int sysTickHook(void);
|
||||||
|
|
||||||
|
/* Default empty handler */
|
||||||
|
void Dummy_Handler(void)
|
||||||
|
{
|
||||||
|
#if defined DEBUG
|
||||||
|
__BKPT(3);
|
||||||
|
#endif
|
||||||
|
for (;;) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cortex-M0+ core handlers */
|
||||||
|
void HardFault_Handler(void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void Reest_Handler (void);
|
||||||
|
void NMI_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SVC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void PendSV_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SysTick_Handler (void);
|
||||||
|
|
||||||
|
/* Peripherals handlers */
|
||||||
|
void PM_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SYSCTRL_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void WDT_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void RTC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void EIC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void NVMCTRL_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void DMAC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void USB_Handler (void) __attribute__ ((weak));
|
||||||
|
void EVSYS_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SERCOM0_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SERCOM1_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SERCOM2_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SERCOM3_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SERCOM4_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void SERCOM5_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void TCC0_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void TCC1_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void TCC2_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void TC3_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void TC4_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void TC5_Handler (void) __attribute__ ((weak)); // Used in Tone.cpp
|
||||||
|
void TC6_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void TC7_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void ADC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void AC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void DAC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void PTC_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
void I2S_Handler (void) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||||
|
|
||||||
|
/* Initialize segments */
|
||||||
|
extern uint32_t __etext;
|
||||||
|
extern uint32_t __data_start__;
|
||||||
|
extern uint32_t __data_end__;
|
||||||
|
extern uint32_t __bss_start__;
|
||||||
|
extern uint32_t __bss_end__;
|
||||||
|
extern uint32_t __StackTop;
|
||||||
|
|
||||||
|
/* Exception Table */
|
||||||
|
__attribute__ ((section(".isr_vector"))) const DeviceVectors exception_table =
|
||||||
|
{
|
||||||
|
/* Configure Initial Stack Pointer, using linker-generated symbols */
|
||||||
|
(void*) (&__StackTop),
|
||||||
|
|
||||||
|
(void*) Reset_Handler,
|
||||||
|
(void*) NMI_Handler,
|
||||||
|
(void*) HardFault_Handler,
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) SVC_Handler,
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) (0UL), /* Reserved */
|
||||||
|
(void*) PendSV_Handler,
|
||||||
|
(void*) SysTick_Handler,
|
||||||
|
|
||||||
|
/* Configurable interrupts */
|
||||||
|
(void*) PM_Handler, /* 0 Power Manager */
|
||||||
|
(void*) SYSCTRL_Handler, /* 1 System Control */
|
||||||
|
(void*) WDT_Handler, /* 2 Watchdog Timer */
|
||||||
|
(void*) RTC_Handler, /* 3 Real-Time Counter */
|
||||||
|
(void*) EIC_Handler, /* 4 External Interrupt Controller */
|
||||||
|
(void*) NVMCTRL_Handler, /* 5 Non-Volatile Memory Controller */
|
||||||
|
(void*) DMAC_Handler, /* 6 Direct Memory Access Controller */
|
||||||
|
(void*) USB_Handler, /* 7 Universal Serial Bus */
|
||||||
|
(void*) EVSYS_Handler, /* 8 Event System Interface */
|
||||||
|
(void*) SERCOM0_Handler, /* 9 Serial Communication Interface 0 */
|
||||||
|
(void*) SERCOM1_Handler, /* 10 Serial Communication Interface 1 */
|
||||||
|
(void*) SERCOM2_Handler, /* 11 Serial Communication Interface 2 */
|
||||||
|
(void*) SERCOM3_Handler, /* 12 Serial Communication Interface 3 */
|
||||||
|
(void*) SERCOM4_Handler, /* 13 Serial Communication Interface 4 */
|
||||||
|
(void*) SERCOM5_Handler, /* 14 Serial Communication Interface 5 */
|
||||||
|
(void*) TCC0_Handler, /* 15 Timer Counter Control 0 */
|
||||||
|
(void*) TCC1_Handler, /* 16 Timer Counter Control 1 */
|
||||||
|
(void*) TCC2_Handler, /* 17 Timer Counter Control 2 */
|
||||||
|
(void*) TC3_Handler, /* 18 Basic Timer Counter 0 */
|
||||||
|
(void*) TC4_Handler, /* 19 Basic Timer Counter 1 */
|
||||||
|
(void*) TC5_Handler, /* 20 Basic Timer Counter 2 */
|
||||||
|
(void*) TC6_Handler, /* 21 Basic Timer Counter 3 */
|
||||||
|
(void*) TC7_Handler, /* 22 Basic Timer Counter 4 */
|
||||||
|
(void*) ADC_Handler, /* 23 Analog Digital Converter */
|
||||||
|
(void*) AC_Handler, /* 24 Analog Comparators */
|
||||||
|
(void*) DAC_Handler, /* 25 Digital Analog Converter */
|
||||||
|
(void*) PTC_Handler, /* 26 Peripheral Touch Controller */
|
||||||
|
(void*) I2S_Handler /* 27 Inter-IC Sound Interface */
|
||||||
|
};
|
||||||
|
|
||||||
|
extern int main(void);
|
||||||
|
extern void __libc_init_array(void);
|
||||||
|
|
||||||
|
/* This is called on processor reset to initialize the device and call main() */
|
||||||
|
void Reset_Handler(void)
|
||||||
|
{
|
||||||
|
uint32_t *pSrc, *pDest;
|
||||||
|
|
||||||
|
/* Initialize the initialized data section */
|
||||||
|
pSrc = &__etext;
|
||||||
|
pDest = &__data_start__;
|
||||||
|
|
||||||
|
if ((&__data_start__ != &__data_end__) && (pSrc != pDest)) {
|
||||||
|
for (; pDest < &__data_end__; pDest++, pSrc++)
|
||||||
|
*pDest = *pSrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clear the zero section */
|
||||||
|
if ((&__data_start__ != &__data_end__) && (pSrc != pDest)) {
|
||||||
|
for (pDest = &__bss_start__; pDest < &__bss_end__; pDest++)
|
||||||
|
*pDest = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize the C library */
|
||||||
|
__libc_init_array();
|
||||||
|
|
||||||
|
SystemInit();
|
||||||
|
|
||||||
|
main();
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Default Arduino systick handler */
|
||||||
|
extern void SysTick_DefaultHandler(void);
|
||||||
|
|
||||||
|
void SysTick_Handler(void)
|
||||||
|
{
|
||||||
|
if (sysTickHook())
|
||||||
|
return;
|
||||||
|
SysTick_DefaultHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void (*usb_isr)(void) = NULL;
|
||||||
|
|
||||||
|
void USB_Handler(void)
|
||||||
|
{
|
||||||
|
if (usb_isr)
|
||||||
|
usb_isr();
|
||||||
|
}
|
||||||
|
|
||||||
|
void USB_SetHandler(void (*new_usb_isr)(void))
|
||||||
|
{
|
||||||
|
usb_isr = new_usb_isr;
|
||||||
|
}
|
||||||
90
cores/samd10/delay.c
Normal file
90
cores/samd10/delay.c
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "delay.h"
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Tick Counter united by ms */
|
||||||
|
static volatile uint32_t _ulTickCount=0 ;
|
||||||
|
|
||||||
|
uint32_t millis( void )
|
||||||
|
{
|
||||||
|
// todo: ensure no interrupts
|
||||||
|
return _ulTickCount ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interrupt-compatible version of micros
|
||||||
|
// Theory: repeatedly take readings of SysTick counter, millis counter and SysTick interrupt pending flag.
|
||||||
|
// When it appears that millis counter and pending is stable and SysTick hasn't rolled over, use these
|
||||||
|
// values to calculate micros. If there is a pending SysTick, add one to the millis counter in the calculation.
|
||||||
|
uint32_t micros( void )
|
||||||
|
{
|
||||||
|
uint32_t ticks, ticks2;
|
||||||
|
uint32_t pend, pend2;
|
||||||
|
uint32_t count, count2;
|
||||||
|
|
||||||
|
ticks2 = SysTick->VAL;
|
||||||
|
pend2 = !!(SCB->ICSR & SCB_ICSR_PENDSTSET_Msk) ;
|
||||||
|
count2 = _ulTickCount ;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ticks=ticks2;
|
||||||
|
pend=pend2;
|
||||||
|
count=count2;
|
||||||
|
ticks2 = SysTick->VAL;
|
||||||
|
pend2 = !!(SCB->ICSR & SCB_ICSR_PENDSTSET_Msk) ;
|
||||||
|
count2 = _ulTickCount ;
|
||||||
|
} while ((pend != pend2) || (count != count2) || (ticks < ticks2));
|
||||||
|
|
||||||
|
return ((count+pend) * 1000) + (((SysTick->LOAD - ticks)*(1048576/(VARIANT_MCK/1000000)))>>20) ;
|
||||||
|
// this is an optimization to turn a runtime division into two compile-time divisions and
|
||||||
|
// a runtime multiplication and shift, saving a few cycles
|
||||||
|
}
|
||||||
|
|
||||||
|
void delay( uint32_t ms )
|
||||||
|
{
|
||||||
|
if ( ms == 0 )
|
||||||
|
{
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t start = _ulTickCount ;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
yield() ;
|
||||||
|
} while ( _ulTickCount - start < ms ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "Reset.h" // for tickReset()
|
||||||
|
|
||||||
|
void SysTick_DefaultHandler(void)
|
||||||
|
{
|
||||||
|
// Increment tick count each ms
|
||||||
|
_ulTickCount++;
|
||||||
|
tickReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
104
cores/samd10/delay.h
Normal file
104
cores/samd10/delay.h
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _DELAY_
|
||||||
|
#define _DELAY_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "variant.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Returns the number of milliseconds since the Arduino board began running the current program.
|
||||||
|
*
|
||||||
|
* This number will overflow (go back to zero), after approximately 50 days.
|
||||||
|
*
|
||||||
|
* \return Number of milliseconds since the program started (uint32_t)
|
||||||
|
*/
|
||||||
|
extern uint32_t millis( void ) ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Returns the number of microseconds since the Arduino board began running the current program.
|
||||||
|
*
|
||||||
|
* This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards
|
||||||
|
* (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is
|
||||||
|
* always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution
|
||||||
|
* of eight microseconds.
|
||||||
|
*
|
||||||
|
* \note There are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second.
|
||||||
|
*/
|
||||||
|
extern uint32_t micros( void ) ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Pauses the program for the amount of time (in miliseconds) specified as parameter.
|
||||||
|
* (There are 1000 milliseconds in a second.)
|
||||||
|
*
|
||||||
|
* \param dwMs the number of milliseconds to pause (uint32_t)
|
||||||
|
*/
|
||||||
|
extern void delay( uint32_t dwMs ) ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Pauses the program for the amount of time (in microseconds) specified as parameter.
|
||||||
|
*
|
||||||
|
* \param dwUs the number of microseconds to pause (uint32_t)
|
||||||
|
*/
|
||||||
|
static __inline__ void delayMicroseconds( uint32_t ) __attribute__((always_inline, unused)) ;
|
||||||
|
static __inline__ void delayMicroseconds( uint32_t usec )
|
||||||
|
{
|
||||||
|
if ( usec == 0 )
|
||||||
|
{
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following loop:
|
||||||
|
*
|
||||||
|
* for (; ul; ul--) {
|
||||||
|
* __asm__ volatile("");
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* produce the following assembly code:
|
||||||
|
*
|
||||||
|
* loop:
|
||||||
|
* subs r3, #1 // 1 Core cycle
|
||||||
|
* bne.n loop // 1 Core cycle + 1 if branch is taken
|
||||||
|
*/
|
||||||
|
|
||||||
|
// VARIANT_MCK / 1000000 == cycles needed to delay 1uS
|
||||||
|
// 3 == cycles used in a loop
|
||||||
|
uint32_t n = usec * (VARIANT_MCK / 1000000) / 3;
|
||||||
|
__asm__ __volatile__(
|
||||||
|
"1: \n"
|
||||||
|
" sub %0, #1 \n" // substract 1 from %0 (n)
|
||||||
|
" bne 1b \n" // if result is not 0 jump to 1
|
||||||
|
: "+r" (n) // '%0' is n variable with RW constraints
|
||||||
|
: // no input
|
||||||
|
: // no clobber
|
||||||
|
);
|
||||||
|
// https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
|
||||||
|
// https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _DELAY_ */
|
||||||
58
cores/samd10/hooks.c
Normal file
58
cores/samd10/hooks.c
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty yield() hook.
|
||||||
|
*
|
||||||
|
* This function is intended to be used by library writers to build
|
||||||
|
* libraries or sketches that supports cooperative threads.
|
||||||
|
*
|
||||||
|
* Its defined as a weak symbol and it can be redefined to implement a
|
||||||
|
* real cooperative scheduler.
|
||||||
|
*/
|
||||||
|
static void __empty() {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
void yield(void) __attribute__ ((weak, alias("__empty")));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SysTick hook
|
||||||
|
*
|
||||||
|
* This function is called from SysTick handler, before the default
|
||||||
|
* handler provided by Arduino.
|
||||||
|
*/
|
||||||
|
static int __false() {
|
||||||
|
// Return false
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int sysTickHook(void) __attribute__ ((weak, alias("__false")));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SVC hook
|
||||||
|
* PendSV hook
|
||||||
|
*
|
||||||
|
* These functions are called from SVC handler, and PensSV handler.
|
||||||
|
* Default action is halting.
|
||||||
|
*/
|
||||||
|
static void __halt() {
|
||||||
|
// Halts
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
void svcHook(void) __attribute__ ((weak, alias("__halt")));
|
||||||
|
void pendSVHook(void) __attribute__ ((weak, alias("__halt")));
|
||||||
170
cores/samd10/itoa.c
Normal file
170
cores/samd10/itoa.c
Normal file
|
|
@ -0,0 +1,170 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "itoa.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* reverse: reverse string s in place */
|
||||||
|
/*
|
||||||
|
static void reverse( char s[] )
|
||||||
|
{
|
||||||
|
int i, j ;
|
||||||
|
char c ;
|
||||||
|
|
||||||
|
for ( i = 0, j = strlen(s)-1 ; i < j ; i++, j-- )
|
||||||
|
{
|
||||||
|
c = s[i] ;
|
||||||
|
s[i] = s[j] ;
|
||||||
|
s[j] = c ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* itoa: convert n to characters in s */
|
||||||
|
/*
|
||||||
|
extern void itoa( int n, char s[] )
|
||||||
|
{
|
||||||
|
int i, sign ;
|
||||||
|
|
||||||
|
if ( (sign = n) < 0 ) // record sign
|
||||||
|
{
|
||||||
|
n = -n; // make n positive
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
do
|
||||||
|
{ // generate digits in reverse order
|
||||||
|
s[i++] = n % 10 + '0'; // get next digit
|
||||||
|
} while ((n /= 10) > 0) ; // delete it
|
||||||
|
|
||||||
|
if (sign < 0 )
|
||||||
|
{
|
||||||
|
s[i++] = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
s[i] = '\0';
|
||||||
|
|
||||||
|
reverse( s ) ;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern char* itoa( int value, char *string, int radix )
|
||||||
|
{
|
||||||
|
return ltoa( value, string, radix ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern char* ltoa( long value, char *string, int radix )
|
||||||
|
{
|
||||||
|
char tmp[33];
|
||||||
|
char *tp = tmp;
|
||||||
|
long i;
|
||||||
|
unsigned long v;
|
||||||
|
int sign;
|
||||||
|
char *sp;
|
||||||
|
|
||||||
|
if ( string == NULL )
|
||||||
|
{
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (radix > 36 || radix <= 1)
|
||||||
|
{
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
sign = (radix == 10 && value < 0);
|
||||||
|
if (sign)
|
||||||
|
{
|
||||||
|
v = -value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
v = (unsigned long)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (v || tp == tmp)
|
||||||
|
{
|
||||||
|
i = v % radix;
|
||||||
|
v = v / radix;
|
||||||
|
if (i < 10)
|
||||||
|
*tp++ = i+'0';
|
||||||
|
else
|
||||||
|
*tp++ = i + 'a' - 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
sp = string;
|
||||||
|
|
||||||
|
if (sign)
|
||||||
|
*sp++ = '-';
|
||||||
|
while (tp > tmp)
|
||||||
|
*sp++ = *--tp;
|
||||||
|
*sp = 0;
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern char* utoa( unsigned long value, char *string, int radix )
|
||||||
|
{
|
||||||
|
return ultoa( value, string, radix ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern char* ultoa( unsigned long value, char *string, int radix )
|
||||||
|
{
|
||||||
|
char tmp[33];
|
||||||
|
char *tp = tmp;
|
||||||
|
long i;
|
||||||
|
unsigned long v = value;
|
||||||
|
char *sp;
|
||||||
|
|
||||||
|
if ( string == NULL )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (radix > 36 || radix <= 1)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (v || tp == tmp)
|
||||||
|
{
|
||||||
|
i = v % radix;
|
||||||
|
v = v / radix;
|
||||||
|
if (i < 10)
|
||||||
|
*tp++ = i+'0';
|
||||||
|
else
|
||||||
|
*tp++ = i + 'a' - 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
sp = string;
|
||||||
|
|
||||||
|
|
||||||
|
while (tp > tmp)
|
||||||
|
*sp++ = *--tp;
|
||||||
|
*sp = 0;
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
35
cores/samd10/itoa.h
Normal file
35
cores/samd10/itoa.h
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//extern void itoa( int n, char s[] ) ;
|
||||||
|
|
||||||
|
extern char* itoa( int value, char *string, int radix ) ;
|
||||||
|
extern char* ltoa( long value, char *string, int radix ) ;
|
||||||
|
extern char* utoa( unsigned long value, char *string, int radix ) ;
|
||||||
|
extern char* ultoa( unsigned long value, char *string, int radix ) ;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
|
|
||||||
53
cores/samd10/main.cpp
Normal file
53
cores/samd10/main.cpp
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define ARDUINO_MAIN
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
// Weak empty variant initialization function.
|
||||||
|
// May be redefined by variant files.
|
||||||
|
void initVariant() __attribute__((weak));
|
||||||
|
void initVariant() { }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Main entry point of Arduino application
|
||||||
|
*/
|
||||||
|
int main( void )
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
|
||||||
|
initVariant();
|
||||||
|
|
||||||
|
delay(1);
|
||||||
|
#if !defined(__SAMD10D14AM__)
|
||||||
|
#if defined(USBCON)
|
||||||
|
USBDevice.init();
|
||||||
|
USBDevice.attach();
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
setup();
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
loop();
|
||||||
|
if (serialEventRun) serialEventRun();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
36
cores/samd10/new.cpp
Normal file
36
cores/samd10/new.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void *operator new(size_t size) {
|
||||||
|
return malloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *operator new[](size_t size) {
|
||||||
|
return malloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator delete(void * ptr) {
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator delete[](void * ptr) {
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
52
cores/samd10/pulse.c
Normal file
52
cores/samd10/pulse.c
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
// See pulse_asm.S
|
||||||
|
extern unsigned long countPulseASM(const volatile uint32_t *port, uint32_t bit, uint32_t stateMask, unsigned long maxloops);
|
||||||
|
|
||||||
|
/* Measures the length (in microseconds) of a pulse on the pin; state is HIGH
|
||||||
|
* or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds
|
||||||
|
* to 3 minutes in length, but must be called at least a few dozen microseconds
|
||||||
|
* before the start of the pulse. */
|
||||||
|
uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout)
|
||||||
|
{
|
||||||
|
// cache the port and bit of the pin in order to speed up the
|
||||||
|
// pulse width measuring loop and achieve finer resolution. calling
|
||||||
|
// digitalRead() instead yields much coarser resolution.
|
||||||
|
PinDescription p = g_APinDescription[pin];
|
||||||
|
uint32_t bit = 1 << p.ulPin;
|
||||||
|
uint32_t stateMask = state ? bit : 0;
|
||||||
|
|
||||||
|
// convert the timeout from microseconds to a number of times through
|
||||||
|
// the initial loop; it takes (roughly) 13 clock cycles per iteration.
|
||||||
|
uint32_t maxloops = microsecondsToClockCycles(timeout) / 13;
|
||||||
|
|
||||||
|
uint32_t width = countPulseASM(&(PORT->Group[p.ulPort].IN.reg), bit, stateMask, maxloops);
|
||||||
|
|
||||||
|
// convert the reading to microseconds. The loop has been determined
|
||||||
|
// to be 13 clock cycles long and have about 16 clocks between the edge
|
||||||
|
// and the start of the loop. There will be some error introduced by
|
||||||
|
// the interrupt handlers.
|
||||||
|
if (width)
|
||||||
|
return clockCyclesToMicroseconds(width * 13 + 16);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
39
cores/samd10/pulse.h
Normal file
39
cores/samd10/pulse.h
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Measures the length (in microseconds) of a pulse on the pin; state is HIGH
|
||||||
|
* or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds
|
||||||
|
* to 3 minutes in length, but must be called at least a few dozen microseconds
|
||||||
|
* before the start of the pulse.
|
||||||
|
*/
|
||||||
|
uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
// Provides a version of pulseIn with a default argument (C++ only)
|
||||||
|
uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout = 1000000L);
|
||||||
|
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
|
|
||||||
175
cores/samd10/pulse_asm.S
Normal file
175
cores/samd10/pulse_asm.S
Normal file
|
|
@ -0,0 +1,175 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
The following function has been compiled to ASM with gcc
|
||||||
|
|
||||||
|
unsigned long countPulseASM(const volatile uint32_t *port, uint32_t bit, uint32_t stateMask, unsigned long maxloops)
|
||||||
|
{
|
||||||
|
unsigned long width = 0;
|
||||||
|
|
||||||
|
// wait for any previous pulse to end
|
||||||
|
while ((*port & bit) == stateMask)
|
||||||
|
if (--maxloops == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// wait for the pulse to start
|
||||||
|
while ((*port & bit) != stateMask)
|
||||||
|
if (--maxloops == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// wait for the pulse to stop
|
||||||
|
while ((*port & bit) == stateMask) {
|
||||||
|
if (++width == maxloops)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
using the command line:
|
||||||
|
|
||||||
|
arm-none-eabi-gcc -mcpu=cortex-m0plus -mthumb -c -Os -W -ffunction-sections -fdata-sections \
|
||||||
|
-nostdlib --param max-inline-insns-single=500 -fno-exceptions -MMD \
|
||||||
|
-DF_CPU=48000000L -DARDUINO=10602 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD \
|
||||||
|
-D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x004d -DUSBCON \
|
||||||
|
-DUSB_MANUFACTURER="Arduino LLC" -DUSB_PRODUCT="Arduino Zero" \
|
||||||
|
-I/Code/arduino/build/linux/work/hardware/tools/CMSIS/CMSIS/Include/ \
|
||||||
|
-I/Code/arduino/build/linux/work/hardware/tools/CMSIS/Device/ATMEL/ \
|
||||||
|
-I/Code/arduino/build/linux/work/hardware/arduino/samd/cores/arduino \
|
||||||
|
-I/Code/arduino/build/linux/work/hardware/arduino/samd/variants/arduino_zero \
|
||||||
|
count.c -Wa,-ahlmsd=output.lst -dp -fverbose-asm -S
|
||||||
|
|
||||||
|
The result has been slightly edited to increase readability.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
.cpu cortex-m0plus
|
||||||
|
.fpu softvfp
|
||||||
|
.eabi_attribute 20, 1 @ Tag_ABI_FP_denormal
|
||||||
|
.eabi_attribute 21, 1 @ Tag_ABI_FP_exceptions
|
||||||
|
.eabi_attribute 23, 3 @ Tag_ABI_FP_number_model
|
||||||
|
.eabi_attribute 24, 1 @ Tag_ABI_align8_needed
|
||||||
|
.eabi_attribute 25, 1 @ Tag_ABI_align8_preserved
|
||||||
|
.eabi_attribute 26, 1 @ Tag_ABI_enum_size
|
||||||
|
.eabi_attribute 30, 4 @ Tag_ABI_optimization_goals
|
||||||
|
.eabi_attribute 34, 0 @ Tag_CPU_unaligned_access
|
||||||
|
.eabi_attribute 18, 4 @ Tag_ABI_PCS_wchar_t
|
||||||
|
.file "count.c"
|
||||||
|
@ GNU C (GNU Tools for ARM Embedded Processors (Arduino build)) version 4.8.3 20140228 (release) [ARM/embedded-4_8-branch revision 208322] (arm-none-eabi)
|
||||||
|
@ compiled by GNU C version 4.3.2, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
|
||||||
|
@ GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
|
||||||
|
@ options passed:
|
||||||
|
@ -I /Code/arduino/build/linux/work/hardware/tools/CMSIS/CMSIS/Include/
|
||||||
|
@ -I /Code/arduino/build/linux/work/hardware/tools/CMSIS/Device/ATMEL/
|
||||||
|
@ -I /Code/arduino/build/linux/work/hardware/arduino/samd/cores/arduino
|
||||||
|
@ -I /Code/arduino/build/linux/work/hardware/arduino/samd/variants/arduino_zero
|
||||||
|
@ -imultilib armv6-m
|
||||||
|
@ -iprefix /Code/arduino/build/linux/work/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/../lib/gcc/arm-none-eabi/4.8.3/
|
||||||
|
@ -isysroot /Code/arduino/build/linux/work/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/../arm-none-eabi
|
||||||
|
@ -MMD count.d -D__USES_INITFINI__ -D F_CPU=48000000L -D ARDUINO=10602
|
||||||
|
@ -D ARDUINO_SAMD_ZERO -D ARDUINO_ARCH_SAMD -D __SAMD21G18A__
|
||||||
|
@ -D USB_VID=0x2341 -D USB_PID=0x004d -D USBCON
|
||||||
|
@ -D USB_MANUFACTURER=Arduino LLC -D USB_PRODUCT=Arduino Zero count.c
|
||||||
|
@ -mcpu=cortex-m0plus -mthumb -Os -Wextra -ffunction-sections
|
||||||
|
@ -fdata-sections -fno-exceptions -fverbose-asm
|
||||||
|
@ --param max-inline-insns-single=500
|
||||||
|
@ options enabled: -faggressive-loop-optimizations -fauto-inc-dec
|
||||||
|
@ -fbranch-count-reg -fcaller-saves -fcombine-stack-adjustments -fcommon
|
||||||
|
@ -fcompare-elim -fcprop-registers -fcrossjumping -fcse-follow-jumps
|
||||||
|
@ -fdata-sections -fdefer-pop -fdelete-null-pointer-checks -fdevirtualize
|
||||||
|
@ -fdwarf2-cfi-asm -fearly-inlining -feliminate-unused-debug-types
|
||||||
|
@ -fexpensive-optimizations -fforward-propagate -ffunction-cse
|
||||||
|
@ -ffunction-sections -fgcse -fgcse-lm -fgnu-runtime
|
||||||
|
@ -fguess-branch-probability -fhoist-adjacent-loads -fident -fif-conversion
|
||||||
|
@ -fif-conversion2 -findirect-inlining -finline -finline-atomics
|
||||||
|
@ -finline-functions -finline-functions-called-once
|
||||||
|
@ -finline-small-functions -fipa-cp -fipa-profile -fipa-pure-const
|
||||||
|
@ -fipa-reference -fipa-sra -fira-hoist-pressure -fira-share-save-slots
|
||||||
|
@ -fira-share-spill-slots -fivopts -fkeep-static-consts
|
||||||
|
@ -fleading-underscore -fmath-errno -fmerge-constants -fmerge-debug-strings
|
||||||
|
@ -fomit-frame-pointer -foptimize-register-move -foptimize-sibling-calls
|
||||||
|
@ -fpartial-inlining -fpeephole -fpeephole2 -fprefetch-loop-arrays
|
||||||
|
@ -freg-struct-return -fregmove -freorder-blocks -freorder-functions
|
||||||
|
@ -frerun-cse-after-loop -fsched-critical-path-heuristic
|
||||||
|
@ -fsched-dep-count-heuristic -fsched-group-heuristic -fsched-interblock
|
||||||
|
@ -fsched-last-insn-heuristic -fsched-pressure -fsched-rank-heuristic
|
||||||
|
@ -fsched-spec -fsched-spec-insn-heuristic -fsched-stalled-insns-dep
|
||||||
|
@ -fschedule-insns2 -fsection-anchors -fshow-column -fshrink-wrap
|
||||||
|
@ -fsigned-zeros -fsplit-ivs-in-unroller -fsplit-wide-types
|
||||||
|
@ -fstrict-aliasing -fstrict-overflow -fstrict-volatile-bitfields
|
||||||
|
@ -fsync-libcalls -fthread-jumps -ftoplevel-reorder -ftrapping-math
|
||||||
|
@ -ftree-bit-ccp -ftree-builtin-call-dce -ftree-ccp -ftree-ch
|
||||||
|
@ -ftree-coalesce-vars -ftree-copy-prop -ftree-copyrename -ftree-cselim
|
||||||
|
@ -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-forwprop -ftree-fre
|
||||||
|
@ -ftree-loop-if-convert -ftree-loop-im -ftree-loop-ivcanon
|
||||||
|
@ -ftree-loop-optimize -ftree-parallelize-loops= -ftree-phiprop -ftree-pre
|
||||||
|
@ -ftree-pta -ftree-reassoc -ftree-scev-cprop -ftree-sink
|
||||||
|
@ -ftree-slp-vectorize -ftree-slsr -ftree-sra -ftree-switch-conversion
|
||||||
|
@ -ftree-tail-merge -ftree-ter -ftree-vect-loop-version -ftree-vrp
|
||||||
|
@ -funit-at-a-time -fverbose-asm -fzero-initialized-in-bss -mlittle-endian
|
||||||
|
@ -mpic-data-is-text-relative -msched-prolog -mthumb
|
||||||
|
@ -mvectorize-with-neon-quad
|
||||||
|
|
||||||
|
.section .text.countPulseASM,"ax",%progbits
|
||||||
|
.align 1
|
||||||
|
.global countPulseASM
|
||||||
|
.code 16
|
||||||
|
.thumb_func
|
||||||
|
.type countPulseASM, %function
|
||||||
|
countPulseASM:
|
||||||
|
push {r4, r5, lr} @ @ 112 *push_multi [length = 2]
|
||||||
|
.L2:
|
||||||
|
ldr r4, [r0] @ D.11539, *port_7(D) @ 22 *thumb1_movsi_insn/7 [length = 2]
|
||||||
|
and r4, r1 @ D.11539, bit @ 24 *thumb1_andsi3_insn [length = 2]
|
||||||
|
cmp r4, r2 @ D.11539, stateMask @ 25 cbranchsi4_insn/1 [length = 4]
|
||||||
|
bne .L5 @,
|
||||||
|
sub r3, r3, #1 @ maxloops, @ 17 *thumb1_addsi3/2 [length = 2]
|
||||||
|
cmp r3, #0 @ maxloops, @ 18 cbranchsi4_insn/1 [length = 4]
|
||||||
|
bne .L2 @,
|
||||||
|
b .L10 @ @ 127 *thumb_jump [length = 2]
|
||||||
|
.L6:
|
||||||
|
sub r3, r3, #1 @ maxloops, @ 30 *thumb1_addsi3/2 [length = 2]
|
||||||
|
cmp r3, #0 @ maxloops, @ 31 cbranchsi4_insn/1 [length = 4]
|
||||||
|
beq .L10 @,
|
||||||
|
.L5:
|
||||||
|
ldr r4, [r0] @ D.11539, *port_7(D) @ 35 *thumb1_movsi_insn/7 [length = 2]
|
||||||
|
and r4, r1 @ D.11539, bit @ 37 *thumb1_andsi3_insn [length = 2]
|
||||||
|
cmp r4, r2 @ D.11539, stateMask @ 38 cbranchsi4_insn/1 [length = 4]
|
||||||
|
bne .L6 @,
|
||||||
|
mov r4, #0 @ width, @ 7 *thumb1_movsi_insn/2 [length = 2]
|
||||||
|
.L7:
|
||||||
|
ldr r5, [r0] @ D.11539, *port_7(D) @ 48 *thumb1_movsi_insn/7 [length = 2]
|
||||||
|
and r5, r1 @ D.11539, bit @ 50 *thumb1_andsi3_insn [length = 2]
|
||||||
|
cmp r5, r2 @ D.11539, stateMask @ 51 cbranchsi4_insn/1 [length = 4]
|
||||||
|
bne .L13 @,
|
||||||
|
add r4, r4, #1 @ width, @ 43 *thumb1_addsi3/1 [length = 2]
|
||||||
|
cmp r4, r3 @ width, maxloops @ 44 cbranchsi4_insn/1 [length = 4]
|
||||||
|
bne .L7 @,
|
||||||
|
mov r0, #0 @ D.11539, @ 11 *thumb1_movsi_insn/2 [length = 2]
|
||||||
|
b .L3 @ @ 130 *thumb_jump [length = 2]
|
||||||
|
.L13:
|
||||||
|
mov r0, r4 @ D.11539, width @ 9 *thumb1_movsi_insn/1 [length = 2]
|
||||||
|
b .L3 @ @ 132 *thumb_jump [length = 2]
|
||||||
|
.L10:
|
||||||
|
mov r0, r3 @ D.11539, maxloops @ 8 *thumb1_movsi_insn/1 [length = 2]
|
||||||
|
.L3:
|
||||||
|
@ sp needed @ @ 115 force_register_use [length = 0]
|
||||||
|
pop {r4, r5, pc}
|
||||||
|
.size countPulseASM, .-countPulseASM
|
||||||
|
.ident "GCC: (GNU Tools for ARM Embedded Processors (Arduino build)) 4.8.3 20140228 (release) [ARM/embedded-4_8-branch revision 208322]"
|
||||||
231
cores/samd10/startup.c
Normal file
231
cores/samd10/startup.c
Normal file
|
|
@ -0,0 +1,231 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sam.h"
|
||||||
|
#include "variant.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief SystemInit() configures the needed clocks and according Flash Read Wait States.
|
||||||
|
* At reset:
|
||||||
|
* - OSC8M clock source is enabled with a divider by 8 (1MHz).
|
||||||
|
* - Generic Clock Generator 0 (GCLKMAIN) is using OSC8M as source.
|
||||||
|
* We need to:
|
||||||
|
* 1) Enable XOSC32K clock (External on-board 32.768Hz oscillator), will be used as DFLL48M reference.
|
||||||
|
* 2) Put XOSC32K as source of Generic Clock Generator 1
|
||||||
|
* 3) Put Generic Clock Generator 1 as source for Generic Clock Multiplexer 0 (DFLL48M reference)
|
||||||
|
* 4) Enable DFLL48M clock
|
||||||
|
* 5) Switch Generic Clock Generator 0 to DFLL48M. CPU will run at 48MHz.
|
||||||
|
* 6) Modify PRESCaler value of OSCM to have 8MHz
|
||||||
|
* 7) Put OSC8M as source for Generic Clock Generator 3
|
||||||
|
*/
|
||||||
|
// Constants for Clock generators
|
||||||
|
#define GENERIC_CLOCK_GENERATOR_MAIN (0u)
|
||||||
|
#define GENERIC_CLOCK_GENERATOR_XOSC32K (1u)
|
||||||
|
#define GENERIC_CLOCK_GENERATOR_OSCULP32K (2u) /* Initialized at reset for WDT */
|
||||||
|
#define GENERIC_CLOCK_GENERATOR_OSC8M (3u)
|
||||||
|
// Constants for Clock multiplexers
|
||||||
|
#define GENERIC_CLOCK_MULTIPLEXER_DFLL48M (0u)
|
||||||
|
|
||||||
|
void SystemInit( void )
|
||||||
|
{
|
||||||
|
/* Set 1 Flash Wait State for 48MHz, cf tables 20.9 and 35.27 in SAMD21 Datasheet */
|
||||||
|
NVMCTRL->CTRLB.bit.RWS = NVMCTRL_CTRLB_RWS_HALF_Val ;
|
||||||
|
|
||||||
|
/* Turn on the digital interface clock */
|
||||||
|
PM->APBAMASK.reg |= PM_APBAMASK_GCLK ;
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------------------------
|
||||||
|
* 1) Enable XOSC32K clock (External on-board 32.768Hz oscillator)
|
||||||
|
*/
|
||||||
|
SYSCTRL->XOSC32K.reg = SYSCTRL_XOSC32K_STARTUP( 0x6u ) | /* cf table 15.10 of product datasheet in chapter 15.8.6 */
|
||||||
|
SYSCTRL_XOSC32K_XTALEN | SYSCTRL_XOSC32K_EN32K ;
|
||||||
|
SYSCTRL->XOSC32K.bit.ENABLE = 1 ; /* separate call, as described in chapter 15.6.3 */
|
||||||
|
|
||||||
|
while ( (SYSCTRL->PCLKSR.reg & SYSCTRL_PCLKSR_XOSC32KRDY) == 0 )
|
||||||
|
{
|
||||||
|
/* Wait for oscillator stabilization */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Software reset the module to ensure it is re-initialized correctly */
|
||||||
|
/* Note: Due to synchronization, there is a delay from writing CTRL.SWRST until the reset is complete.
|
||||||
|
* CTRL.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete, as described in chapter 13.8.1
|
||||||
|
*/
|
||||||
|
GCLK->CTRL.reg = GCLK_CTRL_SWRST ;
|
||||||
|
|
||||||
|
while ( (GCLK->CTRL.reg & GCLK_CTRL_SWRST) && (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY) )
|
||||||
|
{
|
||||||
|
/* Wait for reset to complete */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------------------------
|
||||||
|
* 2) Put XOSC32K as source of Generic Clock Generator 1
|
||||||
|
*/
|
||||||
|
GCLK->GENDIV.reg = GCLK_GENDIV_ID( GENERIC_CLOCK_GENERATOR_XOSC32K ) ; // Generic Clock Generator 1
|
||||||
|
|
||||||
|
while ( GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY )
|
||||||
|
{
|
||||||
|
/* Wait for synchronization */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write Generic Clock Generator 1 configuration */
|
||||||
|
GCLK->GENCTRL.reg = GCLK_GENCTRL_ID( GENERIC_CLOCK_GENERATOR_XOSC32K ) | // Generic Clock Generator 1
|
||||||
|
GCLK_GENCTRL_SRC_XOSC32K | // Selected source is External 32KHz Oscillator
|
||||||
|
// GCLK_GENCTRL_OE | // Output clock to a pin for tests
|
||||||
|
GCLK_GENCTRL_GENEN ;
|
||||||
|
|
||||||
|
while ( GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY )
|
||||||
|
{
|
||||||
|
/* Wait for synchronization */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------------------------
|
||||||
|
* 3) Put Generic Clock Generator 1 as source for Generic Clock Multiplexer 0 (DFLL48M reference)
|
||||||
|
*/
|
||||||
|
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID( GENERIC_CLOCK_MULTIPLEXER_DFLL48M ) | // Generic Clock Multiplexer 0
|
||||||
|
GCLK_CLKCTRL_GEN_GCLK1 | // Generic Clock Generator 1 is source
|
||||||
|
GCLK_CLKCTRL_CLKEN ;
|
||||||
|
|
||||||
|
while ( GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY )
|
||||||
|
{
|
||||||
|
/* Wait for synchronization */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------------------------
|
||||||
|
* 4) Enable DFLL48M clock
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* DFLL Configuration in Closed Loop mode, cf product datasheet chapter 15.6.7.1 - Closed-Loop Operation */
|
||||||
|
|
||||||
|
/* Remove the OnDemand mode, Bug http://avr32.icgroup.norway.atmel.com/bugzilla/show_bug.cgi?id=9905 */
|
||||||
|
SYSCTRL->DFLLCTRL.bit.ONDEMAND = 0 ;
|
||||||
|
|
||||||
|
while ( (SYSCTRL->PCLKSR.reg & SYSCTRL_PCLKSR_DFLLRDY) == 0 )
|
||||||
|
{
|
||||||
|
/* Wait for synchronization */
|
||||||
|
}
|
||||||
|
|
||||||
|
SYSCTRL->DFLLMUL.reg = SYSCTRL_DFLLMUL_CSTEP( 31 ) | // Coarse step is 31, half of the max value
|
||||||
|
SYSCTRL_DFLLMUL_FSTEP( 511 ) | // Fine step is 511, half of the max value
|
||||||
|
SYSCTRL_DFLLMUL_MUL( (VARIANT_MCK/VARIANT_MAINOSC) ) ; // External 32KHz is the reference
|
||||||
|
|
||||||
|
while ( (SYSCTRL->PCLKSR.reg & SYSCTRL_PCLKSR_DFLLRDY) == 0 )
|
||||||
|
{
|
||||||
|
/* Wait for synchronization */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write full configuration to DFLL control register */
|
||||||
|
SYSCTRL->DFLLCTRL.reg |= SYSCTRL_DFLLCTRL_MODE | /* Enable the closed loop mode */
|
||||||
|
SYSCTRL_DFLLCTRL_WAITLOCK |
|
||||||
|
SYSCTRL_DFLLCTRL_QLDIS ; /* Disable Quick lock */
|
||||||
|
|
||||||
|
while ( (SYSCTRL->PCLKSR.reg & SYSCTRL_PCLKSR_DFLLRDY) == 0 )
|
||||||
|
{
|
||||||
|
/* Wait for synchronization */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Enable the DFLL */
|
||||||
|
SYSCTRL->DFLLCTRL.reg |= SYSCTRL_DFLLCTRL_ENABLE ;
|
||||||
|
|
||||||
|
while ( (SYSCTRL->PCLKSR.reg & SYSCTRL_PCLKSR_DFLLLCKC) == 0 ||
|
||||||
|
(SYSCTRL->PCLKSR.reg & SYSCTRL_PCLKSR_DFLLLCKF) == 0 )
|
||||||
|
{
|
||||||
|
/* Wait for locks flags */
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( (SYSCTRL->PCLKSR.reg & SYSCTRL_PCLKSR_DFLLRDY) == 0 )
|
||||||
|
{
|
||||||
|
/* Wait for synchronization */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------------------------
|
||||||
|
* 5) Switch Generic Clock Generator 0 to DFLL48M. CPU will run at 48MHz.
|
||||||
|
*/
|
||||||
|
GCLK->GENDIV.reg = GCLK_GENDIV_ID( GENERIC_CLOCK_GENERATOR_MAIN ) ; // Generic Clock Generator 0
|
||||||
|
|
||||||
|
while ( GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY )
|
||||||
|
{
|
||||||
|
/* Wait for synchronization */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write Generic Clock Generator 0 configuration */
|
||||||
|
GCLK->GENCTRL.reg = GCLK_GENCTRL_ID( GENERIC_CLOCK_GENERATOR_MAIN ) | // Generic Clock Generator 0
|
||||||
|
GCLK_GENCTRL_SRC_DFLL48M | // Selected source is DFLL 48MHz
|
||||||
|
// GCLK_GENCTRL_OE | // Output clock to a pin for tests
|
||||||
|
GCLK_GENCTRL_IDC | // Set 50/50 duty cycle
|
||||||
|
GCLK_GENCTRL_GENEN ;
|
||||||
|
|
||||||
|
while ( GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY )
|
||||||
|
{
|
||||||
|
/* Wait for synchronization */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------------------------
|
||||||
|
* 6) Modify PRESCaler value of OSC8M to have 8MHz
|
||||||
|
*/
|
||||||
|
SYSCTRL->OSC8M.bit.PRESC = SYSCTRL_OSC8M_PRESC_1_Val ;
|
||||||
|
SYSCTRL->OSC8M.bit.ONDEMAND = 0 ;
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------------------------
|
||||||
|
* 7) Put OSC8M as source for Generic Clock Generator 3
|
||||||
|
*/
|
||||||
|
GCLK->GENDIV.reg = GCLK_GENDIV_ID( GENERIC_CLOCK_GENERATOR_OSC8M ) ; // Generic Clock Generator 3
|
||||||
|
|
||||||
|
/* Write Generic Clock Generator 3 configuration */
|
||||||
|
GCLK->GENCTRL.reg = GCLK_GENCTRL_ID( GENERIC_CLOCK_GENERATOR_OSC8M ) | // Generic Clock Generator 3
|
||||||
|
GCLK_GENCTRL_SRC_OSC8M | // Selected source is RC OSC 8MHz (already enabled at reset)
|
||||||
|
// GCLK_GENCTRL_OE | // Output clock to a pin for tests
|
||||||
|
GCLK_GENCTRL_GENEN ;
|
||||||
|
|
||||||
|
while ( GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY )
|
||||||
|
{
|
||||||
|
/* Wait for synchronization */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now that all system clocks are configured, we can set CPU and APBx BUS clocks.
|
||||||
|
* There values are normally the one present after Reset.
|
||||||
|
*/
|
||||||
|
PM->CPUSEL.reg = PM_CPUSEL_CPUDIV_DIV1 ;
|
||||||
|
PM->APBASEL.reg = PM_APBASEL_APBADIV_DIV1_Val ;
|
||||||
|
PM->APBBSEL.reg = PM_APBBSEL_APBBDIV_DIV1_Val ;
|
||||||
|
PM->APBCSEL.reg = PM_APBCSEL_APBCDIV_DIV1_Val ;
|
||||||
|
|
||||||
|
SystemCoreClock=VARIANT_MCK ;
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------------------------
|
||||||
|
* 8) Load ADC factory calibration values
|
||||||
|
*/
|
||||||
|
|
||||||
|
// ADC Bias Calibration
|
||||||
|
uint32_t bias = (*((uint32_t *) ADC_FUSES_BIASCAL_ADDR) & ADC_FUSES_BIASCAL_Msk) >> ADC_FUSES_BIASCAL_Pos;
|
||||||
|
|
||||||
|
// ADC Linearity bits 4:0
|
||||||
|
uint32_t linearity = (*((uint32_t *) ADC_FUSES_LINEARITY_0_ADDR) & ADC_FUSES_LINEARITY_0_Msk) >> ADC_FUSES_LINEARITY_0_Pos;
|
||||||
|
|
||||||
|
// ADC Linearity bits 7:5
|
||||||
|
linearity |= ((*((uint32_t *) ADC_FUSES_LINEARITY_1_ADDR) & ADC_FUSES_LINEARITY_1_Msk) >> ADC_FUSES_LINEARITY_1_Pos) << 5;
|
||||||
|
|
||||||
|
ADC->CALIB.reg = ADC_CALIB_BIAS_CAL(bias) | ADC_CALIB_LINEARITY_CAL(linearity);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 9) Disable automatic NVM write operations
|
||||||
|
*/
|
||||||
|
NVMCTRL->CTRLB.bit.MANW = 1;
|
||||||
|
}
|
||||||
144
cores/samd10/wiring.c
Normal file
144
cores/samd10/wiring.c
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* System Core Clock is at 1MHz (8MHz/8) at Reset.
|
||||||
|
* It is switched to 48MHz in the Reset Handler (startup.c)
|
||||||
|
*/
|
||||||
|
uint32_t SystemCoreClock=1000000ul ;
|
||||||
|
|
||||||
|
/*
|
||||||
|
void calibrateADC()
|
||||||
|
{
|
||||||
|
volatile uint32_t valeur = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < 5; ++i)
|
||||||
|
{
|
||||||
|
ADC->SWTRIG.bit.START = 1;
|
||||||
|
while( ADC->INTFLAG.bit.RESRDY == 0 || ADC->STATUS.bit.SYNCBUSY == 1 )
|
||||||
|
{
|
||||||
|
// Waiting for a complete conversion and complete synchronization
|
||||||
|
}
|
||||||
|
|
||||||
|
valeur += ADC->RESULT.bit.RESULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
valeur = valeur/5;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Arduino Zero board initialization
|
||||||
|
*
|
||||||
|
* Good to know:
|
||||||
|
* - At reset, ResetHandler did the system clock configuration. Core is running at 48MHz.
|
||||||
|
* - Watchdog is disabled by default, unless someone plays with NVM User page
|
||||||
|
* - During reset, all PORT lines are configured as inputs with input buffers, output buffers and pull disabled.
|
||||||
|
*/
|
||||||
|
void init( void )
|
||||||
|
{
|
||||||
|
uint32_t ul ;
|
||||||
|
|
||||||
|
// Set Systick to 1ms interval, common to all Cortex-M variants
|
||||||
|
if ( SysTick_Config( SystemCoreClock / 1000 ) )
|
||||||
|
{
|
||||||
|
// Capture error
|
||||||
|
while ( 1 ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clock PORT for Digital I/O
|
||||||
|
// PM->APBBMASK.reg |= PM_APBBMASK_PORT ;
|
||||||
|
//
|
||||||
|
// // Clock EIC for I/O interrupts
|
||||||
|
// PM->APBAMASK.reg |= PM_APBAMASK_EIC ;
|
||||||
|
|
||||||
|
// Clock SERCOM for Serial
|
||||||
|
PM->APBCMASK.reg |= PM_APBCMASK_SERCOM0 | PM_APBCMASK_SERCOM1 | PM_APBCMASK_SERCOM2
|
||||||
|
#if !defined(__SAMD10D14AM__)
|
||||||
|
| PM_APBCMASK_SERCOM3 | PM_APBCMASK_SERCOM4 | PM_APBCMASK_SERCOM5
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
|
// Clock TC/TCC for Pulse and Analog
|
||||||
|
PM->APBCMASK.reg |= PM_APBCMASK_TCC0
|
||||||
|
#if !defined(__SAMD10D14AM__)
|
||||||
|
| PM_APBCMASK_TCC1 | PM_APBCMASK_TCC2 | PM_APBCMASK_TC3 | PM_APBCMASK_TC4 | PM_APBCMASK_TC5
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
|
// ATSAMR, for example, doesn't have a DAC
|
||||||
|
#ifdef PM_APBCMASK_DAC
|
||||||
|
// Clock ADC/DAC for Analog
|
||||||
|
PM->APBCMASK.reg |= PM_APBCMASK_ADC | PM_APBCMASK_DAC ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Setup all pins (digital and analog) in INPUT mode (default is nothing)
|
||||||
|
for ( ul = 0 ; ul < NUM_DIGITAL_PINS ; ul++ )
|
||||||
|
{
|
||||||
|
pinMode( ul, INPUT ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize Analog Controller
|
||||||
|
// Setting clock
|
||||||
|
while(GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY);
|
||||||
|
|
||||||
|
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID( GCM_ADC ) | // Generic Clock ADC
|
||||||
|
GCLK_CLKCTRL_GEN_GCLK0 | // Generic Clock Generator 0 is source
|
||||||
|
GCLK_CLKCTRL_CLKEN ;
|
||||||
|
|
||||||
|
while( ADC->STATUS.bit.SYNCBUSY == 1 ); // Wait for synchronization of registers between the clock domains
|
||||||
|
|
||||||
|
ADC->CTRLB.reg = ADC_CTRLB_PRESCALER_DIV512 | // Divide Clock by 512.
|
||||||
|
ADC_CTRLB_RESSEL_10BIT; // 10 bits resolution as default
|
||||||
|
|
||||||
|
ADC->SAMPCTRL.reg = 0x3f; // Set max Sampling Time Length
|
||||||
|
|
||||||
|
while( ADC->STATUS.bit.SYNCBUSY == 1 ); // Wait for synchronization of registers between the clock domains
|
||||||
|
|
||||||
|
ADC->INPUTCTRL.reg = ADC_INPUTCTRL_MUXNEG_GND; // No Negative input (Internal Ground)
|
||||||
|
|
||||||
|
// Averaging (see datasheet table in AVGCTRL register description)
|
||||||
|
ADC->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_1 | // 1 sample only (no oversampling nor averaging)
|
||||||
|
ADC_AVGCTRL_ADJRES(0x0ul); // Adjusting result by 0
|
||||||
|
|
||||||
|
analogReference( AR_DEFAULT ) ; // Analog Reference is AREF pin (3.3v)
|
||||||
|
|
||||||
|
// Initialize DAC
|
||||||
|
// Setting clock
|
||||||
|
while ( GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY );
|
||||||
|
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID( GCM_DAC ) | // Generic Clock ADC
|
||||||
|
GCLK_CLKCTRL_GEN_GCLK0 | // Generic Clock Generator 0 is source
|
||||||
|
GCLK_CLKCTRL_CLKEN ;
|
||||||
|
|
||||||
|
// ATSAMR, for example, doesn't have a DAC
|
||||||
|
#ifdef DAC
|
||||||
|
while ( DAC->STATUS.bit.SYNCBUSY == 1 ); // Wait for synchronization of registers between the clock domains
|
||||||
|
DAC->CTRLB.reg = DAC_CTRLB_REFSEL_AVCC | // Using the 3.3V reference
|
||||||
|
DAC_CTRLB_EOEN ; // External Output Enable (Vout)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
29
cores/samd10/wiring.h
Normal file
29
cores/samd10/wiring.h
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern void init(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
356
cores/samd10/wiring_analog.c
Normal file
356
cores/samd10/wiring_analog.c
Normal file
|
|
@ -0,0 +1,356 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "wiring_private.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int _readResolution = 10;
|
||||||
|
static int _ADCResolution = 10;
|
||||||
|
static int _writeResolution = 8;
|
||||||
|
|
||||||
|
// Wait for synchronization of registers between the clock domains
|
||||||
|
static __inline__ void syncADC() __attribute__((always_inline, unused));
|
||||||
|
static void syncADC() {
|
||||||
|
while (ADC->STATUS.bit.SYNCBUSY == 1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ATSAMR, for example, doesn't have a DAC
|
||||||
|
#ifdef DAC
|
||||||
|
// Wait for synchronization of registers between the clock domains
|
||||||
|
static __inline__ void syncDAC() __attribute__((always_inline, unused));
|
||||||
|
static void syncDAC() {
|
||||||
|
while (DAC->STATUS.bit.SYNCBUSY == 1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Wait for synchronization of registers between the clock domains
|
||||||
|
static __inline__ void syncTC_8(Tc* TCx) __attribute__((always_inline, unused));
|
||||||
|
static void syncTC_8(Tc* TCx) {
|
||||||
|
while (TCx->COUNT8.STATUS.bit.SYNCBUSY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for synchronization of registers between the clock domains
|
||||||
|
static __inline__ void syncTCC(Tcc* TCCx) __attribute__((always_inline, unused));
|
||||||
|
static void syncTCC(Tcc* TCCx) {
|
||||||
|
while (TCCx->SYNCBUSY.reg & TCC_SYNCBUSY_MASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
void analogReadResolution( int res )
|
||||||
|
{
|
||||||
|
_readResolution = res ;
|
||||||
|
if (res > 10)
|
||||||
|
{
|
||||||
|
ADC->CTRLB.bit.RESSEL = ADC_CTRLB_RESSEL_12BIT_Val;
|
||||||
|
_ADCResolution = 12;
|
||||||
|
}
|
||||||
|
else if (res > 8)
|
||||||
|
{
|
||||||
|
ADC->CTRLB.bit.RESSEL = ADC_CTRLB_RESSEL_10BIT_Val;
|
||||||
|
_ADCResolution = 10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ADC->CTRLB.bit.RESSEL = ADC_CTRLB_RESSEL_8BIT_Val;
|
||||||
|
_ADCResolution = 8;
|
||||||
|
}
|
||||||
|
syncADC();
|
||||||
|
}
|
||||||
|
|
||||||
|
void analogWriteResolution( int res )
|
||||||
|
{
|
||||||
|
_writeResolution = res ;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t mapResolution( uint32_t value, uint32_t from, uint32_t to )
|
||||||
|
{
|
||||||
|
if ( from == to )
|
||||||
|
{
|
||||||
|
return value ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( from > to )
|
||||||
|
{
|
||||||
|
return value >> (from-to) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return value << (to-from) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Internal Reference is at 1.0v
|
||||||
|
* External Reference should be between 1v and VDDANA-0.6v=2.7v
|
||||||
|
*
|
||||||
|
* Warning : On Arduino Zero board the input/output voltage for SAMD21G18 is 3.3 volts maximum
|
||||||
|
*/
|
||||||
|
void analogReference( eAnalogReference ulMode )
|
||||||
|
{
|
||||||
|
syncADC();
|
||||||
|
switch ( ulMode )
|
||||||
|
{
|
||||||
|
case AR_INTERNAL:
|
||||||
|
case AR_INTERNAL2V23:
|
||||||
|
ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain Factor Selection
|
||||||
|
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC0_Val; // 1/1.48 VDDANA = 1/1.48* 3V3 = 2.2297
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AR_EXTERNAL:
|
||||||
|
ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain Factor Selection
|
||||||
|
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_AREFA_Val;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AR_INTERNAL1V0:
|
||||||
|
ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain Factor Selection
|
||||||
|
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INT1V_Val; // 1.0V voltage reference
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AR_INTERNAL1V65:
|
||||||
|
ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain Factor Selection
|
||||||
|
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; // 1/2 VDDANA = 0.5* 3V3 = 1.65V
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AR_DEFAULT:
|
||||||
|
default:
|
||||||
|
ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_DIV2_Val;
|
||||||
|
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; // 1/2 VDDANA = 0.5* 3V3 = 1.65V
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t analogRead( uint32_t ulPin )
|
||||||
|
{
|
||||||
|
uint32_t valueRead = 0;
|
||||||
|
|
||||||
|
if ( ulPin <= 5 ) // turn '0' -> 'A0'
|
||||||
|
{
|
||||||
|
ulPin += A0 ;
|
||||||
|
}
|
||||||
|
if (ulPin == 6) ulPin = PIN_A6;
|
||||||
|
if (ulPin == 7) ulPin = PIN_A7;
|
||||||
|
|
||||||
|
pinPeripheral(ulPin, PIO_ANALOG);
|
||||||
|
|
||||||
|
// ATSAMR, for example, doesn't have a DAC
|
||||||
|
#ifdef DAC
|
||||||
|
if (ulPin == A0) // Disable DAC, if analogWrite(A0,dval) used previously the DAC is enabled
|
||||||
|
{
|
||||||
|
syncDAC();
|
||||||
|
DAC->CTRLA.bit.ENABLE = 0x00; // Disable DAC
|
||||||
|
//DAC->CTRLB.bit.EOEN = 0x00; // The DAC output is turned off.
|
||||||
|
syncDAC();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
syncADC();
|
||||||
|
ADC->INPUTCTRL.bit.MUXPOS = g_APinDescription[ulPin].ulADCChannelNumber; // Selection for the positive ADC input
|
||||||
|
|
||||||
|
// Control A
|
||||||
|
/*
|
||||||
|
* Bit 1 ENABLE: Enable
|
||||||
|
* 0: The ADC is disabled.
|
||||||
|
* 1: The ADC is enabled.
|
||||||
|
* Due to synchronization, there is a delay from writing CTRLA.ENABLE until the peripheral is enabled/disabled. The
|
||||||
|
* value written to CTRL.ENABLE will read back immediately and the Synchronization Busy bit in the Status register
|
||||||
|
* (STATUS.SYNCBUSY) will be set. STATUS.SYNCBUSY will be cleared when the operation is complete.
|
||||||
|
*
|
||||||
|
* Before enabling the ADC, the asynchronous clock source must be selected and enabled, and the ADC reference must be
|
||||||
|
* configured. The first conversion after the reference is changed must not be used.
|
||||||
|
*/
|
||||||
|
syncADC();
|
||||||
|
ADC->CTRLA.bit.ENABLE = 0x01; // Enable ADC
|
||||||
|
|
||||||
|
// Start conversion
|
||||||
|
syncADC();
|
||||||
|
ADC->SWTRIG.bit.START = 1;
|
||||||
|
|
||||||
|
// Clear the Data Ready flag
|
||||||
|
ADC->INTFLAG.bit.RESRDY = 1;
|
||||||
|
|
||||||
|
// Start conversion again, since The first conversion after the reference is changed must not be used.
|
||||||
|
syncADC();
|
||||||
|
ADC->SWTRIG.bit.START = 1;
|
||||||
|
|
||||||
|
// Store the value
|
||||||
|
while ( ADC->INTFLAG.bit.RESRDY == 0 ); // Waiting for conversion to complete
|
||||||
|
valueRead = ADC->RESULT.reg;
|
||||||
|
|
||||||
|
syncADC();
|
||||||
|
ADC->CTRLA.bit.ENABLE = 0x00; // Disable ADC
|
||||||
|
syncADC();
|
||||||
|
|
||||||
|
return mapResolution(valueRead, _ADCResolution, _readResolution);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Right now, PWM output only works on the pins with
|
||||||
|
// hardware support. These are defined in the appropriate
|
||||||
|
// pins_*.c file. For the rest of the pins, we default
|
||||||
|
// to digital output.
|
||||||
|
void analogWrite( uint32_t ulPin, uint32_t ulValue )
|
||||||
|
{
|
||||||
|
uint32_t attr = g_APinDescription[ulPin].ulPinAttribute ;
|
||||||
|
|
||||||
|
// ATSAMR, for example, doesn't have a DAC
|
||||||
|
#ifdef DAC
|
||||||
|
if ( (attr & PIN_ATTR_ANALOG) == PIN_ATTR_ANALOG )
|
||||||
|
{
|
||||||
|
if ( ulPin != PIN_A0 ) // Only 1 DAC on A0 (PA02)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ulValue = mapResolution(ulValue, _writeResolution, 10);
|
||||||
|
|
||||||
|
syncDAC();
|
||||||
|
DAC->DATA.reg = ulValue & 0x3FF; // DAC on 10 bits.
|
||||||
|
syncDAC();
|
||||||
|
DAC->CTRLA.bit.ENABLE = 0x01; // Enable DAC
|
||||||
|
syncDAC();
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ( (attr & PIN_ATTR_PWM) == PIN_ATTR_PWM )
|
||||||
|
{
|
||||||
|
if (attr & PIN_ATTR_TIMER) {
|
||||||
|
#if !(ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10603)
|
||||||
|
// Compatibility for cores based on SAMD core <=1.6.2
|
||||||
|
if (g_APinDescription[ulPin].ulPinType == PIO_TIMER_ALT) {
|
||||||
|
pinPeripheral(ulPin, PIO_TIMER_ALT);
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
pinPeripheral(ulPin, PIO_TIMER);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// We suppose that attr has PIN_ATTR_TIMER_ALT bit set...
|
||||||
|
pinPeripheral(ulPin, PIO_TIMER_ALT);
|
||||||
|
}
|
||||||
|
|
||||||
|
Tc* TCx = 0 ;
|
||||||
|
Tcc* TCCx = 0 ;
|
||||||
|
uint8_t Channelx = GetTCChannelNumber( g_APinDescription[ulPin].ulPWMChannel ) ;
|
||||||
|
if ( GetTCNumber( g_APinDescription[ulPin].ulPWMChannel ) >= TCC_INST_NUM )
|
||||||
|
{
|
||||||
|
TCx = (Tc*) GetTC( g_APinDescription[ulPin].ulPWMChannel ) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TCCx = (Tcc*) GetTC( g_APinDescription[ulPin].ulPWMChannel ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable clocks according to TCCx instance to use
|
||||||
|
switch ( GetTCNumber( g_APinDescription[ulPin].ulPWMChannel ) )
|
||||||
|
{
|
||||||
|
case 0: // TCC0
|
||||||
|
case 1: // TCC1
|
||||||
|
// Enable GCLK for TCC0 and TCC1 (timer counter input clock)
|
||||||
|
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TCC0_TCC1 )) ;
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case 2: // TCC2
|
||||||
|
case 3: // TC3
|
||||||
|
// Enable GCLK for TCC2 and TC3 (timer counter input clock)
|
||||||
|
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TCC2_TC3 )) ;
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case 4: // TC4
|
||||||
|
case 5: // TC5
|
||||||
|
// Enable GCLK for TC4 and TC5 (timer counter input clock)
|
||||||
|
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TC4_TC5 ));
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case 6: // TC6 (not available on Zero)
|
||||||
|
case 7: // TC7 (not available on Zero)
|
||||||
|
// Enable GCLK for TC6 and TC7 (timer counter input clock)
|
||||||
|
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TC6_TC7 ));
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( GCLK->STATUS.bit.SYNCBUSY == 1 ) ;
|
||||||
|
|
||||||
|
ulValue = mapResolution(ulValue, _writeResolution, 8);
|
||||||
|
|
||||||
|
// Set PORT
|
||||||
|
if ( TCx )
|
||||||
|
{
|
||||||
|
// -- Configure TC
|
||||||
|
|
||||||
|
// Disable TCx
|
||||||
|
TCx->COUNT8.CTRLA.reg &= ~TC_CTRLA_ENABLE;
|
||||||
|
syncTC_8(TCx);
|
||||||
|
// Set Timer counter Mode to 8 bits
|
||||||
|
TCx->COUNT8.CTRLA.reg |= TC_CTRLA_MODE_COUNT8;
|
||||||
|
// Set TCx as normal PWM
|
||||||
|
TCx->COUNT8.CTRLA.reg |= TC_CTRLA_WAVEGEN_NPWM;
|
||||||
|
// Set TCx in waveform mode Normal PWM
|
||||||
|
TCx->COUNT8.CC[Channelx].reg = (uint8_t) ulValue;
|
||||||
|
syncTC_8(TCx);
|
||||||
|
// Set PER to maximum counter value (resolution : 0xFF)
|
||||||
|
TCx->COUNT8.PER.reg = 0xFF;
|
||||||
|
syncTC_8(TCx);
|
||||||
|
// Enable TCx
|
||||||
|
TCx->COUNT8.CTRLA.reg |= TC_CTRLA_ENABLE;
|
||||||
|
syncTC_8(TCx);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// -- Configure TCC
|
||||||
|
// Disable TCCx
|
||||||
|
TCCx->CTRLA.reg &= ~TCC_CTRLA_ENABLE;
|
||||||
|
syncTCC(TCCx);
|
||||||
|
// Set TCx as normal PWM
|
||||||
|
TCCx->WAVE.reg |= TCC_WAVE_WAVEGEN_NPWM;
|
||||||
|
syncTCC(TCCx);
|
||||||
|
// Set TCx in waveform mode Normal PWM
|
||||||
|
TCCx->CC[Channelx].reg = (uint32_t)ulValue;
|
||||||
|
syncTCC(TCCx);
|
||||||
|
// Set PER to maximum counter value (resolution : 0xFF)
|
||||||
|
TCCx->PER.reg = 0xFF;
|
||||||
|
syncTCC(TCCx);
|
||||||
|
// Enable TCCx
|
||||||
|
TCCx->CTRLA.reg |= TCC_CTRLA_ENABLE ;
|
||||||
|
syncTCC(TCCx);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Defaults to digital write
|
||||||
|
pinMode( ulPin, OUTPUT ) ;
|
||||||
|
ulValue = mapResolution(ulValue, _writeResolution, 8);
|
||||||
|
if ( ulValue < 128 )
|
||||||
|
{
|
||||||
|
digitalWrite( ulPin, LOW ) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
digitalWrite( ulPin, HIGH ) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
84
cores/samd10/wiring_analog.h
Normal file
84
cores/samd10/wiring_analog.h
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief SAMD products have only one reference for ADC
|
||||||
|
*/
|
||||||
|
typedef enum _eAnalogReference
|
||||||
|
{
|
||||||
|
AR_DEFAULT,
|
||||||
|
AR_INTERNAL,
|
||||||
|
AR_EXTERNAL,
|
||||||
|
AR_INTERNAL1V0,
|
||||||
|
AR_INTERNAL1V65,
|
||||||
|
AR_INTERNAL2V23
|
||||||
|
} eAnalogReference ;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Configures the reference voltage used for analog input (i.e. the value used as the top of the input range).
|
||||||
|
* This function is kept only for compatibility with existing AVR based API.
|
||||||
|
*
|
||||||
|
* \param ulMmode Should be set to AR_DEFAULT.
|
||||||
|
*/
|
||||||
|
extern void analogReference( eAnalogReference ulMode ) ;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Writes an analog value (PWM wave) to a pin.
|
||||||
|
*
|
||||||
|
* \param ulPin
|
||||||
|
* \param ulValue
|
||||||
|
*/
|
||||||
|
extern void analogWrite( uint32_t ulPin, uint32_t ulValue ) ;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Reads the value from the specified analog pin.
|
||||||
|
*
|
||||||
|
* \param ulPin
|
||||||
|
*
|
||||||
|
* \return Read value from selected pin, if no error.
|
||||||
|
*/
|
||||||
|
extern uint32_t analogRead( uint32_t ulPin ) ;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Set the resolution of analogRead return values. Default is 10 bits (range from 0 to 1023).
|
||||||
|
*
|
||||||
|
* \param res
|
||||||
|
*/
|
||||||
|
extern void analogReadResolution(int res);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Set the resolution of analogWrite parameters. Default is 8 bits (range from 0 to 255).
|
||||||
|
*
|
||||||
|
* \param res
|
||||||
|
*/
|
||||||
|
extern void analogWriteResolution(int res);
|
||||||
|
|
||||||
|
extern void analogOutputInit( void ) ;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
63
cores/samd10/wiring_constants.h
Normal file
63
cores/samd10/wiring_constants.h
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _WIRING_CONSTANTS_
|
||||||
|
#define _WIRING_CONSTANTS_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"{
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#define LOW (0x0)
|
||||||
|
#define HIGH (0x1)
|
||||||
|
|
||||||
|
#define INPUT (0x0)
|
||||||
|
#define OUTPUT (0x1)
|
||||||
|
#define INPUT_PULLUP (0x2)
|
||||||
|
#define INPUT_PULLDOWN (0x3)
|
||||||
|
|
||||||
|
#define PI 3.1415926535897932384626433832795
|
||||||
|
#define HALF_PI 1.5707963267948966192313216916398
|
||||||
|
#define TWO_PI 6.283185307179586476925286766559
|
||||||
|
#define DEG_TO_RAD 0.017453292519943295769236907684886
|
||||||
|
#define RAD_TO_DEG 57.295779513082320876798154814105
|
||||||
|
#define EULER 2.718281828459045235360287471352
|
||||||
|
|
||||||
|
#define SERIAL 0x0
|
||||||
|
#define DISPLAY 0x1
|
||||||
|
|
||||||
|
enum BitOrder {
|
||||||
|
LSBFIRST = 0,
|
||||||
|
MSBFIRST = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
// moved to WInterrupts.h
|
||||||
|
//// LOW 0
|
||||||
|
//// HIGH 1
|
||||||
|
//#define CHANGE 2
|
||||||
|
//#define FALLING 3
|
||||||
|
//#define RISING 4
|
||||||
|
//
|
||||||
|
//#define DEFAULT 1
|
||||||
|
//#define EXTERNAL 0
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#endif /* _WIRING_CONSTANTS_ */
|
||||||
116
cores/samd10/wiring_digital.c
Normal file
116
cores/samd10/wiring_digital.c
Normal file
|
|
@ -0,0 +1,116 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void pinMode( uint32_t ulPin, uint32_t ulMode )
|
||||||
|
{
|
||||||
|
// Handle the case the pin isn't usable as PIO
|
||||||
|
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
|
||||||
|
{
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set pin mode according to chapter '22.6.3 I/O Pin Configuration'
|
||||||
|
switch ( ulMode )
|
||||||
|
{
|
||||||
|
case INPUT:
|
||||||
|
// Set pin to input mode
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg=(uint8_t)(PORT_PINCFG_INEN) ;
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].DIRCLR.reg = (uint32_t)(1<<g_APinDescription[ulPin].ulPin) ;
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case INPUT_PULLUP:
|
||||||
|
// Set pin to input mode with pull-up resistor enabled
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg=(uint8_t)(PORT_PINCFG_INEN|PORT_PINCFG_PULLEN) ;
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].DIRCLR.reg = (uint32_t)(1<<g_APinDescription[ulPin].ulPin) ;
|
||||||
|
|
||||||
|
// Enable pull level (cf '22.6.3.2 Input Configuration' and '22.8.7 Data Output Value Set')
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].OUTSET.reg = (uint32_t)(1<<g_APinDescription[ulPin].ulPin) ;
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case INPUT_PULLDOWN:
|
||||||
|
// Set pin to input mode with pull-down resistor enabled
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg=(uint8_t)(PORT_PINCFG_INEN|PORT_PINCFG_PULLEN) ;
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].DIRCLR.reg = (uint32_t)(1<<g_APinDescription[ulPin].ulPin) ;
|
||||||
|
|
||||||
|
// Enable pull level (cf '22.6.3.2 Input Configuration' and '22.8.6 Data Output Value Clear')
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].OUTCLR.reg = (uint32_t)(1<<g_APinDescription[ulPin].ulPin) ;
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case OUTPUT:
|
||||||
|
// Set pin to output mode
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg&=~(uint8_t)(PORT_PINCFG_INEN) ;
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].DIRSET.reg = (uint32_t)(1<<g_APinDescription[ulPin].ulPin) ;
|
||||||
|
break ;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// do nothing
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void digitalWrite( uint32_t ulPin, uint32_t ulVal )
|
||||||
|
{
|
||||||
|
// Handle the case the pin isn't usable as PIO
|
||||||
|
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
|
||||||
|
{
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable pull-up resistor
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg=(uint8_t)(PORT_PINCFG_PULLEN) ;
|
||||||
|
|
||||||
|
switch ( ulVal )
|
||||||
|
{
|
||||||
|
case LOW:
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].OUTCLR.reg = (1ul << g_APinDescription[ulPin].ulPin) ;
|
||||||
|
break ;
|
||||||
|
|
||||||
|
default:
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].OUTSET.reg = (1ul << g_APinDescription[ulPin].ulPin) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
int digitalRead( uint32_t ulPin )
|
||||||
|
{
|
||||||
|
// Handle the case the pin isn't usable as PIO
|
||||||
|
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
|
||||||
|
{
|
||||||
|
return LOW ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( (PORT->Group[g_APinDescription[ulPin].ulPort].IN.reg & (1ul << g_APinDescription[ulPin].ulPin)) != 0 )
|
||||||
|
{
|
||||||
|
return HIGH ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return LOW ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
71
cores/samd10/wiring_digital.h
Normal file
71
cores/samd10/wiring_digital.h
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _WIRING_DIGITAL_
|
||||||
|
#define _WIRING_DIGITAL_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "WVariant.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Configures the specified pin to behave either as an input or an output. See the description of digital pins for details.
|
||||||
|
*
|
||||||
|
* \param ulPin The number of the pin whose mode you wish to set
|
||||||
|
* \param ulMode Can be INPUT, OUTPUT, INPUT_PULLUP or INPUT_PULLDOWN
|
||||||
|
*/
|
||||||
|
extern void pinMode( uint32_t dwPin, uint32_t dwMode ) ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Write a HIGH or a LOW value to a digital pin.
|
||||||
|
*
|
||||||
|
* If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the
|
||||||
|
* corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.
|
||||||
|
*
|
||||||
|
* If the pin is configured as an INPUT, writing a HIGH value with digitalWrite() will enable an internal
|
||||||
|
* 20K pullup resistor (see the tutorial on digital pins). Writing LOW will disable the pullup. The pullup
|
||||||
|
* resistor is enough to light an LED dimly, so if LEDs appear to work, but very dimly, this is a likely
|
||||||
|
* cause. The remedy is to set the pin to an output with the pinMode() function.
|
||||||
|
*
|
||||||
|
* \note Digital pin PIN_LED is harder to use as a digital input than the other digital pins because it has an LED
|
||||||
|
* and resistor attached to it that's soldered to the board on most boards. If you enable its internal 20k pull-up
|
||||||
|
* resistor, it will hang at around 1.7 V instead of the expected 5V because the onboard LED and series resistor
|
||||||
|
* pull the voltage level down, meaning it always returns LOW. If you must use pin PIN_LED as a digital input, use an
|
||||||
|
* external pull down resistor.
|
||||||
|
*
|
||||||
|
* \param dwPin the pin number
|
||||||
|
* \param dwVal HIGH or LOW
|
||||||
|
*/
|
||||||
|
extern void digitalWrite( uint32_t dwPin, uint32_t dwVal ) ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Reads the value from a specified digital pin, either HIGH or LOW.
|
||||||
|
*
|
||||||
|
* \param ulPin The number of the digital pin you want to read (int)
|
||||||
|
*
|
||||||
|
* \return HIGH or LOW
|
||||||
|
*/
|
||||||
|
extern int digitalRead( uint32_t ulPin ) ;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _WIRING_DIGITAL_ */
|
||||||
118
cores/samd10/wiring_private.c
Normal file
118
cores/samd10/wiring_private.c
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "wiring_private.h"
|
||||||
|
|
||||||
|
int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral )
|
||||||
|
{
|
||||||
|
// Handle the case the pin isn't usable as PIO
|
||||||
|
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
|
||||||
|
{
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ( ulPeripheral )
|
||||||
|
{
|
||||||
|
case PIO_DIGITAL:
|
||||||
|
case PIO_INPUT:
|
||||||
|
case PIO_INPUT_PULLUP:
|
||||||
|
case PIO_OUTPUT:
|
||||||
|
// Disable peripheral muxing, done in pinMode
|
||||||
|
// PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].bit.PMUXEN = 0 ;
|
||||||
|
|
||||||
|
// Configure pin mode, if requested
|
||||||
|
if ( ulPeripheral == PIO_INPUT )
|
||||||
|
{
|
||||||
|
pinMode( ulPin, INPUT ) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( ulPeripheral == PIO_INPUT_PULLUP )
|
||||||
|
{
|
||||||
|
pinMode( ulPin, INPUT_PULLUP ) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( ulPeripheral == PIO_OUTPUT )
|
||||||
|
{
|
||||||
|
pinMode( ulPin, OUTPUT ) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// PIO_DIGITAL, do we have to do something as all cases are covered?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case PIO_ANALOG:
|
||||||
|
case PIO_SERCOM:
|
||||||
|
case PIO_SERCOM_ALT:
|
||||||
|
case PIO_TIMER:
|
||||||
|
case PIO_TIMER_ALT:
|
||||||
|
case PIO_EXTINT:
|
||||||
|
case PIO_COM:
|
||||||
|
case PIO_AC_CLK:
|
||||||
|
#if 0
|
||||||
|
// Is the pio pin in the lower 16 ones?
|
||||||
|
// The WRCONFIG register allows update of only 16 pin max out of 32
|
||||||
|
if ( g_APinDescription[ulPin].ulPin < 16 )
|
||||||
|
{
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUXEN | PORT_WRCONFIG_PMUX( ulPeripheral ) |
|
||||||
|
PORT_WRCONFIG_WRPINCFG |
|
||||||
|
PORT_WRCONFIG_PINMASK( g_APinDescription[ulPin].ulPin ) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = PORT_WRCONFIG_HWSEL |
|
||||||
|
PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUXEN | PORT_WRCONFIG_PMUX( ulPeripheral ) |
|
||||||
|
PORT_WRCONFIG_WRPINCFG |
|
||||||
|
PORT_WRCONFIG_PINMASK( g_APinDescription[ulPin].ulPin - 16 ) ;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if ( g_APinDescription[ulPin].ulPin & 1 ) // is pin odd?
|
||||||
|
{
|
||||||
|
uint32_t temp ;
|
||||||
|
|
||||||
|
// Get whole current setup for both odd and even pins and remove odd one
|
||||||
|
temp = (PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg) & PORT_PMUX_PMUXE( 0xF ) ;
|
||||||
|
// Set new muxing
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg = temp|PORT_PMUX_PMUXO( ulPeripheral ) ;
|
||||||
|
// Enable port mux
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg |= PORT_PINCFG_PMUXEN ;
|
||||||
|
}
|
||||||
|
else // even pin
|
||||||
|
{
|
||||||
|
uint32_t temp ;
|
||||||
|
|
||||||
|
temp = (PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg) & PORT_PMUX_PMUXO( 0xF ) ;
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg = temp|PORT_PMUX_PMUXE( ulPeripheral ) ;
|
||||||
|
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg |= PORT_PINCFG_PMUXEN ; // Enable port mux
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case PIO_NOT_A_PIN:
|
||||||
|
return -1l ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0l ;
|
||||||
|
}
|
||||||
|
|
||||||
41
cores/samd10/wiring_private.h
Normal file
41
cores/samd10/wiring_private.h
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Includes Atmel CMSIS
|
||||||
|
#include "sam.h"
|
||||||
|
|
||||||
|
#include "wiring_constants.h"
|
||||||
|
|
||||||
|
int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral );
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
|
||||||
|
#include "HardwareSerial.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
74
cores/samd10/wiring_shift.c
Normal file
74
cores/samd10/wiring_shift.c
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "wiring_shift.h"
|
||||||
|
#include "wiring_digital.h"
|
||||||
|
#include "wiring_private.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint32_t shiftIn( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder )
|
||||||
|
{
|
||||||
|
uint8_t value = 0 ;
|
||||||
|
uint8_t i ;
|
||||||
|
|
||||||
|
for ( i=0 ; i < 8 ; ++i )
|
||||||
|
{
|
||||||
|
digitalWrite( ulClockPin, HIGH ) ;
|
||||||
|
|
||||||
|
if ( ulBitOrder == LSBFIRST )
|
||||||
|
{
|
||||||
|
value |= digitalRead( ulDataPin ) << i ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value |= digitalRead( ulDataPin ) << (7 - i) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
digitalWrite( ulClockPin, LOW ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void shiftOut( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder, uint32_t ulVal )
|
||||||
|
{
|
||||||
|
uint8_t i ;
|
||||||
|
|
||||||
|
for ( i=0 ; i < 8 ; i++ )
|
||||||
|
{
|
||||||
|
if ( ulBitOrder == LSBFIRST )
|
||||||
|
{
|
||||||
|
digitalWrite( ulDataPin, !!(ulVal & (1 << i)) ) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
digitalWrite( ulDataPin, !!(ulVal & (1 << (7 - i))) ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
digitalWrite( ulClockPin, HIGH ) ;
|
||||||
|
digitalWrite( ulClockPin, LOW ) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
42
cores/samd10/wiring_shift.h
Normal file
42
cores/samd10/wiring_shift.h
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _WIRING_SHIFT_
|
||||||
|
#define _WIRING_SHIFT_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief
|
||||||
|
*/
|
||||||
|
extern uint32_t shiftIn( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder ) ;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief
|
||||||
|
*/
|
||||||
|
extern void shiftOut( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder, uint32_t ulVal ) ;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _WIRING_SHIFT_ */
|
||||||
31
variants/adafruit_samd10/debug_scripts/variant.gdb
Normal file
31
variants/adafruit_samd10/debug_scripts/variant.gdb
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
#
|
||||||
|
# Arduino Zero OpenOCD script.
|
||||||
|
#
|
||||||
|
# Copyright (c) 2014-2015 Arduino LLC. All right reserved.
|
||||||
|
#
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
# See the GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
|
||||||
|
# Define 'reset' command
|
||||||
|
define reset
|
||||||
|
|
||||||
|
info reg
|
||||||
|
|
||||||
|
break main
|
||||||
|
|
||||||
|
# End of 'reset' command
|
||||||
|
end
|
||||||
|
|
||||||
|
target remote | openocd -c "interface cmsis-dap" -c "set CHIPNAME at91samd21g18" -f target/at91samdXX.cfg -c "gdb_port pipe; log_output openocd.log"
|
||||||
|
|
@ -0,0 +1,211 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Linker script to configure memory regions.
|
||||||
|
* Need modifying for a specific board.
|
||||||
|
* FLASH.ORIGIN: starting address of flash
|
||||||
|
* FLASH.LENGTH: length of flash
|
||||||
|
* RAM.ORIGIN: starting address of RAM bank 0
|
||||||
|
* RAM.LENGTH: length of RAM bank 0
|
||||||
|
*/
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00040000-0x2000 /* First 8KB used by bootloader */
|
||||||
|
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Linker script to place sections and symbol values. Should be used together
|
||||||
|
* with other linker script that defines memory regions FLASH and RAM.
|
||||||
|
* It references following symbols, which must be defined in code:
|
||||||
|
* Reset_Handler : Entry of reset handler
|
||||||
|
*
|
||||||
|
* It defines following symbols, which code can use without definition:
|
||||||
|
* __exidx_start
|
||||||
|
* __exidx_end
|
||||||
|
* __copy_table_start__
|
||||||
|
* __copy_table_end__
|
||||||
|
* __zero_table_start__
|
||||||
|
* __zero_table_end__
|
||||||
|
* __etext
|
||||||
|
* __data_start__
|
||||||
|
* __preinit_array_start
|
||||||
|
* __preinit_array_end
|
||||||
|
* __init_array_start
|
||||||
|
* __init_array_end
|
||||||
|
* __fini_array_start
|
||||||
|
* __fini_array_end
|
||||||
|
* __data_end__
|
||||||
|
* __bss_start__
|
||||||
|
* __bss_end__
|
||||||
|
* __end__
|
||||||
|
* end
|
||||||
|
* __HeapLimit
|
||||||
|
* __StackLimit
|
||||||
|
* __StackTop
|
||||||
|
* __stack
|
||||||
|
*/
|
||||||
|
ENTRY(Reset_Handler)
|
||||||
|
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
.text :
|
||||||
|
{
|
||||||
|
KEEP(*(.isr_vector))
|
||||||
|
*(.text*)
|
||||||
|
|
||||||
|
KEEP(*(.init))
|
||||||
|
KEEP(*(.fini))
|
||||||
|
|
||||||
|
/* .ctors */
|
||||||
|
*crtbegin.o(.ctors)
|
||||||
|
*crtbegin?.o(.ctors)
|
||||||
|
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
|
||||||
|
*(SORT(.ctors.*))
|
||||||
|
*(.ctors)
|
||||||
|
|
||||||
|
/* .dtors */
|
||||||
|
*crtbegin.o(.dtors)
|
||||||
|
*crtbegin?.o(.dtors)
|
||||||
|
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
|
||||||
|
*(SORT(.dtors.*))
|
||||||
|
*(.dtors)
|
||||||
|
|
||||||
|
*(.rodata*)
|
||||||
|
|
||||||
|
KEEP(*(.eh_frame*))
|
||||||
|
} > FLASH
|
||||||
|
|
||||||
|
.ARM.extab :
|
||||||
|
{
|
||||||
|
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||||
|
} > FLASH
|
||||||
|
|
||||||
|
__exidx_start = .;
|
||||||
|
.ARM.exidx :
|
||||||
|
{
|
||||||
|
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||||
|
} > FLASH
|
||||||
|
__exidx_end = .;
|
||||||
|
|
||||||
|
/* To copy multiple ROM to RAM sections,
|
||||||
|
* uncomment .copy.table section and,
|
||||||
|
* define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */
|
||||||
|
/*
|
||||||
|
.copy.table :
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
__copy_table_start__ = .;
|
||||||
|
LONG (__etext)
|
||||||
|
LONG (__data_start__)
|
||||||
|
LONG (__data_end__ - __data_start__)
|
||||||
|
LONG (__etext2)
|
||||||
|
LONG (__data2_start__)
|
||||||
|
LONG (__data2_end__ - __data2_start__)
|
||||||
|
__copy_table_end__ = .;
|
||||||
|
} > FLASH
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* To clear multiple BSS sections,
|
||||||
|
* uncomment .zero.table section and,
|
||||||
|
* define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */
|
||||||
|
/*
|
||||||
|
.zero.table :
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
__zero_table_start__ = .;
|
||||||
|
LONG (__bss_start__)
|
||||||
|
LONG (__bss_end__ - __bss_start__)
|
||||||
|
LONG (__bss2_start__)
|
||||||
|
LONG (__bss2_end__ - __bss2_start__)
|
||||||
|
__zero_table_end__ = .;
|
||||||
|
} > FLASH
|
||||||
|
*/
|
||||||
|
|
||||||
|
__etext = .;
|
||||||
|
|
||||||
|
.data : AT (__etext)
|
||||||
|
{
|
||||||
|
__data_start__ = .;
|
||||||
|
*(vtable)
|
||||||
|
*(.data*)
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
/* preinit data */
|
||||||
|
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||||
|
KEEP(*(.preinit_array))
|
||||||
|
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
/* init data */
|
||||||
|
PROVIDE_HIDDEN (__init_array_start = .);
|
||||||
|
KEEP(*(SORT(.init_array.*)))
|
||||||
|
KEEP(*(.init_array))
|
||||||
|
PROVIDE_HIDDEN (__init_array_end = .);
|
||||||
|
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
/* finit data */
|
||||||
|
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||||
|
KEEP(*(SORT(.fini_array.*)))
|
||||||
|
KEEP(*(.fini_array))
|
||||||
|
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||||
|
|
||||||
|
KEEP(*(.jcr*))
|
||||||
|
. = ALIGN(4);
|
||||||
|
/* All data end */
|
||||||
|
__data_end__ = .;
|
||||||
|
|
||||||
|
} > RAM
|
||||||
|
|
||||||
|
.bss :
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
__bss_start__ = .;
|
||||||
|
*(.bss*)
|
||||||
|
*(COMMON)
|
||||||
|
. = ALIGN(4);
|
||||||
|
__bss_end__ = .;
|
||||||
|
} > RAM
|
||||||
|
|
||||||
|
.heap (COPY):
|
||||||
|
{
|
||||||
|
__end__ = .;
|
||||||
|
PROVIDE(end = .);
|
||||||
|
*(.heap*)
|
||||||
|
__HeapLimit = .;
|
||||||
|
} > RAM
|
||||||
|
|
||||||
|
/* .stack_dummy section doesn't contains any symbols. It is only
|
||||||
|
* used for linker to calculate size of stack sections, and assign
|
||||||
|
* values to stack symbols later */
|
||||||
|
.stack_dummy (COPY):
|
||||||
|
{
|
||||||
|
*(.stack*)
|
||||||
|
} > RAM
|
||||||
|
|
||||||
|
/* Set stack top to end of RAM, and stack limit move down by
|
||||||
|
* size of stack_dummy section */
|
||||||
|
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
|
||||||
|
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
|
||||||
|
PROVIDE(__stack = __StackTop);
|
||||||
|
|
||||||
|
__ram_end__ = ORIGIN(RAM) + LENGTH(RAM) -1 ;
|
||||||
|
|
||||||
|
/* Check if data + heap + stack exceeds RAM limit */
|
||||||
|
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,212 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Linker script to configure memory regions.
|
||||||
|
* Need modifying for a specific board.
|
||||||
|
* FLASH.ORIGIN: starting address of flash
|
||||||
|
* FLASH.LENGTH: length of flash
|
||||||
|
* RAM.ORIGIN: starting address of RAM bank 0
|
||||||
|
* RAM.LENGTH: length of RAM bank 0
|
||||||
|
*/
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000
|
||||||
|
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Linker script to place sections and symbol values. Should be used together
|
||||||
|
* with other linker script that defines memory regions FLASH and RAM.
|
||||||
|
* It references following symbols, which must be defined in code:
|
||||||
|
* Reset_Handler : Entry of reset handler
|
||||||
|
*
|
||||||
|
* It defines following symbols, which code can use without definition:
|
||||||
|
* __exidx_start
|
||||||
|
* __exidx_end
|
||||||
|
* __copy_table_start__
|
||||||
|
* __copy_table_end__
|
||||||
|
* __zero_table_start__
|
||||||
|
* __zero_table_end__
|
||||||
|
* __etext
|
||||||
|
* __data_start__
|
||||||
|
* __preinit_array_start
|
||||||
|
* __preinit_array_end
|
||||||
|
* __init_array_start
|
||||||
|
* __init_array_end
|
||||||
|
* __fini_array_start
|
||||||
|
* __fini_array_end
|
||||||
|
* __data_end__
|
||||||
|
* __bss_start__
|
||||||
|
* __bss_end__
|
||||||
|
* __end__
|
||||||
|
* end
|
||||||
|
* __HeapLimit
|
||||||
|
* __StackLimit
|
||||||
|
* __StackTop
|
||||||
|
* __stack
|
||||||
|
* __ram_end__
|
||||||
|
*/
|
||||||
|
ENTRY(Reset_Handler)
|
||||||
|
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
.text :
|
||||||
|
{
|
||||||
|
KEEP(*(.isr_vector))
|
||||||
|
*(.text*)
|
||||||
|
|
||||||
|
KEEP(*(.init))
|
||||||
|
KEEP(*(.fini))
|
||||||
|
|
||||||
|
/* .ctors */
|
||||||
|
*crtbegin.o(.ctors)
|
||||||
|
*crtbegin?.o(.ctors)
|
||||||
|
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
|
||||||
|
*(SORT(.ctors.*))
|
||||||
|
*(.ctors)
|
||||||
|
|
||||||
|
/* .dtors */
|
||||||
|
*crtbegin.o(.dtors)
|
||||||
|
*crtbegin?.o(.dtors)
|
||||||
|
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
|
||||||
|
*(SORT(.dtors.*))
|
||||||
|
*(.dtors)
|
||||||
|
|
||||||
|
*(.rodata*)
|
||||||
|
|
||||||
|
KEEP(*(.eh_frame*))
|
||||||
|
} > FLASH
|
||||||
|
|
||||||
|
.ARM.extab :
|
||||||
|
{
|
||||||
|
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||||
|
} > FLASH
|
||||||
|
|
||||||
|
__exidx_start = .;
|
||||||
|
.ARM.exidx :
|
||||||
|
{
|
||||||
|
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||||
|
} > FLASH
|
||||||
|
__exidx_end = .;
|
||||||
|
|
||||||
|
/* To copy multiple ROM to RAM sections,
|
||||||
|
* uncomment .copy.table section and,
|
||||||
|
* define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */
|
||||||
|
/*
|
||||||
|
.copy.table :
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
__copy_table_start__ = .;
|
||||||
|
LONG (__etext)
|
||||||
|
LONG (__data_start__)
|
||||||
|
LONG (__data_end__ - __data_start__)
|
||||||
|
LONG (__etext2)
|
||||||
|
LONG (__data2_start__)
|
||||||
|
LONG (__data2_end__ - __data2_start__)
|
||||||
|
__copy_table_end__ = .;
|
||||||
|
} > FLASH
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* To clear multiple BSS sections,
|
||||||
|
* uncomment .zero.table section and,
|
||||||
|
* define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */
|
||||||
|
/*
|
||||||
|
.zero.table :
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
__zero_table_start__ = .;
|
||||||
|
LONG (__bss_start__)
|
||||||
|
LONG (__bss_end__ - __bss_start__)
|
||||||
|
LONG (__bss2_start__)
|
||||||
|
LONG (__bss2_end__ - __bss2_start__)
|
||||||
|
__zero_table_end__ = .;
|
||||||
|
} > FLASH
|
||||||
|
*/
|
||||||
|
|
||||||
|
__etext = .;
|
||||||
|
|
||||||
|
.data : AT (__etext)
|
||||||
|
{
|
||||||
|
__data_start__ = .;
|
||||||
|
*(vtable)
|
||||||
|
*(.data*)
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
/* preinit data */
|
||||||
|
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||||
|
KEEP(*(.preinit_array))
|
||||||
|
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
/* init data */
|
||||||
|
PROVIDE_HIDDEN (__init_array_start = .);
|
||||||
|
KEEP(*(SORT(.init_array.*)))
|
||||||
|
KEEP(*(.init_array))
|
||||||
|
PROVIDE_HIDDEN (__init_array_end = .);
|
||||||
|
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
/* finit data */
|
||||||
|
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||||
|
KEEP(*(SORT(.fini_array.*)))
|
||||||
|
KEEP(*(.fini_array))
|
||||||
|
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||||
|
|
||||||
|
KEEP(*(.jcr*))
|
||||||
|
. = ALIGN(4);
|
||||||
|
/* All data end */
|
||||||
|
__data_end__ = .;
|
||||||
|
|
||||||
|
} > RAM
|
||||||
|
|
||||||
|
.bss :
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
__bss_start__ = .;
|
||||||
|
*(.bss*)
|
||||||
|
*(COMMON)
|
||||||
|
. = ALIGN(4);
|
||||||
|
__bss_end__ = .;
|
||||||
|
} > RAM
|
||||||
|
|
||||||
|
.heap (COPY):
|
||||||
|
{
|
||||||
|
__end__ = .;
|
||||||
|
PROVIDE(end = .);
|
||||||
|
*(.heap*)
|
||||||
|
__HeapLimit = .;
|
||||||
|
} > RAM
|
||||||
|
|
||||||
|
/* .stack_dummy section doesn't contains any symbols. It is only
|
||||||
|
* used for linker to calculate size of stack sections, and assign
|
||||||
|
* values to stack symbols later */
|
||||||
|
.stack_dummy (COPY):
|
||||||
|
{
|
||||||
|
*(.stack*)
|
||||||
|
} > RAM
|
||||||
|
|
||||||
|
/* Set stack top to end of RAM, and stack limit move down by
|
||||||
|
* size of stack_dummy section */
|
||||||
|
__StackTop = ORIGIN(RAM) + LENGTH(RAM) ;
|
||||||
|
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
|
||||||
|
PROVIDE(__stack = __StackTop);
|
||||||
|
|
||||||
|
__ram_end__ = ORIGIN(RAM) + LENGTH(RAM) -1 ;
|
||||||
|
|
||||||
|
/* Check if data + heap + stack exceeds RAM limit */
|
||||||
|
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
|
||||||
|
}
|
||||||
30
variants/adafruit_samd10/openocd_scripts/arduino_zero.cfg
Normal file
30
variants/adafruit_samd10/openocd_scripts/arduino_zero.cfg
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
#
|
||||||
|
# Arduino Zero OpenOCD script.
|
||||||
|
#
|
||||||
|
# Copyright (c) 2014-2015 Arduino LLC. All right reserved.
|
||||||
|
#
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
# See the GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
#
|
||||||
|
|
||||||
|
source [find interface/cmsis-dap.cfg]
|
||||||
|
|
||||||
|
# chip name
|
||||||
|
set CHIPNAME at91samd21g18
|
||||||
|
set ENDIAN little
|
||||||
|
|
||||||
|
# choose a port here
|
||||||
|
set telnet_port 0
|
||||||
|
|
||||||
|
source [find target/at91samdXX.cfg]
|
||||||
21
variants/adafruit_samd10/pins_arduino.h
Normal file
21
variants/adafruit_samd10/pins_arduino.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
// API compatibility
|
||||||
|
#include "variant.h"
|
||||||
|
|
||||||
212
variants/adafruit_samd10/variant.cpp
Normal file
212
variants/adafruit_samd10/variant.cpp
Normal file
|
|
@ -0,0 +1,212 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* + Pin number + ZERO Board pin | PIN | Label/Name | Comments (* is for default peripheral in use)
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | | Digital Low | | |
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | 0 | 0 -> RX | PA11 | | EIC/EXTINT[11] ADC/AIN[19] PTC/X[3] *SERCOM0/PAD[3] SERCOM2/PAD[3] TCC0/WO[3] TCC1/WO[1]
|
||||||
|
* | 1 | 1 <- TX | PA10 | | EIC/EXTINT[10] ADC/AIN[18] PTC/X[2] *SERCOM0/PAD[2] TCC0/WO[2] TCC1/WO[0]
|
||||||
|
* | 2 | 2 | PA14 | | EIC/EXTINT[14] SERCOM2/PAD[2] SERCOM4/PAD[2] TC3/WO[0] TCC0/WO[4]
|
||||||
|
* | 3 | ~3 | PA09 | | EIC/EXTINT[9] ADC/AIN[17] PTC/X[1] SERCOM0/PAD[1] SERCOM2/PAD[1] *TCC0/WO[1] TCC1/WO[3]
|
||||||
|
* | 4 | ~4 | PA08 | | EIC/NMI ADC/AIN[16] PTC/X[0] SERCOM0/PAD[0] SERCOM2/PAD[0] *TCC0/WO[0] TCC1/WO[2]
|
||||||
|
* | 5 | ~5 | PA15 | | EIC/EXTINT[15] SERCOM2/PAD[3] SERCOM4/PAD[3] *TC3/WO[1] TCC0/WO[5]
|
||||||
|
* | 6 | ~6 | PA20 | | EIC/EXTINT[4] PTC/X[8] SERCOM5/PAD[2] SERCOM3/PAD[2] *TCC0/WO[6]
|
||||||
|
* | 7 | 7 | PA21 | | EIC/EXTINT[5] PTC/X[9] SERCOM5/PAD[3] SERCOM3/PAD[3] TCC0/WO[7]
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | | Digital High | | |
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | 8 | ~8 | PA06 | | EIC/EXTINT[6] ADC/AIN[6] AC/AIN[2] PTC/Y[4] SERCOM0/PAD[2] *TCC1/WO[0]
|
||||||
|
* | 9 | ~9 | PA07 | | EIC/EXTINT[7] ADC/AIN[7] AC/AIN[3] PTC/Y[5] SERCOM0/PAD[3] *TCC1/WO[1]
|
||||||
|
* | 10 | ~10 | PA18 | | EIC/EXTINT[2] PTC/X[6] +SERCOM1/PAD[2] SERCOM3/PAD[2] *TC3/WO[0] TCC0/WO[2]
|
||||||
|
* | 11 | ~11 | PA16 | | EIC/EXTINT[0] PTC/X[4] +SERCOM1/PAD[0] SERCOM3/PAD[0] *TCC2/WO[0] TCC0/WO[6]
|
||||||
|
* | 12 | ~12 | PA19 | | EIC/EXTINT[3] PTC/X[7] +SERCOM1/PAD[3] SERCOM3/PAD[3] TC3/WO[1] *TCC0/WO[3]
|
||||||
|
* | 13 | ~13 | PA17 | LED | EIC/EXTINT[1] PTC/X[5] +SERCOM1/PAD[1] SERCOM3/PAD[1] *TCC2/WO[1] TCC0/WO[7]
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | | Analog Connector | | |
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | 14 | A0 | PA02 | A0 | EIC/EXTINT[2] *ADC/AIN[0] DAC/VOUT PTC/Y[0]
|
||||||
|
* | 15 | A1 | PB08 | A1 | EIC/EXTINT[8] *ADC/AIN[2] PTC/Y[14] SERCOM4/PAD[0] TC4/WO[0]
|
||||||
|
* | 16 | A2 | PB09 | A2 | EIC/EXTINT[9] *ADC/AIN[3] PTC/Y[15] SERCOM4/PAD[1] TC4/WO[1]
|
||||||
|
* | 17 | A3 | PA04 | A3 | EIC/EXTINT[4] *ADC/AIN[4] AC/AIN[0] PTC/Y[2] SERCOM0/PAD[0] TCC0/WO[0]
|
||||||
|
* | 18 | A4 | PA05 | A4 | EIC/EXTINT[5] *ADC/AIN[5] AC/AIN[1] PTC/Y[5] SERCOM0/PAD[1] TCC0/WO[1]
|
||||||
|
* | 19 | A5 | PB02 | A5 | EIC/EXTINT[2] *ADC/AIN[10] PTC/Y[8] SERCOM5/PAD[0]
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | | Wire | | |
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | 20 | SDA | PA22 | SDA | EIC/EXTINT[6] PTC/X[10] *SERCOM3/PAD[0] SERCOM5/PAD[0] TC4/WO[0] TCC0/WO[4]
|
||||||
|
* | 21 | SCL | PA23 | SCL | EIC/EXTINT[7] PTC/X[11] *SERCOM3/PAD[1] SERCOM5/PAD[1] TC4/WO[1] TCC0/WO[5]
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | |SPI (Legacy ICSP) | | |
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | 22 | 1 | PA12 | MISO | EIC/EXTINT[12] SERCOM2/PAD[0] *SERCOM4/PAD[0] TCC2/WO[0] TCC0/WO[6]
|
||||||
|
* | | 2 | | 5V0 |
|
||||||
|
* | 23 | 4 | PB10 | MOSI | EIC/EXTINT[10] *SERCOM4/PAD[2] TC5/WO[0] TCC0/WO[4]
|
||||||
|
* | 24 | 3 | PB11 | SCK | EIC/EXTINT[11] *SERCOM4/PAD[3] TC5/WO[1] TCC0/WO[5]
|
||||||
|
* | | 5 | | RESET |
|
||||||
|
* | | 6 | | GND |
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | | LEDs | | |
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | 25 | | PB03 | RX |
|
||||||
|
* | 26 | | PA27 | TX |
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | | USB | | |
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | 27 | | PA28 | USB_HOST_ENABLE | EIC/EXTINT[8]
|
||||||
|
* | 28 | | PA24 | USB_NEGATIVE | *USB/DM
|
||||||
|
* | 29 | | PA25 | USB_POSITIVE | *USB/DP
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | | EDBG | | |
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | 30 | | PB22 | EDBG_UART TX | *SERCOM5/PAD[2]
|
||||||
|
* | 31 | | PB23 | EDBG_UART RX | *SERCOM5/PAD[3]
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | 32 | | PA22 | EDBG_SDA | Pin 20 (SDA)
|
||||||
|
* | 33 | | PA23 | EDBG_SCL | Pin 21 (SCL)
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | 34 | | PA19 | EDBG_MISO | EIC/EXTINT[3] *SERCOM1/PAD[3] SERCOM3/PAD[3] TC3/WO[1] TCC0/WO[3]
|
||||||
|
* | 35 | | PA16 | EDBG_MOSI | EIC/EXTINT[0] *SERCOM1/PAD[0] SERCOM3/PAD[0] TCC2/WO[0] TCC0/WO[6]
|
||||||
|
* | 36 | | PA18 | EDBG_SS | EIC/EXTINT[2] *SERCOM1/PAD[2] SERCOM3/PAD[2] TC3/WO[0] TCC0/WO[2]
|
||||||
|
* | 37 | | PA17 | EDBG_SCK | EIC/EXTINT[1] *SERCOM1/PAD[1] SERCOM3/PAD[1] TCC2/WO[1] TCC0/WO[7]
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | 38 | ATN | PA13 | EDBG_GPIO0 | EIC/EXTINT[13] SERCOM2/PAD[1] SERCOM4/PAD[1] *TCC2/WO[1] TCC0/WO[7]
|
||||||
|
* | 39 | | PA21 | EDBG_GPIO1 | Pin 7
|
||||||
|
* | 40 | | PA06 | EDBG_GPIO2 | Pin 8
|
||||||
|
* | 41 | | PA07 | EDBG_GPIO3 | Pin 9
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | | | | |
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | | GND | | |
|
||||||
|
* | 42 | AREF | PA03 | | EIC/EXTINT[3] *[ADC|DAC]/VREFA ADC/AIN[1] PTC/Y[1]
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | |32.768KHz Crystal | | |
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
* | | | PA00 | XIN32 | EIC/EXTINT[0] SERCOM1/PAD[0] TCC2/WO[0]
|
||||||
|
* | | | PA01 | XOUT32 | EIC/EXTINT[1] SERCOM1/PAD[1] TCC2/WO[1]
|
||||||
|
* +------------+------------------+--------+-----------------+--------------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "variant.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Pins descriptions
|
||||||
|
*/
|
||||||
|
const PinDescription g_APinDescription[]=
|
||||||
|
{
|
||||||
|
// 0..13 - Digital pins
|
||||||
|
// ----------------------
|
||||||
|
// 0/1 - SERCOM/UART (Serial1)
|
||||||
|
{ PORTA, 11, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_11 }, // RX: SERCOM0/PAD[3]
|
||||||
|
{ PORTA, 10, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_10 }, // TX: SERCOM0/PAD[2]
|
||||||
|
|
||||||
|
// 2..12
|
||||||
|
// Digital Low
|
||||||
|
{ PORTA, 14, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_14 },
|
||||||
|
{ PORTA, 9, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH1, TCC0_CH1, EXTERNAL_INT_9 }, // TCC0/WO[1]
|
||||||
|
{ PORTA, 8, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH0, TCC0_CH0, EXTERNAL_INT_NMI }, // TCC0/WO[0]
|
||||||
|
{ PORTA, 15, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM3_CH1, TC3_CH1, EXTERNAL_INT_15 }, // TC3/WO[1]
|
||||||
|
{ PORTA, 20, PIO_TIMER_ALT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER_ALT), No_ADC_Channel, PWM0_CH6, TCC0_CH6, EXTERNAL_INT_4 }, // TCC0/WO[6]
|
||||||
|
{ PORTA, 21, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 },
|
||||||
|
|
||||||
|
// Digital High
|
||||||
|
{ PORTA, 6, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM1_CH0, TCC1_CH0, EXTERNAL_INT_6 }, // TCC1/WO[0]
|
||||||
|
{ PORTA, 7, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM1_CH1, TCC1_CH1, EXTERNAL_INT_7 }, // TCC1/WO[1]
|
||||||
|
{ PORTA, 18, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM3_CH0, TC3_CH0, EXTERNAL_INT_2 }, // TC3/WO[0]
|
||||||
|
{ PORTA, 16, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM2_CH0, TCC2_CH0, EXTERNAL_INT_0 }, // TCC2/WO[0]
|
||||||
|
{ PORTA, 19, PIO_TIMER_ALT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER_ALT), No_ADC_Channel, PWM0_CH3, TCC0_CH3, EXTERNAL_INT_3 }, // TCC0/WO[3]
|
||||||
|
|
||||||
|
// 13 (LED)
|
||||||
|
{ PORTA, 17, PIO_PWM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM2_CH1, NOT_ON_TIMER, EXTERNAL_INT_1 }, // TCC2/WO[1]
|
||||||
|
|
||||||
|
// 14..19 - Analog pins
|
||||||
|
// --------------------
|
||||||
|
{ PORTA, 2, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 }, // ADC/AIN[0]
|
||||||
|
{ PORTB, 8, PIO_ANALOG, (PIN_ATTR_PWM|PIN_ATTR_TIMER), ADC_Channel2, PWM4_CH0, TC4_CH0, EXTERNAL_INT_8 }, // ADC/AIN[2]
|
||||||
|
{ PORTB, 9, PIO_ANALOG, (PIN_ATTR_PWM|PIN_ATTR_TIMER), ADC_Channel3, PWM4_CH1, TC4_CH1, EXTERNAL_INT_9 }, // ADC/AIN[3]
|
||||||
|
{ PORTA, 4, PIO_ANALOG, 0, ADC_Channel4, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, // ADC/AIN[4]
|
||||||
|
{ PORTA, 5, PIO_ANALOG, 0, ADC_Channel5, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 }, // ADC/AIN[5]
|
||||||
|
{ PORTB, 2, PIO_ANALOG, 0, ADC_Channel10, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 }, // ADC/AIN[10]
|
||||||
|
|
||||||
|
// 20..21 I2C pins (SDA/SCL and also EDBG:SDA/SCL)
|
||||||
|
// ----------------------
|
||||||
|
{ PORTA, 22, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6 }, // SDA: SERCOM3/PAD[0]
|
||||||
|
{ PORTA, 23, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 }, // SCL: SERCOM3/PAD[1]
|
||||||
|
|
||||||
|
// 22..24 - SPI pins (ICSP:MISO,SCK,MOSI)
|
||||||
|
// ----------------------
|
||||||
|
{ PORTA, 12, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_12 }, // MISO: SERCOM4/PAD[0]
|
||||||
|
{ PORTB, 10, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_10 }, // MOSI: SERCOM4/PAD[2]
|
||||||
|
{ PORTB, 11, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_11 }, // SCK: SERCOM4/PAD[3]
|
||||||
|
|
||||||
|
// 25..26 - RX/TX LEDS (PB03/PA27)
|
||||||
|
// --------------------
|
||||||
|
{ PORTB, 3, PIO_OUTPUT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // used as output only
|
||||||
|
{ PORTA, 27, PIO_OUTPUT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // used as output only
|
||||||
|
|
||||||
|
// 27..29 - USB
|
||||||
|
// --------------------
|
||||||
|
{ PORTA, 28, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB Host enable
|
||||||
|
{ PORTA, 24, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DM
|
||||||
|
{ PORTA, 25, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DP
|
||||||
|
|
||||||
|
// 30..41 - EDBG
|
||||||
|
// ----------------------
|
||||||
|
// 30/31 - EDBG/UART
|
||||||
|
{ PORTB, 22, PIO_SERCOM_ALT, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // TX: SERCOM5/PAD[2]
|
||||||
|
{ PORTB, 23, PIO_SERCOM_ALT, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // RX: SERCOM5/PAD[3]
|
||||||
|
|
||||||
|
// 32/33 I2C (SDA/SCL and also EDBG:SDA/SCL)
|
||||||
|
{ PORTA, 22, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // SDA: SERCOM3/PAD[0]
|
||||||
|
{ PORTA, 23, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // SCL: SERCOM3/PAD[1]
|
||||||
|
|
||||||
|
// 34..37 - EDBG/SPI
|
||||||
|
{ PORTA, 19, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // MISO: SERCOM1/PAD[3]
|
||||||
|
{ PORTA, 16, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // MOSI: SERCOM1/PAD[0]
|
||||||
|
{ PORTA, 18, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // SS: SERCOM1/PAD[2]
|
||||||
|
{ PORTA, 17, PIO_SERCOM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // SCK: SERCOM1/PAD[1]
|
||||||
|
|
||||||
|
// 38..41 - EDBG/Digital
|
||||||
|
{ PORTA, 13, PIO_PWM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM0_CH5, NOT_ON_TIMER, EXTERNAL_INT_13 }, // EIC/EXTINT[13] *TCC2/WO[1] TCC0/WO[7]
|
||||||
|
{ PORTA, 21, PIO_PWM_ALT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM0_CH7, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // Pin 7
|
||||||
|
{ PORTA, 6, PIO_PWM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM1_CH0, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // Pin 8
|
||||||
|
{ PORTA, 7, PIO_PWM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM1_CH1, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // Pin 9
|
||||||
|
|
||||||
|
// 42 (AREF)
|
||||||
|
{ PORTA, 3, PIO_ANALOG, PIN_ATTR_ANALOG, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // DAC/VREFP
|
||||||
|
|
||||||
|
// ----------------------
|
||||||
|
// 43 - Alternate use of A0 (DAC output)
|
||||||
|
{ PORTA, 2, PIO_ANALOG, PIN_ATTR_ANALOG, DAC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 }, // DAC/VOUT
|
||||||
|
} ;
|
||||||
|
|
||||||
|
const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM]={ TCC0 } ;
|
||||||
|
|
||||||
|
// Multi-serial objects instantiation
|
||||||
|
SERCOM sercom0( SERCOM0 ) ;
|
||||||
|
SERCOM sercom1( SERCOM1 ) ;
|
||||||
|
SERCOM sercom2( SERCOM2 ) ;
|
||||||
|
|
||||||
|
Uart Serial( &sercom2, PIN_SERIAL1_RX, PIN_SERIAL1_TX, PAD_SERIAL1_RX, PAD_SERIAL1_TX ) ;
|
||||||
|
|
||||||
|
void SERCOM2_Handler()
|
||||||
|
{
|
||||||
|
Serial.IrqHandler();
|
||||||
|
}
|
||||||
205
variants/adafruit_samd10/variant.h
Normal file
205
variants/adafruit_samd10/variant.h
Normal file
|
|
@ -0,0 +1,205 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _VARIANT_ARDUINO_ZERO_
|
||||||
|
#define _VARIANT_ARDUINO_ZERO_
|
||||||
|
|
||||||
|
// The definitions here needs a SAMD core >=1.6.6
|
||||||
|
#define ARDUINO_SAMD_VARIANT_COMPLIANCE 10606
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
* Definitions
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/** Frequency of the board main oscillator */
|
||||||
|
#define VARIANT_MAINOSC (32768ul)
|
||||||
|
|
||||||
|
/** Master clock frequency */
|
||||||
|
#define VARIANT_MCK (48000000ul)
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
* Headers
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "WVariant.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#include "SERCOM.h"
|
||||||
|
#include "Uart.h"
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
* Pins
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// Number of pins defined in PinDescription array
|
||||||
|
#define PINS_COUNT (26u)
|
||||||
|
#define NUM_DIGITAL_PINS (20u)
|
||||||
|
#define NUM_ANALOG_INPUTS (8u)
|
||||||
|
#define NUM_ANALOG_OUTPUTS (1u)
|
||||||
|
#define analogInputToDigitalPin(p) ((p < 6u) ? (p) + 14u : -1)
|
||||||
|
|
||||||
|
#define digitalPinToPort(P) ( &(PORT->Group[g_APinDescription[P].ulPort]) )
|
||||||
|
#define digitalPinToBitMask(P) ( 1 << g_APinDescription[P].ulPin )
|
||||||
|
//#define analogInPinToBit(P) ( )
|
||||||
|
#define portOutputRegister(port) ( &(port->OUT.reg) )
|
||||||
|
#define portInputRegister(port) ( &(port->IN.reg) )
|
||||||
|
#define portModeRegister(port) ( &(port->DIR.reg) )
|
||||||
|
#define digitalPinHasPWM(P) ( g_APinDescription[P].ulPWMChannel != NOT_ON_PWM || g_APinDescription[P].ulTCChannel != NOT_ON_TIMER )
|
||||||
|
|
||||||
|
/*
|
||||||
|
* digitalPinToTimer(..) is AVR-specific and is not defined for SAMD
|
||||||
|
* architecture. If you need to check if a pin supports PWM you must
|
||||||
|
* use digitalPinHasPWM(..).
|
||||||
|
*
|
||||||
|
* https://github.com/arduino/Arduino/issues/1833
|
||||||
|
*/
|
||||||
|
// #define digitalPinToTimer(P)
|
||||||
|
|
||||||
|
// LEDs
|
||||||
|
#define PIN_LED_13 (13u)
|
||||||
|
#define PIN_LED_RXL (25u)
|
||||||
|
#define PIN_LED_TXL (26u)
|
||||||
|
#define PIN_LED PIN_LED_13
|
||||||
|
#define PIN_LED2 PIN_LED_RXL
|
||||||
|
#define PIN_LED3 PIN_LED_TXL
|
||||||
|
#define LED_BUILTIN PIN_LED_13
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Analog pins
|
||||||
|
*/
|
||||||
|
#define PIN_A0 (14ul)
|
||||||
|
#define PIN_A1 (15ul)
|
||||||
|
#define PIN_A2 (16ul)
|
||||||
|
#define PIN_A3 (17ul)
|
||||||
|
#define PIN_A4 (18ul)
|
||||||
|
#define PIN_A5 (19ul)
|
||||||
|
#define PIN_A6 (8ul)
|
||||||
|
#define PIN_A7 (9ul)
|
||||||
|
#define PIN_DAC0 (14ul)
|
||||||
|
|
||||||
|
static const uint8_t A0 = PIN_A0;
|
||||||
|
static const uint8_t A1 = PIN_A1;
|
||||||
|
static const uint8_t A2 = PIN_A2;
|
||||||
|
static const uint8_t A3 = PIN_A3;
|
||||||
|
static const uint8_t A4 = PIN_A4;
|
||||||
|
static const uint8_t A5 = PIN_A5;
|
||||||
|
static const uint8_t A6 = PIN_A6 ;
|
||||||
|
static const uint8_t A7 = PIN_A7 ;
|
||||||
|
static const uint8_t DAC0 = PIN_DAC0;
|
||||||
|
|
||||||
|
#define ADC_RESOLUTION 12
|
||||||
|
|
||||||
|
// Other pins
|
||||||
|
#define PIN_ATN (38ul)
|
||||||
|
static const uint8_t ATN = PIN_ATN;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Serial interfaces
|
||||||
|
*/
|
||||||
|
// Serial (EDBG)
|
||||||
|
#define PIN_SERIAL_RX (31ul)
|
||||||
|
#define PIN_SERIAL_TX (30ul)
|
||||||
|
#define PAD_SERIAL_TX (UART_TX_PAD_2)
|
||||||
|
#define PAD_SERIAL_RX (SERCOM_RX_PAD_3)
|
||||||
|
|
||||||
|
// Serial1
|
||||||
|
#define PIN_SERIAL1_RX (0ul)
|
||||||
|
#define PIN_SERIAL1_TX (1ul)
|
||||||
|
#define PAD_SERIAL1_TX (UART_TX_PAD_2)
|
||||||
|
#define PAD_SERIAL1_RX (SERCOM_RX_PAD_3)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SPI Interfaces
|
||||||
|
*/
|
||||||
|
#define SPI_INTERFACES_COUNT 1
|
||||||
|
|
||||||
|
#define PIN_SPI_MISO (22u)
|
||||||
|
#define PIN_SPI_MOSI (23u)
|
||||||
|
#define PIN_SPI_SCK (24u)
|
||||||
|
#define PERIPH_SPI sercom4
|
||||||
|
#define PAD_SPI_TX SPI_PAD_2_SCK_3
|
||||||
|
#define PAD_SPI_RX SERCOM_RX_PAD_0
|
||||||
|
|
||||||
|
static const uint8_t SS = PIN_A2 ; // SERCOM4 last PAD is present on A2 but HW SS isn't used. Set here only for reference.
|
||||||
|
static const uint8_t MOSI = PIN_SPI_MOSI ;
|
||||||
|
static const uint8_t MISO = PIN_SPI_MISO ;
|
||||||
|
static const uint8_t SCK = PIN_SPI_SCK ;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wire Interfaces
|
||||||
|
*/
|
||||||
|
#define WIRE_INTERFACES_COUNT 1
|
||||||
|
|
||||||
|
#define PIN_WIRE_SDA (20u)
|
||||||
|
#define PIN_WIRE_SCL (21u)
|
||||||
|
#define PERIPH_WIRE sercom1
|
||||||
|
#define WIRE_IT_HANDLER SERCOM1_Handler
|
||||||
|
|
||||||
|
static const uint8_t SDA = PIN_WIRE_SDA;
|
||||||
|
static const uint8_t SCL = PIN_WIRE_SCL;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
* Arduino objects - C++ only
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
* ===== SERCOM DEFINITION
|
||||||
|
* =========================
|
||||||
|
*/
|
||||||
|
extern SERCOM sercom0;
|
||||||
|
extern SERCOM sercom1;
|
||||||
|
extern SERCOM sercom2;
|
||||||
|
|
||||||
|
extern Uart Serial;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// These serial port names are intended to allow libraries and architecture-neutral
|
||||||
|
// sketches to automatically default to the correct port name for a particular type
|
||||||
|
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||||
|
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||||
|
//
|
||||||
|
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||||
|
//
|
||||||
|
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||||
|
//
|
||||||
|
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||||
|
//
|
||||||
|
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||||
|
//
|
||||||
|
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||||
|
// pins are NOT connected to anything by default.
|
||||||
|
#define SERIAL_PORT_MONITOR Serial
|
||||||
|
// Serial has no physical pins broken out, so it's not listed as HARDWARE port
|
||||||
|
#define SERIAL_PORT_HARDWARE Serial
|
||||||
|
#define SERIAL_PORT_HARDWARE_OPEN Serial
|
||||||
|
|
||||||
|
#endif /* _VARIANT_ARDUINO_ZERO_ */
|
||||||
|
|
||||||
Loading…
Reference in a new issue