void Encoder::attachInterrupt(void (*callback)(int)) { if(mode == MODE_NOSET) return; if(mode == MODE_CAPTURE && callback != NULL) { if(_pcapUsePulseIN == true) return; if(_pcapfunc[mcn][0] != NULL || _pcapfunc[mcn][1] != NULL || _pcapfunc[mcn][2] != NULL) return; if(interrupt_init(mcn) == false) return; mcsif_Disable(mcn, mdn); io_DisableINT(); _pcapfunc[mcn][0] = callback; _pcapfunc[mcn][1] = callback; _pcapfunc[mcn][2] = callback; io_RestoreINT(); clear_INTSTATUS(mcn); enable_MCINT(mcn, SIFB_CAP1INTBIT); enable_MCINT(mcn, SIFB_CAP2INTBIT); enable_MCINT(mcn, SIFB_CAP3INTBIT); // Enable interrupt option for(int i=0; i<3; i++) { sifIntMode[i](mcn, mdn, MCPFAU_CAP_BOTH_CLEAR); sifSetInt[i](mcn, mdn, 1L); } mcsif_Enable(mcn, mdn); _pcapAttchINT = true; return; } if(callback != NULL) { if(_encfunc[mcn] != NULL) return; if(interrupt_init(mcn) == false) return; mcsif_Disable(mcn, mdn); io_DisableINT(); _encfunc[mcn] = callback; io_RestoreINT(); clear_INTSTATUS(mcn); enable_MCINT(mcn, SIFB_TRIGRESETBIT); enable_MCINT(mcn, SIFB_USEREVTBIT); // Enable interrupt option mcenc_SetCapInterval(mcn, mdn, 1L); mcsif_Enable(mcn, mdn); } }
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { int i; unsigned short crossbar_ioaddr; if(interruptNum >= EXTERNAL_NUM_INTERRUPTS) { printf("This interrupt%d has no one pin to use\n", interruptNum); return; } mc = interruptNum/3; md = MCSIF_MODULEB; if(_userfunc[interruptNum] != NULL) return; if(interrupt_init() == false) return; mcmsif_init(); clear_INTSTATUS(); enable_MCINT(0xfc); // SIFB FAULT INT3/2/1 + STAT3/2/1 = 6 bits crossbar_ioaddr = sb_Read16(0x64)&0xfffe; if (mc == 0) io_outpb(crossbar_ioaddr + 2, 0x01); // GPIO port2: 0A, 0B, 0C, 3A else if (mc == 1) io_outpb(crossbar_ioaddr + 3, 0x02); // GPIO port3: 1A, 1B, 1C, 3B else if(mc == 2) io_outpb(crossbar_ioaddr, 0x03); // GPIO port0: 2A, 2B, 2C, 3C else if(mc == 3) { io_outpb(crossbar_ioaddr + 2, 0x01); io_outpb(crossbar_ioaddr + 3, 0x02); io_outpb(crossbar_ioaddr, 0x03); } mcsif_Disable(mc, md); io_DisableINT(); _userfunc[interruptNum] = userFunc; io_RestoreINT(); switch (mode) { case LOW: sifSetPol[interruptNum%3](mc, md, MCPFAU_POL_INVERSE); sifSetMask[interruptNum%3](mc, md, MCPFAU_MASK_INACTIVE); sifSetRelease[interruptNum%3](mc, md, MCPFAU_FAURELS_FSTAT0); sifClearStat[interruptNum%3](mc, md); _usedMode[mc][interruptNum%3] = MCPFAU_CAP_LEVEL0; clear_INTSTATUS(); break; case HIGH: sifSetMask[interruptNum%3](mc, md, MCPFAU_MASK_INACTIVE); sifSetRelease[interruptNum%3](mc, md, MCPFAU_FAURELS_FSTAT0); sifClearStat[interruptNum%3](mc, md); _usedMode[mc][interruptNum%3] = MCPFAU_CAP_LEVEL1; clear_INTSTATUS(); break; case CHANGE: sifIntMode[interruptNum%3](mc, md, MCPFAU_CAP_BOTH); _usedMode[mc][interruptNum%3] = MCPFAU_CAP_BOTH; break; case FALLING: sifIntMode[interruptNum%3](mc, md, MCPFAU_CAP_1TO0); _usedMode[mc][interruptNum%3] = MCPFAU_CAP_1TO0; break; case RISING: sifIntMode[interruptNum%3](mc, md, MCPFAU_CAP_0TO1); _usedMode[mc][interruptNum%3] = MCPFAU_CAP_0TO1; break; default: printf("No support this mode\n"); return; } // switch crossbar to MCM_SIF_PIN io_outpb(crossbar_ioaddr + 0x90 + pin_offset[interruptNum], 0x08);//RICH IO mcsif_Enable(mc, md); // If select level-trigger, switch the MASK to "NONE" after sif is enabled. switch (mode) { case LOW: case HIGH: sifSetMask[interruptNum%3](mc, md, MCPFAU_MASK_NONE); break; default: break; } }
void attachInterrupt(uint8_t interruptNum, void (*userCallBackFunc)(void), int mode) { unsigned short crossbar_ioaddr; if(interruptNum >= EXTERNAL_NUM_INTERRUPTS) { printf("This interrupt%d has no one pin to use\n", interruptNum); return; } mc = PIN86[INTPINSMAP[interruptNum]].ENCMC; md = PIN86[INTPINSMAP[interruptNum]].ENCMD; if(PIN86[INTPINSMAP[interruptNum]].userfunc != NULL) return; if(interrupt_init() == false) return; mcmsif_init(); clear_INTSTATUS(); enable_MCINT(0xfc); // SIFB FAULT INT3/2/1 + STAT3/2/1 = 6 bits crossbar_ioaddr = sb_Read16(0x64)&0xfffe; mcsif_Disable(mc, md); io_DisableINT(); PIN86[INTPINSMAP[interruptNum]].userfunc = userCallBackFunc; io_RestoreINT(); switch (mode) { case LOW: sifSetPol[interruptNum%3](mc, md, MCPFAU_POL_INVERSE); sifSetMask[interruptNum%3](mc, md, MCPFAU_MASK_INACTIVE); sifSetRelease[interruptNum%3](mc, md, MCPFAU_FAURELS_FSTAT0); sifClearStat[interruptNum%3](mc, md); _usedMode[mc][interruptNum%3] = MCPFAU_CAP_LEVEL0; clear_INTSTATUS(); break; case HIGH: sifSetMask[interruptNum%3](mc, md, MCPFAU_MASK_INACTIVE); sifSetRelease[interruptNum%3](mc, md, MCPFAU_FAURELS_FSTAT0); sifClearStat[interruptNum%3](mc, md); _usedMode[mc][interruptNum%3] = MCPFAU_CAP_LEVEL1; clear_INTSTATUS(); break; case CHANGE: sifIntMode[interruptNum%3](mc, md, MCPFAU_CAP_BOTH); _usedMode[mc][interruptNum%3] = MCPFAU_CAP_BOTH; break; case FALLING: sifIntMode[interruptNum%3](mc, md, MCPFAU_CAP_1TO0); _usedMode[mc][interruptNum%3] = MCPFAU_CAP_1TO0; break; case RISING: sifIntMode[interruptNum%3](mc, md, MCPFAU_CAP_0TO1); _usedMode[mc][interruptNum%3] = MCPFAU_CAP_0TO1; break; default: printf("No support this mode\n"); return; } // switch crossbar to MCM_SIF_PIN io_outpb(crossbar_ioaddr + 0x90 + PIN86[INTPINSMAP[interruptNum]].gpN, 0x08);//RICH IO mcsif_Enable(mc, md); // If select level-trigger, switch the MASK to "NONE" after sif is enabled. switch (mode) { case LOW: case HIGH: sifSetMask[interruptNum%3](mc, md, MCPFAU_MASK_NONE); break; default: break; } }