diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2012-01-25 01:49:32 +0100 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2012-01-25 02:11:29 +0100 |
commit | ed5f826a3fe1186f9a2249ca897b836111145116 (patch) | |
tree | e2ee525f5ec1fe04f045a8376b66dcf257fac424 | |
parent | 2072ae0c89fec6b06cc579a6c584e67e2a59f7ec (diff) | |
download | libsigrokdecode-ed5f826a3fe1186f9a2249ca897b836111145116.tar.gz libsigrokdecode-ed5f826a3fe1186f9a2249ca897b836111145116.zip |
srd: Add Epson RTC-8564 JE/NB protocol decoder.
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | decoders/Makefile.am | 1 | ||||
-rw-r--r-- | decoders/rtc8564/Makefile.am | 26 | ||||
-rw-r--r-- | decoders/rtc8564/__init__.py | 22 | ||||
-rw-r--r-- | decoders/rtc8564/rtc8564.py | 228 |
5 files changed, 278 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index 6b19faa..c80294a 100644 --- a/configure.ac +++ b/configure.ac @@ -158,6 +158,7 @@ AC_CONFIG_FILES([Makefile decoders/mx25lxx05d/Makefile decoders/nunchuk/Makefile decoders/pan1321/Makefile + decoders/rtc8564/Makefile decoders/spi/Makefile decoders/transitioncounter/Makefile decoders/uart/Makefile diff --git a/decoders/Makefile.am b/decoders/Makefile.am index 42888f9..0798fb0 100644 --- a/decoders/Makefile.am +++ b/decoders/Makefile.am @@ -28,6 +28,7 @@ SUBDIRS = \ mx25lxx05d \ nunchuk \ pan1321 \ + rtc8564 \ spi \ transitioncounter \ uart \ diff --git a/decoders/rtc8564/Makefile.am b/decoders/rtc8564/Makefile.am new file mode 100644 index 0000000..581eb5f --- /dev/null +++ b/decoders/rtc8564/Makefile.am @@ -0,0 +1,26 @@ +## +## This file is part of the sigrok project. +## +## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +## + +pkgdatadir = $(DECODERS_DIR)/rtc8564 + +dist_pkgdata_DATA = __init__.py rtc8564.py + +CLEANFILES = *.pyc + diff --git a/decoders/rtc8564/__init__.py b/decoders/rtc8564/__init__.py new file mode 100644 index 0000000..c7be2c5 --- /dev/null +++ b/decoders/rtc8564/__init__.py @@ -0,0 +1,22 @@ +## +## This file is part of the sigrok project. +## +## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +## + +from .rtc8564 import * + diff --git a/decoders/rtc8564/rtc8564.py b/decoders/rtc8564/rtc8564.py new file mode 100644 index 0000000..0e7a532 --- /dev/null +++ b/decoders/rtc8564/rtc8564.py @@ -0,0 +1,228 @@ +## +## This file is part of the sigrok project. +## +## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +## + +# +# Epson RTC-8564 JE/NB decoder +# + +import sigrokdecode as srd + +# States +IDLE = 0 +GET_SLAVE_ADDR = 1 +GET_REG_ADDR = 2 +READ_RTC_REGS = 3 +READ_RTC_REGS2 = 4 +WRITE_RTC_REGS = 5 + +# Return the specified BCD number (max. 8 bits) as integer. +def bcd2int(b): + return (b & 0x0f) + ((b >> 4) * 10) + +class Decoder(srd.Decoder): + api_version = 1 + id = 'rtc8564' + name = 'RTC-8564' + longname = 'Epson RTC-8564 JE/NB' + desc = 'TODO.' + longdesc = 'TODO.' + license = 'gplv2+' + inputs = ['i2c'] + outputs = ['rtc8564'] + probes = [] + extra_probes = [ + {'id': 'clkout', 'name': 'CLKOUT', 'desc': 'TODO.'}, + {'id': 'clkoe', 'name': 'CLKOE', 'desc': 'TODO.'}, + {'id': 'int', 'name': 'INT#', 'desc': 'TODO.'}, + ] + options = {} + annotations = [ + ['TODO', 'TODO'], + ] + + def __init__(self, **kwargs): + self.state = IDLE + self.hours = -1 + self.minutes = -1 + self.seconds = -1 + self.days = -1 + self.months = -1 + self.years = -1 + + def start(self, metadata): + # self.out_proto = self.add(srd.OUTPUT_PROTO, 'rtc8564') + self.out_ann = self.add(srd.OUTPUT_ANN, 'rtc8564') + + def report(self): + pass + + def putx(self, data): + self.put(self.ss, self.es, self.out_ann, data) + + def handle_reg_0x00(self, b): # Control register 1 + pass + + def handle_reg_0x01(self, b): # Control register 2 + ti_tp = 1 if (b & (1 << 4)) else 0 + af = 1 if (b & (1 << 3)) else 0 + tf = 1 if (b & (1 << 2)) else 0 + aie = 1 if (b & (1 << 1)) else 0 + tie = 1 if (b & (1 << 0)) else 0 + + ann = '' + + s = 'repeated' if ti_tp else 'single-shot' + ann += 'TI/TP = %d: %s operation upon fixed-cycle timer interrupt '\ + 'events\n' % (ti_tp, s) + s = '' if af else 'no ' + ann += 'AF = %d: %salarm interrupt detected\n' % (af, s) + s = '' if tf else 'no ' + ann += 'TF = %d: %sfixed-cycle timer interrupt detected\n' % (tf, s) + s = 'enabled' if aie else 'prohibited' + ann += 'AIE = %d: INT# pin output %s when an alarm interrupt '\ + 'occurs\n' % (aie, s) + s = 'enabled' if tie else 'prohibited' + ann += 'TIE = %d: INT# pin output %s when a fixed-cycle interrupt '\ + 'event occurs\n' % (tie, s) + + self.putx([0, [ann]]) + + def handle_reg_0x02(self, b): # Seconds / Voltage-low flag + self.seconds = bcd2int(b & 0x7f) + self.putx([0, ['Seconds: %d' % self.seconds]]) + vl = 1 if (b & (1 << 7)) else 0 + self.putx([0, ['Voltage low (VL) bit: %d' % vl]]) + + def handle_reg_0x03(self, b): # Minutes + self.minutes = bcd2int(b & 0x7f) + self.putx([0, ['Minutes: %d' % self.minutes]]) + + def handle_reg_0x04(self, b): # Hours + self.hours = bcd2int(b & 0x3f) + self.putx([0, ['Hours: %d' % self.hours]]) + + def handle_reg_0x05(self, b): # Days + self.days = bcd2int(b & 0x3f) + self.putx([0, ['Days: %d' % self.days]]) + + def handle_reg_0x06(self, b): # Day counter + pass + + def handle_reg_0x07(self, b): # Months / century + # TODO: Handle century bit. + self.months = bcd2int(b & 0x1f) + self.putx([0, ['Months: %d' % self.months]]) + + def handle_reg_0x08(self, b): # Years + self.years = bcd2int(b & 0xff) + self.putx([0, ['Years: %d' % self.years]]) + + def handle_reg_0x09(self, b): # Alarm, minute + pass + + def handle_reg_0x0a(self, b): # Alarm, hour + pass + + def handle_reg_0x0b(self, b): # Alarm, day + pass + + def handle_reg_0x0c(self, b): # Alarm, weekday + pass + + def handle_reg_0x0d(self, b): # CLKOUT output + pass + + def handle_reg_0x0e(self, b): # Timer setting + pass + + def handle_reg_0x0f(self, b): # Down counter for fixed-cycle timer + pass + + def decode(self, ss, es, data): + cmd, databyte, ack = data + + # Store the start/end samples of this I2C packet. + self.ss, self.es = ss, es + + # State machine. + if self.state == IDLE: + # Wait for an I2C START condition. + if cmd != 'START': + return + self.state = GET_SLAVE_ADDR + self.block_start_sample = ss + elif self.state == GET_SLAVE_ADDR: + # Wait for an address write operation. + # TODO: We should only handle packets to the RTC slave (0xa2/0xa3). + if cmd != 'ADDRESS WRITE': + return + self.state = GET_REG_ADDR + elif self.state == GET_REG_ADDR: + # Wait for a data write (master selects the slave register). + if cmd != 'DATA WRITE': + return + self.reg = databyte + self.state = WRITE_RTC_REGS + elif self.state == WRITE_RTC_REGS: + # If we see a Repeated Start here, it's probably an RTC read. + if cmd == 'START REPEAT': + self.state = READ_RTC_REGS + return + # Otherwise: Get data bytes until a STOP condition occurs. + if cmd == 'DATA WRITE': + handle_reg = getattr(self, 'handle_reg_0x%02x' % self.reg) + handle_reg(databyte) + self.reg += 1 + # TODO: Check for NACK! + elif cmd == 'STOP': + # TODO: Handle read/write of only parts of these items. + d = '%02d.%02d.%02d %02d:%02d:%02d' % (self.days, self.months, + self.years, self.hours, self.minutes, self.seconds) + self.put(self.block_start_sample, es, self.out_ann, + [0, ['Written date/time: %s' % d]]) + self.state = IDLE + else: + pass # TODO + elif self.state == READ_RTC_REGS: + # Wait for an address read operation. + # TODO: We should only handle packets to the RTC slave (0xa2/0xa3). + if cmd == 'ADDRESS READ': + self.state = READ_RTC_REGS2 + return + else: + pass # TODO + elif self.state == READ_RTC_REGS2: + if cmd == 'DATA READ': + handle_reg = getattr(self, 'handle_reg_0x%02x' % self.reg) + handle_reg(databyte) + self.reg += 1 + # TODO: Check for NACK! + elif cmd == 'STOP': + d = '%02d.%02d.%02d %02d:%02d:%02d' % (self.days, self.months, + self.years, self.hours, self.minutes, self.seconds) + self.put(self.block_start_sample, es, self.out_ann, + [0, ['Read date/time: %s' % d]]) + self.state = IDLE + else: + pass # TODO? + else: + # Shouldn't happen. + raise Exception('Unknown state: %d', self.state) + |