Subversion Repositories Projects

Compare Revisions

Regard whitespace Rev 506 → Rev 507

/C-OSD/trunk/spi.c
24,10 → 24,10
#include "main.h"
 
volatile uint16_t icnt = 0;
volatile unsigned char * iptr;
volatile unsigned char spi_cmd_buffer[8];
volatile uint8_t request_count = 0;
volatile uint8_t spi_ready = 1;
int16_t ampere = 0, max_ampere = 0;
volatile union SPI_buffer_t SPI_buffer;
int16_t ampere = 0, max_ampere = 0, s_volt;
int32_t ampere_wasted = 0;
 
#define INT0_HIGH PORTD |= (1 << PD2);
53,9 → 53,13
* SPI interrupt handler
*/
ISR(SPI_STC_vect) {
*iptr++ = SPDR; // safe received byte to buffer
icnt--; // dec length
if (icnt) {
if (request_count == 0) {
SPI_buffer.buffer.chk = SPDR; // firs char received is check byte from last transfer
} else {
SPI_buffer.buffer.c[request_count - 1] = SPDR; // safe received byte to buffer
}
request_count++;
if (--icnt) {
//SPDR = *iptr; // send next byte
spi_ready = 1; // we _should_ send later because the slave needs more time
} else {
72,15 → 76,24
}
 
/**
* start a new transfer of <data> with length <len>
* start a new transfer with length <len>
*/
void StartTransfer(unsigned char *data, uint16_t len) {
void StartTransfer(uint16_t len) {
INT0_LOW // /SS LOW ^= SS HIGH ^= slave should listen
 
// this is a new request
request_count = 0;
 
// set up pointer and length for interrupt handler
iptr = data;
icnt = len;
 
SPCR |= _BV(SPIE); // enable spi interrupt
SPDR = *iptr; // start transfer by first bye
SPDR = 'A'; // start transfer by first command char
}
 
/**
* send next command through spi
*/
void spi_send_next() {
SPDR = 'A' + request_count;
}