partCStack.h
Go to the documentation of this file.00001
00008
#ifndef MASTER_H
00009
#define MASTER_H // Only include this header file once
00010
#include <Chipcon/hal.h>
00011
00012
00014 #define RF_DESCRAMBLE_LSB_AND_ROTATE(byte, scrReg, j, i) \
00015
do { \
00016
i=0;\
00017
if (bit_test(scrReg,1)) i++;\
00018
if (bit_test(scrReg,4)) i++;\
00019
scrReg>>= 1;\
00020
if (bit_test(byte, j)) {\
00021
i++;\
00022
bit_set(scrReg, 7);\
00023
}\
00024
if (bit_test(i,0)) {\
00025
bit_set(byte, j);\
00026
} else {\
00027
bit_clear(byte, j);\
00028
} \
00029
} while (0)
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
#define RF_DESCRAMBLE(byte, scrReg, i) \
00050
RF_DESCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 0, i);\
00051
RF_DESCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 1, i);\
00052
RF_DESCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 2, i);\
00053
RF_DESCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 3, i);\
00054
RF_DESCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 4, i);\
00055
RF_DESCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 5, i);\
00056
RF_DESCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 6, i);\
00057
RF_DESCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 7, i);
00058
00059
00060
00061
00062
#define RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, j, i) \
00063
do { \
00064
i=0;\
00065
if (bit_test(scrReg,1)) i++;\
00066
if (bit_test(scrReg,4)) i++;\
00067
if (bit_test(byte, j)) i++;\
00068
scrReg>>= 1;\
00069
if (bit_test(i,0)) \
00070
bit_set(scrReg, 7); \
00071
} while (0)
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
#define RF_SCRAMBLE(byte, scrReg, i) \
00082
RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 0, i); \
00083
RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 1, i); \
00084
RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 2, i); \
00085
RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 3, i); \
00086
RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 4, i); \
00087
RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 5, i); \
00088
RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 6, i); \
00089
RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 7, i); \
00090
byte= scrReg;
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00108 #define RF_SLOT_100_US_LEFT (TH0 < 0xFF || TL0 < 0x84)
00109
00114 #define RF_SLOT_200_US_LEFT (TH0 < 0xFF || TL0 < 0x09)
00115
00120 #define RF_SLOT_500_US_LEFT (TH0 < 0xFD || (TH0 == 0xFD && TL0 < 0x98))
00121
00126 #define RF_SLOT_1_MS_LEFT (TH0 < 0xFC || (TH0 == 0xFC && TL0 < 0xD2))
00127
00129 #define RF_MICROSECONDS_UNTIL_NEXT_SLOT ( ((unsigned short)(TH0 << 8 || TL0)) / 10 * 8 )
00130
00131
#define RF_ALONE (rfStatus != RF_STATE_SYNC_SLAVE && rfSlotsSinceLastPacketReceived < RF_ALONE_STATUS_SLOT_COUNT)
00132
00134 #define RF_NEW_RANDOM_BYTE() ((unsigned char)((randomNumberReg= randomNumberReg * 221 + 1) >> 24))
00135
00137 #define RF_SET_MODE_SLEEP \
00138
RFMAIN=0x38;\
00139
PA_POW= 0;
00140
00144 #define RF_SPI_SEND_BYTE(byte) RF_WAIT_AND_SEND_BYTE(byte)
00145
00149 #define RF_SPI_RECEIVE_BYTE(byte) RF_WAIT_AND_RECEIVE_BYTE(byte)
00150
00156 #define RF_LOW_POWER_SLEEP_UNTIL_NEXT_SLOT() ENTER_IDLE_MODE()
00157
00162 #define WAIT_FOR_TIMER0_EXACT(thi0, tlo0) \
00163
while (TH0 < thi0) {}; \
00164
while (TH0 == thi0 && TL0 < tlo0) {};
00165
00169 #define BIGGER_THAN_TIMER0_RENDEVOUZ_EXACT(thi0, tlo0) \
00170
((TH0 > thi0) || (TH0 == thi0 && TL0 >= tlo0))
00171
00172
00173
00178 #define RF_SET_FIELD_STRENGTH(txPower) PA_POW=txPower;
00179
00180
00182 typedef struct NODE_ADDR_STUCT {
00183 byte a1, a2, a3, a4, a5, a6, a7, a8;
00184 }
nodeAddrType;
00185
00186
00187
00188
00189
00190
00191
unsigned short startOffset= 0;
00192
00193
00194
void RFInitRandom();
00195 byte
RFScramble(byte b);
00196 byte
RFDescramble(byte b);
00197 byte
LLSendingBusy();
00198
00199
00200
00201 byte
ACLSubscribe(byte LL_type_h, byte LL_type_l);
00202 byte
ACLUnsubscribe(byte LL_type_h, byte LL_type_l);
00203
void ACLFlushSubscriptions();
00204 byte
ACLSubscribeDefault();
00205 byte
ACLVerifySubscription(byte type_h,byte type_l);
00206
void ACLInit();
00207
00208 byte
ACLProcessControlMessages();
00209
void ACLSetFieldStrength(byte power);
00210 byte
ACLSendingBusy();
00211 byte
ACLGetSendSuccess();
00212 byte
ACLSendPacket(byte slot_timeout);
00213 byte
ACLAddNewType(byte type_h, byte type_l);
00214 byte
ACLAddData(byte data);
00215
void ACLAbortSending();
00216
void ACLSubscribeAll();
00217 byte
ACLMatchesMyIP(
char *buffer,byte start);
00218
char*
ACLGetReceivedData(byte type_h, byte type_l);
00219 byte
ACLGetReceivedPayloadLength();
00220
void ACLSetControlMessagesBehaviour(
bool ignore,
bool pass);
00221
signed char ACLGetReceivedDataLength(byte type_h, byte type_l);
00222 byte
ACLSentPacketInThisSlot();
00223
void ACLAnswerOnACM();
00224
void ACLNoAnswerOnACM();
00225 byte
ACLClearSendData();
00226
void ACLStart();
00227
void ACLStop();
00228 byte
ACLGetRemainingPayloadSpace();
00229
void ACLLockReceiveBuffer();
00230 byte
ACLReceiveBufferLocked();
00231
void ACLReleaseReceiveBuffer();
00232
void ACLSetDataToOld();
00233
void ACLSetDataToNew();
00234 byte
ACLDataIsNew();
00235
char ACLGetReceivedByte(byte type_h, byte type_l, byte position);
00236
void ACLStartup();
00237 byte
ACLDataReceivedInThisSlot();
00238 byte
ACLDataIsNewNow();
00239 byte
ACLFoundReceivedType(byte type_h, byte type_l);
00240 byte
ACLAdressedDataIsNew();
00241 byte
ACLAdressedDataIsNewNow();
00242 byte
ACLSendPacketAdressed(
nodeAddrType *address, byte timeout);
00243
00244
00245
00246
unsigned short LLCalcCRC16(byte *header_data, byte *payload_data, byte payload_size);
00247
00248
00249
void putchar(
char c);
00250
00251
#endif
Generated on Fri Aug 27 10:04:02 2004 for Cheap Sensor Network by
1.3.8