📄 bulk_only.lst
字号:
249 1 nCurrentBlock = Logical_Block_Address = Logical_Block_Address / 0x20 + Root_Cluster; //由逻辑地址块取簇
250 1
251 1
252 1 nBufCount=0; //传送数据当前位置
253 1
254 1 ReadPage(Logical_Block_Address, nCurrentPage, Page_Buf);//读出当前簇的512个字节数据
255 1
256 1 Transfer_Length--; //传输扇区数减1
257 1 nCurrentPage++; //指向下一扇区
258 1
259 1 bulk_state = BULK_DATA_TRANS; //置传输状态为传数状态
260 1 pCurrentBuf = Page_Buf; //将当前数据缓存指针传给送数指数
261 1
262 1 WriteEpBulk(1, 64, pCurrentBuf);//传送第一个64字节
263 1 }
264
265 void TransDataGoOn()
266 {
267 1 // int i;
268 1 if (nBufCount < 0x1c0)
269 1 { //如果一个扇区数据未传完
270 2 nBufCount += 0x40; //指向下一个64字节
271 2 WriteEpBulk(1, 64, pCurrentBuf + nBufCount);//将当前64个字节传输出去
272 2 }
273 1 else if(Transfer_Length > 0)
274 1 { //如果总扇区未传完,
275 2
276 2 if(nCurrentPage == 0x20)
277 2 { //扇区数满32时,指向下一个Block
278 3 nCurrentBlock++;
279 3 nCurrentPage = 0; //扇区数重新指向0
280 3 }
281 2
282 2 ReadPage(nCurrentBlock, nCurrentPage, Page_Buf); //读新的一个扇区
283 2 nCurrentPage++; //指向下一扇区
284 2 Transfer_Length--;
285 2
286 2 nBufCount =0; //重新计另一扁区
287 2 pCurrentBuf = Page_Buf;
288 2 bulk_state = BULK_DATA_TRANS;
289 2 WriteEpBulk(1, 64, pCurrentBuf); //写第一次
290 2 }
291 1
292 1 else
293 1 {
294 2 bulk_state = BULK_DATA_END; //数据传输结束,置传输状态
295 2
296 2 nBufCount = 0; //指针复位
297 2 TransmitCSW();
298 2 }
299 1 }
300
301 void UFI_Write10()
302 {
C51 COMPILER V7.07 BULK_ONLY 11/20/2006 17:50:24 PAGE 6
303 1 int i;
304 1
305 1 for (i=0; i<4; i++)
306 1 {
307 2 Logical_Block_Address = (Logical_Block_Address << 8) + bulk_CBW.CBWCB[2 + i]; //要传的数据的起始簇
308 2 }
309 1
310 1 Transfer_Length = bulk_CBW.CBWCB[7] * 256 + bulk_CBW.CBWCB[8]; //要传的扇区数
311 1
312 1 nBeginPage = nCurrentPage = Logical_Block_Address % 0x20; //由逻辑地址块取真实扇区
313 1 nCurrentBlock = Logical_Block_Address = Logical_Block_Address/0x20 + Root_Cluster; //由逻辑地址块取簇
314 1
315 1
316 1 bulk_state = BULK_DATA_RECIEVE;//置状态为数据接收状态
317 1 //如果目标Block小于6,或是起始扇区不为零,则擦除1000Block作为缓存Erase The Buf
318 1 if ((nCurrentBlock<6)||nBeginPage)
319 1 {
320 2 Erase_Cluster(1000);//Erase The Buf
321 2 }
322 1 else
323 1 {
324 2 Erase_Cluster(nCurrentBlock);//否则直接擦除目标Blcok,准备存入数据Erase The Block to be write
325 2 }
326 1 }
327
328
329 void Trans_Data2PC()
330 {
331 1 int i;
332 1 // printuf("E:%x\n",nBufCount/0x40);
333 1 // memcpy(Page_Buf+nBufCount,Bulk_Out_Buf,64);//将Bulk_Out端点中的64bytes的数据移入512的Page_buf中共8次
334 1 // dDataResiduce -=0x40;
335 1 // nBufCount+=0x40;
336 1 nBufCount = 512;
337 1 BulkPoint = Page_Buf;//Bulk指针退回到开始
338 1 // if((Transfer_Length==1) &&(dDataResiduce==0x40)) WriteEpBulk(1, sizeof(bulk_CSW), bulk_CSW);
339 1
340 1 //如果满512字节时,
341 1 if (((nBufCount % 0x200 == 0) && nBufCount >= 0x200) || (nBufCount == 0x00))
342 1 {
343 2 //如果写前6个Block或是超始Page不为0时,则需要缓存,先将数据写入第1000Block中
344 2 if ((nCurrentBlock < 6) || nBeginPage)
345 2 {
346 3 WritePage(1000, nCurrentPage, Page_Buf);
347 3 }
348 2 else
349 2 {
350 3 WritePage(nCurrentBlock, nCurrentPage, Page_Buf);//否则,直接写入目标Block
351 3 }
352 2
353 2
354 2 nCurrentPage++; //指向下一扇区
355 2 Transfer_Length--; //已传输扇区减1
356 2 nBufCount = 0; //准备下一个扇区接收
357 2
358 2 }
359 1
360 1 // if(((Transfer_Length%0x20)==0) && (Transfer_Length>=0x20)&&(nCurrentPage == 0x20)){
361 1 if ((Transfer_Length > 0) && (nCurrentPage == 0x20))
362 1 {
363 2 nBufCount = 0;
364 2 // Write2Flash(nCurrentBlock,nBeginPage,nCurrentPage-1,Flash_One_Page);
C51 COMPILER V7.07 BULK_ONLY 11/20/2006 17:50:24 PAGE 7
365 2 if ((nCurrentBlock < 6) || nBeginPage)
366 2 {//如果采用了缓存,则需要保留部分数据
367 3 for (i=0; i<nBeginPage; i++)
368 3 {
369 4 ReadPage(nCurrentBlock, i, Page_Buf);//将起始Block以前的数据移入缓存中
370 4 WritePage(1000, i, Page_Buf);
371 4 }
372 3
373 3 Erase_Cluster(nCurrentBlock);//擦除目标Block
374 3 for (i=0; i<32; i++)
375 3 {//将缓存中的数据存入目标Block中
376 4 ReadPage(1000, i, Page_Buf);
377 4 WritePage(nCurrentBlock, i, Page_Buf);
378 4 }
379 3 }
380 2
381 2 nCurrentBlock++;//指向下一个Block
382 2 nCurrentPage = 0;
383 2 nBeginPage = 0;
384 2
385 2 // Erase_Cluster(1000);
386 2 //根据下一个Block的位置,决定是否缓存,并擦除目标位置
387 2 if ((nCurrentBlock < 6) || nBeginPage)
388 2 {
389 3 Erase_Cluster(1000);//Write One 32k Buf,Erase The Buf for next transaction
390 3 }
391 2 else
392 2 {
393 3 Erase_Cluster(nCurrentBlock);//Erase The Block to be write
394 3 }
395 2
396 2 // Uart_Printf("%x\n",Transfer_Length);
397 2 }
398 1 if (Transfer_Length == 0)
399 1 {//数据传送完毕后,将当前缓存中的所有内容写入Flash
400 2 nBufCount = 0;
401 2 // Write2Flash(nCurrentBlock,nBeginPage,nCurrentPage-1,Flash_One_Page);
402 2 if ((nCurrentBlock < 6) || nBeginPage)
403 2 {
404 3 for (i=0; i<nBeginPage; i++)
405 3 {
406 4 ReadPage(nCurrentBlock, i, Page_Buf);
407 4 WritePage(1000, i, Page_Buf);
408 4 }
409 3 for (i=nCurrentPage; i<32; i++)
410 3 {
411 4 ReadPage(nCurrentBlock, i, Page_Buf);
412 4 WritePage(1000, i, Page_Buf);
413 4 }
414 3
415 3 Erase_Cluster(nCurrentBlock);
416 3
417 3 for (i=0; i<32; i++)
418 3 {
419 4 ReadPage(1000, i, Page_Buf);
420 4 WritePage(nCurrentBlock, i, Page_Buf);
421 4 }
422 3 }
423 2
424 2 TransmitCSW();//向主机发送CSW
425 2 }
426 1 }
C51 COMPILER V7.07 BULK_ONLY 11/20/2006 17:50:24 PAGE 8
427
428
429
430 void UFI_Medium_Removal()
431 {
432 1 TransmitCSW(); //直接返回CSW
433 1 }
434
435 void UFI_Test_Unit_Ready()
436 {
437 1 TransmitCSW(); //Flash Disk are always ready!
438 1 }
439
440
441 void TransmitCSW()
442 {
443 1 unsigned char i;
444 1 // WriteEpBulk(1, sizeof(bulk_CSW), bulk_CSW); //向端点发送CSW
445 1 // bulk_state = BULK_CSW_END; //置传输状态。
446 1
447 1 UEPNUM = 1;//指向相应端点
448 1 UEPSTAX |= DIR;//设置方向为写Set for status of a Control In transaction
449 1 for (i=0; i<13; i++)
450 1 {
451 2 UEPDATX = bulk_CSW[i];//将数据写入端点
452 2 }
453 1 UEPSTAX |= TXRDY;//发送数据Sending the data,this action will switch between bank0 and bank1
454 1
455 1 bulk_state = BULK_CSW_END; //置传输状态。
456 1 }
457
458
459
460 void TransRequestGoOn()
461 {
462 1 if (dDataResiduce > 0x40)
463 1 {//如果要传送的数据大于64,则置传输状态为请求数据传送状态
464 2 dDataResiduce -= 0x40;
465 2 bulk_state = BULK_REQEST_TRANS;
466 2 nBufCount += 0x40;
467 2 WriteEpBulk(1, 64, pCurrentBuf + nBufCount);
468 2 }
469 1 else
470 1 {//如果小于64,则置数据传输完毕状态
471 2 bulk_state = BULK_DATA_END;
472 2 nBufCount += 0x40;
473 2 WriteEpBulk(1, dDataResiduce, pCurrentBuf + nBufCount);
474 2 nBufCount = 0; //prepare for nexe into
475 2 }
476 1 }
477
478
479
480 void UFI_Verify()
481 {
482 1 TransmitCSW();//直接返回CSW
483 1 }
484
485
486 void UFI_Reserved()
487 {
488 1 printuf("\nUFI Function 0x%x doesn't Defined!", bulk_CBW.CBWCB[0]);
C51 COMPILER V7.07 BULK_ONLY 11/20/2006 17:50:24 PAGE 9
489 1 TransmitCSW();
490 1
491 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2503 ----
CONSTANT SIZE = 138 ----
XDATA SIZE = 588 6
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -