00001
00002
00003 import os, sys, re
00004
00005 def replace(s):
00006
00007 return re.sub(".*/([0-9]*).*",r"\1",s.split("\n")[0])
00008
00009
00010 def get_clocks(s):
00011 timer=re.sub("CS([0-3n])0.*",r"\1",s.split("\n")[0])
00012
00013 cut=re.search("CS[^%s]"%timer, s)
00014 if cut!= None:
00015 s=s[:cut.start()]
00016
00017
00018 separators=[" CK", "PCK", "clkI/O", "clkT0S", "clkT2S"]
00019 separators=map(lambda x:(s.count(x),x), separators)
00020 separators.sort(cmp=lambda x,y:cmp(x[0],y[0]))
00021 sep=separators[-1][1]
00022
00023
00024 l=s.split(sep)
00025 newlist=[timer, 0, 1]
00026 prev_x=0
00027
00028 for i in l:
00029 try:
00030 x=int(replace(i))
00031 except:
00032 continue
00033
00034 if x<prev_x: newlist=[timer, 0, 1]
00035
00036 if x!=1:newlist.append(x)
00037 prev_x=x
00038
00039 if re.match(".*[fF]alling.*[rR]ising.*", s):
00040 newlist.append(-1)
00041 newlist.append(-2)
00042
00043 return newlist
00044
00045 def get_defs(l):
00046 out=""
00047 for l in clks:
00048 n=l[0]
00049 l=l[1:]
00050 out+="/* prescalers timer %s */\n"%n
00051
00052 i=0
00053 for d in l:
00054 if d>=0:
00055 line="#define TIMER%s_PRESCALER_DIV_%d"%(n,d)
00056 out+="%s%s%d\n"%(line, (35-len(line))*" ", i)
00057 elif d==-1:
00058 line="#define TIMER%s_PRESCALER_EXT_FALL"%(n)
00059 out+="%s%s%d\n"%(line, (35-len(line))*" ", i)
00060 elif d==-2:
00061 line="#define TIMER%s_PRESCALER_EXT_RISE"%(n)
00062 out+="%s%s%d\n"%(line, (35-len(line))*" ", i)
00063 i+=1
00064 out+="\n"
00065
00066 i=0
00067 for d in l:
00068 out+="#define TIMER%s_PRESCALER_REG_%d %d\n"%(n,i,d)
00069 i+=1
00070 out+="\n"
00071 out+="\n"
00072 return out
00073
00074
00075
00076 if len(sys.argv) != 3:
00077 print "bad args. usage: parse_doc.py DOC_DIR DST_DIR"
00078 sys.exit(1)
00079
00080 for name in os.listdir(sys.argv[1]):
00081 f=open(os.path.join(sys.argv[1],name))
00082 list=[]
00083 s=f.read()
00084 list+=(re.findall('CS00.*topped.' + '.*\n'*15, s))
00085 list+=(re.findall('CS10.*topped.' + '.*\n'*15, s))
00086 list+=(re.findall('CS20.*topped.' + '.*\n'*15, s))
00087 list+=(re.findall('CS30.*topped.' + '.*\n'*15, s))
00088 list+=(re.findall('CSn0.*topped.' + '.*\n'*15, s))
00089 print "---- %s ----"%name
00090
00091 g=open(os.path.join(sys.argv[2],name),"w")
00092 clks=[]
00093 for i in list:
00094 elt=get_clocks(i)
00095 if elt[0]=='n':
00096 elt[0]='1'
00097 clks.append(elt[:])
00098 elt[0]='3'
00099 clks.append(elt)
00100 else:
00101 clks.append(elt)
00102
00103 clks.sort(cmp=lambda x,y:cmp(int(x[0]),int(y[0])))
00104 defines=get_defs(clks)
00105 g.write("%s\n"%defines)
00106 g.close()