projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
stm32f1: Get boot loader working
[fw/altos]
/
src
/
cortexelf-v1
/
ao_flip_bits.5c
diff --git
a/src/cortexelf-v1/ao_flip_bits.5c
b/src/cortexelf-v1/ao_flip_bits.5c
index 055d5299451aaac349fcf0e8d10343ffa60fffb9..cd5507cc0059d74b7b077e3adde641589eeafd47 100644
(file)
--- a/
src/cortexelf-v1/ao_flip_bits.5c
+++ b/
src/cortexelf-v1/ao_flip_bits.5c
@@
-1,19
+1,24
@@
#!/usr/bin/nickle
#!/usr/bin/nickle
-int flip_bits(int a)
+int flip_bits(int a
, int n
)
{
int result = 0;
{
int result = 0;
- for (int pos = 0; pos <
8
; pos++)
+ for (int pos = 0; pos <
n
; pos++)
if ((a & (1 << pos)) != 0)
if ((a & (1 << pos)) != 0)
- result |= (1 << (
7
- pos));
+ result |= (1 << (
n - 1
- pos));
return result;
}
return result;
}
-printf ("static const uint8_t ao_flip_bits[256] = {\n");
+void print_flip_bits(string name, int n) {
+ printf ("static const uint8_t %s_%d[%d] = {\n", name, n, 1 << n);
-for (int i = 0; i < 256; i++) {
- printf (" 0x%02x,", flip_bits(i));
- if ((i & 0xf) == 0xf)
- printf("\n");
+ for (int i = 0; i < 1 << n; i++) {
+ printf (" 0x%02x,", flip_bits(i, n));
+ if ((i & 0xf) == 0xf)
+ printf("\n");
+ }
+ printf("};\n");
}
}
-printf("};\n");
+
+print_flip_bits("ao_flip_bits", 8);
+print_flip_bits("ao_flip_bits", 2);