Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
swap_error_code_helpers.c
Go to the documentation of this file.
1
2#ifdef HAVE_SWAP
3
5#include "swap_utils.h"
6
7__attribute__((noreturn)) void send_swap_error_simple(uint16_t status_word,
8 uint8_t common_error_code,
9 uint8_t application_specific_error_code)
10{
11 send_swap_error_with_buffers(
12 status_word, common_error_code, application_specific_error_code, NULL, 0);
13}
14
15__attribute__((noreturn)) void send_swap_error_with_buffer(uint16_t status_word,
16 uint8_t common_error_code,
17 uint8_t application_specific_error_code,
18 const buffer_t buffer_data)
19{
20 send_swap_error_with_buffers(
21 status_word, common_error_code, application_specific_error_code, &buffer_data, 1);
22}
23
24__attribute__((noreturn)) void send_swap_error_with_buffers(uint16_t status_word,
25 uint8_t common_error_code,
26 uint8_t application_specific_error_code,
27 const buffer_t *buffer_data,
28 size_t count)
29{
30 if (!G_called_from_swap) {
31 PRINTF("Fatal error, send_swap_error_with_buffers called outside of swap context\n");
32 // Don't try to recover, the caller logic has a huge issue
33 os_sched_exit(0);
34 }
35 // Force G_swap_response_ready to true
37
38 // Simply prepend a constructed buffer with the error code to the buffer list and use standard
39 // io function to send
40 uint8_t swap_error_code[2] = {common_error_code, application_specific_error_code};
41
42 // Allocate enough space for the error code and buffers
43 buffer_t response[1 + SWAP_ERROR_HELPER_MAX_BUFFER_COUNT] = {0};
44 response[0].ptr = (uint8_t *) &swap_error_code;
45 response[0].size = sizeof(swap_error_code);
46
47 // Not really an error, let's just truncate without raising
48 if (count > SWAP_ERROR_HELPER_MAX_BUFFER_COUNT) {
49 PRINTF("send_swap_error_with_buffers truncated from %d to %d\n",
50 count,
51 SWAP_ERROR_HELPER_MAX_BUFFER_COUNT);
52 count = SWAP_ERROR_HELPER_MAX_BUFFER_COUNT;
53 }
54 // We are only copying the buffer_t structure, not the content
55 memcpy(&response[1], buffer_data, count * sizeof(buffer_t));
56
57 // io_send_response_buffers will use the correct flag IO_RETURN_AFTER_TX
58 io_send_response_buffers(response, count + 1, status_word);
59
60 // unreachable
61 os_sched_exit(0);
62}
63
64#endif // HAVE_SWAP
WEAK int io_send_response_buffers(const buffer_t *rdatalist, size_t count, uint16_t sw)
Definition io.c:166
__attribute__((section("._nbgl_fonts_"))) const
return the non-unicode font corresponding to the given font ID
Definition nbgl_fonts.c:67
const uint8_t * ptr
Definition buffer.h:19
size_t size
Pointer to byte buffer.
Definition buffer.h:20
volatile bool G_called_from_swap
volatile bool G_swap_response_ready
unsigned short uint16_t
Definition usbd_conf.h:54
unsigned char uint8_t
Definition usbd_conf.h:53