An experimental timer interrupt driven software based 1-Wire master interface that was created by Robert David Brinzer for a University of Glasgow Level 4 Electronic and Software Engineering Final Year project. This implementation requires mbed RTOS and does not use NOP waits. Perfect for programs that require multi-tasking. Includes the Read and Search network commands and can be easily extended to support new network and transport commands.

Committer:
sroy
Date:
Mon Apr 15 07:02:49 2013 +0000
Revision:
0:7c6dd6bc20e4
An experimental 1-Wire Master interface driven by timer interrupts rather than NOP waits created as part of a University of Glasgow Level 4 Electronic and Software Engineering final year project.   Requires the use of mbed RTOS.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sroy 0:7c6dd6bc20e4 1 #ifndef ROM_COMMANDS
sroy 0:7c6dd6bc20e4 2 #define ROM_COMMANDS
sroy 0:7c6dd6bc20e4 3
sroy 0:7c6dd6bc20e4 4 #include "OneWire.h"
sroy 0:7c6dd6bc20e4 5
sroy 0:7c6dd6bc20e4 6 class ROMCommands;
sroy 0:7c6dd6bc20e4 7
sroy 0:7c6dd6bc20e4 8 #define READ_ROM 0x33
sroy 0:7c6dd6bc20e4 9 #define SKIP_ROM 0xCC
sroy 0:7c6dd6bc20e4 10 #define MATCH_ROM 0x55
sroy 0:7c6dd6bc20e4 11 #define SEARCH_ROM 0xF0
sroy 0:7c6dd6bc20e4 12
sroy 0:7c6dd6bc20e4 13 // type used to represent a one-wire rom code
sroy 0:7c6dd6bc20e4 14 typedef unsigned long long OneWire_ROM;
sroy 0:7c6dd6bc20e4 15
sroy 0:7c6dd6bc20e4 16 // types used for the one-wire registers
sroy 0:7c6dd6bc20e4 17 typedef struct TransportRead{
sroy 0:7c6dd6bc20e4 18 unsigned char read; // bits or rom read
sroy 0:7c6dd6bc20e4 19 unsigned char crc8; // crc8 check
sroy 0:7c6dd6bc20e4 20 } TransportRead;
sroy 0:7c6dd6bc20e4 21
sroy 0:7c6dd6bc20e4 22 /** Persistant search structure
sroy 0:7c6dd6bc20e4 23 * Used to keep track of search state and results between executions of the search transport layer command
sroy 0:7c6dd6bc20e4 24 */
sroy 0:7c6dd6bc20e4 25 typedef struct TransportSearchPersist{
sroy 0:7c6dd6bc20e4 26 /** Rom code result of previous search operation
sroy 0:7c6dd6bc20e4 27 *
sroy 0:7c6dd6bc20e4 28 * @note value should be ignored if a one-wire execution error occured
sroy 0:7c6dd6bc20e4 29 */
sroy 0:7c6dd6bc20e4 30 OneWire_ROM rom;
sroy 0:7c6dd6bc20e4 31
sroy 0:7c6dd6bc20e4 32 signed char last; // used internally by the micro instruction system to keep track of state
sroy 0:7c6dd6bc20e4 33
sroy 0:7c6dd6bc20e4 34 /** Used to tell when to end a search sequence
sroy 0:7c6dd6bc20e4 35 *
sroy 0:7c6dd6bc20e4 36 * TRUE when the search has completed
sroy 0:7c6dd6bc20e4 37 *
sroy 0:7c6dd6bc20e4 38 * FALSE when there are still rom codes left to search
sroy 0:7c6dd6bc20e4 39 */
sroy 0:7c6dd6bc20e4 40 bool done;
sroy 0:7c6dd6bc20e4 41
sroy 0:7c6dd6bc20e4 42 /** Clears existing search state and results in preparation for a new search
sroy 0:7c6dd6bc20e4 43 *
sroy 0:7c6dd6bc20e4 44 * This will reset search progress to start a search sequence from the beginning
sroy 0:7c6dd6bc20e4 45 *
sroy 0:7c6dd6bc20e4 46 * @note Search sequences should be restarted if a one-wire execution error occured as persistant state values might be invalid
sroy 0:7c6dd6bc20e4 47 */
sroy 0:7c6dd6bc20e4 48 void clear();
sroy 0:7c6dd6bc20e4 49 } TransportSearchPersist;
sroy 0:7c6dd6bc20e4 50
sroy 0:7c6dd6bc20e4 51 typedef struct TransportSearch{
sroy 0:7c6dd6bc20e4 52 unsigned char read; // bits or rom read
sroy 0:7c6dd6bc20e4 53 unsigned char crc8; // crc8 check
sroy 0:7c6dd6bc20e4 54 signed char marker; // last conflict marker
sroy 0:7c6dd6bc20e4 55 unsigned char bit; // storage place current bit result
sroy 0:7c6dd6bc20e4 56 } TransportSearch;
sroy 0:7c6dd6bc20e4 57
sroy 0:7c6dd6bc20e4 58 /** One-Wire Transport layer class
sroy 0:7c6dd6bc20e4 59 * Used to set up a one-wire instruction with a transport layer
sroy 0:7c6dd6bc20e4 60 */
sroy 0:7c6dd6bc20e4 61 class OWTransport{
sroy 0:7c6dd6bc20e4 62 public:
sroy 0:7c6dd6bc20e4 63 /** Set a one-wire instruction to perform the read transport layer command
sroy 0:7c6dd6bc20e4 64 *
sroy 0:7c6dd6bc20e4 65 * @param inst One-wire instruction that will carry out the command
sroy 0:7c6dd6bc20e4 66 * @param out One-wire rom that will be used to store the read rom code
sroy 0:7c6dd6bc20e4 67 */
sroy 0:7c6dd6bc20e4 68 static void read(OneWire_Instruction * inst, OneWire_ROM * out);
sroy 0:7c6dd6bc20e4 69
sroy 0:7c6dd6bc20e4 70 /** Set a one-wire instruction to perform the search transport layer command
sroy 0:7c6dd6bc20e4 71 *
sroy 0:7c6dd6bc20e4 72 * @param inst One-wire instruction that will carry out the command
sroy 0:7c6dd6bc20e4 73 * @param search Persistant search structure that will be used for search state and results
sroy 0:7c6dd6bc20e4 74 */
sroy 0:7c6dd6bc20e4 75 static void search(OneWire_Instruction * inst, TransportSearchPersist * search);
sroy 0:7c6dd6bc20e4 76 private:
sroy 0:7c6dd6bc20e4 77 // private functions which carry out the one-wire logic
sroy 0:7c6dd6bc20e4 78 static void _inst_readsetup(OneWire * which);
sroy 0:7c6dd6bc20e4 79 static void _inst_read(OneWire * which);
sroy 0:7c6dd6bc20e4 80 static void _inst_readhandler(OneWire * which, char bit);
sroy 0:7c6dd6bc20e4 81 static void _inst_searchsetup(OneWire * which);
sroy 0:7c6dd6bc20e4 82 static void _inst_search(OneWire * which);
sroy 0:7c6dd6bc20e4 83 static void _inst_searchhandler(OneWire * which, char bit);
sroy 0:7c6dd6bc20e4 84 };
sroy 0:7c6dd6bc20e4 85
sroy 0:7c6dd6bc20e4 86 #endif