20from .header
import ConfigMainHeader, Data32bitHeader, ConfigSubHeader
21from .packet
import ConfigPacket, Data32bitPacket
25 def __init__(self, api_object, interface_id, direction):
26 """ constructor for the async interface
27 @param api_object: uC_api parent object
28 @param interface_id: id of the interface this object
is responcible
for
29 @param direction:
"TO_CHIP" or "FROM_CHIP"
70 self.
__api = api_object
75 self.
__name =
"ASYNC_"+direction+str(interface_id)
76 if direction ==
"TO_CHIP":
77 self.
__name =
"ASYNC_"+direction+str(interface_id)
80 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_TO_CHIP0, Data32bitHeader.IN_ASYNC_TO_CHIP0]
81 elif interface_id == 1:
82 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_TO_CHIP1, Data32bitHeader.IN_ASYNC_TO_CHIP1]
83 elif interface_id == 2:
84 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_TO_CHIP2, Data32bitHeader.IN_ASYNC_TO_CHIP2]
85 elif interface_id == 3:
86 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_TO_CHIP3, Data32bitHeader.IN_ASYNC_TO_CHIP3]
87 elif interface_id == 4:
88 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_TO_CHIP4, Data32bitHeader.IN_ASYNC_TO_CHIP4]
89 elif interface_id == 5:
90 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_TO_CHIP5, Data32bitHeader.IN_ASYNC_TO_CHIP5]
91 elif interface_id == 6:
92 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_TO_CHIP6, Data32bitHeader.IN_ASYNC_TO_CHIP6]
93 elif interface_id == 7:
94 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_TO_CHIP7, Data32bitHeader.IN_ASYNC_TO_CHIP7]
96 logging.error(
"only 8 AER to chip interfaces are supported at the moment")
97 elif direction ==
"FROM_CHIP":
99 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_FROM_CHIP0, Data32bitHeader.OUT_ASYNC_FROM_CHIP0]
100 elif interface_id == 1:
101 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_FROM_CHIP1, Data32bitHeader.OUT_ASYNC_FROM_CHIP1]
102 elif interface_id == 2:
103 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_FROM_CHIP2, Data32bitHeader.OUT_ASYNC_FROM_CHIP2]
104 elif interface_id == 3:
105 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_FROM_CHIP3, Data32bitHeader.OUT_ASYNC_FROM_CHIP3]
106 elif interface_id == 4:
107 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_FROM_CHIP4, Data32bitHeader.OUT_ASYNC_FROM_CHIP4]
108 elif interface_id == 5:
109 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_FROM_CHIP5, Data32bitHeader.OUT_ASYNC_FROM_CHIP5]
110 elif interface_id == 6:
111 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_FROM_CHIP6, Data32bitHeader.OUT_ASYNC_FROM_CHIP6]
112 elif interface_id == 7:
113 self.
__header = [ConfigMainHeader.IN_CONF_ASYNC_FROM_CHIP7, Data32bitHeader.OUT_ASYNC_FROM_CHIP7]
115 logging.error(
"only 8 AER to chip interfaces are supported at the moment")
117 logging.error(
"AER unknown direction only TO_CHIP and FROM CHIP allowed")
121 state_str = (
"active" if self.
__status == 2
else (
"activation pending" if self.
__status == 1
else (
"not active" if self.
__status == 0
else "error" )))
123 "\nHeader: " + str(self.
__header) + \
132 "\nERRORS: "+str(self.
__errors) +
"\n"
135 """ get the header this object is responcible for
136 @return: list of headers
141 """ get the human readable status of the interface
142 @return: tuple of status
and timestamp
145 state_str = ("active" if self.
__status == 2
else (
"activation pending" if self.
__status == 1
else (
"not active" if self.
__status == 0
else "error" )))
149 """ get the human readable type of the interface
150 @return: tuple of type
and timestamp of to what
and when the type was actually set on the uC)
156 """ get the data pins of the interface as they are on the uC
157 @return: tuple of data pins
and their timestamps of to what
and when the pins were actually set on the uC
163 """ get the data width of the interface as it is on the uC
164 @return: tuple of data width
and its timestamp of to what
and when the width was actually set on the uC
170 """ get the request pin of the interface as it is on the uC
171 @return: tuple of request pin
and its timestamp of to what
and when the pin was actually set on the uC
177 """ get the ack pin of the interface as it is on the uC
178 @return: tuple of ack pin
and its timestamp of to what
and when the pin was actually set on the uC
184 """ get the request delay of the interface as it is on the uC
185 @return: tuple of request delay
and its timestamp of to what
and when the delay was actually set on the uC
191 """ get the data recived from the chip
192 will retun 2 lists: one with the word recoded
and one
with the time when it was recorded, linked by index
193 @return: tuple of the of data list
and their timestamp list - index matched
199 """ get the data send to the chip when they are actually send off by the uC
200 data_to_chip will retun the data send by the uC to the device under test (DUT)
202 will retun 2 lists: one with the word send
and one
with the exact time when it was send, linked by index
204 the time might differ slightly
from the time you sheduled the send word,
205 as it
is the time when it was send out
and the uC can only send one word at a time
207 @return: tuple of the of data list
and their timestamp list (of when the uC send them) - index matched
213 """ get the data recived from the chip and clear the buffer
214 will retun 2 lists: one with the word recoded
and one
with the time when it was recorded, linked by index
216 @return: tuple of the of data list
and their timestamp list - index matched
226 """ get the data send to the chip when they are actually send off by the uC and clear the buffer
227 data_to_chip will retun the data send by the uC to the device under test (DUT)
229 will retun 2 lists: one with the word send
and one
with the exact time when it was send, linked by index
231 the time might differ slightly
from the time you sheduled the send word,
232 as it
is the time when it was send out
and the uC can only send one word at a time
234 @return: tuple of the of data list
and their timestamp list (of when the uC send them) - index matched
244 """ get the list of errors associated with this interface object
245 @return: list of errors
252 """ process a packet from the uC, update the status of the interface object and store the data
253 @param packet: packet object to be processed
255 if packet.header()
in self.
__header:
257 if packet.header() == self.
__header[0]:
259 if packet.config_header() == ConfigSubHeader.CONF_ACTIVE:
264 elif packet.config_header() == ConfigSubHeader.CONF_TYPE:
265 """@todo replace with type"""
266 if packet.value() == 0:
267 self.
__mode =
"4Phase_Chigh_Dhigh"
268 elif packet.value() == 1:
269 self.
__mode =
"4Phase_Clow_Dhigh"
270 elif packet.value() == 10:
272 elif packet.value() == 20:
273 self.
__mode =
"4Phase_MCP23017"
275 logging.error(
"unknown async type returned")
279 elif packet.config_header() == ConfigSubHeader.CONF_ACK:
284 elif packet.config_header() == ConfigSubHeader.CONF_REQ:
289 elif packet.config_header() == ConfigSubHeader.CONF_WIDTH:
294 elif packet.config_header() < 32:
295 self.
__data_pins[packet.config_header()] = packet.value()
299 elif packet.config_header() == ConfigSubHeader.CONF_REQ_DELAY:
304 elif packet.header() == self.
__header[1]:
317 def activate(self, req_pin, ack_pin, data_width, data_pins, mode="4Phase_Chigh_Dhigh", req_delay = 0, time = 0):
318 """ activate the interface on the uC with the given parameters
321 - "4Phase_Chigh_Dhigh" means 4 phase clock
with high active clock
and high active data
322 -
"4Phase_Clow_Dhigh" means 4 phase clock
with low active clock
and high active data
323 -
"2Phase" means 2 phase clock
with high active data
324 -
"4Phase_MCP23017" means 4 phase clock
with high active clock
and high active data
and MCP23017 port extender, pin IDs are
not used
in this mode
326 @param req_pin: request pin id on the uC
327 @param ack_pin: ack pin id on the uC
328 @param data_width: data width of the interface
329 @param data_pins: list of data pin ids on the uC
330 @param mode: mode of the interface -
"4Phase_Chigh_Dhigh",
"4Phase_Clow_Dhigh",
"2Phase",
"4Phase_MCP23017"
331 @param req_delay: how much the request of the handshake
is delayed multiplied by 20us
332 @param time: the exec_time when the uc should activate the interface, 0 means
as soon
as possible
336 logging.warning(
"ASYNC_to_chip interface "+str(self.
__header[0])+
" is already activated or waiting activation, doing nothing")
339 if mode ==
"4Phase_Chigh_Dhigh":
340 self.
__api.send_packet(
ConfigPacket(header = self.
__header[0], config_header = ConfigSubHeader.CONF_TYPE, value = 0, time = time))
342 elif mode ==
"4Phase_Clow_Dhigh":
343 self.
__api.send_packet(
ConfigPacket(header = self.
__header[0], config_header = ConfigSubHeader.CONF_TYPE, value = 1, time = time))
345 elif mode ==
"2Phase_Chigh_Dhigh":
346 logging.warning(
"pin mode not implmented yet")
348 elif mode ==
"2Phase_Clow_Dhigh":
349 logging.warning(
"pin mode not implmented yet")
351 elif mode ==
"4Phase_MCP23017":
352 self.
__api.send_packet(
ConfigPacket(header = self.
__header[0], config_header = ConfigSubHeader.CONF_TYPE, value = 20, time = time))
355 logging.error(
"pin.activate got wrong type "+str(pin_mode)+
" only 4Phase_Chigh_Dhigh, 4Phase_Clow_Dhigh, 2Phase_Chigh_Dhigh, 2Phase_Clow_Dhigh are allowed, more modes implemted on request")
357 self.
__api.send_packet(
ConfigPacket(header = self.
__header[0], config_header = ConfigSubHeader.CONF_ACK, value = ack_pin, time = time))
358 self.
__api.send_packet(
ConfigPacket(header = self.
__header[0], config_header = ConfigSubHeader.CONF_REQ, value = req_pin, time = time))
359 self.
__api.send_packet(
ConfigPacket(header = self.
__header[0], config_header = ConfigSubHeader.CONF_WIDTH, value = data_width, time = time))
360 for pin
in range(data_width):
362 self.
__api.send_packet(
ConfigPacket(header = self.
__header[0], config_header = ConfigSubHeader.CONF_REQ_DELAY, value = req_delay, time = time))
364 self.
__api.send_packet(
ConfigPacket(header = self.
__header[0], config_header = ConfigSubHeader.CONF_ACTIVE, time = time))
368 def send(self, word, time = 0):
369 """ send a word to the chip
370 @param word: word to be send
371 @param time: the exec_time when the uc should send the word, 0 means
as soon
as possible
379 logging.error(
"AER to chip interface "+str(self.
__header[1])+
" is reading interface - word is not sent.")
382 self.
__api.update_state()
def status(self)
get the human readable status of the interface
def process_packet(self, packet)
process a packet from the uC, update the status of the interface object and store the data
def __init__(self, api_object, interface_id, direction)
constructor for the async interface
def data_to_chip_and_clear(self)
get the data send to the chip when they are actually send off by the uC and clear the buffer data_to_...
def data_from_chip_and_clear(self)
get the data recived from the chip and clear the buffer will retun 2 lists: one with the word recoded...
def send(self, word, time=0)
send a word to the chip
def interface_type(self)
get the human readable type of the interface
def activate(self, req_pin, ack_pin, data_width, data_pins, mode="4Phase_Chigh_Dhigh", req_delay=0, time=0)
activate the interface on the uC with the given parameters
def data_width(self)
get the data width of the interface as it is on the uC
def req_delay(self)
get the request delay of the interface as it is on the uC
def data_pins(self)
get the data pins of the interface as they are on the uC
def ack_pin(self)
get the ack pin of the interface as it is on the uC
def req_pin(self)
get the request pin of the interface as it is on the uC
def errors(self)
get the list of errors associated with this interface object
def data_from_chip(self)
get the data recived from the chip will retun 2 lists: one with the word recoded and one with the tim...
def data_to_chip(self)
get the data send to the chip when they are actually send off by the uC data_to_chip will retun the d...
The ConfigPacket is used to cumunicate configuration instructions with the uC all availible instructi...
The Data32bitPacket is used to send 32bit data instructions to the uC all availible instructions are ...