int main(int argc, char **argv) { int to; IBS = 256 * 1024; if ((IB = (char *) malloc((size_t) IBS)) == NULL) { printf("\n\nCan not allocate buffer with %d size...", IBS); fflush(stdout); return (0); } Version[0] = '\0'; Serial[0] = '\0'; Serial[4] = '\0'; IBCP = 0; #ifdef COMM_DEBUG printf("\nMemory allocated for %d bytes at %x", IBS, IB); fflush(stdout); #endif SetUpSignals(); zerotime(); printf("\n... Opening port"); fflush(stdout); if (OpenAndConfigurePort()) { return 1; } gettime(); printf("\n%6d : Port opened. (%d)", curtime, Port); fflush(stdout); printf("\n... Clearing buffer"); fflush(stdout); sprintf(Message, "\015\015\015"); WriteToPort(Message); printf("\n... Sending Version Request"); fflush(stdout); sprintf(Message, "V\015"); // get version WriteToPort(Message); to = 1000000; while (to) { if (Poll()) { if (Version[0] != '\0') to = 1; } --to; } gettime(); printf("\n%6d : Version = HW : %c.%c SW : %c.%c", curtime, Version[0], Version[1], Version[2], Version[3]); fflush(stdout); printf("\n... Sending Serial Request"); fflush(stdout); sprintf(Message, "N\015"); // get Serial WriteToPort(Message); to = 1000000; while (to) { if (Poll()) { if (Serial[0] != '\0') to = 1; } --to; } printf("\n%6d : Serial ID = %s ( %02x:%02x:%02x:%02x )", curtime, Serial, Serial[0], Serial[1], Serial[2], Serial[3]); fflush(stdout); // When I need to switch from 230K to 115K and wise versa, I uncomment the #def on this one and change U1/U2... //#define SET_NEW_UART_SPEED 1 #ifdef SET_NEW_UART_SPEED CRSignal = 0; sprintf(Message, "U1\015"); // UART with U0=230K, U1=115.2K U2=57.6K WriteToPort(Message); to = 1000000; while (to) { if (Poll()) { if (CRSignal) to = 1; } --to; } if (CRSignal) printf("Set Successfully..."); fflush(stdout); GoodBye(); return; #endif CRSignal = 0; sprintf(Message, "S6\015"); // CAN with 500Kbps S0-10 S1-20 S2-50 S3-100 S4-125 S5-250 S7-800 S8-1M WriteToPort(Message); to = 1000000; while (to) { if (Poll()) { if (CRSignal) to = 1; } --to; } printf("\nCAN speed setup."); fflush(stdout); // The below needs to be done only once... #if 0 CRSignal = 0; sprintf(Message, "X1\015"); // Turn on out poll WriteToPort(Message); to = 1000000; while (to) { if (Poll()) { if (CRSignal) to = 1; } --to; } printf("\nAuto Poll setup."); fflush(stdout); #endif CRSignal = 0; sprintf(Message, "O\015"); // Open the CAN channel WriteToPort(Message); to = 1000000; while (to) { if (Poll()) { if (CRSignal) to = 1; } --to; } printf("\nChannel opened."); fflush(stdout); CRSignal = 0; sprintf(Message, "t0000\015"); // Send 0 byte message to test CAN WriteToPort(Message); to = 1000000; while (to) { if (Poll()) { if (CRSignal) to = 1; } --to; } printf("\nBogus message sent, waiting 5 sec., check red LED, should be lit..."); fflush(stdout); sleep(5); CRSignal = 0; sprintf(Message, "F\015"); // Get Status WriteToPort(Message); to = 1000000; while (to) { if (Poll()) { if (CRSignal) to = 1; } --to; } printf("\nStatus Flag = %02x", StatusFlag); fflush(stdout); to = 1000; while (to) { if (Poll()) { } --to; } GoodBye(); printf("\n\n"); fflush(stdout); return 0; }
static int cpustat(void) { cpc_setgrp_t *accum; cpc_set_t *start; int c, i, retval; int lwps = 0; psetid_t mypset, cpupset; char *errstr; cpc_buf_t **data1, **data2, **scratch; int nreqs; kstat_ctl_t *kc; ncpus = (int)sysconf(_SC_NPROCESSORS_CONF); if ((gstate = calloc(ncpus, sizeof (*gstate))) == NULL) { (void) fprintf(stderr, gettext( "%s: out of heap\n"), opts->pgmname); return (1); } max_chip_id = sysconf(_SC_CPUID_MAX); if ((chip_designees = malloc(max_chip_id * sizeof (int))) == NULL) { (void) fprintf(stderr, gettext( "%s: out of heap\n"), opts->pgmname); return (1); } for (i = 0; i < max_chip_id; i++) chip_designees[i] = -1; if (smt) { if ((kc = kstat_open()) == NULL) { (void) fprintf(stderr, gettext( "%s: kstat_open() failed: %s\n"), opts->pgmname, strerror(errno)); return (1); } } if (opts->dosoaker) if (priocntl(0, 0, PC_GETCID, &fxinfo) == -1) { (void) fprintf(stderr, gettext( "%s: couldn't get FX scheduler class: %s\n"), opts->pgmname, strerror(errno)); return (1); } /* * Only include processors that are participating in the system */ for (c = 0, i = 0; i < ncpus; c++) { switch (p_online(c, P_STATUS)) { case P_ONLINE: case P_NOINTR: if (smt) { gstate[i].chip_id = get_chipid(kc, c); if (gstate[i].chip_id != -1 && chip_designees[gstate[i].chip_id] == -1) chip_designees[gstate[i].chip_id] = c; } gstate[i++].cpuid = c; break; case P_OFFLINE: case P_POWEROFF: case P_FAULTED: case P_SPARE: gstate[i++].cpuid = -1; break; default: gstate[i++].cpuid = -1; (void) fprintf(stderr, gettext("%s: cpu%d in unknown state\n"), opts->pgmname, c); break; case -1: break; } } /* * Examine the processor sets; if we're in one, only attempt * to report on the set we're in. */ if (pset_bind(PS_QUERY, P_PID, P_MYID, &mypset) == -1) { errstr = strerror(errno); (void) fprintf(stderr, gettext("%s: pset_bind - %s\n"), opts->pgmname, errstr); } else { for (i = 0; i < ncpus; i++) { struct tstate *this = &gstate[i]; if (this->cpuid == -1) continue; if (pset_assign(PS_QUERY, this->cpuid, &cpupset) == -1) { errstr = strerror(errno); (void) fprintf(stderr, gettext("%s: pset_assign - %s\n"), opts->pgmname, errstr); continue; } if (mypset != cpupset) this->cpuid = -1; } } if (opts->dotitle) print_title(opts->master); zerotime(); for (i = 0; i < ncpus; i++) { struct tstate *this = &gstate[i]; if (this->cpuid == -1) continue; this->sgrp = cpc_setgrp_clone(opts->master); if (this->sgrp == NULL) { this->cpuid = -1; continue; } if (thr_create(NULL, 0, gtick, this, THR_BOUND|THR_NEW_LWP, &this->tid) == 0) lwps++; else { (void) fprintf(stderr, gettext("%s: cannot create thread for cpu%d\n"), opts->pgmname, this->cpuid); this->status = 4; } } if (lwps != 0) for (i = 0; i < ncpus; i++) (void) thr_join(gstate[i].tid, NULL, NULL); if ((accum = cpc_setgrp_clone(opts->master)) == NULL) { (void) fprintf(stderr, gettext("%s: out of heap\n"), opts->pgmname); return (1); } retval = 0; for (i = 0; i < ncpus; i++) { struct tstate *this = &gstate[i]; if (this->cpuid == -1) continue; cpc_setgrp_accum(accum, this->sgrp); cpc_setgrp_free(this->sgrp); this->sgrp = NULL; if (this->status != 0) retval = 1; } cpc_setgrp_reset(accum); start = cpc_setgrp_getset(accum); do { nreqs = cpc_setgrp_getbufs(accum, &data1, &data2, &scratch); print_total(lwps, *data1, nreqs, cpc_setgrp_getname(accum)); } while (cpc_setgrp_nextset(accum) != start); cpc_setgrp_free(accum); accum = NULL; free(gstate); return (retval); }