Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

embedded C code ( load management function)

Status
Not open for further replies.

hidouri

Newbie level 3
Joined
Mar 9, 2008
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,295
hy all

a part of a function (optimize) that manages electrical load shedding according to the state of a source is wroten as following.

even if there is comment , i can't understand the many lines of the code and what is desired to obtain as result.

need help please.



Code:
#define OPTIMIZE_C

/*****************************************************************************
 * Header Files included                                                     *
 *****************************************************************************/
#include "standard.h"
#include "kcg_types.h"
#include "optimize.h"

/* NO IMA OBJECTS FOR SABER SIMULATION */
/*
#include "COD_A653_API_COMMON.h"
#include "conf_processes_const.h"
*/

/*****************************************************************************
 *  Module Name : Optimize                                                   *
 *                                                                           *
 *  Function    : This function finds the best combination of load groups to *
 *                be shed / reconnected in order to have a power source used *
 *                at a nominal capacity, without being overloaded or under   *
 *                capacity.                                                  *
 *                                                                           *
 *  Written by  : R. MAZO                                 Date : 15-03-2010  *
 *                                                                           *
 *  Programming Language : C.                                                *
 *                                                                           *
 *  Nature      : Function.                                                  *
 *                                                                           *
 *  Called module : Opt_Shed                                                 *
 *                  Opt_Reconnect                                            *
 *                  START                                                    *
 *                                                                           *
 *                                        *
 *****************************************************************************
 * MODIFICATION LOG :                                                        *
 *****************************************************************************
 * PR Ref.  :                                                                *
 * Comments :                                                                *
 *                                                                           *
 *****************************************************************************


 *****************************************************************************
 * INPUT/OUTPUT VARIABLES :                                                  *
 *****************************************************************************
 * Variable Name :                                              I/O type :   *
 *                                                                           *
 *    TabConfRes                                                PARAM IN     *
 *    TabDeltaI                                                 PARAM IN     *
 *    TabPhase                                                  PARAM IN     *
 *    TabTopDel                                                 PARAM IN     *
 *    TabTopLest                                                PARAM IN     *
 *    TabCdDel                                                  PARAM IN     *
 *    TabCdLest                                                 PARAM IN     *
 *    TabBarreCh                                                PARAM IN     *
 *    TabCrntCh                                                 PARAM IN     *
 *    TabCrntNo                                                 PARAM IN     *
 *    TabPriCh                                                  PARAM IN     *
 *    TabSPriCh                                                 PARAM IN     *
 *    TabRtrCde                                                 PARAM IN     *
 *    TabChInsuf                                                PARAM OUT    *
 *    TabCde                                                    PARAM OUT    *
 *    OptimizeTimeOut                                              OUT       *
 *                                                                           *
 *****************************************************************************

 *****************************************************************************
 * GLOBAL CONSTANTS :                                                        *
 *****************************************************************************
 * Constant Name :                                                           *
 *                                                                           *
 *    OPTIMIZE_PROCESS_NAME                                                  *
 *    NO_ERROR                                                               *
 *    FALSE                                                                  *
 *    TRUE                                                                   *
 *    GGPCU_MAX                                                              *
 *    MAX_OVL_CHANNELS                                                        *
 *    PHA                                                                    *
 *    PHB                                                                    *
 *    PHC                                                                    *
 *                                                                           *
 *****************************************************************************

 *****************************************************************************
 * FUNCTIONAL DESCRIPTION :                                                  *
 *****************************************************************************/
/*!                                                                          */
/*!                                                                          */
/*! - Start the OPTIMIZE aperiodic process used to set Optimize Time Out     */
/*!   flag after 2ms.                                                        */
/*!                                                                          */
/*!  - Initialization of output commands to their previous state             */
/*!     - Relevant "status_order" of the load (of TabCde) equal to           */
/*!       the "status_order" computed on the previous cycle (of TabRtrCde).  */
/*!                                                                          */
/*!  - For each Power Source (1...7)                                         */
/*!    .........                                                             */
/*!                                                                          */
/*****************************************************************************/

void OPTIMIZE(
             /* Comments : Pointer to an array indicating the network                 */
             /*            configuration, for each busbar (1..12)                     */
             /* Unit     : T_12Source                                                 */
             /* Range    : N/A                                                        */
             const T_12Source* TabConfRes,

             /* Comments : Pointer to an array indicating, for each Power Source,     */
             /*            (1..7) the amount of current to shed or reconnect          */
             /*            (3phase).                                                  */
             /* Unit     : T_7Crnt                                                    */
             /* Range    : N/A                                                        */
             const T_7Crnt* TabDeltaI,

             /* Comments : Pointer to an array indicating, for each Power Source,     */
             /*            the phase to be treated.                                   */
             /* Unit     : T_7Phase                                                   */
             /* Range    : N/A                                                        */
             const T_7Phase* TabPhase,

             /* Comments : Pointer to a table indicating, for each Power Source,      */
             /*            (1..7) if it is selected for shedding.                     */
             /* Unit     : T_7Bool                                                    */
             /* Range    : N/A                                                        */
             const T_7Bool* TabTopDel,

             /* Comments : Pointer to an array indicating, for each Power Source,     */
             /*            (1..7) if it is selected for reconnection.                 */
             /* Unit     : T_7Bool                                                    */
             /* Range    : N/A                                                        */
             const T_7Bool* TabTopLest,

             /* Comments : Pointer to an array indicating, for each load              */
             /*            (1..80), if it is selected for shedding.                   */
             /* Unit     : T_80Bool                                                   */
             /* Range    : N/A                                                        */
             const T_80Bool* TabCdDel,

             /* Comments : Pointer to an array indicating, for each load              */
             /*            (1..80), if it is selected for reconnection.               */
             /* Unit     : T_80Bool                                                   */
             /* Range    : N/A                                                        */
             const T_80Bool* TabCdLest,

             /* Comments : Pointer to an array indicating, for each load              */
             /*            (1..80), the busbar (1...12) which supplies the load.      */
             /* Unit     : T_80Barre                                                  */
             /* Range    : N/A                                                        */
             const T_80Barre* TabBarreCh,

             /* Comments : Pointer to an array indicating, for each load              */
             /*            (1..80), its current consumption (3 phases).               */
             /* Unit     : T_80Crnt                                                   */
             /* Range    : N/A                                                        */
             const T_80Crnt* TabCrntCh,

             /* Comments : Pointer to an array indicating, for each load (1..80),     */
             /*            its current consumption before shedding                    */
             /* Unit     : T_80Crnt                                                   */
             /* Range    : N/A                                                        */
             const T_80Crnt* TabPreDelCrt,

             /* Comments : Pointer to an array indicating, for each load              */
             /*            (1..80), its priority (1..3) .                             */
             /* Unit     : T_80Int                                                    */
             /* Range    : N/A                                                        */
             const T_80Int* TabPriCh,

             /* Comments : Pointer to an array indicating, for each load              */
             /*            1..80) its sub priority (1..3).                            */
             /* Unit     : T_80Int                                                    */
             /* Range    : N/A                                                        */
             const T_80Int* TabSPriCh,

             /* Comments : Pointer to an array indicating, for each load              */
             /*            (1..80), its "status_order" computed on the                */
             /*            previous cycle.                                            */
             /* Unit     : T_80Bool                                                   */
             /* Range    : N/A                                                        */
             const T_80Bool* TabRtrCde,

             /* Comments : Pointer to an array indicating, for each Power Source      */
             /*            (1..7), a status to indicate if there is no                */
             /*            enough sheddable loads.                                    */
             /* Unit     : T_7Bool                                                    */
             /* Range    : N/A                                                        */
             T_7Bool* TabChInsuf,

             /* Comments : Pointer to an array indicating, for each load              */
             /*            (1..80), the new "status_order" (On, Off)                  */
             /*            computed by this function.                                 */
             /* Unit     : T_80Bool                                                   */
             /* Range    : N/A                                                        */
             T_80Bool* TabCde)
{
/*****************************************************************************
 * LOCAL DATA :                                                              *
 *****************************************************************************/

/* Comments : Pointer to the shedding status of the current Power Source     */
	const kcg_bool* TopDel_Ptr;

/* Comments : Pointer to the reconnection status of the current Power Source */
    const kcg_bool* TopLest_Ptr;

/* Comments : Pointer to the amount of power to shed/reconnect for the       */
/*            current Power Source                                           */
    const T_Crnt*    DeltaI_Ptr;

/* Comments : Pointer to the phase to be treated for the current Power Source*/
    const T_Phase*   Phase_Ptr;

/* Comments : Nb of overloaded channels treated, max 2 per execution cycle   */
    kcg_int		NbOvlChannels;

/* Comments : Index of the loop that indicates the Power Source to treat     */
    kcg_int		i;

	/* NO IMA Return Code FOR SABER SIMULATION */
	/*
	 RETURN_CODE_TYPE rc;
	*/

    /*****************************************************************************/


    /****************************************************************************/
    /* Reset the flag indicating that the 2ms maximum optimize computation time */
    /* is elapsed. This flag is the main the stop condition in Opt_AlgoBB       */
    /****************************************************************************/
    /* NO OPTIMIZE TIMEOUT FOR SABER SIMULATION */
    /* OptimizeTimeOut = FALSE; */


    /************************************************************************/
    /* Start the process which sets to TRUE the OptimizeTimeOut flag after  */
    /* 2ms, stopping the whole process if optimization is not yet ended     */
    /************************************************************************/
    /* NO A653 CALLS FOR SABER SIMULATION */
    /* START(Process_Data[ELMF_OPTIMIZE_PROCESS].Process_Id,&rc); */
    
    /*****************************************************************/
    /* If the process that counts the 2ms could not be started, set  */
    /* Optimize Time Out flag to TRUE as there is no way to ensure   */
    /* that optimize will end; so the optimization is not executed   */
    /*****************************************************************/
    /* NO OPTIMIZE TIMEOUT FOR SABER SIMULATION */
    /*if (rc != NO_ERROR)
    {
        OptimizeTimeOut = TRUE;
    }*/


    NbOvlChannels = 0;
    TopDel_Ptr  = (kcg_bool*)	TabTopDel;
    TopLest_Ptr = (kcg_bool*)	TabTopLest;
    Phase_Ptr   = (T_Phase*)	TabPhase;
    DeltaI_Ptr  = (T_Crnt*)		TabDeltaI;

    /***************************************************************/
    /* Initialization of output commands to their previous state   */
    /* In case of failure of optimize computation, the function    */
    /* shall return the previous command as new output command (if */
    /* no new outputs commands are available).                     */
    /***************************************************************/
    /*****************************************************************/
    /* Relevant "status_order" of the load (of TabCde) equal to the  */
    /* "status_order" computed on the previous cycle (of TabRtrCde). */
    /*****************************************************************/

	/* So, copy orders from previous cycle to new orders */
    for (i = 0; i < SHED_LOAD_MAX;i ++)
	{
		/* The fact that T_80Bool is itself a pointer (array) implies */
		/* that concerned elements are kcg_bool**                    */
		(*TabCde)[i] = (*TabRtrCde)[i];
	}
    

    /*********************************************/
    /* For each Power Source (1..7), check       */
    /* if there is an overload or under capacity */
    /*********************************************/
    for (i=0; i<PWR_SRC_MAX; i++)
    {
        /************************************************/
        /* If the Power Source is in overload and not   */
    	/* in under-capacity and the max number of      */
    	/* shedding computations in one execution cycle */
    	/* is not exceeded                              */
        /************************************************/
        if ((*(TopDel_Ptr+i) == TRUE) &&
            (*(TopLest_Ptr+i) == FALSE) &&
            (NbOvlChannels < MAX_OVL_CHANNELS))
        {
            /*******************************************************/
            /* Determine the phase to be treated (most loaded) and */
        	/* call the appropriate function on that phase         */
            /*******************************************************/
            switch (*(Phase_Ptr+i))
            {
                case PHA : /* Phase A */
                    Opt_Shed (TabConfRes,
                              i,                   /* Power Source index */
                              (DeltaI_Ptr+i)->PhA, /* Amount of current to shed */
                              PHA,                 /* Phase to be treated   */
                              TabCdDel,
                              TabBarreCh,
                              TabCrntCh,
                              TabPriCh,
                              TabSPriCh,
                              TabChInsuf,
                              TabCde);
                    break;

                case PHB : /* Phase B */
                    Opt_Shed (TabConfRes,
                              i,                   /* Power Source index */
                              (DeltaI_Ptr+i)->PhB, /* Amount of current to shed */
                              PHB,                 /* Phase to be treated   */
                              TabCdDel,
                              TabBarreCh,
                              TabCrntCh,
                              TabPriCh,
                              TabSPriCh,
                              TabChInsuf,
                              TabCde);
                    break;

                case PHC : /* Phase C */
                    Opt_Shed (TabConfRes,
                              i,                   /* Power Source index */
                              (DeltaI_Ptr+i)->PhC, /* Amount of current to shed */
                              PHC,                 /* Phase to be treated   */
                              TabCdDel,
                              TabBarreCh,
                              TabCrntCh,
                              TabPriCh,
                              TabSPriCh,
                              TabChInsuf,
                              TabCde);
                    break;

                default :
                    /**********************************************/
                    /* This should never occur. No shedding is    */
                	/* performed if the Phase is out of range     */
                    /**********************************************/
                    break;
            }
            /* One overloaded channel has been treated, indicate it */
            NbOvlChannels++;
        }
        /*******************************************************/
        /* Else, If the Power Source is not in overload and    */
        /* is in under-capacity                                */
        /*******************************************************/
        else if ((*(TopDel_Ptr+i) == FALSE) &&
                (*(TopLest_Ptr+i) == TRUE))
        {
           	/*******************************************************/
           	/* Determine the phase to be treated (most loaded) and */
           	/* call the appropriate function on that phase         */
           	/*******************************************************/
            switch (*(Phase_Ptr+i))
            {
				case PHA : /* Phase A */
					Opt_Reconnect(TabConfRes,
						 	      i,                   /* Power Source index */
                                  (DeltaI_Ptr+i)->PhA, /* Amount of current to reconnect */
                                  PHA,                 /* Phase to be treated   */
                                  TabCdLest,
                                  TabBarreCh,
                                  TabPreDelCrt,
                                  TabPriCh,
                                  TabSPriCh,
                                  TabCde);
					break;

				case PHB : /* Phase B */
					Opt_Reconnect(TabConfRes,
                                  i,                   /* Power Source index */
                                  (DeltaI_Ptr+i)->PhB, /* Amount of current to reconnect */
                                  PHB,                 /* Phase to be treated   */
                                  TabCdLest,
                                  TabBarreCh,
                                  TabPreDelCrt,
                                  TabPriCh,
                                  TabSPriCh,
                                  TabCde);
                    break;

                case PHC : /* Phase C */
                	Opt_Reconnect(TabConfRes,
                                  i,                   /* Power Source index */
                                  (DeltaI_Ptr+i)->PhC, /* Amount of current to reconnect */
                                  PHC,                 /* Phase to be treated   */
                                  TabCdLest,
                                  TabBarreCh,
                                  TabPreDelCrt,
                                  TabPriCh,
                                  TabSPriCh,
                                  TabCde);
                    break;

                default :
                    /**********************************************/
                    /* This should never occur. No reconnection   */
                    /* is performed if the Phase is out of range  */
                    /**********************************************/
                	break;
            }
        }
    }
}
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top