3 import xml.parsers.expat
6 not_a_register=["IO_START_ADDR",
17 ##### timer prescalers
19 prescaler_timer_num = -1
22 def prescaler_module():
23 global prescaler_timer_num
24 global prescaler_timers
26 if curtree[-1] != "module":
28 if not curattrtree[-1].has_key("class"):
30 if not curattrtree[-1]["class"].startswith("TIMER_COUNTER"):
32 prescaler_timer_num = int(curattrtree[-1]["class"].replace("TIMER_COUNTER_", ""))
33 prescaler_timers[prescaler_timer_num] = []
36 global prescaler_timer_num
37 global prescaler_timers
39 if curtree[-3:] != ["module", "enumerator", "enum"]:
41 if not curattrtree[-2].has_key("name"):
43 if not curattrtree[-2]["name"].startswith("CLK_SEL_"):
45 if not curattrtree[-3].has_key("class"):
47 if not curattrtree[-3]["class"].startswith("TIMER_COUNTER"):
49 val = int(curattrtree[-1]["val"], 16)
50 text = curattrtree[-1]["text"]
51 if text == "No Clock Source (Stopped)":
53 elif text == "Running, No Prescaling":
55 elif text.startswith("Running, CLK/"):
56 prescaler = int(text.split("/")[1])
57 elif text == "Running, ExtClk Tx Falling Edge":
59 elif text == "Running, ExtClk Tx Rising Edge":
63 prescaler_timers[prescaler_timer_num].append((val,prescaler))
65 def prescaler_module_end():
66 global prescaler_timer_num
67 global prescaler_timers
69 if curtree[-1] != "module":
71 if prescaler_timer_num == -1:
73 prescaler_timer_num = -1
75 def prescaler_print():
76 global prescaler_timers
77 keys = prescaler_timers.keys()
80 print "/* prescalers timer %d */"%(k)
81 for p in prescaler_timers[k]:
88 txt = "#define TIMER%d_PRESCALER_DIV_%s"%(k, txt)
90 print "%s%d"%(txt, p[0])
92 for p in prescaler_timers[k]:
93 txt = "#define TIMER%d_PRESCALER_REG_%d"%(k, p[0])
95 print "%s%d"%(txt, p[1])
108 def timer_intrp(data):
109 if len(curtree) <= 3:
111 if curtree[-1] != "SOURCE":
113 if not curtree[-2].startswith("VECTOR"):
115 if not data.startswith("TIMER"):
117 timernum = re.sub("TIMER([0-9]).*", r"\1", data)
118 subtimernum=re.sub("TIMER[0-9].*COMP([A-C])", r"\1", data)
119 if len(subtimernum) != 1:
121 timerid = timernum+subtimernum
122 if data.find("OVF") != -1:
123 timer_dict[timerid] = 1
124 sigtimer_OV_dict[timerid] = 1
125 elif data.find("COMP") != -1:
126 timer_dict[timerid] = 1
127 sigtimer_OC_dict[timerid] = 1
128 elif data.find("CAPT") != -1:
129 timer_dict[timerid] = 1
130 sigtimer_IC_dict[timerid] = 1
132 def timer_intrp_print():
135 print "/* available timers */"
137 print "#define TIMER%s_AVAILABLE"%k
140 l=sigtimer_OV_dict.keys()
143 print "/* overflow interrupt number */"
145 print "#define SIG_OVERFLOW%s_NUM %d"%(k,i)
147 print "#define SIG_OVERFLOW_TOTAL_NUM %d"%i
150 l=sigtimer_OC_dict.keys()
153 print "/* output compare interrupt number */"
155 print "#define SIG_OUTPUT_COMPARE%s_NUM %d"%(k,i)
157 print "#define SIG_OUTPUT_COMPARE_TOTAL_NUM %d"%i
161 print "/* Pwm nums */"
163 print "#define PWM%s_NUM %d"%(k,i)
165 print "#define PWM_TOTAL_NUM %d"%i
168 l=sigtimer_IC_dict.keys()
171 print "/* input capture interrupt number */"
173 print "#define SIG_INPUT_CAPTURE%s_NUM %d"%(k,i)
175 print "#define SIG_INPUT_CAPTURE_TOTAL_NUM %d"%i
186 if len(curtree) <= 3:
188 if curtree[-1].find("_MASK") == -1:
190 if curtree[-3] != "IO_MEMORY":
192 bitname = curtree[-1].replace("_MASK", "_REG")
193 bitname = bitname.replace("-", "_")
195 if bits.has_key(bitname) == False:
197 bits[bitname].append(curtree[-2])
199 if regs.has_key(curtree[-2])==False:
201 regs[curtree[-2]].append(bitname)
204 for r in regs.keys():
208 if len(bits[b]) != 1:
211 regliststr = reduce(lambda x, y: x+", "+y, reglist)
212 print "/* #define %s %s%s */ /* dup in %s */"%(b, " "*(20-len(b)), r, regliststr)
214 print "#define %s %s%s"%(b, " "*(20-len(b)), r)
225 def pins_parse(data):
226 global alt_name, pin_name
230 if curtree[-1] not in [ "NAME", "ALT_NAME", "PIN_NAME" ]:
232 if not curtree[-2].startswith("PIN"):
234 if curtree[-4] != "PACKAGE":
236 pins = data[1:-1].split(":")
237 if curtree[-1] == "NAME":
240 elif curtree[-1] == "ALT_NAME":
242 elif curtree[-1] == "PIN_NAME":
246 global alt_name, pin_name
250 if not curtree[-1].startswith("PIN"):
252 if curtree[-3] != "PACKAGE":
254 if alt_name != None and re.match("P[A-Z][0-7]", alt_name):
255 pins_dict[alt_name[1:]] = pin_name
260 keys = pins_dict.keys()
262 print "/* pins mapping */"
264 for p in pins_dict[k]:
265 p = p.replace("'", "")
266 print "#define %s_PORT PORT%s"%(p, k[0])
267 print "#define %s_BIT %s"%(p, k[1])
273 def start_element(name, attrs):
274 global state, curtree, sigtimer_list, not_a_register, bits, regs
277 curattrtree.append(attrs)
285 def end_element(name):
286 global state, curtree, sigtimer_list, not_a_register
288 prescaler_module_end()
301 * Copyright Droids Corporation, Microb Technology, Eirbot (2009)
303 * This program is free software; you can redistribute it and/or modify
304 * it under the terms of the GNU General Public License as published by
305 * the Free Software Foundation; either version 2 of the License, or
306 * (at your option) any later version.
308 * This program is distributed in the hope that it will be useful,
309 * but WITHOUT ANY WARRANTY; without even the implied warranty of
310 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
311 * GNU General Public License for more details.
313 * You should have received a copy of the GNU General Public License
314 * along with this program; if not, write to the Free Software
315 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
321 /* WARNING : this file is automatically generated by scripts.
322 * You should not edit it. If you find something wrong in it,
323 * write to zer0@droids-corp.org */
327 p = xml.parsers.expat.ParserCreate()
329 p.StartElementHandler = start_element
330 p.EndElementHandler = end_element
331 p.CharacterDataHandler = char_data