]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/rpp/fr.c
FlexRay buffer reconfiguration implement
[pes-rpp/rpp-lib.git] / rpp / src / rpp / fr.c
1 /* Copyright (C) 2013 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Carlos Jenkins <carlos@jenkins.co.cr>
5  *     - Michal Horn <hornmich@fel.cvut.cz>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  * File : fr.c
21  * Abstract:
22  *     FlexRay Communication RPP API implementation file.
23  *
24  * References:
25  *     fr.h
26  *     RPP API documentation.
27  */
28
29
30 #include "rpp/rpp.h"
31 #include "stdio.h"
32 #include "string.h"
33
34 #if rppCONFIG_INCLUDE_FR == 1
35
36 static rpp_fr_state_t rpp_fr_state = RPP_FR_NOT_INITIALIZED;    /**< Stores the actual state of the FlexRay module */
37
38 /* AUTOSAR-like API */
39
40 int8_t rpp_fr_init_driver(const Fr_ConfigType* config_ptr, uint32_t* error) {
41         if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED)
42                 return FAILURE;
43         Fr_Init(config_ptr);
44         rpp_fr_state = RPP_FR_DRV_INITIALIZED;
45         return SUCCESS;
46 }
47
48 int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_t* error) {
49         Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
50         if (rpp_fr_state == RPP_FR_DRV_INITIALIZED) {
51                 retVal = Fr_ControllerInit(ctrl);
52                 if (retVal & E_OK) {
53                         rpp_fr_state = RPP_FR_CTR_INITIALIZED;
54                         return SUCCESS;
55                 }
56                 else {
57                         *error = retVal;
58                         return FAILURE;
59                 }
60         }
61         return FAILURE;
62 }
63
64 int8_t rpp_fr_start_communication(uint8_t ctrl, uint32_t* error) {
65         Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
66         if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED) {
67                 retVal = Fr_StartCommunication(ctrl);
68                 if (retVal & E_OK) {
69                         rpp_fr_state = RPP_FR_RUNNING;
70                         return SUCCESS;
71                 }
72                 else {
73                         *error = retVal;
74                         return FAILURE;
75                 }
76         }
77         return FAILURE;
78 }
79
80 int8_t rpp_fr_all_slots(uint8_t ctrl) {
81         if (rpp_fr_state == RPP_FR_RUNNING && Fr_AllSlots(ctrl) & E_OK) {
82                 return SUCCESS;
83         }
84         return FAILURE;
85 }
86
87 int8_t rpp_fr_halt_communication(uint8_t ctrl) {
88         if (rpp_fr_state == RPP_FR_RUNNING && Fr_HaltCommunication(ctrl) & E_OK) {
89                 rpp_fr_state = RPP_FR_HALTED;
90                 return SUCCESS;
91         }
92         return FAILURE;
93 }
94
95 int8_t rpp_fr_abort_communication(uint8_t ctrl) {
96         if (rpp_fr_state == RPP_FR_RUNNING && Fr_AbortCommunication(ctrl) & E_OK) {
97                 rpp_fr_state = RPP_FR_ABORTED;
98                 return SUCCESS;
99         }
100         return FAILURE;
101 }
102
103 int8_t rpp_fr_send_wup(uint8_t ctrl) {
104         if (rpp_fr_state == RPP_FR_CTR_INITIALIZED && Fr_SendWUP(ctrl) & E_OK) {
105                 return SUCCESS;
106         }
107         return FAILURE;
108 }
109
110 int8_t rpp_fr_set_wu_channel(uint8_t ctrl, Fr_ChannelType channel) {
111         if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_SetWakeupChannel(ctrl, channel) & E_OK) {
112                 return SUCCESS;
113         }
114         return FAILURE;
115 }
116
117 int8_t rpp_fr_get_poc_status(uint8_t ctrl, Fr_POCStatusType* poc_status_ptr) {
118         if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetPOCStatus(ctrl, poc_status_ptr) & E_OK) {
119                 return SUCCESS;
120         }
121         return FAILURE;
122 }
123
124 int8_t rpp_fr_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx, const uint8_t* lsdu, uint8_t lsdu_length) {
125         if (rpp_fr_state == RPP_FR_RUNNING && Fr_TransmitTxLPdu(ctrl, lpdu_idx, lsdu, lsdu_length) & E_OK) {
126                 return SUCCESS;
127         }
128         return FAILURE;
129 }
130
131 int8_t rpp_fr_cancel_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx) {
132         if (rpp_fr_state == RPP_FR_RUNNING && Fr_CancelTxLPdu(ctrl, lpdu_idx) & E_OK) {
133                 return SUCCESS;
134         }
135         return FAILURE;
136 }
137
138 int8_t rpp_fr_receive_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint8_t* lsdu, Fr_RxLPduStatusType* lpdu_status, uint8_t* lsdu_length) {
139         if (rpp_fr_state == RPP_FR_RUNNING && Fr_ReceiveRxLPdu(ctrl, lpdu_idx, lsdu, lpdu_status, lsdu_length) & E_OK) {
140                 return SUCCESS;
141         }
142         return FAILURE;
143 }
144
145 int8_t rpp_fr_check_tx_lpdu_status(uint8_t ctrl, uint16_t lpdu_idx, Fr_TxLPduStatusType* lpdu_status) {
146         if (rpp_fr_state == RPP_FR_RUNNING && Fr_CheckTxLPduStatus(ctrl, lpdu_idx, lpdu_status) & E_OK) {
147                 return SUCCESS;
148         }
149         return FAILURE;
150 }
151
152 int8_t rpp_fr_reconfigure_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint16_t frame_id, Fr_ChannelType channel, uint8_t cycle, uint8_t payload) {
153         if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_ReconfigLPdu(ctrl, lpdu_idx, frame_id, channel, cycle, payload) & E_OK) {
154                 return SUCCESS;
155         }
156         return FAILURE;
157 }
158
159 int8_t rpp_fr_disable_lpdu(uint8_t ctrl, uint16_t lpdu_idx) {
160         if (rpp_fr_state == RPP_FR_RUNNING && Fr_DisableLPdu(ctrl, lpdu_idx) & E_OK) {
161                 return SUCCESS;
162         }
163         return FAILURE;
164 }
165
166 int8_t rpp_fr_get_global_time(uint8_t ctrl, uint8_t* cycle, uint16_t* macroticks) {
167         if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetGlobalTime(ctrl, cycle, macroticks) & E_OK) {
168                 return SUCCESS;
169         }
170         return FAILURE;
171 }
172
173 int8_t rpp_fr_get_network_management_vector(uint8_t ctrl, uint8_t* nm_vector) {
174         if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetNmVector(ctrl, nm_vector) & E_OK) {
175                 return SUCCESS;
176         }
177         return FAILURE;
178 }
179
180 int8_t rpp_fr_get_channel_status(uint8_t ctrl, uint16_t* channel_a_status, uint16_t* channel_b_status) {
181         if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetChannelStatus(ctrl, channel_a_status, channel_b_status) & E_OK) {
182                 return SUCCESS;
183         }
184         return FAILURE;
185 }
186
187 int8_t rpp_fr_get_clock_correction(uint8_t ctrl, int16_t* rate_correction, int32_t* offset_correction) {
188         if (rpp_fr_state >= RPP_FR_RUNNING && Fr_GetClockCorrection(ctrl, rate_correction, offset_correction) & E_OK) {
189                 return SUCCESS;
190         }
191         return FAILURE;
192 }
193
194 int8_t rpp_fr_get_sync_frame_list(uint8_t ctrl, uint8_t list_size, uint16_t* channel_a_even_list, uint16_t* channel_b_even_list, uint16_t* channel_a_odd_list, uint16_t* channel_b_odd_list) {
195         if (rpp_fr_state >= RPP_FR_RUNNING && Fr_GetSyncFrameList(ctrl, list_size, channel_a_even_list, channel_b_even_list, channel_a_odd_list, channel_b_odd_list) & E_OK) {
196                 return SUCCESS;
197         }
198         return FAILURE;
199 }
200
201 int8_t rpp_fr_get_wakeup_rx_status(uint8_t ctrl, uint8_t* status) {
202         if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetWakeupRxStatus(ctrl, status) & E_OK) {
203                 return SUCCESS;
204         }
205         return FAILURE;
206 }
207
208 int8_t rpp_fr_set_timer(uint8_t ctrl, uint8_t timer_idx, uint8_t cycle_set, uint16_t offset_threshold) {
209         if (rpp_fr_state == RPP_FR_RUNNING && Fr_SetAbsoluteTimer(ctrl, timer_idx, cycle_set, offset_threshold) & E_OK) {
210                 return SUCCESS;
211         }
212         return FAILURE;
213 }
214
215 int8_t rpp_fr_cancel_timer(uint8_t ctrl, uint8_t timer_idx) {
216         if (rpp_fr_state == RPP_FR_RUNNING && Fr_CancelAbsoluteTimer(ctrl, timer_idx) & E_OK) {
217                 return SUCCESS;
218         }
219         return FAILURE;
220 }
221
222 int8_t rpp_fr_clear_timer_irq(uint8_t ctrl, uint8_t timer_idx) {
223         if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_AckAbsoluteTimerIRQ(ctrl, timer_idx) & E_OK) {
224                 return SUCCESS;
225         }
226         return FAILURE;
227 }
228
229 int8_t rpp_fr_get_timer_irq_status(uint8_t ctrl, uint8_t timer_idx, boolean_t* irq_pending) {
230         if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetAbsoluteTimerIRQStatus(ctrl, timer_idx, irq_pending) & E_OK) {
231                 return SUCCESS;
232         }
233         return FAILURE;
234 }
235
236 int8_t rpp_fr_get_driver_version(Std_VersionInfoType* version) {
237         Fr_GetVersionInfo(version);
238         return SUCCESS;
239 }
240
241 int8_t rpp_fr_read_com_ctrl_config(uint8_t ctrl, uint8_t param_idx, uint32_t* param_value) {
242         if (Fr_ReadCCConfig(ctrl, param_idx, param_value) & E_OK) {
243                 return SUCCESS;
244         }
245         return FAILURE;
246 }
247
248
249 #endif /* rppCONFIG_INCLUDE_FR */