예제 #1
0
	void on_schedule(Struct_type *page)
	{
		if (is_full())
		{
			evict_one();
		}

		new_schedule(page);
	}
예제 #2
0
/*
 * The worst case solver assigns all tasks to one processor.
 */
int
worstcase_solver(char *stg_filename, char *ssf_filename)
{
    int malloced;
    int freed;

    struct stg *tg;
    struct ssf_status *status;
    struct ssf *schedule;

    int ok;
        int tlist[] = { 2, 3, 4};

    printf("** Worst Case Solver\n");

        /* Allocate data structures. */
    malloced = 0;
    freed = 0;
        tg = new_task_graph_from_file(stg_filename, &malloced);
    status = new_status(&malloced);
    strncpy(status->name, "YASA worstcase", 20);
    schedule = new_schedule(tg, &malloced);
    printf("malloced %d bytes\n", malloced);

    /* Solve. */
    print_task_graph(tg);
    printf("twiddle. twiddle, crunch, crunch..\n");

        ok = is_tinsert_ok(tg, 1, 0, tlist);
    printf("is_tinsert_ok = %u\n", ok);

    print_schedule(schedule);
    write_schedule_to_file(ssf_filename, schedule, status);

    /* Free data structures. */
    free_schedule(schedule, &freed);
    free_status(status, &freed);
    free_task_graph(tg, &freed);
    printf("freed %d bytes => ", freed);
    if (malloced == freed)
        printf("OK.\n");
    else {
        printf("Error: malloced != freed!\n");
        return (1);
    }

    return (0);
}
예제 #3
0
	// In LRU, this will be called after is_hit(...)
	inline void update(Struct_type *page, It_type_book it)
	{
		off_schedule(it);

		new_schedule(page);
	}
예제 #4
0
int main(void) {
	watchdog_clear_status();
#ifdef USING_PRINTF
	serial_init();
#endif
	cli();
	clear_radio_strings();
	system_schedule = new_schedule();
	
	//Be aware: order may matter, especially with si4703/5_init and nokia5110_init.  (they all share a reset pin)
	watchdog_set(WD_INTERRUPT_AND_SYSTEM_RESET, WD_TIMEOUT_1_S);

	set_data_directions();
	timer0_pwm_prescaler_compare_A(0, 3, true, false);
	timer1_pwm_prescaler_compare(0, MAX_BRIGHTNESS, 1, 1, false, false);
	timer2_ctc(0.001, true);
	nokia5110_spi_init(0x51);
	i2c_init();
	nokia5110_power_on();
	set_volume(0);
	ADC_init(ADC_PC3, ADC_NO_TRIGGER, ADC_REFERENCE_1V1, true, true); //ADC_TIMER0_OVERFLOW
	sei();
	
	ds1307_getdate_s(&time);
		
	//If the clock isn't set, it reads all values as zero.  Set a default time
	if (time.year == 0) {
		ds1307_setdate(14,10,21,12,28,30);
	}
	
	time_alarm_A.hour = eeprom_read_byte(&alarm_A_hours);
	time_alarm_A.minute = eeprom_read_byte(&alarm_A_minutes);
	alarm_A_is_beep = eeprom_read_byte(&alarm_A_tone_setting);
	if (time_alarm_A.hour >= time_limits[hours]) {
		time_alarm_A.hour = 0;
		eeprom_update_byte(&alarm_A_hours, time_alarm_A.hour);
	}
	if (time_alarm_A.minute >= time_limits[minutes]) {
		time_alarm_A.minute = 0;
		eeprom_update_byte(&alarm_A_minutes, time_alarm_A.minute);
	}
	if (alarm_A_is_beep > true) {
		alarm_A_is_beep = true;
	}
	
	time_alarm_B.hour = eeprom_read_byte(&alarm_B_hours);
	time_alarm_B.minute = eeprom_read_byte(&alarm_B_minutes);
	alarm_B_is_beep = eeprom_read_byte(&alarm_B_tone_setting);
	if (time_alarm_B.hour >= time_limits[hours]) {
		time_alarm_B.hour = 0;
		eeprom_update_byte(&alarm_B_hours, time_alarm_B.hour);
	}
	if (time_alarm_B.minute >= time_limits[minutes]) {
		time_alarm_B.minute = 0;
		eeprom_update_byte(&alarm_B_minutes, time_alarm_B.minute);
	}
	if (alarm_B_is_beep > true) {
		alarm_B_is_beep = true;
	}
	
	channel = eeprom_read_word(&saved_channel);
	if (channel < SI4705_FM_LOW || channel > SI4705_FM_HIGH) channel = 889;
	
	for (err = 0; err < NUMBER_OF_PRESETS; err++) {
		presets[err] = eeprom_read_word(&saved_presets[err]);
		if (presets[err] < SI4705_FM_LOW || presets[err] > SI4705_FM_HIGH) presets[err] = 945;
	}
	
	ms_clock = 0;
	while(true) {
		if (is_fresh) {
			is_fresh = false;
			check_schedule();
			switch(state) {
				case home:
					home_state(); break;
				case menu: 
					menu_state(); break;
				case set_clock:
					set_clock_state(); break;
				case set_alarm_A:
				case set_alarm_B:
					set_alarm_state(); break;
				case alarm_A:
				case alarm_B:
					alarm_state(); break;
				case radio:
					radio_state(); break;
				case preset:
					preset_state(); break;
				default: break;
			}
			init = false;
			state_handler();
			watchdog_entertain();
		}
	}
}
예제 #5
0
/*
 * Sequential version.
 */
int
seqsa_solver(char *stg_filename, char *ssf_filename)
{
    int malloced;
    int freed;

    int malloced_initial;
    int freed_initial;

    int malloced_select;
    int freed_select;

    struct stg *tg;
    struct ssf_status *status;
    struct ssf *schedule;

    double eps;
    unsigned seed;

    int i;
    double t0;
    double t;

    struct iss *alpha;  /* present solution */
    struct iss *beta;   /* neighbour solution of alpha */

    double cost_alpha;
    double cost_beta;

    double r;
    double bf;  /* Boltzmann Factor p(alpha -> beta) */


    printf("** Sequential Simulated Annealing Solver\n");

    /* Allocate data structures. */
    malloced = 0;
    freed = 0;
    tg = new_task_graph_from_file(stg_filename, &malloced);
    status = new_status(&malloced);
    strncpy(status->name, "YASA Sequential", 20);

    eps = 1e-3;
    seed = 0;
    t0 = 1000.0;

    alpha = NULL;
    beta = NULL;

    /* Solve. */
    srand(seed);
    print_task_graph(tg);

    malloced_initial = 0;
    freed_initial = 0;
    alpha = create_initial_solution(tg, &malloced_initial, &freed_initial);
    printf("malloced %d bytes for initial solution\n", malloced_initial);
    printf("freed %d bytes for initial solution\n", freed_initial);
    printf("difference: %d bytes\n", malloced_initial - freed_initial);

    cost_alpha = cost(tg, alpha);

    i = 0;
    t = t0;
    
    while (t > eps) {
        printf("i = %d, t = %f\n", i, t);

        malloced_select = 0;
        freed_select = 0;
        beta = select_neighbour(tg, alpha, &malloced_select, &freed_select);
        printf("malloced %d bytes for selection\n", malloced_select);
        printf("freed %d bytes for selection\n", freed_select);
        printf("difference: %d bytes\n", malloced_select - freed_select);
        cost_beta = cost(tg, beta);

        if (cost_beta <= cost_alpha) {
            /* TODO alpha := beta */
            cost_alpha = cost_beta;
        } else {
            r = get_random_r();  /* r from (0, 1) */
            bf = boltzmann_factor(t, cost_alpha, cost_beta);
            printf("r = %f, bf = %f\n", r, bf);
            if (r < bf) {
                /* TODO alpha := beta */
                cost_alpha = cost_beta;
            }
        }
        i++;
        t = new_temp(t, i);
    }
    printf("stopping at i = %d, t = %f.\n", i, t);

    /* alpha to schedule */
    //schedule = new_schedule(tg, alpha, &malloced);
    schedule = new_schedule(tg, &malloced);
    printf("malloced %d bytes\n", malloced);

    /* Display Results */
    print_schedule(schedule);
    write_schedule_to_file(ssf_filename, schedule, status);

    /* Free data structures. */
    free_schedule(schedule, &freed);
    // TODO free initial solution
    free_status(status, &freed);
    free_task_graph(tg, &freed);
    printf("freed %d bytes => ", freed);
    if (malloced == freed)
        printf("OK.\n");
    else {
        printf("Error: malloced != freed!\n");
        return (1);
    }

    return (0);
}