Beispiel #1
0
//*****************************************************************************
//
//! Loads the motor drive parameter block from flash.
//!
//! This function is called by the serial user interface when the load
//! parameter block function is called. If the motor drive is running, the
//! parameter block is not loaded. If the motor drive is not running and a
//! valid parameter block exists in flash, the contents of the parameter
//! block are loaded from flash.
//!
//! \return None.
//
//*****************************************************************************
void
UIParamLoad(void)
{
    unsigned char *pucBuffer;
    unsigned long ulIdx;

    //
    // Get the motion status so we know what the motor is doing.
    //
    pStepperStatus = StepperGetMotorStatus();

    //
    // Return without doing anything if the motor drive is running.
    //
    if(pStepperStatus->ucMotorStatus != MOTOR_STATUS_STOP)
    {
        return;
    }

    //
    // Get a pointer to the latest parameter block in flash, and return without
    // doing anything if there is not one.
    //
    pucBuffer = FlashPBGet();
    if(!pucBuffer)
    {
        return;
    }

    //
    // Loop through the words of the parameter block to copy its contents from
    // flash to SRAM.
    //
    for(ulIdx = 0; ulIdx < (sizeof(tDriveParameters) / 4); ulIdx++)
    {
        ((unsigned long *)&g_sParameters)[ulIdx] =
            ((unsigned long *)pucBuffer)[ulIdx];
    }

    //
    // Loop through all of the parameters.
    //
    for(ulIdx = 0; ulIdx < g_ulUINumParameters; ulIdx++)
    {
        //
        // If there is an update function for this parameter, then call it now
        // since the parameter value may have changed as a result of the load.
        //
        if(g_sUIParameters[ulIdx].pfnUpdate)
        {
            g_sUIParameters[ulIdx].pfnUpdate();
        }
    }

    //
    // Make sure the correct control mode is set last, after all the
    // parameters are loaded and updated.
    //
    UISetControlMode();
}
//*****************************************************************************
//
// This function reads the saved motor controller parameters from flash, if
// available.
//
//*****************************************************************************
void
ParamLoad(void)
{
    unsigned char *pucBuffer;

    //
    // Get a pointer to the latest parameter block in flash.
    //
    pucBuffer = FlashPBGet();

    //
    // See if a parameter block was found in flash.
    //
    if(pucBuffer)
    {
        //
        // A parameter block was found so copy the contents to the current
        // parameter block.
        //
        g_sParameters = *(tParameters *)pucBuffer;
    }
}