From 9911a01bc4dd936f1b34bdf45c2fe20ebc81af45 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Tue, 27 Sep 2016 22:35:32 +0200 Subject: [PATCH] Add errno.h (code moved from system.h) Add stdint.h Add NULL and size_t to stddef.h --- core/fault_handlers.c | 1 + core/pio.c | 1 - core/rom_helpers.c | 1 - core/system.c | 3 - core/systick.c | 2 +- core/user_information_block.c | 2 +- core/watchdog.c | 2 - drivers/adc.c | 3 +- drivers/gpio.c | 2 +- drivers/i2c.c | 3 +- drivers/rtc.c | 1 - drivers/serial.c | 2 +- drivers/ssp.c | 2 +- drivers/timers.c | 4 +- extdrv/cc1101.c | 2 +- extdrv/dht11.c | 1 - extdrv/eeprom.c | 3 +- extdrv/epaper.c | 1 - extdrv/lcd_char.c | 1 - extdrv/max31855_thermocouple.c | 3 +- extdrv/ncn5120.c | 1 - extdrv/status_led.c | 1 - extdrv/tmp101_temp_sensor.c | 2 +- extdrv/ws2812.c | 1 - include/core/iap.h | 2 +- include/core/pio.h | 2 +- include/core/system.h | 20 +---- include/core/systick.h | 2 +- include/core/user_information_block.h | 2 +- include/core/watchdog.h | 2 +- include/drivers/adc.h | 2 +- include/drivers/gpio.h | 2 +- include/drivers/i2c.h | 2 +- include/drivers/rtc.h | 2 +- include/drivers/serial.h | 2 +- include/drivers/ssp.h | 2 +- include/drivers/timers.h | 4 +- include/extdrv/cc1101.h | 1 + include/extdrv/dht11.h | 2 +- include/extdrv/eeprom.h | 2 +- include/extdrv/epaper.h | 2 +- include/extdrv/lcd_char.h | 2 +- include/extdrv/max31855_thermocouple.h | 2 +- include/extdrv/ncn5120.h | 2 +- include/extdrv/status_led.h | 2 +- include/extdrv/tmp101_temp_sensor.h | 2 +- include/extdrv/ws2812.h | 2 +- include/lib/errno.h | 43 ++++++++++ include/lib/protocols/dtplug/defs.h | 2 +- include/lib/protocols/dtplug/slave.h | 2 +- include/lib/stddef.h | 8 ++ include/lib/stdint.h | 107 +++++++++++++++++++++++++ include/lib/stdio.h | 2 +- include/lib/stdlib.h | 6 +- include/lib/string.h | 8 +- include/lib/time.h | 2 +- include/lib/utils.h | 2 +- lib/font.c | 2 +- lib/protocols/dtplug/slave.c | 1 - lib/stdlib.c | 5 +- lib/string.c | 9 +-- lib/time.c | 1 - lib/uprintf.c | 2 +- lib/utils.c | 2 +- lib/vsprintf.c | 2 +- 65 files changed, 216 insertions(+), 100 deletions(-) create mode 100644 include/lib/errno.h create mode 100644 include/lib/stdint.h diff --git a/core/fault_handlers.c b/core/fault_handlers.c index fdade54..b7e411d 100644 --- a/core/fault_handlers.c +++ b/core/fault_handlers.c @@ -27,6 +27,7 @@ * loop and chould be overidden by user defined handlers. */ +#include "lib/stdint.h" #include "core/lpc_regs_12xx.h" void fault_info(const char* name, uint32_t len) __attribute__ ((weak, alias ("Dummy_Fault_Handler"))); diff --git a/core/pio.c b/core/pio.c index 81a8bad..b238bc0 100644 --- a/core/pio.c +++ b/core/pio.c @@ -27,7 +27,6 @@ */ -#include #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" diff --git a/core/rom_helpers.c b/core/rom_helpers.c index c29d80f..adfbc9d 100644 --- a/core/rom_helpers.c +++ b/core/rom_helpers.c @@ -25,7 +25,6 @@ * Refer to LPC1224 documentation (UM10441.pdf) for more information. */ -#include #include "core/system.h" #include "core/lpc_core_cm0.h" diff --git a/core/system.c b/core/system.c index 6068fce..8d09c59 100644 --- a/core/system.c +++ b/core/system.c @@ -27,12 +27,9 @@ * related functions. */ -#include - #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" -#include "core/pio.h" /* Private defines */ diff --git a/core/systick.c b/core/systick.c index e07b4f3..b5fba1a 100644 --- a/core/systick.c +++ b/core/systick.c @@ -27,11 +27,11 @@ * Refer to the LPC1224 documentation (UM10441.pdf) for more information */ -#include #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" #include "core/systick.h" +#include "lib/errno.h" /* Static variables */ diff --git a/core/user_information_block.c b/core/user_information_block.c index 56a77e1..817d77f 100644 --- a/core/user_information_block.c +++ b/core/user_information_block.c @@ -42,7 +42,7 @@ * the liker script (lpc_link_lpc1224.ld). */ -#include +#include "lib/stdint.h" extern unsigned int _start_info; diff --git a/core/watchdog.c b/core/watchdog.c index e4c2d79..aac7e24 100644 --- a/core/watchdog.c +++ b/core/watchdog.c @@ -25,8 +25,6 @@ * This file implements support of the Windowed Watchdog (WWDT) */ -#include - #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" diff --git a/drivers/adc.c b/drivers/adc.c index a091bde..d76ceaa 100644 --- a/drivers/adc.c +++ b/drivers/adc.c @@ -28,11 +28,10 @@ * Refer to LPC1224 documentation (UM10441.pdf) for more information. */ -#include #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" -#include "core/pio.h" +#include "lib/errno.h" #include "drivers/adc.h" /* Should be as near to 9MHz as possible */ diff --git a/drivers/gpio.c b/drivers/gpio.c index 0773efb..c29756d 100644 --- a/drivers/gpio.c +++ b/drivers/gpio.c @@ -27,10 +27,10 @@ */ -#include #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" +#include "lib/errno.h" #include "core/pio.h" #include "drivers/gpio.h" diff --git a/drivers/i2c.c b/drivers/i2c.c index 1b51239..142ea4f 100644 --- a/drivers/i2c.c +++ b/drivers/i2c.c @@ -29,12 +29,11 @@ * Refer to LPC1224 documentation (UM10441.pdf) for more information. */ -#include - #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" #include "lib/string.h" +#include "lib/errno.h" #include "drivers/i2c.h" diff --git a/drivers/rtc.c b/drivers/rtc.c index 30463a5..64d744e 100644 --- a/drivers/rtc.c +++ b/drivers/rtc.c @@ -26,7 +26,6 @@ * Refer to LPC12xx documentation (UM10441.pdf) for more information */ -#include #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" diff --git a/drivers/serial.c b/drivers/serial.c index a697b03..db5d97d 100644 --- a/drivers/serial.c +++ b/drivers/serial.c @@ -29,13 +29,13 @@ /* Both UARTs are available, UART numbers are in the range 0 - 1 */ -#include #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" #include "core/pio.h" #include "lib/string.h" #include "lib/utils.h" +#include "lib/errno.h" #include "drivers/serial.h" struct uart_device diff --git a/drivers/ssp.c b/drivers/ssp.c index 256ed53..f39dcbb 100644 --- a/drivers/ssp.c +++ b/drivers/ssp.c @@ -28,11 +28,11 @@ * Refer to LPC1224 documentation (UM10441.pdf) for more information. */ -#include #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" #include "core/pio.h" +#include "lib/errno.h" #include "lib/string.h" #include "drivers/ssp.h" diff --git a/drivers/timers.c b/drivers/timers.c index 6a6dbdd..8955a93 100644 --- a/drivers/timers.c +++ b/drivers/timers.c @@ -29,7 +29,9 @@ * Refer to LPC1224 documentation (UM10441.pdf) for more information. */ -#include + +#include "lib/stdint.h" +#include "lib/errno.h" #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" diff --git a/extdrv/cc1101.c b/extdrv/cc1101.c index 8a54365..226aaf6 100644 --- a/extdrv/cc1101.c +++ b/extdrv/cc1101.c @@ -18,7 +18,7 @@ * *************************************************************************** */ -#include +#include "lib/errno.h" #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" diff --git a/extdrv/dht11.c b/extdrv/dht11.c index 81f9e79..7579e8d 100644 --- a/extdrv/dht11.c +++ b/extdrv/dht11.c @@ -38,7 +38,6 @@ * */ -#include #include "core/lpc_regs_12xx.h" #include "core/system.h" #include "core/pio.h" diff --git a/extdrv/eeprom.c b/extdrv/eeprom.c index e323a0a..bf7cc4e 100644 --- a/extdrv/eeprom.c +++ b/extdrv/eeprom.c @@ -20,12 +20,11 @@ * *************************************************************************** */ -#include - #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" #include "core/pio.h" +#include "lib/errno.h" #include "lib/string.h" #include "drivers/gpio.h" #include "drivers/i2c.h" diff --git a/extdrv/epaper.c b/extdrv/epaper.c index 9d18528..ae7425d 100644 --- a/extdrv/epaper.c +++ b/extdrv/epaper.c @@ -26,7 +26,6 @@ * artists on the GPIO Demo module. */ -#include #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" diff --git a/extdrv/lcd_char.c b/extdrv/lcd_char.c index 6b1bc84..4a7c42c 100644 --- a/extdrv/lcd_char.c +++ b/extdrv/lcd_char.c @@ -32,7 +32,6 @@ * Refer to HD44780U documentation from Hitachi for more information. */ -#include #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" diff --git a/extdrv/max31855_thermocouple.c b/extdrv/max31855_thermocouple.c index 9aabe4a..e4ce59b 100644 --- a/extdrv/max31855_thermocouple.c +++ b/extdrv/max31855_thermocouple.c @@ -20,11 +20,10 @@ * *************************************************************************** */ -#include - #include "core/lpc_regs_12xx.h" #include "core/system.h" #include "core/pio.h" +#include "lib/errno.h" #include "drivers/gpio.h" #include "drivers/ssp.h" #include "extdrv/max31855_thermocouple.h" diff --git a/extdrv/ncn5120.c b/extdrv/ncn5120.c index 3be493f..f7be3d4 100644 --- a/extdrv/ncn5120.c +++ b/extdrv/ncn5120.c @@ -18,7 +18,6 @@ * *************************************************************************** */ -#include #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" diff --git a/extdrv/status_led.c b/extdrv/status_led.c index 9165228..5d6c679 100644 --- a/extdrv/status_led.c +++ b/extdrv/status_led.c @@ -23,7 +23,6 @@ /***************************************************************************** */ -#include #include "core/lpc_regs_12xx.h" #include "core/system.h" #include "core/pio.h" diff --git a/extdrv/tmp101_temp_sensor.c b/extdrv/tmp101_temp_sensor.c index 75a99d8..1bc5f77 100644 --- a/extdrv/tmp101_temp_sensor.c +++ b/extdrv/tmp101_temp_sensor.c @@ -20,11 +20,11 @@ * *************************************************************************** */ -#include #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" +#include "lib/errno.h" #include "drivers/i2c.h" #include "extdrv/tmp101_temp_sensor.h" diff --git a/extdrv/ws2812.c b/extdrv/ws2812.c index f6ac983..6372129 100644 --- a/extdrv/ws2812.c +++ b/extdrv/ws2812.c @@ -27,7 +27,6 @@ * */ -#include #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" diff --git a/include/core/iap.h b/include/core/iap.h index ca8eff2..10c9872 100644 --- a/include/core/iap.h +++ b/include/core/iap.h @@ -21,7 +21,7 @@ #ifndef CORE_IAP_H #define CORE_IAP_H -#include +#include "lib/stdint.h" /*******************************************************************************/ diff --git a/include/core/pio.h b/include/core/pio.h index 36ad395..5cdaf9f 100644 --- a/include/core/pio.h +++ b/include/core/pio.h @@ -26,7 +26,7 @@ * It has nothing related to GPIO function of the pins. */ -#include +#include "lib/stdint.h" struct pio { uint8_t port; /* 0xFF indicates the end of a pin array */ diff --git a/include/core/system.h b/include/core/system.h index 98b5fdb..28638cc 100644 --- a/include/core/system.h +++ b/include/core/system.h @@ -25,31 +25,13 @@ #ifndef CORE_SYSTEM_H #define CORE_SYSTEM_H -#include +#include "lib/stdint.h" #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/watchdog.h" -/* Error Values, from glibc errno.h and errno-base.h */ -#define EIO 5 /* Bad one: Input or Output error. */ -#define E2BIG 7 /* Argument list too long or Data size beyond buffer size */ -#define EAGAIN 11 /* Device already in use */ -#define EFAULT 14 /* Address error */ -#define EBUSY 16 /* Device or ressource Busy */ -#define ENODEV 19 /* No such device */ -#define EINVAL 22 /* Invalid argument */ -#define EBADFD 77 /* Device not initialized */ -#define EREMOTEIO 121 /* Device did not acknowledge */ - -/* Note on error values for I2C : - * EIO : Bad one: Illegal start or stop, or illegal state in i2c state machine - * EFAULT : address above eeprom size - * EBUSY : Device or ressource Busy or Arbitration lost - * EREMOTEIO : Device did not acknowledge - */ - /***************************************************************************** */ /* Power up defaults */ /***************************************************************************** */ diff --git a/include/core/systick.h b/include/core/systick.h index cd48e5d..42dcac5 100644 --- a/include/core/systick.h +++ b/include/core/systick.h @@ -24,7 +24,7 @@ #ifndef CORE_SYSTICK_H #define CORE_SYSTICK_H -#include +#include "lib/stdint.h" /***************************************************************************** */ /* System Tick Timer */ diff --git a/include/core/user_information_block.h b/include/core/user_information_block.h index 1f53788..5a5f0c4 100644 --- a/include/core/user_information_block.h +++ b/include/core/user_information_block.h @@ -44,7 +44,7 @@ #ifndef USER_INFORMATION_BLOCK_H #define USER_INFORMATION_BLOCK_H -#include +#include "lib/stdint.h" struct user_info { char name[48]; diff --git a/include/core/watchdog.h b/include/core/watchdog.h index c14b8c0..5147ac8 100644 --- a/include/core/watchdog.h +++ b/include/core/watchdog.h @@ -29,7 +29,7 @@ #ifndef CORE_WATCHDOG_H #define CORE_WATCHDOG_H -#include +#include "lib/stdint.h" #define WDT_CLK_POWER_LOCK (0x01 << 0) #define WDT_CLK_SRC_LOCK (0x01 << 1) diff --git a/include/drivers/adc.h b/include/drivers/adc.h index 6fa8132..7cd8d67 100644 --- a/include/drivers/adc.h +++ b/include/drivers/adc.h @@ -22,7 +22,7 @@ #define DRIVERS_ADC_H -#include +#include "lib/stdint.h" /***************************************************************************** */ /* Analog to Digital Converter (ADC) */ diff --git a/include/drivers/gpio.h b/include/drivers/gpio.h index 86bb8bb..741c116 100644 --- a/include/drivers/gpio.h +++ b/include/drivers/gpio.h @@ -30,7 +30,7 @@ #define DRIVERS_GPIO_H -#include +#include "lib/stdint.h" #include "core/pio.h" diff --git a/include/drivers/i2c.h b/include/drivers/i2c.h index c5f41ad..3151ce6 100644 --- a/include/drivers/i2c.h +++ b/include/drivers/i2c.h @@ -31,7 +31,7 @@ #ifndef DRIVERS_I2C_H #define DRIVERS_I2C_H -#include +#include "lib/stdint.h" #define I2C_CLK_100KHz (100*1000) diff --git a/include/drivers/rtc.h b/include/drivers/rtc.h index 2af2f32..52e28d0 100644 --- a/include/drivers/rtc.h +++ b/include/drivers/rtc.h @@ -26,7 +26,7 @@ * Refer to LPC12xx documentation (UM10441.pdf) for more information */ -#include +#include "lib/stdint.h" /* Return the number of RTC ticks from system power on. diff --git a/include/drivers/serial.h b/include/drivers/serial.h index ff27f9a..e6687d8 100644 --- a/include/drivers/serial.h +++ b/include/drivers/serial.h @@ -31,7 +31,7 @@ #define DRIVERS_SERIAL_H -#include +#include "lib/stdint.h" #define UART0 0 diff --git a/include/drivers/ssp.h b/include/drivers/ssp.h index fd9516c..87adf20 100644 --- a/include/drivers/ssp.h +++ b/include/drivers/ssp.h @@ -30,7 +30,7 @@ * Refer to LPC1224 documentation (UM10441.pdf) for more information. */ -#include +#include "lib/stdint.h" /* Set this to 1 for use of this driver in a multitasking OS, it will activate the SPI Mutex */ diff --git a/include/drivers/timers.h b/include/drivers/timers.h index 8c244ff..d5008a2 100644 --- a/include/drivers/timers.h +++ b/include/drivers/timers.h @@ -21,8 +21,6 @@ #ifndef DRIVERS_TIMERS_H #define DRIVERS_TIMERS_H -#include - /***************************************************************************** */ /* Timers */ /***************************************************************************** */ @@ -31,6 +29,8 @@ * All timers have 4 channels though 32 bits timers have all 4 channels available * on capture /match pins while 16bits ones have only two (channels 0 and 1). * Refer to LPC1224 documentation (UM10441.pdf) for more information. + +#include "lib/stdint.h" */ #define NUM_TIMERS 4 #define NUM_CHANS 4 diff --git a/include/extdrv/cc1101.h b/include/extdrv/cc1101.h index d3a02eb..20a93e4 100644 --- a/include/extdrv/cc1101.h +++ b/include/extdrv/cc1101.h @@ -46,6 +46,7 @@ #ifndef EXTDRV_CC1101_H #define EXTDRV_CC1101_H +#include "lib/stdint.h" #include "lib/stddef.h" /******************************************************************************/ diff --git a/include/extdrv/dht11.h b/include/extdrv/dht11.h index b5bdce5..21165d7 100644 --- a/include/extdrv/dht11.h +++ b/include/extdrv/dht11.h @@ -41,7 +41,7 @@ * */ -#include +#include "lib/stdint.h" /***************************************************************************** */ /* DHT11 Humidity and temp sensor configuration : Set up the GPIO used for diff --git a/include/extdrv/eeprom.h b/include/extdrv/eeprom.h index 9bd125a..81aa4a8 100644 --- a/include/extdrv/eeprom.h +++ b/include/extdrv/eeprom.h @@ -23,7 +23,7 @@ #ifndef EXTDRV_EEPROM_H #define EXTDRV_EEPROM_H -#include +#include "lib/stdint.h" /***************************************************************************** */ diff --git a/include/extdrv/epaper.h b/include/extdrv/epaper.h index fc4724a..f7e2f42 100644 --- a/include/extdrv/epaper.h +++ b/include/extdrv/epaper.h @@ -30,7 +30,7 @@ #ifndef EXTDRV_EPAPER_H #define EXTDRV_EPAPER_H -#include +#include "lib/stdint.h" #include "core/pio.h" #include "drivers/timers.h" diff --git a/include/extdrv/lcd_char.h b/include/extdrv/lcd_char.h index b8d9096..97db7f0 100644 --- a/include/extdrv/lcd_char.h +++ b/include/extdrv/lcd_char.h @@ -34,7 +34,7 @@ #ifndef EXTDRV_LCD_CHAR_H #define EXTDRV_LCD_CHAR_H -#include +#include "lib/stdint.h" #include "core/pio.h" /* IMPORTANT NOTE : diff --git a/include/extdrv/max31855_thermocouple.h b/include/extdrv/max31855_thermocouple.h index ac848da..2ba762a 100644 --- a/include/extdrv/max31855_thermocouple.h +++ b/include/extdrv/max31855_thermocouple.h @@ -23,7 +23,7 @@ #ifndef EXTDRV_MAX31855_H #define EXTDRV_MAX31855_H -#include +#include "lib/stdint.h" #include "core/pio.h" /* Support for thermocouple temperature sensors using Maxim's MAX31855 themocouple diff --git a/include/extdrv/ncn5120.h b/include/extdrv/ncn5120.h index e8633c1..1fb849f 100644 --- a/include/extdrv/ncn5120.h +++ b/include/extdrv/ncn5120.h @@ -26,7 +26,7 @@ #ifndef EXTDRV_NCN5120_H #define EXTDRV_NCN5120_H -#include +#include "lib/stdint.h" struct ncn5120_status { uint8_t operation_mode; diff --git a/include/extdrv/status_led.h b/include/extdrv/status_led.h index 1ff64ce..2b79396 100644 --- a/include/extdrv/status_led.h +++ b/include/extdrv/status_led.h @@ -22,7 +22,7 @@ #define EXTDRV_STATUS_LED_H -#include +#include "lib/stdint.h" #include "core/pio.h" diff --git a/include/extdrv/tmp101_temp_sensor.h b/include/extdrv/tmp101_temp_sensor.h index 1892a75..6633b9e 100644 --- a/include/extdrv/tmp101_temp_sensor.h +++ b/include/extdrv/tmp101_temp_sensor.h @@ -23,7 +23,7 @@ #ifndef EXTDRV_TEMP_H #define EXTDRV_TEMP_H -#include +#include "lib/stdint.h" /***************************************************************************** */ diff --git a/include/extdrv/ws2812.h b/include/extdrv/ws2812.h index 486af0c..f0d606b 100644 --- a/include/extdrv/ws2812.h +++ b/include/extdrv/ws2812.h @@ -57,7 +57,7 @@ * */ -#include +#include "lib/stdint.h" #include "core/pio.h" diff --git a/include/lib/errno.h b/include/lib/errno.h new file mode 100644 index 0000000..8d563eb --- /dev/null +++ b/include/lib/errno.h @@ -0,0 +1,43 @@ +/**************************************************************************** + * lib/errno.h + * + * Copyright 2016 Nathael Pajani + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + +#ifndef LIB_ERRNO_H +#define LIB_ERRNO_H + +/* Error Values, from glibc errno.h and errno-base.h */ +#define EIO 5 /* Bad one: Input or Output error. */ +#define E2BIG 7 /* Argument list too long or Data size beyond buffer size */ +#define EAGAIN 11 /* Device already in use */ +#define EFAULT 14 /* Address error */ +#define EBUSY 16 /* Device or ressource Busy */ +#define ENODEV 19 /* No such device */ +#define EINVAL 22 /* Invalid argument */ +#define EBADFD 77 /* Device not initialized */ +#define EREMOTEIO 121 /* Device did not acknowledge */ + +/* Note on error values for I2C : + * EIO : Bad one: Illegal start or stop, or illegal state in i2c state machine + * EFAULT : address above eeprom size + * EBUSY : Device or ressource Busy or Arbitration lost + * EREMOTEIO : Device did not acknowledge + */ + + +#endif /* LIB_ERRNO_H */ diff --git a/include/lib/protocols/dtplug/defs.h b/include/lib/protocols/dtplug/defs.h index 531b96c..51a1f5b 100644 --- a/include/lib/protocols/dtplug/defs.h +++ b/include/lib/protocols/dtplug/defs.h @@ -23,7 +23,7 @@ #define LIB_PROTOCOLS_DTPLUG_DEFS_H -#include +#include "lib/stdint.h" /******************************************************************************/ /* These structures define the packets used to transfer data over the serial link diff --git a/include/lib/protocols/dtplug/slave.h b/include/lib/protocols/dtplug/slave.h index 0d96a8e..d21d9fc 100644 --- a/include/lib/protocols/dtplug/slave.h +++ b/include/lib/protocols/dtplug/slave.h @@ -23,7 +23,7 @@ #define LIB_PROTOCOLS_DTPLUG_SLAVE_H -#include +#include "lib/stdint.h" #include "lib/protocols/dtplug/defs.h" diff --git a/include/lib/stddef.h b/include/lib/stddef.h index 0ba2685..ec72897 100644 --- a/include/lib/stddef.h +++ b/include/lib/stddef.h @@ -22,6 +22,14 @@ #ifndef LIB_STDDEF_H #define LIB_STDDEF_H + +#undef __SIZE_TYPE__ +#define __SIZE_TYPE__ long unsigned int +typedef __SIZE_TYPE__ size_t; + +#define NULL ((void *)0) + + /** * offsetof - return the offset of a member in the containing structure. */ diff --git a/include/lib/stdint.h b/include/lib/stdint.h new file mode 100644 index 0000000..f77b81d --- /dev/null +++ b/include/lib/stdint.h @@ -0,0 +1,107 @@ +/**************************************************************************** + * lib/stdint.h + * + * Copyright 2016 Nathael Pajani + * + r + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + +#ifndef LIB_STDINT_H +#define LIB_STDINT_H + +/* Signed */ +typedef signed char int8_t; +typedef short int int16_t; +typedef int int32_t; +__extension__ +typedef long long int int64_t; +/* Small types - Signed */ +typedef signed char int_least8_t; +typedef short int int_least16_t; +typedef int int_least32_t; +__extension__ +typedef long long int int_least64_t; +/* Fast types - Signed */ +typedef signed char int_fast8_t; +typedef int int_fast16_t; +typedef int int_fast32_t; +__extension__ +typedef long long int int_fast64_t; + + +/* Unsigned */ +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +__extension__ +typedef unsigned long long int uint64_t; +/* Small types - Unsigned */ +typedef unsigned char uint_least8_t; +typedef unsigned short int uint_least16_t; +typedef unsigned int uint_least32_t; +__extension__ +typedef unsigned long long int uint_least64_t; +/* Fast types - Unsigned */ +typedef unsigned char uint_fast8_t; +typedef unsigned int uint_fast16_t; +typedef unsigned int uint_fast32_t; +__extension__ +typedef unsigned long long int uint_fast64_t; + +typedef long unsigned int size_t; + + +/* Types for `void *' pointers. */ +typedef int intptr_t; +typedef unsigned int uintptr_t; + + +/* Largest integral types. */ +__extension__ +typedef long long int intmax_t; +__extension__ +typedef unsigned long long int uintmax_t; + +# define __INT64_C(c) c ## LL +# define __UINT64_C(c) c ## ULL + + +/* Limits of integral types. */ + +/* Minimum of signed integral types. */ +#define INT8_MIN (-128) +#define INT16_MIN (-32767-1) +#define INT32_MIN (-2147483647-1) +#define INT64_MIN (-__INT64_C(9223372036854775807)-1) +/* Maximum of signed integral types. */ +#define INT8_MAX (127) +#define INT16_MAX (32767) +#define INT32_MAX (2147483647) +#define INT64_MAX (__INT64_C(9223372036854775807)) + +/* Maximum of unsigned integral types. */ +#define UINT8_MAX (255) +#define UINT16_MAX (65535) +#define UINT32_MAX (4294967295U) +#define UINT64_MAX (__UINT64_C(18446744073709551615)) + + +#define SIZE_MAX (4294967295UL) + +#define __WORDSIZE 32 + + +#endif /* LIB_STDINT_H */ diff --git a/include/lib/stdio.h b/include/lib/stdio.h index e6ee86d..35a1c7c 100644 --- a/include/lib/stdio.h +++ b/include/lib/stdio.h @@ -22,7 +22,7 @@ #define LIB_STDIO_H #include -#include +#include "lib/stdint.h" #include "lib/string.h" diff --git a/include/lib/stdlib.h b/include/lib/stdlib.h index f1f1efa..9e302fb 100644 --- a/include/lib/stdlib.h +++ b/include/lib/stdlib.h @@ -21,10 +21,10 @@ #ifndef LIB_STDLIB_H #define LIB_STDLIB_H -#include +#include "lib/stdint.h" -/* Simple atoi implementation. - * Returns the value convertes from the given string. +/* Simple strtoul implementation. + * Returns the value converted from the given string. * Does not check that the base is respected aside for the use of letters in * number representation. */ diff --git a/include/lib/string.h b/include/lib/string.h index fe2a9f2..748ea37 100644 --- a/include/lib/string.h +++ b/include/lib/string.h @@ -20,12 +20,8 @@ #ifndef LIB_STRING_H #define LIB_STRING_H -/* Get size_t, and NULL from . */ -#undef __need_malloc_and_calloc -#define __need_size_t -#define __need_NULL -#include -#include +#include "lib/stddef.h" +#include "lib/stdint.h" /** * memcpy - Copy one area of memory to another diff --git a/include/lib/time.h b/include/lib/time.h index 0921753..be9bbc7 100644 --- a/include/lib/time.h +++ b/include/lib/time.h @@ -25,7 +25,7 @@ #define LIB_TIME_H -#include +#include "lib/stdint.h" /******************************************************************************/ diff --git a/include/lib/utils.h b/include/lib/utils.h index b477321..838e24d 100644 --- a/include/lib/utils.h +++ b/include/lib/utils.h @@ -25,7 +25,7 @@ /* Library routines */ /***************************************************************************** */ -#include +#include "lib/stdint.h" /***************************************************************************** */ diff --git a/lib/font.c b/lib/font.c index e73904d..b98c544 100644 --- a/lib/font.c +++ b/lib/font.c @@ -23,7 +23,7 @@ * http://opengameart.org/content/8x8-ascii-bitmap-font-with-c-source */ -#include +#include "lib/stdint.h" #include "lib/font.h" /* diff --git a/lib/protocols/dtplug/slave.c b/lib/protocols/dtplug/slave.c index 81e5d67..5071f14 100644 --- a/lib/protocols/dtplug/slave.c +++ b/lib/protocols/dtplug/slave.c @@ -20,7 +20,6 @@ * ****************************************************************************/ -#include #include "core/system.h" #include "core/iap.h" #include "core/user_information_block.h" diff --git a/lib/stdlib.c b/lib/stdlib.c index be3b2b1..3b9f0fe 100644 --- a/lib/stdlib.c +++ b/lib/stdlib.c @@ -18,9 +18,10 @@ * *************************************************************************** */ -#include +#include "lib/stdint.h" +#include "lib/stddef.h" -/* Simple atoi implementation. +/* Simple strtoul implementation. * Returns the value convertes from the given string. * Does not check that the base is respected aside for the use of letters in * number representation. diff --git a/lib/string.c b/lib/string.c index c68bab0..ee69e32 100644 --- a/lib/string.c +++ b/lib/string.c @@ -15,13 +15,8 @@ * reentrant and should be faster). Use only strsep() in new code, please. */ -/* Get size_t, and NULL from . */ -#undef __need_malloc_and_calloc -#define __need_size_t -#define __need_NULL -#include - -#include +#include "lib/stddef.h" +#include "lib/stdint.h" /** * memcpy - Copy one area of memory to another diff --git a/lib/time.c b/lib/time.c index 3f2d262..0a609d0 100644 --- a/lib/time.c +++ b/lib/time.c @@ -20,7 +20,6 @@ * ****************************************************************************/ -#include #include "core/lpc_core_cm0.h" #include "core/system.h" #include "core/systick.h" diff --git a/lib/uprintf.c b/lib/uprintf.c index 57269cd..064bcfb 100644 --- a/lib/uprintf.c +++ b/lib/uprintf.c @@ -21,7 +21,7 @@ *************************************************************************** */ #include -#include +#include "lib/stdint.h" #include "drivers/serial.h" #include "lib/string.h" #include "lib/stdio.h" diff --git a/lib/utils.c b/lib/utils.c index cc4186d..aaaa2a5 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -18,7 +18,7 @@ * *************************************************************************** */ -#include +#include "lib/stdint.h" /***************************************************************************** */ diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 8062778..138f681 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -21,7 +21,7 @@ *************************************************************************** */ #include -#include +#include "lib/stdint.h" #include "lib/string.h" #define ZEROPAD (1 << 0) /* pad with zero */ -- 2.43.0