CPU implementation for running RIOT on a Linux and BSD More...
CPU implementation for running RIOT on a Linux and BSD
The native CPU uses system calls to simulate hardware access.
Topics | |
Linux User Mode GPIO Driver | |
Implementation of GPIO access from Linux User Space | |
Linux User Mode SPI Driver | |
Implementation of SPI access from Linux User Space | |
Native FS Integration | |
Access to the host filesystem from RIOT native | |
Native extra API for EEPROM | |
Implementation of EEPROM buffer persistence in file. | |
Files | |
file | architecture_arch.h |
Architecture details. | |
file | async_read.h |
Multiple asynchronous read on file descriptors. | |
file | atomic_utils_arch.h |
Implementation of fast atomic utility functions. | |
file | cpu.h |
Native CPU header. | |
file | cpu_conf.h |
Native CPU configuration. | |
file | native_cli_eui_provider.h |
Command-line EUI provider for native. | |
file | native_internal.h |
Native CPU internal symbols. | |
file | periph_conf.h |
Native CPU peripheral configuration. | |
file | periph_cpu.h |
CPU specific definitions for internal peripheral handling. | |
file | thread_arch.h |
Implementation of the kernels thread interface. | |
file | tty_uart.h |
UART implementation based on /dev/tty devices on host. | |
Data Structures | |
struct | async_read_t |
Interrupt callback information structure. More... | |
Macros | |
#define | ASYNC_READ_NUMOF 8 |
Maximum number of file descriptors. | |
#define | CLOCK_CORECLOCK GHZ(1) |
System core clock in Hz. | |
#define | NATIVE_TIMER_MIN_RES 200 |
Hardware timer clock skew avoidance. | |
#define | RANDOM_NUMOF (1U) |
Random Number Generator configuration. | |
#define | UART_NUMOF (1U) |
UART configuration. | |
#define | PWM_NUMOF (8U) |
PWM configuration. | |
#define | QDEC_NUMOF (8U) |
QDEC configuration. | |
#define | CPUID_LEN (4U) |
Length of the CPU_ID in octets. | |
#define | PM_NUM_MODES (1U) |
Power mode configuration. | |
#define | PROVIDES_PM_LAYERED_OFF |
We provide our own pm_off() function for the native CPU. | |
#define | PERIPH_TIMER_PROVIDES_SET |
Prevent shared timer functions from being used. | |
#define | EEPROM_SIZE (1024U) /* 1kB */ |
EEPROM configuration. | |
Typedefs | |
typedef void(* | native_async_read_callback_t) (int fd, void *arg) |
asynchronous read callback type | |
Functions | |
void | native_breakpoint (void) |
raise SIGTRAP | |
void | native_async_read_setup (void) |
initialize asynchronous read system | |
void | native_async_read_cleanup (void) |
shutdown asynchronous read system | |
void | native_async_read_continue (int fd) |
resume monitoring of file descriptors | |
void | native_async_read_add_handler (int fd, void *arg, native_async_read_callback_t handler) |
start monitoring of file descriptor | |
void | native_async_read_remove_handler (int fd) |
stop monitoring of file descriptor | |
void | native_async_read_add_int_handler (int fd, void *arg, native_async_read_callback_t handler) |
start monitoring of file descriptor as interrupt | |
void | native_cli_add_eui64 (const char *s) |
parse a string as an EUI-64 and add it to the list of EUI-64s | |
int | native_cli_get_eui64 (uint8_t index, eui64_t *addr) |
Get a command-line provided EUI-64. | |
void | tty_uart_setup (uart_t uart, const char *name) |
register /dev/tty device to be used for UART | |
GPIO Configuration | |
enum | gpio_mode_t { GPIO_IN = GPIOHANDLE_REQUEST_INPUT , GPIO_IN_PD = GPIOHANDLE_REQUEST_INPUT | GPIOHANDLE_REQUEST_PULL_DOWN , GPIO_IN_PU = GPIOHANDLE_REQUEST_INPUT | GPIOHANDLE_REQUEST_PULL_UP , GPIO_OUT = GPIOHANDLE_REQUEST_OUTPUT , GPIO_OD = GPIOHANDLE_REQUEST_OPEN_DRAIN , GPIO_OD_PU = GPIOHANDLE_REQUEST_OPEN_DRAIN | GPIOHANDLE_REQUEST_PULL_UP } |
Available pin modes. More... | |
enum | gpio_flank_t { GPIO_FALLING = GPIOEVENT_EVENT_FALLING_EDGE , GPIO_RISING = GPIOEVENT_EVENT_RISING_EDGE , GPIO_BOTH = GPIO_FALLING | GPIO_RISING } |
An enum for the type of flank that emit interrupts. More... | |
#define | GPIO_PORT_SHIFT (24) |
The offset between Port and Pin. | |
#define | GPIO_PIN(port, pin) |
Define a custom GPIO_PIN macro for native. | |
#define | HAVE_GPIO_MODE_T |
Macro indicating whether GPIO modes are available on the native CPU. | |
#define | GPIOHANDLE_REQUEST_PULL_DOWN (0xFF) |
Pull-down. | |
#define | GPIOHANDLE_REQUEST_PULL_UP (0xFF) |
Pull-up. | |
#define | HAVE_GPIO_FLANK_T |
A macro indicating whether the native CPU supports GPIO edge behavior. | |
Internal native CPU API | |
typedef void(* | _native_callback_t) (void) |
Prototype for native's internal callbacks. | |
void | native_cpu_init (void) |
Initializes native CPU. | |
Native flash emulation | |
Use unusual parameters to trigger edge cases | |
char | _native_flash [FLASHPAGE_SIZE *FLASHPAGE_NUMOF] |
Emulated flash buffer. | |
#define | FLASHPAGE_SIZE (512) |
Size of a single emulated flash page. | |
#define | FLASHPAGE_NUMOF (32) |
Total number of emulated flash pages. | |
#define | FLASHPAGE_WRITE_BLOCK_ALIGNMENT (8) |
Flashpage alignment. | |
#define | FLASHPAGE_WRITE_BLOCK_SIZE (16) |
Flashpage block size. | |
#define | FLASHPAGE_ERASE_STATE (0x0) |
Value of bytes in erased flash. | |
#define | CPU_FLASH_BASE ((uintptr_t)_native_flash) |
Base buffer pointer to emulated flash. | |
Native Signal Handling | |
void | native_interrupt_init (void) |
Registers signal handlers for the native CPU. | |
int | native_register_interrupt (int sig, _native_callback_t handler) |
Register interrupt handler handler for interrupt signal. | |
int | native_unregister_interrupt (int sig) |
Unregister interrupt handler for interrupt signal. | |
void | _native_sig_leave_tramp (void) |
Switches to ISR context, then enables IRQ and returns to userspace. | |
System Calls | |
We wrap system calls and syscall-invoking library calls to ensure no context switches occur during a system call. | |
static void | _native_pending_syscalls_up (void) |
Increment spending system call counter. | |
static void | _native_pending_syscalls_down (void) |
Decrements pending system call counter. | |
void | _native_init_syscalls (void) |
Registers system calls. | |
Native Context Switching | |
volatile uintptr_t | _native_user_fptr |
Points to instruction in userspace where RIOT left off and switched to ISR context. | |
volatile int | _native_in_isr |
A boolean variable indicating whether program execution currently takes place in an ISR context. | |
char | _isr_stack [THREAD_STACKSIZE_DEFAULT] |
Stack used in ISR context. | |
ucontext_t * | _native_isr_context |
ISR context. | |
static void | _native_isr_context_make (void(*func)(void)) |
Makes ISR context so that execution continues at func when the context is applied. | |
static ucontext_t * | _native_user_context (void) |
Retrieves user context. | |
static uintptr_t | cpu_get_caller_pc (void) |
Gets the address the callee will return to. | |
#define | CPU_HAS_UNALIGNED_ACCESS |
The CPU supports unaligned memory access. | |
Native Read/Write Methods | |
ssize_t | _native_read (int fd, void *buf, size_t count) |
Reads file, populates given buffer. | |
ssize_t | _native_write (int fd, const void *buf, size_t count) |
Writes given data into file. | |
ssize_t | _native_writev (int fildes, const struct iovec *iov, int iovcnt) |
Performs a vectored write operation. | |
Context accessors | |
static uintptr_t | _context_get_fptr (ucontext_t *context) |
Retrieves function pointer generated during calls to makecontext /setcontext /swapcontext | |
static void | _context_set_fptr (ucontext_t *context, uintptr_t func) |
Retrieves function pointer generated during calls to makecontext /setcontext /swapcontext | |
64-bit support for makecontext | |
void | _start_task_func64 (void) |
Invokes thread task function. | |
static void | makecontext64 (ucontext_t *context, void(*func)(void), void *arg) |
Like makecontext , allows 64-bit wide function argument on 64-bit platforms. | |
#define | THREAD_STACKSIZE_DEFAULT (8192) |
CPU-specific default stack sizes. | |
#define | THREAD_STACKSIZE_IDLE (THREAD_STACKSIZE_DEFAULT) |
Default size of idle thread stack. | |
#define | THREAD_EXTRA_STACKSIZE_PRINTF (4096) |
Extra stack buffer capacity needed for printf | |
#define | THREAD_EXTRA_STACKSIZE_PRINTF_FLOAT (4096) |
Extra stack buffer capacity needed for printf in floating-point operations. | |
#define | THREAD_STACKSIZE_MINIMUM (THREAD_STACKSIZE_DEFAULT) |
Minimum thread size. | |
#define | ISR_STACKSIZE (THREAD_STACKSIZE_DEFAULT) |
Size of stack used in ISR context. | |
Networking constants | |
#define | NATIVE_ETH_PROTO 0x1234 |
Native internal Ethernet protocol number. | |
Timer peripheral configuration | |
#define | TIMER_NUMOF (1U) |
#define | TIMER_CHANNEL_NUMOF (1U) |
Number of timer channels. | |
<tt>xtimer</tt> configuration | |
timer_set_absolute has a high margin for possible underflow if set with value not far in the future. To prevent this, we set high backoff values here. | |
#define | XTIMER_BACKOFF 200 |
#define | XTIMER_ISR_BACKOFF 200 |
SPI configuration (Linux host only) | |
#define | SPI_NUMOF (1U) |
Amount of SPI devices. | |
#define | SPI_MAXCS (4U) |
Maximum amount of chip select lines per bus. | |
#define | SPI_HWCS(x) |
Hardware chip select access macro. | |
SPI Configuration | |
#define | PERIPH_SPI_NEEDS_TRANSFER_BYTE |
Use the common transfer_byte SPI function. | |
#define | PERIPH_SPI_NEEDS_TRANSFER_REG |
Use the common transfer_reg SPI function. | |
#define | PERIPH_SPI_NEEDS_TRANSFER_REGS |
Use the common transfer_regs SPI function. | |
#define ASYNC_READ_NUMOF 8 |
Maximum number of file descriptors.
Definition at line 33 of file async_read.h.
#define CLOCK_CORECLOCK GHZ(1) |
System core clock in Hz.
1GHz is an arbitrary value used for compatibility with other platforms.
Definition at line 34 of file periph_conf.h.
#define CPU_FLASH_BASE ((uintptr_t)_native_flash) |
Base buffer pointer to emulated flash.
Definition at line 150 of file cpu_conf.h.
#define CPU_HAS_UNALIGNED_ACCESS |
#define CPUID_LEN (4U) |
Length of the CPU_ID in octets.
Definition at line 32 of file periph_cpu.h.
#define EEPROM_SIZE (1024U) /* 1kB */ |
EEPROM configuration.
Definition at line 226 of file periph_cpu.h.
#define FLASHPAGE_ERASE_STATE (0x0) |
Value of bytes in erased flash.
The flash is set to this constant when you call flashpage_erase.
Definition at line 139 of file cpu_conf.h.
#define FLASHPAGE_NUMOF (32) |
Total number of emulated flash pages.
Definition at line 111 of file cpu_conf.h.
#define FLASHPAGE_SIZE (512) |
Size of a single emulated flash page.
Definition at line 104 of file cpu_conf.h.
#define FLASHPAGE_WRITE_BLOCK_ALIGNMENT (8) |
Flashpage alignment.
The address passed to flashpage_write must be a multiple of this constant.
Definition at line 120 of file cpu_conf.h.
#define FLASHPAGE_WRITE_BLOCK_SIZE (16) |
Flashpage block size.
When writing to flash, the data size must be a multiple of this constant.
Definition at line 130 of file cpu_conf.h.
#define GPIO_PIN | ( | port, | |
pin ) |
Define a custom GPIO_PIN macro for native.
Definition at line 64 of file periph_cpu.h.
#define GPIO_PORT_SHIFT (24) |
The offset between Port and Pin.
Definition at line 59 of file periph_cpu.h.
#define GPIOHANDLE_REQUEST_PULL_DOWN (0xFF) |
Pull-down.
Definition at line 74 of file periph_cpu.h.
#define GPIOHANDLE_REQUEST_PULL_UP (0xFF) |
Pull-up.
Definition at line 80 of file periph_cpu.h.
#define HAVE_GPIO_FLANK_T |
A macro indicating whether the native CPU supports GPIO edge behavior.
Definition at line 103 of file periph_cpu.h.
#define HAVE_GPIO_MODE_T |
Macro indicating whether GPIO modes are available on the native CPU.
Definition at line 69 of file periph_cpu.h.
#define ISR_STACKSIZE (THREAD_STACKSIZE_DEFAULT) |
Size of stack used in ISR context.
Definition at line 74 of file cpu_conf.h.
#define NATIVE_ETH_PROTO 0x1234 |
Native internal Ethernet protocol number.
Definition at line 86 of file cpu_conf.h.
#define NATIVE_TIMER_MIN_RES 200 |
Hardware timer clock skew avoidance.
Definition at line 40 of file periph_conf.h.
#define PERIPH_SPI_NEEDS_TRANSFER_BYTE |
Use the common transfer_byte
SPI function.
Definition at line 190 of file periph_cpu.h.
#define PERIPH_SPI_NEEDS_TRANSFER_REG |
Use the common transfer_reg
SPI function.
Definition at line 194 of file periph_cpu.h.
#define PERIPH_SPI_NEEDS_TRANSFER_REGS |
Use the common transfer_regs
SPI function.
Definition at line 198 of file periph_cpu.h.
#define PERIPH_TIMER_PROVIDES_SET |
Prevent shared timer functions from being used.
Definition at line 165 of file periph_cpu.h.
#define PM_NUM_MODES (1U) |
Power mode configuration.
Definition at line 39 of file periph_cpu.h.
#define PROVIDES_PM_LAYERED_OFF |
We provide our own pm_off() function for the native CPU.
Definition at line 45 of file periph_cpu.h.
#define PROVIDES_PM_OFF |
Definition at line 172 of file periph_cpu.h.
#define PROVIDES_PM_SET_LOWEST |
Definition at line 173 of file periph_cpu.h.
#define PWM_NUMOF (8U) |
PWM configuration.
Definition at line 80 of file periph_conf.h.
#define QDEC_NUMOF (8U) |
QDEC configuration.
Definition at line 87 of file periph_conf.h.
#define RANDOM_NUMOF (1U) |
Random Number Generator configuration.
Definition at line 45 of file periph_conf.h.
#define SPI_HWCS | ( | x | ) |
Hardware chip select access macro.
The amount of available hardware chip select lines depends on the SPI_MAXCS parameter. If the line is actually available at runtime depends of whether a --spi
startup parameter with the corresponding SPI device and HWCS-line parameter has been given.
Definition at line 126 of file periph_conf.h.
#define SPI_MAXCS (4U) |
Maximum amount of chip select lines per bus.
Allows up to SPI_MAXCS hardware cable select lines per SPI device. The n-th hardware select line can be used with the SPI_HWCS macro.
Definition at line 115 of file periph_conf.h.
#define SPI_NUMOF (1U) |
Amount of SPI devices.
Allows up to SPI_NUMOF SPI devices with each having up to SPI_MAXCS hardware cable select lines. Assignment to hardware devices can be configured at runtime using the --spi
startup parameter.
Can be overridden during compile time with a -DSPI_NUMOF=n
flag.
Definition at line 105 of file periph_conf.h.
#define THREAD_EXTRA_STACKSIZE_PRINTF (4096) |
Extra stack buffer capacity needed for printf
Definition at line 54 of file cpu_conf.h.
#define THREAD_EXTRA_STACKSIZE_PRINTF_FLOAT (4096) |
Extra stack buffer capacity needed for printf
in floating-point operations.
Definition at line 60 of file cpu_conf.h.
#define THREAD_STACKSIZE_DEFAULT (8192) |
CPU-specific default stack sizes.
Default size of a thread stack
Definition at line 41 of file cpu_conf.h.
#define THREAD_STACKSIZE_IDLE (THREAD_STACKSIZE_DEFAULT) |
Default size of idle thread stack.
Definition at line 48 of file cpu_conf.h.
#define THREAD_STACKSIZE_MINIMUM (THREAD_STACKSIZE_DEFAULT) |
Minimum thread size.
Definition at line 67 of file cpu_conf.h.
#define TIMER_CHANNEL_NUMOF (1U) |
Number of timer channels.
Definition at line 53 of file periph_conf.h.
#define TIMER_NUMOF (1U) |
Definition at line 52 of file periph_conf.h.
#define UART_NUMOF (1U) |
UART configuration.
Definition at line 73 of file periph_conf.h.
#define XTIMER_BACKOFF 200 |
Definition at line 65 of file periph_conf.h.
#define XTIMER_ISR_BACKOFF 200 |
Definition at line 66 of file periph_conf.h.
typedef void(* _native_callback_t) (void) |
Prototype for native's internal callbacks.
Definition at line 72 of file native_internal.h.
typedef void(* native_async_read_callback_t) (int fd, void *arg) |
asynchronous read callback type
Definition at line 39 of file async_read.h.
enum gpio_flank_t |
An enum for the type of flank that emit interrupts.
Enumerator | |
---|---|
GPIO_FALLING | emit interrupt on falling flank |
GPIO_RISING | emit interrupt on rising flank |
GPIO_BOTH | emit interrupt on both flanks |
Definition at line 108 of file periph_cpu.h.
enum gpio_mode_t |
Available pin modes.
Generally, a pin can be configured to be input or output. In output mode, a pin can further be put into push-pull or open drain configuration. Though this is supported by most platforms, this is not always the case, so driver implementations may return an error code if a mode is not supported.
Definition at line 91 of file periph_cpu.h.
|
inlinestatic |
Retrieves function pointer generated during calls to makecontext
/setcontext
/swapcontext
context | ucontext_t |
Definition at line 42 of file ucontext.h.
|
inlinestatic |
Retrieves function pointer generated during calls to makecontext
/setcontext
/swapcontext
context | ucontext_t |
func | Function pointer |
Definition at line 65 of file ucontext.h.
void _native_init_syscalls | ( | void | ) |
Registers system calls.
Wraps syscall functions from the standard library.
|
inlinestatic |
Makes ISR context so that execution continues at func
when the context is applied.
func | Function executed when _native_isr_context is applied |
Definition at line 245 of file native_internal.h.
|
inlinestatic |
Decrements pending system call counter.
Definition at line 173 of file native_internal.h.
|
inlinestatic |
Increment spending system call counter.
Definition at line 166 of file native_internal.h.
|
extern |
Switches to ISR context, then enables IRQ and returns to userspace.
|
inlinestatic |
|
extern |
Invokes thread task function.
This function fixes the otherwise necessary cast from void*
to int
of the thread task function pointer. We pass the task func and its argument in registers. See makecontext64.
|
inlinestatic |
|
inlinestatic |
Like makecontext
, allows 64-bit wide function argument on 64-bit platforms.
context | ucontext_t |
func | Function to be executed when context is applied |
arg | Function argument, previously limited to int width, can now be up to 64 bits wide on 64-bit platforms |
Internally, we circumvent the 32-bit int
limitation by passing the parameter in a register. This is done using a custom function defined in native.S
Definition at line 110 of file ucontext.h.
void native_async_read_add_handler | ( | int | fd, |
void * | arg, | ||
native_async_read_callback_t | handler ) |
start monitoring of file descriptor
[in] | fd | The file descriptor to monitor |
[in] | arg | Pointer to be passed as arguments to the callback |
[in] | handler | The callback function to be called when the file descriptor is ready to read. |
void native_async_read_add_int_handler | ( | int | fd, |
void * | arg, | ||
native_async_read_callback_t | handler ) |
start monitoring of file descriptor as interrupt
[in] | fd | The file descriptor to monitor |
[in] | arg | Pointer to be passed as arguments to the callback |
[in] | handler | The callback function to be called when the file descriptor is ready to read. |
void native_async_read_cleanup | ( | void | ) |
shutdown asynchronous read system
This deregisters SIGIO signal handler.
void native_async_read_continue | ( | int | fd | ) |
resume monitoring of file descriptors
Call this function after reading file descriptors.
[in] | fd | The file descriptor to monitor |
void native_async_read_remove_handler | ( | int | fd | ) |
stop monitoring of file descriptor
[in] | fd | The file descriptor to stop monitoring |
void native_async_read_setup | ( | void | ) |
initialize asynchronous read system
This registers SIGIO signal handler.
void native_breakpoint | ( | void | ) |
raise SIGTRAP
We must not include signal.h directly into RIOT application namespace.
void native_cli_add_eui64 | ( | const char * | s | ) |
parse a string as an EUI-64 and add it to the list of EUI-64s
[in] | s | EUI-64 as hexadecimal string representation |
int native_cli_get_eui64 | ( | uint8_t | index, |
eui64_t * | addr ) |
Get a command-line provided EUI-64.
index | index of ZEP device | |
[out] | addr | user supplied EUI-64 |
int native_register_interrupt | ( | int | sig, |
_native_callback_t | handler ) |
Register interrupt handler handler for interrupt signal.
sig | Signal number |
handler | Signal action function |
int native_unregister_interrupt | ( | int | sig | ) |
Unregister interrupt handler for interrupt signal.
sig | Signal number |
void tty_uart_setup | ( | uart_t | uart, |
const char * | name ) |
register /dev/tty device to be used for UART
[in] | uart | UART id |
[in] | name | path name for /dev/tty device |