Skip to content

Commit 516aa6c

Browse files
Merge pull request #271 from HyperloopUPV-H8/fix/general_issues
fix/general_issues
2 parents 8ae6828 + 0538ea4 commit 516aa6c

4 files changed

Lines changed: 13 additions & 68 deletions

File tree

Inc/HALAL/Services/Communication/Ethernet/TCP/ServerSocket.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ class ServerSocket : OrderProtocol{
5959
}
6060

6161
uint8_t* order_buffer = order.build();
62-
if(order.size > tcp_sndbuf(client_control_block)){
62+
if(order.get_size() > tcp_sndbuf(client_control_block)){
6363
return false;
6464
}
6565

66-
struct pbuf* packet = pbuf_alloc(PBUF_TRANSPORT, order.size, PBUF_POOL);
67-
pbuf_take(packet, order_buffer, order.size);
66+
struct pbuf* packet = pbuf_alloc(PBUF_TRANSPORT, order.get_size(), PBUF_POOL);
67+
pbuf_take(packet, order_buffer, order.get_size());
6868
tx_packet_buffer.push(packet);
6969
send();
7070
return true;

Inc/HALAL/Services/Communication/FDCAN/FDCAN.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ class FDCAN{
112112

113113
static bool read(uint8_t id, FDCAN::Packet* data);
114114

115-
//The use of this method is highly discouraged.
116-
static bool wait_and_read(uint8_t id, FDCAN::Packet* data);
117-
118115
/**
119116
* @brief This method is used to check if the FDCAN have received any new packet.
120117
*

Src/HALAL/Services/Communication/FDCAN/FDCAN.cpp

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -101,70 +101,21 @@ bool FDCAN::transmit(uint8_t id, uint32_t message_id, span<uint8_t> data, FDCAN:
101101
return true;
102102
}
103103

104-
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs){
105-
if (not FDCAN::handle_to_fdcan.contains(hfdcan)) {
106-
printf("Warning: message received from an unknown FDCAN");
107-
return;
108-
}
109-
110-
if (FDCAN::handle_to_fdcan[hfdcan]->rx_queue.size() >= FDCAN::handle_to_fdcan[hfdcan]->rx_queue_max_size) {
111-
return; // TODO: WARNING RX_QUEUE FULL
112-
}
113-
114-
FDCAN::DLC dlc = FDCAN::handle_to_fdcan[hfdcan]->dlc;
115-
116-
vector<uint8_t> data_buffer(FDCAN::dlc_to_len[dlc]);
117-
118-
FDCAN_RxHeaderTypeDef header_buffer = FDCAN_RxHeaderTypeDef();
119-
HAL_FDCAN_GetRxMessage(hfdcan, FDCAN::handle_to_fdcan[hfdcan]->rx_location, &header_buffer, data_buffer.data());
120-
121-
122-
FDCAN::Packet packet_buffer = {data_buffer, header_buffer.Identifier, (FDCAN::DLC)header_buffer.DataLength};
123-
FDCAN::handle_to_fdcan[hfdcan]->rx_queue.push(packet_buffer);
124-
}
104+
// void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs){}
125105

126106
bool FDCAN::read(uint8_t id, FDCAN::Packet* data){
127107
if (not FDCAN::registered_fdcan.contains(id)) {
128108
ErrorHandler("There is no FDCAN registered with id: %d.", id);
129109
return false;
130110
}
131111

132-
if (FDCAN::registered_fdcan[id]->rx_queue.empty()) {
133-
data->rx_data.clear();
134-
data->data_length = FDCAN::DLC::BYTES_0;
135-
data->identifier = 0;
136-
return false;
137-
}
138-
139-
FDCAN::Packet packet = FDCAN::registered_fdcan[id]->rx_queue.front();
140-
141-
data->rx_data = packet.rx_data;
142-
data->identifier = packet.identifier;
143-
data->data_length = packet.data_length;
144-
145-
FDCAN::registered_fdcan[id]->rx_queue.pop();
146-
147-
return true;
148-
}
149-
150-
bool FDCAN::wait_and_read(uint8_t id, FDCAN::Packet* data){
151-
if (not FDCAN::registered_fdcan.contains(id)) {
152-
ErrorHandler("There is no FDCAN registered with id: %d.", id);
112+
if(!FDCAN::received_test(id)) {
153113
return false;
154114
}
115+
FDCAN_RxHeaderTypeDef header_buffer = FDCAN_RxHeaderTypeDef();
116+
HAL_FDCAN_GetRxMessage(FDCAN::registered_fdcan.at(id)->hfdcan, FDCAN::registered_fdcan.at(id)->rx_location, &header_buffer, data->rx_data.data());
155117

156-
//Wait until the arrival of a message.
157-
while (FDCAN::registered_fdcan[id]->rx_queue.empty()) {
158-
}
159-
160-
FDCAN::Packet packet = FDCAN::registered_fdcan[id]->rx_queue.front();
161-
162-
data->rx_data = packet.rx_data;
163-
data->identifier = packet.identifier;
164-
data->data_length = packet.data_length;
165-
166-
FDCAN::registered_fdcan[id]->rx_queue.pop();
167-
118+
data->identifier = header_buffer.Identifier;
168119
return true;
169120
}
170121

@@ -174,11 +125,7 @@ bool FDCAN::received_test(uint8_t id){
174125
return false;
175126
}
176127

177-
if (FDCAN::registered_fdcan[id]->rx_queue.empty()) {
178-
return false;
179-
}
180-
181-
return true;
128+
return !((FDCAN::registered_fdcan.at(id)->hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0FL) == 0U);
182129
}
183130

184131
void FDCAN::init(FDCAN::Instance* fdcan){
@@ -220,4 +167,3 @@ void FDCAN::init(FDCAN::Instance* fdcan){
220167

221168
}
222169
#endif
223-

Src/HALAL/Services/Time/Time.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ uint8_t Time::register_low_precision_alarm(uint32_t period_in_ms, function<void(
201201
.period = period_in_ms,
202202
.tim = low_precision_timer,
203203
.alarm = func,
204-
.offset = low_precision_tick % period_in_ms
204+
.offset = low_precision_tick
205205
};
206206

207207
NVIC_DisableIRQ(TIM7_IRQn);
@@ -215,7 +215,7 @@ uint8_t Time::register_low_precision_alarm(uint32_t period_in_ms, void(*func)())
215215
.period = period_in_ms,
216216
.tim = low_precision_timer,
217217
.alarm = func,
218-
.offset = low_precision_tick % period_in_ms
218+
.offset = low_precision_tick
219219
};
220220

221221
NVIC_DisableIRQ(TIM7_IRQn);
@@ -259,6 +259,7 @@ void Time::high_precision_timer_callback(TIM_HandleTypeDef* tim){
259259
void Time::mid_precision_timer_callback(){
260260
for(pair<const uint8_t,Time::Alarm>& pair : Time::mid_precision_alarms_by_id){
261261
Time::Alarm& alarm = pair.second;
262+
if(alarm.offset == Time::mid_precision_tick) continue;
262263
if((Time::mid_precision_tick - alarm.offset) % alarm.period == 0){
263264
alarm.alarm();
264265
}
@@ -269,6 +270,7 @@ void Time::mid_precision_timer_callback(){
269270
void Time::low_precision_timer_callback(){
270271
for(auto& pair : Time::low_precision_alarms_by_id){
271272
Time::Alarm& alarm = pair.second;
273+
if(alarm.offset == Time::low_precision_tick) continue;
272274
if((Time::low_precision_tick - alarm.offset) % alarm.period == 0){
273275
alarm.alarm();
274276
}

0 commit comments

Comments
 (0)