public Func <List <UInt32> > reg_read_repeat(UInt16 num_repeats, REG_APnDP_A3_A2 reg_id, byte dap_index = 0, bool now = true) { //Debug.Assert(num_repeats is six.integer_types); Debug.Assert(Enum.IsDefined(typeof(REG_APnDP_A3_A2), reg_id)); //Debug.Assert(dap_index is six.integer_types); //Debug.Assert(now is @bool); EDapTransferRequestByte request = DebugUnitV2_0_0.DapReadTransferRequestByte(reg_id); var transfer = this._write(dap_index, num_repeats, request, null); Debug.Assert(transfer != null); List <uint> reg_read_repeat_cb() { List <UInt32> res = transfer.get_result(); Debug.Assert(res.Count == num_repeats); return(res); } if (now) { List <UInt32> result = reg_read_repeat_cb(); return(new Func <List <UInt32> >(() => result)); } else { return(new Func <List <UInt32> >(() => reg_read_repeat_cb())); } }
public Func <UInt32> read_reg(REG_APnDP_A3_A2 reg_id, byte dap_index = 0, bool now = true) { Debug.Assert(Enum.IsDefined(typeof(REG_APnDP_A3_A2), reg_id)); EDapTransferRequestByte request = DebugUnitV2_0_0.DapReadTransferRequestByte(reg_id); var transfer = this._write(dap_index, 1, request, null); Debug.Assert(transfer != null); uint read_reg_cb() { List <UInt32> res = transfer.get_result(); Debug.Assert(res.Count == 1); return(res[0]); } if (now) { UInt32 result = read_reg_cb(); return(new Func <UInt32>(() => result)); } else { return(new Func <UInt32>(() => read_reg_cb())); } }
// // Add a single or block register transfer operation to this command // public virtual void add(UInt16 count, EDapTransferRequestByte request, List <UInt32> data, byte dap_index) { Debug.Assert(this._data_encoded == false); if (this._dap_index == null) { this._dap_index = dap_index; } Debug.Assert(this._dap_index == dap_index); if (this._block_request == null) { this._block_request = request; } else if (request != this._block_request) { this._block_allowed = false; } Debug.Assert(!this._block_allowed || this._block_request == request); if ((request & EDapTransferRequestByte.READ) != 0) { this._read_count += count; } else { this._write_count += count; } this._data.Add(Tuple.Create(count, request, data)); if (DapAccessConsts.LOG_PACKET_BUILDS) { //Trace.TraceInformation(String.Format("add(%d, %02x:%s) -> [wc=%d, rc=%d, ba=%d]", count, request, request & READ ? "r" : "w", this._write_count, this._read_count, this._block_allowed)); } }
public void write_reg(REG_APnDP_A3_A2 reg_id, UInt32 value, byte dap_index = 0) { Debug.Assert(Enum.IsDefined(typeof(REG_APnDP_A3_A2), reg_id)); EDapTransferRequestByte request = DebugUnitV2_0_0.DapWriteTransferRequestByte(reg_id); this._write(dap_index, 1, request, new List <UInt32> { value }); }
public void reg_write_repeat(UInt16 num_repeats, REG_APnDP_A3_A2 reg_id, List <UInt32> data_array, byte dap_index = 0) { //Debug.Assert(num_repeats is six.integer_types); Debug.Assert(num_repeats == data_array.Count); Debug.Assert(Enum.IsDefined(typeof(REG_APnDP_A3_A2), reg_id)); //Debug.Assert(dap_index is six.integer_types); EDapTransferRequestByte request = DebugUnitV2_0_0.DapWriteTransferRequestByte(reg_id); this._write(dap_index, num_repeats, request, data_array); }
public static EDapTransferRequestByte DapWriteTransferRequestByte(REG_APnDP_A3_A2 reg_id) { Debug.Assert(Enum.IsDefined(typeof(REG_APnDP_A3_A2), reg_id)); EDapTransferRequestByte request = EDapTransferRequestByte.WRITE; if ((int)reg_id < 4) { request |= EDapTransferRequestByte.DP_ACC; } else { request |= EDapTransferRequestByte.AP_ACC; } request |= (EDapTransferRequestByte)((int)reg_id % 4 * 4); return(request); }
// // Encode this command into a byte array that can be sent // // The data returned by this function is a bytearray in // the format that of a DAP_TransferBlock CMSIS-DAP command. // public virtual byte[] _encode_transfer_block_data() { Debug.Assert(this.get_empty() == false); byte[] buf = new byte[this._size]; UInt16 transfer_count = (UInt16)(this._read_count + this._write_count); Debug.Assert(!(this._read_count != 0 && this._write_count != 0)); Debug.Assert(this._block_request != null); var pos = 0; buf[pos] = (byte)EDapCommandByte.DAP_TRANSFER_BLOCK; pos += 1; buf[pos] = (byte)this._dap_index; pos += 1; buf[pos] = (byte)(transfer_count & 0xFF); pos += 1; buf[pos] = (byte)((transfer_count >> 8) & 0xFF); pos += 1; buf[pos] = (byte)this._block_request; pos += 1; foreach (var _tup_1 in this._data) { UInt32 count = _tup_1.Item1; EDapTransferRequestByte request = _tup_1.Item2; List <UInt32> write_list = _tup_1.Item3; Debug.Assert(write_list == null || write_list.Count <= count); Debug.Assert(request == this._block_request); var write_pos = 0; if ((request & EDapTransferRequestByte.READ) == 0) { foreach (var _ in Enumerable.Range(0, (int)count)) { buf[pos] = (byte)((write_list[write_pos] >> (8 * 0)) & 0xFF); pos += 1; buf[pos] = (byte)((write_list[write_pos] >> (8 * 1)) & 0xFF); pos += 1; buf[pos] = (byte)((write_list[write_pos] >> (8 * 2)) & 0xFF); pos += 1; buf[pos] = (byte)((write_list[write_pos] >> (8 * 3)) & 0xFF); pos += 1; write_pos += 1; } } } return(buf); }
public virtual UInt16 get_request_space(UInt16 count, EDapTransferRequestByte request, byte dap_index) { Debug.Assert(this._data_encoded == false); // Must create another command if the dap index is different. if (this._dap_index != null && dap_index != this._dap_index) { return(0); } // Block transfers must use the same request. var blockAllowed = this._block_allowed; if (this._block_request != null && request != this._block_request) { blockAllowed = false; } // Compute the portion of the request that will fit in this packet. bool is_read = (request & EDapTransferRequestByte.READ) != 0; UInt16 free = this._get_free_words(blockAllowed, is_read); int size = Math.Min(count, free); // Non-block transfers only have 1 byte for request count. if (!blockAllowed) { UInt16 max_count = (UInt16)(this._write_count + this._read_count + size); int delta = max_count - 255; size = Math.Min(size - delta, size); if (DapAccessConsts.LOG_PACKET_BUILDS) { Trace.TraceInformation(String.Format("get_request_space(%d, %02x:%s)[wc=%d, rc=%d, ba=%d->%d] -> (sz=%d, free=%d, delta=%d)", count, request, is_read ? "r" : "w", this._write_count, this._read_count, this._block_allowed, blockAllowed, size, free, delta)); } } else if (DapAccessConsts.LOG_PACKET_BUILDS) { Trace.TraceInformation(String.Format("get_request_space(%d, %02x:%s)[wc=%d, rc=%d, ba=%d->%d] -> (sz=%d, free=%d)", count, request, is_read ? "r" : "w", this._write_count, this._read_count, this._block_allowed, blockAllowed, size, free)); } // We can get a negative free count if the packet already contains more data than can be // sent by a DAP_Transfer command, but the new request forces DAP_Transfer. In this case, // just return 0 to force the DAP_Transfer_Block to be sent. return((UInt16)Math.Max(size, 0)); }
public Transfer( DapAccessLink daplink, byte dap_index, UInt16 transfer_count, EDapTransferRequestByte transfer_request, List <UInt32> transfer_data) { // Writes should not need a transfer object // since they don't have any response data Debug.Assert((transfer_request & EDapTransferRequestByte.READ) != 0); this.daplink = daplink; this.dap_index = dap_index; this.transfer_count = transfer_count; this.transfer_request = transfer_request; this.transfer_data = transfer_data; this._size_bytes = 0; if ((transfer_request & EDapTransferRequestByte.READ) != 0) { this._size_bytes = (UInt32)(transfer_count * 4); } this._result = null; this._error = null; }
// // Write one or more commands // public virtual Transfer _write(byte dap_index, UInt16 transfer_count, EDapTransferRequestByte transfer_request, List <UInt32> transfer_data) { List <UInt32> data; Debug.Assert(dap_index == 0); Debug.Assert(transfer_data == null || transfer_data.Count > 0); // Create transfer and add to transfer list Transfer transfer = null; if ((transfer_request & EDapTransferRequestByte.READ) != 0) { transfer = new Transfer(this, dap_index, transfer_count, transfer_request, transfer_data); this._transfer_list.Add(transfer); } // Build physical packet by adding it to command var cmd = this._crnt_cmd; var is_read = transfer_request & EDapTransferRequestByte.READ; UInt16 size_to_transfer = transfer_count; UInt16 trans_data_pos = 0; while (size_to_transfer > 0) { // Get the size remaining in the current packet for the given request. UInt16 size = cmd.get_request_space(size_to_transfer, transfer_request, dap_index); // This request doesn't fit in the packet so send it. if (size == 0) { if (DapAccessConsts.LOG_PACKET_BUILDS) { Trace.TraceInformation("_write: send packet [size==0]"); } this._send_packet(); cmd = this._crnt_cmd; continue; } // Add request to packet. if (transfer_data == null) { data = null; } else { data = transfer_data.GetRange(trans_data_pos, size); } cmd.add(size, transfer_request, data, dap_index); size_to_transfer -= size; trans_data_pos += size; // Packet has been filled so send it if (cmd.get_full()) { if (DapAccessConsts.LOG_PACKET_BUILDS) { Trace.TraceInformation("_write: send packet [full]"); } this._send_packet(); cmd = this._crnt_cmd; } } if (!this._deferred_transfer) { this.flush(); } return(transfer); }