]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/rpp/fr.c
Merge branch 'init_rework'
[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 document contains proprietary information belonging to Czech
8  * Technical University in Prague. Passing on and copying of this
9  * document, and communication of its contents is not permitted
10  * without prior written authorization.
11  *
12  * File : fr.c
13  * Abstract:
14  *     FlexRay Communication RPP API implementation file.
15  *
16  * References:
17  *     fr.h
18  *     RPP API documentation.
19  */
20
21
22 #include "rpp/rpp.h"
23
24 #ifndef FREERTOS_POSIX
25
26 #include "stdio.h"
27 #include "string.h"
28 #include "drv/drv.h"
29
30 static rpp_fr_state_t rpp_fr_state = RPP_FR_NOT_INITIALIZED;    /**< Stores the actual state of the FlexRay module */
31
32 /* AUTOSAR-like API */
33
34 int8_t rpp_fr_init_driver(const Fr_ConfigType* config_ptr, uint32_t* error) {
35         if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED)
36                 return FAILURE;
37 #if rppCONFIG_DRV == 1
38     spi_tms570_init();
39 #endif
40     Fr_Init(config_ptr);
41         rpp_fr_state = RPP_FR_DRV_INITIALIZED;
42         return SUCCESS;
43 }
44
45 int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_t* error) {
46         Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
47         if (rpp_fr_state == RPP_FR_DRV_INITIALIZED ||
48                         rpp_fr_state == RPP_FR_HALTED ||
49                         rpp_fr_state == RPP_FR_ABORTED) {
50                 retVal = Fr_ControllerInit(ctrl);
51                 if (retVal & E_OK) {
52                         rpp_fr_state = RPP_FR_CTR_INITIALIZED;
53                         return SUCCESS;
54                 }
55                 else {
56                         *error = retVal;
57                         return FAILURE;
58                 }
59         }
60         return FAILURE;
61 }
62
63 int8_t rpp_fr_start_communication(uint8_t ctrl, uint32_t* error) {
64         Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
65         if (rpp_fr_state == RPP_FR_CTR_INITIALIZED) {
66                 retVal = Fr_StartCommunication(ctrl);
67                 if (retVal & E_OK) {
68                         rpp_fr_state = RPP_FR_RUNNING;
69                         return SUCCESS;
70                 }
71                 else {
72                         *error = retVal;
73                         return FAILURE;
74                 }
75         }
76         return FAILURE;
77 }
78
79 int8_t rpp_fr_all_slots(uint8_t ctrl) {
80         if (rpp_fr_state == RPP_FR_RUNNING && Fr_AllSlots(ctrl) & E_OK) {
81                 return SUCCESS;
82         }
83         return FAILURE;
84 }
85
86 int8_t rpp_fr_halt_communication(uint8_t ctrl) {
87         if (rpp_fr_state == RPP_FR_RUNNING && Fr_HaltCommunication(ctrl) & E_OK) {
88                 rpp_fr_state = RPP_FR_HALTED;
89                 return SUCCESS;
90         }
91         return FAILURE;
92 }
93
94 int8_t rpp_fr_abort_communication(uint8_t ctrl) {
95         if (rpp_fr_state == RPP_FR_RUNNING && Fr_AbortCommunication(ctrl) & E_OK) {
96                 rpp_fr_state = RPP_FR_ABORTED;
97                 return SUCCESS;
98         }
99         return FAILURE;
100 }
101
102 int8_t rpp_fr_send_wup(uint8_t ctrl) {
103         if (rpp_fr_state == RPP_FR_CTR_INITIALIZED && Fr_SendWUP(ctrl) & E_OK) {
104                 return SUCCESS;
105         }
106         return FAILURE;
107 }
108
109 int8_t rpp_fr_set_wu_channel(uint8_t ctrl, Fr_ChannelType channel) {
110         if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_SetWakeupChannel(ctrl, channel) & E_OK) {
111                 return SUCCESS;
112         }
113         return FAILURE;
114 }
115
116 int8_t rpp_fr_get_poc_status(uint8_t ctrl, Fr_POCStatusType* poc_status_ptr) {
117         if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetPOCStatus(ctrl, poc_status_ptr) & E_OK) {
118                 return SUCCESS;
119         }
120         return FAILURE;
121 }
122
123 int8_t rpp_fr_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx, const uint8_t* lsdu, uint8_t lsdu_length) {
124         if (rpp_fr_state == RPP_FR_RUNNING && Fr_TransmitTxLPdu(ctrl, lpdu_idx, lsdu, lsdu_length) & E_OK) {
125                 return SUCCESS;
126         }
127         return FAILURE;
128 }
129
130 int8_t rpp_fr_cancel_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx) {
131         if (rpp_fr_state == RPP_FR_RUNNING && Fr_CancelTxLPdu(ctrl, lpdu_idx) & E_OK) {
132                 return SUCCESS;
133         }
134         return FAILURE;
135 }
136
137 int8_t rpp_fr_receive_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint8_t* lsdu, Fr_RxLPduStatusType* lpdu_status, uint8_t* lsdu_length) {
138         if (rpp_fr_state == RPP_FR_RUNNING && Fr_ReceiveRxLPdu(ctrl, lpdu_idx, lsdu, lpdu_status, lsdu_length) & E_OK) {
139                 return SUCCESS;
140         }
141         return FAILURE;
142 }
143
144 int8_t rpp_fr_check_tx_lpdu_status(uint8_t ctrl, uint16_t lpdu_idx, Fr_TxLPduStatusType* lpdu_status) {
145         if (rpp_fr_state == RPP_FR_RUNNING && Fr_CheckTxLPduStatus(ctrl, lpdu_idx, lpdu_status) & E_OK) {
146                 return SUCCESS;
147         }
148         return FAILURE;
149 }
150
151 int8_t rpp_fr_reconfigure_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint16_t frame_id, Fr_ChannelType channel, uint8_t cycle_set, uint8_t cycle_offset, uint8_t payload, uint16_t header_crc) {
152         if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_ReconfigLPdu(ctrl, lpdu_idx, frame_id, channel, cycle_set, cycle_offset, payload, header_crc) & E_OK) {
153                 return SUCCESS;
154         }
155         return FAILURE;
156 }
157
158 int8_t rpp_fr_disable_lpdu(uint8_t ctrl, uint16_t lpdu_idx) {
159         if (rpp_fr_state == RPP_FR_RUNNING && Fr_DisableLPdu(ctrl, lpdu_idx) & E_OK) {
160                 return SUCCESS;
161         }
162         return FAILURE;
163 }
164
165 int8_t rpp_fr_get_global_time(uint8_t ctrl, uint8_t* cycle, uint16_t* macroticks) {
166         if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetGlobalTime(ctrl, cycle, macroticks) & E_OK) {
167                 return SUCCESS;
168         }
169         return FAILURE;
170 }
171
172 int8_t rpp_fr_get_network_management_vector(uint8_t ctrl, uint8_t* nm_vector) {
173         if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetNmVector(ctrl, nm_vector) & E_OK) {
174                 return SUCCESS;
175         }
176         return FAILURE;
177 }
178
179 int8_t rpp_fr_get_channel_status(uint8_t ctrl, uint16_t* channel_a_status, uint16_t* channel_b_status) {
180         if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetChannelStatus(ctrl, channel_a_status, channel_b_status) & E_OK) {
181                 return SUCCESS;
182         }
183         return FAILURE;
184 }
185
186 int8_t rpp_fr_get_clock_correction(uint8_t ctrl, int16_t* rate_correction, int32_t* offset_correction) {
187         if (rpp_fr_state >= RPP_FR_RUNNING && Fr_GetClockCorrection(ctrl, rate_correction, offset_correction) & E_OK) {
188                 return SUCCESS;
189         }
190         return FAILURE;
191 }
192
193 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) {
194         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) {
195                 return SUCCESS;
196         }
197         return FAILURE;
198 }
199
200 int8_t rpp_fr_get_wakeup_rx_status(uint8_t ctrl, uint8_t* status) {
201         if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetWakeupRxStatus(ctrl, status) & E_OK) {
202                 return SUCCESS;
203         }
204         return FAILURE;
205 }
206
207 int8_t rpp_fr_set_timer(uint8_t ctrl, uint8_t timer_idx, uint8_t cycle_set, uint16_t offset_threshold) {
208         if (rpp_fr_state == RPP_FR_RUNNING && Fr_SetAbsoluteTimer(ctrl, timer_idx, cycle_set, offset_threshold) & E_OK) {
209                 return SUCCESS;
210         }
211         return FAILURE;
212 }
213
214 int8_t rpp_fr_cancel_timer(uint8_t ctrl, uint8_t timer_idx) {
215         if (rpp_fr_state == RPP_FR_RUNNING && Fr_CancelAbsoluteTimer(ctrl, timer_idx) & E_OK) {
216                 return SUCCESS;
217         }
218         return FAILURE;
219 }
220
221 int8_t rpp_fr_clear_timer_irq(uint8_t ctrl, uint8_t timer_idx) {
222         if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_AckAbsoluteTimerIRQ(ctrl, timer_idx) & E_OK) {
223                 return SUCCESS;
224         }
225         return FAILURE;
226 }
227
228 int8_t rpp_fr_get_timer_irq_status(uint8_t ctrl, uint8_t timer_idx, boolean_t* irq_pending) {
229         if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetAbsoluteTimerIRQStatus(ctrl, timer_idx, irq_pending) & E_OK) {
230                 return SUCCESS;
231         }
232         return FAILURE;
233 }
234
235 int8_t rpp_fr_get_driver_version(Std_VersionInfoType* version) {
236         Fr_GetVersionInfo(version);
237         return SUCCESS;
238 }
239
240 int8_t rpp_fr_read_com_ctrl_config(uint8_t ctrl, uint8_t param_idx, uint32_t* param_value) {
241         if (Fr_ReadCCConfig(ctrl, param_idx, param_value) & E_OK) {
242                 return SUCCESS;
243         }
244         return FAILURE;
245 }
246 #endif /* FREERTOS_POSIX */