1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/uaccess.h>
#include <linux/mm.h>
#include <linux/kfifo.h>
#include <linux/firmware.h>
#include <linux/syscalls.h>
#include <linux/uaccess.h>
#include <linux/platform_device.h>
#include <linux/proc_fs.h>
#include <ccci.h>
#define CCCI_LOG_MAX_LEN 16
typedef struct _ccci_log
{
struct timeval tv;
ccci_msg_t msg;
int droped;
} ccci_log_t;
typedef struct _logic_ch_record
{
ccci_log_t log[CCCI_LOG_MAX_LEN];
unsigned long msg_num;
unsigned long drop_num;
int log_idx;
int dir;
char *name;
}logic_ch_record_t;
typedef struct _ch_history{
logic_ch_record_t all_ch[CCCI_MAX_CH_NUM];
int md_id;
}ch_history_t;
static ch_history_t *history_ctlb[MAX_MD_NUM];
void add_logic_layer_record(int md_id, ccci_msg_t *data, int drop)
{
logic_ch_record_t *ctlb;
unsigned int ch = data->channel;
ccci_log_t *record;
if (ch >= CCCI_MAX_CH_NUM)
return;
ctlb = &(history_ctlb[md_id]->all_ch[ch]);
if(ctlb == NULL)
return;
record = &(ctlb->log[ctlb->log_idx]);
ctlb->log_idx++;
ctlb->log_idx &= (CCCI_LOG_MAX_LEN-1);
do_gettimeofday(&(record->tv));
record->msg = *data;
record->droped = drop;
if(drop)
ctlb->drop_num++;
else
ctlb->msg_num++;
}
static int s_to_date( long seconds, long usec, int *us, int *sec, int *min, int *hour,
int *day, int *month, int *year)
{
#define DAY_PER_LEAP_YEAR 366
#define DAY_PER_NON_LEAP_YEAR 365
unsigned int i = 0;
unsigned long mins, hours, days, month_t, year_t;
unsigned char m[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if(!sec || !min || !hour || !day || !month || !year)
{
CCCI_MSG("<ctl>%s invalid param!\n", __func__);
return (-1);
}
*us = usec;
*sec = seconds % 60;
mins = seconds / 60;
*min = mins % 60;
hours = mins / 60;
*hour = hours % 24;
days = hours / 24;
year_t = 1970;
while(1)
{
if(!(year_t % 4) && (year_t % 100))
{
if(days >= DAY_PER_LEAP_YEAR)
{
days -= DAY_PER_LEAP_YEAR;
year_t ++;
}
else
break;
}
else
{
if(days >= DAY_PER_NON_LEAP_YEAR)
{
days -= DAY_PER_NON_LEAP_YEAR;
year_t ++;
}
else
break;
}
}
if(!(year_t % 4) && year_t % 100)
{
m[1] = 29;
}
month_t = 1;
for(i=0; i < 12; i++)
{
if(days > m[i])
{
days -= m[i];
month_t++;
}
else
{
break;
}
}
*day = days;
*year = year_t;
*month = month_t;
return 0;
}
static int ccci_record_dump(ccci_log_t *log)
{
int ms, sec, min, hour, day, month, year;
long tv_sec, tv_usec;
tv_sec = (long)log->tv.tv_sec;
tv_usec = (long)log->tv.tv_usec;
if ( (tv_sec==0)&&(tv_usec==0) )
return -1;
s_to_date(tv_sec, tv_usec, &ms, &sec, &min, &hour, &day, &month, &year);
if(!log->droped) {
CCCI_DBG_COM_MSG("%08X %08X %02d %08X %d-%02d-%02d %02d:%02d:%02d.%06d\n",
log->msg.data0,log->msg.data1,log->msg.channel,log->msg.reserved,
year, month, day, hour, min, sec, ms);
} else {
CCCI_DBG_COM_MSG("%08X %08X %02d %08X %d-%02d-%02d %02d:%02d:%02d.%06d -\n",
log->msg.data0,log->msg.data1,log->msg.channel,log->msg.reserved,
year, month, day, hour, min, sec, ms);
}
return 0;
}
void logic_layer_ch_record_dump(int md_id, int ch)
{
ch_history_t *ctlb = history_ctlb[md_id];
int i, j;
logic_ch_record_t *record;
if ((ctlb != NULL)&&(ch < CCCI_MAX_CH_NUM)) {
record = &(ctlb->all_ch[ch]);
CCCI_DBG_COM_MSG("\n");
if(record->dir == CCCI_LOG_TX) {
CCCI_DBG_COM_MSG("ch%02d tx:%ld\t tx_drop:%ld name: %s\t\n", ch, record->msg_num, record->drop_num, record->name);
} else {
CCCI_DBG_COM_MSG("ch%02d rx:%ld\t rx_drop:%ld name: %s\t\n", ch, record->msg_num, record->drop_num, record->name);
}
// dump last ten message
j = record->log_idx - 1;
j &= (CCCI_LOG_MAX_LEN-1);
for (i=0; i<10; i++) {
if (ccci_record_dump(&(record->log[j]))<0)
break;
j--;
j &= (CCCI_LOG_MAX_LEN-1);
}
}
}
void dump_logical_layer_tx_rx_histroy(int md_id)
{
int i=0;
ch_history_t *ctlb = history_ctlb[md_id];
if (ctlb != NULL) {
for(i=0; i<CCCI_MAX_CH_NUM; i++)
logic_layer_ch_record_dump(md_id, i);
}
}
int statistics_init_ch_dir(int md_id, int ch, int dir, char *name)
{
ch_history_t *ctlb = history_ctlb[md_id];
logic_ch_record_t *record;
int ret = 0;
if ((ctlb != NULL)&&(ch < CCCI_MAX_CH_NUM)) {
record = &(ctlb->all_ch[ch]);
record->dir = dir;
record->name = name;
} else {
ret = -1;
}
return ret;
}
int statistics_init(int md_id)
{
history_ctlb[md_id] = kmalloc(sizeof(ch_history_t), GFP_KERNEL);
if(history_ctlb[md_id] != NULL)
memset(history_ctlb[md_id], 0, sizeof(ch_history_t));
return 0;
}
void statistics_exit(int md_id)
{
if(history_ctlb[md_id] != NULL){
kfree(history_ctlb[md_id]);
history_ctlb[md_id] = NULL;
}
return;
}
|