Rev 1202 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1202 | Rev 1466 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | * ... |
2 | * ... |
| 3 | * |
3 | * |
| 4 | * @author Linus |
4 | * @author Linus Lundin, Anders Runeson |
| 5 | * |
5 | * |
| 6 | * @date 2009-03-01 |
6 | * @date 2009-03-01 |
| 7 | */ |
7 | */ |
| 8 | 8 | ||
| 9 | /*----------------------------------------------------------------------------- |
9 | /*----------------------------------------------------------------------------- |
| Line 23... | Line 23... | ||
| 23 | * Globals |
23 | * Globals |
| 24 | *---------------------------------------------------------------------------*/ |
24 | *---------------------------------------------------------------------------*/ |
| 25 | 25 | ||
| 26 | struct { |
26 | struct { |
| 27 | uint8_t pcintBit; |
27 | uint8_t pcintBit; |
| - | 28 | uint8_t pcintMask; |
|
| 28 | uint8_t lastStatus; |
29 | uint8_t lastStatus; |
| 29 | pcintCallback_t callback; |
30 | pcintCallback_t callback; |
| 30 | } pcints[PCINT_NUM_PCINTS]; |
31 | } pcints[PCINT_NUM_PCINTS]; |
| 31 | 32 | ||
| 32 | /*----------------------------------------------------------------------------- |
33 | /*----------------------------------------------------------------------------- |
| Line 48... | Line 49... | ||
| 48 | /* Check which pin that have had a change and call the callback.*/ |
49 | /* Check which pin that have had a change and call the callback.*/ |
| 49 | //printf("I\n"); |
50 | //printf("I\n"); |
| 50 | for (p = 0; p < PCINT_NUM_PCINTS; p++) |
51 | for (p = 0; p < PCINT_NUM_PCINTS; p++) |
| 51 | { |
52 | { |
| 52 | if (pcints[p].pcintBit < 8) { |
53 | if (pcints[p].pcintBit < 8) { |
| 53 | if (pcints[p].lastStatus != (rPinB & |
54 | if (pcints[p].lastStatus != (rPinB & pcints[p].pcintMask)) { |
| 54 | pcints[p].lastStatus = (rPinB & |
55 | pcints[p].lastStatus = (rPinB & pcints[p].pcintMask); |
| 55 | pcints[p].callback(p, pcints[p].lastStatus); |
56 | pcints[p].callback(p, pcints[p].lastStatus); |
| 56 | } |
57 | } |
| 57 | } else if (pcints[p].pcintBit < 16) { |
58 | } else if (pcints[p].pcintBit < 16) { |
| 58 | if (pcints[p].lastStatus != (rPinC & |
59 | if (pcints[p].lastStatus != (rPinC & pcints[p].pcintMask)) { |
| 59 | pcints[p].lastStatus = (rPinC & |
60 | pcints[p].lastStatus = (rPinC & pcints[p].pcintMask); |
| 60 | pcints[p].callback(p, pcints[p].lastStatus); |
61 | pcints[p].callback(p, pcints[p].lastStatus); |
| 61 | } |
62 | } |
| 62 | } else if (pcints[p].pcintBit < 24) { |
63 | } else if (pcints[p].pcintBit < 24) { |
| 63 | if (pcints[p].lastStatus != (rPinD & |
64 | if (pcints[p].lastStatus != (rPinD & pcints[p].pcintMask)) { |
| 64 | pcints[p].lastStatus = (rPinD & |
65 | pcints[p].lastStatus = (rPinD & pcints[p].pcintMask); |
| 65 | pcints[p].callback(p, pcints[p].lastStatus); |
66 | pcints[p].callback(p, pcints[p].lastStatus); |
| 66 | } |
67 | } |
| 67 | } |
68 | } |
| 68 | } |
69 | } |
| 69 | 70 | ||
| Line 104... | Line 105... | ||
| 104 | uint8_t sreg = SREG; |
105 | uint8_t sreg = SREG; |
| 105 | cli(); |
106 | cli(); |
| 106 | 107 | ||
| 107 | PCIFR=(1<<PCIF0|1<<PCIF1|1<<PCIF2); /* clear any pending interrupt before enabling interrupts */ |
108 | PCIFR=(1<<PCIF0|1<<PCIF1|1<<PCIF2); /* clear any pending interrupt before enabling interrupts */ |
| 108 | PCICR|=(1<<PCIE0|1<<PCIE1|1<<PCIE2); /* enable interrupt for PCINT0-2 */ |
109 | PCICR|=(1<<PCIE0|1<<PCIE1|1<<PCIE2); /* enable interrupt for PCINT0-2 */ |
| 109 | #if 0 |
110 | |
| 110 | PCIFR=(1<<PCIF1); /* clear any pending interrupt before enabling interrupts */ |
- | |
| 111 | PCICR|=(1<<PCIE1); /* enable interrupt for PCINT1 */ |
- | |
| 112 | PCIFR=(1<<PCIF2); /* clear any pending interrupt before enabling interrupts */ |
- | |
| 113 | PCICR|=(1<<PCIE2); /* enable interrupt for PCINT2 */ |
- | |
| 114 | #endif |
- | |
| 115 | pcints[pcint_id].pcintBit = pcintBit; |
111 | pcints[pcint_id].pcintBit = pcintBit; |
| - | 112 | pcints[pcint_id].pcintMask = 1<<pcints[pcint_id].pcintBit%8; |
|
| 116 | pcints[pcint_id].lastStatus = 0; |
113 | pcints[pcint_id].lastStatus = 0; |
| 117 | if (callback != 0) { |
114 | if (callback != 0) { |
| 118 | if (pcints[pcint_id].pcintBit < 8) { |
115 | if (pcints[pcint_id].pcintBit < 8) { |
| 119 | pcints[pcint_id].lastStatus = (PINB & |
116 | pcints[pcint_id].lastStatus = (PINB & pcints[pcint_id].pcintMask); |
| 120 | PCMSK0 |= |
117 | PCMSK0 |= pcints[pcint_id].pcintMask; |
| 121 | //printf("PCMSK %u\n", PCMSK0); |
118 | //printf("PCMSK %u\n", PCMSK0); |
| 122 | } else if (pcints[pcint_id].pcintBit < 16) { |
119 | } else if (pcints[pcint_id].pcintBit < 16) { |
| 123 | pcints[pcint_id].lastStatus = (PINC & |
120 | pcints[pcint_id].lastStatus = (PINC & pcints[pcint_id].pcintMask); |
| 124 | PCMSK1 |= |
121 | PCMSK1 |= pcints[pcint_id].pcintMask; |
| 125 | //printf("PCMSK1 %u\n", PCMSK1); |
122 | //printf("PCMSK1 %u\n", PCMSK1); |
| 126 | } else if (pcints[pcint_id].pcintBit < 24) { |
123 | } else if (pcints[pcint_id].pcintBit < 24) { |
| 127 | pcints[pcint_id].lastStatus = (PIND & |
124 | pcints[pcint_id].lastStatus = (PIND & pcints[pcint_id].pcintMask); |
| 128 | PCMSK2 |= |
125 | PCMSK2 |= pcints[pcint_id].pcintMask; |
| 129 | //printf("PCMSK2 %u\n", PCMSK2); |
126 | //printf("PCMSK2 %u\n", PCMSK2); |
| 130 | } |
127 | } |
| 131 | } else { //turn off interupt |
128 | } else { //turn off interupt |
| 132 | if (pcints[pcint_id].pcintBit < 8) { |
129 | if (pcints[pcint_id].pcintBit < 8) { |
| 133 | PCMSK0 &= |
130 | PCMSK0 &= ~pcints[pcint_id].pcintMask; |
| 134 | } else if (pcints[pcint_id].pcintBit < 16) { |
131 | } else if (pcints[pcint_id].pcintBit < 16) { |
| 135 | PCMSK1 &= |
132 | PCMSK1 &= ~pcints[pcint_id].pcintMask; |
| 136 | } else if (pcints[pcint_id].pcintBit < 24) { |
133 | } else if (pcints[pcint_id].pcintBit < 24) { |
| 137 | PCMSK2 &= |
134 | PCMSK2 &= ~pcints[pcint_id].pcintMask; |
| 138 | } |
135 | } |
| 139 | } |
136 | } |
| 140 | 137 | ||
| 141 | pcints[pcint_id].callback = callback; |
138 | pcints[pcint_id].callback = callback; |
| 142 | SREG = sreg; |
139 | SREG = sreg; |