246 from pycde.types
import List, StructType, Window
251 bulk_count_width = 16
254 coord_type = StructType([(
"x", Bits(32)), (
"y", Bits(32))])
257 arg_struct_type = StructType([
258 (
"x_translation", Bits(32)),
259 (
"y_translation", Bits(32)),
260 (
"coords", List(coord_type)),
262 arg_window_type = Window(
271 (
"coords", 0, bulk_count_width),
276 [(
"coords", items_per_frame, 0)],
282 result_struct_type = StructType([(
"coords", List(coord_type))])
283 result_window_type = Window(
284 "serial_coord_result",
289 [(
"coords", 0, bulk_count_width)],
293 [(
"coords", items_per_frame, 0)],
298 result_chan = Wire(Channel(result_window_type))
299 args = esi.FuncService.get_call_chans(
300 AppID(
"translate_coords_serial"),
301 arg_type=arg_window_type,
306 in_ready = Wire(Bits(1))
307 in_window, in_valid = args.unwrap(in_ready)
308 in_union = in_window.unwrap()
310 hdr_frame = in_union[
"header"]
311 data_frame = in_union[
"data"]
313 hdr_x = hdr_frame[
"x_translation"].as_uint(32)
314 hdr_y = hdr_frame[
"y_translation"].as_uint(32)
315 hdr_count_bits = hdr_frame[
"coords_count"]
316 hdr_count = hdr_count_bits.as_uint(bulk_count_width)
318 out_hdr_struct_ty = result_window_type.lowered_type.header
319 out_data_struct_ty = result_window_type.lowered_type.data
322 out_ready_wire = Wire(Bits(1))
323 handshake = in_valid & out_ready_wire
335 hdr_handshake = handshake & in_is_header
336 hdr_handshake.when_true(
337 lambda: print_info(
"Received frame count=%d", hdr_count_bits))
341 hdr_is_zero = hdr_count == UInt(bulk_count_width)(0)
342 footer_handshake = hdr_handshake & hdr_is_zero
343 start_handshake = hdr_handshake & ~hdr_is_zero
344 message_active = ControlReg(
347 asserts=[start_handshake],
348 resets=[footer_handshake],
349 name=
"message_active",
352 UInt(bulk_count_width),
359 count_reg.assign(hdr_count)
361 data_handshake = handshake & ~in_is_header
362 data_count = Counter(bulk_count_width)(
366 increment=data_handshake,
367 instance_name=
"data_count",
371 x_translation_reg = Reg(
376 ce=start_handshake & ~message_active,
377 name=
"x_translation",
379 y_translation_reg = Reg(
384 ce=start_handshake & ~message_active,
385 name=
"y_translation",
387 x_translation_reg.assign(hdr_x)
388 y_translation_reg.assign(hdr_y)
391 count_minus_one = (count_reg -
392 UInt(bulk_count_width)(1)).as_uint(bulk_count_width)
393 data_last = data_count == count_minus_one
394 next_is_header = Mux(in_is_header, data_last, hdr_is_zero)
395 in_is_header.assign(next_is_header)
398 out_hdr_struct = out_hdr_struct_ty(
399 {
"coords_count": hdr_count.as_bits(bulk_count_width)})
401 in_coord = data_frame[
"coords"][0]
402 in_x = in_coord[
"x"].as_uint(32)
403 in_y = in_coord[
"y"].as_uint(32)
404 translated_x = (x_translation_reg + in_x).as_uint(32)
405 translated_y = (y_translation_reg + in_y).as_uint(32)
406 out_coord = coord_type({
407 "x": translated_x.as_bits(32),
408 "y": translated_y.as_bits(32),
410 out_data_struct = out_data_struct_ty({
"coords": [out_coord]})
412 out_union_hdr = result_window_type.lowered_type((
"header", out_hdr_struct))
413 out_union_data = result_window_type.lowered_type((
"data", out_data_struct))
414 out_union = Mux(in_is_header, out_union_data, out_union_hdr)
415 out_window = result_window_type.wrap(out_union)
417 out_chan, out_ready = Channel(result_window_type).
wrap(out_window, in_valid)
418 out_ready_wire.assign(out_ready)
420 in_ready.assign(out_ready)
421 result_chan.assign(out_chan)