Esempio n. 1
0
void spike_process(uint unused0, uint unused1) {
    use(unused0);
    use(unused1);

    // Get current time slot of incoming spike counters
    uint32_t current_time_slot = time & num_delay_slots_mask;
    uint8_t *current_time_slot_spike_counters =
        spike_counters[current_time_slot];

    log_debug("Current time slot %u", current_time_slot);

    // Zero all counters in current time slot
    memset(current_time_slot_spike_counters, 0, sizeof(uint8_t) * num_neurons);

    // While there are any incoming spikes
    spike_t s;
    while (in_spikes_get_next_spike(&s)) {

        // Mask out neuron id
        uint32_t neuron_id = _key_n(s);
        if (neuron_id < num_neurons) {

            // Increment counter
            current_time_slot_spike_counters[neuron_id]++;
            log_debug("Incrementing counter %u = %u\n", neuron_id,
                      current_time_slot_spike_counters[neuron_id]);
        } else {
            log_debug("Invalid neuron ID %u", neuron_id);
        }
    }

    processing_spikes = false;
}
// Callbacks
void timer_callback(uint unused0, uint unused1) {
    use(unused0);
    use(unused1);
    time++;

    log_debug("Timer tick %d", time);

    if ((infinite_run != TRUE) && (time == simulation_ticks)) {
        simulation_handle_pause_resume(NULL);
        log_info("Simulation complete.\n");
        simulation_ready_to_read();
    }

    // Process the incoming spikes
    spike_t s;
    uint32_t nid;
    while (in_spikes_get_next_spike(&s)) {
        nid = (s & NEURON_ID_MASK);

        if (nid < N_COUNTERS) {
            counters[nid] += 1;
        } else {
            log_debug("Received spike from unknown neuron %d", nid);
        }
    }

    // Work out if there is any motion
    if ((time % sample_time) == 0) {

        // Do motion in pairs
        do_motion(MOTION_FORWARD, MOTION_BACK, "Forwards", "Backwards");
        do_motion(MOTION_LEFT, MOTION_RIGHT, "Left", "Right");
        do_motion(MOTION_CLOCKWISE, MOTION_C_CLOCKWISE, "Clockwise",
                  "Anti-clockwise");

        // Reset the counters
        for (uint32_t i = 0; i < N_COUNTERS; i++) {
            counters[i] = 0;
        }
    } else if ((time % update_time) == 0) {

        // Do updates in pairs
        do_update(MOTION_FORWARD, MOTION_BACK, "Forwards", "Backwards");
        do_update(MOTION_LEFT, MOTION_RIGHT, "Left", "Right");
        do_update(MOTION_CLOCKWISE, MOTION_C_CLOCKWISE, "Clockwise",
                  "Anti-clockwise");
    }
}