periph_cpu_common.h File Reference

Common CPU specific definitions for all SAMx21 based CPUs. More...

Detailed Description

Common CPU specific definitions for all SAMx21 based CPUs.

Common CPU specific definitions for all SAMx21 based CPUs

Author
Hauke Petersen hauke.nosp@m..pet.nosp@m.ersen.nosp@m.@fu-.nosp@m.berli.nosp@m.n.de
Dylan Laduranty dylan.nosp@m..lad.nosp@m.urant.nosp@m.y@me.nosp@m.sotic.nosp@m..com

Definition in file periph_cpu_common.h.

#include "cpu.h"
+ Include dependency graph for periph_cpu_common.h:

Go to the source code of this file.

Data Structures

struct  uart_conf_t
 UART device configuration. More...
 
struct  spi_conf_t
 SPI configuration structure type. More...
 
struct  i2c_conf_t
 I2C configuration options. More...
 
struct  tc32_conf_t
 Timer device configuration. More...
 
struct  adc_conf_chan_t
 ADC Channel Configuration. More...
 
struct  sam0_common_usb_config_t
 USB peripheral parameters. More...
 

Macros

#define GPIO_UNDEF   (0xffffffff)
 Definition of a fitting UNDEF value.
 
#define SAM0_UART_TXBUF_SIZE   (64)
 Size of the UART TX buffer for non-blocking mode.
 
#define WDT_HAS_STOP   (1)
 Watchdog can be stopped.
 
#define WDT_HAS_INIT   (1)
 Watchdog has to be initialized.
 

Enumerations

enum  gpio_mux_t {
  GPIO_MUX_A = 0x0, GPIO_MUX_B = 0x1, GPIO_MUX_C = 0x2, GPIO_MUX_D = 0x3,
  GPIO_MUX_E = 0x4, GPIO_MUX_F = 0x5, GPIO_MUX_G = 0x6, GPIO_MUX_H = 0x7,
  GPIO_MUX_A = 0, GPIO_MUX_B = 1
}
 Available MUX values for configuring a pin's alternate function. More...
 
enum  uart_rxpad_t { UART_PAD_RX_0 = 0x0, UART_PAD_RX_1 = 0x1, UART_PAD_RX_2 = 0x2, UART_PAD_RX_3 = 0x3 }
 Available values for SERCOM UART RX pad selection. More...
 
enum  uart_txpad_t { UART_PAD_TX_0 = 0x0, UART_PAD_TX_2 = 0x1, UART_PAD_TX_0_RTS_2_CTS_3 = 0x2 }
 Available values for SERCOM UART TX pad selection. More...
 
enum  uart_flag_t { UART_FLAG_NONE = 0x0, UART_FLAG_RUN_STANDBY = 0x1, UART_FLAG_WAKEUP = 0x2 }
 Available SERCOM UART flag selections. More...
 
enum  spi_misopad_t { SPI_PAD_MISO_0 = 0x0, SPI_PAD_MISO_1 = 0x1, SPI_PAD_MISO_2 = 0x2, SPI_PAD_MISO_3 = 0x3 }
 Available values for SERCOM SPI MISO pad selection. More...
 
enum  spi_mosipad_t { SPI_PAD_MOSI_0_SCK_1 = 0x0, SPI_PAD_MOSI_2_SCK_3 = 0x1, SPI_PAD_MOSI_3_SCK_1 = 0x2, SPI_PAD_MOSI_0_SCK_3 = 0x3 }
 Available values for SERCOM SPI MOSI and SCK pad selection. More...
 
enum  i2c_flag_t { I2C_FLAG_NONE = 0x0, I2C_FLAG_RUN_STANDBY = 0x1 }
 Available SERCOM I2C flag selections. More...
 

Functions

void gpio_init_mux (gpio_t pin, gpio_mux_t mux)
 Set up alternate function (PMUX setting) for a PORT pin. More...
 
static uint8_t sercom_id (const void *sercom)
 Return the numeric id of a SERCOM device derived from its address. More...
 
static void sercom_clk_en (void *sercom)
 Enable peripheral clock for given SERCOM device. More...
 
static void sercom_clk_dis (void *sercom)
 Disable peripheral clock for given SERCOM device. More...
 
static void sercom_set_gen (void *sercom, uint32_t gclk)
 Configure generator clock for given SERCOM device. More...
 
static bool cpu_woke_from_backup (void)
 Returns true if the CPU woke deep sleep (backup/standby)
 
#define CPUID_LEN   (16U)
 Length of the CPU_ID in octets.
 
#define PERIPH_SPI_NEEDS_INIT_CS
 Use shared SPI functions.
 
#define PERIPH_SPI_NEEDS_TRANSFER_BYTE
 
#define PERIPH_SPI_NEEDS_TRANSFER_REG
 
#define PERIPH_SPI_NEEDS_TRANSFER_REGS
 
#define HAVE_GPIO_T
 Override GPIO type.
 
typedef uint32_t gpio_t
 
#define GPIO_PIN(x, y)   (((gpio_t)(&PORT->Group[x])) | y)
 Macro for accessing GPIO pins.
 
#define GPIO_MODE(pr, ie, pe)   (pr | (ie << 1) | (pe << 2))
 Generate GPIO mode bitfields. More...
 
enum  { PA = 0, PB = 1, PC = 2, PD = 3 }
 Available ports on the SAMD21 & SAML21. More...
 

Power mode configuration

#define PM_NUM_MODES   (3)
 

WDT upper and lower bound times in ms

#define NWDT_TIME_LOWER_LIMIT   (8U)
 
#define NWDT_TIME_UPPER_LIMIT   (16384U)
 

Macro Definition Documentation

◆ GPIO_MODE

#define GPIO_MODE (   pr,
  ie,
  pe 
)    (pr | (ie << 1) | (pe << 2))

Generate GPIO mode bitfields.

We use 3 bit to determine the pin functions:

  • bit 0: PD(0) or PU(1)
  • bit 1: input enable
  • bit 2: pull enable

Definition at line 96 of file periph_cpu_common.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Available ports on the SAMD21 & SAML21.

Enumerator
PA 

port A

PB 

port B

PC 

port C

PD 

port D

Definition at line 81 of file periph_cpu_common.h.

◆ gpio_mux_t

enum gpio_mux_t

Available MUX values for configuring a pin's alternate function.

Enumerator
GPIO_MUX_A 

select peripheral function A

GPIO_MUX_B 

select peripheral function B

GPIO_MUX_C 

select peripheral function C

GPIO_MUX_D 

select peripheral function D

GPIO_MUX_E 

select peripheral function E

GPIO_MUX_F 

select peripheral function F

GPIO_MUX_G 

select peripheral function G

GPIO_MUX_H 

select peripheral function H

GPIO_MUX_A 

alternate function A

GPIO_MUX_B 

alternate function B

Definition at line 140 of file periph_cpu_common.h.

◆ i2c_flag_t

enum i2c_flag_t

Available SERCOM I2C flag selections.

Enumerator
I2C_FLAG_NONE 

No flags set.

I2C_FLAG_RUN_STANDBY 

run SERCOM in standby mode

Definition at line 289 of file periph_cpu_common.h.

◆ spi_misopad_t

Available values for SERCOM SPI MISO pad selection.

Enumerator
SPI_PAD_MISO_0 

use pad 0 for MISO line

SPI_PAD_MISO_1 

use pad 0 for MISO line

SPI_PAD_MISO_2 

use pad 0 for MISO line

SPI_PAD_MISO_3 

use pad 0 for MISO line

Definition at line 224 of file periph_cpu_common.h.

◆ spi_mosipad_t

Available values for SERCOM SPI MOSI and SCK pad selection.

Enumerator
SPI_PAD_MOSI_0_SCK_1 

use pad 0 for MOSI, pad 1 for SCK

SPI_PAD_MOSI_2_SCK_3 

use pad 2 for MOSI, pad 3 for SCK

SPI_PAD_MOSI_3_SCK_1 

use pad 3 for MOSI, pad 1 for SCK

SPI_PAD_MOSI_0_SCK_3 

use pad 0 for MOSI, pad 3 for SCK

Definition at line 234 of file periph_cpu_common.h.

◆ uart_flag_t

Available SERCOM UART flag selections.

Enumerator
UART_FLAG_NONE 

No flags set.

UART_FLAG_RUN_STANDBY 

run SERCOM in standby mode

UART_FLAG_WAKEUP 

wake from sleep on receive

Definition at line 175 of file periph_cpu_common.h.

◆ uart_rxpad_t

Available values for SERCOM UART RX pad selection.

Enumerator
UART_PAD_RX_0 

use pad 0 for RX line

UART_PAD_RX_1 

select pad 1

UART_PAD_RX_2 

select pad 2

UART_PAD_RX_3 

select pad 3

Definition at line 155 of file periph_cpu_common.h.

◆ uart_txpad_t

Available values for SERCOM UART TX pad selection.

Enumerator
UART_PAD_TX_0 

select pad 0

UART_PAD_TX_2 

select pad 2

UART_PAD_TX_0_RTS_2_CTS_3 

TX is pad 0, on top RTS on pad 2 and CTS on pad 3.

Definition at line 165 of file periph_cpu_common.h.

Function Documentation

◆ gpio_init_mux()

void gpio_init_mux ( gpio_t  pin,
gpio_mux_t  mux 
)

Set up alternate function (PMUX setting) for a PORT pin.

Parameters
[in]pinPin to set the multiplexing for
[in]muxMux value

◆ sercom_clk_dis()

static void sercom_clk_dis ( void *  sercom)
inlinestatic

Disable peripheral clock for given SERCOM device.

Parameters
[in]sercomSERCOM device

Definition at line 441 of file periph_cpu_common.h.

◆ sercom_clk_en()

static void sercom_clk_en ( void *  sercom)
inlinestatic

Enable peripheral clock for given SERCOM device.

Parameters
[in]sercomSERCOM device

Definition at line 411 of file periph_cpu_common.h.

◆ sercom_id()

static uint8_t sercom_id ( const void *  sercom)
inlinestatic

Return the numeric id of a SERCOM device derived from its address.

Parameters
[in]sercomSERCOM device
Returns
numeric id of the given SERCOM device

Definition at line 357 of file periph_cpu_common.h.

◆ sercom_set_gen()

static void sercom_set_gen ( void *  sercom,
uint32_t  gclk 
)
inlinestatic

Configure generator clock for given SERCOM device.

Parameters
[in]sercomSERCOM device
[in]gclkGenerator clock

Definition at line 483 of file periph_cpu_common.h.