OSDN Git Service

実験的ソースをコミット
authornaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Mon, 14 Dec 2009 07:14:51 +0000 (07:14 +0000)
committernaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Mon, 14 Dec 2009 07:14:51 +0000 (07:14 +0000)
git-svn-id: svn+ssh://svn.osdn.net/svnroot/unagi@329 24ea1065-a21e-4ca1-99c9-f5125deb0858

kazzo/trunk/firmware/avr_main.c
kazzo/trunk/firmware/bus_access.c
kazzo/trunk/firmware/firmware.mak
kazzo/trunk/firmware/flashmemory.c
kazzo/trunk/firmware/kazzo_request.h
kazzo/trunk/firmware/kazzo_task.h [new file with mode: 0644]

index 371d0ce..380853f 100644 (file)
@@ -1,6 +1,7 @@
 #include <avr/wdt.h>
 #include <avr/interrupt.h>
 #include <util/delay.h>
+#include <string.h>
 #include "usbdrv.h"
 #include "bus_access.h"
 #include "disk_access.h"
 #include "kazzo_request.h"
 
 //---- global variable ----
+#define REQUEST_NOP (0xee)
 static struct write_command{
        enum request request;
        uint16_t address, length, offset;
-}write_command;
+}request_both_write, request_cpu_program, request_ppu_program;
 
 //---- function start ----
+static void flash_config_set(const uint8_t *t, void (*set)(uint16_t, uint16_t, uint16_t, uint16_t))
+{
+       uint16_t c000x, c2aaa, c5555, unit;
+       c000x = t[0];
+       c000x |= t[1] << 8;
+       c2aaa = t[2];
+       c2aaa |= t[3] << 8;
+       c5555 = t[4];
+       c5555 |= t[5] << 8;
+       unit = t[6];
+       unit |= t[7] << 8;
+       (*set)(c000x, c2aaa, c5555, unit);
+}
+static uint8_t cpu_buffer[FLASH_PACKET_SIZE];
+static uint8_t ppu_buffer[FLASH_PACKET_SIZE];
 uchar usbFunctionWrite(uchar *data, uchar len)
 {
-       static uint8_t cpu_buffer[FLASH_PACKET_SIZE];
-       static uint8_t ppu_buffer[FLASH_PACKET_SIZE];
+//     static uint8_t cpu_buffer[FLASH_PACKET_SIZE];
+//     static uint8_t ppu_buffer[FLASH_PACKET_SIZE];
        const uint16_t length = (uint16_t) len;
        
-       switch(write_command.request){
+       switch(request_both_write.request){
        case REQUEST_CPU_WRITE_6502:
-               cpu_write_6502(write_command.address + write_command.offset, length, data);
-               break;
+               cpu_write_6502(request_both_write.address + request_both_write.offset, length, data);
+               goto BOTH_NEXT;
        case REQUEST_CPU_WRITE_FLASH:
-               cpu_write_flash(write_command.address + write_command.offset, length, data);
-               break;
+               cpu_write_flash(request_both_write.address + request_both_write.offset, length, data);
+               goto BOTH_NEXT;
        case REQUEST_PPU_WRITE:
-               ppu_write(write_command.address + write_command.offset, length, data);
+               ppu_write(request_both_write.address + request_both_write.offset, length, data);
+               goto BOTH_NEXT;
+       BOTH_NEXT:{
+               request_both_write.offset += length;
+               int ret = request_both_write.offset == request_both_write.length;
+               if(ret){
+                       request_both_write.request = REQUEST_NOP;
+               }
+               return ret;
+               }
+       default:
                break;
+       }
+       switch(request_cpu_program.request){
        case REQUEST_CPU_FLASH_PROGRAM:
-       case REQUEST_PPU_FLASH_PROGRAM:{
+       case REQUEST_CPU_FLASH_CONFIG_SET:{
                static uint8_t *w = cpu_buffer; //this is static pointer! be careful.
-               if(write_command.offset == 0){
-                       if(write_command.request == REQUEST_CPU_FLASH_PROGRAM){
-                               w = cpu_buffer;
-                       }else{
-                               w = ppu_buffer;
-                       }
+               if(request_cpu_program.offset == 0){
+                       w = cpu_buffer;
                }
-               while(len != 0){
-                       *w = *data;
-                       w++;
-                       data++;
-                       write_command.offset += 1;
-                       len--;
-               }
-               if(write_command.length == write_command.offset){
-                       if(write_command.request == REQUEST_CPU_FLASH_PROGRAM){
-                               flash_cpu_program(write_command.address, write_command.length, cpu_buffer);
+               memcpy(w, data, length);
+               w += length;
+               request_cpu_program.offset += length;
+               int ret = request_cpu_program.offset >= request_cpu_program.length;
+               if(ret){
+                       if(request_cpu_program.request == REQUEST_CPU_FLASH_CONFIG_SET){
+                               flash_config_set(cpu_buffer, flash_cpu_config);
                        }else{
-                               flash_ppu_program(write_command.address, write_command.length, ppu_buffer);
+                               flash_cpu_program(request_cpu_program.address, request_cpu_program.length, cpu_buffer);
                        }
+                       request_cpu_program.request = REQUEST_NOP;
                }
-               }return write_command.length == write_command.offset;
-       case REQUEST_CPU_FLASH_CONFIG_SET:
+               return ret;}
+       default:
+               break;
+       }
+       switch(request_ppu_program.request){
+       case REQUEST_PPU_FLASH_PROGRAM:
        case REQUEST_PPU_FLASH_CONFIG_SET:{
-               static uint16_t c000x, c2aaa, c5555, unit;
-               while(len != 0){
-                       switch(write_command.offset){
-                       case 0:
-                               c000x = *data;
-                               break;
-                       case 1:
-                               c000x |= *data;
-                               break;
-                       case 2:
-                               c2aaa = *data;
-                               break;
-                       case 3:
-                               c2aaa |= *data << 8;
-                               break;
-                       case 4:
-                               c5555 = *data;
-                               break;
-                       case 5:
-                               c5555 |= *data << 8;
-                               break;
-                       case 6:
-                               unit = *data;
-                               break;
-                       case 7:
-                               unit |= *data << 8;
-                               break;
-                       }
-                       data += 1;
-                       write_command.offset += 1;
-                       len--;
+               static uint8_t *w = ppu_buffer; //static pointer
+               if(request_ppu_program.offset == 0){
+                       w = ppu_buffer;
                }
-               if(write_command.offset >= 8){
-                       if(write_command.request == REQUEST_CPU_FLASH_CONFIG_SET){
-                               flash_cpu_config(c000x, c2aaa, c5555, unit);
+               memcpy(w, data, length);
+               w += length;
+               request_ppu_program.offset += length;
+               int ret = request_ppu_program.offset >= request_ppu_program.length;
+               if(ret){
+                       if(request_ppu_program.request == REQUEST_PPU_FLASH_CONFIG_SET){
+                               flash_config_set(ppu_buffer, flash_ppu_config);
                        }else{
-                               flash_ppu_config(c000x, c2aaa, c5555, unit);
+                               flash_ppu_program(request_ppu_program.address, request_ppu_program.length, ppu_buffer);
                        }
+                       request_ppu_program.request = REQUEST_NOP;
                }
-               }return write_command.length == write_command.offset;
+               return ret;}
        default:
-               return 1;
+               break;
        }
-       write_command.offset += length;
-       return write_command.length == write_command.offset;
+       return 1; //when returns 0, sometime occours USB commnunication Error
 }
 
 usbMsgLen_t usbFunctionSetup(uchar d[8])
@@ -110,6 +113,7 @@ usbMsgLen_t usbFunctionSetup(uchar d[8])
        static uint8_t status[2];
        usbRequest_t *rq = (void *)d;
        uint8_t *data = readbuffer;
+       struct write_command *write_command;
 
        switch((enum request) rq->bRequest){
        case REQUEST_ECHO:
@@ -137,15 +141,28 @@ usbMsgLen_t usbFunctionSetup(uchar d[8])
                return rq->wLength.word;
        case REQUEST_CPU_WRITE_6502: case REQUEST_CPU_WRITE_FLASH:
        case REQUEST_PPU_WRITE:
+               write_command = &request_both_write;
+               goto xxx_write;
        case REQUEST_CPU_FLASH_PROGRAM:
        case REQUEST_CPU_FLASH_CONFIG_SET:
+               write_command = &request_cpu_program;
+               goto xxx_write;
        case REQUEST_PPU_FLASH_PROGRAM:
        case REQUEST_PPU_FLASH_CONFIG_SET:
-               write_command.request = rq->bRequest;
-               write_command.length = rq->wLength.word;
-               write_command.address = rq->wValue.word;
-               write_command.offset = 0;
+               write_command = &request_ppu_program;
+               goto xxx_write;
+       xxx_write:
+               write_command->request = rq->bRequest;
+               write_command->length = rq->wLength.word;
+               write_command->address = rq->wValue.word;
+               write_command->offset = 0;
                return USB_NO_MSG; //goto usbFunctionWrite
+       case REQUEST_CPU_FLASH_BUFFER_GET:
+               usbMsgPtr = cpu_buffer;
+               return FLASH_PACKET_SIZE;
+       case REQUEST_PPU_FLASH_BUFFER_GET:
+               usbMsgPtr = ppu_buffer;
+               return FLASH_PACKET_SIZE;
        case REQUEST_DISK_STATUS_GET:
                usbMsgPtr = status;
                return disk_status_get(status);
@@ -190,6 +207,12 @@ usbMsgLen_t usbFunctionSetup(uchar d[8])
 
 int main(void)
 {
+       static const struct write_command wc_init = {
+               .request = REQUEST_NOP, .length = 0, .offset = 0
+       };
+       request_both_write = wc_init;
+       request_cpu_program = wc_init;
+       request_ppu_program = wc_init;
        uchar   i;
 
        bus_init();
index ba4575e..905a432 100644 (file)
@@ -387,8 +387,9 @@ static inline void ppu_write_waveform(uint16_t address, uint8_t data)
        address_set(address);//PPU charcter memory /CS open
        BUS_CONTROL_OUT = bit_get_negative(PPU_WR);
        DATABUS_OUT = data;
+       asm("nop"); asm("nop");
        BUS_CONTROL_OUT = BUS_CLOSE;
-       address_set(1 << 13); ///CS close
+       address_set(0x3fff); ///CS close, use pallete area. When address bus is 0x2000-0x2fff, some cartriges enable tilemap area.
 }
 void ppu_write(uint16_t address, uint16_t length, const uint8_t *data)
 {
index d25c6d1..5c9884b 100644 (file)
@@ -131,10 +131,10 @@ LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
 # Programming hardware
 # Type: avrdude -c ?
 # to get a full listing.
-AVRDUDE_PROGRAMMER = avrisp #stk500v2
+AVRDUDE_PROGRAMMER = stk500v2 #avrispv2 #
 
 # com1 = serial port. Use lpt1 to connect to parallel port.
-AVRDUDE_PORT = com4 # programmer connected to serial device
+AVRDUDE_PORT = com3 # programmer connected to serial device
 
 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
index 0e3ca21..8d45ba3 100644 (file)
@@ -1,4 +1,6 @@
 #include <stdint.h>
+//#include <avr/interrupt.h>
+#include "kazzo_task.h"
 #include "bus_access.h"
 
 //---- global variable ----
@@ -8,7 +10,7 @@ struct flash_seqence{
        void (*const reader)(uint16_t address, uint16_t length, uint8_t *data);
        enum compare_status (*const compare)(uint16_t address, uint16_t length, const uint8_t *data);
        enum status{
-               IDLE = 0
+               IDLE = KAZZO_TASK_FLASH_IDLE
                ERASE, ERASE_WAIT,
                PROGRAM, TOGGLE_FIRST, TOGGLE_CHECK
        } status, request;
@@ -67,7 +69,11 @@ void flash_ppu_config(uint16_t c000x, uint16_t c2aaa, uint16_t c5555, uint16_t u
 
 static void program_assign(enum status status, uint16_t address, uint16_t length, const uint8_t *data, struct flash_seqence *t)
 {
-       t->status = status;
+       if(0 && (t->program_unit != 1) && (t->status == PROGRAM)){ //W29C040 ¤ÎºÆ½ñ¤­¹þ¤ß²ó¿ô¤ò¸º¤é¤·¤Æ¤ß¤ë
+               t->status = TOGGLE_FIRST;
+       }else{
+               t->status = status;
+       }
        t->request = status;
        t->address = address;
        t->length = length;
@@ -116,14 +122,27 @@ static void command_execute(const struct flash_command *c, const struct flash_se
                c++;
        }
 }
+#define COMMAND_INTERRUPT_CONTROL (0)
+#include "usbdrv.h"
 static void program(const struct flash_seqence *t)
 {
 /*     static const struct flash_command c[] = {
                {C5555, 0xaa}, {C2AAA, 0x55}, {C5555, 0xa0}, {END, 0}
        };
        command_execute(c, t);*/
+//page write device ¤Ï¤³¤³¤Ç³ä¤ê¹þ¤ß¤òÄä¤á¤ì¤Ð½ñ¤­¹þ¤ß¤¬°ÂÄꤹ¤ë¤Ï¤º¤Ê¤ó¤À¤¬¡¢ usb ¤ÎÄÌ¿®¤¬ÀÚ¤ì¤Æ¤·¤Þ¤¦
+//5 byte ¤Ê¤éÂѤ¨¤é¤ì¤ëÌÏÍÍ
+       if(COMMAND_INTERRUPT_CONTROL == 1){
+               USB_INTR_ENABLE &= ~(1<< USB_INTR_ENABLE_BIT);
+       }
        t->programmer(t->program_command);
+//     USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT);
+//¤³¤ì¤Ï̵Íý
+//     USB_INTR_ENABLE &= ~(1<< USB_INTR_ENABLE_BIT);
        t->writer(t->address, t->program_unit, t->data);
+       if(COMMAND_INTERRUPT_CONTROL == 1){
+               USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT);
+       }
 }
 
 static void erase(const struct flash_seqence *t)
@@ -170,7 +189,7 @@ static void toggle_check(struct flash_seqence *t)
        t->reader(t->address, 1, &d);
        if(t->toggle == (d & 0x40)){
                if((t->program_unit != 1) && (t->request == PROGRAM)){ //page program device retry
-                       if(t->retry_count >= 10){
+                       if(t->retry_count >= 20){
                                if(t->compare(t->address, t->program_unit, t->data) == NG){
                                        t->retry_count += 1;
                                        t->status = PROGRAM;
@@ -228,9 +247,9 @@ static void process(struct flash_seqence *s)
                erase_wait(s);
                break;
        case PROGRAM:
-               if((s->program_unit != 1) || (*(s->data) != 0xff)){
+               //if((s->program_unit != 1) || (*(s->data) != 0xff)){
                        program(s);
-               }
+               //}
                s->status = TOGGLE_FIRST;
                break;
        case TOGGLE_FIRST:
index 706ca4a..83dd1cd 100644 (file)
@@ -14,13 +14,13 @@ enum request{
        REQUEST_CPU_READ_6502, REQUEST_CPU_READ, 
        REQUEST_CPU_WRITE_6502, REQUEST_CPU_WRITE_FLASH,
        REQUEST_PPU_READ, REQUEST_PPU_WRITE,
-       REQUEST_BOTH_FLASH_STATUS,
+       REQUEST_BOTH_FLASH_STATUS, 
        REQUEST_CPU_FLASH_STATUS, REQUEST_CPU_FLASH_CONFIG_SET,
        REQUEST_CPU_FLASH_PROGRAM, REQUEST_CPU_FLASH_ERASE,
-       REQUEST_CPU_FLASH_DEVICE,
+       REQUEST_CPU_FLASH_DEVICE, REQUEST_CPU_FLASH_BUFFER_GET,
        REQUEST_PPU_FLASH_STATUS, REQUEST_PPU_FLASH_CONFIG_SET,
        REQUEST_PPU_FLASH_PROGRAM, REQUEST_PPU_FLASH_ERASE,
-       REQUEST_PPU_FLASH_DEVICE,
+       REQUEST_PPU_FLASH_DEVICE, REQUEST_PPU_FLASH_BUFFER_GET,
        REQUEST_VRAM_CONNECTION,
 
        //future expanstion
@@ -28,6 +28,6 @@ enum request{
 };
 enum {
        READ_PACKET_SIZE = 0x0100,
-       FLASH_PACKET_SIZE = 0x0100
+       FLASH_PACKET_SIZE = 0x0080
 };
 #endif
diff --git a/kazzo/trunk/firmware/kazzo_task.h b/kazzo/trunk/firmware/kazzo_task.h
new file mode 100644 (file)
index 0000000..2cf204a
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef _KAZZO_TASK_H_
+#define _KAZZO_TASK_H_
+enum{
+       KAZZO_TASK_FLASH_IDLE = 0
+};
+#endif