Browse Source

mk2 fw wip

ikari 13 years ago
parent
commit
83f3307680
7 changed files with 71 additions and 49 deletions
  1. 1 1
      src/Makefile
  2. 1 0
      src/cic.c
  3. 14 2
      src/cli.c
  4. 48 31
      src/config.h
  5. 2 2
      src/memory.h
  6. 4 13
      src/sdcard.c
  7. 1 0
      src/sdcard.h

+ 1 - 1
src/Makefile

@@ -55,7 +55,7 @@ TARGET = $(OBJDIR)/sd2snes
 
 
 # List C source files here. (C dependencies are automatically generated.)
-SRC = main.c ff.c ccsbcs.c clock.c uart.c power.c led.c timer.c printf.c sdcard.c spi.c fileops.c rtc.c fpga.c fpga_spi.c snes.c smc.c memory.c filetypes.c faulthandler.c sort.c crc32.c cic.c cli.c xmodem.c
+SRC = main.c ff.c ccsbcs.c clock.c uart.c power.c led.c timer.c printf.c sdcard.c spi.c fileops.c rtc.c fpga.c fpga_spi.c snes.c smc.c memory.c filetypes.c faulthandler.c sort.c crc32.c cic.c cli.c xmodem.c irq.c
 
 
 # List Assembler source files here.

+ 1 - 0
src/cic.c

@@ -20,6 +20,7 @@ enum cicstates get_cic_state() {
   uint8_t state, state_old;
  
   state_old = BITBAND(SNES_CIC_STATUS_REG->FIOPIN, SNES_CIC_STATUS_BIT);
+/* this loop samples at ~10MHz */
   for(count=0; count<1000; count++) {
     state = BITBAND(SNES_CIC_STATUS_REG->FIOPIN, SNES_CIC_STATUS_BIT);
     if(state != state_old) {

+ 14 - 2
src/cli.c

@@ -43,6 +43,7 @@
 #include "memory.h"
 #include "snes.h"
 #include "fpga.h"
+#include "fpga_spi.h"
 #include "cic.h"
 #include "xmodem.h"
 
@@ -56,8 +57,8 @@ static char *curchar;
 
 /* Word lists */
 static char command_words[] =
-  "cd\0reset\0dir\0ls\0test\0resume\0loadrom\0loadraw\0put\0d4\0vmode\0";
-enum { CMD_CD = 0, CMD_RESET, CMD_DIR, CMD_LS, CMD_TEST, CMD_RESUME, CMD_LOADROM, CMD_LOADRAW, CMD_PUT, CMD_D4, CMD_VMODE };
+  "cd\0reset\0dir\0ls\0test\0resume\0loadrom\0loadraw\0put\0d4\0vmode\0mapper\0";
+enum { CMD_CD = 0, CMD_RESET, CMD_DIR, CMD_LS, CMD_TEST, CMD_RESUME, CMD_LOADROM, CMD_LOADRAW, CMD_PUT, CMD_D4, CMD_VMODE, CMD_MAPPER };
 
 /* ------------------------------------------------------------------------- */
 /*   Parse functions                                                         */
@@ -357,6 +358,13 @@ void cmd_put(void) {
   }
 }
 
+void cmd_mapper(void) {
+  int32_t mapper;
+  mapper = parse_unsigned(0,7);
+  set_mapper((uint8_t)mapper & 0x7);
+  printf("mapper set to %ld\n", mapper);
+}
+
 /* ------------------------------------------------------------------------- */
 /*   CLI interface functions                                                 */
 /* ------------------------------------------------------------------------- */
@@ -454,6 +462,10 @@ void cli_loop(void) {
     case CMD_PUT:
       cmd_put();
       break;
+
+    case CMD_MAPPER:
+      cmd_mapper();
+      break;
     }
   }
 }

+ 48 - 31
src/config.h

@@ -1,48 +1,65 @@
 #ifndef _CONFIG_H
 #define _CONFIG_H
 
-#define VER		"0.0.1"
-#define IN_AHBRAM    __attribute__ ((section(".ahbram")))
-
-#define SDCARD_DETECT		(1)
-#define SDCARD_WP		(0)
-#define SD_SUPPLY_VOLTAGE	(1L<<21) /* 3.3V - 3.4V */
-#define CONFIG_SD_BLOCKTRANSFER 1
-#define CONFIG_SD_AUTO_RETRIES	10
-// #define CONFIG_SD_DATACRC	1
-
-
-#define CONFIG_UART_NUM			3
-#define CONFIG_CPU_FREQUENCY		90315789
-#define CONFIG_UART_PCLKDIV		1
-#define CONFIG_UART_TX_BUF_SHIFT	5
-#define CONFIG_UART_BAUDRATE		921600
+#define VER                       "0.0.1"
+#define IN_AHBRAM                 __attribute__ ((section(".ahbram")))
+
+
+#define SD_DT_INT_SETUP()         do {\
+                                    BITBAND(LPC_GPIOINT->IO2IntEnR, SD_DT_BIT) = 1;\
+                                    BITBAND(LPC_GPIOINT->IO2IntEnF, SD_DT_BIT) = 1;\
+                                  } while(0)
+
+#define SD_CHANGE_DETECT          (BITBAND(LPC_GPIOINT->IO2IntStatR, SD_DT_BIT)\
+                                   |BITBAND(LPC_GPIOINT->IO2IntStatF, SD_DT_BIT))
+
+#define SD_CHANGE_CLR()           do {LPC_GPIOINT->IO2IntClr = BV(SD_DT_BIT);} while(0)
+
+#define SD_DT_REG                 LPC_GPIO2
+#define SD_DT_BIT                 3
+#define SD_WP_REG                 LPC_GPIO2
+#define SD_WP_BIT                 4
+
+#define SDCARD_DETECT             (!(BITBAND(SD_DT_REG->FIOPIN, SD_DT_BIT)))
+#define SDCARD_WP                 (BITBAND(SD_WP_REG->FIOPIN, SD_WP_BIT))
+#define SD_SUPPLY_VOLTAGE         (1L<<21) /* 3.3V - 3.4V */
+#define CONFIG_SD_BLOCKTRANSFER   1
+#define CONFIG_SD_AUTO_RETRIES    10
+// #define SD_CHANGE_VECT		
+// #define CONFIG_SD_DATACRC 1
+
+
+#define CONFIG_UART_NUM	          3
+#define CONFIG_CPU_FREQUENCY      90315789
+#define CONFIG_UART_PCLKDIV       1
+#define CONFIG_UART_TX_BUF_SHIFT  5
+#define CONFIG_UART_BAUDRATE      921600
 #define CONFIG_UART_DEADLOCKABLE
 
-#define SPI_SD				1
-#define SPI_FPGA			0
+#define SPI_SD                    1
+#define SPI_FPGA                  0
 
-#define SSP_CLK_DIVISOR_FAST 4
-#define SSP_CLK_DIVISOR_SLOW 250
+#define SSP_CLK_DIVISOR_FAST      4
+#define SSP_CLK_DIVISOR_SLOW      250
 #define SSP_CLK_DIVISOR_FPGA_FAST 6
 #define SSP_CLK_DIVISOR_FPGA_SLOW 16
 
-#define SNES_RESET_REG      LPC_GPIO1
-#define SNES_RESET_BIT      29
+#define SNES_RESET_REG            LPC_GPIO1
+#define SNES_RESET_BIT            29
 /* XXX Rev.B: 1.26 */
-#define SNES_CIC_D0_REG     LPC_GPIO1
-#define SNES_CIC_D0_BIT     26
+#define SNES_CIC_D0_REG           LPC_GPIO1
+#define SNES_CIC_D0_BIT           26
 /* XXX Rev.B: 0.1 */
-#define SNES_CIC_D1_REG     LPC_GPIO1
-#define SNES_CIC_D1_BIT     25
+#define SNES_CIC_D1_REG           LPC_GPIO1
+#define SNES_CIC_D1_BIT           25
 /* XXX Rev.B: 0.0 */
-#define SNES_CIC_STATUS_REG LPC_GPIO0
-#define SNES_CIC_STATUS_BIT 1
+#define SNES_CIC_STATUS_REG       LPC_GPIO0
+#define SNES_CIC_STATUS_BIT       1
 /* XXX Rev.B: 1.29 */
-#define SNES_CIC_PAIR_REG   LPC_GPIO0
-#define SNES_CIC_PAIR_BIT   0
+#define SNES_CIC_PAIR_REG         LPC_GPIO0
+#define SNES_CIC_PAIR_BIT         0
 /* XXX Rev.B: 1.25 */
 
-#define QSORT_MAXELEM   1024
+#define QSORT_MAXELEM             1024
 
 #endif

+ 2 - 2
src/memory.h

@@ -36,8 +36,8 @@
 #define SRAM_MENU_ADDR (0xE00000L)
 #define SRAM_DB_ADDR (0xE20000L)
 #define SRAM_DIR_ADDR (0xE10000L)
-#define SRAM_CMD_ADDR (0xFF1004L)
-#define SRAM_PARAM_ADDR (0xFF1000L)
+#define SRAM_CMD_ADDR (0xFF1000L)
+#define SRAM_PARAM_ADDR (0xFF1004L)
 #define SRAM_MENU_SAVE_ADDR (0xFF0000L)
 #define SRAM_SCRATCHPAD (0xFFFF00L)
 #define SRAM_DIRID (0xFFFFF0L)

+ 4 - 13
src/sdcard.c

@@ -339,14 +339,12 @@ printf("sdInit\n");
 }
 
 /* Detect changes of SD card 0 */
-#ifdef SD_CHANGE_VECT
-ISR(SD_CHANGE_VECT) {
+void sd_changed() {
   if (SDCARD_DETECT)
     disk_state = DISK_CHANGED;
   else
     disk_state = DISK_REMOVED;
 }
-#endif
 
 #ifdef CONFIG_TWINSD
 /* Detect changes of SD card 1 */
@@ -362,16 +360,9 @@ ISR(SD2_CHANGE_VECT) {
 // Public functions
 //
 void sd_init(void) {
-  /*
-  SDCARD_DETECT_SETUP();
-  SDCARD_WP_SETUP();
-  SD_CHANGE_SETUP();
-  */
-#ifdef CONFIG_TWINSD
-  /* Initialize the control lines for card 2 */
-  SD2_SETUP();
-  SD2_CHANGE_SETUP();
-#endif
+  /* enable GPIO interrupt on SD detect pin, both edges */
+  NVIC_EnableIRQ(EINT3_IRQn);
+  SD_DT_INT_SETUP();
 }
 void disk_init(void) __attribute__ ((weak, alias("sd_init")));
 

+ 1 - 0
src/sdcard.h

@@ -42,4 +42,5 @@ DRESULT sd_read(BYTE drv, BYTE *buffer, DWORD sector, BYTE count);
 DRESULT sd_write(BYTE drv, const BYTE *buffer, DWORD sector, BYTE count);
 DRESULT sd_getinfo(BYTE drv, BYTE page, void *buffer);
 
+void    sd_changed(void);
 #endif