ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
c6_hosted_frame.c
Go to the documentation of this file.
1
37
38#include <stdint.h>
39
40#include "c6_hosted.h"
41#include "esp_hosted_header.h"
42#include "esp_hosted_interface.h"
43#include "esp_hosted_os_abstraction.h"
44#include "esp_hosted_transport.h"
47#include "transport_drv.h"
48
66typedef enum : uint16_t {
67 k_c6_hosted_hdr_bytes = (uint16_t)sizeof(struct esp_payload_header),
82
102
129
143
156
170{
171 s_c6_hosted_tx.header.if_type = (uint8_t)ESP_MAX_IF;
172 s_c6_hosted_tx.header.if_num = 0U;
173 s_c6_hosted_tx.header.flags = 0U;
174 s_c6_hosted_tx.header.len = 0U;
175 s_c6_hosted_tx.header.offset = (uint16_t)k_c6_hosted_hdr_bytes;
176 s_c6_hosted_tx.header.checksum = 0U;
177 s_c6_hosted_tx.header.seq_num = 0U;
178 s_c6_hosted_tx.header.throttle_cmd = 0U;
179 s_c6_hosted_tx.header.reserved2 = 0U;
180 s_c6_hosted_tx.header.reserved3 = 0U;
181 s_c6_hosted_tx.header.checksum =
182 compute_checksum(s_c6_hosted_tx.bytes, (uint16_t)k_c6_hosted_hdr_bytes);
183}
184
201{
202 bool all_zero = true;
203 bool all_ones = true;
204 for (uint32_t i = 0U; i < (uint32_t)k_c6_hosted_frame_bytes; i++) {
205 if (s_c6_hosted_rx.bytes[i] != 0U) {
206 all_zero = false;
207 }
208 if (s_c6_hosted_rx.bytes[i] != (uint8_t)k_c6_hosted_byte_ones) {
209 all_ones = false;
210 }
211 }
212 if (all_zero) {
214 }
215 if (all_ones) {
217 }
219}
220
235static uint16_t c6_hosted_rx_checksum(void)
236{
237 uint16_t span = (uint16_t)k_c6_hosted_hdr_bytes;
238 if ((s_c6_hosted_rx.header.offset == (uint16_t)k_c6_hosted_hdr_bytes) &&
239 (s_c6_hosted_rx.header.len <= (uint16_t)k_c6_hosted_max_payload)) {
240 span = (uint16_t)(span + s_c6_hosted_rx.header.len);
241 }
242 const uint16_t saved = s_c6_hosted_rx.header.checksum;
243 s_c6_hosted_rx.header.checksum = 0U;
244 const uint16_t calc = compute_checksum(s_c6_hosted_rx.bytes, span);
245 s_c6_hosted_rx.header.checksum = saved;
246 return calc;
247}
248
271static c6_hosted_verdict_t c6_hosted_classify(int32_t rc, uint16_t calc)
272{
273 const c6_hosted_fill_t fill = c6_hosted_rx_fill();
274
275 if (rc != (int32_t)RET_OK) {
277 }
278 if (fill == k_c6_hosted_fill_zero) {
280 }
281 if (fill == k_c6_hosted_fill_ones) {
283 }
284 if ((s_c6_hosted_rx.header.if_type == (uint8_t)ESP_MAX_IF) &&
285 (s_c6_hosted_rx.header.if_num == (uint8_t)k_c6_hosted_filler_if_num) &&
286 (s_c6_hosted_rx.header.len == 0U)) {
288 }
289 if (s_c6_hosted_rx.header.offset != (uint16_t)k_c6_hosted_hdr_bytes) {
291 }
292 if (s_c6_hosted_rx.header.len > (uint16_t)k_c6_hosted_max_payload) {
294 }
295 if (s_c6_hosted_rx.header.checksum != calc) {
297 }
299}
300
317{
318 switch (verdict) {
320 return "link up";
322 return "link up -- co-processor returned its idle filler frame";
324 return "bus transfer did not return RET_OK";
326 return "receive buffer all-zero -- co-processor did not drive the bus";
328 return "receive buffer all-ones -- co-processor did not drive the bus";
330 return "header offset is not the payload-header size";
332 return "advertised length exceeds MAX_PAYLOAD_SIZE";
334 return "checksum mismatch";
335 default:
336 return "unrecognised verdict";
337 }
338}
339
352static void c6_hosted_print_rx_header(uint16_t calc)
353{
354 c6_hosted_puts("c6_hosted_init: rx if_type=");
355 c6_hosted_put_u32((uint32_t)s_c6_hosted_rx.header.if_type);
356 c6_hosted_puts(" if_num=");
357 c6_hosted_put_u32((uint32_t)s_c6_hosted_rx.header.if_num);
358 c6_hosted_puts(" flags=0x");
359 c6_hosted_put_hex((uint32_t)s_c6_hosted_rx.header.flags, (uint8_t)k_c6_hosted_hex_byte);
360 c6_hosted_puts(" len=");
361 c6_hosted_put_u32((uint32_t)s_c6_hosted_rx.header.len);
362 c6_hosted_puts(" offset=");
363 c6_hosted_put_u32((uint32_t)s_c6_hosted_rx.header.offset);
364 c6_hosted_puts(" seq_num=");
365 c6_hosted_put_u32((uint32_t)s_c6_hosted_rx.header.seq_num);
366 c6_hosted_puts(" csum=0x");
367 c6_hosted_put_hex((uint32_t)s_c6_hosted_rx.header.checksum, (uint8_t)k_c6_hosted_hex_csum);
368 c6_hosted_puts(" calc=0x");
369 c6_hosted_put_hex((uint32_t)calc, (uint8_t)k_c6_hosted_hex_csum);
370 c6_hosted_puts("\r\n");
371}
372
374{
375 struct hosted_transport_context_t ctx = {};
376
378 ctx.tx_buf = s_c6_hosted_tx.bytes;
379 ctx.tx_buf_size = (uint32_t)k_c6_hosted_frame_bytes;
380 ctx.rx_buf = s_c6_hosted_rx.bytes;
381
382 const int32_t rc = (int32_t)g_h.funcs->_h_do_bus_transfer(&ctx);
383 const uint16_t calc = c6_hosted_rx_checksum();
384 const c6_hosted_verdict_t verdict = c6_hosted_classify(rc, calc);
385
386 c6_hosted_puts("c6_hosted_init: transfer rc=");
388 c6_hosted_puts(" frame_bytes=");
390 c6_hosted_puts("\r\n");
392 const bool ok = (verdict == k_c6_hosted_verdict_pass) || (verdict == k_c6_hosted_verdict_idle);
393 c6_hosted_puts(ok ? "c6_hosted_init: PASS " : "c6_hosted_init: FAIL ");
395 c6_hosted_puts("\r\n");
396}
Shared contract for the esp-hosted port bring-up application.
union c6_hosted_frame c6_hosted_frame_t
@ k_c6_hosted_frame_bytes
Bytes clocked in one full-duplex transaction.
Definition c6_hosted.h:119
void c6_hosted_puts(const char *text)
Write a NUL-terminated string to the board console.
void c6_hosted_put_i32(int32_t value)
Emit a signed 32-bit value in decimal.
void c6_hosted_put_u32(uint32_t value)
Emit an unsigned 32-bit value in decimal.
void c6_hosted_put_hex(uint32_t value, uint8_t digits)
Emit a value as a fixed-width lower-case hexadecimal field.
@ k_c6_hosted_dma_align
Transaction-buffer alignment, in bytes.
Definition c6_hosted.h:67
@ k_c6_hosted_hex_byte
Hex digits printed for a byte-wide field.
Definition c6_hosted.h:95
@ k_c6_hosted_hex_csum
Hex digits printed for a 16-bit checksum.
Definition c6_hosted.h:96
static void c6_hosted_build_idle_frame(void)
Build the idle frame this application transmits.
static const char * c6_hosted_verdict_text(c6_hosted_verdict_t verdict)
Map a verdict onto the text printed after PASS or FAIL.
void c6_hosted_run_transaction(void)
Clock one full-duplex transaction and report the verdict.
static void c6_hosted_print_rx_header(uint16_t calc)
Print every field of the received payload header.
static c6_hosted_frame_t s_c6_hosted_tx
Transmit buffer holding the single idle frame this app sends.
static c6_hosted_verdict_t c6_hosted_classify(int32_t rc, uint16_t calc)
Decide the verdict for the completed transaction.
static uint16_t c6_hosted_rx_checksum(void)
Recompute the checksum of the received frame.
c6_hosted_fill_t
Coarse classification of the whole received buffer.
@ k_c6_hosted_fill_mixed
The buffer holds a mix of byte values.
@ k_c6_hosted_fill_zero
Every byte is 0x00.
@ k_c6_hosted_fill_ones
Every byte is 0xFF.
c6_hosted_proto_t
Protocol sizes the verdict is judged against.
@ k_c6_hosted_filler_if_num
The if_num the co-processor stamps into a filler frame.
@ k_c6_hosted_hdr_bytes
Payload-header size; twelve bytes on this ABI.
@ k_c6_hosted_max_payload
Largest payload a valid frame may advertise.
@ k_c6_hosted_byte_ones
The all-ones byte an unterminated RA8 input reads.
static c6_hosted_frame_t s_c6_hosted_rx
Receive buffer the co-processor's frame lands in.
static c6_hosted_fill_t c6_hosted_rx_fill(void)
Classify the received buffer as all-zero, all-ones or mixed.
c6_hosted_verdict_t
Outcome of the single transaction, in the order it is tested.
@ k_c6_hosted_verdict_transfer
The vtable transfer did not return RET_OK.
@ k_c6_hosted_verdict_csum
Received checksum differs from the recomputed one.
@ k_c6_hosted_verdict_offset
Header offset is not the payload-header size.
@ k_c6_hosted_verdict_idle
The co-processor's filler frame arrived: also a pass, and the usual answer to a host that asked nothi...
@ k_c6_hosted_verdict_length
Advertised length exceeds MAX_PAYLOAD_SIZE.
@ k_c6_hosted_verdict_ones
Receive buffer all-ones: bus not driven.
@ k_c6_hosted_verdict_zero
Receive buffer all-zero: bus not driven.
@ k_c6_hosted_verdict_pass
A data frame arrived and verified.
esp-hosted port header: RTOS handle types, return codes and budgets.
#define MAX_PAYLOAD_SIZE
Largest payload one transport frame can carry, in bytes.
#define RET_OK
Operation completed.
esp-hosted port header: full-duplex SPI transport buffer size.
struct hosted_config_t g_h
The handle the vendored core dereferences to reach the vtable.