389 from pycde.types
import List, StructType, Window
394 bulk_count_width = 16
397 coord_type = StructType([(
"x", Bits(32)), (
"y", Bits(32))])
400 arg_struct_type = StructType([
401 (
"x_translation", Bits(32)),
402 (
"y_translation", Bits(32)),
403 (
"coords", List(coord_type)),
405 arg_window_type = Window(
414 (
"coords", 0, bulk_count_width),
419 [(
"coords", items_per_frame, 0)],
425 result_struct_type = StructType([(
"coords", List(coord_type))])
426 result_window_type = Window(
427 "serial_coord_result",
432 [(
"coords", 0, bulk_count_width)],
436 [(
"coords", items_per_frame, 0)],
441 result_chan = Wire(Channel(result_window_type))
442 args = esi.FuncService.get_call_chans(
443 AppID(
"translate_coords_serial"),
444 arg_type=arg_window_type,
449 in_ready = Wire(Bits(1))
450 in_window, in_valid = args.unwrap(in_ready)
451 in_union = in_window.unwrap()
453 hdr_frame = in_union[
"header"]
454 data_frame = in_union[
"data"]
456 hdr_x = hdr_frame[
"x_translation"].as_uint(32)
457 hdr_y = hdr_frame[
"y_translation"].as_uint(32)
458 hdr_count_bits = hdr_frame[
"coords_count"]
459 hdr_count = hdr_count_bits.as_uint(bulk_count_width)
461 out_hdr_struct_ty = result_window_type.lowered_type.header
462 out_data_struct_ty = result_window_type.lowered_type.data
465 out_ready_wire = Wire(Bits(1))
466 handshake = in_valid & out_ready_wire
478 hdr_handshake = handshake & in_is_header
479 hdr_handshake.when_true(
480 lambda: print_info(
"Received frame count=%d", hdr_count_bits))
484 hdr_is_zero = hdr_count == UInt(bulk_count_width)(0)
485 footer_handshake = hdr_handshake & hdr_is_zero
486 start_handshake = hdr_handshake & ~hdr_is_zero
487 message_active = ControlReg(
490 asserts=[start_handshake],
491 resets=[footer_handshake],
492 name=
"message_active",
495 UInt(bulk_count_width),
502 count_reg.assign(hdr_count)
504 data_handshake = handshake & ~in_is_header
505 data_count = Counter(bulk_count_width)(
509 increment=data_handshake,
510 instance_name=
"data_count",
514 x_translation_reg = Reg(
519 ce=start_handshake & ~message_active,
520 name=
"x_translation",
522 y_translation_reg = Reg(
527 ce=start_handshake & ~message_active,
528 name=
"y_translation",
530 x_translation_reg.assign(hdr_x)
531 y_translation_reg.assign(hdr_y)
534 count_minus_one = (count_reg -
535 UInt(bulk_count_width)(1)).as_uint(bulk_count_width)
536 data_last = data_count == count_minus_one
537 next_is_header = Mux(in_is_header, data_last, hdr_is_zero)
538 in_is_header.assign(next_is_header)
541 out_hdr_struct = out_hdr_struct_ty(
542 {
"coords_count": hdr_count.as_bits(bulk_count_width)})
544 in_coord = data_frame[
"coords"][0]
545 in_x = in_coord[
"x"].as_uint(32)
546 in_y = in_coord[
"y"].as_uint(32)
547 translated_x = (x_translation_reg + in_x).as_uint(32)
548 translated_y = (y_translation_reg + in_y).as_uint(32)
549 out_coord = coord_type({
550 "x": translated_x.as_bits(32),
551 "y": translated_y.as_bits(32),
553 out_data_struct = out_data_struct_ty({
"coords": [out_coord]})
555 out_union_hdr = result_window_type.lowered_type((
"header", out_hdr_struct))
556 out_union_data = result_window_type.lowered_type((
"data", out_data_struct))
557 out_union = Mux(in_is_header, out_union_data, out_union_hdr)
558 out_window = result_window_type.wrap(out_union)
560 out_chan, out_ready = Channel(result_window_type).
wrap(out_window, in_valid)
561 out_ready_wire.assign(out_ready)
563 in_ready.assign(out_ready)
564 result_chan.assign(out_chan)