Rev 1134 | Rev 1137 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1134 | Rev 1136 | ||
|---|---|---|---|
| Line 7... | Line 7... | ||
| 7 | */ |
7 | */ |
| 8 | 8 | ||
| 9 | /*----------------------------------------------------------------------------- |
9 | /*----------------------------------------------------------------------------- |
| 10 | * Includes |
10 | * Includes |
| 11 | *---------------------------------------------------------------------------*/ |
11 | *---------------------------------------------------------------------------*/ |
| - | 12 | ||
| - | 13 | #include <config.h> |
|
| - | 14 | #if PCINT_NUM_PCINTS > 0 |
|
| - | 15 | ||
| 12 | #include <inttypes.h> |
16 | #include <inttypes.h> |
| 13 | #include <avr/io.h> |
17 | #include <avr/io.h> |
| 14 | #include <avr/interrupt.h> |
18 | #include <avr/interrupt.h> |
| 15 | 19 | ||
| 16 | #include <drivers/mcu/pcint.h> |
20 | #include <drivers/mcu/pcint.h> |
| 17 | 21 | ||
| 18 | /*----------------------------------------------------------------------------- |
22 | /*----------------------------------------------------------------------------- |
| 19 | * Globals |
23 | * Globals |
| 20 | *---------------------------------------------------------------------------*/ |
24 | *---------------------------------------------------------------------------*/ |
| 21 | 25 | ||
| 22 | struct { |
26 | struct { |
| 23 | uint8_t pcintBit; |
27 | uint8_t pcintBit; |
| 24 |
|
28 | uint8_t lastStatus; |
| 25 | pcintCallback_t callback; |
29 | pcintCallback_t callback; |
| 26 | } pcints[PCINT_NUM_PCINTS]; |
30 | } pcints[PCINT_NUM_PCINTS]; |
| 27 | - | ||
| 28 | uint32_t pinLastStatus; |
- | |
| 29 | 31 | ||
| 30 | /*----------------------------------------------------------------------------- |
32 | /*----------------------------------------------------------------------------- |
| 31 | * Interrupt Service Routines |
33 | * Interrupt Service Routines |
| 32 | *---------------------------------------------------------------------------*/ |
34 | *---------------------------------------------------------------------------*/ |
| 33 | 35 | ||
| Line 38... | Line 40... | ||
| 38 | Returns: - |
40 | Returns: - |
| 39 | **************************************************************************/ |
41 | **************************************************************************/ |
| 40 | ISR(PCINT0_vect) { |
42 | ISR(PCINT0_vect) { |
| 41 | uint8_t p; |
43 | uint8_t p; |
| 42 | 44 | ||
| 43 | uint32_t pin = ((uint32_t)PIND<<16)|((uint32_t)PINC<<8)|(PINB); |
- | |
| 44 | /* Check which pin that have had a change and call the callback.*/ |
45 | /* Check which pin that have had a change and call the callback.*/ |
| 45 | //printf("I\n"); |
46 | //printf("I\n"); |
| 46 | for (p = 0; p < PCINT_NUM_PCINTS; p++) |
47 | for (p = 0; p < PCINT_NUM_PCINTS; p++) |
| 47 | { |
48 | { |
| 48 | if (pinLastStatus != ((pin & (1 << pcints[p].pcintBit)) != 0)) { |
- | |
| 49 | pcints[p].callback(p); |
- | |
| 50 | } |
- | |
| 51 | - | ||
| 52 |
|
49 | if (pcints[p].pcintBit < 8) { |
| 53 | if (pcints[p].lastStatus != ((PINB & (1 << pcints[p].pcintBit)) != 0)) { |
50 | if (pcints[p].lastStatus != ((PINB & (1 << pcints[p].pcintBit)) != 0)) { |
| 54 | pcints[p].lastStatus = ((PINB & (1 << pcints[p].pcintBit)) != 0); |
51 | pcints[p].lastStatus = ((PINB & (1 << pcints[p].pcintBit)) != 0); |
| 55 |
|
52 | pcints[p].callback(p, pcints[p].lastStatus); |
| 56 | } |
53 | } |
| 57 | } else if (pcints[p].pcintBit < 16) { |
54 | } else if (pcints[p].pcintBit < 16) { |
| 58 | if (pcints[p].lastStatus != ((PINC & (1 << pcints[p].pcintBit%8)) != 0)) { |
55 | if (pcints[p].lastStatus != ((PINC & (1 << pcints[p].pcintBit%8)) != 0)) { |
| 59 | pcints[p].lastStatus = ((PINC & (1 << pcints[p].pcintBit%8)) != 0); |
56 | pcints[p].lastStatus = ((PINC & (1 << pcints[p].pcintBit%8)) != 0); |
| 60 |
|
57 | pcints[p].callback(p, pcints[p].lastStatus); |
| 61 | } |
58 | } |
| 62 | } else if (pcints[p].pcintBit < 24) { |
59 | } else if (pcints[p].pcintBit < 24) { |
| 63 | if (pcints[p].lastStatus != ((PIND & (1 << pcints[p].pcintBit%8)) != 0)) { |
60 | if (pcints[p].lastStatus != ((PIND & (1 << pcints[p].pcintBit%8)) != 0)) { |
| 64 | pcints[p].lastStatus = ((PIND & (1 << pcints[p].pcintBit%8)) != 0); |
61 | pcints[p].lastStatus = ((PIND & (1 << pcints[p].pcintBit%8)) != 0); |
| 65 |
|
62 | pcints[p].callback(p, pcints[p].lastStatus); |
| - | 63 | } |
|
| 66 | } |
64 | } |
| 67 | }*/ |
- | |
| 68 | } |
65 | } |
| 69 | 66 | ||
| 70 | pinLastStatus = pin; |
- | |
| 71 | } /* ISR(PCINT0_vect) */ |
67 | } /* ISR(PCINT0_vect) */ |
| 72 | 68 | ||
| 73 | 69 | ||
| 74 | /*********************************************************************//** |
70 | /*********************************************************************//** |
| 75 | Function: ISR(PCINT1_vect) |
71 | Function: ISR(PCINT1_vect) |
| 76 | Purpose: Executed when pin change on PCINT1. |
72 | Purpose: Executed when pin change on PCINT1. |
| 77 | Input: - |
73 | Input: - |
| 78 | Returns: - |
74 | Returns: - |
| 79 | **************************************************************************/ |
75 | **************************************************************************/ |
| 80 | #if ((__GNUC__ == 4 && __GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ > 1)||(__GNUC__ == 4 && __GNUC_MINOR__ > 2)||__GNUC__ > 4) |
76 | #if ((__GNUC__ == 4 && __GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ > 1)||(__GNUC__ == 4 && __GNUC_MINOR__ > 2)||__GNUC__ > 4) |
| 81 | ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect)); |
77 | ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect)); |
| 82 | #else |
78 | #else |
| 83 | ISR_ALIAS(PCINT1_vect, PCINT0_vect); |
79 | ISR_ALIAS(PCINT1_vect, PCINT0_vect); |
| 84 | #endif |
80 | #endif |
| 85 | /*********************************************************************//** |
81 | /*********************************************************************//** |
| 86 | Function: ISR(PCINT0_vect) |
82 | Function: ISR(PCINT0_vect) |
| 87 | Purpose: Executed when pin change on PCINT2. |
83 | Purpose: Executed when pin change on PCINT2. |
| Line 112... | Line 108... | ||
| 112 | PCICR|=(1<<PCIE1); /* enable interrupt for PCINT1 */ |
108 | PCICR|=(1<<PCIE1); /* enable interrupt for PCINT1 */ |
| 113 | PCIFR=(1<<PCIF2); /* clear any pending interrupt before enabling interrupts */ |
109 | PCIFR=(1<<PCIF2); /* clear any pending interrupt before enabling interrupts */ |
| 114 | PCICR|=(1<<PCIE2); /* enable interrupt for PCINT2 */ |
110 | PCICR|=(1<<PCIE2); /* enable interrupt for PCINT2 */ |
| 115 | #endif |
111 | #endif |
| 116 | pcints[pcint_id].pcintBit = pcintBit; |
112 | pcints[pcint_id].pcintBit = pcintBit; |
| 117 |
|
113 | pcints[pcint_id].lastStatus = 0; |
| 118 | if (callback != 0) { |
114 | if (callback != 0) { |
| 119 | if (pcints[pcint_id].pcintBit < 8) { |
115 | if (pcints[pcint_id].pcintBit < 8) { |
| 120 |
|
116 | pcints[pcint_id].lastStatus = ((PINB & (1 << pcints[pcint_id].pcintBit%8)) != 0); |
| 121 | PCMSK0 |= (1<<pcints[pcint_id].pcintBit%8); |
117 | PCMSK0 |= (1<<pcints[pcint_id].pcintBit%8); |
| 122 | //printf("PCMSK %u\n", PCMSK0); |
118 | //printf("PCMSK %u\n", PCMSK0); |
| 123 | } else if (pcints[pcint_id].pcintBit < 16) { |
119 | } else if (pcints[pcint_id].pcintBit < 16) { |
| 124 |
|
120 | pcints[pcint_id].lastStatus = ((PINC & (1 << pcints[pcint_id].pcintBit%8)) != 0); |
| 125 | PCMSK1 |= (1<<pcints[pcint_id].pcintBit%8); |
121 | PCMSK1 |= (1<<pcints[pcint_id].pcintBit%8); |
| 126 | //printf("PCMSK1 %u\n", PCMSK1); |
122 | //printf("PCMSK1 %u\n", PCMSK1); |
| 127 | } else if (pcints[pcint_id].pcintBit < 24) { |
123 | } else if (pcints[pcint_id].pcintBit < 24) { |
| 128 |
|
124 | pcints[pcint_id].lastStatus = ((PIND & (1 << pcints[pcint_id].pcintBit%8)) != 0); |
| 129 | PCMSK2 |= (1<<pcints[pcint_id].pcintBit%8); |
125 | PCMSK2 |= (1<<pcints[pcint_id].pcintBit%8); |
| 130 | //printf("PCMSK2 %u\n", PCMSK2); |
126 | //printf("PCMSK2 %u\n", PCMSK2); |
| 131 | } |
127 | } |
| 132 | } else { //turn off interupt |
128 | } else { //turn off interupt |
| 133 | if (pcints[pcint_id].pcintBit < 8) { |
129 | if (pcints[pcint_id].pcintBit < 8) { |
| 134 | PCMSK0 &= ~(1<<(pcints[pcint_id].pcintBit%8)); |
130 | PCMSK0 &= ~(1<<(pcints[pcint_id].pcintBit%8)); |
| 135 | } else if (pcints[pcint_id].pcintBit < 16) { |
131 | } else if (pcints[pcint_id].pcintBit < 16) { |
| 136 | PCMSK1 &= ~(1<<(pcints[pcint_id].pcintBit%8)); |
132 | PCMSK1 &= ~(1<<(pcints[pcint_id].pcintBit%8)); |
| 137 | } else if (pcints[pcint_id].pcintBit < 24) { |
133 | } else if (pcints[pcint_id].pcintBit < 24) { |
| 138 | PCMSK2 &= ~(1<<(pcints[pcint_id].pcintBit%8)); |
134 | PCMSK2 &= ~(1<<(pcints[pcint_id].pcintBit%8)); |
| 139 | } |
135 | } |
| 140 | } |
136 | } |
| 141 | - | ||
| 142 | uint32_t pinLastStatus = ((uint32_t)PIND<<16)|((uint32_t)PINC<<8)|(PINB); |
- | |
| 143 | 137 | ||
| 144 | pcints[pcint_id].callback = callback; |
138 | pcints[pcint_id].callback = callback; |
| 145 | SREG = sreg; |
139 | SREG = sreg; |
| 146 | } |
140 | } |
| 147 | } |
141 | } |
| - | 142 | ||
| - | 143 | #endif /*PCINT_NUM_PCINTS > 0*/ |
|
| 148 | 144 | ||
| 149 | /*---------------------------------------------------------------------------*/ |
145 | /*---------------------------------------------------------------------------*/ |
| 150 | 146 | ||