| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2006-2011, 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/2 $ |
|---|
| 12 | * $brcm_Date: 6/6/11 10:19a $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/basemodules/dbg/bare/bdbg_os_priv.c $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/2 6/6/11 10:19a ttrammel |
|---|
| 21 | * SW7420-1819: Update NEXUS/pi for NFE 2.0. |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/1 5/3/11 1:41p erickson |
|---|
| 24 | * SW7420-1819: add bare OS support to magnum basemodules |
|---|
| 25 | * |
|---|
| 26 | ***************************************************************************/ |
|---|
| 27 | |
|---|
| 28 | #include "bstd.h" |
|---|
| 29 | #include "bkni.h" |
|---|
| 30 | #include "b_bare_os.h" |
|---|
| 31 | |
|---|
| 32 | b_bare_os_tick g_init_timestamp; |
|---|
| 33 | b_bare_os_lock g_mutex; |
|---|
| 34 | |
|---|
| 35 | void |
|---|
| 36 | BDBG_P_InitializeTimeStamp(void) |
|---|
| 37 | { |
|---|
| 38 | g_init_timestamp = pb_bare_os->current_tick(); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | void |
|---|
| 42 | BDBG_P_GetTimeStamp(char *timeStamp, int size_t) |
|---|
| 43 | { |
|---|
| 44 | b_bare_os_tick currentTime; |
|---|
| 45 | int hours, minutes, seconds; |
|---|
| 46 | int milliseconds; |
|---|
| 47 | int rc; |
|---|
| 48 | |
|---|
| 49 | currentTime = pb_bare_os->current_tick(); |
|---|
| 50 | if (currentTime > g_init_timestamp) { |
|---|
| 51 | milliseconds = pb_bare_os->tick_diff(currentTime, g_init_timestamp); |
|---|
| 52 | } |
|---|
| 53 | else { |
|---|
| 54 | milliseconds = pb_bare_os->tick_diff(g_init_timestamp, currentTime); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | /* Calculate the time */ |
|---|
| 58 | hours = milliseconds/(1000*60*60); |
|---|
| 59 | minutes = milliseconds/(1000*60)%60; |
|---|
| 60 | seconds = milliseconds/1000%60; |
|---|
| 61 | |
|---|
| 62 | /* print the formatted time including the milliseconds */ |
|---|
| 63 | rc = BKNI_Snprintf(timeStamp, size_t, "%02u:%02u:%02u.%03u", hours, minutes, seconds, milliseconds); |
|---|
| 64 | return; |
|---|
| 65 | |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | BERR_Code BDBG_P_OsInit(void) |
|---|
| 69 | { |
|---|
| 70 | g_mutex = pb_bare_os->lock_create(); |
|---|
| 71 | return 0; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | void BDBG_P_OsUninit(void) |
|---|
| 75 | { |
|---|
| 76 | pb_bare_os->lock_destroy(g_mutex); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | /* NOTE: this function is called from both magnum task and isr context */ |
|---|
| 80 | void BDBG_P_Lock(void) |
|---|
| 81 | { |
|---|
| 82 | int rc; |
|---|
| 83 | rc = pb_bare_os->lock_acquire(g_mutex); |
|---|
| 84 | BDBG_ASSERT(0 == rc); |
|---|
| 85 | return; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | /* NOTE: this function is called from both magnum task and isr context */ |
|---|
| 89 | void BDBG_P_Unlock(void) |
|---|
| 90 | { |
|---|
| 91 | pb_bare_os->lock_release(g_mutex); |
|---|
| 92 | return; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | /* End of file */ |
|---|