ata6570  2.0.0.0
ata6570.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
32 // ----------------------------------------------------------------------------
33 
34 #ifndef ATA6570_H
35 #define ATA6570_H
36 
37 #include "mikrosdk_version.h"
38 
39 #ifdef __GNUC__
40 #if mikroSDK_GET_VERSION < 20800ul
41 #include "rcu_delays.h"
42 #else
43 #include "delays.h"
44 #endif
45 #endif
46 
47 #include "drv_digital_out.h"
48 #include "drv_digital_in.h"
49 #include "drv_spi_master.h"
50 #include "drv_uart.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define ATA6570_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX )
70 
77 #define ATA6570_RETVAL uint8_t
78 
79 #define ATA6570_OK 0x00
80 #define ATA6570_INIT_ERROR 0xFF
81 
87 #define DRV_RX_BUFFER_SIZE 500
88 
94 #define ATA6570_DMCR 0x01
95 #define ATA6570_DMSR 0x03
96 #define ATA6570_SECR 0x04
97 #define ATA6570_GPM0 0x06
98 #define ATA6570_GPM1 0x07
99 #define ATA6570_GPM2 0x08
100 #define ATA6570_GPM3 0x09
101 #define ATA6570_RWPR 0x0A
102 
108 #define ATA6570_TRXCR 0x20
109 #define ATA6570_TRXSR 0x22
110 #define ATA6570_TRXECR 0x23
111 #define ATA6570_DRCR 0x26
112 #define ATA6570_CIDR0 0x27
113 #define ATA6570_CIDR1 0x28
114 #define ATA6570_CIDR2 0x29
115 #define ATA6570_CIDR3 0x2A
116 #define ATA6570_CIDMR0 0x2B
117 #define ATA6570_CIDMR1 0x2C
118 #define ATA6570_CIDMR2 0x2D
119 #define ATA6570_CIDMR3 0x2E
120 #define ATA6570_CFCR 0x2F
121 #define ATA6570_BFECR 0x32
122 #define ATA6570_BFIR 0x33
123 #define ATA6570_TRXECR2 0x34
124 #define ATA6570_TRXESR2 0x35
125 #define ATA6570_WDCR1 0x36
126 #define ATA6570_WDCR2 0x37
127 #define ATA6570_WDSR 0x38
128 #define ATA6570_WDTRIG 0x39
129 #define ATA6570_EFCR 0x3A
130 #define ATA6570_FECR 0x3B
131 #define ATA6570_GLFT 0x67
132 #define ATA6570_CDMR0 0x68
133 #define ATA6570_CDMR1 0x69
134 #define ATA6570_CDMR2 0x6A
135 #define ATA6570_CDMR3 0x6B
136 #define ATA6570_CDMR4 0x6C
137 #define ATA6570_CDMR5 0x6D
138 #define ATA6570_CDMR6 0x6E
139 #define ATA6570_CDMR7 0x6F
140 #define ATA6570_PWKS 0x4B
141 #define ATA6570_WKECR 0x4C
142 #define ATA6570_GESR 0x60
143 #define ATA6570_SESR 0x61
144 #define ATA6570_WKESR 0x64
145 
151 #define ATA6570_DIDR 0x7E
152 
158 #define ATA6570_FUDI 0x70
159 #define ATA6570_FUDO 0x71
160 #define ATA6570_FUSEL 0x72
161 #define ATA6570_BGCAL 0x73
162 #define ATA6570_FRCCAL 0x74
163 #define ATA6570_HRCCALL 0x75
164 #define ATA6570_HRCCALH 0x76
165 
171 #define ATA6570_OPMODE_SLEEP 0x01
172 #define ATA6570_OPMODE_STBY 0x04
173 #define ATA6570_OPMODE_NORMAL 0x07
174  // End group macro
177 // --------------------------------------------------------------- PUBLIC TYPES
178 
182 typedef struct
183 {
184  // Output pins
185 
186  digital_out_t cs;
187 
188  // Modules
189 
190  spi_master_t spi;
191  pin_name_t chip_select;
192  uart_t uart;
193 
194  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
195  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
196 
197 } ata6570_t;
198 
202 typedef struct
203 {
204  // Communication gpio pins
205 
206  pin_name_t miso;
207  pin_name_t mosi;
208  pin_name_t sck;
209  pin_name_t cs;
210 
211  pin_name_t rx_pin;
212  pin_name_t tx_pin;
213 
214  // static variables
215 
216  // spi
217 
218  uint32_t spi_speed;
219  spi_master_mode_t spi_mode;
220  spi_master_chip_select_polarity_t cs_polarity;
221 
222  // uart
223 
224  uint32_t baud_rate; // Clock speed.
226  uart_data_bits_t data_bit; // Data bits.
227  uart_parity_t parity_bit; // Parity bit.
228  uart_stop_bits_t stop_bit; // Stop bits.
229 
230 } ata6570_cfg_t;
231  // End types group
233 
234 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
235 
240 #ifdef __cplusplus
241 extern "C"{
242 #endif
243 
253 
263 
275 void ata6570_generic_transfer ( ata6570_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
276 
283 void ata6570_generic_write ( ata6570_t *ctx, char *data_buf, uint16_t len );
284 
292 int32_t ata6570_generic_read ( ata6570_t *ctx, char *data_buf, uint16_t max_len );
293 
306 void ata6570_write_reg ( ata6570_t *ctx, const uint8_t address, uint8_t input );
307 
319 uint8_t ata6570_read_reg ( ata6570_t *ctx, const uint8_t address );
320 
321 #ifdef __cplusplus
322 }
323 #endif
324 #endif // _ATA6570_H_
325  // End public_function group
328 
329 // ------------------------------------------------------------------------- END
ATA6570_RETVAL
#define ATA6570_RETVAL
Definition: ata6570.h:77
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: ata6570.h:87
ata6570_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ata6570.h:226
ata6570_cfg_t::spi_speed
uint32_t spi_speed
Definition: ata6570.h:218
ata6570_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: ata6570.h:220
ata6570_cfg_t::cs
pin_name_t cs
Definition: ata6570.h:209
ata6570_generic_transfer
void ata6570_generic_transfer(ata6570_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
ata6570_t::spi
spi_master_t spi
Definition: ata6570.h:190
ata6570_generic_read
int32_t ata6570_generic_read(ata6570_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
ata6570_t::cs
digital_out_t cs
Definition: ata6570.h:186
ata6570_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ata6570.h:212
ata6570_generic_write
void ata6570_generic_write(ata6570_t *ctx, char *data_buf, uint16_t len)
Generic write function.
ata6570_cfg_t::miso
pin_name_t miso
Definition: ata6570.h:206
ata6570_t::chip_select
pin_name_t chip_select
Definition: ata6570.h:191
ata6570_cfg_t::uart_blocking
bool uart_blocking
Definition: ata6570.h:225
ata6570_cfg_t
Click configuration structure definition.
Definition: ata6570.h:203
ata6570_cfg_t::baud_rate
uint32_t baud_rate
Definition: ata6570.h:224
ata6570_init
ATA6570_RETVAL ata6570_init(ata6570_t *ctx, ata6570_cfg_t *cfg)
Initialization function.
ata6570_cfg_t::mosi
pin_name_t mosi
Definition: ata6570.h:207
ata6570_read_reg
uint8_t ata6570_read_reg(ata6570_t *ctx, const uint8_t address)
Read Register.
ata6570_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ata6570.h:211
ata6570_write_reg
void ata6570_write_reg(ata6570_t *ctx, const uint8_t address, uint8_t input)
Write Register.
ata6570_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ata6570.h:228
ata6570_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ata6570.h:227
ata6570_t::uart
uart_t uart
Definition: ata6570.h:192
ata6570_cfg_setup
void ata6570_cfg_setup(ata6570_cfg_t *cfg)
Config Object Initialization function.
ata6570_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: ata6570.h:219
ata6570_t
Click ctx object definition.
Definition: ata6570.h:183
ata6570_cfg_t::sck
pin_name_t sck
Definition: ata6570.h:208