Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
ldrom_uart.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, Cascoda Ltd.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef BAREMETAL_PLATFORM_CASCODA_NUVOTON_CHILI2_LDROM_UART_LDROM_UART_H_
30 #define BAREMETAL_PLATFORM_CASCODA_NUVOTON_CHILI2_LDROM_UART_LDROM_UART_H_
31 
32 #include <stdbool.h>
33 #include <stdint.h>
34 
35 #include "ca821x_error.h"
36 #include "cascoda_chili_config.h"
37 #include "evbme_messages.h"
38 
39 #if (UART_CHANNEL == 0)
40 #define CLK_APBCLK_MASK CLK_APBCLK0_UART0CKEN_Msk
41 #define UART UART0
42 #define UART_IRQn UART0_IRQn
43 #elif (UART_CHANNEL == 1)
44 #define CLK_APBCLK_MASK CLK_APBCLK0_UART1CKEN_Msk
45 #define UART UART1
46 #define UART_IRQn UART1_IRQn
47 #elif (UART_CHANNEL == 2)
48 #define CLK_APBCLK_MASK CLK_APBCLK0_UART2CKEN_Msk
49 #define UART UART2
50 #define UART_IRQn UART2_IRQn
51 #elif (UART_CHANNEL == 4)
52 #define CLK_APBCLK_MASK CLK_APBCLK0_UART4CKEN_Msk
53 #define UART UART4
54 #define UART_IRQn UART4_IRQn
55 #elif (UART_CHANNEL == 5)
56 #define CLK_APBCLK_MASK CLK_APBCLK0_UART5CKEN_Msk
57 #define UART UART5
58 #define UART_IRQn UART5_IRQn
59 #endif
60 
65 {
66  uint8_t startAddr[4];
67  uint32_t data[61];
68 };
69 //Assert struct is packed even with uint32_t data
70 #pragma GCC diagnostic push
71 #pragma GCC diagnostic ignored "-Wunused-local-typedefs" //Suppresses warnings
72 ca_static_assert(sizeof(struct dfu_write_cmd_aligned) == 248);
73 #pragma GCC diagnostic pop
74 
78 union dfu_cmd_aligned
79 {
85 };
86 
90 struct __attribute__((packed)) dfu_cmd_msg
91 {
92  uint8_t dfu_cmdid;
93  union dfu_cmd_aligned dfu_cmd;
94 };
95 
99 struct __attribute__((packed)) evbme_get_request
100 {
101  uint8_t attributeId;
102 };
103 
107 struct __attribute__((packed)) evbme_get_confirm
108 {
109  uint8_t status;
110  uint8_t attributeId;
111  uint8_t attributeLen;
112  uint8_t attribute[];
113 };
114 
119 {
120  struct evbme_get_request req;
121  struct evbme_get_confirm cnf;
122 };
123 
128 {
129  union evbme_msg evbme;
130  struct dfu_cmd_msg dfu;
131  uint8_t generic;
132 };
133 
137 struct __attribute__((packed)) SerialUARTBuf
138 {
139  volatile uint8_t isReady;
140  uint8_t SofPkt;
141  uint8_t cmdid;
142  uint8_t len;
143  union serial_data data;
144 };
145 
146 /******************************************************************************/
147 /****** Definitions for Serial State ******/
148 /******************************************************************************/
150 {
155 };
156 
157 #define SERIAL_SOM (0xDE)
158 //Assert SerialUARTBuf struct is packed
159 ca_static_assert(sizeof(struct SerialUARTBuf) == (5 + sizeof(struct dfu_write_cmd_aligned)));
160 
161 extern struct SerialUARTBuf gRxBuffer;
162 extern struct SerialUARTBuf gTxBuffer;
163 extern volatile enum serial_state gSerialRxState;
164 extern volatile bool gSerialTxStalled;
165 
166 void UART_Init(void);
167 
168 //Functions to unblock IO:
169 void RxHandled(void); //Call when a Rx message has been fully processed
170 void TxReady(void); //Call when a Tx is ready to send
171 
172 #endif /* BAREMETAL_PLATFORM_CASCODA_NUVOTON_CHILI2_LDROM_UART_LDROM_UART_H_ */
Global error declarations for use across the Cascoda SDK.
Definitions relating to EVBME API messages.
struct SerialUARTBuf gRxBuffer
Definition: hid_transfer.c:61
struct SerialUARTBuf gTxBuffer
Definition: hid_transfer.c:62
enum serial_state gSerialRxState
Definition: uart_transfer.c:39
ca_static_assert(sizeof(struct dfu_write_cmd_aligned)==248)
serial_state
Definition: ldrom_uart.h:150
@ SERIAL_DATA
Definition: ldrom_uart.h:154
@ SERIAL_CMDID
Definition: ldrom_uart.h:152
@ SERIAL_CMDLEN
Definition: ldrom_uart.h:153
@ SERIAL_INBETWEEN
Definition: ldrom_uart.h:151
volatile bool gSerialTxStalled
Definition: uart_transfer.c:40
void RxHandled(void)
Definition: hid_transfer.c:212
void UART_Init(void)
Definition: uart_transfer.c:263
void TxReady(void)
Definition: hid_transfer.c:218
Cascoda serialbuffer structure.
Definition: ldrom_uart.h:138
uint8_t SofPkt
Start of frame.
Definition: ldrom_uart.h:140
uint8_t cmdid
Cascoda command ID = EVBME_DFU_CMD (0xA3)
Definition: ldrom_uart.h:141
volatile uint8_t isReady
Is ready to: Tx-Write, Rx-Read.
Definition: ldrom_uart.h:139
Structure of a DFU message.
Definition: ldrom_uart.h:91
Write command to write words of data - aligned for codespace and speed.
Definition: ldrom_hid.h:41
uint32_t data[61]
Data to write, must be whole words.
Definition: ldrom_hid.h:43
uint8_t startAddr[4]
Start address for writing - must be word aligned.
Definition: ldrom_hid.h:42
Check command to validate flash against a checksum.
Definition: evbme_messages.h:148
Erase command to erase whole pages.
Definition: evbme_messages.h:130
Reboot command to boot into DFU or APROM.
Definition: evbme_messages.h:122
Status command used as a reply from the Chili2 to host.
Definition: evbme_messages.h:158
Evbme GET confirm struct (to respond to received GET requests)
Definition: ldrom_uart.h:108
uint8_t attributeLen
Definition: ldrom_uart.h:111
uint8_t status
Definition: ldrom_uart.h:109
uint8_t attributeId
Definition: ldrom_uart.h:110
Evbme GET request struct (for received messages)
Definition: ldrom_uart.h:100
uint8_t attributeId
Definition: ldrom_uart.h:101
Union of all DFU commands - version with dfu_write_cmd_aligned.
Definition: ldrom_hid.h:55
struct evbme_dfu_reboot_cmd reboot_cmd
Definition: ldrom_hid.h:56
struct evbme_dfu_erase_cmd erase_cmd
Definition: ldrom_hid.h:57
struct evbme_dfu_check_cmd check_cmd
Definition: ldrom_hid.h:59
struct dfu_write_cmd_aligned write_cmd
Definition: ldrom_hid.h:58
struct evbme_dfu_status_cmd status_cmd
Definition: ldrom_hid.h:60
Union of GET request and confirm structs.
Definition: ldrom_uart.h:119
struct evbme_get_confirm cnf
Definition: ldrom_uart.h:121
struct evbme_get_request req
Definition: ldrom_uart.h:120
Union of all types of "data" (which commes after "cmdid" and "len")
Definition: ldrom_uart.h:128
union evbme_msg evbme
Definition: ldrom_uart.h:129
struct dfu_cmd_msg dfu
Definition: ldrom_uart.h:130