Contiki 2.5
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
cpu
avr
radio
mac
mac.c
Go to the documentation of this file.
1
/* Copyright (c) 2008, Swedish Institute of Computer Science
2
* All rights reserved.
3
*
4
* Additional fixes for AVR contributed by:
5
*
6
* Colin O'Flynn coflynn@newae.com
7
* Eric Gnoske egnoske@gmail.com
8
* Blake Leverett bleverett@gmail.com
9
* Mike Vidales mavida404@gmail.com
10
* Kevin Brown kbrown3@uccs.edu
11
* Nate Bohlmann nate@elfwerks.com
12
*
13
* All rights reserved.
14
*
15
* Redistribution and use in source and binary forms, with or without
16
* modification, are permitted provided that the following conditions are met:
17
*
18
* * Redistributions of source code must retain the above copyright
19
* notice, this list of conditions and the following disclaimer.
20
* * Redistributions in binary form must reproduce the above copyright
21
* notice, this list of conditions and the following disclaimer in
22
* the documentation and/or other materials provided with the
23
* distribution.
24
* * Neither the name of the copyright holders nor the names of
25
* contributors may be used to endorse or promote products derived
26
* from this software without specific prior written permission.
27
*
28
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
* POSSIBILITY OF SUCH DAMAGE.
39
**/
40
/**
41
* \addtogroup wireless
42
* @{
43
*/
44
/**
45
* \defgroup rf230mac RF230 MAC
46
* @{
47
*/
48
/**
49
* \file
50
* \brief The IEEE 802.15.4 (2003/2006) MAC utility functions.
51
*
52
*/
53
54
/**
55
* \author
56
* Eric Gnoske <egnoske@gmail.com>
57
* Blake Leverett <bleverett@gmail.com>
58
* Mike Vidales <mavida404@gmail.com>
59
* Colin O'Flynn <coflynn@newae.com>
60
*
61
*/
62
63
/* Includes */
64
65
#include <stdlib.h>
66
#include <string.h>
67
#include "
zmac.h
"
68
#include "radio.h"
69
#include "hal.h"
70
#include "
tcpip.h
"
71
#include "
uip.h
"
72
#include "
sicslowpan.h
"
73
#include "
sicslowmac.h
"
74
75
/* Globals */
76
/** \brief Interface structure for this module */
77
ieee_15_4_manager_t
ieee15_4ManagerAddress
;
78
79
//dataRequest_t dataRequestStructAddress;
80
81
/* Macros & Defines */
82
83
uint8_t msduHandle;
84
bool
iAmCoord;
85
bool
autoModes;
86
87
88
/** \brief The RF channel to use for all following transmissions and
89
* receptions (see 6.1.2). Allowable values are 0-26
90
*/
91
uint8_t
phyCurrentChannel
;
92
93
/** \brief The 64-bit address of the coordinator/router through which
94
* the network layer wishes to communicate.
95
*/
96
uint64_t
macCoordExtendedAddress
;
97
98
/** \brief The 16-bit short address assigned to the coordinator
99
* through which the network layer wishes to communicate. A value
100
* of 0xfffe indicates th the coordinator is only using it's 64-bit
101
* extended address. A value of 0xffff indicates that this value is
102
* unknown. The default value is 0xfff.
103
*/
104
uint16_t
macCoordShortAddress
;
105
106
/** \brief This address is the 64-bit address that will be used as
107
* the mechanism to provide a destination to the upper layers. The
108
* default value is 0xfff.
109
*/
110
uint64_t
macDestAddress
;
111
112
/** \brief The sequence number (0x00 - 0xff) added to the transmitted
113
* data or MAC command frame. The default is a random value within
114
* the range.
115
*/
116
uint8_t
macDSN
;
117
118
/** \brief The 16-bit identifier of the PAN on which the device is
119
* sending to. If this value is 0xffff, the device is not
120
* associated. The default value is 0xffff.
121
*/
122
uint16_t
macDstPANId
;
123
124
/** \brief The 16-bit identifier of the PAN on which the device is
125
* operating. If this value is 0xffff, the device is not
126
* associated. The default value is 0xffff.
127
*/
128
uint16_t
macSrcPANId
;
129
130
/** \brief The 16-bit address that the device uses to communicate in
131
* the PAN. If the device is the PAN coordinator, this value shall
132
* be chosen before a PAN is started. Otherwise, the address is
133
* allocated by a coordinator during association. A value of 0xfffe
134
* indicates that the device has associated but has not been
135
* allocated an address. A value of 0xffff indicates that the
136
* device does not have a short address. The default value is
137
* 0xffff.
138
*/
139
uint16_t
macShortAddress
;
140
141
142
/** \brief Our own long address. This needs to be read from EEPROM or
143
* other secure memory storage.
144
*/
145
uint64_t
macLongAddr
;
146
147
/* Implementation */
148
149
/** \brief Initializes the (quasi) 802.15.4 MAC. This function should
150
* be called only once on startup.
151
*/
152
void
153
mac_init
(
void
)
154
{
155
volatile
uint8_t buf[8];
156
157
sicslowmac_resetRequest
(
true
);
158
159
/* Set up the radio for auto mode operation. */
160
hal_subregister_write
(
SR_MAX_FRAME_RETRIES
, 2 );
161
162
/* Need to laod PANID for auto modes */
163
radio_set_pan_id
(DEST_PAN_ID);
164
165
/* Buffer the uint64_t address for easy loading and debug. */
166
/** \todo Find a better location to load the IEEE address. */
167
buf[0] =
macLongAddr
& 0xFF;
168
buf[1] = (
macLongAddr
>> 8) & 0xFF;
169
buf[2] = (
macLongAddr
>> 16) & 0xFF;
170
buf[3] = (
macLongAddr
>> 24) & 0xFF;
171
buf[4] = (
macLongAddr
>> 32) & 0xFF;
172
buf[5] = (
macLongAddr
>> 40) & 0xFF;
173
buf[6] = (
macLongAddr
>> 48) & 0xFF;
174
buf[7] = (
macLongAddr
>> 56) & 0xFF;
175
/* Load the long address into the radio. This is required for auto mode */
176
/* operation. */
177
radio_set_extended_address
((uint8_t *)&
macLongAddr
);
178
179
srand(1234 );
180
msduHandle = rand();
181
182
/* Ping6 debug */
183
memcpy(
uip_lladdr
.addr, &
macLongAddr
, 8);
184
185
/* Convert expected byte order */
186
byte_reverse((uint8_t *)
uip_lladdr
.addr, 8);
187
}
188
189
190
/** @} */
191
/** @} */
Generated on Fri Aug 30 2013 12:34:05 for Contiki 2.5 by
1.8.3.1