1 /*
2 * Source file for diva log facility
3 *
4 * Copyright (C) Eicon Technology Corporation, 2000.
5 *
6 * Eicon File Revision : 1.5
7 *
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
10 *
11 */
12
13 #include "sys.h"
14 #include "idi.h"
15 #include "divas.h"
16 #include "adapter.h"
17 #include "divalog.h"
18
19 #include "uxio.h"
20
21 /*Counter to monitor number of messages */
22 static int m_count;
23
24 #define MAX_BUFFERED_MSGS (1000)
25
26 /* Our Linked List Structure to hold message */
27 typedef struct klog_link{
28 klog_t klog;
29 struct klog_link *next;
30 }KNODE;
31
32 /* First & Last structures in list*/
33 KNODE *head;
34 KNODE *tail;
35
36 /*
37 * retrieve message from FIFO buffer
38 * returns NULL if buffer empty
39 * otherwise returns pointer to entry
40 */
41
DivasLogFifoRead(void)42 char *DivasLogFifoRead(void)
43
44 {
45 KNODE *old_head;
46
47 if(head==NULL)
48 {
49 /* Buffer Empty - No Messages */
50 return NULL;
51 }
52
53 m_count--;
54 /* Keep track of message to be read & increment to next message*/
55 old_head = head;
56 head = head->next;
57 /*Return ptr to Msg */
58 return((char *)old_head);
59 }
60
61 /*
62 * write message into FIFO buffer
63 */
64
DivasLogFifoWrite(char * entry,int length)65 void DivasLogFifoWrite(char *entry, int length)
66
67 {
68 KNODE *new_klog;
69
70 if(head == NULL)
71 {
72 /* No Entries in Log */
73 tail=NULL;
74 m_count=0;
75 new_klog=UxAlloc(sizeof(KNODE));
76
77 if(new_klog==NULL)
78 {
79 return;
80 }
81
82 m_count++;
83 memset(new_klog, 0, sizeof(KNODE));
84
85 /* Set head & tail to point to the new Msg Struct */
86 head=tail=new_klog;
87 tail->next=NULL;
88 }
89 else
90 {
91 new_klog=UxAlloc(sizeof(KNODE));
92
93 if(new_klog==NULL)
94 {
95 return;
96 }
97
98 m_count++;
99 memset(new_klog, 0, sizeof(KNODE));
100
101 /* Let last Msg Struct point to new Msg Struct & inc tail */
102 tail->next=new_klog;
103 tail=new_klog;
104 tail->next=NULL;
105 }
106
107 if (length > sizeof(klog_t))
108 {
109 length = sizeof(klog_t);
110 }
111
112 memcpy(&tail->klog, entry, length);
113
114 return;
115 }
116
117 /*
118 * DivaslogFifoEmpty:return TRUE if FIFO buffer is empty,otherwise FALSE
119 */
DivasLogFifoEmpty(void)120 int DivasLogFifoEmpty(void)
121 {
122 return (m_count == 0);
123 }
124
125 /*
126 *DivasLogFifoFull:return TRUE if FIFO buffer is full,otherwise FALSE
127 */
DivasLogFifoFull(void)128 int DivasLogFifoFull(void)
129 {
130 return (m_count == MAX_BUFFERED_MSGS);
131 }
132
133 /*
134 * generate an IDI log entry
135 */
136
DivasLogIdi(card_t * card,ENTITY * e,int request)137 void DivasLogIdi(card_t *card, ENTITY *e, int request)
138
139 {
140 klog_t klog;
141
142 memset(&klog, 0, sizeof(klog));
143
144 klog.time_stamp = UxTimeGet();
145
146 klog.length = sizeof(ENTITY) > sizeof(klog.buffer) ?
147 sizeof(klog.buffer) : sizeof(ENTITY);
148
149 klog.card = (int) (card - DivasCards);
150
151 klog.type = request ? KLOG_IDI_REQ : KLOG_IDI_CALLBACK;
152 klog.code = 0;
153 memcpy(klog.buffer, e, klog.length);
154
155 /* send to the log driver and return */
156
157 DivasLogAdd(&klog, sizeof(klog));
158
159 return;
160 }
161