diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cc1111/ao_arch.h | 2 | ||||
| -rw-r--r-- | src/cc1111/ao_button.c | 4 | ||||
| -rw-r--r-- | src/cc1111/ao_radio.c | 6 | ||||
| -rw-r--r-- | src/drivers/ao_btm.c | 8 | ||||
| -rw-r--r-- | src/drivers/ao_cc1120.c | 16 | ||||
| -rw-r--r-- | src/drivers/ao_cc1200.c | 8 | ||||
| -rw-r--r-- | src/drivers/ao_cc1200.h | 32 | ||||
| -rw-r--r-- | src/drivers/ao_cc1200_CC1200.h | 9 | ||||
| -rw-r--r-- | src/drivers/ao_companion.c | 3 | ||||
| -rw-r--r-- | src/drivers/ao_hmc5883.c | 4 | ||||
| -rw-r--r-- | src/drivers/ao_packet.c | 4 | ||||
| -rw-r--r-- | src/drivers/ao_packet_master.c | 8 | ||||
| -rw-r--r-- | src/drivers/ao_packet_slave.c | 2 | ||||
| -rw-r--r-- | src/kernel/ao_packet.h | 2 | ||||
| -rw-r--r-- | src/kernel/ao_pyro.c | 4 | ||||
| -rw-r--r-- | src/kernel/ao_serial.h | 8 | ||||
| -rw-r--r-- | src/kernel/ao_task.c | 48 | ||||
| -rw-r--r-- | src/kernel/ao_task.h | 10 | ||||
| -rw-r--r-- | src/kernel/ao_telemetry.c | 4 | ||||
| -rw-r--r-- | src/product/ao_terraui.c | 4 | ||||
| -rw-r--r-- | src/stm/ao_i2c_stm.c | 18 | ||||
| -rw-r--r-- | src/stm/ao_serial_stm.c | 16 | ||||
| -rw-r--r-- | src/stmf0/ao_crc_stm.c | 90 | ||||
| -rw-r--r-- | src/telebt-v3.0/ao_pins.h | 2 | ||||
| -rw-r--r-- | src/telelco-v0.1/ao_lco.c | 6 | ||||
| -rw-r--r-- | src/telelco-v0.2/ao_lco.c | 4 | 
26 files changed, 207 insertions, 115 deletions
| diff --git a/src/cc1111/ao_arch.h b/src/cc1111/ao_arch.h index b3c6b5dc..6eb1a111 100644 --- a/src/cc1111/ao_arch.h +++ b/src/cc1111/ao_arch.h @@ -228,7 +228,7 @@ void  ao_button_init(void);  char -ao_button_get(void) __critical; +ao_button_get(uint16_t timeout) __critical;  void  ao_button_clear(void) __critical; diff --git a/src/cc1111/ao_button.c b/src/cc1111/ao_button.c index 69f3475f..a0f221c2 100644 --- a/src/cc1111/ao_button.c +++ b/src/cc1111/ao_button.c @@ -72,12 +72,12 @@ ao_button_mask(uint8_t reg)  }  char -ao_button_get(void) __critical +ao_button_get(uint16_t timeout) __critical  {  	char	b;  	while (ao_fifo_empty(ao_button_fifo)) -		if (ao_sleep(&ao_button_fifo)) +		if (ao_sleep_for(&ao_button_fifo, timeout))  			return 0;  	ao_fifo_remove(ao_button_fifo, b);  	return b; diff --git a/src/cc1111/ao_radio.c b/src/cc1111/ao_radio.c index b9821a42..cead0364 100644 --- a/src/cc1111/ao_radio.c +++ b/src/cc1111/ao_radio.c @@ -451,13 +451,9 @@ ao_radio_recv(__xdata void *packet, uint8_t size, uint8_t timeout) __reentrant  	/* Wait for DMA to be done, for the radio receive process to  	 * get aborted or for a receive timeout to fire  	 */ -	if (timeout) -		ao_alarm(timeout);  	__critical while (!ao_radio_dma_done && !ao_radio_abort) -			   if (ao_sleep(&ao_radio_dma_done)) +			   if (ao_sleep_for(&ao_radio_dma_done, timeout))  				   break; -	if (timeout) -		ao_clear_alarm();  	/* If recv was aborted, clean up by stopping the DMA engine  	 * and idling the radio diff --git a/src/drivers/ao_btm.c b/src/drivers/ao_btm.c index e6b28688..93d9dd9d 100644 --- a/src/drivers/ao_btm.c +++ b/src/drivers/ao_btm.c @@ -23,7 +23,7 @@  #ifndef ao_serial_btm_getchar  #define ao_serial_btm_putchar	ao_serial1_putchar  #define _ao_serial_btm_pollchar	_ao_serial1_pollchar -#define _ao_serial_btm_sleep()	ao_sleep((void *) &ao_serial1_rx_fifo) +#define _ao_serial_btm_sleep_for(timeout)	ao_sleep_for((void *) &ao_serial1_rx_fifo, timeout)  #define ao_serial_btm_set_speed ao_serial1_set_speed  #define ao_serial_btm_drain	ao_serial1_drain  #endif @@ -111,7 +111,7 @@ ao_btm_do_echo(void)  	while (ao_btm_enable) {  		ao_arch_block_interrupts();  		while ((c = _ao_serial_btm_pollchar()) == AO_READ_AGAIN && ao_btm_enable) -			_ao_serial_btm_sleep(); +			_ao_serial_btm_sleep_for(0);  		ao_arch_release_interrupts();  		if (c != AO_READ_AGAIN) {  			putchar(c); @@ -166,9 +166,7 @@ ao_btm_getchar(void)  	ao_arch_block_interrupts();  	while ((c = _ao_serial_btm_pollchar()) == AO_READ_AGAIN) { -		ao_alarm(AO_MS_TO_TICKS(10)); -		c = _ao_serial_btm_sleep(); -		ao_clear_alarm(); +		c = _ao_serial_btm_sleep_for(AO_MS_TO_TICKS(10));  		if (c) {  			c = AO_READ_AGAIN;  			break; diff --git a/src/drivers/ao_cc1120.c b/src/drivers/ao_cc1120.c index 90d6cc75..5b814667 100644 --- a/src/drivers/ao_cc1120.c +++ b/src/drivers/ao_cc1120.c @@ -837,15 +837,11 @@ ao_radio_test_cmd(void)  static void  ao_radio_wait_isr(uint16_t timeout)  { -	if (timeout) -		ao_alarm(timeout);  	ao_arch_block_interrupts();  	while (!ao_radio_wake && !ao_radio_mcu_wake && !ao_radio_abort) -		if (ao_sleep(&ao_radio_wake)) +		if (ao_sleep_for(&ao_radio_wake, timeout))  			ao_radio_abort = 1;  	ao_arch_release_interrupts(); -	if (timeout) -		ao_clear_alarm();  	if (ao_radio_mcu_wake)  		ao_radio_check_marc_status();  } @@ -1060,19 +1056,17 @@ ao_radio_rx_isr(void)  static uint16_t  ao_radio_rx_wait(void)  { -	ao_alarm(AO_MS_TO_TICKS(100));  	ao_arch_block_interrupts();  	rx_waiting = 1;  	while (rx_data_cur - rx_data_consumed < AO_FEC_DECODE_BLOCK &&  	       !ao_radio_abort &&  	       !ao_radio_mcu_wake)  	{ -		if (ao_sleep(&ao_radio_wake)) +		if (ao_sleep_for(&ao_radio_wake, AO_MS_TO_TICKS(100)))  			ao_radio_abort = 1;  	}  	rx_waiting = 0;  	ao_arch_release_interrupts(); -	ao_clear_alarm();  	if (ao_radio_abort || ao_radio_mcu_wake)  		return 0;  	rx_data_consumed += AO_FEC_DECODE_BLOCK; @@ -1133,19 +1127,15 @@ ao_radio_recv(__xdata void *d, uint8_t size, uint8_t timeout)  	ao_radio_strobe(CC1120_SRX); -	if (timeout) -		ao_alarm(timeout);  	ao_arch_block_interrupts();  	while (rx_starting && !ao_radio_abort) { -		if (ao_sleep(&ao_radio_wake)) +		if (ao_sleep_for(&ao_radio_wake, timeout))  			ao_radio_abort = 1;  	}  	uint8_t	rx_task_id_save = rx_task_id;  	rx_task_id = 0;  	rx_starting = 0;  	ao_arch_release_interrupts(); -	if (timeout) -		ao_clear_alarm();  	if (ao_radio_abort) {  		if (rx_task_id_save == 0) diff --git a/src/drivers/ao_cc1200.c b/src/drivers/ao_cc1200.c index 8546900e..df4bd335 100644 --- a/src/drivers/ao_cc1200.c +++ b/src/drivers/ao_cc1200.c @@ -715,17 +715,11 @@ ao_radio_show_state(char *where)  static void  ao_radio_wait_isr(uint16_t timeout)  { -	if (timeout) -		ao_alarm(timeout); -  	ao_arch_block_interrupts();  	while (!ao_radio_wake && !ao_radio_abort) -		if (ao_sleep(&ao_radio_wake)) +		if (ao_sleep_for(&ao_radio_wake, timeout))  			ao_radio_abort = 1;  	ao_arch_release_interrupts(); - -	if (timeout) -		ao_clear_alarm();  }  static void diff --git a/src/drivers/ao_cc1200.h b/src/drivers/ao_cc1200.h index b04775fd..b2b63cde 100644 --- a/src/drivers/ao_cc1200.h +++ b/src/drivers/ao_cc1200.h @@ -438,6 +438,38 @@  #define CC1200_IF_MIX_CFG	(CC1200_EXTENDED_BIT | 0x00)  #define CC1200_FREQOFF_CFG	(CC1200_EXTENDED_BIT | 0x01)  #define CC1200_TOC_CFG		(CC1200_EXTENDED_BIT | 0x02) + +#define CC1200_TOC_CFG_TOC_LIMIT		6 +#define  CC1200_TOC_CFG_TOC_LIMIT_0_2			0 +#define  CC1200_TOC_CFG_TOC_LIMIT_2			1 +#define  CC1200_TOC_CFG_TOC_LIMIT_12			3 + +#define CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN	3 +#define  CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_8			0 +#define  CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_16		1 +#define  CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_32		2 +#define  CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_64		3 +#define  CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_128		4 +#define  CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_256		5 +#define  CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_8_16		0 +#define  CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_6_16		1 +#define  CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_2_16		2 +#define  CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_1_16		3 +#define  CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_1_16_SYNC		4 + +#define CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN	0 +#define  CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_8		0 +#define  CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_16		1 +#define  CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_32		2 +#define  CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_64		3 +#define  CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_128		4 +#define  CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_256		5 +#define  CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_FREEZE		0 +#define  CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_6_32		1 +#define  CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_2_32		2 +#define  CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_1_32		3 +#define  CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_1_32_SYNC	4 +  #define CC1200_MARC_SPARE	(CC1200_EXTENDED_BIT | 0x03)  #define CC1200_ECG_CFG		(CC1200_EXTENDED_BIT | 0x04)  #define CC1200_MDMCFG2		(CC1200_EXTENDED_BIT | 0x05) diff --git a/src/drivers/ao_cc1200_CC1200.h b/src/drivers/ao_cc1200_CC1200.h index 35673123..f0214c2a 100644 --- a/src/drivers/ao_cc1200_CC1200.h +++ b/src/drivers/ao_cc1200_CC1200.h @@ -101,6 +101,15 @@  		 (CC1200_MDMCFG2_SYMBOL_MAP_CFG_MODE_0 << CC1200_MDMCFG2_SYMBOL_MAP_CFG) |  		 (CC1200_MDMCFG2_UPSAMPLER_P_8 << CC1200_MDMCFG2_UPSAMPLER_P) |  		 (0 << CC1200_MDMCFG2_CFM_DATA_EN)), +	CC1200_MDMCFG0,					 /* General Modem Parameter Configuration Reg. 0 */  +		((0 << CC1200_MDMCFG0_TRANSPARENT_MODE_EN) | +		 (0 << CC1200_MDMCFG0_TRANSPARENT_INTFACT) | +		 (0 << CC1200_MDMCFG0_DATA_FILTER_EN) |	 +		 (1 << CC1200_MDMCFG0_VITERBI_EN)), +	CC1200_TOC_CFG,					/* Timing Offset Correction Configuration */ +		((CC1200_TOC_CFG_TOC_LIMIT_2 << CC1200_TOC_CFG_TOC_LIMIT) | +		 (CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_6_16 << CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN)| +		 (CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_2_32 << CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN)),          CC1200_FREQ2,                        0x6c,       /* Frequency Configuration [23:16] */          CC1200_FREQ1,                        0xa3,       /* Frequency Configuration [15:8] */          CC1200_FREQ0,                        0x33,       /* Frequency Configuration [7:0] */ diff --git a/src/drivers/ao_companion.c b/src/drivers/ao_companion.c index 570b9e40..7e02939b 100644 --- a/src/drivers/ao_companion.c +++ b/src/drivers/ao_companion.c @@ -102,8 +102,7 @@ ao_companion(void)  		    break;  	}  	while (ao_companion_running) { -		ao_alarm(ao_companion_setup.update_period); -		if (ao_sleep(DATA_TO_XDATA(&ao_flight_state))) +		if (ao_sleep_for(DATA_TO_XDATA(&ao_flight_state), ao_companion_setup.update_period))  			ao_companion_get_data();  		else  			ao_companion_notify(); diff --git a/src/drivers/ao_hmc5883.c b/src/drivers/ao_hmc5883.c index 2d217bcf..f761671a 100644 --- a/src/drivers/ao_hmc5883.c +++ b/src/drivers/ao_hmc5883.c @@ -75,13 +75,11 @@ ao_hmc5883_sample(struct ao_hmc5883_sample *sample)  	ao_exti_enable(AO_HMC5883_INT_PORT, AO_HMC5883_INT_PIN);  	ao_hmc5883_reg_write(HMC5883_MODE, HMC5883_MODE_SINGLE); -	ao_alarm(AO_MS_TO_TICKS(10));  	ao_arch_block_interrupts();  	while (!ao_hmc5883_done) -		if (ao_sleep(&ao_hmc5883_done)) +		if (ao_sleep_for(&ao_hmc5883_done, AO_MS_TO_TICKS(10)))  			++ao_hmc5883_missed_irq;  	ao_arch_release_interrupts(); -	ao_clear_alarm();  	ao_hmc5883_read(HMC5883_X_MSB, (uint8_t *) sample, sizeof (struct ao_hmc5883_sample));  #if __BYTE_ORDER == __LITTLE_ENDIAN diff --git a/src/drivers/ao_packet.c b/src/drivers/ao_packet.c index 8cdf85a9..18330ead 100644 --- a/src/drivers/ao_packet.c +++ b/src/drivers/ao_packet.c @@ -54,14 +54,14 @@ ao_packet_send(void)  }  uint8_t -ao_packet_recv(void) +ao_packet_recv(uint16_t timeout)  {  	uint8_t	dma_done;  #ifdef AO_LED_GREEN  	ao_led_on(AO_LED_GREEN);  #endif -	dma_done = ao_radio_recv(&ao_rx_packet, sizeof (struct ao_packet_recv), 0); +	dma_done = ao_radio_recv(&ao_rx_packet, sizeof (struct ao_packet_recv), timeout);  #ifdef AO_LED_GREEN  	ao_led_off(AO_LED_GREEN);  #endif diff --git a/src/drivers/ao_packet_master.c b/src/drivers/ao_packet_master.c index 42a4f5bf..5e440db0 100644 --- a/src/drivers/ao_packet_master.c +++ b/src/drivers/ao_packet_master.c @@ -97,9 +97,7 @@ ao_packet_master(void)  		if (ao_tx_packet.len)  			ao_packet_master_busy();  		ao_packet_master_check_busy(); -		ao_alarm(AO_PACKET_MASTER_RECV_DELAY); -		r = ao_packet_recv(); -		ao_clear_alarm(); +		r = ao_packet_recv(AO_PACKET_MASTER_RECV_DELAY);  		if (r) {  			/* if we can transmit data, do so */  			if (ao_packet_tx_used && ao_tx_packet.len == 0) @@ -107,9 +105,7 @@ ao_packet_master(void)  			if (ao_rx_packet.packet.len)  				ao_packet_master_busy();  			ao_packet_master_sleeping = 1; -			ao_alarm(ao_packet_master_delay); -			ao_sleep(&ao_packet_master_sleeping); -			ao_clear_alarm(); +			ao_sleep_for(&ao_packet_master_sleeping, ao_packet_master_delay);  			ao_packet_master_sleeping = 0;  		}  	} diff --git a/src/drivers/ao_packet_slave.c b/src/drivers/ao_packet_slave.c index e75df0d6..0872682f 100644 --- a/src/drivers/ao_packet_slave.c +++ b/src/drivers/ao_packet_slave.c @@ -24,7 +24,7 @@ ao_packet_slave(void)  	ao_tx_packet.len = AO_PACKET_SYN;  	ao_packet_restart = 1;  	while (ao_packet_enable) { -		if (ao_packet_recv()) { +		if (ao_packet_recv(0)) {  			ao_xmemcpy(&ao_tx_packet.callsign, &ao_rx_packet.packet.callsign, AO_MAX_CALLSIGN);  #if HAS_FLIGHT  			ao_flight_force_idle = TRUE; diff --git a/src/kernel/ao_packet.h b/src/kernel/ao_packet.h index b8426cf9..136609c3 100644 --- a/src/kernel/ao_packet.h +++ b/src/kernel/ao_packet.h @@ -54,7 +54,7 @@ void  ao_packet_send(void);  uint8_t -ao_packet_recv(void); +ao_packet_recv(uint16_t timeout);  void  ao_packet_flush(void); diff --git a/src/kernel/ao_pyro.c b/src/kernel/ao_pyro.c index 3044d565..43e73de4 100644 --- a/src/kernel/ao_pyro.c +++ b/src/kernel/ao_pyro.c @@ -375,9 +375,7 @@ ao_pyro(void)  		ao_sleep(&ao_flight_state);  	for (;;) { -		ao_alarm(AO_MS_TO_TICKS(100)); -		ao_sleep(&ao_pyro_wakeup); -		ao_clear_alarm(); +		ao_sleep_for(&ao_pyro_wakeup, AO_MS_TO_TICKS(100));  		if (ao_flight_state >= ao_flight_landed)  			break;  		any_waiting = ao_pyro_check(); diff --git a/src/kernel/ao_serial.h b/src/kernel/ao_serial.h index dbc9f8e4..e21643ac 100644 --- a/src/kernel/ao_serial.h +++ b/src/kernel/ao_serial.h @@ -35,7 +35,7 @@ int  _ao_serial0_pollchar(void);  uint8_t -_ao_serial0_sleep(void); +_ao_serial0_sleep_for(uint16_t timeout);  void  ao_serial0_putchar(char c); @@ -58,7 +58,7 @@ int  _ao_serial1_pollchar(void);  uint8_t -_ao_serial1_sleep(void); +_ao_serial1_sleep_for(uint16_t timeout);  void  ao_serial1_putchar(char c); @@ -81,7 +81,7 @@ int  _ao_serial2_pollchar(void);  uint8_t -_ao_serial2_sleep(void); +_ao_serial2_sleep_for(uint16_t timeout);  void  ao_serial2_putchar(char c); @@ -104,7 +104,7 @@ int  _ao_serial3_pollchar(void);  uint8_t -_ao_serial3_sleep(void); +_ao_serial3_sleep_for(uint16_t timeout);  void  ao_serial3_putchar(char c); diff --git a/src/kernel/ao_task.c b/src/kernel/ao_task.c index bafb4943..55e423bb 100644 --- a/src/kernel/ao_task.c +++ b/src/kernel/ao_task.c @@ -450,37 +450,39 @@ ao_wakeup(__xdata void *wchan) __reentrant  	ao_check_stack();  } -void -ao_alarm(uint16_t delay) +uint8_t +ao_sleep_for(__xdata void *wchan, uint16_t timeout)  { +	uint8_t	ret; +	if (timeout) {  #if HAS_TASK_QUEUE -	uint32_t flags; -	/* Make sure we sleep *at least* delay ticks, which means adding -	 * one to account for the fact that we may be close to the next tick -	 */ -	flags = ao_arch_irqsave(); +		uint32_t flags; +		/* Make sure we sleep *at least* delay ticks, which means adding +		 * one to account for the fact that we may be close to the next tick +		 */ +		flags = ao_arch_irqsave();  #endif -	if (!(ao_cur_task->alarm = ao_time() + delay + 1)) -		ao_cur_task->alarm = 1; +		if (!(ao_cur_task->alarm = ao_time() + timeout + 1)) +			ao_cur_task->alarm = 1;  #if HAS_TASK_QUEUE -	ao_task_to_alarm_queue(ao_cur_task); -	ao_arch_irqrestore(flags); +		ao_task_to_alarm_queue(ao_cur_task); +		ao_arch_irqrestore(flags);  #endif -} - -void -ao_clear_alarm(void) -{ +	} +	ret = ao_sleep(wchan); +	if (timeout) {  #if HAS_TASK_QUEUE -	uint32_t flags; +		uint32_t flags; -	flags = ao_arch_irqsave(); +		flags = ao_arch_irqsave();  #endif -	ao_cur_task->alarm = 0; +		ao_cur_task->alarm = 0;  #if HAS_TASK_QUEUE -	ao_task_from_alarm_queue(ao_cur_task); -	ao_arch_irqrestore(flags); +		ao_task_from_alarm_queue(ao_cur_task); +		ao_arch_irqrestore(flags);  #endif +	} +	return ret;  }  static __xdata uint8_t ao_forever; @@ -488,9 +490,7 @@ static __xdata uint8_t ao_forever;  void  ao_delay(uint16_t ticks)  { -	ao_alarm(ticks); -	ao_sleep(&ao_forever); -	ao_clear_alarm(); +	ao_sleep_for(&ao_forever, ticks);  }  void diff --git a/src/kernel/ao_task.h b/src/kernel/ao_task.h index 9c56b480..c6bec0e3 100644 --- a/src/kernel/ao_task.h +++ b/src/kernel/ao_task.h @@ -68,10 +68,19 @@ extern __data uint8_t ao_task_minimize_latency;	/* Reduce IRQ latency */  uint8_t  ao_sleep(__xdata void *wchan); +/* Suspend the current task until wchan is awoken or the timeout + * expires. returns: + *  0 on normal wake + *  1 on alarm + */ +uint8_t +ao_sleep_for(__xdata void *wchan, uint16_t timeout); +  /* Wake all tasks sleeping on wchan */  void  ao_wakeup(__xdata void *wchan) __reentrant; +#if 0  /* set an alarm to go off in 'delay' ticks */  void  ao_alarm(uint16_t delay); @@ -79,6 +88,7 @@ ao_alarm(uint16_t delay);  /* Clear any pending alarm */  void  ao_clear_alarm(void); +#endif  /* Yield the processor to another task */  void diff --git a/src/kernel/ao_telemetry.c b/src/kernel/ao_telemetry.c index e2197f7a..854ac898 100644 --- a/src/kernel/ao_telemetry.c +++ b/src/kernel/ao_telemetry.c @@ -486,9 +486,7 @@ ao_telemetry(void)  #endif /* HAS_APRS */  			delay = time - ao_time();  			if (delay > 0) { -				ao_alarm(delay); -				ao_sleep(&telemetry); -				ao_clear_alarm(); +				ao_sleep_for(&telemetry, delay);  			}  		}  	} diff --git a/src/product/ao_terraui.c b/src/product/ao_terraui.c index 8fd97033..1e7b5dcd 100644 --- a/src/product/ao_terraui.c +++ b/src/product/ao_terraui.c @@ -539,9 +539,7 @@ ao_terraui(void)  		else  			ao_terraui_page[ao_current_page](); -		ao_alarm(AO_SEC_TO_TICKS(1)); -		b = ao_button_get(); -		ao_clear_alarm(); +		b = ao_button_get(AO_SEC_TO_TICKS(1));  		if (b > 0) {  			ao_beep_for(AO_BEEP_HIGH, AO_MS_TO_TICKS(10)); diff --git a/src/stm/ao_i2c_stm.c b/src/stm/ao_i2c_stm.c index 1c90cdb8..158f5b21 100644 --- a/src/stm/ao_i2c_stm.c +++ b/src/stm/ao_i2c_stm.c @@ -195,15 +195,13 @@ ao_i2c_start(uint8_t index, uint16_t addr)  		if (!(stm_i2c->cr1 & (1 << STM_I2C_CR1_START)))  			break;  	} -	ao_alarm(AO_MS_TO_TICKS(250));  	ao_arch_block_interrupts();  	stm_i2c->cr2 = AO_STM_I2C_CR2 | (1 << STM_I2C_CR2_ITEVTEN) | (1 << STM_I2C_CR2_ITERREN);  	ao_i2c_ev_isr(index);  	while (ao_i2c_state[index] == I2C_IDLE) -		if (ao_sleep(&ao_i2c_state[index])) +		if (ao_sleep_for(&ao_i2c_state[index], AO_MS_TO_TICKS(250)))  			break;  	ao_arch_release_interrupts(); -	ao_clear_alarm();  	return ao_i2c_state[index] == I2C_RUNNING;  } @@ -258,16 +256,14 @@ ao_i2c_send(void *block, uint16_t len, uint8_t index, uint8_t stop)  			    (STM_DMA_CCR_DIR_MEM_TO_PER << STM_DMA_CCR_DIR));  	ao_dma_start(tx_dma_index); -	ao_alarm(1 + len);  	ao_arch_block_interrupts();  	while (!ao_dma_done[tx_dma_index]) -		if (ao_sleep(&ao_dma_done[tx_dma_index])) +		if (ao_sleep_for(&ao_dma_done[tx_dma_index], 1 + len))  			break; -	ao_clear_alarm();  	ao_dma_done_transfer(tx_dma_index);  	stm_i2c->cr2 = AO_STM_I2C_CR2 | (1 << STM_I2C_CR2_ITEVTEN) | (1 << STM_I2C_CR2_ITERREN);  	while ((stm_i2c->sr1 & (1 << STM_I2C_SR1_BTF)) == 0) -		if (ao_sleep(&ao_i2c_state[index])) +		if (ao_sleep_for(&ao_i2c_state[index], 1 + len))  			break;  	stm_i2c->cr2 = AO_STM_I2C_CR2;  	ao_arch_release_interrupts(); @@ -321,14 +317,12 @@ ao_i2c_recv(void *block, uint16_t len, uint8_t index, uint8_t stop)  		if (stop)  			stm_i2c->cr1 = AO_STM_I2C_CR1 | (1 << STM_I2C_CR1_STOP); -		ao_alarm(1);  		ao_arch_block_interrupts();  		while (ao_i2c_recv_len[index]) -			if (ao_sleep(&ao_i2c_recv_len[index])) +			if (ao_sleep_for(&ao_i2c_recv_len[index], 1))  				break;  		ao_arch_release_interrupts();  		ret = ao_i2c_recv_len[index] == 0; -		ao_clear_alarm();  	} else {  		uint8_t		rx_dma_index = ao_i2c_stm_info[index].rx_dma_index;  		ao_dma_set_transfer(rx_dma_index, @@ -351,13 +345,11 @@ ao_i2c_recv(void *block, uint16_t len, uint8_t index, uint8_t stop)  		ao_i2c_wait_addr(index);  		ao_dma_start(rx_dma_index); -		ao_alarm(len);  		ao_arch_block_interrupts();  		while (!ao_dma_done[rx_dma_index]) -			if (ao_sleep(&ao_dma_done[rx_dma_index])) +			if (ao_sleep_for(&ao_dma_done[rx_dma_index], len))  				break;  		ao_arch_release_interrupts(); -		ao_clear_alarm();  		ret = ao_dma_done[rx_dma_index];  		ao_dma_done_transfer(rx_dma_index);  		stm_i2c->cr1 = AO_STM_I2C_CR1 | (1 << STM_I2C_CR1_STOP); diff --git a/src/stm/ao_serial_stm.c b/src/stm/ao_serial_stm.c index 2568cf43..88f2d029 100644 --- a/src/stm/ao_serial_stm.c +++ b/src/stm/ao_serial_stm.c @@ -86,9 +86,9 @@ ao_usart_getchar(struct ao_stm_usart *usart)  }  static inline uint8_t -_ao_usart_sleep(struct ao_stm_usart *usart) +_ao_usart_sleep_for(struct ao_stm_usart *usart, uint16_t timeout)  { -	return ao_sleep(&usart->rx_fifo); +	return ao_sleep_for(&usart->rx_fifo, timeout);  }  void @@ -217,9 +217,9 @@ _ao_serial1_pollchar(void)  }  uint8_t -_ao_serial1_sleep(void) +_ao_serial1_sleep_for(uint16_t timeout)  { -	return _ao_usart_sleep(&ao_stm_usart1); +	return _ao_usart_sleep_for(&ao_stm_usart1, timeout);  }  void @@ -260,9 +260,9 @@ _ao_serial2_pollchar(void)  }  uint8_t -_ao_serial2_sleep(void) +_ao_serial2_sleep_for(uint16_t timeout)  { -	return _ao_usart_sleep(&ao_stm_usart2); +	return _ao_usart_sleep_for(&ao_stm_usart2, timeout);  }  void @@ -303,9 +303,9 @@ _ao_serial3_pollchar(void)  }  uint8_t -_ao_serial3_sleep(void) +_ao_serial3_sleep_for(uint16_t timeout)  { -	return _ao_usart_sleep(&ao_stm_usart3); +	return _ao_usart_sleep_for(&ao_stm_usart3, timeout);  }  void diff --git a/src/stmf0/ao_crc_stm.c b/src/stmf0/ao_crc_stm.c new file mode 100644 index 00000000..78efa93a --- /dev/null +++ b/src/stmf0/ao_crc_stm.c @@ -0,0 +1,90 @@ +/* + * Copyright © 2015 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include <ao.h> +#include <ao_crc.h> + +#ifndef AO_CRC_WIDTH +#error "Must define AO_CRC_WIDTH" +#endif + +/* Only the STM32F07x and ST32F09x series have + * programmable CRC units. Others can only do the ANSI CRC-32 computation + */ + +#if !AO_HAVE_PROGRAMMABLE_CRC_UNIT && AO_CRC_WIDTH != 32 +#error "Target hardware does not have programmable CRC unit" +#endif + +#ifndef AO_CRC_POLY +#if AO_CRC_WIDTH == 16 +#define AO_CRC_POLY	AO_CRC_16_DEFAULT +#endif +#if AO_CRC_WIDTH == 32 +#define AO_CRC_POLY	AO_CRC_32_DEFAULT +#endif +#endif + +#if !AO_HAVE_PROGRAMMABLE_CRC_UNIT && (AO_CRC_WIDTH != 32 || AO_CRC_POLY != AO_CRC_32_ANSI) +#error "Target hardware does not have programmable CRC unit" +#endif + +#if AO_CRC_WIDTH == 32 +#define AO_CRC_CR_POLYSIZE	STM_CRC_CR_POLYSIZE_32 +#endif + +#if AO_CRC_WIDTH == 16 +#define AO_CRC_CR_POLYSIZE	STM_CRC_CR_POLYSIZE_16 +#endif + +#if AO_CRC_WIDTH == 8 +#define AO_CRC_CR_POLYSIZE	STM_CRC_CR_POLYSIZE_8 +#endif + +#if AO_CRC_WIDTH == 7 +#define AO_CRC_CR_POLYSIZE	STM_CRC_CR_POLYSIZE_7 +#endif + +#ifndef AO_CRC_INIT +#define AO_CRC_INIT	0xffffffff; +#endif + +void +ao_crc_reset(void) +{ +	stm_crc.cr |= (1 << STM_CRC_CR_RESET); +	while ((stm_crc.cr & (1 << STM_CRC_CR_RESET)) != 0) +		; +} + +void +ao_crc_init(void) +{ +	/* Turn on the CRC clock */ +	stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_CRCEN); + +	/* Need to initialize CR even on non-programmable hardware, +	 * the write to the POLYSIZE bits will be ignored in that +	 * case +	 */ +	stm_crc.cr = (AO_CRC_CR_POLYSIZE << STM_CRC_CR_POLYSIZE); +	stm_crc.init = AO_CRC_INIT; +#if AO_HAVE_PROGRAMMABLE_CRC_UNIT +	stm_crc.pol = AO_CRC_POLY; +#endif +	ao_crc_reset(); +} diff --git a/src/telebt-v3.0/ao_pins.h b/src/telebt-v3.0/ao_pins.h index 838f0dfc..6e90afcc 100644 --- a/src/telebt-v3.0/ao_pins.h +++ b/src/telebt-v3.0/ao_pins.h @@ -168,7 +168,7 @@ struct ao_adc {  #define ao_serial_btm_getchar	ao_serial2_getchar  #define ao_serial_btm_putchar	ao_serial2_putchar  #define _ao_serial_btm_pollchar	_ao_serial2_pollchar -#define _ao_serial_btm_sleep	_ao_serial2_sleep +#define _ao_serial_btm_sleep_for	_ao_serial2_sleep_for  #define ao_serial_btm_set_speed ao_serial2_set_speed  #define ao_serial_btm_drain	ao_serial2_drain  #define ao_serial_btm_rx_fifo	(ao_stm_usart2.rx_fifo) diff --git a/src/telelco-v0.1/ao_lco.c b/src/telelco-v0.1/ao_lco.c index 79f3896b..cb2195ef 100644 --- a/src/telelco-v0.1/ao_lco.c +++ b/src/telelco-v0.1/ao_lco.c @@ -280,9 +280,7 @@ ao_lco_igniter_status(void)  	uint16_t	delay;  	for (;;) { -//		ao_alarm(delay);  		ao_sleep(&ao_pad_query); -//		ao_clear_alarm();  		if (!ao_lco_valid) {  			ao_led_on(AO_LED_RED);  			ao_led_off(AO_LED_GREEN); @@ -364,9 +362,7 @@ ao_lco_monitor(void)  			delay = AO_MS_TO_TICKS(100);  		else  			delay = AO_SEC_TO_TICKS(1); -		ao_alarm(delay); -		ao_sleep(&ao_lco_armed); -		ao_clear_alarm(); +		ao_sleep_for(&ao_lco_armed, delay);  	}  } diff --git a/src/telelco-v0.2/ao_lco.c b/src/telelco-v0.2/ao_lco.c index 4b5f7a9b..12a247bf 100644 --- a/src/telelco-v0.2/ao_lco.c +++ b/src/telelco-v0.2/ao_lco.c @@ -369,9 +369,7 @@ ao_lco_monitor(void)  			delay = AO_MS_TO_TICKS(100);  		else  			delay = AO_SEC_TO_TICKS(1); -		ao_alarm(delay); -		ao_sleep(&ao_lco_armed); -		ao_clear_alarm(); +		ao_sleep_for(&ao_lco_armed, delay);  	}  } | 
