void main(void) { /* Write your local variable definition here */ int a = 0; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ /* Write your code here */ setReg(ADC_CLIST1,0x12); setReg(ADC_SDIS,0xFF88); setRegBitGroup(ADC_CTRL1,SMODE,0x01); AD1_Enable(); Cpu_EnableInt(); while(1) { WDog1_Clear(); a++; if(a) a = 0; } }
/* ** =================================================================== ** Method : SenRpm_getValue ** Description : Devuelve el último valor procesado del AD ** =================================================================== */ int SenRpm_getValue(struct SensorRpm * self){ int val; Cpu_DisableInt(); val= self->procVal; Cpu_EnableInt(); return val; }
/* ** =================================================================== ** Method : Timer_getCuenta ** Description : Regresa la cuenta actual que se resetea al llegar al tiempo ** =================================================================== */ ulong Timer_getCuenta(struct Timer * self){ ulong cuentaTmp; ulong nextCuentaTmp; ulong tiempoTmp; if(Timer_isfinish(self) ) return 0; cuentaTmp = BaseTimers_getCuenta( self->baseTimer ); Cpu_DisableInt(); nextCuentaTmp = self->next_cuenta; tiempoTmp = self->tiempo; Cpu_EnableInt(); return cuentaTmp - (nextCuentaTmp - tiempoTmp); }
void POWSNS_Check(void){ if (PWSN_GetVal() && !PwsnError) //Pwsn is high?? { pwsn++; // inc counter if (pwsn==30){ // is counter = 30? Cpu_DisableInt(); O2_PutVal(0); O4_PutVal(0); O6_PutVal(0); O7_PutVal(0); Display1_PutVal(0); #ifdef _PROGRAMADOR GuardarPrograma(); #endif PwsnError=TRUE; Cpu_EnableInt(); } }else pwsn=0; // put counter=0 }
void DMA_Run(void) { for(;;) { //DMA_PDD_SetDestinationAddress(DMA_BASE_PTR, 0, (uint32_t)&TPM0_C1V); /* set destination address */ DMA_PDD_SetSourceAddress(DMA_BASE_PTR, 0, (uint32_t)&dmaSrc[0]); /* set source address */ DMA_PDD_SetDestinationAddress(DMA_BASE_PTR, 0, (uint32_t)&dmaDst[0]); /* set destination address */ DMA_PDD_SetByteCount(DMA_BASE_PTR, 0, sizeof(dmaSrc)); DMACH1_EnableRequest(DMACH1_DeviceData); /* enable first transfer */ Cpu_EnableInt(); /* enable interrupts */ for(;;) { //WAIT1_Waitms(200); //DMA1_SetTransactionCount(DMACH1_DeviceData, 3); #if SW_DMA_REQUEST DMA1_SetRequestCount(DMACH1_DeviceData, 1); /* 1: 100->101->102->103->104 3: 100->103->106 */ DMACH1_StartTransfer(DMACH1_DeviceData); #endif //errors = DMACH1_GetError(DMACH1_DeviceData); } } }
/***************************************************************************** * void main(void) * * Main application. * * In: n/a * * Out: n/a *****************************************************************************/ void main(void) { UInt16 state; char *temp_ptr; extern word _vba; uint8_t sw0, sw1; INTC_VBA = ((word)&_vba) >> (21-INTC_VBA_BITS); /* Set Vector Base Address */ /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ /*StartDelay = pmem_read((unsigned int *)BOOT_START_DELAY_PLACE) & 0x00FF; if(!StartDelay) bootExit(); else bootTimerInit();*/ /* Write your code here */ GPIO_A_PER &= ~GPIO_A_PER_PE0_MASK; // set to GPIO mode GPIO_A_PER &= ~GPIO_A_PER_PE1_MASK; GPIO_A_DDR |= GPIO_A_DDR_DD0_MASK; // set as output GPIO_A_DDR |= GPIO_A_DDR_DD1_MASK; GPIO_A_DR &= ~GPIO_A_DR_D0_MASK; // set low GPIO_A_DR &= ~GPIO_A_DR_D1_MASK; Cpu_Delay100US(5000); // power-up delay // Initialize R0,R1,M01, and N for circular buffer (including shadows) asm { swap shadows ;// Switch to shadow registers moveu.w #(RX_DATA_SIZE-1),M01 ;// Set buffer size moveu.w #rx_data,R0 ;// Set starting address moveu.w #QSCI_STAT,R1 ;// Use R1 for SCI status register moveu.w #0,N ;// N is unused swap shadows ;// Switch back to normal registers } // with DEFCON 17, we used a timer to keep the badge in bootloader mode on power up for 10 seconds // for DEFCON 18, the bootloader mode is only enabled if both buttons are held down on power up // otherwise it jumps directly to the user application. no timer necessary, so that code is commented out // check buttons GPIO_C_PUR |= GPIO_C_PUR_PU0_MASK; // enable pull-up GPIO_C_PUR |= GPIO_C_PUR_PU1_MASK; GPIO_C_DDR &= ~GPIO_C_DDR_DD0_MASK; // set as input GPIO_C_DDR &= ~GPIO_C_DDR_DD1_MASK; GPIO_C_PER &= ~GPIO_C_PER_PE0_MASK; // set to GPIO mode GPIO_C_PER &= ~GPIO_C_PER_PE1_MASK; Cpu_Delay100US(1000); // setup delay #define SW0_PIN_MASK ((byte)1) /* Pin mask */ #define SW1_PIN_MASK ((byte)2) /* Pin mask */ sw0 = !((bool)(getRegBits(GPIO_C_RAWDATA,SW0_PIN_MASK))); sw1 = !((bool)(getRegBits(GPIO_C_RAWDATA,SW1_PIN_MASK))); if (sw0 || sw1) // one or more buttons has been pressed { Cpu_Delay100US(1000); // give the user time to press both buttons (also serves as 100mS debounce) sw0 = !((bool)(getRegBits(GPIO_C_RAWDATA,SW0_PIN_MASK))); sw1 = !((bool)(getRegBits(GPIO_C_RAWDATA,SW1_PIN_MASK))); } if (sw0 && sw1) // if both buttons have been pressed, enter bootloader { // Turn on LEDs so the user knows we're here GPIO_A_DR |= GPIO_A_DR_D0_MASK; // set high GPIO_A_DR |= GPIO_A_DR_D1_MASK; // Initialize globals mem_init(rx_data, NULL, RX_DATA_SIZE); data_out = data_in = rx_data; state = INITIAL_STATE; temp_ptr = rx_data; // Disable protection setReg(FM_PROT,BOOT_PROT_VALUE); // Output banner sci_tx(&StrCopyright[0]); // Now it is safe to enable interrupts Cpu_EnableInt(); do { // State: Initial State if (state == INITIAL_STATE) { status = 0; sci_tx(&StrWaitingSrec[0]); sci_tx_char(XON); state = WAIT_FOR_S; } if (data_in != temp_ptr) { //Timer_Disable(); // State: Wait for Header "S" if (state == WAIT_FOR_S) { temp_ptr = data_out; if (get_char(&temp_ptr) == 'S') { state = WAIT_FOR_0; } else { get_char(&data_out); } } // State: Wait for Header "0" else if (state == WAIT_FOR_0) { if (get_char(&temp_ptr) == '0') { state = WAIT_FOR_EOL; } else { get_char(&data_out); state = WAIT_FOR_S; } } // State: Wait for EOL else if (state == WAIT_FOR_EOL) { if (get_char(&temp_ptr) == '\r') { if (!(status & TX_XOFF)) { sci_tx_char(XOFF); status |= TX_XOFF; } srec_decode(); temp_ptr = data_out; } } } else { if (status & TX_XOFF) { sci_tx_char(XON); status &= ~TX_XOFF; } } // State: Error if (status & DOWNLOAD_ERROR) { sci_tx(StrErr); sci_tx(int_to_string(status)); state = INITIAL_STATE; sci_tx(StrNewLine); } //bootTimerCheck(); } while (status != DOWNLOAD_OK); sci_tx(StrNewLine); sci_tx(&StrLoaded[0]); } bootExit(); }
/* ** =================================================================== ** Method : SensorHandler ** Description : Checkea si hay un nuevo valor del AD, ** y si lo hay lo procesa. ** =================================================================== */ void SenRpm_procesar(void* _self){ struct SensorRpm *_s=(struct SensorRpm *)_self; int filtro = _s->conf->iFiltro; ulong valProv=0; float val_f=0; ulong microseg=0; uint pulsos=0; uint mult=0; uchar err; if(_s->procesar==TRUE){ _s->procesar=FALSE; microseg=CapturadorPT2_getMicroSegundos(_s->capturador); //(_s->capturador->ultimoproceso.microsegundos);// pulsos=CapturadorPT2_getPulsos(_s->capturador); //_s->capturador->ultimoproceso.pulsos;// mult= 600 * pow10(_s->conf->iDecimales); //600 6000 o 60000 if(microseg!=0){ valProv=(ulong)pulsos*mult; val_f=valProv/(((float)_s->conf->pulsosPorVuelta)*microseg/100000); val_f=(val_f*SenRpm_getAjusteGanancia(_s))/(float)1000; valProv = val_f; if(valProv<65535){ valProv= filtrarL (valProv,filtro,10,200,&buffer); Cpu_DisableInt(); _s->procVal=(long)valProv; buffer=valProv; _s->bufferFiltro=valProv; _s->state=RPM_OK; _s->ContadorUf=0; Cpu_EnableInt(); } else{ Cpu_DisableInt(); _s->state=RPM_OF; Cpu_EnableInt(); } }else { if(_s->ContadorUf<RPM_MAX_UF_COUNT){ _s->ContadorUf++; _s->state=RPM_OK; valProv=(ulong)100*mult/(_s->conf->pulsosPorVuelta*_s->ContadorUf*Timer_getTime(&_s->timerMuestreo)); //calculo cual seria el valor de rpm si hubiese entrado un solo pulso //Nuevo valProv= filtrarL (valProv,filtro,10,200,& _s->bufferFiltro); //Fin Nuevo if(_s->procVal>valProv) _s->procVal=valProv; //redusco el valor de rpms }else{ _s->procVal=filtrarL (0,filtro,10,200,& _s->bufferFiltro); } } setValCalculado(valProv,0); } }