// (调用led_switch函数)将指定的单个led灯以指定的间隔闪烁指定次数。 void led_flash1(int led, int ms100, int times) { // 闪烁前保存三色led灯的亮灭状态。 led_sts_save(); while(times--) { led_switch(led, ON); delay_100ms((unsigned short)ms100); led_switch(led, OFF); delay_100ms((unsigned short)ms100); } // 闪烁后恢复三色led灯的亮灭状态。 led_sts_recovery(); }
void _init_func(void) { trigger_init(); rc632_init(); rc632_test(NULL); DEBUGP("opening reader "); #if 1 rh = rfid_reader_open(NULL, RFID_READER_OPENPCD); DEBUGP("rh=%p ", rh); #endif led_switch(2, 1); }
// 以指定的时间间隔依次点亮、熄灭三个LED灯。 void led_flash2(int led1, int led2, int led3, int ms100) { // 闪烁前保存三色led灯的亮灭状态。 led_sts_save(); led_switch(led1, ON); delay_100ms((unsigned short)ms100); led_switch(led1, OFF); led_switch(led2, ON); delay_100ms((unsigned short)ms100); led_switch(led2, OFF); led_switch(led3, ON); delay_100ms((unsigned short)ms100); led_switch(led3, OFF); // 闪烁后恢复三色led灯的亮灭状态。 led_sts_recovery(); }
int main(void) { /* initialize LED and debug unit */ led_init(); sysirq_init(); AT91F_DBGU_Init(); AT91F_PIOA_CfgPMC(); wdt_init(); pit_init(); blinkcode_init(); /* initialize USB */ req_ctx_init(); usbcmd_gen_init(); udp_open(); /* call application specific init function */ _init_func(); // Enable User Reset and set its minimal assertion to 960 us AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_URSTEN | (0x4 << 8) | (unsigned int)(0xA5 << 24); #ifdef DEBUG_CLOCK_PA6 AT91F_PMC_EnablePCK(AT91C_BASE_PMC, 0, AT91C_PMC_CSS_PLL_CLK); AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, 0, AT91C_PA6_PCK0); #endif /* switch on first led */ led_switch(2, 1); DEBUGPCRF("entering main (idle) loop"); while (1) { /* Call application specific main idle function */ _main_func(); dbgu_rb_flush(); /* restart watchdog timer */ wdt_restart(); #ifdef CONFIG_IDLE //cpu_idle(); #endif } }
void _main_func(void) { int ret; usb_out_process(); usb_in_process(); ret = init_proto(); if (ret >= 4) rfid_protocol_close(ph); if (ret >= 3) rfid_layer2_close(l2h); rc632_turn_off_rf(NULL); { volatile int i; for (i = 0; i < 0xfffff; i++) ; } rc632_turn_on_rf(NULL); led_switch(1, 0); led_toggle(2); }
void _main_func(void) { u_int32_t uid; int status; status = rfid_layer2_open(l2h); if (status >= 0 && l2h->uid_len==4) { uid=((u_int32_t)l2h->uid[0]) | ((u_int32_t)l2h->uid[1])<< 8| ((u_int32_t)l2h->uid[2])<<16| ((u_int32_t)l2h->uid[3])<<24; delay_scan=100; if(uid!=last_uid) { last_uid=last_polled_uid=uid; delay_blink=10; DEBUGPCR("UID:0x%08X", uid); } } else if(delay_scan) delay_scan--; else last_uid=0; led_switch(1,(delay_blink==0)?1:0); if(delay_blink) delay_blink--; /* first we try to get rid of pending to-be-sent stuff */ usb_out_process(); /* next we deal with incoming reqyests from USB EP1 (OUT) */ usb_in_process(); rc632_unthrottle(); }
/* * Panic is called on unresolvable fatal errors. It prints "panic: mesg", * and then reboots. If we are called twice, then we avoid trying to sync * the disks as this often leads to recursive panics. */ void panic(const char *fmt, ...) { int bootopt, newpanic; globaldata_t gd = mycpu; thread_t td = gd->gd_curthread; __va_list ap; static char buf[256]; #ifdef SMP /* * If a panic occurs on multiple cpus before the first is able to * halt the other cpus, only one cpu is allowed to take the panic. * Attempt to be verbose about this situation but if the kprintf() * itself panics don't let us overrun the kernel stack. * * Be very nasty about descheduling our thread at the lowest * level possible in an attempt to freeze the thread without * inducing further panics. * * Bumping gd_trap_nesting_level will also bypass assertions in * lwkt_switch() and allow us to switch away even if we are a * FAST interrupt or IPI. * * The setting of panic_cpu_gd also determines how kprintf() * spin-locks itself. DDB can set panic_cpu_gd as well. */ for (;;) { globaldata_t xgd = panic_cpu_gd; /* * Someone else got the panic cpu */ if (xgd && xgd != gd) { crit_enter(); ++mycpu->gd_trap_nesting_level; if (mycpu->gd_trap_nesting_level < 25) { kprintf("SECONDARY PANIC ON CPU %d THREAD %p\n", mycpu->gd_cpuid, td); } td->td_release = NULL; /* be a grinch */ for (;;) { lwkt_deschedule_self(td); lwkt_switch(); } /* NOT REACHED */ /* --mycpu->gd_trap_nesting_level */ /* crit_exit() */ } /* * Reentrant panic */ if (xgd && xgd == gd) break; /* * We got it */ if (atomic_cmpset_ptr(&panic_cpu_gd, NULL, gd)) break; } #else panic_cpu_gd = gd; #endif /* * Try to get the system into a working state. Save information * we are about to destroy. */ kvcreinitspin(); if (panicstr == NULL) { bcopy(td->td_toks_array, panic_tokens, sizeof(panic_tokens)); panic_tokens_count = td->td_toks_stop - &td->td_toks_base; } lwkt_relalltokens(td); td->td_toks_stop = &td->td_toks_base; /* * Setup */ bootopt = RB_AUTOBOOT | RB_DUMP; if (sync_on_panic == 0) bootopt |= RB_NOSYNC; newpanic = 0; if (panicstr) { bootopt |= RB_NOSYNC; } else { panicstr = fmt; newpanic = 1; } /* * Format the panic string. */ __va_start(ap, fmt); kvsnprintf(buf, sizeof(buf), fmt, ap); if (panicstr == fmt) panicstr = buf; __va_end(ap); kprintf("panic: %s\n", buf); #ifdef SMP /* two separate prints in case of an unmapped page and trap */ kprintf("cpuid = %d\n", mycpu->gd_cpuid); #endif #if (NGPIO > 0) && defined(ERROR_LED_ON_PANIC) led_switch("error", 1); #endif #if defined(WDOG_DISABLE_ON_PANIC) && defined(WATCHDOG_ENABLE) wdog_disable(); #endif /* * Enter the debugger or fall through & dump. Entering the * debugger will stop cpus. If not entering the debugger stop * cpus here. */ #if defined(DDB) if (newpanic && trace_on_panic) print_backtrace(-1); if (debugger_on_panic) Debugger("panic"); else #endif #ifdef SMP if (newpanic) stop_cpus(mycpu->gd_other_cpus); #else ; #endif boot(bootopt); }
void app_register_set (uint8_t uRegNo, uint32_t uValue) { uint16_t tempval16; uint8_t tempval, index; tempval16 = (uint16_t)(uValue & 0x0000FFFF); tempval = (uint8_t)(uValue & 0x000000FF); // registers saved in EEProm if (uRegNo >= APP_eReg_RemoteAddr00 && uRegNo <= APP_eReg_RemoteAddr31) { index = (uRegNo - APP_eReg_RemoteAddr00) * 2; index += APP_eCfg_RemoteAddr00; eeprom_write_word((uint16_t*)®ister_eeprom_array[index], tempval16); } else if (uRegNo >= APP_eReg_RemoteReg00 && uRegNo <= APP_eReg_RemoteReg31) { index = uRegNo - APP_eReg_RemoteReg00; index += APP_eCfg_RemoteReg00; eeprom_write_byte(®ister_eeprom_array[index], tempval); } else if (uRegNo >= APP_eReg_TargetReg00 && uRegNo <= APP_eReg_TargetReg31) { index = uRegNo - APP_eReg_TargetReg00; index += APP_eCfg_TargetReg00; eeprom_write_byte(®ister_eeprom_array[index], tempval); } else if (uRegNo >= APP_eReg_0_Mode && uRegNo <= APP_eReg_7_Mode) { index = uRegNo - APP_eReg_0_Mode; index += APP_eCfg_0_Mode; eeprom_write_byte(®ister_eeprom_array[index], tempval); app_initialize_modes(); } else if (uRegNo >= APP_eReg_0_RemoteAddr0 && uRegNo <= APP_eReg_7_RemoteAddr0) { index = uRegNo - APP_eReg_0_RemoteAddr0; index += APP_eCfg_0_RemoteAddr0; eeprom_write_word((uint16_t*)®ister_eeprom_array[index], tempval16); } else if (uRegNo >= APP_eReg_0_RemoteAddr1 && uRegNo <= APP_eReg_7_RemoteAddr1) { index = uRegNo - APP_eReg_0_RemoteAddr1; index += APP_eCfg_0_RemoteAddr1; eeprom_write_word((uint16_t*)®ister_eeprom_array[index], tempval16); } // registers in ROM/RAM else if (uRegNo >= APP_eReg_0_LEDState && uRegNo <= APP_eReg_7_LEDState) { index = uRegNo - APP_eReg_0_LEDState; ram_reg_led_state[index] = tempval; led_switch(index, tempval); } else if (uRegNo >= APP_eReg_0_TgtChn0 && uRegNo <= APP_eReg_7_TgtChn0) { index = uRegNo - APP_eReg_0_TgtChn0; ram_reg_target_chn_0[index] = tempval; } else if (uRegNo >= APP_eReg_0_TgtChn1 && uRegNo <= APP_eReg_7_TgtChn1) { index = uRegNo - APP_eReg_0_TgtChn1; ram_reg_target_chn_1[index] = tempval; } else if (uRegNo >= APP_eReg_0_TgtChn2 && uRegNo <= APP_eReg_7_TgtChn2) { index = uRegNo - APP_eReg_0_TgtChn2; ram_reg_target_chn_2[index] = tempval; } else if (uRegNo >= APP_eReg_0_RemChn0 && uRegNo <= APP_eReg_7_RemChn0) { index = uRegNo - APP_eReg_0_RemChn0; ram_reg_remote_chn_0[index] = tempval; } else if (uRegNo >= APP_eReg_0_RemChn1 && uRegNo <= APP_eReg_7_RemChn1) { index = uRegNo - APP_eReg_0_RemChn1; ram_reg_remote_chn_1[index] = tempval; } else if (uRegNo >= APP_eReg_0_RemChn2 && uRegNo <= APP_eReg_7_RemChn2) { index = uRegNo - APP_eReg_0_RemChn2; ram_reg_remote_chn_2[index] = tempval; } }
void serialUI(void) { if (commandRetrived == 1) { if (commandType == 0) { checkCmd(); commandRetrived = 0; } if (commandType == 1) { if (setCmd == 0) { //this is to send in data. the data is not yet flashed led_switch(2); //data can be send in at any time also at flight time //it will be used with the next cycle print_uart0("FCm0;storing setting %d;00#",setupCache.settingNum); setToInSettings(); //fill the runtime struct with the settings setTempToInSetting(setupCache.settingNum); //save settings to ram cache commandRetrived = 0; } if (setCmd == 1) { print_uart0("FCm0;flashing settings;00#"); //here we write all the settings from ram to flash enginesOff(); //this is to save some of the flashing cycles. led_switch(3); //we could flash with any retrieved setting but that engineStatus = 0; //just helps abusing the flash cycles so its a manual //step to really save to flash writeSetup(); ADCStandstillValues(); //also we reset the ADCOffset commandRetrived = 0; initFCRuntime(); ledTest(); } } if (commandType == 2) { updateAcdRate(); commandRetrived = 0; } if (commandType == 3) { retriveSetting(); printSettings(); commandRetrived = 0; } if (commandType == 4) { if (I2CcmdType == I2CMODE_WRITEADDRESS){ if (updateYGE == 0) { I2C0Mode = I2CMODE_WRITEADDRESS; I2C0State = 0; updateYGE = 1; I2C0Start(); } } if (I2CcmdType == I2CMODE_STARTUP_TARGET){ if (updateYGE == 0) { I2C0Stop(); I2C0Mode = I2CMODE_WRITEADDRESS; I2C0State = 0; updateYGE = 1; I2C0Start(); } } commandRetrived = 0; } } }
void calib_MM3(void) { led_switch(1); if (MM3_x != MM3_runtime.X_axis) { if (MM3_runtime.X_axis > X_Max){ X_Max = MM3_runtime.X_axis; led_switch(2); }else { if (MM3_runtime.X_axis < X_Min){ X_Min = MM3_runtime.X_axis; led_switch(2); } else { LED2_OFF; } } } if (MM3_y != MM3_runtime.Y_axis) { if (MM3_runtime.Y_axis > Y_Max){ Y_Max = MM3_runtime.Y_axis; led_switch(3); } else { if (MM3_runtime.Y_axis < Y_Min){ Y_Min = MM3_runtime.Y_axis; led_switch(3); } else { LED3_OFF; } } } if (MM3_z != MM3_runtime.Z_axis) { if (MM3_runtime.Z_axis > Z_Max){ Z_Max = MM3_runtime.Z_axis; led_switch(4); } else { if (MM3_runtime.Z_axis < Z_Min){ Z_Min = MM3_runtime.Z_axis; led_switch(4); } else { LED4_OFF; } } } //calibration stops when taking back throttle //if (PWM_channel[PWM_THROTTLE] < 100) calib = 0; // Calculate the values. Done every time which is a waste of resources. // But we do it in off flight and setup situation anyways. // Calculate the Compass range value sysSetup.MM3.X_MAX = X_Max; sysSetup.MM3.Y_MAX = Y_Max; sysSetup.MM3.Z_MAX = Z_Max; sysSetup.MM3.X_MIN = X_Min; sysSetup.MM3.Y_MIN = Y_Min; sysSetup.MM3.Z_MIN = Z_Min; sysSetup.MM3.X_range = (X_Max - X_Min); sysSetup.MM3.Y_range = (Y_Max - Y_Min); sysSetup.MM3.Z_range = (Z_Max - Z_Min); // Calculate the Compass gain offset value sysSetup.MM3.X_off = (X_Max + X_Min) / 2; sysSetup.MM3.Y_off = (Y_Max + Y_Min) / 2; sysSetup.MM3.Z_off = (Z_Max + Z_Min) / 2; }
static int init_proto(void) { struct req_ctx *detect_rctx; struct openpcd_hdr *opcdh; struct openpcd_l2_connectinfo *l2c; struct openpcd_proto_connectinfo *pc; unsigned int size; l2h = rfid_layer2_scan(rh); if (!l2h) return 0; DEBUGP("l2='%s' ", rfid_layer2_name(l2h)); detect_rctx = req_ctx_find_get(0, RCTX_STATE_FREE, RCTX_STATE_LIBRFID_BUSY); if (detect_rctx) { unsigned int uid_len; opcdh = (struct openpcd_hdr *) detect_rctx->data; l2c = (struct openpcd_l2_connectinfo *) (char *) opcdh + sizeof(opcdh); l2c->uid_len = sizeof(l2c->uid); opcdh->cmd = OPENPCD_CMD_LRFID_DETECT_IRQ; opcdh->flags = 0x00; opcdh->reg = 0x03; opcdh->val = l2h->l2->id; detect_rctx->tot_len = sizeof(*opcdh) + sizeof(*l2c); #if 0 /* copy UID / PUPI into data section */ rfid_layer2_getopt(l2h, RFID_OPT_LAYER2_UID, (void *)l2c->uid, &uid_len); l2c->uid_len = uid_len & 0xff; size = sizeof(l2c->proto_supported); rfid_layer2_getopt(l2h, RFID_OPT_LAYER2_PROTO_SUPP, &l2c->proto_supported, &size); switch (l2h->l2->id) { case RFID_LAYER2_ISO14443A: break; case RFID_LAYER2_ISO14443B: break; case RFID_LAYER2_ISO15693: break; } #endif req_ctx_set_state(detect_rctx, RCTX_STATE_UDP_EP3_PENDING); } else DEBUGPCRF("=>>>>>>>>>>>>>>no req_ctx for L2!"); ph = rfid_protocol_scan(l2h); if (!ph) return 3; DEBUGP("p='%s' ", rfid_protocol_name(ph)); detect_rctx = req_ctx_find_get(0, RCTX_STATE_FREE, RCTX_STATE_LIBRFID_BUSY); if (detect_rctx) { opcdh = (struct openpcd_hdr *) detect_rctx->data; pc = (struct openpcd_proto_connectinfo *) ((char *) opcdh + sizeof(*opcdh)); detect_rctx->tot_len = sizeof(*opcdh) + sizeof(*pc); opcdh->cmd = OPENPCD_CMD_LRFID_DETECT_IRQ; opcdh->flags = 0x00; opcdh->reg = 0x04; opcdh->val = ph->proto->id; /* copy L4 info into data section */ #if 0 switch (ph->proto->id) { case RFID_PROTOCOL_TCL: { struct openpcd_proto_tcl_connectinfo *ptc = (struct openpcd_proto_tcl_connectinfo *) ((char *) ph + sizeof(*ph)); unsigned int space; detect_rctx->tot_len += sizeof(*ptc); space = detect_rctx->size - sizeof(*opcdh)-sizeof(*pc); size = space; rfid_protocol_getopt(ph, RFID_OPT_P_TCL_ATS, &ptc->ats_snippet, &size); if (size == space) { /* we've only copied part of the ATS */ size = sizeof(ptc->ats_tot_len); rfid_protocol_getopt(ph, RFID_OPT_P_TCL_ATS_LEN, &ptc->ats_tot_len, &size); } else { ptc->ats_tot_len = size; } } break; } #endif req_ctx_set_state(detect_rctx, RCTX_STATE_UDP_EP3_PENDING); } else DEBUGPCRF("=>>>>>>>>>>>>>>no req_ctx for L2!"); led_switch(1, 1); if (ph->proto->id == RFID_PROTOCOL_MIFARE_CLASSIC) { int rc; DEBUGPCR("Authenticating sector %u: ", sector); rc = mfcl_set_key(ph, MIFARE_CL_KEYA_DEFAULT_INFINEON); if (rc < 0) { DEBUGPCR("key format error"); return 4; } rc = mfcl_auth(ph, RFID_CMD_MIFARE_AUTH1A, sector*4); if (rc < 0) { DEBUGPCR("mifare auth error"); return 4; } else DEBUGPCR("mifare auth succeeded!\n"); mifare_classic_read_sector(ph, sector); return 5; } return 4; }