Пример #1
0
/*----------------------------------------------------------------------------------------------------------------------
Function: DebugInitialize

Description:
Sets up the debug command list and activates the debug functionality.

Requires:
  - The debug application is not yet running
  - The UART resource requested should be free

Promises:
  - UART resource Debug_au8RxBuffer initialized to all 0
  - Buffer pointers Debug_pu8CmdBufferCurrentChar and Debug_pu8RxBufferParser set to the start of the buffer
  - G_DebugStateMachine set to Idle
*/
void DebugInitialize(void)
{
  UartConfigurationType sUartConfig;  
  u8 au8DebugStarted[] = "Debug task initialized\n\r";

  /* Clear the receive buffer */
  for (u16 i = 0; i < DEBUG_RX_BUFFER_SIZE; i++)
  {
    Debug_au8RxBuffer[i] = 0;
  }

  /* Initailze startup values and the command array */
  Debug_pu8RxBufferParser    = &Debug_au8RxBuffer[0];
  Debug_pu8RxBufferNextChar  = &Debug_au8RxBuffer[0]; 
  Debug_pu8CmdBufferNextChar = &Debug_au8CommandBuffer[0]; 

  /* Request the UART resource to be used for the Debug application */
  sUartConfig.UartPeripheral     = DEBUG_UART;
  sUartConfig.pu8RxBufferAddress = &Debug_au8RxBuffer[0];
  sUartConfig.pu8RxNextByte      = &Debug_pu8RxBufferNextChar;
  sUartConfig.u32RxBufferSize    = DEBUG_RX_BUFFER_SIZE;
  
  Debug_Uart = UartRequest(&sUartConfig);
  
  /* Go to error state if the UartRequest failed */
  if(Debug_Uart == NULL)
  {
    G_DebugStateMachine = DebugSM_Error;

  }
  /* Otherwise send the first message, set "good" flag and head to Idle */
  else
  {
    DebugLineFeed();
    DebugLineFeed();
    UartWriteData(Debug_Uart, sizeof(au8DebugStarted) - 1, &au8DebugStarted[0]);
    
    G_u32ApplicationFlags |= _APPLICATION_FLAGS_DEBUG;
    G_DebugStateMachine = DebugSM_Idle;
  }
  
} /* end  DebugInitialize() */
/*----------------------------------------------------------------------------------------------------------------------
Function: SystemStatusReport

Description:
Reports if system is good or not.

Requires:
  - G_u32SystemFlags up to date with system status
  - New tasks should be added to the check list below including in the message string for the task name
  - The system is in initialization state so MsgSenderForceSend() is used
    to output each meassage after it is queued.

Promises:
  - Prints out messages for any system tests that failed
  - Prints out overall good message if all tests passed
*/
void SystemStatusReport(void)
{

  u8 au8SystemPassed[] = "NONE";
  u8 au8SystemReady[] = "\n\rInitialization complete. Type en+c00 for debug menu.  Failed tasks:\n\r";
  u32 u32TaskFlagMaskBit = (u32)0x01;
  bool bNoFailedTasks = TRUE;

#ifdef MPGL1
  u8 aau8AppShortNames[NUMBER_APPLICATIONS][MAX_TASK_NAME_SIZE] = {"LED", "BUTTON", "DEBUG", "LCD", "ANT", "SD"};
#endif /* MPGL1 */

#ifdef MPGL2
  u8 aau8AppShortNames[NUMBER_APPLICATIONS][MAX_TASK_NAME_SIZE] = {"LED", "BUTTON", "DEBUG", "LCD", "ANT", "CAPTOUCH"};
#endif /* MPGL2 */

  /* Announce init complete then report any tasks that failed init */
  DebugPrintf(au8SystemReady);
    
  for(u8 i = 0; i < NUMBER_APPLICATIONS; i++)
  {
    if( !(u32TaskFlagMaskBit & G_u32ApplicationFlags) )
    {
      bNoFailedTasks = FALSE;
      DebugPrintf(&aau8AppShortNames[i][0]);
      DebugLineFeed();
    }
    
    u32TaskFlagMaskBit <<= 1;
  }     
        
  if( bNoFailedTasks)
  {
    DebugPrintf(au8SystemPassed);
  }
  
  DebugLineFeed();
  
} /* end SystemStatusReport() */
/*----------------------------------------------------------------------------------------------------------------------
Error state 
Attempt to print an error message (even though if the Debug UART has failed, then it obviously cannot print
a message to tell you that!)
*/
void DebugSM_Error(void)         
{
  static u8 au8DebugErrorMsg[] = "\n\nDebug task error: ";
  
  /* Flag an error and report it (if possible) */
  G_u32DebugFlags |= _DEBUG_FLAG_ERROR;
  DebugPrintf(au8DebugErrorMsg);
  DebugPrintNumber( (u32)(Debug_u8ErrorCode) );
  DebugLineFeed();
  
  /* Return to Idle state */
  Debug_u16CommandSize = 0;
  Debug_pu8CmdBufferNextChar = &Debug_au8CommandBuffer[0];
  Debug_pfnStateMachine = DebugSM_Idle;

} /* end DebugSM_Error() */
Пример #4
0
/*----------------------------------------------------------------------------------------------------------------------
Function DebugCommandPrepareList

Description:
Queues the entire list of debug commands available in the system so they will
be sent out the debug UART for the user to view.

Requires:
  - Message Sender application is running

Promises:
  - Command numbers and names of all installed commands are queued to messagesender.
*/
static void DebugCommandPrepareList(void)
{
  u8 au8ListHeading[] = "\n\n\rAvailable commands:\n\r";
  u8 au8CommandLine[DEBUG_CMD_PREFIX_LENGTH + DEBUG_CMD_NAME_LENGTH + DEBUG_CMD_POSTFIX_LENGTH];
  
  /* Write static characters to command list line */
  au8CommandLine[2] = ':';
  au8CommandLine[3] = ' ';
  au8CommandLine[DEBUG_CMD_PREFIX_LENGTH + DEBUG_CMD_NAME_LENGTH] = '\n';
  au8CommandLine[DEBUG_CMD_PREFIX_LENGTH + DEBUG_CMD_NAME_LENGTH + 1] = '\r';
  au8CommandLine[DEBUG_CMD_PREFIX_LENGTH + DEBUG_CMD_NAME_LENGTH + 2] = '\0';

  /* Prepare a nicely formatted list of commands */
  DebugPrintf(au8ListHeading);
  
  /* Loop through the array of commands parsing out the command number
  and printing it along with the command name. */  
  for(u8 i = 0; i < DEBUG_COMMANDS; i++)
  {
    /* Get the command number in ASCII */
    if(i >= 10)
    {
      au8CommandLine[0] = (i / 10) + 0x30;
    }
    else
    {
      au8CommandLine[0] = 0x30;
    }
    
    au8CommandLine[1] = (i % 10) + 0x30;
    
    /* Read the command name */
    for(u8 j = 0; j < DEBUG_CMD_NAME_LENGTH; j++)
    {
      au8CommandLine[DEBUG_CMD_PREFIX_LENGTH + j] = Debug_au8Commands[i].pu8CommandName[j];
    }
    
    /* Queue the command name to the UART */
    DebugPrintf(au8CommandLine);
  }

  DebugLineFeed();
  
} /* end DebugCommand0PrepareList() */