examples/serialblaster, serialrx, udpblaster: Update to serial/UDP tests.
This commit is contained in:
parent
049616a651
commit
da100102a7
@ -19,4 +19,9 @@ config EXAMPLES_SERIALBLASTER_PRIORITY
|
|||||||
int "CPU hog task priority"
|
int "CPU hog task priority"
|
||||||
default 50
|
default 50
|
||||||
|
|
||||||
|
config EXAMPLES_SERIALBLASTER_DEVPATH
|
||||||
|
string "Serial device path"
|
||||||
|
default "/dev/ttyS2"
|
||||||
|
---help---
|
||||||
|
The default path to the serial device
|
||||||
endif
|
endif
|
||||||
|
@ -44,8 +44,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <nuttx/clock.h>
|
#include <nuttx/clock.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <nuttx/fs/fs.h>
|
#include <nuttx/fs/fs.h>
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
@ -70,16 +73,60 @@ static const char s[] = "abcdefghijklmnopqrstuvwxyz";
|
|||||||
int main(int argc, FAR char *argv[])
|
int main(int argc, FAR char *argv[])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
int fd;
|
||||||
|
FAR char *devpath;
|
||||||
|
int size = 0;
|
||||||
|
int rem;
|
||||||
|
|
||||||
while (1)
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
#ifdef BUFFERED_IO
|
devpath = CONFIG_EXAMPLES_SERIALBLASTER_DEVPATH;
|
||||||
ret = fputs(s, stdout);
|
}
|
||||||
#else
|
else if (argc == 2)
|
||||||
ret = write(1, s, sizeof(s)-1);
|
{
|
||||||
#endif
|
devpath = argv[1];
|
||||||
|
}
|
||||||
|
else if (argc == 3)
|
||||||
|
{
|
||||||
|
devpath = argv[1];
|
||||||
|
size = strtol(argv[2], NULL, 10);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Usage: %s [devpath]\n", argv[0]);
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = open(devpath, O_RDWR);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
printf("dev_ttyS2: ERROR Failed to open /dev/ttyS2\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rem = size;
|
||||||
|
while (size > sizeof(s))
|
||||||
|
{
|
||||||
|
if (rem > 26)
|
||||||
|
{
|
||||||
|
ret = write(fd, s, (sizeof(s)-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
rem = rem - 26;
|
||||||
|
if (rem < 26)
|
||||||
|
{
|
||||||
|
ret = write(fd, s, rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
size = size - 26;
|
||||||
UNUSED(ret);
|
UNUSED(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
up_udelay(5000000);
|
||||||
|
close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
errout:
|
||||||
|
fflush(stderr);
|
||||||
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ config EXAMPLES_SERIALRX_PRIORITY
|
|||||||
|
|
||||||
config EXAMPLES_SERIALRX_BUFFERED
|
config EXAMPLES_SERIALRX_BUFFERED
|
||||||
bool "Buffered I/O"
|
bool "Buffered I/O"
|
||||||
default y
|
default n
|
||||||
---help---
|
---help---
|
||||||
Use buffered I/O
|
Use buffered I/O
|
||||||
|
|
||||||
|
@ -48,14 +48,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <nuttx/arch.h>
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
@ -69,8 +62,13 @@ int main(int argc, FAR char *argv[])
|
|||||||
{
|
{
|
||||||
#ifdef CONFIG_EXAMPLES_SERIALRX_BUFFERED
|
#ifdef CONFIG_EXAMPLES_SERIALRX_BUFFERED
|
||||||
FAR FILE *f;
|
FAR FILE *f;
|
||||||
|
int fd;
|
||||||
|
int nbytes;
|
||||||
|
int cnt;
|
||||||
#else
|
#else
|
||||||
int fd;
|
int fd;
|
||||||
|
int cnt;
|
||||||
|
int bytecount = 0;
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_EXAMPLES_SERIALRX_PRINTHYPHEN
|
#ifdef CONFIG_EXAMPLES_SERIALRX_PRINTHYPHEN
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -90,6 +88,11 @@ int main(int argc, FAR char *argv[])
|
|||||||
{
|
{
|
||||||
devpath = argv[1];
|
devpath = argv[1];
|
||||||
}
|
}
|
||||||
|
else if (argc == 3)
|
||||||
|
{
|
||||||
|
devpath = argv[1];
|
||||||
|
bytecount = strtol(argv[2], NULL, 10);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s [devpath]\n", argv[0]);
|
fprintf(stderr, "Usage: %s [devpath]\n", argv[0]);
|
||||||
@ -101,6 +104,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
#else
|
#else
|
||||||
buf = (FAR char *)malloc(CONFIG_EXAMPLES_SERIALRX_BUFSIZE);
|
buf = (FAR char *)malloc(CONFIG_EXAMPLES_SERIALRX_BUFSIZE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: malloc failed: %d\n", errno);
|
fprintf(stderr, "ERROR: malloc failed: %d\n", errno);
|
||||||
@ -115,7 +119,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
goto errout_with_buf;
|
goto errout_with_buf;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
fd = open(devpath, O_RDONLY);
|
fd = open(devpath, O_RDWR);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: open failed: %d\n", errno);
|
fprintf(stderr, "ERROR: open failed: %d\n", errno);
|
||||||
@ -125,11 +129,12 @@ int main(int argc, FAR char *argv[])
|
|||||||
|
|
||||||
printf("Reading from %s\n", devpath);
|
printf("Reading from %s\n", devpath);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
cnt = 0;
|
||||||
while (!eof)
|
while (cnt < bytecount)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_EXAMPLES_SERIALRX_BUFFERED
|
#ifdef CONFIG_EXAMPLES_SERIALRX_BUFFERED
|
||||||
size_t n = fread(buf, 1, CONFIG_EXAMPLES_SERIALRX_BUFSIZE, f);
|
size_t n = fread(buf, 1, 26, f);
|
||||||
|
cnt++;
|
||||||
if (feof(f))
|
if (feof(f))
|
||||||
{
|
{
|
||||||
eof = true;
|
eof = true;
|
||||||
@ -142,6 +147,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
ssize_t n = read(fd, buf, CONFIG_EXAMPLES_SERIALRX_BUFSIZE);
|
ssize_t n = read(fd, buf, CONFIG_EXAMPLES_SERIALRX_BUFSIZE);
|
||||||
|
up_udelay(1000);
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
{
|
{
|
||||||
eof = true;
|
eof = true;
|
||||||
@ -167,24 +173,25 @@ int main(int argc, FAR char *argv[])
|
|||||||
{
|
{
|
||||||
printf("0x%02x ", i, buf[i]);
|
printf("0x%02x ", i, buf[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
#elif defined(CONFIG_EXAMPLES_SERIALRX_PRINTSTR)
|
#endif /*Kamal*/
|
||||||
buf[n] = '\0';
|
cnt += n;
|
||||||
printf("%s", buf);
|
|
||||||
fflush(stdout);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNUSED(eof);
|
||||||
|
}
|
||||||
#ifdef CONFIG_EXAMPLES_SERIALRX_PRINTHYPHEN
|
#ifdef CONFIG_EXAMPLES_SERIALRX_PRINTHYPHEN
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
#endif
|
||||||
printf("EOF reached\n");
|
printf("EOF reached\n");
|
||||||
|
printf("Total bytes received = %d\n", cnt); /* Kamal */
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_SERIALRX_BUFFERED
|
#ifdef CONFIG_EXAMPLES_SERIALRX_BUFFERED
|
||||||
fclose(f);
|
fclose(f);
|
||||||
#else
|
#else
|
||||||
|
up_udelay(1000000);
|
||||||
close(fd);
|
close(fd);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -182,7 +182,6 @@ static void netest_initialize(void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
netlib_ifup("eth0");
|
netlib_ifup("eth0");
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif /*CONFIG_EXAMPLES_UDPBLASTER_INIT */
|
#endif /*CONFIG_EXAMPLES_UDPBLASTER_INIT */
|
||||||
|
|
||||||
@ -318,7 +317,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
goto errout_with_socket;
|
goto errout_with_socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++npackets >= 10)
|
if (++npackets >= 10000)
|
||||||
{
|
{
|
||||||
putchar('.');
|
putchar('.');
|
||||||
npackets = 0;
|
npackets = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user