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
|
/*
* fusb302 usb phy driver for type-c and PD
*
* Copyright (C) 2015, 2016 Fairchild Semiconductor Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Seee the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifdef FSC_DEBUG
#include "Log.h"
#include <linux/printk.h>
void InitializeStateLog(StateLog *log)
{
log->Count = 0;
log->End = 0;
log->Start = 0;
}
extern StateLog TypeCStateLog;
extern StateLog PDStateLog;
FSC_BOOL WriteStateLog(StateLog *log, FSC_U16 state, FSC_U16 time_ms, FSC_U16 time_s)
{
if (log == &TypeCStateLog)
pr_debug("FUSB TYPEC state log, state: 0x%x\n", state);
else if (log == &PDStateLog)
pr_debug("FUSB PDPolicy state log, state: 0x%x\n", state);
else
pr_debug("not match TYPEC & PDPolicy\n");
if(!IsStateLogFull(log))
{
FSC_U8 index = log->End;
log->logQueue[index].state = state;
log->logQueue[index].time_ms = time_ms;
log->logQueue[index].time_s = time_s;
log->End += 1;
if(log->End == LOG_SIZE)
{
log->End = 0;
}
log->Count += 1;
return TRUE;
}
else
{
return FALSE;
}
}
FSC_BOOL ReadStateLog(StateLog *log, FSC_U16 * state, FSC_U16 * time_ms, FSC_U16 * time_s) // Read first log and delete entry
{
if(!IsStateLogEmpty(log))
{
FSC_U8 index = log->Start;
*state = log->logQueue[index].state;
*time_ms = log->logQueue[index].time_ms;
*time_s = log->logQueue[index].time_s;
log->Start += 1;
if(log->Start == LOG_SIZE)
{
log->Start = 0;
}
log->Count -= 1;
return TRUE;
}
else
{
return FALSE;
}
}
FSC_BOOL IsStateLogFull(StateLog *log)
{
return (log->Count == LOG_SIZE) ? TRUE : FALSE;
}
FSC_BOOL IsStateLogEmpty(StateLog *log)
{
return (!log->Count) ? TRUE : FALSE;
}
void DeleteStateLog(StateLog *log)
{
}
#endif // FSC_DEBUG
|