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

Subversion Repositories i2cslave

[/] [i2cslave/] [trunk/] [sw/] [aardvark_c/] [aardvark.c] - 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
/*=========================================================================
52
| INCLUDES
53
 ========================================================================*/
54
/* This #include can be customized to conform to the user's build paths. */
55
#include "aardvark.h"
56
 
57
 
58
/*=========================================================================
59
| VERSION CHECK
60
 ========================================================================*/
61
#define AA_CFILE_VERSION   0x0500   /* v5.00 */
62
#define AA_REQ_SW_VERSION  0x0500   /* v5.00 */
63
 
64
/*
65
 * Make sure that the header file was included and that
66
 * the version numbers match.
67
 */
68
#ifndef AA_HEADER_VERSION
69
#  error Unable to include header file. Please check include path.
70
 
71
#elif AA_HEADER_VERSION != AA_CFILE_VERSION
72
#  error Version mismatch between source and header files.
73
 
74
#endif
75
 
76
 
77
/*=========================================================================
78
| DEFINES
79
 ========================================================================*/
80
#define API_NAME                     "aardvark"
81
#define API_DEBUG                    AA_DEBUG
82
#define API_OK                       AA_OK
83
#define API_UNABLE_TO_LOAD_LIBRARY   AA_UNABLE_TO_LOAD_LIBRARY
84
#define API_INCOMPATIBLE_LIBRARY     AA_INCOMPATIBLE_LIBRARY
85
#define API_UNABLE_TO_LOAD_FUNCTION  AA_UNABLE_TO_LOAD_FUNCTION
86
#define API_HEADER_VERSION           AA_HEADER_VERSION
87
#define API_REQ_SW_VERSION           AA_REQ_SW_VERSION
88
 
89
 
90
/*=========================================================================
91
| LINUX AND DARWIN SUPPORT
92
 ========================================================================*/
93
#if defined(__APPLE_CC__) && !defined(DARWIN)
94
#define DARWIN
95
#endif
96
 
97
#if defined(linux) || defined(DARWIN)
98
 
99
#include <stdio.h>
100
#include <stdlib.h>
101
#include <unistd.h>
102
#include <string.h>
103
#include <fcntl.h>
104
 
105
#ifdef DARWIN
106
#define DLOPEN_NO_WARN
107
extern int _NSGetExecutablePath (char *buf, unsigned long *bufsize);
108
#endif
109
 
110
#include <dlfcn.h>
111
 
112
#define DLL_HANDLE  void *
113
#define MAX_SO_PATH 256
114
 
115
static char SO_NAME[MAX_SO_PATH+1] = API_NAME ".so";
116
 
117
/*
118
 * These functions allow the Linux behavior to emulate
119
 * the Windows behavior as specified below in the Windows
120
 * support section.
121
 *
122
 * First, search for the shared object in the application
123
 * binary path, then in the current working directory.
124
 *
125
 * Searching the application binary path requires /proc
126
 * filesystem support, which is standard in 2.4.x kernels.
127
 *
128
 * If the /proc filesystem is not present, the shared object
129
 * will not be loaded from the execution path unless that path
130
 * is either the current working directory or explicitly
131
 * specified in LD_LIBRARY_PATH.
132
 */
133
static int _checkPath (const char *path) {
134
    char *filename = (char *)malloc(strlen(path) +1 + strlen(SO_NAME) +1);
135
    int   fd;
136
 
137
    // Check if the file is readable
138
    sprintf(filename, "%s/%s", path, SO_NAME);
139
    fd = open(filename, O_RDONLY);
140
    if (fd >= 0) {
141
        strncpy(SO_NAME, filename, MAX_SO_PATH);
142
        close(fd);
143
    }
144
 
145
    // Clean up and exit
146
    free(filename);
147
    return (fd >= 0);
148
}
149
 
150
static int _getExecPath (char *path, unsigned long maxlen) {
151
#ifdef linux
152
    return readlink("/proc/self/exe", path, maxlen);
153
#endif
154
 
155
#ifdef DARWIN
156
    _NSGetExecutablePath(path, &maxlen);
157
    return maxlen;
158
#endif
159
}
160
 
161
static void _setSearchPath () {
162
    char  path[MAX_SO_PATH+1];
163
    int   count;
164
    char *p;
165
 
166
    /* Make sure that SO_NAME is not an absolute path. */
167
    if (SO_NAME[0] == '/')  return;
168
 
169
    /* Check the execution directory name. */
170
    memset(path, 0, sizeof(path));
171
    count = _getExecPath(path, MAX_SO_PATH);
172
 
173
    if (count > 0) {
174
        char *p = strrchr(path, '/');
175
        if (p == path)  ++p;
176
        if (p != 0)     *p = '\0';
177
 
178
        /* If there is a match, return immediately. */
179
        if (_checkPath(path))  return;
180
    }
181
 
182
    /* Check the current working directory. */
183
    p = getcwd(path, MAX_SO_PATH);
184
    if (p != 0)  _checkPath(path);
185
}
186
 
187
#endif
188
 
189
 
190
/*=========================================================================
191
| WINDOWS SUPPORT
192
 ========================================================================*/
193
#if defined(WIN32) || defined(_WIN32)
194
 
195
#include <stdio.h>
196
#include <windows.h>
197
 
198
#define DLL_HANDLE           HINSTANCE
199
#define dlopen(name, flags)  LoadLibraryA(name)
200
#define dlsym(handle, name)  GetProcAddress(handle, name)
201
#define dlerror()            "Exiting program"
202
#define SO_NAME              API_NAME ".dll"
203
 
204
/*
205
 * Use the default Windows DLL loading rules:
206
 *   1.  The directory from which the application binary was loaded.
207
 *   2.  The application's current directory.
208
 *   3a. [Windows NT/2000/XP only] 32-bit system directory
209
 *       (default: c:\winnt\System32)
210
 *   3b. 16-bit system directory
211
 *       (default: c:\winnt\System or c:\windows\system)
212
 *   4.  The windows directory
213
 *       (default: c:\winnt or c:\windows)
214
 *   5.  The directories listed in the PATH environment variable
215
 */
216
static void _setSearchPath () {
217
    /* Do nothing */
218
}
219
 
220
#endif
221
 
222
 
223
/*=========================================================================
224
| SHARED LIBRARY LOADER
225
 ========================================================================*/
226
/* The error conditions can be customized depending on the application. */
227
static void *_loadFunction (const char *name, int *result) {
228
    static DLL_HANDLE handle = 0;
229
    void * function = 0;
230
 
231
    /* Load the shared library if necessary */
232
    if (handle == 0) {
233
        u32 (*version) (void);
234
        u16 sw_version;
235
        u16 api_version_req;
236
 
237
        _setSearchPath();
238
        handle = dlopen(SO_NAME, RTLD_LAZY);
239
        if (handle == 0) {
240
#if API_DEBUG
241
            fprintf(stderr, "Unable to load %s\n", SO_NAME);
242
            fprintf(stderr, "%s\n", dlerror());
243
#endif
244
            *result = API_UNABLE_TO_LOAD_LIBRARY;
245
            return 0;
246
        }
247
 
248
        version = (void *)dlsym(handle, "c_version");
249
        if (version == 0) {
250
#if API_DEBUG
251
            fprintf(stderr, "Unable to bind c_version() in %s\n",
252
                    SO_NAME);
253
            fprintf(stderr, "%s\n", dlerror());
254
#endif
255
            handle  = 0;
256
            *result = API_INCOMPATIBLE_LIBRARY;
257
            return 0;
258
        }
259
 
260
        sw_version      = (u16)((version() >>  0) & 0xffff);
261
        api_version_req = (u16)((version() >> 16) & 0xffff);
262
        if (sw_version  < API_REQ_SW_VERSION ||
263
            API_HEADER_VERSION < api_version_req)
264
        {
265
#if API_DEBUG
266
            fprintf(stderr, "\nIncompatible versions:\n");
267
 
268
            fprintf(stderr, "  Header version  = v%d.%02d  ",
269
                    (API_HEADER_VERSION >> 8) & 0xff, API_HEADER_VERSION & 0xff);
270
 
271
            if (sw_version < API_REQ_SW_VERSION)
272
                fprintf(stderr, "(requires library >= %d.%02d)\n",
273
                        (API_REQ_SW_VERSION >> 8) & 0xff,
274
                        API_REQ_SW_VERSION & 0xff);
275
            else
276
                fprintf(stderr, "(library version OK)\n");
277
 
278
 
279
            fprintf(stderr, "  Library version = v%d.%02d  ",
280
                    (sw_version >> 8) & 0xff,
281
                    (sw_version >> 0) & 0xff);
282
 
283
            if (API_HEADER_VERSION < api_version_req)
284
                fprintf(stderr, "(requires header >= %d.%02d)\n",
285
                        (api_version_req >> 8) & 0xff,
286
                        (api_version_req >> 0) & 0xff);
287
            else
288
                fprintf(stderr, "(header version OK)\n");
289
#endif
290
            handle  = 0;
291
            *result = API_INCOMPATIBLE_LIBRARY;
292
            return 0;
293
        }
294
    }
295
 
296
    /* Bind the requested function in the shared library */
297
    function = (void *)dlsym(handle, name);
298
    *result  = function ? API_OK : API_UNABLE_TO_LOAD_FUNCTION;
299
    return function;
300
}
301
 
302
 
303
/*=========================================================================
304
| FUNCTIONS
305
 ========================================================================*/
306
static int (*c_aa_find_devices) (int, u16 *) = 0;
307
int aa_find_devices (
308
    int   num_devices,
309
    u16 * devices
310
)
311
{
312
    if (c_aa_find_devices == 0) {
313
        int res = 0;
314
        if (!(c_aa_find_devices = _loadFunction("c_aa_find_devices", &res)))
315
            return res;
316
    }
317
    return c_aa_find_devices(num_devices, devices);
318
}
319
 
320
 
321
static int (*c_aa_find_devices_ext) (int, u16 *, int, u32 *) = 0;
322
int aa_find_devices_ext (
323
    int   num_devices,
324
    u16 * devices,
325
    int   num_ids,
326
    u32 * unique_ids
327
)
328
{
329
    if (c_aa_find_devices_ext == 0) {
330
        int res = 0;
331
        if (!(c_aa_find_devices_ext = _loadFunction("c_aa_find_devices_ext", &res)))
332
            return res;
333
    }
334
    return c_aa_find_devices_ext(num_devices, devices, num_ids, unique_ids);
335
}
336
 
337
 
338
static Aardvark (*c_aa_open) (int) = 0;
339
Aardvark aa_open (
340
    int port_number
341
)
342
{
343
    if (c_aa_open == 0) {
344
        int res = 0;
345
        if (!(c_aa_open = _loadFunction("c_aa_open", &res)))
346
            return res;
347
    }
348
    return c_aa_open(port_number);
349
}
350
 
351
 
352
static Aardvark (*c_aa_open_ext) (int, AardvarkExt *) = 0;
353
Aardvark aa_open_ext (
354
    int           port_number,
355
    AardvarkExt * aa_ext
356
)
357
{
358
    if (c_aa_open_ext == 0) {
359
        int res = 0;
360
        if (!(c_aa_open_ext = _loadFunction("c_aa_open_ext", &res)))
361
            return res;
362
    }
363
    return c_aa_open_ext(port_number, aa_ext);
364
}
365
 
366
 
367
static int (*c_aa_close) (Aardvark) = 0;
368
int aa_close (
369
    Aardvark aardvark
370
)
371
{
372
    if (c_aa_close == 0) {
373
        int res = 0;
374
        if (!(c_aa_close = _loadFunction("c_aa_close", &res)))
375
            return res;
376
    }
377
    return c_aa_close(aardvark);
378
}
379
 
380
 
381
static int (*c_aa_port) (Aardvark) = 0;
382
int aa_port (
383
    Aardvark aardvark
384
)
385
{
386
    if (c_aa_port == 0) {
387
        int res = 0;
388
        if (!(c_aa_port = _loadFunction("c_aa_port", &res)))
389
            return res;
390
    }
391
    return c_aa_port(aardvark);
392
}
393
 
394
 
395
static int (*c_aa_features) (Aardvark) = 0;
396
int aa_features (
397
    Aardvark aardvark
398
)
399
{
400
    if (c_aa_features == 0) {
401
        int res = 0;
402
        if (!(c_aa_features = _loadFunction("c_aa_features", &res)))
403
            return res;
404
    }
405
    return c_aa_features(aardvark);
406
}
407
 
408
 
409
static u32 (*c_aa_unique_id) (Aardvark) = 0;
410
u32 aa_unique_id (
411
    Aardvark aardvark
412
)
413
{
414
    if (c_aa_unique_id == 0) {
415
        int res = 0;
416
        if (!(c_aa_unique_id = _loadFunction("c_aa_unique_id", &res)))
417
            return res;
418
    }
419
    return c_aa_unique_id(aardvark);
420
}
421
 
422
 
423
static const char * (*c_aa_status_string) (int) = 0;
424
const char * aa_status_string (
425
    int status
426
)
427
{
428
    if (c_aa_status_string == 0) {
429
        int res = 0;
430
        if (!(c_aa_status_string = _loadFunction("c_aa_status_string", &res)))
431
            return 0;
432
    }
433
    return c_aa_status_string(status);
434
}
435
 
436
 
437
static int (*c_aa_log) (Aardvark, int, int) = 0;
438
int aa_log (
439
    Aardvark aardvark,
440
    int      level,
441
    int      handle
442
)
443
{
444
    if (c_aa_log == 0) {
445
        int res = 0;
446
        if (!(c_aa_log = _loadFunction("c_aa_log", &res)))
447
            return res;
448
    }
449
    return c_aa_log(aardvark, level, handle);
450
}
451
 
452
 
453
static int (*c_aa_version) (Aardvark, AardvarkVersion *) = 0;
454
int aa_version (
455
    Aardvark          aardvark,
456
    AardvarkVersion * version
457
)
458
{
459
    if (c_aa_version == 0) {
460
        int res = 0;
461
        if (!(c_aa_version = _loadFunction("c_aa_version", &res)))
462
            return res;
463
    }
464
    return c_aa_version(aardvark, version);
465
}
466
 
467
 
468
static int (*c_aa_configure) (Aardvark, AardvarkConfig) = 0;
469
int aa_configure (
470
    Aardvark       aardvark,
471
    AardvarkConfig config
472
)
473
{
474
    if (c_aa_configure == 0) {
475
        int res = 0;
476
        if (!(c_aa_configure = _loadFunction("c_aa_configure", &res)))
477
            return res;
478
    }
479
    return c_aa_configure(aardvark, config);
480
}
481
 
482
 
483
static int (*c_aa_target_power) (Aardvark, u08) = 0;
484
int aa_target_power (
485
    Aardvark aardvark,
486
    u08      power_mask
487
)
488
{
489
    if (c_aa_target_power == 0) {
490
        int res = 0;
491
        if (!(c_aa_target_power = _loadFunction("c_aa_target_power", &res)))
492
            return res;
493
    }
494
    return c_aa_target_power(aardvark, power_mask);
495
}
496
 
497
 
498
static u32 (*c_aa_sleep_ms) (u32) = 0;
499
u32 aa_sleep_ms (
500
    u32 milliseconds
501
)
502
{
503
    if (c_aa_sleep_ms == 0) {
504
        int res = 0;
505
        if (!(c_aa_sleep_ms = _loadFunction("c_aa_sleep_ms", &res)))
506
            return res;
507
    }
508
    return c_aa_sleep_ms(milliseconds);
509
}
510
 
511
 
512
static int (*c_aa_async_poll) (Aardvark, int) = 0;
513
int aa_async_poll (
514
    Aardvark aardvark,
515
    int      timeout
516
)
517
{
518
    if (c_aa_async_poll == 0) {
519
        int res = 0;
520
        if (!(c_aa_async_poll = _loadFunction("c_aa_async_poll", &res)))
521
            return res;
522
    }
523
    return c_aa_async_poll(aardvark, timeout);
524
}
525
 
526
 
527
static int (*c_aa_i2c_free_bus) (Aardvark) = 0;
528
int aa_i2c_free_bus (
529
    Aardvark aardvark
530
)
531
{
532
    if (c_aa_i2c_free_bus == 0) {
533
        int res = 0;
534
        if (!(c_aa_i2c_free_bus = _loadFunction("c_aa_i2c_free_bus", &res)))
535
            return res;
536
    }
537
    return c_aa_i2c_free_bus(aardvark);
538
}
539
 
540
 
541
static int (*c_aa_i2c_bitrate) (Aardvark, int) = 0;
542
int aa_i2c_bitrate (
543
    Aardvark aardvark,
544
    int      bitrate_khz
545
)
546
{
547
    if (c_aa_i2c_bitrate == 0) {
548
        int res = 0;
549
        if (!(c_aa_i2c_bitrate = _loadFunction("c_aa_i2c_bitrate", &res)))
550
            return res;
551
    }
552
    return c_aa_i2c_bitrate(aardvark, bitrate_khz);
553
}
554
 
555
 
556
static int (*c_aa_i2c_bus_timeout) (Aardvark, u16) = 0;
557
int aa_i2c_bus_timeout (
558
    Aardvark aardvark,
559
    u16      timeout_ms
560
)
561
{
562
    if (c_aa_i2c_bus_timeout == 0) {
563
        int res = 0;
564
        if (!(c_aa_i2c_bus_timeout = _loadFunction("c_aa_i2c_bus_timeout", &res)))
565
            return res;
566
    }
567
    return c_aa_i2c_bus_timeout(aardvark, timeout_ms);
568
}
569
 
570
 
571
static int (*c_aa_i2c_read) (Aardvark, u16, AardvarkI2cFlags, u16, u08 *) = 0;
572
int aa_i2c_read (
573
    Aardvark         aardvark,
574
    u16              slave_addr,
575
    AardvarkI2cFlags flags,
576
    u16              num_bytes,
577
    u08 *            data_in
578
)
579
{
580
    if (c_aa_i2c_read == 0) {
581
        int res = 0;
582
        if (!(c_aa_i2c_read = _loadFunction("c_aa_i2c_read", &res)))
583
            return res;
584
    }
585
    return c_aa_i2c_read(aardvark, slave_addr, flags, num_bytes, data_in);
586
}
587
 
588
 
589
static int (*c_aa_i2c_read_ext) (Aardvark, u16, AardvarkI2cFlags, u16, u08 *, u16 *) = 0;
590
int aa_i2c_read_ext (
591
    Aardvark         aardvark,
592
    u16              slave_addr,
593
    AardvarkI2cFlags flags,
594
    u16              num_bytes,
595
    u08 *            data_in,
596
    u16 *            num_read
597
)
598
{
599
    if (c_aa_i2c_read_ext == 0) {
600
        int res = 0;
601
        if (!(c_aa_i2c_read_ext = _loadFunction("c_aa_i2c_read_ext", &res)))
602
            return res;
603
    }
604
    return c_aa_i2c_read_ext(aardvark, slave_addr, flags, num_bytes, data_in, num_read);
605
}
606
 
607
 
608
static int (*c_aa_i2c_write) (Aardvark, u16, AardvarkI2cFlags, u16, const u08 *) = 0;
609
int aa_i2c_write (
610
    Aardvark         aardvark,
611
    u16              slave_addr,
612
    AardvarkI2cFlags flags,
613
    u16              num_bytes,
614
    const u08 *      data_out
615
)
616
{
617
    if (c_aa_i2c_write == 0) {
618
        int res = 0;
619
        if (!(c_aa_i2c_write = _loadFunction("c_aa_i2c_write", &res)))
620
            return res;
621
    }
622
    return c_aa_i2c_write(aardvark, slave_addr, flags, num_bytes, data_out);
623
}
624
 
625
 
626
static int (*c_aa_i2c_write_ext) (Aardvark, u16, AardvarkI2cFlags, u16, const u08 *, u16 *) = 0;
627
int aa_i2c_write_ext (
628
    Aardvark         aardvark,
629
    u16              slave_addr,
630
    AardvarkI2cFlags flags,
631
    u16              num_bytes,
632
    const u08 *      data_out,
633
    u16 *            num_written
634
)
635
{
636
    if (c_aa_i2c_write_ext == 0) {
637
        int res = 0;
638
        if (!(c_aa_i2c_write_ext = _loadFunction("c_aa_i2c_write_ext", &res)))
639
            return res;
640
    }
641
    return c_aa_i2c_write_ext(aardvark, slave_addr, flags, num_bytes, data_out, num_written);
642
}
643
 
644
 
645
static int (*c_aa_i2c_slave_enable) (Aardvark, u08, u16, u16) = 0;
646
int aa_i2c_slave_enable (
647
    Aardvark aardvark,
648
    u08      addr,
649
    u16      maxTxBytes,
650
    u16      maxRxBytes
651
)
652
{
653
    if (c_aa_i2c_slave_enable == 0) {
654
        int res = 0;
655
        if (!(c_aa_i2c_slave_enable = _loadFunction("c_aa_i2c_slave_enable", &res)))
656
            return res;
657
    }
658
    return c_aa_i2c_slave_enable(aardvark, addr, maxTxBytes, maxRxBytes);
659
}
660
 
661
 
662
static int (*c_aa_i2c_slave_disable) (Aardvark) = 0;
663
int aa_i2c_slave_disable (
664
    Aardvark aardvark
665
)
666
{
667
    if (c_aa_i2c_slave_disable == 0) {
668
        int res = 0;
669
        if (!(c_aa_i2c_slave_disable = _loadFunction("c_aa_i2c_slave_disable", &res)))
670
            return res;
671
    }
672
    return c_aa_i2c_slave_disable(aardvark);
673
}
674
 
675
 
676
static int (*c_aa_i2c_slave_set_response) (Aardvark, u08, const u08 *) = 0;
677
int aa_i2c_slave_set_response (
678
    Aardvark    aardvark,
679
    u08         num_bytes,
680
    const u08 * data_out
681
)
682
{
683
    if (c_aa_i2c_slave_set_response == 0) {
684
        int res = 0;
685
        if (!(c_aa_i2c_slave_set_response = _loadFunction("c_aa_i2c_slave_set_response", &res)))
686
            return res;
687
    }
688
    return c_aa_i2c_slave_set_response(aardvark, num_bytes, data_out);
689
}
690
 
691
 
692
static int (*c_aa_i2c_slave_write_stats) (Aardvark) = 0;
693
int aa_i2c_slave_write_stats (
694
    Aardvark aardvark
695
)
696
{
697
    if (c_aa_i2c_slave_write_stats == 0) {
698
        int res = 0;
699
        if (!(c_aa_i2c_slave_write_stats = _loadFunction("c_aa_i2c_slave_write_stats", &res)))
700
            return res;
701
    }
702
    return c_aa_i2c_slave_write_stats(aardvark);
703
}
704
 
705
 
706
static int (*c_aa_i2c_slave_read) (Aardvark, u08 *, u16, u08 *) = 0;
707
int aa_i2c_slave_read (
708
    Aardvark aardvark,
709
    u08 *    addr,
710
    u16      num_bytes,
711
    u08 *    data_in
712
)
713
{
714
    if (c_aa_i2c_slave_read == 0) {
715
        int res = 0;
716
        if (!(c_aa_i2c_slave_read = _loadFunction("c_aa_i2c_slave_read", &res)))
717
            return res;
718
    }
719
    return c_aa_i2c_slave_read(aardvark, addr, num_bytes, data_in);
720
}
721
 
722
 
723
static int (*c_aa_i2c_slave_write_stats_ext) (Aardvark, u16 *) = 0;
724
int aa_i2c_slave_write_stats_ext (
725
    Aardvark aardvark,
726
    u16 *    num_written
727
)
728
{
729
    if (c_aa_i2c_slave_write_stats_ext == 0) {
730
        int res = 0;
731
        if (!(c_aa_i2c_slave_write_stats_ext = _loadFunction("c_aa_i2c_slave_write_stats_ext", &res)))
732
            return res;
733
    }
734
    return c_aa_i2c_slave_write_stats_ext(aardvark, num_written);
735
}
736
 
737
 
738
static int (*c_aa_i2c_slave_read_ext) (Aardvark, u08 *, u16, u08 *, u16 *) = 0;
739
int aa_i2c_slave_read_ext (
740
    Aardvark aardvark,
741
    u08 *    addr,
742
    u16      num_bytes,
743
    u08 *    data_in,
744
    u16 *    num_read
745
)
746
{
747
    if (c_aa_i2c_slave_read_ext == 0) {
748
        int res = 0;
749
        if (!(c_aa_i2c_slave_read_ext = _loadFunction("c_aa_i2c_slave_read_ext", &res)))
750
            return res;
751
    }
752
    return c_aa_i2c_slave_read_ext(aardvark, addr, num_bytes, data_in, num_read);
753
}
754
 
755
 
756
static int (*c_aa_i2c_monitor_enable) (Aardvark) = 0;
757
int aa_i2c_monitor_enable (
758
    Aardvark aardvark
759
)
760
{
761
    if (c_aa_i2c_monitor_enable == 0) {
762
        int res = 0;
763
        if (!(c_aa_i2c_monitor_enable = _loadFunction("c_aa_i2c_monitor_enable", &res)))
764
            return res;
765
    }
766
    return c_aa_i2c_monitor_enable(aardvark);
767
}
768
 
769
 
770
static int (*c_aa_i2c_monitor_disable) (Aardvark) = 0;
771
int aa_i2c_monitor_disable (
772
    Aardvark aardvark
773
)
774
{
775
    if (c_aa_i2c_monitor_disable == 0) {
776
        int res = 0;
777
        if (!(c_aa_i2c_monitor_disable = _loadFunction("c_aa_i2c_monitor_disable", &res)))
778
            return res;
779
    }
780
    return c_aa_i2c_monitor_disable(aardvark);
781
}
782
 
783
 
784
static int (*c_aa_i2c_monitor_read) (Aardvark, u16, u16 *) = 0;
785
int aa_i2c_monitor_read (
786
    Aardvark aardvark,
787
    u16      num_bytes,
788
    u16 *    data
789
)
790
{
791
    if (c_aa_i2c_monitor_read == 0) {
792
        int res = 0;
793
        if (!(c_aa_i2c_monitor_read = _loadFunction("c_aa_i2c_monitor_read", &res)))
794
            return res;
795
    }
796
    return c_aa_i2c_monitor_read(aardvark, num_bytes, data);
797
}
798
 
799
 
800
static int (*c_aa_i2c_pullup) (Aardvark, u08) = 0;
801
int aa_i2c_pullup (
802
    Aardvark aardvark,
803
    u08      pullup_mask
804
)
805
{
806
    if (c_aa_i2c_pullup == 0) {
807
        int res = 0;
808
        if (!(c_aa_i2c_pullup = _loadFunction("c_aa_i2c_pullup", &res)))
809
            return res;
810
    }
811
    return c_aa_i2c_pullup(aardvark, pullup_mask);
812
}
813
 
814
 
815
static int (*c_aa_spi_bitrate) (Aardvark, int) = 0;
816
int aa_spi_bitrate (
817
    Aardvark aardvark,
818
    int      bitrate_khz
819
)
820
{
821
    if (c_aa_spi_bitrate == 0) {
822
        int res = 0;
823
        if (!(c_aa_spi_bitrate = _loadFunction("c_aa_spi_bitrate", &res)))
824
            return res;
825
    }
826
    return c_aa_spi_bitrate(aardvark, bitrate_khz);
827
}
828
 
829
 
830
static int (*c_aa_spi_configure) (Aardvark, AardvarkSpiPolarity, AardvarkSpiPhase, AardvarkSpiBitorder) = 0;
831
int aa_spi_configure (
832
    Aardvark            aardvark,
833
    AardvarkSpiPolarity polarity,
834
    AardvarkSpiPhase    phase,
835
    AardvarkSpiBitorder bitorder
836
)
837
{
838
    if (c_aa_spi_configure == 0) {
839
        int res = 0;
840
        if (!(c_aa_spi_configure = _loadFunction("c_aa_spi_configure", &res)))
841
            return res;
842
    }
843
    return c_aa_spi_configure(aardvark, polarity, phase, bitorder);
844
}
845
 
846
 
847
static int (*c_aa_spi_write) (Aardvark, u16, const u08 *, u16, u08 *) = 0;
848
int aa_spi_write (
849
    Aardvark    aardvark,
850
    u16         out_num_bytes,
851
    const u08 * data_out,
852
    u16         in_num_bytes,
853
    u08 *       data_in
854
)
855
{
856
    if (c_aa_spi_write == 0) {
857
        int res = 0;
858
        if (!(c_aa_spi_write = _loadFunction("c_aa_spi_write", &res)))
859
            return res;
860
    }
861
    return c_aa_spi_write(aardvark, out_num_bytes, data_out, in_num_bytes, data_in);
862
}
863
 
864
 
865
static int (*c_aa_spi_slave_enable) (Aardvark) = 0;
866
int aa_spi_slave_enable (
867
    Aardvark aardvark
868
)
869
{
870
    if (c_aa_spi_slave_enable == 0) {
871
        int res = 0;
872
        if (!(c_aa_spi_slave_enable = _loadFunction("c_aa_spi_slave_enable", &res)))
873
            return res;
874
    }
875
    return c_aa_spi_slave_enable(aardvark);
876
}
877
 
878
 
879
static int (*c_aa_spi_slave_disable) (Aardvark) = 0;
880
int aa_spi_slave_disable (
881
    Aardvark aardvark
882
)
883
{
884
    if (c_aa_spi_slave_disable == 0) {
885
        int res = 0;
886
        if (!(c_aa_spi_slave_disable = _loadFunction("c_aa_spi_slave_disable", &res)))
887
            return res;
888
    }
889
    return c_aa_spi_slave_disable(aardvark);
890
}
891
 
892
 
893
static int (*c_aa_spi_slave_set_response) (Aardvark, u08, const u08 *) = 0;
894
int aa_spi_slave_set_response (
895
    Aardvark    aardvark,
896
    u08         num_bytes,
897
    const u08 * data_out
898
)
899
{
900
    if (c_aa_spi_slave_set_response == 0) {
901
        int res = 0;
902
        if (!(c_aa_spi_slave_set_response = _loadFunction("c_aa_spi_slave_set_response", &res)))
903
            return res;
904
    }
905
    return c_aa_spi_slave_set_response(aardvark, num_bytes, data_out);
906
}
907
 
908
 
909
static int (*c_aa_spi_slave_read) (Aardvark, u16, u08 *) = 0;
910
int aa_spi_slave_read (
911
    Aardvark aardvark,
912
    u16      num_bytes,
913
    u08 *    data_in
914
)
915
{
916
    if (c_aa_spi_slave_read == 0) {
917
        int res = 0;
918
        if (!(c_aa_spi_slave_read = _loadFunction("c_aa_spi_slave_read", &res)))
919
            return res;
920
    }
921
    return c_aa_spi_slave_read(aardvark, num_bytes, data_in);
922
}
923
 
924
 
925
static int (*c_aa_spi_master_ss_polarity) (Aardvark, AardvarkSpiSSPolarity) = 0;
926
int aa_spi_master_ss_polarity (
927
    Aardvark              aardvark,
928
    AardvarkSpiSSPolarity polarity
929
)
930
{
931
    if (c_aa_spi_master_ss_polarity == 0) {
932
        int res = 0;
933
        if (!(c_aa_spi_master_ss_polarity = _loadFunction("c_aa_spi_master_ss_polarity", &res)))
934
            return res;
935
    }
936
    return c_aa_spi_master_ss_polarity(aardvark, polarity);
937
}
938
 
939
 
940
static int (*c_aa_gpio_direction) (Aardvark, u08) = 0;
941
int aa_gpio_direction (
942
    Aardvark aardvark,
943
    u08      direction_mask
944
)
945
{
946
    if (c_aa_gpio_direction == 0) {
947
        int res = 0;
948
        if (!(c_aa_gpio_direction = _loadFunction("c_aa_gpio_direction", &res)))
949
            return res;
950
    }
951
    return c_aa_gpio_direction(aardvark, direction_mask);
952
}
953
 
954
 
955
static int (*c_aa_gpio_pullup) (Aardvark, u08) = 0;
956
int aa_gpio_pullup (
957
    Aardvark aardvark,
958
    u08      pullup_mask
959
)
960
{
961
    if (c_aa_gpio_pullup == 0) {
962
        int res = 0;
963
        if (!(c_aa_gpio_pullup = _loadFunction("c_aa_gpio_pullup", &res)))
964
            return res;
965
    }
966
    return c_aa_gpio_pullup(aardvark, pullup_mask);
967
}
968
 
969
 
970
static int (*c_aa_gpio_get) (Aardvark) = 0;
971
int aa_gpio_get (
972
    Aardvark aardvark
973
)
974
{
975
    if (c_aa_gpio_get == 0) {
976
        int res = 0;
977
        if (!(c_aa_gpio_get = _loadFunction("c_aa_gpio_get", &res)))
978
            return res;
979
    }
980
    return c_aa_gpio_get(aardvark);
981
}
982
 
983
 
984
static int (*c_aa_gpio_set) (Aardvark, u08) = 0;
985
int aa_gpio_set (
986
    Aardvark aardvark,
987
    u08      value
988
)
989
{
990
    if (c_aa_gpio_set == 0) {
991
        int res = 0;
992
        if (!(c_aa_gpio_set = _loadFunction("c_aa_gpio_set", &res)))
993
            return res;
994
    }
995
    return c_aa_gpio_set(aardvark, value);
996
}
997
 
998
 
999
static int (*c_aa_gpio_change) (Aardvark, u16) = 0;
1000
int aa_gpio_change (
1001
    Aardvark aardvark,
1002
    u16      timeout
1003
)
1004
{
1005
    if (c_aa_gpio_change == 0) {
1006
        int res = 0;
1007
        if (!(c_aa_gpio_change = _loadFunction("c_aa_gpio_change", &res)))
1008
            return res;
1009
    }
1010
    return c_aa_gpio_change(aardvark, timeout);
1011
}
1012
 
1013
 

powered by: WebSVN 2.1.0

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