avr_mdcart_sram_lite

diff main.c @ 6:ff8af8351282

works
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 12 Mar 2017 23:43:41 +0200
parents abb348704dec
children f14e14abe14c
line diff
     1.1 --- a/main.c	Sun Mar 12 04:27:43 2017 +0200
     1.2 +++ b/main.c	Sun Mar 12 23:43:41 2017 +0200
     1.3 @@ -64,7 +64,7 @@
     1.4  
     1.5  int main(void)
     1.6  {
     1.7 -	init_serial(38400);
     1.8 +	init_serial(115200);
     1.9  	run_mode();
    1.10  
    1.11  	sei();
    1.12 @@ -101,12 +101,12 @@
    1.13  
    1.14  	case 'p':
    1.15  		prog_mode();
    1.16 -		printf("OK programming mode\n");
    1.17 +		puts("OK programming mode");
    1.18  		break;
    1.19  
    1.20  	case 'b':
    1.21  		run_mode();
    1.22 -		printf("OK boot mode\n");
    1.23 +		puts("OK run mode");
    1.24  		break;
    1.25  
    1.26  	case 'a':
    1.27 @@ -116,26 +116,26 @@
    1.28  
    1.29  	case 'w':
    1.30  		if(running) {
    1.31 -			printf("ERR running\n");
    1.32 +			puts("ERR running");
    1.33  			break;
    1.34  		}
    1.35  		if(addr >= MEM_SIZE) {
    1.36 -			printf("ERR overflow\n");
    1.37 +			puts("ERR overflow");
    1.38  			break;
    1.39  		}
    1.40  
    1.41  		data = strtol(input + 1, &endp, 0);
    1.42  		sram_write(addr++, data);
    1.43 -		printf("OK %d\n", (int)data);
    1.44 +		puts("OK");
    1.45  		break;
    1.46  
    1.47  	case 'r':
    1.48  		if(running) {
    1.49 -			printf("ERR running\n");
    1.50 +			puts("ERR running");
    1.51  			break;
    1.52  		}
    1.53  		if(addr >= MEM_SIZE) {
    1.54 -			printf("ERR overflow\n");
    1.55 +			puts("ERR overflow");
    1.56  			break;
    1.57  		}
    1.58  
    1.59 @@ -144,7 +144,7 @@
    1.60  		break;
    1.61  
    1.62  	default:
    1.63 -		printf("ERR unknown command\n");
    1.64 +		puts("ERR unknown command");
    1.65  		break;
    1.66  	}
    1.67  }
    1.68 @@ -152,14 +152,15 @@
    1.69  void run_mode(void)
    1.70  {
    1.71  	/* tri-state everything and release the reset line */
    1.72 +	/* do not tri-state WE and keep it high */
    1.73  	DDRA = 0;
    1.74  	PORTA = 0;
    1.75  	DDRB = 0;
    1.76  	PORTB = 0;
    1.77  	DDRC = 0;
    1.78  	PORTC = 0;
    1.79 -	DDRD = RST_BIT;
    1.80 -	PORTD = RST_BIT;
    1.81 +	DDRD = RST_BIT | WE_BIT;
    1.82 +	PORTD = RST_BIT | WE_BIT;
    1.83  
    1.84  	running = 1;
    1.85  }
    1.86 @@ -167,7 +168,7 @@
    1.87  void prog_mode(void)
    1.88  {
    1.89  	/* hold the reset line and take control of the bus */
    1.90 -	PORTD = 0;
    1.91 +	PORTD = WE_BIT;	/* keep WE high to avoid writing random bytes */
    1.92  	DDRD = 0xff;
    1.93  	DDRA = 0xff;
    1.94  	DDRB = 0xff;
    1.95 @@ -192,7 +193,6 @@
    1.96  
    1.97  	/* pulse WE */
    1.98  	PORTD &= ~WE_BIT;
    1.99 -	_delay_us(0.1);
   1.100  	/* WE should be low for at least 9ns, which is way faster than we can toggle it anyway */
   1.101  	PORTD |= WE_BIT;
   1.102  }