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