Code for talking to the MAX3420 USB Device Controller.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 26 Feb 2012 01:11:36 +0000 (01:11 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 26 Feb 2012 01:11:36 +0000 (01:11 +0000)
I might make a monitor for this later, but FTDI is cheaper.

git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@1099 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

firmware/Makefile
firmware/apps/usb/maxusb.c [new file with mode: 0644]
firmware/config.mk
firmware/include/maxusb.h [new file with mode: 0644]
firmware/include/spi.h

index 4df4028..30695a5 100644 (file)
@@ -141,6 +141,14 @@ ifeq ($(filter jtag, $(config)), jtag)
        endif
 endif
 
        endif
 endif
 
+# include MAX342x USB drivers.
+ifeq ($(filter maxusb, $(config)), maxusb)
+       ifneq ($(filter apps/usb/maxusb.o, $(apps)), apps/usb/maxusb.o)
+               apps+= apps/usb/maxusb.o
+               hdrs+= maxusb.h
+       endif
+endif
+
 # include the sbw defs if they specified it
 ifeq ($(filter sbw, $(config)), sbw)
        # if they only specify sbw, include jtag
 # include the sbw defs if they specified it
 ifeq ($(filter sbw, $(config)), sbw)
        # if they only specify sbw, include jtag
diff --git a/firmware/apps/usb/maxusb.c b/firmware/apps/usb/maxusb.c
new file mode 100644 (file)
index 0000000..dbe554a
--- /dev/null
@@ -0,0 +1,99 @@
+/*! \file max3421.c
+  \author Travis Goodspeed
+  \brief SPI Driver for MAX342x USB Controllers
+*/
+
+
+#include "command.h"
+
+#ifdef __MSPGCC__
+#include <msp430.h>
+#else
+#include <signal.h>
+#include <msp430.h>
+#include <iomacros.h>
+#endif
+
+#include "maxusb.h"
+
+#define MAXUSBAPPLICATION
+
+#include "platform.h"
+
+
+// define the spi app's app_t
+app_t const maxusb_app = {
+
+       /* app number */
+       MAXUSB,
+
+       /* handle fn */
+       maxusb_handle_fn,
+
+       /* name */
+       "MAXUSB",
+
+       /* desc */
+       "\tThis allows you to write USB Host or USB Device drivers for\n"
+       "\t the MAX3421 and MAX3420 chips.\n"
+};
+
+//! Set up the pins for SPI mode.
+void maxusb_setup(){
+  SETSS;
+  SPIDIR|=MOSI+SCK+BIT0; //BIT0 might be SS
+  SPIDIR&=~MISO;
+  P4DIR&=~TST; //TST line becomes interrupt input.
+  P2DIR|=RST;
+  DIRSS;
+  
+  
+  //Setup the configuration pins.
+  //This might need some delays.
+  CLRRST; //Put the chip into RESET.
+  debugstr("MAXUSB is off.");
+  SETSS;  //Deselect the chip, end any existing transation.
+  SETRST; //Bring the chip out of RESET.
+  debugstr("MAXUSB is on.");
+}
+
+
+
+//! Handles a MAXUSB monitor command.
+void maxusb_handle_fn( uint8_t const app,
+                      uint8_t const verb,
+                      uint32_t const len){
+  unsigned long i;
+
+  //Raise !SS to end transaction, just in case we forgot.
+  SETSS;
+
+  switch(verb){
+  case READ:
+  case WRITE:
+    CLRSS; //Drop !SS to begin transaction.
+    for(i=0;i<len;i++)
+      cmddata[i]=spitrans8(cmddata[i]);
+    SETSS;  //Raise !SS to end transaction.
+    txdata(app,verb,len);
+    break;
+
+  case PEEK://TODO peek a register.
+    debugstr("PEEK isn't implemented in MAXUSB");
+    txdata(app,verb,0);
+    break;
+
+  case POKE://TODO poke a register.
+    debugstr("POKE isn't implemented in MAXUSB");
+    txdata(app,verb,0);
+    break;
+    
+  case SETUP:
+    maxusb_setup();
+    txdata(app,verb,0);
+    break;
+  }
+       
+  //Raise !SS to end transaction, in case we forgot.
+  SETSS;
+}
index 773e3d2..5305ca3 100644 (file)
@@ -102,6 +102,7 @@ AVAILABLE_APPS = monitor spi jtag sbw jtag430 jtag430x2 i2c jtagarm7 ejtag jtagx
 # defaults
 CONFIG_monitor    ?= y
 CONFIG_spi        ?= y
 # defaults
 CONFIG_monitor    ?= y
 CONFIG_spi        ?= y
+CONFIG_maxusb     ?= n
 CONFIG_jtag       ?= n
 CONFIG_sbw        ?= n
 CONFIG_jtag430    ?= y
 CONFIG_jtag       ?= n
 CONFIG_sbw        ?= n
 CONFIG_jtag430    ?= y
diff --git a/firmware/include/maxusb.h b/firmware/include/maxusb.h
new file mode 100644 (file)
index 0000000..b3aaca0
--- /dev/null
@@ -0,0 +1,14 @@
+#include "spi.h"
+
+
+#define MAXUSB 0x40
+#define MAXUSB_H
+
+//! Handles a monitor command.
+void maxusb_handle_fn( uint8_t const app,
+                      uint8_t const verb,
+                      uint32_t const len);
+
+extern app_t const maxusb_app;
+
+
index cede5c4..d940605 100644 (file)
@@ -22,6 +22,8 @@
 # define MOSI BIT1
 # define MISO BIT2
 # define SCK  BIT3
 # define MOSI BIT1
 # define MISO BIT2
 # define SCK  BIT3
+# define TST  BIT0
+# define RST  BIT6
 #endif
 
 #define SETMOSI SPIOUT|=MOSI
 #endif
 
 #define SETMOSI SPIOUT|=MOSI