avrsysh: A simple shell with some built-in utilities (and pong, of course!)

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 as it is configured assumes a 16 MHz core clock, as it is configured 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 with 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); up/down (player 2); space to resume; 'Q' to quit
    • At 24 frames per second, it uses approximately 30-40% of available CPU cycles at 16 MHz (as measured by the "CPU usage" utility)