1 /* 2 * Copyright 2012-2020 NXP 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef PHTMLUWB_H 18 #define PHTMLUWB_H 19 20 #include <memory> 21 22 #include <phUwbCommon.h> 23 #include <phMessageQueue.h> 24 25 /* 26 * Message posted by Reader thread uponl 27 * completion of requested operation 28 */ 29 #define PH_TMLUWB_READ_MESSAGE (0xAA) 30 31 /* 32 * Message posted by Writer thread upon 33 * completion of requested operation 34 */ 35 #define PH_TMLUWB_WRITE_MESSAGE (0x55) 36 37 /* 38 * Value indicates to reset device 39 */ 40 #define PH_TMLUWB_RESETDEVICE (0x00008001) 41 42 /* 43 ***************************Globals,Structure and Enumeration ****************** 44 */ 45 46 /* 47 * Transaction (Tx/Rx) completion information structure of TML 48 * 49 * This structure holds the completion callback information of the 50 * transaction passed from the TML layer to the Upper layer 51 * along with the completion callback. 52 * 53 * The value of field wStatus can be interpreted as: 54 * 55 * - UWBSTATUS_SUCCESS Transaction performed 56 * successfully. 57 * - UWBSTATUS_FAILED Failed to wait on Read/Write 58 * operation. 59 * - UWBSTATUS_INSUFFICIENT_STORAGE Not enough memory to store data in 60 * case of read. 61 * - UWBSTATUS_BOARD_COMMUNICATION_ERROR Failure to Read/Write from the 62 * file or timeout. 63 */ 64 65 struct phTmlUwb_WriteTransactInfo { 66 tHAL_UWB_STATUS wStatus; 67 const uint8_t* pBuff; 68 size_t wLength; 69 }; 70 71 struct phTmlUwb_ReadTransactInfo { 72 tHAL_UWB_STATUS wStatus; 73 uint8_t* pBuff; 74 size_t wLength; 75 }; 76 77 // IO completion callback to Upper Layer 78 // pContext - Context provided by upper layer 79 // pInfo - Transaction info. See phTmlUwb_[Read|Write]TransactInfo 80 using ReadCallback = void (void *pContext, phTmlUwb_ReadTransactInfo* pInfo); 81 using WriteCallback = void (void *pContext, phTmlUwb_WriteTransactInfo* pInfo); 82 83 /* 84 * Enum definition contains supported ioctl control codes. 85 * 86 * phTmlUwb_Spi_IoCtl 87 */ 88 enum class phTmlUwb_ControlCode_t { 89 Invalid = 0, 90 SetPower, 91 EnableFwdMode, 92 EnableThroughPut, 93 EseReset, 94 }; 95 96 /* Function declarations */ 97 tHAL_UWB_STATUS phTmlUwb_Init(const char* pDevName, std::shared_ptr<MessageQueue<phLibUwb_Message>> pClientMq); 98 tHAL_UWB_STATUS phTmlUwb_Shutdown(void); 99 void phTmlUwb_Suspend(void); 100 void phTmlUwb_Resume(void); 101 102 // Writer: caller should call this for every write io 103 tHAL_UWB_STATUS phTmlUwb_Write(const uint8_t* pBuffer, size_t wLength, 104 WriteCallback pTmlWriteComplete, 105 void* pContext); 106 107 // Reader: caller calls this once, callback will be called for every received packet. 108 // and call StopRead() to unscribe RX packet. 109 tHAL_UWB_STATUS phTmlUwb_StartRead(ReadCallback pTmlReadComplete, void* pContext); 110 void phTmlUwb_StopRead(); 111 112 void phTmlUwb_Chip_Reset(void); 113 void phTmlUwb_DeferredCall(std::shared_ptr<phLibUwb_Message> msg); 114 #endif /* PHTMLUWB_H */ 115