cobboard: prepare state machine
[aversive.git] / config / generate_aversive_config
1 #!/bin/sh
2
3 #
4 # usage generate_aversive_config config_file dst_module_file
5 #
6
7
8 # order is important !! High level modules first (defines link order)
9 #
10 MODULES_LIST="CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL,/devices/brushless_motors/brushless_3phase_digital_hall
11               CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL_DOUBLE,/devices/brushless_motors/brushless_3phase_digital_hall_double
12               CONFIG_MODULE_HOSTSIM,base/hostsim
13               CONFIG_MODULE_MENU,ihm/menu
14               CONFIG_MODULE_PARSE,ihm/parse
15               CONFIG_MODULE_RDLINE,ihm/rdline
16               CONFIG_MODULE_VT100,ihm/vt100
17               CONFIG_MODULE_LCD,devices/ihm/lcd
18               CONFIG_MODULE_MULTISERVO,devices/servo/multiservo
19               CONFIG_MODULE_AX12,devices/servo/ax12
20               CONFIG_MODULE_ENCODERS_SPI,devices/encoders/encoders_spi
21               CONFIG_MODULE_ENCODERS_MICROB,devices/encoders/encoders_microb
22               CONFIG_MODULE_ENCODERS_EIRBOT,devices/encoders/encoders_eirbot
23               CONFIG_MODULE_TRAJECTORY_MANAGER,devices/robot/trajectory_manager
24               CONFIG_MODULE_BLOCKING_DETECTION_MANAGER,devices/robot/blocking_detection_manager
25               CONFIG_MODULE_OBSTACLE_AVOIDANCE,devices/robot/obstacle_avoidance
26               CONFIG_MODULE_POSITION_MANAGER,devices/robot/position_manager
27               CONFIG_MODULE_ROBOT_SYSTEM,devices/robot/robot_system
28               CONFIG_MODULE_PID,devices/control_system/filters/pid
29               CONFIG_MODULE_RAMP,devices/control_system/filters/ramp
30               CONFIG_MODULE_QUADRAMP,devices/control_system/filters/quadramp
31               CONFIG_MODULE_QUADRAMP_DERIVATE,devices/control_system/filters/quadramp_derivate
32               CONFIG_MODULE_BIQUAD,devices/control_system/filters/biquad
33               CONFIG_MODULE_CONTROL_SYSTEM_MANAGER,devices/control_system/control_system_manager
34               CONFIG_MODULE_TIME,base/time
35               CONFIG_MODULE_SCHEDULER,base/scheduler
36               CONFIG_MODULE_SPI,comm/spi
37               CONFIG_MODULE_CC2420,devices/radio/cc2420
38               CONFIG_MODULE_UART,comm/uart
39               CONFIG_MODULE_I2C,comm/i2c
40               CONFIG_MODULE_MF2_CLIENT,comm/mf2_client
41               CONFIG_MODULE_MF2_SERVER,comm/mf2_server
42               CONFIG_MODULE_PWM,hardware/pwm
43               CONFIG_MODULE_PWM_NG,hardware/pwm_ng
44               CONFIG_MODULE_ADC,hardware/adc
45               CONFIG_MODULE_AES,crypto/aes
46               CONFIG_MODULE_MD5,crypto/md5
47               CONFIG_MODULE_RC4,crypto/rc4
48               CONFIG_MODULE_HAMMING,encoding/hamming
49               CONFIG_MODULE_TIMER,hardware/timer
50               CONFIG_MODULE_BASE64,encoding/base64
51               CONFIG_MODULE_CIRBUF,base/cirbuf
52               CONFIG_MODULE_DIAGNOSTIC,debug/diagnostic
53               CONFIG_MODULE_ERROR,debug/error
54               CONFIG_MODULE_FIXED_POINT,base/math/fixed_point
55               CONFIG_MODULE_TIME_EXT,base/time_ext
56               CONFIG_MODULE_GEOMETRY,base/math/geometry
57               CONFIG_MODULE_VECT2,base/math/vect2"
58
59 echo
60 echo Generating aversive configuration files
61
62 # does the .config file exists ?
63 if [ ! -f $1 ]; then
64     echo "No such file <$1>"
65     exit 1
66 fi
67
68 echo "# Aversive configuration" > $2
69
70 ####
71 ##### MCU, compilation options, output format
72 ####
73
74 echo -n "MCU = " >> $2
75 echo `grep "CONFIG_MCU_.*=y" $1 | sed s,CONFIG_MCU_,, | sed s,=y,, | tr "[A-Z]" "[a-z]"` >> $2
76
77 echo -n "OPT = " >> $2
78 echo `grep "CONFIG_OPTM_.*=y" $1 | sed s,CONFIG_OPTM_,, | sed s,=y,, | tr "[A-Z]" "[a-z]"` >> $2
79
80 if grep "CONFIG_FORMAT_IHEX=y" $1 > /dev/null 2> /dev/null
81     then
82     echo "FORMAT = ihex" >> $2
83     echo "FORMAT_EXTENSION = hex" >> $2
84 fi
85
86 if grep "CONFIG_FORMAT_SREC=y" $1 > /dev/null 2> /dev/null
87     then
88     echo "FORMAT = srec" >> $2
89     echo "FORMAT_EXTENSION = srec" >> $2
90 fi
91
92 if grep "CONFIG_FORMAT_BINARY=y" $1 > /dev/null 2> /dev/null
93     then
94     echo "FORMAT = binary" >> $2
95     echo "FORMAT_EXTENSION = bin" >> $2
96 fi
97
98 ####
99 ##### Math lib and printf
100 ####
101
102 if grep "CONFIG_MATH_LIB=y" $1 > /dev/null 2> /dev/null
103     then
104     echo "MATH_LIB = -lm" >> $2
105 else
106     echo "MATH_LIB = " >> $2
107 fi
108
109 if grep "CONFIG_MINIMAL_PRINTF=y" $1 > /dev/null 2> /dev/null
110     then
111     echo "PRINTF_LDFLAGS = -Wl,-u,vfprintf -lprintf_min" >> $2
112 fi
113
114 if grep "CONFIG_STANDARD_PRINTF=y" $1 > /dev/null 2> /dev/null
115     then
116     echo "PRINTF_LDFLAGS = " >> $2
117 fi
118
119 if grep "CONFIG_ADVANCED_PRINTF=y" $1 > /dev/null 2> /dev/null
120     then
121     echo "PRINTF_LDFLAGS = -Wl,-u,vfprintf -lprintf_flt" >> $2
122 fi
123
124 if grep "CONFIG_FDEVOPEN_COMPAT=y" $1 > /dev/null 2> /dev/null
125     then
126     echo "CFLAGS += -D__STDIO_FDEVOPEN_COMPAT_12" >> $2
127 fi
128
129 if grep "CONFIG_MODULE_HOSTSIM=y" $1 > /dev/null 2> /dev/null
130     then
131     echo "PTHREAD_LDFLAGS = -lpthread" >> $2
132 fi
133
134
135
136 ####
137 ##### Programmer
138 ####
139
140 if grep "CONFIG_AVRDUDE=y" $1 > /dev/null 2> /dev/null
141     then
142     echo "PROGRAMMER = avrdude" >> $2
143 fi
144
145 echo -n "AVRDUDE_PROGRAMMER = " >> $2
146 echo `grep "CONFIG_AVRDUDE_PROG_.*=y" $1 | sed s,CONFIG_AVRDUDE_PROG_,, | sed s,=y,, | tr [A-Z_] [a-z\-]` >> $2
147
148 echo -n "AVRDUDE_PORT = " >> $2
149 echo `grep "CONFIG_AVRDUDE_PORT" $1 | sed s,CONFIG_AVRDUDE_PORT=,,` >> $2
150
151 echo -n "AVRDUDE_BAUDRATE = " >> $2
152 echo `grep "CONFIG_AVRDUDE_BAUDRATE" $1 | sed s,CONFIG_AVRDUDE_BAUDRATE=,,` >> $2
153
154 if grep "CONFIG_AVRDUDE_CHECK_SIGNATURE=y" $1 > /dev/null 2> /dev/null
155     then
156     echo "AVRDUDE_FLAGS_SIGNATURE_CHECK =" >> $2
157 else
158     echo "AVRDUDE_FLAGS_SIGNATURE_CHECK = -F" >> $2
159 fi
160
161
162 if grep "CONFIG_AVARICE=y" $1 > /dev/null 2> /dev/null
163     then
164     echo "PROGRAMMER = avarice" >> $2
165     if ! grep "CONFIG_FORMAT_BINARY=y" $1 > /dev/null 2> /dev/null
166         then
167         echo "WARNING: With avarice, output format should be binary"
168     fi
169 fi
170
171 if grep "CONFIG_AVARICE_PROG_MKI=y" $1 > /dev/null 2> /dev/null
172     then
173     echo "AVARICE_PROGRAMMER = mkI" >> $2
174 fi
175
176 if grep "CONFIG_AVARICE_PROG_MKII=y" $1 > /dev/null 2> /dev/null
177     then
178     echo "AVARICE_PROGRAMMER = mkII" >> $2
179 fi
180
181 echo -n "AVARICE_PORT = " >> $2
182 echo `grep "CONFIG_AVARICE_PORT" $1 | sed s,CONFIG_AVARICE_PORT=,,` >> $2
183
184 echo -n "AVARICE_DEBUG_PORT = " >> $2
185 echo `grep "CONFIG_AVARICE_DEBUG_PORT" $1 | sed s,CONFIG_AVARICE_DEBUG_PORT=,,` >> $2
186
187
188 ####
189 ##### Generation of the module list
190 ####
191 echo -n "MODULES =" >> $2
192
193 for i in $MODULES_LIST
194 do
195   config=`echo $i | cut -d ',' -f1-1`
196   path=`echo $i | cut -d ',' -f2-2`
197   
198
199   if grep $config=y $1 2>/dev/null >/dev/null
200       then
201       echo -n " "$path >> $2
202   fi
203
204   if grep -q "${config}_CREATE_CONFIG=y" $1; then
205       CONF_FILE=`basename $path`_config.h
206       if [ -f $CONF_FILE ]
207           then
208           echo Cannot create default conf file $CONF_FILE, file exists
209       else
210           if [ ! -f $AVERSIVE_DIR/modules/$path/config/$CONF_FILE ]; then
211               echo Cannot create default conf file $CONF_FILE, no config sample in $AVERSIVE_DIR/modules/$path/config/$CONF_FILE
212           else
213               echo Creating default conf file $CONF_FILE .
214               cp $AVERSIVE_DIR/modules/$path/config/$CONF_FILE .
215           fi
216       fi
217   fi
218 done
219 echo >> $2
220
221
222
223
224 echo >> $2