1 /* 2 * Copyright (c) 2023 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _NRF_HW_MODEL_BACKEND_FIFO_H 8 #define _NRF_HW_MODEL_BACKEND_FIFO_H 9 10 #include <stdint.h> 11 #include "bs_types.h" 12 13 #ifdef __cplusplus 14 extern "C"{ 15 #endif 16 17 /* 18 * Protocol 19 * 20 * The device creates (if not there) and opens its Tx side FIFO at boot 21 * The device tries to opens its Rx side FIFO when the UART is enabled first time 22 * 23 * Messages: 24 * <uint64_t time> <uint8_t msg_type> <uint16_t msg_size (including time and msg_type)> 25 * <...> 26 * 27 * <uint64_t time> MODE_CHANGE <msg_size> 28 * <uint32_t baudrate> <uint32_t config> 29 * (note the time stamp is ignored, as only the next Tx is affected by the rate change) 30 * 31 * <uint64_t time> TX_BYTE <msg_size> 32 * <uint8_t data > 33 * (note time is when the frame ends) 34 * 35 * <uint64_t time> RTS_CTS_TOGGLE <msg_size> 36 * <uint8_t level {0,1}> 37 * 38 * <uint64_t time> NOP <msg_size> 39 * 40 * <uint64_t time> DISCONNECT <msg_size> 41 * The other side is disconnecting gracefully 42 */ 43 44 struct ufifo_msg_header { 45 bs_time_t time; 46 enum {ufifo_NOP=0, ufifo_MODE_CHANGE, ufifo_TX_BYTE, ufifo_RTS_CTS_TOGGLE, ufifo_DISCONNECT} msg_type; 47 uint16_t size; 48 } __attribute__ ((packed)); 49 50 struct ufifo_msg_tx { 51 struct ufifo_msg_header header; 52 uint8_t data; 53 } __attribute__ ((packed)); 54 55 struct ufifo_msg_rts_cts { 56 struct ufifo_msg_header header; 57 uint8_t level; 58 } __attribute__ ((packed)); 59 60 struct ufifo_msg_mode_change { 61 struct ufifo_msg_header header; 62 uint32_t baudrate; 63 uint32_t config; 64 } __attribute__ ((packed)); 65 66 #define UFIFO_MSG_HEADER_SIZE (sizeof(struct ufifo_msg_header)) 67 #define UFIFO_MSG_TXL_BODY_SIZE (sizeof(struct ufifo_msg_tx) - sizeof(struct ufifo_msg_header)) 68 #define UFIFO_MSG_RTS_CTS_BODY_SIZE (sizeof(struct ufifo_msg_rts_cts) - sizeof(struct ufifo_msg_header)) 69 #define UFIFO_MSG_MODE_CHANGE_BODY_SIZE (sizeof(struct ufifo_msg_mode_change) - sizeof(struct ufifo_msg_header)) 70 71 #define UFIFO_BIGGEST_MSG (sizeof(struct ufifo_msg_mode_change)) 72 73 #ifdef __cplusplus 74 } 75 #endif 76 77 #endif /* _NRF_HW_MODEL_UART_H */ 78