]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-rocon.git/blob - host/app/usb_sendhex/0001-Implement-USB_VENDOR_CALL-feature-in-usb_sendhex.patch
Multiple patches
[fpga/lx-cpu1/lx-rocon.git] / host / app / usb_sendhex / 0001-Implement-USB_VENDOR_CALL-feature-in-usb_sendhex.patch
1 From 225b899f1e904128ed4794041dc625751c08fc3f Mon Sep 17 00:00:00 2001
2 From: Martin Meloun <meloumar@cmp.felk.cvut.cz>
3 Date: Mon, 26 Aug 2013 11:23:24 +0200
4 Subject: [PATCH] Implement USB_VENDOR_CALL feature in usb_sendhex
5
6 USB_VENDOR_CALL feature sends a command with a argument
7 (both 16bit) and expects 16bit return value. It is used
8 for calling functions on the target. If mixed with other
9 arguments, it is executed right before GOTO.
10
11 Signed-off-by: Martin Meloun <meloumar@cmp.felk.cvut.cz>
12 ---
13  app-host/usb_sendhex/usb_sendhex.c | 57 ++++++++++++++++++++++++++++++++++----
14  1 file changed, 52 insertions(+), 5 deletions(-)
15
16 diff --git a/app-host/usb_sendhex/usb_sendhex.c b/app-host/usb_sendhex/usb_sendhex.c
17 index 16f4907..c297822 100644
18 --- a/app-host/usb_sendhex/usb_sendhex.c
19 +++ b/app-host/usb_sendhex/usb_sendhex.c
20 @@ -3,7 +3,7 @@
21   *
22   * Based on 'ul_sendhex'
23   *
24 - * Version 1.0 - 2004/02/03
25 + * Version 1.1 - 2013/08/26
26   */
27  #define _GNU_SOURCE
28  
29 @@ -52,6 +52,9 @@ unsigned long mem_length = 0xff00;
30  unsigned long max_block  = 1024;
31  unsigned long go_addr    = 3;
32  int go_flg     = 0;
33 +int call       = 0xFFFF;
34 +int arg        = 0;
35 +int call_flg   = 0;
36  int reset_flg  = 0;
37  int prt_modules = 0;
38  int debugk     = 0;
39 @@ -579,6 +582,33 @@ int download_file(char *file_name, char *format)
40    return ret;
41  }
42  
43 +int send_cmd_call(int cmd, int val)
44 +{
45 +  int ret, resp_val;
46 +  usb_dev_handle *hdev;
47 +  char resp[10];
48 +
49 +  hdev = usb_open_device(vid, pid);
50 +
51 +  if (!hdev)
52 +  {
53 +    perror("send_cmd_call : USB open failed");
54 +    return -1;
55 +  }
56 +
57 +  ret = usb_control_msg(hdev, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
58 +                        USB_VENDOR_CALL, val & 0xffff, cmd & 0xffff, resp, sizeof(resp), USB_TIMEOUT);
59 +  resp_val = usb_swab16(*((uint16_t *)(resp)));
60 +
61 +  if (ret < 0)
62 +    printf("Call %4X (%4X) ERROR %d: %s\n", (uint16_t)(cmd & 0xffff), (uint16_t)(val & 0xffff), ret, usb_strerror());
63 +  else
64 +    printf("Call %4X (%4X): %4X\n", (uint16_t)(cmd & 0xffff), (uint16_t)(val & 0xffff), resp_val);
65 +
66 +  usb_close_device(hdev);
67 +  return ret;
68 +}
69 +
70  int send_cmd_go(unsigned long addr)
71  {
72    int ret;
73 @@ -893,6 +923,8 @@ usage(void)
74    printf("  -s, --start <addr>       start address of transfer\n");
75    printf("  -l, --length <num>       length of upload block\n");
76    printf("  -b, --block <num>        maximal block length\n");
77 +  printf("  -c, --call <num>         vendor custom call\n");
78 +  printf("  -a, --argument <num>     argument for vendor custom call\n");
79    printf("  -g, --go <addr>          start program from address\n");
80    printf("  -r, --reset              reset before download\n");
81    printf("  -E, --mass-erase <mode>  full device erase\n");
82 @@ -917,6 +949,8 @@ int main(int argc, char *argv[])
83      { "start", 1, 0, 's' },
84      { "length", 1, 0, 'l' },
85      { "block", 1, 0, 'b' },
86 +    { "call", 1, 0, 'c' },
87 +    { "argument", 1, 0, 'a' },
88      { "go",    1, 0, 'g' },
89      { "reset", 0, 0, 'r' },
90      { "mass-erase", 1, 0, 'E' },
91 @@ -934,9 +968,9 @@ int main(int argc, char *argv[])
92    int opt;
93  
94  #ifndef HAS_GETOPT_LONG
95 -  while ((opt = getopt(argc, argv, "d:i:t:s:l:b:g:rE:euwf:pvVhD:")) != EOF)
96 +  while ((opt = getopt(argc, argv, "d:i:t:s:l:b:c:a::g:rE:euwf:pvVhD:")) != EOF)
97  #else
98 -  while ((opt = getopt_long(argc, argv, "d:i:t:s:l:b:g:rE:euwf:pvVh", &long_opts[0], NULL)) != EOF)
99 +  while ((opt = getopt_long(argc, argv, "d:i:t:s:l:b:c:a:g:rE:euwf:pvVh", &long_opts[0], NULL)) != EOF)
100  #endif
101  
102      switch (opt)
103 @@ -979,6 +1013,13 @@ int main(int argc, char *argv[])
104        case 'b':
105          max_block = strtoul(optarg, NULL, 0);
106          break;
107 +      case 'c':
108 +        call = strtoul(optarg, NULL, 0);
109 +        call_flg = 1;
110 +        break;
111 +      case 'a':
112 +        arg = strtoul(optarg, NULL, 0);
113 +        break;
114        case 'g':
115          go_addr = strtoul(optarg, NULL, 0);
116          go_flg = 1;
117 @@ -1013,7 +1054,7 @@ int main(int argc, char *argv[])
118          verbose = 1;
119          break;
120        case 'V':
121 -        fputs("USB sendhex v.1.0\n", stdout);
122 +        fputs("USB sendhex v.1.1\n", stdout);
123          exit(0);
124        case 'h':
125        default:
126 @@ -1021,7 +1062,7 @@ int main(int argc, char *argv[])
127          exit(opt == 'h' ? 0 : 1);
128      }
129  
130 -  if ((optind >= argc) && !go_flg && !prt_modules && !debugk_flg
131 +  if ((optind >= argc) && !go_flg && !call_flg && !prt_modules && !debugk_flg
132        && !masserase_flg && !regerase_flg && !reset_flg)
133    {
134      usage();
135 @@ -1062,6 +1103,12 @@ int main(int argc, char *argv[])
136        exit(2);
137    }
138  
139 +  if (call_flg)
140 +  {
141 +    if (send_cmd_call(call, arg) < 0)
142 +      exit(2);
143 +  }
144 +
145    if (go_flg)
146    {
147      if (send_cmd_go(go_addr) < 0)
148 -- 
149 1.8.4.5
150