Skip to content

Commit

Permalink
Converted build system to cmake, removed redundant file
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter O'Hanley committed Nov 2, 2018
1 parent f25b723 commit d432689
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 82 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
*.a
tmtags*

#CMake
CMakeFiles
CMakeCache.txt
Makefile
cmake_install.cmake

35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
SET(CFLAGS -Wall -Wextra -Wno-missing-braces -Wno-unused-variable -Wno-unused-parameter)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

project(spi_proto)

add_library(spiproto STATIC src/spi_proto.c src/crc16.c src/spi_chunks.cpp)

add_executable(resync_test test/test_resync.c test/test_util.c)
target_link_libraries(resync_test spiproto)
target_include_directories(resync_test PUBLIC src/ PUBLIC test/)

add_executable(spi_test test/spi_proto_tests.c test/test_util.c src/spi_proto_util.c)
target_link_libraries(spi_test spiproto)
target_include_directories(spi_test PUBLIC src/ PUBLIC test/)

add_executable(test_longer_random_messages test/test_longer_random_messages.c test/test_util.c)
target_link_libraries(test_longer_random_messages spiproto)
target_include_directories(test_longer_random_messages PUBLIC src/ PUBLIC test/)

add_executable(chunk_test test/test_chunks.c test/test_util.c src/spi_proto_util.c)
target_link_libraries(chunk_test spiproto)
target_include_directories(chunk_test PUBLIC src/ PUBLIC test/)

#TODO can only run on linux
#click-test: test/click-test.cpp libspiproto.a spi_chunks.o test/test_util.o spi_proto_util.o
# #g++ $(CFLAGS) -o click-test test/click-test.cpp -std=c++14 -pthread spi_chunks.o test/test_util.o spi_proto_util.o -L. -lspiproto -I. -Isrc
# g++ test/click-test.cpp src/spi_proto_master.cpp src/spi_chunks.cpp -std=c++14 -pthread -x c src/binary_semaphore.c -x c src/spi_proto.c -I. -Isrc/ -x c src/crc16.c -x c src/spi_remote_host.c -o click-test -g

#TODO can only run on linux
#blip-test: test/blip-test.cpp libspiproto.a spi_chunks.o test/test_util.o spi_proto_util.o
# #g++ $(CFLAGS) -o blip-test test/blip-test.cpp -std=c++14 -pthread spi_chunks.o test/test_util.o spi_proto_util.o -L. -lspiproto -I. -Isrc
# g++ test/blip-test.cpp src/spi_proto_master_datagram.cpp src/spi_chunks.cpp -std=c++14 -pthread -x c src/binary_semaphore.c -x c src/spi_proto.c -I. -Isrc/ -x c src/crc16.c -x c src/spi_remote_host.c -o blip-test -g
48 changes: 0 additions & 48 deletions Makefile

This file was deleted.

4 changes: 2 additions & 2 deletions src/binary_semaphore.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <pthread.h>
#include "binary_semaphore.h"
#ifdef CPP
#ifdef __cplusplus
extern "C" {
#endif
void bisem_post(struct binary_semaphore *p)
Expand Down Expand Up @@ -37,6 +37,6 @@ bisem_destroy(struct binary_semaphore *p)
pthread_cond_destroy(&p->cvar);
pthread_mutex_destroy(&p->mutex);
}
#ifdef CPP
#ifdef __cplusplus
} // extern
#endif
3 changes: 0 additions & 3 deletions src/config.h

This file was deleted.

4 changes: 3 additions & 1 deletion src/crc16.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
/* ======================================================================== */


#include "config.h"
#include <stdint.h>
typedef uint16_t uint_16;
typedef uint8_t uint_8;
#include "crc16.h"

/* ======================================================================== */
Expand Down
7 changes: 3 additions & 4 deletions src/crc16.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@

#ifndef CRC_16_H_
#define CRC_16_H_ 1

/* ======================================================================== */
/* CRC16_TBL -- Lookup table used for the CRC-16 code. */
/* ======================================================================== */
extern const uint_16 crc16_tbl[256];
extern const uint16_t crc16_tbl[256];

/* ======================================================================== */
/* CRC16_UPDATE -- Updates a 16-bit CRC using the lookup table above. */
Expand All @@ -26,15 +25,15 @@ extern const uint_16 crc16_tbl[256];
/* */
/* All-caps version is a macro for stuff that can use it. */
/* ======================================================================== */
uint_16 crc16_update(uint_16 crc, uint_8 data);
uint16_t crc16_update(uint16_t crc, uint8_t data);
#define CRC16_UPDATE(crc, d) (((crc) << 8) ^ crc16_tbl[((crc) >> 8) ^ (d)])

/* ======================================================================== */
/* CRC16_BLOCK -- Updates a 16-bit CRC on a block of 8-bit data. */
/* Note: The 16-bit CRC is set up as a left-shifting */
/* CRC with no inversions. */
/* ======================================================================== */
uint_16 crc16_block(uint_16 crc, uint_8 *data, int len);
uint16_t crc16_block(uint16_t crc, uint8_t *data, int len);

#endif
/* ======================================================================== */
Expand Down
4 changes: 2 additions & 2 deletions src/spi_chunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "spi_chunks.h"
//#include "spi_chunks_slave.h"

#ifdef CPP
#ifdef __cplusplus
extern "C" {
#endif

Expand Down Expand Up @@ -67,6 +67,6 @@ spi_msg_chunks(uint8_t *buf, size_t len, int (*chunk_handler)(uint8_t *b, size_t
return 0;
}

#ifdef CPP
#ifdef __cplusplus
}
#endif
8 changes: 7 additions & 1 deletion src/spi_chunks.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

#pragma once
#ifdef __cplusplus
extern "C" {
#endif
struct waiting_chunk {
uint8_t buf[SPI_MSG_PAYLOAD_LEN];
//buf[0] is len
Expand All @@ -13,3 +16,6 @@ spi_msg_chunks(uint8_t *buf, size_t len, int (*chunk_handler)(uint8_t *b, size_t
int
chunk_packer(struct waiting_chunk *chunks, size_t numchunk,
uint8_t *buf, size_t len);
#ifdef __cplusplus
}
#endif
11 changes: 4 additions & 7 deletions src/spi_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
#include <stdio.h>
#endif

#ifdef CPP
#ifdef __cplusplus
extern "C" {
#endif
#include "config.h"
#include "crc16.h"
#ifdef CPP
#ifdef __cplusplus
}
#endif

#include "spi_proto.h"

//TODO this was made CPP to fix a linker error, instead determine what was causing the cross-language linking to fail and fix that so this can be pure C

//update the protocol state with a message. Doesn't do any processing of the message itselves
#ifdef CPP
#ifdef __cplusplus
extern "C" {
#endif
void
Expand Down Expand Up @@ -276,6 +273,6 @@ spi_msg_crc(struct spi_packet *p)
//p->crc = crc_res;
return crc_res;
}
#ifdef CPP
#ifdef __cplusplus
} // extern C
#endif
4 changes: 2 additions & 2 deletions src/spi_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#define SPI_REPEAT_RESYNC_THRESH 10

#ifdef CPP
#ifdef __cplusplus
extern "C" {
#endif

Expand Down Expand Up @@ -90,6 +90,6 @@ spi_proto_send_msg(struct spi_state *s, void *buf, size_t n);
uint16_t
spi_msg_crc(struct spi_packet *p);

#ifdef CPP
#ifdef __cplusplus
} // extern C
#endif
5 changes: 2 additions & 3 deletions src/spi_proto_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
#include <stdint.h>
#include <stdio.h>

#ifdef CPP
#ifdef __cplusplus
extern "C" {
#endif
#include "config.h"
#include "crc16.h"
#ifdef CPP
#ifdef __cplusplus
}
#endif

Expand Down
4 changes: 1 addition & 3 deletions test/spi_proto_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

#include "spi_proto.h"
#include "spi_proto_util.h"
#include "config.h"
#include "crc16.h"

#include "test/test_util.h"
#include "test_util.h"

//SPI protocol testing
void
Expand Down
3 changes: 1 addition & 2 deletions test/test_chunks.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

#include "spi_proto.h"
#include "spi_proto_util.h"
#include "config.h"
#include "crc16.h"
#include "spi_chunks.h"

#include "test/test_util.h"
#include "test_util.h"

#define BIG_ROUNDS 5

Expand Down
3 changes: 1 addition & 2 deletions test/test_longer_random_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

#include "spi_proto.h"
#include "spi_proto_util.h"
#include "config.h"
#include "crc16.h"
#include "test/test_util.h"
#include "test_util.h"

//SPI protocol testing

Expand Down
3 changes: 1 addition & 2 deletions test/test_resync.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

#include "spi_proto.h"
#include "spi_proto_util.h"
#include "config.h"
#include "crc16.h"
#include "test/test_util.h"
#include "test_util.h"

//SPI protocol testing
//test resynchronization
Expand Down

0 comments on commit d432689

Please sign in to comment.