Beispiel #1
0
//--------------------- Reads time and date information from RTC (PCF8563)
void rtc_r(void) 
{
  unsigned char tmp;

  Soft_I2C_Start();
  Soft_I2C_Write(0xA2);
  Soft_I2C_Write(2);

  Soft_I2C_Start();
  Soft_I2C_Write(0xA3);
  tmp= 0x7F & Soft_I2C_Read(1); //segundos
  time[5]=':';
  time[6]=getd(tmp);
  time[7]=getu(tmp);
  time[8]=0;

  tmp= 0x7F & Soft_I2C_Read(1); //minutos
  time[2]=':';
  time[3]=getd(tmp);
  time[4]=getu(tmp);

  tmp= 0x3F & Soft_I2C_Read(1); //horas
  time[0]=getd(tmp);
  time[1]=getu(tmp);

  tmp= 0x3F & Soft_I2C_Read(1); //dia
  date[0]=getd(tmp);
  date[1]=getu(tmp);

  Soft_I2C_Read(1); //dia semana

  tmp= 0x1F & Soft_I2C_Read(1); //mes
  date[2]='/'; 
  date[3]=getd(tmp);
  date[4]=getu(tmp);

  tmp=  Soft_I2C_Read(1); //ano
  date[5]='/';
  date[6]=getd(tmp);
  date[7]=getu(tmp);
  date[8]=0;

  Soft_I2C_Stop();

}
Beispiel #2
0
/* newlines are replaced with \0; \x{<hex>+} are unescaped.
the result is in sp->v
*/
static void getv(struct rnc_source *sp) {
  if(sp->nx>0) {
    sp->v='x'; --sp->nx;
  } else if(sp->nx==0) {
    sp->v=sp->w;
    sp->nx=-1;
  } else {
    getu(sp);
    switch(sp->u) {
    case '\r': case '\n': sp->v=0; break;
    case '\\':
      getu(sp);
      if(sp->u=='x') {
	sp->nx=0;
	do {
	  ++sp->nx;
	  getu(sp);
	} while(sp->u=='x');
	if(sp->u=='{') {
	  sp->nx=-1;
	  sp->v=0;
	  for(;;) {
	    getu(sp);
	    if(sp->u=='}') goto END_OF_HEX_DIGITS;
	    sp->v<<=4;
	    switch(sp->u) {
	    case '0': break;
	    case '1': sp->v+=1; break;
	    case '2': sp->v+=2; break;
	    case '3': sp->v+=3; break;
	    case '4': sp->v+=4; break;
	    case '5': sp->v+=5; break;
	    case '6': sp->v+=6; break;
	    case '7': sp->v+=7; break;
	    case '8': sp->v+=8; break;
	    case '9': sp->v+=9; break;
	    case 'A': case 'a': sp->v+=10; break;
	    case 'B': case 'b': sp->v+=11; break;
	    case 'C': case 'c': sp->v+=12; break;
	    case 'D': case 'd': sp->v+=13; break;
	    case 'E': case 'e': sp->v+=14; break;
	    case 'F': case 'f': sp->v+=15; break;
	    default:
	      error(0,sp,RNC_ER_XESC,sp->fn,CUR(sp).line,CUR(sp).col);
	      goto END_OF_HEX_DIGITS;
	    }
	  } END_OF_HEX_DIGITS:;
	} else {
	  sp->v='\\'; sp->w=sp->u;
	}
      } else {
	sp->nx=0;
	sp->v='\\'; sp->w=sp->u;
      }
      break;
    default:
      sp->v=sp->u;
      break;
    }
  }
}
Beispiel #3
0
char *format_next_process(caddr_t handle, char *(*get_userid)())
{
    register struct proc *pp;
    register long cputime;
    register double pct, wcpu, pctmem;
    int where;
    struct user u;
    struct handle *hp;
    register int p_pctcpu;
    register int rm_size;
    register int vm_size;
    register int run_state;
    register int flags;
    register int nthreads;
    register int cur_priority;
    char state_str[10];

    /* find and remember the next proc structure */
    hp = (struct handle *)handle;
    pp = hp->list[hp->current].p_self;
    p_pctcpu = hp->list[hp->current].p_pctcpu;
    cputime = hp->list[hp->current].p_cptime;
    rm_size = hp->list[hp->current].p_rsize;
    vm_size = hp->list[hp->current].p_vsize;
    run_state = hp->list[hp->current].run_state;
    flags = hp->list[hp->current].flags;
    nthreads = hp->list[hp->current].nthreads;
    cur_priority = hp->list[hp->current].cur_priority;
    hp->current++;
    hp->count--;

    /* get the process's user struct and set cputime */
    where = getu(pp, &u);
    if (where == -1)
    {
        (void) strcpy(u.u_comm, "<swapped>");
        cputime = 0;
    }
    else
    {
        /* set u_comm for system processes */
        if (u.u_comm[0] == '\0')
        {
            if (pp->p_pid == 0)
            {
                (void) strcpy(u.u_comm, "Swapper");
            }
            else if (pp->p_pid == 2)
            {
                (void) strcpy(u.u_comm, "Pager");
            }
        }
        if (where == 1) {
            /*
            * Print swapped processes as <pname>
            */
            char buf[sizeof(u.u_comm)];
            (void) strncpy(buf, u.u_comm, sizeof(u.u_comm));
            u.u_comm[0] = '<';
            (void) strncpy(&u.u_comm[1], buf, sizeof(u.u_comm) - 2);
            u.u_comm[sizeof(u.u_comm) - 2] = '\0';
            (void) strncat(u.u_comm, ">", sizeof(u.u_comm) - 1);
            u.u_comm[sizeof(u.u_comm) - 1] = '\0';
        }
        /*	User structure does not work.  Use Thread Info to get cputime for process. */
        /*		cputime = u.u_ru.ru_utime.tv_sec + u.u_ru.ru_stime.tv_sec; */
    }


    /* calculate the base for cpu percentages */
    pct = (double)(p_pctcpu)/TH_USAGE_SCALE;
    /*	wcpu = weighted_cpu(pct, pp);
     */
    pctmem = (double)(rm_size*1024.) / (double)(host_stats.memory_size);

    /* Get process state description */
    if(run_state)
    {
        strcpy(state_str, mach_state[run_state]);
        strcat(state_str, flags_state[flags]);
    } else {
        strcpy(state_str, state_abbrev[pp->p_stat]);
    }

    /* format this entry */
    sprintf(fmt,
            Proc_format,
            pp->p_pid,
            (*get_userid)(pp->p_uid),
            state_str,
            cur_priority,
            /*	    pp->p_pri - PZERO, */
            pp->p_nice - NZERO,
            nthreads,
            format_k(vm_size),
            format_k(rm_size),
            100.0 * pctmem,
            /*	    100.0 * wcpu, */
            100.0 * pct,
            format_time(cputime),
            printable(u.u_comm));

    /* return the result */
    return(fmt);
}