datalog.h File Reference


Detailed Description

AVR32 UC3 Control Panel data logger module interface.

This module is in charge of the logs of data coming from the sensors and the actuators of the Control Panel.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file datalog.h.

#include <time.h>
#include "FreeRTOS.h"
#include "supervisor.h"

Go to the source code of this file.

Data Structures

struct  LogDef

Defines

#define DATALOG_ALLOC_DYNAMIC   TRUE
#define DATALOG_ALLOC_STATIC   FALSE
#define DATALOG_LOG_MAXSIZE   64
#define pxdatalog_log_alloc_init_FromISR()   pxdatalog_log_alloc_init( DATALOG_ALLOC_STATIC )
 Allocate and init a xLogDef structure from an ISR.

Typedefs

typedef struct LogDef xLogDef

Enumerations

enum  eLogSourceId {
  DATALOG_ID_TEMP, DATALOG_ID_POT, DATALOG_ID_LIGHT, DATALOG_ID_PB1,
  DATALOG_ID_PB2, DATALOG_ID_PB3, DATALOG_ID_JS, DATALOG_ID_LEDB1,
  DATALOG_ID_LEDB2, DATALOG_ID_LEDM1, DATALOG_ID_LEDM2, DATALOG_ID_LCD
}

Functions

Bool b_datalog_set_current_log_drive_toDF (void)
 Set the current logs to be stored to the DataFlash.
Bool b_datalog_set_current_log_drive_toSDMMC (void)
 Set the current logs to be stored to the SDMMC card.
Bool bdatalog_start (unsigned portBASE_TYPE uxPriority)
xLogDefpxdatalog_log_alloc_init (Bool bAllocType)
 Allocate and init a xLogDef structure.
void vdatalog_log_free (xLogDef *pxLog)
 Free a data log structure and its content.
void vdatalog_make_logstring (xLogDef *pxLog, signed portCHAR *pcLogString)
 Build a log string from a xLogDef log structure.
portBASE_TYPE x_datalog_AddLogFromISR (xLogDef *pxLog)
 Add a log in the xLogsQueue, from within an ISR.

Variables

char * acLogSourceName []


Define Documentation

#define DATALOG_ALLOC_DYNAMIC   TRUE

xLogDef structure allocation types.

Definition at line 66 of file datalog.h.

Referenced by e_actuator_cmd_get_value(), e_sensor_cmd_get_value(), pxdatalog_log_alloc_init(), and v_datalog_AddSensorLog().

#define DATALOG_ALLOC_STATIC   FALSE

Definition at line 67 of file datalog.h.

#define DATALOG_LOG_MAXSIZE   64

A data log max size.

Definition at line 63 of file datalog.h.

Referenced by e_actuator_cmd_get_value(), and e_sensor_cmd_get_value().

 
#define pxdatalog_log_alloc_init_FromISR (  )     pxdatalog_log_alloc_init( DATALOG_ALLOC_STATIC )

Allocate and init a xLogDef structure from an ISR.

Returns:
Pointer on an xLogDef structure or NULL if the alloc failed.

Definition at line 138 of file datalog.h.

Referenced by prvjoystick_ISR_NonNakedBehaviour(), and prvpushb_ISR_NonNakedBehaviour().


Typedef Documentation

typedef struct LogDef xLogDef


Enumeration Type Documentation

Logs Sources(sensors and actuators) id.

Enumerator:
DATALOG_ID_TEMP 
DATALOG_ID_POT 
DATALOG_ID_LIGHT 
DATALOG_ID_PB1 
DATALOG_ID_PB2 
DATALOG_ID_PB3 
DATALOG_ID_JS 
DATALOG_ID_LEDB1 
DATALOG_ID_LEDB2 
DATALOG_ID_LEDM1 
DATALOG_ID_LEDM2 
DATALOG_ID_LCD 

Definition at line 72 of file datalog.h.

00073 {
00074    DATALOG_ID_TEMP,    // The temperature sensor.
00075    DATALOG_ID_POT,     // The potentiometer sensor.
00076    DATALOG_ID_LIGHT,   // The light sensor.
00077    DATALOG_ID_PB1,     // The pushbutton1 sensor.
00078    DATALOG_ID_PB2,     // The pushbutton2 sensor.
00079    DATALOG_ID_PB3,     // The pushbutton3 sensor.
00080    DATALOG_ID_JS,      // The joystick sensor.
00081    DATALOG_ID_LEDB1,   // The bicolor led 1 actuator.
00082    DATALOG_ID_LEDB2,   // The bicolor led 2 actuator.
00083    DATALOG_ID_LEDM1,   // The monocolor led 1 actuator.
00084    DATALOG_ID_LEDM2,   // The monocolor led 2 actuator.
00085    DATALOG_ID_LCD,     // The LCD actuator.
00086 } eLogSourceId;


Function Documentation

Bool b_datalog_set_current_log_drive_toDF ( void   ) 

Set the current logs to be stored to the DataFlash.

Returns:
TRUE

Definition at line 724 of file datalog.c.

References acLogFileName, pcStringCurrentLogDirectoryName, and pcStringLogDirectoryNameA.

00725 {
00726    // If the current logs were being stored on the SDMMC memory, force a new
00727    // file creation (by resetting the file name).
00728    if(*acLogFileName == 'B')
00729    {
00730       *acLogFileName = '\0';
00731    }
00732    pcStringCurrentLogDirectoryName = pcStringLogDirectoryNameA;
00733    return(pdTRUE);
00734 }

Bool b_datalog_set_current_log_drive_toSDMMC ( void   ) 

Set the current logs to be stored to the SDMMC card.

Returns:
TRUE

Definition at line 742 of file datalog.c.

References acLogFileName, pcStringCurrentLogDirectoryName, and pcStringLogDirectoryNameB.

00743 {
00744    // If the current logs were being stored on the DF memory, force a new
00745    // file creation (by resetting the file name).
00746    if(*acLogFileName == 'A')
00747    {
00748       *acLogFileName = '\0';
00749    }
00750    pcStringCurrentLogDirectoryName = pcStringLogDirectoryNameB;
00751    return(pdTRUE);
00752 }

Bool bdatalog_start ( unsigned portBASE_TYPE  uxPriority  ) 

Start the data logger module.

Parameters:
uxPriority The base priority of the data logger tasks.
Returns:
TRUE upon success, else FALSE.

Definition at line 191 of file datalog.c.

References DATALOG_INVALID_LOGSRC_ID, DATALOG_LOGSQUEUE_HITHRESHOLD, DATALOG_LOGSQUEUE_SIZE, DATALOG_STACK_SIZE, LOGTOFILE_STACK_SIZE, pcStringCurrentLogDirectoryName, pcStringLogDirectoryNameA, SYS_STATUS_DOWN, xDataLogHndl, xDataLogStatus, xLogsQueue, and xLogToFileHndl.

Referenced by portTASK_FUNCTION().

00192 {
00193    int i;
00194 
00195    /* By default, set the current log directory to be in the DataFlash. */
00196    pcStringCurrentLogDirectoryName = pcStringLogDirectoryNameA;
00197 
00198    /* Init the xLogDef pool: set each log as free. */
00199    for( i=0; i<DATALOG_LOGSQUEUE_HITHRESHOLD; i++)
00200       axLogsPool[i].id = DATALOG_INVALID_LOGSRC_ID;
00201 
00202    /* Spawn the data log task. */
00203    if( pdPASS != xTaskCreate( vDataLogTask,
00204                               ( const signed portCHAR * )"DLOG",
00205                               DATALOG_STACK_SIZE, NULL, uxPriority,
00206                               &xDataLogHndl ) )
00207    {
00208       xDataLogStatus = SYS_STATUS_DOWN;
00209       return FALSE;
00210    }
00211 
00212    /* Spawn the LogToFile task. */
00213    if( pdPASS != xTaskCreate( vLogToFileTask,
00214                               ( const signed portCHAR * )"LOGF",
00215                               LOGTOFILE_STACK_SIZE, NULL, uxPriority +1,
00216                               &xLogToFileHndl ) )
00217    {
00218       vTaskDelete( xDataLogHndl );
00219       xDataLogStatus = SYS_STATUS_DOWN;
00220       return FALSE;
00221    }
00222 
00223    // Create the xLogsQueue capable of containing DATALOG_LOGSQUEUE_SIZE ptrs
00224    // to xLogDef structures.
00225    xLogsQueue = xQueueCreate( DATALOG_LOGSQUEUE_SIZE, sizeof( xLogDef * ) );
00226    if( 0 == xLogsQueue )
00227    { // Queue was not created and must not be used.
00228       vTaskDelete( xDataLogHndl );
00229       vTaskDelete( xLogToFileHndl );
00230       return FALSE;
00231    }
00232 
00233    return( TRUE );
00234 }

xLogDef* pxdatalog_log_alloc_init ( Bool  bAllocType  ) 

Allocate and init a xLogDef structure.

Parameters:
bAllocType Allocation type (dynamic or static)
Returns:
Pointer on an xLogDef structure or NULL if the alloc failed.
Parameters:
bAllocType Allocation type (dynamic or static(FromISR))
Returns:
Pointer on an xLogDef structure or NULL if the alloc failed.

Definition at line 468 of file datalog.c.

References DATALOG_ALLOC_DYNAMIC, DATALOG_INVALID_LOGSRC_ID, DATALOG_LOGSQUEUE_HITHRESHOLD, LogDef::pcStringLog, LogDef::pfFreeLogStruct, LogDef::pfFreeStringLog, prv_vdatalog_pool_log_free(), LogDef::rawdate, u8FreeLogIdx, and xcptime_LocalTime.

Referenced by e_actuator_cmd_get_value(), e_sensor_cmd_get_value(), and v_datalog_AddSensorLog().

00469 {
00470    xLogDef   *pxLog;
00471    void      (*pfFreeLogStruct)(void *);
00472 
00473 
00474    // Alloc a log structure.
00475    if( DATALOG_ALLOC_DYNAMIC == bAllocType )
00476    {   // Dynamic alloc.
00477       pxLog = ( xLogDef * )pvPortMalloc( sizeof( xLogDef ) );
00478       pfFreeLogStruct = vPortFree; // Because pvPortMalloc() was used to alloc
00479                                    // the log structure.
00480    }
00481    else
00482    {   // Static alloc.
00483       // TODO : add mutex if events are not on the same int level.
00484       if( DATALOG_INVALID_LOGSRC_ID != axLogsPool[u8FreeLogIdx].id )
00485       {   // Unavailable log.
00486          return( NULL );
00487       }
00488       else
00489       {
00490          pxLog = &(axLogsPool[u8FreeLogIdx++]);
00491          u8FreeLogIdx = (u8FreeLogIdx == DATALOG_LOGSQUEUE_HITHRESHOLD) ? 0 : u8FreeLogIdx;
00492          pfFreeLogStruct = prv_vdatalog_pool_log_free;
00493       }
00494    }
00495 
00496    // Init the fields that can possibly be filled now.
00497    if( NULL != pxLog )
00498    {
00499       pxLog->rawdate = xcptime_LocalTime;
00500       pxLog->pfFreeLogStruct = pfFreeLogStruct;
00501       pxLog->pcStringLog = NULL;
00502       pxLog->pfFreeStringLog = NULL;
00503    }
00504 
00505    return( pxLog );
00506 }

void vdatalog_log_free ( xLogDef pxLog  ) 

Free a data log structure and its content.

Parameters:
pxLog pointer on the data log structure to free.

Definition at line 515 of file datalog.c.

References LogDef::pcStringLog, LogDef::pfFreeLogStruct, and LogDef::pfFreeStringLog.

Referenced by e_actuator_cmd_get_value(), e_sensor_cmd_get_value(), prv_vsave_logs(), v_datalog_AddSensorLog(), and x_datalog_AddLogFromISR().

00516 {
00517    // Free the log string.
00518    if( NULL != pxLog->pfFreeStringLog)
00519    {
00520       pxLog->pfFreeStringLog( pxLog->pcStringLog );
00521    }
00522    // Free the structure.
00523    pxLog->pfFreeLogStruct( pxLog );
00524 }

void vdatalog_make_logstring ( xLogDef pxLog,
signed portCHAR *  pcLogString 
)

Build a log string from a xLogDef log structure.

Parameters:
pxLog Pointer on a data log structure
pcLogString Allocated DATALOG_LOG_MAXSIZE string to fill.

Definition at line 546 of file datalog.c.

References acLogSourceName, LogDef::id, LogDef::pcStringLog, LogDef::rawdate, and sprintf().

Referenced by e_actuator_cmd_get_value(), e_sensor_cmd_get_value(), and prv_vsave_logs().

00547 {
00548    struct tm   *pxLogDate;
00549 
00550 
00551    // Get the broken-down representation of the log date.
00552    pxLogDate = gmtime( &(pxLog->rawdate) );
00553 
00554    // Build the log string.
00555    // WARNING: pxLogDate->tm_year == nunmber of years since 1900.
00556    // For years >= 2000, we'll display the last 2 digits only.
00557    if( pxLogDate->tm_year >= 100 )
00558       pxLogDate->tm_year -= 100;
00559    sprintf( (char *)pcLogString, "%s | %.2d/%.2d/%.2d %.2d:%.2d:%.2d | %s\r\n",
00560             acLogSourceName[pxLog->id], pxLogDate->tm_mon +1,
00561             pxLogDate->tm_mday, pxLogDate->tm_year, pxLogDate->tm_hour,
00562             pxLogDate->tm_min, pxLogDate->tm_sec, pxLog->pcStringLog );
00563 }

portBASE_TYPE x_datalog_AddLogFromISR ( xLogDef pxLog  ) 

Add a log in the xLogsQueue, from within an ISR.

Parameters:
pxLog The log to add to the xLogsQueue.
Note:
This function must be called last by an ISR (Interrupt Service Routine) associated with an event-based sensor.

Definition at line 377 of file datalog.c.

References DATALOG_LOGSQUEUE_SIZE, uxNbMsgsInLogsQueue, vdatalog_log_free(), and xLogsQueue.

Referenced by prvjoystick_ISR_NonNakedBehaviour(), and prvpushb_ISR_NonNakedBehaviour().

00378 {
00379    portBASE_TYPE xYieldRequired = pdFALSE;
00380 
00381 
00382    if( ( NULL != pxLog ) && ( DATALOG_LOGSQUEUE_SIZE != uxNbMsgsInLogsQueue ) )
00383    {
00384       // NOTE: xQueueSendFromISR() doesn't say if it could add the log or not.
00385       // For this reason, we will first test if the queue is full. Note that
00386       // we cannot call uxQueueMessagesWaiting() from an ISR, so we'll play it
00387       // safe by looking at the latest call to uxQueueMessagesWaiting().
00388       // There is some hand-tuning here involved: the vLogToFileTask() must
00389       // work often enough so that the xLogsQueue never gets full.
00390       if( DATALOG_LOGSQUEUE_SIZE == uxNbMsgsInLogsQueue )
00391       {   // Safety
00392          vdatalog_log_free( pxLog );
00393       }
00394       else
00395       {   // Add the log to the xLogsQueue.
00396          portENTER_CRITICAL();
00397          xQueueSendFromISR( xLogsQueue, (void *)&pxLog, &xYieldRequired );
00398          portEXIT_CRITICAL();
00399       }
00400    }
00401    return( xYieldRequired );
00402 }


Variable Documentation

char* acLogSourceName[]


Generated on Fri Feb 19 02:22:44 2010 for AVR32 - Control Panel demonstration. by  doxygen 1.5.5