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 
47 #ifndef FLASH_UTILS_H
48 #define FLASH_UTILS_H
49 
50 #include <stdio.h>
51 #include <string.h>
52 
53 #include "cpu_conf.h"
54 #include "kernel_defines.h"
55 
56 #if IS_ACTIVE(HAS_FLASH_UTILS_ARCH)
57 #include "flash_utils_arch.h" /* IWYU pragma: export */
58 #endif
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 #if defined(DOXYGEN)
68 #define FLASH_ATTR <IMPLEMTATION_DEFINED>
80 #define PRIsflash <IMPLEMTATION_DEFINED>
81 
91 #define TO_FLASH(str_literal) <IMPLEMTATION_DEFINED>
92 
100 int flash_strcmp(const char *ram, FLASH_ATTR const char *flash);
101 
109 int flash_strncmp(const char *ram, FLASH_ATTR const char *flash, size_t n);
110 
118 size_t flash_strlen(FLASH_ATTR const char *flash);
119 
127 char * flash_strcpy(char *ram, FLASH_ATTR const char *flash);
128 
136 char * flash_strncpy(char *ram, FLASH_ATTR const char *flash, size_t n);
137 
145 int flash_printf(FLASH_ATTR const char *flash, ...);
146 
154 int flash_vprintf(FLASH_ATTR const char *flash, va_list args);
155 
163 int flash_fprintf(FILE *stream, FLASH_ATTR const char *flash, ...);
164 
172 int flash_vfprintf(FILE *stream, FLASH_ATTR const char *flash, va_list args);
173 
181 int flash_snprintf(char *buf, size_t buf_len, FLASH_ATTR const char *flash, ...);
182 
190 int flash_vsnprintf(char *buf, size_t buf_len, FLASH_ATTR const char *flash,
191  va_list args);
192 
200 void flash_puts(FLASH_ATTR const char *flash);
201 
210 void * flash_memcpy(void *dest, FLASH_ATTR const void *src, size_t n);
211 #elif !IS_ACTIVE(HAS_FLASH_UTILS_ARCH)
212 # define FLASH_ATTR
213 # define PRIsflash "s"
214 # define ASSERT_IS_STR_LITERAL_HELPER(x) x
215 # define ASSERT_IS_STR_LITERAL(x) ASSERT_IS_STR_LITERAL_HELPER("" x)
216 # define TO_FLASH(x) ASSERT_IS_STR_LITERAL(x)
217 # define flash_strcmp strcmp
218 # define flash_strncmp strncmp
219 # define flash_strlen strlen
220 # define flash_strcpy strcpy
221 # define flash_strncpy strncpy
222 # define flash_printf printf
223 # define flash_vprintf vprintf
224 # define flash_fprintf fprintf
225 # define flash_vfprintf vfprintf
226 # define flash_snprintf snprintf
227 # define flash_vsnprintf vsnprintf
228 # define flash_puts puts
229 # define flash_memcpy memcpy
230 #endif
231 
240 #define FLASH_PUTS(x) flash_puts(TO_FLASH(x))
241 
245 static inline void flash_print_str(FLASH_ATTR const char *flash)
246 {
247  printf("%" PRIsflash, flash);
248 }
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 
254 #endif /* FLASH_UTILS_H */
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:80
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_strncpy(char *ram, FLASH_ATTR const char *flash, size_t n)
Like strncpy(), but the source flash 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:68
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.
void * flash_memcpy(void *dest, FLASH_ATTR const void *src, size_t n)
Like memcpy(), but src 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.
Definition: flash_utils.h:245
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.
Common macros and compiler attributes/pragmas configuration.
stdio wrapper to extend the C libs stdio