Ejemplo n.º 1
0
/*
 * Only commands MEASURE_HUMI or MEASURE_TEMP!
 */
static unsigned int
scmd(unsigned cmd)
{
  unsigned long n;

  if(cmd != MEASURE_HUMI && cmd != MEASURE_TEMP) {
    return -1;
  }
  MCUCR |= (1<<JTD);
  MCUCR |= (1<<JTD);

  sreset();
  /* Start transmission */
  if(!swrite(cmd)) {
	  //printf("-2");
	  goto fail;
  }

  for(n = 0; n < 250000; n++) {
    if(!SDA_IS_1) {
      unsigned t0, t1, rcrc;
      t0 = sread(1);
      t1 = sread(1);
      rcrc = sread(0);
      //printf("t0:%d",t0);
      //printf("t1:%d",t1);
#ifdef CRC_CHECK
      {
	unsigned crc;
	crc = crc8_add(0x0, cmd);
	crc = crc8_add(crc, t0);
	crc = crc8_add(crc, t1);
	if(crc != rev8bits(rcrc)) {
		// printf("-3");
		goto fail;
	}
      }
#endif
      MCUCR &= (0<<JTD);
      MCUCR &= (0<<JTD);

      return (t0 << 8) | t1;
    }
  }

 fail:
  sreset();
  //printf("-1");
  MCUCR &= (0<<JTD);
  MCUCR &= (0<<JTD);

  return -1;
}
Ejemplo n.º 2
0
/*---------------------------------------------------------------------------*/
#if 1 /* But ok! */
unsigned
sht11_sreg(void)
{
  unsigned sreg, rcrc;

  sstart();			/* Start transmission */
  if(!swrite(STATUS_REG_R)) {
    goto fail;
  }

  sreg = sread(1);
  rcrc = sread(0);

#ifdef CRC_CHECK
  {
    unsigned crc;
    crc = crc8_add(0x0, STATUS_REG_R);
    crc = crc8_add(crc, sreg);
    if (crc != rev8bits(rcrc))
      goto fail;
  }
#endif

  return sreg;

 fail:
  sreset();
  return -1;
}
Ejemplo n.º 3
0
/*------------------------------------------------------------------------
 *  writcopy - high-speed copy from user's buffer into system buffer
 *------------------------------------------------------------------------
 */
LOCAL writcopy(char *buff, struct tty *ttyp, int count)
{
	register int	avail;
	register char	*cp, *qhead, *qend, *uend;

	avail = OBUFLEN - ttyp->ocnt;
	qhead = &ttyp->obuff[ttyp->ohead];
	qend  = &ttyp->obuff[OBUFLEN];
	cp    = buff;
	uend  = buff + count;
	while (avail-- > 1 && cp < uend) {
		if (*cp == NEWLINE && ttyp->ocrlf) {
			*qhead++ = RETURN;
			--avail;
			if ( qhead >= qend )
				qhead = ttyp->obuff;
		}
		*qhead++ = *cp++;
		if ( qhead >= qend )
			qhead = ttyp->obuff;
	}					/* avail decremented one*/
	ttyp->ohead = qhead - ttyp->obuff;	/* extra time when loop	*/
	ttyp->ocnt = OBUFLEN - (avail+1);
	sreset(ttyp->osem, ++avail);		/* condition fails.	*/
	*USART[ttyp->unit].UCSRB |= (1<<UDRIE0);			/*ttyostart(ttyp);*/
	return(cp - buff);
}
Ejemplo n.º 4
0
//------------------------------------------------------------------------
//  writecopy - high-speed copy from user's buffer into system buffer
//------------------------------------------------------------------------
static int
writecopy(char *buff, struct tty *ttyp, int count)
{
	int avail;
	char *cp, *qhead, *qend, *uend;

	avail = scount(ttyp->osem);
	qhead = &ttyp->obuff[ttyp->ohead];
	qend = &ttyp->obuff[OBUFLEN];
	cp = buff;
	uend = buff + count;
	while (avail-- > 1 && cp < uend) {
		if (*cp == NEWLINE && ttyp->ocrlf) {
			*qhead++ = RETURN;
			--avail;
			if (qhead >= qend)
				qhead = ttyp->obuff;
		}
		*qhead++ = *cp++;
		if (qhead >= qend)
			qhead = ttyp->obuff;
	}			// avail decremented one
	ttyp->ohead = qhead - ttyp->obuff;	// extra time when loop
	sreset(ttyp->osem, ++avail);	// condition fails.
	ttyp->imr |= DUART_TxINTABLE;
	(ttyp->ioaddr)->imr = ttyp->imr;

	return cp - buff;
}
Ejemplo n.º 5
0
/* <file> resetfile - */
static int
zresetfile(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    stream *s;

    /* According to Adobe, resetfile is a no-op on closed files. */
    check_type(*op, t_file);
    if (file_is_valid(s, op))
	sreset(s);
    pop(1);
    return 0;
}
Ejemplo n.º 6
0
int
sht11_reset(void)
{
  sstart();			/* Start transmission */
  if(!swrite(RESET)) {
    goto fail;
  }

  return 0;

 fail:
  sreset();
  return -1;
}
Ejemplo n.º 7
0
/*------------------------------------------------------------------------
 *  _ptclear  --  used by pdelete and preset to clear a port
 *------------------------------------------------------------------------
 */
_ptclear(struct pt *ppt, int newstate, void (*dispose)())
{
    struct	ptnode	*p;

    /* put port in limbo until done freeing processes */
    ppt->ptstate = PTLIMBO;
    ppt->ptseq++;
    if ( (p=ppt->pthead) != (struct ptnode *)NULL ) {
        if (dispose != PTNODISP)
            for(; p != (struct ptnode *) NULL ; p=p->ptnext)
                (*dispose)( p->ptmsg );
        (ppt->pttail)->ptnext = ptfree;
        ptfree = ppt->pthead;
    }
    if (newstate == PTALLOC) {
        ppt->pttail = ppt->pthead = (struct ptnode *) NULL;
        sreset(ppt->ptssem, ppt->ptmaxcnt);
        sreset(ppt->ptrsem, 0);
    } else {
        sdelete(ppt->ptssem);
        sdelete(ppt->ptrsem);
    }
    ppt->ptstate = newstate;
}
Ejemplo n.º 8
0
/*------------------------------------------------------------------------
 *  readcopy - high speed copy procedure used by ttyread
 *------------------------------------------------------------------------
 */
LOCAL int readcopy( register char *buff, struct tty *iptr, int count )
{
    register char *qtail, *qend, *uend; /* copy loop variables */

    qtail = &iptr->ibuff[iptr->itail];
    qend = &iptr->ibuff[IBUFLEN];
    uend = buff + count;
    while ( buff < uend ) {
        *buff++ = *qtail++;
        if ( qtail >= qend )
            qtail = iptr->ibuff;
    }
    iptr->itail = qtail - iptr->ibuff;
    sreset( iptr->isem, scount( iptr->isem ) - count );
    return;
}
Ejemplo n.º 9
0
int
sht11_set_sreg(unsigned sreg)
{
  sstart();			/* Start transmission */
  if(!swrite(STATUS_REG_W)) {
    goto fail;
  }
  if(!swrite(sreg)) {
    goto fail;
  }

  return 0;

 fail:
  sreset();
  return -1;
}
Ejemplo n.º 10
0
/*
 * Only commands MEASURE_HUMI or MEASURE_TEMP!
 */
static unsigned int
scmd(unsigned cmd)
{
  unsigned int n;

  if(cmd != MEASURE_HUMI && cmd != MEASURE_TEMP) {
    PRINTF("Illegal command: %d\n", cmd);
    return -1;
  }

  sstart();			/* Start transmission */
  if(!swrite(cmd)) {
    PRINTF("SHT11: scmd - swrite failed\n");
    goto fail;
  }

  for(n = 0; n < 20000; n++) {
    if(!SDA_IS_1) {
      unsigned t0, t1, rcrc;
      t0 = sread(1);
      t1 = sread(1);
      rcrc = sread(0);
      PRINTF("SHT11: scmd - read %d, %d\n", t0, t1);
#ifdef CRC_CHECK
      {
	unsigned crc;
	crc = crc8_add(0x0, cmd);
	crc = crc8_add(crc, t0);
	crc = crc8_add(crc, t1);
	if(crc != rev8bits(rcrc)) {
	  PRINTF("SHT11: scmd - crc check failed %d vs %d\n",
		 crc, rev8bits(rcrc));
	  goto fail;
	}
      }
#endif
      return (t0 << 8) | t1;
    }
    /* short wait before next loop */
    clock_wait(1);
  }
 fail:
  sreset();
  return -1;
}
Ejemplo n.º 11
0
int main(void *arg)
{
        int sem, i;

        (void)arg;

        assert(screate(-2) == -1);
        assert((sem = screate(2)) >= 0);
        assert(signaln(sem, -4) < 0);
        assert(sreset(sem, -3) == -1);
        assert(scount(sem) == 2);
        assert(signaln(sem, 32760) == 0);
        assert(signaln(sem, 6) == -2);
        assert(scount(sem) == 32762);
        assert(wait(sem) == 0);
        assert(scount(sem) == 32761);
        assert(signaln(sem, 30000) == -2);
        assert(scount(sem) == 32761);
        assert(wait(sem) == 0);
        assert(scount(sem) == 32760);
        assert(signaln(sem, -2) < 0);
        assert(scount(sem) == 32760);
        assert(wait(sem) == 0);
        assert(scount(sem) == 32759);
        assert(signaln(sem, 8) == 0);
        assert(scount(sem) == 32767);
        assert(signaln(sem, 1) == -2);
        assert(scount(sem) == 32767);
        assert(signal(sem) == -2);
        assert(scount(sem) == 32767);
        for (i=0; i<32767; i++) {
                assert(wait(sem) == 0);
        }
        assert(try_wait(sem) == -3);
        assert(scount(sem) == 0);
        assert(sdelete(sem) == 0);
        printf("ok.\n");
}
Ejemplo n.º 12
0
Archivo: lex.c Proyecto: coyizumi/cs111
/*
 * Interpret user commands one by one.  If standard input is not a tty,
 * print no prompt.
 */
void
commands(void)
{
	int n, eofloop = 0;
	char linebuf[LINESIZE];

	if (!sourcing) {
		if (signal(SIGINT, SIG_IGN) != SIG_IGN)
			(void)signal(SIGINT, intr);
		if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
			(void)signal(SIGHUP, hangup);
		(void)signal(SIGTSTP, stop);
		(void)signal(SIGTTOU, stop);
		(void)signal(SIGTTIN, stop);
	}
	setexit();
	for (;;) {
		/*
		 * Print the prompt, if needed.  Clear out
		 * string space, and flush the output.
		 */
		if (!sourcing && value("interactive") != NULL) {
			if ((value("autoinc") != NULL) && (incfile() > 0))
				printf("New mail has arrived.\n");
			reset_on_stop = 1;
			printf("%s", prompt);
		}
		(void)fflush(stdout);
		sreset();
		/*
		 * Read a line of commands from the current input
		 * and handle end of file specially.
		 */
		n = 0;
		for (;;) {
			if (readline(input, &linebuf[n], LINESIZE - n) < 0) {
				if (n == 0)
					n = -1;
				break;
			}
			if ((n = strlen(linebuf)) == 0)
				break;
			n--;
			if (linebuf[n] != '\\')
				break;
			linebuf[n++] = ' ';
		}
		reset_on_stop = 0;
		if (n < 0) {
				/* eof */
			if (loading)
				break;
			if (sourcing) {
				unstack();
				continue;
			}
			if (value("interactive") != NULL &&
			    value("ignoreeof") != NULL &&
			    ++eofloop < 25) {
				printf("Use \"quit\" to quit.\n");
				continue;
			}
			break;
		}
		eofloop = 0;
		if (execute(linebuf, 0))
			break;
	}
}