Electronic – Multiple AVR Projects Sharing Code – Managing Large Projects

avrcodelibrary

I'm working on a group project that is based around designing an automotive CAN bus system. Essentially there are multiple different nodes on the bus, acting as sensors, displays, controllers or transmitters. My question is how to share/include common code?

Each node is based around an Atmel AVR µC, usually an Atmega or Attiny. All the nodes are making use of Microchip MCP2515 CAN Controllers and MCP2561 CAN Transceivers. Our team consists of multiple members each working on their own nodes. We are using Github & SourceTree for source control.

Some code is common to each node, mainly the SPI/CAN functions for TX and RX. We have this working at proof of concept level at the moment. I'm used to working on individual projects however I'm lost as how to share code among projects effectively.

Really what I would like to do is have each node's code in its own directory and then have the common 'library' code in a directory that is referenced in each nodes source code. This way changes to the 'library' code only need to happen in one place and not in multiple copies.

Something like this:

Code>>
Display Node>>
Display_main.c
Sensor Node>>
Sensor_main.c
TX Node>>
TX_main.c
Shared lib>>
SPI.c
SPI.h
MCP2515_func.c
MCP2515_func.h

I am using Eclipse + AVR plugin for my dev, other members are using Atmel Studio.

I'm not too sure if I should:
a) Lump all the shared code in a folder and #include "../Shared lib/xxxx.h"

b) Lump all the shared code in a folder and set Eclipse compiler to include this folder? then #include "xxxx.h" will work ? (what about ATStudio friends? )

c) Create an Eclipse project without a main.c, that contains all the code and include this project with my other projects?

d) Compile the code into a 'static library' ?

I've done a fair bit of research and haven't found any good idea of direction. I guess it comes down to how to manage multiple code projects (nodes) by multiple members on multiple platforms ? I seem to be pretty good at basic stuff but this is the next level in code organization for me.

EDIT:

To add to this question, how could I create a Github project with all my own custom librarys and macros that I can keep updated and then just include in any project I work on?

Best Answer

Your option b is probably the most reasonable. Every environment should be able to set library paths. Another option is to decouple the build from the IDE with makefiles and set the library path there. I know AVR studio supports makefile-based projects. I presume eclipse does as well. This could be a good option to look at if you have different people on the team using different IDEs.

As for a github repo for libraries, I recommend using git subtree. This will include the entire history of the library inside the project repos and allows commits to be pulled into the project repos from the library repo or sectioned off in the project repo and pushed back to the library repo. I use this setup for a bunch of my projects; take a look at my github and look for repos with a lib folder in the root, such as verilog-ethernet.