1
0
Fork 0
forked from len0rd/rockbox

Creative ZVM:

* Re-enable USB
 * Acknowledge EP0SETUP packets
 * Spin disk down when no files get loaded in the bootloader
 * Clean up/fix some other stuff


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19931 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Maurus Cuelenaere 2009-02-05 21:47:54 +00:00
parent e1aee31878
commit ee1e8be37f
12 changed files with 196 additions and 155 deletions

View file

@ -28,6 +28,7 @@
#include "backlight.h" #include "backlight.h"
#include "button.h" #include "button.h"
#include "common.h" #include "common.h"
#include "usb.h"
static void load_fw(unsigned char* ptr, unsigned int len) static void load_fw(unsigned char* ptr, unsigned int len)
@ -57,6 +58,7 @@ void main(void)
lcd_init(); lcd_init();
font_init(); font_init();
button_init(); button_init();
usb_init();
lcd_enable(true); lcd_enable(true);
lcd_setfont(FONT_SYSFIXED); lcd_setfont(FONT_SYSFIXED);
@ -110,5 +112,7 @@ void main(void)
} }
} }
storage_sleepnow();
while(1); while(1);
} }

View file

@ -27,7 +27,7 @@
#include "isp1583.h" #include "isp1583.h"
#include "thread.h" #include "thread.h"
#include "logf.h" #include "logf.h"
#include <stdio.h> #include "stdio.h"
#define DIR_RX 0 #define DIR_RX 0
#define DIR_TX 1 #define DIR_TX 1
@ -200,7 +200,9 @@ static int usb_receive(int n)
len = usb_get_packet(endpoints[n].in_buf + endpoints[n].in_ptr, len = usb_get_packet(endpoints[n].in_buf + endpoints[n].in_ptr,
endpoints[n].in_max_len - endpoints[n].in_ptr); endpoints[n].in_max_len - endpoints[n].in_ptr);
endpoints[n].in_ptr += len; endpoints[n].in_ptr += len;
if (endpoints[n].in_ptr >= endpoints[n].in_min_len) {
if (endpoints[n].in_ptr >= endpoints[n].in_min_len)
{
endpoints[n].in_min_len = -1; endpoints[n].in_min_len = -1;
if (endpoints[n].in_done) if (endpoints[n].in_done)
(*(endpoints[n].in_done))(n, endpoints[n].in_buf, (*(endpoints[n].in_done))(n, endpoints[n].in_buf,
@ -229,10 +231,10 @@ static int usb_send(int n)
if (endpoints[n].halt[DIR_TX] if (endpoints[n].halt[DIR_TX]
|| !endpoints[n].enabled[DIR_TX] || !endpoints[n].enabled[DIR_TX]
|| !endpoints[n].out_in_progress) || !endpoints[n].out_in_progress)
{ {
logf("NOT SEND TO EP!"); logf("NOT SEND TO EP!");
return -1; return -1;
} }
if (endpoints[n].out_ptr < 0) if (endpoints[n].out_ptr < 0)
{ {
@ -246,9 +248,9 @@ static int usb_send(int n)
if (usb_out_buffer_full(n)) if (usb_out_buffer_full(n))
{ {
logf("BUFFER FULL!"); logf("BUFFER FULL!");
return -1; return -1;
} }
usb_select_endpoint(ep_index(n, DIR_TX)); usb_select_endpoint(ep_index(n, DIR_TX));
max_pkt_size = endpoints[n].max_pkt_size[DIR_TX]; max_pkt_size = endpoints[n].max_pkt_size[DIR_TX];
@ -261,7 +263,8 @@ static int usb_send(int n)
p = endpoints[n].out_buf + endpoints[n].out_ptr; p = endpoints[n].out_buf + endpoints[n].out_ptr;
i = 0; i = 0;
while (len - i >= 2) { while (len - i >= 2)
{
ISP1583_DFLOW_DATA = p[i] | (p[i + 1] << 8); ISP1583_DFLOW_DATA = p[i] | (p[i + 1] << 8);
i += 2; i += 2;
} }
@ -308,7 +311,11 @@ static void usb_unstall_endpoint(int idx)
static void usb_status_ack(int ep, int dir) static void usb_status_ack(int ep, int dir)
{ {
logf("usb_status_ack(%d)", dir); logf("usb_status_ack(%d)", dir);
usb_select_endpoint(ep_index(ep, dir)); if(ep == EP_CONTROL)
usb_select_setup_endpoint();
else
usb_select_endpoint(ep_index(ep, dir));
ISP1583_DFLOW_CTRLFUN |= DFLOW_CTRLFUN_STATUS; ISP1583_DFLOW_CTRLFUN |= DFLOW_CTRLFUN_STATUS;
} }
@ -326,7 +333,10 @@ static void usb_handle_setup_rx(void)
len = usb_get_packet(setup_pkt_buf, 8); len = usb_get_packet(setup_pkt_buf, 8);
if (len == 8) if (len == 8)
{
ISP1583_DFLOW_CTRLFUN |= DFLOW_CTRLFUN_STATUS; /* Acknowledge packet */
usb_core_control_request((struct usb_ctrlrequest*)setup_pkt_buf); usb_core_control_request((struct usb_ctrlrequest*)setup_pkt_buf);
}
else else
{ {
usb_drv_stall(0, true, false); usb_drv_stall(0, true, false);
@ -388,9 +398,7 @@ void usb_helper(void)
{ {
if(ISP1583_GEN_INT_READ & ISP1583_INIT_INTEN_READ) if(ISP1583_GEN_INT_READ & ISP1583_INIT_INTEN_READ)
{ {
#ifdef DEBUG logf("Helper detected interrupt... [%d]", (int)current_tick);
logf("Helper detected interrupt... [%d]", current_tick);
#endif
usb_drv_int(); usb_drv_int();
} }
return; return;
@ -413,14 +421,6 @@ void usb_drv_init(void)
/* Disable all OTG functions */ /* Disable all OTG functions */
ISP1583_INIT_OTG = 0; ISP1583_INIT_OTG = 0;
#if 0
#ifdef USE_HIGH_SPEED
/* Force device to high speed */
ISP1583_GEN_TSTMOD = GEN_TSTMOD_FORCEHS;
high_speed_mode = true;
#endif
#endif
#ifdef DEBUG #ifdef DEBUG
logf("BUS_CONF/DA0:%d MODE0/DA1: %d MODE1: %d", (bool)(ISP1583_INIT_MODE & INIT_MODE_TEST0), (bool)(ISP1583_INIT_MODE & INIT_MODE_TEST1), (bool)(ISP1583_INIT_MODE & INIT_MODE_TEST2)); logf("BUS_CONF/DA0:%d MODE0/DA1: %d MODE1: %d", (bool)(ISP1583_INIT_MODE & INIT_MODE_TEST0), (bool)(ISP1583_INIT_MODE & INIT_MODE_TEST1), (bool)(ISP1583_INIT_MODE & INIT_MODE_TEST2));
logf("Chip ID: 0x%x", ISP1583_GEN_CHIPID); logf("Chip ID: 0x%x", ISP1583_GEN_CHIPID);
@ -454,7 +454,7 @@ void usb_drv_init(void)
ZVM_SPECIFIC; ZVM_SPECIFIC;
tick_add_task(usb_helper); //tick_add_task(usb_helper);
logf("usb_init_device() finished"); logf("usb_init_device() finished");
} }
@ -482,7 +482,7 @@ void usb_drv_exit(void)
ISP1583_INIT_MODE = INIT_MODE_GOSUSP; ISP1583_INIT_MODE = INIT_MODE_GOSUSP;
ISP1583_INIT_MODE = 0; ISP1583_INIT_MODE = 0;
tick_remove_task(usb_helper); //tick_remove_task(usb_helper);
ZVM_SPECIFIC; ZVM_SPECIFIC;
} }
@ -504,7 +504,7 @@ bool usb_drv_stalled(int endpoint, bool in)
static void out_callback(int ep, unsigned char *buf, int len) static void out_callback(int ep, unsigned char *buf, int len)
{ {
(void)buf; (void)buf;
logf("out_callback(%d, 0x%x, %d)", ep, &buf, len); logf("out_callback(%d, 0x%x, %d)", ep, (int)buf, len);
usb_status_ack(ep, DIR_RX); usb_status_ack(ep, DIR_RX);
usb_core_transfer_complete(ep, true, 0, len); /* 0=>status succeeded, haven't worked out status failed yet... */ usb_core_transfer_complete(ep, true, 0, len); /* 0=>status succeeded, haven't worked out status failed yet... */
} }
@ -512,14 +512,14 @@ static void out_callback(int ep, unsigned char *buf, int len)
static void in_callback(int ep, unsigned char *buf, int len) static void in_callback(int ep, unsigned char *buf, int len)
{ {
(void)buf; (void)buf;
logf("in_callback(%d, 0x%x, %d)", ep, &buf, len); logf("in_callback(%d, 0x%x, %d)", ep, (int)buf, len);
usb_status_ack(ep, DIR_TX); usb_status_ack(ep, DIR_TX);
usb_core_transfer_complete(ep, false, 0, len); usb_core_transfer_complete(ep, false, 0, len);
} }
int usb_drv_recv(int ep, void* ptr, int length) int usb_drv_recv(int ep, void* ptr, int length)
{ {
logf("usb_drv_recv(%d, 0x%x, %d)", ep, &ptr, length); logf("usb_drv_recv(%d, 0x%x, %d)", ep, (int)ptr, length);
if(ep == 0 && length == 0 && ptr == NULL) if(ep == 0 && length == 0 && ptr == NULL)
{ {
usb_status_ack(ep, DIR_TX); usb_status_ack(ep, DIR_TX);
@ -562,7 +562,7 @@ static void usb_drv_wait(int ep, bool send)
int usb_drv_send(int ep, void* ptr, int length) int usb_drv_send(int ep, void* ptr, int length)
{ {
logf("usb_drv_send_nb(%d, 0x%x, %d)", ep, &ptr, length); logf("usb_drv_send_nb(%d, 0x%x, %d)", ep, (int)ptr, length);
if(ep == 0 && length == 0 && ptr == NULL) if(ep == 0 && length == 0 && ptr == NULL)
{ {
usb_status_ack(ep, DIR_RX); usb_status_ack(ep, DIR_RX);
@ -624,8 +624,6 @@ void usb_drv_release_endpoint(int ep)
endpoints[ep & 0x7f].allocation &= mask; endpoints[ep & 0x7f].allocation &= mask;
} }
static void bus_reset(void) static void bus_reset(void)
{ {
/* Enable CLKAON & GLINTENA */ /* Enable CLKAON & GLINTENA */
@ -660,9 +658,7 @@ void IRAM_ATTR usb_drv_int(void)
/* Unlock the device's registers */ /* Unlock the device's registers */
ISP1583_GEN_UNLCKDEV = ISP1583_UNLOCK_CODE; ISP1583_GEN_UNLCKDEV = ISP1583_UNLOCK_CODE;
#if 0 //logf(" handling int [0x%lx & 0x%lx = 0x%x]", ISP1583_GEN_INT_READ, ISP1583_INIT_INTEN_READ, (int)ints);
logf(" handling int [0x%x & 0x%x = 0x%x]", ISP1583_GEN_INT_READ, ISP1583_INIT_INTEN_READ, ints);
#endif
if(ints & INT_IEBRST) /* Bus reset */ if(ints & INT_IEBRST) /* Bus reset */
{ {
@ -732,10 +728,35 @@ void usb_drv_set_address(int address)
ISP1583_INIT_ADDRESS = (address & 0x7F) | INIT_ADDRESS_DEVEN; ISP1583_INIT_ADDRESS = (address & 0x7F) | INIT_ADDRESS_DEVEN;
ZVM_SPECIFIC; ZVM_SPECIFIC;
usb_status_ack(0, DIR_TX);
} }
void usb_drv_set_test_mode(int mode)
{
logf("usb_drv_set_test_mode(%d)", mode);
switch(mode){
case 0:
ISP1583_GEN_TSTMOD = 0;
/* Power cycle... */
break;
case 1:
ISP1583_GEN_TSTMOD = GEN_TSTMOD_JSTATE;
break;
case 2:
ISP1583_GEN_TSTMOD = GEN_TSTMOD_KSTATE;
break;
case 3:
ISP1583_GEN_TSTMOD = GEN_TSTMOD_SE0_NAK;
break;
case 4:
//REG_PORTSC1 |= PORTSCX_PTC_PACKET;
break;
case 5:
//REG_PORTSC1 |= PORTSCX_PTC_FORCE_EN;
break;
}
}
#ifndef BOOTLOADER
int dbg_usb_num_items(void) int dbg_usb_num_items(void)
{ {
return 2+USB_NUM_ENDPOINTS*2; return 2+USB_NUM_ENDPOINTS*2;
@ -782,29 +803,4 @@ char* dbg_usb_item(int selected_item, void *data, char *buffer, size_t buffer_le
return NULL; return NULL;
(void)data; (void)data;
} }
#endif
void usb_drv_set_test_mode(int mode)
{
logf("usb_drv_set_test_mode(%d)", mode);
switch(mode){
case 0:
ISP1583_GEN_TSTMOD = 0;
/* Power cycle... */
break;
case 1:
ISP1583_GEN_TSTMOD = GEN_TSTMOD_JSTATE;
break;
case 2:
ISP1583_GEN_TSTMOD = GEN_TSTMOD_KSTATE;
break;
case 3:
ISP1583_GEN_TSTMOD = GEN_TSTMOD_SE0_NAK;
break;
case 4:
//REG_PORTSC1 |= PORTSCX_PTC_PACKET;
break;
case 5:
//REG_PORTSC1 |= PORTSCX_PTC_FORCE_EN;
break;
}
}

View file

@ -167,8 +167,10 @@
#define CONFIG_USBOTG USBOTG_ISP1583 #define CONFIG_USBOTG USBOTG_ISP1583
#define HAVE_USBSTACK #define HAVE_USBSTACK
#define USE_ROCKBOX_USB
#define USB_VENDOR_ID 0x041e #define USB_VENDOR_ID 0x041e
#define USB_PRODUCT_ID 0x4133 #define USB_PRODUCT_ID 0x4133
#define USB_NUM_ENDPOINTS 7
/*DEBUGGING!*/ /*DEBUGGING!*/
/* /*

View file

@ -43,8 +43,6 @@
#define PHY_IO_BASE2 0x00060000 #define PHY_IO_BASE2 0x00060000
#define DM320_REG2(addr) (*(volatile unsigned int *)(PHY_IO_BASE2 + (addr))) #define DM320_REG2(addr) (*(volatile unsigned int *)(PHY_IO_BASE2 + (addr)))
/* USBOTG */
#define USB_NUM_ENDPOINTS 3
/* This needs to be 2048 byte aligned, but USB_QHARRAY_ATTR should take care /* This needs to be 2048 byte aligned, but USB_QHARRAY_ATTR should take care
* of that */ * of that */
#define USB_QHARRAY_ATTR __attribute__((section(".qharray"),nocommon,aligned(4))) #define USB_QHARRAY_ATTR __attribute__((section(".qharray"),nocommon,aligned(4)))

View file

@ -52,10 +52,10 @@
#define ISP1583_GEN_UNLCKDEV (*((volatile unsigned short*)(ISP1583_IOBASE+0x7C))) #define ISP1583_GEN_UNLCKDEV (*((volatile unsigned short*)(ISP1583_IOBASE+0x7C)))
#define ISP1583_GEN_TSTMOD (*((volatile unsigned char*)(ISP1583_IOBASE+0x84))) #define ISP1583_GEN_TSTMOD (*((volatile unsigned char*)(ISP1583_IOBASE+0x84)))
#define set_int_value(a,b,value) a = value; #define set_int_value(a,b,value) (a) = (value);
#endif #endif
#define ISP1583_UNLOCK_CODE (unsigned short)0xAA37 #define ISP1583_UNLOCK_CODE ((unsigned short)0xAA37)
/* Initialization registers' bits */ /* Initialization registers' bits */

View file

@ -203,7 +203,7 @@ static unsigned long cfs_start;
static unsigned long *sectors; static unsigned long *sectors;
#define CFS_START ( ((hdr->partitions[1].start*hdr->sector_size) & ~0xFFFF) + 0x10000 ) #define CFS_START ( ((hdr->partitions[1].start*hdr->sector_size) & ~0xFFFF) + 0x10000 )
#define CFS_CLUSTER2CLUSTER(x) ( CFS_START+((x)-1)*64 ) #define CFS_CLUSTER2CLUSTER(x) ( (CFS_START/512)+((x)-1)*64 )
/* Limited version of UCS -> ASCII */ /* Limited version of UCS -> ASCII */
static char* ucs2letostring(unsigned char* s) static char* ucs2letostring(unsigned char* s)
@ -211,7 +211,7 @@ static char* ucs2letostring(unsigned char* s)
static char res[256]; static char res[256];
int i; int i;
for(i=0; (s[i] == 0 && s[i+1] == 0); i++) for(i=0; (s[i] == 0 && s[i+1] == 0 && i<256); i++)
res[i] = s[i*2]; res[i] = s[i*2];
return (char*)&res; return (char*)&res;
@ -236,111 +236,134 @@ static void cfs_init(void)
_ata_read_sectors(0, 1, &sector); _ata_read_sectors(0, 1, &sector);
hdr = (struct main_header*)&sector; hdr = (struct main_header*)&sector;
//printf("CFS is at 0x%x", CFS_START); logf("CFS is at 0x%x [0x%x]", CFS_START, CFS_START/512);
/* Read CFS header */ /* Read CFS header */
_ata_read_sectors(CFS_START/512, 64, &sector2); _ata_read_sectors(CFS_START/512, 64, &sector2);
cfs = (struct cfs_header*)&sector2; cfs = (struct cfs_header*)&sector2;
//printf("First inode = %d", cfs->first_inode); logf("First inode = 0x%x", cfs->first_inode);
/* Read root inode */ /* Read root inode */
_ata_read_sectors(CFS_CLUSTER2CLUSTER(cfs->first_inode), 64, &sector2); _ata_read_sectors(CFS_CLUSTER2CLUSTER(cfs->first_inode), 64, &sector2);
root_inode = (struct cfs_inode*)&sector2; root_inode = (struct cfs_inode*)&sector2;
logf("Root inode = 0x%x", root_inode);
logf("0x%x 0x%x", CFS_CLUSTER2CLUSTER(root_inode->first_class_chain[0]), root_inode->first_class_chain[0]);
/* Read root inode's first sector */ /* Read root inode's first sector */
_ata_read_sectors(CFS_CLUSTER2CLUSTER(root_inode->first_class_chain[0]), 64, &sector2); _ata_read_sectors(CFS_CLUSTER2CLUSTER(root_inode->first_class_chain[0]), 64, &sector2);
root_direntry = (struct cfs_direntry*)&sector2; root_direntry = (struct cfs_direntry*)&sector2;
root_direntry_items = (struct cfs_direntry_item*)(&sector2+sizeof(struct cfs_direntry)); root_direntry_items = (struct cfs_direntry_item*)(&sector2+sizeof(struct cfs_direntry));
logf("0x%x", root_direntry->identifier);
logf("%d", root_direntry->items);
/* Search VFAT inode */ /* Search VFAT inode */
for(i=0; i < root_direntry->items; i++) for(i=0; i < root_direntry->items; i++)
{ {
//printf(" * [%s] at 0x%x\n", ucs2letostring(&root_direntry_items[i].string[0]), root_direntry_items[i].inode_number); if(root_direntry_items[i].inode_number != 0)
if(strcmp(ucs2letostring(&root_direntry_items[i].string[0]), "VFAT") == 0) {
vfat_inode_nr = root_direntry_items[i].inode_number; //logf(" * [%s] at 0x%x", ucs2letostring(&root_direntry_items[i].string[0]), root_direntry_items[i].inode_number);
if(strcmp(ucs2letostring(&root_direntry_items[i].string[0]), "VFAT") == 0)
vfat_inode_nr = root_direntry_items[i].inode_number;
}
} }
/* Read VFAT inode */ logf("VFAT inode = 0x%x", vfat_inode_nr);
_ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inode_nr), 64, &sector2);
vfat_inode = (struct cfs_inode*)&sector2;
/* Read VFAT inode's first sector */ if(vfat_inode_nr != 0)
_ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inode->first_class_chain[0]), 64, &sector2);
vfat_direntry = (struct cfs_direntry*)&sector2;
vfat_direntry_items = (struct cfs_direntry_item*)(&sector2+sizeof(struct cfs_direntry));
/* Search for VFAT's subinodes */
for(i=0; i < vfat_direntry->items; i++)
{ {
//printf(" * [%s] at 0x%x\n", ucs2letostring(&vfat_direntry_items[i].string[0]), vfat_direntry_items[i].inode_number); /* Read VFAT inode */
if(i > 0) _ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inode_nr), 64, &sector2);
vfat_inodes_nr[i-1] = vfat_direntry_items[i].inode_number; vfat_inode = (struct cfs_inode*)&sector2;
}
/* Determine size of VFAT file */ /* Read VFAT inode's first sector */
_ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inodes_nr[1]), 1, &sector); _ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inode->first_class_chain[0]), 64, &sector2);
inode = (struct cfs_inode*)&sector; vfat_direntry = (struct cfs_direntry*)&sector2;
sectors = (unsigned long*)buffer_alloc(VFAT_SECTOR_SIZE(inode->filesize)); vfat_direntry_items = (struct cfs_direntry_item*)(&sector2+sizeof(struct cfs_direntry));
//printf("VFAT file size: 0x%x", inode->filesize); /* Search for VFAT's subinodes */
for(i=0; i < vfat_direntry->items; i++)
{
logf(" * [%s] at 0x%x\n", ucs2letostring(&vfat_direntry_items[i].string[0]), vfat_direntry_items[i].inode_number);
if(i > 0)
vfat_inodes_nr[i-1] = vfat_direntry_items[i].inode_number;
}
/* Clear data sectors */ /* Determine size of VFAT file */
memset(&sectors, 0, VFAT_SECTOR_SIZE(inode->filesize)*sizeof(unsigned long)); _ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inodes_nr[1]), 1, &sector);
/* Read all data sectors' addresses in memory */
vfat_sector_count = 0;
for(i=0; vfat_inodes_nr[i] != 0; i++)
{
_ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inodes_nr[i]), 1, &sector);
inode = (struct cfs_inode*)&sector; inode = (struct cfs_inode*)&sector;
#ifndef BOOTLOADER
sectors = (unsigned long*)buffer_alloc(VFAT_SECTOR_SIZE(inode->filesize));
#else
static unsigned long _sector[VFAT_SECTOR_SIZE(1024*1024*1024)]; /* 1GB guess */
sectors = _sector;
#endif
/* Read second & third class chain */ logf("VFAT file size: 0x%x", inode->filesize);
_ata_read_sectors(CFS_CLUSTER2CLUSTER(inode->second_class_chain_first_cluster), 64, &vfat_data[0]);
_ata_read_sectors(CFS_CLUSTER2CLUSTER(inode->second_class_chain_second_cluster), 64, &vfat_data[1]);
/* First class chain */ /* Clear data sectors */
for(j=0; j<12; j++) memset(&sectors, 0, VFAT_SECTOR_SIZE(inode->filesize)*sizeof(unsigned long));
/* Read all data sectors' addresses in memory */
vfat_sector_count = 0;
for(i=0; vfat_inodes_nr[i] != 0; i++)
{ {
if( (inode->first_class_chain[j] & 0xFFFF) != 0xFFFF && _ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inodes_nr[i]), 1, &sector);
inode->first_class_chain[j] != 0 inode = (struct cfs_inode*)&sector;
)
sectors[vfat_sector_count++] = inode->first_class_chain[j];
}
/* Second class chain */ /* Read second & third class chain */
for(j=0; j<0x8000/4; j++) _ata_read_sectors(CFS_CLUSTER2CLUSTER(inode->second_class_chain_first_cluster), 64, &vfat_data[0]);
{ _ata_read_sectors(CFS_CLUSTER2CLUSTER(inode->second_class_chain_second_cluster), 64, &vfat_data[1]);
if( (vfat_data[0][j] & 0xFFFF) != 0xFFFF &&
vfat_data[0][j] != 0
)
sectors[vfat_sector_count++] = vfat_data[0][j];
}
/* Third class chain */ /* First class chain */
for(j=0; j<0x8000/4; j++) for(j=0; j<12; j++)
{
if( (vfat_data[1][j] & 0xFFFF) != 0xFFFF &&
vfat_data[1][j] != 0
)
{ {
memset(&vfat_data[0], 0, 0x8000*sizeof(unsigned int)); if( (inode->first_class_chain[j] & 0xFFFF) != 0xFFFF &&
inode->first_class_chain[j] != 0
)
sectors[vfat_sector_count++] = inode->first_class_chain[j];
}
/* Read third class subchain(s) */ /* Second class chain */
_ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_data[1][j]), 64, &vfat_data[0]); for(j=0; j<0x8000/4; j++)
{
if( (vfat_data[0][j] & 0xFFFF) != 0xFFFF &&
vfat_data[0][j] != 0
)
sectors[vfat_sector_count++] = vfat_data[0][j];
}
for(k=0; k<0x8000/4; k++) /* Third class chain */
for(j=0; j<0x8000/4; j++)
{
if( (vfat_data[1][j] & 0xFFFF) != 0xFFFF &&
vfat_data[1][j] != 0
)
{ {
if( (vfat_data[0][k] & 0xFFFF) != 0xFFFF && memset(&vfat_data[0], 0, 0x8000*sizeof(unsigned int));
vfat_data[0][k] != 0
) /* Read third class subchain(s) */
sectors[vfat_sector_count++] = vfat_data[0][k]; _ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_data[1][j]), 64, &vfat_data[0]);
for(k=0; k<0x8000/4; k++)
{
if( (vfat_data[0][k] & 0xFFFF) != 0xFFFF &&
vfat_data[0][k] != 0
)
sectors[vfat_sector_count++] = vfat_data[0][k];
}
} }
} }
} }
}
//printf("Sector count: %d 0x%x", vfat_sector_count, vfat_sector_count); logf("Sector count: %d 0x%x", vfat_sector_count, vfat_sector_count);
}
else
logf("Cannot find virtual FAT filesystem!"); //TODO: panicf
cfs_inited = true; cfs_inited = true;
} }
@ -386,6 +409,7 @@ int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const v
if(!cfs_inited) if(!cfs_inited)
cfs_init(); cfs_init();
#if 0 /* Disabled for now */
/* Check if count is lesser than or equal to 1 native CFS sector */ /* Check if count is lesser than or equal to 1 native CFS sector */
if(count <= 64) if(count <= 64)
return _ata_write_sectors(IF_MV2(drive,) map_sector(start), count, buf); return _ata_write_sectors(IF_MV2(drive,) map_sector(start), count, buf);
@ -406,8 +430,16 @@ int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const v
return ret; return ret;
} }
#else
(void)start;
(void)count;
(void)buf;
return 0;
#endif
} }
#ifdef BOOTLOADER
/* /*
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
MiniFileSystem parsing code MiniFileSystem parsing code
@ -487,3 +519,5 @@ int load_minifs_file(char* filename, unsigned char* location)
return files[found].size; return files[found].size;
} }
#endif

View file

@ -82,6 +82,8 @@ void ata_reset(void);
void ata_device_init(void); void ata_device_init(void);
bool ata_is_coldstart(void); bool ata_is_coldstart(void);
void ide_power_enable(bool on); void ide_power_enable(bool on);
#ifdef BOOTLOADER
int load_minifs_file(char* filename, unsigned char* location); int load_minifs_file(char* filename, unsigned char* location);
#endif
#endif #endif

View file

@ -27,6 +27,7 @@
#include "button-target.h" #include "button-target.h"
#include "i2c-dm320.h" #include "i2c-dm320.h"
#include "sprintf.h" #include "sprintf.h"
#include "logf.h"
#ifdef BUTTON_DEBUG #ifdef BUTTON_DEBUG
#include "lcd-target.h" #include "lcd-target.h"
@ -36,22 +37,22 @@
#ifndef ZEN_VISION #ifndef ZEN_VISION
/* Creative Zen Vision:M */ /* Creative Zen Vision:M */
#define BTN_LEFT 0x5F00 #define BTN_LEFT 0xAF00
#define BTN_RIGHT 0x4F00 #define BTN_RIGHT 0xA700
#define BTN_BACK 0xBF00 #define BTN_BACK 0xDF00
#define BTN_CUSTOM 0x8F00 #define BTN_CUSTOM 0xC700
#define BTN_PLAY 0x2F00 #define BTN_PLAY 0x9700
#define BTN_POWER 0x0F00 #define BTN_POWER 0x8700
#define BTN_MENU 0x9F00 #define BTN_MENU 0xCF00
#define BTN_HOLD 0x9F06 #define BTN_HOLD 0xCF07
#define BTN_UNHOLD 0xAF06 #define BTN_UNHOLD 0xD707
#define BTN_REL 1 #define BTN_REL 1
#define BTN_TOUCHPAD_PRESS 0x1F00 #define BTN_TOUCHPAD_PRESS 0x8F00
#define BTN_TOUCHPAD_SCROLL_DOWN 0x0F03 #define BTN_TOUCHPAD_SCROLL_DOWN 0x0F03
#define BTN_TOUCHPAD_CORNER_DOWN 0xAF00 #define BTN_TOUCHPAD_CORNER_DOWN 0xD700
#define BTN_TOUCHPAD_CORNER_UP 0x3F00 #define BTN_TOUCHPAD_CORNER_UP 0x9F00
#define BTN_TOUCHPAD_SCROLL_UP 0x0F04 #define BTN_TOUCHPAD_SCROLL_UP 0x0F04
#define HEADPHONE_PLUGIN_A 0x5707 #define HEADPHONE_PLUGIN_A 0x5707
@ -63,8 +64,8 @@
#define DOCK_UNPLUG 0xDF06 #define DOCK_UNPLUG 0xDF06
#define DOCK_USB_INSERT 0x2F06 #define DOCK_USB_INSERT 0x2F06
#define DOCK_USB_UNPLUG 0x3F06 #define DOCK_USB_UNPLUG 0x3F06
#define DOCK_POWER_INSERT 0x2707 #define DOCK_POWER_INSERT 0x1707
#define DOCK_POWER_UNPLUG 0x2F07 #define DOCK_POWER_UNPLUG 0x1F07
#else #else
/* Creative Zen Vision */ /* Creative Zen Vision */
@ -272,6 +273,8 @@ void GIO0(void)
lcd_update(); lcd_update();
sw = !sw; sw = !sw;
#endif #endif
logf("PIC: 0x%x", (unsigned int)((msg[3] << 24) |
(msg[2] << 16) | (msg[1] << 8) | msg[0]));
} }
static void send_command_to_pic(const unsigned char in, unsigned char* out, static void send_command_to_pic(const unsigned char in, unsigned char* out,
@ -336,6 +339,7 @@ bool button_usb_connected(void)
return (bool)(nonbtn & NONBUTTON_USB); return (bool)(nonbtn & NONBUTTON_USB);
} }
#ifndef BOOTLOADER
int pic_dbg_num_items(void) int pic_dbg_num_items(void)
{ {
return 13; return 13;
@ -376,3 +380,4 @@ char* pic_dbg_item(int selected_item, void *data, char *buffer, size_t buffer_le
} }
return NULL; return NULL;
} }
#endif

View file

@ -37,7 +37,7 @@ bool usb_drv_connected(void)
int usb_detect(void) int usb_detect(void)
{ {
if(button_usb_connected()) if(usb_drv_connected())
return USB_INSERTED; return USB_INSERTED;
else else
return USB_EXTRACTED; return USB_EXTRACTED;

View file

@ -65,11 +65,11 @@
b = value >> 16; b = value >> 16;
#define ZVM_SPECIFIC asm volatile( \ /*#define ZVM_SPECIFIC asm volatile( \
"LDR R12, =0x50FFC000\n" \ "LDR R12, =0x50FFC000\n" \
"LDRH R12, [R12]\n" \ "LDRH R12, [R12]\n" \
: : : "r12") : : : "r12");*/
//#define ZVM_SPECIFIC #define ZVM_SPECIFIC
#define USE_IRAM #define USE_IRAM

View file

@ -235,7 +235,7 @@ data_abort_handler:
mov r1, #2 mov r1, #2
b UIE b UIE
#if defined(STUB) || defined(BOOTLOADER) #ifdef STUB
UIE: UIE:
b UIE b UIE
#endif #endif

View file

@ -146,7 +146,7 @@ int i2c_read(unsigned short address, unsigned char* buf, int count)
void i2c_init(void) void i2c_init(void)
{ {
#if 0 //TODO: mimic OF I2C clock settings; currently this is done by the bootloader #ifdef CREATIVE_ZVx //TODO: mimic OF I2C clock settings; currently this is done by the bootloader
IO_CLK_MOD2 &= ~CLK_MOD2_I2C; // turn I²C clock off (just to be sure) IO_CLK_MOD2 &= ~CLK_MOD2_I2C; // turn I²C clock off (just to be sure)
IO_CLK_LPCTL1 &= ~1; // set Powerdown mode to off IO_CLK_LPCTL1 &= ~1; // set Powerdown mode to off
IO_CLK_SEL0 &= ~0x800; // set I²C clock to PLLA IO_CLK_SEL0 &= ~0x800; // set I²C clock to PLLA