# 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.
	"""

	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()
		self.__receivedPong = False
		self.__spiDev = spiDev
		self.__spiChipSelect = spiChipSelect
		self.__spiSpeedHz = spiSpeedHz

		try:
			self.__startup()
		except FpgaPhyError as e:
			try:
				self.shutdown()
			except FpgaPhyError:
				pass
			raise e

	def __startup(self):
		"""Startup the driver.
		"""
		self.shutdown()


# 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.
	"""

	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()
		self.__receivedPong = False
		self.__spiDev = spiDev
		self.__spiChipSelect = spiChipSelect
		self.__spiSpeedHz = spiSpeedHz

		try:
			self.__startup()
		except FpgaPhyError as e:
			try:
				self.shutdown()
			except FpgaPhyError:
				pass
			raise e

	def __startup(self):
		"""Startup the driver.
		"""
		self.shutdown()


		self.__faultParity = FaultDebouncer()