1.4. Changing the Demo Application
Now we will extend the myHelloWorld application. The extended myHelloWorld
application will write an output to the first serial interface as well as to the
standard output.
Open Eclipse if it is not opened yet
Double-click
myHelloWorld.c
in the myHelloWorld project
First include the following two additional header files:
#include
<unistd.h>
#include
<fcntl.h>
Then add the function
write_tty()
, which writes n bytes to the first serial
interface (which, on the
phyBOARD-RANA-AM335x
, is connected to the system
console /dev/console):
void
write_tty
(
char
*buffer,
int
count)
{
int
out;
out =
open
(
"/dev/console"
, 666);
write
(out, buffer, count);
close
(out);
}
Enter the following two lines in the
main()
function to declare the buffer and
call the write_tty() function.
char
buf [] = {
"Welcome to the World of the Rana-AM335x! (serial)\n"
};
write_tty(buf,
sizeof
(buf) - 1);
In the next screenshot you can see the complete program.
PHYTEC Embedded Pvt. Ltd 2014
15