source: SVN/cambria/redboot/packages/devs/eth/intel/npe/common/current/src/IxOsalOsSemaphore.c @ 1

Last change on this file since 1 was 1, checked in by Tim Harvey, 2 years ago

restored latest version of files from server backup

Signed-off-by: Tim Harvey <tharvey@…>

File size: 5.6 KB
Line 
1/**
2 * @file IxOsalOsSemaphore.c (eCos)
3 *
4 * @brief Implementation for semaphore and mutex.
5 *
6 *
7 * @par
8 * IXP400 SW Release version 1.5
9 *
10 * -- Intel Copyright Notice --
11 *
12 * @par
13 * Copyright 2002-2004 Intel Corporation All Rights Reserved.
14 *
15 * @par
16 * The source code contained or described herein and all documents
17 * related to the source code ("Material") are owned by Intel Corporation
18 * or its suppliers or licensors.  Title to the Material remains with
19 * Intel Corporation or its suppliers and licensors.
20 *
21 * @par
22 * The Material is protected by worldwide copyright and trade secret laws
23 * and treaty provisions. No part of the Material may be used, copied,
24 * reproduced, modified, published, uploaded, posted, transmitted,
25 * distributed, or disclosed in any way except in accordance with the
26 * applicable license agreement .
27 *
28 * @par
29 * No license under any patent, copyright, trade secret or other
30 * intellectual property right is granted to or conferred upon you by
31 * disclosure or delivery of the Materials, either expressly, by
32 * implication, inducement, estoppel, except in accordance with the
33 * applicable license agreement.
34 *
35 * @par
36 * Unless otherwise agreed by Intel in writing, you may not remove or
37 * alter this notice or any other notice embedded in Materials by Intel
38 * or Intel's suppliers or licensors in any way.
39 *
40 * @par
41 * For further details, please see the file README.TXT distributed with
42 * this software.
43 *
44 * @par
45 * -- End Intel Copyright Notice --
46 */
47
48#include "IxOsal.h"
49
50/* Define a large number */
51#define IX_OSAL_MAX_LONG (0x7FFFFFFF)
52
53/* Max timeout in MS, used to guard against possible overflow */
54#define IX_OSAL_MAX_TIMEOUT_MS (IX_OSAL_MAX_LONG/HZ)
55
56
57PUBLIC IX_STATUS
58ixOsalSemaphoreInit (IxOsalSemaphore * sid, UINT32 start_value)
59{
60#ifdef CYGPKG_REDBOOT
61        *sid = start_value;
62#else
63#error "Need eCos semaphore support"
64#endif
65
66    return IX_SUCCESS;
67}
68
69/**
70 * DESCRIPTION: If the semaphore is 'empty', the calling thread is blocked.
71 *              If the semaphore is 'full', it is taken and control is returned
72 *              to the caller. If the time indicated in 'timeout' is reached,
73 *              the thread will unblock and return an error indication. If the
74 *              timeout is set to 'IX_OSAL_WAIT_NONE', the thread will never block;
75 *              if it is set to 'IX_OSAL_WAIT_FOREVER', the thread will block until
76 *              the semaphore is available.
77 *
78 *
79 */
80
81
82PUBLIC IX_STATUS
83ixOsalSemaphoreWait (IxOsalOsSemaphore * sid, INT32 timeout)
84{
85#ifdef CYGPKG_REDBOOT
86    diag_printf("%s: Can't use this in RedBoot.\n", __FUNCTION__);
87    return IX_FAIL;
88#else
89#error "Need eCos semaphore support"
90#endif
91}
92
93/*
94 * Attempt to get semaphore, return immediately,
95 * no error info because users expect some failures
96 * when using this API.
97 */
98PUBLIC IX_STATUS
99ixOsalSemaphoreTryWait (IxOsalSemaphore * sid)
100{
101#ifdef CYGPKG_REDBOOT
102    if (*sid) {
103        *sid = 0;
104        return IX_SUCCESS;
105    }
106    return IX_FAIL;
107#else
108#error "Need eCos semaphore support"
109#endif
110}
111
112/**
113 *
114 * DESCRIPTION: This function causes the next available thread in the pend queue
115 *              to be unblocked. If no thread is pending on this semaphore, the
116 *              semaphore becomes 'full'.
117 */
118PUBLIC IX_STATUS
119ixOsalSemaphorePost (IxOsalSemaphore * sid)
120{
121#ifdef CYGPKG_REDBOOT
122    *sid = 1;
123    return IX_SUCCESS;
124#else
125#error "Need eCos semaphore support"
126#endif
127}
128
129PUBLIC IX_STATUS
130ixOsalSemaphoreGetValue (IxOsalSemaphore * sid, UINT32 * value)
131{
132#ifdef CYGPKG_REDBOOT
133    *value = *sid;
134    return IX_SUCCESS;
135#else
136#error "Need eCos semaphore support"
137#endif
138}
139
140PUBLIC IX_STATUS
141ixOsalSemaphoreDestroy (IxOsalSemaphore * sid)
142{
143#ifdef CYGPKG_REDBOOT
144    return IX_SUCCESS;
145#else
146#error "Need eCos semaphore support"
147#endif
148}
149
150/****************************
151 *    Mutex
152 ****************************/
153
154PUBLIC IX_STATUS
155ixOsalMutexInit (IxOsalMutex * mutex)
156{
157    cyg_drv_mutex_init(mutex);
158    return IX_SUCCESS; 
159}
160
161PUBLIC IX_STATUS
162ixOsalMutexLock (IxOsalMutex * mutex, INT32 timeout)
163{
164    int tries;
165
166    if (timeout == IX_OSAL_WAIT_NONE) {
167        if (cyg_drv_mutex_trylock(mutex))
168            return IX_SUCCESS;
169        else
170            return IX_FAIL;
171    }
172
173    tries = (timeout * 1000) / 50;
174    while (1) {
175        if (cyg_drv_mutex_trylock(mutex))
176            return IX_SUCCESS;
177        if (timeout != IX_OSAL_WAIT_FOREVER && tries-- <= 0)
178            break;
179#ifdef CYGPKG_REDBOOT
180        /* RedBoot runs with interrupts off. The IX_ETHDB_SYNC_SEND_NPE_MSG
181         * macro expects an ISR to unlock a mutex for an acknowledge. We
182         * have to poll for that incoming NPE message with RedBoot. Too bad
183         * we don't know which NPE to poll...
184         */
185        {
186            int i;
187            for (i = 0; i < 3; i++)
188                ixNpeMhMessagesReceive(i);
189        }
190#endif
191        CYGACC_CALL_IF_DELAY_US(50);
192    }
193    return IX_FAIL;
194}
195
196PUBLIC IX_STATUS
197ixOsalMutexUnlock (IxOsalMutex * mutex)
198{
199    cyg_drv_mutex_unlock(mutex);
200    return IX_SUCCESS;
201}
202
203/*
204 * Attempt to get mutex, return immediately,
205 * no error info because users expect some failures
206 * when using this API.
207 */
208PUBLIC IX_STATUS
209ixOsalMutexTryLock (IxOsalMutex * mutex)
210{
211    if (cyg_drv_mutex_trylock(mutex))
212        return IX_SUCCESS;
213    return IX_FAIL;
214}
215
216PUBLIC IX_STATUS
217ixOsalMutexDestroy (IxOsalMutex * mutex)
218{
219    cyg_drv_mutex_destroy(mutex);
220    return IX_SUCCESS;
221}
222
223PUBLIC IX_STATUS
224ixOsalFastMutexInit (IxOsalFastMutex * mutex)
225{
226    return ixOsalMutexInit(mutex);
227}
228
229PUBLIC IX_STATUS ixOsalFastMutexTryLock(IxOsalFastMutex *mutex)
230{
231    return ixOsalMutexTryLock(mutex);
232}
233
234
235PUBLIC IX_STATUS
236ixOsalFastMutexUnlock (IxOsalFastMutex * mutex)
237{
238    return ixOsalMutexUnlock(mutex);
239}
240
241PUBLIC IX_STATUS
242ixOsalFastMutexDestroy (IxOsalFastMutex * mutex)
243{
244    return ixOsalMutexDestroy(mutex);
245}
Note: See TracBrowser for help on using the repository browser.