hla: add ability to configure read/write buffer size
[fw/openocd] / src / jtag / hla / hla_layout.c
1 /***************************************************************************
2  *   Copyright (C) 2011 by Mathias Kuester                                 *
3  *   Mathias Kuester <kesmtp@freenet.de>                                   *
4  *                                                                         *
5  *   Copyright (C) 2012 by Spencer Oliver                                  *
6  *   spen@spen-soft.co.uk                                                  *
7  *                                                                         *
8  *   This program is free software; you can redistribute it and/or modify  *
9  *   it under the terms of the GNU General Public License as published by  *
10  *   the Free Software Foundation; either version 2 of the License, or     *
11  *   (at your option) any later version.                                   *
12  *                                                                         *
13  *   This program is distributed in the hope that it will be useful,       *
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16  *   GNU General Public License for more details.                          *
17  *                                                                         *
18  *   You should have received a copy of the GNU General Public License     *
19  *   along with this program; if not, write to the                         *
20  *   Free Software Foundation, Inc.,                                       *
21  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
22  ***************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 /* project specific includes */
29 #include <jtag/interface.h>
30 #include <transport/transport.h>
31 #include <helper/time_support.h>
32
33 #include <jtag/hla/hla_layout.h>
34 #include <jtag/hla/hla_tcl.h>
35 #include <jtag/hla/hla_transport.h>
36 #include <jtag/hla/hla_interface.h>
37
38 static int hl_layout_open(struct hl_interface_s *adapter)
39 {
40         int res;
41
42         LOG_DEBUG("hl_layout_open");
43
44         adapter->fd = NULL;
45
46         res = adapter->layout->api->open(&adapter->param, &adapter->fd);
47
48         if (res != ERROR_OK) {
49                 LOG_DEBUG("failed");
50                 return res;
51         }
52
53         /* make sure adapter has set the buffer size */
54         if (!adapter->param.max_buffer) {
55                 LOG_ERROR("buffer size not set");
56                 return ERROR_FAIL;
57         }
58
59         return ERROR_OK;
60 }
61
62 static int hl_layout_close(struct hl_interface_s *adapter)
63 {
64         return ERROR_OK;
65 }
66
67 static const struct hl_layout hl_layouts[] = {
68         {
69          .name = "stlink",
70          .open = hl_layout_open,
71          .close = hl_layout_close,
72          .api = &stlink_usb_layout_api,
73          },
74         {.name = NULL, /* END OF TABLE */ },
75 };
76
77 /** */
78 const struct hl_layout *hl_layout_get_list(void)
79 {
80         return hl_layouts;
81 }
82
83 int hl_layout_init(struct hl_interface_s *adapter)
84 {
85         LOG_DEBUG("hl_layout_init");
86
87         if (adapter->layout == NULL) {
88                 LOG_ERROR("no layout specified");
89                 return ERROR_FAIL;
90         }
91         return ERROR_OK;
92 }