14 #ifndef OPENOCD_HELPER_REPLACEMENTS_H
15 #define OPENOCD_HELPER_REPLACEMENTS_H
22 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
25 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
40 #ifndef HAVE_SYS_TIME_H
42 #ifndef _TIMEVAL_DEFINED
43 #define _TIMEVAL_DEFINED
57 #ifndef IN_REPLACEMENTS_C
90 char *
strndup(
const char *s,
size_t n);
94 size_t strnlen(
const char *s,
size_t maxlen);
99 static inline unsigned int usleep(
unsigned int usecs)
105 #error no usleep defined for your platform
116 #define UNIX_PATH_LEN 108
119 char sun_path[UNIX_PATH_LEN];
125 #define ETIMEDOUT WSAETIMEDOUT
129 #if defined(__x86_64__) || defined(__i386__)
130 static inline unsigned char inb(
unsigned short int port)
133 __asm__ __volatile__ (
"inb %w1,%0" :
"=a" (_v) :
"Nd" (port));
137 static inline void outb(
unsigned char value,
unsigned short int port)
139 __asm__ __volatile__ (
"outb %b0,%w1" : :
"a" (value),
"Nd" (port));
144 #define ffs __builtin_ffs
148 int win_select(
int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds,
struct timeval *tv);
155 #define OCD_FD_SET(fd, set) FD_SET((SOCKET)(fd), (set))
156 #define OCD_FD_CLR(fd, set) FD_CLR((SOCKET)(fd), (set))
157 #define OCD_FD_ISSET(fd, set) FD_ISSET((SOCKET)(fd), (set))
159 #define OCD_FD_SET(fd, set) FD_SET((fd), (set))
160 #define OCD_FD_CLR(fd, set) FD_CLR((fd), (set))
161 #define OCD_FD_ISSET(fd, set) FD_ISSET((fd), (set))
186 return closesocket(sock);
195 unsigned long nonblock = 0;
196 ioctlsocket(fd, FIONBIO, &nonblock);
198 int oldopts = fcntl(fd, F_GETFL, 0);
199 fcntl(fd, F_SETFL, oldopts & ~O_NONBLOCK);
206 unsigned long nonblock = 1;
207 ioctlsocket(fd, FIONBIO, &nonblock);
209 int oldopts = fcntl(fd, F_GETFL, 0);
210 fcntl(fd, F_SETFL, oldopts | O_NONBLOCK);
221 return win_select(max_fd, rfds, wfds, efds, tv);
223 return select(max_fd, rfds, wfds, efds, tv);
231 return setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (
const char *)&
timeout,
235 tv.
tv_sec = timeout_msec / 1000;
236 tv.
tv_usec = (timeout_msec % 1000) * 1000;
237 return setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (
const char *)&tv,
sizeof(tv));
268 #define ELFMAG "\177ELF"
276 #define ELFDATA2LSB 1
277 #define ELFDATA2MSB 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)
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)