/***** * RCR/T-433 Driver for RF Communications * Henry Chan (hc352) * * A driver for RF communication. Communication * will not block program execution. Assuming a * common bus, will only be able to transmit or * receive (not both) at a single time. * * Sample Receiving: * initRF(); * while (checkError()) { * receiveMessage(); // Keep trying to get message * while(rf_state != RF_IDLE_S) { * processByte(); // Until got message * } * decodePayload(); * // rf_payload[] will have payload * } * * Sample Transmitting: * initRF(); * char pl[RF_PAYLOAD_SIZE]; * pl[0] = 0xDE; * pl[1] = 0xAD; * pl[2] = 0xBE; * pl[3] = 0xEF; * // Until ready to send * sendMessage(pl); * while(rf_state != RF_IDLE_S) { * processByte(); * } * *****/ #ifndef RFCOMM_H #define RFCOMM_H #include "portdeclarations.h" // Payload size in bytes #define RF_PAYLOAD_SIZE 4 // Start marker size #define RF_START_SIZE 1 // Sync sequence size #define RF_SYNC_SIZE 4 // Preamble size #define RF_PREAMBLE_SIZE (RF_START_SIZE+RF_SYNC_SIZE) // Stop marker size #define RF_STOP_SIZE 1 // Start marker #define RF_START_MARKER 0xCA // Stop marker #define RF_STOP_MARKER 0xD4 // Sync marker #define RF_SYNC_MARKER 0xAA // Frame size (preamble + payload*2) #define RF_FRAME_SIZE (1+RF_PREAMBLE_SIZE+RF_STOP_SIZE+RF_PAYLOAD_SIZE*2) #define RF_IDLE_S 0x01 #define RF_TX_S 0x02 #define RF_RX_S 0x03 // Use for compare match on timeout clock #define RF_TX_TIMEOUT 253 #define RF_RX_TIMEOUT 234 /***** * Corresponding communications device is either * free or busy. *****/ extern char rf_state; // State of transmitter extern char rf_payload[]; // Payload /**** * Sets RF into a known state ****/ void rf_init(); /**** * Put message into buffer for sending ****/ char rf_send_msg(char buffer[]); /**** * Setup for receiving ****/ char rf_receive_msg(); /**** * Checks for integrity of frame * Returns 0 if frame is alright * Returns 1 if frame is erroneous ****/ char rf_check_error(); /**** * Processes a byte in the stream * Return 0 if uart was free and processed last command * Return 1 if uart is still busy ****/ char rf_process_byte(); /**** * Decodes nibble from a byte in the data stream ****/ void rf_decode_pl(); /**** * Clears the RF transmission channel by transmitting * a non-sync byte long enough to clear a noise-triggered * interrupt capture. A transmitter HIGH (output low) is * sent to adjust the receiver gain. After clearing the * channel, sync bytes should be sent to resync the receiver. ****/ //void rf_clear_channel(); /**** * Reset communications * Clear interrupts and flags ****/ void rf_reset(); #endif