summaryrefslogtreecommitdiffstats
path: root/app/Makefile
blob: 4a007a6401f1036a6bdf82e3139edf6b3db60eb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
##
## This library is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this library.  If not, see <http://www.gnu.org/licenses/>.
##


CPROTO=cproto
PROG=roofclock

LDSCRIPT = ${PROG}.ld

V=1
default: ${PROG}.elf

CSRCS=led.c ticker.c ring.c usart.c stdio.c lwip_glue.c steth.c msf.c abs.c pll.c main.c time_fn.c ntp.c dcf77.c util.c stats.c gps.c hexdump.c bits.c  max7219.c  report.c sysclk.c cdcacm.c usb.c dfu.c
HSRCS= events.h  gps.h  project.h  ring.h  steth.h  time_fn.h  ubx.h





LWIP=lwip/lwip-1.4.1
LWIP_PATH=..

VPATH=${LWIP_PATH}

LWIP_API=#${LWIP}/src/api/err.c ${LWIP}/src/api/netdb.c ${LWIP}/src/api/api_msg.c ${LWIP}/src/api/tcpip.c ${LWIP}/src/api/sockets.c ${LWIP}/src/api/api_lib.c ${LWIP}/src/api/netbuf.c ${LWIP}/src/api/netifapi.c
LWIP_CORE=${LWIP}/src/core/memp.c ${LWIP}/src/core/sys.c ${LWIP}/src/core/init.c ${LWIP}/src/core/pbuf.c ${LWIP}/src/core/dhcp.c ${LWIP}/src/core/ipv4/ip_addr.c ${LWIP}/src/core/ipv4/ip.c ${LWIP}/src/core/ipv4/ip_frag.c ${LWIP}/src/core/ipv4/inet.c ${LWIP}/src/core/ipv4/autoip.c ${LWIP}/src/core/ipv4/icmp.c ${LWIP}/src/core/ipv4/inet_chksum.c ${LWIP}/src/core/timers.c ${LWIP}/src/core/def.c  ${LWIP}/src/core/netif.c  ${LWIP}/src/netif/etharp.c ${LWIP}/src/core/raw.c ${LWIP}/src/core/mem.c  ${LWIP}/src/core/udp.c

DEFINES=#
#${LWIP}/src/core/tcp.c ${LWIP}/src/core/tcp_out.c #${LWIP}/src/core/tcp_in.c 

# ${LWIP}/src/core/snmp/asn1_enc.c ${LWIP}/src/core/snmp/msg_in.c ${LWIP}/src/core/snmp/mib_structs.c ${LWIP}/src/core/snmp/mib2.c ${LWIP}/src/core/snmp/asn1_dec.c ${LWIP}/src/core/snmp/msg_out.c ${LWIP}/src/core/ipv6/icmp6.c ${LWIP}/src/core/ipv6/ip6.c ${LWIP}/src/core/ipv6/ip6_addr.c ${LWIP}/src/core/ipv6/inet6.c 
# ${LWIP}/src/core/dns.c ${LWIP}/src/core/stats.c ${LWIP}/src/core/ipv4/igmp.c 


LWIP_INC=${LWIP_PATH}/${LWIP}
LWIP_LOCAL=${LWIP_PATH}/lwip/lwip-local


LWIP_CSRCS=${LWIP_API} ${LWIP_CORE}
EXTRA_CLEAN=${LWIP}


BINARY = ${PROG}
MYOBJS = ${CSRCS:%.c=%.o} 
LWIP_OBJS = ${LWIP_CSRCS:%.c=%.o}

objs:${OBJS} 

${MYOBJS}: project.h prototypes.h
${LWIP_OBJS}: lwip/lwipopts.h

OBJS=${MYOBJS} ${LWIP_OBJS} 

include ../Makefile.include

CFLAGS+=-Wno-redundant-decls -Wno-unused-parameter
CPPFLAGS        += -I.. -I../libopencm3-local  -I${LWIP_PATH}/${LWIP}/src/include -Ilwip -I${LWIP_PATH}/${LWIP}/src/include/ipv4 -I${LWIP_LOCAL}/port/stm32f4x7 -I. 


LDLIBS+= -lm

fish: ${OBJS}
	echo ${OBJS}

#HOST=clock-lnx
#HOST=10.32.91.140
HOST=tick
HOST=10.32.96.46


reset:
	$(Q)$(OOCD) -f ../oocd/interface/$(OOCD_INTERFACE).cfg \
			-f ../oocd/board/$(OOCD_BOARD).cfg \
		        -c "init" -c "reset run" \
			-c shutdown



test-dfu: ${PROG}.dfu 
	../dfu-util/src/dfu-util -v -R -a 0 -d ${VID}:${DID} -s 0x08004000:leave -D $<
	$(Q)$(OOCD) -f ../oocd/interface/$(OOCD_INTERFACE).cfg \
			-f ../oocd/board/$(OOCD_BOARD).cfg \
		        -c "init" -c "dump_image readback.img  0x8004000 0x7c000" \
			-c shutdown

	hexdump -C ${PROG}.dfu > a
	hexdump -C readback.img> b
	diff -uN a b > c


fl: ${PROG}.hex
	ssh ${HOST} flash_stm32 < ${PROG}.hex


DID=$(shell printf '\#include "id.h"\nID_PRODUCT' | ${CC} -I.. -E - | grep -v ^\# )
VID=$(shell printf '\#include "id.h"\nID_VENDOR' | ${CC} -I.. -E - | grep -v ^\# )


%.dfu: %.elf
	@#printf "  OBJCOPY $(*).dfu\n"
	$(Q)$(OBJCOPY) -Obinary $(*).elf $(*).dfu

dfu:${PROG}.dfu
	dfu-util -R -a 0 -d ${VID}:${DID} -s 0x08004000:leave -D $<


program: ${PROG}.hex
	scp $< ${HOST}:/tmp/img.hex
	echo init | nc -t ${HOST} 4444
	echo reset init | nc -t ${HOST} 4444
	echo flash write_image erase /tmp/img.hex | nc -t ${HOST} 4444
	echo reset run | nc -t ${HOST} 4444

ds:
	$(Q)$(OOCD) -f ../oocd/interface/$(OOCD_INTERFACE).cfg \
		-f ../oocd/board/$(OOCD_BOARD).cfg

debug: ${PROG}.elf
	${PREFIX}-gdb -x gdb.script ${PROG}.elf 

#	openocd

protos: ${CSRCS} 
	echo -n > prototypes.h
	${CPROTO} -E "${CPP} $(CPPFLAGS)" -e -v ${CSRCS} > prototypes.h.tmp
	mv -f prototypes.h.tmp prototypes.h

almanac.txt:
	wget -O $@ 'https://navcen.uscg.gov/?pageName=currentAlmanac&format=yuma'

almanac.h:alamanc.txt parse_alamanc.pl
	./parse_alamanc.pl < almanac.txt > $@ || /bin/rm -f $@


almanac.alp: almanac

almanac:
	wget -O almanac.alp http://alp.u-blox.com/current_7d.alp


EXTRA_CLEAN=${OBJS} ${LWIP_OBJS:%.o=%.d} almanac.c

tidy:
	astyle -A3 -s2 --attach-extern-c -L -c -w -Y -m0 -f -p  -H -U -k3 -xj -xd ${CSRCS} ${HSRCS} 

slog:
	sympathy -d /dev/ttyUSB7 -b 38400 -L ../log -w 132x59 -s