home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************/
- /* */
- /* CSAMP Sample Program */
- /* */
- /*********************************************************/
-
- #include <stdarg.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <rmxc.h>
- #include "cutils.h"
-
- #define UINT_8 unsigned char
- #define UINT_16 unsigned short
- #define UINT_32 unsigned long
- #define FALSE 0
- #define TRUE 1
-
- #define COUNT_PRIORITY (BYTE) 200 /* Priority of count task */
- #define PROCESS_PRIORITY (BYTE) 200 /* Priority of process task */
- #define BUFF_LEN 125 /* Length of buffer in MSG_STRUC */
- #define DATA_MBOX (WORD) 0x20 /* Code for creation of data mbx.*/
- #define MAX_COUNT (WORD) 0xffff /* UI16_MAX */
- #define NULL_TOKEN (TOKEN) NULL
-
- UINT_32 module_data; /* Used in the create task system call */
- /* Identifies the data segment */
-
- typedef struct {
- short count;
- unsigned char fillchar;
- unsigned char buffer[BUFF_LEN];
- } MSG_STRUC;
-
- TOKEN count_token; /* Token for count task */
- TOKEN process_token; /* Token for process task */
- int counter; /* count_task's counter */
-
- void far main()
- {
- UINT_16 exception; /* Status code returned from system calls */
-
- TOKEN main_mbox; /* Token for main task's mailbox */
- TOKEN proc_mbox; /* Token for process task's mailbox */
- UINT_16 msg_length; /* Actual length of received message.*/
- MSG_STRUC msg; /* Message to be sent/received */
- UINT_16 msg_count;
- UINT_16 i;
-
- extern void far count_task ();
- extern void far process_task ();
-
- printf("Soft-Scope III 'C' Sample Session\r\n");
-
- /*
- * Create the mailbox for main task
- */
- main_mbox = rqcreatemailbox (DATA_MBOX, &exception);
- /*
- * Catalog the mailbox token in the object directory
- */
- rqcatalogobject (NULL_TOKEN, main_mbox, (STRING*)"\010Main Box", &exception);
-
- /*
- * Create the process mailbox
- */
- proc_mbox = rqcreatemailbox (DATA_MBOX, &exception);
- /*
- * Catalog the mailbox token in the object directory
- */
- rqcatalogobject (0, proc_mbox, (STRING*)"\013Process Box", &exception);
-
- /*
- * Create tasks...
- */
- count_token = rqcreatetask (
- COUNT_PRIORITY, /* priority. */
- (void (far *)(void))&count_task, /* start address. */
- (selector)&module_data, /* data segment. */
- 0, /* stack pointer. */
- 4096, /* stack size. */
- 0, /* flags (no NPX). */
- &exception); /* exception ptr. */
-
- process_token = rqcreatetask (
- PROCESS_PRIORITY, /* priority. */
- (void (far *)(void))&process_task, /* start address. */
- (selector)&module_data, /* data segment. */
- 0, /* stack pointer. */
- 4096, /* stack size. */
- 0, /* flags (no NPX). */
- &exception); /* exception ptr. */
-
- msg_count = 0;
- while(1) {
- msg.fillchar = '*';
- if (msg_count >= MAX_COUNT)
- msg_count = 0;
- else
- msg.count = msg_count++;
- memset (msg.buffer, 0, sizeof (msg.buffer));
- /*
- * Send data to process task to fill msg.buffer with fillchar
- */
- rqsenddata (main_mbox,
- (STRING *)&msg,
- sizeof (msg),
- &exception);
- /*
- * Receive data back from process task
- */
- msg_length = rqreceivedata (proc_mbox,
- (STRING *)&msg,
- 0xffff,
- &exception);
- }
- }
-
-
-
- void far process_task ()
- {
- WORD exception; /* Status code returned from system calls */
- TOKEN main_mbox; /* Token for the read meter task's mailbox. */
- TOKEN proc_mbox; /* Token for update database task's mailbox. */
- UINT_16 msg_length; /* Actual length of received message. */
- MSG_STRUC msg; /* Message to be processed. */
- unsigned char pattern;
- UINT_8 i;
-
- /*
- * Lookup the process task mailbox token from the object
- * directory.
- */
- proc_mbox = rqlookupobject (0, (STRING*) "\013Process Box", 0xffff, &exception);
-
- /*
- * Lookup the main task mailbox token from the object
- * directory.
- */
- main_mbox = rqlookupobject (0, (STRING*) "\010Main Box", 0xffff, &exception);
-
- /*
- * Loop forever responding to requests.
- */
- while (1) {
-
- /*
- * Receive the next request
- */
- msg_length = rqreceivedata (main_mbox,
- (STRING *)&msg,
- 0xffff,
- &exception);
-
- /*
- * Take action on the received message (fill msg.buffer)
- */
- for (i = 0; i < BUFF_LEN; i++) {
- msg.buffer[i] = msg.fillchar;
- }
-
- delay (1000); /* Sleep for about 1 sec. so others can run. */
- /*
- * Send response
- */
- rqsenddata (proc_mbox,
- (STRING *)&msg,
- sizeof (msg),
- &exception);
- }
- }
-
- void far count_task ()
- {
- WORD exception; /* Status code returned from system calls */
-
- counter = 0;
-
- while (1) {
- counter++;
- delay (1000);
- c_data ();
- }
- }
-