osapi.c revision 653850f71f9caaa41af19cadbab24bb5e655daf4
1/* 2 * osapi.c 3 * 4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved. 5 * All rights reserved. 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 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name Texas Instruments nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 35/* 36 * src/osapi.c 37 * 38 */ 39#include "tidef.h" 40#include "arch_ti.h" 41 42#include <linux/stddef.h> 43#include <linux/string.h> 44#include <linux/time.h> 45#include <linux/timer.h> 46#include <linux/module.h> 47#include <linux/kernel.h> 48#include <linux/netdevice.h> 49#include <linux/completion.h> 50#include <linux/etherdevice.h> 51#include <linux/vmalloc.h> 52#include <linux/string.h> 53#include <linux/delay.h> 54#include <linux/time.h> 55#include <linux/list.h> 56#include <stdarg.h> 57#include <asm/io.h> 58#include "RxBuf_linux.h" 59 60/*#include "debug_module.h"*/ 61#include "host_platform.h" 62#include "WlanDrvIf.h" 63#include "bmtrace_api.h" 64#include "TI_IPC_Api.h" 65#include "802_11Defs.h" 66#include "osApi.h" 67#include "txMgmtQueue_Api.h" 68#include "EvHandler.h" 69 70#ifdef ESTA_TIMER_DEBUG 71#define esta_timer_log(fmt,args...) printk(fmt, ## args) 72#else 73#define esta_timer_log(fmt,args...) 74#endif 75 76#define FRAG_SIZE 200 77 78typedef struct timer_list TOsTimer; 79 80TI_BOOL bRedirectOutputToLogger = TI_FALSE; 81TI_BOOL use_debug_module = TI_FALSE; 82 83/* linux/irq.h declerations */ 84extern void disable_irq(unsigned int); 85extern void enable_irq(unsigned int); 86 87 88/**************************************************************************************** 89 * * 90 * OS Report API * 91 * * 92 ****************************************************************************************/ 93static void SendLoggerData (TI_HANDLE OsContext, TI_UINT8 *pMsg, TI_UINT16 len) 94{ 95 TWlanDrvIfObj *drv = (TWlanDrvIfObj *)OsContext; 96 97 if (len > 0) 98 { 99 EvHandlerSendEvent(drv->tCommon.hEvHandler, IPC_EVENT_LOGGER, pMsg, len); 100 } 101} 102 103void os_setDebugOutputToLogger(TI_BOOL value) 104{ 105 bRedirectOutputToLogger = value; 106} 107/**************************************************************************************** 108 * os_setDebugMode() 109 **************************************************************************************** 110DESCRIPTION: Set the Debug Mode 111 112INPUT: 113 114RETURN: None 115 116NOTES: 117*****************************************************************************************/ 118void os_setDebugMode(TI_BOOL enable) 119{ 120 use_debug_module = enable; 121} 122 123 124/**************************************************************************************** 125 * os_printf() 126 **************************************************************************************** 127DESCRIPTION: Print formatted output. 128 129INPUT: format - Specifies the string, to be printed 130 131RETURN: None 132 133NOTES: 134*****************************************************************************************/ 135void os_printf(const char *format ,...) 136{ 137 static int from_new_line = 1; /* Used to save the last message EOL */ 138 va_list ap; 139 static char msg[MAX_MESSAGE_SIZE]; 140 char *p_msg = msg; /* Pointer to the message */ 141 TI_UINT16 message_len; 142 TI_UINT32 sec = 0; 143 TI_UINT32 uSec = 0; 144 os_memoryZero(NULL,msg, MAX_MESSAGE_SIZE); 145 146 /* Format the message and keep the message length */ 147 va_start(ap,format); 148 message_len = vsnprintf(&msg[0], sizeof(msg) -1 , format, ap); 149 if( from_new_line ) 150 { 151 if (msg[1] == '$') 152 { 153 p_msg += 4; 154 } 155 156 sec = os_timeStampUs(NULL); 157 uSec = sec % MICROSECOND_IN_SECONDS; 158 sec /= MICROSECOND_IN_SECONDS; 159 160 printk(KERN_INFO DRIVER_NAME ": %d.%06d: %s",sec,uSec,p_msg); 161 } 162 else 163 { 164 printk(&msg[0]); 165 } 166 167 from_new_line = ( msg[message_len] == '\n' ); 168 va_end(ap); 169} 170 171/**************************************************************************************** 172 * * 173 * OS TIMER API * 174 * * 175 ****************************************************************************************/ 176 177/**************************************************************************************** 178 * os_timerCreate() 179 **************************************************************************************** 180DESCRIPTION: This function creates and initializes an OS timer object associated with a 181 caller's pRoutine function. 182 183ARGUMENTS: OsContext - The OS handle 184 pRoutine - The user callback function 185 hFuncHandle - The user callback handle 186 187RETURN: A handle of the created OS timer. 188 189NOTES: 1) The user's callback is called directly from OS timer context when expired. 190 2) In some OSs, it may be needed to use an intermediate callback in the 191 osapi layer (use os_timerHandlr for that). 192 193*****************************************************************************************/ 194TI_HANDLE os_timerCreate (TI_HANDLE OsContext, fTimerFunction pRoutine, TI_HANDLE hFuncHandle) 195{ 196 TOsTimer *pOsTimer = os_memoryAlloc (OsContext, sizeof(TOsTimer)); 197 198 init_timer (pOsTimer); 199 pOsTimer->function = (void *)pRoutine; 200 pOsTimer->data = (int)hFuncHandle; 201 202 return (TI_HANDLE)pOsTimer; 203} 204 205 206/**************************************************************************************** 207 * os_timerDestroy() 208 **************************************************************************************** 209DESCRIPTION: This function destroys the OS timer object. 210 211ARGUMENTS: 212 213RETURN: 214 215NOTES: 216*****************************************************************************************/ 217void os_timerDestroy (TI_HANDLE OsContext, TI_HANDLE TimerHandle) 218{ 219 os_timerStop (OsContext, TimerHandle); 220 os_memoryFree (OsContext, TimerHandle, sizeof(TOsTimer)); 221} 222 223 224/**************************************************************************************** 225 * os_timerStart() 226 **************************************************************************************** 227DESCRIPTION: This function start the timer object. 228 229ARGUMENTS: 230 231RETURN: 232 233NOTES: 234*****************************************************************************************/ 235void os_timerStart (TI_HANDLE OsContext, TI_HANDLE TimerHandle, TI_UINT32 DelayMs) 236{ 237 TI_UINT32 jiffie_cnt = msecs_to_jiffies (DelayMs); 238 239 mod_timer ((TOsTimer *)TimerHandle, jiffies + jiffie_cnt); 240} 241 242 243/**************************************************************************************** 244 * os_stopTimer() 245 **************************************************************************************** 246DESCRIPTION: This function stop the timer object. 247 248ARGUMENTS: 249 250RETURN: 251 252NOTES: 253*****************************************************************************************/ 254void os_timerStop (TI_HANDLE OsContext, TI_HANDLE TimerHandle) 255{ 256 del_timer_sync((TOsTimer *)TimerHandle); 257} 258 259 260/**************************************************************************************** 261 * os_periodicIntrTimerStart() 262 **************************************************************************************** 263DESCRIPTION: This function starts the periodic interrupt mechanism. This mode is used 264 when interrupts that usually received from the Fw is now masked, and we are 265 checking for any need of Fw handling in time periods. 266 267ARGUMENTS: 268 269RETURN: 270 271NOTES: Power level of the CHIP should be always awake in this mode (no ELP) 272*****************************************************************************************/ 273#ifdef PRIODIC_INTERRUPT 274void os_periodicIntrTimerStart (TI_HANDLE OsContext) 275{ 276 TWlanDrvIfObj *drv = (TWlanDrvIfObj *)OsContext; 277 278 mod_timer (drv->hPollTimer, jiffies + TIWLAN_IRQ_POLL_INTERVAL); 279} 280#endif 281 282 283/**************************************************************************************** 284 * os_timeStampMs() 285 **************************************************************************************** 286DESCRIPTION: This function returns the number of milliseconds that have elapsed since 287 the system was booted. 288 289ARGUMENTS: OsContext - our adapter context. 290 291RETURN: 292 293NOTES: 294*****************************************************************************************/ 295TI_UINT32 os_timeStampMs (TI_HANDLE OsContext) 296{ 297 struct timeval tv; 298 do_gettimeofday(&tv); 299 return tv.tv_sec*1000 + tv.tv_usec/1000; 300} 301 302 303/**************************************************************************************** 304 * os_timeStampUs() 305 **************************************************************************************** 306DESCRIPTION: This function returns the number of microseconds that have elapsed since 307 the system was booted. 308 309ARGUMENTS: OsContext - our adapter context. 310 Note that sometimes this function will be called with NULL(!!!) as argument! 311 312RETURN: 313 314NOTES: 315*****************************************************************************************/ 316TI_UINT32 os_timeStampUs (TI_HANDLE OsContext) 317{ 318 struct timeval tv; 319 do_gettimeofday(&tv); 320 return tv.tv_sec*1000000 + tv.tv_usec; 321} 322 323 324/**************************************************************************************** 325 * os_StalluSec() 326 **************************************************************************************** 327DESCRIPTION: This function make delay in microseconds. 328 329ARGUMENTS: OsContext - our adapter context. 330 uSec - delay time in microseconds 331 332RETURN: 333 334NOTES: 335*****************************************************************************************/ 336void os_StalluSec (TI_HANDLE OsContext, TI_UINT32 uSec) 337{ 338 udelay (uSec); 339} 340 341 342/**************************************************************************************** 343 * * 344 * Protection services API * 345 * * 346 **************************************************************************************** 347 * OS protection is implemented as spin_lock_irqsave and spin_unlock_irqrestore * 348 ****************************************************************************************/ 349 350 351/**************************************************************************************** 352 * os_protectCreate() 353 **************************************************************************************** 354DESCRIPTION: 355 356ARGUMENTS: OsContext - our adapter context. 357 358RETURN: A handle of the created mutex/spinlock. 359 TI_HANDLE_INVALID if there is insufficient memory available or problems 360 initializing the mutex 361 362NOTES: 363*****************************************************************************************/ 364TI_HANDLE os_protectCreate (TI_HANDLE OsContext) 365{ 366 return NULL; 367} 368 369 370/**************************************************************************************** 371 * os_protectDestroy() 372 **************************************************************************************** 373DESCRIPTION: 374 375ARGUMENTS: OsContext - our adapter context. 376 377RETURN: None - This had better work since there is not a return value to the user 378 379NOTES: 380*****************************************************************************************/ 381void os_protectDestroy (TI_HANDLE OsContext, TI_HANDLE ProtectCtx) 382{ 383} 384 385 386/**************************************************************************************** 387 * os_protectLock() 388 **************************************************************************************** 389DESCRIPTION: 390 391ARGUMENTS: OsContext - our adapter context. 392 393RETURN: None - This had better work since there is not a return value to the user 394 395NOTES: 396*****************************************************************************************/ 397void os_protectLock (TI_HANDLE OsContext, TI_HANDLE ProtectContext) 398{ 399 TWlanDrvIfObj *drv = (TWlanDrvIfObj *)OsContext; 400 401 spin_lock_irqsave (&drv->lock, drv->flags); 402} 403 404 405/**************************************************************************************** 406 * os_protectUnlock() 407 **************************************************************************************** 408DESCRIPTION: 409 410ARGUMENTS: OsContext - our adapter context. 411 412RETURN: None - This had better work since there is not a return value to the user 413 414NOTES: 415*****************************************************************************************/ 416void os_protectUnlock (TI_HANDLE OsContext, TI_HANDLE ProtectContext) 417{ 418 TWlanDrvIfObj *drv = (TWlanDrvIfObj *)OsContext; 419 420 spin_unlock_irqrestore (&drv->lock, drv->flags); 421} 422/**************************************************************************************** 423 * os_receivePacket() 424 **************************************************************************************** 425DESCRIPTION: 426 427ARGUMENTS: 428 429RETURN: 430 431NOTES: 432*****************************************************************************************/ 433TI_BOOL os_receivePacket (TI_HANDLE OsContext, void* pPacket, TI_UINT16 Length) 434{ 435 TWlanDrvIfObj *drv = (TWlanDrvIfObj *)OsContext; 436 unsigned char *pdata = (unsigned char *)((TI_UINT32)pPacket & ~(TI_UINT32)0x3); 437 rx_head_t *rx_head = (rx_head_t *)(pdata - WSPI_PAD_BYTES - RX_HEAD_LEN_ALIGNED); 438 struct sk_buff *skb = rx_head->skb; 439 440#ifdef TI_DBG 441 if ((TI_UINT32)pPacket & 0x3) 442 { 443 if ((TI_UINT32)pPacket - (TI_UINT32)skb->data != 2) 444 { 445 printk("os_receivePacket() address error skb=0x%x skb->data=0x%x pPacket=0x%x !!!\n",(int)skb, (int)skb->data, (int)pPacket); 446 } 447 } 448 else 449 { 450 if ((TI_UINT32)skb->data != (TI_UINT32)pPacket) 451 { 452 printk("os_receivePacket() address error skb=0x%x skb->data=0x%x pPacket=0x%x !!!\n",(int)skb, (int)skb->data, (int)pPacket); 453 } 454 } 455 if (Length != RX_ETH_PKT_LEN(pPacket)) 456 { 457 printk("os_receivePacket() Length=%d != RX_ETH_PKT_LEN(pPacket)=%d!!!\n",(int)Length, RX_ETH_PKT_LEN(pPacket)); 458 } 459 460#endif 461/* 462 printk("-->> os_receivePacket() pPacket=0x%x Length=%d skb=0x%x skb->data=0x%x skb->head=0x%x skb->len=%d\n", 463 (int)pPacket, (int)Length, (int)skb, (int)skb->data, (int)skb->head, (int)skb->len); 464*/ 465 skb->data = RX_ETH_PKT_DATA(pPacket); 466 skb_put(skb, RX_ETH_PKT_LEN(pPacket)); 467/* 468 printk("-->> os_receivePacket() skb=0x%x skb->data=0x%x skb->head=0x%x skb->len=%d\n", 469 (int)skb, (int)skb->data, (int)skb->head, (int)skb->len); 470*/ 471 ti_nodprintf(TIWLAN_LOG_INFO, "os_receivePacket - Received EAPOL len-%d\n", WBUF_LEN(pWbuf)); 472 473 skb->dev = drv->netdev; 474 skb->protocol = eth_type_trans(skb, drv->netdev); 475 skb->ip_summed = CHECKSUM_NONE; 476 477 drv->stats.rx_packets++; 478 drv->stats.rx_bytes += skb->len; 479 480 /* Send the skb to the TCP stack. 481 * it responsibly of the Linux kernel to free the skb 482 */ 483 { 484 CL_TRACE_START_L1(); 485 486 os_protectLock(OsContext, NULL); 487 drv->wl_packet = 1; 488 os_protectUnlock(OsContext, NULL); 489 490 netif_rx_ni(skb); 491 492 /* Note: Don't change this trace (needed to exclude OS processing from Rx CPU utilization) */ 493 CL_TRACE_END_L1("tiwlan_drv.ko", "OS", "RX", ""); 494 } 495 496 return TI_TRUE; 497} 498 499/*----------------------------------------------------------------------------- 500 501Routine Name: os_timerHandlr 502 503Routine Description: 504 505 Just a place holder for timer expiration handling in other OSs. 506 In Linux, user callback is called directly on OS timer expiry. 507 508Arguments: parm - timer object handle 509 510Return Value: None. 511 512Notes: 513 514-----------------------------------------------------------------------------*/ 515void os_timerHandlr(unsigned long parm) 516{ 517 /* Not needed in Linux (user callback is called directly on OS timer expiry). */ 518} 519 520 521/*----------------------------------------------------------------------------- 522Routine Name: os_connectionStatus 523 524Routine Description: 525 526The eSTA-DK will call this API so the OS stack is aware that the 527WLAN layer is ready to function. 528 529Arguments: 530cStatus = 1; WLAN in ready for network packets 531cStatus = 0; WLAN in not ready for network packets 532 533Return Value: None 534-----------------------------------------------------------------------------*/ 535TI_INT32 os_IndicateEvent (TI_HANDLE OsContext, IPC_EV_DATA* pData) 536{ 537 IPC_EVENT_PARAMS *pInParam = &pData->EvParams; 538 TWlanDrvIfObj *drv = (TWlanDrvIfObj *)OsContext; 539 /*TI_UINT8 AuthBuf[sizeof(TI_UINT32) + sizeof(OS_802_11_AUTHENTICATION_REQUEST)];*/ 540 541 ti_nodprintf(TIWLAN_LOG_INFO, "\n os_ConnectionStatus Event 0x%08x \n", CsStatus->Event); 542 543 switch(pInParam->uEventType) 544 { 545 case IPC_EVENT_ASSOCIATED: 546 if (drv->netdev != NULL) 547 netif_carrier_on(drv->netdev); 548 break; 549 550 case IPC_EVENT_DISASSOCIATED: 551 if (drv->netdev != NULL) 552 netif_carrier_off(drv->netdev); 553 break; 554 555 case IPC_EVENT_LINK_SPEED: 556 drv->tCommon.uLinkSpeed = (*(TI_UINT32*)pData->uBuffer * 10000) / 2; 557 ti_nodprintf(TIWLAN_LOG_INFO, "\n Link Speed = 0x%08x \n",drv->tCommon.uLinkSpeed); 558 break; 559 } 560 561 return TI_OK; 562} 563 564 565 566/******************************************************************************/ 567 568void os_disableIrq (TI_HANDLE OsContext) 569{ 570 TWlanDrvIfObj *drv = (TWlanDrvIfObj *)OsContext; 571 disable_irq (drv->irq); 572} 573 574void os_enableIrq (TI_HANDLE OsContext) 575{ 576 TWlanDrvIfObj *drv = (TWlanDrvIfObj *)OsContext; 577 enable_irq (drv->irq); 578} 579 580/*----------------------------------------------------------------------------- 581Routine Name: os_InterruptServiced 582 583Routine Description: Called when IRQ line is not asserted any more 584 (i.e. we can enable IRQ in Level sensitive platform) 585 586Arguments: OsContext - handle to OS context 587 588Return Value: none 589-----------------------------------------------------------------------------*/ 590void os_InterruptServiced (TI_HANDLE OsContext) 591{ 592 /* To be implemented with Level IRQ */ 593} 594 595/*----------------------------------------------------------------------------- 596Routine Name: os_wake_lock_timeout 597 598Routine Description: Called to prevent system from suspend for some time 599 600Arguments: OsContext - handle to OS context 601 602Return Value: packet counter 603-----------------------------------------------------------------------------*/ 604int os_wake_lock_timeout (TI_HANDLE OsContext) 605{ 606 TWlanDrvIfObj *drv = (TWlanDrvIfObj *)OsContext; 607 int ret = 0; 608 609 os_protectLock(OsContext, NULL); 610 if (drv) { 611 ret = drv->wl_packet; 612 if (drv->wl_packet) { 613 drv->wl_packet = 0; 614#ifdef CONFIG_HAS_WAKELOCK 615 wake_lock_timeout(&drv->wl_rxwake, (HZ >> 1)); 616#endif 617 } 618 } 619 os_protectUnlock(OsContext, NULL); 620 /* printk("%s: %d\n", __func__, ret); */ 621 return ret; 622} 623 624/*----------------------------------------------------------------------------- 625Routine Name: os_wake_lock 626 627Routine Description: Called to prevent system from suspend 628 629Arguments: OsContext - handle to OS context 630 631Return Value: wake_lock counter 632-----------------------------------------------------------------------------*/ 633int os_wake_lock (TI_HANDLE OsContext) 634{ 635 TWlanDrvIfObj *drv = (TWlanDrvIfObj *)OsContext; 636 int ret = 0; 637 638 os_protectLock(OsContext, NULL); 639 if (drv) { 640 if (drv->wl_count == 0) { 641#ifdef CONFIG_HAS_WAKELOCK 642 wake_lock(&drv->wl_wifi); 643#endif 644 } 645 drv->wl_count++; 646 ret = drv->wl_count; 647 } 648 os_protectUnlock(OsContext, NULL); 649 /* printk("%s: %d\n", __func__, ret); */ 650 return ret; 651} 652 653/*----------------------------------------------------------------------------- 654Routine Name: os_wake_unlock 655 656Routine Description: Called to allow system to suspend 657 658Arguments: OsContext - handle to OS context 659 660Return Value: wkae_lock counter 661-----------------------------------------------------------------------------*/ 662int os_wake_unlock (TI_HANDLE OsContext) 663{ 664 TWlanDrvIfObj *drv = (TWlanDrvIfObj *)OsContext; 665 int ret = 0; 666 667 os_protectLock(OsContext, NULL); 668 if (drv) { 669 if (drv->wl_count) { 670 drv->wl_count--; 671 if (!drv->wl_count) { 672#ifdef CONFIG_HAS_WAKELOCK 673 wake_unlock(&drv->wl_wifi); 674#endif 675 } 676 } 677 ret = drv->wl_count; 678 } 679 os_protectUnlock(OsContext, NULL); 680 /* printk("%s: %d\n", __func__, ret); */ 681 return ret; 682} 683 684/*----------------------------------------------------------------------------- 685Routine Name: os_RequestSchedule 686 687Routine Description: 688 689Arguments: 690 691Return Value: TI_OK 692-----------------------------------------------------------------------------*/ 693int os_RequestSchedule (TI_HANDLE OsContext) 694{ 695 TWlanDrvIfObj *drv = (TWlanDrvIfObj *)OsContext; 696 697 /* Note: The performance trace below doesn't inclose the schedule 698 * itself because the rescheduling can occur immediately and call 699 * os_RequestSchedule again which will confuse the trace tools */ 700 CL_TRACE_START_L3(); 701 CL_TRACE_END_L3("tiwlan_drv.ko", "OS", "TASK", ""); 702 703 os_wake_lock(drv); 704 if( !queue_work(drv->tiwlan_wq, &drv->tWork) ) { 705 os_wake_unlock(drv); 706 return TI_NOK; 707 } 708 709 return TI_OK; 710} 711 712 713/*----------------------------------------------------------------------------- 714Routine Name: os_SignalObjectCreate 715 716Routine Description: 717 718Arguments: 719 720Return Value: TI_OK 721-----------------------------------------------------------------------------*/ 722void *os_SignalObjectCreate (TI_HANDLE OsContext) 723{ 724 struct completion *myPtr; 725 myPtr = os_memoryAlloc(OsContext, sizeof(struct completion)); 726 init_completion (myPtr); 727 return (myPtr); 728} 729 730 731/*----------------------------------------------------------------------------- 732Routine Name: os_SignalObjectWait 733 734Routine Description: 735 736Arguments: 737 738Return Value: TI_OK 739-----------------------------------------------------------------------------*/ 740int os_SignalObjectWait (TI_HANDLE OsContext, void *signalObject) 741{ 742 wait_for_completion ((struct completion *)signalObject); 743 return TI_OK; 744} 745 746 747/*----------------------------------------------------------------------------- 748Routine Name: os_SignalObjectSet 749 750Routine Description: 751 752Arguments: 753 754Return Value: TI_OK 755-----------------------------------------------------------------------------*/ 756int os_SignalObjectSet (TI_HANDLE OsContext, void *signalObject) 757{ 758 complete ((struct completion *)signalObject); 759 return TI_OK; 760} 761 762 763/*----------------------------------------------------------------------------- 764Routine Name: os_SignalObjectFree 765 766Routine Description: 767 768Arguments: 769 770Return Value: TI_OK 771-----------------------------------------------------------------------------*/ 772int os_SignalObjectFree (TI_HANDLE OsContext, void *signalObject) 773{ 774 os_memoryFree(OsContext, signalObject, sizeof(struct completion)); 775 return TI_OK; 776} 777 778 779/** 780 * \fn os_Trace 781 * \brief Prepare and send trace message to the logger. 782 * 783 * \param OsContext - The OS handle 784 * \param uLevel - Severity level of the trace message 785 * \param uFileId - Source file ID of the trace message 786 * \param uLineNum - Line number of the trace message 787 * \param uParamsNum - Number of parameters in the trace message 788 * \param ... - The trace message parameters 789 * 790 * \return void 791 */ 792void os_Trace (TI_HANDLE OsContext, TI_UINT32 uLevel, TI_UINT32 uFileId, TI_UINT32 uLineNum, TI_UINT32 uParamsNum, ...) 793{ 794 TI_UINT32 index; 795 TI_UINT32 uParam; 796 TI_UINT32 uMaxParamValue = 0; 797 TI_UINT32 uMsgLen = TRACE_MSG_MIN_LENGTH; 798 TI_UINT8 aMsg[TRACE_MSG_MAX_LENGTH] = {0}; 799 TTraceMsg *pMsgHdr = (TTraceMsg *)&aMsg[0]; 800 TI_UINT8 *pMsgData = &aMsg[0] + sizeof(TTraceMsg); 801 va_list list; 802 803 if (!bRedirectOutputToLogger) 804 { 805 return; 806 } 807 808 if (uParamsNum > TRACE_MSG_MAX_PARAMS) 809 { 810 uParamsNum = TRACE_MSG_MAX_PARAMS; 811 } 812 813 /* sync on the parameters */ 814 va_start(list, uParamsNum); 815 816 /* find the longest parameter */ 817 for (index = 0; index < uParamsNum; index++) 818 { 819 /* get parameter from the stack */ 820 uParam = va_arg (list, TI_UINT32); 821 822 /* save the longest parameter at variable 'uMaxParamValue' */ 823 if (uParam > uMaxParamValue) 824 { 825 uMaxParamValue = uParam; 826 } 827 828 /* 32 bit parameter is the longest possible - get out of the loop */ 829 if (uMaxParamValue > UINT16_MAX_VAL) 830 { 831 break; 832 } 833 } 834 835 /* Set msg length and format according to the biggest parameter value (8/16/32 bits) */ 836 if (uMaxParamValue > UINT16_MAX_VAL) 837 { 838 pMsgHdr->uFormat = TRACE_FORMAT_32_BITS_PARAMS; 839 uMsgLen += uParamsNum * sizeof(TI_UINT32); 840 } 841 else if (uMaxParamValue > UINT8_MAX_VAL) 842 { 843 pMsgHdr->uFormat = TRACE_FORMAT_16_BITS_PARAMS; 844 uMsgLen += uParamsNum * sizeof(TI_UINT16); 845 } 846 else 847 { 848 pMsgHdr->uFormat = TRACE_FORMAT_8_BITS_PARAMS; 849 uMsgLen += uParamsNum; 850 } 851 852 /* Fill all other header information */ 853 pMsgHdr->uLevel = (TI_UINT8)uLevel; 854 pMsgHdr->uParamsNum = (TI_UINT8)uParamsNum; 855 pMsgHdr->uFileId = (TI_UINT16)uFileId; 856 pMsgHdr->uLineNum = (TI_UINT16)uLineNum; 857 858 /* re-sync on the parameters */ 859 va_start(list, uParamsNum); 860 861 /* add the parameters */ 862 for (index = 0; index < uParamsNum; index++) 863 { 864 /* get parameter from the stack */ 865 uParam = va_arg(list, TI_UINT32); 866 867 /* insert the parameter and increment msg pointer */ 868 switch(pMsgHdr->uFormat) 869 { 870 case TRACE_FORMAT_8_BITS_PARAMS: 871 INSERT_BYTE(pMsgData, uParam); 872 break; 873 874 case TRACE_FORMAT_16_BITS_PARAMS: 875 INSERT_2_BYTES(pMsgData, uParam); 876 break; 877 878 case TRACE_FORMAT_32_BITS_PARAMS: 879 INSERT_4_BYTES(pMsgData, uParam); 880 break; 881 882 default: 883 va_end(list); 884 return; 885 } 886 } 887 888 va_end(list); 889 890 /* Send the trace message to the logger */ 891 SendLoggerData(OsContext, aMsg, (TI_UINT16)uMsgLen); 892} 893 894/*--------------------------------------------------------------------------------------*/ 895 896/** 897 * \fn os_SetDrvThreadPriority 898 * \brief Called upon init to set WLAN driver thread priority. 899 * Currently not supported in Linux. 900 * 901 * \param OsContext - The OS handle 902 * \param uWlanDrvThreadPriority - The WLAN driver thread priority 903 * \return 904 */ 905void os_SetDrvThreadPriority (TI_HANDLE OsContext, TI_UINT32 uWlanDrvThreadPriority) 906{ 907} 908