/** ****************************************************************************** * @file : debug.c * @brief : debug functions program body ****************************************************************************** */ #include "debug.h" #include "globaldef.h" #include "functions.h" #include "string.h" #include "modbusRTU.h" #include "stm32f0xx_hal.h" #define ADCrefAddr 0x1FFFF7BA int sprintftime = 0; int putstrtime = 0; const unsigned char buf1[16]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff,0x00}; char str1[256]; int LineCount=0; int Uart1baudval=0; int Uart2baudval=0; __asm int add1(int a,int b) { add r0,r1,r0 BLX lr } void clearscreen() { PutStr("\33[2J\33[0;0H",10); return; } void Locate(int y,int x) { char str[16]; int len; len=sprintf(str," \33[%d;%dH",y,x); PutStr(str,len); return; } int FormatHex(char * buf1, unsigned char * data, int n) { int len1=0; for (int i=0;iBRR; // len1+=sprintf(str1+len1,"PCL1 %d, BRR %d Baud %d \r\n",HAL_RCC_GetPCLK1Freq(),USART1->BRR,Uart1baudval); // int periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART1_CLKSOURCE); // len1+=sprintf(str1+len1,"periphclk %d \r\n",periphclk); LL_RCC_ClocksTypeDef RCC_Clocks; LL_RCC_GetSystemClocksFreq(&RCC_Clocks); int pllsource = LL_RCC_PLL_GetMainSource(); len1+=sprintf(str1+len1,"MainSource %x %d \r\n",pllsource,pllsource); int sysclk = RCC_Clocks.SYSCLK_Frequency; len1+=sprintf(str1+len1,"sysclk %d \r\n",sysclk); PutStr(str1,len1); // InitTimer(0,0); // InitTimer(1,1); // InitTimer(2,2); // InitTimer(3,3); // RunTimer(0,1000); // StartTimer(2,1000); Locate(13,1);LineCount=3; return 0; } int ShowRunningInfo() { int Clk1=SysTick->VAL; if (Uart1BaudFirstGot) { Uart1baudval = HAL_RCC_GetPCLK1Freq() / USART1->BRR; Uart1BaudFirstGot=0; } int Reload=SysTick->LOAD; int Clk2=SysTick->VAL; //int us2=GetuS(); int haltick=HAL_GetTick(); int len1=0; uint32_t theUs = GetuS(); int nRunCount2=KMem.nRunCount; if (!Uart1Stat.QTx.bEmpty) return 0; if ( (nRunCount2 & 0xff) == 0x03) { Locate(13,1);LineCount=3; } else if ((nRunCount2 & 0xff) == 0x0f) { int timeus1; int timeus2; len1=sprintf((char *)str1," N %8d Tk %8d %9u CFG %02X R %d M %d S %d %4d IN %04X OUT %04X \r\n", KMem.nRunCount, haltick, theUs, KMem.EffJumperSW, bKBusRepeater, bKBusMaster, bKBusSlave, Clk2, KMem.WX[0],KMem.WY[0]); //len1=sprintf((char *)str1,"U%02X%02XA",x2,x2); // Locate(10,1); timeus1=GetuS(); PutStr(str1,len1); timeus2=GetuS(); sprintftime = timeus1 - theUs; putstrtime = timeus2 - timeus1; // if (IsTimerOn(0)) {RunTimer(1,1000);StopTimer(3);} // if (IsTimerOn(1)) {RunTimer(2,100);StopTimer(0);} // if (IsTimerOn(2)) {RunTimer(3,10);StopTimer(1);} // if (IsTimerOn(3)) {RunTimer(0,10000);StopTimer(2);} } if ((nRunCount2 & 0xff) == 0x2f && 0) { } if ((nRunCount2 & 0xff) == 0x0af) { } return 0; } int ADCProcess() { // ADC channels // 0 -- 24V --> 0 // 1 -- 5V --> 2 // 2 -- // 3 -- // 4 -- // 5 -- // 6 -- // 7 -- // 8 -- // --> 5 // 16 -- Temp --> 6 // 17 -- Vref --> 7 uint16_t ADC_ConvertedValue=0; static int CurChannel=LL_ADC_CHANNEL_0; //static int waitcount = 0; if (!LL_ADC_REG_IsConversionOngoing(ADC1)) { //waitcount++; //if (waitcount<2) return 0; //waitcount=0; ADC_ConvertedValue = LL_ADC_REG_ReadConversionData12(ADC1); // ADC_RegularChannelConfig(LL_ADC_CHANNEL_17,); int channels = CurChannel ;//LL_ADC_REG_GetSequencerChannels(ADC1); int nextchannel = LL_ADC_CHANNEL_0; if ((channels & LL_ADC_CHANNEL_0) == LL_ADC_CHANNEL_0) { KMem.ADCValues[0] = ADC_ConvertedValue; nextchannel = LL_ADC_CHANNEL_8; if (KMem.ADCValues[0] < 2200) { PowerDownEvent=1; }else { PowerDownEvent=0; } }else if ((channels & LL_ADC_CHANNEL_8) == LL_ADC_CHANNEL_8) { KMem.ADCValues[2] = ADC_ConvertedValue; nextchannel = LL_ADC_CHANNEL_TEMPSENSOR; }else if ((channels & LL_ADC_CHANNEL_16) == LL_ADC_CHANNEL_16) { KMem.ADCValues[6] = ADC_ConvertedValue; nextchannel = LL_ADC_CHANNEL_VREFINT; }else if ((channels & LL_ADC_CHANNEL_17) == LL_ADC_CHANNEL_17) { KMem.ADCValues[7] = ADC_ConvertedValue; KMem.ADCValues[5] = *((unsigned short *)ADCrefAddr); nextchannel = LL_ADC_CHANNEL_0; }else { //ADCValues[0] = ADC_ConvertedValue; } //nextchannel = LL_ADC_CHANNEL_VREFINT; LL_ADC_REG_SetSequencerChannels(ADC1,nextchannel); LL_ADC_REG_StartConversion(ADC1); CurChannel = nextchannel; } return 0; } int PowerDownProcess(void ) { AddEventLog(KMem.CurTimeSec,EventTypePowerDown,1,12345); SaveRunStat(&KMRunStat); KMem.PwrFailCount++; KMem.LastPwrFailTime = KMem.CurTimeSec; return 0; } int PowerRecoverProcess(void) { KMem.PwrFailCount++; return 0; }