home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
progm
/
ctask.zip
/
TSIO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-03-01
|
3KB
|
127 lines
/*
Test program for checking the CTask serial I/O interface.
*/
#include <stdio.h>
#include <conio.h>
#include "tsk.h"
#include "sio.h"
#define PORT 0 /* COM1 */
#define BAUD 9600L /* Baudrate */
#define STACKSIZE 2048
word _stklen = 3 * STACKSIZE; /* For Turbo C: Two tasks + main Task Stack */
tcb tcb1, tcb2;
flag halt;
word rcvbuf [100];
byte xmtbuf [100];
int endrun;
/*
Task 1 reads characters from the serial line and displays them on
the screen. While the halt flag is set, characters are not read,
so the XON/XOFF and RTS/CTS protocol can be tested for the receiving
side.
*/
void far task1 (void)
{
word ch;
printf ("Task 1 started\n");
while (!endrun)
{
wait_flag_clear (&halt, 0L);
if (endrun)
return;
ch = v24_receive (0, 0L);
putch (ch);
}
}
/*
Task 2 reads characters from the keyboard and sends them to the
serial port. If 'h' is entered, the halt flag is set, so task1
stops reading. If 'c' is entered, the halt flag is cleared.
Entering 'e' stops the program.
*/
void far task2 (void)
{
int ch;
printf ("Task 2 started\n");
while (!endrun)
{
ch = t_read_key () & 0xff;
switch (ch)
{
case 'h': set_flag (&halt);
puts ("-halt-");
break;
case 'c': clear_flag (&halt);
puts ("-continue-");
break;
case 'e': puts ("-end-");
endrun = 1;
clear_flag (&halt);
wake_task (NULL);
break;
default: putch (ch);
v24_send (0, ch, 0L);
break;
}
}
}
main ()
{
char stack1 [STACKSIZE];
char stack2 [STACKSIZE];
endrun = 0;
install_tasker (0, 0);
v24_install (PORT, rcvbuf, sizeof (rcvbuf), xmtbuf, sizeof (xmtbuf));
v24_change_baud (PORT, BAUD);
v24_protocol (PORT, XONXOFF | RTSCTS, 40, 60);
create_task (&tcb1, task1, stack1, STACKSIZE, 100, NULL);
create_task (&tcb2, task2, stack2, STACKSIZE, 100, NULL);
create_flag (&halt);
start_task (&tcb1);
start_task (&tcb2);
preempt_on ();
t_delay (0L);
endrun = 1;
puts ("******** Main Task *********");
set_priority (NULL, 10);
schedule ();
delete_flag (&halt);
preempt_off ();
v24_remove (PORT);
remove_tasker ();
puts ("******** End Run *********");
}