@@ -1,164 +1,189 | |||||
1 | #!/bin/bash |
|
1 | #!/bin/bash | |
2 | #/*------------------------------------------------------------------------------ |
|
2 | #/*------------------------------------------------------------------------------ | |
3 | #-- This file is a part of the libuc, microcontroler library |
|
3 | #-- This file is a part of the libuc, microcontroler library | |
4 | #-- Copyright (C) 2011, Alexis Jeandet |
|
4 | #-- Copyright (C) 2011, Alexis Jeandet | |
5 | #-- |
|
5 | #-- | |
6 | #-- This program is free software; you can redistribute it and/or modify |
|
6 | #-- This program is free software; you can redistribute it and/or modify | |
7 | #-- it under the terms of the GNU General Public License as published by |
|
7 | #-- it under the terms of the GNU General Public License as published by | |
8 | #-- the Free Software Foundation; either version 3 of the License, or |
|
8 | #-- the Free Software Foundation; either version 3 of the License, or | |
9 | #-- (at your option) any later version. |
|
9 | #-- (at your option) any later version. | |
10 | #-- |
|
10 | #-- | |
11 | #-- This program is distributed in the hope that it will be useful, |
|
11 | #-- This program is distributed in the hope that it will be useful, | |
12 | #-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | #-- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | #-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | #-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | #-- GNU General Public License for more details. |
|
14 | #-- GNU General Public License for more details. | |
15 | #-- |
|
15 | #-- | |
16 | #-- You should have received a copy of the GNU General Public License |
|
16 | #-- You should have received a copy of the GNU General Public License | |
17 | #-- along with this program; if not, write to the Free Software |
|
17 | #-- along with this program; if not, write to the Free Software | |
18 | #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | #------------------------------------------------------------------------------- |
|
19 | #------------------------------------------------------------------------------- | |
20 | #-- Author : Alexis Jeandet |
|
20 | #-- Author : Alexis Jeandet | |
21 | #-- Mail : alexis.jeandet@gmail.com |
|
21 | #-- Mail : alexis.jeandet@gmail.com | |
22 | #-------------------------------------------------------------------------------*/ |
|
22 | #-------------------------------------------------------------------------------*/ | |
23 | TEMPLATE="" |
|
23 | TEMPLATE="" | |
24 | ARCH="" |
|
24 | ARCH="" | |
25 | TARGET="" |
|
25 | TARGET="" | |
26 | SRCFILES="" |
|
26 | SRCFILES="" | |
27 | INCLUDES="" |
|
27 | INCLUDES="" | |
28 | LIBRARIES="" |
|
28 | LIBRARIES="" | |
29 | HEADERSINSTALLPATH="" |
|
29 | HEADERSINSTALLPATH="" | |
30 | TARGETINSTALLPATH="" |
|
30 | TARGETINSTALLPATH="" | |
31 | BSP="generic" |
|
31 | BSP="generic" | |
32 |
|
32 | |||
33 | function getFilesList { |
|
33 | function getFilesList { | |
34 | sed ':a;N;$!ba;s/\\\n/ /g' $1 | sed ':a;N;$!ba;s/\\ \n/ /g' | grep -i $2 | sed 's/\t//g' |
|
34 | sed ':a;N;$!ba;s/\\\n/ /g' $1 | sed ':a;N;$!ba;s/\\ \n/ /g' | grep -i $2 | sed 's/\t//g' | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | function Template { |
|
38 | function Template { | |
39 | TEMPLATE=`more $1 | grep -i "TEMPLATE " | sed s/TEMPLATE// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
39 | TEMPLATE=`more $1 | grep -i "TEMPLATE " | sed s/TEMPLATE// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | function Arch { |
|
42 | function Arch { | |
43 | ARCH=`more $1 | grep -i "ARCH " | sed s/ARCH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
43 | ARCH=`more $1 | grep -i "ARCH " | sed s/ARCH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | function Target { |
|
46 | function Target { | |
47 | TARGET=`more $1 | grep -i "TARGET " | sed s/TARGET// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
47 | TARGET=`more $1 | grep -i "TARGET " | sed s/TARGET// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | function Libs_Inc { |
|
50 | function Libs_Inc { | |
51 | INCLUDEStmp=`more $1 | grep -i "LIBS " | sed s/LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
51 | INCLUDEStmp=`more $1 | grep -i "LIBS " | sed s/LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` | |
52 | for FILES in $INCLUDEStmp |
|
52 | for FILES in $INCLUDEStmp | |
53 | do |
|
53 | do | |
54 | INCLUDES+='$('"LIBUC_INC_DIR_$FILES) " |
|
54 | INCLUDES+='$('"LIBUC_INC_DIR_$FILES) " | |
55 | done |
|
55 | done | |
56 | } |
|
56 | } | |
57 | function Libs_Link { |
|
57 | function Libs_Link { | |
58 | LIBRARIEStmp=`more $1 | grep -i "LIBS " | sed s/LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
58 | LIBRARIEStmp=`more $1 | grep -i "LIBS " | sed s/LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` | |
59 | for FILES in $LIBRARIEStmp |
|
59 | for FILES in $LIBRARIEStmp | |
60 | do |
|
60 | do | |
61 | LIBRARIES+='$('"LIBUC_LIBS_DIR_$FILES) "'$('"LIBUC_LIBS_$FILES) " |
|
61 | LIBRARIES+='$('"LIBUC_LIBS_DIR_$FILES) "'$('"LIBUC_LIBS_$FILES) " | |
62 | done |
|
62 | done | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | function HeadersInstallPath { |
|
65 | function HeadersInstallPath { | |
66 | HEADERSINSTALLPATH=`more $1 | grep -i "HEADERSINSTALLPATH" | sed s/HEADERSINSTALLPATH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
66 | HEADERSINSTALLPATH=`more $1 | grep -i "HEADERSINSTALLPATH" | sed s/HEADERSINSTALLPATH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | function TargetInstallPath { |
|
69 | function TargetInstallPath { | |
70 | TARGETINSTALLPATH=`more $1 | grep -i "TARGETINSTALLPATH" | sed s/TARGETINSTALLPATH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
70 | TARGETINSTALLPATH=`more $1 | grep -i "TARGETINSTALLPATH" | sed s/TARGETINSTALLPATH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | function getBSP { |
|
73 | function getBSP { | |
74 | BSP=`more $1 | grep -i "BSP" | sed s/BSP// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
74 | ||
|
75 | if(more $1 | grep -i "BSP ="); then | |||
|
76 | BSP=`more $1 | grep -i "BSP" | sed s/BSP// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | |||
|
77 | fi | |||
75 | } |
|
78 | } | |
76 |
|
79 | |||
77 | if [ -z "$1" ] ; then |
|
80 | if [ -z "$1" ] ; then | |
78 | echo "try to find a project file ..." |
|
81 | echo "try to find a project file ..." | |
79 | TMP=`ls *.pro` |
|
82 | TMP=`ls *.pro` | |
80 | i=1 |
|
83 | i=1 | |
81 | for Files in $TMP |
|
84 | for Files in $TMP | |
82 | do |
|
85 | do | |
83 | echo "found $Files" |
|
86 | echo "found $Files" | |
84 | PROJECTFILES[i]=$Files |
|
87 | PROJECTFILES[i]=$Files | |
85 | i=$((i + 1)) |
|
88 | i=$((i + 1)) | |
86 | done |
|
89 | done | |
87 | if [ -z "${PROJECTFILES[1]}" ]; then |
|
90 | if [ -z "${PROJECTFILES[1]}" ]; then | |
88 | exit |
|
91 | exit | |
89 | else |
|
92 | else | |
90 | PROJECTFILE=${PROJECTFILES[1]} |
|
93 | PROJECTFILE=${PROJECTFILES[1]} | |
91 | fi |
|
94 | fi | |
92 |
|
95 | |||
93 | else |
|
96 | else | |
94 | PROJECTFILE=$1 |
|
97 | PROJECTFILE=$1 | |
95 | fi |
|
98 | fi | |
96 |
|
99 | |||
97 | CURRENTDIR=`pwd` |
|
100 | CURRENTDIR=`pwd` | |
98 | Template $PROJECTFILE |
|
101 | Template $PROJECTFILE | |
99 | echo "Template = $TEMPLATE" |
|
102 | echo "Template = $TEMPLATE" | |
100 | echo '' > Makefile |
|
103 | echo '' > Makefile | |
101 | echo 'PROJECTDIR = `pwd`'>> Makefile |
|
104 | echo 'PROJECTDIR = `pwd`'>> Makefile | |
102 | echo "LIBUC = $libuc2" >> Makefile |
|
105 | echo "LIBUC = $libuc2" >> Makefile | |
103 |
|
106 | |||
104 | if(echo $TEMPLATE | grep -i 'dir'); then |
|
107 | if(echo $TEMPLATE | grep -i 'dir'); then | |
105 |
|
108 | |||
106 | echo 'include $(LIBUC)/rules/common/rules.mk' >> Makefile |
|
109 | echo 'include $(LIBUC)/rules/common/rules.mk' >> Makefile | |
107 | SUBDIRS=`getFilesList $PROJECTFILE SUBDIRS | sed 's/SUBDIRS//' | sed 's/=//' | sed 's/+//' ` |
|
110 | SUBDIRS=`getFilesList $PROJECTFILE SUBDIRS | sed 's/SUBDIRS//' | sed 's/=//' | sed 's/+//' ` | |
108 | CURRENTDIR=`pwd` |
|
111 | CURRENTDIR=`pwd` | |
109 | echo "" >> Makefile |
|
112 | echo "" >> Makefile | |
110 | echo 'all:subdir' >> Makefile |
|
113 | echo 'all:subdir' >> Makefile | |
111 | for DIRS in $SUBDIRS |
|
114 | for DIRS in $SUBDIRS | |
112 | do |
|
115 | do | |
113 | echo "enter $DIRS" |
|
116 | echo "enter $DIRS" | |
114 | cd $DIRS |
|
117 | cd $DIRS | |
115 | echo "run $0" |
|
118 | echo "run $0" | |
116 | $0 |
|
119 | $0 | |
117 | cd $CURRENTDIR |
|
120 | cd $CURRENTDIR | |
118 | echo "exit $DIRS" |
|
121 | echo "exit $DIRS" | |
119 | if [ -e "$DIRS/Makefile" ]; then |
|
122 | if [ -e "$DIRS/Makefile" ]; then | |
120 | echo " make -C $DIRS">> Makefile |
|
123 | echo " make -C $DIRS">> Makefile | |
121 | fi |
|
124 | fi | |
122 | done |
|
125 | done | |
123 | echo " @echo Code compiled" >> Makefile |
|
126 | echo " @echo Code compiled" >> Makefile | |
124 | echo "" >> Makefile |
|
127 | echo "" >> Makefile | |
|
128 | echo 'clean:' >> Makefile | |||
|
129 | for DIRS in $SUBDIRS | |||
|
130 | do | |||
|
131 | if [ -e "$DIRS/Makefile" ]; then | |||
|
132 | echo " make clean -C $DIRS">> Makefile | |||
|
133 | fi | |||
|
134 | done | |||
|
135 | echo " @echo Code compiled" >> Makefile | |||
|
136 | echo "" >> Makefile | |||
125 | else |
|
137 | else | |
126 | Target $PROJECTFILE |
|
138 | Target $PROJECTFILE | |
127 | Arch $PROJECTFILE |
|
139 | Arch $PROJECTFILE | |
128 | Libs_Inc $PROJECTFILE |
|
140 | Libs_Inc $PROJECTFILE | |
129 | Libs_Link $PROJECTFILE |
|
141 | Libs_Link $PROJECTFILE | |
130 | HeadersInstallPath $PROJECTFILE |
|
142 | HeadersInstallPath $PROJECTFILE | |
131 | TargetInstallPath $PROJECTFILE |
|
143 | TargetInstallPath $PROJECTFILE | |
132 | getBSP $PROJECTFILE |
|
144 | getBSP $PROJECTFILE | |
|
145 | echo "Current BSP is $BSP" | |||
133 | echo $SRCFILES >> Makefile |
|
146 | echo $SRCFILES >> Makefile | |
134 | getFilesList $PROJECTFILE HEADERS >> Makefile |
|
|||
135 | getFilesList $PROJECTFILE SOURCES >> Makefile |
|
|||
136 | echo 'OBJECTFILES = $(SOURCES:.c=.o)'>> Makefile |
|
|||
137 | echo "ARCH = "'$(LIBUC)'"/rules/$ARCH" >> Makefile |
|
|||
138 | echo "TARGET=$TARGET">> Makefile |
|
|||
139 | echo "LIBUC_INCLUDES=$INCLUDES">> Makefile |
|
|||
140 | echo "LIBUC_LIBRARIES=$LIBRARIES">> Makefile |
|
|||
141 | echo "TARGETINSTALLPATH=$TARGETINSTALLPATH">> Makefile |
|
|||
142 | echo "HEADERSINSTALLPATH=$HEADERSINSTALLPATH">> Makefile |
|
|||
143 | echo "BSP=$BSP">> Makefile |
|
|||
144 | echo 'include $(ARCH)/rules.mk' >> Makefile |
|
|||
145 |
|
147 | |||
146 | if(echo $TEMPLATE|grep -i app); then |
|
148 | if(echo $TEMPLATE|grep -i app); then | |
|
149 | getFilesList $PROJECTFILE HEADERS >> Makefile | |||
|
150 | getFilesList $PROJECTFILE SOURCES | sed 's/SOURCES/APPSOURCES/' >> Makefile | |||
|
151 | echo 'OBJECTFILES = $(APPSOURCES:.c=.o)'>> Makefile | |||
|
152 | echo "ARCH = "'$(LIBUC)'"/rules/$ARCH" >> Makefile | |||
|
153 | echo "TARGET=$TARGET">> Makefile | |||
|
154 | echo "LIBUC_INCLUDES=$INCLUDES">> Makefile | |||
|
155 | echo "LIBUC_LIBRARIES=$LIBRARIES">> Makefile | |||
|
156 | echo "TARGETINSTALLPATH=$TARGETINSTALLPATH">> Makefile | |||
|
157 | echo "HEADERSINSTALLPATH=$HEADERSINSTALLPATH">> Makefile | |||
|
158 | echo "BSP=$BSP">> Makefile | |||
|
159 | echo 'include $(ARCH)/rules.mk' >> Makefile | |||
147 | echo '' >> Makefile |
|
160 | echo '' >> Makefile | |
148 | echo 'all:bin' >> Makefile |
|
161 | echo 'all:bin' >> Makefile | |
149 | echo " @echo Code compiled" >> Makefile |
|
162 | echo " @echo Code compiled" >> Makefile | |
|
163 | echo '' >> Makefile | |||
150 | else |
|
164 | else | |
151 | if(echo $TEMPLATE|grep -i lib); then |
|
165 | if(echo $TEMPLATE|grep -i lib); then | |
|
166 | getFilesList $PROJECTFILE HEADERS >> Makefile | |||
|
167 | getFilesList $PROJECTFILE SOURCES | sed 's/SOURCES/LIBSOURCES/' >> Makefile | |||
|
168 | echo 'OBJECTFILES = $(LIBSOURCES:.c=.o)'>> Makefile | |||
|
169 | echo "ARCH = "'$(LIBUC)'"/rules/$ARCH" >> Makefile | |||
|
170 | echo "TARGET=$TARGET">> Makefile | |||
|
171 | echo "LIBUC_INCLUDES=$INCLUDES">> Makefile | |||
|
172 | echo "LIBUC_LIBRARIES=$LIBRARIES">> Makefile | |||
|
173 | echo "TARGETINSTALLPATH=$TARGETINSTALLPATH">> Makefile | |||
|
174 | echo "HEADERSINSTALLPATH=$HEADERSINSTALLPATH">> Makefile | |||
|
175 | echo "BSP=$BSP">> Makefile | |||
|
176 | echo 'include $(ARCH)/rules.mk' >> Makefile | |||
152 | echo '' >> Makefile |
|
177 | echo '' >> Makefile | |
153 | echo 'all:lib' >> Makefile |
|
178 | echo 'all:lib' >> Makefile | |
154 | echo " @echo Code compiled" >> Makefile |
|
179 | echo " @echo Code compiled" >> Makefile | |
155 | fi |
|
180 | fi | |
156 | fi |
|
181 | fi | |
157 | fi |
|
182 | fi | |
158 |
|
183 | |||
159 |
|
184 | |||
160 |
|
185 | |||
161 |
|
186 | |||
162 |
|
187 | |||
163 |
|
188 | |||
164 |
|
189 |
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -1,43 +1,66 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2011, Alexis Jeandet |
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@gmail.com |
|
20 | -- Mail : alexis.jeandet@gmail.com | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
|
22 | #ifndef UART_H | |||
|
23 | #define UART_H | |||
22 | #include "LPC17xx.h" |
|
24 | #include "LPC17xx.h" | |
23 |
|
25 | |||
24 | struct ARM7uartRegs |
|
26 | ||
|
27 | #define uartNoParity 0 | |||
|
28 | #define uartOddParity 1 | |||
|
29 | #define uartEvenParity 3 | |||
|
30 | #define uartTrueParity 5 | |||
|
31 | #define uartFalseParity 7 | |||
|
32 | ||||
|
33 | struct LPC17XXuartRegs | |||
25 | { |
|
34 | { | |
26 | unsigned long RWreg; |
|
35 | unsigned long RWreg; | |
27 | unsigned long IntEN; |
|
36 | unsigned long IntEN; | |
28 | unsigned long IntIdFIFOctrlr; |
|
37 | unsigned long IntIdFIFOctrlr; | |
29 | unsigned long LineCtrl; |
|
38 | unsigned long LineCtrl; | |
30 | unsigned long dummy; |
|
39 | unsigned long dummy; | |
31 | unsigned long LineStat; |
|
40 | unsigned long LineStat; | |
32 | unsigned long ScratchPad; |
|
41 | unsigned long ScratchPad; | |
33 | }; |
|
42 | }; | |
34 |
|
43 | |||
35 |
typedef struct |
|
44 | typedef volatile struct LPC17XXuartRegs uartDev; | |
36 |
|
45 | |||
37 | uartDev* uartopen(int count); |
|
46 | extern uartDev* uartopen(int count); | |
38 | void uartputc(uartDev* dev,char c); |
|
47 | extern void uarton(int count); | |
39 | void uartputs(uartDev* dev,char *s); |
|
48 | extern void uartoff(int count); | |
40 |
void uart |
|
49 | extern void uartputc(uartDev* dev,char c); | |
41 |
|
|
50 | extern void uartputs(uartDev* dev,char *s); | |
42 | void uartsetup(uartDev* dev,int baudRate,int cpuClk); |
|
51 | extern void uartgets(uartDev* dev,char *s); | |
|
52 | extern char uartgetc(uartDev* dev); | |||
|
53 | extern void uartsetbaudrate(uartDev* dev,unsigned int baudRate); | |||
|
54 | extern unsigned char uartgetpclkfactor(uartDev* dev); | |||
|
55 | extern void uartsetpclkfactor(uartDev* dev,unsigned char pclkfactor); | |||
|
56 | extern void uartsetup(uartDev* dev,unsigned int baudRate,unsigned char WordLength,unsigned char StopBitCnt,unsigned char Parity); | |||
43 |
|
57 | |||
|
58 | #endif | |||
|
59 | ||||
|
60 | ||||
|
61 | ||||
|
62 | ||||
|
63 | ||||
|
64 | ||||
|
65 | ||||
|
66 |
@@ -1,18 +1,19 | |||||
1 |
|
1 | |||
2 | PROJECTDIR = `pwd` |
|
2 | PROJECTDIR = `pwd` | |
3 | LIBUC = /opt/libuc2 |
|
3 | LIBUC = /opt/libuc2 | |
4 |
|
4 | |||
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/UART |
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/UART | |
6 | HEADERS += uart.h |
|
6 | HEADERS += uart.h | |
7 | SOURCES += uart.c |
|
7 | LIBSOURCES += uart.c | |
8 | OBJECTFILES = $(SOURCES:.c=.o) |
|
8 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
9 | ARCH = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
9 | ARCH = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
10 | TARGET=libuart |
|
10 | TARGET=libuart | |
11 | LIBUC_INCLUDES= |
|
11 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE) | |
12 | LIBUC_LIBRARIES= |
|
12 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE) $(LIBUC_LIBS_CORE) | |
13 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR)/UART |
|
13 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR)/UART | |
14 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR)/UART |
|
14 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR)/UART | |
|
15 | BSP=generic | |||
15 | include $(ARCH)/rules.mk |
|
16 | include $(ARCH)/rules.mk | |
16 |
|
17 | |||
17 | all:lib |
|
18 | all:lib | |
18 | @echo Code compiled |
|
19 | @echo Code compiled |
@@ -1,69 +1,192 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2011, Alexis Jeandet |
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@gmail.com |
|
20 | -- Mail : alexis.jeandet@gmail.com | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
|
22 | #include "core.h" | |||
22 | #include "uart.h" |
|
23 | #include "uart.h" | |
23 |
|
24 | |||
24 |
|
25 | |||
25 | void uartputc(uartDev* dev,char c) { |
|
26 | void uartputc(uartDev* dev,char c) { | |
26 | while (!((dev->LineStat & (1<<5)))); |
|
27 | while (!((dev->LineStat & (1<<5)))); | |
27 | dev->RWreg = c; |
|
28 | dev->RWreg = c; | |
28 | } |
|
29 | } | |
29 |
|
30 | |||
30 | char uartgetc(uartDev* dev) { |
|
31 | char uartgetc(uartDev* dev) { | |
31 | while (!((dev->LineStat & 1))); |
|
32 | while (!((dev->LineStat & 1))); | |
32 | return (char)dev->RWreg; |
|
33 | return (char)dev->RWreg; | |
33 | } |
|
34 | } | |
34 |
|
35 | |||
35 |
|
36 | |||
36 | void uartputs(uartDev* dev,char *s) { |
|
37 | void uartputs(uartDev* dev,char *s) { | |
37 | while (*s) uartputc(dev,*s++); |
|
38 | while (*s) uartputc(dev,*s++); | |
38 | } |
|
39 | } | |
39 |
|
40 | |||
40 |
|
41 | |||
41 | void uartgets(uartDev* dev,char *s) { |
|
42 | void uartgets(uartDev* dev,char *s) { | |
42 | while (*s && (*s!=0xd)) *s++ = uartgetc(dev); |
|
43 | while (*s && (*s!=0xd)) *s++ = uartgetc(dev); | |
43 | } |
|
44 | } | |
44 |
|
45 | |||
45 | void uartsetup(uartDev* dev,int baudRate,int cpuClk) |
|
46 | void uartoff(int count) | |
46 |
{ |
|
47 | { | |
|
48 | switch(count) | |||
|
49 | { | |||
|
50 | case 0: | |||
|
51 | LPC_SC->PCONP &= ~( 1 << 3 ); | |||
|
52 | break; | |||
|
53 | case 1: | |||
|
54 | LPC_SC->PCONP &= ~( 1 << 4 ); | |||
|
55 | break; | |||
|
56 | case 2: | |||
|
57 | LPC_SC->PCONP &= ~( 1 << 24 ); | |||
|
58 | break; | |||
|
59 | case 3: | |||
|
60 | LPC_SC->PCONP &= ~( 1 << 25 ); | |||
|
61 | break; | |||
|
62 | default: | |||
|
63 | break; | |||
|
64 | } | |||
|
65 | } | |||
|
66 | ||||
|
67 | void uarton(int count) | |||
|
68 | { | |||
|
69 | switch(count) | |||
|
70 | { | |||
|
71 | case 0: | |||
|
72 | LPC_SC->PCONP |= ( 1 << 3 ); | |||
|
73 | break; | |||
|
74 | case 1: | |||
|
75 | LPC_SC->PCONP |= ( 1 << 4 ); | |||
|
76 | break; | |||
|
77 | case 2: | |||
|
78 | LPC_SC->PCONP |= ( 1 << 24 ); | |||
|
79 | break; | |||
|
80 | case 3: | |||
|
81 | LPC_SC->PCONP |= ( 1 << 25 ); | |||
|
82 | break; | |||
|
83 | default: | |||
|
84 | break; | |||
|
85 | } | |||
|
86 | } | |||
|
87 | ||||
|
88 | ||||
|
89 | ||||
|
90 | void uartsetup(uartDev* dev,unsigned int baudRate,unsigned char WordLength,unsigned char StopBitCnt,unsigned char Parity) | |||
|
91 | { | |||
|
92 | if(WordLength>9)WordLength=8; | |||
|
93 | if((StopBitCnt>2)||(StopBitCnt==0))StopBitCnt=1; | |||
|
94 | if(Parity>7)Parity=0; | |||
|
95 | dev->LineCtrl = (WordLength-5) + ((StopBitCnt-1)<<2) + (Parity<<3); | |||
|
96 | uartsetbaudrate(dev,baudRate); | |||
|
97 | } | |||
|
98 | ||||
|
99 | unsigned char uartgetpclkfactor(uartDev* dev) | |||
|
100 | { | |||
|
101 | unsigned int clksel=0; | |||
|
102 | const char clkselDec[]={4,1,2,8}; | |||
|
103 | switch((int)dev) | |||
|
104 | { | |||
|
105 | case (int)LPC_UART0_BASE: | |||
|
106 | clksel = (LPC_SC->PCLKSEL0>>6) & 3; | |||
|
107 | break; | |||
|
108 | case (int)LPC_UART1_BASE: | |||
|
109 | clksel = (LPC_SC->PCLKSEL0>>8) & 3; | |||
|
110 | break; | |||
|
111 | case (int)LPC_UART2_BASE: | |||
|
112 | clksel = (LPC_SC->PCLKSEL1>>16) & 3; | |||
|
113 | break; | |||
|
114 | case (int)LPC_UART3_BASE: | |||
|
115 | clksel = (LPC_SC->PCLKSEL1>>18) & 3; | |||
|
116 | break; | |||
|
117 | default: | |||
|
118 | break; | |||
|
119 | } | |||
|
120 | return clkselDec[clksel]; | |||
|
121 | } | |||
|
122 | ||||
|
123 | void uartsetpclkfactor(uartDev* dev,unsigned char pclkfactor) | |||
|
124 | { | |||
|
125 | const char clkselDec[]={1,1,2,2,0,0,0,0,3}; | |||
|
126 | unsigned int clksel=0; | |||
|
127 | switch((int)dev) | |||
|
128 | { | |||
|
129 | case (int)LPC_UART0_BASE: | |||
|
130 | LPC_SC->PCLKSEL0 |= clkselDec[pclkfactor]<<6; | |||
|
131 | LPC_SC->PCLKSEL0 &= clkselDec[pclkfactor]<<6; | |||
|
132 | break; | |||
|
133 | case (int)LPC_UART1_BASE: | |||
|
134 | LPC_SC->PCLKSEL0 |= clkselDec[pclkfactor]<<8; | |||
|
135 | LPC_SC->PCLKSEL0 &= clkselDec[pclkfactor]<<8; | |||
|
136 | break; | |||
|
137 | case (int)LPC_UART2_BASE: | |||
|
138 | LPC_SC->PCLKSEL1 |= clkselDec[pclkfactor]<<16; | |||
|
139 | LPC_SC->PCLKSEL1 &= clkselDec[pclkfactor]<<16; | |||
|
140 | break; | |||
|
141 | case (int)LPC_UART3_BASE: | |||
|
142 | LPC_SC->PCLKSEL1 |= clkselDec[pclkfactor]<<18; | |||
|
143 | LPC_SC->PCLKSEL1 &= clkselDec[pclkfactor]<<18; | |||
|
144 | break; | |||
|
145 | default: | |||
|
146 | break; | |||
|
147 | } | |||
|
148 | } | |||
|
149 | ||||
|
150 | void uartsetbaudrate(uartDev* dev,unsigned int baudRate) | |||
|
151 | { | |||
|
152 | unsigned int cpuClk=0; | |||
|
153 | unsigned int pclk = 0; | |||
|
154 | unsigned int clksel=0; | |||
|
155 | unsigned int cpuclk=0; | |||
|
156 | if(dev==0)return; | |||
|
157 | cpuclk = coregetCpuFreq(); | |||
|
158 | pclk = cpuclk / uartgetpclkfactor(dev); | |||
|
159 | while((baudRate*16)>pclk) | |||
|
160 | { | |||
|
161 | unsigned char pclkfact= uartgetpclkfactor(dev); | |||
|
162 | if(pclkfact==1)return; | |||
|
163 | uartsetpclkfactor(dev,pclkfact/2); | |||
|
164 | pclk = cpuclk / uartgetpclkfactor(dev); | |||
|
165 | } | |||
|
166 | dev->LineCtrl |= 128; | |||
|
167 | dev->RWreg = pclk/(baudRate*16); | |||
|
168 | dev->LineCtrl &= ~(128); | |||
|
169 | } | |||
47 |
|
170 | |||
48 | uartDev* uartopen(int count){ |
|
171 | uartDev* uartopen(int count){ | |
49 | uartDev* dev; |
|
172 | uartDev* dev; | |
50 | switch(count) |
|
173 | switch(count) | |
51 | { |
|
174 | { | |
52 | case 0: |
|
175 | case 0: | |
53 | dev = (uartDev*)((unsigned long)LPC_UART0_BASE); |
|
176 | dev = (uartDev*)((unsigned long)LPC_UART0_BASE); | |
54 | break; |
|
177 | break; | |
55 | case 1: |
|
178 | case 1: | |
56 | dev = (uartDev*)((unsigned long)LPC_UART1_BASE); |
|
179 | dev = (uartDev*)((unsigned long)LPC_UART1_BASE); | |
57 | break; |
|
180 | break; | |
58 | case 2: |
|
181 | case 2: | |
59 | dev = (uartDev*)((unsigned long)LPC_UART2_BASE); |
|
182 | dev = (uartDev*)((unsigned long)LPC_UART2_BASE); | |
60 | break; |
|
183 | break; | |
61 | case 3: |
|
184 | case 3: | |
62 | dev = (uartDev*)((unsigned long)LPC_UART3_BASE); |
|
185 | dev = (uartDev*)((unsigned long)LPC_UART3_BASE); | |
63 | break; |
|
186 | break; | |
64 | default: |
|
187 | default: | |
65 | dev = (uartDev*)0; |
|
188 | dev = (uartDev*)0; | |
66 | break; |
|
189 | break; | |
67 | } |
|
190 | } | |
68 | return dev; |
|
191 | return dev; | |
69 | } |
|
192 | } |
@@ -1,11 +1,14 | |||||
1 |
uart.o: uart.c |
|
1 | uart.o: uart.c /opt/libuc2/lib/includes/lpc17XX/CORE/core.h \ | |
|
2 | /opt/libuc2/rules/lpc17XX-arm-noabi-gcc/LPC17xx.h \ | |||
2 | /opt/libuc2/rules/lpc17XX-arm-noabi-gcc/core_cm3.h \ |
|
3 | /opt/libuc2/rules/lpc17XX-arm-noabi-gcc/core_cm3.h \ | |
3 | /opt/libuc2/rules/lpc17XX-arm-noabi-gcc/system_LPC17xx.h |
|
4 | /opt/libuc2/rules/lpc17XX-arm-noabi-gcc/system_LPC17xx.h uart.h | |
4 |
|
5 | |||
5 | uart.h: |
|
6 | /opt/libuc2/lib/includes/lpc17XX/CORE/core.h: | |
6 |
|
7 | |||
7 | /opt/libuc2/rules/lpc17XX-arm-noabi-gcc/LPC17xx.h: |
|
8 | /opt/libuc2/rules/lpc17XX-arm-noabi-gcc/LPC17xx.h: | |
8 |
|
9 | |||
9 | /opt/libuc2/rules/lpc17XX-arm-noabi-gcc/core_cm3.h: |
|
10 | /opt/libuc2/rules/lpc17XX-arm-noabi-gcc/core_cm3.h: | |
10 |
|
11 | |||
11 | /opt/libuc2/rules/lpc17XX-arm-noabi-gcc/system_LPC17xx.h: |
|
12 | /opt/libuc2/rules/lpc17XX-arm-noabi-gcc/system_LPC17xx.h: | |
|
13 | ||||
|
14 | uart.h: |
@@ -1,43 +1,66 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2011, Alexis Jeandet |
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@gmail.com |
|
20 | -- Mail : alexis.jeandet@gmail.com | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
|
22 | #ifndef UART_H | |||
|
23 | #define UART_H | |||
22 | #include "LPC17xx.h" |
|
24 | #include "LPC17xx.h" | |
23 |
|
25 | |||
24 | struct ARM7uartRegs |
|
26 | ||
|
27 | #define uartNoParity 0 | |||
|
28 | #define uartOddParity 1 | |||
|
29 | #define uartEvenParity 3 | |||
|
30 | #define uartTrueParity 5 | |||
|
31 | #define uartFalseParity 7 | |||
|
32 | ||||
|
33 | struct LPC17XXuartRegs | |||
25 | { |
|
34 | { | |
26 | unsigned long RWreg; |
|
35 | unsigned long RWreg; | |
27 | unsigned long IntEN; |
|
36 | unsigned long IntEN; | |
28 | unsigned long IntIdFIFOctrlr; |
|
37 | unsigned long IntIdFIFOctrlr; | |
29 | unsigned long LineCtrl; |
|
38 | unsigned long LineCtrl; | |
30 | unsigned long dummy; |
|
39 | unsigned long dummy; | |
31 | unsigned long LineStat; |
|
40 | unsigned long LineStat; | |
32 | unsigned long ScratchPad; |
|
41 | unsigned long ScratchPad; | |
33 | }; |
|
42 | }; | |
34 |
|
43 | |||
35 |
typedef struct |
|
44 | typedef volatile struct LPC17XXuartRegs uartDev; | |
36 |
|
45 | |||
37 | uartDev* uartopen(int count); |
|
46 | extern uartDev* uartopen(int count); | |
38 | void uartputc(uartDev* dev,char c); |
|
47 | extern void uarton(int count); | |
39 | void uartputs(uartDev* dev,char *s); |
|
48 | extern void uartoff(int count); | |
40 |
void uart |
|
49 | extern void uartputc(uartDev* dev,char c); | |
41 |
|
|
50 | extern void uartputs(uartDev* dev,char *s); | |
42 | void uartsetup(uartDev* dev,int baudRate,int cpuClk); |
|
51 | extern void uartgets(uartDev* dev,char *s); | |
|
52 | extern char uartgetc(uartDev* dev); | |||
|
53 | extern void uartsetbaudrate(uartDev* dev,unsigned int baudRate); | |||
|
54 | extern unsigned char uartgetpclkfactor(uartDev* dev); | |||
|
55 | extern void uartsetpclkfactor(uartDev* dev,unsigned char pclkfactor); | |||
|
56 | extern void uartsetup(uartDev* dev,unsigned int baudRate,unsigned char WordLength,unsigned char StopBitCnt,unsigned char Parity); | |||
43 |
|
57 | |||
|
58 | #endif | |||
|
59 | ||||
|
60 | ||||
|
61 | ||||
|
62 | ||||
|
63 | ||||
|
64 | ||||
|
65 | ||||
|
66 |
@@ -1,12 +1,12 | |||||
1 | TEMPLATE = lib |
|
1 | TEMPLATE = lib | |
2 | ARCH = lpc17XX-arm-noabi-gcc |
|
2 | ARCH = lpc17XX-arm-noabi-gcc | |
3 | TARGET = libuart |
|
3 | TARGET = libuart | |
4 | TARGETINSTALLPATH = $(LIBUC_LIBS_DIR)/UART |
|
4 | TARGETINSTALLPATH = $(LIBUC_LIBS_DIR)/UART | |
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/UART |
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/UART | |
6 |
|
6 | |||
7 | LIBS += |
|
7 | LIBS += CORE | |
8 |
|
8 | |||
9 | SOURCES += uart.c |
|
9 | SOURCES += uart.c | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | HEADERS += uart.h |
|
12 | HEADERS += uart.h |
@@ -1,157 +1,160 | |||||
1 | #/*------------------------------------------------------------------------------ |
|
1 | #/*------------------------------------------------------------------------------ | |
2 | #-- This file is a part of the libuc, microcontroler library |
|
2 | #-- This file is a part of the libuc, microcontroler library | |
3 | #-- Copyright (C) 2011, Alexis Jeandet |
|
3 | #-- Copyright (C) 2011, Alexis Jeandet | |
4 | #-- |
|
4 | #-- | |
5 | #-- This program is free software; you can redistribute it and/or modify |
|
5 | #-- This program is free software; you can redistribute it and/or modify | |
6 | #-- it under the terms of the GNU General Public License as published by |
|
6 | #-- it under the terms of the GNU General Public License as published by | |
7 | #-- the Free Software Foundation; either version 3 of the License, or |
|
7 | #-- the Free Software Foundation; either version 3 of the License, or | |
8 | #-- (at your option) any later version. |
|
8 | #-- (at your option) any later version. | |
9 | #-- |
|
9 | #-- | |
10 | #-- This program is distributed in the hope that it will be useful, |
|
10 | #-- This program is distributed in the hope that it will be useful, | |
11 | #-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | #-- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | #-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | #-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | #-- GNU General Public License for more details. |
|
13 | #-- GNU General Public License for more details. | |
14 | #-- |
|
14 | #-- | |
15 | #-- You should have received a copy of the GNU General Public License |
|
15 | #-- You should have received a copy of the GNU General Public License | |
16 | #-- along with this program; if not, write to the Free Software |
|
16 | #-- along with this program; if not, write to the Free Software | |
17 | #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | #------------------------------------------------------------------------------- |
|
18 | #------------------------------------------------------------------------------- | |
19 | #-- Author : Alexis Jeandet |
|
19 | #-- Author : Alexis Jeandet | |
20 | #-- Mail : alexis.jeandet@gmail.com |
|
20 | #-- Mail : alexis.jeandet@gmail.com | |
21 | #-------------------------------------------------------------------------------*/ |
|
21 | #-------------------------------------------------------------------------------*/ | |
22 |
|
22 | |||
23 | #--------------------------------------------------------------------------------- |
|
23 | #--------------------------------------------------------------------------------- | |
24 | # GCC EXECUTABLES |
|
24 | # GCC EXECUTABLES | |
25 | #--------------------------------------------------------------------------------- |
|
25 | #--------------------------------------------------------------------------------- | |
26 | LIBUC_PREFIX = arm-none-eabi- |
|
26 | LIBUC_PREFIX = arm-none-eabi- | |
27 | LIBUC_CC = $(LIBUC_PREFIX)gcc |
|
27 | LIBUC_CC = $(LIBUC_PREFIX)gcc | |
28 | LIBUC_CXX = $(LIBUC_PREFIX)g++ |
|
28 | LIBUC_CXX = $(LIBUC_PREFIX)g++ | |
29 | LIBUC_AR = $(LIBUC_PREFIX)ar |
|
29 | LIBUC_AR = $(LIBUC_PREFIX)ar | |
30 | LIBUC_AS = $(LIBUC_PREFIX)as |
|
30 | LIBUC_AS = $(LIBUC_PREFIX)as | |
31 | LIBUC_LD = $(LIBUC_PREFIX)ld |
|
31 | LIBUC_LD = $(LIBUC_PREFIX)ld | |
32 | LIBUC_SIZE = $(LIBUC_PREFIX)size |
|
32 | LIBUC_SIZE = $(LIBUC_PREFIX)size | |
33 | LIBUC_STRIP = $(LIBUC_PREFIX)strip -s |
|
33 | LIBUC_STRIP = $(LIBUC_PREFIX)strip -s | |
34 | LIBUC_READELF = $(LIBUC_PREFIX)readelf |
|
34 | LIBUC_READELF = $(LIBUC_PREFIX)readelf | |
35 | LIBUC_OBJCOPY=$(LIBUC_PREFIX)objcopy |
|
35 | LIBUC_OBJCOPY=$(LIBUC_PREFIX)objcopy | |
36 | LIBUC_OBJDUMP=$(LIBUC_PREFIX)objdump |
|
36 | LIBUC_OBJDUMP=$(LIBUC_PREFIX)objdump | |
37 |
|
37 | |||
38 |
|
38 | |||
39 |
|
39 | |||
40 | #--------------------------------------------------------------------------------- |
|
40 | #--------------------------------------------------------------------------------- | |
41 | # GCC FLAGS |
|
41 | # GCC FLAGS | |
42 | #--------------------------------------------------------------------------------- |
|
42 | #--------------------------------------------------------------------------------- | |
43 | LIBUC_FMCU = -mcpu=cortex-m3 |
|
43 | LIBUC_FMCU = -mcpu=cortex-m3 | |
44 | LIBUC_CFLAGS = $(LIBUC_FMCU) |
|
44 | LIBUC_CFLAGS = $(LIBUC_FMCU) | |
45 | LIBUC_CFLAGS = --std=gnu99 -fgnu89-inline -mcpu=cortex-m3 -mthumb |
|
45 | LIBUC_CFLAGS = --std=gnu99 -fgnu89-inline -mcpu=cortex-m3 -mthumb | |
46 | LIBUC_CFLAGS += -ffunction-sections -fdata-sections |
|
46 | LIBUC_CFLAGS += -ffunction-sections -fdata-sections | |
47 | LIBUC_LDFLAGS = --gc-sections |
|
47 | LIBUC_LDFLAGS = --gc-sections | |
48 | LIBUC_ODFLAGS = -x --syms |
|
48 | LIBUC_ODFLAGS = -x --syms | |
49 | LIBUC_CPFLAGS = |
|
49 | LIBUC_CPFLAGS = | |
50 | LIBUC_CFLAGS_WARN_ON = -Wall |
|
50 | LIBUC_CFLAGS_WARN_ON = -Wall | |
51 | LIBUC_CFLAGS_WARN_OFF = -w |
|
51 | LIBUC_CFLAGS_WARN_OFF = -w | |
52 | LIBUC_CFLAGS_RELEASE = -O2 |
|
52 | LIBUC_CFLAGS_RELEASE = -O2 | |
53 | LIBUC_CFLAGS_DEBUG = -g |
|
53 | LIBUC_CFLAGS_DEBUG = -g | |
54 | LIBUC_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -g |
|
54 | LIBUC_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -g | |
55 | LIBUC_CFLAGS_STATIC_LIB = -fPIC |
|
55 | LIBUC_CFLAGS_STATIC_LIB = -fPIC | |
56 | LIBUC_CFLAGS_SOFT_FPU = -msoft-float |
|
56 | LIBUC_CFLAGS_SOFT_FPU = -msoft-float | |
57 | LIBUC_CFLAGS_HARD_FPU = |
|
57 | LIBUC_CFLAGS_HARD_FPU = | |
58 |
|
58 | |||
59 | LIBUC_CXXFLAGS = $(LIBUC_FMCU) |
|
59 | LIBUC_CXXFLAGS = $(LIBUC_FMCU) | |
60 | LIBUC_CXXFLAGS += -g -gdwarf-2 |
|
60 | LIBUC_CXXFLAGS += -g -gdwarf-2 | |
61 | LIBUC_CXXFLAGS += -Wextra -Wundef -Wcast-align -mthumb -msoft-float |
|
61 | LIBUC_CXXFLAGS += -Wextra -Wundef -Wcast-align -mthumb -msoft-float | |
62 | LIBUC_CXXFLAGS_WARN_ON = -Wall |
|
62 | LIBUC_CXXFLAGS_WARN_ON = -Wall | |
63 | LIBUC_CXXFLAGS_WARN_OFF = -w |
|
63 | LIBUC_CXXFLAGS_WARN_OFF = -w | |
64 | LIBUC_CXXFLAGS_RELEASE = -O2 |
|
64 | LIBUC_CXXFLAGS_RELEASE = -O2 | |
65 | LIBUC_CXXFLAGS_DEBUG = -g |
|
65 | LIBUC_CXXFLAGS_DEBUG = -g | |
66 | LIBUC_CXXFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -g |
|
66 | LIBUC_CXXFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -g | |
67 | LIBUC_CXXFLAGS_STATIC_LIB = -fPIC |
|
67 | LIBUC_CXXFLAGS_STATIC_LIB = -fPIC | |
68 | LIBUC_CXXFLAGS_SOFT_FPU = -msoft-float |
|
68 | LIBUC_CXXFLAGS_SOFT_FPU = -msoft-float | |
69 | LIBUC_CXXFLAGS_HARD_FPU = |
|
69 | LIBUC_CXXFLAGS_HARD_FPU = | |
70 |
|
70 | |||
71 | LIBUC_LIBS = |
|
71 | LIBUC_LIBS = | |
72 |
LIBUC_LIBS_ |
|
72 | LIBUC_LIBS_CORE = -static -lcore | |
73 |
LIBUC_LIBS_ |
|
73 | LIBUC_LIBS_UART = -static -luart | |
74 |
LIBUC_LIBS_ |
|
74 | LIBUC_LIBS_SPI = -static -lspi | |
75 |
LIBUC_LIBS_ |
|
75 | LIBUC_LIBS_IIC = -static -liic | |
|
76 | LIBUC_LIBS_ADC = -static -ladc | |||
76 |
|
77 | |||
77 | LIBUC_LIBS_DIR = $(LIBUC)/lib/bin/lpc17XX |
|
78 | LIBUC_LIBS_DIR = $(LIBUC)/lib/bin/lpc17XX | |
|
79 | LIBUC_LIBS_DIR_CORE = -L $(LIBUC_LIBS_DIR)/CORE | |||
78 | LIBUC_LIBS_DIR_UART = -L $(LIBUC_LIBS_DIR)/UART |
|
80 | LIBUC_LIBS_DIR_UART = -L $(LIBUC_LIBS_DIR)/UART | |
79 | LIBUC_LIBS_DIR_SPI = -L $(LIBUC_LIBS_DIR)/SPI |
|
81 | LIBUC_LIBS_DIR_SPI = -L $(LIBUC_LIBS_DIR)/SPI | |
80 | LIBUC_LIBS_DIR_IIC = -L $(LIBUC_LIBS_DIR)/IIC |
|
82 | LIBUC_LIBS_DIR_IIC = -L $(LIBUC_LIBS_DIR)/IIC | |
81 | LIBUC_LIBS_DIR_ADC = -L $(LIBUC_LIBS_DIR)/ADC |
|
83 | LIBUC_LIBS_DIR_ADC = -L $(LIBUC_LIBS_DIR)/ADC | |
82 |
|
84 | |||
83 | LIBUC_INC_DIR = $(LIBUC)/lib/includes/lpc17XX |
|
85 | LIBUC_INC_DIR = $(LIBUC)/lib/includes/lpc17XX | |
|
86 | LIBUC_INC_DIR_CORE = -I $(LIBUC_INC_DIR)/CORE | |||
84 | LIBUC_INC_DIR_UART = -I $(LIBUC_INC_DIR)/UART |
|
87 | LIBUC_INC_DIR_UART = -I $(LIBUC_INC_DIR)/UART | |
85 | LIBUC_INC_DIR_SPI = -I $(LIBUC_INC_DIR)/SPI |
|
88 | LIBUC_INC_DIR_SPI = -I $(LIBUC_INC_DIR)/SPI | |
86 | LIBUC_INC_DIR_IIC = -I $(LIBUC_INC_DIR)/IIC |
|
89 | LIBUC_INC_DIR_IIC = -I $(LIBUC_INC_DIR)/IIC | |
87 | LIBUC_INC_DIR_ADC = -I $(LIBUC_INC_DIR)/ADC |
|
90 | LIBUC_INC_DIR_ADC = -I $(LIBUC_INC_DIR)/ADC | |
88 |
|
91 | |||
89 |
|
92 | |||
90 | #--------------------------------------------------------------------------------- |
|
93 | #--------------------------------------------------------------------------------- | |
91 | # BOARD SUPORT PACKAGES |
|
94 | # BOARD SUPORT PACKAGES | |
92 | #--------------------------------------------------------------------------------- |
|
95 | #--------------------------------------------------------------------------------- | |
93 | LIBUC_BSP_DIR=$(LIBUC)/bsp |
|
96 | LIBUC_BSP_DIR=$(LIBUC)/bsp | |
94 | LIBUC_BSP_BIN_DIR= $(LIBUC_BSP_DIR)/bin |
|
97 | LIBUC_BSP_BIN_DIR= $(LIBUC_BSP_DIR)/bin | |
95 | LIBUC_BSP_INC_DIR= $(LIBUC_BSP_DIR)/includes |
|
98 | LIBUC_BSP_INC_DIR= $(LIBUC_BSP_DIR)/includes | |
96 | LIBUC_BSP = -L $(LIBUC_BSP_BIN_DIR)/$(BSP) -lbsp |
|
99 | LIBUC_BSP = -L $(LIBUC_BSP_BIN_DIR)/$(BSP) -static -lbsp | |
97 | LIBUC_BSP_INC = -I $(LIBUC_BSP_INC_DIR)/$(BSP) |
|
100 | LIBUC_BSP_INC = -I $(LIBUC_BSP_INC_DIR)/$(BSP) | |
98 | #--------------------------------------------------------------------------------- |
|
101 | #--------------------------------------------------------------------------------- | |
99 | # DEVICE SPECIAL FILES |
|
102 | # DEVICE SPECIAL FILES | |
100 | #--------------------------------------------------------------------------------- |
|
103 | #--------------------------------------------------------------------------------- | |
101 | LINKER_SCRIPT = $(ARCH)/LPC17xx.ld |
|
104 | LINKER_SCRIPT = $(ARCH)/LPC17xx.ld | |
102 | SOURCES += $(ARCH)/startup_LPC17xx.c $(ARCH)/core_cm3.c $(ARCH)/system_LPC17xx.c |
|
105 | APPSOURCES += $(ARCH)/startup_LPC17xx.c $(ARCH)/core_cm3.c $(ARCH)/system_LPC17xx.c | |
103 | LPC17XX_INCDIR=$(ARCH) |
|
106 | LPC17XX_INCDIR=$(ARCH) | |
104 |
|
107 | |||
105 |
|
108 | |||
106 | all: |
|
109 | all: | |
107 | @echo "lpc17XX-arm-noabi-gcc rules" |
|
110 | @echo "lpc17XX-arm-noabi-gcc rules" | |
108 |
|
111 | |||
109 |
|
112 | |||
110 | bin: $(TARGET).bin $(TARGET).hex |
|
113 | bin: $(TARGET).bin $(TARGET).hex | |
111 | @echo "compile bin" |
|
114 | @echo "compile bin" | |
112 |
|
115 | |||
113 |
|
116 | |||
114 |
|
117 | |||
115 | lib: $(TARGET).a |
|
118 | lib: $(TARGET).a | |
116 | @echo "compile lib" |
|
119 | @echo "compile lib" | |
117 |
|
120 | |||
118 | %.a: $(OBJECTFILES) |
|
121 | %.a: $(OBJECTFILES) | |
119 | mkdir -p $(TARGETINSTALLPATH) |
|
122 | mkdir -p $(TARGETINSTALLPATH) | |
120 | mkdir -p $(HEADERSINSTALLPATH) |
|
123 | mkdir -p $(HEADERSINSTALLPATH) | |
121 |
|
|
124 | $(LIBUC_AR) rcs $(TARGETINSTALLPATH)/$@ $(OBJECTFILES) | |
122 | cp $(HEADERS) $(HEADERSINSTALLPATH)/ |
|
125 | cp -f $(HEADERS) $(HEADERSINSTALLPATH)/ | |
123 |
|
126 | |||
124 |
|
127 | |||
125 | %.o: %.c |
|
128 | %.o: %.c | |
126 | $(LIBUC_CC) -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -MM $< -MF $*.d -MP |
|
129 | $(LIBUC_CC) -O3 -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -MM $< -MF $*.d -MP | |
127 | $(LIBUC_CC) -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -c $(LIBUC_CFLAGS) $< -o $@ |
|
130 | $(LIBUC_CC) -O3 -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -c $(LIBUC_CFLAGS) $< -o $@ | |
128 |
|
131 | |||
129 |
|
132 | |||
130 | %.elf: $(LINKER_SCRIPT) $(OBJECTFILES) |
|
133 | %.elf: $(LINKER_SCRIPT) $(OBJECTFILES) | |
131 |
$(LIBUC_LD) -Map $(@:.elf=.map) $(LIBUC_LDFLAGS) |
|
134 | $(LIBUC_LD) -Map $(@:.elf=.map) $(LIBUC_LDFLAGS) -T $^ -o $@ $(LIBUC_BSP) $(LIBUC_LIBRARIES) | |
132 | $(LIBUC_OBJDUMP) $(LIBUC_ODFLAGS) $@ > $(@:.elf=.dump) |
|
135 | $(LIBUC_OBJDUMP) $(LIBUC_ODFLAGS) $@ > $(@:.elf=.dump) | |
133 | $(LIBUC_SIZE) $@ |
|
136 | $(LIBUC_SIZE) $@ | |
134 |
|
137 | |||
135 | %.bin: %.elf |
|
138 | %.bin: %.elf | |
136 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O binary $< $*.bin |
|
139 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O binary $< $*.bin | |
137 |
|
140 | |||
138 |
|
141 | |||
139 | %.hex: %.elf |
|
142 | %.hex: %.elf | |
140 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O ihex $< $*.hex |
|
143 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O ihex $< $*.hex | |
141 |
|
144 | |||
142 |
|
145 | |||
143 | clean: |
|
146 | clean: | |
144 | rm -f *.o *.d *.bin *.hex *.dump *.map *.a |
|
147 | rm -f *.o *.d *.bin *.hex *.dump *.map *.a | |
145 |
|
148 | |||
146 | distclean: |
|
149 | distclean: | |
147 | rm -f $(TARGETINSTALLPATH)/*.bin |
|
150 | rm -f $(TARGETINSTALLPATH)/*.bin | |
148 | rm -f $(TARGETINSTALLPATH)/*.a |
|
151 | rm -f $(TARGETINSTALLPATH)/*.a | |
149 |
|
152 | |||
150 |
|
153 | |||
151 |
|
154 | |||
152 |
|
155 | |||
153 |
|
156 | |||
154 |
|
157 | |||
155 |
|
158 | |||
156 |
|
159 | |||
157 |
|
160 |
General Comments 0
You need to be logged in to leave comments.
Login now