Exemplo n.º 1
0
VAR_t POSCALL nosRegDel(const char *keyname)
{
  REGELEM_t re, rl;
  VAR_t i;

  posSemaGet(reglist_sema_g);

  for (re = reglist_syselem_g[REGTYPE_USER], rl = NULL;
       re != NULL; rl = re, re = re->next)
  {
    if (!IS_DELETED(re))
    {
      for (i=0; i<NOS_MAX_REGKEYLEN; ++i)
      {
        if (re->name[i] != keyname[i])
          break;
        if ((keyname[i] == 0) || (i == NOS_MAX_REGKEYLEN-1))
        {
          MARK_DELETED(re);
          n_remove(re, rl, REGTYPE_USER);
          posSemaSignal(reglist_sema_g);
          return E_OK;
        }
      }
    }
  }

  posSemaSignal(reglist_sema_g);
  return -E_FAIL;
}
Exemplo n.º 2
0
VAR_t POSCALL nosRegQueryElem(NOSREGQHANDLE_t qh, NOSGENERICHANDLE_t *genh,
                              char* namebuf, VAR_t bufsize)
{
  REGQUERY_t rq = (REGQUERY_t) qh;
  REGELEM_t re;
  VAR_t i;

  if ((rq == NULL) || (genh == NULL) || (namebuf == NULL))
    return -E_ARG;

  posSemaGet(reglist_sema_g);

  if (rq->queryElem == NULL)
  {
    re = reglist_syselem_g[rq->type];
  }
  else
  {
    re = rq->queryElem->next;
    DEC_REFCOUNT(rq->queryElem, rq->type);
  }

  for(;;)
  {
    rq->queryElem = re;

    if (re == NULL)
    {
      posSemaSignal(reglist_sema_g);
      return -E_NOMORE;
    }

    if (IS_VISIBLE(re))
      break;

    re = re->next;
  }

  INC_REFCOUNT(re);

  *genh = re->handle.generic;
  for (i=0; (i < NOS_MAX_REGKEYLEN) && 
            (i < (bufsize-1)) && (re->name[i] != 0); ++i)
  {
    namebuf[i] = re->name[i];
  }
  namebuf[i] = 0;

  posSemaSignal(reglist_sema_g);
  return E_OK;
}
Exemplo n.º 3
0
void POSCALL nos_regDelSysKey(NOSREGTYPE_t type, NOSGENERICHANDLE_t handle,
                              REGELEM_t re)
{
  REGELEM_t rl = REEUNKNOWN;

  posSemaGet(reglist_sema_g);
  if (re == NULL)
  {
    for (re = reglist_syselem_g[type], rl = NULL;
         re != NULL; rl = re, re = re->next)
    {
      if (!IS_DELETED(re) && (re->handle.generic == handle))
        break;
    }
  }
  if (re != NULL)
  {
    if (!IS_DELETED(re))
    {
      MARK_DELETED(re);
      n_remove(re, rl, type);
    }
  }
  posSemaSignal(reglist_sema_g);
}
Exemplo n.º 4
0
/* This function is called from up to three tasks.
 * The function contains a section of code that is protected
 * by a semphore, so that only a maximum number of tasks is allowed
 * to execute the code simultanously. In this example program
 * the semaphore is initialized to 2, the counter variable will
 * count between 1 and 2, and the output is printed by all three
 * tasks. Example printout:
 *   task2: counter = 2
 *   task3: counter = 1
 *   task1: counter = 2
 *   task3: counter = 2
 */
void sharedResource(int tasknbr)
{
  INT_t c;

  /* wait for shared resource */
  posSemaGet(semaphore);

  /* --------------------------------------------------- */

  /* increment global counter */
  posAtomicAdd(&counter, 1);

  /* waste some time (this allows other tasks
     to enter this section of code, too) */
  posTaskSleep(MS(800));

  /* Get and print current counter value.
   * The counter value shows the number of tasks
   * that are currently executing this section of code.
   */
  c = posAtomicGet(&counter);
  nosPrintf2("task%i: counter = %i\n", tasknbr, c);

  /* decrement global counter */
  posAtomicSub(&counter, 1);

  /* --------------------------------------------------- */

  /* quit access to shared resource */
  posSemaSignal(semaphore);
}
Exemplo n.º 5
0
/* This function is called from two tasks.
 * It increments and prints a global counter variable.
 * The function uses a semaphore to protect the shared variable,
 * so only one task is allowed to modify the variable at the time.
 */
void incrementCounter(int tasknbr)
{
  int c;

  /* wait for exclusive access to counter variable */
  posSemaGet(semaphore);

  /* load variable */
  c = counter;

  /* change copy of variable */
  c++;

  /* waste some time */
  posTaskSleep(MS(800));

  /* store changed variable */
  counter = c;

  /* print some text */
  nosPrintf2("task%i: counter = %i\n", tasknbr, counter);

  /* quit exclusive access to the counter variable */
  posSemaSignal(semaphore);
}
Exemplo n.º 6
0
/* This function is executed by the first task.
 */
void task1(void *arg)
{
	VAR_t f;
	
	/* avoid compiler warning */
	(void) arg;

	for(;;) {
	
		f = posFlagGet(flagset, POSFLAG_MODE_GETSINGLE);
		
		nosPrintf("\nfirsttask: going to signal flag %i\n", f);
		
		if(f==1){
			incrementCounter(1);
			posFlagSet(flagset, 2);
			nosPrintf("flag value = %i\n",f);
			task2(arg);
		} 
		
		
		/* do something here and waste some time */
		posTaskSleep(MS(500));
	}
	
	posSemaSignal(semaphore);
	
}
Exemplo n.º 7
0
void task2(void *arg)
{
	VAR_t f; // flag definition variable
	
	(void) arg;

	for(;;) {
	
		// get the flag status
		f = posFlagGet(flagset, POSFLAG_MODE_GETSINGLE);
		
		if(f==2){
			incrementCounter(2);
		}
		
		/* flag status update */
		posFlagSet(flagset, 3);
		nosPrintf("flag value = %i\n",f);
		
		/* do something here and waste some time */
		posTaskSleep(MS(500));
	}
	
	// next the task
	posSemaSignal(semaphore);
}
Exemplo n.º 8
0
/**
 * UART transmit interrupt service routine
 **/
static void usart_txrdy(void)
{
	UDR = tx->buf[tx->tail];
	tx->tail = (tx->tail + 1) & (UART_BUF_SIZE - 1);
	if (tx->tail == tx->head) DISABLE_TXE_INTERRUPT;
	posSemaSignal(tx->lock);
}
Exemplo n.º 9
0
/* This is an example of an interrupt service routine.
 */
void softisr(UVAR_t arg)
{
  /* Avoid compiler warining. arg is the value
   * that was given to the call to posSoftInt.
   */
  (void) arg;

  /* Do something useful here.
   * Note that this function is running at interrupt level,
   * that means the ISR is not allowed to block, and it is not
   * allowed to call operating system functions that may block.
   * The only useful functions that may be called by this
   * routine are posSemaSignal, posFlagSet, posSoftInt and
   * posMessageAlloc/posMessageSend.
   *
   * An interrupt service routine must be as short as possible!
   * (Please see the bottom halfs as a variant of this example)
   *
   */

  /* increment interrupt counter */
  isrCounter++;

  /* signal an event */
  posSemaSignal(event);
}
Exemplo n.º 10
0
REGELEM_t POSCALL nos_regNewSysKey(NOSREGTYPE_t type, const char* name)
{
  REGELEM_t re = NULL;
  posSemaGet(reglist_sema_g);
  (void) n_newKey(type, name, &re);
  posSemaSignal(reglist_sema_g);
  return re;
}
Exemplo n.º 11
0
VAR_t POSCALL nosGetNameByHandle(NOSGENERICHANDLE_t handle,
                                 char *buffer, VAR_t bufsize,
                                 NOSREGTYPE_t what)
{
  NOSREGTYPE_t  rt;
  REGELEM_t re = NULL;
  VAR_t status = -E_NOTFOUND;
  VAR_t i;
  char  c;

  posSemaGet(reglist_sema_g);

  if (what != REGTYPE_SEARCHALL)
  {
    if (what <= MAX_REGTYPE)
    {
      re = n_findKeyByHandle(what, handle);
    }
    else
    {
      status = -E_ARG;
    }
  }
  else  
  for (rt = MIN_REGTYPE; rt <= MAX_REGTYPE; ++rt)
  {
#if NOSCFG_FEATURE_USERREG
    if (rt != REGTYPE_USER)
#endif
    {
      re = n_findKeyByHandle(rt, handle);
      if (re != NULL)
        break;
    }
  }

  if (re != NULL)
  {
    if (IS_VISIBLE(re))
    {
      status = E_OK;
      if ((buffer != NULL) && (bufsize > 0))
      {
        for (i=0; (i<bufsize-1) && (i<NOS_MAX_REGKEYLEN); ++i)
        {
          c = re->name[i];
          if (c == 0)  break;
          buffer[i] = c;
        }
        buffer[i] = 0;
      }
    }
  }

  posSemaSignal(reglist_sema_g);
  return status;
}
Exemplo n.º 12
0
static int sockWrite(UosFile* file, const char* data, int len)
{
  P_ASSERT("sockWrite", file->fs->cf == &netFSConf);
  NetSock* sock = (NetSock*)file->fsPriv;

  posMutexLock(sock->mutex);

  if (sock->state == NET_SOCK_PEER_CLOSED) {

    posMutexUnlock(sock->mutex);
    return NET_SOCK_EOF;
  }

  if (sock->state == NET_SOCK_PEER_ABORTED) {

    posMutexUnlock(sock->mutex);
    return NET_SOCK_ABORT;
  }

  P_ASSERT("sockWrite", sock->state == NET_SOCK_BUSY);

  sock->state = NET_SOCK_WRITING;
  sock->buf = (void*)data;
  sock->len = len;

  dataToSend = 1;
  posSemaSignal(uipGiant);

  while (sock->state == NET_SOCK_WRITING) {

    posMutexUnlock(sock->mutex);
    posFlagGet(sock->uipChange, POSFLAG_MODE_GETMASK);
    posMutexLock(sock->mutex);
  }

  if (sock->state == NET_SOCK_PEER_CLOSED)
    len = NET_SOCK_EOF;
  else if (sock->state == NET_SOCK_PEER_ABORTED)
    len = NET_SOCK_ABORT;
  else {

    P_ASSERT("sockWrite", sock->state == NET_SOCK_WRITE_OK);

    sock->state = NET_SOCK_BUSY;
  }

  posMutexUnlock(sock->mutex);

  return len;
}
Exemplo n.º 13
0
void POSCALL nosRegQueryEnd(NOSREGQHANDLE_t qh)
{
  REGQUERY_t rq = (REGQUERY_t) qh;

  if (rq != NULL)
  {
    if (rq->queryElem != NULL)
    {
      posSemaGet(reglist_sema_g);
      DEC_REFCOUNT(rq->queryElem, rq->type);
      posSemaSignal(reglist_sema_g);
    }
    nosMemFree(rq);
  }
}
Exemplo n.º 14
0
static void uart_rx(void)
{
	uint8_t ch;
	ch = UDR;
	if (rx->full) {
		/* TODO: Handle Serious buffer
		 * Overflow problem. Currently
		 * discarding rx data */
		return ;
	}
	rx->buf[rx->head] = ch;
	rx->head = (rx->head + 1) & (UART_BUF_SIZE - 1);
	posSemaSignal(rx->lock);
	if (rx->head == rx->tail) rx->full = 1;
}
Exemplo n.º 15
0
NOSGENERICHANDLE_t POSCALL nosGetHandleByName(NOSREGTYPE_t objtype, 
                                              const char *objname)
{
  REGELEM_t re;

  if ((objtype > MAX_REGTYPE) || (objname ==NULL))
    return NULL;
  if (n_strlen(objname) > NOS_MAX_REGKEYLEN)
    return NULL;

  posSemaGet(reglist_sema_g);
  re = n_findKeyByName(objtype, objname);
  posSemaSignal(reglist_sema_g);

  if (re == NULL)
    return NULL;
  return IS_VISIBLE(re) ? re->handle.generic : NULL;
}
Exemplo n.º 16
0
VAR_t POSCALL nosRegGet(const char *keyname, KEYVALUE_t *keyvalue)
{
  REGELEM_t re;

  if ((keyname == NULL) || (keyvalue == NULL))
    return -E_ARG;

  posSemaGet(reglist_sema_g);

  re = n_findKeyByName(REGTYPE_USER, keyname);
  if (re != NULL)
  {
    if (IS_VISIBLE(re)) {
      *keyvalue = re->handle.ukv;
    } else {
      re = NULL;
    }
  }

  posSemaSignal(reglist_sema_g);
  return (re == NULL) ? -E_FAIL : E_OK;
}
Exemplo n.º 17
0
static int sockClose(UosFile* file)
{
  P_ASSERT("sockWrite", file->fs->cf == &netFSConf);
  NetSock* sock = (NetSock*)file->fsPriv;

  posMutexLock(sock->mutex);

  if (sock->state == NET_SOCK_BUSY) {

    sock->state = NET_SOCK_CLOSE;

    dataToSend = 1;
    posSemaSignal(uipGiant);

    while (sock->state == NET_SOCK_CLOSE) {

      posMutexUnlock(sock->mutex);
      posFlagGet(sock->uipChange, POSFLAG_MODE_GETMASK);
      posMutexLock(sock->mutex);
    }
  }

  if (sock->state == NET_SOCK_LISTENING) {

    posMutexLock(uipMutex);
    uip_unlisten(sock->port);
    posMutexUnlock(uipMutex);

    sock->port = 0;
    sock->state = NET_SOCK_CLOSE_OK;
  }

  P_ASSERT("CloseState", (sock->state == NET_SOCK_PEER_CLOSED ||
                          sock->state == NET_SOCK_PEER_ABORTED || 
                          sock->state == NET_SOCK_CLOSE_OK));

  netSockFree(file);
  return 0;
}
Exemplo n.º 18
0
void task3(void *arg)
{
	VAR_t f;
	
	(void) arg;
		
	for(;;) {
	
		f = posFlagGet(flagset, POSFLAG_MODE_GETSINGLE);
		
		if(f==3){
			incrementCounter(3);
		}
			
		posFlagSet(flagset, 1);
		nosPrintf("flag value = %i\n",f);
		
		posTaskSleep(MS(500));
	}
	
	posSemaSignal(semaphore);
}
Exemplo n.º 19
0
/* This function is called from two tasks.
 * It increments and prints a global counter variable.
 * The function uses a semaphore to protect the shared variable,
 * so only one task is allowed to modify the variable at the time.
 */
void incrementCounter(int tasknbr) {
	
	/* temporary variable */
	int c;

	posSemaGet(semaphore);
	
	/* get the variable value*/
	c = counter;

	/* increase the temporary variable*/
	c++;

	/* wait the 500ms */
	posTaskSleep(MS(500)); 
  
	/* swap the variables */
	counter = c;

	/* print the status */ 
	nosPrintf("task%i: counter = %i\n", tasknbr, counter);
	
	/* flag state change control */
	if(tasknbr == taskCount){
		tasknbr = 1;
	}
  
  	int tempOfIndexValue = tasknbr;
	
	tempOfIndexValue = tempOfIndexValue+1;
  
	/* flag updated */
	posFlagSet(flagset, tempOfIndexValue);
	
	/* next the semaphore */
	posSemaSignal(semaphore);
}
Exemplo n.º 20
0
VAR_t POSCALL nosRegSet(const char *keyname, KEYVALUE_t keyvalue)
{
  REGELEM_t re;
  VAR_t  status = E_OK;

  if (keyname == NULL)
    return -E_ARG;

  posSemaGet(reglist_sema_g);

  re = n_findKeyByName(REGTYPE_USER, keyname);
  if (re == NULL)
  {
    status = n_newKey(REGTYPE_USER, keyname, &re);
  }
  if (status == E_OK)
  {
    re->handle.ukv = keyvalue;
    MARK_VISIBLE(re);
  }

  posSemaSignal(reglist_sema_g);
  return status;
}
Exemplo n.º 21
0
static void task_semas(void *arg)
{
    static INT_t cntr = 0;
    char  buf[5];

    buf[1] = 'S';
    buf[2] = (char) ((int)arg);
    buf[3] = ' ';
    buf[4] = '\0';

    (void) arg;

    for (;;)
    {
        /* try to get semaphore */
        posSemaGet(sema_g);

        cntr++;

        /* sleep one second */
        posTaskSleep(HZ);

        /* print information, how many tasks are in this function */
        buf[0] = '0' + (char) cntr;
        print(buf);
        if ((cntr < 1) || (cntr > 2))
        {
            print("SEMAPHORE-ERROR");
        }

        cntr--;

        /* release semaphore again */
        posSemaSignal(sema_g);
    }
}
Exemplo n.º 22
0
/*
 * Set a semaphore.
 */
wwd_result_t host_rtos_set_semaphore(host_semaphore_type_t* semaphore, wiced_bool_t fromISR)
{
  P_ASSERT("fromISR / posInInterrupt_g mismatch.", (fromISR == 0) == (posInInterrupt_g == 0));
  posSemaSignal(*semaphore);
  return WWD_SUCCESS;
}
Exemplo n.º 23
0
void netInterrupt()
{
  posSemaSignal(uipGiant);
}
Exemplo n.º 24
0
void netEnableDevicePolling(UINT_t ticks)
{
  pollTicks = ticks;
  posSemaSignal(uipGiant);
}