From f828c7482033b797dfb8bd9e958cf62dbdad7159 Mon Sep 17 00:00:00 2001 From: kremlin Date: Thu, 21 Apr 2016 22:54:26 -0400 Subject: [PATCH] PLEASE --- Makefile | 5 +-- demo.sh | 8 +++++ src/.pru-back.S.swp | Bin 0 -> 12288 bytes src/pru-a.S | 79 ++++++++++++++++++++++++++++++++++++++++++ src/pru-back.S | 47 +++++++++++++++++++++++++ src/pru-down.S | 81 ++++++++++++++++++++++++++++++++++++++++++++ src/pru-gpio.S | 29 ++++++++++++++++ src/pru-up.S | 81 ++++++++++++++++++++++++++++++++++++++++++++ src/pru.S | 53 +++++++++++++++++++++++++---- src/pru_loader.c | 6 ++-- 10 files changed, 379 insertions(+), 10 deletions(-) create mode 100644 demo.sh create mode 100644 src/.pru-back.S.swp create mode 100644 src/pru-a.S create mode 100644 src/pru-back.S create mode 100644 src/pru-down.S create mode 100644 src/pru-gpio.S create mode 100644 src/pru-up.S diff --git a/Makefile b/Makefile index 8087f81..02f8bd8 100644 --- a/Makefile +++ b/Makefile @@ -13,5 +13,6 @@ all: loader rom loader: $(CC) $(CFLAGS) $(LDLIBS) src/pru_loader.c -o bin/pru_loader rom: - pasm -b src/pru.S bin/pru - +# pasm -b src/pru.S bin/pru + pasm -b src/pru-up.S bin/pru-up + pasm -b src/pru-down.S bin/pru-down diff --git a/demo.sh b/demo.sh new file mode 100644 index 0000000..6afd5b9 --- /dev/null +++ b/demo.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +while (true) ; do + sleep 2 && sudo ./bin/pru_loader ./bin/pru.bin & + sleep 2 && + sudo ./bin/pru_loader ./bin/pru2.bin & +done + diff --git a/src/.pru-back.S.swp b/src/.pru-back.S.swp new file mode 100644 index 0000000000000000000000000000000000000000..9064b5665792ea39f05a80bd9bf2784d3c838013 GIT binary patch literal 12288 zcmeI2PirJa7{+UJ5Jz2=^#k~B7DdB2e-d3mM6Arz%rx|L&sJ4W$SL&9RFY(JddOujD%J2zcU8UbQ*ZsMlEX|- zT4QfWZ#K3VuICxM`~Cxcf4Ro)J;B(_Op-XY0~cQt6CWIzNtT+6<4#Tuo6|U-mxyl8 zi)k}27Ozd>>CJ|^IN6Ol0*=6A61dE^HruUh>sRT8E74^`VP7WeGT1(zJfl6 zK7u}k>>5rWcR2!%fFs}tI0BAzHwE_3_Mw8Ws;kYKZ+Kox8P9qt$_R!cH zi_YGd`(Bsskn;LLG-S;UrNhx%jMZ4}#x}1h&84=FfvAPOUY&}qI<;6$McXy|Xw_yI zu_+y2q7ySzAMMxA@&fd1K1{=-Z6YnOS(VkQ4=Lx)Z5wu4xef0|dUw^r$Vf;p>>^s| zN2ja`hV8YP*-uhar4doPWv}zz({$QA?PU#U|_aM8@8HWD2F`g2nu_o2c9Ao_Vf;yqG1DcD76{ehCNTKI_(SuMyd=RtQ@Tg(zV0{bqYk^ z_xhqLM^b2`twWa&d0!|y8xMBRn>z!pRVc==ltM+mwuSX%I3zz*i0;`UumN22RVh5u z1DI?J@;$!o3&QFvOEnT5kNXJrBvw+#s?MGefdZAd5s5$}#ufxVlA~p7>d{ch&Hzom z?fIVGg<+Sl;y@_Xuy}%yP-LJ<;Z*yU&ObaVXj1gK?1K2C+W>=(A9d~0Y_c~T`JU)n z155dAvj`hElHu6viY~2lh4y+?hYeb-y6dTq&%Gfw)3>Xz9@8vO%)Hv_c#_>RwquD? za#&KDmC4jloX)5`Oy-oE;y9VllPo9)m5kCY?kaV>$a#S zyl2V0ERxBhG^Zubv;FdRTo~HViq!%;=j(Z8`YQfz+SjqSaY|}Y;&pp^8!z*}d$Tad PM@ib4PT#@*5n_J>*06JT literal 0 HcmV?d00001 diff --git a/src/pru-a.S b/src/pru-a.S new file mode 100644 index 0000000..95d6fff --- /dev/null +++ b/src/pru-a.S @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2016, Ian Sutton + * + * Permission to use, copy, modify, and/or distribute this software for + * any purpose with or without fee is hereby granted, provided that the + * above copyright notice and this permission notice appear in all + * copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +.origin 0 +.entrypoint START /* used by debugger only */ + +#define PRU0_R31_VEC_VALID (1<<5) +#define SIGNUM 3 /* corresponds to PRU_EVTOUT_0 */ + +#define DELAY_SECONDS 5 +#define CLOCK 200000000 +#define CLOCKS_PER_LOOP 2 +#define DELAYCOUNT DELAY_SECONDS * CLOCK / CLOCKS_PER_LOOP + + +#define R_PINKY 0x0 +#define R_RING 0x1 +#define R_MID 0x10 +#define R_FORE 0x11 +#define R_THUMB 0x100 +#define L_THUMB 0x101 +#define L_FORE 0x110 +#define L_MID 0x111 +#define L_RING 0x1000 +#define L_PINKY 0x1001 + +#define CYCLE 4000000 +#define WIDTH_UP 120000 +#define WIDTH_DOWN 480000 + +// MOV r1, DELAYCOUNT +// ADD r1, r1, r1 +// ADD r1, r1, r1 +// ADD r1, r1, r1 +// ADD r1, r1, r1 +//DELAY: + //SUB r1, r1, 1 + //NOT r30, r30, r30 + //QBNE DELAY, r1, 0 + +START: + + MOV r1, CYCLE + MOV r2, WIDTH_UP + MOV r3, WIDTH_DOWN + MOV r4, 0xffffffff + MOV r30, 0x000002ff + MOV r5, 0x00000000 +KLOOP: + QBGE DOWN, r5, r2 + QBGE KRST, r5, r1 + ADD r5, r5, 4 + JMP KLOOP +DOWN: + MOV r30, 0x00000000 + JMP KLOOP +KRST: + MOV r5, 0x00000000 + MOV r30, 0x000002ff + JMP KLOOP +KHALT: + MOV R31.b0, PRU0_R31_VEC_VALID | SIGNUM + HALT + diff --git a/src/pru-back.S b/src/pru-back.S new file mode 100644 index 0000000..bc65276 --- /dev/null +++ b/src/pru-back.S @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2016, Ian Sutton + * + * Permission to use, copy, modify, and/or distribute this software for + * any purpose with or without fee is hereby granted, provided that the + * above copyright notice and this permission notice appear in all + * copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +.origin 0 +.entrypoint START /* used by debugger only */ + +#define PERIOD 200000 +#define DUTY 100000 + +START: + SET r30, r30, 14 + MOV r1, PERIOD + MOV r2, DUTY + SUB r3, r1, r2 + SUB r2, r2, 4 + +ON: + SUB r2, r2, 1 + QBNE ON, r2, 0 + CLR r30, r30, 14 + +OFF: + SUB r3, r3, 1 + QBNE OFF, r3, 0 + QBA START + + +/*STOP: + MOV R31.b0, PRU0_R31_VEC_VALID | SIGNUM + HALT*/ + + diff --git a/src/pru-down.S b/src/pru-down.S new file mode 100644 index 0000000..136e169 --- /dev/null +++ b/src/pru-down.S @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2016, Ian Sutton + * + * Permission to use, copy, modify, and/or distribute this software for + * any purpose with or without fee is hereby granted, provided that the + * above copyright notice and this permission notice appear in all + * copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +.origin 0 +.entrypoint START /* used by debugger only */ + +#define PRU0_R31_VEC_VALID (1<<5) +#define SIGNUM 3 /* corresponds to PRU_EVTOUT_0 */ + +#define DELAY_SECONDS 5 +#define CLOCK 200000000 +#define CLOCKS_PER_LOOP 2 +#define DELAYCOUNT DELAY_SECONDS * CLOCK / CLOCKS_PER_LOOP + + +#define R_PINKY 0x0 +#define R_RING 0x1 +#define R_MID 0x10 +#define R_FORE 0x11 +#define R_THUMB 0x100 +#define L_THUMB 0x101 +#define L_FORE 0x110 +#define L_MID 0x111 +#define L_RING 0x1000 +#define L_PINKY 0x1001 + +#define CYCLE 4000000 +#define WIDTH_UP 120000 +#define WIDTH_DOWN 480000 + +// MOV r1, DELAYCOUNT +// ADD r1, r1, r1 +// ADD r1, r1, r1 +// ADD r1, r1, r1 +// ADD r1, r1, r1 +//DELAY: + //SUB r1, r1, 1 + //NOT r30, r30, r30 + //QBNE DELAY, r1, 0 + +START: + + MOV r1, CYCLE + MOV r2, WIDTH_UP + MOV r3, WIDTH_DOWN + MOV r4, 0xffffffff + MOV r30, 0x000003ff + MOV r5, 0x00000000 +KLOOP: + QBLE DOWN, r5, r3 + QBLE KRST, r5, r1 + ADD r5, r5, 4 + JMP KLOOP +DOWN: + MOV r30, 0x00000000 + MOV r3, 0xffffffff + JMP KLOOP +KRST: + MOV r5, 0x00000000 + MOV r30, 0x000003ff + MOV r3, WIDTH_DOWN + JMP KLOOP +KHALT: + MOV R31.b0, PRU0_R31_VEC_VALID | SIGNUM + HALT + diff --git a/src/pru-gpio.S b/src/pru-gpio.S new file mode 100644 index 0000000..7077e55 --- /dev/null +++ b/src/pru-gpio.S @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2016, Ian Sutton + * + * Permission to use, copy, modify, and/or distribute this software for + * any purpose with or without fee is hereby granted, provided that the + * above copyright notice and this permission notice appear in all + * copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#define PRU0_R31_VEC_VALID (1<<5) + +.origin 0 +.entrypoint TOP + +TOP: + SET r30, r30, 15 + + MOV R31.b0, PRU0_R31_VEC_VALID | 3 + HALT + diff --git a/src/pru-up.S b/src/pru-up.S new file mode 100644 index 0000000..25cd3c3 --- /dev/null +++ b/src/pru-up.S @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2016, Ian Sutton + * + * Permission to use, copy, modify, and/or distribute this software for + * any purpose with or without fee is hereby granted, provided that the + * above copyright notice and this permission notice appear in all + * copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +.origin 0 +.entrypoint START /* used by debugger only */ + +#define PRU0_R31_VEC_VALID (1<<5) +#define SIGNUM 3 /* corresponds to PRU_EVTOUT_0 */ + +#define DELAY_SECONDS 5 +#define CLOCK 200000000 +#define CLOCKS_PER_LOOP 2 +#define DELAYCOUNT DELAY_SECONDS * CLOCK / CLOCKS_PER_LOOP + + +#define R_PINKY 0x0 +#define R_RING 0x1 +#define R_MID 0x10 +#define R_FORE 0x11 +#define R_THUMB 0x100 +#define L_THUMB 0x101 +#define L_FORE 0x110 +#define L_MID 0x111 +#define L_RING 0x1000 +#define L_PINKY 0x1001 + +#define CYCLE 4000000 +#define WIDTH_UP 120000 +#define WIDTH_DOWN 480000 + +// MOV r1, DELAYCOUNT +// ADD r1, r1, r1 +// ADD r1, r1, r1 +// ADD r1, r1, r1 +// ADD r1, r1, r1 +//DELAY: + //SUB r1, r1, 1 + //NOT r30, r30, r30 + //QBNE DELAY, r1, 0 + +START: + + MOV r1, CYCLE + MOV r2, WIDTH_UP + MOV r3, WIDTH_DOWN + MOV r4, 0xffffffff + MOV r30, 0x000003ff + MOV r5, 0x00000000 +KLOOP: + QBLE DOWN, r5, r2 + QBLE KRST, r5, r1 + ADD r5, r5, 4 + JMP KLOOP +DOWN: + MOV r30, 0x00000000 + MOV r2, 0xffffffff + JMP KLOOP +KRST: + MOV r5, 0x00000000 + MOV r30, 0x000003ff + MOV r2, WIDTH_UP + JMP KLOOP +KHALT: + MOV R31.b0, PRU0_R31_VEC_VALID | SIGNUM + HALT + diff --git a/src/pru.S b/src/pru.S index dcc5493..25cd3c3 100644 --- a/src/pru.S +++ b/src/pru.S @@ -27,14 +27,55 @@ #define CLOCKS_PER_LOOP 2 #define DELAYCOUNT DELAY_SECONDS * CLOCK / CLOCKS_PER_LOOP -START: - MOV r1, DELAYCOUNT -DELAY: - SUB r1, r1, 1 - QBNE DELAY, r1, 0 +#define R_PINKY 0x0 +#define R_RING 0x1 +#define R_MID 0x10 +#define R_FORE 0x11 +#define R_THUMB 0x100 +#define L_THUMB 0x101 +#define L_FORE 0x110 +#define L_MID 0x111 +#define L_RING 0x1000 +#define L_PINKY 0x1001 + +#define CYCLE 4000000 +#define WIDTH_UP 120000 +#define WIDTH_DOWN 480000 + +// MOV r1, DELAYCOUNT +// ADD r1, r1, r1 +// ADD r1, r1, r1 +// ADD r1, r1, r1 +// ADD r1, r1, r1 +//DELAY: + //SUB r1, r1, 1 + //NOT r30, r30, r30 + //QBNE DELAY, r1, 0 + +START: - /* intr */ + MOV r1, CYCLE + MOV r2, WIDTH_UP + MOV r3, WIDTH_DOWN + MOV r4, 0xffffffff + MOV r30, 0x000003ff + MOV r5, 0x00000000 +KLOOP: + QBLE DOWN, r5, r2 + QBLE KRST, r5, r1 + ADD r5, r5, 4 + JMP KLOOP +DOWN: + MOV r30, 0x00000000 + MOV r2, 0xffffffff + JMP KLOOP +KRST: + MOV r5, 0x00000000 + MOV r30, 0x000003ff + MOV r2, WIDTH_UP + JMP KLOOP +KHALT: MOV R31.b0, PRU0_R31_VEC_VALID | SIGNUM HALT diff --git a/src/pru_loader.c b/src/pru_loader.c index 6eeeed5..25fa9f9 100644 --- a/src/pru_loader.c +++ b/src/pru_loader.c @@ -24,6 +24,8 @@ #include #include +#define PRU_NUM 1 + int main(int argc, char *argv[]) { tpruss_intc_initdata init_data = PRUSS_INTC_INITDATA; @@ -47,7 +49,7 @@ int main(int argc, char *argv[]) { return ENXIO; /* exec */ - if(prussdrv_exec_program(0, argv[1])) + if(prussdrv_exec_program(PRU_NUM, argv[1])) return ENXIO; /* block until intr */ @@ -55,7 +57,7 @@ int main(int argc, char *argv[]) { /* clean up, halt & disable pru, terminate pru drv */ prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT); - prussdrv_pru_disable(0); + prussdrv_pru_disable(PRU_NUM); prussdrv_exit(); return 0; -- 2.41.0