Microchip® Advanced Software Framework

supervisor.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include "FreeRTOS.h"
#include "task.h"
#include "conf_ctrlpanel.h"
#include "tracedump.h"
#include "navigation.h"
#include "com1shell.h"
#include "datalog.h"
#include "cptime.h"
#include "sensor.h"
#include "mmi.h"
#include "shell.h"
#include "syscmds.h"
#include "fsaccess.h"
#include "ethernet.h"
#include "netif/etharp.h"
#include "BasicWEB.h"
#include "conf_usb.h"
#include "usbsys.h"
#include "usb_task.h"
#include "usb_standard_request.h"
#include "usb_drv.h"

Macros

#define mainCOMSH_TASK_PRIORITY   ( tskIDLE_PRIORITY + 2 )
 Priority definitions for most of the tasks in the demo application. More...
 
#define mainDATALOG_TASK_PRIORITY   ( tskIDLE_PRIORITY + 2 )
 
#define mainETH_TASK_PRIORITY   ( tskIDLE_PRIORITY + 1 )
 
#define SUPERVISOR_CHECK_KO   (-1)
 Return status false. More...
 
#define SUPERVISOR_CHECK_OK   0
 Return status true. More...
 
#define SUPERVISOR_DEFAULT_PERIOD   ( ( portTickType ) 100 / portTICK_RATE_MS )
 The supervisor rate in ticks. More...
 
#define SUPERVISOR_DELAY_HEAPCHECK   600
 The delay between each heap usage check. More...
 
#define SUPERVISOR_DELAY_MMI_TIMEUPDATE   10
 The delay between each time update on the MMI. More...
 
#define SUPERVISOR_DELAY_PRINTTASKLIST   600
 The delay between each tasks list display. More...
 
#define SUPERVISOR_DELAY_TIMEUPDATE   10
 The delay between each time update. More...
 
#define SUPERVISOR_MAINTENANCE_NBMUTEX_TOTAKE   4
 The number of system mutexes to take before switching to maintenance mode. More...
 
#define SUPERVISOR_QUEUE_SIZE   1
 The supervisor queue length. More...
 
#define SUPERVISOR_STACK_SIZE   ( configMINIMAL_STACK_SIZE + 192 )
 
#define SUPERVISOR_USB_ROLE_DEVICE   1
 The Control Panel is acting as a USB device. More...
 
#define SUPERVISOR_USB_ROLE_HOST   2
 The Control Panel is acting as a USB host. More...
 
#define SUPERVISOR_USB_ROLE_NONE   0
 
#define SUPERVISOR_USER_ACTION_STACK_SIZE   (configMINIMAL_STACK_SIZE+64)
 The supervisor User Action stack size. More...
 
#define SUPERVISOR_USER_ACTION_TASK_PRIORITY   ( tskIDLE_PRIORITY + 2 )
 The supervisor User Action task priority. More...
 

Functions

bool b_supervisor_IsInMaintenanceMode (void)
 Maintenance mode status. More...
 
bool b_supervisor_leave_UsbMassStorage_mode (void)
 Leave the USB Mass Storage mode while the USB host is plugged in. More...
 
bool b_supervisor_leave_waitingforhost_mode (void)
 Leave the waiting-for-host mode while the USB host has not been plugged in yet. More...
 
bool b_supervisor_switch_to_maintenance_mode (void)
 The switch-to-maintenance-mode command: initiate the process to
switch to maintenance mode. More...
 
bool b_USBHostCopyCfg (void)
 Launch the "Upload CFG Files" MMI task that copies the /CFG directory from the USB Mass Storage device to the Control Panel. More...
 
bool b_USBHostCopyLogs (void)
 Launch the "Copy Logs" MMI task that copies the /LOG directory from the
Control Panel to the USB Mass Storage device. More...
 
bool b_USBHostCopyWeb (void)
 Launch the "Upload WEB Files" MMI task that copies the /WEB directory from the USB Mass Storage device to the Control Panel. More...
 
bool b_USBHostMoveLogs (void)
 Launch the "Move Logs" MMI task that moves the /LOG directory content
from the Control Panel to the USB Mass Storage device. More...
 
eExecStatus e_supervisor_switch_to_maintenance_mode (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 The switch-to-maintenance-mode command: initiate the process to
switch to maintenance mode. Format: maintain. More...
 
static portTASK_FUNCTION (vSupervisorUserActionTask, pvParameters)
 The MMI user-action task: in charge of launching an action requested through the MMI. More...
 
static portTASK_FUNCTION (vSupervisorTask, pvParameters)
 Supervisor task. More...
 
static portTASK_FUNCTION_PROTO (vSupervisorTask, pvParameters)
 
static void prv_v_common_leave_UsbDevice_mode (void)
 Release the semaphores and change the MMI user menu mode. More...
 
static void prv_v_leave_maintenance_mode (void)
 Do the required actions to leave the maintenance mode. More...
 
static void prv_v_manage_user_action (void)
 
void prvCheckMallocHeap (void)
 
void v_supervisor_Device_Connects (void)
 Called upon remote device connection (upon PIN ID CHANGE event when we are host) More...
 
void v_supervisor_Device_Disconnects (void)
 Called upon remote device disconnection (upon PIN ID CHANGE event when we are host) More...
 
void v_supervisor_Host_Connects (void)
 Called upon remote host connect (upon VBUS ON event when we are device) More...
 
void v_supervisor_Host_Disconnects (void)
 Called upon VBUS OFF event. More...
 
void vSupervisor_Start (unsigned portBASE_TYPE uxPriority)
 Start the supervisor module. More...
 
portBASE_TYPE x_supervisor_SemaphoreGive (xSemaphoreHandle xSemaphore)
 Release a system mutex. More...
 
portBASE_TYPE x_supervisor_SemaphoreTake (xSemaphoreHandle xSemaphore, portTickType xBlockTime)
 Take a system mutex. More...
 

Variables

void __heap_end__
 
void __heap_start__
 
static bool bIsInMaintenance = false
 
static bool bOutOfMaintenance = false
 
portBASE_TYPE * pxHighestHeapAddr = (portBASE_TYPE *)&__heap_start__
 
signed short sMmiNavId
 
static U8 u8CurrentUsbRole = SUPERVISOR_USB_ROLE_NONE
 
U8 u8IsMaintenanceRequired = 0
 
xSemaphoreHandle xCFGMutex
 
time_t xcptime_LocalTime
 
xSemaphoreHandle xLOGMutex
 
xSemaphoreHandle xSHELLFSMutex
 
xQueueHandle xSUPERVISORQueue = 0
 
static xTaskHandle xSupervisorUserActionHndl = NULL
 
xSemaphoreHandle xUSBMutex
 
xSemaphoreHandle xWEBMutex
 

#define SUPERVISOR_MAINTENANCE_NBMUTEX_TOTAKE   4

The number of system mutexes to take before switching to maintenance mode.

Referenced by e_supervisor_switch_to_maintenance_mode(), and x_supervisor_SemaphoreGive().

bool b_supervisor_IsInMaintenanceMode ( void  )

Maintenance mode status.

Returns
true if the maintenance mode is active else false.

References bIsInMaintenance.

Referenced by e_syscmds_reboot().

bool b_supervisor_leave_UsbMassStorage_mode ( void  )

Leave the USB Mass Storage mode while the USB host is plugged in.

References bIsInMaintenance, pdTRUE, prv_v_leave_maintenance_mode(), and Usb_detach.

bool b_supervisor_leave_waitingforhost_mode ( void  )

Leave the waiting-for-host mode while the USB host has not been plugged in yet.

References bIsInMaintenance, pdTRUE, and prv_v_common_leave_UsbDevice_mode().

bool b_supervisor_switch_to_maintenance_mode ( void  )

The switch-to-maintenance-mode command: initiate the process to
switch to maintenance mode.

References e_supervisor_switch_to_maintenance_mode(), NULL, pdTRUE, and SYS_MODID_NONE.

bool b_USBHostCopyCfg ( void  )

Launch the "Upload CFG Files" MMI task that copies the /CFG directory from the USB Mass Storage device to the Control Panel.

Returns
pdTRUE

References e_usbsys_cp_cfg_to_local(), eUserMenuUSBHost, eUserMenuUSBHostActing, NAKED_TRACE_COM2, NULL, pdFALSE, pdTRUE, SHELL_EXECSTATUS_KO, sMmiNavId, SYS_MODID_MMI, vMMI_SetUserMenuMode(), and vTaskDelay().

bool b_USBHostCopyLogs ( void  )

Launch the "Copy Logs" MMI task that copies the /LOG directory from the
Control Panel to the USB Mass Storage device.

Returns
pdTRUE

References e_usbsys_cp_logs_to_key(), eUserMenuUSBHost, eUserMenuUSBHostActing, NAKED_TRACE_COM2, NULL, pdFALSE, pdTRUE, SHELL_EXECSTATUS_KO, sMmiNavId, SYS_MODID_MMI, vMMI_SetUserMenuMode(), and vTaskDelay().

bool b_USBHostCopyWeb ( void  )

Launch the "Upload WEB Files" MMI task that copies the /WEB directory from the USB Mass Storage device to the Control Panel.

Returns
pdTRUE

References e_usbsys_cp_web_to_local(), eUserMenuUSBHost, eUserMenuUSBHostActing, NAKED_TRACE_COM2, NULL, pdFALSE, pdTRUE, SHELL_EXECSTATUS_KO, sMmiNavId, SYS_MODID_MMI, vMMI_SetUserMenuMode(), and vTaskDelay().

bool b_USBHostMoveLogs ( void  )

Launch the "Move Logs" MMI task that moves the /LOG directory content
from the Control Panel to the USB Mass Storage device.

Returns
pdTRUE

References e_usbsys_mv_logs_to_key(), eUserMenuUSBHost, eUserMenuUSBHostActing, NAKED_TRACE_COM2, NULL, pdFALSE, pdTRUE, SHELL_EXECSTATUS_KO, sMmiNavId, SYS_MODID_MMI, vMMI_SetUserMenuMode(), and vTaskDelay().

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

The switch-to-maintenance-mode command: initiate the process to
switch to maintenance mode. Format: maintain.

Note
This function must be of the type pfShellCmd defined by the shell module.
Parameters
xModIdInput. The module that is calling this function.
FsNavIdIgnored.
acIgnored.
avIgnored.
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 bIsInMaintenance, CRLF, eUserMenuWaitHost, fat_cache_flush(), Is_usb_clock_frozen, Is_usb_detached, NAKED_TRACE_COM2, nav_reset(), NULL, pdTRUE, SHELL_EXECSTATUS_OK, SUPERVISOR_MAINTENANCE_NBMUTEX_TOTAKE, TRACE_COM2, u8CurrentUsbRole, u8IsMaintenanceRequired, Usb_attach, Usb_detach, Usb_unfreeze_clock, vMMI_SetUserMenuMode(), vTaskDelay(), x_supervisor_SemaphoreTake(), and xSemaphoreGive.

Referenced by b_supervisor_switch_to_maintenance_mode(), and e_syscmds_reboot().

static portTASK_FUNCTION ( vSupervisorUserActionTask  ,
pvParameters   
)
static

The MMI user-action task: in charge of launching an action requested through the MMI.

References NAKED_TRACE_COM2, NULL, pdTRUE, void, vTaskSuspend(), and xQueueReceive.

static portTASK_FUNCTION_PROTO ( vSupervisorTask  ,
pvParameters   
)
static
static void prv_v_common_leave_UsbDevice_mode ( void  )
static

Release the semaphores and change the MMI user menu mode.

References eUserMenuIdle, pdFALSE, pdTRUE, TRACE_COM2, vMMI_SetUserMenuMode(), xSemaphoreGive, and xSemaphoreTake.

Referenced by b_supervisor_leave_waitingforhost_mode(), and prv_v_leave_maintenance_mode().

static void prv_v_leave_maintenance_mode ( void  )
static
static void prv_v_manage_user_action ( void  )
static
void prvCheckMallocHeap ( void  )
void v_supervisor_Device_Connects ( void  )

Called upon remote device connection (upon PIN ID CHANGE event when we are host)

References SUPERVISOR_USB_ROLE_HOST, SUPERVISOR_USB_ROLE_NONE, and u8CurrentUsbRole.

void v_supervisor_Device_Disconnects ( void  )

Called upon remote device disconnection (upon PIN ID CHANGE event when we are host)

Called upon remote device disconnection.

References ms_connected, ms_new_device_connected, SUPERVISOR_USB_ROLE_HOST, SUPERVISOR_USB_ROLE_NONE, and u8CurrentUsbRole.

void v_supervisor_Host_Connects ( void  )

Called upon remote host connect (upon VBUS ON event when we are device)

References bIsInMaintenance, SUPERVISOR_USB_ROLE_DEVICE, SUPERVISOR_USB_ROLE_NONE, u8CurrentUsbRole, u8IsMaintenanceRequired, Usb_detach, and Usb_unfreeze_clock.

void v_supervisor_Host_Disconnects ( void  )

Called upon VBUS OFF event.

Called upon remote host disconnection.

Warning
: the name of the function may imply that this is called in case we were a device, but this may not always be the case: this function may be called when we are a device. Explanation: the VBUS OFF event occurs in both cases.

References bIsInMaintenance, bOutOfMaintenance, SUPERVISOR_USB_ROLE_DEVICE, SUPERVISOR_USB_ROLE_NONE, and u8CurrentUsbRole.

void vSupervisor_Start ( unsigned portBASE_TYPE  uxPriority)

Start the supervisor module.

Parameters
uxPriorityThe priority base of the supervisor tasks.

References NULL, SUPERVISOR_STACK_SIZE, and xTaskCreate.

Referenced by main().

portBASE_TYPE x_supervisor_SemaphoreTake ( xSemaphoreHandle  xSemaphore,
portTickType  xBlockTime 
)

Take a system mutex.

Parameters
xSemaphoreA handle to the semaphore being released.
xBlockTimeThe time in ticks to wait for the semaphore to become available.
Returns
pdTRUE if the semaphore was obtained. pdFALSE if xBlockTime expired without the semaphore becoming available.

References bOutOfMaintenance, pdFALSE, and xSemaphoreTake.

Referenced by b_joystick_init(), b_light_init(), b_potentiometer_init(), b_pushb1_init(), b_pushb2_init(), b_pushb3_init(), b_temperature_init(), e_sensor_cmd_set_config(), e_supervisor_switch_to_maintenance_mode(), e_syscmds_cmd_set_config(), portTASK_FUNCTION(), prvEthernetConfigureInterface(), Shell_exec(), and usb_mass_storage_cbw().

void __heap_end__
void __heap_start__
portBASE_TYPE* pxHighestHeapAddr = (portBASE_TYPE *)&__heap_start__

Referenced by prvCheckMallocHeap().

U8 u8IsMaintenanceRequired = 0
xSemaphoreHandle xCFGMutex

The CFG system mutex.

Referenced by prvEthernetConfigureInterface().

xSemaphoreHandle xLOGMutex

The LOG system mutex.

xSemaphoreHandle xSHELLFSMutex

The SHELL system mutex.

xQueueHandle xSUPERVISORQueue = 0

The handle of the queue of SUPERVISOR, holding user actions to perform.

xTaskHandle xSupervisorUserActionHndl = NULL
static

MMI User Action task handle.

Referenced by portTASK_FUNCTION(), and prv_v_manage_user_action().

xSemaphoreHandle xUSBMutex

The USB system mutex.

xSemaphoreHandle xWEBMutex

The Web server system mutex.