386 from pycde.types
import List, StructType, Window
391 bulk_count_width = 16
394 coord_type = StructType([(
"x", Bits(32)), (
"y", Bits(32))])
397 arg_struct_type = StructType([
398 (
"x_translation", Bits(32)),
399 (
"y_translation", Bits(32)),
400 (
"coords", List(coord_type)),
402 arg_window_type = Window(
411 (
"coords", 0, bulk_count_width),
416 [(
"coords", items_per_frame, 0)],
422 result_struct_type = StructType([(
"coords", List(coord_type))])
423 result_window_type = Window(
424 "serial_coord_result",
429 [(
"coords", 0, bulk_count_width)],
433 [(
"coords", items_per_frame, 0)],
438 result_chan = Wire(Channel(result_window_type))
439 args = esi.FuncService.get_call_chans(
440 AppID(
"translate_coords_serial"),
441 arg_type=arg_window_type,
446 in_ready = Wire(Bits(1))
447 in_window, in_valid = args.unwrap(in_ready)
448 in_union = in_window.unwrap()
450 hdr_frame = in_union[
"header"]
451 data_frame = in_union[
"data"]
453 hdr_x = hdr_frame[
"x_translation"].as_uint(32)
454 hdr_y = hdr_frame[
"y_translation"].as_uint(32)
455 hdr_count_bits = hdr_frame[
"coords_count"]
456 hdr_count = hdr_count_bits.as_uint(bulk_count_width)
458 out_hdr_struct_ty = result_window_type.lowered_type.header
459 out_data_struct_ty = result_window_type.lowered_type.data
462 out_ready_wire = Wire(Bits(1))
463 handshake = in_valid & out_ready_wire
475 hdr_handshake = handshake & in_is_header
476 hdr_handshake.when_true(
477 lambda: print_info(
"Received frame count=%d", hdr_count_bits))
481 hdr_is_zero = hdr_count == UInt(bulk_count_width)(0)
482 footer_handshake = hdr_handshake & hdr_is_zero
483 start_handshake = hdr_handshake & ~hdr_is_zero
484 message_active = ControlReg(
487 asserts=[start_handshake],
488 resets=[footer_handshake],
489 name=
"message_active",
492 UInt(bulk_count_width),
499 count_reg.assign(hdr_count)
501 data_handshake = handshake & ~in_is_header
502 data_count = Counter(bulk_count_width)(
506 increment=data_handshake,
507 instance_name=
"data_count",
511 x_translation_reg = Reg(
516 ce=start_handshake & ~message_active,
517 name=
"x_translation",
519 y_translation_reg = Reg(
524 ce=start_handshake & ~message_active,
525 name=
"y_translation",
527 x_translation_reg.assign(hdr_x)
528 y_translation_reg.assign(hdr_y)
531 count_minus_one = (count_reg -
532 UInt(bulk_count_width)(1)).as_uint(bulk_count_width)
533 data_last = data_count == count_minus_one
534 next_is_header = Mux(in_is_header, data_last, hdr_is_zero)
535 in_is_header.assign(next_is_header)
538 out_hdr_struct = out_hdr_struct_ty(
539 {
"coords_count": hdr_count.as_bits(bulk_count_width)})
541 in_coord = data_frame[
"coords"][0]
542 in_x = in_coord[
"x"].as_uint(32)
543 in_y = in_coord[
"y"].as_uint(32)
544 translated_x = (x_translation_reg + in_x).as_uint(32)
545 translated_y = (y_translation_reg + in_y).as_uint(32)
546 out_coord = coord_type({
547 "x": translated_x.as_bits(32),
548 "y": translated_y.as_bits(32),
550 out_data_struct = out_data_struct_ty({
"coords": [out_coord]})
552 out_union_hdr = result_window_type.lowered_type((
"header", out_hdr_struct))
553 out_union_data = result_window_type.lowered_type((
"data", out_data_struct))
554 out_union = Mux(in_is_header, out_union_data, out_union_hdr)
555 out_window = result_window_type.wrap(out_union)
557 out_chan, out_ready = Channel(result_window_type).
wrap(out_window, in_valid)
558 out_ready_wire.assign(out_ready)
560 in_ready.assign(out_ready)
561 result_chan.assign(out_chan)