rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | /*============================================================================*/ |
| 2 | /* eCall ANSI C fixed-point reference source code */ |
| 3 | /* */ |
| 4 | /* File: ecall_control.h */ |
| 5 | /* Version: 8.6.0 (Rel8) / 9.4.0 (Rel9) */ |
| 6 | /* Date: 2011-02-08 */ |
| 7 | /* Description: control message functions (header file) */ |
| 8 | /*----------------------------------------------------------------------------*/ |
| 9 | |
| 10 | #ifndef ECALL_CONTROL_H_ |
| 11 | #define ECALL_CONTROL_H_ |
| 12 | |
| 13 | #include "ecall_defines.h" |
| 14 | #include "ecall_sync.h" |
| 15 | |
| 16 | |
| 17 | typedef enum { |
| 18 | DlMsgNoop = -2, |
| 19 | DlMsgReset, |
| 20 | DlMsgStart, // 0 |
| 21 | DlMsgNack, // 1 |
| 22 | DlMsgAck, // 2 |
| 23 | DlMsgSend, // 3 |
| 24 | DlMsgUndef04, |
| 25 | DlMsgUndef05, |
| 26 | DlMsgUndef06, |
| 27 | DlMsgUndef07, |
| 28 | DlMsgUndef08, |
| 29 | DlMsgUndef09, |
| 30 | DlMsgUndef10, |
| 31 | DlMsgUndef11, |
| 32 | DlMsgUndef12, |
| 33 | DlMsgUndef13, |
| 34 | DlMsgUndef14, |
| 35 | DlMsgUndef15, |
| 36 | DlMsgUndef16, |
| 37 | DlMsgUndef17, |
| 38 | DlMsgUndef18, |
| 39 | DlMsgUndef19, |
| 40 | DlMsgUndef20, |
| 41 | DlMsgUndef21, |
| 42 | DlMsgUndef22, |
| 43 | DlMsgUndef23, |
| 44 | DlMsgUndef24, |
| 45 | DlMsgUndef25, |
| 46 | DlMsgUndef26, |
| 47 | DlMsgUndef27, |
| 48 | DlMsgUndef28, |
| 49 | DlMsgUndef29, |
| 50 | DlMsgUndef30, |
| 51 | DlMsgUndef31, |
| 52 | DlMsgHlack = SET_LLMSG + SET_HLMSG |
| 53 | } DlData; |
| 54 | |
| 55 | #ifdef ECALL_ENUM2STR |
| 56 | #define DLMSG_PAD (-DlMsgNoop) |
| 57 | #define NUM_DLMSGS (DlMsgHlack - DlMsgNoop + 1) |
| 58 | extern const char* const __DLMSG2STR[NUM_DLMSGS]; |
| 59 | #define DLDATA2STR(DLDATA) __DLMSG2STR[DLMSG_PAD + DLDATA] |
| 60 | #endif |
| 61 | |
| 62 | typedef enum { |
| 63 | CtrlRxIdle, |
| 64 | CtrlRxSync, |
| 65 | CtrlRxLock, |
| 66 | CtrlTxIdle, |
| 67 | CtrlTxSend, |
| 68 | NUM_PORTSTATES |
| 69 | } PortState; |
| 70 | |
| 71 | #ifdef ECALL_ENUM2STR |
| 72 | extern const char* const __PORTSTATE2STR[NUM_PORTSTATES]; |
| 73 | #define PORTSTATE2STR(PORTSTATE) __PORTSTATE2STR[PORTSTATE] |
| 74 | #endif |
| 75 | |
| 76 | typedef enum { |
| 77 | PortUndef, |
| 78 | PortIvs, |
| 79 | PortPsap, |
| 80 | NUM_PORTOWNERS |
| 81 | } PortOwner; |
| 82 | |
| 83 | #ifdef ECALL_ENUM2STR |
| 84 | extern const char* const __PORTOWNER2STR[NUM_PORTOWNERS]; |
| 85 | #define PORTOWNER2STR(PORTOWNER) __PORTOWNER2STR[PORTOWNER] |
| 86 | #endif |
| 87 | |
| 88 | /*============================================================================*/ |
| 89 | /* Control structures */ |
| 90 | /*----------------------------------------------------------------------------*/ |
| 91 | |
| 92 | typedef struct { |
| 93 | Int16 dlData; /* message symbol */ |
| 94 | Int16 dlIndex; /* message frame counter */ |
| 95 | } CtrlTxPort; |
| 96 | |
| 97 | typedef struct { |
| 98 | Int16 dlData; /* detected message symbol */ |
| 99 | Int16 dlMetric; /* receiver metric */ |
| 100 | } CtrlRxPort; |
| 101 | |
| 102 | typedef struct { |
| 103 | union { |
| 104 | CtrlTxPort tx; /* port control transmitter */ |
| 105 | CtrlRxPort rx; /* port control receiver */ |
| 106 | } u; |
| 107 | PortState state; /* port state */ |
| 108 | PortOwner owner; /* port owner identification */ |
| 109 | Bool invert; /* port inversion flag */ |
| 110 | } CtrlPort; |
| 111 | |
| 112 | typedef struct { |
| 113 | CtrlPort port; /* port struct */ |
| 114 | } CtrlTxData; |
| 115 | |
| 116 | typedef struct { |
| 117 | CtrlPort port; /* port struct */ |
| 118 | |
| 119 | SyncState *sync; /* pointer to sync struct */ |
| 120 | Int16 *buffer; /* pointer to control receiver buffer */ |
| 121 | |
| 122 | Tern dlRead; /* sync indication (ternary variable) */ |
| 123 | Int16 dlIndex; /* internal frame counter */ |
| 124 | Int16 dlSyncLock; /* number of sync events required */ |
| 125 | } CtrlRxData; |
| 126 | |
| 127 | |
| 128 | /*============================================================================*/ |
| 129 | /* Control functions */ |
| 130 | /*----------------------------------------------------------------------------*/ |
| 131 | |
| 132 | const char* CtrlPortName(PortOwner); |
| 133 | void CtrlSync(CtrlRxData*, const Int16*); |
| 134 | |
| 135 | void CtrlTxReset(CtrlTxData*, PortOwner); |
| 136 | void CtrlTxProcess(CtrlTxData*, Int16*); |
| 137 | void CtrlTxMod(Int16*, Int16, Int16); |
| 138 | |
| 139 | void CtrlRxReset(CtrlRxData*, PortOwner, SyncState*, Int16*, Int16); |
| 140 | void CtrlRxProcess(CtrlRxData*, const Int16*); |
| 141 | Int16 CtrlRxDemod(const Int16*, Int16*); |
| 142 | |
| 143 | #endif |