wifi_rx_queue.c
Go to the documentation of this file.
00001 /*----------------------------------------------------------------------------
00002  *-------------------------      M a R T E   O S      ------------------------
00003  *----------------------------------------------------------------------------
00004  *   Copyright (C) 2003-2005   Universidad de Cantabria, SPAIN
00005  *
00006  *   MaRTE OS web page: http://marte.unican.es
00007  *
00008  *  MaRTE OS  is free software; you can  redistribute it and/or  modify it
00009  *  under the terms of the GNU General Public License  as published by the
00010  *  Free Software Foundation;  either  version 2, or (at  your option) any
00011  *  later version.
00012  *
00013  *  MaRTE OS  is distributed  in the  hope  that  it will be   useful, but
00014  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
00015  *  MERCHANTABILITY  or  FITNESS FOR A  PARTICULAR PURPOSE.    See the GNU
00016  *  General Public License for more details.
00017  *
00018  *  You should have received  a  copy of  the  GNU General Public  License
00019  *  distributed with MaRTE  OS;  see file COPYING.   If not,  write to the
00020  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
00021  *  02111-1307, USA.
00022  *
00023  *  As a  special exception, if you  link this  unit  with other  files to
00024  *  produce an   executable,   this unit  does  not  by  itself cause  the
00025  *  resulting executable to be covered by the  GNU General Public License.
00026  *  This exception does  not however invalidate  any other reasons why the
00027  *  executable file might be covered by the GNU Public License.
00028  *
00029  *---------------------------------------------------------------------------
00030  *
00031  *                            'r x _ q u e u e . c'
00032  *
00033  *                                     C
00034  *
00035  *
00036  * File 'rx_queue.c'                                                  By Chema.
00037  *                                                          Jose Maria Martinez
00038  *                                                            <chema@gmx.net>
00039  * Body fuctions of the ring queue (see description).
00040  *---------------------------------------------------------------------------*/
00041 
00042 /* This module implements a ring buffer. Concurrent access is avoid if     */
00043 /* exactly one producer and exactly one consumer are accesing. The reading */
00044 /* process is waiting to consume data that is produced at interrupt time.  */
00045 /* An important consideration of the ring buffer is that we consider the   */
00046 /* buffer empty when the head (current_pos) is == tail (free_pos), and full*/
00047 /* when the (tail + 1) % RING_BUFFER_LEN == head (we waste one element)    */
00048 
00049 #include <stdbool.h>
00050 #include <string.h>
00051 #include "wifi_rx_queue.h"
00052 
00053         void
00054 ath5k_ring_init (wifi_ring_t *ring)
00055 {
00056         ring->head = 0;
00057         ring->tail = 0;
00058         ring->count = 0;
00059 
00060         ring->blocking_read = true;
00061 
00062         sem_init(&ring->sem, 0,0);
00063 }
00064 
00065         bool
00066 ath5k_ring_empty (wifi_ring_t *ring)
00067 {
00068         return ring->count == 0;
00069 }
00070 
00071         void
00072 ath5k_ring_insert (wifi_ring_t *ring, const unsigned char *data,
00073                 const unsigned short len, const int link_quality, const int noise, const unsigned char rate)
00074 {
00075         memcpy(ring->frames[ring->head].info, data, len);
00076         ring->frames[ring->head].len = len;
00077         ring->frames[ring->head].link_quality = link_quality;
00078         ring->frames[ring->head].noise=noise;
00079         ring->frames[ring->head].rate=rate;
00080         ring->head = (ring->head + 1) % RX_RING_ELEMENTS;
00081         if (ring->count < RX_RING_ELEMENTS)
00082         {
00083                 ring->count++;
00084         }
00085         else
00086         {
00087                 ring->tail = (ring->tail + 1) % RX_RING_ELEMENTS;
00088         }
00089 }
00090 
00091         void
00092 ath5k_ring_extract (wifi_ring_t *ring, frame_t *frame)
00093 {
00094         frame->len = 0;
00095         if (ring->count > 0)
00096         {
00097                 frame->len = ring->frames[ring->tail].len;
00098                 memcpy(frame->info, ring->frames[ring->tail].info, frame->len);
00099                 frame->link_quality = ring->frames[ring->tail].link_quality;
00100                 frame->noise = ring->frames[ring->tail].noise;
00101                 frame->rate = ring->frames[ring->tail].rate;
00102                 ring->tail = (ring->tail + 1) % RX_RING_ELEMENTS;
00103                 ring->count--;
00104         }
00105 }
00106 


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