From: Keith Packard Date: Wed, 27 Jun 2012 21:34:53 +0000 (-0700) Subject: altos: include targe SPI speed in get request X-Git-Tag: 1.0.9.6~14 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=08a4ed8fe794a2b2b52147bd5535fe0954822e95 altos: include targe SPI speed in get request STM needs it to be provided when enabling the SPI device, so just fix AVR and cc1111 to do the same. Signed-off-by: Keith Packard --- diff --git a/src/avr/ao_arch_funcs.h b/src/avr/ao_arch_funcs.h index 1eeca6cc..e400c98b 100644 --- a/src/avr/ao_arch_funcs.h +++ b/src/avr/ao_arch_funcs.h @@ -21,7 +21,7 @@ extern __xdata uint8_t ao_spi_mutex; -#define ao_spi_get_mask(reg,mask,bus) do { \ +#define ao_spi_get_mask(reg,mask,bus,speed) do { \ ao_mutex_get(&ao_spi_mutex); \ (reg) &= ~(mask); \ } while (0) @@ -31,13 +31,13 @@ extern __xdata uint8_t ao_spi_mutex; ao_mutex_put(&ao_spi_mutex); \ } while (0) -#define ao_spi_get_bit(bit) do { \ +#define ao_spi_get_bit(reg,bit,pin,bus,speed) do { \ ao_mutex_get(&ao_spi_mutex); \ - (bit) = 0; \ + (pin) = 0; \ } while (0) -#define ao_spi_put_bit(bit) do { \ - (bit) = 1; \ +#define ao_spi_put_bit(reg,bit,pin,bus) do { \ + (pin) = 1; \ ao_mutex_put(&ao_spi_mutex); \ } while (0) diff --git a/src/cc1111/ao_arch_funcs.h b/src/cc1111/ao_arch_funcs.h index 728f1f76..0a322961 100644 --- a/src/cc1111/ao_arch_funcs.h +++ b/src/cc1111/ao_arch_funcs.h @@ -21,9 +21,18 @@ extern __xdata uint8_t ao_spi_mutex; -#define ao_spi_get_mask(reg,mask,bus) do { \ - ao_mutex_get(&ao_spi_mutex); \ - (reg) &= ~(mask); \ +#define AO_SPI_SPEED_FAST 17 +#define AO_SPI_SPEED_200kHz 13 + +#define ao_spi_set_speed(speed) (U0GCR = (UxGCR_CPOL_NEGATIVE | \ + UxGCR_CPHA_FIRST_EDGE | \ + UxGCR_ORDER_MSB | \ + ((speed) << UxGCR_BAUD_E_SHIFT))) + +#define ao_spi_get_mask(reg,mask,bus,speed) do { \ + ao_mutex_get(&ao_spi_mutex); \ + ao_spi_set_speed(speed); \ + (reg) &= ~(mask); \ } while (0) #define ao_spi_put_mask(reg,mask,bus) do { \ @@ -31,8 +40,10 @@ extern __xdata uint8_t ao_spi_mutex; ao_mutex_put(&ao_spi_mutex); \ } while (0) -#define ao_spi_get_bit(reg,bit,pin,bus) do { \ + +#define ao_spi_get_bit(reg,bit,pin,bus,speed) do { \ ao_mutex_get(&ao_spi_mutex); \ + ao_spi_set_speed(speed); \ pin = 0; \ } while (0) diff --git a/src/drivers/ao_25lc1024.c b/src/drivers/ao_25lc1024.c index b25d52c4..c5d811f7 100644 --- a/src/drivers/ao_25lc1024.c +++ b/src/drivers/ao_25lc1024.c @@ -50,7 +50,7 @@ static __xdata uint8_t ao_ee_mutex; _asm nop _endasm; \ } while(0) -#define ao_ee_cs_low() ao_spi_get_bit(EE_CS_PORT, EE_CS_PIN, EE_CS, AO_EE_SPI_BUS) +#define ao_ee_cs_low() ao_spi_get_bit(EE_CS_PORT, EE_CS_PIN, EE_CS, AO_EE_SPI_BUS, AO_SPI_SPEED_FAST) #define ao_ee_cs_high() ao_spi_put_bit(EE_CS_PORT, EE_CS_PIN, EE_CS, AO_EE_SPI_BUS) diff --git a/src/drivers/ao_at45db161d.c b/src/drivers/ao_at45db161d.c index 5eb25acf..e7e74153 100644 --- a/src/drivers/ao_at45db161d.c +++ b/src/drivers/ao_at45db161d.c @@ -43,7 +43,7 @@ __xdata uint8_t ao_flash_mutex; _asm nop _endasm; \ } while(0) -#define ao_flash_cs_low() ao_spi_get_bit(FLASH_CS_PORT, FLASH_CS_PIN, FLASH_CS, AO_FLASH_SPI_BUS) +#define ao_flash_cs_low() ao_spi_get_bit(FLASH_CS_PORT, FLASH_CS_PIN, FLASH_CS, AO_FLASH_SPI_BUS, AO_SPI_SPEED_FAST) #define ao_flash_cs_high() ao_spi_put_bit(FLASH_CS_PORT, FLASH_CS_PIN, FLASH_CS, AO_FLASH_SPI_BUS) diff --git a/src/drivers/ao_cc1120.c b/src/drivers/ao_cc1120.c index cc9ebd30..c974613e 100644 --- a/src/drivers/ao_cc1120.c +++ b/src/drivers/ao_cc1120.c @@ -33,7 +33,7 @@ const uint32_t ao_radio_cal = 0x6ca333; #define FOSC 32000000 -#define ao_radio_select() ao_spi_get_mask(AO_CC1120_SPI_CS_PORT,(1 << AO_CC1120_SPI_CS_PIN),AO_CC1120_SPI_BUS) +#define ao_radio_select() ao_spi_get_mask(AO_CC1120_SPI_CS_PORT,(1 << AO_CC1120_SPI_CS_PIN),AO_CC1120_SPI_BUS,AO_SPI_SPEED_1MHz) #define ao_radio_deselect() ao_spi_put_mask(AO_CC1120_SPI_CS_PORT,(1 << AO_CC1120_SPI_CS_PIN),AO_CC1120_SPI_BUS) #define ao_radio_spi_send(d,l) ao_spi_send((d), (l), AO_CC1120_SPI_BUS) #define ao_radio_spi_send_fixed(d,l) ao_spi_send_fixed((d), (l), AO_CC1120_SPI_BUS) diff --git a/src/drivers/ao_companion.c b/src/drivers/ao_companion.c index a31cc2ea..85d68c44 100644 --- a/src/drivers/ao_companion.c +++ b/src/drivers/ao_companion.c @@ -18,28 +18,20 @@ #include #include -#ifndef ao_spi_slow -#define ao_spi_slow(bus) (U0GCR = (UxGCR_CPOL_NEGATIVE | \ - UxGCR_CPHA_FIRST_EDGE | \ - UxGCR_ORDER_MSB | \ - (13 << UxGCR_BAUD_E_SHIFT))) - -#define ao_spi_fast(bus) (U0GCR = (UxGCR_CPOL_NEGATIVE | \ - UxGCR_CPHA_FIRST_EDGE | \ - UxGCR_ORDER_MSB | \ - (17 << UxGCR_BAUD_E_SHIFT))) +#ifdef MEGAMETRUM +#define ao_spi_slow(b) +#define ao_spi_fast(b) #endif #define COMPANION_SELECT() do { \ ao_spi_get_bit(AO_COMPANION_CS_PORT, \ AO_COMPANION_CS_PIN, \ AO_COMPANION_CS, \ - AO_COMPANION_SPI_BUS); \ - ao_spi_slow(AO_COMPANION_SPI_BUS); \ + AO_COMPANION_SPI_BUS, \ + AO_SPI_SPEED_200kHz); \ } while (0) #define COMPANION_DESELECT() do { \ - ao_spi_fast(AO_COMPANION_SPI_BUS); \ ao_spi_put_bit(AO_COMPANION_CS_PORT, \ AO_COMPANION_CS_PIN, \ AO_COMPANION_CS, \ diff --git a/src/drivers/ao_m25.c b/src/drivers/ao_m25.c index 2983a405..9603c1de 100644 --- a/src/drivers/ao_m25.c +++ b/src/drivers/ao_m25.c @@ -110,7 +110,7 @@ static void ao_boot_radio(void) { #define ao_boot_radio() #endif -#define M25_SELECT(cs) do { ao_boot_radio(); ao_spi_get_mask(AO_M25_SPI_CS_PORT,cs,AO_M25_SPI_BUS); } while (0) +#define M25_SELECT(cs) do { ao_boot_radio(); ao_spi_get_mask(AO_M25_SPI_CS_PORT,cs,AO_M25_SPI_BUS, AO_SPI_SPEED_FAST); } while (0) #define M25_DESELECT(cs) ao_spi_put_mask(AO_M25_SPI_CS_PORT,cs,AO_M25_SPI_BUS) #define M25_BLOCK_SHIFT 16 diff --git a/src/drivers/ao_ms5607.c b/src/drivers/ao_ms5607.c index e08f4d40..e1d0507e 100644 --- a/src/drivers/ao_ms5607.c +++ b/src/drivers/ao_ms5607.c @@ -24,7 +24,7 @@ static uint8_t ms5607_configured; static void ao_ms5607_start(void) { - ao_spi_get(AO_MS5607_SPI_INDEX); + ao_spi_get(AO_MS5607_SPI_INDEX,AO_SPI_SPEED_FAST); stm_gpio_set(AO_MS5607_CS_GPIO, AO_MS5607_CS, 0); } diff --git a/src/stm-demo/ao_demo.c b/src/stm-demo/ao_demo.c index 73ace558..9a581ff9 100644 --- a/src/stm-demo/ao_demo.c +++ b/src/stm-demo/ao_demo.c @@ -83,7 +83,7 @@ ao_spi_write(void) { int i; for (i = 0; i < 10; i++) { - ao_spi_get(0); + ao_spi_get(0, AO_SPI_SPEED_FAST); stm_gpio_set(&stm_gpioc, 12, 0); ao_spi_send(data, 4, 0); stm_gpio_set(&stm_gpioc, 12, 1); @@ -100,7 +100,7 @@ ao_spi_read(void) { int i; for (i = 0; i < 10; i++) { - ao_spi_get(0); + ao_spi_get(0, AO_SPI_SPEED_FAST); stm_gpio_set(&stm_gpioc, 12, 0); ao_spi_recv(data, 4, 0); stm_gpio_set(&stm_gpioc, 12, 1); diff --git a/src/stm/ao_arch_funcs.h b/src/stm/ao_arch_funcs.h index 62b10063..7820bf79 100644 --- a/src/stm/ao_arch_funcs.h +++ b/src/stm/ao_arch_funcs.h @@ -22,8 +22,12 @@ */ extern uint8_t ao_spi_mutex[STM_NUM_SPI]; +#define AO_SPI_SPEED_FAST STM_SPI_CR1_BR_PCLK_4 +#define AO_SPI_SPEED_1MHz STM_SPI_CR1_BR_PCLK_16 +#define AO_SPI_SPEED_200kHz STM_SPI_CR1_BR_PCLK_256 + void -ao_spi_get(uint8_t spi_index); +ao_spi_get(uint8_t spi_index, uint32_t speed); void ao_spi_put(uint8_t spi_index); @@ -40,20 +44,13 @@ ao_spi_recv(void *block, uint16_t len, uint8_t spi_index); void ao_spi_duplex(void *out, void *in, uint16_t len, uint8_t spi_index); -#define AO_SPI_SPEED_FAST STM_SPI_CR1_BR_PCLK_16 -#define AO_SPI_SPEED_200kHz STM_SPI_CR1_BR_PCLK_256 - extern uint16_t ao_spi_speed[STM_NUM_SPI]; -#define ao_spi_slow(bus) (ao_spi_speed[bus] = AO_SPI_SPEED_200kHz) - -#define ao_spi_fast(bus) (ao_spi_speed[bus] = AO_SPI_SPEED_FAST) - void ao_spi_init(void); -#define ao_spi_get_mask(reg,mask,bus) do { \ - ao_spi_get(bus); \ +#define ao_spi_get_mask(reg,mask,bus, speed) do { \ + ao_spi_get(bus, speed); \ (reg)->bsrr = ((uint32_t) mask) << 16; \ } while (0) @@ -62,7 +59,7 @@ ao_spi_init(void); ao_spi_put(bus); \ } while (0) -#define ao_spi_get_bit(reg,bit,pin,bus) ao_spi_get_mask(reg,(1<