void RealView_timebase_init(void) { assert(gRealviewTimerBase); timer_configure(); /* disable timer */ RealView_timer_enabled(FALSE); /* set timer values and initialize decrementer */ HARDWARE_REGISTER(gRealviewTimerBase + TIMER_CONTROL) |= TIMER_MODE_FREE_RUNNING; HARDWARE_REGISTER(gRealviewTimerBase + TIMER_CONTROL) |= TIMER_SIZE_32_BIT; HARDWARE_REGISTER(gRealviewTimerBase + TIMER_CONTROL) |= TIMER_ENABLE; HARDWARE_REGISTER(gRealviewTimerBase) = clock_decrementer; /* enable irqs so we can get ahold of the timer when it decrements */ ml_set_interrupts_enabled(TRUE); /* re-enable timer */ RealView_timer_enabled(TRUE); clock_initialized = TRUE; while(!clock_had_irq) barrier(); kprintf(KPRINTF_PREFIX "RealView Timer initialized, Timer value %llu\n", RealView_timer_value()); return; }
void status_configure(unsigned int _led_pin) { counter = 0; mode = STATUS_OFF; led_pin = _led_pin; /* Configure timer2 to trigger every 100ms */ timer_power_up(TIMER_2); timer_configure(TIMER_2, TIMER2_PRESCALER_64, 6250, 1); }
static void program_scheduler_handle_process_state_change(void *opaque) { ProgramScheduler *program_scheduler = opaque; Program *program = containerof(program_scheduler, Program, scheduler); bool spawn = false; if (program_scheduler->state != PROGRAM_SCHEDULER_STATE_RUNNING) { return; } if (program_scheduler->last_spawned_process->state == PROCESS_STATE_EXITED) { if (program_scheduler->last_spawned_process->exit_code == 0) { if (program->config.start_mode == PROGRAM_START_MODE_ALWAYS) { spawn = true; } } else { if (program->config.continue_after_error) { if (program->config.start_mode == PROGRAM_START_MODE_ALWAYS) { spawn = true; } } else { program_scheduler_stop(program_scheduler, NULL); } } } else if (program_scheduler->last_spawned_process->state == PROCESS_STATE_ERROR || program_scheduler->last_spawned_process->state == PROCESS_STATE_KILLED) { if (program->config.continue_after_error) { if (program->config.start_mode == PROGRAM_START_MODE_ALWAYS) { spawn = true; } } else { program_scheduler_stop(program_scheduler, NULL); } } if (spawn) { // delay next process spawn by 1 second to avoid running into a tight // loop of process spawn and process exit events which would basically // stop redapid from doing anything else. also if the throughput between // redapid and brickv is low then sending to many program-process-spawned // callbacks might force brickv into doing nothing else but updating // the last-spawned-program-process information if (timer_configure(&program_scheduler->timer, 1000000, 0) < 0) { program_scheduler_handle_error(program_scheduler, false, "Could not start timer: %s (%d)", get_errno_name(errno), errno); return; } log_debug("Started timer for program object (identifier: %s)", program->identifier->buffer); program_scheduler->timer_active = true; } }
static void program_scheduler_stop(ProgramScheduler *program_scheduler, String *message) { static bool recursive = false; Program *program = containerof(program_scheduler, Program, scheduler); if (recursive) { return; } program_scheduler_abort_observer(program_scheduler); if (program_scheduler->timer_active) { if (timer_configure(&program_scheduler->timer, 0, 0) < 0) { recursive = true; program_scheduler_handle_error(program_scheduler, false, "Could not stop timer: %s (%d)", get_errno_name(errno), errno); recursive = false; } else { log_debug("Stopped timer for program object (identifier: %s)", program->identifier->buffer); program_scheduler->timer_active = false; } } if (program_scheduler->cron_active) { cron_remove_entry(program->base.id); log_debug("Removed cron entry for program object (identifier: %s)", program->identifier->buffer); program_scheduler->cron_active = false; } program_scheduler_set_state(program_scheduler, PROGRAM_SCHEDULER_STATE_STOPPED, time(NULL), message); }
void S5L8900X_timebase_init(void) { assert(gS5L8900XTimerBase); /* * Set rtclock stuff */ timer_configure(); /* * Disable the timer. */ S5L8900X_timer_enabled(FALSE); /* * Enable the interrupt. */ HwReg(gS5L8900XVic0Base + VICINTENABLE) = HwReg(gS5L8900XVic0Base + VICINTENABLE) | (1 << 7) | (1 << 6) | (1 << 5); /* * Enable interrupts. */ ml_set_interrupts_enabled(TRUE); /* * Wait for it. */ kprintf(KPRINTF_PREFIX "waiting for system timer to come up...\n"); S5L8900X_timer_enabled(TRUE); clock_initialized = TRUE; while (!clock_had_irq) barrier(); return; }
/** * Initializes the DBGU and ISO7816 driver, and starts some tests. * \return Unused (ANSI-C compatibility) */ extern int main( void ) { uint8_t Atr[MAX_ATR_SIZE] ; uint8_t size ; /* Disable watchdog */ wdt_disable(); /* Disable all PIO interrupts */ pio_reset_all_it(); /* Configure console */ board_cfg_console(); console_clear_screen(); console_reset_cursor(); /* Configure PIT. Must be always ON, used for delay */ printf("Configure PIT \n\r"); timer_configure(BLINK_PERIOD); printf( "-- USART ISO7816 Example %s --\n\r", SOFTPACK_VERSION ) ; printf( "-- %s\n\r", BOARD_NAME ) ; printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ; #ifdef CONFIG_HAVE_PMIC_ACT8945A pio_configure(act8945a_pins, ARRAY_SIZE(act8945a_pins)); if (act8945a_configure(&act8945a, &act8945a_twid)) { act8945a_set_regulator_voltage(&act8945a, 6, 2500); act8945a_enable_regulator(&act8945a, 6, true); } else { printf("--E-- Error initializing ACT8945A PMIC\n\r"); } #endif /* PIO configuration for LEDs */ printf("Configure LED PIOs.\n\r"); _configure_leds(); led_set(LED_BLUE); timer_wait(500); led_clear(LED_BLUE); led_status[LED_BLUE] = 1; /* PIO configuration for Button, use to simulate card detection. */ printf("Configure buttons with debouncing.\n\r"); _configure_buttons(); /* Configure Pios usart*/ pio_configure(&pins_com2[0], ARRAY_SIZE(pins_com2)); /* Init ISO7816 interface */ iso7816_init(&iso7816_desc, &iso7816_opt); /* Warm reset */ iso7816_warm_reset(&iso7816_desc); /* Read ATR */ memset( Atr, 0, sizeof(Atr) ) ; iso7816_get_data_block_ATR(&iso7816_desc, Atr, &size ); /* Decode ATR */ iso7816_decode_ATR(Atr); /* Allow user to send some commands */ _send_receive_commands(&iso7816_desc); printf("\n\r Exit App \n\r"); while (1) ; }
static void program_scheduler_start(ProgramScheduler *program_scheduler) { Program *program = containerof(program_scheduler, Program, scheduler); APIE error_code; if (program_scheduler->shutdown) { return; } // FIXME: delay scheduler start after reboot for some seconds so the system has a moment to settle program_scheduler_abort_observer(program_scheduler); program_scheduler_set_state(program_scheduler, PROGRAM_SCHEDULER_STATE_RUNNING, time(NULL), NULL); switch (program->config.start_mode) { case PROGRAM_START_MODE_NEVER: program_scheduler_stop(program_scheduler, NULL); break; case PROGRAM_START_MODE_ALWAYS: program_scheduler_spawn_process(program_scheduler); break; case PROGRAM_START_MODE_INTERVAL: if (timer_configure(&program_scheduler->timer, 0, (uint64_t)program->config.start_interval * 1000000) < 0) { program_scheduler_handle_error(program_scheduler, false, "Could not start timer: %s (%d)", get_errno_name(errno), errno); return; } log_debug("Started timer for program object (identifier: %s)", program->identifier->buffer); program_scheduler->timer_active = true; break; case PROGRAM_START_MODE_CRON: error_code = cron_add_entry(program->base.id, program->identifier->buffer, program->config.start_fields->buffer, program_scheduler_handle_cron, program_scheduler); if (error_code != API_E_SUCCESS) { program_scheduler_handle_error(program_scheduler, false, "Could not add cron entry: %s (%d)", api_get_error_code_name(error_code), error_code); return; } log_debug("Updated/added cron entry for program object (identifier: %s)", program->identifier->buffer); program_scheduler->cron_active = true; break; default: // should never be reachable program_scheduler_handle_error(program_scheduler, true, "Invalid start mode %d", program->config.start_mode); break; } }