Atmel Software Framework

cptime.c File Reference
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "FreeRTOS.h"
#include "task.h"
#include "cptime.h"
#include "shell.h"

Data Structures

struct  st_scheduled_cmd
 

Macros

#define CPTIME_MAX_NB_SCHED_CMDS   10
 

Typedefs

typedef struct st_scheduled_cmd Scheduled_Cmd
 

Functions

eExecStatus e_cptime_cmd_get_config (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 The get time config command: get the config fields value of the time module Takes no parameter. More...
 
eExecStatus e_cptime_cmd_set_config (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 The set time config command: set each config field value of the time module. Takes one parameter : field=value. More...
 
eExecStatus e_cptime_RecordScheduledCmd (char *pcDate, int CmdId, void(*pfScheduledCmd)(int, void *), void *pvCmdParams, signed portCHAR **ppcStringReply)
 Record a scheduled command. More...
 
static void prv_v_ShiftScheduledCmdsArray (int SrcIdx, int DstIdx)
 Shift the Scheduled Cmds array from the SrcIdx index down to the DstIdx index. More...
 
void v_cptime_ExecuteScheduledCmd (void)
 Execute a scheduled command if expiration date is up. More...
 
void v_cptime_GetDateInFatStringFormat (char *pcDate)
 Get the current time in the "YYYYMMDDHHMMSSMS" string format. More...
 
void v_cptime_Init (void)
 Init the time module. More...
 
void v_cptime_UpdateLocalTime (void)
 Update the local time. More...
 

Variables

static Scheduled_Cmd axCmdsSched [CPTIME_MAX_NB_SCHED_CMDS]
 
const signed portCHAR *const CPTIME_ERRMSG_SETCFG_INVALIDDATE = (signed portCHAR *)ERROR_CRLF"Invalid date"CRLF
 
const signed portCHAR *const CPTIME_ERRMSG_SETCFG_SYNTAXERROR = (signed portCHAR *)ERROR_CRLF"Usage: set_sys_config sys=time field=value"CRLF
 
const signed portCHAR *const CPTIME_ERRMSG_SETCFG_UNKNOWNFIELD = (signed portCHAR *)ERROR_CRLF"Unknown configuration field"CRLF
 
const signed portCHAR *const CPTIME_ERRMSG_SETVAL_INVALIDTIME = (signed portCHAR *)ERROR_CRLF"Invalid schedule date"CRLF
 
const signed portCHAR *const CPTIME_ERRMSG_SETVAL_UNAVAILSCHEDSLOT = (signed portCHAR *)ERROR_CRLF"No scheduling slot left"CRLF
 
static int NbSchedCmd = 0
 
time_t xcptime_LocalTime
 The watchdog timeout delay. More...
 
static portTickType xcptime_TickOrigin = 0
 

#define CPTIME_MAX_NB_SCHED_CMDS   10

The type of a scheduled command entry.

eExecStatus e_cptime_cmd_get_config ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

The get time config command: get the config fields value of the time module Takes no parameter.

Note
This function must be of the type pfShellCmd defined by the shell module.
Parameters
xModIdInput. The module that is calling this function.
FsNavIdIgnored.
acInput. The argument counter. For this command, should be 1.
avInput. The argument vector.
ppcStringReplyInput/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string.
Returns
the status of the command execution.

References NULL, pvPortMalloc(), SHELL_ERRMSG_MEMALLOC, SHELL_EXECSTATUS_KO, SHELL_EXECSTATUS_OK, sprintf(), and xcptime_LocalTime.

Referenced by e_syscmds_cmd_get_config().

eExecStatus e_cptime_cmd_set_config ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

The set time config command: set each config field value of the time module. Takes one parameter : field=value.

Note
This function must be of the type pfShellCmd defined by the shell module.
Parameters
xModIdInput. The module that is calling this function.
FsNavIdIgnored.
acInput. The argument counter. For this command, should be 1.
avInput. The argument vector.
ppcStringReplyInput/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string.
Returns
the status of the command execution.

References CPTIME_ERRMSG_SETCFG_INVALIDDATE, CPTIME_ERRMSG_SETCFG_SYNTAXERROR, CPTIME_ERRMSG_SETCFG_UNKNOWNFIELD, CPTIME_MAX_NB_SCHED_CMDS, i, NAKED_TRACE_COM2, NbSchedCmd, NULL, prv_v_ShiftScheduledCmdsArray(), SHELL_EXECSTATUS_KO, SHELL_EXECSTATUS_OK, xcptime_LocalTime, and st_scheduled_cmd::xScheduledTime.

Referenced by e_syscmds_cmd_set_config().

eExecStatus e_cptime_RecordScheduledCmd ( char *  pcDate,
int  CmdId,
void(*)(int, void *)  pfScheduledCmd,
void *  pvCmdParams,
signed portCHAR **  ppcStringReply 
)

Record a scheduled command.

Parameters
pcDateInput. The date the cmd is scheduled at. Format: seconds OR mm/dd/yy hh:mm:ss
CmdIdScheduled command id.
pfScheduledCmdpointer on fct to be called at expiration date
pvCmdParamspointer on struct to give as param to pfScheduledCmd
ppcStringReplyInput/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string.
Returns
the status of the command execution.

References st_scheduled_cmd::CmdId, CPTIME_ERRMSG_SETVAL_INVALIDTIME, CPTIME_ERRMSG_SETVAL_UNAVAILSCHEDSLOT, CPTIME_MAX_NB_SCHED_CMDS, i, j, NbSchedCmd, st_scheduled_cmd::pfScheduledCmd, st_scheduled_cmd::pxParam, SHELL_EXECSTATUS_KO, SHELL_EXECSTATUS_OK_NO_FREE, xcptime_LocalTime, and st_scheduled_cmd::xScheduledTime.

Referenced by e_actuator_ScheduleCmdSet().

static void prv_v_ShiftScheduledCmdsArray ( int  SrcIdx,
int  DstIdx 
)
static

Shift the Scheduled Cmds array from the SrcIdx index down to the DstIdx index.

Parameters
SrcIdxInput. The source index.
DstIdxInput. The Destination index.

References st_scheduled_cmd::CmdId, CPTIME_MAX_NB_SCHED_CMDS, st_scheduled_cmd::pfScheduledCmd, st_scheduled_cmd::pxParam, and st_scheduled_cmd::xScheduledTime.

Referenced by e_cptime_cmd_set_config(), and v_cptime_ExecuteScheduledCmd().

void v_cptime_ExecuteScheduledCmd ( void  )

Execute a scheduled command if expiration date is up.

References NbSchedCmd, st_scheduled_cmd::pfScheduledCmd, prv_v_ShiftScheduledCmdsArray(), xcptime_LocalTime, and st_scheduled_cmd::xScheduledTime.

Referenced by portTASK_FUNCTION().

void v_cptime_GetDateInFatStringFormat ( char *  pcDate)

Get the current time in the "YYYYMMDDHHMMSSMS" string format.

Parameters
pcDateInput/Output. Input allocated array. Output is the current time expressed in the "YYYYMMDDHHMMSSMS" string format.

References sprintf(), and xcptime_LocalTime.

Referenced by b_mmi_mkdir_aLOG(), b_mmi_mkdir_bLOG(), config_file_set_value(), e_fscmds_shell_mkdir(), e_fscmds_touch(), prv_append(), prv_vsave_logs(), and prv_xopen_current_logfile().

void v_cptime_Init ( void  )

Init the time module.

References xcptime_LocalTime.

Referenced by main().

void v_cptime_UpdateLocalTime ( void  )

Initial value:
= {
{0, 0, NULL, NULL},
{0, 0, NULL, NULL},
{0, 0, NULL, NULL},
{0, 0, NULL, NULL},
{0, 0, NULL, NULL},
{0, 0, NULL, NULL},
{0, 0, NULL, NULL},
{0, 0, NULL, NULL},
{0, 0, NULL, NULL},
{0, 0, NULL, NULL} }
#define NULL
Definition: lwip-1.4.0/src/include/lwip/def.h:47

Array of scheduled commands.

const signed portCHAR* const CPTIME_ERRMSG_SETCFG_INVALIDDATE = (signed portCHAR *)ERROR_CRLF"Invalid date"CRLF

Error msg upon set_sys_config sys=time curtime="date" where date is invalid.

Referenced by e_cptime_cmd_set_config().

const signed portCHAR* const CPTIME_ERRMSG_SETCFG_SYNTAXERROR = (signed portCHAR *)ERROR_CRLF"Usage: set_sys_config sys=time field=value"CRLF

Error msg upon set cfg time syntax error.

Referenced by e_cptime_cmd_set_config().

const signed portCHAR* const CPTIME_ERRMSG_SETCFG_UNKNOWNFIELD = (signed portCHAR *)ERROR_CRLF"Unknown configuration field"CRLF

Error msg upon set cfg time of an invalid config field.

Referenced by e_cptime_cmd_set_config().

const signed portCHAR* const CPTIME_ERRMSG_SETVAL_INVALIDTIME = (signed portCHAR *)ERROR_CRLF"Invalid schedule date"CRLF

Error msg if the time for scheduling is invalid.

Referenced by e_cptime_RecordScheduledCmd().

const signed portCHAR* const CPTIME_ERRMSG_SETVAL_UNAVAILSCHEDSLOT = (signed portCHAR *)ERROR_CRLF"No scheduling slot left"CRLF

Error msg if there is no scheduling slot left.

Referenced by e_cptime_RecordScheduledCmd().

int NbSchedCmd = 0
static
portTickType xcptime_TickOrigin = 0
static

The OS tick origin. This may not be == 0, if the local time is set through a shell command or acquired though the TIME protocol.

Referenced by v_cptime_UpdateLocalTime().