Exemple #1
0
void setup_timer() {
    gpio[LED_GPFSEL] |= (1 << LED_GPFBIT);
    irq_controller()->enable_basic_irqs = IRQ_BASIC_ARM_TIMER;
    arm_timer()->load = 0x400;
    arm_timer()->control = ARM_TIMER_CTRL_23BIT
                         | ARM_TIMER_CTRL_ENABLE
                         | ARM_TIMER_CTRL_INT_ENABLE
                         | ARM_TIMER_CTRL_PRESCALE_256;
    enable_irq();
}
compressed_data
persistence_sqlite::retrieve (data_type type, chunk_coordinates xyz)
{
    boost::mutex::scoped_lock l (lock);

    int idx (static_cast<int>(type));
    auto& query (read_[idx]);

    arm_timer();
    query.reset();

    query.bind(1, xyz.x);
    query.bind(2, xyz.y);
    query.bind(3, xyz.z);

    auto rc (query.step());
    if (rc != SQLITE_DONE && rc != SQLITE_ROW)
    {
        std::stringstream msg;
        msg << "data type " << (int)type << " at " << xyz << ": " << err_str_(rc);
        throw not_in_storage_error(msg.str());
    }

    return deserialize_as<compressed_data>(query.get_blob(0));
}
Exemple #3
0
int main(void) {

  printf ("My pid is %d\n", getpid());
  printf (
   "Signal managed : SIGTALRM(intern), SIGUSR1(30), SIGUSR2(31)\n");


  set_handler (SIGALRM, handler_sigalrm, NULL);
  set_handler (SIGUSR1, handler_sigusr1, NULL);
  set_handler (SIGUSR2, handler_sigusr2, NULL);

  printf ("Start timer\n");
  arm_timer (ITIMER_REAL, (long)ALRM_S, (long)ALRM_U, 1);

  sigpause (sigmask(SIGALRM) | sigmask(SIGUSR1));
  printf ("Done.\n");
  exit(0);
}
void
persistence_sqlite::store (map_coordinates xy, chunk_height z)
{
    boost::mutex::scoped_lock l (lock);

    auto& query (write_height_);

    arm_timer();
    query.reset();

    query.bind(1, xy.x);
    query.bind(2, xy.y);
    query.bind(3, z);

    auto rc (query.step());
    if (rc != SQLITE_DONE && rc != SQLITE_OK)
        throw std::runtime_error(std::string("cannot store data : ") + err_str_(rc));
}
void
persistence_sqlite::store (data_type type, chunk_coordinates xyz,
                           const compressed_data& data)
{
    boost::mutex::scoped_lock l (lock);

    unsigned int idx (static_cast<unsigned int>(type));
    assert(idx < write_.size());
    auto& query (write_[idx]);

    arm_timer();
    query.reset();

    query.bind(1, xyz.x);
    query.bind(2, xyz.y);
    query.bind(3, xyz.z);
    query.bind(4, serialize(data));

    auto rc (query.step());
    if (rc != SQLITE_DONE && rc != SQLITE_OK)
        throw std::runtime_error(std::string("cannot store data : ") + err_str_(rc));
}
chunk_height
persistence_sqlite::retrieve (map_coordinates xy)
{
    boost::mutex::scoped_lock l (lock);

    auto& query (read_height_);

    arm_timer();
    query.reset();

    query.bind(1, xy.x);
    query.bind(2, xy.y);

    auto rc (query.step());
    if (rc != SQLITE_DONE && rc != SQLITE_ROW)
    {
        std::stringstream msg;
        msg << "coarse map height at " << xy << ": " << err_str_(rc);
        throw not_in_storage_error(msg.str());
    }

    return query.get_uint(0);
}
Exemple #7
0
void handle_time_tick(uint32_t status_reg) {
    icount++;
    if (icount & 1) {
        gpio[LED_GPCLR] = 1 << LED_GPIO_BIT;
    } else {
        gpio[LED_GPSET] = 1 << LED_GPIO_BIT;
    }
#if 1
    if (icount % 10 == 0) {
        uart_puts("ping. sp = ");
        inspect_reg("sp");
        uart_puts(", lr = ");
        inspect_reg("lr");
        uart_puts(", status_reg = ");
        puthexint(status_reg);
        uart_puts(", irq_basic_pending = ");
        puthexint(irq_controller()->irq_basic_pending);
        uart_puts(uart_newline);
    }
#else
    UNUSED(status_reg);
#endif
    arm_timer()->irq_clear = 1;
}