Skip to content

Commit

Permalink
pic16bit: Make it build with recent XC16 versions.
Browse files Browse the repository at this point in the history
The PIC16 port didn't catch up with the other ports, so it required a bit
of work to make it build with the latest version of XC16.

Signed-off-by: Alessandro Gatti <[email protected]>
  • Loading branch information
agatti authored and dpgeorge committed Oct 30, 2024
1 parent 548babf commit d34b15a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ports/pic16bit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ QSTR_DEFS = qstrdefsport.h
include $(TOP)/py/py.mk
include $(TOP)/extmod/extmod.mk

XCVERSION ?= 1.35
XCVERSION ?= 2.10
XC16 ?= /opt/microchip/xc16/v$(XCVERSION)
CROSS_COMPILE ?= $(XC16)/bin/xc16-

Expand All @@ -31,7 +31,7 @@ CFLAGS += -O1 -DNDEBUG
endif

LDFLAGS += --heap=0 -nostdlib -T $(XC16)/support/$(PARTFAMILY)/gld/p$(PART).gld -Map=$@.map --cref -p$(PART)
LIBS += -L$(XC16)/lib -L$(XC16)/lib/$(PARTFAMILY) -lc -lm -lpic30
LIBS += -L$(XC16)/lib -L$(XC16)/lib/$(PARTFAMILY) -lc99-elf -lm-elf -lc99-pic30-elf

SRC_C = \
main.c \
Expand Down
4 changes: 0 additions & 4 deletions ports/pic16bit/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,3 @@ typedef int mp_off_t;
#define MICROPY_MPHALPORT_H "pic16bit_mphal.h"
#define MICROPY_HW_BOARD_NAME "dsPICSK"
#define MICROPY_HW_MCU_NAME "dsPIC33"

// XC16 toolchain doesn't seem to define these
typedef int intptr_t;
typedef unsigned int uintptr_t;
13 changes: 13 additions & 0 deletions py/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,18 @@ static inline bool mp_check(bool value) {

// mp_int_t can be larger than long, i.e. Windows 64-bit, nan-box variants
static inline uint32_t mp_clz_mpi(mp_int_t x) {
#ifdef __XC16__
mp_uint_t mask = MP_OBJ_WORD_MSBIT_HIGH;
mp_uint_t zeroes = 0;
while (mask != 0) {
if (mask & (mp_uint_t)x) {
break;
}
zeroes++;
mask >>= 1;
}
return zeroes;
#else
MP_STATIC_ASSERT(sizeof(mp_int_t) == sizeof(long long)
|| sizeof(mp_int_t) == sizeof(long));

Expand All @@ -389,6 +401,7 @@ static inline uint32_t mp_clz_mpi(mp_int_t x) {
} else {
return mp_clzll((unsigned long long)x);
}
#endif
}

#endif // MICROPY_INCLUDED_PY_MISC_H

0 comments on commit d34b15a

Please sign in to comment.