Skip to content

Commit

Permalink
Getting there...
Browse files Browse the repository at this point in the history
  • Loading branch information
makestuff committed Dec 8, 2013
1 parent 74bb776 commit e27b5e6
Show file tree
Hide file tree
Showing 7 changed files with 448 additions and 341 deletions.
39 changes: 39 additions & 0 deletions firmware/avr/boards/minimus.h
@@ -0,0 +1,39 @@
#ifndef MOJO_H
#define MOJO_H

// Platform definitions
#define MCU at90usb162
#define XTAL 16000000

// Bootloader definitions
#define FLASH_SIZE_BYTES 16384
#define BOOTLOADER_SEC_SIZE_BYTES 4096

// JTAG/SPI definitions
#define TDO_PORT 1
#define TDI_PORT 1
#define TMS_PORT 1
#define TCK_PORT 1
#define TDO_BIT 3
#define TDI_BIT 2
#define TMS_BIT 0
#define TCK_BIT 1

// EPP definitions
#define EPP_CTRL_NAME C
#define EPP_DATA_NAME D
#define EPP_ADDRSTB 4
#define EPP_DATASTB 5
#define EPP_WRITE 6
#define EPP_WAIT 7

// Serial port definitions
#define SER_NAME D
#define SER_RX 2
#define SER_TX 3
#define SER_CK 5

#define PROG_HWSPI 0
#define REG_ENABLED 0

#endif
12 changes: 8 additions & 4 deletions firmware/avr/boards/mojo.h
Expand Up @@ -10,10 +10,14 @@
#define BOOTLOADER_SEC_SIZE_BYTES 4096

// JTAG/SPI definitions
#define TCK_PORT PORTD
#define bmTCK 0x01
#define TDI_PORT PORTB
#define bmTDI 0x80
#define TDO_PORT 1
#define TDI_PORT 1
#define TMS_PORT 1
#define TCK_PORT 3
#define TDO_BIT 3
#define TDI_BIT 2
#define TMS_BIT 0
#define TCK_BIT 0

// EPP definitions
#define EPP_CTRL_NAME D
Expand Down
14 changes: 11 additions & 3 deletions firmware/avr/debug.c
Expand Up @@ -26,11 +26,19 @@
DDRC |= DEBUG_MASK;
}

#if F_CPU == 8000000
#define DEBUG_COUNT 20
#elif F_CPU == 16000000
#define DEBUG_COUNT 44
#else
#error Unsupported XTAL frequency
#endif

void debugSendByte(uint8 byte) {
uint8 i = 8;
cli();
PORTC &= ~DEBUG_MASK; // PC2 clear
_delay_loop_1(44);
_delay_loop_1(DEBUG_COUNT);
while ( i-- ) {
if ( byte & 0x01 ) {
PORTC |= DEBUG_MASK;
Expand All @@ -40,10 +48,10 @@
byte >>= 1;
//_delay_loop_1(42); 42 43 44 45 46
//_delay_loop_1(46); ^^
_delay_loop_1(44);
_delay_loop_1(DEBUG_COUNT);
}
PORTC |= DEBUG_MASK;
_delay_loop_1(44);
_delay_loop_1(DEBUG_COUNT);
sei();
}

Expand Down
39 changes: 19 additions & 20 deletions firmware/avr/main.c
Expand Up @@ -141,22 +141,22 @@ void doEPP(void) {
uint32 count;
do {
// Read/write flag & channel
byte = usbFetchByte(); eppSendAddrByte(byte);
byte = usbRecvByte(); eppSendAddrByte(byte);

// Count high byte
count = usbFetchByte();
count = usbRecvByte();

// Count high mid byte
count <<= 8;
count |= usbFetchByte();
count |= usbRecvByte();

// Count low mid byte
count <<= 8;
count |= usbFetchByte();
count |= usbRecvByte();

// Count low byte
count <<= 8;
count |= usbFetchByte();
count |= usbRecvByte();

if ( byte & 0x80 ) {
// The host is reading a channel
Expand All @@ -170,7 +170,7 @@ void doEPP(void) {
usbFlushPacket();
while ( !usbInPacketReady() );
}
usbSendByte(byte);
usbPutByte(byte);
count--;
} while ( count );
eppSending(); // AVR writes to FPGA again
Expand All @@ -180,7 +180,7 @@ void doEPP(void) {
} else {
// The host is writing a channel
do {
byte = usbFetchByte();
byte = usbRecvByte();
eppSendDataByte(byte);
count--;
} while ( count );
Expand Down Expand Up @@ -212,24 +212,24 @@ void doSerial(void) {
uint32 count;
do {
// Read/write flag & channel
chan = usbFetchByte(); usartSendByte(chan);
chan = usbRecvByte(); usartSendByte(chan);

// Count high byte
byte = usbFetchByte(); usartSendByte(byte);
byte = usbRecvByte(); usartSendByte(byte);
count = byte;

// Count high mid byte
byte = usbFetchByte(); usartSendByte(byte);
byte = usbRecvByte(); usartSendByte(byte);
count <<= 8;
count |= byte;

// Count low mid byte
byte = usbFetchByte(); usartSendByte(byte);
byte = usbRecvByte(); usartSendByte(byte);
count <<= 8;
count |= byte;

// Count low byte
byte = usbFetchByte(); usartSendByte(byte);
byte = usbRecvByte(); usartSendByte(byte);
count <<= 8;
count |= byte;

Expand Down Expand Up @@ -257,21 +257,20 @@ void doSerial(void) {
::);
UCSR1B = (1<<RXEN1); // TX disabled, RX enabled
while ( !usbInPacketReady() );
SER_PORT &= ~bmSER_TX; // TX low says "I'm ready"
chan = 0;
SER_PORT &= ~bmSER_TX; // TX low says "I'm ready"
do {
byte = usartRecvByte();
if ( !usbReadWriteAllowed() ) {
SER_PORT |= bmSER_TX; // TX high says "I'm not ready"
SER_PORT |= bmSER_TX; // TX high says "I'm not ready"
usbFlushPacket();
while ( !usbInPacketReady() );
SER_PORT &= ~bmSER_TX; // TX low says "OK I'm ready now"
SER_PORT &= ~bmSER_TX; // TX low says "OK I'm ready now"
}
usbSendByte(byte);
usbPutByte(byte);
count--;
} while ( count );
UCSR1B = (1<<TXEN1); // TX enabled, RX disabled
SER_PORT |= bmSER_TX; // TX high says "I acknowledge receipt of your data"
SER_PORT |= bmSER_TX; // TX high says "I acknowledge receipt of your data"
usbFlushPacket(); // flush final packet
usbSelectEndpoint(OUT_ENDPOINT_ADDR); // ready for next command
return; // there cannot be any more work to do
Expand All @@ -284,8 +283,8 @@ void doSerial(void) {
debugSendByte('\r');
#endif
do {
byte = usbFetchByte();
while ( PIND & bmSER_RX ); // ensure RX is still low
byte = usbRecvByte();
while ( PIND & bmSER_RX ); // ensure RX is still low
usartSendByte(byte);
count--;
} while ( count );
Expand Down

0 comments on commit e27b5e6

Please sign in to comment.