14 #ifndef OPENOCD_HELPER_REPLACEMENTS_H
15 #define OPENOCD_HELPER_REPLACEMENTS_H
23 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
26 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
41 #ifndef HAVE_SYS_TIME_H
43 #ifndef _TIMEVAL_DEFINED
44 #define _TIMEVAL_DEFINED
58 #ifndef IN_REPLACEMENTS_C
91 char *
strndup(
const char *s,
size_t n);
95 size_t strnlen(
const char *s,
size_t maxlen);
100 static inline unsigned int usleep(
unsigned int usecs)
106 #error no usleep defined for your platform
117 #define UNIX_PATH_LEN 108
120 char sun_path[UNIX_PATH_LEN];
126 #define ETIMEDOUT WSAETIMEDOUT
130 #if defined(__x86_64__) || defined(__i386__)
131 static inline unsigned char inb(
unsigned short int port)
134 __asm__ __volatile__ (
"inb %w1,%0" :
"=a" (_v) :
"Nd" (port));
138 static inline void outb(
unsigned char value,
unsigned short int port)
140 __asm__ __volatile__ (
"outb %b0,%w1" : :
"a" (value),
"Nd" (port));
145 #define ffs __builtin_ffs
149 int win_select(
int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds,
struct timeval *tv);
156 #define OCD_FD_SET(fd, set) FD_SET((SOCKET)(fd), (set))
157 #define OCD_FD_CLR(fd, set) FD_CLR((SOCKET)(fd), (set))
158 #define OCD_FD_ISSET(fd, set) FD_ISSET((SOCKET)(fd), (set))
160 #define OCD_FD_SET(fd, set) FD_SET((fd), (set))
161 #define OCD_FD_CLR(fd, set) FD_CLR((fd), (set))
162 #define OCD_FD_ISSET(fd, set) FD_ISSET((fd), (set))
187 return closesocket(sock);
196 unsigned long nonblock = 0;
197 ioctlsocket(fd, FIONBIO, &nonblock);
199 int oldopts = fcntl(fd, F_GETFL, 0);
200 fcntl(fd, F_SETFL, oldopts & ~O_NONBLOCK);
207 unsigned long nonblock = 1;
208 ioctlsocket(fd, FIONBIO, &nonblock);
210 int oldopts = fcntl(fd, F_GETFL, 0);
211 fcntl(fd, F_SETFL, oldopts | O_NONBLOCK);
222 return win_select(max_fd, rfds, wfds, efds, tv);
224 return select(max_fd, rfds, wfds, efds, tv);
232 return setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (
const char *)&
timeout,
236 tv.
tv_sec = timeout_msec / 1000;
237 tv.
tv_usec = (timeout_msec % 1000) * 1000;
238 return setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (
const char *)&tv,
sizeof(tv));
246 return setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (
const char *)&
timeout,
250 tv.
tv_sec = timeout_msec / 1000;
251 tv.
tv_usec = (timeout_msec % 1000) * 1000;
252 return setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (
const char *)&tv,
sizeof(tv));
284 #define ELFMAG "\177ELF"
292 #define ELFDATA2LSB 1
293 #define ELFDATA2MSB 2
310 #define SHF_WRITE BIT(0)
311 #define SHF_ALLOC BIT(1)
312 #define SHF_EXECINSTR BIT(2)
uint64_t buffer
Pointer to data buffer to send over SPI.
uint32_t size
Size of dw_spi_transaction::buffer.
static int socket_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
static void socket_block(int fd)
static int read_socket(int handle, void *buffer, unsigned int count)
static int socket_recv_timeout(int fd, unsigned long timeout_msec)
static int close_socket(int sock)
static int socket_send_timeout(int fd, unsigned long timeout_msec)
char * strndup(const char *s, size_t n)
static int write_socket(int handle, const void *buffer, unsigned int count)
void * clear_malloc(size_t size)
static void socket_nonblock(int fd)
void * fill_malloc(size_t size)
size_t strnlen(const char *s, size_t maxlen)