2 * Serial Wire Debug Open Library.
3 * External Handlers Definition File.
5 * Copyright (C) 2010-2013, Tomasz Boleslaw CEDRO (http://www.tomek.cedro.info)
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * 3. Neither the name of the Tomasz Boleslaw CEDRO nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.*
31 * Written by Tomasz Boleslaw CEDRO <cederom@tlen.pl>, 2010-2013;
35 /** \file libswd_externs.c Template for driver bridge between libswd and your application. */
40 int libswd_drv_mosi_8(libswd_ctx_t
*libswdctx
, libswd_cmd_t
*cmd
, char *data
, int bits
, int nLSBfirst
){
41 if (data
==NULL
) return LIBSWD_ERROR_NULLPOINTER
;
42 if (bits
<0 && bits
>8) return LIBSWD_ERROR_PARAM
;
43 if (nLSBfirst
!=0 && nLSBfirst
!=1) return LIBSWD_ERROR_PARAM
;
45 // Your code goes here...
51 int libswd_drv_mosi_32(libswd_ctx_t
*libswdctx
, libswd_cmd_t
*cmd
, int *data
, int bits
, int nLSBfirst
){
52 if (data
==NULL
) return LIBSWD_ERROR_NULLPOINTER
;
53 if (bits
<0 && bits
>8) return LIBSWD_ERROR_PARAM
;
54 if (nLSBfirst
!=0 && nLSBfirst
!=1) return LIBSWD_ERROR_PARAM
;
56 // Your code goes here...
61 int libswd_drv_miso_8(libswd_ctx_t
*libswdctx
, libswd_cmd_t
*cmd
, char *data
, int bits
, int nLSBfirst
){
62 if (data
==NULL
) return LIBSWD_ERROR_NULLPOINTER
;
63 if (bits
<0 && bits
>8) return LIBSWD_ERROR_PARAM
;
64 if (nLSBfirst
!=0 && nLSBfirst
!=1) return LIBSWD_ERROR_PARAM
;
66 // Your code goes here...
71 int libswd_drv_miso_32(libswd_ctx_t
*libswdctx
, libswd_cmd_t
*cmd
, int *data
, int bits
, int nLSBfirst
){
72 if (data
==NULL
) return LIBSWD_ERROR_NULLPOINTER
;
73 if (bits
<0 && bits
>8) return LIBSWD_ERROR_PARAM
;
74 if (nLSBfirst
!=0 && nLSBfirst
!=1) return LIBSWD_ERROR_PARAM
;
76 // Your code goes here...
82 /* This function sets interface buffers to MOSI direction.
83 * Master Output Slave Input - SWD Write operation.
84 * bits specify how many clock cycles must be used. */
85 int libswd_drv_mosi_trn(libswd_ctx_t
*libswdctx
, int bits
){
86 if (bits
<LIBSWD_TURNROUND_MIN_VAL
&& bits
>LIBSWD_TURNROUND_MAX_VAL
)
87 return LIBSWD_ERROR_TURNAROUND
;
89 // Your code goes here...
94 int libswd_drv_miso_trn(libswd_ctx_t
*libswdctx
, int bits
){
95 if (bits
<LIBSWD_TURNROUND_MIN_VAL
&& bits
>LIBSWD_TURNROUND_MAX_VAL
)
96 return LIBSWD_ERROR_TURNAROUND
;
98 // Your code goes here...
104 /** Set debug level according to caller's application settings.
105 * \params *libswdctx swd context to work on.
106 * \params loglevel caller's application log level to be converted.
107 * \return LIBSWD_OK on success, of error code on failure.
109 int libswd_log_level_inherit(libswd_ctx_t
*libswdctx
, int loglevel
){
110 if (libswdctx
==NULL
){
111 // log(LOG_LEVEL_DEBUG, "libswd_log_level_inherit(): SWD Context not (yet) initialized...\n");
115 libswd_loglevel_t new_swdlevel
;
117 // Your code goes here...
119 new_swdlevel
=LIBSWD_LOGLEVEL_NORMAL
;
122 int res
=libswd_log_level_set(libswdctx
, new_swdlevel
);
124 // Your error routine goes here...
125 // return URJ_ERROR_SYNTAX;
126 } else return LIBSWD_OK
;
129 /** By default we want to use internal logging mechanisms.
130 * It is possible however to use target program mechanisms to log messages.
131 * In order to correctly parse variable number of arguments we need to use
132 * dedicated libswd_log_internal_va() function...
134 int libswd_log(libswd_ctx_t
*libswdctx
, libswd_loglevel_t loglevel
, char *msg
, ...){
138 retval
=libswd_log_internal_va(libswdctx
, loglevel
, msg
, ap
);