NetBurner 3.5.6
PDF Version
ow.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
5#include <predef.h>
6#include <nbrtos.h>
7#include <init.h>
8#include <stdio.h>
9#include <ctype.h>
10#include <sim.h>
11#include <pins.h>
12#include <cfinter.h>
13
14#define OW_CR_PST 0x40 // Presence Set bit
15#define OW_CR_RPP 0x80 // Reset/Presence-detect pulse
16#define OW_IER_ERBF \
17 0x10 // Enable receiver buffer full interrupt, and
18 // Receive buffer full flag
19#define OW_IER_ETSE 0x08 // Enable transmit shift register empty interrupt
20#define OW_IER_ETBE 0x04 // Enable transmit buffer empty interrupt
21
22#ifndef OW_HPP_
23#define OW_HPP_
24
25/*
26 * OWState
27 * An enum type that defines the possible states of the 1-Wire module.
28 */
29enum OWState
30{
31 NOT_INIT = 0,
32 OK = 1,
33 READ = 2,
34 WRITE = 3
35};
36
37/*
38 * owDriverStruct
39 * This struct contains the state variables used for the 1-Wire driver.
40 *
41 * OW_State state - The state of the 1-Wire module. See the enumerated type
42 * above.
43 *
44 * uint8_t* buf - Points to the data buffer. This is the memory location
45 * from which data will be read or written to the peripheral.
46 *
47 * 8int8_t remLength - Counter that keeps track of the number of bytes
48 * that still need to be read or written.
49 *
50 * OS_SEM* sem - Pointer to the external semaphore for the OW_read and
51 * OW_write functions.
52 */
53struct owDriverStruct
54{
55 volatile OWState state;
56 volatile uint8_t *buf;
57 volatile int remLength;
58 OS_SEM *sem;
59
60 // Default constructor
61 owDriverStruct() : state(NOT_INIT), buf(NULL), remLength(0), sem(NULL) {}
62};
63
64/*
65 * 1-Wire interrupt service routine.
66 * Called by hardware when event occurs on the 1-Wire Module
67 */
68void OWMasterIsr();
69
70/*
71 * OWInit()
72 * This function initializes the 1-Wire module registers and sets up the
73 * interrupt service routine
74 */
75void OWInit();
76
77/*
78 * OWDetectDevices()
79 * Generates a reset pulse and listens for a response from external
80 * devices. Returns true if a device is detected, false otherwise
81 */
82bool OWDetectDevices();
83
84/*
85 * OWRead(uint8_t* data, int len, OS_SEM *sem)
86 * Reads len bytes from the 1-Wire Bus. Data points to the buffer
87 * to which the bytes are read. The function posts to the semaphore
88 * sem when complete (optional).
89 */
90OWState OWRead(uint8_t *data, int len, OS_SEM *sem = NULL);
91
92/*
93 * OWWrite(uint8_t* data, int len, OS_SEM *sem)
94 * Writes len bytes to the 1-Wire Bus. Data points to the buffer from
95 * which bytes are written. The function posts to the semaphore
96 * sem when complete (optional).
97 */
98OWState OWWrite(uint8_t *data, int len, OS_SEM *sem = NULL);
99
100/*
101 * OWDone()
102 * Returns true if the driver is ready to be used/read/write data on the bus
103 */
104bool OWDone();
105
106#endif /* OW_HPP_ */