Skip to content

Commit

Permalink
firmware: Add revC3 and support for the new A DAC.
Browse files Browse the repository at this point in the history
  • Loading branch information
esden authored and whitequark committed Feb 7, 2023
1 parent 29b6aa4 commit 9d6f43f
Show file tree
Hide file tree
Showing 5 changed files with 528 additions and 517 deletions.
7 changes: 6 additions & 1 deletion firmware/dac_ldo.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ void iobuf_enable(bool on) {
static bool dac_start(uint8_t mask, bool read) {
uint8_t addr = 0;
switch(mask) {
case IO_BUF_A: addr = I2C_ADDR_IOA_DAC; break;
case IO_BUF_A:
if (glasgow_config.revision < GLASGOW_REV_C3)
addr = I2C_ADDR_IOA_DAC_REVBC12;
else
addr = I2C_ADDR_IOA_DAC_REVC3;
break;
case IO_BUF_B: addr = I2C_ADDR_IOB_DAC; break;
case IO_BUF_ALL: if(!read) addr = I2C_ADDR_ALL_DAC; break;
}
Expand Down
3 changes: 3 additions & 0 deletions firmware/fpga.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void fpga_reset() {
case GLASGOW_REV_C0:
case GLASGOW_REV_C1:
case GLASGOW_REV_C2:
case GLASGOW_REV_C3:
OEA |= (1<<PINA_CRESET_N_REVC);
IOA &= ~(1<<PINA_CRESET_N_REVC);
break;
Expand All @@ -56,6 +57,7 @@ void fpga_reset() {
case GLASGOW_REV_C0:
case GLASGOW_REV_C1:
case GLASGOW_REV_C2:
case GLASGOW_REV_C3:
IOA |= (1<<PINA_CRESET_N_REVC);
break;
}
Expand Down Expand Up @@ -133,6 +135,7 @@ __endasm;
case GLASGOW_REV_C0:
case GLASGOW_REV_C1:
case GLASGOW_REV_C2:
case GLASGOW_REV_C3:
IFCONFIG |= _IFCLKOE|_3048MHZ|_IFCFG0|_IFCFG1;
break;
}
Expand Down
4 changes: 3 additions & 1 deletion firmware/glasgow.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum {
GLASGOW_REV_C0 = 0x30,
GLASGOW_REV_C1 = 0x31,
GLASGOW_REV_C2 = 0x32,
GLASGOW_REV_C3 = 0x33,

GLASGOW_REV_NA = 0xF9,
};
Expand Down Expand Up @@ -53,7 +54,8 @@ enum {
I2C_ADDR_FPGA = 0b0001000,
I2C_ADDR_FX2_MEM = 0b1010001,
I2C_ADDR_ICE_MEM = 0b1010010,
I2C_ADDR_IOA_DAC = 0b0001100,
I2C_ADDR_IOA_DAC_REVBC12 = 0b0001100,
I2C_ADDR_IOA_DAC_REVC3 = 0b0001110,
I2C_ADDR_IOB_DAC = 0b0001101,
I2C_ADDR_ALL_DAC = 0b1001000,
I2C_ADDR_IOA_ADC_ADC081C = 0b1010100,
Expand Down
30 changes: 15 additions & 15 deletions firmware/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ void handle_pending_usb_setup() {

while(EP0CS & _BUSY);

if(glasgow_config.revision == GLASGOW_REV_C2)
if(glasgow_config.revision >= GLASGOW_REV_C2)
result = iobuf_measure_voltage_ina233(arg_mask, (__xdata uint16_t *)EP0BUF);
else
result = iobuf_measure_voltage_adc081c(arg_mask, (__xdata uint16_t *)EP0BUF);
Expand All @@ -633,7 +633,7 @@ void handle_pending_usb_setup() {
if(arg_get) {
while(EP0CS & _BUSY);

if(glasgow_config.revision == GLASGOW_REV_C2)
if(glasgow_config.revision >= GLASGOW_REV_C2)
result = iobuf_get_alert_ina233(arg_mask, (__xdata uint16_t *)EP0BUF, (__xdata uint16_t *)EP0BUF + 1);
else
result = iobuf_get_alert_adc081c(arg_mask, (__xdata uint16_t *)EP0BUF, (__xdata uint16_t *)EP0BUF + 1);
Expand All @@ -647,7 +647,7 @@ void handle_pending_usb_setup() {
SETUP_EP0_BUF(4);
while(EP0CS & _BUSY);

if(glasgow_config.revision == GLASGOW_REV_C2)
if(glasgow_config.revision >= GLASGOW_REV_C2)
result = iobuf_set_alert_ina233(arg_mask, (__xdata uint16_t *)EP0BUF, (__xdata uint16_t *)EP0BUF + 1);
else
result = iobuf_set_alert_adc081c(arg_mask, (__xdata uint16_t *)EP0BUF, (__xdata uint16_t *)EP0BUF + 1);
Expand All @@ -668,21 +668,21 @@ void handle_pending_usb_setup() {
bool result = true;

while(EP0CS & _BUSY);

// Read out the alert status and also clear the alert status (or cache)
if(glasgow_config.revision == GLASGOW_REV_C2)
if(glasgow_config.revision >= GLASGOW_REV_C2)
iobuf_read_alert_cache_ina233(EP0BUF, /*clear=*/true);
else
result = iobuf_poll_alert_adc081c(EP0BUF, /*clear=*/true);

if(!result) {
STALL_EP0();
} else {
SETUP_EP0_BUF(1);
// Clear the ERR led since we cleared the alert status above
reset_status_bit(ST_ALERT);
}

return;
}

Expand Down Expand Up @@ -799,8 +799,8 @@ void handle_pending_usb_setup() {
}

// Directly use the irq enable register EX0 to notify about a pending alert to avoid using
// a separate variable which could get out of sync.
// Define it to armed_alert to document this usage pattern
// a separate variable which could get out of sync.
// Define it to armed_alert to document this usage pattern
#define armed_alert EX0

void isr_IE0() __interrupt(_INT_IE0) {
Expand All @@ -815,8 +815,8 @@ void handle_pending_alert() {

// switch on the ERR led
latch_status_bit(ST_ALERT);
if(glasgow_config.revision == GLASGOW_REV_C2) {

if(glasgow_config.revision >= GLASGOW_REV_C2) {
iobuf_poll_alert_ina233(&mask);
// the ~ALERT line was not yet cleared by this call
} else {
Expand All @@ -825,17 +825,17 @@ void handle_pending_alert() {
}

// TODO: handle i2c comms errors of above calls

// permanently switch off the voltage regulators of the ports we got a alert on
iobuf_set_voltage(mask, &millivolts);

if(glasgow_config.revision == GLASGOW_REV_C2) {
if(glasgow_config.revision >= GLASGOW_REV_C2) {
// only clear the ~ALERT line after the port vio has been disabled
// this prevents re-enabling the port voltage for a short time
// since on revC2 ~ALERT already disables the respective Vreg on a hw level
iobuf_clear_alert_ina233(mask);
}

// the ADC that pulled the ~ALERT line should have released it by now
// so we can re-enable the interrupt to catch the next alert
armed_alert = true;
Expand Down Expand Up @@ -878,7 +878,7 @@ int main() {
descriptors_init();
iobuf_init_dac_ldo();

if(glasgow_config.revision == GLASGOW_REV_C2) {
if(glasgow_config.revision >= GLASGOW_REV_C2) {
if (!iobuf_init_adc_ina233())
latch_status_bit(ST_ERROR);
}
Expand Down

0 comments on commit 9d6f43f

Please sign in to comment.