#include "frescan_hw_buffer.h"
#include <string.h> // memcpy
+#include <assert.h>
-#include "frescan_data.h" // the_networks
+#include "frescan_data.h" // frescan_data
#include "frescan_debug.h" // DEBUG, FRESCAN_ERROR
#include "frescan_servers.h" // frescan_servers_get_highest_prio
#include "frescan_queues.h" // frescan_pqueue_xxx, frescan_servers_dequeue
{
int ret;
- ret = ioctl(the_networks[net].fd, CAN_IOCTL_ABORT_FRAME, NULL);
+ ret = ioctl(frescan_data[net].fd, CAN_IOCTL_ABORT_FRAME, NULL);
if (ret == -1) {
FRESCAN_ERROR ("could not abort the frame\n");
return -1;
frescan_ss_t id;
ret = frescan_servers_get_highest_prio(net, &id, &sprio);
- if (ret != 0) return ret;
+ assert(ret == 0);
- pqueue = the_networks[net].queues.tx_fp_queue;
+ pqueue = frescan_data[net].queues.tx_fp_queue;
ret = frescan_pqueue_get_highest_prio(pqueue, &packet, &fprio);
- if (ret != 0) return ret;
+ assert(ret == 0);
if ((id == FRESCAN_MX_IDS) && (packet == NULL)) {
DEBUG(FRESCAN_HW_BUFFER_ENABLE_DEBUG, "(ss:0 fp:0)\n");
}
prio = (is_fp_highest_prio) ? fprio : sprio;
- is_frame_in_chip = (the_networks[net].last_packet != NULL);
-
- if (is_frame_in_chip &&
- (prio > the_networks[net].last_packet_prio)) {
- DEBUG(FRESCAN_HW_BUFFER_ENABLE_DEBUG,"abort frame\n");
- ret = frescan_hw_buffer_abort(net);
- if (ret != 0) {
- FRESCAN_ERROR ("could not abort frame\n");
- return ret;
+ is_frame_in_chip = (frescan_data[net].last_packet != NULL);
+
+ if (is_frame_in_chip) {
+ if (prio > frescan_data[net].last_packet_prio) {
+ // TODO: if same server, dont abort
+ DEBUG(FRESCAN_HW_BUFFER_ENABLE_DEBUG, "abort frame\n");
+ ret = frescan_hw_buffer_abort(net);
+ assert(ret == 0);
+ return 0;
+ } else {
+ DEBUG(FRESCAN_HW_BUFFER_ENABLE_DEBUG,
+ "frame in chip with highest or equal prio\n");
+ return 0;
}
- return 0;
}
if (is_fp_highest_prio) {
ret = frescan_pqueue_dequeue(pqueue, &packet, &prio, 0);
- if (ret != 0) return ret;
+ assert(ret == 0);
} else {
ret = frescan_servers_dequeue(net, id, &packet, &prio);
- if (ret != 0) return ret;
+ assert(ret == 0);
frescan_id_set_field(&packet->frame->id,
FRESCAN_FIELD_PRIO,
frescan_id_set_field
(&packet->frame->id, FRESCAN_FIELD_FRAG_FLAG, frag_flag);
- the_networks[net].last_packet = packet;
- the_networks[net].last_packet_prio = prio;
+ frescan_data[net].last_packet = packet;
+ frescan_data[net].last_packet_prio = prio;
DEBUG(FRESCAN_HW_BUFFER_ENABLE_DEBUG,
"frame->id:0x%X pend_bytes:%u dlc:%u fflag:%u\n",
packet->frame->dlc,
frag_flag);
- ret = write(the_networks[net].fd,
+ ret = write(frescan_data[net].fd,
(void *)packet->frame,
sizeof(struct can_frame_t));