int main (void) { save_power(); USART0Init(); buttons_init(); tone_init(); int useless_steps = 0; int state = STATE_GO_OFF; while (1) { if (useless_steps >= 1000) { useless_steps = 0; state = STATE_GO_OFF; } if (state == STATE_GO_OFF) { state = STATE_IS_OFF; USART0SendString(""); USART0BacklightOff(); deep_sleep(); } tick(); if (toggle_state() == 0) { useless_steps = 0; USART0BacklightOn(); write_next_chore(); while (toggle_state() == 0) { tick(); } // Wait for button to be released int seconds = 0; int miliseconds = 0; while (1) { if (toggle_state() == 0) { state = STATE_GO_OFF; notone(); break; } if (timer_state() == 0) { miliseconds = 0; seconds = 0; notone(); } miliseconds++; if (miliseconds >= 1000) { seconds++; miliseconds = 0; } if (seconds == TIMER_LENGTH) { tone(4400); } else if (seconds > 1000) { seconds = (TIMER_LENGTH + 1); } tick(); } } else { useless_steps++; } } }
int main (void) { SystemInit (); debug_init (); #ifdef DEBUG_LEVEL debug_set_level (DEBUG_LEVEL); #endif DBG_NEWLINE (DBG_LEVEL_INFO); DBG (DBG_LEVEL_INFO, "HAM relay firmware v" VERSION_STR " (" __GIT_SHA1__ ")"); DBG (DBG_LEVEL_INFO, "Compiled " __DATE__ " at " __TIME__ " on " __BUILD_HOSTNAME__ " using GCC " __VERSION__ " (%d.%d-%d)", __CS_SOURCERYGXX_MAJ__, __CS_SOURCERYGXX_MIN__, __CS_SOURCERYGXX_REV__); DBG (DBG_LEVEL_INFO, "MCU running at %d MHz", SystemCoreClock / 1000000); inputs_init (); systick_init (); tx_init (); tone_init (); roger_beep_init (); call_init (); call_transmit_delay (5); while (1) { if (!tx_is_enabled ()) { roger_beep_transmit_if_needed (); call_transmit_if_needed (); } __WFI (); } return 0; }
int main(void) { int test_mode; int vm_present; int i; unsigned int seed; // Needs to be called ASAP as rf need a looooooong time to wake up. // This function is just sending a pulse over the SCL line. rf_wakeup(); clock_set_speed(16000000UL,16); setup_pps(); setup_io(); leds_init(); CHARGE_500MA = 0; // Switch back to 100mA charge. // Switch on one led to say we are powered on leds_set(LED_BATTERY_0, 32); // Enable the poweroff softirq. _INT3IF = 0; _INT3IP = 1; _INT3IE = 1; // Sound must be enabled before analog, as // The analog interrupt callback into sound processing ... // But must be initialised _after_ leds as it use one led IO for enabling amp. sound_init(); tone_init(); // Init tone generator pwm_motor_init(); pid_motor_init(); // We need the settings for the horizontal prox. load_settings_from_flash(); for (i = 0; i < 2; i++) { // Settings is definitely wrong.... if(settings.mot256[i] <= 0) settings.mot256[i] = 256; // 1024 (AD resolution is 10 bits) * 256 / 9 fits in signed 16 bits. if (settings.mot256[i] < 9) settings.mot256[i] = 9; } // This is the horizontal prox. Vertical one are handled by the ADC // but ADC sync the motor mesurment with the prox, so we don't pullute it with noise ... timer_init(TIMER_IR_COMM, 0,-1); // The period will be changed later. prox_init(PRIO_SENSORS); // Same priority as analog (maybe should be at 7 ...) // Warning: We cannot use the SD before the analog init as some pin are on the analog port. analog_init(TIMER_ANALOG, PRIO_SENSORS); wait_valid_vbat(); log_init(); // We will need to read vbat to be sure we can flash. ntc_init(ntc_callback, PRIO_1KHZ); // i2c_init(I2C_3); i2c_init_master(I2C_3, 400000, PRIO_I2C); I2C3CON = 0x9000; mma7660_init(I2C_3, MMA7660_DEFAULT_ADDRESS, acc_cb, 0); mma7660_set_mode(MMA7660_120HZ, 1); rc5_init(TIMER_RC5, rc5_callback, PRIO_RC5); sd_init(); timer_init(TIMER_1KHZ, 1000, 6); timer_enable_interrupt(TIMER_1KHZ, timer_1khz, PRIO_1KHZ); rf_init(I2C_3); timer_enable(TIMER_1KHZ); sd_log_file(); vm_present = init_aseba_and_fifo(); if(vm_present) log_analyse_bytecode(); vmVariables.fwversion[0] = FW_VERSION; vmVariables.fwversion[1] = FW_VARIANT; // SD file is more important than internal flash if(!sd_load_aseba_code()) { log_set_flag(LOG_FLAG_VMCODESD); vm_present = 1; log_analyse_bytecode(); } // Behavior is on INT4 (softirq trigged by 1khz timer). behavior_init(PRIO_BEHAVIOR); test_mode = sd_test_file_present(); if(!test_mode) mode_init(vm_present); // Enable the LVD interrupt _LVDIE = 1; play_sound(SOUND_POWERON); if(test_mode) { test_mode_start(); while(1) idle_without_aseba(); } while(behavior_enabled(B_MODE)) idle_without_aseba(); // If usb did not put us out of behavior mode, then start the rf link if(!usb_uart_serial_port_open() && (rf_get_status() & RF_PRESENT)) { rf_set_link(RF_UP); } // get the random seed seed = 0; for(i = 0; i < 5; i++) { seed += vmVariables.buttons_mean[i]; seed += vmVariables.buttons_noise[i]; } seed += vmVariables.vbat[0]; seed += vmVariables.vbat[1]; for(i = 0; i < 3; i++) seed += vmVariables.acc[i]; AsebaSetRandomSeed(seed); for(i = 0; i < 3; i++) AsebaGetRandom(); // Give full control to aseba. No way out (except reset). run_aseba_main_loop(); }
int main(int argc, char **argv) { struct sigaction sa; struct tonegend tonegend; struct cmdopt cmdopt; cmdopt.daemon = 0; cmdopt.uid = -1; cmdopt.path = NULL; cmdopt.standard = STD_CEPT; cmdopt.interactive = 0; cmdopt.sample_rate = 48000; cmdopt.statistics = 0; cmdopt.buflen = 0; cmdopt.minreq = 0; cmdopt.dtmf_tags = NULL; cmdopt.ind_tags = NULL; cmdopt.notif_tags = NULL; cmdopt.dtmf_volume = 100; cmdopt.ind_volume = 100; cmdopt.notif_volume = 100; parse_options(argc, argv, &cmdopt); memset(&tonegend, 0, sizeof(tonegend)); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = signal_handler; sa.sa_flags = SA_SIGINFO; if (sigaction(SIGHUP , &sa, NULL) < 0 || sigaction(SIGTERM, &sa, NULL) < 0 || sigaction(SIGINT , &sa, NULL) < 0 ) { LOG_ERROR("Failed to install signal handlers"); return errno; } if (dbusif_init(argc, argv) < 0 || ausrv_init(argc, argv) < 0 || stream_init(argc, argv) < 0 || tone_init(argc, argv) < 0 || envelop_init(argc, argv) < 0 || indicator_init(argc, argv) < 0 || dtmf_init(argc, argv) < 0 || note_init(argc, argv) < 0 || interact_init(argc, argv) < 0 || rfc4733_init(argc, argv) < 0 || notif_init(argc, argv) < 0) { LOG_ERROR("Error during initialization"); return EINVAL; } stream_set_default_samplerate(cmdopt.sample_rate); stream_print_statistics(cmdopt.statistics); stream_buffering_parameters(cmdopt.buflen, cmdopt.minreq); dtmf_set_properties(cmdopt.dtmf_tags); indicator_set_properties(cmdopt.ind_tags); notif_set_properties(cmdopt.notif_tags); dtmf_set_volume(cmdopt.dtmf_volume); indicator_set_volume(cmdopt.ind_volume); notif_set_volume(cmdopt.notif_volume); if (cmdopt.daemon) daemonize(cmdopt.uid, cmdopt.path); if ((main_loop = g_main_loop_new(NULL, FALSE)) == NULL) { LOG_ERROR("Can't create main loop"); return EIO; } if ((tonegend.dbus_ctx = dbusif_create(&tonegend)) == NULL) { LOG_ERROR("D-Bus setup failed"); return EIO; } if ((tonegend.ausrv_ctx = ausrv_create(&tonegend,pa_server_name)) == NULL){ LOG_ERROR("Pulse Audio setup failed"); return EIO; } if (rfc4733_create(&tonegend) < 0) { LOG_ERROR("Can't setup rfc4733 interface on D-Bus"); return EIO; } if (notif_create(&tonegend) < 0) { LOG_ERROR("Can't setup notification interface on D-Bus"); return EIO; } if (!cmdopt.daemon && cmdopt.interactive) { if (!(tonegend.intact_ctx = interact_create(&tonegend,fileno(stdin)))){ LOG_ERROR("Can't setup interactive console"); return EIO; } printf("Running in interactive mode\n"); } indicator_set_standard(cmdopt.standard); g_main_loop_run(main_loop); LOG_INFO("Exiting now ..."); ausrv_destroy(tonegend.ausrv_ctx); dbusif_destroy(tonegend.dbus_ctx); interact_destroy(tonegend.intact_ctx); if (main_loop != NULL) g_main_loop_unref(main_loop); ausrv_exit(); return 0; }
int main(void) { unsigned char cf,key_data; int vol = 127; ROMEMU(); da_init(); timer_init(); P6DDR &= ~0x07; /* P60,1,2 入力 */ PADDR |= 0x0f; /* PA0,1,2,3 出力 */ tone_init(); while (1) { key_data = 0; //key 1,2,3 PADR = 0x07; // PA3 = L cf = P6DR; // データ入力 cf = ~cf; // cfの反転 cf &= 0x07; // P60,1,2のみ見る switch(cf) { case 1 : key_data = '1'; break; case 2 : key_data = '2'; break; case 4 : key_data = '3'; break; } //key 4,5,6 PADR = 0x0b; cf = P6DR; cf = ~cf; cf &= 0x07; switch(cf) { case 1 : key_data = '4'; break; case 2 : key_data = '5'; break; case 4 : key_data = '6'; break; } //key 7,8,9 PADR = 0x0d; /* This is a mistake code. */ cf = P6DR; cf = ~cf; cf &= 0x07; switch(cf) { case 1 : key_data = '7'; break; case 2 : key_data = '8'; break; case 4 : key_data = '9'; break; } //key *,0,# PADR = 0x0e; cf = P6DR; cf = ~cf; cf &= 0x07; switch(cf) { case 1 : key_data = '*'; break; case 2 : key_data = '0'; break; case 4 : key_data = '#'; break; } switch(key_data) { case '1': note_on(DO_L,vol); break; case '2': note_on(RE,vol); break; case '3': note_on(MI,vol); break; case '4': note_on(FA,vol); break; case '5': note_on(SO,vol); break; case '6': note_on(RA,vol); break; case '7': note_on(SI,vol); break; case '8': note_on(DO_H,vol); break; default: note_off(); break; } } return 1; }