/** ****************************************************************************** * File Name : console.c * Description : This file provides code for the configuration * of debug console. ****************************************************************************** * @attention * *

© Copyright (c) 2019 STMicroelectronics. * All rights reserved.

* * This software component is licensed by ST under Ultimate Liberty license * SLA0044, the "License"; You may not use this file except in compliance with * the License. You may obtain a copy of the License at: * www.st.com/SLA0044 * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #ifdef CONSOLE_DEBUG #include "screen.h" #endif #include "includes.h" #include "console.h" #include "delay.h" #include "app_ver.h" #include "usart.h" #include "asutil.h" #include "brtc.h" #include "adc.h" #include "temp.h" #include "vi.h" #include "display_status.h" #include "dflash_sf1.h" #include "dflash_sbs.h" #include "dflash_chg_ctrl.h" #include "dflash_cal.h" #include "can_inv_data_process.h" #include "log.h" #include "ff.h" #include "brtc.h" #include "pl455_comm.h" #include "can_comm.h" #include "rs485_comm.h" #include "device_param.h" #include "modbus.h" #include "ff_shell.h" #include "io.h" #include "calc_soc.h" #include "task_manager.h" #include "can.h" #include "relay.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ s8 screenmode; u8 position; u32 BakOSCtxSwCtr; /* Counter of number of context switches */ u32 BakLocalTime; /* this variable is used to create a time reference incremented by 10ms */ u8 console_text[128]; u8 display_text[81]; /* Private prototype functions -----------------------------------------------*/ void DebugConsole(void); void Console(u8 *one); void Prompt(void); s8 Process_Data(u8 *text, u16 size); s8 Process_DataSet(u8 *text, u16 size); s8 Process_CurrentDataSet(u8 *text, u16 size); s8 Process_DataDiagnostic(u8 *text, u16 size); s8 Process_DataNetSet(u8 *text, u16 size); s8 Process_OSStatus(u8 *text, u16 size); s8 Process_Inventory_Data(u8 *text, u16 size); s8 Process_DataChgCtrlCfgSet(u8 *text, u16 size); extern void ff_process(void); void Console_Initial(void) { position = 0; screenmode = OP_MODE; } void AppTaskDebug(void) { Init_RTC(); Load_Param(); Console_Initial(); SOC_Init(); while (DEF_TRUE) { #ifdef CONSOLE_DEBUG DebugConsole(); #endif ProcessSOC(); if (device_status.battery_status.bit.INIT == true) { LoggingProcess(); SaveStoreSOC(); CheckTimeOutFatfsSem(); } /* Reload IWDG counter */ IWDG_ReloadCounter(); delay_os_ms(1); } } #ifdef CONSOLE_DEBUG u16 debug_recv_data(u8 *data) { u16 len = 0; if (UART1_GetChar(data) == SUCCESS) len = 1; return len; } void DebugConsole(void) { u8 one[20]; u16 i, len; len = debug_recv_data(one); for (i = 0; i < len; i++) Console(&one[i]); DisplayScreen(false); } void Console(u8 *one) { u8 i, ok; ok = 0; switch (one[0]) { case 0x0d: /* ENTER (CR) value */ if (position == 0) { ViewScreen(); Prompt(); /* Print prompt */ position = 0; for (i = 0; i < 80; i++) console_text[i] = 0x00; break; } switch (screenmode) { case OP_MODE: /* operating state */ ok = Process_Data(console_text, position); if (!ok) {UserMessage(" [Invalid Command]");} break; case SET_MODE: /* setting state */ ok = Process_DataSet(console_text, position); if (!ok) {UserMessage(" [Invalid Command]");} break; case OS_STATUS_MODE: /* OS Status */ ok = Process_OSStatus(console_text, position); if (!ok) {UserMessage(" [Invalid Command]");} break; case DIAG_MODE: /* diagnostic */ ok = Process_DataDiagnostic(console_text, position); if (!ok) {UserMessage(" [Invalid Command]");} break; case INVENTORY_MODE: ok = Process_Inventory_Data(console_text, position); if (!ok) {UserMessage(" [Invalid Command]");} break; case SF1_MODE: ok = Process_DataSF1Set(console_text, position); if (!ok) {UserMessage(" [Invalid Command]");} break; case CHG_CTRL_CFG_MODE: ok = Process_DataChgCtrlCfgSet(console_text, position); if (!ok) {UserMessage(" [Invalid Command]");} break; case SBS_MODE: ok = Process_DataSBSSet(console_text, position); if (!ok) {UserMessage(" [Invalid Command]");} break; case CAL_MODE: ok = Process_DataCalSet(console_text, position); if (!ok) {UserMessage(" [Invalid Command]");} break; case CC_MODE: ok = Process_DataCcModeSet(console_text, position); if (!ok) {UserMessage(" [Invalid Command]");} break; default: screenmode = OP_MODE; break; } Prompt(); position = 0; for (i = 0; i < 80; i++) console_text[i] = 0x00; break; case 0x08: /* BACKSPACE (BS) value */ case 0x7F: /* BACKSPACE (BS) value */ if (position > 0) { printf("%c %c", 0x08, 0x08); position--; } break; case 0x0A: /* enter */ break; default : if (one[0] >= 0x20) { printf("%c", one[0]); if (position < 80) { console_text[position++] = one[0]; console_text[position] = 0x00; } else { position = 0; Prompt(); for (i = 0; i < 80; i++) console_text[i] = 0x00; } } break; } } void SYSCLKConfig_STOP(void) { RCC_HSEConfig(RCC_HSE_ON); /* Enable HSE */ if(RCC_WaitForHSEStartUp() == SUCCESS) { /* Wait till HSE is ready */ RCC_PLLCmd(ENABLE); /* Enable PLL */ /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { } /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) { } } } void ChangeToStopMode(void) { /* Request to enter STOP mode with regulator in low power mode*/ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ SYSCLKConfig_STOP(); printf("\n<>\n"); } /* Command processing in OPERATING STATE */ s8 Process_Data(u8 *text, u16 size) /* console_text[0]=0x00, size =0 (default) */ { int ret; if(size > 1) { if (text[1] != ' ') return(0); /* Invalid command if space is in first position */ } text[size] = 0x00; ret = 1; switch (text[0]) { case 's': screenmode = SET_MODE; ViewScreen(); break; case 'd': screenmode = DIAG_MODE; ViewScreen(); break; default: ret = 0; break; } return(ret); } /* Command processing in SETTING STATE */ s8 Process_DataSet(u8 *text, u16 size) { u16 ret, i; /* Invalid command if space is in first position */ if (size > 1) if (text[1] != ' ') return(0); text[size] = 0x00; ret = 1; switch (text[0]) { case 'o': /* Switch to operating mode */ screenmode = OP_MODE; ViewScreen(); break; case 'd': /* Switch to diagnostic mode */ screenmode = DIAG_MODE; ViewScreen(); break; case 'z': screenmode = OS_STATUS_MODE; ViewScreen(); break; case '1': screenmode = SF1_MODE; ViewScreen(); break; case '2': screenmode = CHG_CTRL_CFG_MODE; ViewScreen(); break; case '3': screenmode = SBS_MODE; ViewScreen(); break; case '4': screenmode = CAL_MODE; ViewScreen(); break; case 'C': screenmode = CC_MODE; ViewScreen(); break; case 'b': /* Buzzer Update */ Alarm_Buzzer_Update(); break; case '!': /* INIT */ Param_Init(true, false); Save_Param(); break; case 't': /* Date Time Set */ i = Set_Time(&text[2]); if (i == 0) UserMessage("COMMAND COMPLETE"); else if (i == 1) UserMessage("COMMAND FORMAT ERROR"); /* setting format error */ else UserMessage("COMMAND LIMIT ERROR"); /* setting limit error */ break; default : ret = 0; break; } return(ret); } // Command processing in OPERATING STATE s8 Process_OSStatus(u8 *text, u16 size) // console_text[0]=0x00, size =0 (default) { int ret; if (size > 1) if (text[1] != ' ') return(0); /* Invalid command if space is in first position */ text[size] = 0x00; ret = 1; switch (text[0]) { case 'o': screenmode = OP_MODE; ViewScreen(); break; case 's': screenmode = SET_MODE; ViewScreen(); break; case 'd': screenmode = DIAG_MODE; ViewScreen(); break; default: ret = 0; break; } return(ret); } /* Command processing in diagnostic mode */ s8 Process_DataDiagnostic(u8 *text, u16 size) { s8 ret; if (size > 1) { if (text[1] != ' ') { ret = 0; if (memcmp(text, "log start", 9) == 0) { LogEnable(5); ret = 1; } if (memcmp(text, "log stop", 8) == 0) { LogDisable(); ret = 1; } if (memcmp(text, "log print", 9) == 0) { LogPrint("0:/log/cyclelognow"); ret = 1; } if (memcmp(text, "log delete", 10) == 0) { LogDelete(); ret = 1; } return ret; } } text[size] = 0x00; ret = 1; switch (text[0]) { case 'o': /* Switch to operating mode */ screenmode = OP_MODE; ViewScreen(); break; case 's': /* Switch to setting status */ screenmode = SET_MODE; ViewScreen(); break; case 'I': screenmode = INVENTORY_MODE; ViewScreen(); break; case 'G' : /* Memory Dump */ if (size > 2) dump_mem(TextToAddr((u8 *)&text[2])); break; case '0': case '1': // PL455 COMM MONITOR ret = DPl455CommCommand(text[0]); break; case '2': case '3': // CAN COMM MONITOR ret = DCanCommCommand(text[0]); break; case '4': case '5': // RS485 COMM MONITOR ret = DRs485CommCommand(text[0]); break; case 'a': DisplayAdc2DmaBufferValue(0); break; case 'b': DisplayAdc2DmaBufferValue(1); break; case 'c': RCC_AdjustHSICalibrationValue(0x10); break; case 'e': RCC_AdjustHSICalibrationValue(0x18); break; case 'h': RCC_AdjustHSICalibrationValue(0x08); break; case 'k': printf("\r\n ESR = 0x%08X", CAN1->ESR); CAN1->ESR = 0; printf("\r\n ESR = 0x%08X", CAN1->ESR); printf("\r\n"); printf("\r\n"); break; case 'f': ff_process(); break; case 'q': /* Exit Application */ UserMessage("Exit Application ? (Y or N)"); switch (WaitUserCMD((u8 *)"YyNn")) { case 1: case 2: UserMessage("System Reset !!"); Sys_Soft_Reset(); while(1); case 3: case 4: UserMessage("Exit Application Cancel !!"); break; default: UserMessage("Command Timeout !!"); break; } break; default : ret = 0; break; } return(ret); } /* Command processing in Inventor Mode STATE */ s8 Process_Inventory_Data(u8 *text, u16 size) { #ifdef CONSOLE_DEBUG return Process_InvDataSet(text, size); #else return 0; #endif } void Prompt() { u8 ver[4]; switch (screenmode) { case 0 : case 1 : case 2 : case 3 : case 4 : case 5 : case 6 : case 7 : case 8 : case 9 : case 10 : case 11 : case 12 : case 13 : case 14 : case 21 : case 22 : case 23 : case 24 : case 25 : case 26 : case 27 : case 28 : case 29 : case 30 : case 31 : case 32 : case 33 : case 34 : case 40 : case 41 : case 100 : case 101 : GetAppVersion(ver); printf("%1c[%02d;%02dH", 0x1b, 23, 1); printf("%s %d.%d.%d.%d>" , BD_MODEL , ver[0] , ver[1] , ver[2] , ver[3] ); break; case GUI_MODE: break; default : GetAppVersion(ver); printf("%s %d.%d.%d.%d>" , BD_MODEL , ver[0] , ver[1] , ver[2] , ver[3] ); break; } } void DisplayScreen(u8 p) { switch(screenmode) { case OP_MODE: ODisplayAdcStatus(p); ODisplayDevice(p); ODisplayBalancingValue(p); ODisplayDateTime(p); break; case SET_MODE: SDisplayDateTime(p); break; case OS_STATUS_MODE: osDisplayTaskStatus(p); break; case DIAG_MODE: DDisplay_Pl455Comm(p); DDisplay_CanComm(p); DDisplay_Rs485Comm(p); break; case SF1_MODE: SF1Display(p); break; case CHG_CTRL_CFG_MODE: ChgCfgDisplay(p); break; case SBS_MODE: SBSDisplay(p); break; case CAL_MODE: CalDisplay(p); SDisplayCurrentAdcRealValue(p); break; case CC_MODE: SDisplayCurrentStatus(p); break; case INVENTORY_MODE: InvDataDisplay(p); break; } } void ViewScreen() /* Draw background screen according to Screen Mode */ { ClearConsol(); switch (screenmode) { case OP_MODE : /* View Status */ APPVerDisplay(); OmodeScreen(); break; case SET_MODE : /* View Setting Status */ SmodeScreen(); break; case OS_STATUS_MODE: /* View OS Task Status */ OSmodeScreen(); break; case DIAG_MODE: /* View Diagnostic Status */ DmodeScreen(); break; case SF1_MODE: SF1modeScreen(); break; case CHG_CTRL_CFG_MODE: ChgCtrlCfgmodeScreen(); break; case SBS_MODE: SBSmodeScreen(); break; case CAL_MODE: CalmodeScreen(); break; case CC_MODE: CcModeScreen(); break; case INVENTORY_MODE: InvModeScreen(); break; default : printf("UNDEFINE SCREEN MODE"); screenmode = 0; break; } DisplayScreen(true); } #endif // #ifdef CONSOLE_DEBUG