1 /* 2 * cc_pal.h - CC32xx Host Driver Implementation 3 * 4 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/ 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the 17 * distribution. 18 * 19 * Neither the name of Texas Instruments Incorporated nor the names of 20 * its contributors may be used to endorse or promote products derived 21 * from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 */ 36 /****************************************************************************** 37 * cc_pal.h 38 * 39 * SimpleLink Wi-Fi abstraction file for CC32xx 40 ******************************************************************************/ 41 42 #ifndef __CC31xx_PAL_H__ 43 #define __CC31xx_PAL_H__ 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 50 #include <ti/drivers/dpl/ClockP.h> 51 #if defined(SL_PLATFORM_MULTI_THREADED) 52 /* Use Zephyr posix headers */ 53 #include <posix/time.h> 54 #include <posix/pthread.h> 55 #include <posix/semaphore.h> 56 #include <posix/unistd.h> 57 #else //SL_PLATFORM_MULTI_THREADED 58 #include <ti/drivers/dpl/SemaphoreP.h> 59 #include <ti/drivers/dpl/MutexP.h> 60 61 #endif 62 63 64 65 66 67 #define MAX_QUEUE_SIZE (4) 68 #define OS_WAIT_FOREVER (0xFFFFFFFF) 69 #define OS_NO_WAIT (0) 70 #define OS_OK (0) 71 72 #define Semaphore_OK (0) 73 #define Semaphore_FAILURE (-1) 74 75 #define Mutex_OK (0) 76 #define Mutex_FAILURE (-1) 77 78 79 /*! 80 \brief type definition for the SPI channel file descriptor 81 82 \note On each porting or platform the type could be whatever is needed - integer, pointer to structure etc. 83 */ 84 typedef int Fd_t; 85 86 87 /*! 88 \brief type definition for the host interrupt handler 89 90 \param pValue - pointer to any memory strcuture. The value of this pointer is given on 91 registration of a new interrupt handler 92 93 \note 94 */ 95 96 typedef void (*SL_P_EVENT_HANDLER)(void); 97 98 #define P_EVENT_HANDLER SL_P_EVENT_HANDLER 99 100 /*! 101 \brief type definition for the host spawn function 102 103 \param pValue - pointer to any memory strcuture. The value of this pointer is given on 104 invoking the spawn function. 105 106 \note 107 */ 108 109 typedef signed short (*P_OS_SPAWN_ENTRY)(void* pValue); 110 111 typedef struct 112 { 113 P_OS_SPAWN_ENTRY pEntry; 114 void* pValue; 115 }tSimpleLinkSpawnMsg; 116 117 /*! 118 \brief open spi communication port to be used for communicating with a SimpleLink device 119 120 Given an interface name and option flags, this function opens the spi communication port 121 and creates a file descriptor. This file descriptor can be used afterwards to read and 122 write data from and to this specific spi channel. 123 The SPI speed, clock polarity, clock phase, chip select and all other attributes are all 124 set to hardcoded values in this function. 125 126 \param ifName - points to the interface name/path. The interface name is an 127 optional attributes that the SimpleLink driver receives 128 on opening the device. in systems that the spi channel is 129 not implemented as part of the os device drivers, this 130 parameter could be NULL. 131 \param flags - option flags 132 133 \return upon successful completion, the function shall open the spi channel and return 134 a non-negative integer representing the file descriptor. 135 Otherwise, -1 shall be returned 136 137 \sa spi_Close , spi_Read , spi_Write 138 \note 139 \warning 140 */ 141 Fd_t spi_Open(char *ifName, unsigned long flags); 142 143 /*! 144 \brief closes an opened SPI communication port 145 146 \param fd - file descriptor of an opened SPI channel 147 148 \return upon successful completion, the function shall return 0. 149 Otherwise, -1 shall be returned 150 151 \sa spi_Open 152 \note 153 \warning 154 */ 155 int spi_Close(Fd_t fd); 156 157 /*! 158 \brief attempts to read up to len bytes from SPI channel into a buffer starting at pBuff. 159 160 \param fd - file descriptor of an opened SPI channel 161 162 \param pBuff - points to first location to start writing the data 163 164 \param len - number of bytes to read from the SPI channel 165 166 \return upon successful completion, the function shall return 0. 167 Otherwise, -1 shall be returned 168 169 \sa spi_Open , spi_Write 170 \note 171 \warning 172 */ 173 int spi_Read(Fd_t fd, unsigned char *pBuff, int len); 174 175 /*! 176 \brief attempts to write up to len bytes to the SPI channel 177 178 \param fd - file descriptor of an opened SPI channel 179 180 \param pBuff - points to first location to start getting the data from 181 182 \param len - number of bytes to write to the SPI channel 183 184 \return upon successful completion, the function shall return 0. 185 Otherwise, -1 shall be returned 186 187 \sa spi_Open , spi_Read 188 \note This function could be implemented as zero copy and return only upon successful completion 189 of writing the whole buffer, but in cases that memory allocation is not too tight, the 190 function could copy the data to internal buffer, return back and complete the write in 191 parallel to other activities as long as the other SPI activities would be blocked untill 192 the entire buffer write would be completed 193 \warning 194 */ 195 int spi_Write(Fd_t fd, unsigned char *pBuff, int len); 196 197 /*! 198 \brief register an interrupt handler for the host IRQ 199 200 \param InterruptHdl - pointer to interrupt handler function 201 202 \param pValue - pointer to a memory strcuture that is passed to the interrupt handler. 203 204 \return upon successful registration, the function shall return 0. 205 Otherwise, -1 shall be returned 206 207 \sa 208 \note If there is already registered interrupt handler, the function should overwrite the old handler 209 with the new one 210 \warning 211 */ 212 int NwpRegisterInterruptHandler(P_EVENT_HANDLER InterruptHdl , void* pValue); 213 214 215 /*! 216 \brief Masks host IRQ 217 218 219 \sa NwpUnMaskInterrupt 220 221 \warning 222 */ 223 void NwpMaskInterrupt(); 224 225 226 /*! 227 \brief Unmasks host IRQ 228 229 230 \sa NwpMaskInterrupt 231 232 \warning 233 */ 234 void NwpUnMaskInterrupt(); 235 236 237 /*! 238 \brief Preamble to the enabling the Network Processor. 239 Placeholder to implement any pre-process operations 240 before enabling networking operations. 241 242 \sa sl_DeviceEnable 243 244 \note belongs to \ref ported_sec 245 246 */ 247 248 void NwpPowerOnPreamble(void); 249 250 251 252 /*! 253 \brief Disable the Network Processor 254 255 \sa sl_DeviceEnable 256 257 \note belongs to \ref ported_sec 258 */ 259 void NwpPowerOff(void); 260 261 262 /*! 263 \brief Enable the Network Processor 264 265 \sa sl_DeviceDisable 266 267 \note belongs to \ref ported_sec 268 269 */ 270 void NwpPowerOn(void); 271 272 273 274 275 #if defined(SL_PLATFORM_MULTI_THREADED) 276 277 /*! 278 \brief Time wait for a semaphore handle, using the driver porting layer of the core SDK. 279 280 \param pSemHandle - pointer to a memory structure that would contain the handle. 281 282 \param timeout - specify the time to wait for the signal 283 284 \return The function shall return 0. 285 286 \note belongs to \ref ported_sec 287 */ 288 int Semaphore_pend_handle(sem_t* pSemHandle, uint32_t timeout); 289 290 /*! 291 \brief Creates a mutex object handle, using the driver porting layer of the core SDK. 292 293 \param pMutexHandle - pointer to a memory structure that would contain the handle. 294 295 \return upon successful creation, the function shall return 0. 296 Otherwise, -1 shall be returned 297 298 \note belongs to \ref ported_sec 299 */ 300 int Mutex_create_handle(pthread_mutex_t* pMutexHandle); 301 302 303 /*! 304 \brief Deletes a mutex object handle, using the driver porting layer of the core SDK. 305 306 \param pMutexHandle - pointer to a memory structure that would contain the handle. 307 308 \return the function shall return 0. 309 310 \note belongs to \ref ported_sec 311 */ 312 int MutexP_delete_handle(pthread_mutex_t* pMutexHandle); 313 314 315 #else 316 317 /*! 318 \brief Creates a semaphore handle, using the driver porting layer of the core SDK. 319 320 \param pSemHandle - pointer to a memory structure that would contain the handle. 321 322 \return upon successful creation, the function shall return 0. 323 Otherwise, -1 shall be returned 324 325 \note belongs to \ref ported_sec 326 */ 327 int SemaphoreP_create_handle(SemaphoreP_Handle* pSemHandle); 328 329 330 /*! 331 \brief Deletes a semaphore handle, using the driver porting layer of the core SDK. 332 333 \param pSemHandle - pointer to a memory structure that would contain the handle. 334 335 \return The function shall return 0. 336 337 \note belongs to \ref ported_sec 338 */ 339 int SemaphoreP_delete_handle(SemaphoreP_Handle* pSemHandle); 340 341 342 /*! 343 \brief Post (signal) a semaphore handle, using the driver porting layer of the core SDK. 344 345 \param pSemHandle - pointer to a memory structure that would contain the handle. 346 347 \return The function shall return 0. 348 349 \note belongs to \ref ported_sec 350 */ 351 int SemaphoreP_post_handle(SemaphoreP_Handle* pSemHandle); 352 /*! 353 \brief Creates a mutex object handle, using the driver porting layer of the core SDK. 354 355 \param pMutexHandle - pointer to a memory structure that would contain the handle. 356 357 \return upon successful creation, the function shall return 0. 358 Otherwise, -1 shall be returned 359 360 \note belongs to \ref ported_sec 361 */ 362 int Mutex_create_handle(MutexP_Handle* pMutexHandle); 363 364 365 /*! 366 \brief Deletes a mutex object handle, using the driver porting layer of the core SDK. 367 368 \param pMutexHandle - pointer to a memory structure that would contain the handle. 369 370 \return the function shall return 0. 371 372 \note belongs to \ref ported_sec 373 */ 374 int MutexP_delete_handle(MutexP_Handle* pMutexHandle); 375 376 /*! 377 \brief Unlocks a mutex object. 378 379 \param pMutexHandle - pointer to a memory structure that contains the object. 380 381 \return upon successful unlocking, the function shall return 0. 382 383 \note belongs to \ref ported_sec 384 */ 385 int Mutex_unlock(MutexP_Handle pMutexHandle); 386 387 388 /*! 389 \brief Locks a mutex object. 390 391 \param pMutexHandle - pointer to a memory structure that contains the object. 392 393 \return upon successful locking, the function shall return 0. 394 395 \note belongs to \ref ported_sec 396 397 \warning The lock will block until the mutex is available. 398 */ 399 int Mutex_lock(MutexP_Handle pMutexHandle); 400 #endif 401 402 /*! 403 \brief Take a time stamp value. 404 405 \return 32-bit value of the systick counter. 406 407 \sa 408 409 \warning 410 */ 411 unsigned long TimerGetCurrentTimestamp(); 412 413 /*! 414 \brief 415 416 \return 417 418 \sa 419 420 \warning 421 */ 422 void NwpWaitForShutDownInd(); 423 424 425 #ifdef __cplusplus 426 } 427 #endif // __cplusplus 428 429 #endif 430 431