$compact debug pw(79) rom procio_mod: DO; $INCLUDE (:RMX:inc/rmxplm.ext) $if rmx=3 DECLARE SIZE$OF$OFFSET LITERALLY 'DWORD'; $else DECLARE SIZE$OF$OFFSET LITERALLY 'WORD'; $endif strlen: PROCEDURE (str$ptr) BYTE EXTERNAL; DECLARE str$ptr POINTER; END strlen; btoa: PROCEDURE (chr, str$ptr) EXTERNAL; DECLARE chr BYTE, str$ptr POINTER; END btoa; atob: PROCEDURE (str$ptr, status$ptr) BYTE EXTERNAL; DECLARE str$ptr POINTER, status$ptr POINTER; END atob; calc$mean: PROCEDURE (count, buffer$ptr) BYTE EXTERNAL; DECLARE count BYTE, buffer$ptr POINTER; END calc$mean; calc$median: PROCEDURE (count, buffer$ptr) BYTE EXTERNAL; DECLARE count BYTE, buffer$ptr POINTER; END calc$median; calc$mode: PROCEDURE (count, buffer$ptr) BYTE EXTERNAL; DECLARE count BYTE, buffer$ptr POINTER; END calc$mode; DECLARE WAIT$FOREVER LITERALLY '0FFFFH', NO$WAITING LITERALLY '0', E$OK LITERALLY '0', CR LITERALLY '0DH', LF LITERALLY '0AH', TRUE LITERALLY '0FFH', FALSE LITERALLY '0', FOREVER LITERALLY 'WHILE 1', MY$JOB$DIRECTORY LITERALLY 'SELECTOR$OF(NIL)'; procio_task: PROCEDURE PUBLIC; DECLARE actual SIZE$OF$OFFSET, buffer$token TOKEN, procio$mbox TOKEN, procio$resp$mbox TOKEN, sbx350$mbox TOKEN, status WORD, term$in$mbox TOKEN, term$out$mbox TOKEN, data$buffer (100H) BYTE, last$sample BYTE, mean BYTE, median BYTE, mode BYTE, number$of$samples BYTE, valid BYTE, waiting$for$keyboard BYTE, buffer BASED buffer$token (100H) BYTE; DECLARE init$msg (*) BYTE DATA (CR,LF,'Input initialization complete.',CR,LF,0), mean$msg (*) BYTE DATA (CR,LF,'The mean input value was ',0), median$msg (*) BYTE DATA (CR,LF,'The median input value was ',0), mode$msg (*) BYTE DATA (CR,LF,'The mode input value was ',0), entry$msg (*) BYTE DATA (CR,LF,'Please enter a decimal value between 1 and 128 ',0), sample$msg (*) BYTE DATA (CR,LF,'The number of samples taken was ',0); /* Lookup the mailboxes for terminal I/O and the iSBX350 task. */ term$in$mbox = rq$lookup$object (MY$JOB$DIRECTORY, @(6,'TERMIN'), WAIT$FOREVER, @status); term$out$mbox = rq$lookup$object (MY$JOB$DIRECTORY, @(7,'TERMOUT'), WAIT$FOREVER, @status); sbx350$mbox = rq$lookup$object (MY$JOB$DIRECTORY, @(9,'SBX350MBX'), WAIT$FOREVER, @status); /* Set up a data mailbox where the PPI task can send data for * processing. */ procio$mbox = rq$create$mailbox (60H, @status); /* Catalog the mailbox so the PPI task can find it. */ CALL rq$catalog$object (MY$JOB$DIRECTORY, procio$mbox, @(9,'PROCIOMBX'), @status); /* Wait for data from the PPI task intialization before proceeding. */ actual = rq$receive$data (procio$mbox, @data$buffer, WAIT$FOREVER, @status); /* Create an object mailbox for use when requesting keyboard input. */ procio$resp$mbox = rq$create$mailbox (0, @status); /* Wait for a response from the operator before proceeding. */ valid = FALSE; DO WHILE (NOT valid); /* Send a message requesting operator input. */ buffer$token = rq$create$segment (SIZE (buffer), @status); CALL MOVB (@entry$msg, @buffer, SIZE (entry$msg)); CALL rq$send$message (term$out$mbox, buffer$token, SELECTOR$OF(NIL), @status); /* Check for a response. */ buffer$token = rq$create$segment (SIZE (buffer), @status); buffer (0) = 80H; CALL rq$send$message (term$in$mbox, buffer$token, procio$resp$mbox, @status); buffer$token = rq$receive$message (procio$resp$mbox, WAIT$FOREVER, NIL, @status); /* Transform the input parameter from ASCII and validate it. */ number$of$samples = atob (@buffer, @status); IF ((status = E$OK) AND (number$of$samples > 0) AND (number$of$samples <= 128)) THEN valid = TRUE; /* Delete the segment received at procio$resp$mbox. */ CALL rq$delete$segment (buffer$token, @status); END; /* DO WHILE (NOT valid) */ last$sample = number$of$samples; /* Let the PPI task proceed. */ CALL rq$send$data (sbx350$mbox, @number$of$samples, 1, @status); /* Set a flag indicating that no requests are pending for keyboard input. */ waiting$for$keyboard = FALSE; /* Enter main loop for processing digital I/O. */ DO FOREVER; /* Wait for data from PPI task. */ actual = rq$receive$data (procio$mbox, @data$buffer, WAIT$FOREVER, @status); /* Format the data and send it to the terminal output task. */ /* Inform the operator of the number of samples taken. */ buffer$token = rq$create$segment (SIZE (buffer), @status); CALL MOVB (@sample$msg, @buffer, SIZE (sample$msg)); CALL btoa (BYTE (actual), @buffer (SIZE (sample$msg))); CALL rq$send$message (term$out$mbox, buffer$token, SELECTOR$OF(NIL), @status); /* Calculate the mean input value and send it to the operator * as part of a zero terminated string. */ mean = calc$mean (BYTE (actual), @data$buffer); buffer$token = rq$create$segment (SIZE (buffer), @status); CALL MOVB (@mean$msg, @buffer, SIZE (mean$msg)); CALL btoa (mean, @buffer (SIZE (mean$msg))); CALL rq$send$message (term$out$mbox, buffer$token, SELECTOR$OF(NIL), @status); /* Calculate the median input value and send it to the * operator as part of a zero terminated string. */ median = calc$median (BYTE (actual), @data$buffer); buffer$token = rq$create$segment (SIZE (buffer), @status); CALL MOVB (@median$msg, @buffer, SIZE (median$msg)); CALL btoa (median, @buffer (SIZE (median$msg))); CALL rq$send$message (term$out$mbox, buffer$token, SELECTOR$OF(NIL), @status); /* Calculate the mode input value and send it to the operator * as part of a zero terminated string. */ mode = calc$mode (BYTE (actual), @data$buffer); buffer$token = rq$create$segment (SIZE (buffer), @status); CALL MOVB (@mode$msg, @buffer, SIZE (mode$msg)); CALL btoa (mode, @buffer (SIZE (mode$msg))); CALL rq$send$message (term$out$mbox, buffer$token, SELECTOR$OF(NIL), @status); /* Send a message requesting operator input. */ buffer$token = rq$create$segment (SIZE (buffer), @status); CALL MOVB (@entry$msg, @buffer, SIZE (entry$msg)); CALL rq$send$message (term$out$mbox, buffer$token, SELECTOR$OF(NIL), @status); IF (waiting$for$keyboard <> TRUE) THEN DO; /* If no input request is pending, send one. */ buffer$token = rq$create$segment (SIZE (buffer), @status); buffer (0) = 80H; CALL rq$send$message (term$in$mbox, buffer$token, procio$resp$mbox, @status); buffer$token = rq$receive$message (procio$resp$mbox, WAIT$FOREVER, NIL, @status); /* Transform the input parameter from ASCII and validate it. */ number$of$samples = ATOB (@buffer, @status); IF ((status = E$OK) AND (number$of$samples > 0) AND (number$of$samples <= 128)) THEN DO; /* New sample size requested. Inform the interrupt task. */ CALL rq$send$data (sbx350$mbox, @number$of$samples, 1, @status); last$sample = number$of$samples; END; /* Delete the segment received at procio$resp$mbox. */ CALL rq$delete$segment (buffer$token, @status); /* Clear the flag showing that a keyboard input request * is pending. */ waiting$for$keyboard = FALSE; END; /* IF (waiting$for$keyboard <> TRUE) */ END; /* DO FOREVER */ END procio_task; END procio_mod;