diff options
| -rw-r--r-- | src/micropeak/Makefile | 2 | ||||
| -rw-r--r-- | src/micropeak/ao_async.c | 43 | ||||
| -rw-r--r-- | src/micropeak/ao_async.h | 6 | ||||
| -rw-r--r-- | src/micropeak/ao_log_micro.c | 55 | ||||
| -rw-r--r-- | src/micropeak/ao_micropeak.c | 1 | 
5 files changed, 99 insertions, 8 deletions
| diff --git a/src/micropeak/Makefile b/src/micropeak/Makefile index 82944cb1..ff0a4499 100644 --- a/src/micropeak/Makefile +++ b/src/micropeak/Makefile @@ -50,7 +50,7 @@ IDPRODUCT=0  PRODUCT=MicroPeak-v0.1  PRODUCT_DEF=-DMICROPEAK  CFLAGS = $(PRODUCT_DEF) -I. -I../attiny -I../core -I.. -I../drivers -CFLAGS += -g -mmcu=$(MCU) -Wall -Wstrict-prototypes -O3 -mcall-prologues -DATTINY +CFLAGS += -g -mmcu=$(MCU) -Wall -Wstrict-prototypes -O2 -mcall-prologues -DATTINY  NICKLE=nickle diff --git a/src/micropeak/ao_async.c b/src/micropeak/ao_async.c index 04bba9e8..3556f54c 100644 --- a/src/micropeak/ao_async.c +++ b/src/micropeak/ao_async.c @@ -21,20 +21,51 @@  #define AO_ASYNC_BAUD	38400l  #define AO_ASYNC_DELAY	(uint8_t) (1000000l / AO_ASYNC_BAUD) +#define LED_PORT	PORTB + +void +ao_async_start(void) +{ +	LED_PORT |= (1 << AO_LED_SERIAL); +} + +void +ao_async_stop(void) +{ +	LED_PORT &= ~(1 << AO_LED_SERIAL); +} +  void  ao_async_byte(uint8_t byte)  {  	uint8_t		b;  	uint16_t	w; -	/* start bit */ - -	/* start     data         stop */ -	w = 0x001 | (byte << 1) | 0x000; +	/*    start           data           stop */ +	w = (0x000 << 0) | (byte << 1) | (0x001 << 9); +	ao_arch_block_interrupts();  	for (b = 0; b < 10; b++) { -		ao_led_set((w & 1) << AO_LED_SERIAL); +		uint8_t	v = LED_PORT & ~(1 << AO_LED_SERIAL); +		v |= (w & 1) << AO_LED_SERIAL; +		LED_PORT = v;  		w >>= 1; -		ao_delay_us(26); + +		/* Carefully timed to hit around 9600 baud */ +		asm volatile ("nop"); +		asm volatile ("nop"); + +		asm volatile ("nop"); +		asm volatile ("nop"); +		asm volatile ("nop"); +		asm volatile ("nop"); +		asm volatile ("nop"); + +		asm volatile ("nop"); +		asm volatile ("nop"); +		asm volatile ("nop"); +		asm volatile ("nop"); +		asm volatile ("nop");  	} +	ao_arch_release_interrupts();  } diff --git a/src/micropeak/ao_async.h b/src/micropeak/ao_async.h index a06d2e1a..1b239712 100644 --- a/src/micropeak/ao_async.h +++ b/src/micropeak/ao_async.h @@ -19,6 +19,12 @@  #define _AO_ASYNC_H_  void +ao_async_start(void); + +void +ao_async_stop(void); + +void  ao_async_byte(uint8_t byte);  #endif /* _AO_ASYNC_H_ */ diff --git a/src/micropeak/ao_log_micro.c b/src/micropeak/ao_log_micro.c index 40a7a35d..d665efb5 100644 --- a/src/micropeak/ao_log_micro.c +++ b/src/micropeak/ao_log_micro.c @@ -49,6 +49,46 @@ ao_log_micro_data(void)  	}  } +#define POLY 0x8408 + +static uint16_t +ao_log_micro_crc(uint16_t crc, uint8_t byte) +{ +	uint8_t	i; + +	for (i = 0; i < 8; i++) { +		if ((crc & 0x0001) ^ (byte & 0x0001)) +			crc = (crc >> 1) ^ POLY; +		else +			crc = crc >> 1; +		byte >>= 1; +	} +	return crc; +} + +static void +ao_log_hex_nibble(uint8_t b) +{ +	if (b < 10) +		ao_async_byte('0' + b); +	else +		ao_async_byte('a' - 10 + b); +} + +static void +ao_log_hex(uint8_t b) +{ +	ao_log_hex_nibble(b>>4); +	ao_log_hex_nibble(b&0xf); +} + +static void +ao_log_newline(void) +{ +	ao_async_byte('\r'); +	ao_async_byte('\n'); +} +  void  ao_log_micro_dump(void)  { @@ -56,13 +96,26 @@ ao_log_micro_dump(void)  	uint16_t	nbytes;  	uint8_t		byte;  	uint16_t	b; +	uint16_t	crc = 0xffff;  	ao_eeprom_read(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples)); +	if (n_samples == 0xffff) +		n_samples = 0;  	nbytes = STARTING_LOG_OFFSET + sizeof (uint16_t) * n_samples; +	ao_async_start();  	ao_async_byte('M');  	ao_async_byte('P');  	for (b = 0; b < nbytes; b++) { +		if ((b & 0xf) == 0) +			ao_log_newline();  		ao_eeprom_read(b, &byte, 1); -		ao_async_byte(byte); +		ao_log_hex(byte); +		crc = ao_log_micro_crc(crc, byte);  	} +	ao_log_newline(); +	crc = ~crc; +	ao_log_hex(crc >> 8); +	ao_log_hex(crc); +	ao_log_newline(); +	ao_async_stop();  } diff --git a/src/micropeak/ao_micropeak.c b/src/micropeak/ao_micropeak.c index 3bbc7eea..f579a09a 100644 --- a/src/micropeak/ao_micropeak.c +++ b/src/micropeak/ao_micropeak.c @@ -19,6 +19,7 @@  #include <ao_micropeak.h>  #include <ao_ms5607.h>  #include <ao_log_micro.h> +#include <ao_async.h>  static struct ao_ms5607_sample	sample;  static struct ao_ms5607_value	value; | 
