Loading...
Searching...
No Matches
flash_utils.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 Otto-von-Guericke-Universität Magdeburg
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser General
5 * Public License v2.1. See the file LICENSE in the top level directory for more
6 * details.
7 */
8
9#pragma once
10
48
49#include <stdio.h>
50#include <string.h>
51
52#include "cpu_conf.h"
53#include "kernel_defines.h"
54
55#if IS_ACTIVE(HAS_FLASH_UTILS_ARCH)
56#include "flash_utils_arch.h" /* IWYU pragma: export */
57#endif
58
59#ifdef __cplusplus
60extern "C" {
61#endif
62
63#if defined(DOXYGEN)
67#define FLASH_ATTR <IMPLEMTATION_DEFINED>
79#define PRIsflash <IMPLEMTATION_DEFINED>
80
90#define TO_FLASH(str_literal) <IMPLEMTATION_DEFINED>
91
99int flash_strcmp(const char *ram, FLASH_ATTR const char *flash);
100
108int flash_strncmp(const char *ram, FLASH_ATTR const char *flash, size_t n);
109
117size_t flash_strlen(FLASH_ATTR const char *flash);
118
126char * flash_strcpy(char *ram, FLASH_ATTR const char *flash);
127
135char * flash_strncpy(char *ram, FLASH_ATTR const char *flash, size_t n);
136
144int flash_printf(FLASH_ATTR const char *flash, ...);
145
153int flash_vprintf(FLASH_ATTR const char *flash, va_list args);
154
162int flash_fprintf(FILE *stream, FLASH_ATTR const char *flash, ...);
163
171int flash_vfprintf(FILE *stream, FLASH_ATTR const char *flash, va_list args);
172
180int flash_snprintf(char *buf, size_t buf_len, FLASH_ATTR const char *flash, ...);
181
189int flash_vsnprintf(char *buf, size_t buf_len, FLASH_ATTR const char *flash,
190 va_list args);
191
199void flash_puts(FLASH_ATTR const char *flash);
200
209void * flash_memcpy(void *dest, FLASH_ATTR const void *src, size_t n);
210#elif !IS_ACTIVE(HAS_FLASH_UTILS_ARCH)
211# define FLASH_ATTR
212# define PRIsflash "s"
213# define ASSERT_IS_STR_LITERAL_HELPER(x) x
214# define ASSERT_IS_STR_LITERAL(x) ASSERT_IS_STR_LITERAL_HELPER("" x)
215# define TO_FLASH(x) ASSERT_IS_STR_LITERAL(x)
216# define flash_strcmp strcmp
217# define flash_strncmp strncmp
218# define flash_strlen strlen
219# define flash_strcpy strcpy
220# define flash_strncpy strncpy
221# define flash_printf printf
222# define flash_vprintf vprintf
223# define flash_fprintf fprintf
224# define flash_vfprintf vfprintf
225# define flash_snprintf snprintf
226# define flash_vsnprintf vsnprintf
227# define flash_puts puts
228# define flash_memcpy memcpy
229#endif
230
239#define FLASH_PUTS(x) flash_puts(TO_FLASH(x))
240
244static inline void flash_print_str(FLASH_ATTR const char *flash)
245{
246 printf("%" PRIsflash, flash);
247}
248
249#ifdef __cplusplus
250}
251#endif
252
Implementation of flash_utils.
#define printf(...)
A wrapper for the printf() function that passes arguments through unmodified, but fails to compile if...
Definition stdio.h:60
#define PRIsflash
Format specifier for printing FLASH CONST char *
Definition flash_utils.h:79
int flash_snprintf(char *buf, size_t buf_len, FLASH_ATTR const char *flash,...)
Like snprintf(), but the format string resides in flash.
int flash_vfprintf(FILE *stream, FLASH_ATTR const char *flash, va_list args)
Like vfprintf(), but the format string resides in flash.
char * flash_strcpy(char *ram, FLASH_ATTR const char *flash)
Like strcpy(), but the source flash resides in flash.
int flash_strncmp(const char *ram, FLASH_ATTR const char *flash, size_t n)
Like strncmp(), but the first string resides in flash.
#define FLASH_ATTR
C type qualifier required to place a variable in flash.
Definition flash_utils.h:67
int flash_strcmp(const char *ram, FLASH_ATTR const char *flash)
Like strcmp(), but the second string resides in flash.
int flash_vprintf(FLASH_ATTR const char *flash, va_list args)
Like vprintf(), but the format string resides in flash.
int flash_fprintf(FILE *stream, FLASH_ATTR const char *flash,...)
Like fprintf(), but the format string resides in flash.
int flash_printf(FLASH_ATTR const char *flash,...)
Like printf(), but the format string resides in flash.
static void flash_print_str(FLASH_ATTR const char *flash)
Like flash_puts but without line break.
char * flash_strncpy(char *ram, FLASH_ATTR const char *flash, size_t n)
Like strncpy(), but the source flash resides in flash.
int flash_vsnprintf(char *buf, size_t buf_len, FLASH_ATTR const char *flash, va_list args)
Like vsnprintf(), but the format string resides in flash.
size_t flash_strlen(FLASH_ATTR const char *flash)
Like strlen(), but the string resides in flash.
void flash_puts(FLASH_ATTR const char *flash)
Like puts(), but the string resides in flash.
void * flash_memcpy(void *dest, FLASH_ATTR const void *src, size_t n)
Like memcpy(), but src resides in flash.
Common macros and compiler attributes/pragmas configuration.