MCPcopy Create free account
hub / github.com/davidgiven/fluxengine / cmd_write

Function cmd_write

FluxEngine.cydsn/main.c:557–694  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

555}
556
557static void cmd_write(struct write_frame* f)
558{
559 print("cmd_write");
560
561 if (f->bytes_to_write % FRAME_SIZE)
562 {
563 send_error(F_ERROR_INVALID_VALUE);
564 return;
565 }
566
567 seek_to(current_track);
568 SIDE_REG_Write(f->side);
569 STEP_REG_Write(f->side); /* for drives which multiplex SIDE and DIR */
570 SEQUENCER_CONTROL_Write(1); /* put the sequencer into reset */
571 {
572 uint8_t i = CyEnterCriticalSection();
573 REPLAY_FIFO_SET_LEVEL_MID;
574 REPLAY_FIFO_CLEAR;
575 REPLAY_FIFO_SINGLE_BUFFER_UNSET;
576 CyExitCriticalSection(i);
577 }
578
579 init_replay_dma();
580 bool writing = false; /* to the disk */
581 int packets = f->bytes_to_write / FRAME_SIZE;
582 bool finished = (packets == 0);
583 int count_written = 0;
584 int count_read = 0;
585 dma_writing_to_td = 0;
586 dma_reading_from_td = -1;
587 dma_underrun = false;
588
589 int old_reading_from_td = -1;
590 for (;;)
591 {
592 //CyWdtClear();
593
594 /* Read data from USB into the buffers. */
595
596 if (NEXT_BUFFER(dma_writing_to_td) != dma_reading_from_td)
597 {
598 if (writing && (dma_underrun || index_irq))
599 goto abort;
600
601 uint8_t* buffer = dma_buffer[dma_writing_to_td];
602 if (finished)
603 {
604 /* There's no more data to read, so fake some. */
605
606 memset(buffer, 0x3f, BUFFER_SIZE);
607 }
608 else
609 {
610 (void) usb_read(FLUXENGINE_DATA_OUT_EP_NUM, buffer);
611 count_read++;
612
613 if (count_read == packets)
614 finished = true;

Callers 1

handle_commandFunction · 0.85

Calls 7

printFunction · 0.85
send_errorFunction · 0.85
seek_toFunction · 0.85
init_replay_dmaFunction · 0.85
usb_readFunction · 0.85
deinit_dmaFunction · 0.85
send_replyFunction · 0.85

Tested by

no test coverage detected