Scott Roy / OneWire
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Transport.h Source File

Transport.h

00001 #ifndef ROM_COMMANDS
00002 #define ROM_COMMANDS
00003 
00004 #include "OneWire.h"
00005 
00006 class ROMCommands;
00007 
00008 #define READ_ROM 0x33
00009 #define SKIP_ROM 0xCC
00010 #define MATCH_ROM 0x55
00011 #define SEARCH_ROM 0xF0
00012 
00013 // type used to represent a one-wire rom code
00014 typedef unsigned long long OneWire_ROM;
00015 
00016 // types used for the one-wire registers
00017 typedef struct TransportRead{
00018     unsigned char read; // bits or rom read
00019     unsigned char crc8; // crc8 check
00020 } TransportRead;
00021 
00022 /** Persistant search structure
00023  *  Used to keep track of search state and results between executions of the search transport layer command
00024  */
00025 typedef struct TransportSearchPersist{
00026     /** Rom code result of previous search operation
00027      *
00028      *  @note value should be ignored if a one-wire execution error occured
00029      */
00030     OneWire_ROM rom;
00031     
00032     signed char last; // used internally by the micro instruction system to keep track of state
00033     
00034     /** Used to tell when to end a search sequence
00035      *
00036      *  TRUE when the search has completed
00037      *
00038      *  FALSE when there are still rom codes left to search
00039      */
00040     bool done;
00041     
00042     /** Clears existing search state and results in preparation for a new search
00043      *
00044      *  This will reset search progress to start a search sequence from the beginning
00045      *
00046      *  @note Search sequences should be restarted if a one-wire execution error occured as persistant state values might be invalid
00047      */
00048     void clear();
00049 } TransportSearchPersist;
00050 
00051 typedef struct TransportSearch{
00052     unsigned char read; // bits or rom read
00053     unsigned char crc8; // crc8 check
00054     signed char marker; // last conflict marker
00055     unsigned char bit; // storage place current bit result
00056 } TransportSearch;
00057 
00058 /** One-Wire Transport layer class
00059  *  Used to set up a one-wire instruction with a transport layer
00060  */
00061 class OWTransport{
00062 public:
00063     /** Set a one-wire instruction to perform the read transport layer command
00064      *
00065      * @param inst One-wire instruction that will carry out the command
00066      * @param out One-wire rom that will be used to store the read rom code
00067      */
00068     static void read(OneWire_Instruction * inst, OneWire_ROM * out);
00069     
00070     /** Set a one-wire instruction to perform the search transport layer command
00071      *
00072      * @param inst One-wire instruction that will carry out the command
00073      * @param search Persistant search structure that will be used for search state and results
00074      */
00075     static void search(OneWire_Instruction * inst, TransportSearchPersist * search);
00076 private:
00077     // private functions which carry out the one-wire logic
00078     static void _inst_readsetup(OneWire * which);
00079     static void _inst_read(OneWire * which);
00080     static void _inst_readhandler(OneWire * which, char bit);
00081     static void _inst_searchsetup(OneWire * which);
00082     static void _inst_search(OneWire * which);
00083     static void _inst_searchhandler(OneWire * which, char bit);
00084 };
00085 
00086 #endif