ih_twi.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00076 #include <dev/irqreg.h>
00077
00082
00083 #if defined(SIG_2WIRE_SERIAL) || defined(iv_TWI)
00084
00085 static int AvrTwiIrqCtl(int cmd, void *param);
00086
00087 IRQ_HANDLER sig_2WIRE_SERIAL = {
00088 #ifdef NUT_PERFMON
00089 0,
00090 #endif
00091 NULL,
00092 NULL,
00093 AvrTwiIrqCtl
00094 };
00095
00111 static int AvrTwiIrqCtl(int cmd, void *param)
00112 {
00113 int rc = 0;
00114 unsigned int *ival = (unsigned int *) param;
00115 int_fast8_t enabled = bit_is_set(TWCR, TWIE);
00116 uint8_t bval;
00117
00118
00119 cbi(TWCR, TWIE);
00120
00121 switch (cmd) {
00122 case NUT_IRQCTL_INIT:
00123 enabled = 0;
00124 case NUT_IRQCTL_CLEAR:
00125
00126 if (bit_is_set(SPSR, SPIF)) {
00127 bval = inb(SPDR);
00128 }
00129 break;
00130 case NUT_IRQCTL_STATUS:
00131 if (bit_is_set(TWCR, TWINT)) {
00132 *ival = 1;
00133 } else {
00134 *ival = 0;
00135 }
00136 if (enabled) {
00137 *ival |= 0x80;
00138 }
00139 break;
00140 case NUT_IRQCTL_ENABLE:
00141 enabled = 1;
00142 break;
00143 case NUT_IRQCTL_DISABLE:
00144 enabled = 0;
00145 break;
00146 case NUT_IRQCTL_GETPRIO:
00147 *ival = 16;
00148 break;
00149 #ifdef NUT_PERFMON
00150 case NUT_IRQCTL_GETCOUNT:
00151 *ival = (unsigned int) sig_2WIRE_SERIAL.ir_count;
00152 sig_2WIRE_SERIAL.ir_count = 0;
00153 break;
00154 #endif
00155 default:
00156 rc = -1;
00157 break;
00158 }
00159
00160
00161 if (enabled) {
00162 sbi(TWCR, TWIE);
00163 }
00164 return rc;
00165 }
00166
00170 #ifdef __IMAGECRAFT__
00171 #pragma interrupt_handler SIG_2WIRE_SERIAL:iv_TWI
00172 #endif
00173 NUTSIGNAL(SIG_2WIRE_SERIAL, sig_2WIRE_SERIAL)
00174 #endif
00175