Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

bank/eventmanager: refactor, rename EventSourceLevel -> EventSourcePr…

…ocess, add fully externally controlled event source
  • Loading branch information...
commit b9b6df6f291f8d1377f5175adc050a900bf9404e 1 parent 7a74dae
Sébastien Bourdeauducq authored May 08, 2013

Showing 1 changed file with 42 additions and 34 deletions. Show diff stats Hide diff stats

  1. 76  migen/bank/eventmanager.py
76  migen/bank/eventmanager.py
@@ -6,14 +6,41 @@
6 6
 class _EventSource(HUID):
7 7
 	def __init__(self):
8 8
 		HUID.__init__(self)
9  
-		self.trigger = Signal()
10  
-		self.pending = Signal()
  9
+		self.status = Signal() # value in the status register
  10
+		self.pending = Signal() # value in the pending register + assert irq if unmasked
  11
+		self.trigger = Signal() # trigger signal interface to the user design
  12
+		self.clear = Signal() # clearing attempt by W1C to pending register, ignored by some event sources
11 13
 
12  
-class EventSourcePulse(_EventSource):
13  
-	pass
  14
+# set on a positive trigger pulse
  15
+class EventSourcePulse(Module, _EventSource):
  16
+	def __init__(self):
  17
+		_EventSource.__init__(self)
  18
+		self.comb += self.status.eq(0)
  19
+		self.sync += [
  20
+			If(self.clear, self.pending.eq(0)),
  21
+			If(self.trigger, self.pending.eq(1))
  22
+		]
  23
+
  24
+# set on the falling edge of the trigger, status = trigger
  25
+class EventSourceProcess(Module, _EventSource):
  26
+	def __init__(self):
  27
+		_EventSource.__init__(self)
  28
+		self.comb += self.status.eq(self.trigger)
  29
+		old_trigger = Signal()
  30
+		self.sync += [
  31
+			If(self.clear, self.pending.eq(0)),
  32
+			old_trigger.eq(self.trigger),
  33
+			If(~self.trigger & old_trigger, self.pending.eq(1))
  34
+		]
14 35
 
15  
-class EventSourceLevel(_EventSource):
16  
-	pass
  36
+# all status set by external trigger
  37
+class EventSourceLevel(Module, _EventSource):
  38
+	def __init__(self):
  39
+		_EventSource.__init__(self)
  40
+		self.comb += [
  41
+			self.status.eq(self.trigger),
  42
+			self.pending.eq(self.trigger)
  43
+		]
17 44
 
18 45
 class EventManager(Module, AutoCSR):
19 46
 	def __init__(self):
@@ -27,38 +54,19 @@ def do_finalize(self):
27 54
 		self.pending = CSR(n)
28 55
 		self.enable = CSRStorage(n)
29 56
 
30  
-		# status
31  
-		for i, source in enumerate(sources):
32  
-			if isinstance(source, EventSourcePulse):
33  
-				self.comb += self.status.w[i].eq(0)
34  
-			elif isinstance(source, EventSourceLevel):
35  
-				self.comb += self.status.w[i].eq(source.trigger)
36  
-			else:
37  
-				raise TypeError
38  
-		
39  
-		# pending
40 57
 		for i, source in enumerate(sources):
41  
-			# W1C
42  
-			self.sync += If(self.pending.re & self.pending.r[i], source.pending.eq(0))
43  
-			if isinstance(source, EventSourcePulse):
44  
-				# set on a positive trigger pulse
45  
-				self.sync += If(source.trigger, source.pending.eq(1))
46  
-			elif isinstance(source, EventSourceLevel):
47  
-				# set on the falling edge of the trigger
48  
-				old_trigger = Signal()
49  
-				self.sync += [
50  
-					old_trigger.eq(source.trigger),
51  
-					If(~source.trigger & old_trigger, source.pending.eq(1))
52  
-				]
53  
-			else:
54  
-				raise TypeError
55  
-			self.comb += self.pending.w[i].eq(source.pending)
  58
+			self.comb += [
  59
+				self.status.w[i].eq(source.status),
  60
+				If(self.pending.re & self.pending.r[i], source.clear.eq(1)),
  61
+				self.pending.w[i].eq(source.pending)
  62
+			]
56 63
 		
57  
-		# IRQ
58 64
 		irqs = [self.pending.w[i] & self.enable.storage[i] for i in range(n)]
59 65
 		self.comb += self.irq.eq(optree("|", irqs))
60 66
 
61 67
 	def __setattr__(self, name, value):
62  
-		if isinstance(value, _EventSource) and self.finalized:
63  
-			raise FinalizeError
64 68
 		object.__setattr__(self, name, value)
  69
+		if isinstance(value, _EventSource):
  70
+			if self.finalized:
  71
+				raise FinalizeError
  72
+			self.submodules += value

0 notes on commit b9b6df6

Please sign in to comment.
Something went wrong with that request. Please try again.