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> // Include hardware abstraction layer 00011 00012 // defines 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 /* // old implementation 00032 b= bit_test(scrReg,1) ^ bit_test(scrReg,4) ^ bit_test(byte, 0);\ 00033 scrReg>>= 1;\ 00034 byte>>= 1;\ 00035 if (b) {\ 00036 bit_set(scrReg, 7);\ 00037 bit_set(byte, 7);\ 00038 } 00039 */ 00040 00041 /* 00042 this macro descrambles a byte. 00043 00044 @param byte value to descramble 00045 @param scrReg current scrambling register 00046 @param i counter variable 00047 @return descrambled value in var byte 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 helper macro used by macro SCRAMBLE. not for direct use 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 this macro scrambles a byte. 00075 00076 @param byte value to scramble 00077 @param scrReg current scrambling register 00078 @param i counter variable 00079 @return unsigned_char scrambled value in byte 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 /* #define RF_SCRAMBLE(byte, scrReg, i) \ 00093 RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 0, i) \ 00094 RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 1, i) \ 00095 RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 2, i) \ 00096 RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 3, i) \ 00097 RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 4, i) \ 00098 RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 5, i) \ 00099 RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 6, i) \ 00100 RF_SCRAMBLE_LSB_AND_ROTATE(byte, scrReg, 7, i) \ 00101 byte= scrReg; 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 // external variables //////////////// 00188 00189 // this is the reload-value of counter0. the counter increases from this value until it 00190 // overflows from 0xFFFF. 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 // pre-declare ACL interface 00201 byte ACLSubscribe(byte LL_type_h, byte LL_type_l); //adds a type to the subscription list 00202 byte ACLUnsubscribe(byte LL_type_h, byte LL_type_l); //deletes a type out of the subscription list 00203 void ACLFlushSubscriptions(); //deletes all subscription (not the default ones) 00204 byte ACLSubscribeDefault(); //subscribes to the default types (control msgs..) 00205 byte ACLVerifySubscription(byte type_h,byte type_l); //checks if a subscription is there 00206 void ACLInit(); //start ACL and lower layers, resets the whole stack 00207 //#inline 00208 byte ACLProcessControlMessages(); //internal: is called if control msg is there 00209 void ACLSetFieldStrength(byte power); //sets the field strength of transmitter signals 00210 byte ACLSendingBusy(); //returns true if LL has Packet in send queue 00211 byte ACLGetSendSuccess(); //returns the result of last Packet transmission 00212 byte ACLSendPacket(byte slot_timeout); //starts packet transmission, return values! 00213 byte ACLAddNewType(byte type_h, byte type_l); //adds a type into the ACL send buffer, return values! 00214 byte ACLAddData(byte data); //adds one byte data into the ACL send buffer, return values! 00215 void ACLAbortSending(); //stops a running transmission 00216 void ACLSubscribeAll(); //subscribes to any possible type (all packets are received) 00217 byte ACLMatchesMyIP(char *buffer,byte start); //checks, if buffer holds my IP 00218 char* ACLGetReceivedData(byte type_h, byte type_l); //returns the ACL payload data of the given type in the last received packet 00219 byte ACLGetReceivedPayloadLength(); //returns the number of bytes received 00220 void ACLSetControlMessagesBehaviour(bool ignore, bool pass); 00221 signed char ACLGetReceivedDataLength(byte type_h, byte type_l); //returns number of bytes received of given type in last msg 00222 byte ACLSentPacketInThisSlot(); //is true until next slot if msg was send in this slot 00223 void ACLAnswerOnACM(); //if a control msgs comes in that requires an answer, it is answered 00224 void ACLNoAnswerOnACM(); //if a control msgs comes in that requires an answer, it will not be answered 00225 byte ACLClearSendData(); //deletes the send buffer of ACL 00226 void ACLStart(); //restart ACL after ACLstop() 00227 void ACLStop(); //stops the RF stack. Everything is hold, continues after ACLstart. msg stay in queue 00228 byte ACLGetRemainingPayloadSpace(); //returns the number of free bytes in the transmit buffer 00229 void ACLLockReceiveBuffer(); //locks the receive buffer: no new msgs are received 00230 byte ACLReceiveBufferLocked(); //returns true if receivebuffer is locked 00231 void ACLReleaseReceiveBuffer(); //un-lock the receivebuffer; 00232 void ACLSetDataToOld(); //set received data to "old": means ACLDataIsNew will not return true unless a new packet was received 00233 void ACLSetDataToNew(); //set received data to "new": means ACLDataIsNew will return true every slot 00234 byte ACLDataIsNew(); //returns true if data in receive buffer is "new" 00235 char ACLGetReceivedByte(byte type_h, byte type_l, byte position); //returns a single received byte on the position 00236 void ACLStartup(); // is the first function in any case, runs selftest and aclinit 00237 byte ACLDataReceivedInThisSlot(); //returns true if data was received in this slot 00238 byte ACLDataIsNewNow(); //==ACLDataReceivedin this slot 00239 byte ACLFoundReceivedType(byte type_h, byte type_l); //returns true if type was found 00240 byte ACLAdressedDataIsNew(); // return1 if adressed data came 00241 byte ACLAdressedDataIsNewNow(); // return 1 if adressed data came in this slot 00242 byte ACLSendPacketAdressed(nodeAddrType *address, byte timeout); //sends out the current packet with a target ID 00243 00244 00245 // pre-declare LL interface 00246 unsigned short LLCalcCRC16(byte *header_data, byte *payload_data, byte payload_size); 00247 00248 // for output 00249 void putchar(char c); 00250 00251 #endif

Generated on Fri Aug 27 10:04:02 2004 for Cheap Sensor Network by doxygen 1.3.8