diff options
Diffstat (limited to 'cpukit/dev')
-rw-r--r-- | cpukit/dev/flash/flashdev.c | 931 | ||||
-rw-r--r-- | cpukit/dev/i2c/eeprom.c | 8 | ||||
-rw-r--r-- | cpukit/dev/i2c/gpio-nxp-pca9535.c | 8 | ||||
-rw-r--r-- | cpukit/dev/i2c/i2c-bus.c | 53 | ||||
-rw-r--r-- | cpukit/dev/i2c/i2c-dev.c | 8 | ||||
-rw-r--r-- | cpukit/dev/i2c/sensor-lm75a.c | 8 | ||||
-rw-r--r-- | cpukit/dev/i2c/switch-nxp-pca9548a.c | 8 | ||||
-rw-r--r-- | cpukit/dev/ioprintf.c | 53 | ||||
-rw-r--r-- | cpukit/dev/iorelax.c | 53 | ||||
-rw-r--r-- | cpukit/dev/iovprintf.c | 377 | ||||
-rw-r--r-- | cpukit/dev/serial/sc16is752-regs.h | 8 | ||||
-rw-r--r-- | cpukit/dev/serial/sc16is752-spi.c | 8 | ||||
-rw-r--r-- | cpukit/dev/serial/sc16is752.c | 8 | ||||
-rw-r--r-- | cpukit/dev/spi/spi-bus.c | 8 |
14 files changed, 1464 insertions, 75 deletions
diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c new file mode 100644 index 0000000000..f39f8dde4d --- /dev/null +++ b/cpukit/dev/flash/flashdev.c @@ -0,0 +1,931 @@ +/* + * Copyright (C) 2023 Aaron Nyholm + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <dev/flash/flashdev.h> + +#include <rtems/imfs.h> +#include <rtems/score/assert.h> + +#include <errno.h> +#include <fcntl.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <assert.h> + +#define RTEMS_FLASHDEV_REGION_ALLOC_FULL 0xFFFFFFFFUL +#define RTEMS_FLASHDEV_REGION_UNDEFINED 0xFFFFFFFFUL +#define RTEMS_FLASHDEV_REGION_BITALLOC_LENGTH 32 + +#define RTEMS_FLASHDEV_BITALLOC_LENGTH(t) \ + (t->max_regions/RTEMS_FLASHDEV_REGION_BITALLOC_LENGTH) +#define RTEMS_FLASHDEV_BITALLOC_FINAL_BITS(t) \ + (t->max_regions%RTEMS_FLASHDEV_REGION_BITALLOC_LENGTH) + +static int rtems_flashdev_do_init( + rtems_flashdev *flash, + void ( *destroy )( rtems_flashdev *flash ) +); + +static int rtems_flashdev_read_write( + rtems_libio_t *iop, + const void *write_buff, + void *read_buff, + size_t count +); + +static int rtems_flashdev_ioctl_erase( + rtems_flashdev *flash, + rtems_libio_t *iop, + void *arg +); + +static off_t rtems_flashdev_get_region_offset( + rtems_flashdev *flash, + rtems_libio_t *iop +); + +static size_t rtems_flashdev_get_region_size( + rtems_flashdev *flash, + rtems_libio_t *iop +); + +static int rtems_flashdev_ioctl_set_region( + rtems_flashdev *flash, + rtems_libio_t *iop, + void *arg +); + +static int rtems_flashdev_ioctl_create_region( + rtems_flashdev *flash, + rtems_libio_t *iop, + rtems_flashdev_region *region_in +); + +static int rtems_flashdev_ioctl_update_region( + rtems_flashdev *flash, + rtems_libio_t *iop, + rtems_flashdev_region *region_in +); + +static int rtems_flashdev_ioctl_clear_region( + rtems_flashdev *flash, + rtems_libio_t *iop +); + +static uint32_t rtems_flashdev_ioctl_jedec_id( + rtems_flashdev *flash +); + +static uint32_t rtems_flashdev_ioctl_flash_type( + rtems_flashdev *flash, + void *arg +); + +static int rtems_flashdev_ioctl_pageinfo_offset( + rtems_flashdev *flash, + void *arg +); + +static int rtems_flashdev_ioctl_pageinfo_index( + rtems_flashdev *flash, + void *arg +); + +static int rtems_flashdev_ioctl_page_count( + rtems_flashdev *flash, + void *arg +); + +static int rtems_flashdev_ioctl_write_block_size( + rtems_flashdev *flash, + void *arg +); + +static int rtems_flashdev_get_addr( + rtems_flashdev *flash, + rtems_libio_t *iop, + size_t count, + off_t *addr +); + +static int rtems_flashdev_get_abs_addr( + rtems_flashdev *flash, + rtems_libio_t *iop, + size_t count, + off_t *addr +); + +static int rtems_flashdev_update_and_return( + rtems_libio_t *iop, + int status, + size_t count, + off_t new_offset +); + +static uint32_t rtems_flashdev_find_unallocated_region( + rtems_flashdev_region_table *region_table +); + +static uint32_t rtems_flashdev_set_region( + rtems_flashdev_region_table *region_table, + int index +); + +static uint32_t rtems_flashdev_unset_region( + rtems_flashdev_region_table *region_table, + int index +); + +static uint32_t rtems_flashdev_check_allocation( + rtems_flashdev_region_table *region_table, + int index +); + +static int rtems_flashdev_open( + rtems_libio_t *iop, + const char *path, + int oflag, + mode_t mode +); + +static int rtems_flashdev_close( + rtems_libio_t *iop +); + +static ssize_t rtems_flashdev_read( + rtems_libio_t *iop, + void *buffer, + size_t count +); + +static ssize_t rtems_flashdev_write( + rtems_libio_t *iop, + const void *buffer, + size_t count +); + +static int rtems_flashdev_ioctl( + rtems_libio_t *iop, + ioctl_command_t command, + void *arg +); + +static off_t rtems_flashdev_lseek( + rtems_libio_t *iop, + off_t offset, + int whence +); + +static void rtems_flashdev_node_destroy( + IMFS_jnode_t *node +); + +static const rtems_filesystem_file_handlers_r rtems_flashdev_handler = { + .open_h = rtems_flashdev_open, + .close_h = rtems_flashdev_close, + .read_h = rtems_flashdev_read, + .write_h = rtems_flashdev_write, + .ioctl_h = rtems_flashdev_ioctl, + .lseek_h = rtems_flashdev_lseek, + .fstat_h = IMFS_stat, + .ftruncate_h = rtems_filesystem_default_ftruncate, + .fsync_h = rtems_filesystem_default_fsync_or_fdatasync, + .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync, + .fcntl_h = rtems_filesystem_default_fcntl, + .kqfilter_h = rtems_filesystem_default_kqfilter, + .mmap_h = rtems_filesystem_default_mmap, + .poll_h = rtems_filesystem_default_poll, + .readv_h = rtems_filesystem_default_readv, + .writev_h = rtems_filesystem_default_writev }; + +static const IMFS_node_control + rtems_flashdev_node_control = IMFS_GENERIC_INITIALIZER( + &rtems_flashdev_handler, + IMFS_node_initialize_generic, + rtems_flashdev_node_destroy +); + +static void rtems_flashdev_node_destroy( + IMFS_jnode_t *node +) +{ + rtems_flashdev *flash; + + flash = IMFS_generic_get_context_by_node( node ); + + ( *flash->destroy )( flash ); + + IMFS_node_destroy_default( node ); +} + +static uint32_t rtems_flashdev_get_region_index( + rtems_libio_t *iop +) +{ + return (uint32_t)iop->data0; +} + +static int rtems_flashdev_is_region_defined( + rtems_libio_t *iop +) +{ + return (rtems_flashdev_get_region_index( iop ) != RTEMS_FLASHDEV_REGION_UNDEFINED); +} + +static void rtems_flashdev_set_region_index( + rtems_libio_t *iop, + uint32_t index +) +{ + iop->data0 = index; +} + +static int rtems_flashdev_check_offset_region( + rtems_flashdev *flash, + rtems_libio_t *iop, + off_t offset +) +{ + if ( ( rtems_flashdev_is_region_defined( iop ) ) && + ( offset > rtems_flashdev_get_region_size( flash, iop ) ) ) { + rtems_set_errno_and_return_minus_one( EINVAL ); + } + return 0; +} + +static void rtems_flashdev_obtain( rtems_flashdev *flash ) +{ + rtems_recursive_mutex_lock( &flash->mutex ); +} + +static void rtems_flashdev_release( rtems_flashdev *flash ) +{ + rtems_recursive_mutex_unlock( &flash->mutex ); +} + +static ssize_t rtems_flashdev_read( + rtems_libio_t *iop, + void *buffer, + size_t count +) +{ + return rtems_flashdev_read_write( iop, NULL, buffer, count ); +} + +static ssize_t rtems_flashdev_write( + rtems_libio_t *iop, + const void *buffer, + size_t count +) +{ + return rtems_flashdev_read_write( iop, buffer, NULL, count); +} + +static int rtems_flashdev_read_write( + rtems_libio_t *iop, + const void *write_buff, + void *read_buff, + size_t count +) +{ + rtems_flashdev *flash = IMFS_generic_get_context_by_iop( iop ); + off_t addr; + int status; + + if ( read_buff == NULL && write_buff == NULL ) { + rtems_set_errno_and_return_minus_one( EINVAL ); + } + + /* Get flash address */ + status = rtems_flashdev_get_addr( flash, iop, count, &addr ); + if ( status < 0 ) { + return status; + } + + /* Read or Write to flash */ + rtems_flashdev_obtain( flash ); + if ( read_buff != NULL ) { + status = ( *flash->read )( flash, addr, count, read_buff ); + } else if ( write_buff != NULL ) { + status = ( *flash->write )( flash, addr, count, write_buff ); + } + rtems_flashdev_release( flash ); + + /* Update offset and return */ + return rtems_flashdev_update_and_return( iop, status, count, addr + count ); +} + +static int rtems_flashdev_ioctl( + rtems_libio_t *iop, + ioctl_command_t command, + void *arg +) +{ + rtems_flashdev *flash = IMFS_generic_get_context_by_iop( iop ); + int err = 0; + + rtems_flashdev_obtain( flash ); + + switch ( command ) { + case RTEMS_FLASHDEV_IOCTL_OBTAIN: + rtems_flashdev_obtain( flash ); + err = 0; + break; + case RTEMS_FLASHDEV_IOCTL_RELEASE: + rtems_flashdev_release( flash ); + err = 0; + break; + case RTEMS_FLASHDEV_IOCTL_JEDEC_ID: + *( (uint32_t *) arg ) = rtems_flashdev_ioctl_jedec_id( flash ); + err = 0; + break; + case RTEMS_FLASHDEV_IOCTL_ERASE: + err = rtems_flashdev_ioctl_erase( flash, iop, arg ); + break; + case RTEMS_FLASHDEV_IOCTL_REGION_SET: + err = rtems_flashdev_ioctl_set_region( flash, iop, arg ); + break; + case RTEMS_FLASHDEV_IOCTL_REGION_UNSET: + err = rtems_flashdev_ioctl_clear_region( flash, iop ); + break; + case RTEMS_FLASHDEV_IOCTL_TYPE: + err = rtems_flashdev_ioctl_flash_type( flash, arg ); + break; + case RTEMS_FLASHDEV_IOCTL_PAGEINFO_BY_OFFSET: + err = rtems_flashdev_ioctl_pageinfo_offset( flash, arg ); + break; + case RTEMS_FLASHDEV_IOCTL_PAGEINFO_BY_INDEX: + err = rtems_flashdev_ioctl_pageinfo_index( flash, arg ); + break; + case RTEMS_FLASHDEV_IOCTL_PAGE_COUNT: + err = rtems_flashdev_ioctl_page_count( flash, arg ); + break; + case RTEMS_FLASHDEV_IOCTL_WRITE_BLOCK_SIZE: + err = rtems_flashdev_ioctl_write_block_size( flash, arg ); + break; + default: + err = EINVAL; + } + + rtems_flashdev_release( flash ); + if ( err != 0 ) { + rtems_set_errno_and_return_minus_one( err ); + } else { + return 0; + } +} + +static off_t rtems_flashdev_lseek( + rtems_libio_t *iop, + off_t offset, + int whence +) +{ + off_t tmp_offset; + rtems_flashdev *flash = IMFS_generic_get_context_by_iop( iop ); + + if ( offset < 0 ) { + rtems_set_errno_and_return_minus_one( EINVAL ); + } + + switch ( whence ) { + case SEEK_CUR: + tmp_offset = iop->offset + offset; + break; + case SEEK_SET: + tmp_offset = offset; + break; + case SEEK_END: + default: + rtems_set_errno_and_return_minus_one( EINVAL ); + } + + if ( ( rtems_flashdev_is_region_defined(iop) ) && + ( tmp_offset > rtems_flashdev_get_region_size( flash, iop ) ) ) { + rtems_set_errno_and_return_minus_one( EINVAL ); + } + + iop->offset = tmp_offset; + return iop->offset; +} + +static int rtems_flashdev_close( + rtems_libio_t *iop +) +{ + rtems_flashdev *flash = IMFS_generic_get_context_by_iop( iop ); + rtems_flashdev_ioctl_clear_region( flash, iop ); + return rtems_filesystem_default_close( iop ); +} + +static int rtems_flashdev_open( + rtems_libio_t *iop, + const char *path, + int oflag, + mode_t mode +) +{ + int ret = rtems_filesystem_default_open( iop, path, oflag, mode ); + rtems_flashdev_set_region_index(iop, RTEMS_FLASHDEV_REGION_UNDEFINED); + return ret; +} + +int rtems_flashdev_register( + rtems_flashdev *flash, + const char *flash_path +) +{ + int rv; + rtems_flashdev_region_table *table = flash->region_table; + int alloc_array_len; + + rv = IMFS_make_generic_node( + flash_path, + S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, + &rtems_flashdev_node_control, + flash + ); + + if ( rv != 0 ) { + ( *flash->destroy )( flash ); + } + + alloc_array_len = RTEMS_FLASHDEV_BITALLOC_LENGTH(table) + + ((RTEMS_FLASHDEV_BITALLOC_FINAL_BITS(table)) != 0); + + memset(table->bit_allocator, 0, alloc_array_len); + + return rv; +} + +static int rtems_flashdev_do_init( + rtems_flashdev *flash, + void ( *destroy )( rtems_flashdev *flash ) +) +{ + rtems_recursive_mutex_init( &flash->mutex, "RTEMS_FLASHDEV Flash" ); + flash->destroy = destroy; + flash->read = NULL; + flash->write = NULL; + flash->erase = NULL; + flash->jedec_id = NULL; + flash->flash_type = NULL; + flash->page_info_by_offset = NULL; + flash->page_info_by_index = NULL; + flash->page_count = NULL; + flash->write_block_size = NULL; + flash->region_table = NULL; + return 0; +} + +void rtems_flashdev_destroy( rtems_flashdev *flash ) +{ + rtems_recursive_mutex_destroy( &flash->mutex ); +} + +void rtems_flashdev_destroy_and_free( rtems_flashdev *flash ) +{ + if ( flash == NULL ) { + return; + } + rtems_recursive_mutex_destroy( &( flash->mutex ) ); + free( flash ); + flash = NULL; + return; +} + +int rtems_flashdev_init( rtems_flashdev *flash ) +{ + memset( flash, 0, sizeof( *flash ) ); + + return rtems_flashdev_do_init( flash, rtems_flashdev_destroy ); +} + +rtems_flashdev *rtems_flashdev_alloc_and_init( size_t size ) +{ + rtems_flashdev *flash = NULL; + + if ( size >= sizeof( *flash ) ) { + flash = calloc( 1, size ); + if ( flash != NULL ) { + int rv; + + rv = rtems_flashdev_do_init( flash, rtems_flashdev_destroy_and_free ); + if ( rv != 0 ) { + rtems_recursive_mutex_destroy( &flash->mutex ); + free( flash ); + return NULL; + } + } + } + + return flash; +} + +static int rtems_flashdev_get_addr( + rtems_flashdev *flash, + rtems_libio_t *iop, + size_t count, + off_t *addr +) +{ + off_t new_offset; + + /* Check address is in valid region */ + new_offset = iop->offset + count; + + if (rtems_flashdev_check_offset_region(flash, iop, new_offset)) { + return -1; + } + + /* Get address for operation */ + if ( !rtems_flashdev_is_region_defined( iop ) ) { + *addr = iop->offset; + } else { + *addr = ( iop->offset + rtems_flashdev_get_region_offset( flash, iop ) ); + } + return 0; +} + +static int rtems_flashdev_get_abs_addr( + rtems_flashdev *flash, + rtems_libio_t *iop, + size_t count, + off_t *addr +) +{ + off_t new_offset; + + /* Check address is in valid region */ + new_offset = *addr + count; + + if (rtems_flashdev_check_offset_region(flash, iop, new_offset)) { + return -1; + } + + /* Get address for operation */ + if ( rtems_flashdev_is_region_defined( iop ) ) { + *addr = ( *addr + rtems_flashdev_get_region_offset( flash, iop ) ); + } + return 0; +} +static int rtems_flashdev_update_and_return( + rtems_libio_t *iop, + int status, + size_t count, + off_t new_offset +) +{ + /* Update offset and return */ + if ( status == 0 ) { + iop->offset = new_offset; + return count; + } else { + rtems_set_errno_and_return_minus_one( status ); + } +} + +static int rtems_flashdev_ioctl_erase( + rtems_flashdev *flash, + rtems_libio_t *iop, + void *arg +) +{ + rtems_flashdev_region *erase_args_1; + off_t new_offset; + int status; + + if ( flash->erase == NULL ) { + return 0; + } + + erase_args_1 = (rtems_flashdev_region *) arg; + /* Check erasing valid region */ + new_offset = erase_args_1->offset; + status = rtems_flashdev_get_abs_addr(flash, iop, erase_args_1->size, &new_offset); + if ( status < 0 ) { + return status; + } + + /* Erase flash */ + status = ( *flash->erase )( flash, new_offset, erase_args_1->size ); + return status; +} + +static int rtems_flashdev_ioctl_set_region( + rtems_flashdev *flash, + rtems_libio_t *iop, + void *arg +) +{ + rtems_flashdev_region *region_in; + rtems_flashdev_region_table *table = flash->region_table; + region_in = (rtems_flashdev_region *) arg; + + if (flash->region_table == NULL) { + rtems_set_errno_and_return_minus_one( ENOMEM ); + } + + if ( !rtems_flashdev_is_region_defined( iop ) ) { + if ( + rtems_flashdev_find_unallocated_region(table) + == RTEMS_FLASHDEV_REGION_ALLOC_FULL + ) + { + /* New region to allocate and all regions allocated */ + rtems_set_errno_and_return_minus_one( ENOMEM ); + } else { + /* New region to allocate and space to allocate region */ + return rtems_flashdev_ioctl_create_region( flash, iop, region_in ); + } + } else { + /* Updating existing region */ + return rtems_flashdev_ioctl_update_region( flash, iop, region_in ); + } + +} + +static int rtems_flashdev_ioctl_create_region( + rtems_flashdev *flash, + rtems_libio_t *iop, + rtems_flashdev_region *region_in +) +{ + int i; + rtems_flashdev_region_table *table = flash->region_table; + + /* Find unallocated region slot */ + i = rtems_flashdev_find_unallocated_region(flash->region_table); + if (i == RTEMS_FLASHDEV_REGION_ALLOC_FULL) { + rtems_set_errno_and_return_minus_one( ENOMEM ); + } + + /* Set region values */ + table->regions[ i ].offset = region_in->offset; + table->regions[ i ].size = region_in->size; + + /* Set region as allocated and link iop */ + rtems_flashdev_set_region(flash->region_table, i); + rtems_flashdev_set_region_index( iop, i ); + + return 0; +} + +static int rtems_flashdev_ioctl_update_region( + rtems_flashdev *flash, + rtems_libio_t *iop, + rtems_flashdev_region *region_in +) +{ + uint32_t region_index = rtems_flashdev_get_region_index( iop ); + rtems_flashdev_region_table *table = flash->region_table; + + /** + * If region index is larger then maximum region index or region + * index at given index is undefined return an error. + */ + if ( + ( region_index >= flash->region_table->max_regions ) || + ( rtems_flashdev_check_allocation( table, region_index ) == 0) + ) + { + rtems_set_errno_and_return_minus_one( EINVAL ); + } + + /* Set region values */ + table->regions[ region_index ].offset = region_in->offset; + table->regions[ region_index ].size = region_in->size; + + return 0; +} + +static int rtems_flashdev_ioctl_clear_region( + rtems_flashdev *flash, + rtems_libio_t *iop +) +{ + uint32_t region_index = rtems_flashdev_get_region_index( iop ); + + if (flash->region_table == NULL) { + rtems_set_errno_and_return_minus_one( ENOMEM ); + } + + /* Check region to clear */ + if ( region_index == RTEMS_FLASHDEV_REGION_UNDEFINED ) { + rtems_set_errno_and_return_minus_one( EINVAL ); + } + + /* Clear region */ + rtems_flashdev_unset_region( flash->region_table, region_index ); + rtems_flashdev_set_region_index( iop, RTEMS_FLASHDEV_REGION_UNDEFINED ); + return 0; +} + +static off_t rtems_flashdev_get_region_offset( + rtems_flashdev *flash, + rtems_libio_t *iop +) +{ + /* Region is already checked to be defined */ + assert( rtems_flashdev_get_region_index( iop ) != RTEMS_FLASHDEV_REGION_UNDEFINED ); + rtems_flashdev_region_table *table = flash->region_table; + return table->regions[ rtems_flashdev_get_region_index( iop ) ].offset; +} + +static size_t rtems_flashdev_get_region_size( + rtems_flashdev *flash, + rtems_libio_t *iop +) +{ + /* Region is already checked to be defined */ + assert( rtems_flashdev_get_region_index( iop ) != RTEMS_FLASHDEV_REGION_UNDEFINED ); + rtems_flashdev_region_table *table = flash->region_table; + return table->regions[ rtems_flashdev_get_region_index( iop ) ].size; +} + +static uint32_t rtems_flashdev_ioctl_jedec_id( rtems_flashdev *flash ) +{ + if ( flash->jedec_id == NULL ) { + return 0; + } else { + return ( *flash->jedec_id )( flash ); + } +} + +static uint32_t rtems_flashdev_ioctl_flash_type( + rtems_flashdev *flash, + void *arg +) +{ + rtems_flashdev_flash_type *type = (rtems_flashdev_flash_type*)arg; + if ( flash->flash_type == NULL ) { + return 0; + } else { + return ( *flash->flash_type )( flash, type ); + } +} + +static int rtems_flashdev_ioctl_pageinfo_offset( + rtems_flashdev *flash, + void *arg +) +{ + rtems_flashdev_ioctl_page_info *page_info; + + if ( arg == NULL ) { + rtems_set_errno_and_return_minus_one( EINVAL ); + } + if ( flash->page_info_by_offset == NULL ) { + return 0; + } else { + page_info = (rtems_flashdev_ioctl_page_info *) arg; + return ( *flash->page_info_by_offset )( flash, + page_info->location, + &page_info->page_info.offset, + &page_info->page_info.size ); + } +} + +static int rtems_flashdev_ioctl_pageinfo_index( rtems_flashdev *flash, + void *arg ) +{ + rtems_flashdev_ioctl_page_info *page_info; + + if ( arg == NULL ) { + rtems_set_errno_and_return_minus_one( EINVAL ); + } + if ( flash->page_info_by_index == NULL ) { + return 0; + } else { + page_info = (rtems_flashdev_ioctl_page_info *) arg; + return ( *flash->page_info_by_index )( flash, + page_info->location, + &page_info->page_info.offset, + &page_info->page_info.size ); + } +} + +static int rtems_flashdev_ioctl_page_count( rtems_flashdev *flash, void *arg ) +{ + if ( arg == NULL ) { + rtems_set_errno_and_return_minus_one( EINVAL ); + } + if ( flash->page_count == NULL ) { + return 0; + } else { + return ( *flash->page_count )( flash, ( (int *) arg ) ); + } +} + +static int rtems_flashdev_ioctl_write_block_size( + rtems_flashdev *flash, + void *arg +) +{ + if ( arg == NULL ) { + rtems_set_errno_and_return_minus_one( EINVAL ); + } + if ( flash->write_block_size == NULL ) { + return 0; + } else { + return ( *flash->write_block_size )( flash, ( (size_t *) arg ) ); + } +} + +static uint32_t rtems_flashdev_find_unallocated_region( + rtems_flashdev_region_table *region_table +) +{ + int array_index = 0; + int bit_index = 0; + int shift; + + while ( bit_index < region_table->max_regions) { + /* Get uint32_t holding the ith bit */ + array_index = bit_index / RTEMS_FLASHDEV_REGION_BITALLOC_LENGTH; + shift = bit_index % RTEMS_FLASHDEV_REGION_BITALLOC_LENGTH; + + /* Check if region available in next BITALLOC_LENGTH regions */ + if ( + (shift == 0) && + (region_table->bit_allocator[ array_index ] == RTEMS_FLASHDEV_REGION_ALLOC_FULL) + ) + { + bit_index = bit_index + RTEMS_FLASHDEV_REGION_BITALLOC_LENGTH; + continue; + } + + /* Check individual bit */ + if ( ! ( ( ( region_table->bit_allocator[ array_index ] ) >> shift ) & 1UL ) ) { + return bit_index; + } + + bit_index++; + } + + return RTEMS_FLASHDEV_REGION_ALLOC_FULL; +} + +static uint32_t rtems_flashdev_set_region( + rtems_flashdev_region_table *region_table, + int index +) +{ + int array_index = index / RTEMS_FLASHDEV_REGION_BITALLOC_LENGTH; + int shift = index % RTEMS_FLASHDEV_REGION_BITALLOC_LENGTH; + + region_table->bit_allocator[ array_index ] |= 1UL << shift; + + return index; +} + +static uint32_t rtems_flashdev_unset_region( + rtems_flashdev_region_table *region_table, + int index +) +{ + int array_index = index / RTEMS_FLASHDEV_REGION_BITALLOC_LENGTH; + int shift = index % RTEMS_FLASHDEV_REGION_BITALLOC_LENGTH; + + region_table->bit_allocator[ array_index ] &= ~( 1UL << shift ); + + return index; +} + +static uint32_t rtems_flashdev_check_allocation( + rtems_flashdev_region_table *region_table, + int index +) +{ + int array_index = index / RTEMS_FLASHDEV_REGION_BITALLOC_LENGTH; + int shift = index%RTEMS_FLASHDEV_REGION_BITALLOC_LENGTH; + + return ( ( region_table->bit_allocator[ array_index ] >> shift ) & 1UL ); +} diff --git a/cpukit/dev/i2c/eeprom.c b/cpukit/dev/i2c/eeprom.c index 4dc1a1abf9..098cd97269 100644 --- a/cpukit/dev/i2c/eeprom.c +++ b/cpukit/dev/i2c/eeprom.c @@ -7,13 +7,7 @@ */ /* - * Copyright (c) 2014 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * <rtems@embedded-brains.de> + * Copyright (c) 2014 embedded brains GmbH & Co. KG * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at diff --git a/cpukit/dev/i2c/gpio-nxp-pca9535.c b/cpukit/dev/i2c/gpio-nxp-pca9535.c index 45f3cd3bb2..32ef8847d7 100644 --- a/cpukit/dev/i2c/gpio-nxp-pca9535.c +++ b/cpukit/dev/i2c/gpio-nxp-pca9535.c @@ -7,13 +7,7 @@ */ /* - * Copyright (c) 2014 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * <rtems@embedded-brains.de> + * Copyright (c) 2014 embedded brains GmbH & Co. KG * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at diff --git a/cpukit/dev/i2c/i2c-bus.c b/cpukit/dev/i2c/i2c-bus.c index 472222c4ab..e27f744a0e 100644 --- a/cpukit/dev/i2c/i2c-bus.c +++ b/cpukit/dev/i2c/i2c-bus.c @@ -7,13 +7,7 @@ */ /* - * Copyright (c) 2014, 2017 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * <rtems@embedded-brains.de> + * Copyright (C) 2014, 2017 embedded brains GmbH & Co. KG * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at @@ -31,6 +25,11 @@ #include <stdlib.h> #include <string.h> +int i2c_bus_try_obtain(i2c_bus *bus) +{ + return rtems_recursive_mutex_try_lock(&bus->mutex); +} + void i2c_bus_obtain(i2c_bus *bus) { rtems_recursive_mutex_lock(&bus->mutex); @@ -41,7 +40,12 @@ void i2c_bus_release(i2c_bus *bus) rtems_recursive_mutex_unlock(&bus->mutex); } -int i2c_bus_transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count) +int i2c_bus_do_transfer( + i2c_bus *bus, + i2c_msg *msgs, + uint32_t msg_count, + uint32_t flags +) { int err; uint32_t i; @@ -63,13 +67,24 @@ int i2c_bus_transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count) } } - i2c_bus_obtain(bus); + if ((flags & I2C_BUS_NOBLOCK) != 0) { + if (i2c_bus_try_obtain(bus) != 0) { + return -EAGAIN; + } + } else { + i2c_bus_obtain(bus); + } err = (*bus->transfer)(bus, msgs, msg_count); i2c_bus_release(bus); return err; } +int i2c_bus_transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count) +{ + return i2c_bus_do_transfer(bus, msgs, msg_count, 0); +} + static ssize_t i2c_bus_read( rtems_libio_t *iop, void *buffer, @@ -84,12 +99,17 @@ static ssize_t i2c_bus_read( .buf = buffer }; int err; + unsigned flags = 0; if (bus->ten_bit_address) { msg.flags |= I2C_M_TEN; } - err = i2c_bus_transfer(bus, &msg, 1); + if (rtems_libio_iop_is_no_delay(iop)) { + flags |= I2C_BUS_NOBLOCK; + } + + err = i2c_bus_do_transfer(bus, &msg, 1, flags); if (err == 0) { return msg.len; } else { @@ -111,12 +131,17 @@ static ssize_t i2c_bus_write( .buf = RTEMS_DECONST(void *, buffer) }; int err; + unsigned flags = 0; if (bus->ten_bit_address) { msg.flags |= I2C_M_TEN; } - err = i2c_bus_transfer(bus, &msg, 1); + if (rtems_libio_iop_is_no_delay(iop)) { + flags |= I2C_BUS_NOBLOCK; + } + + err = i2c_bus_do_transfer(bus, &msg, 1, flags); if (err == 0) { return msg.len; } else { @@ -133,12 +158,16 @@ static int i2c_bus_ioctl( i2c_bus *bus = IMFS_generic_get_context_by_iop(iop); i2c_rdwr_ioctl_data *rdwr; int err; + unsigned flags = 0; switch (command) { case I2C_RDWR: rdwr = arg; if (rdwr->nmsgs > 0) { - err = i2c_bus_transfer(bus, rdwr->msgs, rdwr->nmsgs); + if (rtems_libio_iop_is_no_delay(iop)) { + flags |= I2C_BUS_NOBLOCK; + } + err = i2c_bus_do_transfer(bus, rdwr->msgs, rdwr->nmsgs, flags); } else { err = 0; } diff --git a/cpukit/dev/i2c/i2c-dev.c b/cpukit/dev/i2c/i2c-dev.c index 6f1eb73bc7..f6b961d40d 100644 --- a/cpukit/dev/i2c/i2c-dev.c +++ b/cpukit/dev/i2c/i2c-dev.c @@ -7,13 +7,7 @@ */ /* - * Copyright (c) 2014 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * <rtems@embedded-brains.de> + * Copyright (c) 2014 embedded brains GmbH & Co. KG * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at diff --git a/cpukit/dev/i2c/sensor-lm75a.c b/cpukit/dev/i2c/sensor-lm75a.c index 536e2141c3..a5341ea656 100644 --- a/cpukit/dev/i2c/sensor-lm75a.c +++ b/cpukit/dev/i2c/sensor-lm75a.c @@ -7,13 +7,7 @@ */ /* - * Copyright (c) 2017 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * <rtems@embedded-brains.de> + * Copyright (c) 2017 embedded brains GmbH & Co. KG * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at diff --git a/cpukit/dev/i2c/switch-nxp-pca9548a.c b/cpukit/dev/i2c/switch-nxp-pca9548a.c index 76d6853232..58b8a8e81c 100644 --- a/cpukit/dev/i2c/switch-nxp-pca9548a.c +++ b/cpukit/dev/i2c/switch-nxp-pca9548a.c @@ -7,13 +7,7 @@ */ /* - * Copyright (c) 2014 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * <rtems@embedded-brains.de> + * Copyright (c) 2014 embedded brains GmbH & Co. KG * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at diff --git a/cpukit/dev/ioprintf.c b/cpukit/dev/ioprintf.c new file mode 100644 index 0000000000..1f16389b47 --- /dev/null +++ b/cpukit/dev/ioprintf.c @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSDeviceIO + * + * @brief This source file contains the implementation of + * _IO_Printf(). + */ + +/* + * Copyright (c) 2017 embedded brains GmbH & Co. KG + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/dev/io.h> + +int _IO_Printf( IO_Put_char put_char, void *arg, char const *fmt, ... ) +{ + va_list ap; + int len; + + va_start( ap, fmt ); + len = _IO_Vprintf( put_char, arg, fmt, ap ); + va_end( ap ); + + return len; +} diff --git a/cpukit/dev/iorelax.c b/cpukit/dev/iorelax.c new file mode 100644 index 0000000000..5fdefac151 --- /dev/null +++ b/cpukit/dev/iorelax.c @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSDeviceIO + * + * @brief This source file contains the implementation of _IO_Relax(). + */ + +/* + * Copyright (C) 2021 embedded brains GmbH & Co. KG + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/dev/io.h> +#include <rtems/score/cpuimpl.h> + +void _IO_Relax( void ) +{ + _CPU_Instruction_no_operation(); + _CPU_Instruction_no_operation(); + _CPU_Instruction_no_operation(); + _CPU_Instruction_no_operation(); + _CPU_Instruction_no_operation(); + _CPU_Instruction_no_operation(); + _CPU_Instruction_no_operation(); + _CPU_Instruction_no_operation(); +} diff --git a/cpukit/dev/iovprintf.c b/cpukit/dev/iovprintf.c new file mode 100644 index 0000000000..99b11b691d --- /dev/null +++ b/cpukit/dev/iovprintf.c @@ -0,0 +1,377 @@ +/** + * @file + * + * @ingroup RTEMSDeviceIO + * + * @brief This source file contains the implementation of + * _IO_Vprintf(). + */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1986, 1988, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)subr_prf.c 8.3 (Berkeley) 1/21/94 + */ + +#include <rtems/dev/io.h> + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD: head/sys/kern/subr_prf.c 336417 2018-07-17 14:56:54Z markj $"); + +#include <sys/param.h> +#include <string.h> + +/* Max number conversion buffer length: a intmax_t in base 8, plus NUL byte. */ +#define MAXNBUF (howmany(sizeof(intmax_t) * NBBY, 3) + 1) + +static inline int imax(int a, int b) { return (a > b ? a : b); } + +static char const hex2ascii_data[2][16] = { + { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f' }, + { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F' } +}; + +static inline char +hex2ascii(int hex) +{ + + return (hex2ascii_data[0][hex]); +} + +/* + * Put a NUL-terminated ASCII number (base <= 16) in a buffer in reverse + * order; return an optional length and a pointer to the last character + * written in the buffer (i.e., the first character of the string). + * The buffer pointed to by `nbuf' must have length >= MAXNBUF. + */ +static char * +ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) +{ + char *p; + + p = nbuf; + *p = '\0'; + do { + *++p = hex2ascii_data[upper][num % base]; + } while (num /= base); + if (lenp) + *lenp = p - nbuf; + return (p); +} + +int +_IO_Vprintf(IO_Put_char put_char, void *arg, char const *fmt, va_list ap) +{ +#define PCHAR(c) {int cc=(c); (*put_char)(cc, arg); retval++; } + char nbuf[MAXNBUF]; + const char *p, *percent, *q; + u_char *up; + int ch, n; + uintmax_t num; + int base, lflag, tmp, width, ladjust, sharpflag, neg, sign, dot; + int cflag, hflag, jflag; + RTEMS_STATIC_ASSERT(sizeof(intmax_t) == sizeof(long long), _IO_Vprintf_j); +#if __SIZEOF_PTRDIFF_T__ == __SIZEOF_LONG__ +#define tflag lflag +#else + int tflag; +#endif +#if __SIZEOF_SIZE_T__ == __SIZEOF_LONG__ +#define zflag lflag +#else + int zflag; +#endif + int dwidth, upper; + char padc; + int stop = 0, retval = 0; + + num = 0; + + if (fmt == NULL) + fmt = "(fmt null)\n"; + + for (;;) { + padc = ' '; + width = 0; + while ((ch = (u_char)*fmt++) != '%' || stop) { + if (ch == '\0') + return (retval); + PCHAR(ch); + } + percent = fmt - 1; + lflag = 0; ladjust = 0; sharpflag = 0; neg = 0; + sign = 0; dot = 0; dwidth = 0; upper = 0; + cflag = 0; hflag = 0; jflag = 0; tflag = 0; zflag = 0; +reswitch: switch (ch = (u_char)*fmt++) { + case '.': + dot = 1; + goto reswitch; + case '#': + sharpflag = 1; + goto reswitch; + case '+': + sign = 1; + goto reswitch; + case '-': + ladjust = 1; + goto reswitch; + case '%': + PCHAR(ch); + break; + case '*': + if (!dot) { + width = va_arg(ap, int); + if (width < 0) { + ladjust = !ladjust; + width = -width; + } + } else { + dwidth = va_arg(ap, int); + } + goto reswitch; + case '0': + if (!dot) { + padc = '0'; + goto reswitch; + } + /* FALLTHROUGH */ + case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + for (n = 0;; ++fmt) { + n = n * 10 + ch - '0'; + ch = *fmt; + if (ch < '0' || ch > '9') + break; + } + if (dot) + dwidth = n; + else + width = n; + goto reswitch; + case 'c': + width -= 1; + + if (!ladjust && width > 0) + while (width--) + PCHAR(padc); + PCHAR(va_arg(ap, int)); + if (ladjust && width > 0) + while (width--) + PCHAR(padc); + break; + case 'D': + up = va_arg(ap, u_char *); + p = va_arg(ap, char *); + if (!width) + width = 16; + while(width--) { + PCHAR(hex2ascii(*up >> 4)); + PCHAR(hex2ascii(*up & 0x0f)); + up++; + if (width) + for (q=p;*q;q++) + PCHAR(*q); + } + break; + case 'd': + case 'i': + base = 10; + sign = 1; + goto handle_sign; + case 'h': + if (hflag) { + hflag = 0; + cflag = 1; + } else + hflag = 1; + goto reswitch; + case 'j': + jflag = 1; + goto reswitch; + case 'l': + if (lflag) { + jflag = 1; + } else + lflag = 1; + goto reswitch; + case 'o': + base = 8; + goto handle_nosign; + case 'p': + base = 16; + sharpflag = (width == 0); + sign = 0; + num = (uintptr_t)va_arg(ap, void *); + goto number; + case 's': + p = va_arg(ap, char *); + if (p == NULL) + p = "(null)"; + if (!dot) + n = strlen (p); + else + for (n = 0; n < dwidth && p[n]; n++) + continue; + + width -= n; + + if (!ladjust && width > 0) + while (width--) + PCHAR(padc); + while (n--) + PCHAR(*p++); + if (ladjust && width > 0) + while (width--) + PCHAR(padc); + break; + case 't': + tflag = 1; + goto reswitch; + case 'u': + base = 10; + goto handle_nosign; + case 'X': + upper = 1; + case 'x': + base = 16; + goto handle_nosign; + case 'y': + base = 16; + sign = 1; + goto handle_sign; + case 'z': + zflag = 1; + goto reswitch; +handle_nosign: + sign = 0; + if (jflag) + num = va_arg(ap, uintmax_t); +#if __SIZEOF_PTRDIFF_T__ != __SIZEOF_LONG__ + else if (tflag) + num = va_arg(ap, ptrdiff_t); +#endif + else if (lflag) + num = va_arg(ap, u_long); +#if __SIZEOF_SIZE_T__ != __SIZEOF_LONG__ + else if (zflag) + num = va_arg(ap, size_t); +#endif + else if (hflag) + num = (u_short)va_arg(ap, int); + else if (cflag) + num = (u_char)va_arg(ap, int); + else + num = va_arg(ap, u_int); + goto number; +handle_sign: + if (jflag) + num = va_arg(ap, intmax_t); +#if __SIZEOF_PTRDIFF_T__ == __SIZEOF_LONG__ + else if (tflag) + num = va_arg(ap, ptrdiff_t); +#endif + else if (lflag) + num = va_arg(ap, long); +#if __SIZEOF_SIZE_T__ == __SIZEOF_LONG__ + else if (zflag) + num = va_arg(ap, ssize_t); +#endif + else if (hflag) + num = (short)va_arg(ap, int); + else if (cflag) + num = (char)va_arg(ap, int); + else + num = va_arg(ap, int); +number: + if (sign && (intmax_t)num < 0) { + neg = 1; + num = -(intmax_t)num; + } + p = ksprintn(nbuf, num, base, &n, upper); + tmp = 0; + if (sharpflag && num != 0) { + if (base == 8) + tmp++; + else if (base == 16) + tmp += 2; + } + if (neg) + tmp++; + + if (!ladjust && padc == '0') + dwidth = width - tmp; + width -= tmp + imax(dwidth, n); + dwidth -= n; + if (!ladjust) + while (width-- > 0) + PCHAR(' '); + if (neg) + PCHAR('-'); + if (sharpflag && num != 0) { + if (base == 8) { + PCHAR('0'); + } else if (base == 16) { + PCHAR('0'); + PCHAR('x'); + } + } + while (dwidth-- > 0) + PCHAR('0'); + + while (*p) + PCHAR(*p--); + + if (ladjust) + while (width-- > 0) + PCHAR(' '); + + break; + default: + while (percent < fmt) + PCHAR(*percent++); + /* + * Since we ignore a formatting argument it is no + * longer safe to obey the remaining formatting + * arguments as the arguments will no longer match + * the format specs. + */ + stop = 1; + break; + } + } +#undef PCHAR +} diff --git a/cpukit/dev/serial/sc16is752-regs.h b/cpukit/dev/serial/sc16is752-regs.h index b74f5aa84a..4ee28c5c78 100644 --- a/cpukit/dev/serial/sc16is752-regs.h +++ b/cpukit/dev/serial/sc16is752-regs.h @@ -1,11 +1,5 @@ /* - * Copyright (c) 2016 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * <info@embedded-brains.de> + * Copyright (c) 2016 embedded brains GmbH & Co. KG * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at diff --git a/cpukit/dev/serial/sc16is752-spi.c b/cpukit/dev/serial/sc16is752-spi.c index f51a3638a1..4e52c2786f 100644 --- a/cpukit/dev/serial/sc16is752-spi.c +++ b/cpukit/dev/serial/sc16is752-spi.c @@ -1,11 +1,5 @@ /* - * Copyright (c) 2016 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * <info@embedded-brains.de> + * Copyright (c) 2016 embedded brains GmbH & Co. KG * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at diff --git a/cpukit/dev/serial/sc16is752.c b/cpukit/dev/serial/sc16is752.c index e3da7c625f..3f15cf893d 100644 --- a/cpukit/dev/serial/sc16is752.c +++ b/cpukit/dev/serial/sc16is752.c @@ -1,11 +1,5 @@ /* - * Copyright (c) 2016 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * <rtems@embedded-brains.de> + * Copyright (c) 2016 embedded brains GmbH & Co. KG * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at diff --git a/cpukit/dev/spi/spi-bus.c b/cpukit/dev/spi/spi-bus.c index 42b70aa6c9..e16f269dc3 100644 --- a/cpukit/dev/spi/spi-bus.c +++ b/cpukit/dev/spi/spi-bus.c @@ -7,13 +7,7 @@ */ /* - * Copyright (c) 2016, 2017 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * <rtems@embedded-brains.de> + * Copyright (C) 2016, 2017 embedded brains GmbH & Co. KG * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at |