No changes between revisions
/Designs/Tools/Oscilloscope/SW/firmware/gnuradio/Makefile
0,0 → 1,33
PRG = scope
OBJ = main.o ./libs/usart.o ./libs/spi.o
MCU_TARGET = atmega8
AVRDUDE_PART = m8
 
OPTIMIZE = -O1
# OPTIMIZE = -Os
 
CC = avr-gcc
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
 
all: hex
 
./libs/spi.o: ./libs/spi.h
./libs/usart.o: ./libs/usart.h
#./libs/timer.o: ./libs/timer.h
 
hex: $(PRG).hex
 
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
 
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
 
load: $(PRG).hex
avrdude -p $(AVRDUDE_PART) -c stk500v2 -P /dev/ttyUSB0 -B 2 -U flash:w:$<
 
clean:
rm -rf *.o $(PRG).elf $(PRG).hex ./libs/*.o
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/Designs/Tools/Oscilloscope/SW/firmware/gnuradio/libs/spi.c
0,0 → 1,20
#include "spi.h"
 
#include <avr/io.h>
 
void SPI_MasterInit(void)
{
/* Enable SPI, Master, set clock rate fck/4, SCK high when idle, sample on rising */
// SPSR|= 0b00000001; //for fck/2
SPCR = 0b01011100;
}
 
char SPI_MasterTransmit(char cData) {
/* Start transmission */
SPDR = cData;
 
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)))
;
return SPDR;
}
/Designs/Tools/Oscilloscope/SW/firmware/gnuradio/libs/spi.h
0,0 → 1,7
#ifndef SPI_H
#define SPI_H
 
void SPI_MasterInit(void);
char SPI_MasterTransmit(char cData);
 
#endif
/Designs/Tools/Oscilloscope/SW/firmware/gnuradio/libs/usart.c
0,0 → 1,128
#include "usart.h"
 
#include <avr/io.h>
 
 
void USART_Init( unsigned int ubrr)
{
/* Set baud rate */
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;
 
/* flush transmitt register Double speed */
UCSRA = (1<<UDRE)|(1 << U2X);
 
/* enable receiver interrupt and transmitter, pins forced */
UCSRB = (1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
 
/* Asynchronous, no parity, Set frame format: 8data, 1stop bit */
UCSRC = (1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1);
}
 
 
void USART_Transmit( unsigned char data )
{
while ( !( UCSRA & (1<<UDRE)) ); /* Wait for empty transmit buffer */
 
UDR = data; /* Put data into buffer, sends the data */
}
 
 
void USART_Transmit_string( char *data )
{
while ( *data != 0 ) {
USART_Transmit(*data);
data++;
}
}
 
 
void USART_Transmit_longnum(signed long data ) {
unsigned char digits[10],i;
 
if (data==0)
USART_Transmit('0');
else { // PROZKOUMAT!
 
if (data<0) {
USART_Transmit('-');
data*=-1;
}
 
for (i=0;i<10;i++) {
digits[i]=data%10;
data=data/10;
}
 
i=9;
while (digits[i]==0) i--;
while (i>0) {
USART_Transmit(digits[i]+48);
i--;
}
USART_Transmit(digits[0]+48);
 
}
}
 
 
void USART_Transmit_uint16 (unsigned int data ) {
unsigned char digits[5],i;
 
if (data==0) //podivne, ale nulu to odeslat neumi
USART_Transmit('0');
else {
 
for (i=0;i<5;i++) {
digits[i]=data%10;
data=data/10;
}
 
i=4;
while (digits[i]==0) i--;
while (i>0) {
USART_Transmit(digits[i]+48);
i--;
}
USART_Transmit(digits[0]+48);
 
}
}
 
 
void USART_Transmit_num(unsigned char data ) {
unsigned char a,b,c;
 
c=data%10;
data=data/10;
b=data%10;
data=data/10;
a=data%10;
 
USART_Transmit(a+48);
USART_Transmit(b+48);
USART_Transmit(c+48);
}
 
 
/*void USART_Transmit_float( float data ) {
int a,b,c;
 
c=((int)data)%10;
b=((int)(data/10))%10;
a=((int)(data/100))%10;
 
USART_Transmit(a+48);
USART_Transmit(b+48);
USART_Transmit(c+48);
}*/
 
 
void USART_Transmit_byte( char data ) {
unsigned char i;
i=0b10000000;
while (i) {
USART_Transmit( ( (i&data)&&1 ) + 48 );
i>>=1;
}
}
/Designs/Tools/Oscilloscope/SW/firmware/gnuradio/libs/usart.h
0,0 → 1,17
#ifndef USART_H
#define USART_H
 
//Inits:
void USART_Init( unsigned int ubrr); // 8b, no parity, 1 stop
// asynchronous, RX interrupt
 
// Busy loops:
void USART_Transmit( unsigned char data ); // send char (1B)
void USART_Transmit_string( char *data ); // send string
void USART_Transmit_num( unsigned char data ); // send ascii
void USART_Transmit_longnum( signed long data ); // send ascii
void USART_Transmit_uint16( unsigned int data ); // send ascii
//void USART_Transmit_float( float data );
void USART_Transmit_byte( char data ); //send in ascii hex reprezentation
 
#endif
/Designs/Tools/Oscilloscope/SW/firmware/gnuradio/main.c
0,0 → 1,38
// Oscilloscope firmware, Roman Pavelka, 2011
// written for atmega8
 
#define F_CPU 16000000
#define BAUD 1000000
//#define MYUBRR F_CPU/8/BAUD-1
#define MYUBRR 1
 
#include "./libs/usart.h"
#include "./libs/spi.h"
 
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <inttypes.h>
 
int main (void) {
USART_Init(MYUBRR);
 
DDRB = 0b00100100; //SCK, SS out
PORTB = 0b00000000; // CONV low
 
SPI_MasterInit();
 
 
while(1)
{
PORTB |= 0b00000100;
_delay_us(4);
PORTB &= 0b11111011; //one conversion
 
USART_Transmit(SPI_MasterTransmit(0x0)); //Binary transfer
USART_Transmit(SPI_MasterTransmit(0x0));
_delay_us(4);
}
return 0;
}
 
/Designs/Tools/Oscilloscope/SW/firmware/Makefile
0,0 → 1,33
PRG = scope
OBJ = main.o ./libs/usart.o ./libs/spi.o
MCU_TARGET = atmega8
AVRDUDE_PART = m8
 
OPTIMIZE = -O1
# OPTIMIZE = -Os
 
CC = avr-gcc
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
 
all: hex
 
./libs/spi.o: ./libs/spi.h
./libs/usart.o: ./libs/usart.h
#./libs/timer.o: ./libs/timer.h
 
hex: $(PRG).hex
 
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
 
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
 
load: $(PRG).hex
avrdude -p $(AVRDUDE_PART) -c stk500v2 -P /dev/ttyUSB0 -B 2 -U flash:w:$<
 
clean:
rm -rf *.o $(PRG).elf $(PRG).hex ./libs/*.o
 
Property changes:
Added: svn:executable
/Designs/Tools/Oscilloscope/SW/firmware/scope.elf
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:executable
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Designs/Tools/Oscilloscope/SW/firmware/scope.hex
0,0 → 1,67
:1000000012C021C020C01FC01EC01DC01CC01BC00C
:100010001AC019C018C053C016C015C014C013C0F0
:1000200012C011C010C011241FBECFE5D4E0DEBF46
:10003000CDBF11E0A0E6B0E001C01D92A832B1072B
:10004000E1F702D0E8C1DCCF81E090E05FD084E24C
:1000500087BB18BA7BD17894FFCF0F931F93CF93B0
:10006000DF93C0E6D0E008E211E0C29A85E18A950C
:10007000F1F70000C29880E06CD1888380E069D1FC
:1000800089832296C017D10781F7DF91CF911F9105
:100090000F9108950F931F93CF93DF93C0E6D0E0A5
:1000A00008E211E088813BD0898139D02296C017BF
:1000B000D107C1F7DF91CF911F910F9108951F9242
:1000C0000F920FB60F9211242F933F934F935F938C
:1000D0006F937F938F939F93AF93BF93EF93FF9310
:1000E0008CB18D3611F4B9DFD5DFFF91EF91BF915F
:1000F000AF919F918F917F916F915F914F913F91C0
:100100002F910F900FBE0F901F90189590BD89B939
:1001100082E28BB988E98AB986E880BD08955D9B43
:10012000FECF8CB90895CF93DF93EC0188818823AB
:1001300029F02196F4DF89918823E1F7DF91CF91AF
:1001400008956F927F928F929F92AF92BF92CF92BB
:10015000DF92EF92FF920F931F93DF93CF93CDB770
:10016000DEB72A970FB6F894DEBF0FBECDBF7B0176
:100170008C01611571058105910519F480E3CFDFCC
:1001800050C0992354F48DE2CADF10950095F09485
:10019000E094E11CF11C011D111D6E010894C11CAD
:1001A000D11C0F2EFBE06F2E7724F02D6C0E7D1EE0
:1001B0000F2EFAE08F2EF0E09F2EF0E0AF2EF0E051
:1001C000BF2EF02DC801B701A5019401E7D0F601BB
:1001D00061936F01E22EF32E042F152FE615F7051C
:1001E00089F78A85882311F019E00CC019E0CE0147
:1001F00001961150FC01E10FF11D20812223C9F36A
:10020000112361F07E010894E11CF11CF701E10F5C
:10021000F11D8081805D83DF1150C1F78981805D90
:100220007EDF2A960FB6F894DEBF0FBECDBFCF910A
:10023000DF911F910F91FF90EF90DF90CF90BF90D3
:10024000AF909F908F907F906F900895FF920F9343
:100250001F93DF93CF9300D000D00F92CDB7DEB7BE
:10026000009719F480E35BDF32C0FE0131968E0106
:100270000A5F1F4F2AE030E0B9017CD08193862FBE
:10028000972FE017F107C1F78D81882321F0FF2414
:100290006894F2F80EC0FF246894F2F8CE0101963B
:1002A000FA94FC01EF0DF11D20812223C9F3FF20F8
:1002B00059F08E010F5F1F4FF801EF0DF11D808186
:1002C000805D2DDFFA94C1F78981805D28DF0F9072
:1002D0000F900F900F900F90CF91DF911F910F9182
:1002E000FF9008950F931F932AE0622F37D0192FA4
:1002F00035D0092F33D0892F805D11DF802F805DAD
:100300000EDF812F805D0BDF1F910F910895EF921B
:10031000FF921F93CF93DF93C8E0D0E010E8E82E60
:10032000FF24E7FCF094812F90E08E219F2100971D
:1003300011F081E301C080E3F2DE1695219799F771
:10034000DF91CF911F91FF90EF9008958CE58DB9CB
:1003500008958FB9779BFECF8FB10895991B79E0EF
:1003600004C0991F961708F0961B881F7A95C9F745
:1003700080950895AA1BBB1B51E107C0AA1FBB1F94
:10038000A617B70710F0A61BB70B881F991F5A9521
:10039000A9F780959095BC01CD01089597FB092E92
:1003A00005260ED057FD04D014D00AD0001C38F416
:1003B00050954095309521953F4F4F4F5F4F089591
:1003C000F6F790958095709561957F4F8F4F9F4F71
:1003D0000895A1E21A2EAA1BBB1BFD010DC0AA1F86
:1003E000BB1FEE1FFF1FA217B307E407F50720F09E
:1003F000A21BB30BE40BF50B661F771F881F991F19
:100400001A9469F760957095809590959B01AC0161
:0A041000BD01CF010895F894FFCF5D
:00000001FF
/Designs/Tools/Oscilloscope/SW/firmware/libs/spi.c
0,0 → 1,20
#include "spi.h"
 
#include <avr/io.h>
 
void SPI_MasterInit(void)
{
/* Enable SPI, Master, set clock rate fck/4, SCK high when idle, sample on rising */
// SPSR|= 0b00000001; //for fck/2
SPCR = 0b01011100;
}
 
char SPI_MasterTransmit(char cData) {
/* Start transmission */
SPDR = cData;
 
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)))
;
return SPDR;
}
/Designs/Tools/Oscilloscope/SW/firmware/libs/spi.h
0,0 → 1,7
#ifndef SPI_H
#define SPI_H
 
void SPI_MasterInit(void);
char SPI_MasterTransmit(char cData);
 
#endif
/Designs/Tools/Oscilloscope/SW/firmware/libs/usart.c
0,0 → 1,128
#include "usart.h"
 
#include <avr/io.h>
 
 
void USART_Init( unsigned int ubrr)
{
/* Set baud rate */
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;
 
/* flush transmitt register Double speed */
UCSRA = (1<<UDRE)|(1 << U2X);
 
/* enable receiver interrupt and transmitter, pins forced */
UCSRB = (1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
 
/* Asynchronous, no parity, Set frame format: 8data, 1stop bit */
UCSRC = (1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1);
}
 
 
void USART_Transmit( unsigned char data )
{
while ( !( UCSRA & (1<<UDRE)) ); /* Wait for empty transmit buffer */
 
UDR = data; /* Put data into buffer, sends the data */
}
 
 
void USART_Transmit_string( char *data )
{
while ( *data != 0 ) {
USART_Transmit(*data);
data++;
}
}
 
 
void USART_Transmit_longnum(signed long data ) {
unsigned char digits[10],i;
 
if (data==0)
USART_Transmit('0');
else { // PROZKOUMAT!
 
if (data<0) {
USART_Transmit('-');
data*=-1;
}
 
for (i=0;i<10;i++) {
digits[i]=data%10;
data=data/10;
}
 
i=9;
while (digits[i]==0) i--;
while (i>0) {
USART_Transmit(digits[i]+48);
i--;
}
USART_Transmit(digits[0]+48);
 
}
}
 
 
void USART_Transmit_uint16 (unsigned int data ) {
unsigned char digits[5],i;
 
if (data==0) //podivne, ale nulu to odeslat neumi
USART_Transmit('0');
else {
 
for (i=0;i<5;i++) {
digits[i]=data%10;
data=data/10;
}
 
i=4;
while (digits[i]==0) i--;
while (i>0) {
USART_Transmit(digits[i]+48);
i--;
}
USART_Transmit(digits[0]+48);
 
}
}
 
 
void USART_Transmit_num(unsigned char data ) {
unsigned char a,b,c;
 
c=data%10;
data=data/10;
b=data%10;
data=data/10;
a=data%10;
 
USART_Transmit(a+48);
USART_Transmit(b+48);
USART_Transmit(c+48);
}
 
 
/*void USART_Transmit_float( float data ) {
int a,b,c;
 
c=((int)data)%10;
b=((int)(data/10))%10;
a=((int)(data/100))%10;
 
USART_Transmit(a+48);
USART_Transmit(b+48);
USART_Transmit(c+48);
}*/
 
 
void USART_Transmit_byte( char data ) {
unsigned char i;
i=0b10000000;
while (i) {
USART_Transmit( ( (i&data)&&1 ) + 48 );
i>>=1;
}
}
/Designs/Tools/Oscilloscope/SW/firmware/libs/usart.h
0,0 → 1,17
#ifndef USART_H
#define USART_H
 
//Inits:
void USART_Init( unsigned int ubrr); // 8b, no parity, 1 stop
// asynchronous, RX interrupt
 
// Busy loops:
void USART_Transmit( unsigned char data ); // send char (1B)
void USART_Transmit_string( char *data ); // send string
void USART_Transmit_num( unsigned char data ); // send ascii
void USART_Transmit_longnum( signed long data ); // send ascii
void USART_Transmit_uint16( unsigned int data ); // send ascii
//void USART_Transmit_float( float data );
void USART_Transmit_byte( char data ); //send in ascii hex reprezentation
 
#endif
/Designs/Tools/Oscilloscope/SW/firmware/main.c
0,0 → 1,79
// Oscilloscope firmware, Roman Pavelka, 2011
// written for atmega8
 
#define F_CPU 16000000
#define BAUD 1000000
//#define MYUBRR F_CPU/8/BAUD-1
#define MYUBRR 1
 
#include "./libs/usart.h"
#include "./libs/spi.h"
 
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <inttypes.h>
 
#define LEN 100
uint8_t data[2*LEN];
 
void measure(void);
void send(void);
 
 
int main (void) {
USART_Init(MYUBRR);
 
DDRB = 0b00100100; //SCK, SS out
PORTB = 0b00000000; // CONV low
 
SPI_MasterInit();
 
sei();
 
while(1) {}
 
return 0;
 
}
 
 
void measure(void) {
uint8_t i;
 
for(i=0;i<LEN;i++) {
PORTB |= 0b00000100;
_delay_us(4);
PORTB &= 0b11111011; //one conversion
 
data[2*i] = SPI_MasterTransmit(0x0);
data[2*i+1] = SPI_MasterTransmit(0x0);
}
}
 
void send(void) {
uint8_t i;
 
for(i=0;i<LEN;i++) {
 
/* USART_Transmit_uint16(data[i]); //ASCII transfer
USART_Transmit('\n');*/
 
USART_Transmit(data[2*i]); //Binary transfer
USART_Transmit(data[2*i+1]);
// USART_Transmit('\n');
 
}
}
 
 
ISR(USART_RXC_vect) {
char data;
 
data=UDR; //must be read to untrigger interupt
 
if (data=='m') {
measure();
send();
}
}