30
30
#include <stddef.h>
31
31
#include <stdbool.h>
32
32
33
- #define NP_USB_BUF_SIZE 64
33
+ #define NP_PACKET_BUF_SIZE 64
34
34
#define NP_MAX_PAGE_SIZE 0x0800
35
35
#define NP_WRITE_ACK_BYTES 1984
36
36
#define NP_NAND_TIMEOUT 0x1000000
@@ -169,14 +169,6 @@ typedef struct
169
169
typedef struct
170
170
{
171
171
uint8_t * rx_buf ;
172
- uint8_t rx_buf_size ;
173
- uint8_t * tx_buf ;
174
- uint8_t tx_buf_size ;
175
- } np_usb_t ;
176
-
177
- typedef struct
178
- {
179
- np_usb_t usb ;
180
172
uint32_t addr ;
181
173
uint32_t len ;
182
174
int addr_is_valid ;
@@ -196,19 +188,15 @@ typedef struct
196
188
197
189
static np_comm_cb_t * np_comm_cb ;
198
190
199
- uint8_t np_usb_send_buf [ NP_USB_BUF_SIZE ];
191
+ uint8_t np_packet_send_buf [ NP_PACKET_BUF_SIZE ];
200
192
201
- static void np_usb_init (np_usb_t * usb )
193
+ static void np_usb_init ()
202
194
{
203
195
Set_System ();
204
196
Set_USBClock ();
205
197
USB_Interrupts_Config ();
206
198
USB_Init ();
207
- while (!USB_IsDeviceConfigured ());
208
-
209
- usb -> tx_buf = (uint8_t * )np_usb_send_buf ;
210
- usb -> tx_buf_size = NP_USB_BUF_SIZE ;
211
- usb -> rx_buf_size = NP_USB_BUF_SIZE ;
199
+ while (!USB_IsDeviceConfigured ());
212
200
}
213
201
214
202
static int np_send_ok_status ()
@@ -254,7 +242,7 @@ static int np_cmd_nand_read_id(np_prog_t *prog)
254
242
255
243
DEBUG_PRINT ("Read ID command\r\n" );
256
244
257
- if (prog -> usb . tx_buf_size < resp_len )
245
+ if (NP_PACKET_BUF_SIZE < resp_len )
258
246
{
259
247
ERROR_PRINT ("Response size is more then TX buffer size\r\n" );
260
248
return np_send_error (NP_ERR_BUF_OVERFLOW );
@@ -301,7 +289,7 @@ static int np_nand_erase(uint32_t page, uint32_t addr)
301
289
static int np_cmd_nand_erase (np_prog_t * prog )
302
290
{
303
291
uint32_t addr , page , pages_in_block ;
304
- np_erase_cmd_t * erase_cmd = (np_erase_cmd_t * )prog -> usb . rx_buf ;
292
+ np_erase_cmd_t * erase_cmd = (np_erase_cmd_t * )prog -> rx_buf ;
305
293
306
294
led_wr_set (true);
307
295
@@ -353,7 +341,7 @@ static int np_send_write_ack(uint32_t bytes_ack)
353
341
static int np_cmd_nand_write_start (np_prog_t * prog )
354
342
{
355
343
np_write_start_cmd_t * write_start_cmd =
356
- (np_write_start_cmd_t * )prog -> usb . rx_buf ;
344
+ (np_write_start_cmd_t * )prog -> rx_buf ;
357
345
358
346
DEBUG_PRINT ("Write at 0x%lx command\r\n" , write_start_cmd -> addr );
359
347
@@ -436,10 +424,10 @@ static int np_cmd_nand_write_data(np_prog_t *prog)
436
424
{
437
425
uint32_t write_len , bytes_left ;
438
426
np_write_data_cmd_t * write_data_cmd =
439
- (np_write_data_cmd_t * )prog -> usb . rx_buf ;
427
+ (np_write_data_cmd_t * )prog -> rx_buf ;
440
428
441
429
if (write_data_cmd -> len + offsetof(np_write_data_cmd_t , data ) >
442
- prog -> usb . rx_buf_size )
430
+ NP_PACKET_BUF_SIZE )
443
431
{
444
432
ERROR_PRINT ("Data size is wrong %d\r\n" , write_data_cmd -> len );
445
433
return np_send_error (NP_ERR_CMD_DATA_SIZE );
@@ -514,7 +502,7 @@ static int np_cmd_nand_write_end(np_prog_t *prog)
514
502
515
503
static int np_cmd_nand_write (np_prog_t * prog )
516
504
{
517
- np_cmd_t * cmd = (np_cmd_t * )prog -> usb . rx_buf ;
505
+ np_cmd_t * cmd = (np_cmd_t * )prog -> rx_buf ;
518
506
int ret = 0 ;
519
507
520
508
switch (cmd -> code )
@@ -570,9 +558,9 @@ static int np_cmd_nand_read(np_prog_t *prog)
570
558
static np_page_t page ;
571
559
uint32_t write_len ;
572
560
uint32_t resp_header_size = offsetof(np_resp_t , data );
573
- uint32_t tx_data_len = prog -> usb . tx_buf_size - resp_header_size ;
574
- np_read_cmd_t * read_cmd = (np_read_cmd_t * )prog -> usb . rx_buf ;
575
- np_resp_t * resp = (np_resp_t * )prog -> usb . tx_buf ;
561
+ uint32_t tx_data_len = sizeof ( np_packet_send_buf ) - resp_header_size ;
562
+ np_read_cmd_t * read_cmd = (np_read_cmd_t * )prog -> rx_buf ;
563
+ np_resp_t * resp = (np_resp_t * )np_packet_send_buf ;
576
564
577
565
led_rd_set (true);
578
566
@@ -612,7 +600,7 @@ static int np_cmd_nand_read(np_prog_t *prog)
612
600
while (!np_comm_cb -> send_ready ());
613
601
614
602
resp -> info = write_len ;
615
- if (np_comm_cb -> send (prog -> usb . tx_buf ,
603
+ if (np_comm_cb -> send (np_packet_send_buf ,
616
604
resp_header_size + write_len ))
617
605
{
618
606
return -1 ;
@@ -643,7 +631,7 @@ static int np_cmd_nand_read(np_prog_t *prog)
643
631
644
632
static int np_cmd_nand_select (np_prog_t * prog )
645
633
{
646
- np_select_cmd_t * select_cmd = (np_select_cmd_t * )prog -> usb . rx_buf ;
634
+ np_select_cmd_t * select_cmd = (np_select_cmd_t * )prog -> rx_buf ;
647
635
648
636
DEBUG_PRINT ("Chip select ID %lu command\r\n" , select_cmd -> chip_num );
649
637
@@ -751,7 +739,7 @@ static bool np_cmd_is_valid(int cmd)
751
739
752
740
static int np_cmd_handler (np_prog_t * prog )
753
741
{
754
- np_cmd_t * cmd = (np_cmd_t * )prog -> usb . rx_buf ;
742
+ np_cmd_t * cmd = (np_cmd_t * )prog -> rx_buf ;
755
743
756
744
if (!prog -> chip_info && cmd -> code != NP_CMD_NAND_SELECT )
757
745
{
@@ -775,9 +763,9 @@ static void np_packet_handler(np_prog_t *prog)
775
763
{
776
764
do
777
765
{
778
- np_comm_cb -> peek (& prog -> usb . rx_buf );
766
+ np_comm_cb -> peek (& prog -> rx_buf );
779
767
780
- if (!prog -> usb . rx_buf )
768
+ if (!prog -> rx_buf )
781
769
break ;
782
770
783
771
np_cmd_handler (prog );
@@ -825,7 +813,7 @@ int main()
825
813
printf ("done.\r\n" );
826
814
827
815
printf ("USB init..." );
828
- np_usb_init (& prog . usb );
816
+ np_usb_init ();
829
817
printf ("done.\r\n" );
830
818
831
819
printf ("CDC init..." );
0 commit comments