Check-in [8d5d3b6aff]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Committing extracted code for mpssespi package.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8d5d3b6aff20d3acdf92d674a2b02b5c4601f01d
User & Date: andrewm 2014-05-20 14:24:24
Context
2014-05-22
14:23
Committing build binaries and docs in preparation for release of 1.0 of mpssespi package. check-in: d4fce2e055 user: andrewm tags: trunk
2014-05-20
14:24
Committing extracted code for mpssespi package. check-in: 8d5d3b6aff user: andrewm tags: trunk
14:21
Configuration edits in preparation for 1.0 release of mpssespi package. check-in: 79e24c1a17 user: andrewm tags: trunk
Changes

Changes to mpssespi/generic/mpssespi.c.

1
2
3
4
5
6
7
8
..
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
...
145
146
147
148
149
150
151








































152
















153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
...
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
...
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
...
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
...
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
...
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
...
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
...
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
...
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
...
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
...
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
...
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
...
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
...
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
....
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
....
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
....
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
....
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
....
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
....
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
....
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
....
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
....
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
....
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740


1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751

1752
1753
1754







1755
1756
1757







1758
1759
1760







1761
1762
1763







1764
1765
1766







1767
1768
1769







1770
1771
1772







1773
1774
1775







1776
1777
1778







1779
1780
1781







1782
1783
1784







1785
1786
1787







1788
1789
1790







1791
1792
1793
1794
1795
1796

1797





1798


1799

1800
1801
1802
1803
1804
1805
1806
1807





1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
#line 3348 "mpssespi.aweb"
/*
 * DO NOT EDIT THIS FILE!
 * THIS FILE IS AUTOMATICALLY EXTRACTED FROM A LITERATE PROGRAM SOURCE FILE.
 *
 * This software is copyrighted 2014 by G. Andrew Mangogna.  The following
 * terms apply to all files associated with the software unless explicitly
 * disclaimed in individual files.
................................................................................
/*
 * MACRO DEFINITIONS
 */
#ifndef COUNTOF
#   define COUNTOF(a)  (sizeof(a) / sizeof(a[0]))
#endif /* COUNTOF */

#line 313 "mpssespi.aweb"
#define DEFAULT_CHANNEL_CONFIG_ClockRate    1000000
#define DEFAULT_CHANNEL_CONFIG_LatencyTimer 2
#define DEFAULT_CHANNEL_CONFIG_configOptions \
        (SPI_CONFIG_OPTION_MODE0 |\
         SPI_CONFIG_OPTION_CS_DBUS3 |\
         SPI_CONFIG_OPTION_CS_ACTIVELOW)
#define DEFAULT_CHANNEL_CONFIG_Pin          0
#line 335 "mpssespi.aweb"
#define DEFAULT_TRANSFER_OPTIONS \
    (SPI_TRANSFER_OPTIONS_SIZE_IN_BYTES |\
     SPI_TRANSFER_OPTIONS_CHIPSELECT_ENABLE|\
     SPI_TRANSFER_OPTIONS_CHIPSELECT_DISABLE)
#line 1727 "mpssespi.aweb"
#define BITMASK(l)              ((1 << (l)) - 1)
#define FIELDMASK(o, l)         (BITMASK(l) << (o))
#define EXTRACT_BITFIELD(v, o, l)   (((v) & FIELDMASK(o, l)) >> (o))

#define CLEARFIELD(v, o, l)     ((v) & ~FIELDMASK(o, l))
#define ALIGNTOFIELD(f, o, l)   (((f) & BITMASK(l)) << (o))
#define INSERT_BITFIELD(v, f, o, l)\
    (CLEARFIELD(v, o, l) | ALIGNTOFIELD(f, o, l))

#define IS_BIT_XFER(o) (((o) & SPI_TRANSFER_OPTIONS_SIZE_IN_BITS) != 0)
#line 1751 "mpssespi.aweb"
#define PIN_BITFIELD_LENGTH         8

#define PIN_INITIAL_DIR_OFFSET      0
#define PIN_INITIAL_VALUE_OFFSET\
    (PIN_INITIAL_DIR_OFFSET + PIN_BITFIELD_LENGTH)
#define PIN_CLOSE_DIR_OFFSET\
    (PIN_INITIAL_VALUE_OFFSET + PIN_BITFIELD_LENGTH)
#define PIN_CLOSE_VALUE_OFFSET\
    (PIN_CLOSE_DIR_OFFSET + PIN_BITFIELD_LENGTH)

/*
 * TYPE DEFINITIONS
 */
#line 145 "mpssespi.aweb"
typedef struct MPSSEPkgInfo {
    Tcl_HashTable handleMap ;       /* <1> */
    unsigned counter ;              /* <2> */
} MPSSEPkgInfo ;
#line 229 "mpssespi.aweb"
typedef struct MPSSSEChanInfo {
    FT_HANDLE handle ;          /* <1> */
    bool isInitialized ;        /* <2> */
    ChannelConfig config ;      /* <3> */
    uint32 transferOptions ;    /* <4> */
} MPSSEChanConfig ;

................................................................................
/*
 * EXTERNAL DATA DEFINITIONS
 */

/*
 * STATIC DATA DEFINITIONS
 */








































#line 3219 "mpssespi.aweb"
















static char const mpssespi_ns_name[] = "::mpssespi" ;

#line 3298 "mpssespi.aweb"
#if TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION >= 5
static Tcl_Config mpssespi_config[] = {
    {"pkgname", PACKAGE_NAME},
    {"version", PACKAGE_VERSION},
    {"copyright",
"This software is copyrighted 2014 by G. Andrew Mangogna.\
 Terms and conditions for use are distributed with the source code."},
    {NULL, NULL}
} ;
#endif

/*
 * STATIC FUNCTION DEFINITIONS
 */
#line 193 "mpssespi.aweb"
static void
DeleteMPSSEPkgInfo(
    ClientData clientData,
    Tcl_Interp *interp)
{
    MPSSEPkgInfo *info ;
    Tcl_HashEntry *entry ;
................................................................................
        MPSSEChanConfig *config = (MPSSEChanConfig *)Tcl_GetHashValue(entry) ;
        ckfree((char *)config) ;
    }
    Tcl_DeleteHashTable(&info->handleMap) ; /* <2> */

    ckfree((char *)info) ; /* <3> */
}
#line 165 "mpssespi.aweb"
static ClientData
NewMPSSEPkgInfo(
    Tcl_Interp *interp)
{
    MPSSEPkgInfo *info ;

    info = (MPSSEPkgInfo *)ckalloc(sizeof(*info)) ;
    memset(info, 0, sizeof(*info)) ;
    Tcl_InitHashTable(&info->handleMap, TCL_STRING_KEYS) ;            /* <1> */
    Tcl_SetAssocData(interp, PACKAGE_NAME, DeleteMPSSEPkgInfo, info) ;/* <2> */

    return (ClientData)info ;
}
#line 262 "mpssespi.aweb"
static Tcl_Obj *
NewHandleMapping(
    MPSSEPkgInfo *info,
    FT_HANDLE handle)
{
    Tcl_Obj *handleName ;
    Tcl_HashEntry *entry ;
................................................................................
    } else {
        Tcl_Panic("failed to create mpssespi channel handle entry, \"%s\"\n",
            Tcl_GetString(handleName)) ;
    }

    return handleName ;
}
#line 362 "mpssespi.aweb"
static void
DeleteHandleMapping(
    MPSSEPkgInfo *info,
    Tcl_Obj *handleName)
{
    Tcl_HashEntry *entry ;
    MPSSEChanConfig *chanConfig ;
................................................................................
    assert(entry != NULL) ;
    if (entry) {
        chanConfig = (MPSSEChanConfig *)Tcl_GetHashValue(entry) ;
        ckfree((char *)chanConfig) ;
        Tcl_DeleteHashEntry(entry) ;
    }
}
#line 391 "mpssespi.aweb"
static int
LookUpHandle(
    Tcl_Interp *interp,
    MPSSEPkgInfo *info,
    Tcl_Obj *handleName,
    MPSSEChanConfig **chanConfigPtr)
{
................................................................................
        return TCL_OK ;
    } else {
        Tcl_SetObjResult(interp, Tcl_ObjPrintf("unknown channel handle, \"%s\"",
                Tcl_GetString(handleName))) ;
        return TCL_ERROR ;
    }
}
#line 1255 "mpssespi.aweb"
static int
GetDirectionDict(
    Tcl_Interp *interp,
    uint8 dirBitMask,
    Tcl_Obj **dirDictObjPtr)
{
    char key[2] ; /* <1> */
................................................................................
    return TCL_OK ;

errorout:
    Tcl_DecrRefCount(dirObj) ;
    *dirDictObjPtr = NULL ;
    return TCL_ERROR ;
}
#line 1312 "mpssespi.aweb"
static int
GetPinValueDict(
    Tcl_Interp *interp,
    uint8 pinBitMask,
    Tcl_Obj **pinDictObjPtr)
{
    char key[2] ;
................................................................................
    return TCL_OK ;

errorout:
    Tcl_DecrRefCount(pinObj) ;
    *pinDictObjPtr = NULL ;
    return TCL_ERROR ;
}
#line 1784 "mpssespi.aweb"
static int
GetDirectionBitMask(
    Tcl_Interp *interp,
    Tcl_Obj *dirSpecObj,
    uint8 *directionPtr)
{
    char key[2] ;
................................................................................

    return TCL_OK ;

errorout:
    Tcl_DecrRefCount(keyObj) ;
    return TCL_ERROR ;
}
#line 1845 "mpssespi.aweb"
static int
GetPinValueBitMask(
    Tcl_Interp *interp,
    Tcl_Obj *lvalueSpecObj,
    uint8 *lvaluePtr)
{
    char key[2] ;
................................................................................

    return TCL_OK ;

errorout:
    Tcl_DecrRefCount(keyObj) ;
    return TCL_ERROR ;
}
#line 2185 "mpssespi.aweb"
static int
SetTransferOptions(
    Tcl_Interp *interp,
    Tcl_Obj *optionsDict,
    uint32 *optionsPtr)
{
    uint32 transferOptions ;
................................................................................
    *optionsPtr = transferOptions ;
    return TCL_OK ;

errorout:
    Tcl_DecrRefCount(key) ;
    return TCL_ERROR ;
}
#line 2273 "mpssespi.aweb"
static int
ConvertXferUnitsToBytes(
    uint32 transferOptions,
    uint32 xferSize)
{
    return IS_BIT_XFER(transferOptions) ? (xferSize + 7) / 8 : xferSize ;
}
#line 2444 "mpssespi.aweb"
static int
VerifyOutputLength(
    Tcl_Interp *interp,
    uint32 transferOptions,
    int byteLen,
    int bitLen)
{
................................................................................
            "output data is %d bytes long, \
however %d bits were requested to be written",
            byteLen, bitLen)) ;
        return TCL_ERROR ;
    }
    return TCL_OK ;
}
#line 3091 "mpssespi.aweb"
static int
SetStatusResult(
    Tcl_Interp *interp,
    FT_STATUS status)
{
    static struct ftErrorMap {
        char const *resultString ;
................................................................................
        Tcl_Obj *result = Tcl_GetObjResult(interp) ;
        Tcl_AppendPrintfToObj(result, "unknown FT_STATUS value, \"%d\"",
            status) ;
        Tcl_SetObjResult(interp, result) ;
    }
    return TCL_ERROR ;
}
#line 3152 "mpssespi.aweb"
static void
SetInitializationError(
    Tcl_Interp *interp)
{
    static char const msg[] = "channel must be initialized first" ;
    Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1)) ;
    Tcl_SetErrorCode(interp, "MPSSESPI", "UNINITIALIZED", msg, NULL) ;
}
#line 454 "mpssespi.aweb"
static int
GetNumChannelsProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    result = SetStatusResult(interp, status) ;     /* <2> */
    if (result == TCL_OK) {
        Tcl_SetObjResult(interp, Tcl_NewLongObj(numChannels)) ;
    }
    return result ;
}

#line 568 "mpssespi.aweb"
static int
GetChannelInfoProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    return result ;

errout:
    Tcl_DecrRefCount(infoObj) ;
    return TCL_ERROR ;
}

#line 759 "mpssespi.aweb"
static int
OpenChannelProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
                handle) ;       /* <1> */
        Tcl_SetObjResult(interp, handleName) ;
    }

    return result ;
}

#line 872 "mpssespi.aweb"
static int
InitChannelProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
        chanConfig->isInitialized = 1 ;     /* <3> */
        Tcl_ResetResult(interp) ;
    }

    return result ;
}

#line 1035 "mpssespi.aweb"
static int
GetChannelConfigProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    Tcl_DecrRefCount(pinObj) ;

errorout:
    Tcl_DecrRefCount(configObj) ;
    return TCL_ERROR ;
}

#line 1455 "mpssespi.aweb"
static int
SetChannelConfigProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    return TCL_OK ;

errorout:
    Tcl_DecrRefCount(keyObj) ;
    return TCL_ERROR ;
}

#line 1920 "mpssespi.aweb"
static int
CloseChannelProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
        DeleteHandleMapping(pkgInfo, handleObj) ; /* <1> */
        Tcl_ResetResult(interp) ;
    }

    return result ;
}

#line 2044 "mpssespi.aweb"
static int
ReadChannelProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    } else {
        Tcl_DecrRefCount(inputObj) ;
    }

    return result ;
}

#line 2352 "mpssespi.aweb"
static int
WriteChannelProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    if (result == TCL_OK) {
        Tcl_SetObjResult(interp, Tcl_NewIntObj(xferActual)) ;
    }

    return result ;
}

#line 2586 "mpssespi.aweb"
static int
ReadWriteChannelProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    } else {
        Tcl_DecrRefCount(inputObj) ;
    }

    return result ;
}

#line 2725 "mpssespi.aweb"
static int
IsBusyProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    if (result == TCL_OK) {
        Tcl_SetObjResult(interp, Tcl_NewBooleanObj(busyStatus)) ;
    }

    return result ;
}

#line 2823 "mpssespi.aweb"
static int
ChangeCSProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    if (result == TCL_OK) {
        Tcl_ResetResult(interp) ;
    }

    return result ;
}

#line 2915 "mpssespi.aweb"
static int
WriteGPIOProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    if (result == TCL_OK) {
        Tcl_ResetResult(interp) ;
    }

    return result ;
}

#line 3012 "mpssespi.aweb"
static int
ReadGPIOProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    return TCL_OK ;
}


/*
 * EXTERNAL FUNCTION DEFINITIONS
 */
#line 3180 "mpssespi.aweb"
DLLEXPORT       /* <1> */
int
Mpssespi_Init(
    Tcl_Interp *interp)
{
    ClientData clientData ;
    Tcl_Namespace *ns ;



    if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
        return TCL_ERROR ;
    }

    clientData = NewMPSSEPkgInfo(interp) ;  /* <2> */

    Init_libMPSSE() ;

    #line 3222 "mpssespi.aweb"
    ns = Tcl_CreateNamespace(interp, mpssespi_ns_name, NULL, NULL) ;

    #line 484 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::getNumChannels", GetNumChannelsProc,
            clientData, NULL) ;







    #line 681 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::getChannelInfo", GetChannelInfoProc,
            clientData, NULL) ;







    #line 804 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::openChannel", OpenChannelProc,
            clientData, NULL) ;







    #line 911 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::initChannel", InitChannelProc,
            clientData, NULL) ;







    #line 1210 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::getChannelConfig",
            GetChannelConfigProc, clientData, NULL) ;







    #line 1685 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::setChannelConfig",
            SetChannelConfigProc, clientData, NULL) ;







    #line 1960 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::closeChannel", CloseChannelProc,
            clientData, NULL) ;







    #line 2127 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::readChannel", ReadChannelProc,
            clientData, NULL) ;







    #line 2426 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::writeChannel", WriteChannelProc,
            clientData, NULL) ;







    #line 2676 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::readWriteChannel",
            ReadWriteChannelProc, clientData, NULL) ;







    #line 2767 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::isBusy", IsBusyProc, clientData,
            NULL) ;







    #line 2863 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::changeCS", ChangeCSProc, clientData,
            NULL) ;







    #line 2967 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::writeGPIO", WriteGPIOProc,
            clientData, NULL) ;







    #line 3060 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, "::mpssespi::readGPIO", ReadGPIOProc,
            clientData, NULL) ;
    #line 3231 "mpssespi.aweb"
    if (Tcl_Export(interp, ns, "*", 0) != TCL_OK) {
        return TCL_ERROR ;

    }





    (void)Tcl_CreateEnsemble(interp, mpssespi_ns_name, ns, TCL_ENSEMBLE_PREFIX) ;




    #line 3315 "mpssespi.aweb"
    #       if TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION >= 5
        Tcl_RegisterConfig(interp, PACKAGE_NAME, mpssespi_config, "iso8859-1") ;
    #       endif

    Tcl_PkgProvide(interp, "mpssespi", PACKAGE_VERSION) ;
    return TCL_OK ;
}





#line 3266 "mpssespi.aweb"
DLLEXPORT int
Mpssespi_SafeInit(
    Tcl_Interp *interp)
{
    return TCL_ERROR ;
}

#if TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION >= 5
#line 3247 "mpssespi.aweb"
DLLEXPORT int
Mpssespi_Unload(
    Tcl_Interp *interp)
{
    Cleanup_libMPSSE() ;
    return TCL_OK ;
}
#line 3276 "mpssespi.aweb"
DLLEXPORT
int
Mpssespi_SafeUnload(
    Tcl_Interp *interp)
{
    return TCL_ERROR ;
}
#endif /* TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION >= 5 */
|







 







|







|




|










|













|




|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


|
<








<




|







 







|













|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







|







 







|







 







|








|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







>
>









|

>
|
|

>
>
>
>
>
>
>
|
|

>
>
>
>
>
>
>
|
|

>
>
>
>
>
>
>
|
|

>
>
>
>
>
>
>
|
|
|
>
>
>
>
>
>
>
|
|
|
>
>
>
>
>
>
>
|
|

>
>
>
>
>
>
>
|
|

>
>
>
>
>
>
>
|
|

>
>
>
>
>
>
>
|
|
|
>
>
>
>
>
>
>
|
|
|
>
>
>
>
>
>
>
|
|
|
>
>
>
>
>
>
>
|
|

>
>
>
>
>
>
>
|
|

<
|
<
>

>
>
>
>
>
|
>
>
|
>
|
<

<

|

|
>
>
>
>
>
|







<
|







|







<
1
2
3
4
5
6
7
8
..
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229
230
231
...
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
...
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
...
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
...
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
...
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
...
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
...
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
...
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
...
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
...
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
...
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
...
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
...
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
...
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
...
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
....
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
....
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
....
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
....
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
....
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
....
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
....
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
....
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
....
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
....
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941

1942

1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955

1956

1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973

1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989

#line 3550 "mpssespi.aweb"
/*
 * DO NOT EDIT THIS FILE!
 * THIS FILE IS AUTOMATICALLY EXTRACTED FROM A LITERATE PROGRAM SOURCE FILE.
 *
 * This software is copyrighted 2014 by G. Andrew Mangogna.  The following
 * terms apply to all files associated with the software unless explicitly
 * disclaimed in individual files.
................................................................................
/*
 * MACRO DEFINITIONS
 */
#ifndef COUNTOF
#   define COUNTOF(a)  (sizeof(a) / sizeof(a[0]))
#endif /* COUNTOF */

#line 329 "mpssespi.aweb"
#define DEFAULT_CHANNEL_CONFIG_ClockRate    1000000
#define DEFAULT_CHANNEL_CONFIG_LatencyTimer 2
#define DEFAULT_CHANNEL_CONFIG_configOptions \
        (SPI_CONFIG_OPTION_MODE0 |\
         SPI_CONFIG_OPTION_CS_DBUS3 |\
         SPI_CONFIG_OPTION_CS_ACTIVELOW)
#define DEFAULT_CHANNEL_CONFIG_Pin          0
#line 351 "mpssespi.aweb"
#define DEFAULT_TRANSFER_OPTIONS \
    (SPI_TRANSFER_OPTIONS_SIZE_IN_BYTES |\
     SPI_TRANSFER_OPTIONS_CHIPSELECT_ENABLE|\
     SPI_TRANSFER_OPTIONS_CHIPSELECT_DISABLE)
#line 1835 "mpssespi.aweb"
#define BITMASK(l)              ((1 << (l)) - 1)
#define FIELDMASK(o, l)         (BITMASK(l) << (o))
#define EXTRACT_BITFIELD(v, o, l)   (((v) & FIELDMASK(o, l)) >> (o))

#define CLEARFIELD(v, o, l)     ((v) & ~FIELDMASK(o, l))
#define ALIGNTOFIELD(f, o, l)   (((f) & BITMASK(l)) << (o))
#define INSERT_BITFIELD(v, f, o, l)\
    (CLEARFIELD(v, o, l) | ALIGNTOFIELD(f, o, l))

#define IS_BIT_XFER(o) (((o) & SPI_TRANSFER_OPTIONS_SIZE_IN_BITS) != 0)
#line 1859 "mpssespi.aweb"
#define PIN_BITFIELD_LENGTH         8

#define PIN_INITIAL_DIR_OFFSET      0
#define PIN_INITIAL_VALUE_OFFSET\
    (PIN_INITIAL_DIR_OFFSET + PIN_BITFIELD_LENGTH)
#define PIN_CLOSE_DIR_OFFSET\
    (PIN_INITIAL_VALUE_OFFSET + PIN_BITFIELD_LENGTH)
#define PIN_CLOSE_VALUE_OFFSET\
    (PIN_CLOSE_DIR_OFFSET + PIN_BITFIELD_LENGTH)

/*
 * TYPE DEFINITIONS
 */
#line 161 "mpssespi.aweb"
typedef struct MPSSEPkgInfo {
    Tcl_HashTable handleMap ;       /* <1> */
    unsigned counter ;              /* <2> */
} MPSSEPkgInfo ;
#line 245 "mpssespi.aweb"
typedef struct MPSSSEChanInfo {
    FT_HANDLE handle ;          /* <1> */
    bool isInitialized ;        /* <2> */
    ChannelConfig config ;      /* <3> */
    uint32 transferOptions ;    /* <4> */
} MPSSEChanConfig ;

................................................................................
/*
 * EXTERNAL DATA DEFINITIONS
 */

/*
 * STATIC DATA DEFINITIONS
 */
#line 505 "mpssespi.aweb"
static char const getNumChannelsCmdName[] = "::mpssespi::getNumChannels" ;
static char const getNumChannelsName[] = "getNumChannels" ;

#line 734 "mpssespi.aweb"
static char const getChannelInfoCmdName[] = "::mpssespi::getChannelInfo" ;
static char const getChannelInfoName[] = "getChannelInfo" ;

#line 868 "mpssespi.aweb"
static char const openChannelCmdName[] = "::mpssespi::openChannel" ;
static char const openChannelName[] = "openChannel" ;

#line 986 "mpssespi.aweb"
static char const initChannelCmdName[] = "::mpssespi::initChannel" ;
static char const initChannelName[] = "initChannel" ;

#line 1296 "mpssespi.aweb"
static char const getChannelConfigCmdName[] = "::mpssespi::getChannelConfig" ;
static char const getChannelConfigName[] = "getChannelConfig" ;

#line 1782 "mpssespi.aweb"
static char const setChannelConfigCmdName[] = "::mpssespi::setChannelConfig" ;
static char const setChannelConfigName[] = "setChannelConfig" ;

#line 2068 "mpssespi.aweb"
static char const closeChannelCmdName[] = "::mpssespi::closeChannel" ;
static char const closeChannelName[] = "closeChannel" ;

#line 2246 "mpssespi.aweb"
static char const readChannelCmdName[] = "::mpssespi::readChannel" ;
static char const readChannelName[] = "readChannel" ;

#line 2556 "mpssespi.aweb"
static char const writeChannelCmdName[] = "::mpssespi::writeChannel" ;
static char const writeChannelName[] = "writeChannel" ;

#line 2817 "mpssespi.aweb"
static char const readWriteChannelCmdName[] = "::mpssespi::readWriteChannel" ;
static char const readWriteChannelName[] = "readWriteChannel" ;

#line 2919 "mpssespi.aweb"
static char const isBusyCmdName[] = "::mpssespi::isBusy" ;
static char const isBusyName[] = "isBusy" ;

#line 3026 "mpssespi.aweb"
static char const changeCSCmdName[] = "::mpssespi::changeCS" ;
static char const changeCSName[] = "changeCS" ;

#line 3141 "mpssespi.aweb"
static char const writeGPIOCmdName[] = "::mpssespi::writeGPIO" ;
static char const writeGPIOName[] = "writeGPIO" ;

#line 3245 "mpssespi.aweb"
static char const readGPIOCmdName[] = "::mpssespi::readGPIO" ;
static char const readGPIOName[] = "readGPIO" ;

#line 3422 "mpssespi.aweb"
static char const mpssespi_ns_name[] = "::mpssespi" ;

#line 3504 "mpssespi.aweb"

static Tcl_Config mpssespi_config[] = {
    {"pkgname", PACKAGE_NAME},
    {"version", PACKAGE_VERSION},
    {"copyright",
"This software is copyrighted 2014 by G. Andrew Mangogna.\
 Terms and conditions for use are distributed with the source code."},
    {NULL, NULL}
} ;


/*
 * STATIC FUNCTION DEFINITIONS
 */
#line 209 "mpssespi.aweb"
static void
DeleteMPSSEPkgInfo(
    ClientData clientData,
    Tcl_Interp *interp)
{
    MPSSEPkgInfo *info ;
    Tcl_HashEntry *entry ;
................................................................................
        MPSSEChanConfig *config = (MPSSEChanConfig *)Tcl_GetHashValue(entry) ;
        ckfree((char *)config) ;
    }
    Tcl_DeleteHashTable(&info->handleMap) ; /* <2> */

    ckfree((char *)info) ; /* <3> */
}
#line 181 "mpssespi.aweb"
static ClientData
NewMPSSEPkgInfo(
    Tcl_Interp *interp)
{
    MPSSEPkgInfo *info ;

    info = (MPSSEPkgInfo *)ckalloc(sizeof(*info)) ;
    memset(info, 0, sizeof(*info)) ;
    Tcl_InitHashTable(&info->handleMap, TCL_STRING_KEYS) ;            /* <1> */
    Tcl_SetAssocData(interp, PACKAGE_NAME, DeleteMPSSEPkgInfo, info) ;/* <2> */

    return (ClientData)info ;
}
#line 278 "mpssespi.aweb"
static Tcl_Obj *
NewHandleMapping(
    MPSSEPkgInfo *info,
    FT_HANDLE handle)
{
    Tcl_Obj *handleName ;
    Tcl_HashEntry *entry ;
................................................................................
    } else {
        Tcl_Panic("failed to create mpssespi channel handle entry, \"%s\"\n",
            Tcl_GetString(handleName)) ;
    }

    return handleName ;
}
#line 378 "mpssespi.aweb"
static void
DeleteHandleMapping(
    MPSSEPkgInfo *info,
    Tcl_Obj *handleName)
{
    Tcl_HashEntry *entry ;
    MPSSEChanConfig *chanConfig ;
................................................................................
    assert(entry != NULL) ;
    if (entry) {
        chanConfig = (MPSSEChanConfig *)Tcl_GetHashValue(entry) ;
        ckfree((char *)chanConfig) ;
        Tcl_DeleteHashEntry(entry) ;
    }
}
#line 407 "mpssespi.aweb"
static int
LookUpHandle(
    Tcl_Interp *interp,
    MPSSEPkgInfo *info,
    Tcl_Obj *handleName,
    MPSSEChanConfig **chanConfigPtr)
{
................................................................................
        return TCL_OK ;
    } else {
        Tcl_SetObjResult(interp, Tcl_ObjPrintf("unknown channel handle, \"%s\"",
                Tcl_GetString(handleName))) ;
        return TCL_ERROR ;
    }
}
#line 1352 "mpssespi.aweb"
static int
GetDirectionDict(
    Tcl_Interp *interp,
    uint8 dirBitMask,
    Tcl_Obj **dirDictObjPtr)
{
    char key[2] ; /* <1> */
................................................................................
    return TCL_OK ;

errorout:
    Tcl_DecrRefCount(dirObj) ;
    *dirDictObjPtr = NULL ;
    return TCL_ERROR ;
}
#line 1409 "mpssespi.aweb"
static int
GetPinValueDict(
    Tcl_Interp *interp,
    uint8 pinBitMask,
    Tcl_Obj **pinDictObjPtr)
{
    char key[2] ;
................................................................................
    return TCL_OK ;

errorout:
    Tcl_DecrRefCount(pinObj) ;
    *pinDictObjPtr = NULL ;
    return TCL_ERROR ;
}
#line 1892 "mpssespi.aweb"
static int
GetDirectionBitMask(
    Tcl_Interp *interp,
    Tcl_Obj *dirSpecObj,
    uint8 *directionPtr)
{
    char key[2] ;
................................................................................

    return TCL_OK ;

errorout:
    Tcl_DecrRefCount(keyObj) ;
    return TCL_ERROR ;
}
#line 1953 "mpssespi.aweb"
static int
GetPinValueBitMask(
    Tcl_Interp *interp,
    Tcl_Obj *lvalueSpecObj,
    uint8 *lvaluePtr)
{
    char key[2] ;
................................................................................

    return TCL_OK ;

errorout:
    Tcl_DecrRefCount(keyObj) ;
    return TCL_ERROR ;
}
#line 2315 "mpssespi.aweb"
static int
SetTransferOptions(
    Tcl_Interp *interp,
    Tcl_Obj *optionsDict,
    uint32 *optionsPtr)
{
    uint32 transferOptions ;
................................................................................
    *optionsPtr = transferOptions ;
    return TCL_OK ;

errorout:
    Tcl_DecrRefCount(key) ;
    return TCL_ERROR ;
}
#line 2403 "mpssespi.aweb"
static int
ConvertXferUnitsToBytes(
    uint32 transferOptions,
    uint32 xferSize)
{
    return IS_BIT_XFER(transferOptions) ? (xferSize + 7) / 8 : xferSize ;
}
#line 2585 "mpssespi.aweb"
static int
VerifyOutputLength(
    Tcl_Interp *interp,
    uint32 transferOptions,
    int byteLen,
    int bitLen)
{
................................................................................
            "output data is %d bytes long, \
however %d bits were requested to be written",
            byteLen, bitLen)) ;
        return TCL_ERROR ;
    }
    return TCL_OK ;
}
#line 3287 "mpssespi.aweb"
static int
SetStatusResult(
    Tcl_Interp *interp,
    FT_STATUS status)
{
    static struct ftErrorMap {
        char const *resultString ;
................................................................................
        Tcl_Obj *result = Tcl_GetObjResult(interp) ;
        Tcl_AppendPrintfToObj(result, "unknown FT_STATUS value, \"%d\"",
            status) ;
        Tcl_SetObjResult(interp, result) ;
    }
    return TCL_ERROR ;
}
#line 3348 "mpssespi.aweb"
static void
SetInitializationError(
    Tcl_Interp *interp)
{
    static char const msg[] = "channel must be initialized first" ;
    Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1)) ;
    Tcl_SetErrorCode(interp, "MPSSESPI", "UNINITIALIZED", msg, NULL) ;
}
#line 475 "mpssespi.aweb"
static int
GetNumChannelsProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    result = SetStatusResult(interp, status) ;     /* <2> */
    if (result == TCL_OK) {
        Tcl_SetObjResult(interp, Tcl_NewLongObj(numChannels)) ;
    }
    return result ;
}

#line 621 "mpssespi.aweb"
static int
GetChannelInfoProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    return result ;

errout:
    Tcl_DecrRefCount(infoObj) ;
    return TCL_ERROR ;
}

#line 823 "mpssespi.aweb"
static int
OpenChannelProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
                handle) ;       /* <1> */
        Tcl_SetObjResult(interp, handleName) ;
    }

    return result ;
}

#line 947 "mpssespi.aweb"
static int
InitChannelProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
        chanConfig->isInitialized = 1 ;     /* <3> */
        Tcl_ResetResult(interp) ;
    }

    return result ;
}

#line 1121 "mpssespi.aweb"
static int
GetChannelConfigProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    Tcl_DecrRefCount(pinObj) ;

errorout:
    Tcl_DecrRefCount(configObj) ;
    return TCL_ERROR ;
}

#line 1552 "mpssespi.aweb"
static int
SetChannelConfigProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    return TCL_OK ;

errorout:
    Tcl_DecrRefCount(keyObj) ;
    return TCL_ERROR ;
}

#line 2028 "mpssespi.aweb"
static int
CloseChannelProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
        DeleteHandleMapping(pkgInfo, handleObj) ; /* <1> */
        Tcl_ResetResult(interp) ;
    }

    return result ;
}

#line 2163 "mpssespi.aweb"
static int
ReadChannelProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    } else {
        Tcl_DecrRefCount(inputObj) ;
    }

    return result ;
}

#line 2482 "mpssespi.aweb"
static int
WriteChannelProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    if (result == TCL_OK) {
        Tcl_SetObjResult(interp, Tcl_NewIntObj(xferActual)) ;
    }

    return result ;
}

#line 2727 "mpssespi.aweb"
static int
ReadWriteChannelProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    } else {
        Tcl_DecrRefCount(inputObj) ;
    }

    return result ;
}

#line 2877 "mpssespi.aweb"
static int
IsBusyProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    if (result == TCL_OK) {
        Tcl_SetObjResult(interp, Tcl_NewBooleanObj(busyStatus)) ;
    }

    return result ;
}

#line 2986 "mpssespi.aweb"
static int
ChangeCSProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    if (result == TCL_OK) {
        Tcl_ResetResult(interp) ;
    }

    return result ;
}

#line 3089 "mpssespi.aweb"
static int
WriteGPIOProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    if (result == TCL_OK) {
        Tcl_ResetResult(interp) ;
    }

    return result ;
}

#line 3197 "mpssespi.aweb"
static int
ReadGPIOProc(
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
................................................................................
    return TCL_OK ;
}


/*
 * EXTERNAL FUNCTION DEFINITIONS
 */
#line 3376 "mpssespi.aweb"
DLLEXPORT       /* <1> */
int
Mpssespi_Init(
    Tcl_Interp *interp)
{
    ClientData clientData ;
    Tcl_Namespace *ns ;
    Tcl_Obj *mapObj ;
    Tcl_Command cmdToken ;

    if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
        return TCL_ERROR ;
    }

    clientData = NewMPSSEPkgInfo(interp) ;  /* <2> */

    Init_libMPSSE() ;

    #line 3425 "mpssespi.aweb"
    ns = Tcl_CreateNamespace(interp, mpssespi_ns_name, NULL, NULL) ;
    mapObj = Tcl_NewDictObj() ;     /* <1> */
    #line 509 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, getNumChannelsCmdName, GetNumChannelsProc,
            clientData, NULL) ;
    if (Tcl_Export(interp, ns, getNumChannelsName, 0) != TCL_OK) {
        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(getNumChannelsName, -1),
            Tcl_NewStringObj(getNumChannelsCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 738 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, getChannelInfoCmdName, GetChannelInfoProc,
            clientData, NULL) ;
    if (Tcl_Export(interp, ns, getChannelInfoName, 0) != TCL_OK) {
        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(getChannelInfoName, -1),
            Tcl_NewStringObj(getChannelInfoCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 872 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, openChannelCmdName, OpenChannelProc,
            clientData, NULL) ;
    if (Tcl_Export(interp, ns, openChannelName, 0) != TCL_OK) {
        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(openChannelName, -1),
            Tcl_NewStringObj(openChannelCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 990 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, initChannelCmdName, InitChannelProc,
            clientData, NULL) ;
    if (Tcl_Export(interp, ns, initChannelName, 0) != TCL_OK) {
        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(initChannelName, -1),
            Tcl_NewStringObj(initChannelCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 1300 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, getChannelConfigCmdName, GetChannelConfigProc,
            clientData, NULL) ;
    if (Tcl_Export(interp, ns, getChannelConfigName, 0) != TCL_OK) {
        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(getChannelConfigName, -1),
            Tcl_NewStringObj(getChannelConfigCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 1786 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, setChannelConfigCmdName, SetChannelConfigProc,
            clientData, NULL) ;
    if (Tcl_Export(interp, ns, setChannelConfigName, 0) != TCL_OK) {
        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(setChannelConfigName, -1),
            Tcl_NewStringObj(setChannelConfigCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 2072 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, closeChannelCmdName, CloseChannelProc,
            clientData, NULL) ;
    if (Tcl_Export(interp, ns, closeChannelName, 0) != TCL_OK) {
        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(closeChannelName, -1),
            Tcl_NewStringObj(closeChannelCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 2250 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, readChannelCmdName, ReadChannelProc,
            clientData, NULL) ;
    if (Tcl_Export(interp, ns, readChannelName, 0) != TCL_OK) {
        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(readChannelName, -1),
            Tcl_NewStringObj(readChannelCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 2560 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, writeChannelCmdName, WriteChannelProc,
            clientData, NULL) ;
    if (Tcl_Export(interp, ns, writeChannelName, 0) != TCL_OK) {
        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(writeChannelName, -1),
            Tcl_NewStringObj(writeChannelCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 2821 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, readWriteChannelCmdName, ReadWriteChannelProc,
            clientData, NULL) ;
    if (Tcl_Export(interp, ns, readWriteChannelName, 0) != TCL_OK) {
        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(readWriteChannelName, -1),
            Tcl_NewStringObj(readWriteChannelCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 2923 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, isBusyCmdName, IsBusyProc,
            clientData, NULL) ;
    if (Tcl_Export(interp, ns, isBusyName, 0) != TCL_OK) {
        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(isBusyName, -1),
            Tcl_NewStringObj(isBusyCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 3030 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, changeCSCmdName, ChangeCSProc,
            clientData, NULL) ;
    if (Tcl_Export(interp, ns, changeCSName, 0) != TCL_OK) {
        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(changeCSName, -1),
            Tcl_NewStringObj(changeCSCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 3145 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, writeGPIOCmdName, WriteGPIOProc,
            clientData, NULL) ;
    if (Tcl_Export(interp, ns, writeGPIOName, 0) != TCL_OK) {
        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(writeGPIOName, -1),
            Tcl_NewStringObj(writeGPIOCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 3249 "mpssespi.aweb"
    Tcl_CreateObjCommand(interp, readGPIOCmdName, ReadGPIOProc,
            clientData, NULL) ;

    if (Tcl_Export(interp, ns, readGPIOName, 0) != TCL_OK) {

        goto errorout ;
    }
    if (Tcl_DictObjPut(interp, mapObj, Tcl_NewStringObj(readGPIOName, -1),
            Tcl_NewStringObj(readGPIOCmdName, -1)) != TCL_OK) {
        goto errorout ;
    }
    #line 3437 "mpssespi.aweb"
    cmdToken = Tcl_CreateEnsemble(interp, mpssespi_ns_name, ns, TCL_ENSEMBLE_PREFIX) ;
    if (Tcl_SetEnsembleMappingDict(interp, cmdToken, mapObj) != TCL_OK) {
        goto errorout ;
    }

    #line 3519 "mpssespi.aweb"

        Tcl_RegisterConfig(interp, PACKAGE_NAME, mpssespi_config, "iso8859-1") ;


    Tcl_PkgProvide(interp, PACKAGE_NAME, PACKAGE_VERSION) ;
    return TCL_OK ;

errorout:
    Tcl_DecrRefCount(mapObj) ;
    Tcl_DeleteNamespace(ns) ;
    return TCL_ERROR ;
}
#line 3472 "mpssespi.aweb"
DLLEXPORT int
Mpssespi_SafeInit(
    Tcl_Interp *interp)
{
    return TCL_ERROR ;
}


#line 3453 "mpssespi.aweb"
DLLEXPORT int
Mpssespi_Unload(
    Tcl_Interp *interp)
{
    Cleanup_libMPSSE() ;
    return TCL_OK ;
}
#line 3482 "mpssespi.aweb"
DLLEXPORT
int
Mpssespi_SafeUnload(
    Tcl_Interp *interp)
{
    return TCL_ERROR ;
}

Changes to mpssespi/tests/example.tcl.

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
        csactive high
    }
    mpssespi initChannel $spichan       ; # <1>

    for {set address 0} {$address < 16} {incr address} {
        set data [expr {$address + 3}]
        puts "writing address $address, data = $data"
        set bindata [binary format S $data]
        write_byte $spichan $address $bindata
    }

    for {set address 0} {$address < 16} {incr address} {
        set bindata [read_byte $spichan $address]
        binary scan $bindata Su $bindata data
        puts "reading address $address, data = $data"
    }

    mpssespi closeChannel $spichan
}

# Run the example
main







|





|








52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
        csactive high
    }
    mpssespi initChannel $spichan       ; # <1>

    for {set address 0} {$address < 16} {incr address} {
        set data [expr {$address + 3}]
        puts "writing address $address, data = $data"
        set bindata [binary format S $data]     ; # <2>
        write_byte $spichan $address $bindata
    }

    for {set address 0} {$address < 16} {incr address} {
        set bindata [read_byte $spichan $address]
        binary scan $bindata Su $bindata data   ; # <3>
        puts "reading address $address, data = $data"
    }

    mpssespi closeChannel $spichan
}

# Run the example
main