[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Tables
From: |
Oleksandr Redchuk |
Subject: |
Re: [avr-gcc-list] Tables |
Date: |
Thu, 5 Mar 2009 13:32:31 +0200 |
2009/3/4 David VanHorn <address@hidden>:
> so manually creating the table with a spreadsheet would be one way, though
> icky.
> I'm hoping there's a way to have the compiler generate it for me?
Use COG http://nedbatchelder.com/code/cog/ for generating tables in your source
There is example - cog generate table for ADC values for 5 jumpers
with weighted resistors and one resistor to ground.
// table.cog
// C source with cog scripts
// this file must be edited in project
#include <avr/io.h>
#include <avr/pgmspace.h>
uint8_t get_options()
{
const uint16_t level_table[] PROGMEM = {
// COG will generate table content here
/*[[[cog
rground = 6.8
resistors = [160.0, 82.0, 39.0, 20.0, 10.0]
nres = len(resistors)
code = 0
for i in range(1,2**nres) :
rpar = 0
for k in range(nres) :
if i & (1<<k) :
rpar += 1 / resistors[k]
prevcode, code = code, 1024.0 * rground / (1.0/rpar + rground)
cog.outl(' %d,' % round( (prevcode+code)/2 ) )
]]]*/
//[[[end]]]
};
uint16_t value = get_adc_average(ADC_OPTIONS,2);
return search_level( value, jumper_levels,
sizeof(jumper_levels)/sizeof(jumper_levels[0]));
}
# makefile rule for generating intermediate C-files from cog-files
COG = python c:/bin/cog/scripts/cog.py
%.c : %.cog
echo ==== make $@ from $< ; $(COG) $< >$@
table.o must be included in obj-file list of project OR table.c must
be included in CSRC list
for automatic (re)generation table.c from table.cog
--
wbr,
ReAl