static void tftp_test(struct bootp *bp) { int res, err, len; struct sockaddr_in host; #ifdef CYGPKG_NET_INET6 struct sockaddr_in6 ipv6router; char server[64]; #endif memset((char *)&host, 0, sizeof(host)); host.sin_len = sizeof(host); host.sin_family = AF_INET; host.sin_addr = bp->bp_siaddr; host.sin_port = 0; diag_printf("Trying tftp_get %s %16s...\n", GETFILE, inet_ntoa(host.sin_addr)); res = tftp_get( GETFILE, &host, buf, sizeof(buf), TFTP_OCTET, &err); diag_printf("res = %d, err = %d\n", res, err); if (res > 0) { diag_dump_buf(buf, min(res,1024)); } len = res; diag_printf("Trying tftp_put %s %16s, length %d\n", PUTFILE, inet_ntoa(host.sin_addr), len); res = tftp_put( PUTFILE, &host, buf, len, TFTP_OCTET, &err); diag_printf("put - res: %d\n", res); #ifdef CYGPKG_NET_INET6 // Wait for router solicit process to happen. if (!cyg_net_get_ipv6_advrouter(&ipv6router)) { diag_printf("No router advertisement recieved\n"); cyg_test_exit(); } getnameinfo((struct sockaddr *)&ipv6router,sizeof(ipv6router), server, sizeof(server), 0 ,0 ,NI_NUMERICHOST); diag_printf("Trying tftp_get %s using IPv6 from %16s...\n", GETFILE, server); res = tftp_client_get( GETFILE, server, 0, buf, sizeof(buf), TFTP_OCTET, &err); diag_printf("IPv6 res = %d, err = %d\n", res, err); if (res > 0) { diag_dump_buf(buf, min(res,1024)); } len = res; diag_printf("Trying tftp_put %s using IPv6 to %16s, length %d\n", PUTFILE, server, len); res = tftp_client_put( PUTFILE, server, 0, buf, len, TFTP_OCTET, &err); diag_printf("put - res: %d\n", res); #endif }
/* * Tries to read from the serial device. Same as sio_read but returns * immediately if no data is available and never blocks. */ u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len) { Cyg_ErrNo ret; cyg_serial_buf_info_t info; cyg_uint32 l; #ifdef CYGDBG_LWIP_DEBUG_SIO diag_printf("sio_tryread(fd=%p,data=%p,len=%lu:)\n", fd, data, len); #endif // Check how many bytes there are to read l = sizeof(info); ret = cyg_io_get_config((cyg_io_handle_t) fd, CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO, &info, &l); if (ret != ENOERR) return 0; l = info.rx_count; if (l < 1) return 0; if (l > len) l = len; ret = cyg_io_read((cyg_io_handle_t) fd, data, &l); if (ret != ENOERR) return 0; #ifdef CYGDBG_LWIP_DEBUG_SIO diag_printf("sio_tryread: "); diag_dump_buf(data, len); #endif return l; }
static void net_io_flush(void) { int n; char *bp = out_buf; #ifdef DEBUG_TCP if (show_tcp) { int old_console; old_console = start_console(); diag_printf("%s.%d\n", __FUNCTION__, __LINE__); diag_dump_buf(out_buf, out_buflen); end_console(old_console); } #endif // SHOW_TCP n = __tcp_write_block(&tcp_sock, bp, out_buflen); if (n < 0) { // The connection is gone! net_io_revert_console(); } else { out_buflen -= n; bp += n; } out_bufp = out_buf; out_buflen = 0; // Check interrupt flag if (CYGACC_CALL_IF_CONSOLE_INTERRUPT_FLAG()) { CYGACC_CALL_IF_CONSOLE_INTERRUPT_FLAG_SET(0); cyg_hal_user_break(0); } }
void SpiFlash::readCmd(cTerm & t,int argc,char *argv[]) { if (argc > 2) { cyg_uint32 addr = (cyg_uint32)strtoul(argv[1],NULL,16); cyg_uint32 num = (cyg_uint32)strtoul(argv[2],NULL,16); cyg_uint8 buff[num]; int error = cyg_flash_read(addr, buff, num, 0); if (!error) { t<<t.format(GREEN("Read %d bytes from serial flash at address 0x%08X\n"), num, addr); // for (cyg_uint32 i = 0 ; i < num ; i++) // { // diag_printf(" 0x%02X", buff[i]); // // } diag_dump_buf(buff, num); diag_printf("\n"); } else { t<<(RED("Error reading from serial flash!\n")); printfError(error); } } else { t<<"You need to supply an address and number of bytes to read\n"; } }
int flash_hwr_init(void) { struct FLASH_query data, *qp; extern char flash_query, flash_query_end; typedef int code_fun(unsigned char *); code_fun *_flash_query; int code_len, stat, num_regions, region_size; // Copy 'program' code to RAM for execution code_len = (unsigned long)&flash_query_end - (unsigned long)&flash_query; _flash_query = (code_fun *)flash_info.work_space; memcpy(_flash_query, &flash_query, code_len); HAL_DCACHE_SYNC(); // Should guarantee this code will run HAL_ICACHE_INVALIDATE_ALL(); // is also required to avoid old contents stat = (*_flash_query)(&data); qp = &data; if (/*(qp->manuf_code == FLASH_Intel_code) && */ (strncmp(qp->id, "QRY", 3) == 0)) { num_regions = _si(qp->num_regions)+1; region_size = _si(qp->region_size)*256; flash_info.block_size = region_size*2; // Pairs of chips in parallel flash_info.blocks = num_regions*2; // and pairs of chips in serial flash_info.start = (void *)0x9c000000; flash_info.end = (void *)0x9e000000; return FLASH_ERR_OK; } else { (*flash_info.pf)("Can't identify FLASH, sorry\n"); diag_dump_buf(data, sizeof(data)); return FLASH_ERR_HWR; } }
static Cyg_ErrNo kbd_read(cyg_io_handle_t handle, void *buffer, cyg_uint32 *len) { unsigned char *ev; int tot = *len; unsigned char *bp = (unsigned char *)buffer; cyg_scheduler_lock(); // Prevent interaction with DSR code while (tot >= sizeof(*ev)) { if (num_events > 0) { ev = &_events[_event_get++]; if (_event_get == MAX_EVENTS) { _event_get = 0; } memcpy(bp, ev, sizeof(*ev)); bp += sizeof(*ev); tot -= sizeof(*ev); num_events--; } else { break; // No more events } } cyg_scheduler_unlock(); // Allow DSRs again diag_dump_buf(buffer, tot); *len -= tot; return ENOERR; }
void dump_frame(unsigned char *frame) { HAL_SavedRegisters *rp = (HAL_SavedRegisters *)frame; int i; diag_dump_buf(frame, 128); diag_printf("Registers:\n"); for (i = 0; i <= 10; i++) { if ((i == 0) || (i == 6)) diag_printf("R%d: ", i); diag_printf("%08X ", rp->d[i]); if ((i == 5) || (i == 10)) diag_printf("\n"); } diag_printf("FP: %08X, SP: %08X, LR: %08X, PC: %08X, PSR: %08X\n", rp->fp, rp->sp, rp->lr, rp->pc, rp->cpsr); }
// // Note: this routine is called from the Atmel processing DSR // static void ts_handler(atmel_pkt *pkt) { unsigned char *dp = pkt->data; static short lastX, lastY; short x, y; struct _event *ev; #ifdef DEBUG_RAW_EVENTS memcpy(&_ts_buf[_ts_buf_ptr], pkt->data, 8); _ts_buf_ptr += 8; if (_ts_buf_ptr == 512) { diag_printf("TS handler\n"); diag_dump_buf(_ts_buf, 512); _ts_buf_ptr = 0; } #endif // Try and interpret the mouse data if ((dp[0] & 0x0F) == 0) { // This is a pen up event x = lastX; y = lastY; pen_down = false; } else { // Some sort of event with the pen down x = lastX = (dp[1] << 8) | dp[2]; y = lastY = (dp[3] << 8) | dp[4]; pen_down = true; } if (num_events < MAX_EVENTS) { num_events++; ev = &_events[_event_put++]; if (_event_put == MAX_EVENTS) { _event_put = 0; } ev->button_state = pen_down ? 0x04 : 0x00; ev->xPos = x; ev->yPos = y; if (ts_select_active) { ts_select_active = false; cyg_selwakeup(&ts_select_info); } } }
/* * Reads from the serial device. */ u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len) { Cyg_ErrNo ret; #ifdef CYGDBG_LWIP_DEBUG_SIO diag_printf("sio_read(fd=%p,data=%p,len=%lu:)\n", fd, data, len); #endif ret = cyg_io_read((cyg_io_handle_t) fd, data, (cyg_uint32 *) &len); if (ret != ENOERR) return 0; #ifdef CYGDBG_LWIP_DEBUG_SIO diag_printf("sio_read: "); diag_dump_buf(data, len); #endif return len; }
int flash_hwr_init(void) { struct FLASH_query data, *qp; extern char flash_query, flash_query_end; typedef int code_fun(unsigned char *); code_fun *_flash_query; int code_len, stat, num_regions, region_size, icache_isenabled; // Copy 'program' code to RAM for execution code_len = (unsigned long)&flash_query_end - (unsigned long)&flash_query; _flash_query = (code_fun *)flash_info.work_space; memcpy(_flash_query, &flash_query, code_len); HAL_ICACHE_IS_ENABLED(icache_isenabled); HAL_DCACHE_SYNC(); // Should guarantee this code will run HAL_ICACHE_DISABLE(); // is also required to avoid old contents memset(&data,0,sizeof(data)); stat = (*_flash_query)((void*)&data); if (icache_isenabled) HAL_ICACHE_ENABLE(); qp = &data; if (/*(qp->manuf_code == FLASH_Intel_code) && */ (strncmp(qp->id, "QRY", 3) == 0)) { num_regions = _si(qp->num_regions)+1; region_size = _si(qp->region_size)*256; flash_info.block_size = region_size; flash_info.blocks = num_regions; flash_info.start = (void *)0x00000000; flash_info.end = (void *)(0x00000000+(num_regions*region_size)); return FLASH_ERR_OK; } else { (*flash_info.pf)("Can't identify FLASH sorry\n"); diag_dump_buf(data, sizeof(data)); return FLASH_ERR_HWR; } }
int flash_hwr_init(void) { unsigned char data[96]; extern char flash_query, flash_query_end; typedef int code_fun(unsigned char *); code_fun *_flash_query; int code_len, stat, num_regions, region_size, icache_isenabled; // Copy 'program' code to RAM for execution code_len = (unsigned long)&flash_query_end - (unsigned long)&flash_query; _flash_query = (code_fun *)flash_info.work_space; memcpy(_flash_query, &flash_query, code_len); HAL_ICACHE_IS_ENABLED(icache_isenabled); HAL_DCACHE_SYNC(); // Should guarantee this code will run HAL_ICACHE_DISABLE(); // is also required to avoid old contents stat = (*_flash_query)(data); if (icache_isenabled) HAL_ICACHE_ENABLE(); if ((data[0] == FLASH_Intel_code) && (data[4] == FLASH_28F016SV_low) && (data[5] == FLASH_28F016SV_hi)) { num_regions = 32; region_size = 0x20000; flash_info.block_size = region_size; flash_info.blocks = num_regions; flash_info.start = (void *)0x08000000; flash_info.end = (void *)(0x08000000+(num_regions*region_size)); return FLASH_ERR_OK; } else { (*flash_info.pf)("Can't identify FLASH, sorry\n"); diag_dump_buf(data, sizeof(data)); return FLASH_ERR_HWR; } }
static cyg_bool _net_io_getc_nonblock(void* __ch_data, cyg_uint8* ch) { if (in_buflen == 0) { __tcp_poll(); if (tcp_sock.state == _CLOSE_WAIT) { // This connection is breaking if (tcp_sock.data_bytes == 0 && tcp_sock.rxcnt == 0) { __tcp_close(&tcp_sock); return false; } } if (tcp_sock.state == _CLOSED) { // The connection is gone net_io_revert_console(); *ch = '\n'; return true; } in_buflen = __tcp_read(&tcp_sock, in_buf, sizeof(in_buf)); in_bufp = in_buf; #ifdef DEBUG_TCP if (show_tcp && (in_buflen > 0)) { int old_console; old_console = start_console(); diag_printf("%s:%d\n", __FUNCTION__, __LINE__); diag_dump_buf(in_buf, in_buflen); end_console(old_console); } #endif // DEBUG_TCP } if (in_buflen) { *ch = *in_bufp++; in_buflen--; return true; } else { return false; } }
int flash_hwr_init(void) { unsigned char data[96]; int num_regions, region_size; flash_dev_query(&data); if ((data[0] == FLASH_Intel_code) && ((data[4] == FLASH_28F008SA) || (data[4] == FLASH_28F008SC))) { num_regions = 16; region_size = 0x40000; flash_info.block_size = region_size; flash_info.blocks = num_regions; flash_info.start = (void *)0x41000000; flash_info.end = (void *)(0x41000000+(num_regions*region_size)); return FLASH_ERR_OK; } else { (*flash_info.pf)("Can't identify FLASH, sorry\n"); diag_dump_buf(data, sizeof(data)); return FLASH_ERR_HWR; } }
/* * Writes to the serial device. */ u32_t sio_write(sio_fd_t fd, u8_t *data, u32_t len) { Cyg_ErrNo ret; cyg_uint32 count = 0; cyg_uint32 chunk; #ifdef CYGDBG_LWIP_DEBUG_SIO diag_printf("sio_write(fd=%p,data=%p,len=%lu:)\n", fd, data, len); diag_printf("sio_write: "); diag_dump_buf(data, len); #endif while (count < len) { chunk = len - count; ret = cyg_io_write((cyg_io_handle_t) fd, data, &chunk); if (ret != ENOERR) break; data += chunk; count += chunk; } return count; }
void dump_frame(unsigned char *frame) { #ifdef CYGPKG_HAL_SMP_SUPPORT HAL_SMP_CPU_TYPE cpu; cpu = HAL_SMP_CPU_THIS(); #endif HAL_SavedRegisters *rp = (HAL_SavedRegisters *)frame; int i; diag_dump_buf(frame, 128); #ifdef CYGPKG_HAL_SMP_SUPPORT diag_printf("Registers for CPU %d:\n", cpu); #else diag_printf("Registers:\n"); #endif for (i = 0; i <= 10; i++) { if ((i == 0) || (i == 6)) diag_printf("R%d: ", i); diag_printf("%08X ", rp->d[i]); if ((i == 5) || (i == 10)) diag_printf("\n"); } diag_printf("FP: %08X, SP: %08X, LR: %08X, PC: %08X, PSR: %08X\n", rp->fp, rp->sp, rp->lr, rp->pc, rp->cpsr); }
// ------------------------------------------------------------------------ // // API Function : dm9000_recv // // ------------------------------------------------------------------------ static void dm9000_recv( struct eth_drv_sc *sc, struct eth_drv_sg *sg_list, int sg_len ) { struct dm9000 *priv = (struct dm9000 *)sc->driver_private; struct eth_drv_sg *sg = sg_list; cyg_uint8 tmpbuf[4]; char *p; int len, total_len, nread, n, leftover; total_len = priv->rxlen; nread = leftover = 0; // diag_printf("dm9000_recv: total_len=%d\n", total_len); do { p = (char *)sg->buf; len = sg->len; // diag_printf("recv: buf=%p len=%d to_read=%d, leftover=%d\n", p, len, total_len - nread, leftover); if ((nread + len) > total_len) len = total_len - nread; if (leftover) { if (leftover <= len) { memcpy(p, tmpbuf + (sizeof(tmpbuf) - leftover), leftover); p += leftover; len -= leftover; nread += leftover; leftover = 0; } else { memcpy(p, tmpbuf + (sizeof(tmpbuf) - leftover), len); leftover -= len; p += len; nread += len; len = 0; } } while (len >= sizeof(tmpbuf)) { n = priv->read_data(priv, p); nread += n; len -= n; p += n; } while (len > 0) { n = priv->read_data(priv, tmpbuf); if (n <= len) { memcpy(p, tmpbuf, n); len -= n; nread += n; p += n; } else { memcpy(p, tmpbuf, len); nread += len; leftover = n - len; len = 0; } } ++sg; } while (nread < total_len); #if 0 // dump packet for (sg = sg_list; sg < (sg_list + sg_len); sg++) { diag_printf("\n"); diag_dump_buf(sg->buf, sg->len); } #endif }
void show_jpeg(int client, char *file, int show_time) { GR_EVENT event; /* current event */ GR_IMAGE_ID id = 0; GR_SIZE w = -1; GR_SIZE h = -1; GR_IMAGE_INFO info; GR_WINDOW_ID w1; /* id for large window */ GR_GC_ID gc1; /* graphics context for text */ GR_SCREEN_INFO si; int time_left; bool ever_exposed = false; #if !defined(HAVE_JPEG_SUPPORT) && !defined(HAVE_BMP_SUPPORT) && !defined(HAVE_GIF_SUPPORT) printf("Sorry, no image support compiled in\n"); exit(1); #endif GrGetScreenInfo(&si); printf("Loading image: %s\n", file); if (access(file, F_OK) < 0) { fdprintf(client, "Can't access \"%s\": %s\n", file, strerror(errno)); return; } id = GrLoadImageFromFile(file, 0); if (id) { GrGetImageInfo(id, &info); } else { // File exists, so why the error? int fd, len; char buf[64]; fdprintf(client, "Can't load %s\n", file); if ((fd = open(file, O_RDONLY)) >= 0) { len = read(fd, buf, 64); if (len != 64) { diag_printf("Short read? len = %d\n", len); } else { diag_dump_buf(buf, len); } close(fd); } else { diag_printf("Can't oopen \"%s\": %s\n", file, strerror(errno)); } return; } w = info.width; h = info.height; if ((si.rows < info.height) || (si.cols < info.width)) { // Preserve aspect ratio if (si.cols < info.width) { w = si.cols; h = (si.cols * info.height) / info.width; } if (si.rows < h) { w = (si.rows * w) / h; h = si.rows; } } printf("Create window - orig %dx%d => %dx%d\n", info.width, info.height, w, h); fdprintf(client, "<INFO> Display \"%s\" - orig %dx%d => %dx%d\n", file, info.width, info.height, w, h); w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 10, 10, w, h, 4, BLACK, WHITE); GrSelectEvents(w1, GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE); GrMapWindow(w1); gc1 = GrNewGC(); GrSetGCForeground(gc1, WHITE); #define TO_MS 50 time_left = show_time * 1000; while (time_left > 0) { GrGetNextEventTimeout(&event, TO_MS); // milliseconds switch(event.type) { case GR_EVENT_TYPE_CLOSE_REQ: GrDestroyWindow(w1); GrFreeImage(id); return; /* no return*/ case GR_EVENT_TYPE_EXPOSURE: /*GrDrawImageFromFile(w1, gc1, 0, 0, w, h, argv[1],0);*/ GrDrawImageToFit(w1, gc1, 0, 0, w, h, id); ever_exposed = true; break; default: case GR_EVENT_TYPE_NONE: case GR_EVENT_TYPE_TIMEOUT: time_left -= TO_MS; if ((time_left < 0) && !ever_exposed) { // Things get real cranky if we delete the window too fast! time_left = TO_MS; } break; } } GrUnmapWindow(w1); GrDestroyWindow(w1); GrDestroyGC(gc1); GrFreeImage(id); }
static void read_partition(cyg_uint8 *data, cyg_disk_info_t *info, cyg_disk_partition_t *part) { cyg_disk_identify_t *ident = &info->ident; cyg_uint16 c, h, s; cyg_uint32 start, end, size; #ifdef DEBUG diag_printf("Partition data:\n"); diag_dump_buf( data, 16 ); diag_printf("Disk geometry: %d/%d/%d\n",info->ident.cylinders_num, info->ident.heads_num, info->ident.sectors_num ); #endif // Retrieve basic information part->type = data[4]; part->state = data[0]; READ_DWORD(&data[12], part->size); READ_DWORD(&data[8], start); READ_DWORD(&data[12], size); // Use the LBA start and size fields if they are valid. Otherwise // fall back to CHS. if( start > 0 && size > 0 ) { READ_DWORD(&data[8], start); end = start + size - 1; #ifdef DEBUG diag_printf("Using LBA partition parameters\n"); diag_printf(" LBA start %d\n",start); diag_printf(" LBA size %d\n",size); diag_printf(" LBA end %d\n",end); #endif } else { READ_CHS(&data[1], c, h, s); CHS_TO_LBA(ident, c, h, s, start); #ifdef DEBUG diag_printf("Using CHS partition parameters\n"); diag_printf(" CHS start %d/%d/%d => %d\n",c,h,s,start); #endif READ_CHS(&data[5], c, h, s); CHS_TO_LBA(ident, c, h, s, end); #ifdef DEBUG diag_printf(" CHS end %d/%d/%d => %d\n",c,h,s,end); diag_printf(" CHS size %d\n",size); #endif } part->size = size; part->start = start; part->end = end; }
externC void cyg_start( void ) { Cyg_ErrNo stat; cyg_io_handle_t flash_handle; cyg_io_flash_getconfig_erase_t e; cyg_io_flash_getconfig_devsize_t d; cyg_io_flash_getconfig_blocksize_t b; cyg_io_flash_getconfig_lock_t l; cyg_io_flash_getconfig_unlock_t u; CYG_ADDRWORD flash_start, flash_end; CYG_ADDRWORD flash_test_start, flash_addr; cyg_uint32 flash_block_size, flash_num_blocks; CYG_ADDRWORD test_buf1, test_buf2; cyg_uint32 *lp1, *lp2; int i, len; cyg_bool passed, ok; CYG_TEST_INIT(); passed = true; if ((stat = cyg_io_lookup(FLASH_TEST_DEVICE, &flash_handle)) == -ENOENT) { stat = cyg_io_lookup(FLASH_TEST_DEVICE2, &flash_handle); } if (stat != 0) { diag_printf("FLASH: driver init failed: %s\n", strerror(-stat)); CYG_TEST_FAIL_FINISH("FLASH driver init failed"); } len = sizeof(d); stat = cyg_io_get_config( flash_handle, CYG_IO_GET_CONFIG_FLASH_DEVSIZE, &d, &len ); flash_start = 0; // Keep 'end' address as last valid location, to avoid wrap around problems flash_end = d.dev_size - 1; len = sizeof(b); b.offset = 0; stat = cyg_io_get_config( flash_handle, CYG_IO_GET_CONFIG_FLASH_BLOCKSIZE, &b, &len ); flash_block_size = b.block_size; flash_num_blocks = d.dev_size/flash_block_size; diag_printf("FLASH: %p - %p, %d blocks of 0x%x bytes each.\n", (void*)flash_start, (void*)(flash_end + 1), flash_num_blocks, flash_block_size); // Verify that the testing limits are within the bounds of the // physical device. Also verify that the size matches with // the erase block size on the device if ((FLASH_TEST_OFFSET > (flash_end - flash_start)) || ((FLASH_TEST_OFFSET + FLASH_TEST_LENGTH) > (flash_end - flash_start))) { CYG_TEST_FAIL_FINISH("FLASH test region outside physical limits"); } if ((FLASH_TEST_LENGTH % flash_block_size) != 0) { CYG_TEST_FAIL_FINISH("FLASH test region must be integral multiple of erase block size"); } // Allocate two buffers large enough for the test test_buf1 = (CYG_ADDRWORD)CYGMEM_SECTION_heap1; test_buf2 = test_buf1 + FLASH_TEST_LENGTH; if (CYGMEM_SECTION_heap1_SIZE < (FLASH_TEST_LENGTH * 2)) { CYG_TEST_FAIL_FINISH("FLASH not enough heap space - reduce size of test region"); } diag_printf("... Using test buffers at %p and %p\n", (void *)test_buf1, (void *)test_buf2); flash_test_start = flash_start + FLASH_TEST_OFFSET; #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING // Unlock test diag_printf("... Unlock test\n"); ok = true; u.offset = flash_test_start; u.len = FLASH_TEST_LENGTH; len = sizeof(u); if ((stat = cyg_io_get_config(flash_handle, CYG_IO_GET_CONFIG_FLASH_UNLOCK, &u, &len ) ) != 0 || u.flasherr != 0) { diag_printf("FLASH: unlock failed: %s %s\n", strerror(stat), cyg_flash_errmsg(u.flasherr)); ok = false; } #endif // Erase test diag_printf("... Erase test\n"); ok = true; e.offset = flash_test_start; e.len = FLASH_TEST_LENGTH; len = sizeof(e); if ((stat = cyg_io_get_config(flash_handle, CYG_IO_GET_CONFIG_FLASH_ERASE, &e, &len ) ) != 0 || e.flasherr != 0) { diag_printf("FLASH: erase failed: %s %s\n", cyg_epcs_errmsg(stat), cyg_epcs_errmsg(e.flasherr)); ok = false; } len = FLASH_TEST_LENGTH; if (ok && (stat = cyg_io_bread(flash_handle, (void *)test_buf1, &len, flash_test_start)) != 0) { diag_printf("FLASH: read/verify after erase failed: %s\n", cyg_epcs_errmsg(stat)); ok = false; } lp1 = (cyg_uint32 *)test_buf1; for (i = 0; i < FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) { if (*lp1++ != 0xFFFFFFFF) { diag_printf("FLASH: non-erased data found at offset %p\n", (void*)((CYG_ADDRWORD)(lp1-1) - test_buf1)); diag_dump_buf((void *)(lp1-1), 32); ok = false; break; } } // Try reading in little pieces len = FLASH_TEST_LENGTH; flash_addr = flash_test_start; while (len > 0) { cyg_uint32 l = 0x200; if ((stat = cyg_io_bread(flash_handle, (void *)test_buf1, &l, flash_addr)) != CYG_FLASH_ERR_OK) { diag_printf("FLASH: read[short]/verify after erase failed: %s\n", strerror(stat)); ok = false; break; } flash_addr = flash_addr + l; len -= l; lp1 = (cyg_uint32 *)test_buf1; for (i = 0; i < 0x200; i += sizeof(cyg_uint32)) { if (*lp1++ != 0xFFFFFFFF) { diag_printf("FLASH: non-erased data found at offset %p\n", (cyg_uint8 *)flash_addr + (CYG_ADDRWORD)((lp1-1) - test_buf1)); diag_dump_buf((void *)(lp1-1), 32); ok = false; len = 0; break; } } } if (!ok) { CYG_TEST_INFO("FLASH erase failed"); passed = false; } // Simple write/verify test diag_printf("... Write/verify test\n"); lp1 = (cyg_uint32 *)test_buf1; for (i = 0; i < FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) { *lp1 = (cyg_uint32)lp1; lp1++; } ok = true; len = FLASH_TEST_LENGTH; if (ok && (stat = cyg_io_bwrite(flash_handle, (void *)test_buf1, &len, flash_test_start)) != 0) { diag_printf("FLASH: write failed: %s\n", strerror(stat)); ok = false; } len = FLASH_TEST_LENGTH; if (ok && (stat = cyg_io_bread(flash_handle, (void *)test_buf2, &len, flash_test_start)) != CYG_FLASH_ERR_OK) { diag_printf("FLASH: read/verify after write failed: %s\n", strerror(stat)); ok = false; } lp1 = (cyg_uint32 *)test_buf1; lp2 = (cyg_uint32 *)test_buf2; for (i = 0; i < FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) { if (*lp2++ != *lp1++) { diag_printf("FLASH: incorrect data found at offset %p\n", (void *)((CYG_ADDRWORD)(lp2-1) - test_buf2)); diag_dump_buf((void *)(lp2-1), 32); ok = false; break; } } // Try reading in little pieces len = FLASH_TEST_LENGTH; flash_addr = flash_test_start; lp1 = (cyg_uint32 *)test_buf1; lp2 = (cyg_uint32 *)test_buf2; while (len > 0) { cyg_uint32 l = 0x200; if ((stat = cyg_io_bread(flash_handle, (void *)lp2, &l, flash_addr)) != 0) { diag_printf("FLASH: read[short]/verify after erase failed: %s\n", strerror(stat)); ok = false; break; } flash_addr = flash_addr + l; len -= l; for (i = 0; i < l; i += sizeof(cyg_uint32)) { if (*lp2++ != *lp1++) { diag_printf("FLASH: incorrect data found at offset %p\n", (cyg_uint8 *)flash_addr + (CYG_ADDRWORD)((lp2-1) - test_buf2)); diag_dump_buf((void *)(lp2-1), 32); ok = false; len = 0; break; } } } #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING // Lock test diag_printf("... Lock test\n"); ok = true; l.offset = flash_test_start; l.len = FLASH_TEST_LENGTH; len = sizeof(l); if ((stat = cyg_io_get_config(flash_handle, CYG_IO_GET_CONFIG_FLASH_LOCK, &l, &len ) ) != 0 || l.flasherr != 0 ) { diag_printf("FLASH: unlock failed: %s %s\n", strerror(stat), cyg_flash_errmsg(l.flasherr)); ok = false; } #endif if (!ok) { CYG_TEST_INFO("FLASH write/verify failed"); } if (passed) { CYG_TEST_PASS_FINISH("FLASH test1"); } else { CYG_TEST_FAIL_FINISH("FLASH test1"); } }
int flash_hwr_init(void) { struct FLASH_query data, *qp; extern char flash_query[], flash_query_end[]; typedef int code_fun(unsigned char *); code_fun *_flash_query; int code_len, stat, num_regions, region_size, buffer_size; int icache_on, dcache_on; HAL_DCACHE_IS_ENABLED(dcache_on); HAL_ICACHE_IS_ENABLED(icache_on); // Copy 'program' code to RAM for execution code_len = (unsigned long)&flash_query_end - (unsigned long)&flash_query; _flash_query = (code_fun *)flash_info.work_space; memcpy(_flash_query, &flash_query, code_len); if (dcache_on) { HAL_DCACHE_SYNC(); // Should guarantee this code will run } if (icache_on) { HAL_ICACHE_DISABLE(); // is also required to avoid old contents } stat = (*_flash_query)((unsigned char *)&data); if (icache_on) { HAL_ICACHE_ENABLE(); } qp = &data; if ( (qp->manuf_code == FLASH_Intel_code) #ifdef CYGOPT_FLASH_IS_BOOTBLOCK // device types go as follows: 0x90 for 16-bits, 0xD0 for 8-bits, // plus 0 or 1 for -T (Top Boot) or -B (Bottom Boot) // [FIXME: whatever that means :FIXME] // [I think it means the boot blocks are top/bottom of addr space] // plus the following size codes: // 0: 16Mbit 2: 8Mbit 4: 4Mbit // 6: 32Mbit 8: 64Mbit #if 16 == CYGNUM_FLASH_WIDTH && (0x90 == (0xF0 & qp->device_code)) // 16-bit devices #elif 8 == CYGNUM_FLASH_WIDTH && (0xD0 == (0xF0 & qp->device_code)) // 8-bit devices #else && 0 #error Only understand 16 and 8-bit bootblock flash types #endif ) { int lookup[] = { 16, 8, 4, 32, 64 }; #define BLOCKSIZE (0x10000) region_size = BLOCKSIZE; num_regions = qp->device_code & 0x0F; num_regions >>= 1; if ( num_regions > 4 ) goto flash_type_unknown; num_regions = lookup[num_regions]; num_regions *= 1024 * 1024; // to bits num_regions /= 8; // to bytes num_regions /= BLOCKSIZE; // to blocks buffer_size = 0; #else // CYGOPT_FLASH_IS_BOOTBLOCK && (strncmp(qp->id, "QRY", 3) == 0)) { num_regions = _si(qp->num_regions)+1; region_size = _si(qp->region_size)*256; if (_si(qp->buffer_size)) { buffer_size = CYGNUM_FLASH_DEVICES << _si(qp->buffer_size); } else { buffer_size = 0; } #endif // Not CYGOPT_FLASH_IS_BOOTBLOCK flash_info.block_size = region_size*CYGNUM_FLASH_DEVICES; flash_info.buffer_size = buffer_size; flash_info.blocks = num_regions; flash_info.start = (void *)CYGNUM_FLASH_BASE; flash_info.end = (void *)(CYGNUM_FLASH_BASE + (num_regions*region_size*CYGNUM_FLASH_DEVICES)); #ifdef CYGNUM_FLASH_BASE_MASK // Then this gives us a maximum size for the (visible) device. // This is to cope with oversize devices fitted, with some high // address lines ignored. if ( ((unsigned int)flash_info.start & CYGNUM_FLASH_BASE_MASK) != (((unsigned int)flash_info.end - 1) & CYGNUM_FLASH_BASE_MASK ) ) { // then the size of the device appears to span >1 device-worth! unsigned int x; x = (~(CYGNUM_FLASH_BASE_MASK)) + 1; // expected device size x += (unsigned int)flash_info.start; if ( x < (unsigned int)flash_info.end ) { // 2nd sanity check (*flash_info.pf)("\nFLASH: Oversized device! End addr %p changed to %p\n", flash_info.end, (void *)x ); flash_info.end = (void *)x; // Also adjust the block count else unlock crashes! x = ((cyg_uint8 *)flash_info.end - (cyg_uint8 *)flash_info.start) / flash_info.block_size; flash_info.blocks = x; } } #endif // CYGNUM_FLASH_BASE_MASK return FLASH_ERR_OK; } #ifdef CYGOPT_FLASH_IS_BOOTBLOCK flash_type_unknown: #endif (*flash_info.pf)("Can't identify FLASH, sorry, man %x, dev %x, id [%4s] stat %x\n", qp->manuf_code, qp->device_code, qp->id, stat ); diag_dump_buf(qp, sizeof(data)); return FLASH_ERR_HWR; }
static void _mbx_init_i2c(void) { volatile EPPC *eppc = eppc_base(); unsigned char *sp, *ep; int i, len, RxBD, TxBD; struct i2c_pram *i2c; volatile struct cp_bufdesc *rxbd, *txbd; unsigned char i2c_address[521]; static int i2c_init = 0; if (i2c_init) return; i2c_init = 1; eppc->cp_rccr = 0; // Disables any current ucode running #ifdef _DOWNLOAD_UCODE_UPDATE // Not currently used // Patch the ucode sp = i2c_ucode_low; ep = (unsigned char *)eppc->udata_ucode; for (i = 0; i < sizeof(i2c_ucode_low); i++) { *ep++ = *sp++; } sp = i2c_ucode_high; ep = (unsigned char *)eppc->udata_ext; for (i = 0; i < sizeof(i2c_ucode_high); i++) { *ep++ = *sp++; } eppc->cp_rctr1 = 0x802A; eppc->cp_rctr2 = 0x8028; eppc->cp_rctr3 = 0x802E; eppc->cp_rctr4 = 0x802C; diag_printf("RCCR: %x, RTCRx: %x/%x/%x/%x\n", eppc->cp_rccr, eppc->cp_rctr1, eppc->cp_rctr2, eppc->cp_rctr3, eppc->cp_rctr4); diag_dump_buf(eppc->udata_ucode, 256); diag_dump_buf(&eppc->pram[0].scc.pothers.i2c_idma, 0x40); eppc->cp_rccr = 0x01; // Enable ucode diag_printf("RCCR: %x, RTCRx: %x/%x/%x/%x\n", eppc->cp_rccr, eppc->cp_rctr1, eppc->cp_rctr2, eppc->cp_rctr3, eppc->cp_rctr4); diag_dump_buf(eppc->udata_ucode, 256); diag_dump_buf(&eppc->pram[0].scc.pothers.i2c_idma, 0x40); diag_printf("RPBASE = %x/%x\n", eppc->pram[0].scc.pothers.i2c_idma.i2c.rpbase, &eppc->pram[0].scc.pothers.i2c_idma.i2c.rpbase); eppc->pram[0].scc.pothers.i2c_idma.i2c.rpbase = (unsigned long)&eppc->i2c_spare_pram - (unsigned long)eppc; diag_printf("RPBASE = %x/%x\n", eppc->pram[0].scc.pothers.i2c_idma.i2c.rpbase, &eppc->pram[0].scc.pothers.i2c_idma.i2c.rpbase); eppc->i2c_i2mod = 0; // Disable I2C controller i2c = (struct i2c_pram *)&eppc->i2c_spare_pram; #else eppc->i2c_i2mod = 0; // Disable I2C controller i2c = (struct i2c_pram *)&eppc->pram[0].scc.pothers.i2c_idma.i2c; #endif // _DOWNLOAD_UCODE_UPDATE sp = (unsigned char *)i2c; for (i = 0; i < sizeof(*i2c); i++) { *sp++ = 0; } RxBD = 0x2E08; // CAUTION TxBD = 0x2E00; i2c->rbase = RxBD; i2c->tbase = TxBD; i2c->rfcr = QUICC_I2C_FCR_BE; i2c->tfcr = QUICC_I2C_FCR_BE; i2c->mrblr = sizeof(i2c_address); rxbd = (volatile struct cp_bufdesc *)((char *)eppc + RxBD); rxbd->ctrl = QUICC_BD_CTL_Ready | QUICC_BD_CTL_Wrap | QUICC_BD_CTL_Last; rxbd->length = 257; rxbd->buffer = i2c_address; txbd = (volatile struct cp_bufdesc *)((char *)eppc + TxBD); txbd->length = 1+520; i2c_address[0] = MBX_CONFIG_EEPROM; txbd->buffer = i2c_address; txbd->ctrl = QUICC_BD_CTL_Ready | QUICC_BD_CTL_Wrap | QUICC_BD_CTL_Last; eppc->i2c_i2add = 0x00; eppc->i2c_i2brg = 0x50; eppc->i2c_i2mod = QUICC_I2C_MOD_EN; // Enable I2C interface // Initialize the CPM (set up buffer pointers, etc). // This needs to be done *after* the interface is enabled. eppc->cp_cr = QUICC_CPM_I2C | QUICC_CPM_CR_INIT_RX | QUICC_CPM_CR_BUSY; while (eppc->cp_cr & QUICC_CPM_CR_BUSY) ; eppc->cp_cr = QUICC_CPM_I2C | QUICC_CPM_CR_INIT_TX | QUICC_CPM_CR_BUSY; while (eppc->cp_cr & QUICC_CPM_CR_BUSY) ; eppc->i2c_i2com = QUICC_I2C_CMD_MASTER | QUICC_I2C_CMD_START; i = 0; while (txbd->ctrl & QUICC_BD_CTL_Ready) { if (++i > 50000) break; } // Rebuild the actual VPD for (i = 0; i < sizeof(_MBX_eeprom_data); i++) { _MBX_eeprom_data[i] = VPD_EOD; // Undefined } sp = (unsigned char *)&i2c_address[1]; ep = (unsigned char *)&i2c_address[sizeof(i2c_address)]; while (sp != ep) { if ((sp[0] == 'M') && (sp[1] == 'O') && (sp[2] == 'T')) { // Found the "eye catcher" string sp += 8; len = (sp[0] << 8) | sp[1]; sp += 2; for (i = 0; i < len; i++) { _MBX_eeprom_data[i] = *sp++; if (sp == ep) sp = (unsigned char *)&i2c_address[1]; } break; } sp++; } eppc->i2c_i2mod = 0; // Disable I2C interface }
static void ts_scan(cyg_addrword_t param) { short lastX, lastY; short x, y; struct _event *ev; bool pen_down; diag_printf("Touch Screen thread started\n"); // Discard the first sample - it's always 0 x = read_ts(ADS_MEASURE_X); y = read_ts(ADS_MEASURE_Y); lastX = lastY = -1; pen_down = false; while (true) { cyg_thread_delay(SCAN_DELAY); if ((*(volatile cyg_uint32 *)AAEC_PFDR & TS_INT) == 0) { // Pen is down x = read_ts(ADS_MEASURE_X); y = read_ts(ADS_MEASURE_Y); // diag_printf("X = %x, Y = %x\n", x, y); if ((x < X_THRESHOLD) || (y < Y_THRESHOLD)) { // Ignore 'bad' samples continue; } lastX = x; lastY = y; pen_down = true; } else { if (pen_down) { // Capture first 'up' event pen_down = false; x = lastX; y = lastY; } else { continue; // Nothing new to report } } if (num_events < MAX_EVENTS) { num_events++; ev = &_events[_event_put++]; if (_event_put == MAX_EVENTS) { _event_put = 0; } ev->button_state = pen_down ? 0x04 : 0x00; ev->xPos = x; ev->yPos = y; if (ts_select_active) { ts_select_active = false; cyg_selwakeup(&ts_select_info); } } #ifdef DEBUG_RAW_EVENTS memcpy(&_ts_buf[_ts_buf_ptr], pkt->data, 8); _ts_buf_ptr += 8; if (_ts_buf_ptr == 512) { diag_printf("TS handler\n"); diag_dump_buf(_ts_buf, 512); _ts_buf_ptr = 0; } #endif } }
int flash_hwr_init(void) { struct FLASH_query data, *qp; int num_regions, region_size, buffer_size; flash_dev_query(&data); qp = &data; if ( ((qp->manuf_code == FLASH_Intel_code) || (qp->manuf_code == FLASH_STMicro_code)) #ifdef CYGOPT_FLASH_IS_BOOTBLOCK // device types go as follows: 0x90 for 16-bits, 0xD0 for 8-bits, // plus 0 or 1 for -T (Top Boot) or -B (Bottom Boot) // [FIXME: whatever that means :FIXME] // [I think it means the boot blocks are top/bottom of addr space] // plus the following size codes: // 0: 16Mbit 2: 8Mbit 4: 4Mbit // 6: 32Mbit 8: 64Mbit #if 16 == CYGNUM_FLASH_WIDTH && (0x90 == (0xF0 & qp->device_code)) // 16-bit devices #elif 8 == CYGNUM_FLASH_WIDTH && (0xD0 == (0xF0 & qp->device_code)) // 8-bit devices #else && 0 #error Only understand 16 and 8-bit bootblock flash types #endif ) { int lookup[] = { 16, 8, 4, 32, 64 }; #define BLOCKSIZE (0x10000) region_size = BLOCKSIZE; num_regions = qp->device_code & 0x0F; num_regions >>= 1; if ( num_regions > 4 ) goto flash_type_unknown; num_regions = lookup[num_regions]; num_regions *= 1024 * 1024; // to bits num_regions /= 8; // to bytes num_regions /= BLOCKSIZE; // to blocks buffer_size = 0; #else // CYGOPT_FLASH_IS_BOOTBLOCK && (strncmp(qp->id, "QRY", 3) == 0)) { num_regions = _si(qp->num_regions)+1; region_size = _si(qp->region_size)*256; if (_si(qp->buffer_size)) { buffer_size = CYGNUM_FLASH_DEVICES << _si(qp->buffer_size); } else { buffer_size = 0; } #endif // Not CYGOPT_FLASH_IS_BOOTBLOCK flash_info.block_size = region_size*CYGNUM_FLASH_DEVICES; flash_info.buffer_size = buffer_size; flash_info.blocks = num_regions; flash_info.start = (void *)CYGNUM_FLASH_BASE; flash_info.end = (void *)(CYGNUM_FLASH_BASE + (num_regions*region_size*CYGNUM_FLASH_DEVICES)); #ifdef CYGNUM_FLASH_BASE_MASK // Then this gives us a maximum size for the (visible) device. // This is to cope with oversize devices fitted, with some high // address lines ignored. if ( ((unsigned int)flash_info.start & CYGNUM_FLASH_BASE_MASK) != (((unsigned int)flash_info.end - 1) & CYGNUM_FLASH_BASE_MASK ) ) { // then the size of the device appears to span >1 device-worth! unsigned int x; x = (~(CYGNUM_FLASH_BASE_MASK)) + 1; // expected device size x += (unsigned int)flash_info.start; if ( x < (unsigned int)flash_info.end ) { // 2nd sanity check (*flash_info.pf)("\nFLASH: Oversized device! End addr %p changed to %p\n", flash_info.end, (void *)x ); flash_info.end = (void *)x; // Also adjust the block count else unlock crashes! x = ((cyg_uint8 *)flash_info.end - (cyg_uint8 *)flash_info.start) / flash_info.block_size; flash_info.blocks = x; } } #endif // CYGNUM_FLASH_BASE_MASK return FLASH_ERR_OK; } #ifdef CYGOPT_FLASH_IS_BOOTBLOCK flash_type_unknown: #endif (*flash_info.pf)("Can't identify FLASH, sorry, man %x, dev %x, id [%4s] \n", qp->manuf_code, qp->device_code, qp->id ); diag_dump_buf(qp, sizeof(data)); return FLASH_ERR_HWR; }
externC void cyg_start( void ) { int stat; void *err_addr; CYG_ADDRWORD flash_start, flash_end; void **flash_start_addr = (void *)&flash_start; void **flash_end_addr = (void *)&flash_end; void *flash_test_start, *flash_addr; cyg_int32 flash_block_size, flash_num_blocks; CYG_ADDRWORD test_buf1, test_buf2; cyg_uint32 *lp1, *lp2; int i, len; cyg_bool passed, ok; CYG_TEST_INIT(); #if 0 int j; diag_printf("Testing udelay: "); for (i = 0; i < 30; i++) { for (j = 0; j < 1000; j++) { CYGACC_CALL_IF_DELAY_US(1000); // Should be 1 second } diag_printf("."); } diag_printf("\n"); #endif passed = true; if ((stat = flash_init(diag_printf)) != 0) { diag_printf("FLASH: driver init failed: %s\n", flash_errmsg(stat)); CYG_TEST_FAIL_FINISH("FLASH driver init failed"); } flash_get_limits((void *)0, flash_start_addr, flash_end_addr); // Keep 'end' address as last valid location, to avoid wrap around problems flash_end = flash_end - 1; flash_get_block_info(&flash_block_size, &flash_num_blocks); diag_printf("FLASH: 0x%x - 0x%x, %d blocks of 0x%x bytes each.\n", flash_start, flash_end + 1, flash_num_blocks, flash_block_size); // Verify that the testing limits are within the bounds of the // physical device. Also verify that the size matches with // the erase block size on the device if ((CYGNUM_IO_FLASH_TEST_OFFSET > (flash_end - flash_start)) || ((CYGNUM_IO_FLASH_TEST_OFFSET + CYGNUM_IO_FLASH_TEST_LENGTH) > (flash_end - flash_start))) { CYG_TEST_FAIL_FINISH("FLASH test region outside physical limits"); } if ((CYGNUM_IO_FLASH_TEST_LENGTH % flash_block_size) != 0) { CYG_TEST_FAIL_FINISH("FLASH test region must be integral multiple of erase block size"); } // Allocate two buffers large enough for the test test_buf1 = (CYG_ADDRWORD)CYGMEM_SECTION_heap1; test_buf2 = test_buf1 + CYGNUM_IO_FLASH_TEST_LENGTH; if (CYGMEM_SECTION_heap1_SIZE < (CYGNUM_IO_FLASH_TEST_LENGTH * 2)) { CYG_TEST_FAIL_FINISH("FLASH not enough heap space - reduce size of test region"); } diag_printf("... Using test buffers at %p and %p\n", (void *)test_buf1, (void *)test_buf2); flash_test_start = (void *)(flash_start + CYGNUM_IO_FLASH_TEST_OFFSET); #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING // Unlock test diag_printf("... Unlock test\n"); ok = true; if ((stat = flash_unlock(flash_test_start, CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) { diag_printf("FLASH: unlock failed: %s\n", flash_errmsg(stat)); ok = false; } #endif // Erase test diag_printf("... Erase test\n"); ok = true; if ((stat = flash_erase(flash_test_start, CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) { diag_printf("FLASH: erase failed: %s\n", flash_errmsg(stat)); ok = false; } if (ok && (stat = flash_read(flash_test_start, (void *)test_buf1, CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) { diag_printf("FLASH: read/verify after erase failed: %s\n", flash_errmsg(stat)); ok = false; } lp1 = (cyg_uint32 *)test_buf1; for (i = 0; i < CYGNUM_IO_FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) { if (*lp1++ != 0xFFFFFFFF) { diag_printf("FLASH: non-erased data found at offset %x\n", (CYG_ADDRWORD)(lp1-1) - test_buf1); diag_dump_buf((void *)(lp1-1), 32); ok = false; break; } } // Try reading in little pieces len = CYGNUM_IO_FLASH_TEST_LENGTH; flash_addr = flash_test_start; while (len > 0) { if ((stat = flash_read(flash_addr, (void *)test_buf1, 0x200, &err_addr)) != CYG_FLASH_ERR_OK) { diag_printf("FLASH: read[short]/verify after erase failed: %s\n", flash_errmsg(stat)); ok = false; break; } flash_addr = (cyg_uint8 *)flash_addr + 0x200; len -= 0x200; lp1 = (cyg_uint32 *)test_buf1; for (i = 0; i < 0x200; i += sizeof(cyg_uint32)) { if (*lp1++ != 0xFFFFFFFF) { diag_printf("FLASH: non-erased data found at offset %p\n", (cyg_uint8 *)flash_addr + (CYG_ADDRWORD)((lp1-1) - test_buf1)); diag_dump_buf((void *)(lp1-1), 32); ok = false; len = 0; break; } } } if (!ok) { CYG_TEST_INFO("FLASH erase failed"); passed = false; } // Simple write/verify test diag_printf("... Write/verify test\n"); lp1 = (cyg_uint32 *)test_buf1; for (i = 0; i < CYGNUM_IO_FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) { *lp1 = (cyg_uint32)lp1; lp1++; } ok = true; if (ok && (stat = flash_program(flash_test_start, (void *)test_buf1, CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) { diag_printf("FLASH: write failed: %s\n", flash_errmsg(stat)); ok = false; } if (ok && (stat = flash_read(flash_test_start, (void *)test_buf2, CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) { diag_printf("FLASH: read/verify after write failed: %s\n", flash_errmsg(stat)); ok = false; } lp1 = (cyg_uint32 *)test_buf1; lp2 = (cyg_uint32 *)test_buf2; for (i = 0; i < CYGNUM_IO_FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) { if (*lp2++ != *lp1++) { diag_printf("FLASH: incorrect data found at offset %x\n", (CYG_ADDRWORD)(lp2-1) - test_buf2); diag_dump_buf((void *)(lp2-1), 32); ok = false; break; } } // Try reading in little pieces len = CYGNUM_IO_FLASH_TEST_LENGTH; flash_addr = flash_test_start; lp1 = (cyg_uint32 *)test_buf1; lp2 = (cyg_uint32 *)test_buf2; while (len > 0) { if ((stat = flash_read(flash_addr, lp2, 0x200, &err_addr)) != CYG_FLASH_ERR_OK) { diag_printf("FLASH: read[short]/verify after erase failed: %s\n", flash_errmsg(stat)); ok = false; break; } flash_addr = (cyg_uint8 *)flash_addr + 0x200; len -= 0x200; for (i = 0; i < 0x200; i += sizeof(cyg_uint32)) { if (*lp2++ != *lp1++) { diag_printf("FLASH: incorrect data found at offset %p\n", (cyg_uint8 *)flash_addr + (CYG_ADDRWORD)((lp2-1) - test_buf2)); diag_dump_buf((void *)(lp2-1), 32); ok = false; len = 0; break; } } } if (!ok) { CYG_TEST_INFO("FLASH write/verify failed"); } #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING // Lock test diag_printf("... Lock test\n"); ok = true; if ((stat = flash_lock(flash_test_start, CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) { diag_printf("FLASH: unlock failed: %s\n", flash_errmsg(stat)); ok = false; } #endif if (passed) { CYG_TEST_PASS_FINISH("FLASH test1"); } else { CYG_TEST_FAIL_FINISH("FLASH test1"); } }