Go to the documentation of this file.
49 #include <sys/ioctl.h>
54 #include <sys/types.h>
57 #include <sys/socket.h>
58 #include <sys/sysmacros.h>
59 #include <netinet/tcp.h>
60 #include <arpa/inet.h>
61 #include <sys/select.h>
191 #define THOUSAND 1000
192 #define MILLION 1000000
193 #define BILLION 1000000000
195 #define BANK (gpio>>5)
197 #define BIT (1<<(gpio&0x1F))
199 #ifndef EMBEDDED_IN_VM
200 #define DBG(level, format, arg...) DO_DBG(level, format, ## arg)
202 #define DBG(level, format, arg...)
205 #define DO_DBG(level, format, arg...) \
207 if ((gpioCfg.dbgLevel >= level) && \
208 (!(gpioCfg.internals & PI_CFG_NOSIGHANDLER))) \
209 fprintf(stderr, "%s %s: " format "\n" , \
210 myTimeStamp(), __FUNCTION__ , ## arg); \
213 #ifndef DISABLE_SER_CHECK_INITED
214 #define SER_CHECK_INITED CHECK_INITED
216 #define SER_CHECK_INITED
219 #define CHECK_INITED \
222 if (!libInitialised) \
225 "pigpio uninitialised, call gpioInitialise()"); \
226 return PI_NOT_INITIALISED; \
231 #define CHECK_INITED_RET_NULL_PTR \
234 if (!libInitialised) \
237 "pigpio uninitialised, call gpioInitialise()"); \
243 #define CHECK_INITED_RET_NIL \
246 if (!libInitialised) \
249 "pigpio uninitialised, call gpioInitialise()"); \
254 #define CHECK_NOT_INITED \
257 if (libInitialised) \
260 "pigpio initialised, call gpioTerminate()"); \
261 return PI_INITIALISED; \
266 #define SOFT_ERROR(x, format, arg...) \
269 DBG(DBG_ALWAYS, format, ## arg); \
274 #define TIMER_ADD(a, b, result) \
277 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
278 (result)->tv_nsec = (a)->tv_nsec + (b)->tv_nsec; \
279 if ((result)->tv_nsec >= BILLION) \
281 ++(result)->tv_sec; \
282 (result)->tv_nsec -= BILLION; \
287 #define TIMER_SUB(a, b, result) \
290 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
291 (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \
292 if ((result)->tv_nsec < 0) \
294 --(result)->tv_sec; \
295 (result)->tv_nsec += BILLION; \
300 #define PI_PERI_BUS 0x7E000000
302 #define AUX_BASE (pi_peri_phys + 0x00215000)
303 #define BSCS_BASE (pi_peri_phys + 0x00214000)
304 #define CLK_BASE (pi_peri_phys + 0x00101000)
305 #define DMA_BASE (pi_peri_phys + 0x00007000)
306 #define DMA15_BASE (pi_peri_phys + 0x00E05000)
307 #define GPIO_BASE (pi_peri_phys + 0x00200000)
308 #define PADS_BASE (pi_peri_phys + 0x00100000)
309 #define PCM_BASE (pi_peri_phys + 0x00203000)
310 #define PWM_BASE (pi_peri_phys + 0x0020C000)
311 #define SPI_BASE (pi_peri_phys + 0x00204000)
312 #define SYST_BASE (pi_peri_phys + 0x00003000)
315 #define BSCS_LEN 0x40
317 #define DMA_LEN 0x1000
318 #define GPIO_LEN 0xB4
319 #define PADS_LEN 0x38
323 #define SYST_LEN 0x1C
325 #define DMA_ENABLE (0xFF0/4)
359 #define DMA_CONBLK_AD 1
363 #define DMA_CHANNEL_RESET (1<<31)
364 #define DMA_WAIT_ON_WRITES (1<<28)
365 #define DMA_PANIC_PRIORITY(x) ((x)<<20)
366 #define DMA_PRIORITY(x) ((x)<<16)
367 #define DMA_INTERRUPT_STATUS (1<< 2)
368 #define DMA_END_FLAG (1<< 1)
369 #define DMA_ACTIVATE (1<< 0)
372 #define DMA_NO_WIDE_BURSTS (1<<26)
373 #define DMA_PERIPHERAL_MAPPING(x) ((x)<<16)
374 #define DMA_BURST_LENGTH(x) ((x)<<12)
375 #define DMA_SRC_IGNORE (1<<11)
376 #define DMA_SRC_DREQ (1<<10)
377 #define DMA_SRC_WIDTH (1<< 9)
378 #define DMA_SRC_INC (1<< 8)
379 #define DMA_DEST_IGNORE (1<< 7)
380 #define DMA_DEST_DREQ (1<< 6)
381 #define DMA_DEST_WIDTH (1<< 5)
382 #define DMA_DEST_INC (1<< 4)
383 #define DMA_WAIT_RESP (1<< 3)
385 #define DMA_DEBUG_READ_ERR (1<<2)
386 #define DMA_DEBUG_FIFO_ERR (1<<1)
387 #define DMA_DEBUG_RD_LST_NOT_SET_ERR (1<<0)
389 #define DMA_LITE_FIRST 7
390 #define DMA_LITE_MAX 0xfffc
401 #define PWM_CTL_MSEN2 (1<<15)
402 #define PWM_CTL_PWEN2 (1<<8)
403 #define PWM_CTL_MSEN1 (1<<7)
404 #define PWM_CTL_CLRF1 (1<<6)
405 #define PWM_CTL_USEF1 (1<<5)
406 #define PWM_CTL_MODE1 (1<<1)
407 #define PWM_CTL_PWEN1 (1<<0)
409 #define PWM_DMAC_ENAB (1 <<31)
410 #define PWM_DMAC_PANIC(x) ((x)<< 8)
411 #define PWM_DMAC_DREQ(x) (x)
423 #define PCM_CS_STBY (1 <<25)
424 #define PCM_CS_SYNC (1 <<24)
425 #define PCM_CS_RXSEX (1 <<23)
426 #define PCM_CS_RXERR (1 <<16)
427 #define PCM_CS_TXERR (1 <<15)
428 #define PCM_CS_DMAEN (1 <<9)
429 #define PCM_CS_RXTHR(x) ((x)<<7)
430 #define PCM_CS_TXTHR(x) ((x)<<5)
431 #define PCM_CS_RXCLR (1 <<4)
432 #define PCM_CS_TXCLR (1 <<3)
433 #define PCM_CS_TXON (1 <<2)
434 #define PCM_CS_RXON (1 <<1)
435 #define PCM_CS_EN (1 <<0)
437 #define PCM_MODE_CLK_DIS (1 <<28)
438 #define PCM_MODE_PDMN (1 <<27)
439 #define PCM_MODE_PDME (1 <<26)
440 #define PCM_MODE_FRXP (1 <<25)
441 #define PCM_MODE_FTXP (1 <<24)
442 #define PCM_MODE_CLKM (1 <<23)
443 #define PCM_MODE_CLKI (1 <<22)
444 #define PCM_MODE_FSM (1 <<21)
445 #define PCM_MODE_FSI (1 <<20)
446 #define PCM_MODE_FLEN(x) ((x)<<10)
447 #define PCM_MODE_FSLEN(x) ((x)<< 0)
449 #define PCM_RXC_CH1WEX (1 <<31)
450 #define PCM_RXC_CH1EN (1 <<30)
451 #define PCM_RXC_CH1POS(x) ((x)<<20)
452 #define PCM_RXC_CH1WID(x) ((x)<<16)
453 #define PCM_RXC_CH2WEX (1 <<15)
454 #define PCM_RXC_CH2EN (1 <<14)
455 #define PCM_RXC_CH2POS(x) ((x)<< 4)
456 #define PCM_RXC_CH2WID(x) ((x)<< 0)
458 #define PCM_TXC_CH1WEX (1 <<31)
459 #define PCM_TXC_CH1EN (1 <<30)
460 #define PCM_TXC_CH1POS(x) ((x)<<20)
461 #define PCM_TXC_CH1WID(x) ((x)<<16)
462 #define PCM_TXC_CH2WEX (1 <<15)
463 #define PCM_TXC_CH2EN (1 <<14)
464 #define PCM_TXC_CH2POS(x) ((x)<< 4)
465 #define PCM_TXC_CH2WID(x) ((x)<< 0)
467 #define PCM_DREQ_TX_PANIC(x) ((x)<<24)
468 #define PCM_DREQ_RX_PANIC(x) ((x)<<16)
469 #define PCM_DREQ_TX_REQ_L(x) ((x)<< 8)
470 #define PCM_DREQ_RX_REQ_L(x) ((x)<< 0)
472 #define PCM_INTEN_RXERR (1<<3)
473 #define PCM_INTEN_TXERR (1<<2)
474 #define PCM_INTEN_RXR (1<<1)
475 #define PCM_INTEN_TXW (1<<0)
477 #define PCM_INTSTC_RXERR (1<<3)
478 #define PCM_INTSTC_TXERR (1<<2)
479 #define PCM_INTSTC_RXR (1<<1)
480 #define PCM_INTSTC_TXW (1<<0)
482 #define PCM_GRAY_FLUSH (1<<2)
483 #define PCM_GRAY_CLR (1<<1)
484 #define PCM_GRAY_EN (1<<0)
486 #define BCM_PASSWD (0x5A<<24)
488 #define CLK_CTL_MASH(x)((x)<<9)
489 #define CLK_CTL_BUSY (1 <<7)
490 #define CLK_CTL_KILL (1 <<5)
491 #define CLK_CTL_ENAB (1 <<4)
492 #define CLK_CTL_SRC(x) ((x)<<0)
496 #define CLK_CTL_SRC_OSC 1
497 #define CLK_CTL_SRC_PLLD 6
499 #define CLK_OSC_FREQ 19200000
500 #define CLK_PLLD_FREQ 500000000
502 #define CLK_DIV_DIVI(x) ((x)<<12)
503 #define CLK_DIV_DIVF(x) ((x)<< 0)
505 #define CLK_GP0_CTL 28
506 #define CLK_GP0_DIV 29
507 #define CLK_GP1_CTL 30
508 #define CLK_GP1_DIV 31
509 #define CLK_GP2_CTL 32
510 #define CLK_GP2_DIV 33
512 #define CLK_PCMCTL 38
513 #define CLK_PCMDIV 39
515 #define CLK_PWMCTL 40
516 #define CLK_PWMDIV 41
531 #define SPI_CS_LEN_LONG (1<<25)
532 #define SPI_CS_DMA_LEN (1<<24)
533 #define SPI_CS_CSPOLS(x) ((x)<<21)
534 #define SPI_CS_RXF (1<<20)
535 #define SPI_CS_RXR (1<<19)
536 #define SPI_CS_TXD (1<<18)
537 #define SPI_CS_RXD (1<<17)
538 #define SPI_CS_DONE (1<<16)
539 #define SPI_CS_LEN (1<<13)
540 #define SPI_CS_REN (1<<12)
541 #define SPI_CS_ADCS (1<<11)
542 #define SPI_CS_INTR (1<<10)
543 #define SPI_CS_INTD (1<<9)
544 #define SPI_CS_DMAEN (1<<8)
545 #define SPI_CS_TA (1<<7)
546 #define SPI_CS_CSPOL(x) ((x)<<6)
547 #define SPI_CS_CLEAR(x) ((x)<<4)
548 #define SPI_CS_MODE(x) ((x)<<2)
549 #define SPI_CS_CS(x) ((x)<<0)
551 #define SPI_DC_RPANIC(x) ((x)<<24)
552 #define SPI_DC_RDREQ(x) ((x)<<16)
553 #define SPI_DC_TPANIC(x) ((x)<<8)
554 #define SPI_DC_TDREQ(x) ((x)<<0)
569 #define PI_SPI_SCLK 11
570 #define PI_SPI_MISO 9
571 #define PI_SPI_MOSI 10
575 #define PI_ASPI_CE0 18
576 #define PI_ASPI_CE1 17
577 #define PI_ASPI_CE2 16
578 #define PI_ASPI_MISO 19
579 #define PI_ASPI_MOSI 20
580 #define PI_ASPI_SCLK 21
585 #define AUX_ENABLES 1
587 #define AUX_MU_IO_REG 16
588 #define AUX_MU_IER_REG 17
589 #define AUX_MU_IIR_REG 18
590 #define AUX_MU_LCR_REG 19
591 #define AUX_MU_MCR_REG 20
592 #define AUX_MU_LSR_REG 21
593 #define AUX_MU_MSR_REG 22
594 #define AUX_MU_SCRATCH 23
595 #define AUX_MU_CNTL_REG 24
596 #define AUX_MU_STAT_REG 25
597 #define AUX_MU_BAUD_REG 26
599 #define AUX_SPI0_CNTL0_REG 32
600 #define AUX_SPI0_CNTL1_REG 33
601 #define AUX_SPI0_STAT_REG 34
602 #define AUX_SPI0_PEEK_REG 35
604 #define AUX_SPI0_IO_REG 40
605 #define AUX_SPI0_TX_HOLD 44
607 #define AUX_SPI1_CNTL0_REG 48
608 #define AUX_SPI1_CNTL1_REG 49
609 #define AUX_SPI1_STAT_REG 50
610 #define AUX_SPI1_PEEK_REG 51
612 #define AUX_SPI1_IO_REG 56
613 #define AUX_SPI1_TX_HOLD 60
615 #define AUXENB_SPI2 (1<<2)
616 #define AUXENB_SPI1 (1<<1)
617 #define AUXENB_UART (1<<0)
619 #define AUXSPI_CNTL0_SPEED(x) ((x)<<20)
620 #define AUXSPI_CNTL0_CS(x) ((x)<<17)
621 #define AUXSPI_CNTL0_POSTINP (1<<16)
622 #define AUXSPI_CNTL0_VAR_CS (1<<15)
623 #define AUXSPI_CNTL0_VAR_WIDTH (1<<14)
624 #define AUXSPI_CNTL0_DOUT_HOLD(x) ((x)<<12)
625 #define AUXSPI_CNTL0_ENABLE (1<<11)
626 #define AUXSPI_CNTL0_IN_RISING(x) ((x)<<10)
627 #define AUXSPI_CNTL0_CLR_FIFOS (1<<9)
628 #define AUXSPI_CNTL0_OUT_RISING(x) ((x)<<8)
629 #define AUXSPI_CNTL0_INVERT_CLK(x) ((x)<<7)
630 #define AUXSPI_CNTL0_MSB_FIRST(x) ((x)<<6)
631 #define AUXSPI_CNTL0_SHIFT_LEN(x) ((x)<<0)
633 #define AUXSPI_CNTL1_CS_HIGH(x) ((x)<<8)
634 #define AUXSPI_CNTL1_TX_IRQ (1<<7)
635 #define AUXSPI_CNTL1_DONE_IRQ (1<<6)
636 #define AUXSPI_CNTL1_MSB_FIRST(x)((x)<<1)
637 #define AUXSPI_CNTL1_KEEP_INPUT (1<<0)
639 #define AUXSPI_STAT_TX_FIFO(x) ((x)<<28)
640 #define AUXSPI_STAT_RX_FIFO(x) ((x)<<20)
641 #define AUXSPI_STAT_TX_FULL (1<<10)
642 #define AUXSPI_STAT_TX_EMPTY (1<<9)
643 #define AUXSPI_STAT_RX_EMPTY (1<<7)
644 #define AUXSPI_STAT_BUSY (1<<6)
645 #define AUXSPI_STAT_BITS(x) ((x)<<0)
649 #define NORMAL_DMA (DMA_NO_WIDE_BURSTS | DMA_WAIT_RESP)
651 #define TIMED_DMA(x) (DMA_DEST_DREQ | DMA_PERIPHERAL_MAPPING(x))
653 #define PCM_TIMER (((PCM_BASE + PCM_FIFO*4) & 0x00ffffff) | PI_PERI_BUS)
654 #define PWM_TIMER (((PWM_BASE + PWM_FIFO*4) & 0x00ffffff) | PI_PERI_BUS)
656 #define DBG_MIN_LEVEL 0
658 #define DBG_STARTUP 1
662 #define DBG_INTERNAL 5
663 #define DBG_SLOW_TICK 6
664 #define DBG_FAST_TICK 7
665 #define DBG_MAX_LEVEL 8
667 #define GPIO_UNDEFINED 0
671 #define GPIO_HW_CLK 4
672 #define GPIO_HW_PWM 5
676 #define STACK_SIZE (256*1024)
678 #define PAGE_SIZE 4096
682 #define CYCLES_PER_BLOCK 80
683 #define PULSE_PER_CYCLE 25
685 #define PAGES_PER_BLOCK 53
687 #define CBS_PER_IPAGE 117
688 #define LVS_PER_IPAGE 38
689 #define OFF_PER_IPAGE 38
690 #define TCK_PER_IPAGE 2
691 #define ON_PER_IPAGE 2
692 #define PAD_PER_IPAGE 7
694 #define CBS_PER_OPAGE 118
695 #define OOL_PER_OPAGE 79
710 #define WCB_CNT_PER_PAGE 2
711 #define WCB_COUNTERS (WCB_CNT_PER_PAGE * PI_WAVE_COUNT_PAGES)
712 #define WCB_CNT_CBS 13
713 #define WCB_CNT_OOL 68
714 #define WCB_COUNTER_OOL (WCB_CNT_PER_PAGE * WCB_CNT_OOL)
715 #define WCB_COUNTER_CBS (WCB_CNT_PER_PAGE * WCB_CNT_CBS)
716 #define WCB_CHAIN_CBS 60
717 #define WCB_CHAIN_OOL 60
719 #define CBS_PER_CYCLE ((PULSE_PER_CYCLE*3)+2)
721 #define NUM_CBS (CBS_PER_CYCLE * bufferCycles)
723 #define SUPERCYCLE 800
724 #define SUPERLEVEL 20000
726 #define BLOCK_SIZE (PAGES_PER_BLOCK*PAGE_SIZE)
728 #define DMAI_PAGES (PAGES_PER_BLOCK * bufferBlocks)
730 #define DMAO_PAGES (PAGES_PER_BLOCK * PI_WAVE_BLOCKS)
732 #define NUM_WAVE_OOL (DMAO_PAGES * OOL_PER_OPAGE)
733 #define NUM_WAVE_CBS (DMAO_PAGES * CBS_PER_OPAGE)
737 #define PI_I2C_CLOSED 0
738 #define PI_I2C_RESERVED 1
739 #define PI_I2C_OPENED 2
741 #define PI_SPI_CLOSED 0
742 #define PI_SPI_RESERVED 1
743 #define PI_SPI_OPENED 2
745 #define PI_SER_CLOSED 0
746 #define PI_SER_RESERVED 1
747 #define PI_SER_OPENED 2
749 #define PI_FILE_CLOSED 0
750 #define PI_FILE_RESERVED 1
751 #define PI_FILE_OPENED 2
753 #define PI_NOTIFY_CLOSED 0
754 #define PI_NOTIFY_RESERVED 1
755 #define PI_NOTIFY_CLOSING 2
756 #define PI_NOTIFY_OPENED 3
757 #define PI_NOTIFY_RUNNING 4
758 #define PI_NOTIFY_PAUSED 5
760 #define PI_WFRX_NONE 0
761 #define PI_WFRX_SERIAL 1
762 #define PI_WFRX_I2C_SDA 2
763 #define PI_WFRX_I2C_SCL 3
764 #define PI_WFRX_SPI_SCLK 4
765 #define PI_WFRX_SPI_MISO 5
766 #define PI_WFRX_SPI_MOSI 6
767 #define PI_WFRX_SPI_CS 7
769 #define PI_WF_MICROS 1
773 #define MAX_REPORT 250
774 #define MAX_SAMPLE 4000
776 #define DEFAULT_PWM_IDX 5
778 #define MAX_EMITS (PIPE_BUF / sizeof(gpioReport_t))
780 #define SRX_BUF_SIZE 8192
782 #define PI_I2C_RETRIES 0x0701
783 #define PI_I2C_TIMEOUT 0x0702
784 #define PI_I2C_SLAVE 0x0703
785 #define PI_I2C_FUNCS 0x0705
786 #define PI_I2C_RDWR 0x0707
787 #define PI_I2C_SMBUS 0x0720
789 #define PI_I2C_SMBUS_READ 1
790 #define PI_I2C_SMBUS_WRITE 0
792 #define PI_I2C_SMBUS_QUICK 0
793 #define PI_I2C_SMBUS_BYTE 1
794 #define PI_I2C_SMBUS_BYTE_DATA 2
795 #define PI_I2C_SMBUS_WORD_DATA 3
796 #define PI_I2C_SMBUS_PROC_CALL 4
797 #define PI_I2C_SMBUS_BLOCK_DATA 5
798 #define PI_I2C_SMBUS_I2C_BLOCK_BROKEN 6
799 #define PI_I2C_SMBUS_BLOCK_PROC_CALL 7
800 #define PI_I2C_SMBUS_I2C_BLOCK_DATA 8
802 #define PI_I2C_SMBUS_BLOCK_MAX 32
803 #define PI_I2C_SMBUS_I2C_BLOCK_MAX 32
805 #define PI_I2C_FUNC_SMBUS_QUICK 0x00010000
806 #define PI_I2C_FUNC_SMBUS_READ_BYTE 0x00020000
807 #define PI_I2C_FUNC_SMBUS_WRITE_BYTE 0x00040000
808 #define PI_I2C_FUNC_SMBUS_READ_BYTE_DATA 0x00080000
809 #define PI_I2C_FUNC_SMBUS_WRITE_BYTE_DATA 0x00100000
810 #define PI_I2C_FUNC_SMBUS_READ_WORD_DATA 0x00200000
811 #define PI_I2C_FUNC_SMBUS_WRITE_WORD_DATA 0x00400000
812 #define PI_I2C_FUNC_SMBUS_PROC_CALL 0x00800000
813 #define PI_I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000
814 #define PI_I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000
815 #define PI_I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000
816 #define PI_I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000
818 #define PI_MASH_MAX_FREQ 23800000
820 #define FLUSH_PAGES 1024
822 #define MB_DEV_MAJOR 100
824 #define MB_IOCTL _IOWR(MB_DEV_MAJOR, 0, char *)
826 #define MB_DEV1 "/dev/vcio"
827 #define MB_DEV2 "/dev/pigpio-mb"
829 #define BUS_TO_PHYS(x) ((x)&~0xC0000000)
832 #define MB_PROCESS_REQUEST 0
834 #define MB_ALLOCATE_MEMORY_TAG 0x3000C
835 #define MB_LOCK_MEMORY_TAG 0x3000D
836 #define MB_UNLOCK_MEMORY_TAG 0x3000E
837 #define MB_RELEASE_MEMORY_TAG 0x3000F
839 #define PI_SCRIPT_FREE 0
840 #define PI_SCRIPT_RESERVED 1
841 #define PI_SCRIPT_IN_USE 2
842 #define PI_SCRIPT_DYING 3
844 #define PI_SCRIPT_HALT 0
845 #define PI_SCRIPT_RUN 1
846 #define PI_SCRIPT_DELETE 2
848 #define PI_SCRIPT_STACK_SIZE 256
850 #define PI_SPI_FLAGS_CHANNEL(x) ((x&7)<<29)
852 #define PI_SPI_FLAGS_GET_CHANNEL(x) (((x)>>29)&7)
853 #define PI_SPI_FLAGS_GET_BITLEN(x) (((x)>>16)&63)
854 #define PI_SPI_FLAGS_GET_RX_LSB(x) (((x)>>15)&1)
855 #define PI_SPI_FLAGS_GET_TX_LSB(x) (((x)>>14)&1)
856 #define PI_SPI_FLAGS_GET_3WREN(x) (((x)>>10)&15)
857 #define PI_SPI_FLAGS_GET_3WIRE(x) (((x)>>9)&1)
858 #define PI_SPI_FLAGS_GET_AUX_SPI(x) (((x)>>8)&1)
859 #define PI_SPI_FLAGS_GET_RESVD(x) (((x)>>5)&7)
860 #define PI_SPI_FLAGS_GET_CSPOLS(x) (((x)>>2)&7)
861 #define PI_SPI_FLAGS_GET_MODE(x) ((x)&3)
863 #define PI_SPI_FLAGS_GET_CPHA(x) ((x)&1)
864 #define PI_SPI_FLAGS_GET_CPOL(x) ((x)&2)
865 #define PI_SPI_FLAGS_GET_CSPOL(x) ((x)&4)
867 #define PI_STARTING 0
871 #define PI_THREAD_NONE 0
872 #define PI_THREAD_STARTED 1
873 #define PI_THREAD_RUNNING 2
875 #define PI_MAX_PATH 512
1317 static volatile uint32_t *
auxReg = MAP_FAILED;
1319 static volatile uint32_t *
clkReg = MAP_FAILED;
1320 static volatile uint32_t *
dmaReg = MAP_FAILED;
1323 static volatile uint32_t *
pcmReg = MAP_FAILED;
1324 static volatile uint32_t *
pwmReg = MAP_FAILED;
1325 static volatile uint32_t *
spiReg = MAP_FAILED;
1328 static volatile uint32_t *
dmaIn = MAP_FAILED;
1329 static volatile uint32_t *
dmaOut = MAP_FAILED;
1388 0x00, 0x00, 0x00, 0x00, 0x84, 0x94, 0xA4, 0x00, 0x00, 0x00,
1389 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1390 0x82, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1391 0x00, 0x00, 0x84, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00,
1392 0x00, 0x00, 0x94, 0xA4, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00,
1393 0x00, 0x00, 0x00, 0x00,
1420 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1421 0x00, 0x00, 0x84, 0x94, 0x00, 0x00, 0x00, 0x00, 0x82, 0x92,
1422 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1423 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1424 0x84, 0x94, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x00,
1425 0x00, 0x00, 0x85, 0x95,
1464 { 1, 2, 4, 5, 8, 10, 16, 20, 25,
1465 32, 40, 50, 80, 100, 160, 200, 400, 800};
1468 { 25, 50, 100, 125, 200, 250, 400, 500, 625,
1469 800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000};
1482 (
int clkCtl,
int clkDiv,
int clkSrc,
int divI,
int divF,
int MASH);
1484 static void initDMAgo(
volatile uint32_t *dmaAddr, uint32_t cbAddr);
1495 int i,
c, len, valid;
1501 for (i=0; i<len; i++)
1505 if ((!isalnum(
c)) && (
c !=
'_') && (
c !=
'-'))
1518 static struct timeval last;
1519 static char buf[32];
1524 gettimeofday(&now, NULL);
1526 if (now.tv_sec != last.tv_sec)
1528 localtime_r(&now.tv_sec, &tmp);
1529 strftime(buf,
sizeof(buf),
"%F %T", &tmp);
1530 last.tv_sec = now.tv_sec;
1540 int i,
c, len, in_part, parts, last_char_dot;
1549 for (i=0; i<len; i++)
1553 if (memchr(bad,
c, 4))
1557 if (last_char_dot)
return 1;
1560 else last_char_dot = 0;
1568 if (!in_part) parts++;
1574 if (parts < 2)
return 1;
else return 0;
1581 static char str[128];
1586 if (count > 40)
c = 40;
else c = count;
1588 for (i=0; i<
c; i++) sprintf(str+(3*i),
"%02X ", buf[i]);
1599 int fd,
char rw, uint8_t cmd,
int size,
union my_smbus_data *data)
1621 shift = (gpio%10) * 3;
1648 struct timespec ts, rem;
1650 ts.tv_sec = seconds;
1651 ts.tv_nsec = micros * 1000;
1653 while (clock_nanosleep(CLOCK_REALTIME, 0, &ts, &rem))
1688 if (chmod(
name, perm) < 0)
1739 if (*esc) bytes = 2;
else bytes = 1;
1743 if (*inPos <= (inLen - bytes))
1747 return inBuf[(*inPos)++];
1752 return inBuf[*inPos-2] + (inBuf[*inPos-1]<<8);
1776 if (
gpioMask & ((uint64_t)(1)<<gpio))
return 1;
1790 PROT_READ|PROT_WRITE|PROT_EXEC,
1791 MAP_SHARED|MAP_ANONYMOUS|MAP_NORESERVE|MAP_LOCKED,
1794 if (dummy == MAP_FAILED)
1810 pthread_mutex_lock(&
wfRx[i].mutex);
1817 pthread_mutex_unlock(&
wfRx[i].mutex);
1837 uint32_t tmp1, tmp2, tmp3, tmp4, tmp5;
1850 if ((mask | p[1]) != mask)
1853 "gpioWrite_Bits_0_31_Clear: bad bits %08X (permissions %08X)",
1864 if ((mask | p[1]) != mask)
1867 "gpioWrite_Bits_32_53_Clear: bad bits %08X (permissions %08X)",
1878 memcpy(&p[4], buf, 4);
1884 if (p[3] > (bufSize/2)) p[3] = bufSize/2;
1885 res =
bbI2CZip(p[1], buf, p[3], buf+(bufSize/2), bufSize/2);
1888 memcpy(buf, buf+(bufSize/2), res);
1896 if (p[3]) memcpy(&xfer.
txBuf, buf, p[3]);
1900 memcpy(buf, &res, 4);
1901 res = 4 + xfer.
rxCnt;
1902 if (res > 4) memcpy(buf+4, &xfer.
rxBuf, res-4);
1908 memcpy(&tmp1, buf+ 0, 4);
1909 memcpy(&tmp2, buf+ 4, 4);
1910 memcpy(&tmp3, buf+ 8, 4);
1911 memcpy(&tmp4, buf+12, 4);
1912 memcpy(&tmp5, buf+16, 4);
1917 "bbSPIOpen: gpio %d, no permission to update CS", p[1]);
1924 "bbSPIOpen: gpio %d, no permission to update MISO", tmp1);
1931 "bbSPIOpen: gpio %d, no permission to update MOSI", tmp2);
1938 "bbSPIOpen: gpio %d, no permission to update SCLK", tmp3);
1942 if (!res) res =
bbSPIOpen(p[1], tmp1, tmp2, tmp3, tmp4, tmp5);
1950 if (p[3] > bufSize) p[3] = bufSize;
1963 if ((mask | p[1]) != mask)
1966 "gpioWrite_Bits_0_31_Set: bad bits %08X (permissions %08X)",
1977 if ((mask | p[1]) != mask)
1980 "gpioWrite_Bits_32_53_Set: bad bits %08X (permissions %08X)",
1992 if (p[2] > bufSize) p[2] = bufSize;
1994 if (res > p[2]) res = p[2];
2012 if (p[1] > bufSize) p[1] = bufSize;
2017 memcpy(&p[4], buf, 4);
2024 if (p[2] > bufSize) p[2] = bufSize;
2029 memcpy(&p[4], buf, 4);
2045 "gpioHardwareClock: gpio %d, no permission to update",
2056 memcpy(&p[4], buf, 4);
2062 "gpioHardwarePWM: gpio %d, no permission to update", p[1]);
2074 memcpy(&p[4], buf, 4);
2075 res =
i2cOpen(p[1], p[2], p[4]);
2079 memcpy(&p[4], buf, 4);
2090 if (p[2] > bufSize) p[2] = bufSize;
2095 memcpy(&p[4], buf, 4);
2108 memcpy(&p[4], buf, 4);
2129 memcpy(&p[4], buf, 4);
2135 if (p[3] > (bufSize/2)) p[3] = bufSize/2;
2136 res =
i2cZip(p[1], buf, p[3], buf+(bufSize/2), bufSize/2);
2139 memcpy(buf, buf+(bufSize/2), res);
2160 "gpioSetMode: gpio %d, no permission to update", p[1]);
2184 "gpioSetPWMfrequency: gpio %d, no permission to update", p[1]);
2220 "gpioSetPWMrange: gpio %d, no permission to update", p[1]);
2230 "gpioSetPullUpDown: gpio %d, no permission to update", p[1]);
2239 DBG(
DBG_USER,
"gpioPWM: gpio %d, no permission to update", p[1]);
2251 "gpioServo: gpio %d, no permission to update", p[1]);
2269 if (p[2] > bufSize) p[2] = bufSize;
2270 res =
serRead(p[1], buf, p[2]);
2277 res =
shell(buf, buf+p[1]+1);
2282 if (p[2] > bufSize) p[2] = bufSize;
2289 memcpy(&p[4], buf, 4);
2299 memcpy(&p[4], buf, 4);
2300 res =
spiOpen(p[1], p[2], p[4]);
2304 if (p[2] > bufSize) p[2] = bufSize;
2305 res =
spiRead(p[1], buf, p[2]);
2309 if (p[3] > bufSize) p[3] = bufSize;
2314 if (p[3] > bufSize) p[3] = bufSize;
2315 res =
spiXfer(p[1], buf, buf, p[3]);
2323 memcpy(&p[4], buf, 4);
2329 "gpioTrigger: gpio %d, no permission to update", p[1]);
2340 DBG(
DBG_USER,
"gpioWrite: gpio %d, no permission to update", p[1]);
2358 tmp1 = pulse[i].
gpioOn & mask;
2359 if (tmp1 != pulse[i].gpioOn)
2365 tmp1 = pulse[i].
gpioOff & mask;
2366 if (tmp1 != pulse[i].gpioOff)
2372 pulse[i].gpioOn, pulse[i].gpioOff, pulse[i].usDelay);
2385 memcpy(&tmp1, buf, 4);
2386 memcpy(&tmp2, buf+4, 4);
2387 memcpy(&tmp3, buf+8, 4);
2389 (p[1], p[2], tmp1, tmp2, tmp3, p[3]-12, buf+12);
2395 "gpioWaveAddSerial: gpio %d, no permission to update", p[1]);
2403 if (p[3] > bufSize) p[3] = bufSize;
2522 int newOff, oldOff, realRange, cycles, i;
2523 int deferOff, deferRng;
2526 "myGpioSetPwm %d from %d to %d", gpio, oldVal, newVal);
2534 newOff = (newVal * realRange)/
gpioInfo[gpio].range;
2535 oldOff = (oldVal * realRange)/
gpioInfo[gpio].range;
2549 if (newOff != oldOff)
2551 if (newOff && oldOff)
2553 if (newOff != realRange)
2558 if (newOff > oldOff)
2571 if (newOff != realRange)
2605 int newOff, oldOff, realRange, cycles, i;
2606 int deferOff, deferRng;
2609 "myGpioSetServo %d from %d to %d", gpio, oldVal, newVal);
2614 newOff = (newVal * realRange)/20000;
2615 oldOff = (oldVal * realRange)/20000;
2629 if (newOff != oldOff)
2631 if (newOff && oldOff)
2636 if (newOff > oldOff)
2687 return mknod(dev, S_IFCHR|0600, makedev(
MB_DEV_MAJOR, 0));
2717 int fd,
unsigned size,
unsigned align,
unsigned flags)
2730 p[0] = i*
sizeof(*p);
2748 p[0] = i*
sizeof(*p);
2766 p[0] = i*
sizeof(*p);
2784 p[0] = i*
sizeof(*p);
2793 void *mem = MAP_FAILED;
2795 mem = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED,
fdMem, base);
2803 return munmap(addr, size);
2819 DMAMemP->
size = size;
2859 return (uint32_t) &
dmaOBus[page]->
cb[slot];
2897 (
unsigned baud,
unsigned bits,
unsigned stops,
unsigned *bitDelay)
2899 unsigned fullBit, last, diff, t, i;
2903 fullBit = 1000000000 /
baud;
2906 for (i=0; i<=bits; i++)
2908 t = (((i+1)*fullBit)+500)/1000;
2914 t = (((bits+1)*fullBit) + ((stops*fullBit)/2) + 500)/1000;
2923 if (!
delay)
return 0;
2934 int numCB=0, numBOOL=0, numTOOL=0;
2949 for (i=0; i<numWaves; i++)
2951 if (waves[i].gpioOn) {numCB++; numBOOL++;}
2952 if (waves[i].gpioOff) {numCB++; numBOOL++;}
2960 *numBOOLs = numBOOL;
2961 *numTOOLs = numTOOL;
2966 static int wave2Cbs(
unsigned wave_mode,
int *CB,
int *BOOL,
int *TOOL)
2968 int botCB=*CB, botOOL=*BOOL, topOOL=*TOOL;
2974 unsigned i, repeatCB;
2978 unsigned delayCBs, dcb;
3004 p->
src = (uint32_t) (&
dmaOBus[0]->periphData);
3010 for (i=0; i<numWaves; i++)
3012 if (waves[i].gpioOn)
3025 if (waves[i].gpioOff)
3060 if (waves[i].usDelay)
3066 for (dcb=0; dcb<delayCBs; dcb++)
3083 p->
src = (uint32_t) (&
dmaOBus[0]->periphData);
3120 int diffTicks, lastLevel;
3123 level = level ^
w->s.invert;
3127 diffTicks = tick -
w->s.startBitTick;
3134 else lastLevel =
w->s.level;
3136 while ((
w->s.bit <=
w->s.dataBits) &&
3137 (diffTicks > (
w->s.nextBitDiff/1000)))
3141 if (lastLevel)
w->s.data |= (1<<(
w->s.bit-1));
3147 w->s.nextBitDiff +=
w->s.fullBit;
3150 if (
w->s.bit >
w->s.dataBits)
3152 memcpy(
w->s.buf +
w->s.writePos, &
w->s.data,
w->s.bytes);
3156 newWritePos = (
w->s.writePos +
w->s.bytes) % (
w->s.bufSize);
3158 if (newWritePos !=
w->s.readPos)
w->s.writePos = newWritePos;
3164 w->s.startBitTick = tick;
3165 w->s.nextBitDiff =
w->s.halfBit;
3183 w->s.startBitTick = tick;
3184 w->s.nextBitDiff =
w->s.halfBit;
3206 unsigned inPos1=0, inPos2=0, outPos=0, level =
NUM_WAVE_OOL;
3210 unsigned numIn2, numOut;
3212 uint32_t tNow, tNext1, tNext2, tDelay;
3224 if (!numIn1) tNext1 = -1;
else tNext1 = 0;
3225 if (!numIn2) tNext2 = -1;
else tNext2 = 0;
3227 while (((inPos1<numIn1) || (inPos2<numIn2)) && (outPos<numOut))
3229 if (tNext1 < tNext2)
3236 out[outPos-1].
usDelay += (tNext1 - tNow);
3244 tNext1 = tNow + in1[inPos1].
usDelay; ++inPos1;
3246 else if (tNext2 < tNext1)
3253 out[outPos-1].
usDelay += (tNext2 - tNow);
3261 tNext2 = tNow + in2[inPos2].
usDelay; ++inPos2;
3270 out[outPos-1].
usDelay += (tNext1 - tNow);
3278 tNext1 = tNow + in1[inPos1].
usDelay; ++inPos1;
3279 tNext2 = tNow + in2[inPos2].
usDelay; ++inPos2;
3282 if (tNext1 <= tNext2) { tDelay = tNext1 - tNow; tNow = tNext1; }
3283 else { tDelay = tNext2 - tNow; tNow = tNext2; }
3289 if (out[outPos].gpioOn) cbs++;
3291 if (out[outPos].gpioOff) cbs++;
3307 if (inPos1 >= numIn1) tNext1 = -1;
3308 if (inPos2 >= numIn2) tNext2 = -1;
3312 if ((outPos < numOut) && (outPos < level))
3395 return 0xFF &
data.byte;
3466 return 0xFF &
data.byte;
3548 return 0xFFFF &
data.word;
3634 return 0xFFFF &
data.word;
3676 for (i=0; i<
data.block[0]; i++) buf[i] =
data.block[i+1];
3677 return data.block[0];
3685 unsigned handle,
unsigned reg,
char *buf,
unsigned count)
3708 if ((count < 1) || (count > 32))
3711 for (i=1; i<=count; i++)
data.block[i] = buf[i-1];
3712 data.block[0] = count;
3732 unsigned handle,
unsigned reg,
char *buf,
unsigned count)
3755 if ((count < 1) || (count > 32))
3758 for (i=1; i<=count; i++)
data.block[i] = buf[i-1];
3759 data.block[0] = count;
3774 for (i=0; i<
data.block[0]; i++) buf[i] =
data.block[i+1];
3775 return data.block[0];
3783 unsigned handle,
unsigned reg,
char *buf,
unsigned count)
3790 DBG(
DBG_USER,
"handle=%d reg=%d count=%d buf=%08X",
3791 handle, reg, count, (
unsigned)buf);
3807 if ((count < 1) || (count > 32))
3815 data.block[0] = count;
3829 for (i=0; i<
data.block[0]; i++) buf[i] =
data.block[i+1];
3830 return data.block[0];
3838 unsigned handle,
unsigned reg,
char *buf,
unsigned count)
3861 if ((count < 1) || (count > 32))
3864 for (i=1; i<=count; i++)
data.block[i] = buf[i-1];
3866 data.block[0] = count;
3918 handle, count, (
unsigned)buf);
3942 int i2cOpen(
unsigned i2cBus,
unsigned i2cAddr,
unsigned i2cFlags)
3944 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
3950 i2cBus, i2cAddr, i2cFlags);
3962 pthread_mutex_lock(&mutex);
3974 pthread_mutex_unlock(&mutex);
3978 sprintf(dev,
"/dev/i2c-%d", i2cBus);
3980 if ((fd = open(dev, O_RDWR)) < 0)
3984 if (system(
"/sbin/modprobe i2c_dev") == -1) { }
3985 if (system(
"/sbin/modprobe i2c_bcm2835") == -1) { }
3989 if ((fd = open(dev, O_RDWR)) < 0)
4049 if (write(fd,
"1\n", 2) == -1) { }
4053 if (write(fd,
"0\n", 2) == -1) { }
4082 rdwr.
nmsgs = numSegs;
4086 if (retval >= 0)
return retval;
4092 char *inBuf,
unsigned inLen,
char *outBuf,
unsigned outLen)
4094 int numSegs, inPos, outPos,
status, bytes, flags, addr;
4098 DBG(
DBG_USER,
"handle=%d inBuf=%s outBuf=%08X len=%d",
4109 if (!inBuf || !inLen)
4112 if (!outBuf && outLen)
4126 while (!
status && (inPos < inLen))
4128 DBG(
DBG_INTERNAL,
"status=%d inpos=%d inlen=%d cmd=%d addr=%d flags=%x",
4129 status, inPos, inLen, inBuf[inPos], addr, flags);
4131 switch (inBuf[inPos++])
4181 if ((bytes + outPos) < outLen)
4183 segs[numSegs].
addr = addr;
4184 segs[numSegs].
flags = (flags|1);
4185 segs[numSegs].
len = bytes;
4186 segs[numSegs].
buf = (uint8_t *)(outBuf + outPos);
4207 if ((bytes + inPos) < inLen)
4209 segs[numSegs].
addr = addr;
4210 segs[numSegs].
flags = (flags&0xfffe);
4211 segs[numSegs].
len = bytes;
4212 segs[numSegs].
buf = (uint8_t *)(inBuf + inPos);
4231 if (setesc) esc = 1;
else esc = 0;
4256 if (bitlen <= 8) bits = *((( uint8_t*)buf)+
pos);
4257 else if (bitlen <= 16) bits = *(((uint16_t*)buf)+
pos);
4258 else bits = *(((uint32_t*)buf)+
pos);
4260 if (msbf) bits <<= (32-bitlen);
4267 char *buf,
int pos,
int bitlen,
int msbf, uint32_t bits)
4271 if (!msbf) bits >>= (32-bitlen);
4273 if (bitlen <= 8) *((( uint8_t*)buf)+
pos) = bits;
4274 else if (bitlen <= 16) *(((uint16_t*)buf)+
pos) = bits;
4275 else *(((uint32_t*)buf)+
pos) = bits;
4300 char bit_ir[4] = {1, 0, 0, 1};
4301 char bit_or[4] = {0, 1, 1, 0};
4302 char bit_ic[4] = {0, 0, 1, 1};
4304 int mode, bitlen, txmsbf, rxmsbf, channel;
4307 uint32_t spiDefaults;
4309 int txFull, rxEmpty;
4316 if (!bitlen) bitlen = 8;
4320 if (bitlen > 8) count /= 2;
4321 if (bitlen > 16) count /= 2;
4355 while ((txCnt < count) || (rxCnt < count))
4361 txFull = (((statusReg>>28)&15) > 2);
4376 if (txCnt != (count-1))
4404 unsigned cnt, cnt4w, cnt3w;
4405 uint32_t spiDefaults;
4406 unsigned mode, channel, cspol, cspols, flag3w, ren3w;
4411 cspol = (cspols>>channel) & 1;
4432 cnt3w = count - ren3w;
4452 while((txCnt < cnt) || (rxCnt < cnt))
4477 while((txCnt < cnt) || (rxCnt < cnt))
4506 static pthread_mutex_t main_mutex = PTHREAD_MUTEX_INITIALIZER;
4507 static pthread_mutex_t aux_mutex = PTHREAD_MUTEX_INITIALIZER;
4511 pthread_mutex_lock(&aux_mutex);
4512 spiGoA(speed, flags, txBuf, rxBuf, count);
4513 pthread_mutex_unlock(&aux_mutex);
4517 pthread_mutex_lock(&main_mutex);
4518 spiGoS(speed, flags, txBuf, rxBuf, count);
4519 pthread_mutex_unlock(&main_mutex);
4540 uint32_t resvd, cspols;
4654 int spiOpen(
unsigned spiChan,
unsigned baud,
unsigned spiFlags)
4656 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
4660 spiChan,
baud, spiFlags);
4680 if (spiFlags > (1<<22))
4691 pthread_mutex_lock(&mutex);
4703 pthread_mutex_unlock(&mutex);
4800 int serOpen(
char *tty,
unsigned serBaud,
unsigned serFlags)
4802 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
4808 DBG(
DBG_USER,
"tty=%s serBaud=%d serFlags=0x%X", tty, serBaud, serFlags);
4812 if (strncmp(
"/dev/tty", tty, 8) && strncmp(
"/dev/serial", tty, 11))
4817 case 50: speed = B50;
break;
4818 case 75: speed = B75;
break;
4819 case 110: speed = B110;
break;
4820 case 134: speed = B134;
break;
4821 case 150: speed = B150;
break;
4822 case 200: speed = B200;
break;
4823 case 300: speed = B300;
break;
4824 case 600: speed = B600;
break;
4825 case 1200: speed = B1200;
break;
4826 case 1800: speed = B1800;
break;
4827 case 2400: speed = B2400;
break;
4828 case 4800: speed = B4800;
break;
4829 case 9600: speed = B9600;
break;
4830 case 19200: speed = B19200;
break;
4831 case 38400: speed = B38400;
break;
4832 case 57600: speed = B57600;
break;
4833 case 115200: speed = B115200;
break;
4834 case 230400: speed = B230400;
break;
4845 pthread_mutex_lock(&mutex);
4857 pthread_mutex_unlock(&mutex);
4861 if ((fd = open(tty, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK)) == -1)
4867 tcgetattr(fd, &
new);
4871 cfsetispeed(&
new, speed);
4872 cfsetospeed(&
new, speed);
4874 new.c_cc [VMIN] = 0;
4875 new.c_cc [VTIME] = 0;
4877 tcflush(fd, TCIFLUSH);
4878 tcsetattr(fd, TCSANOW, &
new);
4952 return ((
int)x) & 0xFF;
4957 else if ((
r == -1) && (errno == EAGAIN))
4966 int written=0, wrote=0;
4982 while ((written != count) && (wrote >= 0))
4984 wrote = write(
serInfo[
handle].fd, buf+written, count-written);
4994 if (written != count)
5021 if (errno == EAGAIN)
5028 if (
r < count) buf[
r] = 0;
5047 if (ioctl(
serInfo[
handle].fd, FIONREAD, &result) == -1)
return 0;
5055 (
clkInf_t *clkInf,
unsigned f,
unsigned numc,
unsigned *cf)
5057 int c, valid, offby, offby2, best_offby;
5064 for (
c=0;
c<numc;
c++)
5068 if ((div > 1) && (div < 4096))
5072 frac = cf[
c] - (div *
f);
5073 frac = (frac * 4096) /
f;
5074 offby = cf[
c] - (div *
f) - ((frac *
f) / 4096);
5077 offby2 = cf[
c] - (div *
f) - (((frac+1) *
f) / 4096);
5078 if (offby2 < 0) offby2 = -offby2;
5089 offby = cf[
c] - (div *
f);
5092 offby2 = cf[
c] - ((div+1) *
f);
5093 if (offby2 < 0) offby2 = -offby2;
5102 if ((!valid) || (offby <= best_offby))
5106 clkInf->
frac = frac;
5135 fprintf(stderr,
"i=%x s=%x d=%x len=%x s=%x nxt=%x\n",
5144 static unsigned lastPage=0;
5147 uint32_t startTick, endTick;
5159 cb = (cbAddr - ((int)
dmaIBus[page])) / 32;
5165 if (endTick != startTick)
5177 if (page == lastPage)
break;
5201 cb = (cbAddr - ((int)
dmaOBus[page])) / 32;
5220 cb = (cbAddr - ((int)
dmaOBus[page])) / 32;
5235 static unsigned lastPage=0;
5241 if (!cbAddr)
return -1;
5249 cb = (cbAddr - ((int)
dmaOBus[page])) / 32;
5260 if (page == lastPage)
break;
5270 unsigned cycle=0, slot=0, tmp;
5275 if (tmp > 2) slot = ((tmp-2)/3);
5341 return (uint32_t) &
dmaIBus[page]->
cb[slot];
5432 int b, pulse, level, cycle;
5519 DBG(
DBG_ALWAYS,
"Unhandled signal %d, terminating\n", signum);
5529 DBG(
DBG_ALWAYS,
"Unhandled signal %d, terminating\n", signum);
5540 struct sigaction new;
5545 memset(&
new, 0,
sizeof(
new));
5548 sigaction(i, &
new, NULL);
5574 900000, 225000, 240000, 257142, 276923, 300000, 327272, 360000,
5575 400000, 450000, 514285, 600000, 720000, 900000, 1200000, 1800000
5583 uint32_t steadyUs, changedTick, RBitV, LBitV;
5597 for (j=0; j<numSamples; j++)
5599 bitV = sample[j].
level & bit;
5606 changedTick = sample[j].
tick;
5614 diff = sample[j].
tick - changedTick;
5616 if (diff >= steadyUs)
5625 sample[j].
level ^= bit;
5653 for (j=0; j<numSamples; j++)
5655 bitV = sample[j].
level & bit;
5656 nowTick = sample[j].
tick;
5692 sample[j].
level ^= bit;
5705 gpioSample_t *sample,
int numSamples, uint32_t changedBits, uint32_t eTick)
5707 uint32_t oldLevel, newLevel;
5709 int emit, seqno, emitted;
5710 uint32_t changes, bits, timeoutBits, eventBits;
5747 eventBits |= (1<<b);
5771 for (
d=0;
d<numSamples;
d++)
5775 if (newLevel != oldLevel)
5777 changes = (newLevel ^ oldLevel);
5781 if (changes & (1<<b))
5783 if (newLevel & (1<<b))
v = 1;
else v = 0;
5790 (b,
v, sample[
d].tick,
5800 oldLevel = newLevel;
5819 timeoutBits |= (1<<b);
5849 sprintf(fifo,
"/dev/pigpio%d", n);
5873 if (changedBits & bits)
5877 for (
d=0;
d<numSamples;
d++)
5879 newLevel = sample[
d].
level & bits;
5881 if (newLevel != oldLevel)
5883 report[emit].seqno = seqno;
5888 oldLevel = newLevel;
5905 if (timeoutBits & bits)
5913 if (timeoutBits & bits & (1<<b))
5916 newLevel = sample[numSamples-1].
level;
5920 report[emit].seqno = seqno;
5923 report[emit].tick = eTick;
5924 report[emit].level = newLevel;
5942 if (eventBits &
gpioNotify[n].eventBits & (1<<b))
5945 newLevel = sample[numSamples-1].
level;
5949 report[emit].seqno = seqno;
5952 report[emit].tick = eTick;
5953 report[emit].level = newLevel;
5963 if ((
int)(eTick -
gpioNotify[n].lastReportTick) > 60000000)
5966 newLevel = sample[numSamples-1].
level;
5970 report[emit].seqno = seqno;
5972 report[emit].tick = eTick;
5973 report[emit].level = newLevel;
5993 if (emit > max_emits)
6005 if ((errno != EAGAIN) && (errno != EWOULDBLOCK))
6033 emitted += max_emits;
6046 if ((errno != EAGAIN) && (errno != EWOULDBLOCK))
6100 pthread_mutex_unlock(&
gpioScript[n].pthMutex);
6122 pthread_mutex_unlock(&
gpioScript[n].pthMutex);
6148 for (j=0; j<numSamples; j++)
6150 if ((sample[j].level & bit) != LBitV)
6152 LBitV = sample[j].
level & bit;
6164 struct timespec req, rem;
6165 uint32_t oldLevel, newLevel, level;
6166 uint32_t oldSlot, newSlot;
6167 uint32_t expected, ft, sTick;
6168 uint32_t changedBits;
6169 int32_t diff, minDiff, stickInited;
6171 int numSamples, ticks, i;
6172 int rp, reports, totalSamples;
6248 while ((oldSlot != newSlot) && (numSamples <
MAX_SAMPLE))
6252 sample[numSamples].
tick = sTick;
6253 sample[numSamples].
level = level;
6275 diff = sTick - expected;
6277 if (abs(diff) > minDiff)
6316 if (oldSlot == newSlot) moreToDo = 0;
else moreToDo = 1;
6333 for (rp=0; rp<numSamples; rp++)
6337 if (newLevel != oldLevel)
6339 sample[reports].
tick = sample[rp].
tick;
6341 changedBits |= (newLevel ^ oldLevel);
6342 oldLevel = newLevel;
6348 totalSamples += reports;
6355 alertEmit(sample, reports, changedBits, sample[rp].tick);
6365 totalSamples += reports;
6373 alertEmit(sample, reports, changedBits, sTick);
6389 while (nanosleep(&req, &rem))
6391 req.tv_sec = rem.tv_sec;
6392 req.tv_nsec = rem.tv_nsec;
6437 t=*v1; *v1=*v2; *v2= t;
6444 pthread_mutex_lock(&
s->pthMutex);
6449 s->eventBits = bits;
6452 pthread_cond_wait(&
s->pthCond, &
s->pthMutex);
6459 pthread_mutex_unlock(&
s->pthMutex);
6461 return s->changedBits;
6468 pthread_mutex_lock(&
s->pthMutex);
6476 pthread_cond_wait(&
s->pthCond, &
s->pthMutex);
6483 pthread_mutex_unlock(&
s->pthMutex);
6485 return s->changedBits;
6490 static int scrSys(
char *cmd, uint32_t p1, uint32_t p2)
6498 snprintf(buf,
sizeof(buf),
"/opt/pigpio/cgi/%s %u %u", cmd, p1, p2);
6515 int p1, p2, p1o, p2o, p3o, *
t1, *
t2;
6527 pthread_mutex_lock(&
s->pthMutex);
6529 pthread_cond_wait(&
s->pthCond, &
s->pthMutex);
6530 pthread_mutex_unlock(&
s->pthMutex);
6542 instr =
s->script.instr[PC];
6547 if (instr.
opt[1] ==
CMD_VAR) instr.
p[1] =
s->script.var[p1o];
6548 else if (instr.
opt[1] ==
CMD_PAR) instr.
p[1] =
s->script.par[p1o];
6550 if (instr.
opt[2] ==
CMD_VAR) instr.
p[2] =
s->script.var[p2o];
6551 else if (instr.
opt[2] ==
CMD_PAR) instr.
p[2] =
s->script.par[p2o];
6564 memcpy((
char*)&p3o, (
char *)instr.
p[4],
sizeof(
int));
6565 if (instr.
opt[3] ==
CMD_VAR) memcpy(buf, (
char *)&(
s->script.var[p3o]),
sizeof(
int));
6566 else memcpy(buf, (
char *)&(
s->script.par[p3o]),
sizeof(
int));
6570 memcpy(buf, (
char *)instr.
p[4], instr.
p[3]);
6597 {--
s->script.par[p1o]; F=
s->script.par[p1o];}
6599 {--
s->script.var[p1o]; F=
s->script.var[p1o];}
6613 {++
s->script.par[p1o]; F=
s->script.par[p1o];}
6615 {++
s->script.var[p1o]; F=
s->script.var[p1o];}
6621 case PI_CMD_JM:
if (F<0) PC=p1;
else PC++;
break;
6625 case PI_CMD_JNZ:
if (F) PC=p1;
else PC++;
break;
6627 case PI_CMD_JP:
if (F>=0) PC=p1;
else PC++;
break;
6629 case PI_CMD_JZ:
if (!F) PC=p1;
else PC++;
break;
6632 if (instr.
opt[1] ==
CMD_PAR)
s->script.par[p1o]=p2;
6633 else s->script.var[p1o]=p2;
6640 if ((p1 >= 0) && (p1 <
sizeof(buf))) A = buf[p1];
6648 case PI_CMD_OR: A|=p1; F=A; PC++;
break;
6652 s->script.par[p1o]=
scrPop(
s, &SP, S);
6654 s->script.var[p1o]=
scrPop(
s, &SP, S);
6674 {
s->script.par[p1o]<<=p2; F=
s->script.par[p1o];}
6676 {
s->script.var[p1o]<<=p2; F=
s->script.var[p1o];}
6684 {
s->script.par[p1o]>>=p2; F=
s->script.par[p1o];}
6686 {
s->script.var[p1o]>>=p2; F=
s->script.var[p1o];}
6693 if (instr.
opt[1] ==
CMD_PAR)
s->script.par[p1o]=A;
6694 else s->script.var[p1o]=A;
6699 if ((p1 >= 0) && (p1 <
sizeof(buf))) buf[p1] = A;
6715 else t1 = &
s->script.var[p1o];
6718 else t2 = &
s->script.var[p2o];
6754 struct timespec req, rem;
6763 while (nanosleep(&req, &rem))
6765 req.tv_sec = rem.tv_sec;
6766 req.tv_nsec = rem.tv_nsec;
6769 if (tp->ex) (tp->func)(tp->userdata);
6782 int idx, flags, len, res, i;
6800 flags = fcntl(fileno(
outFifo), F_GETFL, 0);
6801 fcntl(fileno(
outFifo), F_SETFL, flags | O_NONBLOCK);
6809 if (fgets(buf,
sizeof(buf),
inpFifo) == NULL)
6823 while (((ctl.
eaten)<len) && (idx >= 0))
6836 fprintf(
outFifo,
"%d\n", res);
6840 fprintf(
outFifo,
"%d\n", res);
6844 fprintf(
outFifo,
"%d\n", res);
6848 fprintf(
outFifo,
"%08X\n", res);
6852 fprintf(
outFifo,
"%u\n", res);
6863 for (i=0; i<res; i++)
6872 if (res < 0) fprintf(
outFifo,
"%d\n", res);
6899 int sock = *(
int*)fdC;
6908 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)&opt,
sizeof(
int));
6912 if (recv(sock, p, 16, MSG_WAITALL) != 16)
break;
6916 if (p[3] <
sizeof(buf))
6919 if (recv(sock, buf, p[3], MSG_WAITALL) != p[3])
6923 "recv failed for %d bytes, sock=%d", p[3], sock);
6936 "ext too large %d(%d), sock=%d", p[3],
sizeof(buf), sock);
6959 sock, IPPROTO_TCP, TCP_NODELAY, (
char*)&opt,
sizeof(
int));
6964 p[3] =
myDoCommand(p,
sizeof(buf)-1, buf+
sizeof(
int));
6965 if (((
int)p[3]) >= 0)
6967 memcpy(buf, &p[3], 4);
6976 if (write(sock, p, 16) == -1) { }
6999 if (((
int)p[3]) > 0)
7001 if (write(sock, buf, p[3]) == 1) { }
7025 if (saddr->sa_family != AF_INET)
return 0;
7027 addr = ((
struct sockaddr_in *) saddr)->sin_addr.s_addr;
7040 int fdC=0,
c, *sock;
7041 struct sockaddr_storage
client;
7042 pthread_attr_t attr;
7044 if (pthread_attr_init(&attr))
7046 "pthread_attr_init failed (%m)");
7048 if (pthread_attr_setstacksize(&attr,
STACK_SIZE))
7050 "pthread_attr_setstacksize failed (%m)");
7052 if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))
7054 "pthread_attr_setdetachstate failed (%m)");
7071 fdC = accept(
fdSock, (
struct sockaddr *)&
client, (socklen_t*)&
c);
7077 sock = malloc(
sizeof(
int));
7084 "socket pthread_create failed (%m)");
7116 count = read(fd, str,
sizeof(str)-1);
7122 if (!err)
delete = 0;
7143 fd = open(
PI_LOCKFILE, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC, 0644);
7147 lockResult = flock(fd, LOCK_EX|LOCK_NB);
7151 sprintf(pidStr,
"%d\n", (
int)getpid());
7153 if (write(fd, pidStr, strlen(pidStr)) == -1)
7170 static uint32_t *
initMapMem(
int fd, uint32_t addr, uint32_t len)
7172 return (uint32_t *) mmap(0, len,
7173 PROT_READ|PROT_WRITE|PROT_EXEC,
7174 MAP_SHARED|MAP_LOCKED,
7184 if ((
fdMem = open(
"/dev/mem", O_RDWR | O_SYNC) ) < 0)
7188 "+---------------------------------------------------------+\n" \
7189 "|Sorry, you don't have permission to run this program. |\n" \
7190 "|Try running as root, e.g. precede the command with sudo. |\n" \
7191 "+---------------------------------------------------------+\n\n");
7220 if (
dmaReg == MAP_FAILED)
7236 if (
clkReg == MAP_FAILED)
7246 if (
spiReg == MAP_FAILED)
7251 if (
pwmReg == MAP_FAILED)
7256 if (
pcmReg == MAP_FAILED)
7261 if (
auxReg == MAP_FAILED)
7280 (
int pmapFd,
void *virtualBase,
int basePage,
int pages)
7289 unsigned long long pa;
7295 pageAdr = (uint32_t)
dmaVirt[basePage];
7297 index = ((uint32_t)virtualBase /
PAGE_SIZE) * 8;
7299 offset = lseek(pmapFd, index, SEEK_SET);
7301 if (offset != index)
7304 for (n=0; n<pages; n++)
7306 t = read(pmapFd, &pa,
sizeof(pa));
7308 if (t !=
sizeof(pa))
7313 physical = 0x3FFFFFFF & (
PAGE_SIZE * (pa & 0xFFFFFFFF));
7323 PROT_READ|PROT_WRITE,
7324 MAP_SHARED|MAP_FIXED|MAP_LOCKED|MAP_NORESERVE,
7348 PROT_READ|PROT_WRITE,
7349 MAP_SHARED|MAP_ANONYMOUS|MAP_NORESERVE|MAP_LOCKED,
7367 PROT_READ|PROT_WRITE,
7368 MAP_SHARED|MAP_ANONYMOUS|MAP_NORESERVE|MAP_LOCKED,
7371 if (
dmaVirt[pageNum] == MAP_FAILED)
7379 while ((trys < 10) && !
ok)
7399 uintptr_t virtualAdr;
7411 virtualAdr = (uintptr_t)
dmaMboxBlk[block].virtual_addr;
7429 int i, servoCycles, superCycles;
7458 PROT_READ|PROT_WRITE,
7459 MAP_PRIVATE|MAP_ANONYMOUS|MAP_LOCKED,
7467 PROT_READ|PROT_WRITE,
7468 MAP_PRIVATE|MAP_ANONYMOUS|MAP_LOCKED,
7471 if (
dmaBus == MAP_FAILED)
7488 PROT_READ|PROT_WRITE,
7489 MAP_PRIVATE|MAP_ANONYMOUS|MAP_LOCKED,
7495 fdPmap = open(
"/proc/self/pagemap", O_RDONLY);
7521 PROT_READ|PROT_WRITE,
7522 MAP_PRIVATE|MAP_ANONYMOUS|MAP_LOCKED,
7550 "gpioReg=%08X pwmReg=%08X pcmReg=%08X clkReg=%08X auxReg=%08X",
7559 fprintf(stderr,
"*** INPUT DMA CONTROL BLOCKS ***\n");
7664 (
int clkCtl,
int clkDiv,
int clkSrc,
int divI,
int divF,
int MASH)
7667 clkCtl, clkDiv, clkSrc, divI, divF, MASH);
7693 const unsigned BITS=10;
7695 unsigned clkCtl, clkDiv, clkSrc, clkDivI, clkDivF, clkMash, clkBits;
7720 clkDivI = 50 * micros;
7726 per, clkDivI, clkDivF, clkMash, clkBits);
7728 initHWClk(clkCtl, clkDiv, clkSrc, clkDivI, clkDivF, clkMash);
7738 static void initDMAgo(
volatile uint32_t *dmaAddr, uint32_t cbAddr)
7807 pthread_mutex_init(&
wfRx[i].mutex, NULL);
7953 if (
dmaBus != MAP_FAILED)
8056 struct sockaddr_in
server;
8057 struct sockaddr_in6 server6;
8060 struct sched_param
param;
8061 pthread_attr_t pthAttr;
8092 model = (rev >> 4) & 0xFF;
8116 #ifndef EMBEDDED_IN_VM
8133 param.sched_priority = sched_get_priority_max(SCHED_FIFO);
8136 sched_setscheduler(0, SCHED_FIFO, &
param);
8142 if (pthread_attr_init(&pthAttr))
8145 if (pthread_attr_setstacksize(&pthAttr,
STACK_SIZE))
8172 fdSock = socket(AF_INET6, SOCK_STREAM , 0);
8176 bzero((
char *)&server6,
sizeof(server6));
8177 server6.sin6_family = AF_INET6;
8180 server6.sin6_addr = in6addr_loopback;
8184 server6.sin6_addr = in6addr_any;
8186 server6.sin6_port = htons(port);
8188 if (bind(
fdSock,(
struct sockaddr *)&server6,
sizeof(server6)) < 0)
8195 fdSock = socket(AF_INET , SOCK_STREAM , 0);
8200 server.sin_family = AF_INET;
8203 server.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
8207 server.sin_addr.s_addr = htonl(INADDR_ANY);
8209 server.sin_port = htons(port);
8239 if (bitPos < numBits)
8242 bitp = 7 - (bitPos % 8);
8243 if (buf[bufp] & (1<<bitp))
return 1;
8256 bitp = 7 - (bitPos % 8);
8258 if (bit) buf[bufp] |= (1<<bitp);
8259 else buf[bufp] &= (~(1<<bitp));
8271 return (
dmaOVirt[page]->OOL[slot]);
8300 return (
dmaOVirt[page]->OOL[slot]);
8329 return (
dmaOVirt[page]->OOL[slot]);
8365 gettimeofday(&tv, 0);
8367 t = (double)tv.tv_sec + ((
double)tv.tv_usec / 1E6);
8376 struct timespec ts, rem;
8380 ts.tv_sec = seconds;
8381 ts.tv_nsec = (seconds-(double)ts.tv_sec) * 1E9;
8383 while (clock_nanosleep(CLOCK_REALTIME, 0, &ts, &rem))
8386 ts.tv_sec = rem.tv_sec;
8387 ts.tv_nsec = rem.tv_nsec;
8398 unsigned numWaves, t;
8407 for (i=0; i<numWaves; i++)
8409 fprintf(stderr,
"%10u %08X %08X %08X %10u\n",
8410 t, waves[i].gpioOn, waves[i].gpioOff,
8411 waves[i].flags, waves[i].usDelay);
8429 fprintf(stderr,
"p%d=%d ", i,
gpioScript[script_id].script.par[i]);
8432 fprintf(stderr,
"\n");
8436 fprintf(stderr,
"v%d=%d ", i,
gpioScript[script_id].script.var[i]);
8439 fprintf(stderr,
"\n");
8444 "c%d=[%d, %d(%d), %d(%d), %d, %d]\n",
8514 #ifndef EMBEDDED_IN_VM
8519 "\n#####################################################\n");
8520 fprintf(stderr,
"pigpio version=%d internals=%X\n",
8524 "micros=%d allocMode=%d dmaInitCbs=%d DMARestarts=%d\n",
8529 "samples %u maxSamples %u maxEmit %u emitFrags %u\n",
8533 fprintf(stderr,
"cbTicks %d, cbCalls %u\n",
8536 fprintf(stderr,
"pipe: good %u, short %u, would block %u\n",
8540 fprintf(stderr,
"alertTicks %u, lateTicks %u, moreToDo %u\n",
8547 "\n#####################################################\n\n\n");
8594 pwm = (
PWMDef[i] >> 4) & 3;
8609 int reg, shift, old_mode;
8622 shift = (gpio%10) * 3;
8624 old_mode = (
gpioReg[reg] >> shift) & 7;
8626 if (
mode != old_mode)
8653 shift = (gpio%10) * 3;
8655 return (
gpioReg[reg] >> shift) & 7;
8793 pwm = (
PWMDef[gpio] >> 4) & 3;
8809 int oldWidth, newWidth;
8827 newWidth = (range * oldWidth) /
gpioInfo[gpio].range;
8883 pwm = (
PWMDef[gpio] >> 4) & 3;
8900 unsigned diff, best, idx;
8902 DBG(
DBG_USER,
"gpio=%d frequency=%d", gpio, frequency);
8909 if (frequency >
pwmFreq[0]) idx = 0;
8919 else diff =
pwmFreq[i] - frequency;
8951 unsigned pwm, clock;
8963 pwm = (
PWMDef[gpio] >> 4) & 3;
8967 clock = (
clkDef[gpio] >> 4) & 3;
8980 DBG(
DBG_USER,
"gpio=%d pulsewidth=%d", gpio, val);
8989 "gpio %d, bad pulsewidth (%d)", gpio, val);
8993 "gpio %d, bad pulsewidth (%d)", gpio, val);
9088 DBG(
DBG_USER,
"numPulses=%u pulses=%08X", numPulses, (uint32_t)pulses);
9097 for (p=0; p<numPulses; p++)
9100 wf[2][p].
gpioOn = pulses[p].gpioOn;
9119 int i, b, p, lev,
c,
v;
9121 uint16_t *wstr = (uint16_t *)bstr;
9122 uint32_t *lstr = (uint32_t *)bstr;
9124 unsigned bitDelay[32];
9127 "gpio=%d baud=%d bits=%d stops=%d offset=%d numBytes=%d str=[%s]",
9128 gpio,
baud, data_bits, stop_bits, offset,
9129 numBytes,
myBuf2Str(numBytes, (
char *)bstr));
9146 "bad number of (half) stop bits (%d)", stop_bits);
9157 if (data_bits > 8) numBytes /= 2;
9158 if (data_bits > 16) numBytes /= 2;
9160 if (!numBytes)
return 0;
9170 if (offset > bitDelay[0])
wf[2][p].
usDelay = offset;
9173 for (i=0; i<numBytes; i++)
9186 if (data_bits < 9)
c = bstr[i];
9187 else if (data_bits < 17)
c = wstr[i];
9190 for (b=0; b<data_bits; b++)
9192 if (
c & (1<<b))
v=1;
else v=0;
9194 if (
v == lev)
wf[2][p].
usDelay += bitDelay[b+1];
9220 if (lev)
wf[2][p].
usDelay += bitDelay[data_bits+1];
9227 wf[2][p].
usDelay = bitDelay[data_bits+1];
9250 unsigned spiBitFirst,
9251 unsigned spiBitLast,
9254 int p, bit, dbv, halfbit;
9255 int rising_edge[2], read_cycle[2];
9256 uint32_t on_bits, off_bits;
9260 "spi=%08X off=%d spiSS=%d tx=%08X, num=%d fb=%d lb=%d spiBits=%d",
9261 (uint32_t)spi, offset, spiSS, (uint32_t)buf, spiTxBits,
9262 spiBitFirst, spiBitLast, spiBits);
9277 if (spi->clk_pol) {rising_edge[0] = 0; rising_edge[1] = 1;}
9278 else {rising_edge[0] = 1; rising_edge[1] = 0;}
9280 if (spi->clk_pha) {read_cycle[0] = 0; read_cycle[1] = 1;}
9281 else {read_cycle[0] = 1; read_cycle[1] = 0;}
9303 on_bits |= (1<<(spi->mosi));
9308 off_bits |= (1<<(spi->mosi));
9312 if (!spi->clk_pha) tx_bit_pos ++;
9314 if (spi->ss_pol) off_bits |= (1<<spiSS);
9315 else on_bits |= (1<<spiSS);
9317 if (spi->clk_pol) on_bits |= (1<<(spi->clk));
9318 else off_bits |= (1<<(spi->clk));
9324 if (spi->clk_us > spi->ss_us)
wf[2][p].
usDelay = spi->clk_us;
9329 for (bit=1; bit<=spiBits; bit++)
9331 for (halfbit=0; halfbit<2; halfbit++)
9339 if (read_cycle[halfbit])
9341 if ((bit>=spiBitFirst) && (bit<=spiBitLast))
9348 if (!dbv) on_bits |= (1<<(spi->mosi));
9353 if (dbv) off_bits |= (1<<(spi->mosi));
9360 if (rising_edge[halfbit]) on_bits |= (1<<(spi->clk));
9361 else off_bits |= (1<<(spi->clk));
9373 if (spi->ss_pol) on_bits |= (1<<spiSS);
9374 else off_bits |= (1<<spiSS);
9391 int numCB, numBOOL, numTOOL;
9412 (
waveInfo[i].numBOOL == numBOOL) &&
9459 if ( (numCB != (CB-
waveInfo[wid].botCB)) ||
9460 (numBOOL != (BOOL-
waveInfo[wid].botOOL)) ||
9461 (numTOOL != (
waveInfo[wid].topOOL-TOOL)) )
9463 DBG(
DBG_ALWAYS,
"ERROR wid=%d CBs %d=%d BOOL %d=%d TOOL %d=%d", wid,
9465 numBOOL, BOOL-
waveInfo[wid].botOOL,
9466 numTOOL,
waveInfo[wid].topOOL-TOOL);
9499 while ((wave_id > 0) && (
waveInfo[wave_id-1].deleted)) --wave_id;
9528 DBG(
DBG_USER,
"wave_id=%d wave_mode=%d", wave_id, wave_mode);
9621 return (uint32_t) (p + index);
9684 for (b=0; b < (blocks*(blklen+1)); b++)
chainSetCntVal(counter, b, repeat);
9686 for (b=0; b<blocks; b++)
9688 ((b*(blklen+1))+blklen),
9691 for (b=0; b<blocks; b++)
9739 p->
length = blocks*(blklen+1)*4;
9744 while (count && (b<blocks))
9746 dig = count % blklen;
9758 for (b=0; b < (blocks*(blklen+1)); b++)
9766 unsigned blklen=16, blocks=4;
9769 int i, wid, cmd, loop, counters;
9770 unsigned cycles, delayCBs, dcb, delayLeft;
9771 uint32_t repeat, next, *endPtr;
9772 int stk_pos[10], stk_lev=0;
9811 p->
src = (uint32_t) (&
dmaOBus[0]->periphData);
9822 wid = (unsigned)buf[i];
9826 if ((i+2) > bufSize)
9828 "incomplete chain command (at %d)", i);
9834 if (stk_lev >= (
sizeof(stk_pos)/
sizeof(
int)))
9836 "chain counters nested too deep (at %d)", i);
9838 stk_pos[stk_lev++] =
cb;
9846 "too many chain counters (at %d)", i);
9848 if ((i+4) > bufSize)
9850 "incomplete chain command (at %d)", i);
9853 if (--stk_lev >= 0) loop = stk_pos[stk_lev];
9855 if ((loop < 1) || (loop ==
cb))
9857 "empty chain loop (at %d)", i);
9859 cycles = ((unsigned)buf[i+3] << 8) + (unsigned)buf[i+2];
9865 "bad chain loop count (%d)", cycles);
9876 else if (cycles == 1)
9901 p->
src = (uint32_t) (&
dmaOBus[0]->periphData);
9902 p->
dst = (uint32_t) (&
dmaOBus[0]->periphData);
9907 cycles-1, repeat, next);
9914 if ((i+4) > bufSize)
9916 "incomplete chain command (at %d)", i);
9918 cycles = ((unsigned)buf[i+3] << 8) + (unsigned)buf[i+2];
9924 "bad chain delay micros (%d)", cycles);
9930 for (dcb=0; dcb<delayCBs; dcb++)
9953 p->
src = (uint32_t) (&
dmaOBus[0]->periphData);
9974 if (--stk_lev >= 0) loop = stk_pos[stk_lev];
9976 if ((loop < 1) || (loop ==
cb))
9978 "empty chain loop (at %d)", i);
9986 "loop forever must be last command");
9992 p->
src = (uint32_t) (&
dmaOBus[0]->periphData);
9993 p->
dst = (uint32_t) (&
dmaOBus[0]->periphData);
10000 "unknown chain command (255 %d)", cmd);
10040 p->
src = (uint32_t) (&
dmaOBus[0]->periphData);
10041 p->
dst = (uint32_t) (&
dmaOBus[0]->periphData);
10045 if (!endPtr) endPtr = &p->
next;
10080 if (
cb < 0)
return -
cb;
10239 uint32_t now, max_stretch=100000;
10305 for(bit=0; bit<8; bit++)
10320 for (bit=0; bit<8; bit++)
10346 "SDA %d, bad baud rate (%d)", SDA,
baud);
10417 int i, ack, inPos, outPos,
status, bytes;
10418 int addr, flags, esc, setesc;
10421 DBG(
DBG_USER,
"gpio=%d inBuf=%s outBuf=%08X len=%d",
10422 SDA,
myBuf2Str(inLen, (
char *)inBuf), (
int)outBuf, outLen);
10432 if (!inBuf || !inLen)
10435 if (!outBuf && outLen)
10451 while (!
status && (inPos < inLen))
10453 DBG(
DBG_INTERNAL,
"status=%d inpos=%d inlen=%d cmd=%d addr=%d flags=%x",
10454 status, inPos, inLen, inBuf[inPos], addr, flags);
10456 switch (inBuf[inPos++])
10490 if (bytes >= 0) ack =
I2CPutByte(
w, (addr<<1)|1);
10496 if ((bytes + outPos) <= outLen)
10498 for (i=0; i<(bytes-1); i++)
10521 if ((bytes + inPos) <= inLen)
10523 for (i=0; i<(bytes-1); i++)
10540 if (setesc) esc = 1;
else esc = 0;
10590 static int bscMode = 0;
10595 DBG(
DBG_USER,
"control=0x%X (sa=0x%X, cr=0x%X) tx=%d [%s]",
10615 if (
mode > bscMode)
10623 if (bscMode)
bscTerm(bscMode);
10640 while ((copied < xfer->txCnt) &&
10666 return (copied<<16) |
bscFR;
10720 uint8_t bit, rxByte=0;
10730 for (bit=0; bit<8; bit++)
10751 rxByte = (rxByte >> 1) |
myGpioRead(
w->S.MISO) << 7;
10769 for (bit=0; bit<8; bit++)
10788 rxByte = (rxByte >> 1) |
myGpioRead(
w->S.MISO) << 7;
10807 unsigned CS,
unsigned MISO,
unsigned MOSI,
unsigned SCLK,
10808 unsigned baud,
unsigned spiFlags)
10813 DBG(
DBG_USER,
"CS=%d MISO=%d MOSI=%d SCLK=%d baud=%d flags=%d",
10814 CS, MISO, MOSI, SCLK,
baud, spiFlags);
10835 "CS %d is already being used, mode %d", CS,
wfRx[CS].
mode);
10841 bits = (1<<CS) | (1<<MISO) | (1<<MOSI) | (1<<SCLK);
10843 if (__builtin_popcount(bits) == 4)
10865 "GPIO already being used (%d=%d %d=%d, %d=%d %d=%d)",
10941 if (--
wfRx[SCLK].S.usage <= 0)
10977 DBG(
DBG_USER,
"CS=%d inBuf=%s outBuf=%08X count=%d",
10978 CS,
myBuf2Str(count, (
char *)inBuf), (
int)outBuf, count);
10988 if (!inBuf || !count)
10991 if (!outBuf && count)
11023 int bitTime, timeout;
11025 DBG(
DBG_USER,
"gpio=%d baud=%d data_bits=%d", gpio,
baud, data_bits);
11034 "gpio %d, bad baud rate (%d)", gpio,
baud);
11039 "gpio %d, bad data bits (%d)", gpio, data_bits);
11046 timeout = ((data_bits+2) * bitTime)/
MILLION;
11048 if (timeout < 1) timeout = 1;
11066 else if (data_bits < 17)
wfRx[gpio].
s.
bytes = 2;
11078 DBG(
DBG_USER,
"gpio=%d invert=%d", gpio, invert);
11091 "bad invert level for gpio %d (%d)", gpio, invert);
11102 unsigned bytes=0, wpos;
11105 DBG(
DBG_USER,
"gpio=%d buf=%08X bufSize=%d", gpio, (
int)buf, bufSize);
11120 if (
w->s.readPos !=
w->s.writePos)
11122 wpos =
w->s.writePos;
11124 if (wpos >
w->s.readPos) bytes = wpos -
w->s.readPos;
11125 else bytes =
w->s.bufSize -
w->s.readPos;
11127 if (bytes > bufSize) bytes = bufSize;
11131 bytes = (bytes /
w->s.bytes) *
w->s.bytes;
11133 if (buf) memcpy(buf,
w->s.buf+
w->s.readPos, bytes);
11135 w->s.readPos += bytes;
11137 if (
w->s.readPos >=
w->s.bufSize)
w->s.readPos = 0;
11164 free(
wfRx[gpio].
s.buf);
11188 event, (uint32_t)
f, user, (uint32_t)userdata);
11203 DBG(
DBG_USER,
"event=%d function=%08X", event, (uint32_t)
f);
11220 DBG(
DBG_USER,
"event=%d function=%08X userdata=%08X",
11221 event, (uint32_t)
f, (uint32_t)userdata);
11280 gpio, (uint32_t)
f, user, (uint32_t)userdata);
11305 DBG(
DBG_USER,
"gpio=%d function=%08X", gpio, (uint32_t)
f);
11322 DBG(
DBG_USER,
"gpio=%d function=%08X userdata=%08X",
11323 gpio, (uint32_t)
f, (uint32_t)userdata);
11346 DBG(
DBG_USER,
"gpio=%d edge=%d timeout=%d f=%x u=%d data=%x",
11350 sprintf(buf,
"/sys/class/gpio/gpio%d/value", isr->
gpio);
11352 if ((fd = open(buf, O_RDONLY)) < 0)
11360 pfd.events = POLLPRI;
11362 lseek(fd, 0, SEEK_SET);
11363 if (read(fd, buf,
sizeof buf) == -1) { }
11367 retval = poll(&pfd, 1, isr->
timeout);
11375 lseek(fd, 0, SEEK_SET);
11376 if (read(fd, buf,
sizeof buf) == -1) { }
11385 else (isr->
func)(isr->
gpio, level, tick);
11405 char *edge_str[]={
"rising\n",
"falling\n",
"both\n"};
11410 "gpio=%d edge=%d timeout=%d function=%08X user=%d userdata=%08X",
11411 gpio, edge, timeout, (uint32_t)
f, user, (uint32_t)userdata);
11417 fd = open(
"/sys/class/gpio/export", O_WRONLY);
11421 sprintf(buf,
"%d\n", gpio);
11422 err = write(fd, buf, strlen(buf));
11425 sprintf(buf,
"/sys/class/gpio/gpio%d/direction", gpio);
11426 fd = open(buf, O_WRONLY);
11429 err = write(fd,
"in\n", 3);
11440 if (
gpioISR[gpio].edge != edge)
11442 sprintf(buf,
"/sys/class/gpio/gpio%d/edge", gpio);
11443 fd = open(buf, O_WRONLY);
11446 err = write(fd, edge_str[edge], strlen(edge_str[edge]));
11452 if (
gpioISR[gpio].pth != NULL)
11453 pthread_kill(*
gpioISR[gpio].pth, SIGCHLD);
11456 if (timeout <= 0) timeout = -1;
11457 if (
gpioISR[gpio].timeout != timeout)
11461 if (
gpioISR[gpio].pth != NULL)
11462 pthread_kill(*
gpioISR[gpio].pth, SIGCHLD);
11469 if (
gpioISR[gpio].pth == NULL)
11483 fd = open(
"/sys/class/gpio/unexport", O_WRONLY);
11485 sprintf(buf,
"%d\n", gpio);
11486 err = write(fd, buf, strlen(buf));
11504 DBG(
DBG_USER,
"gpio=%d edge=%d timeout=%d function=%08X",
11505 gpio, edge, timeout, (uint32_t)
f);
11528 DBG(
DBG_USER,
"gpio=%d edge=%d timeout=%d function=%08X userdata=%08X",
11529 gpio, edge, timeout, (uint32_t)
f, (uint32_t)userdata);
11554 DBG(
DBG_USER,
"closed orphaned fd=%d (handle=%d)", fd, i);
11565 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
11566 if (lock) pthread_mutex_lock(&mutex);
11567 else pthread_mutex_unlock(&mutex);
11599 sprintf(
name,
"/dev/pigpio%d", slot);
11603 fd = open(
name, O_RDWR|O_NONBLOCK);
11613 i = fcntl(fd, F_SETPIPE_SZ, bufSize);
11618 "fcntl %s size %d failed (%m)",
name, bufSize);
11822 DBG(
DBG_USER,
"gpio=%d pulseLen=%d level=%d", gpio, pulseLen, level);
11834 "gpio %d, bad pulseLen (%d)", gpio, pulseLen);
11852 DBG(
DBG_USER,
"gpio=%d timeout=%d", gpio, timeout);
11861 "gpio %d, bad timeout (%d)", gpio, timeout);
11866 if (timeout)
wdogBits |= (1<<gpio);
11876 DBG(
DBG_USER,
"gpio=%d steady=%d active=%d", gpio, steady, active);
11906 DBG(
DBG_USER,
"gpio=%d steady=%d", gpio, steady);
11944 DBG(
DBG_USER,
"function=%08X bits=%08X", (uint32_t)
f, bits);
11967 DBG(
DBG_USER,
"function=%08X bits=%08X", (uint32_t)
f, bits);
11992 pthread_attr_t pthAttr;
11994 DBG(
DBG_INTERNAL,
"id=%d millis=%d function=%08X user=%d userdata=%08X",
11995 id, millis, (uint32_t)
f, user, (uint32_t)userdata);
12008 if (pthread_attr_init(&pthAttr))
12010 "pthread_attr_init failed (%m)");
12012 if (pthread_attr_setstacksize(&pthAttr,
STACK_SIZE))
12014 "pthread_attr_setstacksize failed (%m)");
12016 if (pthread_create(
12019 "timer %d, create failed (%m)",
id);
12031 if (pthread_self() ==
gpioTimer[
id].pthId)
12035 pthread_exit(NULL);
12039 if (pthread_cancel(
gpioTimer[
id].pthId))
12042 if (pthread_join(
gpioTimer[
id].pthId, NULL))
12059 DBG(
DBG_USER,
"id=%d millis=%d function=%08X",
id, millis, (uint32_t)
f);
12080 DBG(
DBG_USER,
"id=%d millis=%d function=%08X, userdata=%08X",
12081 id, millis, (uint32_t)
f, (uint32_t)userdata);
12101 pthread_attr_t pthAttr;
12103 DBG(
DBG_USER,
"f=%08X, userdata=%08X", (uint32_t)
f, (uint32_t)userdata);
12107 pth = malloc(
sizeof(pthread_t));
12111 if (pthread_attr_init(&pthAttr))
12114 SOFT_ERROR(NULL,
"pthread_attr_init failed");
12117 if (pthread_attr_setstacksize(&pthAttr,
STACK_SIZE))
12120 SOFT_ERROR(NULL,
"pthread_attr_setstacksize failed");
12123 if (pthread_create(pth, &pthAttr,
f, userdata))
12142 if (pthread_self() == *pth)
12145 pthread_exit(NULL);
12149 pthread_cancel(*pth);
12150 pthread_join(*pth, NULL);
12160 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
12170 pthread_mutex_lock(&mutex);
12182 pthread_mutex_unlock(&mutex);
12195 pthread_cond_init(&
s->pthCond, NULL);
12196 pthread_mutex_init(&
s->pthMutex, NULL);
12208 if (
s->script.par) free(
s->script.par);
12209 s->script.par = NULL;
12223 DBG(
DBG_USER,
"script_id=%d numParam=%d param=%08X",
12224 script_id, numParam, (uint32_t)
param);
12236 pthread_mutex_lock(&
gpioScript[script_id].pthMutex);
12240 if ((numParam > 0) && (
param != 0))
12243 sizeof(uint32_t) * numParam);
12248 pthread_cond_signal(&
gpioScript[script_id].pthCond);
12255 pthread_mutex_unlock(&
gpioScript[script_id].pthMutex);
12270 DBG(
DBG_USER,
"script_id=%d numParam=%d param=%08X",
12271 script_id, numParam, (uint32_t)
param);
12283 if ((numParam > 0) && (
param != 0))
12286 sizeof(uint32_t) * numParam);
12336 pthread_mutex_lock(&
gpioScript[script_id].pthMutex);
12342 pthread_cond_signal(&
gpioScript[script_id].pthCond);
12345 pthread_mutex_unlock(&
gpioScript[script_id].pthMutex);
12367 pthread_mutex_lock(&
gpioScript[script_id].pthMutex);
12373 pthread_cond_signal(&
gpioScript[script_id].pthCond);
12376 pthread_mutex_unlock(&
gpioScript[script_id].pthMutex);
12403 DBG(
DBG_USER,
"signum=%d function=%08X", signum, (uint32_t)
f);
12424 DBG(
DBG_USER,
"signum=%d function=%08X userdata=%08X",
12425 signum, (uint32_t)
f, (uint32_t)userdata);
12528 unsigned clock,
mode, mash;
12533 DBG(
DBG_USER,
"gpio=%d frequency=%d", gpio, frequency);
12537 if ((gpio >> 24) == 0x5A) password = 1;
12551 "bad hardware clock frequency (%d)", frequency);
12553 clock = (
clkDef[gpio] >> 4) & 3;
12555 if ((clock == 1) && (!password))
12557 "Need password to use clock 1 (%d)", gpio);
12566 if (clkInf.
frac == 0) mash = 0;
12575 f = (double) cfreq[clkInf.
clock] /
12576 ((
double)clkInf.
div + ((double)clkInf.
frac / 4096.0));
12586 "bad hardware clock frequency (%d)", frequency);
12604 unsigned gpio,
unsigned frequency,
unsigned dutycycle)
12606 uint32_t old_PWM_CTL;
12607 unsigned pwm,
mode;
12608 uint32_t real_range, real_dutycycle;
12610 DBG(
DBG_USER,
"gpio=%d frequency=%d dutycycle=%d",
12611 gpio, frequency, dutycycle);
12628 "bad hardware PWM frequency (%d)", frequency);
12633 pwm = (
PWMDef[gpio] >> 4) & 3;
12638 real_range = ((double)
CLK_PLLD_FREQ / (2.0 * frequency)) + 0.5;
12639 real_dutycycle = ((uint64_t)dutycycle * real_range) /
PI_HW_PWM_RANGE;
12719 DBG(
DBG_USER,
"pad=%d padStrength=%d", pad, padStrength);
12752 strength =
padsReg[11+pad] & 7;
12760 int shell(
char *scriptName,
char *scriptString)
12765 DBG(
DBG_USER,
"name=%s string=%s", scriptName, scriptString);
12772 snprintf(buf,
sizeof(buf),
12773 "/opt/pigpio/cgi/%s %s", scriptName, scriptString);
12798 f = fopen(
"/opt/pigpio/access",
"r");
12807 if (fgets(line,
sizeof(line),
f))
12809 sscanf(line,
" %511s %c%c", buffer, &perm, &term);
12814 if (fnmatch(buffer, filename, 0) == 0)
12818 if (fnmatch(match, buffer, 0) == 0)
12820 strcpy(match, buffer);
12826 strcpy(match, buffer);
12838 switch (toupper(mperm))
12852 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
12854 int i, slot, oflag, omode;
12855 struct stat statbuf;
12871 pthread_mutex_lock(&mutex);
12883 pthread_mutex_unlock(&mutex);
12899 omode |= (S_IRUSR|S_IWUSR);
12911 fd = open(file, O_RDONLY|oflag, omode);
12915 fd = open(file, O_WRONLY|oflag, omode);
12919 fd = open(file, O_RDWR|oflag, omode);
12930 if (stat(file, &statbuf) == 0)
12932 if (S_ISDIR(statbuf.st_mode))
12993 if (
w == -1)
DBG(
DBG_USER,
"write failed with errno %d", errno);
13024 DBG(
DBG_USER,
"read failed with errno %d", errno);
13040 handle, seekOffset, seekFrom);
13072 DBG(
DBG_USER,
"seek failed with errno %d", errno);
13085 DBG(
DBG_USER,
"fpat=%s count=%d buf=%x", fpat, count, (
unsigned)buf);
13094 if (glob(fpat, GLOB_MARK, NULL, &pglob) == 0)
13096 for (i=0; i<pglob.gl_pathc; i++)
13098 len = strlen(pglob.gl_pathv[i]);
13099 if ((bufpos + len + 1) < count)
13101 strcpy(buf+bufpos, pglob.gl_pathv[i]);
13103 buf[bufpos++] =
'\n';
13123 struct timespec ts;
13125 DBG(
DBG_USER,
"timetype=%d &seconds=%08X µs=%08X",
13126 timetype, (uint32_t)seconds, (uint32_t)micros);
13135 clock_gettime(CLOCK_REALTIME, &ts);
13136 *seconds = ts.tv_sec;
13137 *micros = ts.tv_nsec/1000;
13141 clock_gettime(CLOCK_REALTIME, &ts);
13145 *seconds = ts.tv_sec;
13146 *micros = ts.tv_nsec/1000;
13157 struct timespec ts, rem;
13159 DBG(
DBG_USER,
"timetype=%d seconds=%d micros=%d",
13160 timetype, seconds, micros);
13170 if ((micros < 0) || (micros > 999999))
13173 ts.tv_sec = seconds;
13174 ts.tv_nsec = micros * 1000;
13178 while (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, &rem));
13182 while (clock_nanosleep(CLOCK_REALTIME, 0, &ts, &rem))
13185 ts.tv_sec = rem.tv_sec;
13186 ts.tv_nsec = rem.tv_nsec;
13261 static unsigned rev = 0;
13269 if (rev)
return rev;
13273 filp = fopen (
"/proc/cpuinfo",
"r");
13277 while (fgets(buf,
sizeof(buf), filp) != NULL)
13281 if (!strncasecmp(
"model name", buf, 10))
13283 if (strstr (buf,
"ARMv6") != NULL)
13290 else if (strstr (buf,
"ARMv7") != NULL)
13297 else if (strstr (buf,
"ARMv8") != NULL)
13307 if (!strncasecmp(
"revision\t:", buf, 10))
13309 if (sscanf(buf+10,
"%x%c", &rev, &term) == 2)
13311 if (term !=
'\n') rev = 0;
13312 else rev &= 0xFFFFFF;
13344 DBG(
DBG_USER,
"micros=%d peripheral=%d", micros, peripheral);
13348 if ((micros < 1) || (micros > 10))
13351 if (!
clkCfg[micros].valid)
13385 DBG(
DBG_USER,
"primary channel=%d, secondary channel=%d",
13386 primaryChannel, secondaryChannel);
13395 (secondaryChannel == primaryChannel))
13479 numSockAddr, (
unsigned)sockAddr);
13489 for (i=0; i<numSockAddr; i++)
sockNetAddr[i] = sockAddr[i];
13516 DBG(
DBG_USER,
"cfgWhat=%u, cfgVal=%d", cfgWhat, cfgVal);
13553 #include "custom.cext"
#define AUXSPI_CNTL1_MSB_FIRST(x)
static int waveClockInited
#define PI_BAD_SER_OFFSET
static int initZaps(int pmapFd, void *virtualBase, int basePage, int pages)
#define PI_BUF_MILLIS_MAX
static int initGrabLockFile(void)
static volatile uint32_t * bscsReg
unsigned gpioHardwareRevision(void)
static unsigned old_mode_ace2
#define PI_BAD_WVSM_COMMND
#define PI_HW_PWM_MIN_FREQ
rawCbs_t * rawWaveCBAdr(int cbNum)
#define PI_I2C_SMBUS_WORD_DATA
static unsigned old_mode_ace1
#define PI_BB_I2C_MIN_BAUD
int bbSPIXfer(unsigned CS, char *inBuf, char *outBuf, unsigned count)
static unsigned mbUnlockMemory(int fd, unsigned handle)
static gpioTimer_t gpioTimer[PI_MAX_TIMER+1]
#define MB_ALLOCATE_MEMORY_TAG
int gpioNotifyOpenWithSize(int bufSize)
#define PI_BAD_FILE_WRITE
#define PI_LOCALHOST_SOCK_IF
static int pthFifoRunning
#define PI_NO_WAVEFORM_ID
static int chainGetCntCB(int counter)
static pthread_t pthSocket
static volatile uint32_t * gpioReg
#define PI_NOTIFY_CLOSING
static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL)
int gpioSerialReadInvert(unsigned gpio, unsigned invert)
pthread_t * gpioStartThread(gpioThreadFunc_t f, void *userdata)
void(* gpioGetSamplesFuncEx_t)(const gpioSample_t *samples, int numSamples, void *userdata)
#define PI_BAD_MICS_DELAY
int gpioSetGetSamplesFuncEx(gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata)
#define PI_WAVE_MODE_ONE_SHOT
static void flushMemory(void)
static int myI2CGetPar(char *inBuf, int *inPos, int inLen, int *esc)
#define PI_I2C_FUNC_SMBUS_READ_BYTE
static uint32_t waveOOLPOadr(int pos)
#define PI_BAD_CLK_PERIPH
#define PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS
static volatile uint32_t * systReg
int gpioCfgMemAlloc(unsigned memAllocMode)
int gpioSetPullUpDown(unsigned gpio, unsigned pud)
static volatile uint32_t * pcmReg
static uint32_t hw_pwm_real_range[2]
static void initClearGlobals(void)
int gpioWrite(unsigned gpio, unsigned level)
int serReadByte(unsigned handle)
static void wfRx_unlock(int i)
#define AUX_SPI0_STAT_REG
int gpioWaveGetMaxMicros(void)
#define DMA_DEBUG_READ_ERR
int gpioSetTimerFuncEx(unsigned id, unsigned millis, gpioTimerFuncEx_t f, void *userdata)
#define PI_NOT_SERVO_GPIO
#define PI_WAVE_MAX_CHARS
int gpioCustom1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)
#define PI_DEFAULT_DMA_PRIMARY_CHANNEL
#define MB_UNLOCK_MEMORY_TAG
static void myClearGpioOn(unsigned gpio, int pos)
#define PI_BAD_SER_INVERT
static int initCheckPermitted(void)
static DMAMem_t * dmaMboxBlk
#define PI_I2C_FUNC_SMBUS_PROC_CALL
static volatile uint32_t * dmaIn
uint32_t gpioDelay(uint32_t micros)
static int pwmFreq[PWM_FREQS]
#define PI_DEFAULT_UPDATE_MASK_A_B2
void *() gpioThreadFunc_t(void *)
#define PI_MAX_MILS_DELAY
#define PI_MIN_PAD_STRENGTH
int rawWaveAddSPI(rawSPI_t *spi, unsigned offset, unsigned spiSS, char *buf, unsigned spiTxBits, unsigned spiBitFirst, unsigned spiBitLast, unsigned spiBits)
static int mbUnmapMem(void *addr, unsigned size)
#define MB_PROCESS_REQUEST
#define PI_MAX_DUTYCYCLE_RANGE
int gpioPWM(unsigned gpio, unsigned val)
int gpioSetPad(unsigned pad, unsigned padStrength)
static uint32_t old_spi_cntl1
static void myCreatePipe(char *name, int perm)
static volatile uint32_t wdogBits
int i2cReadDevice(unsigned handle, char *buf, unsigned count)
#define PI_SER_READ_NO_DATA
static unsigned bufferBlocks
#define CHECK_INITED_RET_NULL_PTR
uint32_t OOL[OOL_PER_OPAGE]
static gpioGetSamples_t gpioGetSamples
#define PI_I2C_OPEN_FAILED
static volatile uint32_t scriptEventBits
#define PI_SPI_FLAGS_GET_CSPOLS(x)
#define PI_DEFAULT_UPDATE_MASK_PI3B
void putBitInBytes(int bitPos, char *buf, int bit)
static unsigned old_mode_ce0
int gpioCfgSocketPort(unsigned port)
#define AUXSPI_CNTL0_INVERT_CLK(x)
static int numSockNetAddr
char txBuf[BSC_FIFO_SIZE]
static void alertNoiseFilter(gpioSample_t *sample, int numSamples)
static gpioSignal_t gpioSignal[PI_MAX_SIGNUM+1]
int i2cWriteByte(unsigned handle, unsigned bVal)
int gpioCfgDMAchannel(unsigned DMAchannel)
static pthread_t pthAlert
static void spinWhileStarting(void)
static volatile uint32_t pi_mem_flag
static volatile uint32_t pi_peri_phys
int serOpen(char *tty, unsigned serBaud, unsigned serFlags)
static volatile uint32_t notifyBits
int gpioWrite_Bits_0_31_Clear(uint32_t bits)
int bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spiFlags)
static void scrPush(gpioScript_t *s, int *SP, int *S, int val)
static uint32_t dmaPwmDataAdr(int pos)
static gpioInfo_t gpioInfo[PI_MAX_GPIO+1]
static void * pthScript(void *x)
int gpioGetPWMrealRange(unsigned gpio)
#define PI_TOO_MANY_PULSES
uint32_t tick[TCK_PER_IPAGE]
#define PI_MAX_WDOG_TIMEOUT
static int waveDelayCBs(uint32_t delay)
#define PI_BUF_MILLIS_MIN
static void alertGlitchFilter(gpioSample_t *sample, int numSamples)
#define PI_BAD_BUF_MILLIS
static const uint8_t clkDef[PI_MAX_GPIO+1]
#define PI_SCRIPT_RESERVED
int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)
#define PI_NO_FILE_ACCESS
static rawWave_t wf[3][PI_WAVE_MAX_PULSES]
static void dmaGpioOffCb(int b, int pos)
static dmaOPage_t ** dmaOBus
static void waveOOLPageSlot(int pos, int *page, int *slot)
#define AUXSPI_CNTL0_SHIFT_LEN(x)
#define MAX_CONNECT_ADDRESSES
#define PI_BAD_CHAIN_DELAY
static void waveBitDelay(unsigned baud, unsigned bits, unsigned stops, unsigned *bitDelay)
#define PI_MIN_DMA_CHANNEL
#define PI_WAVE_MODE_ONE_SHOT_SYNC
#define PI_I2C_FUNC_SMBUS_READ_WORD_DATA
unsigned DMAprimaryChannel
#define PI_I2C_SMBUS_BLOCK_MAX
static int dmaNowAtOCB(void)
int gpioSleep(unsigned timetype, int seconds, int micros)
static int mbDMAAlloc(DMAMem_t *DMAMemP, unsigned size, uint32_t pi_mem_flag)
static void myTckPageSlot(int pos, int *page, int *slot)
static void clear_SCL(wfRx_t *w)
#define PI_I2C_FUNC_SMBUS_READ_BYTE_DATA
static i2cInfo_t i2cInfo[PI_I2C_SLOTS]
static int scrSys(char *cmd, uint32_t p1, uint32_t p2)
#define PI_MAX_PAD_STRENGTH
#define CHECK_INITED_RET_NIL
void rawDumpScript(unsigned script_id)
int gpioSetSignalFuncEx(unsigned signum, gpioSignalFuncEx_t f, void *userdata)
int gpioGetPWMrange(unsigned gpio)
uint32_t gpioOff[OFF_PER_IPAGE]
static volatile uint32_t pi_dram_bus
int serWrite(unsigned handle, char *buf, unsigned count)
static rawWaveInfo_t waveInfo[PI_MAX_WAVES]
static uint64_t updateMask
#define PI_DEFAULT_CLK_MICROS
static void myLvsPageSlot(int pos, int *page, int *slot)
#define PI_SOME_PERMITTED
static void chainMakeCounter(unsigned counter, unsigned blklen, unsigned blocks, unsigned count, uint32_t repeat, uint32_t next)
uint32_t diffTick[TICKSLOTS]
int gpioGetPWMdutycycle(unsigned gpio)
#define PI_BB_SER_MIN_BAUD
static void stopHardwarePWM(void)
static void set_SDA(wfRx_t *w)
int i2cWriteDevice(unsigned handle, char *buf, unsigned count)
int gpioTrigger(unsigned gpio, unsigned pulseLen, unsigned level)
void(* gpioAlertFuncEx_t)(int gpio, int level, uint32_t tick, void *userdata)
#define AUXSPI_STAT_RX_EMPTY
#define PI_SPI_FLAGS_GET_3WREN(x)
static uint32_t reportedLevel
static int initMboxBlock(int block)
static uint32_t old_spi_cs
static unsigned bufferCycles
static volatile uint32_t alertBits
#define PI_HW_CLK_MAX_FREQ
static void initPWM(unsigned bits)
static void * mbMapMem(unsigned base, unsigned size)
int eventTrigger(unsigned event)
#define PI_BAD_SPI_CHANNEL
#define PI_I2C_FUNC_SMBUS_READ_BLOCK_DATA
static unsigned mbLockMemory(int fd, unsigned handle)
int gpioDeleteScript(unsigned script_id)
#define PI_I2C_FUNC_SMBUS_READ_I2C_BLOCK
static void spiInit(uint32_t flags)
static uint32_t waveCbPOadr(int pos)
static unsigned memAllocMode
static volatile uint32_t monitorBits
int gpioWaveGetHighCbs(void)
#define PI_BAD_SCRIPT_NAME
#define PI_MAX_SOCKET_PORT
#define PI_MEM_ALLOC_AUTO
uint32_t gpioRead_Bits_0_31(void)
static uint32_t myGetTick(int pos)
int spiWrite(unsigned handle, char *buf, unsigned count)
static volatile uint32_t * pwmReg
static int chainGetCB(int n)
#define DMA_INTERRUPT_STATUS
int gpioServo(unsigned gpio, unsigned val)
int gpioCfgInterfaces(unsigned ifFlags)
#define PI_MAX_MICS_DELAY
static int initAllocDMAMem(void)
#define PI_DISABLE_FIFO_IF
static volatile uint32_t * dmaReg
static int initPagemapBlock(int block)
void(* gpioAlertFunc_t)(int gpio, int level, uint32_t tick)
#define MB_RELEASE_MEMORY_TAG
static uint32_t hw_pwm_duty[2]
static void * pthSocketThread(void *x)
#define PI_SPI_FLAGS_GET_CSPOL(x)
#define PI_I2C_SMBUS_WRITE
#define PI_I2C_FUNC_SMBUS_WRITE_BYTE
static int intGpioSetISRFunc(unsigned gpio, unsigned edge, int timeout, void *f, int user, void *userdata)
#define PI_MAX_SCRIPT_PARAMS
#define PI_I2C_FUNC_SMBUS_QUICK
static spiInfo_t spiInfo[PI_SPI_SLOTS]
static void spiGoA(unsigned speed, uint32_t flags, char *txBuf, char *rxBuf, unsigned count)
static uint32_t chainGetCntValPadr(int counter, int slot)
int gpioWaveTxStart(unsigned wave_mode)
static dmaIPage_t ** dmaIVirt
int i2cReadWordData(unsigned handle, unsigned reg)
static void _spiRXBits(char *buf, int pos, int bitlen, int msbf, uint32_t bits)
int gpioSetAlertFunc(unsigned gpio, gpioAlertFunc_t f)
#define PI_SPI_FLAGS_GET_MODE(x)
#define PI_NTFY_FLAGS_BIT(x)
#define PI_SER_WRITE_FAILED
static volatile int runState
void rawWaveSetIn(int pos, uint32_t value)
#define PI_I2C_SMBUS_READ
#define PCM_DREQ_TX_REQ_L(x)
static unsigned old_mode_amosi
static void myGpioWrite(unsigned gpio, unsigned level)
static dmaPage_t ** dmaBus
#define PI_I2C_COMBINED_OFF
int spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)
static void set_SCLK(wfRx_t *w)
static int scrPop(gpioScript_t *s, int *SP, int *S)
int gpioWrite_Bits_32_53_Set(uint32_t bits)
int fileSeek(unsigned handle, int32_t seekOffset, int seekFrom)
static void I2CPutBit(wfRx_t *w, int bit)
int gpioStopScript(unsigned script_id)
#define PI_DEFAULT_BUFFER_MILLIS
static void initHWClk(int clkCtl, int clkDiv, int clkSrc, int divI, int divF, int MASH)
static unsigned old_mode_sclk
#define PI_SPI_FLAGS_CHANNEL(x)
int gpioWaveGetHighMicros(void)
static int scrWait(gpioScript_t *s, uint32_t bits)
#define PI_NO_SCRIPT_ROOM
#define PI_TOO_MANY_PARAM
int gpioWaveGetMaxPulses(void)
int myPathBad(char *name)
static int read_SDA(wfRx_t *w)
static void spiGoS(unsigned speed, uint32_t flags, char *txBuf, char *rxBuf, unsigned count)
#define PI_DEFAULT_UPDATE_MASK_COMPUTE
static void waveRxSerial(wfRx_t *w, int level, uint32_t tick)
#define PI_BAD_SER_DEVICE
int gpioGlitchFilter(unsigned gpio, unsigned steady)
static int myDoCommand(uint32_t *p, unsigned bufSize, char *buf)
static unsigned old_mode_amiso
#define AUXSPI_CNTL0_IN_RISING(x)
#define PI_I2C_SMBUS_BYTE_DATA
int gpioUpdateScript(unsigned script_id, unsigned numParam, uint32_t *param)
#define PI_I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
static uint8_t I2CGetByte(wfRx_t *w, int nack)
int gpioCfgClock(unsigned micros, unsigned peripheral, unsigned source)
static void mbDMAFree(DMAMem_t *DMAMemP)
static unsigned dmaCurrentSlot(unsigned pos)
static uint32_t old_spi_cntl0
#define PI_SCRIPT_STACK_SIZE
static int intGpioSetTimerFunc(unsigned id, unsigned millis, void *f, int user, void *userdata)
int fileApprove(char *filename)
static void I2C_delay(wfRx_t *w)
int gpioNotifyPause(unsigned handle)
static dmaIPage_t ** dmaIBus
static void I2C_clock_stretch(wfRx_t *w)
int gpioWaveAddSerial(unsigned gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *bstr)
char rxBuf[BSC_FIFO_SIZE]
static void myOffPageSlot(int pos, int *page, int *slot)
static uint32_t chainGetValPadr(int n)
#define PI_BB_I2C_MAX_BAUD
static uint32_t spi_dummy
void(* gpioTimerFuncEx_t)(void *userdata)
unsigned bufferMilliseconds
int gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses)
int gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f)
static int gpioNotifyOpenInBand(int fd)
#define PI_SPI_FLAGS_GET_RESVD(x)
static void bbSPIStop(wfRx_t *w)
static unsigned old_mode_asclk
#define PI_MIN_SOCKET_PORT
#define PI_SCRIPT_WAITING
static void * pthTimerTick(void *x)
static uint32_t myGetLevel(int pos)
#define AUX_SPI0_CNTL1_REG
#define PI_UNKNOWN_COMMAND
#define PI_BAD_CFG_INTERNAL
static volatile uint32_t scriptBits
static void wfRx_lock(int i)
static volatile uint32_t * padsReg
void(* gpioGetSamplesFunc_t)(const gpioSample_t *samples, int numSamples)
int fileClose(unsigned handle)
#define PI_I2C_SMBUS_I2C_BLOCK_BROKEN
#define PI_BAD_MILS_DELAY
static int mbProperty(int fd, void *buf)
uint32_t gpioCfgGetInternals(void)
#define PI_NOTIFY_RESERVED
int gpioWrite_Bits_32_53_Clear(uint32_t bits)
#define PI_DEFAULT_IF_FLAGS
static char * myBuf2Str(unsigned count, char *buf)
static void dmaCbPrint(int pos)
int gpioNoiseFilter(unsigned gpio, unsigned steady, unsigned active)
static int myGpioRead(unsigned gpio)
int i2cWriteBlockData(unsigned handle, unsigned reg, char *buf, unsigned count)
#define PI_TOO_MANY_CHARS
int gpioSetPWMrange(unsigned gpio, unsigned range)
static void initClock(int mainClock)
#define CMD_MAX_EXTENSION
#define PI_SPI_FLAGS_GET_3WIRE(x)
#define PI_I2C_SMBUS_BLOCK_DATA
int spiRead(unsigned handle, char *buf, unsigned count)
static int intGpioSetAlertFunc(unsigned gpio, void *f, int user, void *userdata)
static void * pthISRThread(void *x)
int bbSPIClose(unsigned CS)
static unsigned mbAllocateMemory(int fd, unsigned size, unsigned align, unsigned flags)
int cmdParseScript(char *script, cmdScript_t *s, int diags)
static void mbClose(int fd)
static void bbSPIStart(wfRx_t *w)
#define PI_DEFAULT_UPDATE_MASK_PI2B
static int PWMClockInited
void(* gpioISRFunc_t)(int gpio, int level, uint32_t tick)
static void myClearGpioOff(unsigned gpio, int pos)
int gpioRunScript(unsigned script_id, unsigned numParam, uint32_t *param)
static uint32_t myGpioDelay(uint32_t micros)
#define PI_I2C_SMBUS_PROC_CALL
#define PI_I2C_COMBINED_ON
static void alertEmit(gpioSample_t *sample, int numSamples, uint32_t changedBits, uint32_t eTick)
static int mbCreate(char *dev)
static void mySetGpioOff(unsigned gpio, int pos)
#define PI_MAX_WAVE_DATABITS
static void intScriptBits(void)
#define PI_MEM_ALLOC_PAGEMAP
int i2cSegments(unsigned handle, pi_i2c_msg_t *segs, unsigned numSegs)
int gpioCfgNetAddr(int numSockAddr, uint32_t *sockAddr)
static gpioAlert_t gpioAlert[PI_MAX_USER_GPIO+1]
#define PI_NUM_STD_SPI_CHANNEL
#define PI_I2C_FUNC_SMBUS_WRITE_WORD_DATA
#define PI_DEFAULT_DMA_SECONDARY_CHANNEL
int i2cWriteByteData(unsigned handle, unsigned reg, unsigned bVal)
static void clear_SCLK(wfRx_t *w)
static void myGpioSetPwm(unsigned gpio, int oldVal, int newVal)
static uint32_t dmaCbAdr(int pos)
#define DMA_PANIC_PRIORITY(x)
int gpioCustom2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)
static void waveRxBit(int gpio, int level, uint32_t tick)
int gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits)
static char * myTimeStamp()
#define PI_SPI_FLAGS_GET_CPOL(x)
static uintptr_t ** dmaPMapBlk
uint32_t rawWaveGetOut(int pos)
void i2cSwitchCombined(int setting)
#define AUXSPI_CNTL0_MSB_FIRST(x)
static uint8_t bbSPIXferByte(wfRx_t *w, char txByte)
#define PI_CFG_ALERT_FREQ
static void notifyMutex(int lock)
int gpioWrite_Bits_0_31_Set(uint32_t bits)
static int addrAllowed(struct sockaddr *saddr)
static fileInfo_t fileInfo[PI_FILE_SLOTS]
int gpioSetWatchdog(unsigned gpio, unsigned timeout)
int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)
static void chainSetCntVal(int counter, int slot, uint32_t value)
static void initDMAgo(volatile uint32_t *dmaAddr, uint32_t cbAddr)
#define PI_MAX_WAVE_CYCLES
uint32_t gpioOn[ON_PER_IPAGE]
static void I2CStop(wfRx_t *w)
static int libInitialised
#define PI_MAX_SERVO_PULSEWIDTH
int i2cWriteWordData(unsigned handle, unsigned reg, unsigned wVal)
#define AUX_SPI0_CNTL0_REG
int gpioSetMode(unsigned gpio, unsigned mode)
rawCbs_t cb[CBS_PER_OPAGE]
int gpioWaveGetMicros(void)
uint32_t level[LVS_PER_IPAGE]
int bbI2CZip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)
int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1)
#define PI_SPI_FLAGS_GET_CPHA(x)
static uint32_t dmaGpioOnAdr(int pos)
void rawWaveSetOut(int pos, uint32_t value)
static void * pthSocketThreadHandler(void *fdC)
int gpioWaveChain(char *buf, unsigned bufSize)
void rawWaveSetOOL(int pos, uint32_t value)
static uint32_t old_spi_clk
#define PI_DEFAULT_UPDATE_MASK_ZERO
static uint32_t _spiTXBits(char *buf, int pos, int bitlen, int msbf)
uint32_t rawWaveGetOOL(int pos)
#define PI_SPI_FLAGS_GET_TX_LSB(x)
static int I2CGetBit(wfRx_t *w)
static void dmaInitCbs(void)
union my_smbus_data * data
#define AUXSPI_CNTL0_OUT_RISING(x)
#define PI_BAD_WVSP_COMMND
#define PI_SCRIPT_INITING
static void dmaTickCb(int b, int pos)
static void closeOrphanedNotifications(int slot, int fd)
#define PI_MAX_BUSY_DELAY
int fileOpen(char *file, unsigned mode)
static const uint16_t pwmCycles[PWM_FREQS]
int gpioWaveGetHighPulses(void)
#define PI_BAD_CHAIN_LOOP
#define PI_I2C_SMBUS_BYTE
static uint32_t hw_clk_freq[3]
int i2cReadI2CBlockData(unsigned handle, unsigned reg, char *buf, unsigned count)
static const uint8_t PWMDef[PI_MAX_GPIO+1]
static void myGpioSetServo(unsigned gpio, int oldVal, int newVal)
#define PCM_TXC_CH1WID(x)
#define PI_MAX_WAVE_HALFSTOPBITS
int gpioWaveGetMaxCbs(void)
#define PI_WAVE_COUNT_PAGES
static uint32_t hw_pwm_freq[2]
#define PI_I2C_SMBUS_BLOCK_PROC_CALL
static void intNotifyBits(void)
int eventSetFuncEx(unsigned event, eventFuncEx_t f, void *userdata)
int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal)
int gpioWaveGetPulses(void)
static unsigned old_mode_mosi
int i2cWriteQuick(unsigned handle, unsigned bit)
unsigned gpioVersion(void)
int serWriteByte(unsigned handle, unsigned bVal)
static volatile uint32_t * clkReg
static int intEventSetFunc(unsigned event, void *f, int user, void *userdata)
rawCbs_t cb[CBS_PER_IPAGE]
#define PI_WAVE_MODE_REPEAT
#define PI_BAD_FIFO_COMMAND
static int spiAnyOpen(uint32_t flags)
int gpioSetAlertFuncEx(unsigned gpio, gpioAlertFuncEx_t f, void *userdata)
#define PI_NTFY_FLAGS_ALIVE
static dmaOPage_t ** dmaOVirt
#define PI_DEFAULT_CLK_PERIPHERAL
#define PWM_DMAC_PANIC(x)
int gpioWaveDelete(unsigned wave_id)
uint32_t wouldBlockPipeWrite
static dmaPage_t ** dmaVirt
#define PI_MAX_SCRIPT_VARS
#define PI_NOTIFY_RUNNING
int gpioRead(unsigned gpio)
int gpioSetPWMfrequency(unsigned gpio, unsigned frequency)
static void * pthAlertThread(void *x)
int gpioGetPad(unsigned pad)
#define DMA_CHANNEL_RESET
#define PI_WAVE_NOT_FOUND
#define PI_BAD_PRIM_CHANNEL
#define PI_I2C_FUNC_SMBUS_WRITE_BYTE_DATA
int gpioGetMode(unsigned gpio)
#define PI_BAD_WVSC_COMMND
int gpioCfgBufferSize(unsigned millis)
int bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud)
static void mySetGpioOn(unsigned gpio, int pos)
int serDataAvailable(unsigned handle)
static void clear_SDA(wfRx_t *w)
static uint32_t * waveEndPtr
void(* gpioSignalFuncEx_t)(int signum, void *userdata)
int i2cReadByte(unsigned handle)
#define PI_SCRIPT_RUNNING
#define PI_SPI_FLAGS_GET_CHANNEL(x)
#define PI_BB_SPI_MAX_BAUD
static eventAlert_t eventAlert[PI_MAX_EVENT+1]
#define PI_BAD_WDOG_TIMEOUT
int gpioSetTimerFunc(unsigned id, unsigned millis, gpioTimerFunc_t f)
int i2cWriteI2CBlockData(unsigned handle, unsigned reg, char *buf, unsigned count)
static void waveSetOOL(int pos, uint32_t OOL)
static unsigned dmaNowAtICB(void)
#define PI_SER_READ_FAILED
static volatile uint32_t nFilterBits
int shell(char *scriptName, char *scriptString)
static volatile uint32_t * auxReg
static void waveCBsOOLs(int *numCBs, int *numBOOLs, int *numTOOLs)
#define PI_BAD_SERIAL_COUNT
static void spiGo(unsigned speed, uint32_t flags, char *txBuf, char *rxBuf, unsigned count)
#define TIMER_SUB(a, b, result)
static volatile uint32_t * spiReg
int gpioHardwareClock(unsigned gpio, unsigned frequency)
static void spiTerm(uint32_t flags)
int bbI2CClose(unsigned SDA)
static volatile uint32_t piCores
int gpioCfgPermissions(uint64_t updateMask)
int eventSetFunc(unsigned event, eventFunc_t f)
#define AUXSPI_CNTL0_SPEED(x)
#define PI_NOT_SERIAL_GPIO
static const uint16_t pwmRealRange[PWM_FREQS]
int serRead(unsigned handle, char *buf, unsigned count)
#define PI_MEM_ALLOC_MAILBOX
#define PI_I2C_WRITE_FAILED
uint8_t block[PI_I2C_SMBUS_BLOCK_MAX+2]
static uint32_t chainGetCntVal(int counter, int slot)
#define PI_DISABLE_SOCK_IF
int gpioSerialReadClose(unsigned gpio)
#define PI_DEFAULT_UPDATE_MASK_B1
int gpioSerialReadOpen(unsigned gpio, unsigned baud, unsigned data_bits)
#define PI_FIL_OPEN_FAILED
int getBitInBytes(int bitPos, char *buf, int numBits)
#define PI_DEFAULT_MEM_ALLOC_MODE
#define PI_NTFY_FLAGS_WDOG
void(* eventFunc_t)(int event, uint32_t tick)
#define PI_DEFAULT_DUTYCYCLE_RANGE
int i2cZip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)
void report(int err, char *fmt,...)
#define DMA_DEBUG_RD_LST_NOT_SET_ERR
int gpioNotifyBegin(unsigned handle, uint32_t bits)
#define PI_BAD_CLK_MICROS
int gpioHardwarePWM(unsigned gpio, unsigned frequency, unsigned dutycycle)
static void switchFunctionOff(unsigned gpio)
int cmdParse(char *buf, uint32_t *p, unsigned ext_len, char *ext, cmdCtlParse_t *ctl)
static gpioScript_t gpioScript[PI_MAX_SCRIPTS]
#define PI_NTFY_FLAGS_EVENT
int gpioStoreScript(char *script)
void gpioStopThread(pthread_t *pth)
static unsigned mbReleaseMemory(int fd, unsigned handle)
#define PI_EMPTY_WAVEFORM
static void I2CStart(wfRx_t *w)
int gpioGetPWMfrequency(unsigned gpio)
static void intScriptEventBits(void)
int gpioSerialRead(unsigned gpio, void *buf, size_t bufSize)
#define PI_MAX_WAVE_DELAY
#define PI_CHAIN_LOOP_CNT
T param(const std::string ¶m_name, const T &default_val)
static volatile gpioStats_t gpioStats
int gpioSetISRFuncEx(unsigned gpio, unsigned edge, int timeout, gpioAlertFuncEx_t f, void *userdata)
#define PI_BAD_SOCKET_PORT
void(* gpioTimerFunc_t)(void)
static int myPermit(unsigned gpio)
#define PI_THREAD_RUNNING
static serInfo_t serInfo[PI_SER_SLOTS]
int i2cProcessCall(unsigned handle, unsigned reg, unsigned wVal)
#define PI_BAD_PULSEWIDTH
static void dmaDelayCb(int b)
static void clear_CS(wfRx_t *w)
int gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel)
static gpioNotify_t gpioNotify[PI_NOTIFY_SLOTS]
#define PI_MAX_I2C_DEVICE_COUNT
int fileRead(unsigned handle, char *buf, unsigned count)
static volatile uint32_t * dmaOut
int serClose(unsigned handle)
rawWaveInfo_t rawWaveInfo(int wave_id)
#define PI_I2C_SMBUS_QUICK
#define PI_SPI_FLAGS_GET_BITLEN(x)
#define PI_SPI_FLAGS_GET_AUX_SPI(x)
#define PI_I2C_SMBUS_I2C_BLOCK_DATA
static void dmaReadLevelsCb(int b, int pos)
int fileList(char *fpat, char *buf, unsigned count)
static void initCheckLockFile(void)
#define PI_BB_SPI_MIN_BAUD
#define PI_WAVE_MAX_PULSES
int bscXfer(bsc_xfer_t *xfer)
static int I2CPutByte(wfRx_t *w, int byte)
int spiClose(unsigned handle)
int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)
#define PI_WAVE_MAX_MICROS
#define PI_SCRIPT_NOT_READY
static void SPI_delay(wfRx_t *w)
static volatile gpioCfg_t gpioCfg
static void dmaGpioOnCb(int b, int pos)
int gpioGetServoPulsewidth(unsigned gpio)
#define PI_MAX_SPI_DEVICE_COUNT
#define PI_NUM_AUX_SPI_CHANNEL
#define DMA_WAIT_ON_WRITES
int gpioCfgSetInternals(uint32_t cfgVal)
#define SOFT_ERROR(x, format, arg...)
int i2cBlockProcessCall(unsigned handle, unsigned reg, char *buf, unsigned count)
uint32_t rawWaveGetIn(int pos)
static uint32_t dmaTickAdr(int pos)
#define PI_MAX_DMA_CHANNEL
static uint32_t sockNetAddr[MAX_CONNECT_ADDRESSES]
static unsigned old_mode_miso
int i2cReadByteData(unsigned handle, unsigned reg)
#define PI_I2C_SMBUS_I2C_BLOCK_MAX
static wfRx_t wfRx[PI_MAX_USER_GPIO+1]
#define PI_HW_CLK_MIN_FREQ
void(* gpioSignalFunc_t)(int signum)
int i2cReadBlockData(unsigned handle, unsigned reg, char *buf)
int i2cClose(unsigned handle)
void(* eventFuncEx_t)(int event, uint32_t tick, void *userdata)
static volatile uint32_t gFilterBits
#define PI_THREAD_STARTED
static void spiACS(int channel, int on)
#define PI_FILE_NOT_WOPEN
#define PI_SPI_FLAGS_GET_RX_LSB(x)
#define AUXSPI_CNTL0_CLR_FIFOS
#define PI_CFG_NOSIGHANDLER
#define PI_SER_OPEN_FAILED
#define PI_I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
static struct timespec libStarted
static gpioISR_t gpioISR[PI_MAX_GPIO+1]
#define AUXSPI_CNTL0_ENABLE
static const clkCfg_t clkCfg[]
static unsigned old_mode_ce1
#define PI_CFG_RT_PRIORITY
static void * pthFifoThread(void *x)
static void initPCM(unsigned bits)
#define PI_DEFAULT_SOCKET_PORT
#define PI_BAD_SHELL_STATUS
#define PI_BB_SER_MAX_BAUD
#define PCM_DREQ_TX_PANIC(x)
static void scrSwap(int *v1, int *v2)
static int pthSocketRunning
unsigned DMAsecondaryChannel
static void sigHandler(int signum)
#define PI_MIN_DUTYCYCLE_RANGE
#define PI_I2C_READ_FAILED
static void chainSetVal(int n, uint32_t val)
static int initPeripherals(void)
int gpioNotifyClose(unsigned handle)
void time_sleep(double seconds)
static unsigned old_mode_ace0
#define MB_LOCK_MEMORY_TAG
static void set_CS(wfRx_t *w)
int myScriptNameValid(char *name)
#define PI_WAVE_MODE_REPEAT_SYNC
#define DMA_DEBUG_FIFO_ERR
#define DBG(level, format, arg...)
int gpioScriptStatus(unsigned script_id, uint32_t *param)
static int chooseBestClock(clkInf_t *clkInf, unsigned f, unsigned numc, unsigned *cf)
uint32_t gpioRead_Bits_32_53(void)
static int scrEvtWait(gpioScript_t *s, uint32_t bits)
int gpioTime(unsigned timetype, int *seconds, int *micros)
#define PI_BAD_MALLOC_MODE
#define PI_DEFAULT_UPDATE_MASK_UNKNOWN
#define PI_I2C_RDRW_IOCTL_MAX_MSGS
static uint32_t dmaReadLevelsAdr(int pos)
static void myGpioSleep(int seconds, int micros)
#define PI_MIN_SERVO_PULSEWIDTH
static void alertWdogCheck(gpioSample_t *sample, int numSamples)
static int pthAlertRunning
static rawCbs_t * dmaCB2adr(int pos)
int eventMonitor(unsigned handle, uint32_t bits)
#define PI_HW_PWM_MAX_FREQ
static void sigSetHandler(void)
static void myGpioSetMode(unsigned gpio, unsigned mode)
#define PI_BAD_SECO_CHANNEL
static uint32_t dmaGpioOffAdr(int pos)
static uint32_t * initMapMem(int fd, uint32_t addr, uint32_t len)
static void initReleaseResources(void)
int fileWrite(unsigned handle, char *buf, unsigned count)
int gpioSetISRFunc(unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f)
#define PI_FILE_NOT_ROPEN
#define PI_MIN_WAVE_DATABITS
#define PI_MIN_WAVE_HALFSTOPBITS
static int my_smbus_access(int fd, char rw, uint8_t cmd, int size, union my_smbus_data *data)
cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Fri Aug 2 2024 09:40:56