DeepCover Embedded Security in IoT: Public-key Secured Data Paths
Dependencies: MaximInterface
The MAXREFDES155# is an internet-of-things (IoT) embedded-security reference design, built to authenticate and control a sensing node using elliptic-curve-based public-key cryptography with control and notification from a web server.
The hardware includes an ARM® mbed™ shield and attached sensor endpoint. The shield contains a DS2476 DeepCover® ECDSA/SHA-2 coprocessor, Wifi communication, LCD push-button controls, and status LEDs. The sensor endpoint is attached to the shield using a 300mm cable and contains a DS28C36 DeepCover ECDSA/SHA-2 authenticator, IR-thermal sensor, and aiming laser for the IR sensor. The MAXREFDES155# is equipped with a standard Arduino® form-factor shield connector for immediate testing using an mbed board such as the MAX32600MBED#. The combination of these two devices represent an IoT device. Communication to the web server is accomplished with the shield Wifi circuitry. Communication from the shield to the attached sensor module is accomplished over I2C . The sensor module represents an IoT endpoint that generates small data with a requirement for message authenticity/integrity and secure on/off operational control.
The design is hierarchical with each mbed platform and shield communicating data from the sensor node to a web server that maintains a centralized log and dispatches notifications as necessary. The simplicity of this design enables rapid integration into any star-topology IoT network to provide security with the low overhead and cost provided by the ECDSA-P256 asymmetric-key and SHA-256 symmetric-key algorithms.
More information about the MAXREFDES155# is available on the Maxim Integrated website.
xternal/simplelink/source/driver.c@18:c2631e985780, 2019-12-03 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Tue Dec 03 12:56:25 2019 -0600
- Revision:
- 18:c2631e985780
- Parent:
- 16:a004191a79ab
Updated MaximInterface to version 2.1.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IanBenzMaxim | 0:33d4e66780c0 | 1 | /* |
IanBenzMaxim | 0:33d4e66780c0 | 2 | * driver.c - CC31xx/CC32xx Host Driver Implementation |
IanBenzMaxim | 0:33d4e66780c0 | 3 | * |
IanBenzMaxim | 0:33d4e66780c0 | 4 | * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ |
IanBenzMaxim | 0:33d4e66780c0 | 5 | * |
IanBenzMaxim | 0:33d4e66780c0 | 6 | * |
IanBenzMaxim | 0:33d4e66780c0 | 7 | * Redistribution and use in source and binary forms, with or without |
IanBenzMaxim | 0:33d4e66780c0 | 8 | * modification, are permitted provided that the following conditions |
IanBenzMaxim | 0:33d4e66780c0 | 9 | * are met: |
IanBenzMaxim | 0:33d4e66780c0 | 10 | * |
IanBenzMaxim | 0:33d4e66780c0 | 11 | * Redistributions of source code must retain the above copyright |
IanBenzMaxim | 0:33d4e66780c0 | 12 | * notice, this list of conditions and the following disclaimer. |
IanBenzMaxim | 0:33d4e66780c0 | 13 | * |
IanBenzMaxim | 0:33d4e66780c0 | 14 | * Redistributions in binary form must reproduce the above copyright |
IanBenzMaxim | 0:33d4e66780c0 | 15 | * notice, this list of conditions and the following disclaimer in the |
IanBenzMaxim | 0:33d4e66780c0 | 16 | * documentation and/or other materials provided with the |
IanBenzMaxim | 0:33d4e66780c0 | 17 | * distribution. |
IanBenzMaxim | 0:33d4e66780c0 | 18 | * |
IanBenzMaxim | 0:33d4e66780c0 | 19 | * Neither the name of Texas Instruments Incorporated nor the names of |
IanBenzMaxim | 0:33d4e66780c0 | 20 | * its contributors may be used to endorse or promote products derived |
IanBenzMaxim | 0:33d4e66780c0 | 21 | * from this software without specific prior written permission. |
IanBenzMaxim | 0:33d4e66780c0 | 22 | * |
IanBenzMaxim | 0:33d4e66780c0 | 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
IanBenzMaxim | 0:33d4e66780c0 | 24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
IanBenzMaxim | 0:33d4e66780c0 | 25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
IanBenzMaxim | 0:33d4e66780c0 | 26 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
IanBenzMaxim | 0:33d4e66780c0 | 27 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
IanBenzMaxim | 0:33d4e66780c0 | 28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
IanBenzMaxim | 0:33d4e66780c0 | 29 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
IanBenzMaxim | 0:33d4e66780c0 | 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
IanBenzMaxim | 0:33d4e66780c0 | 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
IanBenzMaxim | 0:33d4e66780c0 | 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
IanBenzMaxim | 0:33d4e66780c0 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
IanBenzMaxim | 0:33d4e66780c0 | 34 | * |
IanBenzMaxim | 0:33d4e66780c0 | 35 | */ |
IanBenzMaxim | 0:33d4e66780c0 | 36 | |
IanBenzMaxim | 0:33d4e66780c0 | 37 | /*****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 38 | /* Include files */ |
IanBenzMaxim | 0:33d4e66780c0 | 39 | /*****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 40 | #include "simplelink.h" |
IanBenzMaxim | 0:33d4e66780c0 | 41 | #include "protocol.h" |
IanBenzMaxim | 0:33d4e66780c0 | 42 | #include "driver.h" |
IanBenzMaxim | 0:33d4e66780c0 | 43 | #include "flowcont.h" |
IanBenzMaxim | 0:33d4e66780c0 | 44 | |
IanBenzMaxim | 0:33d4e66780c0 | 45 | /*****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 46 | /* Macro declarations */ |
IanBenzMaxim | 0:33d4e66780c0 | 47 | /*****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 48 | |
IanBenzMaxim | 0:33d4e66780c0 | 49 | #define _SL_PENDING_RX_MSG(pDriverCB) (RxIrqCnt != (pDriverCB)->RxDoneCnt) |
IanBenzMaxim | 0:33d4e66780c0 | 50 | |
IanBenzMaxim | 0:33d4e66780c0 | 51 | /* 2 LSB of the N2H_SYNC_PATTERN are for sequence number |
IanBenzMaxim | 0:33d4e66780c0 | 52 | only in SPI interface |
IanBenzMaxim | 0:33d4e66780c0 | 53 | support backward sync pattern */ |
IanBenzMaxim | 0:33d4e66780c0 | 54 | #define N2H_SYNC_PATTERN_SEQ_NUM_BITS ((_u32)0x00000003) /* Bits 0..1 - use the 2 LBS for seq num */ |
IanBenzMaxim | 0:33d4e66780c0 | 55 | #define N2H_SYNC_PATTERN_SEQ_NUM_EXISTS ((_u32)0x00000004) /* Bit 2 - sign that sequence number exists in the sync pattern */ |
IanBenzMaxim | 0:33d4e66780c0 | 56 | #define N2H_SYNC_PATTERN_MASK ((_u32)0xFFFFFFF8) /* Bits 3..31 - constant SYNC PATTERN */ |
IanBenzMaxim | 0:33d4e66780c0 | 57 | #define N2H_SYNC_SPI_BUGS_MASK ((_u32)0x7FFF7F7F) /* Bits 7,15,31 - ignore the SPI (8,16,32 bites bus) error bits */ |
IanBenzMaxim | 0:33d4e66780c0 | 58 | #define BUF_SYNC_SPIM(pBuf) ((*(_u32 *)(pBuf)) & N2H_SYNC_SPI_BUGS_MASK) |
IanBenzMaxim | 0:33d4e66780c0 | 59 | |
IanBenzMaxim | 0:33d4e66780c0 | 60 | #define N2H_SYNC_SPIM (N2H_SYNC_PATTERN & N2H_SYNC_SPI_BUGS_MASK) |
IanBenzMaxim | 0:33d4e66780c0 | 61 | #define N2H_SYNC_SPIM_WITH_SEQ(TxSeqNum) ((N2H_SYNC_SPIM & N2H_SYNC_PATTERN_MASK) | N2H_SYNC_PATTERN_SEQ_NUM_EXISTS | ((TxSeqNum) & (N2H_SYNC_PATTERN_SEQ_NUM_BITS))) |
IanBenzMaxim | 0:33d4e66780c0 | 62 | #define MATCH_WOUT_SEQ_NUM(pBuf) ( BUF_SYNC_SPIM(pBuf) == N2H_SYNC_SPIM ) |
IanBenzMaxim | 0:33d4e66780c0 | 63 | #define MATCH_WITH_SEQ_NUM(pBuf, TxSeqNum) ( BUF_SYNC_SPIM(pBuf) == (N2H_SYNC_SPIM_WITH_SEQ(TxSeqNum)) ) |
IanBenzMaxim | 0:33d4e66780c0 | 64 | #define N2H_SYNC_PATTERN_MATCH(pBuf, TxSeqNum) \ |
IanBenzMaxim | 0:33d4e66780c0 | 65 | ( \ |
IanBenzMaxim | 0:33d4e66780c0 | 66 | ( (*((_u32 *)pBuf) & N2H_SYNC_PATTERN_SEQ_NUM_EXISTS) && ( MATCH_WITH_SEQ_NUM(pBuf, TxSeqNum) ) ) || \ |
IanBenzMaxim | 0:33d4e66780c0 | 67 | ( !(*((_u32 *)pBuf) & N2H_SYNC_PATTERN_SEQ_NUM_EXISTS) && ( MATCH_WOUT_SEQ_NUM(pBuf ) ) ) \ |
IanBenzMaxim | 0:33d4e66780c0 | 68 | ) |
IanBenzMaxim | 0:33d4e66780c0 | 69 | |
IanBenzMaxim | 0:33d4e66780c0 | 70 | #define OPCODE(_ptr) (((_SlResponseHeader_t *)(_ptr))->GenHeader.Opcode) |
IanBenzMaxim | 0:33d4e66780c0 | 71 | #define RSP_PAYLOAD_LEN(_ptr) (((_SlResponseHeader_t *)(_ptr))->GenHeader.Len - _SL_RESP_SPEC_HDR_SIZE) |
IanBenzMaxim | 0:33d4e66780c0 | 72 | #define SD(_ptr) (((_SocketAddrResponse_u *)(_ptr))->IpV4.sd) |
IanBenzMaxim | 0:33d4e66780c0 | 73 | /* Actual size of Recv/Recvfrom response data */ |
IanBenzMaxim | 0:33d4e66780c0 | 74 | #define ACT_DATA_SIZE(_ptr) (((_SocketAddrResponse_u *)(_ptr))->IpV4.statusOrLen) |
IanBenzMaxim | 0:33d4e66780c0 | 75 | |
IanBenzMaxim | 0:33d4e66780c0 | 76 | |
IanBenzMaxim | 0:33d4e66780c0 | 77 | /* Internal function prototype declaration */ |
IanBenzMaxim | 0:33d4e66780c0 | 78 | |
IanBenzMaxim | 0:33d4e66780c0 | 79 | |
IanBenzMaxim | 0:33d4e66780c0 | 80 | /* General Events handling*/ |
IanBenzMaxim | 0:33d4e66780c0 | 81 | #if defined (EXT_LIB_REGISTERED_GENERAL_EVENTS) |
IanBenzMaxim | 0:33d4e66780c0 | 82 | |
IanBenzMaxim | 0:33d4e66780c0 | 83 | typedef _SlEventPropogationStatus_e (*general_callback) (SlDeviceEvent_t *); |
IanBenzMaxim | 0:33d4e66780c0 | 84 | |
IanBenzMaxim | 0:33d4e66780c0 | 85 | static const general_callback general_callbacks[] = |
IanBenzMaxim | 0:33d4e66780c0 | 86 | { |
IanBenzMaxim | 0:33d4e66780c0 | 87 | #ifdef SlExtLib1GeneralEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 88 | SlExtLib1GeneralEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 89 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 90 | |
IanBenzMaxim | 0:33d4e66780c0 | 91 | #ifdef SlExtLib2GeneralEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 92 | SlExtLib2GeneralEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 93 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 94 | |
IanBenzMaxim | 0:33d4e66780c0 | 95 | #ifdef SlExtLib3GeneralEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 96 | SlExtLib3GeneralEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 97 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 98 | |
IanBenzMaxim | 0:33d4e66780c0 | 99 | #ifdef SlExtLib4GeneralEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 100 | SlExtLib4GeneralEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 101 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 102 | |
IanBenzMaxim | 0:33d4e66780c0 | 103 | #ifdef SlExtLib5GeneralEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 104 | SlExtLib5GeneralEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 105 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 106 | }; |
IanBenzMaxim | 0:33d4e66780c0 | 107 | |
IanBenzMaxim | 0:33d4e66780c0 | 108 | #undef _SlDrvHandleGeneralEvents |
IanBenzMaxim | 0:33d4e66780c0 | 109 | |
IanBenzMaxim | 0:33d4e66780c0 | 110 | /******************************************************************** |
IanBenzMaxim | 0:33d4e66780c0 | 111 | _SlDrvHandleGeneralEvents |
IanBenzMaxim | 0:33d4e66780c0 | 112 | Iterates through all the general(device) event handlers which are |
IanBenzMaxim | 0:33d4e66780c0 | 113 | registered by the external libs/user application. |
IanBenzMaxim | 0:33d4e66780c0 | 114 | *********************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 115 | void _SlDrvHandleGeneralEvents(SlDeviceEvent_t *slGeneralEvent) |
IanBenzMaxim | 0:33d4e66780c0 | 116 | { |
IanBenzMaxim | 0:33d4e66780c0 | 117 | _u8 i; |
IanBenzMaxim | 0:33d4e66780c0 | 118 | |
IanBenzMaxim | 0:33d4e66780c0 | 119 | /* Iterate over all the extenal libs handlers */ |
IanBenzMaxim | 0:33d4e66780c0 | 120 | for ( i = 0 ; i < sizeof(general_callbacks)/sizeof(general_callbacks[0]) ; i++ ) |
IanBenzMaxim | 0:33d4e66780c0 | 121 | { |
IanBenzMaxim | 0:33d4e66780c0 | 122 | if (EVENT_PROPAGATION_BLOCK == general_callbacks[i](slGeneralEvent) ) |
IanBenzMaxim | 0:33d4e66780c0 | 123 | { |
IanBenzMaxim | 0:33d4e66780c0 | 124 | /* exit immediately and do not call the user specific handler as well */ |
IanBenzMaxim | 0:33d4e66780c0 | 125 | return; |
IanBenzMaxim | 0:33d4e66780c0 | 126 | } |
IanBenzMaxim | 0:33d4e66780c0 | 127 | } |
IanBenzMaxim | 0:33d4e66780c0 | 128 | |
IanBenzMaxim | 0:33d4e66780c0 | 129 | /* At last call the Application specific handler if registered */ |
IanBenzMaxim | 0:33d4e66780c0 | 130 | #ifdef sl_GeneralEvtHdlr |
IanBenzMaxim | 0:33d4e66780c0 | 131 | sl_GeneralEvtHdlr(slGeneralEvent); |
IanBenzMaxim | 0:33d4e66780c0 | 132 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 133 | |
IanBenzMaxim | 0:33d4e66780c0 | 134 | } |
IanBenzMaxim | 0:33d4e66780c0 | 135 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 136 | |
IanBenzMaxim | 0:33d4e66780c0 | 137 | |
IanBenzMaxim | 0:33d4e66780c0 | 138 | |
IanBenzMaxim | 0:33d4e66780c0 | 139 | /* WLAN Events handling*/ |
IanBenzMaxim | 0:33d4e66780c0 | 140 | |
IanBenzMaxim | 0:33d4e66780c0 | 141 | #if defined (EXT_LIB_REGISTERED_WLAN_EVENTS) |
IanBenzMaxim | 0:33d4e66780c0 | 142 | |
IanBenzMaxim | 0:33d4e66780c0 | 143 | typedef _SlEventPropogationStatus_e (*wlan_callback) (SlWlanEvent_t *); |
IanBenzMaxim | 0:33d4e66780c0 | 144 | |
IanBenzMaxim | 0:33d4e66780c0 | 145 | static wlan_callback wlan_callbacks[] = |
IanBenzMaxim | 0:33d4e66780c0 | 146 | { |
IanBenzMaxim | 0:33d4e66780c0 | 147 | #ifdef SlExtLib1WlanEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 148 | SlExtLib1WlanEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 149 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 150 | |
IanBenzMaxim | 0:33d4e66780c0 | 151 | #ifdef SlExtLib2WlanEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 152 | SlExtLib2WlanEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 153 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 154 | |
IanBenzMaxim | 0:33d4e66780c0 | 155 | #ifdef SlExtLib3WlanEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 156 | SlExtLib3WlanEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 157 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 158 | |
IanBenzMaxim | 0:33d4e66780c0 | 159 | #ifdef SlExtLib4WlanEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 160 | SlExtLib4WlanEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 161 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 162 | |
IanBenzMaxim | 0:33d4e66780c0 | 163 | #ifdef SlExtLib5WlanEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 164 | SlExtLib5WlanEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 165 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 166 | }; |
IanBenzMaxim | 0:33d4e66780c0 | 167 | |
IanBenzMaxim | 0:33d4e66780c0 | 168 | #undef _SlDrvHandleWlanEvents |
IanBenzMaxim | 0:33d4e66780c0 | 169 | |
IanBenzMaxim | 0:33d4e66780c0 | 170 | /*********************************************************** |
IanBenzMaxim | 0:33d4e66780c0 | 171 | _SlDrvHandleWlanEvents |
IanBenzMaxim | 0:33d4e66780c0 | 172 | Iterates through all the wlan event handlers which are |
IanBenzMaxim | 0:33d4e66780c0 | 173 | registered by the external libs/user application. |
IanBenzMaxim | 0:33d4e66780c0 | 174 | ************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 175 | void _SlDrvHandleWlanEvents(SlWlanEvent_t *slWlanEvent) |
IanBenzMaxim | 0:33d4e66780c0 | 176 | { |
IanBenzMaxim | 0:33d4e66780c0 | 177 | _u8 i; |
IanBenzMaxim | 0:33d4e66780c0 | 178 | |
IanBenzMaxim | 0:33d4e66780c0 | 179 | /* Iterate over all the extenal libs handlers */ |
IanBenzMaxim | 0:33d4e66780c0 | 180 | for ( i = 0 ; i < sizeof(wlan_callbacks)/sizeof(wlan_callbacks[0]) ; i++ ) |
IanBenzMaxim | 0:33d4e66780c0 | 181 | { |
IanBenzMaxim | 0:33d4e66780c0 | 182 | if ( EVENT_PROPAGATION_BLOCK == wlan_callbacks[i](slWlanEvent) ) |
IanBenzMaxim | 0:33d4e66780c0 | 183 | { |
IanBenzMaxim | 0:33d4e66780c0 | 184 | /* exit immediately and do not call the user specific handler as well */ |
IanBenzMaxim | 0:33d4e66780c0 | 185 | return; |
IanBenzMaxim | 0:33d4e66780c0 | 186 | } |
IanBenzMaxim | 0:33d4e66780c0 | 187 | } |
IanBenzMaxim | 0:33d4e66780c0 | 188 | |
IanBenzMaxim | 0:33d4e66780c0 | 189 | /* At last call the Application specific handler if registered */ |
IanBenzMaxim | 0:33d4e66780c0 | 190 | #ifdef sl_WlanEvtHdlr |
IanBenzMaxim | 0:33d4e66780c0 | 191 | sl_WlanEvtHdlr(slWlanEvent); |
IanBenzMaxim | 0:33d4e66780c0 | 192 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 193 | |
IanBenzMaxim | 0:33d4e66780c0 | 194 | } |
IanBenzMaxim | 0:33d4e66780c0 | 195 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 196 | |
IanBenzMaxim | 0:33d4e66780c0 | 197 | |
IanBenzMaxim | 0:33d4e66780c0 | 198 | /* NetApp Events handling */ |
IanBenzMaxim | 0:33d4e66780c0 | 199 | #if defined (EXT_LIB_REGISTERED_NETAPP_EVENTS) |
IanBenzMaxim | 0:33d4e66780c0 | 200 | |
IanBenzMaxim | 0:33d4e66780c0 | 201 | typedef _SlEventPropogationStatus_e (*netApp_callback) (SlNetAppEvent_t *); |
IanBenzMaxim | 0:33d4e66780c0 | 202 | |
IanBenzMaxim | 0:33d4e66780c0 | 203 | static const netApp_callback netApp_callbacks[] = |
IanBenzMaxim | 0:33d4e66780c0 | 204 | { |
IanBenzMaxim | 0:33d4e66780c0 | 205 | #ifdef SlExtLib1NetAppEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 206 | SlExtLib1NetAppEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 207 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 208 | |
IanBenzMaxim | 0:33d4e66780c0 | 209 | #ifdef SlExtLib2NetAppEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 210 | SlExtLib2NetAppEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 211 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 212 | |
IanBenzMaxim | 0:33d4e66780c0 | 213 | #ifdef SlExtLib3NetAppEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 214 | SlExtLib3NetAppEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 215 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 216 | |
IanBenzMaxim | 0:33d4e66780c0 | 217 | #ifdef SlExtLib4NetAppEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 218 | SlExtLib4NetAppEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 219 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 220 | |
IanBenzMaxim | 0:33d4e66780c0 | 221 | #ifdef SlExtLib5NetAppEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 222 | SlExtLib5NetAppEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 223 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 224 | }; |
IanBenzMaxim | 0:33d4e66780c0 | 225 | |
IanBenzMaxim | 0:33d4e66780c0 | 226 | #undef _SlDrvHandleNetAppEvents |
IanBenzMaxim | 0:33d4e66780c0 | 227 | |
IanBenzMaxim | 0:33d4e66780c0 | 228 | /************************************************************ |
IanBenzMaxim | 0:33d4e66780c0 | 229 | _SlDrvHandleNetAppEvents |
IanBenzMaxim | 0:33d4e66780c0 | 230 | Iterates through all the net app event handlers which are |
IanBenzMaxim | 0:33d4e66780c0 | 231 | registered by the external libs/user application. |
IanBenzMaxim | 0:33d4e66780c0 | 232 | ************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 233 | void _SlDrvHandleNetAppEvents(SlNetAppEvent_t *slNetAppEvent) |
IanBenzMaxim | 0:33d4e66780c0 | 234 | { |
IanBenzMaxim | 0:33d4e66780c0 | 235 | _u8 i; |
IanBenzMaxim | 0:33d4e66780c0 | 236 | |
IanBenzMaxim | 0:33d4e66780c0 | 237 | /* Iterate over all the extenal libs handlers */ |
IanBenzMaxim | 0:33d4e66780c0 | 238 | for ( i = 0 ; i < sizeof(netApp_callbacks)/sizeof(netApp_callbacks[0]) ; i++ ) |
IanBenzMaxim | 0:33d4e66780c0 | 239 | { |
IanBenzMaxim | 0:33d4e66780c0 | 240 | if (EVENT_PROPAGATION_BLOCK == netApp_callbacks[i](slNetAppEvent) ) |
IanBenzMaxim | 0:33d4e66780c0 | 241 | { |
IanBenzMaxim | 0:33d4e66780c0 | 242 | /* exit immediately and do not call the user specific handler as well */ |
IanBenzMaxim | 0:33d4e66780c0 | 243 | return; |
IanBenzMaxim | 0:33d4e66780c0 | 244 | } |
IanBenzMaxim | 0:33d4e66780c0 | 245 | } |
IanBenzMaxim | 0:33d4e66780c0 | 246 | |
IanBenzMaxim | 0:33d4e66780c0 | 247 | /* At last call the Application specific handler if registered */ |
IanBenzMaxim | 0:33d4e66780c0 | 248 | #ifdef sl_NetAppEvtHdlr |
IanBenzMaxim | 0:33d4e66780c0 | 249 | sl_NetAppEvtHdlr(slNetAppEvent); |
IanBenzMaxim | 0:33d4e66780c0 | 250 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 251 | |
IanBenzMaxim | 0:33d4e66780c0 | 252 | } |
IanBenzMaxim | 0:33d4e66780c0 | 253 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 254 | |
IanBenzMaxim | 0:33d4e66780c0 | 255 | |
IanBenzMaxim | 0:33d4e66780c0 | 256 | /* Http Server Events handling */ |
IanBenzMaxim | 0:33d4e66780c0 | 257 | #if defined (EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS) |
IanBenzMaxim | 0:33d4e66780c0 | 258 | |
IanBenzMaxim | 0:33d4e66780c0 | 259 | typedef _SlEventPropogationStatus_e (*httpServer_callback) (SlHttpServerEvent_t*, SlHttpServerResponse_t*); |
IanBenzMaxim | 0:33d4e66780c0 | 260 | |
IanBenzMaxim | 0:33d4e66780c0 | 261 | static const httpServer_callback httpServer_callbacks[] = |
IanBenzMaxim | 0:33d4e66780c0 | 262 | { |
IanBenzMaxim | 0:33d4e66780c0 | 263 | #ifdef SlExtLib1HttpServerEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 264 | SlExtLib1HttpServerEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 265 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 266 | |
IanBenzMaxim | 0:33d4e66780c0 | 267 | #ifdef SlExtLib2HttpServerEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 268 | SlExtLib2HttpServerEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 269 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 270 | |
IanBenzMaxim | 0:33d4e66780c0 | 271 | #ifdef SlExtLib3HttpServerEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 272 | SlExtLib3HttpServerEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 273 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 274 | |
IanBenzMaxim | 0:33d4e66780c0 | 275 | #ifdef SlExtLib4HttpServerEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 276 | SlExtLib4HttpServerEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 277 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 278 | |
IanBenzMaxim | 0:33d4e66780c0 | 279 | #ifdef SlExtLib5HttpServerEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 280 | SlExtLib5HttpServerEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 281 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 282 | }; |
IanBenzMaxim | 0:33d4e66780c0 | 283 | |
IanBenzMaxim | 0:33d4e66780c0 | 284 | #undef _SlDrvHandleHttpServerEvents |
IanBenzMaxim | 0:33d4e66780c0 | 285 | |
IanBenzMaxim | 0:33d4e66780c0 | 286 | /******************************************************************* |
IanBenzMaxim | 0:33d4e66780c0 | 287 | _SlDrvHandleHttpServerEvents |
IanBenzMaxim | 0:33d4e66780c0 | 288 | Iterates through all the http server event handlers which are |
IanBenzMaxim | 0:33d4e66780c0 | 289 | registered by the external libs/user application. |
IanBenzMaxim | 0:33d4e66780c0 | 290 | ********************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 291 | void _SlDrvHandleHttpServerEvents(SlHttpServerEvent_t *slHttpServerEvent, SlHttpServerResponse_t *slHttpServerResponse) |
IanBenzMaxim | 0:33d4e66780c0 | 292 | { |
IanBenzMaxim | 0:33d4e66780c0 | 293 | _u8 i; |
IanBenzMaxim | 0:33d4e66780c0 | 294 | |
IanBenzMaxim | 0:33d4e66780c0 | 295 | /* Iterate over all the external libs handlers */ |
IanBenzMaxim | 0:33d4e66780c0 | 296 | for ( i = 0 ; i < sizeof(httpServer_callbacks)/sizeof(httpServer_callbacks[0]) ; i++ ) |
IanBenzMaxim | 0:33d4e66780c0 | 297 | { |
IanBenzMaxim | 0:33d4e66780c0 | 298 | if ( EVENT_PROPAGATION_BLOCK == httpServer_callbacks[i](slHttpServerEvent, slHttpServerResponse) ) |
IanBenzMaxim | 0:33d4e66780c0 | 299 | { |
IanBenzMaxim | 0:33d4e66780c0 | 300 | /* exit immediately and do not call the user specific handler as well */ |
IanBenzMaxim | 0:33d4e66780c0 | 301 | return; |
IanBenzMaxim | 0:33d4e66780c0 | 302 | } |
IanBenzMaxim | 0:33d4e66780c0 | 303 | } |
IanBenzMaxim | 0:33d4e66780c0 | 304 | |
IanBenzMaxim | 0:33d4e66780c0 | 305 | /* At last call the Application specific handler if registered */ |
IanBenzMaxim | 0:33d4e66780c0 | 306 | #ifdef sl_HttpServerCallback |
IanBenzMaxim | 0:33d4e66780c0 | 307 | sl_HttpServerCallback(slHttpServerEvent, slHttpServerResponse); |
IanBenzMaxim | 0:33d4e66780c0 | 308 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 309 | |
IanBenzMaxim | 0:33d4e66780c0 | 310 | } |
IanBenzMaxim | 0:33d4e66780c0 | 311 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 312 | |
IanBenzMaxim | 0:33d4e66780c0 | 313 | |
IanBenzMaxim | 0:33d4e66780c0 | 314 | /* Socket Events */ |
IanBenzMaxim | 0:33d4e66780c0 | 315 | #if defined (EXT_LIB_REGISTERED_SOCK_EVENTS) |
IanBenzMaxim | 0:33d4e66780c0 | 316 | |
IanBenzMaxim | 0:33d4e66780c0 | 317 | typedef _SlEventPropogationStatus_e (*sock_callback) (SlSockEvent_t *); |
IanBenzMaxim | 0:33d4e66780c0 | 318 | |
IanBenzMaxim | 0:33d4e66780c0 | 319 | static const sock_callback sock_callbacks[] = |
IanBenzMaxim | 0:33d4e66780c0 | 320 | { |
IanBenzMaxim | 0:33d4e66780c0 | 321 | #ifdef SlExtLib1SockEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 322 | SlExtLib1SockEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 323 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 324 | |
IanBenzMaxim | 0:33d4e66780c0 | 325 | #ifdef SlExtLib2SockEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 326 | SlExtLib2SockEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 327 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 328 | |
IanBenzMaxim | 0:33d4e66780c0 | 329 | #ifdef SlExtLib3SockEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 330 | SlExtLib3SockEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 331 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 332 | |
IanBenzMaxim | 0:33d4e66780c0 | 333 | #ifdef SlExtLib4SockEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 334 | SlExtLib4SockEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 335 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 336 | |
IanBenzMaxim | 0:33d4e66780c0 | 337 | #ifdef SlExtLib5SockEventHandler |
IanBenzMaxim | 0:33d4e66780c0 | 338 | SlExtLib5SockEventHandler, |
IanBenzMaxim | 0:33d4e66780c0 | 339 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 340 | }; |
IanBenzMaxim | 0:33d4e66780c0 | 341 | |
IanBenzMaxim | 0:33d4e66780c0 | 342 | /************************************************************* |
IanBenzMaxim | 0:33d4e66780c0 | 343 | _SlDrvHandleSockEvents |
IanBenzMaxim | 0:33d4e66780c0 | 344 | Iterates through all the socket event handlers which are |
IanBenzMaxim | 0:33d4e66780c0 | 345 | registered by the external libs/user application. |
IanBenzMaxim | 0:33d4e66780c0 | 346 | **************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 347 | void _SlDrvHandleSockEvents(SlSockEvent_t *slSockEvent) |
IanBenzMaxim | 0:33d4e66780c0 | 348 | { |
IanBenzMaxim | 0:33d4e66780c0 | 349 | _u8 i; |
IanBenzMaxim | 0:33d4e66780c0 | 350 | |
IanBenzMaxim | 0:33d4e66780c0 | 351 | /* Iterate over all the external libs handlers */ |
IanBenzMaxim | 0:33d4e66780c0 | 352 | for ( i = 0 ; i < sizeof(sock_callbacks)/sizeof(sock_callbacks[0]) ; i++ ) |
IanBenzMaxim | 0:33d4e66780c0 | 353 | { |
IanBenzMaxim | 0:33d4e66780c0 | 354 | if ( EVENT_PROPAGATION_BLOCK == sock_callbacks[i](slSockEvent) ) |
IanBenzMaxim | 0:33d4e66780c0 | 355 | { |
IanBenzMaxim | 0:33d4e66780c0 | 356 | /* exit immediately and do not call the user specific handler as well */ |
IanBenzMaxim | 0:33d4e66780c0 | 357 | return; |
IanBenzMaxim | 0:33d4e66780c0 | 358 | } |
IanBenzMaxim | 0:33d4e66780c0 | 359 | } |
IanBenzMaxim | 0:33d4e66780c0 | 360 | |
IanBenzMaxim | 0:33d4e66780c0 | 361 | /* At last call the Application specific handler if registered */ |
IanBenzMaxim | 0:33d4e66780c0 | 362 | #ifdef sl_SockEvtHdlr |
IanBenzMaxim | 0:33d4e66780c0 | 363 | sl_SockEvtHdlr(slSockEvent); |
IanBenzMaxim | 0:33d4e66780c0 | 364 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 365 | |
IanBenzMaxim | 0:33d4e66780c0 | 366 | } |
IanBenzMaxim | 0:33d4e66780c0 | 367 | |
IanBenzMaxim | 0:33d4e66780c0 | 368 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 369 | |
IanBenzMaxim | 0:33d4e66780c0 | 370 | |
IanBenzMaxim | 0:33d4e66780c0 | 371 | #ifndef SL_MEMORY_MGMT_DYNAMIC |
IanBenzMaxim | 0:33d4e66780c0 | 372 | typedef struct |
IanBenzMaxim | 0:33d4e66780c0 | 373 | { |
IanBenzMaxim | 0:33d4e66780c0 | 374 | _u32 Align; |
IanBenzMaxim | 0:33d4e66780c0 | 375 | _SlDriverCb_t DriverCB; |
IanBenzMaxim | 0:33d4e66780c0 | 376 | _u8 AsyncRespBuf[SL_ASYNC_MAX_MSG_LEN]; |
IanBenzMaxim | 0:33d4e66780c0 | 377 | }_SlStatMem_t; |
IanBenzMaxim | 0:33d4e66780c0 | 378 | |
IanBenzMaxim | 0:33d4e66780c0 | 379 | static _SlStatMem_t g_StatMem; |
IanBenzMaxim | 0:33d4e66780c0 | 380 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 381 | |
IanBenzMaxim | 0:33d4e66780c0 | 382 | _u8 _SlDrvProtectAsyncRespSetting(_u8 *pAsyncRsp, _SlActionID_e ActionID, _u8 SocketID) |
IanBenzMaxim | 0:33d4e66780c0 | 383 | { |
IanBenzMaxim | 0:33d4e66780c0 | 384 | _u8 ObjIdx; |
IanBenzMaxim | 0:33d4e66780c0 | 385 | |
IanBenzMaxim | 0:33d4e66780c0 | 386 | |
IanBenzMaxim | 0:33d4e66780c0 | 387 | /* Use Obj to issue the command, if not available try later */ |
IanBenzMaxim | 0:33d4e66780c0 | 388 | ObjIdx = (_u8)_SlDrvWaitForPoolObj(ActionID, SocketID); |
IanBenzMaxim | 0:33d4e66780c0 | 389 | |
IanBenzMaxim | 0:33d4e66780c0 | 390 | if (MAX_CONCURRENT_ACTIONS != ObjIdx) |
IanBenzMaxim | 0:33d4e66780c0 | 391 | { |
IanBenzMaxim | 0:33d4e66780c0 | 392 | SL_DRV_PROTECTION_OBJ_LOCK_FOREVER(); |
IanBenzMaxim | 0:33d4e66780c0 | 393 | g_pCB->ObjPool[ObjIdx].pRespArgs = pAsyncRsp; |
IanBenzMaxim | 0:33d4e66780c0 | 394 | SL_DRV_PROTECTION_OBJ_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 395 | } |
IanBenzMaxim | 0:33d4e66780c0 | 396 | |
IanBenzMaxim | 0:33d4e66780c0 | 397 | return ObjIdx; |
IanBenzMaxim | 0:33d4e66780c0 | 398 | } |
IanBenzMaxim | 0:33d4e66780c0 | 399 | |
IanBenzMaxim | 0:33d4e66780c0 | 400 | |
IanBenzMaxim | 0:33d4e66780c0 | 401 | /*****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 402 | /* Variables */ |
IanBenzMaxim | 0:33d4e66780c0 | 403 | /*****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 404 | static const _SlSyncPattern_t g_H2NSyncPattern = H2N_SYNC_PATTERN; |
IanBenzMaxim | 0:33d4e66780c0 | 405 | |
IanBenzMaxim | 0:33d4e66780c0 | 406 | #ifndef SL_IF_TYPE_UART |
IanBenzMaxim | 0:33d4e66780c0 | 407 | static const _SlSyncPattern_t g_H2NCnysPattern = H2N_CNYS_PATTERN; |
IanBenzMaxim | 0:33d4e66780c0 | 408 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 409 | |
IanBenzMaxim | 0:33d4e66780c0 | 410 | |
IanBenzMaxim | 0:33d4e66780c0 | 411 | _volatile _u8 RxIrqCnt; |
IanBenzMaxim | 0:33d4e66780c0 | 412 | |
IanBenzMaxim | 0:33d4e66780c0 | 413 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 414 | |
IanBenzMaxim | 0:33d4e66780c0 | 415 | _volatile _u8 g_bDeviceRestartIsRequired; |
IanBenzMaxim | 0:33d4e66780c0 | 416 | |
IanBenzMaxim | 0:33d4e66780c0 | 417 | const _SlActionLookup_t _SlActionLookupTable[] = |
IanBenzMaxim | 0:33d4e66780c0 | 418 | { |
IanBenzMaxim | 0:33d4e66780c0 | 419 | {ACCEPT_ID, SL_OPCODE_SOCKET_ACCEPTASYNCRESPONSE, (_SlSpawnEntryFunc_t)_sl_HandleAsync_Accept}, |
IanBenzMaxim | 0:33d4e66780c0 | 420 | {CONNECT_ID, SL_OPCODE_SOCKET_CONNECTASYNCRESPONSE,(_SlSpawnEntryFunc_t)_sl_HandleAsync_Connect}, |
IanBenzMaxim | 0:33d4e66780c0 | 421 | {SELECT_ID, SL_OPCODE_SOCKET_SELECTASYNCRESPONSE,(_SlSpawnEntryFunc_t)_sl_HandleAsync_Select}, |
IanBenzMaxim | 0:33d4e66780c0 | 422 | {GETHOSYBYNAME_ID, SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE,(_SlSpawnEntryFunc_t)_sl_HandleAsync_DnsGetHostByName}, |
IanBenzMaxim | 0:33d4e66780c0 | 423 | {GETHOSYBYSERVICE_ID, SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE,(_SlSpawnEntryFunc_t)_sl_HandleAsync_DnsGetHostByService}, |
IanBenzMaxim | 0:33d4e66780c0 | 424 | {PING_ID, SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE, (_SlSpawnEntryFunc_t)_sl_HandleAsync_PingResponse}, |
IanBenzMaxim | 0:33d4e66780c0 | 425 | {START_STOP_ID, SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE,(_SlSpawnEntryFunc_t)_sl_HandleAsync_Stop} |
IanBenzMaxim | 0:33d4e66780c0 | 426 | }; |
IanBenzMaxim | 0:33d4e66780c0 | 427 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 428 | const _SlActionLookup_t _SlActionLookupTable[] = |
IanBenzMaxim | 0:33d4e66780c0 | 429 | { |
IanBenzMaxim | 0:33d4e66780c0 | 430 | {CONNECT_ID, SL_OPCODE_SOCKET_CONNECTASYNCRESPONSE,(_SlSpawnEntryFunc_t)_sl_HandleAsync_Connect}, |
IanBenzMaxim | 0:33d4e66780c0 | 431 | {GETHOSYBYNAME_ID, SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE,(_SlSpawnEntryFunc_t)_sl_HandleAsync_DnsGetHostByName}, |
IanBenzMaxim | 0:33d4e66780c0 | 432 | {START_STOP_ID, SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE,(_SlSpawnEntryFunc_t)_sl_HandleAsync_Stop} |
IanBenzMaxim | 0:33d4e66780c0 | 433 | }; |
IanBenzMaxim | 0:33d4e66780c0 | 434 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 435 | |
IanBenzMaxim | 0:33d4e66780c0 | 436 | |
IanBenzMaxim | 0:33d4e66780c0 | 437 | |
IanBenzMaxim | 0:33d4e66780c0 | 438 | typedef struct |
IanBenzMaxim | 0:33d4e66780c0 | 439 | { |
IanBenzMaxim | 0:33d4e66780c0 | 440 | _u16 opcode; |
IanBenzMaxim | 0:33d4e66780c0 | 441 | _u8 event; |
IanBenzMaxim | 0:33d4e66780c0 | 442 | } OpcodeKeyVal_t; |
IanBenzMaxim | 0:33d4e66780c0 | 443 | |
IanBenzMaxim | 0:33d4e66780c0 | 444 | /* The table translates opcode to user's event type */ |
IanBenzMaxim | 0:33d4e66780c0 | 445 | const OpcodeKeyVal_t OpcodeTranslateTable[] = |
IanBenzMaxim | 0:33d4e66780c0 | 446 | { |
IanBenzMaxim | 0:33d4e66780c0 | 447 | {SL_OPCODE_WLAN_SMART_CONFIG_START_ASYNC_RESPONSE, SL_WLAN_SMART_CONFIG_COMPLETE_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 448 | {SL_OPCODE_WLAN_SMART_CONFIG_STOP_ASYNC_RESPONSE,SL_WLAN_SMART_CONFIG_STOP_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 449 | {SL_OPCODE_WLAN_STA_CONNECTED, SL_WLAN_STA_CONNECTED_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 450 | {SL_OPCODE_WLAN_STA_DISCONNECTED,SL_WLAN_STA_DISCONNECTED_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 451 | {SL_OPCODE_WLAN_P2P_DEV_FOUND,SL_WLAN_P2P_DEV_FOUND_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 452 | {SL_OPCODE_WLAN_P2P_NEG_REQ_RECEIVED, SL_WLAN_P2P_NEG_REQ_RECEIVED_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 453 | {SL_OPCODE_WLAN_CONNECTION_FAILED, SL_WLAN_CONNECTION_FAILED_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 454 | {SL_OPCODE_WLAN_WLANASYNCCONNECTEDRESPONSE, SL_WLAN_CONNECT_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 455 | {SL_OPCODE_WLAN_WLANASYNCDISCONNECTEDRESPONSE, SL_WLAN_DISCONNECT_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 456 | {SL_OPCODE_NETAPP_IPACQUIRED, SL_NETAPP_IPV4_IPACQUIRED_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 457 | {SL_OPCODE_NETAPP_IPACQUIRED_V6, SL_NETAPP_IPV6_IPACQUIRED_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 458 | {SL_OPCODE_NETAPP_IP_LEASED, SL_NETAPP_IP_LEASED_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 459 | {SL_OPCODE_NETAPP_IP_RELEASED, SL_NETAPP_IP_RELEASED_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 460 | {SL_OPCODE_SOCKET_TXFAILEDASYNCRESPONSE, SL_SOCKET_TX_FAILED_EVENT}, |
IanBenzMaxim | 0:33d4e66780c0 | 461 | {SL_OPCODE_SOCKET_SOCKETASYNCEVENT, SL_SOCKET_ASYNC_EVENT} |
IanBenzMaxim | 0:33d4e66780c0 | 462 | }; |
IanBenzMaxim | 0:33d4e66780c0 | 463 | |
IanBenzMaxim | 0:33d4e66780c0 | 464 | |
IanBenzMaxim | 0:33d4e66780c0 | 465 | |
IanBenzMaxim | 0:33d4e66780c0 | 466 | _SlDriverCb_t* g_pCB = NULL; |
IanBenzMaxim | 0:33d4e66780c0 | 467 | P_SL_DEV_PING_CALLBACK pPingCallBackFunc = NULL; |
IanBenzMaxim | 0:33d4e66780c0 | 468 | |
IanBenzMaxim | 0:33d4e66780c0 | 469 | #ifndef SL_IF_TYPE_UART |
IanBenzMaxim | 0:33d4e66780c0 | 470 | static _u8 gFirstCmdMode = 0; |
IanBenzMaxim | 0:33d4e66780c0 | 471 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 472 | |
IanBenzMaxim | 0:33d4e66780c0 | 473 | /*****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 474 | /* Function prototypes */ |
IanBenzMaxim | 0:33d4e66780c0 | 475 | /*****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 476 | static _SlReturnVal_t _SlDrvMsgRead(void); |
IanBenzMaxim | 0:33d4e66780c0 | 477 | static _SlReturnVal_t _SlDrvMsgWrite(_SlCmdCtrl_t *pCmdCtrl,_SlCmdExt_t *pCmdExt, _u8 *pTxRxDescBuff); |
IanBenzMaxim | 0:33d4e66780c0 | 478 | static _SlReturnVal_t _SlDrvMsgReadCmdCtx(_u16 cmdOpcode); |
IanBenzMaxim | 0:33d4e66780c0 | 479 | static _SlReturnVal_t _SlDrvClassifyRxMsg(_SlOpcode_t Opcode ); |
IanBenzMaxim | 0:33d4e66780c0 | 480 | static _SlReturnVal_t _SlDrvRxHdrRead(_u8 *pBuf, _u8 *pAlignSize); |
IanBenzMaxim | 0:33d4e66780c0 | 481 | static void _SlAsyncEventGenericHandler(_u8 bInCmdContext); |
IanBenzMaxim | 0:33d4e66780c0 | 482 | static void _SlRemoveFromList(_u8* ListIndex, _u8 ItemIndex); |
IanBenzMaxim | 0:33d4e66780c0 | 483 | static _SlReturnVal_t _SlFindAndSetActiveObj(_SlOpcode_t Opcode, _u8 Sd); |
IanBenzMaxim | 0:33d4e66780c0 | 484 | static _SlReturnVal_t _SlDrvObjGlobalLockWaitForever(void); |
IanBenzMaxim | 0:33d4e66780c0 | 485 | |
IanBenzMaxim | 0:33d4e66780c0 | 486 | /*****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 487 | /* Internal functions */ |
IanBenzMaxim | 0:33d4e66780c0 | 488 | /*****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 489 | |
IanBenzMaxim | 0:33d4e66780c0 | 490 | |
IanBenzMaxim | 0:33d4e66780c0 | 491 | /***************************************************************************** |
IanBenzMaxim | 0:33d4e66780c0 | 492 | _SlDrvDriverCBInit - init Driver Control Block |
IanBenzMaxim | 0:33d4e66780c0 | 493 | *****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 494 | |
IanBenzMaxim | 0:33d4e66780c0 | 495 | _SlReturnVal_t _SlDrvDriverCBInit(void) |
IanBenzMaxim | 0:33d4e66780c0 | 496 | { |
IanBenzMaxim | 0:33d4e66780c0 | 497 | _u8 Idx =0; |
IanBenzMaxim | 0:33d4e66780c0 | 498 | |
IanBenzMaxim | 0:33d4e66780c0 | 499 | #ifdef SL_MEMORY_MGMT_DYNAMIC |
IanBenzMaxim | 0:33d4e66780c0 | 500 | g_pCB = (_SlDriverCb_t*)sl_Malloc(sizeof(_SlDriverCb_t)); |
IanBenzMaxim | 0:33d4e66780c0 | 501 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 502 | g_pCB = &(g_StatMem.DriverCB); |
IanBenzMaxim | 0:33d4e66780c0 | 503 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 504 | MALLOC_OK_CHECK(g_pCB); |
IanBenzMaxim | 0:33d4e66780c0 | 505 | |
IanBenzMaxim | 0:33d4e66780c0 | 506 | #ifndef SL_PLATFORM_MULTI_THREADED |
IanBenzMaxim | 0:33d4e66780c0 | 507 | { |
IanBenzMaxim | 0:33d4e66780c0 | 508 | extern _SlNonOsCB_t g__SlNonOsCB; |
IanBenzMaxim | 0:33d4e66780c0 | 509 | sl_Memset(&g__SlNonOsCB, 0, sizeof(g__SlNonOsCB)); |
IanBenzMaxim | 0:33d4e66780c0 | 510 | } |
IanBenzMaxim | 0:33d4e66780c0 | 511 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 512 | |
IanBenzMaxim | 0:33d4e66780c0 | 513 | _SlDrvMemZero(g_pCB, (_u16)sizeof(_SlDriverCb_t)); |
IanBenzMaxim | 0:33d4e66780c0 | 514 | RxIrqCnt = 0; |
IanBenzMaxim | 0:33d4e66780c0 | 515 | OSI_RET_OK_CHECK( sl_SyncObjCreate(&g_pCB->CmdSyncObj, "CmdSyncObj") ); |
IanBenzMaxim | 0:33d4e66780c0 | 516 | SL_DRV_SYNC_OBJ_CLEAR(&g_pCB->CmdSyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 517 | |
IanBenzMaxim | 0:33d4e66780c0 | 518 | OSI_RET_OK_CHECK( sl_LockObjCreate(&g_pCB->GlobalLockObj, "GlobalLockObj") ); |
IanBenzMaxim | 0:33d4e66780c0 | 519 | OSI_RET_OK_CHECK( sl_LockObjCreate(&g_pCB->ProtectionLockObj, "ProtectionLockObj") ); |
IanBenzMaxim | 0:33d4e66780c0 | 520 | |
IanBenzMaxim | 0:33d4e66780c0 | 521 | /* Init Drv object */ |
IanBenzMaxim | 0:33d4e66780c0 | 522 | _SlDrvMemZero(&g_pCB->ObjPool[0], (_u16)(MAX_CONCURRENT_ACTIONS*sizeof(_SlPoolObj_t))); |
IanBenzMaxim | 0:33d4e66780c0 | 523 | |
IanBenzMaxim | 0:33d4e66780c0 | 524 | /* place all Obj in the free list*/ |
IanBenzMaxim | 0:33d4e66780c0 | 525 | g_pCB->FreePoolIdx = 0; |
IanBenzMaxim | 0:33d4e66780c0 | 526 | |
IanBenzMaxim | 0:33d4e66780c0 | 527 | for (Idx = 0 ; Idx < MAX_CONCURRENT_ACTIONS ; Idx++) |
IanBenzMaxim | 0:33d4e66780c0 | 528 | { |
IanBenzMaxim | 0:33d4e66780c0 | 529 | g_pCB->ObjPool[Idx].NextIndex = Idx + 1; |
IanBenzMaxim | 0:33d4e66780c0 | 530 | g_pCB->ObjPool[Idx].AdditionalData = SL_MAX_SOCKETS; |
IanBenzMaxim | 0:33d4e66780c0 | 531 | |
IanBenzMaxim | 0:33d4e66780c0 | 532 | OSI_RET_OK_CHECK( sl_SyncObjCreate(&g_pCB->ObjPool[Idx].SyncObj, "SyncObj")); |
IanBenzMaxim | 0:33d4e66780c0 | 533 | SL_DRV_SYNC_OBJ_CLEAR(&g_pCB->ObjPool[Idx].SyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 534 | } |
IanBenzMaxim | 0:33d4e66780c0 | 535 | |
IanBenzMaxim | 0:33d4e66780c0 | 536 | g_pCB->ActivePoolIdx = MAX_CONCURRENT_ACTIONS; |
IanBenzMaxim | 0:33d4e66780c0 | 537 | g_pCB->PendingPoolIdx = MAX_CONCURRENT_ACTIONS; |
IanBenzMaxim | 0:33d4e66780c0 | 538 | |
IanBenzMaxim | 0:33d4e66780c0 | 539 | /* Flow control init */ |
IanBenzMaxim | 0:33d4e66780c0 | 540 | g_pCB->FlowContCB.TxPoolCnt = FLOW_CONT_MIN; |
IanBenzMaxim | 0:33d4e66780c0 | 541 | OSI_RET_OK_CHECK(sl_LockObjCreate(&g_pCB->FlowContCB.TxLockObj, "TxLockObj")); |
IanBenzMaxim | 0:33d4e66780c0 | 542 | OSI_RET_OK_CHECK(sl_SyncObjCreate(&g_pCB->FlowContCB.TxSyncObj, "TxSyncObj")); |
IanBenzMaxim | 0:33d4e66780c0 | 543 | |
IanBenzMaxim | 0:33d4e66780c0 | 544 | #ifndef SL_IF_TYPE_UART |
IanBenzMaxim | 0:33d4e66780c0 | 545 | gFirstCmdMode = 0; |
IanBenzMaxim | 0:33d4e66780c0 | 546 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 547 | |
IanBenzMaxim | 0:33d4e66780c0 | 548 | return SL_OS_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 549 | } |
IanBenzMaxim | 0:33d4e66780c0 | 550 | |
IanBenzMaxim | 0:33d4e66780c0 | 551 | /***************************************************************************** |
IanBenzMaxim | 0:33d4e66780c0 | 552 | _SlDrvDriverCBDeinit - De init Driver Control Block |
IanBenzMaxim | 0:33d4e66780c0 | 553 | *****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 554 | _SlReturnVal_t _SlDrvDriverCBDeinit(void) |
IanBenzMaxim | 0:33d4e66780c0 | 555 | { |
IanBenzMaxim | 0:33d4e66780c0 | 556 | _u8 Idx =0; |
IanBenzMaxim | 0:33d4e66780c0 | 557 | |
IanBenzMaxim | 0:33d4e66780c0 | 558 | /* Flow control de-init */ |
IanBenzMaxim | 0:33d4e66780c0 | 559 | g_pCB->FlowContCB.TxPoolCnt = 0; |
IanBenzMaxim | 0:33d4e66780c0 | 560 | OSI_RET_OK_CHECK(sl_LockObjDelete(&g_pCB->FlowContCB.TxLockObj)); |
IanBenzMaxim | 0:33d4e66780c0 | 561 | OSI_RET_OK_CHECK(sl_SyncObjDelete(&g_pCB->FlowContCB.TxSyncObj)); |
IanBenzMaxim | 0:33d4e66780c0 | 562 | |
IanBenzMaxim | 0:33d4e66780c0 | 563 | OSI_RET_OK_CHECK( sl_SyncObjDelete(&g_pCB->CmdSyncObj) ); |
IanBenzMaxim | 0:33d4e66780c0 | 564 | |
IanBenzMaxim | 0:33d4e66780c0 | 565 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 566 | if (g_bDeviceRestartIsRequired == 0) |
IanBenzMaxim | 0:33d4e66780c0 | 567 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 568 | { |
IanBenzMaxim | 0:33d4e66780c0 | 569 | OSI_RET_OK_CHECK( sl_LockObjDelete(&g_pCB->GlobalLockObj) ); |
IanBenzMaxim | 0:33d4e66780c0 | 570 | } |
IanBenzMaxim | 0:33d4e66780c0 | 571 | |
IanBenzMaxim | 0:33d4e66780c0 | 572 | OSI_RET_OK_CHECK( sl_LockObjDelete(&g_pCB->ProtectionLockObj) ); |
IanBenzMaxim | 0:33d4e66780c0 | 573 | |
IanBenzMaxim | 0:33d4e66780c0 | 574 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 575 | for (Idx = 0; Idx < MAX_CONCURRENT_ACTIONS; Idx++) |
IanBenzMaxim | 0:33d4e66780c0 | 576 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 577 | { |
IanBenzMaxim | 0:33d4e66780c0 | 578 | OSI_RET_OK_CHECK( sl_SyncObjDelete(&g_pCB->ObjPool[Idx].SyncObj) ); |
IanBenzMaxim | 0:33d4e66780c0 | 579 | } |
IanBenzMaxim | 0:33d4e66780c0 | 580 | |
IanBenzMaxim | 0:33d4e66780c0 | 581 | g_pCB->FreePoolIdx = 0; |
IanBenzMaxim | 0:33d4e66780c0 | 582 | g_pCB->PendingPoolIdx = MAX_CONCURRENT_ACTIONS; |
IanBenzMaxim | 0:33d4e66780c0 | 583 | g_pCB->ActivePoolIdx = MAX_CONCURRENT_ACTIONS; |
IanBenzMaxim | 0:33d4e66780c0 | 584 | |
IanBenzMaxim | 0:33d4e66780c0 | 585 | #ifdef SL_MEMORY_MGMT_DYNAMIC |
IanBenzMaxim | 0:33d4e66780c0 | 586 | sl_Free(g_pCB); |
IanBenzMaxim | 0:33d4e66780c0 | 587 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 588 | g_pCB = NULL; |
IanBenzMaxim | 0:33d4e66780c0 | 589 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 590 | |
IanBenzMaxim | 0:33d4e66780c0 | 591 | |
IanBenzMaxim | 0:33d4e66780c0 | 592 | g_pCB = NULL; |
IanBenzMaxim | 0:33d4e66780c0 | 593 | return SL_OS_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 594 | } |
IanBenzMaxim | 0:33d4e66780c0 | 595 | |
IanBenzMaxim | 0:33d4e66780c0 | 596 | /***************************************************************************** |
IanBenzMaxim | 0:33d4e66780c0 | 597 | _SlDrvRxIrqHandler - Interrupt handler |
IanBenzMaxim | 0:33d4e66780c0 | 598 | *****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 599 | _SlReturnVal_t _SlDrvRxIrqHandler(void *pValue) |
IanBenzMaxim | 0:33d4e66780c0 | 600 | { |
IanBenzMaxim | 0:33d4e66780c0 | 601 | (void)pValue; |
IanBenzMaxim | 0:33d4e66780c0 | 602 | |
IanBenzMaxim | 0:33d4e66780c0 | 603 | sl_IfMaskIntHdlr(); |
IanBenzMaxim | 0:33d4e66780c0 | 604 | |
IanBenzMaxim | 0:33d4e66780c0 | 605 | RxIrqCnt++; |
IanBenzMaxim | 0:33d4e66780c0 | 606 | |
IanBenzMaxim | 0:33d4e66780c0 | 607 | if (TRUE == g_pCB->IsCmdRespWaited) |
IanBenzMaxim | 0:33d4e66780c0 | 608 | { |
IanBenzMaxim | 0:33d4e66780c0 | 609 | OSI_RET_OK_CHECK( sl_SyncObjSignalFromIRQ(&g_pCB->CmdSyncObj) ); |
IanBenzMaxim | 0:33d4e66780c0 | 610 | } |
IanBenzMaxim | 0:33d4e66780c0 | 611 | else |
IanBenzMaxim | 0:33d4e66780c0 | 612 | { |
IanBenzMaxim | 0:33d4e66780c0 | 613 | (void)sl_Spawn((_SlSpawnEntryFunc_t)_SlDrvMsgReadSpawnCtx, NULL, SL_SPAWN_FLAG_FROM_SL_IRQ_HANDLER); |
IanBenzMaxim | 0:33d4e66780c0 | 614 | } |
IanBenzMaxim | 0:33d4e66780c0 | 615 | return SL_OS_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 616 | } |
IanBenzMaxim | 0:33d4e66780c0 | 617 | |
IanBenzMaxim | 0:33d4e66780c0 | 618 | /***************************************************************************** |
IanBenzMaxim | 0:33d4e66780c0 | 619 | _SlDrvCmdOp |
IanBenzMaxim | 0:33d4e66780c0 | 620 | *****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 621 | _SlReturnVal_t _SlDrvCmdOp( |
IanBenzMaxim | 0:33d4e66780c0 | 622 | _SlCmdCtrl_t *pCmdCtrl , |
IanBenzMaxim | 0:33d4e66780c0 | 623 | void *pTxRxDescBuff , |
IanBenzMaxim | 0:33d4e66780c0 | 624 | _SlCmdExt_t *pCmdExt) |
IanBenzMaxim | 0:33d4e66780c0 | 625 | { |
IanBenzMaxim | 0:33d4e66780c0 | 626 | _SlReturnVal_t RetVal; |
IanBenzMaxim | 0:33d4e66780c0 | 627 | |
IanBenzMaxim | 0:33d4e66780c0 | 628 | SL_DRV_LOCK_GLOBAL_LOCK_FOREVER(); |
IanBenzMaxim | 0:33d4e66780c0 | 629 | |
IanBenzMaxim | 0:33d4e66780c0 | 630 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 631 | /* In case the global was succesffully taken but error in progress |
IanBenzMaxim | 0:33d4e66780c0 | 632 | it means it has been released as part of an error handling and we should abort immediately */ |
IanBenzMaxim | 0:33d4e66780c0 | 633 | if (TRUE == g_bDeviceRestartIsRequired) |
IanBenzMaxim | 0:33d4e66780c0 | 634 | { |
IanBenzMaxim | 0:33d4e66780c0 | 635 | SL_DRV_LOCK_GLOBAL_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 636 | return SL_API_ABORTED; |
IanBenzMaxim | 0:33d4e66780c0 | 637 | } |
IanBenzMaxim | 0:33d4e66780c0 | 638 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 639 | |
IanBenzMaxim | 0:33d4e66780c0 | 640 | g_pCB->IsCmdRespWaited = TRUE; |
IanBenzMaxim | 0:33d4e66780c0 | 641 | |
IanBenzMaxim | 0:33d4e66780c0 | 642 | SL_TRACE0(DBG_MSG, MSG_312, "_SlDrvCmdOp: call _SlDrvMsgWrite"); |
IanBenzMaxim | 0:33d4e66780c0 | 643 | |
IanBenzMaxim | 0:33d4e66780c0 | 644 | |
IanBenzMaxim | 0:33d4e66780c0 | 645 | /* send the message */ |
IanBenzMaxim | 0:33d4e66780c0 | 646 | RetVal = _SlDrvMsgWrite(pCmdCtrl, pCmdExt, pTxRxDescBuff); |
IanBenzMaxim | 0:33d4e66780c0 | 647 | |
IanBenzMaxim | 0:33d4e66780c0 | 648 | if(SL_OS_RET_CODE_OK == RetVal) |
IanBenzMaxim | 0:33d4e66780c0 | 649 | { |
IanBenzMaxim | 0:33d4e66780c0 | 650 | |
IanBenzMaxim | 0:33d4e66780c0 | 651 | #ifndef SL_IF_TYPE_UART |
IanBenzMaxim | 0:33d4e66780c0 | 652 | /* Waiting for SPI to stabilize after first command */ |
IanBenzMaxim | 0:33d4e66780c0 | 653 | if( 0 == gFirstCmdMode ) |
IanBenzMaxim | 0:33d4e66780c0 | 654 | { |
IanBenzMaxim | 0:33d4e66780c0 | 655 | volatile _u32 CountVal = 0; |
IanBenzMaxim | 0:33d4e66780c0 | 656 | gFirstCmdMode = 1; |
IanBenzMaxim | 0:33d4e66780c0 | 657 | CountVal = CPU_FREQ_IN_MHZ*USEC_DELAY; |
IanBenzMaxim | 0:33d4e66780c0 | 658 | while( CountVal-- ); |
IanBenzMaxim | 0:33d4e66780c0 | 659 | } |
IanBenzMaxim | 0:33d4e66780c0 | 660 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 661 | /* wait for respond */ |
IanBenzMaxim | 0:33d4e66780c0 | 662 | RetVal = _SlDrvMsgReadCmdCtx(pCmdCtrl->Opcode); /* will free global lock */ |
IanBenzMaxim | 0:33d4e66780c0 | 663 | SL_TRACE0(DBG_MSG, MSG_314, "_SlDrvCmdOp: exited _SlDrvMsgReadCmdCtx"); |
IanBenzMaxim | 0:33d4e66780c0 | 664 | } |
IanBenzMaxim | 0:33d4e66780c0 | 665 | else |
IanBenzMaxim | 0:33d4e66780c0 | 666 | { |
IanBenzMaxim | 0:33d4e66780c0 | 667 | SL_DRV_LOCK_GLOBAL_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 668 | } |
IanBenzMaxim | 0:33d4e66780c0 | 669 | |
IanBenzMaxim | 0:33d4e66780c0 | 670 | return RetVal; |
IanBenzMaxim | 0:33d4e66780c0 | 671 | } |
IanBenzMaxim | 0:33d4e66780c0 | 672 | |
IanBenzMaxim | 0:33d4e66780c0 | 673 | |
IanBenzMaxim | 0:33d4e66780c0 | 674 | |
IanBenzMaxim | 0:33d4e66780c0 | 675 | /***************************************************************************** |
IanBenzMaxim | 0:33d4e66780c0 | 676 | _SlDrvDataReadOp |
IanBenzMaxim | 0:33d4e66780c0 | 677 | *****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 678 | _SlReturnVal_t _SlDrvDataReadOp( |
IanBenzMaxim | 0:33d4e66780c0 | 679 | _SlSd_t Sd, |
IanBenzMaxim | 0:33d4e66780c0 | 680 | _SlCmdCtrl_t *pCmdCtrl , |
IanBenzMaxim | 0:33d4e66780c0 | 681 | void *pTxRxDescBuff , |
IanBenzMaxim | 0:33d4e66780c0 | 682 | _SlCmdExt_t *pCmdExt) |
IanBenzMaxim | 0:33d4e66780c0 | 683 | { |
IanBenzMaxim | 0:33d4e66780c0 | 684 | _SlReturnVal_t RetVal; |
IanBenzMaxim | 0:33d4e66780c0 | 685 | _u8 ObjIdx = MAX_CONCURRENT_ACTIONS; |
IanBenzMaxim | 0:33d4e66780c0 | 686 | _SlArgsData_t pArgsData; |
IanBenzMaxim | 0:33d4e66780c0 | 687 | |
IanBenzMaxim | 0:33d4e66780c0 | 688 | /* Validate input arguments */ |
IanBenzMaxim | 0:33d4e66780c0 | 689 | VERIFY_PROTOCOL(NULL != pCmdExt->pRxPayload); |
IanBenzMaxim | 0:33d4e66780c0 | 690 | |
IanBenzMaxim | 0:33d4e66780c0 | 691 | /* If zero bytes is requested, return error. */ |
IanBenzMaxim | 0:33d4e66780c0 | 692 | /* This allows us not to fill remote socket's IP address in return arguments */ |
IanBenzMaxim | 0:33d4e66780c0 | 693 | VERIFY_PROTOCOL(0 != pCmdExt->RxPayloadLen); |
IanBenzMaxim | 0:33d4e66780c0 | 694 | |
IanBenzMaxim | 0:33d4e66780c0 | 695 | /* Validate socket */ |
IanBenzMaxim | 0:33d4e66780c0 | 696 | if((Sd & BSD_SOCKET_ID_MASK) >= SL_MAX_SOCKETS) |
IanBenzMaxim | 0:33d4e66780c0 | 697 | { |
IanBenzMaxim | 0:33d4e66780c0 | 698 | return SL_EBADF; |
IanBenzMaxim | 0:33d4e66780c0 | 699 | } |
IanBenzMaxim | 0:33d4e66780c0 | 700 | |
IanBenzMaxim | 0:33d4e66780c0 | 701 | /*Use Obj to issue the command, if not available try later*/ |
IanBenzMaxim | 0:33d4e66780c0 | 702 | ObjIdx = (_u8)_SlDrvWaitForPoolObj(RECV_ID, Sd & BSD_SOCKET_ID_MASK); |
IanBenzMaxim | 0:33d4e66780c0 | 703 | |
IanBenzMaxim | 0:33d4e66780c0 | 704 | if (MAX_CONCURRENT_ACTIONS == ObjIdx) |
IanBenzMaxim | 0:33d4e66780c0 | 705 | { |
IanBenzMaxim | 0:33d4e66780c0 | 706 | return SL_POOL_IS_EMPTY; |
IanBenzMaxim | 0:33d4e66780c0 | 707 | } |
IanBenzMaxim | 0:33d4e66780c0 | 708 | |
IanBenzMaxim | 0:33d4e66780c0 | 709 | SL_DRV_PROTECTION_OBJ_LOCK_FOREVER(); |
IanBenzMaxim | 0:33d4e66780c0 | 710 | |
IanBenzMaxim | 0:33d4e66780c0 | 711 | pArgsData.pData = pCmdExt->pRxPayload; |
IanBenzMaxim | 0:33d4e66780c0 | 712 | pArgsData.pArgs = (_u8 *)pTxRxDescBuff; |
IanBenzMaxim | 0:33d4e66780c0 | 713 | g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&pArgsData; |
IanBenzMaxim | 0:33d4e66780c0 | 714 | |
IanBenzMaxim | 0:33d4e66780c0 | 715 | SL_DRV_PROTECTION_OBJ_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 716 | |
IanBenzMaxim | 0:33d4e66780c0 | 717 | |
IanBenzMaxim | 0:33d4e66780c0 | 718 | /* Do Flow Control check/update for DataWrite operation */ |
IanBenzMaxim | 0:33d4e66780c0 | 719 | SL_DRV_OBJ_LOCK_FOREVER(&g_pCB->FlowContCB.TxLockObj); |
IanBenzMaxim | 0:33d4e66780c0 | 720 | |
IanBenzMaxim | 0:33d4e66780c0 | 721 | |
IanBenzMaxim | 0:33d4e66780c0 | 722 | /* Clear SyncObj for the case it was signalled before TxPoolCnt */ |
IanBenzMaxim | 0:33d4e66780c0 | 723 | /* dropped below '1' (last Data buffer was taken) */ |
IanBenzMaxim | 0:33d4e66780c0 | 724 | /* OSI_RET_OK_CHECK( sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj) ); */ |
IanBenzMaxim | 0:33d4e66780c0 | 725 | SL_DRV_SYNC_OBJ_CLEAR(&g_pCB->FlowContCB.TxSyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 726 | |
IanBenzMaxim | 0:33d4e66780c0 | 727 | if(g_pCB->FlowContCB.TxPoolCnt <= FLOW_CONT_MIN) |
IanBenzMaxim | 0:33d4e66780c0 | 728 | { |
IanBenzMaxim | 0:33d4e66780c0 | 729 | |
IanBenzMaxim | 0:33d4e66780c0 | 730 | /* If TxPoolCnt was increased by other thread at this moment, |
IanBenzMaxim | 0:33d4e66780c0 | 731 | TxSyncObj won't wait here */ |
IanBenzMaxim | 0:33d4e66780c0 | 732 | SL_DRV_SYNC_OBJ_WAIT_FOREVER(&g_pCB->FlowContCB.TxSyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 733 | |
IanBenzMaxim | 0:33d4e66780c0 | 734 | } |
IanBenzMaxim | 0:33d4e66780c0 | 735 | |
IanBenzMaxim | 0:33d4e66780c0 | 736 | SL_DRV_LOCK_GLOBAL_LOCK_FOREVER(); |
IanBenzMaxim | 0:33d4e66780c0 | 737 | |
IanBenzMaxim | 0:33d4e66780c0 | 738 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 739 | /* In case the global was succesffully taken but error in progress |
IanBenzMaxim | 0:33d4e66780c0 | 740 | it means it has been released as part of an error handling and we should abort immediately */ |
IanBenzMaxim | 0:33d4e66780c0 | 741 | if (TRUE == g_bDeviceRestartIsRequired) |
IanBenzMaxim | 0:33d4e66780c0 | 742 | { |
IanBenzMaxim | 0:33d4e66780c0 | 743 | SL_DRV_LOCK_GLOBAL_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 744 | return SL_API_ABORTED; |
IanBenzMaxim | 0:33d4e66780c0 | 745 | } |
IanBenzMaxim | 0:33d4e66780c0 | 746 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 747 | |
IanBenzMaxim | 0:33d4e66780c0 | 748 | VERIFY_PROTOCOL(g_pCB->FlowContCB.TxPoolCnt > FLOW_CONT_MIN); |
IanBenzMaxim | 0:33d4e66780c0 | 749 | g_pCB->FlowContCB.TxPoolCnt--; |
IanBenzMaxim | 0:33d4e66780c0 | 750 | |
IanBenzMaxim | 0:33d4e66780c0 | 751 | SL_DRV_OBJ_UNLOCK(&g_pCB->FlowContCB.TxLockObj); |
IanBenzMaxim | 0:33d4e66780c0 | 752 | |
IanBenzMaxim | 0:33d4e66780c0 | 753 | /* send the message */ |
IanBenzMaxim | 0:33d4e66780c0 | 754 | RetVal = _SlDrvMsgWrite(pCmdCtrl, pCmdExt, (_u8 *)pTxRxDescBuff); |
IanBenzMaxim | 0:33d4e66780c0 | 755 | |
IanBenzMaxim | 0:33d4e66780c0 | 756 | SL_DRV_LOCK_GLOBAL_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 757 | |
IanBenzMaxim | 0:33d4e66780c0 | 758 | |
IanBenzMaxim | 0:33d4e66780c0 | 759 | if(SL_OS_RET_CODE_OK == RetVal) |
IanBenzMaxim | 0:33d4e66780c0 | 760 | { |
IanBenzMaxim | 0:33d4e66780c0 | 761 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 762 | /* in case socket is non-blocking one, the async event should be received immediately */ |
IanBenzMaxim | 0:33d4e66780c0 | 763 | if( g_pCB->SocketNonBlocking & (1<<(Sd & BSD_SOCKET_ID_MASK) )) |
IanBenzMaxim | 0:33d4e66780c0 | 764 | { |
IanBenzMaxim | 0:33d4e66780c0 | 765 | SlDriverAPIWithTimeout_e api = (pCmdCtrl->Opcode == SL_OPCODE_SOCKET_RECV) ? SL_DRIVER_API_SOCKET_RECV : SL_DRIVER_API_SOCKET_RECVFROM; |
IanBenzMaxim | 0:33d4e66780c0 | 766 | |
IanBenzMaxim | 0:33d4e66780c0 | 767 | SL_DRV_SYNC_OBJ_WAIT_TIMEOUT(&g_pCB->ObjPool[ObjIdx].SyncObj, |
IanBenzMaxim | 0:33d4e66780c0 | 768 | SL_DRIVER_TIMEOUT_SHORT, |
IanBenzMaxim | 0:33d4e66780c0 | 769 | api |
IanBenzMaxim | 0:33d4e66780c0 | 770 | ); |
IanBenzMaxim | 0:33d4e66780c0 | 771 | } |
IanBenzMaxim | 0:33d4e66780c0 | 772 | else |
IanBenzMaxim | 0:33d4e66780c0 | 773 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 774 | { |
IanBenzMaxim | 0:33d4e66780c0 | 775 | /* Wait for response message. Will be signaled by _SlDrvMsgRead. */ |
IanBenzMaxim | 0:33d4e66780c0 | 776 | SL_DRV_SYNC_OBJ_WAIT_FOREVER(&g_pCB->ObjPool[ObjIdx].SyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 777 | } |
IanBenzMaxim | 0:33d4e66780c0 | 778 | |
IanBenzMaxim | 0:33d4e66780c0 | 779 | } |
IanBenzMaxim | 0:33d4e66780c0 | 780 | |
IanBenzMaxim | 0:33d4e66780c0 | 781 | _SlDrvReleasePoolObj(ObjIdx); |
IanBenzMaxim | 0:33d4e66780c0 | 782 | return RetVal; |
IanBenzMaxim | 0:33d4e66780c0 | 783 | } |
IanBenzMaxim | 0:33d4e66780c0 | 784 | |
IanBenzMaxim | 0:33d4e66780c0 | 785 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 786 | /* _SlDrvDataWriteOp */ |
IanBenzMaxim | 0:33d4e66780c0 | 787 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 788 | _SlReturnVal_t _SlDrvDataWriteOp( |
IanBenzMaxim | 0:33d4e66780c0 | 789 | _SlSd_t Sd, |
IanBenzMaxim | 0:33d4e66780c0 | 790 | _SlCmdCtrl_t *pCmdCtrl , |
IanBenzMaxim | 0:33d4e66780c0 | 791 | void *pTxRxDescBuff , |
IanBenzMaxim | 0:33d4e66780c0 | 792 | _SlCmdExt_t *pCmdExt) |
IanBenzMaxim | 0:33d4e66780c0 | 793 | { |
IanBenzMaxim | 0:33d4e66780c0 | 794 | _SlReturnVal_t RetVal = SL_EAGAIN; /* initiated as SL_EAGAIN for the non blocking mode */ |
IanBenzMaxim | 0:33d4e66780c0 | 795 | while( 1 ) |
IanBenzMaxim | 0:33d4e66780c0 | 796 | { |
IanBenzMaxim | 0:33d4e66780c0 | 797 | /* Do Flow Control check/update for DataWrite operation */ |
IanBenzMaxim | 0:33d4e66780c0 | 798 | SL_DRV_OBJ_LOCK_FOREVER(&g_pCB->FlowContCB.TxLockObj); |
IanBenzMaxim | 0:33d4e66780c0 | 799 | |
IanBenzMaxim | 0:33d4e66780c0 | 800 | /* Clear SyncObj for the case it was signalled before TxPoolCnt */ |
IanBenzMaxim | 0:33d4e66780c0 | 801 | /* dropped below '1' (last Data buffer was taken) */ |
IanBenzMaxim | 0:33d4e66780c0 | 802 | /* OSI_RET_OK_CHECK( sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj) ); */ |
IanBenzMaxim | 0:33d4e66780c0 | 803 | SL_DRV_SYNC_OBJ_CLEAR(&g_pCB->FlowContCB.TxSyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 804 | |
IanBenzMaxim | 0:33d4e66780c0 | 805 | /* we have indication that the last send has failed - socket is no longer valid for operations */ |
IanBenzMaxim | 0:33d4e66780c0 | 806 | if(g_pCB->SocketTXFailure & (1<<(Sd & BSD_SOCKET_ID_MASK))) |
IanBenzMaxim | 0:33d4e66780c0 | 807 | { |
IanBenzMaxim | 0:33d4e66780c0 | 808 | SL_DRV_OBJ_UNLOCK(&g_pCB->FlowContCB.TxLockObj); |
IanBenzMaxim | 0:33d4e66780c0 | 809 | return SL_SOC_ERROR; |
IanBenzMaxim | 0:33d4e66780c0 | 810 | } |
IanBenzMaxim | 0:33d4e66780c0 | 811 | if(g_pCB->FlowContCB.TxPoolCnt <= FLOW_CONT_MIN + 1) |
IanBenzMaxim | 0:33d4e66780c0 | 812 | { |
IanBenzMaxim | 0:33d4e66780c0 | 813 | /* we have indication that this socket is set as blocking and we try to */ |
IanBenzMaxim | 0:33d4e66780c0 | 814 | /* unblock it - return an error */ |
IanBenzMaxim | 0:33d4e66780c0 | 815 | if( g_pCB->SocketNonBlocking & (1<<(Sd & BSD_SOCKET_ID_MASK) )) |
IanBenzMaxim | 0:33d4e66780c0 | 816 | { |
IanBenzMaxim | 0:33d4e66780c0 | 817 | SL_DRV_OBJ_UNLOCK(&g_pCB->FlowContCB.TxLockObj); |
IanBenzMaxim | 0:33d4e66780c0 | 818 | return RetVal; |
IanBenzMaxim | 0:33d4e66780c0 | 819 | } |
IanBenzMaxim | 0:33d4e66780c0 | 820 | /* If TxPoolCnt was increased by other thread at this moment, */ |
IanBenzMaxim | 0:33d4e66780c0 | 821 | /* TxSyncObj won't wait here */ |
IanBenzMaxim | 0:33d4e66780c0 | 822 | |
IanBenzMaxim | 0:33d4e66780c0 | 823 | SL_DRV_SYNC_OBJ_WAIT_FOREVER(&g_pCB->FlowContCB.TxSyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 824 | } |
IanBenzMaxim | 0:33d4e66780c0 | 825 | if(g_pCB->FlowContCB.TxPoolCnt > FLOW_CONT_MIN + 1 ) |
IanBenzMaxim | 0:33d4e66780c0 | 826 | { |
IanBenzMaxim | 0:33d4e66780c0 | 827 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 828 | } |
IanBenzMaxim | 0:33d4e66780c0 | 829 | else |
IanBenzMaxim | 0:33d4e66780c0 | 830 | { |
IanBenzMaxim | 0:33d4e66780c0 | 831 | SL_DRV_OBJ_UNLOCK(&g_pCB->FlowContCB.TxLockObj); |
IanBenzMaxim | 0:33d4e66780c0 | 832 | } |
IanBenzMaxim | 0:33d4e66780c0 | 833 | } |
IanBenzMaxim | 0:33d4e66780c0 | 834 | |
IanBenzMaxim | 0:33d4e66780c0 | 835 | SL_DRV_LOCK_GLOBAL_LOCK_FOREVER(); |
IanBenzMaxim | 0:33d4e66780c0 | 836 | |
IanBenzMaxim | 0:33d4e66780c0 | 837 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 838 | /* In case the global was succesffully taken but error in progress |
IanBenzMaxim | 0:33d4e66780c0 | 839 | it means it has been released as part of an error handling and we should abort immediately */ |
IanBenzMaxim | 0:33d4e66780c0 | 840 | if (TRUE == g_bDeviceRestartIsRequired) |
IanBenzMaxim | 0:33d4e66780c0 | 841 | { |
IanBenzMaxim | 0:33d4e66780c0 | 842 | SL_DRV_LOCK_GLOBAL_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 843 | return SL_API_ABORTED; |
IanBenzMaxim | 0:33d4e66780c0 | 844 | } |
IanBenzMaxim | 0:33d4e66780c0 | 845 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 846 | |
IanBenzMaxim | 0:33d4e66780c0 | 847 | |
IanBenzMaxim | 0:33d4e66780c0 | 848 | VERIFY_PROTOCOL(g_pCB->FlowContCB.TxPoolCnt > FLOW_CONT_MIN + 1 ); |
IanBenzMaxim | 0:33d4e66780c0 | 849 | g_pCB->FlowContCB.TxPoolCnt--; |
IanBenzMaxim | 0:33d4e66780c0 | 850 | |
IanBenzMaxim | 0:33d4e66780c0 | 851 | SL_DRV_OBJ_UNLOCK(&g_pCB->FlowContCB.TxLockObj); |
IanBenzMaxim | 0:33d4e66780c0 | 852 | |
IanBenzMaxim | 0:33d4e66780c0 | 853 | /* send the message */ |
IanBenzMaxim | 0:33d4e66780c0 | 854 | RetVal = _SlDrvMsgWrite(pCmdCtrl, pCmdExt, pTxRxDescBuff); |
IanBenzMaxim | 0:33d4e66780c0 | 855 | |
IanBenzMaxim | 0:33d4e66780c0 | 856 | SL_DRV_LOCK_GLOBAL_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 857 | |
IanBenzMaxim | 0:33d4e66780c0 | 858 | return RetVal; |
IanBenzMaxim | 0:33d4e66780c0 | 859 | } |
IanBenzMaxim | 0:33d4e66780c0 | 860 | |
IanBenzMaxim | 0:33d4e66780c0 | 861 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 862 | /* _SlDrvMsgWrite */ |
IanBenzMaxim | 0:33d4e66780c0 | 863 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 864 | static _SlReturnVal_t _SlDrvMsgWrite(_SlCmdCtrl_t *pCmdCtrl,_SlCmdExt_t *pCmdExt, _u8 *pTxRxDescBuff) |
IanBenzMaxim | 0:33d4e66780c0 | 865 | { |
IanBenzMaxim | 0:33d4e66780c0 | 866 | _u8 sendRxPayload = FALSE; |
IanBenzMaxim | 0:33d4e66780c0 | 867 | VERIFY_PROTOCOL(NULL != pCmdCtrl); |
IanBenzMaxim | 0:33d4e66780c0 | 868 | |
IanBenzMaxim | 0:33d4e66780c0 | 869 | g_pCB->FunctionParams.pCmdCtrl = pCmdCtrl; |
IanBenzMaxim | 0:33d4e66780c0 | 870 | g_pCB->FunctionParams.pTxRxDescBuff = pTxRxDescBuff; |
IanBenzMaxim | 0:33d4e66780c0 | 871 | g_pCB->FunctionParams.pCmdExt = pCmdExt; |
IanBenzMaxim | 0:33d4e66780c0 | 872 | |
IanBenzMaxim | 0:33d4e66780c0 | 873 | g_pCB->TempProtocolHeader.Opcode = pCmdCtrl->Opcode; |
IanBenzMaxim | 0:33d4e66780c0 | 874 | g_pCB->TempProtocolHeader.Len = (_u16)(_SL_PROTOCOL_CALC_LEN(pCmdCtrl, pCmdExt)); |
IanBenzMaxim | 0:33d4e66780c0 | 875 | |
IanBenzMaxim | 0:33d4e66780c0 | 876 | if (pCmdExt && pCmdExt->RxPayloadLen < 0 ) |
IanBenzMaxim | 0:33d4e66780c0 | 877 | { |
IanBenzMaxim | 0:33d4e66780c0 | 878 | pCmdExt->RxPayloadLen = pCmdExt->RxPayloadLen * (-1); /* change sign */ |
IanBenzMaxim | 0:33d4e66780c0 | 879 | sendRxPayload = TRUE; |
IanBenzMaxim | 0:33d4e66780c0 | 880 | g_pCB->TempProtocolHeader.Len = g_pCB->TempProtocolHeader.Len + pCmdExt->RxPayloadLen; |
IanBenzMaxim | 0:33d4e66780c0 | 881 | } |
IanBenzMaxim | 0:33d4e66780c0 | 882 | |
IanBenzMaxim | 0:33d4e66780c0 | 883 | #ifdef SL_START_WRITE_STAT |
IanBenzMaxim | 0:33d4e66780c0 | 884 | sl_IfStartWriteSequence(g_pCB->FD); |
IanBenzMaxim | 0:33d4e66780c0 | 885 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 886 | |
IanBenzMaxim | 0:33d4e66780c0 | 887 | #ifdef SL_IF_TYPE_UART |
IanBenzMaxim | 0:33d4e66780c0 | 888 | /* Write long sync pattern */ |
IanBenzMaxim | 0:33d4e66780c0 | 889 | NWP_IF_WRITE_CHECK(g_pCB->FD, (_u8 *)&g_H2NSyncPattern.Long, 2*SYNC_PATTERN_LEN); |
IanBenzMaxim | 0:33d4e66780c0 | 890 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 891 | /* Write short sync pattern */ |
IanBenzMaxim | 0:33d4e66780c0 | 892 | NWP_IF_WRITE_CHECK(g_pCB->FD, (_u8 *)&g_H2NSyncPattern.Short, SYNC_PATTERN_LEN); |
IanBenzMaxim | 0:33d4e66780c0 | 893 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 894 | |
IanBenzMaxim | 0:33d4e66780c0 | 895 | /* Header */ |
IanBenzMaxim | 0:33d4e66780c0 | 896 | NWP_IF_WRITE_CHECK(g_pCB->FD, (_u8 *)&g_pCB->TempProtocolHeader, _SL_CMD_HDR_SIZE); |
IanBenzMaxim | 0:33d4e66780c0 | 897 | |
IanBenzMaxim | 0:33d4e66780c0 | 898 | /* Descriptors */ |
IanBenzMaxim | 0:33d4e66780c0 | 899 | if (pTxRxDescBuff && pCmdCtrl->TxDescLen > 0) |
IanBenzMaxim | 0:33d4e66780c0 | 900 | { |
IanBenzMaxim | 0:33d4e66780c0 | 901 | NWP_IF_WRITE_CHECK(g_pCB->FD, pTxRxDescBuff, |
IanBenzMaxim | 0:33d4e66780c0 | 902 | _SL_PROTOCOL_ALIGN_SIZE(pCmdCtrl->TxDescLen)); |
IanBenzMaxim | 0:33d4e66780c0 | 903 | } |
IanBenzMaxim | 0:33d4e66780c0 | 904 | |
IanBenzMaxim | 0:33d4e66780c0 | 905 | /* A special mode where Rx payload and Rx length are used as Tx as well */ |
IanBenzMaxim | 0:33d4e66780c0 | 906 | /* This mode requires no Rx payload on the response and currently used by fs_Close and sl_Send on */ |
IanBenzMaxim | 0:33d4e66780c0 | 907 | /* transceiver mode */ |
IanBenzMaxim | 0:33d4e66780c0 | 908 | if (sendRxPayload == TRUE ) |
IanBenzMaxim | 0:33d4e66780c0 | 909 | { |
IanBenzMaxim | 0:33d4e66780c0 | 910 | NWP_IF_WRITE_CHECK(g_pCB->FD, pCmdExt->pRxPayload, |
IanBenzMaxim | 0:33d4e66780c0 | 911 | _SL_PROTOCOL_ALIGN_SIZE(pCmdExt->RxPayloadLen)); |
IanBenzMaxim | 0:33d4e66780c0 | 912 | } |
IanBenzMaxim | 0:33d4e66780c0 | 913 | |
IanBenzMaxim | 0:33d4e66780c0 | 914 | /* Payload */ |
IanBenzMaxim | 0:33d4e66780c0 | 915 | if (pCmdExt && pCmdExt->TxPayloadLen > 0) |
IanBenzMaxim | 0:33d4e66780c0 | 916 | { |
IanBenzMaxim | 0:33d4e66780c0 | 917 | /* If the message has payload, it is mandatory that the message's arguments are protocol aligned. */ |
IanBenzMaxim | 0:33d4e66780c0 | 918 | /* Otherwise the aligning of arguments will create a gap between arguments and payload. */ |
IanBenzMaxim | 0:33d4e66780c0 | 919 | VERIFY_PROTOCOL(_SL_IS_PROTOCOL_ALIGNED_SIZE(pCmdCtrl->TxDescLen)); |
IanBenzMaxim | 0:33d4e66780c0 | 920 | |
IanBenzMaxim | 0:33d4e66780c0 | 921 | NWP_IF_WRITE_CHECK(g_pCB->FD, pCmdExt->pTxPayload, |
IanBenzMaxim | 0:33d4e66780c0 | 922 | _SL_PROTOCOL_ALIGN_SIZE(pCmdExt->TxPayloadLen)); |
IanBenzMaxim | 0:33d4e66780c0 | 923 | } |
IanBenzMaxim | 0:33d4e66780c0 | 924 | |
IanBenzMaxim | 0:33d4e66780c0 | 925 | |
IanBenzMaxim | 0:33d4e66780c0 | 926 | _SL_DBG_CNT_INC(MsgCnt.Write); |
IanBenzMaxim | 0:33d4e66780c0 | 927 | |
IanBenzMaxim | 0:33d4e66780c0 | 928 | #ifdef SL_START_WRITE_STAT |
IanBenzMaxim | 0:33d4e66780c0 | 929 | sl_IfEndWriteSequence(g_pCB->FD); |
IanBenzMaxim | 0:33d4e66780c0 | 930 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 931 | |
IanBenzMaxim | 0:33d4e66780c0 | 932 | return SL_OS_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 933 | } |
IanBenzMaxim | 0:33d4e66780c0 | 934 | |
IanBenzMaxim | 0:33d4e66780c0 | 935 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 936 | /* _SlDrvMsgRead */ |
IanBenzMaxim | 0:33d4e66780c0 | 937 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 938 | static _SlReturnVal_t _SlDrvMsgRead(void) |
IanBenzMaxim | 0:33d4e66780c0 | 939 | { |
IanBenzMaxim | 0:33d4e66780c0 | 940 | /* alignment for small memory models */ |
IanBenzMaxim | 0:33d4e66780c0 | 941 | union |
IanBenzMaxim | 0:33d4e66780c0 | 942 | { |
IanBenzMaxim | 0:33d4e66780c0 | 943 | _u8 TempBuf[_SL_RESP_HDR_SIZE]; |
IanBenzMaxim | 0:33d4e66780c0 | 944 | _u32 DummyBuf[2]; |
IanBenzMaxim | 0:33d4e66780c0 | 945 | } uBuf; |
IanBenzMaxim | 0:33d4e66780c0 | 946 | _u8 TailBuffer[4]; |
IanBenzMaxim | 0:33d4e66780c0 | 947 | _u16 LengthToCopy; |
IanBenzMaxim | 0:33d4e66780c0 | 948 | _u16 AlignedLengthRecv; |
IanBenzMaxim | 0:33d4e66780c0 | 949 | _u8 AlignSize; |
IanBenzMaxim | 0:33d4e66780c0 | 950 | _u8 *pAsyncBuf = NULL; |
IanBenzMaxim | 0:33d4e66780c0 | 951 | _u16 OpCode; |
IanBenzMaxim | 0:33d4e66780c0 | 952 | _u16 RespPayloadLen; |
IanBenzMaxim | 0:33d4e66780c0 | 953 | _u8 sd = SL_MAX_SOCKETS; |
IanBenzMaxim | 0:33d4e66780c0 | 954 | _SlRxMsgClass_e RxMsgClass; |
IanBenzMaxim | 0:33d4e66780c0 | 955 | |
IanBenzMaxim | 0:33d4e66780c0 | 956 | |
IanBenzMaxim | 0:33d4e66780c0 | 957 | /* save params in global CB */ |
IanBenzMaxim | 0:33d4e66780c0 | 958 | g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL; |
IanBenzMaxim | 0:33d4e66780c0 | 959 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler= NULL; |
IanBenzMaxim | 0:33d4e66780c0 | 960 | |
IanBenzMaxim | 0:33d4e66780c0 | 961 | #ifdef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 962 | VERIFY_RET_OK(_SlDrvRxHdrRead((_u8*)(uBuf.TempBuf), &AlignSize)); |
IanBenzMaxim | 0:33d4e66780c0 | 963 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 964 | if (_SlDrvRxHdrRead((_u8*)(uBuf.TempBuf), &AlignSize) == SL_API_ABORTED) |
IanBenzMaxim | 0:33d4e66780c0 | 965 | { |
IanBenzMaxim | 0:33d4e66780c0 | 966 | SL_DRV_LOCK_GLOBAL_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 967 | |
IanBenzMaxim | 0:33d4e66780c0 | 968 | _SlDriverHandleError(SL_DEVICE_DRIVER_TIMEOUT_SYNC_PATTERN, 0, 0); |
IanBenzMaxim | 0:33d4e66780c0 | 969 | return SL_API_ABORTED; |
IanBenzMaxim | 0:33d4e66780c0 | 970 | } |
IanBenzMaxim | 0:33d4e66780c0 | 971 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 972 | OpCode = OPCODE(uBuf.TempBuf); |
IanBenzMaxim | 0:33d4e66780c0 | 973 | RespPayloadLen = (_u16)(RSP_PAYLOAD_LEN(uBuf.TempBuf)); |
IanBenzMaxim | 0:33d4e66780c0 | 974 | |
IanBenzMaxim | 0:33d4e66780c0 | 975 | |
IanBenzMaxim | 0:33d4e66780c0 | 976 | /* 'Init Compelete' message bears no valid FlowControl info */ |
IanBenzMaxim | 0:33d4e66780c0 | 977 | if(SL_OPCODE_DEVICE_INITCOMPLETE != OpCode) |
IanBenzMaxim | 0:33d4e66780c0 | 978 | { |
IanBenzMaxim | 0:33d4e66780c0 | 979 | g_pCB->FlowContCB.TxPoolCnt = ((_SlResponseHeader_t *)uBuf.TempBuf)->TxPoolCnt; |
IanBenzMaxim | 0:33d4e66780c0 | 980 | g_pCB->SocketNonBlocking = ((_SlResponseHeader_t *)uBuf.TempBuf)->SocketNonBlocking; |
IanBenzMaxim | 0:33d4e66780c0 | 981 | g_pCB->SocketTXFailure = ((_SlResponseHeader_t *)uBuf.TempBuf)->SocketTXFailure; |
IanBenzMaxim | 0:33d4e66780c0 | 982 | |
IanBenzMaxim | 0:33d4e66780c0 | 983 | if(g_pCB->FlowContCB.TxPoolCnt > FLOW_CONT_MIN) |
IanBenzMaxim | 0:33d4e66780c0 | 984 | { |
IanBenzMaxim | 0:33d4e66780c0 | 985 | SL_DRV_SYNC_OBJ_SIGNAL(&g_pCB->FlowContCB.TxSyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 986 | } |
IanBenzMaxim | 0:33d4e66780c0 | 987 | } |
IanBenzMaxim | 0:33d4e66780c0 | 988 | |
IanBenzMaxim | 0:33d4e66780c0 | 989 | /* Find the RX messaage class and set its async event handler */ |
IanBenzMaxim | 0:33d4e66780c0 | 990 | _SlDrvClassifyRxMsg(OpCode); |
IanBenzMaxim | 0:33d4e66780c0 | 991 | |
IanBenzMaxim | 0:33d4e66780c0 | 992 | RxMsgClass = g_pCB->FunctionParams.AsyncExt.RxMsgClass; |
IanBenzMaxim | 0:33d4e66780c0 | 993 | |
IanBenzMaxim | 0:33d4e66780c0 | 994 | |
IanBenzMaxim | 0:33d4e66780c0 | 995 | switch(RxMsgClass) |
IanBenzMaxim | 0:33d4e66780c0 | 996 | { |
IanBenzMaxim | 0:33d4e66780c0 | 997 | case ASYNC_EVT_CLASS: |
IanBenzMaxim | 0:33d4e66780c0 | 998 | |
IanBenzMaxim | 0:33d4e66780c0 | 999 | VERIFY_PROTOCOL(NULL == pAsyncBuf); |
IanBenzMaxim | 0:33d4e66780c0 | 1000 | |
IanBenzMaxim | 0:33d4e66780c0 | 1001 | #ifdef SL_MEMORY_MGMT_DYNAMIC |
IanBenzMaxim | 0:33d4e66780c0 | 1002 | g_pCB->FunctionParams.AsyncExt.pAsyncBuf = (_u8*)sl_Malloc(SL_ASYNC_MAX_MSG_LEN); |
IanBenzMaxim | 0:33d4e66780c0 | 1003 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 1004 | g_pCB->FunctionParams.AsyncExt.pAsyncBuf = g_StatMem.AsyncRespBuf; |
IanBenzMaxim | 0:33d4e66780c0 | 1005 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1006 | /* set the local pointer to the allocated one */ |
IanBenzMaxim | 0:33d4e66780c0 | 1007 | pAsyncBuf = g_pCB->FunctionParams.AsyncExt.pAsyncBuf; |
IanBenzMaxim | 0:33d4e66780c0 | 1008 | |
IanBenzMaxim | 0:33d4e66780c0 | 1009 | /* clear the async buffer */ |
IanBenzMaxim | 0:33d4e66780c0 | 1010 | _SlDrvMemZero(pAsyncBuf, (_u16)SL_ASYNC_MAX_MSG_LEN); |
IanBenzMaxim | 0:33d4e66780c0 | 1011 | |
IanBenzMaxim | 0:33d4e66780c0 | 1012 | MALLOC_OK_CHECK(pAsyncBuf); |
IanBenzMaxim | 0:33d4e66780c0 | 1013 | |
IanBenzMaxim | 0:33d4e66780c0 | 1014 | sl_Memcpy(pAsyncBuf, uBuf.TempBuf, _SL_RESP_HDR_SIZE); |
IanBenzMaxim | 0:33d4e66780c0 | 1015 | if (_SL_PROTOCOL_ALIGN_SIZE(RespPayloadLen) <= SL_ASYNC_MAX_PAYLOAD_LEN) |
IanBenzMaxim | 0:33d4e66780c0 | 1016 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1017 | AlignedLengthRecv = (_u16)_SL_PROTOCOL_ALIGN_SIZE(RespPayloadLen); |
IanBenzMaxim | 0:33d4e66780c0 | 1018 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1019 | else |
IanBenzMaxim | 0:33d4e66780c0 | 1020 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1021 | AlignedLengthRecv = (_u16)_SL_PROTOCOL_ALIGN_SIZE(SL_ASYNC_MAX_PAYLOAD_LEN); |
IanBenzMaxim | 0:33d4e66780c0 | 1022 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1023 | if (RespPayloadLen > 0) |
IanBenzMaxim | 0:33d4e66780c0 | 1024 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1025 | NWP_IF_READ_CHECK(g_pCB->FD, |
IanBenzMaxim | 0:33d4e66780c0 | 1026 | pAsyncBuf + _SL_RESP_HDR_SIZE, |
IanBenzMaxim | 0:33d4e66780c0 | 1027 | AlignedLengthRecv); |
IanBenzMaxim | 0:33d4e66780c0 | 1028 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1029 | /* In case ASYNC RX buffer length is smaller then the received data length, dump the rest */ |
IanBenzMaxim | 0:33d4e66780c0 | 1030 | if ((_SL_PROTOCOL_ALIGN_SIZE(RespPayloadLen) > SL_ASYNC_MAX_PAYLOAD_LEN)) |
IanBenzMaxim | 0:33d4e66780c0 | 1031 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1032 | AlignedLengthRecv = (_u16)(_SL_PROTOCOL_ALIGN_SIZE(RespPayloadLen) - SL_ASYNC_MAX_PAYLOAD_LEN); |
IanBenzMaxim | 0:33d4e66780c0 | 1033 | while (AlignedLengthRecv > 0) |
IanBenzMaxim | 0:33d4e66780c0 | 1034 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1035 | NWP_IF_READ_CHECK(g_pCB->FD,TailBuffer,4); |
IanBenzMaxim | 0:33d4e66780c0 | 1036 | AlignedLengthRecv = AlignedLengthRecv - 4; |
IanBenzMaxim | 0:33d4e66780c0 | 1037 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1038 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1039 | |
IanBenzMaxim | 0:33d4e66780c0 | 1040 | SL_DRV_PROTECTION_OBJ_LOCK_FOREVER(); |
IanBenzMaxim | 0:33d4e66780c0 | 1041 | |
IanBenzMaxim | 0:33d4e66780c0 | 1042 | if ( |
IanBenzMaxim | 0:33d4e66780c0 | 1043 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1044 | (SL_OPCODE_SOCKET_ACCEPTASYNCRESPONSE == OpCode) || |
IanBenzMaxim | 0:33d4e66780c0 | 1045 | (SL_OPCODE_SOCKET_ACCEPTASYNCRESPONSE_V6 == OpCode) || |
IanBenzMaxim | 0:33d4e66780c0 | 1046 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1047 | (SL_OPCODE_SOCKET_CONNECTASYNCRESPONSE == OpCode) |
IanBenzMaxim | 0:33d4e66780c0 | 1048 | ) |
IanBenzMaxim | 0:33d4e66780c0 | 1049 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1050 | /* go over the active list if exist to find obj waiting for this Async event */ |
IanBenzMaxim | 0:33d4e66780c0 | 1051 | sd = ((((_SocketResponse_t *)(pAsyncBuf + _SL_RESP_HDR_SIZE))->sd) & BSD_SOCKET_ID_MASK); |
IanBenzMaxim | 0:33d4e66780c0 | 1052 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1053 | |
IanBenzMaxim | 0:33d4e66780c0 | 1054 | (void)_SlFindAndSetActiveObj(OpCode, sd); |
IanBenzMaxim | 0:33d4e66780c0 | 1055 | |
IanBenzMaxim | 0:33d4e66780c0 | 1056 | SL_DRV_PROTECTION_OBJ_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 1057 | |
IanBenzMaxim | 0:33d4e66780c0 | 1058 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 1059 | case RECV_RESP_CLASS: |
IanBenzMaxim | 0:33d4e66780c0 | 1060 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1061 | _u8 ExpArgSize; /* Expected size of Recv/Recvfrom arguments */ |
IanBenzMaxim | 0:33d4e66780c0 | 1062 | |
IanBenzMaxim | 0:33d4e66780c0 | 1063 | switch(OpCode) |
IanBenzMaxim | 0:33d4e66780c0 | 1064 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1065 | case SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE: |
IanBenzMaxim | 0:33d4e66780c0 | 1066 | ExpArgSize = (_u8)RECVFROM_IPV4_ARGS_SIZE; |
IanBenzMaxim | 0:33d4e66780c0 | 1067 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 1068 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1069 | case SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE_V6: |
IanBenzMaxim | 0:33d4e66780c0 | 1070 | ExpArgSize = (_u8)RECVFROM_IPV6_ARGS_SIZE; |
IanBenzMaxim | 0:33d4e66780c0 | 1071 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 1072 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1073 | default: |
IanBenzMaxim | 0:33d4e66780c0 | 1074 | /* SL_OPCODE_SOCKET_RECVASYNCRESPONSE: */ |
IanBenzMaxim | 0:33d4e66780c0 | 1075 | ExpArgSize = (_u8)RECV_ARGS_SIZE; |
IanBenzMaxim | 0:33d4e66780c0 | 1076 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1077 | |
IanBenzMaxim | 0:33d4e66780c0 | 1078 | /* Read first 4 bytes of Recv/Recvfrom response to get SocketId and actual */ |
IanBenzMaxim | 0:33d4e66780c0 | 1079 | /* response data length */ |
IanBenzMaxim | 0:33d4e66780c0 | 1080 | NWP_IF_READ_CHECK(g_pCB->FD, &uBuf.TempBuf[4], RECV_ARGS_SIZE); |
IanBenzMaxim | 0:33d4e66780c0 | 1081 | |
IanBenzMaxim | 0:33d4e66780c0 | 1082 | /* Validate Socket ID and Received Length value. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1083 | VERIFY_PROTOCOL((SD(&uBuf.TempBuf[4])& BSD_SOCKET_ID_MASK) < SL_MAX_SOCKETS); |
IanBenzMaxim | 0:33d4e66780c0 | 1084 | |
IanBenzMaxim | 0:33d4e66780c0 | 1085 | SL_DRV_PROTECTION_OBJ_LOCK_FOREVER(); |
IanBenzMaxim | 0:33d4e66780c0 | 1086 | |
IanBenzMaxim | 0:33d4e66780c0 | 1087 | /* go over the active list if exist to find obj waiting for this Async event */ |
IanBenzMaxim | 0:33d4e66780c0 | 1088 | VERIFY_RET_OK(_SlFindAndSetActiveObj(OpCode,SD(&uBuf.TempBuf[4]) & BSD_SOCKET_ID_MASK)); |
IanBenzMaxim | 0:33d4e66780c0 | 1089 | |
IanBenzMaxim | 0:33d4e66780c0 | 1090 | /* Verify data is waited on this socket. The pArgs should have been set by _SlDrvDataReadOp(). */ |
IanBenzMaxim | 0:33d4e66780c0 | 1091 | VERIFY_SOCKET_CB(NULL != ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pData))->pArgs); |
IanBenzMaxim | 0:33d4e66780c0 | 1092 | |
IanBenzMaxim | 0:33d4e66780c0 | 1093 | sl_Memcpy( ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pArgs, &uBuf.TempBuf[4], RECV_ARGS_SIZE); |
IanBenzMaxim | 0:33d4e66780c0 | 1094 | |
IanBenzMaxim | 0:33d4e66780c0 | 1095 | if(ExpArgSize > (_u8)RECV_ARGS_SIZE) |
IanBenzMaxim | 0:33d4e66780c0 | 1096 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1097 | NWP_IF_READ_CHECK(g_pCB->FD, |
IanBenzMaxim | 0:33d4e66780c0 | 1098 | ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pArgs + RECV_ARGS_SIZE, |
IanBenzMaxim | 0:33d4e66780c0 | 1099 | ExpArgSize - RECV_ARGS_SIZE); |
IanBenzMaxim | 0:33d4e66780c0 | 1100 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1101 | |
IanBenzMaxim | 0:33d4e66780c0 | 1102 | /* Here g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pData contains requested(expected) Recv/Recvfrom DataSize. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1103 | /* Overwrite requested DataSize with actual one. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1104 | /* If error is received, this information will be read from arguments. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1105 | if(ACT_DATA_SIZE(&uBuf.TempBuf[4]) > 0) |
IanBenzMaxim | 0:33d4e66780c0 | 1106 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1107 | VERIFY_SOCKET_CB(NULL != ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pData); |
IanBenzMaxim | 0:33d4e66780c0 | 1108 | |
IanBenzMaxim | 0:33d4e66780c0 | 1109 | /* Read 4 bytes aligned from interface */ |
IanBenzMaxim | 0:33d4e66780c0 | 1110 | /* therefore check the requested length and read only */ |
IanBenzMaxim | 0:33d4e66780c0 | 1111 | /* 4 bytes aligned data. The rest unaligned (if any) will be read */ |
IanBenzMaxim | 0:33d4e66780c0 | 1112 | /* and copied to a TailBuffer */ |
IanBenzMaxim | 0:33d4e66780c0 | 1113 | LengthToCopy = (_u16)(ACT_DATA_SIZE(&uBuf.TempBuf[4]) & (3)); |
IanBenzMaxim | 0:33d4e66780c0 | 1114 | AlignedLengthRecv = (_u16)(ACT_DATA_SIZE(&uBuf.TempBuf[4]) & (~3)); |
IanBenzMaxim | 0:33d4e66780c0 | 1115 | if( AlignedLengthRecv >= 4) |
IanBenzMaxim | 0:33d4e66780c0 | 1116 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1117 | NWP_IF_READ_CHECK(g_pCB->FD,((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pData,AlignedLengthRecv ); |
IanBenzMaxim | 0:33d4e66780c0 | 1118 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1119 | /* copy the unaligned part, if any */ |
IanBenzMaxim | 0:33d4e66780c0 | 1120 | if( LengthToCopy > 0) |
IanBenzMaxim | 0:33d4e66780c0 | 1121 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1122 | NWP_IF_READ_CHECK(g_pCB->FD,TailBuffer,4); |
IanBenzMaxim | 0:33d4e66780c0 | 1123 | /* copy TailBuffer unaligned part (1/2/3 bytes) */ |
IanBenzMaxim | 0:33d4e66780c0 | 1124 | sl_Memcpy(((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pData + AlignedLengthRecv,TailBuffer,LengthToCopy); |
IanBenzMaxim | 0:33d4e66780c0 | 1125 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1126 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1127 | SL_DRV_SYNC_OBJ_SIGNAL(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 1128 | SL_DRV_PROTECTION_OBJ_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 1129 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1130 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 1131 | |
IanBenzMaxim | 0:33d4e66780c0 | 1132 | case CMD_RESP_CLASS: |
IanBenzMaxim | 0:33d4e66780c0 | 1133 | |
IanBenzMaxim | 0:33d4e66780c0 | 1134 | /* Some commands pass a maximum arguments size. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1135 | /* In this case Driver will send extra dummy patterns to NWP if */ |
IanBenzMaxim | 0:33d4e66780c0 | 1136 | /* the response message is smaller than maximum. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1137 | /* When RxDescLen is not exact, using RxPayloadLen is forbidden! */ |
IanBenzMaxim | 0:33d4e66780c0 | 1138 | /* If such case cannot be avoided - parse message here to detect */ |
IanBenzMaxim | 0:33d4e66780c0 | 1139 | /* arguments/payload border. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1140 | NWP_IF_READ_CHECK(g_pCB->FD, |
IanBenzMaxim | 0:33d4e66780c0 | 1141 | g_pCB->FunctionParams.pTxRxDescBuff, |
IanBenzMaxim | 0:33d4e66780c0 | 1142 | _SL_PROTOCOL_ALIGN_SIZE(g_pCB->FunctionParams.pCmdCtrl->RxDescLen)); |
IanBenzMaxim | 0:33d4e66780c0 | 1143 | |
IanBenzMaxim | 0:33d4e66780c0 | 1144 | if((NULL != g_pCB->FunctionParams.pCmdExt) && (0 != g_pCB->FunctionParams.pCmdExt->RxPayloadLen)) |
IanBenzMaxim | 0:33d4e66780c0 | 1145 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1146 | /* Actual size of command's response payload: <msg_payload_len> - <rsp_args_len> */ |
IanBenzMaxim | 0:33d4e66780c0 | 1147 | _i16 ActDataSize = (_i16)(RSP_PAYLOAD_LEN(uBuf.TempBuf) - g_pCB->FunctionParams.pCmdCtrl->RxDescLen); |
IanBenzMaxim | 0:33d4e66780c0 | 1148 | |
IanBenzMaxim | 0:33d4e66780c0 | 1149 | g_pCB->FunctionParams.pCmdExt->ActualRxPayloadLen = ActDataSize; |
IanBenzMaxim | 0:33d4e66780c0 | 1150 | |
IanBenzMaxim | 0:33d4e66780c0 | 1151 | /* Check that the space prepared by user for the response data is sufficient. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1152 | if(ActDataSize <= 0) |
IanBenzMaxim | 0:33d4e66780c0 | 1153 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1154 | g_pCB->FunctionParams.pCmdExt->RxPayloadLen = 0; |
IanBenzMaxim | 0:33d4e66780c0 | 1155 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1156 | else |
IanBenzMaxim | 0:33d4e66780c0 | 1157 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1158 | /* In case the user supplied Rx buffer length which is smaller then the received data length, copy according to user length */ |
IanBenzMaxim | 0:33d4e66780c0 | 1159 | if (ActDataSize > g_pCB->FunctionParams.pCmdExt->RxPayloadLen) |
IanBenzMaxim | 0:33d4e66780c0 | 1160 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1161 | LengthToCopy = (_u16)(g_pCB->FunctionParams.pCmdExt->RxPayloadLen & (3)); |
IanBenzMaxim | 0:33d4e66780c0 | 1162 | AlignedLengthRecv = (_u16)(g_pCB->FunctionParams.pCmdExt->RxPayloadLen & (~3)); |
IanBenzMaxim | 0:33d4e66780c0 | 1163 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1164 | else |
IanBenzMaxim | 0:33d4e66780c0 | 1165 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1166 | LengthToCopy = (_u16)(ActDataSize & (3)); |
IanBenzMaxim | 0:33d4e66780c0 | 1167 | AlignedLengthRecv = (_u16)(ActDataSize & (~3)); |
IanBenzMaxim | 0:33d4e66780c0 | 1168 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1169 | /* Read 4 bytes aligned from interface */ |
IanBenzMaxim | 0:33d4e66780c0 | 1170 | /* therefore check the requested length and read only */ |
IanBenzMaxim | 0:33d4e66780c0 | 1171 | /* 4 bytes aligned data. The rest unaligned (if any) will be read */ |
IanBenzMaxim | 0:33d4e66780c0 | 1172 | /* and copied to a TailBuffer */ |
IanBenzMaxim | 0:33d4e66780c0 | 1173 | |
IanBenzMaxim | 0:33d4e66780c0 | 1174 | if( AlignedLengthRecv >= 4) |
IanBenzMaxim | 0:33d4e66780c0 | 1175 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1176 | NWP_IF_READ_CHECK(g_pCB->FD, |
IanBenzMaxim | 0:33d4e66780c0 | 1177 | g_pCB->FunctionParams.pCmdExt->pRxPayload, |
IanBenzMaxim | 0:33d4e66780c0 | 1178 | AlignedLengthRecv ); |
IanBenzMaxim | 0:33d4e66780c0 | 1179 | |
IanBenzMaxim | 0:33d4e66780c0 | 1180 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1181 | /* copy the unaligned part, if any */ |
IanBenzMaxim | 0:33d4e66780c0 | 1182 | if( LengthToCopy > 0) |
IanBenzMaxim | 0:33d4e66780c0 | 1183 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1184 | NWP_IF_READ_CHECK(g_pCB->FD,TailBuffer,4); |
IanBenzMaxim | 0:33d4e66780c0 | 1185 | /* copy TailBuffer unaligned part (1/2/3 bytes) */ |
IanBenzMaxim | 0:33d4e66780c0 | 1186 | sl_Memcpy(g_pCB->FunctionParams.pCmdExt->pRxPayload + AlignedLengthRecv, |
IanBenzMaxim | 0:33d4e66780c0 | 1187 | TailBuffer, |
IanBenzMaxim | 0:33d4e66780c0 | 1188 | LengthToCopy); |
IanBenzMaxim | 0:33d4e66780c0 | 1189 | ActDataSize = ActDataSize-4; |
IanBenzMaxim | 0:33d4e66780c0 | 1190 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1191 | /* In case the user supplied Rx buffer length which is smaller then the received data length, dump the rest */ |
IanBenzMaxim | 0:33d4e66780c0 | 1192 | if (ActDataSize > g_pCB->FunctionParams.pCmdExt->RxPayloadLen) |
IanBenzMaxim | 0:33d4e66780c0 | 1193 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1194 | /* calculate the rest of the data size to dump */ |
IanBenzMaxim | 0:33d4e66780c0 | 1195 | AlignedLengthRecv = (_u16)( (ActDataSize + 3 - g_pCB->FunctionParams.pCmdExt->RxPayloadLen) & (~3) ); |
IanBenzMaxim | 0:33d4e66780c0 | 1196 | while( AlignedLengthRecv > 0) |
IanBenzMaxim | 0:33d4e66780c0 | 1197 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1198 | NWP_IF_READ_CHECK(g_pCB->FD,TailBuffer, 4 ); |
IanBenzMaxim | 0:33d4e66780c0 | 1199 | AlignedLengthRecv = AlignedLengthRecv - 4; |
IanBenzMaxim | 0:33d4e66780c0 | 1200 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1201 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1202 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1203 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1204 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 1205 | |
IanBenzMaxim | 0:33d4e66780c0 | 1206 | default: |
IanBenzMaxim | 0:33d4e66780c0 | 1207 | /* DUMMY_MSG_CLASS: Flow control message has no payload. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1208 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 1209 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1210 | |
IanBenzMaxim | 0:33d4e66780c0 | 1211 | if(AlignSize > 0) |
IanBenzMaxim | 0:33d4e66780c0 | 1212 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1213 | NWP_IF_READ_CHECK(g_pCB->FD, uBuf.TempBuf, AlignSize); |
IanBenzMaxim | 0:33d4e66780c0 | 1214 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1215 | |
IanBenzMaxim | 0:33d4e66780c0 | 1216 | _SL_DBG_CNT_INC(MsgCnt.Read); |
IanBenzMaxim | 0:33d4e66780c0 | 1217 | |
IanBenzMaxim | 0:33d4e66780c0 | 1218 | /* Unmask Interrupt call */ |
IanBenzMaxim | 0:33d4e66780c0 | 1219 | sl_IfUnMaskIntHdlr(); |
IanBenzMaxim | 0:33d4e66780c0 | 1220 | |
IanBenzMaxim | 0:33d4e66780c0 | 1221 | return SL_OS_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 1222 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1223 | |
IanBenzMaxim | 0:33d4e66780c0 | 1224 | |
IanBenzMaxim | 0:33d4e66780c0 | 1225 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1226 | /* _SlAsyncEventGenericHandler */ |
IanBenzMaxim | 0:33d4e66780c0 | 1227 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1228 | static void _SlAsyncEventGenericHandler(_u8 bInCmdContext) |
IanBenzMaxim | 0:33d4e66780c0 | 1229 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1230 | _u32 SlAsyncEvent = 0; |
IanBenzMaxim | 0:33d4e66780c0 | 1231 | _u8 OpcodeFound = FALSE; |
IanBenzMaxim | 0:33d4e66780c0 | 1232 | _u8 i; |
IanBenzMaxim | 0:33d4e66780c0 | 1233 | |
IanBenzMaxim | 0:33d4e66780c0 | 1234 | _u32* pEventLocation = NULL; /* This pointer will override the async buffer with the translated event type */ |
IanBenzMaxim | 0:33d4e66780c0 | 1235 | _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)g_pCB->FunctionParams.AsyncExt.pAsyncBuf; |
IanBenzMaxim | 0:33d4e66780c0 | 1236 | |
IanBenzMaxim | 0:33d4e66780c0 | 1237 | |
IanBenzMaxim | 0:33d4e66780c0 | 1238 | /* if no async event registered nothing to do..*/ |
IanBenzMaxim | 0:33d4e66780c0 | 1239 | if (g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler == NULL) |
IanBenzMaxim | 0:33d4e66780c0 | 1240 | return; |
IanBenzMaxim | 0:33d4e66780c0 | 1241 | |
IanBenzMaxim | 0:33d4e66780c0 | 1242 | /* Iterate through all the opcode in the table */ |
IanBenzMaxim | 0:33d4e66780c0 | 1243 | for (i=0; i< (_u8)(sizeof(OpcodeTranslateTable) / sizeof(OpcodeKeyVal_t)); i++) |
IanBenzMaxim | 0:33d4e66780c0 | 1244 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1245 | if (OpcodeTranslateTable[i].opcode == pHdr->GenHeader.Opcode) |
IanBenzMaxim | 0:33d4e66780c0 | 1246 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1247 | SlAsyncEvent = OpcodeTranslateTable[i].event; |
IanBenzMaxim | 0:33d4e66780c0 | 1248 | OpcodeFound = TRUE; |
IanBenzMaxim | 0:33d4e66780c0 | 1249 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 1250 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1251 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1252 | |
IanBenzMaxim | 0:33d4e66780c0 | 1253 | /* No Async event found in the table */ |
IanBenzMaxim | 0:33d4e66780c0 | 1254 | if (OpcodeFound == FALSE) |
IanBenzMaxim | 0:33d4e66780c0 | 1255 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1256 | if ((pHdr->GenHeader.Opcode & SL_OPCODE_SILO_MASK) == SL_OPCODE_SILO_DEVICE) |
IanBenzMaxim | 0:33d4e66780c0 | 1257 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1258 | DeviceEventInfo_t deviceEvent; |
IanBenzMaxim | 0:33d4e66780c0 | 1259 | |
IanBenzMaxim | 0:33d4e66780c0 | 1260 | deviceEvent.pAsyncMsgBuff = g_pCB->FunctionParams.AsyncExt.pAsyncBuf; |
IanBenzMaxim | 0:33d4e66780c0 | 1261 | deviceEvent.bInCmdContext = bInCmdContext; |
IanBenzMaxim | 0:33d4e66780c0 | 1262 | |
IanBenzMaxim | 0:33d4e66780c0 | 1263 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&deviceEvent); |
IanBenzMaxim | 0:33d4e66780c0 | 1264 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1265 | else |
IanBenzMaxim | 0:33d4e66780c0 | 1266 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1267 | /* This case handles all the async events handlers of the DEVICE & SOCK Silos which are handled internally. |
IanBenzMaxim | 0:33d4e66780c0 | 1268 | For these cases we send the async even buffer as is */ |
IanBenzMaxim | 0:33d4e66780c0 | 1269 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
IanBenzMaxim | 0:33d4e66780c0 | 1270 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1271 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1272 | else |
IanBenzMaxim | 0:33d4e66780c0 | 1273 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1274 | /* calculate the event type location to be filled in the async buffer */ |
IanBenzMaxim | 0:33d4e66780c0 | 1275 | pEventLocation = (_u32*)(g_pCB->FunctionParams.AsyncExt.pAsyncBuf + sizeof (_SlResponseHeader_t) - sizeof(SlAsyncEvent) ); |
IanBenzMaxim | 0:33d4e66780c0 | 1276 | |
IanBenzMaxim | 0:33d4e66780c0 | 1277 | /* Override the async buffer (before the data starts ) with our event type */ |
IanBenzMaxim | 0:33d4e66780c0 | 1278 | *pEventLocation = SlAsyncEvent; |
IanBenzMaxim | 0:33d4e66780c0 | 1279 | |
IanBenzMaxim | 0:33d4e66780c0 | 1280 | /* call the event handler registered by the user with our async buffer which now holds |
IanBenzMaxim | 0:33d4e66780c0 | 1281 | the User's event type and its related data */ |
IanBenzMaxim | 0:33d4e66780c0 | 1282 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(pEventLocation); |
IanBenzMaxim | 0:33d4e66780c0 | 1283 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1284 | |
IanBenzMaxim | 0:33d4e66780c0 | 1285 | |
IanBenzMaxim | 0:33d4e66780c0 | 1286 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1287 | |
IanBenzMaxim | 0:33d4e66780c0 | 1288 | |
IanBenzMaxim | 0:33d4e66780c0 | 1289 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1290 | /* _SlDrvMsgReadCmdCtx */ |
IanBenzMaxim | 0:33d4e66780c0 | 1291 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1292 | static _SlReturnVal_t _SlDrvMsgReadCmdCtx(_u16 cmdOpcode) |
IanBenzMaxim | 0:33d4e66780c0 | 1293 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1294 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1295 | _u16 CmdCmpltTimeout; |
IanBenzMaxim | 0:33d4e66780c0 | 1296 | |
IanBenzMaxim | 0:33d4e66780c0 | 1297 | /* For any FS command, the timeout will be the long one as the commnad response holds the full response data */ |
IanBenzMaxim | 0:33d4e66780c0 | 1298 | CmdCmpltTimeout = (SL_OPCODE_SILO_NVMEM & cmdOpcode)? (_u16)(SL_DRIVER_TIMEOUT_LONG) : (_u16)SL_DRIVER_TIMEOUT_SHORT; |
IanBenzMaxim | 0:33d4e66780c0 | 1299 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1300 | |
IanBenzMaxim | 0:33d4e66780c0 | 1301 | /* after command response is received and isCmdRespWaited */ |
IanBenzMaxim | 0:33d4e66780c0 | 1302 | /* flag is set FALSE, it is necessary to read out all */ |
IanBenzMaxim | 0:33d4e66780c0 | 1303 | /* Async messages in Commands context, because ssiDma_IsrHandleSignalFromSlave */ |
IanBenzMaxim | 0:33d4e66780c0 | 1304 | /* could have dispatched some Async messages to g_NwpIf.CmdSyncObj */ |
IanBenzMaxim | 0:33d4e66780c0 | 1305 | /* after command response but before this response has been processed */ |
IanBenzMaxim | 0:33d4e66780c0 | 1306 | /* by spi_singleRead and isCmdRespWaited was set FALSE. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1307 | while (TRUE == g_pCB->IsCmdRespWaited) |
IanBenzMaxim | 0:33d4e66780c0 | 1308 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1309 | if(_SL_PENDING_RX_MSG(g_pCB)) |
IanBenzMaxim | 0:33d4e66780c0 | 1310 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1311 | #ifdef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1312 | VERIFY_RET_OK(_SlDrvMsgRead()); |
IanBenzMaxim | 0:33d4e66780c0 | 1313 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 1314 | if (_SlDrvMsgRead() != SL_OS_RET_CODE_OK) |
IanBenzMaxim | 0:33d4e66780c0 | 1315 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1316 | SL_DRV_LOCK_GLOBAL_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 1317 | return SL_API_ABORTED; |
IanBenzMaxim | 0:33d4e66780c0 | 1318 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1319 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1320 | g_pCB->RxDoneCnt++; |
IanBenzMaxim | 0:33d4e66780c0 | 1321 | |
IanBenzMaxim | 0:33d4e66780c0 | 1322 | if (CMD_RESP_CLASS == g_pCB->FunctionParams.AsyncExt.RxMsgClass) |
IanBenzMaxim | 0:33d4e66780c0 | 1323 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1324 | g_pCB->IsCmdRespWaited = FALSE; |
IanBenzMaxim | 0:33d4e66780c0 | 1325 | |
IanBenzMaxim | 0:33d4e66780c0 | 1326 | /* In case CmdResp has been read without waiting on CmdSyncObj - that */ |
IanBenzMaxim | 0:33d4e66780c0 | 1327 | /* Sync object. That to prevent old signal to be processed. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1328 | SL_DRV_SYNC_OBJ_CLEAR(&g_pCB->CmdSyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 1329 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1330 | else if (ASYNC_EVT_CLASS == g_pCB->FunctionParams.AsyncExt.RxMsgClass) |
IanBenzMaxim | 0:33d4e66780c0 | 1331 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1332 | /* If Async event has been read in CmdResp context, check whether */ |
IanBenzMaxim | 0:33d4e66780c0 | 1333 | /* there is a handler for this event. If there is, spawn specific */ |
IanBenzMaxim | 0:33d4e66780c0 | 1334 | /* handler. Otherwise free the event's buffer. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1335 | /* This way there will be no "dry shots" from CmdResp context to */ |
IanBenzMaxim | 0:33d4e66780c0 | 1336 | /* temporary context, i.e less waste of CPU and faster buffer */ |
IanBenzMaxim | 0:33d4e66780c0 | 1337 | /* release. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1338 | _SlAsyncEventGenericHandler(TRUE); |
IanBenzMaxim | 0:33d4e66780c0 | 1339 | |
IanBenzMaxim | 0:33d4e66780c0 | 1340 | |
IanBenzMaxim | 0:33d4e66780c0 | 1341 | #ifdef SL_MEMORY_MGMT_DYNAMIC |
IanBenzMaxim | 0:33d4e66780c0 | 1342 | sl_Free(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
IanBenzMaxim | 0:33d4e66780c0 | 1343 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 1344 | g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL; |
IanBenzMaxim | 0:33d4e66780c0 | 1345 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1346 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1347 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1348 | else |
IanBenzMaxim | 0:33d4e66780c0 | 1349 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1350 | #ifdef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1351 | /* CmdSyncObj will be signaled by IRQ */ |
IanBenzMaxim | 0:33d4e66780c0 | 1352 | _SlDrvSyncObjWaitForever(&g_pCB->CmdSyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 1353 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 1354 | |
IanBenzMaxim | 0:33d4e66780c0 | 1355 | |
IanBenzMaxim | 0:33d4e66780c0 | 1356 | if (sl_SyncObjWait(&g_pCB->CmdSyncObj, CmdCmpltTimeout)) |
IanBenzMaxim | 0:33d4e66780c0 | 1357 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1358 | SL_DRV_LOCK_GLOBAL_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 1359 | _SlDriverHandleError(SL_DEVICE_DRIVER_TIMEOUT_CMD_COMPLETE, cmdOpcode, CmdCmpltTimeout); |
IanBenzMaxim | 0:33d4e66780c0 | 1360 | return SL_API_ABORTED; |
IanBenzMaxim | 0:33d4e66780c0 | 1361 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1362 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1363 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1364 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1365 | |
IanBenzMaxim | 0:33d4e66780c0 | 1366 | /* If there are more pending Rx Msgs after CmdResp is received, */ |
IanBenzMaxim | 0:33d4e66780c0 | 1367 | /* that means that these are Async, Dummy or Read Data Msgs. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1368 | /* Spawn _SlDrvMsgReadSpawnCtx to trigger reading these messages from */ |
IanBenzMaxim | 0:33d4e66780c0 | 1369 | /* Temporary context. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1370 | /* sl_Spawn is activated, using a different context */ |
IanBenzMaxim | 0:33d4e66780c0 | 1371 | |
IanBenzMaxim | 0:33d4e66780c0 | 1372 | SL_DRV_LOCK_GLOBAL_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 1373 | |
IanBenzMaxim | 0:33d4e66780c0 | 1374 | if(_SL_PENDING_RX_MSG(g_pCB)) |
IanBenzMaxim | 0:33d4e66780c0 | 1375 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1376 | (void)sl_Spawn((_SlSpawnEntryFunc_t)_SlDrvMsgReadSpawnCtx, NULL, 0); |
IanBenzMaxim | 0:33d4e66780c0 | 1377 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1378 | |
IanBenzMaxim | 0:33d4e66780c0 | 1379 | return SL_OS_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 1380 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1381 | |
IanBenzMaxim | 0:33d4e66780c0 | 1382 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1383 | /* _SlDrvMsgReadSpawnCtx */ |
IanBenzMaxim | 0:33d4e66780c0 | 1384 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1385 | _SlReturnVal_t _SlDrvMsgReadSpawnCtx(void *pValue) |
IanBenzMaxim | 0:33d4e66780c0 | 1386 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1387 | #ifdef SL_POLLING_MODE_USED |
IanBenzMaxim | 0:33d4e66780c0 | 1388 | _i16 retCode = OSI_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 1389 | /* for polling based systems */ |
IanBenzMaxim | 0:33d4e66780c0 | 1390 | do |
IanBenzMaxim | 0:33d4e66780c0 | 1391 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1392 | retCode = sl_LockObjLock(&g_pCB->GlobalLockObj, 0); |
IanBenzMaxim | 0:33d4e66780c0 | 1393 | if ( OSI_OK != retCode ) |
IanBenzMaxim | 0:33d4e66780c0 | 1394 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1395 | if (TRUE == g_pCB->IsCmdRespWaited) |
IanBenzMaxim | 0:33d4e66780c0 | 1396 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1397 | SL_DRV_SYNC_OBJ_SIGNAL(&g_pCB->CmdSyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 1398 | return SL_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 1399 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1400 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1401 | |
IanBenzMaxim | 0:33d4e66780c0 | 1402 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1403 | while (OSI_OK != retCode); |
IanBenzMaxim | 0:33d4e66780c0 | 1404 | |
IanBenzMaxim | 0:33d4e66780c0 | 1405 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 1406 | SL_DRV_LOCK_GLOBAL_LOCK_FOREVER(); |
IanBenzMaxim | 0:33d4e66780c0 | 1407 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1408 | |
IanBenzMaxim | 0:33d4e66780c0 | 1409 | /* pValue paramater is currently not in use */ |
IanBenzMaxim | 0:33d4e66780c0 | 1410 | (void)pValue; |
IanBenzMaxim | 0:33d4e66780c0 | 1411 | |
IanBenzMaxim | 0:33d4e66780c0 | 1412 | /* Messages might have been read by CmdResp context. Therefore after */ |
IanBenzMaxim | 0:33d4e66780c0 | 1413 | /* getting LockObj, check again where the Pending Rx Msg is still present. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1414 | if(FALSE == (_SL_PENDING_RX_MSG(g_pCB))) |
IanBenzMaxim | 0:33d4e66780c0 | 1415 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1416 | SL_DRV_LOCK_GLOBAL_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 1417 | |
IanBenzMaxim | 0:33d4e66780c0 | 1418 | return SL_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 1419 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1420 | |
IanBenzMaxim | 0:33d4e66780c0 | 1421 | #ifdef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1422 | VERIFY_RET_OK(_SlDrvMsgRead()); |
IanBenzMaxim | 0:33d4e66780c0 | 1423 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 1424 | if (_SlDrvMsgRead() != SL_OS_RET_CODE_OK) |
IanBenzMaxim | 0:33d4e66780c0 | 1425 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1426 | SL_DRV_LOCK_GLOBAL_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 1427 | return SL_API_ABORTED; |
IanBenzMaxim | 0:33d4e66780c0 | 1428 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1429 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1430 | |
IanBenzMaxim | 0:33d4e66780c0 | 1431 | g_pCB->RxDoneCnt++; |
IanBenzMaxim | 0:33d4e66780c0 | 1432 | |
IanBenzMaxim | 0:33d4e66780c0 | 1433 | switch(g_pCB->FunctionParams.AsyncExt.RxMsgClass) |
IanBenzMaxim | 0:33d4e66780c0 | 1434 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1435 | case ASYNC_EVT_CLASS: |
IanBenzMaxim | 0:33d4e66780c0 | 1436 | /* If got here and protected by LockObj a message is waiting */ |
IanBenzMaxim | 0:33d4e66780c0 | 1437 | /* to be read */ |
IanBenzMaxim | 0:33d4e66780c0 | 1438 | VERIFY_PROTOCOL(NULL != g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
IanBenzMaxim | 0:33d4e66780c0 | 1439 | |
IanBenzMaxim | 0:33d4e66780c0 | 1440 | _SlAsyncEventGenericHandler(FALSE); |
IanBenzMaxim | 0:33d4e66780c0 | 1441 | |
IanBenzMaxim | 0:33d4e66780c0 | 1442 | #ifdef SL_MEMORY_MGMT_DYNAMIC |
IanBenzMaxim | 0:33d4e66780c0 | 1443 | sl_Free(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
IanBenzMaxim | 0:33d4e66780c0 | 1444 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 1445 | g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL; |
IanBenzMaxim | 0:33d4e66780c0 | 1446 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1447 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 1448 | case DUMMY_MSG_CLASS: |
IanBenzMaxim | 0:33d4e66780c0 | 1449 | case RECV_RESP_CLASS: |
IanBenzMaxim | 0:33d4e66780c0 | 1450 | /* These types are legal in this context. Do nothing */ |
IanBenzMaxim | 0:33d4e66780c0 | 1451 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 1452 | case CMD_RESP_CLASS: |
IanBenzMaxim | 0:33d4e66780c0 | 1453 | /* Command response is illegal in this context. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1454 | /* No 'break' here: Assert! */ |
IanBenzMaxim | 0:33d4e66780c0 | 1455 | default: |
IanBenzMaxim | 0:33d4e66780c0 | 1456 | VERIFY_PROTOCOL(0); |
IanBenzMaxim | 0:33d4e66780c0 | 1457 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1458 | |
IanBenzMaxim | 0:33d4e66780c0 | 1459 | SL_DRV_LOCK_GLOBAL_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 1460 | |
IanBenzMaxim | 0:33d4e66780c0 | 1461 | return(SL_RET_CODE_OK); |
IanBenzMaxim | 0:33d4e66780c0 | 1462 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1463 | |
IanBenzMaxim | 0:33d4e66780c0 | 1464 | |
IanBenzMaxim | 0:33d4e66780c0 | 1465 | |
IanBenzMaxim | 0:33d4e66780c0 | 1466 | /* |
IanBenzMaxim | 0:33d4e66780c0 | 1467 | |
IanBenzMaxim | 0:33d4e66780c0 | 1468 | #define SL_OPCODE_SILO_DEVICE ( 0x0 << SL_OPCODE_SILO_OFFSET ) |
IanBenzMaxim | 0:33d4e66780c0 | 1469 | #define SL_OPCODE_SILO_WLAN ( 0x1 << SL_OPCODE_SILO_OFFSET ) |
IanBenzMaxim | 0:33d4e66780c0 | 1470 | #define SL_OPCODE_SILO_SOCKET ( 0x2 << SL_OPCODE_SILO_OFFSET ) |
IanBenzMaxim | 0:33d4e66780c0 | 1471 | #define SL_OPCODE_SILO_NETAPP ( 0x3 << SL_OPCODE_SILO_OFFSET ) |
IanBenzMaxim | 0:33d4e66780c0 | 1472 | #define SL_OPCODE_SILO_NVMEM ( 0x4 << SL_OPCODE_SILO_OFFSET ) |
IanBenzMaxim | 0:33d4e66780c0 | 1473 | #define SL_OPCODE_SILO_NETCFG ( 0x5 << SL_OPCODE_SILO_OFFSET ) |
IanBenzMaxim | 0:33d4e66780c0 | 1474 | |
IanBenzMaxim | 0:33d4e66780c0 | 1475 | |
IanBenzMaxim | 0:33d4e66780c0 | 1476 | */ |
IanBenzMaxim | 0:33d4e66780c0 | 1477 | |
IanBenzMaxim | 0:33d4e66780c0 | 1478 | /* The Lookup table below holds the event handlers to be called according to the incoming |
IanBenzMaxim | 0:33d4e66780c0 | 1479 | RX message SILO type */ |
IanBenzMaxim | 0:33d4e66780c0 | 1480 | static const _SlSpawnEntryFunc_t RxMsgClassLUT[] = { |
IanBenzMaxim | 0:33d4e66780c0 | 1481 | (_SlSpawnEntryFunc_t)_SlDrvDeviceEventHandler, /* SL_OPCODE_SILO_DEVICE */ |
IanBenzMaxim | 0:33d4e66780c0 | 1482 | #if defined(sl_WlanEvtHdlr) || defined(EXT_LIB_REGISTERED_WLAN_EVENTS) |
IanBenzMaxim | 0:33d4e66780c0 | 1483 | (_SlSpawnEntryFunc_t)_SlDrvHandleWlanEvents, /* SL_OPCODE_SILO_WLAN */ |
IanBenzMaxim | 0:33d4e66780c0 | 1484 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 1485 | NULL, |
IanBenzMaxim | 0:33d4e66780c0 | 1486 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1487 | #if defined (sl_SockEvtHdlr) || defined(EXT_LIB_REGISTERED_SOCK_EVENTS) |
IanBenzMaxim | 0:33d4e66780c0 | 1488 | (_SlSpawnEntryFunc_t)_SlDrvHandleSockEvents, /* SL_OPCODE_SILO_SOCKET */ |
IanBenzMaxim | 0:33d4e66780c0 | 1489 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 1490 | NULL, |
IanBenzMaxim | 0:33d4e66780c0 | 1491 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1492 | |
IanBenzMaxim | 0:33d4e66780c0 | 1493 | #if defined(sl_NetAppEvtHdlr) || defined(EXT_LIB_REGISTERED_NETAPP_EVENTS) |
IanBenzMaxim | 0:33d4e66780c0 | 1494 | (_SlSpawnEntryFunc_t)_SlDrvHandleNetAppEvents, /* SL_OPCODE_SILO_NETAPP */ |
IanBenzMaxim | 0:33d4e66780c0 | 1495 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 1496 | NULL, |
IanBenzMaxim | 0:33d4e66780c0 | 1497 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1498 | NULL, /* SL_OPCODE_SILO_NVMEM */ |
IanBenzMaxim | 0:33d4e66780c0 | 1499 | NULL, /* SL_OPCODE_SILO_NETCFG */ |
IanBenzMaxim | 0:33d4e66780c0 | 1500 | NULL, |
IanBenzMaxim | 0:33d4e66780c0 | 1501 | NULL |
IanBenzMaxim | 0:33d4e66780c0 | 1502 | }; |
IanBenzMaxim | 0:33d4e66780c0 | 1503 | |
IanBenzMaxim | 0:33d4e66780c0 | 1504 | |
IanBenzMaxim | 0:33d4e66780c0 | 1505 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1506 | /* _SlDrvClassifyRxMsg */ |
IanBenzMaxim | 0:33d4e66780c0 | 1507 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1508 | static _SlReturnVal_t _SlDrvClassifyRxMsg( |
IanBenzMaxim | 0:33d4e66780c0 | 1509 | _SlOpcode_t Opcode) |
IanBenzMaxim | 0:33d4e66780c0 | 1510 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1511 | _SlSpawnEntryFunc_t AsyncEvtHandler = NULL; |
IanBenzMaxim | 0:33d4e66780c0 | 1512 | _SlRxMsgClass_e RxMsgClass = CMD_RESP_CLASS; |
IanBenzMaxim | 0:33d4e66780c0 | 1513 | _u8 Silo; |
IanBenzMaxim | 0:33d4e66780c0 | 1514 | |
IanBenzMaxim | 0:33d4e66780c0 | 1515 | |
IanBenzMaxim | 0:33d4e66780c0 | 1516 | if (0 == (SL_OPCODE_SYNC & Opcode)) |
IanBenzMaxim | 0:33d4e66780c0 | 1517 | { /* Async event has received */ |
IanBenzMaxim | 0:33d4e66780c0 | 1518 | |
IanBenzMaxim | 0:33d4e66780c0 | 1519 | if (SL_OPCODE_DEVICE_DEVICEASYNCDUMMY == Opcode) |
IanBenzMaxim | 0:33d4e66780c0 | 1520 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1521 | RxMsgClass = DUMMY_MSG_CLASS; |
IanBenzMaxim | 0:33d4e66780c0 | 1522 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1523 | else if ( (SL_OPCODE_SOCKET_RECVASYNCRESPONSE == Opcode) || (SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE == Opcode) |
IanBenzMaxim | 0:33d4e66780c0 | 1524 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1525 | || (SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE_V6 == Opcode) |
IanBenzMaxim | 0:33d4e66780c0 | 1526 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1527 | ) |
IanBenzMaxim | 0:33d4e66780c0 | 1528 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1529 | RxMsgClass = RECV_RESP_CLASS; |
IanBenzMaxim | 0:33d4e66780c0 | 1530 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1531 | else |
IanBenzMaxim | 0:33d4e66780c0 | 1532 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1533 | /* This is Async Event class message */ |
IanBenzMaxim | 0:33d4e66780c0 | 1534 | RxMsgClass = ASYNC_EVT_CLASS; |
IanBenzMaxim | 0:33d4e66780c0 | 1535 | |
IanBenzMaxim | 0:33d4e66780c0 | 1536 | /* Despite the fact that 4 bits are allocated in the SILO field, we actually have only 6 SILOs |
IanBenzMaxim | 0:33d4e66780c0 | 1537 | So we can use the 8 options of SILO in look up table */ |
IanBenzMaxim | 0:33d4e66780c0 | 1538 | Silo = (_u8)((Opcode >> SL_OPCODE_SILO_OFFSET) & 0x7); |
IanBenzMaxim | 0:33d4e66780c0 | 1539 | |
IanBenzMaxim | 0:33d4e66780c0 | 1540 | VERIFY_PROTOCOL(Silo < (_u8)(sizeof(RxMsgClassLUT)/sizeof(_SlSpawnEntryFunc_t))); |
IanBenzMaxim | 0:33d4e66780c0 | 1541 | |
IanBenzMaxim | 0:33d4e66780c0 | 1542 | /* Set the async event hander according to the LUT */ |
IanBenzMaxim | 0:33d4e66780c0 | 1543 | AsyncEvtHandler = RxMsgClassLUT[Silo]; |
IanBenzMaxim | 0:33d4e66780c0 | 1544 | |
IanBenzMaxim | 0:33d4e66780c0 | 1545 | if ((SL_OPCODE_NETAPP_HTTPGETTOKENVALUE == Opcode) || (SL_OPCODE_NETAPP_HTTPPOSTTOKENVALUE == Opcode)) |
IanBenzMaxim | 0:33d4e66780c0 | 1546 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1547 | AsyncEvtHandler = _SlDrvNetAppEventHandler; |
IanBenzMaxim | 0:33d4e66780c0 | 1548 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1549 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1550 | else if (SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE == Opcode) |
IanBenzMaxim | 0:33d4e66780c0 | 1551 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1552 | AsyncEvtHandler = (_SlSpawnEntryFunc_t)_sl_HandleAsync_PingResponse; |
IanBenzMaxim | 0:33d4e66780c0 | 1553 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1554 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1555 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1556 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1557 | |
IanBenzMaxim | 0:33d4e66780c0 | 1558 | g_pCB->FunctionParams.AsyncExt.RxMsgClass = RxMsgClass; |
IanBenzMaxim | 0:33d4e66780c0 | 1559 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = AsyncEvtHandler; |
IanBenzMaxim | 0:33d4e66780c0 | 1560 | |
IanBenzMaxim | 0:33d4e66780c0 | 1561 | |
IanBenzMaxim | 0:33d4e66780c0 | 1562 | return SL_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 1563 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1564 | |
IanBenzMaxim | 0:33d4e66780c0 | 1565 | |
IanBenzMaxim | 0:33d4e66780c0 | 1566 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1567 | /* _SlDrvRxHdrRead */ |
IanBenzMaxim | 0:33d4e66780c0 | 1568 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1569 | static _SlReturnVal_t _SlDrvRxHdrRead(_u8 *pBuf, _u8 *pAlignSize) |
IanBenzMaxim | 0:33d4e66780c0 | 1570 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1571 | _u32 SyncCnt = 0; |
IanBenzMaxim | 0:33d4e66780c0 | 1572 | _u8 ShiftIdx; |
IanBenzMaxim | 0:33d4e66780c0 | 1573 | _u8 TimeoutState = TIMEOUT_STATE_INIT_VAL; |
IanBenzMaxim | 0:33d4e66780c0 | 1574 | _u8 SearchSync = TRUE; |
IanBenzMaxim | 0:33d4e66780c0 | 1575 | |
IanBenzMaxim | 0:33d4e66780c0 | 1576 | |
IanBenzMaxim | 0:33d4e66780c0 | 1577 | #if (!defined (SL_TINY_EXT)) && (defined(sl_GetTimestamp)) |
IanBenzMaxim | 0:33d4e66780c0 | 1578 | _SlTimeoutParams_t TimeoutInfo={0}; |
IanBenzMaxim | 0:33d4e66780c0 | 1579 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1580 | |
IanBenzMaxim | 0:33d4e66780c0 | 1581 | #ifndef SL_IF_TYPE_UART |
IanBenzMaxim | 0:33d4e66780c0 | 1582 | /* 1. Write CNYS pattern to NWP when working in SPI mode only */ |
IanBenzMaxim | 0:33d4e66780c0 | 1583 | NWP_IF_WRITE_CHECK(g_pCB->FD, (_u8 *)&g_H2NCnysPattern.Short, SYNC_PATTERN_LEN); |
IanBenzMaxim | 0:33d4e66780c0 | 1584 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1585 | |
IanBenzMaxim | 0:33d4e66780c0 | 1586 | #if (!defined (SL_TINY)) && (defined(sl_GetTimestamp)) |
IanBenzMaxim | 0:33d4e66780c0 | 1587 | _SlDrvStartMeasureTimeout(&TimeoutInfo, SYNC_PATTERN_TIMEOUT_IN_MSEC); |
IanBenzMaxim | 0:33d4e66780c0 | 1588 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1589 | |
IanBenzMaxim | 0:33d4e66780c0 | 1590 | /* 2. Read 8 bytes (protocol aligned) - expected to be the sync pattern */ |
IanBenzMaxim | 0:33d4e66780c0 | 1591 | NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[0], 8); |
IanBenzMaxim | 0:33d4e66780c0 | 1592 | _SL_DBG_SYNC_LOG(SyncCnt,pBuf); |
IanBenzMaxim | 0:33d4e66780c0 | 1593 | |
IanBenzMaxim | 0:33d4e66780c0 | 1594 | /* read while first 4 bytes are different than last 4 bytes */ |
IanBenzMaxim | 0:33d4e66780c0 | 1595 | while ( *(_u32 *)&pBuf[0] == *(_u32 *)&pBuf[4]) |
IanBenzMaxim | 0:33d4e66780c0 | 1596 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1597 | NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[4], 4); |
IanBenzMaxim | 0:33d4e66780c0 | 1598 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1599 | |
IanBenzMaxim | 0:33d4e66780c0 | 1600 | |
IanBenzMaxim | 0:33d4e66780c0 | 1601 | /* scan for the sync pattern till found or timeout elapsed (if configured) */ |
IanBenzMaxim | 0:33d4e66780c0 | 1602 | while (SearchSync && TimeoutState) |
IanBenzMaxim | 0:33d4e66780c0 | 1603 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1604 | /* scan till we get the real sync pattern */ |
IanBenzMaxim | 0:33d4e66780c0 | 1605 | for (ShiftIdx =0; ShiftIdx <=4 ; ShiftIdx++) |
IanBenzMaxim | 0:33d4e66780c0 | 1606 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1607 | /* sync pattern found so complete the read to 4 bytes aligned */ |
IanBenzMaxim | 0:33d4e66780c0 | 1608 | if (N2H_SYNC_PATTERN_MATCH(&pBuf[ShiftIdx], g_pCB->TxSeqNum)) |
IanBenzMaxim | 0:33d4e66780c0 | 1609 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1610 | /* copy the bytes following the sync pattern to the buffer start */ |
IanBenzMaxim | 0:33d4e66780c0 | 1611 | *(_u32 *)&pBuf[0] = *(_u32 *)&pBuf[ShiftIdx + SYNC_PATTERN_LEN]; |
IanBenzMaxim | 0:33d4e66780c0 | 1612 | |
IanBenzMaxim | 0:33d4e66780c0 | 1613 | /* read the rest of the byte */ |
IanBenzMaxim | 0:33d4e66780c0 | 1614 | NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[SYNC_PATTERN_LEN - ShiftIdx], ShiftIdx); |
IanBenzMaxim | 0:33d4e66780c0 | 1615 | |
IanBenzMaxim | 0:33d4e66780c0 | 1616 | /* here we except to get the opcode + length or false doubled sync..*/ |
IanBenzMaxim | 0:33d4e66780c0 | 1617 | SearchSync = FALSE; |
IanBenzMaxim | 0:33d4e66780c0 | 1618 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 1619 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1620 | |
IanBenzMaxim | 0:33d4e66780c0 | 1621 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1622 | |
IanBenzMaxim | 0:33d4e66780c0 | 1623 | if (SearchSync == TRUE) |
IanBenzMaxim | 0:33d4e66780c0 | 1624 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1625 | /* sync not found move top 4 bytes to bottom */ |
IanBenzMaxim | 0:33d4e66780c0 | 1626 | *(_u32 *)&pBuf[0] = *(_u32 *)&pBuf[4]; |
IanBenzMaxim | 0:33d4e66780c0 | 1627 | |
IanBenzMaxim | 0:33d4e66780c0 | 1628 | /* read 4 more bytes to the buffer top */ |
IanBenzMaxim | 0:33d4e66780c0 | 1629 | NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[4], 4); |
IanBenzMaxim | 0:33d4e66780c0 | 1630 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1631 | |
IanBenzMaxim | 0:33d4e66780c0 | 1632 | |
IanBenzMaxim | 0:33d4e66780c0 | 1633 | #if (defined (sl_GetTimestamp)) && (!defined (SL_TINY)) |
IanBenzMaxim | 0:33d4e66780c0 | 1634 | |
IanBenzMaxim | 0:33d4e66780c0 | 1635 | /* if we got here after first timeout detection, it means that we gave |
IanBenzMaxim | 0:33d4e66780c0 | 1636 | one more chance, and we can now exit the loop with timeout expiry */ |
IanBenzMaxim | 0:33d4e66780c0 | 1637 | if (TIMEOUT_ONE_MORE_SHOT == TimeoutState) |
IanBenzMaxim | 0:33d4e66780c0 | 1638 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1639 | TimeoutState = TIMEOUT_STATE_EXPIRY; |
IanBenzMaxim | 0:33d4e66780c0 | 1640 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 1641 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1642 | |
IanBenzMaxim | 0:33d4e66780c0 | 1643 | /* Timeout occured. do not break now as we want to give one more chance in case |
IanBenzMaxim | 0:33d4e66780c0 | 1644 | the timeout occured due to some external context switch */ |
IanBenzMaxim | 0:33d4e66780c0 | 1645 | if (_SlDrvIsTimeoutExpired(&TimeoutInfo)) |
IanBenzMaxim | 0:33d4e66780c0 | 1646 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1647 | TimeoutState = TIMEOUT_ONE_MORE_SHOT; |
IanBenzMaxim | 0:33d4e66780c0 | 1648 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1649 | |
IanBenzMaxim | 0:33d4e66780c0 | 1650 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1651 | |
IanBenzMaxim | 0:33d4e66780c0 | 1652 | } /* end of while*/ |
IanBenzMaxim | 0:33d4e66780c0 | 1653 | |
IanBenzMaxim | 0:33d4e66780c0 | 1654 | |
IanBenzMaxim | 0:33d4e66780c0 | 1655 | #if (defined (sl_GetTimestamp)) && (!defined (SL_TINY)) |
IanBenzMaxim | 0:33d4e66780c0 | 1656 | if (TIMEOUT_STATE_EXPIRY == TimeoutState) |
IanBenzMaxim | 0:33d4e66780c0 | 1657 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1658 | return SL_API_ABORTED; |
IanBenzMaxim | 0:33d4e66780c0 | 1659 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1660 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1661 | |
IanBenzMaxim | 0:33d4e66780c0 | 1662 | |
IanBenzMaxim | 0:33d4e66780c0 | 1663 | |
IanBenzMaxim | 0:33d4e66780c0 | 1664 | /* 6. Scan for Double pattern. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1665 | while ( N2H_SYNC_PATTERN_MATCH(pBuf, g_pCB->TxSeqNum) ) |
IanBenzMaxim | 0:33d4e66780c0 | 1666 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1667 | _SL_DBG_CNT_INC(Work.DoubleSyncPattern); |
IanBenzMaxim | 0:33d4e66780c0 | 1668 | NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[0], SYNC_PATTERN_LEN); |
IanBenzMaxim | 0:33d4e66780c0 | 1669 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1670 | g_pCB->TxSeqNum++; |
IanBenzMaxim | 0:33d4e66780c0 | 1671 | |
IanBenzMaxim | 0:33d4e66780c0 | 1672 | /* 7. Here we've read Generic Header (4 bytes opcode+length). |
IanBenzMaxim | 0:33d4e66780c0 | 1673 | * Now Read the Resp Specific header (4 more bytes). */ |
IanBenzMaxim | 0:33d4e66780c0 | 1674 | NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[SYNC_PATTERN_LEN], _SL_RESP_SPEC_HDR_SIZE); |
IanBenzMaxim | 0:33d4e66780c0 | 1675 | |
IanBenzMaxim | 0:33d4e66780c0 | 1676 | /* 8. Here we've read the entire Resp Header. */ |
IanBenzMaxim | 0:33d4e66780c0 | 1677 | /* Return number bytes needed to be sent after read for NWP Rx 4-byte alignment (protocol alignment) */ |
IanBenzMaxim | 0:33d4e66780c0 | 1678 | *pAlignSize = (_u8)((SyncCnt > 0) ? (SYNC_PATTERN_LEN - SyncCnt) : 0); |
IanBenzMaxim | 0:33d4e66780c0 | 1679 | |
IanBenzMaxim | 0:33d4e66780c0 | 1680 | return SL_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 1681 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1682 | |
IanBenzMaxim | 0:33d4e66780c0 | 1683 | /* ***************************************************************************** */ |
IanBenzMaxim | 0:33d4e66780c0 | 1684 | /* _SlDrvBasicCmd */ |
IanBenzMaxim | 0:33d4e66780c0 | 1685 | /* ***************************************************************************** */ |
IanBenzMaxim | 0:33d4e66780c0 | 1686 | typedef union |
IanBenzMaxim | 0:33d4e66780c0 | 1687 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1688 | _BasicResponse_t Rsp; |
IanBenzMaxim | 0:33d4e66780c0 | 1689 | }_SlBasicCmdMsg_u; |
IanBenzMaxim | 0:33d4e66780c0 | 1690 | |
IanBenzMaxim | 0:33d4e66780c0 | 1691 | |
IanBenzMaxim | 0:33d4e66780c0 | 1692 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1693 | _i16 _SlDrvBasicCmd(_SlOpcode_t Opcode) |
IanBenzMaxim | 0:33d4e66780c0 | 1694 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1695 | _SlBasicCmdMsg_u Msg; |
IanBenzMaxim | 0:33d4e66780c0 | 1696 | _SlCmdCtrl_t CmdCtrl; |
IanBenzMaxim | 0:33d4e66780c0 | 1697 | |
IanBenzMaxim | 0:33d4e66780c0 | 1698 | _SlDrvMemZero(&Msg, (_u16)sizeof(_SlBasicCmdMsg_u)); |
IanBenzMaxim | 0:33d4e66780c0 | 1699 | |
IanBenzMaxim | 0:33d4e66780c0 | 1700 | CmdCtrl.Opcode = Opcode; |
IanBenzMaxim | 0:33d4e66780c0 | 1701 | CmdCtrl.TxDescLen = 0; |
IanBenzMaxim | 0:33d4e66780c0 | 1702 | CmdCtrl.RxDescLen = (_SlArgSize_t)sizeof(_BasicResponse_t); |
IanBenzMaxim | 0:33d4e66780c0 | 1703 | |
IanBenzMaxim | 0:33d4e66780c0 | 1704 | |
IanBenzMaxim | 0:33d4e66780c0 | 1705 | VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, &Msg, NULL)); |
IanBenzMaxim | 0:33d4e66780c0 | 1706 | |
IanBenzMaxim | 0:33d4e66780c0 | 1707 | return (_i16)Msg.Rsp.status; |
IanBenzMaxim | 0:33d4e66780c0 | 1708 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1709 | |
IanBenzMaxim | 0:33d4e66780c0 | 1710 | /***************************************************************************** |
IanBenzMaxim | 0:33d4e66780c0 | 1711 | _SlDrvCmdSend |
IanBenzMaxim | 0:33d4e66780c0 | 1712 | Send SL command without waiting for command response |
IanBenzMaxim | 0:33d4e66780c0 | 1713 | This function is unprotected and the caller should make |
IanBenzMaxim | 0:33d4e66780c0 | 1714 | sure global lock is active |
IanBenzMaxim | 0:33d4e66780c0 | 1715 | *****************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1716 | _SlReturnVal_t _SlDrvCmdSend( |
IanBenzMaxim | 0:33d4e66780c0 | 1717 | _SlCmdCtrl_t *pCmdCtrl , |
IanBenzMaxim | 0:33d4e66780c0 | 1718 | void *pTxRxDescBuff , |
IanBenzMaxim | 0:33d4e66780c0 | 1719 | _SlCmdExt_t *pCmdExt) |
IanBenzMaxim | 0:33d4e66780c0 | 1720 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1721 | _SlReturnVal_t RetVal; |
IanBenzMaxim | 0:33d4e66780c0 | 1722 | _u8 IsCmdRespWaitedOriginalVal; |
IanBenzMaxim | 0:33d4e66780c0 | 1723 | |
IanBenzMaxim | 0:33d4e66780c0 | 1724 | _SlFunctionParams_t originalFuncParms; |
IanBenzMaxim | 0:33d4e66780c0 | 1725 | |
IanBenzMaxim | 0:33d4e66780c0 | 1726 | /* save the current RespWait flag before clearing it */ |
IanBenzMaxim | 0:33d4e66780c0 | 1727 | IsCmdRespWaitedOriginalVal = g_pCB->IsCmdRespWaited; |
IanBenzMaxim | 0:33d4e66780c0 | 1728 | |
IanBenzMaxim | 0:33d4e66780c0 | 1729 | /* save the current command paramaters */ |
IanBenzMaxim | 0:33d4e66780c0 | 1730 | sl_Memcpy(&originalFuncParms, &g_pCB->FunctionParams, sizeof(_SlFunctionParams_t)); |
IanBenzMaxim | 0:33d4e66780c0 | 1731 | |
IanBenzMaxim | 0:33d4e66780c0 | 1732 | g_pCB->IsCmdRespWaited = FALSE; |
IanBenzMaxim | 0:33d4e66780c0 | 1733 | |
IanBenzMaxim | 0:33d4e66780c0 | 1734 | SL_TRACE0(DBG_MSG, MSG_312, "_SlDrvCmdSend: call _SlDrvMsgWrite"); |
IanBenzMaxim | 0:33d4e66780c0 | 1735 | |
IanBenzMaxim | 0:33d4e66780c0 | 1736 | /* send the message */ |
IanBenzMaxim | 0:33d4e66780c0 | 1737 | RetVal = _SlDrvMsgWrite(pCmdCtrl, pCmdExt, pTxRxDescBuff); |
IanBenzMaxim | 0:33d4e66780c0 | 1738 | |
IanBenzMaxim | 0:33d4e66780c0 | 1739 | /* restore the original RespWait flag */ |
IanBenzMaxim | 0:33d4e66780c0 | 1740 | g_pCB->IsCmdRespWaited = IsCmdRespWaitedOriginalVal; |
IanBenzMaxim | 0:33d4e66780c0 | 1741 | |
IanBenzMaxim | 0:33d4e66780c0 | 1742 | /* restore the original command paramaters */ |
IanBenzMaxim | 0:33d4e66780c0 | 1743 | sl_Memcpy(&g_pCB->FunctionParams, &originalFuncParms, sizeof(_SlFunctionParams_t)); |
IanBenzMaxim | 0:33d4e66780c0 | 1744 | |
IanBenzMaxim | 0:33d4e66780c0 | 1745 | return RetVal; |
IanBenzMaxim | 0:33d4e66780c0 | 1746 | |
IanBenzMaxim | 0:33d4e66780c0 | 1747 | |
IanBenzMaxim | 0:33d4e66780c0 | 1748 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1749 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1750 | |
IanBenzMaxim | 0:33d4e66780c0 | 1751 | /* ***************************************************************************** */ |
IanBenzMaxim | 0:33d4e66780c0 | 1752 | /* _SlDrvWaitForPoolObj */ |
IanBenzMaxim | 0:33d4e66780c0 | 1753 | /* ***************************************************************************** */ |
IanBenzMaxim | 0:33d4e66780c0 | 1754 | _u8 _SlDrvWaitForPoolObj(_u8 ActionID, _u8 SocketID) |
IanBenzMaxim | 0:33d4e66780c0 | 1755 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1756 | _u8 CurrObjIndex = MAX_CONCURRENT_ACTIONS; |
IanBenzMaxim | 0:33d4e66780c0 | 1757 | |
IanBenzMaxim | 0:33d4e66780c0 | 1758 | /* Get free object */ |
IanBenzMaxim | 0:33d4e66780c0 | 1759 | SL_DRV_PROTECTION_OBJ_LOCK_FOREVER(); |
IanBenzMaxim | 0:33d4e66780c0 | 1760 | |
IanBenzMaxim | 0:33d4e66780c0 | 1761 | if (MAX_CONCURRENT_ACTIONS > g_pCB->FreePoolIdx) |
IanBenzMaxim | 0:33d4e66780c0 | 1762 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1763 | /* save the current obj index */ |
IanBenzMaxim | 0:33d4e66780c0 | 1764 | CurrObjIndex = g_pCB->FreePoolIdx; |
IanBenzMaxim | 0:33d4e66780c0 | 1765 | /* set the new free index */ |
IanBenzMaxim | 0:33d4e66780c0 | 1766 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1767 | if (MAX_CONCURRENT_ACTIONS > g_pCB->ObjPool[CurrObjIndex].NextIndex) |
IanBenzMaxim | 0:33d4e66780c0 | 1768 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1769 | g_pCB->FreePoolIdx = g_pCB->ObjPool[CurrObjIndex].NextIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1770 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1771 | else |
IanBenzMaxim | 0:33d4e66780c0 | 1772 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1773 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1774 | /* No further free actions available */ |
IanBenzMaxim | 0:33d4e66780c0 | 1775 | g_pCB->FreePoolIdx = MAX_CONCURRENT_ACTIONS; |
IanBenzMaxim | 0:33d4e66780c0 | 1776 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1777 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1778 | else |
IanBenzMaxim | 0:33d4e66780c0 | 1779 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1780 | SL_DRV_PROTECTION_OBJ_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 1781 | return CurrObjIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1782 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1783 | g_pCB->ObjPool[CurrObjIndex].ActionID = (_u8)ActionID; |
IanBenzMaxim | 0:33d4e66780c0 | 1784 | if (SL_MAX_SOCKETS > SocketID) |
IanBenzMaxim | 0:33d4e66780c0 | 1785 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1786 | g_pCB->ObjPool[CurrObjIndex].AdditionalData = SocketID; |
IanBenzMaxim | 0:33d4e66780c0 | 1787 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1788 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1789 | /*In case this action is socket related, SocketID bit will be on |
IanBenzMaxim | 0:33d4e66780c0 | 1790 | In case SocketID is set to SL_MAX_SOCKETS, the socket is not relevant to the action. In that case ActionID bit will be on */ |
IanBenzMaxim | 0:33d4e66780c0 | 1791 | while ( ( (SL_MAX_SOCKETS > SocketID) && (g_pCB->ActiveActionsBitmap & (1<<SocketID)) ) || |
IanBenzMaxim | 0:33d4e66780c0 | 1792 | ( (g_pCB->ActiveActionsBitmap & (1<<ActionID)) && (SL_MAX_SOCKETS == SocketID) ) ) |
IanBenzMaxim | 0:33d4e66780c0 | 1793 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1794 | /* action in progress - move to pending list */ |
IanBenzMaxim | 0:33d4e66780c0 | 1795 | g_pCB->ObjPool[CurrObjIndex].NextIndex = g_pCB->PendingPoolIdx; |
IanBenzMaxim | 0:33d4e66780c0 | 1796 | g_pCB->PendingPoolIdx = CurrObjIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1797 | SL_DRV_PROTECTION_OBJ_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 1798 | |
IanBenzMaxim | 0:33d4e66780c0 | 1799 | /* wait for action to be free */ |
IanBenzMaxim | 0:33d4e66780c0 | 1800 | (void)_SlDrvSyncObjWaitForever(&g_pCB->ObjPool[CurrObjIndex].SyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 1801 | |
IanBenzMaxim | 0:33d4e66780c0 | 1802 | /* set params and move to active (remove from pending list at _SlDrvReleasePoolObj) */ |
IanBenzMaxim | 0:33d4e66780c0 | 1803 | SL_DRV_PROTECTION_OBJ_LOCK_FOREVER(); |
IanBenzMaxim | 0:33d4e66780c0 | 1804 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1805 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1806 | /* mark as active. Set socket as active if action is on socket, otherwise mark action as active */ |
IanBenzMaxim | 0:33d4e66780c0 | 1807 | if (SL_MAX_SOCKETS > SocketID) |
IanBenzMaxim | 0:33d4e66780c0 | 1808 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1809 | g_pCB->ActiveActionsBitmap |= (1<<SocketID); |
IanBenzMaxim | 0:33d4e66780c0 | 1810 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1811 | else |
IanBenzMaxim | 0:33d4e66780c0 | 1812 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1813 | g_pCB->ActiveActionsBitmap |= (1<<ActionID); |
IanBenzMaxim | 0:33d4e66780c0 | 1814 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1815 | /* move to active list */ |
IanBenzMaxim | 0:33d4e66780c0 | 1816 | g_pCB->ObjPool[CurrObjIndex].NextIndex = g_pCB->ActivePoolIdx; |
IanBenzMaxim | 0:33d4e66780c0 | 1817 | g_pCB->ActivePoolIdx = CurrObjIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1818 | /* unlock */ |
IanBenzMaxim | 0:33d4e66780c0 | 1819 | SL_DRV_PROTECTION_OBJ_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 1820 | return CurrObjIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1821 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1822 | |
IanBenzMaxim | 0:33d4e66780c0 | 1823 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1824 | /* _SlDrvReleasePoolObj */ |
IanBenzMaxim | 0:33d4e66780c0 | 1825 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1826 | void _SlDrvReleasePoolObj(_u8 ObjIdx) |
IanBenzMaxim | 0:33d4e66780c0 | 1827 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1828 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1829 | _u8 PendingIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1830 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1831 | |
IanBenzMaxim | 0:33d4e66780c0 | 1832 | SL_DRV_PROTECTION_OBJ_LOCK_FOREVER(); |
IanBenzMaxim | 0:33d4e66780c0 | 1833 | |
IanBenzMaxim | 0:33d4e66780c0 | 1834 | /* In Tiny mode, there is only one object pool so no pending actions are available */ |
IanBenzMaxim | 0:33d4e66780c0 | 1835 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1836 | /* go over the pending list and release other pending action if needed */ |
IanBenzMaxim | 0:33d4e66780c0 | 1837 | PendingIndex = g_pCB->PendingPoolIdx; |
IanBenzMaxim | 0:33d4e66780c0 | 1838 | |
IanBenzMaxim | 0:33d4e66780c0 | 1839 | while(MAX_CONCURRENT_ACTIONS > PendingIndex) |
IanBenzMaxim | 0:33d4e66780c0 | 1840 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1841 | /* In case this action is socket related, SocketID is in use, otherwise will be set to SL_MAX_SOCKETS */ |
IanBenzMaxim | 0:33d4e66780c0 | 1842 | if ( (g_pCB->ObjPool[PendingIndex].ActionID == g_pCB->ObjPool[ObjIdx].ActionID) && |
IanBenzMaxim | 0:33d4e66780c0 | 1843 | ( (SL_MAX_SOCKETS == (g_pCB->ObjPool[PendingIndex].AdditionalData & BSD_SOCKET_ID_MASK)) || |
IanBenzMaxim | 0:33d4e66780c0 | 1844 | ((SL_MAX_SOCKETS > (g_pCB->ObjPool[ObjIdx].AdditionalData & BSD_SOCKET_ID_MASK)) && ( (g_pCB->ObjPool[PendingIndex].AdditionalData & BSD_SOCKET_ID_MASK) == (g_pCB->ObjPool[ObjIdx].AdditionalData & BSD_SOCKET_ID_MASK) ))) ) |
IanBenzMaxim | 0:33d4e66780c0 | 1845 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1846 | /* remove from pending list */ |
IanBenzMaxim | 0:33d4e66780c0 | 1847 | _SlRemoveFromList(&g_pCB->PendingPoolIdx, PendingIndex); |
IanBenzMaxim | 0:33d4e66780c0 | 1848 | SL_DRV_SYNC_OBJ_SIGNAL(&g_pCB->ObjPool[PendingIndex].SyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 1849 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 1850 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1851 | PendingIndex = g_pCB->ObjPool[PendingIndex].NextIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1852 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1853 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1854 | |
IanBenzMaxim | 0:33d4e66780c0 | 1855 | if (SL_MAX_SOCKETS > (g_pCB->ObjPool[ObjIdx].AdditionalData & BSD_SOCKET_ID_MASK)) |
IanBenzMaxim | 0:33d4e66780c0 | 1856 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1857 | /* unset socketID */ |
IanBenzMaxim | 0:33d4e66780c0 | 1858 | g_pCB->ActiveActionsBitmap &= ~(1<<(g_pCB->ObjPool[ObjIdx].AdditionalData & BSD_SOCKET_ID_MASK)); |
IanBenzMaxim | 0:33d4e66780c0 | 1859 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1860 | else |
IanBenzMaxim | 0:33d4e66780c0 | 1861 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1862 | /* unset actionID */ |
IanBenzMaxim | 0:33d4e66780c0 | 1863 | g_pCB->ActiveActionsBitmap &= ~(1<<g_pCB->ObjPool[ObjIdx].ActionID); |
IanBenzMaxim | 0:33d4e66780c0 | 1864 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1865 | |
IanBenzMaxim | 0:33d4e66780c0 | 1866 | /* delete old data */ |
IanBenzMaxim | 0:33d4e66780c0 | 1867 | g_pCB->ObjPool[ObjIdx].pRespArgs = NULL; |
IanBenzMaxim | 0:33d4e66780c0 | 1868 | g_pCB->ObjPool[ObjIdx].ActionID = 0; |
IanBenzMaxim | 0:33d4e66780c0 | 1869 | g_pCB->ObjPool[ObjIdx].AdditionalData = SL_MAX_SOCKETS; |
IanBenzMaxim | 0:33d4e66780c0 | 1870 | |
IanBenzMaxim | 0:33d4e66780c0 | 1871 | /* remove from active list */ |
IanBenzMaxim | 0:33d4e66780c0 | 1872 | _SlRemoveFromList(&g_pCB->ActivePoolIdx, ObjIdx); |
IanBenzMaxim | 0:33d4e66780c0 | 1873 | /* move to free list */ |
IanBenzMaxim | 0:33d4e66780c0 | 1874 | g_pCB->ObjPool[ObjIdx].NextIndex = g_pCB->FreePoolIdx; |
IanBenzMaxim | 0:33d4e66780c0 | 1875 | g_pCB->FreePoolIdx = ObjIdx; |
IanBenzMaxim | 0:33d4e66780c0 | 1876 | SL_DRV_PROTECTION_OBJ_UNLOCK(); |
IanBenzMaxim | 0:33d4e66780c0 | 1877 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1878 | |
IanBenzMaxim | 0:33d4e66780c0 | 1879 | |
IanBenzMaxim | 0:33d4e66780c0 | 1880 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1881 | /* _SlRemoveFromList */ |
IanBenzMaxim | 0:33d4e66780c0 | 1882 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1883 | static void _SlRemoveFromList(_u8 *ListIndex, _u8 ItemIndex) |
IanBenzMaxim | 0:33d4e66780c0 | 1884 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1885 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1886 | _u8 Idx; |
IanBenzMaxim | 0:33d4e66780c0 | 1887 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1888 | |
IanBenzMaxim | 0:33d4e66780c0 | 1889 | if (MAX_CONCURRENT_ACTIONS == g_pCB->ObjPool[*ListIndex].NextIndex) |
IanBenzMaxim | 0:33d4e66780c0 | 1890 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1891 | *ListIndex = MAX_CONCURRENT_ACTIONS; |
IanBenzMaxim | 0:33d4e66780c0 | 1892 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1893 | /* As MAX_CONCURRENT_ACTIONS is equal to 1 in Tiny mode */ |
IanBenzMaxim | 0:33d4e66780c0 | 1894 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1895 | /* need to remove the first item in the list and therefore update the global which holds this index */ |
IanBenzMaxim | 0:33d4e66780c0 | 1896 | else if (*ListIndex == ItemIndex) |
IanBenzMaxim | 0:33d4e66780c0 | 1897 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1898 | *ListIndex = g_pCB->ObjPool[ItemIndex].NextIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1899 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1900 | else |
IanBenzMaxim | 0:33d4e66780c0 | 1901 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1902 | Idx = *ListIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1903 | |
IanBenzMaxim | 0:33d4e66780c0 | 1904 | while(MAX_CONCURRENT_ACTIONS > Idx) |
IanBenzMaxim | 0:33d4e66780c0 | 1905 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1906 | /* remove from list */ |
IanBenzMaxim | 0:33d4e66780c0 | 1907 | if (g_pCB->ObjPool[Idx].NextIndex == ItemIndex) |
IanBenzMaxim | 0:33d4e66780c0 | 1908 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1909 | g_pCB->ObjPool[Idx].NextIndex = g_pCB->ObjPool[ItemIndex].NextIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1910 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 1911 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1912 | |
IanBenzMaxim | 0:33d4e66780c0 | 1913 | Idx = g_pCB->ObjPool[Idx].NextIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1914 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1915 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1916 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1917 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1918 | |
IanBenzMaxim | 0:33d4e66780c0 | 1919 | |
IanBenzMaxim | 0:33d4e66780c0 | 1920 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1921 | /* _SlFindAndSetActiveObj */ |
IanBenzMaxim | 0:33d4e66780c0 | 1922 | /* ******************************************************************************/ |
IanBenzMaxim | 0:33d4e66780c0 | 1923 | static _SlReturnVal_t _SlFindAndSetActiveObj(_SlOpcode_t Opcode, _u8 Sd) |
IanBenzMaxim | 0:33d4e66780c0 | 1924 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1925 | _u8 ActiveIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1926 | |
IanBenzMaxim | 0:33d4e66780c0 | 1927 | ActiveIndex = g_pCB->ActivePoolIdx; |
IanBenzMaxim | 0:33d4e66780c0 | 1928 | /* go over the active list if exist to find obj waiting for this Async event */ |
IanBenzMaxim | 0:33d4e66780c0 | 1929 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1930 | while (MAX_CONCURRENT_ACTIONS > ActiveIndex) |
IanBenzMaxim | 0:33d4e66780c0 | 1931 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 1932 | /* Only one Active action is availabe in tiny mode, so we can replace the loop with if condition */ |
IanBenzMaxim | 0:33d4e66780c0 | 1933 | if (MAX_CONCURRENT_ACTIONS > ActiveIndex) |
IanBenzMaxim | 0:33d4e66780c0 | 1934 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1935 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1936 | /* unset the Ipv4\IPv6 bit in the opcode if family bit was set */ |
IanBenzMaxim | 0:33d4e66780c0 | 1937 | if (g_pCB->ObjPool[ActiveIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) |
IanBenzMaxim | 0:33d4e66780c0 | 1938 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1939 | Opcode &= ~SL_OPCODE_IPV6; |
IanBenzMaxim | 0:33d4e66780c0 | 1940 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1941 | |
IanBenzMaxim | 0:33d4e66780c0 | 1942 | if ((g_pCB->ObjPool[ActiveIndex].ActionID == RECV_ID) && (Sd == g_pCB->ObjPool[ActiveIndex].AdditionalData) && |
IanBenzMaxim | 0:33d4e66780c0 | 1943 | ( (SL_OPCODE_SOCKET_RECVASYNCRESPONSE == Opcode) || (SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE == Opcode) |
IanBenzMaxim | 0:33d4e66780c0 | 1944 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 1945 | || (SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE_V6 == Opcode) |
IanBenzMaxim | 0:33d4e66780c0 | 1946 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1947 | ) |
IanBenzMaxim | 0:33d4e66780c0 | 1948 | |
IanBenzMaxim | 0:33d4e66780c0 | 1949 | ) |
IanBenzMaxim | 0:33d4e66780c0 | 1950 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1951 | g_pCB->FunctionParams.AsyncExt.ActionIndex = ActiveIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1952 | return SL_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 1953 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1954 | /* In case this action is socket related, SocketID is in use, otherwise will be set to SL_MAX_SOCKETS */ |
IanBenzMaxim | 0:33d4e66780c0 | 1955 | if ( (_SlActionLookupTable[ g_pCB->ObjPool[ActiveIndex].ActionID - MAX_SOCKET_ENUM_IDX].ActionAsyncOpcode == Opcode) && |
IanBenzMaxim | 0:33d4e66780c0 | 1956 | ( ((Sd == (g_pCB->ObjPool[ActiveIndex].AdditionalData & BSD_SOCKET_ID_MASK) ) && (SL_MAX_SOCKETS > Sd)) || (SL_MAX_SOCKETS == (g_pCB->ObjPool[ActiveIndex].AdditionalData & BSD_SOCKET_ID_MASK)) ) ) |
IanBenzMaxim | 0:33d4e66780c0 | 1957 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1958 | /* set handler */ |
IanBenzMaxim | 0:33d4e66780c0 | 1959 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = _SlActionLookupTable[ g_pCB->ObjPool[ActiveIndex].ActionID - MAX_SOCKET_ENUM_IDX].AsyncEventHandler; |
IanBenzMaxim | 0:33d4e66780c0 | 1960 | g_pCB->FunctionParams.AsyncExt.ActionIndex = ActiveIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1961 | return SL_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 1962 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1963 | ActiveIndex = g_pCB->ObjPool[ActiveIndex].NextIndex; |
IanBenzMaxim | 0:33d4e66780c0 | 1964 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1965 | |
IanBenzMaxim | 0:33d4e66780c0 | 1966 | return SL_RET_CODE_SELF_ERROR; |
IanBenzMaxim | 0:33d4e66780c0 | 1967 | |
IanBenzMaxim | 0:33d4e66780c0 | 1968 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1969 | |
IanBenzMaxim | 0:33d4e66780c0 | 1970 | |
IanBenzMaxim | 0:33d4e66780c0 | 1971 | #if defined(sl_HttpServerCallback) || defined(EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS) |
IanBenzMaxim | 0:33d4e66780c0 | 1972 | void _SlDrvDispatchHttpServerEvents(SlHttpServerEvent_t *slHttpServerEvent, SlHttpServerResponse_t *slHttpServerResponse) |
IanBenzMaxim | 0:33d4e66780c0 | 1973 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1974 | _SlDrvHandleHttpServerEvents (slHttpServerEvent, slHttpServerResponse); |
IanBenzMaxim | 0:33d4e66780c0 | 1975 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1976 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 1977 | |
IanBenzMaxim | 0:33d4e66780c0 | 1978 | |
IanBenzMaxim | 0:33d4e66780c0 | 1979 | /* Wrappers for the object functions */ |
IanBenzMaxim | 0:33d4e66780c0 | 1980 | |
IanBenzMaxim | 0:33d4e66780c0 | 1981 | |
IanBenzMaxim | 0:33d4e66780c0 | 1982 | _SlReturnVal_t _SlDrvSyncObjSignal(_SlSyncObj_t *pSyncObj) |
IanBenzMaxim | 0:33d4e66780c0 | 1983 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1984 | OSI_RET_OK_CHECK(sl_SyncObjSignal(pSyncObj)); |
IanBenzMaxim | 0:33d4e66780c0 | 1985 | return SL_OS_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 1986 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1987 | |
IanBenzMaxim | 0:33d4e66780c0 | 1988 | _SlReturnVal_t _SlDrvObjLockWaitForever(_SlLockObj_t *pLockObj) |
IanBenzMaxim | 0:33d4e66780c0 | 1989 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1990 | OSI_RET_OK_CHECK(sl_LockObjLock(pLockObj, SL_OS_WAIT_FOREVER)); |
IanBenzMaxim | 0:33d4e66780c0 | 1991 | return SL_OS_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 1992 | } |
IanBenzMaxim | 0:33d4e66780c0 | 1993 | |
IanBenzMaxim | 0:33d4e66780c0 | 1994 | _SlReturnVal_t _SlDrvProtectionObjLockWaitForever(void) |
IanBenzMaxim | 0:33d4e66780c0 | 1995 | { |
IanBenzMaxim | 0:33d4e66780c0 | 1996 | OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); |
IanBenzMaxim | 0:33d4e66780c0 | 1997 | |
IanBenzMaxim | 0:33d4e66780c0 | 1998 | return SL_OS_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 1999 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2000 | |
IanBenzMaxim | 0:33d4e66780c0 | 2001 | _SlReturnVal_t _SlDrvObjUnLock(_SlLockObj_t *pLockObj) |
IanBenzMaxim | 0:33d4e66780c0 | 2002 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2003 | OSI_RET_OK_CHECK(sl_LockObjUnlock(pLockObj)); |
IanBenzMaxim | 0:33d4e66780c0 | 2004 | |
IanBenzMaxim | 0:33d4e66780c0 | 2005 | return SL_OS_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 2006 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2007 | |
IanBenzMaxim | 0:33d4e66780c0 | 2008 | _SlReturnVal_t _SlDrvProtectionObjUnLock(void) |
IanBenzMaxim | 0:33d4e66780c0 | 2009 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2010 | OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); |
IanBenzMaxim | 0:33d4e66780c0 | 2011 | return SL_OS_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 2012 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2013 | |
IanBenzMaxim | 0:33d4e66780c0 | 2014 | static _SlReturnVal_t _SlDrvObjGlobalLockWaitForever(void) |
IanBenzMaxim | 0:33d4e66780c0 | 2015 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2016 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 2017 | if (g_bDeviceRestartIsRequired == TRUE) |
IanBenzMaxim | 0:33d4e66780c0 | 2018 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2019 | return SL_API_ABORTED; |
IanBenzMaxim | 0:33d4e66780c0 | 2020 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2021 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 2022 | return sl_LockObjLock(&g_pCB->GlobalLockObj, SL_OS_WAIT_FOREVER); |
IanBenzMaxim | 0:33d4e66780c0 | 2023 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2024 | _SlReturnVal_t _SlDrvGlobalObjUnLock(void) |
IanBenzMaxim | 0:33d4e66780c0 | 2025 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2026 | |
IanBenzMaxim | 0:33d4e66780c0 | 2027 | OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->GlobalLockObj)); |
IanBenzMaxim | 0:33d4e66780c0 | 2028 | |
IanBenzMaxim | 0:33d4e66780c0 | 2029 | return SL_OS_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 2030 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2031 | |
IanBenzMaxim | 0:33d4e66780c0 | 2032 | void _SlDrvMemZero(void* Addr, _u16 size) |
IanBenzMaxim | 0:33d4e66780c0 | 2033 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2034 | sl_Memset(Addr, 0, size); |
IanBenzMaxim | 0:33d4e66780c0 | 2035 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2036 | |
IanBenzMaxim | 0:33d4e66780c0 | 2037 | |
IanBenzMaxim | 0:33d4e66780c0 | 2038 | void _SlDrvResetCmdExt(_SlCmdExt_t* pCmdExt) |
IanBenzMaxim | 0:33d4e66780c0 | 2039 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2040 | _SlDrvMemZero(pCmdExt, (_u16)sizeof (_SlCmdExt_t)); |
IanBenzMaxim | 0:33d4e66780c0 | 2041 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2042 | |
IanBenzMaxim | 0:33d4e66780c0 | 2043 | |
IanBenzMaxim | 0:33d4e66780c0 | 2044 | #ifdef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 2045 | |
IanBenzMaxim | 0:33d4e66780c0 | 2046 | _SlReturnVal_t _SlDrvSyncObjWaitForever(_SlSyncObj_t *pSyncObj) |
IanBenzMaxim | 0:33d4e66780c0 | 2047 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2048 | return sl_SyncObjWait(pSyncObj, SL_OS_WAIT_FOREVER); |
IanBenzMaxim | 0:33d4e66780c0 | 2049 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2050 | |
IanBenzMaxim | 0:33d4e66780c0 | 2051 | #else |
IanBenzMaxim | 0:33d4e66780c0 | 2052 | _SlReturnVal_t _SlDrvSyncObjWaitForever(_SlSyncObj_t *pSyncObj) |
IanBenzMaxim | 0:33d4e66780c0 | 2053 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2054 | (void)sl_SyncObjWait(pSyncObj, SL_OS_WAIT_FOREVER); |
IanBenzMaxim | 0:33d4e66780c0 | 2055 | |
IanBenzMaxim | 0:33d4e66780c0 | 2056 | /* if the wait is finished and we detect that restart is required (we in the middle of error handling), |
IanBenzMaxim | 0:33d4e66780c0 | 2057 | than we should abort immediately from the current API command execution |
IanBenzMaxim | 0:33d4e66780c0 | 2058 | */ |
IanBenzMaxim | 0:33d4e66780c0 | 2059 | if (g_bDeviceRestartIsRequired == TRUE) |
IanBenzMaxim | 0:33d4e66780c0 | 2060 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2061 | return SL_API_ABORTED; |
IanBenzMaxim | 0:33d4e66780c0 | 2062 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2063 | |
IanBenzMaxim | 0:33d4e66780c0 | 2064 | return SL_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 2065 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2066 | |
IanBenzMaxim | 0:33d4e66780c0 | 2067 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 2068 | |
IanBenzMaxim | 0:33d4e66780c0 | 2069 | |
IanBenzMaxim | 0:33d4e66780c0 | 2070 | #ifndef SL_TINY_EXT |
IanBenzMaxim | 0:33d4e66780c0 | 2071 | |
IanBenzMaxim | 0:33d4e66780c0 | 2072 | |
IanBenzMaxim | 0:33d4e66780c0 | 2073 | _SlReturnVal_t _SlDrvSyncObjWaitTimeout(_SlSyncObj_t *pSyncObj, _u32 timeoutVal, SlDriverAPIWithTimeout_e apiIdx) |
IanBenzMaxim | 0:33d4e66780c0 | 2074 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2075 | _SlReturnVal_t ret = sl_SyncObjWait(pSyncObj, timeoutVal); |
IanBenzMaxim | 0:33d4e66780c0 | 2076 | |
IanBenzMaxim | 0:33d4e66780c0 | 2077 | /* if timeout occured...*/ |
IanBenzMaxim | 0:33d4e66780c0 | 2078 | if (ret) |
IanBenzMaxim | 0:33d4e66780c0 | 2079 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2080 | _SlDriverHandleError(SL_DEVICE_DRIVER_TIMEOUT_ASYNC_EVENT, apiIdx, timeoutVal); |
IanBenzMaxim | 0:33d4e66780c0 | 2081 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2082 | else if (g_bDeviceRestartIsRequired == TRUE) |
IanBenzMaxim | 0:33d4e66780c0 | 2083 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2084 | return SL_API_ABORTED; |
IanBenzMaxim | 0:33d4e66780c0 | 2085 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2086 | |
IanBenzMaxim | 0:33d4e66780c0 | 2087 | return SL_RET_CODE_OK; |
IanBenzMaxim | 0:33d4e66780c0 | 2088 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2089 | |
IanBenzMaxim | 0:33d4e66780c0 | 2090 | |
IanBenzMaxim | 0:33d4e66780c0 | 2091 | void _SlDriverHandleError(SlDeviceDriverError_e eError, _u32 info1, _u32 info2) |
IanBenzMaxim | 0:33d4e66780c0 | 2092 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2093 | _u8 i; |
IanBenzMaxim | 0:33d4e66780c0 | 2094 | SlDeviceEvent_t devHandler; |
IanBenzMaxim | 0:33d4e66780c0 | 2095 | |
IanBenzMaxim | 0:33d4e66780c0 | 2096 | if (TRUE == g_bDeviceRestartIsRequired) |
IanBenzMaxim | 0:33d4e66780c0 | 2097 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2098 | return; |
IanBenzMaxim | 0:33d4e66780c0 | 2099 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2100 | |
IanBenzMaxim | 0:33d4e66780c0 | 2101 | /* set the restart flag */ |
IanBenzMaxim | 0:33d4e66780c0 | 2102 | g_bDeviceRestartIsRequired = TRUE; |
IanBenzMaxim | 0:33d4e66780c0 | 2103 | |
IanBenzMaxim | 0:33d4e66780c0 | 2104 | /* Upon the deletion of the mutex, all thread waiting on this |
IanBenzMaxim | 0:33d4e66780c0 | 2105 | mutex will return immediately with an error (i.e. MUTEX_DELETED status) */ |
IanBenzMaxim | 0:33d4e66780c0 | 2106 | (void)sl_LockObjDelete(&g_pCB->GlobalLockObj); |
IanBenzMaxim | 0:33d4e66780c0 | 2107 | |
IanBenzMaxim | 0:33d4e66780c0 | 2108 | /* signal all waiting sync objects */ |
IanBenzMaxim | 0:33d4e66780c0 | 2109 | for (i=0; i< MAX_CONCURRENT_ACTIONS; i++) |
IanBenzMaxim | 0:33d4e66780c0 | 2110 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2111 | SL_DRV_SYNC_OBJ_SIGNAL(&g_pCB->ObjPool[i].SyncObj); |
IanBenzMaxim | 0:33d4e66780c0 | 2112 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2113 | |
IanBenzMaxim | 0:33d4e66780c0 | 2114 | /* prepare the event and notify the user app/ext libraries */ |
IanBenzMaxim | 0:33d4e66780c0 | 2115 | devHandler.Event = eError; |
IanBenzMaxim | 0:33d4e66780c0 | 2116 | |
IanBenzMaxim | 0:33d4e66780c0 | 2117 | switch (eError) |
IanBenzMaxim | 0:33d4e66780c0 | 2118 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2119 | case SL_DEVICE_ABORT_ERROR_EVENT: |
IanBenzMaxim | 0:33d4e66780c0 | 2120 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2121 | devHandler.EventData.deviceReport.AbortType = (_u32)info1; |
IanBenzMaxim | 0:33d4e66780c0 | 2122 | devHandler.EventData.deviceReport.AbortData = (_u32)info2; |
IanBenzMaxim | 0:33d4e66780c0 | 2123 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2124 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 2125 | |
IanBenzMaxim | 0:33d4e66780c0 | 2126 | /* For asyn event timeout type error: |
IanBenzMaxim | 0:33d4e66780c0 | 2127 | * Info1 - Holds the SL API index (2 bytes) |
IanBenzMaxim | 0:33d4e66780c0 | 2128 | */ |
IanBenzMaxim | 0:33d4e66780c0 | 2129 | case SL_DEVICE_DRIVER_TIMEOUT_ASYNC_EVENT: |
IanBenzMaxim | 0:33d4e66780c0 | 2130 | |
IanBenzMaxim | 0:33d4e66780c0 | 2131 | /* For cmd complete timeout type error: |
IanBenzMaxim | 0:33d4e66780c0 | 2132 | * Info1 - Holds the cmd opcode (2 bytes) |
IanBenzMaxim | 0:33d4e66780c0 | 2133 | */ |
IanBenzMaxim | 0:33d4e66780c0 | 2134 | case SL_DEVICE_DRIVER_TIMEOUT_CMD_COMPLETE: |
IanBenzMaxim | 0:33d4e66780c0 | 2135 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2136 | devHandler.EventData.deviceDriverReport.info = info1; |
IanBenzMaxim | 0:33d4e66780c0 | 2137 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2138 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 2139 | |
IanBenzMaxim | 0:33d4e66780c0 | 2140 | default: |
IanBenzMaxim | 0:33d4e66780c0 | 2141 | devHandler.EventData.deviceDriverReport.info = info1; |
IanBenzMaxim | 0:33d4e66780c0 | 2142 | break; |
IanBenzMaxim | 0:33d4e66780c0 | 2143 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2144 | |
IanBenzMaxim | 0:33d4e66780c0 | 2145 | /* call the registered handlers */ |
IanBenzMaxim | 0:33d4e66780c0 | 2146 | _SlDrvHandleGeneralEvents(&devHandler); |
IanBenzMaxim | 0:33d4e66780c0 | 2147 | |
IanBenzMaxim | 0:33d4e66780c0 | 2148 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2149 | |
IanBenzMaxim | 0:33d4e66780c0 | 2150 | |
IanBenzMaxim | 0:33d4e66780c0 | 2151 | #if (defined(sl_GetTimestamp)) |
IanBenzMaxim | 0:33d4e66780c0 | 2152 | |
IanBenzMaxim | 0:33d4e66780c0 | 2153 | void _SlDrvStartMeasureTimeout(_SlTimeoutParams_t *pTimeoutInfo, _u32 TimeoutInMsec) |
IanBenzMaxim | 0:33d4e66780c0 | 2154 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2155 | pTimeoutInfo->Total10MSecUnits = TimeoutInMsec / 10; |
IanBenzMaxim | 0:33d4e66780c0 | 2156 | pTimeoutInfo->TSPrev = sl_GetTimestamp(); |
IanBenzMaxim | 0:33d4e66780c0 | 2157 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2158 | |
IanBenzMaxim | 0:33d4e66780c0 | 2159 | _u8 _SlDrvIsTimeoutExpired(_SlTimeoutParams_t *pTimeoutInfo) |
IanBenzMaxim | 0:33d4e66780c0 | 2160 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2161 | _u32 TSCount; |
IanBenzMaxim | 0:33d4e66780c0 | 2162 | |
IanBenzMaxim | 0:33d4e66780c0 | 2163 | pTimeoutInfo->TSCurr = sl_GetTimestamp(); |
IanBenzMaxim | 0:33d4e66780c0 | 2164 | |
IanBenzMaxim | 0:33d4e66780c0 | 2165 | if (pTimeoutInfo->TSCurr >= pTimeoutInfo->TSPrev) |
IanBenzMaxim | 0:33d4e66780c0 | 2166 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2167 | pTimeoutInfo->DeltaTicks = pTimeoutInfo->TSCurr - pTimeoutInfo->TSPrev; |
IanBenzMaxim | 0:33d4e66780c0 | 2168 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2169 | else |
IanBenzMaxim | 0:33d4e66780c0 | 2170 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2171 | pTimeoutInfo->DeltaTicks = (SL_TIMESTAMP_MAX_VALUE - pTimeoutInfo->TSPrev) + pTimeoutInfo->TSCurr; |
IanBenzMaxim | 0:33d4e66780c0 | 2172 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2173 | |
IanBenzMaxim | 0:33d4e66780c0 | 2174 | TSCount = pTimeoutInfo->DeltaTicksReminder + pTimeoutInfo->DeltaTicks; |
IanBenzMaxim | 0:33d4e66780c0 | 2175 | |
IanBenzMaxim | 0:33d4e66780c0 | 2176 | |
IanBenzMaxim | 0:33d4e66780c0 | 2177 | if (TSCount > SL_TIMESTAMP_TICKS_IN_10_MILLISECONDS) |
IanBenzMaxim | 0:33d4e66780c0 | 2178 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2179 | pTimeoutInfo->Total10MSecUnits -= (TSCount / SL_TIMESTAMP_TICKS_IN_10_MILLISECONDS); |
IanBenzMaxim | 0:33d4e66780c0 | 2180 | pTimeoutInfo->DeltaTicksReminder = TSCount % SL_TIMESTAMP_TICKS_IN_10_MILLISECONDS; |
IanBenzMaxim | 0:33d4e66780c0 | 2181 | |
IanBenzMaxim | 0:33d4e66780c0 | 2182 | if (pTimeoutInfo->Total10MSecUnits > 0) |
IanBenzMaxim | 0:33d4e66780c0 | 2183 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2184 | pTimeoutInfo->TSPrev = pTimeoutInfo->TSCurr; |
IanBenzMaxim | 0:33d4e66780c0 | 2185 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2186 | else |
IanBenzMaxim | 0:33d4e66780c0 | 2187 | { |
IanBenzMaxim | 0:33d4e66780c0 | 2188 | return TRUE; |
IanBenzMaxim | 0:33d4e66780c0 | 2189 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2190 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2191 | |
IanBenzMaxim | 0:33d4e66780c0 | 2192 | return FALSE; |
IanBenzMaxim | 0:33d4e66780c0 | 2193 | } |
IanBenzMaxim | 0:33d4e66780c0 | 2194 | |
IanBenzMaxim | 0:33d4e66780c0 | 2195 | #endif |
IanBenzMaxim | 0:33d4e66780c0 | 2196 | |
IanBenzMaxim | 0:33d4e66780c0 | 2197 | #endif |