/************************************************************************* * Function Name: main * Parameters: none * Return: Int32U * * Description: The main subroutine * *************************************************************************/ int main(void) { unsigned short deviceid=0x0000; // システムを初期化します(外部水晶をONにし72MHz動作に切り替えます) SystemInit(); /* FSMC Configuration */ p.FSMC_AddressSetupTime = 30; p.FSMC_AddressHoldTime = 0; p.FSMC_DataSetupTime = 30; p.FSMC_BusTurnAroundDuration = 0x00; p.FSMC_CLKDivision = 0x00; p.FSMC_DataLatency = FSMC_AccessMode_A; FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); /* Enable FSMC Bank1_NOR Bank */ FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE); LCD->LCD_REG = 0x0000; deviceid = LCD->LCD_RAM; if (deviceid != 0x8989) { goto error; } /* * LCD Initialize */ /* power on */ LCD->LCD_REG = 0x0007; LCD->LCD_RAM = 0x0021; LCD->LCD_REG = 0x0000; LCD->LCD_RAM = 0x0001; LCD->LCD_REG = 0x0007; LCD->LCD_RAM = 0x0023; LCD->LCD_REG = 0x0010; LCD->LCD_RAM = 0x0000; Delay(3000000); LCD->LCD_REG = 0x0007; LCD->LCD_RAM = 0x0033; LCD->LCD_REG = 0x0011; LCD->LCD_RAM = 0x6070; LCD->LCD_REG = 0x0002; LCD->LCD_RAM = 0x0500; LCD->LCD_REG = 0x0003; LCD->LCD_RAM = 0x0804; LCD->LCD_REG = 0x000C; LCD->LCD_RAM = 0x0000; LCD->LCD_REG = 0x000D; LCD->LCD_RAM = 0x0808; write_reg(0x000E,0x2900); write_reg(0x001E,0x00B8); write_reg(0x0001,0x2B3F);//Çý¶¯Êä³ö¿ØÖÆ320*240 0x6B3F write_reg(0x0010,0x0000); write_reg(0x0005,0x0000); write_reg(0x0006,0x0000); write_reg(0x0016,0xEF1C); write_reg(0x0017,0x0003); write_reg(0x0007,0x0233);//0x0233 write_reg(0x000B,0x0000|(3<<6)); write_reg(0x000F,0x0000);//ɨÃ迪ʼµØÖ· write_reg(0x0041,0x0000); write_reg(0x0042,0x0000); write_reg(0x0048,0x0000); write_reg(0x0049,0x013F); write_reg(0x004A,0x0000); write_reg(0x004B,0x0000); write_reg(0x0044,0xEF00); write_reg(0x0045,0x0000); write_reg(0x0046,0x013F); write_reg(0x0030,0x0707); write_reg(0x0031,0x0204); write_reg(0x0032,0x0204); write_reg(0x0033,0x0502); write_reg(0x0034,0x0507); write_reg(0x0035,0x0204); write_reg(0x0036,0x0204); write_reg(0x0037,0x0502); write_reg(0x003A,0x0302); write_reg(0x003B,0x0302); write_reg(0x0023,0x0000); write_reg(0x0024,0x0000); write_reg(0x0025,0x8000); // 65hz write_reg(0x004f,0); // ÐÐÊ×Ö·0 write_reg(0x004e,0); // ÁÐÊ×Ö·0 /* set cursor */ LCD->LCD_REG = 0x004e; LCD->LCD_RAM = 0x0000; LCD->LCD_REG = 0x004f; LCD->LCD_RAM = 0x0000; LCD->LCD_REG = 0x0034; LCD->LCD_RAM = 0xAA55; while(1); /* end here */ error: // GPIO Dポートを有効にします RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); // PD.4ポートを出力にします。PD.4=赤LED Lowで点灯 GPIO_InitStructure.GPIO_Pin = _BV(4); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure); // 初期化関数を読み出します。 // GPIOコントロール関数を使うならこのようになります。 while(1){ GPIO_ResetBits(GPIOD, _BV(4)); Delay(200000); GPIO_SetBits(GPIOD, _BV(4)); Delay(200000); } // 直接I/Oを操作するにはこのようにすればできます。 // 上記GPIO_ResetBits, GPIO_SetBitsの関数内ではこれと同じことをやっています。 /********************** while(1){ GPIOD->BRR = _BV(4); // 4ビット目をクリアします。 // BRRレジスタを立っているビットをクリアします。 // それ以外のビットには影響を与えません Delay(200000); GPIOD->BSRR = _BV(4); // 4ビット目をセットします。 // BSRRレジスタ(下位16ビット)は立っているビットをセットします。 // それ以外のビットには影響を与えません Delay(200000); } ***********************/ }
void main (void) { int a=1;//само число int direction=1;//1-влево 0-вправо int move=1;//Если 1 движение, если 0 остановка int i = 2; // Настроить порт SCS |= 0x01; //Разрешить быстрый ввод/вывод FIO0DIR = 0x00000000; // Все разряды порта 0 на ввод для чтения состояния кнопок и энкодера FIO0MASK = 0; //Все разряды порта 0 работают в быстром режиме FIO2DIR = 0x00FF; // Биты 0-7 порта 2 на вывод для управления светодиодами FIO2MASK = 0; //Все разряды порта 2 работают в быстром режиме ENCA_cur = ENCA_prev = (FIO0PIN & 0x00000800) >> 11; //Чтение начального состояния контакта А энкодера (P0.11) ENCB_cur = ENCB_prev = (FIO0PIN & 0x00200000) >> 21; //Чтение начального состояния контакта B энкодера (P0.21) BTN1_cur = BTN1_prev = FIO0PIN & 0x0020; //Чтение начального состояния кнопки 1 BTN2_cur = BTN2_prev = FIO0PIN & 0x0040; //Чтение начального состояния кнопки 2 BTN2_cur = BTN2_prev = FIO0PIN & 0x0080; //Чтение начального состояния кнопки 3 BTN2_cur = BTN2_prev = FIO0PIN & 0x0200; //Чтение начального состояния кнопки 4 while (1)//Loop forever { if( GetBtn1State() ) { move = 0; } if( GetBtn2State() ) { move = 1; } if(GetBtn3State()) { direction=!direction; //Меняем направление } if(GetBtn4State()) { direction=!direction; //Меняем направление } switch(GetEncState()) { case 1://УСКОРЕНИЕ i=i++; break; case -1://ЗАМЕДЛЕНИЕ i=i--; break; } if(move) { if(direction) { a<<=1; } else { a>>=1; } } if((a & 0x0100) && direction) { a=1; //ловим крайнее левое состояние и смещаем "каретку" } if((!a) && !direction) { a=0x0080; //ловим крайнее правое состояние и смещаем "каретку" } FIO2PIN = a;//Вывод на светодиоды Delay(i*10000); } }
void ScriptNR04::ActorChangedGoal(int actorId, int newGoal, int oldGoal, bool currentSet) { if (actorId == 18) { switch (newGoal) { case 214: Actor_Change_Animation_Mode(18, 29); Delay(2500); Actor_Says(18, 290, 3); sub_401DB0(); //return true; break; case 213: Actor_Clue_Acquire(0, 88, 0, 18); Item_Pickup_Spin_Effect(984, 200, 160); Actor_Says(18, 200, 30); Actor_Says(18, 210, 30); Actor_Says(18, 220, 30); Actor_Says_With_Pause(0, 3425, 1.5f, 23); Actor_Says(0, 3430, 3); Actor_Says(18, 240, 30); Actor_Says(0, 3435, 3); Actor_Says(18, 250, 30); Actor_Says(0, 3440, 3); Actor_Says(18, 280, 30); Actor_Says(0, 3445, 3); Actor_Set_Goal_Number(18, 214); //return true; break; case 209: Actor_Face_Actor(0, 18, true); Delay(3000); Actor_Says(18, 170, 30); Actor_Says(0, 3415, 3); Actor_Says(18, 180, 30); Actor_Says_With_Pause(0, 3420, 1.5f, 3); Actor_Says(18, 190, 30); Actor_Set_Goal_Number(18, 211); //return true; break; case 207: Loop_Actor_Walk_To_Waypoint(18, 445, 0, 1, false); Actor_Face_Heading(18, 49, false); Actor_Change_Animation_Mode(18, 85); Actor_Face_Actor(0, 18, true); Actor_Set_Goal_Number(18, 208); Actor_Clue_Acquire(0, 92, 0, 18); //return true; break; case 204: Actor_Face_Actor(0, 18, true); Actor_Says(18, 90, 73); Actor_Says(0, 3390, 3); Actor_Face_Actor(18, 0, true); Actor_Says(18, 110, 74); Actor_Says(0, 3385, 3); Actor_Says(18, 120, 74); Actor_Face_Actor(18, 0, true); Actor_Set_Goal_Number(18, 205); //return true; break; case 202: Actor_Face_Actor(18, 0, true); Actor_Face_Actor(0, 18, true); Actor_Says(18, 30, 3); Actor_Says(0, 3375, 3); Actor_Says_With_Pause(18, 50, 1.5f, 3); Actor_Says(18, 60, 3); Actor_Says_With_Pause(0, 3380, 1.0f, 3); Actor_Says(18, 70, 3); Actor_Says(0, 3415, 3); Actor_Says(18, 80, 3); Player_Gains_Control(); Actor_Set_Goal_Number(18, 203); //return true; break; } } //return false; }
void Work3(){printf("Start 3\n");Delay();printf("End 3\n");}
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f30x.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f30x.c file */ /* Configure the ADC clock */ RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div2); /* Enable ADC1 clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE); /* Setup SysTick Timer for 1 µsec interrupts */ if (SysTick_Config(SystemCoreClock / 1000000)) { /* Capture error */ while (1) {} } /* ADC Channel configuration */ /* GPIOC Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); /* Configure ADC Channel7 as analog input */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOC, &GPIO_InitStructure); ADC_StructInit(&ADC_InitStructure); /* Calibration procedure */ ADC_VoltageRegulatorCmd(ADC1, ENABLE); /* Insert delay equal to 10 µs */ Delay(10); ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single); ADC_StartCalibration(ADC1); while(ADC_GetCalibrationStatus(ADC1) != RESET ); calibration_value = ADC_GetCalibrationValue(ADC1); ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_OneShot; ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0; ADC_CommonInit(ADC1, &ADC_CommonInitStructure); ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable; ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0; ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable; ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable; ADC_InitStructure.ADC_NbrOfRegChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channel7 configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 1, ADC_SampleTime_7Cycles5); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* wait for ADRDY */ while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY)); /* Start ADC1 Software Conversion */ ADC_StartConversion(ADC1); /* Infinite loop */ while (1) { /* Test EOC flag */ while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); /* Get ADC1 converted data */ ADC1ConvertedValue =ADC_GetConversionValue(ADC1); /* Compute the voltage */ ADC1ConvertedVoltage = (ADC1ConvertedValue *3300)/0xFFF; /* Display converted data on the LCD */ Display(); } }
/* * I2C中断服务程序 * 根据剩余的数据长度选择继续传输或者结束 */ void I2CIntHandle(void) { unsigned int iicSt,i; // 清中断 SRCPND = BIT_IIC; INTPND = BIT_IIC; iicSt = IICSTAT; if(iicSt & 0x8){ printf("Bus arbitration failed\n\r"); } switch (g_tS3C24xx_I2C.Mode) { case WRDATA: { if((g_tS3C24xx_I2C.DataCount--) == 0) { // 下面两行用来恢复I2C操作,发出P信号 IICSTAT = 0xd0; IICCON = 0xaf; Delay(10000); // 等待一段时间以便P信号已经发出 break; } printf("[*] %s WRDATA 0x%x \r\n", __FUNCTION__, g_tS3C24xx_I2C.pData[g_tS3C24xx_I2C.Pt]); IICDS = g_tS3C24xx_I2C.pData[g_tS3C24xx_I2C.Pt++]; // 将数据写入IICDS后,需要一段时间才能出现在SDA线上 for (i = 0; i < 10; i++); IICCON = 0xaf; // 恢复I2C传输 break; } case RDDATA: { if (g_tS3C24xx_I2C.Pt == -1) { // 这次中断是发送I2C设备地址后发生的,没有数据 // 只接收一个数据时,不要发出ACK信号 g_tS3C24xx_I2C.Pt = 0; if(g_tS3C24xx_I2C.DataCount == 1) IICCON = 0x2f; // 恢复I2C传输,开始接收数据,接收到数据时不发出ACK else IICCON = 0xaf; // 恢复I2C传输,开始接收数据 break; } printf("[*] %s RDDATA 0x%x \r\n", __FUNCTION__, IICDS); if ((g_tS3C24xx_I2C.DataCount--) == 0) { g_tS3C24xx_I2C.pData[g_tS3C24xx_I2C.Pt++] = IICDS; // 下面两行恢复I2C操作,发出P信号 IICSTAT = 0x90; IICCON = 0xaf; Delay(10000); // 等待一段时间以便P信号已经发出 break; } g_tS3C24xx_I2C.pData[g_tS3C24xx_I2C.Pt++] = IICDS; // 接收最后一个数据时,不要发出ACK信号 if(g_tS3C24xx_I2C.DataCount == 0) IICCON = 0x2f; // 恢复I2C传输,接收到下一数据时无ACK else IICCON = 0xaf; // 恢复I2C传输,接收到下一数据时发出ACK break; } default: break; } }
void Work1(){printf("Start 1\n");Delay();printf("End 1\n");}
/* *********************************** */ int ProSLIC_testInRinging(proslicChanType *pProslic, proslicTestInObjType *pTstin) { uInt8 ringcon_save,enhance_save; int32 vtr[MAX_RINGING_SAMPLES]; int i; uInt8 lf; uInt32 rtper_save, ringfr_save,ringamp_save,ringof_save,rtacth_save,rtdcth_save; ProSLIC_DCfeed_Cfg dcfeedCfg; /* Valid device check */ if(TSTIN_INVALID_PART_NUM) { return RC_UNSUPPORTED_FEATURE; } /* Check if enabled */ if(!pTstin->ringingTest.testEnable) { return RC_TEST_DISABLED; } /* Verify line not in use */ if(ProSLIC_ReadReg(pProslic,34) & 0x02) /* LCR */ { #ifdef ENABLE_DEBUG if(pProslic->debugMode) { LOGPRINT("\nProSLIC : TestIn : Ringing : Line in Use\n"); } #endif if(pTstin->ringingTest.abortIfLineInUse) { return RC_LINE_IN_USE; } } /* Invalidate last test results */ pTstin->ringingTest.testDataValid = TSTIN_RESULTS_INVALID; /* Check sample size/rate */ if(pTstin->ringingTest.numSamples > MAX_RINGING_SAMPLES) pTstin->ringingTest.numSamples = MAX_RINGING_SAMPLES; if(pTstin->ringingTest.sampleInterval > MAX_RINGING_SAMPLE_INTERVAL) pTstin->ringingTest.sampleInterval = MAX_RINGING_SAMPLE_INTERVAL; if(pTstin->ringingTest.sampleInterval < MIN_RINGING_SAMPLE_INTERVAL) pTstin->ringingTest.sampleInterval = MIN_RINGING_SAMPLE_INTERVAL; /* Disable Powersave */ enhance_save = ProSLIC_ReadReg(pProslic,47); ProSLIC_WriteReg(pProslic,47,0x20); Delay(pProTimer,10); /* Disable ring cadencing */ ringcon_save = ProSLIC_ReadReg(pProslic,38); /* RINGCON */ ProSLIC_WriteReg(pProslic,38,ringcon_save&0xE7); /* RINGCON */ /* Must enter ringing through active state */ lf = ProSLIC_ReadReg(pProslic,30); /* LINEFEED */ ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE); Delay(pProTimer,20); /* settle */ /* Start ringing */ ProSLIC_SetLinefeedStatus(pProslic,LF_RINGING); Delay(pProTimer,500); /* Verify Ring Started */ if(ProSLIC_ReadReg(pProslic,30) != 0x44) { ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE); ProSLIC_SetLinefeedStatus(pProslic,LF_OPEN); ProSLIC_WriteReg(pProslic,38,ringcon_save); ProSLIC_WriteReg(pProslic,47,enhance_save); ProSLIC_SetLinefeedStatus(pProslic,lf); #ifdef ENABLE_DEBUG if(pProslic->debugMode) { LOGPRINT("ProSLIC : TestIn : Ringing : Ring Start Fail\n"); } #endif pTstin->ringingTest.testResult = RC_TEST_FAILED; return RC_RING_START_FAIL; } /* Capture samples */ pTstin->ringingTest.ringingVdc.value = 0; for(i=0;i<pTstin->ringingTest.numSamples;i++) { vtr[i] = ProSLIC_ReadMADCScaled(pProslic,69,0); /* VDIFF_FILT */ pTstin->ringingTest.ringingVdc.value += vtr[i]; #ifdef ENABLE_DEBUG if(pProslic->debugMode) { LOGPRINT("ProSLIC : TestIn : Ringing : Vtr[%d] = %d\n",i,vtr[i]); } #endif Delay(pProTimer,pTstin->ringingTest.sampleInterval); } /* Restore linefeed */ ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE); Delay(pProTimer,20); /* Process Results */ pTstin->ringingTest.ringingVdc.value /= pTstin->ringingTest.numSamples; for(i=0;i<pTstin->ringingTest.numSamples;i++) { vtr[i] -= pTstin->ringingTest.ringingVdc.value; pTstin->ringingTest.ringingVac.value += ((vtr[i]/100L) * (vtr[i]/100L)); } pTstin->ringingTest.ringingVac.value /= pTstin->ringingTest.numSamples; pTstin->ringingTest.ringingVac.value = Isqrt32(pTstin->ringingTest.ringingVac.value); pTstin->ringingTest.ringingVac.value *= 100L; pTstin->ringingTest.testResult = RC_TEST_PASSED; pTstin->ringingTest.testResult |= logTest(pProslic,&(pTstin->ringingTest.ringingVdc),"Ringing : VDC"); pTstin->ringingTest.testResult |= logTest(pProslic,&(pTstin->ringingTest.ringingVac),"Ringing : VAC"); /* ** Optional Ringtrip Test */ if(pTstin->ringingTest.ringtripTestEnable == RTP_CHECK_ENABLED) { /* Setup low voltage linefeed so low level ringing may be used */ ProSLIC_SetLinefeedStatus(pProslic,LF_OPEN); storeDCFeedPreset(pProslic,&dcfeedCfg); ProSLIC_DCFeedSetupCfg(pProslic,ringtripTestDCFeedPreset,0); /* Optional Ringtrip Test (modified ringer settings to use test load to trip) */ rtper_save = ProSLIC_ReadRAM(pProslic,755); ringfr_save = ProSLIC_ReadRAM(pProslic,844); ringamp_save = ProSLIC_ReadRAM(pProslic,845); ringof_save = ProSLIC_ReadRAM(pProslic,843); rtacth_save = ProSLIC_ReadRAM(pProslic,848); rtdcth_save = ProSLIC_ReadRAM(pProslic,847); ProSLIC_WriteRAM(pProslic,755,0x50000L); /* RTPER */ ProSLIC_WriteRAM(pProslic,844,0x7EFE000L);/* RINGFR */ ProSLIC_WriteRAM(pProslic,845,0xD6307L); /* RINGAMP */ ProSLIC_WriteRAM(pProslic,843,0x0L); /* RINGOF */ ProSLIC_WriteRAM(pProslic,848,0x7827FL); /* RTACTH */ ProSLIC_WriteRAM(pProslic,847,0xFFFFFFFL);/* RTDCTH */ /* Start ringing from active state */ ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE); Delay(pProTimer,20); ProSLIC_SetLinefeedStatus(pProslic,LF_RINGING); Delay(pProTimer,200); /* Verify Ring Started */ if(ProSLIC_ReadReg(pProslic,30) != 0x44) { ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE); ProSLIC_SetLinefeedStatus(pProslic,LF_OPEN); ProSLIC_WriteReg(pProslic,38,ringcon_save); ProSLIC_WriteReg(pProslic,47,enhance_save); ProSLIC_SetLinefeedStatus(pProslic,lf); #ifdef ENABLE_DEBUG if(pProslic->debugMode) { LOGPRINT("ProSLIC : TestIn : Ringtrip : Ring Start Fail\n"); } #endif pTstin->ringingTest.testResult=RC_TEST_FAILED; return RC_RING_START_FAIL; } /* Connect Test Load to cause ringtrip */ setInternalTestLoad(pProslic,1); Delay(pProTimer,200); /* Check for RTP */ if(ProSLIC_ReadReg(pProslic,34) & 0x01) /* LCRRTP */ { pTstin->ringingTest.rtpStatus = 1; pTstin->ringingTest.testResult |= RC_TEST_PASSED; } else { pTstin->ringingTest.rtpStatus = 0; pTstin->ringingTest.testResult |= RC_TEST_FAILED; ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE); } setInternalTestLoad(pProslic,0); Delay(pProTimer,20); logStatus(pProslic,pTstin->ringingTest.rtpStatus,"Ringing : RTP"); /* Restore DC Feed */ ProSLIC_DCFeedSetupCfg(pProslic,&dcfeedCfg,0); /* Restore Ring Settings */ ProSLIC_WriteRAM(pProslic,755,rtper_save);/* RTPER */ ProSLIC_WriteRAM(pProslic,844,ringfr_save);/*RINGFR */ ProSLIC_WriteRAM(pProslic,845,ringamp_save); /* RINGAMP */ ProSLIC_WriteRAM(pProslic,843,ringof_save); /* RINGOF */ ProSLIC_WriteRAM(pProslic,848,rtacth_save);/* RTACTH */ ProSLIC_WriteRAM(pProslic,847,rtdcth_save);/* RTDCTH */ }/* end of ringtrip test /* Restore Linefeed */ ProSLIC_SetLinefeedStatus(pProslic,lf); /* Restore RINGCON and ENHANCE */ ProSLIC_WriteReg(pProslic,38,ringcon_save); ProSLIC_WriteReg(pProslic,47,enhance_save); pTstin->ringingTest.testDataValid = TSTIN_RESULTS_VALID; return (pTstin->ringingTest.testResult); }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s) before to branch to application main. */ /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* Initialize LEDs mounted on EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDOn(LED1); /* Initialize the LCD */ LCD_Init(); LCD_Clear(Black); LCD_SetTextColor(White); LCD_LOG_SetHeader((uint8_t*)"STM32 Camera Demo"); LCD_LOG_SetFooter ((uint8_t*)" Copyright (c) STMicroelectronics" ); /* ADC configuration */ ADC_Config(); /* Initializes the DCMI interface (I2C and GPIO) used to configure the camera */ OV2640_HW_Init(); /* Read the OV9655/OV2640 Manufacturer identifier */ OV9655_ReadID(&OV9655_Camera_ID); OV2640_ReadID(&OV2640_Camera_ID); if(OV9655_Camera_ID.PID == 0x96) { Camera = OV9655_CAMERA; sprintf((char*)abuffer, "OV9655 Camera ID 0x%x", OV9655_Camera_ID.PID); ValueMax = 2; } else if(OV2640_Camera_ID.PIDH == 0x26) { Camera = OV2640_CAMERA; sprintf((char*)abuffer, "OV2640 Camera ID 0x%x", OV2640_Camera_ID.PIDH); ValueMax = 2; } else { LCD_SetTextColor(LCD_COLOR_RED); LCD_DisplayStringLine(LINE(4), (uint8_t*)"Check the Camera HW and try again"); while(1); } LCD_SetTextColor(LCD_COLOR_YELLOW); LCD_DisplayStringLine(LINE(4), (uint8_t*)abuffer); LCD_SetTextColor(LCD_COLOR_WHITE); Delay(200); /* Initialize demo */ ImageFormat = (ImageFormat_TypeDef)Demo_Init(); /* Configure the Camera module mounted on STM324xG-EVAL/STM324x7I-EVAL boards */ Demo_LCD_Clear(); LCD_DisplayStringLine(LINE(4), (uint8_t*)"Camera Init.. "); Camera_Config(); sprintf((char*)abuffer, " Image selected: %s", ImageForematArray[ImageFormat]); LCD_DisplayStringLine(LINE(4),(uint8_t*)abuffer); /* Enable DMA2 stream 1 and DCMI interface then start image capture */ DMA_Cmd(DMA2_Stream1, ENABLE); DCMI_Cmd(ENABLE); /* Insert 100ms delay: wait 100ms */ Delay(200); DCMI_CaptureCmd(ENABLE); LCD_ClearLine(LINE(4)); Demo_LCD_Clear(); if(ImageFormat == BMP_QQVGA) { /* LCD Display window */ LCD_SetDisplayWindow(179, 239, 120, 160); LCD_WriteReg(LCD_REG_3, 0x1038); LCD_WriteRAM_Prepare(); } else if(ImageFormat == BMP_QVGA) { /* LCD Display window */ LCD_SetDisplayWindow(239, 319, 240, 320); LCD_WriteReg(LCD_REG_3, 0x1038); LCD_WriteRAM_Prepare(); } while(1) { /* Blink LD1, LED2 and LED4 */ STM_EVAL_LEDToggle(LED1); STM_EVAL_LEDToggle(LED2); STM_EVAL_LEDToggle(LED3); STM_EVAL_LEDToggle(LED4); /* Insert 100ms delay */ Delay(10); /* Get the last ADC3 conversion result data */ uhADCVal = ADC_GetConversionValue(ADC3); /* Change the Brightness of camera using "Brightness Adjustment" register: For OV9655 camera Brightness can be positively (0x01 ~ 0x7F) and negatively (0x80 ~ 0xFF) adjusted For OV2640 camera Brightness can be positively (0x20 ~ 0x40) and negatively (0 ~ 0x20) adjusted */ if(Camera == OV9655_CAMERA) { OV9655_BrightnessConfig(uhADCVal); } if(Camera == OV2640_CAMERA) { OV2640_BrightnessConfig(uhADCVal/2); } } }
/* *********************************** */ int ProSLIC_testInAudio(proslicChanType *pProslic, proslicTestInObjType *pTstin) { uInt8 enhanceRegSave; uInt8 lf; int32 data; int32 gainMeas1,gainMeas2; int32 gainMeas3 = 0; ProSLIC_audioGain_Cfg gainCfg; int32 Pin = -3980; /* -10dBm + 6.02dB (since OHT w/ no AC load) */ /* Valid device check */ if(TSTIN_INVALID_PART_NUM) { return RC_UNSUPPORTED_FEATURE; } /* Check if enabled */ if(!pTstin->audioTest.testEnable) { return RC_TEST_DISABLED; } /* Invalidate last test results */ pTstin->audioTest.testDataValid = TSTIN_RESULTS_INVALID; /* Verify line not in use */ if(ProSLIC_ReadReg(pProslic,34) & 0x02) /* LCR */ { #ifdef ENABLE_DEBUG if(pProslic->debugMode) { LOGPRINT("\nProSLIC : TestIn : Audio : Line in Use\n"); } #endif if(pTstin->audioTest.abortIfLineInUse == ABORT_LIU_ENABLED) { return RC_LINE_IN_USE; } } /* Disable Powersave */ enhanceRegSave = ProSLIC_ReadReg(pProslic,47); ProSLIC_WriteReg(pProslic,47,0x20); Delay(pProTimer,10); /* Setup Audio Filter, enable audio in OHT */ lf = ProSLIC_ReadReg(pProslic,30); /* LINEFEED */ ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE); Delay(pProTimer,20); /* settle */ setup1kHzBandpass(pProslic); ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_OHT); /* Setup osc1 for 1kHz -10dBm tone, disable hybrid, enable filters */ ProSLIC_WriteRAM(pProslic,26,0x5A80000L); /* OSC1FREQ */ ProSLIC_WriteRAM(pProslic,27,0x5D8000L); /* OSC1AMP */ ProSLIC_WriteReg(pProslic,48,0x02); /* OMODE */ ProSLIC_WriteReg(pProslic,49,0x01); /* OCON */ ProSLIC_WriteReg(pProslic,44,0x10); /* DIGCON */ ProSLIC_WriteReg(pProslic,71,0x10); /* DIAG1 */ /* Settle */ Delay(pProTimer,800); /* Read first gain measurement (Gtx + Grx + Gzadj) */ gainMeas1 = readAudioDiagLevel(pProslic,pTstin->audioTest.zerodBm_mVpk); /* Bypass TXACHPF and set TXACEQ to unity */ gainCfg.acgain = ProSLIC_ReadRAM(pProslic,544); /* TXACGAIN */ gainCfg.aceq_c0 = ProSLIC_ReadRAM(pProslic,540); /* TXACEQ_C0 */ gainCfg.aceq_c1 = ProSLIC_ReadRAM(pProslic,541); /* TXACEQ_C1 */ gainCfg.aceq_c2 = ProSLIC_ReadRAM(pProslic,542); /* TXACEQ_C2 */ gainCfg.aceq_c3 = ProSLIC_ReadRAM(pProslic,543); /* TXACEQ_C3 */ ProSLIC_WriteRAM(pProslic,544,0x8000000L); ProSLIC_WriteRAM(pProslic,543,0x0L); ProSLIC_WriteRAM(pProslic,542,0x0L); ProSLIC_WriteRAM(pProslic,541,0x0L); ProSLIC_WriteRAM(pProslic,540,0x8000000L); ProSLIC_WriteReg(pProslic,44,0x18); /* Settle */ Delay(pProTimer,800); /* Read second level measurement (RX level only) */ gainMeas2 = readAudioDiagLevel(pProslic,pTstin->audioTest.zerodBm_mVpk); /* Adjust txgain if TXACGAIN wasn't unity during gainMeas1 */ if(gainCfg.acgain != 0x8000000L) { data = (gainCfg.acgain*10)/134217; gainMeas3 = dBLookup(data); } /* Computations */ pTstin->audioTest.rxGain.value = gainMeas2 - Pin; pTstin->audioTest.txGain.value = gainMeas1 - gainMeas2 + gainMeas3; #ifdef ENABLE_DEBUG if(pProslic->debugMode) { LOGPRINT("ProSLIC : TestIn : Audio : gainMeas1 = %d\n", gainMeas1); LOGPRINT("ProSLIC : TestIn : Audio : gainMeas2 = %d\n", gainMeas2); LOGPRINT("ProSLIC : TestIn : Audio : gainMeas3 = %d\n", gainMeas3); } #endif pTstin->audioTest.testResult = RC_TEST_PASSED; pTstin->audioTest.testResult |= logTest(pProslic,&(pTstin->audioTest.rxGain),"RX Path Gain"); pTstin->audioTest.testResult |= logTest(pProslic,&(pTstin->audioTest.txGain),"TX Path Gain"); /* ** Restore */ /* Need to store/restore all modified reg/RAM */ ProSLIC_WriteRAM(pProslic,544,gainCfg.acgain); ProSLIC_WriteRAM(pProslic,540,gainCfg.aceq_c0); ProSLIC_WriteRAM(pProslic,541,gainCfg.aceq_c1); ProSLIC_WriteRAM(pProslic,542,gainCfg.aceq_c2); ProSLIC_WriteRAM(pProslic,543,gainCfg.aceq_c3); ProSLIC_WriteReg(pProslic,71,0x0); /* DIAG1 */ ProSLIC_WriteReg(pProslic,44,0x0); /* DIGCON */ ProSLIC_WriteReg(pProslic,48,0x0); /* OMODE */ ProSLIC_WriteReg(pProslic,49,0x0); /* OCON */ ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE); ProSLIC_WriteReg(pProslic,47,enhanceRegSave); ProSLIC_SetLinefeedStatus(pProslic,lf); /* Validate last test results */ pTstin->audioTest.testDataValid = TSTIN_RESULTS_VALID; return pTstin->audioTest.testResult; }
int ProSLIC_testInDCFeed(proslicChanType *pProslic, proslicTestInObjType *pTstin) { uInt8 enhanceRegSave; proslicMonitorType monitor; ramData lcroffhk_save; ramData lcronhk_save; /* Valid device check */ if(TSTIN_INVALID_PART_NUM) { return RC_UNSUPPORTED_FEATURE; } /* Check if enabled */ if(!pTstin->dcFeedTest.testEnable) { return RC_TEST_DISABLED; } /* Invalidate last test results */ pTstin->dcFeedTest.testDataValid = TSTIN_RESULTS_INVALID; /* Verify line not in use */ if(ProSLIC_ReadReg(pProslic,34) & 0x02) /* LCR */ { #ifdef ENABLE_DEBUG if(pProslic->debugMode) { LOGPRINT("\nProSLIC : TestIn : DC Feed : Line in Use\n"); } #endif if(pTstin->dcFeedTest.abortIfLineInUse==ABORT_LIU_ENABLED) { return RC_LINE_IN_USE; } } /* Disable Powersave */ enhanceRegSave = ProSLIC_ReadReg(pProslic,47); ProSLIC_WriteReg(pProslic,47,0x20); Delay(pProTimer,10); /* Onhook measurement */ ProSLIC_LineMonitor(pProslic,&monitor); pTstin->dcFeedTest.dcfeedVtipOnhook.value = monitor.vtip; pTstin->dcFeedTest.dcfeedVringOnhook.value = monitor.vring; pTstin->dcFeedTest.dcfeedVloopOnhook.value = monitor.vtr; pTstin->dcFeedTest.dcfeedVbatOnhook.value = monitor.vbat; pTstin->dcFeedTest.dcfeedItipOnhook.value = monitor.itip; pTstin->dcFeedTest.dcfeedIringOnhook.value = monitor.iring; pTstin->dcFeedTest.dcfeedIloopOnhook.value = monitor.itr; pTstin->dcFeedTest.dcfeedIlongOnhook.value = monitor.ilong; /* Modify LCR threshold (optional) before connecting test load */ if(pTstin->dcFeedTest.applyLcrThresh == LCR_CHECK_ENABLED) { lcroffhk_save = ProSLIC_ReadRAM(pProslic,852); lcronhk_save = ProSLIC_ReadRAM(pProslic,853); ProSLIC_WriteRAM(pProslic,852,pTstin->dcFeedTest.altLcrOffThresh); ProSLIC_WriteRAM(pProslic,853,pTstin->dcFeedTest.altLcrOnThresh); } /* Connect internal test load for 2nd dc feed i/v point */ setInternalTestLoad(pProslic,1); Delay(pProTimer,50); /* Offhook measurement */ ProSLIC_LineMonitor(pProslic,&monitor); pTstin->dcFeedTest.dcfeedVtipOffhook.value = monitor.vtip; pTstin->dcFeedTest.dcfeedVringOffhook.value = monitor.vring; pTstin->dcFeedTest.dcfeedVloopOffhook.value = monitor.vtr; pTstin->dcFeedTest.dcfeedVbatOffhook.value = monitor.vbat; pTstin->dcFeedTest.dcfeedItipOffhook.value = monitor.itip; pTstin->dcFeedTest.dcfeedIringOffhook.value = monitor.iring; pTstin->dcFeedTest.dcfeedIloopOffhook.value = monitor.itr; pTstin->dcFeedTest.dcfeedIlongOffhook.value = monitor.ilong; pTstin->dcFeedTest.testResult = RC_TEST_PASSED; /* initialize */ /* Read LCR */ if(ProSLIC_ReadReg(pProslic,34) & 0x07) /* LCRRTP */ { pTstin->dcFeedTest.lcrStatus = 1; } else { pTstin->dcFeedTest.lcrStatus = 0; } /* Only fail check if enabled */ if(pTstin->dcFeedTest.applyLcrThresh == LCR_CHECK_ENABLED) { pTstin->dcFeedTest.testResult |= !pTstin->dcFeedTest.lcrStatus; } /* Disconnect Test Load */ setInternalTestLoad(pProslic,0); /* Restore LCR thresholds */ if(pTstin->dcFeedTest.applyLcrThresh == LCR_CHECK_ENABLED) { ProSLIC_WriteRAM(pProslic,852,lcroffhk_save); ProSLIC_WriteRAM(pProslic,853,lcronhk_save); } /* Restore enhance reg */ ProSLIC_WriteReg(pProslic,47,enhanceRegSave); /* Process Results */ pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVtipOnhook),"DcFeed : Vtip Onhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVringOnhook),"DcFeed : Vring Onhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVloopOnhook),"DcFeed : Vloop Onhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVbatOnhook),"DcFeed : Vbat Onhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedItipOnhook),"DcFeed : Itip Onhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedIringOnhook),"DcFeed : Iring Onhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedIloopOnhook),"DcFeed : Iloop Onhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedIlongOnhook),"DcFeed : Ilong Onhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVtipOffhook),"DcFeed : Vtip Offhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVringOffhook),"DcFeed : Vring Offhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVloopOffhook),"DcFeed : Vloop Offhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVbatOffhook),"DcFeed : Vbat Offhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedItipOffhook),"DcFeed : Itip Offhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedIringOffhook),"DcFeed : Iring Offhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedIloopOffhook),"DcFeed : Iloop Offhook"); pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedIlongOffhook),"DcFeed : Ilong Offhook"); logStatus(pProslic,pTstin->dcFeedTest.lcrStatus,"DcFeed : LCR"); pTstin->dcFeedTest.testDataValid = 1; /* New valid results */ /* return cumulative pass/fail result */ return (pTstin->dcFeedTest.testResult); }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* Configure the system clocks */ RCC_Configuration(); /* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* Test if Key Button GPIO Pin level is low (Key push-button on Eval Board pressed) */ if (STM_EVAL_PBGetState(BUTTON_KEY) == 0x00) { /* Key is pressed */ /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); /* Disable the Serial Wire Jtag Debug Port SWJ-DP */ GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE); /* Configure PA.13 (JTMS/SWDAT), PA.14 (JTCK/SWCLK) and PA.15 (JTDI) as output push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure PB.03 (JTDO) and PB.04 (JTRST) as output push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4; GPIO_Init(GPIOB, &GPIO_InitStructure); while (1) { /* Toggle JTMS/SWDAT pin */ GPIO_WriteBit(GPIOA, GPIO_Pin_13, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_13))); /* Insert delay */ Delay(0x5FFFF); /* Toggle JTCK/SWCLK pin */ GPIO_WriteBit(GPIOA, GPIO_Pin_14, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_14))); /* Insert delay */ Delay(0x5FFFF); /* Toggle JTDI pin */ GPIO_WriteBit(GPIOA, GPIO_Pin_15, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_15))); /* Insert delay */ Delay(0x5FFFF); /* Toggle JTDO pin */ GPIO_WriteBit(GPIOB, GPIO_Pin_3, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_3))); /* Insert delay */ Delay(0x5FFFF); /* Toggle JTRST pin */ GPIO_WriteBit(GPIOB, GPIO_Pin_4, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_4))); /* Insert delay */ Delay(0x5FFFF); } } else { /* Turn on LED2 */ STM_EVAL_LEDOn(LED2); while (1) { } } }
int sendbinfile(void) { struct TransferFiles *tf; int xprreturkod,cnt=0; if(!(XProtocolBase=(struct Library *)OpenLibrary("xprzmodem.library",0L))) { puttekn("\r\n\nKunde inte öppna xprzmodem.library!\r\n",-1); return(2); } if(!(xio=(struct XPR_IO *)AllocMem(sizeof(struct XPR_IO),MEMF_PUBLIC | MEMF_CLEAR))) { puttekn("\r\n\nKunde inte allokera en io-struktur\r\n",-1); CloseLibrary(XProtocolBase); return(2); } puttekn("\r\nDu kan börja ta emot med Zmodem.\r\n",-1); puttekn("Tryck Ctrl-X några gånger för att avbryta.\r\n",-1); AbortIO((struct IORequest *)serreadreq); WaitIO((struct IORequest *)serreadreq); if(!CheckIO((struct IORequest *)inactivereq)) { AbortIO((struct IORequest *)inactivereq); WaitIO((struct IORequest *)inactivereq); } xpr_setup(xio); xio->xpr_filename=zinitstring; XProtocolSetup(xio); xio->xpr_filename="Hejhopp"; xprreturkod=XProtocolSend(xio); Delay(30); XProtocolCleanup(xio); CloseLibrary(XProtocolBase); if(!CheckIO((struct IORequest *)serreadreq)) { AbortIO((struct IORequest *)serreadreq); WaitIO((struct IORequest *)serreadreq); printf("Serreadreq avbruten!!\n"); } if(!CheckIO((struct IORequest *)timerreq)) { AbortIO((struct IORequest *)timerreq); WaitIO((struct IORequest *)timerreq); printf("Timerreq avbruten!!\n"); } FreeMem(xio,sizeof(struct XPR_IO)); Delay(100); serchangereq->IOSer.io_Command=CMD_CLEAR; DoIO((struct IORequest *)serchangereq); serchangereq->IOSer.io_Command=CMD_FLUSH; DoIO((struct IORequest *)serchangereq); serreqtkn(); updateinactive(); if(Servermem->cfg.logmask & LOG_SENDFILE) { for(tf=(struct TransferFiles *)tf_list.mlh_Head; tf->node.mln_Succ; tf=(struct TransferFiles *)tf->node.mln_Succ) if(tf->sucess) { LogEvent(USAGE_LOG, INFO, "Skickar filen %s till %s", tf->path, getusername(inloggad)); } } for(tf=(struct TransferFiles *)tf_list.mlh_Head; tf->node.mln_Succ; tf=(struct TransferFiles *)tf->node.mln_Succ) if(tf->sucess) cnt++; if(cnt==1) strcpy(outbuffer,"\n\n\rFörde över 1 fil.\n\n\r"); else sprintf(outbuffer,"\n\n\rFörde över %d filer.\n\n\r",cnt); puttekn(outbuffer,-1); return(0); }
int recbinfile(char *dir) { int xprreturkod; char zmodeminit[100]; ulfiles = 0; if(access(dir,0)) { puttekn("\r\nDirectoryt finns inte!\r\n",-1); return 2; } if(Servermem->cfg.diskfree != 0 && !HasPartitionEnoughFreeSpace(dir, Servermem->cfg.diskfree)) { puttekn("\r\nTyvärr, gränsen för hur full disken får bli har överskridits!\r\n",-1); return 2; } if(Servermem->cfg.ar.preup2) { sendautorexx(Servermem->cfg.ar.preup2); } sprintf(zmodeminit,"%s%s",zinitstring,dir); if(!(XProtocolBase = (struct Library *) OpenLibrary("xprzmodem.library", 0L))) { puttekn("\r\n\nKunde inte öppna xprzmodem.library!\r\n",-1); return 2; } if(!(xio = (struct XPR_IO *) AllocMem(sizeof(struct XPR_IO), MEMF_PUBLIC | MEMF_CLEAR))) { puttekn("\r\n\nKunde inte allokera en io-struktur\r\n",-1); CloseLibrary(XProtocolBase); return 2; } NewList((struct List *)&tf_list); puttekn("\r\nDu kan börja sända med Zmodem. Du kan nu skicka fler filer!",-1); puttekn("\r\nTryck Ctrl-X några gånger för att avbryta.\r\n",-1); AbortIO((struct IORequest *)serreadreq); WaitIO((struct IORequest *)serreadreq); if(!CheckIO((struct IORequest *)inactivereq)) { AbortIO((struct IORequest *)inactivereq); WaitIO((struct IORequest *)inactivereq); } xpr_setup(xio); xio->xpr_filename = zmodeminit; XProtocolSetup(xio); xprreturkod = XProtocolReceive(xio); Delay(30); XProtocolCleanup(xio); CloseLibrary(XProtocolBase); if(!CheckIO((struct IORequest *)serreadreq)) { AbortIO((struct IORequest *)serreadreq); WaitIO((struct IORequest *)serreadreq); printf("Serreadreq avbruten!!\n"); } if(!CheckIO((struct IORequest *)timerreq)) { AbortIO((struct IORequest *)timerreq); WaitIO((struct IORequest *)timerreq); printf("Timerreq avbruten!!\n"); } FreeMem(xio,sizeof(struct XPR_IO)); Delay(100); serchangereq->IOSer.io_Command=CMD_CLEAR; DoIO((struct IORequest *)serchangereq); serchangereq->IOSer.io_Command=CMD_FLUSH; DoIO((struct IORequest *)serchangereq); serreqtkn(); updateinactive(); if(Servermem->cfg.ar.postup2) { sendautorexx(Servermem->cfg.ar.postup2); } if(ulfiles > 0) { puttekn("\r\n\nÖverföringen lyckades.\r\n",-1); return 0; } else { puttekn("\r\n\nÖverföringen misslyckades.\r\n",-1); return 2; } }
//***************************************************************************** // // This is the main example program. It checks to see that the interrupts are // processed in the correct order when they have identical priorities, // increasing priorities, and decreasing priorities. This exercises interrupt // preemption and tail chaining. // //***************************************************************************** int main(void) { unsigned long ulError; // // Set the clocking to run directly from the crystal. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Enable the peripherals used by this example. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Initialize the OLED display and write status. // RIT128x96x4Init(1000000); RIT128x96x4StringDraw("Act: Pend: ", 18, 40, 15); // // Configure the F0, D1 and D2 to be outputs to indicate entry/exit of one // of the interrupt handlers. // GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2); GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2, 0); // // Set up and enable the SysTick timer. It will be used as a reference // for delay loops in the interrupt handlers. The SysTick timer period // will be set up for one second. // SysTickPeriodSet(SysCtlClockGet()); SysTickEnable(); // // Reset the error indicator. // ulError = 0; // // Enable interrupts to the processor. // IntMasterEnable(); // // Enable the interrupts. // IntEnable(INT_GPIOA); IntEnable(INT_GPIOB); IntEnable(INT_GPIOC); // // Indicate that the equal interrupt priority test is beginning. // RIT128x96x4StringDraw("Equal Priority ", 18, 24, 15); // // Set the interrupt priorities so they are all equal. // IntPrioritySet(INT_GPIOA, 0x00); IntPrioritySet(INT_GPIOB, 0x00); IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ulGPIOa = 0; g_ulGPIOb = 0; g_ulGPIOc = 0; g_ulIndex = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the LCD. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ulGPIOa != 3) || (g_ulGPIOb != 2) || (g_ulGPIOc != 1)) { ulError |= 1; } // // Wait two seconds. // Delay(2); // // Indicate that the decreasing interrupt priority test is beginning. // RIT128x96x4StringDraw("Dec. Priority ", 18, 24, 15); // // Set the interrupt priorities so that they are decreasing (i.e. C > B > // A). // IntPrioritySet(INT_GPIOA, 0x80); IntPrioritySet(INT_GPIOB, 0x40); IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ulGPIOa = 0; g_ulGPIOb = 0; g_ulGPIOc = 0; g_ulIndex = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the OLED. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ulGPIOa != 3) || (g_ulGPIOb != 2) || (g_ulGPIOc != 1)) { ulError |= 2; } // // Wait two seconds. // Delay(2); // // Indicate that the increasing interrupt priority test is beginning. // RIT128x96x4StringDraw("Inc. Priority ", 18, 24, 15); // // Set the interrupt priorities so that they are increasing (i.e. C < B < // A). // IntPrioritySet(INT_GPIOA, 0x00); IntPrioritySet(INT_GPIOB, 0x40); IntPrioritySet(INT_GPIOC, 0x80); // // Reset the interrupt flags. // g_ulGPIOa = 0; g_ulGPIOb = 0; g_ulGPIOc = 0; g_ulIndex = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the OLED. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ulGPIOa != 1) || (g_ulGPIOb != 2) || (g_ulGPIOc != 3)) { ulError |= 4; } // // Wait two seconds. // Delay(2); // // Disable the interrupts. // IntDisable(INT_GPIOA); IntDisable(INT_GPIOB); IntDisable(INT_GPIOC); // // Disable interrupts to the processor. // IntMasterDisable(); // // Print out the test results. // RIT128x96x4StringDraw("Int Priority ", 18, 24, 15); if(ulError) { RIT128x96x4StringDraw("=: P >: P <: P", 18, 40, 15); if(ulError & 1) { RIT128x96x4StringDraw("F", 36, 40, 15); } if(ulError & 2) { RIT128x96x4StringDraw("F", 72, 40, 15); } if(ulError & 4) { RIT128x96x4StringDraw("F", 108, 40, 15); } } else { RIT128x96x4StringDraw("Success. ", 18, 40, 15); } // // Finished. // while(1) { } }
int main(void) { //uint8_t Rx1_Buffer[BUFFER_SIZE1]; volatile uint16_t NumDataRead = 0; volatile uint16_t symbol; uint8_t command_buffer[10]= {0xe2,0xeb,0x81,120,0xc6,0xaf,0x88,0xb0,0x00,0x10}; uint32_t xtal_value; /* 0: 0xe2 - 11100010 - System Reset 1: 0xeb - 11101011 - Set LCD BIAS ratio [b1:b0] 2: 0x81 - 10000001 - Set VBIAS potentiometer 3: 0x50 - 01010000 - VBIAS potentiometer value 4: 0xc6 - 11000110 - Set LCD Mapping Control [b2:b1] 5: 0xaf - 10101111 - Set display ENABLE [b0] 6: 0x89 - 10001001 - Set RAM adress Control [b2:b0] 7: 0xb0 - 10110000 - Set Page Adress [b3:b0] 8: 0x00 - 00000000 - Set Column Adress LSB [b3:b0] 9: 0x10 - 00010000 - Set Column Adress MSB [b3:b0] */ uint32_t decimal[8]; //uint8_t string0[]="Display Works Fine"; //uint8_t tune.tune_freq_vis[]="14000000"; /*Start Frequency*/ //uint8_t string2[]="FREQUENCY"; //uint8_t string3[]="HAM RADIO BAND"; uint8_t string4[]="20m USB 2800Hz x100";/*BAND MODE FILTER GAIN*/ //uint8_t string5[]="MODE SSB USB"; //uint8_t string6[]="GAIN 1000"; uint8_t string7[]="PRE:Off ATT:20 AGC:S"; uint8_t data_buffer[132]; uint8_t data_buffer1[132]; uint8_t data_buffer2[132]; uint8_t data_buffer3[132]; uint8_t si570_buf[11]; uint32_t bit_order; uint8_t current_pointer; uint8_t k, n, sp, lzs_flag, symb_width, enc1_pulse_ccw, enc1_pulse_cw,enc2_pulse_ccw, enc2_pulse_cw, show_it; uint8_t option_select, sub_option_select; uint8_t n1; uint8_t hs_div_code; uint32_t i,j/*,noise_filter_button*/; uint8_t display_menu; uint8_t offcet_x; extern menu_struct_t menu[MAX_MENU_QTY]; extern band_struct_t band_menu[MAX_BAND_QTY]; extern mode_struct_t mode_menu[MAX_MODE_QTY]; extern filter_struct_t filter_menu[MAX_FILTER_QTY]; extern gain_struct_t gain_menu; extern tune_struct_t tune; RCC_ClocksTypeDef RCC_Clocks; RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* SysTick end of count event each 10ms */ //if (FLASH_OB_GetRDP()!=SET) //{ // FLASH_OB_Unlock(); /*enable the FLASH option control register access*/ // FLASH_OB_RDPConfig(OB_RDP_Level_1); /*SET RDP=1*/ // FLASH_OB_Launch(); /*launch the Option Bytes programming process*/ // FLASH_OB_Lock(); /*disable the FLASH option control register*/ //} /* Initialize LEDs and LCD available on STM324xG-EVAL board *****************/ STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED5); STM_EVAL_LEDInit(LED6); /* Initialize user button STM324xG-EVAL board *****************/ STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); STM_EVAL_ControlInit(CODEC_RESET); BOARD_GPIO_Init(); /*encoder input init*/ /* Turn on LEDs available on STM324xG-EVAL **********************************/ STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); STM_EVAL_LEDOff(LED5); STM_EVAL_LEDOff(LED6); STM_EVAL_ControlOn(CODEC_RESET); Delay (300); STM_EVAL_ControlOff(CODEC_RESET); xtal_value=(uint32_t)114197425;/*0x6cfd9c8*/ freq_code_old=0; NumDataRead = 1; /* Initialize the I2C EEPROM driver ----------------------------------------*/ sEE_Init(); /* Initialize the CODEC driver*/ EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_I2S); EVAL_AUDIO_Init(OUTPUT_DEVICE_HEADPHONE, 255, I2S_AudioFreq_48k); EVAL_AUDIO_Play(sound, 96); /*Continuous Beep from codec*/ Codec_WriteRegister(0x1E, 0xC0); Delay (100); LCD_Write_Command(0x70, command_buffer, 1); Delay (10); LCD_Write_Command(0x70, (command_buffer+1), 5); Delay (10); n=0xA1;/*100 Hz frame rate*/ LCD_Write_Command(0x70, &n, 1); bit_order=0x989680; /*1e+7 decimal*/ for (j=0; j<8; j++) /*filling array for decimal to binary conversion*/ { decimal[j]=bit_order; bit_order=bit_order/10; } /*Clear display*/ symbol=0x00; for (j=0; j<8; j++) { for (i=0; i<131; i++) { data_buffer[i]=symbol; } LCD_Write_Command(0x70, (command_buffer+6), 4); Delay (10); LCD_Write_Data(0x70, data_buffer, (uint32_t)132); command_buffer[7]++; Delay (10); } si570_buf[6]=0x10;/*freeze DCO reg 137*/ si570_buf[7]=0x00;/*unfreeze DCO reg 137*/ si570_buf[8]=0x40;/*status new dco reg 135*/ si570_buf[9]=0x20;/*freeze M bit reg 135*/ si570_buf[10]=0x00;/*unfreeze M bit reg 135*/ // command_buffer[7]=0xb3; // LCD_Write_Command(0x70, (command_buffer+6), 4); freq2=0; i=5; j=0; k=0; sp=0; display_menu=0; show_it=1; /*initial display*/ display_menu=1; current_menu=0; old_value=new_value=((uint32_t)GPIO_ReadInputData(GPIOB))&ENCODERS_MASK; while (1) { new_value=((uint32_t)GPIO_ReadInputData(GPIOB))&ENCODERS_MASK; if (new_value!=old_value) { current_pointer=1; enc1_old_value=old_value&ENCODER1_MASK; enc2_old_value=old_value&ENCODER2_MASK; enc1_new_value=new_value&ENCODER1_MASK; enc2_new_value=new_value&ENCODER2_MASK; if (enc2_new_value!=enc2_old_value) { current_pointer=0; if ((enc2_old_value&ENCODER2_A_MASK)!=((enc2_new_value<<1)&ENCODER2_A_MASK))/*==ENCODER2_MASK*/ { STM_EVAL_LEDToggle(LED3); enc2_pulse_ccw=0; enc2_pulse_cw++; } else { STM_EVAL_LEDToggle(LED6); enc2_pulse_cw=0; enc2_pulse_ccw++; } //old_value=new_value; if (enc2_pulse_cw==4) /*increment*/ { if (STM_EVAL_PBGetState(BUTTON_USER)==0) /*if user button not pressed - > change sub menu*/ { menu[current_menu].menu_current_state++; if(menu[current_menu].menu_current_state>menu[current_menu].menu_states_qty-1) /*control if submenu<MAX_SUBMENU*/ { menu[current_menu].menu_current_state=0; } /*apply handler with action parameter*/ } else /*change menu*/ { current_menu++; if (current_menu>MAX_MENU_QTY-1) /*control if menu<MAX_MENU*/ { current_menu=0; } } enc2_pulse_cw=0; enc2_pulse_ccw=0; display_menu=1; if (current_menu==0) show_it=1; } else { if (enc2_pulse_ccw==4) /*decrement*/ { if (STM_EVAL_PBGetState(BUTTON_USER)==0) /*if user button not pressed - > change sub menu*/ { menu[current_menu].menu_current_state--; if (menu[current_menu].menu_current_state<0) { menu[current_menu].menu_current_state=menu[current_menu].menu_states_qty-1; } /*apply handler with action parameter*/ } else /*change menu*/ { current_menu--;/*control if menu<MAX_MENU*/ if (current_menu<0) { current_menu=MAX_MENU_QTY-1; } } enc2_pulse_cw=0; enc2_pulse_ccw=0; display_menu=1; if (current_menu==0) show_it=1; } } } if (current_pointer==1) { if ((enc1_old_value&ENCODER1_A_MASK)!=((enc1_new_value<<1)&ENCODER1_A_MASK))/*==ENCODER1_MASK*/ { STM_EVAL_LEDToggle(LED5); enc1_pulse_ccw=0; enc1_pulse_cw++; } else { STM_EVAL_LEDToggle(LED4); enc1_pulse_cw=0; enc1_pulse_ccw++; } old_value=new_value; /*--------------------------------------------------*/ if (enc1_pulse_cw==4) /*increment*/ { if (STM_EVAL_PBGetState(BUTTON_USER)==0) { for (j=1; j<8-i; j++) { tune.tune_freq_vis[i+j]=0x30; } enc1_pulse_cw=0; enc1_pulse_ccw=0; if ((tune.tune_freq_vis[i]&0x0f)==0x09) { tune.tune_freq_vis[i]=0; j=1; while ((tune.tune_freq_vis[i-j]&0x0f)==0x09) { tune.tune_freq_vis[i-j]=0; j++; } tune.tune_freq_vis[i-j]++; } else { tune.tune_freq_vis[i]++; } show_it=1; } else { enc1_pulse_cw=0; enc1_pulse_ccw=0; if (i==7) { i=0; } else { i++; } show_it=1; } } /*--------------------------------------------------*/ else { if (enc1_pulse_ccw==4) /*decrement*/ { if (STM_EVAL_PBGetState(BUTTON_USER)==0) { for (j=1; j<8-i; j++) { tune.tune_freq_vis[i+j]=0x30; } enc1_pulse_cw=0; enc1_pulse_ccw=0; if ((tune.tune_freq_vis[i]&0x0f)==0x00) { tune.tune_freq_vis[i]=9; j=1; while ((tune.tune_freq_vis[i-j]&0x0f)==0x00) { tune.tune_freq_vis[i-j]=9; j++; } tune.tune_freq_vis[i-j]--; } else { tune.tune_freq_vis[i]--; } } else { enc1_pulse_cw=0; enc1_pulse_ccw=0; if (i==0) { i=7; } else { i--; } show_it=1; } } show_it=1; } } if (display_menu==1) /*build menu buffer*/ { display_menu=0; pp1=menu[current_menu].pFunc(MODIFY); for (j=0; j<MAX_MENU_QTY; j++) { k=0; offcet_x=menu[j].menu_x_pos; pp1=menu[j].pFunc(DISPLAY); if (j==current_menu) { data_buffer2[k+offcet_x]=0xFF; data_buffer3[k+offcet_x]=0x07; k++; while ((*pp1)!=0) { for (jj=0; jj<5; jj++) { symbol=symboltable[(*pp1)-0x20][jj]; data_buffer2[k+offcet_x]=~(symbol<<2);/*Fill Upper buffer*/ data_buffer3[k+offcet_x]=~((symbol>>6)|0xF8); k++; } data_buffer2[k+offcet_x]=0xFF; data_buffer3[k+offcet_x]=0x07; k++; pp1++; } data_buffer2[k+offcet_x]=0xFF; data_buffer3[k+offcet_x]=0x07; } else { data_buffer2[k+offcet_x]=0x00; data_buffer3[k+offcet_x]=0x00; k++; while ((*pp1)!=0) { for (jj=0; jj<5; jj++) { symbol=symboltable[(*pp1)-0x20][jj]; data_buffer2[k+offcet_x]=(uint8_t)symbol<<2;/*Fill Upper buffer*/ data_buffer3[k+offcet_x]=(uint8_t)symbol>>6; k++; } data_buffer2[k+offcet_x]=0x00; data_buffer3[k+offcet_x]=0x00; k++; pp1++; } data_buffer2[k+offcet_x]=0x00; data_buffer3[k+offcet_x]=0x00; } }
void GetChangedExternInputs(void) { COUNTER_PxOUT |= (COUNTER1_PxBIT | COUNTER2_PxBIT); SBx_PxOUT |= (SB1_PxBIT | SB2_PxBIT); TAMPER_PxOUT |= TAMPER_PxBIT; #ifdef USE_DELAY_EXT_INPUT Delay(DELAY_EXT_INPUT_ms); #endif if(!(TAMPER_PxIN & TAMPER_PxBIT)) param.statusButtons |= E_BUTTON_TAMPER; else { if(param.status & E_STATUS_MAIN_MODE) param.status |= E_STATUS_ERROR; } if(!(SBx_PxIN & SB1_PxBIT)) param.statusButtons |= E_BUTTON_SBI; if(!(SBx_PxIN & SB2_PxBIT)) param.statusButtons |= E_BUTTON_SB2; /* counter 1 */ if(!(COUNTER_PxIN & COUNTER1_PxBIT)) { if(param.status & E_STATUS_COUNTER1_UP) { param.status &=~ E_STATUS_COUNTER1_UP; param.status |= E_STATUS_COUNTER1_DW; if(!(param.status & E_STATUS_ERROR)) ExternCounterInc(NUM_CHANEL1); } }else { if(param.status & E_STATUS_COUNTER1_DW) { param.status &=~ E_STATUS_COUNTER1_DW; param.status |= E_STATUS_COUNTER1_UP; if(!(param.status & E_STATUS_ERROR)) ExternCounterInc(NUM_CHANEL1); } } /* counter 2 */ if(!(COUNTER_PxIN & COUNTER2_PxBIT)) { if(param.status & E_STATUS_COUNTER2_UP) { param.status &=~ E_STATUS_COUNTER2_UP; param.status |= E_STATUS_COUNTER2_DW; if(!(param.status & E_STATUS_ERROR)) ExternCounterInc(NUM_CHANEL2); } }else { if(param.status & E_STATUS_COUNTER2_DW) { param.status &=~ E_STATUS_COUNTER2_DW; param.status |= E_STATUS_COUNTER2_UP; if(!(param.status & E_STATUS_ERROR)) ExternCounterInc(NUM_CHANEL2); } } COUNTER_PxOUT &=~ (COUNTER1_PxBIT | COUNTER2_PxBIT); SBx_PxOUT &=~ (SB1_PxBIT | SB2_PxBIT); TAMPER_PxOUT &=~ TAMPER_PxBIT; }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f2xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f2xx.c file */ /* Initialize LED1, LED2 and Key Button mounted on STM322xG-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); /* Setup SysTick Timer for 1 msec interrupts */ if (SysTick_Config(SystemCoreClock / 1000)) { /* Capture error */ while (1); } /* Check if the system has resumed from IWDG reset */ if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET) { /* IWDGRST flag set */ /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); /* Clear reset flags */ RCC_ClearFlag(); } else { /* IWDGRST flag is not set */ /* Turn off LED1 */ STM_EVAL_LEDOff(LED1); } /* Get the LSI frequency: TIM5 is used to measure the LSI frequency */ LsiFreq = GetLSIFrequency(); /* IWDG timeout equal to 250 ms (the timeout may varies due to LSI frequency dispersion) */ /* Enable write access to IWDG_PR and IWDG_RLR registers */ IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); /* IWDG counter clock: LSI/32 */ IWDG_SetPrescaler(IWDG_Prescaler_32); /* Set counter reload value to obtain 250ms IWDG TimeOut. Counter Reload Value = 250ms/IWDG counter clock period = 250ms / (LSI/32) = 0.25s / (LsiFreq/32) = LsiFreq/(32 * 4) = LsiFreq/128 */ IWDG_SetReload(LsiFreq/128); /* Reload IWDG counter */ IWDG_ReloadCounter(); /* Enable IWDG (the LSI oscillator will be enabled by hardware) */ IWDG_Enable(); while (1) { /* Toggle LED2 */ STM_EVAL_LEDToggle(LED2); /* Insert 240 ms delay */ Delay(240); /* Reload IWDG counter */ IWDG_ReloadCounter(); } }
/* ** main routine. Open required library and window and draw the images. ** This routine opens a very simple window with no IDCMP. See the ** chapters on "Windows" and "Input and Output Methods" for more info. ** Free all resources when done. */ int main(int argc, char **argv) { struct Screen *screen; struct DrawInfo *drawinfo; struct Window *win; struct IntuiText myIText; struct TextAttr myTextAttr; ULONG myTEXTPEN; ULONG myBACKGROUNDPEN; IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37); if (IntuitionBase) { #ifdef __AROS__ if ((screen = LockPubScreen(NULL))) #else if (screen = LockPubScreen(NULL)) #endif { #ifdef __AROS__ if ((drawinfo = GetScreenDrawInfo(screen))) #else if (drawinfo = GetScreenDrawInfo(screen)) #endif { /* Get a copy of the correct pens for the screen. ** This is very important in case the user or the ** application has the pens set in a unusual way. */ myTEXTPEN = drawinfo->dri_Pens[TEXTPEN]; myBACKGROUNDPEN = drawinfo->dri_Pens[BACKGROUNDPEN]; /* create a TextAttr that matches the specified font. */ myTextAttr.ta_Name = drawinfo->dri_Font->tf_Message.mn_Node.ln_Name; myTextAttr.ta_YSize = drawinfo->dri_Font->tf_YSize; myTextAttr.ta_Style = drawinfo->dri_Font->tf_Style; myTextAttr.ta_Flags = drawinfo->dri_Font->tf_Flags; /* open a simple window on the workbench screen for displaying ** a text string. An application would probably never use such a ** window, but it is useful for demonstrating graphics... */ #ifdef __AROS__ if ((win = OpenWindowTags(NULL, WA_PubScreen, (IPTR)screen, WA_RMBTrap, TRUE, WA_IDCMP, IDCMP_RAWKEY, TAG_END))) #else if (win = OpenWindowTags(NULL, WA_PubScreen, screen, WA_RMBTrap, TRUE, TAG_END)) #endif { myIText.FrontPen = myTEXTPEN; myIText.BackPen = myBACKGROUNDPEN; myIText.DrawMode = JAM2; myIText.LeftEdge = MYTEXT_LEFT; myIText.TopEdge = MYTEXT_TOP; myIText.ITextFont = &myTextAttr; myIText.IText = "Hello, World. ;-)"; myIText.NextText = NULL; /* Draw the text string at 10,10 */ PrintIText(win->RPort,&myIText,10,10); #ifdef __AROS__ /* Wait for keypress */ Wait (1L << win->UserPort->mp_SigBit); #else /* Wait a bit, then quit. ** In a real application, this would be an event loop, ** like the one described in the Intuition Input and ** Output Methods chapter. */ Delay(200); #endif CloseWindow(win); } FreeScreenDrawInfo(screen,drawinfo); } UnlockPubScreen(NULL,screen); } CloseLibrary((struct Library *)IntuitionBase); } return 0; }
//*-------------------------------------------------------------------------------------- //* Function Name : main //* Object : //*-------------------------------------------------------------------------------------- int main ( void ) { // char button = 0; // int x = 0, y = 0, j = 0; // int adc; // int i = 0; int x,y,z,i; button_flag = 0; //Init trace DBGU //AT91F_DBGU_Init(); //AT91F_DBGU_Printk("\n\r-I- BasicUSB 1.1 (USB_DP_PUP) \n\r0) Set Pull-UP 1) Clear Pull UP\n\r"); //Enable RESET m_pRSTC->RSTC_RCR = 0xA5000008; m_pRSTC->RSTC_RMR = 0xA5000001; Delay(1000); // Init USB device AT91F_USB_Open(); // Configure the RTT: *AT91C_RTTC_RTMR = BUTTON_SAMPLING; // Set in PIO mode and Configure in Input AT91F_PIOA_CfgPMC(); // AT91F_PIO_CfgInput(AT91C_BASE_PIOA, (SW1|SW2)); // Wait for the end of enumeration // while (!HID.IsConfigured(&HID)); // InitMAM InitMMA(); // InitADC ADCInit(); // UART0 Init InitUSART0(); // Stat led s_pPio->PIO_PER = BIT31; // Configure PA31 as output s_pPio->PIO_OER = BIT31; // Set PA31 to HIGH s_pPio->PIO_SODR = BIT31; // Test flash if(TestFlash()) { for(i=0; i<20; i++) { s_pPio->PIO_CODR = BIT31; Delay(150000); s_pPio->PIO_SODR = BIT31; Delay(150000); } } // Button // Configure P20 as input s_pPio->PIO_ODR = BIT20; // Enable s_pPio->PIO_PER = BIT20; Delay(1000); // CALIBRATE WHEN BUTT IS PRESS // while((s_pPio->PIO_PDSR&BIT20)==BIT20); Delay(1000); // Get coordinates GetCoordinates(); base_y = Coordinates[0]/NSAMPLE; base_x = Coordinates[1]/NSAMPLE; base_z = Coordinates[2]/NSAMPLE; // Start waiting some cmd while (1) { // Check enumeration if (HID.IsConfigured(&HID)) { // check button status if((s_pPio->PIO_PDSR&BIT20)==0) { // Set PA31 to LOW s_pPio->PIO_CODR = BIT31; // set button flag button_flag = 0x01; Delay(1000); } else { // Set PA31 to HIGH // s_pPio->PIO_SODR = BIT31; // clear button flag button_flag = 0x00; } GetCoordinates(); Delay(10000); //* if((j++)==100) { //* //* print_view = PRINT_COORDINATES; //* write_report_USART0(); //* //* // print_view = PRINT_DIVERSION; //* // write_report_USART0(); //* //* j=0; //* } y = 478 - Coordinates[0]/NSAMPLE; // y = base_y - Coordinates[0]/NSAMPLE; if(y>40) { if(y<50) HID.SendReport(&HID, button_flag, 0, -1); else if (y<100) HID.SendReport(&HID, button_flag, 0, -2); else if (y<150) HID.SendReport(&HID, button_flag, 0, -3); else if (y<200) HID.SendReport(&HID, button_flag, 0, -6); else HID.SendReport(&HID, button_flag, 0, -16); } else if(y<-40){ if(y>-50) HID.SendReport(&HID, button_flag, 0, 1); else if (y>-100) HID.SendReport(&HID, button_flag, 0, 2); else if (y>-150) HID.SendReport(&HID, button_flag, 0, 3); else if (y>-200) HID.SendReport(&HID, button_flag, 0, 6); else HID.SendReport(&HID, button_flag, 0, 16); } x = 565 - Coordinates[1]/NSAMPLE; // x = base_x - Coordinates[1]/NSAMPLE; if(x>40) { if(x<50) HID.SendReport(&HID, button_flag, -1, 0); else if (x<100) HID.SendReport(&HID, button_flag, -2, 0); else if (x<150) HID.SendReport(&HID, button_flag, -3, 0); else if (x<200) HID.SendReport(&HID, button_flag, -6, 0); else HID.SendReport(&HID, button_flag, -16, 0); } else if(x<-40){ if(x>-50) HID.SendReport(&HID, button_flag, 1, 0); else if (x>-100) HID.SendReport(&HID, button_flag, 2, 0); else if (x>-150) HID.SendReport(&HID, button_flag, 3, 0); else if (x>-200) HID.SendReport(&HID, button_flag, 6, 0); else HID.SendReport(&HID, button_flag, 16, 0); } // just test Z coordinate z = Coordinates[2]/NSAMPLE; if(z<300) { s_pPio->PIO_CODR = BIT31; } else { s_pPio->PIO_SODR = BIT31; } Delay(20); //* x = ((150) - GetADC4())/20; //* HID.SendReport(&HID, button, x, 0); //* Delay(50); //* HID.SendReport(&HID, button, ((base_y) - GetADC5())/50, 0); //* Delay(50); //* HID.SendReport(&HID, button, ((base_z) - GetADC6())/50, 0); //* Delay(50); //* //* button = 0; //* //* for(j=0; j<100; j++) { //* HID.SendReport(&HID, button, 1, 0); //* Delay(50); //* } //* //* for(j=0; j<100; j++) { //* HID.SendReport(&HID, button, 0, 1); //* Delay(50); //* } //* //* for(j=0; j<100; j++) { //* HID.SendReport(&HID, button, -1, 0); //* Delay(50); //* } //* //* for(j=0; j<100; j++) { //* HID.SendReport(&HID, button, 0, -1); //* Delay(50); //* } } } }
void Work2(){printf("Start 2\n");Delay();printf("End 2\n");}
//----------------------------------------------- //local functions //----------------------------------------------- void execEvent(struct Event event) { int i, iPara, iCmd; int iSynchVal, iSynchValMeasNorm, iDeltaSynchMeas; static enum STATE_Connection s_StConnection = ST_ConnReset; static enum STATE_Motor s_StMotor = ST_BrakeClosed; iCmd = event.ucData[0]; switch(s_StConnection) { case ST_ConnReset: //------------------- switch(iCmd) { //------------------- case CMD_MOTCTRL_CONNECT: transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK); s_StConnection = ST_ConnConnected; break; //------------------- case CMD_MOTCTRL_DISCONNECT: _trap_(0x00); break; //------------------- default: if(event.iSource != EVSOURCE_INTERN) transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept); break; } break; //case ST_ConnReset case ST_ConnConnected: //--------------------------------------- //commands always executed switch(iCmd) { //------------------- case CMD_MOTCTRL_DISCONNECT: _trap_(0x00); return; //------------------- //io case CMD_MOTCTRL_SETDIGOUT: setOutputPort8(event.ucData[1], event.ucData[2]); return; //------------------- case CMD_MOTCTRL_GETDIGIN: transmitMsg(event.iSource, P1H, P1L, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK); return; //------------------- case CMD_MOTCTRL_GETANALOGIN: iPara = g_iAnIn[event.ucData[1]]; transmitMsg(event.iSource, iPara >> 8, iPara, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK); return; //------------------- //debug case CMD_MOTCTRL_SETCTRLPARA: g_iIn1 = (event.ucData[1] << 8) | event.ucData[2]; g_iIn2 = (event.ucData[3] << 8) | event.ucData[4]; g_iIn3 = (event.ucData[5] << 8) | event.ucData[6]; //synch pos fine tuning //gc_iFieldPosSynchNorm = g_iIn1; return; //------------------- case CMD_MOTCTRL_GETCTRLPARA: transmitMsg(event.iSource, g_iOut1 >> 8, g_iOut1, g_iOut2 >> 8, g_iOut2, g_iOut3 >> 8, g_iOut3, 0, (iCmd << 2) | Msg_OK); return; //------------------- //get data case CMD_MOTCTRL_GETPOSVEL: transmitMsg(event.iSource, g_lPosMeas >> 24, g_lPosMeas >> 16, g_lPosMeas >> 8, g_lPosMeas, g_iVelMeas >> 8, g_iVelMeas, 0, (iCmd << 2) | Msg_OK); return; //------------------- case CMD_MOTCTRL_GETSTATUS: transmitMsg(event.iSource, g_iStateCtrl >> 8, g_iStateCtrl, g_iTempMeas >> 8, g_iTempMeas, 0, 0, 0, (iCmd << 2) | Msg_OK); return; } //--------------------------------------- //motor control commands state machine switch(s_StMotor) { //------------------- case ST_BrakeClosed: switch(iCmd) { case CMD_MOTCTRL_DISABLEBRAKE: if(event.ucData[1] == 1) { openBrake(gc_iBrakeHasRelais); transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK); s_StMotor = ST_BrakeOpen; } break; //CMD_MOTCTRL_DISABLEBRAKE default: if(event.iSource != EVSOURCE_INTERN) transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept); } //switch(iCmd) break; //ST_BrakeClosed //------------------- case ST_BrakeOpen: switch(iCmd) { case CMD_MOTCTRL_DISABLEBRAKE: if(event.ucData[1] == 0) { closeBrake(gc_iBrakeHasRelais); s_StMotor = ST_BrakeClosed; transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK); } break; //CMD_MOTCTRL_DISABLEBRAKE case CMD_MOTCTRL_ENABLEMOTOR: if(event.ucData[1] == 1) { enableMotor(gc_iSineZero); g_iPosVelCtrlRun = 0; g_iTorqueCmd = 0; g_iTorqueCtrlRun = 1; g_iFieldPos = 0; g_iCommRun = 0; g_iSynchRun = 1; //increase torque slowly do { g_iTorqueCmd++; Delay(5000); } while(g_iTorqueCmd < gc_iSynchTorque); s_StMotor = ST_MotorEnabled; transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK); } break; //CMD_MOTCTRL_ENABLEMOTOR default: if(event.iSource != EVSOURCE_INTERN) transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept); } //switch(iCmd) break; //ST_BrakeOpen //------------------- case ST_MotorEnabled: switch(iCmd) { case CMD_MOTCTRL_ENABLEMOTOR: if(event.ucData[1] == 0) { disableMotorCtrl(); s_StMotor = ST_BrakeOpen; transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK); } break; //CMD_MOTCTRL_ENABLEMOTOR case CMD_MOTCTRL_SYNCHMOTOR: //exec single rot to snap in rotor for(i=0; i<gc_iEncPulsePerRev; i++) { g_iFieldPos++; Delay(gc_iSynchVelDelay); } g_iFieldPos = 0; g_lPosOffset = g_lPosOffset + T2; //g_lPosOffset used to move back to 0 after synch T2 = 0; //enable synch int g_iSynchIntCaptured = 0; EXICON = 0x0008 | 0x0001; //EXIN0 interrupt on pos edge, EXIN1 interrupt on neg edge //wait for synch interrupt, communication blocking while(g_iSynchIntCaptured == 0) { _atomic_(3); //if no synch interrupt captured, update iSynchVal if(g_iSynchIntCaptured == 0) iSynchVal = T2; g_iFieldPos++; Delay(gc_iSynchVelDelay); } g_lPosOffset = g_lPosOffset + iSynchVal; //shift back iSynchVal while(iSynchVal > gc_iEncPulsePerPhase) iSynchVal = iSynchVal - gc_iEncPulsePerPhase; //reset T2, g_iT2RevCnt -> EncPosAbs = 0 T2 = 0; g_iT2RevCnt = 0; if(gc_iMotorType == MotorType_6Pol) iSynchValMeasNorm = toFieldPosNorm_Mot6Pol_Enc4096(iSynchVal); if(gc_iMotorType == MotorType_4Pol) iSynchValMeasNorm = toFieldPosNorm_Mot4Pol_Enc4096(iSynchVal); iDeltaSynchMeas = iSynchValMeasNorm - gc_iFieldPosSynchNorm; if(iDeltaSynchMeas < -255) iDeltaSynchMeas = iDeltaSynchMeas + 512; if(iDeltaSynchMeas > 255) iDeltaSynchMeas = iDeltaSynchMeas - 512; //test for correct SynchVal if((iDeltaSynchMeas > -30) && (iDeltaSynchMeas < 90)) { transmitMsg(event.iSource, iSynchValMeasNorm >> 8, iSynchValMeasNorm, gc_iFieldPosSynchNorm >> 8, gc_iFieldPosSynchNorm, 0, 0, 0, (iCmd << 2) | Msg_OK); s_StMotor = ST_MotorSynch; } else { disableMotorCtrl(); transmitMsg(event.iSource, iSynchValMeasNorm >> 8, iSynchValMeasNorm, gc_iFieldPosSynchNorm >> 8, gc_iFieldPosSynchNorm, 0, 0, 0, (iCmd << 2) | Msg_Error); s_StMotor = ST_BrakeOpen; } break; //CMD_MOTCTRL_SYNCHMOTOR default: if(event.iSource != EVSOURCE_INTERN) transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept); } //switch(iCmd) break; //ST_MotorEnabled //------------------- case ST_MotorSynch: switch(iCmd) { case CMD_MOTCTRL_ENABLECOMM: g_iTorqueCmd = 0; while(g_lTorqueCmd != 0) ; g_iT2Overflow = 0; g_lPosCmd = getEncPosAbsAsLong(); g_iSynchRun = 0; g_iCommRun = 1; g_iPosVelCtrlRun = 1; s_StMotor = ST_MotorRunning; setVoltDownBrake(gc_iBrakeHasRelais); transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK); break; //CMD_MOTCTRL_ENABLECOMM default: if(event.iSource != EVSOURCE_INTERN) transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept); } //switch break; //ST_MotorSynch //------------------- case ST_MotorRunning: switch(iCmd) { case CMD_MOTCTRL_SETCMDVAL: g_lPosCmd = (((long int)event.ucData[1]) << 24 | ((long int)event.ucData[2]) << 16 | ((long int)event.ucData[3]) << 8 | (long int)event.ucData[4]); g_iVelCmd = event.ucData[5] << 8 | event.ucData[6]; transmitMsg(event.iSource, g_iStateCtrl >> 8, g_iStateCtrl, g_iTempMeas >> 8, g_iTempMeas, 0, 0, 0, (CMD_MOTCTRL_GETSTATUS << 2) | Msg_OK); transmitMsg(event.iSource, g_lPosMeas >> 24, g_lPosMeas >> 16, g_lPosMeas >> 8, g_lPosMeas, g_iVelMeas >> 8, g_iVelMeas, 0, (CMD_MOTCTRL_GETPOSVEL << 2) | Msg_OK); break; //CMD_MOTCTRL_SETCMDVAL case CMD_MOTCTRL_SETMOTIONTYPE: g_iStMotionType = event.ucData[1]; transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK); break; //CMD_MOTCTRL_SETMOTIONTYPE case CMD_MOTCTRL_SETEMSTOP: g_iPosVelCtrlRun = 0; g_iVelCmd = 0; g_iTorqueCmd = 0; //decrease torque slowly /* while(g_iTorqueCmd > 0) { g_iTorqueCmd--; Delay(3000); } */ closeBrake(gc_iBrakeHasRelais); s_StMotor = ST_MotorEMStop; if(event.iSource != EVSOURCE_INTERN) transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK); break; //CMD_MOTCTRL_SETEMSTOP case CMD_MOTCTRL_ENABLEMOTOR: if(event.ucData[1] == 0) { disableMotorCtrl(); s_StMotor = ST_BrakeOpen; transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK); } break; //CMD_MOTCTRL_ENABLEMOTOR default: if(event.iSource != EVSOURCE_INTERN) transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept); } //switch(iCmd) break; //ST_MotorRunning //------------------- case ST_MotorEMStop: switch(iCmd) { case CMD_MOTCTRL_SETCMDVAL: transmitMsg(event.iSource, g_iStateCtrl >> 8, g_iStateCtrl, g_iTempMeas >> 8, g_iTempMeas, 0, 0, 0, (CMD_MOTCTRL_GETSTATUS << 2) | Msg_OK); transmitMsg(event.iSource, g_lPosMeas >> 24, g_lPosMeas >> 16, g_lPosMeas >> 8, g_lPosMeas, g_iVelMeas >> 8, g_iVelMeas, 0, (CMD_MOTCTRL_GETPOSVEL << 2) | Msg_OK); break; //CMD_MOTCTRL_SETCMDVAL case CMD_MOTCTRL_RESETEMSTOP: openBrake(gc_iBrakeHasRelais); g_iPosVelCtrlRun = 1; s_StMotor = ST_MotorRunning; transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK); break; case CMD_MOTCTRL_ENABLEMOTOR: if(event.ucData[1] == 0) { disableMotorCtrl(); s_StMotor = ST_BrakeOpen; transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK); } break; //CMD_MOTCTRL_ENABLEMOTOR default: if(event.iSource != EVSOURCE_INTERN) transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept); } //switch(iCmd) break; //ST_MotorEMStop } //switch(StMotor)
/* * Automatic baudrate detection. * * Switch to different baud rates and wait * for a space character. */ int DetectSpeed(void) { #if defined (__AVR__) uint8_t bstab[] = { 1, /* 115200 @ 3.6864 */ 7, /* 115200 @ 14.7456 */ 23, /* 9600 @ 3.6864, 19200 @ 7.3728, 38400 @ 14.7456 */ 11, /* 19200 @ 3.6864, 38400 @ 7.3728, 76800 @ 14.7456 */ 12, /* 19200 @ 4.0000, 38400 @ 8.0000, 57600 @ 12.0000, 76800 @ 16.0000 */ 25, /* 9600 @ 4.0000, 19200 @ 8.0000, 38400 @ 16.0000 */ 5, /* 38400 @ 3.6864, 76800 @ 7.3728 */ 47, /* 9600 @ 7.3728, 19200 @ 14.7456 */ 51, /* 9600 @ 8.0000, 19200 @ 16.0000 */ 3, /* 115200 @ 7.3728 */ 9, /* 115200 @ 18.4320 */ 2, /* 76800 @ 3.6864 */ 14, /* 76800 @ 18.4320 */ 29, /* 38400 @ 18.4320 */ 64, /* 19200 @ 20.0000 */ 59, /* 19200 @ 18.4320 */ 95, /* 9600 @ 14.7456 */ 103, /* 9600 @ 16.0000 */ 119, /* 9600 @ 18.4320 */ 129, /* 9600 @ 20.0000 */ 77 /* 9600 @ 12.0000 */ }; uint8_t bsx; int bs; uint16_t i; uint8_t t; uint8_t rec; uint8_t ict; /* Imagecraft dummy */ /* * Enable UART transmitter and receiver. */ outb(UCR, _BV(RXEN) | _BV(TXEN)); /* * Sixteen retries. */ for (t = 1; t < 16; t++) { for (bsx = 0; bsx < sizeof(bstab); bsx++) { bs = bstab[bsx]; /* * Set baudrate selector. */ Delay(1000); if ((inb(USR) & _BV(RXC)) != 0) ict = inb(UDR); outb(UBRR, (uint8_t) bs); Delay(1000); if ((inb(USR) & _BV(RXC)) != 0) ict = inb(UDR); /* * Now wait for some time for a character received. */ for (i = 0; i < 40; i++) { if ((inb(USR) & _BV(RXC)) != 0) break; Delay(1000); } rec = 0; for (i = 1; i; i++) { if ((inb(USR) & _BV(RXC)) != 0) { if (inb(UDR) == 32) { if (rec++) return bs; i = 1; } else { rec = 0; break; } } else if (rec) Delay(100); } } } outb(UBRR, 23); #endif return -1; }
// Arena Script NamedScript MapSpecial void ArenaLoop() { int BonusRandomizer, Buttons, OldButtons; bool Ready; ArenaSetEnvironment(AEVENT_NONE); // Arena Loop while (true) { // Stop the script if the Arena is stopped or the Arena activator dies if (!ArenaActive || ClassifyActor(Players(ArenaPlayerNumber).TID) & ACTOR_DEAD) { ArenaStop(); return; } // Arena HUD ArenaDrawHUD(); // Arena Status Handling if (ArenaState == ARENA_INTERMISSION) { BonusRandomizer = Random(-10, ABONUS_MAX - 1); ArenaMod = -1; ArenaGetBonus(BonusRandomizer); ArenaSetEnvironment(AEVENT_NONE); ArenaState = ARENA_WAITING; } else if (ArenaState == ARENA_WAITING) { Buttons = GetPlayerInput(ArenaPlayerNumber, INPUT_BUTTONS); OldButtons = GetPlayerInput(ArenaPlayerNumber, INPUT_OLDBUTTONS); Ready = true; SetHudSize(0, 0, false); SetFont("BIGFONT"); if (ArenaPlayerNumber == PlayerNumber()) { if (!Player.InMenu && !Player.InShop && !Player.OutpostMenu) { HudMessage("Press \Cd%jS\C- to start the next wave\nPress \Cd%jS\C- to exit the Arena", "+use" , "+speed"); EndHudMessage(HUDMSG_PLAIN, 0, "White", 1.5, 0.75, 0.05); } if (Buttons & BT_USE && (!Player.InMenu && !Player.InShop && !Player.OutpostMenu && !Player.CrateOpen) && !Player.MenuBlock) { // Check to see if others are still in the menu for (int i = 0; i < MAX_PLAYERS; i++) if (Players(i).InMenu || Players(i).InShop) Ready = false; if (Ready) { ArenaKeyTimer++; ArenaKeyTimerType = AKTIMER_CONTINUE; if (ArenaKeyTimer > ARENA_HOLDTIME) { // Multiplayer Countdown if (InMultiplayer) { SetFont("BIGFONT"); for (int i = 3; i > 0; i--) { HudMessage("%d", i); EndHudMessageBold(HUDMSG_FADEOUT, 0, "Green", 0.5, 0.5, 0.25, 0.75); Delay(35); } } ArenaWave++; ArenaState = ARENA_READY; } } else { PrintError("Someone is currently in a menu"); ActivatorSound("menu/error", 127); } } else if (Buttons & BT_SPEED && (!Player.InMenu && !Player.InShop && !Player.OutpostMenu && !Player.CrateOpen)) { ArenaKeyTimer++; ArenaKeyTimerType = AKTIMER_STOP; if (ArenaKeyTimer > ARENA_HOLDTIME) { ArenaStop(); return; } } else ArenaKeyTimer = 0; // Reset menu block if (Buttons == 0 && OldButtons == 0) Player.MenuBlock = false; } }
//**************************************************************************** // //! \brief Opening a server side socket and receiving data //! //! This function opens a TCP socket in Listen mode and waits for an incoming //! TCP connection. If a socket connection is established then the function //! will try to read 1000 TCP packets from the connected client. //! //! \param[in] port number on which the server will be listening on //! //! \return 0 on success, -1 on Error. //! //! \note This function will wait for an incoming connection till one //! is established // //**************************************************************************** static int BsdTcpServer(unsigned short Port) { SlSockAddrIn_t Addr; SlSockAddrIn_t LocalAddr; int idx; int AddrSize; int SockID; int Status; int newSockID; long LoopCount = 0; long nonBlocking = 1; for (idx=0 ; idx<BUF_SIZE ; idx++) { uBuf.BsdBuf[idx] = (char)(idx % 10); } LocalAddr.sin_family = SL_AF_INET; LocalAddr.sin_port = sl_Htons((unsigned short)Port); LocalAddr.sin_addr.s_addr = 0; SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0); ASSERT_ON_ERROR(SockID); AddrSize = sizeof(SlSockAddrIn_t); Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize); if( Status < 0 ) { /* error */ sl_Close(SockID); ASSERT_ON_ERROR(Status); } Status = sl_Listen(SockID, 0); if( Status < 0 ) { sl_Close(SockID); ASSERT_ON_ERROR(Status); } Status = sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlocking, sizeof(nonBlocking)); ASSERT_ON_ERROR(Status); newSockID = SL_EAGAIN; while( newSockID < 0 && IS_IP_ACQUIRED(g_ulStatus)) { newSockID = sl_Accept(SockID, ( struct SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize); if( newSockID == SL_EAGAIN ) { /* Wait for 1 ms */ Delay(1); } else if( newSockID < 0 ) { sl_Close(SockID); ASSERT_ON_ERROR(newSockID); } } if(! IS_IP_ACQUIRED(g_ulStatus)) { return CLIENT_DISCONNECTED; } // run 'iperf -c <device IP> -i 1 -t 10000' command on PC/Smartphone while (LoopCount < TCP_PACKET_COUNT) { Status = sl_Recv(newSockID, uBuf.BsdBuf, BUF_SIZE, 0); if( Status <= 0 ) { /* error */ ASSERT_ON_ERROR(sl_Close(newSockID)); ASSERT_ON_ERROR(sl_Close(SockID)); ASSERT_ON_ERROR(Status); } LoopCount++; } GPIO_IF_LedOn(MCU_EXECUTE_SUCCESS_IND); ASSERT_ON_ERROR(sl_Close(newSockID)); ASSERT_ON_ERROR(sl_Close(SockID)); return SUCCESS; }
void delay_1_second(void) { Delay(1000); }
void ADC_Configuration(void) { #if DEBUG __IO uint32_t calibration_value; #endif ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; ADC_InjectedInitTypeDef ADC_InjInitStructure; ADC_StructInit(&ADC_InitStructure); /* Calibration procedure */ ADC_VoltageRegulatorCmd(ADC2, ENABLE); /* Insert delay equal to 10 µs */ Delay(10); ADC_SelectCalibrationMode(ADC2, ADC_CalibrationMode_Single); ADC_StartCalibration(ADC2); for (; ADC_GetCalibrationStatus(ADC2) != RESET ;); #if DEBUG calibration_value = ADC_GetCalibrationValue(ADC2); #endif ADC_CommonInitStructure.ADC_Mode = ADC_Mode_InjSimul; ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_OneShot; ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0; ADC_CommonInit(ADC2, &ADC_CommonInitStructure); ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable; ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0; ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable; ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Enable; ADC_InitStructure.ADC_NbrOfRegChannel = 3; ADC_Init(ADC2, &ADC_InitStructure); ADC_InjInitStructure.ADC_ExternalTrigInjecConvEvent = ADC_ExternalTrigInjecConvEvent_0; ADC_InjInitStructure.ADC_ExternalTrigInjecEventEdge = ADC_ExternalTrigInjecEventEdge_None; ADC_InjInitStructure.ADC_NbrOfInjecChannel = 3; ADC_InjInitStructure.ADC_InjecSequence1 = ADC_Channel_5; ADC_InjInitStructure.ADC_InjecSequence2 = ADC_Channel_11; ADC_InjInitStructure.ADC_InjecSequence3 = ADC_Channel_12; ADC_InjectedInit(ADC2, &ADC_InjInitStructure); /* ADC1 regular channel7 configuration */ //ADC_RegularChannelConfig(ADC2, ADC_Channel_5, 1, ADC_SampleTime_7Cycles5); ADC_InjectedChannelSampleTimeConfig(ADC2, ADC_Channel_5, ADC_SampleTime_7Cycles5); ADC_InjectedChannelSampleTimeConfig(ADC2, ADC_Channel_11,ADC_SampleTime_7Cycles5); ADC_InjectedChannelSampleTimeConfig(ADC2, ADC_Channel_12,ADC_SampleTime_7Cycles5); /* Enable ADC1 */ ADC_Cmd(ADC2, ENABLE); /* wait for ADRDY */ while(!ADC_GetFlagStatus(ADC2, ADC_FLAG_RDY)); /* Start ADC1 Software Conversion */ ADC_StartConversion(ADC2); }
void delay_100_milli_second(void) { Delay(100); }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f2xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f2xx.c file */ /* Initialize LEDs and Key Button mounted on STM322xG-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* Test if Key push-button on STM322xG-EVAL board is pressed */ if (STM_EVAL_PBGetState(BUTTON_KEY) == 0x00) { /* Key is pressed */ /* Enable GPIOA and GPIOB clocks */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB , ENABLE); /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); /* Configure PA.13 (JTMS/SWDIO), PA.14 (JTCK/SWCLK) and PA.15 (JTDI) as output push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure PB.03 (JTDO) and PB.04 (JTRST) as output push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4; GPIO_Init(GPIOB, &GPIO_InitStructure); while (1) { /* Toggle JTMS/SWDAT pin */ GPIO_WriteBit(GPIOA, GPIO_Pin_13, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_13))); /* Insert delay */ Delay(0x5FFFF); /* Toggle JTCK/SWCLK pin */ GPIO_WriteBit(GPIOA, GPIO_Pin_14, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_14))); /* Insert delay */ Delay(0x5FFFF); /* Toggle JTDI pin */ GPIO_WriteBit(GPIOA, GPIO_Pin_15, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_15))); /* Insert delay */ Delay(0x5FFFF); /* Toggle JTDO pin */ GPIO_WriteBit(GPIOB, GPIO_Pin_3, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_3))); /* Insert delay */ Delay(0x5FFFF); /* Toggle JTRST pin */ GPIO_WriteBit(GPIOB, GPIO_Pin_4, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_4))); /* Insert delay */ Delay(0x5FFFF); } } else { /* Turn on LED2 */ STM_EVAL_LEDOn(LED2); while (1) { } } }
int main(void) { ///////// Initial Portion ///////////////////////// init_USART1(460800); // initialize USART1 @ 9600 baud SystemCoreClockUpdate(); /* Get Core Clock Frequency */ if (SysTick_Config(SystemCoreClock / 1000000)) { /* SysTick 1 micro sec interrupts */ while (1); /* Capture error */ } USART_puts(USART1, "START !"); // just send a message to indicate that it works USART_puts(USART1, " \r \n"); // new line //Init GPIO for Leds on board and button input init_GPIO(); //Init SPI1 mySPI_Init(); //Delay for all periferals to be ready Delay(1000000); //Delay 1s for cap to be charged // mySPI_SendByte(0x11); //SDATAC //mySPI_Send3Byte(0x20,0x00,0x00); //Issue Reset Pulse for ADS1299 GPIO_ResetBits(GPIOD, GPIO_Pin_2); Delay(5); //Delay couples of clock cycles for ADS to read the signal GPIO_SetBits(GPIOD, GPIO_Pin_2); // Complete reset Pulse Delay(18); //Delay at least 18 clock cycles //Send stop command for ADS1299 /*Put CS line down send out command (stop command) SDATAC = 0x11, delay 1 micro seccond; put CS line up again*/ mySPI_SendByte(0x11); //SDATAC Delay(10000); //¾WREG CONFIG3 E0h // mySPI_SendData(0x43); //Configure register mySPI_Send3Byte(0x43,0x00,0xE1); //config3 ENABLE internal reference mySPI_Send3Byte(0x41,0x00,0xD6); // Config1 noi daisy chain; output data rate 250sps(F/4096) mySPI_Send3Byte(0x42,0x00,0xC0); //Config 2: test source externa, keep all as default //Write to 8 channel open the shorted mySPI_Send3Byte(0x45,0x00,0x00); //collecting data for channel 1-4 mySPI_Send3Byte(0x46,0x00,0x00); mySPI_Send3Byte(0x47,0x00,0x00); mySPI_Send3Byte(0x48,0x00,0x00); mySPI_Send3Byte(0x20,0x00,0x00); switch (getIDval & 0x1F ) { //least significant bits reports channels case 0x10: //16 gMaxChan = 4; //ads1294 break; case 0x11: //17 gMaxChan = 6; //ads1296 break; case 0x12: //18 gMaxChan = 8; //ads1298 break; case 0x1E: //30 gMaxChan = 8; //ads1299 USART_puts(USART1, "ADS1299 Hooray!"); break; default: gMaxChan = 0; } readRegister(18,0); // Read all register from address 0 //Start conversation. Set start pin to 1 GPIO_SetBits(GPIOD, GPIO_Pin_0); // Asking for data to send continueously mySPI_SendByte(0x10); //SDATAC begin to read data /////////////////- Loop - //////////////////////////////////// while (1){ uint8_t i =0; // You can do whatever you want in here /* USART_puts(USART1, "Init 2 complete! Hello World! \r \n"); // just send a message to indicate that it works //GPIO_ToggleBits(GPIOD, GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13| GPIO_Pin_12 ); GPIO_ToggleBits(GPIOD, GPIO_Pin_12 ); //Test Leds on board Delay(200); GPIO_ToggleBits(GPIOD, GPIO_Pin_13 ); //Test Leds on board Delay(200); GPIO_ToggleBits(GPIOD, GPIO_Pin_14 ); //Test Leds on board Delay(1000); */ // GPIO_ToggleBits(GPIOD, GPIO_Pin_12 ); //Test Leds on board if(!(GPIO_ReadInputData(GPIOD) & GPIO_Pin_1)){ //Read state of D1 (DRDY signal). Start new process if it is 0 for( i=0; i<9; i++){ char strADS[50]; getdata = mySPI_GetData(0x00); // regAddress = (0x20 | i); // getDataSPI = mySPI_Send3Byte((0x20 | i),0x00,0x00); //Increase to required address from the base address; if( i==2){ //Read 1 register at a time if (getdata > 0x007FFFFF) //Convert minus data { getdata = 0xFFFFFF - getdata; getdata = getdata/19373; //snprintf(strADS, 50, "Channel %d Val: %X \r \n", i, getdata); //convert int to string snprintf(strADS, 50, "E0,%d\n",getdata); //convert int to string USART_puts(USART1, strADS); //pirnt the address in string format } else{ getdata = getdata/19373; //snprintf(strADS, 50, "Channel %d Val: %X \r \n", i, getdata); //convert int to string snprintf(strADS, 50, "E0,%d\n",getdata); //convert int to string USART_puts(USART1, strADS); //pirnt the address in string format } } } //Delay(50000); } //if }// while (1) ////////////////////////////////////////////////////////// } //main