SmartFusion2: Change linker file to run from NVM. Add in FreeRTOS+CLI and FreeRTOS+FAT SL demo.
parent
e3a868ca58
commit
410f5d45eb
@ -0,0 +1 @@
|
||||
Run the CreateProjectDirectoryStructure.bat batch file to populate this directory before building the demo.
|
@ -0,0 +1 @@
|
||||
Run the CreateProjectDirectoryStructure.bat batch file to populate this directory before building the demo.
|
@ -0,0 +1 @@
|
||||
Run the CreateProjectDirectoryStructure.bat batch file to populate this directory before building the demo.
|
@ -0,0 +1,574 @@
|
||||
/*
|
||||
FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||
|
||||
FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
|
||||
http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* FreeRTOS tutorial books are available in pdf and paperback. *
|
||||
* Complete, revised, and edited pdf reference manuals are also *
|
||||
* available. *
|
||||
* *
|
||||
* Purchasing FreeRTOS documentation will not only help you, by *
|
||||
* ensuring you get running as quickly as possible and with an *
|
||||
* in-depth knowledge of how to use FreeRTOS, it will also help *
|
||||
* the FreeRTOS project to continue with its mission of providing *
|
||||
* professional grade, cross platform, de facto standard solutions *
|
||||
* for microcontrollers - completely free of charge! *
|
||||
* *
|
||||
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
|
||||
* *
|
||||
* Thank you for using FreeRTOS, and thank you for your support! *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
|
||||
This file is part of the FreeRTOS distribution.
|
||||
|
||||
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License (version 2) as published by the
|
||||
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
||||
|
||||
>>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
|
||||
distribute a combined work that includes FreeRTOS without being obliged to
|
||||
provide the source code for proprietary components outside of the FreeRTOS
|
||||
kernel.
|
||||
|
||||
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details. You should have received a copy of the GNU General Public License
|
||||
and the FreeRTOS license exception along with FreeRTOS; if not itcan be
|
||||
viewed here: http://www.freertos.org/a00114.html and also obtained by
|
||||
writing to Real Time Engineers Ltd., contact details for whom are available
|
||||
on the FreeRTOS WEB site.
|
||||
|
||||
1 tab == 4 spaces!
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* Having a problem? Start by reading the FAQ "My application does *
|
||||
* not run, what could be wrong?" *
|
||||
* *
|
||||
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
|
||||
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||
license and Real Time Engineers Ltd. contact details.
|
||||
|
||||
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||
including FreeRTOS+Trace - an indispensable productivity tool, and our new
|
||||
fully thread aware and reentrant UDP/IP stack.
|
||||
|
||||
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||
Integrity Systems, who sell the code with commercial support,
|
||||
indemnification and middleware, under the OpenRTOS brand.
|
||||
|
||||
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||
engineered and independently SIL3 certified version for use in safety and
|
||||
mission critical applications that require provable dependability.
|
||||
*/
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
/* Standard includes. */
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* FreeRTOS+CLI includes. */
|
||||
#include "FreeRTOS_CLI.h"
|
||||
|
||||
/* File system includes. */
|
||||
#include "fat_sl.h"
|
||||
#include "api_mdriver_ram.h"
|
||||
|
||||
#ifdef _WINDOWS_
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#define cliNEW_LINE "\r\n"
|
||||
|
||||
/*******************************************************************************
|
||||
* See the URL in the comments within main.c for the location of the online
|
||||
* documentation.
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* Print out information on a single file.
|
||||
*/
|
||||
static void prvCreateFileInfoString( int8_t *pcBuffer, F_FIND *pxFindStruct );
|
||||
|
||||
/*
|
||||
* Copies an existing file into a newly created file.
|
||||
*/
|
||||
static portBASE_TYPE prvPerformCopy( int8_t *pcSourceFile,
|
||||
int32_t lSourceFileLength,
|
||||
int8_t *pcDestinationFile,
|
||||
int8_t *pxWriteBuffer,
|
||||
size_t xWriteBufferLen );
|
||||
|
||||
/*
|
||||
* Implements the DIR command.
|
||||
*/
|
||||
static portBASE_TYPE prvDIRCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the CD command.
|
||||
*/
|
||||
static portBASE_TYPE prvCDCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the DEL command.
|
||||
*/
|
||||
static portBASE_TYPE prvDELCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the TYPE command.
|
||||
*/
|
||||
static portBASE_TYPE prvTYPECommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the COPY command.
|
||||
*/
|
||||
static portBASE_TYPE prvCOPYCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/* Structure that defines the DIR command line command, which lists all the
|
||||
files in the current directory. */
|
||||
static const CLI_Command_Definition_t xDIR =
|
||||
{
|
||||
( const int8_t * const ) "dir", /* The command string to type. */
|
||||
( const int8_t * const ) "\r\ndir:\r\n Lists the files in the current directory\r\n",
|
||||
prvDIRCommand, /* The function to run. */
|
||||
0 /* No parameters are expected. */
|
||||
};
|
||||
|
||||
/* Structure that defines the CD command line command, which changes the
|
||||
working directory. */
|
||||
static const CLI_Command_Definition_t xCD =
|
||||
{
|
||||
( const int8_t * const ) "cd", /* The command string to type. */
|
||||
( const int8_t * const ) "\r\ncd <dir name>:\r\n Changes the working directory\r\n",
|
||||
prvCDCommand, /* The function to run. */
|
||||
1 /* One parameter is expected. */
|
||||
};
|
||||
|
||||
/* Structure that defines the TYPE command line command, which prints the
|
||||
contents of a file to the console. */
|
||||
static const CLI_Command_Definition_t xTYPE =
|
||||
{
|
||||
( const int8_t * const ) "type", /* The command string to type. */
|
||||
( const int8_t * const ) "\r\ntype <filename>:\r\n Prints file contents to the terminal\r\n",
|
||||
prvTYPECommand, /* The function to run. */
|
||||
1 /* One parameter is expected. */
|
||||
};
|
||||
|
||||
/* Structure that defines the DEL command line command, which deletes a file. */
|
||||
static const CLI_Command_Definition_t xDEL =
|
||||
{
|
||||
( const int8_t * const ) "del", /* The command string to type. */
|
||||
( const int8_t * const ) "\r\ndel <filename>:\r\n deletes a file or directory\r\n",
|
||||
prvDELCommand, /* The function to run. */
|
||||
1 /* One parameter is expected. */
|
||||
};
|
||||
|
||||
/* Structure that defines the COPY command line command, which deletes a file. */
|
||||
static const CLI_Command_Definition_t xCOPY =
|
||||
{
|
||||
( const int8_t * const ) "copy", /* The command string to type. */
|
||||
( const int8_t * const ) "\r\ncopy <source file> <dest file>:\r\n Copies <source file> to <dest file>\r\n",
|
||||
prvCOPYCommand, /* The function to run. */
|
||||
2 /* Two parameters are expected. */
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vRegisterFileSystemCLICommands( void )
|
||||
{
|
||||
/* Register all the command line commands defined immediately above. */
|
||||
FreeRTOS_CLIRegisterCommand( &xDIR );
|
||||
FreeRTOS_CLIRegisterCommand( &xCD );
|
||||
FreeRTOS_CLIRegisterCommand( &xTYPE );
|
||||
FreeRTOS_CLIRegisterCommand( &xDEL );
|
||||
FreeRTOS_CLIRegisterCommand( &xCOPY );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portBASE_TYPE prvTYPECommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
int8_t *pcParameter;
|
||||
portBASE_TYPE xParameterStringLength, xReturn = pdTRUE;
|
||||
static F_FILE *pxFile = NULL;
|
||||
int iChar;
|
||||
size_t xByte;
|
||||
size_t xColumns = 50U;
|
||||
|
||||
/* Ensure there is always a null terminator after each character written. */
|
||||
memset( pcWriteBuffer, 0x00, xWriteBufferLen );
|
||||
|
||||
/* Ensure the buffer leaves space for the \r\n. */
|
||||
configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
|
||||
xWriteBufferLen -= strlen( cliNEW_LINE );
|
||||
|
||||
if( xWriteBufferLen < xColumns )
|
||||
{
|
||||
/* Ensure the loop that uses xColumns as an end condition does not
|
||||
write off the end of the buffer. */
|
||||
xColumns = xWriteBufferLen;
|
||||
}
|
||||
|
||||
if( pxFile == NULL )
|
||||
{
|
||||
/* The file has not been opened yet. Find the file name. */
|
||||
pcParameter = ( int8_t * ) FreeRTOS_CLIGetParameter
|
||||
(
|
||||
pcCommandString, /* The command string itself. */
|
||||
1, /* Return the first parameter. */
|
||||
&xParameterStringLength /* Store the parameter string length. */
|
||||
);
|
||||
|
||||
/* Sanity check something was returned. */
|
||||
configASSERT( pcParameter );
|
||||
|
||||
/* Attempt to open the requested file. */
|
||||
pxFile = f_open( ( const char * ) pcParameter, "r" );
|
||||
}
|
||||
|
||||
if( pxFile != NULL )
|
||||
{
|
||||
/* Read the next chunk of data from the file. */
|
||||
for( xByte = 0; xByte < xColumns; xByte++ )
|
||||
{
|
||||
iChar = f_getc( pxFile );
|
||||
|
||||
if( iChar == -1 )
|
||||
{
|
||||
/* No more characters to return. */
|
||||
f_close( pxFile );
|
||||
pxFile = NULL;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
pcWriteBuffer[ xByte ] = ( int8_t ) iChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( pxFile == NULL )
|
||||
{
|
||||
/* Either the file was not opened, or all the data from the file has
|
||||
been returned and the file is now closed. */
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
|
||||
strcat( ( char * ) pcWriteBuffer, cliNEW_LINE );
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portBASE_TYPE prvCDCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
int8_t *pcParameter;
|
||||
portBASE_TYPE xParameterStringLength;
|
||||
unsigned char ucReturned;
|
||||
size_t xStringLength;
|
||||
|
||||
/* Obtain the parameter string. */
|
||||
pcParameter = ( int8_t * ) FreeRTOS_CLIGetParameter
|
||||
(
|
||||
pcCommandString, /* The command string itself. */
|
||||
1, /* Return the first parameter. */
|
||||
&xParameterStringLength /* Store the parameter string length. */
|
||||
);
|
||||
|
||||
/* Sanity check something was returned. */
|
||||
configASSERT( pcParameter );
|
||||
|
||||
/* Attempt to move to the requested directory. */
|
||||
ucReturned = f_chdir( ( char * ) pcParameter );
|
||||
|
||||
if( ucReturned == F_NO_ERROR )
|
||||
{
|
||||
sprintf( ( char * ) pcWriteBuffer, "In: " );
|
||||
xStringLength = strlen( ( const char * ) pcWriteBuffer );
|
||||
f_getcwd( ( char * ) &( pcWriteBuffer[ xStringLength ] ), ( unsigned char ) ( xWriteBufferLen - xStringLength ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( ( char * ) pcWriteBuffer, "Error" );
|
||||
}
|
||||
|
||||
strcat( ( char * ) pcWriteBuffer, cliNEW_LINE );
|
||||
|
||||
return pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portBASE_TYPE prvDIRCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
static F_FIND *pxFindStruct = NULL;
|
||||
unsigned char ucReturned;
|
||||
portBASE_TYPE xReturn = pdFALSE;
|
||||
|
||||
/* This assumes pcWriteBuffer is long enough. */
|
||||
( void ) pcCommandString;
|
||||
|
||||
/* Ensure the buffer leaves space for the \r\n. */
|
||||
configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
|
||||
xWriteBufferLen -= strlen( cliNEW_LINE );
|
||||
|
||||
if( pxFindStruct == NULL )
|
||||
{
|
||||
/* This is the first time this function has been executed since the Dir
|
||||
command was run. Create the find structure. */
|
||||
pxFindStruct = ( F_FIND * ) pvPortMalloc( sizeof( F_FIND ) );
|
||||
|
||||
if( pxFindStruct != NULL )
|
||||
{
|
||||
ucReturned = f_findfirst( "*.*", pxFindStruct );
|
||||
|
||||
if( ucReturned == F_NO_ERROR )
|
||||
{
|
||||
prvCreateFileInfoString( pcWriteBuffer, pxFindStruct );
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf( ( char * ) pcWriteBuffer, xWriteBufferLen, "Error: f_findfirst() failed." );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf( ( char * ) pcWriteBuffer, xWriteBufferLen, "Failed to allocate RAM (using heap_4.c will prevent fragmentation)." );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The find struct has already been created. Find the next file in
|
||||
the directory. */
|
||||
ucReturned = f_findnext( pxFindStruct );
|
||||
|
||||
if( ucReturned == F_NO_ERROR )
|
||||
{
|
||||
prvCreateFileInfoString( pcWriteBuffer, pxFindStruct );
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* There are no more files. Free the find structure. */
|
||||
vPortFree( pxFindStruct );
|
||||
pxFindStruct = NULL;
|
||||
|
||||
/* No string to return. */
|
||||
pcWriteBuffer[ 0 ] = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
strcat( ( char * ) pcWriteBuffer, cliNEW_LINE );
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portBASE_TYPE prvDELCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
int8_t *pcParameter;
|
||||
portBASE_TYPE xParameterStringLength;
|
||||
unsigned char ucReturned;
|
||||
|
||||
/* This function assumes xWriteBufferLen is large enough! */
|
||||
( void ) xWriteBufferLen;
|
||||
|
||||
/* Obtain the parameter string. */
|
||||
pcParameter = ( int8_t * ) FreeRTOS_CLIGetParameter
|
||||
(
|
||||
pcCommandString, /* The command string itself. */
|
||||
1, /* Return the first parameter. */
|
||||
&xParameterStringLength /* Store the parameter string length. */
|
||||
);
|
||||
|
||||
/* Sanity check something was returned. */
|
||||
configASSERT( pcParameter );
|
||||
|
||||
/* Attempt to delete the file. */
|
||||
ucReturned = f_delete( ( const char * ) pcParameter );
|
||||
|
||||
if( ucReturned == F_NO_ERROR )
|
||||
{
|
||||
sprintf( ( char * ) pcWriteBuffer, "%s was deleted", pcParameter );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( ( char * ) pcWriteBuffer, "Error" );
|
||||
}
|
||||
|
||||
strcat( ( char * ) pcWriteBuffer, cliNEW_LINE );
|
||||
|
||||
return pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portBASE_TYPE prvCOPYCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
int8_t *pcSourceFile, *pcDestinationFile;
|
||||
portBASE_TYPE xParameterStringLength;
|
||||
long lSourceLength, lDestinationLength = 0;
|
||||
|
||||
/* Obtain the name of the destination file. */
|
||||
pcDestinationFile = ( int8_t * ) FreeRTOS_CLIGetParameter
|
||||
(
|
||||
pcCommandString, /* The command string itself. */
|
||||
2, /* Return the second parameter. */
|
||||
&xParameterStringLength /* Store the parameter string length. */
|
||||
);
|
||||
|
||||
/* Sanity check something was returned. */
|
||||
configASSERT( pcDestinationFile );
|
||||
|
||||
/* Obtain the name of the source file. */
|
||||
pcSourceFile = ( int8_t * ) FreeRTOS_CLIGetParameter
|
||||
(
|
||||
pcCommandString, /* The command string itself. */
|
||||
1, /* Return the first parameter. */
|
||||
&xParameterStringLength /* Store the parameter string length. */
|
||||
);
|
||||
|
||||
/* Sanity check something was returned. */
|
||||
configASSERT( pcSourceFile );
|
||||
|
||||
/* Terminate the string. */
|
||||
pcSourceFile[ xParameterStringLength ] = 0x00;
|
||||
|
||||
/* See if the source file exists, obtain its length if it does. */
|
||||
lSourceLength = f_filelength( ( const char * ) pcSourceFile );
|
||||
|
||||
if( lSourceLength == 0 )
|
||||
{
|
||||
sprintf( ( char * ) pcWriteBuffer, "Source file does not exist" );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* See if the destination file exists. */
|
||||
lDestinationLength = f_filelength( ( const char * ) pcDestinationFile );
|
||||
|
||||
if( lDestinationLength != 0 )
|
||||
{
|
||||
sprintf( ( char * ) pcWriteBuffer, "Error: Destination file already exists" );
|
||||
}
|
||||
}
|
||||
|
||||
/* Continue only if the source file exists and the destination file does
|
||||
not exist. */
|
||||
if( ( lSourceLength != 0 ) && ( lDestinationLength == 0 ) )
|
||||
{
|
||||
if( prvPerformCopy( pcSourceFile, lSourceLength, pcDestinationFile, pcWriteBuffer, xWriteBufferLen ) == pdPASS )
|
||||
{
|
||||
sprintf( ( char * ) pcWriteBuffer, "Copy made" );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( ( char * ) pcWriteBuffer, "Error during copy" );
|
||||
}
|
||||
}
|
||||
|
||||
strcat( ( char * ) pcWriteBuffer, cliNEW_LINE );
|
||||
|
||||
return pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portBASE_TYPE prvPerformCopy( int8_t *pcSourceFile,
|
||||
int32_t lSourceFileLength,
|
||||
int8_t *pcDestinationFile,
|
||||
int8_t *pxWriteBuffer,
|
||||
size_t xWriteBufferLen )
|
||||
{
|
||||
int32_t lBytesRead = 0, lBytesToRead, lBytesRemaining;
|
||||
F_FILE *pxFile;
|
||||
portBASE_TYPE xReturn = pdPASS;
|
||||
|
||||
/* NOTE: Error handling has been omitted for clarity. */
|
||||
|
||||
while( lBytesRead < lSourceFileLength )
|
||||
{
|
||||
/* How many bytes are left? */
|
||||
lBytesRemaining = lSourceFileLength - lBytesRead;
|
||||
|
||||
/* How many bytes should be read this time around the loop. Can't
|
||||
read more bytes than will fit into the buffer. */
|
||||
if( lBytesRemaining > ( long ) xWriteBufferLen )
|
||||
{
|
||||
lBytesToRead = ( long ) xWriteBufferLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
lBytesToRead = lBytesRemaining;
|
||||
}
|
||||
|
||||
/* Open the source file, seek past the data that has already been
|
||||
read from the file, read the next block of data, then close the
|
||||
file again so the destination file can be opened. */
|
||||
pxFile = f_open( ( const char * ) pcSourceFile, "r" );
|
||||
if( pxFile != NULL )
|
||||
{
|
||||
f_seek( pxFile, lBytesRead, F_SEEK_SET );
|
||||
f_read( pxWriteBuffer, lBytesToRead, 1, pxFile );
|
||||
f_close( pxFile );
|
||||
}
|
||||
else
|
||||
{
|
||||
xReturn = pdFAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Open the destination file and write the block of data to the end of
|
||||
the file. */
|
||||
pxFile = f_open( ( const char * ) pcDestinationFile, "a" );
|
||||
if( pxFile != NULL )
|
||||
{
|
||||
f_write( pxWriteBuffer, lBytesToRead, 1, pxFile );
|
||||
f_close( pxFile );
|
||||
}
|
||||
else
|
||||
{
|
||||
xReturn = pdFAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
lBytesRead += lBytesToRead;
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvCreateFileInfoString( int8_t *pcBuffer, F_FIND *pxFindStruct )
|
||||
{
|
||||
const char *pcWritableFile = "writable file", *pcReadOnlyFile = "read only file", *pcDirectory = "directory";
|
||||
const char * pcAttrib;
|
||||
|
||||
/* Point pcAttrib to a string that describes the file. */
|
||||
if( ( pxFindStruct->attr & F_ATTR_DIR ) != 0 )
|
||||
{
|
||||
pcAttrib = pcDirectory;
|
||||
}
|
||||
else if( pxFindStruct->attr & F_ATTR_READONLY )
|
||||
{
|
||||
pcAttrib = pcReadOnlyFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
pcAttrib = pcWritableFile;
|
||||
}
|
||||
|
||||
/* Create a string that includes the file name, the file size and the
|
||||
attributes string. */
|
||||
sprintf( ( char * ) pcBuffer, "%s [%s] [size=%d]", pxFindStruct->filename, pcAttrib, pxFindStruct->filesize );
|
||||
}
|
@ -0,0 +1,383 @@
|
||||
/*
|
||||
FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||
|
||||
FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
|
||||
http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* FreeRTOS tutorial books are available in pdf and paperback. *
|
||||
* Complete, revised, and edited pdf reference manuals are also *
|
||||
* available. *
|
||||
* *
|
||||
* Purchasing FreeRTOS documentation will not only help you, by *
|
||||
* ensuring you get running as quickly as possible and with an *
|
||||
* in-depth knowledge of how to use FreeRTOS, it will also help *
|
||||
* the FreeRTOS project to continue with its mission of providing *
|
||||
* professional grade, cross platform, de facto standard solutions *
|
||||
* for microcontrollers - completely free of charge! *
|
||||
* *
|
||||
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
|
||||
* *
|
||||
* Thank you for using FreeRTOS, and thank you for your support! *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
|
||||
This file is part of the FreeRTOS distribution.
|
||||
|
||||
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License (version 2) as published by the
|
||||
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
||||
|
||||
>>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
|
||||
distribute a combined work that includes FreeRTOS without being obliged to
|
||||
provide the source code for proprietary components outside of the FreeRTOS
|
||||
kernel.
|
||||
|
||||
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details. You should have received a copy of the GNU General Public License
|
||||
and the FreeRTOS license exception along with FreeRTOS; if not itcan be
|
||||
viewed here: http://www.freertos.org/a00114.html and also obtained by
|
||||
writing to Real Time Engineers Ltd., contact details for whom are available
|
||||
on the FreeRTOS WEB site.
|
||||
|
||||
1 tab == 4 spaces!
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* Having a problem? Start by reading the FAQ "My application does *
|
||||
* not run, what could be wrong?" *
|
||||
* *
|
||||
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
|
||||
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||
license and Real Time Engineers Ltd. contact details.
|
||||
|
||||
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||
including FreeRTOS+Trace - an indispensable productivity tool, and our new
|
||||
fully thread aware and reentrant UDP/IP stack.
|
||||
|
||||
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||
Integrity Systems, who sell the code with commercial support,
|
||||
indemnification and middleware, under the OpenRTOS brand.
|
||||
|
||||
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||
engineered and independently SIL3 certified version for use in safety and
|
||||
mission critical applications that require provable dependability.
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* See the URL in the comments within main.c for the location of the online
|
||||
* documentation.
|
||||
******************************************************************************/
|
||||
|
||||
/* Standard includes. */
|
||||
#include <stdio.h>
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
/* File system includes. */
|
||||
#include "fat_sl.h"
|
||||
#include "api_mdriver_ram.h"
|
||||
|
||||
/* 8.3 format, plus null terminator. */
|
||||
#define fsMAX_FILE_NAME_LEN 13
|
||||
|
||||
/* The number of bytes read/written to the example files at a time. */
|
||||
#define fsRAM_BUFFER_SIZE 200
|
||||
|
||||
/* The number of bytes written to the file that uses f_putc() and f_getc(). */
|
||||
#define fsPUTC_FILE_SIZE 100
|
||||
|
||||
/* The number of files created in root. */
|
||||
#define fsROOT_FILES 3
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* Creates and verifies different files on the volume, demonstrating the use of
|
||||
* various different API functions.
|
||||
*/
|
||||
void vCreateAndVerifySampleFiles( void );
|
||||
|
||||
/*
|
||||
* Create a set of example files in the root directory of the volume using
|
||||
* f_write().
|
||||
*/
|
||||
static void prvCreateDemoFilesUsing_f_write( void );
|
||||
|
||||
/*
|
||||
* Use f_read() to read back and verify the files that were created by
|
||||
* prvCreateDemoFilesUsing_f_write().
|
||||
*/
|
||||
static void prvVerifyDemoFileUsing_f_read( void );
|
||||
|
||||
/*
|
||||
* Create an example file in a sub-directory using f_putc().
|
||||
*/
|
||||
static void prvCreateDemoFileUsing_f_putc( void );
|
||||
|
||||
/*
|
||||
* Use f_getc() to read back and verify the file that was created by
|
||||
* prvCreateDemoFileUsing_f_putc().
|
||||
*/
|
||||
static void prvVerifyDemoFileUsing_f_getc( void );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* A buffer used to both create content to write to disk, and read content back
|
||||
from a disk. Note there is no mutual exclusion on this buffer. */
|
||||
static char cRAMBuffer[ fsRAM_BUFFER_SIZE ];
|
||||
|
||||
/* Names of directories that are created. */
|
||||
static const char *pcRoot = "/", *pcDirectory1 = "SUB1", *pcDirectory2 = "SUB2", *pcFullPath = "/SUB1/SUB2";
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vCreateAndVerifySampleFiles( void )
|
||||
{
|
||||
unsigned char ucStatus;
|
||||
|
||||
/* First create the volume. */
|
||||
ucStatus = f_initvolume( ram_initfunc );
|
||||
|
||||
/* It is expected that the volume is not formatted. */
|
||||
if( ucStatus == F_ERR_NOTFORMATTED )
|
||||
{
|
||||
/* Format the created volume. */
|
||||
ucStatus = f_format( F_FAT12_MEDIA );
|
||||
}
|
||||
|
||||
if( ucStatus == F_NO_ERROR )
|
||||
{
|
||||
/* Create a set of files using f_write(). */
|
||||
prvCreateDemoFilesUsing_f_write();
|
||||
|
||||
/* Read back and verify the files that were created using f_write(). */
|
||||
prvVerifyDemoFileUsing_f_read();
|
||||
|
||||
/* Create sub directories two deep then create a file using putc. */
|
||||
prvCreateDemoFileUsing_f_putc();
|
||||
|
||||
/* Read back and verify the file created by
|
||||
prvCreateDemoFileUsing_f_putc(). */
|
||||
prvVerifyDemoFileUsing_f_getc();
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvCreateDemoFilesUsing_f_write( void )
|
||||
{
|
||||
portBASE_TYPE xFileNumber, xWriteNumber;
|
||||
char cFileName[ fsMAX_FILE_NAME_LEN ];
|
||||
long lItemsWritten;
|
||||
F_FILE *pxFile;
|
||||
|
||||
/* Create fsROOT_FILES files. Each created file will be
|
||||
( xFileNumber * fsRAM_BUFFER_SIZE ) bytes in length, and filled
|
||||
with a different repeating character. */
|
||||
for( xFileNumber = 1; xFileNumber <= fsROOT_FILES; xFileNumber++ )
|
||||
{
|
||||
/* Generate a file name. */
|
||||
sprintf( cFileName, "root%03d.txt", xFileNumber );
|
||||
|
||||
/* Obtain the current working directory and print out the file name and
|
||||
the directory into which the file is being written. */
|
||||
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
|
||||
printf( "Creating file %s in %s\r\n", cFileName, cRAMBuffer );
|
||||
|
||||
/* Open the file, creating the file if it does not already exist. */
|
||||
pxFile = f_open( cFileName, "w" );
|
||||
configASSERT( pxFile );
|
||||
|
||||
/* Fill the RAM buffer with data that will be written to the file. This
|
||||
is just a repeating ascii character that indicates the file number. */
|
||||
memset( cRAMBuffer, ( int ) ( '0' + xFileNumber ), fsRAM_BUFFER_SIZE );
|
||||
|
||||
/* Write the RAM buffer to the opened file a number of times. The
|
||||
number of times the RAM buffer is written to the file depends on the
|
||||
file number, so the length of each created file will be different. */
|
||||
for( xWriteNumber = 0; xWriteNumber < xFileNumber; xWriteNumber++ )
|
||||
{
|
||||
lItemsWritten = f_write( cRAMBuffer, fsRAM_BUFFER_SIZE, 1, pxFile );
|
||||
configASSERT( lItemsWritten == 1 );
|
||||
}
|
||||
|
||||
/* Close the file so another file can be created. */
|
||||
f_close( pxFile );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvVerifyDemoFileUsing_f_read( void )
|
||||
{
|
||||
portBASE_TYPE xFileNumber, xReadNumber;
|
||||
char cFileName[ fsMAX_FILE_NAME_LEN ];
|
||||
long lItemsRead, lChar;
|
||||
F_FILE *pxFile;
|
||||
|
||||
/* Read back the files that were created by
|
||||
prvCreateDemoFilesUsing_f_write(). */
|
||||
for( xFileNumber = 1; xFileNumber <= fsROOT_FILES; xFileNumber++ )
|
||||
{
|
||||
/* Generate the file name. */
|
||||
sprintf( cFileName, "root%03d.txt", xFileNumber );
|
||||
|
||||
/* Obtain the current working directory and print out the file name and
|
||||
the directory from which the file is being read. */
|
||||
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
|
||||
printf( "Reading file %s from %s\r\n", cFileName, cRAMBuffer );
|
||||
|
||||
/* Open the file for reading. */
|
||||
pxFile = f_open( cFileName, "r" );
|
||||
configASSERT( pxFile );
|
||||
|
||||
/* Read the file into the RAM buffer, checking the file contents are as
|
||||
expected. The size of the file depends on the file number. */
|
||||
for( xReadNumber = 0; xReadNumber < xFileNumber; xReadNumber++ )
|
||||
{
|
||||
/* Start with the RAM buffer clear. */
|
||||
memset( cRAMBuffer, 0x00, fsRAM_BUFFER_SIZE );
|
||||
|
||||
lItemsRead = f_read( cRAMBuffer, fsRAM_BUFFER_SIZE, 1, pxFile );
|
||||
configASSERT( lItemsRead == 1 );
|
||||
|
||||
/* Check the RAM buffer is filled with the expected data. Each
|
||||
file contains a different repeating ascii character that indicates
|
||||
the number of the file. */
|
||||
for( lChar = 0; lChar < fsRAM_BUFFER_SIZE; lChar++ )
|
||||
{
|
||||
configASSERT( cRAMBuffer[ lChar ] == ( '0' + ( char ) xFileNumber ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Close the file. */
|
||||
f_close( pxFile );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvCreateDemoFileUsing_f_putc( void )
|
||||
{
|
||||
unsigned char ucReturn;
|
||||
int iByte, iReturned;
|
||||
F_FILE *pxFile;
|
||||
char cFileName[ fsMAX_FILE_NAME_LEN ];
|
||||
|
||||
/* Obtain and print out the working directory. */
|
||||
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
|
||||
printf( "In directory %s\r\n", cRAMBuffer );
|
||||
|
||||
/* Create a sub directory. */
|
||||
ucReturn = f_mkdir( pcDirectory1 );
|
||||
configASSERT( ucReturn == F_NO_ERROR );
|
||||
|
||||
/* Move into the created sub-directory. */
|
||||
ucReturn = f_chdir( pcDirectory1 );
|
||||
configASSERT( ucReturn == F_NO_ERROR );
|
||||
|
||||
/* Obtain and print out the working directory. */
|
||||
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
|
||||
printf( "In directory %s\r\n", cRAMBuffer );
|
||||
|
||||
/* Create a subdirectory in the new directory. */
|
||||
ucReturn = f_mkdir( pcDirectory2 );
|
||||
configASSERT( ucReturn == F_NO_ERROR );
|
||||
|
||||
/* Move into the directory just created - now two directories down from
|
||||
the root. */
|
||||
ucReturn = f_chdir( pcDirectory2 );
|
||||
configASSERT( ucReturn == F_NO_ERROR );
|
||||
|
||||
/* Obtain and print out the working directory. */
|
||||
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
|
||||
printf( "In directory %s\r\n", cRAMBuffer );
|
||||
configASSERT( strcmp( ( const char * ) cRAMBuffer, pcFullPath ) == 0 );
|
||||
|
||||
/* Generate the file name. */
|
||||
sprintf( cFileName, "%s.txt", pcDirectory2 );
|
||||
|
||||
/* Print out the file name and the directory into which the file is being
|
||||
written. */
|
||||
printf( "Writing file %s in %s\r\n", cFileName, cRAMBuffer );
|
||||
|
||||
pxFile = f_open( cFileName, "w" );
|
||||
|
||||
/* Create a file 1 byte at a time. The file is filled with incrementing
|
||||
ascii characters starting from '0'. */
|
||||
for( iByte = 0; iByte < fsPUTC_FILE_SIZE; iByte++ )
|
||||
{
|
||||
iReturned = f_putc( ( ( int ) '0' + iByte ), pxFile );
|
||||
configASSERT( iReturned == ( ( int ) '0' + iByte ) );
|
||||
}
|
||||
|
||||
/* Finished so close the file. */
|
||||
f_close( pxFile );
|
||||
|
||||
/* Move back to the root directory. */
|
||||
ucReturn = f_chdir( "../.." );
|
||||
configASSERT( ucReturn == F_NO_ERROR );
|
||||
|
||||
/* Obtain and print out the working directory. */
|
||||
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
|
||||
printf( "Back in root directory %s\r\n", cRAMBuffer );
|
||||
configASSERT( strcmp( ( const char * ) cRAMBuffer, pcRoot ) == 0 );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvVerifyDemoFileUsing_f_getc( void )
|
||||
{
|
||||
unsigned char ucReturn;
|
||||
int iByte, iReturned;
|
||||
F_FILE *pxFile;
|
||||
char cFileName[ fsMAX_FILE_NAME_LEN ];
|
||||
|
||||
/* Move into the directory in which the file was created. */
|
||||
ucReturn = f_chdir( pcFullPath );
|
||||
configASSERT( ucReturn == F_NO_ERROR );
|
||||
|
||||
/* Obtain and print out the working directory. */
|
||||
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
|
||||
printf( "Back in directory %s\r\n", cRAMBuffer );
|
||||
configASSERT( strcmp( ( const char * ) cRAMBuffer, pcFullPath ) == 0 );
|
||||
|
||||
/* Generate the file name. */
|
||||
sprintf( cFileName, "%s.txt", pcDirectory2 );
|
||||
|
||||
/* Print out the file name and the directory from which the file is being
|
||||
read. */
|
||||
printf( "Reading file %s in %s\r\n", cFileName, cRAMBuffer );
|
||||
|
||||
/* This time the file is opened for reading. */
|
||||
pxFile = f_open( cFileName, "r" );
|
||||
|
||||
/* Read the file 1 byte at a time. */
|
||||
for( iByte = 0; iByte < fsPUTC_FILE_SIZE; iByte++ )
|
||||
{
|
||||
iReturned = f_getc( pxFile );
|
||||
configASSERT( iReturned == ( ( int ) '0' + iByte ) );
|
||||
}
|
||||
|
||||
/* Finished so close the file. */
|
||||
f_close( pxFile );
|
||||
|
||||
/* Move back to the root directory. */
|
||||
ucReturn = f_chdir( "../.." );
|
||||
configASSERT( ucReturn == F_NO_ERROR );
|
||||
|
||||
/* Obtain and print out the working directory. */
|
||||
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
|
||||
printf( "Back in root directory %s\r\n", cRAMBuffer );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
Contains source and header files that implement FreeRTOS+CLI. See
|
||||
http://www.FreeRTOS.org/cli for documentation and license information.
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
Run the CreateProjectDirectoryStructure.bat batch file to populate this directory before building the demo.
|
@ -0,0 +1 @@
|
||||
Run the CreateProjectDirectoryStructure.bat batch file to populate this directory before building the demo.
|
@ -0,0 +1,426 @@
|
||||
/*
|
||||
FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||
|
||||
FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
|
||||
http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* FreeRTOS tutorial books are available in pdf and paperback. *
|
||||
* Complete, revised, and edited pdf reference manuals are also *
|
||||
* available. *
|
||||
* *
|
||||
* Purchasing FreeRTOS documentation will not only help you, by *
|
||||
* ensuring you get running as quickly as possible and with an *
|
||||
* in-depth knowledge of how to use FreeRTOS, it will also help *
|
||||
* the FreeRTOS project to continue with its mission of providing *
|
||||
* professional grade, cross platform, de facto standard solutions *
|
||||
* for microcontrollers - completely free of charge! *
|
||||
* *
|
||||
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
|
||||
* *
|
||||
* Thank you for using FreeRTOS, and thank you for your support! *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
|
||||
This file is part of the FreeRTOS distribution.
|
||||
|
||||
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License (version 2) as published by the
|
||||
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
||||
|
||||
>>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
|
||||
distribute a combined work that includes FreeRTOS without being obliged to
|
||||
provide the source code for proprietary components outside of the FreeRTOS
|
||||
kernel.
|
||||
|
||||
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details. You should have received a copy of the GNU General Public License
|
||||
and the FreeRTOS license exception along with FreeRTOS; if not itcan be
|
||||
viewed here: http://www.freertos.org/a00114.html and also obtained by
|
||||
writing to Real Time Engineers Ltd., contact details for whom are available
|
||||
on the FreeRTOS WEB site.
|
||||
|
||||
1 tab == 4 spaces!
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* Having a problem? Start by reading the FAQ "My application does *
|
||||
* not run, what could be wrong?" *
|
||||
* *
|
||||
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
|
||||
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||
license and Real Time Engineers Ltd. contact details.
|
||||
|
||||
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||
including FreeRTOS+Trace - an indispensable productivity tool, and our new
|
||||
fully thread aware and reentrant UDP/IP stack.
|
||||
|
||||
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||
Integrity Systems, who sell the code with commercial support,
|
||||
indemnification and middleware, under the OpenRTOS brand.
|
||||
|
||||
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||
engineered and independently SIL3 certified version for use in safety and
|
||||
mission critical applications that require provable dependability.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* See the following URL for information on the commands defined in this file:
|
||||
* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
/* Standard includes. */
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* FreeRTOS+CLI includes. */
|
||||
#include "FreeRTOS_CLI.h"
|
||||
|
||||
#ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
|
||||
#define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Implements the run-time-stats command.
|
||||
*/
|
||||
static portBASE_TYPE prvTaskStatsCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the task-stats command.
|
||||
*/
|
||||
static portBASE_TYPE prvRunTimeStatsCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the echo-three-parameters command.
|
||||
*/
|
||||
static portBASE_TYPE prvThreeParameterEchoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the echo-parameters command.
|
||||
*/
|
||||
static portBASE_TYPE prvParameterEchoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the "trace start" and "trace stop" commands;
|
||||
*/
|
||||
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
|
||||
static portBASE_TYPE prvStartStopTraceCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
#endif
|
||||
|
||||
/* Structure that defines the "run-time-stats" command line command. This
|
||||
generates a table that shows how much run time each task has */
|
||||
static const CLI_Command_Definition_t xRunTimeStats =
|
||||
{
|
||||
( const int8_t * const ) "run-time-stats", /* The command string to type. */
|
||||
( const int8_t * const ) "\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
|
||||
prvRunTimeStatsCommand, /* The function to run. */
|
||||
0 /* No parameters are expected. */
|
||||
};
|
||||
|
||||
/* Structure that defines the "task-stats" command line command. This generates
|
||||
a table that gives information on each task in the system. */
|
||||
static const CLI_Command_Definition_t xTaskStats =
|
||||
{
|
||||
( const int8_t * const ) "task-stats", /* The command string to type. */
|
||||
( const int8_t * const ) "\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
|
||||
prvTaskStatsCommand, /* The function to run. */
|
||||
0 /* No parameters are expected. */
|
||||
};
|
||||
|
||||
/* Structure that defines the "echo_3_parameters" command line command. This
|
||||
takes exactly three parameters that the command simply echos back one at a
|
||||
time. */
|
||||
static const CLI_Command_Definition_t xThreeParameterEcho =
|
||||
{
|
||||
( const int8_t * const ) "echo-3-parameters",
|
||||
( const int8_t * const ) "\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
|
||||
prvThreeParameterEchoCommand, /* The function to run. */
|
||||
3 /* Three parameters are expected, which can take any value. */
|
||||
};
|
||||
|
||||
/* Structure that defines the "echo_parameters" command line command. This
|
||||
takes a variable number of parameters that the command simply echos back one at
|
||||
a time. */
|
||||
static const CLI_Command_Definition_t xParameterEcho =
|
||||
{
|
||||
( const int8_t * const ) "echo-parameters",
|
||||
( const int8_t * const ) "\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
|
||||
prvParameterEchoCommand, /* The function to run. */
|
||||
-1 /* The user can enter any number of commands. */
|
||||
};
|
||||
|
||||
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
|
||||
/* Structure that defines the "trace" command line command. This takes a single
|
||||
parameter, which can be either "start" or "stop". */
|
||||
static const CLI_Command_Definition_t xStartStopTrace =
|
||||
{
|
||||
( const int8_t * const ) "trace",
|
||||
( const int8_t * const ) "\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
|
||||
prvStartStopTraceCommand, /* The function to run. */
|
||||
1 /* One parameter is expected. Valid values are "start" and "stop". */
|
||||
};
|
||||
#endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vRegisterSampleCLICommands( void )
|
||||
{
|
||||
/* Register all the command line commands defined immediately above. */
|
||||
FreeRTOS_CLIRegisterCommand( &xTaskStats );
|
||||
FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
|
||||
FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
|
||||
FreeRTOS_CLIRegisterCommand( &xParameterEcho );
|
||||
|
||||
#if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
|
||||
{
|
||||
FreeRTOS_CLIRegisterCommand( & xStartStopTrace );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portBASE_TYPE prvTaskStatsCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
const int8_t *const pcHeader = ( int8_t * ) "Task State Priority Stack #\r\n************************************************\r\n";
|
||||
|
||||
/* Remove compile time warnings about unused parameters, and check the
|
||||
write buffer is not NULL. NOTE - for simplicity, this example assumes the
|
||||
write buffer length is adequate, so does not check for buffer overflows. */
|
||||
( void ) pcCommandString;
|
||||
( void ) xWriteBufferLen;
|
||||
configASSERT( pcWriteBuffer );
|
||||
|
||||
/* Generate a table of task stats. */
|
||||
strcpy( ( char * ) pcWriteBuffer, ( char * ) pcHeader );
|
||||
vTaskList( pcWriteBuffer + strlen( ( char * ) pcHeader ) );
|
||||
|
||||
/* There is no more data to return after this single string, so return
|
||||
pdFALSE. */
|
||||
return pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portBASE_TYPE prvRunTimeStatsCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
const int8_t * const pcHeader = ( int8_t * ) "Task Abs Time % Time\r\n****************************************\r\n";
|
||||
|
||||
/* Remove compile time warnings about unused parameters, and check the
|
||||
write buffer is not NULL. NOTE - for simplicity, this example assumes the
|
||||
write buffer length is adequate, so does not check for buffer overflows. */
|
||||
( void ) pcCommandString;
|
||||
( void ) xWriteBufferLen;
|
||||
configASSERT( pcWriteBuffer );
|
||||
|
||||
/* Generate a table of task stats. */
|
||||
strcpy( ( char * ) pcWriteBuffer, ( char * ) pcHeader );
|
||||
vTaskGetRunTimeStats( pcWriteBuffer + strlen( ( char * ) pcHeader ) );
|
||||
|
||||
/* There is no more data to return after this single string, so return
|
||||
pdFALSE. */
|
||||
return pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portBASE_TYPE prvThreeParameterEchoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
int8_t *pcParameter;
|
||||
portBASE_TYPE xParameterStringLength, xReturn;
|
||||
static portBASE_TYPE lParameterNumber = 0;
|
||||
|
||||
/* Remove compile time warnings about unused parameters, and check the
|
||||
write buffer is not NULL. NOTE - for simplicity, this example assumes the
|
||||
write buffer length is adequate, so does not check for buffer overflows. */
|
||||
( void ) pcCommandString;
|
||||
( void ) xWriteBufferLen;
|
||||
configASSERT( pcWriteBuffer );
|
||||
|
||||
if( lParameterNumber == 0 )
|
||||
{
|
||||
/* The first time the function is called after the command has been
|
||||
entered just a header string is returned. */
|
||||
sprintf( ( char * ) pcWriteBuffer, "The three parameters were:\r\n" );
|
||||
|
||||
/* Next time the function is called the first parameter will be echoed
|
||||
back. */
|
||||
lParameterNumber = 1L;
|
||||
|
||||
/* There is more data to be returned as no parameters have been echoed
|
||||
back yet. */
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Obtain the parameter string. */
|
||||
pcParameter = ( int8_t * ) FreeRTOS_CLIGetParameter
|
||||
(
|
||||
pcCommandString, /* The command string itself. */
|
||||
lParameterNumber, /* Return the next parameter. */
|
||||
&xParameterStringLength /* Store the parameter string length. */
|
||||
);
|
||||
|
||||
/* Sanity check something was returned. */
|
||||
configASSERT( pcParameter );
|
||||
|
||||
/* Return the parameter string. */
|
||||
memset( pcWriteBuffer, 0x00, xWriteBufferLen );
|
||||
sprintf( ( char * ) pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
|
||||
strncat( ( char * ) pcWriteBuffer, ( const char * ) pcParameter, xParameterStringLength );
|
||||
strncat( ( char * ) pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
|
||||
|
||||
/* If this is the last of the three parameters then there are no more
|
||||
strings to return after this one. */
|
||||
if( lParameterNumber == 3L )
|
||||
{
|
||||
/* If this is the last of the three parameters then there are no more
|
||||
strings to return after this one. */
|
||||
xReturn = pdFALSE;
|
||||
lParameterNumber = 0L;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* There are more parameters to return after this one. */
|
||||
xReturn = pdTRUE;
|
||||
lParameterNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portBASE_TYPE prvParameterEchoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
int8_t *pcParameter;
|
||||
portBASE_TYPE xParameterStringLength, xReturn;
|
||||
static portBASE_TYPE lParameterNumber = 0;
|
||||
|
||||
/* Remove compile time warnings about unused parameters, and check the
|
||||
write buffer is not NULL. NOTE - for simplicity, this example assumes the
|
||||
write buffer length is adequate, so does not check for buffer overflows. */
|
||||
( void ) pcCommandString;
|
||||
( void ) xWriteBufferLen;
|
||||
configASSERT( pcWriteBuffer );
|
||||
|
||||
if( lParameterNumber == 0 )
|
||||
{
|
||||
/* The first time the function is called after the command has been
|
||||
entered just a header string is returned. */
|
||||
sprintf( ( char * ) pcWriteBuffer, "The parameters were:\r\n" );
|
||||
|
||||
/* Next time the function is called the first parameter will be echoed
|
||||
back. */
|
||||
lParameterNumber = 1L;
|
||||
|
||||
/* There is more data to be returned as no parameters have been echoed
|
||||
back yet. */
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Obtain the parameter string. */
|
||||
pcParameter = ( int8_t * ) FreeRTOS_CLIGetParameter
|
||||
(
|
||||
pcCommandString, /* The command string itself. */
|
||||
lParameterNumber, /* Return the next parameter. */
|
||||
&xParameterStringLength /* Store the parameter string length. */
|
||||
);
|
||||
|
||||
if( pcParameter != NULL )
|
||||
{
|
||||
/* Return the parameter string. */
|
||||
memset( pcWriteBuffer, 0x00, xWriteBufferLen );
|
||||
sprintf( ( char * ) pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
|
||||
strncat( ( char * ) pcWriteBuffer, ( const char * ) pcParameter, xParameterStringLength );
|
||||
strncat( ( char * ) pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
|
||||
|
||||
/* There might be more parameters to return after this one. */
|
||||
xReturn = pdTRUE;
|
||||
lParameterNumber++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No more parameters were found. Make sure the write buffer does
|
||||
not contain a valid string. */
|
||||
pcWriteBuffer[ 0 ] = 0x00;
|
||||
|
||||
/* No more data to return. */
|
||||
xReturn = pdFALSE;
|
||||
|
||||
/* Start over the next time this command is executed. */
|
||||
lParameterNumber = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
|
||||
|
||||
static portBASE_TYPE prvStartStopTraceCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
int8_t *pcParameter;
|
||||
portBASE_TYPE lParameterStringLength;
|
||||
|
||||
/* Remove compile time warnings about unused parameters, and check the
|
||||
write buffer is not NULL. NOTE - for simplicity, this example assumes the
|
||||
write buffer length is adequate, so does not check for buffer overflows. */
|
||||
( void ) pcCommandString;
|
||||
( void ) xWriteBufferLen;
|
||||
configASSERT( pcWriteBuffer );
|
||||
|
||||
/* Obtain the parameter string. */
|
||||
pcParameter = ( int8_t * ) FreeRTOS_CLIGetParameter
|
||||
(
|
||||
pcCommandString, /* The command string itself. */
|
||||
1, /* Return the first parameter. */
|
||||
&lParameterStringLength /* Store the parameter string length. */
|
||||
);
|
||||
|
||||
/* Sanity check something was returned. */
|
||||
configASSERT( pcParameter );
|
||||
|
||||
/* There are only two valid parameter values. */
|
||||
if( strncmp( ( const char * ) pcParameter, "start", strlen( "start" ) ) == 0 )
|
||||
{
|
||||
/* Start or restart the trace. */
|
||||
vTraceStop();
|
||||
vTraceClear();
|
||||
vTraceStart();
|
||||
|
||||
sprintf( ( char * ) pcWriteBuffer, "Trace recording (re)started.\r\n" );
|
||||
}
|
||||
else if( strncmp( ( const char * ) pcParameter, "stop", strlen( "stop" ) ) == 0 )
|
||||
{
|
||||
/* End the trace, if one is running. */
|
||||
vTraceStop();
|
||||
sprintf( ( char * ) pcWriteBuffer, "Stopping trace recording.\r\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( ( char * ) pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
|
||||
}
|
||||
|
||||
/* There is no more data to return after this single string, so return
|
||||
pdFALSE. */
|
||||
return pdFALSE;
|
||||
}
|
||||
|
||||
#endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
|
@ -0,0 +1,208 @@
|
||||
/*
|
||||
FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.
|
||||
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* FreeRTOS tutorial books are available in pdf and paperback. *
|
||||
* Complete, revised, and edited pdf reference manuals are also *
|
||||
* available. *
|
||||
* *
|
||||
* Purchasing FreeRTOS documentation will not only help you, by *
|
||||
* ensuring you get running as quickly as possible and with an *
|
||||
* in-depth knowledge of how to use FreeRTOS, it will also help *
|
||||
* the FreeRTOS project to continue with its mission of providing *
|
||||
* professional grade, cross platform, de facto standard solutions *
|
||||
* for microcontrollers - completely free of charge! *
|
||||
* *
|
||||
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
|
||||
* *
|
||||
* Thank you for using FreeRTOS, and thank you for your support! *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
|
||||
This file is part of the FreeRTOS distribution.
|
||||
|
||||
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License (version 2) as published by the
|
||||
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
||||
>>>NOTE<<< The modification to the GPL is included to allow you to
|
||||
distribute a combined work that includes FreeRTOS without being obliged to
|
||||
provide the source code for proprietary components outside of the FreeRTOS
|
||||
kernel. FreeRTOS is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
more details. You should have received a copy of the GNU General Public
|
||||
License and the FreeRTOS license exception along with FreeRTOS; if not it
|
||||
can be viewed here: http://www.freertos.org/a00114.html and also obtained
|
||||
by writing to Richard Barry, contact details for whom are available on the
|
||||
FreeRTOS WEB site.
|
||||
|
||||
1 tab == 4 spaces!
|
||||
|
||||
http://www.FreeRTOS.org - Documentation, latest information, license and
|
||||
contact details.
|
||||
|
||||
http://www.SafeRTOS.com - A version that is certified for use in safety
|
||||
critical systems.
|
||||
|
||||
http://www.OpenRTOS.com - Commercial support, development, porting,
|
||||
licensing and training services.
|
||||
*/
|
||||
|
||||
/* Standard includes. */
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
|
||||
/* Driver includes. */
|
||||
#include "drivers/mss_uart/mss_uart.h"
|
||||
|
||||
/* Example includes. */
|
||||
#include "FreeRTOS_CLI.h"
|
||||
#include "UARTCommandConsole.h"
|
||||
|
||||
/* Dimensions the buffer into which input characters are placed. */
|
||||
#define cmdMAX_INPUT_SIZE 50
|
||||
|
||||
/* The maximum time in ticks to wait for the UART access mutex. */
|
||||
#define cmdMAX_MUTEX_WAIT ( 200 / portTICK_RATE_MS )
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* The task that implements the command console processing.
|
||||
*/
|
||||
static void prvUARTCommandConsoleTask( void *pvParameters );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Const messages output by the command console. */
|
||||
static const uint8_t * const pcWelcomeMessage = ( uint8_t * ) "FreeRTOS command server.\r\nType Help to view a list of registered commands.\r\n\r\n>";
|
||||
static const uint8_t * const pcEndOfOutputMessage = ( uint8_t * ) "\r\n[Press ENTER to execute the previous command again]\r\n>";
|
||||
static const uint8_t * const pcNewLine = ( uint8_t * ) "\r\n";
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vUARTCommandConsoleStart( uint16_t usStackSize, unsigned portBASE_TYPE uxPriority )
|
||||
{
|
||||
/* Create that task that handles the console itself. */
|
||||
xTaskCreate( prvUARTCommandConsoleTask, /* The task that implements the command console. */
|
||||
( const int8_t * const ) "CLI", /* Text name assigned to the task. This is just to assist debugging. The kernel does not use this name itself. */
|
||||
usStackSize, /* The size of the stack allocated to the task. */
|
||||
NULL, /* The parameter is not used, so NULL is passed. */
|
||||
uxPriority, /* The priority allocated to the task. */
|
||||
NULL ); /* A handle is not required, so just pass NULL. */
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvUARTCommandConsoleTask( void *pvParameters )
|
||||
{
|
||||
int8_t cRxedChar, cInputIndex = 0, *pcOutputString;
|
||||
static int8_t cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];
|
||||
portBASE_TYPE xReturned;
|
||||
mss_uart_instance_t * const pxUART = &g_mss_uart0;
|
||||
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Obtain the address of the output buffer. Note there is no mutual
|
||||
exclusion on this buffer as it is assumed only one command console
|
||||
interface will be used at any one time. */
|
||||
pcOutputString = FreeRTOS_CLIGetOutputBuffer();
|
||||
|
||||
/* Initialise the UART. */
|
||||
MSS_UART_init( pxUART, MSS_UART_115200_BAUD, MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT );
|
||||
|
||||
/* Send the welcome message. */
|
||||
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcWelcomeMessage );
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* No characters received yet for the current input string. */
|
||||
cRxedChar = 0;
|
||||
|
||||
/* Only interested in reading one character at a time. */
|
||||
MSS_UART_get_rx( pxUART, &cRxedChar, sizeof( cRxedChar ) );
|
||||
|
||||
/* Echo the character back. */
|
||||
MSS_UART_polled_tx( pxUART, &cRxedChar, sizeof( cRxedChar ) );
|
||||
|
||||
/* Was it the end of the line? */
|
||||
if( cRxedChar == '\n' || cRxedChar == '\r' )
|
||||
{
|
||||
/* Just to space the output from the input. */
|
||||
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcNewLine );
|
||||
|
||||
/* See if the command is empty, indicating that the last command is
|
||||
to be executed again. */
|
||||
if( cInputIndex == 0 )
|
||||
{
|
||||
/* Copy the last command back into the input string. */
|
||||
strcpy( ( char * ) cInputString, ( char * ) cLastInputString );
|
||||
}
|
||||
|
||||
/* Pass the received command to the command interpreter. The
|
||||
command interpreter is called repeatedly until it returns pdFALSE
|
||||
(indicating there is no more output) as it might generate more than
|
||||
one string. */
|
||||
do
|
||||
{
|
||||
/* Get the next output string from the command interpreter. */
|
||||
xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );
|
||||
|
||||
/* Write the generated string to the UART. */
|
||||
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcOutputString );
|
||||
vTaskDelay( 1 );
|
||||
|
||||
} while( xReturned != pdFALSE );
|
||||
|
||||
/* All the strings generated by the input command have been sent.
|
||||
Clear the input string ready to receive the next command. Remember
|
||||
the command that was just processed first in case it is to be
|
||||
processed again. */
|
||||
strcpy( ( char * ) cLastInputString, ( char * ) cInputString );
|
||||
cInputIndex = 0;
|
||||
memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
|
||||
|
||||
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcEndOfOutputMessage );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( cRxedChar == '\r' )
|
||||
{
|
||||
/* Ignore the character. */
|
||||
}
|
||||
else if( cRxedChar == '\b' )
|
||||
{
|
||||
/* Backspace was pressed. Erase the last character in the
|
||||
string - if any. */
|
||||
if( cInputIndex > 0 )
|
||||
{
|
||||
cInputIndex--;
|
||||
cInputString[ cInputIndex ] = '\0';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* A character was entered. Add it to the string
|
||||
entered so far. When a \n is entered the complete
|
||||
string will be passed to the command interpreter. */
|
||||
if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
|
||||
{
|
||||
if( cInputIndex < cmdMAX_INPUT_SIZE )
|
||||
{
|
||||
cInputString[ cInputIndex ] = cRxedChar;
|
||||
cInputIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||
|
||||
FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
|
||||
http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* FreeRTOS tutorial books are available in pdf and paperback. *
|
||||
* Complete, revised, and edited pdf reference manuals are also *
|
||||
* available. *
|
||||
* *
|
||||
* Purchasing FreeRTOS documentation will not only help you, by *
|
||||
* ensuring you get running as quickly as possible and with an *
|
||||
* in-depth knowledge of how to use FreeRTOS, it will also help *
|
||||
* the FreeRTOS project to continue with its mission of providing *
|
||||
* professional grade, cross platform, de facto standard solutions *
|
||||
* for microcontrollers - completely free of charge! *
|
||||
* *
|
||||
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
|
||||
* *
|
||||
* Thank you for using FreeRTOS, and thank you for your support! *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
|
||||
This file is part of the FreeRTOS distribution.
|
||||
|
||||
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License (version 2) as published by the
|
||||
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
||||
|
||||
>>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
|
||||
distribute a combined work that includes FreeRTOS without being obliged to
|
||||
provide the source code for proprietary components outside of the FreeRTOS
|
||||
kernel.
|
||||
|
||||
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details. You should have received a copy of the GNU General Public License
|
||||
and the FreeRTOS license exception along with FreeRTOS; if not it can be
|
||||
viewed here: http://www.freertos.org/a00114.html and also obtained by
|
||||
writing to Real Time Engineers Ltd., contact details for whom are available
|
||||
on the FreeRTOS WEB site.
|
||||
|
||||
1 tab == 4 spaces!
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* Having a problem? Start by reading the FAQ "My application does *
|
||||
* not run, what could be wrong?" *
|
||||
* *
|
||||
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
|
||||
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||
license and Real Time Engineers Ltd. contact details.
|
||||
|
||||
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||
including FreeRTOS+Trace - an indispensable productivity tool, and our new
|
||||
fully thread aware and reentrant UDP/IP stack.
|
||||
|
||||
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||
Integrity Systems, who sell the code with commercial support,
|
||||
indemnification and middleware, under the OpenRTOS brand.
|
||||
|
||||
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||
engineered and independently SIL3 certified version for use in safety and
|
||||
mission critical applications that require provable dependability.
|
||||
*/
|
||||
|
||||
#ifndef UART_COMMAND_CONSOLE_H
|
||||
#define UART_COMMAND_CONSOLE_H
|
||||
|
||||
/*
|
||||
* Create the task that implements a command console using the USB virtual com
|
||||
* port driver for intput and output.
|
||||
*/
|
||||
void vUARTCommandConsoleStart( uint16_t usStackSize, unsigned portBASE_TYPE uxPriority );
|
||||
|
||||
#endif /* UART_COMMAND_CONSOLE_H */
|
||||
|
||||
|
||||
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
|
||||
*
|
||||
* FreeRTOS+FAT SL is an complementary component provided to Real Time Engineers
|
||||
* Ltd. by HCC Embedded for use with FreeRTOS. It is not, in itself, part of
|
||||
* the FreeRTOS kernel. FreeRTOS+FAT SL is licensed separately from FreeRTOS,
|
||||
* and uses a different license to FreeRTOS. FreeRTOS+FAT SL uses a dual
|
||||
* license model, information on which is provided below:
|
||||
*
|
||||
* - Open source licensing -
|
||||
* FreeRTOS+FAT SL is a free download and may be used, modified and distributed
|
||||
* without charge provided the user adheres to version two of the GNU General
|
||||
* Public license (GPL) and does not remove the copyright notice or this text.
|
||||
* The GPL V2 text is available on the gnu.org web site, and on the following
|
||||
* URL: http://www.FreeRTOS.org/gpl-2.0.txt
|
||||
*
|
||||
* - Commercial licensing -
|
||||
* Businesses and individuals who wish to incorporate FreeRTOS+FAT SL into
|
||||
* proprietary software for redistribution in any form must first obtain a
|
||||
* commercial license - and in-so-doing support the maintenance, support and
|
||||
* further development of the FreeRTOS+FAT SL product. Commercial licenses can
|
||||
* be obtained from http://shop.freertos.org and do not require any source files
|
||||
* to be changed.
|
||||
*
|
||||
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
|
||||
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
|
||||
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
|
||||
* conditions and terms, be they implied, expressed, or statutory.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://www.FreeRTOS.org/FreeRTOS-Plus
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CONFIG_FAT_SL_H
|
||||
#define _CONFIG_FAT_SL_H
|
||||
|
||||
#include "../version/ver_fat_sl.h"
|
||||
#if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
|
||||
#error Incompatible FAT_SL version number!
|
||||
#endif
|
||||
|
||||
#include "../api/api_mdriver.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**
|
||||
** FAT SL user settings
|
||||
**
|
||||
**************************************************************************/
|
||||
#define F_SECTOR_SIZE 512u /* Disk sector size. */
|
||||
#define F_FS_THREAD_AWARE 1 /* Set to one if the file system will be access from more than one task. */
|
||||
#define F_MAXPATH 64 /* Maximum length a file name (including its full path) can be. */
|
||||
#define F_MAX_LOCK_WAIT_TICKS 20 /* The maximum number of RTOS ticks to wait when attempting to obtain a lock on the file system when F_FS_THREAD_AWARE is set to 1. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CONFIG_FAT_SL_H */
|
||||
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
|
||||
*
|
||||
* FreeRTOS+FAT SL is an complementary component provided to Real Time Engineers
|
||||
* Ltd. by HCC Embedded for use with FreeRTOS. It is not, in itself, part of
|
||||
* the FreeRTOS kernel. FreeRTOS+FAT SL is licensed separately from FreeRTOS,
|
||||
* and uses a different license to FreeRTOS. FreeRTOS+FAT SL uses a dual
|
||||
* license model, information on which is provided below:
|
||||
*
|
||||
* - Open source licensing -
|
||||
* FreeRTOS+FAT SL is a free download and may be used, modified and distributed
|
||||
* without charge provided the user adheres to version two of the GNU General
|
||||
* Public license (GPL) and does not remove the copyright notice or this text.
|
||||
* The GPL V2 text is available on the gnu.org web site, and on the following
|
||||
* URL: http://www.FreeRTOS.org/gpl-2.0.txt
|
||||
*
|
||||
* - Commercial licensing -
|
||||
* Businesses and individuals who wish to incorporate FreeRTOS+FAT SL into
|
||||
* proprietary software for redistribution in any form must first obtain a
|
||||
* commercial license - and in-so-doing support the maintenance, support and
|
||||
* further development of the FreeRTOS+FAT SL product. Commercial licenses can
|
||||
* be obtained from http://shop.freertos.org and do not require any source files
|
||||
* to be changed.
|
||||
*
|
||||
* FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
|
||||
* cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
|
||||
* is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
|
||||
* conditions and terms, be they implied, expressed, or statutory.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://www.FreeRTOS.org/FreeRTOS-Plus
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CONFIG_MDRIVER_RAM_H_
|
||||
#define _CONFIG_MDRIVER_RAM_H_
|
||||
|
||||
#include "../version/ver_mdriver_ram.h"
|
||||
#if VER_MDRIVER_RAM_MAJOR != 1 || VER_MDRIVER_RAM_MINOR != 2
|
||||
#error Incompatible MDRIVER_RAM version number!
|
||||
#endif
|
||||
|
||||
#define MDRIVER_RAM_SECTOR_SIZE 512 /* Sector size */
|
||||
|
||||
#define MDRIVER_RAM_VOLUME0_SIZE (28 * 1024) /* defintion for size of ramdrive0 */
|
||||
|
||||
#define MDRIVER_MEM_LONG_ACCESS 1 /* set this value to 1 if 32bit access available */
|
||||
|
||||
#endif /* ifndef _CONFIG_MDRIVER_RAM_H_ */
|
||||
|
@ -0,0 +1,138 @@
|
||||
/*
|
||||
FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||
|
||||
FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
|
||||
http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* FreeRTOS tutorial books are available in pdf and paperback. *
|
||||
* Complete, revised, and edited pdf reference manuals are also *
|
||||
* available. *
|
||||
* *
|
||||
* Purchasing FreeRTOS documentation will not only help you, by *
|
||||
* ensuring you get running as quickly as possible and with an *
|
||||
* in-depth knowledge of how to use FreeRTOS, it will also help *
|
||||
* the FreeRTOS project to continue with its mission of providing *
|
||||
* professional grade, cross platform, de facto standard solutions *
|
||||
* for microcontrollers - completely free of charge! *
|
||||
* *
|
||||
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
|
||||
* *
|
||||
* Thank you for using FreeRTOS, and thank you for your support! *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
|
||||
This file is part of the FreeRTOS distribution.
|
||||
|
||||
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License (version 2) as published by the
|
||||
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
||||
|
||||
>>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
|
||||
distribute a combined work that includes FreeRTOS without being obliged to
|
||||
provide the source code for proprietary components outside of the FreeRTOS
|
||||
kernel.
|
||||
|
||||
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details. You should have received a copy of the GNU General Public License
|
||||
and the FreeRTOS license exception along with FreeRTOS; if not it can be
|
||||
viewed here: http://www.freertos.org/a00114.html and also obtained by
|
||||
writing to Real Time Engineers Ltd., contact details for whom are available
|
||||
on the FreeRTOS WEB site.
|
||||
|
||||
1 tab == 4 spaces!
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* Having a problem? Start by reading the FAQ "My application does *
|
||||
* not run, what could be wrong?" *
|
||||
* *
|
||||
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
|
||||
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||
license and Real Time Engineers Ltd. contact details.
|
||||
|
||||
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||
including FreeRTOS+Trace - an indispensable productivity tool, and our new
|
||||
fully thread aware and reentrant UDP/IP stack.
|
||||
|
||||
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||
Integrity Systems, who sell the code with commercial support,
|
||||
indemnification and middleware, under the OpenRTOS brand.
|
||||
|
||||
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||
engineered and independently SIL3 certified version for use in safety and
|
||||
mission critical applications that require provable dependability.
|
||||
*/
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
/* Utility functions to implement run time stats on Cortex-M CPUs. The collected
|
||||
run time data can be viewed through the CLI interface. See the following URL for
|
||||
more information on run time stats:
|
||||
http://www.freertos.org/rtos-run-time-stats.html */
|
||||
|
||||
/* Used in the run time stats calculations. */
|
||||
static uint32_t ulClocksPer10thOfAMilliSecond = 0UL;
|
||||
|
||||
|
||||
void vConfigureTimerForRunTimeStats( void )
|
||||
{
|
||||
/* How many clocks are there per tenth of a millisecond? */
|
||||
ulClocksPer10thOfAMilliSecond = configCPU_CLOCK_HZ / 10000UL;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
uint32_t ulGetRunTimeCounterValue( void )
|
||||
{
|
||||
uint32_t ulSysTickCounts, ulTickCount, ulReturn;
|
||||
const uint32_t ulSysTickReloadValue = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
|
||||
volatile uint32_t * const pulCurrentSysTickCount = ( ( volatile uint32_t *) 0xe000e018 );
|
||||
volatile uint32_t * const pulInterruptCTRLState = ( ( volatile uint32_t *) 0xe000ed04 );
|
||||
const uint32_t ulSysTickPendingBit = 0x04000000UL;
|
||||
|
||||
/* NOTE: There are potentially race conditions here. However, it is used
|
||||
anyway to keep the examples simple, and to avoid reliance on a separate
|
||||
timer peripheral. */
|
||||
|
||||
|
||||
/* The SysTick is a down counter. How many clocks have passed since it was
|
||||
last reloaded? */
|
||||
ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;
|
||||
|
||||
/* How many times has it overflowed? */
|
||||
ulTickCount = xTaskGetTickCountFromISR();
|
||||
|
||||
/* Is there a SysTick interrupt pending? */
|
||||
if( ( *pulInterruptCTRLState & ulSysTickPendingBit ) != 0UL )
|
||||
{
|
||||
/* There is a SysTick interrupt pending, so the SysTick has overflowed
|
||||
but the tick count not yet incremented. */
|
||||
ulTickCount++;
|
||||
|
||||
/* Read the SysTick again, as the overflow might have occurred since
|
||||
it was read last. */
|
||||
ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;
|
||||
}
|
||||
|
||||
/* Convert the tick count into tenths of a millisecond. THIS ASSUMES
|
||||
configTICK_RATE_HZ is 1000! */
|
||||
ulReturn = ( ulTickCount * 10UL ) ;
|
||||
|
||||
/* Add on the number of tenths of a millisecond that have passed since the
|
||||
tick count last got updated. */
|
||||
ulReturn += ( ulSysTickCounts / ulClocksPer10thOfAMilliSecond );
|
||||
|
||||
return ulReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
@ -0,0 +1,292 @@
|
||||
/*
|
||||
Copyright 2001, 2002 Georges Menie (www.menie.org)
|
||||
stdarg version contributed by Christian Ettinger
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
putchar is the only external dependency for this file,
|
||||
if you have a working putchar, leave it commented out.
|
||||
If not, uncomment the define below and
|
||||
replace outbyte(c) by your own function call.
|
||||
|
||||
*/
|
||||
|
||||
#define putchar(c) c
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
static void printchar(char **str, int c)
|
||||
{
|
||||
//extern int putchar(int c);
|
||||
|
||||
if (str) {
|
||||
**str = (char)c;
|
||||
++(*str);
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)putchar(c);
|
||||
}
|
||||
}
|
||||
|
||||
#define PAD_RIGHT 1
|
||||
#define PAD_ZERO 2
|
||||
|
||||
static int prints(char **out, const char *string, int width, int pad)
|
||||
{
|
||||
register int pc = 0, padchar = ' ';
|
||||
|
||||
if (width > 0) {
|
||||
register int len = 0;
|
||||
register const char *ptr;
|
||||
for (ptr = string; *ptr; ++ptr) ++len;
|
||||
if (len >= width) width = 0;
|
||||
else width -= len;
|
||||
if (pad & PAD_ZERO) padchar = '0';
|
||||
}
|
||||
if (!(pad & PAD_RIGHT)) {
|
||||
for ( ; width > 0; --width) {
|
||||
printchar (out, padchar);
|
||||
++pc;
|
||||
}
|
||||
}
|
||||
for ( ; *string ; ++string) {
|
||||
printchar (out, *string);
|
||||
++pc;
|
||||
}
|
||||
for ( ; width > 0; --width) {
|
||||
printchar (out, padchar);
|
||||
++pc;
|
||||
}
|
||||
|
||||
return pc;
|
||||
}
|
||||
|
||||
/* the following should be enough for 32 bit int */
|
||||
#define PRINT_BUF_LEN 12
|
||||
|
||||
static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase)
|
||||
{
|
||||
char print_buf[PRINT_BUF_LEN];
|
||||
register char *s;
|
||||
register int t, neg = 0, pc = 0;
|
||||
register unsigned int u = (unsigned int)i;
|
||||
|
||||
if (i == 0) {
|
||||
print_buf[0] = '0';
|
||||
print_buf[1] = '\0';
|
||||
return prints (out, print_buf, width, pad);
|
||||
}
|
||||
|
||||
if (sg && b == 10 && i < 0) {
|
||||
neg = 1;
|
||||
u = (unsigned int)-i;
|
||||
}
|
||||
|
||||
s = print_buf + PRINT_BUF_LEN-1;
|
||||
*s = '\0';
|
||||
|
||||
while (u) {
|
||||
t = (unsigned int)u % b;
|
||||
if( t >= 10 )
|
||||
t += letbase - '0' - 10;
|
||||
*--s = (char)(t + '0');
|
||||
u /= b;
|
||||
}
|
||||
|
||||
if (neg) {
|
||||
if( width && (pad & PAD_ZERO) ) {
|
||||
printchar (out, '-');
|
||||
++pc;
|
||||
--width;
|
||||
}
|
||||
else {
|
||||
*--s = '-';
|
||||
}
|
||||
}
|
||||
|
||||
return pc + prints (out, s, width, pad);
|
||||
}
|
||||
|
||||
static int print( char **out, const char *format, va_list args )
|
||||
{
|
||||
register int width, pad;
|
||||
register int pc = 0;
|
||||
char scr[2];
|
||||
|
||||
for (; *format != 0; ++format) {
|
||||
if (*format == '%') {
|
||||
++format;
|
||||
width = pad = 0;
|
||||
if (*format == '\0') break;
|
||||
if (*format == '%') goto out;
|
||||
if (*format == '-') {
|
||||
++format;
|
||||
pad = PAD_RIGHT;
|
||||
}
|
||||
while (*format == '0') {
|
||||
++format;
|
||||
pad |= PAD_ZERO;
|
||||
}
|
||||
for ( ; *format >= '0' && *format <= '9'; ++format) {
|
||||
width *= 10;
|
||||
width += *format - '0';
|
||||
}
|
||||
if( *format == 's' ) {
|
||||
register char *s = (char *)va_arg( args, int );
|
||||
pc += prints (out, s?s:"(null)", width, pad);
|
||||
continue;
|
||||
}
|
||||
if( *format == 'd' || *format == 'i' ) {
|
||||
pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
|
||||
continue;
|
||||
}
|
||||
if( *format == 'x' ) {
|
||||
pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
|
||||
continue;
|
||||
}
|
||||
if( *format == 'X' ) {
|
||||
pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A');
|
||||
continue;
|
||||
}
|
||||
if( *format == 'u' ) {
|
||||
pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a');
|
||||
continue;
|
||||
}
|
||||
if( *format == 'c' ) {
|
||||
/* char are converted to int then pushed on the stack */
|
||||
scr[0] = (char)va_arg( args, int );
|
||||
scr[1] = '\0';
|
||||
pc += prints (out, scr, width, pad);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
out:
|
||||
printchar (out, *format);
|
||||
++pc;
|
||||
}
|
||||
}
|
||||
if (out) **out = '\0';
|
||||
va_end( args );
|
||||
return pc;
|
||||
}
|
||||
|
||||
int printf(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start( args, format );
|
||||
return print( 0, format, args );
|
||||
}
|
||||
|
||||
int sprintf(char *out, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start( args, format );
|
||||
return print( &out, format, args );
|
||||
}
|
||||
|
||||
|
||||
int snprintf( char *buf, unsigned int count, const char *format, ... )
|
||||
{
|
||||
va_list args;
|
||||
|
||||
( void ) count;
|
||||
|
||||
va_start( args, format );
|
||||
return print( &buf, format, args );
|
||||
}
|
||||
|
||||
#ifdef TEST_PRINTF
|
||||
int main(void)
|
||||
{
|
||||
char *ptr = "Hello world!";
|
||||
char *np = 0;
|
||||
int i = 5;
|
||||
unsigned int bs = sizeof(int)*8;
|
||||
int mi;
|
||||
char buf[80];
|
||||
|
||||
mi = (1 << (bs-1)) + 1;
|
||||
printf("%s\n", ptr);
|
||||
printf("printf test\n");
|
||||
printf("%s is null pointer\n", np);
|
||||
printf("%d = 5\n", i);
|
||||
printf("%d = - max int\n", mi);
|
||||
printf("char %c = 'a'\n", 'a');
|
||||
printf("hex %x = ff\n", 0xff);
|
||||
printf("hex %02x = 00\n", 0);
|
||||
printf("signed %d = unsigned %u = hex %x\n", -3, -3, -3);
|
||||
printf("%d %s(s)%", 0, "message");
|
||||
printf("\n");
|
||||
printf("%d %s(s) with %%\n", 0, "message");
|
||||
sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf);
|
||||
sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf);
|
||||
sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf);
|
||||
sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf);
|
||||
sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf);
|
||||
sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf);
|
||||
sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf);
|
||||
sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* if you compile this file with
|
||||
* gcc -Wall $(YOUR_C_OPTIONS) -DTEST_PRINTF -c printf.c
|
||||
* you will get a normal warning:
|
||||
* printf.c:214: warning: spurious trailing `%' in format
|
||||
* this line is testing an invalid % at the end of the format string.
|
||||
*
|
||||
* this should display (on 32bit int machine) :
|
||||
*
|
||||
* Hello world!
|
||||
* printf test
|
||||
* (null) is null pointer
|
||||
* 5 = 5
|
||||
* -2147483647 = - max int
|
||||
* char a = 'a'
|
||||
* hex ff = ff
|
||||
* hex 00 = 00
|
||||
* signed -3 = unsigned 4294967293 = hex fffffffd
|
||||
* 0 message(s)
|
||||
* 0 message(s) with %
|
||||
* justif: "left "
|
||||
* justif: " right"
|
||||
* 3: 0003 zero padded
|
||||
* 3: 3 left justif.
|
||||
* 3: 3 right justif.
|
||||
* -3: -003 zero padded
|
||||
* -3: -3 left justif.
|
||||
* -3: -3 right justif.
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* To keep linker happy. */
|
||||
int write( int i, char* c, int n)
|
||||
{
|
||||
(void)i;
|
||||
(void)n;
|
||||
(void)c;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue