text
stringlengths
9
39.2M
dir
stringlengths
25
226
lang
stringclasses
163 values
created_date
timestamp[s]
updated_date
timestamp[s]
repo_name
stringclasses
751 values
repo_full_name
stringclasses
752 values
star
int64
1.01k
183k
len_tokens
int64
1
18.5M
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_ZEPHYR_ZVFS_EVENTFD_H_ #define ZEPHYR_INCLUDE_ZEPHYR_ZVFS_EVENTFD_H_ #include <stdint.h> #include <zephyr/kernel.h> #ifdef __cplusplus extern "C" { #endif #define ZVFS_EFD_SEMAPHORE 2 #define ZVFS_EFD_NONBLOCK 0x4000 typedef uint64_t zvfs_eventfd_t; /** * @brief Create a file descriptor for ZVFS event notification * * The returned file descriptor can be used with POSIX read/write calls or * with the @ref zvfs_eventfd_read or @ref zvfs_eventfd_write functions. * * It also supports polling and by including an eventfd in a call to poll, * it is possible to signal and wake the polling thread by simply writing to * the eventfd. * * When using read() and write() on a ZVFS eventfd, the size must always be at * least 8 bytes or the operation will fail with EINVAL. * * @return New ZVFS eventfd file descriptor on success, -1 on error */ int zvfs_eventfd(unsigned int initval, int flags); /** * @brief Read from a ZVFS eventfd * * If call is successful, the value parameter will have the value 1 * * @param fd File descriptor * @param value Pointer for storing the read value * * @return 0 on success, -1 on error */ int zvfs_eventfd_read(int fd, zvfs_eventfd_t *value); /** * @brief Write to a ZVFS eventfd * * @param fd File descriptor * @param value Value to write * * @return 0 on success, -1 on error */ int zvfs_eventfd_write(int fd, zvfs_eventfd_t value); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_ZEPHYR_ZVFS_EVENTFD_H_ */ ```
/content/code_sandbox/include/zephyr/zvfs/eventfd.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
427
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_FS_FCB_H_ #define ZEPHYR_INCLUDE_FS_FCB_H_ /* * Flash circular buffer. */ #include <inttypes.h> #include <limits.h> #include <zephyr/storage/flash_map.h> #include <zephyr/sys/util_macro.h> #include <zephyr/kernel.h> #ifdef __cplusplus extern "C" { #endif /** * @defgroup fcb Flash Circular Buffer (FCB) * @since 1.11 * @version 1.0.0 * @ingroup file_system_storage * @{ * @} */ /** * @defgroup fcb_data_structures Flash Circular Buffer Data Structures * @ingroup fcb * @{ */ #define FCB_MAX_LEN (0x3fffu) /**< Max length of element (16,383) */ /** * @brief FCB entry info structure. This data structure describes the element * location in the flash. * * You would use it to figure out what parameters to pass to flash_area_read() * to read element contents. Or to flash_area_write() when adding a new element. * Entry location is pointer to area (within fcb->f_sectors), and offset * within that area. */ struct fcb_entry { struct flash_sector *fe_sector; /**< Pointer to info about sector where data are placed */ uint32_t fe_elem_off; /**< Offset from the start of the sector to beginning of element. */ uint32_t fe_data_off; /**< Offset from the start of the sector to the start of element. */ uint16_t fe_data_len; /**< Size of data area in fcb entry*/ }; /** * @brief Helper macro for calculating the data offset related to * the fcb flash_area start offset. * * @param entry fcb entry structure */ #define FCB_ENTRY_FA_DATA_OFF(entry) (entry.fe_sector->fs_off +\ entry.fe_data_off) /** * @brief Structure for transferring complete information about FCB entry * location within flash memory. */ struct fcb_entry_ctx { struct fcb_entry loc; /**< FCB entry info */ const struct flash_area *fap; /**< Flash area where the entry is placed */ }; /** * @brief Flag to disable CRC for the fcb_entries in flash. */ #define FCB_FLAGS_CRC_DISABLED BIT(0) /** * @brief FCB instance structure * * The following data structure describes the FCB itself. First part should * be filled in by the user before calling @ref fcb_init. The second part is * used by FCB for its internal bookkeeping. */ struct fcb { /* Caller of fcb_init fills this in */ uint32_t f_magic; /**< Magic value, should not be 0xFFFFFFFF. * It is xored with inversion of f_erase_value and placed in * the beginning of FCB flash sector. FCB uses this when determining * whether sector contains valid data or not. * Giving it value of 0xFFFFFFFF means leaving bytes of the filed * in "erased" state. */ uint8_t f_version; /**< Current version number of the data */ uint8_t f_sector_cnt; /**< Number of elements in sector array */ uint8_t f_scratch_cnt; /**< Number of sectors to keep empty. This can be used if you need * to have scratch space for garbage collecting when FCB fills up. */ struct flash_sector *f_sectors; /**< Array of sectors, must be contiguous */ /* Flash circular buffer internal state */ struct k_mutex f_mtx; /**< Locking for accessing the FCB data, internal state */ struct flash_sector *f_oldest; /**< Pointer to flash sector containing the oldest data, * internal state */ struct fcb_entry f_active; /**< internal state */ uint16_t f_active_id; /**< Flash location where the newest data is, internal state */ uint8_t f_align; /**< writes to flash have to aligned to this, internal state */ const struct flash_area *fap; /**< Flash area used by the fcb instance, internal state. * This can be transfer to FCB user */ uint8_t f_erase_value; /**< The value flash takes when it is erased. This is read from * flash parameters and initialized upon call to fcb_init. */ #ifdef CONFIG_FCB_ALLOW_FIXED_ENDMARKER const uint8_t f_flags; /**< Flags for configuring the FCB. */ #endif }; /** * @} */ /** * @brief Flash Circular Buffer APIs * @defgroup fcb_api fcb API * @ingroup fcb * @{ */ /** * Initialize FCB instance. * * @param[in] f_area_id ID of flash area where fcb storage resides. * @param[in,out] fcbp FCB instance structure. * * @return 0 on success, non-zero on failure. */ int fcb_init(int f_area_id, struct fcb *fcbp); /** * Appends an entry to circular buffer. * * When writing the * contents for the entry, use loc->fe_sector and loc->fe_data_off with * flash_area_write() to fcb flash_area. * When you're finished, call fcb_append_finish() with loc as argument. * * @param[in] fcbp FCB instance structure. * @param[in] len Length of data which are expected to be written as the entry * payload. * @param[out] loc entry location information * * @return 0 on success, non-zero on failure. */ int fcb_append(struct fcb *fcbp, uint16_t len, struct fcb_entry *loc); /** * Finishes entry append operation. * * @param[in] fcbp FCB instance structure. * @param[in] append_loc entry location information * * @return 0 on success, non-zero on failure. */ int fcb_append_finish(struct fcb *fcbp, struct fcb_entry *append_loc); /** * FCB Walk callback function type. * * Type of function which is expected to be called while walking over fcb * entries thanks to a @ref fcb_walk call. * * Entry data can be read using flash_area_read(), using * loc_ctx fields as arguments. * If cb wants to stop the walk, it should return non-zero value. * * @param[in] loc_ctx entry location information (full context) * @param[in,out] arg callback context, transferred from @ref fcb_walk. * * @return 0 continue walking, non-zero stop walking. */ typedef int (*fcb_walk_cb)(struct fcb_entry_ctx *loc_ctx, void *arg); /** * Walk over all entries in the FCB sector * * @param[in] sector fcb sector to be walked. If null, traverse entire * storage. * @param[in] fcbp FCB instance structure. * @param[in] cb pointer to the function which gets called for every * entry. If cb wants to stop the walk, it should return * non-zero value. * @param[in,out] cb_arg callback context, transferred to the callback * implementation. * * @return 0 on success, negative on failure (or transferred form callback * return-value), positive transferred form callback return-value */ int fcb_walk(struct fcb *fcbp, struct flash_sector *sector, fcb_walk_cb cb, void *cb_arg); /** * Get next fcb entry location. * * Function to obtain fcb entry location in relation to entry pointed by * <p> loc. * If loc->fe_sector is set and loc->fe_elem_off is not 0 function fetches next * fcb entry location. * If loc->fe_sector is NULL function fetches the oldest entry location within * FCB storage. loc->fe_sector is set and loc->fe_elem_off is 0 function fetches * the first entry location in the fcb sector. * * @param[in] fcbp FCB instance structure. * @param[in,out] loc entry location information * * @return 0 on success, non-zero on failure. */ int fcb_getnext(struct fcb *fcbp, struct fcb_entry *loc); /** * Rotate fcb sectors * * Function erases the data from oldest sector. Upon that the next sector * becomes the oldest. Active sector is also switched if needed. * * @param[in] fcbp FCB instance structure. */ int fcb_rotate(struct fcb *fcbp); /** * Start using the scratch block. * * Take one of the scratch blocks into use. So a scratch sector becomes * active sector to which entries can be appended. * * @param[in] fcbp FCB instance structure. * * @return 0 on success, non-zero on failure. */ int fcb_append_to_scratch(struct fcb *fcbp); /** * Get free sector count. * * @param[in] fcbp FCB instance structure. * * @return Number of free sectors. */ int fcb_free_sector_cnt(struct fcb *fcbp); /** * Check whether FCB has any data. * * @param[in] fcbp FCB instance structure. * * @return Positive value if fcb is empty, otherwise 0. */ int fcb_is_empty(struct fcb *fcbp); /** * Finds the fcb entry that gives back up to n entries at the end. * * @param[in] fcbp FCB instance structure. * @param[in] entries number of fcb entries the user wants to get * @param[out] last_n_entry last_n_entry the fcb_entry to be returned * * @return 0 on there are any fcbs available; -ENOENT otherwise */ int fcb_offset_last_n(struct fcb *fcbp, uint8_t entries, struct fcb_entry *last_n_entry); /** * Clear fcb instance storage. * * @param[in] fcbp FCB instance structure. * * @return 0 on success; non-zero on failure */ int fcb_clear(struct fcb *fcbp); /** * @} */ /** * @brief Flash Circular internal * @defgroup fcb_internal fcb non-API prototypes * @ingroup fcb * @{ */ /** * Read raw data from the fcb flash sector. * * @param[in] fcbp FCB instance structure. * @param[in] sector FCB sector. * @param[in] off Read offset form sector begin. * @param[out] dst Destination buffer. * @param[in] len Read-out size. * * @return 0 on success, negative errno code on fail. */ int fcb_flash_read(const struct fcb *fcbp, const struct flash_sector *sector, off_t off, void *dst, size_t len); /** * Write raw data to the fcb flash sector. * * @param[in] fcbp FCB instance structure. * @param[in] sector FCB sector. * @param[in] off Write offset form sector begin. * @param[in] src Source buffer. * @param[in] len Write size. * * @return 0 on success, negative errno code on fail. */ int fcb_flash_write(const struct fcb *fcbp, const struct flash_sector *sector, off_t off, const void *src, size_t len); /** * @} */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_FS_FCB_H_ */ ```
/content/code_sandbox/include/zephyr/fs/fcb.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
2,471
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_FS_LITTLEFS_H_ #define ZEPHYR_INCLUDE_FS_LITTLEFS_H_ #include <zephyr/types.h> #include <zephyr/kernel.h> #include <zephyr/storage/flash_map.h> #include <lfs.h> #ifdef __cplusplus extern "C" { #endif /** @brief Filesystem info structure for LittleFS mount */ struct fs_littlefs { /* Defaulted in driver, customizable before mount. */ struct lfs_config cfg; /* Must be cfg.cache_size */ uint8_t *read_buffer; /* Must be cfg.cache_size */ uint8_t *prog_buffer; /* Must be cfg.lookahead_size/4 elements, and * cfg.lookahead_size must be a multiple of 8. */ uint32_t *lookahead_buffer[CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE / sizeof(uint32_t)]; /* These structures are filled automatically at mount. */ struct lfs lfs; void *backend; struct k_mutex mutex; }; /** @brief Define a littlefs configuration with customized size * characteristics. * * This defines static arrays required for caches, and initializes the * littlefs configuration structure to use the provided values instead * of the global Kconfig defaults. A pointer to the named object must * be stored in the @ref fs_mount_t.fs_data field of a @ref fs_mount_t object. * * To define an instance for the Kconfig defaults, use * @ref FS_LITTLEFS_DECLARE_DEFAULT_CONFIG. * * To completely control file system configuration the application can * directly define and initialize a @ref fs_littlefs * object. The application is responsible for ensuring the configured * values are consistent with littlefs requirements. * * @note If you use a non-default configuration for cache size, you * must also select @kconfig{CONFIG_FS_LITTLEFS_FC_HEAP_SIZE} to relax * the size constraints on per-file cache allocations. * * @param name the name for the structure. The defined object has * file scope. * @param alignment needed alignment for read/prog buffer for specific device * @param read_sz see @kconfig{CONFIG_FS_LITTLEFS_READ_SIZE} * @param prog_sz see @kconfig{CONFIG_FS_LITTLEFS_PROG_SIZE} * @param cache_sz see @kconfig{CONFIG_FS_LITTLEFS_CACHE_SIZE} * @param lookahead_sz see @kconfig{CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE} */ #define FS_LITTLEFS_DECLARE_CUSTOM_CONFIG(name, alignment, read_sz, prog_sz, cache_sz, \ lookahead_sz) \ static uint8_t __aligned(alignment) name ## _read_buffer[cache_sz]; \ static uint8_t __aligned(alignment) name ## _prog_buffer[cache_sz]; \ static uint32_t name ## _lookahead_buffer[(lookahead_sz) / sizeof(uint32_t)]; \ static struct fs_littlefs name = { \ .cfg = { \ .read_size = (read_sz), \ .prog_size = (prog_sz), \ .cache_size = (cache_sz), \ .lookahead_size = (lookahead_sz), \ .read_buffer = name ## _read_buffer, \ .prog_buffer = name ## _prog_buffer, \ .lookahead_buffer = name ## _lookahead_buffer, \ }, \ } /** @brief Define a littlefs configuration with default characteristics. * * This defines static arrays and initializes the littlefs * configuration structure to use the default size configuration * provided by Kconfig. * * @param name the name for the structure. The defined object has * file scope. */ #define FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(name) \ FS_LITTLEFS_DECLARE_CUSTOM_CONFIG(name, \ 4, \ CONFIG_FS_LITTLEFS_READ_SIZE, \ CONFIG_FS_LITTLEFS_PROG_SIZE, \ CONFIG_FS_LITTLEFS_CACHE_SIZE, \ CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE) #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_FS_LITTLEFS_H_ */ ```
/content/code_sandbox/include/zephyr/fs/littlefs.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
892
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_FS_FS_H_ #define ZEPHYR_INCLUDE_FS_FS_H_ #include <sys/types.h> #include <zephyr/sys/dlist.h> #include <zephyr/fs/fs_interface.h> #ifdef __cplusplus extern "C" { #endif /** * @brief File System APIs * @defgroup file_system_api File System APIs * @since 1.5 * @version 1.0.0 * @ingroup os_services * @{ */ struct fs_file_system_t; /** * @brief Enumeration for directory entry types */ enum fs_dir_entry_type { /** Identifier for file entry */ FS_DIR_ENTRY_FILE = 0, /** Identifier for directory entry */ FS_DIR_ENTRY_DIR }; /** @brief Enumeration to uniquely identify file system types. * * Zephyr supports in-tree file systems and external ones. Each * requires a unique identifier used to register the file system * implementation and to associate a mount point with the file system * type. This anonymous enum defines global identifiers for the * in-tree file systems. * * External file systems should be registered using unique identifiers * starting at @c FS_TYPE_EXTERNAL_BASE. It is the responsibility of * applications that use external file systems to ensure that these * identifiers are unique if multiple file system implementations are * used by the application. */ enum { /** Identifier for in-tree FatFS file system. */ FS_FATFS = 0, /** Identifier for in-tree LittleFS file system. */ FS_LITTLEFS, /** Identifier for in-tree Ext2 file system. */ FS_EXT2, /** Base identifier for external file systems. */ FS_TYPE_EXTERNAL_BASE, }; /** Flag prevents formatting device if requested file system not found */ #define FS_MOUNT_FLAG_NO_FORMAT BIT(0) /** Flag makes mounted file system read-only */ #define FS_MOUNT_FLAG_READ_ONLY BIT(1) /** Flag used in pre-defined mount structures that are to be mounted * on startup. * * This flag has no impact in user-defined mount structures. */ #define FS_MOUNT_FLAG_AUTOMOUNT BIT(2) /** Flag requests file system driver to use Disk Access API. When the flag is * set to the fs_mount_t.flags prior to fs_mount call, a file system * needs to use the Disk Access API, otherwise mount callback for the driver * should return -ENOSUP; when the flag is not set the file system driver * should use Flash API by default, unless it only supports Disc Access API. * When file system will use Disk Access API and the flag is not set, the mount * callback for the file system should set the flag on success. */ #define FS_MOUNT_FLAG_USE_DISK_ACCESS BIT(3) /** * @brief File system mount info structure */ struct fs_mount_t { /** Entry for the fs_mount_list list */ sys_dnode_t node; /** File system type */ int type; /** Mount point directory name (ex: "/fatfs") */ const char *mnt_point; /** Pointer to file system specific data */ void *fs_data; /** Pointer to backend storage device */ void *storage_dev; /* The following fields are filled by file system core */ /** Length of Mount point string */ size_t mountp_len; /** Pointer to File system interface of the mount point */ const struct fs_file_system_t *fs; /** Mount flags */ uint8_t flags; }; /** * @brief Structure to receive file or directory information * * Used in functions that read the directory entries to get * file or directory information. */ struct fs_dirent { /** * File/directory type (FS_DIR_ENTRY_FILE or FS_DIR_ENTRY_DIR) */ enum fs_dir_entry_type type; /** Name of file or directory */ char name[MAX_FILE_NAME + 1]; /** Size of file (0 if directory). */ size_t size; }; /** * @brief Structure to receive volume statistics * * Used to retrieve information about total and available space * in the volume. */ struct fs_statvfs { /** Optimal transfer block size */ unsigned long f_bsize; /** Allocation unit size */ unsigned long f_frsize; /** Size of FS in f_frsize units */ unsigned long f_blocks; /** Number of free blocks */ unsigned long f_bfree; }; /** * @name fs_open open and creation mode flags * @{ */ /** Open for read flag */ #define FS_O_READ 0x01 /** Open for write flag */ #define FS_O_WRITE 0x02 /** Open for read-write flag combination */ #define FS_O_RDWR (FS_O_READ | FS_O_WRITE) /** Bitmask for read and write flags */ #define FS_O_MODE_MASK 0x03 /** Create file if it does not exist */ #define FS_O_CREATE 0x10 /** Open/create file for append */ #define FS_O_APPEND 0x20 /** Truncate the file while opening */ #define FS_O_TRUNC 0x40 /** Bitmask for open/create flags */ #define FS_O_FLAGS_MASK 0x70 /** Bitmask for open flags */ #define FS_O_MASK (FS_O_MODE_MASK | FS_O_FLAGS_MASK) /** * @} */ /** * @name fs_seek whence parameter values * @{ */ #ifndef FS_SEEK_SET /** Seek from the beginning of file */ #define FS_SEEK_SET 0 #endif #ifndef FS_SEEK_CUR /** Seek from a current position */ #define FS_SEEK_CUR 1 #endif #ifndef FS_SEEK_END /** Seek from the end of file */ #define FS_SEEK_END 2 #endif /** * @} */ /** * @brief Get the common mount flags for an fstab entry. * @param node_id the node identifier for a child entry in a * zephyr,fstab node. * @return a value suitable for initializing an fs_mount_t flags * member. */ #define FSTAB_ENTRY_DT_MOUNT_FLAGS(node_id) \ ((DT_PROP(node_id, automount) ? FS_MOUNT_FLAG_AUTOMOUNT : 0) \ | (DT_PROP(node_id, read_only) ? FS_MOUNT_FLAG_READ_ONLY : 0) \ | (DT_PROP(node_id, no_format) ? FS_MOUNT_FLAG_NO_FORMAT : 0) \ | (DT_PROP(node_id, disk_access) ? FS_MOUNT_FLAG_USE_DISK_ACCESS : 0)) /** * @brief The name under which a zephyr,fstab entry mount structure is * defined. * * @param node_id the node identifier for a child entry in a zephyr,fstab node. */ #define FS_FSTAB_ENTRY(node_id) _CONCAT(z_fsmp_, node_id) /** * @brief Generate a declaration for the externally defined fstab * entry. * * This will evaluate to the name of a struct fs_mount_t object. * * @param node_id the node identifier for a child entry in a zephyr,fstab node. */ #define FS_FSTAB_DECLARE_ENTRY(node_id) \ extern struct fs_mount_t FS_FSTAB_ENTRY(node_id) /** * @brief Initialize fs_file_t object * * Initializes the fs_file_t object; the function needs to be invoked * on object before first use with fs_open. * * @param zfp Pointer to file object * */ static inline void fs_file_t_init(struct fs_file_t *zfp) { zfp->filep = NULL; zfp->mp = NULL; zfp->flags = 0; } /** * @brief Initialize fs_dir_t object * * Initializes the fs_dir_t object; the function needs to be invoked * on object before first use with fs_opendir. * * @param zdp Pointer to file object * */ static inline void fs_dir_t_init(struct fs_dir_t *zdp) { zdp->dirp = NULL; zdp->mp = NULL; } /** * @brief Open or create file * * Opens or possibly creates a file and associates a stream with it. * Successfully opened file, when no longer in use, should be closed * with fs_close(). * * @details * @p flags can be 0 or a binary combination of one or more of the following * identifiers: * - @c FS_O_READ open for read * - @c FS_O_WRITE open for write * - @c FS_O_RDWR open for read/write (<tt>FS_O_READ | FS_O_WRITE</tt>) * - @c FS_O_CREATE create file if it does not exist * - @c FS_O_APPEND move to end of file before each write * - @c FS_O_TRUNC truncate the file * * @warning If @p flags are set to 0 the function will open file, if it exists * and is accessible, but you will have no read/write access to it. * * @param zfp Pointer to a file object * @param file_name The name of a file to open * @param flags The mode flags * * @retval 0 on success; * @retval -EBUSY when zfp is already used; * @retval -EINVAL when a bad file name is given; * @retval -EROFS when opening read-only file for write, or attempting to * create a file on a system that has been mounted with the * FS_MOUNT_FLAG_READ_ONLY flag; * @retval -ENOENT when the file does not exist at the path; * @retval -ENOTSUP when not implemented by underlying file system driver; * @retval -EACCES when trying to truncate a file without opening it for write. * @retval <0 an other negative errno code, depending on a file system back-end. */ int fs_open(struct fs_file_t *zfp, const char *file_name, fs_mode_t flags); /** * @brief Close file * * Flushes the associated stream and closes the file. * * @param zfp Pointer to the file object * * @retval 0 on success; * @retval -ENOTSUP when not implemented by underlying file system driver; * @retval <0 a negative errno code on error. */ int fs_close(struct fs_file_t *zfp); /** * @brief Unlink file * * Deletes the specified file or directory * * @param path Path to the file or directory to delete * * @retval 0 on success; * @retval -EINVAL when a bad file name is given; * @retval -EROFS if file is read-only, or when file system has been mounted * with the FS_MOUNT_FLAG_READ_ONLY flag; * @retval -ENOTSUP when not implemented by underlying file system driver; * @retval <0 an other negative errno code on error. */ int fs_unlink(const char *path); /** * @brief Rename file or directory * * Performs a rename and / or move of the specified source path to the * specified destination. The source path can refer to either a file or a * directory. All intermediate directories in the destination path must * already exist. If the source path refers to a file, the destination path * must contain a full filename path, rather than just the new parent * directory. If an object already exists at the specified destination path, * this function causes it to be unlinked prior to the rename (i.e., the * destination gets clobbered). * @note Current implementation does not allow moving files between mount * points. * * @param from The source path * @param to The destination path * * @retval 0 on success; * @retval -EINVAL when a bad file name is given, or when rename would cause move * between mount points; * @retval -EROFS if file is read-only, or when file system has been mounted * with the FS_MOUNT_FLAG_READ_ONLY flag; * @retval -ENOTSUP when not implemented by underlying file system driver; * @retval <0 an other negative errno code on error. */ int fs_rename(const char *from, const char *to); /** * @brief Read file * * Reads up to @p size bytes of data to @p ptr pointed buffer, returns number * of bytes read. A returned value may be lower than @p size if there were * fewer bytes available than requested. * * @param zfp Pointer to the file object * @param ptr Pointer to the data buffer * @param size Number of bytes to be read * * @retval >=0 a number of bytes read, on success; * @retval -EBADF when invoked on zfp that represents unopened/closed file; * @retval -ENOTSUP when not implemented by underlying file system driver; * @retval <0 a negative errno code on error. */ ssize_t fs_read(struct fs_file_t *zfp, void *ptr, size_t size); /** * @brief Write file * * Attempts to write @p size number of bytes to the specified file. * If a negative value is returned from the function, the file pointer has not * been advanced. * If the function returns a non-negative number that is lower than @p size, * the global @c errno variable should be checked for an error code, * as the device may have no free space for data. * * @param zfp Pointer to the file object * @param ptr Pointer to the data buffer * @param size Number of bytes to be written * * @retval >=0 a number of bytes written, on success; * @retval -EBADF when invoked on zfp that represents unopened/closed file; * @retval -ENOTSUP when not implemented by underlying file system driver; * @retval <0 an other negative errno code on error. */ ssize_t fs_write(struct fs_file_t *zfp, const void *ptr, size_t size); /** * @brief Seek file * * Moves the file position to a new location in the file. The @p offset is added * to file position based on the @p whence parameter. * * @param zfp Pointer to the file object * @param offset Relative location to move the file pointer to * @param whence Relative location from where offset is to be calculated. * - @c FS_SEEK_SET for the beginning of the file; * - @c FS_SEEK_CUR for the current position; * - @c FS_SEEK_END for the end of the file. * * @retval 0 on success; * @retval -EBADF when invoked on zfp that represents unopened/closed file; * @retval -ENOTSUP if not supported by underlying file system driver; * @retval <0 an other negative errno code on error. */ int fs_seek(struct fs_file_t *zfp, off_t offset, int whence); /** * @brief Get current file position. * * Retrieves and returns the current position in the file stream. * * @param zfp Pointer to the file object * * @retval >= 0 a current position in file; * @retval -EBADF when invoked on zfp that represents unopened/closed file; * @retval -ENOTSUP if not supported by underlying file system driver; * @retval <0 an other negative errno code on error. * * The current revision does not validate the file object. */ off_t fs_tell(struct fs_file_t *zfp); /** * @brief Truncate or extend an open file to a given size * * Truncates the file to the new length if it is shorter than the current * size of the file. Expands the file if the new length is greater than the * current size of the file. The expanded region would be filled with zeroes. * * @note In the case of expansion, if the volume got full during the * expansion process, the function will expand to the maximum possible length * and return success. Caller should check if the expanded size matches the * requested length. * * @param zfp Pointer to the file object * @param length New size of the file in bytes * * @retval 0 on success; * @retval -EBADF when invoked on zfp that represents unopened/closed file; * @retval -ENOTSUP when not implemented by underlying file system driver; * @retval <0 an other negative errno code on error. */ int fs_truncate(struct fs_file_t *zfp, off_t length); /** * @brief Flush cached write data buffers of an open file * * The function flushes the cache of an open file; it can be invoked to ensure * data gets written to the storage media immediately, e.g. to avoid data loss * in case if power is removed unexpectedly. * @note Closing a file will cause caches to be flushed correctly so the * function need not be called when the file is being closed. * * @param zfp Pointer to the file object * * @retval 0 on success; * @retval -EBADF when invoked on zfp that represents unopened/closed file; * @retval -ENOTSUP when not implemented by underlying file system driver; * @retval <0 a negative errno code on error. */ int fs_sync(struct fs_file_t *zfp); /** * @brief Directory create * * Creates a new directory using specified path. * * @param path Path to the directory to create * * @retval 0 on success; * @retval -EEXIST if entry of given name exists; * @retval -EROFS if @p path is within read-only directory, or when * file system has been mounted with the FS_MOUNT_FLAG_READ_ONLY flag; * @retval -ENOTSUP when not implemented by underlying file system driver; * @retval <0 an other negative errno code on error */ int fs_mkdir(const char *path); /** * @brief Directory open * * Opens an existing directory specified by the path. * * @param zdp Pointer to the directory object * @param path Path to the directory to open * * @retval 0 on success; * @retval -EINVAL when a bad directory path is given; * @retval -EBUSY when zdp is already used; * @retval -ENOTSUP when not implemented by underlying file system driver; * @retval <0 a negative errno code on error. */ int fs_opendir(struct fs_dir_t *zdp, const char *path); /** * @brief Directory read entry * * Reads directory entries of an open directory. In end-of-dir condition, * the function will return 0 and set the <tt>entry->name[0]</tt> to 0. * * @note: Most existing underlying file systems do not generate POSIX * special directory entries "." or "..". For consistency the * abstraction layer will remove these from lower layer results so * higher layers see consistent results. * * @param zdp Pointer to the directory object * @param entry Pointer to zfs_dirent structure to read the entry into * * @retval 0 on success or end-of-dir; * @retval -ENOENT when no such directory found; * @retval -ENOTSUP when not implemented by underlying file system driver; * @retval <0 a negative errno code on error. */ int fs_readdir(struct fs_dir_t *zdp, struct fs_dirent *entry); /** * @brief Directory close * * Closes an open directory. * * @param zdp Pointer to the directory object * * @retval 0 on success; * @retval -ENOTSUP when not implemented by underlying file system driver; * @retval <0 a negative errno code on error. */ int fs_closedir(struct fs_dir_t *zdp); /** * @brief Mount filesystem * * Perform steps needed for mounting a file system like * calling the file system specific mount function and adding * the mount point to mounted file system list. * * @note Current implementation of ELM FAT driver allows only following mount * points: "/RAM:","/NAND:","/CF:","/SD:","/SD2:","/USB:","/USB2:","/USB3:" * or mount points that consist of single digit, e.g: "/0:", "/1:" and so forth. * * @param mp Pointer to the fs_mount_t structure. Referenced object * is not changed if the mount operation failed. * A reference is captured in the fs infrastructure if the * mount operation succeeds, and the application must not * mutate the structure contents until fs_unmount is * successfully invoked on the same pointer. * * @retval 0 on success; * @retval -ENOENT when file system type has not been registered; * @retval -ENOTSUP when not supported by underlying file system driver; * when @c FS_MOUNT_FLAG_USE_DISK_ACCESS is set but driver does not * support it. * @retval -EROFS if system requires formatting but @c FS_MOUNT_FLAG_READ_ONLY * has been set; * @retval <0 an other negative errno code on error. */ int fs_mount(struct fs_mount_t *mp); /** * @brief Unmount filesystem * * Perform steps needed to unmount a file system like * calling the file system specific unmount function and removing * the mount point from mounted file system list. * * @param mp Pointer to the fs_mount_t structure * * @retval 0 on success; * @retval -EINVAL if no system has been mounted at given mount point; * @retval -ENOTSUP when not supported by underlying file system driver; * @retval <0 an other negative errno code on error. */ int fs_unmount(struct fs_mount_t *mp); /** * @brief Get path of mount point at index * * This function iterates through the list of mount points and returns * the directory name of the mount point at the given @p index. * On success @p index is incremented and @p name is set to the mount directory * name. If a mount point with the given @p index does not exist, @p name will * be set to @c NULL. * * @param index Pointer to mount point index * @param name Pointer to pointer to path name * * @retval 0 on success; * @retval -ENOENT if there is no mount point with given index. */ int fs_readmount(int *index, const char **name); /** * @brief File or directory status * * Checks the status of a file or directory specified by the @p path. * @note The file on a storage device may not be updated until it is closed. * * @param path Path to the file or directory * @param entry Pointer to the zfs_dirent structure to fill if the file or * directory exists. * * @retval 0 on success; * @retval -EINVAL when a bad directory or file name is given; * @retval -ENOENT when no such directory or file is found; * @retval -ENOTSUP when not supported by underlying file system driver; * @retval <0 negative errno code on error. */ int fs_stat(const char *path, struct fs_dirent *entry); /** * @brief Retrieves statistics of the file system volume * * Returns the total and available space in the file system volume. * * @param path Path to the mounted directory * @param stat Pointer to the zfs_statvfs structure to receive the fs * statistics. * * @retval 0 on success; * @retval -EINVAL when a bad path to a directory, or a file, is given; * @retval -ENOTSUP when not implemented by underlying file system driver; * @retval <0 an other negative errno code on error. */ int fs_statvfs(const char *path, struct fs_statvfs *stat); /** * @brief Create fresh file system * * @param fs_type Type of file system to create. * @param dev_id Id of storage device. * @param cfg Backend dependent init object. If NULL then default configuration is used. * @param flags Additional flags for file system implementation. * * @retval 0 on success; * @retval <0 negative errno code on error. */ int fs_mkfs(int fs_type, uintptr_t dev_id, void *cfg, int flags); /** * @brief Register a file system * * Register file system with virtual file system. * Number of allowed file system types to be registered is controlled with the * CONFIG_FILE_SYSTEM_MAX_TYPES Kconfig option. * * @param type Type of file system (ex: @c FS_FATFS) * @param fs Pointer to File system * * @retval 0 on success; * @retval -EALREADY when a file system of a given type has already been registered; * @retval -ENOSCP when there is no space left, in file system registry, to add * this file system type. */ int fs_register(int type, const struct fs_file_system_t *fs); /** * @brief Unregister a file system * * Unregister file system from virtual file system. * * @param type Type of file system (ex: @c FS_FATFS) * @param fs Pointer to File system * * @retval 0 on success; * @retval -EINVAL when file system of a given type has not been registered. */ int fs_unregister(int type, const struct fs_file_system_t *fs); /** * @} */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_FS_FS_H_ */ ```
/content/code_sandbox/include/zephyr/fs/fs.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
5,401
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_FS_EXT2_H_ #define ZEPHYR_INCLUDE_FS_EXT2_H_ #include <stdint.h> /** @brief Configuration used to format ext2 file system. * * If a field is set to 0 then default value is used. * (In volume name the first cell of an array must be 0 to use default value.) * * @param block_size Requested size of block. * @param fs_size Requested size of file system. If 0 then whole available memory is used. * @param bytes_per_inode Requested memory for one inode. It is used to calculate number of inodes * in created file system. * @param uuid UUID for created file system. Used when set_uuid is true. * @param volume_name Name for created file system. * @param set_uuid If true then UUID from that structure is used in created file system. * If false then UUID (ver4) is generated. */ struct ext2_cfg { uint32_t block_size; uint32_t fs_size; /* Number of blocks that we want to take. */ uint32_t bytes_per_inode; uint8_t uuid[16]; uint8_t volume_name[17]; /* If first byte is 0 then name ext2" is given. */ bool set_uuid; }; #define FS_EXT2_DECLARE_DEFAULT_CONFIG(name) \ static struct ext2_cfg name = { \ .block_size = 1024, \ .fs_size = 0x800000, \ .bytes_per_inode = 4096, \ .volume_name = {'e', 'x', 't', '2', '\0'}, \ .set_uuid = false, \ } #endif /* ZEPHYR_INCLUDE_FS_EXT2_H_ */ ```
/content/code_sandbox/include/zephyr/fs/ext2.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
382
```objective-c /* NVS: non volatile storage in flash * * */ #ifndef ZEPHYR_INCLUDE_FS_NVS_H_ #define ZEPHYR_INCLUDE_FS_NVS_H_ #include <sys/types.h> #include <zephyr/kernel.h> #include <zephyr/device.h> #include <zephyr/toolchain.h> #ifdef __cplusplus extern "C" { #endif /** * @brief Non-volatile Storage (NVS) * @defgroup nvs Non-volatile Storage (NVS) * @since 1.12 * @version 1.0.0 * @ingroup file_system_storage * @{ * @} */ /** * @brief Non-volatile Storage Data Structures * @defgroup nvs_data_structures Non-volatile Storage Data Structures * @ingroup nvs * @{ */ /** * @brief Non-volatile Storage File system structure */ struct nvs_fs { /** File system offset in flash **/ off_t offset; /** Allocation table entry write address. * Addresses are stored as uint32_t: * - high 2 bytes correspond to the sector * - low 2 bytes are the offset in the sector */ uint32_t ate_wra; /** Data write address */ uint32_t data_wra; /** File system is split into sectors, each sector must be multiple of erase-block-size */ uint16_t sector_size; /** Number of sectors in the file system */ uint16_t sector_count; /** Flag indicating if the file system is initialized */ bool ready; /** Mutex */ struct k_mutex nvs_lock; /** Flash device runtime structure */ const struct device *flash_device; /** Flash memory parameters structure */ const struct flash_parameters *flash_parameters; #if CONFIG_NVS_LOOKUP_CACHE uint32_t lookup_cache[CONFIG_NVS_LOOKUP_CACHE_SIZE]; #endif }; /** * @} */ /** * @brief Non-volatile Storage APIs * @defgroup nvs_high_level_api Non-volatile Storage APIs * @ingroup nvs * @{ */ /** * @brief Mount an NVS file system onto the flash device specified in @p fs. * * @param fs Pointer to file system * @retval 0 Success * @retval -ERRNO errno code if error */ int nvs_mount(struct nvs_fs *fs); /** * @brief Clear the NVS file system from flash. * * @param fs Pointer to file system * @retval 0 Success * @retval -ERRNO errno code if error */ int nvs_clear(struct nvs_fs *fs); /** * @brief Write an entry to the file system. * * @note When @p len parameter is equal to @p 0 then entry is effectively removed (it is * equivalent to calling of nvs_delete). Any calls to nvs_read for entries with data of length * @p 0 will return error.@n It is not possible to distinguish between deleted entry and entry * with data of length 0. * * @param fs Pointer to file system * @param id Id of the entry to be written * @param data Pointer to the data to be written * @param len Number of bytes to be written * * @return Number of bytes written. On success, it will be equal to the number of bytes requested * to be written. When a rewrite of the same data already stored is attempted, nothing is written * to flash, thus 0 is returned. On error, returns negative value of errno.h defined error codes. */ ssize_t nvs_write(struct nvs_fs *fs, uint16_t id, const void *data, size_t len); /** * @brief Delete an entry from the file system * * @param fs Pointer to file system * @param id Id of the entry to be deleted * @retval 0 Success * @retval -ERRNO errno code if error */ int nvs_delete(struct nvs_fs *fs, uint16_t id); /** * @brief Read an entry from the file system. * * @param fs Pointer to file system * @param id Id of the entry to be read * @param data Pointer to data buffer * @param len Number of bytes to be read * * @return Number of bytes read. On success, it will be equal to the number of bytes requested * to be read. When the return value is larger than the number of bytes requested to read this * indicates not all bytes were read, and more data is available. On error, returns negative * value of errno.h defined error codes. */ ssize_t nvs_read(struct nvs_fs *fs, uint16_t id, void *data, size_t len); /** * @brief Read a history entry from the file system. * * @param fs Pointer to file system * @param id Id of the entry to be read * @param data Pointer to data buffer * @param len Number of bytes to be read * @param cnt History counter: 0: latest entry, 1: one before latest ... * * @return Number of bytes read. On success, it will be equal to the number of bytes requested * to be read. When the return value is larger than the number of bytes requested to read this * indicates not all bytes were read, and more data is available. On error, returns negative * value of errno.h defined error codes. */ ssize_t nvs_read_hist(struct nvs_fs *fs, uint16_t id, void *data, size_t len, uint16_t cnt); /** * @brief Calculate the available free space in the file system. * * @param fs Pointer to file system * * @return Number of bytes free. On success, it will be equal to the number of bytes that can * still be written to the file system. Calculating the free space is a time consuming operation, * especially on spi flash. On error, returns negative value of errno.h defined error codes. */ ssize_t nvs_calc_free_space(struct nvs_fs *fs); /** * @brief Tell how many contiguous free space remains in the currently active NVS sector. * * @param fs Pointer to the file system. * * @return Number of free bytes. */ size_t nvs_sector_max_data_size(struct nvs_fs *fs); /** * @brief Close the currently active sector and switch to the next one. * * @note The garbage collector is called on the new sector. * * @warning This routine is made available for specific use cases. * It breaks the aim of the NVS to avoid any unnecessary flash erases. * Using this routine extensively can result in premature failure of the flash device. * * @param fs Pointer to the file system. * * @return 0 on success. On error, returns negative value of errno.h defined error codes. */ int nvs_sector_use_next(struct nvs_fs *fs); /** * @} */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_FS_NVS_H_ */ ```
/content/code_sandbox/include/zephyr/fs/nvs.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,472
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_FS_FS_INTERFACE_H_ #define ZEPHYR_INCLUDE_FS_FS_INTERFACE_H_ #include <stdint.h> #ifdef __cplusplus extern "C" { #endif #if defined(CONFIG_FILE_SYSTEM_MAX_FILE_NAME) && (CONFIG_FILE_SYSTEM_MAX_FILE_NAME - 0) > 0 /* No in-tree file system supports name longer than 255 characters */ #if (CONFIG_FILE_SYSTEM_LITTLEFS || CONFIG_FAT_FILESYSTEM_ELM || \ CONFIG_FILE_SYSTEM_EXT2) && (CONFIG_FILE_SYSTEM_MAX_FILE_NAME > 255) #error "Max allowed CONFIG_FILE_SYSTEM_MAX_FILE_NAME is 255 characters, when any in-tree FS enabled" #endif /* Enabled FAT driver, without LFN, restricts name length to 12 characters */ #if defined(CONFIG_FAT_FILESYSTEM_ELM) && !(CONFIG_FS_FATFS_LFN) && \ (CONFIG_FILE_SYSTEM_MAX_FILE_NAME > 12) #error "CONFIG_FILE_SYSTEM_MAX_FILE_NAME can not be > 12 if FAT is enabled without LFN" #endif #define MAX_FILE_NAME CONFIG_FILE_SYSTEM_MAX_FILE_NAME #else /* Select from enabled file systems */ #if defined(CONFIG_FAT_FILESYSTEM_ELM) #if defined(CONFIG_FS_FATFS_LFN) #define MAX_FILE_NAME CONFIG_FS_FATFS_MAX_LFN #else /* CONFIG_FS_FATFS_LFN */ #define MAX_FILE_NAME 12 /* Uses 8.3 SFN */ #endif /* CONFIG_FS_FATFS_LFN */ #endif #if !defined(MAX_FILE_NAME) && defined(CONFIG_FILE_SYSTEM_EXT2) #define MAX_FILE_NAME 255 #endif #if !defined(MAX_FILE_NAME) && defined(CONFIG_FILE_SYSTEM_LITTLEFS) #define MAX_FILE_NAME 255 #endif #if !defined(MAX_FILE_NAME) /* filesystem selection */ /* Use standard 8.3 when no filesystem is explicitly selected */ #define MAX_FILE_NAME 12 #endif /* filesystem selection */ #endif /* CONFIG_FILE_SYSTEM_MAX_FILE_NAME */ /* Type for fs_open flags */ typedef uint8_t fs_mode_t; struct fs_mount_t; /** * @addtogroup file_system_api * @{ */ /** * @brief File object representing an open file * * The object needs to be initialized with fs_file_t_init(). */ struct fs_file_t { /** Pointer to file object structure */ void *filep; /** Pointer to mount point structure */ const struct fs_mount_t *mp; /** Open/create flags */ fs_mode_t flags; }; /** * @brief Directory object representing an open directory * * The object needs to be initialized with fs_dir_t_init(). */ struct fs_dir_t { /** Pointer to directory object structure */ void *dirp; /** Pointer to mount point structure */ const struct fs_mount_t *mp; }; /** * @} */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_FS_FS_INTERFACE_H_ */ ```
/content/code_sandbox/include/zephyr/fs/fs_interface.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
592
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_FS_FS_SYS_H_ #define ZEPHYR_INCLUDE_FS_FS_SYS_H_ #ifdef __cplusplus extern "C" { #endif /** * @ingroup file_system_api * @{ */ /** * @brief File System interface structure */ struct fs_file_system_t { /** * @name File operations * @{ */ /** * Opens or creates a file, depending on flags given. * * @param filp File to open/create. * @param fs_path Path to the file. * @param flags Flags for opening/creating the file. * @return 0 on success, negative errno code on fail. */ int (*open)(struct fs_file_t *filp, const char *fs_path, fs_mode_t flags); /** * Reads nbytes number of bytes. * * @param filp File to read from. * @param dest Destination buffer. * @param nbytes Number of bytes to read. * @return Number of bytes read on success, negative errno code on fail. */ ssize_t (*read)(struct fs_file_t *filp, void *dest, size_t nbytes); /** * Writes nbytes number of bytes. * * @param filp File to write to. * @param src Source buffer. * @param nbytes Number of bytes to write. * @return Number of bytes written on success, negative errno code on fail. */ ssize_t (*write)(struct fs_file_t *filp, const void *src, size_t nbytes); /** * Moves the file position to a new location in the file. * * @param filp File to move. * @param off Relative offset from the position specified by whence. * @param whence Position in the file. Possible values: SEEK_CUR, SEEK_SET, SEEK_END. * @return New position in the file or negative errno code on fail. */ int (*lseek)(struct fs_file_t *filp, off_t off, int whence); /** * Retrieves the current position in the file. * * @param filp File to get the current position from. * @return Current position in the file or negative errno code on fail. */ off_t (*tell)(struct fs_file_t *filp); /** * Truncates/expands the file to the new length. * * @param filp File to truncate/expand. * @param length New length of the file. * @return 0 on success, negative errno code on fail. */ int (*truncate)(struct fs_file_t *filp, off_t length); /** * Flushes the cache of an open file. * * @param filp File to flush. * @return 0 on success, negative errno code on fail. */ int (*sync)(struct fs_file_t *filp); /** * Flushes the associated stream and closes the file. * * @param filp File to close. * @return 0 on success, negative errno code on fail. */ int (*close)(struct fs_file_t *filp); /** @} */ /** * @name Directory operations * @{ */ /** * Opens an existing directory specified by the path. * * @param dirp Directory to open. * @param fs_path Path to the directory. * @return 0 on success, negative errno code on fail. */ int (*opendir)(struct fs_dir_t *dirp, const char *fs_path); /** * Reads directory entries of an open directory. * * @param dirp Directory to read from. * @param entry Next directory entry in the dirp directory. * @return 0 on success, negative errno code on fail. */ int (*readdir)(struct fs_dir_t *dirp, struct fs_dirent *entry); /** * Closes an open directory. * * @param dirp Directory to close. * @return 0 on success, negative errno code on fail. */ int (*closedir)(struct fs_dir_t *dirp); /** @} */ /** * @name File system level operations * @{ */ /** * Mounts a file system. * * @param mountp Mount point. * @return 0 on success, negative errno code on fail. */ int (*mount)(struct fs_mount_t *mountp); /** * Unmounts a file system. * * @param mountp Mount point. * @return 0 on success, negative errno code on fail. */ int (*unmount)(struct fs_mount_t *mountp); /** * Deletes the specified file or directory. * * @param mountp Mount point. * @param name Path to the file or directory to delete. * @return 0 on success, negative errno code on fail. */ int (*unlink)(struct fs_mount_t *mountp, const char *name); /** * Renames a file or directory. * * @param mountp Mount point. * @param from Path to the file or directory to rename. * @param to New name of the file or directory. * @return 0 on success, negative errno code on fail. */ int (*rename)(struct fs_mount_t *mountp, const char *from, const char *to); /** * Creates a new directory using specified path. * * @param mountp Mount point. * @param name Path to the directory to create. * @return 0 on success, negative errno code on fail. */ int (*mkdir)(struct fs_mount_t *mountp, const char *name); /** * Checks the status of a file or directory specified by the path. * * @param mountp Mount point. * @param path Path to the file or directory. * @param entry Directory entry. * @return 0 on success, negative errno code on fail. */ int (*stat)(struct fs_mount_t *mountp, const char *path, struct fs_dirent *entry); /** * Returns the total and available space on the file system volume. * * @param mountp Mount point. * @param path Path to the file or directory. * @param stat File system statistics. * @return 0 on success, negative errno code on fail. */ int (*statvfs)(struct fs_mount_t *mountp, const char *path, struct fs_statvfs *stat); #if defined(CONFIG_FILE_SYSTEM_MKFS) || defined(__DOXYGEN__) /** * Formats a device to specified file system type. * Available only if @kconfig{CONFIG_FILE_SYSTEM_MKFS} is enabled. * * @param dev_id Device identifier. * @param cfg File system configuration. * @param flags Formatting flags. * @return 0 on success, negative errno code on fail. * * @note This operation destroys existing data on the target device. */ int (*mkfs)(uintptr_t dev_id, void *cfg, int flags); #endif /** @} */ }; /** * @} */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_FS_FS_SYS_H_ */ ```
/content/code_sandbox/include/zephyr/fs/fs_sys.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,593
```objective-c /* * */ #ifndef ZEPHYR_LLEXT_BUF_LOADER_H #define ZEPHYR_LLEXT_BUF_LOADER_H #include <zephyr/llext/loader.h> #ifdef __cplusplus extern "C" { #endif /** * @file * @brief LLEXT buffer loader implementation. * * @addtogroup llext_loader_apis * @{ */ /** * @brief Implementation of @ref llext_loader that reads from a memory buffer. */ struct llext_buf_loader { /** Extension loader */ struct llext_loader loader; /** @cond ignore */ const uint8_t *buf; size_t len; size_t pos; /** @endcond */ }; /** @cond ignore */ int llext_buf_read(struct llext_loader *ldr, void *buf, size_t len); int llext_buf_seek(struct llext_loader *ldr, size_t pos); void *llext_buf_peek(struct llext_loader *ldr, size_t pos); /** @endcond */ /** * @brief Initializer for an llext_buf_loader structure * * @param _buf Buffer containing the ELF binary * @param _buf_len Buffer length in bytes */ #define LLEXT_BUF_LOADER(_buf, _buf_len) \ { \ .loader = { \ .read = llext_buf_read, \ .seek = llext_buf_seek, \ .peek = llext_buf_peek, \ }, \ .buf = (_buf), \ .len = (_buf_len), \ .pos = 0 \ } /** * @} */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_LLEXT_BUF_LOADER_H */ ```
/content/code_sandbox/include/zephyr/llext/buf_loader.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
377
```objective-c /* * */ #ifndef ZEPHYR_LLEXT_LOADER_H #define ZEPHYR_LLEXT_LOADER_H #include <zephyr/llext/elf.h> #include <stddef.h> #ifdef __cplusplus extern "C" { #endif /** * @file * @brief LLEXT ELF loader context types. * * The following types are used to define the context of the ELF loader * used by the \ref llext subsystem. * * @defgroup llext_loader_apis ELF loader context * @ingroup llext_apis * @{ */ #include <zephyr/llext/llext.h> /** @cond ignore */ struct llext_elf_sect_map; /* defined in llext_priv.h */ /** @endcond */ /** * @brief Linkable loadable extension loader context * * This object is used to access the ELF file data and cache its contents * while an extension is being loaded by the LLEXT subsystem. Once the * extension is loaded, this object is no longer needed. */ struct llext_loader { /** * @brief Function to read (copy) from the loader * * Copies len bytes into buf from the current position of the * loader. * * @param[in] ldr Loader * @param[in] out Output location * @param[in] len Length to copy into the output location * * @returns 0 on success, or a negative error code. */ int (*read)(struct llext_loader *ldr, void *out, size_t len); /** * @brief Function to seek to a new absolute location in the stream. * * Changes the location of the loader position to a new absolute * given position. * * @param[in] ldr Loader * @param[in] pos Position in stream to move loader * * @returns 0 on success, or a negative error code. */ int (*seek)(struct llext_loader *ldr, size_t pos); /** * @brief Optional function to peek at an absolute location in the ELF. * * Return a pointer to the buffer at specified offset. * * @param[in] ldr Loader * @param[in] pos Position to obtain a pointer to * * @returns a pointer into the buffer or `NULL` if not supported */ void *(*peek)(struct llext_loader *ldr, size_t pos); /** @cond ignore */ elf_ehdr_t hdr; elf_shdr_t sects[LLEXT_MEM_COUNT]; elf_shdr_t *sect_hdrs; bool sect_hdrs_on_heap; struct llext_elf_sect_map *sect_map; uint32_t sect_cnt; /** @endcond */ }; /** @cond ignore */ static inline int llext_read(struct llext_loader *l, void *buf, size_t len) { return l->read(l, buf, len); } static inline int llext_seek(struct llext_loader *l, size_t pos) { return l->seek(l, pos); } static inline void *llext_peek(struct llext_loader *l, size_t pos) { if (l->peek) { return l->peek(l, pos); } return NULL; } /* @endcond */ /** * @} */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_LLEXT_LOADER_H */ ```
/content/code_sandbox/include/zephyr/llext/loader.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
735
```objective-c /* * */ #ifndef ZEPHYR_LLEXT_SYMBOL_H #define ZEPHYR_LLEXT_SYMBOL_H #include <zephyr/sys/iterable_sections.h> #include <zephyr/toolchain.h> #include <stddef.h> #include <stdint.h> #ifdef __cplusplus extern "C" { #endif /** * @file * @brief Linkable loadable extension symbol definitions * * This file provides a set of macros and structures for defining and exporting * symbols from the base image to extensions and vice versa, so that proper * linking can be done between the two entities. * * @defgroup llext_symbols Exported symbol definitions * @ingroup llext_apis * @{ */ /** * @brief Constant symbols are unchangeable named memory addresses * * Symbols may be named function or global objects that have been exported * for linking. These constant symbols are useful in the base image * as they may be placed in ROM. * * @note When updating this structure, make sure to also update the * 'scripts/build/llext_prepare_exptab.py' build script. */ struct llext_const_symbol { /** At build time, we always write to 'name'. * At runtime, which field is used depends * on CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID. */ union { /** Name of symbol */ const char *const name; /** Symbol Link Identifier */ const uintptr_t slid; }; /** Address of symbol */ const void *const addr; }; BUILD_ASSERT(sizeof(struct llext_const_symbol) == 2 * sizeof(uintptr_t)); /** * @brief Symbols are named memory addresses * * Symbols may be named function or global objects that have been exported * for linking. These are mutable and should come from extensions where * the location may need updating depending on where memory is placed. */ struct llext_symbol { /** Name of symbol */ const char *name; /** Address of symbol */ void *addr; }; /** * @brief A symbol table * * An array of symbols */ struct llext_symtable { /** Number of symbols in the table */ size_t sym_cnt; /** Array of symbols */ struct llext_symbol *syms; }; /** * @brief Export a constant symbol to extensions * * Takes a symbol (function or object) by symbolic name and adds the name * and address of the symbol to a table of symbols that may be referenced * by extensions. * * @param x Symbol to export to extensions */ #if defined(CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID) #define EXPORT_SYMBOL(x) \ static const char Z_GENERIC_SECTION("llext_exports_strtab") __used \ x ## _sym_name[] = STRINGIFY(x); \ static const STRUCT_SECTION_ITERABLE(llext_const_symbol, x ## _sym) = { \ .name = x ## _sym_name, .addr = (const void *)&x, \ } #elif defined(CONFIG_LLEXT) #define EXPORT_SYMBOL(x) \ static const STRUCT_SECTION_ITERABLE(llext_const_symbol, x ## _sym) = { \ .name = STRINGIFY(x), .addr = (const void *)&x, \ } #else #define EXPORT_SYMBOL(x) #endif /** * @brief Exports a symbol from an extension to the base image * * This macro can be used in extensions to add a symbol (function or object) * to the extension's exported symbol table, so that it may be referenced by * the base image. * * @param x Extension symbol to export to the base image */ #if defined(CONFIG_LLEXT) && defined(LL_EXTENSION_BUILD) #define LL_EXTENSION_SYMBOL(x) \ static const struct llext_const_symbol \ Z_GENERIC_SECTION(".exported_sym") __used \ x ## _sym = { \ .name = STRINGIFY(x), .addr = (const void *)&x, \ } #else #define LL_EXTENSION_SYMBOL(x) #endif /** * @} */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_LLEXT_SYMBOL_H */ ```
/content/code_sandbox/include/zephyr/llext/symbol.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
886
```objective-c /* * */ #ifndef ZEPHYR_LLEXT_H #define ZEPHYR_LLEXT_H #include <zephyr/sys/slist.h> #include <zephyr/llext/elf.h> #include <zephyr/llext/symbol.h> #include <zephyr/kernel.h> #include <sys/types.h> #include <stdbool.h> #ifdef __cplusplus extern "C" { #endif /** * @file * @brief Support for linkable loadable extensions * * This file describes the APIs for loading and interacting with Linkable * Loadable Extensions (LLEXTs) in Zephyr. * * @defgroup llext_apis Linkable loadable extensions * @since 3.5 * @version 0.1.0 * @ingroup os_services * @{ */ /** * @brief List of memory regions stored or referenced in the LLEXT subsystem * * This enum lists the different types of memory regions that are used by the * LLEXT subsystem. The names match common ELF file section names; but note * that at load time multiple ELF sections with similar flags may be merged * together into a single memory region. */ enum llext_mem { LLEXT_MEM_TEXT, /**< Executable code */ LLEXT_MEM_DATA, /**< Initialized data */ LLEXT_MEM_RODATA, /**< Read-only data */ LLEXT_MEM_BSS, /**< Uninitialized data */ LLEXT_MEM_EXPORT, /**< Exported symbol table */ LLEXT_MEM_SYMTAB, /**< Symbol table */ LLEXT_MEM_STRTAB, /**< Symbol name strings */ LLEXT_MEM_SHSTRTAB, /**< Section name strings */ LLEXT_MEM_COUNT, /**< Number of regions managed by LLEXT */ }; /** @cond ignore */ /* Number of memory partitions used by LLEXT */ #define LLEXT_MEM_PARTITIONS (LLEXT_MEM_BSS+1) struct llext_loader; /** @endcond */ /** * @brief Structure describing a linkable loadable extension * * This structure holds the data for a loaded extension. It is created by the * @ref llext_load function and destroyed by the @ref llext_unload function. */ struct llext { /** @cond ignore */ sys_snode_t _llext_list; #ifdef CONFIG_USERSPACE struct k_mem_partition mem_parts[LLEXT_MEM_PARTITIONS]; struct k_mem_domain mem_domain; #endif /** @endcond */ /** Name of the llext */ char name[16]; /** Lookup table of memory regions */ void *mem[LLEXT_MEM_COUNT]; /** Is the memory for this region allocated on heap? */ bool mem_on_heap[LLEXT_MEM_COUNT]; /** Size of each stored region */ size_t mem_size[LLEXT_MEM_COUNT]; /** Total llext allocation size */ size_t alloc_size; /** * Table of all global symbols in the extension; used internally as * part of the linking process. E.g. if the extension is built out of * several files, if any symbols are referenced between files, this * table will be used to link them. */ struct llext_symtable sym_tab; /** * Table of symbols exported by the llext via @ref LL_EXTENSION_SYMBOL. * This can be used in the main Zephyr binary to find symbols in the * extension. */ struct llext_symtable exp_tab; /** Extension use counter, prevents unloading while in use */ unsigned int use_count; }; /** * @brief Advanced llext_load parameters * * This structure contains advanced parameters for @ref llext_load. */ struct llext_load_param { /** Perform local relocation */ bool relocate_local; /** * Use the virtual symbol addresses from the ELF, not addresses within * the memory buffer, when calculating relocation targets. */ bool pre_located; }; /** Default initializer for @ref llext_load_param */ #define LLEXT_LOAD_PARAM_DEFAULT { .relocate_local = true, } /** * @brief Find an llext by name * * @param[in] name String name of the llext * @returns a pointer to the @ref llext, or `NULL` if not found */ struct llext *llext_by_name(const char *name); /** * @brief Iterate over all loaded extensions * * Calls a provided callback function for each registered extension or until the * callback function returns a non-0 value. * * @param[in] fn callback function * @param[in] arg a private argument to be provided to the callback function * @returns the value returned by the last callback invocation * @retval 0 if no extensions are registered */ int llext_iterate(int (*fn)(struct llext *ext, void *arg), void *arg); /** * @brief Load and link an extension * * Loads relevant ELF data into memory and provides a structure to work with it. * * @param[in] loader An extension loader that provides input data and context * @param[in] name A string identifier for the extension * @param[out] ext Pointer to the newly allocated @ref llext structure * @param[in] ldr_parm Optional advanced load parameters (may be `NULL`) * * @returns the previous extension use count on success, or a negative error code. * @retval -ENOMEM Not enough memory * @retval -ENOEXEC Invalid ELF stream * @retval -ENOTSUP Unsupported ELF features */ int llext_load(struct llext_loader *loader, const char *name, struct llext **ext, struct llext_load_param *ldr_parm); /** * @brief Unload an extension * * @param[in] ext Extension to unload */ int llext_unload(struct llext **ext); /** * @brief Find the address for an arbitrary symbol. * * Searches for a symbol address, either in the list of symbols exported by * the main Zephyr binary or in an extension's symbol table. * * @param[in] sym_table Symbol table to lookup symbol in, or `NULL` to search * in the main Zephyr symbol table * @param[in] sym_name Symbol name to find * * @returns the address of symbol in memory, or `NULL` if not found */ const void *llext_find_sym(const struct llext_symtable *sym_table, const char *sym_name); /** * @brief Call a function by name. * * Expects a symbol representing a `void fn(void)` style function exists * and may be called. * * @param[in] ext Extension to call function in * @param[in] sym_name Function name (exported symbol) in the extension * * @retval 0 Success * @retval -ENOENT Symbol name not found */ int llext_call_fn(struct llext *ext, const char *sym_name); /** * @brief Add an extension to a memory domain. * * Allows an extension to be executed in user mode threads when memory * protection hardware is enabled by adding memory partitions covering the * extension's memory regions to a memory domain. * * @param[in] ext Extension to add to a domain * @param[in] domain Memory domain to add partitions to * * @returns 0 on success, or a negative error code. * @retval -ENOSYS @kconfig{CONFIG_USERSPACE} is not enabled or supported */ int llext_add_domain(struct llext *ext, struct k_mem_domain *domain); /** * @brief Architecture specific opcode update function * * ELF files include sections describing a series of _relocations_, which are * instructions on how to rewrite opcodes given the actual placement of some * symbolic data such as a section, function, or object. These relocations * are architecture specific and each architecture supporting LLEXT must * implement this. * * @param[in] rel Relocation data provided by ELF * @param[in] loc Address of opcode to rewrite * @param[in] sym_base_addr Address of symbol referenced by relocation * @param[in] sym_name Name of symbol referenced by relocation * @param[in] load_bias `.text` load address * @retval 0 Success * @retval -ENOTSUP Unsupported relocation * @retval -ENOEXEC Invalid relocation */ int arch_elf_relocate(elf_rela_t *rel, uintptr_t loc, uintptr_t sym_base_addr, const char *sym_name, uintptr_t load_bias); /** * @brief Locates an ELF section in the file. * * Searches for a section by name in the ELF file and returns its offset. * * @param loader Extension loader data and context * @param search_name Section name to search for * @returns the section offset or a negative error code */ ssize_t llext_find_section(struct llext_loader *loader, const char *search_name); /** * @brief Architecture specific function for updating addresses via relocation table * * @param[in] loader Extension loader data and context * @param[in] ext Extension to call function in * @param[in] rel Relocation data provided by elf * @param[in] sym Corresponding symbol table entry * @param[in] got_offset Offset within a relocation table */ void arch_elf_relocate_local(struct llext_loader *loader, struct llext *ext, const elf_rela_t *rel, const elf_sym_t *sym, size_t got_offset); /** * @} */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_LLEXT_H */ ```
/content/code_sandbox/include/zephyr/llext/llext.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
2,025
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_LORAWAN_EMUL_H_ #define ZEPHYR_INCLUDE_LORAWAN_EMUL_H_ #include <stdbool.h> #include <stdint.h> #include <zephyr/lorawan/lorawan.h> /** * @brief Defines the emulator uplink callback handler function signature. * * @param port LoRaWAN port * @param len Payload data length * @param data Pointer to the payload data */ typedef void (*lorawan_uplink_cb_t)(uint8_t port, uint8_t len, const uint8_t *data); /** * @brief Emulate LoRaWAN downlink message * * @param port Port message was sent on * @param data_pending Network server has more downlink packets pending * @param rssi Received signal strength in dBm * @param snr Signal to Noise ratio in dBm * @param len Length of data received, will be 0 for ACKs * @param data Data received, will be NULL for ACKs */ void lorawan_emul_send_downlink(uint8_t port, bool data_pending, int16_t rssi, int8_t snr, uint8_t len, const uint8_t *data); /** * @brief Register callback for emulated uplink messages * * @param cb Pointer to the uplink callback handler function */ void lorawan_emul_register_uplink_callback(lorawan_uplink_cb_t cb); #endif /* ZEPHYR_INCLUDE_LORAWAN_EMUL_H_ */ ```
/content/code_sandbox/include/zephyr/lorawan/emul.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
326
```objective-c /* * * */ #ifndef ZEPHYR_LLEXT_ELF_H #define ZEPHYR_LLEXT_ELF_H #include <stdint.h> /** * @file * @brief Data structures and constants defined in the ELF specification. * * Reference documents can be found here: path_to_url * * @defgroup llext_elf ELF constants and data types * @ingroup llext_apis * @{ */ #ifdef __cplusplus extern "C" { #endif /** Unsigned program address */ typedef uint32_t elf32_addr; /** Unsigned medium integer */ typedef uint16_t elf32_half; /** Unsigned file offset */ typedef uint32_t elf32_off; /** Signed integer */ typedef int32_t elf32_sword; /** Unsigned integer */ typedef uint32_t elf32_word; /** Unsigned program address */ typedef uint64_t elf64_addr; /** Unsigned medium integer */ typedef uint16_t elf64_half; /** Unsigned file offset */ typedef uint64_t elf64_off; /** Signed integer */ typedef int32_t elf64_sword; /** Unsigned integer */ typedef uint32_t elf64_word; /** Signed long integer */ typedef int64_t elf64_sxword; /** Unsigned long integer */ typedef uint64_t elf64_xword; /** * @brief ELF identifier block * * 4 byte magic (.ELF) * 1 byte class (Invalid, 32 bit, 64 bit) * 1 byte endianness (Invalid, LSB, MSB) * 1 byte version (1) * 1 byte OS ABI (0 None, 1 HP-UX, 2 NetBSD, 3 Linux) * 1 byte ABI (0) * 7 bytes padding */ #define EI_NIDENT 16 /** * @brief ELF Header(32-bit) */ struct elf32_ehdr { /** Magic string identifying ELF binary */ unsigned char e_ident[EI_NIDENT]; /** Type of ELF */ elf32_half e_type; /** Machine type */ elf32_half e_machine; /** Object file version */ elf32_word e_version; /** Virtual address of entry */ elf32_addr e_entry; /** Program header table offset */ elf32_off e_phoff; /** Section header table offset */ elf32_off e_shoff; /** Processor specific flags */ elf32_word e_flags; /** ELF header size */ elf32_half e_ehsize; /** Program header count */ elf32_half e_phentsize; /** Program header count */ elf32_half e_phnum; /** Section header size */ elf32_half e_shentsize; /** Section header count */ elf32_half e_shnum; /** Section header containing section header string table */ elf32_half e_shstrndx; }; /** * @brief ELF Header(64-bit) */ struct elf64_ehdr { /** Magic string identifying ELF binary */ unsigned char e_ident[EI_NIDENT]; /** Type of ELF */ elf64_half e_type; /** Machine type */ elf64_half e_machine; /** Object file version */ elf64_word e_version; /** Virtual address of entry */ elf64_addr e_entry; /** Program header table offset */ elf64_off e_phoff; /** Section header table offset */ elf64_off e_shoff; /** Processor specific flags */ elf64_word e_flags; /** ELF header size */ elf64_half e_ehsize; /** Program header size */ elf64_half e_phentsize; /** Program header count */ elf64_half e_phnum; /** Section header size */ elf64_half e_shentsize; /** Section header count */ elf64_half e_shnum; /** Section header containing section header string table */ elf64_half e_shstrndx; }; /** Relocatable (unlinked) ELF */ #define ET_REL 1 /** Executable (without PIC/PIE) ELF */ #define ET_EXEC 2 /** Dynamic (executable with PIC/PIE or shared lib) ELF */ #define ET_DYN 3 /** Core Dump */ #define ET_CORE 4 /** * @brief Section Header(32-bit) */ struct elf32_shdr { /** Section header name index in section header string table */ elf32_word sh_name; /** Section type */ elf32_word sh_type; /** Section header attributes */ elf32_word sh_flags; /** Address of section in the image */ elf32_addr sh_addr; /** Location of section in the ELF binary in bytes */ elf32_off sh_offset; /** Section size in bytes */ elf32_word sh_size; /** Section header table link index, depends on section type */ elf32_word sh_link; /** Section info, depends on section type */ elf32_word sh_info; /** Section address alignment */ elf32_word sh_addralign; /** Section contains table of fixed size entries sh_entsize bytes large */ elf32_word sh_entsize; }; /** * @brief Section Header(64-bit) */ struct elf64_shdr { /** Section header name index in section header string table */ elf64_word sh_name; /** Section type */ elf64_word sh_type; /** Section header attributes */ elf64_xword sh_flags; /** Address of section in the image */ elf64_addr sh_addr; /** Location of section in the ELF binary in bytes */ elf64_off sh_offset; /** Section size in bytes */ elf64_xword sh_size; /** Section header table link index, depends on section type */ elf64_word sh_link; /** Section info, depends on section type */ elf64_word sh_info; /** Section address alignment */ elf64_xword sh_addralign; /** Section contains table of fixed size entries sh_entsize bytes large */ elf64_xword sh_entsize; }; /** ELF section types */ #define SHT_NULL 0x0 /**< Unused section */ #define SHT_PROGBITS 0x1 /**< Program data */ #define SHT_SYMTAB 0x2 /**< Symbol table */ #define SHT_STRTAB 0x3 /**< String table */ #define SHT_RELA 0x4 /**< Relocation entries with addends */ #define SHT_NOBITS 0x8 /**< Program data with no file image */ #define SHT_REL 0x9 /**< Relocation entries without addends */ #define SHT_DYNSYM 0xB /**< Dynamic linking symbol table */ /** ELF section flags */ #define SHF_WRITE 0x1 /**< Section is writable */ #define SHF_ALLOC 0x2 /**< Section is present in memory */ #define SHF_EXECINSTR 0x4 /**< Section contains executable instructions */ /** * @brief Symbol table entry(32-bit) */ struct elf32_sym { /** Name of the symbol as an index into the symbol string table */ elf32_word st_name; /** Value or location of the symbol */ elf32_addr st_value; /** Size of the symbol */ elf32_word st_size; /** Symbol binding and type information */ unsigned char st_info; /** Symbol visibility */ unsigned char st_other; /** Symbols related section given by section header index */ elf32_half st_shndx; }; /** * @brief Symbol table entry(64-bit) */ struct elf64_sym { /** Name of the symbol as an index into the symbol string table */ elf64_word st_name; /** Symbol binding and type information */ unsigned char st_info; /** Symbol visibility */ unsigned char st_other; /** Symbols related section given by section header index */ elf64_half st_shndx; /** Value or location of the symbol */ elf64_addr st_value; /** Size of the symbol */ elf64_xword st_size; }; /** ELF section numbers */ #define SHN_UNDEF 0 /**< Undefined section */ #define SHN_LORESERVE 0xff00 /**< Start of reserved section numbers */ #define SHN_ABS 0xfff1 /**< Special value for absolute symbols */ #define SHN_COMMON 0xfff2 /**< Common block */ #define SHN_HIRESERVE 0xffff /**< End of reserved section numbers */ /** Symbol table entry types */ #define STT_NOTYPE 0 /**< No type */ #define STT_OBJECT 1 /**< Data or object */ #define STT_FUNC 2 /**< Function */ #define STT_SECTION 3 /**< Section */ #define STT_FILE 4 /**< File name */ #define STT_COMMON 5 /**< Common block */ #define STT_LOOS 10 /**< Start of OS specific */ #define STT_HIOS 12 /**< End of OS specific */ #define STT_LOPROC 13 /**< Start of processor specific */ #define STT_HIPROC 15 /**< End of processor specific */ /** Symbol table entry bindings */ #define STB_LOCAL 0 /**< Local symbol */ #define STB_GLOBAL 1 /**< Global symbol */ #define STB_WEAK 2 /**< Weak symbol */ #define STB_LOOS 10 /**< Start of OS specific */ #define STB_HIOS 12 /**< End of OS specific */ #define STB_LOPROC 13 /**< Start of processor specific */ #define STB_HIPROC 15 /**< End of processor specific */ /** * @brief Symbol binding from 32bit st_info * * @param i Value of st_info */ #define ELF32_ST_BIND(i) ((i) >> 4) /** * @brief Symbol type from 32bit st_info * * @param i Value of st_info */ #define ELF32_ST_TYPE(i) ((i) & 0xf) /** * @brief Symbol binding from 32bit st_info * * @param i Value of st_info */ #define ELF64_ST_BIND(i) ((i) >> 4) /** * @brief Symbol type from 32bit st_info * * @param i Value of st_info */ #define ELF64_ST_TYPE(i) ((i) & 0xf) /** * @brief Relocation entry for 32-bit ELFs. * * This structure stores information describing a relocation to be performed. * Additional information about the relocation is stored at the location * pointed to by @ref r_offset. */ struct elf32_rel { /** Offset in the section to perform a relocation */ elf32_addr r_offset; /** Information about the relocation, related symbol and type */ elf32_word r_info; }; /** * @brief Relocation entry for 32-bit ELFs with addend. * * This structure stores information describing a relocation to be performed. */ struct elf32_rela { /** Offset in the section to perform a relocation */ elf32_addr r_offset; /** Information about the relocation, related symbol and type */ elf32_word r_info; /** Offset to be applied to the symbol address */ elf32_sword r_addend; }; /** * @brief Relocation symbol index from r_info * * @param i Value of r_info */ #define ELF32_R_SYM(i) ((i) >> 8) /** * @brief Relocation type from r_info * * @param i Value of r_info */ #define ELF32_R_TYPE(i) ((i) & 0xff) /** * @brief Relocation entry for 64-bit ELFs. * * This structure stores information describing a relocation to be performed. * Additional information about the relocation is stored at the location * pointed to by @ref r_offset. */ struct elf64_rel { /** Offset in the section to perform a relocation */ elf64_addr r_offset; /** Information about the relocation, related symbol and type */ elf64_xword r_info; }; /** * @brief Relocation entry for 64-bit ELFs with addend. * * This structure stores information describing a relocation to be performed. */ struct elf64_rela { /** Offset in the section to perform a relocation */ elf64_addr r_offset; /** Information about the relocation, related symbol and type */ elf64_xword r_info; /** Offset to be applied to the symbol address */ elf64_sxword r_addend; }; /** @brief Relocation symbol from r_info * * @param i Value of r_info */ #define ELF64_R_SYM(i) ((i) >> 32) /** * @brief Relocation type from r_info * * @param i Value of r_info */ #define ELF64_R_TYPE(i) ((i) & 0xffffffff) /** * Relocation names (should be moved to arch-specific files) * @cond ignore */ #define R_386_NONE 0 #define R_386_32 1 #define R_386_PC32 2 #define R_386_GOT32 3 #define R_386_PLT32 4 #define R_386_COPY 5 #define R_386_GLOB_DAT 6 #define R_386_JMP_SLOT 7 #define R_386_RELATIVE 8 #define R_386_GOTOFF 9 #define R_ARM_NONE 0 #define R_ARM_PC24 1 #define R_ARM_ABS32 2 #define R_ARM_REL32 3 #define R_ARM_COPY 20 #define R_ARM_GLOB_DAT 21 #define R_ARM_JUMP_SLOT 22 #define R_ARM_RELATIVE 23 #define R_ARM_CALL 28 #define R_ARM_JUMP24 29 #define R_ARM_TARGET1 38 #define R_ARM_V4BX 40 #define R_ARM_PREL31 42 #define R_ARM_MOVW_ABS_NC 43 #define R_ARM_MOVT_ABS 44 #define R_ARM_MOVW_PREL_NC 45 #define R_ARM_MOVT_PREL 46 #define R_ARM_ALU_PC_G0_NC 57 #define R_ARM_ALU_PC_G1_NC 59 #define R_ARM_LDR_PC_G2 63 #define R_ARM_THM_CALL 10 #define R_ARM_THM_JUMP24 30 #define R_ARM_THM_MOVW_ABS_NC 47 #define R_ARM_THM_MOVT_ABS 48 #define R_ARM_THM_MOVW_PREL_NC 49 #define R_ARM_THM_MOVT_PREL 50 #define R_XTENSA_NONE 0 #define R_XTENSA_32 1 #define R_XTENSA_SLOT0_OP 20 /** @endcond */ /** * Dynamic features currently not used by LLEXT * @cond ignore */ /** * @brief Program header(32-bit) */ struct elf32_phdr { elf32_word p_type; /**< Type of segment */ elf32_off p_offset; /**< Offset in file */ elf32_addr p_vaddr; /**< Virtual address in memory */ elf32_addr p_paddr; /**< Physical address (usually reserved) */ elf32_word p_filesz; /**< Size of segment in file */ elf32_word p_memsz; /**< Size of segment in memory */ elf32_word p_flags; /**< Segment flags */ elf32_word p_align; /**< Alignment of segment */ }; /** * @brief Program header(64-bit) */ struct elf64_phdr { elf64_word p_type; /**< Type of segment */ elf64_off p_offset; /**< Offset in file */ elf64_addr p_vaddr; /**< Virtual address in memory */ elf64_addr p_paddr; /**< Physical address (usually reserved) */ elf64_xword p_filesz; /**< Size of segment in file */ elf64_xword p_memsz; /**< Size of segment in memory */ elf64_word p_flags; /**< Segment flags */ elf64_xword p_align; /**< Alignment of segment */ }; /** * @brief Program segment type */ #define PT_LOAD 1 /** * @brief Dynamic section entry(32-bit) */ struct elf32_dyn { elf32_sword d_tag; /**< Entry tag */ union { elf32_word d_val; /**< Integer value */ elf32_addr d_ptr; /**< Address value */ } d_un; }; /** * @brief Dynamic section entry(64-bit) */ struct elf64_dyn { elf64_sxword d_tag; /**< Entry tag */ union { elf64_xword d_val; /**< Integer value */ elf64_addr d_ptr; /**< Address value */ } d_un; }; /** @endcond */ #if defined(CONFIG_64BIT) || defined(__DOXYGEN__) /** Machine sized elf header structure */ typedef struct elf64_ehdr elf_ehdr_t; /** Machine sized section header structure */ typedef struct elf64_shdr elf_shdr_t; /** Machine sized program header structure */ typedef struct elf64_phdr elf_phdr_t; /** Machine sized program address */ typedef elf64_addr elf_addr; /** Machine sized small integer */ typedef elf64_half elf_half; /** Machine sized integer */ typedef elf64_xword elf_word; /** Machine sized relocation struct */ typedef struct elf64_rel elf_rel_t; /** Machine sized relocation struct with addend */ typedef struct elf64_rela elf_rela_t; /** Machine sized symbol struct */ typedef struct elf64_sym elf_sym_t; /** Machine sized macro alias for obtaining a relocation symbol */ #define ELF_R_SYM ELF64_R_SYM /** Machine sized macro alias for obtaining a relocation type */ #define ELF_R_TYPE ELF64_R_TYPE /** Machine sized macro alias for obtaining a symbol bind */ #define ELF_ST_BIND ELF64_ST_BIND /** Machine sized macro alias for obtaining a symbol type */ #define ELF_ST_TYPE ELF64_ST_TYPE #else /** Machine sized elf header structure */ typedef struct elf32_ehdr elf_ehdr_t; /** Machine sized section header structure */ typedef struct elf32_shdr elf_shdr_t; /** Machine sized program header structure */ typedef struct elf32_phdr elf_phdr_t; /** Machine sized program address */ typedef elf32_addr elf_addr; /** Machine sized small integer */ typedef elf32_half elf_half; /** Machine sized integer */ typedef elf32_word elf_word; /** Machine sized relocation struct */ typedef struct elf32_rel elf_rel_t; /** Machine sized relocation struct with addend */ typedef struct elf32_rela elf_rela_t; /** Machine sized symbol struct */ typedef struct elf32_sym elf_sym_t; /** Machine sized macro alias for obtaining a relocation symbol */ #define ELF_R_SYM ELF32_R_SYM /** Machine sized macro alias for obtaining a relocation type */ #define ELF_R_TYPE ELF32_R_TYPE /** Machine sized macro alias for obtaining a symbol bind */ #define ELF_ST_BIND ELF32_ST_BIND /** Machine sized macro alias for obtaining a symbol type */ #define ELF_ST_TYPE ELF32_ST_TYPE #endif #ifdef __cplusplus } #endif /** * @} */ #endif /* ZEPHYR_LLEXT_ELF_H */ ```
/content/code_sandbox/include/zephyr/llext/elf.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
3,971
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_LORAWAN_LORAWAN_H_ #define ZEPHYR_INCLUDE_LORAWAN_LORAWAN_H_ /** * @file * @brief Public LoRaWAN APIs * @defgroup lorawan_api LoRaWAN APIs * @since 2.5 * @version 0.1.0 * @ingroup connectivity * @{ */ #include <zephyr/device.h> #include <zephyr/sys/slist.h> #ifdef __cplusplus extern "C" { #endif /** * @brief LoRaWAN class types. */ enum lorawan_class { LORAWAN_CLASS_A = 0x00, /**< Class A device */ LORAWAN_CLASS_B = 0x01, /**< Class B device */ LORAWAN_CLASS_C = 0x02, /**< Class C device */ }; /** * @brief LoRaWAN activation types. */ enum lorawan_act_type { LORAWAN_ACT_OTAA = 0, /**< Over-the-Air Activation (OTAA) */ LORAWAN_ACT_ABP, /**< Activation by Personalization (ABP) */ }; /** * @brief LoRaWAN channels mask sizes. */ enum lorawan_channels_mask_size { LORAWAN_CHANNELS_MASK_SIZE_AS923 = 1, /**< Region AS923 mask size */ LORAWAN_CHANNELS_MASK_SIZE_AU915 = 6, /**< Region AU915 mask size */ LORAWAN_CHANNELS_MASK_SIZE_CN470 = 6, /**< Region CN470 mask size */ LORAWAN_CHANNELS_MASK_SIZE_CN779 = 1, /**< Region CN779 mask size */ LORAWAN_CHANNELS_MASK_SIZE_EU433 = 1, /**< Region EU433 mask size */ LORAWAN_CHANNELS_MASK_SIZE_EU868 = 1, /**< Region EU868 mask size */ LORAWAN_CHANNELS_MASK_SIZE_KR920 = 1, /**< Region KR920 mask size */ LORAWAN_CHANNELS_MASK_SIZE_IN865 = 1, /**< Region IN865 mask size */ LORAWAN_CHANNELS_MASK_SIZE_US915 = 6, /**< Region US915 mask size */ LORAWAN_CHANNELS_MASK_SIZE_RU864 = 1, /**< Region RU864 mask size */ }; /** * @brief LoRaWAN datarate types. */ enum lorawan_datarate { LORAWAN_DR_0 = 0, /**< DR0 data rate */ LORAWAN_DR_1, /**< DR1 data rate */ LORAWAN_DR_2, /**< DR2 data rate */ LORAWAN_DR_3, /**< DR3 data rate */ LORAWAN_DR_4, /**< DR4 data rate */ LORAWAN_DR_5, /**< DR5 data rate */ LORAWAN_DR_6, /**< DR6 data rate */ LORAWAN_DR_7, /**< DR7 data rate */ LORAWAN_DR_8, /**< DR8 data rate */ LORAWAN_DR_9, /**< DR9 data rate */ LORAWAN_DR_10, /**< DR10 data rate */ LORAWAN_DR_11, /**< DR11 data rate */ LORAWAN_DR_12, /**< DR12 data rate */ LORAWAN_DR_13, /**< DR13 data rate */ LORAWAN_DR_14, /**< DR14 data rate */ LORAWAN_DR_15, /**< DR15 data rate */ }; /** * @brief LoRaWAN region types. */ enum lorawan_region { LORAWAN_REGION_AS923, /**< Asia 923 MHz frequency band */ LORAWAN_REGION_AU915, /**< Australia 915 MHz frequency band */ LORAWAN_REGION_CN470, /**< China 470 MHz frequency band */ LORAWAN_REGION_CN779, /**< China 779 MHz frequency band */ LORAWAN_REGION_EU433, /**< Europe 433 MHz frequency band */ LORAWAN_REGION_EU868, /**< Europe 868 MHz frequency band */ LORAWAN_REGION_KR920, /**< South Korea 920 MHz frequency band */ LORAWAN_REGION_IN865, /**< India 865 MHz frequency band */ LORAWAN_REGION_US915, /**< United States 915 MHz frequency band */ LORAWAN_REGION_RU864, /**< Russia 864 MHz frequency band */ }; /** * @brief LoRaWAN message types. */ enum lorawan_message_type { LORAWAN_MSG_UNCONFIRMED = 0, /**< Unconfirmed message */ LORAWAN_MSG_CONFIRMED, /**< Confirmed message */ }; /** * @brief LoRaWAN join parameters for over-the-Air activation (OTAA) * * Note that all of the fields use LoRaWAN 1.1 terminology. * * All parameters are optional if a secure element is present in which * case the values stored in the secure element will be used instead. */ struct lorawan_join_otaa { /** Join EUI */ uint8_t *join_eui; /** Network Key */ uint8_t *nwk_key; /** Application Key */ uint8_t *app_key; /** * Device Nonce * * Starting with LoRaWAN 1.0.4 the DevNonce must be monotonically * increasing for each OTAA join with the same EUI. The DevNonce * should be stored in non-volatile memory by the application. */ uint16_t dev_nonce; }; /** * @brief LoRaWAN join parameters for activation by personalization (ABP) */ struct lorawan_join_abp { /** Device address on the network */ uint32_t dev_addr; /** Application session key */ uint8_t *app_skey; /** Network session key */ uint8_t *nwk_skey; /** Application EUI */ uint8_t *app_eui; }; /** * @brief LoRaWAN join parameters */ struct lorawan_join_config { /** Join parameters */ union { struct lorawan_join_otaa otaa; /**< OTAA join parameters */ struct lorawan_join_abp abp; /**< ABP join parameters */ }; /** Device EUI. Optional if a secure element is present. */ uint8_t *dev_eui; /** Activation mode */ enum lorawan_act_type mode; }; /** Flag to indicate receiving on any port */ #define LW_RECV_PORT_ANY UINT16_MAX /** * @brief LoRaWAN downlink callback parameters */ struct lorawan_downlink_cb { /** * @brief Port to handle messages for. * * - Port 0: TX packet acknowledgements * - Ports 1-255: Standard downlink port * - LW_RECV_PORT_ANY: All downlinks */ uint16_t port; /** * @brief Callback function to run on downlink data * * @note Callbacks are run on the system workqueue, * and should therefore be as short as possible. * * @param port Port message was sent on * @param data_pending Network server has more downlink packets pending * @param rssi Received signal strength in dBm * @param snr Signal to Noise ratio in dBm * @param len Length of data received, will be 0 for ACKs * @param data Data received, will be NULL for ACKs */ void (*cb)(uint8_t port, bool data_pending, int16_t rssi, int8_t snr, uint8_t len, const uint8_t *data); /** Node for callback list */ sys_snode_t node; }; /** * @brief Defines the battery level callback handler function signature. * * @retval 0 if the node is connected to an external power source * @retval 1..254 battery level, where 1 is the minimum and 254 is the maximum value * @retval 255 if the node was not able to measure the battery level */ typedef uint8_t (*lorawan_battery_level_cb_t)(void); /** * @brief Defines the datarate changed callback handler function signature. * * @param dr Updated datarate. */ typedef void (*lorawan_dr_changed_cb_t)(enum lorawan_datarate dr); /** * @brief Register a battery level callback function. * * Provide the LoRaWAN stack with a function to be called whenever a battery * level needs to be read. * * Should no callback be provided the lorawan backend will report 255. * * @param cb Pointer to the battery level function */ void lorawan_register_battery_level_callback(lorawan_battery_level_cb_t cb); /** * @brief Register a callback to be run on downlink packets * * @param cb Pointer to structure containing callback parameters */ void lorawan_register_downlink_callback(struct lorawan_downlink_cb *cb); /** * @brief Register a callback to be called when the datarate changes * * The callback is called once upon successfully joining a network and again * each time the datarate changes due to ADR. * * @param cb Pointer to datarate update callback */ void lorawan_register_dr_changed_callback(lorawan_dr_changed_cb_t cb); /** * @brief Join the LoRaWAN network * * Join the LoRaWAN network using OTAA or AWB. * * @param config Configuration to be used * * @return 0 if successful, negative errno code if failure */ int lorawan_join(const struct lorawan_join_config *config); /** * @brief Start the LoRaWAN stack * * This function need to be called before joining the network. * * @return 0 if successful, negative errno code if failure */ int lorawan_start(void); /** * @brief Send data to the LoRaWAN network * * Send data to the connected LoRaWAN network. * * @param port Port to be used for sending data. Must be set if the * payload is not empty. * @param data Data buffer to be sent * @param len Length of the buffer to be sent. Maximum length of this * buffer is 255 bytes but the actual payload size varies with * region and datarate. * @param type Specifies if the message shall be confirmed or unconfirmed. * Must be one of @ref lorawan_message_type. * * @return 0 if successful, negative errno code if failure */ int lorawan_send(uint8_t port, uint8_t *data, uint8_t len, enum lorawan_message_type type); /** * @brief Set the current device class * * Change the current device class. This function may be called before * or after a network connection has been established. * * @param dev_class New device class * * @return 0 if successful, negative errno code if failure */ int lorawan_set_class(enum lorawan_class dev_class); /** * @brief Set the number of tries used for transmissions * * @param tries Number of tries to be used * * @return 0 if successful, negative errno code if failure */ int lorawan_set_conf_msg_tries(uint8_t tries); /** * @brief Enable Adaptive Data Rate (ADR) * * Control whether adaptive data rate (ADR) is enabled. When ADR is enabled, * the data rate is treated as a default data rate that will be used if the * ADR algorithm has not established a data rate. ADR should normally only * be enabled for devices with stable RF conditions (i.e., devices in a mostly * static location). * * @param enable Enable or Disable adaptive data rate. */ void lorawan_enable_adr(bool enable); /** * @brief Set the channels mask. * * Change the default channels mask. When mask is not changed, all the channels * can be used for data transmission. Some Network Servers don't use all the channels, * in this case, the channels mask must be provided. * * @param channels_mask Buffer with channels mask to be used. * @param channels_mask_size Size of channels mask buffer. * * @retval 0 successful * @retval -EINVAL channels mask or channels mask size is wrong */ int lorawan_set_channels_mask(uint16_t *channels_mask, size_t channels_mask_size); /** * @brief Set the default data rate * * Change the default data rate. * * @param dr Data rate used for transmissions * * @return 0 if successful, negative errno code if failure */ int lorawan_set_datarate(enum lorawan_datarate dr); /** * @brief Get the minimum possible datarate * * The minimum possible datarate may change in response to a TxParamSetupReq * command from the network server. * * @return Minimum possible data rate */ enum lorawan_datarate lorawan_get_min_datarate(void); /** * @brief Get the current payload sizes * * Query the current payload sizes. The maximum payload size varies with * datarate, while the current payload size can be less due to MAC layer * commands which are inserted into uplink packets. * * @param max_next_payload_size Maximum payload size for the next transmission * @param max_payload_size Maximum payload size for this datarate */ void lorawan_get_payload_sizes(uint8_t *max_next_payload_size, uint8_t *max_payload_size); /** * @brief Set the region and frequency to be used * * Control the LoRa region and frequency settings. This should be called before * @a lorawan_start(). If you only have support for a single region selected via * Kconfig, this function does not need to be called at all. * * @param region The region to be selected * @return 0 if successful, negative errno otherwise */ int lorawan_set_region(enum lorawan_region region); #ifdef CONFIG_LORAWAN_APP_CLOCK_SYNC /** * @brief Run Application Layer Clock Synchronization service * * This service sends out its current time in a regular interval (configurable * via Kconfig) and receives a correction offset from the application server if * the clock deviation is considered too large. * * Clock synchronization is required for firmware upgrades over multicast * sessions, but can also be used independent of a FUOTA process. * * @return 0 if successful, negative errno otherwise. */ int lorawan_clock_sync_run(void); /** * @brief Retrieve the current synchronized time * * This function uses the GPS epoch format, as used in all LoRaWAN services. * * The GPS epoch started on 1980-01-06T00:00:00Z, but has since diverged * from UTC, as it does not consider corrections like leap seconds. * * @param gps_time Synchronized time in GPS epoch format truncated to 32-bit. * * @return 0 if successful, -EAGAIN if the clock is not yet synchronized. */ int lorawan_clock_sync_get(uint32_t *gps_time); #endif /* CONFIG_LORAWAN_APP_CLOCK_SYNC */ #ifdef CONFIG_LORAWAN_FRAG_TRANSPORT /** * @brief Run Fragmented Data Block Transport service * * This service receives fragmented data (usually firmware images) and * stores them in the image-1 flash partition. * * After all fragments have been received, the provided callback is invoked. * * @param transport_finished_cb Callback for notification of finished data transfer. * * @return 0 if successful, negative errno otherwise. */ int lorawan_frag_transport_run(void (*transport_finished_cb)(void)); #endif /* CONFIG_LORAWAN_FRAG_TRANSPORT */ #ifdef __cplusplus } #endif /** * @} */ #endif /* ZEPHYR_INCLUDE_LORAWAN_LORAWAN_H_ */ ```
/content/code_sandbox/include/zephyr/lorawan/lorawan.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
3,343
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_DATA_JWT_H_ #define ZEPHYR_INCLUDE_DATA_JWT_H_ #include <zephyr/types.h> #include <stdbool.h> #ifdef __cplusplus extern "C" { #endif /** * @brief JSON Web Token (JWT) * @defgroup jwt JSON Web Token (JWT) * @ingroup json * @{ */ /** * @brief JWT data tracking. * * JSON Web Tokens contain several sections, each encoded in base-64. * This structure tracks the token as it is being built, including * limits on the amount of available space. It should be initialized * with jwt_init(). */ struct jwt_builder { /** The base of the buffer we are writing to. */ char *base; /** The place in this buffer where we are currently writing. */ char *buf; /** The length remaining to write. */ size_t len; /** * Flag that is set if we try to write past the end of the * buffer. If set, the token is not valid. */ bool overflowed; /* Pending bytes yet to be converted to base64. */ unsigned char wip[3]; /* Number of pending bytes. */ int pending; }; /** * @brief Initialize the JWT builder. * * Initialize the given JWT builder for the creation of a fresh token. * The buffer size should at least be as long as JWT_BUILDER_MAX_SIZE * returns. * * @param builder The builder to initialize. * @param buffer The buffer to write the token to. * @param buffer_size The size of this buffer. The token will be NULL * terminated, which needs to be allowed for in this size. * * @retval 0 Success * @retval -ENOSPC Buffer is insufficient to initialize */ int jwt_init_builder(struct jwt_builder *builder, char *buffer, size_t buffer_size); /** * @brief add JWT primary payload. */ int jwt_add_payload(struct jwt_builder *builder, int32_t exp, int32_t iat, const char *aud); /** * @brief Sign the JWT token. */ int jwt_sign(struct jwt_builder *builder, const char *der_key, size_t der_key_len); static inline size_t jwt_payload_len(struct jwt_builder *builder) { return (builder->buf - builder->base); } #ifdef __cplusplus } #endif /** * @} */ #endif /* ZEPHYR_INCLUDE_DATA_JWT_H_ */ ```
/content/code_sandbox/include/zephyr/data/jwt.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
523
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_DATA_NAVIGATION_H_ #define ZEPHYR_INCLUDE_DATA_NAVIGATION_H_ #include <zephyr/types.h> /** * @brief Navigation utilities * @defgroup navigation Navigation * @ingroup utilities * @{ */ /** * @brief Navigation data structure * * @details The structure describes the momentary navigation details of a * point relative to a sphere (commonly Earth) */ struct navigation_data { /** Latitudal position in nanodegrees (0 to +-180E9) */ int64_t latitude; /** Longitudal position in nanodegrees (0 to +-180E9) */ int64_t longitude; /** Bearing angle in millidegrees (0 to 360E3) */ uint32_t bearing; /** Speed in millimeters per second */ uint32_t speed; /** Altitude in millimeters */ int32_t altitude; }; /** * @brief Calculate the distance between two navigation points along the * surface of the sphere they are relative to. * * @param distance Destination for calculated distance in millimeters * @param p1 First navigation point * @param p2 Second navigation point * * @return 0 if successful * @return -EINVAL if either navigation point is invalid */ int navigation_distance(uint64_t *distance, const struct navigation_data *p1, const struct navigation_data *p2); /** * @brief Calculate the bearing from one navigation point to another * * @param bearing Destination for calculated bearing angle in millidegrees * @param from First navigation point * @param to Second navigation point * * @return 0 if successful * @return -EINVAL if either navigation point is invalid */ int navigation_bearing(uint32_t *bearing, const struct navigation_data *from, const struct navigation_data *to); /** * @} */ #endif /* ZEPHYR_INCLUDE_DATA_NAVIGATION_H_ */ ```
/content/code_sandbox/include/zephyr/data/navigation.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
409
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_DATA_JSON_H_ #define ZEPHYR_INCLUDE_DATA_JSON_H_ #include <zephyr/sys/util.h> #include <stddef.h> #include <zephyr/toolchain.h> #include <zephyr/types.h> #include <sys/types.h> #ifdef __cplusplus extern "C" { #endif /** * @defgroup json JSON * @ingroup utilities * @{ */ enum json_tokens { /* Before changing this enum, ensure that its maximum * value is still within 7 bits. See comment next to the * declaration of `type` in struct json_obj_descr. */ JSON_TOK_NONE = '_', JSON_TOK_OBJECT_START = '{', JSON_TOK_OBJECT_END = '}', JSON_TOK_ARRAY_START = '[', JSON_TOK_ARRAY_END = ']', JSON_TOK_STRING = '"', JSON_TOK_COLON = ':', JSON_TOK_COMMA = ',', JSON_TOK_NUMBER = '0', JSON_TOK_FLOAT = '1', JSON_TOK_OPAQUE = '2', JSON_TOK_OBJ_ARRAY = '3', JSON_TOK_ENCODED_OBJ = '4', JSON_TOK_INT64 = '5', JSON_TOK_TRUE = 't', JSON_TOK_FALSE = 'f', JSON_TOK_NULL = 'n', JSON_TOK_ERROR = '!', JSON_TOK_EOF = '\0', }; struct json_token { enum json_tokens type; char *start; char *end; }; struct json_lexer { void *(*state)(struct json_lexer *lex); char *start; char *pos; char *end; struct json_token tok; }; struct json_obj { struct json_lexer lex; }; struct json_obj_token { char *start; size_t length; }; struct json_obj_descr { const char *field_name; /* Alignment can be 1, 2, 4, or 8. The macros to create * a struct json_obj_descr will store the alignment's * power of 2 in order to keep this value in the 0-3 range * and thus use only 2 bits. */ uint32_t align_shift : 2; /* 127 characters is more than enough for a field name. */ uint32_t field_name_len : 7; /* Valid values here (enum json_tokens): JSON_TOK_STRING, * JSON_TOK_NUMBER, JSON_TOK_TRUE, JSON_TOK_FALSE, * JSON_TOK_OBJECT_START, JSON_TOK_ARRAY_START. (All others * ignored.) Maximum value is '}' (125), so this has to be 7 bits * long. */ uint32_t type : 7; /* 65535 bytes is more than enough for many JSON payloads. */ uint32_t offset : 16; union { struct { const struct json_obj_descr *sub_descr; size_t sub_descr_len; } object; struct { const struct json_obj_descr *element_descr; size_t n_elements; } array; }; }; /** * @brief Function pointer type to append bytes to a buffer while * encoding JSON data. * * @param bytes Contents to write to the output * @param len Number of bytes to append to output * @param data User-provided pointer * * @return This callback function should return a negative number on * error (which will be propagated to the return value of * json_obj_encode()), or 0 on success. */ typedef int (*json_append_bytes_t)(const char *bytes, size_t len, void *data); #define Z_ALIGN_SHIFT(type) (__alignof__(type) == 1 ? 0 : \ __alignof__(type) == 2 ? 1 : \ __alignof__(type) == 4 ? 2 : 3) /** * @brief Helper macro to declare a descriptor for supported primitive * values. * * @param struct_ Struct packing the values * @param field_name_ Field name in the struct * @param type_ Token type for JSON value corresponding to a primitive * type. Must be one of: JSON_TOK_STRING for strings, JSON_TOK_NUMBER * for numbers, JSON_TOK_TRUE (or JSON_TOK_FALSE) for booleans. * * Here's an example of use: * * struct foo { * int32_t some_int; * }; * * struct json_obj_descr foo[] = { * JSON_OBJ_DESCR_PRIM(struct foo, some_int, JSON_TOK_NUMBER), * }; */ #define JSON_OBJ_DESCR_PRIM(struct_, field_name_, type_) \ { \ .field_name = (#field_name_), \ .align_shift = Z_ALIGN_SHIFT(struct_), \ .field_name_len = sizeof(#field_name_) - 1, \ .type = type_, \ .offset = offsetof(struct_, field_name_), \ } /** * @brief Helper macro to declare a descriptor for an object value * * @param struct_ Struct packing the values * @param field_name_ Field name in the struct * @param sub_descr_ Array of json_obj_descr describing the subobject * * Here's an example of use: * * struct nested { * int32_t foo; * struct { * int32_t baz; * } bar; * }; * * struct json_obj_descr nested_bar[] = { * { ... declare bar.baz descriptor ... }, * }; * struct json_obj_descr nested[] = { * { ... declare foo descriptor ... }, * JSON_OBJ_DESCR_OBJECT(struct nested, bar, nested_bar), * }; */ #define JSON_OBJ_DESCR_OBJECT(struct_, field_name_, sub_descr_) \ { \ .field_name = (#field_name_), \ .align_shift = Z_ALIGN_SHIFT(struct_), \ .field_name_len = (sizeof(#field_name_) - 1), \ .type = JSON_TOK_OBJECT_START, \ .offset = offsetof(struct_, field_name_), \ .object = { \ .sub_descr = sub_descr_, \ .sub_descr_len = ARRAY_SIZE(sub_descr_), \ }, \ } /** * @internal @brief Helper macro to declare an element descriptor * * @param struct_ Struct packing the values * @param len_field_ Field name in the struct for the number of elements * in the array * @param elem_type_ Element type, must be a primitive type * @param union_ Optional macro argument containing array or object descriptor */ #define Z_JSON_ELEMENT_DESCR(struct_, len_field_, elem_type_, union_) \ (const struct json_obj_descr[]) \ { \ { \ .align_shift = Z_ALIGN_SHIFT(struct_), \ .type = elem_type_, \ .offset = offsetof(struct_, len_field_), \ union_ \ } \ } /** * @internal @brief Helper macro to declare an array descriptor * * @param elem_descr_ Element descriptor, pointer to a descriptor array * @param elem_descr_len_ Number of elements in elem_descr_ */ #define Z_JSON_DESCR_ARRAY(elem_descr_, elem_descr_len_) \ { \ .array = { \ .element_descr = elem_descr_, \ .n_elements = elem_descr_len_, \ }, \ } /** * @internal @brief Helper macro to declare an object descriptor * * @param elem_descr_ Element descriptor, pointer to a descriptor array * @param elem_descr_len_ Number of elements in elem_descr_ */ #define Z_JSON_DESCR_OBJ(elem_descr_, elem_descr_len_) \ { \ .object = { \ .sub_descr = elem_descr_, \ .sub_descr_len = elem_descr_len_, \ }, \ } /** * @brief Helper macro to declare a descriptor for an array of primitives * * @param struct_ Struct packing the values * @param field_name_ Field name in the struct * @param max_len_ Maximum number of elements in array * @param len_field_ Field name in the struct for the number of elements * in the array * @param elem_type_ Element type, must be a primitive type * * Here's an example of use: * * struct example { * int32_t foo[10]; * size_t foo_len; * }; * * struct json_obj_descr array[] = { * JSON_OBJ_DESCR_ARRAY(struct example, foo, 10, foo_len, * JSON_TOK_NUMBER) * }; */ #define JSON_OBJ_DESCR_ARRAY(struct_, field_name_, max_len_, \ len_field_, elem_type_) \ { \ .field_name = (#field_name_), \ .align_shift = Z_ALIGN_SHIFT(struct_), \ .field_name_len = sizeof(#field_name_) - 1, \ .type = JSON_TOK_ARRAY_START, \ .offset = offsetof(struct_, field_name_), \ .array = { \ .element_descr = Z_JSON_ELEMENT_DESCR(struct_, len_field_, \ elem_type_,), \ .n_elements = (max_len_), \ }, \ } /** * @brief Helper macro to declare a descriptor for an array of objects * * @param struct_ Struct packing the values * @param field_name_ Field name in the struct containing the array * @param max_len_ Maximum number of elements in the array * @param len_field_ Field name in the struct for the number of elements * in the array * @param elem_descr_ Element descriptor, pointer to a descriptor array * @param elem_descr_len_ Number of elements in elem_descr_ * * Here's an example of use: * * struct person_height { * const char *name; * int32_t height; * }; * * struct people_heights { * struct person_height heights[10]; * size_t heights_len; * }; * * struct json_obj_descr person_height_descr[] = { * JSON_OBJ_DESCR_PRIM(struct person_height, name, JSON_TOK_STRING), * JSON_OBJ_DESCR_PRIM(struct person_height, height, JSON_TOK_NUMBER), * }; * * struct json_obj_descr array[] = { * JSON_OBJ_DESCR_OBJ_ARRAY(struct people_heights, heights, 10, * heights_len, person_height_descr, * ARRAY_SIZE(person_height_descr)), * }; */ #define JSON_OBJ_DESCR_OBJ_ARRAY(struct_, field_name_, max_len_, \ len_field_, elem_descr_, elem_descr_len_) \ { \ .field_name = (#field_name_), \ .align_shift = Z_ALIGN_SHIFT(struct_), \ .field_name_len = sizeof(#field_name_) - 1, \ .type = JSON_TOK_ARRAY_START, \ .offset = offsetof(struct_, field_name_), \ .array = { \ .element_descr = Z_JSON_ELEMENT_DESCR(struct_, len_field_, \ JSON_TOK_OBJECT_START, \ Z_JSON_DESCR_OBJ(elem_descr_, elem_descr_len_)), \ .n_elements = (max_len_), \ }, \ } /** * @brief Helper macro to declare a descriptor for an array of array * * @param struct_ Struct packing the values * @param field_name_ Field name in the struct containing the array * @param max_len_ Maximum number of elements in the array * @param len_field_ Field name in the struct for the number of elements * in the array * @param elem_descr_ Element descriptor, pointer to a descriptor array * @param elem_descr_len_ Number of elements in elem_descr_ * * Here's an example of use: * * struct person_height { * const char *name; * int32_t height; * }; * * struct person_heights_array { * struct person_height heights; * } * * struct people_heights { * struct person_height_array heights[10]; * size_t heights_len; * }; * * struct json_obj_descr person_height_descr[] = { * JSON_OBJ_DESCR_PRIM(struct person_height, name, JSON_TOK_STRING), * JSON_OBJ_DESCR_PRIM(struct person_height, height, JSON_TOK_NUMBER), * }; * * struct json_obj_descr person_height_array_descr[] = { * JSON_OBJ_DESCR_OBJECT(struct person_heights_array, * heights, person_height_descr), * }; * * struct json_obj_descr array_array[] = { * JSON_OBJ_DESCR_ARRAY_ARRAY(struct people_heights, heights, 10, * heights_len, person_height_array_descr, * ARRAY_SIZE(person_height_array_descr)), * }; */ #define JSON_OBJ_DESCR_ARRAY_ARRAY(struct_, field_name_, max_len_, len_field_, \ elem_descr_, elem_descr_len_) \ { \ .field_name = (#field_name_), \ .align_shift = Z_ALIGN_SHIFT(struct_), \ .field_name_len = sizeof(#field_name_) - 1, \ .type = JSON_TOK_ARRAY_START, \ .offset = offsetof(struct_, field_name_), \ .array = { \ .element_descr = Z_JSON_ELEMENT_DESCR( \ struct_, len_field_, JSON_TOK_ARRAY_START, \ Z_JSON_DESCR_ARRAY( \ elem_descr_, \ 1 + ZERO_OR_COMPILE_ERROR(elem_descr_len_ == 1))), \ .n_elements = (max_len_), \ }, \ } /** * @brief Variant of JSON_OBJ_DESCR_ARRAY_ARRAY that can be used when the * structure and JSON field names differ. * * This is useful when the JSON field is not a valid C identifier. * * @param struct_ Struct packing the values * @param json_field_name_ String, field name in JSON strings * @param struct_field_name_ Field name in the struct containing the array * @param max_len_ Maximum number of elements in the array * @param len_field_ Field name in the struct for the number of elements * in the array * @param elem_descr_ Element descriptor, pointer to a descriptor array * @param elem_descr_len_ Number of elements in elem_descr_ * * @see JSON_OBJ_DESCR_ARRAY_ARRAY */ #define JSON_OBJ_DESCR_ARRAY_ARRAY_NAMED(struct_, json_field_name_, struct_field_name_, \ max_len_, len_field_, elem_descr_, elem_descr_len_) \ { \ .field_name = (#json_field_name_), \ .align_shift = Z_ALIGN_SHIFT(struct_), \ .field_name_len = sizeof(#json_field_name_) - 1, \ .type = JSON_TOK_ARRAY_START, \ .offset = offsetof(struct_, struct_field_name_), \ .array = { \ .element_descr = Z_JSON_ELEMENT_DESCR( \ struct_, len_field_, JSON_TOK_ARRAY_START, \ Z_JSON_DESCR_ARRAY( \ elem_descr_, \ 1 + ZERO_OR_COMPILE_ERROR(elem_descr_len_ == 1))), \ .n_elements = (max_len_), \ }, \ } /** * @brief Variant of JSON_OBJ_DESCR_PRIM that can be used when the * structure and JSON field names differ. * * This is useful when the JSON field is not a valid C identifier. * * @param struct_ Struct packing the values. * @param json_field_name_ String, field name in JSON strings * @param struct_field_name_ Field name in the struct * @param type_ Token type for JSON value corresponding to a primitive * type. * * @see JSON_OBJ_DESCR_PRIM */ #define JSON_OBJ_DESCR_PRIM_NAMED(struct_, json_field_name_, \ struct_field_name_, type_) \ { \ .field_name = (json_field_name_), \ .align_shift = Z_ALIGN_SHIFT(struct_), \ .field_name_len = sizeof(json_field_name_) - 1, \ .type = type_, \ .offset = offsetof(struct_, struct_field_name_), \ } /** * @brief Variant of JSON_OBJ_DESCR_OBJECT that can be used when the * structure and JSON field names differ. * * This is useful when the JSON field is not a valid C identifier. * * @param struct_ Struct packing the values * @param json_field_name_ String, field name in JSON strings * @param struct_field_name_ Field name in the struct * @param sub_descr_ Array of json_obj_descr describing the subobject * * @see JSON_OBJ_DESCR_OBJECT */ #define JSON_OBJ_DESCR_OBJECT_NAMED(struct_, json_field_name_, \ struct_field_name_, sub_descr_) \ { \ .field_name = (json_field_name_), \ .align_shift = Z_ALIGN_SHIFT(struct_), \ .field_name_len = (sizeof(json_field_name_) - 1), \ .type = JSON_TOK_OBJECT_START, \ .offset = offsetof(struct_, struct_field_name_), \ .object = { \ .sub_descr = sub_descr_, \ .sub_descr_len = ARRAY_SIZE(sub_descr_), \ }, \ } /** * @brief Variant of JSON_OBJ_DESCR_ARRAY that can be used when the * structure and JSON field names differ. * * This is useful when the JSON field is not a valid C identifier. * * @param struct_ Struct packing the values * @param json_field_name_ String, field name in JSON strings * @param struct_field_name_ Field name in the struct * @param max_len_ Maximum number of elements in array * @param len_field_ Field name in the struct for the number of elements * in the array * @param elem_type_ Element type, must be a primitive type * * @see JSON_OBJ_DESCR_ARRAY */ #define JSON_OBJ_DESCR_ARRAY_NAMED(struct_, json_field_name_,\ struct_field_name_, max_len_, len_field_, \ elem_type_) \ { \ .field_name = (json_field_name_), \ .align_shift = Z_ALIGN_SHIFT(struct_), \ .field_name_len = sizeof(json_field_name_) - 1, \ .type = JSON_TOK_ARRAY_START, \ .offset = offsetof(struct_, struct_field_name_), \ .array = { \ .element_descr = \ Z_JSON_ELEMENT_DESCR(struct_, len_field_, elem_type_,), \ .n_elements = (max_len_), \ }, \ } /** * @brief Variant of JSON_OBJ_DESCR_OBJ_ARRAY that can be used when * the structure and JSON field names differ. * * This is useful when the JSON field is not a valid C identifier. * * @param struct_ Struct packing the values * @param json_field_name_ String, field name of the array in JSON strings * @param struct_field_name_ Field name in the struct containing the array * @param max_len_ Maximum number of elements in the array * @param len_field_ Field name in the struct for the number of elements * in the array * @param elem_descr_ Element descriptor, pointer to a descriptor array * @param elem_descr_len_ Number of elements in elem_descr_ * * Here's an example of use: * * struct person_height { * const char *name; * int32_t height; * }; * * struct people_heights { * struct person_height heights[10]; * size_t heights_len; * }; * * struct json_obj_descr person_height_descr[] = { * JSON_OBJ_DESCR_PRIM(struct person_height, name, JSON_TOK_STRING), * JSON_OBJ_DESCR_PRIM(struct person_height, height, JSON_TOK_NUMBER), * }; * * struct json_obj_descr array[] = { * JSON_OBJ_DESCR_OBJ_ARRAY_NAMED(struct people_heights, * "people-heights", heights, * 10, heights_len, * person_height_descr, * ARRAY_SIZE(person_height_descr)), * }; */ #define JSON_OBJ_DESCR_OBJ_ARRAY_NAMED(struct_, json_field_name_, \ struct_field_name_, max_len_, \ len_field_, elem_descr_, \ elem_descr_len_) \ { \ .field_name = json_field_name_, \ .align_shift = Z_ALIGN_SHIFT(struct_), \ .field_name_len = sizeof(json_field_name_) - 1, \ .type = JSON_TOK_ARRAY_START, \ .offset = offsetof(struct_, struct_field_name_), \ .array = { \ .element_descr = Z_JSON_ELEMENT_DESCR(struct_, len_field_, \ JSON_TOK_OBJECT_START, \ Z_JSON_DESCR_OBJ(elem_descr_, elem_descr_len_)), \ .n_elements = (max_len_), \ }, \ } /** * @brief Parses the JSON-encoded object pointed to by @a json, with * size @a len, according to the descriptor pointed to by @a descr. * Values are stored in a struct pointed to by @a val. Set up the * descriptor like this: * * struct s { int32_t foo; char *bar; } * struct json_obj_descr descr[] = { * JSON_OBJ_DESCR_PRIM(struct s, foo, JSON_TOK_NUMBER), * JSON_OBJ_DESCR_PRIM(struct s, bar, JSON_TOK_STRING), * }; * * Since this parser is designed for machine-to-machine communications, some * liberties were taken to simplify the design: * (1) strings are not unescaped (but only valid escape sequences are * accepted); * (2) no UTF-8 validation is performed; and * (3) only integer numbers are supported (no strtod() in the minimal libc). * * @param json Pointer to JSON-encoded value to be parsed * @param len Length of JSON-encoded value * @param descr Pointer to the descriptor array * @param descr_len Number of elements in the descriptor array. Must be less * than 63 due to implementation detail reasons (if more fields are * necessary, use two descriptors) * @param val Pointer to the struct to hold the decoded values * * @return < 0 if error, bitmap of decoded fields on success (bit 0 * is set if first field in the descriptor has been properly decoded, etc). */ int64_t json_obj_parse(char *json, size_t len, const struct json_obj_descr *descr, size_t descr_len, void *val); /** * @brief Parses the JSON-encoded array pointed to by @a json, with * size @a len, according to the descriptor pointed to by @a descr. * Values are stored in a struct pointed to by @a val. Set up the * descriptor like this: * * struct s { int32_t foo; char *bar; } * struct json_obj_descr descr[] = { * JSON_OBJ_DESCR_PRIM(struct s, foo, JSON_TOK_NUMBER), * JSON_OBJ_DESCR_PRIM(struct s, bar, JSON_TOK_STRING), * }; * struct a { struct s baz[10]; size_t count; } * struct json_obj_descr array[] = { * JSON_OBJ_DESCR_OBJ_ARRAY(struct a, baz, 10, count, * descr, ARRAY_SIZE(descr)), * }; * * Since this parser is designed for machine-to-machine communications, some * liberties were taken to simplify the design: * (1) strings are not unescaped (but only valid escape sequences are * accepted); * (2) no UTF-8 validation is performed; and * (3) only integer numbers are supported (no strtod() in the minimal libc). * * @param json Pointer to JSON-encoded array to be parsed * @param len Length of JSON-encoded array * @param descr Pointer to the descriptor array * @param val Pointer to the struct to hold the decoded values * * @return 0 if array has been successfully parsed. A negative value * indicates an error (as defined on errno.h). */ int json_arr_parse(char *json, size_t len, const struct json_obj_descr *descr, void *val); /** * @brief Initialize single-object array parsing * * JSON-encoded array data is going to be parsed one object at a time. Data is provided by * @a payload with the size of @a len bytes. * * Function validate that Json Array start is detected and initialize @a json object for * Json object parsing separately. * * @param json Provide storage for parser states. To be used when parsing the array. * @param payload Pointer to JSON-encoded array to be parsed * @param len Length of JSON-encoded array * * @return 0 if array start is detected and initialization is successful or negative error * code in case of failure. */ int json_arr_separate_object_parse_init(struct json_obj *json, char *payload, size_t len); /** * @brief Parse a single object from array. * * Parses the JSON-encoded object pointed to by @a json object array, with * size @a len, according to the descriptor pointed to by @a descr. * * @param json Pointer to JSON-object message state * @param descr Pointer to the descriptor array * @param descr_len Number of elements in the descriptor array. Must be less than 31. * @param val Pointer to the struct to hold the decoded values * * @return < 0 if error, 0 for end of message, bitmap of decoded fields on success (bit 0 * is set if first field in the descriptor has been properly decoded, etc). */ int json_arr_separate_parse_object(struct json_obj *json, const struct json_obj_descr *descr, size_t descr_len, void *val); /** * @brief Escapes the string so it can be used to encode JSON objects * * @param str The string to escape; the escape string is stored the * buffer pointed to by this parameter * @param len Points to a size_t containing the size before and after * the escaping process * @param buf_size The size of buffer str points to * * @return 0 if string has been escaped properly, or -ENOMEM if there * was not enough space to escape the buffer */ ssize_t json_escape(char *str, size_t *len, size_t buf_size); /** * @brief Calculates the JSON-escaped string length * * @param str The string to analyze * @param len String size * * @return The length str would have if it were escaped */ size_t json_calc_escaped_len(const char *str, size_t len); /** * @brief Calculates the string length to fully encode an object * * @param descr Pointer to the descriptor array * @param descr_len Number of elements in the descriptor array * @param val Struct holding the values * * @return Number of bytes necessary to encode the values if >0, * an error code is returned. */ ssize_t json_calc_encoded_len(const struct json_obj_descr *descr, size_t descr_len, const void *val); /** * @brief Calculates the string length to fully encode an array * * @param descr Pointer to the descriptor array * @param val Struct holding the values * * @return Number of bytes necessary to encode the values if >0, * an error code is returned. */ ssize_t json_calc_encoded_arr_len(const struct json_obj_descr *descr, const void *val); /** * @brief Encodes an object in a contiguous memory location * * @param descr Pointer to the descriptor array * @param descr_len Number of elements in the descriptor array * @param val Struct holding the values * @param buffer Buffer to store the JSON data * @param buf_size Size of buffer, in bytes, with space for the terminating * NUL character * * @return 0 if object has been successfully encoded. A negative value * indicates an error (as defined on errno.h). */ int json_obj_encode_buf(const struct json_obj_descr *descr, size_t descr_len, const void *val, char *buffer, size_t buf_size); /** * @brief Encodes an array in a contiguous memory location * * @param descr Pointer to the descriptor array * @param val Struct holding the values * @param buffer Buffer to store the JSON data * @param buf_size Size of buffer, in bytes, with space for the terminating * NUL character * * @return 0 if object has been successfully encoded. A negative value * indicates an error (as defined on errno.h). */ int json_arr_encode_buf(const struct json_obj_descr *descr, const void *val, char *buffer, size_t buf_size); /** * @brief Encodes an object using an arbitrary writer function * * @param descr Pointer to the descriptor array * @param descr_len Number of elements in the descriptor array * @param val Struct holding the values * @param append_bytes Function to append bytes to the output * @param data Data pointer to be passed to the append_bytes callback * function. * * @return 0 if object has been successfully encoded. A negative value * indicates an error. */ int json_obj_encode(const struct json_obj_descr *descr, size_t descr_len, const void *val, json_append_bytes_t append_bytes, void *data); /** * @brief Encodes an array using an arbitrary writer function * * @param descr Pointer to the descriptor array * @param val Struct holding the values * @param append_bytes Function to append bytes to the output * @param data Data pointer to be passed to the append_bytes callback * function. * * @return 0 if object has been successfully encoded. A negative value * indicates an error. */ int json_arr_encode(const struct json_obj_descr *descr, const void *val, json_append_bytes_t append_bytes, void *data); #ifdef __cplusplus } #endif /** * @} */ #endif /* ZEPHYR_INCLUDE_DATA_JSON_H_ */ ```
/content/code_sandbox/include/zephyr/data/json.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
6,384
```objective-c /* * */ /* * Client API in this file is based on mbm_core.c from uC/Modbus Stack. * * uC/Modbus * The Embedded Modbus Stack * * * * This software is subject to an open source license and is distributed by * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. */ /** * @brief MODBUS transport protocol API * @defgroup modbus MODBUS * @ingroup io_interfaces * @{ */ #ifndef ZEPHYR_INCLUDE_MODBUS_H_ #define ZEPHYR_INCLUDE_MODBUS_H_ #include <zephyr/drivers/uart.h> #include <zephyr/sys/slist.h> #ifdef __cplusplus extern "C" { #endif /** Length of MBAP Header */ #define MODBUS_MBAP_LENGTH 7 /** Length of MBAP Header plus function code */ #define MODBUS_MBAP_AND_FC_LENGTH (MODBUS_MBAP_LENGTH + 1) /** @name Modbus exception codes * @{ */ /** No exception */ #define MODBUS_EXC_NONE 0 /** Illegal function code */ #define MODBUS_EXC_ILLEGAL_FC 1 /** Illegal data address */ #define MODBUS_EXC_ILLEGAL_DATA_ADDR 2 /** Illegal data value */ #define MODBUS_EXC_ILLEGAL_DATA_VAL 3 /** Server device failure */ #define MODBUS_EXC_SERVER_DEVICE_FAILURE 4 /** Acknowledge */ #define MODBUS_EXC_ACK 5 /** Server device busy */ #define MODBUS_EXC_SERVER_DEVICE_BUSY 6 /** Memory parity error */ #define MODBUS_EXC_MEM_PARITY_ERROR 8 /** Gateway path unavailable */ #define MODBUS_EXC_GW_PATH_UNAVAILABLE 10 /** Gateway target device failed to respond */ #define MODBUS_EXC_GW_TARGET_FAILED_TO_RESP 11 /** @} */ /** * @brief Frame struct used internally and for raw ADU support. */ struct modbus_adu { /** Transaction Identifier */ uint16_t trans_id; /** Protocol Identifier */ uint16_t proto_id; /** Length of the data only (not the length of unit ID + PDU) */ uint16_t length; /** Unit Identifier */ uint8_t unit_id; /** Function Code */ uint8_t fc; /** Transaction Data */ uint8_t data[CONFIG_MODBUS_BUFFER_SIZE - 4]; /** RTU CRC */ uint16_t crc; }; /** * @brief Coil read (FC01) * * Sends a Modbus message to read the status of coils from a server. * * @param iface Modbus interface index * @param unit_id Modbus unit ID of the server * @param start_addr Coil starting address * @param coil_tbl Pointer to an array of bytes containing the value * of the coils read. * The format is: * * MSB LSB * B7 B6 B5 B4 B3 B2 B1 B0 * ------------------------------------- * coil_tbl[0] #8 #7 #1 * coil_tbl[1] #16 #15 #9 * : * : * * Note that the array that will be receiving the coil * values must be greater than or equal to: * (num_coils - 1) / 8 + 1 * @param num_coils Quantity of coils to read * * @retval 0 If the function was successful */ int modbus_read_coils(const int iface, const uint8_t unit_id, const uint16_t start_addr, uint8_t *const coil_tbl, const uint16_t num_coils); /** * @brief Read discrete inputs (FC02) * * Sends a Modbus message to read the status of discrete inputs from * a server. * * @param iface Modbus interface index * @param unit_id Modbus unit ID of the server * @param start_addr Discrete input starting address * @param di_tbl Pointer to an array that will receive the state * of the discrete inputs. * The format of the array is as follows: * * MSB LSB * B7 B6 B5 B4 B3 B2 B1 B0 * ------------------------------------- * di_tbl[0] #8 #7 #1 * di_tbl[1] #16 #15 #9 * : * : * * Note that the array that will be receiving the discrete * input values must be greater than or equal to: * (num_di - 1) / 8 + 1 * @param num_di Quantity of discrete inputs to read * * @retval 0 If the function was successful */ int modbus_read_dinputs(const int iface, const uint8_t unit_id, const uint16_t start_addr, uint8_t *const di_tbl, const uint16_t num_di); /** * @brief Read holding registers (FC03) * * Sends a Modbus message to read the value of holding registers * from a server. * * @param iface Modbus interface index * @param unit_id Modbus unit ID of the server * @param start_addr Register starting address * @param reg_buf Is a pointer to an array that will receive * the current values of the holding registers from * the server. The array pointed to by 'reg_buf' needs * to be able to hold at least 'num_regs' entries. * @param num_regs Quantity of registers to read * * @retval 0 If the function was successful */ int modbus_read_holding_regs(const int iface, const uint8_t unit_id, const uint16_t start_addr, uint16_t *const reg_buf, const uint16_t num_regs); /** * @brief Read input registers (FC04) * * Sends a Modbus message to read the value of input registers from * a server. * * @param iface Modbus interface index * @param unit_id Modbus unit ID of the server * @param start_addr Register starting address * @param reg_buf Is a pointer to an array that will receive * the current value of the holding registers * from the server. The array pointed to by 'reg_buf' * needs to be able to hold at least 'num_regs' entries. * @param num_regs Quantity of registers to read * * @retval 0 If the function was successful */ int modbus_read_input_regs(const int iface, const uint8_t unit_id, const uint16_t start_addr, uint16_t *const reg_buf, const uint16_t num_regs); /** * @brief Write single coil (FC05) * * Sends a Modbus message to write the value of single coil to a server. * * @param iface Modbus interface index * @param unit_id Modbus unit ID of the server * @param coil_addr Coils starting address * @param coil_state Is the desired state of the coil * * @retval 0 If the function was successful */ int modbus_write_coil(const int iface, const uint8_t unit_id, const uint16_t coil_addr, const bool coil_state); /** * @brief Write single holding register (FC06) * * Sends a Modbus message to write the value of single holding register * to a server unit. * * @param iface Modbus interface index * @param unit_id Modbus unit ID of the server * @param start_addr Coils starting address * @param reg_val Desired value of the holding register * * @retval 0 If the function was successful */ int modbus_write_holding_reg(const int iface, const uint8_t unit_id, const uint16_t start_addr, const uint16_t reg_val); /** * @brief Read diagnostic (FC08) * * Sends a Modbus message to perform a diagnostic function of a server unit. * * @param iface Modbus interface index * @param unit_id Modbus unit ID of the server * @param sfunc Diagnostic sub-function code * @param data Sub-function data * @param data_out Pointer to the data value * * @retval 0 If the function was successful */ int modbus_request_diagnostic(const int iface, const uint8_t unit_id, const uint16_t sfunc, const uint16_t data, uint16_t *const data_out); /** * @brief Write coils (FC15) * * Sends a Modbus message to write to coils on a server unit. * * @param iface Modbus interface index * @param unit_id Modbus unit ID of the server * @param start_addr Coils starting address * @param coil_tbl Pointer to an array of bytes containing the value * of the coils to write. * The format is: * * MSB LSB * B7 B6 B5 B4 B3 B2 B1 B0 * ------------------------------------- * coil_tbl[0] #8 #7 #1 * coil_tbl[1] #16 #15 #9 * : * : * * Note that the array that will be receiving the coil * values must be greater than or equal to: * (num_coils - 1) / 8 + 1 * @param num_coils Quantity of coils to write * * @retval 0 If the function was successful */ int modbus_write_coils(const int iface, const uint8_t unit_id, const uint16_t start_addr, uint8_t *const coil_tbl, const uint16_t num_coils); /** * @brief Write holding registers (FC16) * * Sends a Modbus message to write to integer holding registers * to a server unit. * * @param iface Modbus interface index * @param unit_id Modbus unit ID of the server * @param start_addr Register starting address * @param reg_buf Is a pointer to an array containing * the value of the holding registers to write. * Note that the array containing the register values must * be greater than or equal to 'num_regs' * @param num_regs Quantity of registers to write * * @retval 0 If the function was successful */ int modbus_write_holding_regs(const int iface, const uint8_t unit_id, const uint16_t start_addr, uint16_t *const reg_buf, const uint16_t num_regs); /** * @brief Read floating-point holding registers (FC03) * * Sends a Modbus message to read the value of floating-point * holding registers from a server unit. * * @param iface Modbus interface index * @param unit_id Modbus unit ID of the server * @param start_addr Register starting address * @param reg_buf Is a pointer to an array that will receive * the current values of the holding registers from * the server. The array pointed to by 'reg_buf' needs * to be able to hold at least 'num_regs' entries. * @param num_regs Quantity of registers to read * * @retval 0 If the function was successful */ int modbus_read_holding_regs_fp(const int iface, const uint8_t unit_id, const uint16_t start_addr, float *const reg_buf, const uint16_t num_regs); /** * @brief Write floating-point holding registers (FC16) * * Sends a Modbus message to write to floating-point holding registers * to a server unit. * * @param iface Modbus interface index * @param unit_id Modbus unit ID of the server * @param start_addr Register starting address * @param reg_buf Is a pointer to an array containing * the value of the holding registers to write. * Note that the array containing the register values must * be greater than or equal to 'num_regs' * @param num_regs Quantity of registers to write * * @retval 0 If the function was successful */ int modbus_write_holding_regs_fp(const int iface, const uint8_t unit_id, const uint16_t start_addr, float *const reg_buf, const uint16_t num_regs); /** Modbus Server User Callback structure */ struct modbus_user_callbacks { /** Coil read callback */ int (*coil_rd)(uint16_t addr, bool *state); /** Coil write callback */ int (*coil_wr)(uint16_t addr, bool state); /** Discrete Input read callback */ int (*discrete_input_rd)(uint16_t addr, bool *state); /** Input Register read callback */ int (*input_reg_rd)(uint16_t addr, uint16_t *reg); /** Floating Point Input Register read callback */ int (*input_reg_rd_fp)(uint16_t addr, float *reg); /** Holding Register read callback */ int (*holding_reg_rd)(uint16_t addr, uint16_t *reg); /** Holding Register write callback */ int (*holding_reg_wr)(uint16_t addr, uint16_t reg); /** Floating Point Holding Register read callback */ int (*holding_reg_rd_fp)(uint16_t addr, float *reg); /** Floating Point Holding Register write callback */ int (*holding_reg_wr_fp)(uint16_t addr, float reg); }; /** * @brief Get Modbus interface index according to interface name * * If there is more than one interface, it can be used to clearly * identify interfaces in the application. * * @param iface_name Modbus interface name * * @retval Modbus interface index or negative error value. */ int modbus_iface_get_by_name(const char *iface_name); /** * @brief ADU raw callback function signature * * @param iface Modbus RTU interface index * @param adu Pointer to the RAW ADU struct to send * @param user_data Pointer to the user data * * @retval 0 If transfer was successful */ typedef int (*modbus_raw_cb_t)(const int iface, const struct modbus_adu *adu, void *user_data); /** * @brief Custom function code handler function signature. * * Modbus allows user defined function codes which can be used to extend * the base protocol. These callbacks can also be used to implement * function codes currently not supported by Zephyr's Modbus subsystem. * * If an error occurs during the handling of the request, the handler should * signal this by setting excep_code to a modbus exception code. * * User data pointer can be used to pass state between subsequent calls to * the handler. * * @param iface Modbus interface index * @param rx_adu Pointer to the received ADU struct * @param tx_adu Pointer to the outgoing ADU struct * @param excep_code Pointer to possible exception code * @param user_data Pointer to user data * * @retval true If response should be sent, false otherwise */ typedef bool (*modbus_custom_cb_t)(const int iface, const struct modbus_adu *const rx_adu, struct modbus_adu *const tx_adu, uint8_t *const excep_code, void *const user_data); /** @cond INTERNAL_HIDDEN */ /** * @brief Custom function code definition. */ struct modbus_custom_fc { sys_snode_t node; modbus_custom_cb_t cb; void *user_data; uint8_t fc; uint8_t excep_code; }; /** @endcond INTERNAL_HIDDEN */ /** * @brief Helper macro for initializing custom function code structs */ #define MODBUS_CUSTOM_FC_DEFINE(name, user_cb, user_fc, userdata) \ static struct modbus_custom_fc modbus_cfg_##name = { \ .cb = user_cb, \ .user_data = userdata, \ .fc = user_fc, \ .excep_code = MODBUS_EXC_NONE, \ } /** * @brief Modbus interface mode */ enum modbus_mode { /** Modbus over serial line RTU mode */ MODBUS_MODE_RTU, /** Modbus over serial line ASCII mode */ MODBUS_MODE_ASCII, /** Modbus raw ADU mode */ MODBUS_MODE_RAW, }; /** * @brief Modbus serial line parameter */ struct modbus_serial_param { /** Baudrate of the serial line */ uint32_t baud; /** parity UART's parity setting: * UART_CFG_PARITY_NONE, * UART_CFG_PARITY_EVEN, * UART_CFG_PARITY_ODD */ enum uart_config_parity parity; /** stop_bits_client UART's stop bits setting if in client mode: * UART_CFG_STOP_BITS_0_5, * UART_CFG_STOP_BITS_1, * UART_CFG_STOP_BITS_1_5, * UART_CFG_STOP_BITS_2, */ enum uart_config_stop_bits stop_bits_client; }; /** * @brief Modbus server parameter */ struct modbus_server_param { /** Pointer to the User Callback structure */ struct modbus_user_callbacks *user_cb; /** Modbus unit ID of the server */ uint8_t unit_id; }; struct modbus_raw_cb { modbus_raw_cb_t raw_tx_cb; void *user_data; }; /** * @brief User parameter structure to configure Modbus interface * as client or server. */ struct modbus_iface_param { /** Mode of the interface */ enum modbus_mode mode; union { struct modbus_server_param server; /** Amount of time client will wait for * a response from the server. */ uint32_t rx_timeout; }; union { /** Serial support parameter of the interface */ struct modbus_serial_param serial; /** Pointer to raw ADU callback function */ struct modbus_raw_cb rawcb; }; }; /** * @brief Configure Modbus Interface as raw ADU server * * @param iface Modbus RTU interface index * @param param Configuration parameter of the server interface * * @retval 0 If the function was successful */ int modbus_init_server(const int iface, struct modbus_iface_param param); /** * @brief Configure Modbus Interface as raw ADU client * * @param iface Modbus RTU interface index * @param param Configuration parameter of the client interface * * @retval 0 If the function was successful */ int modbus_init_client(const int iface, struct modbus_iface_param param); /** * @brief Disable Modbus Interface * * This function is called to disable Modbus interface. * * @param iface Modbus interface index * * @retval 0 If the function was successful */ int modbus_disable(const uint8_t iface); /** * @brief Submit raw ADU * * @param iface Modbus RTU interface index * @param adu Pointer to the RAW ADU struct that is received * * @retval 0 If transfer was successful */ int modbus_raw_submit_rx(const int iface, const struct modbus_adu *adu); /** * @brief Put MBAP header into a buffer * * @param adu Pointer to the RAW ADU struct * @param header Pointer to the buffer in which MBAP header * will be placed. */ void modbus_raw_put_header(const struct modbus_adu *adu, uint8_t *header); /** * @brief Get MBAP header from a buffer * * @param adu Pointer to the RAW ADU struct * @param header Pointer to the buffer containing MBAP header */ void modbus_raw_get_header(struct modbus_adu *adu, const uint8_t *header); /** * @brief Set Server Device Failure exception * * This function modifies ADU passed by the pointer. * * @param adu Pointer to the RAW ADU struct */ void modbus_raw_set_server_failure(struct modbus_adu *adu); /** * @brief Use interface as backend to send and receive ADU * * This function overwrites ADU passed by the pointer and generates * exception responses if backend interface is misconfigured or * target device is unreachable. * * @param iface Modbus client interface index * @param adu Pointer to the RAW ADU struct * * @retval 0 If transfer was successful */ int modbus_raw_backend_txn(const int iface, struct modbus_adu *adu); /** * @brief Register a user-defined function code handler. * * The Modbus specification allows users to define standard function codes * missing from Zephyr's Modbus implementation as well as add non-standard * function codes in the ranges 65 to 72 and 100 to 110 (decimal), as per * specification. * * This function registers a new handler at runtime for the given * function code. * * @param iface Modbus client interface index * @param custom_fc User defined function code and callback pair * * @retval 0 on success */ int modbus_register_user_fc(const int iface, struct modbus_custom_fc *custom_fc); #ifdef __cplusplus } #endif /** * @} */ #endif /* ZEPHYR_INCLUDE_MODBUS_H_ */ ```
/content/code_sandbox/include/zephyr/modbus/modbus.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
4,639
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_CONSOLE_CONSOLE_H_ #define ZEPHYR_INCLUDE_CONSOLE_CONSOLE_H_ #include <sys/types.h> #include <zephyr/types.h> #include <zephyr/kernel.h> #ifdef __cplusplus extern "C" { #endif /** * @brief Console API * @defgroup console_api Console API * @ingroup os_services * @{ */ /** @brief Initialize console device. * * This function should be called once to initialize pull-style * access to console via console_getchar() function and buffered * output using console_putchar() function. This function supersedes, * and incompatible with, callback (push-style) console handling * (via console_input_fn callback, etc.). * * @return 0 on success, error code (<0) otherwise */ int console_init(void); /** * @brief Read data from console. * * @param dummy ignored, present to follow read() prototype * @param buf buffer to read data to * @param size maximum number of bytes to read * @return >0, number of actually read bytes (can be less than size param) * =0, in case of EOF * <0, in case of error (e.g. -EAGAIN if timeout expired). errno * variable is also set. */ ssize_t console_read(void *dummy, void *buf, size_t size); /** * @brief Write data to console. * * @param dummy ignored, present to follow write() prototype * @param buf buffer to write data to * @param size maximum number of bytes to write * @return =>0, number of actually written bytes (can be less than size param) * <0, in case of error (e.g. -EAGAIN if timeout expired). errno * variable is also set. */ ssize_t console_write(void *dummy, const void *buf, size_t size); /** @brief Get next char from console input buffer. * * Return next input character from console. If no characters available, * this function will block. This function is similar to ANSI C * getchar() function and is intended to ease porting of existing * software. Before this function can be used, console_init() * should be called once. This function is incompatible with native * Zephyr callback-based console input processing, shell subsystem, * or console_getline(). * * @return 0-255: a character read, including control characters. * <0: error occurred. */ int console_getchar(void); /** @brief Output a char to console (buffered). * * Puts a character into console output buffer. It will be sent * to a console asynchronously, e.g. using an IRQ handler. * * @return <0 on error, otherwise 0. */ int console_putchar(char c); /** @brief Initialize console_getline() call. * * This function should be called once to initialize pull-style * access to console via console_getline() function. This function * supersedes, and incompatible with, callback (push-style) console * handling (via console_input_fn callback, etc.). */ void console_getline_init(void); /** @brief Get next line from console input buffer. * * Return next input line from console. Until full line is available, * this function will block. This function is similar to ANSI C * gets() function (except a line is returned in system-owned buffer, * and system takes care of the buffer overflow checks) and is * intended to ease porting of existing software. Before this function * can be used, console_getline_init() should be called once. This * function is incompatible with native Zephyr callback-based console * input processing, shell subsystem, or console_getchar(). * * @return A pointer to a line read, not including EOL character(s). * A line resides in a system-owned buffer, so an application * should finish any processing of this line immediately * after console_getline() call, or the buffer can be reused. */ char *console_getline(void); #ifdef __cplusplus } #endif /** * @} */ #endif /* ZEPHYR_INCLUDE_CONSOLE_CONSOLE_H_ */ ```
/content/code_sandbox/include/zephyr/console/console.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
914
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_CONSOLE_TTY_H_ #define ZEPHYR_INCLUDE_CONSOLE_TTY_H_ #include <sys/types.h> #include <zephyr/types.h> #include <zephyr/kernel.h> #ifdef __cplusplus extern "C" { #endif struct tty_serial { const struct device *uart_dev; struct k_sem rx_sem; uint8_t *rx_ringbuf; uint32_t rx_ringbuf_sz; uint16_t rx_get, rx_put; int32_t rx_timeout; struct k_sem tx_sem; uint8_t *tx_ringbuf; uint32_t tx_ringbuf_sz; uint16_t tx_get, tx_put; int32_t tx_timeout; }; /** * @brief Initialize serial port object (classically known as tty). * * "tty" device provides support for buffered, interrupt-driven, * timeout-controlled access to an underlying UART device. For * completeness, it also support non-interrupt-driven, busy-polling * access mode. After initialization, tty is in the "most conservative" * unbuffered mode with infinite timeouts (this is guaranteed to work * on any hardware). Users should configure buffers and timeouts as * they need using functions tty_set_rx_buf(), tty_set_tx_buf(), * tty_set_rx_timeout(), tty_set_tx_timeout(). * * @param tty tty device structure to initialize * @param uart_dev underlying UART device to use (should support * interrupt-driven operation) * * @return 0 on success, error code (<0) otherwise */ int tty_init(struct tty_serial *tty, const struct device *uart_dev); /** * @brief Set receive timeout for tty device. * * Set timeout for getchar() operation. Default timeout after * device initialization is SYS_FOREVER_MS. * * @param tty tty device structure * @param timeout timeout in milliseconds, or 0, or SYS_FOREVER_MS. */ static inline void tty_set_rx_timeout(struct tty_serial *tty, int32_t timeout) { tty->rx_timeout = timeout; } /** * @brief Set transmit timeout for tty device. * * Set timeout for putchar() operation, for a case when output buffer is full. * Default timeout after device initialization is SYS_FOREVER_MS. * * @param tty tty device structure * @param timeout timeout in milliseconds, or 0, or SYS_FOREVER_MS. */ static inline void tty_set_tx_timeout(struct tty_serial *tty, int32_t timeout) { tty->tx_timeout = timeout; } /** * @brief Set receive buffer for tty device. * * Set receive buffer or switch to unbuffered operation for receive. * * @param tty tty device structure * @param buf buffer, or NULL for unbuffered operation * @param size buffer buffer size, 0 for unbuffered operation * @return 0 on success, error code (<0) otherwise: * EINVAL: unsupported buffer (size) */ int tty_set_rx_buf(struct tty_serial *tty, void *buf, size_t size); /** * @brief Set transmit buffer for tty device. * * Set transmit buffer or switch to unbuffered operation for transmit. * Note that unbuffered mode is implicitly blocking, i.e. behaves as * if tty_set_tx_timeout(SYS_FOREVER_MS) was set. * * @param tty tty device structure * @param buf buffer, or NULL for unbuffered operation * @param size buffer buffer size, 0 for unbuffered operation * @return 0 on success, error code (<0) otherwise: * EINVAL: unsupported buffer (size) */ int tty_set_tx_buf(struct tty_serial *tty, void *buf, size_t size); /** * @brief Read data from a tty device. * * @param tty tty device structure * @param buf buffer to read data to * @param size maximum number of bytes to read * @return >0, number of actually read bytes (can be less than size param) * =0, for EOF-like condition (e.g., break signaled) * <0, in case of error (e.g. -EAGAIN if timeout expired). errno * variable is also set. */ ssize_t tty_read(struct tty_serial *tty, void *buf, size_t size); /** * @brief Write data to tty device. * * @param tty tty device structure * @param buf buffer containing data * @param size maximum number of bytes to write * @return =>0, number of actually written bytes (can be less than size param) * <0, in case of error (e.g. -EAGAIN if timeout expired). errno * variable is also set. */ ssize_t tty_write(struct tty_serial *tty, const void *buf, size_t size); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_CONSOLE_TTY_H_ */ ```
/content/code_sandbox/include/zephyr/console/tty.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,020
```objective-c /* * Shell backend used for testing * * */ #ifndef SHELL_DUMMY_H__ #define SHELL_DUMMY_H__ #include <zephyr/shell/shell.h> #ifdef __cplusplus extern "C" { #endif extern const struct shell_transport_api shell_dummy_transport_api; struct shell_dummy { bool initialized; /** current number of bytes in buffer (0 if no output) */ size_t len; /** output buffer to collect shell output */ char buf[CONFIG_SHELL_BACKEND_DUMMY_BUF_SIZE]; }; #define SHELL_DUMMY_DEFINE(_name) \ static struct shell_dummy _name##_shell_dummy; \ struct shell_transport _name = { \ .api = &shell_dummy_transport_api, \ .ctx = (struct shell_dummy *)&_name##_shell_dummy \ } /** * @brief This function shall not be used directly. It provides pointer to shell * dummy backend instance. * * Function returns pointer to the shell dummy instance. This instance can be * next used with shell_execute_cmd function in order to test commands behavior. * * @returns Pointer to the shell instance. */ const struct shell *shell_backend_dummy_get_ptr(void); /** * @brief Returns the buffered output in the shell and resets the pointer * * The returned data is always followed by a nul character at position *sizep * * @param sh Shell pointer * @param sizep Returns size of data in shell buffer * @returns pointer to buffer containing shell output */ const char *shell_backend_dummy_get_output(const struct shell *sh, size_t *sizep); /** * @brief Clears the output buffer in the shell backend. * * @param sh Shell pointer */ void shell_backend_dummy_clear_output(const struct shell *sh); #ifdef __cplusplus } #endif #endif /* SHELL_DUMMY_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell_dummy.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
390
```objective-c /* * */ #ifndef SHELL_BACKEND_H__ #define SHELL_BACKEND_H__ #include <zephyr/types.h> #include <zephyr/shell/shell.h> #include <zephyr/sys/iterable_sections.h> #ifdef __cplusplus extern "C" { #endif /** * @brief Get backend. * * @param[in] idx Pointer to the backend instance. * * @return Pointer to the backend instance. */ static inline const struct shell *shell_backend_get(uint32_t idx) { const struct shell *backend; STRUCT_SECTION_GET(shell, idx, &backend); return backend; } /** * @brief Get number of backends. * * @return Number of backends. */ static inline int shell_backend_count_get(void) { int cnt; STRUCT_SECTION_COUNT(shell, &cnt); return cnt; } /** * @brief Get backend by name. * * @param[in] backend_name Name of the backend as defined by the SHELL_DEFINE. * * @retval Pointer to the backend instance if found, NULL if backend is not found. */ const struct shell *shell_backend_get_by_name(const char *backend_name); #ifdef __cplusplus } #endif #endif /* SHELL_BACKEND_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell_backend.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
251
```objective-c /* * */ #ifndef SHELL_MQTT_H__ #define SHELL_MQTT_H__ #include <zephyr/kernel.h> #include <zephyr/shell/shell.h> #include <zephyr/net/socket.h> #include <zephyr/net/net_mgmt.h> #include <zephyr/net/net_event.h> #include <zephyr/net/conn_mgr_monitor.h> #include <zephyr/net/mqtt.h> #include <zephyr/sys/ring_buffer.h> #ifdef __cplusplus extern "C" { #endif #define RX_RB_SIZE CONFIG_SHELL_MQTT_RX_BUF_SIZE #define TX_BUF_SIZE CONFIG_SHELL_MQTT_TX_BUF_SIZE #define SH_MQTT_BUFFER_SIZE 64 #define DEVICE_ID_BIN_MAX_SIZE 3 #define DEVICE_ID_HEX_MAX_SIZE ((DEVICE_ID_BIN_MAX_SIZE * 2) + 1) #define SH_MQTT_TOPIC_MAX_SIZE DEVICE_ID_HEX_MAX_SIZE + 3 extern const struct shell_transport_api shell_mqtt_transport_api; struct shell_mqtt_tx_buf { /** tx buffer. */ char buf[TX_BUF_SIZE]; /** Current tx buf length. */ uint16_t len; }; /** MQTT-based shell transport. */ struct shell_mqtt { char device_id[DEVICE_ID_HEX_MAX_SIZE]; char sub_topic[SH_MQTT_TOPIC_MAX_SIZE]; char pub_topic[SH_MQTT_TOPIC_MAX_SIZE]; /** Handler function registered by shell. */ shell_transport_handler_t shell_handler; struct ring_buf rx_rb; uint8_t rx_rb_buf[RX_RB_SIZE]; uint8_t *rx_rb_ptr; struct shell_mqtt_tx_buf tx_buf; /** Context registered by shell. */ void *shell_context; /** The mqtt client struct */ struct mqtt_client mqtt_cli; /* Buffers for MQTT client. */ struct buffer { uint8_t rx[SH_MQTT_BUFFER_SIZE]; uint8_t tx[SH_MQTT_BUFFER_SIZE]; } buf; struct k_mutex lock; /** MQTT Broker details. */ struct sockaddr_storage broker; struct zsock_addrinfo *haddr; struct zsock_pollfd fds[1]; int nfds; struct mqtt_publish_param pub_data; struct net_mgmt_event_callback mgmt_cb; /** work */ struct k_work_q workq; struct k_work net_disconnected_work; struct k_work_delayable connect_dwork; struct k_work_delayable subscribe_dwork; struct k_work_delayable process_dwork; struct k_work_delayable publish_dwork; /** MQTT connection states */ enum sh_mqtt_transport_state { SHELL_MQTT_TRANSPORT_DISCONNECTED, SHELL_MQTT_TRANSPORT_CONNECTED, } transport_state; /** MQTT subscription states */ enum sh_mqtt_subscribe_state { SHELL_MQTT_NOT_SUBSCRIBED, SHELL_MQTT_SUBSCRIBED, } subscribe_state; /** Network states */ enum sh_mqtt_network_state { SHELL_MQTT_NETWORK_DISCONNECTED, SHELL_MQTT_NETWORK_CONNECTED, } network_state; }; #define SHELL_MQTT_DEFINE(_name) \ static struct shell_mqtt _name##_shell_mqtt; \ struct shell_transport _name = { .api = &shell_mqtt_transport_api, \ .ctx = (struct shell_mqtt *)&_name##_shell_mqtt } /** * @brief This function provides pointer to shell mqtt backend instance. * * Function returns pointer to the shell mqtt instance. This instance can be * next used with shell_execute_cmd function in order to test commands behavior. * * @returns Pointer to the shell instance. */ const struct shell *shell_backend_mqtt_get_ptr(void); /** * @brief Function to define the device ID (devid) for which the shell mqtt backend uses as a * client ID when it connects to the broker. It will publish its output to devid_tx and subscribe * to devid_rx for input . * * @note This is a weak-linked function, and can be overridden if desired. * * @param id Pointer to the devid buffer * @param id_max_len Maximum size of the devid buffer defined by DEVICE_ID_HEX_MAX_SIZE * * @return true if length of devid > 0 */ bool shell_mqtt_get_devid(char *id, int id_max_len); #ifdef __cplusplus } #endif #endif /* SHELL_MQTT_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell_mqtt.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
917
```objective-c /* * */ #ifndef SHELL_TYPES_H__ #define SHELL_TYPES_H__ #ifdef __cplusplus extern "C" { #endif enum shell_vt100_color { SHELL_VT100_COLOR_BLACK, SHELL_VT100_COLOR_RED, SHELL_VT100_COLOR_GREEN, SHELL_VT100_COLOR_YELLOW, SHELL_VT100_COLOR_BLUE, SHELL_VT100_COLOR_MAGENTA, SHELL_VT100_COLOR_CYAN, SHELL_VT100_COLOR_WHITE, SHELL_VT100_COLOR_DEFAULT, VT100_COLOR_END }; struct shell_vt100_colors { enum shell_vt100_color col; /*!< Text color. */ enum shell_vt100_color bgcol; /*!< Background color. */ }; struct shell_multiline_cons { uint16_t cur_x; /*!< horizontal cursor position in edited command line.*/ uint16_t cur_x_end; /*!< horizontal cursor position at the end of command.*/ uint16_t cur_y; /*!< vertical cursor position in edited command.*/ uint16_t cur_y_end; /*!< vertical cursor position at the end of command.*/ uint16_t terminal_hei; /*!< terminal screen height.*/ uint16_t terminal_wid; /*!< terminal screen width.*/ uint8_t name_len; /*!<console name length.*/ }; struct shell_vt100_ctx { struct shell_multiline_cons cons; struct shell_vt100_colors col; uint16_t printed_cmd; /*!< printed commands counter */ }; #ifdef __cplusplus } #endif #endif /* SHELL_TYPES_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell_types.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
309
```objective-c /* * */ #ifndef SHELL_LOG_BACKEND_H__ #define SHELL_LOG_BACKEND_H__ #include <zephyr/kernel.h> #include <zephyr/logging/log_backend.h> #include <zephyr/logging/log_output.h> #include <zephyr/sys/mpsc_pbuf.h> #include <zephyr/sys/atomic.h> #ifdef __cplusplus extern "C" { #endif extern const struct log_backend_api log_backend_shell_api; /** @brief Shell log backend states. */ enum shell_log_backend_state { SHELL_LOG_BACKEND_UNINIT, SHELL_LOG_BACKEND_ENABLED, SHELL_LOG_BACKEND_DISABLED, SHELL_LOG_BACKEND_PANIC, }; /** @brief Shell log backend control block (RW data). */ struct shell_log_backend_control_block { atomic_t dropped_cnt; enum shell_log_backend_state state; }; /** @brief Shell log backend instance structure (RO data). */ struct shell_log_backend { const struct log_backend *backend; const struct log_output *log_output; struct shell_log_backend_control_block *control_block; uint32_t timeout; const struct mpsc_pbuf_buffer_config *mpsc_buffer_config; struct mpsc_pbuf_buffer *mpsc_buffer; }; /** @brief Shell log backend message structure. */ struct shell_log_backend_msg { struct log_msg *msg; uint32_t timestamp; }; /** @brief Prototype of function outputting processed data. */ int z_shell_log_backend_output_func(uint8_t *data, size_t length, void *ctx); /** @def Z_SHELL_LOG_BACKEND_DEFINE * @brief Macro for creating instance of shell log backend. * * @param _name Shell name. * @param _buf Output buffer. * @param _size Output buffer size. * @param _queue_size Log message queue size. * @param _timeout Timeout in milliseconds for pending on queue full. * Message is dropped on timeout. */ /** @def Z_SHELL_LOG_BACKEND_PTR * @brief Macro for retrieving pointer to the instance of shell log backend. * * @param _name Shell name. */ #ifdef CONFIG_SHELL_LOG_BACKEND #define Z_SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size, _queue_size, _timeout) \ LOG_BACKEND_DEFINE(_name##_backend, log_backend_shell_api, false); \ LOG_OUTPUT_DEFINE(_name##_log_output, z_shell_log_backend_output_func,\ _buf, _size); \ static struct shell_log_backend_control_block _name##_control_block; \ static uint32_t __aligned(Z_LOG_MSG_ALIGNMENT) \ _name##_buf[_queue_size / sizeof(uint32_t)]; \ const struct mpsc_pbuf_buffer_config _name##_mpsc_buffer_config = { \ .buf = _name##_buf, \ .size = ARRAY_SIZE(_name##_buf), \ .notify_drop = NULL, \ .get_wlen = log_msg_generic_get_wlen, \ .flags = MPSC_PBUF_MODE_OVERWRITE, \ }; \ struct mpsc_pbuf_buffer _name##_mpsc_buffer; \ static const struct shell_log_backend _name##_log_backend = { \ .backend = &_name##_backend, \ .log_output = &_name##_log_output, \ .control_block = &_name##_control_block, \ .timeout = _timeout, \ .mpsc_buffer_config = &_name##_mpsc_buffer_config, \ .mpsc_buffer = &_name##_mpsc_buffer, \ } #define Z_SHELL_LOG_BACKEND_PTR(_name) (&_name##_log_backend) #else /* CONFIG_LOG */ #define Z_SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size, _queue_size, _timeout) #define Z_SHELL_LOG_BACKEND_PTR(_name) NULL #endif /* CONFIG_LOG */ /** @brief Enable shell log backend. * * @param backend Shell log backend instance. * @param ctx Pointer to shell instance. * @param init_log_level Initial log level set to all logging sources. */ void z_shell_log_backend_enable(const struct shell_log_backend *backend, void *ctx, uint32_t init_log_level); /** @brief Disable shell log backend. * * @param backend Shell log backend instance. */ void z_shell_log_backend_disable(const struct shell_log_backend *backend); /** @brief Trigger processing of one log entry. * * @param backend Shell log backend instance. * * @return True if message was processed, false if FIFO was empty */ bool z_shell_log_backend_process(const struct shell_log_backend *backend); #ifdef __cplusplus } #endif #endif /* SHELL_LOG_BACKEND_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell_log_backend.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
957
```objective-c /* * */ #ifndef SHELL_RPMSG_H__ #define SHELL_RPMSG_H__ #include <zephyr/kernel.h> #include <zephyr/shell/shell.h> #include <openamp/rpmsg.h> #ifdef __cplusplus extern "C" { #endif extern const struct shell_transport_api shell_rpmsg_transport_api; /** RPMsg received message placeholder */ struct shell_rpmsg_rx { /** Pointer to the data held by RPMsg endpoint */ void *data; /** The length of the data */ size_t len; }; /** RPMsg-based shell transport. */ struct shell_rpmsg { /** Handler function registered by shell. */ shell_transport_handler_t shell_handler; /** Context registered by shell. */ void *shell_context; /** Indicator if we are ready to read/write */ bool ready; /** Setting for blocking mode */ bool blocking; /** RPMsg endpoint */ struct rpmsg_endpoint ept; /** Queue for received data. */ struct k_msgq rx_q; /** Buffer for received messages */ struct shell_rpmsg_rx rx_buf[CONFIG_SHELL_RPMSG_MAX_RX]; /** The current rx message */ struct shell_rpmsg_rx rx_cur; /** The number of bytes consumed from rx_cur */ size_t rx_consumed; }; #define SHELL_RPMSG_DEFINE(_name) \ static struct shell_rpmsg _name##_shell_rpmsg; \ struct shell_transport _name = { \ .api = &shell_rpmsg_transport_api, \ .ctx = (struct shell_rpmsg *)&_name##_shell_rpmsg, \ } /** * @brief Initialize the Shell backend using the provided @p rpmsg_dev device. * * @param rpmsg_dev A pointer to an RPMsg device * @return 0 on success or a negative value on error */ int shell_backend_rpmsg_init_transport(struct rpmsg_device *rpmsg_dev); /** * @brief This function provides pointer to shell RPMsg backend instance. * * Function returns pointer to the shell RPMsg instance. This instance can be * next used with shell_execute_cmd function in order to test commands behavior. * * @returns Pointer to the shell instance. */ const struct shell *shell_backend_rpmsg_get_ptr(void); #ifdef __cplusplus } #endif #endif /* SHELL_RPMSG_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell_rpmsg.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
489
```objective-c /* * */ #ifndef SHELL_HISTORY_H__ #define SHELL_HISTORY_H__ #include <zephyr/kernel.h> #include <zephyr/sys/util.h> #include <zephyr/sys/dlist.h> #include <zephyr/sys/ring_buffer.h> #include <stdbool.h> #ifdef __cplusplus extern "C" { #endif struct shell_history { struct ring_buf *ring_buf; sys_dlist_t list; sys_dnode_t *current; }; /** * @brief Create shell history instance. * * @param _name History instance name. * @param _size Memory dedicated for shell history. */ #define Z_SHELL_HISTORY_DEFINE(_name, _size) \ static uint8_t __noinit __aligned(sizeof(void *)) \ _name##_ring_buf_data[_size]; \ static struct ring_buf _name##_ring_buf = \ { \ .size = _size, \ .buffer = _name##_ring_buf_data \ }; \ static struct shell_history _name = { \ .ring_buf = &_name##_ring_buf \ } /** * @brief Initialize shell history module. * * @param history Shell history instance. */ void z_shell_history_init(struct shell_history *history); /** * @brief Purge shell history. * * Function clears whole shell command history. * * @param history Shell history instance. * */ void z_shell_history_purge(struct shell_history *history); /** * @brief Exit history browsing mode. * * @param history Shell history instance. */ void z_shell_history_mode_exit(struct shell_history *history); /** * @brief Get next entry in shell command history. * * Function returns next (in given direction) stored line. * * @param[in] history Shell history instance. * @param[in] up Direction. * @param[out] dst Buffer where line is copied. * @param[in,out] len Buffer size (input), amount of copied * data (output). * @return True if remains in history mode. */ bool z_shell_history_get(struct shell_history *history, bool up, uint8_t *dst, uint16_t *len); /** * @brief Put line into shell command history. * * If history is full, oldest entry (or entries) is removed. * * @param history Shell history instance. * @param line Data. * @param len Data length. * */ void z_shell_history_put(struct shell_history *history, uint8_t *line, size_t len); /** * @brief Get state of shell history. * * @param history Shell history instance. * * @return True if in browsing mode. */ static inline bool z_shell_history_active(struct shell_history *history) { return (history->current) ? true : false; } #ifdef __cplusplus } #endif #endif /* SHELL_HISTORY_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell_history.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
609
```objective-c /* * */ #ifndef SHELL_FPRINTF_H__ #define SHELL_FPRINTF_H__ #include <zephyr/kernel.h> #include <stdbool.h> #include <stddef.h> #ifdef __cplusplus extern "C" { #endif typedef void (*shell_fprintf_fwrite)(const void *user_ctx, const char *data, size_t length); struct shell_fprintf_control_block { size_t buffer_cnt; bool autoflush; }; /** * @brief fprintf context */ struct shell_fprintf { uint8_t *buffer; size_t buffer_size; shell_fprintf_fwrite fwrite; const void *user_ctx; struct shell_fprintf_control_block *ctrl_blk; }; /** * @brief Macro for defining shell_fprintf instance. * * @param _name Instance name. * @param _user_ctx Pointer to user data. * @param _buf Pointer to output buffer * @param _size Size of output buffer. * @param _autoflush Indicator if buffer shall be automatically flush. * @param _fwrite Pointer to function sending data stream. */ #define Z_SHELL_FPRINTF_DEFINE(_name, _user_ctx, _buf, _size, \ _autoflush, _fwrite) \ static struct shell_fprintf_control_block \ _name##_shell_fprintf_ctx = { \ .autoflush = _autoflush, \ .buffer_cnt = 0 \ }; \ static const struct shell_fprintf _name = { \ .buffer = _buf, \ .buffer_size = _size, \ .fwrite = _fwrite, \ .user_ctx = _user_ctx, \ .ctrl_blk = &_name##_shell_fprintf_ctx \ } /** * @brief fprintf like function which send formatted data stream to output. * * @param sh_fprintf fprintf instance. * @param fmt Format string. * @param args List of parameters to print. */ void z_shell_fprintf_fmt(const struct shell_fprintf *sh_fprintf, char const *fmt, va_list args); /** * @brief function flushing data stored in io_buffer. * * @param sh_fprintf fprintf instance */ void z_shell_fprintf_buffer_flush(const struct shell_fprintf *sh_fprintf); #ifdef __cplusplus } #endif #endif /* SHELL_FPRINTF_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell_fprintf.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
514
```objective-c /* * */ #ifndef SHELL_STRING_CONV_H__ #define SHELL_STRING_CONV_H__ #include <stdbool.h> #include <stdint.h> #ifdef __cplusplus extern "C" { #endif /** @brief String to long conversion with error check. * * @warning On success the passed err reference will not be altered * to avoid err check bloating. Passed err reference should be initialized * to zero. * * @param str Input string. * @param base Conversion base. * @param err Error code pointer: * -EINVAL on invalid string input. * -ERANGE if numeric string input is to large to convert. * Unchanged on success. * * @return Converted long value. */ long shell_strtol(const char *str, int base, int *err); /** @brief String to unsigned long conversion with error check. * * @warning On success the passed err reference will not be altered * to avoid err check bloating. Passed err reference should be initialized * to zero. * * @param str Input string. * @param base Conversion base. * @param err Error code pointer: * Set to -EINVAL on invalid string input. * Set to -ERANGE if numeric string input is to large to convert. * Unchanged on success. * * @return Converted unsigned long value. */ unsigned long shell_strtoul(const char *str, int base, int *err); /** @brief String to unsigned long long conversion with error check. * * @warning On success the passed err reference will not be altered * to avoid err check bloating. Passed err reference should be initialized * to zero. * * @param str Input string. * @param base Conversion base. * @param err Error code pointer: * Set to -EINVAL on invalid string input. * Set to -ERANGE if numeric string input is to large to convert. * Unchanged on success. * * @return Converted unsigned long long value. */ unsigned long long shell_strtoull(const char *str, int base, int *err); /** @brief String to boolean conversion with error check. * * @warning On success the passed err reference will not be altered * to avoid err check bloating. Passed err reference should be initialized * to zero. * * @param str Input string. * @param base Conversion base. * @param err Error code pointer: * Set to -EINVAL on invalid string input. * Set to -ERANGE if numeric string input is to large to convert. * Unchanged on success. * * @return Converted boolean value. */ bool shell_strtobool(const char *str, int base, int *err); #ifdef __cplusplus } #endif #endif /* SHELL_STRING_CONV_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell_string_conv.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
577
```objective-c /* * */ #ifndef SHELL_TELNET_H__ #define SHELL_TELNET_H__ #include <zephyr/net/socket.h> #include <zephyr/shell/shell.h> #ifdef __cplusplus extern "C" { #endif extern const struct shell_transport_api shell_telnet_transport_api; #define SHELL_TELNET_POLLFD_COUNT 3 #define SHELL_TELNET_MAX_CMD_SIZE 3 /** Line buffer structure. */ struct shell_telnet_line_buf { /** Line buffer. */ char buf[CONFIG_SHELL_TELNET_LINE_BUF_SIZE]; /** Current line length. */ uint16_t len; }; /** TELNET-based shell transport. */ struct shell_telnet { /** Handler function registered by shell. */ shell_transport_handler_t shell_handler; /** Context registered by shell. */ void *shell_context; /** Buffer for outgoing line. */ struct shell_telnet_line_buf line_out; /** Array for sockets used by the telnet service. */ struct zsock_pollfd fds[SHELL_TELNET_POLLFD_COUNT]; /** Input buffer. */ uint8_t rx_buf[CONFIG_SHELL_CMD_BUFF_SIZE]; /** Number of data bytes within the input buffer. */ size_t rx_len; /** Mutex protecting the input buffer access. */ struct k_mutex rx_lock; uint8_t cmd_buf[SHELL_TELNET_MAX_CMD_SIZE]; uint8_t cmd_len; /** The delayed work is used to send non-lf terminated output that has * been around for "too long". This will prove to be useful * to send the shell prompt for instance. */ struct k_work_delayable send_work; struct k_work_sync work_sync; /** If set, no output is sent to the TELNET client. */ bool output_lock; }; #define SHELL_TELNET_DEFINE(_name) \ static struct shell_telnet _name##_shell_telnet; \ struct shell_transport _name = { \ .api = &shell_telnet_transport_api, \ .ctx = (struct shell_telnet *)&_name##_shell_telnet \ } /** * @brief This function provides pointer to shell telnet backend instance. * * Function returns pointer to the shell telnet instance. This instance can be * next used with shell_execute_cmd function in order to test commands behavior. * * @returns Pointer to the shell instance. */ const struct shell *shell_backend_telnet_get_ptr(void); #ifdef __cplusplus } #endif #endif /* SHELL_TELNET_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell_telnet.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
536
```objective-c /* * */ #ifndef SHELL_RTT_H__ #define SHELL_RTT_H__ #include <zephyr/shell/shell.h> #ifdef __cplusplus extern "C" { #endif extern const struct shell_transport_api shell_rtt_transport_api; struct shell_rtt { shell_transport_handler_t handler; struct k_timer timer; void *context; }; #define SHELL_RTT_DEFINE(_name) \ static struct shell_rtt _name##_shell_rtt; \ struct shell_transport _name = { \ .api = &shell_rtt_transport_api, \ .ctx = (struct shell_rtt *)&_name##_shell_rtt \ } /** * @brief Function provides pointer to shell rtt backend instance. * * Function returns pointer to the shell rtt instance. This instance can be * next used with shell_execute_cmd function in order to test commands behavior. * * @returns Pointer to the shell instance. */ const struct shell *shell_backend_rtt_get_ptr(void); #ifdef __cplusplus } #endif #endif /* SHELL_RTT_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell_rtt.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
231
```objective-c /* * */ #ifndef SHELL_UART_H__ #define SHELL_UART_H__ #include <zephyr/drivers/serial/uart_async_rx.h> #include <zephyr/mgmt/mcumgr/transport/smp_shell.h> #include <zephyr/shell/shell.h> #ifdef __cplusplus extern "C" { #endif extern const struct shell_transport_api shell_uart_transport_api; #ifndef CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE #define CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE 0 #endif #ifndef CONFIG_SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE #define CONFIG_SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE 0 #endif #ifndef CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_COUNT #define CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_COUNT 0 #endif #ifndef CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_SIZE #define CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_SIZE 0 #endif #define ASYNC_RX_BUF_SIZE (CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_COUNT * \ (CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_SIZE + \ UART_ASYNC_RX_BUF_OVERHEAD)) struct shell_uart_common { const struct device *dev; shell_transport_handler_t handler; void *context; bool blocking_tx; #ifdef CONFIG_MCUMGR_TRANSPORT_SHELL struct smp_shell_data smp; #endif /* CONFIG_MCUMGR_TRANSPORT_SHELL */ }; struct shell_uart_int_driven { struct shell_uart_common common; struct ring_buf tx_ringbuf; struct ring_buf rx_ringbuf; uint8_t tx_buf[CONFIG_SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE]; uint8_t rx_buf[CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE]; struct k_timer dtr_timer; atomic_t tx_busy; }; struct shell_uart_async { struct shell_uart_common common; struct k_sem tx_sem; struct uart_async_rx async_rx; struct uart_async_rx_config async_rx_config; atomic_t pending_rx_req; uint8_t rx_data[ASYNC_RX_BUF_SIZE]; }; struct shell_uart_polling { struct shell_uart_common common; struct ring_buf rx_ringbuf; uint8_t rx_buf[CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE]; struct k_timer rx_timer; }; #ifdef CONFIG_SHELL_BACKEND_SERIAL_API_POLLING #define SHELL_UART_STRUCT struct shell_uart_polling #elif defined(CONFIG_SHELL_BACKEND_SERIAL_API_ASYNC) #define SHELL_UART_STRUCT struct shell_uart_async #else #define SHELL_UART_STRUCT struct shell_uart_int_driven #endif /** * @brief Macro for creating shell UART transport instance named @p _name * * @note Additional arguments are accepted (but ignored) for compatibility with * previous Zephyr version, it will be removed in future release. */ #define SHELL_UART_DEFINE(_name, ...) \ static SHELL_UART_STRUCT _name##_shell_uart; \ struct shell_transport _name = { \ .api = &shell_uart_transport_api, \ .ctx = (struct shell_telnet *)&_name##_shell_uart, \ } /** * @brief This function provides pointer to the shell UART backend instance. * * Function returns pointer to the shell UART instance. This instance can be * next used with shell_execute_cmd function in order to test commands behavior. * * @returns Pointer to the shell instance. */ const struct shell *shell_backend_uart_get_ptr(void); /** * @brief This function provides pointer to the smp shell data of the UART shell transport. * * @returns Pointer to the smp shell data. */ struct smp_shell_data *shell_uart_smp_shell_data_get_ptr(void); #ifdef __cplusplus } #endif #endif /* SHELL_UART_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell_uart.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
748
```objective-c /* * */ #ifndef SHELL_ADSP_MEMORY_WINDOW_H__ #define SHELL_ADSP_MEMORY_WINDOW_H__ #include <zephyr/kernel.h> #include <zephyr/shell/shell.h> #ifdef __cplusplus extern "C" { #endif extern const struct shell_transport_api shell_adsp_memory_window_transport_api; struct sys_winstream; /** Memwindow based shell transport. */ struct shell_adsp_memory_window { /** Handler function registered by shell. */ shell_transport_handler_t shell_handler; struct k_timer timer; /** Context registered by shell. */ void *shell_context; /** Receive winstream object */ struct sys_winstream *ws_rx; /** Transmit winstream object */ struct sys_winstream *ws_tx; /** Last read sequence number */ uint32_t read_seqno; }; #define SHELL_ADSP_MEMORY_WINDOW_DEFINE(_name) \ static struct shell_adsp_memory_window _name##_shell_adsp_memory_window;\ struct shell_transport _name = { \ .api = &shell_adsp_memory_window_transport_api, \ .ctx = &_name##_shell_adsp_memory_window, \ } /** * @brief This function provides pointer to shell ADSP memory window backend instance. * * Function returns pointer to the shell ADSP memory window instance. This instance can be * next used with shell_execute_cmd function in order to test commands behavior. * * @returns Pointer to the shell instance. */ const struct shell *shell_backend_adsp_memory_window_get_ptr(void); #ifdef __cplusplus } #endif #endif /* SHELL_ADSP_MEMORY_WINDOW_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell_adsp_memory_window.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
333
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_SIP_SVC_H_ #define ZEPHYR_INCLUDE_SIP_SVC_H_ /** * @file * @brief Public API for ARM SiP services * * ARM SiP service provides the capability to send the * SMC/HVC call from kernel running at EL1 to hypervisor/secure * monitor firmware running at EL2/EL3. * * Only allow one SMC and one HVC per system. * * The service support multiple clients. * * The client must open a channel before sending any request and * close the channel immediately after complete. The service only * allow one channel at one time. * * The service will return the SMC/HVC return value to the client * via callback function. * * The client state machine * - INVALID: Invalid state before registration. * - IDLE : Initial state. * - OPEN : The client will switch from IDLE to OPEN once it * successfully open the channel. On the other hand, it * will switch from OPEN to IDLE state once it successfully * close the channel. * - ABORT : The client has closed the channel, however, there are * incomplete transactions being left over. The service * will only move the client back to IDLE state once all * transactions completed. The client is not allowed to * re-open the channel when in ABORT state/ */ #include <zephyr/kernel.h> #include <zephyr/arch/arm64/arm-smccc.h> #include <zephyr/drivers/sip_svc/sip_svc_proto.h> #define SIP_SVC_CLIENT_ST_INVALID 0 #define SIP_SVC_CLIENT_ST_IDLE 1 #define SIP_SVC_CLIENT_ST_OPEN 2 #define SIP_SVC_CLIENT_ST_ABORT 3 /** @brief ARM sip service callback function prototype for response after completion * * On success , response is returned via a callback to the user. * * @param c_token Client's token * @param res pointer to struct sip_svc_response */ typedef void (*sip_svc_cb_fn)(uint32_t c_token, struct sip_svc_response *res); /** * @brief Register a client on ARM SiP service * * On success, the client will be at IDLE state in the service and * the service will return a token to the client. The client can then * use the token to open the channel on the service and communicate * with hypervisor/secure monitor firmware running at EL2/EL3. * * @param ctrl Pointer to controller instance whose service provides ARM SMC/HVC * SiP services. * @param priv_data Pointer to client private data. * * @retval token_id on success. * @retval SIP_SVC_ID_INVALID invalid arguments, failure to allocate a client id and failure to get * a lock. */ uint32_t sip_svc_register(void *ctrl, void *priv_data); /** * @brief Unregister a client on ARM SiP service * * On success, detach the client from the service. Unregistration * is only allowed when all transactions belong to the client are closed. * * @param ctrl Pointer to controller instance which provides ARM SiP services. * @param c_token Client's token * * @retval 0 on success. * @retval -EINVALinvalid arguments. * @retval -ENODATA if client is not registered correctly. * @retval -EBUSY if client has pending transactions. * @retval -ECANCELED if client is not in IDLE state. * @retval -ENOLCK if failure in acquiring mutex. */ int sip_svc_unregister(void *ctrl, uint32_t c_token); /** * @brief Client requests to open a channel on ARM SiP service. * * Client must open a channel before sending any request via * SMC/HVC to hypervisor/secure monitor firmware running at EL2/EL3. * * The service only allows one opened channel at one time and it is protected * by mutex. * * @param ctrl Pointer to controller instance which provides ARM SiP services. * @param c_token Client's token * @param k_timeout Waiting time if the mutex have been locked. * When the mutex have been locked: * - returns non-zero error code immediately if value is K_NO_WAIT * - wait forever if the value is K_FOREVER * - otherwise, for the given time * * @retval 0 on success. * @retval -EINVAL invalid arguments. * @retval -ETIMEDOUT timeout expiry. * @retval -EALREADY client state is already open. */ int sip_svc_open(void *ctrl, uint32_t c_token, k_timeout_t k_timeout); /** * @brief Client requests to close the channel on ARM SiP services. * * Client must close the channel immediately once complete. * * @param ctrl Pointer to controller instance which provides ARM SiP services. * @param c_token Client's token * @param pre_close_req pre close request sent to lower layer on channel close. * * @retval 0 on success, negative errno on failure. * @retval -EINVAL invalid arguments. * @retval -ENOTSUP error on sending pre_close_request. * @retval -EPROTO client is not in OPEN state. */ int sip_svc_close(void *ctrl, uint32_t c_token, struct sip_svc_request *pre_close_req); /** * @brief Client requests to send a SMC/HVC call to EL3/EL2 * * Client must open a channel on the device before using this function. * This function is non-blocking and can be called from any context. The * service will return a Transaction ID to the client if the request * is being accepted. Client callback is called when the transaction is * completed. * * @param ctrl Pointer to controller instance which provides ARM SiP services. * @param c_token Client's token * @param req Address to the user input in struct sip_svc_request format. * @param cb Callback. SMC/SVC return value will be passed to client via * context in struct sip_svc_response format in callback. * * @retval transaction id on success. * @retval -EINVAL invalid arguments. * @retval -EOPNOTSUPP invalid command id or function id. * @retval -ESRCH invalid client state. * @retval -ENOMEM failure to allocate memory. * @retval -ENOMSG failure to insert into database. * @retval -ENOBUF failure to insert into msgq. * @retval -ENOLCK failure to get lock. * @retval -EHOSTDOWN sip_svc thread not present. * @retval -ENOTSUP check for unsupported condition. */ int sip_svc_send(void *ctrl, uint32_t c_token, struct sip_svc_request *req, sip_svc_cb_fn cb); /** * @brief Get the address pointer to the client private data. * * The pointer is provided by client during registration. * * @param ctrl Pointer to controller instance which provides ARM SiP service. * @param c_token Client's token * * @retval Address pointer to the client private data. * @retval NULL invalid arguments and failure to get lock. */ void *sip_svc_get_priv_data(void *ctrl, uint32_t c_token); /** * @brief get the ARM SiP service handle * * @param method Pointer to controller instance which provides ARM SiP service. * * @retval Valid pointer. * @retval NULL invalid arguments and on providing unsupported method name. */ void *sip_svc_get_controller(char *method); #endif /* ZEPHYR_INCLUDE_SIP_SVC_H_ */ ```
/content/code_sandbox/include/zephyr/sip_svc/sip_svc.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,604
```objective-c /* * */ #ifndef ZEPHYR_SIP_SVC_CONTROLLER_H_ #define ZEPHYR_SIP_SVC_CONTROLLER_H_ /** * @note This file should only be included by sip_svc driver. */ #ifdef CONFIG_ARM_SIP_SVC_SUBSYS #include <zephyr/sys/atomic.h> /** * @brief Length of SVC conduit name in sip svc subsystem. * */ #define SIP_SVC_SUBSYS_CONDUIT_NAME_LENGTH (4U) /** * @brief Open lock states in sip_svc atomic variable */ enum open_state { SIP_SVC_OPEN_UNLOCKED = 0, SIP_SVC_OPEN_LOCKED }; /** * @brief Arm SiP Service client data. * */ struct sip_svc_client { /* Client id internal to sip_svc*/ uint32_t id; /* Client's token id provided back to client during sip_svc_register() */ uint32_t token; /* Client's state */ uint32_t state; /* Total Number of on-going transaction of the client */ uint32_t active_trans_cnt; /* Private data of each client , Provided during sip_svc_register() */ void *priv_data; /* Transaction id pool for each client */ struct sip_svc_id_pool *trans_idx_pool; }; /** * @brief Arm SiP Services controller data. * */ struct sip_svc_controller { /* Initialization status*/ bool init; /* Total number of clients*/ const uint32_t num_clients; /* Maximum allowable transactions in the system per controller*/ const uint32_t max_transactions; /* Response size of buffer used for ASYNC transaction*/ const uint32_t resp_size; /* Total Number of active transactions */ uint32_t active_job_cnt; /* Active ASYNC transactions */ uint32_t active_async_job_cnt; /* Supervisory call name , got from dts entry */ char method[SIP_SVC_SUBSYS_CONDUIT_NAME_LENGTH]; /* Pointer to driver instance */ const struct device *dev; /* Pointer to client id pool */ struct sip_svc_id_pool *client_id_pool; /* Pointer to database for storing arguments from sip_svc_send() */ struct sip_svc_id_map *trans_id_map; /* Pointer to client array */ struct sip_svc_client *clients; /* Pointer to Buffer used for storing response from lower layers */ uint8_t *async_resp_data; /* Thread id of sip_svc thread */ k_tid_t tid; #if CONFIG_ARM_SIP_SVC_SUBSYS_SINGLY_OPEN /* Atomic variable to restrict one client access */ atomic_t open_lock; #endif /* Mutex for protecting database access */ struct k_mutex data_mutex; /* msgq for sending sip_svc_request to sip_svc thread */ struct k_msgq req_msgq; /* sip_svc thread object */ struct k_thread thread; /* Stack object of sip_svc thread */ K_KERNEL_STACK_MEMBER(stack, CONFIG_ARM_SIP_SVC_SUBSYS_THREAD_STACK_SIZE); }; /** * @brief Controller define used by sip_svc driver to instantiate each controller. * Each sip_svc driver will use this API to instantiate a controller for sip_svc * subsystem to consume, for more details check @ref ITERABLE_SECTION_RAM() */ #define SIP_SVC_CONTROLLER_DEFINE(inst, conduit_name, sip_dev, sip_num_clients, \ sip_max_transactions, sip_resp_size) \ BUILD_ASSERT( \ ((sip_num_clients <= CONFIG_ARM_SIP_SVC_SUBSYS_MAX_CLIENT_COUNT) && \ (sip_num_clients > 0)), \ "Number of client should be within 1 and ARM_SIP_SVC_SUBSYS_MAX_CLIENT_COUNT"); \ static STRUCT_SECTION_ITERABLE(sip_svc_controller, sip_svc_##inst) = { \ .method = conduit_name, \ .dev = sip_dev, \ .num_clients = sip_num_clients, \ .max_transactions = sip_max_transactions, \ .resp_size = sip_resp_size, \ } #else #define SIP_SVC_CONTROLLER_DEFINE(inst, conduit_name, sip_dev, sip_num_clients, \ sip_max_transactions, sip_resp_size) #endif #endif /* ZEPHYR_SIP_SVC_CONTROLLER_H_ */ ```
/content/code_sandbox/include/zephyr/sip_svc/sip_svc_controller.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
867
```objective-c /* * */ /** * @file * @brief Public API for SDIO subsystem */ #ifndef ZEPHYR_INCLUDE_SD_SDIO_H_ #define ZEPHYR_INCLUDE_SD_SDIO_H_ #include <zephyr/device.h> #include <zephyr/drivers/sdhc.h> #include <zephyr/sd/sd.h> #ifdef __cplusplus extern "C" { #endif /** * @brief Initialize SDIO function. * * Initializes SDIO card function. The card function will not be enabled, * but after this call returns the SDIO function structure can be used to read * and write data from the card. * @param func: function structure to initialize * @param card: SD card to enable function on * @param num: function number to initialize * @retval 0 function was initialized successfully * @retval -EIO: I/O error */ int sdio_init_func(struct sd_card *card, struct sdio_func *func, enum sdio_func_num num); /** * @brief Enable SDIO function * * Enables SDIO card function. @ref sdio_init_func must be called to * initialized the function structure before enabling it in the card. * @param func: function to enable * @retval 0 function was enabled successfully * @retval -ETIMEDOUT: card I/O timed out * @retval -EIO: I/O error */ int sdio_enable_func(struct sdio_func *func); /** * @brief Set block size of SDIO function * * Set desired block size for SDIO function, used by block transfers * to SDIO registers. * @param func: function to set block size for * @param bsize: block size * @retval 0 block size was set * @retval -EINVAL: unsupported/invalid block size * @retval -EIO: I/O error */ int sdio_set_block_size(struct sdio_func *func, uint16_t bsize); /** * @brief Read byte from SDIO register * * Reads byte from SDIO register * @param func: function to read from * @param reg: register address to read from * @param val: filled with byte value read from register * @retval 0 read succeeded * @retval -EBUSY: card is busy with another request * @retval -ETIMEDOUT: card read timed out * @retval -EIO: I/O error */ int sdio_read_byte(struct sdio_func *func, uint32_t reg, uint8_t *val); /** * @brief Write byte to SDIO register * * Writes byte to SDIO register * @param func: function to write to * @param reg: register address to write to * @param write_val: value to write to register * @retval 0 write succeeded * @retval -EBUSY: card is busy with another request * @retval -ETIMEDOUT: card write timed out * @retval -EIO: I/O error */ int sdio_write_byte(struct sdio_func *func, uint32_t reg, uint8_t write_val); /** * @brief Write byte to SDIO register, and read result * * Writes byte to SDIO register, and reads the register after write * @param func: function to write to * @param reg: register address to write to * @param write_val: value to write to register * @param read_val: filled with value read from register * @retval 0 write succeeded * @retval -EBUSY: card is busy with another request * @retval -ETIMEDOUT: card write timed out * @retval -EIO: I/O error */ int sdio_rw_byte(struct sdio_func *func, uint32_t reg, uint8_t write_val, uint8_t *read_val); /** * @brief Read bytes from SDIO fifo * * Reads bytes from SDIO register, treating it as a fifo. Reads will * all be done from same address. * @param func: function to read from * @param reg: register address of fifo * @param data: filled with data read from fifo * @param len: length of data to read from card * @retval 0 read succeeded * @retval -EBUSY: card is busy with another request * @retval -ETIMEDOUT: card read timed out * @retval -EIO: I/O error */ int sdio_read_fifo(struct sdio_func *func, uint32_t reg, uint8_t *data, uint32_t len); /** * @brief Write bytes to SDIO fifo * * Writes bytes to SDIO register, treating it as a fifo. Writes will * all be done to same address. * @param func: function to write to * @param reg: register address of fifo * @param data: data to write to fifo * @param len: length of data to write to card * @retval 0 write succeeded * @retval -EBUSY: card is busy with another request * @retval -ETIMEDOUT: card write timed out * @retval -EIO: I/O error */ int sdio_write_fifo(struct sdio_func *func, uint32_t reg, uint8_t *data, uint32_t len); /** * @brief Read blocks from SDIO fifo * * Reads blocks from SDIO register, treating it as a fifo. Reads will * all be done from same address. * @param func: function to read from * @param reg: register address of fifo * @param data: filled with data read from fifo * @param blocks: number of blocks to read from fifo * @retval 0 read succeeded * @retval -EBUSY: card is busy with another request * @retval -ETIMEDOUT: card read timed out * @retval -EIO: I/O error */ int sdio_read_blocks_fifo(struct sdio_func *func, uint32_t reg, uint8_t *data, uint32_t blocks); /** * @brief Write blocks to SDIO fifo * * Writes blocks from SDIO register, treating it as a fifo. Writes will * all be done to same address. * @param func: function to write to * @param reg: register address of fifo * @param data: data to write to fifo * @param blocks: number of blocks to write to fifo * @retval 0 write succeeded * @retval -EBUSY: card is busy with another request * @retval -ETIMEDOUT: card write timed out * @retval -EIO: I/O error */ int sdio_write_blocks_fifo(struct sdio_func *func, uint32_t reg, uint8_t *data, uint32_t blocks); /** * @brief Copy bytes from an SDIO card * * Copies bytes from an SDIO card, starting from provided address. * @param func: function to read from * @param reg: register address to start copy at * @param data: buffer to copy data into * @param len: length of data to read * @retval 0 read succeeded * @retval -EBUSY: card is busy with another request * @retval -ETIMEDOUT: card read timed out * @retval -EIO: I/O error */ int sdio_read_addr(struct sdio_func *func, uint32_t reg, uint8_t *data, uint32_t len); /** * @brief Copy bytes to an SDIO card * * Copies bytes to an SDIO card, starting from provided address. * * @param func: function to write to * @param reg: register address to start copy at * @param data: buffer to copy data from * @param len: length of data to write * @retval 0 write succeeded * @retval -EBUSY: card is busy with another request * @retval -ETIMEDOUT: card write timed out * @retval -EIO: I/O error */ int sdio_write_addr(struct sdio_func *func, uint32_t reg, uint8_t *data, uint32_t len); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_SD_SDMMC_H_ */ ```
/content/code_sandbox/include/zephyr/sd/sdio.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,786
```objective-c /* * */ #ifndef SHELL_H__ #define SHELL_H__ #include <zephyr/kernel.h> #include <zephyr/shell/shell_types.h> #include <zephyr/shell/shell_history.h> #include <zephyr/shell/shell_fprintf.h> #include <zephyr/shell/shell_log_backend.h> #include <zephyr/shell/shell_string_conv.h> #include <zephyr/logging/log_instance.h> #include <zephyr/logging/log.h> #include <zephyr/sys/iterable_sections.h> #include <zephyr/sys/util.h> #if defined CONFIG_SHELL_GETOPT #include <getopt.h> #endif #ifdef __cplusplus extern "C" { #endif #ifndef CONFIG_SHELL_PROMPT_BUFF_SIZE #define CONFIG_SHELL_PROMPT_BUFF_SIZE 0 #endif #ifndef CONFIG_SHELL_CMD_BUFF_SIZE #define CONFIG_SHELL_CMD_BUFF_SIZE 0 #endif #ifndef CONFIG_SHELL_PRINTF_BUFF_SIZE #define CONFIG_SHELL_PRINTF_BUFF_SIZE 0 #endif #ifndef CONFIG_SHELL_HISTORY_BUFFER #define CONFIG_SHELL_HISTORY_BUFFER 0 #endif #define Z_SHELL_CMD_ROOT_LVL (0u) #define SHELL_HEXDUMP_BYTES_IN_LINE 16 /** * @brief Flag indicates that optional arguments will be treated as one, * unformatted argument. * * By default, shell is parsing all arguments, treats all spaces as argument * separators unless they are within quotation marks which are removed in that * case. If command rely on unformatted argument then this flag shall be used * in place of number of optional arguments in command definition to indicate * that only mandatory arguments shall be parsed and remaining command string is * passed as a raw string. */ #define SHELL_OPT_ARG_RAW (0xFE) /** * @brief Flag indicating that number of optional arguments is not limited. */ #define SHELL_OPT_ARG_CHECK_SKIP (0xFF) /** * @brief Flag indicating maximum number of optional arguments that can be * validated. */ #define SHELL_OPT_ARG_MAX (0xFD) /** * @brief Shell API * @defgroup shell_api Shell API * @since 1.14 * @version 1.0.0 * @ingroup os_services * @{ */ struct shell_static_entry; /** * @brief Shell dynamic command descriptor. * * @details Function shall fill the received shell_static_entry structure * with requested (idx) dynamic subcommand data. If there is more than * one dynamic subcommand available, the function shall ensure that the * returned commands: entry->syntax are sorted in alphabetical order. * If idx exceeds the available dynamic subcommands, the function must * write to entry->syntax NULL value. This will indicate to the shell * module that there are no more dynamic commands to read. */ typedef void (*shell_dynamic_get)(size_t idx, struct shell_static_entry *entry); /** * @brief Shell command descriptor. */ union shell_cmd_entry { /** Pointer to function returning dynamic commands.*/ shell_dynamic_get dynamic_get; /** Pointer to array of static commands. */ const struct shell_static_entry *entry; }; struct shell; struct shell_static_args { uint8_t mandatory; /*!< Number of mandatory arguments. */ uint8_t optional; /*!< Number of optional arguments. */ }; /** * @brief Get by index a device that matches . * * This can be used, for example, to identify I2C_1 as the second I2C * device. * * Devices that failed to initialize or do not have a non-empty name * are excluded from the candidates for a match. * * @param idx the device number starting from zero. * * @param prefix optional name prefix used to restrict candidate * devices. Indexing is done relative to devices with names that * start with this text. Pass null if no prefix match is required. */ const struct device *shell_device_lookup(size_t idx, const char *prefix); /** * @brief Filter callback type, for use with shell_device_lookup_filter * * This is used as an argument of shell_device_lookup_filter to only return * devices that match a specific condition, implemented by the filter. * * @param dev pointer to a struct device. * * @return bool, true if the filter matches the device type. */ typedef bool (*shell_device_filter_t)(const struct device *dev); /** * @brief Get a device by index and filter. * * This can be used to return devices matching a specific type. * * Devices that the filter returns false for, failed to initialize or do not * have a non-empty name are excluded from the candidates for a match. * * @param idx the device number starting from zero. * * @param filter a pointer to a shell_device_filter_t function that returns * true if the device matches the filter. */ const struct device *shell_device_filter(size_t idx, shell_device_filter_t filter); /** * @brief Shell command handler prototype. * * @param sh Shell instance. * @param argc Arguments count. * @param argv Arguments. * * @retval 0 Successful command execution. * @retval 1 Help printed and command not executed. * @retval -EINVAL Argument validation failed. * @retval -ENOEXEC Command not executed. */ typedef int (*shell_cmd_handler)(const struct shell *sh, size_t argc, char **argv); /** * @brief Shell dictionary command handler prototype. * * @param sh Shell instance. * @param argc Arguments count. * @param argv Arguments. * @param data Pointer to the user data. * * @retval 0 Successful command execution. * @retval 1 Help printed and command not executed. * @retval -EINVAL Argument validation failed. * @retval -ENOEXEC Command not executed. */ typedef int (*shell_dict_cmd_handler)(const struct shell *sh, size_t argc, char **argv, void *data); /* When entries are added to the memory section a padding is applied for * the posix architecture with 64bits builds and x86_64 targets. Adding padding to allow handle data * in the memory section as array. */ #if (defined(CONFIG_ARCH_POSIX) && defined(CONFIG_64BIT)) || defined(CONFIG_X86_64) #define Z_SHELL_STATIC_ENTRY_PADDING 24 #else #define Z_SHELL_STATIC_ENTRY_PADDING 0 #endif /* * @brief Shell static command descriptor. */ struct shell_static_entry { const char *syntax; /*!< Command syntax strings. */ const char *help; /*!< Command help string. */ const union shell_cmd_entry *subcmd; /*!< Pointer to subcommand. */ shell_cmd_handler handler; /*!< Command handler. */ struct shell_static_args args; /*!< Command arguments. */ uint8_t padding[Z_SHELL_STATIC_ENTRY_PADDING]; }; /** * @brief Macro for defining and adding a root command (level 0) with required * number of arguments. * * @note Each root command shall have unique syntax. If a command will be called * with wrong number of arguments shell will print an error message and command * handler will not be called. * * @param[in] syntax Command syntax (for example: history). * @param[in] subcmd Pointer to a subcommands array. * @param[in] help Pointer to a command help string. * @param[in] handler Pointer to a function handler. * @param[in] mandatory Number of mandatory arguments including command name. * @param[in] optional Number of optional arguments. */ #define SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, \ mandatory, optional) \ static const struct shell_static_entry UTIL_CAT(_shell_, syntax) = \ SHELL_CMD_ARG(syntax, subcmd, help, handler, mandatory, optional); \ static const TYPE_SECTION_ITERABLE(union shell_cmd_entry, \ UTIL_CAT(shell_cmd_, syntax), shell_root_cmds, \ UTIL_CAT(shell_cmd_, syntax) \ ) = { \ .entry = &UTIL_CAT(_shell_, syntax) \ } /** * @brief Macro for defining and adding a conditional root command (level 0) * with required number of arguments. * * @see SHELL_CMD_ARG_REGISTER for details. * * Macro can be used to create a command which can be conditionally present. * It is and alternative to \#ifdefs around command registration and command * handler. If command is disabled handler and subcommands are removed from * the application. * * @param[in] flag Compile time flag. Command is present only if flag * exists and equals 1. * @param[in] syntax Command syntax (for example: history). * @param[in] subcmd Pointer to a subcommands array. * @param[in] help Pointer to a command help string. * @param[in] handler Pointer to a function handler. * @param[in] mandatory Number of mandatory arguments including command name. * @param[in] optional Number of optional arguments. */ #define SHELL_COND_CMD_ARG_REGISTER(flag, syntax, subcmd, help, handler, \ mandatory, optional) \ COND_CODE_1(\ flag, \ (\ SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, \ mandatory, optional) \ ), \ (\ static shell_cmd_handler dummy_##syntax##_handler __unused = \ handler;\ static const union shell_cmd_entry *dummy_subcmd_##syntax \ __unused = subcmd\ ) \ ) /** * @brief Macro for defining and adding a root command (level 0) with * arguments. * * @note All root commands must have different name. * * @param[in] syntax Command syntax (for example: history). * @param[in] subcmd Pointer to a subcommands array. * @param[in] help Pointer to a command help string. * @param[in] handler Pointer to a function handler. */ #define SHELL_CMD_REGISTER(syntax, subcmd, help, handler) \ SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, 0, 0) /** * @brief Macro for defining and adding a conditional root command (level 0) * with arguments. * * @see SHELL_COND_CMD_ARG_REGISTER. * * @param[in] flag Compile time flag. Command is present only if flag * exists and equals 1. * @param[in] syntax Command syntax (for example: history). * @param[in] subcmd Pointer to a subcommands array. * @param[in] help Pointer to a command help string. * @param[in] handler Pointer to a function handler. */ #define SHELL_COND_CMD_REGISTER(flag, syntax, subcmd, help, handler) \ SHELL_COND_CMD_ARG_REGISTER(flag, syntax, subcmd, help, handler, 0, 0) /** * @brief Macro for creating a subcommand set. It must be used outside of any * function body. * * Example usage: * @code{.c} * SHELL_STATIC_SUBCMD_SET_CREATE( * foo, * SHELL_CMD(abc, ...), * SHELL_CMD(def, ...), * SHELL_SUBCMD_SET_END * ) * @endcode * * @param[in] name Name of the subcommand set. * @param[in] ... List of commands created with @ref SHELL_CMD_ARG or * or @ref SHELL_CMD */ #define SHELL_STATIC_SUBCMD_SET_CREATE(name, ...) \ static const struct shell_static_entry shell_##name[] = { \ __VA_ARGS__ \ }; \ static const union shell_cmd_entry name = { \ .entry = shell_##name \ } #define Z_SHELL_UNDERSCORE(x) _##x #define Z_SHELL_SUBCMD_NAME(...) \ UTIL_CAT(shell_subcmds, MACRO_MAP_CAT(Z_SHELL_UNDERSCORE, __VA_ARGS__)) #define Z_SHELL_SUBCMD_SECTION_TAG(...) MACRO_MAP_CAT(Z_SHELL_UNDERSCORE, __VA_ARGS__) #define Z_SHELL_SUBCMD_SET_SECTION_TAG(x) \ Z_SHELL_SUBCMD_SECTION_TAG(NUM_VA_ARGS_LESS_1 x, __DEBRACKET x) #define Z_SHELL_SUBCMD_ADD_SECTION_TAG(x, y) \ Z_SHELL_SUBCMD_SECTION_TAG(NUM_VA_ARGS_LESS_1 x, __DEBRACKET x, y) /** @brief Create set of subcommands. * * Commands to this set are added using @ref SHELL_SUBCMD_ADD and @ref SHELL_SUBCMD_COND_ADD. * Commands can be added from multiple files. * * @param[in] _name Name of the set. @p _name is used to refer the set in the parent * command. * * @param[in] _parent Set of comma separated parent commands in parenthesis, e.g. * (foo_cmd) if subcommands are for the root command "foo_cmd". */ #define SHELL_SUBCMD_SET_CREATE(_name, _parent) \ static const TYPE_SECTION_ITERABLE(struct shell_static_entry, _name, shell_subcmds, \ Z_SHELL_SUBCMD_SET_SECTION_TAG(_parent)) /** @brief Conditionally add command to the set of subcommands. * * Add command to the set created with @ref SHELL_SUBCMD_SET_CREATE. * * @note The name of the section is formed as concatenation of number of parent * commands, names of all parent commands and own syntax. Number of parent commands * is added to ensure that section prefix is unique. Without it subcommands of * (foo) and (foo, cmd1) would mix. * * @param[in] _flag Compile time flag. Command is present only if flag * exists and equals 1. * @param[in] _parent Parent command sequence. Comma separated in parenthesis. * @param[in] _syntax Command syntax (for example: history). * @param[in] _subcmd Pointer to a subcommands array. * @param[in] _help Pointer to a command help string. * @param[in] _handler Pointer to a function handler. * @param[in] _mand Number of mandatory arguments including command name. * @param[in] _opt Number of optional arguments. */ #define SHELL_SUBCMD_COND_ADD(_flag, _parent, _syntax, _subcmd, _help, _handler, \ _mand, _opt) \ COND_CODE_1(_flag, \ (static const TYPE_SECTION_ITERABLE(struct shell_static_entry, \ Z_SHELL_SUBCMD_NAME(__DEBRACKET _parent, _syntax), \ shell_subcmds, \ Z_SHELL_SUBCMD_ADD_SECTION_TAG(_parent, _syntax)) = \ SHELL_EXPR_CMD_ARG(1, _syntax, _subcmd, _help, \ _handler, _mand, _opt)\ ), \ (static shell_cmd_handler dummy_handler_##_syntax __unused = _handler;\ static const union shell_cmd_entry dummy_subcmd_##_syntax __unused = { \ .entry = (const struct shell_static_entry *)_subcmd\ } \ ) \ ) /** @brief Add command to the set of subcommands. * * Add command to the set created with @ref SHELL_SUBCMD_SET_CREATE. * * @param[in] _parent Parent command sequence. Comma separated in parenthesis. * @param[in] _syntax Command syntax (for example: history). * @param[in] _subcmd Pointer to a subcommands array. * @param[in] _help Pointer to a command help string. * @param[in] _handler Pointer to a function handler. * @param[in] _mand Number of mandatory arguments including command name. * @param[in] _opt Number of optional arguments. */ #define SHELL_SUBCMD_ADD(_parent, _syntax, _subcmd, _help, _handler, _mand, _opt) \ SHELL_SUBCMD_COND_ADD(1, _parent, _syntax, _subcmd, _help, _handler, _mand, _opt) /** * @brief Define ending subcommands set. * */ #define SHELL_SUBCMD_SET_END {NULL} /** * @brief Macro for creating a dynamic entry. * * @param[in] name Name of the dynamic entry. * @param[in] get Pointer to the function returning dynamic commands array */ #define SHELL_DYNAMIC_CMD_CREATE(name, get) \ static const TYPE_SECTION_ITERABLE(union shell_cmd_entry, name, \ shell_dynamic_subcmds, name) = \ { \ .dynamic_get = get \ } /** * @brief Initializes a shell command with arguments. * * @note If a command will be called with wrong number of arguments shell will * print an error message and command handler will not be called. * * @param[in] syntax Command syntax (for example: history). * @param[in] subcmd Pointer to a subcommands array. * @param[in] help Pointer to a command help string. * @param[in] handler Pointer to a function handler. * @param[in] mand Number of mandatory arguments including command name. * @param[in] opt Number of optional arguments. */ #define SHELL_CMD_ARG(syntax, subcmd, help, handler, mand, opt) \ SHELL_EXPR_CMD_ARG(1, syntax, subcmd, help, handler, mand, opt) /** * @brief Initializes a conditional shell command with arguments. * * @see SHELL_CMD_ARG. Based on the flag, creates a valid entry or an empty * command which is ignored by the shell. It is an alternative to \#ifdefs * around command registration and command handler. However, empty structure is * present in the flash even if command is disabled (subcommands and handler are * removed). Macro internally handles case if flag is not defined so flag must * be provided without any wrapper, e.g.: SHELL_COND_CMD_ARG(CONFIG_FOO, ...) * * @param[in] flag Compile time flag. Command is present only if flag * exists and equals 1. * @param[in] syntax Command syntax (for example: history). * @param[in] subcmd Pointer to a subcommands array. * @param[in] help Pointer to a command help string. * @param[in] handler Pointer to a function handler. * @param[in] mand Number of mandatory arguments including command name. * @param[in] opt Number of optional arguments. */ #define SHELL_COND_CMD_ARG(flag, syntax, subcmd, help, handler, mand, opt) \ SHELL_EXPR_CMD_ARG(IS_ENABLED(flag), syntax, subcmd, help, \ handler, mand, opt) /** * @brief Initializes a conditional shell command with arguments if expression * gives non-zero result at compile time. * * @see SHELL_CMD_ARG. Based on the expression, creates a valid entry or an * empty command which is ignored by the shell. It should be used instead of * @ref SHELL_COND_CMD_ARG if condition is not a single configuration flag, * e.g.: * SHELL_EXPR_CMD_ARG(IS_ENABLED(CONFIG_FOO) && * IS_ENABLED(CONFIG_FOO_SETTING_1), ...) * * @param[in] _expr Expression. * @param[in] _syntax Command syntax (for example: history). * @param[in] _subcmd Pointer to a subcommands array. * @param[in] _help Pointer to a command help string. * @param[in] _handler Pointer to a function handler. * @param[in] _mand Number of mandatory arguments including command name. * @param[in] _opt Number of optional arguments. */ #define SHELL_EXPR_CMD_ARG(_expr, _syntax, _subcmd, _help, _handler, \ _mand, _opt) \ { \ .syntax = (_expr) ? (const char *)STRINGIFY(_syntax) : "", \ .help = (_expr) ? (const char *)_help : NULL, \ .subcmd = (const union shell_cmd_entry *)((_expr) ? \ _subcmd : NULL), \ .handler = (shell_cmd_handler)((_expr) ? _handler : NULL), \ .args = { .mandatory = _mand, .optional = _opt} \ } /** * @brief Initializes a shell command. * * @param[in] _syntax Command syntax (for example: history). * @param[in] _subcmd Pointer to a subcommands array. * @param[in] _help Pointer to a command help string. * @param[in] _handler Pointer to a function handler. */ #define SHELL_CMD(_syntax, _subcmd, _help, _handler) \ SHELL_CMD_ARG(_syntax, _subcmd, _help, _handler, 0, 0) /** * @brief Initializes a conditional shell command. * * @see SHELL_COND_CMD_ARG. * * @param[in] _flag Compile time flag. Command is present only if flag * exists and equals 1. * @param[in] _syntax Command syntax (for example: history). * @param[in] _subcmd Pointer to a subcommands array. * @param[in] _help Pointer to a command help string. * @param[in] _handler Pointer to a function handler. */ #define SHELL_COND_CMD(_flag, _syntax, _subcmd, _help, _handler) \ SHELL_COND_CMD_ARG(_flag, _syntax, _subcmd, _help, _handler, 0, 0) /** * @brief Initializes shell command if expression gives non-zero result at * compile time. * * @see SHELL_EXPR_CMD_ARG. * * @param[in] _expr Compile time expression. Command is present only if * expression is non-zero. * @param[in] _syntax Command syntax (for example: history). * @param[in] _subcmd Pointer to a subcommands array. * @param[in] _help Pointer to a command help string. * @param[in] _handler Pointer to a function handler. */ #define SHELL_EXPR_CMD(_expr, _syntax, _subcmd, _help, _handler) \ SHELL_EXPR_CMD_ARG(_expr, _syntax, _subcmd, _help, _handler, 0, 0) /* Internal macro used for creating handlers for dictionary commands. */ #define Z_SHELL_CMD_DICT_HANDLER_CREATE(_data, _handler) \ static int UTIL_CAT(UTIL_CAT(cmd_dict_, UTIL_CAT(_handler, _)), \ GET_ARG_N(1, __DEBRACKET _data))( \ const struct shell *sh, size_t argc, char **argv) \ { \ return _handler(sh, argc, argv, \ (void *)GET_ARG_N(2, __DEBRACKET _data)); \ } /* Internal macro used for creating dictionary commands. */ #define SHELL_CMD_DICT_CREATE(_data, _handler) \ SHELL_CMD_ARG(GET_ARG_N(1, __DEBRACKET _data), NULL, GET_ARG_N(3, __DEBRACKET _data), \ UTIL_CAT(UTIL_CAT(cmd_dict_, UTIL_CAT(_handler, _)), \ GET_ARG_N(1, __DEBRACKET _data)), 1, 0) /** * @brief Initializes shell dictionary commands. * * This is a special kind of static commands. Dictionary commands can be used * every time you want to use a pair: (string <-> corresponding data) in * a command handler. The string is usually a verbal description of a given * data. The idea is to use the string as a command syntax that can be prompted * by the shell and corresponding data can be used to process the command. * * @param[in] _name Name of the dictionary subcommand set * @param[in] _handler Command handler common for all dictionary commands. * @see shell_dict_cmd_handler * @param[in] ... Dictionary triplets: (command_syntax, value, helper). Value will be * passed to the _handler as user data. * * Example usage: * @code{.c} * static int my_handler(const struct shell *sh, * size_t argc, char **argv, void *data) * { * int val = (int)data; * * shell_print(sh, "(syntax, value) : (%s, %d)", argv[0], val); * return 0; * } * * SHELL_SUBCMD_DICT_SET_CREATE(sub_dict_cmds, my_handler, * (value_0, 0, "value 0"), (value_1, 1, "value 1"), * (value_2, 2, "value 2"), (value_3, 3, "value 3") * ); * SHELL_CMD_REGISTER(dictionary, &sub_dict_cmds, NULL, NULL); * @endcode */ #define SHELL_SUBCMD_DICT_SET_CREATE(_name, _handler, ...) \ FOR_EACH_FIXED_ARG(Z_SHELL_CMD_DICT_HANDLER_CREATE, (), \ _handler, __VA_ARGS__) \ SHELL_STATIC_SUBCMD_SET_CREATE(_name, \ FOR_EACH_FIXED_ARG(SHELL_CMD_DICT_CREATE, (,), _handler, __VA_ARGS__), \ SHELL_SUBCMD_SET_END \ ) /** * @internal @brief Internal shell state in response to data received from the * terminal. */ enum shell_receive_state { SHELL_RECEIVE_DEFAULT, SHELL_RECEIVE_ESC, SHELL_RECEIVE_ESC_SEQ, SHELL_RECEIVE_TILDE_EXP }; /** * @internal @brief Internal shell state. */ enum shell_state { SHELL_STATE_UNINITIALIZED, SHELL_STATE_INITIALIZED, SHELL_STATE_ACTIVE, SHELL_STATE_PANIC_MODE_ACTIVE, /*!< Panic activated.*/ SHELL_STATE_PANIC_MODE_INACTIVE /*!< Panic requested, not supported.*/ }; /** @brief Shell transport event. */ enum shell_transport_evt { SHELL_TRANSPORT_EVT_RX_RDY, SHELL_TRANSPORT_EVT_TX_RDY }; typedef void (*shell_transport_handler_t)(enum shell_transport_evt evt, void *context); typedef void (*shell_uninit_cb_t)(const struct shell *sh, int res); /** @brief Bypass callback. * * @param sh Shell instance. * @param data Raw data from transport. * @param len Data length. */ typedef void (*shell_bypass_cb_t)(const struct shell *sh, uint8_t *data, size_t len); struct shell_transport; /** * @struct shell_transport_api * @brief Unified shell transport interface. */ struct shell_transport_api { /** * @brief Function for initializing the shell transport interface. * * @param[in] transport Pointer to the transfer instance. * @param[in] config Pointer to instance configuration. * @param[in] evt_handler Event handler. * @param[in] context Pointer to the context passed to event * handler. * * @return Standard error code. */ int (*init)(const struct shell_transport *transport, const void *config, shell_transport_handler_t evt_handler, void *context); /** * @brief Function for uninitializing the shell transport interface. * * @param[in] transport Pointer to the transfer instance. * * @return Standard error code. */ int (*uninit)(const struct shell_transport *transport); /** * @brief Function for enabling transport in given TX mode. * * Function can be used to reconfigure TX to work in blocking mode. * * @param transport Pointer to the transfer instance. * @param blocking_tx If true, the transport TX is enabled in blocking * mode. * * @return NRF_SUCCESS on successful enabling, error otherwise (also if * not supported). */ int (*enable)(const struct shell_transport *transport, bool blocking_tx); /** * @brief Function for writing data to the transport interface. * * @param[in] transport Pointer to the transfer instance. * @param[in] data Pointer to the source buffer. * @param[in] length Source buffer length. * @param[out] cnt Pointer to the sent bytes counter. * * @return Standard error code. */ int (*write)(const struct shell_transport *transport, const void *data, size_t length, size_t *cnt); /** * @brief Function for reading data from the transport interface. * * @param[in] transport Pointer to the transfer instance. * @param[in] data Pointer to the destination buffer. * @param[in] length Destination buffer length. * @param[out] cnt Pointer to the received bytes counter. * * @return Standard error code. */ int (*read)(const struct shell_transport *transport, void *data, size_t length, size_t *cnt); /** * @brief Function called in shell thread loop. * * Can be used for backend operations that require longer execution time * * @param[in] transport Pointer to the transfer instance. */ void (*update)(const struct shell_transport *transport); }; struct shell_transport { const struct shell_transport_api *api; void *ctx; }; /** * @brief Shell statistics structure. */ struct shell_stats { atomic_t log_lost_cnt; /*!< Lost log counter.*/ }; #ifdef CONFIG_SHELL_STATS #define Z_SHELL_STATS_DEFINE(_name) static struct shell_stats _name##_stats #define Z_SHELL_STATS_PTR(_name) (&(_name##_stats)) #else #define Z_SHELL_STATS_DEFINE(_name) #define Z_SHELL_STATS_PTR(_name) NULL #endif /* CONFIG_SHELL_STATS */ /** * @internal @brief Flags for shell backend configuration. */ struct shell_backend_config_flags { uint32_t insert_mode :1; /*!< Controls insert mode for text introduction */ uint32_t echo :1; /*!< Controls shell echo */ uint32_t obscure :1; /*!< If echo on, print asterisk instead */ uint32_t mode_delete :1; /*!< Operation mode of backspace key */ uint32_t use_colors :1; /*!< Controls colored syntax */ uint32_t use_vt100 :1; /*!< Controls VT100 commands usage in shell */ }; BUILD_ASSERT((sizeof(struct shell_backend_config_flags) == sizeof(uint32_t)), "Structure must fit in 4 bytes"); /** * @internal @brief Default backend configuration. */ #define SHELL_DEFAULT_BACKEND_CONFIG_FLAGS \ { \ .insert_mode = 0, \ .echo = 1, \ .obscure = IS_ENABLED(CONFIG_SHELL_START_OBSCURED), \ .mode_delete = 1, \ .use_colors = 1, \ .use_vt100 = 1, \ }; struct shell_backend_ctx_flags { uint32_t processing :1; /*!< Shell is executing process function */ uint32_t tx_rdy :1; uint32_t history_exit :1; /*!< Request to exit history mode */ uint32_t last_nl :8; /*!< Last received new line character */ uint32_t cmd_ctx :1; /*!< Shell is executing command */ uint32_t print_noinit :1; /*!< Print request from not initialized shell */ uint32_t sync_mode :1; /*!< Shell in synchronous mode */ uint32_t handle_log :1; /*!< Shell is handling logger backend */ }; BUILD_ASSERT((sizeof(struct shell_backend_ctx_flags) == sizeof(uint32_t)), "Structure must fit in 4 bytes"); /** * @internal @brief Union for internal shell usage. */ union shell_backend_cfg { atomic_t value; struct shell_backend_config_flags flags; }; /** * @internal @brief Union for internal shell usage. */ union shell_backend_ctx { uint32_t value; struct shell_backend_ctx_flags flags; }; enum shell_signal { SHELL_SIGNAL_RXRDY, SHELL_SIGNAL_LOG_MSG, SHELL_SIGNAL_KILL, SHELL_SIGNAL_TXDONE, /* TXDONE must be last one before SHELL_SIGNALS */ SHELL_SIGNALS }; /** * @brief Shell instance context. */ struct shell_ctx { #if defined(CONFIG_SHELL_PROMPT_CHANGE) && CONFIG_SHELL_PROMPT_CHANGE char prompt[CONFIG_SHELL_PROMPT_BUFF_SIZE]; /*!< shell current prompt. */ #else const char *prompt; #endif enum shell_state state; /*!< Internal module state.*/ enum shell_receive_state receive_state;/*!< Escape sequence indicator.*/ /** Currently executed command.*/ struct shell_static_entry active_cmd; /** New root command. If NULL shell uses default root commands. */ const struct shell_static_entry *selected_cmd; /** VT100 color and cursor position, terminal width.*/ struct shell_vt100_ctx vt100_ctx; /** Callback called from shell thread context when unitialization is * completed just before aborting shell thread. */ shell_uninit_cb_t uninit_cb; /** When bypass is set, all incoming data is passed to the callback. */ shell_bypass_cb_t bypass; /*!< Logging level for a backend. */ uint32_t log_level; #if defined CONFIG_SHELL_GETOPT /*!< getopt context for a shell backend. */ struct getopt_state getopt; #endif uint16_t cmd_buff_len; /*!< Command length.*/ uint16_t cmd_buff_pos; /*!< Command buffer cursor position.*/ uint16_t cmd_tmp_buff_len; /*!< Command length in tmp buffer.*/ /** Command input buffer.*/ char cmd_buff[CONFIG_SHELL_CMD_BUFF_SIZE]; /** Command temporary buffer.*/ char temp_buff[CONFIG_SHELL_CMD_BUFF_SIZE]; /** Printf buffer size.*/ char printf_buff[CONFIG_SHELL_PRINTF_BUFF_SIZE]; volatile union shell_backend_cfg cfg; volatile union shell_backend_ctx ctx; struct k_poll_signal signals[SHELL_SIGNALS]; /** Events that should be used only internally by shell thread. * Event for SHELL_SIGNAL_TXDONE is initialized but unused. */ struct k_poll_event events[SHELL_SIGNALS]; struct k_mutex wr_mtx; k_tid_t tid; int ret_val; }; extern const struct log_backend_api log_backend_shell_api; /** * @brief Flags for setting shell output newline sequence. */ enum shell_flag { SHELL_FLAG_CRLF_DEFAULT = (1<<0), /*!< Do not map CR or LF */ SHELL_FLAG_OLF_CRLF = (1<<1) /*!< Map LF to CRLF on output */ }; /** * @brief Shell instance internals. */ struct shell { const char *default_prompt; /*!< shell default prompt. */ const struct shell_transport *iface; /*!< Transport interface.*/ struct shell_ctx *ctx; /*!< Internal context.*/ struct shell_history *history; const enum shell_flag shell_flag; const struct shell_fprintf *fprintf_ctx; struct shell_stats *stats; const struct shell_log_backend *log_backend; LOG_INSTANCE_PTR_DECLARE(log); const char *name; struct k_thread *thread; k_thread_stack_t *stack; }; extern void z_shell_print_stream(const void *user_ctx, const char *data, size_t data_len); /** * @brief Macro for defining a shell instance. * * @param[in] _name Instance name. * @param[in] _prompt Shell default prompt string. * @param[in] _transport_iface Pointer to the transport interface. * @param[in] _log_queue_size Logger processing queue size. * @param[in] _log_timeout Logger thread timeout in milliseconds on full * log queue. If queue is full logger thread is * blocked for given amount of time before log * message is dropped. * @param[in] _shell_flag Shell output newline sequence. */ #define SHELL_DEFINE(_name, _prompt, _transport_iface, \ _log_queue_size, _log_timeout, _shell_flag) \ static const struct shell _name; \ static struct shell_ctx UTIL_CAT(_name, _ctx); \ static uint8_t _name##_out_buffer[CONFIG_SHELL_PRINTF_BUFF_SIZE]; \ Z_SHELL_LOG_BACKEND_DEFINE(_name, _name##_out_buffer, \ CONFIG_SHELL_PRINTF_BUFF_SIZE, \ _log_queue_size, _log_timeout); \ Z_SHELL_HISTORY_DEFINE(_name##_history, CONFIG_SHELL_HISTORY_BUFFER); \ Z_SHELL_FPRINTF_DEFINE(_name##_fprintf, &_name, _name##_out_buffer, \ CONFIG_SHELL_PRINTF_BUFF_SIZE, \ true, z_shell_print_stream); \ LOG_INSTANCE_REGISTER(shell, _name, CONFIG_SHELL_LOG_LEVEL); \ Z_SHELL_STATS_DEFINE(_name); \ static K_KERNEL_STACK_DEFINE(_name##_stack, CONFIG_SHELL_STACK_SIZE); \ static struct k_thread _name##_thread; \ static const STRUCT_SECTION_ITERABLE(shell, _name) = { \ .default_prompt = _prompt, \ .iface = _transport_iface, \ .ctx = &UTIL_CAT(_name, _ctx), \ .history = IS_ENABLED(CONFIG_SHELL_HISTORY) ? \ &_name##_history : NULL, \ .shell_flag = _shell_flag, \ .fprintf_ctx = &_name##_fprintf, \ .stats = Z_SHELL_STATS_PTR(_name), \ .log_backend = Z_SHELL_LOG_BACKEND_PTR(_name), \ LOG_INSTANCE_PTR_INIT(log, shell, _name) \ .name = STRINGIFY(_name), \ .thread = &_name##_thread, \ .stack = _name##_stack \ } /** * @brief Function for initializing a transport layer and internal shell state. * * @param[in] sh Pointer to shell instance. * @param[in] transport_config Transport configuration during initialization. * @param[in] cfg_flags Initial backend configuration flags. * Shell will copy this data. * @param[in] log_backend If true, the console will be used as logger * backend. * @param[in] init_log_level Default severity level for the logger. * * @return Standard error code. */ int shell_init(const struct shell *sh, const void *transport_config, struct shell_backend_config_flags cfg_flags, bool log_backend, uint32_t init_log_level); /** * @brief Uninitializes the transport layer and the internal shell state. * * @param sh Pointer to shell instance. * @param cb Callback called when uninitialization is completed. */ void shell_uninit(const struct shell *sh, shell_uninit_cb_t cb); /** * @brief Function for starting shell processing. * * @param sh Pointer to the shell instance. * * @return Standard error code. */ int shell_start(const struct shell *sh); /** * @brief Function for stopping shell processing. * * @param sh Pointer to shell instance. * * @return Standard error code. */ int shell_stop(const struct shell *sh); /** * @brief Terminal default text color for shell_fprintf function. */ #define SHELL_NORMAL SHELL_VT100_COLOR_DEFAULT /** * @brief Green text color for shell_fprintf function. */ #define SHELL_INFO SHELL_VT100_COLOR_GREEN /** * @brief Cyan text color for shell_fprintf function. */ #define SHELL_OPTION SHELL_VT100_COLOR_CYAN /** * @brief Yellow text color for shell_fprintf function. */ #define SHELL_WARNING SHELL_VT100_COLOR_YELLOW /** * @brief Red text color for shell_fprintf function. */ #define SHELL_ERROR SHELL_VT100_COLOR_RED /** * @brief printf-like function which sends formatted data stream to the shell. * * This function can be used from the command handler or from threads, but not * from an interrupt context. * * @param[in] sh Pointer to the shell instance. * @param[in] color Printed text color. * @param[in] fmt Format string. * @param[in] ... List of parameters to print. */ void __printf_like(3, 4) shell_fprintf_impl(const struct shell *sh, enum shell_vt100_color color, const char *fmt, ...); #define shell_fprintf(sh, color, fmt, ...) shell_fprintf_impl(sh, color, fmt, ##__VA_ARGS__) /** * @brief vprintf-like function which sends formatted data stream to the shell. * * This function can be used from the command handler or from threads, but not * from an interrupt context. It is similar to shell_fprintf() but takes a * va_list instead of variable arguments. * * @param[in] sh Pointer to the shell instance. * @param[in] color Printed text color. * @param[in] fmt Format string. * @param[in] args List of parameters to print. */ void shell_vfprintf(const struct shell *sh, enum shell_vt100_color color, const char *fmt, va_list args); /** * @brief Print a line of data in hexadecimal format. * * Each line shows the offset, bytes and then ASCII representation. * * For example: * * 00008010: 20 25 00 20 2f 48 00 08 80 05 00 20 af 46 00 * | %. /H.. ... .F. | * * @param[in] sh Pointer to the shell instance. * @param[in] offset Offset to show for this line. * @param[in] data Pointer to data. * @param[in] len Length of data. */ void shell_hexdump_line(const struct shell *sh, unsigned int offset, const uint8_t *data, size_t len); /** * @brief Print data in hexadecimal format. * * @param[in] sh Pointer to the shell instance. * @param[in] data Pointer to data. * @param[in] len Length of data. */ void shell_hexdump(const struct shell *sh, const uint8_t *data, size_t len); /** * @brief Print info message to the shell. * * See @ref shell_fprintf. * * @param[in] _sh Pointer to the shell instance. * @param[in] _ft Format string. * @param[in] ... List of parameters to print. */ #define shell_info(_sh, _ft, ...) \ shell_info_impl(_sh, _ft "\n", ##__VA_ARGS__) void __printf_like(2, 3) shell_info_impl(const struct shell *sh, const char *fmt, ...); /** * @brief Print normal message to the shell. * * See @ref shell_fprintf. * * @param[in] _sh Pointer to the shell instance. * @param[in] _ft Format string. * @param[in] ... List of parameters to print. */ #define shell_print(_sh, _ft, ...) \ shell_print_impl(_sh, _ft "\n", ##__VA_ARGS__) void __printf_like(2, 3) shell_print_impl(const struct shell *sh, const char *fmt, ...); /** * @brief Print warning message to the shell. * * See @ref shell_fprintf. * * @param[in] _sh Pointer to the shell instance. * @param[in] _ft Format string. * @param[in] ... List of parameters to print. */ #define shell_warn(_sh, _ft, ...) \ shell_warn_impl(_sh, _ft "\n", ##__VA_ARGS__) void __printf_like(2, 3) shell_warn_impl(const struct shell *sh, const char *fmt, ...); /** * @brief Print error message to the shell. * * See @ref shell_fprintf. * * @param[in] _sh Pointer to the shell instance. * @param[in] _ft Format string. * @param[in] ... List of parameters to print. */ #define shell_error(_sh, _ft, ...) \ shell_error_impl(_sh, _ft "\n", ##__VA_ARGS__) void __printf_like(2, 3) shell_error_impl(const struct shell *sh, const char *fmt, ...); /** * @brief Process function, which should be executed when data is ready in the * transport interface. To be used if shell thread is disabled. * * @param[in] sh Pointer to the shell instance. */ void shell_process(const struct shell *sh); /** * @brief Change displayed shell prompt. * * @param[in] sh Pointer to the shell instance. * @param[in] prompt New shell prompt. * * @return 0 Success. * @return -EINVAL Pointer to new prompt is not correct. */ int shell_prompt_change(const struct shell *sh, const char *prompt); /** * @brief Prints the current command help. * * Function will print a help string with: the currently entered command * and subcommands (if they exist). * * @param[in] sh Pointer to the shell instance. */ void shell_help(const struct shell *sh); /** @brief Command's help has been printed */ #define SHELL_CMD_HELP_PRINTED (1) /** @brief Execute command. * * Pass command line to shell to execute. * * Note: This by no means makes any of the commands a stable interface, so * this function should only be used for debugging/diagnostic. * * This function must not be called from shell command context! * * @param[in] sh Pointer to the shell instance. * It can be NULL when the * @kconfig{CONFIG_SHELL_BACKEND_DUMMY} option is enabled. * @param[in] cmd Command to be executed. * * @return Result of the execution */ int shell_execute_cmd(const struct shell *sh, const char *cmd); /** @brief Set root command for all shell instances. * * It allows setting from the code the root command. It is an equivalent of * calling select command with one of the root commands as the argument * (e.g "select log") except it sets command for all shell instances. * * @param cmd String with one of the root commands or null pointer to reset. * * @retval 0 if root command is set. * @retval -EINVAL if invalid root command is provided. */ int shell_set_root_cmd(const char *cmd); /** @brief Set bypass callback. * * Bypass callback is called whenever data is received. Shell is bypassed and * data is passed directly to the callback. Use null to disable bypass functionality. * * @param[in] sh Pointer to the shell instance. * @param[in] bypass Bypass callback or null to disable. */ void shell_set_bypass(const struct shell *sh, shell_bypass_cb_t bypass); /** @brief Get shell readiness to execute commands. * * @param[in] sh Pointer to the shell instance. * * @retval true Shell backend is ready to execute commands. * @retval false Shell backend is not initialized or not started. */ bool shell_ready(const struct shell *sh); /** * @brief Allow application to control text insert mode. * Value is modified atomically and the previous value is returned. * * @param[in] sh Pointer to the shell instance. * @param[in] val Insert mode. * * @retval 0 or 1: previous value * @retval -EINVAL if shell is NULL. */ int shell_insert_mode_set(const struct shell *sh, bool val); /** * @brief Allow application to control whether terminal output uses colored * syntax. * Value is modified atomically and the previous value is returned. * * @param[in] sh Pointer to the shell instance. * @param[in] val Color mode. * * @retval 0 or 1: previous value * @retval -EINVAL if shell is NULL. */ int shell_use_colors_set(const struct shell *sh, bool val); /** * @brief Allow application to control whether terminal is using vt100 commands. * Value is modified atomically and the previous value is returned. * * @param[in] sh Pointer to the shell instance. * @param[in] val vt100 mode. * * @retval 0 or 1: previous value * @retval -EINVAL if shell is NULL. */ int shell_use_vt100_set(const struct shell *sh, bool val); /** * @brief Allow application to control whether user input is echoed back. * Value is modified atomically and the previous value is returned. * * @param[in] sh Pointer to the shell instance. * @param[in] val Echo mode. * * @retval 0 or 1: previous value * @retval -EINVAL if shell is NULL. */ int shell_echo_set(const struct shell *sh, bool val); /** * @brief Allow application to control whether user input is obscured with * asterisks -- useful for implementing passwords. * Value is modified atomically and the previous value is returned. * * @param[in] sh Pointer to the shell instance. * @param[in] obscure Obscure mode. * * @retval 0 or 1: previous value. * @retval -EINVAL if shell is NULL. */ int shell_obscure_set(const struct shell *sh, bool obscure); /** * @brief Allow application to control whether the delete key backspaces or * deletes. * Value is modified atomically and the previous value is returned. * * @param[in] sh Pointer to the shell instance. * @param[in] val Delete mode. * * @retval 0 or 1: previous value * @retval -EINVAL if shell is NULL. */ int shell_mode_delete_set(const struct shell *sh, bool val); /** * @brief Retrieve return value of most recently executed shell command. * * @param[in] sh Pointer to the shell instance * * @retval return value of previous command */ int shell_get_return_value(const struct shell *sh); /** * @} */ #ifdef __cplusplus } #endif #ifdef CONFIG_SHELL_CUSTOM_HEADER /* This include must always be at the end of shell.h */ #include <zephyr_custom_shell.h> #endif #endif /* SHELL_H__ */ ```
/content/code_sandbox/include/zephyr/shell/shell.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
10,706
```objective-c /* * */ /** * @file * @brief Public API for SD subsystem */ #ifndef ZEPHYR_INCLUDE_SD_SD_H_ #define ZEPHYR_INCLUDE_SD_SD_H_ #include <zephyr/device.h> #include <zephyr/drivers/sdhc.h> #include <zephyr/kernel.h> #ifdef __cplusplus extern "C" { #endif /** * @brief card status. Used internally by subsystem. */ enum card_status { CARD_UNINITIALIZED = 0, /*!< card has not been initialized */ CARD_ERROR = 1, /*!< card state is error */ CARD_INITIALIZED = 2, /*!< card is in valid state */ }; /** * @brief card type. Used internally by subsystem. */ enum card_type { CARD_SDMMC = 0, /*!< SD memory card */ CARD_SDIO = 1, /*!< SD I/O card */ CARD_COMBO = 2, /*!< SD memory and I/O card */ CARD_MMC = 3, /*!< MMC memory card */ }; /** * @brief SDIO function definition * * SDIO function definition. Used to store function information * per each SDIO function */ struct sdio_func { enum sdio_func_num num; /*!< Function number */ struct sd_card *card; /*!< Card this function is present on */ struct sdio_cis cis; /*!< CIS tuple data for this function */ uint16_t block_size; /*!< Current block size for this function */ }; /** * @brief SD card structure * * This structure is used by the subsystem to track an individual SD * device connected to the system. The application may access these * fields, but use caution when changing values. */ struct sd_card { const struct device *sdhc; /*!< SD host controller for card */ struct sdhc_io bus_io; /*!< Current bus I/O props for SDHC */ enum sd_voltage card_voltage; /*!< Card signal voltage */ struct k_mutex lock; /*!< card mutex */ struct sdhc_host_props host_props; /*!< SDHC host properties */ uint32_t ocr; /*!< Raw card OCR content */ struct sd_switch_caps switch_caps; /*!< SD switch capabilities */ unsigned int num_io: 3; /*!< I/O function count. 0 for SD cards */ uint16_t relative_addr; /*!< Card relative address */ uint32_t block_count; /*!< Number of blocks in SD card */ uint16_t block_size; /*!< SD block size */ uint8_t sd_version; /*!< SD specification version */ uint8_t card_speed; /*!< Card timing mode */ enum card_status status; /*!< Card status */ enum card_type type; /*!< Card type */ uint16_t flags; /*!< Card flags */ uint8_t bus_width; /*!< Desired bus width */ uint32_t cccr_flags; /*!< SDIO CCCR data */ struct sdio_func func0; /*!< Function 0 common card data */ /* NOTE: The buffer is accessed as a uint32_t* by the SD subsystem, so must be * aligned to 4 bytes for platforms that don't support unaligned access... * Systems where the buffer is accessed by DMA may require wider alignment, in * which case, use CONFIG_SDHC_BUFFER_ALIGNMENT. */ uint8_t card_buffer[CONFIG_SD_BUFFER_SIZE] __aligned(MAX(4, CONFIG_SDHC_BUFFER_ALIGNMENT)); /* Card internal buffer */ }; /** * @brief Initialize an SD device * * Initializes an SD device to use with the subsystem. After this call, * only the SD card structure is required to access the card. * @param sdhc_dev SD host controller device for this card * @param card SD card structure for this card * @retval 0 card was initialized * @retval -ETIMEDOUT: card initialization timed out * @retval -EBUSY: card is busy * @retval -EIO: IO error while starting card */ int sd_init(const struct device *sdhc_dev, struct sd_card *card); /** * @brief checks to see if card is present in the SD slot * * @param sdhc_dev SD host controller to check for card presence on * @retval true card is present * @retval false card is not present */ bool sd_is_card_present(const struct device *sdhc_dev); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_SD_SD_H_ */ ```
/content/code_sandbox/include/zephyr/sd/sd.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
902
```objective-c /* * */ /** * @file * @brief Public API for SD memory card subsystem */ #ifndef ZEPHYR_INCLUDE_SD_SDMMC_H_ #define ZEPHYR_INCLUDE_SD_SDMMC_H_ #include <zephyr/device.h> #include <zephyr/drivers/sdhc.h> #include <zephyr/sd/sd.h> #ifdef __cplusplus extern "C" { #endif /** * @brief Write blocks to SD card from buffer * * Writes blocks from SD buffer to SD card. For best performance, this buffer * should be aligned to CONFIG_SDHC_BUFFER_ALIGNMENT * @param card SD card to write from * @param wbuf write buffer * @param start_block first block to write to * @param num_blocks number of blocks to write * @retval 0 write succeeded * @retval -EBUSY: card is busy with another request * @retval -ETIMEDOUT: card write timed out * @retval -EIO: I/O error */ int sdmmc_write_blocks(struct sd_card *card, const uint8_t *wbuf, uint32_t start_block, uint32_t num_blocks); /** * @brief Read block from SD card to buffer * * Reads blocks into SD buffer from SD card. For best performance, this buffer * should be aligned to CONFIG_SDHC_BUFFER_ALIGNMENT * @param card SD card to read from * @param rbuf read buffer * @param start_block first block to read from * @param num_blocks number of blocks to read * @retval 0 read succeeded * @retval -EBUSY: card is busy with another request * @retval -ETIMEDOUT: card read timed out * @retval -EIO: I/O error */ int sdmmc_read_blocks(struct sd_card *card, uint8_t *rbuf, uint32_t start_block, uint32_t num_blocks); /** * @brief Get I/O control data from SD card * * Sends I/O control commands to SD card. * @param card SD card * @param cmd I/O control command * @param buf I/O control buf * @retval 0 IOCTL command succeeded * @retval -ENOTSUP: IOCTL command not supported * @retval -EIO: I/O failure */ int sdmmc_ioctl(struct sd_card *card, uint8_t cmd, void *buf); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_SD_SDMMC_H_ */ ```
/content/code_sandbox/include/zephyr/sd/sdmmc.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
527
```objective-c /* * */ /** * @file * @brief Public API for MMC memory card subsystem */ #ifndef ZEPHYR_INCLUDE_SD_MMC_H_ #define ZEPHYR_INCLUDE_SD_MMC_H_ #include <zephyr/device.h> #include <zephyr/drivers/sdhc.h> #include <zephyr/sd/sd.h> #ifdef __cplusplus extern "C" { #endif /** * @brief Write blocks to MMC card from buffer * * Writes blocks from MMC buffer to MMC card. For best performance, this buffer * should be aligned to CONFIG_SDHC_BUFFER_ALIGNMENT * @param card MMC card to write from * @param wbuf write buffer * @param start_block first block to write to * @param num_blocks number of blocks to write * @retval 0 write succeeded * @retval -EBUSY: card is busy with another request * @retval -ETIMEDOUT: card write timed out * @retval -EIO: I/O error */ int mmc_write_blocks(struct sd_card *card, const uint8_t *wbuf, uint32_t start_block, uint32_t num_blocks); /** * @brief Read block from MMC card to buffer * * Reads blocks into MMC buffer from MMC card. For best performance, this buffer * should be aligned to CONFIG_SDHC_BUFFER_ALIGNMENT * @param card MMC card to read from * @param rbuf read buffer * @param start_block first block to read from * @param num_blocks number of blocks to read * @retval 0 read succeeded * @retval -EBUSY: card is busy with another request * @retval -ETIMEDOUT: card read timed out * @retval -EIO: I/O error */ int mmc_read_blocks(struct sd_card *card, uint8_t *rbuf, uint32_t start_block, uint32_t num_blocks); /** * @brief Get I/O control data from MMC card * * Sends I/O control commands to MMC card. * @param card MMC card * @param cmd I/O control command * Mirrors disk subsystem, * see include/zephyr/drivers/disk.h for list of possible commands. * @param buf I/O control buf * @retval 0 IOCTL command succeeded * @retval -ENOTSUP: IOCTL command not supported * @retval -EIO: I/O failure */ int mmc_ioctl(struct sd_card *card, uint8_t cmd, void *buf); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_SD_MMC_H_ */ ```
/content/code_sandbox/include/zephyr/sd/mmc.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
548
```objective-c /* * */ /* * SD card specification */ #ifndef ZEPHYR_SUBSYS_SD_SPEC_H_ #define ZEPHYR_SUBSYS_SD_SPEC_H_ #include <stdint.h> #include <zephyr/sys/util.h> #ifdef __cplusplus extern "C" { #endif /** * @brief SD specification command opcodes * * SD specification command opcodes. Note that some command opcodes are * specific to SDIO cards, or cards running in SPI mode instead of native SD * mode. */ enum sd_opcode { SD_GO_IDLE_STATE = 0, MMC_SEND_OP_COND = 1, SD_ALL_SEND_CID = 2, SD_SEND_RELATIVE_ADDR = 3, MMC_SEND_RELATIVE_ADDR = 3, SDIO_SEND_OP_COND = 5, /* SDIO cards only */ SD_SWITCH = 6, SD_SELECT_CARD = 7, SD_SEND_IF_COND = 8, MMC_SEND_EXT_CSD = 8, SD_SEND_CSD = 9, SD_SEND_CID = 10, SD_VOL_SWITCH = 11, SD_STOP_TRANSMISSION = 12, SD_SEND_STATUS = 13, MMC_CHECK_BUS_TEST = 14, SD_GO_INACTIVE_STATE = 15, SD_SET_BLOCK_SIZE = 16, SD_READ_SINGLE_BLOCK = 17, SD_READ_MULTIPLE_BLOCK = 18, SD_SEND_TUNING_BLOCK = 19, MMC_SEND_BUS_TEST = 19, MMC_SEND_TUNING_BLOCK = 21, SD_SET_BLOCK_COUNT = 23, SD_WRITE_SINGLE_BLOCK = 24, SD_WRITE_MULTIPLE_BLOCK = 25, SD_ERASE_BLOCK_START = 32, SD_ERASE_BLOCK_END = 33, SD_ERASE_BLOCK_OPERATION = 38, SDIO_RW_DIRECT = 52, SDIO_RW_EXTENDED = 53, SD_APP_CMD = 55, SD_SPI_READ_OCR = 58, /* SPI mode only */ SD_SPI_CRC_ON_OFF = 59, /* SPI mode only */ }; /** * @brief SD application command opcodes. * * all application command opcodes must be prefixed with a CMD55 command * to inform the SD card the next command is an application-specific one. */ enum sd_app_cmd { SD_APP_SET_BUS_WIDTH = 6, SD_APP_SEND_STATUS = 13, SD_APP_SEND_NUM_WRITTEN_BLK = 22, SD_APP_SET_WRITE_BLK_ERASE_CNT = 23, SD_APP_SEND_OP_COND = 41, SD_APP_CLEAR_CARD_DETECT = 42, SD_APP_SEND_SCR = 51, }; /** * @brief Native SD mode R1 response status flags * * Native response flags for SD R1 response, used to check for error in command. */ enum sd_r1_status { /* Bits 0-2 reserved */ SD_R1_AUTH_ERR = BIT(3), /* Bit 4 reserved for SDIO */ SD_R1_APP_CMD = BIT(5), SD_R1_FX_EVENT = BIT(6), /* Bit 7 reserved */ SD_R1_RDY_DATA = BIT(8), SD_R1_CUR_STATE = (0xFU << 9), SD_R1_ERASE_RESET = BIT(13), SD_R1_ECC_DISABLED = BIT(14), SD_R1_ERASE_SKIP = BIT(15), SD_R1_CSD_OVERWRITE = BIT(16), /* Bits 17-18 reserved */ SD_R1_ERR = BIT(19), SD_R1_CC_ERR = BIT(20), SD_R1_ECC_FAIL = BIT(21), SD_R1_ILLEGAL_CMD = BIT(22), SD_R1_CRC_ERR = BIT(23), SD_R1_UNLOCK_FAIL = BIT(24), SD_R1_CARD_LOCKED = BIT(25), SD_R1_WP_VIOLATION = BIT(26), SD_R1_ERASE_PARAM = BIT(27), SD_R1_ERASE_SEQ_ERR = BIT(28), SD_R1_BLOCK_LEN_ERR = BIT(29), SD_R1_ADDR_ERR = BIT(30), SD_R1_OUT_OF_RANGE = BIT(31), SD_R1_ERR_FLAGS = (SD_R1_AUTH_ERR | SD_R1_ERASE_SKIP | SD_R1_CSD_OVERWRITE | SD_R1_ERR | SD_R1_CC_ERR | SD_R1_ECC_FAIL | SD_R1_ILLEGAL_CMD | SD_R1_CRC_ERR | SD_R1_UNLOCK_FAIL | SD_R1_WP_VIOLATION | SD_R1_ERASE_PARAM | SD_R1_ERASE_SEQ_ERR | SD_R1_BLOCK_LEN_ERR | SD_R1_ADDR_ERR | SD_R1_OUT_OF_RANGE), SD_R1ERR_NONE = 0, }; #define SD_R1_CURRENT_STATE(x) (((x) & SD_R1_CUR_STATE) >> 9U) /** * @brief SD current state values * * SD current state values, contained in R1 response data. */ enum sd_r1_current_state { SDMMC_R1_IDLE = 0U, SDMMC_R1_READY = 1U, SDMMC_R1_IDENTIFY = 2U, SDMMC_R1_STANDBY = 3U, SDMMC_R1_TRANSFER = 4U, SDMMC_R1_SEND_DATA = 5U, SDMMC_R1_RECIVE_DATA = 6U, SDMMC_R1_PROGRAM = 7U, SDMMC_R1_DISCONNECT = 8U, }; /** * @brief SPI SD mode R1 response status flags * * SPI mode R1 response flags. Used to check for error in SD SPI mode command. */ enum sd_spi_r1_error_flag { SD_SPI_R1PARAMETER_ERR = BIT(6), SD_SPI_R1ADDRESS_ERR = BIT(5), SD_SPI_R1ERASE_SEQ_ERR = BIT(4), SD_SPI_R1CMD_CRC_ERR = BIT(3), SD_SPI_R1ILLEGAL_CMD_ERR = BIT(2), SD_SPI_R1ERASE_RESET = BIT(1), SD_SPI_R1IDLE_STATE = BIT(0), }; /** * @brief SPI SD mode R2 response status flags * * SPI mode R2 response flags. Sent in response to SEND_STATUS command. Used * to check status of SD card. */ enum sd_spi_r2_status { SDHC_SPI_R2_CARD_LOCKED = BIT(8), SDHC_SPI_R2_UNLOCK_FAIL = BIT(9), SDHC_SPI_R2_ERR = BIT(10), SDHC_SPI_R2_CC_ERR = BIT(11), SDHC_SPI_R2_ECC_FAIL = BIT(12), SDHC_SPI_R2_WP_VIOLATION = BIT(13), SDHC_SPI_R2_ERASE_PARAM = BIT(14), SDHC_SPI_R2_OUT_OF_RANGE = BIT(15), }; /* Byte length of SD SPI mode command */ #define SD_SPI_CMD_SIZE 6 #define SD_SPI_CMD_BODY_SIZE (SD_SPI_CMD_SIZE - 1) /* Byte length of CRC16 appended to data blocks in SPI mode */ #define SD_SPI_CRC16_SIZE 2 /* SPI Command flags */ #define SD_SPI_START 0x80 #define SD_SPI_TX 0x40 #define SD_SPI_CMD 0x3F /* SPI Data block tokens */ #define SD_SPI_TOKEN_SINGLE 0xFE #define SD_SPI_TOKEN_MULTI_WRITE 0xFC #define SD_SPI_TOKEN_STOP_TRAN 0xFD /* SPI Data block responses */ #define SD_SPI_RESPONSE_ACCEPTED 0x05 #define SD_SPI_RESPONSE_CRC_ERR 0x0B #define SD_SPI_RESPONSE_WRITE_ERR 0x0C /* Masks used in SD interface condition query (CMD8) */ #define SD_IF_COND_VHS_MASK (0x0F << 8) #define SD_IF_COND_VHS_3V3 BIT(8) #define SD_IF_COND_CHECK 0xAA /** * @brief SD response types * * SD response types. Note that SPI mode has difference response types than * cards in native SD mode. */ enum sd_rsp_type { /* Native response types (lower 4 bits) */ SD_RSP_TYPE_NONE = 0U, SD_RSP_TYPE_R1 = 1U, SD_RSP_TYPE_R1b = 2U, SD_RSP_TYPE_R2 = 3U, SD_RSP_TYPE_R3 = 4U, SD_RSP_TYPE_R4 = 5U, SD_RSP_TYPE_R5 = 6U, SD_RSP_TYPE_R5b = 7U, SD_RSP_TYPE_R6 = 8U, SD_RSP_TYPE_R7 = 9U, /* SPI response types (bits [7:4]) */ SD_SPI_RSP_TYPE_R1 = (1U << 4), SD_SPI_RSP_TYPE_R1b = (2U << 4), SD_SPI_RSP_TYPE_R2 = (3U << 4), SD_SPI_RSP_TYPE_R3 = (4U << 4), SD_SPI_RSP_TYPE_R4 = (5U << 4), SD_SPI_RSP_TYPE_R5 = (6U << 4), SD_SPI_RSP_TYPE_R7 = (7U << 4), }; /** * @brief SD support flags * * flags used by SD subsystem to determine support for SD card features. */ enum sd_support_flag { SD_HIGH_CAPACITY_FLAG = BIT(1), SD_4BITS_WIDTH = BIT(2), SD_SDHC_FLAG = BIT(3), SD_SDXC_FLAG = BIT(4), SD_1800MV_FLAG = BIT(5), SD_3000MV_FLAG = BIT(6), SD_CMD23_FLAG = BIT(7), SD_SPEED_CLASS_CONTROL_FLAG = BIT(8), SD_MEM_PRESENT_FLAG = BIT(9), }; /** * @brief SD OCR bit flags * * bit flags present in SD OCR response. Used to determine status and * supported functions of SD card. */ enum sd_ocr_flag { /** Power up busy status */ SD_OCR_PWR_BUSY_FLAG = BIT(31), /** Card capacity status */ SD_OCR_HOST_CAP_FLAG = BIT(30), /** Card capacity status */ SD_OCR_CARD_CAP_FLAG = SD_OCR_HOST_CAP_FLAG, /** Switch to 1.8V request */ SD_OCR_SWITCH_18_REQ_FLAG = BIT(24), /** Switch to 1.8V accepted */ SD_OCR_SWITCH_18_ACCEPT_FLAG = SD_OCR_SWITCH_18_REQ_FLAG, /** VDD 2.7-2.8 */ SD_OCR_VDD27_28FLAG = BIT(15), /** VDD 2.8-2.9 */ SD_OCR_VDD28_29FLAG = BIT(16), /** VDD 2.9-3.0 */ SD_OCR_VDD29_30FLAG = BIT(17), /** VDD 3.0-3.1 */ SD_OCR_VDD30_31FLAG = BIT(18), /** VDD 3.1-3.2 */ SD_OCR_VDD31_32FLAG = BIT(19), /** VDD 3.2-3.3 */ SD_OCR_VDD32_33FLAG = BIT(20), /** VDD 3.3-3.4 */ SD_OCR_VDD33_34FLAG = BIT(21), /** VDD 3.4-3.5 */ SD_OCR_VDD34_35FLAG = BIT(22), /** VDD 3.5-3.6 */ SD_OCR_VDD35_36FLAG = BIT(23), }; /** * @brief MMC OCR bit flags * * bit flags present in MMC OCR response. Used to determine status and * supported functions of MMC card. */ enum mmc_ocr_flag { MMC_OCR_VDD170_195FLAG = BIT(7), MMC_OCR_VDD20_26FLAG = 0x7F << 8, MMC_OCR_VDD27_36FLAG = 0x1FF << 15, MMC_OCR_SECTOR_MODE = BIT(30), MMC_OCR_PWR_BUSY_FLAG = BIT(31) }; #define SDIO_OCR_IO_NUMBER_SHIFT 28 /* Lower 24 bits hold SDIO I/O OCR */ #define SDIO_IO_OCR_MASK 0xFFFFFF /** * @brief SDIO OCR bit flags * * bit flags present in SDIO OCR response. Used to determine status and * supported functions of SDIO card. */ enum sdio_ocr_flag { SDIO_OCR_IO_READY_FLAG = BIT(31), SDIO_OCR_IO_NUMBER = (7U << 28U), /*!< Number of io function */ SDIO_OCR_MEM_PRESENT_FLAG = BIT(27), /*!< Memory present flag */ SDIO_OCR_180_VOL_FLAG = BIT(24), /*!< Switch to 1.8v signalling */ SDIO_OCR_VDD20_21FLAG = BIT(8), /*!< VDD 2.0-2.1 */ SDIO_OCR_VDD21_22FLAG = BIT(9), /*!< VDD 2.1-2.2 */ SDIO_OCR_VDD22_23FLAG = BIT(10), /*!< VDD 2.2-2.3 */ SDIO_OCR_VDD23_24FLAG = BIT(11), /*!< VDD 2.3-2.4 */ SDIO_OCR_VDD24_25FLAG = BIT(12), /*!< VDD 2.4-2.5 */ SDIO_OCR_VDD25_26FLAG = BIT(13), /*!< VDD 2.5-2.6 */ SDIO_OCR_VDD26_27FLAG = BIT(14), /*!< VDD 2.6-2.7 */ SDIO_OCR_VDD27_28FLAG = BIT(15), /*!< VDD 2.7-2.8 */ SDIO_OCR_VDD28_29FLAG = BIT(16), /*!< VDD 2.8-2.9 */ SDIO_OCR_VDD29_30FLAG = BIT(17), /*!< VDD 2.9-3.0 */ SDIO_OCR_VDD30_31FLAG = BIT(18), /*!< VDD 2.9-3.0 */ SDIO_OCR_VDD31_32FLAG = BIT(19), /*!< VDD 3.0-3.1 */ SDIO_OCR_VDD32_33FLAG = BIT(20), /*!< VDD 3.1-3.2 */ SDIO_OCR_VDD33_34FLAG = BIT(21), /*!< VDD 3.2-3.3 */ SDIO_OCR_VDD34_35FLAG = BIT(22), /*!< VDD 3.3-3.4 */ SDIO_OCR_VDD35_36FLAG = BIT(23), /*!< VDD 3.4-3.5 */ }; /** * @brief SD switch arguments * * SD CMD6 can either check or set a function. Bitfields are used to indicate * feature support when checking a function, and when setting a function an * integer value is used to select it. */ enum sd_switch_arg { /** SD switch mode 0: check function */ SD_SWITCH_CHECK = 0U, /** SD switch mode 1: set function */ SD_SWITCH_SET = 1U, }; /** * @brief SD switch group numbers * * SD CMD6 has multiple function groups it can check/set. These indicies are * used to determine which group CMD6 will interact with. */ enum sd_group_num { /** access mode group */ SD_GRP_TIMING_MODE = 0U, /** command system group */ SD_GRP_CMD_SYS_MODE = 1U, /** driver strength group */ SD_GRP_DRIVER_STRENGTH_MODE = 2U, /** current limit group */ SD_GRP_CURRENT_LIMIT_MODE = 3U, }; /* Maximum data rate possible for SD high speed cards */ enum hs_max_data_rate { HS_UNSUPPORTED = 0, HS_MAX_DTR = MHZ(50), }; /* Maximum data rate possible for SD uhs cards */ enum uhs_max_data_rate { UHS_UNSUPPORTED = 0, UHS_SDR12_MAX_DTR = MHZ(25), UHS_SDR25_MAX_DTR = MHZ(50), UHS_SDR50_MAX_DTR = MHZ(100), UHS_SDR104_MAX_DTR = MHZ(208), UHS_DDR50_MAX_DTR = MHZ(50), }; /** * @brief SD bus speed support bit flags * * Bit flags indicating support for SD bus speeds. * these bit flags are provided as a response to CMD6 by the card */ enum sd_bus_speed { UHS_SDR12_BUS_SPEED = BIT(0), DEFAULT_BUS_SPEED = BIT(0), HIGH_SPEED_BUS_SPEED = BIT(1), UHS_SDR25_BUS_SPEED = BIT(1), UHS_SDR50_BUS_SPEED = BIT(2), UHS_SDR104_BUS_SPEED = BIT(3), UHS_DDR50_BUS_SPEED = BIT(4), }; /** * @brief SD timing mode function selection values. * * sent to the card via CMD6 to select a card speed, and used by SD host * controller to identify timing of card. */ enum sd_timing_mode { /** Default Mode */ SD_TIMING_DEFAULT = 0U, /** SDR12 mode */ SD_TIMING_SDR12 = 0U, /** High speed mode */ SD_TIMING_HIGH_SPEED = 1U, /** SDR25 mode */ SD_TIMING_SDR25 = 1U, /** SDR50 mode*/ SD_TIMING_SDR50 = 2U, /** SDR104 mode */ SD_TIMING_SDR104 = 3U, /** DDR50 mode */ SD_TIMING_DDR50 = 4U, }; /** * @brief SD host controller clock speed * * Controls the SD host controller clock speed on the SD bus. */ enum sdhc_clock_speed { SDMMC_CLOCK_400KHZ = KHZ(400), SD_CLOCK_25MHZ = MHZ(25), SD_CLOCK_50MHZ = MHZ(50), SD_CLOCK_100MHZ = MHZ(100), SD_CLOCK_208MHZ = MHZ(208), MMC_CLOCK_26MHZ = MHZ(26), MMC_CLOCK_52MHZ = MHZ(52), MMC_CLOCK_DDR52 = MHZ(52), MMC_CLOCK_HS200 = MHZ(200), MMC_CLOCK_HS400 = MHZ(200), /* Same clock freq as HS200, just DDR */ }; /** * @brief SD current setting values * * Used with CMD6 to inform the card what its maximum current draw is. */ enum sd_current_setting { SD_SET_CURRENT_200MA = 0, SD_SET_CURRENT_400MA = 1, SD_SET_CURRENT_600MA = 2, SD_SET_CURRENT_800MA = 3, }; /** * @brief SD current support bitfield * * Used with CMD6 to determine the maximum current the card will draw. */ enum sd_current_limit { /** default current limit */ SD_MAX_CURRENT_200MA = BIT(0), /** current limit to 400MA */ SD_MAX_CURRENT_400MA = BIT(1), /** current limit to 600MA */ SD_MAX_CURRENT_600MA = BIT(2), /** current limit to 800MA */ SD_MAX_CURRENT_800MA = BIT(3), }; /** * @brief SD driver types * * Used with CMD6 to determine the driver type the card should use. */ enum sd_driver_type { SD_DRIVER_TYPE_B = 0x1, SD_DRIVER_TYPE_A = 0x2, SD_DRIVER_TYPE_C = 0x4, SD_DRIVER_TYPE_D = 0x8, }; /** * @brief SD switch drive type selection * * These values are used to select the preferred driver type for an SD card. */ enum sd_driver_strength { /** default driver strength*/ SD_DRV_STRENGTH_TYPEB = 0U, /** driver strength TYPE A */ SD_DRV_STRENGTH_TYPEA = 1U, /** driver strength TYPE C */ SD_DRV_STRENGTH_TYPEC = 2U, /** driver strength TYPE D */ SD_DRV_STRENGTH_TYPED = 3U, }; /** * @brief SD switch capabilities * * records switch capabilities for SD card. These capabilities are set * and queried via CMD6 */ struct sd_switch_caps { enum hs_max_data_rate hs_max_dtr; enum uhs_max_data_rate uhs_max_dtr; enum sd_bus_speed bus_speed; enum sd_driver_type sd_drv_type; enum sd_current_limit sd_current_limit; }; #define SD_PRODUCT_NAME_BYTES 5 /** * @brief SD card identification register * * Layout of SD card identification register */ struct sd_cid { /** Manufacturer ID [127:120] */ uint8_t manufacturer; /** OEM/Application ID [119:104] */ uint16_t application; /** Product name [103:64] */ uint8_t name[SD_PRODUCT_NAME_BYTES]; /** Product revision [63:56] */ uint8_t version; /** Product serial number [55:24] */ uint32_t ser_num; /** Manufacturing date [19:8] */ uint16_t date; }; /** * @brief SD card specific data register. * * Card specific data register. contains additional data about SD card. */ struct sd_csd { /** CSD structure [127:126] */ uint8_t csd_structure; /** Data read access-time-1 [119:112] */ uint8_t read_time1; /** Data read access-time-2 in clock cycles (NSAC*100) [111:104] */ uint8_t read_time2; /** Maximum data transfer rate [103:96] */ uint8_t xfer_rate; /** Card command classes [95:84] */ uint16_t cmd_class; /** Maximum read data block length [83:80] */ uint8_t read_blk_len; /** Flags in _sd_csd_flag */ uint16_t flags; /** Device size [73:62] */ uint32_t device_size; /** Maximum read current at VDD min [61:59] */ uint8_t read_current_min; /** Maximum read current at VDD max [58:56] */ uint8_t read_current_max; /** Maximum write current at VDD min [55:53] */ uint8_t write_current_min; /** Maximum write current at VDD max [52:50] */ uint8_t write_current_max; /** Device size multiplier [49:47] */ uint8_t dev_size_mul; /** Erase sector size [45:39] */ uint8_t erase_size; /** Write protect group size [38:32] */ uint8_t write_prtect_size; /** Write speed factor [28:26] */ uint8_t write_speed_factor; /** Maximum write data block length [25:22] */ uint8_t write_blk_len; /** File format [11:10] */ uint8_t file_fmt; }; /** * @brief MMC Maximum Frequency * * Max freq in MMC csd */ enum mmc_csd_freq { MMC_MAXFREQ_100KHZ = 0U << 0U, MMC_MAXFREQ_1MHZ = 1U << 0U, MMC_MAXFREQ_10MHZ = 2U << 0U, MMC_MAXFREQ_100MHZ = 3U << 0U, MMC_MAXFREQ_MULT_10 = 1U << 3U, MMC_MAXFREQ_MULT_12 = 2U << 3U, MMC_MAXFREQ_MULT_13 = 3U << 3U, MMC_MAXFREQ_MULT_15 = 4U << 3U, MMC_MAXFREQ_MULT_20 = 5U << 3U, MMC_MAXFREQ_MULT_26 = 6U << 3U, MMC_MAXFREQ_MULT_30 = 7U << 3U, MMC_MAXFREQ_MULT_35 = 8U << 3U, MMC_MAXFREQ_MULT_40 = 9U << 3U, MMC_MAXFREQ_MULT_45 = 0xAU << 3U, MMC_MAXFREQ_MULT_52 = 0xBU << 3U, MMC_MAXFREQ_MULT_55 = 0xCU << 3U, MMC_MAXFREQ_MULT_60 = 0xDU << 3U, MMC_MAXFREQ_MULT_70 = 0xEU << 3U, MMC_MAXFREQ_MULT_80 = 0xFU << 3u }; /** * @brief MMC Timing Modes * * MMC Timing Mode, encoded in EXT_CSD */ enum mmc_timing_mode { MMC_LEGACY_TIMING = 0U, MMC_HS_TIMING = 1U, MMC_HS200_TIMING = 2U, MMC_HS400_TIMING = 3U }; /** * @brief MMC Driver Strengths * * Encoded in EXT_CSD */ enum mmc_driver_strengths { mmc_driv_type0 = 0U, mmc_driv_type1 = 1U, mmc_driv_type2 = 2U, mmc_driv_type3 = 3U, mmc_driv_type4 = 4U }; /** * @brief MMC Device Type * * Encoded in EXT_CSD */ struct mmc_device_type { bool MMC_HS400_DDR_1200MV; bool MMC_HS400_DDR_1800MV; bool MMC_HS200_SDR_1200MV; bool MMC_HS200_SDR_1800MV; bool MMC_HS_DDR_1200MV; bool MMC_HS_DDR_1800MV; bool MMC_HS_52_DV; bool MMC_HS_26_DV; }; /** * @brief CSD Revision * * Value of CSD rev in EXT_CSD */ enum mmc_ext_csd_rev { MMC_5_1 = 8U, MMC_5_0 = 7U, MMC_4_5 = 6U, MMC_4_4 = 5U, MMC_4_3 = 3U, MMC_4_2 = 2U, MMC_4_1 = 1U, MMC_4_0 = 0U }; /** * @brief MMC extended card specific data register * * Extended card specific data register. * Contains additional additional data about MMC card. */ struct mmc_ext_csd { /** Sector Count [215:212] */ uint32_t sec_count; /** Bus Width Mode [183] */ uint8_t bus_width; /** High Speed Timing Mode [185] */ enum mmc_timing_mode hs_timing; /** Device Type [196] */ struct mmc_device_type device_type; /** Extended CSD Revision [192] */ enum mmc_ext_csd_rev rev; /** Selected power class [187]*/ uint8_t power_class; /** Driver strengths [197] */ uint8_t mmc_driver_strengths; /** Power class information for HS200 at VCC!=1.95V [237] */ uint8_t pwr_class_200MHZ_VCCQ195; /** Power class information for HS400 [253] */ uint8_t pwr_class_HS400; /** Size of eMMC cache [252:249] */ uint32_t cache_size; }; /** * @brief SD card specific data flags * * flags used in decoding the SD card specific data register */ enum sd_csd_flag { /** Partial blocks for read allowed [79:79] */ SD_CSD_READ_BLK_PARTIAL_FLAG = BIT(0), /** Write block misalignment [78:78] */ SD_CSD_WRITE_BLK_MISALIGN_FLAG = BIT(1), /** Read block misalignment [77:77] */ SD_CSD_READ_BLK_MISALIGN_FLAG = BIT(2), /** DSR implemented [76:76] */ SD_CSD_DSR_IMPLEMENTED_FLAG = BIT(3), /** Erase single block enabled [46:46] */ SD_CSD_ERASE_BLK_EN_FLAG = BIT(4), /** Write protect group enabled [31:31] */ SD_CSD_WRITE_PROTECT_GRP_EN_FLAG = BIT(5), /** Partial blocks for write allowed [21:21] */ SD_CSD_WRITE_BLK_PARTIAL_FLAG = BIT(6), /** File format group [15:15] */ SD_CSD_FILE_FMT_GRP_FLAG = BIT(7), /** Copy flag [14:14] */ SD_CSD_COPY_FLAG = BIT(8), /** Permanent write protection [13:13] */ SD_CSD_PERMANENT_WRITE_PROTECT_FLAG = BIT(9), /** Temporary write protection [12:12] */ SD_CSD_TMP_WRITE_PROTECT_FLAG = BIT(10), }; /** * @brief SD card configuration register * * Even more SD card data. */ struct sd_scr { /** SCR Structure [63:60] */ uint8_t scr_structure; /** SD memory card specification version [59:56] */ uint8_t sd_spec; /** SCR flags in _sd_scr_flag */ uint16_t flags; /** Security specification supported [54:52] */ uint8_t sd_sec; /** Data bus widths supported [51:48] */ uint8_t sd_width; /** Extended security support [46:43] */ uint8_t sd_ext_sec; /** Command support bits [33:32] 33-support CMD23, 32-support cmd20*/ uint8_t cmd_support; /** reserved for manufacturer usage [31:0] */ uint32_t rsvd; }; /** * @brief SD card configuration register * * flags used in decoding the SD card configuration register */ enum sd_scr_flag { /** Data status after erases [55:55] */ SD_SCR_DATA_STATUS_AFTER_ERASE = BIT(0), /** Specification version 3.00 or higher [47:47]*/ SD_SCR_SPEC3 = BIT(1), }; /** * @brief SD specification version * * SD spec version flags used in decoding the SD card configuration register */ enum sd_spec_version { /** SD card version 1.0-1.01 */ SD_SPEC_VER1_0 = BIT(0), /** SD card version 1.10 */ SD_SPEC_VER1_1 = BIT(1), /** SD card version 2.00 */ SD_SPEC_VER2_0 = BIT(2), /** SD card version 3.0 */ SD_SPEC_VER3_0 = BIT(3), }; #define SDMMC_DEFAULT_BLOCK_SIZE 512 #define MMC_EXT_CSD_BYTES 512 /** * @brief SDIO function number * * SDIO function number used to select function when performing I/O on SDIO card */ enum sdio_func_num { SDIO_FUNC_NUM_0 = 0, SDIO_FUNC_NUM_1 = 1, SDIO_FUNC_NUM_2 = 2, SDIO_FUNC_NUM_3 = 3, SDIO_FUNC_NUM_4 = 4, SDIO_FUNC_NUM_5 = 5, SDIO_FUNC_NUM_6 = 6, SDIO_FUNC_NUM_7 = 7, SDIO_FUNC_MEMORY = 8, }; /** * @brief SDIO I/O direction * * SDIO I/O direction (read or write) */ enum sdio_io_dir { SDIO_IO_READ = 0, SDIO_IO_WRITE = 1, }; #define SDIO_CMD_ARG_RW_SHIFT 31 /*!< read/write flag shift */ #define SDIO_CMD_ARG_FUNC_NUM_SHIFT 28 /*!< function number shift */ #define SDIO_DIRECT_CMD_ARG_RAW_SHIFT 27 /*!< direct raw flag shift */ #define SDIO_CMD_ARG_REG_ADDR_SHIFT 9 /*!< direct reg addr shift */ #define SDIO_CMD_ARG_REG_ADDR_MASK 0x1FFFF /*!< direct reg addr mask */ #define SDIO_DIRECT_CMD_DATA_MASK 0xFF /*!< data mask */ #define SDIO_EXTEND_CMD_ARG_BLK_SHIFT 27 /*!< extended write block mode */ #define SDIO_EXTEND_CMD_ARG_OP_CODE_SHIFT 26 /*!< op code (increment address) */ /** * @brief Card common control register definitions * * Card common control registers, present on all SDIO cards */ #define SDIO_CCCR_CCCR 0x00 /*!< SDIO CCCR revision register */ #define SDIO_CCCR_CCCR_REV_MASK 0x0F #define SDIO_CCCR_CCCR_REV_SHIFT 0x0 #define SDIO_CCCR_CCCR_REV_1_00 0x0 /*!< CCCR/FBR Version 1.00 */ #define SDIO_CCCR_CCCR_REV_1_10 0x1 /*!< CCCR/FBR Version 1.10 */ #define SDIO_CCCR_CCCR_REV_2_00 0x2 /*!< CCCR/FBR Version 2.00 */ #define SDIO_CCCR_CCCR_REV_3_00 0x3 /*!< CCCR/FBR Version 3.00 */ #define SDIO_CCCR_SD 0x01 /*!< SD spec version register */ #define SDIO_CCCR_SD_SPEC_MASK 0x0F #define SDIO_CCCR_SD_SPEC_SHIFT 0x0 #define SDIO_CCCR_IO_EN 0x02 /*!< SDIO IO Enable register */ #define SDIO_CCCR_IO_RD 0x03 /*!< SDIO IO Ready register */ #define SDIO_CCCR_INT_EN 0x04 /*!< SDIO Interrupt enable register */ #define SDIO_CCCR_INT_P 0x05 /*!< SDIO Interrupt pending register */ #define SDIO_CCCR_ABORT 0x06 /*!< SDIO IO abort register */ #define SDIO_CCCR_BUS_IF 0x07 /*!< SDIO bus interface control register */ #define SDIO_CCCR_BUS_IF_WIDTH_MASK 0x3 /*!< SDIO bus width setting mask */ #define SDIO_CCCR_BUS_IF_WIDTH_1_BIT 0x00 /*!< 1 bit SDIO bus setting */ #define SDIO_CCCR_BUS_IF_WIDTH_4_BIT 0x02 /*!< 4 bit SDIO bus setting */ #define SDIO_CCCR_BUS_IF_WIDTH_8_BIT 0x03 /*!< 8 bit SDIO bus setting */ #define SDIO_CCCR_CAPS 0x08 /*!< SDIO card capabilities */ #define SDIO_CCCR_CAPS_SDC BIT(0) /*!< support CMD52 while data transfer */ #define SDIO_CCCR_CAPS_SMB BIT(1) /*!< support multiple block transfer */ #define SDIO_CCCR_CAPS_SRW BIT(2) /*!< support read wait control */ #define SDIO_CCCR_CAPS_SBS BIT(3) /*!< support bus control */ #define SDIO_CCCR_CAPS_S4MI BIT(4) /*!< support block gap interrupt */ #define SDIO_CCCR_CAPS_E4MI BIT(5) /*!< enable block gap interrupt */ #define SDIO_CCCR_CAPS_LSC BIT(6) /*!< low speed card */ #define SDIO_CCCR_CAPS_BLS BIT(7) /*!< low speed card with 4 bit support */ #define SDIO_CCCR_CIS 0x09 /*!< SDIO CIS tuples pointer */ #define SDIO_CCCR_SPEED 0x13 /*!< SDIO bus speed select */ #define SDIO_CCCR_SPEED_SHS BIT(0) /*!< high speed support */ #define SDIO_CCCR_SPEED_MASK 0xE /*!< bus speed select mask*/ #define SDIO_CCCR_SPEED_SHIFT 0x1 /*!< bus speed select shift */ #define SDIO_CCCR_SPEED_SDR12 0x0 /*!< select SDR12 */ #define SDIO_CCCR_SPEED_HS 0x1 /*!< select High speed mode */ #define SDIO_CCCR_SPEED_SDR25 0x1 /*!< select SDR25 */ #define SDIO_CCCR_SPEED_SDR50 0x2 /*!< select SDR50 */ #define SDIO_CCCR_SPEED_SDR104 0x3 /*!< select SDR104 */ #define SDIO_CCCR_SPEED_DDR50 0x4 /*!< select DDR50 */ #define SDIO_CCCR_UHS 0x14 /*!< SDIO UHS support */ #define SDIO_CCCR_UHS_SDR50 BIT(0) /*!< SDR50 support */ #define SDIO_CCCR_UHS_SDR104 BIT(1) /*!< SDR104 support */ #define SDIO_CCCR_UHS_DDR50 BIT(2) /*!< DDR50 support */ #define SDIO_CCCR_DRIVE_STRENGTH 0x15 /*!< SDIO drive strength */ #define SDIO_CCCR_DRIVE_STRENGTH_A BIT(0) /*!< drive type A */ #define SDIO_CCCR_DRIVE_STRENGTH_C BIT(1) /*!< drive type C */ #define SDIO_CCCR_DRIVE_STRENGTH_D BIT(2) /*!< drive type D */ #define SDIO_FBR_BASE(n) ((n) * 0x100) /*!< Get function base register addr */ #define SDIO_FBR_CIS 0x09 /*!< SDIO function base register CIS pointer */ #define SDIO_FBR_CSA 0x0C /*!< SDIO function base register CSA pointer */ #define SDIO_FBR_BLK_SIZE 0x10 /*!< SDIO function base register block size */ #define SDIO_MAX_IO_NUMS 7 /*!< Maximum number of I/O functions for SDIO */ #define SDIO_TPL_CODE_NULL 0x00 /*!< NULL CIS tuple code */ #define SDIO_TPL_CODE_MANIFID 0x20 /*!< manufacturer ID CIS tuple code */ #define SDIO_TPL_CODE_FUNCID 0x21 /*!< function ID CIS tuple code */ #define SDIO_TPL_CODE_FUNCE 0x22 /*!< function extension CIS tuple code */ #define SDIO_TPL_CODE_END 0xFF /*!< End CIS tuple code */ /** * @brief Card common control register flags * * flags to indicate capabilities supported by an SDIO card, read from the CCCR * registers */ enum sdio_cccr_flags { SDIO_SUPPORT_HS = BIT(0), SDIO_SUPPORT_SDR50 = BIT(1), SDIO_SUPPORT_SDR104 = BIT(2), SDIO_SUPPORT_DDR50 = BIT(3), SDIO_SUPPORT_4BIT_LS_BUS = BIT(4), SDIO_SUPPORT_MULTIBLOCK = BIT(5), }; /** * @brief SDIO common CIS tuple properties * * CIS tuple properties. Note that additional properties exist for * functions 1-7, but we do not read this data as the stack does not utilize it. */ struct sdio_cis { /* Manufacturer ID string tuple */ uint16_t manf_id; /*!< manufacturer ID */ uint16_t manf_code; /*!< manufacturer code */ /* Function identification tuple */ uint8_t func_id; /*!< sdio device class function id */ /* Function extension table */ uint16_t max_blk_size; /*!< Max transfer block size */ uint8_t max_speed; /*!< Max transfer speed */ uint16_t rdy_timeout; /*!< I/O ready timeout */ }; #ifdef __cplusplus } #endif #endif /* ZEPHYR_SUBSYS_SD_SPEC_H_ */ ```
/content/code_sandbox/include/zephyr/sd/sd_spec.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
8,453
```objective-c /* * */ /* * Basic macro definitions that gcc and clang provide on their own * but that xcc lacks. Only those that Zephyr requires are provided here. */ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_XCC_MISSING_DEFS_H_ #define ZEPHYR_INCLUDE_TOOLCHAIN_XCC_MISSING_DEFS_H_ #if __CHAR_BIT__ == 8 #define __SCHAR_WIDTH__ 8 #else #error "unexpected __CHAR_BIT__ value" #endif #if __SHRT_MAX__ == 32767 #define __SHRT_WIDTH__ 16 #define __SIZEOF_SHORT__ 2 #else #error "unexpected __SHRT_WIDTH__ value" #endif #if __INT_MAX__ == 2147483647 #define __INT_WIDTH__ 32 #define __SIZEOF_INT__ 4 #else #error "unexpected __INT_MAX__ value" #endif #if __LONG_MAX__ == 2147483647L #define __LONG_WIDTH__ 32 #define __SIZEOF_LONG__ 4 #else #error "unexpected __LONG_MAX__ value" #endif #if __LONG_LONG_MAX__ == 9223372036854775807LL #define __LONG_LONG_WIDTH__ 64 #define __SIZEOF_LONG_LONG__ 8 #else #error "unexpected __LONG_LONG_MAX__ value" #endif #if __INTMAX_MAX__ == 9223372036854775807LL #define __INTMAX_WIDTH__ 64 #define __SIZEOF_INTMAX__ 8 #define __UINTMAX_MAX__ 0xffffffffffffffffULL #define __UINTMAX_WIDTH__ 64 #define __SIZEOF_UINTMAX__ 8 #else #error "unexpected __INTMAX_MAX__ value" #endif /* * No xcc provided definitions related to pointers, so let's just enforce * the Zephyr expected type. */ #define __INTPTR_MAX__ 0x7fffffffL #define __INTPTR_TYPE__ long int #define __INTPTR_WIDTH__ 32 #define __SIZEOF_POINTER__ 4 #define __PTRDIFF_MAX__ 0x7fffffffL #define __PTRDIFF_WIDTH__ 32 #define __SIZEOF_PTRDIFF_T__ 4 #define __UINTPTR_MAX__ 0xffffffffLU #define __UINTPTR_TYPE__ long unsigned int /* * xcc already defines __SIZE_TYPE__ as "unsigned int" but there is no way * to safeguard that here with preprocessor equality. */ #define __SIZE_MAX__ 0xffffffffU #define __SIZE_WIDTH__ 32 #define __SIZEOF_SIZE_T__ 4 /* * The following defines are inferred from the xcc provided defines * already tested above. */ #define __INT8_MAX__ 0x7f #define __INT8_TYPE__ signed char #define __INT16_MAX__ 0x7fff #define __INT16_TYPE__ short int #define __INT32_MAX__ 0x7fffffff #define __INT32_TYPE__ int #define __INT64_MAX__ 0x7fffffffffffffffLL #define __INT64_TYPE__ long long int #define __INT_FAST8_MAX__ 0x7f #define __INT_FAST8_TYPE__ signed char #define __INT_FAST8_WIDTH__ 8 #define __INT_FAST16_MAX__ 0x7fffffff #define __INT_FAST16_TYPE__ int #define __INT_FAST16_WIDTH__ 32 #define __INT_FAST32_MAX__ 0x7fffffff #define __INT_FAST32_TYPE__ int #define __INT_FAST32_WIDTH__ 32 #define __INT_FAST64_MAX__ 0x7fffffffffffffffLL #define __INT_FAST64_TYPE__ long long int #define __INT_FAST64_WIDTH__ 64 #define __INT_LEAST8_MAX__ 0x7f #define __INT_LEAST8_TYPE__ signed char #define __INT_LEAST8_WIDTH__ 8 #define __INT_LEAST16_MAX__ 0x7fff #define __INT_LEAST16_TYPE__ short int #define __INT_LEAST16_WIDTH__ 16 #define __INT_LEAST32_MAX__ 0x7fffffff #define __INT_LEAST32_TYPE__ int #define __INT_LEAST32_WIDTH__ 32 #define __INT_LEAST64_MAX__ 0x7fffffffffffffffLL #define __INT_LEAST64_TYPE__ long long int #define __INT_LEAST64_WIDTH__ 64 #define __UINT8_MAX__ 0xffU #define __UINT8_TYPE__ unsigned char #define __UINT16_MAX__ 0xffffU #define __UINT16_TYPE__ short unsigned int #define __UINT32_MAX__ 0xffffffffU #define __UINT32_TYPE__ unsigned int #define __UINT64_MAX__ 0xffffffffffffffffULL #define __UINT64_TYPE__ long long unsigned int #define __UINT_FAST8_MAX__ 0xffU #define __UINT_FAST8_TYPE__ unsigned char #define __UINT_FAST16_MAX__ 0xffffffffU #define __UINT_FAST16_TYPE__ unsigned int #define __UINT_FAST32_MAX__ 0xffffffffU #define __UINT_FAST32_TYPE__ unsigned int #define __UINT_FAST64_MAX__ 0xffffffffffffffffULL #define __UINT_FAST64_TYPE__ long long unsigned int #define __UINT_LEAST8_MAX__ 0xffU #define __UINT_LEAST8_TYPE__ unsigned char #define __UINT_LEAST16_MAX__ 0xffffU #define __UINT_LEAST16_TYPE__ short unsigned int #define __UINT_LEAST32_MAX__ 0xffffffffU #define __UINT_LEAST32_TYPE__ unsigned int #define __UINT_LEAST64_MAX__ 0xffffffffffffffffULL #define __UINT_LEAST64_TYPE__ long long unsigned int #endif ```
/content/code_sandbox/include/zephyr/toolchain/xcc_missing_defs.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,199
```objective-c /* * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com> * */ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_MWDT_H_ #define ZEPHYR_INCLUDE_TOOLCHAIN_MWDT_H_ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_H_ #error Please do not include toolchain-specific headers directly, use <zephyr/toolchain.h> instead #endif #ifndef _LINKER #if defined(_ASMLANGUAGE) #include <zephyr/toolchain/common.h> #define FUNC_CODE() #define FUNC_INSTR(a) #ifdef __MW_ASM_RV_MACRO__ .macro section_var_mwdt, section, symbol .section \section().\symbol, "aw" \symbol : .endm .macro section_func_mwdt, section, symbol .section \section().\symbol, "ax" FUNC_CODE() PERFOPT_ALIGN \symbol : FUNC_INSTR(symbol) .endm .macro section_subsec_func_mwdt, section, subsection, symbol .section \section().\subsection, "ax" PERFOPT_ALIGN \symbol : .endm #else .macro section_var_mwdt, section, symbol .section .\&section\&.\&symbol, "aw" symbol : .endm .macro section_func_mwdt, section, symbol .section .\&section\&.\&symbol, "ax" FUNC_CODE() PERFOPT_ALIGN symbol : FUNC_INSTR(symbol) .endm .macro section_subsec_func_mwdt, section, subsection, symbol .section .\&section\&.\&subsection, "ax" PERFOPT_ALIGN symbol : .endm #endif /* __MW_ASM_RV_MACRO__ */ #define SECTION_VAR(sect, sym) section_var_mwdt sect, sym #define SECTION_FUNC(sect, sym) section_func_mwdt sect, sym #define SECTION_SUBSEC_FUNC(sect, subsec, sym) \ section_subsec_func_mwdt sect, subsec, sym #ifdef __MW_ASM_RV_MACRO__ .macro glbl_text_mwdt, symbol .globl \symbol .type \symbol, @function .endm .macro glbl_data_mwdt, symbol .globl \symbol .type \symbol, @object .endm .macro weak_data_mwdt, symbol .weak \symbol .type \symbol, @object .endm .macro weak_text_mwdt, symbol .weak \symbol .type \symbol, @function .endm #else .macro glbl_text_mwdt, symbol .globl symbol .type symbol, @function .endm .macro glbl_data_mwdt, symbol .globl symbol .type symbol, @object .endm .macro weak_data_mwdt, symbol .weak symbol .type symbol, @object .endm .macro weak_text_mwdt, symbol .weak symbol .type symbol, @function .endm #endif /* __MW_ASM_RV_MACRO__ */ #define GTEXT(sym) glbl_text_mwdt sym #define GDATA(sym) glbl_data_mwdt sym #define WDATA(sym) weak_data_mwdt sym #define WTEXT(sym) weak_text_mwdt sym #else /* defined(_ASMLANGUAGE) */ /* MWDT toolchain misses ssize_t definition which is used by Zephyr */ #ifndef _SSIZE_T_DEFINED #define _SSIZE_T_DEFINED #ifdef CONFIG_64BIT typedef long ssize_t; #else typedef int ssize_t; #endif #endif /* _SSIZE_T_DEFINED */ #ifdef CONFIG_NEWLIB_LIBC #error "ARC MWDT doesn't support building with CONFIG_NEWLIB_LIBC as it doesn't have newlib" #endif /* CONFIG_NEWLIB_LIBC */ #ifdef CONFIG_NATIVE_APPLICATION #error "ARC MWDT doesn't support building Zephyr as an native application" #endif /* CONFIG_NATIVE_APPLICATION */ #define __no_optimization __attribute__((optnone)) #define __fallthrough __attribute__((fallthrough)) #define TOOLCHAIN_HAS_C_GENERIC 1 #define TOOLCHAIN_HAS_C_AUTO_TYPE 1 #include <zephyr/toolchain/gcc.h> #undef BUILD_ASSERT #if defined(__cplusplus) && (__cplusplus >= 201103L) #define BUILD_ASSERT(EXPR, MSG...) static_assert(EXPR, "" MSG) #elif defined(__cplusplus) /* For cpp98 */ #define BUILD_ASSERT(EXPR, MSG...) #else #define BUILD_ASSERT(EXPR, MSG...) _Static_assert((EXPR), "" MSG) #endif #define __builtin_arc_nop() _nop() #endif /* _ASMLANGUAGE */ #endif /* !_LINKER */ #endif /* ZEPHYR_INCLUDE_TOOLCHAIN_MWDT_H_ */ ```
/content/code_sandbox/include/zephyr/toolchain/mwdt.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,025
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_ARMCLANG_H_ #define ZEPHYR_INCLUDE_TOOLCHAIN_ARMCLANG_H_ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_H_ #error Please do not include toolchain-specific headers directly, use <zephyr/toolchain.h> instead #endif #include <zephyr/toolchain/llvm.h> /* * To reuse as much as possible from the llvm.h header we only redefine the * __GENERIC_SECTION and Z_GENERIC_SECTION macros here to include the `used` keyword. */ #undef __GENERIC_SECTION #undef Z_GENERIC_SECTION #define __GENERIC_SECTION(segment) __attribute__((section(STRINGIFY(segment)), used)) #define Z_GENERIC_SECTION(segment) __GENERIC_SECTION(segment) #endif /* ZEPHYR_INCLUDE_TOOLCHAIN_ARMCLANG_H_ */ ```
/content/code_sandbox/include/zephyr/toolchain/armclang.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
169
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_STDINT_H_ #define ZEPHYR_INCLUDE_TOOLCHAIN_STDINT_H_ /* * Some gcc versions and/or configurations as found in the Zephyr SDK * (questionably) define __INT32_TYPE__ and derivatives as a long int * which makes the printf format checker to complain about long vs int * mismatch when %u is given a uint32_t argument, and uint32_t pointers not * being compatible with int pointers. Let's redefine them to follow * common expectations and usage. */ #if __SIZEOF_INT__ != 4 #error "unexpected int width" #endif #undef __INT32_TYPE__ #undef __UINT32_TYPE__ #undef __INT_FAST32_TYPE__ #undef __UINT_FAST32_TYPE__ #undef __INT_LEAST32_TYPE__ #undef __UINT_LEAST32_TYPE__ #undef __INT64_TYPE__ #undef __UINT64_TYPE__ #undef __INT_FAST64_TYPE__ #undef __UINT_FAST64_TYPE__ #undef __INT_LEAST64_TYPE__ #undef __UINT_LEAST64_TYPE__ #define __INT32_TYPE__ int #define __UINT32_TYPE__ unsigned int #define __INT_FAST32_TYPE__ __INT32_TYPE__ #define __UINT_FAST32_TYPE__ __UINT32_TYPE__ #define __INT_LEAST32_TYPE__ __INT32_TYPE__ #define __UINT_LEAST32_TYPE__ __UINT32_TYPE__ #define __INT64_TYPE__ long long int #define __UINT64_TYPE__ unsigned long long int #define __INT_FAST64_TYPE__ __INT64_TYPE__ #define __UINT_FAST64_TYPE__ __UINT64_TYPE__ #define __INT_LEAST64_TYPE__ __INT64_TYPE__ #define __UINT_LEAST64_TYPE__ __UINT64_TYPE__ /* * The confusion also exists with __INTPTR_TYPE__ which is either an int * (even when __INT32_TYPE__ is a long int) or a long int. Let's redefine * it to a long int to get some uniformity. Doing so also makes it compatible * with LP64 (64-bit) targets where a long is always 64-bit wide. */ #if __SIZEOF_POINTER__ != __SIZEOF_LONG__ #error "unexpected size difference between pointers and long ints" #endif #undef __INTPTR_TYPE__ #undef __UINTPTR_TYPE__ #define __INTPTR_TYPE__ long int #define __UINTPTR_TYPE__ long unsigned int /* * Re-define the INTN_C(value) integer constant expression macros to match the * integer types re-defined above. */ #undef __INT32_C #undef __UINT32_C #undef __INT64_C #undef __UINT64_C #define __INT32_C(c) c #define __UINT32_C(c) c ## U #define __INT64_C(c) c ## LL #define __UINT64_C(c) c ## ULL #endif /* ZEPHYR_INCLUDE_TOOLCHAIN_STDINT_H_ */ ```
/content/code_sandbox/include/zephyr/toolchain/zephyr_stdint.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
602
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ #define ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_H_ #error Please do not include toolchain-specific headers directly, use <zephyr/toolchain.h> instead #endif #define __no_optimization __attribute__((optnone)) #if __clang_major__ >= 10 #define __fallthrough __attribute__((fallthrough)) #endif #define TOOLCHAIN_CLANG_VERSION \ ((__clang_major__ * 10000) + (__clang_minor__ * 100) + \ __clang_patchlevel__) #define TOOLCHAIN_HAS_PRAGMA_DIAG 1 #if TOOLCHAIN_CLANG_VERSION >= 30800 #define TOOLCHAIN_HAS_C_GENERIC 1 #define TOOLCHAIN_HAS_C_AUTO_TYPE 1 #endif #include <zephyr/toolchain/gcc.h> /* * Provide these definitions only when minimal libc is used. * Avoid collision with defines from include/zephyr/toolchain/zephyr_stdint.h */ #ifdef CONFIG_MINIMAL_LIBC #define __int_c(v, suffix) v ## suffix #define int_c(v, suffix) __int_c(v, suffix) #define uint_c(v, suffix) __int_c(v ## U, suffix) #ifndef CONFIG_ENFORCE_ZEPHYR_STDINT #ifdef __INT64_TYPE__ #undef __int_least64_c_suffix__ #undef __int_least32_c_suffix__ #undef __int_least16_c_suffix__ #undef __int_least8_c_suffix__ #ifdef __INT64_C_SUFFIX__ #define __int_least64_c_suffix__ __INT64_C_SUFFIX__ #define __int_least32_c_suffix__ __INT64_C_SUFFIX__ #define __int_least16_c_suffix__ __INT64_C_SUFFIX__ #define __int_least8_c_suffix__ __INT64_C_SUFFIX__ #endif /* __INT64_C_SUFFIX__ */ #endif /* __INT64_TYPE__ */ #ifdef __INT_LEAST64_TYPE__ #ifdef __int_least64_c_suffix__ #define __INT64_C(x) int_c(x, __int_least64_c_suffix__) #define __UINT64_C(x) uint_c(x, __int_least64_c_suffix__) #else #define __INT64_C(x) x #define __UINT64_C(x) x ## U #endif /* __int_least64_c_suffix__ */ #endif /* __INT_LEAST64_TYPE__ */ #ifdef __INT32_TYPE__ #undef __int_least32_c_suffix__ #undef __int_least16_c_suffix__ #undef __int_least8_c_suffix__ #ifdef __INT32_C_SUFFIX__ #define __int_least32_c_suffix__ __INT32_C_SUFFIX__ #define __int_least16_c_suffix__ __INT32_C_SUFFIX__ #define __int_least8_c_suffix__ __INT32_C_SUFFIX__ #endif /* __INT32_C_SUFFIX__ */ #endif /* __INT32_TYPE__ */ #ifdef __INT_LEAST32_TYPE__ #ifdef __int_least32_c_suffix__ #define __INT32_C(x) int_c(x, __int_least32_c_suffix__) #define __UINT32_C(x) uint_c(x, __int_least32_c_suffix__) #else #define __INT32_C(x) x #define __UINT32_C(x) x ## U #endif /* __int_least32_c_suffix__ */ #endif /* __INT_LEAST32_TYPE__ */ #endif /* !CONFIG_ENFORCE_ZEPHYR_STDINT */ #ifdef __INT16_TYPE__ #undef __int_least16_c_suffix__ #undef __int_least8_c_suffix__ #ifdef __INT16_C_SUFFIX__ #define __int_least16_c_suffix__ __INT16_C_SUFFIX__ #define __int_least8_c_suffix__ __INT16_C_SUFFIX__ #endif /* __INT16_C_SUFFIX__ */ #endif /* __INT16_TYPE__ */ #ifdef __INT_LEAST16_TYPE__ #ifdef __int_least16_c_suffix__ #define __INT16_C(x) int_c(x, __int_least16_c_suffix__) #define __UINT16_C(x) uint_c(x, __int_least16_c_suffix__) #else #define __INT16_C(x) x #define __UINT16_C(x) x ## U #endif /* __int_least16_c_suffix__ */ #endif /* __INT_LEAST16_TYPE__ */ #ifdef __INT8_TYPE__ #undef __int_least8_c_suffix__ #ifdef __INT8_C_SUFFIX__ #define __int_least8_c_suffix__ __INT8_C_SUFFIX__ #endif /* __INT8_C_SUFFIX__ */ #endif /* __INT8_TYPE__ */ #ifdef __INT_LEAST8_TYPE__ #ifdef __int_least8_c_suffix__ #define __INT8_C(x) int_c(x, __int_least8_c_suffix__) #define __UINT8_C(x) uint_c(x, __int_least8_c_suffix__) #else #define __INT8_C(x) x #define __UINT8_C(x) x ## U #endif /* __int_least8_c_suffix__ */ #endif /* __INT_LEAST8_TYPE__ */ #define __INTMAX_C(x) int_c(x, __INTMAX_C_SUFFIX__) #define __UINTMAX_C(x) int_c(x, __UINTMAX_C_SUFFIX__) #endif /* CONFIG_MINIMAL_LIBC */ #endif /* ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ */ ```
/content/code_sandbox/include/zephyr/toolchain/llvm.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,057
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_COMMON_H_ #define ZEPHYR_INCLUDE_TOOLCHAIN_COMMON_H_ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_H_ #error Please do not include toolchain-specific headers directly, use <zephyr/toolchain.h> instead #endif /** * @file * @brief Common toolchain abstraction * * Macros to abstract compiler capabilities (common to all toolchains). */ /* Abstract use of extern keyword for compatibility between C and C++ */ #ifdef __cplusplus #define EXTERN_C extern "C" #else #define EXTERN_C extern #endif /* Use TASK_ENTRY_CPP to tag task entry points defined in C++ files. */ #ifdef __cplusplus #define TASK_ENTRY_CPP extern "C" #endif #ifndef ZRESTRICT #ifndef __cplusplus #define ZRESTRICT restrict #else #define ZRESTRICT #endif #endif /* * Generate a reference to an external symbol. * The reference indicates to the linker that the symbol is required * by the module containing the reference and should be included * in the image if the module is in the image. * * The assembler directive ".set" is used to define a local symbol. * No memory is allocated, and the local symbol does not appear in * the symbol table. */ #ifdef _ASMLANGUAGE #define REQUIRES(sym) .set sym ## _Requires, sym #else #define REQUIRES(sym) __asm__ (".set " # sym "_Requires, " # sym "\n\t"); #endif #ifdef _ASMLANGUAGE #define SECTION .section #endif /* * If the project is being built for speed (i.e. not for minimum size) then * align functions and branches in executable sections to improve performance. */ #ifdef _ASMLANGUAGE #if defined(CONFIG_X86) #ifdef PERF_OPT #define PERFOPT_ALIGN .balign 16 #else #define PERFOPT_ALIGN .balign 1 #endif #elif defined(CONFIG_ARM) || defined(CONFIG_ARM64) #define PERFOPT_ALIGN .balign 4 #elif defined(CONFIG_ARC) /* .align assembler directive is supposed by all ARC toolchains and it is * implemented in a same way across ARC toolchains. */ #define PERFOPT_ALIGN .align 4 #elif defined(CONFIG_NIOS2) || defined(CONFIG_RISCV) || \ defined(CONFIG_XTENSA) || defined(CONFIG_MIPS) #define PERFOPT_ALIGN .balign 4 #elif defined(CONFIG_ARCH_POSIX) #elif defined(CONFIG_SPARC) #define PERFOPT_ALIGN .align 4 #else #error Architecture unsupported #endif #define GC_SECTION(sym) SECTION .text.##sym, "ax" #endif /* _ASMLANGUAGE */ /* force inlining a function */ #if !defined(_ASMLANGUAGE) #ifdef CONFIG_COVERAGE /* * The always_inline attribute forces a function to be inlined, * even ignoring -fno-inline. So for code coverage, do not * force inlining of these functions to keep their bodies around * so their number of executions can be counted. * * Note that "inline" is kept here for kobject_hash.c and * priv_stacks_hash.c. These are built without compiler flags * used for coverage. ALWAYS_INLINE cannot be empty as compiler * would complain about unused functions. Attaching unused * attribute would result in their text sections balloon more than * 10 times in size, as those functions are kept in text section. * So just keep "inline" here. */ #define ALWAYS_INLINE inline #else #define ALWAYS_INLINE inline __attribute__((always_inline)) #endif #endif #define Z_STRINGIFY(x) #x #define STRINGIFY(s) Z_STRINGIFY(s) /* concatenate the values of the arguments into one */ #define _DO_CONCAT(x, y) x ## y #define _CONCAT(x, y) _DO_CONCAT(x, y) /* Additionally used as a sentinel by gen_syscalls.py to identify what * functions are system calls * * Note POSIX unit tests don't still generate the system call stubs, so * until path_to_url is * fixed via possibly #4174, we introduce this hack -- which will * disallow us to test system calls in POSIX unit testing (currently * not used). */ #ifndef ZTEST_UNITTEST #define __syscall static inline #define __syscall_always_inline static inline __attribute__((always_inline)) #else #define __syscall #define __syscall_always_inline #endif /* ZTEST_UNITTEST */ /* Definitions for struct declaration tags. These are sentinel values used by * parse_syscalls.py to gather a list of names of struct declarations that * have these tags applied for them. */ /* Indicates this is a driver subsystem */ #define __subsystem /* Indicates this is a network socket object */ #define __net_socket #ifndef BUILD_ASSERT /* Compile-time assertion that makes the build to fail. * Common implementation swallows the message. */ #define BUILD_ASSERT(EXPR, MSG...) \ enum _CONCAT(__build_assert_enum, __COUNTER__) { \ _CONCAT(__build_assert, __COUNTER__) = 1 / !!(EXPR) \ } #endif /* * This is meant to be used in conjunction with __in_section() and similar * where scattered structure instances are concatenated together by the linker * and walked by the code at run time just like a contiguous array of such * structures. * * Assemblers and linkers may insert alignment padding by default whose * size is larger than the natural alignment for those structures when * gathering various section segments together, messing up the array walk. * To prevent this, we need to provide an explicit alignment not to rely * on the default that might just work by luck. * * Alignment statements in linker scripts are not sufficient as * the assembler may add padding by itself to each segment when switching * between sections within the same file even if it merges many such segments * into a single section in the end. */ #define Z_DECL_ALIGN(type) __aligned(__alignof(type)) type /* Check if a pointer is aligned for against a specific byte boundary */ #define IS_PTR_ALIGNED_BYTES(ptr, bytes) ((((uintptr_t)ptr) % bytes) == 0) /* Check if a pointer is aligned enough for a particular data type. */ #define IS_PTR_ALIGNED(ptr, type) IS_PTR_ALIGNED_BYTES(ptr, __alignof(type)) /** @brief Tag a symbol (e.g. function) to be kept in the binary even though it is not used. * * It prevents symbol from being removed by the linker garbage collector. It * is achieved by adding a pointer to that symbol to the kept memory section. * * @param symbol Symbol to keep. */ #define LINKER_KEEP(symbol) \ static const void * const symbol##_ptr __used \ __attribute__((__section__(".symbol_to_keep"))) = (void *)&symbol #endif /* ZEPHYR_INCLUDE_TOOLCHAIN_COMMON_H_ */ ```
/content/code_sandbox/include/zephyr/toolchain/common.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,527
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_XCC_H_ #define ZEPHYR_INCLUDE_TOOLCHAIN_XCC_H_ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_H_ #error Please do not include toolchain-specific headers directly, use <zephyr/toolchain.h> instead #endif /* toolchain/gcc.h errors out if __BYTE_ORDER__ cannot be determined * there. However, __BYTE_ORDER__ is actually being defined later in * this file. So define __BYTE_ORDER__ to skip the check in gcc.h * and undefine after including gcc.h. * * Clang has it defined so there is no need to work around. */ #ifndef __clang__ #define __BYTE_ORDER__ #endif #ifdef __clang__ #include <zephyr/toolchain/llvm.h> #else #include <zephyr/toolchain/gcc.h> #endif #ifndef __clang__ #undef __BYTE_ORDER__ #endif #include <stdbool.h> #ifndef __INT8_C #define __INT8_C(x) x #endif #ifndef INT8_C #define INT8_C(x) __INT8_C(x) #endif #ifndef __UINT8_C #define __UINT8_C(x) x ## U #endif #ifndef UINT8_C #define UINT8_C(x) __UINT8_C(x) #endif #ifndef __INT16_C #define __INT16_C(x) x #endif #ifndef INT16_C #define INT16_C(x) __INT16_C(x) #endif #ifndef __UINT16_C #define __UINT16_C(x) x ## U #endif #ifndef UINT16_C #define UINT16_C(x) __UINT16_C(x) #endif #ifndef __INT32_C #define __INT32_C(x) x #endif #ifndef INT32_C #define INT32_C(x) __INT32_C(x) #endif #ifndef __UINT32_C #define __UINT32_C(x) x ## U #endif #ifndef UINT32_C #define UINT32_C(x) __UINT32_C(x) #endif #ifndef __INT64_C #define __INT64_C(x) x #endif #ifndef INT64_C #define INT64_C(x) __INT64_C(x) #endif #ifndef __UINT64_C #define __UINT64_C(x) x ## ULL #endif #ifndef UINT64_C #define UINT64_C(x) __UINT64_C(x) #endif #ifndef __INTMAX_C #define __INTMAX_C(x) x #endif #ifndef INTMAX_C #define INTMAX_C(x) __INTMAX_C(x) #endif #ifndef __UINTMAX_C #define __UINTMAX_C(x) x ## ULL #endif #ifndef UINTMAX_C #define UINTMAX_C(x) __UINTMAX_C(x) #endif #ifndef __COUNTER__ /* XCC (GCC-based compiler) doesn't support __COUNTER__ * but this should be good enough */ #define __COUNTER__ __LINE__ #endif #undef __in_section_unique #define __in_section_unique(seg) \ __attribute__((section("." STRINGIFY(seg) "." STRINGIFY(__COUNTER__)))) #undef __in_section_unique_named #define __in_section_unique_named(seg, name) \ __attribute__((section("." STRINGIFY(seg) \ "." STRINGIFY(__COUNTER__) \ "." STRINGIFY(name)))) #ifndef __GCC_LINKER_CMD__ #include <xtensa/config/core.h> /* * XCC does not define the following macros with the expected names, but the * HAL defines similar ones. Thus we include it and define the missing macros * ourselves. */ #if XCHAL_MEMORY_ORDER == XTHAL_BIGENDIAN #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__ #elif XCHAL_MEMORY_ORDER == XTHAL_LITTLEENDIAN #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ #else #error "Cannot determine __BYTE_ORDER__" #endif #endif /* __GCC_LINKER_CMD__ */ #define __builtin_unreachable() __builtin_trap() /* Not a full barrier, just a SW barrier */ #define __sync_synchronize() do { __asm__ __volatile__ ("" ::: "memory"); } \ while (false) #ifdef __deprecated /* * XCC does not support using deprecated attribute in enum, * so just nullify it here to avoid compilation errors. */ #undef __deprecated #define __deprecated #endif #endif ```
/content/code_sandbox/include/zephyr/toolchain/xcc.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
909
```objective-c /* * */ #ifndef ZEPHYR_POSIX_FCNTL_H_ #define ZEPHYR_POSIX_FCNTL_H_ #ifdef CONFIG_PICOLIBC #define O_CREAT 0x0040 #else #define O_CREAT 0x0200 #endif #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) #define O_RDONLY 00 #define O_WRONLY 01 #define O_RDWR 02 #define O_APPEND 0x0400 #define O_EXCL 0x0800 #define O_NONBLOCK 0x4000 #define F_DUPFD 0 #define F_GETFL 3 #define F_SETFL 4 #ifdef __cplusplus extern "C" { #endif int open(const char *name, int flags, ...); int fcntl(int fildes, int cmd, ...); #ifdef __cplusplus } #endif #endif /* ZEPHYR_POSIX_FCNTL_H_ */ ```
/content/code_sandbox/include/zephyr/posix/fcntl.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
200
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_SYSLOG_H_ #define ZEPHYR_INCLUDE_POSIX_SYSLOG_H_ #include <stdarg.h> /* option */ #define LOG_PID 1 #define LOG_CONS 2 #define LOG_NDELAY 4 #define LOG_ODELAY 8 #define LOG_NOWAIT 16 #define LOG_PERROR 32 /* facility */ #define LOG_KERN 0 #define LOG_USER 1 #define LOG_MAIL 2 #define LOG_NEWS 3 #define LOG_UUCP 4 #define LOG_DAEMON 5 #define LOG_AUTH 6 #define LOG_CRON 7 #define LOG_LPR 8 #define LOG_LOCAL0 9 #define LOG_LOCAL1 10 #define LOG_LOCAL2 11 #define LOG_LOCAL3 12 #define LOG_LOCAL4 13 #define LOG_LOCAL5 14 #define LOG_LOCAL6 15 #define LOG_LOCAL7 16 /* priority */ #define LOG_EMERG 0 #define LOG_ALERT 1 #define LOG_CRIT 2 #define LOG_ERR 3 #define LOG_WARNING 4 #define LOG_NOTICE 5 #define LOG_INFO 6 #define LOG_DEBUG 7 /* generate a valid log mask */ #define LOG_MASK(mask) ((mask) & BIT_MASK(LOG_DEBUG + 1)) #ifdef __cplusplus extern "C" { #endif void closelog(void); void openlog(const char *ident, int logopt, int facility); int setlogmask(int maskpri); void syslog(int priority, const char *message, ...); void vsyslog(int priority, const char *format, va_list ap); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_SYSLOG_H_ */ ```
/content/code_sandbox/include/zephyr/posix/syslog.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
379
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_STROPTS_H_ #define ZEPHYR_INCLUDE_POSIX_STROPTS_H_ #define RS_HIPRI BIT(0) #ifdef __cplusplus extern "C" { #endif struct strbuf { int maxlen; int len; char *buf; }; int putmsg(int fildes, const struct strbuf *ctlptr, const struct strbuf *dataptr, int flags); int fdetach(const char *path); int fattach(int fildes, const char *path); int getmsg(int fildes, struct strbuf *ctlptr, struct strbuf *dataptr, int *flagsp); int getpmsg(int fildes, struct strbuf *ctlptr, struct strbuf *dataptr, int *bandp, int *flagsp); int isastream(int fildes); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_STROPTS_H_ */ ```
/content/code_sandbox/include/zephyr/posix/stropts.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
205
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_GCC_H_ #define ZEPHYR_INCLUDE_TOOLCHAIN_GCC_H_ #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_H_ #error Please do not include toolchain-specific headers directly, use <zephyr/toolchain.h> instead #endif /** * @file * @brief GCC toolchain abstraction * * Macros to abstract compiler capabilities for GCC toolchain. */ #define TOOLCHAIN_GCC_VERSION \ ((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) + __GNUC_PATCHLEVEL__) /* GCC supports #pragma diagnostics since 4.6.0 */ #if !defined(TOOLCHAIN_HAS_PRAGMA_DIAG) && (TOOLCHAIN_GCC_VERSION >= 40600) #define TOOLCHAIN_HAS_PRAGMA_DIAG 1 #endif #if !defined(TOOLCHAIN_HAS_C_GENERIC) && (TOOLCHAIN_GCC_VERSION >= 40900) #define TOOLCHAIN_HAS_C_GENERIC 1 #endif #if !defined(TOOLCHAIN_HAS_C_AUTO_TYPE) && (TOOLCHAIN_GCC_VERSION >= 40900) #define TOOLCHAIN_HAS_C_AUTO_TYPE 1 #endif #define TOOLCHAIN_HAS_ZLA 1 /* * Older versions of GCC do not define __BYTE_ORDER__, so it must be manually * detected and defined using arch-specific definitions. */ #ifndef _LINKER #ifndef __ORDER_BIG_ENDIAN__ #define __ORDER_BIG_ENDIAN__ (1) #endif #ifndef __ORDER_LITTLE_ENDIAN__ #define __ORDER_LITTLE_ENDIAN__ (2) #endif #ifndef __BYTE_ORDER__ #if defined(__BIG_ENDIAN__) || defined(__ARMEB__) || \ defined(__THUMBEB__) || defined(__AARCH64EB__) || \ defined(__MIPSEB__) || defined(__TC32EB__) #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__ #elif defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || \ defined(__THUMBEL__) || defined(__AARCH64EL__) || \ defined(__MIPSEL__) || defined(__TC32EL__) #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ #else #error "__BYTE_ORDER__ is not defined and cannot be automatically resolved" #endif #endif #undef BUILD_ASSERT /* clear out common version */ /* C++11 has static_assert built in */ #if defined(__cplusplus) && (__cplusplus >= 201103L) #define BUILD_ASSERT(EXPR, MSG...) static_assert(EXPR, "" MSG) /* * GCC 4.6 and higher have the C11 _Static_assert built in and its * output is easier to understand than the common BUILD_ASSERT macros. * Don't use this in C++98 mode though (which we can hit, as * static_assert() is not available) */ #elif !defined(__cplusplus) && \ (((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))) || \ (__STDC_VERSION__) >= 201100) #define BUILD_ASSERT(EXPR, MSG...) _Static_assert((EXPR), "" MSG) #else #define BUILD_ASSERT(EXPR, MSG...) #endif #ifdef __cplusplus #define ZRESTRICT __restrict #else #define ZRESTRICT restrict #endif #include <zephyr/toolchain/common.h> #include <stdbool.h> #define ALIAS_OF(of) __attribute__((alias(#of))) #define FUNC_ALIAS(real_func, new_alias, return_type) \ return_type new_alias() ALIAS_OF(real_func) #if defined(CONFIG_ARCH_POSIX) && !defined(_ASMLANGUAGE) #include <zephyr/arch/posix/posix_trace.h> /*let's not segfault if this were to happen for some reason*/ #define CODE_UNREACHABLE \ {\ posix_print_error_and_exit("CODE_UNREACHABLE reached from %s:%d\n",\ __FILE__, __LINE__);\ __builtin_unreachable(); \ } #else #define CODE_UNREACHABLE __builtin_unreachable() #endif #define FUNC_NORETURN __attribute__((__noreturn__)) /* The GNU assembler for Cortex-M3 uses # for immediate values, not * comments, so the @nobits# trick does not work. */ #if defined(CONFIG_ARM) || defined(CONFIG_ARM64) #define _NODATA_SECTION(segment) __attribute__((section(#segment))) #else #define _NODATA_SECTION(segment) \ __attribute__((section(#segment ",\"wa\",@nobits#"))) #endif /* Unaligned access */ #define UNALIGNED_GET(g) \ __extension__ ({ \ struct __attribute__((__packed__)) { \ __typeof__(*(g)) __v; \ } *__g = (__typeof__(__g)) (g); \ __g->__v; \ }) #if (__GNUC__ >= 7) && (defined(CONFIG_ARM) || defined(CONFIG_ARM64)) /* Version of UNALIGNED_PUT() which issues a compiler_barrier() after * the store. It is required to workaround an apparent optimization * bug in GCC for ARM Cortex-M3 and higher targets, when multiple * byte, half-word and word stores (strb, strh, str instructions), * which support unaligned access, can be coalesced into store double * (strd) instruction, which doesn't support unaligned access (the * compilers in question do this optimization ignoring __packed__ * attribute). */ #define UNALIGNED_PUT(v, p) \ do { \ struct __attribute__((__packed__)) { \ __typeof__(*p) __v; \ } *__p = (__typeof__(__p)) (p); \ __p->__v = (v); \ compiler_barrier(); \ } while (false) #else #define UNALIGNED_PUT(v, p) \ do { \ struct __attribute__((__packed__)) { \ __typeof__(*p) __v; \ } *__p = (__typeof__(__p)) (p); \ __p->__v = (v); \ } while (false) #endif /* Double indirection to ensure section names are expanded before * stringification */ #define __GENERIC_SECTION(segment) __attribute__((section(STRINGIFY(segment)))) #define Z_GENERIC_SECTION(segment) __GENERIC_SECTION(segment) #define __GENERIC_DOT_SECTION(segment) \ __attribute__((section("." STRINGIFY(segment)))) #define Z_GENERIC_DOT_SECTION(segment) __GENERIC_DOT_SECTION(segment) #define ___in_section(a, b, c) \ __attribute__((section("." Z_STRINGIFY(a) \ "." Z_STRINGIFY(b) \ "." Z_STRINGIFY(c)))) #define __in_section(a, b, c) ___in_section(a, b, c) #define __in_section_unique(seg) ___in_section(seg, __FILE__, __COUNTER__) #define __in_section_unique_named(seg, name) \ ___in_section(seg, __FILE__, name) /* When using XIP, using '__ramfunc' places a function into RAM instead * of FLASH. Make sure '__ramfunc' is defined only when * CONFIG_ARCH_HAS_RAMFUNC_SUPPORT is defined, so that the compiler can * report an error if '__ramfunc' is used but the architecture does not * support it. */ #if !defined(CONFIG_XIP) #define __ramfunc #elif defined(CONFIG_ARCH_HAS_RAMFUNC_SUPPORT) #if defined(CONFIG_ARM) #define __ramfunc __attribute__((noinline)) \ __attribute__((long_call, section(".ramfunc"))) #else #define __ramfunc __attribute__((noinline)) \ __attribute__((section(".ramfunc"))) #endif #endif /* !CONFIG_XIP */ #ifndef __fallthrough #if __GNUC__ >= 7 #define __fallthrough __attribute__((fallthrough)) #else #define __fallthrough #endif /* __GNUC__ >= 7 */ #endif #ifndef __packed #define __packed __attribute__((__packed__)) #endif #ifndef __aligned #define __aligned(x) __attribute__((__aligned__(x))) #endif #define __may_alias __attribute__((__may_alias__)) #ifndef __printf_like #ifdef CONFIG_ENFORCE_ZEPHYR_STDINT #define __printf_like(f, a) __attribute__((format (printf, f, a))) #else /* * The Zephyr stdint convention enforces int32_t = int, int64_t = long long, * and intptr_t = long so that short string format length modifiers can be * used universally across ILP32 and LP64 architectures. Without that it * is possible for ILP32 toolchains to have int32_t = long and intptr_t = int * clashing with the Zephyr convention and generating pointless warnings * as they're still the same size. Inhibit the format argument type * validation in that case and let the other configs do it. */ #define __printf_like(f, a) #endif #endif #define __used __attribute__((__used__)) #define __unused __attribute__((__unused__)) #define __maybe_unused __attribute__((__unused__)) #ifndef __deprecated #define __deprecated __attribute__((deprecated)) /* When adding this, remember to follow the instructions in * path_to_url#deprecated */ #endif #ifndef __attribute_const__ #define __attribute_const__ __attribute__((__const__)) #endif #ifndef __must_check #define __must_check __attribute__((warn_unused_result)) #endif #define ARG_UNUSED(x) (void)(x) #define likely(x) (__builtin_expect((bool)!!(x), true) != 0L) #define unlikely(x) (__builtin_expect((bool)!!(x), false) != 0L) #define POPCOUNT(x) __builtin_popcount(x) #ifndef __no_optimization #define __no_optimization __attribute__((optimize("-O0"))) #endif #ifndef __weak #define __weak __attribute__((__weak__)) #endif #ifndef __attribute_nonnull #define __attribute_nonnull(...) __attribute__((nonnull(__VA_ARGS__))) #endif /* Builtins with availability that depend on the compiler version. */ #if __GNUC__ >= 5 #define HAS_BUILTIN___builtin_add_overflow 1 #define HAS_BUILTIN___builtin_sub_overflow 1 #define HAS_BUILTIN___builtin_mul_overflow 1 #define HAS_BUILTIN___builtin_div_overflow 1 #endif #if __GNUC__ >= 4 #define HAS_BUILTIN___builtin_clz 1 #define HAS_BUILTIN___builtin_clzl 1 #define HAS_BUILTIN___builtin_clzll 1 #define HAS_BUILTIN___builtin_ctz 1 #define HAS_BUILTIN___builtin_ctzl 1 #define HAS_BUILTIN___builtin_ctzll 1 #endif /* * Be *very* careful with these. You cannot filter out __DEPRECATED_MACRO with * -wno-deprecated, which has implications for -Werror. */ /* * Expands to nothing and generates a warning. Used like * * #define FOO __WARN("Please use BAR instead") ... * * The warning points to the location where the macro is expanded. */ #define __WARN(msg) __WARN1(GCC warning msg) #define __WARN1(s) _Pragma(#s) /* Generic message */ #ifndef __DEPRECATED_MACRO #define __DEPRECATED_MACRO __WARN("Macro is deprecated") /* When adding this, remember to follow the instructions in * path_to_url#deprecated */ #endif /* These macros allow having ARM asm functions callable from thumb */ #if defined(_ASMLANGUAGE) #if defined(CONFIG_ARM) #if defined(CONFIG_ASSEMBLER_ISA_THUMB2) #define FUNC_CODE() .thumb; #define FUNC_INSTR(a) #else #define FUNC_CODE() .code 32; #define FUNC_INSTR(a) #endif /* CONFIG_ASSEMBLER_ISA_THUMB2 */ #else #define FUNC_CODE() #define FUNC_INSTR(a) #endif /* CONFIG_ARM */ #endif /* _ASMLANGUAGE */ /* * These macros are used to declare assembly language symbols that need * to be typed properly(func or data) to be visible to the OMF tool. * So that the build tool could mark them as an entry point to be linked * correctly. This is an elfism. Use #if 0 for a.out. */ #if defined(_ASMLANGUAGE) #if defined(CONFIG_ARM) || defined(CONFIG_NIOS2) || defined(CONFIG_RISCV) \ || defined(CONFIG_XTENSA) || defined(CONFIG_ARM64) \ || defined(CONFIG_MIPS) #define GTEXT(sym) .global sym; .type sym, %function #define GDATA(sym) .global sym; .type sym, %object #define WTEXT(sym) .weak sym; .type sym, %function #define WDATA(sym) .weak sym; .type sym, %object #elif defined(CONFIG_ARC) /* * Need to use assembly macros because ';' is interpreted as the start of * a single line comment in the ARC assembler. */ .macro glbl_text symbol .globl \symbol .type \symbol, %function .endm .macro glbl_data symbol .globl \symbol .type \symbol, %object .endm .macro weak_data symbol .weak \symbol .type \symbol, %object .endm #define GTEXT(sym) glbl_text sym #define GDATA(sym) glbl_data sym #define WDATA(sym) weak_data sym #else /* !CONFIG_ARM && !CONFIG_ARC */ #define GTEXT(sym) .globl sym; .type sym, @function #define GDATA(sym) .globl sym; .type sym, @object #endif /* * These macros specify the section in which a given function or variable * resides. * * - SECTION_FUNC allows only one function to reside in a sub-section * - SECTION_SUBSEC_FUNC allows multiple functions to reside in a sub-section * This ensures that garbage collection only discards the section * if all functions in the sub-section are not referenced. */ #if defined(CONFIG_ARC) /* * Need to use assembly macros because ';' is interpreted as the start of * a single line comment in the ARC assembler. * * Also, '\()' is needed in the .section directive of these macros for * correct substitution of the 'section' variable. */ .macro section_var section, symbol .section .\section\().\symbol \symbol : .endm .macro section_func section, symbol .section .\section\().\symbol, "ax" FUNC_CODE() PERFOPT_ALIGN \symbol : FUNC_INSTR(\symbol) .endm .macro section_subsec_func section, subsection, symbol .section .\section\().\subsection, "ax" PERFOPT_ALIGN \symbol : .endm #define SECTION_VAR(sect, sym) section_var sect, sym #define SECTION_FUNC(sect, sym) section_func sect, sym #define SECTION_SUBSEC_FUNC(sect, subsec, sym) \ section_subsec_func sect, subsec, sym #else /* !CONFIG_ARC */ #define SECTION_VAR(sect, sym) .section .sect.sym; sym: #define SECTION_FUNC(sect, sym) \ .section .sect.sym, "ax"; \ FUNC_CODE() \ PERFOPT_ALIGN; sym : \ FUNC_INSTR(sym) #define SECTION_SUBSEC_FUNC(sect, subsec, sym) \ .section .sect.subsec, "ax"; PERFOPT_ALIGN; sym : #endif /* CONFIG_ARC */ #endif /* _ASMLANGUAGE */ #if defined(_ASMLANGUAGE) #if defined(CONFIG_ARM) #if defined(CONFIG_ASSEMBLER_ISA_THUMB2) /* '.syntax unified' is a gcc-ism used in thumb-2 asm files */ #define _ASM_FILE_PROLOGUE .text; .syntax unified; .thumb #else #define _ASM_FILE_PROLOGUE .text; .code 32 #endif /* CONFIG_ASSEMBLER_ISA_THUMB2 */ #elif defined(CONFIG_ARM64) #define _ASM_FILE_PROLOGUE .text #endif /* CONFIG_ARM64 || CONFIG_ARM */ #endif /* _ASMLANGUAGE */ /* * These macros generate absolute symbols for GCC */ /* create an extern reference to the absolute symbol */ #define GEN_OFFSET_EXTERN(name) extern const char name[] #define GEN_ABS_SYM_BEGIN(name) \ EXTERN_C void name(void); \ void name(void) \ { #define GEN_ABS_SYM_END } /* * Note that GEN_ABSOLUTE_SYM(), depending on the architecture * and toolchain, may restrict the range of values permitted * for assignment to the named symbol. * * For example, on x86, "value" is interpreted as signed * 32-bit integer. Passing in an unsigned 32-bit integer * with MSB set would result in a negative integer. * Moreover, GCC would error out if an integer larger * than 2^32-1 is passed as "value". */ /* * GEN_ABSOLUTE_SYM_KCONFIG() is outputted by the build system * to generate named symbol/value pairs for kconfigs. */ #if defined(CONFIG_ARM) /* * GNU/ARM backend does not have a proper operand modifier which does not * produces prefix # followed by value, such as %0 for PowerPC, Intel, and * MIPS. The workaround performed here is using %B0 which converts * the value to ~(value). Thus "n"(~(value)) is set in operand constraint * to output (value) in the ARM specific GEN_OFFSET macro. */ #define GEN_ABSOLUTE_SYM(name, value) \ __asm__(".globl\t" #name "\n\t.equ\t" #name \ ",%B0" \ "\n\t.type\t" #name ",%%object" : : "n"(~(value))) #define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \ __asm__(".globl\t" #name \ "\n\t.equ\t" #name "," #value \ "\n\t.type\t" #name ",%object") #elif defined(CONFIG_X86) #define GEN_ABSOLUTE_SYM(name, value) \ __asm__(".globl\t" #name "\n\t.equ\t" #name \ ",%c0" \ "\n\t.type\t" #name ",@object" : : "n"(value)) #define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \ __asm__(".globl\t" #name \ "\n\t.equ\t" #name "," #value \ "\n\t.type\t" #name ",@object") #elif defined(CONFIG_ARC) || defined(CONFIG_ARM64) #define GEN_ABSOLUTE_SYM(name, value) \ __asm__(".globl\t" #name "\n\t.equ\t" #name \ ",%c0" \ "\n\t.type\t" #name ",@object" : : "n"(value)) #define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \ __asm__(".globl\t" #name \ "\n\t.equ\t" #name "," #value \ "\n\t.type\t" #name ",@object") #elif defined(CONFIG_NIOS2) || defined(CONFIG_RISCV) || \ defined(CONFIG_XTENSA) || defined(CONFIG_MIPS) /* No special prefixes necessary for constants in this arch AFAICT */ #define GEN_ABSOLUTE_SYM(name, value) \ __asm__(".globl\t" #name "\n\t.equ\t" #name \ ",%0" \ "\n\t.type\t" #name ",%%object" : : "n"(value)) #define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \ __asm__(".globl\t" #name \ "\n\t.equ\t" #name "," #value \ "\n\t.type\t" #name ",%object") #elif defined(CONFIG_ARCH_POSIX) #define GEN_ABSOLUTE_SYM(name, value) \ __asm__(".globl\t" #name "\n\t.equ\t" #name \ ",%c0" \ "\n\t.type\t" #name ",@object" : : "n"(value)) #define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \ __asm__(".globl\t" #name \ "\n\t.equ\t" #name "," #value \ "\n\t.type\t" #name ",@object") #elif defined(CONFIG_SPARC) #define GEN_ABSOLUTE_SYM(name, value) \ __asm__(".global\t" #name "\n\t.equ\t" #name \ ",%0" \ "\n\t.type\t" #name ",#object" : : "n"(value)) #define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \ __asm__(".globl\t" #name \ "\n\t.equ\t" #name "," #value \ "\n\t.type\t" #name ",#object") #else #error processor architecture not supported #endif #define compiler_barrier() do { \ __asm__ __volatile__ ("" ::: "memory"); \ } while (false) /** @brief Return larger value of two provided expressions. * * Macro ensures that expressions are evaluated only once. * * @note Macro has limited usage compared to the standard macro as it cannot be * used: * - to generate constant integer, e.g. __aligned(Z_MAX(4,5)) * - static variable, e.g. array like static uint8_t array[Z_MAX(...)]; */ #define Z_MAX(a, b) ({ \ /* random suffix to avoid naming conflict */ \ __typeof__(a) _value_a_ = (a); \ __typeof__(b) _value_b_ = (b); \ (_value_a_ > _value_b_) ? _value_a_ : _value_b_; \ }) /** @brief Return smaller value of two provided expressions. * * Macro ensures that expressions are evaluated only once. See @ref Z_MAX for * macro limitations. */ #define Z_MIN(a, b) ({ \ /* random suffix to avoid naming conflict */ \ __typeof__(a) _value_a_ = (a); \ __typeof__(b) _value_b_ = (b); \ (_value_a_ < _value_b_) ? _value_a_ : _value_b_; \ }) /** @brief Return a value clamped to a given range. * * Macro ensures that expressions are evaluated only once. See @ref Z_MAX for * macro limitations. */ #define Z_CLAMP(val, low, high) ({ \ /* random suffix to avoid naming conflict */ \ __typeof__(val) _value_val_ = (val); \ __typeof__(low) _value_low_ = (low); \ __typeof__(high) _value_high_ = (high); \ (_value_val_ < _value_low_) ? _value_low_ : \ (_value_val_ > _value_high_) ? _value_high_ : \ _value_val_; \ }) /** * @brief Calculate power of two ceiling for some nonzero value * * @param x Nonzero unsigned long value * @return X rounded up to the next power of two */ #define Z_POW2_CEIL(x) \ ((x) <= 2UL ? (x) : (1UL << (8 * sizeof(long) - __builtin_clzl((x) - 1)))) /** * @brief Check whether or not a value is a power of 2 * * @param x The value to check * @return true if x is a power of 2, false otherwise */ #define Z_IS_POW2(x) (((x) != 0) && (((x) & ((x)-1)) == 0)) #if defined(CONFIG_ASAN) && defined(__clang__) #define __noasan __attribute__((no_sanitize("address"))) #else #define __noasan /**/ #endif #if defined(CONFIG_UBSAN) #define __noubsan __attribute__((no_sanitize("undefined"))) #else #define __noubsan #endif /** * @brief Function attribute to disable stack protector. * * @note Only supported for GCC >= 11.0.0 or Clang >= 7. */ #if (TOOLCHAIN_GCC_VERSION >= 110000) || \ (defined(TOOLCHAIN_CLANG_VERSION) && (TOOLCHAIN_CLANG_VERSION >= 70000)) #define FUNC_NO_STACK_PROTECTOR __attribute__((no_stack_protector)) #else #define FUNC_NO_STACK_PROTECTOR #endif #define TOOLCHAIN_IGNORE_WSHADOW_BEGIN \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wshadow\"") #define TOOLCHAIN_IGNORE_WSHADOW_END \ _Pragma("GCC diagnostic pop") #endif /* !_LINKER */ #endif /* ZEPHYR_INCLUDE_TOOLCHAIN_GCC_H_ */ ```
/content/code_sandbox/include/zephyr/toolchain/gcc.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
5,349
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_TIME_H_ #define ZEPHYR_INCLUDE_POSIX_TIME_H_ /* Read standard header. This may find <posix/time.h> since they * refer to the same file when include/posix is in the search path. */ #include <time.h> #ifdef CONFIG_NEWLIB_LIBC /* Kludge to support outdated newlib version as used in SDK 0.10 for Xtensa */ #include <newlib.h> #ifdef __NEWLIB__ /* Newever Newlib 3.x+ */ #include <sys/timespec.h> #else /* __NEWLIB__ */ /* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h, * so mimic it here. */ #include <sys/types.h> #ifndef __timespec_defined #ifdef __cplusplus extern "C" { #endif struct timespec { time_t tv_sec; long tv_nsec; }; struct itimerspec { struct timespec it_interval; /* Timer interval */ struct timespec it_value; /* Timer expiration */ }; #ifdef __cplusplus } #endif #endif /* __timespec_defined */ #endif /* __NEWLIB__ */ #else /* CONFIG_NEWLIB_LIBC */ /* Not Newlib */ # if defined(CONFIG_ARCH_POSIX) && defined(CONFIG_EXTERNAL_LIBC) # include <bits/types/struct_timespec.h> # include <bits/types/struct_itimerspec.h> # else # include <sys/timespec.h> # endif #endif /* CONFIG_NEWLIB_LIBC */ #include <zephyr/kernel.h> #include <errno.h> #include "posix_types.h" #include <zephyr/posix/signal.h> #ifdef __cplusplus extern "C" { #endif #ifndef CLOCK_REALTIME #define CLOCK_REALTIME 1 #endif #ifndef CLOCK_PROCESS_CPUTIME_ID #define CLOCK_PROCESS_CPUTIME_ID 2 #endif #ifndef CLOCK_THREAD_CPUTIME_ID #define CLOCK_THREAD_CPUTIME_ID 3 #endif #ifndef CLOCK_MONOTONIC #define CLOCK_MONOTONIC 4 #endif #ifndef TIMER_ABSTIME #define TIMER_ABSTIME 4 #endif static inline int32_t _ts_to_ms(const struct timespec *to) { return (int32_t)(to->tv_sec * MSEC_PER_SEC) + (int32_t)(to->tv_nsec / NSEC_PER_MSEC); } int clock_gettime(clockid_t clock_id, struct timespec *ts); int clock_getres(clockid_t clock_id, struct timespec *ts); int clock_settime(clockid_t clock_id, const struct timespec *ts); int clock_getcpuclockid(pid_t pid, clockid_t *clock_id); /* Timer APIs */ int timer_create(clockid_t clockId, struct sigevent *evp, timer_t *timerid); int timer_delete(timer_t timerid); int timer_gettime(timer_t timerid, struct itimerspec *its); int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue); int timer_getoverrun(timer_t timerid); int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp); #ifdef __cplusplus } #endif #else /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */ /* Read the toolchain header when <posix/time.h> finds itself on the * first attempt. */ #include_next <time.h> #endif /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */ ```
/content/code_sandbox/include/zephyr/posix/time.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
757
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_PWD_H_ #define ZEPHYR_INCLUDE_POSIX_PWD_H_ #ifdef __cplusplus extern "C" { #endif #include <zephyr/posix/sys/stat.h> struct passwd { /* user's login name */ char *pw_name; /* numerical user ID */ uid_t pw_uid; /* numerical group ID */ gid_t pw_gid; /* initial working directory */ char *pw_dir; /* program to use as shell */ char *pw_shell; }; int getpwnam_r(const char *nam, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result); int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_PWD_H_ */ ```
/content/code_sandbox/include/zephyr/posix/pwd.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
192
```objective-c /* $NetBSD: fnmatch.h,v 1.12.50.1 2011/02/08 16:18:55 bouyer Exp $ */ /*- * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)fnmatch.h 8.1 (Berkeley) 6/2/93 */ #ifndef _FNMATCH_H_ #define _FNMATCH_H_ #define FNM_NOMATCH 1 /* Match failed. */ #define FNM_NOSYS 2 /* Function not implemented. */ #define FNM_NORES 3 /* Out of resources */ #define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ #define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ #define FNM_PERIOD 0x04 /* Period must be matched by period. */ #define FNM_CASEFOLD 0x08 /* Pattern is matched case-insensitive */ #define FNM_LEADING_DIR 0x10 /* Ignore /<tail> after Imatch. */ #ifdef __cplusplus extern "C" { #endif int fnmatch(const char *, const char *, int); #ifdef __cplusplus } #endif #endif /* !_FNMATCH_H_ */ ```
/content/code_sandbox/include/zephyr/posix/fnmatch.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
568
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_UNISTD_H_ #define ZEPHYR_INCLUDE_POSIX_UNISTD_H_ #include "posix_types.h" #ifdef CONFIG_POSIX_API #include <zephyr/fs/fs.h> #endif #ifdef CONFIG_NETWORKING /* For zsock_gethostname() */ #include <zephyr/net/socket.h> #include <zephyr/net/hostname.h> #endif #include <zephyr/posix/sys/confstr.h> #include <zephyr/posix/sys/stat.h> #include <zephyr/posix/sys/sysconf.h> #include "posix_features.h" #ifdef __cplusplus extern "C" { #endif #ifdef CONFIG_POSIX_API /* File related operations */ int close(int file); ssize_t write(int file, const void *buffer, size_t count); ssize_t read(int file, void *buffer, size_t count); off_t lseek(int file, off_t offset, int whence); int fsync(int fd); int ftruncate(int fd, off_t length); #ifdef CONFIG_POSIX_SYNCHRONIZED_IO int fdatasync(int fd); #endif /* CONFIG_POSIX_SYNCHRONIZED_IO */ /* File System related operations */ int rename(const char *old, const char *newp); int unlink(const char *path); int stat(const char *path, struct stat *buf); int mkdir(const char *path, mode_t mode); FUNC_NORETURN void _exit(int status); #ifdef CONFIG_NETWORKING static inline int gethostname(char *buf, size_t len) { return zsock_gethostname(buf, len); } #endif /* CONFIG_NETWORKING */ #endif /* CONFIG_POSIX_API */ #ifdef CONFIG_POSIX_C_LIB_EXT int getopt(int argc, char *const argv[], const char *optstring); extern char *optarg; extern int opterr, optind, optopt; #endif int getentropy(void *buffer, size_t length); pid_t getpid(void); unsigned sleep(unsigned int seconds); int usleep(useconds_t useconds); #if _POSIX_C_SOURCE >= 2 size_t confstr(int name, char *buf, size_t len); #endif #ifdef CONFIG_POSIX_SYSCONF_IMPL_MACRO #define sysconf(x) (long)CONCAT(__z_posix_sysconf, x) #else long sysconf(int opt); #endif /* CONFIG_POSIX_SYSCONF_IMPL_FULL */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_UNISTD_H_ */ ```
/content/code_sandbox/include/zephyr/posix/unistd.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
516
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_MESSAGE_PASSING_H_ #define ZEPHYR_INCLUDE_POSIX_MESSAGE_PASSING_H_ #include <zephyr/kernel.h> #include <zephyr/posix/time.h> #include <zephyr/posix/fcntl.h> #include <zephyr/posix/signal.h> #include <zephyr/posix/sys/stat.h> #include "posix_types.h" #ifdef __cplusplus extern "C" { #endif typedef void *mqd_t; struct mq_attr { long mq_flags; long mq_maxmsg; long mq_msgsize; long mq_curmsgs; /* Number of messages currently queued. */ }; mqd_t mq_open(const char *name, int oflags, ...); int mq_close(mqd_t mqdes); int mq_unlink(const char *name); int mq_getattr(mqd_t mqdes, struct mq_attr *mqstat); int mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned int *msg_prio); int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned int msg_prio); int mq_setattr(mqd_t mqdes, const struct mq_attr *mqstat, struct mq_attr *omqstat); int mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned int *msg_prio, const struct timespec *abstime); int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned int msg_prio, const struct timespec *abstime); int mq_notify(mqd_t mqdes, const struct sigevent *notification); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_MESSAGE_PASSING_H_ */ ```
/content/code_sandbox/include/zephyr/posix/mqueue.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
381
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_SIGNAL_H_ #define ZEPHYR_INCLUDE_POSIX_SIGNAL_H_ #include "posix_types.h" #include "posix_features.h" #ifdef __cplusplus extern "C" { #endif #define SIGHUP 1 /**< Hangup */ #define SIGINT 2 /**< Interrupt */ #define SIGQUIT 3 /**< Quit */ #define SIGILL 4 /**< Illegal instruction */ #define SIGTRAP 5 /**< Trace/breakpoint trap */ #define SIGABRT 6 /**< Aborted */ #define SIGBUS 7 /**< Bus error */ #define SIGFPE 8 /**< Arithmetic exception */ #define SIGKILL 9 /**< Killed */ #define SIGUSR1 10 /**< User-defined signal 1 */ #define SIGSEGV 11 /**< Invalid memory reference */ #define SIGUSR2 12 /**< User-defined signal 2 */ #define SIGPIPE 13 /**< Broken pipe */ #define SIGALRM 14 /**< Alarm clock */ #define SIGTERM 15 /**< Terminated */ /* 16 not used */ #define SIGCHLD 17 /**< Child status changed */ #define SIGCONT 18 /**< Continued */ #define SIGSTOP 19 /**< Stop executing */ #define SIGTSTP 20 /**< Stopped */ #define SIGTTIN 21 /**< Stopped (read) */ #define SIGTTOU 22 /**< Stopped (write) */ #define SIGURG 23 /**< Urgent I/O condition */ #define SIGXCPU 24 /**< CPU time limit exceeded */ #define SIGXFSZ 25 /**< File size limit exceeded */ #define SIGVTALRM 26 /**< Virtual timer expired */ #define SIGPROF 27 /**< Profiling timer expired */ /* 28 not used */ #define SIGPOLL 29 /**< Pollable event occurred */ /* 30 not used */ #define SIGSYS 31 /**< Bad system call */ #define SIGRTMIN 32 #define SIGRTMAX (SIGRTMIN + RTSIG_MAX) #define _NSIG (SIGRTMAX + 1) BUILD_ASSERT(RTSIG_MAX >= 0); typedef struct { unsigned long sig[DIV_ROUND_UP(_NSIG, BITS_PER_LONG)]; } sigset_t; #ifndef SIGEV_NONE #define SIGEV_NONE 1 #endif #ifndef SIGEV_SIGNAL #define SIGEV_SIGNAL 2 #endif #ifndef SIGEV_THREAD #define SIGEV_THREAD 3 #endif #ifndef SIG_BLOCK #define SIG_BLOCK 0 #endif #ifndef SIG_SETMASK #define SIG_SETMASK 1 #endif #ifndef SIG_UNBLOCK #define SIG_UNBLOCK 2 #endif typedef int sig_atomic_t; /* Atomic entity type (ANSI) */ union sigval { void *sival_ptr; int sival_int; }; struct sigevent { void (*sigev_notify_function)(union sigval val); pthread_attr_t *sigev_notify_attributes; union sigval sigev_value; int sigev_notify; int sigev_signo; }; char *strsignal(int signum); int sigemptyset(sigset_t *set); int sigfillset(sigset_t *set); int sigaddset(sigset_t *set, int signo); int sigdelset(sigset_t *set, int signo); int sigismember(const sigset_t *set, int signo); int sigprocmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset); int pthread_sigmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_SIGNAL_H_ */ ```
/content/code_sandbox/include/zephyr/posix/signal.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
774
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_DIRENT_H_ #define ZEPHYR_INCLUDE_POSIX_DIRENT_H_ #include <limits.h> #include "posix_types.h" #ifdef CONFIG_POSIX_FILE_SYSTEM #include <zephyr/fs/fs.h> #ifdef __cplusplus extern "C" { #endif typedef void DIR; struct dirent { unsigned int d_ino; char d_name[PATH_MAX + 1]; }; /* Directory related operations */ DIR *opendir(const char *dirname); int closedir(DIR *dirp); struct dirent *readdir(DIR *dirp); int readdir_r(DIR *ZRESTRICT dirp, struct dirent *ZRESTRICT entry, struct dirent **ZRESTRICT result); #ifdef __cplusplus } #endif #endif /* CONFIG_POSIX_FILE_SYSTEM */ #endif /* ZEPHYR_INCLUDE_POSIX_DIRENT_H_ */ ```
/content/code_sandbox/include/zephyr/posix/dirent.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
183
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_ZEPHYR_POSIX_AIO_H_ #define ZEPHYR_INCLUDE_ZEPHYR_POSIX_AIO_H_ #include <signal.h> #include <sys/types.h> #include <time.h> #ifdef __cplusplus extern "C" { #endif struct aiocb { int aio_fildes; off_t aio_offset; volatile void *aio_buf; size_t aio_nbytes; int aio_reqprio; struct sigevent aio_sigevent; int aio_lio_opcode; }; #if _POSIX_C_SOURCE >= 200112L int aio_cancel(int fildes, struct aiocb *aiocbp); int aio_error(const struct aiocb *aiocbp); int aio_fsync(int filedes, struct aiocb *aiocbp); int aio_read(struct aiocb *aiocbp); ssize_t aio_return(struct aiocb *aiocbp); int aio_suspend(const struct aiocb *const list[], int nent, const struct timespec *timeout); int aio_write(struct aiocb *aiocbp); int lio_listio(int mode, struct aiocb *const ZRESTRICT list[], int nent, struct sigevent *ZRESTRICT sig); #endif /* _POSIX_C_SOURCE >= 200112L */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_ZEPHYR_POSIX_AIO_H_ */ ```
/content/code_sandbox/include/zephyr/posix/aio.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
302
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_PTHREAD_H_ #define ZEPHYR_INCLUDE_POSIX_PTHREAD_H_ #include <stdlib.h> #include <string.h> #include <zephyr/kernel.h> #include <zephyr/posix/time.h> #include <zephyr/posix/unistd.h> #include <zephyr/posix/sched.h> #ifdef __cplusplus extern "C" { #endif /* * Pthread detach/joinable * Undefine possibly predefined values by external toolchain headers */ #undef PTHREAD_CREATE_DETACHED #define PTHREAD_CREATE_DETACHED 1 #undef PTHREAD_CREATE_JOINABLE #define PTHREAD_CREATE_JOINABLE 0 /* Pthread resource visibility */ #define PTHREAD_PROCESS_PRIVATE 0 #define PTHREAD_PROCESS_SHARED 1 /* Pthread cancellation */ #define PTHREAD_CANCELED ((void *)-1) #define PTHREAD_CANCEL_ENABLE 0 #define PTHREAD_CANCEL_DISABLE 1 #define PTHREAD_CANCEL_DEFERRED 0 #define PTHREAD_CANCEL_ASYNCHRONOUS 1 /* Pthread scope */ #undef PTHREAD_SCOPE_PROCESS #define PTHREAD_SCOPE_PROCESS 1 #undef PTHREAD_SCOPE_SYSTEM #define PTHREAD_SCOPE_SYSTEM 0 /* Pthread inherit scheduler */ #undef PTHREAD_INHERIT_SCHED #define PTHREAD_INHERIT_SCHED 0 #undef PTHREAD_EXPLICIT_SCHED #define PTHREAD_EXPLICIT_SCHED 1 /* Passed to pthread_once */ #define PTHREAD_ONCE_INIT {0} /* The minimum allowable stack size */ #define PTHREAD_STACK_MIN K_KERNEL_STACK_LEN(0) /** * @brief Declare a condition variable as initialized * * Initialize a condition variable with the default condition variable attributes. */ #define PTHREAD_COND_INITIALIZER (-1) /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_cond_init(pthread_cond_t *cv, const pthread_condattr_t *att); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_cond_destroy(pthread_cond_t *cv); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_cond_signal(pthread_cond_t *cv); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_cond_broadcast(pthread_cond_t *cv); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mut); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mut, const struct timespec *abstime); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1. * */ int pthread_condattr_init(pthread_condattr_t *att); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 * */ int pthread_condattr_destroy(pthread_condattr_t *att); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 * */ int pthread_condattr_getclock(const pthread_condattr_t *ZRESTRICT att, clockid_t *ZRESTRICT clock_id); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 * */ int pthread_condattr_setclock(pthread_condattr_t *att, clockid_t clock_id); /** * @brief Declare a mutex as initialized * * Initialize a mutex with the default mutex attributes. */ #define PTHREAD_MUTEX_INITIALIZER (-1) /** * @brief Declare a rwlock as initialized * * Initialize a rwlock with the default rwlock attributes. */ #define PTHREAD_RWLOCK_INITIALIZER (-1) /* * Mutex attributes - type * * PTHREAD_MUTEX_NORMAL: Owner of mutex cannot relock it. Attempting * to relock will cause deadlock. * PTHREAD_MUTEX_RECURSIVE: Owner can relock the mutex. * PTHREAD_MUTEX_ERRORCHECK: If owner attempts to relock the mutex, an * error is returned. * */ #define PTHREAD_MUTEX_NORMAL 0 #define PTHREAD_MUTEX_RECURSIVE 1 #define PTHREAD_MUTEX_ERRORCHECK 2 #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL /* * Mutex attributes - protocol * * PTHREAD_PRIO_NONE: Ownership of mutex does not affect priority. * PTHREAD_PRIO_INHERIT: Owner's priority is boosted to the priority of * highest priority thread blocked on the mutex. * PTHREAD_PRIO_PROTECT: Mutex has a priority ceiling. The owner's * priority is boosted to the highest priority ceiling of all mutexes * owned (regardless of whether or not other threads are blocked on * any of these mutexes). * FIXME: Only PRIO_NONE is supported. Implement other protocols. */ #define PTHREAD_PRIO_NONE 0 #define PTHREAD_PRIO_INHERIT 1 #define PTHREAD_PRIO_PROTECT 2 /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_mutex_destroy(pthread_mutex_t *m); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_mutex_lock(pthread_mutex_t *m); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_mutex_unlock(pthread_mutex_t *m); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *abstime); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_mutex_trylock(pthread_mutex_t *m); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *att); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *protocol); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 * * Note that pthread attribute structs are currently noops in Zephyr. */ int pthread_mutexattr_init(pthread_mutexattr_t *attr); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 * * Note that pthread attribute structs are currently noops in Zephyr. */ int pthread_mutexattr_destroy(pthread_mutexattr_t *attr); #define PTHREAD_BARRIER_SERIAL_THREAD 1 /* * Barrier attributes - type */ #define PTHREAD_PROCESS_PRIVATE 0 #define PTHREAD_PROCESS_PUBLIC 1 /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_barrier_wait(pthread_barrier_t *b); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_barrier_init(pthread_barrier_t *b, const pthread_barrierattr_t *attr, unsigned int count); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_barrier_destroy(pthread_barrier_t *b); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_barrierattr_init(pthread_barrierattr_t *b); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_barrierattr_destroy(pthread_barrierattr_t *b); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared); /** * @brief POSIX threading compatibility API * * See IEEE 1003.1 */ int pthread_barrierattr_getpshared(const pthread_barrierattr_t *ZRESTRICT attr, int *ZRESTRICT pshared); /* Predicates and setters for various pthread attribute values that we * don't support (or always support: the "process shared" attribute * can only be true given the way Zephyr implements these * objects). Leave these undefined for simplicity instead of defining * stubs to return an error that would have to be logged and * interpreted just to figure out that we didn't support it in the * first place. These APIs are very rarely used even in production * Unix code. Leave the declarations here so they can be easily * uncommented and implemented as needed. int pthread_condattr_getpshared(const pthread_condattr_t * int *); int pthread_condattr_setpshared(pthread_condattr_t *, int); int pthread_mutex_consistent(pthread_mutex_t *); int pthread_mutexattr_getpshared(const pthread_mutexattr_t * int *); int pthread_mutexattr_getrobust(const pthread_mutexattr_t * int *); int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int); int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int); */ #ifdef CONFIG_POSIX_THREAD_PRIO_PROTECT int pthread_mutex_getprioceiling(const pthread_mutex_t *ZRESTRICT mutex, int *ZRESTRICT prioceiling); int pthread_mutex_setprioceiling(pthread_mutex_t *ZRESTRICT mutex, int prioceiling, int *ZRESTRICT old_ceiling); int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *ZRESTRICT attr, int *ZRESTRICT prioceiling); int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, int prioceiling); #endif /* CONFIG_POSIX_THREAD_PRIO_PROTECT */ /* Base Pthread related APIs */ /** * @brief Obtain ID of the calling thread. * * The results of calling this API from threads not created with * pthread_create() are undefined. * * See IEEE 1003.1 */ pthread_t pthread_self(void); /** * @brief Compare thread IDs. * * See IEEE 1003.1 */ int pthread_equal(pthread_t pt1, pthread_t pt2); /** * @brief Destroy the read-write lock attributes object. * * See IEEE 1003.1 */ int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr); /** * @brief initialize the read-write lock attributes object. * * See IEEE 1003.1 */ int pthread_rwlockattr_init(pthread_rwlockattr_t *attr); int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *ZRESTRICT attr, int *ZRESTRICT pshared); int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared); int pthread_attr_getguardsize(const pthread_attr_t *ZRESTRICT attr, size_t *ZRESTRICT guardsize); int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize); int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize); int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize); int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy); int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy); int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate); int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate); int pthread_attr_init(pthread_attr_t *attr); int pthread_attr_destroy(pthread_attr_t *attr); int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *schedparam); int pthread_getschedparam(pthread_t pthread, int *policy, struct sched_param *param); int pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t *stacksize); int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize); int pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope); int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope); int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched); int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched); #ifdef CONFIG_POSIX_THREADS int pthread_once(pthread_once_t *once, void (*initFunc)(void)); #endif FUNC_NORETURN void pthread_exit(void *retval); int pthread_join(pthread_t thread, void **status); int pthread_cancel(pthread_t pthread); int pthread_detach(pthread_t thread); int pthread_create(pthread_t *newthread, const pthread_attr_t *attr, void *(*threadroutine)(void *), void *arg); int pthread_setcancelstate(int state, int *oldstate); int pthread_setcanceltype(int type, int *oldtype); void pthread_testcancel(void); int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *schedparam); int pthread_setschedparam(pthread_t pthread, int policy, const struct sched_param *param); int pthread_setschedprio(pthread_t thread, int prio); int pthread_rwlock_destroy(pthread_rwlock_t *rwlock); int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr); int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abstime); int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abstime); int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock); int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock); int pthread_rwlock_unlock(pthread_rwlock_t *rwlock); int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); int pthread_key_create(pthread_key_t *key, void (*destructor)(void *)); int pthread_key_delete(pthread_key_t key); int pthread_setspecific(pthread_key_t key, const void *value); void *pthread_getspecific(pthread_key_t key); int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)); int pthread_getconcurrency(void); int pthread_setconcurrency(int new_level); void __z_pthread_cleanup_push(void *cleanup[3], void (*routine)(void *arg), void *arg); void __z_pthread_cleanup_pop(int execute); #define pthread_cleanup_push(_rtn, _arg) \ do /* enforce '{'-like behaviour */ { \ void *_z_pthread_cleanup[3]; \ __z_pthread_cleanup_push(_z_pthread_cleanup, _rtn, _arg) #define pthread_cleanup_pop(_ex) \ __z_pthread_cleanup_pop(_ex); \ } /* enforce '}'-like behaviour */ while (0) /* Glibc / Oracle Extension Functions */ /** * @brief Set name of POSIX thread. * * Non-portable, extension function that conforms with most * other definitions of this function. * * @param thread POSIX thread to set name * @param name Name string * @retval 0 Success * @retval ESRCH Thread does not exist * @retval EINVAL Name buffer is NULL * @retval Negative value if kernel function error * */ int pthread_setname_np(pthread_t thread, const char *name); /** * @brief Get name of POSIX thread and store in name buffer * that is of size len. * * Non-portable, extension function that conforms with most * other definitions of this function. * * @param thread POSIX thread to obtain name information * @param name Destination buffer * @param len Destination buffer size * @retval 0 Success * @retval ESRCH Thread does not exist * @retval EINVAL Name buffer is NULL * @retval Negative value if kernel function error */ int pthread_getname_np(pthread_t thread, char *name, size_t len); #ifdef CONFIG_POSIX_THREADS /** * @brief Destroy a pthread_spinlock_t. * * See IEEE 1003.1 */ int pthread_spin_destroy(pthread_spinlock_t *lock); /** * @brief Initialize a thread_spinlock_t. * * See IEEE 1003.1 */ int pthread_spin_init(pthread_spinlock_t *lock, int pshared); /** * @brief Lock a previously initialized thread_spinlock_t. * * See IEEE 1003.1 */ int pthread_spin_lock(pthread_spinlock_t *lock); /** * @brief Attempt to lock a previously initialized thread_spinlock_t. * * See IEEE 1003.1 */ int pthread_spin_trylock(pthread_spinlock_t *lock); /** * @brief Unlock a previously locked thread_spinlock_t. * * See IEEE 1003.1 */ int pthread_spin_unlock(pthread_spinlock_t *lock); #endif #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_PTHREAD_H_ */ ```
/content/code_sandbox/include/zephyr/posix/pthread.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
3,658
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_TYPES_H_ #define ZEPHYR_INCLUDE_POSIX_TYPES_H_ #if !(defined(CONFIG_ARCH_POSIX) && defined(CONFIG_EXTERNAL_LIBC)) #include <sys/types.h> #endif #ifdef CONFIG_NEWLIB_LIBC #include <sys/_pthreadtypes.h> #endif #include <zephyr/kernel.h> #ifdef __cplusplus extern "C" { #endif #if !defined(_DEV_T_DECLARED) && !defined(__dev_t_defined) typedef int dev_t; #define _DEV_T_DECLARED #define __dev_t_defined #endif #if !defined(_INO_T_DECLARED) && !defined(__ino_t_defined) typedef int ino_t; #define _INO_T_DECLARED #define __ino_t_defined #endif #if !defined(_NLINK_T_DECLARED) && !defined(__nlink_t_defined) typedef unsigned short nlink_t; #define _NLINK_T_DECLARED #define __nlink_t_defined #endif #if !defined(_UID_T_DECLARED) && !defined(__uid_t_defined) typedef unsigned short uid_t; #define _UID_T_DECLARED #define __uid_t_defined #endif #if !defined(_GID_T_DECLARED) && !defined(__gid_t_defined) typedef unsigned short gid_t; #define _GID_T_DECLARED #define __gid_t_defined #endif #if !defined(_BLKSIZE_T_DECLARED) && !defined(__blksize_t_defined) typedef unsigned long blksize_t; #define _BLKSIZE_T_DECLARED #define __blksize_t_defined #endif #if !defined(_BLKCNT_T_DECLARED) && !defined(__blkcnt_t_defined) typedef unsigned long blkcnt_t; #define _BLKCNT_T_DECLARED #define __blkcnt_t_defined #endif #if !defined(CONFIG_ARCMWDT_LIBC) typedef int pid_t; #endif #ifndef __useconds_t_defined typedef unsigned long useconds_t; #endif /* time related attributes */ #if !defined(CONFIG_NEWLIB_LIBC) && !defined(CONFIG_ARCMWDT_LIBC) #ifndef __clockid_t_defined typedef uint32_t clockid_t; #endif #endif /* !CONFIG_NEWLIB_LIBC && !CONFIG_ARCMWDT_LIBC */ #ifndef __timer_t_defined typedef unsigned long timer_t; #endif /* Thread attributes */ struct pthread_attr { void *stack; uint32_t details[2]; }; #if !defined(CONFIG_NEWLIB_LIBC) typedef struct pthread_attr pthread_attr_t; BUILD_ASSERT(sizeof(pthread_attr_t) >= sizeof(struct pthread_attr)); #endif typedef uint32_t pthread_t; typedef uint32_t pthread_spinlock_t; /* Semaphore */ typedef struct k_sem sem_t; /* Mutex */ typedef uint32_t pthread_mutex_t; struct pthread_mutexattr { unsigned char type: 2; bool initialized: 1; }; #if !defined(CONFIG_NEWLIB_LIBC) typedef struct pthread_mutexattr pthread_mutexattr_t; BUILD_ASSERT(sizeof(pthread_mutexattr_t) >= sizeof(struct pthread_mutexattr)); #endif /* Condition variables */ typedef uint32_t pthread_cond_t; struct pthread_condattr { clockid_t clock; }; #if !defined(CONFIG_NEWLIB_LIBC) typedef struct pthread_condattr pthread_condattr_t; BUILD_ASSERT(sizeof(pthread_condattr_t) >= sizeof(struct pthread_condattr)); #endif /* Barrier */ typedef uint32_t pthread_barrier_t; typedef struct pthread_barrierattr { int pshared; } pthread_barrierattr_t; typedef uint32_t pthread_rwlockattr_t; typedef uint32_t pthread_rwlock_t; struct pthread_once { bool flag; }; #if !defined(CONFIG_NEWLIB_LIBC) typedef uint32_t pthread_key_t; typedef struct pthread_once pthread_once_t; /* Newlib typedefs pthread_once_t as a struct with two ints */ BUILD_ASSERT(sizeof(pthread_once_t) >= sizeof(struct pthread_once)); #endif #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_TYPES_H_ */ ```
/content/code_sandbox/include/zephyr/posix/posix_types.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
810
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_POLL_H_ #define ZEPHYR_INCLUDE_POSIX_POLL_H_ #include <zephyr/net/socket.h> #ifdef __cplusplus extern "C" { #endif #define pollfd zsock_pollfd #define POLLIN ZSOCK_POLLIN #define POLLOUT ZSOCK_POLLOUT #define POLLERR ZSOCK_POLLERR #define POLLHUP ZSOCK_POLLHUP #define POLLNVAL ZSOCK_POLLNVAL int poll(struct pollfd *fds, int nfds, int timeout); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_POLL_H_ */ ```
/content/code_sandbox/include/zephyr/posix/poll.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
141
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_GRP_H_ #define ZEPHYR_INCLUDE_POSIX_GRP_H_ #ifdef __cplusplus extern "C" { #endif #include <zephyr/posix/sys/stat.h> /** * @brief Group structure */ struct group { /**< the name of the group */ char *gr_name; /**< numerical group ID */ gid_t gr_gid; /**< pointer to a null-terminated array of character pointers to member names */ char **gr_mem; }; int getgrnam_r(const char *name, struct group *grp, char *buffer, size_t bufsize, struct group **result); int getgrgid_r(gid_t gid, struct group *grp, char *buffer, size_t bufsize, struct group **result); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_GRP_H_ */ ```
/content/code_sandbox/include/zephyr/posix/grp.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
183
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_SCHED_H_ #define ZEPHYR_INCLUDE_POSIX_SCHED_H_ #include <zephyr/kernel.h> #include "posix_types.h" #include <time.h> #ifdef __cplusplus extern "C" { #endif /* * Other mandatory scheduling policy. Must be numerically distinct. May * execute identically to SCHED_RR or SCHED_FIFO. For Zephyr this is a * pseudonym for SCHED_RR. */ #define SCHED_OTHER 0 /* Cooperative scheduling policy */ #define SCHED_FIFO 1 /* Priority based preemptive scheduling policy */ #define SCHED_RR 2 #if defined(CONFIG_MINIMAL_LIBC) || defined(CONFIG_PICOLIBC) || defined(CONFIG_ARMCLANG_STD_LIBC) \ || defined(CONFIG_ARCMWDT_LIBC) struct sched_param { int sched_priority; }; #endif /** * @brief Yield the processor * * See IEEE 1003.1 */ static inline int sched_yield(void) { k_yield(); return 0; } int sched_get_priority_min(int policy); int sched_get_priority_max(int policy); int sched_getparam(pid_t pid, struct sched_param *param); int sched_getscheduler(pid_t pid); int sched_setparam(pid_t pid, const struct sched_param *param); int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param); int sched_rr_get_interval(pid_t pid, struct timespec *interval); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_SCHED_H_ */ ```
/content/code_sandbox/include/zephyr/posix/sched.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
327
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_SEMAPHORE_H_ #define ZEPHYR_INCLUDE_POSIX_SEMAPHORE_H_ #include <zephyr/posix/time.h> #include "posix_types.h" #ifdef __cplusplus extern "C" { #endif #define SEM_FAILED ((sem_t *) 0) int sem_destroy(sem_t *semaphore); int sem_getvalue(sem_t *ZRESTRICT semaphore, int *ZRESTRICT value); int sem_init(sem_t *semaphore, int pshared, unsigned int value); int sem_post(sem_t *semaphore); int sem_timedwait(sem_t *ZRESTRICT semaphore, struct timespec *ZRESTRICT abstime); int sem_trywait(sem_t *semaphore); int sem_wait(sem_t *semaphore); sem_t *sem_open(const char *name, int oflags, ...); int sem_unlink(const char *name); int sem_close(sem_t *sem); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_SEMAPHORE_H_ */ ```
/content/code_sandbox/include/zephyr/posix/semaphore.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
220
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_NETDB_H_ #define ZEPHYR_INCLUDE_POSIX_NETDB_H_ #include <zephyr/net/socket.h> #ifndef NI_MAXSERV /** Provide a reasonable size for apps using getnameinfo */ #define NI_MAXSERV 32 #endif #define EAI_BADFLAGS DNS_EAI_BADFLAGS #define EAI_NONAME DNS_EAI_NONAME #define EAI_AGAIN DNS_EAI_AGAIN #define EAI_FAIL DNS_EAI_FAIL #define EAI_NODATA DNS_EAI_NODATA #define EAI_MEMORY DNS_EAI_MEMORY #define EAI_SYSTEM DNS_EAI_SYSTEM #define EAI_SERVICE DNS_EAI_SERVICE #define EAI_SOCKTYPE DNS_EAI_SOCKTYPE #define EAI_FAMILY DNS_EAI_FAMILY #define EAI_OVERFLOW DNS_EAI_OVERFLOW #ifdef __cplusplus extern "C" { #endif struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }; struct netent { char *n_name; char **n_aliases; int n_addrtype; uint32_t n_net; }; struct protoent { char *p_name; char **p_aliases; int p_proto; }; struct servent { char *s_name; char **s_aliases; int s_port; char *s_proto; }; #define addrinfo zsock_addrinfo void endhostent(void); void endnetent(void); void endprotoent(void); void endservent(void); void freeaddrinfo(struct zsock_addrinfo *ai); const char *gai_strerror(int errcode); int getaddrinfo(const char *host, const char *service, const struct zsock_addrinfo *hints, struct zsock_addrinfo **res); struct hostent *gethostent(void); int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags); struct netent *getnetbyaddr(uint32_t net, int type); struct netent *getnetbyname(const char *name); struct netent *getnetent(void); struct protoent *getprotobyname(const char *name); struct protoent *getprotobynumber(int proto); struct protoent *getprotoent(void); struct servent *getservbyname(const char *name, const char *proto); struct servent *getservbyport(int port, const char *proto); struct servent *getservent(void); void sethostent(int stayopen); void setnetent(int stayopen); void setprotoent(int stayopen); void setservent(int stayopen); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_NETDB_H_ */ ```
/content/code_sandbox/include/zephyr/posix/netdb.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
590
```objective-c /* * */ #ifndef INCLUDE_ZEPHYR_POSIX_POSIX_FEATURES_H_ #define INCLUDE_ZEPHYR_POSIX_POSIX_FEATURES_H_ #include <zephyr/autoconf.h> /* CONFIG_* */ #include <zephyr/sys/util_macro.h> /* COND_CODE_1() */ /* * POSIX Application Environment Profiles (AEP - IEEE Std 1003.13-2003) */ #ifdef CONFIG_POSIX_AEP_REALTIME_MINIMAL #define _POSIX_AEP_REALTIME_MINIMAL 200312L #endif #ifdef CONFIG_POSIX_AEP_REALTIME_CONTROLLER #define _POSIX_AEP_REALTIME_CONTROLLER 200312L #endif #ifdef CONFIG_POSIX_AEP_REALTIME_DEDICATED #define _POSIX_AEP_REALTIME_DEDICATED 200312L #endif /* * POSIX System Interfaces */ #define _POSIX_VERSION 200809L #define _POSIX_CHOWN_RESTRICTED (0) #define _POSIX_NO_TRUNC (0) #define _POSIX_VDISABLE ('\0') /* #define _POSIX_ADVISORY_INFO (-1L) */ #ifdef CONFIG_POSIX_ASYNCHRONOUS_IO #define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION #endif #ifdef CONFIG_POSIX_BARRIERS #define _POSIX_BARRIERS _POSIX_VERSION #endif #ifdef CONFIG_POSIX_CLOCK_SELECTION #define _POSIX_CLOCK_SELECTION _POSIX_VERSION #endif #ifdef CONFIG_POSIX_CPUTIME #define _POSIX_CPUTIME _POSIX_VERSION #endif #ifdef CONFIG_POSIX_FSYNC #define _POSIX_FSYNC _POSIX_VERSION #endif #ifdef CONFIG_NET_IPV6 #define _POSIX_IPV6 _POSIX_VERSION #endif /* #define _POSIX_JOB_CONTROL (-1L) */ #ifdef CONFIG_POSIX_MAPPED_FILES #define _POSIX_MAPPED_FILES _POSIX_VERSION #endif #ifdef CONFIG_POSIX_MEMLOCK #define _POSIX_MEMLOCK _POSIX_VERSION #endif #ifdef CONFIG_POSIX_MEMLOCK_RANGE #define _POSIX_MEMLOCK_RANGE _POSIX_VERSION #endif #ifdef CONFIG_POSIX_MEMORY_PROTECTION #define _POSIX_MEMORY_PROTECTION _POSIX_VERSION #endif #ifdef CONFIG_POSIX_MESSAGE_PASSING #define _POSIX_MESSAGE_PASSING _POSIX_VERSION #endif #ifdef CONFIG_POSIX_MONOTONIC_CLOCK #define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION #endif /* #define _POSIX_PRIORITIZED_IO (-1L) */ #ifdef CONFIG_POSIX_PRIORITY_SCHEDULING #define _POSIX_PRIORITY_SCHEDULING _POSIX_VERSION #endif #ifdef CONFIG_NET_SOCKETS_PACKET #define _POSIX_RAW_SOCKETS _POSIX_VERSION #endif #ifdef CONFIG_POSIX_READER_WRITER_LOCKS #define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION #endif /* #define _POSIX_REALTIME_SIGNALS (-1L) */ /* #define _POSIX_REGEXP (-1L) */ /* #define _POSIX_SAVED_IDS (-1L) */ #ifdef CONFIG_POSIX_SEMAPHORES #define _POSIX_SEMAPHORES _POSIX_VERSION #endif #ifdef CONFIG_POSIX_SHARED_MEMORY_OBJECTS #define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION #endif /* #define _POSIX_SHELL (-1L) */ /* #define _POSIX_SPAWN (-1L) */ #ifdef CONFIG_POSIX_SPIN_LOCKS #define _POSIX_SPIN_LOCKS _POSIX_VERSION #endif /* #define _POSIX_SPORADIC_SERVER (-1L) */ #ifdef CONFIG_POSIX_SYNCHRONIZED_IO #define _POSIX_SYNCHRONIZED_IO _POSIX_VERSION #endif #ifdef CONFIG_POSIX_THREAD_ATTR_STACKADDR #define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION #endif #ifdef CONFIG_POSIX_THREAD_ATTR_STACKSIZE #define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION #endif #ifdef CONFIG_POSIX_THREAD_CPUTIME #define _POSIX_THREAD_CPUTIME _POSIX_VERSION #endif #ifdef CONFIG_POSIX_THREAD_PRIO_INHERIT #define _POSIX_THREAD_PRIO_INHERIT _POSIX_VERSION #endif #ifdef CONFIG_POSIX_THREAD_PRIO_PROTECT #define _POSIX_THREAD_PRIO_PROTECT _POSIX_VERSION #endif #ifdef CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING #define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION #endif /* #define _POSIX_THREAD_PROCESS_SHARED (-1L) */ /* #define _POSIX_THREAD_ROBUST_PRIO_INHERIT (-1L) */ /* #define _POSIX_THREAD_ROBUST_PRIO_PROTECT (-1L) */ #ifdef CONFIG_POSIX_THREAD_SAFE_FUNCTIONS #define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION #endif /* #define _POSIX_THREAD_SPORADIC_SERVER (-1L) */ #ifdef CONFIG_POSIX_THREADS #ifndef _POSIX_THREADS #define _POSIX_THREADS _POSIX_VERSION #endif #endif #ifdef CONFIG_POSIX_TIMEOUTS #define _POSIX_TIMEOUTS _POSIX_VERSION #endif #ifdef CONFIG_POSIX_TIMERS #define _POSIX_TIMERS _POSIX_VERSION #endif /* #define _POSIX_TRACE (-1L) */ /* #define _POSIX_TRACE_EVENT_FILTER (-1L) */ /* #define _POSIX_TRACE_INHERIT (-1L) */ /* #define _POSIX_TRACE_LOG (-1L) */ /* #define _POSIX_TYPED_MEMORY_OBJECTS (-1L) */ /* * POSIX v6 Options */ /* #define _POSIX_V6_ILP32_OFF32 (-1L) */ /* #define _POSIX_V6_ILP32_OFFBIG (-1L) */ /* #define _POSIX_V6_LP64_OFF64 (-1L) */ /* #define _POSIX_V6_LPBIG_OFFBIG (-1L) */ /* * POSIX v7 Options */ /* #define _POSIX_V7_ILP32_OFF32 (-1L) */ /* #define _POSIX_V7_ILP32_OFFBIG (-1L) */ /* #define _POSIX_V7_LP64_OFF64 (-1L) */ /* #define _POSIX_V7_LPBIG_OFFBIG (-1L) */ /* * POSIX2 Options */ #define _POSIX2_VERSION _POSIX_VERSION #define _POSIX2_C_BIND _POSIX2_VERSION #define _POSIX2_C_DEV _POSIX2_VERSION /* #define _POSIX2_CHAR_TERM (-1L) */ /* #define _POSIX2_FORT_DEV (-1L) */ /* #define _POSIX2_FORT_RUN (-1L) */ /* #define _POSIX2_LOCALEDEF (-1L) */ /* #define _POSIX2_PBS (-1L) */ /* #define _POSIX2_PBS_ACCOUNTING (-1L) */ /* #define _POSIX2_PBS_CHECKPOINT (-1L) */ /* #define _POSIX2_PBS_LOCATE (-1L) */ /* #define _POSIX2_PBS_MESSAGE (-1L) */ /* #define _POSIX2_PBS_TRACK (-1L) */ /* #define _POSIX2_SW_DEV (-1L) */ /* #define _POSIX2_UPE (-1L) */ /* * X/Open System Interfaces */ #define _XOPEN_VERSION 700 /* #define _XOPEN_CRYPT (-1L) */ /* #define _XOPEN_ENH_I18N (-1L) */ /* #define _XOPEN_REALTIME (-1L) */ /* #define _XOPEN_REALTIME_THREADS (-1L) */ /* #define _XOPEN_SHM (-1L) */ #ifdef CONFIG_XOPEN_STREAMS #define _XOPEN_STREAMS _XOPEN_VERSION #endif /* #define _XOPEN_UNIX (-1L) */ /* #define _XOPEN_UUCP (-1L) */ /* Maximum values */ #define _POSIX_CLOCKRES_MIN (20000000L) /* Minimum values */ #define _POSIX_AIO_LISTIO_MAX (2) #define _POSIX_AIO_MAX (1) #define _POSIX_ARG_MAX (4096) #define _POSIX_CHILD_MAX (25) #define _POSIX_DELAYTIMER_MAX \ COND_CODE_1(CONFIG_POSIX_TIMERS, (CONFIG_POSIX_DELAYTIMER_MAX), (0)) #define _POSIX_HOST_NAME_MAX \ COND_CODE_1(CONFIG_POSIX_NETWORKING, (CONFIG_POSIX_HOST_NAME_MAX), (0)) #define _POSIX_LINK_MAX (8) #define _POSIX_LOGIN_NAME_MAX (9) #define _POSIX_MAX_CANON (255) #define _POSIX_MAX_INPUT (255) #define _POSIX_MQ_OPEN_MAX \ COND_CODE_1(CONFIG_POSIX_MESSAGE_PASSING, (CONFIG_POSIX_MQ_OPEN_MAX), (0)) #define _POSIX_MQ_PRIO_MAX (32) #define _POSIX_NAME_MAX (14) #define _POSIX_NGROUPS_MAX (8) #define _POSIX_OPEN_MAX CONFIG_POSIX_OPEN_MAX #define _POSIX_PATH_MAX (256) #define _POSIX_PIPE_BUF (512) #define _POSIX_RE_DUP_MAX (255) #define _POSIX_RTSIG_MAX \ COND_CODE_1(CONFIG_POSIX_REALTIME_SIGNALS, (CONFIG_POSIX_RTSIG_MAX), (0)) #define _POSIX_SEM_NSEMS_MAX \ COND_CODE_1(CONFIG_POSIX_SEMAPHORES, (CONFIG_POSIX_SEM_NSEMS_MAX), (0)) #define _POSIX_SEM_VALUE_MAX \ COND_CODE_1(CONFIG_POSIX_SEMAPHORES, (CONFIG_POSIX_SEM_VALUE_MAX), (0)) #define _POSIX_SIGQUEUE_MAX (32) #define _POSIX_SSIZE_MAX (32767) #define _POSIX_SS_REPL_MAX (4) #define _POSIX_STREAM_MAX (8) #define _POSIX_SYMLINK_MAX (255) #define _POSIX_SYMLOOP_MAX (8) #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS (4) #define _POSIX_THREAD_KEYS_MAX \ COND_CODE_1(CONFIG_POSIX_THREADS, (CONFIG_POSIX_THREAD_KEYS_MAX), (0)) #define _POSIX_THREAD_THREADS_MAX \ COND_CODE_1(CONFIG_POSIX_THREADS, (CONFIG_POSIX_THREAD_THREADS_MAX), (0)) #define _POSIX_TIMER_MAX \ COND_CODE_1(CONFIG_POSIX_TIMERS, (CONFIG_POSIX_TIMER_MAX), (0)) #define _POSIX_TRACE_EVENT_NAME_MAX (30) #define _POSIX_TRACE_NAME_MAX (8) #define _POSIX_TRACE_SYS_MAX (8) #define _POSIX_TRACE_USER_EVENT_MAX (32) #define _POSIX_TTY_NAME_MAX (9) #define _POSIX_TZNAME_MAX (6) #define _POSIX2_BC_BASE_MAX (99) #define _POSIX2_BC_DIM_MAX (2048) #define _POSIX2_BC_SCALE_MAX (99) #define _POSIX2_BC_STRING_MAX (1000) #define _POSIX2_CHARCLASS_NAME_MAX (14) #define _POSIX2_COLL_WEIGHTS_MAX (2) #define _POSIX2_EXPR_NEST_MAX (32) #define _POSIX2_LINE_MAX (2048) #define _XOPEN_IOV_MAX (16) #define _XOPEN_NAME_MAX (255) #define _XOPEN_PATH_MAX (1024) /* Other invariant values */ #define NL_LANGMAX (14) #define NL_MSGMAX (32767) #define NL_SETMAX (255) #define NL_TEXTMAX (_POSIX2_LINE_MAX) #define NZERO (20) /* Runtime invariant values */ #define AIO_LISTIO_MAX _POSIX_AIO_LISTIO_MAX #define AIO_MAX _POSIX_AIO_MAX #define AIO_PRIO_DELTA_MAX (0) #define DELAYTIMER_MAX _POSIX_DELAYTIMER_MAX #define HOST_NAME_MAX _POSIX_HOST_NAME_MAX #define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX #define MQ_OPEN_MAX _POSIX_MQ_OPEN_MAX #define MQ_PRIO_MAX _POSIX_MQ_PRIO_MAX #ifndef ATEXIT_MAX #define ATEXIT_MAX 8 #endif #define PAGE_SIZE CONFIG_POSIX_PAGE_SIZE #define PAGESIZE PAGE_SIZE #define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS #define PTHREAD_KEYS_MAX _POSIX_THREAD_KEYS_MAX #define PTHREAD_THREADS_MAX _POSIX_THREAD_THREADS_MAX #define RTSIG_MAX _POSIX_RTSIG_MAX #define SEM_NSEMS_MAX _POSIX_SEM_NSEMS_MAX #define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX #define SIGQUEUE_MAX _POSIX_SIGQUEUE_MAX #define STREAM_MAX _POSIX_STREAM_MAX #define SYMLOOP_MAX _POSIX_SYMLOOP_MAX #define TIMER_MAX _POSIX_TIMER_MAX #define TTY_NAME_MAX _POSIX_TTY_NAME_MAX #define TZNAME_MAX _POSIX_TZNAME_MAX /* Pathname variable values */ #define FILESIZEBITS (32) #define POSIX_ALLOC_SIZE_MIN (256) #define POSIX_REC_INCR_XFER_SIZE (1024) #define POSIX_REC_MAX_XFER_SIZE (32767) #define POSIX_REC_MIN_XFER_SIZE (1) #define POSIX_REC_XFER_ALIGN (4) #define SYMLINK_MAX _POSIX_SYMLINK_MAX #endif /* INCLUDE_ZEPHYR_POSIX_POSIX_FEATURES_H_ */ ```
/content/code_sandbox/include/zephyr/posix/posix_features.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
2,883
```objective-c /* * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef ZEPHYR_POSIX_SYS_STAT_H_ #define ZEPHYR_POSIX_SYS_STAT_H_ #ifdef __cplusplus extern "C" { #endif #include <time.h> #include <sys/cdefs.h> #include <zephyr/posix/posix_types.h> /* dj's stat defines _STAT_H_ */ #ifndef _STAT_H_ /* * It is intended that the layout of this structure not change when the * sizes of any of the basic types change (short, int, long) [via a compile * time option]. */ #ifdef __CYGWIN__ #include <cygwin/stat.h> #ifdef _LIBC #define stat64 stat #endif #else struct stat { dev_t st_dev; ino_t st_ino; mode_t st_mode; nlink_t st_nlink; uid_t st_uid; gid_t st_gid; #if defined(__linux) && defined(__x86_64__) int __pad0; #endif dev_t st_rdev; #if defined(__linux) && !defined(__x86_64__) unsigned short int __pad2; #endif off_t st_size; #if defined(__linux) blksize_t st_blksize; blkcnt_t st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; #define st_atime st_atim.tv_sec /* Backward compatibility */ #define st_mtime st_mtim.tv_sec #define st_ctime st_ctim.tv_sec #if defined(__linux) && defined(__x86_64__) uint64_t __glibc_reserved[3]; #endif #else #if defined(__rtems__) struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; blksize_t st_blksize; blkcnt_t st_blocks; #else /* SysV/sco doesn't have the rest... But Solaris, eabi does. */ #if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__) time_t st_atime; time_t st_mtime; time_t st_ctime; #else struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; blksize_t st_blksize; blkcnt_t st_blocks; #if !defined(__rtems__) long st_spare4[2]; #endif #endif #endif #endif }; #if !(defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)) #define st_atime st_atim.tv_sec #define st_ctime st_ctim.tv_sec #define st_mtime st_mtim.tv_sec #endif #endif #define _IFMT 0170000 /* type of file */ #define _IFDIR 0040000 /* directory */ #define _IFCHR 0020000 /* character special */ #define _IFBLK 0060000 /* block special */ #define _IFREG 0100000 /* regular */ #define _IFLNK 0120000 /* symbolic link */ #define _IFSOCK 0140000 /* socket */ #define _IFIFO 0010000 /* fifo */ #define S_BLKSIZE 1024 /* size of a block */ #define S_ISUID 0004000 /* set user id on execution */ #define S_ISGID 0002000 /* set group id on execution */ #define S_ISVTX 0001000 /* save swapped text even after use */ #if __BSD_VISIBLE #define S_IREAD 0000400 /* read permission, owner */ #define S_IWRITE 0000200 /* write permission, owner */ #define S_IEXEC 0000100 /* execute/search permission, owner */ #define S_ENFMT 0002000 /* enforcement-mode locking */ #endif /* !_BSD_VISIBLE */ #define S_IFMT _IFMT #define S_IFDIR _IFDIR #define S_IFCHR _IFCHR #define S_IFBLK _IFBLK #define S_IFREG _IFREG #define S_IFLNK _IFLNK #define S_IFSOCK _IFSOCK #define S_IFIFO _IFIFO #ifdef _WIN32 /* * The Windows header files define _S_ forms of these, so we do too * for easier portability. */ #define _S_IFMT _IFMT #define _S_IFDIR _IFDIR #define _S_IFCHR _IFCHR #define _S_IFIFO _IFIFO #define _S_IFREG _IFREG #define _S_IREAD 0000400 #define _S_IWRITE 0000200 #define _S_IEXEC 0000100 #endif #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) #define S_IRUSR 0000400 /* read permission, owner */ #define S_IWUSR 0000200 /* write permission, owner */ #define S_IXUSR 0000100 /* execute/search permission, owner */ #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) #define S_IRGRP 0000040 /* read permission, group */ #define S_IWGRP 0000020 /* write permission, grougroup */ #define S_IXGRP 0000010 /* execute/search permission, group */ #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) #define S_IROTH 0000004 /* read permission, other */ #define S_IWOTH 0000002 /* write permission, other */ #define S_IXOTH 0000001 /* execute/search permission, other */ #if __BSD_VISIBLE #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */ #define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */ #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */ #endif #define S_ISBLK(m) (((m)&_IFMT) == _IFBLK) #define S_ISCHR(m) (((m)&_IFMT) == _IFCHR) #define S_ISDIR(m) (((m)&_IFMT) == _IFDIR) #define S_ISFIFO(m) (((m)&_IFMT) == _IFIFO) #define S_ISREG(m) (((m)&_IFMT) == _IFREG) #define S_ISLNK(m) (((m)&_IFMT) == _IFLNK) #define S_ISSOCK(m) (((m)&_IFMT) == _IFSOCK) #if defined(__CYGWIN__) || defined(__rtems__) /* Special tv_nsec values for futimens(2) and utimensat(2). */ #define UTIME_NOW -2L #define UTIME_OMIT -1L #endif int chmod(const char *__path, mode_t __mode); int fchmod(int __fd, mode_t __mode); int fstat(int __fd, struct stat *__sbuf); int mkdir(const char *_path, mode_t __mode); int mkfifo(const char *__path, mode_t __mode); int stat(const char *__restrict __path, struct stat *__restrict __sbuf); mode_t umask(mode_t __mask); #if defined(__SPU__) || defined(__rtems__) || defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__) int lstat(const char *__restrict __path, struct stat *__restrict __buf); int mknod(const char *__path, mode_t __mode, dev_t __dev); #endif #if __ATFILE_VISIBLE && !defined(__INSIDE_CYGWIN__) int fchmodat(int __fd, const char *__path, mode_t __mode, int __flag); int fstatat(int __fd, const char *__restrict __path, struct stat *__restrict __buf, int __flag); int mkdirat(int __fd, const char *__path, mode_t __mode); int mkfifoat(int __fd, const char *__path, mode_t __mode); int mknodat(int __fd, const char *__path, mode_t __mode, dev_t __dev); int utimensat(int __fd, const char *__path, const struct timespec __times[2], int __flag); #endif #if __POSIX_VISIBLE >= 200809 && !defined(__INSIDE_CYGWIN__) int futimens(int __fd, const struct timespec __times[2]); #endif /* * Provide prototypes for most of the _<systemcall> names that are * provided in newlib for some compilers. */ #ifdef _LIBC int _fstat(int __fd, struct stat *__sbuf); int _stat(const char *__restrict __path, struct stat *__restrict __sbuf); int _mkdir(const char *_path, mode_t __mode); #ifdef __LARGE64_FILES struct stat64; int _stat64(const char *__restrict __path, struct stat64 *__restrict __sbuf); int _fstat64(int __fd, struct stat64 *__sbuf); #endif #endif #endif /* !_STAT_H_ */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_POSIX_SYS_STAT_H_ */ ```
/content/code_sandbox/include/zephyr/posix/sys/stat.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
2,270
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_SYS_TIME_H_ #define ZEPHYR_INCLUDE_POSIX_SYS_TIME_H_ #ifdef CONFIG_NEWLIB_LIBC /* Kludge to support outdated newlib version as used in SDK 0.10 for Xtensa */ #include <newlib.h> #ifdef __NEWLIB__ #include <sys/_timeval.h> #else #include <sys/types.h> struct timeval { time_t tv_sec; suseconds_t tv_usec; }; #endif #else #include <sys/_timeval.h> #endif /* CONFIG_NEWLIB_LIBC */ #ifdef __cplusplus extern "C" { #endif int gettimeofday(struct timeval *tv, void *tz); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_SYS_TIME_H_ */ ```
/content/code_sandbox/include/zephyr/posix/sys/time.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
163
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_SYS_UTSNAME_H_ #define ZEPHYR_INCLUDE_POSIX_SYS_UTSNAME_H_ #include <zephyr/sys/util_macro.h> #ifdef __cplusplus extern "C" { #endif /* These are for compatibility / practicality */ #define _UTSNAME_NODENAME_LENGTH \ COND_CODE_1(CONFIG_POSIX_SINGLE_PROCESS, (CONFIG_POSIX_UNAME_VERSION_LEN), (0)) #define _UTSNAME_VERSION_LENGTH \ COND_CODE_1(CONFIG_POSIX_SINGLE_PROCESS, (CONFIG_POSIX_UNAME_VERSION_LEN), (0)) struct utsname { char sysname[sizeof("Zephyr")]; char nodename[_UTSNAME_NODENAME_LENGTH + 1]; char release[sizeof("99.99.99-rc1")]; char version[_UTSNAME_VERSION_LENGTH + 1]; char machine[sizeof(CONFIG_ARCH)]; }; int uname(struct utsname *name); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_SYS_UTSNAME_H_ */ ```
/content/code_sandbox/include/zephyr/posix/sys/utsname.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
223
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_SYS_SELECT_H_ #define ZEPHYR_INCLUDE_POSIX_SYS_SELECT_H_ #include <zephyr/net/socket_types.h> #include <zephyr/net/socket_select.h> #ifdef __cplusplus extern "C" { #endif #define fd_set zsock_fd_set #define FD_SETSIZE ZSOCK_FD_SETSIZE #define FD_ZERO ZSOCK_FD_ZERO #define FD_SET ZSOCK_FD_SET #define FD_CLR ZSOCK_FD_CLR #define FD_ISSET ZSOCK_FD_ISSET struct timeval; int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_SYS_SELECT_H_ */ ```
/content/code_sandbox/include/zephyr/posix/sys/select.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
169
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_ZEPHYR_POSIX_SYS_MMAN_H_ #define ZEPHYR_INCLUDE_ZEPHYR_POSIX_SYS_MMAN_H_ #include <stddef.h> #include <sys/types.h> #define PROT_NONE 0x0 #define PROT_READ 0x1 #define PROT_WRITE 0x2 #define PROT_EXEC 0x4 #define MAP_SHARED 0x1 #define MAP_PRIVATE 0x2 #define MAP_FIXED 0x4 /* for Linux compatibility */ #define MAP_ANONYMOUS 0x20 #define MS_SYNC 0x0 #define MS_ASYNC 0x1 #define MS_INVALIDATE 0x2 #define MAP_FAILED ((void *)-1) #define MCL_CURRENT 0 #define MCL_FUTURE 1 #ifdef __cplusplus extern "C" { #endif int mlock(const void *addr, size_t len); int mlockall(int flags); void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off); int msync(void *addr, size_t length, int flags); int munlock(const void *addr, size_t len); int munlockall(void); int munmap(void *addr, size_t len); int shm_open(const char *name, int oflag, mode_t mode); int shm_unlink(const char *name); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_ZEPHYR_POSIX_SYS_MMAN_H_ */ ```
/content/code_sandbox/include/zephyr/posix/sys/mman.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
329
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_SYS_CONFSTR_H_ #define ZEPHYR_INCLUDE_POSIX_SYS_CONFSTR_H_ #ifdef __cplusplus extern "C" { #endif enum { _CS_PATH, _CS_POSIX_V7_ILP32_OFF32_CFLAGS, _CS_POSIX_V7_ILP32_OFF32_LDFLAGS, _CS_POSIX_V7_ILP32_OFF32_LIBS, _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS, _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS, _CS_POSIX_V7_ILP32_OFFBIG_LIBS, _CS_POSIX_V7_LP64_OFF64_CFLAGS, _CS_POSIX_V7_LP64_OFF64_LDFLAGS, _CS_POSIX_V7_LP64_OFF64_LIBS, _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS, _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS, _CS_POSIX_V7_LPBIG_OFFBIG_LIBS, _CS_POSIX_V7_THREADS_CFLAGS, _CS_POSIX_V7_THREADS_LDFLAGS, _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS, _CS_V7_ENV, _CS_POSIX_V6_ILP32_OFF32_CFLAGS, _CS_POSIX_V6_ILP32_OFF32_LDFLAGS, _CS_POSIX_V6_ILP32_OFF32_LIBS, _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_LIBS, _CS_POSIX_V6_LP64_OFF64_CFLAGS, _CS_POSIX_V6_LP64_OFF64_LDFLAGS, _CS_POSIX_V6_LP64_OFF64_LIBS, _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_LIBS, _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS, _CS_V6_ENV, }; #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_SYS_CONFSTR_H_ */ ```
/content/code_sandbox/include/zephyr/posix/sys/confstr.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
476
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_SYS_EVENTFD_H_ #define ZEPHYR_INCLUDE_POSIX_SYS_EVENTFD_H_ #include <zephyr/zvfs/eventfd.h> #ifdef __cplusplus extern "C" { #endif #define EFD_SEMAPHORE ZVFS_EFD_SEMAPHORE #define EFD_NONBLOCK ZVFS_EFD_NONBLOCK typedef zvfs_eventfd_t eventfd_t; /** * @brief Create a file descriptor for event notification * * The returned file descriptor can be used with POSIX read/write calls or * with the eventfd_read/eventfd_write functions. * * It also supports polling and by including an eventfd in a call to poll, * it is possible to signal and wake the polling thread by simply writing to * the eventfd. * * When using read() and write() on an eventfd, the size must always be at * least 8 bytes or the operation will fail with EINVAL. * * @return New eventfd file descriptor on success, -1 on error */ int eventfd(unsigned int initval, int flags); /** * @brief Read from an eventfd * * If call is successful, the value parameter will have the value 1 * * @param fd File descriptor * @param value Pointer for storing the read value * * @return 0 on success, -1 on error */ int eventfd_read(int fd, eventfd_t *value); /** * @brief Write to an eventfd * * @param fd File descriptor * @param value Value to write * * @return 0 on success, -1 on error */ int eventfd_write(int fd, eventfd_t value); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_SYS_EVENTFD_H_ */ ```
/content/code_sandbox/include/zephyr/posix/sys/eventfd.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
383
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_ #define ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_ #include <sys/types.h> #include <zephyr/net/socket.h> #define SHUT_RD ZSOCK_SHUT_RD #define SHUT_WR ZSOCK_SHUT_WR #define SHUT_RDWR ZSOCK_SHUT_RDWR #define MSG_PEEK ZSOCK_MSG_PEEK #define MSG_TRUNC ZSOCK_MSG_TRUNC #define MSG_DONTWAIT ZSOCK_MSG_DONTWAIT #define MSG_WAITALL ZSOCK_MSG_WAITALL #ifdef __cplusplus extern "C" { #endif struct linger { int l_onoff; int l_linger; }; int accept(int sock, struct sockaddr *addr, socklen_t *addrlen); int bind(int sock, const struct sockaddr *addr, socklen_t addrlen); int connect(int sock, const struct sockaddr *addr, socklen_t addrlen); int getpeername(int sock, struct sockaddr *addr, socklen_t *addrlen); int getsockname(int sock, struct sockaddr *addr, socklen_t *addrlen); int getsockopt(int sock, int level, int optname, void *optval, socklen_t *optlen); int listen(int sock, int backlog); ssize_t recv(int sock, void *buf, size_t max_len, int flags); ssize_t recvfrom(int sock, void *buf, size_t max_len, int flags, struct sockaddr *src_addr, socklen_t *addrlen); ssize_t recvmsg(int sock, struct msghdr *msg, int flags); ssize_t send(int sock, const void *buf, size_t len, int flags); ssize_t sendmsg(int sock, const struct msghdr *message, int flags); ssize_t sendto(int sock, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); int setsockopt(int sock, int level, int optname, const void *optval, socklen_t optlen); int shutdown(int sock, int how); int sockatmark(int s); int socket(int family, int type, int proto); int socketpair(int family, int type, int proto, int sv[2]); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_ */ ```
/content/code_sandbox/include/zephyr/posix/sys/socket.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
501
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_SYS_IOCTL_H_ #define ZEPHYR_INCLUDE_POSIX_SYS_IOCTL_H_ #include <zephyr/sys/fdtable.h> #define FIONBIO ZFD_IOCTL_FIONBIO #define FIONREAD ZFD_IOCTL_FIONREAD #ifdef __cplusplus extern "C" { #endif int ioctl(int fd, unsigned long request, ...); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_SYS_IOCTL_H_ */ ```
/content/code_sandbox/include/zephyr/posix/sys/ioctl.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
106
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_ #define ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_ #include <stddef.h> #include <zephyr/posix/netinet/in.h> #include <zephyr/posix/sys/socket.h> #include <zephyr/net/socket.h> #ifdef __cplusplus extern "C" { #endif typedef uint32_t in_addr_t; in_addr_t inet_addr(const char *cp); char *inet_ntoa(struct in_addr in); char *inet_ntop(sa_family_t family, const void *src, char *dst, size_t size); int inet_pton(sa_family_t family, const char *src, void *dst); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_ */ ```
/content/code_sandbox/include/zephyr/posix/arpa/inet.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
169
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_NET_IF_H_ #define ZEPHYR_INCLUDE_POSIX_NET_IF_H_ #ifdef CONFIG_NET_INTERFACE_NAME_LEN #define IF_NAMESIZE CONFIG_NET_INTERFACE_NAME_LEN #else #define IF_NAMESIZE 1 #endif #ifdef __cplusplus extern "C" { #endif struct if_nameindex { unsigned int if_index; char *if_name; }; char *if_indextoname(unsigned int ifindex, char *ifname); void if_freenameindex(struct if_nameindex *ptr); struct if_nameindex *if_nameindex(void); unsigned int if_nametoindex(const char *ifname); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_NET_IF_H_ */ ```
/content/code_sandbox/include/zephyr/posix/net/if.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
156
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_SYS_SYSCONF_H_ #define ZEPHYR_INCLUDE_POSIX_SYS_SYSCONF_H_ #include <zephyr/sys/util_macro.h> #ifdef __cplusplus extern "C" { #endif enum { _SC_ADVISORY_INFO, _SC_ASYNCHRONOUS_IO, _SC_BARRIERS, _SC_CLOCK_SELECTION, _SC_CPUTIME, _SC_FSYNC, _SC_IPV6, _SC_JOB_CONTROL, _SC_MAPPED_FILES, _SC_MEMLOCK, _SC_MEMLOCK_RANGE, _SC_MEMORY_PROTECTION, _SC_MESSAGE_PASSING, _SC_MONOTONIC_CLOCK, _SC_PRIORITIZED_IO, _SC_PRIORITY_SCHEDULING, _SC_RAW_SOCKETS, _SC_RE_DUP_MAX, _SC_READER_WRITER_LOCKS, _SC_REALTIME_SIGNALS, _SC_REGEXP, _SC_SAVED_IDS, _SC_SEMAPHORES, _SC_SHARED_MEMORY_OBJECTS, _SC_SHELL, _SC_SPAWN, _SC_SPIN_LOCKS, _SC_SPORADIC_SERVER, _SC_SS_REPL_MAX, _SC_SYNCHRONIZED_IO, _SC_THREAD_ATTR_STACKADDR, _SC_THREAD_ATTR_STACKSIZE, _SC_THREAD_CPUTIME, _SC_THREAD_PRIO_INHERIT, _SC_THREAD_PRIO_PROTECT, _SC_THREAD_PRIORITY_SCHEDULING, _SC_THREAD_PROCESS_SHARED, _SC_THREAD_ROBUST_PRIO_INHERIT, _SC_THREAD_ROBUST_PRIO_PROTECT, _SC_THREAD_SAFE_FUNCTIONS, _SC_THREAD_SPORADIC_SERVER, _SC_THREADS, _SC_TIMEOUTS, _SC_TIMERS, _SC_TRACE, _SC_TRACE_EVENT_FILTER, _SC_TRACE_EVENT_NAME_MAX, _SC_TRACE_INHERIT, _SC_TRACE_LOG, _SC_TRACE_NAME_MAX, _SC_TRACE_SYS_MAX, _SC_TRACE_USER_EVENT_MAX, _SC_TYPED_MEMORY_OBJECTS, _SC_VERSION, _SC_V7_ILP32_OFF32, _SC_V7_ILP32_OFFBIG, _SC_V7_LP64_OFF64, _SC_V7_LPBIG_OFFBIG, _SC_V6_ILP32_OFF32, _SC_V6_ILP32_OFFBIG, _SC_V6_LP64_OFF64, _SC_V6_LPBIG_OFFBIG, _SC_BC_BASE_MAX, _SC_BC_DIM_MAX, _SC_BC_SCALE_MAX, _SC_BC_STRING_MAX, _SC_2_C_BIND, _SC_2_C_DEV, _SC_2_CHAR_TERM, _SC_COLL_WEIGHTS_MAX, _SC_DELAYTIMER_MAX, _SC_EXPR_NEST_MAX, _SC_2_FORT_DEV, _SC_2_FORT_RUN, _SC_LINE_MAX, _SC_2_LOCALEDEF, _SC_2_PBS, _SC_2_PBS_ACCOUNTING, _SC_2_PBS_CHECKPOINT, _SC_2_PBS_LOCATE, _SC_2_PBS_MESSAGE, _SC_2_PBS_TRACK, _SC_2_SW_DEV, _SC_2_UPE, _SC_2_VERSION, _SC_XOPEN_CRYPT, _SC_XOPEN_ENH_I18N, _SC_XOPEN_REALTIME, _SC_XOPEN_REALTIME_THREADS, _SC_XOPEN_SHM, _SC_XOPEN_STREAMS, _SC_XOPEN_UNIX, _SC_XOPEN_UUCP, _SC_XOPEN_VERSION, _SC_CLK_TCK, _SC_GETGR_R_SIZE_MAX, _SC_GETPW_R_SIZE_MAX, _SC_AIO_LISTIO_MAX, _SC_AIO_MAX, _SC_AIO_PRIO_DELTA_MAX, _SC_ARG_MAX, _SC_ATEXIT_MAX, _SC_CHILD_MAX, _SC_HOST_NAME_MAX, _SC_IOV_MAX, _SC_LOGIN_NAME_MAX, _SC_NGROUPS_MAX, _SC_MQ_OPEN_MAX, _SC_MQ_PRIO_MAX, _SC_OPEN_MAX, _SC_PAGE_SIZE, _SC_PAGESIZE, _SC_THREAD_DESTRUCTOR_ITERATIONS, _SC_THREAD_KEYS_MAX, _SC_THREAD_STACK_MIN, _SC_THREAD_THREADS_MAX, _SC_RTSIG_MAX, _SC_SEM_NSEMS_MAX, _SC_SEM_VALUE_MAX, _SC_SIGQUEUE_MAX, _SC_STREAM_MAX, _SC_SYMLOOP_MAX, _SC_TIMER_MAX, _SC_TTY_NAME_MAX, _SC_TZNAME_MAX, }; #define __z_posix_sysconf_SC_ADVISORY_INFO (-1L) #define __z_posix_sysconf_SC_ASYNCHRONOUS_IO \ COND_CODE_1(CONFIG_POSIX_ASYNCHRONOUS_IO, (_POSIX_ASYNCHRONOUS_IO), (-1L)) #define __z_posix_sysconf_SC_BARRIERS COND_CODE_1(CONFIG_POSIX_BARRIERS, (_POSIX_BARRIERS), (-1L)) #define __z_posix_sysconf_SC_CLOCK_SELECTION \ COND_CODE_1(CONFIG_POSIX_CLOCK_SELECTION, (_POSIX_CLOCK_SELECTION), (-1L)) #define __z_posix_sysconf_SC_CPUTIME \ COND_CODE_1(CONFIG_POSIX_CPUTIME, (_POSIX_CPUTIME), (-1L)) #define __z_posix_sysconf_SC_FSYNC \ COND_CODE_1(CONFIG_POSIX_FSYNC, (_POSIX_FSYNC), (-1L)) #define __z_posix_sysconf_SC_IPV6 COND_CODE_1(CONFIG_NET_IPV6, (_POSIX_IPV6), (-1L)) #define __z_posix_sysconf_SC_JOB_CONTROL (-1L) #define __z_posix_sysconf_SC_MAPPED_FILES \ COND_CODE_1(CONFIG_POSIX_MAPPED_FILES, (_POSIX_MAPPED_FILES), (-1L)) #define __z_posix_sysconf_SC_MEMLOCK \ COND_CODE_1(CONFIG_POSIX_MEMLOCK, (_POSIX_MEMLOCK), (-1L)) #define __z_posix_sysconf_SC_MEMLOCK_RANGE \ COND_CODE_1(CONFIG_POSIX_MEMLOCK_RANGE, (_POSIX_MEMLOCK_RANGE), (-1L)) #define __z_posix_sysconf_SC_MEMORY_PROTECTION \ COND_CODE_1(CONFIG_POSIX_MEMORY_PROTECTION, (_POSIX_MEMORY_PROTECTION), (-1L)) #define __z_posix_sysconf_SC_MESSAGE_PASSING \ COND_CODE_1(CONFIG_POSIX_MESSAGE_PASSING, (_POSIX_MESSAGE_PASSING), (-1L)) #define __z_posix_sysconf_SC_MONOTONIC_CLOCK \ COND_CODE_1(CONFIG_POSIX_MONOTONIC_CLOCK, (_POSIX_MONOTONIC_CLOCK), (-1L)) #define __z_posix_sysconf_SC_PRIORITIZED_IO (-1L) #define __z_posix_sysconf_SC_PRIORITY_SCHEDULING \ COND_CODE_1(CONFIG_POSIX_PRIORITY_SCHEDULING, (_POSIX_PRIORITY_SCHEDULING), (-1L)) #define __z_posix_sysconf_SC_RAW_SOCKETS \ COND_CODE_1(CONFIG_NET_SOCKETS_PACKET, (_POSIX_RAW_SOCKETS), (-1L)) #define __z_posix_sysconf_SC_RE_DUP_MAX _POSIX_RE_DUP_MAX #define __z_posix_sysconf_SC_READER_WRITER_LOCKS \ COND_CODE_1(CONFIG_POSIX_READER_WRITER_LOCKS, (_POSIX_READER_WRITER_LOCKS), (-1L)) #define __z_posix_sysconf_SC_REALTIME_SIGNALS (-1L) #define __z_posix_sysconf_SC_REGEXP (-1L) #define __z_posix_sysconf_SC_SAVED_IDS (-1L) #define __z_posix_sysconf_SC_SEMAPHORES \ COND_CODE_1(CONFIG_POSIX_SEMAPHORES, (_POSIX_SEMAPHORES), (-1L)) #define __z_posix_sysconf_SC_SHARED_MEMORY_OBJECTS \ COND_CODE_1(CONFIG_POSIX_SHARED_MEMORY_OBJECTS, (_POSIX_SHARED_MEMORY_OBJECTS), (-1L)) #define __z_posix_sysconf_SC_SHELL (-1L) #define __z_posix_sysconf_SC_SPAWN (-1L) #define __z_posix_sysconf_SC_SPIN_LOCKS \ COND_CODE_1(CONFIG_POSIX_SPIN_LOCKS, (_POSIX_SPIN_LOCKS), (-1L)) #define __z_posix_sysconf_SC_SPORADIC_SERVER (-1L) #define __z_posix_sysconf_SC_SS_REPL_MAX _POSIX_SS_REPL_MAX #define __z_posix_sysconf_SC_SYNCHRONIZED_IO (-1L) #define __z_posix_sysconf_SC_THREAD_ATTR_STACKADDR \ COND_CODE_1(CONFIG_POSIX_THREAD_ATTR_STACKADDR, (_POSIX_THREAD_ATTR_STACKADDR), (-1)) #define __z_posix_sysconf_SC_THREAD_ATTR_STACKSIZE \ COND_CODE_1(CONFIG_POSIX_THREAD_ATTR_STACKSIZE, (_POSIX_THREAD_ATTR_STACKSIZE), (-1L)) #define __z_posix_sysconf_SC_THREAD_CPUTIME (-1L) #define __z_posix_sysconf_SC_THREAD_PRIO_INHERIT \ COND_CODE_1(CONFIG_POSIX_THREAD_PRIO_INHERIT, (_POSIX_THREAD_PRIO_INHERIT), (-1L)) #define __z_posix_sysconf_SC_THREAD_PRIO_PROTECT (-1L) #define __z_posix_sysconf_SC_THREAD_PRIORITY_SCHEDULING \ COND_CODE_1(CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING, (_POSIX_THREAD_PRIORITY_SCHEDULING), \ (-1L)) #define __z_posix_sysconf_SC_THREAD_PROCESS_SHARED (-1L) #define __z_posix_sysconf_SC_THREAD_ROBUST_PRIO_INHERIT (-1L) #define __z_posix_sysconf_SC_THREAD_ROBUST_PRIO_PROTECT (-1L) #define __z_posix_sysconf_SC_THREAD_SAFE_FUNCTIONS \ COND_CODE_1(CONFIG_POSIX_THREAD_SAFE_FUNCTIONS, (_POSIX_THREAD_SAFE_FUNCTIONS), (-1L)) #define __z_posix_sysconf_SC_THREAD_SPORADIC_SERVER (-1L) #define __z_posix_sysconf_SC_THREADS \ COND_CODE_1(CONFIG_POSIX_THREADS, (_POSIX_THREADS), (-1L)) #define __z_posix_sysconf_SC_TIMEOUTS \ COND_CODE_1(CONFIG_POSIX_TIMEOUTS, (_POSIX_TIMEOUTS), (-1L)) #define __z_posix_sysconf_SC_TIMERS \ COND_CODE_1(CONFIG_POSIX_TIMEOUTS, (_POSIX_TIMERS), (-1)) #define __z_posix_sysconf_SC_TRACE (-1L) #define __z_posix_sysconf_SC_TRACE_EVENT_FILTER (-1L) #define __z_posix_sysconf_SC_TRACE_EVENT_NAME_MAX _POSIX_TRACE_NAME_MAX #define __z_posix_sysconf_SC_TRACE_INHERIT (-1L) #define __z_posix_sysconf_SC_TRACE_LOG (-1L) #define __z_posix_sysconf_SC_TRACE_NAME_MAX _POSIX_TRACE_NAME_MAX #define __z_posix_sysconf_SC_TRACE_SYS_MAX _POSIX_TRACE_SYS_MAX #define __z_posix_sysconf_SC_TRACE_USER_EVENT_MAX _POSIX_TRACE_USER_EVENT_MAX #define __z_posix_sysconf_SC_TYPED_MEMORY_OBJECTS (-1L) #define __z_posix_sysconf_SC_VERSION _POSIX_VERSION #define __z_posix_sysconf_SC_V6_ILP32_OFF32 (-1L) #define __z_posix_sysconf_SC_V6_ILP32_OFFBIG (-1L) #define __z_posix_sysconf_SC_V6_LP64_OFF64 (-1L) #define __z_posix_sysconf_SC_V6_LPBIG_OFFBIG (-1L) #define __z_posix_sysconf_SC_V7_ILP32_OFF32 (-1L) #define __z_posix_sysconf_SC_V7_ILP32_OFFBIG (-1L) #define __z_posix_sysconf_SC_V7_LP64_OFF64 (-1L) #define __z_posix_sysconf_SC_V7_LPBIG_OFFBIG (-1L) #define __z_posix_sysconf_SC_BC_BASE_MAX _POSIX2_BC_BASE_MAX #define __z_posix_sysconf_SC_BC_DIM_MAX _POSIX2_BC_DIM_MAX #define __z_posix_sysconf_SC_BC_SCALE_MAX _POSIX2_BC_SCALE_MAX #define __z_posix_sysconf_SC_BC_STRING_MAX _POSIX2_BC_STRING_MAX #define __z_posix_sysconf_SC_2_C_BIND _POSIX2_C_BIND #define __z_posix_sysconf_SC_2_C_DEV _POSIX2_C_DEV #define __z_posix_sysconf_SC_2_CHAR_TERM (-1L) #define __z_posix_sysconf_SC_COLL_WEIGHTS_MAX _POSIX2_COLL_WEIGHTS_MAX #define __z_posix_sysconf_SC_DELAYTIMER_MAX _POSIX_DELAYTIMER_MAX #define __z_posix_sysconf_SC_EXPR_NEST_MAX _POSIX2_EXPR_NEST_MAX #define __z_posix_sysconf_SC_2_FORT_DEV (-1L) #define __z_posix_sysconf_SC_2_FORT_RUN (-1L) #define __z_posix_sysconf_SC_LINE_MAX (-1L) #define __z_posix_sysconf_SC_2_LOCALEDEF (-1L) #define __z_posix_sysconf_SC_2_PBS (-1L) #define __z_posix_sysconf_SC_2_PBS_ACCOUNTING (-1L) #define __z_posix_sysconf_SC_2_PBS_CHECKPOINT (-1L) #define __z_posix_sysconf_SC_2_PBS_LOCATE (-1L) #define __z_posix_sysconf_SC_2_PBS_MESSAGE (-1L) #define __z_posix_sysconf_SC_2_PBS_TRACK (-1L) #define __z_posix_sysconf_SC_2_SW_DEV (-1L) #define __z_posix_sysconf_SC_2_UPE (-1L) #define __z_posix_sysconf_SC_2_VERSION _POSIX2_VERSION #define __z_posix_sysconf_SC_XOPEN_CRYPT (-1L) #define __z_posix_sysconf_SC_XOPEN_ENH_I18N (-1L) #define __z_posix_sysconf_SC_XOPEN_REALTIME (-1L) #define __z_posix_sysconf_SC_XOPEN_REALTIME_THREADS (-1L) #define __z_posix_sysconf_SC_XOPEN_SHM (-1L) #define __z_posix_sysconf_SC_XOPEN_STREAMS \ COND_CODE_1(CONFIG_XOPEN_STREAMS, (_XOPEN_STREAMS), (-1)) #define __z_posix_sysconf_SC_XOPEN_UNIX (-1L) #define __z_posix_sysconf_SC_XOPEN_UUCP (-1L) #define __z_posix_sysconf_SC_XOPEN_VERSION _XOPEN_VERSION #define __z_posix_sysconf_SC_CLK_TCK (100L) #define __z_posix_sysconf_SC_GETGR_R_SIZE_MAX (0L) #define __z_posix_sysconf_SC_GETPW_R_SIZE_MAX (0L) #define __z_posix_sysconf_SC_AIO_LISTIO_MAX AIO_LISTIO_MAX #define __z_posix_sysconf_SC_AIO_MAX AIO_MAX #define __z_posix_sysconf_SC_AIO_PRIO_DELTA_MAX AIO_PRIO_DELTA_MAX #define __z_posix_sysconf_SC_ARG_MAX ARG_MAX #define __z_posix_sysconf_SC_ATEXIT_MAX ATEXIT_MAX #define __z_posix_sysconf_SC_CHILD_MAX CHILD_MAX #define __z_posix_sysconf_SC_HOST_NAME_MAX HOST_NAME_MAX #define __z_posix_sysconf_SC_IOV_MAX IOV_MAX #define __z_posix_sysconf_SC_LOGIN_NAME_MAX LOGIN_NAME_MAX #define __z_posix_sysconf_SC_NGROUPS_MAX _POSIX_NGROUPS_MAX #define __z_posix_sysconf_SC_MQ_OPEN_MAX MQ_OPEN_MAX #define __z_posix_sysconf_SC_MQ_PRIO_MAX MQ_PRIO_MAX #define __z_posix_sysconf_SC_OPEN_MAX CONFIG_ZVFS_OPEN_MAX #define __z_posix_sysconf_SC_PAGE_SIZE PAGE_SIZE #define __z_posix_sysconf_SC_PAGESIZE PAGESIZE #define __z_posix_sysconf_SC_THREAD_DESTRUCTOR_ITERATIONS PTHREAD_DESTRUCTOR_ITERATIONS #define __z_posix_sysconf_SC_THREAD_KEYS_MAX PTHREAD_KEYS_MAX #define __z_posix_sysconf_SC_THREAD_STACK_MIN PTHREAD_STACK_MIN #define __z_posix_sysconf_SC_THREAD_THREADS_MAX PTHREAD_THREADS_MAX #define __z_posix_sysconf_SC_RTSIG_MAX RTSIG_MAX #define __z_posix_sysconf_SC_SEM_NSEMS_MAX SEM_NSEMS_MAX #define __z_posix_sysconf_SC_SEM_VALUE_MAX SEM_VALUE_MAX #define __z_posix_sysconf_SC_SIGQUEUE_MAX SIGQUEUE_MAX #define __z_posix_sysconf_SC_STREAM_MAX STREAM_MAX #define __z_posix_sysconf_SC_SYMLOOP_MAX SYMLOOP_MAX #define __z_posix_sysconf_SC_TIMER_MAX TIMER_MAX #define __z_posix_sysconf_SC_TTY_NAME_MAX TTY_NAME_MAX #define __z_posix_sysconf_SC_TZNAME_MAX TZNAME_MAX #ifdef CONFIG_POSIX_SYSCONF_IMPL_MACRO #define sysconf(x) (long)CONCAT(__z_posix_sysconf, x) #endif #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_SYS_SYSCONF_H_ */ ```
/content/code_sandbox/include/zephyr/posix/sys/sysconf.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
3,738
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_NETINET_TCP_H_ #define ZEPHYR_INCLUDE_POSIX_NETINET_TCP_H_ #include <zephyr/net/socket.h> #ifdef __cplusplus extern "C" { #endif #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_NETINET_TCP_H_ */ ```
/content/code_sandbox/include/zephyr/posix/netinet/tcp.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
72
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_NETINET_IN_H_ #define ZEPHYR_INCLUDE_POSIX_NETINET_IN_H_ #include <stdint.h> #include <zephyr/net/socket.h> #ifdef __cplusplus extern "C" { #endif typedef uint16_t in_port_t; typedef uint32_t in_addr_t; #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_NETINET_IN_H_ */ ```
/content/code_sandbox/include/zephyr/posix/netinet/in.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
93
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_POSIX_NET_IF_ARP_H_ #define ZEPHYR_INCLUDE_POSIX_NET_IF_ARP_H_ #ifdef __cplusplus extern "C" { #endif /* See path_to_url * for the ARP hardware address type values. */ /* ARP protocol HARDWARE identifiers. */ #define ARPHRD_NETROM 0 /* From KA9Q: NET/ROM pseudo. */ #define ARPHRD_ETHER 1 /* Ethernet 10/100Mbps. */ #define ARPHRD_EETHER 2 /* Experimental Ethernet. */ #define ARPHRD_AX25 3 /* AX.25 Level 2. */ #define ARPHRD_PRONET 4 /* PROnet token ring. */ #define ARPHRD_CHAOS 5 /* Chaosnet. */ #define ARPHRD_IEEE802 6 /* IEEE 802.2 Ethernet/TR/TB. */ #define ARPHRD_ARCNET 7 /* ARCnet. */ #define ARPHRD_APPLETLK 8 /* APPLEtalk. */ #define ARPHRD_DLCI 15 /* Frame Relay DLCI. */ #define ARPHRD_ATM 19 /* ATM. */ #define ARPHRD_METRICOM 23 /* Metricom STRIP (new IANA id). */ #define ARPHRD_IEEE1394 24 /* IEEE 1394 IPv4 - RFC 2734. */ #define ARPHRD_EUI64 27 /* EUI-64. */ #define ARPHRD_INFINIBAND 32 /* InfiniBand. */ /* Dummy types for non ARP hardware */ #define ARPHRD_SLIP 256 #define ARPHRD_CSLIP 257 #define ARPHRD_SLIP6 258 #define ARPHRD_CSLIP6 259 #define ARPHRD_RSRVD 260 /* Notional KISS type. */ #define ARPHRD_ADAPT 264 #define ARPHRD_ROSE 270 #define ARPHRD_X25 271 /* CCITT X.25. */ #define ARPHRD_HWX25 272 /* Boards with X.25 in firmware. */ #define ARPHRD_CAN 280 /* Controller Area Network. */ #define ARPHRD_MCTP 290 #define ARPHRD_PPP 512 #define ARPHRD_CISCO 513 /* Cisco HDLC. */ #define ARPHRD_HDLC ARPHRD_CISCO #define ARPHRD_LAPB 516 /* LAPB. */ #define ARPHRD_DDCMP 517 /* Digital's DDCMP. */ #define ARPHRD_RAWHDLC 518 /* Raw HDLC. */ #define ARPHRD_RAWIP 519 /* Raw IP. */ #define ARPHRD_TUNNEL 768 /* IPIP tunnel. */ #define ARPHRD_TUNNEL6 769 /* IPIP6 tunnel. */ #define ARPHRD_FRAD 770 /* Frame Relay Access Device. */ #define ARPHRD_SKIP 771 /* SKIP vif. */ #define ARPHRD_LOOPBACK 772 /* Loopback device. */ #define ARPHRD_LOCALTLK 773 /* Localtalk device. */ #define ARPHRD_FDDI 774 /* Fiber Distributed Data Interface. */ #define ARPHRD_BIF 775 /* AP1000 BIF. */ #define ARPHRD_SIT 776 /* sit0 device - IPv6-in-IPv4. */ #define ARPHRD_IPDDP 777 /* IP-in-DDP tunnel. */ #define ARPHRD_IPGRE 778 /* GRE over IP. */ #define ARPHRD_PIMREG 779 /* PIMSM register interface. */ #define ARPHRD_HIPPI 780 /* High Performance Parallel I'face. */ #define ARPHRD_ASH 781 /* (Nexus Electronics) Ash. */ #define ARPHRD_ECONET 782 /* Acorn Econet. */ #define ARPHRD_IRDA 783 /* Linux-IrDA. */ #define ARPHRD_FCPP 784 /* Point to point fibrechanel. */ #define ARPHRD_FCAL 785 /* Fibrechanel arbitrated loop. */ #define ARPHRD_FCPL 786 /* Fibrechanel public loop. */ #define ARPHRD_FCFABRIC 787 /* Fibrechanel fabric. */ #define ARPHRD_IEEE802_TR 800 /* Magic type ident for TR. */ #define ARPHRD_IEEE80211 801 /* IEEE 802.11. */ #define ARPHRD_IEEE80211_PRISM 802 /* IEEE 802.11 + Prism2 header. */ #define ARPHRD_IEEE80211_RADIOTAP 803 /* IEEE 802.11 + radiotap header. */ #define ARPHRD_IEEE802154 804 /* IEEE 802.15.4 header. */ #define ARPHRD_IEEE802154_PHY 805 /* IEEE 802.15.4 PHY header. */ #define ARPHRD_VOID 0xFFFF /* Void type, nothing is known. */ #define ARPHRD_NONE 0xFFFE /* Zero header length. */ #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_POSIX_NET_IF_ARP_H_ */ ```
/content/code_sandbox/include/zephyr/posix/net/if_arp.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,223
```objective-c /* * */ #ifndef ZEPHYR_ARCH_X86_INCLUDE_ACPI_OSAL_H_ #define ZEPHYR_ARCH_X86_INCLUDE_ACPI_OSAL_H_ #if defined(CONFIG_X86 || CONFIG_X86_64) #include <zephyr/acpi/x86_acpi_osal.h> #else #error "Currently only x86 Architecture support ACPI !!" #endif #endif /* ZEPHYR_ARCH_X86_INCLUDE_ACPI_OSAL_H_ */ ```
/content/code_sandbox/include/zephyr/acpi/acpi_osal.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
93
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_SENSING_SENSOR_TYPES_H_ #define ZEPHYR_INCLUDE_SENSING_SENSOR_TYPES_H_ /** * @brief Sensor Types Definition * * Sensor types definition followed HID standard. * path_to_url * * TODO: will add more types * * @addtogroup sensing_sensor_types * @{ */ /** * sensor category light */ #define SENSING_SENSOR_TYPE_LIGHT_AMBIENTLIGHT 0x41 /** * sensor category motion */ /* Sensor type for 3D accelerometers. */ #define SENSING_SENSOR_TYPE_MOTION_ACCELEROMETER_3D 0x73 /* Sensor type for 3D gyrometers. */ #define SENSING_SENSOR_TYPE_MOTION_GYROMETER_3D 0x76 /* Sensor type for motion detectors. */ #define SENSING_SENSOR_TYPE_MOTION_MOTION_DETECTOR 0x77 /** * sensor category other */ #define SENSING_SENSOR_TYPE_OTHER_CUSTOM 0xE1 /* Sensor type for uncalibrated 3D accelerometers. */ #define SENSING_SENSOR_TYPE_MOTION_UNCALIB_ACCELEROMETER_3D 0x240 /* Sensor type for hinge angle sensors. */ #define SENSING_SENSOR_TYPE_MOTION_HINGE_ANGLE 0x20B /** * @brief Sensor type for all sensors. * * This macro defines the sensor type for all sensors. */ #define SENSING_SENSOR_TYPE_ALL 0xFFFF /** * @} */ #endif /*ZEPHYR_INCLUDE_SENSING_SENSOR_TYPES_H_*/ ```
/content/code_sandbox/include/zephyr/sensing/sensing_sensor_types.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
333
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_SENSING_DATATYPES_H_ #define ZEPHYR_INCLUDE_SENSING_DATATYPES_H_ #include <stdint.h> #include <zephyr/dsp/types.h> /** * @brief Data Types * @addtogroup sensing_datatypes * @{ */ /** * @struct sensing_sensor_value_header * @brief sensor value header * * Each sensor value data structure should have this header * * Here use 'base_timestamp' (uint64_t) and 'timestamp_delta' (uint32_t) to * save memory usage in batching mode. * * The 'base_timestamp' is for readings[0], the 'timestamp_delta' is relation * to the previous 'readings'. So, * timestamp of readings[0] is * header.base_timestamp + readings[0].timestamp_delta. * timestamp of readings[1] is * timestamp of readings[0] + readings[1].timestamp_delta. * * Since timestamp unit is micro seconds, the max 'timestamp_delta' (uint32_t) * is 4295 seconds. * * If a sensor has batched data where two consecutive readings differ by * more than 4295 seconds, the sensor subsystem core will split them * across multiple instances of the readings structure, and send multiple * events. * * This concept is borrowed from CHRE: * path_to_url * system/chre/chre_api/include/chre_api/chre/sensor_types.h */ struct sensing_sensor_value_header { /** Base timestamp of this data readings, unit is micro seconds */ uint64_t base_timestamp; /** Count of this data readings */ uint16_t reading_count; }; /** * @brief Sensor value data structure types based on common data types. * Suitable for common sensors, such as IMU, Light sensors and orientation sensors. */ /** * @brief Sensor value data structure for 3-axis sensors. * struct sensing_sensor_value_3d_q31 can be used by 3D IMU sensors like: * SENSING_SENSOR_TYPE_MOTION_ACCELEROMETER_3D, * SENSING_SENSOR_TYPE_MOTION_UNCALIB_ACCELEROMETER_3D, * SENSING_SENSOR_TYPE_MOTION_GYROMETER_3D, * q31 version */ struct sensing_sensor_value_3d_q31 { /** Header of the sensor value data structure. */ struct sensing_sensor_value_header header; int8_t shift; /**< The shift value for the q31_t v[3] reading. */ struct { /** Timestamp delta of the reading. Unit is micro seconds. */ uint32_t timestamp_delta; union { /** * 3D vector of the reading represented as an array. * For SENSING_SENSOR_TYPE_MOTION_ACCELEROMETER_3D and * SENSING_SENSOR_TYPE_MOTION_UNCALIB_ACCELEROMETER_3D, * the unit is Gs (gravitational force). * For SENSING_SENSOR_TYPE_MOTION_GYROMETER_3D, the unit is degrees. */ q31_t v[3]; struct { q31_t x; /**< X value of the 3D vector. */ q31_t y; /**< Y value of the 3D vector. */ q31_t z; /**< Z value of the 3D vector. */ }; }; } readings[1]; /**< Array of readings. */ }; /** * @brief Sensor value data structure for single 1-axis value. * struct sensing_sensor_value_uint32 can be used by SENSING_SENSOR_TYPE_LIGHT_AMBIENTLIGHT sensor * uint32_t version */ struct sensing_sensor_value_uint32 { /** Header of the sensor value data structure. */ struct sensing_sensor_value_header header; struct { /** Timestamp delta of the reading. Unit is micro seconds. */ uint32_t timestamp_delta; /** * Value of the reading. * For SENSING_SENSOR_TYPE_LIGHT_AMBIENTLIGHT, the unit is luxs. */ uint32_t v; } readings[1]; /**< Array of readings. */ }; /** * @brief Sensor value data structure for single 1-axis value. * struct sensing_sensor_value_q31 can be used by SENSING_SENSOR_TYPE_MOTION_HINGE_ANGLE sensor * q31 version */ struct sensing_sensor_value_q31 { /** Header of the sensor value data structure. */ struct sensing_sensor_value_header header; int8_t shift; /**< The shift value for the q31_t v reading. */ struct { /** Timestamp delta of the reading. Unit is micro seconds. */ uint32_t timestamp_delta; /** * Value of the reading. * For SENSING_SENSOR_TYPE_MOTION_HINGE_ANGLE, the unit is degrees. */ q31_t v; } readings[1]; /**< Array of readings. */ }; /** * @} */ #endif /*ZEPHYR_INCLUDE_SENSING_DATATYPES_H_*/ ```
/content/code_sandbox/include/zephyr/sensing/sensing_datatypes.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,056
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_DRIVERS_ACPI_H_ #define ZEPHYR_INCLUDE_DRIVERS_ACPI_H_ #include <acpica/source/include/acpi.h> #include <zephyr/drivers/pcie/pcie.h> #define ACPI_RES_INVALID ACPI_RESOURCE_TYPE_MAX #define ACPI_DRHD_FLAG_INCLUDE_PCI_ALL BIT(0) #define ACPI_DMAR_FLAG_INTR_REMAP BIT(0) #define ACPI_DMAR_FLAG_X2APIC_OPT_OUT BIT(1) #define ACPI_DMAR_FLAG_DMA_CTRL_PLATFORM_OPT_IN BIT(2) #define ACPI_MMIO_GET(res) (res)->reg_base[0].mmio #define ACPI_IO_GET(res) (res)->reg_base[0].port #define ACPI_RESOURCE_SIZE_GET(res) (res)->reg_base[0].length #define ACPI_RESOURCE_TYPE_GET(res) (res)->reg_base[0].type #define ACPI_MULTI_MMIO_GET(res, idx) (res)->reg_base[idx].mmio #define ACPI_MULTI_IO_GET(res, idx) (res)->reg_base[idx].port #define ACPI_MULTI_RESOURCE_SIZE_GET(res, idx) (res)->reg_base[idx].length #define ACPI_MULTI_RESOURCE_TYPE_GET(res, idx) (res)->reg_base[idx].type #define ACPI_RESOURCE_COUNT_GET(res) (res)->mmio_max enum acpi_res_type { /** IO mapped Resource type */ ACPI_RES_TYPE_IO, /** Memory mapped Resource type */ ACPI_RES_TYPE_MEM, /** Unknown Resource type */ ACPI_RES_TYPE_UNKNOWN, }; struct acpi_dev { ACPI_HANDLE handle; char *path; ACPI_RESOURCE *res_lst; int res_type; ACPI_DEVICE_INFO *dev_info; }; union acpi_dmar_id { struct { uint16_t function: 3; uint16_t device: 5; uint16_t bus: 8; } bits; uint16_t raw; }; struct acpi_mcfg { ACPI_TABLE_HEADER header; uint64_t _reserved; ACPI_MCFG_ALLOCATION pci_segs[]; } __packed; struct acpi_irq_resource { uint32_t flags; uint8_t irq_vector_max; uint16_t *irqs; }; struct acpi_reg_base { enum acpi_res_type type; union { uintptr_t mmio; uintptr_t port; }; uint32_t length; }; struct acpi_mmio_resource { uint8_t mmio_max; struct acpi_reg_base *reg_base; }; /** * @brief Get the ACPI HID for a node * * @param node_id DTS node identifier * @return The HID of the ACPI node */ #define ACPI_DT_HID(node_id) DT_PROP(node_id, acpi_hid) /** * @brief Get the ACPI UID for a node if one exist * * @param node_id DTS node identifier * @return The UID of the ACPI node else NULL if does not exist */ #define ACPI_DT_UID(node_id) DT_PROP_OR(node_id, acpi_uid, NULL) /** * @brief check whether the node has ACPI HID property or not * * @param node_id DTS node identifier * @return 1 if the node has the HID, 0 otherwise. */ #define ACPI_DT_HAS_HID(node_id) DT_NODE_HAS_PROP(node_id, acpi_hid) /** * @brief check whether the node has ACPI UID property or not * * @param node_id DTS node identifier * @return 1 if the node has the UID, 0 otherwise. */ #define ACPI_DT_HAS_UID(node_id) DT_NODE_HAS_PROP(node_id, acpi_uid) /** * @brief Init legacy interrupt routing table information from ACPI. * Currently assume platform have only one PCI bus. * * @param hid the hardware id of the ACPI child device * @param uid the unique id of the ACPI child device. The uid can be * NULL if only one device with given hid present in the platform. * @return return 0 on success or error code */ int acpi_legacy_irq_init(const char *hid, const char *uid); /** * @brief Retrieve a legacy interrupt number for a PCI device. * * @param bdf the BDF of endpoint/PCI device * @return return IRQ number or UINT_MAX if not found */ uint32_t acpi_legacy_irq_get(pcie_bdf_t bdf); /** * @brief Retrieve the current resource settings of a device. * * @param dev_name the name of the device * @param res the list of acpi resource list * @return return 0 on success or error code */ int acpi_current_resource_get(char *dev_name, ACPI_RESOURCE **res); /** * @brief Retrieve possible resource settings of a device. * * @param dev_name the name of the device * @param res the list of acpi resource list * @return return 0 on success or error code */ int acpi_possible_resource_get(char *dev_name, ACPI_RESOURCE **res); /** * @brief Free current resource list memory which is retrieved by * acpi_current_resource_get(). * * @param res the list of acpi resource list * @return return 0 on success or error code */ int acpi_current_resource_free(ACPI_RESOURCE *res); /** * @brief Parse resource table for a given resource type. * * @param res the list of acpi resource list * @param res_type the acpi resource type * @return resource list for the given type on success or NULL */ ACPI_RESOURCE *acpi_resource_parse(ACPI_RESOURCE *res, int res_type); /** * @brief Retrieve ACPI device info for given hardware id and unique id. * * @param hid the hardware id of the ACPI child device * @param uid the unique id of the ACPI child device. The uid can be * NULL if only one device with given HID present in the platform. * @return ACPI child device info on success or NULL */ struct acpi_dev *acpi_device_get(const char *hid, const char *uid); /** * @brief Retrieve acpi device info from the index. * * @param index the device index of an acpi child device * @return acpi child device info on success or NULL */ struct acpi_dev *acpi_device_by_index_get(int index); /** * @brief Parse resource table for irq info. * * @param res_lst the list of acpi resource list * @return irq resource list on success or NULL */ static inline ACPI_RESOURCE_IRQ *acpi_irq_res_get(ACPI_RESOURCE *res_lst) { ACPI_RESOURCE *res = acpi_resource_parse(res_lst, ACPI_RESOURCE_TYPE_IRQ); return res ? &res->Data.Irq : NULL; } /** * @brief Parse resource table for irq info. * * @param child_dev the device object of the ACPI node * @param irq_res irq resource info * @return return 0 on success or error code */ int acpi_device_irq_get(struct acpi_dev *child_dev, struct acpi_irq_resource *irq_res); /** * @brief Parse resource table for MMIO info. * * @param child_dev the device object of the ACPI node * @param mmio_res MMIO resource info * @return return 0 on success or error code */ int acpi_device_mmio_get(struct acpi_dev *child_dev, struct acpi_mmio_resource *mmio_res); /** * @brief Parse resource table for identify resource type. * * @param res the list of acpi resource list * @return resource type on success or invalid resource type */ int acpi_device_type_get(ACPI_RESOURCE *res); /** * @brief Retrieve acpi table for the given signature. * * @param signature pointer to the 4-character ACPI signature for the requested table * @param inst instance number for the requested table * @return acpi_table pointer to the acpi table on success else return NULL */ void *acpi_table_get(char *signature, int inst); /** * @brief retrieve acpi MAD table for the given type. * * @param type type of requested MAD table * @param tables pointer to the MAD table * @param num_inst number of instance for the requested table * @return return 0 on success or error code */ int acpi_madt_entry_get(int type, ACPI_SUBTABLE_HEADER **tables, int *num_inst); /** * @brief retrieve DMA remapping structure for the given type. * * @param type type of remapping structure * @param tables pointer to the dmar id structure * @return return 0 on success or error code */ int acpi_dmar_entry_get(enum AcpiDmarType type, ACPI_SUBTABLE_HEADER **tables); /** * @brief retrieve acpi DRHD info for the given scope. * * @param scope scope of requested DHRD table * @param dev_scope pointer to the sub table (optional) * @param dmar_id pointer to the DHRD info * @param num_inst number of instance for the requested table * @param max_inst maximum number of entry for the given dmar_id buffer * @return return 0 on success or error code */ int acpi_drhd_get(enum AcpiDmarScopeType scope, ACPI_DMAR_DEVICE_SCOPE *dev_scope, union acpi_dmar_id *dmar_id, int *num_inst, int max_inst); typedef void (*dmar_foreach_subtable_func_t)(ACPI_DMAR_HEADER *subtable, void *arg); typedef void (*dmar_foreach_devscope_func_t)(ACPI_DMAR_DEVICE_SCOPE *devscope, void *arg); void acpi_dmar_foreach_subtable(ACPI_TABLE_DMAR *dmar, dmar_foreach_subtable_func_t func, void *arg); void acpi_dmar_foreach_devscope(ACPI_DMAR_HARDWARE_UNIT *hu, dmar_foreach_devscope_func_t func, void *arg); /** * @brief Retrieve IOAPIC id * * @param ioapic_id IOAPIC id * @return return 0 on success or error code */ int acpi_dmar_ioapic_get(uint16_t *ioapic_id); /** * @brief Retrieve the 'n'th enabled local apic info. * * @param cpu_num the cpu number * @return local apic info on success or NULL otherwise */ ACPI_MADT_LOCAL_APIC *acpi_local_apic_get(int cpu_num); /** * @brief invoke an ACPI method and return the result. * * @param path the path name of the ACPI object * @param arg_list the list of arguments to be pass down * @param ret_obj the ACPI result to be return * @return return 0 on success or error code */ int acpi_invoke_method(char *path, ACPI_OBJECT_LIST *arg_list, ACPI_OBJECT *ret_obj); #endif ```
/content/code_sandbox/include/zephyr/acpi/acpi.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
2,314
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_SENSING_H_ #define ZEPHYR_INCLUDE_SENSING_H_ /** * @defgroup sensing Sensing * @defgroup sensing_api Sensing Subsystem API * @ingroup sensing * @defgroup sensing_sensor_types Sensor Types * @ingroup sensing * @defgroup sensing_datatypes Data Types * @ingroup sensing */ #include <zephyr/sensing/sensing_datatypes.h> #include <zephyr/sensing/sensing_sensor_types.h> #include <zephyr/device.h> /** * @brief Sensing Subsystem API * @addtogroup sensing_api * @{ */ #ifdef __cplusplus extern "C" { #endif /** * @struct sensing_sensor_version * @brief Sensor Version */ struct sensing_sensor_version { union { uint32_t value; /**< The version represented as a 32-bit value. */ struct { uint8_t major; /**< The major version number. */ uint8_t minor; /**< The minor version number. */ uint8_t hotfix; /**< The hotfix version number. */ uint8_t build; /**< The build version number. */ }; }; }; /** * @brief Macro to create a sensor version value. * */ #define SENSING_SENSOR_VERSION(_major, _minor, _hotfix, _build) \ (FIELD_PREP(GENMASK(31, 24), _major) | \ FIELD_PREP(GENMASK(23, 16), _minor) | \ FIELD_PREP(GENMASK(15, 8), _hotfix) | \ FIELD_PREP(GENMASK(7, 0), _build)) /** * @brief Sensor flag indicating if this sensor is on event reporting data. * * Reporting sensor data when the sensor event occurs, such as a motion detect sensor reporting * a motion or motionless detected event. */ #define SENSING_SENSOR_FLAG_REPORT_ON_EVENT BIT(0) /** * @brief Sensor flag indicating if this sensor is on change reporting data. * * Reporting sensor data when the sensor data changes. * * Exclusive with \ref SENSING_SENSOR_FLAG_REPORT_ON_EVENT */ #define SENSING_SENSOR_FLAG_REPORT_ON_CHANGE BIT(1) /** * @brief SENSING_SENSITIVITY_INDEX_ALL indicating sensitivity of each data field should be set * */ #define SENSING_SENSITIVITY_INDEX_ALL -1 /** * @brief Sensing subsystem sensor state. * */ enum sensing_sensor_state { SENSING_SENSOR_STATE_READY = 0, /**< The sensor is ready. */ SENSING_SENSOR_STATE_OFFLINE = 1, /**< The sensor is offline. */ }; /** * @brief Sensing subsystem sensor config attribute * */ enum sensing_sensor_attribute { /** The interval attribute of a sensor configuration. */ SENSING_SENSOR_ATTRIBUTE_INTERVAL = 0, /** The sensitivity attribute of a sensor configuration. */ SENSING_SENSOR_ATTRIBUTE_SENSITIVITY = 1, /** The latency attribute of a sensor configuration. */ SENSING_SENSOR_ATTRIBUTE_LATENCY = 2, /** The maximum number of attributes that a sensor configuration can have. */ SENSING_SENSOR_ATTRIBUTE_MAX, }; /** * @brief Define Sensing subsystem sensor handle * */ typedef void *sensing_sensor_handle_t; /** * @brief Sensor data event receive callback. * * @param handle The sensor instance handle. * @param buf The data buffer with sensor data. * @param context User provided context pointer. */ typedef void (*sensing_data_event_t)( sensing_sensor_handle_t handle, const void *buf, void *context); /** * @struct sensing_sensor_info * @brief Sensor basic constant information * */ struct sensing_sensor_info { /** Name of the sensor instance */ const char *name; /** Friendly name of the sensor instance */ const char *friendly_name; /** Vendor name of the sensor instance */ const char *vendor; /** Model name of the sensor instance */ const char *model; /** Sensor type */ const int32_t type; /** Minimal report interval in micro seconds */ const uint32_t minimal_interval; }; /** * @struct sensing_callback_list * @brief Sensing subsystem event callback list * */ struct sensing_callback_list { sensing_data_event_t on_data_event; /**< Callback function for a sensor data event. */ void *context; /**< Associated context with on_data_event */ }; /** * @struct sensing_sensor_config * @brief Sensing subsystem sensor configure, including interval, sensitivity, latency * */ struct sensing_sensor_config { enum sensing_sensor_attribute attri; /**< Attribute of the sensor configuration. */ /** \ref SENSING_SENSITIVITY_INDEX_ALL */ int8_t data_field; /**< Data field of the sensor configuration. */ union { /** Interval between two sensor samples in microseconds (us). */ uint32_t interval; /** * Sensitivity threshold for reporting new data. A new sensor sample is reported * only if the difference between it and the previous sample exceeds this * sensitivity value. */ uint32_t sensitivity; /** * Maximum duration for batching sensor samples before reporting in * microseconds (us). This defines how long sensor samples can be * accumulated before they must be reported. */ uint64_t latency; }; }; /** * @brief Get all supported sensor instances' information. * * This API just returns read only information of sensor instances, pointer info will * directly point to internal buffer, no need for caller to allocate buffer, * no side effect to sensor instances. * * @param num_sensors Get number of sensor instances. * @param info For receiving sensor instances' information array pointer. * @return 0 on success or negative error value on failure. */ int sensing_get_sensors(int *num_sensors, const struct sensing_sensor_info **info); /** * @brief Open sensor instance by sensing sensor info * * Application clients use it to open a sensor instance and get its handle. * Support multiple Application clients for open same sensor instance, * in this case, the returned handle will different for different clients. * meanwhile, also register sensing callback list * * @param info The sensor info got from \ref sensing_get_sensors * @param cb_list callback list to be registered to sensing, must have a static * lifetime. * @param handle The opened instance handle, if failed will be set to NULL. * @return 0 on success or negative error value on failure. */ int sensing_open_sensor( const struct sensing_sensor_info *info, struct sensing_callback_list *cb_list, sensing_sensor_handle_t *handle); /** * @brief Open sensor instance by device. * * Application clients use it to open a sensor instance and get its handle. * Support multiple Application clients for open same sensor instance, * in this case, the returned handle will different for different clients. * meanwhile, also register sensing callback list. * * @param dev pointer device get from device tree. * @param cb_list callback list to be registered to sensing, must have a static * lifetime. * @param handle The opened instance handle, if failed will be set to NULL. * @return 0 on success or negative error value on failure. */ int sensing_open_sensor_by_dt( const struct device *dev, struct sensing_callback_list *cb_list, sensing_sensor_handle_t *handle); /** * @brief Close sensor instance. * * @param handle The sensor instance handle need to close. * @return 0 on success or negative error value on failure. */ int sensing_close_sensor( sensing_sensor_handle_t *handle); /** * @brief Set current config items to Sensing subsystem. * * @param handle The sensor instance handle. * @param configs The configs to be set according to config attribute. * @param count count of configs. * @return 0 on success or negative error value on failure, not support etc. */ int sensing_set_config( sensing_sensor_handle_t handle, struct sensing_sensor_config *configs, int count); /** * @brief Get current config items from Sensing subsystem. * * @param handle The sensor instance handle. * @param configs The configs to be get according to config attribute. * @param count count of configs. * @return 0 on success or negative error value on failure, not support etc. */ int sensing_get_config( sensing_sensor_handle_t handle, struct sensing_sensor_config *configs, int count); /** * @brief Get sensor information from sensor instance handle. * * @param handle The sensor instance handle. * @return a const pointer to \ref sensing_sensor_info on success or NULL on failure. */ const struct sensing_sensor_info *sensing_get_sensor_info( sensing_sensor_handle_t handle); #ifdef __cplusplus } #endif /** * @} */ #endif /*ZEPHYR_INCLUDE_SENSING_H_*/ ```
/content/code_sandbox/include/zephyr/sensing/sensing.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,867
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_SENSING_SENSOR_H_ #define ZEPHYR_INCLUDE_SENSING_SENSOR_H_ #include <stdbool.h> #include <zephyr/device.h> #include <zephyr/drivers/sensor.h> #include <zephyr/sensing/sensing.h> /** * @defgroup sensing_sensor Sensing Sensor API * @ingroup sensing * @defgroup sensing_sensor_callbacks Sensor Callbacks * @ingroup sensing_sensor */ /** * @brief Sensing Sensor API * @addtogroup sensing_sensor * @{ */ #ifdef __cplusplus extern "C" { #endif /** * @brief Sensor registration information * */ struct sensing_sensor_register_info { /** * Sensor flags */ uint16_t flags; /** * Sample size in bytes for a single sample of the registered sensor. * sensing runtime need this information for internal buffer allocation. */ uint16_t sample_size; /** * The number of sensor sensitivities */ uint8_t sensitivity_count; /** * Sensor version. * Version can be used to identify different versions of sensor implementation. */ struct sensing_sensor_version version; }; /** @cond INTERNAL_HIDDEN */ /** * @brief Enumeration for sensing subsystem event. * * This enumeration defines the various events used by the sensing subsystem. */ enum { EVENT_CONFIG_READY, /**< Configuration is ready. */ }; /** * @brief Enumeration for sensor flag bit. * * This enumeration defines the bit for sensor flag. */ enum { SENSOR_LATER_CFG_BIT, /**< Indicates if there is a configuration request pending. */ }; /** * @brief Connection between a source and sink of sensor data */ struct sensing_connection { sys_snode_t snode; /**< Node in the singly-linked list of connections. */ struct sensing_sensor *source; /**< Source sensor of the connection. */ struct sensing_sensor *sink; /**< Sink sensor of the connection. */ uint32_t interval; /**< Report interval in micro seconds. */ /** Sensitivity of the connection. */ int sensitivity[CONFIG_SENSING_MAX_SENSITIVITY_COUNT]; void *data; /**< Pointer to sensor sample data of the connection. */ /** Next consume time of the connection. Unit is micro seconds. */ uint64_t next_consume_time; struct sensing_callback_list *callback_list; /**< Callback list of the connection. */ }; /** * @brief Internal sensor instance data structure. * * Each sensor instance will have its unique data structure for storing all * it's related information. * * Sensor management will enumerate all these instance data structures, * build report relationship model base on them, etc. */ struct sensing_sensor { const struct device *dev; /**< Device of the sensor instance. */ const struct sensing_sensor_info *info; /**< Info of the sensor instance. */ /** Register info of the sensor instance. */ const struct sensing_sensor_register_info *register_info; const uint16_t reporter_num; /**< Reporter number of the sensor instance. */ sys_slist_t client_list; /**< List of the sensor clients. */ uint32_t interval; /**< Report interval of the sensor sample in micro seconds. */ uint8_t sensitivity_count; /**< Sensitivity count of the sensor instance. */ /** Sensitivity array of the sensor instance. */ int sensitivity[CONFIG_SENSING_MAX_SENSITIVITY_COUNT]; enum sensing_sensor_state state; /**< State of the sensor instance. */ struct rtio_iodev *iodev; /**< Pointer to RTIO device of the sensor instance. */ struct k_timer timer; /**< Timer for non streaming mode */ struct rtio_sqe *stream_sqe; /**< Sqe for streaming mode. */ atomic_t flag; /**< Sensor flag of the sensor instance. */ struct sensing_connection *conns; /**< Pointer to sensor connections. */ }; /** * @brief Macro to generate a name for a sensor info structure. * * This macro generates a name for a sensor info structure based on a node and an index. * * @param node The devicetree node identifier. * @param idx Logical index into the sensor-types array. */ #define SENSING_SENSOR_INFO_NAME(node, idx) \ _CONCAT(_CONCAT(__sensing_sensor_info_, idx), DEVICE_DT_NAME_GET(node)) /** * @brief Macro to define a sensor info structure. * * This macro defines a sensor info structure based on a node and an index. * The structure includes the type, name, friendly name, vendor, model, and minimal interval of the * sensor. * * @param node The devicetree node identifier. * @param idx Logical index into the sensor-types array. */ #define SENSING_SENSOR_INFO_DEFINE(node, idx) \ const static STRUCT_SECTION_ITERABLE(sensing_sensor_info, \ SENSING_SENSOR_INFO_NAME(node, idx)) = { \ .type = DT_PROP_BY_IDX(node, sensor_types, idx), \ .name = DT_NODE_FULL_NAME(node), \ .friendly_name = DT_PROP(node, friendly_name), \ .vendor = DT_NODE_VENDOR_OR(node, NULL), \ .model = DT_NODE_MODEL_OR(node, NULL), \ .minimal_interval = DT_PROP(node, minimal_interval), \ }; /** * @brief Macro to generate a name for a connections array. * * This macro generates a name for a connections array based on a node. * * @param node The devicetree node identifier. */ #define SENSING_CONNECTIONS_NAME(node) \ _CONCAT(__sensing_connections_, DEVICE_DT_NAME_GET(node)) /** * @brief Macro to generate a name for a sensor source. * * This macro generates a name for a sensor source based on an index and a node. * * @param idx Logical index into the reporters array. * @param node The devicetree node identifier. */ #define SENSING_SENSOR_SOURCE_NAME(idx, node) \ SENSING_SENSOR_NAME(DT_PHANDLE_BY_IDX(node, reporters, idx), \ DT_PROP_BY_IDX(node, reporters_index, idx)) /** * @brief Macro to declare an external sensor source. * * This macro declares an external sensor source based on an index and a node. * * @param idx Logical index into the reporters array. * @param node The devicetree node identifier. */ #define SENSING_SENSOR_SOURCE_EXTERN(idx, node) \ extern struct sensing_sensor SENSING_SENSOR_SOURCE_NAME(idx, node); /** * @brief Macro to initialize a connection. * * This macro initializes a connection with a source name and a callback list pointer. * * @param source_name The name of struct sensing_sensor for source sensor. * @param cb_list_ptr Pointer to sensing callback list. */ #define SENSING_CONNECTION_INITIALIZER(source_name, cb_list_ptr) \ { \ .callback_list = cb_list_ptr, \ .source = &source_name, \ } /** * @brief Macro to define a connection. * * This macro defines a connection based on an index, a node, and a callback list pointer. * * @param idx Logical index into the reporters array. * @param node The devicetree node identifier. * @param cb_list_ptr Pointer to sensing callback list. */ #define SENSING_CONNECTION_DEFINE(idx, node, cb_list_ptr) \ SENSING_CONNECTION_INITIALIZER(SENSING_SENSOR_SOURCE_NAME(idx, node), \ cb_list_ptr) /** * @brief Macro to define an array of connections. * * This macro defines an array of connections based on a node, a number, and a callback list * pointer. * * @param node The devicetree node identifier. * @param num The number of the connections. * @param cb_list_ptr Pointer to sensing callback list. */ #define SENSING_CONNECTIONS_DEFINE(node, num, cb_list_ptr) \ LISTIFY(num, SENSING_SENSOR_SOURCE_EXTERN, \ (), node) \ static struct sensing_connection \ SENSING_CONNECTIONS_NAME(node)[(num)] = { \ LISTIFY(num, SENSING_CONNECTION_DEFINE, \ (,), node, cb_list_ptr) \ }; /** * @brief Structure for sensor submit configuration. * * This structure represents a sensor submit configuration. It includes the channel, info index, and * streaming flag. */ struct sensing_submit_config { enum sensor_channel chan; /**< Channel of the sensor to submit. */ const int info_index; /**< Logical index into the sensor-types array. */ const bool is_streaming; /**< Working in streaming mode or not. */ }; /** * @brief External declaration for the sensing I/O device API. * * This external declaration represents the sensing I/O device API. */ extern const struct rtio_iodev_api __sensing_iodev_api; /** * @brief Macro to generate a name for a submit configuration. * * This macro generates a name for a submit configuration based on a node and an index. * * @param node The devicetree node identifier. * @param idx Logical index into the sensor-types array. */ #define SENSING_SUBMIT_CFG_NAME(node, idx) \ _CONCAT(_CONCAT(__sensing_submit_cfg_, idx), DEVICE_DT_NAME_GET(node)) /** * @brief Macro to generate a name for a sensor I/O device. * * This macro generates a name for a sensor I/O device based on a node and an index. * * @param node The devicetree node identifier. * @param idx Logical index into the sensor-types array. */ #define SENSING_SENSOR_IODEV_NAME(node, idx) \ _CONCAT(_CONCAT(__sensing_iodev_, idx), DEVICE_DT_NAME_GET(node)) /** * @brief Macro to define a sensor I/O device. * * This macro defines a sensor I/O device based on a node and an index. * The device includes a submit configuration with a streaming flag and an info index. * * @param node The devicetree node identifier. * @param idx Logical index into the sensor-types array. */ #define SENSING_SENSOR_IODEV_DEFINE(node, idx) \ static struct sensing_submit_config SENSING_SUBMIT_CFG_NAME(node, idx) = { \ .is_streaming = DT_PROP(node, stream_mode), \ .info_index = idx, \ }; \ RTIO_IODEV_DEFINE(SENSING_SENSOR_IODEV_NAME(node, idx), \ &__sensing_iodev_api, \ &SENSING_SUBMIT_CFG_NAME(node, idx)); /** * @brief Macro to generate a name for a sensor. * * This macro generates a name for a sensor based on a node and an index. * * @param node The devicetree node identifier. * @param idx Logical index into the sensor-types array. */ #define SENSING_SENSOR_NAME(node, idx) \ _CONCAT(_CONCAT(__sensing_sensor_, idx), DEVICE_DT_NAME_GET(node)) /** * @brief Macro to define a sensor. * * This macro defines a sensor based on a node, a property, an index, a register info pointer, and a * callback list pointer. The sensor includes a device, info, register info, reporter number, * connections, and an I/O device. * * @param node The devicetree node identifier. * @param prop property name. * @param idx Logical index into the sensor-types array. * @param reg_ptr Pointer to the device's sensing_sensor_register_info. * @param cb_list_ptr Pointer to sensing callback list. */ #define SENSING_SENSOR_DEFINE(node, prop, idx, reg_ptr, cb_list_ptr) \ SENSING_SENSOR_INFO_DEFINE(node, idx) \ SENSING_SENSOR_IODEV_DEFINE(node, idx) \ STRUCT_SECTION_ITERABLE(sensing_sensor, \ SENSING_SENSOR_NAME(node, idx)) = { \ .dev = DEVICE_DT_GET(node), \ .info = &SENSING_SENSOR_INFO_NAME(node, idx), \ .register_info = reg_ptr, \ .reporter_num = DT_PROP_LEN_OR(node, reporters, 0), \ .conns = SENSING_CONNECTIONS_NAME(node), \ .iodev = &SENSING_SENSOR_IODEV_NAME(node, idx), \ }; /** * @brief Macro to define sensors. * * This macro defines sensors based on a node, a register info pointer, and a callback list pointer. * It uses the DT_FOREACH_PROP_ELEM_VARGS macro to define each sensor. * * @param node The devicetree node identifier. * @param reg_ptr Pointer to the device's sensing_sensor_register_info. * @param cb_list_ptr Pointer to sensing callback list. */ #define SENSING_SENSORS_DEFINE(node, reg_ptr, cb_list_ptr) \ DT_FOREACH_PROP_ELEM_VARGS(node, sensor_types, \ SENSING_SENSOR_DEFINE, reg_ptr, cb_list_ptr) /** @endcond */ /** * @brief Like SENSOR_DEVICE_DT_DEFINE() with sensing specifics. * * @details Defines a sensor which implements the sensor API. May define an * element in the sensing sensor iterable section used to enumerate all sensing * sensors. * * @param node The devicetree node identifier. * @param reg_ptr Pointer to the device's sensing_sensor_register_info. * @param cb_list_ptr Pointer to sensing callback list. * @param init_fn Name of the init function of the driver. * @param pm_device PM device resources reference (NULL if device does not use * PM). * @param data_ptr Pointer to the device's private data. * @param cfg_ptr The address to the structure containing the configuration * information for this instance of the driver. * @param level The initialization level. See SYS_INIT() for details. * @param prio Priority within the selected initialization level. See * SYS_INIT() for details. * @param api_ptr Provides an initial pointer to the API function struct used * by the driver. Can be NULL. */ #define SENSING_SENSORS_DT_DEFINE(node, reg_ptr, cb_list_ptr, \ init_fn, pm_device, \ data_ptr, cfg_ptr, level, prio, \ api_ptr, ...) \ SENSOR_DEVICE_DT_DEFINE(node, init_fn, pm_device, \ data_ptr, cfg_ptr, level, prio, \ api_ptr, __VA_ARGS__); \ SENSING_CONNECTIONS_DEFINE(node, \ DT_PROP_LEN_OR(node, reporters, 0), \ cb_list_ptr); \ SENSING_SENSORS_DEFINE(node, reg_ptr, cb_list_ptr); /** * @brief Like SENSING_SENSORS_DT_DEFINE() for an instance of a DT_DRV_COMPAT * compatible * * @param inst instance number. This is replaced by * <tt>DT_DRV_COMPAT(inst)</tt> in the call to SENSING_SENSORS_DT_DEFINE(). * @param ... other parameters as expected by SENSING_SENSORS_DT_DEFINE(). */ #define SENSING_SENSORS_DT_INST_DEFINE(inst, ...) \ SENSING_SENSORS_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__) /** * @brief Get reporter handles of a given sensor instance by sensor type. * * @param dev The sensor instance device structure. * @param type The given type, \ref SENSING_SENSOR_TYPE_ALL to get reporters * with all types. * @param max_handles The max count of the \p reporter_handles array input. Can * get real count number via \ref sensing_sensor_get_reporters_count * @param reporter_handles Input handles array for receiving found reporter * sensor instances * @return number of reporters found, 0 returned if not found. */ int sensing_sensor_get_reporters( const struct device *dev, int type, sensing_sensor_handle_t *reporter_handles, int max_handles); /** * @brief Get reporters count of a given sensor instance by sensor type. * * @param dev The sensor instance device structure. * @param type The sensor type for checking, \ref SENSING_SENSOR_TYPE_ALL * @return Count of reporters by \p type, 0 returned if no reporters by \p type. */ int sensing_sensor_get_reporters_count( const struct device *dev, int type); /** * @brief Get this sensor's state * * @param dev The sensor instance device structure. * @param state Returned sensor state value * @return 0 on success or negative error value on failure. */ int sensing_sensor_get_state( const struct device *dev, enum sensing_sensor_state *state); /** * @} */ #ifdef __cplusplus } #endif #endif /*ZEPHYR_INCLUDE_SENSING_SENSOR_H_*/ ```
/content/code_sandbox/include/zephyr/sensing/sensing_sensor.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
3,550
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_INPUT_PMW3610_H_ #define ZEPHYR_INCLUDE_INPUT_PMW3610_H_ /** * @brief Set resolution on a pmw3610 device * * @param dev pmw3610 device. * @param res_cpi CPI resolution, 200 to 3200. */ int pmw3610_set_resolution(const struct device *dev, uint16_t res_cpi); /** * @brief Set force awake mode on a pmw3610 device * * @param dev pmw3610 device. * @param enable whether to enable or disable force awake mode. */ int pmw3610_force_awake(const struct device *dev, bool enable); #endif /* ZEPHYR_INCLUDE_INPUT_PMW3610_H_ */ ```
/content/code_sandbox/include/zephyr/input/input_pmw3610.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
165
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_INPUT_PAT912X_H_ #define ZEPHYR_INCLUDE_INPUT_PAT912X_H_ /** * @brief Set resolution on a pat912x device * * @param dev pat912x device. * @param res_x_cpi CPI resolution for the X axis, 0 to 1275, -1 to keep the * current value. * @param res_y_cpi CPI resolution for the Y axis, 0 to 1275, -1 to keep the * current value. */ int pat912x_set_resolution(const struct device *dev, int16_t res_x_cpi, int16_t res_y_cpi); #endif /* ZEPHYR_INCLUDE_INPUT_PAT912X_H_ */ ```
/content/code_sandbox/include/zephyr/input/input_pat912x.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
160
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_INPUT_HID_H_ #define ZEPHYR_INCLUDE_INPUT_HID_H_ /** * @addtogroup input_interface * @{ */ /** * @brief Convert an input code to HID code. * * Takes an input code as input and returns the corresponding HID code as * output. The return value is -1 if the code is not found, if found it can * safely be casted to a uint8_t type. * * @param input_code Event code (see @ref INPUT_KEY_CODES). * @retval the HID code corresponding to the input code. * @retval -1 if there's no HID code for the specified input code. */ int16_t input_to_hid_code(uint16_t input_code); /** * @brief Convert an input code to HID modifier. * * Takes an input code as input and returns the corresponding HID modifier as * output or 0. * * @param input_code Event code (see @ref INPUT_KEY_CODES). * @retval the HID modifier corresponding to the input code. * @retval 0 if there's no HID modifier for the specified input code. */ uint8_t input_to_hid_modifier(uint16_t input_code); /** @} */ #endif /* ZEPHYR_INCLUDE_INPUT_HID_H_ */ ```
/content/code_sandbox/include/zephyr/input/input_hid.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
265
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_INPUT_PAW32XX_H_ #define ZEPHYR_INCLUDE_INPUT_PAW32XX_H_ /** * @brief Set resolution on a paw32xx device * * @param dev paw32xx device. * @param res_cpi CPI resolution, 200 to 3200. */ int paw32xx_set_resolution(const struct device *dev, uint16_t res_cpi); /** * @brief Set force awake mode on a paw32xx device * * @param dev paw32xx device. * @param enable whether to enable or disable force awake mode. */ int paw32xx_force_awake(const struct device *dev, bool enable); #endif /* ZEPHYR_INCLUDE_INPUT_PAW32XX_H_ */ ```
/content/code_sandbox/include/zephyr/input/input_paw32xx.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
159
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_INPUT_ANALOG_AXIS_H_ #define ZEPHYR_INCLUDE_INPUT_ANALOG_AXIS_H_ #include <stdint.h> #include <zephyr/device.h> /** * @brief Analog axis API * @defgroup input_analog_axis Analog axis API * @ingroup io_interfaces * @{ */ /** * @brief Analog axis calibration data structure. * * Holds the calibration data for a single analog axis. Initial values are set * from the devicetree and can be changed by the applicatoin in runtime using * @ref analog_axis_calibration_set and @ref analog_axis_calibration_get. */ struct analog_axis_calibration { /** Input value that corresponds to the minimum output value. */ int16_t in_min; /** Input value that corresponds to the maximum output value. */ int16_t in_max; /** Input value center deadzone. */ uint16_t in_deadzone; }; /** * @brief Analog axis raw data callback. * * @param dev Analog axis device. * @param channel Channel number. * @param raw_val Raw value for the channel. */ typedef void (*analog_axis_raw_data_t)(const struct device *dev, int channel, int16_t raw_val); /** * @brief Set a raw data callback. * * Set a callback to receive raw data for the specified analog axis device. * This is meant to be use in the application to acquire the data to use for * calibration. Set cb to NULL to disable the callback. * * @param dev Analog axis device. * @param cb An analog_axis_raw_data_t callback to use, NULL disable. */ void analog_axis_set_raw_data_cb(const struct device *dev, analog_axis_raw_data_t cb); /** * @brief Get the number of defined axes. * * @retval n The number of defined axes for dev. */ int analog_axis_num_axes(const struct device *dev); /** * @brief Get the axis calibration data. * * @param dev Analog axis device. * @param channel Channel number. * @param cal Pointer to an analog_axis_calibration structure that is going to * get set with the current calibration data. * * @retval 0 If successful. * @retval -EINVAL If the specified channel is not valid. */ int analog_axis_calibration_get(const struct device *dev, int channel, struct analog_axis_calibration *cal); /** * @brief Set the axis calibration data. * * @param dev Analog axis device. * @param channel Channel number. * @param cal Pointer to an analog_axis_calibration structure with the new * calibration data * * @retval 0 If successful. * @retval -EINVAL If the specified channel is not valid. */ int analog_axis_calibration_set(const struct device *dev, int channel, struct analog_axis_calibration *cal); /** @} */ #endif /* ZEPHYR_INCLUDE_INPUT_ANALOG_AXIS_H_ */ ```
/content/code_sandbox/include/zephyr/input/input_analog_axis.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
600
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_INPUT_H_ #define ZEPHYR_INCLUDE_INPUT_H_ /** * @brief Input Interface * @defgroup input_interface Input Interface * @since 3.4 * @version 0.1.0 * @ingroup io_interfaces * @{ */ #include <stdint.h> #include <zephyr/device.h> #include <zephyr/dt-bindings/input/input-event-codes.h> #include <zephyr/kernel.h> #include <zephyr/sys/iterable_sections.h> #ifdef __cplusplus extern "C" { #endif /** * @brief Input event structure. * * This structure represents a single input event, for example a key or button * press for a single button, or an absolute or relative coordinate for a * single axis. */ struct input_event { /** Device generating the event or NULL. */ const struct device *dev; /** Sync flag. */ uint8_t sync; /** Event type (see @ref INPUT_EV_CODES). */ uint8_t type; /** * Event code (see @ref INPUT_KEY_CODES, @ref INPUT_BTN_CODES, * @ref INPUT_ABS_CODES, @ref INPUT_REL_CODES, @ref INPUT_MSC_CODES). */ uint16_t code; /** Event value. */ int32_t value; }; /** * @brief Report a new input event. * * This causes all the callbacks for the specified device to be executed, * either synchronously or through the input thread if utilized. * * @param dev Device generating the event or NULL. * @param type Event type (see @ref INPUT_EV_CODES). * @param code Event code (see @ref INPUT_KEY_CODES, @ref INPUT_BTN_CODES, * @ref INPUT_ABS_CODES, @ref INPUT_REL_CODES, @ref INPUT_MSC_CODES). * @param value Event value. * @param sync Set the synchronization bit for the event. * @param timeout Timeout for reporting the event, ignored if * @kconfig{CONFIG_INPUT_MODE_SYNCHRONOUS} is used. * @retval 0 if the message has been processed. * @retval negative if @kconfig{CONFIG_INPUT_MODE_THREAD} is enabled and the * message failed to be enqueued. */ int input_report(const struct device *dev, uint8_t type, uint16_t code, int32_t value, bool sync, k_timeout_t timeout); /** * @brief Report a new @ref INPUT_EV_KEY input event, note that value is * converted to either 0 or 1. * * @see input_report() for more details. */ static inline int input_report_key(const struct device *dev, uint16_t code, int32_t value, bool sync, k_timeout_t timeout) { return input_report(dev, INPUT_EV_KEY, code, !!value, sync, timeout); } /** * @brief Report a new @ref INPUT_EV_REL input event. * * @see input_report() for more details. */ static inline int input_report_rel(const struct device *dev, uint16_t code, int32_t value, bool sync, k_timeout_t timeout) { return input_report(dev, INPUT_EV_REL, code, value, sync, timeout); } /** * @brief Report a new @ref INPUT_EV_ABS input event. * * @see input_report() for more details. */ static inline int input_report_abs(const struct device *dev, uint16_t code, int32_t value, bool sync, k_timeout_t timeout) { return input_report(dev, INPUT_EV_ABS, code, value, sync, timeout); } /** * @brief Returns true if the input queue is empty. * * This can be used to batch input event processing until the whole queue has * been emptied. Always returns true if @kconfig{CONFIG_INPUT_MODE_SYNCHRONOUS} * is enabled. */ bool input_queue_empty(void); /** * @brief Input callback structure. */ struct input_callback { /** @ref device pointer or NULL. */ const struct device *dev; /** The callback function. */ void (*callback)(struct input_event *evt, void *user_data); /** User data pointer. */ void *user_data; }; /** * @brief Register a callback structure for input events with a custom name. * * Same as @ref INPUT_CALLBACK_DEFINE but allows specifying a custom name * for the callback structure. Useful if multiple callbacks are used for the * same callback function. */ #define INPUT_CALLBACK_DEFINE_NAMED(_dev, _callback, _user_data, name) \ static const STRUCT_SECTION_ITERABLE(input_callback, name) = { \ .dev = _dev, \ .callback = _callback, \ .user_data = _user_data, \ } /** * @brief Register a callback structure for input events. * * The @p _dev field can be used to only invoke callback for events generated * by a specific device. Setting dev to NULL causes callback to be invoked for * every event. * * @param _dev @ref device pointer or NULL. * @param _callback The callback function. * @param _user_data Pointer to user specified data. */ #define INPUT_CALLBACK_DEFINE(_dev, _callback, _user_data) \ INPUT_CALLBACK_DEFINE_NAMED(_dev, _callback, _user_data, \ _input_callback__##_callback) #ifdef __cplusplus } #endif /** @} */ #endif /* ZEPHYR_INCLUDE_INPUT_H_ */ ```
/content/code_sandbox/include/zephyr/input/input.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,151
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_SETTINGS_SETTINGS_H_ #define ZEPHYR_INCLUDE_SETTINGS_SETTINGS_H_ #include <sys/types.h> #include <zephyr/sys/util.h> #include <zephyr/sys/slist.h> #include <zephyr/sys/iterable_sections.h> #include <stdint.h> #ifdef __cplusplus extern "C" { #endif /** * @defgroup file_system_storage File System Storage * @ingroup os_services * @{ * @} */ /** * @defgroup settings Settings * @since 1.12 * @version 1.0.0 * @ingroup file_system_storage * @{ */ #define SETTINGS_MAX_DIR_DEPTH 8 /* max depth of settings tree */ #define SETTINGS_MAX_NAME_LEN (8 * SETTINGS_MAX_DIR_DEPTH) #define SETTINGS_MAX_VAL_LEN 256 #define SETTINGS_NAME_SEPARATOR '/' #define SETTINGS_NAME_END '=' /* place for settings additions: * up to 7 separators, '=', '\0' */ #define SETTINGS_EXTRA_LEN ((SETTINGS_MAX_DIR_DEPTH - 1) + 2) /** * Function used to read the data from the settings storage in * h_set handler implementations. * * @param[in] cb_arg arguments for the read function. Appropriate cb_arg is * transferred to h_set handler implementation by * the backend. * @param[out] data the destination buffer * @param[in] len length of read * * @return positive: Number of bytes read, 0: key-value pair is deleted. * On error returns -ERRNO code. */ typedef ssize_t (*settings_read_cb)(void *cb_arg, void *data, size_t len); /** * @struct settings_handler * Config handlers for subtree implement a set of handler functions. * These are registered using a call to @ref settings_register. */ struct settings_handler { const char *name; /**< Name of subtree. */ int (*h_get)(const char *key, char *val, int val_len_max); /**< Get values handler of settings items identified by keyword names. * * Parameters: * - key[in] the name with skipped part that was used as name in * handler registration * - val[out] buffer to receive value. * - val_len_max[in] size of that buffer. * * Return: length of data read on success, negative on failure. */ int (*h_set)(const char *key, size_t len, settings_read_cb read_cb, void *cb_arg); /**< Set value handler of settings items identified by keyword names. * * Parameters: * - key[in] the name with skipped part that was used as name in * handler registration * - len[in] the size of the data found in the backend. * - read_cb[in] function provided to read the data from the backend. * - cb_arg[in] arguments for the read function provided by the * backend. * * Return: 0 on success, non-zero on failure. */ int (*h_commit)(void); /**< This handler gets called after settings has been loaded in full. * User might use it to apply setting to the application. * * Return: 0 on success, non-zero on failure. */ int (*h_export)(int (*export_func)(const char *name, const void *val, size_t val_len)); /**< This gets called to dump all current settings items. * * This happens when @ref settings_save tries to save the settings. * Parameters: * - export_func: the pointer to the internal function which appends * a single key-value pair to persisted settings. Don't store * duplicated value. The name is subtree/key string, val is the string * with value. * * @remarks The User might limit a implementations of handler to serving * only one keyword at one call - what will impose limit to get/set * values using full subtree/key name. * * Return: 0 on success, non-zero on failure. */ sys_snode_t node; /**< Linked list node info for module internal usage. */ }; /** * @struct settings_handler_static * Config handlers without the node element, used for static handlers. * These are registered using a call to SETTINGS_STATIC_HANDLER_DEFINE(). */ struct settings_handler_static { const char *name; /**< Name of subtree. */ int (*h_get)(const char *key, char *val, int val_len_max); /**< Get values handler of settings items identified by keyword names. * * Parameters: * - key[in] the name with skipped part that was used as name in * handler registration * - val[out] buffer to receive value. * - val_len_max[in] size of that buffer. * * Return: length of data read on success, negative on failure. */ int (*h_set)(const char *key, size_t len, settings_read_cb read_cb, void *cb_arg); /**< Set value handler of settings items identified by keyword names. * * Parameters: * - key[in] the name with skipped part that was used as name in * handler registration * - len[in] the size of the data found in the backend. * - read_cb[in] function provided to read the data from the backend. * - cb_arg[in] arguments for the read function provided by the * backend. * * Return: 0 on success, non-zero on failure. */ int (*h_commit)(void); /**< This handler gets called after settings has been loaded in full. * User might use it to apply setting to the application. */ int (*h_export)(int (*export_func)(const char *name, const void *val, size_t val_len)); /**< This gets called to dump all current settings items. * * This happens when @ref settings_save tries to save the settings. * Parameters: * - export_func: the pointer to the internal function which appends * a single key-value pair to persisted settings. Don't store * duplicated value. The name is subtree/key string, val is the string * with value. * * @remarks The User might limit a implementations of handler to serving * only one keyword at one call - what will impose limit to get/set * values using full subtree/key name. * * Return: 0 on success, non-zero on failure. */ }; /** * Define a static handler for settings items * * @param _hname handler name * @param _tree subtree name * @param _get get routine (can be NULL) * @param _set set routine (can be NULL) * @param _commit commit routine (can be NULL) * @param _export export routine (can be NULL) * * This creates a variable _hname prepended by settings_handler_. * */ #define SETTINGS_STATIC_HANDLER_DEFINE(_hname, _tree, _get, _set, _commit, \ _export) \ const STRUCT_SECTION_ITERABLE(settings_handler_static, \ settings_handler_ ## _hname) = { \ .name = _tree, \ .h_get = _get, \ .h_set = _set, \ .h_commit = _commit, \ .h_export = _export, \ } /** * Initialization of settings and backend * * Can be called at application startup. * In case the backend is a FS Remember to call it after the FS was mounted. * For FCB backend it can be called without such a restriction. * * @return 0 on success, non-zero on failure. */ int settings_subsys_init(void); /** * Register a handler for settings items stored in RAM. * * @param cf Structure containing registration info. * * @return 0 on success, non-zero on failure. */ int settings_register(struct settings_handler *cf); /** * Load serialized items from registered persistence sources. Handlers for * serialized item subtrees registered earlier will be called for encountered * values. * * @return 0 on success, non-zero on failure. */ int settings_load(void); /** * Load limited set of serialized items from registered persistence sources. * Handlers for serialized item subtrees registered earlier will be called for * encountered values that belong to the subtree. * * @param[in] subtree name of the subtree to be loaded. * @return 0 on success, non-zero on failure. */ int settings_load_subtree(const char *subtree); /** * Callback function used for direct loading. * Used by @ref settings_load_subtree_direct function. * * @param[in] key the name with skipped part that was used as name in * handler registration * @param[in] len the size of the data found in the backend. * @param[in] read_cb function provided to read the data from the backend. * @param[in,out] cb_arg arguments for the read function provided by the * backend. * @param[in,out] param parameter given to the * @ref settings_load_subtree_direct function. * * @return When nonzero value is returned, further subtree searching is stopped. */ typedef int (*settings_load_direct_cb)( const char *key, size_t len, settings_read_cb read_cb, void *cb_arg, void *param); /** * Load limited set of serialized items using given callback. * * This function bypasses the normal data workflow in settings module. * All the settings values that are found are passed to the given callback. * * @note * This function does not call commit function. * It works as a blocking function, so it is up to the user to call * any kind of commit function when this operation ends. * * @param[in] subtree subtree name of the subtree to be loaded. * @param[in] cb pointer to the callback function. * @param[in,out] param parameter to be passed when callback * function is called. * @return 0 on success, non-zero on failure. */ int settings_load_subtree_direct( const char *subtree, settings_load_direct_cb cb, void *param); /** * Save currently running serialized items. All serialized items which are * different from currently persisted values will be saved. * * @return 0 on success, non-zero on failure. */ int settings_save(void); /** * Save limited set of currently running serialized items. All serialized items * that belong to subtree and which are different from currently persisted * values will be saved. * * @param[in] subtree name of the subtree to be loaded. * @return 0 on success, non-zero on failure. */ int settings_save_subtree(const char *subtree); /** * Write a single serialized value to persisted storage (if it has * changed value). * * @param name Name/key of the settings item. * @param value Pointer to the value of the settings item. This value will * be transferred to the @ref settings_handler::h_export handler implementation. * @param val_len Length of the value. * * @return 0 on success, non-zero on failure. */ int settings_save_one(const char *name, const void *value, size_t val_len); /** * Delete a single serialized in persisted storage. * * Deleting an existing key-value pair in the settings mean * to set its value to NULL. * * @param name Name/key of the settings item. * * @return 0 on success, non-zero on failure. */ int settings_delete(const char *name); /** * Call commit for all settings handler. This should apply all * settings which has been set, but not applied yet. * * @return 0 on success, non-zero on failure. */ int settings_commit(void); /** * Call commit for settings handler that belong to subtree. * This should apply all settings which has been set, but not applied yet. * * @param[in] subtree name of the subtree to be committed. * * @return 0 on success, non-zero on failure. */ int settings_commit_subtree(const char *subtree); /** * @} settings */ /** * @defgroup settings_backend Settings backend interface * @ingroup settings * @{ */ /* * API for config storage */ struct settings_store_itf; /** * Backend handler node for storage handling. */ struct settings_store { sys_snode_t cs_next; /**< Linked list node info for internal usage. */ const struct settings_store_itf *cs_itf; /**< Backend handler structure. */ }; /** * Arguments for data loading. * Holds all parameters that changes the way data should be loaded from backend. */ struct settings_load_arg { /** * @brief Name of the subtree to be loaded * * If NULL, all values would be loaded. */ const char *subtree; /** * @brief Pointer to the callback function. * * If NULL then matching registered function would be used. */ settings_load_direct_cb cb; /** * @brief Parameter for callback function * * Parameter to be passed to the callback function. */ void *param; }; /** * Backend handler functions. * Sources are registered using a call to @ref settings_src_register. * Destinations are registered using a call to @ref settings_dst_register. */ struct settings_store_itf { int (*csi_load)(struct settings_store *cs, const struct settings_load_arg *arg); /**< Loads values from storage limited to subtree defined by subtree. * * Parameters: * - cs - Corresponding backend handler node, * - arg - Structure that holds additional data for data loading. * * @note * Backend is expected not to provide duplicates of the entities. * It means that if the backend does not contain any functionality to * really delete old keys, it has to filter out old entities and call * load callback only on the final entity. */ int (*csi_save_start)(struct settings_store *cs); /**< Handler called before an export operation. * * Parameters: * - cs - Corresponding backend handler node */ int (*csi_save)(struct settings_store *cs, const char *name, const char *value, size_t val_len); /**< Save a single key-value pair to storage. * * Parameters: * - cs - Corresponding backend handler node * - name - Key in string format * - value - Binary value * - val_len - Length of value in bytes. */ int (*csi_save_end)(struct settings_store *cs); /**< Handler called after an export operation. * * Parameters: * - cs - Corresponding backend handler node */ /**< Get pointer to the storage instance used by the backend. * * Parameters: * - cs - Corresponding backend handler node */ void *(*csi_storage_get)(struct settings_store *cs); }; /** * Register a backend handler acting as source. * * @param cs Backend handler node containing handler information. * */ void settings_src_register(struct settings_store *cs); /** * Register a backend handler acting as destination. * * @param cs Backend handler node containing handler information. * */ void settings_dst_register(struct settings_store *cs); /* * API for handler lookup */ /** * Parses a key to an array of elements and locate corresponding module handler. * * @param[in] name in string format * @param[out] next remaining of name after matched handler * * @return settings_handler_static on success, NULL on failure. */ struct settings_handler_static *settings_parse_and_lookup(const char *name, const char **next); /** * Calls settings handler. * * @param[in] name The name of the data found in the backend. * @param[in] len The size of the data found in the backend. * @param[in] read_cb Function provided to read the data from * the backend. * @param[in,out] read_cb_arg Arguments for the read function provided by * the backend. * @param[in,out] load_arg Arguments for data loading. * * @return 0 or negative error code */ int settings_call_set_handler(const char *name, size_t len, settings_read_cb read_cb, void *read_cb_arg, const struct settings_load_arg *load_arg); /** * @} */ /** * @defgroup settings_name_proc Settings name processing * @brief API for const name processing * @ingroup settings * @{ */ /** * Compares the start of name with a key * * @param[in] name in string format * @param[in] key comparison string * @param[out] next pointer to remaining of name, when the remaining part * starts with a separator the separator is removed from next * * Some examples: * settings_name_steq("bt/btmesh/iv", "b", &next) returns 1, next="t/btmesh/iv" * settings_name_steq("bt/btmesh/iv", "bt", &next) returns 1, next="btmesh/iv" * settings_name_steq("bt/btmesh/iv", "bt/", &next) returns 0, next=NULL * settings_name_steq("bt/btmesh/iv", "bta", &next) returns 0, next=NULL * * REMARK: This routine could be simplified if the settings_handler names * would include a separator at the end. * * @return 0: no match * 1: match, next can be used to check if match is full */ int settings_name_steq(const char *name, const char *key, const char **next); /** * determine the number of characters before the first separator * * @param[in] name in string format * @param[out] next pointer to remaining of name (excluding separator) * * @return index of the first separator, in case no separator was found this * is the size of name * */ int settings_name_next(const char *name, const char **next); /** * @} */ #ifdef CONFIG_SETTINGS_RUNTIME /** * @defgroup settings_rt Settings subsystem runtime * @brief API for runtime settings * @ingroup settings * @{ */ /** * Set a value with a specific key to a module handler. * * @param name Key in string format. * @param data Binary value. * @param len Value length in bytes. * * @return 0 on success, non-zero on failure. */ int settings_runtime_set(const char *name, const void *data, size_t len); /** * Get a value corresponding to a key from a module handler. * * @param name Key in string format. * @param data Returned binary value. * @param len requested value length in bytes. * * @return length of data read on success, negative on failure. */ int settings_runtime_get(const char *name, void *data, size_t len); /** * Apply settings in a module handler. * * @param name Key in string format. * * @return 0 on success, non-zero on failure. */ int settings_runtime_commit(const char *name); /** * @} */ #endif /* CONFIG_SETTINGS_RUNTIME */ /** * Get the storage instance used by zephyr. * * The type of storage object instance depends on the settings backend used. * It might pointer to: `struct nvs_fs`, `struct fcb` or string witch file name * depends on settings backend type used. * * @retval Pointer to which reference to the storage object can be stored. * * @retval 0 on success, negative error code on failure. */ int settings_storage_get(void **storage); #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_SETTINGS_SETTINGS_H_ */ ```
/content/code_sandbox/include/zephyr/settings/settings.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
4,257
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_INPUT_INPUT_KEYMAP_H_ #define ZEPHYR_INCLUDE_INPUT_INPUT_KEYMAP_H_ #define MATRIX_ROW(keymap_entry) (((keymap_entry) >> 24) & 0xff) #define MATRIX_COL(keymap_entry) (((keymap_entry) >> 16) & 0xff) #endif /* ZEPHYR_INCLUDE_INPUT_INPUT_KEYMAP_H_ */ ```
/content/code_sandbox/include/zephyr/input/input_keymap.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
84
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_INPUT_ANALOG_AXIS_SETTINGS_H_ #define ZEPHYR_INCLUDE_INPUT_ANALOG_AXIS_SETTINGS_H_ #include <stdint.h> #include <zephyr/device.h> /** * @addtogroup input_analog_axis * @{ */ /** * @brief Save the calibration data. * * Save the calibration data permanently on the specifided device, requires * the @ref settings subsystem to be configured and initialized. * * @param dev Analog axis device. * * @retval 0 If successful. * @retval -errno In case of any other error. */ int analog_axis_calibration_save(const struct device *dev); /** @} */ #endif /* ZEPHYR_INCLUDE_INPUT_ANALOG_AXIS_SETTINGS_H_ */ ```
/content/code_sandbox/include/zephyr/input/input_analog_axis_settings.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
152
```objective-c /* * */ #ifndef ZEPHYR_INCLUDE_INPUT_KBD_MATRIX_H_ #define ZEPHYR_INCLUDE_INPUT_KBD_MATRIX_H_ /** * @brief Keyboard Matrix API * @defgroup input_kbd_matrix Keyboard Matrix API * @ingroup io_interfaces * @{ */ #include <zephyr/device.h> #include <zephyr/kernel.h> #include <zephyr/sys/util.h> #include <zephyr/sys_clock.h> #include <zephyr/toolchain.h> /** Special drive_column argument for not driving any column */ #define INPUT_KBD_MATRIX_COLUMN_DRIVE_NONE -1 /** Special drive_column argument for driving all the columns */ #define INPUT_KBD_MATRIX_COLUMN_DRIVE_ALL -2 /** Number of tracked scan cycles */ #define INPUT_KBD_MATRIX_SCAN_OCURRENCES 30U /** Row entry data type */ #if CONFIG_INPUT_KBD_MATRIX_16_BIT_ROW typedef uint16_t kbd_row_t; #define PRIkbdrow "04" PRIx16 #else typedef uint8_t kbd_row_t; #define PRIkbdrow "02" PRIx8 #endif #if defined(CONFIG_INPUT_KBD_ACTUAL_KEY_MASK_DYNAMIC) || defined(__DOXYGEN__) #define INPUT_KBD_ACTUAL_KEY_MASK_CONST /** * @brief Enables or disables a specific row, column combination in the actual * key mask. * * This allows enabling or disabling specific row, column combination in the * actual key mask in runtime. It can be useful if some of the keys are not * present in some configuration, and the specific configuration is determined * in runtime. Requires @kconfig{CONFIG_INPUT_KBD_ACTUAL_KEY_MASK_DYNAMIC} to * be enabled. * * @param dev Pointer to the keyboard matrix device. * @param row The matrix row to enable or disable. * @param col The matrix column to enable or disable. * @param enabled Whether the specified row, col has to be enabled or disabled. * * @retval 0 If the change is successful. * @retval -errno Negative errno if row or col are out of range for the device. */ int input_kbd_matrix_actual_key_mask_set(const struct device *dev, uint8_t row, uint8_t col, bool enabled); #else #define INPUT_KBD_ACTUAL_KEY_MASK_CONST const #endif /** Maximum number of rows */ #define INPUT_KBD_MATRIX_ROW_BITS NUM_BITS(kbd_row_t) /** * @brief Keyboard matrix internal APIs. */ struct input_kbd_matrix_api { /** * @brief Request to drive a specific column. * * Request to drive a specific matrix column, or none, or all. * * @param dev Pointer to the keyboard matrix device. * @param col The column to drive, or * @ref INPUT_KBD_MATRIX_COLUMN_DRIVE_NONE or * @ref INPUT_KBD_MATRIX_COLUMN_DRIVE_ALL. */ void (*drive_column)(const struct device *dev, int col); /** * @brief Read the matrix row. * * @param dev Pointer to the keyboard matrix device. */ kbd_row_t (*read_row)(const struct device *dev); /** * @brief Request to put the matrix in detection mode. * * Request to put the driver in detection mode, this is called after a * request to drive all the column and typically involves reenabling * interrupts row pin changes. * * @param dev Pointer to the keyboard matrix device. * @param enable Whether detection mode has to be enabled or disabled. */ void (*set_detect_mode)(const struct device *dev, bool enabled); }; /** * @brief Common keyboard matrix config. * * This structure **must** be placed first in the driver's config structure. */ struct input_kbd_matrix_common_config { const struct input_kbd_matrix_api *api; uint8_t row_size; uint8_t col_size; uint32_t poll_period_us; uint32_t poll_timeout_ms; uint32_t debounce_down_us; uint32_t debounce_up_us; uint32_t settle_time_us; bool ghostkey_check; INPUT_KBD_ACTUAL_KEY_MASK_CONST kbd_row_t *actual_key_mask; /* extra data pointers */ kbd_row_t *matrix_stable_state; kbd_row_t *matrix_unstable_state; kbd_row_t *matrix_previous_state; kbd_row_t *matrix_new_state; uint8_t *scan_cycle_idx; }; #define INPUT_KBD_MATRIX_DATA_NAME(node_id, name) \ _CONCAT(__input_kbd_matrix_, \ _CONCAT(name, DEVICE_DT_NAME_GET(node_id))) /** * @brief Defines the common keyboard matrix support data from devicetree, * specify row and col count. */ #define INPUT_KBD_MATRIX_DT_DEFINE_ROW_COL(node_id, _row_size, _col_size) \ BUILD_ASSERT(IN_RANGE(_row_size, 1, INPUT_KBD_MATRIX_ROW_BITS), "invalid row-size"); \ BUILD_ASSERT(IN_RANGE(_col_size, 1, UINT8_MAX), "invalid col-size"); \ IF_ENABLED(DT_NODE_HAS_PROP(node_id, actual_key_mask), ( \ BUILD_ASSERT(DT_PROP_LEN(node_id, actual_key_mask) == _col_size, \ "actual-key-mask size does not match the number of columns"); \ static INPUT_KBD_ACTUAL_KEY_MASK_CONST kbd_row_t \ INPUT_KBD_MATRIX_DATA_NAME(node_id, actual_key_mask)[_col_size] = \ DT_PROP(node_id, actual_key_mask); \ )) \ static kbd_row_t INPUT_KBD_MATRIX_DATA_NAME(node_id, stable_state)[_col_size]; \ static kbd_row_t INPUT_KBD_MATRIX_DATA_NAME(node_id, unstable_state)[_col_size]; \ static kbd_row_t INPUT_KBD_MATRIX_DATA_NAME(node_id, previous_state)[_col_size]; \ static kbd_row_t INPUT_KBD_MATRIX_DATA_NAME(node_id, new_state)[_col_size]; \ static uint8_t INPUT_KBD_MATRIX_DATA_NAME(node_id, scan_cycle_idx)[_row_size * _col_size]; /** * @brief Defines the common keyboard matrix support data from devicetree. */ #define INPUT_KBD_MATRIX_DT_DEFINE(node_id) \ INPUT_KBD_MATRIX_DT_DEFINE_ROW_COL( \ node_id, DT_PROP(node_id, row_size), DT_PROP(node_id, col_size)) /** * @brief Defines the common keyboard matrix support data from devicetree * instance, specify row and col count. * * @param inst Instance. * @param row_size The matrix row count. * @param col_size The matrix column count. */ #define INPUT_KBD_MATRIX_DT_INST_DEFINE_ROW_COL(inst, row_size, col_size) \ INPUT_KBD_MATRIX_DT_DEFINE_ROW_COL(DT_DRV_INST(inst), row_size, col_size) /** * @brief Defines the common keyboard matrix support data from devicetree instance. * * @param inst Instance. */ #define INPUT_KBD_MATRIX_DT_INST_DEFINE(inst) \ INPUT_KBD_MATRIX_DT_DEFINE(DT_DRV_INST(inst)) /** * @brief Initialize common keyboard matrix config from devicetree, specify row and col count. * * @param node_id The devicetree node identifier. * @param _api Pointer to a @ref input_kbd_matrix_api structure. * @param _row_size The matrix row count. * @param _col_size The matrix column count. */ #define INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT_ROW_COL(node_id, _api, _row_size, _col_size) \ { \ .api = _api, \ .row_size = _row_size, \ .col_size = _col_size, \ .poll_period_us = DT_PROP(node_id, poll_period_ms) * USEC_PER_MSEC, \ .poll_timeout_ms = DT_PROP(node_id, poll_timeout_ms), \ .debounce_down_us = DT_PROP(node_id, debounce_down_ms) * USEC_PER_MSEC, \ .debounce_up_us = DT_PROP(node_id, debounce_up_ms) * USEC_PER_MSEC, \ .settle_time_us = DT_PROP(node_id, settle_time_us), \ .ghostkey_check = !DT_PROP(node_id, no_ghostkey_check), \ IF_ENABLED(DT_NODE_HAS_PROP(node_id, actual_key_mask), ( \ .actual_key_mask = INPUT_KBD_MATRIX_DATA_NAME(node_id, actual_key_mask), \ )) \ \ .matrix_stable_state = INPUT_KBD_MATRIX_DATA_NAME(node_id, stable_state), \ .matrix_unstable_state = INPUT_KBD_MATRIX_DATA_NAME(node_id, unstable_state), \ .matrix_previous_state = INPUT_KBD_MATRIX_DATA_NAME(node_id, previous_state), \ .matrix_new_state = INPUT_KBD_MATRIX_DATA_NAME(node_id, new_state), \ .scan_cycle_idx = INPUT_KBD_MATRIX_DATA_NAME(node_id, scan_cycle_idx), \ } /** * @brief Initialize common keyboard matrix config from devicetree. * * @param node_id The devicetree node identifier. * @param api Pointer to a @ref input_kbd_matrix_api structure. */ #define INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT(node_id, api) \ INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT_ROW_COL( \ node_id, api, DT_PROP(node_id, row_size), DT_PROP(node_id, col_size)) /** * @brief Initialize common keyboard matrix config from devicetree instance, * specify row and col count. * * @param inst Instance. * @param api Pointer to a @ref input_kbd_matrix_api structure. * @param row_size The matrix row count. * @param col_size The matrix column count. */ #define INPUT_KBD_MATRIX_DT_INST_COMMON_CONFIG_INIT_ROW_COL(inst, api, row_size, col_size) \ INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT_ROW_COL(DT_DRV_INST(inst), api, row_size, col_size) /** * @brief Initialize common keyboard matrix config from devicetree instance. * * @param inst Instance. * @param api Pointer to a @ref input_kbd_matrix_api structure. */ #define INPUT_KBD_MATRIX_DT_INST_COMMON_CONFIG_INIT(inst, api) \ INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT(DT_DRV_INST(inst), api) /** * @brief Common keyboard matrix data. * * This structure **must** be placed first in the driver's data structure. */ struct input_kbd_matrix_common_data { /* Track previous cycles, used for debouncing. */ uint32_t scan_clk_cycle[INPUT_KBD_MATRIX_SCAN_OCURRENCES]; uint8_t scan_cycles_idx; struct k_sem poll_lock; struct k_thread thread; K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_INPUT_KBD_MATRIX_THREAD_STACK_SIZE); }; /** * @brief Validate the offset of the common data structures. * * @param config Name of the config structure. * @param data Name of the data structure. */ #define INPUT_KBD_STRUCT_CHECK(config, data) \ BUILD_ASSERT(offsetof(config, common) == 0, \ "struct input_kbd_matrix_common_config must be placed first"); \ BUILD_ASSERT(offsetof(data, common) == 0, \ "struct input_kbd_matrix_common_data must be placed first") /** * @brief Start scanning the keyboard matrix * * Starts the keyboard matrix scanning cycle, this should be called in reaction * of a press event, after the device has been put in detect mode. * * @param dev Keyboard matrix device instance. */ void input_kbd_matrix_poll_start(const struct device *dev); #if defined(CONFIG_INPUT_KBD_DRIVE_COLUMN_HOOK) || defined(__DOXYGEN__) /** * @brief Drive column hook * * This can be implemented by the application to handle column selection * quirks. Called after the driver specific drive_column function. Requires * @kconfig{CONFIG_INPUT_KBD_DRIVE_COLUMN_HOOK} to be enabled. * * @param dev Keyboard matrix device instance. * @param col The column to drive, or * @ref INPUT_KBD_MATRIX_COLUMN_DRIVE_NONE or * @ref INPUT_KBD_MATRIX_COLUMN_DRIVE_ALL. */ void input_kbd_matrix_drive_column_hook(const struct device *dev, int col); #endif /** * @brief Common function to initialize a keyboard matrix device at init time. * * This function must be called at the end of the device init function. * * @param dev Keyboard matrix device instance. * * @retval 0 If initialized successfully. * @retval -errno Negative errno in case of failure. */ int input_kbd_matrix_common_init(const struct device *dev); /** @} */ #endif /* ZEPHYR_INCLUDE_INPUT_KBD_MATRIX_H_ */ ```
/content/code_sandbox/include/zephyr/input/input_kbd_matrix.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
2,658