1 //----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2009 by the FRESCOR consortium:
4 // Universidad de Cantabria, SPAIN
5 // University of York, UK
6 // Scuola Superiore Sant'Anna, ITALY
7 // Kaiserslautern University, GERMANY
8 // Univ. Politecnica Valencia, SPAIN
9 // Czech Technical University in Prague, CZECH REPUBLIC
11 // Thales Communication S.A. FRANCE
12 // Visual Tools S.A. SPAIN
13 // Rapita Systems Ltd UK
16 // See http://www.frescor.org
18 // The FRESCOR project (FP6/2005/IST/5-034026) is funded
19 // in part by the European Union Sixth Framework Programme
20 // The European Union is not liable of any use that may be
24 // based on previous work (FSF) done in the FIRST project
26 // Copyright (C) 2005 Mälardalen University, SWEDEN
27 // Scuola Superiore S.Anna, ITALY
28 // Universidad de Cantabria, SPAIN
29 // University of York, UK
31 // This file is part of FNA (Frescor Network Adaptation)
33 // FNA is free software; you can redistribute it and/or modify it
34 // under terms of the GNU General Public License as published by the
35 // Free Software Foundation; either version 2, or (at your option) any
36 // later version. FNA is distributed in the hope that it will be
37 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
38 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 // General Public License for more details. You should have received a
40 // copy of the GNU General Public License along with FNA; see file
41 // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
42 // Cambridge, MA 02139, USA.
44 // As a special exception, including FNA header files in a file,
45 // instantiating FNA generics or templates, or linking other files
46 // with FNA objects to produce an executable application, does not
47 // by itself cause the resulting executable application to be covered
48 // by the GNU General Public License. This exception does not
49 // however invalidate any other reasons why the executable file might be
50 // covered by the GNU Public License.
51 // -----------------------------------------------------------------------
52 #include <stdio.h> // perror
53 #include <stdlib.h> // exit
54 #include <unistd.h> // sleep
55 #include <stdint.h> // uint32_t
57 #include "frescan_queues.h"
58 #include "frescan_packets.h"
59 #include "frescan_debug.h"
60 #include <drivers/can.h>
61 #include <misc/linux_list.h>
63 #define DEBUG_ENABLE 1
65 // static void pause(){
67 // printf(" press Enter...");
74 frescan_queues_t queues;
75 frescan_packet_t *packet, *head;
76 struct can_frame_t *frame;
77 frescan_prio_queue_t *pqueue;
80 frescan_init_params_t init_params;
82 DEBUG(DEBUG_ENABLE, "init frames and packets pool\n");
84 // ret = can_framespool_init();
85 // if (ret != 0) FRESCAN_ERROR ("could not init frames pool\n");
87 ret = frescan_packets_init();
88 if (ret != 0) FRESCAN_ERROR ("could not init packet pool\n");
90 DEBUG(DEBUG_ENABLE, "init queues\n");
92 init_params.tx_fp_max_prio = 10;
93 init_params.rx_num_of_channels = 5;
94 init_params.rx_channel_max_prio = NULL;
96 ret = frescan_queues_init(&queues, &init_params);
97 if (ret != 0) FRESCAN_ERROR("could not initialize the queues\n");
101 DEBUG(DEBUG_ENABLE, "create queue of 5 packets\n");
103 for (i=0; i<5; i++) {
104 frame = can_framespool_alloc();
105 if (frame == NULL) FRESCAN_ERROR ("frames pool is exhausted\n");
107 frame->is_extended_format = 1;
109 frame->id = 0x696969;
114 packet = frescan_packets_alloc();
115 if (packet == NULL) FRESCAN_ERROR ("could not alloc packet\n");
117 packet->frame = frame;
120 DEBUG(DEBUG_ENABLE, "head was null\n");
121 head = frescan_packets_alloc();
122 if (head == NULL) FRESCAN_ERROR ("could not alloc packet\n");
123 INIT_LIST_HEAD(&head->msg_list);
126 list_add_tail(&packet->msg_list, &head->msg_list);
129 DEBUG(DEBUG_ENABLE, "enqueue head in priority queue\n");
131 pqueue = queues.rx_channel_queues[0];
132 ret = frescan_pqueue_enqueue(pqueue, head, 7);
133 if (ret != 0) FRESCAN_ERROR ("could not enqueue packet\n");
137 DEBUG(DEBUG_ENABLE, "dequeue head from priority queue\n");
139 ret = frescan_pqueue_dequeue(pqueue, &head, &prio, blocking);
140 if (ret != 0) FRESCAN_ERROR ("could not dequeue packet\n");
143 if (blocking == false) {
144 FRESCAN_ERROR ("blocking false packet null\n");
146 FRESCAN_ERROR ("blocking true, and packet = null\n");
150 DEBUG(DEBUG_ENABLE, "traverse the list of packets\n");
152 list_for_each_entry(packet, &head->msg_list, msg_list) {
154 "ID Packet, dlc: %u, frame pool pos: %u\n",
155 packet->frame->dlc, packet->frame->pool_pos);
157 ret = can_framespool_free(packet->frame);
158 if (ret != 0) FRESCAN_ERROR("could not free frame\n");
160 ret = frescan_packets_free(packet);
161 if (ret != 0) FRESCAN_ERROR("could not free packet\n");
164 DEBUG(DEBUG_ENABLE, "free head\n");
166 ret = frescan_packets_free(head);
168 FRESCAN_ERROR("could not free head packet\n");