Contiki 2.5
mspi-mgr.h
Go to the documentation of this file.
1 /* Copyright (c) 2010, Ulf Kulau
2  *
3  * Permission is hereby granted, free of charge, to any person
4  * obtaining a copy of this software and associated documentation
5  * files (the "Software"), to deal in the Software without
6  * restriction, including without limitation the rights to use,
7  * copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following
10  * conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 /**
26  * \addtogroup Drivers
27  * @{
28  *
29  * \defgroup spi_bus_manager Master SPI Bus Manager
30  *
31  * <p>The various SPI devices are all connected to the SPI Bus (SCK, MOSI/SDA,
32  * MISO/SDI) and only separated by the Chip Select. With a high probability,
33  * not every SPI Device will use the same SPI Bus configuration (SPI Mode), so
34  * you would have to change (or to check) the SPI mode whenever accessing another
35  * SPI device. But in higher software layers you are not interested in such
36  * details like SPI Mode. Therefore the SPI Bus Manager was implemented, to separate
37  * the low level hardware and register level from higher software layers.
38  * The SPI Bus Manager holds all devices, which are connected to the SPI Bus. With
39  * a checksum he can decide, if the SPI configuration has to change. So in some cases
40  * these reconfiguration can be avoid.</p>
41  * \note If you know what you are doing, it is possible to disable the SPI Bus Manager
42  * by setting MSPI_BUS_MANAGER in the mspi-drv.h to 0.
43  * @{
44  *
45  */
46 
47 /**
48  * \file
49  * Master SPI Bus Manager definitions
50  * \author
51  * Ulf Kulau <kulau@ibr.cs.tu-bs.de>
52  */
53 
54 #ifndef MSPIMGR_H_
55 #define MSPIMGR_H_
56 #include <avr/io.h>
57 
58 /*!
59  * Defines the maximum number of SPI devices
60  * \note In our case we have 7 (2³-1) possible SPI devices, because
61  * we are using 3 I/O pins and a BCD-to-decimal encoder for the
62  * chip select.
63  */
64 #define MAX_SPI_DEVICES 7
65 
66 typedef struct {
67  uint8_t dev_mode;
68  uint16_t dev_baud;
69  uint8_t checksum;
70 }spi_dev;
71 /*!
72  * SPI Device Table: Holds the information about the SPI devices.
73  * \note Index contains Chip Select information
74  */
75 static spi_dev spi_bus_config[MAX_SPI_DEVICES];
76 
77 /*!
78  * Holds the current SPI-Bus configuration
79  */
80 static uint8_t spi_current_config = 0xFF;
81 
82 /**
83  * \brief This function add a device to the SPI device table
84  * and calculates the specific checksum
85  *
86  * \param cs Chip Select: Device ID
87  * \param mode Select the (M)SPI mode (MSPI_MODE_0 ...
88  * MSPI_MODE_3)
89  * \param baud The MSPI BAUD rate. Sometimes it is necessary
90  * to reduce the SCK. Use MSPI_BAUD_MAX in common case.
91  *
92  */
93 void add_to_spi_mgr(uint8_t cs, uint8_t mode, uint16_t baud);
94 
95 /**
96  * \brief This function changes the SPI configuration
97  *
98  * \param spi_dev The specified entry of the SPI Device Table
99  *
100  */
101 void change_spi_mode(spi_dev new_config);
102 
103 
104 
105 
106 
107 #endif /* SPIMGR_H_ */