13 #DEFINE __PRUIO_COMPILING__
28 #INCLUDE ONCE "pasm_init.bi"
30 #INCLUDE ONCE "pasm_run.bi"
32 #INCLUDE ONCE "dir.bi"
35 #DEFINE PMUX_NAME
"pruio-"
39 #DEFINE ArrayBytes(_A_) (
UBOUND(_A_) + 1) *
SIZEOF(_A_(0))
42 DECLARE FUNCTION memcpy CDECL ALIAS "memcpy"(
BYVAL AS ANY PTR,
BYVAL AS ANY PTR,
BYVAL AS ULONG )
AS ANY PTR
48 ,
BYVAL AS UInt8)
AS ZSTRING PTR
52 ,
BYVAL AS UInt8)
AS ZSTRING PTR
56 ,
BYVAL AS UInt8)
AS ZSTRING PTR
60 ,
BYVAL AS UInt8)
AS ZSTRING PTR
64 ,
BYVAL AS UInt8)
AS ZSTRING PTR
152 IF OPEN(
"/dev/uio5" FOR OUTPUT AS fnr)
THEN _
153 Errr = @
"cannot open /dev/uio5" :
EXIT CONSTRUCTOR
156 STATIC AS STRING mux, bbb
157 IF 0 =
OPEN(
"/proc/device-tree/model" FOR INPUT AS fnr)
THEN
161 IF INSTR(bbb,
"Pocket")
THEN BbType = PBB2x36
162 IF INSTR(bbb,
"Blue")
THEN BbType = BB_Blue
166 IF 0 =
OPEN(
"/sys/devices/platform/libpruio/state" FOR OUTPUT AS fnr)
THEN
167 IF Act
AND PRUIO_ACT_FREMUX
THEN
171 Errr = setPin(@
THIS, 255, 0)
172 IF Errr
THEN CLOSE #fnr : setPin = @
setPin_nogo() : fnr = 0
173 END IF : MuxFnr = fnr
176 VAR p =
"/sys/devices/" _
177 , n =
DIR(p &
"ocp.*", fbDirectory)
179 mux = p & n &
"/" & PMUX_NAME : MuxFnr = 256
181 p &=
"platform/ocp/ocp:"
182 IF LEN(
DIR(p &
"pruio-*", fbDirectory))
THEN mux = p & PMUX_NAME : MuxFnr = 257
184 IF MuxFnr
THEN setPin = @
setPin_dtbo() : MuxAcc =
SADD(mux) : Errr = 0 _
188 IF Act
AND PRUIO_ACT_PRU1
THEN
189 PruIntNo = ARM_PRU1_INTERRUPT
190 PruIRam = PRUSS0_PRU1_IRAM
191 PruDRam = PRUSS0_PRU1_DRAM
194 PruIntNo = ARM_PRU1_INTERRUPT
195 PruIRam = PRUSS0_PRU0_IRAM
196 PruDRam = PRUSS0_PRU0_DRAM
200 Errr = @
"failed opening PRUIO_EVNT" :
EXIT CONSTRUCTOR
209 DRam[1] = PRUIO_DAT_ALL
217 Adc =
NEW AdcUdt(@
THIS)
218 Gpio =
NEW GpioUdt(@
THIS)
221 ParOffs += 1 : DRam[ParOffs] = &h44E10800
223 PwmSS =
NEW PwmssUdt(@
THIS)
224 TimSS =
NEW TimerUdt(@
THIS)
226 ASSERT(ParOffs < DRam[1]
SHR 4)
227 VAR l = ArrayBytes(Pru_Init)
229 Errr = @
"failed loading Pru_Init instructions" :
EXIT CONSTRUCTOR
233 Pwm =
NEW PwmMod(@
THIS)
234 Cap =
NEW CapMod(@
THIS)
235 Qep =
NEW QepMod(@
THIS)
240 IF DRam[0] <> PRUIO_MSG_INIT_OK
THEN _
241 Errr = @
"failed executing Pru_Init instructions" :
EXIT CONSTRUCTOR
243 DSize = DRam[ParOffs] - DRam[1]
244 DInit =
ALLOCATE(DSize * 2)
245 IF 0 = DInit
THEN Errr = @
"out of memory" :
EXIT CONSTRUCTOR
247 MOffs = DInit - DRam[1]
248 DConf = DInit + DSize
249 VAR p0 =
CAST(
ANY PTR, DRam) + DRam[1]
253 Init = MOffs + DRam[offs]
254 Conf =
CAST(
ANY PTR, Init) + DSize
255 BallInit =
CAST(
ANY PTR, Init) +
OFFSETOF(BallSet, Value(0))
256 BallConf = BallInit + DSize
257 FOR b
AS INTEGER = 0
TO PRUIO_AZ_BALL : BallConf[b]
OR= &b11000 :
NEXT
259 IF Adc->initialize(Av, OpD, SaD)
THEN EXIT CONSTRUCTOR
260 IF Gpio->initialize()
THEN EXIT CONSTRUCTOR
261 IF PwmSS->initialize()
THEN EXIT CONSTRUCTOR
262 IF TimSS->initialize()
THEN EXIT CONSTRUCTOR
284 VAR mux =
"" : Errr = 0
288 IF BallInit <> BallConf
THEN
289 FOR i
AS INTEGER = 0
TO PRUIO_AZ_BALL
290 IF (BallConf[i]
AND &b11000) = &b11000
THEN CONTINUE FOR
291 IF (BallConf[i]
XOR BallInit[i])
AND &b1111111
THEN _
292 IF setPin(@
THIS, i, BallInit[i])
THEN mux &= _
294 &
BIN(BallConf[i], 7) &
" -> " &
BIN(BallInit[i], 7) _
295 &
" failed (" & *Errr &
")"
298 IF MuxFnr < 256
THEN CLOSE #MuxFnr
303 DRam[1] = PRUIO_DAT_ALL
304 memcpy(
CAST(
ANY PTR, DRam) + DRam[1], DInit, DSize)
307 VAR l = ArrayBytes(Pru_Run)
309 Errr = @
"failed loading Pru_Exit instructions"
314 IF DRam[0] <> PRUIO_MSG_CONF_OK
THEN _
315 Errr = @
"failed executing Pru_Exit instructions"
318 Errr = @
"destructor warning: subsystems are NOT restored"
323 Errr = @
"destructor warning: constructor failed"
326 IF Errr
THEN mux &= !
"\n" & *Errr
328 VAR fnr =
FREEFILE :
OPEN ERR AS fnr :
PRINT #fnr,
MID(mux, 2) :
CLOSE #fnr
458 IF Adc->configure(Samp, Mask, Tmr, Mds)
THEN RETURN Errr
460 DRam[1] = PRUIO_DAT_ALL
461 memcpy(
CAST(
ANY PTR, DRam) + DRam[1], DConf, DSize)
463 VAR l = ArrayBytes(Pru_Run)
465 Errr = @
"failed loading Pru_Run instructions" :
RETURN Errr
469 SELECT CASE AS CONST Samp
470 CASE 0 : l = DRam[0] <> PRUIO_MSG_CONF_OK
471 CASE 1 : l = DRam[0] <> PRUIO_MSG_IO_OK
472 CASE ELSE : l = DRam[0] <> PRUIO_MSG_MM_WAIT
474 IF l
THEN Errr = @
"failed executing Pru_Run instructions" :
RETURN Errr
475 IF Samp < 2
THEN RETURN 0
506 BYVAL Ball
AS UInt8, _
507 BYVAL Mo
AS UInt8 = 1)
AS ZSTRING PTR
508 STATIC AS STRING*50 t
514 IF Ball > PRUIO_AZ_BALL
THEN Errr = @
"unknown pin number" :
RETURN Errr
515 t =
"b " &
RIGHT(
"00" & Ball, 3)
518 VAR r =
IIF(Mo, BallConf[Ball], BallInit[Ball]) _
521 VAR i = BallGpio(Ball)
SHR 5 _
522 , n = BallGpio(Ball)
AND 31 _
524 t &=
", GPIO " & i &
"/" &
RIGHT(
"0" & n, 2)
528 WITH *
IIF(Mo,
Gpio->Conf(i),
Gpio->Init(i))
529 t &=
": output-" & *
IIF((.DATAOUT
OR .SETDATAOUT)
AND m, @
"1", @
"0")
534 &
": input " & *
IIF(
BIT(r, 5), @
"enabled", @
"disabled")
540 IF BIT(r, 4)
THEN t &=
", pullup" ELSE t &=
", pulldown"
541 END IF :
RETURN SADD(t)
554 CASE P8_03 :
RETURN @
"P8_03"
555 CASE P8_04 :
RETURN @
"P8_04"
556 CASE P8_05 :
RETURN @
"P8_05"
557 CASE P8_06 :
RETURN @
"P8_06"
558 CASE P8_07 :
RETURN @
"P8_07"
559 CASE P8_08 :
RETURN @
"P8_08"
560 CASE P8_09 :
RETURN @
"P8_09"
561 CASE P8_10 :
RETURN @
"P8_10"
562 CASE P8_11 :
RETURN @
"P8_11"
563 CASE P8_12 :
RETURN @
"P8_12"
564 CASE P8_13 :
RETURN @
"P8_13"
565 CASE P8_14 :
RETURN @
"P8_14"
566 CASE P8_15 :
RETURN @
"P8_15"
567 CASE P8_16 :
RETURN @
"P8_16"
568 CASE P8_17 :
RETURN @
"P8_17"
569 CASE P8_18 :
RETURN @
"P8_18"
570 CASE P8_19 :
RETURN @
"P8_19"
571 CASE P8_20 :
RETURN @
"P8_20"
572 CASE P8_21 :
RETURN @
"P8_21"
573 CASE P8_22 :
RETURN @
"P8_22"
574 CASE P8_23 :
RETURN @
"P8_23"
575 CASE P8_24 :
RETURN @
"P8_24"
576 CASE P8_25 :
RETURN @
"P8_25"
577 CASE P8_26 :
RETURN @
"P8_26"
578 CASE P8_27 :
RETURN @
"P8_27"
579 CASE P8_28 :
RETURN @
"P8_28"
580 CASE P8_29 :
RETURN @
"P8_29"
581 CASE P8_30 :
RETURN @
"P8_30"
582 CASE P8_31 :
RETURN @
"P8_31"
583 CASE P8_32 :
RETURN @
"P8_32"
584 CASE P8_33 :
RETURN @
"P8_33"
585 CASE P8_34 :
RETURN @
"P8_34"
586 CASE P8_35 :
RETURN @
"P8_35"
587 CASE P8_36 :
RETURN @
"P8_36"
588 CASE P8_37 :
RETURN @
"P8_37"
589 CASE P8_38 :
RETURN @
"P8_38"
590 CASE P8_39 :
RETURN @
"P8_39"
591 CASE P8_40 :
RETURN @
"P8_40"
592 CASE P8_41 :
RETURN @
"P8_41"
593 CASE P8_42 :
RETURN @
"P8_42"
594 CASE P8_43 :
RETURN @
"P8_43"
595 CASE P8_44 :
RETURN @
"P8_44"
596 CASE P8_45 :
RETURN @
"P8_45"
597 CASE P8_46 :
RETURN @
"P8_46"
598 CASE P9_11 :
RETURN @
"P9_11"
599 CASE P9_12 :
RETURN @
"P9_12"
600 CASE P9_13 :
RETURN @
"P9_13"
601 CASE P9_14 :
RETURN @
"P9_14"
602 CASE P9_15 :
RETURN @
"P9_15"
603 CASE P9_16 :
RETURN @
"P9_16"
604 CASE P9_17 :
RETURN @
"P9_17"
605 CASE P9_18 :
RETURN @
"P9_18"
606 CASE P9_19 :
RETURN @
"P9_19"
607 CASE P9_20 :
RETURN @
"P9_20"
608 CASE P9_21 :
RETURN @
"P9_21"
609 CASE P9_22 :
RETURN @
"P9_22"
610 CASE P9_23 :
RETURN @
"P9_23"
611 CASE P9_24 :
RETURN @
"P9_24"
612 CASE P9_25 :
RETURN @
"P9_25"
613 CASE P9_26 :
RETURN @
"P9_26"
614 CASE P9_27 :
RETURN @
"P9_27"
615 CASE P9_28 :
RETURN @
"P9_28"
616 CASE P9_29 :
RETURN @
"P9_29"
617 CASE P9_30 :
RETURN @
"P9_30"
618 CASE P9_31 :
RETURN @
"P9_31"
619 CASE P9_41 :
RETURN @
"P9_41"
620 CASE 106 :
RETURN @
"P9_41"
621 CASE P9_42 :
RETURN @
"P9_42"
622 CASE 104 :
RETURN @
"P9_42"
623 CASE JT_04 :
RETURN @
"JT_04"
624 CASE JT_05 :
RETURN @
"JT_05"
636 CASE E1_3 :
RETURN @
"E1_3"
637 CASE E1_4 :
RETURN @
"E1_4"
638 CASE E2_3 :
RETURN @
"E2_3"
639 CASE E2_4 :
RETURN @
"E2_4"
640 CASE E3_3 :
RETURN @
"E3_3"
641 CASE E3_4 :
RETURN @
"E3_4"
642 CASE E4_3 :
RETURN @
"E4_3"
643 CASE E4_4 :
RETURN @
"E4_4"
644 CASE UT0_3 :
RETURN @
"UT0_3"
645 CASE UT0_4 :
RETURN @
"UT0_4"
646 CASE UT1_3 :
RETURN @
"UT1_3"
647 CASE UT1_4 :
RETURN @
"UT1_4"
648 CASE UT5_3 :
RETURN @
"UT5_3"
649 CASE UT5_4 :
RETURN @
"UT5_4"
650 CASE DSM2_3 :
RETURN @
"DSM2_3"
651 CASE GP0_3 :
RETURN @
"GP0_3"
652 CASE GP0_4 :
RETURN @
"GP0_4"
653 CASE GP0_5 :
RETURN @
"GP0_5"
654 CASE GP0_6 :
RETURN @
"GP0_6"
655 CASE GP1_3 :
RETURN @
"GP1_3"
656 CASE GP1_4 :
RETURN @
"GP1_4"
657 CASE GP1_5 :
RETURN @
"GP1_5"
658 CASE GP1_6 :
RETURN @
"GP1_6"
659 CASE GPS_3 :
RETURN @
"GPS_3"
660 CASE GPS_4 :
RETURN @
"GPS_4"
661 CASE SPI1_3 :
RETURN @
"SPI1_3"
662 CASE SPI1_4 :
RETURN @
"SPI1_4"
663 CASE SPI1_5 :
RETURN @
"SPI1_5"
664 CASE SPI1_6 :
RETURN @
"SPI1_6"
665 CASE SPI2_6 :
RETURN @
"SPI2_6"
676 #MACRO POCKET_NAMES()
677 CASE P1_02 :
RETURN @
"P1_02"
678 CASE P1_04 :
RETURN @
"P1_04"
679 CASE P1_06 :
RETURN @
"P1_06"
680 CASE P1_08 :
RETURN @
"P1_08"
681 CASE P1_10 :
RETURN @
"P1_10"
682 CASE P1_12 :
RETURN @
"P1_12"
683 CASE P1_20 :
RETURN @
"P1_20"
684 CASE P1_26 :
RETURN @
"P1_26"
685 CASE P1_28 :
RETURN @
"P1_28"
686 CASE P1_29 :
RETURN @
"P1_29"
687 CASE P1_30 :
RETURN @
"P1_30"
688 CASE P1_31 :
RETURN @
"P1_31"
689 CASE P1_32 :
RETURN @
"P1_32"
690 CASE P1_33 :
RETURN @
"P1_33"
691 CASE P1_34 :
RETURN @
"P1_34"
692 CASE P1_35 :
RETURN @
"P1_35"
693 CASE P1_36 :
RETURN @
"P1_36"
694 CASE P2_01 :
RETURN @
"P2_01"
695 CASE P2_02 :
RETURN @
"P2_02"
696 CASE P2_03 :
RETURN @
"P2_03"
697 CASE P2_04 :
RETURN @
"P2_04"
698 CASE P2_05 :
RETURN @
"P2_05"
699 CASE P2_06 :
RETURN @
"P2_06"
700 CASE P2_07 :
RETURN @
"P2_07"
701 CASE P2_08 :
RETURN @
"P2_08"
702 CASE P2_09 :
RETURN @
"P2_09"
703 CASE P2_10 :
RETURN @
"P2_10"
704 CASE P2_11 :
RETURN @
"P2_11"
705 CASE P2_17 :
RETURN @
"P2_17"
706 CASE P2_18 :
RETURN @
"P2_18"
707 CASE P2_19 :
RETURN @
"P2_19"
708 CASE P2_20 :
RETURN @
"P2_20"
709 CASE P2_22 :
RETURN @
"P2_22"
710 CASE P2_24 :
RETURN @
"P2_24"
711 CASE P2_25 :
RETURN @
"P2_25"
712 CASE P2_27 :
RETURN @
"P2_27"
713 CASE P2_28 :
RETURN @
"P2_28"
714 CASE P2_29 :
RETURN @
"P2_29"
715 CASE P2_30 :
RETURN @
"P2_30"
716 CASE P2_31 :
RETURN @
"P2_31"
717 CASE P2_32 :
RETURN @
"P2_32"
718 CASE P2_33 :
RETURN @
"P2_33"
719 CASE P2_34 :
RETURN @
"P2_34"
720 CASE P2_35 :
RETURN @
"P2_35"
740 SELECT CASE AS CONST BbType
742 SELECT CASE AS CONST Ball
746 SELECT CASE AS CONST Ball
750 SELECT CASE AS CONST Ball
754 SELECT CASE AS CONST Ball
755 CASE SD_01 :
RETURN @
"SD_01"
756 CASE SD_02 :
RETURN @
"SD_02"
757 CASE SD_03 :
RETURN @
"SD_03"
758 CASE SD_05 :
RETURN @
"SD_05"
759 CASE SD_07 :
RETURN @
"SD_07"
760 CASE SD_08 :
RETURN @
"SD_08"
761 CASE SD_10 :
RETURN @
"SD_10"
762 END SELECT :
RETURN 0
786 IF DRam[0] <> PRUIO_MSG_MM_WAIT
THEN _
787 Errr = @
"ring buffer mode not ready" :
RETURN Errr
789 DRam[1] =
Adc->Samples
SHL 1
832 BYVAL Trg1
AS UInt32 = 0 _
833 ,
BYVAL Trg2
AS UInt32 = 0 _
834 ,
BYVAL Trg3
AS UInt32 = 0 _
835 ,
BYVAL Trg4
AS UInt32 = 0)
AS ZSTRING PTR
837 IF DRam[0] <> PRUIO_MSG_MM_WAIT
THEN _
838 Errr = @
"measurement mode not ready" :
RETURN Errr
840 STATIC AS UInt32 tmin = (1
SHL 22), t_pin
844 #DEFINE PRUIO_PRE_TRIG(_T_) Trg##_T_ >= tmin
ANDALSO (Trg##_T_
AND (&b10000))
THEN : _
845 IF BIT(Trg##_T_, 5)
ORELSE BIT(
Adc->Conf->STEPENABLE, (Trg##_T_
AND &b1111) + 1)
THEN : _
846 VAR n = (Trg##_T_
SHR 22) *
Adc->ChAz : _
847 IF n <
Adc->Samples
THEN : DRam[3] = n
SHL 1 : _
848 ELSE : Errr = @
"Trg" #_T_
": too much pre-trigger samples" :
RETURN Errr : _
850 ELSE : Errr = @
"Trg" #_T_
": pre-trigger step must be active" :
RETURN Errr : _
853 #DEFINE PRUIO_GPIO_TRIG(_T_)
BIT(Trg##_T_, 21)
THEN : _
854 t_pin = (Trg##_T_
SHR 8)
AND &b1111111 : _
855 IF t_pin > PRUIO_AZ_BALL
THEN _
856 Errr = @
"Trg" #_T_
": unknown trigger pin number" :
RETURN Errr : _
858 IF &b111 <> (BallConf[t_pin]
AND &b111)
THEN _
859 Errr = @
"Trg" #_T_
": trigger pin must be in mode 7 (GPIO)" :
RETURN Errr : _
860 ELSE Trg##_T_
AND= &b11111111111100000000000011111111uL : _
861 Trg##_T_
OR= BallGpio(t_pin)
SHL 8 : _
868 IF PRUIO_GPIO_TRIG(1)
872 IF PRUIO_GPIO_TRIG(2)
876 IF PRUIO_GPIO_TRIG(3)
880 IF PRUIO_GPIO_TRIG(4)