예제 #1
0
/****f* spin1_api.c/spin1_callback_on
*
* SUMMARY
*  This function sets the given callback to be scheduled on occurrence of the
*  specified event. The priority argument dictates the order in which
*  callbacks are executed by the scheduler.
*
* SYNOPSIS
*  void spin1_callback_on(uchar event_id, callback_t cback, int priority)
*
* INPUTS
*  uint event_id: event for which callback should be enabled
*  callback_t cback: callback function
*  int priority:   0 = non-queueable callback (associated to irq)
*                > 0 = queueable callback
*                < 0 = preeminent callback (associated to fiq)
*
* SOURCE
*/
void spin1_callback_on (uint event_id, callback_t cback, int priority)
{
  callback[event_id].cback = cback;
  callback[event_id].priority = priority;

  // Enforce a single callback on FIQ

  if (priority < 0)
  {
    if (fiq_event == -1)
      fiq_event = event_id;
    else
      rt_error (RTE_API);
  }

  // Enforce same interrupt handler for both packet callbacks

  if (event_id == MC_PACKET_RECEIVED || event_id == MCPL_PACKET_RECEIVED)
    {
      if (pkt_prio == -2)
	pkt_prio = priority;
      else if (pkt_prio == -1 && priority != -1)
	rt_error (RTE_API);
    }
}
예제 #2
0
// Entry point
void c_main(void) {

    // Initialise
    uint32_t timer_period = 0;
    if (!initialize(&timer_period)) {
        log_error("Error in initialisation - exiting!");
         rt_error(RTE_SWERR);
    }

    // Start the time at "-1" so that the first tick will be 0
    time = UINT32_MAX;

    // Initialize the incoming spike buffer
    if (!in_spikes_initialize_spike_buffer(256)) {
         rt_error(RTE_SWERR);
    }

    // Set timer tick (in microseconds)
    spin1_set_timer_tick(timer_period);

    // Register callbacks
    spin1_callback_on(MC_PACKET_RECEIVED, incoming_spike_callback, -1);
    spin1_callback_on(USER_EVENT, spike_process, 1);
    spin1_callback_on(TIMER_TICK, timer_callback, 2);

    log_info("Starting");
    simulation_run();
}
예제 #3
0
static void
fpe_catch(FPE_ARGS)
{
    FPE_DECL;

#if defined(NOINFO_SIGFPE)
    rt_error("floating point exception, probably overflow");
    /* does not return */
#else

    switch (why) {
#ifdef FPE_FLTDIV
    case FPE_FLTDIV:
	rt_error("floating point division by zero");
#endif

#ifdef FPE_FLTOVF
    case FPE_FLTOVF:
	rt_error("floating point overflow");
#endif

#ifdef FPE_FLTUND
    case FPE_FLTUND:
	rt_error("floating point underflow");
#endif

    default:
	rt_error("floating point exception");
    }
#endif /* noinfo_sigfpe */
}
예제 #4
0
파일: ljg.cpp 프로젝트: Cell-veto/postlhc
    void set_parameter (string_ref name, double value)
    {
        if (! (value > 0.))
            rt_error ("Invalid " + name + " value");

        if (name == "temperature")
            inv_temperature = 1./value;
        else if (name == "inv_temperature")
            inv_temperature = value;
        else if (name == "cutoff")
            cutoff = value;
        else if (name == "gauss_epsilon")
            gauss_epsilon = value;
        else if (name == "gauss_r0")
            gauss_r0 = value;
        else if (name == "gauss_sigma_sq")
            gauss_sigma_sq = value;
        else
            rt_error ("Invalid parameter: " + name);

        if (gauss_r0 < LJ_MINIMUM || cutoff < gauss_r0)
            std::cerr << "Code is not correct in this regime" << ABORT;

        // precompute some interesting quantities
        lj_at_cutoff = evaluate_lj (sq (cutoff));
        pref_g = -.5 / gauss_sigma_sq;
        g_at_cutoff = evaluate_g (sq (cutoff));
        g_at_origin = evaluate_g (sq (0.));
    }
예제 #5
0
파일: lj.hpp 프로젝트: Cell-veto/postlhc
    void set_parameter (string_ref name, double value)
    {
        if (! (value > 0.))
            rt_error ("Invalid " + name + " value");

        if (name == "strength")
            strength = value;
        else if (name == "scale")
            scale = value;
        else if (name == "cutoff")
            cutoff = value;
        else if (name == "sr_lr_split")
            sr_lr_split = value;
        else
            rt_error ("Invalid parameter: " + name);

        // after changing any parameters, the prober _must_ be re-initialized.
        prober.clear ();

        // precompute some interesting quantities
        rep_cutoff  = fmin (LJ_MINIMUM, cutoff, sr_lr_split);
        attr_cutoff = fmin (cutoff, sr_lr_split);
        lj_at_cutoff = evaluate_lj (sq (attr_cutoff));
        if (sr_lr_split > cutoff)
            probe_prefactor = 0.;
        else
            probe_prefactor = strength * 6.0001 * pow6 (scale)
                * fmax (1, fabs (2 / pow6 (sr_lr_split) - 1));
    }
예제 #6
0
int
matherr(struct exception *e)
{
    char *error = "?";

    switch (e->type) {
    case DOMAIN:
    case SING:
	error = "domain error";
	break;

    case OVERFLOW:
	error = "overflow";
	break;

    case TLOSS:
    case PLOSS:
	error = "loss of significance";
	break;

    case UNDERFLOW:
	e->retval = 0.0;
	return 1;		/* ignore it */
    }

    if (strcmp(e->name, "atan2") == 0)
	rt_error("atan2(%g,%g) : %s",
		 e->arg1, e->arg2, error);
    else
	rt_error("%s(%g) : %s", e->name, e->arg1, error);

    /* won't get here */
    return 0;
}
예제 #7
0
void AbstractCorrelator::savetxt (string_ref filename)
{
    std::ofstream ofs (filename);
    if (!ofs)
        rt_error ("cannot open file: " + filename);
    savetxt (ofs);
    if (!ofs)
        rt_error ("error writing data: " + filename);
    ofs.close ();
    if (!ofs)
        rt_error ("error writing data (2): " + filename);
}
예제 #8
0
파일: c_main.c 프로젝트: lmateev/sPyNNaker
//! \brief The entry point for this model.
void c_main(void) {

    // Load DTCM data
    uint32_t timer_period;

    // initialise the model
    if (!initialise(&timer_period)){
        rt_error(RTE_API);
    }

    // Start the time at "-1" so that the first tick will be 0
    time = UINT32_MAX;

    // Set timer tick (in microseconds)
    log_info("setting timer tick callback for %d microseconds",
              timer_period);
    spin1_set_timer_tick(timer_period);

    // Set up the timer tick callback (others are handled elsewhere)
    spin1_callback_on(TIMER_TICK, timer_callback, TIMER_AND_BUFFERING);

    // Set up callback listening to SDP messages
    simulation_register_simulation_sdp_callback(
        &simulation_ticks, &infinite_run, SDP_AND_DMA_AND_USER);

    // set up provenance registration
    simulation_register_provenance_callback(
        c_main_store_provenance_data, PROVENANCE_DATA_REGION);

    simulation_run();
}
//! \brief runs any functions needed at resume time.
//! \return None
void resume_callback() {
    recording_reset();

    address_t address = data_specification_get_data_address();

    if (!read_poisson_parameters(
            data_specification_get_region(POISSON_PARAMS, address))){
        log_error("failed to reread the Poisson parameters from SDRAM");
        rt_error(RTE_SWERR);
    }

    // Loop through slow spike sources and initialise 1st time to spike
    for (index_t s = 0; s < global_parameters.n_spike_sources; s++) {
        if (!poisson_parameters[s].is_fast_source &&
                poisson_parameters[s].time_to_spike_ticks == 0) {
            poisson_parameters[s].time_to_spike_ticks =
                slow_spike_source_get_time_to_spike(
                    poisson_parameters[s].mean_isi_ticks);
        }
    }

    log_info("Successfully resumed Poisson spike source at time: %u", time);

    // print spike sources for debug purposes
    // print_spike_sources();
}
예제 #10
0
static inline void _mark_spike(uint32_t neuron_id, uint32_t n_spikes) {
    if (recording_flags > 0) {
        if (n_spike_buffers_allocated < n_spikes) {
            uint32_t new_size = 8 + (n_spikes * spike_buffer_size);
            timed_out_spikes *new_spikes = (timed_out_spikes *) spin1_malloc(
                new_size);
            if (new_spikes == NULL) {
                log_error("Cannot reallocate spike buffer");
                rt_error(RTE_SWERR);
            }
            uint32_t *data = (uint32_t *) new_spikes;
            for (uint32_t n = new_size >> 2; n > 0; n--) {
                data[n - 1] = 0;
            }
            if (spikes != NULL) {
                uint32_t old_size =
                    8 + (n_spike_buffers_allocated * spike_buffer_size);
                spin1_memcpy(new_spikes, spikes, old_size);
                sark_free(spikes);
            }
            spikes = new_spikes;
            n_spike_buffers_allocated = n_spikes;
        }
        if (spikes->n_buffers < n_spikes) {
            spikes->n_buffers = n_spikes;
        }
        for (uint32_t n = n_spikes; n > 0; n--) {
            bit_field_set(_out_spikes(n - 1), neuron_id);
        }
    }
예제 #11
0
파일: c_main.c 프로젝트: lmateev/sPyNNaker
void resume_callback() {
    // restart the recording status
    if (!initialise_recording()) {
        log_error("Error setting up recording");
        rt_error(RTE_SWERR);
    }
}
예제 #12
0
void c_main(void) {
    sark_cpu_state(CPU_STATE_RUN);

    // Register each of the components
    register_connection_generators();
    register_param_generators();

    // Get the addresses of the regions
    log_info("Starting To Build Delays");
    address_t core_address = data_specification_get_data_address();
    address_t delay_params_address = data_specification_get_region(
        DELAY_PARAMS, core_address);
    address_t params_address = data_specification_get_region(
        EXPANDER_REGION, core_address);
    log_info("\tReading SDRAM delay params at 0x%08x,"
            " expander params at 0x%08x",
            delay_params_address, params_address);

    // Run the expander
    if (!read_sdram_data(
            (address_t) delay_params_address, (address_t) params_address)) {
        log_info("!!!   Error reading SDRAM data   !!!");
        rt_error(RTE_ABORT);
    }

    log_info("Finished On Machine Delays!");
}
// Entry point
void c_main(void) {

    // Initialise
    uint32_t timer_period = 0;
    if (!initialize(&timer_period)) {
        log_error("Error in initialisation - exiting!");
        rt_error(RTE_SWERR);
    }

    // Initialise the incoming spike buffer
    if (!in_spikes_initialize_spike_buffer(8192)) {
        return;
    }

    // Set timer_callback
    spin1_set_timer_tick(timer_period);

    // Register callbacks
    spin1_callback_on(MC_PACKET_RECEIVED, incoming_spike_callback, MC);
    spin1_callback_on(TIMER_TICK, timer_callback, TIMER);

    // Start the time at "-1" so that the first tick will be 0
    time = UINT32_MAX;
    simulation_run(timer_callback, TIMER);
}
예제 #14
0
static void
fplib_err(
	     char *fname,
	     double val,
	     char *error)
{
    rt_error("%s(%g) : %s", fname, val, error);
}
예제 #15
0
static void
out_of_mem()
{
   static char out[] = "out of memory" ;

   if (mawk_state == EXECUTION)	 rt_error(out) ;
   else
   {
      /* I don't think this will ever happen */
      compile_error(out) ; mawk_exit(2) ; 
   }
}
예제 #16
0
/*
 * convert a double d to a field index	$d -> $i
 *
 * Note: this used to return (unsigned) d_to_I(d), but is done inline to
 * aid static analysis.
 */
static UInt
d_to_index(double d)
{
    if (d >= Max_Int) {
	return (UInt) Max_Int;
    } else if (d >= 0.0) {
	return (UInt) (Int) (d);
    } else {
	/* might include nan */
	rt_error("negative field index $%.6g", d);
	return 0;		/* shutup */
    }
}
예제 #17
0
/* convert a double d to a field index	$d -> $i */
static int
d_to_index(double d)
{
    if (d > MAX_FIELD)
	rt_overflow("maximum number of fields", MAX_FIELD);

    if (d >= 0.0)
	return (int) d;

    /* might include nan */
    rt_error("negative field index $%.6g", d);
    return 0;			/* shutup */
}
예제 #18
0
파일: ipl.cpp 프로젝트: Cell-veto/postlhc
 void set_parameter (string_ref name, double value)
 {
     if (name == "cutoff")
     {
         assert (value > 0.);
         sr_lr_split = value;
     }
     else if (name == "sr_lr_split")
     {
         rt_error ("Invalid parameter sr_lr_split for truncated IPL");
     }
     else
     {
         PowerLawInteraction::set_parameter (name, value);
     }
 }
예제 #19
0
CELL *
bi_atan2(CELL * sp)
{
#if  !	STDC_MATHERR
    sp--;
    if (TEST2(sp) != TWO_DOUBLES)
	cast2_to_d(sp);
    sp->dval = atan2(sp->dval, (sp + 1)->dval);
    return sp;
#else

    errno = 0;
    sp--;
    if (TEST2(sp) != TWO_DOUBLES)
	cast2_to_d(sp);
    sp->dval = atan2(sp->dval, (sp + 1)->dval);
    if (errno)
	rt_error("atan2(0,0) : domain error");
    return sp;
#endif
}
예제 #20
0
void event_register_pkt(uint queue_size, vic_slot slot)
{
    if (queue_size <= 256 &&
            (queue_size & (queue_size - 1)) == 0 &&
            slot <= SLOT_MAX &&
            vic[VIC_CNTL + slot] == 0) {
        event.pkt_queue = sark_alloc(queue_size, sizeof(pkt_t));

        if (event.pkt_queue != NULL) {
            event.pkt_insert = 1;
            event.pkt_size = queue_size;

            sark_vic_set(slot, CC_TNF_INT, 0, txpkt_int_han);

            cc[CC_TCR] = PKT_MC;

            return;
        }
    }

    rt_error(RTE_PKT);
}
예제 #21
0
void
cast1_to_d(CELL * cp)
{
    switch (cp->type) {
    case C_NOINIT:
	cp->dval = 0.0;
	break;

    case C_DOUBLE:
	return;

    case C_MBSTRN:
    case C_STRING:
	{
	    register STRING *s = (STRING *) cp->ptr;

#ifdef FPE_TRAPS_ON		/* look for overflow error */
	    errno = 0;
	    cp->dval = strtod(s->str, (char **) 0);
	    if (errno && cp->dval != 0.0)	/* ignore underflow */
		rt_error("overflow converting %s to double", s->str);
#else
	    cp->dval = strtod(s->str, (char **) 0);
#endif
	    free_STRING(s);
	}
	break;

    case C_STRNUM:
	/* don't need to convert, but do need to free the STRING part */
	free_STRING(string(cp));
	break;

    default:
	bozo("cast on bad type");
    }
    cp->type = C_DOUBLE;
}
예제 #22
0
CELL *
bi_atan2(CELL *sp)
{
    TRACE_FUNC("bi_atan2", sp);

#if  !	STDC_MATHERR
    sp--;
    if (TEST2(sp) != TWO_DOUBLES)
	cast2_to_d(sp);
    sp->dval = atan2(sp->dval, (sp + 1)->dval);
#else
    {
	errno = 0;
	sp--;
	if (TEST2(sp) != TWO_DOUBLES)
	    cast2_to_d(sp);
	sp->dval = atan2(sp->dval, (sp + 1)->dval);
	if (errno)
	    rt_error("atan2(0,0) : domain error");
    }
#endif
    return_CELL("bi_atan2", sp);
}
예제 #23
0
//! \brief The entry point for this model.
void c_main(void) {

    // Load DTCM data
    uint32_t timer_period;

    // initialise the model
    if (!initialize(&timer_period)){
        rt_error(RTE_API);
    }

    // Start the time at "-1" so that the first tick will be 0
    time = UINT32_MAX;

    // Set timer tick (in microseconds)
    log_info("setting timer tic callback for %d microseconds",
              timer_period);
    spin1_set_timer_tick(timer_period);

    // Set up the timer tick callback (others are handled elsewhere)
    spin1_callback_on(TIMER_TICK, timer_callback, 2);

    log_info("Starting");
    simulation_run();
}
예제 #24
0
void
fpcheck(void)
{
    register int fperrval;
    char *errdesc;

    if ((fperrval = iserr()) == 0)
	return;			/* no error */

    errdesc = (char *) 0;

    if (fperrval & INFNAN)
	errdesc = "arg is infinity or NAN";
    else if (fperrval & ZERODIV)
	errdesc = "division by zero";
    else if (fperrval & OVFLOW)
	errdesc = "overflow";
    else if (fperrval & UFLOW) {
	;			/* ignored */
    }

    if (errdesc)
	rt_error("%s", errdesc);
}
예제 #25
0
/*
 * Find a file on file_list.  Outputs return a FILE*, while inputs return FIN*.
 */
PTR
file_find(STRING * sval, int type)
{
    PTR result = 0;
    FILE_NODE *p;
    FILE_NODE *q;
    char *name = sval->str;

    TRACE(("file_find(%s, %d)\n", name, type));
    for (q = 0, p = file_list; p != 0; q = p, p = p->link) {
	/* search is by name and type */
	if (strcmp(name, p->name->str) == 0 &&
	    (p->type == type ||
	/* no distinction between F_APPEND and F_TRUNC here */
	     (p->type >= F_APPEND && type >= F_APPEND))) {
	    if (q != 0) {
		/* delete from list for move to front */
		q->link = p->link;
	    }
	    break;		/* while loop */
	}
    }

    if (!p) {
	/* open a new one */
	p = alloc_filenode();

	switch (p->type = (short) type) {
	case F_TRUNC:
	    if (!(p->ptr = (PTR) tfopen(name, BinMode2("wb", "w"))))
		output_failed(name);
	    break;

	case F_APPEND:
	    if (!(p->ptr = (PTR) tfopen(name, BinMode2("ab", "a"))))
		output_failed(name);
	    break;

	case F_IN:
	    p->ptr = (PTR) FINopen(name, 0);
	    break;

	case PIPE_OUT:
	case PIPE_IN:

#if    defined(HAVE_REAL_PIPES) || defined(HAVE_FAKE_PIPES)

	    if (!(p->ptr = get_pipe(name, type, &p->pid))) {
		if (type == PIPE_OUT)
		    output_failed(name);
	    }
#else
	    rt_error("pipes not supported");
#endif
	    break;

#ifdef	DEBUG
	default:
	    bozo("bad file type");
#endif
	}
    } else if (p->ptr == 0 && type == F_IN) {
	p->ptr = (PTR) FINopen(name, 0);
    }

    /* put p at the front of the list */
    if (p->ptr == 0) {
	free_filenode(p);
    } else {
	if (p != file_list) {
	    p->link = file_list;
	    file_list = p;
	}
	/* successful open */
	p->name = sval;
	sval->ref_cnt++;
	TRACE(("-> %p\n", p->ptr));
	result = p->ptr;
    }
    return result;
}
예제 #26
0
/*
 * Note: caller must do CELL cleanup.
 * The format parameter is modified, but restored.
 *
 * This routine does both printf and sprintf (if fp==0)
 */
static STRING *
do_printf(
         FILE *fp,
         char *format,
         unsigned argcnt,    /* number of args on eval stack */
         CELL *cp)        /* ptr to an array of arguments
                   (on the eval stack) */
{
    char save;
    char *p;
    register char *q = format;
    register char *target;
    int l_flag, h_flag;        /* seen %ld or %hd  */
    int ast_cnt;
    int ast[2];
    UInt Uval = 0;
    Int Ival = 0;
    int sfmt_width, sfmt_prec, sfmt_flags, s_format;
    int num_conversion = 0;    /* for error messages */
    const char *who;        /*ditto */
    int pf_type = 0;        /* conversion type */
    PRINTER printer;        /* pts at fprintf() or sprintf() */
    STRING onechr;

#ifdef     SHORT_INTS
    char xbuff[256];        /* splice in l qualifier here */
#endif

    if (fp == (FILE *) 0) {    /* doing sprintf */
    target = sprintf_buff;
    printer = (PRINTER) sprintf;
    who = "sprintf";
    } else {            /* doing printf */
    target = (char *) fp;    /* will never change */
    printer = (PRINTER) fprintf;
    who = "printf";
    }

    while (1) {
    if (fp) {        /* printf */
        while (*q != '%') {
        if (*q == 0) {
            if (ferror(fp))
            write_error();
            /* return is ignored */
            return (STRING *) 0;
        } else {
            putc(*q, fp);
            q++;
        }
        }
    } else {        /* sprintf */
        while (*q != '%') {
        if (*q == 0) {
            if (target > sprintf_limit)        /* damaged */
            {
            /* hope this works */
            rt_overflow("sprintf buffer",
                    (unsigned) (sprintf_limit - sprintf_buff));
            } else {    /* really done */
            return new_STRING1(sprintf_buff,
                       (size_t) (target - sprintf_buff));
            }
        } else {
            *target++ = *q++;
        }
        }
    }

    /* *q == '%' */
    num_conversion++;

    if (*++q == '%') {    /* %% */
        if (fp)
        putc(*q, fp);
        else
        *target++ = *q;

        q++;
        continue;
    }

    /* mark the '%' with p */
    p = q - 1;

    /* eat the flags */
    while (*q == '-' || *q == '+' || *q == ' ' ||
           *q == '#' || *q == '0')
        q++;

    ast_cnt = 0;
    ast[0] = 0;
    if (*q == '*') {
        if (cp->type != C_DOUBLE)
        cast1_to_d(cp);
        ast[ast_cnt++] = d_to_i(cp++->dval);
        argcnt--;
        q++;
    } else
        while (scan_code[*(unsigned char *) q] == SC_DIGIT)
        q++;
    /* width is done */

    if (*q == '.') {    /* have precision */
        q++;
        if (*q == '*') {
        if (cp->type != C_DOUBLE)
            cast1_to_d(cp);
        ast[ast_cnt++] = d_to_i(cp++->dval);
        argcnt--;
        q++;
        } else {
        while (scan_code[*(unsigned char *) q] == SC_DIGIT)
            q++;
        }
    }

    if (argcnt <= 0)
        rt_error("not enough arguments passed to %s(\"%s\")",
             who, format);

    l_flag = h_flag = 0;

    if (*q == 'l') {
        q++;
        l_flag = 1;
    } else if (*q == 'h') {
        q++;
        h_flag = 1;
    }
    switch (*q++) {
    case 's':
        if (l_flag + h_flag)
        bad_conversion(num_conversion, who, format);
        if (cp->type < C_STRING)
        cast1_to_s(cp);
        pf_type = PF_S;
        break;

    case 'c':
        if (l_flag + h_flag)
        bad_conversion(num_conversion, who, format);

        switch (cp->type) {
        case C_NOINIT:
        Ival = 0;
        break;

        case C_STRNUM:
        case C_DOUBLE:
        Ival = d_to_I(cp->dval);
        break;

        case C_STRING:
        /* fall thru to check for bad number formats */ 
        //Ival = string(cp)->str[0];
        //break;
        /* fall thru */

        case C_FIELDWIDTHS:
        case C_MBSTRN:
        check_strnum(cp);
        Ival = ((cp->type == C_STRING)
            ? string(cp)->str[0]
            : d_to_I(cp->dval));
        break;

        default:
        bozo("printf %c");
        }
        onechr.len = 1;
        onechr.str[0] = (char) Ival;

        pf_type = PF_C;
        break;

    case 'd':
    case 'i':
        if (cp->type != C_DOUBLE)
        cast1_to_d(cp);
            Ival = d_to_I(cp->dval);
        pf_type = PF_D;
        break;

    case 'o':
    case 'x':
    case 'X':
    case 'u':
        if (cp->type != C_DOUBLE)
        cast1_to_d(cp);
        Uval = d_to_U(cp->dval);
        pf_type = PF_U;
        break;

    case 'e':
    case 'g':
    case 'f':
    case 'E':
    case 'G':
        if (h_flag + l_flag)
        bad_conversion(num_conversion, who, format);
        if (cp->type != C_DOUBLE)
        cast1_to_d(cp);
        pf_type = PF_F;
        break;

    default:
        bad_conversion(num_conversion, who, format);
    }

    save = *q;
    *q = 0;

#ifdef    SHORT_INTS
    if (pf_type == PF_D) {
        /* need to splice in long modifier */
        strcpy(xbuff, p);

        if (l_flag) /* do nothing */ ;
        else {
        int k = q - p;

        if (h_flag) {
            Ival = (short) Ival;
            /* replace the 'h' with 'l' (really!) */
            xbuff[k - 2] = 'l';
            if (xbuff[k - 1] != 'd' && xbuff[k - 1] != 'i')
            Ival &= 0xffff;
        } else {
            /* the usual case */
            xbuff[k] = xbuff[k - 1];
            xbuff[k - 1] = 'l';
            xbuff[k + 1] = 0;
        }
        }
    }
#endif

#define PUTS_C_ARGS target, fp, 0,  &onechr, sfmt_width, sfmt_prec, sfmt_flags
#define PUTS_S_ARGS target, fp, cp, 0,       sfmt_width, sfmt_prec, sfmt_flags

    /* ready to call printf() */
    s_format = 0;
    switch (AST(ast_cnt, pf_type)) {
    case AST(0, PF_C):
        /* FALLTHRU */
    case AST(1, PF_C):
        /* FALLTHRU */
    case AST(2, PF_C):
        s_format = 1;
        make_sfmt(p, ast, &sfmt_width, &sfmt_prec, &sfmt_flags);
        target = puts_sfmt(PUTS_C_ARGS);
        break;

    case AST(0, PF_S):
        /* FALLTHRU */
    case AST(1, PF_S):
        /* FALLTHRU */
    case AST(2, PF_S):
        s_format = 1;
        make_sfmt(p, ast, &sfmt_width, &sfmt_prec, &sfmt_flags);
        target = puts_sfmt(PUTS_S_ARGS);
        break;

#ifdef    SHORT_INTS
#define FMT    xbuff        /* format in xbuff */
#else
#define FMT    p        /* p -> format */
#endif
    case AST(0, PF_D):
            if (cp->dval > Max_Int && l_flag == 0
                    && h_flag == 0) {
        STRING *newp;
        char *np;
                newp = new_STRING0(strlen(p)+5);
                np = (char *) newp->str;
                while (*p != '\0') {
                    if (*p == 'd' || *p == 'i') {
                        *np++ = '.';
                        *np++ = '0';
                        *np++ = 'f';
                        ++p;
                    } else 
                        *np++ = *p++;
                }
                np = '\0';
            (*printer) ((PTR) target,  newp->str, cp->dval);
                free_STRING(newp);
            } else 
            (*printer) ((PTR) target, FMT, Ival);
        break;

    case AST(1, PF_D):
        (*printer) ((PTR) target, FMT, ast[0], Ival);
        break;

    case AST(2, PF_D):
        (*printer) ((PTR) target, FMT, ast[0], ast[1], Ival);
        break;

    case AST(0, PF_U):
            if (*(p+1) == 'u' && cp->dval > Max_Int ) {
        STRING *newp;
        char *np;
                newp = new_STRING0(strlen(p)+5);
                np = (char *) newp->str;
                while (*p != '\0') {
                    if (*p == 'u') {
                        *np++ = '.';
                        *np++ = '0';
                        *np++ = 'f';
            ++p;
                    } else 
                        *np++ = *p++;
                }
                np = '\0';
            (*printer) ((PTR) target,  newp->str, cp->dval);
                free_STRING(newp);
            } else 
            (*printer) ((PTR) target, FMT, Uval);
        break;

    case AST(1, PF_U):
        (*printer) ((PTR) target, FMT, ast[0], Uval);
        break;

    case AST(2, PF_U):
        (*printer) ((PTR) target, FMT, ast[0], ast[1], Uval);
        break;

#undef    FMT

    case AST(0, PF_F):
        (*printer) ((PTR) target, p, cp->dval);
        break;

    case AST(1, PF_F):
        (*printer) ((PTR) target, p, ast[0], cp->dval);
        break;

    case AST(2, PF_F):
        (*printer) ((PTR) target, p, ast[0], ast[1], cp->dval);
        break;
    }
    if (fp == (FILE *) 0 && !s_format) {
        while (*target)
        target++;
    }
    *q = save;
    argcnt--;
    cp++;
    }
}
예제 #27
0
void
cast2_to_d(CELL *cp)
{
    register STRING *s;

    switch (cp->type) {
    case C_NOINIT:
	cp->dval = 0.0;
	break;

    case C_DOUBLE:
	goto two;
    case C_STRNUM:
	free_STRING(string(cp));
	break;

    case C_MBSTRN:
    case C_STRING:
	s = (STRING *) cp->ptr;

	errno = 0;
#ifdef FPE_TRAPS_ON		/* look for overflow error */
	cp->dval = strtod(s->str, (char **) 0);
	if (errno && cp->dval != 0.0)	/* ignore underflow */
	    rt_error("overflow converting %s to double", s->str);
#else
	cp->dval = strtod(s->str, (char **) 0);
#endif
	free_STRING(s);
	break;

    default:
	bozo("cast on bad type");
    }
    cp->type = C_DOUBLE;

  two:
    cp++;

    switch (cp->type) {
    case C_NOINIT:
	cp->dval = 0.0;
	break;

    case C_DOUBLE:
	return;
    case C_STRNUM:
	free_STRING(string(cp));
	break;

    case C_MBSTRN:
    case C_STRING:
	s = (STRING *) cp->ptr;

	errno = 0;
#ifdef FPE_TRAPS_ON		/* look for overflow error */
	cp->dval = strtod(s->str, (char **) 0);
	if (errno && cp->dval != 0.0)	/* ignore underflow */
	    rt_error("overflow converting %s to double", s->str);
#else
	cp->dval = strtod(s->str, (char **) 0);
#endif
	free_STRING(s);
	break;

    default:
	bozo("cast on bad type");
    }
    cp->type = C_DOUBLE;
}
예제 #28
0
파일: fin.c 프로젝트: jhoughten/Ted-s-Repo
int
is_cmdline_assign(char *s)
{
    register char *p;
    int c;
    SYMTAB *stp;
    CELL *cp = 0;
    size_t len;
    CELL cell;			/* used if command line assign to pseudo field */
    CELL *fp = (CELL *) 0;	/* ditto */
    size_t length;

    if (scan_code[*(unsigned char *) s] != SC_IDCHAR)
	return 0;

    p = s + 1;
    while ((c = scan_code[*(unsigned char *) p]) == SC_IDCHAR
	   || c == SC_DIGIT)
	p++;

    if (*p != '=')
	return 0;

    *p = 0;
    stp = find(s);

    switch (stp->type) {
    case ST_NONE:
	stp->type = ST_VAR;
	stp->stval.cp = cp = ZMALLOC(CELL);
	break;

    case ST_VAR:
    case ST_NR:		/* !! no one will do this */
	cp = stp->stval.cp;
	cell_destroy(cp);
	break;

    case ST_FIELD:
	/* must be pseudo field */
	fp = stp->stval.cp;
	cp = &cell;
	break;

    default:
	rt_error(
		    "cannot command line assign to %s\n\ttype clash or keyword"
		    ,s);
    }

    /* we need to keep ARGV[i] intact */
    *p++ = '=';
    len = strlen(p) + 1;
    /* posix says escape sequences are on from command line */
    p = rm_escape(strcpy((char *) zmalloc(len), p), &length);
    cp->ptr = (PTR) new_STRING1(p, length);
    zfree(p, len);
    check_strnum(cp);		/* sets cp->type */
    if (fp)			/* move it from cell to pfield[] */
    {
	field_assign(fp, cp);
	free_STRING(string(cp));
    }
    return 1;
}
void c_main (void)
{
    int chipIDs[] = {0, 1, 256, 257};

    chipID = spin1_get_chip_id();
    coreID = spin1_get_core_id();
    spikeNumber = 0;
    //io_printf(IO_STD, "Simulation starting on (chip: %d, core: %d)...\n", chipID, coreID);

    // Set the number of chips in the simulation
    //spin1_set_core_map(64, (uint *)(0x74220000));

    // set the core map for the simulation
    //spin1_application_core_map(2, 2, core_map);
    //spin1_set_core_map(4, (uint *)(core_map));

    // initialise routing entries
    // set a MC routing table entry to send my packets back to me


    if (chipID == 0 && coreID == 1)
    {
  /* ------------------------------------------------------------------- */
  /* initialise routing entries                                          */
  /* ------------------------------------------------------------------- */
  /* set a MC routing table entry to send my packets back to me */

  io_printf(IO_STD, "Setting routing table on (chip: %d, core: %d)...\n", chipID, coreID);

   uint e = rtr_alloc (1);
   if (e == 0)
      rt_error (RTE_ABORT);

    rtr_mc_set (e,			// entry
	      0x11100001, 			// key
	      0xFFFF0001,		// mask
	      SOUTH_WEST
	      );
   e = rtr_alloc (1);
   if (e == 0)
      rt_error (RTE_ABORT);
    rtr_mc_set (e,			// entry
	      0x11100000, 			// key
	      0xFFFF0001,		// mask
	      SOUTH_WEST
	      );

   e = rtr_alloc (1);
   if (e == 0)
      rt_error (RTE_ABORT);

    rtr_mc_set (e,
        0x80000000 | 9 << 7 | 0 << 2,
        0x80000000 | 15 << 7 | 31 << 2,
        CORE(2) // core 2 handles bump sensor
        );

   e = rtr_alloc (1);
   if (e == 0)
      rt_error (RTE_ABORT);

    rtr_mc_set (e,
        0x80000000 | 9  << 7 | 4 << 2 | 2,
        0x80000000 | 15 << 7 | 31 << 2 | 3,
        CORE(3) // core 3 handles compass sensor
        );

   e = rtr_alloc (1);
   if (e == 0)
      rt_error (RTE_ABORT);

    rtr_mc_set (e,
        0x80000000 , //| 9  << 7 | 0 << 2,
        0x80000000 , //| 15 << 7 | 0 << 2,
        CORE(4) // core 4 logs data 
        );

    }

    // Call hardware and simulation configuration functions
    spin1_set_timer_tick(TIME_STEP_MICROSEC);

    if (chipID == 0 && coreID == 1) //core1 handles time-based stuff
    {
    spin1_callback_on(TIMER_TICK, timer_callback, TIMER_PRIORITY);
    }

    if (chipID == 0 && coreID == 2)
    {    
    spin1_callback_on(MCPL_PACKET_RECEIVED, bump_received, MC_PACKET_EVENT_PRIORITY);
    }
    
    if (chipID == 0 && coreID == 3)
    {
    spin1_callback_on(MC_PACKET_RECEIVED, enable_packet_received, MC_PACKET_EVENT_PRIORITY);

    }
    
    if (chipID == 0 && coreID == 4)
    {
    // Register callbacks
    spin1_callback_on(MC_PACKET_RECEIVED, multiCastPacketReceived_callback, MC_PACKET_EVENT_PRIORITY);
    spin1_callback_on(MCPL_PACKET_RECEIVED, multiCastPacketReceived_with_payload_callback, MC_PACKET_EVENT_PRIORITY);
    }

    // transfer control to the run-time kernel
    //if (chipID == 0 && coreID == 1)
    {
       spin1_start(0);


    }

}
예제 #30
0
void
field_assign(CELL * fp, CELL * cp)
{
    CELL c;
    int i, j;

    /* the most common case first */
    if (fp == field) {
	cell_destroy(field);
	cellcpy(fp, cp);
	nf = -1;
	return;
    }

    /* its not important to do any of this fast */

    if (nf < 0)
	split_field0();

#ifdef  MSDOS
    if (!SAMESEG(fp, field)) {
	i = -1;
	goto lm_dos_label;
    }
#endif

    switch (i = (int) (fp - field)) {

    case NF_field:

	cell_destroy(NF);
	cellcpy(NF, cellcpy(&c, cp));
	if (c.type != C_DOUBLE)
	    cast1_to_d(&c);

	if ((j = d_to_i(c.dval)) < 0)
	    rt_error("negative value assigned to NF");

	if (j > nf)
	    for (i = nf + 1; i <= j; i++) {
		cp = field_ptr(i);
		cell_destroy(cp);
		cp->type = C_STRING;
		cp->ptr = (PTR) & null_str;
		null_str.ref_cnt++;
	    }

	nf = j;
	build_field0();
	break;

    case RS_field:
	cell_destroy(RS);
	cellcpy(RS, cp);
	set_rs_shadow();
	break;

    case FS_field:
	cell_destroy(FS);
	cast_for_split(cellcpy(&fs_shadow, cellcpy(FS, cp)));
	break;

    case OFMT_field:
    case CONVFMT_field:
	/* If the user does something stupid with OFMT or CONVFMT,
	   we could crash.
	   We'll make an attempt to protect ourselves here.  This is
	   why OFMT and CONVFMT are pseudo fields.

	   The ptrs of OFMT and CONVFMT always have a valid STRING,
	   even if assigned a DOUBLE or NOINIT
	 */

	free_STRING(string(fp));
	cellcpy(fp, cp);
	if (fp->type < C_STRING)	/* !! */
	    fp->ptr = (PTR) new_STRING("%.6g");
	else if (fp == CONVFMT) {
	    /* It's a string, but if it's really goofy and CONVFMT,
	       it could still damage us. Test it .
	     */
	    char xbuff[512];

	    xbuff[256] = 0;
	    sprintf(xbuff, string(fp)->str, 3.1459);
	    if (xbuff[256])
		rt_error("CONVFMT assigned unusable value");
	}
	break;

#ifdef MSDOS
      lm_dos_label:
#endif

    default:			/* $1 or $2 or ... */

	cell_destroy(fp);
	cellcpy(fp, cp);

	if (i < 0 || i > MAX_SPLIT)
	    i = field_addr_to_index(fp);

	if (i > nf) {
	    for (j = nf + 1; j < i; j++) {
		cp = field_ptr(j);
		cell_destroy(cp);
		cp->type = C_STRING;
		cp->ptr = (PTR) & null_str;
		null_str.ref_cnt++;
	    }
	    nf = i;
	    cell_destroy(NF);
	    NF->type = C_DOUBLE;
	    NF->dval = (double) i;
	}

	build_field0();

    }
}