|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -1,192 +1,191 | |||
|
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 | #include "core.h" |
|
23 | 23 | #include "uart.h" |
|
24 | 24 | |
|
25 | 25 | |
|
26 | 26 | void uartputc(uartDev* dev,char c) { |
|
27 | 27 | while (!((dev->LineStat & (1<<5)))); |
|
28 | 28 | dev->RWreg = c; |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | char uartgetc(uartDev* dev) { |
|
32 | 32 | while (!((dev->LineStat & 1))); |
|
33 | 33 | return (char)dev->RWreg; |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | void uartputs(uartDev* dev,char *s) { |
|
38 | 38 | while (*s) uartputc(dev,*s++); |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | |
|
42 | 42 | void uartgets(uartDev* dev,char *s) { |
|
43 | 43 | while (*s && (*s!=0xd)) *s++ = uartgetc(dev); |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | void uartoff(int count) |
|
47 | 47 | { |
|
48 | 48 | switch(count) |
|
49 | 49 | { |
|
50 | 50 | case 0: |
|
51 | 51 | LPC_SC->PCONP &= ~( 1 << 3 ); |
|
52 | 52 | break; |
|
53 | 53 | case 1: |
|
54 | 54 | LPC_SC->PCONP &= ~( 1 << 4 ); |
|
55 | 55 | break; |
|
56 | 56 | case 2: |
|
57 | 57 | LPC_SC->PCONP &= ~( 1 << 24 ); |
|
58 | 58 | break; |
|
59 | 59 | case 3: |
|
60 | 60 | LPC_SC->PCONP &= ~( 1 << 25 ); |
|
61 | 61 | break; |
|
62 | 62 | default: |
|
63 | 63 | break; |
|
64 | 64 | } |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | void uarton(int count) |
|
68 | 68 | { |
|
69 | 69 | switch(count) |
|
70 | 70 | { |
|
71 | 71 | case 0: |
|
72 | 72 | LPC_SC->PCONP |= ( 1 << 3 ); |
|
73 | 73 | break; |
|
74 | 74 | case 1: |
|
75 | 75 | LPC_SC->PCONP |= ( 1 << 4 ); |
|
76 | 76 | break; |
|
77 | 77 | case 2: |
|
78 | 78 | LPC_SC->PCONP |= ( 1 << 24 ); |
|
79 | 79 | break; |
|
80 | 80 | case 3: |
|
81 | 81 | LPC_SC->PCONP |= ( 1 << 25 ); |
|
82 | 82 | break; |
|
83 | 83 | default: |
|
84 | 84 | break; |
|
85 | 85 | } |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | |
|
89 | 89 | |
|
90 | 90 | void uartsetup(uartDev* dev,unsigned int baudRate,unsigned char WordLength,unsigned char StopBitCnt,unsigned char Parity) |
|
91 | 91 | { |
|
92 | 92 | if(WordLength>9)WordLength=8; |
|
93 | 93 | if((StopBitCnt>2)||(StopBitCnt==0))StopBitCnt=1; |
|
94 | 94 | if(Parity>7)Parity=0; |
|
95 | 95 | dev->LineCtrl = (WordLength-5) + ((StopBitCnt-1)<<2) + (Parity<<3); |
|
96 | 96 | uartsetbaudrate(dev,baudRate); |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | unsigned char uartgetpclkfactor(uartDev* dev) |
|
100 | 100 | { |
|
101 | 101 | unsigned int clksel=0; |
|
102 | 102 | const char clkselDec[]={4,1,2,8}; |
|
103 | 103 | switch((int)dev) |
|
104 | 104 | { |
|
105 | 105 | case (int)LPC_UART0_BASE: |
|
106 | 106 | clksel = (LPC_SC->PCLKSEL0>>6) & 3; |
|
107 | 107 | break; |
|
108 | 108 | case (int)LPC_UART1_BASE: |
|
109 | 109 | clksel = (LPC_SC->PCLKSEL0>>8) & 3; |
|
110 | 110 | break; |
|
111 | 111 | case (int)LPC_UART2_BASE: |
|
112 | 112 | clksel = (LPC_SC->PCLKSEL1>>16) & 3; |
|
113 | 113 | break; |
|
114 | 114 | case (int)LPC_UART3_BASE: |
|
115 | 115 | clksel = (LPC_SC->PCLKSEL1>>18) & 3; |
|
116 | 116 | break; |
|
117 | 117 | default: |
|
118 | 118 | break; |
|
119 | 119 | } |
|
120 | 120 | return clkselDec[clksel]; |
|
121 | 121 | } |
|
122 | 122 | |
|
123 | 123 | void uartsetpclkfactor(uartDev* dev,unsigned char pclkfactor) |
|
124 | 124 | { |
|
125 | 125 | const char clkselDec[]={1,1,2,2,0,0,0,0,3}; |
|
126 | 126 | unsigned int clksel=0; |
|
127 | 127 | switch((int)dev) |
|
128 | 128 | { |
|
129 | 129 | case (int)LPC_UART0_BASE: |
|
130 | 130 | LPC_SC->PCLKSEL0 |= clkselDec[pclkfactor]<<6; |
|
131 | 131 | LPC_SC->PCLKSEL0 &= clkselDec[pclkfactor]<<6; |
|
132 | 132 | break; |
|
133 | 133 | case (int)LPC_UART1_BASE: |
|
134 | 134 | LPC_SC->PCLKSEL0 |= clkselDec[pclkfactor]<<8; |
|
135 | 135 | LPC_SC->PCLKSEL0 &= clkselDec[pclkfactor]<<8; |
|
136 | 136 | break; |
|
137 | 137 | case (int)LPC_UART2_BASE: |
|
138 | 138 | LPC_SC->PCLKSEL1 |= clkselDec[pclkfactor]<<16; |
|
139 | 139 | LPC_SC->PCLKSEL1 &= clkselDec[pclkfactor]<<16; |
|
140 | 140 | break; |
|
141 | 141 | case (int)LPC_UART3_BASE: |
|
142 | 142 | LPC_SC->PCLKSEL1 |= clkselDec[pclkfactor]<<18; |
|
143 | 143 | LPC_SC->PCLKSEL1 &= clkselDec[pclkfactor]<<18; |
|
144 | 144 | break; |
|
145 | 145 | default: |
|
146 | 146 | break; |
|
147 | 147 | } |
|
148 | 148 | } |
|
149 | 149 | |
|
150 | 150 | void uartsetbaudrate(uartDev* dev,unsigned int baudRate) |
|
151 | 151 | { |
|
152 | unsigned int cpuClk=0; | |
|
153 | 152 | unsigned int pclk = 0; |
|
154 | 153 | unsigned int clksel=0; |
|
155 | 154 | unsigned int cpuclk=0; |
|
156 | 155 | if(dev==0)return; |
|
157 | 156 | cpuclk = coregetCpuFreq(); |
|
158 | 157 | pclk = cpuclk / uartgetpclkfactor(dev); |
|
159 | 158 | while((baudRate*16)>pclk) |
|
160 | 159 | { |
|
161 | 160 | unsigned char pclkfact= uartgetpclkfactor(dev); |
|
162 | 161 | if(pclkfact==1)return; |
|
163 | 162 | uartsetpclkfactor(dev,pclkfact/2); |
|
164 | 163 | pclk = cpuclk / uartgetpclkfactor(dev); |
|
165 | 164 | } |
|
166 | 165 | dev->LineCtrl |= 128; |
|
167 | 166 | dev->RWreg = pclk/(baudRate*16); |
|
168 | 167 | dev->LineCtrl &= ~(128); |
|
169 | 168 | } |
|
170 | 169 | |
|
171 | 170 | uartDev* uartopen(int count){ |
|
172 | 171 | uartDev* dev; |
|
173 | 172 | switch(count) |
|
174 | 173 | { |
|
175 | 174 | case 0: |
|
176 | 175 | dev = (uartDev*)((unsigned long)LPC_UART0_BASE); |
|
177 | 176 | break; |
|
178 | 177 | case 1: |
|
179 | 178 | dev = (uartDev*)((unsigned long)LPC_UART1_BASE); |
|
180 | 179 | break; |
|
181 | 180 | case 2: |
|
182 | 181 | dev = (uartDev*)((unsigned long)LPC_UART2_BASE); |
|
183 | 182 | break; |
|
184 | 183 | case 3: |
|
185 | 184 | dev = (uartDev*)((unsigned long)LPC_UART3_BASE); |
|
186 | 185 | break; |
|
187 | 186 | default: |
|
188 | 187 | dev = (uartDev*)0; |
|
189 | 188 | break; |
|
190 | 189 | } |
|
191 | 190 | return dev; |
|
192 | 191 | } |
@@ -1,160 +1,163 | |||
|
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 | 72 | LIBUC_LIBS_CORE = -static -lcore |
|
73 | LIBUC_LIBS_UCSTRINGS = -static -lucstrings | |
|
73 | 74 | LIBUC_LIBS_UART = -static -luart |
|
74 | 75 | LIBUC_LIBS_SPI = -static -lspi |
|
75 | 76 | LIBUC_LIBS_IIC = -static -liic |
|
76 | 77 | LIBUC_LIBS_ADC = -static -ladc |
|
77 | 78 | |
|
78 | 79 | LIBUC_LIBS_DIR = $(LIBUC)/lib/bin/lpc17XX |
|
79 | 80 | LIBUC_LIBS_DIR_CORE = -L $(LIBUC_LIBS_DIR)/CORE |
|
81 | LIBUC_LIBS_DIR_UCSTRINGS = -L $(LIBUC_LIBS_DIR)/STRINGS | |
|
80 | 82 | LIBUC_LIBS_DIR_UART = -L $(LIBUC_LIBS_DIR)/UART |
|
81 | 83 | LIBUC_LIBS_DIR_SPI = -L $(LIBUC_LIBS_DIR)/SPI |
|
82 | 84 | LIBUC_LIBS_DIR_IIC = -L $(LIBUC_LIBS_DIR)/IIC |
|
83 | 85 | LIBUC_LIBS_DIR_ADC = -L $(LIBUC_LIBS_DIR)/ADC |
|
84 | 86 | |
|
85 | 87 | LIBUC_INC_DIR = $(LIBUC)/lib/includes/lpc17XX |
|
86 | 88 | LIBUC_INC_DIR_CORE = -I $(LIBUC_INC_DIR)/CORE |
|
89 | LIBUC_INC_DIR_UCSTRINGS = -I $(LIBUC_INC_DIR)/STRINGS | |
|
87 | 90 | LIBUC_INC_DIR_UART = -I $(LIBUC_INC_DIR)/UART |
|
88 | 91 | LIBUC_INC_DIR_SPI = -I $(LIBUC_INC_DIR)/SPI |
|
89 | 92 | LIBUC_INC_DIR_IIC = -I $(LIBUC_INC_DIR)/IIC |
|
90 | 93 | LIBUC_INC_DIR_ADC = -I $(LIBUC_INC_DIR)/ADC |
|
91 | 94 | |
|
92 | 95 | |
|
93 | 96 | #--------------------------------------------------------------------------------- |
|
94 | 97 | # BOARD SUPORT PACKAGES |
|
95 | 98 | #--------------------------------------------------------------------------------- |
|
96 | 99 | LIBUC_BSP_DIR=$(LIBUC)/bsp |
|
97 | 100 | LIBUC_BSP_BIN_DIR= $(LIBUC_BSP_DIR)/bin |
|
98 | 101 | LIBUC_BSP_INC_DIR= $(LIBUC_BSP_DIR)/includes |
|
99 | 102 | LIBUC_BSP = -L $(LIBUC_BSP_BIN_DIR)/$(BSP) -static -lbsp |
|
100 | 103 | LIBUC_BSP_INC = -I $(LIBUC_BSP_INC_DIR)/$(BSP) |
|
101 | 104 | #--------------------------------------------------------------------------------- |
|
102 | 105 | # DEVICE SPECIAL FILES |
|
103 | 106 | #--------------------------------------------------------------------------------- |
|
104 | 107 | LINKER_SCRIPT = $(ARCH)/LPC17xx.ld |
|
105 | 108 | APPSOURCES += $(ARCH)/startup_LPC17xx.c $(ARCH)/core_cm3.c $(ARCH)/system_LPC17xx.c |
|
106 | 109 | LPC17XX_INCDIR=$(ARCH) |
|
107 | 110 | |
|
108 | 111 | |
|
109 | 112 | all: |
|
110 | 113 | @echo "lpc17XX-arm-noabi-gcc rules" |
|
111 | 114 | |
|
112 | 115 | |
|
113 | 116 | bin: $(TARGET).bin $(TARGET).hex |
|
114 | 117 | @echo "compile bin" |
|
115 | 118 | |
|
116 | 119 | |
|
117 | 120 | |
|
118 | 121 | lib: $(TARGET).a |
|
119 | 122 | @echo "compile lib" |
|
120 | 123 | |
|
121 | 124 | %.a: $(OBJECTFILES) |
|
122 | 125 | mkdir -p $(TARGETINSTALLPATH) |
|
123 | 126 | mkdir -p $(HEADERSINSTALLPATH) |
|
124 | 127 | $(LIBUC_AR) rcs $(TARGETINSTALLPATH)/$@ $(OBJECTFILES) |
|
125 | 128 | cp -f $(HEADERS) $(HEADERSINSTALLPATH)/ |
|
126 | 129 | |
|
127 | 130 | |
|
128 | 131 | %.o: %.c |
|
129 | 132 | $(LIBUC_CC) -O3 -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -MM $< -MF $*.d -MP |
|
130 | 133 | $(LIBUC_CC) -O3 -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -c $(LIBUC_CFLAGS) $< -o $@ |
|
131 | 134 | |
|
132 | 135 | |
|
133 | 136 | %.elf: $(LINKER_SCRIPT) $(OBJECTFILES) |
|
134 | 137 | $(LIBUC_LD) -Map $(@:.elf=.map) $(LIBUC_LDFLAGS) -T $^ -o $@ $(LIBUC_BSP) $(LIBUC_LIBRARIES) |
|
135 | 138 | $(LIBUC_OBJDUMP) $(LIBUC_ODFLAGS) $@ > $(@:.elf=.dump) |
|
136 | 139 | $(LIBUC_SIZE) $@ |
|
137 | 140 | |
|
138 | 141 | %.bin: %.elf |
|
139 | 142 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O binary $< $*.bin |
|
140 | 143 | |
|
141 | 144 | |
|
142 | 145 | %.hex: %.elf |
|
143 | 146 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O ihex $< $*.hex |
|
144 | 147 | |
|
145 | 148 | |
|
146 | 149 | clean: |
|
147 | 150 | rm -f *.o *.d *.bin *.hex *.dump *.map *.a |
|
148 | 151 | |
|
149 | 152 | distclean: |
|
150 | 153 | rm -f $(TARGETINSTALLPATH)/*.bin |
|
151 | 154 | rm -f $(TARGETINSTALLPATH)/*.a |
|
152 | 155 | |
|
153 | 156 | |
|
154 | 157 | |
|
155 | 158 | |
|
156 | 159 | |
|
157 | 160 | |
|
158 | 161 | |
|
159 | 162 | |
|
160 | 163 |
General Comments 0
You need to be logged in to leave comments.
Login now