1 /****************************************************************************** 2 TORNADO AMC modules Software Development Kit (SDK). Rev 3A. 3 TI SYS/BIOS RTOS abstraction layer for TORNADO AMC embedded controllers. 4 (C) MicroLAB Systems, 2014-2015 5 6 7 File: This file contains TI SYS/BIOS RTOS abstraction layer definitions 8 ----- for TORNADO AMC embedded controllers, which is used for various 9 low-level drivers (LLD) and libraries that the application use. 10 11 12 Revision history: 13 ----------------- 14 rev.1A - 2014, initial release for TORNADO-A6678 board 15 rev.2A - 2015, totally redesigned SDK; 16 rev.3A - 2016, added support for TORNADO-A6678/FMC board rev.1A; 17 18 ******************************************************************************/ 19 20 21 /** 22 * @file TA66XX_OSAL.h 23 * 24 * @brief RTOS abstraction layer definitions 25 * 26 * This file contains TI SYS/BIOS RTOS abstraction layer (OSAL) definitions for 27 * TORNADO AMC embedded controllers, which is used for various 28 * low-level drivers (LLD) and libraries that the application use. 29 * 30 */ 31 32 33 #ifndef __TA66XX_OSAL_H__ // check for this file has been already included 34 #define __TA66XX_OSAL_H__ 1 35 36 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 43 44 //============================================================================= 45 //------------ Definitions ---------------------------------------------------- 46 //============================================================================= 47 /** @addtogroup TA66XX_OSAL_GENERAL OS abstraction layer (OSAL) general definitions 48 * @{ 49 */ 50 51 // Hardware semaphore defs 52 #define TA66XX_OSAL_CPPI_HW_SEM 1 /**< CPPI LLD hardware semaphore */ 53 #define TA66XX_OSAL_QMSS_HW_SEM 2 /**< QMSS LLD hardware semaphore */ 54 #define TA66XX_OSAL_SRIO_HW_SEM 3 /**< SRIO LLD hardware semaphore */ 55 #define TA66XX_OSAL_SPI_HW_SEM 4 /**< SPI driver hardware semaphore */ 56 57 /** Macro to define high-priority QMSS queue for accumulator (depends on DSP event ID and core number) */ 58 #define TA66XX_OSAL_set_qmss_queue_acc(eventid, core) (704 + (eventid - 48) * 8 + core) 59 60 // Interrupts and event IDs used by NIMU library (DSP core 0 is assumed to be used) 61 #define TA66XX_OSAL_ETHERNET_AMC_EVENTID 48 /**< Ethernet AMC port event - used by NIMU library */ 62 #define TA66XX_OSAL_ETHERNET_AMC_INTERRUPT 7 /**< Ethernet AMC port interrupt - used by NIMU library */ 63 /** QMSS queue for AMC Ethernet port accumulator (depends on TA66XX_OSAL_ETHERNET_AMC_EVENTID) */ 64 #define TA66XX_OSAL_ETHERNET_AMC_QMSS_QUEUE_ACC TA66XX_OSAL_set_qmss_queue_acc(TA66XX_OSAL_ETHERNET_AMC_EVENTID, 0) 65 #define TA66XX_OSAL_ETHERNET_PHY_EVENTID 49 /**< Ethernet PHY port event - used by NIMU library */ 66 #define TA66XX_OSAL_ETHERNET_PHY_INTERRUPT 8 /**< Ethernet PHY port interrupt - used by NIMU library */ 67 /** QMSS queue for PHY Ethernet port accumulator (depends on TA66XX_OSAL_ETHERNET_PHY_EVENTID) */ 68 #define TA66XX_OSAL_ETHERNET_PHY_QMSS_QUEUE_ACC TA66XX_OSAL_set_qmss_queue_acc(TA66XX_OSAL_ETHERNET_PHY_EVENTID, 0) 69 70 // Interrupts and event IDs used by SRIO (DSP core 0 is assumed to be used) 71 #define TA66XX_OSAL_SRIO_MESSAGES_EVENTID 50 /**< SRIO event ID used by messages (Type 9 and Type 11) */ 72 #define TA66XX_OSAL_SRIO_INTERRUPT 9 /**< SRIO interrupt */ 73 /** QMSS queue for SRIO accumulator (depends on TA66XX_OSAL_SRIO_MESSAGES_EVENTID) */ 74 #define TA66XX_OSAL_SRIO_QMSS_QUEUE_ACC TA66XX_OSAL_set_qmss_queue_acc(TA66XX_OSAL_SRIO_MESSAGES_EVENTID, 0) 75 #define TA66XX_OSAL_SRIO_DIO_EVENTID 20 /**< SRIO event ID used by DirectIO (INTDST(n + 16), n - core number) */ 76 /** @}*/ 77 //============================================================================= 78 79 80 81 //============================================================================= 82 //------------ Global variables ----------------------------------------------- 83 //============================================================================= 84 extern uint32_t qmssMallocCounter; 85 extern uint32_t qmssFreeCounter; 86 extern uint32_t cppiMallocCounter; 87 extern uint32_t cppiFreeCounter; 88 extern uint32_t srioMallocCounter; 89 extern uint32_t srioFreeCounter; 90 extern uint32_t srioDataBufferMallocCounter; 91 extern uint32_t srioDataBufferFreeCounter; 92 //============================================================================= 93 94 95 96 //============================================================================= 97 //============ T-AMC controllers OSAL functions declarations ================== 98 //============================================================================= 99 /** @addtogroup TA66XX_OSAL_FUNCTIONS TORNADO AMC OSAL functions 100 * @{ 101 */ 102 103 104 //============================================================================= 105 //============ QMSS LLD OSAL functions ======================================== 106 //============================================================================= 107 108 /*------------ Osal_qmssBeginMemAccess() function ------------------------*//** 109 * @brief Function is used to indicate that a block of memory is about to be 110 * accessed 111 * 112 * If the memory block is cached then this indicates that the application 113 * would need to ensure that the cache is updated with the data from the actual 114 * memory 115 * 116 * @param[in] ptr - address of memory block 117 * @param[in] size - size of memory block 118 * 119 * @return None 120 * 121 -----------------------------------------------------------------------------*/ 122 void Osal_qmssBeginMemAccess(void *ptr, uint32_t size); 123 124 125 /*------------ Osal_qmssEndMemAccess() function --------------------------*//** 126 * @brief Function is used to indicate that the block of memory has finished 127 * being accessed 128 * 129 * If the memory block is cached then the application would need to ensure that 130 * the contents of the cache are updated immediately to the actual memory. 131 * 132 * @param[in] ptr - address of memory block 133 * @param[in] size - size of memory block 134 * 135 * @return None 136 * 137 -----------------------------------------------------------------------------*/ 138 void Osal_qmssEndMemAccess(void *ptr, uint32_t size); 139 140 141 /*------------ Osal_qmssMalloc() function --------------------------------*//** 142 * @brief Function implements the memory allocation library function 143 * 144 * This function allocates a memory block of a given size specified by input 145 * parameter 'num_bytes'. 146 * 147 * @param[in] num_bytes - number of bytes to be allocated 148 * 149 * @return Allocated block address 150 * 151 -----------------------------------------------------------------------------*/ 152 Ptr Osal_qmssMalloc(uint32_t num_bytes); 153 154 155 /*------------ Osal_qmssFree() function ----------------------------------*//** 156 * @brief Function implements the memory free library function 157 * 158 * This function frees up memory allocated using Osal_qmssMalloc() 159 * function call. 160 * 161 * @param[in] dataPtr - pointer to the memory block to be cleaned up 162 * @param[in] num_bytes - size of the memory block to be cleaned up in bytes 163 * 164 * @return None 165 * 166 -----------------------------------------------------------------------------*/ 167 void Osal_qmssFree(Ptr dataPtr, uint32_t num_bytes); 168 169 170 /*------------ Osal_qmssCsEnter() function -------------------------------*//** 171 * @brief Function is used to enter a critical section 172 * 173 * Function protects against access from multiple cores and access from 174 * multiple threads on single core 175 * 176 * @return Handle used to lock critical section 177 * 178 -----------------------------------------------------------------------------*/ 179 void *Osal_qmssCsEnter(void); 180 181 182 /*------------ Osal_qmssCsExit() function --------------------------------*//** 183 * @brief Function is used to exit a critical section protected using 184 * Osal_qmssCsEnter() API. 185 * 186 * @param[in] CsHandle - handle for unlocking critical section 187 * 188 * @return None 189 * 190 -----------------------------------------------------------------------------*/ 191 void Osal_qmssCsExit(void *CsHandle); 192 193 //============================================================================= 194 195 196 197 //============================================================================= 198 //============ CPPI LLD OSAL functions ======================================== 199 //============================================================================= 200 201 /*------------ Osal_cppiBeginMemAccess() function ------------------------*//** 202 * @brief Function is used to indicate that a block of memory is about to be 203 * accessed 204 * 205 * If the memory block is cached then this indicates that the application 206 * would need to ensure that the cache is updated with the data from the actual 207 * memory 208 * 209 * @param[in] ptr - address of memory block 210 * @param[in] size - size of memory block 211 * 212 * @return None 213 * 214 -----------------------------------------------------------------------------*/ 215 void Osal_cppiBeginMemAccess(void *ptr, uint32_t size); 216 217 218 /*------------ Osal_cppiEndMemAccess() function --------------------------*//** 219 * @brief Function is used to indicate that the block of memory has finished 220 * being accessed 221 * 222 * If the memory block is cached then the application would need to ensure that 223 * the contents of the cache are updated immediately to the actual memory. 224 * 225 * @param[in] ptr - address of memory block 226 * @param[in] size - size of memory block 227 * 228 * @return None 229 * 230 -----------------------------------------------------------------------------*/ 231 void Osal_cppiEndMemAccess(void *ptr, uint32_t size); 232 233 234 /*------------ Osal_cppiMalloc() function --------------------------------*//** 235 * @brief Function implements the memory allocation library function 236 * 237 * This function allocates a memory block of a given size specified by input 238 * parameter 'num_bytes'. 239 * 240 * @param[in] num_bytes - number of bytes to be allocated 241 * 242 * @return Allocated block address 243 * 244 -----------------------------------------------------------------------------*/ 245 Ptr Osal_cppiMalloc(uint32_t num_bytes); 246 247 248 /*------------ Osal_cppiFree() function ----------------------------------*//** 249 * @brief Function implements the memory free library function 250 * 251 * This function frees up memory allocated using Osal_cppiMalloc() 252 * function call. 253 * 254 * @param[in] dataPtr - pointer to the memory block to be cleaned up 255 * @param[in] num_bytes - size of the memory block to be cleaned up in bytes 256 * 257 * @return None 258 * 259 -----------------------------------------------------------------------------*/ 260 void Osal_cppiFree(Ptr dataPtr, uint32_t num_bytes); 261 262 263 /*------------ Osal_cppiCsEnter() function -------------------------------*//** 264 * @brief Function is used to enter a critical section 265 * 266 * Function protects against access from multiple cores and access from 267 * multiple threads on single core 268 * 269 * @return Handle used to lock critical section 270 * 271 -----------------------------------------------------------------------------*/ 272 void *Osal_cppiCsEnter(void); 273 274 275 /*------------ Osal_cppiCsExit() function --------------------------------*//** 276 * @brief Function is used to exit a critical section protected using 277 * Osal_cppiCsEnter() API. 278 * 279 * @param[in] CsHandle - handle for unlocking critical section 280 * 281 * @return None 282 * 283 -----------------------------------------------------------------------------*/ 284 void Osal_cppiCsExit(void *CsHandle); 285 286 //============================================================================= 287 288 289 #ifdef __TA66XX_FUNCTIONS_INCLUDE_SRIO__ 290 291 292 //============================================================================= 293 //============ SRIO LLD OSAL functions ======================================== 294 //============================================================================= 295 296 /*------------ Osal_srioBeginMemAccess() function ------------------------*//** 297 * @brief Function is used to indicate that a block of memory is about to be 298 * accessed 299 * 300 * If the memory block is cached then this indicates that the application 301 * would need to ensure that the cache is updated with the data from the actual 302 * memory 303 * 304 * @param[in] ptr - address of memory block 305 * @param[in] size - size of memory block 306 * 307 * @return None 308 * 309 -----------------------------------------------------------------------------*/ 310 void Osal_srioBeginMemAccess(void *ptr, uint32_t size); 311 312 313 /*------------ Osal_srioEndMemAccess() function --------------------------*//** 314 * @brief Function is used to indicate that the block of memory has finished 315 * being accessed 316 * 317 * If the memory block is cached then the application would need to ensure that 318 * the contents of the cache are updated immediately to the actual memory. 319 * 320 * @param[in] ptr - address of memory block 321 * @param[in] size - size of memory block 322 * 323 * @return None 324 * 325 -----------------------------------------------------------------------------*/ 326 void Osal_srioEndMemAccess(void *ptr, uint32_t size); 327 328 329 /*------------ Osal_srioBeginDescriptorAccess() function -----------------*//** 330 * @brief Function is invoked by the SRIO LLD to indicate that a descriptor is 331 * being accessed. 332 * 333 * @param[in] drvHandle - driver instance for which descriptor is being 334 * accessed 335 * @param[in] ptr - pointer to the descriptor being accessed 336 * @param[in] descSize - size of the descriptor (valid only for driver managed 337 * configuration) 338 * 339 * @return None 340 * 341 -----------------------------------------------------------------------------*/ 342 void Osal_srioBeginDescriptorAccess(Srio_DrvHandle drvHandle, void *ptr, uint32_t descSize); 343 344 345 /*------------ Osal_srioEndDescriptorAccess() function -------------------*//** 346 * @brief Function is invoked by the SRIO LLD to indicate that a descriptor is 347 * finished being accessed. 348 * 349 * @param[in] drvHandle - driver instance for which descriptor is being 350 * accessed 351 * @param[in] ptr - pointer to the descriptor being accessed 352 * @param[in] descSize - size of the descriptor (valid only for driver managed 353 * configuration) 354 * 355 * @return None 356 * 357 -----------------------------------------------------------------------------*/ 358 void Osal_srioEndDescriptorAccess(Srio_DrvHandle drvHandle, void *ptr, uint32_t descSize); 359 360 361 /*------------ Osal_srioMalloc() function --------------------------------*//** 362 * @brief Function implements the memory allocation library function 363 * 364 * This function allocates a memory block of a given size specified by input 365 * parameter 'num_bytes'. 366 * 367 * @param[in] num_bytes - number of bytes to be allocated 368 * 369 * @return Allocated block address 370 * 371 -----------------------------------------------------------------------------*/ 372 Ptr Osal_srioMalloc(uint32_t num_bytes); 373 374 375 /*------------ Osal_srioFree() function ----------------------------------*//** 376 * @brief Function implements the memory free library function 377 * 378 * This function frees up memory allocated using Osal_srioMalloc() 379 * function call. 380 * 381 * @param[in] dataPtr - pointer to the memory block to be cleaned up 382 * @param[in] num_bytes - size of the memory block to be cleaned up in bytes 383 * 384 * @return None 385 * 386 -----------------------------------------------------------------------------*/ 387 void Osal_srioFree(Ptr dataPtr, uint32_t num_bytes); 388 389 390 /*------------ Osal_dataBufferInitMemory() function ----------------------*//** 391 * @brief Function is used to allocate a block of memory for all the data 392 * buffer operations. This function is called by the application. 393 * 394 * @param[in] dataBufferSize - size of each data buffer 395 * 396 * @return Error code 397 * 398 -----------------------------------------------------------------------------*/ 399 int32_t Osal_dataBufferInitMemory(uint32_t dataBufferSize); 400 401 402 /*------------ Osal_srioDataBufferMalloc() function ----------------------*//** 403 * @brief Function is used to allocate a data buffer of the specified size. 404 * Data buffers should always be allocated from the global address space. 405 * 406 * @param[in] numBytes - number of bytes to be allocated 407 * 408 * @return Allocated block address 409 * 410 -----------------------------------------------------------------------------*/ 411 void *Osal_srioDataBufferMalloc(uint32_t numBytes); 412 413 414 /*------------ Osal_srioDataBufferFree() function ------------------------*//** 415 * @brief Function is used to clean up a previously allocated data buffer 416 * block. All data buffers are in the global address space. 417 * 418 * @param[in] ptr - pointer to the memory block to be cleaned up 419 * @param[in] numBytes - size of the memory block to be cleaned up in bytes 420 * 421 * @return None 422 * 423 -----------------------------------------------------------------------------*/ 424 void Osal_srioDataBufferFree(void *ptr, uint32_t numBytes); 425 426 427 /*------------ Osal_srioLog() function -----------------------------------*//** 428 * @brief Function is used to log the messages from SRIO LLD on the console. 429 * 430 * @param[in] fmt - formatted string 431 * 432 * @return None 433 * 434 -----------------------------------------------------------------------------*/ 435 void Osal_srioLog(String fmt, ... ); 436 437 438 /*------------ Osal_srioCreateSem() function -----------------------------*//** 439 * @brief Function is used to create a critical section. 440 * 441 * @return Semaphore handle created 442 * 443 -----------------------------------------------------------------------------*/ 444 void *Osal_srioCreateSem(void); 445 446 447 /*------------ Osal_srioDeleteSem() function -----------------------------*//** 448 * @brief Function is used to delete a critical section. 449 * 450 * @param[in] semHandle - semaphore handle to be deleted 451 * 452 * @return None 453 * 454 -----------------------------------------------------------------------------*/ 455 void Osal_srioDeleteSem(void *semHandle); 456 457 458 /*------------ Osal_srioPendSem() function -------------------------------*//** 459 * @brief Function is used to pend on a semaphore 460 * 461 * @param[in] semHandle - semaphore handle on which the API will pend 462 * 463 * @return None 464 * 465 -----------------------------------------------------------------------------*/ 466 void Osal_srioPendSem(void *semHandle); 467 468 469 /*------------ Osal_srioPostSem() function -------------------------------*//** 470 * @brief Function is used to post a semaphore 471 * 472 * @param[in] semHandle - semaphore handle which will be posted 473 * 474 * @return None 475 * 476 -----------------------------------------------------------------------------*/ 477 void Osal_srioPostSem(void *semHandle); 478 479 480 /*------------ Osal_srioEnterMultipleCoreCriticalSection() function ------*//** 481 * @brief Function is used to protect the driver shared resources across 482 * multiple cores. 483 * 484 * @return Handle used to lock critical section 485 * 486 -----------------------------------------------------------------------------*/ 487 void *Osal_srioEnterMultipleCoreCriticalSection(void); 488 489 490 /*------------ Osal_srioExitMultipleCoreCriticalSection() function -------*//** 491 * @brief Function is called to end the critical section which was protecting 492 * shared resources from access across multiple cores. 493 * 494 * @param[in] critSectHandle - handle for unlocking critical section 495 * 496 * @return None 497 * 498 -----------------------------------------------------------------------------*/ 499 void Osal_srioExitMultipleCoreCriticalSection(void *critSectHandle); 500 501 502 /*------------ Osal_srioEnterSingleCoreCriticalSection() function --------*//** 503 * @brief Function is used to provide critical section to prevent access of 504 * shared resources from single core and multiple threads. 505 * 506 * @param[in] drvHandle - driver handle which needs critical section to 507 * protect its resources 508 * 509 * @return Handle used to lock critical section 510 * 511 -----------------------------------------------------------------------------*/ 512 void *Osal_srioEnterSingleCoreCriticalSection(Srio_DrvHandle drvHandle); 513 514 515 /*------------ Osal_srioExitSingleCoreCriticalSection() function ---------*//** 516 * @brief Function is called to end the critical section access of shared 517 * resources from single cores. 518 * 519 * @param[in] drvHandle - driver handle which needs critical section to 520 * protect its resources 521 * @param[in] critSectHandle - critical handle retreived by 522 * Osal_srioEnterSingleCoreCriticalSection() function call 523 * 524 * @return None 525 * 526 -----------------------------------------------------------------------------*/ 527 void Osal_srioExitSingleCoreCriticalSection(Srio_DrvHandle drvHandle, void *critSectHandle); 528 529 //============================================================================= 530 531 532 #endif /* __TA66XX_FUNCTIONS_INCLUDE_SRIO__ */ 533 534 535 //============================================================================= 536 //============ NIMU LLD OSAL functions ======================================== 537 //============================================================================= 538 539 /*------------ Osal_nimuMalloc() function --------------------------------*//** 540 * @brief Function implements the memory allocate function for the NIMU 541 * library. 542 * 543 * This function allocates a memory block of a given size specified by input 544 * parameter 'num_bytes'. 545 * 546 * @param[in] num_bytes - number of bytes to be allocated 547 * @param[in] alignment - alignment of allocated memory block in bytes 548 * 549 * @return Allocated block address 550 * 551 -----------------------------------------------------------------------------*/ 552 Ptr Osal_nimuMalloc(uint32_t num_bytes, uint32_t alignment); 553 554 555 /*------------ Osal_nimuFree() function ----------------------------------*//** 556 * @brief Function implements the memory free function for the NIMU library. 557 * 558 * This function frees up memory allocated using Osal_nimuMalloc() 559 * function call. 560 * 561 * @param[in] dataPtr - pointer to the memory block to be cleaned up 562 * @param[in] num_bytes - size of the memory block to be cleaned up in bytes 563 * 564 * @return None 565 * 566 -----------------------------------------------------------------------------*/ 567 void Osal_nimuFree(Ptr dataPtr, uint32_t num_bytes); 568 569 //============================================================================= 570 571 572 573 //============================================================================= 574 //============ PASS LLD OSAL functions ======================================== 575 //============================================================================= 576 577 578 /*------------ Osal_paBeginMemAccess() function --------------------------*//** 579 * @brief Function is used to indicate that a block of memory is about to be 580 * accessed 581 * 582 * If the memory block is cached then this indicates that the application 583 * would need to ensure that the cache is updated with the data from the actual 584 * memory 585 * 586 * @param[in] addr - address of memory block 587 * @param[in] size - size of memory block 588 * 589 * @return None 590 * 591 -----------------------------------------------------------------------------*/ 592 void Osal_paBeginMemAccess(Ptr addr, uint32_t size); 593 594 595 /*------------ Osal_paEndMemAccess() function ----------------------------*//** 596 * @brief Function is used to indicate that the block of memory has finished 597 * being accessed 598 * 599 * If the memory block is cached then the application would need to ensure that 600 * the contents of the cache are updated immediately to the actual memory. 601 * 602 * @param[in] addr - address of memory block 603 * @param[in] size - size of memory block 604 * 605 * @return None 606 * 607 -----------------------------------------------------------------------------*/ 608 void Osal_paEndMemAccess(Ptr addr, uint32_t size); 609 610 611 /*------------ Osal_paMtCsEnter() function -------------------------------*//** 612 * @brief Function is used to enter a critical section 613 * 614 * Function protects against access from multiple cores and access from 615 * multiple threads on single core 616 * 617 * @param[out] key - pointer to a variable to receive a handle for unlocking 618 * critical section 619 620 * @return None 621 * 622 -----------------------------------------------------------------------------*/ 623 void Osal_paMtCsEnter(uint32_t *key); 624 625 626 /*------------ Osal_paMtCsExit() function --------------------------------*//** 627 * @brief Function is used to exit a critical section protected using 628 * Osal_paMtCsEnter() API. 629 * 630 * @param[in] key - handle for unlocking critical section 631 * 632 * @return None 633 * 634 -----------------------------------------------------------------------------*/ 635 void Osal_paMtCsExit(uint32_t key); 636 637 /** @}*/ 638 //============================================================================= 639 640 641 642 #ifdef __cplusplus 643 } 644 #endif 645 646 647 648 //============================================================================= 649 #endif /* __TA66XX_OSAL_H__ */ 650