@@ -19,9 +19,7 @@ static int8_t transfer_fds_byte(uint8_t *output, uint8_t input, uint8_t *end_of_
1919 // waiting for interrupt
2020 // timeout 5 secs
2121 if (HAL_GetTick () - start_time >= 5000 )
22- {
2322 return - COMMAND_FDS_TIMEOUT ;
24- }
2523 }
2624 if (output )
2725 * output = PRG (FDS_DATA_READ );
@@ -37,9 +35,7 @@ static int8_t transfer_fds_byte(uint8_t *output, uint8_t input, uint8_t *end_of_
3735 // is interrupt flag cleared?
3836 // timeout 5 secs
3937 if (HAL_GetTick () - start_time >= 5000 )
40- {
4138 return - COMMAND_FDS_TIMEOUT ;
42- }
4339 }
4440 return 1 ;
4541}
@@ -93,23 +89,28 @@ static int8_t read_fds_block_send(uint16_t length, uint8_t send, uint16_t *file_
9389 // send data over USB if need
9490 if (send )
9591 {
96- if (!comm_send_byte (data ))
97- return 0 ;
92+ if (!comm_send_byte (data )) return 0 ;
9893 }
9994 }
10095 r = transfer_fds_byte (0 , 0 , & end_of_head );
10196 if (r <= 0 )
10297 {
103- if (!comm_send_byte (0 )) return 0 ;
104- if (!comm_send_byte (0 )) return 0 ;
98+ if (send )
99+ {
100+ if (!comm_send_byte (0 )) return 0 ;
101+ if (!comm_send_byte (0 )) return 0 ;
102+ }
105103 return r ;
106104 }
107105 PRG (FDS_CONTROL ) = FDS_CONTROL_READ | FDS_CONTROL_MOTOR_ON | FDS_CONTROL_TRANSFER_ON | FDS_CONTROL_IRQ_ON | FDS_CONTROL_CRC ; // enable CRC control
108106 r = transfer_fds_byte (0 , 0 , & end_of_head );
109107 if (r <= 0 )
110108 {
111- if (!comm_send_byte (0 )) return 0 ;
112- if (!comm_send_byte (0 )) return 0 ;
109+ if (send )
110+ {
111+ if (!comm_send_byte (0 )) return 0 ;
112+ if (!comm_send_byte (0 )) return 0 ;
113+ }
113114 return r ;
114115 }
115116 disk_status = PRG (FDS_DISK_STATUS );
@@ -152,13 +153,9 @@ static int8_t write_fds_block(uint8_t *data, uint16_t length, uint32_t gap_delay
152153 if (r <= 0 ) return r ;
153154 while (length )
154155 {
155- if (end_of_head )
156- {
157- PRG (FDS_CONTROL ) = FDS_CONTROL_READ | FDS_CONTROL_MOTOR_OFF ; // reset, stop
158- return - COMMAND_FDS_END_OF_HEAD ;
159- }
156+ if (end_of_head ) return - COMMAND_FDS_END_OF_HEAD ;
160157 r = transfer_fds_byte (0 , * data , & end_of_head );
161- return r ;
158+ if ( r <= 0 ) return r ;
162159 data ++ ;
163160 length -- ;
164161 pos ++ ;
@@ -171,11 +168,7 @@ static int8_t write_fds_block(uint8_t *data, uint16_t length, uint32_t gap_delay
171168 }
172169 r = transfer_fds_byte (0 , 0xFF , & end_of_head );
173170 if (r <= 0 ) return r ;
174- if (end_of_head )
175- {
176- PRG (FDS_CONTROL ) = FDS_CONTROL_READ | FDS_CONTROL_MOTOR_OFF ; // reset, stop
177- return - COMMAND_FDS_END_OF_HEAD ;
178- }
171+ if (end_of_head ) return - COMMAND_FDS_END_OF_HEAD ;
179172 PRG (FDS_CONTROL ) = FDS_CONTROL_WRITE | FDS_CONTROL_MOTOR_ON | FDS_CONTROL_TRANSFER_ON | FDS_CONTROL_IRQ_ON | FDS_CONTROL_CRC ; // enable CRC control
180173 delay_clock (FDS_WRITE_CRC_DELAY );
181174 start_time = HAL_GetTick ();
0 commit comments