📄 binio.c
字号:
BINIO_SetupOutputPort(BINIO_A2, BINIO_HIGH);
BINIO_SetupOutputPort(BINIO_A3, BINIO_HIGH);
BINIO_SetupOutputPort(BINIO_A4, BINIO_HIGH);
BINIO_SetupOutputPort(BINIO_A5, BINIO_HIGH);
BINIO_SetupOutputPort(BINIO_D0, BINIO_HIGH);
BINIO_SetupOutputPort(BINIO_D1, BINIO_HIGH);
BINIO_SetupOutputPort(BINIO_D2, BINIO_HIGH);
BINIO_SetupOutputPort(BINIO_D3, BINIO_HIGH);
BINIO_SetupOutputPort(BINIO_D4, BINIO_HIGH);
BINIO_SetupOutputPort(BINIO_D5, BINIO_HIGH);
BINIO_SetupOutputPort(BINIO_D6, BINIO_HIGH);
BINIO_SetupOutputPort(BINIO_D7, BINIO_HIGH);
#endif
BINIO_SetupInputPort(BINIO_DOWNLOAD);
#ifdef DE9901_BOARD
/* User defined signals. */
BINIO_SetupInputPort(BINIO_BIN1);
BINIO_SetupInputPort(BINIO_BIN2);
BINIO_SetupInputPort(BINIO_BIN3);
BINIO_SetupInputPort(BINIO_BIN4);
BINIO_SetupInputPort(BINIO_BIN5);
BINIO_SetupInputPort(BINIO_SPI_SO); /* Not used */
/* The following signals are used for handshaking on the MASC serial port. */
/* This must be handled by the user application since it is not supported in eCos */
/* in the current version of eCos package for DE9901. */
BINIO_SetupInputPort(BINIO_RTS); /* MASC port RTS line */
BINIO_SetupInputPort(BINIO_DTR); /* MASC port DTR line */
BINIO_SetupOutputPort(BINIO_CTS, BINIO_HIGH); /* MASC port output */
BINIO_SetupOutputPort(BINIO_DCD, BINIO_HIGH); /* MASC port output */
BINIO_SetupOutputPort(BINIO_DSR, BINIO_HIGH); /* MASC port output */
BINIO_SetupOutputPort(BINIO_RI, BINIO_HIGH); /* MASC port output */
#endif
#ifdef EB40A_BOARD
BINIO_SetupInputPort(BINIO_SW2);
BINIO_SetupInputPort(BINIO_SW3);
BINIO_SetupInputPort(BINIO_SW4);
#endif
/* I2C lines */
BINIO_SetupOutputPort(BINIO_SDA, BINIO_HIGH); /* I2C Data line */
BINIO_SetupOutputPort(BINIO_SCL, BINIO_HIGH); /* I2C Clock line */
/* A dummy read of the interrupt status register */
intReg = INPUT32(PIO_ISR);
/* Setup interrupt to be handled by eCos. */
cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_PIO, BINIO_ISR_PRIO, 0, BINIO_IsrStart, BINIO_Dsr, &isrHandle, &isr);
cyg_drv_interrupt_attach(isrHandle);
cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_PIO);
}
/****************************************************************************
* ROUTINE: BINIO_ReadPort
* DESCRIPTION: Reads the value of one port of the binary I/O module.
****************************************************************************/
BINIO_State_t BINIO_ReadPort(BINIO_Port_t port) {
u32 portData;
portData = INPUT32(PIO_PDSR);
return (BINIO_State_t)((portData >> (port % 32)) & 0x01);
}
/****************************************************************************
* ROUTINE: BINIO_SetPort
* DESCRIPTION: Sets the ouput value of a port.
****************************************************************************/
void BINIO_SetPort(BINIO_Port_t port, BINIO_State_t state) {
u32 bitMask = 0x00000001;
if (BINIO_OUT != BINIO_ReadDirection(port)) {
return;
}
/* Calculate the bit pattern for the register */
bitMask = bitMask << (port % 32);
/* Set the new state of the requested port */
if (state) {
OUTPUT32(PIO_SODR, bitMask);
} else {
OUTPUT32(PIO_CODR, bitMask);
}
PrintEvent("pio %d=%d", port, state);
}
/****************************************************************************
* ROUTINE: BINIO_Isr
* DESCRIPTION: Interrupt service routine for BINIO interrupts.
* The real handle of interrupts are done in the DSR.
****************************************************************************/
cyg_uint32 BINIO_Isr(cyg_vector_t vector, cyg_addrword_t data) {
cyg_drv_interrupt_mask(vector);
cyg_drv_interrupt_acknowledge(vector);
return (CYG_ISR_CALL_DSR);
}
/****************************************************************************
* ROUTINE: BINIO_Dsr
* DESCRIPTION: Interrupt service routine for BINIO interrupts.
* The DSR is called from eCos to handle interrupts instead of doing it
* directly in the ISR. The DSR is called from the scheduler and can therefore
* be interrupted by other interrupts with higher priority.
* The function checks which port that generated the interrupt
* and calls appropriate function.
****************************************************************************/
static void BINIO_Dsr(cyg_vector_t vector, cyg_ucount32 dsrCount, cyg_addrword_t dsrData) {
u32 intReg, intEn, portData, v, s;
s16 i;
intReg = INPUT32(PIO_ISR); /* Read which ports has triggered interrupt. */
intEn = INPUT32(PIO_IMR); /* Read which ports has interrupt enabled. */
portData = INPUT32(PIO_PDSR); /* Read status of all input lines. */
v = 1;
for (i=0; i<32; i++) {
/* Only check ports that has interrupt enabled. */
if (intEn & v) {
if (intReg & v) {
s = (portData & v ? 1 : 0);
PrintEvent("pio %d=%d", i, s);
/* If we receive 2 interrupts and the value of the input port is the same */
/* both times, we probably are trigging spurious interrupts on that port. */
/* Disable interrupt on that port and print a warning. */
if (lastInValue[i] == s) {
BINIO_EnableBinioInterrupt(i, FALSE);
Print("Spurious interrupt on port %d, interrupt is disabled.\n", i);
}
lastInValue[i] = s;
}
}
v = v << 1;
}
cyg_drv_interrupt_unmask(vector);
return;
}
/****************************************************************************
* ROUTINE: BINIO_EnableBinioInterrupt
* DESCRIPTION: Enables/Disables interrupts for a requested BINIO port.
* Interrupts are triggered on both positive and negative
* transitions of the input.
****************************************************************************/
void BINIO_EnableBinioInterrupt(BINIO_Port_t port, bool enable) {
u32 bitMask = 0x00000001;
/* Calculate the bit pattern for the register */
bitMask = bitMask << (port % 32);
if (enable) {
/* Set the interrupt mask for the requested port */
OUTPUT32(PIO_IER, bitMask);
} else {
/* Reset the interrupt mask for the requested port */
OUTPUT32(PIO_IDR, bitMask);
}
}
/****************************************************************************
* ROUTINE: BINIO_EnableBinioFilter
* DESCRIPTION: Enables/Disables interrupts for a requested BINIO port.
* Interrupts are triggered on both positive and negative
* transitions of the input.
****************************************************************************/
void BINIO_EnableBinioFilter(BINIO_Port_t port, bool enable) {
u32 bitMask = 0x00000001;
/* Calculate the bit pattern for the register */
bitMask = bitMask << (port % 32);
if (enable) {
/* Set the filter mask for the requested port */
OUTPUT32(PIO_IFER, bitMask);
} else {
/* Reset the filter mask for the requested port */
OUTPUT32(PIO_IFDR, bitMask);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -