summaryrefslogtreecommitdiff
path: root/digital/io/src/twi_master.h
blob: 143e872740a28dfb0803da832336e27caceaf8d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef twi_master_h
#define twi_master_h
/* twi_master.h */
/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
 *
 * Copyright (C) 2010 Nicolas Schodet
 *
 * APBTeam:
 *        Web: http://apbteam.org/
 *      Email: team AT apbteam DOT org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * }}} */

/**
 * Handle communication as a master to several slaves.
 *
 * The communication protocol is always based on:
 *  - a message sent to the slave with a command to execute,
 *  - a status read from the slave containing the current slave state.
 *
 * The first byte of all messages is a CRC of the following bytes, called the
 * message payload.
 *
 * The first byte of payload sent to slave is the command sequence number.  It
 * is used by the master to know if its command has been handled.  The last
 * handled command sequence number is available in the slave status (third
 * byte).
 *
 * As long as the slave last command sequence number is not equal to the last
 * sent sequence number, the master can not send any other command.  If the
 * slave do not acknowledge the command after a time out, the command is sent
 * again.
 *
 * Several commands can be stored by this module, it will defer their
 * transmission until the first command is acknowledged.
 */

/** Initialise module. */
void
twi_master_init (void);

/** Synchronise all slaves, return non zero if synchronised. */
uint8_t
twi_master_sync (void);

/** Get a buffer to send a command to the corresponding slave. */
uint8_t *
twi_master_get_buffer (uint8_t slave);

/** Send previously got buffer with the given length. */
void
twi_master_send (uint8_t length);

#endif /* twi_master_h */