int _ajax_sesinit() { capability owner; /* Current owner; may be session svr private */ capability self; /* This process */ capability *session; /* Most specific session svr cap */ capability *tty; /* TTY (stdin) */ int pid; /* Process ID if known */ int err; MU_LOCK(&mu); if (!_ajax_sesinited) { session = getcap("_SESSION"); if (session == NULL) { MU_UNLOCK(&mu); _ajax_puts( "Ajax (init): can't find _SESSION in cap env"); ERR(EIO, "sesinit: no _SESSION in cap env"); } if (_ajax_getowner(&owner) != 0) { MU_UNLOCK(&mu); return -1; /* Can't find owner capability */ } if (getinfo(&self, NILPD, 0) < 0) { MU_UNLOCK(&mu); ERR(EIO, "sesinit: getinfo failed"); } if (PORTCMP(&owner.cap_port, &session->cap_port)) { /* Session svr already owns us */ session = &owner; pid = prv_number(&owner.cap_priv); } else { /* Owner is not the session svr */ pid = 0; } if ((err = ses_init(session, &self, &_ajax_session)) < 0) { MU_UNLOCK(&mu); _ajax_putnum("Ajax (init): session init failed, error", err); ERR(EIO, "sesinit: ses_init failed"); } if (pid == 0) { /* Arrange for tty interrupts to go to the * session server. */ if ((tty = getcap("TTY")) != NULL) { (void) ttq_intcap(tty, &_ajax_session); } } _ajax_sesinited = 1; } MU_UNLOCK(&mu); return 0; }
/* * Initialise. * Try using the capabilities STDERR and STDOUT in turn * otherwise lookup /tty:00 */ static capability * init() { static capability *capp, tty; if ((capp = getcap("STDERR")) != NULL || (capp = getcap("STDOUT")) != NULL) return capp; if ((capp = getcap("ROOT")) != NULL && dir_lookup(capp, "tty:00", &tty) == STD_OK) { return capp = &tty; } return (capability *) NULL; } /* init */
void loop () { char capval[6]; char pinval[6] = {1<<PINB0,1<<PINB1,1<<PINB2,1<<PINB3,1<<PINB4,1<<PINB5}; delay(1000); for(char i = 0; i < 6; i++) { capval[i] = getcap(pinval[i]); Serial.print("digital "); Serial.print(i+8, DEC); Serial.print(": "); Serial.println(capval[i], DEC); } Serial.println(""); }
void haunt(void) /* Become a daemon, print jobs while there are any, exit. */ { int fd; if ((fd= open("/dev/tty", O_RDONLY)) != -1) { /* We have a controlling tty! Disconnect. */ close(fd); switch(fork()) { case -1: fatal("can't fork"); case 0: break; default: exit(0); } if ((fd= open("/dev/null", O_RDONLY)) < 0) fatal("/dev/null"); dup2(fd, 0); close(fd); if ((fd= open(LOG, O_WRONLY)) < 0) fatal(LOG); dup2(fd, 1); dup2(fd, 2); close(fd); setsid(); } getcap(); do { if ((lp= open(PRINTER, O_WRONLY)) < 0) { /* Another lpd? */ if (errno == EBUSY) exit(0); fatal(PRINTER); } while (job()) work(); close(lp); } while (job()); }
void populate_package_C(package_RC_t *p, thermal_config_t *config, double width, double height) { double s_spreader = config->s_spreader; double t_spreader = config->t_spreader; double s_sink = config->s_sink; double t_sink = config->t_sink; double c_convec = config->c_convec; double s_sub = config->s_sub; double t_sub = config->t_sub; double s_solder = config->s_solder; double t_solder = config->t_solder; double s_pcb = config->s_pcb; double t_pcb = config->t_pcb; double c_convec_sec = config->c_convec_sec; double p_sink = config->p_sink; double p_spreader = config->p_spreader; /* vertical C's of spreader and sink */ p->c_sp_per_x = getcap(p_spreader, t_spreader, (s_spreader+height) * (s_spreader-width) / 4.0); p->c_sp_per_y = getcap(p_spreader, t_spreader, (s_spreader+width) * (s_spreader-height) / 4.0); p->c_hs_c_per_x = getcap(p_sink, t_sink, (s_spreader+height) * (s_spreader-width) / 4.0); p->c_hs_c_per_y = getcap(p_sink, t_sink, (s_spreader+width) * (s_spreader-height) / 4.0); p->c_hs_per = getcap(p_sink, t_sink, (s_sink*s_sink - s_spreader*s_spreader) / 4.0); /* vertical C's to ambient (divide c_convec proportional to area) */ p->c_amb_c_per_x = C_FACTOR * c_convec / (s_sink * s_sink) * ((s_spreader+height) * (s_spreader-width) / 4.0); p->c_amb_c_per_y = C_FACTOR * c_convec / (s_sink * s_sink) * ((s_spreader+width) * (s_spreader-height) / 4.0); p->c_amb_per = C_FACTOR * c_convec / (s_sink * s_sink) * ((s_sink*s_sink - s_spreader*s_spreader) / 4.0); /* vertical C's of package substrate, solder balls, and PCB */ p->c_sub_per_x = getcap(SPEC_HEAT_SUB, t_sub, (s_sub+height) * (s_sub-width) / 4.0); p->c_sub_per_y = getcap(SPEC_HEAT_SUB, t_sub, (s_sub+width) * (s_sub-height) / 4.0); p->c_solder_per_x = getcap(SPEC_HEAT_SOLDER, t_solder, (s_solder+height) * (s_solder-width) / 4.0); p->c_solder_per_y = getcap(SPEC_HEAT_SOLDER, t_solder, (s_solder+width) * (s_solder-height) / 4.0); p->c_pcb_c_per_x = getcap(SPEC_HEAT_PCB, t_pcb, (s_solder+height) * (s_solder-width) / 4.0); p->c_pcb_c_per_y = getcap(SPEC_HEAT_PCB, t_pcb, (s_solder+width) * (s_solder-height) / 4.0); p->c_pcb_per = getcap(SPEC_HEAT_PCB, t_pcb, (s_pcb*s_pcb - s_solder*s_solder) / 4.0); /* vertical C's to ambient at PCB (divide c_convec_sec proportional to area) */ p->c_amb_sec_c_per_x = C_FACTOR * c_convec_sec / (s_pcb * s_pcb) * ((s_solder+height) * (s_solder-width) / 4.0); p->c_amb_sec_c_per_y = C_FACTOR * c_convec_sec / (s_pcb * s_pcb) * ((s_solder+width) * (s_solder-height) / 4.0); p->c_amb_sec_per = C_FACTOR * c_convec_sec / (s_pcb * s_pcb) * ((s_pcb*s_pcb - s_solder*s_solder) / 4.0); }
/* creates 2 matrices: invA, C: dT + A^-1*BT = A^-1*Power, * C = A^-1 * B. note that A is a diagonal matrix (no lateral * capacitances. all capacitances are to ground). also note that * it is stored as a 1-d vector. so, for computing the inverse, * inva[i] = 1/a[i] is just enough. */ void populate_C_model_block(block_model_t *model, flp_t *flp) { /* shortcuts */ double *inva = model->inva, **c = model->c; double **b = model->b; double *a = model->a; double t_chip = model->config.t_chip; double c_convec = model->config.c_convec; double s_sink = model->config.s_sink; double t_sink = model->config.t_sink; double t_spreader = model->config.t_spreader; double t_interface = model->config.t_interface; double p_chip = model->config.p_chip; double p_sink = model->config.p_sink; double p_spreader = model->config.p_spreader; double p_interface = model->config.p_interface; double c_amb; double w_chip, l_chip; int i, n = flp->n_units; if (!model->r_ready) fatal("R model not ready\n"); if (model->flp != flp || model->n_units != flp->n_units || model->n_nodes != NL * flp->n_units + EXTRA) fatal("different floorplans for R and C models!\n"); w_chip = get_total_width (flp); /* x-axis */ l_chip = get_total_height (flp); /* y-axis */ /* package C's */ populate_package_C(&model->pack, &model->config, w_chip, l_chip); /* functional block C's */ for (i = 0; i < n; i++) { double area = (flp->units[i].height * flp->units[i].width); /* C's from functional units to ground */ a[i] = getcap(p_chip, t_chip, area); /* C's from interface portion of the functional units to ground */ a[IFACE*n+i] = getcap(p_interface, t_interface, area); /* C's from spreader portion of the functional units to ground */ a[HSP*n+i] = getcap(p_spreader, t_spreader, area); /* C's from heatsink portion of the functional units to ground */ /* vertical C to ambient: divide c_convec proportional to area */ c_amb = C_FACTOR * c_convec / (s_sink * s_sink) * area; a[HSINK*n+i] = getcap(p_sink, t_sink, area) + c_amb; } /* C's from peripheral(n,s,e,w) nodes */ /* from peripheral spreader nodes to ground */ a[NL*n+SP_N] = a[NL*n+SP_S] = model->pack.c_sp_per_y; a[NL*n+SP_E] = a[NL*n+SP_W] = model->pack.c_sp_per_x; /* from center peripheral sink nodes to ground * NOTE: this treatment of capacitances (and * the corresponding treatment of resistances * in populate_R_model) as parallel (series) * is only approximate and is done in order * to avoid creating an extra layer of nodes */ a[NL*n+SINK_C_N] = a[NL*n+SINK_C_S] = model->pack.c_hs_c_per_y + model->pack.c_amb_c_per_y; a[NL*n+SINK_C_E] = a[NL*n+SINK_C_W] = model->pack.c_hs_c_per_x + model->pack.c_amb_c_per_x; /* from outer peripheral sink nodes to ground */ a[NL*n+SINK_N] = a[NL*n+SINK_S] = a[NL*n+SINK_E] = a[NL*n+SINK_W] = model->pack.c_hs_per + model->pack.c_amb_per; /* calculate A^-1 (for diagonal matrix A) such that A(dT) + BT = POWER */ for (i = 0; i < NL*n+EXTRA; i++) inva[i] = 1.0/a[i]; /* we are always going to use the eqn dT + A^-1 * B T = A^-1 * POWER. so, store C = A^-1 * B */ diagmatmult(c, inva, b, NL*n+EXTRA); /* done */ model->c_ready = TRUE; }
int cinit() { /* we need tty capability for the <cr> input */ return (ttycap = getcap("TTY")) != NILCAP; }