# Coastal Profiling Float, C++ Edition

**Table of Contents:**

1. [Building the Project](#building-the-project)
2. [Documentation](#documentation)
3. [File Structure and Layering](#file-structure-and-layering)

## Building the Project

This project builds with CMake, and is based on the [Embedded Artistry CMake build infrastructure](https://github.com/embeddedartistry/cmake-buildsystem). This project is also configured to be built with VisualGDB, and unit tests can be compiled in MSVC on Windows as well.

Make shims are put in place to make the build easier. You can run:

```
# Build unit test targets for your native platform
$ make

# Cross-compile to build the main application and on-device tests
$ make CROSS=1
```

Additional commands are provided. Run `make help` for more information. Makefile usage examples can be [found on this page](https://embeddedartistry.com/fieldatlas/embedded-artistrys-standardized-meson-build-system/).

## Documentation

The `docs` folder contains useful development and architecture documentation for you to refer to.

- [decisions](docs/decisions/) records significant architectural decisions and their rationale
- [DesignDocs](docs/DesignDocs/) contains UML diagrams and other useful design documentation

There are also a number of useful developer instructions:

- [AddingANewState.md](docs/AddingANewState.md) describes the process of adding new system states and new state actions
- [BuildSystem.md](docs/BuildSystem.md) provides pointers for handling common tasks within the build system
- [ConnectingANewDevice.md](docs/ConnectingANewDevice.md) describes the process of adding taking a new driver (e.g., GPS) and connecting it to the appropriate bus (e.g., DMA-enabled UART)
- [EventSystemREADME.md](docs/EventSystemREADME.md) provides an overview of working with events. This provides instructions for defining new events and generating events
- [MemoryRegions.md](docs/MemoryRegions.md) describes different memory regions in the CPF system and how to control where data gets placed
- [PowerManagement_README.md](docs/PowerManagement_README.md) describes the different power states in the system and how low-power modes work
- [Testing.md](docs/Testing.md) contains notes on working with the various test programs

## File Structure and Layering

The [`CPF`](CPF/) folder contains the source code for this system.

The code is organized according to the following layering hierarchy, starting from the "bottom" up. Layers can use the capabilities provided by lower layers, but not higher layers.

- [Interfaces](CPF/Interfaces) defines abstract interfaces that are safe to use throughout the system
- [Support](CPF/Support/) contains a catch-all for common, platform-independent code that can be utilized by multiple components in the system. This includes:
	+ Controls algorithms
	+ Utilities like endianness swapping, safer volatile-operations
	+ Logger
	+ Queues
- [HwPlatform](CPF/HwPlatform/) contains all of the code related to the Hardware Platform / bsp.
	+ This is where you will find things like STM32 processor configuration code, processor peripheral drivers, external component drivers, and the BSP abstractions.
	+ The Hardware Platform layer also has its own internal layered hierarchy:
		- [STM32H7](CPF/HwPlatform/), which contains startup code, core processor configuration, and interrupt/exception handler defaults
		- [Devices](CPF/HwPlatform/Devices), which contains drivers for non-processor components
		- [FatFs](CPF/HwPlatform/FatFs/), which contains device-specific code related to the FAT filesystem that is used on the SDCard
		- [SDLogger](CPF/HwPlatform/SDLogger), which contains the SD driver code and the SD logger implementation
		- [bsp](CPF/HwPlatform/bsp), which contains the implementation of the hardware-layer abstractions that are used by the hardware-independent portions of the system
			+ STM32 peripheral driver implementations are found here as well
- [ErrorHandler](CPF/ErrorHandler/) contains the system error handler implementation
- [State](CPF/State/), which contains the implementations for the system-level states and their actions

For more information on the structure of the build system, see [docs/BuildSystem.md](docs/BuildSystem.md).

Top-level application logic is kept in the top-level CPF folder:

- main.cpp kicks off the application
- CPFStateProcessing.cpp contains the main event/state processing loop code

External dependencies are kept in a separate source tree within the `external` folder. This includes components like:

- cpputest for unit testing
- ETL for static-memory containers, useful embedded frameworks, and other items
- FatFs common code
- stm32h7 SDK
- SysProgsProfiler, which handles profiling and semihosting when debugging
