/************************************************************ * Utils.h * general module of system utility functions **************************************************************/ #include #include #include #include #include "Common/Utilities/Utils.h" //#include #include "driverlib/hibernate.h" static const float speedCoef = 5.3051647697298445256294587790838f;//(200 micro steping)/2*Pi*Radius - 200 micro steping //***************************************************************************** bool DanserCheckPosition(uint16_t position , Danser_t danser, bool test) { if (test == false) return true; #ifdef DEBUG_DANCER ProfileType_t profileType = GetCurrentProfileType(); if (position < DANSER_POS_MIN) { if(danser == Winder) { if(profileType == Manual) { JigStopAllWithError("Thread torn in winder danser");//for stoping the system operation } else if (profileType == User) { //notify the UI about an error and pause the system SendMessageToHost(ERROR_IN_PROFILE_EXECUTION,"Thread torn in winder danser"); JigPauseAll(); } } else { if(profileType == Manual) { JigStopAllWithError("Thread torn in pooler danser");//for stoping the system operation } else if (profileType == User) { //notify the UI about an error and pause the system SendMessageToHost(ERROR_IN_PROFILE_EXECUTION,"Thread torn in pooler danser"); JigPauseAll(); } } return false; } if (position > DANSER_POS_MAX) { if(danser == Pooler) { if(profileType == Manual) { JigStopAllWithError("Thread stocked in pooler danser"); } else if (profileType == User) { SendMessageToHost(ERROR_IN_PROFILE_EXECUTION,"Thread stuck in pooler danser"); JigPauseAll(); } } else { if(profileType == Manual) { JigStopAllWithError("Thread stocked in winder danser"); } else if (profileType ==User) { SendMessageToHost(ERROR_IN_PROFILE_EXECUTION,"Thread stuck in winder danser"); JigPauseAll(); } } return false; } #endif return true; } //***************************************************************************** //convert thread speed recieved in milimeters per second into motor steps of pps //***************************************************************************** uint16_t ConvertSpeed2Pps(uint16_t milimeterPerSecond) { float res = speedCoef*(float)milimeterPerSecond; return (uint16_t)res; } //***************************************************************************** uint16_t ConvertPpsToSpeed(uint16_t Pps) { float res = (float)Pps/speedCoef; return (uint16_t)res; } //***************************************************************************** // // Init WD timer // //***************************************************************************** void InitWatchdog(uint32_t clock) { // // Enable the watchdog interrupt. // ROM_IntEnable(INT_WATCHDOG); // // Set the period of the watchdog timer. // ROM_WatchdogReloadSet(WATCHDOG0_BASE, clock); // // Enable reset generation from the watchdog timer. // ROM_WatchdogResetEnable(WATCHDOG0_BASE); // // Enable the watchdog timer. // ROM_WatchdogEnable(WATCHDOG0_BASE); } void utilsInit(uint32_t ui32SysClock) { // Configure Hibernate module clock. // HibernateEnableExpClk(ui32SysClock); // Enable RTC mode. // HibernateRTCEnable(); // // Configure the hibernate module counter to 24-hour calendar mode. // // HibernateCounterMode(HIBERNATE_COUNTER_24HR); // Configure the hibernate module counter to RTC counter mode. HibernateCounterMode(HIBERNATE_COUNTER_RTC); } uint32_t UsersysTickGet (void) { uint32_t tick = 0; // tick = SysTickValueGet(); tick = HibernateRTCSSGet()*10000/0x8000; return tick; } //***************************************************************************** // // The interrupt handler for the watchdog. This feeds the dog (so that the // processor does not get reset) and winks the LED connected to GPIO B3. // //***************************************************************************** void WatchdogIntHandler(void) { // // Clear the watchdog interrupt. // ROM_WatchdogIntClear(WATCHDOG0_BASE); } bool sendDataToHost = false; void UtilsSetCommunicationOk(void) { sendDataToHost = true; }