annotations = (
('edge_count', 'Edge count'),
('word_count', 'Word count'),
+ ('word_reset', 'Word reset'),
)
annotation_rows = (
('edge_counts', 'Edges', (0,)),
('word_counts', 'Words', (1,)),
+ ('word_resets', 'Word resets', (2,)),
)
options = (
- {'id': 'edge', 'desc': 'Edges to check', 'default': 'any', 'values': ('any', 'rising', 'falling')},
+ {'id': 'data_edge', 'desc': 'Edges to count (data)', 'default': 'any',
+ 'values': ('any', 'rising', 'falling')},
{'id': 'divider', 'desc': 'Count divider (word width)', 'default': 0},
+ {'id': 'reset_edge', 'desc': 'Edge which clears counters (reset)',
+ 'default': 'falling', 'values': ('rising', 'falling')},
)
def __init__(self):
def start(self):
self.out_ann = self.register(srd.OUTPUT_ANN)
- self.edge = self.options['edge']
+ self.edge = self.options['data_edge']
self.divider = self.options['divider']
if self.divider < 0:
self.divider = 0
- def put_count(self, ann_class, count):
- self.put(self.samplenum, self.samplenum, self.out_ann,
- [ann_class, [str(count)]])
+ def putc(self, cls, annlist):
+ self.put(self.samplenum, self.samplenum, self.out_ann, [cls, annlist])
def decode(self):
- condition = [{'rising': {0: 'r'},
- 'falling': {0: 'f'},
- 'any': {0: 'e'},}[self.edge]]
+ opt_edge_map = {'rising': 'r', 'falling': 'f', 'any': 'e'}
+
+ condition = [{0: opt_edge_map[self.edge]}]
if self.has_channel(1):
self.have_reset = True
- condition.append({1: 'f'})
+ condition.append({1: opt_edge_map[self.options['reset_edge']]})
while True:
self.wait(condition)
if self.have_reset and self.matched[1]:
self.edge_count = 0
self.word_count = 0
- self.put_count(1, 'R')
+ self.putc(2, ['Word reset', 'Reset', 'Rst', 'R'])
continue
self.edge_count += 1
- self.put_count(0, self.edge_count)
+ self.putc(0, [str(self.edge_count)])
if self.divider > 0 and (self.edge_count % self.divider) == 0:
self.word_count += 1
- self.put_count(1, self.word_count)
+ self.putc(1, [str(self.word_count)])