source: svn/trunk/newcon3bcm2_21bu/magnum/basemodules/dbg/linuxuser/bdbg_os_priv.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2006-2009, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bdbg_os_priv.c $
11 * $brcm_Revision: Hydra_Software_Devel/4 $
12 * $brcm_Date: 1/26/09 10:33a $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/basemodules/dbg/linuxuser/bdbg_os_priv.c $
19 *
20 * Hydra_Software_Devel/4   1/26/09 10:33a erickson
21 * PR51415: rework bdbg_os_priv interface to not suggest BKNI_EventHandle
22 * usage in BDBG_P_Lock, which must lock in both task and isr contexts
23 *
24 * Hydra_Software_Devel/3   11/27/07 10:29a jgarrett
25 * PR 37550: Coverity fixes
26 *
27 * Hydra_Software_Devel/2   10/4/06 3:21p jgarrett
28 * PR 24626: Converting lock routines to use internal mutex.  BKNI mutexes
29 * are not appropriate as this may be called from critical section or isr
30 * code.
31 *
32 * Hydra_Software_Devel/1   4/27/06 10:22a vle
33 * PR 21065: Redefined BDBG_LOCK and BDBG_UNLOCK to be OS specific
34 * functions.
35 *
36 ***************************************************************************/
37
38#include "bstd.h"
39#include "bkni.h"
40#include <sys/time.h>
41#include <pthread.h>
42
43static struct timeval initTimeStamp;
44static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
45
46void
47BDBG_P_InitializeTimeStamp(void)
48{
49    int rc;
50
51    rc = gettimeofday(&initTimeStamp, NULL);
52    if (rc!=0) {
53        BDBG_P_PrintString("### debug: gettimeofday returned %d, ignored", rc);
54    }
55}
56
57void
58BDBG_P_GetTimeStamp(char *timeStamp, int size_t)
59{
60    struct timeval currentTime;
61    int hours, minutes, seconds;
62    int milliseconds;
63    int rc;
64
65    rc = gettimeofday(&currentTime, NULL);
66    if (rc!=0) {
67        BDBG_P_PrintString("### debug: gettimeofday returned %d, ignored", rc);
68    }
69
70    if (currentTime.tv_usec < initTimeStamp.tv_usec)
71    {
72        milliseconds = (currentTime.tv_usec - initTimeStamp.tv_usec + 1000000)/1000;
73        currentTime.tv_sec--;
74    }
75    else    {
76        milliseconds = (currentTime.tv_usec - initTimeStamp.tv_usec)/1000;
77    }
78
79    /* Calculate the time   */
80    hours = (currentTime.tv_sec - initTimeStamp.tv_sec)/3600;
81    minutes = (((currentTime.tv_sec - initTimeStamp.tv_sec)/60))%60;
82    seconds = (currentTime.tv_sec - initTimeStamp.tv_sec)%60;
83
84    /* print the formatted time including the milliseconds  */
85    rc = BKNI_Snprintf(timeStamp, size_t, "%02u:%02u:%02u.%03u", hours, minutes, seconds, milliseconds);
86    return;
87
88}
89
90BERR_Code BDBG_P_OsInit(void)
91{
92    /* g_mutex is statically initialized */
93    return 0;
94}
95
96void BDBG_P_OsUninit(void)
97{
98}
99
100/* NOTE: this function is called from both magnum task and isr context */
101void BDBG_P_Lock(void)
102{
103    int rc;
104    rc = pthread_mutex_lock(&g_mutex);
105    BDBG_ASSERT(0 == rc);
106    return;
107}
108
109/* NOTE: this function is called from both magnum task and isr context */
110void BDBG_P_Unlock(void)
111{
112    pthread_mutex_unlock(&g_mutex);
113    return;
114}
115
116/* End of file */
Note: See TracBrowser for help on using the repository browser.