From cbc941282074856fc6179761b70a0c9879b0b64d Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Tue, 11 Oct 2011 21:56:36 +0200 Subject: update firmware to @319 --- firmware/spi.c | 190 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 128 insertions(+), 62 deletions(-) (limited to 'firmware/spi.c') diff --git a/firmware/spi.c b/firmware/spi.c index 2b8abb1..b3e3a95 100644 --- a/firmware/spi.c +++ b/firmware/spi.c @@ -36,26 +36,24 @@ #include "spi.h" + void spi_parser(char *buf) { switch(buf[0]) { case CMD_SPI_INIT: - spi_init_usb(); - break; + spi_init_usb(buf[2], buf[3], buf[4]); + break; case CMD_SPI_DEINIT: spi_deinit_usb(); - break; - case CMD_SPI_SPEED: - spi_set_speed_usb((int)buf[2]); - break; + break; case CMD_SPI_SEND: - spi_send_usb(&buf[2], (int)buf[1]); - break; + spi_send_usb(buf[2], &buf[3]); + break; case CMD_SPI_RECV: - spi_receive_usb((int)buf[1]); + spi_receive_usb((int)buf[2]); case CMD_SPI_SEND_AND_RECV: - spi_send_and_receive_usb(&buf[2], (int)buf[1]); - break; + spi_send_and_receive_usb(&buf[3], (int)buf[2]); + break; default: answer[0] = buf[0]; answer[1] = RSP_UNKOWN_CMD; @@ -64,38 +62,111 @@ void spi_parser(char *buf) } } -void spi_init_usb(void) +void spi_init_usb(uint8_t dord, uint8_t mode, uint8_t speed) { answer[0] = CMD_SPI_INIT; - answer[1] = (unsigned char) spi_init(); - answer[3] = 0; + answer[1] = (unsigned char) spi_init(dord, mode, speed); + answer[2] = 0; CommandAnswer(3); } -int spi_init(void) +int spi_init(uint8_t dord, uint8_t mode, uint8_t speed) { - PORTB &= ~((1 << SCK)|(1< 1000) return RSP_TIMEOUT; } - buf[i]=SPDR; + while(!(SPSR & (1 << SPIF))) + { + if(timeout++ > 1000) + return RSP_TIMEOUT; + } + buf[i] = SPDR; } + return RSP_OK; } @@ -164,8 +236,8 @@ void spi_send_and_receive_usb(char * txbuf, int length) { answer[0]=CMD_SPI_SEND; answer[1]=(unsigned char)spi_send_and_receive(txbuf,(char *)&answer[2],length); - answer[2]=0; - CommandAnswer(2+length); + answer[2+length]=0; + CommandAnswer(3+length); } @@ -180,9 +252,3 @@ int spi_send_and_receive(char * txbuf, char * rxbuf, int length){ } return RSP_OK; } - - - - - - -- cgit v1.2.1