OSDN Git Service

usb layer data are masked xor 0xa5. packet loss fixed
authornaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Tue, 15 Dec 2009 03:48:49 +0000 (03:48 +0000)
committernaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Tue, 15 Dec 2009 03:48:49 +0000 (03:48 +0000)
git-svn-id: svn+ssh://svn.osdn.net/svnroot/unagi@332 24ea1065-a21e-4ca1-99c9-f5125deb0858

kazzo/trunk/firmware/avr_main.c
kazzo/trunk/firmware/kazzo_request.h
kazzo/trunk/usbrequest.txt

index a9e9cb3..cbbff1f 100644 (file)
@@ -29,14 +29,18 @@ static void flash_config_set(const uint8_t *t, void (*set)(uint16_t, uint16_t, u
        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];
+/*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;
-       
+       uchar i;
+       //decode masked data
+       for(i = 0; i < len; i++){
+               data[i] ^= 0xa5;
+       }
        switch(request_both_write.request){
        case REQUEST_CPU_WRITE_6502:
                cpu_write_6502(request_both_write.address + request_both_write.offset, length, data);
@@ -68,7 +72,7 @@ uchar usbFunctionWrite(uchar *data, uchar len)
                memcpy(w, data, length);
                w += length;
                request_cpu_program.offset += length;
-               int ret = request_cpu_program.offset >= request_cpu_program.length;
+               int ret = request_cpu_program.offset == request_cpu_program.length;
                if(ret){
                        if(request_cpu_program.request == REQUEST_FLASH_CONFIG_SET){
                                flash_config_set(cpu_buffer, flash_cpu_config);
@@ -91,7 +95,7 @@ uchar usbFunctionWrite(uchar *data, uchar len)
                memcpy(w, data, length);
                w += length;
                request_ppu_program.offset += length;
-               int ret = request_ppu_program.offset >= request_ppu_program.length;
+               int ret = request_ppu_program.offset == request_ppu_program.length;
                if(ret){
                        if(request_ppu_program.request == REQUEST_FLASH_CONFIG_SET){
                                flash_config_set(ppu_buffer, flash_ppu_config);
@@ -157,13 +161,13 @@ usbMsgLen_t usbFunctionSetup(uchar d[8])
                write_command->address = rq->wValue.word;
                write_command->offset = 0;
                return USB_NO_MSG; //goto usbFunctionWrite
-       case REQUEST_FLASH_BUFFER_GET:
+/*     case REQUEST_FLASH_BUFFER_GET:
                if(rq->wIndex.word == INDEX_CPU){
                        usbMsgPtr = cpu_buffer;
                }else{
                        usbMsgPtr = ppu_buffer;
                }
-               return FLASH_PACKET_SIZE;
+               return FLASH_PACKET_SIZE;*/
        case REQUEST_DISK_STATUS_GET:
                usbMsgPtr = status;
                return disk_status_get(status);
@@ -173,18 +177,20 @@ usbMsgLen_t usbFunctionSetup(uchar d[8])
        case REQUEST_DISK_WRITE:
                disk_init(DISK_WRITE);
                return 0;
-       case REQUEST_BOTH_FLASH_STATUS:
-               status[0] = flash_cpu_status();
-               status[1] = flash_ppu_status();
-               usbMsgPtr = status;
-               return 2;
        case REQUEST_FLASH_STATUS:
-               if(rq->wIndex.word == INDEX_CPU){
+               usbMsgPtr = status;
+               switch((enum index) rq->wIndex.word){
+               case INDEX_CPU:
                        status[0] = flash_cpu_status();
-               }else{
+                       return 1;
+               case INDEX_PPU:
                        status[0] = flash_ppu_status();
+                       return 1;
+               default:
+                       status[0] = flash_cpu_status();
+                       status[1] = flash_ppu_status();
+                       return 2;
                }
-               usbMsgPtr = status;
                return 1;
        case REQUEST_FLASH_DEVICE:
                if(rq->wIndex.word == INDEX_CPU){
index 90dc668..eb3cf6e 100644 (file)
@@ -14,10 +14,9 @@ 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_FLASH_STATUS, REQUEST_FLASH_CONFIG_SET,
        REQUEST_FLASH_PROGRAM, REQUEST_FLASH_ERASE,
-       REQUEST_FLASH_DEVICE, REQUEST_FLASH_BUFFER_GET,
+       REQUEST_FLASH_DEVICE, //REQUEST_FLASH_BUFFER_GET,
        REQUEST_VRAM_CONNECTION,
 
        //future expanstion
index 29e3779..c5f574b 100644 (file)
@@ -116,13 +116,12 @@ buses. Data is sent in sequential order.
 - REQUEST_CPU_WRITE_FLASH is assigned for debugging.
 - REQUEST_PPU_WRITE is assigned for dectecting charcter ROM or RAM.
 
-REQUEST_CPU_FLASH_CONFIG_SET
-REQUEST_PPU_FLASH_CONFIG_SET
+REQUEST_FLASH_CONFIG_SET
 R/W: write (task)
 Arguments:
  wLength: must be set as a value of 8
  wValue:  not used
- wIndex:  not used
+ wIndex:  target memory region. INDEX_CPU or INDEX_PPU
  bData:   programmed data for current memory region
  bData[0] bit0-7 for command address 0x0000 (c000x)
  bData[1] bit8-15 for command address 0x0000 (c000x)
@@ -138,13 +137,12 @@ This request defines flash memory command addresses for the target
 mapper and flash memory device. Please note that address (c000x) is 
 reserved for future expansion, so currently that address has no effect.
 
-REQUEST_CPU_FLASH_PROGRAM
-REQUEST_PPU_FLASH_PROGRAM
+REQUEST_FLASH_PROGRAM
 R/W: write (task)
 Arguments:
  wLength: programming length
  wValue:  target address on current memory region
- wIndex:  not used
+ wIndex:  target memory region. INDEX_CPU or INDEX_PPU
  bData:   programming data for current memory region
 Returns: nothing
 Description:
@@ -158,43 +156,29 @@ REQUEST_DISK_STATUS_GET
 REQUEST_DISK_READ
 REQUEST_DISK_WRITE
 (For reference only, these are currently reserved for future expansion.)
-
-REQUEST_BOTH_FLASH_STATUS
+REQUEST_FLASH_STATUS
 R/W: read
 Arguments:
- wLength: must be set as a value of 2
+ wLength: must be set as a value of 1 or 2
  wValue:  not used
- wIndex:  not used
+ wIndex:  target memory region. INDEX_CPU, INDEX_PPU or INDEX_BOTH
 Returns:
+when wIndex is INDEX_CPU or INDEX_PPU:
+ data[0]: current memory region's flash programming task status
+when wIndex is INDEX_BOTH:
  data[0]: CPU flash programming task status
  data[1]: PPU flash programming task status
 Description:
-This request determines the flash programming task status for both the 
-CPU and PPU. If the request returns a value of 0, the current task is 
-considered idle. In this case, the host software can proceed to send 
-the next programming request.
-
-REQUEST_CPU_FLASH_STATUS
-REQUEST_PPU_FLASH_STATUS
-R/W: read
-Arguments:
- wLength: must be set as a value of 1
- wValue:  not used
- wIndex:  not used
-Returns:
- data[0]: current memory region's flash programming task status
-Description:
 This request determines the flash programming task status for either 
 the CPU or PPU individually. Please see the description for 
 REQUEST_BOTH_FLASH_STATUS for more info.
 
-REQUEST_CPU_FLASH_DEVICE
-REQUEST_PPU_FLASH_DEVICE
+REQUEST_FLASH_DEVICE
 R/W: read
 Arguments:
  wLength: must be set as a value of 2
  wValue:  not used
- wIndex:  not used
+ wIndex:  target memory region. INDEX_CPU or INDEX_PPU
 Returns:
  data[0]: flash memory device manufacturer code
  data[1]: flash memory device device code
@@ -203,18 +187,17 @@ This request is reserved for future expansion. Soon, this will be used
 to retrieve the flash memory's product ID. Otherwise this does not 
 function correctly at this time.
 
-REQUEST_CPU_FLASH_ERASE
-REQUEST_PPU_FLASH_ERASE
+REQUEST_FLASH_ERASE
 R/W: write (task)
 Arguments:
  wLength: must be set as a value of 0
  wValue:  confirmed current region address during erase
- wIndex:  not used
+ wIndex:  target memory region. INDEX_CPU or INDEX_PPU
 Returns: nothing
 Description:
 Firmware registers an 'erase task' on flash memory. The host software 
 can retrieve the current progress status via the aforementioned 
-REQUEST_xxx_FLASH_STATUS requests.
+REQUEST_FLASH_STATUS requests.
 
 REQUEST_VRAM_CONNECTION
 R/W: read