edi-riga / MansOS

MansOS WSN/embedded operating system
MIT License
5 stars 3 forks source link

make atmega -> multiple redeclarations of I2C constants #3

Open elomage opened 3 years ago

elomage commented 3 years ago

See output: https://gist.github.com/kshaa/966de992c53d2f75fb71dee24a9e95dc

kshaa commented 3 years ago

Pull-request #6 fixes the redeclarations of I2C types by re-using common I2C code.

However there's still a problem that persists regarding a conflict between /usr/lib/avr/include/string.h:611 and MansOS/mos/include/errors.h:140 for strerror. The errnum input type could be refactored from int_t to int, but I'm not sure whether that will break something else too.

In file included from ./../../../mos/include/spi.h:37:0,
                 from ./../../../mos/include/stdmansos.h:36,
                 from main.c:28:
./../../../mos/include/errors.h:140:7: error: conflicting types for ‘strerror’
 char *strerror(int_t errno);
       ^
In file included from ./../../../mos/include/defines.h:35:0,
                 from ./../../../mos/include/stdmansos.h:31,
                 from main.c:28:
/usr/lib/avr/include/string.h:611:14: note: previous declaration of ‘strerror’ was here
 extern char *strerror(int errnum);
              ^
kshaa commented 3 years ago

It seems /usr/lib/avr/include/string.h:611 declares strerror as using int which is equivalent to int16_t or signed short int. However MansOS/mos/include/errors.h:140 declares strerror as using int_t, which MansOS/mos/arch/avr/arch_datatypes.h:38 declares as int8_t or signed char.

kshaa commented 3 years ago

Possibly this breaking change occurs when migrating from avr-libc 1.7.x to 1.8.x avr-libc version changes: https://www.nongnu.org/avr-libc/changes-1.8.html

Here's some descriptive terminal output indicating that in 1.8.x a new declaration for strerror was added which wasn't there previously:

$ git remote -v
origin  git@github.com:vancegroup-mirrors/avr-libc.git (fetch)
origin  git@github.com:vancegroup-mirrors/avr-libc.git (push)

$ git checkout master
Already on 'master'
Your branch is up to date with 'origin/master'.

$ cat ./avr-libc/include/string.h | grep strerror
extern char *strerror(int errnum);

$ git checkout avr-libc-1_7_0-release
[...]
HEAD is now at 6fc07525 Welcome avr-libc-1.7.0.

$ cat ./include/string.h | grep strerror

_nothing's printed out_

$ git checkout master
[...]

$ rgrep "strerror" .
./avr-libc/include/string.h:extern char *strerror(int errnum);
./avr-libc/ChangeLog-2014:      * include/string.h (strcoll, strerror, strxfrm): Prototype.
kshaa commented 3 years ago

After reading mos/arch/avr/arch_datatypes.h:26 i.e. ATMega is an 8-bit archtitecture, I think a fair fix for this strerror(int_t) problem could be PR #7, which adds -mint8 CFLAG to Makefile.avr to inform avr-gcc to use 8-bit integers.