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#include "os_print.h"
7
8__attribute__((noreturn)) void send_swap_error_simple(uint16_t status_word,
9 uint8_t common_error_code,
10 uint8_t application_specific_error_code)
11{
12 send_swap_error_with_buffers(
13 status_word, common_error_code, application_specific_error_code, NULL, 0);
14}
15
16__attribute__((noreturn)) void send_swap_error_with_buffer(uint16_t status_word,
17 uint8_t common_error_code,
18 uint8_t application_specific_error_code,
19 const buffer_t buffer_data)
20{
21 send_swap_error_with_buffers(
22 status_word, common_error_code, application_specific_error_code, &buffer_data, 1);
23}
24
25__attribute__((noreturn)) void send_swap_error_with_buffers(uint16_t status_word,
26 uint8_t common_error_code,
27 uint8_t application_specific_error_code,
28 const buffer_t *buffer_data,
29 size_t count)
30{
31 if (!G_called_from_swap) {
32 PRINTF("Fatal error, send_swap_error_with_buffers called outside of swap context\n");
33 // Don't try to recover, the caller logic has a huge issue
34 os_sched_exit(0);
35 }
36 // Force G_swap_response_ready to true
38
39 // Simply prepend a constructed buffer with the error code to the buffer list and use standard
40 // io function to send
41 uint8_t swap_error_code[2] = {common_error_code, application_specific_error_code};
42
43 // Allocate enough space for the error code and buffers
44 buffer_t response[1 + SWAP_ERROR_HELPER_MAX_BUFFER_COUNT] = {0};
45 response[0].ptr = (uint8_t *) &swap_error_code;
46 response[0].size = sizeof(swap_error_code);
47
48 // Not really an error, let's just truncate without raising
49 if (count > SWAP_ERROR_HELPER_MAX_BUFFER_COUNT) {
50 PRINTF("send_swap_error_with_buffers truncated from %d to %d\n",
51 count,
52 SWAP_ERROR_HELPER_MAX_BUFFER_COUNT);
53 count = SWAP_ERROR_HELPER_MAX_BUFFER_COUNT;
54 }
55 // We are only copying the buffer_t structure, not the content
56 memcpy(&response[1], buffer_data, count * sizeof(buffer_t));
57
58 // io_send_response_buffers will use the correct flag IO_RETURN_AFTER_TX
59 io_send_response_buffers(response, count + 1, status_word);
60
61 // unreachable
62 os_sched_exit(0);
63}
64
65#endif // HAVE_SWAP
WEAK int io_send_response_buffers(const buffer_t *rdatalist, size_t count, uint16_t sw)
Definition io.c:124
__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