/******************************************************************************* * 打开关闭结点 ********************************************************************************/ void configNode(uint8 config) { //LCD_Char_1_PrintNumber(config); if(config < 19) switch(config) { case 0 : { Timer_Start(); /* 开启定时器 */ break; } case 1 : { UART_1_PutStringConst("soe"); break; } case 2 : { UART_2_PutStringConst("soe"); break; } case 3 : { Timer_Start(); UART_1_PutStringConst("soe"); UART_2_PutStringConst("soe"); break; } case 10 : { Timer_Stop(); /* 关闭定时器 */ break; } case 11 : { UART_1_PutStringConst("sce"); break; } case 12 : { UART_2_PutStringConst("sce"); break; } case 13 : { Timer_Stop(); UART_1_PutStringConst("sce"); UART_2_PutStringConst("sce"); break; } default : { break; } } }
/* Valeur mini ? 1ms Valeur neutre ? 1,50 ms Valeur maxi ? 2,0ms */ void EXTI9_5_RFHandler(){ if(Port_IO_Read(GPIOB, PIN_RF)){ Timer_Run(TIM_RF_CNT); } else { timcnt = TIM_RF_CNT->CNT; Timer_Stop(TIM_RF_CNT); TIM_RF_CNT->CNT = 0; timcnt = (timcnt*TIM_RF_US)/autoreload; if (first>10){ correction = timcnt; first=0; } else if (first!=0) { first+=1; } else { commande = timcnt - correction; if (commande > commande_max){ commande_max=commande; } else if ((-commande) > commande_max){ commande_max=(-commande); } if (commande > seuilCommande) { Port_IO_Set(GPIOA, 2); rapport = (float) commande/commande_max; } else if (commande < -seuilCommande) { Port_IO_Reset(GPIOA, 2); rapport = (float) (-commande)/commande_max; } else { rapport = 0; } update_PWM(TIM2, 1.0f-rapport, 2); } } EXTI->PR |= 0x1 << 6; }
void Connected(event e, void* data) { Timer_Stop(&connectionTimer); Leds_GreenOn(); Timer_CreateConfiguration(&pingerTimer, 2000000, TIMER_MODE_RELAXED_CONTINUES, Pinger); Timer_Start(&pingerTimer); }
// cancel all scheduled iterations void Metro_stop( int ix ) { if( ix < 0 || ix >= max_num_metros ){ printf("metro_stop: bad index\n"); return; } Metro_t* t = &(metros[ix]); if( t->status == METRO_STATUS_RUNNING ){ t->status = METRO_STATUS_STOPPED; Timer_Stop( ix ); } }
/* ** =================================================================== ** Method : BaseTiempo_constructor (bean TimeDate) ** ** Description : ** =================================================================== */ void BaseTiempo_constructor(void * _self,word Year,byte Month,byte Day,byte Hour,byte Min,byte secs,bool start) { struct BaseTiempo * self =(struct BaseTiempo *) _self; struct BaseTiempoClass * _class =(struct BaseTiempoClass *) classOf(_self); TmDt1_Constructor(_self,Year,Month,Day,Hour,Min,secs); self->configurado = FALSE; newAlloced(&self->timer,&RlxMTimer,(ulong)1000,_class->inc1Segundo,_self); if(!start) Timer_Stop(&self->timer); }
int main() { //Initializations clearPacketSBD(); clearPacketwind(); UART_Wind_Start(); UART_SBD_Start(); psoc_Start(); isr_Wind_StartEx(IntWind); SBD_reply_StartEx(SBD_int); clock_Start(); master_Start(); ADC_Start(); CyGlobalIntEnable; //Writes to magnetometer to be read from (not calibration mode) writeregister((uint8) 0x00, (uint8) 0x70); writeregister((uint8) 0x01, (uint8) 0xA0); writeregister((uint8) 0x02, (uint8) 0x00); CyDelay(15000u); clearPacketwind(); //Query Sensor for wind, pressure, temperature and humidity data UART_Wind_PutString("0R\r\n"); timeout_isr_StartEx(windtimer); timer_clock_Start(); Timer_Start(); windtime = 0; for(;;) { //When the packet is received takes other sensor data, sends packet and turns off power if(windpacketReceived){ Timer_Stop(); timer_clock_Stop(); timeout_isr_Stop(); windprocessPacket(); } //Here to clear any unexpected outputs from SBD Warrior if(SBDpacketReceived) { clearPacketSBD(); } //changes if(windtimeout == 1) { windbroke = 1; windprocessPacket(); } //end changes } }
/******************************************************************************* * Function Name: Timer_Sleep ******************************************************************************** * * Summary: * Stops the component operation and saves the user configuration. * * Parameters: * None * * Return: * None * *******************************************************************************/ void Timer_Sleep(void) { if(0u != (Timer_BLOCK_CONTROL_REG & Timer_MASK)) { Timer_backup.enableState = 1u; } else { Timer_backup.enableState = 0u; } Timer_Stop(); Timer_SaveConfig(); }
//returns the checksum int Zdma1Int(int srcAddr,int dstAddr,int length,int dw) { int time; zdma1Done=0; rINTMSK=~(BIT_GLOBAL|BIT_ZDMA1); rZDISRC1=srcAddr|(dw<<30)|(1<<28); // inc rZDIDES1=dstAddr|( 2<<30)|(1<<28); // inc rZDICNT1=length |( 2<<28)|(1<<26)|(3<<22)|(1<<20); //whole,unit transfer,int@TC,enable DMA rZDCON1=0x1; // start!!! Timer_Start(3);//128us resolution while(zdma1Done==0); time=Timer_Stop(); Uart_Printf(" ZDMA1 %8x->%8x,%x: time = %dms\n",srcAddr,dstAddr,length,time);//*128E-6); rINTMSK=BIT_GLOBAL; }
/******************************************************************************* * Function Name: Timer_Sleep ******************************************************************************** * * Summary: * Stop and Save the user configuration * * Parameters: * void * * Return: * void * * Global variables: * Timer_backup.TimerEnableState: Is modified depending on the * enable state of the block before entering sleep mode. * *******************************************************************************/ void Timer_Sleep(void) { #if(!Timer_UDB_CONTROL_REG_REMOVED) /* Save Counter's enable state */ if(Timer_CTRL_ENABLE == (Timer_CONTROL & Timer_CTRL_ENABLE)) { /* Timer is enabled */ Timer_backup.TimerEnableState = 1u; } else { /* Timer is disabled */ Timer_backup.TimerEnableState = 0u; } #endif /* Back up enable state from the Timer control register */ Timer_Stop(); Timer_SaveConfig(); }
int Zdma0Int(int srcAddr,int dstAddr,int length,int dw) //returns the checksum { int time; zdma0Done=0; rINTMSK=~(BIT_GLOBAL|BIT_ZDMA0); rZDISRC0=srcAddr|(dw<<30)|(1<<28); // inc rZDIDES0=dstAddr|( 2<<30)|(1<<28); // inc rZDICNT0=length |( 2<<28)|(1<<26)|(3<<22)|(1<<20); //whole,unit transfer,int@TC,enable DMA rZDCON0=0x1; // start!!! Timer_Start(3);//128us resolution while(zdma0Done==0); time=Timer_Stop(); Uart_Printf(" ZDMA0 %8x->%8x,%x: time = %dms\n",srcAddr,dstAddr,length,time);//*128E-6); rINTMSK=BIT_GLOBAL; return time; }
bool Notify_Wait( Notify_t *pstNotify_, K_ULONG ulWaitTimeMS_, bool *pbFlag_ ) { bool bUseTimer = false; Timer_t stNotifyTimer; CS_ENTER(); if (ulWaitTimeMS_) { bUseTimer = true; Thread_SetExpired( Scheduler_GetCurrentThread(), false ); Timer_Init( &stNotifyTimer ); Timer_Start( &stNotifyTimer, 0, ulWaitTimeMS_, TimedNotify_Callback, (void*)pstNotify_); } Block(g_pstCurrent); if (pbFlag_) { *pbFlag_ = false; } CS_EXIT(); Thread_Yield(); if (pbFlag_) { *pbFlag_ = true; } if (bUseTimer) { Timer_Stop( &stNotifyTimer ); return ( Thread_GetExpired( Scheduler_GetCurrentThread() ) == false ); } return true; }
void windprocessPacket(){ struct evappacket sendpacket; SensirionData tempandrh; float32 float32size; int16 int16size; uint8 uint8size; uint16 uint16size; uint32 uint32size; int i = 0; //int j = 0; int gpsvalid = 0; int16 watertemperature; int16 externalairtemp; //int count = 0; //char weatherdata[256]; char gpsdata[64]; char8 text[256]; float time; char validornot; float northgps; float westgps; uint32 date; int matches; uint16 externalrh; uint8 Vtempbroke = 0; uint8 Vpressurebroke = 0; uint8 Vhumiditybroke = 0; tempandrh.temp = 0; tempandrh.rh = 0; tempandrh.valid = 1; // get magnetometer reading readingx = getmeasurement((uint8) 3,(uint8) 4); readingy = getmeasurement((uint8) 7,(uint8) 8); readingz = getmeasurement((uint8) 5,(uint8) 6); heading = getheading(readingz, readingx); // z then x when mounted with board parallel to drifter pole // get reading from thermocouple output as an integer with last two spots as hundreths and thousandths watertemperature = gettemperature(); voltage = getvoltage(); tempandrh = TakeTempRHReading(); clearPacketSBD(); //query for last gps fix and wait for response from SBD Warrior UART_SBD_PutString("0000000000000000000000000\r\n"); UART_SBD_PutString("AT-WSGPLF\r\n"); UART_SBD_PutString("AT-WSGPLF\r\n"); timeout_isr_StartEx(windtimer); timer_clock_Start(); Timer_Start(); windtime = 0; gpstimeout = 0; while(SBDpacketReceived == 0) { if(gpstimeout == 1 && gpsbroke != 1) { gpsbroke = 1; } } clearPacketSBD(); while(SBDpacketReceived == 0 && gpsbroke != 1) { if(gpstimeout == 1) { gpsbroke = 1; } } SBD_reply_Stop(); Timer_Stop(); timer_clock_Stop(); timeout_isr_Stop(); //extracts needed data from GPRMC Sentance matches = sscanf(SBDData, "$GPRMC,%f,%c,%f,%*c,%f,%*c,%*f,%*f,%d", &time, &validornot, &northgps, &westgps, &date); if(validornot == 'A' && matches == 5) { gpsvalid = 1; } else { gpsvalid = 0; } SBD_reply_Start(); i = 0; // fetchs each parameter needed from the weather sensor and put each parameter in a c string char windDirection[4]; for(i=0;i<3; i++) { windDirection[i] = windData[15+i]; } windDirection[3] = '\0'; uint16 winddirection = atoi(windDirection); char windSpeed[4]; for(i=0;i<3;i++) { windSpeed[i] = windData[39+i]; } windSpeed[3] = '\0'; uint8 windspeed = atof(windSpeed) * 10; char airtemp[5]; for(i=0;i<4;i++) { airtemp[i] = windData[60+i]; } if(strchr(airtemp, '#')) { Vtempbroke = 1; } airtemp[4] = '\0'; int16 airtemperature = atof(airtemp) * 10; char relhumidity[5]; for(i=0;i<4;i++) { relhumidity[i] = windData[69+i]; } if(strchr(relhumidity, '#')) { Vhumiditybroke = 1; } relhumidity[4] = '\0'; uint16 humidity = atof(relhumidity) * 10; char airpressure[6]; for(i=0;i<6;i++) { airpressure[i] = windData[78+i]; } if(strchr(airpressure, '#')) { Vpressurebroke = 1; } airpressure[5] = '\0'; uint16 pressure = atof(airpressure) * 10; sendpacket.gpstime = time; sendpacket.gpsnorth = northgps; sendpacket.gpswest = westgps; sendpacket.gpsdate = date; sendpacket.VaisalawindDirection = winddirection; sendpacket.VaisalawindSpeed = windspeed; sendpacket.Vaisalaairtemp = airtemperature; sendpacket.externaltemp = (int16)(tempandrh.temp * 100); sendpacket.Vaisalarelhumidity = humidity; sendpacket.RHsensor = tempandrh.rh * 100; sendpacket.Vaisalaairpressure = pressure; sendpacket.Thermocouplewatertemperature = watertemperature; sendpacket.Magnetometerheading = (uint16)heading; sendpacket.battery = voltage; if (windbroke == 1) { sendpacket.VaisalawindDirection = 65535; sendpacket.VaisalawindSpeed = 255; sendpacket.Vaisalaairtemp = -32768; sendpacket.Vaisalarelhumidity = 65535; sendpacket.Vaisalaairpressure = 32768; } if(Vpressurebroke == 1) { sendpacket.Vaisalaairpressure = 32768; } if(Vtempbroke == 1) { sendpacket.Vaisalaairtemp = -32768; } if(Vhumiditybroke == 1) { sendpacket.Vaisalarelhumidity = 65535; } if (gpsbroke == 1) { sendpacket.gpstime = -1; sendpacket.gpsnorth = 0; sendpacket.gpswest = 0; sendpacket.gpsdate = 4294967295; } if(tempandrh.valid == 0) { sendpacket.externaltemp = -32768; sendpacket.RHsensor = 65535; } //sprintf(text, "AT-WSMOST=%s,%s,%s,%s,%s,%s,%d,%d\r\n", gpsdata, windDirection, windSpeed, airtemp, relhumidity, airpressure, (int)heading, (uint16)watertemperature); //start changes if(gpsvalid == 1) { UART_SBD_PutString("0000000000000000000000000\r\n"); UART_SBD_PutString("0000000000000000000000000\r\n"); UART_SBD_PutString("AT-WSMOBW=34\r\n"); UART_SBD_PutArray(&sendpacket.gpstime, sizeof(float32size)); UART_SBD_PutArray(&sendpacket.gpsnorth, sizeof(float32size)); UART_SBD_PutArray(&sendpacket.gpswest, sizeof(float32size)); UART_SBD_PutArray(&sendpacket.gpsdate, sizeof(uint32size)); UART_SBD_PutArray(&sendpacket.VaisalawindDirection, sizeof(uint16size)); UART_SBD_PutArray(&sendpacket.VaisalawindSpeed, sizeof(uint8size)); UART_SBD_PutArray(&sendpacket.Vaisalaairtemp, sizeof(int16size)); UART_SBD_PutArray(&sendpacket.externaltemp, sizeof(int16size)); UART_SBD_PutArray(&sendpacket.Vaisalarelhumidity, sizeof(uint16size)); UART_SBD_PutArray(&sendpacket.RHsensor, sizeof(uint16size)); UART_SBD_PutArray(&sendpacket.Vaisalaairpressure, sizeof(uint16size)); UART_SBD_PutArray(&sendpacket.Magnetometerheading, sizeof(uint16size)); UART_SBD_PutArray(&sendpacket.Thermocouplewatertemperature, sizeof(int16size)); UART_SBD_PutArray(&sendpacket.battery, sizeof(uint8size)); UART_SBD_PutArray(&sendpacket.dummychecksum, sizeof(uint16size)); } else { UART_SBD_PutString("0000000000000000000000000\r\n"); UART_SBD_PutString("0000000000000000000000000\r\n"); UART_SBD_PutString("AT-WSMOBW=1\r\n"); UART_SBD_PutString("I"); } //end changes UART_SBD_PutString("0000000000000000000000000\r\n"); //UART_SBD_PutString("AT-WSSBDIS\r\n"); //UART_SBD_PutString(text); clearPacketSBD(); clearPacketwind(); UART_SBD_PutString("0000000000000000000000000\r\n"); UART_SBD_PutString("AT-WSEPOFF\r\n"); UART_SBD_PutString("AT-WSEPOFF\r\n"); clearPacketSBD(); CyDelay(30000); }
void OnTimePass(void*a){ Step=0; Timer_Stop(&comu_timer); }
/******************************************************************** // 语法格式:void DMA_M2M(int ch,int srcAddr,int dstAddr,int tc,int dsz,int burst) // 功能描述: DMA方式内存拷贝 // 入口参数: // : int ch:DMA通道 0-DMA0, 1-DMA1, 2-DMA2, 3-DMA3 // : int srcAddr:源地址 // : int dstAddr:目的地址 // : int tc:初始传输计数值 // : int dsz:传输数据宽度 0:1字节 1:2字节 2:4字节 // : int burst:自动传输的传输宽度 0-单元传输(一个字节) 1-突发模式传输(四个字节) // 出口参数: 无 *********************************************************************/ void DMA_M2M(int ch,int srcAddr,int dstAddr,int tc,int dsz,int burst) { int i,time; volatile U32 memSum0=0,memSum1=0; DMA *pDMA; int length; length=tc*(burst ? 4:1)*((dsz==0)+(dsz==1)*2+(dsz==2)*4); //确定一次传输的字节数( 传输单元模式 * 传输数据宽度 ) Uart_Printf("[DMA%d MEM2MEM Test]\n",ch); switch(ch) { case 0: pISR_DMA0 = (unsigned)Dma0Done; EnableIrq(BIT_DMA0); //open DMA0 INTERRUPT pDMA=(void *)0x4b000000; break; case 1: pISR_DMA1 = (unsigned)Dma1Done; EnableIrq(BIT_DMA1); //open DMA1 INTERRUPT pDMA=(void *)0x4b000040; break; case 2: pISR_DMA2 = (unsigned)Dma2Done; EnableIrq(BIT_DMA2); //open DMA2 INTERRUPT pDMA=(void *)0x4b000080; break; case 3: pISR_DMA3 = (unsigned)Dma3Done; EnableIrq(BIT_DMA3); //open DMA3 INTERRUPT pDMA=(void *)0x4b0000c0; break; } Uart_Printf("DMA%d %8xh->%8xh,size=%xh(tc=%xh),dsz=%d,burst=%d\n",ch, srcAddr,dstAddr,length,tc,dsz,burst); Uart_Printf("Initialize the src.\n"); for(i=srcAddr;i<(srcAddr+length);i+=4) { *((U32 *)i)=i^0x55aa5aa5; //向源地址写入任意数据 写入长度为length memSum0+=i^0x55aa5aa5; //将写入数据累加,为校验读出数据的准确性 } Uart_Printf("DMA%d start\n",ch); dmaDone=0; pDMA->DISRC=srcAddr; //设置源地址 pDMA->DISRCC=(0<<1)|(0<<0); //设置源控制寄存器 inc,AHB pDMA->DIDST=dstAddr; //设置目的地址 pDMA->DIDSTC=(0<<1)|(0<<0); //设置目的控制寄存器 inc,AHB pDMA->DCON=(1<<31)|(1<<30)|(1<<29)|(burst<<28)|(1<<27)| (0<<23)|(1<<22)|(dsz<<20)|(tc); //DMA控制寄存器 HS,AHB sync,enable interrupt,whole, SW request mode,relaod off pDMA->DMASKTRIG=(1<<1)|1; //DMA on, SW_TRIG Timer_Start(3);//128us resolution while(dmaDone==0); time=Timer_Stop(); Uart_Printf("DMA transfer done.\n"); Uart_Printf("time = %u MS\n", time*128/1000); DisableIrq(BIT_DMA0); DisableIrq(BIT_DMA1); DisableIrq(BIT_DMA2); DisableIrq(BIT_DMA3); for(i=dstAddr;i<dstAddr+length;i+=4) { memSum1+=*((U32 *)i)=i^0x55aa5aa5; } Uart_Printf("\n memSum0=%x,memSum1=%x\n",memSum0,memSum1); if(memSum0==memSum1) Uart_Printf("DMA test result--------------------------------------O.K.\n"); else Uart_Printf("DMA test result--------------------------------------ERROR!!!\n"); }
void BatteryController_Task(void) { SoftwareInit(); uint16_t i; timer_t balanceDoneTimer; Timer_Setup(&balanceDoneTimer, NULL); // Run this task forever. // todo: Update this to variable that disables on error while(1) { I2C_Update(); state_t state = GetState(); if ((state == CHARGE) || (state == CHARGE_BALANCE)) { for (i = 0; i < CELLS_IN_SERIES; i++) { // If any cell above maximum cell voltage if (cells[i].voltage >= MAX_CELL_VOLTAGE) { // If only charging, go to wait. If charge and balance, // go to balance. (state == CHARGE) ? SetState(WAIT) : SetState(BALANCE); } if (cells[i].voltage >= MAX_CELL_CRITICAL_VOLTAGE) { // Go into error state. // todo: Assert error SetState(ERROR); } } } if ((state == BALANCE) || (state == CHARGE_BALANCE)) { // todo: This probably needs changed. We will leave balancing // as soon as no cells are balancing but we should wait for // relaxation time before knowing for sure to leave this state Bool doneBalancing = TRUE; for (i = 0; i < CELLS_IN_SERIES; i++) { if (batteryController_NeedsBalanced(&cells[i])) { cells[i].balance = TRUE; doneBalancing = FALSE; } else { cells[i].balance = FALSE; } } if (doneBalancing) { /// No cells balancing. Start timer that will transition /// states if cell doesn't balance in #BALANCE_RELAXATION_TIME if (!Timer_IsActive(&balanceDoneTimer)) { Timer_Start(&balanceDoneTimer, BALANCE_RELAXATION_TIME); } } else { /// Cell still balancing. Stop balancer timeout timer. Timer_Stop(&balanceDoneTimer); } } if (state == WAIT) { //TEMPORARY uint8_t expanderInputPort0 = I2C_GetPortInput(PORT_0); uint8_t expanderInputPort1 = I2C_GetPortInput(PORT_1); uint16_t * testPtr = NULL; /// Update SPI outputs Uint16 i = 0; for (i = 0; i < DRV8860_IN_SERIES; i++) { /// Open all relays SPI_PushToQueue(0xFF, RELAYS); } SPI_SendTx(RELAYS); //SPI_DRV8860_GetFaults(testPtr, 1); if (expanderInputPort0 & START_BUTTON) { if (expanderInputPort0 & SWITCH_CHARGE_AND_BALANCE) { SetState(CHARGE_BALANCE); } else if (expanderInputPort0 & SWITCH_CHARGE) { // Set next state to CHARGE SetState(CHARGE); } else { // Balance only mode SetState(BALANCE); } } } } }
void MTimer_Stop(struct MethodTimer*t){ Timer_Stop((t->_base)); }
/* ** =================================================================== ** Function : Comu_Init ** Description : ** Inicialización de la comunicación ** =================================================================== */ void Comu_Init(void){ AS1_Init(); newAlloced(&comu_timer,&MethodTimer,(ulong)3,OnTimePass,NULL); Timer_Stop(&comu_timer); }
void input_eval_loop(int isRecording) { char** recHistory = NULL; int curRecHistEntry = 0; if(isRecording) recHistory = (char**)alloca(200); // space for 200 pointers to history entries while (1) { DefineStatusMessage((char*)"", 1, 0, 0); strcpy(expr, (char*)""); printf("\x1e"); dConsoleRedraw(); int res = gets(expr,INPUTBUFLEN); if(res == 2) { dConsolePut("\n"); select_script_and_run(); continue; } if(res == 4) { dConsolePut("\n"); select_strip_script(); continue; } if(res == 3) { dConsolePut("\n"); char buf[100] = ""; sprintf(buf, "prizmUIkeyHandler(%d,%d)", custom_key_to_handle, custom_key_to_handle_modifier); strcpy(expr, (char*)buf); execution_in_progress = 1; run(buf); execution_in_progress = 0; check_do_graph(); if(run_startup_script_again) { run_startup_script_again = 0; run_startup_script(); } continue; } puts(expr); update_cmd_history(expr); dConsoleRedraw(); if(strcmp(expr, "testmode") == 0) { TestMode(1); } else if(strcmp(expr, "meminfo") == 0) { print_mem_info(); } else if(strcmp(expr, "memgc") == 0) { gc(); } else if(strcmp(expr, "record") == 0) { if(!isRecording) script_recorder(); else { // create and save a script. this must be done here, because we used alloca // the "clean" way would be using malloc&free, but on the Prizm the heap is already being heavily used by the Eigenmath core. if(curRecHistEntry == 0) { printf("Nothing to record.\n"); return; } printf("Recording stopped.\n"); printf("Type a name for the script, or\n"); printf("leave empty to discard.\n:"); char inputname[MAX_FILENAME_SIZE+1] = ""; gets(inputname,MAX_FILENAME_SIZE-50); puts(inputname); if(!strlen(inputname)) { // user aborted printf("Recording discarded.\n"); return; } if (aborttimer > 0) { Timer_Stop(aborttimer); Timer_Deinstall(aborttimer); } char filename[MAX_FILENAME_SIZE+1] = ""; sprintf(filename, "\\\\fls0\\%s.txt", inputname); unsigned short pFile[MAX_FILENAME_SIZE+1]; Bfile_StrToName_ncpy(pFile, (unsigned char*)filename, strlen(filename)+1); // calculate size int size = 0; int maxHistory = curRecHistEntry - 1; //because we ++'ed at the end of last addition for(int i=0; i <= maxHistory; i++) { size = size + strlen(recHistory[i]) + 1; // 1 byte for \n. we will use unix line termination } int BCEres = Bfile_CreateEntry_OS(pFile, CREATEMODE_FILE, &size); if(BCEres >= 0) // Did it create? { BCEres = Bfile_OpenFile_OS(pFile, READWRITE, 0); // Get handle for(int i=0; i <= maxHistory; i++) { char* buf = (char*)alloca(strlen(recHistory[i])+5); strcpy(buf, recHistory[i]); strcat(buf, (char*)"\n"); Bfile_WriteFile_OS(BCEres, buf, strlen(recHistory[i])+1); } Bfile_CloseFile_OS(BCEres); printf("Script created.\n"); } else { printf("An error occurred when creating the script for recording.\n"); } aborttimer = Timer_Install(0, check_execution_abort, 100); if (aborttimer > 0) Timer_Start(aborttimer); return; } } else { execution_in_progress = 1; has_drawn_graph = 0; run(expr); // run_startup_script cannot run from inside eval_clear because then it would be a run() inside a run() if(run_startup_script_again) { run_startup_script_again = 0; run_startup_script(); } execution_in_progress = 0; // if recording, add input to record if(isRecording && curRecHistEntry <= 200) { recHistory[curRecHistEntry] = (char*)alloca(strlen(expr)+2); // 2 bytes for security strcpy(recHistory[curRecHistEntry], expr); curRecHistEntry++; } check_do_graph(); } } }
/* ** =================================================================== ** Method : Timer_OnTime ** Description : Evento al llegar al tiempo fijado ** =================================================================== */ void Timer_OnTime(struct Timer * self){ Timer_Stop(self); }
/* ** =================================================================== ** Method : Timer_Destruct ** Description : Metodo para destruir el Timer ** =================================================================== */ void * Timer_Destruct(struct Timer * self){ Timer_Stop(self); return self; }
void Mutex_Claii( Mutex_t *pstMutex_ ) #endif { KERNEL_TRACE_1( STR_MUTEX_CLAIM_1, (K_USHORT)Thread_GetID( g_pstCurrent ) ); #if KERNEL_USE_TIMEOUTS Timer_t stTimer; K_BOOL bUseTimer = false; #endif // Disable the scheduler while claiming the Mutex_t - we're dealing with all // sorts of private thread data, can't have a thread switch while messing // with internal data structures. Scheduler_SetScheduler( false ); // Check to see if the Mutex_t is claimed or not if (pstMutex_->bReady != 0) { // Mutex_t isn't claimed, claim it. pstMutex_->bReady = 0; pstMutex_->ucRecurse = 0; pstMutex_->ucMaxPri = Thread_GetPriority( g_pstCurrent ); pstMutex_->pstOwner = g_pstCurrent; Scheduler_SetScheduler( true ); #if KERNEL_USE_TIMEOUTS return true; #else return; #endif } // If the Mutex_t is already claimed, check to see if this is the owner thread, // since we allow the Mutex_t to be claimed recursively. if (g_pstCurrent == pstMutex_->pstOwner) { // Ensure that we haven't exceeded the maximum recursive-lock count KERNEL_ASSERT( (pstMutex_->ucRecurse < 255) ); pstMutex_->ucRecurse++; // Increment the lock count and bail Scheduler_SetScheduler( true ); #if KERNEL_USE_TIMEOUTS return true; #else return; #endif } // The Mutex_t is claimed already - we have to block now. Move the // current thread to the list of threads waiting on the Mutex_t. #if KERNEL_USE_TIMEOUTS if (ulWaitTimeMS_) { Thread_SetExpired( g_pstCurrent, false ); Timer_Init( &stTimer ); Timer_Start( &stTimer, false, ulWaitTimeMS_, (TimerCallback_t)TimedMutex_Calback, (void*)pstMutex_); bUseTimer = true; } #endif BlockingObject_Block( (ThreadList_t*)pstMutex_, g_pstCurrent ); // Check if priority inheritence is necessary. We do this in order // to ensure that we don't end up with priority inversions in case // multiple threads are waiting on the same resource. if(pstMutex_->ucMaxPri <= Thread_GetPriority( g_pstCurrent ) ) { pstMutex_->ucMaxPri = Thread_GetPriority( g_pstCurrent ); Thread_t *pstTemp = (Thread_t*)(LinkList_GetHead( (LinkList_t*)pstMutex_ )); while(pstTemp) { Thread_InheritPriority( pstTemp, pstMutex_->ucMaxPri ); if(pstTemp == (Thread_t*)(LinkList_GetTail( (LinkList_t*)pstMutex_ )) ) { break; } pstTemp = (Thread_t*)LinkListNode_GetNext( (LinkListNode_t*)pstTemp ); } Thread_InheritPriority( pstMutex_->pstOwner, pstMutex_->ucMaxPri ); } // Done with thread data -reenable the scheduler Scheduler_SetScheduler( true ); // Switch threads if this thread acquired the Mutex_t Thread_Yield(); #if KERNEL_USE_TIMEOUTS if (bUseTimer) { Timer_Stop( &stTimer ); return ( Thread_GetExpired( g_pstCurrent ) == 0); } return true; #endif }
/***** Memory to Memory DMA Service Routine *****/ void DMA_M2M(int ch,int srcAddr,int dstAddr,int tc,int dsz,int burst) { int i,time; volatile U32 memSum0=0,memSum1=0; DMA *pDMA; //Pointer for DMA Special Register Structure int length; length=tc*(burst ? 4:1)*((dsz==0)+(dsz==1)*2+(dsz==2)*4); //total data size(byte address) // Counter value * burst size * data size Uart_Printf("[DMA%d MEM2MEM Test]\n",ch); switch(ch) { case 0: pISR_DMA0=(int)Dma0Done; //DMA0 interrupt Vector Table Initialzation rINTMSK&=~(BIT_DMA0); //DMA0 interrupt Enable pDMA=(void *)0x4b000000; //pDMA ponter indicate first addr. of DMA0 Special Register break; case 1: pISR_DMA1=(int)Dma1Done; //DMA1 interrupt Vector Table Initialzation rINTMSK&=~(BIT_DMA1); pDMA=(void *)0x4b000040; break; case 2: pISR_DMA2=(int)Dma2Done; //DMA2 interrupt Vector Table Initialzation rINTMSK&=~(BIT_DMA2); pDMA=(void *)0x4b000080; break; case 3: pISR_DMA3=(int)Dma3Done; //DMA3 interrupt Vector Table Initialzation rINTMSK&=~(BIT_DMA3); pDMA=(void *)0x4b0000c0; break; } Uart_Printf("DMA%d %8xh->%8xh,size=%xh(tc=%xh),dsz=%d,burst=%d\n",ch,srcAddr,dstAddr,length,tc,dsz,burst); Uart_Printf("Initialize the src.\n"); for(i=srcAddr;i<(srcAddr+length);i+=4) { *((U32 *)i)=i^0x55aa5aa5; memSum0+=i^0x55aa5aa5; } Uart_Printf("DMA%d start\n",ch); dmaDone=0; /* Value Setting of Current DMA Special Registers */ pDMA->DISRC=srcAddr; pDMA->DISRCC=(0<<1)|(0<<0); //inc,AHB pDMA->DIDST=dstAddr; pDMA->DIDSTC=(0<<1)|(0<<0); //inc,AHB pDMA->DCON=tc|((unsigned int)1<<31)|(1<<30)|(1<<29)|(burst<<28)|(1<<27)|(0x3<<24)|(1<<23)|(1<<22)|(dsz<<20)|(tc); //HS,AHB,TC interrupt,whole, HWSource request mode,relaod off pDMA->DMASKTRIG= 0x1<<1; //DMA on, /* DMA Start */ Timer_Start(3);//128us resolution while(dmaDone==0); time=Timer_Stop(); Uart_Printf("DMA transfer done. time=%f, %fMB/S\n",(float)time/ONESEC3, length/((float)time/ONESEC3)/1000000.); rINTMSK=BIT_ALLMSK; /* Check DMA Result */ for(i=dstAddr;i<dstAddr+length;i+=4) { memSum1+=*((U32 *)i)=i^0x55aa5aa5; } Uart_Printf("memSum0=%x,memSum1=%x\n",memSum0,memSum1); if(memSum0==memSum1) Uart_Printf("DMA test result--------------------------------------O.K.\n"); else Uart_Printf("DMA test result--------------------------------------ERROR!!!\n"); }
int main(){ CyGlobalIntEnable; isrSW_Start(); isr_Timer_Start(); UART_Start(); ADC_Start(); ADC_StartConvert(); CyDelay(50); UART_PutString("nRF Tx\r\n"); NRF_INIT_t tx; tx.channel = NRF_CHANNEL; tx.isTX = true; tx.RF_SETUP_DR = NRF_RF_SETUP_RF_DR_1000; tx.RF_SETUP_PWR = NRF_RF_SETUP_RF_PWR_18; tx.SETUP_RETR_ARC = NRF_SETUP_RETR_ARC_15; tx.SETUP_RETR_ARD = NRF_SETUP_RETR_ARD_1500; /* Start the component before anything else */ nRF_Tx_Start(&tx); /* Test Dynamic Payload */ nRF_Tx_EnableDynamicPayload(NRF_DYNPD_DPL_P0); nRF_Tx_SetRxPayloadSize(NRF_RX_PW_P0, PAYLOAD_SIZE); nRF_Tx_SetRxAddress(ADDR, sizeof(ADDR)); nRF_Tx_SetTxAddress(ADDR, sizeof(ADDR)); Timer_Start(); for(;;){ if(true == isrTimerFlag){ // Stop the Timer just for fun Timer_Stop(); test++; data[0] = pressCount; data[9] = test; ADCoutput = ADC_Read32(); UART_PutString("Resultado de la conversion del ADC: "); UART_PutHexInt((uint16_t)ADCoutput); UART_PutCRLF(); data[1] = (ADCoutput & 0xFF00) >> 8; data[2] = ADCoutput & 0xFF; nRF_Tx_TxTransmit(data, sizeof(data)); isrTimerFlag = false; // Start the Timer again Timer_Start(); } if(isrFlag){ if(nRF_Tx_GetStatus() & NRF_STATUS_RX_DR_MASK){ UART_PutString("Status: "); UART_PutHexByte(nRF_Tx_GetStatus()); UART_PutCRLF(); UART_PutString("RX\r\n"); do{ nRF_Tx_RxPayload(RXdata, sizeof(RXdata)); nRF_Tx_ResetStatusIRQ(NRF_STATUS_RX_DR); nRF_Tx_ReadSingleRegister(NRF_FIFO_STATUS, &status); }while(!(status & NRF_STATUS_TX_FIFO_FULL)); printFlag = true; }else if(nRF_Tx_GetStatus() & NRF_STATUS_TX_DS_MASK){ UART_PutString("Status: "); UART_PutHexByte(nRF_Tx_GetStatus()); UART_PutCRLF(); UART_PutString("TX\r\n"); LED_Write(~LED_Read()); nRF_Tx_ResetStatusIRQ(NRF_STATUS_TX_DS); }else if(nRF_Tx_GetStatus() & NRF_STATUS_MAX_RT_MASK){ UART_PutString("Status: "); UART_PutHexByte(nRF_Tx_GetStatus()); UART_PutCRLF(); UART_PutString("Max RT\r\n"); MAX_Write(~MAX_Read()); nRF_Tx_ResetStatusIRQ(NRF_STATUS_MAX_RT); } isrFlag = false; } if(printFlag){ UART_PutHexByte(RXdata[0]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[1]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[2]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[3]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[4]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[5]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[6]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[7]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[8]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[9]); UART_PutString("\r\n"); printFlag = false; } }