blob: 07e8481bf270d7939e6cc70333714d250027affe [file] [log] [blame]
developer02e65912023-08-17 16:33:10 +08001/* eip202_cdr_event.c
2 *
3 * EIP-202 Ring Control Driver Library
4 * CDR Event Management API implementation
5 */
6
7/* -------------------------------------------------------------------------- */
8/* */
9/* Module : ddk197 */
10/* Version : 5.6.1 */
11/* Configuration : DDK-197-GPL */
12/* */
13/* Date : 2022-Dec-16 */
14/* */
15/* Copyright (c) 2008-2022 by Rambus, Inc. and/or its subsidiaries. */
16/* */
17/* This program is free software: you can redistribute it and/or modify */
18/* it under the terms of the GNU General Public License as published by */
19/* the Free Software Foundation, either version 2 of the License, or */
20/* any later version. */
21/* */
22/* This program is distributed in the hope that it will be useful, */
23/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
24/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
25/* GNU General Public License for more details. */
26/* */
27/* You should have received a copy of the GNU General Public License */
28/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
29/* -------------------------------------------------------------------------- */
30
31/*----------------------------------------------------------------------------
32 * This module implements (provides) the following interface(s):
33 */
34
35#include "eip202_cdr.h"
36
37
38/*----------------------------------------------------------------------------
39 * This module uses (requires) the following interface(s):
40 */
41
42// Default configuration
43#include "c_eip202_ring.h"
44
45// EIP-202 Ring Control Driver Library Internal interfaces
46#include "eip202_ring_internal.h"
47#include "eip202_cdr_level0.h" // EIP-202 Level 0 macros
48#include "eip202_cdr_fsm.h" // CDR State machine
49
50// Driver Framework Basic Definitions API
51#include "basic_defs.h" // IDENTIFIER_NOT_USED, bool, uint32_t
52
53
54/*----------------------------------------------------------------------------
55 * Definitions and macros
56 */
57
58/*----------------------------------------------------------------------------
59 * Local variables
60 */
61
62
63/*----------------------------------------------------------------------------
64 * EIP202_CDR_Status_Get
65 */
66EIP202_Ring_Error_t
67EIP202_CDR_Status_Get(
68 EIP202_Ring_IOArea_t * const IOArea_p,
69 EIP202_CDR_Status_t * const Status_p)
70{
71 Device_Handle_t Device;
72 EIP202_Ring_Error_t rv;
73 volatile EIP202_CDR_True_IOArea_t * const TrueIOArea_p = CDRIOAREA(IOArea_p);
74
75 EIP202_RING_CHECK_POINTER(IOArea_p);
76 EIP202_RING_CHECK_POINTER(Status_p);
77
78 Device = TrueIOArea_p->Device;
79
80 EIP202_CDR_STAT_RD(Device,
81 &Status_p->fDMAError,
82 &Status_p->fTresholdInt,
83 &Status_p->fError,
84 &Status_p->fOUFlowError,
85 &Status_p->fTimeoutInt,
86 &Status_p->CDFIFOWordCount);
87
88 EIP202_CDR_COUNT_RD(Device, &Status_p->CDPrepWordCount);
89 EIP202_CDR_PROC_COUNT_RD(Device,
90 &Status_p->CDProcWordCount,
91 &Status_p->CDProcPktWordCount);
92
93 // Transit to a new state
94 if(Status_p->fDMAError)
95 rv = EIP202_CDR_State_Set((volatile EIP202_CDR_State_t*)&TrueIOArea_p->State,
96 EIP202_CDR_STATE_FATAL_ERROR);
97 else
98 // Remain in the current state
99 rv = EIP202_CDR_State_Set((volatile EIP202_CDR_State_t*)&TrueIOArea_p->State,
100 (EIP202_CDR_State_t)TrueIOArea_p->State);
101 if(rv != EIP202_RING_NO_ERROR)
102 return EIP202_RING_ILLEGAL_IN_STATE;
103
104 return EIP202_RING_NO_ERROR;
105}
106
107
108/*----------------------------------------------------------------------------
109 * EIP202_CDR_FillLevel_Low_INT_Enable
110 */
111EIP202_Ring_Error_t
112EIP202_CDR_FillLevel_Low_INT_Enable(
113 EIP202_Ring_IOArea_t * const IOArea_p,
114 const unsigned int ThresholdDscrCount,
115 const unsigned int Timeout)
116{
117 Device_Handle_t Device;
118 EIP202_Ring_Error_t rv;
119 volatile EIP202_CDR_True_IOArea_t * const TrueIOArea_p = CDRIOAREA(IOArea_p);
120
121 EIP202_RING_CHECK_POINTER(IOArea_p);
122
123 Device = TrueIOArea_p->Device;
124
125 EIP202_CDR_THRESH_WR(Device,
126 (uint32_t)ThresholdDscrCount *
127 TrueIOArea_p->DescOffsWordCount,
128 (uint8_t)Timeout);
129
130 // Remain in the current state
131 rv = EIP202_CDR_State_Set((volatile EIP202_CDR_State_t*)&TrueIOArea_p->State,
132 (EIP202_CDR_State_t)TrueIOArea_p->State);
133 if(rv != EIP202_RING_NO_ERROR)
134 return EIP202_RING_ILLEGAL_IN_STATE;
135
136 return EIP202_RING_NO_ERROR;
137}
138
139
140/*----------------------------------------------------------------------------
141 * EIP202_CDR_FillLevel_Low_INT_ClearAndDisable
142 */
143EIP202_Ring_Error_t
144EIP202_CDR_FillLevel_Low_INT_ClearAndDisable(
145 EIP202_Ring_IOArea_t * const IOArea_p)
146{
147 Device_Handle_t Device;
148 EIP202_Ring_Error_t rv;
149 volatile EIP202_CDR_True_IOArea_t * const TrueIOArea_p = CDRIOAREA(IOArea_p);
150
151 EIP202_RING_CHECK_POINTER(IOArea_p);
152
153 Device = TrueIOArea_p->Device;
154
155 // Disable timeout interrupt and stop timeout counter for
156 // reducing power consumption
157 EIP202_CDR_THRESH_DEFAULT_WR(Device);
158
159 // Clear all CDR interrupts
160 EIP202_CDR_STAT_CLEAR_ALL_IRQ_WR(Device);
161
162 // Remain in the current state
163 rv = EIP202_CDR_State_Set((volatile EIP202_CDR_State_t*)&TrueIOArea_p->State,
164 (EIP202_CDR_State_t)TrueIOArea_p->State);
165 if(rv != EIP202_RING_NO_ERROR)
166 return EIP202_RING_ILLEGAL_IN_STATE;
167
168 return EIP202_RING_NO_ERROR;
169}
170
171
172/* end of file eip202_cdr_event.c */