Merge "Make fault_isr better for what we do"
diff --git a/motors/button_board.cc b/motors/button_board.cc
index 4064725..2e3e2c1 100644
--- a/motors/button_board.cc
+++ b/motors/button_board.cc
@@ -87,31 +87,31 @@
report0[2] = report1[2] = adc.analog2 / 16;
report0[3] = report1[3] = adc.analog3 / 16;
- report0[4] = ((GPIO_BITBAND(GPIOD_PDIR, 5) << 0) |
- (GPIO_BITBAND(GPIOD_PDIR, 6) << 1) |
- (GPIO_BITBAND(GPIOB_PDIR, 0) << 2) |
- (GPIO_BITBAND(GPIOB_PDIR, 1) << 3) |
- (GPIO_BITBAND(GPIOA_PDIR, 14) << 4) |
- (GPIO_BITBAND(GPIOE_PDIR, 26) << 5) |
- (GPIO_BITBAND(GPIOA_PDIR, 16) << 6) |
- (GPIO_BITBAND(GPIOA_PDIR, 15) << 7)) ^
+ report0[4] = ((PERIPHERAL_BITBAND(GPIOD_PDIR, 5) << 0) |
+ (PERIPHERAL_BITBAND(GPIOD_PDIR, 6) << 1) |
+ (PERIPHERAL_BITBAND(GPIOB_PDIR, 0) << 2) |
+ (PERIPHERAL_BITBAND(GPIOB_PDIR, 1) << 3) |
+ (PERIPHERAL_BITBAND(GPIOA_PDIR, 14) << 4) |
+ (PERIPHERAL_BITBAND(GPIOE_PDIR, 26) << 5) |
+ (PERIPHERAL_BITBAND(GPIOA_PDIR, 16) << 6) |
+ (PERIPHERAL_BITBAND(GPIOA_PDIR, 15) << 7)) ^
0xff;
- report0[5] = ((GPIO_BITBAND(GPIOE_PDIR, 25) << 0) |
- (GPIO_BITBAND(GPIOE_PDIR, 24) << 1) |
- (GPIO_BITBAND(GPIOC_PDIR, 3) << 2) |
- (GPIO_BITBAND(GPIOC_PDIR, 7) << 3) |
- (GPIO_BITBAND(GPIOD_PDIR, 3) << 4) |
- (GPIO_BITBAND(GPIOD_PDIR, 2) << 5) |
- (GPIO_BITBAND(GPIOD_PDIR, 7) << 6) |
- (GPIO_BITBAND(GPIOA_PDIR, 13) << 7)) ^
+ report0[5] = ((PERIPHERAL_BITBAND(GPIOE_PDIR, 25) << 0) |
+ (PERIPHERAL_BITBAND(GPIOE_PDIR, 24) << 1) |
+ (PERIPHERAL_BITBAND(GPIOC_PDIR, 3) << 2) |
+ (PERIPHERAL_BITBAND(GPIOC_PDIR, 7) << 3) |
+ (PERIPHERAL_BITBAND(GPIOD_PDIR, 3) << 4) |
+ (PERIPHERAL_BITBAND(GPIOD_PDIR, 2) << 5) |
+ (PERIPHERAL_BITBAND(GPIOD_PDIR, 7) << 6) |
+ (PERIPHERAL_BITBAND(GPIOA_PDIR, 13) << 7)) ^
0xff;
report1[4] =
- ((GPIO_BITBAND(GPIOA_PDIR, 12) << 0) |
- (GPIO_BITBAND(GPIOD_PDIR, 0) << 1) |
- (GPIO_BITBAND(GPIOB_PDIR, 17) << 2) |
- (GPIO_BITBAND(GPIOB_PDIR, 16) << 3) | (DecodeAnalog(report1[0]) << 4) |
+ ((PERIPHERAL_BITBAND(GPIOA_PDIR, 12) << 0) |
+ (PERIPHERAL_BITBAND(GPIOD_PDIR, 0) << 1) |
+ (PERIPHERAL_BITBAND(GPIOB_PDIR, 17) << 2) |
+ (PERIPHERAL_BITBAND(GPIOB_PDIR, 16) << 3) | (DecodeAnalog(report1[0]) << 4) |
(DecodeAnalog(report1[1]) << 6)) ^
0x0f;
report1[5] = (DecodeAnalog(report1[2])) | (DecodeAnalog(report1[3]) << 2);
@@ -213,37 +213,37 @@
// Set all the LED pins to output, slew rate controlled, high drive strength.
// Builtin
- GPIO_BITBAND(GPIOC_PDOR, 5) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 5) = 1;
PORTC_PCR5 = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(1);
- GPIO_BITBAND(GPIOC_PDDR, 5) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDDR, 5) = 1;
// LED0 FTM0_CH1
- GPIO_BITBAND(GPIOC_PDOR, 2) = 0;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 2) = 0;
PORTC_PCR2 = PORT_PCR_DSE | PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_MUX(4);
- GPIO_BITBAND(GPIOC_PDDR, 2) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDDR, 2) = 1;
// LED1 FTM0_CH0
- GPIO_BITBAND(GPIOC_PDOR, 1) = 0;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 1) = 0;
PORTC_PCR1 = PORT_PCR_DSE | PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_MUX(4);
- GPIO_BITBAND(GPIOC_PDDR, 1) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDDR, 1) = 1;
// LED2 FTM0_CH4
- GPIO_BITBAND(GPIOD_PDOR, 4) = 0;
+ PERIPHERAL_BITBAND(GPIOD_PDOR, 4) = 0;
PORTD_PCR4 = PORT_PCR_DSE | PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_MUX(4);
- GPIO_BITBAND(GPIOD_PDDR, 4) = 1;
+ PERIPHERAL_BITBAND(GPIOD_PDDR, 4) = 1;
// LED3 FTM0_CH3
- GPIO_BITBAND(GPIOC_PDOR, 4) = 0;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 4) = 0;
PORTC_PCR4 = PORT_PCR_DSE | PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_MUX(4);
- GPIO_BITBAND(GPIOC_PDDR, 4) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDDR, 4) = 1;
// LED4 FTM3_CH4 yellow
- GPIO_BITBAND(GPIOC_PDOR, 8) = 0;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 8) = 0;
PORTC_PCR8 = PORT_PCR_DSE | PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_MUX(1);
- GPIO_BITBAND(GPIOC_PDDR, 8) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDDR, 8) = 1;
// LED5 FTM3_CH5 green
- GPIO_BITBAND(GPIOC_PDOR, 9) = 0;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 9) = 0;
PORTC_PCR9 = PORT_PCR_DSE | PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_MUX(1);
- GPIO_BITBAND(GPIOC_PDDR, 9) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDDR, 9) = 1;
// LED6 FTM3_CH6 red
- GPIO_BITBAND(GPIOC_PDOR, 10) = 0;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 10) = 0;
PORTC_PCR10 = PORT_PCR_DSE | PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_MUX(1);
- GPIO_BITBAND(GPIOC_PDDR, 10) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDDR, 10) = 1;
// Set up the CAN pins.
PORTB_PCR18 = PORT_PCR_DSE | PORT_PCR_MUX(2);
@@ -343,14 +343,14 @@
printf("Done starting up\n");
// Done starting up, now turn all the LEDs off.
- GPIO_BITBAND(GPIOC_PDOR, 5) = 0;
- GPIO_BITBAND(GPIOC_PDOR, 2) = 1;
- GPIO_BITBAND(GPIOC_PDOR, 1) = 1;
- GPIO_BITBAND(GPIOD_PDOR, 4) = 1;
- GPIO_BITBAND(GPIOC_PDOR, 4) = 1;
- GPIO_BITBAND(GPIOC_PDOR, 8) = 1;
- GPIO_BITBAND(GPIOC_PDOR, 9) = 1;
- GPIO_BITBAND(GPIOC_PDOR, 10) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 5) = 0;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 2) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 1) = 1;
+ PERIPHERAL_BITBAND(GPIOD_PDOR, 4) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 4) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 8) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 9) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDOR, 10) = 1;
SendJoystickData(&joystick0, &joystick1);
diff --git a/motors/medium_salsa.cc b/motors/medium_salsa.cc
index 3ac0337..f2ee181 100644
--- a/motors/medium_salsa.cc
+++ b/motors/medium_salsa.cc
@@ -110,7 +110,7 @@
void ZeroMotor() {
#if 0
while (true) {
- if (GPIO_BITBAND(GPIOE_PDIR, 24)) {
+ if (PERIPHERAL_BITBAND(GPIOE_PDIR, 24)) {
encoder_ftm_->CNT = 0;
break;
}
@@ -137,7 +137,7 @@
// value we store because writing anything resets it to CNTIN (ie 0).
"str %[scratch], [%[cnt]]\n"
: [scratch] "=&l"(scratch)
- : [pdir_word] "l"(&GPIO_BITBAND(GPIOE_PDIR, 24)),
+ : [pdir_word] "l"(&PERIPHERAL_BITBAND(GPIOE_PDIR, 24)),
[cnt] "l"(&FTM1->CNT));
__enable_irq();
#endif
@@ -161,10 +161,10 @@
NVIC_SET_SANE_PRIORITY(IRQ_FTM0, 0x3);
// Set the LED's pin to output mode.
- GPIO_BITBAND(GPIOC_PDDR, 5) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDDR, 5) = 1;
PORTC_PCR5 = PORT_PCR_DSE | PORT_PCR_MUX(1);
- GPIO_BITBAND(GPIOA_PDDR, 15) = 1;
+ PERIPHERAL_BITBAND(GPIOA_PDDR, 15) = 1;
PORTA_PCR15 = PORT_PCR_DSE | PORT_PCR_MUX(1);
// Set up the CAN pins.
@@ -181,7 +181,7 @@
can_init(0, 1);
GPIOD_PCOR = 1 << 3;
- GPIO_BITBAND(GPIOD_PDDR, 3) = 1;
+ PERIPHERAL_BITBAND(GPIOD_PDDR, 3) = 1;
PORTD_PCR3 = PORT_PCR_DSE | PORT_PCR_MUX(1);
delay(1000);
GPIOD_PSOR = 1 << 3;
diff --git a/motors/pistol_grip/controller.cc b/motors/pistol_grip/controller.cc
index 6e1c710..a77977b 100644
--- a/motors/pistol_grip/controller.cc
+++ b/motors/pistol_grip/controller.cc
@@ -419,16 +419,16 @@
::std::memory_order_relaxed);
uint8_t buttons = 0;
- if (!GPIO_BITBAND(GPIOA_PDIR, 14)) {
+ if (!PERIPHERAL_BITBAND(GPIOA_PDIR, 14)) {
buttons |= 0x1;
}
- if (!GPIO_BITBAND(GPIOE_PDIR, 26)) {
+ if (!PERIPHERAL_BITBAND(GPIOE_PDIR, 26)) {
buttons |= 0x2;
}
- if (!GPIO_BITBAND(GPIOC_PDIR, 7)) {
+ if (!PERIPHERAL_BITBAND(GPIOC_PDIR, 7)) {
buttons |= 0x4;
}
- if (!GPIO_BITBAND(GPIOD_PDIR, 0)) {
+ if (!PERIPHERAL_BITBAND(GPIOD_PDIR, 0)) {
buttons |= 0x8;
}
@@ -587,7 +587,7 @@
NVIC_SET_SANE_PRIORITY(IRQ_PIT_CH3, 0x5);
// Set the LED's pin to output mode.
- GPIO_BITBAND(GPIOC_PDDR, 5) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDDR, 5) = 1;
PORTC_PCR5 = PORT_PCR_DSE | PORT_PCR_MUX(1);
// Set up the CAN pins.
@@ -634,12 +634,12 @@
can_init(2, 3);
GPIOD_PCOR = 1 << 3;
- GPIO_BITBAND(GPIOD_PDDR, 3) = 1;
+ PERIPHERAL_BITBAND(GPIOD_PDDR, 3) = 1;
PORTD_PCR3 = PORT_PCR_DSE | PORT_PCR_MUX(1);
GPIOD_PSOR = 1 << 3;
GPIOC_PCOR = 1 << 4;
- GPIO_BITBAND(GPIOC_PDDR, 4) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDDR, 4) = 1;
PORTC_PCR4 = PORT_PCR_DSE | PORT_PCR_MUX(1);
GPIOC_PSOR = 1 << 4;
@@ -774,7 +774,7 @@
}
// Turn an LED on for Austin.
- GPIO_BITBAND(GPIOC_PDDR, 6) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDDR, 6) = 1;
GPIOC_PCOR = 1 << 6;
PORTC_PCR6 = PORT_PCR_DSE | PORT_PCR_MUX(1);
@@ -839,26 +839,26 @@
// TODO(Brian): Use SLEEPONEXIT to reduce interrupt latency?
while (true) {
- if (!GPIO_BITBAND(GPIOC_PDIR, 11)) {
- if (!GPIO_BITBAND(GPIOC_PDOR, 5)) {
+ if (!PERIPHERAL_BITBAND(GPIOC_PDIR, 11)) {
+ if (!PERIPHERAL_BITBAND(GPIOC_PDOR, 5)) {
printf("M0_THW\n");
}
GPIOC_PSOR = 1 << 5;
}
- if (!GPIO_BITBAND(GPIOD_PDIR, 6)) {
- if (!GPIO_BITBAND(GPIOC_PDOR, 5)) {
+ if (!PERIPHERAL_BITBAND(GPIOD_PDIR, 6)) {
+ if (!PERIPHERAL_BITBAND(GPIOC_PDOR, 5)) {
printf("M0_FAULT\n");
}
GPIOC_PSOR = 1 << 5;
}
- if (!GPIO_BITBAND(GPIOC_PDIR, 2)) {
- if (!GPIO_BITBAND(GPIOC_PDOR, 5)) {
+ if (!PERIPHERAL_BITBAND(GPIOC_PDIR, 2)) {
+ if (!PERIPHERAL_BITBAND(GPIOC_PDOR, 5)) {
printf("M1_THW\n");
}
GPIOC_PSOR = 1 << 5;
}
- if (!GPIO_BITBAND(GPIOD_PDIR, 5)) {
- if (!GPIO_BITBAND(GPIOC_PDOR, 5)) {
+ if (!PERIPHERAL_BITBAND(GPIOD_PDIR, 5)) {
+ if (!PERIPHERAL_BITBAND(GPIOC_PDOR, 5)) {
printf("M1_FAULT\n");
}
GPIOC_PSOR = 1 << 5;
diff --git a/motors/pistol_grip/drivers_station.cc b/motors/pistol_grip/drivers_station.cc
index 893aa9f..33c6caa 100644
--- a/motors/pistol_grip/drivers_station.cc
+++ b/motors/pistol_grip/drivers_station.cc
@@ -260,7 +260,7 @@
NVIC_SET_SANE_PRIORITY(IRQ_USBOTG, 0x7);
// Set the LED's pin to output mode.
- GPIO_BITBAND(GPIOC_PDDR, 5) = 1;
+ PERIPHERAL_BITBAND(GPIOC_PDDR, 5) = 1;
PORTC_PCR5 = PORT_PCR_DSE | PORT_PCR_MUX(1);
// Set up the CAN pins.
diff --git a/motors/util.h b/motors/util.h
index d1eaf53..458cf20 100644
--- a/motors/util.h
+++ b/motors/util.h
@@ -11,11 +11,11 @@
{
#endif
-// The GPIO bitband register for a specific bit of a given GPIO register.
+// This bitband register for a specific bit of a given peripheral register.
//
-// reg really must be one of the GPIO module's addresses
-// (0x400FF000 - 0x400FFFFF).
-#define GPIO_BITBAND(reg, bit) \
+// reg must be an address in one of the peripheral modules (on AIPS0, AIPS1, or
+// GPIO) (0x40000000 - 0x400FFFFF).
+#define PERIPHERAL_BITBAND(reg, bit) \
(*(volatile uint32_t *)(((uint32_t) & (reg)-0x40000000) * 32 + (bit)*4 + \
0x42000000))