ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
c6_fwver_priv.c
Go to the documentation of this file.
1
35
36#include <stdint.h>
37
38#include "c6_fwver.h"
39#include "esp_hosted_host_fw_ver.h"
40#include "esp_hosted_interface.h"
41#include "esp_hosted_transport.h"
42#include "esp_hosted_transport_init.h"
44#include "transport_drv.h"
45
78
105
117
134static uint16_t c6_fwver_priv_put_tlv(uint8_t* out, uint16_t at, uint8_t tag, uint8_t value)
135{
136 out[at + (uint16_t)k_c6_fwver_priv_tlv_tag] = tag;
137 out[at + (uint16_t)k_c6_fwver_priv_tlv_size] = (uint8_t)k_c6_fwver_priv_tlv_len;
138 out[at + (uint16_t)k_c6_fwver_priv_tlv_value] = value;
139 return (uint16_t)(at + (uint16_t)k_c6_fwver_priv_tlv_stride);
140}
141
142ra8_err_t c6_fwver_priv_host_caps(uint8_t* out, uint16_t cap, uint16_t* out_len)
143{
144 if ((out == nullptr) || (out_len == nullptr)) {
145 return k_ra8_err_null_ptr;
146 }
147 const uint16_t tlv_bytes =
148 (uint16_t)((uint16_t)k_c6_fwver_priv_tag_count * (uint16_t)k_c6_fwver_priv_tlv_stride);
149 const uint16_t total = (uint16_t)(tlv_bytes + (uint16_t)k_c6_fwver_priv_evt_hdr);
150 if (cap < total) {
151 *out_len = 0U;
153 }
154
155 out[k_c6_fwver_priv_evt_type] = (uint8_t)ESP_PRIV_EVENT_INIT;
156 out[k_c6_fwver_priv_evt_len] = (uint8_t)tlv_bytes;
157
158 uint16_t at = (uint16_t)k_c6_fwver_priv_evt_hdr;
159 at =
160 c6_fwver_priv_put_tlv(out, at, (uint8_t)HOST_CAPABILITIES, (uint8_t)k_c6_fwver_priv_host_cap);
161 at = c6_fwver_priv_put_tlv(out,
162 at,
163 (uint8_t)RCVD_ESP_FIRMWARE_CHIP_ID,
164 (uint8_t)ESP_PRIV_FIRMWARE_CHIP_ESP32C6);
165 at = c6_fwver_priv_put_tlv(out, at, (uint8_t)SLV_CONFIG_TEST_RAW_TP, (uint8_t)H_TEST_RAW_TP_DIR);
166 at = c6_fwver_priv_put_tlv(out,
167 at,
168 (uint8_t)SLV_CONFIG_THROTTLE_HIGH_THRESHOLD,
170 at = c6_fwver_priv_put_tlv(out,
171 at,
172 (uint8_t)SLV_CONFIG_THROTTLE_LOW_THRESHOLD,
174
175 *out_len = at;
176 return k_ra8_ok;
177}
178
195static void c6_fwver_priv_tlv(uint8_t tag, const uint8_t* value, uint8_t len)
196{
197 c6_fwver_puts("c6_fwver: priv tlv tag=0x");
198 c6_fwver_put_hex((uint32_t)tag, (uint8_t)k_c6_fwver_hex_byte);
199
200 if ((tag == (uint8_t)ESP_PRIV_FIRMWARE_VERSION) && (len == (uint8_t)k_c6_fwver_priv_ver_bytes)) {
202 (uint32_t)value[k_c6_fwver_priv_ver_b0] |
203 ((uint32_t)value[k_c6_fwver_priv_ver_b1] << (uint32_t)k_c6_fwver_priv_shift_1) |
204 ((uint32_t)value[k_c6_fwver_priv_ver_b2] << (uint32_t)k_c6_fwver_priv_shift_2) |
205 ((uint32_t)value[k_c6_fwver_priv_ver_b3] << (uint32_t)k_c6_fwver_priv_shift_3);
206 c6_fwver_puts(" firmware_version=");
207 c6_fwver_put_u32(ESP_HOSTED_VERSION_MAJOR(s_c6_fwver_priv_version));
208 c6_fwver_puts(".");
209 c6_fwver_put_u32(ESP_HOSTED_VERSION_MINOR(s_c6_fwver_priv_version));
210 c6_fwver_puts(".");
211 c6_fwver_put_u32(ESP_HOSTED_VERSION_PATCH(s_c6_fwver_priv_version));
212 } else if (len == (uint8_t)k_c6_fwver_priv_tlv_len) {
213 c6_fwver_puts(" value=0x");
214 c6_fwver_put_hex((uint32_t)value[0], (uint8_t)k_c6_fwver_hex_byte);
215 } else {
216 c6_fwver_puts(" len=");
217 c6_fwver_put_u32((uint32_t)len);
218 }
219 c6_fwver_puts("\r\n");
220}
221
222bool c6_fwver_priv_consume(uint8_t if_type, uint8_t if_num, const uint8_t* payload, uint16_t len)
223{
224 (void)if_num;
225 if ((if_type != (uint8_t)ESP_PRIV_IF) || (payload == nullptr) ||
226 (len < (uint16_t)k_c6_fwver_priv_evt_hdr)) {
227 return false;
228 }
229
230 const uint8_t event_type = payload[k_c6_fwver_priv_evt_type];
231 const uint16_t event_len = (uint16_t)payload[k_c6_fwver_priv_evt_len];
232 c6_fwver_puts("c6_fwver: priv event type=0x");
233 c6_fwver_put_hex((uint32_t)event_type, (uint8_t)k_c6_fwver_hex_byte);
234 c6_fwver_puts(" tlv_bytes=");
235 c6_fwver_put_u32((uint32_t)event_len);
236 c6_fwver_puts("\r\n");
237
238 if ((event_type != (uint8_t)ESP_PRIV_EVENT_INIT) ||
239 (event_len > (uint16_t)(len - (uint16_t)k_c6_fwver_priv_evt_hdr))) {
240 return false;
241 }
242
243 uint16_t at = (uint16_t)k_c6_fwver_priv_evt_hdr;
244 for (uint16_t seen = 0U; seen < event_len; seen++) {
245 if ((uint16_t)(at + (uint16_t)k_c6_fwver_priv_tlv_value) > len) {
246 break;
247 }
248 const uint8_t tag = payload[at + (uint16_t)k_c6_fwver_priv_tlv_tag];
249 const uint8_t tag_len = payload[at + (uint16_t)k_c6_fwver_priv_tlv_size];
250 const uint16_t next = (uint16_t)(at + (uint16_t)k_c6_fwver_priv_tlv_value + tag_len);
251 if (next > len) {
252 break;
253 }
254 c6_fwver_priv_tlv(tag, &payload[at + (uint16_t)k_c6_fwver_priv_tlv_value], tag_len);
255 at = next;
256 if (at >= (uint16_t)(event_len + (uint16_t)k_c6_fwver_priv_evt_hdr)) {
257 break;
258 }
259 }
260 return false;
261}
262
264{
266}
Shared contract for the esp-hosted RPC round-trip application.
void c6_fwver_put_hex(uint32_t value, uint8_t digits)
Emit a value as a fixed-width lower-case hexadecimal field.
@ k_c6_fwver_hex_byte
Hex digits printed for a byte-wide field.
Definition c6_fwver.h:111
void c6_fwver_put_u32(uint32_t value)
Emit an unsigned 32-bit value in decimal.
void c6_fwver_puts(const char *text)
Write a NUL-terminated string to the board console.
ra8_err_t c6_fwver_priv_host_caps(uint8_t *out, uint16_t cap, uint16_t *out_len)
Build the host-capabilities frame the reference host sends first.
static void c6_fwver_priv_tlv(uint8_t tag, const uint8_t *value, uint8_t len)
Decode and report one TLV of an INIT event.
c6_fwver_priv_ver_t
Byte layout of the ESP_PRIV_FIRMWARE_VERSION tag's value.
@ k_c6_fwver_priv_shift_2
Shift for the 3rd byte.
@ k_c6_fwver_priv_ver_bytes
Width of the tag value.
@ k_c6_fwver_priv_ver_b1
Second byte.
@ k_c6_fwver_priv_shift_3
Shift for the 4th byte.
@ k_c6_fwver_priv_shift_1
Shift for the 2nd byte.
@ k_c6_fwver_priv_ver_b2
Third byte.
@ k_c6_fwver_priv_ver_b3
Most significant byte.
@ k_c6_fwver_priv_ver_b0
Least significant byte.
static uint32_t s_c6_fwver_priv_version
Version word the boot INIT event announced, or zero.
static uint16_t c6_fwver_priv_put_tlv(uint8_t *out, uint16_t at, uint8_t tag, uint8_t value)
Append one one-byte-valued TLV at a cursor.
bool c6_fwver_priv_consume(uint8_t if_type, uint8_t if_num, const uint8_t *payload, uint16_t len)
Decode an ESP_PRIV_IF frame and report what it announced.
c6_fwver_priv_t
Layout and values of the ESP_PRIV_IF event this host sends.
@ k_c6_fwver_priv_evt_type
Offset of the event type byte.
@ k_c6_fwver_priv_tlv_stride
Bytes one one-byte-valued TLV occupies.
@ k_c6_fwver_priv_tlv_tag
Offset of a TLV's tag, from its start.
@ k_c6_fwver_priv_host_cap
Host capability word; zero, as upstream.
@ k_c6_fwver_priv_evt_hdr
Bytes before the first TLV.
@ k_c6_fwver_priv_evt_len
Offset of the event length byte.
@ k_c6_fwver_priv_tlv_len
Value width of every tag this host emits.
@ k_c6_fwver_priv_tag_count
TLVs this host emits.
@ k_c6_fwver_priv_tlv_value
Offset of a TLV's value, from its start.
@ k_c6_fwver_priv_tlv_size
Offset of a TLV's length, from its start.
uint32_t c6_fwver_priv_init_version(void)
Report the version the boot INIT event announced, if one arrived.
esp-hosted port header: optional host features, RPC bounds, counters.
#define H_WIFI_TX_DATA_THROTTLE_HIGH_THRESHOLD
Queue occupancy, in percent, at which the co-processor throttles.
#define H_TEST_RAW_TP_DIR
Direction bitmap advertised for the raw-throughput test.
#define H_WIFI_TX_DATA_THROTTLE_LOW_THRESHOLD
Queue occupancy, in percent, at which throttling is released.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
Definition ra8_err.h:478
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
Definition ra8_err.h:167
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546