comparison gsm-fw/g23m-aci/gdd_dio/gdd_dio_queue.c @ 775:eedbf248bac0

gsm-fw/g23m-aci subtree: initial import from LoCosto source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 12 Oct 2014 01:45:14 +0000
parents
children
comparison
equal deleted inserted replaced
774:40a721fd9854 775:eedbf248bac0
1 /*
2 +-----------------------------------------------------------------------------
3 | File : gdd_dio_queue.c
4 +-----------------------------------------------------------------------------
5 | Copyright 2002 Texas Instruments Berlin, AG
6 | All rights reserved.
7 |
8 | This file is confidential and a trade secret of Texas
9 | Instruments Berlin, AG
10 | The receipt of or possession of this file does not convey
11 | any rights to reproduce or disclose its contents or to
12 | manufacture, use, or sell anything it may describe, in
13 | whole, or in part, without the specific written consent of
14 | Texas Instruments Berlin, AG.
15 +-----------------------------------------------------------------------------
16 | Purpose : Implements the queue functions for the DIO buffer FIFO
17 +-----------------------------------------------------------------------------
18 */
19
20
21 #define ENTITY_GDD_DIO
22
23 /*==== INCLUDES =============================================================*/
24
25 #include "typedefs.h" /* to get Condat data types */
26 #include "vsi.h" /* to get a lot of macros */
27
28 #include <string.h> /* for memset */
29
30 #include "gdd_dio_queue.h"
31
32 /*==== CONST ================================================================*/
33
34 /*==== LOCAL VARS ===========================================================*/
35
36 /*==== PRIVATE FUNCTIONS ====================================================*/
37
38 /*==== PUBLIC FUNCTIONS =====================================================*/
39
40
41 GLOBAL void gdd_dio_queue_clear(T_GDD_BUF_QUEUE *queue)
42 {
43 queue->next_in = 0;
44 queue->next_out = 0;
45 memset(queue->elems, 0, sizeof(T_dio_buffer *) * GDD_MAX_DIO_BUF);
46 }
47
48
49 BOOL gdd_dio_queue_is_empty(const T_GDD_BUF_QUEUE *queue)
50 {
51 return (queue->next_in == queue->next_out) &&
52 (0 == queue->elems[queue->next_out]);
53 }
54
55
56 GLOBAL BOOL gdd_dio_queue_is_full(const T_GDD_BUF_QUEUE *queue)
57 {
58 return (queue->next_in == queue->next_out) &&
59 !(0 == queue->elems[queue->next_out]);
60 }
61
62
63 GLOBAL BOOL gdd_dio_dequeue(T_GDD_BUF_QUEUE *queue, T_dio_buffer **elem)
64 {
65 if(gdd_dio_queue_is_empty(queue))
66 {
67 return FALSE;
68 }
69 else
70 {
71 (*elem) = queue->elems[queue->next_out];
72 queue->elems[queue->next_out] = 0;
73 ++(queue->next_out);
74 if(queue->next_out EQ GDD_MAX_DIO_BUF)
75 queue->next_out = 0;
76 return TRUE;
77 }
78 }
79
80 GLOBAL BOOL gdd_dio_queue_peek_next_for_dequeue
81 (const T_GDD_BUF_QUEUE *queue, /*out*/T_dio_buffer **elem)
82 {
83 if(gdd_dio_queue_is_empty(queue))
84 {
85 return FALSE;
86 }
87 else
88 {
89 (*elem) = queue->elems[queue->next_out];
90 return TRUE;
91 }
92 }
93
94 GLOBAL BOOL gdd_dio_enqueue(T_dio_buffer *elem, T_GDD_BUF_QUEUE *queue, /*out*/U16 *pos)
95 {
96 if(gdd_dio_queue_is_full(queue))
97 {
98 return FALSE;
99 }
100 else
101 {
102 queue->elems[queue->next_in] = elem;
103 (*pos) = queue->next_in;
104 ++(queue->next_in);
105 if(queue->next_in EQ GDD_MAX_DIO_BUF)
106 queue->next_in = 0;
107 return TRUE;
108 }
109 }
110
111
112 GLOBAL void gdd_dio_queue_peek(const T_GDD_BUF_QUEUE *queue, U16 pos, /*out*/T_dio_buffer **elem)
113 {
114 (*elem) = queue->elems[pos];
115 }