changeset 109:2c1a9e6ae70e

Added more CLI commands. - reset -> Simulates power cycle (Not yet compatible with AVR) - reload -> Sets the device into firmware reload mode - led -> Toggles the error LED - version -> Displays detailed version information (additions to CMake files was necessary, might have broken Windows builds...)
author Jacob Alexander <haata@kiibohd.com>
date Thu, 23 Jan 2014 02:01:12 -0800
parents ecb57880e3bc
children 98d940b60d12
files Debug/cli/cli.c Debug/cli/cli.h Lib/_buildvars.h Lib/mk20dx128.h Output/pjrcUSB/arm/usb_dev.c Output/pjrcUSB/arm/usb_dev.h Output/pjrcUSB/output_com.c Output/pjrcUSB/output_com.h setup.cmake
diffstat 9 files changed, 156 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/Debug/cli/cli.c	Wed Jan 22 01:58:34 2014 -0800
+++ b/Debug/cli/cli.c	Thu Jan 23 02:01:12 2014 -0800
@@ -25,7 +25,9 @@
 //#include <stdarg.h>
 
 // Project Includes
+#include <buildvars.h>
 #include "cli.h"
+#include <led.h>
 #include <print.h>
 
 
@@ -34,8 +36,12 @@
 
 // Basic command dictionary
 CLIDictItem basicCLIDict[] = {
-	{ "help",    "You're looking at it :P", cliFunc_help },
-	{ "version", "Version information about this firmware.", cliFunc_version },
+	{ "cliDebug", "Enables/Disables hex output of the most recent cli input.", cliFunc_cliDebug },
+	{ "help",     "You're looking at it :P", cliFunc_help },
+	{ "led",      "Enables/Disables indicator LED. Try a couple times just in case the LED is in an odd state.\r\n\t\t\033[33mWarning\033[0m: May adversely affect some modules...", cliFunc_led },
+	{ "reload",   "Signals microcontroller to reflash/reload.", cliFunc_reload },
+	{ "reset",    "Sends a software reset, should be similar to powering on the device.", cliFunc_reset },
+	{ "version",  "Version information about this firmware.", cliFunc_version },
 	{ 0, 0, 0 } // Null entry for dictionary end
 };
 
@@ -59,6 +65,10 @@
 	// Register first dictionary
 	CLIDictionariesUsed = 0;
 	registerDictionary_cli( basicCLIDict );
+
+	// Initialize main LED
+	init_errorLED();
+	CLILEDState = 0;
 }
 
 void process_cli()
@@ -251,6 +261,10 @@
 
 // ----- CLI Command Functions -----
 
+void cliFunc_cliDebug( char* args )
+{
+}
+
 void cliFunc_help( char* args )
 {
 	// Scan array of dictionaries and print every description
@@ -264,15 +278,51 @@
 		// Parse each cmd/description until a null command entry is found
 		for ( uint8_t cmd = 0; CLIDict[dict][cmd].name != 0; cmd++ )
 		{
-			dPrintStrs( " \033[35m", CLIDict[dict][cmd].name, NL, "\033[0m    ", CLIDict[dict][cmd].description, NL );
+			dPrintStrs(" \033[35m", CLIDict[dict][cmd].name, "\033[0m");
+
+			// Determine number of spaces to tab by the length of the command and TabAlign
+			uint8_t padLength = CLIEntryTabAlign - lenStr( CLIDict[dict][cmd].name );
+			while ( padLength-- > 0 )
+				print(" ");
+
+			dPrintStrNL( CLIDict[dict][cmd].description );
 		}
 	}
 }
 
+void cliFunc_led( char* args )
+{
+	CLILEDState ^= 1 << 1; // Toggle between 0 and 1
+	errorLED( CLILEDState ); // Enable/Disable error LED
+}
+
+void cliFunc_reload( char* args )
+{
+	// Request to output module to be set into firmware reload mode
+	output_firmwareReload();
+}
+
+void cliFunc_reset( char* args )
+{
+	// Trigger an overall software reset
+	SOFTWARE_RESET();
+}
+
 void cliFunc_version( char* args )
 {
 	print( NL );
-	print("Version!");
-	dPrint( args );
+	print( " \033[1mRevision:\033[0m      " CLI_Revision       NL );
+	print( " \033[1mBranch:\033[0m        " CLI_Branch         NL );
+	print( " \033[1mTree Status:\033[0m   " CLI_ModifiedStatus NL );
+	print( " \033[1mRepo Origin:\033[0m   " CLI_RepoOrigin     NL );
+	print( " \033[1mCommit Date:\033[0m   " CLI_CommitDate     NL );
+	print( " \033[1mCommit Author:\033[0m " CLI_CommitAuthor   NL );
+	print( " \033[1mBuild Date:\033[0m    " CLI_BuildDate      NL );
+	print( " \033[1mBuild OS:\033[0m      " CLI_BuildOS        NL );
+	print( " \033[1mArchitecture:\033[0m  " CLI_Arch           NL );
+	print( " \033[1mChip:\033[0m          " CLI_Chip           NL );
+	print( " \033[1mCPU:\033[0m           " CLI_CPU            NL );
+	print( " \033[1mDevice:\033[0m        " CLI_Device         NL );
+	print( " \033[1mModules:\033[0m       " CLI_Modules        NL );
 }
 
--- a/Debug/cli/cli.h	Wed Jan 22 01:58:34 2014 -0800
+++ b/Debug/cli/cli.h	Thu Jan 23 02:01:12 2014 -0800
@@ -25,20 +25,17 @@
 // ----- Includes -----
 
 // Compiler Includes
-#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
-
-#elif defined(_mk20dx128_)
+#include <Lib/MainLib.h>
 
-#include "arm/usb_serial.h"
-
-#endif
-
+// Project Includes
+#include <output_com.h>
 
 
 // ----- Defines -----
 
 #define CLILineBufferMaxSize 100
 #define CLIMaxDictionaries   5
+#define CLIEntryTabAlign     12
 
 
 // ----- Structs -----
@@ -61,6 +58,8 @@
 CLIDictItem *CLIDict[CLIMaxDictionaries];
 uint8_t CLIDictionariesUsed;
 
+uint8_t CLILEDState;
+
 
 
 
@@ -74,8 +73,15 @@
 void commandLookup_cli();
 
 // CLI Command Functions
-void cliFunc_help   ( char* args );
-void cliFunc_version( char* args );
+void cliFunc_arch    ( char* args );
+void cliFunc_chip    ( char* args );
+void cliFunc_cliDebug( char* args );
+void cliFunc_device  ( char* args );
+void cliFunc_help    ( char* args );
+void cliFunc_led     ( char* args );
+void cliFunc_reload  ( char* args );
+void cliFunc_reset   ( char* args );
+void cliFunc_version ( char* args );
 
 
 #endif
--- a/Lib/_buildvars.h	Wed Jan 22 01:58:34 2014 -0800
+++ b/Lib/_buildvars.h	Thu Jan 23 02:01:12 2014 -0800
@@ -1,15 +1,15 @@
-/* Copyright (C) 2013 by Jacob Alexander
- * 
+/* Copyright (C) 2013-2014 by Jacob Alexander
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -30,10 +30,26 @@
 
 // You can change these to give your code its own name.
 #define STR_MANUFACTURER	L"@MANUFACTURER@"
-#define STR_PRODUCT		L"Keyboard - @ScanModule@ @MacroModule@ @USBModule@ @DebugModule@"
+#define STR_PRODUCT		L"ForceGauge - @OutputModule@ @DebugModule@"
 #define STR_SERIAL              L"@GitLastCommitDate@"
 
 
+// Strings used in the CLI module
+#define CLI_Revision            "@Git_Commit_Revision@"
+#define CLI_Branch              "@Git_Branch_INFO@"
+#define CLI_ModifiedStatus      "@Git_Modified_Status@"
+#define CLI_RepoOrigin          "@Git_Origin_URL@"
+#define CLI_CommitDate          "@Git_Date_INFO@"
+#define CLI_CommitAuthor        @Git_Commit_Author@
+#define CLI_Modules             "@OutputModule@ @DebugModule@"
+#define CLI_BuildDate           "@Build_Date@"
+#define CLI_BuildOS             "@CMAKE_SYSTEM@"
+#define CLI_Arch                "@COMPILER_FAMILY@"
+#define CLI_Chip                "@MCU@"
+#define CLI_CPU                 "@CPU@"
+#define CLI_Device              "ForceGauge"
+
+
 // Mac OS-X and Linux automatically load the correct drivers.  On
 // Windows, even though the driver is supplied by Microsoft, an
 // INF file is needed to load the driver.  These numbers need to
--- a/Lib/mk20dx128.h	Wed Jan 22 01:58:34 2014 -0800
+++ b/Lib/mk20dx128.h	Thu Jan 23 02:01:12 2014 -0800
@@ -1424,6 +1424,9 @@
 #define ARM_DWT_CTRL_CYCCNTENA          (1 << 0)                // Enable cycle count
 #define ARM_DWT_CYCCNT          *(volatile uint32_t *)0xE0001004 // Cycle count register
 
+// Software Reset
+#define SOFTWARE_RESET()        SCB_AIRCR = 0x5FA0004
+
 
 extern void nmi_isr(void);
 extern void hard_fault_isr(void);
--- a/Output/pjrcUSB/arm/usb_dev.c	Wed Jan 22 01:58:34 2014 -0800
+++ b/Output/pjrcUSB/arm/usb_dev.c	Thu Jan 23 02:01:12 2014 -0800
@@ -596,7 +596,10 @@
 
 
 
-
+void usb_device_reload()
+{
+	asm volatile("bkpt");
+}
 
 
 void _reboot_Teensyduino_(void)
--- a/Output/pjrcUSB/arm/usb_dev.h	Wed Jan 22 01:58:34 2014 -0800
+++ b/Output/pjrcUSB/arm/usb_dev.h	Thu Jan 23 02:01:12 2014 -0800
@@ -19,6 +19,8 @@
 void usb_tx(uint32_t endpoint, usb_packet_t *packet);
 void usb_tx_isr(uint32_t endpoint, usb_packet_t *packet);
 
+void usb_device_reload();
+
 extern volatile uint8_t usb_configuration;
 
 #ifdef CDC_DATA_INTERFACE
--- a/Output/pjrcUSB/output_com.c	Wed Jan 22 01:58:34 2014 -0800
+++ b/Output/pjrcUSB/output_com.c	Thu Jan 23 02:01:12 2014 -0800
@@ -73,7 +73,7 @@
 // ----- Functions -----
 
 // USB Module Setup
-inline void output_setup(void)
+inline void output_setup()
 {
 	// Initialize the USB, and then wait for the host to set configuration.
 	// If the Teensy is powered without a PC connected to the USB port,
@@ -105,3 +105,13 @@
 		scan_finishedWithUSBBuffer( USBKeys_Sent <= USBKeys_MaxSize ? USBKeys_Sent : USBKeys_MaxSize );
 }
 
+
+// Sets the device into firmware reload mode
+inline void output_firmwareReload()
+{
+#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
+#elif defined(_mk20dx128_)
+	usb_device_reload();
+#endif
+}
+
--- a/Output/pjrcUSB/output_com.h	Wed Jan 22 01:58:34 2014 -0800
+++ b/Output/pjrcUSB/output_com.h	Thu Jan 23 02:01:12 2014 -0800
@@ -58,7 +58,9 @@
 
 // ----- Functions -----
 
-void output_setup(void);
+void output_setup();
+
+void output_firmwareReload();
 
 #endif
 
--- a/setup.cmake	Wed Jan 22 01:58:34 2014 -0800
+++ b/setup.cmake	Thu Jan 23 02:01:12 2014 -0800
@@ -165,8 +165,10 @@
 	OUTPUT_STRIP_TRAILING_WHITESPACE
 )
 string( LENGTH "${Git_Modified_INFO}" Git_Modified_LENGTH )
+set( Git_Modified_Status "Clean" )
 if ( ${Git_Modified_LENGTH} GREATER 2 )
 	string( SUBSTRING "${Git_Modified_INFO}" 1 2 Git_Modified_Flag_INFO )
+	set( Git_Modified_Status "Dirty" )
 endif ()
 
 #| Branch
@@ -186,6 +188,46 @@
 	OUTPUT_STRIP_TRAILING_WHITESPACE
 )
 
+#| Commit Author and Email
+execute_process( COMMAND git show -s --format="%cn <%ce>"
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+	OUTPUT_VARIABLE Git_Commit_Author
+	RESULT_VARIABLE Git_RETURN
+	ERROR_QUIET
+	OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
+#| Commit Revision
+execute_process( COMMAND git show -s --format=%H
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+	OUTPUT_VARIABLE Git_Commit_Revision
+	RESULT_VARIABLE Git_RETURN
+	ERROR_QUIET
+	OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
+#| Origin URL
+execute_process( COMMAND git config --get remote.origin.url
+	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+	OUTPUT_VARIABLE Git_Origin_URL
+	RESULT_VARIABLE Git_RETURN
+	ERROR_QUIET
+	OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
+#| Date Macro
+macro ( dateNow RESULT )
+	if ( WIN32 )
+		execute_process( COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT} OUTPUT_STRIP_TRAILING_WHITESPACE )
+	elseif ( UNIX )
+		execute_process( COMMAND "date" "+%Y-%m-%d %T %z" OUTPUT_VARIABLE ${RESULT} OUTPUT_STRIP_TRAILING_WHITESPACE )
+	else ()
+		message( send_error "date not implemented" )
+		set( ${RESULT} 000000 )
+	endif ()
+endmacro (dateNow)
+dateNow( Build_Date )
+
 
 #| Only use Git variables if we were successful in calling the commands
 if ( ${Git_RETURN} EQUAL 0 )