brewing-logger:firmware.git
4 years agosd-card: Only add header to the results file if it’s empty
Philip Withnall [Sun, 9 Dec 2012 22:57:40 +0000 (22:57 +0000)]
sd-card: Only add header to the results file if it’s empty

This fixes commit 872947711af1ac0aa8837ee0de32a8eb416b0afc, where I did
intend to wrap the whole lot in an ‘if’ statement, but apparently forgot
to do so before committing.

4 years agomain: Take a set of sensor readings before enabling the UI
Philip Withnall [Sun, 9 Dec 2012 22:56:55 +0000 (22:56 +0000)]
main: Take a set of sensor readings before enabling the UI

This prevents the possibility of the user pressing the UI button and viewing
sensor readings before the first set of sensor readings have actually been
taken.

4 years agomain: Remove some unnecessary zero padding from output printf formats
Philip Withnall [Sun, 9 Dec 2012 22:56:32 +0000 (22:56 +0000)]
main: Remove some unnecessary zero padding from output printf formats

4 years agolcd: Take the LCD data line low when powering down the LCD
Philip Withnall [Sun, 9 Dec 2012 22:55:40 +0000 (22:55 +0000)]
lcd: Take the LCD data line low when powering down the LCD

This prevents it continuing to partially power the LCD controller, and drawing
~28mA for no good reason.

4 years agoflash-rom, sd-card: Add comments about endianness in storage
Philip Withnall [Sun, 9 Dec 2012 22:54:12 +0000 (22:54 +0000)]
flash-rom, sd-card: Add comments about endianness in storage

Everyone loves endianness. Especially when it’s little.

4 years agobuild: Add -ggdb flag to CFLAGS for firmware and simulator
Philip Withnall [Sun, 9 Dec 2012 13:51:51 +0000 (13:51 +0000)]
build: Add -ggdb flag to CFLAGS for firmware and simulator

This doesn’t affect the firmware which gets put on to the physical
microcontroller, since the conversion from ELF to HEX removes it. However,
it does mean that debug information is available when running the firmware
under the simulator, which is very useful.

4 years agosd-card: Add a header and checksums to the brew results file
Philip Withnall [Sun, 9 Dec 2012 13:49:48 +0000 (13:49 +0000)]
sd-card: Add a header and checksums to the brew results file

This allows the file to be associated with a brew config file (by its brew
ID), and corrupted log entries to be detected by their checksums.

4 years agobuild: Update .gitignore file
Philip Withnall [Sun, 9 Dec 2012 12:38:10 +0000 (12:38 +0000)]
build: Update .gitignore file

4 years agosimulation: Add conditional support for VCDs of SPI traffic
Philip Withnall [Sun, 9 Dec 2012 12:36:13 +0000 (12:36 +0000)]
simulation: Add conditional support for VCDs of SPI traffic

This was useful when debugging the chip select problems fixed in commit
4439556dcf460b2771beb38a6e9528d1d22843f0.

To enable it, define VCD_SPI somewhere (either on the gcc command line, or
as a temporary edit to simulation/main.c).

4 years agospi: Split SPI bus state from SPI chip selects
Philip Withnall [Sun, 9 Dec 2012 12:31:02 +0000 (12:31 +0000)]
spi: Split SPI bus state from SPI chip selects

It turns out that the FatFs MMC/SPI code wasn’t enabling the SPI bus in
CS_LOW(), so when the bus was disabled by spi_disable() at the end of some
flash-rom.c code, the FatFs code would stall and go into an infinite loop
in rcvr_spi() because the bus wasn’t enabled.

Enabling the bus in CS_LOW() doesn’t work for some reason (possibly a timing
issue, or perhaps a bug in simavr — I haven’t tried it with actual hardware).

The tidiest solution is to split the SPI bus enabled/disabled state from the
state of any of the chip selects, so that the bus is only disabled at the
end of a large transaction, potentially involving multiple slaves.

4 years agosd-card: Document the flushing behaviour of appending results to the SD card
Philip Withnall [Sun, 9 Dec 2012 11:04:15 +0000 (11:04 +0000)]
sd-card: Document the flushing behaviour of appending results to the SD card

Clarify that there is no potential for data loss between appending results
to the SD card and overwriting their checksums on the flash memory.

4 years agosd-card: Remove call to disk_initialize()
Philip Withnall [Sun, 9 Dec 2012 00:21:42 +0000 (00:21 +0000)]
sd-card: Remove call to disk_initialize()

This is called by f_mount(), and calling it a second time could be dangerous.
See: http://elm-chan.org/fsw/ff/en/dinit.html.

4 years agohumidity: Make humidity measurement initialisation more robust
Philip Withnall [Sun, 9 Dec 2012 00:19:25 +0000 (00:19 +0000)]
humidity: Make humidity measurement initialisation more robust

The RHT03 has problems in synchronising with the ‘start’ signal sent by the
microcontroller if the RHT03 has previously been power gated. The changes in
this commit go some way to improving this, but unfortunately the only
reliable solution seems to be to not gate power to the RHT03 in the first
place. Sigh. At least its current consumption is only 3mA.

4 years agolcd: Add a delay after enabling the LCD power domain
Philip Withnall [Sun, 9 Dec 2012 00:18:06 +0000 (00:18 +0000)]
lcd: Add a delay after enabling the LCD power domain

This gives the LCD controller time to boot up, meaning our commands to it
aren’t lost.

4 years agoconfig: Remove some outdated TODOs
Philip Withnall [Sun, 9 Dec 2012 00:17:11 +0000 (00:17 +0000)]
config: Remove some outdated TODOs

4 years agopower: Split sensor power management code out into power.[ch]
Philip Withnall [Sun, 9 Dec 2012 00:16:24 +0000 (00:16 +0000)]
power: Split sensor power management code out into power.[ch]

This allows it to be re-used in the test suite, meaning the test suite works
again.

4 years agohumidity: Disable interrupts while in the humidity sensor critical section
Philip Withnall [Sat, 8 Dec 2012 14:00:05 +0000 (14:00 +0000)]
humidity: Disable interrupts while in the humidity sensor critical section

4 years agometa: Add bug about adding power-down support to the M25P simulation
Philip Withnall [Sat, 8 Dec 2012 11:21:10 +0000 (11:21 +0000)]
meta: Add bug about adding power-down support to the M25P simulation

4 years agomain: Disable various MCU components to save power
Philip Withnall [Sat, 8 Dec 2012 10:50:36 +0000 (10:50 +0000)]
main: Disable various MCU components to save power

Disable various digital inputs, the analogue comparator and the ADC (when
it’s not in use) to save power.

This fixes bug #3dd#.

4 years agoflash-rom: Add support for DP and RES instructions to power down the memory
Philip Withnall [Sat, 8 Dec 2012 10:37:36 +0000 (10:37 +0000)]
flash-rom: Add support for DP and RES instructions to power down the memory

By powering down the flash memory when not in use (which is the vast majority
of time), its current consumption should be reduced by a factor of 5.

4 years agortc: Disable a few RTC features on initialisation
Philip Withnall [Sat, 8 Dec 2012 10:13:33 +0000 (10:13 +0000)]
rtc: Disable a few RTC features on initialisation

This might save a few microamps.

4 years agoheater: Fix controller to use signed fixed point rather than unsigned
Philip Withnall [Sat, 8 Dec 2012 09:51:18 +0000 (09:51 +0000)]
heater: Fix controller to use signed fixed point rather than unsigned

Whoops. Still untested, but this has a better chance of working. Testing it
isn’t really feasible unless I can set up a heater, 20l water bath and a
thermometer, as the operation (and tuning) of the controller will be highly
dependent on the lag in the system.

4 years agomain: Add support for gating power to the sensors
Philip Withnall [Sat, 8 Dec 2012 09:47:04 +0000 (09:47 +0000)]
main: Add support for gating power to the sensors

As with the LCD, the sensors draw a considerable amount of current. For
example, the IR distance sensor draws 17mA and the humidity sensor draws
3mA.

By putting a beefy transistor in the common ground of all the sensors, we can
gate power to them for the long periods of time between sensor readings.

4 years agolcd: Add support for gating power to the LCD
Philip Withnall [Sat, 8 Dec 2012 09:38:16 +0000 (09:38 +0000)]
lcd: Add support for gating power to the LCD

main.c can now control a beefy transistor on the LCD board’s ground. Since the
LCD draws ~60mA, being able to turn it off for the vast majority of the time
is a big win.

4 years agosleep: Fix various bugs with the event handling/sleep code
Philip Withnall [Sat, 8 Dec 2012 09:36:14 +0000 (09:36 +0000)]
sleep: Fix various bugs with the event handling/sleep code

The code wasn’t checking whether the button had been pressed when it woke
up from sleep, meaning it would do some work, loop around and try to go to
sleep again before a button press was detected.

This also includes some tidy up of the UI screens.

4 years agogas: Add support for turning the gas sensor’s heater on/off
Philip Withnall [Sat, 8 Dec 2012 09:32:59 +0000 (09:32 +0000)]
gas: Add support for turning the gas sensor’s heater on/off

This also includes a test case. It modifies the high fuse byte for the
microcontroller to disable the JTAG port, which otherwise takes over various
pins on PORTC.

This also fixes the port configuration for the heater power port.

4 years agometa: Mark some hardware bugs as fixed
Philip Withnall [Fri, 7 Dec 2012 23:54:11 +0000 (23:54 +0000)]
meta: Mark some hardware bugs as fixed

The work for them has been done on the prototyping board and has been
committed to the hardware repository as part of commit
57cb20c9bf5e5a6313931b370844fddbfdc4d15a.

4 years agohumidity: Un-inline functions
Philip Withnall [Fri, 7 Dec 2012 11:57:53 +0000 (11:57 +0000)]
humidity: Un-inline functions

The compiler was warning about them, and the compiler generally has a better
idea about how to optimise things than I do.

4 years agobuild: Fix reference to non-existent common Makefile
Philip Withnall [Thu, 6 Dec 2012 20:02:24 +0000 (20:02 +0000)]
build: Fix reference to non-existent common Makefile

An artifact of the way the directories were restructured before being
rearranged. (The rearrangement isn’t obvious because it was done using
`git filter-branch`.)

4 years agocode: Add lots of missing documentation
Philip Withnall [Thu, 6 Dec 2012 17:11:15 +0000 (17:11 +0000)]
code: Add lots of missing documentation

This doesn’t add all the missing documentation, but does ensure that every
file has a documentation header. This means doxygen will emit warnings for
all the remaining missing documetation. It’s currently emitting 89 warnings.

4 years agocode: Fix SPI pin configuration
Philip Withnall [Thu, 6 Dec 2012 15:05:08 +0000 (15:05 +0000)]
code: Fix SPI pin configuration

4 years agocode: Add a test for the heater code
Philip Withnall [Thu, 6 Dec 2012 12:26:49 +0000 (12:26 +0000)]
code: Add a test for the heater code

4 years agocode: Display a UI message about heater failure if necessary
Philip Withnall [Thu, 6 Dec 2012 12:26:10 +0000 (12:26 +0000)]
code: Display a UI message about heater failure if necessary

4 years agocode: Implement the heater controller and safety mechanisms
Philip Withnall [Thu, 6 Dec 2012 12:13:55 +0000 (12:13 +0000)]
code: Implement the heater controller and safety mechanisms

The heater is controlled using a proportional–integral controller (adding
derivative control would’ve made it too sensitive to the temperature
sampling rate, which varies when the user presses the UI button). The
controller parameters haven’t yet been tuned.

See: http://www.embedded.com/design/prototyping-and-development/4211211/PID-without-a-PhD

This also integrates the heater controller into the main event loop,
including extending the temperature sensor code to add safety limits, and
cutting out the heater if those limits are exceeded. The safety limits define
upper and lower bounds for sensible temperatures — beyond these limits, it’s
assumed that the sensors have failed, and the only safe course of action is
to disable the heater.

4 years agometa: Add some new bugs
Philip Withnall [Thu, 6 Dec 2012 09:09:41 +0000 (09:09 +0000)]
meta: Add some new bugs

4 years agocode: Add a Flash ROM test
Philip Withnall [Wed, 5 Dec 2012 20:39:42 +0000 (20:39 +0000)]
code: Add a Flash ROM test

4 years agocode: Refactor Flash ROM code a lot
Philip Withnall [Wed, 5 Dec 2012 20:37:08 +0000 (20:37 +0000)]
code: Refactor Flash ROM code a lot

This splits a number of bits of flash memory code out into separate, public
functions, and adds a few extra functions; all to make testing easier.

This also fixes various operations which weren’t working when the code
was tested on the actual hardware. This is because I mis-read the M25P16
data sheet, and neglected to take the chip select line low after WREN
instructions.

The simulated M25P16 will need to be updated to correctly reject a WREN
where the chip select isn’t immediately taken high after the instruction
byte is received by the flash memory.

4 years agocode: Add a test for the UI button
Philip Withnall [Wed, 5 Dec 2012 18:12:29 +0000 (18:12 +0000)]
code: Add a test for the UI button

This also tests out the sleep/watchdog code.

4 years agocode: Move the sleep/watchdog code out into a separate file
Philip Withnall [Wed, 5 Dec 2012 18:11:47 +0000 (18:11 +0000)]
code: Move the sleep/watchdog code out into a separate file

This means it can be used by the test suite.

4 years agocode: Disable static assertions if the compiler doesn’t support them
Philip Withnall [Wed, 5 Dec 2012 17:52:37 +0000 (17:52 +0000)]
code: Disable static assertions if the compiler doesn’t support them

The avr-gcc version on the CL machines is only 4.5.3, whereas version 4.6.0
is needed for _Static_assert() support. Emit a warning if static assertions
are disabled.

4 years agocode: Fix comments in diskio licencing headers
Philip Withnall [Wed, 5 Dec 2012 17:52:07 +0000 (17:52 +0000)]
code: Fix comments in diskio licencing headers

4 years agocode: Fix seeking to the end of the results file in the SD card code
Philip Withnall [Tue, 4 Dec 2012 00:00:27 +0000 (00:00 +0000)]
code: Fix seeking to the end of the results file in the SD card code

FatFs does clip seek offsets to the file size, but using (-1) is a bad idea
because it’s the value of a magic constant, CREATE_LINKMAP, which causes the
code to run off into the distance and fill up the entire file system.

Instead, it’s safer to just pass in the file size, which we have access to
anyway as part of the FIL structure.

4 years agocode: Fix handling of unusual return values in SD card code
Philip Withnall [Mon, 3 Dec 2012 23:59:51 +0000 (23:59 +0000)]
code: Fix handling of unusual return values in SD card code

Turns out I can’t write ‘else’ statements correctly.

4 years agocode: Fix f_open() flags used in the SD card code
Philip Withnall [Mon, 3 Dec 2012 23:58:32 +0000 (23:58 +0000)]
code: Fix f_open() flags used in the SD card code

Having now read the documentation for FatFs, the meaning of the various flags
is clearer. We were truncating files if they already existed, or failing to
open files if they already existed. This was bad.

See: http://elm-chan.org/fsw/ff/en/open.html

4 years agosimulation: Ensure the M25P is initialised to all 1s
Philip Withnall [Mon, 3 Dec 2012 23:26:35 +0000 (23:26 +0000)]
simulation: Ensure the M25P is initialised to all 1s

The data sheet specifies that it’s supplied with its status register as all
0s, and its data area as all 1s. Comply with that.

4 years agosimulation: Fix address handling in the M25P simulation
Philip Withnall [Mon, 3 Dec 2012 23:24:59 +0000 (23:24 +0000)]
simulation: Fix address handling in the M25P simulation

Typo. Doh.

4 years agocode: Various fixes to the Flash ROM code as a result of testing
Philip Withnall [Mon, 3 Dec 2012 23:21:54 +0000 (23:21 +0000)]
code: Various fixes to the Flash ROM code as a result of testing

I’m fairly confident the ring buffer in the flash memory will behave properly
now. The only which hasn’t been tested is the bus interaction between the
flash memory and the SD card when flushing, since the simulation stalls when
handing over from the flash memory to the SD card. I’m unsure why this
happens — something about the simulation not implementing a virtual pull-up
resistor for the bus wire, perhaps?

4 years agometa: Add a COPYING file to make the licencing more obvious
Philip Withnall [Mon, 3 Dec 2012 14:52:37 +0000 (14:52 +0000)]
meta: Add a COPYING file to make the licencing more obvious

With a few exceptions (in the Code/lib directory), all code in this project
is licenced under the GPLv3+.

4 years agocode: Clarify licencing of code in the ‘lib’ directory
Philip Withnall [Mon, 3 Dec 2012 14:39:31 +0000 (14:39 +0000)]
code: Clarify licencing of code in the ‘lib’ directory

The ff.[ch], diskio.[ch] and ffconf.h files are from FatFs by ChaN, licenced
under a BSD-style licence.

See: http://elm-chan.org/fsw/ff/en/appnote.html#license

The ds3231.[ch], i2c.[ch] and serial_lcd.[ch] files are by Brian Jones
at the University of Cambridge Computer Lab, and are released under a
GPLv3+ licence. Permission for this licencing was obtained by private
e-mail on 2012-12-03.

See: http://www.cl.cam.ac.uk/research/dtg/www/people/bdj23/

4 years agocode: Tidy up assertions and non-nulls
Philip Withnall [Mon, 3 Dec 2012 14:18:08 +0000 (14:18 +0000)]
code: Tidy up assertions and non-nulls

4 years agosimulation: Remove lingering debug output from the M25P simulation
Philip Withnall [Mon, 3 Dec 2012 13:52:50 +0000 (13:52 +0000)]
simulation: Remove lingering debug output from the M25P simulation

4 years agocode: Implement the main UI
Philip Withnall [Mon, 3 Dec 2012 13:51:36 +0000 (13:51 +0000)]
code: Implement the main UI

4 years agocode: Fix some signed/unsigned comparisons in the gas sensor code
Philip Withnall [Mon, 3 Dec 2012 13:49:44 +0000 (13:49 +0000)]
code: Fix some signed/unsigned comparisons in the gas sensor code

4 years agocode: Fix gas sensor interpolation code after some testing
Philip Withnall [Mon, 3 Dec 2012 12:00:56 +0000 (12:00 +0000)]
code: Fix gas sensor interpolation code after some testing

I’m still not entirely convinced it’s right, since I haven’t had a chance
to calibrate the sensor yet. The most obvious bugs have been fixed after
some simulation, though.

4 years agometa: Mark two hardware bugs as fixed
Philip Withnall [Mon, 3 Dec 2012 10:24:51 +0000 (10:24 +0000)]
meta: Mark two hardware bugs as fixed

4 years agocode: Fix conversion of temperature readings
Philip Withnall [Sun, 2 Dec 2012 20:13:06 +0000 (20:13 +0000)]
code: Fix conversion of temperature readings

This has now been tested. The MCP9700 isn’t a particularly accurate
thermometer, with temperatures varying by ±3V between consecutive
readings. The data sheet does have some notes on improving the accuracy
to ±0.5V, but that’s still not really good enough. Looks like I’ll have
to get some different temperature sensors. The MCP9700s will do for now
though.

4 years agocode: Fix krausen level code to correctly give results in mm rather than cm
Philip Withnall [Sun, 2 Dec 2012 18:36:21 +0000 (18:36 +0000)]
code: Fix krausen level code to correctly give results in mm rather than cm

This improves resolution by a factor of 10, for free. That’s good, because
that was the original design.

4 years agocode: Eliminate floating point from the ADC code
Philip Withnall [Sun, 2 Dec 2012 18:28:00 +0000 (18:28 +0000)]
code: Eliminate floating point from the ADC code

Push floating point calculations to compile time, so that values are stored
in constant tables as AdcReadings, rather than as floats. This shaves a
good 1KiB off the compiled code size and should speed things up too (though
I haven’t measured this).

4 years agocode: Add a test for the gas concentration sensor
Philip Withnall [Sun, 2 Dec 2012 17:00:35 +0000 (17:00 +0000)]
code: Add a test for the gas concentration sensor

4 years agocode: Add support for a UI input button
Philip Withnall [Sun, 2 Dec 2012 16:21:35 +0000 (16:21 +0000)]
code: Add support for a UI input button

This includes debounce code, race-less integration with the sleep code in
main.c, and a first attempt at using it to trigger display of a UI.

As always, completely untested.

4 years agocode: Fix whitespace in main.c
Philip Withnall [Sun, 2 Dec 2012 15:21:42 +0000 (15:21 +0000)]
code: Fix whitespace in main.c

Somehow it had ended up with Windows line endings. Ewww…

4 years agocode: Tidy up a function call
Philip Withnall [Sun, 2 Dec 2012 15:21:15 +0000 (15:21 +0000)]
code: Tidy up a function call

It was missing a layer of abstraction.

4 years agocode: Change units for gas concentration measurements
Philip Withnall [Sun, 2 Dec 2012 14:09:34 +0000 (14:09 +0000)]
code: Change units for gas concentration measurements

The gas concentration is now stored in hundredths of a milligram per litre,
using fixed point notation (factor 100). This also implements all the
interpolation code necessary to convert an ADC measurement from the gas
sensor into a gas concentration in milligrams per litre. Writing all the
code to adjust for temperature and humidity was not fun.

As always, this is completely untested.

4 years agocode: Improve error handling when taking sensor measurements
Philip Withnall [Sat, 1 Dec 2012 21:54:51 +0000 (21:54 +0000)]
code: Improve error handling when taking sensor measurements

If a sensor measurement turns out to be invalid, only that measurement in
the LogEntry is anulled, rather than (for example) aborting the whole
LogEntry. This does require any consumers of the data to be aware of the
special invalid values, but this isn’t too much to ask.

4 years agometa: Move TODO list to Bugs Everywhere
Philip Withnall [Sat, 1 Dec 2012 00:34:38 +0000 (00:34 +0000)]
meta: Move TODO list to Bugs Everywhere

Also remove some outdated planning metadata.

4 years agosimulation: Add a simulated Flash ROM peripheral
Philip Withnall [Sat, 1 Dec 2012 00:04:57 +0000 (00:04 +0000)]
simulation: Add a simulated Flash ROM peripheral

This simulates the M25P16, but the simulation has been written so that it
can be (fairly) easily generalised to other members of the M25P Flash memory
family. They all use the same instruction set and have the same set of
registers. Timings and capacities differ between them.

The simulation is mostly there, but is missing a few things:
 • Support for the Write Protect and Hold pins.
 • Realistic timeouts on operations (they currently all complete in delta
   time).
 • Write protection using Write Protect and SRWD.
 • Power-down support, including the DP and RES instructions.
 • Support for any variants of the M25P other than the M25P16.

4 years agosimulation: Remove some unnecessary debug spew from the simulated SD card
Philip Withnall [Sat, 1 Dec 2012 00:01:06 +0000 (00:01 +0000)]
simulation: Remove some unnecessary debug spew from the simulated SD card

4 years agocode: Ensure the Flash ROM is initialised during boot
Philip Withnall [Sat, 1 Dec 2012 00:00:46 +0000 (00:00 +0000)]
code: Ensure the Flash ROM is initialised during boot

4 years agocode: Add support for SPI chip selection
Philip Withnall [Fri, 30 Nov 2012 23:59:21 +0000 (23:59 +0000)]
code: Add support for SPI chip selection

It was notably absent from the Flash ROM code, meaning the Flash ROM never
actually got selected. Whoops.

4 years agocode: Rename some enum values in the Flash ROM
Philip Withnall [Fri, 30 Nov 2012 23:58:40 +0000 (23:58 +0000)]
code: Rename some enum values in the Flash ROM

Make the names more explicit and less likely to collide with symbols defined
by AVR.

4 years agosimulation: Fix chip select pin connection for SD card simulation
Philip Withnall [Fri, 30 Nov 2012 17:01:53 +0000 (17:01 +0000)]
simulation: Fix chip select pin connection for SD card simulation

4 years agosimulation: Disable debugging in the simulated SD card
Philip Withnall [Fri, 30 Nov 2012 16:54:51 +0000 (16:54 +0000)]
simulation: Disable debugging in the simulated SD card

4 years agometa: Add bug tracking using Bugs Everywhere
Philip Withnall [Fri, 30 Nov 2012 16:50:44 +0000 (16:50 +0000)]
meta: Add bug tracking using Bugs Everywhere

As an experiment, I’m going to track the bugs in this project using Bugs
Everywhere (from now on).

http://bugseverywhere.org/

It’s a distributed bug tracker with a nice command line interface, and good
integration with git. I’ll see how it goes.

4 years agosimulation: Add a SIGINT signal handler to exit the simulation gracefully
Philip Withnall [Fri, 30 Nov 2012 16:12:29 +0000 (16:12 +0000)]
simulation: Add a SIGINT signal handler to exit the simulation gracefully

4 years agocode: Use an SFD partition table rather than an FDISK one
Philip Withnall [Fri, 30 Nov 2012 16:11:27 +0000 (16:11 +0000)]
code: Use an SFD partition table rather than an FDISK one

This stops Linux complaining when I try to mount the simulator’s SD card
image as a loopback file system. Obviously it doesn’t expect loopback file
systems to have their own partition tables and MBRs.

4 years agosimulation: Add a simulated SD card peripheral
Philip Withnall [Fri, 30 Nov 2012 16:08:48 +0000 (16:08 +0000)]
simulation: Add a simulated SD card peripheral

This takes an image file and presents it as an SD card on the SPI bus of
the microcontroller.

The peripheral is very much a work in progress, but works well enough for
the firmware to boot, create a FAT file system and create and use a default
brew config. This is good enough for now.

4 years agosimulation: Ensure serial LCD output is flushed regularly
Philip Withnall [Thu, 29 Nov 2012 13:32:03 +0000 (13:32 +0000)]
simulation: Ensure serial LCD output is flushed regularly

Otherwise we can get to the end of the test run and never see the last few
lines of output because they’re still in a buffer somewhere.

4 years agosimulation: Add a simulated RHT03 peripheral
Philip Withnall [Thu, 29 Nov 2012 13:27:15 +0000 (13:27 +0000)]
simulation: Add a simulated RHT03 peripheral

This simulates the RHT03 humidity/temperature sensor. The simulation isn’t
quite cycle accurate, but does behave fairly similarly to the actual device.

More involved testing functionality, such as being able to send back invalid
checksums, isn’t (yet) implemented.

4 years agosimulation: Add a simulated DS3231 RTC peripheral
Philip Withnall [Thu, 29 Nov 2012 10:43:44 +0000 (10:43 +0000)]
simulation: Add a simulated DS3231 RTC peripheral

This is only very roughly implemented. It doesn’t really do anything except
accept bus reads and writes — reads always return 0, and writes are ignored.
This is enough to get the firmware to boot, however, if the call to
reset_rtc_i2c() is removed from the firmware. Having tried for a few hours,
I can find no way to get the firmware to see MISO as high on boot.

4 years agobuild: Improve ‘simulate’ target in the Makefile
Philip Withnall [Wed, 28 Nov 2012 23:29:45 +0000 (23:29 +0000)]
build: Improve ‘simulate’ target in the Makefile

4 years agosimulation: Allow the gdb port to be specified on the command line
Philip Withnall [Wed, 28 Nov 2012 23:26:00 +0000 (23:26 +0000)]
simulation: Allow the gdb port to be specified on the command line

If a port isn’t specified, gdb support isn’t initialised.

4 years agocode: Explicitly set the default states on the LCD DATA/CLK lines
Philip Withnall [Wed, 28 Nov 2012 23:25:34 +0000 (23:25 +0000)]
code: Explicitly set the default states on the LCD DATA/CLK lines

The DATA line should be normally high.

4 years agosimulation: Add a simulated serial LCD peripheral
Philip Withnall [Wed, 28 Nov 2012 23:24:43 +0000 (23:24 +0000)]
simulation: Add a simulated serial LCD peripheral

The way it outputs the LCD screen to the console is a bit clunky, but it
works for now.

4 years agosimulation: Add the beginnings of a simavr-based simulator for the project
Philip Withnall [Wed, 28 Nov 2012 20:54:29 +0000 (20:54 +0000)]
simulation: Add the beginnings of a simavr-based simulator for the project

This will load the ELF file built for the MCU and run it in a simulated MCU
provided by simavr, coupled together with software-simulated peripherals.

See: https://gitorious.org/simavr/pages/GetStarted#Virtual+PCB+with+simavr

4 years agocode: Fix the defined reference voltage for the MCU
Philip Withnall [Wed, 28 Nov 2012 18:03:26 +0000 (18:03 +0000)]
code: Fix the defined reference voltage for the MCU

4 years agocode: Implement periodic flushing of the Flash ROM to the SD card
Philip Withnall [Wed, 28 Nov 2012 17:59:35 +0000 (17:59 +0000)]
code: Implement periodic flushing of the Flash ROM to the SD card

As usual, this is completely untested. I also haven’t yet worked out how the
user will be notified of failures.

4 years agocode: Initialise the sensors in main()
Philip Withnall [Wed, 28 Nov 2012 17:59:28 +0000 (17:59 +0000)]
code: Initialise the sensors in main()

4 years agocode: Fix tests which use the ADC
Philip Withnall [Wed, 28 Nov 2012 17:21:51 +0000 (17:21 +0000)]
code: Fix tests which use the ADC

The ADC requires interrupts to be enabled, but we weren’t enabling them in
the test code.

4 years agobuild: Remove a compiler flag which isn’t supported on the lab machines
Philip Withnall [Wed, 28 Nov 2012 15:47:56 +0000 (15:47 +0000)]
build: Remove a compiler flag which isn’t supported on the lab machines

Silly lab machines.

4 years agocode: Change units for humidity measurements
Philip Withnall [Wed, 28 Nov 2012 15:46:59 +0000 (15:46 +0000)]
code: Change units for humidity measurements

Humidity measurements are now stored as 16-bit fixed point numbers, with a
factor of 10. i.e. Each measurement is stored in tenths of a percentage
point of relative humidity. The maximum permissible value is 1000,
corresponding to 100.0% relative humidity.

4 years agocode: Change units for krausen level
Philip Withnall [Wed, 28 Nov 2012 13:56:03 +0000 (13:56 +0000)]
code: Change units for krausen level

The krausen level is now stored as a fixed point number of centimetres
(effectively a number of millimetres, since the factor is 10). The code to
convert the ADC reading from the proximity sensor to a distance has also been
written (but is untested).

4 years agocode: Change units for temperature
Philip Withnall [Wed, 28 Nov 2012 12:47:35 +0000 (12:47 +0000)]
code: Change units for temperature

Temperatures are now uniformly represented as a fixed point value in tenths
of a degree Celsius. e.g. 215 represents 21.5℃.

This also implements scaling/conversion of temperatures measured by the
MCP9700 sensors (untested).

4 years agocode: Add measurement code for the krausen level using the proximity sensor
Philip Withnall [Wed, 28 Nov 2012 11:07:24 +0000 (11:07 +0000)]
code: Add measurement code for the krausen level using the proximity sensor

Another simple ADC input.

4 years agocode: Fix various compiler warnings in the library code
Philip Withnall [Wed, 28 Nov 2012 11:00:29 +0000 (11:00 +0000)]
code: Fix various compiler warnings in the library code

4 years agocode: Handle checksum failures on boot
Philip Withnall [Wed, 28 Nov 2012 10:52:32 +0000 (10:52 +0000)]
code: Handle checksum failures on boot

4 years agocode: Fix various compiler warnings
Philip Withnall [Tue, 27 Nov 2012 19:43:50 +0000 (19:43 +0000)]
code: Fix various compiler warnings

4 years agocode: Add some documentation comments
Philip Withnall [Tue, 27 Nov 2012 19:06:56 +0000 (19:06 +0000)]
code: Add some documentation comments

4 years agobuild: Enable a load of extra compiler warnings
Philip Withnall [Tue, 27 Nov 2012 18:47:23 +0000 (18:47 +0000)]
build: Enable a load of extra compiler warnings

4 years agocode: Tidy up handling of response enums in sd-card.[ch]
Philip Withnall [Tue, 27 Nov 2012 18:46:49 +0000 (18:46 +0000)]
code: Tidy up handling of response enums in sd-card.[ch]

4 years agobuild: Add simulation support using simavr
Philip Withnall [Tue, 27 Nov 2012 18:11:37 +0000 (18:11 +0000)]
build: Add simulation support using simavr

This runs the built ELF file, but doesn’t get too far because none of the
peripherals are simulated (at the moment).