OpenCores
URL https://opencores.org/ocsvn/i2cslave/i2cslave/trunk

Subversion Repositories i2cslave

[/] [i2cslave/] [trunk/] [sw/] [aardvark_c/] [aardvark.h] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 sfielding
/*=========================================================================
2
| Aardvark Interface Library
3
|--------------------------------------------------------------------------
4
| Copyright (c) 2002-2008 Total Phase, Inc.
5
| All rights reserved.
6
| www.totalphase.com
7
|
8
| Redistribution and use in source and binary forms, with or without
9
| modification, are permitted provided that the following conditions
10
| are met:
11
|
12
| - Redistributions of source code must retain the above copyright
13
|   notice, this list of conditions and the following disclaimer.
14
|
15
| - Redistributions in binary form must reproduce the above copyright
16
|   notice, this list of conditions and the following disclaimer in the
17
|   documentation and/or other materials provided with the distribution.
18
|
19
| - Neither the name of Total Phase, Inc. nor the names of its
20
|   contributors may be used to endorse or promote products derived from
21
|   this software without specific prior written permission.
22
|
23
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
| FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
27
| COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
| INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
| BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
| LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
| ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
| POSSIBILITY OF SUCH DAMAGE.
35
|--------------------------------------------------------------------------
36
| To access Aardvark devices through the API:
37
|
38
| 1) Use one of the following shared objects:
39
|      aardvark.so      --  Linux shared object
40
|      aardvark.dll     --  Windows dynamic link library
41
|
42
| 2) Along with one of the following language modules:
43
|      aardvark.c/h     --  C/C++ API header file and interface module
44
|      aardvark_py.py   --  Python API
45
|      aardvark.bas     --  Visual Basic 6 API
46
|      aardvark.cs      --  C# .NET source
47
|      aardvark_net.dll --  Compiled .NET binding
48
 ========================================================================*/
49
 
50
 
51
#ifndef __aardvark_h__
52
#define __aardvark_h__
53
 
54
#ifdef __cplusplus
55
extern "C" {
56
#endif
57
 
58
 
59
/*=========================================================================
60
| TYPEDEFS
61
 ========================================================================*/
62
#ifndef TOTALPHASE_DATA_TYPES
63
#define TOTALPHASE_DATA_TYPES
64
 
65
#ifndef _MSC_VER
66
/* C99-compliant compilers (GCC) */
67
#include <stdint.h>
68
typedef uint8_t   u08;
69
typedef uint16_t  u16;
70
typedef uint32_t  u32;
71
typedef uint64_t  u64;
72
typedef int8_t    s08;
73
typedef int16_t   s16;
74
typedef int32_t   s32;
75
typedef int64_t   s64;
76
 
77
#else
78
/* Microsoft compilers (Visual C++) */
79
typedef unsigned __int8   u08;
80
typedef unsigned __int16  u16;
81
typedef unsigned __int32  u32;
82
typedef unsigned __int64  u64;
83
typedef signed   __int8   s08;
84
typedef signed   __int16  s16;
85
typedef signed   __int32  s32;
86
typedef signed   __int64  s64;
87
 
88
#endif /* __MSC_VER */
89
 
90
#endif /* TOTALPHASE_DATA_TYPES */
91
 
92
 
93
/*=========================================================================
94
| DEBUG
95
 ========================================================================*/
96
/* Set the following macro to '1' for debugging */
97
#define AA_DEBUG 0
98
 
99
 
100
/*=========================================================================
101
| VERSION
102
 ========================================================================*/
103
#define AA_HEADER_VERSION  0x0500   /* v5.00 */
104
 
105
 
106
/*=========================================================================
107
| STATUS CODES
108
 ========================================================================*/
109
/*
110
 * All API functions return an integer which is the result of the
111
 * transaction, or a status code if negative.  The status codes are
112
 * defined as follows:
113
 */
114
enum AardvarkStatus {
115
    /* General codes (0 to -99) */
116
    AA_OK                        =    0,
117
    AA_UNABLE_TO_LOAD_LIBRARY    =   -1,
118
    AA_UNABLE_TO_LOAD_DRIVER     =   -2,
119
    AA_UNABLE_TO_LOAD_FUNCTION   =   -3,
120
    AA_INCOMPATIBLE_LIBRARY      =   -4,
121
    AA_INCOMPATIBLE_DEVICE       =   -5,
122
    AA_COMMUNICATION_ERROR       =   -6,
123
    AA_UNABLE_TO_OPEN            =   -7,
124
    AA_UNABLE_TO_CLOSE           =   -8,
125
    AA_INVALID_HANDLE            =   -9,
126
    AA_CONFIG_ERROR              =  -10,
127
 
128
    /* I2C codes (-100 to -199) */
129
    AA_I2C_NOT_AVAILABLE         = -100,
130
    AA_I2C_NOT_ENABLED           = -101,
131
    AA_I2C_READ_ERROR            = -102,
132
    AA_I2C_WRITE_ERROR           = -103,
133
    AA_I2C_SLAVE_BAD_CONFIG      = -104,
134
    AA_I2C_SLAVE_READ_ERROR      = -105,
135
    AA_I2C_SLAVE_TIMEOUT         = -106,
136
    AA_I2C_DROPPED_EXCESS_BYTES  = -107,
137
    AA_I2C_BUS_ALREADY_FREE      = -108,
138
 
139
    /* SPI codes (-200 to -299) */
140
    AA_SPI_NOT_AVAILABLE         = -200,
141
    AA_SPI_NOT_ENABLED           = -201,
142
    AA_SPI_WRITE_ERROR           = -202,
143
    AA_SPI_SLAVE_READ_ERROR      = -203,
144
    AA_SPI_SLAVE_TIMEOUT         = -204,
145
    AA_SPI_DROPPED_EXCESS_BYTES  = -205,
146
 
147
    /* GPIO codes (-400 to -499) */
148
    AA_GPIO_NOT_AVAILABLE        = -400,
149
 
150
    /* I2C bus monitor codes (-500 to -599) */
151
    AA_I2C_MONITOR_NOT_AVAILABLE = -500,
152
    AA_I2C_MONITOR_NOT_ENABLED   = -501
153
};
154
#ifndef __cplusplus
155
typedef enum AardvarkStatus AardvarkStatus;
156
#endif
157
 
158
 
159
/*=========================================================================
160
| GENERAL TYPE DEFINITIONS
161
 ========================================================================*/
162
/* Aardvark handle type definition */
163
typedef int Aardvark;
164
 
165
/*
166
 * Deprecated type definitions.
167
 *
168
 * These are only for use with legacy code and
169
 * should not be used for new development.
170
 */
171
typedef u08 aa_u08;
172
 
173
typedef u16 aa_u16;
174
 
175
typedef u32 aa_u32;
176
 
177
typedef s08 aa_s08;
178
 
179
typedef s16 aa_s16;
180
 
181
typedef s32 aa_s32;
182
 
183
/*
184
 * Aardvark version matrix.
185
 *
186
 * This matrix describes the various version dependencies
187
 * of Aardvark components.  It can be used to determine
188
 * which component caused an incompatibility error.
189
 *
190
 * All version numbers are of the format:
191
 *   (major << 8) | minor
192
 *
193
 * ex. v1.20 would be encoded as:  0x0114
194
 */
195
struct AardvarkVersion {
196
    /* Software, firmware, and hardware versions. */
197
    u16 software;
198
    u16 firmware;
199
    u16 hardware;
200
 
201
    /* Firmware requires that software must be >= this version. */
202
    u16 sw_req_by_fw;
203
 
204
    /* Software requires that firmware must be >= this version. */
205
    u16 fw_req_by_sw;
206
 
207
    /* Software requires that the API interface must be >= this version. */
208
    u16 api_req_by_sw;
209
};
210
#ifndef __cplusplus
211
typedef struct AardvarkVersion AardvarkVersion;
212
#endif
213
 
214
 
215
/*=========================================================================
216
| GENERAL API
217
 ========================================================================*/
218
/*
219
 * Get a list of ports to which Aardvark devices are attached.
220
 *
221
 * nelem   = maximum number of elements to return
222
 * devices = array into which the port numbers are returned
223
 *
224
 * Each element of the array is written with the port number.
225
 * Devices that are in-use are ORed with AA_PORT_NOT_FREE (0x8000).
226
 *
227
 * ex.  devices are attached to ports 0, 1, 2
228
 *      ports 0 and 2 are available, and port 1 is in-use.
229
 *      array => 0x0000, 0x8001, 0x0002
230
 *
231
 * If the array is NULL, it is not filled with any values.
232
 * If there are more devices than the array size, only the
233
 * first nmemb port numbers will be written into the array.
234
 *
235
 * Returns the number of devices found, regardless of the
236
 * array size.
237
 */
238
#define AA_PORT_NOT_FREE 0x8000
239
int aa_find_devices (
240
    int   num_devices,
241
    u16 * devices
242
);
243
 
244
 
245
/*
246
 * Get a list of ports to which Aardvark devices are attached.
247
 *
248
 * This function is the same as aa_find_devices() except that
249
 * it returns the unique IDs of each Aardvark device.  The IDs
250
 * are guaranteed to be non-zero if valid.
251
 *
252
 * The IDs are the unsigned integer representation of the 10-digit
253
 * serial numbers.
254
 */
255
int aa_find_devices_ext (
256
    int   num_devices,
257
    u16 * devices,
258
    int   num_ids,
259
    u32 * unique_ids
260
);
261
 
262
 
263
/*
264
 * Open the Aardvark port.
265
 *
266
 * The port number is a zero-indexed integer.
267
 *
268
 * The port number is the same as that obtained from the
269
 * aa_find_devices() function above.
270
 *
271
 * Returns an Aardvark handle, which is guaranteed to be
272
 * greater than zero if it is valid.
273
 *
274
 * This function is recommended for use in simple applications
275
 * where extended information is not required.  For more complex
276
 * applications, the use of aa_open_ext() is recommended.
277
 */
278
Aardvark aa_open (
279
    int port_number
280
);
281
 
282
 
283
/*
284
 * Open the Aardvark port, returning extended information
285
 * in the supplied structure.  Behavior is otherwise identical
286
 * to aa_open() above.  If 0 is passed as the pointer to the
287
 * structure, this function is exactly equivalent to aa_open().
288
 *
289
 * The structure is zeroed before the open is attempted.
290
 * It is filled with whatever information is available.
291
 *
292
 * For example, if the firmware version is not filled, then
293
 * the device could not be queried for its version number.
294
 *
295
 * This function is recommended for use in complex applications
296
 * where extended information is required.  For more simple
297
 * applications, the use of aa_open() is recommended.
298
 */
299
struct AardvarkExt {
300
    /* Version matrix */
301
    AardvarkVersion   version;
302
 
303
    /* Features of this device. */
304
    int               features;
305
};
306
#ifndef __cplusplus
307
typedef struct AardvarkExt AardvarkExt;
308
#endif
309
 
310
Aardvark aa_open_ext (
311
    int           port_number,
312
    AardvarkExt * aa_ext
313
);
314
 
315
 
316
/* Close the Aardvark port. */
317
int aa_close (
318
    Aardvark aardvark
319
);
320
 
321
 
322
/*
323
 * Return the port for this Aardvark handle.
324
 *
325
 * The port number is a zero-indexed integer.
326
 */
327
int aa_port (
328
    Aardvark aardvark
329
);
330
 
331
 
332
/*
333
 * Return the device features as a bit-mask of values, or
334
 * an error code if the handle is not valid.
335
 */
336
#define AA_FEATURE_SPI 0x00000001
337
#define AA_FEATURE_I2C 0x00000002
338
#define AA_FEATURE_GPIO 0x00000008
339
#define AA_FEATURE_I2C_MONITOR 0x00000010
340
int aa_features (
341
    Aardvark aardvark
342
);
343
 
344
 
345
/*
346
 * Return the unique ID for this Aardvark adapter.
347
 * IDs are guaranteed to be non-zero if valid.
348
 * The ID is the unsigned integer representation of the
349
 * 10-digit serial number.
350
 */
351
u32 aa_unique_id (
352
    Aardvark aardvark
353
);
354
 
355
 
356
/*
357
 * Return the status string for the given status code.
358
 * If the code is not valid or the library function cannot
359
 * be loaded, return a NULL string.
360
 */
361
const char * aa_status_string (
362
    int status
363
);
364
 
365
 
366
/*
367
 * Enable logging to a file.  The handle must be standard file
368
 * descriptor.  In C, a file descriptor can be obtained by using
369
 * the ANSI C function "open" or by using the function "fileno"
370
 * on a FILE* stream.  A FILE* stream can be obtained using "fopen"
371
 * or can correspond to the common "stdout" or "stderr" --
372
 * available when including stdlib.h
373
 */
374
int aa_log (
375
    Aardvark aardvark,
376
    int      level,
377
    int      handle
378
);
379
 
380
 
381
/*
382
 * Return the version matrix for the device attached to the
383
 * given handle.  If the handle is 0 or invalid, only the
384
 * software and required api versions are set.
385
 */
386
int aa_version (
387
    Aardvark          aardvark,
388
    AardvarkVersion * version
389
);
390
 
391
 
392
/*
393
 * Configure the device by enabling/disabling I2C, SPI, and
394
 * GPIO functions.
395
 */
396
enum AardvarkConfig {
397
    AA_CONFIG_GPIO_ONLY = 0x00,
398
    AA_CONFIG_SPI_GPIO  = 0x01,
399
    AA_CONFIG_GPIO_I2C  = 0x02,
400
    AA_CONFIG_SPI_I2C   = 0x03,
401
    AA_CONFIG_QUERY     = 0x80
402
};
403
#ifndef __cplusplus
404
typedef enum AardvarkConfig AardvarkConfig;
405
#endif
406
 
407
#define AA_CONFIG_SPI_MASK 0x00000001
408
#define AA_CONFIG_I2C_MASK 0x00000002
409
int aa_configure (
410
    Aardvark       aardvark,
411
    AardvarkConfig config
412
);
413
 
414
 
415
/*
416
 * Configure the target power pins.
417
 * This is only supported on hardware versions >= 2.00
418
 */
419
#define AA_TARGET_POWER_NONE 0x00
420
#define AA_TARGET_POWER_BOTH 0x03
421
#define AA_TARGET_POWER_QUERY 0x80
422
int aa_target_power (
423
    Aardvark aardvark,
424
    u08      power_mask
425
);
426
 
427
 
428
/*
429
 * Sleep for the specified number of milliseconds
430
 * Accuracy depends on the operating system scheduler
431
 * Returns the number of milliseconds slept
432
 */
433
u32 aa_sleep_ms (
434
    u32 milliseconds
435
);
436
 
437
 
438
 
439
/*=========================================================================
440
| ASYNC MESSAGE POLLING
441
 ========================================================================*/
442
/*
443
 * Polling function to check if there are any asynchronous
444
 * messages pending for processing. The function takes a timeout
445
 * value in units of milliseconds.  If the timeout is < 0, the
446
 * function will block until data is received.  If the timeout is 0,
447
 * the function will perform a non-blocking check.
448
 */
449
#define AA_ASYNC_NO_DATA 0x00000000
450
#define AA_ASYNC_I2C_READ 0x00000001
451
#define AA_ASYNC_I2C_WRITE 0x00000002
452
#define AA_ASYNC_SPI 0x00000004
453
#define AA_ASYNC_I2C_MONITOR 0x00000008
454
int aa_async_poll (
455
    Aardvark aardvark,
456
    int      timeout
457
);
458
 
459
 
460
 
461
/*=========================================================================
462
| I2C API
463
 ========================================================================*/
464
/* Free the I2C bus. */
465
int aa_i2c_free_bus (
466
    Aardvark aardvark
467
);
468
 
469
 
470
/*
471
 * Set the I2C bit rate in kilohertz.  If a zero is passed as the
472
 * bitrate, the bitrate is unchanged and the current bitrate is
473
 * returned.
474
 */
475
int aa_i2c_bitrate (
476
    Aardvark aardvark,
477
    int      bitrate_khz
478
);
479
 
480
 
481
/*
482
 * Set the bus lock timeout.  If a zero is passed as the timeout,
483
 * the timeout is unchanged and the current timeout is returned.
484
 */
485
int aa_i2c_bus_timeout (
486
    Aardvark aardvark,
487
    u16      timeout_ms
488
);
489
 
490
 
491
enum AardvarkI2cFlags {
492
    AA_I2C_NO_FLAGS          = 0x00,
493
    AA_I2C_10_BIT_ADDR       = 0x01,
494
    AA_I2C_COMBINED_FMT      = 0x02,
495
    AA_I2C_NO_STOP           = 0x04,
496
    AA_I2C_SIZED_READ        = 0x10,
497
    AA_I2C_SIZED_READ_EXTRA1 = 0x20
498
};
499
#ifndef __cplusplus
500
typedef enum AardvarkI2cFlags AardvarkI2cFlags;
501
#endif
502
 
503
/* Read a stream of bytes from the I2C slave device. */
504
int aa_i2c_read (
505
    Aardvark         aardvark,
506
    u16              slave_addr,
507
    AardvarkI2cFlags flags,
508
    u16              num_bytes,
509
    u08 *            data_in
510
);
511
 
512
 
513
enum AardvarkI2cStatus {
514
    AA_I2C_STATUS_OK            = 0,
515
    AA_I2C_STATUS_BUS_ERROR     = 1,
516
    AA_I2C_STATUS_SLA_ACK       = 2,
517
    AA_I2C_STATUS_SLA_NACK      = 3,
518
    AA_I2C_STATUS_DATA_NACK     = 4,
519
    AA_I2C_STATUS_ARB_LOST      = 5,
520
    AA_I2C_STATUS_BUS_LOCKED    = 6,
521
    AA_I2C_STATUS_LAST_DATA_ACK = 7
522
};
523
#ifndef __cplusplus
524
typedef enum AardvarkI2cStatus AardvarkI2cStatus;
525
#endif
526
 
527
/*
528
 * Read a stream of bytes from the I2C slave device.
529
 * This API function returns the number of bytes read into
530
 * the num_read variable.  The return value of the function
531
 * is a status code.
532
 */
533
int aa_i2c_read_ext (
534
    Aardvark         aardvark,
535
    u16              slave_addr,
536
    AardvarkI2cFlags flags,
537
    u16              num_bytes,
538
    u08 *            data_in,
539
    u16 *            num_read
540
);
541
 
542
 
543
/* Write a stream of bytes to the I2C slave device. */
544
int aa_i2c_write (
545
    Aardvark         aardvark,
546
    u16              slave_addr,
547
    AardvarkI2cFlags flags,
548
    u16              num_bytes,
549
    const u08 *      data_out
550
);
551
 
552
 
553
/*
554
 * Write a stream of bytes to the I2C slave device.
555
 * This API function returns the number of bytes written into
556
 * the num_written variable.  The return value of the function
557
 * is a status code.
558
 */
559
int aa_i2c_write_ext (
560
    Aardvark         aardvark,
561
    u16              slave_addr,
562
    AardvarkI2cFlags flags,
563
    u16              num_bytes,
564
    const u08 *      data_out,
565
    u16 *            num_written
566
);
567
 
568
 
569
/* Enable/Disable the Aardvark as an I2C slave device */
570
int aa_i2c_slave_enable (
571
    Aardvark aardvark,
572
    u08      addr,
573
    u16      maxTxBytes,
574
    u16      maxRxBytes
575
);
576
 
577
 
578
int aa_i2c_slave_disable (
579
    Aardvark aardvark
580
);
581
 
582
 
583
/*
584
 * Set the slave response in the event the Aardvark is put
585
 * into slave mode and contacted by a Master.
586
 */
587
int aa_i2c_slave_set_response (
588
    Aardvark    aardvark,
589
    u08         num_bytes,
590
    const u08 * data_out
591
);
592
 
593
 
594
/*
595
 * Return number of bytes written from a previous
596
 * Aardvark->I2C_master transmission.  Since the transmission is
597
 * happening asynchronously with respect to the PC host
598
 * software, there could be responses queued up from many
599
 * previous write transactions.
600
 */
601
int aa_i2c_slave_write_stats (
602
    Aardvark aardvark
603
);
604
 
605
 
606
/* Read the bytes from an I2C slave reception */
607
int aa_i2c_slave_read (
608
    Aardvark aardvark,
609
    u08 *    addr,
610
    u16      num_bytes,
611
    u08 *    data_in
612
);
613
 
614
 
615
/* Extended functions that return status code */
616
int aa_i2c_slave_write_stats_ext (
617
    Aardvark aardvark,
618
    u16 *    num_written
619
);
620
 
621
 
622
int aa_i2c_slave_read_ext (
623
    Aardvark aardvark,
624
    u08 *    addr,
625
    u16      num_bytes,
626
    u08 *    data_in,
627
    u16 *    num_read
628
);
629
 
630
 
631
/*
632
 * Enable the I2C bus monitor
633
 * This disables all other functions on the Aardvark adapter
634
 */
635
int aa_i2c_monitor_enable (
636
    Aardvark aardvark
637
);
638
 
639
 
640
/* Disable the I2C bus monitor */
641
int aa_i2c_monitor_disable (
642
    Aardvark aardvark
643
);
644
 
645
 
646
/* Read the data collected by the bus monitor */
647
#define AA_I2C_MONITOR_DATA 0x00ff
648
#define AA_I2C_MONITOR_NACK 0x0100
649
#define AA_I2C_MONITOR_CMD_START 0xff00
650
#define AA_I2C_MONITOR_CMD_STOP 0xff01
651
int aa_i2c_monitor_read (
652
    Aardvark aardvark,
653
    u16      num_bytes,
654
    u16 *    data
655
);
656
 
657
 
658
/*
659
 * Configure the I2C pullup resistors.
660
 * This is only supported on hardware versions >= 2.00
661
 */
662
#define AA_I2C_PULLUP_NONE 0x00
663
#define AA_I2C_PULLUP_BOTH 0x03
664
#define AA_I2C_PULLUP_QUERY 0x80
665
int aa_i2c_pullup (
666
    Aardvark aardvark,
667
    u08      pullup_mask
668
);
669
 
670
 
671
 
672
/*=========================================================================
673
| SPI API
674
 ========================================================================*/
675
/*
676
 * Set the SPI bit rate in kilohertz.  If a zero is passed as the
677
 * bitrate, the bitrate is unchanged and the current bitrate is
678
 * returned.
679
 */
680
int aa_spi_bitrate (
681
    Aardvark aardvark,
682
    int      bitrate_khz
683
);
684
 
685
 
686
/*
687
 * These configuration parameters specify how to clock the
688
 * bits that are sent and received on the Aardvark SPI
689
 * interface.
690
 *
691
 *   The polarity option specifies which transition
692
 *   constitutes the leading edge and which transition is the
693
 *   falling edge.  For example, AA_SPI_POL_RISING_FALLING
694
 *   would configure the SPI to idle the SCK clock line low.
695
 *   The clock would then transition low-to-high on the
696
 *   leading edge and high-to-low on the trailing edge.
697
 *
698
 *   The phase option determines whether to sample or setup on
699
 *   the leading edge.  For example, AA_SPI_PHASE_SAMPLE_SETUP
700
 *   would configure the SPI to sample on the leading edge and
701
 *   setup on the trailing edge.
702
 *
703
 *   The bitorder option is used to indicate whether LSB or
704
 *   MSB is shifted first.
705
 *
706
 * See the diagrams in the Aardvark datasheet for
707
 * more details.
708
 */
709
enum AardvarkSpiPolarity {
710
    AA_SPI_POL_RISING_FALLING = 0,
711
    AA_SPI_POL_FALLING_RISING = 1
712
};
713
#ifndef __cplusplus
714
typedef enum AardvarkSpiPolarity AardvarkSpiPolarity;
715
#endif
716
 
717
enum AardvarkSpiPhase {
718
    AA_SPI_PHASE_SAMPLE_SETUP = 0,
719
    AA_SPI_PHASE_SETUP_SAMPLE = 1
720
};
721
#ifndef __cplusplus
722
typedef enum AardvarkSpiPhase AardvarkSpiPhase;
723
#endif
724
 
725
enum AardvarkSpiBitorder {
726
    AA_SPI_BITORDER_MSB = 0,
727
    AA_SPI_BITORDER_LSB = 1
728
};
729
#ifndef __cplusplus
730
typedef enum AardvarkSpiBitorder AardvarkSpiBitorder;
731
#endif
732
 
733
/* Configure the SPI master or slave interface */
734
int aa_spi_configure (
735
    Aardvark            aardvark,
736
    AardvarkSpiPolarity polarity,
737
    AardvarkSpiPhase    phase,
738
    AardvarkSpiBitorder bitorder
739
);
740
 
741
 
742
/* Write a stream of bytes to the downstream SPI slave device. */
743
int aa_spi_write (
744
    Aardvark    aardvark,
745
    u16         out_num_bytes,
746
    const u08 * data_out,
747
    u16         in_num_bytes,
748
    u08 *       data_in
749
);
750
 
751
 
752
/* Enable/Disable the Aardvark as an SPI slave device */
753
int aa_spi_slave_enable (
754
    Aardvark aardvark
755
);
756
 
757
 
758
int aa_spi_slave_disable (
759
    Aardvark aardvark
760
);
761
 
762
 
763
/*
764
 * Set the slave response in the event the Aardvark is put
765
 * into slave mode and contacted by a Master.
766
 */
767
int aa_spi_slave_set_response (
768
    Aardvark    aardvark,
769
    u08         num_bytes,
770
    const u08 * data_out
771
);
772
 
773
 
774
/* Read the bytes from an SPI slave reception */
775
int aa_spi_slave_read (
776
    Aardvark aardvark,
777
    u16      num_bytes,
778
    u08 *    data_in
779
);
780
 
781
 
782
/*
783
 * Change the output polarity on the SS line.
784
 *
785
 * Note: When configured as an SPI slave, the Aardvark will
786
 * always be setup with SS as active low.  Hence this function
787
 * only affects the SPI master functions on the Aardvark.
788
 */
789
enum AardvarkSpiSSPolarity {
790
    AA_SPI_SS_ACTIVE_LOW  = 0,
791
    AA_SPI_SS_ACTIVE_HIGH = 1
792
};
793
#ifndef __cplusplus
794
typedef enum AardvarkSpiSSPolarity AardvarkSpiSSPolarity;
795
#endif
796
 
797
int aa_spi_master_ss_polarity (
798
    Aardvark              aardvark,
799
    AardvarkSpiSSPolarity polarity
800
);
801
 
802
 
803
 
804
/*=========================================================================
805
| GPIO API
806
 ========================================================================*/
807
/*
808
 * The following enumerated type maps the named lines on the
809
 * Aardvark I2C/SPI line to bit positions in the GPIO API.
810
 * All GPIO API functions will index these lines through an
811
 * 8-bit masked value.  Thus, each bit position in the mask
812
 * can be referred back its corresponding line through the
813
 * enumerated type.
814
 */
815
enum AardvarkGpioBits {
816
    AA_GPIO_SCL  = 0x01,
817
    AA_GPIO_SDA  = 0x02,
818
    AA_GPIO_MISO = 0x04,
819
    AA_GPIO_SCK  = 0x08,
820
    AA_GPIO_MOSI = 0x10,
821
    AA_GPIO_SS   = 0x20
822
};
823
#ifndef __cplusplus
824
typedef enum AardvarkGpioBits AardvarkGpioBits;
825
#endif
826
 
827
/*
828
 * Configure the GPIO, specifying the direction of each bit.
829
 *
830
 * A call to this function will not change the value of the pullup
831
 * mask in the Aardvark.  This is illustrated by the following
832
 * example:
833
 *   (1) Direction mask is first set to 0x00
834
 *   (2) Pullup is set to 0x01
835
 *   (3) Direction mask is set to 0x01
836
 *   (4) Direction mask is later set back to 0x00.
837
 *
838
 * The pullup will be active after (4).
839
 *
840
 * On Aardvark power-up, the default value of the direction
841
 * mask is 0x00.
842
 */
843
#define AA_GPIO_DIR_INPUT 0
844
#define AA_GPIO_DIR_OUTPUT 1
845
int aa_gpio_direction (
846
    Aardvark aardvark,
847
    u08      direction_mask
848
);
849
 
850
 
851
/*
852
 * Enable an internal pullup on any of the GPIO input lines.
853
 *
854
 * Note: If a line is configured as an output, the pullup bit
855
 * for that line will be ignored, though that pullup bit will
856
 * be cached in case the line is later configured as an input.
857
 *
858
 * By default the pullup mask is 0x00.
859
 */
860
#define AA_GPIO_PULLUP_OFF 0
861
#define AA_GPIO_PULLUP_ON 1
862
int aa_gpio_pullup (
863
    Aardvark aardvark,
864
    u08      pullup_mask
865
);
866
 
867
 
868
/*
869
 * Read the current digital values on the GPIO input lines.
870
 *
871
 * The bits will be ordered as described by AA_GPIO_BITS.  If a
872
 * line is configured as an output, its corresponding bit
873
 * position in the mask will be undefined.
874
 */
875
int aa_gpio_get (
876
    Aardvark aardvark
877
);
878
 
879
 
880
/*
881
 * Set the outputs on the GPIO lines.
882
 *
883
 * Note: If a line is configured as an input, it will not be
884
 * affected by this call, but the output value for that line
885
 * will be cached in the event that the line is later
886
 * configured as an output.
887
 */
888
int aa_gpio_set (
889
    Aardvark aardvark,
890
    u08      value
891
);
892
 
893
 
894
/*
895
 * Block until there is a change on the GPIO input lines.
896
 * Pins configured as outputs will be ignored.
897
 *
898
 * The function will return either when a change has occurred or
899
 * the timeout expires.  The timeout, specified in millisecods, has
900
 * a precision of ~16 ms. The maximum allowable timeout is
901
 * approximately 4 seconds. If the timeout expires, this function
902
 * will return the current state of the GPIO lines.
903
 *
904
 * This function will return immediately with the current value
905
 * of the GPIO lines for the first invocation after any of the
906
 * following functions are called: aa_configure,
907
 * aa_gpio_direction, or aa_gpio_pullup.
908
 *
909
 * If the function aa_gpio_get is called before calling
910
 * aa_gpio_change, aa_gpio_change will only register any changes
911
 * from the value last returned by aa_gpio_get.
912
 */
913
int aa_gpio_change (
914
    Aardvark aardvark,
915
    u16      timeout
916
);
917
 
918
 
919
 
920
 
921
#ifdef __cplusplus
922
}
923
#endif
924
 
925
#endif  /* __aardvark_h__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.