#include <unistd.h> // ioctl
#include <stdlib.h> // malloc
#include <string.h> // memcpy
+#include <assert.h>
#include <drivers/can.h> // can_chip_t, can_frame_t
#include "frescan.h" // frescan_init_params_t, frescan_send_params_t
// NOTE: instead of this we could use a chain of frames but
// i think it would be inefficient since each one can only
// hold 8 user bytes and we need to write its headers.
- packet->buffer_head = (uint8_t *)malloc(size*sizeof(uint8_t));
+ FRESCAN_ACQUIRE_LOCK(&frescan_data[params->net].lock);
+ packet->buffer_head = (uint8_t *)malloc(size*sizeof(uint8_t)); // TODO: FREE IT!!!
+ FRESCAN_RELEASE_LOCK(&frescan_data[params->net].lock);
memcpy(packet->buffer_head, msg, size);
} else {
packet->buffer_head = (uint8_t *)msg;
frescan_ss_t id;
packet = frescan_data[chip->minor].last_packet;
+ assert(packet != NULL);
id = frescan_id_get_field(packet->frame->id,
FRESCAN_FIELD_FRAG_ID);
pqueue = frescan_data[chip->minor].queues.tx_fp_queue;
ret = frescan_pqueue_requeue(pqueue, packet, prio);
if (ret != 0) {
- FRESCAN_ERROR("could not requeue the packet\n");
+ FRESCAN_ERROR("could not requeue the packet packet:%p flags:0x%X\n", packet, packet->flags);
return -1;
}
} else if (packet->flags & FRESCAN_SS) {