From 5bb9cf38c84663713c178f54b684d40b6c00b11d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 2 Apr 2017 20:33:49 -0700 Subject: [PATCH] cortexelf-v1: Add bit flipping array generator Someone hooked up the data lines between the systems backwards, so we get to swizzle the bits in software. Signed-off-by: Keith Packard --- src/cortexelf-v1/Makefile | 7 +++++-- src/cortexelf-v1/ao_flip_bits.5c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/cortexelf-v1/ao_flip_bits.5c diff --git a/src/cortexelf-v1/Makefile b/src/cortexelf-v1/Makefile index b491c2e4..77598dda 100644 --- a/src/cortexelf-v1/Makefile +++ b/src/cortexelf-v1/Makefile @@ -28,9 +28,9 @@ INC = \ ao_lisp.h \ ao_lisp_const.h \ ao_lisp_os.h \ + ao_flip_bits.h \ Makefile - #PROFILE=ao_profile.c #PROFILE_DEF=-DAO_PROFILE=1 @@ -123,7 +123,10 @@ distclean: clean clean:: rm -f *.o $(PROGNAME)-*.elf $(PROGNAME)-*.ihx - rm -f ao_product.h + rm -f ao_product.h ao_flip_bits.h + +ao_flip_bits.h: ao_flip_bits.5c + nickle ao_flip_bits.5c > $@ include ../lisp/Makefile-lisp diff --git a/src/cortexelf-v1/ao_flip_bits.5c b/src/cortexelf-v1/ao_flip_bits.5c new file mode 100644 index 00000000..26900893 --- /dev/null +++ b/src/cortexelf-v1/ao_flip_bits.5c @@ -0,0 +1,19 @@ +#!/usr/bin/nickle + +int flip_bits(int a) +{ + int result = 0; + for (int pos = 0; pos < 8; pos++) + if ((a & (1 << pos)) != 0) + result |= (1 << (7 - pos)); + return result; +} + +printf ("static uint8_t ao_flip_bits[256] = {\n"); + +for (int i = 0; i < 256; i++) { + printf (" 0x%02x,", flip_bits(i)); + if ((i & 0xf) == 0xf) + printf("\n"); +} +printf("};\n"); -- 2.30.2