avrsysh: A system/shell with some built-in utilities and some games

ls4096's picture
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Type: 

Compiler/Assembler: 

I've been working on this small software project, mainly to experiment with the capabilities of the ATmega328P. It has been interesting to see how much can be done using as few resources as possible, and while nothing here is particularly novel, I am sharing this project in the hopes that maybe some of the code or ideas within might be useful to others.

 

Note that this code has only been tested on the ATmega328P (on an Arduino board), but it should mostly run fine on many other AVR MCUs, subject to the code and data memory constraints, as long as the USART and timer are present. Additionally, the build script without modification assumes a 16 MHz core clock, as is the default on the Arduino boards it was tested on. If running with a different clock, the F_CPU value should be modified accordingly. Other things may also misbehave at different clocks (such as the ADC, where the prescale factor used may need to be changed, and possibly the serial communication if the timings don't quite match up), but it should be possible to resolve these with just some minor code changes if necessary.

 

Some ATmega328P functionality used:

  • Timer
  • Serial communication using the USART
  • ADC to estimate chip's internal temperature
  • Some very basic power management using the "sleep" instruction

 

Features of "avrsysh" include:

  • A lightweight "shell" in which to launch built-in commands
    • with limited use of VT100 codes to support "backspace", "up" for previous command, and for clearing the screen
  • Some system utilities, including a "CPU usage" counter and a stack pointer monitor which samples stack memory usage over time
  • Random number generator
    • LCG algorithm with some added entropy based on USART RX timings
  • Pong
    • 'w'/'s' (player 1); 'o'/'l' (player 2); space to resume; 'Q' to quit
    • at 24 frames per second, it consumes approximately 10% of available CPU cycles at 16 MHz (as measured by the "CPU usage" utility)
  • Snake
    • "wasd" to control direction; space to resume; 'Q' to quit
    • at 12 frames per second, it consumes less than 5% of available CPU cycles at 16 MHz (as measured by the "CPU usage" utility)
  • Bricks
    • 'a'/'d' to control; space to resume; 'Q' to quit
    • at 24 frames per second, it consumes approximately 10-15% of available CPU cycles at 16 MHz (as measured by the "CPU usage" utility)

 

Startup and "help" command:

 

System information command and stack pointer monitor:

 

Pong:

 

Snake:

 

Bricks: