31 CONSTRUCTOR AdcUdt(
BYVAL T
AS Pruio_
PTR)
36 i += 1 : .DRam[i] = &h44E0D000uL
37 i += 1 : .DRam[i] =
IIF(.DevAct
AND PRUIO_ACT_ADC, &h44E004BCuL, 0)
62 VAR p = .MOffs + .DRam[InitParA]
70 .DeAd = 0 : .ClVa = &h30000 : _
71 Init->DeAd = 0 : Init->ClAd = 0 :
RETURN 0
76 VAR a =
ABS((Av > 1) + (Av > 2) + (Av > 4) + (Av > 8))
SHL 2 _
78 FOR i
AS LONG = 1
TO 8
80 .Confg = a + ((i - 1)
SHL 19)
81 .Delay = d + SaD
SHL 24
110 IF 2 <> Conf->ClVa
THEN
111 IF Samp < 2
ANDALSO _
112 Mask = 0
THEN .DRam[2] = Samp _
113 ELSE .DRam[2] = 0 : .Errr = E5
116 .DRam[5] = 0 :
RETURN .Errr
120 VAR c =
UBOUND(Conf->St_p) _
123 FOR i
AS LONG = c - 1
TO 0 STEP -1
124 IF 0 =
BIT(Mask, i)
THEN CONTINUE FOR
128 VAR opd = .Delay
AND &h3FFFF _
129 , smd = .Delay
SHR 24 _
130 , avr = (.Confg
SHR 2)
AND &b111
131 d += opd + 1 + (14 + smd) * (1
SHL avr)
138 Value =
CAST(
ANY PTR, .DRam) + PRUIO_DAT_ADC + 4
140 IF r < 1
THEN .Errr = @
"no step active" :
RETURN .Errr
141 Samples = Samp * ChAz
142 IF (Samples
SHL 1) > .ESize
THEN _
143 .Errr = @
"out of memory" :
RETURN .Errr
144 d = (d * (Conf->ADC_CLKDIV + 1) * 1000) \ 24
145 IF Tmr <= d
ORELSE Tmr < 5000
THEN _
146 .Errr = @
"sample rate too big" :
RETURN .Errr
151 IF BIT(Mask, 31)
THEN _
152 .IDLECONFIG = .St_p(r).Confg
AND &b1111111111111111111100000
154 Mask
AND= (1
SHL c) - 1
157 LslMode =
IIF(Mds < 4, Mds,
CAST(UInt16, 4))
225 ,
BYVAL ChN
AS UInt8 _
231 IF 2 <> Conf->ClVa
THEN .Errr = E5 :
RETURN .Errr
232 IF Stp >
UBOUND(Conf->St_p)
THEN .Errr = E0 :
RETURN .Errr
233 IF ChN > 7
THEN .Errr = E1 :
RETURN .Errr
237 VAR a =
ABS((Av > 1) + (Av > 2) + (Av > 4) + (Av > 8))
238 .Confg = (a
SHL 2) + (ChN
SHL 19)
239 .Delay = (OpD
AND &h3FFFF) + (SaD
SHL 24)
279 BYVAL Ball
AS UInt8 _
280 ,
BYVAL GpioV
AS UInt8 = 0 _
281 ,
BYVAL Skip
AS UInt16 = 0)
AS UInt32
284 IF 2 <> Conf->ClVa
THEN .Errr = E5 :
RETURN 0
285 IF Skip > 1023
THEN .Errr = E2 :
RETURN 0
286 BallCheck(
" trigger", 0)
291 IF 2 <> .Gpio->Conf(.BallGpio(Ball)
SHR 5)->ClVa
THEN _
292 .Errr = @
"GPIO subsystem not enabled" :
RETURN 0
293 IF 7 <> (.BallConf[Ball]
AND &b111)
THEN _
294 .Errr = @
"pin must be in GPIO mode (mode 7)" :
RETURN 0
297 DIM AS UInt32 r = (Skip
SHL 22) _
300 +
IIF(GpioV = 0, 1
SHL 7, 0)
369 ,
BYVAL AdcV
AS Int32 _
370 ,
BYVAL Rela
AS UInt8 = 0 _
371 ,
BYVAL Skip
AS UInt16 = 0)
AS UInt32
374 IF 2 <> Conf->ClVa
THEN .Errr = E5 :
RETURN 0
375 IF Stp > 16
THEN .Errr = E4 :
RETURN 0
376 IF Stp
ANDALSO 0 = Conf->St_p(Stp).Confg
THEN .Errr = E3 :
RETURN 0
377 IF Skip > 1023
THEN .Errr = E2 :
RETURN 0
380 VAR v =
ABS(AdcV)
SHR LslMode
381 IF v < &hF
THEN v = &hF
ELSE IF v > &hFF0
THEN v = &hFF0
383 DIM AS UInt32 r = (Skip
SHL 22) _
385 +
IIF(AdcV < 0, 1
SHL 7, 0)
386 IF 0 = Stp
THEN r += (1
SHL 5) _
388 +
IIF(Rela, 1
SHL 6, 0)
456 ,
BYVAL AdcV
AS Int32 _
457 ,
BYVAL Samp
AS UInt16 = 0 _
458 ,
BYVAL Rela
AS UInt8 = 0)
AS UInt32
461 IF 2 <> Conf->ClVa
THEN .Errr = E5 :
RETURN 0
462 IF Stp > 16
THEN .Errr = E4 :
RETURN 0
463 IF Stp
ANDALSO 0 = Conf->St_p(Stp).Confg
THEN .Errr = E3 :
RETURN 0
464 IF Stp
ANDALSO 0 = (Conf->STEPENABLE
AND (1
SHL Stp))
THEN _
465 .Errr = @
"trigger step not activated" :
RETURN 0
466 VAR t = (Samp + 1) * ChAz
467 IF t > ((16384 - PRUIO_DAT_ADC - 32)
SHR 1)
THEN _
468 .Errr = @
"too much pre-samples" :
RETURN 0
469 IF t > Samples
THEN _
470 .Errr = @
"more pre-samples than samples" :
RETURN 0
473 VAR v =
ABS(AdcV)
SHR LslMode
474 IF v < &hF
THEN v = &hF
ELSE IF v > &hFF0
THEN v = &hFF0
476 DIM AS UInt32 r = (Samp
SHL 22) _
478 +
IIF(AdcV < 0, 1
SHL 7, 0) _
480 IF 0 = Stp
THEN r += (1
SHL 5) _
482 +
IIF(Rela, 1
SHL 6, 0)