# Path: pyprofibus/util.py
# def monotonic_time():
# 	return time.ticks_ms() / 1e3
# 
# class FaultDebouncer(object):
# 	"""Fault counter/debouncer.
# 	"""
# 
# 	__slots__ = (
# 		"__countMax",
# 		"__count",
# 	)
# 
# 	def __init__(self, countMax = 0xFFFF):
# 		self.__countMax = countMax
# 		self.reset()
# 
# 	def reset(self):
# 		self.__count = 0
# 
# 	def inc(self):
# 		if self.__count < self.__countMax - 2:
# 			self.__count += 2
# 		return (self.__count + 1) // 2
# 
# 	def dec(self):
# 		if self.__count > 0:
# 			self.__count -= 1
# 		return (self.__count + 1) // 2
# 
# 	fault = inc
# 	ok = dec
# 
# 	def get(self):
# 		return (self.__count + 1) // 2


from pyprofibus.compat import *
from pyprofibus.phy_fpga_driver.exceptions import *
from pyprofibus.phy_fpga_driver.messages import *
from pyprofibus.phy_fpga_driver.io import *
from pyprofibus.util import monotonic_time, FaultDebouncer
import time
#
# Driver for FPGA based PROFIBUS PHY.
#
# Copyright (c) 2019 Michael Buesch <m@bues.ch>
#
# Licensed under the terms of the GNU General Public License version 2,
# or (at your option) any later version.
#

from __future__ import division, absolute_import, print_function, unicode_literals




__all__ = [
	"FpgaPhyDriver",
]


class FpgaPhyDriver(object):
	"""Driver for FPGA based PROFIBUS PHY.
	"""

	FPGA_CLK_HZ		= 24 * 1e6
	PING_INTERVAL		= 0.1
	DEB_INTERVAL		= 1.0

	def __init__(self, spiDev=0, spiChipSelect=0, spiSpeedHz=1000000):
		self.__baudrate = 9600
		self.__ioProc = None

# Path: pyprofibus/util.py
# def monotonic_time():
# 	return time.ticks_ms() / 1e3
# 
# class FaultDebouncer(object):
# 	"""Fault counter/debouncer.
# 	"""
# 
# 	__slots__ = (
# 		"__countMax",
# 		"__count",
# 	)
# 
# 	def __init__(self, countMax = 0xFFFF):
# 		self.__countMax = countMax
# 		self.reset()
# 
# 	def reset(self):
# 		self.__count = 0
# 
# 	def inc(self):
# 		if self.__count < self.__countMax - 2:
# 			self.__count += 2
# 		return (self.__count + 1) // 2
# 
# 	def dec(self):
# 		if self.__count > 0:
# 			self.__count -= 1
# 		return (self.__count + 1) // 2
# 
# 	fault = inc
# 	ok = dec
# 
# 	def get(self):
# 		return (self.__count + 1) // 2


# Path: pyprofibus/phy_fpga_driver/driver.py
from pyprofibus.compat import *
from pyprofibus.phy_fpga_driver.exceptions import *
from pyprofibus.phy_fpga_driver.messages import *
from pyprofibus.phy_fpga_driver.io import *
from pyprofibus.util import monotonic_time, FaultDebouncer
import time

#
# Driver for FPGA based PROFIBUS PHY.
#
# Copyright (c) 2019 Michael Buesch <m@bues.ch>
#
# Licensed under the terms of the GNU General Public License version 2,
# or (at your option) any later version.
#

from __future__ import division, absolute_import, print_function, unicode_literals




__all__ = [
	"FpgaPhyDriver",
]


class FpgaPhyDriver(object):
	"""Driver for FPGA based PROFIBUS PHY.
	"""

	FPGA_CLK_HZ		= 24 * 1e6
	PING_INTERVAL		= 0.1
	DEB_INTERVAL		= 1.0

	def __init__(self, spiDev=0, spiChipSelect=0, spiSpeedHz=1000000):
		self.__baudrate = 9600
		self.__ioProc = None

		self.__nextPing = monotonic_time()