4
Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
10
Fax: +49(0)7223/9493-92
11
http://www.addi-data.com
14
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
16
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
You should also find the complete GPL in the COPYING file accompanying this source code.
26
+-----------------------------------------------------------------------+
27
| (C) ADDI-DATA GmbH DieselstraĆe 3 D-77833 Ottersweier |
28
+-----------------------------------------------------------------------+
29
| Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com |
30
| Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com |
31
+-----------------------------------------------------------------------+
32
| Project : API APCI1710 | Compiler : gcc |
33
| Module name : PWM.C | Version : 2.96 |
34
+-------------------------------+---------------------------------------+
35
| Project manager: Eric Stolz | Date : 02/12/2002 |
36
+-----------------------------------------------------------------------+
37
| Description : APCI-1710 Wulse wide modulation module |
40
+-----------------------------------------------------------------------+
42
+-----------------------------------------------------------------------+
43
| Date | Author | Description of updates |
44
+-----------------------------------------------------------------------+
45
| 08/05/00 | Guinot C | - 0400/0228 All Function in RING 0 |
47
+-----------------------------------------------------------------------+
51
+----------------------------------------------------------------------------+
53
+----------------------------------------------------------------------------+
56
#include "APCI1710_Pwm.h"
59
+----------------------------------------------------------------------------+
60
| Function Name :INT i_APCI1710_InsnConfigPWM(struct comedi_device *dev,
61
struct comedi_subdevice *s,struct comedi_insn *insn,unsigned int *data) |
62
+----------------------------------------------------------------------------+
63
| Task : Pwm Init and Get Pwm Initialisation |
64
+----------------------------------------------------------------------------+
66
+----------------------------------------------------------------------------+
67
| Output Parameters : - |
68
+----------------------------------------------------------------------------+
70
+----------------------------------------------------------------------------+
73
int i_APCI1710_InsnConfigPWM(struct comedi_device *dev, struct comedi_subdevice *s,
74
struct comedi_insn *insn, unsigned int *data)
76
unsigned char b_ConfigType;
77
int i_ReturnValue = 0;
78
b_ConfigType = CR_CHAN(insn->chanspec);
80
switch (b_ConfigType) {
81
case APCI1710_PWM_INIT:
82
i_ReturnValue = i_APCI1710_InitPWM(dev, (unsigned char) CR_AREF(insn->chanspec), /* b_ModulNbr */
83
(unsigned char) data[0], /* b_PWM */
84
(unsigned char) data[1], /* b_ClockSelection */
85
(unsigned char) data[2], /* b_TimingUnit */
86
(unsigned int) data[3], /* ul_LowTiming */
87
(unsigned int) data[4], /* ul_HighTiming */
88
(unsigned int *) &data[0], /* pul_RealLowTiming */
89
(unsigned int *) &data[1] /* pul_RealHighTiming */
93
case APCI1710_PWM_GETINITDATA:
94
i_ReturnValue = i_APCI1710_GetPWMInitialisation(dev, (unsigned char) CR_AREF(insn->chanspec), /* b_ModulNbr */
95
(unsigned char) data[0], /* b_PWM */
96
(unsigned char *) &data[0], /* pb_TimingUnit */
97
(unsigned int *) &data[1], /* pul_LowTiming */
98
(unsigned int *) &data[2], /* pul_HighTiming */
99
(unsigned char *) &data[3], /* pb_StartLevel */
100
(unsigned char *) &data[4], /* pb_StopMode */
101
(unsigned char *) &data[5], /* pb_StopLevel */
102
(unsigned char *) &data[6], /* pb_ExternGate */
103
(unsigned char *) &data[7], /* pb_InterruptEnable */
104
(unsigned char *) &data[8] /* pb_Enable */
109
printk(" Config Parameter Wrong\n");
112
if (i_ReturnValue >= 0)
113
i_ReturnValue = insn->n;
114
return i_ReturnValue;
118
+----------------------------------------------------------------------------+
119
| Function Name : _INT_ i_APCI1710_InitPWM |
120
| (unsigned char_ b_BoardHandle, |
121
| unsigned char_ b_ModulNbr, |
122
| unsigned char_ b_PWM, |
123
| unsigned char_ b_ClockSelection, |
124
| unsigned char_ b_TimingUnit, |
125
| ULONG_ ul_LowTiming, |
126
| ULONG_ ul_HighTiming, |
127
| PULONG_ pul_RealLowTiming, |
128
| PULONG_ pul_RealHighTiming) |
129
+----------------------------------------------------------------------------+
130
| Task : Configure the selected PWM (b_PWM) from selected module|
131
| (b_ModulNbr). The ul_LowTiming, ul_HighTiming and |
132
| ul_TimingUnit determine the low/high timing base for |
133
| the period. pul_RealLowTiming, pul_RealHighTiming |
134
| return the real timing value. |
135
| You must calling this function be for you call any |
136
| other function witch access of the PWM. |
137
+----------------------------------------------------------------------------+
138
| Input Parameters : unsigned char_ b_BoardHandle : Handle of board APCI-1710 |
139
| unsigned char_ b_ModulNbr : Module number to configure|
141
| unsigned char_ b_PWM : Selected PWM (0 or 1). |
142
| unsigned char_ b_ClockSelection : Selection from PCI bus |
144
| - APCI1710_30MHZ : |
145
| The PC have a 30 MHz |
147
| - APCI1710_33MHZ : |
148
| The PC have a 33 MHz |
151
| The APCI-1710 have a |
154
| unsigned char_ b_TimingUnit : Base timing Unit (0 to 4) |
160
| ULONG_ ul_LowTiming : Low base timing value. |
161
| ULONG_ ul_HighTiming : High base timing value. |
162
+----------------------------------------------------------------------------+
163
| Output Parameters : PULONG_ pul_RealLowTiming : Real low base timing |
165
| PULONG_ pul_RealHighTiming : Real high base timing |
167
+----------------------------------------------------------------------------+
168
| Return Value : 0: No error |
169
| -1: The handle parameter of the board is wrong |
170
| -2: Module selection wrong |
171
| -3: The module is not a PWM module |
172
| -4: PWM selection is wrong |
173
| -5: The selected input clock is wrong |
174
| -6: Timing Unit selection is wrong |
175
| -7: Low base timing selection is wrong |
176
| -8: High base timing selection is wrong |
177
| -9: You can not used the 40MHz clock selection with |
179
+----------------------------------------------------------------------------+
182
int i_APCI1710_InitPWM(struct comedi_device *dev,
183
unsigned char b_ModulNbr,
185
unsigned char b_ClockSelection,
186
unsigned char b_TimingUnit,
187
unsigned int ul_LowTiming,
188
unsigned int ul_HighTiming,
189
unsigned int *pul_RealLowTiming, unsigned int *pul_RealHighTiming)
191
int i_ReturnValue = 0;
192
unsigned int ul_LowTimerValue = 0;
193
unsigned int ul_HighTimerValue = 0;
194
unsigned int dw_Command;
195
double d_RealLowTiming = 0;
196
double d_RealHighTiming = 0;
198
/**************************/
199
/* Test the module number */
200
/**************************/
202
if (b_ModulNbr < 4) {
207
if ((devpriv->s_BoardInfos.
208
dw_MolduleConfiguration[b_ModulNbr] &
209
0xFFFF0000UL) == APCI1710_PWM) {
210
/**************************/
211
/* Test the PWM selection */
212
/**************************/
219
if ((b_ClockSelection == APCI1710_30MHZ) ||
220
(b_ClockSelection == APCI1710_33MHZ) ||
221
(b_ClockSelection == APCI1710_40MHZ)) {
222
/************************/
223
/* Test the timing unit */
224
/************************/
226
if (b_TimingUnit <= 4) {
227
/*********************************/
228
/* Test the low timing selection */
229
/*********************************/
231
if (((b_ClockSelection ==
240
|| ((b_ClockSelection ==
249
|| ((b_ClockSelection ==
258
|| ((b_ClockSelection ==
267
|| ((b_ClockSelection ==
275
|| ((b_ClockSelection ==
284
|| ((b_ClockSelection ==
293
|| ((b_ClockSelection ==
302
|| ((b_ClockSelection ==
311
|| ((b_ClockSelection ==
319
|| ((b_ClockSelection ==
328
|| ((b_ClockSelection ==
337
|| ((b_ClockSelection ==
346
|| ((b_ClockSelection ==
355
|| ((b_ClockSelection ==
364
/**********************************/
365
/* Test the High timing selection */
366
/**********************************/
368
if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 266) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230650UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 9UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 242) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691043UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 520UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 8UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 200) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496729UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 7UL))) {
369
/**************************/
370
/* Test the board version */
371
/**************************/
373
if (((b_ClockSelection == APCI1710_40MHZ) && (devpriv->s_BoardInfos.b_BoardVersion > 0)) || (b_ClockSelection != APCI1710_40MHZ)) {
375
/************************************/
376
/* Calculate the low division fator */
377
/************************************/
382
switch (b_TimingUnit) {
398
(0.00025 * b_ClockSelection));
400
/*******************/
401
/* Round the value */
402
/*******************/
404
if ((double)((double)ul_LowTiming * (0.00025 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) {
412
/*****************************/
413
/* Calculate the real timing */
414
/*****************************/
421
(0.00025 * (double)b_ClockSelection));
432
if ((double)((double)ul_LowTimerValue / (0.00025 * (double)b_ClockSelection)) >= (double)((double)*pul_RealLowTiming + 0.5)) {
451
if (b_ClockSelection != APCI1710_40MHZ) {
479
(0.25 * b_ClockSelection));
481
/*******************/
482
/* Round the value */
483
/*******************/
485
if ((double)((double)ul_LowTiming * (0.25 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) {
493
/*****************************/
494
/* Calculate the real timing */
495
/*****************************/
502
(0.25 * (double)b_ClockSelection));
515
if ((double)((double)ul_LowTimerValue / (0.25 * (double)b_ClockSelection)) >= (double)((double)*pul_RealLowTiming + 0.5)) {
534
if (b_ClockSelection != APCI1710_40MHZ) {
565
/*******************/
566
/* Round the value */
567
/*******************/
569
if ((double)((double)ul_LowTiming * (250.0 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) {
577
/*****************************/
578
/* Calculate the real timing */
579
/*****************************/
586
(250.0 * (double)b_ClockSelection));
597
if ((double)((double)ul_LowTimerValue / (250.0 * (double)b_ClockSelection)) >= (double)((double)*pul_RealLowTiming + 0.5)) {
616
if (b_ClockSelection != APCI1710_40MHZ) {
647
/*******************/
648
/* Round the value */
649
/*******************/
651
if ((double)((double)ul_LowTiming * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) {
659
/*****************************/
660
/* Calculate the real timing */
661
/*****************************/
682
if ((double)((double)ul_LowTimerValue / (250000.0 * (double)b_ClockSelection)) >= (double)((double)*pul_RealLowTiming + 0.5)) {
701
if (b_ClockSelection != APCI1710_40MHZ) {
736
/*******************/
737
/* Round the value */
738
/*******************/
740
if ((double)((double)(ul_LowTiming * 60.0) * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) {
748
/*****************************/
749
/* Calculate the real timing */
750
/*****************************/
776
if ((double)(((double)ul_LowTimerValue / (250000.0 * (double)b_ClockSelection)) / 60.0) >= (double)((double)*pul_RealLowTiming + 0.5)) {
795
if (b_ClockSelection != APCI1710_40MHZ) {
809
/*************************************/
810
/* Calculate the high division fator */
811
/*************************************/
813
switch (b_TimingUnit) {
829
(0.00025 * b_ClockSelection));
831
/*******************/
832
/* Round the value */
833
/*******************/
835
if ((double)((double)ul_HighTiming * (0.00025 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) {
843
/*****************************/
844
/* Calculate the real timing */
845
/*****************************/
852
(0.00025 * (double)b_ClockSelection));
863
if ((double)((double)ul_HighTimerValue / (0.00025 * (double)b_ClockSelection)) >= (double)((double)*pul_RealHighTiming + 0.5)) {
882
if (b_ClockSelection != APCI1710_40MHZ) {
910
(0.25 * b_ClockSelection));
912
/*******************/
913
/* Round the value */
914
/*******************/
916
if ((double)((double)ul_HighTiming * (0.25 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) {
924
/*****************************/
925
/* Calculate the real timing */
926
/*****************************/
933
(0.25 * (double)b_ClockSelection));
946
if ((double)((double)ul_HighTimerValue / (0.25 * (double)b_ClockSelection)) >= (double)((double)*pul_RealHighTiming + 0.5)) {
965
if (b_ClockSelection != APCI1710_40MHZ) {
996
/*******************/
997
/* Round the value */
998
/*******************/
1000
if ((double)((double)ul_HighTiming * (250.0 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) {
1008
/*****************************/
1009
/* Calculate the real timing */
1010
/*****************************/
1017
(250.0 * (double)b_ClockSelection));
1028
if ((double)((double)ul_HighTimerValue / (250.0 * (double)b_ClockSelection)) >= (double)((double)*pul_RealHighTiming + 0.5)) {
1047
if (b_ClockSelection != APCI1710_40MHZ) {
1066
/******************/
1067
/* Timer 0 factor */
1068
/******************/
1079
/*******************/
1080
/* Round the value */
1081
/*******************/
1083
if ((double)((double)ul_HighTiming * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) {
1091
/*****************************/
1092
/* Calculate the real timing */
1093
/*****************************/
1114
if ((double)((double)ul_HighTimerValue / (250000.0 * (double)b_ClockSelection)) >= (double)((double)*pul_RealHighTiming + 0.5)) {
1133
if (b_ClockSelection != APCI1710_40MHZ) {
1152
/******************/
1153
/* Timer 0 factor */
1154
/******************/
1168
/*******************/
1169
/* Round the value */
1170
/*******************/
1172
if ((double)((double)(ul_HighTiming * 60.0) * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) {
1180
/*****************************/
1181
/* Calculate the real timing */
1182
/*****************************/
1208
if ((double)(((double)ul_HighTimerValue / (250000.0 * (double)b_ClockSelection)) / 60.0) >= (double)((double)*pul_RealHighTiming + 0.5)) {
1227
if (b_ClockSelection != APCI1710_40MHZ) {
1242
/****************************/
1243
/* Save the clock selection */
1244
/****************************/
1254
/************************/
1255
/* Save the timing unit */
1256
/************************/
1268
/****************************/
1269
/* Save the low base timing */
1270
/****************************/
1292
/****************************/
1293
/* Save the high base timing */
1294
/****************************/
1314
*pul_RealHighTiming;
1316
/************************/
1317
/* Write the low timing */
1318
/************************/
1320
outl(ul_LowTimerValue, devpriv->s_BoardInfos.ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr));
1322
/*************************/
1323
/* Write the high timing */
1324
/*************************/
1326
outl(ul_HighTimerValue, devpriv->s_BoardInfos.ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr));
1328
/***************************/
1329
/* Set the clock selection */
1330
/***************************/
1341
(20 * b_PWM) + (64 * b_ModulNbr));
1349
if (b_ClockSelection == APCI1710_40MHZ) {
1357
/***************************/
1358
/* Set the clock selection */
1359
/***************************/
1361
outl(dw_Command, devpriv->s_BoardInfos.ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));
1376
/***************************************************/
1377
/* You can not used the 40MHz clock selection with */
1379
/***************************************************/
1380
DPRINTK("You can not used the 40MHz clock selection with this board\n");
1386
/***************************************/
1387
/* High base timing selection is wrong */
1388
/***************************************/
1389
DPRINTK("High base timing selection is wrong\n");
1394
/**************************************/
1395
/* Low base timing selection is wrong */
1396
/**************************************/
1397
DPRINTK("Low base timing selection is wrong\n");
1400
} /* if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) */
1402
/**********************************/
1403
/* Timing unit selection is wrong */
1404
/**********************************/
1405
DPRINTK("Timing unit selection is wrong\n");
1407
} /* if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) */
1408
} /* if ((b_ClockSelection == APCI1710_30MHZ) || (b_ClockSelection == APCI1710_33MHZ) || (b_ClockSelection == APCI1710_40MHZ)) */
1410
/*******************************/
1411
/* The selected clock is wrong */
1412
/*******************************/
1413
DPRINTK("The selected clock is wrong\n");
1415
} /* if ((b_ClockSelection == APCI1710_30MHZ) || (b_ClockSelection == APCI1710_33MHZ) || (b_ClockSelection == APCI1710_40MHZ)) */
1416
} /* if (b_PWM >= 0 && b_PWM <= 1) */
1418
/******************************/
1419
/* Tor PWM selection is wrong */
1420
/******************************/
1421
DPRINTK("Tor PWM selection is wrong\n");
1423
} /* if (b_PWM >= 0 && b_PWM <= 1) */
1425
/**********************************/
1426
/* The module is not a PWM module */
1427
/**********************************/
1428
DPRINTK("The module is not a PWM module\n");
1432
/***********************/
1433
/* Module number error */
1434
/***********************/
1435
DPRINTK("Module number error\n");
1439
return i_ReturnValue;
1443
+----------------------------------------------------------------------------+
1444
| Function Name : _INT_ i_APCI1710_GetPWMInitialisation |
1445
| (unsigned char_ b_BoardHandle, |
1446
| unsigned char_ b_ModulNbr, |
1447
| unsigned char_ b_PWM, |
1448
| unsigned char *_ pb_TimingUnit, |
1449
| PULONG_ pul_LowTiming, |
1450
| PULONG_ pul_HighTiming, |
1451
| unsigned char *_ pb_StartLevel, |
1452
| unsigned char *_ pb_StopMode, |
1453
| unsigned char *_ pb_StopLevel, |
1454
| unsigned char *_ pb_ExternGate, |
1455
| unsigned char *_ pb_InterruptEnable, |
1456
| unsigned char *_ pb_Enable) |
1457
+----------------------------------------------------------------------------+
1458
| Task : Return the PWM (b_PWM) initialisation from selected |
1459
| module (b_ModulNbr). You must calling the |
1460
| "i_APCI1710_InitPWM" function be for you call this |
1462
+----------------------------------------------------------------------------+
1463
| Input Parameters : unsigned char_ b_BoardHandle : Handle of board APCI-1710 |
1464
| unsigned char_ b_ModulNbr : Selected module number (0 to 3) |
1465
| unsigned char_ b_PWM : Selected PWM (0 or 1) |
1466
+----------------------------------------------------------------------------+
1467
| Output Parameters : unsigned char *_ pb_TimingUnit : Base timing Unit (0 to 4) |
1473
| PULONG_ pul_LowTiming : Low base timing value. |
1474
| PULONG_ pul_HighTiming : High base timing value. |
1475
| unsigned char *_ pb_StartLevel : Start period level |
1477
| 0 : The period start |
1478
| with a low level |
1479
| 1 : The period start |
1480
| with a high level|
1481
| unsigned char *_ pb_StopMode : Stop mode selection |
1482
| 0 : The PWM is stopped |
1483
| directly after the |
1484
| "i_APCI1710_DisablePWM"|
1485
| function and break the|
1488
| "i_APCI1710_DisablePWM"|
1489
| function the PWM is |
1490
| stopped at the end |
1491
| from last period cycle|
1492
| unsigned char *_ pb_StopLevel : Stop PWM level selection |
1493
| 0 : The output signal |
1494
| keep the level after|
1496
| "i_APCI1710_DisablePWM"|
1498
| 1 : The output signal is|
1499
| set to low after the|
1500
| "i_APCI1710_DisablePWM"|
1502
| 2 : The output signal is|
1503
| set to high after |
1505
| "i_APCI1710_DisablePWM"|
1507
| unsigned char *_ pb_ExternGate : Extern gate action |
1509
| 0 : Extern gate signal |
1511
| 1 : Extern gate signal |
1513
| unsigned char *_ pb_InterruptEnable : Enable or disable the PWM |
1515
| - APCI1710_ENABLE : |
1516
| Enable the PWM interrupt|
1517
| A interrupt occur after |
1519
| - APCI1710_DISABLE : |
1522
| unsigned char *_ pb_Enable : Indicate if the PWM is |
1524
| 0 : PWM not enabled |
1526
+----------------------------------------------------------------------------+
1527
| Return Value : 0: No error |
1528
| -1: The handle parameter of the board is wrong |
1529
| -2: Module selection wrong |
1530
| -3: The module is not a PWM module |
1531
| -4: PWM selection is wrong |
1532
| -5: PWM not initialised see function |
1533
| "i_APCI1710_InitPWM" |
1534
+----------------------------------------------------------------------------+
1537
int i_APCI1710_GetPWMInitialisation(struct comedi_device *dev,
1538
unsigned char b_ModulNbr,
1539
unsigned char b_PWM,
1540
unsigned char *pb_TimingUnit,
1541
unsigned int *pul_LowTiming,
1542
unsigned int *pul_HighTiming,
1543
unsigned char *pb_StartLevel,
1544
unsigned char *pb_StopMode,
1545
unsigned char *pb_StopLevel,
1546
unsigned char *pb_ExternGate, unsigned char *pb_InterruptEnable, unsigned char *pb_Enable)
1548
int i_ReturnValue = 0;
1549
unsigned int dw_Status;
1550
unsigned int dw_Command;
1552
/**************************/
1553
/* Test the module number */
1554
/**************************/
1556
if (b_ModulNbr < 4) {
1561
if ((devpriv->s_BoardInfos.
1562
dw_MolduleConfiguration[b_ModulNbr] &
1563
0xFFFF0000UL) == APCI1710_PWM) {
1564
/**************************/
1565
/* Test the PWM selection */
1566
/**************************/
1569
/***************************/
1570
/* Test if PWM initialised */
1571
/***************************/
1573
dw_Status = inl(devpriv->s_BoardInfos.
1574
ui_Address + 12 + (20 * b_PWM) +
1577
if (dw_Status & 0x10) {
1578
/***********************/
1579
/* Read the low timing */
1580
/***********************/
1583
inl(devpriv->s_BoardInfos.
1584
ui_Address + 0 + (20 * b_PWM) +
1587
/************************/
1588
/* Read the high timing */
1589
/************************/
1592
inl(devpriv->s_BoardInfos.
1593
ui_Address + 4 + (20 * b_PWM) +
1596
/********************/
1597
/* Read the command */
1598
/********************/
1600
dw_Command = inl(devpriv->s_BoardInfos.
1601
ui_Address + 8 + (20 * b_PWM) +
1605
(unsigned char) ((dw_Command >> 5) & 1);
1607
(unsigned char) ((dw_Command >> 0) & 1);
1609
(unsigned char) ((dw_Command >> 1) & 1);
1611
(unsigned char) ((dw_Command >> 4) & 1);
1612
*pb_InterruptEnable =
1613
(unsigned char) ((dw_Command >> 3) & 1);
1615
if (*pb_StopLevel) {
1618
(unsigned char) ((dw_Command >>
1622
/********************/
1623
/* Read the command */
1624
/********************/
1626
dw_Command = inl(devpriv->s_BoardInfos.
1627
ui_Address + 8 + (20 * b_PWM) +
1631
(unsigned char) ((dw_Command >> 0) & 1);
1633
*pb_TimingUnit = devpriv->
1634
s_ModuleInfo[b_ModulNbr].
1636
s_PWMInfo[b_PWM].b_TimingUnit;
1637
} /* if (dw_Status & 0x10) */
1639
/***********************/
1640
/* PWM not initialised */
1641
/***********************/
1642
DPRINTK("PWM not initialised\n");
1644
} /* if (dw_Status & 0x10) */
1645
} /* if (b_PWM >= 0 && b_PWM <= 1) */
1647
/******************************/
1648
/* Tor PWM selection is wrong */
1649
/******************************/
1650
DPRINTK("Tor PWM selection is wrong\n");
1652
} /* if (b_PWM >= 0 && b_PWM <= 1) */
1654
/**********************************/
1655
/* The module is not a PWM module */
1656
/**********************************/
1657
DPRINTK("The module is not a PWM module\n");
1661
/***********************/
1662
/* Module number error */
1663
/***********************/
1664
DPRINTK("Module number error\n");
1668
return i_ReturnValue;
1672
+----------------------------------------------------------------------------+
1673
| Function Name :INT i_APCI1710_InsnWritePWM(struct comedi_device *dev,
1674
struct comedi_subdevice *s,struct comedi_insn *insn,unsigned int *data) |
1675
+----------------------------------------------------------------------------+
1676
| Task : Pwm Enable Disable and Set New Timing |
1677
+----------------------------------------------------------------------------+
1678
| Input Parameters :
1679
+----------------------------------------------------------------------------+
1680
| Output Parameters : - |
1681
+----------------------------------------------------------------------------+
1683
+----------------------------------------------------------------------------+
1686
int i_APCI1710_InsnWritePWM(struct comedi_device *dev, struct comedi_subdevice *s,
1687
struct comedi_insn *insn, unsigned int *data)
1689
unsigned char b_WriteType;
1690
int i_ReturnValue = 0;
1691
b_WriteType = CR_CHAN(insn->chanspec);
1693
switch (b_WriteType) {
1694
case APCI1710_PWM_ENABLE:
1695
i_ReturnValue = i_APCI1710_EnablePWM(dev,
1696
(unsigned char) CR_AREF(insn->chanspec),
1697
(unsigned char) data[0],
1698
(unsigned char) data[1],
1699
(unsigned char) data[2],
1700
(unsigned char) data[3], (unsigned char) data[4], (unsigned char) data[5]);
1703
case APCI1710_PWM_DISABLE:
1704
i_ReturnValue = i_APCI1710_DisablePWM(dev,
1705
(unsigned char) CR_AREF(insn->chanspec), (unsigned char) data[0]);
1708
case APCI1710_PWM_NEWTIMING:
1709
i_ReturnValue = i_APCI1710_SetNewPWMTiming(dev,
1710
(unsigned char) CR_AREF(insn->chanspec),
1711
(unsigned char) data[0],
1712
(unsigned char) data[1], (unsigned int) data[2], (unsigned int) data[3]);
1716
printk("Write Config Parameter Wrong\n");
1719
if (i_ReturnValue >= 0)
1720
i_ReturnValue = insn->n;
1721
return i_ReturnValue;
1725
+----------------------------------------------------------------------------+
1726
| Function Name : _INT_ i_APCI1710_EnablePWM |
1727
| (unsigned char_ b_BoardHandle, |
1728
| unsigned char_ b_ModulNbr, |
1729
| unsigned char_ b_PWM, |
1730
| unsigned char_ b_StartLevel, |
1731
| unsigned char_ b_StopMode, |
1732
| unsigned char_ b_StopLevel, |
1733
| unsigned char_ b_ExternGate, |
1734
| unsigned char_ b_InterruptEnable) |
1735
+----------------------------------------------------------------------------+
1736
| Task : Enable the selected PWM (b_PWM) from selected module |
1737
| (b_ModulNbr). You must calling the "i_APCI1710_InitPWM"|
1738
| function be for you call this function. |
1739
| If you enable the PWM interrupt, the PWM generate a |
1740
| interrupt after each period. |
1741
| See function "i_APCI1710_SetBoardIntRoutineX" and the |
1742
| Interrupt mask description chapter. |
1743
+----------------------------------------------------------------------------+
1744
| Input Parameters : unsigned char_ b_BoardHandle : Handle of board APCI-1710 |
1745
| unsigned char_ b_ModulNbr : Selected module number |
1747
| unsigned char_ b_PWM : Selected PWM (0 or 1) |
1748
| unsigned char_ b_StartLevel : Start period level selection |
1749
| 0 : The period start with a |
1751
| 1 : The period start with a |
1753
| unsigned char_ b_StopMode : Stop mode selection |
1754
| 0 : The PWM is stopped |
1755
| directly after the |
1756
| "i_APCI1710_DisablePWM" |
1757
| function and break the |
1760
| "i_APCI1710_DisablePWM" |
1761
| function the PWM is |
1762
| stopped at the end from|
1763
| last period cycle. |
1764
| unsigned char_ b_StopLevel : Stop PWM level selection |
1765
| 0 : The output signal keep |
1766
| the level after the |
1767
| "i_APCI1710_DisablePWM" |
1769
| 1 : The output signal is set|
1770
| to low after the |
1771
| "i_APCI1710_DisablePWM" |
1773
| 2 : The output signal is set|
1774
| to high after the |
1775
| "i_APCI1710_DisablePWM" |
1777
| unsigned char_ b_ExternGate : Extern gate action selection |
1778
| 0 : Extern gate signal not |
1780
| 1 : Extern gate signal used.|
1781
| unsigned char_ b_InterruptEnable : Enable or disable the PWM |
1783
| - APCI1710_ENABLE : |
1784
| Enable the PWM interrupt |
1785
| A interrupt occur after |
1787
| - APCI1710_DISABLE : |
1788
| Disable the PWM interrupt |
1789
+----------------------------------------------------------------------------+
1790
| Output Parameters : - |
1791
+----------------------------------------------------------------------------+
1792
| Return Value : 0: No error |
1793
| -1: The handle parameter of the board is wrong |
1794
| -2: Module selection wrong |
1795
| -3: The module is not a PWM module |
1796
| -4: PWM selection is wrong |
1797
| -5: PWM not initialised see function |
1798
| "i_APCI1710_InitPWM" |
1799
| -6: PWM start level selection is wrong |
1800
| -7: PWM stop mode selection is wrong |
1801
| -8: PWM stop level selection is wrong |
1802
| -9: Extern gate signal selection is wrong |
1803
| -10: Interrupt parameter is wrong |
1804
| -11: Interrupt function not initialised. |
1805
| See function "i_APCI1710_SetBoardIntRoutineX" |
1806
+----------------------------------------------------------------------------+
1809
int i_APCI1710_EnablePWM(struct comedi_device *dev,
1810
unsigned char b_ModulNbr,
1811
unsigned char b_PWM,
1812
unsigned char b_StartLevel,
1813
unsigned char b_StopMode,
1814
unsigned char b_StopLevel, unsigned char b_ExternGate, unsigned char b_InterruptEnable)
1816
int i_ReturnValue = 0;
1817
unsigned int dw_Status;
1818
unsigned int dw_Command;
1820
devpriv->tsk_Current = current; /* Save the current process task structure */
1821
/**************************/
1822
/* Test the module number */
1823
/**************************/
1825
if (b_ModulNbr < 4) {
1830
if ((devpriv->s_BoardInfos.
1831
dw_MolduleConfiguration[b_ModulNbr] &
1832
0xFFFF0000UL) == APCI1710_PWM) {
1833
/**************************/
1834
/* Test the PWM selection */
1835
/**************************/
1838
/***************************/
1839
/* Test if PWM initialised */
1840
/***************************/
1842
dw_Status = inl(devpriv->s_BoardInfos.
1843
ui_Address + 12 + (20 * b_PWM) +
1846
if (dw_Status & 0x10) {
1847
/**********************************/
1848
/* Test the start level selection */
1849
/**********************************/
1851
if (b_StartLevel <= 1) {
1852
/**********************/
1853
/* Test the stop mode */
1854
/**********************/
1856
if (b_StopMode <= 1) {
1857
/***********************/
1858
/* Test the stop level */
1859
/***********************/
1861
if (b_StopLevel <= 2) {
1862
/*****************************/
1863
/* Test the extern gate mode */
1864
/*****************************/
1868
/*****************************/
1869
/* Test the interrupt action */
1870
/*****************************/
1872
if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE) {
1873
/******************************************/
1874
/* Test if interrupt function initialised */
1875
/******************************************/
1877
/********************/
1878
/* Read the command */
1879
/********************/
1890
(20 * b_PWM) + (64 * b_ModulNbr));
1898
/********************/
1899
/* Make the command */
1900
/********************/
1920
if (b_StopLevel & 3) {
1927
if (b_StopLevel & 2) {
1946
/*******************/
1947
/* Set the command */
1948
/*******************/
1950
outl(dw_Command, devpriv->s_BoardInfos.ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));
1952
/******************/
1953
/* Enable the PWM */
1954
/******************/
1955
outl(1, devpriv->s_BoardInfos.ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));
1956
} /* if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE) */
1958
/********************************/
1959
/* Interrupt parameter is wrong */
1960
/********************************/
1961
DPRINTK("Interrupt parameter is wrong\n");
1965
} /* if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE) */
1966
} /* if (b_ExternGate >= 0 && b_ExternGate <= 1) */
1968
/*****************************************/
1969
/* Extern gate signal selection is wrong */
1970
/*****************************************/
1971
DPRINTK("Extern gate signal selection is wrong\n");
1975
} /* if (b_ExternGate >= 0 && b_ExternGate <= 1) */
1976
} /* if (b_StopLevel >= 0 && b_StopLevel <= 2) */
1978
/*************************************/
1979
/* PWM stop level selection is wrong */
1980
/*************************************/
1981
DPRINTK("PWM stop level selection is wrong\n");
1984
} /* if (b_StopLevel >= 0 && b_StopLevel <= 2) */
1985
} /* if (b_StopMode >= 0 && b_StopMode <= 1) */
1987
/************************************/
1988
/* PWM stop mode selection is wrong */
1989
/************************************/
1990
DPRINTK("PWM stop mode selection is wrong\n");
1992
} /* if (b_StopMode >= 0 && b_StopMode <= 1) */
1993
} /* if (b_StartLevel >= 0 && b_StartLevel <= 1) */
1995
/**************************************/
1996
/* PWM start level selection is wrong */
1997
/**************************************/
1998
DPRINTK("PWM start level selection is wrong\n");
2000
} /* if (b_StartLevel >= 0 && b_StartLevel <= 1) */
2001
} /* if (dw_Status & 0x10) */
2003
/***********************/
2004
/* PWM not initialised */
2005
/***********************/
2006
DPRINTK("PWM not initialised\n");
2008
} /* if (dw_Status & 0x10) */
2009
} /* if (b_PWM >= 0 && b_PWM <= 1) */
2011
/******************************/
2012
/* Tor PWM selection is wrong */
2013
/******************************/
2014
DPRINTK("Tor PWM selection is wrong\n");
2016
} /* if (b_PWM >= 0 && b_PWM <= 1) */
2018
/**********************************/
2019
/* The module is not a PWM module */
2020
/**********************************/
2021
DPRINTK("The module is not a PWM module\n");
2025
/***********************/
2026
/* Module number error */
2027
/***********************/
2028
DPRINTK("Module number error\n");
2032
return i_ReturnValue;
2036
+----------------------------------------------------------------------------+
2037
| Function Name : _INT_ i_APCI1710_DisablePWM (unsigned char_ b_BoardHandle, |
2038
| unsigned char_ b_ModulNbr, |
2039
| unsigned char_ b_PWM) |
2040
+----------------------------------------------------------------------------+
2041
| Task : Disable the selected PWM (b_PWM) from selected module |
2042
| (b_ModulNbr). The output signal level depend of the |
2043
| initialisation by the "i_APCI1710_EnablePWM". |
2044
| See the b_StartLevel, b_StopMode and b_StopLevel |
2045
| parameters from this function. |
2046
+----------------------------------------------------------------------------+
2047
| Input Parameters :BYTE_ b_BoardHandle : Handle of board APCI-1710 |
2048
| unsigned char_ b_ModulNbr : Selected module number (0 to 3) |
2049
| unsigned char_ b_PWM : Selected PWM (0 or 1) |
2050
+----------------------------------------------------------------------------+
2051
| Output Parameters : - |
2052
+----------------------------------------------------------------------------+
2053
| Return Value : 0: No error |
2054
| -1: The handle parameter of the board is wrong |
2055
| -2: Module selection wrong |
2056
| -3: The module is not a PWM module |
2057
| -4: PWM selection is wrong |
2058
| -5: PWM not initialised see function |
2059
| "i_APCI1710_InitPWM" |
2060
| -6: PWM not enabled see function |
2061
| "i_APCI1710_EnablePWM" |
2062
+----------------------------------------------------------------------------+
2065
int i_APCI1710_DisablePWM(struct comedi_device *dev, unsigned char b_ModulNbr, unsigned char b_PWM)
2067
int i_ReturnValue = 0;
2068
unsigned int dw_Status;
2070
/**************************/
2071
/* Test the module number */
2072
/**************************/
2074
if (b_ModulNbr < 4) {
2079
if ((devpriv->s_BoardInfos.
2080
dw_MolduleConfiguration[b_ModulNbr] &
2081
0xFFFF0000UL) == APCI1710_PWM) {
2082
/**************************/
2083
/* Test the PWM selection */
2084
/**************************/
2087
/***************************/
2088
/* Test if PWM initialised */
2089
/***************************/
2091
dw_Status = inl(devpriv->s_BoardInfos.
2092
ui_Address + 12 + (20 * b_PWM) +
2095
if (dw_Status & 0x10) {
2096
/***********************/
2097
/* Test if PWM enabled */
2098
/***********************/
2100
if (dw_Status & 0x1) {
2101
/*******************/
2102
/* Disable the PWM */
2103
/*******************/
2104
outl(0, devpriv->s_BoardInfos.
2108
} /* if (dw_Status & 0x1) */
2110
/*******************/
2111
/* PWM not enabled */
2112
/*******************/
2113
DPRINTK("PWM not enabled\n");
2115
} /* if (dw_Status & 0x1) */
2116
} /* if (dw_Status & 0x10) */
2118
/***********************/
2119
/* PWM not initialised */
2120
/***********************/
2121
DPRINTK(" PWM not initialised\n");
2123
} /* if (dw_Status & 0x10) */
2124
} /* if (b_PWM >= 0 && b_PWM <= 1) */
2126
/******************************/
2127
/* Tor PWM selection is wrong */
2128
/******************************/
2129
DPRINTK("Tor PWM selection is wrong\n");
2131
} /* if (b_PWM >= 0 && b_PWM <= 1) */
2133
/**********************************/
2134
/* The module is not a PWM module */
2135
/**********************************/
2136
DPRINTK("The module is not a PWM module\n");
2140
/***********************/
2141
/* Module number error */
2142
/***********************/
2143
DPRINTK("Module number error\n");
2147
return i_ReturnValue;
2151
+----------------------------------------------------------------------------+
2152
| Function Name : _INT_ i_APCI1710_SetNewPWMTiming |
2153
| (unsigned char_ b_BoardHandle, |
2154
| unsigned char_ b_ModulNbr, |
2155
| unsigned char_ b_PWM, |
2156
| unsigned char_ b_ClockSelection, |
2157
| unsigned char_ b_TimingUnit, |
2158
| ULONG_ ul_LowTiming, |
2159
| ULONG_ ul_HighTiming) |
2160
+----------------------------------------------------------------------------+
2161
| Task : Set a new timing. The ul_LowTiming, ul_HighTiming and |
2162
| ul_TimingUnit determine the low/high timing base for |
2164
+----------------------------------------------------------------------------+
2165
| Input Parameters : unsigned char_ b_BoardHandle : Handle of board APCI-1710 |
2166
| unsigned char_ b_ModulNbr : Module number to configure|
2168
| unsigned char_ b_PWM : Selected PWM (0 or 1). |
2169
| unsigned char_ b_TimingUnit : Base timing Unit (0 to 4) |
2175
| ULONG_ ul_LowTiming : Low base timing value. |
2176
| ULONG_ ul_HighTiming : High base timing value. |
2177
+----------------------------------------------------------------------------+
2178
| Output Parameters : - |
2179
+----------------------------------------------------------------------------+
2180
| Return Value : 0: No error |
2181
| -1: The handle parameter of the board is wrong |
2182
| -2: Module selection wrong |
2183
| -3: The module is not a PWM module |
2184
| -4: PWM selection is wrong |
2185
| -5: PWM not initialised |
2186
| -6: Timing Unit selection is wrong |
2187
| -7: Low base timing selection is wrong |
2188
| -8: High base timing selection is wrong |
2189
+----------------------------------------------------------------------------+
2192
int i_APCI1710_SetNewPWMTiming(struct comedi_device *dev,
2193
unsigned char b_ModulNbr,
2194
unsigned char b_PWM, unsigned char b_TimingUnit, unsigned int ul_LowTiming, unsigned int ul_HighTiming)
2196
unsigned char b_ClockSelection;
2197
int i_ReturnValue = 0;
2198
unsigned int ul_LowTimerValue = 0;
2199
unsigned int ul_HighTimerValue = 0;
2200
unsigned int ul_RealLowTiming = 0;
2201
unsigned int ul_RealHighTiming = 0;
2202
unsigned int dw_Status;
2203
unsigned int dw_Command;
2204
double d_RealLowTiming = 0;
2205
double d_RealHighTiming = 0;
2207
/**************************/
2208
/* Test the module number */
2209
/**************************/
2211
if (b_ModulNbr < 4) {
2216
if ((devpriv->s_BoardInfos.
2217
dw_MolduleConfiguration[b_ModulNbr] &
2218
0xFFFF0000UL) == APCI1710_PWM) {
2219
/**************************/
2220
/* Test the PWM selection */
2221
/**************************/
2224
/***************************/
2225
/* Test if PWM initialised */
2226
/***************************/
2228
dw_Status = inl(devpriv->s_BoardInfos.
2229
ui_Address + 12 + (20 * b_PWM) +
2232
if (dw_Status & 0x10) {
2233
b_ClockSelection = devpriv->
2234
s_ModuleInfo[b_ModulNbr].
2238
/************************/
2239
/* Test the timing unit */
2240
/************************/
2242
if (b_TimingUnit <= 4) {
2243
/*********************************/
2244
/* Test the low timing selection */
2245
/*********************************/
2247
if (((b_ClockSelection ==
2256
|| ((b_ClockSelection ==
2265
|| ((b_ClockSelection ==
2274
|| ((b_ClockSelection ==
2283
|| ((b_ClockSelection ==
2291
|| ((b_ClockSelection ==
2300
|| ((b_ClockSelection ==
2309
|| ((b_ClockSelection ==
2318
|| ((b_ClockSelection ==
2327
|| ((b_ClockSelection ==
2335
|| ((b_ClockSelection ==
2344
|| ((b_ClockSelection ==
2353
|| ((b_ClockSelection ==
2362
|| ((b_ClockSelection ==
2371
|| ((b_ClockSelection ==
2380
/**********************************/
2381
/* Test the High timing selection */
2382
/**********************************/
2384
if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 266) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230650UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 9UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 242) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691043UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 520UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 8UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 200) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496729UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 7UL))) {
2385
/************************************/
2386
/* Calculate the low division fator */
2387
/************************************/
2390
switch (b_TimingUnit) {
2397
/******************/
2398
/* Timer 0 factor */
2399
/******************/
2406
(0.00025 * b_ClockSelection));
2408
/*******************/
2409
/* Round the value */
2410
/*******************/
2412
if ((double)((double)ul_LowTiming * (0.00025 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) {
2420
/*****************************/
2421
/* Calculate the real timing */
2422
/*****************************/
2429
(0.00025 * (double)b_ClockSelection));
2440
if ((double)((double)ul_LowTimerValue / (0.00025 * (double)b_ClockSelection)) >= (double)((double)ul_RealLowTiming + 0.5)) {
2459
if (b_ClockSelection != APCI1710_40MHZ) {
2478
/******************/
2479
/* Timer 0 factor */
2480
/******************/
2487
(0.25 * b_ClockSelection));
2489
/*******************/
2490
/* Round the value */
2491
/*******************/
2493
if ((double)((double)ul_LowTiming * (0.25 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) {
2501
/*****************************/
2502
/* Calculate the real timing */
2503
/*****************************/
2510
(0.25 * (double)b_ClockSelection));
2523
if ((double)((double)ul_LowTimerValue / (0.25 * (double)b_ClockSelection)) >= (double)((double)ul_RealLowTiming + 0.5)) {
2542
if (b_ClockSelection != APCI1710_40MHZ) {
2561
/******************/
2562
/* Timer 0 factor */
2563
/******************/
2573
/*******************/
2574
/* Round the value */
2575
/*******************/
2577
if ((double)((double)ul_LowTiming * (250.0 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) {
2585
/*****************************/
2586
/* Calculate the real timing */
2587
/*****************************/
2594
(250.0 * (double)b_ClockSelection));
2605
if ((double)((double)ul_LowTimerValue / (250.0 * (double)b_ClockSelection)) >= (double)((double)ul_RealLowTiming + 0.5)) {
2624
if (b_ClockSelection != APCI1710_40MHZ) {
2643
/******************/
2644
/* Timer 0 factor */
2645
/******************/
2656
/*******************/
2657
/* Round the value */
2658
/*******************/
2660
if ((double)((double)ul_LowTiming * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) {
2668
/*****************************/
2669
/* Calculate the real timing */
2670
/*****************************/
2691
if ((double)((double)ul_LowTimerValue / (250000.0 * (double)b_ClockSelection)) >= (double)((double)ul_RealLowTiming + 0.5)) {
2710
if (b_ClockSelection != APCI1710_40MHZ) {
2729
/******************/
2730
/* Timer 0 factor */
2731
/******************/
2745
/*******************/
2746
/* Round the value */
2747
/*******************/
2749
if ((double)((double)(ul_LowTiming * 60.0) * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) {
2757
/*****************************/
2758
/* Calculate the real timing */
2759
/*****************************/
2785
if ((double)(((double)ul_LowTimerValue / (250000.0 * (double)b_ClockSelection)) / 60.0) >= (double)((double)ul_RealLowTiming + 0.5)) {
2804
if (b_ClockSelection != APCI1710_40MHZ) {
2818
/*************************************/
2819
/* Calculate the high division fator */
2820
/*************************************/
2822
switch (b_TimingUnit) {
2829
/******************/
2830
/* Timer 0 factor */
2831
/******************/
2838
(0.00025 * b_ClockSelection));
2840
/*******************/
2841
/* Round the value */
2842
/*******************/
2844
if ((double)((double)ul_HighTiming * (0.00025 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) {
2852
/*****************************/
2853
/* Calculate the real timing */
2854
/*****************************/
2861
(0.00025 * (double)b_ClockSelection));
2872
if ((double)((double)ul_HighTimerValue / (0.00025 * (double)b_ClockSelection)) >= (double)((double)ul_RealHighTiming + 0.5)) {
2891
if (b_ClockSelection != APCI1710_40MHZ) {
2910
/******************/
2911
/* Timer 0 factor */
2912
/******************/
2919
(0.25 * b_ClockSelection));
2921
/*******************/
2922
/* Round the value */
2923
/*******************/
2925
if ((double)((double)ul_HighTiming * (0.25 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) {
2933
/*****************************/
2934
/* Calculate the real timing */
2935
/*****************************/
2942
(0.25 * (double)b_ClockSelection));
2955
if ((double)((double)ul_HighTimerValue / (0.25 * (double)b_ClockSelection)) >= (double)((double)ul_RealHighTiming + 0.5)) {
2974
if (b_ClockSelection != APCI1710_40MHZ) {
2993
/******************/
2994
/* Timer 0 factor */
2995
/******************/
3005
/*******************/
3006
/* Round the value */
3007
/*******************/
3009
if ((double)((double)ul_HighTiming * (250.0 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) {
3017
/*****************************/
3018
/* Calculate the real timing */
3019
/*****************************/
3026
(250.0 * (double)b_ClockSelection));
3037
if ((double)((double)ul_HighTimerValue / (250.0 * (double)b_ClockSelection)) >= (double)((double)ul_RealHighTiming + 0.5)) {
3056
if (b_ClockSelection != APCI1710_40MHZ) {
3075
/******************/
3076
/* Timer 0 factor */
3077
/******************/
3088
/*******************/
3089
/* Round the value */
3090
/*******************/
3092
if ((double)((double)ul_HighTiming * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) {
3100
/*****************************/
3101
/* Calculate the real timing */
3102
/*****************************/
3123
if ((double)((double)ul_HighTimerValue / (250000.0 * (double)b_ClockSelection)) >= (double)((double)ul_RealHighTiming + 0.5)) {
3142
if (b_ClockSelection != APCI1710_40MHZ) {
3161
/******************/
3162
/* Timer 0 factor */
3163
/******************/
3177
/*******************/
3178
/* Round the value */
3179
/*******************/
3181
if ((double)((double)(ul_HighTiming * 60.0) * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) {
3189
/*****************************/
3190
/* Calculate the real timing */
3191
/*****************************/
3217
if ((double)(((double)ul_HighTimerValue / (250000.0 * (double)b_ClockSelection)) / 60.0) >= (double)((double)ul_RealHighTiming + 0.5)) {
3236
if (b_ClockSelection != APCI1710_40MHZ) {
3252
/************************/
3253
/* Save the timing unit */
3254
/************************/
3266
/****************************/
3267
/* Save the low base timing */
3268
/****************************/
3290
/****************************/
3291
/* Save the high base timing */
3292
/****************************/
3314
/************************/
3315
/* Write the low timing */
3316
/************************/
3318
outl(ul_LowTimerValue, devpriv->s_BoardInfos.ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr));
3320
/*************************/
3321
/* Write the high timing */
3322
/*************************/
3324
outl(ul_HighTimerValue, devpriv->s_BoardInfos.ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr));
3326
/***************************/
3327
/* Set the clock selection */
3328
/***************************/
3336
(20 * b_PWM) + (64 * b_ModulNbr));
3342
if (b_ClockSelection == APCI1710_40MHZ) {
3350
/***************************/
3351
/* Set the clock selection */
3352
/***************************/
3359
(20 * b_PWM) + (64 * b_ModulNbr));
3361
/***************************************/
3362
/* High base timing selection is wrong */
3363
/***************************************/
3364
DPRINTK("High base timing selection is wrong\n");
3369
/**************************************/
3370
/* Low base timing selection is wrong */
3371
/**************************************/
3372
DPRINTK("Low base timing selection is wrong\n");
3375
} /* if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) */
3377
/**********************************/
3378
/* Timing unit selection is wrong */
3379
/**********************************/
3380
DPRINTK("Timing unit selection is wrong\n");
3382
} /* if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) */
3383
} /* if (dw_Status & 0x10) */
3385
/***********************/
3386
/* PWM not initialised */
3387
/***********************/
3388
DPRINTK("PWM not initialised\n");
3390
} /* if (dw_Status & 0x10) */
3391
} /* if (b_PWM >= 0 && b_PWM <= 1) */
3393
/******************************/
3394
/* Tor PWM selection is wrong */
3395
/******************************/
3396
DPRINTK("Tor PWM selection is wrong\n");
3398
} /* if (b_PWM >= 0 && b_PWM <= 1) */
3400
/**********************************/
3401
/* The module is not a PWM module */
3402
/**********************************/
3403
DPRINTK("The module is not a PWM module\n");
3407
/***********************/
3408
/* Module number error */
3409
/***********************/
3410
DPRINTK("Module number error\n");
3414
return i_ReturnValue;
3418
+----------------------------------------------------------------------------+
3419
| Function Name : _INT_ i_APCI1710_GetPWMStatus |
3420
| (unsigned char_ b_BoardHandle, |
3421
| unsigned char_ b_ModulNbr, |
3422
| unsigned char_ b_PWM, |
3423
| unsigned char *_ pb_PWMOutputStatus, |
3424
| unsigned char *_ pb_ExternGateStatus) |
3425
+----------------------------------------------------------------------------+
3426
| Task : Return the status from selected PWM (b_PWM) from |
3427
| selected module (b_ModulNbr). |
3428
+----------------------------------------------------------------------------+
3429
| Input Parameters : unsigned char_ b_BoardHandle : Handle of board APCI-1710 |
3430
| unsigned char_ b_PWM : Selected PWM (0 or 1) |
3431
| unsigned char_ b_ModulNbr : Selected module number (0 to 3)
3432
b_ModulNbr =(unsigned char) CR_AREF(insn->chanspec);
3433
b_PWM =(unsigned char) data[0];
3436
+----------------------------------------------------------------------------+
3437
| Output Parameters : unsigned char *_ pb_PWMOutputStatus : Return the PWM output |
3439
| 0 : The PWM output level|
3441
| 1 : The PWM output level|
3443
| unsigned char *_ pb_ExternGateStatus : Return the extern gate |
3445
| 0 : The extern gate is |
3447
| 1 : The extern gate is |
3449
pb_PWMOutputStatus =(unsigned char *) data[0];
3450
pb_ExternGateStatus =(unsigned char *) data[1]; |
3451
+----------------------------------------------------------------------------+
3452
| Return Value : 0: No error |
3453
| -1: The handle parameter of the board is wrong |
3454
| -2: Module selection wrong |
3455
| -3: The module is not a PWM module |
3456
| -4: PWM selection is wrong |
3457
| -5: PWM not initialised see function |
3458
| "i_APCI1710_InitPWM" |
3459
| -6: PWM not enabled see function "i_APCI1710_EnablePWM"|
3460
+----------------------------------------------------------------------------+
3463
int i_APCI1710_InsnReadGetPWMStatus(struct comedi_device *dev, struct comedi_subdevice *s,
3464
struct comedi_insn *insn, unsigned int *data)
3466
int i_ReturnValue = 0;
3467
unsigned int dw_Status;
3469
unsigned char b_ModulNbr;
3470
unsigned char b_PWM;
3471
unsigned char *pb_PWMOutputStatus;
3472
unsigned char *pb_ExternGateStatus;
3474
i_ReturnValue = insn->n;
3475
b_ModulNbr = (unsigned char) CR_AREF(insn->chanspec);
3476
b_PWM = (unsigned char) CR_CHAN(insn->chanspec);
3477
pb_PWMOutputStatus = (unsigned char *) &data[0];
3478
pb_ExternGateStatus = (unsigned char *) &data[1];
3480
/**************************/
3481
/* Test the module number */
3482
/**************************/
3484
if (b_ModulNbr < 4) {
3489
if ((devpriv->s_BoardInfos.
3490
dw_MolduleConfiguration[b_ModulNbr] &
3491
0xFFFF0000UL) == APCI1710_PWM) {
3492
/**************************/
3493
/* Test the PWM selection */
3494
/**************************/
3497
/***************************/
3498
/* Test if PWM initialised */
3499
/***************************/
3501
dw_Status = inl(devpriv->s_BoardInfos.
3502
ui_Address + 12 + (20 * b_PWM) +
3505
if (dw_Status & 0x10) {
3506
/***********************/
3507
/* Test if PWM enabled */
3508
/***********************/
3510
if (dw_Status & 0x1) {
3511
*pb_PWMOutputStatus =
3512
(unsigned char) ((dw_Status >> 7)
3514
*pb_ExternGateStatus =
3515
(unsigned char) ((dw_Status >> 6)
3517
} /* if (dw_Status & 0x1) */
3519
/*******************/
3520
/* PWM not enabled */
3521
/*******************/
3523
DPRINTK("PWM not enabled \n");
3525
} /* if (dw_Status & 0x1) */
3526
} /* if (dw_Status & 0x10) */
3528
/***********************/
3529
/* PWM not initialised */
3530
/***********************/
3532
DPRINTK("PWM not initialised\n");
3534
} /* if (dw_Status & 0x10) */
3535
} /* if (b_PWM >= 0 && b_PWM <= 1) */
3537
/******************************/
3538
/* Tor PWM selection is wrong */
3539
/******************************/
3541
DPRINTK("Tor PWM selection is wrong\n");
3543
} /* if (b_PWM >= 0 && b_PWM <= 1) */
3545
/**********************************/
3546
/* The module is not a PWM module */
3547
/**********************************/
3549
DPRINTK("The module is not a PWM module\n");
3553
/***********************/
3554
/* Module number error */
3555
/***********************/
3557
DPRINTK("Module number error\n");
3561
return i_ReturnValue;
3564
int i_APCI1710_InsnBitsReadPWMInterrupt(struct comedi_device *dev,
3565
struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data)
3567
data[0] = devpriv->s_InterruptParameters.
3568
s_FIFOInterruptParameters[devpriv->
3569
s_InterruptParameters.ui_Read].b_OldModuleMask;
3570
data[1] = devpriv->s_InterruptParameters.
3571
s_FIFOInterruptParameters[devpriv->
3572
s_InterruptParameters.ui_Read].ul_OldInterruptMask;
3573
data[2] = devpriv->s_InterruptParameters.
3574
s_FIFOInterruptParameters[devpriv->
3575
s_InterruptParameters.ui_Read].ul_OldCounterLatchValue;
3577
/**************************/
3578
/* Increment the read FIFO */
3579
/***************************/
3582
s_InterruptParameters.
3583
ui_Read = (devpriv->
3584
s_InterruptParameters.ui_Read + 1) % APCI1710_SAVE_INTERRUPT;