ieee-15-4-manager.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Swedish Institute of Computer Science.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the Institute nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  * This file is part of the Contiki operating system.
00030  *
00031  * $Id: ieee-15-4-manager.c,v 1.2 2008/10/14 18:38:09 c_oflynn Exp $
00032  */
00033 
00034 /**
00035  *
00036  * \addtogroup rf230mac
00037  * \{
00038  */
00039 
00040 /**
00041  * \file
00042  * \brief  Interfaces the 802.15.4 MAC to upper network layers.
00043  *
00044  * \author
00045  *         Mike Vidales <mavida404@gmail.com>
00046  */
00047 
00048 #include "zmac.h"
00049 #include "radio.h"
00050 #include "ieee-15-4-manager.h"
00051 
00052 /*---------------------------------------------------------------------------*/
00053 static int
00054 wake(void)
00055 {
00056   /* Wake the radio. */
00057   return radio_leave_sleep_mode();
00058 }
00059 /*---------------------------------------------------------------------------*/
00060 static int
00061 sleep(void)
00062 {
00063   /* Sleep the radio. */
00064   return radio_enter_sleep_mode();
00065 }
00066 /*---------------------------------------------------------------------------*/
00067 static void
00068 set_channel(int channel)
00069 {
00070   /* Set the channel. */
00071   phyCurrentChannel = channel;
00072   radio_set_operating_channel(phyCurrentChannel);
00073 }
00074 /*---------------------------------------------------------------------------*/
00075 static int
00076 get_channel(void)
00077 {
00078   /* Reads the current channel. */
00079   phyCurrentChannel = radio_get_operating_channel();
00080   return phyCurrentChannel;
00081 }
00082 /*---------------------------------------------------------------------------*/
00083 static void
00084 set_dst_panid(int panid)
00085 {
00086   macDstPANId = panid;
00087 }
00088 /*---------------------------------------------------------------------------*/
00089 static int
00090 get_dst_panid(void)
00091 {
00092   return macDstPANId;
00093 }
00094 /*---------------------------------------------------------------------------*/
00095 static void
00096 set_src_panid(int panid)
00097 {
00098   /* Writes the PAN_ID to the radio. */
00099   macSrcPANId = panid;
00100   radio_set_pan_id(macSrcPANId);
00101 }
00102 /*---------------------------------------------------------------------------*/
00103 static int
00104 get_src_panid(void)
00105 {
00106   /* Gets the PAN_ID from the radio. */
00107   macSrcPANId = radio_get_pan_id();
00108   return macSrcPANId;
00109 }
00110 /*---------------------------------------------------------------------------*/
00111 static void
00112 set_auto_mode(bool mode)
00113 {
00114   autoModes = mode;
00115 }
00116 /*---------------------------------------------------------------------------*/
00117 static bool
00118 get_auto_mode(void)
00119 {
00120   return autoModes;
00121 }
00122 /*---------------------------------------------------------------------------*/
00123 static void
00124 set_long_addr(uint64_t address)
00125 {
00126   /* Set the Long address in the radio. */
00127   macLongAddr = address;
00128   radio_set_extended_address((uint8_t *)&macLongAddr);
00129 }
00130 /*---------------------------------------------------------------------------*/
00131 static uint64_t
00132 get_long_addr(void)
00133 {
00134   /* Get the Long address from the radio. */
00135   radio_get_extended_address((uint8_t *)&macLongAddr);
00136   return macLongAddr;
00137 }
00138 /*---------------------------------------------------------------------------*/
00139 static void
00140 set_short_addr(int address)
00141 {
00142   /* Set the Short address in the radio. */
00143   macShortAddress = address;
00144   radio_set_short_address(macShortAddress);
00145 }
00146 /*---------------------------------------------------------------------------*/
00147 static int
00148 get_short_addr(void)
00149 {
00150   /* Get the Short address from the radio. */
00151   macShortAddress = radio_get_short_address();
00152   return macShortAddress;
00153 }
00154 /*---------------------------------------------------------------------------*/
00155 static void
00156 set_iamcoord_bit(bool iamcoord)
00157 {
00158     /** Set the iAmCoord bit. */
00159     iAmCoord = iamcoord;
00160     radio_set_device_role(iAmCoord);
00161 }
00162 /*---------------------------------------------------------------------------*/
00163 static bool
00164 get_iamcoord_bit(void)
00165 {
00166     /** Get the iAmCoord bit. */
00167     iAmCoord = radio_get_device_role();
00168     return iAmCoord;
00169 }
00170 /*---------------------------------------------------------------------------*/
00171 static void
00172 set_coord_long_addr(uint64_t address)
00173 {
00174     macCoordExtendedAddress = address;
00175 }
00176 /*---------------------------------------------------------------------------*/
00177 static uint64_t
00178 get_coord_long_addr(void)
00179 {
00180     return macCoordExtendedAddress;
00181 }
00182 /*---------------------------------------------------------------------------*/
00183 static void
00184 set_coord_short_addr(int address)
00185 {
00186     macCoordShortAddress = address;
00187 }
00188 /*---------------------------------------------------------------------------*/
00189 static int
00190 get_coord_short_addr(void)
00191 {
00192     return macCoordShortAddress;
00193 }
00194 /*---------------------------------------------------------------------------*/
00195 static void
00196 set_dest_long_addr(uint64_t address)
00197 {
00198     macDestAddress = address;
00199 }
00200 /*---------------------------------------------------------------------------*/
00201 static uint64_t
00202 get_dest_long_addr(void)
00203 {
00204     return macDestAddress;
00205 }
00206 /*---------------------------------------------------------------------------*/
00207 /** \brief initializes the 802.15.4 manager layer.
00208  *  \param pieee_15_4_manager Pointer to \ref ieee_15_4_manager
00209  */
00210 void ieee_15_4_init(ieee_15_4_manager_t *pieee_15_4_manager)
00211 {
00212 /* Initialize the IEEE 15.4 manager. */
00213   pieee_15_4_manager->wake = wake;
00214   pieee_15_4_manager->sleep = sleep;
00215   pieee_15_4_manager->set_channel = set_channel;
00216   pieee_15_4_manager->get_channel = get_channel;
00217   pieee_15_4_manager->set_dst_panid = set_dst_panid;
00218   pieee_15_4_manager->get_dst_panid = get_dst_panid;
00219   pieee_15_4_manager->set_src_panid = set_src_panid;
00220   pieee_15_4_manager->get_src_panid = get_src_panid;
00221   pieee_15_4_manager->set_auto_mode = set_auto_mode;
00222   pieee_15_4_manager->get_auto_mode = get_auto_mode;
00223   pieee_15_4_manager->set_long_addr = set_long_addr;
00224   pieee_15_4_manager->get_long_addr = get_long_addr;
00225   pieee_15_4_manager->set_short_addr = set_short_addr;
00226   pieee_15_4_manager->get_short_addr = get_short_addr;
00227   pieee_15_4_manager->set_iamcoord_bit = set_iamcoord_bit;
00228   pieee_15_4_manager->get_iamcoord_bit = get_iamcoord_bit;
00229   pieee_15_4_manager->set_coord_long_addr = set_coord_long_addr;
00230   pieee_15_4_manager->get_coord_long_addr = get_coord_long_addr;
00231   pieee_15_4_manager->set_coord_short_addr = set_coord_short_addr;
00232   pieee_15_4_manager->get_coord_short_addr = get_coord_short_addr;
00233   pieee_15_4_manager->set_dest_long_addr = set_dest_long_addr;
00234   pieee_15_4_manager->get_dest_long_addr = get_dest_long_addr;
00235 }
00236 
00237 /** \} */

Generated on Mon Apr 11 14:23:37 2011 for Contiki 2.5 by  doxygen 1.6.1