updates from head

This commit is contained in:
Andrew J. Kroll 2013-09-02 04:09:49 -04:00
parent d46f251345
commit 5dcc65cab9
2 changed files with 85 additions and 78 deletions

View file

@ -12,31 +12,43 @@ PROGRAMMER = arduino
# set your Arduino tty port here # set your Arduino tty port here
PORT = /dev/ttyUSB0 PORT = /dev/ttyUSB0
EXTRA_FLAGS = -D _FS_TINY=0 EXTRA_FLAGS = -D _USE_LFN=3
EXTRA_FLAGS += -D _USE_LFN=1
# change to 0 if you have quadram to take advantage of caching FAT
EXTRA_FLAGS += -D _FS_TINY=1
EXTRA_FLAGS += -D _MAX_SS=512
# Don't worry if you don't have external RAM, xmem2 detects this situation. # Don't worry if you don't have external RAM, xmem2 detects this situation.
# You *WILL* be wanting to get some kind of external ram on your mega in order to # You *WILL* be wanting to get some kind of external ram on your mega in order to
# do anything that is intense. # do anything that is intense.
EXTRA_FLAGS += -D HAVEXMEM=1
EXTRA_FLAGS += -D EXT_RAM_STACK=1 EXTRA_FLAGS += -D EXT_RAM_STACK=1
EXTRA_FLAGS += -D EXT_RAM_HEAP=1 EXTRA_FLAGS += -D EXT_RAM_HEAP=1
# These are no longer needed for the demo to work.
# In the event you need more ram, uncomment these 3 lines.
#EXTRA_FLAGS += -D DISABLE_SERIAL1
#EXTRA_FLAGS += -D DISABLE_SERIAL2
#EXTRA_FLAGS += -D DISABLE_SERIAL3
EXTRA_FLAGS += -D DISABLE_SERIAL1 #
EXTRA_FLAGS += -D DISABLE_SERIAL2 # Advanced debug on Serial3
EXTRA_FLAGS += -D DISABLE_SERIAL3 #
# You should not need to change this, but I place it here if you want to play. # uncomment the next two to enable debug on Serial3
# These are the defaults for the optimization of the flash and ram EXTRA_FLAGS += -D USB_HOST_SERIAL=Serial3
#OPT_FLAGS = -Os -fno-exceptions -ffunction-sections -fdata-sections -MMD #EXTRA_FLAGS += -D DEBUG_USB_HOST
# The following are the libraries used. # The following are the libraries used.
LIB_DIRS = LIB_DIRS =
LIB_DIRS += ../../ LIB_DIRS += ../libraries/xmem
LIB_DIRS += ../testusbhostFAT/xmem2 LIB_DIRS += ../libraries/USB_Host_Shield_2_0
LIB_DIRS += ../testusbhostFAT/generic_storage LIB_DIRS += ../libraries/generic_storage
LIB_DIRS += ../libraries/RTClib
LIB_DIRS += $(ARD_HOME)/libraries/Wire
LIB_DIRS += $(ARD_HOME)/libraries/Wire/utility
# And finally, the part that brings everything together for you. # And finally, the part that brings everything together for you.
include Arduino_Makefile_master/_Makefile.master include ../Arduino_Makefile_master/_Makefile.master

View file

@ -1,47 +1,73 @@
/* /*
* Mega + USB storage + optional expansion RAM + funky status LED, * Mega + USB storage + optional DS1307 + optional expansion RAM + funky status LED,
* Includes interactive debug level setting, and supports emulated hot-plug. * Includes interactive debug level setting, and supports hot-plug.
* *
* IMPORTANT! PLEASE USE Arduino 1.0.5 or better! * IMPORTANT! PLEASE USE Arduino 1.0.5 or better!
* Older versions HAVE MAJOR BUGS AND WILL NOT WORK AT ALL! * Older versions HAVE MAJOR BUGS AND WILL NOT WORK AT ALL!
* Use of gcc-avr and lib-c that is newer than the Arduino version is even better. * Use of gcc-avr and lib-c that is newer than the Arduino version is even better.
* If you experience random crashes, use make.
* The options that the IDE use can generate bad code and cause the AVR to crash.
*
* This sketch requires the following libraries:
* https://github.com/felis/USB_Host_Shield_2.0 Install as 'USB_Host_Shield_2_0'
* https://github.com/xxxajk/xmem2 Install as 'xmem', provides memory services.
* https://github.com/xxxajk/generic_storage provides access to FAT file system.
* https://github.com/xxxajk/RTClib provides access to DS1307, or fake clock.
*
* Optional, to use the Makefile (Recommended! See above!):
* https://github.com/xxxajk/Arduino_Makefile_master
* *
*/ */
#define WANT_HUB_TEST 1 // You can set this to 0 if you are not using a USB hub.
#ifndef HAVE_XMEM // It will save a little bit of flash and RAM.
// Set this to zero to disable xmem // Set to 1 if you want to use a hub.
#define HAVE_XMEM 1 #define WANT_HUB_TEST 0
/////////////////////////////////////////////////////////////
// Please Note: This section is for Arduino IDE ONLY. //
// Use of Make creates a flash image that is 3.3KB smaller //
/////////////////////////////////////////////////////////////
#ifndef USING_MAKEFILE
// Uncomment to enable debugging
//#define DEBUG_USB_HOST
// This is where stderr/USB debugging goes to
#define USB_HOST_SERIAL Serial3
// If you have external memory, setting this to 0 enables FAT table caches.
// The 0 setting is recommended only if you have external memory.
#define _FS_TINY 1
// These you can safely leave alone.
#define _USE_LFN 3
#define EXT_RAM_STACK 1
#define EXT_RAM_HEAP 1
#define _MAX_SS 512
#endif #endif
/////////////////////////////////////////////////////////////
// End of Arduino IDE specific hacks //
/////////////////////////////////////////////////////////////
#include <avr/pgmspace.h>
#if HAVE_XMEM
#include <xmem.h> #include <xmem.h>
#endif
#include <avrpins.h>
#include <max3421e.h> #include <max3421e.h>
#include <usbhost.h> #include <usbhost.h>
#include <usb_ch9.h> #include <usb_ch9.h>
#include <address.h>
#include <Usb.h> #include <Usb.h>
#if WANT_HUB_TEST #if WANT_HUB_TEST
#include <usbhub.h> #include <usbhub.h>
#endif #endif
#include <RTClib.h> #include <avrpins.h>
#include <avr/pgmspace.h>
#include <address.h>
#include <masstorage.h> #include <masstorage.h>
#include <Storage.h>
#include <PCpartition/PCPartition.h>
#include <message.h> #include <message.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <PCpartition/PCPartition.h>
#include <Storage.h>
#include <FAT/FAT.h> #include <FAT/FAT.h>
#include <Wire.h>
#include <RTClib.h>
// Warning! Do not use this unless you are aware of what it does!
#if HAVE_XMEM
#define GOD_MODE 0
#endif
static FILE tty_stdio; static FILE tty_stdio;
static FILE tty_stderr; static FILE tty_stderr;
USB Usb; USB Usb;
@ -66,7 +92,7 @@ int cpart = 0;
PCPartition *PT; PCPartition *PT;
#if WANT_HUB_TEST #if WANT_HUB_TEST
#define MAX_HUBS 2 #define MAX_HUBS 1
USBHub *Hubs[MAX_HUBS]; USBHub *Hubs[MAX_HUBS];
#endif #endif
@ -89,10 +115,12 @@ extern "C" unsigned int freeHeap();
static int tty_stderr_putc(char c, FILE *t) { static int tty_stderr_putc(char c, FILE *t) {
USB_HOST_SERIAL.write(c); USB_HOST_SERIAL.write(c);
return 0;
} }
static int tty_std_putc(char c, FILE *t) { static int tty_std_putc(char c, FILE *t) {
Serial.write(c); Serial.write(c);
return 0;
} }
static int tty_std_getc(FILE *t) { static int tty_std_getc(FILE *t) {
@ -196,23 +224,22 @@ void setup() {
printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap()); printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap());
} }
#endif #endif
// Initialize generic storage. This must be done before USB starts.
InitStorage();
while (Usb.Init(1000) == -1) { while (Usb.Init(1000) == -1) {
printf_P(PSTR("No\r\n")); printf_P(PSTR("No USB HOST Shield?\r\n"));
Notify(PSTR("OSC did not start."), 0x40); Notify(PSTR("OSC did not start."), 0x40);
} }
// usb VBUS _OFF_ // usb VBUS _OFF_
Usb.gpioWr(0x00); //Usb.gpioWr(0x00);
digitalWrite(2, 0); //digitalWrite(2, 0);
usbon_time = millis() + 2000; //usbon_time = millis() + 2000;
cli(); cli();
TCCR3A = 0; TCCR3A = 0;
TCCR3B = 0; TCCR3B = 0;
// (0.01/(1/((16 *(10^6)) / 8))) - 1 = 19999 // (0.01/(1/((16 *(10^6)) / 8))) - 1 = 19999
#if GOD_MODE
OCR3A = 10;
#else
OCR3A = 19999; OCR3A = 19999;
#endif
TCCR3B |= prescale8; TCCR3B |= prescale8;
TIMSK3 |= (1 << OCIE1A); TIMSK3 |= (1 << OCIE1A);
sei(); sei();
@ -220,10 +247,6 @@ void setup() {
HEAPnext_time = millis() + 10000; HEAPnext_time = millis() + 10000;
} }
#if GOD_MODE
volatile uint16_t *foof = reinterpret_cast<uint16_t *>(0x2200);
#endif
void serialEvent() { void serialEvent() {
// Adjust UsbDEBUGlvl level on-the-fly. // Adjust UsbDEBUGlvl level on-the-fly.
// + to increase, - to decrease, * to display current level. // + to increase, - to decrease, * to display current level.
@ -259,30 +282,11 @@ void serialEvent() {
change = true; change = true;
usbon = false; usbon = false;
break; break;
#if GOD_MODE
case 'z':
cli();
*foof = 0xffff;
*(foof + 2) = 0x0000;
sei();
break;
#endif
} }
} }
} }
ISR(TIMER3_COMPA_vect) { ISR(TIMER3_COMPA_vect) {
#if GOD_MODE
#if !EXT_RAM_HEAP && !EXT_RAM_STACK
// Super cool debug feature to detect stack and heap collisions.
// We can use this in conjuction with the AVR dragon
// to check max depth of the stack and height of heap.
if (*foof >= (uint16_t)(SP)) {
*foof = (uint16_t)(SP);
*(foof + 2) = (uint16_t)__brkval;
}
#endif
#endif
if (millis() >= LEDnext_time) { if (millis() >= LEDnext_time) {
LEDnext_time = millis() + 30; LEDnext_time = millis() + 30;
@ -320,12 +324,6 @@ void loop() {
if (millis() >= HEAPnext_time) { if (millis() >= HEAPnext_time) {
if (UsbDEBUGlvl > 0x50) { if (UsbDEBUGlvl > 0x50) {
printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap()); printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap());
#if GOD_MODE
cli();
uint16_t p = *foof;
sei();
printf_P(PSTR("MAXSP %4.4x, current %4.4x\r\n"), p, SP);
#endif
} }
HEAPnext_time = millis() + 10000; HEAPnext_time = millis() + 10000;
} }
@ -340,13 +338,10 @@ void loop() {
if (change) { if (change) {
change = false; change = false;
if (usbon) { if (usbon) {
Usb.vbusPower(VBUS_t(on));
printf_P(PSTR("VBUS on\r\n")); printf_P(PSTR("VBUS on\r\n"));
Usb.gpioWr(0xFF);
digitalWrite(2, 1);
} else { } else {
Usb.gpioWr(0x00); Usb.vbusPower(VBUS_t(off));
digitalWrite(2, 0);
usbon = false;
usbon_time = millis() + 2000; usbon_time = millis() + 2000;
} }
} }