ROM facilities are defined in the
include/picolibrary/rom.h
/source/picolibrary/rom.cc
header/source file pair.
The ::picolibrary::ROM::String
type is used for handles to null-terminated strings that
may be stored in ROM.
This type defaults to char const *
.
A HIL can replace this type with a HIL specific version by doing the following:
picolibrary-hil
library that provides picolibrary/hil/rom.h
PICOLIBRARY_ROM_STRING_IS_HIL_DEFINED
in picolibrary/hil/rom.h
::picolibrary::ROM::String
in
picolibrary/hil/rom.h
If a function is being overloaded to work with null-terminated strings stored in RAM and
null-terminated strings that may be stored in ROM, the ::picolibrary::ROM::String
overload must only be defined if PICOLIBRARY_ROM_STRING_IS_HIL_DEFINED
is defined since
::picolibrary::ROM::String
defaults to char const *
:
void foo( char const * string ) noexcept
{
}
#ifdef PICOLIBRARY_ROM_STRING_IS_HIL_DEFINED
void foo( ::picolibrary::ROM::String string ) noexcept;
{
}
#endif // PICOLIBRARY_ROM_STRING_IS_HIL_DEFINED
To create a string literal that can be stored in ROM, use the PICOLIBRARY_ROM_STRING()
macro:
auto foo() noexcept -> ::picolibrary::ROM::String
{
return PICOLIBRARY_ROM_STRING( "string" );
}
If a toolchain does not store string literals in ROM automatically, a HIL can replace the
PICOLIBRARY_ROM_STRING()
macro by doing the following:
picolibrary-hil
library that provides picolibrary/hil/rom.h
picolibrary/hil/rom.h
To get the length of a null-terminated string that may be stored in ROM, use the
::picolibrary::ROM::strlen()
function:
void foo( ::picolibrary::ROM::String string ) noexcept
{
auto const length = ::picolibrary::ROM::strlen( string );
}