queues.c
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *---------------------           RT-WMP              --------------------
00003  *------------------------------------------------------------------------
00004  *                                                         V7.0B  11/05/10
00005  *
00006  *
00007  *  File: ./src/core/queues.c
00008  *  Authors: Danilo Tardioli
00009  *  ----------------------------------------------------------------------
00010  *  Copyright (C) 2000-2010, Universidad de Zaragoza, SPAIN
00011  *
00012  *  Contact Addresses: Danilo Tardioli                   dantard@unizar.es
00013  *
00014  *  RT-WMP is free software; you can  redistribute it and/or  modify it
00015  *  under the terms of the GNU General Public License  as published by the
00016  *  Free Software Foundation;  either  version 2, or (at  your option) any
00017  *  later version.
00018  *
00019  *  RT-WMP  is distributed  in the  hope  that  it will be   useful, but
00020  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
00021  *  MERCHANTABILITY  or  FITNESS FOR A  PARTICULAR PURPOSE.    See the GNU
00022  *  General Public License for more details.
00023  *
00024  *  You should have received  a  copy of  the  GNU General Public  License
00025  *  distributed with RT-WMP;  see file COPYING.   If not,  write to the
00026  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
00027  *  02111-1307, USA.
00028  *
00029  *  As a  special exception, if you  link this  unit  with other  files to
00030  *  produce an   executable,   this unit  does  not  by  itself cause  the
00031  *  resulting executable to be covered by the  GNU General Public License.
00032  *  This exception does  not however invalidate  any other reasons why the
00033  *  executable file might be covered by the GNU Public License.
00034  *
00035  *----------------------------------------------------------------------*/
00036 #include "config/compiler.h"
00037 #include "include/queues.h"
00038 #include "include/flow_control.h"
00039 #include "interface/wmp_interface.h"
00040 #include "include/queue_core.h"
00041 #include "include/frames.h"
00042 #include "include/task_timing.h"
00043 
00044 queue_t wmp_queue_rx;
00045 queue_t wmp_queue_tx;
00046 
00047 int wmp_queue_rx_get_size() {
00048         return queue_get_size(&wmp_queue_rx);
00049 }
00050 int wmp_queue_rx_get_len() {
00051         return queue_rx_get_count(&wmp_queue_rx, 0);
00052 }
00053 
00054 void wmp_queue_tx_force_sort(int blocking) {
00055 
00056 }
00057 
00058 int wmp_queue_tx_inspect(void) {
00059         return queue_tx_inspect_head(&wmp_queue_tx, 0);
00060 }
00061 
00062 int wmp_queue_tx_get_len(void) {
00063         return queue_tx_get_count(&wmp_queue_tx);
00064 }
00065 
00066 int wmp_queue_tx_get_size(void) {
00067         return queue_get_size(&wmp_queue_tx);
00068 }
00069 int wmp_queue_tx_get_mpm_age(void) {
00070         return queue_tx_get_head_age(&wmp_queue_tx);
00071 }
00072 
00073 int wmp_queue_tx_get_mpm_dest(void) {
00074         return queue_tx_get_head_dest(&wmp_queue_tx);
00075 }
00076 
00077 int wmp_queue_tx_get_elem_age(int id) {
00078         return queue_get_elem_age(&wmp_queue_tx, id);
00079 }
00080 
00081 void wmp_queue_tx_drop_elem(int id){
00082         queue_tx_drop_elem(&wmp_queue_tx, id);
00083 }
00084 
00085 int wmp_queue_tx_get_elem_port(int id) {
00086         return queue_get_elem_port(&wmp_queue_tx, id);
00087 }
00088 
00089 int wmp_queue_tx_get_head_id() {
00090         return queue_tx_get_head_id(&wmp_queue_tx);
00091 }
00092 
00093 int wmp_queue_tx_get_elem_dest(int id) {
00094         return queue_get_elem_dest(&wmp_queue_tx, id);
00095 }
00096 int wmp_queue_tx_get_elem_priority(int id) {
00097         return queue_get_elem_priority(&wmp_queue_tx, id);
00098 }
00099 
00100 int wmp_queue_rx_get_elem_size(int id) {
00101         return queue_get_elem_size(&wmp_queue_rx, id);
00102 }
00103 
00104 int wmp_queue_rx_get_elem_priority(int id) {
00105         return queue_get_elem_priority(&wmp_queue_rx, id);
00106 }
00107 
00108 int wmp_queue_rx_get_elem_source(int id) {
00109         return queue_get_elem_source(&wmp_queue_rx, id);
00110 }
00111 
00112 char * wmp_queue_rx_get_elem_data(int id) {
00113         return queue_get_elem_data(&wmp_queue_rx, id);
00114 }
00115 
00116 int wmp_queue_tx_get_elem_rescheduled(int id) {
00117         return queue_get_elem_rescheduled(&wmp_queue_rx, id);
00118 }
00119 
00120 void wmp_queue_rx_set_elem_done(int id) {
00121         clear(&wmp_queue_rx,id);
00122 
00123 }
00124 
00125 int wmp_queue_tx_get_elem_burst(int id) {
00126         return queue_get_elem_burst(&wmp_queue_tx, id);
00127 }
00128 
00129 void wmp_queue_free(void) {
00130         queue_rx_free(&wmp_queue_rx);
00131         queue_tx_free(&wmp_queue_tx);
00132 }
00133 
00134 int wmp_queue_rx_push_part(longMsg_t * p) {
00135         return queue_push_part(&wmp_queue_rx, p);
00136 }
00137 
00138 int wmp_queue_tx_pop_part(longMsg_t ** p) {
00139         return queue_tx_pop_part(&wmp_queue_tx, p);
00140 }
00141 
00142 void wmp_queue_tx_pop_part_done(int id) {
00143         queue_tx_pop_part_done(&wmp_queue_tx, id);
00144 }
00145 
00146 int wmp_queue_tx_get_count(void) {
00147         return queue_tx_get_count(&wmp_queue_tx);
00148 }
00149 
00150 void wmp_queue_tx_drop_next(void){
00151         queue_tx_drop_next(&wmp_queue_tx);
00152 }
00153 
00154 int wmp_queue_tx_get_room(void) {
00155         return (queue_get_size(&wmp_queue_tx) - queue_tx_get_count(&wmp_queue_tx));
00156 }
00157 
00158 int wmp_queue_rx_get_room(void) {
00159         return queue_rx_get_room(&wmp_queue_rx);
00160 }
00161 
00162 int wmp_queue_tx_remove_head() {
00163         return queue_tx_remove_head(&wmp_queue_tx);
00164 }
00165 int wmp_queue_tx_reschedule(){
00166         return queue_tx_reschedule(&wmp_queue_tx);
00167 }
00168 
00169 int wmp_queue_tx_confirm(){
00170         return queue_tx_confirm(&wmp_queue_tx);
00171 }
00172 
00173 int wmp_queue_rx_get_count(int port){
00174         return queue_rx_get_count(&wmp_queue_rx, port);
00175 }
00176 void wmp_queue_tx_get_last_popped_info(int * age, int *port, int * priority){
00177         queue_tx_get_last_popped_info(&wmp_queue_tx,age,port, priority);
00178 }
00179 /* PUSH & POP FUNCTIONS*/
00180 
00181 int wmpGetNumOfElementsInTXQueue(void) {
00182         return wmp_queue_tx_get_count();
00183 }
00184 
00185 int wmpGetNumOfElementsInRXQueue(int port) {
00186         return wmp_queue_rx_get_count(port);
00187 }
00188 
00189 int wmpPush(Msg *p) {
00190         unsigned int dest = (1 << p->dest);
00191         if (p->dest > ((1 << wmpGetNumOfNodes())-1)){
00192                 //XXX:WMP_ERR(KERN_ERR "Erroreeeeee2\n");
00193                 return 0;
00194         }
00195         task_push(p->priority);
00196         return queue_tx_push_data(&wmp_queue_tx, p->port, p->data, p->len, dest,
00197                         p->priority);
00198 }
00199 
00200 void wmp_queue_init(int rx_nelems, int tx_nelems, int max_msg_size, int num_ports) {
00201         int max_part_size = 1500 - sizeof(Token_Hdr) - sizeof(Message) - 60;
00202         queue_tx_init(&wmp_queue_tx, max_msg_size, tx_nelems, max_part_size);
00203         queue_rx_init(&wmp_queue_rx, max_msg_size, rx_nelems, num_ports); /* 32 rx ports --> 32 semaphores!*/
00204         task_init();
00205 }
00206 
00207 unsigned int wmpPop(Msg * p) {
00208         char *q;
00209         int ts, id = queue_rx_pop_data(&wmp_queue_rx, 0, 0, &q, &p->len, &p->src,
00210                         &p->priority);
00211         memcpy(p->data, q, p->len);
00212         ts = queue_get_elem_age(&wmp_queue_rx, id);
00213         queue_rx_pop_data_done(&wmp_queue_rx, id);
00214         return ts;
00215 }
00216 
00217 int wmpTimedPop(Msg * p, int timeout_ms) {
00218         char *q;
00219         int ts=-1, id = queue_rx_pop_data(&wmp_queue_rx, timeout_ms, 0, &q,
00220                         &p->len, &p->src, &p->priority);
00221         if (id>=0){
00222                 memcpy(p->data, q, p->len);
00223                 ts = queue_get_elem_age(&wmp_queue_rx, id);
00224         }
00225         queue_rx_pop_data_done(&wmp_queue_rx, id);
00226         return ts;
00227 }
00228 
00229 int wmpNonBlockingPop(Msg * p) {
00230         return wmpTimedPop(p, 1);
00231 }
00232 
00233 void wmpAddDest(unsigned int dest, char id) {
00234         dest = dest | (1 << id);
00235 }
00236 
00237 int wmpPushData(unsigned int port, char  * p, unsigned int   size, unsigned int   dest, signed char priority){
00238 
00239         unsigned int filter = (1 << wmpGetNumOfNodes()) - 1;
00240         dest = dest & filter;
00241 
00242         if (dest == (1 << wmpGetNodeId())){
00243                 return queue_rx_push_loop_data(&wmp_queue_rx, port, p, size, dest, priority, wmpGetNodeId());
00244         }else if (dest & (1 << wmpGetNodeId())){
00245                 queue_rx_push_loop_data(&wmp_queue_rx, port, p, size, dest, priority, wmpGetNodeId());
00246                 dest = dest & ~(1 << wmpGetNodeId());
00247                 task_push(priority);
00248                 return queue_tx_push_data(&wmp_queue_tx, port, p, size, dest, priority);
00249         }else{
00250                 task_push(priority);
00251                 return queue_tx_push_data(&wmp_queue_tx, port, p, size, dest, priority);
00252         }
00253 }
00254 
00255 int wmpPopData (unsigned int port, char ** p, unsigned int * size, unsigned char * src, signed char * priority){
00256         return queue_rx_pop_data(&wmp_queue_rx, 0, port, p, size, src, priority);
00257 }
00258 
00259 int wmpPopDataTimeout(unsigned int port, char ** p, unsigned int * size, unsigned char * src, signed char * priority, int to){
00260         return queue_rx_pop_data(&wmp_queue_rx, to, port, p, size, src, priority);
00261 }
00262 
00263 int wmpWaitData(unsigned int port, int to){
00264         return queue_rx_wait_data(&wmp_queue_rx, port, to);
00265 }
00266 
00267 void wmpPopDataDone(int id) {
00268         queue_rx_pop_data_done(&wmp_queue_rx, id);
00269 }
00270 
00271 int wmpPopDataCopy (unsigned int port, char  * p, unsigned int * size, unsigned char * src, signed char * priority){
00272         char * q;
00273         int id = wmpPopData(port,&q,size,src,priority);
00274         memcpy(p,q,*size);
00275         wmpPopDataDone(id);
00276         return id;
00277 }
00278 
00279 int wmpPopDataTimeoutCopy (unsigned int port, char  * p, unsigned int * size, unsigned char * src, signed char * priority, int to){
00280         char * q;
00281         int id = wmpPopDataTimeout(port,&q,size,src,priority, to);
00282         memcpy(p,q,*size);
00283         wmpPopDataDone(id);
00284         return id;
00285 }
00286 
00287 void wmpForceBurst(int port){
00288         queue_tx_force_burst(&wmp_queue_tx,port);
00289 }
00290 


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Fri Jan 3 2014 12:07:55