📄 scc.h
字号:
#define DCR_BRG_USE_PCLK 0x02#define DCR_DTRREQ_IS_REQ 0x04#define DCR_AUTO_ECHO 0x08#define DCR_LOCAL_LOOPBACK 0x10#define DCR_DPLL_EDGE_SEARCH 0x20#define DCR_DPLL_ERR_RESET 0x40#define DCR_DPLL_DISAB 0x60#define DCR_DPLL_CLK_BRG 0x80#define DCR_DPLL_CLK_RTxC 0xa0#define DCR_DPLL_FM 0xc0#define DCR_DPLL_NRZI 0xe0/* WR15: INT_CTRL_REG "ICR" */#define ICR_OPTIONREG_SELECT 0x01#define ICR_ENAB_BRG_ZERO_INT 0x02#define ICR_USE_FS_FIFO 0x04#define ICR_ENAB_DCD_INT 0x08#define ICR_ENAB_SYNC_INT 0x10#define ICR_ENAB_CTS_INT 0x20#define ICR_ENAB_UNDERRUN_INT 0x40#define ICR_ENAB_BREAK_INT 0x80/* RR0: STATUS_REG "SR" */#define SR_CHAR_AVAIL 0x01#define SR_BRG_ZERO 0x02#define SR_TX_BUF_EMPTY 0x04#define SR_DCD 0x08#define SR_SYNC_ABORT 0x10#define SR_CTS 0x20#define SR_TX_UNDERRUN 0x40#define SR_BREAK 0x80/* RR1: SPCOND_STATUS_REG "SCSR" */#define SCSR_ALL_SENT 0x01#define SCSR_RESIDUAL_MASK 0x0e#define SCSR_PARITY_ERR 0x10#define SCSR_RX_OVERRUN 0x20#define SCSR_CRC_FRAME_ERR 0x40#define SCSR_END_OF_FRAME 0x80/* RR3: INT_PENDING_REG "IPR" */#define IPR_B_EXTSTAT 0x01#define IPR_B_TX 0x02#define IPR_B_RX 0x04#define IPR_A_EXTSTAT 0x08#define IPR_A_TX 0x10#define IPR_A_RX 0x20/* RR7: FS_FIFO_HIGH_REG "FFHR" */#define FFHR_CNT_MASK 0x3f#define FFHR_IS_FROM_FIFO 0x40#define FFHR_FIFO_OVERRUN 0x80/* RR10: DPLL_STATUS_REG "DSR" */#define DSR_ON_LOOP 0x02#define DSR_ON_LOOP_SENDING 0x10#define DSR_TWO_CLK_MISSING 0x40#define DSR_ONE_CLK_MISSING 0x80/***********************************************************************//* *//* Register Access *//* *//***********************************************************************//* The SCC needs 3.5 PCLK cycles recovery time between to register * accesses. PCLK runs with 8 MHz on an Atari, so this delay is 3.5 * * 125 ns = 437.5 ns. This is too short for udelay(). * 10/16/95: A tstb mfp.par_dt_reg takes 600ns (sure?) and thus should be * quite right */#define scc_reg_delay() \ do { \ if (MACH_IS_MVME16x || MACH_IS_BVME6000 || MACH_IS_MVME147) \ __asm__ __volatile__ ( " nop; nop"); \ else if (MACH_IS_ATARI) \ __asm__ __volatile__ ( "tstb %0" : : "g" (*_scc_del) : "cc" );\ } while (0)extern unsigned char scc_shadow[2][16];/* The following functions should relax the somehow complicated * register access of the SCC. _SCCwrite() stores all written values * (except for WR0 and WR8) in shadow registers for later recall. This * removes the burden of remembering written values as needed. The * extra work of storing the value doesn't count, since a delay is * needed after a SCC access anyway. Additionally, _SCCwrite() manages * writes to WR0 and WR8 differently, because these can be accessed * directly with less overhead. Another special case are WR7 and WR7'. * _SCCwrite automatically checks what of this registers is selected * and changes b0 of WR15 if needed. * * _SCCread() for standard read registers is straightforward, except * for RR2 (split into two "virtual" registers: one for the value * written to WR2 (from the shadow) and one for the vector including * status from RR2, Ch. B) and RR3. The latter must be read from * Channel A, because it reads as all zeros on Ch. B. RR0 and RR8 can * be accessed directly as before. * * The two inline function contain complicated switch statements. But * I rely on regno and final_delay being constants, so gcc can reduce * the whole stuff to just some assembler statements. * * _SCCwrite and _SCCread aren't intended to be used directly under * normal circumstances. The macros SCCread[_ND] and SCCwrite[_ND] are * for that purpose. They assume that a local variable 'port' is * declared and pointing to the port's scc_struct entry. The * variants with "_NB" appended should be used if no other SCC * accesses follow immediatly (within 0.5 usecs). They just skip the * final delay nops. * * Please note that accesses to SCC registers should only take place * when interrupts are turned off (at least if SCC interrupts are * enabled). Otherwise, an interrupt could interfere with the * two-stage accessing process. * */static __inline__ void _SCCwrite( struct scc_port *port, unsigned char *shadow, volatile unsigned char *_scc_del, int regno, unsigned char val, int final_delay ){ switch( regno ) { case COMMAND_REG: /* WR0 can be written directly without pointing */ *port->ctrlp = val; break; case SYNC_CHAR_REG: /* For WR7, first set b0 of WR15 to 0, if needed */ if (shadow[INT_CTRL_REG] & ICR_OPTIONREG_SELECT) { *port->ctrlp = 15; shadow[INT_CTRL_REG] &= ~ICR_OPTIONREG_SELECT; scc_reg_delay(); *port->ctrlp = shadow[INT_CTRL_REG]; scc_reg_delay(); } goto normal_case; case SDLC_OPTION_REG: /* For WR7', first set b0 of WR15 to 1, if needed */ if (!(shadow[INT_CTRL_REG] & ICR_OPTIONREG_SELECT)) { *port->ctrlp = 15; shadow[INT_CTRL_REG] |= ICR_OPTIONREG_SELECT; scc_reg_delay(); *port->ctrlp = shadow[INT_CTRL_REG]; scc_reg_delay(); } *port->ctrlp = 7; shadow[8] = val; /* WR7' shadowed at WR8 */ scc_reg_delay(); *port->ctrlp = val; break; case TX_DATA_REG: /* WR8 */ /* TX_DATA_REG can be accessed directly on some h/w */ if (MACH_IS_MVME16x || MACH_IS_BVME6000 || MACH_IS_MVME147) { *port->ctrlp = regno; scc_reg_delay(); *port->ctrlp = val; } else *port->datap = val; break; case MASTER_INT_CTRL: *port->ctrlp = regno; val &= 0x3f; /* bits 6..7 are the reset commands */ scc_shadow[0][regno] = val; scc_reg_delay(); *port->ctrlp = val; break; case DPLL_CTRL_REG: *port->ctrlp = regno; val &= 0x1f; /* bits 5..7 are the DPLL commands */ shadow[regno] = val; scc_reg_delay(); *port->ctrlp = val; break; case 1 ... 6: case 10 ... 13: case 15: normal_case: *port->ctrlp = regno; shadow[regno] = val; scc_reg_delay(); *port->ctrlp = val; break; default: printk( "Bad SCC write access to WR%d\n", regno ); break; } if (final_delay) scc_reg_delay();}static __inline__ unsigned char _SCCread( struct scc_port *port, unsigned char *shadow, volatile unsigned char *_scc_del, int regno, int final_delay ){ unsigned char rv; switch( regno ) { /* --- real read registers --- */ case STATUS_REG: rv = *port->ctrlp; break; case INT_PENDING_REG: /* RR3: read only from Channel A! */ port = port->port_a; goto normal_case; case RX_DATA_REG: /* RR8 can be accessed directly on some h/w */ if (MACH_IS_MVME16x || MACH_IS_BVME6000 || MACH_IS_MVME147) { *port->ctrlp = 8; scc_reg_delay(); rv = *port->ctrlp; } else rv = *port->datap; break; case CURR_VECTOR_REG: /* RR2 (vector including status) from Ch. B */ port = port->port_b; goto normal_case; /* --- reading write registers: access the shadow --- */ case 1 ... 7: case 10 ... 15: return shadow[regno]; /* no final delay! */ /* WR7' is special, because it is shadowed at the place of WR8 */ case SDLC_OPTION_REG: return shadow[8]; /* no final delay! */ /* WR9 is special too, because it is common for both channels */ case MASTER_INT_CTRL: return scc_shadow[0][9]; /* no final delay! */ default: printk( "Bad SCC read access to %cR%d\n", (regno & 16) ? 'R' : 'W', regno & ~16 ); break; case SPCOND_STATUS_REG: case FS_FIFO_LOW_REG: case FS_FIFO_HIGH_REG: case DPLL_STATUS_REG: normal_case: *port->ctrlp = regno & 0x0f; scc_reg_delay(); rv = *port->ctrlp; break; } if (final_delay) scc_reg_delay(); return rv;}#define SCC_ACCESS_INIT(port) \ unsigned char *_scc_shadow = &scc_shadow[port->channel][0]#define SCCwrite(reg,val) _SCCwrite(port,_scc_shadow,scc_del,(reg),(val),1)#define SCCwrite_NB(reg,val) _SCCwrite(port,_scc_shadow,scc_del,(reg),(val),0)#define SCCread(reg) _SCCread(port,_scc_shadow,scc_del,(reg),1)#define SCCread_NB(reg) _SCCread(port,_scc_shadow,scc_del,(reg),0)#define SCCmod(reg,and,or) SCCwrite((reg),(SCCread(reg)&(and))|(or))#endif /* _SCC_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -