home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CTASK22.ZIP / TSKPORW.C < prev    next >
C/C++ Source or Header  |  1990-10-12  |  3KB  |  120 lines

  1. /*
  2.    --- Version 2.2 90-10-12 10:33 ---
  3.  
  4.    TSKPORW.C - CTask - Port watch operations.
  5.  
  6.    CTask - a Multitasking Kernel for C
  7.  
  8.    Public Domain Software written by
  9.       Thomas Wagner
  10.       Ferrari electronic Gmbh
  11.       Beusselstrasse 27
  12.       D-1000 Berlin 21
  13.       Germany
  14.  
  15.    No rights reserved.
  16.  
  17.    This file is new with 2.1. The port watch related functions were moved
  18.    from tsktimer to this module.
  19.  
  20.    Version 2.2 adds a create routine that does not enqueue the created
  21.    element. Separate enable and disable routines have been added in
  22.    tsktsub.c.
  23. */
  24.  
  25. #include "tsk.h"
  26. #include "tsklocal.h"
  27.  
  28. #include <stdarg.h>
  29.  
  30. /*
  31.    create_port_watch_elem
  32.       Creates a port watch element.
  33. */
  34.  
  35. tlinkptr CGlobalfunc create_port_watch_elem (tlinkptr elem, word port, 
  36.                                              byte in_word, word mask, 
  37.                                              word compare, byte cmpkind,
  38.                                              farptr strucp, byte kind, 
  39.                                              int rept, ...)
  40. {
  41.    va_list val;
  42.  
  43.    if (cmpkind < TCMP_EQ || cmpkind > TCMP_CHG)
  44.       return LNULL;
  45.  
  46.    va_start (val, rept);
  47.    elem = tsk_setup_telem (elem, TYP_WATCH, strucp, kind, va_arg (val, dword));
  48.    va_end (val);
  49.    if (elem == LNULL)
  50.       return LNULL;
  51.  
  52.    if (rept)
  53.       elem->flags |= TFLAG_REPEAT;
  54.    elem->elkind = (byte)(TELEM_PORT | cmpkind);
  55.    elem->elem.port.port = port;
  56.    elem->elem.port.in_word = in_word;
  57.    elem->elem.port.mask = mask;
  58.    elem->elem.port.compare = compare;
  59.  
  60.    return elem;
  61. }
  62.  
  63. /*
  64.    create_port_watch
  65.       Creates a port watch element and activates it.
  66.       For compatibility to previous versions only.
  67. */
  68.  
  69. tlinkptr CGlobalfunc create_port_watch (tlinkptr elem, word port, byte in_word,
  70.                                         word mask, word compare, byte cmpkind,
  71.                                         farptr strucp, byte kind, int rept, ...)
  72. {
  73.    va_list val;
  74.  
  75.    va_start (val, rept);
  76.    elem = create_port_watch_elem (elem, port, in_word, mask, compare, cmpkind,
  77.                                   strucp, kind, rept, va_arg (val, dword));
  78.    va_end (val);
  79.    if (elem != LNULL)
  80.       enable_watch (elem);
  81.  
  82.    return elem;
  83. }
  84.  
  85.  
  86. /*
  87.    wait_port
  88.       Delay current task until specified port watch condition is met.
  89. */
  90.  
  91. int Globalfunc wait_port (word port, byte in_word,
  92.                           word mask, word compare, byte cmpkind)
  93. {
  94.    tlinkptr elem;
  95.    tcbptr task = GLOBDATA current_task;
  96.  
  97.    if (cmpkind < TCMP_EQ || cmpkind > TCMP_CHG)
  98.       return 1;
  99.  
  100.    elem = &task->timerq;
  101.    elem->link.kind = TYP_WATCH;
  102.    elem->struckind = TKIND_WAKE;
  103.    elem->elkind = (byte)(TELEM_PORT | cmpkind);
  104.    elem->flags = 0;
  105.    elem->elem.port.port = port;
  106.    elem->elem.port.in_word = in_word;
  107.    elem->elem.port.mask = mask;
  108.    elem->elem.port.compare = compare;
  109.  
  110.    tsk_cli ();
  111.    task->state = ST_DELAYED;
  112.    task->qhead = LNULL;
  113.  
  114.    tsk_putqueue (&GLOBDATA watch_queue, &elem->link);
  115.  
  116.    schedule ();
  117.    return (int)((dword)task->retptr);
  118. }
  119.  
  120.