static int32_t pflash_erase_page(FlashInfo* flash) { uint32_t command[5], result[3]; IAP iap_entry; iap_entry = (IAP) IAP_LOCATION; /* prepare page/sector */ command[0] = IAP_PREPARE_SECTORS; command[1] = flash->page_nr; command[2] = flash->page_nr; disableIRQ(); iap_entry(command, result); enableIRQ(); if (result[0] != 0) return result[0]; /* erase page/sector */ command[0] = IAP_ERASE_SECTORS; command[1] = flash->page_nr; command[2] = flash->page_nr; disableIRQ(); iap_entry(command, result); enableIRQ(); if (result[0] != 0) return result[0]; /* verify erase */ command[0] = IAP_BLANK_CHECK_SECTORS; command[1] = flash->page_nr; command[2] = flash->page_nr; iap_entry(command, result); if (result[0] != 0) return result[0]; return 0; }
static int32_t pflash_program_array(FlashInfo* flash, uint32_t dest, uint32_t src) { uint32_t command[5], result[3]; IAP iap_entry; iap_entry = (IAP) IAP_LOCATION; /* prepare page/sector */ command[0] = IAP_PREPARE_SECTORS; command[1] = flash->page_nr; command[2] = flash->page_nr; disableIRQ(); iap_entry(command, result); enableIRQ(); if (result[0] != 0) return result[0]; /* flash from ram */ command[0] = IAP_COPY_RAM_TO_FLASH; command[1] = dest; command[2] = src; command[3] = BOUND; command[4] = CCLK/1000; disableIRQ(); iap_entry(command, result); enableIRQ(); if (result[0] != 0) return result[0]; return 0; }
__attribute__((naked)) void thread_arch_start_threading(void) { /* enable IRQs to make sure the SVC interrupt is reachable */ enableIRQ(); /* trigger the SVC interrupt which will get and execute the next thread */ asm("svc 0x01"); }
int main() { disableIRQ(); disableFIQ(); *AT91C_AIC_IDCR = 0xffffffff; *AT91C_PMC_PCDR = 0xffffffff; *AT91C_PMC_PCER = (1 << AT91C_ID_PIOA); dbg_setup_uart(); printf("Initialising\n"); dbg_set_input_handler(recv_input); leds_arch_init(); clock_init(); process_init(); printf("Started\n"); procinit_init(); enableIRQ(); printf("Processes running\n"); while(1) { do { /* Reset watchdog. */ } while(process_run() > 0); /* Idle! */ /* Stop processor clock */ *AT91C_PMC_SCDR |= AT91C_PMC_PCK; } return 0; }
bool_t i2c_submit(struct i2c_periph* p, struct i2c_transaction* t) { uint8_t idx; idx = p->trans_insert_idx + 1; if (idx >= I2C_TRANSACTION_QUEUE_LEN) idx = 0; if (idx == p->trans_extract_idx) { /* queue full */ p->errors->queue_full_cnt++; t->status = I2CTransFailed; return FALSE; } t->status = I2CTransPending; /* disable I2C interrupt */ //uint8_t* vic = (uint8_t*)(p->init_struct); //VICIntEnClear = VIC_BIT(*vic); disableIRQ(); p->trans[p->trans_insert_idx] = t; p->trans_insert_idx = idx; /* if peripheral is idle, start the transaction */ if (p->status == I2CIdle) I2cSendStart(p); /* else it will be started by the interrupt handler */ /* when the previous transactions completes */ /* enable I2C interrupt again */ //VICIntEnable = VIC_BIT(*vic); enableIRQ(); return TRUE; }
void msp430_set_cpu_speed(uint32_t speed) { disableIRQ(); __msp430_cpu_speed = speed; msp430_init_dco(); enableIRQ(); }
void ethernetIsr(void){ U32 irq_status = pVIC->IRQStatus; if (irq_status & __INTERRUPT_TIMER0_MASK__){ tickCount++; pVIC_VECTDEFADDR->VectAddr =0; //clear isr function address pTIMER0->IR |= 1<<5; //clear timer0 CR1 interrupt request enableIRQ( __INTERRUPT_TIMER0__ ); } }
__attribute__((naked)) void NORETURN thread_arch_start_threading(void) { /* enable IRQs to make sure the SVC interrupt can be triggered */ enableIRQ(); /* trigger the SVC interrupt that will schedule and load the next thread */ asm("svc 0x01"); UNREACHABLE(); }
static irqreturn_t keyboard_row1(int irq, void *dev_id) { disable_irq_nosync(irq); spin_lock(&spinlock); disableIRQ(); gzsd_select(input,KEY_ROW1); enableIRQ(); spin_unlock(&spinlock); enable_irq(irq); return IRQ_HANDLED; }
INITIALIZER FASTCALL void init_timer(){ startupTime=wallClock=read_RTC(); io_out8(TIMER_MODE_PORT, RATE_GENERATOR); io_out8(TIMER0_PORT, (u8)(TIMER_FREQ/HZ)); io_out8(TIMER0_PORT, (u8)((TIMER_FREQ/HZ)>>8)); registerIRQ(0, apic_timer_init); apic_write(APIC_TIMER_DCR, 0x3); apic_write(APIC_LVT_TIMER, 0x20); apic_write(APIC_TIMER_ICR, 0xFFFFFFFF); enableIRQ(0); restart(); }
void restoreIRQ(unsigned state) { DEBUG("restoreIRQ()\n"); if (state == 1) { enableIRQ(); } else { disableIRQ(); } return; }
int main (void) { // Initialize the system Initialize(); scheduler_init("led_task",0); scheduler_init("motor_task",1); set_timer(); enableIRQ(); Execute_Led_Task(); while(1); }
PmReturn_t plat_init(void) { /* Configure the Phase Locked Loop (PLL) */ PLLCFG=0x24; //set multiplier/divider of PLL for 60MHz PLLFEED=0xAA; PLLFEED=0x55; PLLCON=0x01; //enable PLL PLLFEED=0xAA; PLLFEED=0x55; while(!(PLLSTAT & PLOCK)); //wait for PLL to lock to set frequency PLLCON=0x3; //connect PLL as clock source PLLFEED=0xAA; PLLFEED=0x55; /* Configure the Memory Acceleration Module (MAM) */ MAMCR=0x02; //enable MAM MAMTIM=0x04; //set number of clocks for flash memory fetch VPBDIV=0x01; //set peripheral clock(pclk) to system clock(cclk) /* Configure the Timer 0 for an interrupt generation of every 200 ms */ T0TCR = 0x02; //reset counter T0IR = 0xff; T0MCR = 0x0003; //interrupt and reset on MR0 T0MR0 = COUNT_200_MS; //compare-hit count /* Configure the Vectored Interrupt Controller (VIC) */ VICVectCntl0 = 0x00000024; //use it for Timer 0 Interrupt: VICVectAddr0 = (unsigned)IRQ_Routine; //set interrupt vector in 0 VICIntEnable = 0x00000010; //enable TIMER0 interrupt /* Configure the Universal Asynchronous Receiver/Transmitter 0 (UART0) */ PINSEL0 = 0x00000005; //enable TXD0/RXD0 pins - P0.0 & 1 U0LCR = 0x83; //8-N-1, enable DLAB U0DLM = 0; //115200 baud U0DLL = 0x13; U0FCR = 0x07; //enable & clear FIFOs U0FDR = 0x00000075; //set fractional divider U0LCR = 0x03; //disable DLAB T0TCR = 0x01; //enable Timer0 enableIRQ(); //enable IRQ interrupt which was disabled in startup code return PM_RET_OK; }
/** Reads one character from VCOM port @returns character read, or EOF if character could not be read */ int VCOM_getchar(void) { int result; U8 c; result = fifo_get(&rxfifo, &c) ? c : EOF; if (BulkOut_is_blocked && fifo_free(&rxfifo) >= MAX_PACKET_SIZE) { disableIRQ(); // get more data from usb bus BulkOut(BULK_OUT_EP, 0); BulkOut_is_blocked = false; enableIRQ(); } return result; }
void thread_yield_higher(void) { ucontext_t *ctx = (ucontext_t *)(sched_active_thread->sp); if (_native_in_isr == 0) { _native_in_isr = 1; disableIRQ(); native_isr_context.uc_stack.ss_sp = __isr_stack; native_isr_context.uc_stack.ss_size = SIGSTKSZ; native_isr_context.uc_stack.ss_flags = 0; makecontext(&native_isr_context, isr_thread_yield, 0); if (swapcontext(ctx, &native_isr_context) == -1) { err(EXIT_FAILURE, "thread_yield_higher: swapcontext"); } enableIRQ(); } else { isr_thread_yield(); } }
void Kernel::executeIntVector(u32 vec, CPUState *state) { // Auto-Mask the IRQ. Any interrupt handler or user program // needs to re-enable the IRQ to receive it again. This prevents // interrupt loops in case the kernel cannot clear the IRQ immediately. enableIRQ(vec, false); // Fetch the list of interrupt hooks (for this vector) List<InterruptHook *> *lst = m_interrupts[vec]; // Does at least one handler exist? if (!lst) return; // Execute them all for (ListIterator<InterruptHook *> i(lst); i.hasCurrent(); i++) { i.current()->handler(state, i.current()->param); } }
/************************************************************************************************ * @fn adc12_single_conversion * @brief Init ADC12. Do single conversion. Turn off ADC12. * @param none * @return none ************************************************************************************************/ uint16_t adc12_single_conversion(uint16_t ref, uint16_t sht, uint16_t channel) { /* Initialize the shared reference module */ REFCTL0 |= REFMSTR + ref + REFON; /* Enable internal reference (1.5V or 2.5V) */ /* Initialize ADC12_A */ ADC12CTL0 = sht + ADC12ON; /* Set sample time */ ADC12CTL1 = ADC12SHP; /* Enable sample timer */ ADC12MCTL0 = ADC12SREF_1 + channel; /* ADC input channel */ ADC12IE = 0x001; /* ADC_IFG upon conv result-ADCMEMO */ enableIRQ(); /* Wait 2 ticks (66us) to allow internal reference to settle */ hwtimer_wait(2); /* Start ADC12 */ ADC12CTL0 |= ADC12ENC; /* Clear data ready flag */ adc12_data_ready = 0; /* Sampling and conversion start */ ADC12CTL0 |= ADC12SC; /* Wait until ADC12 has finished */ hwtimer_wait(5); while (!adc12_data_ready); /* Shut down ADC12 */ ADC12CTL0 &= ~(ADC12ENC | ADC12SC | sht); ADC12CTL0 &= ~ADC12ON; /* Shut down reference voltage */ REFCTL0 &= ~(REFMSTR + ref + REFON); ADC12IE = 0; /* Return ADC result */ return adc12_result; }
/* * initialize * ----------------------------------------------- * initialize the lpc2148 pll * cpu interrupts * the uart0 serial port * the rtc VIC interrupt */ void initialize(void) { // PLL and MAM // hwSysInit(SIXTY_MHZ); // hwSysInit(FOURTYEIGHT_MHZ); // hwSysInit(THIRTYSIX_MHZ); hwSysInit(TWENTYFOUR_MHZ); // hwSysInit(TWELVE_MHZ); // enable interrupts in the CPSR enableIRQ(); // enable the leds enable_leds(); // 48Mhz PCLK, divisor is 0x1a for 115200 console0Init(ONE_FIFTEEN_TWO_B); // enable the interrupt control register. enableTIMER0_INT(0x4, (unsigned) TIMER0_Handler ); }
static int32_t flash_detect(FlashInfo* flash) { uint32_t command[5], result[3]; IAP iap_entry; iap_entry = (IAP) IAP_LOCATION; /* get part ID */ command[0] = IAP_READ_PART_ID; disableIRQ(); iap_entry(command, result); enableIRQ(); if (result[0] != 0) return result[0]; switch (result[1]) { /* LPC2141, 32k Flash, 8k RAM */ case 0x0402FF01: /* LPC2142, 64k Flash, 16k RAM */ case 0x0402FF11: /* LPC2144, 128k Flash, 16k RAM */ case 0x0402FF12: /* LPC2146, 256k Flash, 32k+8k RAM */ case 0x0402FF23: { return -1; break; } /* have LPC2148 support only */ /* LPC2148, 512k Flash, 32k+8k RAM */ case 0x0402FF25: { flash->page_size = 0x1000; flash->page_nr = 26; flash->addr = 0x7C000; break; } default: return -1; } return 0; }
/** * \brief This function initializes the hardware * * * \details Sensors are set up, polynomials are calculated and other general preparations are made */ void setup(void) { initBluetoothStorage();//initialize space for variables used for Bluetooth Communication //-------------------Dave Setup--------------------- DAVE_STATUS_t status; status = DAVE_Init();//Initialization of DAVE APPs if (status == DAVE_STATUS_FAILURE) { /* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */ XMC_DEBUG("DAVE APPs initialization failed\n"); while (1U); } disableIRQ();//disables all Interrupts delay(2000);//waits 2000ms enableIRQ();//enables configurated Interrupts setup_STATE_LEDs();//setup Status-LED's WatchRC_Init();//initialize RC-Watchdog setup_UART_Trigger_limits();//setup Trigger-Limits of UART-FIFO PressureFIR = Initialize_FIR_Filter(PressureFIR, MOVING_AVERAGE);//initialize FIR Filter setupDPS310I2C();//initialize DPS310 getCoefficients();//get Coefficients of DPS310 setupDPS310();//setup DPS Hardware MPU9150_Setup();//configures the IMU delay(3000);//wait 3000ms to wait for ESC's to startup // initialize controller polynomials polynoms.b_roll[0]=parameter.P_roll-parameter.I_roll*parameter.T-parameter.P_roll*parameter.N_roll*parameter.T+parameter.N_roll*parameter.I_roll*parameter.T*parameter.T+parameter.D_roll*parameter.N_roll; polynoms.b_roll[1]=parameter.I_roll*parameter.T-2*parameter.P_roll+parameter.P_roll*parameter.N_roll*parameter.T-2*parameter.D_roll*parameter.N_roll; polynoms.b_roll[2]=parameter.P_roll+parameter.D_roll*parameter.N_roll; polynoms.a_roll[0]=1-parameter.N_roll*parameter.T; polynoms.a_roll[1]=parameter.N_roll*parameter.T-2; polynoms.b_pitch[0]=parameter.P_pitch-parameter.I_pitch*parameter.T-parameter.P_pitch*parameter.N_pitch*parameter.T+parameter.N_pitch*parameter.I_pitch*parameter.T*parameter.T+parameter.D_pitch*parameter.N_pitch; polynoms.b_pitch[1]=parameter.I_pitch*parameter.T-2*parameter.P_pitch+parameter.P_pitch*parameter.N_pitch*parameter.T-2*parameter.D_pitch*parameter.N_pitch; polynoms.b_pitch[2]=parameter.P_pitch+parameter.D_pitch*parameter.N_pitch; polynoms.a_pitch[0]=1-parameter.N_pitch*parameter.T; polynoms.a_pitch[1]=parameter.N_pitch*parameter.T-2; TIMER_Start(&Control_Timer);//start Timer for Controller }
void setSpeed(unsigned char sp) { disableIRQ(); switch(sp) { case SPEED_60: // turbo speed (60 mhz) BCFG0 = 0x100005EF; PLLCFG = 0x45; // 0100.0101 = PSEL=10=4 MSEL=00101=6 = 240mhz Fcco PLLFEED = 0xAA; PLLFEED = 0x55; VPBDIV = 0x00; BCFG0 = 0x100004A0; BCFG2 = 0x100004A0; BCFG1 = 0x00000C21; sysInfo |= 0x80; break; case SPEED_30: // normal speed (30 mhz) default: BCFG0 = 0x100005EF; PLLCFG = 0x42; // 0100.0010 = PSEL=10=4 MSEL=00010=3 PLLFEED = 0xAA; PLLFEED = 0x55; VPBDIV = 0x02; BCFG0 = 0x10000420; BCFG2 = 0x10000420; BCFG1 = 0x00000400; sysInfo &= 0x7F; break; } enableIRQ(); }
void ArchInterrupts::enableTimer() { enableIRQ(0); }
void ArchInterrupts::enableKBD() { enableIRQ(1); enableIRQ(9); }
void int_enable(void) { enableIRQ(); }
void eINT(void) { enableIRQ(); }
X86Kernel::X86Kernel() : Kernel(), ticks(0) { /* ICW1: Initialize PIC's (Edge triggered, Cascade) */ outb(PIC1_CMD, 0x11); outb(PIC2_CMD, 0x11); /* ICW2: Remap IRQ's to interrupts 32-47. */ outb(PIC1_DATA, PIC_IRQ_BASE); outb(PIC2_DATA, PIC_IRQ_BASE + 8); /* ICW3: PIC2 is connected to PIC1 via IRQ2. */ outb(PIC1_DATA, 0x04); outb(PIC2_DATA, 0x02); /* ICW4: 8086 mode, fully nested, not buffered, no implicit EOI. */ outb(PIC1_DATA, 0x01); outb(PIC2_DATA, 0x01); /* OCW1: Disable all IRQ's for now. */ outb(PIC1_DATA, 0xff); outb(PIC2_DATA, 0xff); /* Let the i8253 timer run continuously (square wave). */ outb(PIT_CMD, 0x36); outb(PIT_CHAN0, PIT_DIVISOR & 0xff); outb(PIT_CHAN0, PIT_DIVISOR >> 8); /* Make sure to enable PIC2 and the i8253. */ enableIRQ(2, true); enableIRQ(0, true); /* Setup exception handlers. */ for (int i = 0; i < 17; i++) { hookInterrupt(i, exception, 0); } /* Setup IRQ handlers. */ for (int i = 17; i < 256; i++) { /* Trap gate. */ if (i == 0x90) hookInterrupt(0x90, trap, 0); /* Hardware Interrupt. */ else hookInterrupt(i, interrupt, 0); } /* Install PIT (i8253) IRQ handler. */ hookInterrupt(IRQ(0), clocktick, 0); /* Initialize TSS Segment. */ gdt[USER_TSS].limitLow = sizeof(TSS) + (0xfff / 8); gdt[USER_TSS].baseLow = ((Address) &kernelTss) & 0xffff; gdt[USER_TSS].baseMid = (((Address) &kernelTss) >> 16) & 0xff; gdt[USER_TSS].type = 9; gdt[USER_TSS].privilege = 0; gdt[USER_TSS].present = 1; gdt[USER_TSS].limitHigh = 0; gdt[USER_TSS].granularity = 8; gdt[USER_TSS].baseHigh = (((Address) &kernelTss) >> 24) & 0xff; /* Let TSS point to I/O bitmap page. */ kernelTss.bitmap = PAGESIZE << 16; /* Load Task State Register. */ ltr(USER_TSS_SEL); }
int main(void){ SCS |= 0x01; FIODIR0 = 0; /* Just to make sure that all pins on Port0 are input. */ /* The following pins are output: */ FIODIR0 |= ((1<<21) | BACKLIGHT_PWM_PIN | SOUND_ENABLE_PIN | (1<<6)); /* TODO what is this pin for ? */ FIODIR0 |= (1<<12); FIOSET0 = (1<<12); setSpeed(SPEED_30); rand_seed(13); // initialize the random number generator /* Initialize the kernel. Kernel is not running yet */ kernel_init(); /* Initialize the display */ lcd_init(0); /* Initialize the serial port */ serial_init(38400); task_add(&serial_out); // Task 0 /* Enable IRQs. Now IRQ service routines start to run */ enableIRQ(); /* Enable radio communication */ RF_init(); // Task 1 == produce_send_token) /* Initialize backlight task */ inactivity_cnt = 0; // consider power on to be a user activity task_add(&backl_proc); // Task 2 startPWMIRQ(); /* Initialize keyboard handling */ key_init(); // Task 3 == key_scan() /* Build an initial model of the internal and external state of the world */ model_init(); // Task 4 == update_playtime() /* Show something to the user depending on model */ mainscreen_init(); // Task 5 == win_scroll_all() dbg("RESET"); /* Start the controller task - keeps model up to date - starts actions according to model - shows relevant information on the screen */ task_add(&controller); // Task 6 // Task 7 == assemble_line() /* Start the kernel scheduler */ while(1){ schedule(); }; return 0; }
int main() { disableIRQ(); disableFIQ(); *AT91C_AIC_IDCR = 0xffffffff; *AT91C_PMC_PCDR = 0xffffffff; *AT91C_PMC_PCER = (1 << AT91C_ID_PIOA); dbg_setup_uart(); printf("Initialising\n"); leds_arch_init(); clock_init(); process_init(); process_start(&etimer_process, NULL); ctimer_init(); robot_stepper_init(); enableIRQ(); cc2420_init(); cc2420_set_pan_addr(0x2024, 0, &uip_hostaddr.u16[1]); cc2420_set_channel(RF_CHANNEL); rime_init(nullmac_init(&cc2420_driver)); printf("CC2420 setup done\n"); rimeaddr_set_node_addr(&node_addr); #if WITH_UIP { uip_ipaddr_t hostaddr, netmask; uip_init(); uip_ipaddr(&hostaddr, 172,16, rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]); uip_ipaddr(&netmask, 255,255,0,0); uip_ipaddr_copy(&meshif.ipaddr, &hostaddr); printf("Host addr\n"); uip_sethostaddr(&hostaddr); uip_setnetmask(&netmask); uip_over_mesh_set_net(&hostaddr, &netmask); /* uip_fw_register(&slipif);*/ /*uip_over_mesh_set_gateway_netif(&slipif);*/ uip_fw_default(&meshif); printf("Mesh init\n"); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); printf("uIP started with IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* WITH_UIP */ #if WITH_UIP process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ #endif /* WITH_UIP */ printf("Heap size: %ld bytes\n", &__heap_end__ - (char*)sbrk(0)); printf("Started\n"); autostart_start(autostart_processes); printf("Processes running\n"); while(1) { do { /* Reset watchdog. */ wdt_reset(); } while(process_run() > 0); /* Idle! */ /* Stop processor clock */ *AT91C_PMC_SCDR |= AT91C_PMC_PCK; } return 0; }
/************************************************************************* main ==== **************************************************************************/ int main(void) { int c, i; // PLL and MAM HalSysInit(); #ifdef LPC214x // init DBG ConsoleInit(60000000 / (16 * BAUD_RATE)); #else // init DBG ConsoleInit(72000000 / (16 * BAUD_RATE)); #endif configureADCPort(AD0_3); DBG("Initialising USB stack\n"); // initialise stack USBInit(); // register descriptors USBRegisterDescriptors(abDescriptors); // register class request handler USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData); // register endpoint handlers USBHwRegisterEPIntHandler(INT_IN_EP, NULL); // register frame handler USBHwRegisterFrameHandler(USBFrameHandler); // register device event handler USBHwRegisterDevIntHandler(USBDevIntHandler); USBInitializeUSBDMA(udcaHeadArray); USBEnableDMAForEndpoint(ISOC_IN_EP); DBG("Starting USB communication\n"); #ifdef LPC214x (*(&VICVectCntl0+INT_VECT_NUM)) = 0x20 | 22; // choose highest priority ISR slot (*(&VICVectAddr0+INT_VECT_NUM)) = (int)USBIntHandler; #else VICVectCntl22 = 0x01; VICVectAddr22 = (int)USBIntHandler; #endif // set up USB interrupt VICIntSelect &= ~(1<<22); // select IRQ for USB VICIntEnable |= (1<<22); enableIRQ(); // connect to bus USBHwConnect(TRUE); int x = 0; c = EOF; //populate source data with all 'B's for(i = 0; i < ISOC_INPUT_DATA_BUFFER_SIZE; i++ ) { inputIsocDataBuffer[i] = 'B'; } int cnt = 0; const int interval = 100000; // echo any character received (do USB stuff in interrupt) for(;;) { x++; U32 temp = cADC_Result(AD0_3); if( temp >= 0 && temp <= 1024 ) currentADCReadValue = temp; if (x == interval) { qq++; IOSET0 = (1<<11); //turn on led } else if (x >= (interval*2)) { IOCLR0 = (1<<11); //turn off led x = 0; } } return 0; }
/* Return Values: 0 = OK 1 = too manny pulse lengths 2 = abort 3 = too long */ unsigned char captureIR(struct ir_raw_* capture) { unsigned long hightime, lowtime; unsigned long T0count; unsigned short highpulse, lowpulse; unsigned long T1count; unsigned long timeout; unsigned char status; unsigned char wide; while(ANYKEY); setSpeed(SPEED_60); disableIRQ(); T0MCR = 0x00; FIOSET0 |= (1<<4); FIOCLR0 |= (1<<12); PINSEL1 |= (1<<27); T0CCR = (1<<9) | (1<<10) | (1<<11); capture->widetable[0].count = 0; capture->widetable[1].count = 0; capture->count = 0; status = 0; T0TC = 0; while (T0TC < 5000); T0IR = 0xff; while (!T0IR && !ANYKEY); if(!ANYKEY) { T0TC = 0; T0IR = 0xff; T0count = waitIrHi(&highpulse,&hightime,0); capture->pulsetime = (hightime * 1000) / highpulse; capture->data[0] = (decodewide(highpulse, &capture->widetable[1]) & 0x0F)<<4; while (!(T0IR)); T0IR = 0xff; T1count= T0CR3; while ((capture->count < max_capture_data-1) && !status) { lowtime = T1count-T0count; T0count = waitIrHi(&highpulse,&hightime,T1count); lowpulse = ((lowtime *1000)+(capture->pulsetime / 2)) / capture->pulsetime; wide = decodewide(lowpulse, &capture->widetable[1]); if(wide & 0xf0) status = 2; capture->data[capture->count] |= wide; wide = decodewide(highpulse, &capture->widetable[1]); if(wide & 0xf0) status = 2; capture->count++; capture->data[capture->count] = wide<<4; timeout = T0count + 500000; while (!(T0IR) && !status) { if (T0TC > timeout) status =1; } T0IR = 0xff; T1count= T0CR3; } } else status = 3; if(capture->count == max_capture_data-1) status = 4; T0TC = 0; T0MCR = 0x03; FIOSET0 |= (1<<12); T0CCR = 0; T0IR = 0xff; enableIRQ(); setBacklight(BL_AUTO); setSpeed(SPEED_30); return status - 1; }