ConOpSys V2970  P004.07
ANVILEX control operating system
SPI_Master_Base.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 //! @file SPI_Master_Base.h
3 //! @brief SPI bus master base class header file.
4 //! @attention No special attention requered.
5 //! @copyright (C) 2015-2020 ANVILEX LLC
6 //! $HeadURL: https://192.168.3.4:8443/svn/P004_07/ConOpSys/Engine/SPI_Master_Base.h $
7 //! $Revision: 2821 $
8 //! $Date: 2021-07-26 18:16:22 +0500 (Mo, 26 Jul 2021) $
9 //! $Author: ggavrituhin $
10 //------------------------------------------------------------------------------
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are met:
14 //
15 // 1. Redistributions of source code must retain the above copyright notice,
16 // this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright notice,
19 // this list of conditions and the following disclaimer in the documentation
20 // and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of ANVILEX nor the names of its contributors may be
23 // used to endorse or promote products derived from this software without
24 // specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 // POSSIBILITY OF SUCH DAMAGE.
37 //
38 //------------------------------------------------------------------------------
39 
40 //------------------------------------------------------------------------------
41 // Protecting header files from mutual, recursive inclusion.
42 //------------------------------------------------------------------------------
43 
44 #pragma once
45 
46 //------------------------------------------------------------------------------
47 // Include project files
48 //------------------------------------------------------------------------------
49 
50 #include "Defines.h"
51 
52 //------------------------------------------------------------------------------
53 // Class definitions
54 //------------------------------------------------------------------------------
55 
56 //! @brief SPI master base class
58 {
59 
60  //----------------------------------------------------------------------------
61  // Public defines, methods and variables
62  //----------------------------------------------------------------------------
63 
64  public:
65 
66  //--------------------------------------------------------------------------
67  // Public methods
68  //--------------------------------------------------------------------------
69 
70  //!-------------------------------------------------------------------------
71  //! @brief Class constructor method
72  //! @note None
73  //! \par Override
74  //! Not allowed
75  //! @attention Don't call this method directly.
76  //--------------------------------------------------------------------------
77 
79 
80  //!-------------------------------------------------------------------------
81  //! @brief Class destructor method
82  //! @note None
83  //! \par Override
84  //! Not allowed
85  //! @attention Don't call this method directly.
86  //--------------------------------------------------------------------------
87 
88  virtual ~TSPI_Master_Base();
89 
90  //!-------------------------------------------------------------------------
91  //! @brief SPI bus initialisation method
92  //! @note None
93  //! @return None
94  //! \par Override
95  //! Requered
96  //! @attention None
97  //--------------------------------------------------------------------------
98 
99  virtual VOID Init() = 0;
100 
101  //!-------------------------------------------------------------------------
102  //! @brief SPI bus finalisation method
103  //! @note Override method must initialise hardware dependent SPI bus unit and related GPIO.
104  //! @return None
105  //! \par Override
106  //! Requered
107  //! @attention None
108  //--------------------------------------------------------------------------
109 
110  VOID Done();
111 
112  //!-------------------------------------------------------------------------
113  //! @brief PIO initialisation method
114  //! @note None
115  //! @return None
116  //! \par Override
117  //! Not allowed
118  //! @attention None
119  //--------------------------------------------------------------------------
120 
121  virtual VOID PIO_Init() = 0;
122 
123  //!-------------------------------------------------------------------------
124  //! @brief PIO reinitialisation as GPIO method
125  //! @note None
126  //! @return None
127  //! \par Override
128  //! Not allowed
129  //! @attention None
130  //--------------------------------------------------------------------------
131 
132  virtual VOID PIO_Done() = 0;
133 
134  //!-------------------------------------------------------------------------
135  //! @brief Start SPI bus operation method
136  //! @note Start SPI bus opearation.
137  //! @return None
138  //! \par Override
139  //! Requered
140  //! @attention None
141  //--------------------------------------------------------------------------
142 
143  virtual VOID Start() = 0;
144 
145  //!-------------------------------------------------------------------------
146  //! @brief Stop SPI bus operation method
147  //! @note Stops SPI bus operation.
148  //! @return None
149  //! \par Override
150  //! Requered
151  //! @attention None
152  //--------------------------------------------------------------------------
153 
154  virtual VOID Stop() = 0;
155 
156  //!-------------------------------------------------------------------------
157  //! @brief Activate (set to 0) SPI bus chip select signal
158  //! @note None
159  //! @return None
160  //! \par Override
161  //! Requered
162  //! @attention None
163  //--------------------------------------------------------------------------
164 
165  virtual VOID CS_Activate() = 0;
166 
167  //!-------------------------------------------------------------------------
168  //! @brief Deactivate (set to 1) SPI bus chip select signal
169  //! @note None
170  //! @return None
171  //! \par Override
172  //! Requered
173  //! @attention None
174  //--------------------------------------------------------------------------
175 
176  virtual VOID CS_Deactivate() = 0;
177 
178  //!-------------------------------------------------------------------------
179  //! @brief Send byte and receive byte over SPI bus at some time
180  //! @note None
181  //! @param [in] u8_Byte_To_Send - Byte to send
182  //! @param [in] *u8_Byte_To_Receive - Pointer to the byte to receive
183  //! @return None
184  //! \par Override
185  //! Requered
186  //! @attention None
187  //--------------------------------------------------------------------------
188 
189  virtual VOID Transfer_Byte( U8 u8_Byte_To_Send, U8 *u8_Byte_To_Receive );
190 
191  //!-------------------------------------------------------------------------
192  //! @brief Send byte over SPI bus
193  //! @note None
194  //! @param [in] u8_Byte_To_Send - Byte to send
195  //! @return None
196  //! \par Override
197  //! Requered
198  //! @attention None
199  //--------------------------------------------------------------------------
200 
201  virtual VOID Send_Byte( U8 u8_Byte_To_Send ) = 0;
202 
203  //!-------------------------------------------------------------------------
204  //! @brief Receive byte over SPI bus
205  //! @note Function sent 0x00 over SPI bus during receiving.
206  //! @param [in] *u8_Byte_To_Receive - Pointer to the byte to receive
207  //! @return None
208  //! \par Override
209  //! Requered
210  //! @attention None
211  //--------------------------------------------------------------------------
212 
213  virtual VOID Receive_Byte( U8 *u8_Byte_To_Receive ) = 0;
214 
215  //!-------------------------------------------------------------------------
216  //! @brief Verify byte over SPI bus
217  //! @note None
218  //! @param [in] u8_Byte_To_Verify - Byte to verify
219  //! @return BOOL - Verify operation status
220  //! @retval false - Verification error, bytes is different
221  //! @retval true - Verification cuccessed, bytes is equal
222  //! \par Override
223  //! Not allowed
224  //! @attention None
225  //--------------------------------------------------------------------------
226 
227  virtual BOOL Verify_Byte( U8 u8_Byte_To_Verify ) = 0;
228 
229  //!-------------------------------------------------------------------------
230  //! @brief Send buffer and receive buffer over SPI bus at some time
231  //! @note None
232  //! @param [in] *u8_Buffer_To_Send - Pointer to the buffer to send
233  //! @param [in] *u8_Buffer_To_Receive - Pointer to the buffer to receive
234  //! @param [in] u16_Length - Length of the send and receive buffer.
235  //! @return None
236  //! \par Override
237  //! Not allowed
238  //! @attention Length of the send and length of the receive buffer must be the equal.
239  //--------------------------------------------------------------------------
240 
241  VOID Transfer_Buffer( U8 *u8_Buffer_To_Send, U8 *u8_Buffer_To_Receive, U16 u16_Length );
242 
243  //!-------------------------------------------------------------------------
244  //! @brief Set transmit mode method
245  //! @note None
246  //! @return None
247  //! \par Override
248  //! Requered
249  //! @attention None
250  //--------------------------------------------------------------------------
251 
252  virtual VOID Set_Transmit_Mode();
253 
254  //!-------------------------------------------------------------------------
255  //! @brief Set receive mode method
256  //! @note None
257  //! @return None
258  //! \par Override
259  //! Requered
260  //! @attention None
261  //--------------------------------------------------------------------------
262 
263  virtual VOID Set_Receive_Mode();
264 
265  //!-------------------------------------------------------------------------
266  //! @brief Set MOSI in high state
267  //! @note None
268  //! @return None
269  //! \par Override
270  //! Requered
271  //! @attention None
272  //--------------------------------------------------------------------------
273 
274  virtual VOID Set_MOSI();
275 
276  //!-------------------------------------------------------------------------
277  //! @brief Set MOSI in low state
278  //! @note None
279  //! @return None
280  //! \par Override
281  //! Requered
282  //! @attention None
283  //--------------------------------------------------------------------------
284 
285  virtual VOID Clear_MOSI();
286 
287  //!-------------------------------------------------------------------------
288  //! @brief Set clock in low state
289  //! @note None
290  //! @return None
291  //! \par Override
292  //! Requered
293  //! @attention None
294  //--------------------------------------------------------------------------
295 
296  virtual VOID Clear_Clock();
297 
298  //!-------------------------------------------------------------------------
299  //! @brief Set clock in high state
300  //! @note None
301  //! @return None
302  //! \par Override
303  //! Requered
304  //! @attention None
305  //--------------------------------------------------------------------------
306 
307  virtual VOID Set_Clock();
308 
309  //!-------------------------------------------------------------------------
310  //! @brief Get MISO pin state
311  //! @note None
312  //! @return None
313  //! \par Override
314  //! Requered
315  //! @attention None
316  //--------------------------------------------------------------------------
317 
318  virtual BOOL Get_MISO();
319 
320  //----------------------------------------------------------------------------
321  // Protected defines, methods and variables
322  //----------------------------------------------------------------------------
323 
324  protected:
325 
326  //--------------------------------------------------------------------------
327  // Protected variables
328  //--------------------------------------------------------------------------
329 
330  //! @brief Object initialisation status
332 
333  //----------------------------------------------------------------------------
334  // Private defines, methods and variables
335  //----------------------------------------------------------------------------
336 
337  private:
338 
339 };
340 
341 //------------------------------------------------------------------------------
342 // End of file
343 //------------------------------------------------------------------------------
ConOpSys data type definitions header file.
int BOOL
Boolean datatype definition.
Definition: Defines.h:124
unsigned char U8
Binary 8-Bit unsigned integer datatype defenition.
Definition: Defines.h:183
void VOID
Datatypesess datatype definition.
Definition: Defines.h:105
unsigned short U16
Binary 16-Bit unsigned integer datatype defenition.
Definition: Defines.h:193
SPI master base class.
Definition: SPI_Master_Base.h:58
virtual ~TSPI_Master_Base()
Class destructor method.
Definition: SPI_Master_Base.cpp:64
virtual BOOL Get_MISO()
Get MISO pin state.
Definition: SPI_Master_Base.cpp:173
virtual VOID Receive_Byte(U8 *u8_Byte_To_Receive)=0
Receive byte over SPI bus.
virtual VOID Set_Transmit_Mode()
Set transmit mode method.
Definition: SPI_Master_Base.cpp:117
virtual VOID Init()=0
SPI bus initialisation method.
VOID Done()
SPI bus finalisation method.
Definition: SPI_Master_Base.cpp:72
virtual VOID Clear_Clock()
Set clock in low state.
Definition: SPI_Master_Base.cpp:157
virtual VOID Stop()=0
Stop SPI bus operation method.
virtual VOID CS_Activate()=0
Activate (set to 0) SPI bus chip select signal.
BOOL bool_Initialised
Object initialisation status.
Definition: SPI_Master_Base.h:331
VOID Transfer_Buffer(U8 *u8_Buffer_To_Send, U8 *u8_Buffer_To_Receive, U16 u16_Length)
Send buffer and receive buffer over SPI bus at some time.
Definition: SPI_Master_Base.cpp:93
virtual VOID Set_MOSI()
Set MOSI in high state.
Definition: SPI_Master_Base.cpp:141
virtual VOID Set_Clock()
Set clock in high state.
Definition: SPI_Master_Base.cpp:165
virtual BOOL Verify_Byte(U8 u8_Byte_To_Verify)=0
Verify byte over SPI bus.
TSPI_Master_Base()
Class constructor method.
Definition: SPI_Master_Base.cpp:56
virtual VOID Clear_MOSI()
Set MOSI in low state.
Definition: SPI_Master_Base.cpp:149
virtual VOID Start()=0
Start SPI bus operation method.
virtual VOID Send_Byte(U8 u8_Byte_To_Send)=0
Send byte over SPI bus.
virtual VOID Transfer_Byte(U8 u8_Byte_To_Send, U8 *u8_Byte_To_Receive)
Send byte and receive byte over SPI bus at some time.
Definition: SPI_Master_Base.cpp:133
virtual VOID PIO_Init()=0
PIO initialisation method.
virtual VOID CS_Deactivate()=0
Deactivate (set to 1) SPI bus chip select signal.
virtual VOID Set_Receive_Mode()
Set receive mode method.
Definition: SPI_Master_Base.cpp:125
virtual VOID PIO_Done()=0
PIO reinitialisation as GPIO method.