]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Adding chip usage display after build completion.
authorJacob Alexander <haata@kiibohd.com>
Sat, 19 Apr 2014 07:10:28 +0000 (00:10 -0700)
committerJacob Alexander <haata@kiibohd.com>
Sat, 19 Apr 2014 07:10:28 +0000 (00:10 -0700)
- Uses an internal database of microcontroller sizes

Lib/CMake/arm.cmake
Lib/CMake/avr.cmake
Lib/CMake/modules.cmake
Lib/CMake/sizeCalculator [new file with mode: 0755]

index 6045afcb85726971a97402380a22534e0e82a11f..c8e5ce6476585b10a4178f8ad7b1cb76a4cec246 100644 (file)
@@ -33,6 +33,23 @@ message( "${CHIP}" )
 set( MCU "${CHIP}" ) # For loading script compatibility
 
 
+#| Chip Size Database
+#| Teensy 3.0
+if ( "${CHIP}" MATCHES "mk20dx128" )
+       set( SIZE_RAM    16384 )
+       set( SIZE_FLASH 131072 )
+
+#| Teensy 3.1
+elseif ( "${CHIP}" MATCHES "mk20dx256" )
+       set( SIZE_RAM    65536 )
+       set( SIZE_FLASH 262144 )
+
+#| Unknown ARM
+else ()
+       message( AUTHOR_WARNING "CHIP: ${CHIP} - Unknown ARM microcontroller" )
+endif ()
+
+
 #| Chip Base Type
 #| Automatically chosed based on the chip name.
 if ( "${CHIP}" MATCHES "^mk20dx.*$" )
index b191fe76a14f24231be56fac2cbcee68435e49f8..f27efb9272ac177464dd53536a4d03b4c1d6f816 100644 (file)
@@ -36,6 +36,33 @@ message( STATUS "MCU Selected:" )
 message( "${MCU}" )
 
 
+#| Chip Size Database
+#| Teensy 1.0
+if ( "${CHIP}" MATCHES "at90usb162" )
+       set( SIZE_RAM      512 )
+       set( SIZE_FLASH  15872 )
+
+#| Teensy 2.0
+elseif ( "${CHIP}" MATCHES "atmega32u4" )
+       set( SIZE_RAM     2560 )
+       set( SIZE_FLASH  32256 )
+
+#| Teensy++ 1.0
+elseif ( "${CHIP}" MATCHES "at90usb646" )
+       set( SIZE_RAM     4096 )
+       set( SIZE_FLASH  64512 )
+
+#| Teensy++ 2.0
+elseif ( "${CHIP}" MATCHES "at90usb1286" )
+       set( SIZE_RAM     8192 )
+       set( SIZE_FLASH 130048 )
+
+#| Unknown AVR
+else ()
+       message( AUTHOR_WARNING "CHIP: ${CHIP} - Unknown AVR microcontroller" )
+endif ()
+
+
 #| Extra Compiler Sources
 #| Mostly for convenience functions like interrupt handlers
 set( COMPILER_SRCS
index dad2edb8695060414910adc86a2c6c6892ada41e..689725d20f73c9a97f462bb14c5e3d0e02934974 100644 (file)
@@ -67,7 +67,6 @@ add_definitions(
 
 
 
-
 ###
 # Module Processing
 #
@@ -286,11 +285,11 @@ add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
 #
 
 #| After Changes Size Information
-#| TODO Do lookup on Flash and RAM sizes and do % used
 add_custom_target( SizeAfter ALL
-       COMMAND ${CMAKE_SIZE} --target=${FORMAT} ${TARGET_HEX} ${TARGET_ELF}
+       COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ${FORMAT} ${TARGET_ELF} ${SIZE_RAM}   " SRAM"
+       COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ${FORMAT} ${TARGET_HEX} ${SIZE_FLASH} "Flash"
        DEPENDS ${TARGET_ELF}
-       COMMENT "Size after generation\n\tFlash Usage: data (hex)\n\t  RAM Usage: data (elf)"
+       COMMENT "Chip usage for ${CHIP}"
 )
 
 
diff --git a/Lib/CMake/sizeCalculator b/Lib/CMake/sizeCalculator
new file mode 100755 (executable)
index 0000000..1bf814e
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/bash
+#| Jacob Alexander 2014
+#| Arg List
+#| 1 - size binary   (e.g. avr-size)
+#| 2 - target binary (e.g. ihex)
+#| 3 - binary file   (e.g. kiibohd.hex)
+#| 4 - total available (flash/ram) in bytes
+#| 5 - flash/ram
+
+
+# Looks for the data column, to get the flash/ram used (in bytes)
+# <size binary> --target=<target binary> <binary file> | cut -f2 | tail -n 1
+USED=$("$1" --target="$2" "$3" | cut -f2 | tail -n 1)
+
+# Calculates the total flash/ram used
+TOTAL="$4"
+PERCENTAGE=$((USED * 100 / TOTAL))
+
+# Size Colours
+# Red/Flashing - Almost full
+if (( PERCENTAGE > 95 )); then
+       COLOR="\t\033[1;5;31m"
+# Red - Getting full
+elif (( PERCENTAGE > 90 )); then
+       COLOR="\t\033[1;31m"
+
+# Yellow - Starting to fill up
+elif (( PERCENTAGE > 50 )); then
+       COLOR="\t\033[1;33m"
+
+# Green - Lots of room
+else
+       COLOR="\t\033[1;32m"
+fi
+
+# Displays Results
+NAME="$5"
+echo -e "\t\033[1m${NAME}\033[m: ${COLOR}${PERCENTAGE}%\033[m ${USED}/${TOTAL}\tbytes"
+
+exit 0
+