rp2040/driver/inc/pio_instr.h

120 lines
9.7 KiB
C

#ifndef __HARDWARE_PIO_INSTR_H__
#define __HARDWARE_PIO_INSTR_H__
#define PIO_INSTR_OP_CODE_POS (13U)
#define PIO_INSTR_JMP_COND_POS (5U)
#define PIO_INSTR_WAIT_SRC_POS (5U)
#define PIO_INSTR_WAIT_POL_POS (7U)
#define PIO_INSTR_IN_SRC_POS (5U)
#define PIO_INSTR_OUT_DEST_POS (5U)
#define PIO_INSTR_PUSH_IFF_POS (6U)
#define PIO_INSTR_PUSH_BLK_POS (5U)
#define PIO_INSTR_PULL_IFE_POS (6U)
#define PIO_INSTR_PULL_BLK_POS (5U)
#define PIO_INSTR_MOV_SRC_POS (0U)
#define PIO_INSTR_MOV_DEST_POS (5U)
#define PIO_INSTR_MOV_OP_POS (3U)
#define PIO_INSTR_IRQ_OP_POS (6U)
#define PIO_INSTR_IRQ_WAIT_POS (5U)
#define PIO_INSTR_SET_DEST_POS (5U)
#define PIO_INSTR_SIDE_POS (8U)
#define PIO_INSTR_OP_CODE_JMP (0 << PIO_INSTR_OP_CODE_POS) /* Set program counter to Address if Condition is true, otherwise no operation */
#define PIO_INSTR_OP_CODE_WAIT (1 << PIO_INSTR_OP_CODE_POS) /* Stall until some condition is met */
#define PIO_INSTR_OP_CODE_IN (2 << PIO_INSTR_OP_CODE_POS) /* Shift Bit count bits from Source into the Input Shift Register (ISR) */
#define PIO_INSTR_OP_CODE_OUT (3 << PIO_INSTR_OP_CODE_POS) /* Shift Bit count bits out of the Output Shift Register (OSR), and write those bits to Destination */
#define PIO_INSTR_OP_CODE_PUSH ((4 << PIO_INSTR_OP_CODE_POS) | (0 << 7U)) /* Push the contents of the ISR into the RX FIFO, as a single 32-bit word. Clear ISR to all-zeroes */
#define PIO_INSTR_OP_CODE_PULL ((4 << PIO_INSTR_OP_CODE_POS) | (1 << 7U)) /* Load a 32-bit word from the TX FIFO into the OSR */
#define PIO_INSTR_OP_CODE_MOV (5 << PIO_INSTR_OP_CODE_POS) /* Copy data from Source to Destination */
#define PIO_INSTR_OP_CODE_IRQ (6 << PIO_INSTR_OP_CODE_POS) /* Set or clear the IRQ flag selected by Index argument */
#define PIO_INSTR_OP_CODE_SET (7 << PIO_INSTR_OP_CODE_POS) /* Write immediate value Data to Destination */
#define PIO_INSTR_JMP_COND_ALWAYS (0 << PIO_INSTR_JMP_COND_POS) /* Always, no condition */
#define PIO_INSTR_JMP_COND_X_ZERO (1 << PIO_INSTR_JMP_COND_POS) /* scratch X zero */
#define PIO_INSTR_JMP_COND_X_WITH_DEC (2 << PIO_INSTR_JMP_COND_POS) /* scratch X non-zero, post-decrement */
#define PIO_INSTR_JMP_COND_Y_ZERO (3 << PIO_INSTR_JMP_COND_POS) /* scratch Y zero */
#define PIO_INSTR_JMP_COND_Y_WITH_DEC (4 << PIO_INSTR_JMP_COND_POS) /* scratch Y non-zero, post-decrement */
#define PIO_INSTR_JMP_COND_X_NEQ_Y (5 << PIO_INSTR_JMP_COND_POS) /* scratch X not equal scratch Y */
#define PIO_INSTR_JMP_COND_PIN (6 << PIO_INSTR_JMP_COND_POS) /* branch on input pin */
#define PIO_INSTR_JMP_COND_OSR_NEMPTY (7 << PIO_INSTR_JMP_COND_POS) /* output shift register not empty */
#define PIO_INSTR_WAIT_SRC_GPIO (0 << PIO_INSTR_WAIT_SRC_POS) /* GPIO: System GPIO input selected by Index */
#define PIO_INSTR_WAIT_SRC_PIN (1 << PIO_INSTR_WAIT_SRC_POS) /* PIN: Input pin selected by Index */
#define PIO_INSTR_WAIT_SRC_IRQ (2 << PIO_INSTR_WAIT_SRC_POS) /* IRQ: PIO IRQ flag selected by Index */
#define PIO_INSTR_WAIT_POL_0 (0 << PIO_INSTR_WAIT_POL_POS) /* wait for a 0 */
#define PIO_INSTR_WAIT_POL_1 (1 << PIO_INSTR_WAIT_POL_POS) /* wait for a 1 */
#define PIO_INSTR_IN_SRC_PINS (0 << PIO_INSTR_IN_SRC_POS) /* */
#define PIO_INSTR_IN_SRC_X (1 << PIO_INSTR_IN_SRC_POS) /* scratch register X */
#define PIO_INSTR_IN_SRC_Y (2 << PIO_INSTR_IN_SRC_POS) /* scratch register Y */
#define PIO_INSTR_IN_SRC_NULL (3 << PIO_INSTR_IN_SRC_POS) /* all zeroes */
#define PIO_INSTR_IN_SRC_ISR (6 << PIO_INSTR_IN_SRC_POS) /* */
#define PIO_INSTR_IN_SRC_OSR (7 << PIO_INSTR_IN_SRC_POS) /* */
#define PIO_INSTR_OUT_DEST_PINS (0 << PIO_INSTR_OUT_DEST_POS) /* */
#define PIO_INSTR_OUT_DEST_X (1 << PIO_INSTR_OUT_DEST_POS) /* scratch register X */
#define PIO_INSTR_OUT_DEST_Y (2 << PIO_INSTR_OUT_DEST_POS) /* scratch register Y */
#define PIO_INSTR_OUT_DEST_NULL (3 << PIO_INSTR_OUT_DEST_POS) /* discard data */
#define PIO_INSTR_OUT_DEST_PINDIRS (4 << PIO_INSTR_OUT_DEST_POS) /* */
#define PIO_INSTR_OUT_DEST_PC (5 << PIO_INSTR_OUT_DEST_POS) /* */
#define PIO_INSTR_OUT_DEST_ISR (6 << PIO_INSTR_OUT_DEST_POS) /* also sets ISR shift counter to Bit count */
#define PIO_INSTR_OUT_DEST_EXEC (7 << PIO_INSTR_OUT_DEST_POS) /* Execute OSR shift data as instruction */
#define PIO_INSTR_PUSH_IFF_DISABLE (0 << PIO_INSTR_PUSH_IFF_POS) /* */
#define PIO_INSTR_PUSH_IFF_ENABLE (1 << PIO_INSTR_PUSH_IFF_POS) /* do nothing unless the total input shift count has reached its threshold */
#define PIO_INSTR_PUSH_BLK_DISABLE (0 << PIO_INSTR_PUSH_BLK_POS) /* */
#define PIO_INSTR_PUSH_BLK_ENABLE (1 << PIO_INSTR_PUSH_BLK_POS) /* stall execution if RX FIFO is full */
#define PIO_INSTR_PULL_IFE_DISABLE (0 << PIO_INSTR_PULL_IFE_POS) /* */
#define PIO_INSTR_PULL_IFE_ENABLE (1 << PIO_INSTR_PULL_IFE_POS) /* do nothing unless the total output shift count has reached its threshold */
#define PIO_INSTR_PULL_BLK_DISABLE (0 << PIO_INSTR_PULL_BLK_POS) /* pulling from an empty FIFO copies scratch X to OSR */
#define PIO_INSTR_PULL_BLK_ENABLE (1 << PIO_INSTR_PULL_BLK_POS) /* stall if TX FIFO is empty */
#define PIO_INSTR_MOV_SRC_PINS (0 << PIO_INSTR_MOV_SRC_POS) /* Uses same pin mapping as IN */
#define PIO_INSTR_MOV_SRC_X (1 << PIO_INSTR_MOV_SRC_POS) /* Scratch register X */
#define PIO_INSTR_MOV_SRC_Y (2 << PIO_INSTR_MOV_SRC_POS) /* Scratch register Y */
#define PIO_INSTR_MOV_SRC_NULL (3 << PIO_INSTR_MOV_SRC_POS) /* */
#define PIO_INSTR_MOV_SRC_STATUS (5 << PIO_INSTR_MOV_SRC_POS) /* */
#define PIO_INSTR_MOV_SRC_ISR (6 << PIO_INSTR_MOV_SRC_POS) /* */
#define PIO_INSTR_MOV_SRC_OSR (7 << PIO_INSTR_MOV_SRC_POS) /* */
#define PIO_INSTR_MOV_DEST_PINS (0 << PIO_INSTR_MOV_DEST_POS) /* Uses same pin mapping as OUT */
#define PIO_INSTR_MOV_DEST_X (1 << PIO_INSTR_MOV_DEST_POS) /* Scratch register X */
#define PIO_INSTR_MOV_DEST_Y (2 << PIO_INSTR_MOV_DEST_POS) /* Scratch register Y */
#define PIO_INSTR_MOV_DEST_EXEC (4 << PIO_INSTR_MOV_DEST_POS) /* Execute data as instruction */
#define PIO_INSTR_MOV_DEST_PC (5 << PIO_INSTR_MOV_DEST_POS) /* */
#define PIO_INSTR_MOV_DEST_ISR (6 << PIO_INSTR_MOV_DEST_POS) /* Input shift counter is reset to 0 by this operation, i.e. empty */
#define PIO_INSTR_MOV_DEST_OSR (7 << PIO_INSTR_MOV_DEST_POS) /* Output shift counter is reset to 0 by this operation, i.e. full */
#define PIO_INSTR_MOV_OP_NONE (0 << PIO_INSTR_MOV_OP_POS) /* */
#define PIO_INSTR_MOV_OP_INVERT (1 << PIO_INSTR_MOV_OP_POS) /* bitwise complement */
#define PIO_INSTR_MOV_OP_BIT_REVERSE (2 << PIO_INSTR_MOV_OP_POS) /* */
#define PIO_INSTR_IRQ_OP_RAISE (0 << PIO_INSTR_IRQ_OP_POS) /* raise the flag selected by Index */
#define PIO_INSTR_IRQ_OP_CLR (1 << PIO_INSTR_IRQ_OP_POS) /* clear the flag selected by Index */
#define PIO_INSTR_IRQ_WAIT_DISABLE (0 << PIO_INSTR_IRQ_WAIT_POS) /* */
#define PIO_INSTR_IRQ_WAIT_ENABLE (1 << PIO_INSTR_IRQ_WAIT_POS) /* halt until the raised flag is lowered again */
#define PIO_INSTR_SET_DEST_PINS (0 << PIO_INSTR_SET_DEST_POS) /* */
#define PIO_INSTR_SET_DEST_X (1 << PIO_INSTR_SET_DEST_POS) /* X (scratch register X) 5 LSBs are set to Data, all others cleared to 0 */
#define PIO_INSTR_SET_DEST_Y (2 << PIO_INSTR_SET_DEST_POS) /* Y (scratch register Y) 5 LSBs are set to Data, all others cleared to 0 */
#define PIO_INSTR_SET_DEST_PINDIRS (4 << PIO_INSTR_SET_DEST_POS) /* */
#define pio_instr_side(side, delay, side_width) ((side << (PIO_INSTR_SIDE_POS + 5 - side_width)) | ((delay) << PIO_INSTR_SIDE_POS))
#define pio_instr_JMP(cond, addr, side) ((PIO_INSTR_OP_CODE_JMP) | (cond) | (addr) | (side))
#define pio_instr_WAIT(src, pol, index, side) ((PIO_INSTR_OP_CODE_WAIT) | (src) | (pol) | (index) | (side))
#define pio_instr_IN(src, bit_count, side) ((PIO_INSTR_OP_CODE_IN) | (src) | ((bit_count) & 0x1F) | (side))
#define pio_instr_OUT(dest, bit_count, side) ((PIO_INSTR_OP_CODE_OUT) | (dest) | ((bit_count) & 0x1F) | (side))
#define pio_instr_PUSH(iff, blk, side) ((PIO_INSTR_OP_CODE_PUSH) | (iff) | (blk) | (side))
#define pio_instr_PULL(ife, blk, side) ((PIO_INSTR_OP_CODE_PULL) | (ife) | (blk) | (side))
#define pio_instr_MOV(dest, src, op, side) ((PIO_INSTR_OP_CODE_MOV) | (dest) | (src) | (op) | (side))
#define pio_instr_IRQ(op, wait, index, side) ((PIO_INSTR_OP_CODE_IRQ) | (op) | (wait) | (index) | (side))
#define pio_instr_SET(dest, data, side) ((PIO_INSTR_OP_CODE_SET) | (dest) | (data) | (side))
#endif /* __HARDWARE_PIO_INSTR_H__ */