|  | Dual Active Bridge Development Board (Part-No. ) |
Content |  |  |  |  |  |

Loading...
Searching...
No Matches
PBV_interface.c
1
3#include "config/comms_config.h"
4#include "PBV_interface.h"
5#include "PBV_config.h"
6
7
12extern const APP_PBV_INTF_API_t appPbvFuncs;
13
14
19 static PBV_Datatype_TX_t * appSystemToPbvPtr;
20
21
22
27 static PBV_Datatype_RX_t * appPbvToSystemPtr;
28
29
34static PBV_Datatype_TX_t * appSystemToPbvAsciiPtr;
35
36
46 void PBV_Change_from_Sixteen_to_Eight(uint16_t * sixteenPtr, uint8_t * eightPtr, uint16_t length)
47{
48 for (uint16_t i = 0, j = 0; i < (length * 2); i = i + 2, j++)
49 {
50 eightPtr[i] = (uint8_t) (sixteenPtr[j] >> 8);
51 eightPtr[i + 1] = (uint8_t) (sixteenPtr[j] & 0x00FF);
52 }
53}
54
55
64 void PBV_Change_from_Eight_to_Sixteen(uint8_t * eightPtr, uint16_t * sixteenPtr, uint16_t length)
65{
66 uint8_t length_odd = (uint8_t) (length & 0x01);
67 uint16_t length_t;
68
69 uint16_t i, j;
70
71 if (length_odd)
72 {
73 length_t = (length & 0xFFFE);
74 }
75 else
76 {
77 length_t = length;
78 }
79
80 for (i = 0, j = 0; i < length_t; i = i + 2, j++)
81 {
82 sixteenPtr[j] = ((uint16_t) (eightPtr[i] << 8)) + eightPtr[i + 1];
83 }
84 if (length_odd)
85 {
86 sixteenPtr[++j] = ((uint16_t) (eightPtr[length-1] << 8));
87 }
88
89}
90
91
103 void App_PBV_Init(PBV_Datatype_TX_t * boardToPbv, PBV_Datatype_TX_t * boardToPpvAscii, PBV_Datatype_RX_t *pbvToBoard)
104{
105 appSystemToPbvPtr = boardToPbv;
106 appSystemToPbvAsciiPtr = boardToPpvAscii;
107 appPbvToSystemPtr = pbvToBoard;
108
109 appPbvFuncs.init(appSystemToPbvPtr, appSystemToPbvAsciiPtr, pbvToBoard);
110}
111
112
122 void App_PBV_Re_Init(PBV_Datatype_TX_t * ptr)
123{
124 // experiment with reassigning the protocol IDs in runtime to CAN objects.
125 // or changing DLCs...
126 appPbvFuncs.reinit(ptr);
127}
128
129
139 void App_Receive_From_PBV(PBV_Datatype_RX_t * ptr)
140{
141 if (ptr->PBV_Message_State != PBV_STATE_RECEIVING)
142 {
143 ptr->PBV_Message_State = PBV_MESSAGE_READY_TO_RECEIVE;
144 }
145}
146
147
158 void App_Send_To_PBV(PBV_Datatype_TX_t * ptr)
159{
160 if (ptr->PBV_Message_State == PBV_MESSAGE_INIT
161 ||
162 ptr->PBV_Message_State == PBV_MESSAGE_TRANSMITTED
163 ||
164 ptr->PBV_Message_State == PBV_MESSAGE_TX_ERROR // TODO: for CAN. If the tx fails in arbitration. Introduce a RETRY mechanism.
165 )
166 {
167 appPbvFuncs.linkDataTX(ptr);
168 ptr->PBV_Message_State = PBV_MESSAGE_TRANSMIT_START;
169 }
170}
171
172
182 int App_Read_Received_From_PBV(PBV_Datatype_RX_t * ptr)
183{
184 return appPbvFuncs.linkDataRX(ptr);
185}
186
187
196 static void App_PBV_Task(void)
197{
198 if (appPbvToSystemPtr->PBV_Message_State == PBV_MESSAGE_READY_TO_RECEIVE ||
199 appPbvToSystemPtr->PBV_Message_State == PBV_STATE_RECEIVING
200 )
201 {
202 appPbvToSystemPtr->PBV_Message_State = appPbvFuncs.rxGui();
203 }
204
205 if (appSystemToPbvPtr->PBV_Message_State == PBV_MESSAGE_TRANSMIT_START ||
206 appSystemToPbvPtr->PBV_Message_State == PBV_MESSAGE_TRANSMITTING
207 )
208 {
209 appSystemToPbvPtr->PBV_Message_State = appPbvFuncs.txGui();
210 }
211
212 if (appSystemToPbvAsciiPtr->PBV_Message_State == PBV_MESSAGE_TRANSMIT_START ||
213 appSystemToPbvAsciiPtr->PBV_Message_State == PBV_MESSAGE_TRANSMITTING
214 )
215 {
216 appSystemToPbvAsciiPtr->PBV_Message_State = appPbvFuncs.txGuiAscii();
217 }
218}
219
220
229 void App_PBV_Task_10ms()
230{
231#if PBV_CANFD
232 App_PBV_Task();
233#endif
234}
235
236
244 void App_PBV_Task_100us()
245{
246#if PBV_UART
247 App_PBV_Task();
248#endif
249}
App_PBV_Task_100us
void App_PBV_Task_100us()
Task to be executed every 100 us.
Definition PBV_interface.c:244
PBV_Change_from_Sixteen_to_Eight
void PBV_Change_from_Sixteen_to_Eight(uint16_t *sixteenPtr, uint8_t *eightPtr, uint16_t length)
This function changes 16 bit data to 8 bit data.
Definition PBV_interface.c:46
App_PBV_Init
void App_PBV_Init(PBV_Datatype_TX_t *boardToPbv, PBV_Datatype_TX_t *boardToPpvAscii, PBV_Datatype_RX_t *pbvToBoard)
Initializes the PBV init, by linking the application object pointers from the application to CAN or U...
Definition PBV_interface.c:103
App_PBV_Task_10ms
void App_PBV_Task_10ms()
task to be executed every 10ms
Definition PBV_interface.c:229
App_Send_To_PBV
void App_Send_To_PBV(PBV_Datatype_TX_t *ptr)
This function links the data from application object to the CAN or UART object and This function ch...
Definition PBV_interface.c:158
appPbvFuncs
const APP_PBV_INTF_API_t appPbvFuncs
< Includes
Definition PBV_config.c:26
appPbvToSystemPtr
static PBV_Datatype_RX_t * appPbvToSystemPtr
pointer to the PBV_Datatype_RX_t object that will be passed from the application.
Definition PBV_interface.c:27
App_PBV_Task
static void App_PBV_Task(void)
Main application task for Power Board Visualizer.
Definition PBV_interface.c:196
App_Read_Received_From_PBV
int App_Read_Received_From_PBV(PBV_Datatype_RX_t *ptr)
This function links the data received by CAN or UART objects to the application object.
Definition PBV_interface.c:182
appSystemToPbvPtr
static PBV_Datatype_TX_t * appSystemToPbvPtr
pointer to the PBV_Datatype_TX_t object that will be passed from the application.
Definition PBV_interface.c:19
App_PBV_Re_Init
void App_PBV_Re_Init(PBV_Datatype_TX_t *ptr)
Reinitializes the objects if any parameters( ID, length, etc) are to be changed to the CAN or UART ob...
Definition PBV_interface.c:122
App_Receive_From_PBV
void App_Receive_From_PBV(PBV_Datatype_RX_t *ptr)
This function changes the state of the application object. this acts as a trigger for the periodic ta...
Definition PBV_interface.c:139
PBV_Change_from_Eight_to_Sixteen
void PBV_Change_from_Eight_to_Sixteen(uint8_t *eightPtr, uint16_t *sixteenPtr, uint16_t length)
This function changes 8 bit data to sixteen bit data.
Definition PBV_interface.c:64
PBV_MESSAGE_READY_TO_RECEIVE
@ PBV_MESSAGE_READY_TO_RECEIVE
Message Reception triggered.
Definition PBV_interface.h:52
PBV_STATE_RECEIVING
@ PBV_STATE_RECEIVING
Message beinf received.
Definition PBV_interface.h:53
PBV_MESSAGE_TRANSMITTED
@ PBV_MESSAGE_TRANSMITTED
Message transmitted. successful transmit.
Definition PBV_interface.h:35
PBV_MESSAGE_INIT
@ PBV_MESSAGE_INIT
Init State. Only Send Messages in this State
Definition PBV_interface.h:36
PBV_MESSAGE_TX_ERROR
@ PBV_MESSAGE_TX_ERROR
if some error happens. unsuccessful transmit
Definition PBV_interface.h:39
PBV_MESSAGE_TRANSMIT_START
@ PBV_MESSAGE_TRANSMIT_START
Start Transmitting message.
Definition PBV_interface.h:37
PBV_MESSAGE_TRANSMITTING
@ PBV_MESSAGE_TRANSMITTING
Transmitting Message.
Definition PBV_interface.h:38
APP_PBV_INTF_API_s
structure of API function pointers.
Definition PBV_config.h:89
APP_PBV_INTF_API_s::init
PBV_Intf_Init_t init
Definition PBV_config.h:90
APP_PBV_INTF_API_s::linkDataTX
PBV_Intf_Link_Data_TX_t linkDataTX
Definition PBV_config.h:95
APP_PBV_INTF_API_s::txGuiAscii
PBV_Intf_Transmit_Ascii_to_GUI_t txGuiAscii
Definition PBV_config.h:93
APP_PBV_INTF_API_s::reinit
PBV_Intf_Reinit_t reinit
Definition PBV_config.h:94
APP_PBV_INTF_API_s::linkDataRX
PBV_Intf_Link_Data_RX_t linkDataRX
Definition PBV_config.h:96
APP_PBV_INTF_API_s::txGui
PBV_Intf_Transmit_to_GUI_t txGui
Definition PBV_config.h:92
APP_PBV_INTF_API_s::rxGui
PBV_Intf_Receive_from_GUI_t rxGui
Definition PBV_config.h:91
PBV_Datatype_TX_t
Definition PBV_interface.h:75
PBV_Datatype_TX_t::PBV_Message_State
PBV_MESSAGE_TX_STATE_t PBV_Message_State
State of the TX object.
Definition PBV_interface.h:79
PBV_Datatype_RX_t
Definition PBV_interface.h:89
PBV_Datatype_RX_t::PBV_Message_State
PBV_MESSAGE_RX_STATE_t PBV_Message_State
State of the received message.
Definition PBV_interface.h:93