Skip to content

Instantly share code, notes, and snippets.

@stanislaw
Forked from jphickey/sch_custom.c
Created July 31, 2023 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stanislaw/036a4e6321edf1ab3f2bf37a5741bea2 to your computer and use it in GitHub Desktop.
Save stanislaw/036a4e6321edf1ab3f2bf37a5741bea2 to your computer and use it in GitHub Desktop.
Simplified "custom" logic for CFS SCH applcation
/*
** $Id: sch_custom.c 1.3 2015/03/01 14:01:44EST sstrege Exp $
**
** Copyright 2007-2014 United States Government as represented by the
** Administrator of the National Aeronautics and Space Administration.
** All Other Rights Reserved.
**
** This software was created at NASA's Goddard Space Flight Center.
** This software is governed by the NASA Open Source Agreement and may be
** used, distributed and modified only pursuant to the terms of that
** agreement.
**
** Purpose: Scheduler (SCH) application custom component
**
** Author:
**
** Notes:
**
** $Log: sch_custom.c $
** Revision 1.3 2015/03/01 14:01:44EST sstrege
** Added copyright information
** Revision 1.2 2011/06/30 20:39:09EDT aschoeni
** updated OS_SUCCESS to CFE_SUCCESS for custom earlyinit
** Revision 1.1 2011/06/30 15:30:03EDT aschoeni
** Initial revision
** Member added to project c:/MKSDATA/MKS-REPOSITORY/CFS-REPOSITORY/sch/fsw/src/project.pj
*/
/*************************************************************************
**
** Include section
**
**************************************************************************/
#include "cfe.h"
#include "sch_custom.h"
#include "sch_platform_cfg.h"
#include "sch_msgdefs.h"
#include "sch_app.h"
#include "cfe_time_msg.h"
#include "cfe_psp.h"
/*************************************************************************
**
** Macro definitions
**
**************************************************************************/
/*
** Timer Characteristics
*/
#define SCH_TIMER_NAME "SCH_MINOR_TIMER"
/*************************************************************************
** Local function prototypes
**************************************************************************/
/*************************************************************************
**
** Function definitions
**
**************************************************************************/
/*************************************************************************
**
** At some point the CFE_PSP should support customizable timers, which at
** minimum can fall through to the OSAL timers. Until this is implemented
** in CFE_PSP, this redefinition supplies the same functionality to allow
** Scheduler to work out of box.
**
**************************************************************************/
#ifndef CFE_PSP_MAX_TIMERS
int32 CFE_PSP_TimerAdd(uint32 *timer_id, const char *timer_name, uint32 timebase_ref_id, OS_ArgCallback_t callback_ptr, void *callback_arg)
{
int32 Status = CFE_SUCCESS;
Status = OS_TimerAdd(timer_id, timer_name, timebase_ref_id, callback_ptr, NULL);
if(Status == OS_SUCCESS)
{
Status = CFE_SUCCESS;
}
return Status;
}
int32 CFE_PSP_TimerSet(uint32 timer_id, uint32 start_time, uint32 interval_time)
{
return OS_TimerSet(timer_id, start_time, interval_time);
}
#endif
/*******************************************************************
**
** SCH_CustomEarlyInit
**
** NOTE: For complete prolog information, see 'sch_custom.h'
**
** This function MUST update SCH_AppData.ClockAccuracy to the
** resolution of the minor frame timer.
********************************************************************/
int32 SCH_CustomEarlyInit(void)
{
int32 Status = CFE_SUCCESS;
return Status;
} /* End of CustomEarlyInit() */
/*******************************************************************
**
** SCH_CustomLateInit
**
** NOTE: For complete prolog information, see 'sch_custom.h'
**
** This function MUST perform any startup synchronization required,
** and MUST finish setting up the major and minor frame timers.
********************************************************************/
int32 SCH_CustomLateInit(void)
{
int32 Status = CFE_SUCCESS;
uint32 TimeBaseId;
CFE_ES_WaitForStartupSync(SCH_PLATFORM_STARTUP_SYNC_TIMEOUT);
/* Start Minor Frame Timer at 100 Hz */
Status = OS_TimeBaseGetIdByName(&TimeBaseId, "cFS-Master");
if (Status == OS_SUCCESS)
{
Status = CFE_PSP_TimerAdd(&SCH_AppData.TimerId, SCH_TIMER_NAME, TimeBaseId, SCH_MinorFrameCallback, NULL);
}
if (Status == OS_SUCCESS)
{
Status = CFE_PSP_TimerSet(SCH_AppData.TimerId, SCH_PLATFORM_STARTUP_PERIOD, SCH_NORMAL_SLOT_PERIOD);
}
return Status;
} /* End of SH_CustomLateInit() */
/*******************************************************************
**
** SCH_CustomGetCurrentSlotNumber
**
** NOTE: For complete prolog information, see 'sch_custom.h'
********************************************************************/
uint32 SCH_CustomGetCurrentSlotNumber(void)
{
return SCH_AppData.MinorFramesSinceTone;
} /* End of SH_CustomGetCurrentSlotNumber() */
/*******************************************************************
**
** SCH_CustomCleanup
**
** NOTE: For complete prolog information, see 'sch_custom.h'
********************************************************************/
void SCH_CustomCleanup(void)
{
return;
} /* End of SH_CustomCleanup() */
/*******************************************************************
**
** SCH_MinorFrameCallback
**
** NOTE: For complete prolog information, see above
********************************************************************/
void SCH_MinorFrameCallback(uint32 TimerId, void *Arg)
{
SCH_AppData.MinorFramesSinceTone++;
/* Update Major Frame when Minor Frame rolls over number of slots */
if (SCH_AppData.MinorFramesSinceTone >= SCH_MISSION_TOTAL_SLOTS)
{
SCH_AppData.MinorFramesSinceTone = 0;
SCH_AppData.ValidMajorFrameCount++;
}
/*
** Give "wakeup SCH" semaphore
*/
OS_BinSemGive(SCH_AppData.TimeSemaphore);
} /* End of SCH_MinorFrameCallback() */
/************************/
/* End of File Comment */
/************************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment