#include "config.h"
Go to the source code of this file.
Defines | |
#define | MEM_BSY 0 |
#define | MEM_OK 1 |
#define | MEM_KO 2 |
#define | DF_MSK_DENSITY ((Byte)0x3C) |
#define | DF_MSK_BIT_BUSY ((Byte)0x80) |
#define | DF_MEM_BUSY ((Byte)0x00) |
#define | DF_RD_STATUS ((Byte)0xD7) |
#define | DF_PG_ERASE ((Byte)0x81) |
#define | DF_BK_ERASE ((Byte)0x50) |
#define | DF_WR_BUF_1 ((Byte)0x84) |
#define | DF_WR_BUF_2 ((Byte)0x87) |
#define | DF_B1_MAIN ((Byte)0x83) |
#define | DF_B2_MAIN ((Byte)0x86) |
#define | DF_RD_MAIN ((Byte)0xD2) |
#define | DF_TF_BUF_1 ((Byte)0x53) |
#define | DF_TF_BUF_2 ((Byte)0x55) |
#define | DF_RD_BUF_1 ((Byte)0xD4) |
#define | DF_RD_BUF_2 ((Byte)0xD6) |
#define | DF_4MB ((Byte)0) |
#define | DF_8MB ((Byte)1) |
#define | DF_16MB ((Byte)2) |
#define | DF_32MB ((Byte)3) |
#define | DF_64MB ((Byte)4) |
#define | df_set_busy(i) (df_mem_busy |= (1<<i)) |
#define | df_release_busy(i) (df_mem_busy &= ~(1<<i)) |
#define | is_df_busy(i) (((df_mem_busy&(1<<i)) != 0) ? TRUE : FALSE) |
Functions | |
void | df_init (void) |
This function initializes the SPI bus over which the DF is controlled. | |
Bool | df_mem_check (void) |
This function performs a memory check on all DF. | |
Bool | df_read_open (Uint32) |
This function opens a DF memory in read mode at a given sector address. | |
void | df_read_close (void) |
This function unselects the current DF memory. | |
Bool | df_write_open (Uint32) |
This function opens a DF memory in write mode at a given sector address. | |
void | df_write_close (void) |
This function fills the end of the logical sector (512B) and launch page programming. | |
Bool | df_write_sector (Uint16) |
Funtions to link USB DEVICE flow with data flash. | |
Bool | df_read_sector (Uint16) |
This function is optimized and writes nb-sector * 512 Bytes from DataFlash memory to USB controller. | |
bit | df_host_write_sector (Uint16) |
Funtions to link USB HOST flow with data flash. | |
bit | df_host_read_sector (Uint16) |
Bool | df_read_sector_2_ram (U8 *ram) |
Functions to read/write one sector (512btes) with ram buffer pointer. | |
Bool | df_write_sector_from_ram (U8 *ram) |
This function write one DF sector from a ram buffer. |
Definition in file df.h.
#define DF_MSK_DENSITY ((Byte)0x3C) |
#define DF_MSK_BIT_BUSY ((Byte)0x80) |
#define DF_MEM_BUSY ((Byte)0x00) |
#define DF_RD_STATUS ((Byte)0xD7) |
#define DF_RD_MAIN ((Byte)0xD2) |
#define DF_TF_BUF_1 ((Byte)0x53) |
#define df_set_busy | ( | i | ) | (df_mem_busy |= (1<<i)) |
Definition at line 89 of file df.h.
Referenced by df_host_write_sector(), df_write_close(), and df_write_sector().
#define df_release_busy | ( | i | ) | (df_mem_busy &= ~(1<<i)) |
#define is_df_busy | ( | i | ) | (((df_mem_busy&(1<<i)) != 0) ? TRUE : FALSE) |
void df_init | ( | void | ) |
This function initializes the SPI bus over which the DF is controlled.
Definition at line 67 of file df.c.
References Df_init_spi, df_mem_busy, df_select, Spi_disable_ss, Spi_enable, Spi_init_bus, SPI_MODE_3, SPI_RATE_0, Spi_select_master, Spi_set_mode, and Spi_set_rate.
00068 { 00069 // Init the SPI communication link between the DF and the DF driver. 00070 Df_init_spi(); 00071 Spi_select_master(); 00072 Spi_set_mode(SPI_MODE_3); 00073 Spi_init_bus(); 00074 Spi_set_rate(SPI_RATE_0); // SCK freq == fosc/2. 00075 Spi_disable_ss(); 00076 Spi_enable(); 00077 00078 // Data Flash Controller init. 00079 df_mem_busy = 0; // all memories ready 00080 df_select = 0; 00081 }
Bool df_mem_check | ( | void | ) |
This function performs a memory check on all DF.
Definition at line 197 of file df.c.
References df_chipselect_current(), Df_desel_all, DF_MSK_DENSITY, DF_NB_MEM, DF_RD_STATUS, df_select, KO, OK, Spi_read_data, and Spi_write_data.
00198 { 00199 // DF memory check. 00200 for(df_select=0; df_select<DF_NB_MEM; df_select++) 00201 { 00202 df_chipselect_current(); 00203 Spi_write_data(DF_RD_STATUS); // Send the read status register cmd 00204 // + 1st step to clear the SPIF bit 00205 Spi_write_data(0); // dummy write that: 00206 // - finalize the clear of the SPIF bit (access to SPDR) 00207 // - get status register 00208 // - does the 1st step to clear the SPIF bit 00209 // Following Spi_read_data() finalize the clear of SPIF by accessing SPDR. 00210 // Check the DF density. 00211 if ((Spi_read_data() & DF_MSK_DENSITY) != DF_DENSITY) 00212 { 00213 // Unexpected value. 00214 Df_desel_all(); 00215 return (KO); 00216 } 00217 Df_desel_all(); 00218 } 00219 return OK; 00220 }
This function opens a DF memory in read mode at a given sector address.
NOTE: Address may not be synchronized on the beginning of a page (depending on the DF page size).
pos | Logical sector address |
Definition at line 255 of file df.c.
References df_chipselect_current(), df_chipselect_memzone(), DF_RD_MAIN, df_release_busy, df_select, df_translate_addr(), df_wait_busy(), gl_ptr_mem, is_df_busy, LSB0, MSB1, MSB2, MSB3, OK, Spi_ack_write, and Spi_write_data.
00256 { 00257 // Set the global memory ptr at a Byte address. 00258 gl_ptr_mem = df_translate_addr(pos); 00259 00260 // Select the DF that memory "pos" points to (the "df_select" variable will be updated) 00261 df_chipselect_memzone(LSB0(pos)); 00262 00263 // If the DF memory is busy, wait until it's not. 00264 if (is_df_busy(df_select)) 00265 { 00266 df_release_busy(df_select); 00267 df_wait_busy(); // wait end of programming 00268 } 00269 00270 // Physically assert the selected dataflash 00271 df_chipselect_current(); 00272 00273 //# 00274 //# Initiate a page read at a given sector address. 00275 //# 00276 // Send read main command, + first step to clear the SPIF bit 00277 Spi_write_data(DF_RD_MAIN); 00278 // Final step to clear the SPIF bit will be done on the next write 00279 00280 // Send the three address Bytes made of: 00281 // - the page-address(first xbits), 00282 // - the Byte-address within the page(last ybits). 00283 // (x and y depending on the DF type). 00284 // NOTE: the bits of gl_ptr_mem above the 24bits are not useful for the local 00285 // DF addressing. They are used for DF discrimination when there are several 00286 // DFs. 00287 Spi_write_data((MSB1(gl_ptr_mem) << DF_SHFT_B1) | (MSB2(gl_ptr_mem) >> DF_SHFT_B2)); 00288 Spi_write_data(((MSB2(gl_ptr_mem) & ~DF_PAGE_MASK) << DF_SHFT_B1) | (MSB2(gl_ptr_mem) & DF_PAGE_MASK)); 00289 Spi_write_data(MSB3(gl_ptr_mem)); 00290 // Final step to clear the SPIF bit will be done on the next write 00291 00292 // 4 dummy writes for reading delay 00293 Spi_write_data(0xFF); 00294 Spi_write_data(0xFF); 00295 Spi_write_data(0xFF); 00296 Spi_write_data(0xFF); // Tx 0xFF, first step to clear the SPIF bit 00297 Spi_ack_write(); // Final step to clear the SPIF bit. 00298 00299 return OK; 00300 }
void df_read_close | ( | void | ) |
This function unselects the current DF memory.
Definition at line 305 of file df.c.
References Df_desel_all.
00306 { 00307 Df_desel_all(); // Unselect memory 00308 }
This function opens a DF memory in write mode at a given sector address.
NOTE: If page buffer > 512 bytes, page content is first loaded in buffer to be partially updated by write_byte or write64 functions.
pos | Sector address |
Definition at line 455 of file df.c.
References df_chipselect_current(), df_chipselect_memzone(), Df_desel_all, df_release_busy, df_select, DF_TF_BUF_1, df_translate_addr(), df_wait_busy(), gl_ptr_mem, is_df_busy, LSB0, MSB1, MSB2, MSB3, OK, Spi_ack_write, and Spi_write_data.
00456 { 00457 // Set the global memory ptr at a Byte address. 00458 gl_ptr_mem = df_translate_addr(pos); 00459 00460 // Select the DF that memory "pos" points to 00461 df_chipselect_memzone(LSB0(pos)); 00462 00463 // If the DF memory is busy, wait until it's not. 00464 if (is_df_busy(df_select)) 00465 { 00466 df_release_busy(df_select); 00467 df_wait_busy(); // wait end of programming 00468 } 00469 00470 #if DF_PAGE_SIZE > 512 00471 // Physically assert the selected dataflash 00472 df_chipselect_current(); 00473 00474 //# 00475 //# Transfer the current page content in buffer1. 00476 //# 00477 // Send Main Mem page to Buffer1 command, + first step to clear the SPIF bit 00478 Spi_write_data(DF_TF_BUF_1); 00479 // Final step to clear the SPIF bit will be done on the next write 00480 00481 // Send the three address Bytes made of: 00482 // - the page-address(first xbits), 00483 // - remaining don't care bits(last ybits). 00484 // (x and y depending on the DF type). 00485 // NOTE: the bits of gl_ptr_mem above the 24bits are not useful for the local 00486 // DF addressing. They are used for DF discrimination when there are several 00487 // DFs. 00488 Spi_write_data((MSB1(gl_ptr_mem) << DF_SHFT_B1) | (MSB2(gl_ptr_mem) >> DF_SHFT_B2)); 00489 Spi_write_data(MSB2(gl_ptr_mem) << DF_SHFT_B1); 00490 Spi_write_data(0); // Remaining don't care bits. 00491 Spi_ack_write(); // Final step to clear the SPIF bit. 00492 00493 Df_desel_all(); // Unselect memory to validate the command 00494 00495 df_wait_busy(); // Wait end of page transfer 00496 #endif 00497 00498 // Physically assert the selected dataflash 00499 df_chipselect_current(); 00500 00501 //# 00502 //# Initiate a page write at a given sector address. 00503 //# 00504 // Send Main Memory Page Program Through Buffer1 command, 00505 // + first step to clear the SPIF bit 00506 Spi_write_data(DF_PG_BUF_1); 00507 // Final step to clear the SPIF bit will be done on the next write 00508 00509 // Send the three address Bytes made of: 00510 // (.) the page-address(first xbits), 00511 // (.) the Byte-address within the page(last ybits). 00512 // (x and y depending on the DF type). 00513 // NOTE: the bits of gl_ptr_mem above the 24bits are not useful for the local 00514 // DF addressing. They are used for DF discrimination when there are several 00515 // DFs. 00516 Spi_write_data((MSB1(gl_ptr_mem) << DF_SHFT_B1) | (MSB2(gl_ptr_mem) >> DF_SHFT_B2)); 00517 Spi_write_data(((MSB2(gl_ptr_mem) & ~DF_PAGE_MASK) << DF_SHFT_B1) | (MSB2(gl_ptr_mem) & DF_PAGE_MASK)); 00518 Spi_write_data(MSB3(gl_ptr_mem)); 00519 Spi_ack_write(); // Final step to clear the SPIF bit. 00520 00521 return OK; 00522 }
void df_write_close | ( | void | ) |
This function fills the end of the logical sector (512B) and launch page programming.
Definition at line 527 of file df.c.
References Df_desel_all, df_select, df_set_busy, gl_ptr_mem, MSB2, MSB3, Spi_ack_write, and Spi_write_data.
00528 { 00529 //# 00530 //# While end of logical sector (512B) not reached, zero-fill the remaining 00531 //# memory Bytes. 00532 //# 00533 while ((MSB3(gl_ptr_mem) != 0x00) || ((MSB2(gl_ptr_mem) & 0x01) != 0x00)) 00534 { 00535 Spi_write_data(0x00); // - Final step to clear the SPIF bit, 00536 // - Write 0x00 00537 // - first step to clear the SPIF bit. 00538 gl_ptr_mem++; 00539 } 00540 Spi_ack_write(); // Final step to clear the SPIF bit. 00541 00542 Df_desel_all(); // Launch page programming (or simply unselect memory 00543 // if the while loop was not performed). 00544 df_set_busy(df_select); // Current memory is busy 00545 }
Funtions to link USB DEVICE flow with data flash.
Funtions to link USB DEVICE flow with data flash.
NOTE:
nb_sector | number of contiguous sectors to write [IN] |
Definition at line 562 of file df.c.
References Df_desel_all, df_select, df_set_busy, df_write_open(), gl_ptr_mem, i, Is_usb_endpoint_enabled, Is_usb_read_enabled, j, KO, MSB2, OK, Spi_ack_write, Spi_write_data, Usb_ack_receive_out, and Usb_read_byte.
00563 { 00564 U8 i; 00565 #ifdef DF_CODE_SIZE_OPTIMIZATION 00566 U8 j; 00567 #endif 00568 do 00569 { 00570 //# Write 8x64b = 512b from the USB FIFO OUT. 00571 for (i = 8; i != 0; i--) 00572 { 00573 // Wait end of rx in USB EPOUT. 00574 while(!Is_usb_read_enabled()) 00575 { 00576 if(!Is_usb_endpoint_enabled()) 00577 return KO; // USB Reset 00578 } 00579 00580 Disable_interrupt(); // Global disable. 00581 00582 // SPI write principle: send a Byte then clear the SPIF flag. 00583 // Spi_write_data(Usb_read_byte()): (.) Final step to clear the SPIF bit, 00584 // (.) send a Byte read from USB, 00585 // (.) 1st step to clear the SPIF bit. 00586 #ifdef DF_CODE_SIZE_OPTIMIZATION 00587 for(j=0;j<64;j++) 00588 { 00589 Spi_write_data(Usb_read_byte()); 00590 } 00591 #else 00592 Spi_write_data(Usb_read_byte()); 00593 Spi_write_data(Usb_read_byte()); 00594 Spi_write_data(Usb_read_byte()); 00595 Spi_write_data(Usb_read_byte()); 00596 Spi_write_data(Usb_read_byte()); 00597 Spi_write_data(Usb_read_byte()); 00598 Spi_write_data(Usb_read_byte()); 00599 Spi_write_data(Usb_read_byte()); 00600 Spi_write_data(Usb_read_byte()); 00601 Spi_write_data(Usb_read_byte()); 00602 Spi_write_data(Usb_read_byte()); 00603 Spi_write_data(Usb_read_byte()); 00604 Spi_write_data(Usb_read_byte()); 00605 Spi_write_data(Usb_read_byte()); 00606 Spi_write_data(Usb_read_byte()); 00607 Spi_write_data(Usb_read_byte()); 00608 Spi_write_data(Usb_read_byte()); 00609 Spi_write_data(Usb_read_byte()); 00610 Spi_write_data(Usb_read_byte()); 00611 Spi_write_data(Usb_read_byte()); 00612 Spi_write_data(Usb_read_byte()); 00613 Spi_write_data(Usb_read_byte()); 00614 Spi_write_data(Usb_read_byte()); 00615 Spi_write_data(Usb_read_byte()); 00616 Spi_write_data(Usb_read_byte()); 00617 Spi_write_data(Usb_read_byte()); 00618 Spi_write_data(Usb_read_byte()); 00619 Spi_write_data(Usb_read_byte()); 00620 Spi_write_data(Usb_read_byte()); 00621 Spi_write_data(Usb_read_byte()); 00622 Spi_write_data(Usb_read_byte()); 00623 Spi_write_data(Usb_read_byte()); 00624 Spi_write_data(Usb_read_byte()); 00625 Spi_write_data(Usb_read_byte()); 00626 Spi_write_data(Usb_read_byte()); 00627 Spi_write_data(Usb_read_byte()); 00628 Spi_write_data(Usb_read_byte()); 00629 Spi_write_data(Usb_read_byte()); 00630 Spi_write_data(Usb_read_byte()); 00631 Spi_write_data(Usb_read_byte()); 00632 Spi_write_data(Usb_read_byte()); 00633 Spi_write_data(Usb_read_byte()); 00634 Spi_write_data(Usb_read_byte()); 00635 Spi_write_data(Usb_read_byte()); 00636 Spi_write_data(Usb_read_byte()); 00637 Spi_write_data(Usb_read_byte()); 00638 Spi_write_data(Usb_read_byte()); 00639 Spi_write_data(Usb_read_byte()); 00640 Spi_write_data(Usb_read_byte()); 00641 Spi_write_data(Usb_read_byte()); 00642 Spi_write_data(Usb_read_byte()); 00643 Spi_write_data(Usb_read_byte()); 00644 Spi_write_data(Usb_read_byte()); 00645 Spi_write_data(Usb_read_byte()); 00646 Spi_write_data(Usb_read_byte()); 00647 Spi_write_data(Usb_read_byte()); 00648 Spi_write_data(Usb_read_byte()); 00649 Spi_write_data(Usb_read_byte()); 00650 Spi_write_data(Usb_read_byte()); 00651 Spi_write_data(Usb_read_byte()); 00652 Spi_write_data(Usb_read_byte()); 00653 Spi_write_data(Usb_read_byte()); 00654 Spi_write_data(Usb_read_byte()); 00655 Spi_write_data(Usb_read_byte()); 00656 #endif 00657 Spi_ack_write(); // Final step to clear the SPIF bit. 00658 00659 Usb_ack_receive_out(); // USB EPOUT read acknowledgement. 00660 00661 Enable_interrupt(); // Global re-enable. 00662 } // for (i = 8; i != 0; i--) 00663 00664 gl_ptr_mem += 512; // Update the memory pointer. 00665 nb_sector--; // 1 more sector written 00666 00667 //# Launch page programming if end of page. 00668 //# 00669 #if DF_PAGE_SIZE > 512 00670 // Check if end of 1024b page. 00671 if ((MSB2(gl_ptr_mem) & DF_PAGE_MASK) == 0x00) 00672 { 00673 Df_desel_all(); // Launch page programming 00674 df_set_busy(df_select); // memory is busy 00675 #if (DF_NB_MEM == 1) 00676 if (nb_sector != 0) 00677 df_write_open(gl_ptr_mem>>9); 00678 #endif 00679 } 00680 #else 00681 // Always end of page. 00682 Df_desel_all(); // Launch page programming 00683 df_set_busy(df_select); // memory is busy 00684 #if (DF_NB_MEM == 1) 00685 if (nb_sector != 0) 00686 df_write_open(gl_ptr_mem>>9); 00687 #endif 00688 #endif 00689 } 00690 while (nb_sector != 0); 00691 00692 return OK; // Write done 00693 }
This function is optimized and writes nb-sector * 512 Bytes from DataFlash memory to USB controller.
NOTE:
nb_sector | number of contiguous sectors to read [IN] |
Definition at line 326 of file df.c.
References Df_desel_all, df_read_open(), FALSE, gl_ptr_mem, i, Is_usb_endpoint_enabled, Is_usb_write_enabled, j, KO, MSB2, OK, Spi_read_data, Spi_write_data, Usb_send_in, and Usb_write_byte.
00327 { 00328 U8 i; 00329 #ifdef DF_CODE_SIZE_OPTIMIZATION 00330 U8 j; 00331 #endif 00332 do 00333 { 00334 for (i = 8; i != 0; i--) 00335 { 00336 Disable_interrupt(); // Global disable. 00337 00338 // Principle: send any Byte to get a Byte. 00339 // Spi_write_data(0): send any Byte + 1st step to clear the SPIF bit. 00340 // Spi_read_data(): get the Byte + final step to clear the SPIF bit. 00341 #ifdef DF_CODE_SIZE_OPTIMIZATION 00342 for(j=0;j<64;j++) 00343 { 00344 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00345 } 00346 #else 00347 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00348 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00349 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00350 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00351 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00352 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00353 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00354 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00355 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00356 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00357 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00358 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00359 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00360 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00361 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00362 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00363 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00364 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00365 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00366 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00367 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00368 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00369 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00370 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00371 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00372 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00373 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00374 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00375 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00376 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00377 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00378 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00379 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00380 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00381 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00382 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00383 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00384 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00385 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00386 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00387 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00388 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00389 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00390 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00391 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00392 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00393 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00394 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00395 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00396 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00397 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00398 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00399 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00400 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00401 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00402 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00403 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00404 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00405 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00406 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00407 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00408 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00409 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00410 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00411 #endif 00412 Usb_send_in(); // Send the FIFO IN content to the USB Host. 00413 00414 Enable_interrupt(); // Global interrupt re-enable. 00415 00416 // Wait until the tx is done so that we may write to the FIFO IN again. 00417 while(Is_usb_write_enabled()==FALSE) 00418 { 00419 if(!Is_usb_endpoint_enabled()) 00420 return KO; // USB Reset 00421 } 00422 } 00423 gl_ptr_mem += 512; // increment global address pointer 00424 nb_sector--; // 1 more sector read 00425 #if (DF_NB_MEM == 1) // end of page ? 00426 #if (DF_PAGE_SIZE == 512) 00427 Df_desel_all(); 00428 if (nb_sector != 0) 00429 df_read_open(gl_ptr_mem>>9); 00430 #else 00431 if ((MSB2(gl_ptr_mem) & DF_PAGE_MASK) == 0x00) 00432 { 00433 Df_desel_all(); 00434 if (nb_sector != 0) 00435 df_read_open(gl_ptr_mem>>9); 00436 } 00437 #endif 00438 #endif 00439 } 00440 while (nb_sector != 0); 00441 00442 return OK; 00443 }
bit df_host_write_sector | ( | Uint16 | nb_sector | ) |
Funtions to link USB HOST flow with data flash.
This function is optimized and writes nb-sector * 512 Bytes from USB HOST controller to DataFlash memory DATA FLOW is: USB => DF NOTE:
nb_sector | number of contiguous sectors to write [IN] |
Definition at line 720 of file df.c.
References Df_desel_all, df_select, df_set_busy, df_write_open(), FALSE, gl_ptr_mem, Host_ack_in_received, Host_unfreeze_pipe, i, Is_host_read_enabled, MSB2, OK, Spi_ack_write, Spi_write_data, and Usb_read_byte.
00721 { 00722 Byte i; 00723 00724 do 00725 { 00726 //# Write 8x64b = 512b from the USB FIFO OUT. 00727 for (i = 8; i != 0; i--) 00728 { 00729 // Wait end of rx in USB PIPE IN. 00730 Host_unfreeze_pipe(); 00731 while(Is_host_read_enabled()==FALSE); 00732 00733 Disable_interrupt(); // Global disable. 00734 00735 // SPI write principle: send a Byte then clear the SPIF flag. 00736 // Spi_write_data(Usb_read_byte()): (.) Final step to clear the SPIF bit, 00737 // (.) send a Byte read from USB, 00738 // (.) 1st step to clear the SPIF bit. 00739 Spi_write_data(Usb_read_byte()); 00740 Spi_write_data(Usb_read_byte()); 00741 Spi_write_data(Usb_read_byte()); 00742 Spi_write_data(Usb_read_byte()); 00743 Spi_write_data(Usb_read_byte()); 00744 Spi_write_data(Usb_read_byte()); 00745 Spi_write_data(Usb_read_byte()); 00746 Spi_write_data(Usb_read_byte()); 00747 Spi_write_data(Usb_read_byte()); 00748 Spi_write_data(Usb_read_byte()); 00749 Spi_write_data(Usb_read_byte()); 00750 Spi_write_data(Usb_read_byte()); 00751 Spi_write_data(Usb_read_byte()); 00752 Spi_write_data(Usb_read_byte()); 00753 Spi_write_data(Usb_read_byte()); 00754 Spi_write_data(Usb_read_byte()); 00755 Spi_write_data(Usb_read_byte()); 00756 Spi_write_data(Usb_read_byte()); 00757 Spi_write_data(Usb_read_byte()); 00758 Spi_write_data(Usb_read_byte()); 00759 Spi_write_data(Usb_read_byte()); 00760 Spi_write_data(Usb_read_byte()); 00761 Spi_write_data(Usb_read_byte()); 00762 Spi_write_data(Usb_read_byte()); 00763 Spi_write_data(Usb_read_byte()); 00764 Spi_write_data(Usb_read_byte()); 00765 Spi_write_data(Usb_read_byte()); 00766 Spi_write_data(Usb_read_byte()); 00767 Spi_write_data(Usb_read_byte()); 00768 Spi_write_data(Usb_read_byte()); 00769 Spi_write_data(Usb_read_byte()); 00770 Spi_write_data(Usb_read_byte()); 00771 Spi_write_data(Usb_read_byte()); 00772 Spi_write_data(Usb_read_byte()); 00773 Spi_write_data(Usb_read_byte()); 00774 Spi_write_data(Usb_read_byte()); 00775 Spi_write_data(Usb_read_byte()); 00776 Spi_write_data(Usb_read_byte()); 00777 Spi_write_data(Usb_read_byte()); 00778 Spi_write_data(Usb_read_byte()); 00779 Spi_write_data(Usb_read_byte()); 00780 Spi_write_data(Usb_read_byte()); 00781 Spi_write_data(Usb_read_byte()); 00782 Spi_write_data(Usb_read_byte()); 00783 Spi_write_data(Usb_read_byte()); 00784 Spi_write_data(Usb_read_byte()); 00785 Spi_write_data(Usb_read_byte()); 00786 Spi_write_data(Usb_read_byte()); 00787 Spi_write_data(Usb_read_byte()); 00788 Spi_write_data(Usb_read_byte()); 00789 Spi_write_data(Usb_read_byte()); 00790 Spi_write_data(Usb_read_byte()); 00791 Spi_write_data(Usb_read_byte()); 00792 Spi_write_data(Usb_read_byte()); 00793 Spi_write_data(Usb_read_byte()); 00794 Spi_write_data(Usb_read_byte()); 00795 Spi_write_data(Usb_read_byte()); 00796 Spi_write_data(Usb_read_byte()); 00797 Spi_write_data(Usb_read_byte()); 00798 Spi_write_data(Usb_read_byte()); 00799 Spi_write_data(Usb_read_byte()); 00800 Spi_write_data(Usb_read_byte()); 00801 Spi_write_data(Usb_read_byte()); 00802 Spi_write_data(Usb_read_byte()); 00803 Spi_ack_write(); // Final step to clear the SPIF bit. 00804 Host_ack_in_received(); // USB PIPE IN read acknowledgement. 00805 00806 Enable_interrupt(); // Global re-enable. 00807 } // for (i = 8; i != 0; i--) 00808 00809 gl_ptr_mem += 512; // Update the memory pointer. 00810 nb_sector--; // 1 more sector written 00811 00812 //# Launch page programming if end of page. 00813 //# 00814 #if DF_PAGE_SIZE > 512 00815 // Check if end of 1024b page. 00816 if ((MSB2(gl_ptr_mem) & DF_PAGE_MASK) == 0x00) 00817 { 00818 Df_desel_all(); // Launch page programming 00819 df_set_busy(df_select); // memory is busy 00820 #if (DF_NB_MEM == 1) 00821 if (nb_sector != 0) 00822 df_write_open(gl_ptr_mem>>9); 00823 #endif 00824 } 00825 #else 00826 // Always end of page. 00827 Df_desel_all(); // Launch page programming 00828 df_set_busy(df_select); // memory is busy 00829 #if (DF_NB_MEM == 1) 00830 if (nb_sector != 0) 00831 df_write_open(gl_ptr_mem>>9); 00832 #endif 00833 #endif 00834 } 00835 while (nb_sector != 0); 00836 00837 return OK; // Write done 00838 }
bit df_host_read_sector | ( | Uint16 | nb_sector | ) |
This function is optimized and writes nb-sector * 512 Bytes from DataFlash memory to USB HOST controller DATA FLOW is: DF => USB NOTE:
nb_sector | number of contiguous sectors to read [IN] |
Definition at line 864 of file df.c.
References Df_desel_all, df_read_open(), FALSE, gl_ptr_mem, Host_ack_out_sent, Host_send_out, Host_unfreeze_pipe, i, Is_host_out_sent, MSB2, OK, Spi_read_data, Spi_write_data, and Usb_write_byte.
00865 { 00866 U8 i; 00867 do 00868 { 00869 for (i = 8; i != 0; i--) 00870 { 00871 Disable_interrupt(); // Global disable. 00872 00873 // Principle: send any Byte to get a Byte. 00874 // Spi_write_data(0): send any Byte + 1st step to clear the SPIF bit. 00875 // Spi_read_data(): get the Byte + final step to clear the SPIF bit. 00876 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00877 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00878 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00879 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00880 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00881 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00882 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00883 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00884 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00885 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00886 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00887 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00888 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00889 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00890 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00891 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00892 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00893 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00894 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00895 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00896 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00897 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00898 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00899 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00900 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00901 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00902 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00903 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00904 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00905 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00906 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00907 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00908 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00909 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00910 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00911 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00912 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00913 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00914 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00915 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00916 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00917 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00918 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00919 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00920 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00921 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00922 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00923 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00924 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00925 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00926 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00927 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00928 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00929 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00930 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00931 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00932 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00933 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00934 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00935 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00936 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00937 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00938 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00939 Spi_write_data(0); Usb_write_byte(Spi_read_data()); 00940 00941 Enable_interrupt(); // Global re-enable. 00942 00943 //# 00944 //# Send the USB FIFO IN content to the USB Host. 00945 //# 00946 Host_send_out(); // Send the FIFO from the USB Host. 00947 Host_unfreeze_pipe(); 00948 // Wait until the tx is done so that we may write to the FIFO IN again. 00949 while(Is_host_out_sent()==FALSE); 00950 Host_ack_out_sent(); 00951 } 00952 gl_ptr_mem += 512; // increment global address pointer 00953 nb_sector--; // 1 more sector read 00954 #if (DF_NB_MEM == 1) // end of page ? 00955 #if (DF_PAGE_SIZE == 512) 00956 Df_desel_all(); 00957 if (nb_sector != 0) 00958 df_read_open(gl_ptr_mem>>9); 00959 #else 00960 if ((MSB2(gl_ptr_mem) & DF_PAGE_MASK) == 0x00) 00961 { 00962 Df_desel_all(); 00963 if (nb_sector != 0) 00964 df_read_open(gl_ptr_mem>>9); 00965 } 00966 #endif 00967 #endif 00968 } 00969 while (nb_sector != 0); 00970 00971 return OK; // Read done. 00972 }
Functions to read/write one sector (512btes) with ram buffer pointer.
Functions to read/write one sector (512btes) with ram buffer pointer.
NOTE:
*ram | pointer to ram buffer |
Definition at line 984 of file df.c.
References gl_ptr_mem, i, OK, Spi_read_data, and Spi_write_data.
00985 { 00986 U16 i; 00987 for(i=0;i<512;i++) 00988 { 00989 Spi_write_data(0); 00990 *ram=Spi_read_data(); 00991 ram++; 00992 } 00993 gl_ptr_mem += 512; // Update the memory pointer. 00994 return OK; 00995 }
This function write one DF sector from a ram buffer.
NOTE:
*ram | pointer to ram buffer |
Definition at line 1007 of file df.c.
References gl_ptr_mem, i, OK, Spi_ack_write, and Spi_write_data.
01008 { 01009 U16 i; 01010 for(i=0;i<512;i++) 01011 { 01012 Spi_write_data(*ram); 01013 ram++; 01014 } 01015 Spi_ack_write(); // Final step to clear the SPIF bit. 01016 gl_ptr_mem += 512; // Update the memory pointer. 01017 return OK; 01018 }