spi protocol defined?

master
Dario Ernst 15 years ago
parent aa90daa614
commit b199352e54

@ -24,3 +24,7 @@ Where following values are Valid:
| 0000005 0x05 Write-Var16 Number of the Value of Var Value of Var zeroes/Rand Writes 16 |
| var-DEFINE to write (HIGH) to write (LOW) Bit Var |
|--------------------------------------------------------------------------------------------------------------------------|
| 0000006 0x07 Call-Func Number of the zeroes/Rand zeroes/Rand zeroes/Rand Calls a |
| func-DEFINE remote |
function |
|--------------------------------------------------------------------------------------------------------------------------|

@ -1,17 +1,28 @@
#include <avr/io.h>
#include <stdint.h>
#include <math.h>
#include "main.h"
#include <spi.h>
uint16_t *spi_proto_globals8[] = {
&foo
};
uint8_t *spi_proto_globals16[] = {
&bar
};
funptr_t spi_proto_funcs[] = {
&baz
};
/* SPI framework.
*
* currently alpha, uses interrupts, single master/single slave operation
*/
uint8_t * volatile spi_writeptr;
uint8_t * volatile spi_readptr;
uint8_t volatile spi_writelen;
@ -19,6 +30,8 @@ uint8_t volatile spi_readlen;
uint8_t spi_readbuf[SPI_READBUF_LEN];
void spi_init(){
uint8_t spcr, spsr, d;

@ -1,11 +1,14 @@
#ifndef __SPI_H
#define __SPI_H
#include "spi_proto.h"
#define SPI_BAUDRATE 1000000
#define SPI_MASTER 1
#define SPI_READBUF_LEN 32
#define SPI_SS_PORT D
#define SPI_SS_PIN 7
// copied/adapted from usbdrv.h
#define SPI_CONCAT(a, b) a ## b
@ -19,3 +22,5 @@
uint8_t spi_write(uint8_t *data, uint8_t len);
void spi_init();
#endif

@ -0,0 +1,30 @@
#include "spi_proto.h"
uint8_t spi_proto_needswrite(uint8_t opcode) {
if(opcode == 4 || opcode == 5) return 1;
return 0;
}
uint16_t spi_proto_handlewrite(uint8_t opcode, uint8_t addr) {
if(opcode == 4) {
return (uint16_t) (*spi_proto_globals8[addr]);
} else if(opcode == 5) {
return (*spi_proto_globals16[addr]);
} else {
return 0xFFFF;
}
}
void spi_proto_handleread(uint8_t opcode, uint8_t addr, uint16_t data) {
if(opcode == 2) {
*spi_proto_globals8[addr] = (uint8_t) data;
} else if(opcode == 3) {
*spi_proto_globals16[addr] = data;
} else if (opcode == 6) {
funptr_t func = spi_proto_funcs[addr];
(*func)();
} else {
// boom
}
}

@ -0,0 +1,18 @@
#ifndef __SPIPROTO_H
#define __SPIPROTO_H
#include <stdint.h>
#include "main.h"
typedef void(*funptr_t)();
extern uint16_t *spi_proto_globals8[];
extern uint8_t *spi_proto_globals16[];
extern funptr_t spi_proto_funcs[];
uint8_t spi_proto_needswrite(uint8_t opcode);
uint16_t spi_proto_handlewrite(uint8_t opcode, uint8_t addr);
void spi_proto_handleread(uint8_t opcode, uint8_t addr, uint16_t data);
#endif

@ -2,7 +2,7 @@ include ../Makefile.inc
COMPILE = avr-gcc $(CFLAGS) $(DEFINES)
OBJECTS = main.o mcp_adc.o i2c_simple.o softtimer.o
OBJECTS = main.o mcp_adc.o i2c_simple.o softtimer.o spi_proto.o spi.o
# symbolic targets:
all: firmware.hex

@ -1,6 +1,13 @@
#include "main.h"
#include "spi.h"
uint16_t foo = 16;
uint8_t bar = 8;
void baz() {
}
void hardinit() {
/* initializes the hardware */

@ -1,5 +1,6 @@
#ifndef __MAIN_H
#define __MAIN_H
#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
@ -12,4 +13,9 @@
#define SOFTTIMERNUMS 4
#include "softtimer.h"
extern uint16_t foo;
extern uint8_t bar;
void baz();
#endif //__MAIN_H

@ -0,0 +1 @@
../shared/spi_proto.c

@ -0,0 +1 @@
../shared/spi_proto.h
Loading…
Cancel
Save