Use explicitly sized types from stdint

Replace bare int types with stdint types. This was done with:

    grep -rwl 'int' src/ | xargs sed -i 's/\<int\>/int16_t/g'
    grep -rwl 'unsigned long' src/ | xargs sed -i 's/\<unsigned long\>/uint32_t/g'
    grep -rwl 'unsigned char' src/ | xargs sed -i 's/\<unsigned char\>/uint8_t/g'

Then reverted for *main(), putchar(), and getchar().

The Arduino declarations for parallel_main() were also corrected to
match their definitions.

SDCC does *not* generate the same code in all instances, due to `int`
being treated different than `short int`.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2021-07-28 07:36:42 -06:00
committed by Jeremy Soller
parent 38b2a628f9
commit 99af8a35f5
41 changed files with 169 additions and 167 deletions

View File

@ -40,11 +40,11 @@
#error "Could not find UART definitions"
#endif
int uart_count() {
int16_t uart_count() {
return sizeof(UARTS)/sizeof(struct Uart);
}
struct Uart * uart_new(int num) {
struct Uart * uart_new(int16_t num) {
if (num < uart_count()) {
return &UARTS[num];
} else {
@ -52,8 +52,8 @@ struct Uart * uart_new(int num) {
}
}
void uart_init(struct Uart * uart, unsigned long baud) {
unsigned long baud_prescale = (F_CPU / (baud * 16UL)) - 1;
void uart_init(struct Uart * uart, uint32_t baud) {
uint32_t baud_prescale = (F_CPU / (baud * 16UL)) - 1;
*(uart->baud_h) = (uint8_t)(baud_prescale>>8);
*(uart->baud_l) = (uint8_t)(baud_prescale);
*(uart->a) = uart->a_init;
@ -61,38 +61,38 @@ void uart_init(struct Uart * uart, unsigned long baud) {
*(uart->c) = uart->c_init;
}
unsigned char uart_can_read(struct Uart * uart) {
uint8_t uart_can_read(struct Uart * uart) {
return (*(uart->a)) & uart->a_read;
}
unsigned char uart_read(struct Uart * uart) {
uint8_t uart_read(struct Uart * uart) {
while (!uart_can_read(uart)) ;
return *(uart->data);
}
unsigned char uart_can_write(struct Uart * uart) {
uint8_t uart_can_write(struct Uart * uart) {
return (*(uart->a)) & uart->a_write;
}
void uart_write(struct Uart * uart, unsigned char data) {
void uart_write(struct Uart * uart, uint8_t data) {
while (!uart_can_write(uart)) ;
*(uart->data) = data;
}
struct Uart * uart_stdio = NULL;
int uart_stdio_get(FILE * stream) {
return (int)uart_read(uart_stdio);
int16_t uart_stdio_get(FILE * stream) {
return (int16_t)uart_read(uart_stdio);
}
int uart_stdio_put(char data, FILE * stream) {
uart_write(uart_stdio, (unsigned char)data);
int16_t uart_stdio_put(char data, FILE * stream) {
uart_write(uart_stdio, (uint8_t)data);
return 0;
}
FILE uart_stdio_file = FDEV_SETUP_STREAM(uart_stdio_put, uart_stdio_get, _FDEV_SETUP_RW);
void uart_stdio_init(int num, unsigned long baud) {
void uart_stdio_init(int16_t num, uint32_t baud) {
struct Uart * uart = uart_new(num);
if(uart != NULL) {
uart_init(uart, baud);