source: svn/newcon3bcm2_21bu/magnum/basemodules/dbg/ucos_ii/bdbg_os_priv.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 6.2 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2006-2010, 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_Revision: Hydra_Software_Devel/1 $
11 * $brcm_Date: 7/19/10 2:47p $
12 * $brcm_Workfile: bdbg_os_priv.c $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/basemodules/dbg/ucos_ii/bdbg_os_priv.c $
19 *
20 * Hydra_Software_Devel/1   7/19/10 2:47p jfisher
21 * SW7572-30:  Add ucos_ii support.
22 *
23 * Hydra_Software_Devel/1   7/19/10 1:05p jfisher
24 * SW7572-30:  Add ucos_ii support.
25 *
26 * Hydra_Software_Devel/6   3/20/09 4:24p cnovak
27 * PR51415: Fix release build compile warnings. Detab file.
28 *
29 * Hydra_Software_Devel/5   2/18/09 11:22a cnovak
30 * PR51415: In BDBG_P_Lock/Unlock, call bkni's CHECK_CRITICAL to know
31 * whether or not to mutex lock.
32 *
33 * Hydra_Software_Devel/4   1/26/09 5:20p cnovak
34 * PR51415: rework bdbg_os_priv interface to not suggest BKNI_EventHandle
35 * usage in BDBG_P_Lock, which must lock in both task and isr contexts
36 *
37 * Hydra_Software_Devel/3   1/21/09 2:50p cnovak
38 * PR24626: Now that assert checks have been added to bkni for context
39 * validity, BDBG_P_Lock/Unlock can not use the BKNI interface for its
40 * mutex.
41 *
42 * Hydra_Software_Devel/2   6/19/08 4:05p cnovak
43 * PR43697: Move to Hydra branch.
44 *
45 * Platform_Software_Devel/3   7/31/06 5:21p cnovak
46 * PR12841: Add support for task-mode uC/OS driver.
47 *
48 * Platform_Software_Devel/2   5/17/06 6:11p cnovak
49 * PR21065: Add BDBG_P_Lock/Unlock
50 *
51 * Platform_Software_Devel/1   3/8/06 1:07p cnovak
52 * PR 12841: From HDI97401_Integration
53 *
54 ***************************************************************************/
55
56/* uCOS include files */
57#include "bos.h"
58 
59#include "bstd.h"
60#include "bkni.h"
61#include "bdbg_os_priv.h"
62
63/****************************************************************************
64    Global functions
65****************************************************************************/
66/* tap into bkni's function to check for a BKNI critical section. It's ugly,
67   but there is no BKNI standard interface to do this.
68*/
69/*
70        JPF - The PI often calls BDBG_MSG which calls BDBG_P_Lock in critical sections
71        BDBG_P_Lock uses a mutex which causes scheduling which is not legal in a real
72        critical section.  One possible workaround is to not do real critical sections.
73        The current workaround is to have CHECK_CRITICAL return true when uCos
74        OSLockNesting > 0.
75  */
76extern unsigned char OSLockNesting;
77extern unsigned char OSIntNesting;
78#define CHECK_CRITICAL() ( bos_in_interrupt() || (OSLockNesting > 0) || (OSIntNesting > 0))
79
80/****************************************************************************
81    Static data
82****************************************************************************/
83/* platform spefic type for timestamps */
84static unsigned int initTicks;
85/* OS-specific mutex */
86static b_mutex_t g_BdbgMutex;
87static b_mutex_t *g_pBdbgMutex = NULL;
88
89/****************************************************************************
90****************************************************************************/
91void
92BDBG_P_InitializeTimeStamp(void)
93{
94    initTicks = bos_getticks();
95}
96
97/****************************************************************************
98****************************************************************************/
99void
100BDBG_P_GetTimeStamp(char *timeStamp, int size_t)
101{
102    unsigned int currentTicks;
103    int milliseconds;
104
105    currentTicks = bos_getticks();
106
107    milliseconds = (currentTicks - initTicks)*(1000/g_ticks_per_second);
108
109    /* print the formatted time including the milliseconds  */
110    BKNI_Snprintf(timeStamp, size_t, "%08u", milliseconds);
111    return;
112}
113
114/****************************************************************************
115****************************************************************************/
116BERR_Code
117BDBG_P_OsInit(void)
118{
119    BERR_Code rc;
120   
121    /* This lock needs to work between both ISR and Task contexts. We're using
122       a mutex because we only have a tiny amount of code running in ISR
123       context -- the L1 handler -- and we don't expect it to need the BDBG
124       lock.
125       
126       The lock is only used when a debug module is registered for the first
127       time.
128       
129       We need to go directly to the OS for our mutex because we have code
130       in BKNI which checks to make sure no one is trying to call AcquireMutex
131       from within a Magnum ISR context.
132    */
133    if (g_pBdbgMutex != NULL) {
134#if 0
135        rc = BERR_TRACE(BERR_UNKNOWN);
136        BKNI_Fail();
137#else
138                return BERR_SUCCESS;
139#endif
140    }
141
142        if (bos_create_mutex(&g_BdbgMutex) != BERR_SUCCESS)
143        {
144        rc = BERR_TRACE(BERR_OS_ERROR);
145        BKNI_Fail();
146        }
147
148    g_pBdbgMutex = &g_BdbgMutex;
149   
150    return BERR_SUCCESS;
151}
152
153/****************************************************************************
154****************************************************************************/
155void 
156BDBG_P_OsUninit(void)
157{
158    /* No way to release kernel object in uCOS */
159    BKNI_Printf("%s: uCOS Event Leak - no method to destroy semaphore\n", __FUNCTION__);
160    if (g_pBdbgMutex) {
161                bos_delete_mutex(g_pBdbgMutex);
162                g_pBdbgMutex = NULL;
163        }
164}
165
166/****************************************************************************
167****************************************************************************/
168void 
169BDBG_P_Lock(void)
170{
171    unsigned char ucosError;
172
173    if (g_pBdbgMutex == NULL) {
174        ucosError = BERR_TRACE(BERR_NOT_INITIALIZED);
175        return;
176    }
177   
178    if (CHECK_CRITICAL()) {
179        return;
180    }
181   
182    /* Wait forever on this mutex */
183    bos_acquire_mutex(g_pBdbgMutex,BOS_PEND_FOREVER); 
184}
185
186/****************************************************************************
187****************************************************************************/
188void 
189BDBG_P_Unlock(void)
190{
191    BERR_Code rc;
192
193    if (g_pBdbgMutex == NULL) {
194        rc = BERR_TRACE(BERR_NOT_INITIALIZED);
195        return;
196    }
197
198    if (CHECK_CRITICAL()) {
199        return;
200    }
201
202    bos_release_mutex(g_pBdbgMutex);
203}
204
205/* End of file */
206
Note: See TracBrowser for help on using the repository browser.