@@ -0,0 +1,101 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef BSP_H | |||
|
23 | #define BSP_H | |||
|
24 | #include "LPC23xx.h" | |||
|
25 | #include <uart.h> | |||
|
26 | ||||
|
27 | ||||
|
28 | extern uartDev* UART0; | |||
|
29 | extern uartDev* UART1; | |||
|
30 | extern uartDev* UART2; | |||
|
31 | extern uartDev* UART3; | |||
|
32 | ||||
|
33 | /*extern i2cDev* IIC0; | |||
|
34 | extern i2cDev* IIC1; | |||
|
35 | extern i2cDev* IIC2; | |||
|
36 | ||||
|
37 | extern sspDev* SSP0; | |||
|
38 | extern sspDev* SSP1; | |||
|
39 | ||||
|
40 | extern eeprom24lc0xDev eeprom0;*/ | |||
|
41 | ||||
|
42 | extern float VREF0; | |||
|
43 | ||||
|
44 | extern unsigned int currentCpuFreq; | |||
|
45 | ||||
|
46 | #define pll0useInternal 0 | |||
|
47 | #define pll0useMainOsc 1 | |||
|
48 | #define pll0useRTC 2 | |||
|
49 | ||||
|
50 | ||||
|
51 | #define pll0setClksrc(src) if((unsigned int)(src)<3) CLKSRCSEL=(src) | |||
|
52 | #define pll0getClksrc (CLKSRCSEL & 3) | |||
|
53 | ||||
|
54 | #define LEDS_ON | |||
|
55 | ||||
|
56 | #define LED1_ON | |||
|
57 | #define LED2_ON | |||
|
58 | #define LED3_ON | |||
|
59 | #define LED4_ON | |||
|
60 | #define LED5_ON | |||
|
61 | #define LED6_ON | |||
|
62 | #define LED7_ON | |||
|
63 | #define LED8_ON | |||
|
64 | ||||
|
65 | #define LEDS_OFF | |||
|
66 | ||||
|
67 | #define LED1_OFF | |||
|
68 | #define LED2_OFF | |||
|
69 | #define LED3_OFF | |||
|
70 | #define LED4_OFF | |||
|
71 | #define LED5_OFF | |||
|
72 | #define LED6_OFF | |||
|
73 | #define LED7_OFF | |||
|
74 | #define LED8_OFF | |||
|
75 | ||||
|
76 | extern int bsp_init(); | |||
|
77 | ||||
|
78 | extern void bsp_GPIO_init(); | |||
|
79 | extern void bsp_uart_init(); | |||
|
80 | extern void bsp_iic_init(); | |||
|
81 | extern void bsp_ssp_init(); | |||
|
82 | extern void consoleputc(char); | |||
|
83 | extern char consolegetc(); | |||
|
84 | ||||
|
85 | /* VS1053 */ | |||
|
86 | extern void clearXCS(); | |||
|
87 | extern void setXCS(); | |||
|
88 | extern int vs10XXDREQ(); | |||
|
89 | ||||
|
90 | ||||
|
91 | #endif | |||
|
92 | ||||
|
93 | ||||
|
94 | ||||
|
95 | ||||
|
96 | ||||
|
97 | ||||
|
98 | ||||
|
99 | ||||
|
100 | ||||
|
101 |
@@ -0,0 +1,30 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/LandTigerdualssp | |||
|
6 | HEADERS += bsp.h | |||
|
7 | LIBSOURCES += bsp.c | |||
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
12 | ARCH = lpc17XX-arm-noabi-gcc | |||
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |||
|
14 | TARGET=libbsp | |||
|
15 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_ALLFS_CMD) $(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_24LC0X_CMD) $(LIBUC_INC_DIR_IIC_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
16 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_ALLFS_CMD) $(LIBUC_LIBS_ALLFS) $(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_24LC0X_CMD) $(LIBUC_LIBS_24LC0X) $(LIBUC_LIBS_DIR_IIC_CMD) $(LIBUC_LIBS_IIC) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
17 | TARGETINSTALLPATH=$(LIBUC_BSP_BIN_DIR)/LandTigerdualssp | |||
|
18 | HEADERSINSTALLPATH=$(LIBUC_BSP_INC_DIR)/LandTigerdualssp | |||
|
19 | BSP=generic | |||
|
20 | include $(ARCHFOLDER)/rules.mk | |||
|
21 | ||||
|
22 | all:lib | |||
|
23 | @echo Code compiled | |||
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -0,0 +1,191 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #include "bsp.h" | |||
|
23 | #include "core.h" | |||
|
24 | ||||
|
25 | ||||
|
26 | unsigned int OSC0 =12000000; | |||
|
27 | unsigned int INTOSC =4000000; | |||
|
28 | unsigned int RTCOSC =32768; | |||
|
29 | unsigned int currentCpuFreq=0; | |||
|
30 | float VREF0 =(float)3.3; | |||
|
31 | uartDev UART0=(uartDev)0; | |||
|
32 | uartDev UART1=(uartDev)0; | |||
|
33 | uartDev UART2=(uartDev)0; | |||
|
34 | uartDev UART3=(uartDev)0; | |||
|
35 | ||||
|
36 | i2cDev IIC0=(i2cDev)0; | |||
|
37 | i2cDev IIC1=(i2cDev)0; | |||
|
38 | i2cDev IIC2=(i2cDev)0; | |||
|
39 | ||||
|
40 | sspDev SSP0=(sspDev)0; | |||
|
41 | sspDev SSP1=(sspDev)0; | |||
|
42 | ||||
|
43 | sdcardDev SDCARD0; | |||
|
44 | blkdevice BLKDEVSDCARD0; | |||
|
45 | dikpartition PART0; | |||
|
46 | FAT32fs fs0; | |||
|
47 | ucdirent root; | |||
|
48 | ||||
|
49 | eeprom24lc0xDev eeprom0; | |||
|
50 | ||||
|
51 | int bsp_init() | |||
|
52 | { | |||
|
53 | bsp_GPIO_init(); | |||
|
54 | coresetCpuFreq(20000000); | |||
|
55 | currentCpuFreq=coregetCpuFreq(); | |||
|
56 | coresetCpuFreq(60000000); | |||
|
57 | currentCpuFreq=coregetCpuFreq(); | |||
|
58 | bsp_uart_init(); | |||
|
59 | bsp_iic_init(); | |||
|
60 | bsp_ssp_init(); | |||
|
61 | bsp_SD_init(); | |||
|
62 | return 0; | |||
|
63 | } | |||
|
64 | ||||
|
65 | void bsp_GPIO_init() | |||
|
66 | { | |||
|
67 | LPC_SC->PCONP |= ( 1 << 15 ); // power up GPIO | |||
|
68 | LPC_GPIO2->FIODIR |=255; | |||
|
69 | LEDS_OFF; | |||
|
70 | } | |||
|
71 | ||||
|
72 | void bsp_uart_init() | |||
|
73 | { | |||
|
74 | LPC_SC->PCONP |= ( 1 << 24 ); // power up UART3 | |||
|
75 | LPC_SC->PCONP |= ( 1 << 4 ); // power up UART1 | |||
|
76 | LPC_PINCON->PINSEL0 |= (1<<4); | |||
|
77 | LPC_PINCON->PINSEL0 &= ~(1<<5); | |||
|
78 | LPC_PINCON->PINSEL0 |= (1<<6); | |||
|
79 | LPC_PINCON->PINSEL0 &= ~(1<<7); | |||
|
80 | LPC_PINCON->PINSEL0 |= (1<<20); | |||
|
81 | LPC_PINCON->PINSEL0 &= ~(1<<21); | |||
|
82 | LPC_PINCON->PINSEL0 |= (1<<22); | |||
|
83 | LPC_PINCON->PINSEL0 &= ~(1<<23); | |||
|
84 | UART0= uartopen(0); | |||
|
85 | uartsetup(UART0,38400,8,1,uartNoParity); | |||
|
86 | UART2= uartopen(2); | |||
|
87 | uartsetup(UART2,38400,8,1,uartNoParity); | |||
|
88 | } | |||
|
89 | ||||
|
90 | void bsp_ssp_init() | |||
|
91 | { | |||
|
92 | SSP0 = sspopen(0); // power up SSP0 | |||
|
93 | SSP1 = sspopen(1); | |||
|
94 | ssppowerup(SSP0); | |||
|
95 | ssppowerup(SSP1); | |||
|
96 | sspsetpclkfactor(SSP0,1); | |||
|
97 | sspsetpclkfactor(SSP1,1); | |||
|
98 | sspsetup(SSP0,16,FFSPI|CLKINHLOW|CKfirstEdge,loopbackOFF|MASTERMODE, 350000); | |||
|
99 | sspsetup(SSP1,16,FFSPI|CLKINHLOW|CKfirstEdge,loopbackOFF|MASTERMODE, 350000); | |||
|
100 | enableSSP(SSP0); | |||
|
101 | enableSSP(SSP1); | |||
|
102 | LPC_PINCON->PINSEL3 |= (3<<14); //MISO0 on P1.23 | |||
|
103 | LPC_PINCON->PINSEL3 |= (3<<16); //MOSI0 on P1.24 | |||
|
104 | LPC_PINCON->PINSEL3 |= (3<<8); //SCK0 on P1.20 | |||
|
105 | LPC_PINCON->PINSEL0 |= (1<<17); //MISO0 on P1.23 | |||
|
106 | LPC_PINCON->PINSEL0 &= ~(1<<16); | |||
|
107 | LPC_PINCON->PINSEL0 |= (1<<19); //MOSI0 on P1.24 | |||
|
108 | LPC_PINCON->PINSEL0 &= ~(1<<18); //MOSI0 on P1.24 | |||
|
109 | LPC_PINCON->PINSEL0 |= (1<<15); //SCK0 on P1.20 | |||
|
110 | LPC_PINCON->PINSEL0 &= ~(1<<14); //SCK0 on P1.20 | |||
|
111 | LPC_GPIO1->FIODIR |= (1<<24) + (1<<20); | |||
|
112 | LPC_PINCON->PINMODE3 &= ~(1<<14); | |||
|
113 | LPC_PINCON->PINMODE3 &= ~(1<<15); | |||
|
114 | //LPC_PINCON->PINSEL3 |= (3<<10); //SSEL0 on P1.21 disable for SDCARD -> need to send dummy clock | |||
|
115 | ||||
|
116 | } | |||
|
117 | ||||
|
118 | ||||
|
119 | void bsp_iic_init() | |||
|
120 | { | |||
|
121 | /*LPC_SC->PCONP |= ( 1 << 7 ); // power up IIC0 | |||
|
122 | LPC_PINCON->PINSEL1 |= (1<<22); | |||
|
123 | LPC_PINCON->PINSEL1 &= ~(1<<23); | |||
|
124 | LPC_PINCON->PINSEL1 |= (1<<24); | |||
|
125 | LPC_PINCON->PINSEL1 &= ~(1<<25); | |||
|
126 | IIC0 = i2copen(0); | |||
|
127 | i2csetdatarate(IIC0,100000); | |||
|
128 | eeprom24lc0xopen(&eeprom0,IIC0,0,2048);*/ | |||
|
129 | } | |||
|
130 | ||||
|
131 | void bsp_SD_init() | |||
|
132 | { | |||
|
133 | /*LPC_GPIO1->FIODIR |=1<<21; //SD chip select on P1.21 | |||
|
134 | LPC_GPIO1->FIOSET = 1<<21; //unselect SD card | |||
|
135 | LPC_GPIO3->FIODIR |=1<<26; | |||
|
136 | LPC_GPIO3->FIODIR &= ~(1<<25); | |||
|
137 | LPC_GPIO3->FIOCLR |=1<<26; | |||
|
138 | sdcardmake(&SDCARD0,SSP0,&sspgetnc,&sspputnc,&sspsetdatarate,&sspgetdatarate); | |||
|
139 | sdcardmakeblkdev(&BLKDEVSDCARD0,&SDCARD0,&bspsdcardselect,&bsppowersdcard,&bspsdcardpresent,&bspsdcardwriteprotected); | |||
|
140 | BLKDEVSDCARD0.initialize(&BLKDEVSDCARD0); | |||
|
141 | mbropen(&BLKDEVSDCARD0,&PART0,1); | |||
|
142 | fat32open(&fs0,&PART0); | |||
|
143 | fat32mkdirent(&fs0,&root);*/ | |||
|
144 | } | |||
|
145 | ||||
|
146 | void consoleputc(char c) | |||
|
147 | { | |||
|
148 | uartputc(UART0,c); | |||
|
149 | } | |||
|
150 | ||||
|
151 | ||||
|
152 | char consolegetc() | |||
|
153 | { | |||
|
154 | return uartgetc(UART0); | |||
|
155 | } | |||
|
156 | ||||
|
157 | ||||
|
158 | ||||
|
159 | void vs10XXclearXCS(){} | |||
|
160 | void vs10XXsetXCS(){} | |||
|
161 | int vs10XXDREQ() | |||
|
162 | { | |||
|
163 | return 1; | |||
|
164 | } | |||
|
165 | ||||
|
166 | ||||
|
167 | void bsppowersdcard(char onoff) //always ON | |||
|
168 | { | |||
|
169 | ||||
|
170 | } | |||
|
171 | ||||
|
172 | char bspsdcardpresent() | |||
|
173 | { | |||
|
174 | return (((LPC_GPIO3->FIOPIN >> 25) & 1) ^1); | |||
|
175 | } | |||
|
176 | ||||
|
177 | char bspsdcardwriteprotected() | |||
|
178 | { | |||
|
179 | return 0; | |||
|
180 | } | |||
|
181 | ||||
|
182 | void bspsdcardselect(char YESNO) | |||
|
183 | { | |||
|
184 | ||||
|
185 | LPC_GPIO1->FIOPIN = ((YESNO & 1)^1)<<21; | |||
|
186 | } | |||
|
187 | ||||
|
188 | ||||
|
189 | ||||
|
190 | ||||
|
191 |
@@ -0,0 +1,129 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef BSP_H | |||
|
23 | #define BSP_H | |||
|
24 | #include "LPC17xx.h" | |||
|
25 | #include <uart.h> | |||
|
26 | #include <iic.h> | |||
|
27 | #include <ssp.h> | |||
|
28 | #include <24LC0X.h> | |||
|
29 | #include <blkdevice.h> | |||
|
30 | #include <sdcard.h> | |||
|
31 | #include <mbr.h> | |||
|
32 | #include <fat32.h> | |||
|
33 | ||||
|
34 | ||||
|
35 | extern uartDev UART0; | |||
|
36 | extern uartDev UART1; | |||
|
37 | extern uartDev UART2; | |||
|
38 | extern uartDev UART3; | |||
|
39 | ||||
|
40 | extern i2cDev IIC0; | |||
|
41 | extern i2cDev IIC1; | |||
|
42 | extern i2cDev IIC2; | |||
|
43 | ||||
|
44 | extern sspDev SSP0; | |||
|
45 | extern sspDev SSP1; | |||
|
46 | ||||
|
47 | extern sdcardDev SDCARD0; | |||
|
48 | extern blkdevice BLKDEVSDCARD0; | |||
|
49 | extern dikpartition PART0; | |||
|
50 | extern FAT32fs fs0; | |||
|
51 | extern ucdirent root; | |||
|
52 | ||||
|
53 | extern eeprom24lc0xDev eeprom0; | |||
|
54 | ||||
|
55 | extern float VREF0; | |||
|
56 | ||||
|
57 | extern unsigned int currentCpuFreq; | |||
|
58 | ||||
|
59 | #define pll0useInternal 0 | |||
|
60 | #define pll0useMainOsc 1 | |||
|
61 | #define pll0useRTC 2 | |||
|
62 | ||||
|
63 | ||||
|
64 | #define pll0setClksrc(src) if((unsigned int)(src)<3) LPC_SC->CLKSRCSEL=(src) | |||
|
65 | #define pll0getClksrc (LPC_SC->CLKSRCSEL & 3) | |||
|
66 | ||||
|
67 | #define LEDS_ON LPC_GPIO2->FIOSET = 255 | |||
|
68 | ||||
|
69 | #define LED1_ON LPC_GPIO2->FIOSET = (1<<0) | |||
|
70 | #define LED2_ON LPC_GPIO2->FIOSET = (1<<1) | |||
|
71 | #define LED3_ON LPC_GPIO2->FIOSET = (1<<2) | |||
|
72 | #define LED4_ON LPC_GPIO2->FIOSET = (1<<3) | |||
|
73 | #define LED5_ON LPC_GPIO2->FIOSET = (1<<4) | |||
|
74 | #define LED6_ON LPC_GPIO2->FIOSET = (1<<5) | |||
|
75 | #define LED7_ON LPC_GPIO2->FIOSET = (1<<6) | |||
|
76 | #define LED8_ON LPC_GPIO2->FIOSET = (1<<7) | |||
|
77 | ||||
|
78 | #define LEDS_OFF LPC_GPIO2->FIOCLR = ~(255) | |||
|
79 | ||||
|
80 | #define LED1_OFF LPC_GPIO2->FIOCLR = (1<<0) | |||
|
81 | #define LED2_OFF LPC_GPIO2->FIOCLR = (1<<1) | |||
|
82 | #define LED3_OFF LPC_GPIO2->FIOCLR = (1<<2) | |||
|
83 | #define LED4_OFF LPC_GPIO2->FIOCLR = (1<<3) | |||
|
84 | #define LED5_OFF LPC_GPIO2->FIOCLR = (1<<4) | |||
|
85 | #define LED6_OFF LPC_GPIO2->FIOCLR = (1<<5) | |||
|
86 | #define LED7_OFF LPC_GPIO2->FIOCLR = (1<<6) | |||
|
87 | #define LED8_OFF LPC_GPIO2->FIOCLR = (1<<7) | |||
|
88 | ||||
|
89 | extern int bsp_init(); | |||
|
90 | ||||
|
91 | extern void bsp_GPIO_init(); | |||
|
92 | extern void bsp_uart_init(); | |||
|
93 | extern void bsp_iic_init(); | |||
|
94 | extern void bsp_ssp_init(); | |||
|
95 | extern void bsp_SD_init(); | |||
|
96 | extern void consoleputc(char); | |||
|
97 | extern char consolegetc(); | |||
|
98 | ||||
|
99 | /* VS1053 */ | |||
|
100 | extern void clearXCS(); | |||
|
101 | extern void setXCS(); | |||
|
102 | extern int vs10XXDREQ(); | |||
|
103 | ||||
|
104 | /* SD CARD */ | |||
|
105 | void bsppowersdcard(char onoff); | |||
|
106 | char bspsdcardpresent(); | |||
|
107 | void bspsdcardselect(char YESNO); | |||
|
108 | char bspsdcardwriteprotected(); | |||
|
109 | ||||
|
110 | #endif | |||
|
111 | ||||
|
112 | ||||
|
113 | ||||
|
114 | ||||
|
115 | ||||
|
116 | ||||
|
117 | ||||
|
118 | ||||
|
119 | ||||
|
120 | ||||
|
121 | ||||
|
122 | ||||
|
123 | ||||
|
124 | ||||
|
125 | ||||
|
126 | ||||
|
127 | ||||
|
128 | ||||
|
129 |
@@ -0,0 +1,12 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | ARCH = lpc17XX-arm-noabi-gcc | |||
|
3 | TARGET = libbsp | |||
|
4 | TARGETINSTALLPATH = $(LIBUC_BSP_BIN_DIR)/LandTigerdualssp | |||
|
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/LandTigerdualssp | |||
|
6 | ||||
|
7 | LIBS += ALLFS UART SSP 24LC0X IIC CORE UCSTRINGS UHANDLE | |||
|
8 | ||||
|
9 | SOURCES += bsp.c | |||
|
10 | ||||
|
11 | ||||
|
12 | HEADERS += bsp.h |
@@ -0,0 +1,12 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
3 | TARGET = libbsp | |||
|
4 | TARGETINSTALLPATH = $(LIBUC_BSP_BIN_DIR)/MP3PlayerV1 | |||
|
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/MP3PlayerV1 | |||
|
6 | ||||
|
7 | LIBS += UART CORE UHANDLE | |||
|
8 | ||||
|
9 | SOURCES += bsp.c | |||
|
10 | ||||
|
11 | ||||
|
12 | HEADERS += bsp.h |
@@ -0,0 +1,30 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/MP3PlayerV1 | |||
|
6 | HEADERS += bsp.h | |||
|
7 | LIBSOURCES += bsp.c | |||
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
12 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
14 | TARGET=libbsp | |||
|
15 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
16 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
17 | TARGETINSTALLPATH=$(LIBUC_BSP_BIN_DIR)/MP3PlayerV1 | |||
|
18 | HEADERSINSTALLPATH=$(LIBUC_BSP_INC_DIR)/MP3PlayerV1 | |||
|
19 | BSP=generic | |||
|
20 | include $(ARCHFOLDER)/rules.mk | |||
|
21 | ||||
|
22 | all:lib | |||
|
23 | @echo Code compiled | |||
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -0,0 +1,136 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #include "bsp.h" | |||
|
23 | #include "core.h" | |||
|
24 | ||||
|
25 | ||||
|
26 | unsigned int OSC0 =12000000; | |||
|
27 | unsigned int INTOSC =4000000; | |||
|
28 | unsigned int RTCOSC =32768; | |||
|
29 | unsigned int currentCpuFreq=0; | |||
|
30 | float VREF0 =(float)3.3; | |||
|
31 | uartDev* UART0=(uartDev*)0; | |||
|
32 | uartDev* UART1=(uartDev*)0; | |||
|
33 | uartDev* UART2=(uartDev*)0; | |||
|
34 | uartDev* UART3=(uartDev*)0; | |||
|
35 | /* | |||
|
36 | i2cDev* IIC0=(i2cDev*)0; | |||
|
37 | i2cDev* IIC1=(i2cDev*)0; | |||
|
38 | i2cDev* IIC2=(i2cDev*)0; | |||
|
39 | ||||
|
40 | sspDev* SSP0=(sspDev*)0; | |||
|
41 | sspDev* SSP1=(sspDev*)0; | |||
|
42 | ||||
|
43 | eeprom24lc0xDev eeprom0;*/ | |||
|
44 | ||||
|
45 | int bsp_init() | |||
|
46 | { | |||
|
47 | bsp_GPIO_init(); | |||
|
48 | //coresetCpuFreq(20000000); | |||
|
49 | //currentCpuFreq=coregetCpuFreq(); | |||
|
50 | //coresetCpuFreq(60000000); | |||
|
51 | //currentCpuFreq=coregetCpuFreq(); | |||
|
52 | bsp_uart_init(); | |||
|
53 | bsp_iic_init(); | |||
|
54 | bsp_ssp_init(); | |||
|
55 | return 0; | |||
|
56 | } | |||
|
57 | ||||
|
58 | void bsp_GPIO_init() | |||
|
59 | { | |||
|
60 | /*PCONP |= ( 1 << 15 ); // power up GPIO | |||
|
61 | FIO2DIR |=255; | |||
|
62 | LEDS_OFF;*/ | |||
|
63 | } | |||
|
64 | ||||
|
65 | void bsp_uart_init() | |||
|
66 | { | |||
|
67 | /*PCONP |= ( 1 << 24 ); // power up UART3 | |||
|
68 | PCONP |= ( 1 << 4 ); // power up UART1 | |||
|
69 | PINSEL0 |= (1<<4); | |||
|
70 | PINSEL0 &= ~(1<<5); | |||
|
71 | PINSEL0 |= (1<<6); | |||
|
72 | PINSEL0 &= ~(1<<7); | |||
|
73 | PINSEL0 |= (1<<20); | |||
|
74 | PINSEL0 &= ~(1<<21); | |||
|
75 | PINSEL0 |= (1<<22); | |||
|
76 | PINSEL0 &= ~(1<<23);*/ | |||
|
77 | UART0= uartopen(0); | |||
|
78 | //uartsetup(UART0,38400,8,1,uartNoParity); | |||
|
79 | /*UART2= uartopen(2); | |||
|
80 | uartsetup(UART2,38400,8,1,uartNoParity);*/ | |||
|
81 | } | |||
|
82 | ||||
|
83 | void bsp_ssp_init() | |||
|
84 | { | |||
|
85 | /*SSP0 = sspopen(0); // power up SSP0 | |||
|
86 | ssppowerup(SSP0); | |||
|
87 | sspsetpclkfactor(SSP0,1); | |||
|
88 | PINSEL3 |= (3<<14); //MISO0 on P1.23 | |||
|
89 | PINSEL3 |= (3<<16); //MOSI0 on P1.24 | |||
|
90 | PINSEL3 |= (3<<8); //SCK0 on P1.24 | |||
|
91 | PINSEL3 |= (3<<10); //SSEL0 on P1.21 | |||
|
92 | sspsetup(SSP0,8,FFSPI|CLKINHLOW|CKfirstEdge,loopbackOFF|MASTERMODE, 250000); | |||
|
93 | enableSSP(SSP0);*/ | |||
|
94 | } | |||
|
95 | ||||
|
96 | ||||
|
97 | void bsp_iic_init() | |||
|
98 | { | |||
|
99 | /*LPC_SC->PCONP |= ( 1 << 7 ); // power up IIC0 | |||
|
100 | PINSEL1 |= (1<<22); | |||
|
101 | PINSEL1 &= ~(1<<23); | |||
|
102 | PINSEL1 |= (1<<24); | |||
|
103 | PINSEL1 &= ~(1<<25); | |||
|
104 | IIC0 = i2copen(0); | |||
|
105 | i2csetdatarate(IIC0,100000); | |||
|
106 | eeprom24lc0xopen(&eeprom0,IIC0,0,2048);*/ | |||
|
107 | } | |||
|
108 | ||||
|
109 | void consoleputc(char c) | |||
|
110 | { | |||
|
111 | uartputc(UART0,c); | |||
|
112 | } | |||
|
113 | ||||
|
114 | ||||
|
115 | char consolegetc() | |||
|
116 | { | |||
|
117 | return uartgetc(UART0); | |||
|
118 | } | |||
|
119 | ||||
|
120 | ||||
|
121 | ||||
|
122 | void vs10XXclearXCS(){} | |||
|
123 | void vs10XXsetXCS(){} | |||
|
124 | int vs10XXDREQ() | |||
|
125 | { | |||
|
126 | return 1; | |||
|
127 | } | |||
|
128 | ||||
|
129 | ||||
|
130 | ||||
|
131 | ||||
|
132 | ||||
|
133 | ||||
|
134 | ||||
|
135 | ||||
|
136 |
@@ -0,0 +1,101 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef BSP_H | |||
|
23 | #define BSP_H | |||
|
24 | #include "LPC23xx.h" | |||
|
25 | #include <uart.h> | |||
|
26 | ||||
|
27 | ||||
|
28 | extern uartDev* UART0; | |||
|
29 | extern uartDev* UART1; | |||
|
30 | extern uartDev* UART2; | |||
|
31 | extern uartDev* UART3; | |||
|
32 | ||||
|
33 | /*extern i2cDev* IIC0; | |||
|
34 | extern i2cDev* IIC1; | |||
|
35 | extern i2cDev* IIC2; | |||
|
36 | ||||
|
37 | extern sspDev* SSP0; | |||
|
38 | extern sspDev* SSP1; | |||
|
39 | ||||
|
40 | extern eeprom24lc0xDev eeprom0;*/ | |||
|
41 | ||||
|
42 | extern float VREF0; | |||
|
43 | ||||
|
44 | extern unsigned int currentCpuFreq; | |||
|
45 | ||||
|
46 | #define pll0useInternal 0 | |||
|
47 | #define pll0useMainOsc 1 | |||
|
48 | #define pll0useRTC 2 | |||
|
49 | ||||
|
50 | ||||
|
51 | #define pll0setClksrc(src) if((unsigned int)(src)<3) CLKSRCSEL=(src) | |||
|
52 | #define pll0getClksrc (CLKSRCSEL & 3) | |||
|
53 | ||||
|
54 | #define LEDS_ON | |||
|
55 | ||||
|
56 | #define LED1_ON | |||
|
57 | #define LED2_ON | |||
|
58 | #define LED3_ON | |||
|
59 | #define LED4_ON | |||
|
60 | #define LED5_ON | |||
|
61 | #define LED6_ON | |||
|
62 | #define LED7_ON | |||
|
63 | #define LED8_ON | |||
|
64 | ||||
|
65 | #define LEDS_OFF | |||
|
66 | ||||
|
67 | #define LED1_OFF | |||
|
68 | #define LED2_OFF | |||
|
69 | #define LED3_OFF | |||
|
70 | #define LED4_OFF | |||
|
71 | #define LED5_OFF | |||
|
72 | #define LED6_OFF | |||
|
73 | #define LED7_OFF | |||
|
74 | #define LED8_OFF | |||
|
75 | ||||
|
76 | extern int bsp_init(); | |||
|
77 | ||||
|
78 | extern void bsp_GPIO_init(); | |||
|
79 | extern void bsp_uart_init(); | |||
|
80 | extern void bsp_iic_init(); | |||
|
81 | extern void bsp_ssp_init(); | |||
|
82 | extern void consoleputc(char); | |||
|
83 | extern char consolegetc(); | |||
|
84 | ||||
|
85 | /* VS1053 */ | |||
|
86 | extern void clearXCS(); | |||
|
87 | extern void setXCS(); | |||
|
88 | extern int vs10XXDREQ(); | |||
|
89 | ||||
|
90 | ||||
|
91 | #endif | |||
|
92 | ||||
|
93 | ||||
|
94 | ||||
|
95 | ||||
|
96 | ||||
|
97 | ||||
|
98 | ||||
|
99 | ||||
|
100 | ||||
|
101 |
@@ -0,0 +1,195 | |||||
|
1 | asm{ | |||
|
2 | .global main // int main(void) | |||
|
3 | ||||
|
4 | .global _etext // -> .data initial values in ROM | |||
|
5 | .global _data // -> .data area in RAM | |||
|
6 | .global _edata // end of .data area | |||
|
7 | .global __bss_start // -> .bss area in RAM | |||
|
8 | .global __bss_end__ // end of .bss area | |||
|
9 | .global _stack // top of stack | |||
|
10 | ||||
|
11 | // Stack Sizes | |||
|
12 | .set UND_STACK_SIZE, 0x00000004 | |||
|
13 | .set ABT_STACK_SIZE, 0x00000004 | |||
|
14 | .set FIQ_STACK_SIZE, 0x00000004 | |||
|
15 | .set IRQ_STACK_SIZE, 0X00000080 | |||
|
16 | .set SVC_STACK_SIZE, 0x00000004 | |||
|
17 | ||||
|
18 | // Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs | |||
|
19 | .set MODE_USR, 0x10 // User Mode | |||
|
20 | .set MODE_FIQ, 0x11 // FIQ Mode | |||
|
21 | .set MODE_IRQ, 0x12 // IRQ Mode | |||
|
22 | .set MODE_SVC, 0x13 // Supervisor Mode | |||
|
23 | .set MODE_ABT, 0x17 // Abort Mode | |||
|
24 | .set MODE_UND, 0x1B // Undefined Mode | |||
|
25 | .set MODE_SYS, 0x1F // System Mode | |||
|
26 | ||||
|
27 | .equ I_BIT, 0x80 // when I bit is set, IRQ is disabled | |||
|
28 | .equ F_BIT, 0x40 // when F bit is set, FIQ is disabled | |||
|
29 | ||||
|
30 | .text | |||
|
31 | .code 32 | |||
|
32 | .align 2 | |||
|
33 | ||||
|
34 | .global _boot | |||
|
35 | .func _boot | |||
|
36 | _boot: | |||
|
37 | ||||
|
38 | // Runtime Interrupt Vectors | |||
|
39 | // ------------------------- | |||
|
40 | Vectors: | |||
|
41 | b _start // reset - _start | |||
|
42 | ldr pc,_undf // undefined - _undf | |||
|
43 | ldr pc,_swi // SWI - _swi | |||
|
44 | ldr pc,_pabt // program abort - _pabt | |||
|
45 | ldr pc,_dabt // data abort - _dabt | |||
|
46 | nop // reserved | |||
|
47 | ldr pc,[pc,#-0xFF0] // IRQ - read the VIC | |||
|
48 | ldr pc,_fiq // FIQ - _fiq | |||
|
49 | ||||
|
50 | #if 0 | |||
|
51 | // Use this group for production | |||
|
52 | _undf: .word _reset // undefined - _reset | |||
|
53 | _swi: .word _reset // SWI - _reset | |||
|
54 | _pabt: .word _reset // program abort - _reset | |||
|
55 | _dabt: .word _reset // data abort - _reset | |||
|
56 | _irq: .word _reset // IRQ - _reset | |||
|
57 | _fiq: .word _reset // FIQ - _reset | |||
|
58 | ||||
|
59 | #else | |||
|
60 | // Use this group for development | |||
|
61 | _undf: .word __undf // undefined | |||
|
62 | _swi: .word __swi // SWI | |||
|
63 | _pabt: .word __pabt // program abort | |||
|
64 | _dabt: .word __dabt // data abort | |||
|
65 | _irq: .word __irq // IRQ | |||
|
66 | _fiq: .word __fiq // FIQ | |||
|
67 | ||||
|
68 | __undf: b . // undefined | |||
|
69 | __swi: b . // SWI | |||
|
70 | __pabt: b . // program abort | |||
|
71 | __dabt: b . // data abort | |||
|
72 | __irq: b . // IRQ | |||
|
73 | __fiq: b . // FIQ | |||
|
74 | #endif | |||
|
75 | .size _boot, . - _boot | |||
|
76 | .endfunc | |||
|
77 | ||||
|
78 | ||||
|
79 | // Setup the operating mode & stack. | |||
|
80 | // --------------------------------- | |||
|
81 | .global _start, start, _mainCRTStartup | |||
|
82 | .func _start | |||
|
83 | ||||
|
84 | _start: | |||
|
85 | start: | |||
|
86 | _mainCRTStartup: | |||
|
87 | ||||
|
88 | // Initialize Interrupt System | |||
|
89 | // - Set stack location for each mode | |||
|
90 | // - Leave in System Mode with Interrupts Disabled | |||
|
91 | // ----------------------------------------------- | |||
|
92 | ldr r0,=_stack | |||
|
93 | msr CPSR_c,#MODE_UND|I_BIT|F_BIT // Undefined Instruction Mode | |||
|
94 | mov sp,r0 | |||
|
95 | sub r0,r0,#UND_STACK_SIZE | |||
|
96 | msr CPSR_c,#MODE_ABT|I_BIT|F_BIT // Abort Mode | |||
|
97 | mov sp,r0 | |||
|
98 | sub r0,r0,#ABT_STACK_SIZE | |||
|
99 | msr CPSR_c,#MODE_FIQ|I_BIT|F_BIT // FIQ Mode | |||
|
100 | mov sp,r0 | |||
|
101 | sub r0,r0,#FIQ_STACK_SIZE | |||
|
102 | msr CPSR_c,#MODE_IRQ|I_BIT|F_BIT // IRQ Mode | |||
|
103 | mov sp,r0 | |||
|
104 | sub r0,r0,#IRQ_STACK_SIZE | |||
|
105 | msr CPSR_c,#MODE_SVC|I_BIT|F_BIT // Supervisor Mode | |||
|
106 | mov sp,r0 | |||
|
107 | sub r0,r0,#SVC_STACK_SIZE | |||
|
108 | msr CPSR_c,#MODE_SYS|I_BIT|F_BIT // System Mode | |||
|
109 | mov sp,r0 | |||
|
110 | ||||
|
111 | // Copy initialized data to its execution address in RAM | |||
|
112 | // ----------------------------------------------------- | |||
|
113 | #ifdef ROM_RUN | |||
|
114 | ldr r1,=_etext // -> ROM data start | |||
|
115 | ldr r2,=_data // -> data start | |||
|
116 | ldr r3,=_edata // -> end of data | |||
|
117 | 1: cmp r2,r3 // check if data to move | |||
|
118 | ldrlo r0,[r1],#4 // copy it | |||
|
119 | strlo r0,[r2],#4 | |||
|
120 | blo 1b // loop until done | |||
|
121 | #endif | |||
|
122 | // Clear .bss | |||
|
123 | // ---------- | |||
|
124 | mov r0,#0 // get a zero | |||
|
125 | ldr r1,=__bss_start // -> bss start | |||
|
126 | ldr r2,=__bss_end__ // -> bss end | |||
|
127 | 2: cmp r1,r2 // check if data to clear | |||
|
128 | strlo r0,[r1],#4 // clear 4 bytes | |||
|
129 | blo 2b // loop until done | |||
|
130 | ||||
|
131 | /* | |||
|
132 | Call C++ constructors (for objects in "global scope") | |||
|
133 | ctor loop added by Martin Thomas 4/2005 | |||
|
134 | based on a Anglia Design example-application for ST ARM | |||
|
135 | */ | |||
|
136 | ||||
|
137 | LDR r0, =__ctors_start__ | |||
|
138 | LDR r1, =__ctors_end__ | |||
|
139 | ctor_loop: | |||
|
140 | CMP r0, r1 | |||
|
141 | BEQ ctor_end | |||
|
142 | LDR r2, [r0], #4 | |||
|
143 | STMFD sp!, {r0-r1} | |||
|
144 | MOV lr, pc | |||
|
145 | MOV pc, r2 | |||
|
146 | LDMFD sp!, {r0-r1} | |||
|
147 | B ctor_loop | |||
|
148 | ctor_end: | |||
|
149 | ||||
|
150 | // Call main program: main(0) | |||
|
151 | // -------------------------- | |||
|
152 | mov r0,#0 // no arguments (argc = 0) | |||
|
153 | mov r1,r0 | |||
|
154 | mov r2,r0 | |||
|
155 | mov fp,r0 // null frame pointer | |||
|
156 | mov r7,r0 // null frame pointer for thumb | |||
|
157 | ldr r10,=main | |||
|
158 | mov lr,pc | |||
|
159 | bx r10 // enter main() | |||
|
160 | ||||
|
161 | /* "global object"-dtors are never called and it should not be | |||
|
162 | needed since there is no OS to exit to. */ | |||
|
163 | ||||
|
164 | .size _start, . - _start | |||
|
165 | .endfunc | |||
|
166 | ||||
|
167 | .global _reset, reset, exit, abort | |||
|
168 | .func _reset | |||
|
169 | _reset: | |||
|
170 | reset: | |||
|
171 | exit: | |||
|
172 | abort: | |||
|
173 | #if 0 | |||
|
174 | // Disable interrupts, then force a hardware reset by driving P23 low | |||
|
175 | // ------------------------------------------------------------------- | |||
|
176 | mrs r0,cpsr // get PSR | |||
|
177 | orr r0,r0,#I_BIT|F_BIT // disable IRQ and FIQ | |||
|
178 | msr cpsr,r0 // set up status register | |||
|
179 | ||||
|
180 | ldr r1,=(PS_BASE) // PS Base Address | |||
|
181 | ldr r0,=(PS_PIO) // PIO Module | |||
|
182 | str r0,[r1,#PS_PCER_OFF] // enable its clock | |||
|
183 | ldr r1,=(PIO_BASE) // PIO Base Address | |||
|
184 | ldr r0,=(1<<23) // P23 | |||
|
185 | str r0,[r1,#PIO_PER_OFF] // make sure pin is contolled by PIO | |||
|
186 | str r0,[r1,#PIO_CODR_OFF] // set the pin low | |||
|
187 | str r0,[r1,#PIO_OER_OFF] // make it an output | |||
|
188 | #endif | |||
|
189 | b . // loop until reset | |||
|
190 | ||||
|
191 | .size _reset, . - _reset | |||
|
192 | .endfunc | |||
|
193 | ||||
|
194 | .end | |||
|
195 | } |
@@ -0,0 +1,13 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | include $(LIBUC)/rules/common/rules.mk | |||
|
5 | ||||
|
6 | all:subdir | |||
|
7 | make -C helloworld | |||
|
8 | @echo Code compiled | |||
|
9 | ||||
|
10 | clean: | |||
|
11 | make clean -C helloworld | |||
|
12 | @echo Code compiled | |||
|
13 |
@@ -0,0 +1,23 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | HEADERS += | |||
|
6 | APPSOURCES += main.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(APPSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
13 | TARGET=helloworld | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
16 | TARGETINSTALLPATH= | |||
|
17 | HEADERSINSTALLPATH= | |||
|
18 | BSP=MP3PlayerV1 | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:bin | |||
|
22 | @echo Code compiled | |||
|
23 |
@@ -0,0 +1,193 | |||||
|
1 | .global main // int main(void) | |||
|
2 | ||||
|
3 | .global _etext // -> .data initial values in ROM | |||
|
4 | .global _data // -> .data area in RAM | |||
|
5 | .global _edata // end of .data area | |||
|
6 | .global __bss_start // -> .bss area in RAM | |||
|
7 | .global __bss_end__ // end of .bss area | |||
|
8 | .global _stack // top of stack | |||
|
9 | ||||
|
10 | // Stack Sizes | |||
|
11 | .set UND_STACK_SIZE, 0x00000004 | |||
|
12 | .set ABT_STACK_SIZE, 0x00000004 | |||
|
13 | .set FIQ_STACK_SIZE, 0x00000004 | |||
|
14 | .set IRQ_STACK_SIZE, 0X00000080 | |||
|
15 | .set SVC_STACK_SIZE, 0x00000004 | |||
|
16 | ||||
|
17 | // Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs | |||
|
18 | .set MODE_USR, 0x10 // User Mode | |||
|
19 | .set MODE_FIQ, 0x11 // FIQ Mode | |||
|
20 | .set MODE_IRQ, 0x12 // IRQ Mode | |||
|
21 | .set MODE_SVC, 0x13 // Supervisor Mode | |||
|
22 | .set MODE_ABT, 0x17 // Abort Mode | |||
|
23 | .set MODE_UND, 0x1B // Undefined Mode | |||
|
24 | .set MODE_SYS, 0x1F // System Mode | |||
|
25 | ||||
|
26 | .equ I_BIT, 0x80 // when I bit is set, IRQ is disabled | |||
|
27 | .equ F_BIT, 0x40 // when F bit is set, FIQ is disabled | |||
|
28 | ||||
|
29 | .text | |||
|
30 | .code 32 | |||
|
31 | .align 2 | |||
|
32 | ||||
|
33 | .global _boot | |||
|
34 | .func _boot | |||
|
35 | _boot: | |||
|
36 | ||||
|
37 | // Runtime Interrupt Vectors | |||
|
38 | // ------------------------- | |||
|
39 | Vectors: | |||
|
40 | b _start // reset - _start | |||
|
41 | ldr pc,_undf // undefined - _undf | |||
|
42 | ldr pc,_swi // SWI - _swi | |||
|
43 | ldr pc,_pabt // program abort - _pabt | |||
|
44 | ldr pc,_dabt // data abort - _dabt | |||
|
45 | nop // reserved | |||
|
46 | ldr pc,[pc,#-0xFF0] // IRQ - read the VIC | |||
|
47 | ldr pc,_fiq // FIQ - _fiq | |||
|
48 | ||||
|
49 | #if 0 | |||
|
50 | // Use this group for production | |||
|
51 | _undf: .word _reset // undefined - _reset | |||
|
52 | _swi: .word _reset // SWI - _reset | |||
|
53 | _pabt: .word _reset // program abort - _reset | |||
|
54 | _dabt: .word _reset // data abort - _reset | |||
|
55 | _irq: .word _reset // IRQ - _reset | |||
|
56 | _fiq: .word _reset // FIQ - _reset | |||
|
57 | ||||
|
58 | #else | |||
|
59 | // Use this group for development | |||
|
60 | _undf: .word __undf // undefined | |||
|
61 | _swi: .word __swi // SWI | |||
|
62 | _pabt: .word __pabt // program abort | |||
|
63 | _dabt: .word __dabt // data abort | |||
|
64 | _irq: .word __irq // IRQ | |||
|
65 | _fiq: .word __fiq // FIQ | |||
|
66 | ||||
|
67 | __undf: b . // undefined | |||
|
68 | __swi: b . // SWI | |||
|
69 | __pabt: b . // program abort | |||
|
70 | __dabt: b . // data abort | |||
|
71 | __irq: b . // IRQ | |||
|
72 | __fiq: b . // FIQ | |||
|
73 | #endif | |||
|
74 | .size _boot, . - _boot | |||
|
75 | .endfunc | |||
|
76 | ||||
|
77 | ||||
|
78 | // Setup the operating mode & stack. | |||
|
79 | // --------------------------------- | |||
|
80 | .global _start, start, _mainCRTStartup | |||
|
81 | .func _start | |||
|
82 | ||||
|
83 | _start: | |||
|
84 | start: | |||
|
85 | _mainCRTStartup: | |||
|
86 | ||||
|
87 | // Initialize Interrupt System | |||
|
88 | // - Set stack location for each mode | |||
|
89 | // - Leave in System Mode with Interrupts Disabled | |||
|
90 | // ----------------------------------------------- | |||
|
91 | ldr r0,=_stack | |||
|
92 | msr CPSR_c,#MODE_UND|I_BIT|F_BIT // Undefined Instruction Mode | |||
|
93 | mov sp,r0 | |||
|
94 | sub r0,r0,#UND_STACK_SIZE | |||
|
95 | msr CPSR_c,#MODE_ABT|I_BIT|F_BIT // Abort Mode | |||
|
96 | mov sp,r0 | |||
|
97 | sub r0,r0,#ABT_STACK_SIZE | |||
|
98 | msr CPSR_c,#MODE_FIQ|I_BIT|F_BIT // FIQ Mode | |||
|
99 | mov sp,r0 | |||
|
100 | sub r0,r0,#FIQ_STACK_SIZE | |||
|
101 | msr CPSR_c,#MODE_IRQ|I_BIT|F_BIT // IRQ Mode | |||
|
102 | mov sp,r0 | |||
|
103 | sub r0,r0,#IRQ_STACK_SIZE | |||
|
104 | msr CPSR_c,#MODE_SVC|I_BIT|F_BIT // Supervisor Mode | |||
|
105 | mov sp,r0 | |||
|
106 | sub r0,r0,#SVC_STACK_SIZE | |||
|
107 | msr CPSR_c,#MODE_SYS|I_BIT|F_BIT // System Mode | |||
|
108 | mov sp,r0 | |||
|
109 | ||||
|
110 | // Copy initialized data to its execution address in RAM | |||
|
111 | // ----------------------------------------------------- | |||
|
112 | #ifdef ROM_RUN | |||
|
113 | ldr r1,=_etext // -> ROM data start | |||
|
114 | ldr r2,=_data // -> data start | |||
|
115 | ldr r3,=_edata // -> end of data | |||
|
116 | 1: cmp r2,r3 // check if data to move | |||
|
117 | ldrlo r0,[r1],#4 // copy it | |||
|
118 | strlo r0,[r2],#4 | |||
|
119 | blo 1b // loop until done | |||
|
120 | #endif | |||
|
121 | // Clear .bss | |||
|
122 | // ---------- | |||
|
123 | mov r0,#0 // get a zero | |||
|
124 | ldr r1,=__bss_start // -> bss start | |||
|
125 | ldr r2,=__bss_end__ // -> bss end | |||
|
126 | 2: cmp r1,r2 // check if data to clear | |||
|
127 | strlo r0,[r1],#4 // clear 4 bytes | |||
|
128 | blo 2b // loop until done | |||
|
129 | ||||
|
130 | /* | |||
|
131 | Call C++ constructors (for objects in "global scope") | |||
|
132 | ctor loop added by Martin Thomas 4/2005 | |||
|
133 | based on a Anglia Design example-application for ST ARM | |||
|
134 | */ | |||
|
135 | ||||
|
136 | LDR r0, =__ctors_start__ | |||
|
137 | LDR r1, =__ctors_end__ | |||
|
138 | ctor_loop: | |||
|
139 | CMP r0, r1 | |||
|
140 | BEQ ctor_end | |||
|
141 | LDR r2, [r0], #4 | |||
|
142 | STMFD sp!, {r0-r1} | |||
|
143 | MOV lr, pc | |||
|
144 | MOV pc, r2 | |||
|
145 | LDMFD sp!, {r0-r1} | |||
|
146 | B ctor_loop | |||
|
147 | ctor_end: | |||
|
148 | ||||
|
149 | // Call main program: main(0) | |||
|
150 | // -------------------------- | |||
|
151 | mov r0,#0 // no arguments (argc = 0) | |||
|
152 | mov r1,r0 | |||
|
153 | mov r2,r0 | |||
|
154 | mov fp,r0 // null frame pointer | |||
|
155 | mov r7,r0 // null frame pointer for thumb | |||
|
156 | ldr r10,=main | |||
|
157 | mov lr,pc | |||
|
158 | bx r10 // enter main() | |||
|
159 | ||||
|
160 | /* "global object"-dtors are never called and it should not be | |||
|
161 | needed since there is no OS to exit to. */ | |||
|
162 | ||||
|
163 | .size _start, . - _start | |||
|
164 | .endfunc | |||
|
165 | ||||
|
166 | .global _reset, reset, exit, abort | |||
|
167 | .func _reset | |||
|
168 | _reset: | |||
|
169 | reset: | |||
|
170 | exit: | |||
|
171 | abort: | |||
|
172 | #if 0 | |||
|
173 | // Disable interrupts, then force a hardware reset by driving P23 low | |||
|
174 | // ------------------------------------------------------------------- | |||
|
175 | mrs r0,cpsr // get PSR | |||
|
176 | orr r0,r0,#I_BIT|F_BIT // disable IRQ and FIQ | |||
|
177 | msr cpsr,r0 // set up status register | |||
|
178 | ||||
|
179 | ldr r1,=(PS_BASE) // PS Base Address | |||
|
180 | ldr r0,=(PS_PIO) // PIO Module | |||
|
181 | str r0,[r1,#PS_PCER_OFF] // enable its clock | |||
|
182 | ldr r1,=(PIO_BASE) // PIO Base Address | |||
|
183 | ldr r0,=(1<<23) // P23 | |||
|
184 | str r0,[r1,#PIO_PER_OFF] // make sure pin is contolled by PIO | |||
|
185 | str r0,[r1,#PIO_CODR_OFF] // set the pin low | |||
|
186 | str r0,[r1,#PIO_OER_OFF] // make it an output | |||
|
187 | #endif | |||
|
188 | b . // loop until reset | |||
|
189 | ||||
|
190 | .size _reset, . - _reset | |||
|
191 | .endfunc | |||
|
192 | ||||
|
193 | .end |
@@ -0,0 +1,193 | |||||
|
1 | .global main // int main(void) | |||
|
2 | ||||
|
3 | .global _etext // -> .data initial values in ROM | |||
|
4 | .global _data // -> .data area in RAM | |||
|
5 | .global _edata // end of .data area | |||
|
6 | .global __bss_start // -> .bss area in RAM | |||
|
7 | .global __bss_end__ // end of .bss area | |||
|
8 | .global _stack // top of stack | |||
|
9 | ||||
|
10 | // Stack Sizes | |||
|
11 | .set UND_STACK_SIZE, 0x00000004 | |||
|
12 | .set ABT_STACK_SIZE, 0x00000004 | |||
|
13 | .set FIQ_STACK_SIZE, 0x00000004 | |||
|
14 | .set IRQ_STACK_SIZE, 0X00000080 | |||
|
15 | .set SVC_STACK_SIZE, 0x00000004 | |||
|
16 | ||||
|
17 | // Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs | |||
|
18 | .set MODE_USR, 0x10 // User Mode | |||
|
19 | .set MODE_FIQ, 0x11 // FIQ Mode | |||
|
20 | .set MODE_IRQ, 0x12 // IRQ Mode | |||
|
21 | .set MODE_SVC, 0x13 // Supervisor Mode | |||
|
22 | .set MODE_ABT, 0x17 // Abort Mode | |||
|
23 | .set MODE_UND, 0x1B // Undefined Mode | |||
|
24 | .set MODE_SYS, 0x1F // System Mode | |||
|
25 | ||||
|
26 | .equ I_BIT, 0x80 // when I bit is set, IRQ is disabled | |||
|
27 | .equ F_BIT, 0x40 // when F bit is set, FIQ is disabled | |||
|
28 | ||||
|
29 | .text | |||
|
30 | .code 32 | |||
|
31 | .align 2 | |||
|
32 | ||||
|
33 | .global _boot | |||
|
34 | .func _boot | |||
|
35 | _boot: | |||
|
36 | ||||
|
37 | // Runtime Interrupt Vectors | |||
|
38 | // ------------------------- | |||
|
39 | Vectors: | |||
|
40 | b _start // reset - _start | |||
|
41 | ldr pc,_undf // undefined - _undf | |||
|
42 | ldr pc,_swi // SWI - _swi | |||
|
43 | ldr pc,_pabt // program abort - _pabt | |||
|
44 | ldr pc,_dabt // data abort - _dabt | |||
|
45 | nop // reserved | |||
|
46 | ldr pc,[pc,#-0xFF0] // IRQ - read the VIC | |||
|
47 | ldr pc,_fiq // FIQ - _fiq | |||
|
48 | ||||
|
49 | #if 0 | |||
|
50 | // Use this group for production | |||
|
51 | _undf: .word _reset // undefined - _reset | |||
|
52 | _swi: .word _reset // SWI - _reset | |||
|
53 | _pabt: .word _reset // program abort - _reset | |||
|
54 | _dabt: .word _reset // data abort - _reset | |||
|
55 | _irq: .word _reset // IRQ - _reset | |||
|
56 | _fiq: .word _reset // FIQ - _reset | |||
|
57 | ||||
|
58 | #else | |||
|
59 | // Use this group for development | |||
|
60 | _undf: .word __undf // undefined | |||
|
61 | _swi: .word __swi // SWI | |||
|
62 | _pabt: .word __pabt // program abort | |||
|
63 | _dabt: .word __dabt // data abort | |||
|
64 | _irq: .word __irq // IRQ | |||
|
65 | _fiq: .word __fiq // FIQ | |||
|
66 | ||||
|
67 | __undf: b . // undefined | |||
|
68 | __swi: b . // SWI | |||
|
69 | __pabt: b . // program abort | |||
|
70 | __dabt: b . // data abort | |||
|
71 | __irq: b . // IRQ | |||
|
72 | __fiq: b . // FIQ | |||
|
73 | #endif | |||
|
74 | .size _boot, . - _boot | |||
|
75 | .endfunc | |||
|
76 | ||||
|
77 | ||||
|
78 | // Setup the operating mode & stack. | |||
|
79 | // --------------------------------- | |||
|
80 | .global _start, start, _mainCRTStartup | |||
|
81 | .func _start | |||
|
82 | ||||
|
83 | _start: | |||
|
84 | start: | |||
|
85 | _mainCRTStartup: | |||
|
86 | ||||
|
87 | // Initialize Interrupt System | |||
|
88 | // - Set stack location for each mode | |||
|
89 | // - Leave in System Mode with Interrupts Disabled | |||
|
90 | // ----------------------------------------------- | |||
|
91 | ldr r0,=_stack | |||
|
92 | msr CPSR_c,#MODE_UND|I_BIT|F_BIT // Undefined Instruction Mode | |||
|
93 | mov sp,r0 | |||
|
94 | sub r0,r0,#UND_STACK_SIZE | |||
|
95 | msr CPSR_c,#MODE_ABT|I_BIT|F_BIT // Abort Mode | |||
|
96 | mov sp,r0 | |||
|
97 | sub r0,r0,#ABT_STACK_SIZE | |||
|
98 | msr CPSR_c,#MODE_FIQ|I_BIT|F_BIT // FIQ Mode | |||
|
99 | mov sp,r0 | |||
|
100 | sub r0,r0,#FIQ_STACK_SIZE | |||
|
101 | msr CPSR_c,#MODE_IRQ|I_BIT|F_BIT // IRQ Mode | |||
|
102 | mov sp,r0 | |||
|
103 | sub r0,r0,#IRQ_STACK_SIZE | |||
|
104 | msr CPSR_c,#MODE_SVC|I_BIT|F_BIT // Supervisor Mode | |||
|
105 | mov sp,r0 | |||
|
106 | sub r0,r0,#SVC_STACK_SIZE | |||
|
107 | msr CPSR_c,#MODE_SYS|I_BIT|F_BIT // System Mode | |||
|
108 | mov sp,r0 | |||
|
109 | ||||
|
110 | // Copy initialized data to its execution address in RAM | |||
|
111 | // ----------------------------------------------------- | |||
|
112 | #ifdef ROM_RUN | |||
|
113 | ldr r1,=_etext // -> ROM data start | |||
|
114 | ldr r2,=_data // -> data start | |||
|
115 | ldr r3,=_edata // -> end of data | |||
|
116 | 1: cmp r2,r3 // check if data to move | |||
|
117 | ldrlo r0,[r1],#4 // copy it | |||
|
118 | strlo r0,[r2],#4 | |||
|
119 | blo 1b // loop until done | |||
|
120 | #endif | |||
|
121 | // Clear .bss | |||
|
122 | // ---------- | |||
|
123 | mov r0,#0 // get a zero | |||
|
124 | ldr r1,=__bss_start // -> bss start | |||
|
125 | ldr r2,=__bss_end__ // -> bss end | |||
|
126 | 2: cmp r1,r2 // check if data to clear | |||
|
127 | strlo r0,[r1],#4 // clear 4 bytes | |||
|
128 | blo 2b // loop until done | |||
|
129 | ||||
|
130 | /* | |||
|
131 | Call C++ constructors (for objects in "global scope") | |||
|
132 | ctor loop added by Martin Thomas 4/2005 | |||
|
133 | based on a Anglia Design example-application for ST ARM | |||
|
134 | */ | |||
|
135 | ||||
|
136 | LDR r0, =__ctors_start__ | |||
|
137 | LDR r1, =__ctors_end__ | |||
|
138 | ctor_loop: | |||
|
139 | CMP r0, r1 | |||
|
140 | BEQ ctor_end | |||
|
141 | LDR r2, [r0], #4 | |||
|
142 | STMFD sp!, {r0-r1} | |||
|
143 | MOV lr, pc | |||
|
144 | MOV pc, r2 | |||
|
145 | LDMFD sp!, {r0-r1} | |||
|
146 | B ctor_loop | |||
|
147 | ctor_end: | |||
|
148 | ||||
|
149 | // Call main program: main(0) | |||
|
150 | // -------------------------- | |||
|
151 | mov r0,#0 // no arguments (argc = 0) | |||
|
152 | mov r1,r0 | |||
|
153 | mov r2,r0 | |||
|
154 | mov fp,r0 // null frame pointer | |||
|
155 | mov r7,r0 // null frame pointer for thumb | |||
|
156 | ldr r10,=main | |||
|
157 | mov lr,pc | |||
|
158 | bx r10 // enter main() | |||
|
159 | ||||
|
160 | /* "global object"-dtors are never called and it should not be | |||
|
161 | needed since there is no OS to exit to. */ | |||
|
162 | ||||
|
163 | .size _start, . - _start | |||
|
164 | .endfunc | |||
|
165 | ||||
|
166 | .global _reset, reset, exit, abort | |||
|
167 | .func _reset | |||
|
168 | _reset: | |||
|
169 | reset: | |||
|
170 | exit: | |||
|
171 | abort: | |||
|
172 | #if 0 | |||
|
173 | // Disable interrupts, then force a hardware reset by driving P23 low | |||
|
174 | // ------------------------------------------------------------------- | |||
|
175 | mrs r0,cpsr // get PSR | |||
|
176 | orr r0,r0,#I_BIT|F_BIT // disable IRQ and FIQ | |||
|
177 | msr cpsr,r0 // set up status register | |||
|
178 | ||||
|
179 | ldr r1,=(PS_BASE) // PS Base Address | |||
|
180 | ldr r0,=(PS_PIO) // PIO Module | |||
|
181 | str r0,[r1,#PS_PCER_OFF] // enable its clock | |||
|
182 | ldr r1,=(PIO_BASE) // PIO Base Address | |||
|
183 | ldr r0,=(1<<23) // P23 | |||
|
184 | str r0,[r1,#PIO_PER_OFF] // make sure pin is contolled by PIO | |||
|
185 | str r0,[r1,#PIO_CODR_OFF] // set the pin low | |||
|
186 | str r0,[r1,#PIO_OER_OFF] // make it an output | |||
|
187 | #endif | |||
|
188 | b . // loop until reset | |||
|
189 | ||||
|
190 | .size _reset, . - _reset | |||
|
191 | .endfunc | |||
|
192 | ||||
|
193 | .end |
@@ -0,0 +1,12 | |||||
|
1 | TEMPLATE = app | |||
|
2 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
3 | TARGET = helloworld | |||
|
4 | BSP = MP3PlayerV1 | |||
|
5 | ||||
|
6 | LIBS += UART CORE UCSTRINGS UHANDLE | |||
|
7 | ||||
|
8 | SOURCES += main.c | |||
|
9 | ||||
|
10 | ||||
|
11 | HEADERS += | |||
|
12 |
@@ -0,0 +1,88 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | ||||
|
23 | #include "LPC23xx.h" | |||
|
24 | #include "bsp.h" | |||
|
25 | #include "core.h" | |||
|
26 | #include "uart.h" | |||
|
27 | #include "libucstrings.h" | |||
|
28 | ||||
|
29 | #define __delay(t) for(volatile int i=0;i<t;i++); | |||
|
30 | #define ledspos1 LED1_OFF;LED2_ON;LED3_OFF;LED4_ON;LED5_OFF;LED6_ON;LED7_OFF;LED8_ON | |||
|
31 | #define ledspos2 LED1_ON;LED2_OFF;LED3_ON;LED4_OFF;LED5_ON;LED6_OFF;LED7_ON;LED8_OFF | |||
|
32 | int main (void) | |||
|
33 | { | |||
|
34 | ||||
|
35 | bsp_init(); | |||
|
36 | //uartsetbaudrate(UART0,38400); | |||
|
37 | while(1)libucprintf("hello\n\r"); | |||
|
38 | ||||
|
39 | } | |||
|
40 | ||||
|
41 | ||||
|
42 | ||||
|
43 | ||||
|
44 | ||||
|
45 | ||||
|
46 | ||||
|
47 | ||||
|
48 | ||||
|
49 | ||||
|
50 | ||||
|
51 | ||||
|
52 | ||||
|
53 | ||||
|
54 | ||||
|
55 | ||||
|
56 | ||||
|
57 | ||||
|
58 | ||||
|
59 | ||||
|
60 | ||||
|
61 | ||||
|
62 | ||||
|
63 | ||||
|
64 | ||||
|
65 | ||||
|
66 | ||||
|
67 | ||||
|
68 | ||||
|
69 | ||||
|
70 | ||||
|
71 | ||||
|
72 | ||||
|
73 | ||||
|
74 | ||||
|
75 | ||||
|
76 | ||||
|
77 | ||||
|
78 | ||||
|
79 | ||||
|
80 | ||||
|
81 | ||||
|
82 | ||||
|
83 | ||||
|
84 | ||||
|
85 | ||||
|
86 | ||||
|
87 | ||||
|
88 |
@@ -0,0 +1,11 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | all: | |||
|
6 | make -f lpc17XX.mk | |||
|
7 | make -f lpc21XX.mk | |||
|
8 | ||||
|
9 | clean: | |||
|
10 | make clean -f lpc17XX.mk | |||
|
11 | make clean -f lpc21XX.mk |
@@ -0,0 +1,140 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #include "fsexplorer.h" | |||
|
23 | ||||
|
24 | ||||
|
25 | int fsexplprintSector(blkdevice* dev,unsigned int sectorIndex) | |||
|
26 | { | |||
|
27 | char sector[512]; | |||
|
28 | if(dev) | |||
|
29 | { | |||
|
30 | libucprintf("\n\r"); | |||
|
31 | libucprintf("========================================================\n\r"); | |||
|
32 | libucprintf("============== S E C T O R V I E W E R ==============\n\r"); | |||
|
33 | libucprintf("========================================================\n\r"); | |||
|
34 | libucprintf("Print sector N°%d\n\r",sectorIndex); | |||
|
35 | dev->read(dev,sector,sectorIndex,1); | |||
|
36 | hexviewershow(sector,512,sectorIndex*512); | |||
|
37 | libucprintf("\n\r"); | |||
|
38 | libucprintf("________________________________________________________\n\r"); | |||
|
39 | } | |||
|
40 | ||||
|
41 | } | |||
|
42 | ||||
|
43 | int fsexplprintPartInfos(dikpartition* part) | |||
|
44 | { | |||
|
45 | char sector[512]; | |||
|
46 | if(part) | |||
|
47 | { | |||
|
48 | libucprintf("\n\r"); | |||
|
49 | libucprintf("========================================================\n\r"); | |||
|
50 | libucprintf("=== P A R T I T I O N I N F O s P R I N T E R ====\n\r"); | |||
|
51 | libucprintf("========================================================\n\r"); | |||
|
52 | part->phy->read(part->phy,sector,part->LBABegin,1); | |||
|
53 | hexviewershow(sector,512,0); | |||
|
54 | libucprintf("\n\r"); | |||
|
55 | libucprintf("FAT32 PART lba begin = %d\n\r",0xFFFF & part->LBABegin); | |||
|
56 | libucprintf("________________________________________________________\n\r"); | |||
|
57 | } | |||
|
58 | } | |||
|
59 | ||||
|
60 | ||||
|
61 | int fsexplprintBootSector(blkdevice* dev) | |||
|
62 | { | |||
|
63 | char sector[512]; | |||
|
64 | if(dev) | |||
|
65 | { | |||
|
66 | libucprintf("\n\r"); | |||
|
67 | libucprintf("========================================================\n\r"); | |||
|
68 | libucprintf("======== B O O T S E C T O R P R I N T E R =======\n\r"); | |||
|
69 | libucprintf("========================================================\n\r"); | |||
|
70 | dev->read(dev,sector,0,1); | |||
|
71 | hexviewershow(sector,512,0); | |||
|
72 | libucprintf("\n\r"); | |||
|
73 | libucprintf("________________________________________________________\n\r"); | |||
|
74 | } | |||
|
75 | ||||
|
76 | } | |||
|
77 | ||||
|
78 | int fsexplprintDirentInfos(ucdirent* dirent) | |||
|
79 | { | |||
|
80 | if(dirent) | |||
|
81 | { | |||
|
82 | libucprintf("\n\r"); | |||
|
83 | libucprintf("========================================================\n\r"); | |||
|
84 | libucprintf("======== E N T R Y I N F O P R I N T E R =======\n\r"); | |||
|
85 | libucprintf("========================================================\n\r"); | |||
|
86 | libucprintf("Entry Name:\t"); | |||
|
87 | libucprintf(dirent->DIR_Name); | |||
|
88 | libucprintf("\n\r"); | |||
|
89 | libucprintf("--------------------------------------------------------\n\r"); | |||
|
90 | if(dirent->DIR_Attr&ATTR_READ_ONLY)libucprintf("This entry is read only\n\r"); | |||
|
91 | if(dirent->DIR_Attr&ATTR_HIDDEN)libucprintf("This entry is hidden\n\r"); | |||
|
92 | if(dirent->DIR_Attr&ATTR_SYSTEM)libucprintf("This entry is a system file/folder\n\r"); | |||
|
93 | if(dirent->DIR_Attr&ATTR_VOLUME_ID)libucprintf("This entry is the root entry of the system\n\r"); | |||
|
94 | if(dirent->DIR_Attr&ATTR_DIRECTORY)libucprintf("This entry is a directory\n\r"); | |||
|
95 | if(dirent->DIR_Attr&ATTR_ARCHIVE)libucprintf("This entry is an archive\n\r"); | |||
|
96 | if(dirent->DIR_Attr&ATTR_LONGNAME)libucprintf("This entry is a long name entry\n\r"); | |||
|
97 | libucprintf("In sector %d\n\r",dirent->CurrentSec); | |||
|
98 | libucprintf("Entry %d\n\r",dirent->Currententry); | |||
|
99 | libucprintf("________________________________________________________\n\r"); | |||
|
100 | return 0; | |||
|
101 | } | |||
|
102 | return 1; | |||
|
103 | } | |||
|
104 | ||||
|
105 | ||||
|
106 | ||||
|
107 | ||||
|
108 | ||||
|
109 | ||||
|
110 | ||||
|
111 | ||||
|
112 | ||||
|
113 | ||||
|
114 | ||||
|
115 | ||||
|
116 | ||||
|
117 | ||||
|
118 | ||||
|
119 | ||||
|
120 | ||||
|
121 | ||||
|
122 | ||||
|
123 | ||||
|
124 | ||||
|
125 | ||||
|
126 | ||||
|
127 | ||||
|
128 | ||||
|
129 | ||||
|
130 | ||||
|
131 | ||||
|
132 | ||||
|
133 | ||||
|
134 | ||||
|
135 | ||||
|
136 | ||||
|
137 | ||||
|
138 | ||||
|
139 | ||||
|
140 |
@@ -0,0 +1,74 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef FSEXPLORER_H | |||
|
23 | #define FSEXPLORER_H | |||
|
24 | #include <blkdevice.h> | |||
|
25 | #include <sdcard.h> | |||
|
26 | #include <mbr.h> | |||
|
27 | #include <fat32.h> | |||
|
28 | #include <libucstrings.h> | |||
|
29 | #include <hexviewer.h> | |||
|
30 | #include <ucdirent.h> | |||
|
31 | ||||
|
32 | extern int fsexplprintDirentInfos(ucdirent* dirent); | |||
|
33 | extern int fsexplprintBootSector(blkdevice* dev); | |||
|
34 | extern int fsexplprintPartInfos(dikpartition* part); | |||
|
35 | extern int fsexplprintSector(blkdevice* dev,unsigned int sectorIndex); | |||
|
36 | ||||
|
37 | ||||
|
38 | ||||
|
39 | ||||
|
40 | #endif | |||
|
41 | ||||
|
42 | ||||
|
43 | ||||
|
44 | ||||
|
45 | ||||
|
46 | ||||
|
47 | ||||
|
48 | ||||
|
49 | ||||
|
50 | ||||
|
51 | ||||
|
52 | ||||
|
53 | ||||
|
54 | ||||
|
55 | ||||
|
56 | ||||
|
57 | ||||
|
58 | ||||
|
59 | ||||
|
60 | ||||
|
61 | ||||
|
62 | ||||
|
63 | ||||
|
64 | ||||
|
65 | ||||
|
66 | ||||
|
67 | ||||
|
68 | ||||
|
69 | ||||
|
70 | ||||
|
71 | ||||
|
72 | ||||
|
73 | ||||
|
74 |
@@ -0,0 +1,26 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | lpc17XX.ARCH = lpc17XX-arm-noabi-gcc | |||
|
3 | lpc17XX.TARGET = libfsexplorer | |||
|
4 | lpc17XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_FSEXPLORER) | |||
|
5 | lpc17XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FSEXPLORER) | |||
|
6 | ||||
|
7 | lpc17XX.LIBS += HEXVIEWER ALLFS UCSTRINGS UHANDLE | |||
|
8 | ||||
|
9 | lpc17XX.SOURCES += fsexplorer.c | |||
|
10 | ||||
|
11 | ||||
|
12 | lpc17XX.HEADERS += fsexplorer.h | |||
|
13 | ||||
|
14 | ||||
|
15 | ||||
|
16 | lpc21XX.ARCH = lpc21XX-arm-noabi-gcc | |||
|
17 | lpc21XX.TARGET = libfsexplorer | |||
|
18 | lpc21XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_FSEXPLORER) | |||
|
19 | lpc21XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FSEXPLORER) | |||
|
20 | ||||
|
21 | lpc21XX.LIBS += HEXVIEWER ALLFS UCSTRINGS UHANDLE | |||
|
22 | ||||
|
23 | lpc21XX.SOURCES += fsexplorer.c | |||
|
24 | ||||
|
25 | ||||
|
26 | lpc21XX.HEADERS += fsexplorer.h |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FSEXPLORER) | |||
|
5 | HEADERS += fsexplorer.h | |||
|
6 | LIBSOURCES += fsexplorer.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |||
|
13 | TARGET=libfsexplorer | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_HEXVIEWER_CMD) $(LIBUC_INC_DIR_ALLFS_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_HEXVIEWER_CMD) $(LIBUC_LIBS_HEXVIEWER) $(LIBUC_LIBS_DIR_ALLFS_CMD) $(LIBUC_LIBS_ALLFS) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_FSEXPLORER) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_FSEXPLORER) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FSEXPLORER) | |||
|
5 | HEADERS += fsexplorer.h | |||
|
6 | LIBSOURCES += fsexplorer.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
13 | TARGET=libfsexplorer | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_HEXVIEWER_CMD) $(LIBUC_INC_DIR_ALLFS_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) $(LIBUC_INC_DIR_HEXVIEWER_CMD) $(LIBUC_INC_DIR_ALLFS_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_HEXVIEWER_CMD) $(LIBUC_LIBS_HEXVIEWER) $(LIBUC_LIBS_DIR_ALLFS_CMD) $(LIBUC_LIBS_ALLFS) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) $(LIBUC_LIBS_DIR_HEXVIEWER_CMD) $(LIBUC_LIBS_HEXVIEWER) $(LIBUC_LIBS_DIR_ALLFS_CMD) $(LIBUC_LIBS_ALLFS) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_FSEXPLORER) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_FSEXPLORER) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,13 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | include $(LIBUC)/rules/common/rules.mk | |||
|
5 | ||||
|
6 | all:subdir | |||
|
7 | make -C FS_Explorer | |||
|
8 | @echo Code compiled | |||
|
9 | ||||
|
10 | clean: | |||
|
11 | make clean -C FS_Explorer | |||
|
12 | @echo Code compiled | |||
|
13 |
@@ -0,0 +1,11 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | all: | |||
|
6 | make -f lpc17XX.mk | |||
|
7 | make -f lpc21XX.mk | |||
|
8 | ||||
|
9 | clean: | |||
|
10 | make clean -f lpc17XX.mk | |||
|
11 | make clean -f lpc21XX.mk |
@@ -0,0 +1,23 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | ||||
|
23 | #include "blkdevice.h" |
@@ -0,0 +1,128 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef BLKDEVICE_H | |||
|
23 | #define BLKDEVICE_H | |||
|
24 | #include <uhandle.h> | |||
|
25 | /* Disk Status Bits (DSTATUS) */ | |||
|
26 | ||||
|
27 | #define STA_NOINIT 0x01 /* Drive not initialized */ | |||
|
28 | #define STA_NODISK 0x02 /* No medium in the drive */ | |||
|
29 | #define STA_PROTECT 0x04 /* Write protected */ | |||
|
30 | ||||
|
31 | ||||
|
32 | /* Command code for disk_ioctrl fucntion */ | |||
|
33 | /* Generic ioctl command (defined for FatFs) */ | |||
|
34 | #define CTRL_SYNC 0 /* Flush disk cache (for write functions) */ | |||
|
35 | #define GET_SECTOR_COUNT 1 /* Get media size (for only f_mkfs()) */ | |||
|
36 | #define GET_SECTOR_SIZE 2 /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */ | |||
|
37 | #define GET_BLOCK_SIZE 3 /* Get erase block size (for only f_mkfs()) */ | |||
|
38 | #define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */ | |||
|
39 | ||||
|
40 | /* Generic ioctl command */ | |||
|
41 | #define CTRL_POWER 5 /* Get/Set power status */ | |||
|
42 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ | |||
|
43 | #define CTRL_EJECT 7 /* Eject media */ | |||
|
44 | ||||
|
45 | /* MMC/SDC specific ioctl command */ | |||
|
46 | #define MMC_GET_TYPE 10 /* Get card type */ | |||
|
47 | #define MMC_GET_CSD 11 /* Get CSD */ | |||
|
48 | #define MMC_GET_CID 12 /* Get CID */ | |||
|
49 | #define MMC_GET_OCR 13 /* Get OCR */ | |||
|
50 | #define MMC_GET_SDSTAT 14 /* Get SD status */ | |||
|
51 | ||||
|
52 | /* ATA/CF specific ioctl command */ | |||
|
53 | #define ATA_GET_REV 20 /* Get F/W revision */ | |||
|
54 | #define ATA_GET_MODEL 21 /* Get model name */ | |||
|
55 | #define ATA_GET_SN 22 /* Get serial number */ | |||
|
56 | ||||
|
57 | /* NAND specific ioctl command */ | |||
|
58 | #define NAND_FORMAT 30 /* Create physical format */ | |||
|
59 | ||||
|
60 | /* Status of Disk Functions */ | |||
|
61 | typedef unsigned char DSTATUS; | |||
|
62 | ||||
|
63 | /* Results of Disk Functions */ | |||
|
64 | typedef enum { | |||
|
65 | RES_OK = 0, /* 0: Successful */ | |||
|
66 | RES_ERROR, /* 1: R/W Error */ | |||
|
67 | RES_WRPRT, /* 2: Write Protected */ | |||
|
68 | RES_NOTRDY, /* 3: Not Ready */ | |||
|
69 | RES_PARERR /* 4: Invalid Parameter */ | |||
|
70 | } DRESULT; | |||
|
71 | ||||
|
72 | typedef volatile struct blkdevice_str blkdevice; | |||
|
73 | ||||
|
74 | typedef void (*blkdevselect_t)(char); | |||
|
75 | typedef void (*blkdevpower_t)(char) ; | |||
|
76 | typedef char (*blkdevdetect_t)() ; | |||
|
77 | typedef char (*blkdevwriteprotected_t)() ; | |||
|
78 | typedef DRESULT (*blkdevwrite_t)(blkdevice* _this,const char *buff,unsigned long sector,char count) ; | |||
|
79 | typedef DRESULT (*blkdevread_t)(blkdevice* _this,char *buff,unsigned long sector,char count) ; | |||
|
80 | typedef DRESULT (*blkdevioctl_t)(blkdevice* _this,char ctrl,void *buff) ; | |||
|
81 | typedef DSTATUS (*blkdevinitialize_t)(blkdevice* _this) ; | |||
|
82 | typedef DSTATUS (*blkdevstatus_t) (blkdevice* _this) ; | |||
|
83 | ||||
|
84 | struct blkdevice_str | |||
|
85 | { | |||
|
86 | UHANDLE phy; | |||
|
87 | unsigned int size; | |||
|
88 | unsigned int MaxSpeed; | |||
|
89 | unsigned char Version; | |||
|
90 | blkdevselect_t select; | |||
|
91 | blkdevpower_t power; | |||
|
92 | blkdevdetect_t detect; | |||
|
93 | blkdevwriteprotected_t writeprotected; | |||
|
94 | blkdevwrite_t write; | |||
|
95 | blkdevread_t read; | |||
|
96 | blkdevioctl_t ioctl; | |||
|
97 | blkdevinitialize_t initialize; | |||
|
98 | blkdevstatus_t status; | |||
|
99 | }; | |||
|
100 | ||||
|
101 | ||||
|
102 | ||||
|
103 | ||||
|
104 | ||||
|
105 | ||||
|
106 | #endif | |||
|
107 | ||||
|
108 | ||||
|
109 | ||||
|
110 | ||||
|
111 | ||||
|
112 | ||||
|
113 | ||||
|
114 | ||||
|
115 | ||||
|
116 | ||||
|
117 | ||||
|
118 | ||||
|
119 | ||||
|
120 | ||||
|
121 | ||||
|
122 | ||||
|
123 | ||||
|
124 | ||||
|
125 | ||||
|
126 | ||||
|
127 | ||||
|
128 |
@@ -0,0 +1,26 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | lpc17XX.ARCH = lpc17XX-arm-noabi-gcc | |||
|
3 | lpc17XX.TARGET = libblkdevice | |||
|
4 | lpc17XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_BLKDEVICE) | |||
|
5 | lpc17XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_BLKDEVICE) | |||
|
6 | ||||
|
7 | lpc17XX.LIBS += UHANDLE | |||
|
8 | ||||
|
9 | lpc17XX.SOURCES += blkdevice.c | |||
|
10 | ||||
|
11 | ||||
|
12 | lpc17XX.HEADERS += blkdevice.h | |||
|
13 | ||||
|
14 | ||||
|
15 | ||||
|
16 | lpc21XX.ARCH = lpc21XX-arm-noabi-gcc | |||
|
17 | lpc21XX.TARGET = libblkdevice | |||
|
18 | lpc21XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_BLKDEVICE) | |||
|
19 | lpc21XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_BLKDEVICE) | |||
|
20 | ||||
|
21 | lpc21XX.LIBS += UHANDLE | |||
|
22 | ||||
|
23 | lpc21XX.SOURCES += blkdevice.c | |||
|
24 | ||||
|
25 | ||||
|
26 | lpc21XX.HEADERS += blkdevice.h |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_BLKDEVICE) | |||
|
5 | HEADERS += blkdevice.h | |||
|
6 | LIBSOURCES += blkdevice.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |||
|
13 | TARGET=libblkdevice | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_BLKDEVICE) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_BLKDEVICE) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_BLKDEVICE) | |||
|
5 | HEADERS += blkdevice.h | |||
|
6 | LIBSOURCES += blkdevice.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
13 | TARGET=libblkdevice | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_UHANDLE_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_BLKDEVICE) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_BLKDEVICE) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,11 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | all: | |||
|
6 | make -f lpc17XX.mk | |||
|
7 | make -f lpc21XX.mk | |||
|
8 | ||||
|
9 | clean: | |||
|
10 | make clean -f lpc17XX.mk | |||
|
11 | make clean -f lpc21XX.mk |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_UCDIRENT) | |||
|
5 | HEADERS += ucdirent.h | |||
|
6 | LIBSOURCES += ucdirent.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |||
|
13 | TARGET=libucdirent | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_UCDIRENT) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_UCDIRENT) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_UCDIRENT) | |||
|
5 | HEADERS += ucdirent.h | |||
|
6 | LIBSOURCES += ucdirent.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
13 | TARGET=libucdirent | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) $(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) $(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_UCDIRENT) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_UCDIRENT) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 |
@@ -0,0 +1,110 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef UCDIRENT_H | |||
|
23 | #define UCDIRENT_H | |||
|
24 | #include <uhandle.h> | |||
|
25 | #include <blkdevice.h> | |||
|
26 | //#include <fs.h> | |||
|
27 | ||||
|
28 | #define ATTR_READ_ONLY 0x01 | |||
|
29 | #define ATTR_HIDDEN 0x02 | |||
|
30 | #define ATTR_SYSTEM 0x04 | |||
|
31 | #define ATTR_VOLUME_ID 0x08 | |||
|
32 | #define ATTR_DIRECTORY 0x10 | |||
|
33 | #define ATTR_ARCHIVE 0x20 | |||
|
34 | #define ATTR_LONGNAME 0x0F | |||
|
35 | ||||
|
36 | #define DIRENT_EndOfDir 1 | |||
|
37 | #define DIRENT_BabArg 2 | |||
|
38 | #define DIRENT_ReadErr 3 | |||
|
39 | #define DIRENT_LastSect 4 | |||
|
40 | #define DIRENT_BadSect 5 | |||
|
41 | #define DIRENT_noErr 0 | |||
|
42 | ||||
|
43 | typedef struct dirent_str ucdirent; | |||
|
44 | typedef int (*getrootfirstent_t)(ucdirent* entry); | |||
|
45 | typedef int (*nextdirent_t)(ucdirent* entry); | |||
|
46 | ||||
|
47 | ||||
|
48 | struct dirent_str | |||
|
49 | { | |||
|
50 | unsigned char DIR_Name[16]; | |||
|
51 | unsigned char DIR_Attr; | |||
|
52 | unsigned char DIR_CrtTimeTenth; | |||
|
53 | unsigned short DIR_CrtTime; | |||
|
54 | unsigned short DIR_CrtDate; | |||
|
55 | unsigned short DIR_LstAccDate; | |||
|
56 | unsigned short DIR_FstClusHI; | |||
|
57 | unsigned short DIR_WrtTime; | |||
|
58 | unsigned short DIR_WrtDate; | |||
|
59 | unsigned short DIR_FstClustLO; | |||
|
60 | unsigned int DIR_FileSize; | |||
|
61 | unsigned int CurrentSec; | |||
|
62 | unsigned char Currententry; | |||
|
63 | UHANDLE fs; | |||
|
64 | getrootfirstent_t getrootfirstent; | |||
|
65 | nextdirent_t nextdirent; | |||
|
66 | }; | |||
|
67 | ||||
|
68 | ||||
|
69 | #define direntgetroot(dirent) (dirent).getrootfirstent(&dirent) | |||
|
70 | #define direntgetnext(dirent) (dirent).nextdirent(&dirent) | |||
|
71 | ||||
|
72 | #endif | |||
|
73 | ||||
|
74 | ||||
|
75 | ||||
|
76 | ||||
|
77 | ||||
|
78 | ||||
|
79 | ||||
|
80 | ||||
|
81 | ||||
|
82 | ||||
|
83 | ||||
|
84 | ||||
|
85 | ||||
|
86 | ||||
|
87 | ||||
|
88 | ||||
|
89 | ||||
|
90 | ||||
|
91 | ||||
|
92 | ||||
|
93 | ||||
|
94 | ||||
|
95 | ||||
|
96 | ||||
|
97 | ||||
|
98 | ||||
|
99 | ||||
|
100 | ||||
|
101 | ||||
|
102 | ||||
|
103 | ||||
|
104 | ||||
|
105 | ||||
|
106 | ||||
|
107 | ||||
|
108 | ||||
|
109 | ||||
|
110 |
@@ -0,0 +1,26 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | lpc17XX.ARCH = lpc17XX-arm-noabi-gcc | |||
|
3 | lpc17XX.TARGET = libucdirent | |||
|
4 | lpc17XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_UCDIRENT) | |||
|
5 | lpc17XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_UCDIRENT) | |||
|
6 | ||||
|
7 | lpc17XX.LIBS += BLKDEVICE UCSTRINGS UHANDLE | |||
|
8 | ||||
|
9 | lpc17XX.SOURCES += ucdirent.c | |||
|
10 | ||||
|
11 | ||||
|
12 | lpc17XX.HEADERS += ucdirent.h | |||
|
13 | ||||
|
14 | ||||
|
15 | ||||
|
16 | lpc21XX.ARCH = lpc21XX-arm-noabi-gcc | |||
|
17 | lpc21XX.TARGET = libucdirent | |||
|
18 | lpc21XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_UCDIRENT) | |||
|
19 | lpc21XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_UCDIRENT) | |||
|
20 | ||||
|
21 | lpc21XX.LIBS += BLKDEVICE UCSTRINGS UHANDLE | |||
|
22 | ||||
|
23 | lpc21XX.SOURCES += ucdirent.c | |||
|
24 | ||||
|
25 | ||||
|
26 | lpc21XX.HEADERS += ucdirent.h |
@@ -0,0 +1,11 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | all: | |||
|
6 | make -f lpc17XX.mk | |||
|
7 | make -f lpc21XX.mk | |||
|
8 | ||||
|
9 | clean: | |||
|
10 | make clean -f lpc17XX.mk | |||
|
11 | make clean -f lpc21XX.mk |
@@ -0,0 +1,176 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #include "fat32.h" | |||
|
23 | #include "libucstrings.h" | |||
|
24 | ||||
|
25 | char fat32buff[512]; | |||
|
26 | unsigned int lastSecAddrs=-1; | |||
|
27 | FAT32fs* lastFATFS=0; | |||
|
28 | ||||
|
29 | int fat32open(FAT32fs* fs,dikpartition* part) | |||
|
30 | { | |||
|
31 | char sector[512]; | |||
|
32 | fs->part = part; | |||
|
33 | if(!isFat32(fs->part->TypeCode))return FATBadpart; | |||
|
34 | if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr; | |||
|
35 | fs->BPB_BytsPerSec = sector[BPB_BytsPerSecoff] + (sector[BPB_BytsPerSecoff+1]<<8); | |||
|
36 | fs->BPB_RsvdSecCnt = sector[BPB_RsvdSecCntoff] + (sector[BPB_RsvdSecCntoff+1]<<8); | |||
|
37 | fs->BPB_FATSz32 = sector[BPB_FATSz32off] + (sector[BPB_FATSz32off+1]<<8) + (sector[BPB_FATSz32off+2]<<16) + (sector[BPB_FATSz32off+3]<<24); | |||
|
38 | fs->BPB_RootClus = sector[BPB_RootClusoff] + (sector[BPB_RootClusoff+1]<<8) + (sector[BPB_RootClusoff+2]<<16) + (sector[BPB_RootClusoff+3]<<24); | |||
|
39 | fs->BPB_SecPerClus = sector[BPB_SecPerClusoff]; | |||
|
40 | fs->BPB_NumFATs = sector[BPB_NumFATsoff]; | |||
|
41 | fs->fat_begin_lba = (unsigned int)fs->part->LBABegin + (unsigned int)(unsigned short)fs->BPB_RsvdSecCnt; | |||
|
42 | fs->cluster_begin_lba = (unsigned int)fs->fat_begin_lba + ((unsigned int)fs->BPB_NumFATs * (unsigned int)fs->BPB_FATSz32 ); | |||
|
43 | return FATnoErr; | |||
|
44 | } | |||
|
45 | ||||
|
46 | int fat32mkdirent(FAT32fs* fs,ucdirent* dirent) | |||
|
47 | { | |||
|
48 | if(fs==0) return DIRENT_BabArg; | |||
|
49 | if(dirent==0) return DIRENT_BabArg; | |||
|
50 | dirent->fs = (UHANDLE)fs; | |||
|
51 | dirent->getrootfirstent = &fat32getrootfirstent; | |||
|
52 | dirent->nextdirent = &fat32nextdirent; | |||
|
53 | return DIRENT_noErr; | |||
|
54 | } | |||
|
55 | ||||
|
56 | ||||
|
57 | int fat32getrootfirstent(ucdirent* entry) | |||
|
58 | { | |||
|
59 | entry->CurrentSec = ((FAT32fs*)entry->fs)->cluster_begin_lba; | |||
|
60 | entry->Currententry = -1; | |||
|
61 | return fat32nextdirent(entry); | |||
|
62 | } | |||
|
63 | ||||
|
64 | ||||
|
65 | int fat32nextdirent(ucdirent* entry) | |||
|
66 | { | |||
|
67 | int n=0,res=DIRENT_noErr,k,j; | |||
|
68 | k=(((signed char)entry->Currententry)+1)*32; /*Restart at last dir entry*/ | |||
|
69 | j=entry->CurrentSec;//-((FAT32fs*)entry->fs)->cluster_begin_lba; /*Restart at last sector*/ | |||
|
70 | do | |||
|
71 | { | |||
|
72 | if((lastSecAddrs!=j) || (lastFATFS!=((FAT32fs*)entry->fs))) | |||
|
73 | { | |||
|
74 | if(((FAT32fs*)entry->fs)->part->phy->read(((FAT32fs*)entry->fs)->part->phy,fat32buff,j,1)!=RES_OK) | |||
|
75 | { | |||
|
76 | return DIRENT_ReadErr; | |||
|
77 | } | |||
|
78 | } | |||
|
79 | for(k=k;k<(512);k+=32) /*512 Bytes per sector and 32 bytes per entry*/ | |||
|
80 | { | |||
|
81 | if(fat32buff[DIR_Nameoff+k]!=0xE5) /*0xE5 = free entry*/ | |||
|
82 | { | |||
|
83 | if(fat32buff[DIR_Nameoff+k]==0) return DIRENT_EndOfDir; /*0x00 = end of dir*/ | |||
|
84 | else | |||
|
85 | if(fat32buff[DIR_Attroff + k]!=ATTR_LONGNAME) | |||
|
86 | { | |||
|
87 | for(n=0;n<11;n++)entry->DIR_Name[n] = fat32buff[n+DIR_Nameoff + k]; | |||
|
88 | entry->DIR_Attr = fat32buff[DIR_Attroff + k]; | |||
|
89 | entry->DIR_CrtTimeTenth = fat32buff[DIR_CrtTimeTenthoff + k]; | |||
|
90 | entry->DIR_CrtTime = fat32buff[DIR_CrtTimeoff + k] + (fat32buff[DIR_CrtTimeoff+1 + k]<<8); | |||
|
91 | entry->DIR_CrtDate = fat32buff[DIR_CrtDateoff + k] + (fat32buff[DIR_CrtDateoff+1 + k]<<8); | |||
|
92 | entry->DIR_LstAccDate = fat32buff[DIR_LstAccDateoff + k] + (fat32buff[DIR_LstAccDateoff+1 + k]<<8); | |||
|
93 | entry->DIR_FstClusHI = fat32buff[DIR_FstClusHIoff + k] + (fat32buff[DIR_FstClusHIoff+1 + k]<<8); | |||
|
94 | entry->DIR_WrtTime = fat32buff[DIR_WrtTimeoff + k] + (fat32buff[DIR_WrtTimeoff+1 + k]<<8); | |||
|
95 | entry->DIR_FstClustLO = fat32buff[DIR_FstClusLOoff + k] + (fat32buff[DIR_FstClusLOoff+1 + k]<<8); | |||
|
96 | entry->DIR_FileSize = fat32buff[DIR_FileSizeoff + k] + (fat32buff[DIR_FileSizeoff+1 + k]<<8) + (fat32buff[DIR_FileSizeoff+2 + k]<<16) + (fat32buff[DIR_FileSizeoff+3 + k]<<24); | |||
|
97 | entry->CurrentSec = j; | |||
|
98 | entry->Currententry = (unsigned char)(k/32); | |||
|
99 | return DIRENT_noErr; | |||
|
100 | } | |||
|
101 | } | |||
|
102 | ||||
|
103 | } | |||
|
104 | j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k); | |||
|
105 | if(j!=DIRENT_noErr) | |||
|
106 | { | |||
|
107 | if(j==DIRENT_LastSect) return DIRENT_EndOfDir; /*Not clean but can avoid some bugs*/ | |||
|
108 | return j; | |||
|
109 | } | |||
|
110 | j=k; | |||
|
111 | k=0; | |||
|
112 | }while(res==DIRENT_noErr); | |||
|
113 | return res; | |||
|
114 | } | |||
|
115 | ||||
|
116 | ||||
|
117 | ||||
|
118 | unsigned int fat32getdirentlba(ucdirent* entry) | |||
|
119 | { | |||
|
120 | unsigned int culsterNum = (unsigned int)((unsigned short)entry->DIR_FstClustLO) + ((unsigned int)((unsigned short)entry->DIR_FstClusHI) <<16); | |||
|
121 | unsigned int lba=clusterlba(((FAT32fs*)entry->fs),culsterNum); | |||
|
122 | return lba; | |||
|
123 | } | |||
|
124 | ||||
|
125 | int fat32nextsectorlba(FAT32fs* fs,unsigned int lastsector_lba,unsigned int* nextsector_lba) | |||
|
126 | { | |||
|
127 | ||||
|
128 | if((lastsector_lba + 1 - fs->cluster_begin_lba & (fs->BPB_SecPerClus-1))!=0) /*Is it the last sector of the cluster?*/ | |||
|
129 | { | |||
|
130 | *nextsector_lba = lastsector_lba+1; | |||
|
131 | libucprintf("Next sector is %x\n\r",*nextsector_lba); | |||
|
132 | return DIRENT_noErr; | |||
|
133 | } | |||
|
134 | int clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ | |||
|
135 | int fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ | |||
|
136 | if((lastSecAddrs!=fatsec) || (lastFATFS!=fs)) /*Check if sector already buffered*/ | |||
|
137 | { | |||
|
138 | if(fs->part->phy->read(fs->part->phy,fat32buff,fatsec,1)!=RES_OK) | |||
|
139 | { | |||
|
140 | return DIRENT_ReadErr; | |||
|
141 | } | |||
|
142 | } | |||
|
143 | lastSecAddrs=fatsec; | |||
|
144 | lastFATFS=fs; | |||
|
145 | char i= fat32clusterinfatoff(clusternum); | |||
|
146 | *nextsector_lba = fat32buff[i] + (fat32buff[i+1]<<8) + (fat32buff[i+2]<<16) + (fat32buff[i+3]<<24); | |||
|
147 | if(*nextsector_lba>=0xFFFFFFF8)return DIRENT_LastSect; | |||
|
148 | if(*nextsector_lba==0xFFFFFFF7)return DIRENT_BadSect; | |||
|
149 | *nextsector_lba = clusterlba(fs,*nextsector_lba); | |||
|
150 | return DIRENT_noErr; | |||
|
151 | } | |||
|
152 | ||||
|
153 | ||||
|
154 | ||||
|
155 | ||||
|
156 | ||||
|
157 | ||||
|
158 | ||||
|
159 | ||||
|
160 | ||||
|
161 | ||||
|
162 | ||||
|
163 | ||||
|
164 | ||||
|
165 | ||||
|
166 | ||||
|
167 | ||||
|
168 | ||||
|
169 | ||||
|
170 | ||||
|
171 | ||||
|
172 | ||||
|
173 | ||||
|
174 | ||||
|
175 | ||||
|
176 |
@@ -0,0 +1,139 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef FAT32_H | |||
|
23 | #define FAT32_H | |||
|
24 | #include <mbr.h> | |||
|
25 | #include <fs.h> | |||
|
26 | #include <ucdirent.h> | |||
|
27 | /*BPB (Boot Sector) Offsets */ | |||
|
28 | ||||
|
29 | #define BS_jmpBootoff 0 | |||
|
30 | #define BS_OEMNameoff 3 | |||
|
31 | #define BPB_BytsPerSecoff 11 | |||
|
32 | #define BPB_SecPerClusoff 13 | |||
|
33 | #define BPB_RsvdSecCntoff 14 | |||
|
34 | #define BPB_NumFATsoff 16 | |||
|
35 | #define BPB_RootEntCntoff 17 | |||
|
36 | #define BPB_TotSec16off 19 | |||
|
37 | #define BPB_Mediaoff 21 | |||
|
38 | #define BPB_FATSz16off 22 | |||
|
39 | #define BPB_SecPerTrkoff 24 | |||
|
40 | #define BPB_NumHeadsoff 26 | |||
|
41 | #define BPB_HiddSecoff 28 | |||
|
42 | #define BPB_TotSec32off 32 | |||
|
43 | /*FAT16*/ | |||
|
44 | #define BS_DrvNumFAT16off 36 | |||
|
45 | #define BS_Reserved1FAT16off 37 | |||
|
46 | #define BS_BootSigFAT16off 38 | |||
|
47 | #define BS_VolIDFAT16off 39 | |||
|
48 | #define BS_VolLabFAT16off 43 | |||
|
49 | #define BS_FilSysTypeFAT16off 54 | |||
|
50 | /*FAT32*/ | |||
|
51 | #define BPB_FATSz32off 36 | |||
|
52 | #define BPB_ExtFlagsoff 40 | |||
|
53 | #define BPB_FSVeroff 42 | |||
|
54 | #define BPB_RootClusoff 44 | |||
|
55 | #define BPB_FSInfooff 48 | |||
|
56 | #define BPB_BkBootSecoff 50 | |||
|
57 | #define BPB_Reservedoff 52 | |||
|
58 | #define BS_DrvNumFAT32off 64 | |||
|
59 | #define BS_Reserved1FAT32off 65 | |||
|
60 | #define BS_BootSigFAT32off 66 | |||
|
61 | #define BS_VolIDFAT32off 67 | |||
|
62 | #define BS_VolLabFAT32off 71 | |||
|
63 | #define BS_FilSysTypeFAT32off 82 | |||
|
64 | ||||
|
65 | ||||
|
66 | #define DIR_Nameoff 0 | |||
|
67 | #define DIR_Attroff 0xb | |||
|
68 | #define DIR_FstClusHIoff 0x14 | |||
|
69 | #define DIR_FstClusLOoff 0x1A | |||
|
70 | #define DIR_FileSizeoff 0x1c | |||
|
71 | #define DIR_CrtTimeTenthoff 13 | |||
|
72 | #define DIR_CrtTimeoff 14 | |||
|
73 | #define DIR_CrtDateoff 16 | |||
|
74 | #define DIR_LstAccDateoff 18 | |||
|
75 | #define DIR_WrtTimeoff 22 | |||
|
76 | #define DIR_WrtDateoff 24 | |||
|
77 | ||||
|
78 | ||||
|
79 | ||||
|
80 | #define FATBadpart 1 | |||
|
81 | #define FATBabArg 2 | |||
|
82 | #define FATReadErr 3 | |||
|
83 | #define FATnoErr 0 | |||
|
84 | ||||
|
85 | struct FAT32part_str | |||
|
86 | { | |||
|
87 | unsigned short BPB_BytsPerSec; | |||
|
88 | unsigned short BPB_RsvdSecCnt; | |||
|
89 | unsigned int BPB_FATSz32; | |||
|
90 | unsigned int BPB_RootClus; | |||
|
91 | unsigned int fat_begin_lba; | |||
|
92 | unsigned int cluster_begin_lba; | |||
|
93 | unsigned char BPB_SecPerClus; | |||
|
94 | unsigned char BPB_NumFATs; | |||
|
95 | dikpartition* part; | |||
|
96 | }; | |||
|
97 | ||||
|
98 | typedef volatile struct FAT32part_str FAT32fs; | |||
|
99 | ||||
|
100 | #define clusterlba(fs,cluster_number) ((unsigned int)fs->cluster_begin_lba + (((unsigned int)cluster_number) - (2)) * (unsigned int)fs->BPB_SecPerClus) | |||
|
101 | #define fat32clusterinfatsect(fs,cluster_number) ((((unsigned int)(cluster_number))>>6) + fs->fat_begin_lba) | |||
|
102 | #define fat32clusterinfatoff(cluster_number) (((cluster_number)&0x3F)*4) | |||
|
103 | #define fat32sectorlbatoclusternum(fs,sectorlba) ((((((unsigned int)sectorlba & (-1^(fs->BPB_SecPerClus-1))))-((unsigned int)fs->cluster_begin_lba))/(unsigned int)fs->BPB_SecPerClus)+(2)) | |||
|
104 | ||||
|
105 | extern int fat32open(FAT32fs* fs,dikpartition* part); | |||
|
106 | extern int fat32mkdirent(FAT32fs* fs,ucdirent* dirent); | |||
|
107 | ||||
|
108 | extern int fat32getrootfirstent(ucdirent* entry); | |||
|
109 | extern int fat32nextdirent(ucdirent* entry); | |||
|
110 | extern int fat32nextsectorlba(FAT32fs* fs,unsigned int lastsector_lba,unsigned int* nextsector_lba); | |||
|
111 | extern unsigned int fat32getdirentlba(ucdirent* entry); | |||
|
112 | ||||
|
113 | ||||
|
114 | #endif | |||
|
115 | ||||
|
116 | ||||
|
117 | ||||
|
118 | ||||
|
119 | ||||
|
120 | ||||
|
121 | ||||
|
122 | ||||
|
123 | ||||
|
124 | ||||
|
125 | ||||
|
126 | ||||
|
127 | ||||
|
128 | ||||
|
129 | ||||
|
130 | ||||
|
131 | ||||
|
132 | ||||
|
133 | ||||
|
134 | ||||
|
135 | ||||
|
136 | ||||
|
137 | ||||
|
138 | ||||
|
139 |
@@ -0,0 +1,26 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | lpc17XX.ARCH = lpc17XX-arm-noabi-gcc | |||
|
3 | lpc17XX.TARGET = libfat32 | |||
|
4 | lpc17XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_FAT32) | |||
|
5 | lpc17XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FAT32) | |||
|
6 | ||||
|
7 | lpc17XX.LIBS += BLKDEVICE MBR UCSTRINGS UHANDLE FS UCDIRENT | |||
|
8 | ||||
|
9 | lpc17XX.SOURCES += fat32.c | |||
|
10 | ||||
|
11 | ||||
|
12 | lpc17XX.HEADERS += fat32.h | |||
|
13 | ||||
|
14 | ||||
|
15 | ||||
|
16 | lpc21XX.ARCH = lpc21XX-arm-noabi-gcc | |||
|
17 | lpc21XX.TARGET = libfat32 | |||
|
18 | lpc21XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_FAT32) | |||
|
19 | lpc21XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FAT32) | |||
|
20 | ||||
|
21 | lpc21XX.LIBS += BLKDEVICE MBR UCSTRINGS UHANDLE FS UCDIRENT | |||
|
22 | ||||
|
23 | lpc21XX.SOURCES += fat32.c | |||
|
24 | ||||
|
25 | ||||
|
26 | lpc21XX.HEADERS += fat32.h |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FAT32) | |||
|
5 | HEADERS += fat32.h | |||
|
6 | LIBSOURCES += fat32.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |||
|
13 | TARGET=libfat32 | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_MBR_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) $(LIBUC_INC_DIR_FS_CMD) $(LIBUC_INC_DIR_UCDIRENT_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_MBR_CMD) $(LIBUC_LIBS_MBR) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) $(LIBUC_LIBS_DIR_FS_CMD) $(LIBUC_LIBS_FS) $(LIBUC_LIBS_DIR_UCDIRENT_CMD) $(LIBUC_LIBS_UCDIRENT) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_FAT32) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_FAT32) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FAT32) | |||
|
5 | HEADERS += fat32.h | |||
|
6 | LIBSOURCES += fat32.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
13 | TARGET=libfat32 | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_MBR_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) $(LIBUC_INC_DIR_FS_CMD) $(LIBUC_INC_DIR_UCDIRENT_CMD) $(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_MBR_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) $(LIBUC_INC_DIR_FS_CMD) $(LIBUC_INC_DIR_UCDIRENT_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_MBR_CMD) $(LIBUC_LIBS_MBR) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) $(LIBUC_LIBS_DIR_FS_CMD) $(LIBUC_LIBS_FS) $(LIBUC_LIBS_DIR_UCDIRENT_CMD) $(LIBUC_LIBS_UCDIRENT) $(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_MBR_CMD) $(LIBUC_LIBS_MBR) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) $(LIBUC_LIBS_DIR_FS_CMD) $(LIBUC_LIBS_FS) $(LIBUC_LIBS_DIR_UCDIRENT_CMD) $(LIBUC_LIBS_UCDIRENT) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_FAT32) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_FAT32) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,7 | |||||
|
1 | TEMPLATE = dir | |||
|
2 | SUBDIRS += BLOCKDEVICES \ | |||
|
3 | SDCARD \ | |||
|
4 | MBR \ | |||
|
5 | FS \ | |||
|
6 | DIRENT \ | |||
|
7 | FAT32 |
@@ -0,0 +1,11 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | all: | |||
|
6 | make -f lpc17XX.mk | |||
|
7 | make -f lpc21XX.mk | |||
|
8 | ||||
|
9 | clean: | |||
|
10 | make clean -f lpc17XX.mk | |||
|
11 | make clean -f lpc21XX.mk |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 |
@@ -0,0 +1,78 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef FS_H | |||
|
23 | #define FS_H | |||
|
24 | #include <uhandle.h> | |||
|
25 | #include <blkdevice.h> | |||
|
26 | ||||
|
27 | struct fs_str | |||
|
28 | { | |||
|
29 | UHANDLE fat; | |||
|
30 | }; | |||
|
31 | ||||
|
32 | typedef struct fs_str filesys_t; | |||
|
33 | ||||
|
34 | ||||
|
35 | ||||
|
36 | #endif | |||
|
37 | ||||
|
38 | ||||
|
39 | ||||
|
40 | ||||
|
41 | ||||
|
42 | ||||
|
43 | ||||
|
44 | ||||
|
45 | ||||
|
46 | ||||
|
47 | ||||
|
48 | ||||
|
49 | ||||
|
50 | ||||
|
51 | ||||
|
52 | ||||
|
53 | ||||
|
54 | ||||
|
55 | ||||
|
56 | ||||
|
57 | ||||
|
58 | ||||
|
59 | ||||
|
60 | ||||
|
61 | ||||
|
62 | ||||
|
63 | ||||
|
64 | ||||
|
65 | ||||
|
66 | ||||
|
67 | ||||
|
68 | ||||
|
69 | ||||
|
70 | ||||
|
71 | ||||
|
72 | ||||
|
73 | ||||
|
74 | ||||
|
75 | ||||
|
76 | ||||
|
77 | ||||
|
78 |
@@ -0,0 +1,26 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | lpc17XX.ARCH = lpc17XX-arm-noabi-gcc | |||
|
3 | lpc17XX.TARGET = libfs | |||
|
4 | lpc17XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_FS) | |||
|
5 | lpc17XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FS) | |||
|
6 | ||||
|
7 | lpc17XX.LIBS += BLKDEVICE UHANDLE | |||
|
8 | ||||
|
9 | lpc17XX.SOURCES += fs.c | |||
|
10 | ||||
|
11 | ||||
|
12 | lpc17XX.HEADERS += fs.h | |||
|
13 | ||||
|
14 | ||||
|
15 | ||||
|
16 | lpc21XX.ARCH = lpc21XX-arm-noabi-gcc | |||
|
17 | lpc21XX.TARGET = libfs | |||
|
18 | lpc21XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_FS) | |||
|
19 | lpc21XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FS) | |||
|
20 | ||||
|
21 | lpc21XX.LIBS += BLKDEVICE UHANDLE | |||
|
22 | ||||
|
23 | lpc21XX.SOURCES += fs.c | |||
|
24 | ||||
|
25 | ||||
|
26 | lpc21XX.HEADERS += fs.h |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FS) | |||
|
5 | HEADERS += fs.h | |||
|
6 | LIBSOURCES += fs.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |||
|
13 | TARGET=libfs | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_FS) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_FS) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FS) | |||
|
5 | HEADERS += fs.h | |||
|
6 | LIBSOURCES += fs.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
13 | TARGET=libfs | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) $(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) $(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_FS) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_FS) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,26 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | lpc17XX.ARCH = lpc17XX-arm-noabi-gcc | |||
|
3 | lpc17XX.TARGET = libmbr | |||
|
4 | lpc17XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_MBR) | |||
|
5 | lpc17XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_MBR) | |||
|
6 | ||||
|
7 | lpc17XX.LIBS += BLKDEVICE UCSTRINGS UHANDLE | |||
|
8 | ||||
|
9 | lpc17XX.SOURCES += mbr.c | |||
|
10 | ||||
|
11 | ||||
|
12 | lpc17XX.HEADERS += mbr.h | |||
|
13 | ||||
|
14 | ||||
|
15 | ||||
|
16 | lpc21XX.ARCH = lpc21XX-arm-noabi-gcc | |||
|
17 | lpc21XX.TARGET = libmbr | |||
|
18 | lpc21XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_MBR) | |||
|
19 | lpc21XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_MBR) | |||
|
20 | ||||
|
21 | lpc21XX.LIBS += BLKDEVICE UCSTRINGS UHANDLE | |||
|
22 | ||||
|
23 | lpc21XX.SOURCES += mbr.c | |||
|
24 | ||||
|
25 | ||||
|
26 | lpc21XX.HEADERS += mbr.h |
@@ -0,0 +1,11 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | all: | |||
|
6 | make -f lpc17XX.mk | |||
|
7 | make -f lpc21XX.mk | |||
|
8 | ||||
|
9 | clean: | |||
|
10 | make clean -f lpc17XX.mk | |||
|
11 | make clean -f lpc21XX.mk |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_MBR) | |||
|
5 | HEADERS += mbr.h | |||
|
6 | LIBSOURCES += mbr.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |||
|
13 | TARGET=libmbr | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_MBR) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_MBR) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_MBR) | |||
|
5 | HEADERS += mbr.h | |||
|
6 | LIBSOURCES += mbr.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
13 | TARGET=libmbr | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) $(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) $(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_MBR) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_MBR) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,70 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #include "mbr.h" | |||
|
23 | ||||
|
24 | ||||
|
25 | int mbropen(blkdevice* phy,dikpartition* part,char partNum) | |||
|
26 | { | |||
|
27 | char mbr[512]; | |||
|
28 | if((part==0) || (phy ==0) || (partNum>4) || (partNum==0) ) return MBRBabArg; | |||
|
29 | part->phy = phy; | |||
|
30 | if(phy->read(phy,mbr,0,1)!=RES_OK)return MBRReadErr; | |||
|
31 | if((mbr[510] != 0x55) || (mbr[511] != 0xAA)) return MBRBadMbr; | |||
|
32 | part->TypeCode = mbr[(512-82+TypeCodeoffset)+partNum*16]; | |||
|
33 | part->LBABegin = (unsigned int)mbr[(512-82+LBABeginoffset)+partNum*16] + ((unsigned int)mbr[(512-82+LBABeginoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+LBABeginoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+LBABeginoffset+3)+partNum*16]<<24); | |||
|
34 | part->NumOfSec = (unsigned int)mbr[(512-82+NumOfSecoffset)+partNum*16] + ((unsigned int)mbr[(512-82+NumOfSecoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+3)+partNum*16]<<24); | |||
|
35 | return MBRnoErr; | |||
|
36 | } | |||
|
37 | ||||
|
38 | ||||
|
39 | ||||
|
40 | ||||
|
41 | ||||
|
42 | ||||
|
43 | ||||
|
44 | ||||
|
45 | ||||
|
46 | ||||
|
47 | ||||
|
48 | ||||
|
49 | ||||
|
50 | ||||
|
51 | ||||
|
52 | ||||
|
53 | ||||
|
54 | ||||
|
55 | ||||
|
56 | ||||
|
57 | ||||
|
58 | ||||
|
59 | ||||
|
60 | ||||
|
61 | ||||
|
62 | ||||
|
63 | ||||
|
64 | ||||
|
65 | ||||
|
66 | ||||
|
67 | ||||
|
68 | ||||
|
69 | ||||
|
70 |
@@ -0,0 +1,73 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef MBR_H | |||
|
23 | #define MBR_H | |||
|
24 | #include <uhandle.h> | |||
|
25 | #include <blkdevice.h> | |||
|
26 | ||||
|
27 | #define BootFlagoffset 0 | |||
|
28 | #define TypeCodeoffset 4 | |||
|
29 | #define LBABeginoffset 8 | |||
|
30 | #define NumOfSecoffset 12 | |||
|
31 | ||||
|
32 | #define MBRBadMbr 1 | |||
|
33 | #define MBRBabArg 2 | |||
|
34 | #define MBRReadErr 3 | |||
|
35 | #define MBRnoErr 0 | |||
|
36 | ||||
|
37 | #define isFat32(TypeCode) (((TypeCode)==0x0b)||((TypeCode)==0x0c)) | |||
|
38 | ||||
|
39 | struct MBRpartition | |||
|
40 | { | |||
|
41 | char TypeCode; | |||
|
42 | unsigned int LBABegin; | |||
|
43 | unsigned int NumOfSec; | |||
|
44 | blkdevice* phy; | |||
|
45 | }; | |||
|
46 | ||||
|
47 | typedef struct MBRpartition dikpartition; | |||
|
48 | ||||
|
49 | ||||
|
50 | int mbropen(blkdevice* phy,dikpartition* part,char partNum); | |||
|
51 | ||||
|
52 | ||||
|
53 | #endif | |||
|
54 | ||||
|
55 | ||||
|
56 | ||||
|
57 | ||||
|
58 | ||||
|
59 | ||||
|
60 | ||||
|
61 | ||||
|
62 | ||||
|
63 | ||||
|
64 | ||||
|
65 | ||||
|
66 | ||||
|
67 | ||||
|
68 | ||||
|
69 | ||||
|
70 | ||||
|
71 | ||||
|
72 | ||||
|
73 |
@@ -0,0 +1,23 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | include $(LIBUC)/rules/common/rules.mk | |||
|
5 | ||||
|
6 | all:subdir | |||
|
7 | make -C BLOCKDEVICES | |||
|
8 | make -C SDCARD | |||
|
9 | make -C MBR | |||
|
10 | make -C FS | |||
|
11 | make -C DIRENT | |||
|
12 | make -C FAT32 | |||
|
13 | @echo Code compiled | |||
|
14 | ||||
|
15 | clean: | |||
|
16 | make clean -C BLOCKDEVICES | |||
|
17 | make clean -C SDCARD | |||
|
18 | make clean -C MBR | |||
|
19 | make clean -C FS | |||
|
20 | make clean -C DIRENT | |||
|
21 | make clean -C FAT32 | |||
|
22 | @echo Code compiled | |||
|
23 |
@@ -0,0 +1,11 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | all: | |||
|
6 | make -f lpc17XX.mk | |||
|
7 | make -f lpc21XX.mk | |||
|
8 | ||||
|
9 | clean: | |||
|
10 | make clean -f lpc17XX.mk | |||
|
11 | make clean -f lpc21XX.mk |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_SDCARD) | |||
|
5 | HEADERS += sdcard.h | |||
|
6 | LIBSOURCES += sdcard.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |||
|
13 | TARGET=libsdcard | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_SDCARD) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_SDCARD) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_SDCARD) | |||
|
5 | HEADERS += sdcard.h | |||
|
6 | LIBSOURCES += sdcard.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
13 | TARGET=libsdcard | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_BLKDEVICE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) $(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_BLKDEVICE_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) $(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_BLKDEVICE_CMD) $(LIBUC_LIBS_BLKDEVICE) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_SDCARD) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_SDCARD) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,482 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #include "sdcard.h" | |||
|
23 | static volatile | |||
|
24 | unsigned int Timer1, Timer2; /* 1kHz decrement timer stopped at zero (disk_timerproc()) */ | |||
|
25 | ||||
|
26 | void sdcarddeselect (blkdevice* _this) | |||
|
27 | { | |||
|
28 | char d; | |||
|
29 | _this->select(0); | |||
|
30 | ((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,&d, 1); /* Dummy clock (force DO hi-z for multiple slave SPI) */ | |||
|
31 | } | |||
|
32 | ||||
|
33 | int sdcardselect (blkdevice* _this) /* 1:OK, 0:Timeout */ | |||
|
34 | { | |||
|
35 | char d; | |||
|
36 | _this->select(1); | |||
|
37 | ((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,&d, 1); /* Dummy clock (force DO enabled) */ | |||
|
38 | ||||
|
39 | if (sdcardwait_ready(((sdcardDev*)_this->phy))) return 1; /* OK */ | |||
|
40 | _this->select(0); | |||
|
41 | return 0; /* Timeout */ | |||
|
42 | } | |||
|
43 | ||||
|
44 | int sdcardwait_ready (sdcardDev* sdcard) /* 1:OK, 0:Timeout */ | |||
|
45 | { | |||
|
46 | char d; | |||
|
47 | unsigned int tmr; | |||
|
48 | volatile unsigned int i=0; | |||
|
49 | ||||
|
50 | for (tmr = 100000; tmr; tmr--) { /* Wait for ready in timeout of 500ms */ | |||
|
51 | sdcard->rcvr_mmc(sdcard->phy,&d, 1); | |||
|
52 | if (d == 0xFF) break; | |||
|
53 | for(i=0;i<128;i++); | |||
|
54 | } | |||
|
55 | ||||
|
56 | return tmr ? 1 : 0; | |||
|
57 | } | |||
|
58 | ||||
|
59 | int sdcardrcvr_datablock (sdcardDev* sdcard,char *buff,unsigned int btr) | |||
|
60 | { | |||
|
61 | char d[2]; | |||
|
62 | unsigned int tmr; | |||
|
63 | volatile unsigned int i=0; | |||
|
64 | for (tmr = 50000; tmr; tmr--) { /* Wait for data packet in timeout of 100ms */ | |||
|
65 | sdcard->rcvr_mmc(sdcard->phy,d, 1); | |||
|
66 | if (d[0] != 0xFF) break; | |||
|
67 | for(i=0;i<64;i++); | |||
|
68 | } | |||
|
69 | if (d[0] != 0xFE) return 0; /* If not valid data token, return with error */ | |||
|
70 | ||||
|
71 | sdcard->rcvr_mmc(sdcard->phy,buff, btr); /* Receive the data block into buffer */ | |||
|
72 | sdcard->rcvr_mmc(sdcard->phy,d, 2); /* Discard CRC */ | |||
|
73 | ||||
|
74 | return 1; /* Return with success */ | |||
|
75 | } | |||
|
76 | ||||
|
77 | ||||
|
78 | int sdcardxmit_datablock (sdcardDev* sdcard,const char *buff,char token) | |||
|
79 | { | |||
|
80 | char d[2]; | |||
|
81 | ||||
|
82 | ||||
|
83 | if (!sdcardwait_ready(sdcard)) return 0; | |||
|
84 | ||||
|
85 | d[0] = token; | |||
|
86 | sdcard->xmit_mmc(sdcard->phy,d, 1); /* Xmit a token */ | |||
|
87 | if (token != 0xFD) { /* Is it data token? */ | |||
|
88 | sdcard->xmit_mmc(sdcard->phy,buff, 512); /* Xmit the 512 byte data block to MMC */ | |||
|
89 | sdcard->rcvr_mmc(sdcard->phy,d, 2); /* Xmit dummy CRC (0xFF,0xFF) */ | |||
|
90 | sdcard->rcvr_mmc(sdcard->phy,d, 1); /* Receive data response */ | |||
|
91 | if ((d[0] & 0x1F) != 0x05) /* If not accepted, return with error */ | |||
|
92 | return 0; | |||
|
93 | } | |||
|
94 | ||||
|
95 | return 1; | |||
|
96 | } | |||
|
97 | ||||
|
98 | ||||
|
99 | char sdcardsend_cmd (blkdevice* _this,char cmd,unsigned int arg) | |||
|
100 | { | |||
|
101 | char n, d, buf[6]; | |||
|
102 | ||||
|
103 | ||||
|
104 | if (cmd & 0x80) { /* ACMD<n> is the command sequense of CMD55-CMD<n> */ | |||
|
105 | cmd &= 0x7F; | |||
|
106 | n = sdcardsend_cmd(_this,CMD55, 0); | |||
|
107 | if (n > 1) return n; | |||
|
108 | } | |||
|
109 | /* Select the card and wait for ready */ | |||
|
110 | sdcarddeselect(_this); | |||
|
111 | if (!sdcardselect(_this)) return 0xFF; | |||
|
112 | /* Send a command packet */ | |||
|
113 | buf[0] = 0x40 | cmd; /* Start + Command index */ | |||
|
114 | buf[1] = (char)(arg >> 24); /* Argument[31..24] */ | |||
|
115 | buf[2] = (char)(arg >> 16); /* Argument[23..16] */ | |||
|
116 | buf[3] = (char)(arg >> 8); /* Argument[15..8] */ | |||
|
117 | buf[4] = (char)arg; /* Argument[7..0] */ | |||
|
118 | n = 0x01; /* Dummy CRC + Stop */ | |||
|
119 | if (cmd == CMD0) n = 0x95; /* (valid CRC for CMD0(0)) */ | |||
|
120 | if (cmd == CMD8) n = 0x87; /* (valid CRC for CMD8(0x1AA)) */ | |||
|
121 | if (cmd == CMD55) n = 0x63; | |||
|
122 | buf[5] = n; | |||
|
123 | ((sdcardDev*)_this->phy)->xmit_mmc(((sdcardDev*)_this->phy)->phy,buf, 6); | |||
|
124 | /* Receive command response */ | |||
|
125 | if (cmd == CMD12) {((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,&d, 1);} /* Skip a stuff byte when stop reading */ | |||
|
126 | n = 10; /* Wait for a valid response in timeout of 10 attempts */ | |||
|
127 | do | |||
|
128 | { | |||
|
129 | ((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,&d, 1); | |||
|
130 | //libucprintf("resp=%d\n\r",d); | |||
|
131 | } | |||
|
132 | while ((d & 0x80) && --n); | |||
|
133 | ||||
|
134 | return d; /* Return with the response value */ | |||
|
135 | } | |||
|
136 | ||||
|
137 | ||||
|
138 | ||||
|
139 | ||||
|
140 | DSTATUS sdcarddisk_status (blkdevice* _this) | |||
|
141 | { | |||
|
142 | DSTATUS s = ((sdcardDev*)_this->phy)->Stat; | |||
|
143 | char ocr[4]; | |||
|
144 | ||||
|
145 | ||||
|
146 | if ((_this==0) || !_this->detect()) { | |||
|
147 | s = STA_NODISK | STA_NOINIT; | |||
|
148 | } else { | |||
|
149 | s &= ~STA_NODISK; | |||
|
150 | if (_this->writeprotected()) /* Check card write protection */ | |||
|
151 | s |= STA_PROTECT; | |||
|
152 | else | |||
|
153 | s &= ~STA_PROTECT; | |||
|
154 | if (!(s & STA_NOINIT)) { | |||
|
155 | if (sdcardsend_cmd(_this,CMD58, 0)) /* Check if the card is kept initialized */ | |||
|
156 | s |= STA_NOINIT; | |||
|
157 | ((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,ocr, 4); | |||
|
158 | _this->select(0); | |||
|
159 | } | |||
|
160 | } | |||
|
161 | ((sdcardDev*)_this->phy)->Stat = s; | |||
|
162 | ||||
|
163 | return s; | |||
|
164 | } | |||
|
165 | ||||
|
166 | ||||
|
167 | ||||
|
168 | ||||
|
169 | DSTATUS sdcarddisk_initialize (blkdevice* _this) | |||
|
170 | { | |||
|
171 | char n, cmd, ty, ocr[4],ocr2[4]; | |||
|
172 | const unsigned char dummy=0xff; | |||
|
173 | unsigned int speed = 1000000; | |||
|
174 | ||||
|
175 | ((sdcardDev*)_this->phy)->setspeed(((sdcardDev*)_this->phy)->phy,350000); | |||
|
176 | if (_this==0) return STA_NOINIT; /* Supports only drive 0 */ | |||
|
177 | if (((sdcardDev*)_this->phy)->Stat & STA_NODISK) return ((sdcardDev*)_this->phy)->Stat; /* Is card existing in the soket? */ | |||
|
178 | ||||
|
179 | for (n = 10; n; n--) ((sdcardDev*)_this->phy)->xmit_mmc(((sdcardDev*)_this->phy)->phy,&dummy, 1); /* Send 80 dummy clocks */ | |||
|
180 | ||||
|
181 | ty = 0; | |||
|
182 | if (sdcardsend_cmd(_this,CMD0, 0) == 1) { /* Put the card SPI/Idle state */ | |||
|
183 | Timer1 = 1000; /* Initialization timeout = 1 sec */ | |||
|
184 | if (sdcardsend_cmd(_this,CMD8, 0x1AA) == 1) { /* SDv2? */ | |||
|
185 | ((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,ocr, 4); | |||
|
186 | //for (n = 0; n < 4; n++) ocr[n] = xchg_spi(0xFF); /* Get 32 bit return value of R7 resp */ | |||
|
187 | if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* Is the card supports vcc of 2.7-3.6V? */ | |||
|
188 | while (Timer1 && sdcardsend_cmd(_this,ACMD41, 1UL << 30)) ; /* Wait for end of initialization with ACMD41(HCS) */ | |||
|
189 | if (Timer1 && sdcardsend_cmd(_this,CMD58, 0) == 0) { /* Check CCS bit in the OCR */ | |||
|
190 | //for (n = 0; n < 4; n++) ocr[n] = xchg_spi(0xFF); | |||
|
191 | ((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,ocr, 4); | |||
|
192 | ty = (ocr[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2; /* Card id SDv2 */ | |||
|
193 | } | |||
|
194 | } | |||
|
195 | } else { /* Not SDv2 card */ | |||
|
196 | if (sdcardsend_cmd(_this,ACMD41, 0) <= 1) { /* SDv1 or MMC? */ | |||
|
197 | ty = CT_SD1; cmd = ACMD41; /* SDv1 (ACMD41(0)) */ | |||
|
198 | } else { | |||
|
199 | ty = CT_MMC; cmd = CMD1; /* MMCv3 (CMD1(0)) */ | |||
|
200 | } | |||
|
201 | while (Timer1 && sdcardsend_cmd(_this,cmd, 0)) ; /* Wait for end of initialization */ | |||
|
202 | if (!Timer1 || sdcardsend_cmd(_this,CMD16, 512) != 0) /* Set block length: 512 */ | |||
|
203 | ty = 0; | |||
|
204 | } | |||
|
205 | } | |||
|
206 | ((sdcardDev*)_this->phy)->CardType = ty; /* Card type */ | |||
|
207 | ||||
|
208 | if (ty) { /* OK */ | |||
|
209 | ((sdcardDev*)_this->phy)->Stat &= ~STA_NOINIT; /* Clear STA_NOINIT flag */ | |||
|
210 | sdcardsend_cmd(_this,CMD58, 0); | |||
|
211 | ((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,ocr, 4); | |||
|
212 | do | |||
|
213 | { | |||
|
214 | speed+=1000000; | |||
|
215 | ((sdcardDev*)_this->phy)->setspeed(((sdcardDev*)_this->phy)->phy,speed); | |||
|
216 | sdcardsend_cmd(_this,CMD58, 0); | |||
|
217 | ((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,ocr2, 4); | |||
|
218 | for(n=0;n<4;n++) | |||
|
219 | { | |||
|
220 | if(ocr[n]!=ocr2[n]) | |||
|
221 | { | |||
|
222 | n=0; | |||
|
223 | break; | |||
|
224 | } | |||
|
225 | } | |||
|
226 | if(speed>(50*1000*1000)) | |||
|
227 | { | |||
|
228 | break; | |||
|
229 | } | |||
|
230 | }while(n); | |||
|
231 | if(!n) | |||
|
232 | { | |||
|
233 | speed-=1000000; | |||
|
234 | ((sdcardDev*)_this->phy)->setspeed(((sdcardDev*)_this->phy)->phy,speed); | |||
|
235 | } | |||
|
236 | ||||
|
237 | } else { /* Failed */ | |||
|
238 | //power_off(); | |||
|
239 | ((sdcardDev*)_this->phy)->Stat = STA_NOINIT; | |||
|
240 | } | |||
|
241 | sdcarddeselect (_this); | |||
|
242 | return ((sdcardDev*)_this->phy)->Stat; | |||
|
243 | } | |||
|
244 | ||||
|
245 | ||||
|
246 | ||||
|
247 | ||||
|
248 | ||||
|
249 | ||||
|
250 | ||||
|
251 | ||||
|
252 | ||||
|
253 | ||||
|
254 | DRESULT sdcarddisk_read (blkdevice* _this,char *buff,unsigned int sector,char count) | |||
|
255 | { | |||
|
256 | DSTATUS s; | |||
|
257 | ||||
|
258 | ||||
|
259 | s = sdcarddisk_status(_this); | |||
|
260 | if (s & STA_NOINIT) return RES_NOTRDY; | |||
|
261 | if (!count) return RES_PARERR; | |||
|
262 | if (!(((sdcardDev*)_this->phy)->CardType & CT_BLOCK)) sector *= 512; /* Convert LBA to byte address if needed */ | |||
|
263 | ||||
|
264 | if (count == 1) { /* Single block read */ | |||
|
265 | if ((sdcardsend_cmd(_this,CMD17, sector) == 0) && sdcardrcvr_datablock((sdcardDev*)(_this->phy),buff, 512)) | |||
|
266 | count = 0; | |||
|
267 | } | |||
|
268 | else { /* Multiple block read */ | |||
|
269 | if (sdcardsend_cmd(_this,CMD18, sector) == 0) { /* READ_MULTIPLE_BLOCK */ | |||
|
270 | do { | |||
|
271 | if (!sdcardrcvr_datablock (((sdcardDev*)_this->phy),buff, 512)) break; | |||
|
272 | buff += 512; | |||
|
273 | } while (--count); | |||
|
274 | sdcardsend_cmd(_this,CMD12, 0); /* STOP_TRANSMISSION */ | |||
|
275 | } | |||
|
276 | } | |||
|
277 | sdcarddeselect (_this); | |||
|
278 | ||||
|
279 | return count ? RES_ERROR : RES_OK; | |||
|
280 | } | |||
|
281 | ||||
|
282 | ||||
|
283 | ||||
|
284 | ||||
|
285 | ||||
|
286 | DRESULT sdcarddisk_write (blkdevice* _this,const char *buff,unsigned int sector,char count) | |||
|
287 | { | |||
|
288 | DSTATUS s; | |||
|
289 | ||||
|
290 | ||||
|
291 | s = sdcarddisk_status(_this); | |||
|
292 | if (s & STA_NOINIT) return RES_NOTRDY; | |||
|
293 | if (s & STA_PROTECT) return RES_WRPRT; | |||
|
294 | if (!count) return RES_PARERR; | |||
|
295 | if (!(((sdcardDev*)_this->phy)->CardType & CT_BLOCK)) sector *= 512; /* Convert LBA to byte address if needed */ | |||
|
296 | ||||
|
297 | if (count == 1) { /* Single block write */ | |||
|
298 | if ((sdcardsend_cmd(_this,CMD24, sector) == 0) /* WRITE_BLOCK */ | |||
|
299 | && sdcardxmit_datablock (((sdcardDev*)_this->phy),buff, 0xFE)) | |||
|
300 | count = 0; | |||
|
301 | } | |||
|
302 | else { /* Multiple block write */ | |||
|
303 | if (((sdcardDev*)_this->phy)->CardType & CT_SDC) sdcardsend_cmd(_this,ACMD23, count); | |||
|
304 | if (sdcardsend_cmd(_this,CMD25, sector) == 0) { /* WRITE_MULTIPLE_BLOCK */ | |||
|
305 | do { | |||
|
306 | if (!sdcardxmit_datablock (((sdcardDev*)_this->phy),buff, 0xFC)) break; | |||
|
307 | buff += 512; | |||
|
308 | } while (--count); | |||
|
309 | if (!sdcardxmit_datablock (((sdcardDev*)_this->phy),0, 0xFD)) /* STOP_TRAN token */ | |||
|
310 | count = 1; | |||
|
311 | } | |||
|
312 | } | |||
|
313 | sdcarddeselect (_this); | |||
|
314 | ||||
|
315 | return count ? RES_ERROR : RES_OK; | |||
|
316 | } | |||
|
317 | ||||
|
318 | ||||
|
319 | DRESULT sdcarddisk_ioctl (blkdevice* _this,char ctrl,void *buff) | |||
|
320 | { | |||
|
321 | DRESULT res; | |||
|
322 | const unsigned char dummy=0xff; | |||
|
323 | char n, csd[16], *ptr = buff; | |||
|
324 | unsigned short csize; | |||
|
325 | unsigned long *dp, st, ed; | |||
|
326 | ||||
|
327 | ||||
|
328 | if (_this==0) return RES_PARERR; /* Check parameter */ | |||
|
329 | if (((sdcardDev*)_this->phy)->Stat & STA_NOINIT) return RES_NOTRDY; /* Check if drive is ready */ | |||
|
330 | ||||
|
331 | res = RES_ERROR; | |||
|
332 | ||||
|
333 | switch (ctrl) { | |||
|
334 | case CTRL_SYNC : /* Wait for end of internal write process of the drive */ | |||
|
335 | if (sdcardselect (_this)) { | |||
|
336 | sdcarddeselect (_this); | |||
|
337 | res = RES_OK; | |||
|
338 | } | |||
|
339 | break; | |||
|
340 | ||||
|
341 | case GET_SECTOR_COUNT : /* Get drive capacity in unit of sector (DWORD) */ | |||
|
342 | if ((sdcardsend_cmd(_this,CMD9, 0) == 0) && sdcardrcvr_datablock (((sdcardDev*)_this->phy),csd, 16)) { | |||
|
343 | if ((csd[0] >> 6) == 1) { /* SDC ver 2.00 */ | |||
|
344 | csize = csd[9] + ((unsigned short)csd[8] << 8) + 1; | |||
|
345 | *(unsigned long*)buff = (unsigned long)csize << 10; | |||
|
346 | } else { /* SDC ver 1.XX or MMC ver 3 */ | |||
|
347 | n = (csd[5] & 15) + ((csd[10] & 128) >> 7) + ((csd[9] & 3) << 1) + 2; | |||
|
348 | csize = (csd[8] >> 6) + ((unsigned short)csd[7] << 2) + ((unsigned short)(csd[6] & 3) << 10) + 1; | |||
|
349 | *(unsigned long*)buff = (unsigned long)csize << (n - 9); | |||
|
350 | } | |||
|
351 | res = RES_OK; | |||
|
352 | } | |||
|
353 | break; | |||
|
354 | ||||
|
355 | case GET_SECTOR_SIZE : /* Get sector size in unit of byte (WORD) */ | |||
|
356 | *(unsigned short*)buff = 512; | |||
|
357 | res = RES_OK; | |||
|
358 | break; | |||
|
359 | ||||
|
360 | case GET_BLOCK_SIZE : /* Get erase block size in unit of sector (DWORD) */ | |||
|
361 | if (((sdcardDev*)_this->phy)->CardType & CT_SD2) { /* SDC ver 2.00 */ | |||
|
362 | if (sdcardsend_cmd(_this,ACMD13, 0) == 0) { /* Read SD status */ | |||
|
363 | ((sdcardDev*)_this->phy)->xmit_mmc(((sdcardDev*)_this->phy)->phy,&dummy, 1); | |||
|
364 | if (sdcardrcvr_datablock (((sdcardDev*)_this->phy),csd, 16)) { /* Read partial block */ | |||
|
365 | for (n = 64 - 16; n; n--) ((sdcardDev*)_this->phy)->xmit_mmc(((sdcardDev*)_this->phy)->phy,&dummy, 1); /* Purge trailing data */ | |||
|
366 | *(unsigned long*)buff = 16UL << (csd[10] >> 4); | |||
|
367 | res = RES_OK; | |||
|
368 | ((sdcardDev*)_this->phy)->xmit_mmc(((sdcardDev*)_this->phy)->phy,&dummy, 1); | |||
|
369 | } | |||
|
370 | } | |||
|
371 | } else { /* SDC ver 1.XX or MMC */ | |||
|
372 | if ((sdcardsend_cmd(_this,CMD9, 0) == 0) && sdcardrcvr_datablock (((sdcardDev*)_this->phy),csd, 16)) { /* Read CSD */ | |||
|
373 | if (((sdcardDev*)_this->phy)->CardType & CT_SD1) { /* SDC ver 1.XX */ | |||
|
374 | *(unsigned long*)buff = (((csd[10] & 63) << 1) + ((unsigned short)(csd[11] & 128) >> 7) + 1) << ((csd[13] >> 6) - 1); | |||
|
375 | } else { /* MMC */ | |||
|
376 | *(unsigned long*)buff = ((unsigned short)((csd[10] & 124) >> 2) + 1) * (((csd[11] & 3) << 3) + ((csd[11] & 224) >> 5) + 1); | |||
|
377 | } | |||
|
378 | res = RES_OK; | |||
|
379 | } | |||
|
380 | } | |||
|
381 | break; | |||
|
382 | ||||
|
383 | case CTRL_ERASE_SECTOR : /* Erase a block of sectors (used when _USE_ERASE == 1) */ | |||
|
384 | if (!(((sdcardDev*)_this->phy)->CardType & CT_SDC)) break; /* Check if the card is SDC */ | |||
|
385 | if (sdcarddisk_ioctl(_this, MMC_GET_CSD, csd)) break; /* Get CSD */ | |||
|
386 | if (!(csd[0] >> 6) && !(csd[10] & 0x40)) break; /* Check if sector erase can be applied to the card */ | |||
|
387 | dp = buff; st = dp[0]; ed = dp[1]; /* Load sector block */ | |||
|
388 | if (!(((sdcardDev*)_this->phy)->CardType & CT_BLOCK)) { | |||
|
389 | st *= 512; ed *= 512; | |||
|
390 | } | |||
|
391 | if (sdcardsend_cmd(_this,CMD32, st) == 0 && sdcardsend_cmd(_this,CMD33, ed) == 0 && sdcardsend_cmd(_this,CMD38, 0) == 0 && sdcardwait_ready(((sdcardDev*)_this->phy))) /* Erase sector block */ | |||
|
392 | res = RES_OK; /* FatFs does not check result of this command */ | |||
|
393 | break; | |||
|
394 | ||||
|
395 | /* Following command are not used by FatFs module */ | |||
|
396 | ||||
|
397 | case MMC_GET_TYPE : /* Get MMC/SDC type (BYTE) */ | |||
|
398 | *ptr = ((sdcardDev*)_this->phy)->CardType; | |||
|
399 | res = RES_OK; | |||
|
400 | break; | |||
|
401 | ||||
|
402 | case MMC_GET_CSD : /* Read CSD (16 bytes) */ | |||
|
403 | if (sdcardsend_cmd(_this,CMD9, 0) == 0 /* READ_CSD */ | |||
|
404 | && sdcardrcvr_datablock (((sdcardDev*)_this->phy),ptr, 16)) | |||
|
405 | res = RES_OK; | |||
|
406 | break; | |||
|
407 | ||||
|
408 | case MMC_GET_CID : /* Read CID (16 bytes) */ | |||
|
409 | if (sdcardsend_cmd(_this,CMD10, 0) == 0 /* READ_CID */ | |||
|
410 | && sdcardrcvr_datablock (((sdcardDev*)_this->phy),ptr, 16)) | |||
|
411 | res = RES_OK; | |||
|
412 | break; | |||
|
413 | ||||
|
414 | case MMC_GET_OCR : /* Read OCR (4 bytes) */ | |||
|
415 | if (sdcardsend_cmd(_this,CMD58, 0) == 0) { /* READ_OCR */ | |||
|
416 | //for (n = 4; n; n--) *ptr++ = | |||
|
417 | ((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,ptr, 4); | |||
|
418 | res = RES_OK; | |||
|
419 | } | |||
|
420 | break; | |||
|
421 | ||||
|
422 | case MMC_GET_SDSTAT : /* Read SD status (64 bytes) */ | |||
|
423 | if (sdcardsend_cmd(_this,ACMD13, 0) == 0) { /* SD_STATUS */ | |||
|
424 | ((sdcardDev*)_this->phy)->xmit_mmc(((sdcardDev*)_this->phy)->phy,&dummy, 1); | |||
|
425 | if (sdcardrcvr_datablock (((sdcardDev*)_this->phy),ptr, 64)) | |||
|
426 | res = RES_OK; | |||
|
427 | } | |||
|
428 | break; | |||
|
429 | ||||
|
430 | default: | |||
|
431 | res = RES_PARERR; | |||
|
432 | } | |||
|
433 | ||||
|
434 | sdcarddeselect (_this); | |||
|
435 | ||||
|
436 | return res; | |||
|
437 | } | |||
|
438 | ||||
|
439 | ||||
|
440 | ||||
|
441 | void sdcardmake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,unsigned int ),void (*xmit_mmc) (UHANDLE,const char *,unsigned int ),void (*setspeed) (UHANDLE phy,unsigned int speed),unsigned int (*getspeed) (UHANDLE phy)) | |||
|
442 | { | |||
|
443 | sdcard->phy = phy; | |||
|
444 | sdcard->rcvr_mmc = rcvr_mmc; | |||
|
445 | sdcard->xmit_mmc = xmit_mmc; | |||
|
446 | sdcard->setspeed = setspeed; | |||
|
447 | sdcard->getspeed = getspeed; | |||
|
448 | } | |||
|
449 | ||||
|
450 | void sdcardmakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected) | |||
|
451 | { | |||
|
452 | dev->phy=sdcard; | |||
|
453 | dev->select=select; | |||
|
454 | dev->power = power; | |||
|
455 | dev->detect = detect; | |||
|
456 | dev->writeprotected = writeprotected; | |||
|
457 | dev->write = sdcarddisk_write; | |||
|
458 | dev->read = sdcarddisk_read; | |||
|
459 | dev->ioctl = sdcarddisk_ioctl; | |||
|
460 | dev->initialize = sdcarddisk_initialize; | |||
|
461 | dev->status = sdcarddisk_status; | |||
|
462 | ||||
|
463 | } | |||
|
464 | ||||
|
465 | ||||
|
466 | ||||
|
467 | ||||
|
468 | ||||
|
469 | ||||
|
470 | ||||
|
471 | ||||
|
472 | ||||
|
473 | ||||
|
474 | ||||
|
475 | ||||
|
476 | ||||
|
477 | ||||
|
478 | ||||
|
479 | ||||
|
480 | ||||
|
481 | ||||
|
482 |
@@ -0,0 +1,118 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef SDCARD_H | |||
|
23 | #define SDCARD_H | |||
|
24 | #include "blkdevice.h" | |||
|
25 | #include <libucstrings.h> | |||
|
26 | #include <uhandle.h> | |||
|
27 | ||||
|
28 | /* MMC/SD command */ | |||
|
29 | #define CMD0 (0) /* GO_IDLE_STATE */ | |||
|
30 | #define CMD1 (1) /* SEND_OP_COND (MMC) */ | |||
|
31 | #define ACMD41 (0x80+41) /* SEND_OP_COND (SDC) */ | |||
|
32 | #define CMD8 (8) /* SEND_IF_COND */ | |||
|
33 | #define CMD9 (9) /* SEND_CSD */ | |||
|
34 | #define CMD10 (10) /* SEND_CID */ | |||
|
35 | #define CMD12 (12) /* STOP_TRANSMISSION */ | |||
|
36 | #define ACMD13 (0x80+13) /* SD_STATUS (SDC) */ | |||
|
37 | #define CMD16 (16) /* SET_BLOCKLEN */ | |||
|
38 | #define CMD17 (17) /* READ_SINGLE_BLOCK */ | |||
|
39 | #define CMD18 (18) /* READ_MULTIPLE_BLOCK */ | |||
|
40 | #define CMD23 (23) /* SET_BLOCK_COUNT (MMC) */ | |||
|
41 | #define ACMD23 (0x80+23) /* SET_WR_BLK_ERASE_COUNT (SDC) */ | |||
|
42 | #define CMD24 (24) /* WRITE_BLOCK */ | |||
|
43 | #define CMD25 (25) /* WRITE_MULTIPLE_BLOCK */ | |||
|
44 | #define CMD32 (32) /* ERASE_ER_BLK_START */ | |||
|
45 | #define CMD33 (33) /* ERASE_ER_BLK_END */ | |||
|
46 | #define CMD38 (38) /* ERASE */ | |||
|
47 | #define CMD55 (55) /* APP_CMD */ | |||
|
48 | #define CMD58 (58) /* READ_OCR */ | |||
|
49 | ||||
|
50 | /* Card type flags (CardType) */ | |||
|
51 | #define CT_MMC 0x01 /* MMC ver 3 */ | |||
|
52 | #define CT_SD1 0x02 /* SD ver 1 */ | |||
|
53 | #define CT_SD2 0x04 /* SD ver 2 */ | |||
|
54 | #define CT_SDC (CT_SD1|CT_SD2) /* SD */ | |||
|
55 | #define CT_BLOCK 0x08 /* Block addressing */ | |||
|
56 | ||||
|
57 | struct sdcard_str | |||
|
58 | { | |||
|
59 | UHANDLE phy; | |||
|
60 | void (*rcvr_mmc) (UHANDLE phy,char *buff,unsigned int bc); | |||
|
61 | void (*xmit_mmc) (UHANDLE phy,const char *buff,unsigned int bc); | |||
|
62 | void (*setspeed) (UHANDLE phy,unsigned int speed); | |||
|
63 | unsigned int (*getspeed) (UHANDLE phy); | |||
|
64 | DSTATUS Stat; | |||
|
65 | char CardType; | |||
|
66 | }; | |||
|
67 | ||||
|
68 | typedef volatile struct sdcard_str sdcardDev; | |||
|
69 | ||||
|
70 | extern void sdcardmake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,unsigned int ),void (*xmit_mmc) (UHANDLE,const char *,unsigned int ),void (*setspeed) (UHANDLE phy,unsigned int speed),unsigned int (*getspeed) (UHANDLE phy)); | |||
|
71 | extern void sdcardmakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected); | |||
|
72 | ||||
|
73 | extern int sdcardselect (blkdevice* _this); | |||
|
74 | extern void sdcarddeselect (blkdevice* _this); | |||
|
75 | extern int sdcardwait_ready (sdcardDev* sdcard); | |||
|
76 | extern int sdcardxmit_datablock (sdcardDev* sdcard,const char *buff,char token); | |||
|
77 | extern int sdcardrcvr_datablock (sdcardDev* sdcard,char *buff,unsigned int btr); | |||
|
78 | extern char sdcardsend_cmd (blkdevice* _this,char cmd,unsigned int arg); | |||
|
79 | ||||
|
80 | extern DSTATUS sdcarddisk_status (blkdevice* _this); | |||
|
81 | extern DSTATUS sdcarddisk_initialize (blkdevice* _this); | |||
|
82 | extern DRESULT sdcarddisk_read (blkdevice* _this,char *buff,unsigned int sector,char count); | |||
|
83 | extern DRESULT sdcarddisk_write (blkdevice* _this,const char *buff,unsigned int sector,char count); | |||
|
84 | extern DRESULT sdcarddisk_ioctl (blkdevice* _this,char ctrl,void *buff); | |||
|
85 | ||||
|
86 | #endif | |||
|
87 | ||||
|
88 | ||||
|
89 | ||||
|
90 | ||||
|
91 | ||||
|
92 | ||||
|
93 | ||||
|
94 | ||||
|
95 | ||||
|
96 | ||||
|
97 | ||||
|
98 | ||||
|
99 | ||||
|
100 | ||||
|
101 | ||||
|
102 | ||||
|
103 | ||||
|
104 | ||||
|
105 | ||||
|
106 | ||||
|
107 | ||||
|
108 | ||||
|
109 | ||||
|
110 | ||||
|
111 | ||||
|
112 | ||||
|
113 | ||||
|
114 | ||||
|
115 | ||||
|
116 | ||||
|
117 | ||||
|
118 |
@@ -0,0 +1,26 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | lpc17XX.ARCH = lpc17XX-arm-noabi-gcc | |||
|
3 | lpc17XX.TARGET = libsdcard | |||
|
4 | lpc17XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_SDCARD) | |||
|
5 | lpc17XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_SDCARD) | |||
|
6 | ||||
|
7 | lpc17XX.LIBS += SSP BLKDEVICE UCSTRINGS UHANDLE | |||
|
8 | ||||
|
9 | lpc17XX.SOURCES += sdcard.c | |||
|
10 | ||||
|
11 | ||||
|
12 | lpc17XX.HEADERS += sdcard.h | |||
|
13 | ||||
|
14 | ||||
|
15 | ||||
|
16 | lpc21XX.ARCH = lpc21XX-arm-noabi-gcc | |||
|
17 | lpc21XX.TARGET = libsdcard | |||
|
18 | lpc21XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_SDCARD) | |||
|
19 | lpc21XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_SDCARD) | |||
|
20 | ||||
|
21 | lpc21XX.LIBS += SSP BLKDEVICE | |||
|
22 | ||||
|
23 | lpc21XX.SOURCES += sdcard.c | |||
|
24 | ||||
|
25 | ||||
|
26 | lpc21XX.HEADERS += sdcard.h |
@@ -0,0 +1,11 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | all: | |||
|
6 | make -f lpc17XX.mk | |||
|
7 | make -f lpc21XX.mk | |||
|
8 | ||||
|
9 | clean: | |||
|
10 | make clean -f lpc17XX.mk | |||
|
11 | make clean -f lpc21XX.mk |
@@ -0,0 +1,73 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | #-- This file is a part of the libuc, microcontroler library | |||
|
3 | #-- Copyright (C) 2011, Alexis Jeandet | |||
|
4 | #-- | |||
|
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 | |||
|
7 | #-- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | #-- (at your option) any later version. | |||
|
9 | #-- | |||
|
10 | #-- This program is distributed in the hope that it will be useful, | |||
|
11 | #-- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | #-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | #-- GNU General Public License for more details. | |||
|
14 | #-- | |||
|
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 | |||
|
17 | #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | #------------------------------------------------------------------------------- | |||
|
19 | #-- Author : Alexis Jeandet | |||
|
20 | #-- Mail : alexis.jeandet@gmail.com | |||
|
21 | #-------------------------------------------------------------------------------*/ | |||
|
22 | #include "hexviewer.h" | |||
|
23 | ||||
|
24 | void hexviewershow(const char* table,unsigned int size,unsigned int offset) | |||
|
25 | { | |||
|
26 | int i=0,n=0; | |||
|
27 | if(!offset) | |||
|
28 | libucprintf("00"); | |||
|
29 | libucprintf(" "); | |||
|
30 | for(i=0;i<(size);i+=16) | |||
|
31 | { | |||
|
32 | libucprintf("%X:\t",n+i+offset); | |||
|
33 | for(n=0;n<16;n++) | |||
|
34 | { | |||
|
35 | if(table[n+i]==0)libucprintf("0"); | |||
|
36 | if(0x10>table[n+i])libucprintf("0"); | |||
|
37 | libucprintf("%X ",0xFF & table[n+i]); | |||
|
38 | if((n & 3)==3)libucprintf(" "); | |||
|
39 | } | |||
|
40 | libucprintf("\t "); | |||
|
41 | for(n=0;n<16;n++) | |||
|
42 | { | |||
|
43 | if(33<=table[n+i]) | |||
|
44 | { | |||
|
45 | if(126>=table[n+i]) | |||
|
46 | libucprintf("%c",0x7f & table[n+i]); | |||
|
47 | else | |||
|
48 | libucprintf("."); | |||
|
49 | } | |||
|
50 | else | |||
|
51 | libucprintf("."); | |||
|
52 | } | |||
|
53 | libucprintf("\n\r "); | |||
|
54 | if((i & (3<<4))==(3<<4))libucprintf("\n\r "); | |||
|
55 | } | |||
|
56 | } | |||
|
57 | ||||
|
58 | ||||
|
59 | ||||
|
60 | ||||
|
61 | ||||
|
62 | ||||
|
63 | ||||
|
64 | ||||
|
65 | ||||
|
66 | ||||
|
67 | ||||
|
68 | ||||
|
69 | ||||
|
70 | ||||
|
71 | ||||
|
72 | ||||
|
73 |
@@ -0,0 +1,52 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | #-- This file is a part of the libuc, microcontroler library | |||
|
3 | #-- Copyright (C) 2011, Alexis Jeandet | |||
|
4 | #-- | |||
|
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 | |||
|
7 | #-- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | #-- (at your option) any later version. | |||
|
9 | #-- | |||
|
10 | #-- This program is distributed in the hope that it will be useful, | |||
|
11 | #-- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | #-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | #-- GNU General Public License for more details. | |||
|
14 | #-- | |||
|
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 | |||
|
17 | #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | #------------------------------------------------------------------------------- | |||
|
19 | #-- Author : Alexis Jeandet | |||
|
20 | #-- Mail : alexis.jeandet@gmail.com | |||
|
21 | #-------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef HEXVIEWER_H | |||
|
23 | #define HEXVIEWER_H | |||
|
24 | ||||
|
25 | #include <libucstrings.h> | |||
|
26 | ||||
|
27 | ||||
|
28 | ||||
|
29 | ||||
|
30 | extern void hexviewershow(const char* table,unsigned int size,unsigned int offset); | |||
|
31 | ||||
|
32 | ||||
|
33 | #endif | |||
|
34 | ||||
|
35 | ||||
|
36 | ||||
|
37 | ||||
|
38 | ||||
|
39 | ||||
|
40 | ||||
|
41 | ||||
|
42 | ||||
|
43 | ||||
|
44 | ||||
|
45 | ||||
|
46 | ||||
|
47 | ||||
|
48 | ||||
|
49 | ||||
|
50 | ||||
|
51 | ||||
|
52 |
@@ -0,0 +1,26 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | lpc17XX.ARCH = lpc17XX-arm-noabi-gcc | |||
|
3 | lpc17XX.TARGET = libhexviewer | |||
|
4 | lpc17XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_HEXVIEWER) | |||
|
5 | lpc17XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_HEXVIEWER) | |||
|
6 | ||||
|
7 | lpc17XX.LIBS += UCSTRINGS | |||
|
8 | ||||
|
9 | lpc17XX.SOURCES += hexviewer.c | |||
|
10 | ||||
|
11 | ||||
|
12 | lpc17XX.HEADERS += hexviewer.h | |||
|
13 | ||||
|
14 | ||||
|
15 | ||||
|
16 | lpc21XX.ARCH = lpc21XX-arm-noabi-gcc | |||
|
17 | lpc21XX.TARGET = libhexviewer | |||
|
18 | lpc21XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_HEXVIEWER) | |||
|
19 | lpc21XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_HEXVIEWER) | |||
|
20 | ||||
|
21 | lpc21XX.LIBS += UCSTRINGS | |||
|
22 | ||||
|
23 | lpc21XX.SOURCES += hexviewer.c | |||
|
24 | ||||
|
25 | ||||
|
26 | lpc21XX.HEADERS += hexviewer.h |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_HEXVIEWER) | |||
|
5 | HEADERS += hexviewer.h | |||
|
6 | LIBSOURCES += hexviewer.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |||
|
13 | TARGET=libhexviewer | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_UCSTRINGS_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_HEXVIEWER) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_HEXVIEWER) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_HEXVIEWER) | |||
|
5 | HEADERS += hexviewer.h | |||
|
6 | LIBSOURCES += hexviewer.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
13 | TARGET=libhexviewer | |||
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) | |||
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_HEXVIEWER) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_HEXVIEWER) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,11 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | all: | |||
|
6 | make -f lpc17XX.mk | |||
|
7 | make -f lpc21XX.mk | |||
|
8 | ||||
|
9 | clean: | |||
|
10 | make clean -f lpc17XX.mk | |||
|
11 | make clean -f lpc21XX.mk |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_UHANDLE) | |||
|
5 | HEADERS += uhandle.h | |||
|
6 | LIBSOURCES += uhandle.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |||
|
13 | TARGET=libuhandle | |||
|
14 | LIBUC_INCLUDES= | |||
|
15 | LIBUC_LIBRARIES= | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_UHANDLE) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_UHANDLE) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,29 | |||||
|
1 | PROJECTDIR = `pwd` | |||
|
2 | LIBUC = /opt/libuc2 | |||
|
3 | ||||
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_UHANDLE) | |||
|
5 | HEADERS += uhandle.h | |||
|
6 | LIBSOURCES += uhandle.c | |||
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
11 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
13 | TARGET=libuhandle | |||
|
14 | LIBUC_INCLUDES= | |||
|
15 | LIBUC_LIBRARIES= | |||
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_UHANDLE) | |||
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_UHANDLE) | |||
|
18 | BSP=generic | |||
|
19 | include $(ARCHFOLDER)/rules.mk | |||
|
20 | ||||
|
21 | all:lib | |||
|
22 | @echo Code compiled | |||
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -0,0 +1,21 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ |
@@ -0,0 +1,29 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef UHANDLE_H | |||
|
23 | #define UHANDLE_H | |||
|
24 | ||||
|
25 | typedef volatile void* UHANDLE; | |||
|
26 | ||||
|
27 | #define uhandlevalide(HANDLE) ((HANDLE)!=0) | |||
|
28 | ||||
|
29 | #endif |
@@ -0,0 +1,26 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | lpc17XX.ARCH = lpc17XX-arm-noabi-gcc | |||
|
3 | lpc17XX.TARGET = libuhandle | |||
|
4 | lpc17XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_UHANDLE) | |||
|
5 | lpc17XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_UHANDLE) | |||
|
6 | ||||
|
7 | lpc17XX.LIBS += | |||
|
8 | ||||
|
9 | lpc17XX.SOURCES += uhandle.c | |||
|
10 | ||||
|
11 | ||||
|
12 | lpc17XX.HEADERS += uhandle.h | |||
|
13 | ||||
|
14 | ||||
|
15 | ||||
|
16 | lpc21XX.ARCH = lpc21XX-arm-noabi-gcc | |||
|
17 | lpc21XX.TARGET = libuhandle | |||
|
18 | lpc21XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_UHANDLE) | |||
|
19 | lpc21XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_UHANDLE) | |||
|
20 | ||||
|
21 | lpc21XX.LIBS += | |||
|
22 | ||||
|
23 | lpc21XX.SOURCES += uhandle.c | |||
|
24 | ||||
|
25 | ||||
|
26 | lpc21XX.HEADERS += uhandle.h |
This diff has been collapsed as it changes many lines, (4077 lines changed) Show them Hide them | |||||
@@ -0,0 +1,4077 | |||||
|
1 | /*----------------------------------------------------------------------------/ | |||
|
2 | / FatFs - FAT file system module R0.09 (C)ChaN, 2011 | |||
|
3 | /-----------------------------------------------------------------------------/ | |||
|
4 | / FatFs module is a generic FAT file system module for small embedded systems. | |||
|
5 | / This is a free software that opened for education, research and commercial | |||
|
6 | / developments under license policy of following terms. | |||
|
7 | / | |||
|
8 | / Copyright (C) 2011, ChaN, all right reserved. | |||
|
9 | / | |||
|
10 | / * The FatFs module is a free software and there is NO WARRANTY. | |||
|
11 | / * No restriction on use. You can use, modify and redistribute it for | |||
|
12 | / personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY. | |||
|
13 | / * Redistributions of source code must retain the above copyright notice. | |||
|
14 | / | |||
|
15 | /-----------------------------------------------------------------------------/ | |||
|
16 | / Feb 26,'06 R0.00 Prototype. | |||
|
17 | / | |||
|
18 | / Apr 29,'06 R0.01 First stable version. | |||
|
19 | / | |||
|
20 | / Jun 01,'06 R0.02 Added FAT12 support. | |||
|
21 | / Removed unbuffered mode. | |||
|
22 | / Fixed a problem on small (<32M) partition. | |||
|
23 | / Jun 10,'06 R0.02a Added a configuration option (_FS_MINIMUM). | |||
|
24 | / | |||
|
25 | / Sep 22,'06 R0.03 Added f_rename(). | |||
|
26 | / Changed option _FS_MINIMUM to _FS_MINIMIZE. | |||
|
27 | / Dec 11,'06 R0.03a Improved cluster scan algorithm to write files fast. | |||
|
28 | / Fixed f_mkdir() creates incorrect directory on FAT32. | |||
|
29 | / | |||
|
30 | / Feb 04,'07 R0.04 Supported multiple drive system. | |||
|
31 | / Changed some interfaces for multiple drive system. | |||
|
32 | / Changed f_mountdrv() to f_mount(). | |||
|
33 | / Added f_mkfs(). | |||
|
34 | / Apr 01,'07 R0.04a Supported multiple partitions on a physical drive. | |||
|
35 | / Added a capability of extending file size to f_lseek(). | |||
|
36 | / Added minimization level 3. | |||
|
37 | / Fixed an endian sensitive code in f_mkfs(). | |||
|
38 | / May 05,'07 R0.04b Added a configuration option _USE_NTFLAG. | |||
|
39 | / Added FSInfo support. | |||
|
40 | / Fixed DBCS name can result FR_INVALID_NAME. | |||
|
41 | / Fixed short seek (<= csize) collapses the file object. | |||
|
42 | / | |||
|
43 | / Aug 25,'07 R0.05 Changed arguments of f_read(), f_write() and f_mkfs(). | |||
|
44 | / Fixed f_mkfs() on FAT32 creates incorrect FSInfo. | |||
|
45 | / Fixed f_mkdir() on FAT32 creates incorrect directory. | |||
|
46 | / Feb 03,'08 R0.05a Added f_truncate() and f_utime(). | |||
|
47 | / Fixed off by one error at FAT sub-type determination. | |||
|
48 | / Fixed btr in f_read() can be mistruncated. | |||
|
49 | / Fixed cached sector is not flushed when create and close without write. | |||
|
50 | / | |||
|
51 | / Apr 01,'08 R0.06 Added fputc(), fputs(), fprintf() and fgets(). | |||
|
52 | / Improved performance of f_lseek() on moving to the same or following cluster. | |||
|
53 | / | |||
|
54 | / Apr 01,'09 R0.07 Merged Tiny-FatFs as a configuration option. (_FS_TINY) | |||
|
55 | / Added long file name feature. | |||
|
56 | / Added multiple code page feature. | |||
|
57 | / Added re-entrancy for multitask operation. | |||
|
58 | / Added auto cluster size selection to f_mkfs(). | |||
|
59 | / Added rewind option to f_readdir(). | |||
|
60 | / Changed result code of critical errors. | |||
|
61 | / Renamed string functions to avoid name collision. | |||
|
62 | / Apr 14,'09 R0.07a Separated out OS dependent code on reentrant cfg. | |||
|
63 | / Added multiple sector size feature. | |||
|
64 | / Jun 21,'09 R0.07c Fixed f_unlink() can return FR_OK on error. | |||
|
65 | / Fixed wrong cache control in f_lseek(). | |||
|
66 | / Added relative path feature. | |||
|
67 | / Added f_chdir() and f_chdrive(). | |||
|
68 | / Added proper case conversion to extended char. | |||
|
69 | / Nov 03,'09 R0.07e Separated out configuration options from ff.h to ffconf.h. | |||
|
70 | / Fixed f_unlink() fails to remove a sub-dir on _FS_RPATH. | |||
|
71 | / Fixed name matching error on the 13 char boundary. | |||
|
72 | / Added a configuration option, _LFN_UNICODE. | |||
|
73 | / Changed f_readdir() to return the SFN with always upper case on non-LFN cfg. | |||
|
74 | / | |||
|
75 | / May 15,'10 R0.08 Added a memory configuration option. (_USE_LFN = 3) | |||
|
76 | / Added file lock feature. (_FS_SHARE) | |||
|
77 | / Added fast seek feature. (_USE_FASTSEEK) | |||
|
78 | / Changed some types on the API, XCHAR->TCHAR. | |||
|
79 | / Changed fname member in the FILINFO structure on Unicode cfg. | |||
|
80 | / String functions support UTF-8 encoding files on Unicode cfg. | |||
|
81 | / Aug 16,'10 R0.08a Added f_getcwd(). (_FS_RPATH = 2) | |||
|
82 | / Added sector erase feature. (_USE_ERASE) | |||
|
83 | / Moved file lock semaphore table from fs object to the bss. | |||
|
84 | / Fixed a wrong directory entry is created on non-LFN cfg when the given name contains ';'. | |||
|
85 | / Fixed f_mkfs() creates wrong FAT32 volume. | |||
|
86 | / Jan 15,'11 R0.08b Fast seek feature is also applied to f_read() and f_write(). | |||
|
87 | / f_lseek() reports required table size on creating CLMP. | |||
|
88 | / Extended format syntax of f_printf function. | |||
|
89 | / Ignores duplicated directory separators in given path names. | |||
|
90 | / | |||
|
91 | / Sep 06,'11 R0.09 f_mkfs() supports multiple partition to finish the multiple partition feature. | |||
|
92 | / Added f_fdisk(). (_MULTI_PARTITION = 2) | |||
|
93 | /---------------------------------------------------------------------------*/ | |||
|
94 | ||||
|
95 | #include "fat.h" /* FatFs configurations and declarations */ | |||
|
96 | #include "blkdevice.h" /* Declarations of low level disk I/O functions */ | |||
|
97 | ||||
|
98 | ||||
|
99 | /*-------------------------------------------------------------------------- | |||
|
100 | ||||
|
101 | Module Private Definitions | |||
|
102 | ||||
|
103 | ---------------------------------------------------------------------------*/ | |||
|
104 | ||||
|
105 | #if _FATFS != 6502 /* Revision ID */ | |||
|
106 | #error Wrong include file (ff.h). | |||
|
107 | #endif | |||
|
108 | ||||
|
109 | ||||
|
110 | /* Definitions on sector size */ | |||
|
111 | #if _MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096 | |||
|
112 | #error Wrong sector size. | |||
|
113 | #endif | |||
|
114 | #if _MAX_SS != 512 | |||
|
115 | #define SS(fs) ((fs)->ssize) /* Variable sector size */ | |||
|
116 | #else | |||
|
117 | #define SS(fs) 512U /* Fixed sector size */ | |||
|
118 | #endif | |||
|
119 | ||||
|
120 | ||||
|
121 | /* Reentrancy related */ | |||
|
122 | #if _FS_REENTRANT | |||
|
123 | #if _USE_LFN == 1 | |||
|
124 | #error Static LFN work area must not be used in re-entrant configuration. | |||
|
125 | #endif | |||
|
126 | #define ENTER_FF(fs) { if (!lock_fs(fs)) return FR_TIMEOUT; } | |||
|
127 | #define LEAVE_FF(fs, res) { unlock_fs(fs, res); return res; } | |||
|
128 | #else | |||
|
129 | #define ENTER_FF(fs) | |||
|
130 | #define LEAVE_FF(fs, res) return res | |||
|
131 | #endif | |||
|
132 | ||||
|
133 | #define ABORT(fs, res) { fp->flag |= FA__ERROR; LEAVE_FF(fs, res); } | |||
|
134 | ||||
|
135 | ||||
|
136 | /* File shareing feature */ | |||
|
137 | #if _FS_SHARE | |||
|
138 | #if _FS_READONLY | |||
|
139 | #error _FS_SHARE must be 0 on read-only cfg. | |||
|
140 | #endif | |||
|
141 | typedef struct { | |||
|
142 | FATFS *fs; /* File ID 1, volume (NULL:blank entry) */ | |||
|
143 | DWORD clu; /* File ID 2, directory */ | |||
|
144 | WORD idx; /* File ID 3, directory index */ | |||
|
145 | WORD ctr; /* File open counter, 0:none, 0x01..0xFF:read open count, 0x100:write mode */ | |||
|
146 | } FILESEM; | |||
|
147 | #endif | |||
|
148 | ||||
|
149 | ||||
|
150 | /* Misc definitions */ | |||
|
151 | #define LD_CLUST(dir) (((DWORD)LD_WORD(dir+DIR_FstClusHI)<<16) | LD_WORD(dir+DIR_FstClusLO)) | |||
|
152 | #define ST_CLUST(dir,cl) {ST_WORD(dir+DIR_FstClusLO, cl); ST_WORD(dir+DIR_FstClusHI, (DWORD)cl>>16);} | |||
|
153 | ||||
|
154 | ||||
|
155 | /* DBCS code ranges and SBCS extend char conversion table */ | |||
|
156 | ||||
|
157 | #if _CODE_PAGE == 932 /* Japanese Shift-JIS */ | |||
|
158 | #define _DF1S 0x81 /* DBC 1st byte range 1 start */ | |||
|
159 | #define _DF1E 0x9F /* DBC 1st byte range 1 end */ | |||
|
160 | #define _DF2S 0xE0 /* DBC 1st byte range 2 start */ | |||
|
161 | #define _DF2E 0xFC /* DBC 1st byte range 2 end */ | |||
|
162 | #define _DS1S 0x40 /* DBC 2nd byte range 1 start */ | |||
|
163 | #define _DS1E 0x7E /* DBC 2nd byte range 1 end */ | |||
|
164 | #define _DS2S 0x80 /* DBC 2nd byte range 2 start */ | |||
|
165 | #define _DS2E 0xFC /* DBC 2nd byte range 2 end */ | |||
|
166 | ||||
|
167 | #elif _CODE_PAGE == 936 /* Simplified Chinese GBK */ | |||
|
168 | #define _DF1S 0x81 | |||
|
169 | #define _DF1E 0xFE | |||
|
170 | #define _DS1S 0x40 | |||
|
171 | #define _DS1E 0x7E | |||
|
172 | #define _DS2S 0x80 | |||
|
173 | #define _DS2E 0xFE | |||
|
174 | ||||
|
175 | #elif _CODE_PAGE == 949 /* Korean */ | |||
|
176 | #define _DF1S 0x81 | |||
|
177 | #define _DF1E 0xFE | |||
|
178 | #define _DS1S 0x41 | |||
|
179 | #define _DS1E 0x5A | |||
|
180 | #define _DS2S 0x61 | |||
|
181 | #define _DS2E 0x7A | |||
|
182 | #define _DS3S 0x81 | |||
|
183 | #define _DS3E 0xFE | |||
|
184 | ||||
|
185 | #elif _CODE_PAGE == 950 /* Traditional Chinese Big5 */ | |||
|
186 | #define _DF1S 0x81 | |||
|
187 | #define _DF1E 0xFE | |||
|
188 | #define _DS1S 0x40 | |||
|
189 | #define _DS1E 0x7E | |||
|
190 | #define _DS2S 0xA1 | |||
|
191 | #define _DS2E 0xFE | |||
|
192 | ||||
|
193 | #elif _CODE_PAGE == 437 /* U.S. (OEM) */ | |||
|
194 | #define _DF1S 0 | |||
|
195 | #define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F,0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ | |||
|
196 | 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
197 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
198 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} | |||
|
199 | ||||
|
200 | #elif _CODE_PAGE == 720 /* Arabic (OEM) */ | |||
|
201 | #define _DF1S 0 | |||
|
202 | #define _EXCVT {0x80,0x81,0x45,0x41,0x84,0x41,0x86,0x43,0x45,0x45,0x45,0x49,0x49,0x8D,0x8E,0x8F,0x90,0x92,0x92,0x93,0x94,0x95,0x49,0x49,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ | |||
|
203 | 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
204 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
205 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} | |||
|
206 | ||||
|
207 | #elif _CODE_PAGE == 737 /* Greek (OEM) */ | |||
|
208 | #define _DF1S 0 | |||
|
209 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x92,0x92,0x93,0x94,0x95,0x96,0x97,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, \ | |||
|
210 | 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0xAA,0x92,0x93,0x94,0x95,0x96,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
211 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
212 | 0x97,0xEA,0xEB,0xEC,0xE4,0xED,0xEE,0xE7,0xE8,0xF1,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} | |||
|
213 | ||||
|
214 | #elif _CODE_PAGE == 775 /* Baltic (OEM) */ | |||
|
215 | #define _DF1S 0 | |||
|
216 | #define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F,0x90,0x92,0x92,0xE2,0x99,0x95,0x96,0x97,0x97,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \ | |||
|
217 | 0xA0,0xA1,0xE0,0xA3,0xA3,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
218 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xB5,0xB6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xA5,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
219 | 0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE3,0xE8,0xE8,0xEA,0xEA,0xEE,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} | |||
|
220 | ||||
|
221 | #elif _CODE_PAGE == 850 /* Multilingual Latin 1 (OEM) */ | |||
|
222 | #define _DF1S 0 | |||
|
223 | #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0xDE,0x8E,0x8F,0x90,0x92,0x92,0xE2,0x99,0xE3,0xEA,0xEB,0x59,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \ | |||
|
224 | 0xB5,0xD6,0xE0,0xE9,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
225 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
226 | 0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE7,0xE7,0xE9,0xEA,0xEB,0xED,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} | |||
|
227 | ||||
|
228 | #elif _CODE_PAGE == 852 /* Latin 2 (OEM) */ | |||
|
229 | #define _DF1S 0 | |||
|
230 | #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xDE,0x8F,0x80,0x9D,0xD3,0x8A,0x8A,0xD7,0x8D,0x8E,0x8F,0x90,0x91,0x91,0xE2,0x99,0x95,0x95,0x97,0x97,0x99,0x9A,0x9B,0x9B,0x9D,0x9E,0x9F, \ | |||
|
231 | 0xB5,0xD6,0xE0,0xE9,0xA4,0xA4,0xA6,0xA6,0xA8,0xA8,0xAA,0x8D,0xAC,0xB8,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBD,0xBF, \ | |||
|
232 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC6,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD1,0xD1,0xD2,0xD3,0xD2,0xD5,0xD6,0xD7,0xB7,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
233 | 0xE0,0xE1,0xE2,0xE3,0xE3,0xD5,0xE6,0xE6,0xE8,0xE9,0xE8,0xEB,0xED,0xED,0xDD,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xEB,0xFC,0xFC,0xFE,0xFF} | |||
|
234 | ||||
|
235 | #elif _CODE_PAGE == 855 /* Cyrillic (OEM) */ | |||
|
236 | #define _DF1S 0 | |||
|
237 | #define _EXCVT {0x81,0x81,0x83,0x83,0x85,0x85,0x87,0x87,0x89,0x89,0x8B,0x8B,0x8D,0x8D,0x8F,0x8F,0x91,0x91,0x93,0x93,0x95,0x95,0x97,0x97,0x99,0x99,0x9B,0x9B,0x9D,0x9D,0x9F,0x9F, \ | |||
|
238 | 0xA1,0xA1,0xA3,0xA3,0xA5,0xA5,0xA7,0xA7,0xA9,0xA9,0xAB,0xAB,0xAD,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB6,0xB6,0xB8,0xB8,0xB9,0xBA,0xBB,0xBC,0xBE,0xBE,0xBF, \ | |||
|
239 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD1,0xD1,0xD3,0xD3,0xD5,0xD5,0xD7,0xD7,0xDD,0xD9,0xDA,0xDB,0xDC,0xDD,0xE0,0xDF, \ | |||
|
240 | 0xE0,0xE2,0xE2,0xE4,0xE4,0xE6,0xE6,0xE8,0xE8,0xEA,0xEA,0xEC,0xEC,0xEE,0xEE,0xEF,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFD,0xFE,0xFF} | |||
|
241 | ||||
|
242 | #elif _CODE_PAGE == 857 /* Turkish (OEM) */ | |||
|
243 | #define _DF1S 0 | |||
|
244 | #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0x98,0x8E,0x8F,0x90,0x92,0x92,0xE2,0x99,0xE3,0xEA,0xEB,0x98,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9E, \ | |||
|
245 | 0xB5,0xD6,0xE0,0xE9,0xA5,0xA5,0xA6,0xA6,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
246 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
247 | 0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xDE,0x59,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} | |||
|
248 | ||||
|
249 | #elif _CODE_PAGE == 858 /* Multilingual Latin 1 + Euro (OEM) */ | |||
|
250 | #define _DF1S 0 | |||
|
251 | #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0xDE,0x8E,0x8F,0x90,0x92,0x92,0xE2,0x99,0xE3,0xEA,0xEB,0x59,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \ | |||
|
252 | 0xB5,0xD6,0xE0,0xE9,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
253 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD1,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
254 | 0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE7,0xE7,0xE9,0xEA,0xEB,0xED,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} | |||
|
255 | ||||
|
256 | #elif _CODE_PAGE == 862 /* Hebrew (OEM) */ | |||
|
257 | #define _DF1S 0 | |||
|
258 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ | |||
|
259 | 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
260 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
261 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} | |||
|
262 | ||||
|
263 | #elif _CODE_PAGE == 866 /* Russian (OEM) */ | |||
|
264 | #define _DF1S 0 | |||
|
265 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ | |||
|
266 | 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
267 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
268 | 0x90,0x91,0x92,0x93,0x9d,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} | |||
|
269 | ||||
|
270 | #elif _CODE_PAGE == 874 /* Thai (OEM, Windows) */ | |||
|
271 | #define _DF1S 0 | |||
|
272 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ | |||
|
273 | 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
274 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
275 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} | |||
|
276 | ||||
|
277 | #elif _CODE_PAGE == 1250 /* Central Europe (Windows) */ | |||
|
278 | #define _DF1S 0 | |||
|
279 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x8A,0x9B,0x8C,0x8D,0x8E,0x8F, \ | |||
|
280 | 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xA3,0xB4,0xB5,0xB6,0xB7,0xB8,0xA5,0xAA,0xBB,0xBC,0xBD,0xBC,0xAF, \ | |||
|
281 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
282 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xFF} | |||
|
283 | ||||
|
284 | #elif _CODE_PAGE == 1251 /* Cyrillic (Windows) */ | |||
|
285 | #define _DF1S 0 | |||
|
286 | #define _EXCVT {0x80,0x81,0x82,0x82,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x80,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x8A,0x9B,0x8C,0x8D,0x8E,0x8F, \ | |||
|
287 | 0xA0,0xA2,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB2,0xA5,0xB5,0xB6,0xB7,0xA8,0xB9,0xAA,0xBB,0xA3,0xBD,0xBD,0xAF, \ | |||
|
288 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
289 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF} | |||
|
290 | ||||
|
291 | #elif _CODE_PAGE == 1252 /* Latin 1 (Windows) */ | |||
|
292 | #define _DF1S 0 | |||
|
293 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0xAd,0x9B,0x8C,0x9D,0xAE,0x9F, \ | |||
|
294 | 0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
295 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
296 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x9F} | |||
|
297 | ||||
|
298 | #elif _CODE_PAGE == 1253 /* Greek (Windows) */ | |||
|
299 | #define _DF1S 0 | |||
|
300 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ | |||
|
301 | 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
302 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xA2,0xB8,0xB9,0xBA, \ | |||
|
303 | 0xE0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xF2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xFB,0xBC,0xFD,0xBF,0xFF} | |||
|
304 | ||||
|
305 | #elif _CODE_PAGE == 1254 /* Turkish (Windows) */ | |||
|
306 | #define _DF1S 0 | |||
|
307 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x8A,0x9B,0x8C,0x9D,0x9E,0x9F, \ | |||
|
308 | 0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
309 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
310 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x9F} | |||
|
311 | ||||
|
312 | #elif _CODE_PAGE == 1255 /* Hebrew (Windows) */ | |||
|
313 | #define _DF1S 0 | |||
|
314 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ | |||
|
315 | 0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
316 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
317 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} | |||
|
318 | ||||
|
319 | #elif _CODE_PAGE == 1256 /* Arabic (Windows) */ | |||
|
320 | #define _DF1S 0 | |||
|
321 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x8C,0x9D,0x9E,0x9F, \ | |||
|
322 | 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
323 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
324 | 0x41,0xE1,0x41,0xE3,0xE4,0xE5,0xE6,0x43,0x45,0x45,0x45,0x45,0xEC,0xED,0x49,0x49,0xF0,0xF1,0xF2,0xF3,0x4F,0xF5,0xF6,0xF7,0xF8,0x55,0xFA,0x55,0x55,0xFD,0xFE,0xFF} | |||
|
325 | ||||
|
326 | #elif _CODE_PAGE == 1257 /* Baltic (Windows) */ | |||
|
327 | #define _DF1S 0 | |||
|
328 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ | |||
|
329 | 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xA8,0xB9,0xAA,0xBB,0xBC,0xBD,0xBE,0xAF, \ | |||
|
330 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
331 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xFF} | |||
|
332 | ||||
|
333 | #elif _CODE_PAGE == 1258 /* Vietnam (OEM, Windows) */ | |||
|
334 | #define _DF1S 0 | |||
|
335 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0xAC,0x9D,0x9E,0x9F, \ | |||
|
336 | 0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ | |||
|
337 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ | |||
|
338 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xEC,0xCD,0xCE,0xCF,0xD0,0xD1,0xF2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xFE,0x9F} | |||
|
339 | ||||
|
340 | #elif _CODE_PAGE == 1 /* ASCII (for only non-LFN cfg) */ | |||
|
341 | #if _USE_LFN | |||
|
342 | #error Cannot use LFN feature without valid code page. | |||
|
343 | #endif | |||
|
344 | #define _DF1S 0 | |||
|
345 | ||||
|
346 | #else | |||
|
347 | #error Unknown code page | |||
|
348 | ||||
|
349 | #endif | |||
|
350 | ||||
|
351 | ||||
|
352 | /* Character code support macros */ | |||
|
353 | #define IsUpper(c) (((c)>='A')&&((c)<='Z')) | |||
|
354 | #define IsLower(c) (((c)>='a')&&((c)<='z')) | |||
|
355 | #define IsDigit(c) (((c)>='0')&&((c)<='9')) | |||
|
356 | ||||
|
357 | #if _DF1S /* Code page is DBCS */ | |||
|
358 | ||||
|
359 | #ifdef _DF2S /* Two 1st byte areas */ | |||
|
360 | #define IsDBCS1(c) (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E)) | |||
|
361 | #else /* One 1st byte area */ | |||
|
362 | #define IsDBCS1(c) ((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) | |||
|
363 | #endif | |||
|
364 | ||||
|
365 | #ifdef _DS3S /* Three 2nd byte areas */ | |||
|
366 | #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E) || ((BYTE)(c) >= _DS3S && (BYTE)(c) <= _DS3E)) | |||
|
367 | #else /* Two 2nd byte areas */ | |||
|
368 | #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E)) | |||
|
369 | #endif | |||
|
370 | ||||
|
371 | #else /* Code page is SBCS */ | |||
|
372 | ||||
|
373 | #define IsDBCS1(c) 0 | |||
|
374 | #define IsDBCS2(c) 0 | |||
|
375 | ||||
|
376 | #endif /* _DF1S */ | |||
|
377 | ||||
|
378 | ||||
|
379 | /* Name status flags */ | |||
|
380 | #define NS 11 /* Index of name status byte in fn[] */ | |||
|
381 | #define NS_LOSS 0x01 /* Out of 8.3 format */ | |||
|
382 | #define NS_LFN 0x02 /* Force to create LFN entry */ | |||
|
383 | #define NS_LAST 0x04 /* Last segment */ | |||
|
384 | #define NS_BODY 0x08 /* Lower case flag (body) */ | |||
|
385 | #define NS_EXT 0x10 /* Lower case flag (ext) */ | |||
|
386 | #define NS_DOT 0x20 /* Dot entry */ | |||
|
387 | ||||
|
388 | ||||
|
389 | /* FAT sub-type boundaries */ | |||
|
390 | /* Note that the FAT spec by Microsoft says 4085 but Windows works with 4087! */ | |||
|
391 | #define MIN_FAT16 4086 /* Minimum number of clusters for FAT16 */ | |||
|
392 | #define MIN_FAT32 65526 /* Minimum number of clusters for FAT32 */ | |||
|
393 | ||||
|
394 | ||||
|
395 | /* FatFs refers the members in the FAT structures as byte array instead of | |||
|
396 | / structure member because the structure is not binary compatible between | |||
|
397 | / different platforms */ | |||
|
398 | ||||
|
399 | #define BS_jmpBoot 0 /* Jump instruction (3) */ | |||
|
400 | #define BS_OEMName 3 /* OEM name (8) */ | |||
|
401 | #define BPB_BytsPerSec 11 /* Sector size [byte] (2) */ | |||
|
402 | #define BPB_SecPerClus 13 /* Cluster size [sector] (1) */ | |||
|
403 | #define BPB_RsvdSecCnt 14 /* Size of reserved area [sector] (2) */ | |||
|
404 | #define BPB_NumFATs 16 /* Number of FAT copies (1) */ | |||
|
405 | #define BPB_RootEntCnt 17 /* Number of root dir entries for FAT12/16 (2) */ | |||
|
406 | #define BPB_TotSec16 19 /* Volume size [sector] (2) */ | |||
|
407 | #define BPB_Media 21 /* Media descriptor (1) */ | |||
|
408 | #define BPB_FATSz16 22 /* FAT size [sector] (2) */ | |||
|
409 | #define BPB_SecPerTrk 24 /* Track size [sector] (2) */ | |||
|
410 | #define BPB_NumHeads 26 /* Number of heads (2) */ | |||
|
411 | #define BPB_HiddSec 28 /* Number of special hidden sectors (4) */ | |||
|
412 | #define BPB_TotSec32 32 /* Volume size [sector] (4) */ | |||
|
413 | #define BS_DrvNum 36 /* Physical drive number (2) */ | |||
|
414 | #define BS_BootSig 38 /* Extended boot signature (1) */ | |||
|
415 | #define BS_VolID 39 /* Volume serial number (4) */ | |||
|
416 | #define BS_VolLab 43 /* Volume label (8) */ | |||
|
417 | #define BS_FilSysType 54 /* File system type (1) */ | |||
|
418 | #define BPB_FATSz32 36 /* FAT size [sector] (4) */ | |||
|
419 | #define BPB_ExtFlags 40 /* Extended flags (2) */ | |||
|
420 | #define BPB_FSVer 42 /* File system version (2) */ | |||
|
421 | #define BPB_RootClus 44 /* Root dir first cluster (4) */ | |||
|
422 | #define BPB_FSInfo 48 /* Offset of FSInfo sector (2) */ | |||
|
423 | #define BPB_BkBootSec 50 /* Offset of backup boot sectot (2) */ | |||
|
424 | #define BS_DrvNum32 64 /* Physical drive number (2) */ | |||
|
425 | #define BS_BootSig32 66 /* Extended boot signature (1) */ | |||
|
426 | #define BS_VolID32 67 /* Volume serial number (4) */ | |||
|
427 | #define BS_VolLab32 71 /* Volume label (8) */ | |||
|
428 | #define BS_FilSysType32 82 /* File system type (1) */ | |||
|
429 | #define FSI_LeadSig 0 /* FSI: Leading signature (4) */ | |||
|
430 | #define FSI_StrucSig 484 /* FSI: Structure signature (4) */ | |||
|
431 | #define FSI_Free_Count 488 /* FSI: Number of free clusters (4) */ | |||
|
432 | #define FSI_Nxt_Free 492 /* FSI: Last allocated cluster (4) */ | |||
|
433 | #define MBR_Table 446 /* MBR: Partition table offset (2) */ | |||
|
434 | #define SZ_PTE 16 /* MBR: Size of a partition table entry */ | |||
|
435 | #define BS_55AA 510 /* Boot sector signature (2) */ | |||
|
436 | ||||
|
437 | #define DIR_Name 0 /* Short file name (11) */ | |||
|
438 | #define DIR_Attr 11 /* Attribute (1) */ | |||
|
439 | #define DIR_NTres 12 /* NT flag (1) */ | |||
|
440 | #define DIR_CrtTime 14 /* Created time (2) */ | |||
|
441 | #define DIR_CrtDate 16 /* Created date (2) */ | |||
|
442 | #define DIR_FstClusHI 20 /* Higher 16-bit of first cluster (2) */ | |||
|
443 | #define DIR_WrtTime 22 /* Modified time (2) */ | |||
|
444 | #define DIR_WrtDate 24 /* Modified date (2) */ | |||
|
445 | #define DIR_FstClusLO 26 /* Lower 16-bit of first cluster (2) */ | |||
|
446 | #define DIR_FileSize 28 /* File size (4) */ | |||
|
447 | #define LDIR_Ord 0 /* LFN entry order and LLE flag (1) */ | |||
|
448 | #define LDIR_Attr 11 /* LFN attribute (1) */ | |||
|
449 | #define LDIR_Type 12 /* LFN type (1) */ | |||
|
450 | #define LDIR_Chksum 13 /* Sum of corresponding SFN entry */ | |||
|
451 | #define LDIR_FstClusLO 26 /* Filled by zero (0) */ | |||
|
452 | #define SZ_DIR 32 /* Size of a directory entry */ | |||
|
453 | #define LLE 0x40 /* Last long entry flag in LDIR_Ord */ | |||
|
454 | #define DDE 0xE5 /* Deleted directory enrty mark in DIR_Name[0] */ | |||
|
455 | #define NDDE 0x05 /* Replacement of a character collides with DDE */ | |||
|
456 | ||||
|
457 | ||||
|
458 | /*------------------------------------------------------------*/ | |||
|
459 | /* Module private work area */ | |||
|
460 | /*------------------------------------------------------------*/ | |||
|
461 | /* Note that uninitialized variables with static duration are | |||
|
462 | / zeroed/nulled at start-up. If not, the compiler or start-up | |||
|
463 | / routine is out of ANSI-C standard. | |||
|
464 | */ | |||
|
465 | ||||
|
466 | #if _VOLUMES | |||
|
467 | static | |||
|
468 | FATFS *FatFs[_VOLUMES]; /* Pointer to the file system objects (logical drives) */ | |||
|
469 | #else | |||
|
470 | #error Number of volumes must not be 0. | |||
|
471 | #endif | |||
|
472 | ||||
|
473 | static | |||
|
474 | WORD Fsid; /* File system mount ID */ | |||
|
475 | ||||
|
476 | #if _FS_RPATH | |||
|
477 | static | |||
|
478 | BYTE CurrVol; /* Current drive */ | |||
|
479 | #endif | |||
|
480 | ||||
|
481 | #if _FS_SHARE | |||
|
482 | static | |||
|
483 | FILESEM Files[_FS_SHARE]; /* File lock semaphores */ | |||
|
484 | #endif | |||
|
485 | ||||
|
486 | #if _USE_LFN == 0 /* No LFN feature */ | |||
|
487 | #define DEF_NAMEBUF BYTE sfn[12] | |||
|
488 | #define INIT_BUF(dobj) (dobj).fn = sfn | |||
|
489 | #define FREE_BUF() | |||
|
490 | ||||
|
491 | #elif _USE_LFN == 1 /* LFN feature with static working buffer */ | |||
|
492 | static WCHAR LfnBuf[_MAX_LFN+1]; | |||
|
493 | #define DEF_NAMEBUF BYTE sfn[12] | |||
|
494 | #define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = LfnBuf; } | |||
|
495 | #define FREE_BUF() | |||
|
496 | ||||
|
497 | #elif _USE_LFN == 2 /* LFN feature with dynamic working buffer on the stack */ | |||
|
498 | #define DEF_NAMEBUF BYTE sfn[12]; WCHAR lbuf[_MAX_LFN+1] | |||
|
499 | #define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = lbuf; } | |||
|
500 | #define FREE_BUF() | |||
|
501 | ||||
|
502 | #elif _USE_LFN == 3 /* LFN feature with dynamic working buffer on the heap */ | |||
|
503 | #define DEF_NAMEBUF BYTE sfn[12]; WCHAR *lfn | |||
|
504 | #define INIT_BUF(dobj) { lfn = ff_memalloc((_MAX_LFN + 1) * 2); \ | |||
|
505 | if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); \ | |||
|
506 | (dobj).lfn = lfn; (dobj).fn = sfn; } | |||
|
507 | #define FREE_BUF() ff_memfree(lfn) | |||
|
508 | ||||
|
509 | #else | |||
|
510 | #error Wrong LFN configuration. | |||
|
511 | #endif | |||
|
512 | ||||
|
513 | ||||
|
514 | ||||
|
515 | ||||
|
516 | /*-------------------------------------------------------------------------- | |||
|
517 | ||||
|
518 | Module Private Functions | |||
|
519 | ||||
|
520 | ---------------------------------------------------------------------------*/ | |||
|
521 | ||||
|
522 | ||||
|
523 | /*-----------------------------------------------------------------------*/ | |||
|
524 | /* String functions */ | |||
|
525 | /*-----------------------------------------------------------------------*/ | |||
|
526 | ||||
|
527 | /* Copy memory to memory */ | |||
|
528 | static | |||
|
529 | void mem_cpy (void* dst, const void* src, UINT cnt) { | |||
|
530 | BYTE *d = (BYTE*)dst; | |||
|
531 | const BYTE *s = (const BYTE*)src; | |||
|
532 | ||||
|
533 | #if _WORD_ACCESS == 1 | |||
|
534 | while (cnt >= sizeof(int)) { | |||
|
535 | *(int*)d = *(int*)s; | |||
|
536 | d += sizeof(int); s += sizeof(int); | |||
|
537 | cnt -= sizeof(int); | |||
|
538 | } | |||
|
539 | #endif | |||
|
540 | while (cnt--) | |||
|
541 | *d++ = *s++; | |||
|
542 | } | |||
|
543 | ||||
|
544 | /* Fill memory */ | |||
|
545 | static | |||
|
546 | void mem_set (void* dst, int val, UINT cnt) { | |||
|
547 | BYTE *d = (BYTE*)dst; | |||
|
548 | ||||
|
549 | while (cnt--) | |||
|
550 | *d++ = (BYTE)val; | |||
|
551 | } | |||
|
552 | ||||
|
553 | /* Compare memory to memory */ | |||
|
554 | static | |||
|
555 | int mem_cmp (const void* dst, const void* src, UINT cnt) { | |||
|
556 | const BYTE *d = (const BYTE *)dst, *s = (const BYTE *)src; | |||
|
557 | int r = 0; | |||
|
558 | ||||
|
559 | while (cnt-- && (r = *d++ - *s++) == 0) ; | |||
|
560 | return r; | |||
|
561 | } | |||
|
562 | ||||
|
563 | /* Check if chr is contained in the string */ | |||
|
564 | static | |||
|
565 | int chk_chr (const char* str, int chr) { | |||
|
566 | while (*str && *str != chr) str++; | |||
|
567 | return *str; | |||
|
568 | } | |||
|
569 | ||||
|
570 | ||||
|
571 | ||||
|
572 | /*-----------------------------------------------------------------------*/ | |||
|
573 | /* Request/Release grant to access the volume */ | |||
|
574 | /*-----------------------------------------------------------------------*/ | |||
|
575 | #if _FS_REENTRANT | |||
|
576 | ||||
|
577 | static | |||
|
578 | int lock_fs ( | |||
|
579 | FATFS *fs /* File system object */ | |||
|
580 | ) | |||
|
581 | { | |||
|
582 | return ff_req_grant(fs->sobj); | |||
|
583 | } | |||
|
584 | ||||
|
585 | ||||
|
586 | static | |||
|
587 | void unlock_fs ( | |||
|
588 | FATFS *fs, /* File system object */ | |||
|
589 | FRESULT res /* Result code to be returned */ | |||
|
590 | ) | |||
|
591 | { | |||
|
592 | if (res != FR_NOT_ENABLED && | |||
|
593 | res != FR_INVALID_DRIVE && | |||
|
594 | res != FR_INVALID_OBJECT && | |||
|
595 | res != FR_TIMEOUT) { | |||
|
596 | ff_rel_grant(fs->sobj); | |||
|
597 | } | |||
|
598 | } | |||
|
599 | #endif | |||
|
600 | ||||
|
601 | ||||
|
602 | ||||
|
603 | /*-----------------------------------------------------------------------*/ | |||
|
604 | /* File shareing control functions */ | |||
|
605 | /*-----------------------------------------------------------------------*/ | |||
|
606 | #if _FS_SHARE | |||
|
607 | ||||
|
608 | static | |||
|
609 | FRESULT chk_lock ( /* Check if the file can be accessed */ | |||
|
610 | DIR* dj, /* Directory object pointing the file to be checked */ | |||
|
611 | int acc /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */ | |||
|
612 | ) | |||
|
613 | { | |||
|
614 | UINT i, be; | |||
|
615 | ||||
|
616 | /* Search file semaphore table */ | |||
|
617 | for (i = be = 0; i < _FS_SHARE; i++) { | |||
|
618 | if (Files[i].fs) { /* Existing entry */ | |||
|
619 | if (Files[i].fs == dj->fs && /* Check if the file matched with an open file */ | |||
|
620 | Files[i].clu == dj->sclust && | |||
|
621 | Files[i].idx == dj->index) break; | |||
|
622 | } else { /* Blank entry */ | |||
|
623 | be++; | |||
|
624 | } | |||
|
625 | } | |||
|
626 | if (i == _FS_SHARE) /* The file is not opened */ | |||
|
627 | return (be || acc == 2) ? FR_OK : FR_TOO_MANY_OPEN_FILES; /* Is there a blank entry for new file? */ | |||
|
628 | ||||
|
629 | /* The file has been opened. Reject any open against writing file and all write mode open */ | |||
|
630 | return (acc || Files[i].ctr == 0x100) ? FR_LOCKED : FR_OK; | |||
|
631 | } | |||
|
632 | ||||
|
633 | ||||
|
634 | static | |||
|
635 | int enq_lock (void) /* Check if an entry is available for a new file */ | |||
|
636 | { | |||
|
637 | UINT i; | |||
|
638 | ||||
|
639 | for (i = 0; i < _FS_SHARE && Files[i].fs; i++) ; | |||
|
640 | return (i == _FS_SHARE) ? 0 : 1; | |||
|
641 | } | |||
|
642 | ||||
|
643 | ||||
|
644 | static | |||
|
645 | UINT inc_lock ( /* Increment file open counter and returns its index (0:int error) */ | |||
|
646 | DIR* dj, /* Directory object pointing the file to register or increment */ | |||
|
647 | int acc /* Desired access mode (0:Read, !0:Write) */ | |||
|
648 | ) | |||
|
649 | { | |||
|
650 | UINT i; | |||
|
651 | ||||
|
652 | ||||
|
653 | for (i = 0; i < _FS_SHARE; i++) { /* Find the file */ | |||
|
654 | if (Files[i].fs == dj->fs && | |||
|
655 | Files[i].clu == dj->sclust && | |||
|
656 | Files[i].idx == dj->index) break; | |||
|
657 | } | |||
|
658 | ||||
|
659 | if (i == _FS_SHARE) { /* Not opened. Register it as new. */ | |||
|
660 | for (i = 0; i < _FS_SHARE && Files[i].fs; i++) ; | |||
|
661 | if (i == _FS_SHARE) return 0; /* No space to register (int err) */ | |||
|
662 | Files[i].fs = dj->fs; | |||
|
663 | Files[i].clu = dj->sclust; | |||
|
664 | Files[i].idx = dj->index; | |||
|
665 | Files[i].ctr = 0; | |||
|
666 | } | |||
|
667 | ||||
|
668 | if (acc && Files[i].ctr) return 0; /* Access violation (int err) */ | |||
|
669 | ||||
|
670 | Files[i].ctr = acc ? 0x100 : Files[i].ctr + 1; /* Set semaphore value */ | |||
|
671 | ||||
|
672 | return i + 1; | |||
|
673 | } | |||
|
674 | ||||
|
675 | ||||
|
676 | static | |||
|
677 | FRESULT dec_lock ( /* Decrement file open counter */ | |||
|
678 | UINT i /* Semaphore index */ | |||
|
679 | ) | |||
|
680 | { | |||
|
681 | WORD n; | |||
|
682 | FRESULT res; | |||
|
683 | ||||
|
684 | ||||
|
685 | if (--i < _FS_SHARE) { | |||
|
686 | n = Files[i].ctr; | |||
|
687 | if (n == 0x100) n = 0; | |||
|
688 | if (n) n--; | |||
|
689 | Files[i].ctr = n; | |||
|
690 | if (!n) Files[i].fs = 0; | |||
|
691 | res = FR_OK; | |||
|
692 | } else { | |||
|
693 | res = FR_INT_ERR; | |||
|
694 | } | |||
|
695 | return res; | |||
|
696 | } | |||
|
697 | ||||
|
698 | ||||
|
699 | static | |||
|
700 | void clear_lock ( /* Clear lock entries of the volume */ | |||
|
701 | FATFS *fs | |||
|
702 | ) | |||
|
703 | { | |||
|
704 | UINT i; | |||
|
705 | ||||
|
706 | for (i = 0; i < _FS_SHARE; i++) { | |||
|
707 | if (Files[i].fs == fs) Files[i].fs = 0; | |||
|
708 | } | |||
|
709 | } | |||
|
710 | #endif | |||
|
711 | ||||
|
712 | ||||
|
713 | ||||
|
714 | /*-----------------------------------------------------------------------*/ | |||
|
715 | /* Change window offset */ | |||
|
716 | /*-----------------------------------------------------------------------*/ | |||
|
717 | ||||
|
718 | static | |||
|
719 | FRESULT move_window ( | |||
|
720 | FATFS *fs, /* File system object */ | |||
|
721 | DWORD sector /* Sector number to make appearance in the fs->win[] */ | |||
|
722 | ) /* Move to zero only writes back dirty window */ | |||
|
723 | { | |||
|
724 | DWORD wsect; | |||
|
725 | ||||
|
726 | ||||
|
727 | wsect = fs->winsect; | |||
|
728 | if (wsect != sector) { /* Changed current window */ | |||
|
729 | #if !_FS_READONLY | |||
|
730 | if (fs->wflag) { /* Write back dirty window if needed */ | |||
|
731 | if (disk_write(fs->drv, fs->win, wsect, 1) != RES_OK) | |||
|
732 | return FR_DISK_ERR; | |||
|
733 | fs->wflag = 0; | |||
|
734 | if (wsect < (fs->fatbase + fs->fsize)) { /* In FAT area */ | |||
|
735 | BYTE nf; | |||
|
736 | for (nf = fs->n_fats; nf > 1; nf--) { /* Reflect the change to all FAT copies */ | |||
|
737 | wsect += fs->fsize; | |||
|
738 | disk_write(fs->drv, fs->win, wsect, 1); | |||
|
739 | } | |||
|
740 | } | |||
|
741 | } | |||
|
742 | #endif | |||
|
743 | if (sector) { | |||
|
744 | if (disk_read(fs->drv, fs->win, sector, 1) != RES_OK) | |||
|
745 | return FR_DISK_ERR; | |||
|
746 | fs->winsect = sector; | |||
|
747 | } | |||
|
748 | } | |||
|
749 | ||||
|
750 | return FR_OK; | |||
|
751 | } | |||
|
752 | ||||
|
753 | ||||
|
754 | ||||
|
755 | ||||
|
756 | /*-----------------------------------------------------------------------*/ | |||
|
757 | /* Clean-up cached data */ | |||
|
758 | /*-----------------------------------------------------------------------*/ | |||
|
759 | #if !_FS_READONLY | |||
|
760 | static | |||
|
761 | FRESULT sync ( /* FR_OK: successful, FR_DISK_ERR: failed */ | |||
|
762 | FATFS *fs /* File system object */ | |||
|
763 | ) | |||
|
764 | { | |||
|
765 | FRESULT res; | |||
|
766 | ||||
|
767 | ||||
|
768 | res = move_window(fs, 0); | |||
|
769 | if (res == FR_OK) { | |||
|
770 | /* Update FSInfo sector if needed */ | |||
|
771 | if (fs->fs_type == FS_FAT32 && fs->fsi_flag) { | |||
|
772 | fs->winsect = 0; | |||
|
773 | /* Create FSInfo structure */ | |||
|
774 | mem_set(fs->win, 0, 512); | |||
|
775 | ST_WORD(fs->win+BS_55AA, 0xAA55); | |||
|
776 | ST_DWORD(fs->win+FSI_LeadSig, 0x41615252); | |||
|
777 | ST_DWORD(fs->win+FSI_StrucSig, 0x61417272); | |||
|
778 | ST_DWORD(fs->win+FSI_Free_Count, fs->free_clust); | |||
|
779 | ST_DWORD(fs->win+FSI_Nxt_Free, fs->last_clust); | |||
|
780 | /* Write it into the FSInfo sector */ | |||
|
781 | disk_write(fs->drv, fs->win, fs->fsi_sector, 1); | |||
|
782 | fs->fsi_flag = 0; | |||
|
783 | } | |||
|
784 | /* Make sure that no pending write process in the physical drive */ | |||
|
785 | if (disk_ioctl(fs->drv, CTRL_SYNC, 0) != RES_OK) | |||
|
786 | res = FR_DISK_ERR; | |||
|
787 | } | |||
|
788 | ||||
|
789 | return res; | |||
|
790 | } | |||
|
791 | #endif | |||
|
792 | ||||
|
793 | ||||
|
794 | ||||
|
795 | ||||
|
796 | /*-----------------------------------------------------------------------*/ | |||
|
797 | /* Get sector# from cluster# */ | |||
|
798 | /*-----------------------------------------------------------------------*/ | |||
|
799 | ||||
|
800 | ||||
|
801 | DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */ | |||
|
802 | FATFS *fs, /* File system object */ | |||
|
803 | DWORD clst /* Cluster# to be converted */ | |||
|
804 | ) | |||
|
805 | { | |||
|
806 | clst -= 2; | |||
|
807 | if (clst >= (fs->n_fatent - 2)) return 0; /* Invalid cluster# */ | |||
|
808 | return clst * fs->csize + fs->database; | |||
|
809 | } | |||
|
810 | ||||
|
811 | ||||
|
812 | ||||
|
813 | ||||
|
814 | /*-----------------------------------------------------------------------*/ | |||
|
815 | /* FAT access - Read value of a FAT entry */ | |||
|
816 | /*-----------------------------------------------------------------------*/ | |||
|
817 | ||||
|
818 | ||||
|
819 | DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, Else:Cluster status */ | |||
|
820 | FATFS *fs, /* File system object */ | |||
|
821 | DWORD clst /* Cluster# to get the link information */ | |||
|
822 | ) | |||
|
823 | { | |||
|
824 | UINT wc, bc; | |||
|
825 | BYTE *p; | |||
|
826 | ||||
|
827 | ||||
|
828 | if (clst < 2 || clst >= fs->n_fatent) /* Chack range */ | |||
|
829 | return 1; | |||
|
830 | ||||
|
831 | switch (fs->fs_type) { | |||
|
832 | case FS_FAT12 : | |||
|
833 | bc = (UINT)clst; bc += bc / 2; | |||
|
834 | if (move_window(fs, fs->fatbase + (bc / SS(fs)))) break; | |||
|
835 | wc = fs->win[bc % SS(fs)]; bc++; | |||
|
836 | if (move_window(fs, fs->fatbase + (bc / SS(fs)))) break; | |||
|
837 | wc |= fs->win[bc % SS(fs)] << 8; | |||
|
838 | return (clst & 1) ? (wc >> 4) : (wc & 0xFFF); | |||
|
839 | ||||
|
840 | case FS_FAT16 : | |||
|
841 | if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 2)))) break; | |||
|
842 | p = &fs->win[clst * 2 % SS(fs)]; | |||
|
843 | return LD_WORD(p); | |||
|
844 | ||||
|
845 | case FS_FAT32 : | |||
|
846 | if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4)))) break; | |||
|
847 | p = &fs->win[clst * 4 % SS(fs)]; | |||
|
848 | return LD_DWORD(p) & 0x0FFFFFFF; | |||
|
849 | } | |||
|
850 | ||||
|
851 | return 0xFFFFFFFF; /* An error occurred at the disk I/O layer */ | |||
|
852 | } | |||
|
853 | ||||
|
854 | ||||
|
855 | ||||
|
856 | ||||
|
857 | /*-----------------------------------------------------------------------*/ | |||
|
858 | /* FAT access - Change value of a FAT entry */ | |||
|
859 | /*-----------------------------------------------------------------------*/ | |||
|
860 | #if !_FS_READONLY | |||
|
861 | ||||
|
862 | FRESULT put_fat ( | |||
|
863 | FATFS *fs, /* File system object */ | |||
|
864 | DWORD clst, /* Cluster# to be changed in range of 2 to fs->n_fatent - 1 */ | |||
|
865 | DWORD val /* New value to mark the cluster */ | |||
|
866 | ) | |||
|
867 | { | |||
|
868 | UINT bc; | |||
|
869 | BYTE *p; | |||
|
870 | FRESULT res; | |||
|
871 | ||||
|
872 | ||||
|
873 | if (clst < 2 || clst >= fs->n_fatent) { /* Check range */ | |||
|
874 | res = FR_INT_ERR; | |||
|
875 | ||||
|
876 | } else { | |||
|
877 | switch (fs->fs_type) { | |||
|
878 | case FS_FAT12 : | |||
|
879 | bc = clst; bc += bc / 2; | |||
|
880 | res = move_window(fs, fs->fatbase + (bc / SS(fs))); | |||
|
881 | if (res != FR_OK) break; | |||
|
882 | p = &fs->win[bc % SS(fs)]; | |||
|
883 | *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; | |||
|
884 | bc++; | |||
|
885 | fs->wflag = 1; | |||
|
886 | res = move_window(fs, fs->fatbase + (bc / SS(fs))); | |||
|
887 | if (res != FR_OK) break; | |||
|
888 | p = &fs->win[bc % SS(fs)]; | |||
|
889 | *p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F)); | |||
|
890 | break; | |||
|
891 | ||||
|
892 | case FS_FAT16 : | |||
|
893 | res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 2))); | |||
|
894 | if (res != FR_OK) break; | |||
|
895 | p = &fs->win[clst * 2 % SS(fs)]; | |||
|
896 | ST_WORD(p, (WORD)val); | |||
|
897 | break; | |||
|
898 | ||||
|
899 | case FS_FAT32 : | |||
|
900 | res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))); | |||
|
901 | if (res != FR_OK) break; | |||
|
902 | p = &fs->win[clst * 4 % SS(fs)]; | |||
|
903 | val |= LD_DWORD(p) & 0xF0000000; | |||
|
904 | ST_DWORD(p, val); | |||
|
905 | break; | |||
|
906 | ||||
|
907 | default : | |||
|
908 | res = FR_INT_ERR; | |||
|
909 | } | |||
|
910 | fs->wflag = 1; | |||
|
911 | } | |||
|
912 | ||||
|
913 | return res; | |||
|
914 | } | |||
|
915 | #endif /* !_FS_READONLY */ | |||
|
916 | ||||
|
917 | ||||
|
918 | ||||
|
919 | ||||
|
920 | /*-----------------------------------------------------------------------*/ | |||
|
921 | /* FAT handling - Remove a cluster chain */ | |||
|
922 | /*-----------------------------------------------------------------------*/ | |||
|
923 | #if !_FS_READONLY | |||
|
924 | static | |||
|
925 | FRESULT remove_chain ( | |||
|
926 | FATFS *fs, /* File system object */ | |||
|
927 | DWORD clst /* Cluster# to remove a chain from */ | |||
|
928 | ) | |||
|
929 | { | |||
|
930 | FRESULT res; | |||
|
931 | DWORD nxt; | |||
|
932 | #if _USE_ERASE | |||
|
933 | DWORD scl = clst, ecl = clst, resion[2]; | |||
|
934 | #endif | |||
|
935 | ||||
|
936 | if (clst < 2 || clst >= fs->n_fatent) { /* Check range */ | |||
|
937 | res = FR_INT_ERR; | |||
|
938 | ||||
|
939 | } else { | |||
|
940 | res = FR_OK; | |||
|
941 | while (clst < fs->n_fatent) { /* Not a last link? */ | |||
|
942 | nxt = get_fat(fs, clst); /* Get cluster status */ | |||
|
943 | if (nxt == 0) break; /* Empty cluster? */ | |||
|
944 | if (nxt == 1) { res = FR_INT_ERR; break; } /* Internal error? */ | |||
|
945 | if (nxt == 0xFFFFFFFF) { res = FR_DISK_ERR; break; } /* Disk error? */ | |||
|
946 | res = put_fat(fs, clst, 0); /* Mark the cluster "empty" */ | |||
|
947 | if (res != FR_OK) break; | |||
|
948 | if (fs->free_clust != 0xFFFFFFFF) { /* Update FSInfo */ | |||
|
949 | fs->free_clust++; | |||
|
950 | fs->fsi_flag = 1; | |||
|
951 | } | |||
|
952 | #if _USE_ERASE | |||
|
953 | if (ecl + 1 == nxt) { /* Next cluster is contiguous */ | |||
|
954 | ecl = nxt; | |||
|
955 | } else { /* End of contiguous clusters */ | |||
|
956 | resion[0] = clust2sect(fs, scl); /* Start sector */ | |||
|
957 | resion[1] = clust2sect(fs, ecl) + fs->csize - 1; /* End sector */ | |||
|
958 | disk_ioctl(fs->drv, CTRL_ERASE_SECTOR, resion); /* Erase the block */ | |||
|
959 | scl = ecl = nxt; | |||
|
960 | } | |||
|
961 | #endif | |||
|
962 | clst = nxt; /* Next cluster */ | |||
|
963 | } | |||
|
964 | } | |||
|
965 | ||||
|
966 | return res; | |||
|
967 | } | |||
|
968 | #endif | |||
|
969 | ||||
|
970 | ||||
|
971 | ||||
|
972 | ||||
|
973 | /*-----------------------------------------------------------------------*/ | |||
|
974 | /* FAT handling - Stretch or Create a cluster chain */ | |||
|
975 | /*-----------------------------------------------------------------------*/ | |||
|
976 | #if !_FS_READONLY | |||
|
977 | static | |||
|
978 | DWORD create_chain ( /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */ | |||
|
979 | FATFS *fs, /* File system object */ | |||
|
980 | DWORD clst /* Cluster# to stretch. 0 means create a new chain. */ | |||
|
981 | ) | |||
|
982 | { | |||
|
983 | DWORD cs, ncl, scl; | |||
|
984 | FRESULT res; | |||
|
985 | ||||
|
986 | ||||
|
987 | if (clst == 0) { /* Create a new chain */ | |||
|
988 | scl = fs->last_clust; /* Get suggested start point */ | |||
|
989 | if (!scl || scl >= fs->n_fatent) scl = 1; | |||
|
990 | } | |||
|
991 | else { /* Stretch the current chain */ | |||
|
992 | cs = get_fat(fs, clst); /* Check the cluster status */ | |||
|
993 | if (cs < 2) return 1; /* It is an invalid cluster */ | |||
|
994 | if (cs < fs->n_fatent) return cs; /* It is already followed by next cluster */ | |||
|
995 | scl = clst; | |||
|
996 | } | |||
|
997 | ||||
|
998 | ncl = scl; /* Start cluster */ | |||
|
999 | for (;;) { | |||
|
1000 | ncl++; /* Next cluster */ | |||
|
1001 | if (ncl >= fs->n_fatent) { /* Wrap around */ | |||
|
1002 | ncl = 2; | |||
|
1003 | if (ncl > scl) return 0; /* No free cluster */ | |||
|
1004 | } | |||
|
1005 | cs = get_fat(fs, ncl); /* Get the cluster status */ | |||
|
1006 | if (cs == 0) break; /* Found a free cluster */ | |||
|
1007 | if (cs == 0xFFFFFFFF || cs == 1)/* An error occurred */ | |||
|
1008 | return cs; | |||
|
1009 | if (ncl == scl) return 0; /* No free cluster */ | |||
|
1010 | } | |||
|
1011 | ||||
|
1012 | res = put_fat(fs, ncl, 0x0FFFFFFF); /* Mark the new cluster "last link" */ | |||
|
1013 | if (res == FR_OK && clst != 0) { | |||
|
1014 | res = put_fat(fs, clst, ncl); /* Link it to the previous one if needed */ | |||
|
1015 | } | |||
|
1016 | if (res == FR_OK) { | |||
|
1017 | fs->last_clust = ncl; /* Update FSINFO */ | |||
|
1018 | if (fs->free_clust != 0xFFFFFFFF) { | |||
|
1019 | fs->free_clust--; | |||
|
1020 | fs->fsi_flag = 1; | |||
|
1021 | } | |||
|
1022 | } else { | |||
|
1023 | ncl = (res == FR_DISK_ERR) ? 0xFFFFFFFF : 1; | |||
|
1024 | } | |||
|
1025 | ||||
|
1026 | return ncl; /* Return new cluster number or error code */ | |||
|
1027 | } | |||
|
1028 | #endif /* !_FS_READONLY */ | |||
|
1029 | ||||
|
1030 | ||||
|
1031 | ||||
|
1032 | /*-----------------------------------------------------------------------*/ | |||
|
1033 | /* FAT handling - Convert offset into cluster with link map table */ | |||
|
1034 | /*-----------------------------------------------------------------------*/ | |||
|
1035 | ||||
|
1036 | #if _USE_FASTSEEK | |||
|
1037 | static | |||
|
1038 | DWORD clmt_clust ( /* <2:Error, >=2:Cluster number */ | |||
|
1039 | FIL* fp, /* Pointer to the file object */ | |||
|
1040 | DWORD ofs /* File offset to be converted to cluster# */ | |||
|
1041 | ) | |||
|
1042 | { | |||
|
1043 | DWORD cl, ncl, *tbl; | |||
|
1044 | ||||
|
1045 | ||||
|
1046 | tbl = fp->cltbl + 1; /* Top of CLMT */ | |||
|
1047 | cl = ofs / SS(fp->fs) / fp->fs->csize; /* Cluster order from top of the file */ | |||
|
1048 | for (;;) { | |||
|
1049 | ncl = *tbl++; /* Number of cluters in the fragment */ | |||
|
1050 | if (!ncl) return 0; /* End of table? (error) */ | |||
|
1051 | if (cl < ncl) break; /* In this fragment? */ | |||
|
1052 | cl -= ncl; tbl++; /* Next fragment */ | |||
|
1053 | } | |||
|
1054 | return cl + *tbl; /* Return the cluster number */ | |||
|
1055 | } | |||
|
1056 | #endif /* _USE_FASTSEEK */ | |||
|
1057 | ||||
|
1058 | ||||
|
1059 | ||||
|
1060 | /*-----------------------------------------------------------------------*/ | |||
|
1061 | /* Directory handling - Set directory index */ | |||
|
1062 | /*-----------------------------------------------------------------------*/ | |||
|
1063 | ||||
|
1064 | static | |||
|
1065 | FRESULT dir_sdi ( | |||
|
1066 | DIR *dj, /* Pointer to directory object */ | |||
|
1067 | WORD idx /* Directory index number */ | |||
|
1068 | ) | |||
|
1069 | { | |||
|
1070 | DWORD clst; | |||
|
1071 | WORD ic; | |||
|
1072 | ||||
|
1073 | ||||
|
1074 | dj->index = idx; | |||
|
1075 | clst = dj->sclust; | |||
|
1076 | if (clst == 1 || clst >= dj->fs->n_fatent) /* Check start cluster range */ | |||
|
1077 | return FR_INT_ERR; | |||
|
1078 | if (!clst && dj->fs->fs_type == FS_FAT32) /* Replace cluster# 0 with root cluster# if in FAT32 */ | |||
|
1079 | clst = dj->fs->dirbase; | |||
|
1080 | ||||
|
1081 | if (clst == 0) { /* Static table (root-dir in FAT12/16) */ | |||
|
1082 | dj->clust = clst; | |||
|
1083 | if (idx >= dj->fs->n_rootdir) /* Index is out of range */ | |||
|
1084 | return FR_INT_ERR; | |||
|
1085 | dj->sect = dj->fs->dirbase + idx / (SS(dj->fs) / SZ_DIR); /* Sector# */ | |||
|
1086 | } | |||
|
1087 | else { /* Dynamic table (sub-dirs or root-dir in FAT32) */ | |||
|
1088 | ic = SS(dj->fs) / SZ_DIR * dj->fs->csize; /* Entries per cluster */ | |||
|
1089 | while (idx >= ic) { /* Follow cluster chain */ | |||
|
1090 | clst = get_fat(dj->fs, clst); /* Get next cluster */ | |||
|
1091 | if (clst == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error */ | |||
|
1092 | if (clst < 2 || clst >= dj->fs->n_fatent) /* Reached to end of table or int error */ | |||
|
1093 | return FR_INT_ERR; | |||
|
1094 | idx -= ic; | |||
|
1095 | } | |||
|
1096 | dj->clust = clst; | |||
|
1097 | dj->sect = clust2sect(dj->fs, clst) + idx / (SS(dj->fs) / SZ_DIR); /* Sector# */ | |||
|
1098 | } | |||
|
1099 | ||||
|
1100 | dj->dir = dj->fs->win + (idx % (SS(dj->fs) / SZ_DIR)) * SZ_DIR; /* Ptr to the entry in the sector */ | |||
|
1101 | ||||
|
1102 | return FR_OK; /* Seek succeeded */ | |||
|
1103 | } | |||
|
1104 | ||||
|
1105 | ||||
|
1106 | ||||
|
1107 | ||||
|
1108 | /*-----------------------------------------------------------------------*/ | |||
|
1109 | /* Directory handling - Move directory index next */ | |||
|
1110 | /*-----------------------------------------------------------------------*/ | |||
|
1111 | ||||
|
1112 | static | |||
|
1113 | FRESULT dir_next ( /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:EOT and could not stretch */ | |||
|
1114 | DIR *dj, /* Pointer to directory object */ | |||
|
1115 | int stretch /* 0: Do not stretch table, 1: Stretch table if needed */ | |||
|
1116 | ) | |||
|
1117 | { | |||
|
1118 | DWORD clst; | |||
|
1119 | WORD i; | |||
|
1120 | ||||
|
1121 | ||||
|
1122 | stretch = stretch; /* To suppress warning on read-only cfg. */ | |||
|
1123 | i = dj->index + 1; | |||
|
1124 | if (!i || !dj->sect) /* Report EOT when index has reached 65535 */ | |||
|
1125 | return FR_NO_FILE; | |||
|
1126 | ||||
|
1127 | if (!(i % (SS(dj->fs) / SZ_DIR))) { /* Sector changed? */ | |||
|
1128 | dj->sect++; /* Next sector */ | |||
|
1129 | ||||
|
1130 | if (dj->clust == 0) { /* Static table */ | |||
|
1131 | if (i >= dj->fs->n_rootdir) /* Report EOT when end of table */ | |||
|
1132 | return FR_NO_FILE; | |||
|
1133 | } | |||
|
1134 | else { /* Dynamic table */ | |||
|
1135 | if (((i / (SS(dj->fs) / SZ_DIR)) & (dj->fs->csize - 1)) == 0) { /* Cluster changed? */ | |||
|
1136 | clst = get_fat(dj->fs, dj->clust); /* Get next cluster */ | |||
|
1137 | if (clst <= 1) return FR_INT_ERR; | |||
|
1138 | if (clst == 0xFFFFFFFF) return FR_DISK_ERR; | |||
|
1139 | if (clst >= dj->fs->n_fatent) { /* When it reached end of dynamic table */ | |||
|
1140 | #if !_FS_READONLY | |||
|
1141 | BYTE c; | |||
|
1142 | if (!stretch) return FR_NO_FILE; /* When do not stretch, report EOT */ | |||
|
1143 | clst = create_chain(dj->fs, dj->clust); /* Stretch cluster chain */ | |||
|
1144 | if (clst == 0) return FR_DENIED; /* No free cluster */ | |||
|
1145 | if (clst == 1) return FR_INT_ERR; | |||
|
1146 | if (clst == 0xFFFFFFFF) return FR_DISK_ERR; | |||
|
1147 | /* Clean-up stretched table */ | |||
|
1148 | if (move_window(dj->fs, 0)) return FR_DISK_ERR; /* Flush active window */ | |||
|
1149 | mem_set(dj->fs->win, 0, SS(dj->fs)); /* Clear window buffer */ | |||
|
1150 | dj->fs->winsect = clust2sect(dj->fs, clst); /* Cluster start sector */ | |||
|
1151 | for (c = 0; c < dj->fs->csize; c++) { /* Fill the new cluster with 0 */ | |||
|
1152 | dj->fs->wflag = 1; | |||
|
1153 | if (move_window(dj->fs, 0)) return FR_DISK_ERR; | |||
|
1154 | dj->fs->winsect++; | |||
|
1155 | } | |||
|
1156 | dj->fs->winsect -= c; /* Rewind window address */ | |||
|
1157 | #else | |||
|
1158 | return FR_NO_FILE; /* Report EOT */ | |||
|
1159 | #endif | |||
|
1160 | } | |||
|
1161 | dj->clust = clst; /* Initialize data for new cluster */ | |||
|
1162 | dj->sect = clust2sect(dj->fs, clst); | |||
|
1163 | } | |||
|
1164 | } | |||
|
1165 | } | |||
|
1166 | ||||
|
1167 | dj->index = i; | |||
|
1168 | dj->dir = dj->fs->win + (i % (SS(dj->fs) / SZ_DIR)) * SZ_DIR; | |||
|
1169 | ||||
|
1170 | return FR_OK; | |||
|
1171 | } | |||
|
1172 | ||||
|
1173 | ||||
|
1174 | ||||
|
1175 | ||||
|
1176 | /*-----------------------------------------------------------------------*/ | |||
|
1177 | /* LFN handling - Test/Pick/Fit an LFN segment from/to directory entry */ | |||
|
1178 | /*-----------------------------------------------------------------------*/ | |||
|
1179 | #if _USE_LFN | |||
|
1180 | static | |||
|
1181 | const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30}; /* Offset of LFN chars in the directory entry */ | |||
|
1182 | ||||
|
1183 | ||||
|
1184 | static | |||
|
1185 | int cmp_lfn ( /* 1:Matched, 0:Not matched */ | |||
|
1186 | WCHAR *lfnbuf, /* Pointer to the LFN to be compared */ | |||
|
1187 | BYTE *dir /* Pointer to the directory entry containing a part of LFN */ | |||
|
1188 | ) | |||
|
1189 | { | |||
|
1190 | UINT i, s; | |||
|
1191 | WCHAR wc, uc; | |||
|
1192 | ||||
|
1193 | ||||
|
1194 | i = ((dir[LDIR_Ord] & ~LLE) - 1) * 13; /* Get offset in the LFN buffer */ | |||
|
1195 | s = 0; wc = 1; | |||
|
1196 | do { | |||
|
1197 | uc = LD_WORD(dir+LfnOfs[s]); /* Pick an LFN character from the entry */ | |||
|
1198 | if (wc) { /* Last char has not been processed */ | |||
|
1199 | wc = ff_wtoupper(uc); /* Convert it to upper case */ | |||
|
1200 | if (i >= _MAX_LFN || wc != ff_wtoupper(lfnbuf[i++])) /* Compare it */ | |||
|
1201 | return 0; /* Not matched */ | |||
|
1202 | } else { | |||
|
1203 | if (uc != 0xFFFF) return 0; /* Check filler */ | |||
|
1204 | } | |||
|
1205 | } while (++s < 13); /* Repeat until all chars in the entry are checked */ | |||
|
1206 | ||||
|
1207 | if ((dir[LDIR_Ord] & LLE) && wc && lfnbuf[i]) /* Last segment matched but different length */ | |||
|
1208 | return 0; | |||
|
1209 | ||||
|
1210 | return 1; /* The part of LFN matched */ | |||
|
1211 | } | |||
|
1212 | ||||
|
1213 | ||||
|
1214 | ||||
|
1215 | static | |||
|
1216 | int pick_lfn ( /* 1:Succeeded, 0:Buffer overflow */ | |||
|
1217 | WCHAR *lfnbuf, /* Pointer to the Unicode-LFN buffer */ | |||
|
1218 | BYTE *dir /* Pointer to the directory entry */ | |||
|
1219 | ) | |||
|
1220 | { | |||
|
1221 | UINT i, s; | |||
|
1222 | WCHAR wc, uc; | |||
|
1223 | ||||
|
1224 | ||||
|
1225 | i = ((dir[LDIR_Ord] & 0x3F) - 1) * 13; /* Offset in the LFN buffer */ | |||
|
1226 | ||||
|
1227 | s = 0; wc = 1; | |||
|
1228 | do { | |||
|
1229 | uc = LD_WORD(dir+LfnOfs[s]); /* Pick an LFN character from the entry */ | |||
|
1230 | if (wc) { /* Last char has not been processed */ | |||
|
1231 | if (i >= _MAX_LFN) return 0; /* Buffer overflow? */ | |||
|
1232 | lfnbuf[i++] = wc = uc; /* Store it */ | |||
|
1233 | } else { | |||
|
1234 | if (uc != 0xFFFF) return 0; /* Check filler */ | |||
|
1235 | } | |||
|
1236 | } while (++s < 13); /* Read all character in the entry */ | |||
|
1237 | ||||
|
1238 | if (dir[LDIR_Ord] & LLE) { /* Put terminator if it is the last LFN part */ | |||
|
1239 | if (i >= _MAX_LFN) return 0; /* Buffer overflow? */ | |||
|
1240 | lfnbuf[i] = 0; | |||
|
1241 | } | |||
|
1242 | ||||
|
1243 | return 1; | |||
|
1244 | } | |||
|
1245 | ||||
|
1246 | ||||
|
1247 | #if !_FS_READONLY | |||
|
1248 | static | |||
|
1249 | void fit_lfn ( | |||
|
1250 | const WCHAR *lfnbuf, /* Pointer to the LFN buffer */ | |||
|
1251 | BYTE *dir, /* Pointer to the directory entry */ | |||
|
1252 | BYTE ord, /* LFN order (1-20) */ | |||
|
1253 | BYTE sum /* SFN sum */ | |||
|
1254 | ) | |||
|
1255 | { | |||
|
1256 | UINT i, s; | |||
|
1257 | WCHAR wc; | |||
|
1258 | ||||
|
1259 | ||||
|
1260 | dir[LDIR_Chksum] = sum; /* Set check sum */ | |||
|
1261 | dir[LDIR_Attr] = AM_LFN; /* Set attribute. LFN entry */ | |||
|
1262 | dir[LDIR_Type] = 0; | |||
|
1263 | ST_WORD(dir+LDIR_FstClusLO, 0); | |||
|
1264 | ||||
|
1265 | i = (ord - 1) * 13; /* Get offset in the LFN buffer */ | |||
|
1266 | s = wc = 0; | |||
|
1267 | do { | |||
|
1268 | if (wc != 0xFFFF) wc = lfnbuf[i++]; /* Get an effective char */ | |||
|
1269 | ST_WORD(dir+LfnOfs[s], wc); /* Put it */ | |||
|
1270 | if (!wc) wc = 0xFFFF; /* Padding chars following last char */ | |||
|
1271 | } while (++s < 13); | |||
|
1272 | if (wc == 0xFFFF || !lfnbuf[i]) ord |= LLE; /* Bottom LFN part is the start of LFN sequence */ | |||
|
1273 | dir[LDIR_Ord] = ord; /* Set the LFN order */ | |||
|
1274 | } | |||
|
1275 | ||||
|
1276 | #endif | |||
|
1277 | #endif | |||
|
1278 | ||||
|
1279 | ||||
|
1280 | ||||
|
1281 | /*-----------------------------------------------------------------------*/ | |||
|
1282 | /* Create numbered name */ | |||
|
1283 | /*-----------------------------------------------------------------------*/ | |||
|
1284 | #if _USE_LFN | |||
|
1285 | void gen_numname ( | |||
|
1286 | BYTE *dst, /* Pointer to generated SFN */ | |||
|
1287 | const BYTE *src, /* Pointer to source SFN to be modified */ | |||
|
1288 | const WCHAR *lfn, /* Pointer to LFN */ | |||
|
1289 | WORD seq /* Sequence number */ | |||
|
1290 | ) | |||
|
1291 | { | |||
|
1292 | BYTE ns[8], c; | |||
|
1293 | UINT i, j; | |||
|
1294 | ||||
|
1295 | ||||
|
1296 | mem_cpy(dst, src, 11); | |||
|
1297 | ||||
|
1298 | if (seq > 5) { /* On many collisions, generate a hash number instead of sequential number */ | |||
|
1299 | do seq = (seq >> 1) + (seq << 15) + (WORD)*lfn++; while (*lfn); | |||
|
1300 | } | |||
|
1301 | ||||
|
1302 | /* itoa (hexdecimal) */ | |||
|
1303 | i = 7; | |||
|
1304 | do { | |||
|
1305 | c = (seq % 16) + '0'; | |||
|
1306 | if (c > '9') c += 7; | |||
|
1307 | ns[i--] = c; | |||
|
1308 | seq /= 16; | |||
|
1309 | } while (seq); | |||
|
1310 | ns[i] = '~'; | |||
|
1311 | ||||
|
1312 | /* Append the number */ | |||
|
1313 | for (j = 0; j < i && dst[j] != ' '; j++) { | |||
|
1314 | if (IsDBCS1(dst[j])) { | |||
|
1315 | if (j == i - 1) break; | |||
|
1316 | j++; | |||
|
1317 | } | |||
|
1318 | } | |||
|
1319 | do { | |||
|
1320 | dst[j++] = (i < 8) ? ns[i++] : ' '; | |||
|
1321 | } while (j < 8); | |||
|
1322 | } | |||
|
1323 | #endif | |||
|
1324 | ||||
|
1325 | ||||
|
1326 | ||||
|
1327 | ||||
|
1328 | /*-----------------------------------------------------------------------*/ | |||
|
1329 | /* Calculate sum of an SFN */ | |||
|
1330 | /*-----------------------------------------------------------------------*/ | |||
|
1331 | #if _USE_LFN | |||
|
1332 | static | |||
|
1333 | BYTE sum_sfn ( | |||
|
1334 | const BYTE *dir /* Ptr to directory entry */ | |||
|
1335 | ) | |||
|
1336 | { | |||
|
1337 | BYTE sum = 0; | |||
|
1338 | UINT n = 11; | |||
|
1339 | ||||
|
1340 | do sum = (sum >> 1) + (sum << 7) + *dir++; while (--n); | |||
|
1341 | return sum; | |||
|
1342 | } | |||
|
1343 | #endif | |||
|
1344 | ||||
|
1345 | ||||
|
1346 | ||||
|
1347 | ||||
|
1348 | /*-----------------------------------------------------------------------*/ | |||
|
1349 | /* Directory handling - Find an object in the directory */ | |||
|
1350 | /*-----------------------------------------------------------------------*/ | |||
|
1351 | ||||
|
1352 | static | |||
|
1353 | FRESULT dir_find ( | |||
|
1354 | DIR *dj /* Pointer to the directory object linked to the file name */ | |||
|
1355 | ) | |||
|
1356 | { | |||
|
1357 | FRESULT res; | |||
|
1358 | BYTE c, *dir; | |||
|
1359 | #if _USE_LFN | |||
|
1360 | BYTE a, ord, sum; | |||
|
1361 | #endif | |||
|
1362 | ||||
|
1363 | res = dir_sdi(dj, 0); /* Rewind directory object */ | |||
|
1364 | if (res != FR_OK) return res; | |||
|
1365 | ||||
|
1366 | #if _USE_LFN | |||
|
1367 | ord = sum = 0xFF; | |||
|
1368 | #endif | |||
|
1369 | do { | |||
|
1370 | res = move_window(dj->fs, dj->sect); | |||
|
1371 | if (res != FR_OK) break; | |||
|
1372 | dir = dj->dir; /* Ptr to the directory entry of current index */ | |||
|
1373 | c = dir[DIR_Name]; | |||
|
1374 | if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ | |||
|
1375 | #if _USE_LFN /* LFN configuration */ | |||
|
1376 | a = dir[DIR_Attr] & AM_MASK; | |||
|
1377 | if (c == DDE || ((a & AM_VOL) && a != AM_LFN)) { /* An entry without valid data */ | |||
|
1378 | ord = 0xFF; | |||
|
1379 | } else { | |||
|
1380 | if (a == AM_LFN) { /* An LFN entry is found */ | |||
|
1381 | if (dj->lfn) { | |||
|
1382 | if (c & LLE) { /* Is it start of LFN sequence? */ | |||
|
1383 | sum = dir[LDIR_Chksum]; | |||
|
1384 | c &= ~LLE; ord = c; /* LFN start order */ | |||
|
1385 | dj->lfn_idx = dj->index; | |||
|
1386 | } | |||
|
1387 | /* Check validity of the LFN entry and compare it with given name */ | |||
|
1388 | ord = (c == ord && sum == dir[LDIR_Chksum] && cmp_lfn(dj->lfn, dir)) ? ord - 1 : 0xFF; | |||
|
1389 | } | |||
|
1390 | } else { /* An SFN entry is found */ | |||
|
1391 | if (!ord && sum == sum_sfn(dir)) break; /* LFN matched? */ | |||
|
1392 | ord = 0xFF; dj->lfn_idx = 0xFFFF; /* Reset LFN sequence */ | |||
|
1393 | if (!(dj->fn[NS] & NS_LOSS) && !mem_cmp(dir, dj->fn, 11)) break; /* SFN matched? */ | |||
|
1394 | } | |||
|
1395 | } | |||
|
1396 | #else /* Non LFN configuration */ | |||
|
1397 | if (!(dir[DIR_Attr] & AM_VOL) && !mem_cmp(dir, dj->fn, 11)) /* Is it a valid entry? */ | |||
|
1398 | break; | |||
|
1399 | #endif | |||
|
1400 | res = dir_next(dj, 0); /* Next entry */ | |||
|
1401 | } while (res == FR_OK); | |||
|
1402 | ||||
|
1403 | return res; | |||
|
1404 | } | |||
|
1405 | ||||
|
1406 | ||||
|
1407 | ||||
|
1408 | ||||
|
1409 | /*-----------------------------------------------------------------------*/ | |||
|
1410 | /* Read an object from the directory */ | |||
|
1411 | /*-----------------------------------------------------------------------*/ | |||
|
1412 | #if _FS_MINIMIZE <= 1 | |||
|
1413 | static | |||
|
1414 | FRESULT dir_read ( | |||
|
1415 | DIR *dj /* Pointer to the directory object that pointing the entry to be read */ | |||
|
1416 | ) | |||
|
1417 | { | |||
|
1418 | FRESULT res; | |||
|
1419 | BYTE c, *dir; | |||
|
1420 | #if _USE_LFN | |||
|
1421 | BYTE a, ord = 0xFF, sum = 0xFF; | |||
|
1422 | #endif | |||
|
1423 | ||||
|
1424 | res = FR_NO_FILE; | |||
|
1425 | while (dj->sect) { | |||
|
1426 | res = move_window(dj->fs, dj->sect); | |||
|
1427 | if (res != FR_OK) break; | |||
|
1428 | dir = dj->dir; /* Ptr to the directory entry of current index */ | |||
|
1429 | c = dir[DIR_Name]; | |||
|
1430 | if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ | |||
|
1431 | #if _USE_LFN /* LFN configuration */ | |||
|
1432 | a = dir[DIR_Attr] & AM_MASK; | |||
|
1433 | if (c == DDE || (!_FS_RPATH && c == '.') || ((a & AM_VOL) && a != AM_LFN)) { /* An entry without valid data */ | |||
|
1434 | ord = 0xFF; | |||
|
1435 | } else { | |||
|
1436 | if (a == AM_LFN) { /* An LFN entry is found */ | |||
|
1437 | if (c & LLE) { /* Is it start of LFN sequence? */ | |||
|
1438 | sum = dir[LDIR_Chksum]; | |||
|
1439 | c &= ~LLE; ord = c; | |||
|
1440 | dj->lfn_idx = dj->index; | |||
|
1441 | } | |||
|
1442 | /* Check LFN validity and capture it */ | |||
|
1443 | ord = (c == ord && sum == dir[LDIR_Chksum] && pick_lfn(dj->lfn, dir)) ? ord - 1 : 0xFF; | |||
|
1444 | } else { /* An SFN entry is found */ | |||
|
1445 | if (ord || sum != sum_sfn(dir)) /* Is there a valid LFN? */ | |||
|
1446 | dj->lfn_idx = 0xFFFF; /* It has no LFN. */ | |||
|
1447 | break; | |||
|
1448 | } | |||
|
1449 | } | |||
|
1450 | #else /* Non LFN configuration */ | |||
|
1451 | if (c != DDE && (_FS_RPATH || c != '.') && !(dir[DIR_Attr] & AM_VOL)) /* Is it a valid entry? */ | |||
|
1452 | break; | |||
|
1453 | #endif | |||
|
1454 | res = dir_next(dj, 0); /* Next entry */ | |||
|
1455 | if (res != FR_OK) break; | |||
|
1456 | } | |||
|
1457 | ||||
|
1458 | if (res != FR_OK) dj->sect = 0; | |||
|
1459 | ||||
|
1460 | return res; | |||
|
1461 | } | |||
|
1462 | #endif | |||
|
1463 | ||||
|
1464 | ||||
|
1465 | ||||
|
1466 | /*-----------------------------------------------------------------------*/ | |||
|
1467 | /* Register an object to the directory */ | |||
|
1468 | /*-----------------------------------------------------------------------*/ | |||
|
1469 | #if !_FS_READONLY | |||
|
1470 | static | |||
|
1471 | FRESULT dir_register ( /* FR_OK:Successful, FR_DENIED:No free entry or too many SFN collision, FR_DISK_ERR:Disk error */ | |||
|
1472 | DIR *dj /* Target directory with object name to be created */ | |||
|
1473 | ) | |||
|
1474 | { | |||
|
1475 | FRESULT res; | |||
|
1476 | BYTE c, *dir; | |||
|
1477 | #if _USE_LFN /* LFN configuration */ | |||
|
1478 | WORD n, ne, is; | |||
|
1479 | BYTE sn[12], *fn, sum; | |||
|
1480 | WCHAR *lfn; | |||
|
1481 | ||||
|
1482 | ||||
|
1483 | fn = dj->fn; lfn = dj->lfn; | |||
|
1484 | mem_cpy(sn, fn, 12); | |||
|
1485 | ||||
|
1486 | if (_FS_RPATH && (sn[NS] & NS_DOT)) /* Cannot create dot entry */ | |||
|
1487 | return FR_INVALID_NAME; | |||
|
1488 | ||||
|
1489 | if (sn[NS] & NS_LOSS) { /* When LFN is out of 8.3 format, generate a numbered name */ | |||
|
1490 | fn[NS] = 0; dj->lfn = 0; /* Find only SFN */ | |||
|
1491 | for (n = 1; n < 100; n++) { | |||
|
1492 | gen_numname(fn, sn, lfn, n); /* Generate a numbered name */ | |||
|
1493 | res = dir_find(dj); /* Check if the name collides with existing SFN */ | |||
|
1494 | if (res != FR_OK) break; | |||
|
1495 | } | |||
|
1496 | if (n == 100) return FR_DENIED; /* Abort if too many collisions */ | |||
|
1497 | if (res != FR_NO_FILE) return res; /* Abort if the result is other than 'not collided' */ | |||
|
1498 | fn[NS] = sn[NS]; dj->lfn = lfn; | |||
|
1499 | } | |||
|
1500 | ||||
|
1501 | if (sn[NS] & NS_LFN) { /* When LFN is to be created, reserve an SFN + LFN entries. */ | |||
|
1502 | for (ne = 0; lfn[ne]; ne++) ; | |||
|
1503 | ne = (ne + 25) / 13; | |||
|
1504 | } else { /* Otherwise reserve only an SFN entry. */ | |||
|
1505 | ne = 1; | |||
|
1506 | } | |||
|
1507 | ||||
|
1508 | /* Reserve contiguous entries */ | |||
|
1509 | res = dir_sdi(dj, 0); | |||
|
1510 | if (res != FR_OK) return res; | |||
|
1511 | n = is = 0; | |||
|
1512 | do { | |||
|
1513 | res = move_window(dj->fs, dj->sect); | |||
|
1514 | if (res != FR_OK) break; | |||
|
1515 | c = *dj->dir; /* Check the entry status */ | |||
|
1516 | if (c == DDE || c == 0) { /* Is it a blank entry? */ | |||
|
1517 | if (n == 0) is = dj->index; /* First index of the contiguous entry */ | |||
|
1518 | if (++n == ne) break; /* A contiguous entry that required count is found */ | |||
|
1519 | } else { | |||
|
1520 | n = 0; /* Not a blank entry. Restart to search */ | |||
|
1521 | } | |||
|
1522 | res = dir_next(dj, 1); /* Next entry with table stretch */ | |||
|
1523 | } while (res == FR_OK); | |||
|
1524 | ||||
|
1525 | if (res == FR_OK && ne > 1) { /* Initialize LFN entry if needed */ | |||
|
1526 | res = dir_sdi(dj, is); | |||
|
1527 | if (res == FR_OK) { | |||
|
1528 | sum = sum_sfn(dj->fn); /* Sum of the SFN tied to the LFN */ | |||
|
1529 | ne--; | |||
|
1530 | do { /* Store LFN entries in bottom first */ | |||
|
1531 | res = move_window(dj->fs, dj->sect); | |||
|
1532 | if (res != FR_OK) break; | |||
|
1533 | fit_lfn(dj->lfn, dj->dir, (BYTE)ne, sum); | |||
|
1534 | dj->fs->wflag = 1; | |||
|
1535 | res = dir_next(dj, 0); /* Next entry */ | |||
|
1536 | } while (res == FR_OK && --ne); | |||
|
1537 | } | |||
|
1538 | } | |||
|
1539 | ||||
|
1540 | #else /* Non LFN configuration */ | |||
|
1541 | res = dir_sdi(dj, 0); | |||
|
1542 | if (res == FR_OK) { | |||
|
1543 | do { /* Find a blank entry for the SFN */ | |||
|
1544 | res = move_window(dj->fs, dj->sect); | |||
|
1545 | if (res != FR_OK) break; | |||
|
1546 | c = *dj->dir; | |||
|
1547 | if (c == DDE || c == 0) break; /* Is it a blank entry? */ | |||
|
1548 | res = dir_next(dj, 1); /* Next entry with table stretch */ | |||
|
1549 | } while (res == FR_OK); | |||
|
1550 | } | |||
|
1551 | #endif | |||
|
1552 | ||||
|
1553 | if (res == FR_OK) { /* Initialize the SFN entry */ | |||
|
1554 | res = move_window(dj->fs, dj->sect); | |||
|
1555 | if (res == FR_OK) { | |||
|
1556 | dir = dj->dir; | |||
|
1557 | mem_set(dir, 0, SZ_DIR); /* Clean the entry */ | |||
|
1558 | mem_cpy(dir, dj->fn, 11); /* Put SFN */ | |||
|
1559 | #if _USE_LFN | |||
|
1560 | dir[DIR_NTres] = *(dj->fn+NS) & (NS_BODY | NS_EXT); /* Put NT flag */ | |||
|
1561 | #endif | |||
|
1562 | dj->fs->wflag = 1; | |||
|
1563 | } | |||
|
1564 | } | |||
|
1565 | ||||
|
1566 | return res; | |||
|
1567 | } | |||
|
1568 | #endif /* !_FS_READONLY */ | |||
|
1569 | ||||
|
1570 | ||||
|
1571 | ||||
|
1572 | ||||
|
1573 | /*-----------------------------------------------------------------------*/ | |||
|
1574 | /* Remove an object from the directory */ | |||
|
1575 | /*-----------------------------------------------------------------------*/ | |||
|
1576 | #if !_FS_READONLY && !_FS_MINIMIZE | |||
|
1577 | static | |||
|
1578 | FRESULT dir_remove ( /* FR_OK: Successful, FR_DISK_ERR: A disk error */ | |||
|
1579 | DIR *dj /* Directory object pointing the entry to be removed */ | |||
|
1580 | ) | |||
|
1581 | { | |||
|
1582 | FRESULT res; | |||
|
1583 | #if _USE_LFN /* LFN configuration */ | |||
|
1584 | WORD i; | |||
|
1585 | ||||
|
1586 | i = dj->index; /* SFN index */ | |||
|
1587 | res = dir_sdi(dj, (WORD)((dj->lfn_idx == 0xFFFF) ? i : dj->lfn_idx)); /* Goto the SFN or top of the LFN entries */ | |||
|
1588 | if (res == FR_OK) { | |||
|
1589 | do { | |||
|
1590 | res = move_window(dj->fs, dj->sect); | |||
|
1591 | if (res != FR_OK) break; | |||
|
1592 | *dj->dir = DDE; /* Mark the entry "deleted" */ | |||
|
1593 | dj->fs->wflag = 1; | |||
|
1594 | if (dj->index >= i) break; /* When reached SFN, all entries of the object has been deleted. */ | |||
|
1595 | res = dir_next(dj, 0); /* Next entry */ | |||
|
1596 | } while (res == FR_OK); | |||
|
1597 | if (res == FR_NO_FILE) res = FR_INT_ERR; | |||
|
1598 | } | |||
|
1599 | ||||
|
1600 | #else /* Non LFN configuration */ | |||
|
1601 | res = dir_sdi(dj, dj->index); | |||
|
1602 | if (res == FR_OK) { | |||
|
1603 | res = move_window(dj->fs, dj->sect); | |||
|
1604 | if (res == FR_OK) { | |||
|
1605 | *dj->dir = DDE; /* Mark the entry "deleted" */ | |||
|
1606 | dj->fs->wflag = 1; | |||
|
1607 | } | |||
|
1608 | } | |||
|
1609 | #endif | |||
|
1610 | ||||
|
1611 | return res; | |||
|
1612 | } | |||
|
1613 | #endif /* !_FS_READONLY */ | |||
|
1614 | ||||
|
1615 | ||||
|
1616 | ||||
|
1617 | ||||
|
1618 | /*-----------------------------------------------------------------------*/ | |||
|
1619 | /* Pick a segment and create the object name in directory form */ | |||
|
1620 | /*-----------------------------------------------------------------------*/ | |||
|
1621 | ||||
|
1622 | static | |||
|
1623 | FRESULT create_name ( | |||
|
1624 | DIR *dj, /* Pointer to the directory object */ | |||
|
1625 | const TCHAR **path /* Pointer to pointer to the segment in the path string */ | |||
|
1626 | ) | |||
|
1627 | { | |||
|
1628 | #ifdef _EXCVT | |||
|
1629 | static const BYTE excvt[] = _EXCVT; /* Upper conversion table for extended chars */ | |||
|
1630 | #endif | |||
|
1631 | ||||
|
1632 | #if _USE_LFN /* LFN configuration */ | |||
|
1633 | BYTE b, cf; | |||
|
1634 | WCHAR w, *lfn; | |||
|
1635 | UINT i, ni, si, di; | |||
|
1636 | const TCHAR *p; | |||
|
1637 | ||||
|
1638 | /* Create LFN in Unicode */ | |||
|
1639 | for (p = *path; *p == '/' || *p == '\\'; p++) ; /* Strip duplicated separator */ | |||
|
1640 | lfn = dj->lfn; | |||
|
1641 | si = di = 0; | |||
|
1642 | for (;;) { | |||
|
1643 | w = p[si++]; /* Get a character */ | |||
|
1644 | if (w < ' ' || w == '/' || w == '\\') break; /* Break on end of segment */ | |||
|
1645 | if (di >= _MAX_LFN) /* Reject too long name */ | |||
|
1646 | return FR_INVALID_NAME; | |||
|
1647 | #if !_LFN_UNICODE | |||
|
1648 | w &= 0xFF; | |||
|
1649 | if (IsDBCS1(w)) { /* Check if it is a DBC 1st byte (always false on SBCS cfg) */ | |||
|
1650 | b = (BYTE)p[si++]; /* Get 2nd byte */ | |||
|
1651 | if (!IsDBCS2(b)) | |||
|
1652 | return FR_INVALID_NAME; /* Reject invalid sequence */ | |||
|
1653 | w = (w << 8) + b; /* Create a DBC */ | |||
|
1654 | } | |||
|
1655 | w = ff_convert(w, 1); /* Convert ANSI/OEM to Unicode */ | |||
|
1656 | if (!w) return FR_INVALID_NAME; /* Reject invalid code */ | |||
|
1657 | #endif | |||
|
1658 | if (w < 0x80 && chk_chr("\"*:<>\?|\x7F", w)) /* Reject illegal chars for LFN */ | |||
|
1659 | return FR_INVALID_NAME; | |||
|
1660 | lfn[di++] = w; /* Store the Unicode char */ | |||
|
1661 | } | |||
|
1662 | *path = &p[si]; /* Return pointer to the next segment */ | |||
|
1663 | cf = (w < ' ') ? NS_LAST : 0; /* Set last segment flag if end of path */ | |||
|
1664 | #if _FS_RPATH | |||
|
1665 | if ((di == 1 && lfn[di-1] == '.') || /* Is this a dot entry? */ | |||
|
1666 | (di == 2 && lfn[di-1] == '.' && lfn[di-2] == '.')) { | |||
|
1667 | lfn[di] = 0; | |||
|
1668 | for (i = 0; i < 11; i++) | |||
|
1669 | dj->fn[i] = (i < di) ? '.' : ' '; | |||
|
1670 | dj->fn[i] = cf | NS_DOT; /* This is a dot entry */ | |||
|
1671 | return FR_OK; | |||
|
1672 | } | |||
|
1673 | #endif | |||
|
1674 | while (di) { /* Strip trailing spaces and dots */ | |||
|
1675 | w = lfn[di-1]; | |||
|
1676 | if (w != ' ' && w != '.') break; | |||
|
1677 | di--; | |||
|
1678 | } | |||
|
1679 | if (!di) return FR_INVALID_NAME; /* Reject nul string */ | |||
|
1680 | ||||
|
1681 | lfn[di] = 0; /* LFN is created */ | |||
|
1682 | ||||
|
1683 | /* Create SFN in directory form */ | |||
|
1684 | mem_set(dj->fn, ' ', 11); | |||
|
1685 | for (si = 0; lfn[si] == ' ' || lfn[si] == '.'; si++) ; /* Strip leading spaces and dots */ | |||
|
1686 | if (si) cf |= NS_LOSS | NS_LFN; | |||
|
1687 | while (di && lfn[di - 1] != '.') di--; /* Find extension (di<=si: no extension) */ | |||
|
1688 | ||||
|
1689 | b = i = 0; ni = 8; | |||
|
1690 | for (;;) { | |||
|
1691 | w = lfn[si++]; /* Get an LFN char */ | |||
|
1692 | if (!w) break; /* Break on end of the LFN */ | |||
|
1693 | if (w == ' ' || (w == '.' && si != di)) { /* Remove spaces and dots */ | |||
|
1694 | cf |= NS_LOSS | NS_LFN; continue; | |||
|
1695 | } | |||
|
1696 | ||||
|
1697 | if (i >= ni || si == di) { /* Extension or end of SFN */ | |||
|
1698 | if (ni == 11) { /* Long extension */ | |||
|
1699 | cf |= NS_LOSS | NS_LFN; break; | |||
|
1700 | } | |||
|
1701 | if (si != di) cf |= NS_LOSS | NS_LFN; /* Out of 8.3 format */ | |||
|
1702 | if (si > di) break; /* No extension */ | |||
|
1703 | si = di; i = 8; ni = 11; /* Enter extension section */ | |||
|
1704 | b <<= 2; continue; | |||
|
1705 | } | |||
|
1706 | ||||
|
1707 | if (w >= 0x80) { /* Non ASCII char */ | |||
|
1708 | #ifdef _EXCVT | |||
|
1709 | w = ff_convert(w, 0); /* Unicode -> OEM code */ | |||
|
1710 | if (w) w = excvt[w - 0x80]; /* Convert extended char to upper (SBCS) */ | |||
|
1711 | #else | |||
|
1712 | w = ff_convert(ff_wtoupper(w), 0); /* Upper converted Unicode -> OEM code */ | |||
|
1713 | #endif | |||
|
1714 | cf |= NS_LFN; /* Force create LFN entry */ | |||
|
1715 | } | |||
|
1716 | ||||
|
1717 | if (_DF1S && w >= 0x100) { /* Double byte char (always false on SBCS cfg) */ | |||
|
1718 | if (i >= ni - 1) { | |||
|
1719 | cf |= NS_LOSS | NS_LFN; i = ni; continue; | |||
|
1720 | } | |||
|
1721 | dj->fn[i++] = (BYTE)(w >> 8); | |||
|
1722 | } else { /* Single byte char */ | |||
|
1723 | if (!w || chk_chr("+,;=[]", w)) { /* Replace illegal chars for SFN */ | |||
|
1724 | w = '_'; cf |= NS_LOSS | NS_LFN;/* Lossy conversion */ | |||
|
1725 | } else { | |||
|
1726 | if (IsUpper(w)) { /* ASCII large capital */ | |||
|
1727 | b |= 2; | |||
|
1728 | } else { | |||
|
1729 | if (IsLower(w)) { /* ASCII small capital */ | |||
|
1730 | b |= 1; w -= 0x20; | |||
|
1731 | } | |||
|
1732 | } | |||
|
1733 | } | |||
|
1734 | } | |||
|
1735 | dj->fn[i++] = (BYTE)w; | |||
|
1736 | } | |||
|
1737 | ||||
|
1738 | if (dj->fn[0] == DDE) dj->fn[0] = NDDE; /* If the first char collides with deleted mark, replace it with 0x05 */ | |||
|
1739 | ||||
|
1740 | if (ni == 8) b <<= 2; | |||
|
1741 | if ((b & 0x0C) == 0x0C || (b & 0x03) == 0x03) /* Create LFN entry when there are composite capitals */ | |||
|
1742 | cf |= NS_LFN; | |||
|
1743 | if (!(cf & NS_LFN)) { /* When LFN is in 8.3 format without extended char, NT flags are created */ | |||
|
1744 | if ((b & 0x03) == 0x01) cf |= NS_EXT; /* NT flag (Extension has only small capital) */ | |||
|
1745 | if ((b & 0x0C) == 0x04) cf |= NS_BODY; /* NT flag (Filename has only small capital) */ | |||
|
1746 | } | |||
|
1747 | ||||
|
1748 | dj->fn[NS] = cf; /* SFN is created */ | |||
|
1749 | ||||
|
1750 | return FR_OK; | |||
|
1751 | ||||
|
1752 | ||||
|
1753 | #else /* Non-LFN configuration */ | |||
|
1754 | BYTE b, c, d, *sfn; | |||
|
1755 | UINT ni, si, i; | |||
|
1756 | const char *p; | |||
|
1757 | ||||
|
1758 | /* Create file name in directory form */ | |||
|
1759 | for (p = *path; *p == '/' || *p == '\\'; p++) ; /* Strip duplicated separator */ | |||
|
1760 | sfn = dj->fn; | |||
|
1761 | mem_set(sfn, ' ', 11); | |||
|
1762 | si = i = b = 0; ni = 8; | |||
|
1763 | #if _FS_RPATH | |||
|
1764 | if (p[si] == '.') { /* Is this a dot entry? */ | |||
|
1765 | for (;;) { | |||
|
1766 | c = (BYTE)p[si++]; | |||
|
1767 | if (c != '.' || si >= 3) break; | |||
|
1768 | sfn[i++] = c; | |||
|
1769 | } | |||
|
1770 | if (c != '/' && c != '\\' && c > ' ') return FR_INVALID_NAME; | |||
|
1771 | *path = &p[si]; /* Return pointer to the next segment */ | |||
|
1772 | sfn[NS] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT; /* Set last segment flag if end of path */ | |||
|
1773 | return FR_OK; | |||
|
1774 | } | |||
|
1775 | #endif | |||
|
1776 | for (;;) { | |||
|
1777 | c = (BYTE)p[si++]; | |||
|
1778 | if (c <= ' ' || c == '/' || c == '\\') break; /* Break on end of segment */ | |||
|
1779 | if (c == '.' || i >= ni) { | |||
|
1780 | if (ni != 8 || c != '.') return FR_INVALID_NAME; | |||
|
1781 | i = 8; ni = 11; | |||
|
1782 | b <<= 2; continue; | |||
|
1783 | } | |||
|
1784 | if (c >= 0x80) { /* Extended char? */ | |||
|
1785 | b |= 3; /* Eliminate NT flag */ | |||
|
1786 | #ifdef _EXCVT | |||
|
1787 | c = excvt[c-0x80]; /* Upper conversion (SBCS) */ | |||
|
1788 | #else | |||
|
1789 | #if !_DF1S /* ASCII only cfg */ | |||
|
1790 | return FR_INVALID_NAME; | |||
|
1791 | #endif | |||
|
1792 | #endif | |||
|
1793 | } | |||
|
1794 | if (IsDBCS1(c)) { /* Check if it is a DBC 1st byte (always false on SBCS cfg) */ | |||
|
1795 | d = (BYTE)p[si++]; /* Get 2nd byte */ | |||
|
1796 | if (!IsDBCS2(d) || i >= ni - 1) /* Reject invalid DBC */ | |||
|
1797 | return FR_INVALID_NAME; | |||
|
1798 | sfn[i++] = c; | |||
|
1799 | sfn[i++] = d; | |||
|
1800 | } else { /* Single byte code */ | |||
|
1801 | if (chk_chr("\"*+,:;<=>\?[]|\x7F", c)) /* Reject illegal chrs for SFN */ | |||
|
1802 | return FR_INVALID_NAME; | |||
|
1803 | if (IsUpper(c)) { /* ASCII large capital? */ | |||
|
1804 | b |= 2; | |||
|
1805 | } else { | |||
|
1806 | if (IsLower(c)) { /* ASCII small capital? */ | |||
|
1807 | b |= 1; c -= 0x20; | |||
|
1808 | } | |||
|
1809 | } | |||
|
1810 | sfn[i++] = c; | |||
|
1811 | } | |||
|
1812 | } | |||
|
1813 | *path = &p[si]; /* Return pointer to the next segment */ | |||
|
1814 | c = (c <= ' ') ? NS_LAST : 0; /* Set last segment flag if end of path */ | |||
|
1815 | ||||
|
1816 | if (!i) return FR_INVALID_NAME; /* Reject nul string */ | |||
|
1817 | if (sfn[0] == DDE) sfn[0] = NDDE; /* When first char collides with DDE, replace it with 0x05 */ | |||
|
1818 | ||||
|
1819 | if (ni == 8) b <<= 2; | |||
|
1820 | if ((b & 0x03) == 0x01) c |= NS_EXT; /* NT flag (Name extension has only small capital) */ | |||
|
1821 | if ((b & 0x0C) == 0x04) c |= NS_BODY; /* NT flag (Name body has only small capital) */ | |||
|
1822 | ||||
|
1823 | sfn[NS] = c; /* Store NT flag, File name is created */ | |||
|
1824 | ||||
|
1825 | return FR_OK; | |||
|
1826 | #endif | |||
|
1827 | } | |||
|
1828 | ||||
|
1829 | ||||
|
1830 | ||||
|
1831 | ||||
|
1832 | /*-----------------------------------------------------------------------*/ | |||
|
1833 | /* Get file information from directory entry */ | |||
|
1834 | /*-----------------------------------------------------------------------*/ | |||
|
1835 | #if _FS_MINIMIZE <= 1 | |||
|
1836 | static | |||
|
1837 | void get_fileinfo ( /* No return code */ | |||
|
1838 | DIR *dj, /* Pointer to the directory object */ | |||
|
1839 | FILINFO *fno /* Pointer to the file information to be filled */ | |||
|
1840 | ) | |||
|
1841 | { | |||
|
1842 | UINT i; | |||
|
1843 | BYTE nt, *dir; | |||
|
1844 | TCHAR *p, c; | |||
|
1845 | ||||
|
1846 | ||||
|
1847 | p = fno->fname; | |||
|
1848 | if (dj->sect) { | |||
|
1849 | dir = dj->dir; | |||
|
1850 | nt = dir[DIR_NTres]; /* NT flag */ | |||
|
1851 | for (i = 0; i < 8; i++) { /* Copy name body */ | |||
|
1852 | c = dir[i]; | |||
|
1853 | if (c == ' ') break; | |||
|
1854 | if (c == NDDE) c = (TCHAR)DDE; | |||
|
1855 | if (_USE_LFN && (nt & NS_BODY) && IsUpper(c)) c += 0x20; | |||
|
1856 | #if _LFN_UNICODE | |||
|
1857 | if (IsDBCS1(c) && i < 7 && IsDBCS2(dir[i+1])) | |||
|
1858 | c = (c << 8) | dir[++i]; | |||
|
1859 | c = ff_convert(c, 1); | |||
|
1860 | if (!c) c = '?'; | |||
|
1861 | #endif | |||
|
1862 | *p++ = c; | |||
|
1863 | } | |||
|
1864 | if (dir[8] != ' ') { /* Copy name extension */ | |||
|
1865 | *p++ = '.'; | |||
|
1866 | for (i = 8; i < 11; i++) { | |||
|
1867 | c = dir[i]; | |||
|
1868 | if (c == ' ') break; | |||
|
1869 | if (_USE_LFN && (nt & NS_EXT) && IsUpper(c)) c += 0x20; | |||
|
1870 | #if _LFN_UNICODE | |||
|
1871 | if (IsDBCS1(c) && i < 10 && IsDBCS2(dir[i+1])) | |||
|
1872 | c = (c << 8) | dir[++i]; | |||
|
1873 | c = ff_convert(c, 1); | |||
|
1874 | if (!c) c = '?'; | |||
|
1875 | #endif | |||
|
1876 | *p++ = c; | |||
|
1877 | } | |||
|
1878 | } | |||
|
1879 | fno->fattrib = dir[DIR_Attr]; /* Attribute */ | |||
|
1880 | fno->fsize = LD_DWORD(dir+DIR_FileSize); /* Size */ | |||
|
1881 | fno->fdate = LD_WORD(dir+DIR_WrtDate); /* Date */ | |||
|
1882 | fno->ftime = LD_WORD(dir+DIR_WrtTime); /* Time */ | |||
|
1883 | } | |||
|
1884 | *p = 0; /* Terminate SFN str by a \0 */ | |||
|
1885 | ||||
|
1886 | #if _USE_LFN | |||
|
1887 | if (fno->lfname && fno->lfsize) { | |||
|
1888 | TCHAR *tp = fno->lfname; | |||
|
1889 | WCHAR w, *lfn; | |||
|
1890 | ||||
|
1891 | i = 0; | |||
|
1892 | if (dj->sect && dj->lfn_idx != 0xFFFF) {/* Get LFN if available */ | |||
|
1893 | lfn = dj->lfn; | |||
|
1894 | while ((w = *lfn++) != 0) { /* Get an LFN char */ | |||
|
1895 | #if !_LFN_UNICODE | |||
|
1896 | w = ff_convert(w, 0); /* Unicode -> OEM conversion */ | |||
|
1897 | if (!w) { i = 0; break; } /* Could not convert, no LFN */ | |||
|
1898 | if (_DF1S && w >= 0x100) /* Put 1st byte if it is a DBC (always false on SBCS cfg) */ | |||
|
1899 | tp[i++] = (TCHAR)(w >> 8); | |||
|
1900 | #endif | |||
|
1901 | if (i >= fno->lfsize - 1) { i = 0; break; } /* Buffer overflow, no LFN */ | |||
|
1902 | tp[i++] = (TCHAR)w; | |||
|
1903 | } | |||
|
1904 | } | |||
|
1905 | tp[i] = 0; /* Terminate the LFN str by a \0 */ | |||
|
1906 | } | |||
|
1907 | #endif | |||
|
1908 | } | |||
|
1909 | #endif /* _FS_MINIMIZE <= 1 */ | |||
|
1910 | ||||
|
1911 | ||||
|
1912 | ||||
|
1913 | ||||
|
1914 | /*-----------------------------------------------------------------------*/ | |||
|
1915 | /* Follow a file path */ | |||
|
1916 | /*-----------------------------------------------------------------------*/ | |||
|
1917 | ||||
|
1918 | static | |||
|
1919 | FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ | |||
|
1920 | DIR *dj, /* Directory object to return last directory and found object */ | |||
|
1921 | const TCHAR *path /* Full-path string to find a file or directory */ | |||
|
1922 | ) | |||
|
1923 | { | |||
|
1924 | FRESULT res; | |||
|
1925 | BYTE *dir, ns; | |||
|
1926 | ||||
|
1927 | ||||
|
1928 | #if _FS_RPATH | |||
|
1929 | if (*path == '/' || *path == '\\') { /* There is a heading separator */ | |||
|
1930 | path++; dj->sclust = 0; /* Strip it and start from the root dir */ | |||
|
1931 | } else { /* No heading separator */ | |||
|
1932 | dj->sclust = dj->fs->cdir; /* Start from the current dir */ | |||
|
1933 | } | |||
|
1934 | #else | |||
|
1935 | if (*path == '/' || *path == '\\') /* Strip heading separator if exist */ | |||
|
1936 | path++; | |||
|
1937 | dj->sclust = 0; /* Start from the root dir */ | |||
|
1938 | #endif | |||
|
1939 | ||||
|
1940 | if ((UINT)*path < ' ') { /* Nul path means the start directory itself */ | |||
|
1941 | res = dir_sdi(dj, 0); | |||
|
1942 | dj->dir = 0; | |||
|
1943 | ||||
|
1944 | } else { /* Follow path */ | |||
|
1945 | for (;;) { | |||
|
1946 | res = create_name(dj, &path); /* Get a segment */ | |||
|
1947 | if (res != FR_OK) break; | |||
|
1948 | res = dir_find(dj); /* Find it */ | |||
|
1949 | ns = *(dj->fn+NS); | |||
|
1950 | if (res != FR_OK) { /* Failed to find the object */ | |||
|
1951 | if (res != FR_NO_FILE) break; /* Abort if any hard error occured */ | |||
|
1952 | /* Object not found */ | |||
|
1953 | if (_FS_RPATH && (ns & NS_DOT)) { /* If dot entry is not exit */ | |||
|
1954 | dj->sclust = 0; dj->dir = 0; /* It is the root dir */ | |||
|
1955 | res = FR_OK; | |||
|
1956 | if (!(ns & NS_LAST)) continue; | |||
|
1957 | } else { /* Could not find the object */ | |||
|
1958 | if (!(ns & NS_LAST)) res = FR_NO_PATH; | |||
|
1959 | } | |||
|
1960 | break; | |||
|
1961 | } | |||
|
1962 | if (ns & NS_LAST) break; /* Last segment match. Function completed. */ | |||
|
1963 | dir = dj->dir; /* There is next segment. Follow the sub directory */ | |||
|
1964 | if (!(dir[DIR_Attr] & AM_DIR)) { /* Cannot follow because it is a file */ | |||
|
1965 | res = FR_NO_PATH; break; | |||
|
1966 | } | |||
|
1967 | dj->sclust = LD_CLUST(dir); | |||
|
1968 | } | |||
|
1969 | } | |||
|
1970 | ||||
|
1971 | return res; | |||
|
1972 | } | |||
|
1973 | ||||
|
1974 | ||||
|
1975 | ||||
|
1976 | ||||
|
1977 | /*-----------------------------------------------------------------------*/ | |||
|
1978 | /* Load a sector and check if it is an FAT Volume Boot Record */ | |||
|
1979 | /*-----------------------------------------------------------------------*/ | |||
|
1980 | ||||
|
1981 | static | |||
|
1982 | BYTE check_fs ( /* 0:FAT-VBR, 1:Valid BR but not FAT, 2:Not a BR, 3:Disk error */ | |||
|
1983 | FATFS *fs, /* File system object */ | |||
|
1984 | DWORD sect /* Sector# (lba) to check if it is an FAT boot record or not */ | |||
|
1985 | ) | |||
|
1986 | { | |||
|
1987 | if (disk_read(fs->drv, fs->win, sect, 1) != RES_OK) /* Load boot record */ | |||
|
1988 | return 3; | |||
|
1989 | if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature (always placed at offset 510 even if the sector size is >512) */ | |||
|
1990 | return 2; | |||
|
1991 | ||||
|
1992 | if ((LD_DWORD(&fs->win[BS_FilSysType]) & 0xFFFFFF) == 0x544146) /* Check "FAT" string */ | |||
|
1993 | return 0; | |||
|
1994 | if ((LD_DWORD(&fs->win[BS_FilSysType32]) & 0xFFFFFF) == 0x544146) | |||
|
1995 | return 0; | |||
|
1996 | ||||
|
1997 | return 1; | |||
|
1998 | } | |||
|
1999 | ||||
|
2000 | ||||
|
2001 | ||||
|
2002 | ||||
|
2003 | /*-----------------------------------------------------------------------*/ | |||
|
2004 | /* Check if the file system object is valid or not */ | |||
|
2005 | /*-----------------------------------------------------------------------*/ | |||
|
2006 | ||||
|
2007 | static | |||
|
2008 | FRESULT chk_mounted ( /* FR_OK(0): successful, !=0: any error occurred */ | |||
|
2009 | const TCHAR **path, /* Pointer to pointer to the path name (drive number) */ | |||
|
2010 | FATFS **rfs, /* Pointer to pointer to the found file system object */ | |||
|
2011 | BYTE chk_wp /* !=0: Check media write protection for write access */ | |||
|
2012 | ) | |||
|
2013 | { | |||
|
2014 | BYTE fmt, b, pi, *tbl; | |||
|
2015 | UINT vol; | |||
|
2016 | DSTATUS stat; | |||
|
2017 | DWORD bsect, fasize, tsect, sysect, nclst, szbfat; | |||
|
2018 | WORD nrsv; | |||
|
2019 | const TCHAR *p = *path; | |||
|
2020 | FATFS *fs; | |||
|
2021 | ||||
|
2022 | /* Get logical drive number from the path name */ | |||
|
2023 | vol = p[0] - '0'; /* Is there a drive number? */ | |||
|
2024 | if (vol <= 9 && p[1] == ':') { /* Found a drive number, get and strip it */ | |||
|
2025 | p += 2; *path = p; /* Return pointer to the path name */ | |||
|
2026 | } else { /* No drive number is given */ | |||
|
2027 | #if _FS_RPATH | |||
|
2028 | vol = CurrVol; /* Use current drive */ | |||
|
2029 | #else | |||
|
2030 | vol = 0; /* Use drive 0 */ | |||
|
2031 | #endif | |||
|
2032 | } | |||
|
2033 | ||||
|
2034 | /* Check if the file system object is valid or not */ | |||
|
2035 | if (vol >= _VOLUMES) /* Is the drive number valid? */ | |||
|
2036 | return FR_INVALID_DRIVE; | |||
|
2037 | *rfs = fs = FatFs[vol]; /* Return pointer to the corresponding file system object */ | |||
|
2038 | if (!fs) return FR_NOT_ENABLED; /* Is the file system object available? */ | |||
|
2039 | ||||
|
2040 | ENTER_FF(fs); /* Lock file system */ | |||
|
2041 | ||||
|
2042 | if (fs->fs_type) { /* If the logical drive has been mounted */ | |||
|
2043 | stat = disk_status(fs->drv); | |||
|
2044 | if (!(stat & STA_NOINIT)) { /* and the physical drive is kept initialized (has not been changed), */ | |||
|
2045 | if (!_FS_READONLY && chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */ | |||
|
2046 | return FR_WRITE_PROTECTED; | |||
|
2047 | return FR_OK; /* The file system object is valid */ | |||
|
2048 | } | |||
|
2049 | } | |||
|
2050 | ||||
|
2051 | /* The file system object is not valid. */ | |||
|
2052 | /* Following code attempts to mount the volume. (analyze BPB and initialize the fs object) */ | |||
|
2053 | ||||
|
2054 | fs->fs_type = 0; /* Clear the file system object */ | |||
|
2055 | fs->drv = LD2PD(vol); /* Bind the logical drive and a physical drive */ | |||
|
2056 | stat = disk_initialize(fs->drv); /* Initialize low level disk I/O layer */ | |||
|
2057 | if (stat & STA_NOINIT) /* Check if the initialization succeeded */ | |||
|
2058 | return FR_NOT_READY; /* Failed to initialize due to no media or hard error */ | |||
|
2059 | if (!_FS_READONLY && chk_wp && (stat & STA_PROTECT)) /* Check disk write protection if needed */ | |||
|
2060 | return FR_WRITE_PROTECTED; | |||
|
2061 | #if _MAX_SS != 512 /* Get disk sector size (variable sector size cfg only) */ | |||
|
2062 | if (disk_ioctl(fs->drv, GET_SECTOR_SIZE, &fs->ssize) != RES_OK) | |||
|
2063 | return FR_DISK_ERR; | |||
|
2064 | #endif | |||
|
2065 | /* Search FAT partition on the drive. Supports only generic partitionings, FDISK and SFD. */ | |||
|
2066 | fmt = check_fs(fs, bsect = 0); /* Load sector 0 and check if it is an FAT-VBR (in SFD) */ | |||
|
2067 | if (LD2PT(vol) && !fmt) fmt = 1; /* Force non-SFD if the volume is forced partition */ | |||
|
2068 | if (fmt == 1) { /* Not an FAT-VBR, the physical drive can be partitioned */ | |||
|
2069 | /* Check the partition listed in the partition table */ | |||
|
2070 | pi = LD2PT(vol); | |||
|
2071 | if (pi) pi--; | |||
|
2072 | tbl = &fs->win[MBR_Table + pi * SZ_PTE];/* Partition table */ | |||
|
2073 | if (tbl[4]) { /* Is the partition existing? */ | |||
|
2074 | bsect = LD_DWORD(&tbl[8]); /* Partition offset in LBA */ | |||
|
2075 | fmt = check_fs(fs, bsect); /* Check the partition */ | |||
|
2076 | } | |||
|
2077 | } | |||
|
2078 | if (fmt == 3) return FR_DISK_ERR; | |||
|
2079 | if (fmt) return FR_NO_FILESYSTEM; /* No FAT volume is found */ | |||
|
2080 | ||||
|
2081 | /* An FAT volume is found. Following code initializes the file system object */ | |||
|
2082 | ||||
|
2083 | if (LD_WORD(fs->win+BPB_BytsPerSec) != SS(fs)) /* (BPB_BytsPerSec must be equal to the physical sector size) */ | |||
|
2084 | return FR_NO_FILESYSTEM; | |||
|
2085 | ||||
|
2086 | fasize = LD_WORD(fs->win+BPB_FATSz16); /* Number of sectors per FAT */ | |||
|
2087 | if (!fasize) fasize = LD_DWORD(fs->win+BPB_FATSz32); | |||
|
2088 | fs->fsize = fasize; | |||
|
2089 | ||||
|
2090 | fs->n_fats = b = fs->win[BPB_NumFATs]; /* Number of FAT copies */ | |||
|
2091 | if (b != 1 && b != 2) return FR_NO_FILESYSTEM; /* (Must be 1 or 2) */ | |||
|
2092 | fasize *= b; /* Number of sectors for FAT area */ | |||
|
2093 | ||||
|
2094 | fs->csize = b = fs->win[BPB_SecPerClus]; /* Number of sectors per cluster */ | |||
|
2095 | if (!b || (b & (b - 1))) return FR_NO_FILESYSTEM; /* (Must be power of 2) */ | |||
|
2096 | ||||
|
2097 | fs->n_rootdir = LD_WORD(fs->win+BPB_RootEntCnt); /* Number of root directory entries */ | |||
|
2098 | if (fs->n_rootdir % (SS(fs) / SZ_DIR)) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must be sector aligned) */ | |||
|
2099 | ||||
|
2100 | tsect = LD_WORD(fs->win+BPB_TotSec16); /* Number of sectors on the volume */ | |||
|
2101 | if (!tsect) tsect = LD_DWORD(fs->win+BPB_TotSec32); | |||
|
2102 | ||||
|
2103 | nrsv = LD_WORD(fs->win+BPB_RsvdSecCnt); /* Number of reserved sectors */ | |||
|
2104 | if (!nrsv) return FR_NO_FILESYSTEM; /* (BPB_RsvdSecCnt must not be 0) */ | |||
|
2105 | ||||
|
2106 | /* Determine the FAT sub type */ | |||
|
2107 | sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZ_DIR); /* RSV+FAT+DIR */ | |||
|
2108 | if (tsect < sysect) return FR_NO_FILESYSTEM; /* (Invalid volume size) */ | |||
|
2109 | nclst = (tsect - sysect) / fs->csize; /* Number of clusters */ | |||
|
2110 | if (!nclst) return FR_NO_FILESYSTEM; /* (Invalid volume size) */ | |||
|
2111 | fmt = FS_FAT12; | |||
|
2112 | if (nclst >= MIN_FAT16) fmt = FS_FAT16; | |||
|
2113 | if (nclst >= MIN_FAT32) fmt = FS_FAT32; | |||
|
2114 | ||||
|
2115 | /* Boundaries and Limits */ | |||
|
2116 | fs->n_fatent = nclst + 2; /* Number of FAT entries */ | |||
|
2117 | fs->database = bsect + sysect; /* Data start sector */ | |||
|
2118 | fs->fatbase = bsect + nrsv; /* FAT start sector */ | |||
|
2119 | if (fmt == FS_FAT32) { | |||
|
2120 | if (fs->n_rootdir) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must be 0) */ | |||
|
2121 | fs->dirbase = LD_DWORD(fs->win+BPB_RootClus); /* Root directory start cluster */ | |||
|
2122 | szbfat = fs->n_fatent * 4; /* (Required FAT size) */ | |||
|
2123 | } else { | |||
|
2124 | if (!fs->n_rootdir) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must not be 0) */ | |||
|
2125 | fs->dirbase = fs->fatbase + fasize; /* Root directory start sector */ | |||
|
2126 | szbfat = (fmt == FS_FAT16) ? /* (Required FAT size) */ | |||
|
2127 | fs->n_fatent * 2 : fs->n_fatent * 3 / 2 + (fs->n_fatent & 1); | |||
|
2128 | } | |||
|
2129 | if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) /* (BPB_FATSz must not be less than required) */ | |||
|
2130 | return FR_NO_FILESYSTEM; | |||
|
2131 | ||||
|
2132 | #if !_FS_READONLY | |||
|
2133 | /* Initialize cluster allocation information */ | |||
|
2134 | fs->free_clust = 0xFFFFFFFF; | |||
|
2135 | fs->last_clust = 0; | |||
|
2136 | ||||
|
2137 | /* Get fsinfo if available */ | |||
|
2138 | if (fmt == FS_FAT32) { | |||
|
2139 | fs->fsi_flag = 0; | |||
|
2140 | fs->fsi_sector = bsect + LD_WORD(fs->win+BPB_FSInfo); | |||
|
2141 | if (disk_read(fs->drv, fs->win, fs->fsi_sector, 1) == RES_OK && | |||
|
2142 | LD_WORD(fs->win+BS_55AA) == 0xAA55 && | |||
|
2143 | LD_DWORD(fs->win+FSI_LeadSig) == 0x41615252 && | |||
|
2144 | LD_DWORD(fs->win+FSI_StrucSig) == 0x61417272) { | |||
|
2145 | fs->last_clust = LD_DWORD(fs->win+FSI_Nxt_Free); | |||
|
2146 | fs->free_clust = LD_DWORD(fs->win+FSI_Free_Count); | |||
|
2147 | } | |||
|
2148 | } | |||
|
2149 | #endif | |||
|
2150 | fs->fs_type = fmt; /* FAT sub-type */ | |||
|
2151 | fs->id = ++Fsid; /* File system mount ID */ | |||
|
2152 | fs->winsect = 0; /* Invalidate sector cache */ | |||
|
2153 | fs->wflag = 0; | |||
|
2154 | #if _FS_RPATH | |||
|
2155 | fs->cdir = 0; /* Current directory (root dir) */ | |||
|
2156 | #endif | |||
|
2157 | #if _FS_SHARE /* Clear file lock semaphores */ | |||
|
2158 | clear_lock(fs); | |||
|
2159 | #endif | |||
|
2160 | ||||
|
2161 | return FR_OK; | |||
|
2162 | } | |||
|
2163 | ||||
|
2164 | ||||
|
2165 | ||||
|
2166 | ||||
|
2167 | /*-----------------------------------------------------------------------*/ | |||
|
2168 | /* Check if the file/dir object is valid or not */ | |||
|
2169 | /*-----------------------------------------------------------------------*/ | |||
|
2170 | ||||
|
2171 | static | |||
|
2172 | FRESULT validate ( /* FR_OK(0): The object is valid, !=0: Invalid */ | |||
|
2173 | FATFS *fs, /* Pointer to the file system object */ | |||
|
2174 | WORD id /* Member id of the target object to be checked */ | |||
|
2175 | ) | |||
|
2176 | { | |||
|
2177 | if (!fs || !fs->fs_type || fs->id != id) | |||
|
2178 | return FR_INVALID_OBJECT; | |||
|
2179 | ||||
|
2180 | ENTER_FF(fs); /* Lock file system */ | |||
|
2181 | ||||
|
2182 | if (disk_status(fs->drv) & STA_NOINIT) | |||
|
2183 | return FR_NOT_READY; | |||
|
2184 | ||||
|
2185 | return FR_OK; | |||
|
2186 | } | |||
|
2187 | ||||
|
2188 | ||||
|
2189 | ||||
|
2190 | ||||
|
2191 | /*-------------------------------------------------------------------------- | |||
|
2192 | ||||
|
2193 | Public Functions | |||
|
2194 | ||||
|
2195 | --------------------------------------------------------------------------*/ | |||
|
2196 | ||||
|
2197 | ||||
|
2198 | ||||
|
2199 | /*-----------------------------------------------------------------------*/ | |||
|
2200 | /* Mount/Unmount a Logical Drive */ | |||
|
2201 | /*-----------------------------------------------------------------------*/ | |||
|
2202 | ||||
|
2203 | FRESULT f_mount ( | |||
|
2204 | BYTE vol, /* Logical drive number to be mounted/unmounted */ | |||
|
2205 | FATFS *fs /* Pointer to new file system object (NULL for unmount)*/ | |||
|
2206 | ) | |||
|
2207 | { | |||
|
2208 | FATFS *rfs; | |||
|
2209 | ||||
|
2210 | ||||
|
2211 | if (vol >= _VOLUMES) /* Check if the drive number is valid */ | |||
|
2212 | return FR_INVALID_DRIVE; | |||
|
2213 | rfs = FatFs[vol]; /* Get current fs object */ | |||
|
2214 | ||||
|
2215 | if (rfs) { | |||
|
2216 | #if _FS_SHARE | |||
|
2217 | clear_lock(rfs); | |||
|
2218 | #endif | |||
|
2219 | #if _FS_REENTRANT /* Discard sync object of the current volume */ | |||
|
2220 | if (!ff_del_syncobj(rfs->sobj)) return FR_INT_ERR; | |||
|
2221 | #endif | |||
|
2222 | rfs->fs_type = 0; /* Clear old fs object */ | |||
|
2223 | } | |||
|
2224 | ||||
|
2225 | if (fs) { | |||
|
2226 | fs->fs_type = 0; /* Clear new fs object */ | |||
|
2227 | #if _FS_REENTRANT /* Create sync object for the new volume */ | |||
|
2228 | if (!ff_cre_syncobj(vol, &fs->sobj)) return FR_INT_ERR; | |||
|
2229 | #endif | |||
|
2230 | } | |||
|
2231 | FatFs[vol] = fs; /* Register new fs object */ | |||
|
2232 | ||||
|
2233 | return FR_OK; | |||
|
2234 | } | |||
|
2235 | ||||
|
2236 | ||||
|
2237 | ||||
|
2238 | ||||
|
2239 | /*-----------------------------------------------------------------------*/ | |||
|
2240 | /* Open or Create a File */ | |||
|
2241 | /*-----------------------------------------------------------------------*/ | |||
|
2242 | ||||
|
2243 | FRESULT f_open ( | |||
|
2244 | FIL *fp, /* Pointer to the blank file object */ | |||
|
2245 | const TCHAR *path, /* Pointer to the file name */ | |||
|
2246 | BYTE mode /* Access mode and file open mode flags */ | |||
|
2247 | ) | |||
|
2248 | { | |||
|
2249 | FRESULT res; | |||
|
2250 | DIR dj; | |||
|
2251 | BYTE *dir; | |||
|
2252 | DEF_NAMEBUF; | |||
|
2253 | ||||
|
2254 | ||||
|
2255 | fp->fs = 0; /* Clear file object */ | |||
|
2256 | ||||
|
2257 | #if !_FS_READONLY | |||
|
2258 | mode &= FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW; | |||
|
2259 | res = chk_mounted(&path, &dj.fs, (BYTE)(mode & ~FA_READ)); | |||
|
2260 | #else | |||
|
2261 | mode &= FA_READ; | |||
|
2262 | res = chk_mounted(&path, &dj.fs, 0); | |||
|
2263 | #endif | |||
|
2264 | INIT_BUF(dj); | |||
|
2265 | if (res == FR_OK) | |||
|
2266 | res = follow_path(&dj, path); /* Follow the file path */ | |||
|
2267 | dir = dj.dir; | |||
|
2268 | ||||
|
2269 | #if !_FS_READONLY /* R/W configuration */ | |||
|
2270 | if (res == FR_OK) { | |||
|
2271 | if (!dir) /* Current dir itself */ | |||
|
2272 | res = FR_INVALID_NAME; | |||
|
2273 | #if _FS_SHARE | |||
|
2274 | else | |||
|
2275 | res = chk_lock(&dj, (mode & ~FA_READ) ? 1 : 0); | |||
|
2276 | #endif | |||
|
2277 | } | |||
|
2278 | /* Create or Open a file */ | |||
|
2279 | if (mode & (FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW)) { | |||
|
2280 | DWORD dw, cl; | |||
|
2281 | ||||
|
2282 | if (res != FR_OK) { /* No file, create new */ | |||
|
2283 | if (res == FR_NO_FILE) /* There is no file to open, create a new entry */ | |||
|
2284 | #if _FS_SHARE | |||
|
2285 | res = enq_lock() ? dir_register(&dj) : FR_TOO_MANY_OPEN_FILES; | |||
|
2286 | #else | |||
|
2287 | res = dir_register(&dj); | |||
|
2288 | #endif | |||
|
2289 | mode |= FA_CREATE_ALWAYS; /* File is created */ | |||
|
2290 | dir = dj.dir; /* New entry */ | |||
|
2291 | } | |||
|
2292 | else { /* Any object is already existing */ | |||
|
2293 | if (dir[DIR_Attr] & (AM_RDO | AM_DIR)) { /* Cannot overwrite it (R/O or DIR) */ | |||
|
2294 | res = FR_DENIED; | |||
|
2295 | } else { | |||
|
2296 | if (mode & FA_CREATE_NEW) /* Cannot create as new file */ | |||
|
2297 | res = FR_EXIST; | |||
|
2298 | } | |||
|
2299 | } | |||
|
2300 | if (res == FR_OK && (mode & FA_CREATE_ALWAYS)) { /* Truncate it if overwrite mode */ | |||
|
2301 | dw = get_fattime(); /* Created time */ | |||
|
2302 | ST_DWORD(dir+DIR_CrtTime, dw); | |||
|
2303 | dir[DIR_Attr] = 0; /* Reset attribute */ | |||
|
2304 | ST_DWORD(dir+DIR_FileSize, 0); /* size = 0 */ | |||
|
2305 | cl = LD_CLUST(dir); /* Get start cluster */ | |||
|
2306 | ST_CLUST(dir, 0); /* cluster = 0 */ | |||
|
2307 | dj.fs->wflag = 1; | |||
|
2308 | if (cl) { /* Remove the cluster chain if exist */ | |||
|
2309 | dw = dj.fs->winsect; | |||
|
2310 | res = remove_chain(dj.fs, cl); | |||
|
2311 | if (res == FR_OK) { | |||
|
2312 | dj.fs->last_clust = cl - 1; /* Reuse the cluster hole */ | |||
|
2313 | res = move_window(dj.fs, dw); | |||
|
2314 | } | |||
|
2315 | } | |||
|
2316 | } | |||
|
2317 | } | |||
|
2318 | else { /* Open an existing file */ | |||
|
2319 | if (res == FR_OK) { /* Follow succeeded */ | |||
|
2320 | if (dir[DIR_Attr] & AM_DIR) { /* It is a directory */ | |||
|
2321 | res = FR_NO_FILE; | |||
|
2322 | } else { | |||
|
2323 | if ((mode & FA_WRITE) && (dir[DIR_Attr] & AM_RDO)) /* R/O violation */ | |||
|
2324 | res = FR_DENIED; | |||
|
2325 | } | |||
|
2326 | } | |||
|
2327 | } | |||
|
2328 | if (res == FR_OK) { | |||
|
2329 | if (mode & FA_CREATE_ALWAYS) /* Set file change flag if created or overwritten */ | |||
|
2330 | mode |= FA__WRITTEN; | |||
|
2331 | fp->dir_sect = dj.fs->winsect; /* Pointer to the directory entry */ | |||
|
2332 | fp->dir_ptr = dir; | |||
|
2333 | #if _FS_SHARE | |||
|
2334 | fp->lockid = inc_lock(&dj, (mode & ~FA_READ) ? 1 : 0); | |||
|
2335 | if (!fp->lockid) res = FR_INT_ERR; | |||
|
2336 | #endif | |||
|
2337 | } | |||
|
2338 | ||||
|
2339 | #else /* R/O configuration */ | |||
|
2340 | if (res == FR_OK) { /* Follow succeeded */ | |||
|
2341 | if (!dir) { /* Current dir itself */ | |||
|
2342 | res = FR_INVALID_NAME; | |||
|
2343 | } else { | |||
|
2344 | if (dir[DIR_Attr] & AM_DIR) /* It is a directory */ | |||
|
2345 | res = FR_NO_FILE; | |||
|
2346 | } | |||
|
2347 | } | |||
|
2348 | #endif | |||
|
2349 | FREE_BUF(); | |||
|
2350 | ||||
|
2351 | if (res == FR_OK) { | |||
|
2352 | fp->flag = mode; /* File access mode */ | |||
|
2353 | fp->sclust = LD_CLUST(dir); /* File start cluster */ | |||
|
2354 | fp->fsize = LD_DWORD(dir+DIR_FileSize); /* File size */ | |||
|
2355 | fp->fptr = 0; /* File pointer */ | |||
|
2356 | fp->dsect = 0; | |||
|
2357 | #if _USE_FASTSEEK | |||
|
2358 | fp->cltbl = 0; /* Normal seek mode */ | |||
|
2359 | #endif | |||
|
2360 | fp->fs = dj.fs; fp->id = dj.fs->id; /* Validate file object */ | |||
|
2361 | } | |||
|
2362 | ||||
|
2363 | LEAVE_FF(dj.fs, res); | |||
|
2364 | } | |||
|
2365 | ||||
|
2366 | ||||
|
2367 | ||||
|
2368 | ||||
|
2369 | /*-----------------------------------------------------------------------*/ | |||
|
2370 | /* Read File */ | |||
|
2371 | /*-----------------------------------------------------------------------*/ | |||
|
2372 | ||||
|
2373 | FRESULT f_read ( | |||
|
2374 | FIL *fp, /* Pointer to the file object */ | |||
|
2375 | void *buff, /* Pointer to data buffer */ | |||
|
2376 | UINT btr, /* Number of bytes to read */ | |||
|
2377 | UINT *br /* Pointer to number of bytes read */ | |||
|
2378 | ) | |||
|
2379 | { | |||
|
2380 | FRESULT res; | |||
|
2381 | DWORD clst, sect, remain; | |||
|
2382 | UINT rcnt, cc; | |||
|
2383 | BYTE csect, *rbuff = buff; | |||
|
2384 | ||||
|
2385 | ||||
|
2386 | *br = 0; /* Initialize byte counter */ | |||
|
2387 | ||||
|
2388 | res = validate(fp->fs, fp->id); /* Check validity */ | |||
|
2389 | if (res != FR_OK) LEAVE_FF(fp->fs, res); | |||
|
2390 | if (fp->flag & FA__ERROR) /* Aborted file? */ | |||
|
2391 | LEAVE_FF(fp->fs, FR_INT_ERR); | |||
|
2392 | if (!(fp->flag & FA_READ)) /* Check access mode */ | |||
|
2393 | LEAVE_FF(fp->fs, FR_DENIED); | |||
|
2394 | remain = fp->fsize - fp->fptr; | |||
|
2395 | if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */ | |||
|
2396 | ||||
|
2397 | for ( ; btr; /* Repeat until all data read */ | |||
|
2398 | rbuff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) { | |||
|
2399 | if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */ | |||
|
2400 | csect = (BYTE)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */ | |||
|
2401 | if (!csect) { /* On the cluster boundary? */ | |||
|
2402 | if (fp->fptr == 0) { /* On the top of the file? */ | |||
|
2403 | clst = fp->sclust; /* Follow from the origin */ | |||
|
2404 | } else { /* Middle or end of the file */ | |||
|
2405 | #if _USE_FASTSEEK | |||
|
2406 | if (fp->cltbl) | |||
|
2407 | clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */ | |||
|
2408 | else | |||
|
2409 | #endif | |||
|
2410 | clst = get_fat(fp->fs, fp->clust); /* Follow cluster chain on the FAT */ | |||
|
2411 | } | |||
|
2412 | if (clst < 2) ABORT(fp->fs, FR_INT_ERR); | |||
|
2413 | if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); | |||
|
2414 | fp->clust = clst; /* Update current cluster */ | |||
|
2415 | } | |||
|
2416 | sect = clust2sect(fp->fs, fp->clust); /* Get current sector */ | |||
|
2417 | if (!sect) ABORT(fp->fs, FR_INT_ERR); | |||
|
2418 | sect += csect; | |||
|
2419 | cc = btr / SS(fp->fs); /* When remaining bytes >= sector size, */ | |||
|
2420 | if (cc) { /* Read maximum contiguous sectors directly */ | |||
|
2421 | if (csect + cc > fp->fs->csize) /* Clip at cluster boundary */ | |||
|
2422 | cc = fp->fs->csize - csect; | |||
|
2423 | if (disk_read(fp->fs->drv, rbuff, sect, (BYTE)cc) != RES_OK) | |||
|
2424 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
2425 | #if !_FS_READONLY && _FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */ | |||
|
2426 | #if _FS_TINY | |||
|
2427 | if (fp->fs->wflag && fp->fs->winsect - sect < cc) | |||
|
2428 | mem_cpy(rbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), fp->fs->win, SS(fp->fs)); | |||
|
2429 | #else | |||
|
2430 | if ((fp->flag & FA__DIRTY) && fp->dsect - sect < cc) | |||
|
2431 | mem_cpy(rbuff + ((fp->dsect - sect) * SS(fp->fs)), fp->buf, SS(fp->fs)); | |||
|
2432 | #endif | |||
|
2433 | #endif | |||
|
2434 | rcnt = SS(fp->fs) * cc; /* Number of bytes transferred */ | |||
|
2435 | continue; | |||
|
2436 | } | |||
|
2437 | #if !_FS_TINY | |||
|
2438 | if (fp->dsect != sect) { /* Load data sector if not in cache */ | |||
|
2439 | #if !_FS_READONLY | |||
|
2440 | if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */ | |||
|
2441 | if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) | |||
|
2442 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
2443 | fp->flag &= ~FA__DIRTY; | |||
|
2444 | } | |||
|
2445 | #endif | |||
|
2446 | if (disk_read(fp->fs->drv, fp->buf, sect, 1) != RES_OK) /* Fill sector cache */ | |||
|
2447 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
2448 | } | |||
|
2449 | #endif | |||
|
2450 | fp->dsect = sect; | |||
|
2451 | } | |||
|
2452 | rcnt = SS(fp->fs) - (fp->fptr % SS(fp->fs)); /* Get partial sector data from sector buffer */ | |||
|
2453 | if (rcnt > btr) rcnt = btr; | |||
|
2454 | #if _FS_TINY | |||
|
2455 | if (move_window(fp->fs, fp->dsect)) /* Move sector window */ | |||
|
2456 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
2457 | mem_cpy(rbuff, &fp->fs->win[fp->fptr % SS(fp->fs)], rcnt); /* Pick partial sector */ | |||
|
2458 | #else | |||
|
2459 | mem_cpy(rbuff, &fp->buf[fp->fptr % SS(fp->fs)], rcnt); /* Pick partial sector */ | |||
|
2460 | #endif | |||
|
2461 | } | |||
|
2462 | ||||
|
2463 | LEAVE_FF(fp->fs, FR_OK); | |||
|
2464 | } | |||
|
2465 | ||||
|
2466 | ||||
|
2467 | ||||
|
2468 | ||||
|
2469 | #if !_FS_READONLY | |||
|
2470 | /*-----------------------------------------------------------------------*/ | |||
|
2471 | /* Write File */ | |||
|
2472 | /*-----------------------------------------------------------------------*/ | |||
|
2473 | ||||
|
2474 | FRESULT f_write ( | |||
|
2475 | FIL *fp, /* Pointer to the file object */ | |||
|
2476 | const void *buff, /* Pointer to the data to be written */ | |||
|
2477 | UINT btw, /* Number of bytes to write */ | |||
|
2478 | UINT *bw /* Pointer to number of bytes written */ | |||
|
2479 | ) | |||
|
2480 | { | |||
|
2481 | FRESULT res; | |||
|
2482 | DWORD clst, sect; | |||
|
2483 | UINT wcnt, cc; | |||
|
2484 | const BYTE *wbuff = buff; | |||
|
2485 | BYTE csect; | |||
|
2486 | ||||
|
2487 | ||||
|
2488 | *bw = 0; /* Initialize byte counter */ | |||
|
2489 | ||||
|
2490 | res = validate(fp->fs, fp->id); /* Check validity */ | |||
|
2491 | if (res != FR_OK) LEAVE_FF(fp->fs, res); | |||
|
2492 | if (fp->flag & FA__ERROR) /* Aborted file? */ | |||
|
2493 | LEAVE_FF(fp->fs, FR_INT_ERR); | |||
|
2494 | if (!(fp->flag & FA_WRITE)) /* Check access mode */ | |||
|
2495 | LEAVE_FF(fp->fs, FR_DENIED); | |||
|
2496 | if ((DWORD)(fp->fsize + btw) < fp->fsize) btw = 0; /* File size cannot reach 4GB */ | |||
|
2497 | ||||
|
2498 | for ( ; btw; /* Repeat until all data written */ | |||
|
2499 | wbuff += wcnt, fp->fptr += wcnt, *bw += wcnt, btw -= wcnt) { | |||
|
2500 | if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */ | |||
|
2501 | csect = (BYTE)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */ | |||
|
2502 | if (!csect) { /* On the cluster boundary? */ | |||
|
2503 | if (fp->fptr == 0) { /* On the top of the file? */ | |||
|
2504 | clst = fp->sclust; /* Follow from the origin */ | |||
|
2505 | if (clst == 0) /* When no cluster is allocated, */ | |||
|
2506 | fp->sclust = clst = create_chain(fp->fs, 0); /* Create a new cluster chain */ | |||
|
2507 | } else { /* Middle or end of the file */ | |||
|
2508 | #if _USE_FASTSEEK | |||
|
2509 | if (fp->cltbl) | |||
|
2510 | clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */ | |||
|
2511 | else | |||
|
2512 | #endif | |||
|
2513 | clst = create_chain(fp->fs, fp->clust); /* Follow or stretch cluster chain on the FAT */ | |||
|
2514 | } | |||
|
2515 | if (clst == 0) break; /* Could not allocate a new cluster (disk full) */ | |||
|
2516 | if (clst == 1) ABORT(fp->fs, FR_INT_ERR); | |||
|
2517 | if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); | |||
|
2518 | fp->clust = clst; /* Update current cluster */ | |||
|
2519 | } | |||
|
2520 | #if _FS_TINY | |||
|
2521 | if (fp->fs->winsect == fp->dsect && move_window(fp->fs, 0)) /* Write-back sector cache */ | |||
|
2522 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
2523 | #else | |||
|
2524 | if (fp->flag & FA__DIRTY) { /* Write-back sector cache */ | |||
|
2525 | if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) | |||
|
2526 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
2527 | fp->flag &= ~FA__DIRTY; | |||
|
2528 | } | |||
|
2529 | #endif | |||
|
2530 | sect = clust2sect(fp->fs, fp->clust); /* Get current sector */ | |||
|
2531 | if (!sect) ABORT(fp->fs, FR_INT_ERR); | |||
|
2532 | sect += csect; | |||
|
2533 | cc = btw / SS(fp->fs); /* When remaining bytes >= sector size, */ | |||
|
2534 | if (cc) { /* Write maximum contiguous sectors directly */ | |||
|
2535 | if (csect + cc > fp->fs->csize) /* Clip at cluster boundary */ | |||
|
2536 | cc = fp->fs->csize - csect; | |||
|
2537 | if (disk_write(fp->fs->drv, wbuff, sect, (BYTE)cc) != RES_OK) | |||
|
2538 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
2539 | #if _FS_TINY | |||
|
2540 | if (fp->fs->winsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */ | |||
|
2541 | mem_cpy(fp->fs->win, wbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), SS(fp->fs)); | |||
|
2542 | fp->fs->wflag = 0; | |||
|
2543 | } | |||
|
2544 | #else | |||
|
2545 | if (fp->dsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */ | |||
|
2546 | mem_cpy(fp->buf, wbuff + ((fp->dsect - sect) * SS(fp->fs)), SS(fp->fs)); | |||
|
2547 | fp->flag &= ~FA__DIRTY; | |||
|
2548 | } | |||
|
2549 | #endif | |||
|
2550 | wcnt = SS(fp->fs) * cc; /* Number of bytes transferred */ | |||
|
2551 | continue; | |||
|
2552 | } | |||
|
2553 | #if _FS_TINY | |||
|
2554 | if (fp->fptr >= fp->fsize) { /* Avoid silly cache filling at growing edge */ | |||
|
2555 | if (move_window(fp->fs, 0)) ABORT(fp->fs, FR_DISK_ERR); | |||
|
2556 | fp->fs->winsect = sect; | |||
|
2557 | } | |||
|
2558 | #else | |||
|
2559 | if (fp->dsect != sect) { /* Fill sector cache with file data */ | |||
|
2560 | if (fp->fptr < fp->fsize && | |||
|
2561 | disk_read(fp->fs->drv, fp->buf, sect, 1) != RES_OK) | |||
|
2562 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
2563 | } | |||
|
2564 | #endif | |||
|
2565 | fp->dsect = sect; | |||
|
2566 | } | |||
|
2567 | wcnt = SS(fp->fs) - (fp->fptr % SS(fp->fs));/* Put partial sector into file I/O buffer */ | |||
|
2568 | if (wcnt > btw) wcnt = btw; | |||
|
2569 | #if _FS_TINY | |||
|
2570 | if (move_window(fp->fs, fp->dsect)) /* Move sector window */ | |||
|
2571 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
2572 | mem_cpy(&fp->fs->win[fp->fptr % SS(fp->fs)], wbuff, wcnt); /* Fit partial sector */ | |||
|
2573 | fp->fs->wflag = 1; | |||
|
2574 | #else | |||
|
2575 | mem_cpy(&fp->buf[fp->fptr % SS(fp->fs)], wbuff, wcnt); /* Fit partial sector */ | |||
|
2576 | fp->flag |= FA__DIRTY; | |||
|
2577 | #endif | |||
|
2578 | } | |||
|
2579 | ||||
|
2580 | if (fp->fptr > fp->fsize) fp->fsize = fp->fptr; /* Update file size if needed */ | |||
|
2581 | fp->flag |= FA__WRITTEN; /* Set file change flag */ | |||
|
2582 | ||||
|
2583 | LEAVE_FF(fp->fs, FR_OK); | |||
|
2584 | } | |||
|
2585 | ||||
|
2586 | ||||
|
2587 | ||||
|
2588 | ||||
|
2589 | /*-----------------------------------------------------------------------*/ | |||
|
2590 | /* Synchronize the File Object */ | |||
|
2591 | /*-----------------------------------------------------------------------*/ | |||
|
2592 | ||||
|
2593 | FRESULT f_sync ( | |||
|
2594 | FIL *fp /* Pointer to the file object */ | |||
|
2595 | ) | |||
|
2596 | { | |||
|
2597 | FRESULT res; | |||
|
2598 | DWORD tim; | |||
|
2599 | BYTE *dir; | |||
|
2600 | ||||
|
2601 | ||||
|
2602 | res = validate(fp->fs, fp->id); /* Check validity of the object */ | |||
|
2603 | if (res == FR_OK) { | |||
|
2604 | if (fp->flag & FA__WRITTEN) { /* Has the file been written? */ | |||
|
2605 | #if !_FS_TINY /* Write-back dirty buffer */ | |||
|
2606 | if (fp->flag & FA__DIRTY) { | |||
|
2607 | if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) | |||
|
2608 | LEAVE_FF(fp->fs, FR_DISK_ERR); | |||
|
2609 | fp->flag &= ~FA__DIRTY; | |||
|
2610 | } | |||
|
2611 | #endif | |||
|
2612 | /* Update the directory entry */ | |||
|
2613 | res = move_window(fp->fs, fp->dir_sect); | |||
|
2614 | if (res == FR_OK) { | |||
|
2615 | dir = fp->dir_ptr; | |||
|
2616 | dir[DIR_Attr] |= AM_ARC; /* Set archive bit */ | |||
|
2617 | ST_DWORD(dir+DIR_FileSize, fp->fsize); /* Update file size */ | |||
|
2618 | ST_CLUST(dir, fp->sclust); /* Update start cluster */ | |||
|
2619 | tim = get_fattime(); /* Update updated time */ | |||
|
2620 | ST_DWORD(dir+DIR_WrtTime, tim); | |||
|
2621 | fp->flag &= ~FA__WRITTEN; | |||
|
2622 | fp->fs->wflag = 1; | |||
|
2623 | res = sync(fp->fs); | |||
|
2624 | } | |||
|
2625 | } | |||
|
2626 | } | |||
|
2627 | ||||
|
2628 | LEAVE_FF(fp->fs, res); | |||
|
2629 | } | |||
|
2630 | ||||
|
2631 | #endif /* !_FS_READONLY */ | |||
|
2632 | ||||
|
2633 | ||||
|
2634 | ||||
|
2635 | ||||
|
2636 | /*-----------------------------------------------------------------------*/ | |||
|
2637 | /* Close File */ | |||
|
2638 | /*-----------------------------------------------------------------------*/ | |||
|
2639 | ||||
|
2640 | FRESULT f_close ( | |||
|
2641 | FIL *fp /* Pointer to the file object to be closed */ | |||
|
2642 | ) | |||
|
2643 | { | |||
|
2644 | FRESULT res; | |||
|
2645 | ||||
|
2646 | #if _FS_READONLY | |||
|
2647 | FATFS *fs = fp->fs; | |||
|
2648 | res = validate(fs, fp->id); | |||
|
2649 | if (res == FR_OK) fp->fs = 0; /* Discard file object */ | |||
|
2650 | LEAVE_FF(fs, res); | |||
|
2651 | ||||
|
2652 | #else | |||
|
2653 | res = f_sync(fp); /* Flush cached data */ | |||
|
2654 | #if _FS_SHARE | |||
|
2655 | if (res == FR_OK) { /* Decrement open counter */ | |||
|
2656 | #if _FS_REENTRANT | |||
|
2657 | res = validate(fp->fs, fp->id); | |||
|
2658 | if (res == FR_OK) { | |||
|
2659 | res = dec_lock(fp->lockid); | |||
|
2660 | unlock_fs(fp->fs, FR_OK); | |||
|
2661 | } | |||
|
2662 | #else | |||
|
2663 | res = dec_lock(fp->lockid); | |||
|
2664 | #endif | |||
|
2665 | } | |||
|
2666 | #endif | |||
|
2667 | if (res == FR_OK) fp->fs = 0; /* Discard file object */ | |||
|
2668 | return res; | |||
|
2669 | #endif | |||
|
2670 | } | |||
|
2671 | ||||
|
2672 | ||||
|
2673 | ||||
|
2674 | ||||
|
2675 | /*-----------------------------------------------------------------------*/ | |||
|
2676 | /* Current Drive/Directory Handlings */ | |||
|
2677 | /*-----------------------------------------------------------------------*/ | |||
|
2678 | ||||
|
2679 | #if _FS_RPATH >= 1 | |||
|
2680 | ||||
|
2681 | FRESULT f_chdrive ( | |||
|
2682 | BYTE drv /* Drive number */ | |||
|
2683 | ) | |||
|
2684 | { | |||
|
2685 | if (drv >= _VOLUMES) return FR_INVALID_DRIVE; | |||
|
2686 | ||||
|
2687 | CurrVol = drv; | |||
|
2688 | ||||
|
2689 | return FR_OK; | |||
|
2690 | } | |||
|
2691 | ||||
|
2692 | ||||
|
2693 | ||||
|
2694 | FRESULT f_chdir ( | |||
|
2695 | const TCHAR *path /* Pointer to the directory path */ | |||
|
2696 | ) | |||
|
2697 | { | |||
|
2698 | FRESULT res; | |||
|
2699 | DIR dj; | |||
|
2700 | DEF_NAMEBUF; | |||
|
2701 | ||||
|
2702 | ||||
|
2703 | res = chk_mounted(&path, &dj.fs, 0); | |||
|
2704 | if (res == FR_OK) { | |||
|
2705 | INIT_BUF(dj); | |||
|
2706 | res = follow_path(&dj, path); /* Follow the path */ | |||
|
2707 | FREE_BUF(); | |||
|
2708 | if (res == FR_OK) { /* Follow completed */ | |||
|
2709 | if (!dj.dir) { | |||
|
2710 | dj.fs->cdir = dj.sclust; /* Start directory itself */ | |||
|
2711 | } else { | |||
|
2712 | if (dj.dir[DIR_Attr] & AM_DIR) /* Reached to the directory */ | |||
|
2713 | dj.fs->cdir = LD_CLUST(dj.dir); | |||
|
2714 | else | |||
|
2715 | res = FR_NO_PATH; /* Reached but a file */ | |||
|
2716 | } | |||
|
2717 | } | |||
|
2718 | if (res == FR_NO_FILE) res = FR_NO_PATH; | |||
|
2719 | } | |||
|
2720 | ||||
|
2721 | LEAVE_FF(dj.fs, res); | |||
|
2722 | } | |||
|
2723 | ||||
|
2724 | ||||
|
2725 | #if _FS_RPATH >= 2 | |||
|
2726 | FRESULT f_getcwd ( | |||
|
2727 | TCHAR *path, /* Pointer to the directory path */ | |||
|
2728 | UINT sz_path /* Size of path */ | |||
|
2729 | ) | |||
|
2730 | { | |||
|
2731 | FRESULT res; | |||
|
2732 | DIR dj; | |||
|
2733 | UINT i, n; | |||
|
2734 | DWORD ccl; | |||
|
2735 | TCHAR *tp; | |||
|
2736 | FILINFO fno; | |||
|
2737 | DEF_NAMEBUF; | |||
|
2738 | ||||
|
2739 | ||||
|
2740 | *path = 0; | |||
|
2741 | res = chk_mounted((const TCHAR**)&path, &dj.fs, 0); /* Get current volume */ | |||
|
2742 | if (res == FR_OK) { | |||
|
2743 | INIT_BUF(dj); | |||
|
2744 | i = sz_path; /* Bottom of buffer (dir stack base) */ | |||
|
2745 | dj.sclust = dj.fs->cdir; /* Start to follow upper dir from current dir */ | |||
|
2746 | while ((ccl = dj.sclust) != 0) { /* Repeat while current dir is a sub-dir */ | |||
|
2747 | res = dir_sdi(&dj, 1); /* Get parent dir */ | |||
|
2748 | if (res != FR_OK) break; | |||
|
2749 | res = dir_read(&dj); | |||
|
2750 | if (res != FR_OK) break; | |||
|
2751 | dj.sclust = LD_CLUST(dj.dir); /* Goto parent dir */ | |||
|
2752 | res = dir_sdi(&dj, 0); | |||
|
2753 | if (res != FR_OK) break; | |||
|
2754 | do { /* Find the entry links to the child dir */ | |||
|
2755 | res = dir_read(&dj); | |||
|
2756 | if (res != FR_OK) break; | |||
|
2757 | if (ccl == LD_CLUST(dj.dir)) break; /* Found the entry */ | |||
|
2758 | res = dir_next(&dj, 0); | |||
|
2759 | } while (res == FR_OK); | |||
|
2760 | if (res == FR_NO_FILE) res = FR_INT_ERR;/* It cannot be 'not found'. */ | |||
|
2761 | if (res != FR_OK) break; | |||
|
2762 | #if _USE_LFN | |||
|
2763 | fno.lfname = path; | |||
|
2764 | fno.lfsize = i; | |||
|
2765 | #endif | |||
|
2766 | get_fileinfo(&dj, &fno); /* Get the dir name and push it to the buffer */ | |||
|
2767 | tp = fno.fname; | |||
|
2768 | if (_USE_LFN && *path) tp = path; | |||
|
2769 | for (n = 0; tp[n]; n++) ; | |||
|
2770 | if (i < n + 3) { | |||
|
2771 | res = FR_NOT_ENOUGH_CORE; break; | |||
|
2772 | } | |||
|
2773 | while (n) path[--i] = tp[--n]; | |||
|
2774 | path[--i] = '/'; | |||
|
2775 | } | |||
|
2776 | tp = path; | |||
|
2777 | if (res == FR_OK) { | |||
|
2778 | *tp++ = '0' + CurrVol; /* Put drive number */ | |||
|
2779 | *tp++ = ':'; | |||
|
2780 | if (i == sz_path) { /* Root-dir */ | |||
|
2781 | *tp++ = '/'; | |||
|
2782 | } else { /* Sub-dir */ | |||
|
2783 | do /* Add stacked path str */ | |||
|
2784 | *tp++ = path[i++]; | |||
|
2785 | while (i < sz_path); | |||
|
2786 | } | |||
|
2787 | } | |||
|
2788 | *tp = 0; | |||
|
2789 | FREE_BUF(); | |||
|
2790 | } | |||
|
2791 | ||||
|
2792 | LEAVE_FF(dj.fs, res); | |||
|
2793 | } | |||
|
2794 | #endif /* _FS_RPATH >= 2 */ | |||
|
2795 | #endif /* _FS_RPATH >= 1 */ | |||
|
2796 | ||||
|
2797 | ||||
|
2798 | ||||
|
2799 | #if _FS_MINIMIZE <= 2 | |||
|
2800 | /*-----------------------------------------------------------------------*/ | |||
|
2801 | /* Seek File R/W Pointer */ | |||
|
2802 | /*-----------------------------------------------------------------------*/ | |||
|
2803 | ||||
|
2804 | FRESULT f_lseek ( | |||
|
2805 | FIL *fp, /* Pointer to the file object */ | |||
|
2806 | DWORD ofs /* File pointer from top of file */ | |||
|
2807 | ) | |||
|
2808 | { | |||
|
2809 | FRESULT res; | |||
|
2810 | ||||
|
2811 | ||||
|
2812 | res = validate(fp->fs, fp->id); /* Check validity of the object */ | |||
|
2813 | if (res != FR_OK) LEAVE_FF(fp->fs, res); | |||
|
2814 | if (fp->flag & FA__ERROR) /* Check abort flag */ | |||
|
2815 | LEAVE_FF(fp->fs, FR_INT_ERR); | |||
|
2816 | ||||
|
2817 | #if _USE_FASTSEEK | |||
|
2818 | if (fp->cltbl) { /* Fast seek */ | |||
|
2819 | DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl; | |||
|
2820 | ||||
|
2821 | if (ofs == CREATE_LINKMAP) { /* Create CLMT */ | |||
|
2822 | tbl = fp->cltbl; | |||
|
2823 | tlen = *tbl++; ulen = 2; /* Given table size and required table size */ | |||
|
2824 | cl = fp->sclust; /* Top of the chain */ | |||
|
2825 | if (cl) { | |||
|
2826 | do { | |||
|
2827 | /* Get a fragment */ | |||
|
2828 | tcl = cl; ncl = 0; ulen += 2; /* Top, length and used items */ | |||
|
2829 | do { | |||
|
2830 | pcl = cl; ncl++; | |||
|
2831 | cl = get_fat(fp->fs, cl); | |||
|
2832 | if (cl <= 1) ABORT(fp->fs, FR_INT_ERR); | |||
|
2833 | if (cl == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); | |||
|
2834 | } while (cl == pcl + 1); | |||
|
2835 | if (ulen <= tlen) { /* Store the length and top of the fragment */ | |||
|
2836 | *tbl++ = ncl; *tbl++ = tcl; | |||
|
2837 | } | |||
|
2838 | } while (cl < fp->fs->n_fatent); /* Repeat until end of chain */ | |||
|
2839 | } | |||
|
2840 | *fp->cltbl = ulen; /* Number of items used */ | |||
|
2841 | if (ulen <= tlen) | |||
|
2842 | *tbl = 0; /* Terminate table */ | |||
|
2843 | else | |||
|
2844 | res = FR_NOT_ENOUGH_CORE; /* Given table size is smaller than required */ | |||
|
2845 | ||||
|
2846 | } else { /* Fast seek */ | |||
|
2847 | if (ofs > fp->fsize) /* Clip offset at the file size */ | |||
|
2848 | ofs = fp->fsize; | |||
|
2849 | fp->fptr = ofs; /* Set file pointer */ | |||
|
2850 | if (ofs) { | |||
|
2851 | fp->clust = clmt_clust(fp, ofs - 1); | |||
|
2852 | dsc = clust2sect(fp->fs, fp->clust); | |||
|
2853 | if (!dsc) ABORT(fp->fs, FR_INT_ERR); | |||
|
2854 | dsc += (ofs - 1) / SS(fp->fs) & (fp->fs->csize - 1); | |||
|
2855 | if (fp->fptr % SS(fp->fs) && dsc != fp->dsect) { /* Refill sector cache if needed */ | |||
|
2856 | #if !_FS_TINY | |||
|
2857 | #if !_FS_READONLY | |||
|
2858 | if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */ | |||
|
2859 | if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) | |||
|
2860 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
2861 | fp->flag &= ~FA__DIRTY; | |||
|
2862 | } | |||
|
2863 | #endif | |||
|
2864 | if (disk_read(fp->fs->drv, fp->buf, dsc, 1) != RES_OK) /* Load current sector */ | |||
|
2865 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
2866 | #endif | |||
|
2867 | fp->dsect = dsc; | |||
|
2868 | } | |||
|
2869 | } | |||
|
2870 | } | |||
|
2871 | } else | |||
|
2872 | #endif | |||
|
2873 | ||||
|
2874 | /* Normal Seek */ | |||
|
2875 | { | |||
|
2876 | DWORD clst, bcs, nsect, ifptr; | |||
|
2877 | ||||
|
2878 | if (ofs > fp->fsize /* In read-only mode, clip offset with the file size */ | |||
|
2879 | #if !_FS_READONLY | |||
|
2880 | && !(fp->flag & FA_WRITE) | |||
|
2881 | #endif | |||
|
2882 | ) ofs = fp->fsize; | |||
|
2883 | ||||
|
2884 | ifptr = fp->fptr; | |||
|
2885 | fp->fptr = nsect = 0; | |||
|
2886 | if (ofs) { | |||
|
2887 | bcs = (DWORD)fp->fs->csize * SS(fp->fs); /* Cluster size (byte) */ | |||
|
2888 | if (ifptr > 0 && | |||
|
2889 | (ofs - 1) / bcs >= (ifptr - 1) / bcs) { /* When seek to same or following cluster, */ | |||
|
2890 | fp->fptr = (ifptr - 1) & ~(bcs - 1); /* start from the current cluster */ | |||
|
2891 | ofs -= fp->fptr; | |||
|
2892 | clst = fp->clust; | |||
|
2893 | } else { /* When seek to back cluster, */ | |||
|
2894 | clst = fp->sclust; /* start from the first cluster */ | |||
|
2895 | #if !_FS_READONLY | |||
|
2896 | if (clst == 0) { /* If no cluster chain, create a new chain */ | |||
|
2897 | clst = create_chain(fp->fs, 0); | |||
|
2898 | if (clst == 1) ABORT(fp->fs, FR_INT_ERR); | |||
|
2899 | if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); | |||
|
2900 | fp->sclust = clst; | |||
|
2901 | } | |||
|
2902 | #endif | |||
|
2903 | fp->clust = clst; | |||
|
2904 | } | |||
|
2905 | if (clst != 0) { | |||
|
2906 | while (ofs > bcs) { /* Cluster following loop */ | |||
|
2907 | #if !_FS_READONLY | |||
|
2908 | if (fp->flag & FA_WRITE) { /* Check if in write mode or not */ | |||
|
2909 | clst = create_chain(fp->fs, clst); /* Force stretch if in write mode */ | |||
|
2910 | if (clst == 0) { /* When disk gets full, clip file size */ | |||
|
2911 | ofs = bcs; break; | |||
|
2912 | } | |||
|
2913 | } else | |||
|
2914 | #endif | |||
|
2915 | clst = get_fat(fp->fs, clst); /* Follow cluster chain if not in write mode */ | |||
|
2916 | if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); | |||
|
2917 | if (clst <= 1 || clst >= fp->fs->n_fatent) ABORT(fp->fs, FR_INT_ERR); | |||
|
2918 | fp->clust = clst; | |||
|
2919 | fp->fptr += bcs; | |||
|
2920 | ofs -= bcs; | |||
|
2921 | } | |||
|
2922 | fp->fptr += ofs; | |||
|
2923 | if (ofs % SS(fp->fs)) { | |||
|
2924 | nsect = clust2sect(fp->fs, clst); /* Current sector */ | |||
|
2925 | if (!nsect) ABORT(fp->fs, FR_INT_ERR); | |||
|
2926 | nsect += ofs / SS(fp->fs); | |||
|
2927 | } | |||
|
2928 | } | |||
|
2929 | } | |||
|
2930 | if (fp->fptr % SS(fp->fs) && nsect != fp->dsect) { /* Fill sector cache if needed */ | |||
|
2931 | #if !_FS_TINY | |||
|
2932 | #if !_FS_READONLY | |||
|
2933 | if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */ | |||
|
2934 | if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) | |||
|
2935 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
2936 | fp->flag &= ~FA__DIRTY; | |||
|
2937 | } | |||
|
2938 | #endif | |||
|
2939 | if (disk_read(fp->fs->drv, fp->buf, nsect, 1) != RES_OK) /* Fill sector cache */ | |||
|
2940 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
2941 | #endif | |||
|
2942 | fp->dsect = nsect; | |||
|
2943 | } | |||
|
2944 | #if !_FS_READONLY | |||
|
2945 | if (fp->fptr > fp->fsize) { /* Set file change flag if the file size is extended */ | |||
|
2946 | fp->fsize = fp->fptr; | |||
|
2947 | fp->flag |= FA__WRITTEN; | |||
|
2948 | } | |||
|
2949 | #endif | |||
|
2950 | } | |||
|
2951 | ||||
|
2952 | LEAVE_FF(fp->fs, res); | |||
|
2953 | } | |||
|
2954 | ||||
|
2955 | ||||
|
2956 | ||||
|
2957 | #if _FS_MINIMIZE <= 1 | |||
|
2958 | /*-----------------------------------------------------------------------*/ | |||
|
2959 | /* Create a Directroy Object */ | |||
|
2960 | /*-----------------------------------------------------------------------*/ | |||
|
2961 | ||||
|
2962 | FRESULT f_opendir ( | |||
|
2963 | DIR *dj, /* Pointer to directory object to create */ | |||
|
2964 | const TCHAR *path /* Pointer to the directory path */ | |||
|
2965 | ) | |||
|
2966 | { | |||
|
2967 | FRESULT res; | |||
|
2968 | DEF_NAMEBUF; | |||
|
2969 | ||||
|
2970 | ||||
|
2971 | res = chk_mounted(&path, &dj->fs, 0); | |||
|
2972 | if (res == FR_OK) { | |||
|
2973 | INIT_BUF(*dj); | |||
|
2974 | res = follow_path(dj, path); /* Follow the path to the directory */ | |||
|
2975 | FREE_BUF(); | |||
|
2976 | if (res == FR_OK) { /* Follow completed */ | |||
|
2977 | if (dj->dir) { /* It is not the root dir */ | |||
|
2978 | if (dj->dir[DIR_Attr] & AM_DIR) { /* The object is a directory */ | |||
|
2979 | dj->sclust = LD_CLUST(dj->dir); | |||
|
2980 | } else { /* The object is not a directory */ | |||
|
2981 | res = FR_NO_PATH; | |||
|
2982 | } | |||
|
2983 | } | |||
|
2984 | if (res == FR_OK) { | |||
|
2985 | dj->id = dj->fs->id; | |||
|
2986 | res = dir_sdi(dj, 0); /* Rewind dir */ | |||
|
2987 | } | |||
|
2988 | } | |||
|
2989 | if (res == FR_NO_FILE) res = FR_NO_PATH; | |||
|
2990 | } | |||
|
2991 | ||||
|
2992 | LEAVE_FF(dj->fs, res); | |||
|
2993 | } | |||
|
2994 | ||||
|
2995 | ||||
|
2996 | ||||
|
2997 | ||||
|
2998 | /*-----------------------------------------------------------------------*/ | |||
|
2999 | /* Read Directory Entry in Sequense */ | |||
|
3000 | /*-----------------------------------------------------------------------*/ | |||
|
3001 | ||||
|
3002 | FRESULT f_readdir ( | |||
|
3003 | DIR *dj, /* Pointer to the open directory object */ | |||
|
3004 | FILINFO *fno /* Pointer to file information to return */ | |||
|
3005 | ) | |||
|
3006 | { | |||
|
3007 | FRESULT res; | |||
|
3008 | DEF_NAMEBUF; | |||
|
3009 | ||||
|
3010 | ||||
|
3011 | res = validate(dj->fs, dj->id); /* Check validity of the object */ | |||
|
3012 | if (res == FR_OK) { | |||
|
3013 | if (!fno) { | |||
|
3014 | res = dir_sdi(dj, 0); /* Rewind the directory object */ | |||
|
3015 | } else { | |||
|
3016 | INIT_BUF(*dj); | |||
|
3017 | res = dir_read(dj); /* Read an directory item */ | |||
|
3018 | if (res == FR_NO_FILE) { /* Reached end of dir */ | |||
|
3019 | dj->sect = 0; | |||
|
3020 | res = FR_OK; | |||
|
3021 | } | |||
|
3022 | if (res == FR_OK) { /* A valid entry is found */ | |||
|
3023 | get_fileinfo(dj, fno); /* Get the object information */ | |||
|
3024 | res = dir_next(dj, 0); /* Increment index for next */ | |||
|
3025 | if (res == FR_NO_FILE) { | |||
|
3026 | dj->sect = 0; | |||
|
3027 | res = FR_OK; | |||
|
3028 | } | |||
|
3029 | } | |||
|
3030 | FREE_BUF(); | |||
|
3031 | } | |||
|
3032 | } | |||
|
3033 | ||||
|
3034 | LEAVE_FF(dj->fs, res); | |||
|
3035 | } | |||
|
3036 | ||||
|
3037 | ||||
|
3038 | ||||
|
3039 | #if _FS_MINIMIZE == 0 | |||
|
3040 | /*-----------------------------------------------------------------------*/ | |||
|
3041 | /* Get File Status */ | |||
|
3042 | /*-----------------------------------------------------------------------*/ | |||
|
3043 | ||||
|
3044 | FRESULT f_stat ( | |||
|
3045 | const TCHAR *path, /* Pointer to the file path */ | |||
|
3046 | FILINFO *fno /* Pointer to file information to return */ | |||
|
3047 | ) | |||
|
3048 | { | |||
|
3049 | FRESULT res; | |||
|
3050 | DIR dj; | |||
|
3051 | DEF_NAMEBUF; | |||
|
3052 | ||||
|
3053 | ||||
|
3054 | res = chk_mounted(&path, &dj.fs, 0); | |||
|
3055 | if (res == FR_OK) { | |||
|
3056 | INIT_BUF(dj); | |||
|
3057 | res = follow_path(&dj, path); /* Follow the file path */ | |||
|
3058 | if (res == FR_OK) { /* Follow completed */ | |||
|
3059 | if (dj.dir) /* Found an object */ | |||
|
3060 | get_fileinfo(&dj, fno); | |||
|
3061 | else /* It is root dir */ | |||
|
3062 | res = FR_INVALID_NAME; | |||
|
3063 | } | |||
|
3064 | FREE_BUF(); | |||
|
3065 | } | |||
|
3066 | ||||
|
3067 | LEAVE_FF(dj.fs, res); | |||
|
3068 | } | |||
|
3069 | ||||
|
3070 | ||||
|
3071 | ||||
|
3072 | #if !_FS_READONLY | |||
|
3073 | /*-----------------------------------------------------------------------*/ | |||
|
3074 | /* Get Number of Free Clusters */ | |||
|
3075 | /*-----------------------------------------------------------------------*/ | |||
|
3076 | ||||
|
3077 | FRESULT f_getfree ( | |||
|
3078 | const TCHAR *path, /* Pointer to the logical drive number (root dir) */ | |||
|
3079 | DWORD *nclst, /* Pointer to the variable to return number of free clusters */ | |||
|
3080 | FATFS **fatfs /* Pointer to pointer to corresponding file system object to return */ | |||
|
3081 | ) | |||
|
3082 | { | |||
|
3083 | FRESULT res; | |||
|
3084 | DWORD n, clst, sect, stat; | |||
|
3085 | UINT i; | |||
|
3086 | BYTE fat, *p; | |||
|
3087 | ||||
|
3088 | ||||
|
3089 | /* Get drive number */ | |||
|
3090 | res = chk_mounted(&path, fatfs, 0); | |||
|
3091 | if (res == FR_OK) { | |||
|
3092 | /* If free_clust is valid, return it without full cluster scan */ | |||
|
3093 | if ((*fatfs)->free_clust <= (*fatfs)->n_fatent - 2) { | |||
|
3094 | *nclst = (*fatfs)->free_clust; | |||
|
3095 | } else { | |||
|
3096 | /* Get number of free clusters */ | |||
|
3097 | fat = (*fatfs)->fs_type; | |||
|
3098 | n = 0; | |||
|
3099 | if (fat == FS_FAT12) { | |||
|
3100 | clst = 2; | |||
|
3101 | do { | |||
|
3102 | stat = get_fat(*fatfs, clst); | |||
|
3103 | if (stat == 0xFFFFFFFF) { res = FR_DISK_ERR; break; } | |||
|
3104 | if (stat == 1) { res = FR_INT_ERR; break; } | |||
|
3105 | if (stat == 0) n++; | |||
|
3106 | } while (++clst < (*fatfs)->n_fatent); | |||
|
3107 | } else { | |||
|
3108 | clst = (*fatfs)->n_fatent; | |||
|
3109 | sect = (*fatfs)->fatbase; | |||
|
3110 | i = 0; p = 0; | |||
|
3111 | do { | |||
|
3112 | if (!i) { | |||
|
3113 | res = move_window(*fatfs, sect++); | |||
|
3114 | if (res != FR_OK) break; | |||
|
3115 | p = (*fatfs)->win; | |||
|
3116 | i = SS(*fatfs); | |||
|
3117 | } | |||
|
3118 | if (fat == FS_FAT16) { | |||
|
3119 | if (LD_WORD(p) == 0) n++; | |||
|
3120 | p += 2; i -= 2; | |||
|
3121 | } else { | |||
|
3122 | if ((LD_DWORD(p) & 0x0FFFFFFF) == 0) n++; | |||
|
3123 | p += 4; i -= 4; | |||
|
3124 | } | |||
|
3125 | } while (--clst); | |||
|
3126 | } | |||
|
3127 | (*fatfs)->free_clust = n; | |||
|
3128 | if (fat == FS_FAT32) (*fatfs)->fsi_flag = 1; | |||
|
3129 | *nclst = n; | |||
|
3130 | } | |||
|
3131 | } | |||
|
3132 | LEAVE_FF(*fatfs, res); | |||
|
3133 | } | |||
|
3134 | ||||
|
3135 | ||||
|
3136 | ||||
|
3137 | ||||
|
3138 | /*-----------------------------------------------------------------------*/ | |||
|
3139 | /* Truncate File */ | |||
|
3140 | /*-----------------------------------------------------------------------*/ | |||
|
3141 | ||||
|
3142 | FRESULT f_truncate ( | |||
|
3143 | FIL *fp /* Pointer to the file object */ | |||
|
3144 | ) | |||
|
3145 | { | |||
|
3146 | FRESULT res; | |||
|
3147 | DWORD ncl; | |||
|
3148 | ||||
|
3149 | ||||
|
3150 | res = validate(fp->fs, fp->id); /* Check validity of the object */ | |||
|
3151 | if (res == FR_OK) { | |||
|
3152 | if (fp->flag & FA__ERROR) { /* Check abort flag */ | |||
|
3153 | res = FR_INT_ERR; | |||
|
3154 | } else { | |||
|
3155 | if (!(fp->flag & FA_WRITE)) /* Check access mode */ | |||
|
3156 | res = FR_DENIED; | |||
|
3157 | } | |||
|
3158 | } | |||
|
3159 | if (res == FR_OK) { | |||
|
3160 | if (fp->fsize > fp->fptr) { | |||
|
3161 | fp->fsize = fp->fptr; /* Set file size to current R/W point */ | |||
|
3162 | fp->flag |= FA__WRITTEN; | |||
|
3163 | if (fp->fptr == 0) { /* When set file size to zero, remove entire cluster chain */ | |||
|
3164 | res = remove_chain(fp->fs, fp->sclust); | |||
|
3165 | fp->sclust = 0; | |||
|
3166 | } else { /* When truncate a part of the file, remove remaining clusters */ | |||
|
3167 | ncl = get_fat(fp->fs, fp->clust); | |||
|
3168 | res = FR_OK; | |||
|
3169 | if (ncl == 0xFFFFFFFF) res = FR_DISK_ERR; | |||
|
3170 | if (ncl == 1) res = FR_INT_ERR; | |||
|
3171 | if (res == FR_OK && ncl < fp->fs->n_fatent) { | |||
|
3172 | res = put_fat(fp->fs, fp->clust, 0x0FFFFFFF); | |||
|
3173 | if (res == FR_OK) res = remove_chain(fp->fs, ncl); | |||
|
3174 | } | |||
|
3175 | } | |||
|
3176 | } | |||
|
3177 | if (res != FR_OK) fp->flag |= FA__ERROR; | |||
|
3178 | } | |||
|
3179 | ||||
|
3180 | LEAVE_FF(fp->fs, res); | |||
|
3181 | } | |||
|
3182 | ||||
|
3183 | ||||
|
3184 | ||||
|
3185 | ||||
|
3186 | /*-----------------------------------------------------------------------*/ | |||
|
3187 | /* Delete a File or Directory */ | |||
|
3188 | /*-----------------------------------------------------------------------*/ | |||
|
3189 | ||||
|
3190 | FRESULT f_unlink ( | |||
|
3191 | const TCHAR *path /* Pointer to the file or directory path */ | |||
|
3192 | ) | |||
|
3193 | { | |||
|
3194 | FRESULT res; | |||
|
3195 | DIR dj, sdj; | |||
|
3196 | BYTE *dir; | |||
|
3197 | DWORD dclst; | |||
|
3198 | DEF_NAMEBUF; | |||
|
3199 | ||||
|
3200 | ||||
|
3201 | res = chk_mounted(&path, &dj.fs, 1); | |||
|
3202 | if (res == FR_OK) { | |||
|
3203 | INIT_BUF(dj); | |||
|
3204 | res = follow_path(&dj, path); /* Follow the file path */ | |||
|
3205 | if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT)) | |||
|
3206 | res = FR_INVALID_NAME; /* Cannot remove dot entry */ | |||
|
3207 | #if _FS_SHARE | |||
|
3208 | if (res == FR_OK) res = chk_lock(&dj, 2); /* Cannot remove open file */ | |||
|
3209 | #endif | |||
|
3210 | if (res == FR_OK) { /* The object is accessible */ | |||
|
3211 | dir = dj.dir; | |||
|
3212 | if (!dir) { | |||
|
3213 | res = FR_INVALID_NAME; /* Cannot remove the start directory */ | |||
|
3214 | } else { | |||
|
3215 | if (dir[DIR_Attr] & AM_RDO) | |||
|
3216 | res = FR_DENIED; /* Cannot remove R/O object */ | |||
|
3217 | } | |||
|
3218 | dclst = LD_CLUST(dir); | |||
|
3219 | if (res == FR_OK && (dir[DIR_Attr] & AM_DIR)) { /* Is it a sub-dir? */ | |||
|
3220 | if (dclst < 2) { | |||
|
3221 | res = FR_INT_ERR; | |||
|
3222 | } else { | |||
|
3223 | mem_cpy(&sdj, &dj, sizeof(DIR)); /* Check if the sub-dir is empty or not */ | |||
|
3224 | sdj.sclust = dclst; | |||
|
3225 | res = dir_sdi(&sdj, 2); /* Exclude dot entries */ | |||
|
3226 | if (res == FR_OK) { | |||
|
3227 | res = dir_read(&sdj); | |||
|
3228 | if (res == FR_OK /* Not empty dir */ | |||
|
3229 | #if _FS_RPATH | |||
|
3230 | || dclst == sdj.fs->cdir /* Current dir */ | |||
|
3231 | #endif | |||
|
3232 | ) res = FR_DENIED; | |||
|
3233 | if (res == FR_NO_FILE) res = FR_OK; /* Empty */ | |||
|
3234 | } | |||
|
3235 | } | |||
|
3236 | } | |||
|
3237 | if (res == FR_OK) { | |||
|
3238 | res = dir_remove(&dj); /* Remove the directory entry */ | |||
|
3239 | if (res == FR_OK) { | |||
|
3240 | if (dclst) /* Remove the cluster chain if exist */ | |||
|
3241 | res = remove_chain(dj.fs, dclst); | |||
|
3242 | if (res == FR_OK) res = sync(dj.fs); | |||
|
3243 | } | |||
|
3244 | } | |||
|
3245 | } | |||
|
3246 | FREE_BUF(); | |||
|
3247 | } | |||
|
3248 | LEAVE_FF(dj.fs, res); | |||
|
3249 | } | |||
|
3250 | ||||
|
3251 | ||||
|
3252 | ||||
|
3253 | ||||
|
3254 | /*-----------------------------------------------------------------------*/ | |||
|
3255 | /* Create a Directory */ | |||
|
3256 | /*-----------------------------------------------------------------------*/ | |||
|
3257 | ||||
|
3258 | FRESULT f_mkdir ( | |||
|
3259 | const TCHAR *path /* Pointer to the directory path */ | |||
|
3260 | ) | |||
|
3261 | { | |||
|
3262 | FRESULT res; | |||
|
3263 | DIR dj; | |||
|
3264 | BYTE *dir, n; | |||
|
3265 | DWORD dsc, dcl, pcl, tim = get_fattime(); | |||
|
3266 | DEF_NAMEBUF; | |||
|
3267 | ||||
|
3268 | ||||
|
3269 | res = chk_mounted(&path, &dj.fs, 1); | |||
|
3270 | if (res == FR_OK) { | |||
|
3271 | INIT_BUF(dj); | |||
|
3272 | res = follow_path(&dj, path); /* Follow the file path */ | |||
|
3273 | if (res == FR_OK) res = FR_EXIST; /* Any object with same name is already existing */ | |||
|
3274 | if (_FS_RPATH && res == FR_NO_FILE && (dj.fn[NS] & NS_DOT)) | |||
|
3275 | res = FR_INVALID_NAME; | |||
|
3276 | if (res == FR_NO_FILE) { /* Can create a new directory */ | |||
|
3277 | dcl = create_chain(dj.fs, 0); /* Allocate a cluster for the new directory table */ | |||
|
3278 | res = FR_OK; | |||
|
3279 | if (dcl == 0) res = FR_DENIED; /* No space to allocate a new cluster */ | |||
|
3280 | if (dcl == 1) res = FR_INT_ERR; | |||
|
3281 | if (dcl == 0xFFFFFFFF) res = FR_DISK_ERR; | |||
|
3282 | if (res == FR_OK) /* Flush FAT */ | |||
|
3283 | res = move_window(dj.fs, 0); | |||
|
3284 | if (res == FR_OK) { /* Initialize the new directory table */ | |||
|
3285 | dsc = clust2sect(dj.fs, dcl); | |||
|
3286 | dir = dj.fs->win; | |||
|
3287 | mem_set(dir, 0, SS(dj.fs)); | |||
|
3288 | mem_set(dir+DIR_Name, ' ', 8+3); /* Create "." entry */ | |||
|
3289 | dir[DIR_Name] = '.'; | |||
|
3290 | dir[DIR_Attr] = AM_DIR; | |||
|
3291 | ST_DWORD(dir+DIR_WrtTime, tim); | |||
|
3292 | ST_CLUST(dir, dcl); | |||
|
3293 | mem_cpy(dir+SZ_DIR, dir, SZ_DIR); /* Create ".." entry */ | |||
|
3294 | dir[33] = '.'; pcl = dj.sclust; | |||
|
3295 | if (dj.fs->fs_type == FS_FAT32 && pcl == dj.fs->dirbase) | |||
|
3296 | pcl = 0; | |||
|
3297 | ST_CLUST(dir+SZ_DIR, pcl); | |||
|
3298 | for (n = dj.fs->csize; n; n--) { /* Write dot entries and clear following sectors */ | |||
|
3299 | dj.fs->winsect = dsc++; | |||
|
3300 | dj.fs->wflag = 1; | |||
|
3301 | res = move_window(dj.fs, 0); | |||
|
3302 | if (res != FR_OK) break; | |||
|
3303 | mem_set(dir, 0, SS(dj.fs)); | |||
|
3304 | } | |||
|
3305 | } | |||
|
3306 | if (res == FR_OK) res = dir_register(&dj); /* Register the object to the directoy */ | |||
|
3307 | if (res != FR_OK) { | |||
|
3308 | remove_chain(dj.fs, dcl); /* Could not register, remove cluster chain */ | |||
|
3309 | } else { | |||
|
3310 | dir = dj.dir; | |||
|
3311 | dir[DIR_Attr] = AM_DIR; /* Attribute */ | |||
|
3312 | ST_DWORD(dir+DIR_WrtTime, tim); /* Created time */ | |||
|
3313 | ST_CLUST(dir, dcl); /* Table start cluster */ | |||
|
3314 | dj.fs->wflag = 1; | |||
|
3315 | res = sync(dj.fs); | |||
|
3316 | } | |||
|
3317 | } | |||
|
3318 | FREE_BUF(); | |||
|
3319 | } | |||
|
3320 | ||||
|
3321 | LEAVE_FF(dj.fs, res); | |||
|
3322 | } | |||
|
3323 | ||||
|
3324 | ||||
|
3325 | ||||
|
3326 | ||||
|
3327 | /*-----------------------------------------------------------------------*/ | |||
|
3328 | /* Change Attribute */ | |||
|
3329 | /*-----------------------------------------------------------------------*/ | |||
|
3330 | ||||
|
3331 | FRESULT f_chmod ( | |||
|
3332 | const TCHAR *path, /* Pointer to the file path */ | |||
|
3333 | BYTE value, /* Attribute bits */ | |||
|
3334 | BYTE mask /* Attribute mask to change */ | |||
|
3335 | ) | |||
|
3336 | { | |||
|
3337 | FRESULT res; | |||
|
3338 | DIR dj; | |||
|
3339 | BYTE *dir; | |||
|
3340 | DEF_NAMEBUF; | |||
|
3341 | ||||
|
3342 | ||||
|
3343 | res = chk_mounted(&path, &dj.fs, 1); | |||
|
3344 | if (res == FR_OK) { | |||
|
3345 | INIT_BUF(dj); | |||
|
3346 | res = follow_path(&dj, path); /* Follow the file path */ | |||
|
3347 | FREE_BUF(); | |||
|
3348 | if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT)) | |||
|
3349 | res = FR_INVALID_NAME; | |||
|
3350 | if (res == FR_OK) { | |||
|
3351 | dir = dj.dir; | |||
|
3352 | if (!dir) { /* Is it a root directory? */ | |||
|
3353 | res = FR_INVALID_NAME; | |||
|
3354 | } else { /* File or sub directory */ | |||
|
3355 | mask &= AM_RDO|AM_HID|AM_SYS|AM_ARC; /* Valid attribute mask */ | |||
|
3356 | dir[DIR_Attr] = (value & mask) | (dir[DIR_Attr] & (BYTE)~mask); /* Apply attribute change */ | |||
|
3357 | dj.fs->wflag = 1; | |||
|
3358 | res = sync(dj.fs); | |||
|
3359 | } | |||
|
3360 | } | |||
|
3361 | } | |||
|
3362 | ||||
|
3363 | LEAVE_FF(dj.fs, res); | |||
|
3364 | } | |||
|
3365 | ||||
|
3366 | ||||
|
3367 | ||||
|
3368 | ||||
|
3369 | /*-----------------------------------------------------------------------*/ | |||
|
3370 | /* Change Timestamp */ | |||
|
3371 | /*-----------------------------------------------------------------------*/ | |||
|
3372 | ||||
|
3373 | FRESULT f_utime ( | |||
|
3374 | const TCHAR *path, /* Pointer to the file/directory name */ | |||
|
3375 | const FILINFO *fno /* Pointer to the time stamp to be set */ | |||
|
3376 | ) | |||
|
3377 | { | |||
|
3378 | FRESULT res; | |||
|
3379 | DIR dj; | |||
|
3380 | BYTE *dir; | |||
|
3381 | DEF_NAMEBUF; | |||
|
3382 | ||||
|
3383 | ||||
|
3384 | res = chk_mounted(&path, &dj.fs, 1); | |||
|
3385 | if (res == FR_OK) { | |||
|
3386 | INIT_BUF(dj); | |||
|
3387 | res = follow_path(&dj, path); /* Follow the file path */ | |||
|
3388 | FREE_BUF(); | |||
|
3389 | if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT)) | |||
|
3390 | res = FR_INVALID_NAME; | |||
|
3391 | if (res == FR_OK) { | |||
|
3392 | dir = dj.dir; | |||
|
3393 | if (!dir) { /* Root directory */ | |||
|
3394 | res = FR_INVALID_NAME; | |||
|
3395 | } else { /* File or sub-directory */ | |||
|
3396 | ST_WORD(dir+DIR_WrtTime, fno->ftime); | |||
|
3397 | ST_WORD(dir+DIR_WrtDate, fno->fdate); | |||
|
3398 | dj.fs->wflag = 1; | |||
|
3399 | res = sync(dj.fs); | |||
|
3400 | } | |||
|
3401 | } | |||
|
3402 | } | |||
|
3403 | ||||
|
3404 | LEAVE_FF(dj.fs, res); | |||
|
3405 | } | |||
|
3406 | ||||
|
3407 | ||||
|
3408 | ||||
|
3409 | ||||
|
3410 | /*-----------------------------------------------------------------------*/ | |||
|
3411 | /* Rename File/Directory */ | |||
|
3412 | /*-----------------------------------------------------------------------*/ | |||
|
3413 | ||||
|
3414 | FRESULT f_rename ( | |||
|
3415 | const TCHAR *path_old, /* Pointer to the old name */ | |||
|
3416 | const TCHAR *path_new /* Pointer to the new name */ | |||
|
3417 | ) | |||
|
3418 | { | |||
|
3419 | FRESULT res; | |||
|
3420 | DIR djo, djn; | |||
|
3421 | BYTE buf[21], *dir; | |||
|
3422 | DWORD dw; | |||
|
3423 | DEF_NAMEBUF; | |||
|
3424 | ||||
|
3425 | ||||
|
3426 | res = chk_mounted(&path_old, &djo.fs, 1); | |||
|
3427 | if (res == FR_OK) { | |||
|
3428 | djn.fs = djo.fs; | |||
|
3429 | INIT_BUF(djo); | |||
|
3430 | res = follow_path(&djo, path_old); /* Check old object */ | |||
|
3431 | if (_FS_RPATH && res == FR_OK && (djo.fn[NS] & NS_DOT)) | |||
|
3432 | res = FR_INVALID_NAME; | |||
|
3433 | #if _FS_SHARE | |||
|
3434 | if (res == FR_OK) res = chk_lock(&djo, 2); | |||
|
3435 | #endif | |||
|
3436 | if (res == FR_OK) { /* Old object is found */ | |||
|
3437 | if (!djo.dir) { /* Is root dir? */ | |||
|
3438 | res = FR_NO_FILE; | |||
|
3439 | } else { | |||
|
3440 | mem_cpy(buf, djo.dir+DIR_Attr, 21); /* Save the object information except for name */ | |||
|
3441 | mem_cpy(&djn, &djo, sizeof(DIR)); /* Check new object */ | |||
|
3442 | res = follow_path(&djn, path_new); | |||
|
3443 | if (res == FR_OK) res = FR_EXIST; /* The new object name is already existing */ | |||
|
3444 | if (res == FR_NO_FILE) { /* Is it a valid path and no name collision? */ | |||
|
3445 | /* Start critical section that any interruption or error can cause cross-link */ | |||
|
3446 | res = dir_register(&djn); /* Register the new entry */ | |||
|
3447 | if (res == FR_OK) { | |||
|
3448 | dir = djn.dir; /* Copy object information except for name */ | |||
|
3449 | mem_cpy(dir+13, buf+2, 19); | |||
|
3450 | dir[DIR_Attr] = buf[0] | AM_ARC; | |||
|
3451 | djo.fs->wflag = 1; | |||
|
3452 | if (djo.sclust != djn.sclust && (dir[DIR_Attr] & AM_DIR)) { /* Update .. entry in the directory if needed */ | |||
|
3453 | dw = clust2sect(djn.fs, LD_CLUST(dir)); | |||
|
3454 | if (!dw) { | |||
|
3455 | res = FR_INT_ERR; | |||
|
3456 | } else { | |||
|
3457 | res = move_window(djn.fs, dw); | |||
|
3458 | dir = djn.fs->win+SZ_DIR; /* .. entry */ | |||
|
3459 | if (res == FR_OK && dir[1] == '.') { | |||
|
3460 | dw = (djn.fs->fs_type == FS_FAT32 && djn.sclust == djn.fs->dirbase) ? 0 : djn.sclust; | |||
|
3461 | ST_CLUST(dir, dw); | |||
|
3462 | djn.fs->wflag = 1; | |||
|
3463 | } | |||
|
3464 | } | |||
|
3465 | } | |||
|
3466 | if (res == FR_OK) { | |||
|
3467 | res = dir_remove(&djo); /* Remove old entry */ | |||
|
3468 | if (res == FR_OK) | |||
|
3469 | res = sync(djo.fs); | |||
|
3470 | } | |||
|
3471 | } | |||
|
3472 | /* End critical section */ | |||
|
3473 | } | |||
|
3474 | } | |||
|
3475 | } | |||
|
3476 | FREE_BUF(); | |||
|
3477 | } | |||
|
3478 | LEAVE_FF(djo.fs, res); | |||
|
3479 | } | |||
|
3480 | ||||
|
3481 | #endif /* !_FS_READONLY */ | |||
|
3482 | #endif /* _FS_MINIMIZE == 0 */ | |||
|
3483 | #endif /* _FS_MINIMIZE <= 1 */ | |||
|
3484 | #endif /* _FS_MINIMIZE <= 2 */ | |||
|
3485 | ||||
|
3486 | ||||
|
3487 | ||||
|
3488 | /*-----------------------------------------------------------------------*/ | |||
|
3489 | /* Forward data to the stream directly (available on only tiny cfg) */ | |||
|
3490 | /*-----------------------------------------------------------------------*/ | |||
|
3491 | #if _USE_FORWARD && _FS_TINY | |||
|
3492 | ||||
|
3493 | FRESULT f_forward ( | |||
|
3494 | FIL *fp, /* Pointer to the file object */ | |||
|
3495 | UINT (*func)(const BYTE*,UINT), /* Pointer to the streaming function */ | |||
|
3496 | UINT btr, /* Number of bytes to forward */ | |||
|
3497 | UINT *bf /* Pointer to number of bytes forwarded */ | |||
|
3498 | ) | |||
|
3499 | { | |||
|
3500 | FRESULT res; | |||
|
3501 | DWORD remain, clst, sect; | |||
|
3502 | UINT rcnt; | |||
|
3503 | BYTE csect; | |||
|
3504 | ||||
|
3505 | ||||
|
3506 | *bf = 0; /* Initialize byte counter */ | |||
|
3507 | ||||
|
3508 | res = validate(fp->fs, fp->id); /* Check validity of the object */ | |||
|
3509 | if (res != FR_OK) LEAVE_FF(fp->fs, res); | |||
|
3510 | if (fp->flag & FA__ERROR) /* Check error flag */ | |||
|
3511 | LEAVE_FF(fp->fs, FR_INT_ERR); | |||
|
3512 | if (!(fp->flag & FA_READ)) /* Check access mode */ | |||
|
3513 | LEAVE_FF(fp->fs, FR_DENIED); | |||
|
3514 | ||||
|
3515 | remain = fp->fsize - fp->fptr; | |||
|
3516 | if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */ | |||
|
3517 | ||||
|
3518 | for ( ; btr && (*func)(0, 0); /* Repeat until all data transferred or stream becomes busy */ | |||
|
3519 | fp->fptr += rcnt, *bf += rcnt, btr -= rcnt) { | |||
|
3520 | csect = (BYTE)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */ | |||
|
3521 | if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */ | |||
|
3522 | if (!csect) { /* On the cluster boundary? */ | |||
|
3523 | clst = (fp->fptr == 0) ? /* On the top of the file? */ | |||
|
3524 | fp->sclust : get_fat(fp->fs, fp->clust); | |||
|
3525 | if (clst <= 1) ABORT(fp->fs, FR_INT_ERR); | |||
|
3526 | if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); | |||
|
3527 | fp->clust = clst; /* Update current cluster */ | |||
|
3528 | } | |||
|
3529 | } | |||
|
3530 | sect = clust2sect(fp->fs, fp->clust); /* Get current data sector */ | |||
|
3531 | if (!sect) ABORT(fp->fs, FR_INT_ERR); | |||
|
3532 | sect += csect; | |||
|
3533 | if (move_window(fp->fs, sect)) /* Move sector window */ | |||
|
3534 | ABORT(fp->fs, FR_DISK_ERR); | |||
|
3535 | fp->dsect = sect; | |||
|
3536 | rcnt = SS(fp->fs) - (WORD)(fp->fptr % SS(fp->fs)); /* Forward data from sector window */ | |||
|
3537 | if (rcnt > btr) rcnt = btr; | |||
|
3538 | rcnt = (*func)(&fp->fs->win[(WORD)fp->fptr % SS(fp->fs)], rcnt); | |||
|
3539 | if (!rcnt) ABORT(fp->fs, FR_INT_ERR); | |||
|
3540 | } | |||
|
3541 | ||||
|
3542 | LEAVE_FF(fp->fs, FR_OK); | |||
|
3543 | } | |||
|
3544 | #endif /* _USE_FORWARD */ | |||
|
3545 | ||||
|
3546 | ||||
|
3547 | ||||
|
3548 | #if _USE_MKFS && !_FS_READONLY | |||
|
3549 | /*-----------------------------------------------------------------------*/ | |||
|
3550 | /* Create File System on the Drive */ | |||
|
3551 | /*-----------------------------------------------------------------------*/ | |||
|
3552 | #define N_ROOTDIR 512 /* Number of root dir entries for FAT12/16 */ | |||
|
3553 | #define N_FATS 1 /* Number of FAT copies (1 or 2) */ | |||
|
3554 | ||||
|
3555 | ||||
|
3556 | FRESULT f_mkfs ( | |||
|
3557 | BYTE drv, /* Logical drive number */ | |||
|
3558 | BYTE sfd, /* Partitioning rule 0:FDISK, 1:SFD */ | |||
|
3559 | UINT au /* Allocation unit size [bytes] */ | |||
|
3560 | ) | |||
|
3561 | { | |||
|
3562 | static const WORD vst[] = { 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 0}; | |||
|
3563 | static const WORD cst[] = {32768, 16384, 8192, 4096, 2048, 16384, 8192, 4096, 2048, 1024, 512}; | |||
|
3564 | BYTE fmt, md, sys, *tbl, pdrv, part; | |||
|
3565 | DWORD n_clst, vs, n, wsect; | |||
|
3566 | UINT i; | |||
|
3567 | DWORD b_vol, b_fat, b_dir, b_data; /* LBA */ | |||
|
3568 | DWORD n_vol, n_rsv, n_fat, n_dir; /* Size */ | |||
|
3569 | FATFS *fs; | |||
|
3570 | DSTATUS stat; | |||
|
3571 | ||||
|
3572 | ||||
|
3573 | /* Check mounted drive and clear work area */ | |||
|
3574 | if (drv >= _VOLUMES) return FR_INVALID_DRIVE; | |||
|
3575 | if (sfd > 1) return FR_INVALID_PARAMETER; | |||
|
3576 | if (au & (au - 1)) return FR_INVALID_PARAMETER; | |||
|
3577 | fs = FatFs[drv]; | |||
|
3578 | if (!fs) return FR_NOT_ENABLED; | |||
|
3579 | fs->fs_type = 0; | |||
|
3580 | pdrv = LD2PD(drv); /* Physical drive */ | |||
|
3581 | part = LD2PT(drv); /* Partition (0:auto detect, 1-4:get from partition table)*/ | |||
|
3582 | ||||
|
3583 | /* Get disk statics */ | |||
|
3584 | stat = disk_initialize(pdrv); | |||
|
3585 | if (stat & STA_NOINIT) return FR_NOT_READY; | |||
|
3586 | if (stat & STA_PROTECT) return FR_WRITE_PROTECTED; | |||
|
3587 | #if _MAX_SS != 512 /* Get disk sector size */ | |||
|
3588 | if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > _MAX_SS) | |||
|
3589 | return FR_DISK_ERR; | |||
|
3590 | #endif | |||
|
3591 | if (_MULTI_PARTITION && part) { | |||
|
3592 | /* Get partition information from partition table in the MBR */ | |||
|
3593 | if (disk_read(pdrv, fs->win, 0, 1) != RES_OK) return FR_DISK_ERR; | |||
|
3594 | if (LD_WORD(fs->win+BS_55AA) != 0xAA55) return FR_MKFS_ABORTED; | |||
|
3595 | tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE]; | |||
|
3596 | if (!tbl[4]) return FR_MKFS_ABORTED; /* No partition? */ | |||
|
3597 | b_vol = LD_DWORD(tbl+8); /* Volume start sector */ | |||
|
3598 | n_vol = LD_DWORD(tbl+12); /* Volume size */ | |||
|
3599 | } else { | |||
|
3600 | /* Create a partition in this function */ | |||
|
3601 | if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &n_vol) != RES_OK || n_vol < 128) | |||
|
3602 | return FR_DISK_ERR; | |||
|
3603 | b_vol = (sfd) ? 0 : 63; /* Volume start sector */ | |||
|
3604 | n_vol -= b_vol; /* Volume size */ | |||
|
3605 | } | |||
|
3606 | ||||
|
3607 | if (!au) { /* AU auto selection */ | |||
|
3608 | vs = n_vol / (2000 / (SS(fs) / 512)); | |||
|
3609 | for (i = 0; vs < vst[i]; i++) ; | |||
|
3610 | au = cst[i]; | |||
|
3611 | } | |||
|
3612 | au /= SS(fs); /* Number of sectors per cluster */ | |||
|
3613 | if (au == 0) au = 1; | |||
|
3614 | if (au > 128) au = 128; | |||
|
3615 | ||||
|
3616 | /* Pre-compute number of clusters and FAT syb-type */ | |||
|
3617 | n_clst = n_vol / au; | |||
|
3618 | fmt = FS_FAT12; | |||
|
3619 | if (n_clst >= MIN_FAT16) fmt = FS_FAT16; | |||
|
3620 | if (n_clst >= MIN_FAT32) fmt = FS_FAT32; | |||
|
3621 | ||||
|
3622 | /* Determine offset and size of FAT structure */ | |||
|
3623 | if (fmt == FS_FAT32) { | |||
|
3624 | n_fat = ((n_clst * 4) + 8 + SS(fs) - 1) / SS(fs); | |||
|
3625 | n_rsv = 32; | |||
|
3626 | n_dir = 0; | |||
|
3627 | } else { | |||
|
3628 | n_fat = (fmt == FS_FAT12) ? (n_clst * 3 + 1) / 2 + 3 : (n_clst * 2) + 4; | |||
|
3629 | n_fat = (n_fat + SS(fs) - 1) / SS(fs); | |||
|
3630 | n_rsv = 1; | |||
|
3631 | n_dir = (DWORD)N_ROOTDIR * SZ_DIR / SS(fs); | |||
|
3632 | } | |||
|
3633 | b_fat = b_vol + n_rsv; /* FAT area start sector */ | |||
|
3634 | b_dir = b_fat + n_fat * N_FATS; /* Directory area start sector */ | |||
|
3635 | b_data = b_dir + n_dir; /* Data area start sector */ | |||
|
3636 | if (n_vol < b_data + au - b_vol) return FR_MKFS_ABORTED; /* Too small volume */ | |||
|
3637 | ||||
|
3638 | /* Align data start sector to erase block boundary (for flash memory media) */ | |||
|
3639 | if (disk_ioctl(pdrv, GET_BLOCK_SIZE, &n) != RES_OK || !n || n > 32768) n = 1; | |||
|
3640 | n = (b_data + n - 1) & ~(n - 1); /* Next nearest erase block from current data start */ | |||
|
3641 | n = (n - b_data) / N_FATS; | |||
|
3642 | if (fmt == FS_FAT32) { /* FAT32: Move FAT offset */ | |||
|
3643 | n_rsv += n; | |||
|
3644 | b_fat += n; | |||
|
3645 | } else { /* FAT12/16: Expand FAT size */ | |||
|
3646 | n_fat += n; | |||
|
3647 | } | |||
|
3648 | ||||
|
3649 | /* Determine number of clusters and final check of validity of the FAT sub-type */ | |||
|
3650 | n_clst = (n_vol - n_rsv - n_fat * N_FATS - n_dir) / au; | |||
|
3651 | if ( (fmt == FS_FAT16 && n_clst < MIN_FAT16) | |||
|
3652 | || (fmt == FS_FAT32 && n_clst < MIN_FAT32)) | |||
|
3653 | return FR_MKFS_ABORTED; | |||
|
3654 | ||||
|
3655 | switch (fmt) { /* Determine system ID for partition table */ | |||
|
3656 | case FS_FAT12: sys = 0x01; break; | |||
|
3657 | case FS_FAT16: sys = (n_vol < 0x10000) ? 0x04 : 0x06; break; | |||
|
3658 | default: sys = 0x0C; | |||
|
3659 | } | |||
|
3660 | ||||
|
3661 | if (_MULTI_PARTITION && part) { | |||
|
3662 | /* Update system ID in the partition table */ | |||
|
3663 | tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE]; | |||
|
3664 | tbl[4] = sys; | |||
|
3665 | if (disk_write(pdrv, fs->win, 0, 1) != RES_OK) return FR_DISK_ERR; | |||
|
3666 | md = 0xF8; | |||
|
3667 | } else { | |||
|
3668 | if (sfd) { /* No patition table (SFD) */ | |||
|
3669 | md = 0xF0; | |||
|
3670 | } else { /* Create partition table (FDISK) */ | |||
|
3671 | mem_set(fs->win, 0, SS(fs)); | |||
|
3672 | tbl = fs->win+MBR_Table; /* Create partiton table for single partition in the drive */ | |||
|
3673 | tbl[1] = 1; /* Partition start head */ | |||
|
3674 | tbl[2] = 1; /* Partition start sector */ | |||
|
3675 | tbl[3] = 0; /* Partition start cylinder */ | |||
|
3676 | tbl[4] = sys; /* System type */ | |||
|
3677 | tbl[5] = 254; /* Partition end head */ | |||
|
3678 | n = (b_vol + n_vol) / 63 / 255; | |||
|
3679 | tbl[6] = (BYTE)((n >> 2) | 63); /* Partiiton end sector */ | |||
|
3680 | tbl[7] = (BYTE)n; /* End cylinder */ | |||
|
3681 | ST_DWORD(tbl+8, 63); /* Partition start in LBA */ | |||
|
3682 | ST_DWORD(tbl+12, n_vol); /* Partition size in LBA */ | |||
|
3683 | ST_WORD(fs->win+BS_55AA, 0xAA55); /* MBR signature */ | |||
|
3684 | if (disk_write(pdrv, fs->win, 0, 1) != RES_OK) /* Write it to the MBR sector */ | |||
|
3685 | return FR_DISK_ERR; | |||
|
3686 | md = 0xF8; | |||
|
3687 | } | |||
|
3688 | } | |||
|
3689 | ||||
|
3690 | /* Create BPB in the VBR */ | |||
|
3691 | tbl = fs->win; /* Clear sector */ | |||
|
3692 | mem_set(tbl, 0, SS(fs)); | |||
|
3693 | mem_cpy(tbl, "\xEB\xFE\x90" "MSDOS5.0", 11);/* Boot jump code, OEM name */ | |||
|
3694 | i = SS(fs); /* Sector size */ | |||
|
3695 | ST_WORD(tbl+BPB_BytsPerSec, i); | |||
|
3696 | tbl[BPB_SecPerClus] = (BYTE)au; /* Sectors per cluster */ | |||
|
3697 | ST_WORD(tbl+BPB_RsvdSecCnt, n_rsv); /* Reserved sectors */ | |||
|
3698 | tbl[BPB_NumFATs] = N_FATS; /* Number of FATs */ | |||
|
3699 | i = (fmt == FS_FAT32) ? 0 : N_ROOTDIR; /* Number of rootdir entries */ | |||
|
3700 | ST_WORD(tbl+BPB_RootEntCnt, i); | |||
|
3701 | if (n_vol < 0x10000) { /* Number of total sectors */ | |||
|
3702 | ST_WORD(tbl+BPB_TotSec16, n_vol); | |||
|
3703 | } else { | |||
|
3704 | ST_DWORD(tbl+BPB_TotSec32, n_vol); | |||
|
3705 | } | |||
|
3706 | tbl[BPB_Media] = md; /* Media descriptor */ | |||
|
3707 | ST_WORD(tbl+BPB_SecPerTrk, 63); /* Number of sectors per track */ | |||
|
3708 | ST_WORD(tbl+BPB_NumHeads, 255); /* Number of heads */ | |||
|
3709 | ST_DWORD(tbl+BPB_HiddSec, b_vol); /* Hidden sectors */ | |||
|
3710 | n = get_fattime(); /* Use current time as VSN */ | |||
|
3711 | if (fmt == FS_FAT32) { | |||
|
3712 | ST_DWORD(tbl+BS_VolID32, n); /* VSN */ | |||
|
3713 | ST_DWORD(tbl+BPB_FATSz32, n_fat); /* Number of sectors per FAT */ | |||
|
3714 | ST_DWORD(tbl+BPB_RootClus, 2); /* Root directory start cluster (2) */ | |||
|
3715 | ST_WORD(tbl+BPB_FSInfo, 1); /* FSInfo record offset (VBR+1) */ | |||
|
3716 | ST_WORD(tbl+BPB_BkBootSec, 6); /* Backup boot record offset (VBR+6) */ | |||
|
3717 | tbl[BS_DrvNum32] = 0x80; /* Drive number */ | |||
|
3718 | tbl[BS_BootSig32] = 0x29; /* Extended boot signature */ | |||
|
3719 | mem_cpy(tbl+BS_VolLab32, "NO NAME " "FAT32 ", 19); /* Volume label, FAT signature */ | |||
|
3720 | } else { | |||
|
3721 | ST_DWORD(tbl+BS_VolID, n); /* VSN */ | |||
|
3722 | ST_WORD(tbl+BPB_FATSz16, n_fat); /* Number of sectors per FAT */ | |||
|
3723 | tbl[BS_DrvNum] = 0x80; /* Drive number */ | |||
|
3724 | tbl[BS_BootSig] = 0x29; /* Extended boot signature */ | |||
|
3725 | mem_cpy(tbl+BS_VolLab, "NO NAME " "FAT ", 19); /* Volume label, FAT signature */ | |||
|
3726 | } | |||
|
3727 | ST_WORD(tbl+BS_55AA, 0xAA55); /* Signature (Offset is fixed here regardless of sector size) */ | |||
|
3728 | if (disk_write(pdrv, tbl, b_vol, 1) != RES_OK) /* Write it to the VBR sector */ | |||
|
3729 | return FR_DISK_ERR; | |||
|
3730 | if (fmt == FS_FAT32) /* Write backup VBR if needed (VBR+6) */ | |||
|
3731 | disk_write(pdrv, tbl, b_vol + 6, 1); | |||
|
3732 | ||||
|
3733 | /* Initialize FAT area */ | |||
|
3734 | wsect = b_fat; | |||
|
3735 | for (i = 0; i < N_FATS; i++) { /* Initialize each FAT copy */ | |||
|
3736 | mem_set(tbl, 0, SS(fs)); /* 1st sector of the FAT */ | |||
|
3737 | n = md; /* Media descriptor byte */ | |||
|
3738 | if (fmt != FS_FAT32) { | |||
|
3739 | n |= (fmt == FS_FAT12) ? 0x00FFFF00 : 0xFFFFFF00; | |||
|
3740 | ST_DWORD(tbl+0, n); /* Reserve cluster #0-1 (FAT12/16) */ | |||
|
3741 | } else { | |||
|
3742 | n |= 0xFFFFFF00; | |||
|
3743 | ST_DWORD(tbl+0, n); /* Reserve cluster #0-1 (FAT32) */ | |||
|
3744 | ST_DWORD(tbl+4, 0xFFFFFFFF); | |||
|
3745 | ST_DWORD(tbl+8, 0x0FFFFFFF); /* Reserve cluster #2 for root dir */ | |||
|
3746 | } | |||
|
3747 | if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK) | |||
|
3748 | return FR_DISK_ERR; | |||
|
3749 | mem_set(tbl, 0, SS(fs)); /* Fill following FAT entries with zero */ | |||
|
3750 | for (n = 1; n < n_fat; n++) { /* This loop may take a time on FAT32 volume due to many single sector writes */ | |||
|
3751 | if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK) | |||
|
3752 | return FR_DISK_ERR; | |||
|
3753 | } | |||
|
3754 | } | |||
|
3755 | ||||
|
3756 | /* Initialize root directory */ | |||
|
3757 | i = (fmt == FS_FAT32) ? au : n_dir; | |||
|
3758 | do { | |||
|
3759 | if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK) | |||
|
3760 | return FR_DISK_ERR; | |||
|
3761 | } while (--i); | |||
|
3762 | ||||
|
3763 | #if _USE_ERASE /* Erase data area if needed */ | |||
|
3764 | { | |||
|
3765 | DWORD eb[2]; | |||
|
3766 | ||||
|
3767 | eb[0] = wsect; eb[1] = wsect + (n_clst - ((fmt == FS_FAT32) ? 1 : 0)) * au - 1; | |||
|
3768 | disk_ioctl(pdrv, CTRL_ERASE_SECTOR, eb); | |||
|
3769 | } | |||
|
3770 | #endif | |||
|
3771 | ||||
|
3772 | /* Create FSInfo if needed */ | |||
|
3773 | if (fmt == FS_FAT32) { | |||
|
3774 | ST_DWORD(tbl+FSI_LeadSig, 0x41615252); | |||
|
3775 | ST_DWORD(tbl+FSI_StrucSig, 0x61417272); | |||
|
3776 | ST_DWORD(tbl+FSI_Free_Count, n_clst - 1); /* Number of free clusters */ | |||
|
3777 | ST_DWORD(tbl+FSI_Nxt_Free, 2); /* Last allocated cluster# */ | |||
|
3778 | ST_WORD(tbl+BS_55AA, 0xAA55); | |||
|
3779 | disk_write(pdrv, tbl, b_vol + 1, 1); /* Write original (VBR+1) */ | |||
|
3780 | disk_write(pdrv, tbl, b_vol + 7, 1); /* Write backup (VBR+7) */ | |||
|
3781 | } | |||
|
3782 | ||||
|
3783 | return (disk_ioctl(pdrv, CTRL_SYNC, 0) == RES_OK) ? FR_OK : FR_DISK_ERR; | |||
|
3784 | } | |||
|
3785 | ||||
|
3786 | ||||
|
3787 | #if _MULTI_PARTITION == 2 | |||
|
3788 | /*-----------------------------------------------------------------------*/ | |||
|
3789 | /* Divide Physical Drive */ | |||
|
3790 | /*-----------------------------------------------------------------------*/ | |||
|
3791 | ||||
|
3792 | FRESULT f_fdisk ( | |||
|
3793 | BYTE pdrv, /* Physical drive number */ | |||
|
3794 | const DWORD szt[], /* Pointer to the size table for each partitions */ | |||
|
3795 | void* work /* Pointer to the working buffer */ | |||
|
3796 | ) | |||
|
3797 | { | |||
|
3798 | UINT i, n, sz_cyl, tot_cyl, b_cyl, e_cyl, p_cyl; | |||
|
3799 | BYTE s_hd, e_hd, *p, *buf = (BYTE*)work; | |||
|
3800 | DSTATUS stat; | |||
|
3801 | DWORD sz_disk, sz_part, s_part; | |||
|
3802 | ||||
|
3803 | ||||
|
3804 | stat = disk_initialize(pdrv); | |||
|
3805 | if (stat & STA_NOINIT) return FR_NOT_READY; | |||
|
3806 | if (stat & STA_PROTECT) return FR_WRITE_PROTECTED; | |||
|
3807 | if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_disk)) return FR_DISK_ERR; | |||
|
3808 | ||||
|
3809 | /* Determine CHS in the table regardless of the drive geometry */ | |||
|
3810 | for (n = 16; n < 256 && sz_disk / n / 63 > 1024; n *= 2) ; | |||
|
3811 | if (n == 256) n--; | |||
|
3812 | e_hd = n - 1; | |||
|
3813 | sz_cyl = 63 * n; | |||
|
3814 | tot_cyl = sz_disk / sz_cyl; | |||
|
3815 | ||||
|
3816 | /* Create partition table */ | |||
|
3817 | mem_set(buf, 0, _MAX_SS); | |||
|
3818 | p = buf + MBR_Table; b_cyl = 0; | |||
|
3819 | for (i = 0; i < 4; i++, p += SZ_PTE) { | |||
|
3820 | p_cyl = (szt[i] <= 100) ? (DWORD)tot_cyl * szt[i] / 100 : szt[i] / sz_cyl; | |||
|
3821 | if (!p_cyl) continue; | |||
|
3822 | s_part = (DWORD)sz_cyl * b_cyl; | |||
|
3823 | sz_part = (DWORD)sz_cyl * p_cyl; | |||
|
3824 | if (i == 0) { /* Exclude first track of cylinder 0 */ | |||
|
3825 | s_hd = 1; | |||
|
3826 | s_part += 63; sz_part -= 63; | |||
|
3827 | } else { | |||
|
3828 | s_hd = 0; | |||
|
3829 | } | |||
|
3830 | e_cyl = b_cyl + p_cyl - 1; | |||
|
3831 | if (e_cyl >= tot_cyl) return FR_INVALID_PARAMETER; | |||
|
3832 | ||||
|
3833 | /* Set partition table */ | |||
|
3834 | p[1] = s_hd; /* Start head */ | |||
|
3835 | p[2] = (BYTE)((b_cyl >> 2) + 1); /* Start sector */ | |||
|
3836 | p[3] = (BYTE)b_cyl; /* Start cylinder */ | |||
|
3837 | p[4] = 0x06; /* System type (temporary setting) */ | |||
|
3838 | p[5] = e_hd; /* End head */ | |||
|
3839 | p[6] = (BYTE)((e_cyl >> 2) + 63); /* End sector */ | |||
|
3840 | p[7] = (BYTE)e_cyl; /* End cylinder */ | |||
|
3841 | ST_DWORD(p + 8, s_part); /* Start sector in LBA */ | |||
|
3842 | ST_DWORD(p + 12, sz_part); /* Partition size */ | |||
|
3843 | ||||
|
3844 | /* Next partition */ | |||
|
3845 | b_cyl += p_cyl; | |||
|
3846 | } | |||
|
3847 | ST_WORD(p, 0xAA55); | |||
|
3848 | ||||
|
3849 | /* Write it to the MBR */ | |||
|
3850 | return (disk_write(pdrv, buf, 0, 1) || disk_ioctl(pdrv, CTRL_SYNC, 0)) ? FR_DISK_ERR : FR_OK; | |||
|
3851 | } | |||
|
3852 | ||||
|
3853 | ||||
|
3854 | #endif /* _MULTI_PARTITION == 2 */ | |||
|
3855 | #endif /* _USE_MKFS && !_FS_READONLY */ | |||
|
3856 | ||||
|
3857 | ||||
|
3858 | ||||
|
3859 | ||||
|
3860 | #if _USE_STRFUNC | |||
|
3861 | /*-----------------------------------------------------------------------*/ | |||
|
3862 | /* Get a string from the file */ | |||
|
3863 | /*-----------------------------------------------------------------------*/ | |||
|
3864 | TCHAR* f_gets ( | |||
|
3865 | TCHAR* buff, /* Pointer to the string buffer to read */ | |||
|
3866 | int len, /* Size of string buffer (characters) */ | |||
|
3867 | FIL* fil /* Pointer to the file object */ | |||
|
3868 | ) | |||
|
3869 | { | |||
|
3870 | int n = 0; | |||
|
3871 | TCHAR c, *p = buff; | |||
|
3872 | BYTE s[2]; | |||
|
3873 | UINT rc; | |||
|
3874 | ||||
|
3875 | ||||
|
3876 | while (n < len - 1) { /* Read bytes until buffer gets filled */ | |||
|
3877 | f_read(fil, s, 1, &rc); | |||
|
3878 | if (rc != 1) break; /* Break on EOF or error */ | |||
|
3879 | c = s[0]; | |||
|
3880 | #if _LFN_UNICODE /* Read a character in UTF-8 encoding */ | |||
|
3881 | if (c >= 0x80) { | |||
|
3882 | if (c < 0xC0) continue; /* Skip stray trailer */ | |||
|
3883 | if (c < 0xE0) { /* Two-byte sequense */ | |||
|
3884 | f_read(fil, s, 1, &rc); | |||
|
3885 | if (rc != 1) break; | |||
|
3886 | c = ((c & 0x1F) << 6) | (s[0] & 0x3F); | |||
|
3887 | if (c < 0x80) c = '?'; | |||
|
3888 | } else { | |||
|
3889 | if (c < 0xF0) { /* Three-byte sequense */ | |||
|
3890 | f_read(fil, s, 2, &rc); | |||
|
3891 | if (rc != 2) break; | |||
|
3892 | c = (c << 12) | ((s[0] & 0x3F) << 6) | (s[1] & 0x3F); | |||
|
3893 | if (c < 0x800) c = '?'; | |||
|
3894 | } else { /* Reject four-byte sequense */ | |||
|
3895 | c = '?'; | |||
|
3896 | } | |||
|
3897 | } | |||
|
3898 | } | |||
|
3899 | #endif | |||
|
3900 | #if _USE_STRFUNC >= 2 | |||
|
3901 | if (c == '\r') continue; /* Strip '\r' */ | |||
|
3902 | #endif | |||
|
3903 | *p++ = c; | |||
|
3904 | n++; | |||
|
3905 | if (c == '\n') break; /* Break on EOL */ | |||
|
3906 | } | |||
|
3907 | *p = 0; | |||
|
3908 | return n ? buff : 0; /* When no data read (eof or error), return with error. */ | |||
|
3909 | } | |||
|
3910 | ||||
|
3911 | ||||
|
3912 | ||||
|
3913 | #if !_FS_READONLY | |||
|
3914 | #include <stdarg.h> | |||
|
3915 | /*-----------------------------------------------------------------------*/ | |||
|
3916 | /* Put a character to the file */ | |||
|
3917 | /*-----------------------------------------------------------------------*/ | |||
|
3918 | int f_putc ( | |||
|
3919 | TCHAR c, /* A character to be output */ | |||
|
3920 | FIL* fil /* Pointer to the file object */ | |||
|
3921 | ) | |||
|
3922 | { | |||
|
3923 | UINT bw, btw; | |||
|
3924 | BYTE s[3]; | |||
|
3925 | ||||
|
3926 | ||||
|
3927 | #if _USE_STRFUNC >= 2 | |||
|
3928 | if (c == '\n') f_putc ('\r', fil); /* LF -> CRLF conversion */ | |||
|
3929 | #endif | |||
|
3930 | ||||
|
3931 | #if _LFN_UNICODE /* Write the character in UTF-8 encoding */ | |||
|
3932 | if (c < 0x80) { /* 7-bit */ | |||
|
3933 | s[0] = (BYTE)c; | |||
|
3934 | btw = 1; | |||
|
3935 | } else { | |||
|
3936 | if (c < 0x800) { /* 11-bit */ | |||
|
3937 | s[0] = (BYTE)(0xC0 | (c >> 6)); | |||
|
3938 | s[1] = (BYTE)(0x80 | (c & 0x3F)); | |||
|
3939 | btw = 2; | |||
|
3940 | } else { /* 16-bit */ | |||
|
3941 | s[0] = (BYTE)(0xE0 | (c >> 12)); | |||
|
3942 | s[1] = (BYTE)(0x80 | ((c >> 6) & 0x3F)); | |||
|
3943 | s[2] = (BYTE)(0x80 | (c & 0x3F)); | |||
|
3944 | btw = 3; | |||
|
3945 | } | |||
|
3946 | } | |||
|
3947 | #else /* Write the character without conversion */ | |||
|
3948 | s[0] = (BYTE)c; | |||
|
3949 | btw = 1; | |||
|
3950 | #endif | |||
|
3951 | f_write(fil, s, btw, &bw); /* Write the char to the file */ | |||
|
3952 | return (bw == btw) ? 1 : EOF; /* Return the result */ | |||
|
3953 | } | |||
|
3954 | ||||
|
3955 | ||||
|
3956 | ||||
|
3957 | ||||
|
3958 | /*-----------------------------------------------------------------------*/ | |||
|
3959 | /* Put a string to the file */ | |||
|
3960 | /*-----------------------------------------------------------------------*/ | |||
|
3961 | int f_puts ( | |||
|
3962 | const TCHAR* str, /* Pointer to the string to be output */ | |||
|
3963 | FIL* fil /* Pointer to the file object */ | |||
|
3964 | ) | |||
|
3965 | { | |||
|
3966 | int n; | |||
|
3967 | ||||
|
3968 | ||||
|
3969 | for (n = 0; *str; str++, n++) { | |||
|
3970 | if (f_putc(*str, fil) == EOF) return EOF; | |||
|
3971 | } | |||
|
3972 | return n; | |||
|
3973 | } | |||
|
3974 | ||||
|
3975 | ||||
|
3976 | ||||
|
3977 | ||||
|
3978 | /*-----------------------------------------------------------------------*/ | |||
|
3979 | /* Put a formatted string to the file */ | |||
|
3980 | /*-----------------------------------------------------------------------*/ | |||
|
3981 | int f_printf ( | |||
|
3982 | FIL* fil, /* Pointer to the file object */ | |||
|
3983 | const TCHAR* str, /* Pointer to the format string */ | |||
|
3984 | ... /* Optional arguments... */ | |||
|
3985 | ) | |||
|
3986 | { | |||
|
3987 | va_list arp; | |||
|
3988 | BYTE f, r; | |||
|
3989 | UINT i, j, w; | |||
|
3990 | ULONG v; | |||
|
3991 | TCHAR c, d, s[16], *p; | |||
|
3992 | int res, chc, cc; | |||
|
3993 | ||||
|
3994 | ||||
|
3995 | va_start(arp, str); | |||
|
3996 | ||||
|
3997 | for (cc = res = 0; cc != EOF; res += cc) { | |||
|
3998 | c = *str++; | |||
|
3999 | if (c == 0) break; /* End of string */ | |||
|
4000 | if (c != '%') { /* Non escape character */ | |||
|
4001 | cc = f_putc(c, fil); | |||
|
4002 | if (cc != EOF) cc = 1; | |||
|
4003 | continue; | |||
|
4004 | } | |||
|
4005 | w = f = 0; | |||
|
4006 | c = *str++; | |||
|
4007 | if (c == '0') { /* Flag: '0' padding */ | |||
|
4008 | f = 1; c = *str++; | |||
|
4009 | } else { | |||
|
4010 | if (c == '-') { /* Flag: left justified */ | |||
|
4011 | f = 2; c = *str++; | |||
|
4012 | } | |||
|
4013 | } | |||
|
4014 | while (IsDigit(c)) { /* Precision */ | |||
|
4015 | w = w * 10 + c - '0'; | |||
|
4016 | c = *str++; | |||
|
4017 | } | |||
|
4018 | if (c == 'l' || c == 'L') { /* Prefix: Size is long int */ | |||
|
4019 | f |= 4; c = *str++; | |||
|
4020 | } | |||
|
4021 | if (!c) break; | |||
|
4022 | d = c; | |||
|
4023 | if (IsLower(d)) d -= 0x20; | |||
|
4024 | switch (d) { /* Type is... */ | |||
|
4025 | case 'S' : /* String */ | |||
|
4026 | p = va_arg(arp, TCHAR*); | |||
|
4027 | for (j = 0; p[j]; j++) ; | |||
|
4028 | chc = 0; | |||
|
4029 | if (!(f & 2)) { | |||
|
4030 | while (j++ < w) chc += (cc = f_putc(' ', fil)); | |||
|
4031 | } | |||
|
4032 | chc += (cc = f_puts(p, fil)); | |||
|
4033 | while (j++ < w) chc += (cc = f_putc(' ', fil)); | |||
|
4034 | if (cc != EOF) cc = chc; | |||
|
4035 | continue; | |||
|
4036 | case 'C' : /* Character */ | |||
|
4037 | cc = f_putc((TCHAR)va_arg(arp, int), fil); continue; | |||
|
4038 | case 'B' : /* Binary */ | |||
|
4039 | r = 2; break; | |||
|
4040 | case 'O' : /* Octal */ | |||
|
4041 | r = 8; break; | |||
|
4042 | case 'D' : /* Signed decimal */ | |||
|
4043 | case 'U' : /* Unsigned decimal */ | |||
|
4044 | r = 10; break; | |||
|
4045 | case 'X' : /* Hexdecimal */ | |||
|
4046 | r = 16; break; | |||
|
4047 | default: /* Unknown type (passthrough) */ | |||
|
4048 | cc = f_putc(c, fil); continue; | |||
|
4049 | } | |||
|
4050 | ||||
|
4051 | /* Get an argument and put it in numeral */ | |||
|
4052 | v = (f & 4) ? (ULONG)va_arg(arp, long) : ((d == 'D') ? (ULONG)(long)va_arg(arp, int) : (ULONG)va_arg(arp, unsigned int)); | |||
|
4053 | if (d == 'D' && (v & 0x80000000)) { | |||
|
4054 | v = 0 - v; | |||
|
4055 | f |= 8; | |||
|
4056 | } | |||
|
4057 | i = 0; | |||
|
4058 | do { | |||
|
4059 | d = (TCHAR)(v % r); v /= r; | |||
|
4060 | if (d > 9) d += (c == 'x') ? 0x27 : 0x07; | |||
|
4061 | s[i++] = d + '0'; | |||
|
4062 | } while (v && i < sizeof(s) / sizeof(s[0])); | |||
|
4063 | if (f & 8) s[i++] = '-'; | |||
|
4064 | j = i; d = (f & 1) ? '0' : ' '; | |||
|
4065 | res = 0; | |||
|
4066 | while (!(f & 2) && j++ < w) res += (cc = f_putc(d, fil)); | |||
|
4067 | do res += (cc = f_putc(s[--i], fil)); while(i); | |||
|
4068 | while (j++ < w) res += (cc = f_putc(' ', fil)); | |||
|
4069 | if (cc != EOF) cc = res; | |||
|
4070 | } | |||
|
4071 | ||||
|
4072 | va_end(arp); | |||
|
4073 | return (cc == EOF) ? cc : res; | |||
|
4074 | } | |||
|
4075 | ||||
|
4076 | #endif /* !_FS_READONLY */ | |||
|
4077 | #endif /* _USE_STRFUNC */ |
@@ -0,0 +1,340 | |||||
|
1 | /*---------------------------------------------------------------------------/ | |||
|
2 | / FatFs - FAT file system module include file R0.09 (C)ChaN, 2011 | |||
|
3 | /----------------------------------------------------------------------------/ | |||
|
4 | / FatFs module is a generic FAT file system module for small embedded systems. | |||
|
5 | / This is a free software that opened for education, research and commercial | |||
|
6 | / developments under license policy of following trems. | |||
|
7 | / | |||
|
8 | / Copyright (C) 2011, ChaN, all right reserved. | |||
|
9 | / | |||
|
10 | / * The FatFs module is a free software and there is NO WARRANTY. | |||
|
11 | / * No restriction on use. You can use, modify and redistribute it for | |||
|
12 | / personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY. | |||
|
13 | / * Redistributions of source code must retain the above copyright notice. | |||
|
14 | / | |||
|
15 | /----------------------------------------------------------------------------*/ | |||
|
16 | ||||
|
17 | #ifndef _FATFS | |||
|
18 | #define _FATFS 6502 /* Revision ID */ | |||
|
19 | ||||
|
20 | #ifdef __cplusplus | |||
|
21 | extern "C" { | |||
|
22 | #endif | |||
|
23 | ||||
|
24 | #include "integer.h" /* Basic integer types */ | |||
|
25 | #include "ffconf.h" /* FatFs configuration options */ | |||
|
26 | #include <blkdevice.h> | |||
|
27 | ||||
|
28 | #if _FATFS != _FFCONF | |||
|
29 | #error Wrong configuration file (ffconf.h). | |||
|
30 | #endif | |||
|
31 | ||||
|
32 | ||||
|
33 | ||||
|
34 | /* Definitions of volume management */ | |||
|
35 | ||||
|
36 | #if _MULTI_PARTITION /* Multiple partition configuration */ | |||
|
37 | typedef struct { | |||
|
38 | BYTE pd; /* Physical drive number */ | |||
|
39 | BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */ | |||
|
40 | } PARTITION; | |||
|
41 | extern PARTITION VolToPart[]; /* Volume - Partition resolution table */ | |||
|
42 | #define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */ | |||
|
43 | #define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */ | |||
|
44 | ||||
|
45 | #else /* Single partition configuration */ | |||
|
46 | #define LD2PD(vol) (vol) /* Each logical drive is bound to the same physical drive number */ | |||
|
47 | #define LD2PT(vol) 0 /* Always mounts the 1st partition or in SFD */ | |||
|
48 | ||||
|
49 | #endif | |||
|
50 | ||||
|
51 | ||||
|
52 | ||||
|
53 | /* Type of path name strings on FatFs API */ | |||
|
54 | ||||
|
55 | #if _LFN_UNICODE /* Unicode string */ | |||
|
56 | #if !_USE_LFN | |||
|
57 | #error _LFN_UNICODE must be 0 in non-LFN cfg. | |||
|
58 | #endif | |||
|
59 | #ifndef _INC_TCHAR | |||
|
60 | typedef WCHAR TCHAR; | |||
|
61 | #define _T(x) L ## x | |||
|
62 | #define _TEXT(x) L ## x | |||
|
63 | #endif | |||
|
64 | ||||
|
65 | #else /* ANSI/OEM string */ | |||
|
66 | #ifndef _INC_TCHAR | |||
|
67 | typedef char TCHAR; | |||
|
68 | #define _T(x) x | |||
|
69 | #define _TEXT(x) x | |||
|
70 | #endif | |||
|
71 | ||||
|
72 | #endif | |||
|
73 | ||||
|
74 | ||||
|
75 | ||||
|
76 | /* File system object structure (FATFS) */ | |||
|
77 | ||||
|
78 | typedef struct { | |||
|
79 | BYTE fs_type; /* FAT sub-type (0:Not mounted) */ | |||
|
80 | BYTE csize; /* Sectors per cluster (1,2,4...128) */ | |||
|
81 | BYTE n_fats; /* Number of FAT copies (1,2) */ | |||
|
82 | BYTE wflag; /* win[] dirty flag (1:must be written back) */ | |||
|
83 | BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */ | |||
|
84 | /*AJE 01/06/2012*/ | |||
|
85 | //BYTE drv; /* Physical drive number */ | |||
|
86 | blkdevice* drv; | |||
|
87 | WORD id; /* File system mount ID */ | |||
|
88 | WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ | |||
|
89 | #if _MAX_SS != 512 | |||
|
90 | WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */ | |||
|
91 | #endif | |||
|
92 | #if _FS_REENTRANT | |||
|
93 | _SYNC_t sobj; /* Identifier of sync object */ | |||
|
94 | #endif | |||
|
95 | #if !_FS_READONLY | |||
|
96 | DWORD last_clust; /* Last allocated cluster */ | |||
|
97 | DWORD free_clust; /* Number of free clusters */ | |||
|
98 | DWORD fsi_sector; /* fsinfo sector (FAT32) */ | |||
|
99 | #endif | |||
|
100 | #if _FS_RPATH | |||
|
101 | DWORD cdir; /* Current directory start cluster (0:root) */ | |||
|
102 | #endif | |||
|
103 | DWORD n_fatent; /* Number of FAT entries (= number of clusters + 2) */ | |||
|
104 | DWORD fsize; /* Sectors per FAT */ | |||
|
105 | DWORD fatbase; /* FAT start sector */ | |||
|
106 | DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */ | |||
|
107 | DWORD database; /* Data start sector */ | |||
|
108 | DWORD winsect; /* Current sector appearing in the win[] */ | |||
|
109 | BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and Data on tiny cfg) */ | |||
|
110 | } FATFS; | |||
|
111 | ||||
|
112 | ||||
|
113 | ||||
|
114 | /* File object structure (FIL) */ | |||
|
115 | ||||
|
116 | typedef struct { | |||
|
117 | FATFS* fs; /* Pointer to the owner file system object */ | |||
|
118 | WORD id; /* Owner file system mount ID */ | |||
|
119 | BYTE flag; /* File status flags */ | |||
|
120 | BYTE pad1; | |||
|
121 | DWORD fptr; /* File read/write pointer (0 on file open) */ | |||
|
122 | DWORD fsize; /* File size */ | |||
|
123 | DWORD sclust; /* File start cluster (0 when fsize==0) */ | |||
|
124 | DWORD clust; /* Current cluster */ | |||
|
125 | DWORD dsect; /* Current data sector */ | |||
|
126 | #if !_FS_READONLY | |||
|
127 | DWORD dir_sect; /* Sector containing the directory entry */ | |||
|
128 | BYTE* dir_ptr; /* Ponter to the directory entry in the window */ | |||
|
129 | #endif | |||
|
130 | #if _USE_FASTSEEK | |||
|
131 | DWORD* cltbl; /* Pointer to the cluster link map table (null on file open) */ | |||
|
132 | #endif | |||
|
133 | #if _FS_SHARE | |||
|
134 | UINT lockid; /* File lock ID (index of file semaphore table) */ | |||
|
135 | #endif | |||
|
136 | #if !_FS_TINY | |||
|
137 | BYTE buf[_MAX_SS]; /* File data read/write buffer */ | |||
|
138 | #endif | |||
|
139 | } FIL; | |||
|
140 | ||||
|
141 | ||||
|
142 | ||||
|
143 | /* Directory object structure (DIR) */ | |||
|
144 | ||||
|
145 | typedef struct { | |||
|
146 | FATFS* fs; /* Pointer to the owner file system object */ | |||
|
147 | WORD id; /* Owner file system mount ID */ | |||
|
148 | WORD index; /* Current read/write index number */ | |||
|
149 | DWORD sclust; /* Table start cluster (0:Root dir) */ | |||
|
150 | DWORD clust; /* Current cluster */ | |||
|
151 | DWORD sect; /* Current sector */ | |||
|
152 | BYTE* dir; /* Pointer to the current SFN entry in the win[] */ | |||
|
153 | BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */ | |||
|
154 | #if _USE_LFN | |||
|
155 | WCHAR* lfn; /* Pointer to the LFN working buffer */ | |||
|
156 | WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */ | |||
|
157 | #endif | |||
|
158 | } DIR; | |||
|
159 | ||||
|
160 | ||||
|
161 | ||||
|
162 | /* File status structure (FILINFO) */ | |||
|
163 | ||||
|
164 | typedef struct { | |||
|
165 | DWORD fsize; /* File size */ | |||
|
166 | WORD fdate; /* Last modified date */ | |||
|
167 | WORD ftime; /* Last modified time */ | |||
|
168 | BYTE fattrib; /* Attribute */ | |||
|
169 | TCHAR fname[13]; /* Short file name (8.3 format) */ | |||
|
170 | #if _USE_LFN | |||
|
171 | TCHAR* lfname; /* Pointer to the LFN buffer */ | |||
|
172 | UINT lfsize; /* Size of LFN buffer in TCHAR */ | |||
|
173 | #endif | |||
|
174 | } FILINFO; | |||
|
175 | ||||
|
176 | ||||
|
177 | ||||
|
178 | /* File function return code (FRESULT) */ | |||
|
179 | ||||
|
180 | typedef enum { | |||
|
181 | FR_OK = 0, /* (0) Succeeded */ | |||
|
182 | FR_DISK_ERR, /* (1) A hard error occured in the low level disk I/O layer */ | |||
|
183 | FR_INT_ERR, /* (2) Assertion failed */ | |||
|
184 | FR_NOT_READY, /* (3) The physical drive cannot work */ | |||
|
185 | FR_NO_FILE, /* (4) Could not find the file */ | |||
|
186 | FR_NO_PATH, /* (5) Could not find the path */ | |||
|
187 | FR_INVALID_NAME, /* (6) The path name format is invalid */ | |||
|
188 | FR_DENIED, /* (7) Acces denied due to prohibited access or directory full */ | |||
|
189 | FR_EXIST, /* (8) Acces denied due to prohibited access */ | |||
|
190 | FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */ | |||
|
191 | FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */ | |||
|
192 | FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */ | |||
|
193 | FR_NOT_ENABLED, /* (12) The volume has no work area */ | |||
|
194 | FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */ | |||
|
195 | FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */ | |||
|
196 | FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */ | |||
|
197 | FR_LOCKED, /* (16) The operation is rejected according to the file shareing policy */ | |||
|
198 | FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */ | |||
|
199 | FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */ | |||
|
200 | FR_INVALID_PARAMETER /* (19) Given parameter is invalid */ | |||
|
201 | } FRESULT; | |||
|
202 | ||||
|
203 | ||||
|
204 | ||||
|
205 | /*--------------------------------------------------------------*/ | |||
|
206 | /* FatFs module application interface */ | |||
|
207 | ||||
|
208 | FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */ | |||
|
209 | FRESULT f_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */ | |||
|
210 | FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */ | |||
|
211 | FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */ | |||
|
212 | FRESULT f_close (FIL*); /* Close an open file object */ | |||
|
213 | FRESULT f_opendir (DIR*, const TCHAR*); /* Open an existing directory */ | |||
|
214 | FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */ | |||
|
215 | FRESULT f_stat (const TCHAR*, FILINFO*); /* Get file status */ | |||
|
216 | FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */ | |||
|
217 | FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ | |||
|
218 | FRESULT f_truncate (FIL*); /* Truncate file */ | |||
|
219 | FRESULT f_sync (FIL*); /* Flush cached data of a writing file */ | |||
|
220 | FRESULT f_unlink (const TCHAR*); /* Delete an existing file or directory */ | |||
|
221 | FRESULT f_mkdir (const TCHAR*); /* Create a new directory */ | |||
|
222 | FRESULT f_chmod (const TCHAR*, BYTE, BYTE); /* Change attriburte of the file/dir */ | |||
|
223 | FRESULT f_utime (const TCHAR*, const FILINFO*); /* Change timestamp of the file/dir */ | |||
|
224 | FRESULT f_rename (const TCHAR*, const TCHAR*); /* Rename/Move a file or directory */ | |||
|
225 | FRESULT f_chdrive (BYTE); /* Change current drive */ | |||
|
226 | FRESULT f_chdir (const TCHAR*); /* Change current directory */ | |||
|
227 | FRESULT f_getcwd (TCHAR*, UINT); /* Get current directory */ | |||
|
228 | FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */ | |||
|
229 | FRESULT f_mkfs (BYTE, BYTE, UINT); /* Create a file system on the drive */ | |||
|
230 | FRESULT f_fdisk (BYTE, const DWORD[], void*); /* Divide a physical drive into some partitions */ | |||
|
231 | int f_putc (TCHAR, FIL*); /* Put a character to the file */ | |||
|
232 | int f_puts (const TCHAR*, FIL*); /* Put a string to the file */ | |||
|
233 | int f_printf (FIL*, const TCHAR*, ...); /* Put a formatted string to the file */ | |||
|
234 | TCHAR* f_gets (TCHAR*, int, FIL*); /* Get a string from the file */ | |||
|
235 | ||||
|
236 | #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0) | |||
|
237 | #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0) | |||
|
238 | #define f_tell(fp) ((fp)->fptr) | |||
|
239 | #define f_size(fp) ((fp)->fsize) | |||
|
240 | ||||
|
241 | #ifndef EOF | |||
|
242 | #define EOF (-1) | |||
|
243 | #endif | |||
|
244 | ||||
|
245 | ||||
|
246 | ||||
|
247 | ||||
|
248 | /*--------------------------------------------------------------*/ | |||
|
249 | /* Additional user defined functions */ | |||
|
250 | ||||
|
251 | /* RTC function */ | |||
|
252 | #if !_FS_READONLY | |||
|
253 | DWORD get_fattime (void); | |||
|
254 | #endif | |||
|
255 | ||||
|
256 | /* Unicode support functions */ | |||
|
257 | #if _USE_LFN /* Unicode - OEM code conversion */ | |||
|
258 | WCHAR ff_convert (WCHAR, UINT); /* OEM-Unicode bidirectional conversion */ | |||
|
259 | WCHAR ff_wtoupper (WCHAR); /* Unicode upper-case conversion */ | |||
|
260 | #if _USE_LFN == 3 /* Memory functions */ | |||
|
261 | void* ff_memalloc (UINT); /* Allocate memory block */ | |||
|
262 | void ff_memfree (void*); /* Free memory block */ | |||
|
263 | #endif | |||
|
264 | #endif | |||
|
265 | ||||
|
266 | /* Sync functions */ | |||
|
267 | #if _FS_REENTRANT | |||
|
268 | int ff_cre_syncobj (BYTE, _SYNC_t*);/* Create a sync object */ | |||
|
269 | int ff_req_grant (_SYNC_t); /* Lock sync object */ | |||
|
270 | void ff_rel_grant (_SYNC_t); /* Unlock sync object */ | |||
|
271 | int ff_del_syncobj (_SYNC_t); /* Delete a sync object */ | |||
|
272 | #endif | |||
|
273 | ||||
|
274 | ||||
|
275 | ||||
|
276 | ||||
|
277 | /*--------------------------------------------------------------*/ | |||
|
278 | /* Flags and offset address */ | |||
|
279 | ||||
|
280 | ||||
|
281 | /* File access control and file status flags (FIL.flag) */ | |||
|
282 | ||||
|
283 | #define FA_READ 0x01 | |||
|
284 | #define FA_OPEN_EXISTING 0x00 | |||
|
285 | #define FA__ERROR 0x80 | |||
|
286 | ||||
|
287 | #if !_FS_READONLY | |||
|
288 | #define FA_WRITE 0x02 | |||
|
289 | #define FA_CREATE_NEW 0x04 | |||
|
290 | #define FA_CREATE_ALWAYS 0x08 | |||
|
291 | #define FA_OPEN_ALWAYS 0x10 | |||
|
292 | #define FA__WRITTEN 0x20 | |||
|
293 | #define FA__DIRTY 0x40 | |||
|
294 | #endif | |||
|
295 | ||||
|
296 | ||||
|
297 | /* FAT sub type (FATFS.fs_type) */ | |||
|
298 | ||||
|
299 | #define FS_FAT12 1 | |||
|
300 | #define FS_FAT16 2 | |||
|
301 | #define FS_FAT32 3 | |||
|
302 | ||||
|
303 | ||||
|
304 | /* File attribute bits for directory entry */ | |||
|
305 | ||||
|
306 | #define AM_RDO 0x01 /* Read only */ | |||
|
307 | #define AM_HID 0x02 /* Hidden */ | |||
|
308 | #define AM_SYS 0x04 /* System */ | |||
|
309 | #define AM_VOL 0x08 /* Volume label */ | |||
|
310 | #define AM_LFN 0x0F /* LFN entry */ | |||
|
311 | #define AM_DIR 0x10 /* Directory */ | |||
|
312 | #define AM_ARC 0x20 /* Archive */ | |||
|
313 | #define AM_MASK 0x3F /* Mask of defined bits */ | |||
|
314 | ||||
|
315 | ||||
|
316 | /* Fast seek feature */ | |||
|
317 | #define CREATE_LINKMAP 0xFFFFFFFF | |||
|
318 | ||||
|
319 | ||||
|
320 | ||||
|
321 | /*--------------------------------*/ | |||
|
322 | /* Multi-byte word access macros */ | |||
|
323 | ||||
|
324 | #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */ | |||
|
325 | #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr)) | |||
|
326 | #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr)) | |||
|
327 | #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val) | |||
|
328 | #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val) | |||
|
329 | #else /* Use byte-by-byte access to the FAT structure */ | |||
|
330 | #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr)) | |||
|
331 | #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr)) | |||
|
332 | #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8) | |||
|
333 | #define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24) | |||
|
334 | #endif | |||
|
335 | ||||
|
336 | #ifdef __cplusplus | |||
|
337 | } | |||
|
338 | #endif | |||
|
339 | ||||
|
340 | #endif /* _FATFS */ |
@@ -0,0 +1,26 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | lpc17XX.ARCH = lpc17XX-arm-noabi-gcc | |||
|
3 | lpc17XX.TARGET = libfat32 | |||
|
4 | lpc17XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_FAT32) | |||
|
5 | lpc17XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FAT32) | |||
|
6 | ||||
|
7 | lpc17XX.LIBS += BLKDEVICE | |||
|
8 | ||||
|
9 | lpc17XX.SOURCES += fat32.c | |||
|
10 | ||||
|
11 | ||||
|
12 | lpc17XX.HEADERS += fat32.h | |||
|
13 | ||||
|
14 | ||||
|
15 | ||||
|
16 | lpc21XX.ARCH = lpc21XX-arm-noabi-gcc | |||
|
17 | lpc21XX.TARGET = libfat32 | |||
|
18 | lpc21XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_FAT32) | |||
|
19 | lpc21XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_FAT32) | |||
|
20 | ||||
|
21 | lpc21XX.LIBS += BLKDEVICE | |||
|
22 | ||||
|
23 | lpc21XX.SOURCES += fat32.c | |||
|
24 | ||||
|
25 | ||||
|
26 | lpc21XX.HEADERS += fat32.h |
@@ -0,0 +1,190 | |||||
|
1 | /*---------------------------------------------------------------------------/ | |||
|
2 | / FatFs - FAT file system module configuration file R0.09 (C)ChaN, 2011 | |||
|
3 | /----------------------------------------------------------------------------/ | |||
|
4 | / | |||
|
5 | / CAUTION! Do not forget to make clean the project after any changes to | |||
|
6 | / the configuration options. | |||
|
7 | / | |||
|
8 | /----------------------------------------------------------------------------*/ | |||
|
9 | #ifndef _FFCONF | |||
|
10 | #define _FFCONF 6502 /* Revision ID */ | |||
|
11 | ||||
|
12 | ||||
|
13 | /*---------------------------------------------------------------------------/ | |||
|
14 | / Functions and Buffer Configurations | |||
|
15 | /----------------------------------------------------------------------------*/ | |||
|
16 | ||||
|
17 | #define _FS_TINY 0 /* 0:Normal or 1:Tiny */ | |||
|
18 | /* When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system | |||
|
19 | / object instead of the sector buffer in the individual file object for file | |||
|
20 | / data transfer. This reduces memory consumption 512 bytes each file object. */ | |||
|
21 | ||||
|
22 | ||||
|
23 | #define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */ | |||
|
24 | /* Setting _FS_READONLY to 1 defines read only configuration. This removes | |||
|
25 | / writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename, | |||
|
26 | / f_truncate and useless f_getfree. */ | |||
|
27 | ||||
|
28 | ||||
|
29 | #define _FS_MINIMIZE 0 /* 0 to 3 */ | |||
|
30 | /* The _FS_MINIMIZE option defines minimization level to remove some functions. | |||
|
31 | / | |||
|
32 | / 0: Full function. | |||
|
33 | / 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename | |||
|
34 | / are removed. | |||
|
35 | / 2: f_opendir and f_readdir are removed in addition to 1. | |||
|
36 | / 3: f_lseek is removed in addition to 2. */ | |||
|
37 | ||||
|
38 | ||||
|
39 | #define _USE_STRFUNC 0 /* 0:Disable or 1-2:Enable */ | |||
|
40 | /* To enable string functions, set _USE_STRFUNC to 1 or 2. */ | |||
|
41 | ||||
|
42 | ||||
|
43 | #define _USE_MKFS 0 /* 0:Disable or 1:Enable */ | |||
|
44 | /* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */ | |||
|
45 | ||||
|
46 | ||||
|
47 | #define _USE_FORWARD 0 /* 0:Disable or 1:Enable */ | |||
|
48 | /* To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */ | |||
|
49 | ||||
|
50 | ||||
|
51 | #define _USE_FASTSEEK 0 /* 0:Disable or 1:Enable */ | |||
|
52 | /* To enable fast seek feature, set _USE_FASTSEEK to 1. */ | |||
|
53 | ||||
|
54 | ||||
|
55 | ||||
|
56 | /*---------------------------------------------------------------------------/ | |||
|
57 | / Locale and Namespace Configurations | |||
|
58 | /----------------------------------------------------------------------------*/ | |||
|
59 | ||||
|
60 | #define _CODE_PAGE 932 | |||
|
61 | /* The _CODE_PAGE specifies the OEM code page to be used on the target system. | |||
|
62 | / Incorrect setting of the code page can cause a file open failure. | |||
|
63 | / | |||
|
64 | / 932 - Japanese Shift-JIS (DBCS, OEM, Windows) | |||
|
65 | / 936 - Simplified Chinese GBK (DBCS, OEM, Windows) | |||
|
66 | / 949 - Korean (DBCS, OEM, Windows) | |||
|
67 | / 950 - Traditional Chinese Big5 (DBCS, OEM, Windows) | |||
|
68 | / 1250 - Central Europe (Windows) | |||
|
69 | / 1251 - Cyrillic (Windows) | |||
|
70 | / 1252 - Latin 1 (Windows) | |||
|
71 | / 1253 - Greek (Windows) | |||
|
72 | / 1254 - Turkish (Windows) | |||
|
73 | / 1255 - Hebrew (Windows) | |||
|
74 | / 1256 - Arabic (Windows) | |||
|
75 | / 1257 - Baltic (Windows) | |||
|
76 | / 1258 - Vietnam (OEM, Windows) | |||
|
77 | / 437 - U.S. (OEM) | |||
|
78 | / 720 - Arabic (OEM) | |||
|
79 | / 737 - Greek (OEM) | |||
|
80 | / 775 - Baltic (OEM) | |||
|
81 | / 850 - Multilingual Latin 1 (OEM) | |||
|
82 | / 858 - Multilingual Latin 1 + Euro (OEM) | |||
|
83 | / 852 - Latin 2 (OEM) | |||
|
84 | / 855 - Cyrillic (OEM) | |||
|
85 | / 866 - Russian (OEM) | |||
|
86 | / 857 - Turkish (OEM) | |||
|
87 | / 862 - Hebrew (OEM) | |||
|
88 | / 874 - Thai (OEM, Windows) | |||
|
89 | / 1 - ASCII only (Valid for non LFN cfg.) | |||
|
90 | */ | |||
|
91 | ||||
|
92 | ||||
|
93 | #define _USE_LFN 0 /* 0 to 3 */ | |||
|
94 | #define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */ | |||
|
95 | /* The _USE_LFN option switches the LFN support. | |||
|
96 | / | |||
|
97 | / 0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect. | |||
|
98 | / 1: Enable LFN with static working buffer on the BSS. Always NOT reentrant. | |||
|
99 | / 2: Enable LFN with dynamic working buffer on the STACK. | |||
|
100 | / 3: Enable LFN with dynamic working buffer on the HEAP. | |||
|
101 | / | |||
|
102 | / The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. To enable LFN, | |||
|
103 | / Unicode handling functions ff_convert() and ff_wtoupper() must be added | |||
|
104 | / to the project. When enable to use heap, memory control functions | |||
|
105 | / ff_memalloc() and ff_memfree() must be added to the project. */ | |||
|
106 | ||||
|
107 | ||||
|
108 | #define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */ | |||
|
109 | /* To switch the character code set on FatFs API to Unicode, | |||
|
110 | / enable LFN feature and set _LFN_UNICODE to 1. */ | |||
|
111 | ||||
|
112 | ||||
|
113 | #define _FS_RPATH 0 /* 0 to 2 */ | |||
|
114 | /* The _FS_RPATH option configures relative path feature. | |||
|
115 | / | |||
|
116 | / 0: Disable relative path feature and remove related functions. | |||
|
117 | / 1: Enable relative path. f_chdrive() and f_chdir() are available. | |||
|
118 | / 2: f_getcwd() is available in addition to 1. | |||
|
119 | / | |||
|
120 | / Note that output of the f_readdir fnction is affected by this option. */ | |||
|
121 | ||||
|
122 | ||||
|
123 | ||||
|
124 | /*---------------------------------------------------------------------------/ | |||
|
125 | / Physical Drive Configurations | |||
|
126 | /----------------------------------------------------------------------------*/ | |||
|
127 | ||||
|
128 | #define _VOLUMES 1 | |||
|
129 | /* Number of volumes (logical drives) to be used. */ | |||
|
130 | ||||
|
131 | ||||
|
132 | #define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */ | |||
|
133 | /* Maximum sector size to be handled. | |||
|
134 | / Always set 512 for memory card and hard disk but a larger value may be | |||
|
135 | / required for on-board flash memory, floppy disk and optical disk. | |||
|
136 | / When _MAX_SS is larger than 512, it configures FatFs to variable sector size | |||
|
137 | / and GET_SECTOR_SIZE command must be implememted to the disk_ioctl function. */ | |||
|
138 | ||||
|
139 | ||||
|
140 | #define _MULTI_PARTITION 0 /* 0:Single partition, 1/2:Enable multiple partition */ | |||
|
141 | /* When set to 0, each volume is bound to the same physical drive number and | |||
|
142 | / it can mount only first primaly partition. When it is set to 1, each volume | |||
|
143 | / is tied to the partitions listed in VolToPart[]. */ | |||
|
144 | ||||
|
145 | ||||
|
146 | #define _USE_ERASE 0 /* 0:Disable or 1:Enable */ | |||
|
147 | /* To enable sector erase feature, set _USE_ERASE to 1. CTRL_ERASE_SECTOR command | |||
|
148 | / should be added to the disk_ioctl functio. */ | |||
|
149 | ||||
|
150 | ||||
|
151 | ||||
|
152 | /*---------------------------------------------------------------------------/ | |||
|
153 | / System Configurations | |||
|
154 | /----------------------------------------------------------------------------*/ | |||
|
155 | ||||
|
156 | #define _WORD_ACCESS 0 /* 0 or 1 */ | |||
|
157 | /* Set 0 first and it is always compatible with all platforms. The _WORD_ACCESS | |||
|
158 | / option defines which access method is used to the word data on the FAT volume. | |||
|
159 | / | |||
|
160 | / 0: Byte-by-byte access. | |||
|
161 | / 1: Word access. Do not choose this unless following condition is met. | |||
|
162 | / | |||
|
163 | / When the byte order on the memory is big-endian or address miss-aligned word | |||
|
164 | / access results incorrect behavior, the _WORD_ACCESS must be set to 0. | |||
|
165 | / If it is not the case, the value can also be set to 1 to improve the | |||
|
166 | / performance and code size. | |||
|
167 | */ | |||
|
168 | ||||
|
169 | ||||
|
170 | /* A header file that defines sync object types on the O/S, such as | |||
|
171 | / windows.h, ucos_ii.h and semphr.h, must be included prior to ff.h. */ | |||
|
172 | ||||
|
173 | #define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */ | |||
|
174 | #define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */ | |||
|
175 | #define _SYNC_t HANDLE /* O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc.. */ | |||
|
176 | ||||
|
177 | /* The _FS_REENTRANT option switches the reentrancy (thread safe) of the FatFs module. | |||
|
178 | / | |||
|
179 | / 0: Disable reentrancy. _SYNC_t and _FS_TIMEOUT have no effect. | |||
|
180 | / 1: Enable reentrancy. Also user provided synchronization handlers, | |||
|
181 | / ff_req_grant, ff_rel_grant, ff_del_syncobj and ff_cre_syncobj | |||
|
182 | / function must be added to the project. */ | |||
|
183 | ||||
|
184 | ||||
|
185 | #define _FS_SHARE 0 /* 0:Disable or >=1:Enable */ | |||
|
186 | /* To enable file shareing feature, set _FS_SHARE to 1 or greater. The value | |||
|
187 | defines how many files can be opened simultaneously. */ | |||
|
188 | ||||
|
189 | ||||
|
190 | #endif /* _FFCONFIG */ |
@@ -0,0 +1,37 | |||||
|
1 | /*-------------------------------------------*/ | |||
|
2 | /* Integer type definitions for FatFs module */ | |||
|
3 | /*-------------------------------------------*/ | |||
|
4 | ||||
|
5 | #ifndef _INTEGER | |||
|
6 | #define _INTEGER | |||
|
7 | ||||
|
8 | #ifdef _WIN32 /* FatFs development platform */ | |||
|
9 | ||||
|
10 | #include <windows.h> | |||
|
11 | #include <tchar.h> | |||
|
12 | ||||
|
13 | #else /* Embedded platform */ | |||
|
14 | ||||
|
15 | /* These types must be 16-bit, 32-bit or larger integer */ | |||
|
16 | typedef int INT; | |||
|
17 | typedef unsigned int UINT; | |||
|
18 | ||||
|
19 | /* These types must be 8-bit integer */ | |||
|
20 | typedef char CHAR; | |||
|
21 | typedef unsigned char UCHAR; | |||
|
22 | typedef unsigned char BYTE; | |||
|
23 | ||||
|
24 | /* These types must be 16-bit integer */ | |||
|
25 | typedef short SHORT; | |||
|
26 | typedef unsigned short USHORT; | |||
|
27 | typedef unsigned short WORD; | |||
|
28 | typedef unsigned short WCHAR; | |||
|
29 | ||||
|
30 | /* These types must be 32-bit integer */ | |||
|
31 | typedef long LONG; | |||
|
32 | typedef unsigned long ULONG; | |||
|
33 | typedef unsigned long DWORD; | |||
|
34 | ||||
|
35 | #endif | |||
|
36 | ||||
|
37 | #endif |
@@ -0,0 +1,30 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_IIC) | |||
|
6 | HEADERS += iic.h | |||
|
7 | LIBSOURCES += iic.c | |||
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
12 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
14 | TARGET=libiic | |||
|
15 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
16 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
17 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_IIC) | |||
|
18 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_IIC) | |||
|
19 | BSP=generic | |||
|
20 | include $(ARCHFOLDER)/rules.mk | |||
|
21 | ||||
|
22 | all:lib | |||
|
23 | @echo Code compiled | |||
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -0,0 +1,350 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #include "iic.h" | |||
|
23 | #include "core.h" | |||
|
24 | ||||
|
25 | #define iicputdata(iicdev,W,IICONSET,IICONCLR) {((_i2cDev)(iicdev))->I2DAT = (W);\ | |||
|
26 | ((_i2cDev)(iicdev))->I2CONSET = (IICONSET);\ | |||
|
27 | ((_i2cDev)(iicdev))->I2CONCLR = (IICONCLR);} | |||
|
28 | ||||
|
29 | #define iicgetdata(iicdev,W,IICONSET,IICONCLR) {(W) = ((_i2cDev)(iicdev))->I2DAT;\ | |||
|
30 | ((_i2cDev)(iicdev))->I2CONSET = (IICONSET);\ | |||
|
31 | ((_i2cDev)(iicdev))->I2CONCLR = (IICONCLR);} | |||
|
32 | ||||
|
33 | i2ctrl i2cwrite2(i2cDev dev,char address,char*cmd,int* cmdcnt,char*data,int* datcnt) | |||
|
34 | { | |||
|
35 | char iicdat=0; | |||
|
36 | ((_i2cDev)dev)->I2CONCLR = 0x28; | |||
|
37 | iicdat = (address<<1) & 0xFE; | |||
|
38 | int count = (*datcnt) + 2; | |||
|
39 | (*datcnt) = 0; | |||
|
40 | while(((_i2cDev)dev)->I2STAT != 0xF8); //waiting for device to be ready /!\ should add timeout | |||
|
41 | ((_i2cDev)dev)->I2CONSET = (1<<5); //initiate transfert | |||
|
42 | while(count>0) | |||
|
43 | { | |||
|
44 | while((((_i2cDev)dev)->I2CONSET & 0x08)!=0x08); | |||
|
45 | switch(((_i2cDev)dev)->I2STAT) | |||
|
46 | { | |||
|
47 | case 0x08: | |||
|
48 | iicputdata(dev,iicdat,(1<<2),0x28); | |||
|
49 | iicdat = *cmd++; | |||
|
50 | break; | |||
|
51 | case 0x10: | |||
|
52 | iicputdata(dev,iicdat,(1<<2),0x28); | |||
|
53 | iicdat = *cmd++; | |||
|
54 | *cmdcnt = (*cmdcnt) - 1; | |||
|
55 | break; | |||
|
56 | case 0x18: | |||
|
57 | iicputdata(dev,iicdat,0,0x08); | |||
|
58 | if((*cmdcnt)>1) | |||
|
59 | { | |||
|
60 | iicdat = *cmd++; | |||
|
61 | *cmdcnt = (*cmdcnt) - 1; | |||
|
62 | } | |||
|
63 | else | |||
|
64 | { | |||
|
65 | count--; | |||
|
66 | iicdat = *data++; | |||
|
67 | } | |||
|
68 | break; | |||
|
69 | case 0x28: | |||
|
70 | iicputdata(dev,iicdat,(1<<2),0x08); | |||
|
71 | if((*cmdcnt)>1) | |||
|
72 | { | |||
|
73 | iicdat = *cmd++; | |||
|
74 | *cmdcnt = (*cmdcnt) - 1; | |||
|
75 | } | |||
|
76 | else | |||
|
77 | { | |||
|
78 | count--; | |||
|
79 | *datcnt = (*datcnt)+1; | |||
|
80 | iicdat = *data++; | |||
|
81 | } | |||
|
82 | break; | |||
|
83 | case 0x20: | |||
|
84 | return i2noack; | |||
|
85 | count = 0; | |||
|
86 | break; | |||
|
87 | case 0x30: | |||
|
88 | return i2noack; | |||
|
89 | count = 0; | |||
|
90 | break; | |||
|
91 | case 0x38: | |||
|
92 | return i2arbloss; | |||
|
93 | count = 0; | |||
|
94 | break; | |||
|
95 | default: | |||
|
96 | break; | |||
|
97 | } | |||
|
98 | ||||
|
99 | } | |||
|
100 | ((_i2cDev)dev)->I2CONSET = (1<<4) + (1<<2); | |||
|
101 | ((_i2cDev)dev)->I2CONCLR = 1<<3; | |||
|
102 | return i2noerr; | |||
|
103 | } | |||
|
104 | ||||
|
105 | ||||
|
106 | ||||
|
107 | i2ctrl i2cwrite(i2cDev dev,char address,char*data,int* cnt) | |||
|
108 | { | |||
|
109 | char iicdat=0; | |||
|
110 | ((_i2cDev)dev)->I2CONCLR = 0x28; | |||
|
111 | iicdat = (address<<1) & 0xFE; | |||
|
112 | int count = (*cnt) + 1; | |||
|
113 | *cnt = 0; | |||
|
114 | while(((_i2cDev)dev)->I2STAT != 0xF8); //waiting for device to be ready /!\ should add timeout | |||
|
115 | ((_i2cDev)dev)->I2CONSET = (1<<5); //initiate transfert | |||
|
116 | while(count>0) | |||
|
117 | { | |||
|
118 | while((((_i2cDev)dev)->I2CONSET & 0x08)!=0x08); | |||
|
119 | switch(((_i2cDev)dev)->I2STAT) | |||
|
120 | { | |||
|
121 | case 0x08: | |||
|
122 | iicputdata(dev,iicdat,(1<<2),0x28); | |||
|
123 | iicdat = *data++; | |||
|
124 | break; | |||
|
125 | case 0x10: | |||
|
126 | iicputdata(dev,iicdat,(1<<2),0x28); | |||
|
127 | iicdat = *data++; | |||
|
128 | break; | |||
|
129 | case 0x18: | |||
|
130 | iicputdata(dev,iicdat,0,0x08); | |||
|
131 | count--; | |||
|
132 | iicdat = *data++; | |||
|
133 | break; | |||
|
134 | case 0x28: | |||
|
135 | iicputdata(dev,iicdat,(1<<2),0x08); | |||
|
136 | *cnt = (*cnt)+1; | |||
|
137 | count--; | |||
|
138 | iicdat = *data++; | |||
|
139 | break; | |||
|
140 | case 0x20: | |||
|
141 | return i2noack; | |||
|
142 | count = 0; | |||
|
143 | break; | |||
|
144 | case 0x30: | |||
|
145 | return i2noack; | |||
|
146 | count = 0; | |||
|
147 | break; | |||
|
148 | case 0x38: | |||
|
149 | return i2arbloss; | |||
|
150 | count = 0; | |||
|
151 | break; | |||
|
152 | default: | |||
|
153 | break; | |||
|
154 | } | |||
|
155 | ||||
|
156 | } | |||
|
157 | ((_i2cDev)dev)->I2CONSET = (1<<4) + (1<<2); | |||
|
158 | ((_i2cDev)dev)->I2CONCLR = 1<<3; | |||
|
159 | return i2noerr; | |||
|
160 | } | |||
|
161 | ||||
|
162 | ||||
|
163 | i2ctrl i2cread(i2cDev dev,char address,char*data,int* cnt) | |||
|
164 | { | |||
|
165 | char iicdat=0; | |||
|
166 | ((_i2cDev)dev)->I2CONCLR = 0x28; | |||
|
167 | iicdat = (address<<1) + 1; | |||
|
168 | unsigned int count = (*cnt); | |||
|
169 | *cnt = 0; | |||
|
170 | while(((_i2cDev)dev)->I2STAT != 0xF8); //waiting for device to be ready /!\ should add timeout | |||
|
171 | ((_i2cDev)dev)->I2CONSET = (1<<5); //initiate transfert | |||
|
172 | while(count!=0) | |||
|
173 | { | |||
|
174 | while((((_i2cDev)dev)->I2CONSET & 0x08)!=0x08); | |||
|
175 | switch(((_i2cDev)dev)->I2STAT) | |||
|
176 | { | |||
|
177 | while((((_i2cDev)dev)->I2CONSET & (1<<3))!=(1<<3)); | |||
|
178 | case 0x08: | |||
|
179 | iicputdata(dev,iicdat,(1<<2),0x28); | |||
|
180 | break; | |||
|
181 | case 0x10: | |||
|
182 | iicputdata(dev,iicdat,(1<<2),0x28); | |||
|
183 | break; | |||
|
184 | case 0x40: | |||
|
185 | if((count!=1)) ((_i2cDev)dev)->I2CONSET = (1<<2); | |||
|
186 | else ((_i2cDev)dev)->I2CONCLR = (1<<2); | |||
|
187 | ((_i2cDev)dev)->I2CONCLR = 1<<3; | |||
|
188 | break; | |||
|
189 | case 0x50: | |||
|
190 | if((count==2)) iicgetdata(dev,iicdat,(0),(0x0c)) | |||
|
191 | else iicgetdata(dev,iicdat,(4),(8)) | |||
|
192 | count--; | |||
|
193 | *cnt = (*cnt) + 1; | |||
|
194 | *data = iicdat; | |||
|
195 | data++; | |||
|
196 | break; | |||
|
197 | case 0x48: | |||
|
198 | ((_i2cDev)dev)->I2CONSET = 0x14; | |||
|
199 | ((_i2cDev)dev)->I2CONCLR = 8; | |||
|
200 | return i2noerr; | |||
|
201 | break; | |||
|
202 | case 0x58: | |||
|
203 | iicgetdata(dev,iicdat,(0x14),(8)); | |||
|
204 | count--; | |||
|
205 | *cnt = (*cnt) + 1; | |||
|
206 | *data = iicdat; | |||
|
207 | data++; | |||
|
208 | return i2noerr; | |||
|
209 | break; | |||
|
210 | default: | |||
|
211 | break; | |||
|
212 | } | |||
|
213 | ||||
|
214 | } | |||
|
215 | ((_i2cDev)dev)->I2CONSET = (1<<4); | |||
|
216 | ((_i2cDev)dev)->I2CONCLR =(1<<2); | |||
|
217 | ((_i2cDev)dev)->I2CONCLR = 1<<3; | |||
|
218 | return i2noerr; | |||
|
219 | } | |||
|
220 | ||||
|
221 | ||||
|
222 | void i2csetup(i2cDev dev,int clkH,int clkL) | |||
|
223 | { | |||
|
224 | ((_i2cDev)dev)->I2CONCLR = 0x6C; | |||
|
225 | ((_i2cDev)dev)->I2SCLH = clkH; | |||
|
226 | ((_i2cDev)dev)->I2SCLL = clkL; | |||
|
227 | ((_i2cDev)dev)->I2CONSET = 1<<6; //enable I2C block | |||
|
228 | ((_i2cDev)dev)->I2CONCLR = 0x28; | |||
|
229 | } | |||
|
230 | ||||
|
231 | ||||
|
232 | void i2cenable(i2cDev dev) | |||
|
233 | { | |||
|
234 | ((_i2cDev)dev)->I2CONSET = 1<<6; | |||
|
235 | } | |||
|
236 | ||||
|
237 | ||||
|
238 | void i2cdisable(i2cDev dev) | |||
|
239 | { | |||
|
240 | ((_i2cDev)dev)->I2CONCLR = (1<<6); | |||
|
241 | } | |||
|
242 | ||||
|
243 | ||||
|
244 | i2cDev i2copen(int count){ | |||
|
245 | i2cDev dev; | |||
|
246 | switch(count) | |||
|
247 | { | |||
|
248 | case 0: | |||
|
249 | dev = (i2cDev)((unsigned long)I2C0_BASE_ADDR); | |||
|
250 | break; | |||
|
251 | case 1: | |||
|
252 | dev = (i2cDev)((unsigned long)I2C1_BASE_ADDR); | |||
|
253 | break; | |||
|
254 | case 2: | |||
|
255 | dev = (i2cDev)((unsigned long)I2C2_BASE_ADDR); | |||
|
256 | break; | |||
|
257 | default: | |||
|
258 | dev = (i2cDev)0; | |||
|
259 | break; | |||
|
260 | } | |||
|
261 | return dev; | |||
|
262 | } | |||
|
263 | ||||
|
264 | ||||
|
265 | ||||
|
266 | unsigned char i2cgetpclkfactor(i2cDev dev) | |||
|
267 | { | |||
|
268 | unsigned int clksel=0; | |||
|
269 | const char clkselDec[]={4,1,2,8}; | |||
|
270 | switch((int)dev) | |||
|
271 | { | |||
|
272 | case (int)I2C0_BASE_ADDR: | |||
|
273 | clksel = (PCLKSEL0>>14) & 3; | |||
|
274 | break; | |||
|
275 | case (int)I2C1_BASE_ADDR: | |||
|
276 | clksel = (PCLKSEL1>>6) & 3; | |||
|
277 | break; | |||
|
278 | case (int)I2C2_BASE_ADDR: | |||
|
279 | clksel = (PCLKSEL1>>20) & 3; | |||
|
280 | break; | |||
|
281 | default: | |||
|
282 | break; | |||
|
283 | } | |||
|
284 | return clkselDec[clksel]; | |||
|
285 | } | |||
|
286 | ||||
|
287 | ||||
|
288 | void i2csetpclkfactor(i2cDev dev,unsigned char pclkfactor) | |||
|
289 | { | |||
|
290 | const char clkselDec[]={1,1,2,2,0,0,0,0,3}; | |||
|
291 | unsigned int clksel=0; | |||
|
292 | switch((int)dev) | |||
|
293 | { | |||
|
294 | case (int)I2C0_BASE_ADDR: | |||
|
295 | PCLKSEL0 |= clkselDec[pclkfactor]<<14; | |||
|
296 | PCLKSEL0 &= clkselDec[pclkfactor]<<14; | |||
|
297 | break; | |||
|
298 | case (int)I2C1_BASE_ADDR: | |||
|
299 | PCLKSEL1 |= clkselDec[pclkfactor]<<6; | |||
|
300 | PCLKSEL1 &= clkselDec[pclkfactor]<<6; | |||
|
301 | break; | |||
|
302 | case (int)I2C2_BASE_ADDR: | |||
|
303 | PCLKSEL1 |= clkselDec[pclkfactor]<<20; | |||
|
304 | PCLKSEL1 &= clkselDec[pclkfactor]<<20; | |||
|
305 | break; | |||
|
306 | default: | |||
|
307 | break; | |||
|
308 | } | |||
|
309 | ||||
|
310 | } | |||
|
311 | ||||
|
312 | ||||
|
313 | void i2csetdatarate(i2cDev dev,unsigned int dataRate) | |||
|
314 | { | |||
|
315 | unsigned int pclk = 0; | |||
|
316 | unsigned int cpuclk=0; | |||
|
317 | unsigned int i2csclkl=0; | |||
|
318 | if(dev==0)return; | |||
|
319 | cpuclk = coregetCpuFreq(); | |||
|
320 | pclk = cpuclk / i2cgetpclkfactor(dev); | |||
|
321 | i2csclkl = (pclk / dataRate)>>1; | |||
|
322 | if(i2csclkl<4) i2csclkl = 4; | |||
|
323 | i2csetup(dev,i2csclkl,i2csclkl); | |||
|
324 | } | |||
|
325 | ||||
|
326 | int i2cgetdatarate(i2cDev dev) | |||
|
327 | { | |||
|
328 | unsigned int dataRate=0; | |||
|
329 | unsigned int pclk = 0; | |||
|
330 | unsigned int cpuclk=0; | |||
|
331 | unsigned int i2csclkl=0; | |||
|
332 | if(dev==0)return 0; | |||
|
333 | cpuclk = coregetCpuFreq(); | |||
|
334 | pclk = cpuclk / i2cgetpclkfactor(dev); | |||
|
335 | dataRate = pclk /( ((_i2cDev)dev)->I2SCLH + ((_i2cDev)dev)->I2SCLL); | |||
|
336 | return dataRate; | |||
|
337 | } | |||
|
338 | ||||
|
339 | ||||
|
340 | ||||
|
341 | ||||
|
342 | ||||
|
343 | ||||
|
344 | ||||
|
345 | ||||
|
346 | ||||
|
347 | ||||
|
348 | ||||
|
349 | ||||
|
350 |
@@ -0,0 +1,73 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef IIC_H | |||
|
23 | #define IIC_H | |||
|
24 | ||||
|
25 | #include "LPC23xx.h" | |||
|
26 | #include <uhandle.h> | |||
|
27 | ||||
|
28 | enum iicctrlvals | |||
|
29 | { | |||
|
30 | i2noerr, | |||
|
31 | i2noack, | |||
|
32 | i2arbloss, | |||
|
33 | i2busy, | |||
|
34 | i2timeout | |||
|
35 | }; | |||
|
36 | ||||
|
37 | typedef enum iicctrlvals i2ctrl; | |||
|
38 | ||||
|
39 | struct lpc17XXi2cRegs | |||
|
40 | { | |||
|
41 | unsigned long I2CONSET; | |||
|
42 | unsigned long I2STAT; | |||
|
43 | unsigned long I2DAT; | |||
|
44 | unsigned long I2ADR; | |||
|
45 | unsigned long I2SCLH; | |||
|
46 | unsigned long I2SCLL; | |||
|
47 | unsigned long I2CONCLR; | |||
|
48 | }; | |||
|
49 | ||||
|
50 | typedef volatile struct lpc17XXi2cRegs* _i2cDev; | |||
|
51 | typedef UHANDLE i2cDev; | |||
|
52 | ||||
|
53 | extern i2ctrl i2cwrite(i2cDev dev,char address,char*data,int* cnt); | |||
|
54 | extern i2ctrl i2cwrite2(i2cDev dev,char address,char*cmd,int* cmdcnt,char*data,int* datcnt); | |||
|
55 | extern i2ctrl i2cread(i2cDev dev,char address,char*data,int* cnt); | |||
|
56 | extern i2cDev i2copen(int count); | |||
|
57 | extern void i2cenable(i2cDev dev); | |||
|
58 | extern void i2cdisable(i2cDev dev); | |||
|
59 | extern void i2csetup(i2cDev dev,int clkH,int clkL); | |||
|
60 | extern unsigned char i2cgetpclkfactor(i2cDev dev); | |||
|
61 | extern void i2csetpclkfactor(i2cDev dev,unsigned char pclkfactor); | |||
|
62 | extern void i2csetdatarate(i2cDev dev,unsigned int dataRate); | |||
|
63 | extern int i2cgetdatarate(i2cDev dev); | |||
|
64 | #endif | |||
|
65 | ||||
|
66 | ||||
|
67 | ||||
|
68 | ||||
|
69 | ||||
|
70 | ||||
|
71 | ||||
|
72 | ||||
|
73 |
@@ -0,0 +1,12 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
3 | TARGET = libiic | |||
|
4 | TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_IIC) | |||
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_IIC) | |||
|
6 | ||||
|
7 | LIBS += CORE UHANDLE | |||
|
8 | ||||
|
9 | SOURCES += iic.c | |||
|
10 | ||||
|
11 | ||||
|
12 | HEADERS += iic.h |
@@ -0,0 +1,30 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_SSP) | |||
|
6 | HEADERS += ssp.h | |||
|
7 | LIBSOURCES += ssp.c | |||
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
12 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
14 | TARGET=libssp | |||
|
15 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |||
|
16 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |||
|
17 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_SSP) | |||
|
18 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_SSP) | |||
|
19 | BSP=generic | |||
|
20 | include $(ARCHFOLDER)/rules.mk | |||
|
21 | ||||
|
22 | all:lib | |||
|
23 | @echo Code compiled | |||
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -0,0 +1,240 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #include "ssp.h" | |||
|
23 | #include "core.h" | |||
|
24 | ||||
|
25 | ||||
|
26 | void sspputw(sspDev dev,int c) { | |||
|
27 | volatile int a; | |||
|
28 | ((_sspDev)dev)->SSPDataReg = c; | |||
|
29 | while (((((_sspDev)dev)->SSPStatReg & (1<<4)))); | |||
|
30 | a=((_sspDev)dev)->SSPDataReg; | |||
|
31 | } | |||
|
32 | ||||
|
33 | void sspputc(sspDev dev,char c) { | |||
|
34 | volatile char a; | |||
|
35 | ((_sspDev)dev)->SSPDataReg = c; | |||
|
36 | while (((((_sspDev)dev)->SSPStatReg & (1<<4)))); | |||
|
37 | a=((_sspDev)dev)->SSPDataReg; | |||
|
38 | } | |||
|
39 | ||||
|
40 | void sspputnc(sspDev dev,const char *c,unsigned int n) | |||
|
41 | { | |||
|
42 | volatile char a; | |||
|
43 | while(n--) | |||
|
44 | { | |||
|
45 | ((_sspDev)dev)->SSPDataReg = *c++; | |||
|
46 | while (((((_sspDev)dev)->SSPStatReg & (1<<4)))); | |||
|
47 | a=((_sspDev)dev)->SSPDataReg; | |||
|
48 | } | |||
|
49 | } | |||
|
50 | ||||
|
51 | char sspgetc(sspDev dev) { | |||
|
52 | ((_sspDev)dev)->SSPDataReg = 0xffff; | |||
|
53 | while ((((_sspDev)dev)->SSPStatReg & (0x10))); | |||
|
54 | return ((char)((_sspDev)dev)->SSPDataReg); | |||
|
55 | } | |||
|
56 | ||||
|
57 | void sspgetnc(sspDev dev,char *c,unsigned int n) | |||
|
58 | { | |||
|
59 | volatile char a; | |||
|
60 | while (((((_sspDev)dev)->SSPStatReg & (1<<2)))) a=((_sspDev)dev)->SSPDataReg; | |||
|
61 | while(n) | |||
|
62 | { | |||
|
63 | ((_sspDev)dev)->SSPDataReg = 0xff; | |||
|
64 | while (((((_sspDev)dev)->SSPStatReg & (1<<4)))); | |||
|
65 | *c= (char)((_sspDev)dev)->SSPDataReg; | |||
|
66 | c++; | |||
|
67 | n--; | |||
|
68 | } | |||
|
69 | } | |||
|
70 | ||||
|
71 | int sspgetw(sspDev dev) { | |||
|
72 | int dummy; | |||
|
73 | while(((((_sspDev)dev)->SSPStatReg & (1<<2)))) | |||
|
74 | dummy = ((_sspDev)dev)->SSPDataReg; | |||
|
75 | ((_sspDev)dev)->SSPDataReg = 0xFFFF; | |||
|
76 | while (((((_sspDev)dev)->SSPStatReg & (1<<4)))); | |||
|
77 | return (((_sspDev)dev)->SSPDataReg); | |||
|
78 | } | |||
|
79 | ||||
|
80 | ||||
|
81 | void sspputs(sspDev dev,char *s) { | |||
|
82 | while (*s) sspputc(dev,*s++); | |||
|
83 | } | |||
|
84 | ||||
|
85 | ||||
|
86 | void sspgets(sspDev dev,char *s) { | |||
|
87 | while (*s && (*s!=0xd)) *s++ = sspgetc(dev); | |||
|
88 | } | |||
|
89 | ||||
|
90 | void sspsetup(sspDev dev,unsigned char bitscount,int sspCtrlRegValue0,int sspCtrlRegValue1, unsigned int dataRate) | |||
|
91 | { | |||
|
92 | ((_sspDev)dev)->SSPCtrlReg0 = sspCtrlRegValue0; | |||
|
93 | ((_sspDev)dev)->SSPCtrlReg1 = sspCtrlRegValue1; | |||
|
94 | sspsetupTRsize(dev,bitscount); | |||
|
95 | sspsetdatarate(dev,dataRate); | |||
|
96 | } | |||
|
97 | ||||
|
98 | void sspsetupTRsize(sspDev dev,unsigned char value) | |||
|
99 | { | |||
|
100 | disableSSP(dev); | |||
|
101 | if(value < 4)value =4; | |||
|
102 | value--; | |||
|
103 | ((_sspDev)dev)->SSPCtrlReg0 |= value; | |||
|
104 | ((_sspDev)dev)->SSPCtrlReg0 &= 0xFFFFFFF0 | value; | |||
|
105 | enableSSP(dev); | |||
|
106 | } | |||
|
107 | ||||
|
108 | void enableSSP(sspDev dev) | |||
|
109 | { | |||
|
110 | ((_sspDev)dev)->SSPCtrlReg1 |= 1<<1; | |||
|
111 | } | |||
|
112 | ||||
|
113 | void disableSSP(sspDev dev) | |||
|
114 | { | |||
|
115 | ((_sspDev)dev)->SSPCtrlReg1 &= -1 - (1<<1); | |||
|
116 | } | |||
|
117 | ||||
|
118 | void ssppowerup(sspDev dev) | |||
|
119 | { | |||
|
120 | switch((int)dev) | |||
|
121 | { | |||
|
122 | case (int)SSP0_BASE_ADDR: | |||
|
123 | PCONP |= ( 1 << 21 ); | |||
|
124 | break; | |||
|
125 | case (int)SSP1_BASE_ADDR: | |||
|
126 | PCONP |= ( 1 << 10 ); | |||
|
127 | break; | |||
|
128 | default: | |||
|
129 | break; | |||
|
130 | } | |||
|
131 | } | |||
|
132 | ||||
|
133 | void ssppowerdown(sspDev dev) | |||
|
134 | { | |||
|
135 | switch((int)dev) | |||
|
136 | { | |||
|
137 | case (int)SSP0_BASE_ADDR: | |||
|
138 | PCONP &= ~( 1 << 21 ); | |||
|
139 | break; | |||
|
140 | case (int)SSP1_BASE_ADDR: | |||
|
141 | PCONP &= ~( 1 << 10 ); | |||
|
142 | break; | |||
|
143 | default: | |||
|
144 | break; | |||
|
145 | } | |||
|
146 | } | |||
|
147 | ||||
|
148 | ||||
|
149 | sspDev sspopen(int count){ | |||
|
150 | sspDev dev; | |||
|
151 | switch(count) | |||
|
152 | { | |||
|
153 | case 0: | |||
|
154 | dev = (sspDev)((unsigned long)SSP0_BASE_ADDR); | |||
|
155 | break; | |||
|
156 | case 1: | |||
|
157 | dev = (sspDev)((unsigned long)SSP1_BASE_ADDR); | |||
|
158 | break; | |||
|
159 | default: | |||
|
160 | dev = (sspDev)0; | |||
|
161 | break; | |||
|
162 | } | |||
|
163 | return dev; | |||
|
164 | } | |||
|
165 | ||||
|
166 | ||||
|
167 | ||||
|
168 | ||||
|
169 | ||||
|
170 | ||||
|
171 | ||||
|
172 | ||||
|
173 | unsigned char sspgetpclkfactor(sspDev dev) | |||
|
174 | { | |||
|
175 | unsigned int clksel=0; | |||
|
176 | const char clkselDec[]={4,1,2,8}; | |||
|
177 | switch((int)dev) | |||
|
178 | { | |||
|
179 | case (int)SSP0_BASE_ADDR: | |||
|
180 | clksel = (PCLKSEL1>>10) & 3; | |||
|
181 | break; | |||
|
182 | case (int)SSP1_BASE_ADDR: | |||
|
183 | clksel = (PCLKSEL0>>20) & 3; | |||
|
184 | break; | |||
|
185 | default: | |||
|
186 | break; | |||
|
187 | } | |||
|
188 | return clkselDec[clksel]; | |||
|
189 | } | |||
|
190 | ||||
|
191 | ||||
|
192 | void sspsetpclkfactor(sspDev dev,unsigned char pclkfactor) | |||
|
193 | { | |||
|
194 | const char clkselDec[]={1,1,2,2,0,0,0,0,3}; | |||
|
195 | unsigned int clksel=0; | |||
|
196 | switch((int)dev) | |||
|
197 | { | |||
|
198 | case (int)SSP0_BASE_ADDR: | |||
|
199 | PCLKSEL1 |= clkselDec[pclkfactor]<<10; | |||
|
200 | PCLKSEL1 &= clkselDec[pclkfactor]<<10; | |||
|
201 | break; | |||
|
202 | case (int)SSP1_BASE_ADDR: | |||
|
203 | PCLKSEL0 |= clkselDec[pclkfactor]<<20; | |||
|
204 | PCLKSEL0 &= clkselDec[pclkfactor]<<20; | |||
|
205 | break; | |||
|
206 | default: | |||
|
207 | break; | |||
|
208 | } | |||
|
209 | ||||
|
210 | } | |||
|
211 | ||||
|
212 | ||||
|
213 | ||||
|
214 | ||||
|
215 | void sspsetdatarate(sspDev dev,unsigned int dataRate) | |||
|
216 | { | |||
|
217 | unsigned int pclk = 0; | |||
|
218 | unsigned int cpuclk=0; | |||
|
219 | unsigned int sspsclkl=0; | |||
|
220 | unsigned char error; | |||
|
221 | if(dev==0)return; | |||
|
222 | cpuclk = coregetCpuFreq(); | |||
|
223 | pclk = (cpuclk) / sspgetpclkfactor(dev); | |||
|
224 | sspsclkl = ((pclk*32) / (dataRate)); | |||
|
225 | error = (unsigned char)(sspsclkl & 0x3F); | |||
|
226 | if(error >= 0x1F) sspsclkl = sspsclkl + 0x1F; | |||
|
227 | sspsclkl = sspsclkl / 32; | |||
|
228 | if(sspisslave(dev)) | |||
|
229 | { | |||
|
230 | if(sspsclkl<12) sspsclkl = 12; | |||
|
231 | } | |||
|
232 | else | |||
|
233 | { | |||
|
234 | if(sspsclkl<2) sspsclkl = 2; | |||
|
235 | } | |||
|
236 | sspsclkl &= 0xFE; | |||
|
237 | ((_sspDev)dev)->SSPClkPrescReg = sspsclkl; | |||
|
238 | } | |||
|
239 | ||||
|
240 |
@@ -0,0 +1,108 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef SSP_H | |||
|
23 | #define SSP_H | |||
|
24 | ||||
|
25 | #include "LPC23xx.h" | |||
|
26 | #include <uhandle.h> | |||
|
27 | ||||
|
28 | ||||
|
29 | #define l4bits ((1<<1)+(1)) //0011 4 bit transfer | |||
|
30 | #define l5bits ((1<<2)) //0100 5 bit transfer | |||
|
31 | #define l6bits ((1<<2)+(1)) //0101 6 bit transfer | |||
|
32 | #define l7bits ((1<<1)+(1<<1)) //0110 7 bit transfer | |||
|
33 | #define l8bits ((1<<2)+(1<<1)+(1)) //0111 8 bit transfer | |||
|
34 | #define l9bits ((1<<3)) //1000 9 bit transfer | |||
|
35 | #define l10bits ((1<<3)+(1)) //1001 10 bit transfer | |||
|
36 | #define l11bits ((1<<3)+(1<<1)) //1010 11 bit transfer | |||
|
37 | #define l12bits ((1<<3)+(1<<1)+1) //1011 12 bit transfer | |||
|
38 | #define l13bits ((1<<3)+(1<<2)) //1100 13 bit transfer | |||
|
39 | #define l14bits ((1<<3)+(1<<2)+1) //1101 14 bit transfer | |||
|
40 | #define l15bits ((1<<3)+(1<<2)+(1<<1)) //1110 15 bit transfer | |||
|
41 | #define l16bits ((1<<3)+(1<<2)+(1<<1)+1) //1111 16 bit transfer | |||
|
42 | ||||
|
43 | #define FFSPI 0 | |||
|
44 | #define FFTI (1<<4) | |||
|
45 | #define FFMICROWIRE (1<<5) | |||
|
46 | ||||
|
47 | #define CLKINHLOW 0 | |||
|
48 | #define CLKINHHIGH (1<<6) | |||
|
49 | ||||
|
50 | #define CKfirstEdge 0 | |||
|
51 | #define CKsecondEdge (1<<7) | |||
|
52 | ||||
|
53 | ||||
|
54 | ||||
|
55 | #define loopbackOFF 0 | |||
|
56 | #define loopbackON 1 | |||
|
57 | ||||
|
58 | #define MASTERMODE 0 | |||
|
59 | #define SLAVEMODE (1<<2) | |||
|
60 | ||||
|
61 | #define SLAVEOUTPUTDISABLEMODE (1<<3) | |||
|
62 | ||||
|
63 | #define sspisslave(dev) ((((((_sspDev)dev))->SSPCtrlReg1>>2) & 1)==1) | |||
|
64 | ||||
|
65 | struct sspRegs | |||
|
66 | { | |||
|
67 | unsigned long SSPCtrlReg0; | |||
|
68 | unsigned long SSPCtrlReg1; | |||
|
69 | unsigned long SSPDataReg; | |||
|
70 | unsigned long SSPStatReg; | |||
|
71 | unsigned long SSPClkPrescReg; | |||
|
72 | unsigned long SSPIntMaskReg; | |||
|
73 | unsigned long SSPRawIntStatReg; | |||
|
74 | unsigned long SSPMaskedIntStatReg; | |||
|
75 | unsigned long SSPIntClearReg; | |||
|
76 | unsigned long SSPDMACtrlReg; | |||
|
77 | }; | |||
|
78 | ||||
|
79 | typedef volatile struct sspRegs* _sspDev; | |||
|
80 | typedef UHANDLE sspDev; | |||
|
81 | ||||
|
82 | extern sspDev sspopen(int count); | |||
|
83 | extern void sspputc(sspDev dev,char c); | |||
|
84 | extern void sspputnc(sspDev dev,const char *c,unsigned int n); | |||
|
85 | extern void sspputw(sspDev dev,int c); | |||
|
86 | extern void sspputs(sspDev dev,char *s); | |||
|
87 | extern void sspgets(sspDev dev,char *s); | |||
|
88 | extern char sspgetc(sspDev dev); | |||
|
89 | extern void sspgetnc(sspDev dev,char *c,unsigned int n); | |||
|
90 | extern int sspgetw(sspDev dev); | |||
|
91 | extern void enableSSP(sspDev dev); | |||
|
92 | extern void disableSSP(sspDev dev); | |||
|
93 | extern void sspsetup(sspDev dev,unsigned char bitscount,int sspCtrlRegValue0,int sspCtrlRegValue1, unsigned int dataRate); | |||
|
94 | extern void sspsetupTRsize(sspDev dev,unsigned char value); | |||
|
95 | extern unsigned char sspgetpclkfactor(sspDev dev); | |||
|
96 | extern void sspsetpclkfactor(sspDev dev,unsigned char pclkfactor); | |||
|
97 | extern void sspsetdatarate(sspDev dev,unsigned int dataRate); | |||
|
98 | ||||
|
99 | #endif | |||
|
100 | ||||
|
101 | ||||
|
102 | ||||
|
103 | ||||
|
104 | ||||
|
105 | ||||
|
106 | ||||
|
107 | ||||
|
108 |
@@ -0,0 +1,12 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
3 | TARGET = libssp | |||
|
4 | TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_SSP) | |||
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_SSP) | |||
|
6 | ||||
|
7 | LIBS += CORE UHANDLE | |||
|
8 | ||||
|
9 | SOURCES += ssp.c | |||
|
10 | ||||
|
11 | ||||
|
12 | HEADERS += ssp.h |
@@ -0,0 +1,28 | |||||
|
1 | ||||
|
2 | PROJECTDIR = `pwd` | |||
|
3 | LIBUC = /opt/libuc2 | |||
|
4 | ||||
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/UART | |||
|
6 | HEADERS += uart.h | |||
|
7 | LIBSOURCES += uart.c | |||
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |||
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
|
12 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |||
|
14 | TARGET=libuart | |||
|
15 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) | |||
|
16 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) | |||
|
17 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR)/UART | |||
|
18 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR)/UART | |||
|
19 | BSP=generic | |||
|
20 | include $(ARCHFOLDER)/rules.mk | |||
|
21 | ||||
|
22 | all:lib | |||
|
23 | @echo Code compiled | |||
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h |
@@ -0,0 +1,191 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #include "core.h" | |||
|
23 | #include "uart.h" | |||
|
24 | ||||
|
25 | ||||
|
26 | void uartputc(uartDev* dev,char c) { | |||
|
27 | while (!((dev->LineStat & (1<<5)))); | |||
|
28 | dev->RWreg = c; | |||
|
29 | } | |||
|
30 | ||||
|
31 | char uartgetc(uartDev* dev) { | |||
|
32 | while (!((dev->LineStat & 1))); | |||
|
33 | return (char)dev->RWreg; | |||
|
34 | } | |||
|
35 | ||||
|
36 | ||||
|
37 | void uartputs(uartDev* dev,char *s) { | |||
|
38 | while (*s) uartputc(dev,*s++); | |||
|
39 | } | |||
|
40 | ||||
|
41 | ||||
|
42 | void uartgets(uartDev* dev,char *s) { | |||
|
43 | while (*s && (*s!=0xd)) *s++ = uartgetc(dev); | |||
|
44 | } | |||
|
45 | ||||
|
46 | void uartoff(int count) | |||
|
47 | { | |||
|
48 | switch(count) | |||
|
49 | { | |||
|
50 | case 0: | |||
|
51 | PCONP &= ~( 1 << 3 ); | |||
|
52 | break; | |||
|
53 | case 1: | |||
|
54 | PCONP &= ~( 1 << 4 ); | |||
|
55 | break; | |||
|
56 | case 2: | |||
|
57 | PCONP &= ~( 1 << 24 ); | |||
|
58 | break; | |||
|
59 | case 3: | |||
|
60 | 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 | PCONP |= ( 1 << 3 ); | |||
|
73 | break; | |||
|
74 | case 1: | |||
|
75 | PCONP |= ( 1 << 4 ); | |||
|
76 | break; | |||
|
77 | case 2: | |||
|
78 | PCONP |= ( 1 << 24 ); | |||
|
79 | break; | |||
|
80 | case 3: | |||
|
81 | 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)UART0_BASE_ADDR: | |||
|
106 | clksel = (PCLKSEL0>>6) & 3; | |||
|
107 | break; | |||
|
108 | case (int)UART1_BASE_ADDR: | |||
|
109 | clksel = (PCLKSEL0>>8) & 3; | |||
|
110 | break; | |||
|
111 | case (int)UART2_BASE_ADDR: | |||
|
112 | clksel = (PCLKSEL1>>16) & 3; | |||
|
113 | break; | |||
|
114 | case (int)UART3_BASE_ADDR: | |||
|
115 | clksel = (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)UART0_BASE_ADDR: | |||
|
130 | PCLKSEL0 |= clkselDec[pclkfactor]<<6; | |||
|
131 | PCLKSEL0 &= clkselDec[pclkfactor]<<6; | |||
|
132 | break; | |||
|
133 | case (int)UART1_BASE_ADDR: | |||
|
134 | PCLKSEL0 |= clkselDec[pclkfactor]<<8; | |||
|
135 | PCLKSEL0 &= clkselDec[pclkfactor]<<8; | |||
|
136 | break; | |||
|
137 | case (int)UART2_BASE_ADDR: | |||
|
138 | PCLKSEL1 |= clkselDec[pclkfactor]<<16; | |||
|
139 | PCLKSEL1 &= clkselDec[pclkfactor]<<16; | |||
|
140 | break; | |||
|
141 | case (int)UART3_BASE_ADDR: | |||
|
142 | PCLKSEL1 |= clkselDec[pclkfactor]<<18; | |||
|
143 | 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 pclk = 0; | |||
|
153 | unsigned int clksel=0; | |||
|
154 | unsigned int cpuclk=0; | |||
|
155 | if(dev==0)return; | |||
|
156 | cpuclk = coregetCpuFreq(); | |||
|
157 | pclk = cpuclk / uartgetpclkfactor(dev); | |||
|
158 | while((baudRate*16)>pclk) | |||
|
159 | { | |||
|
160 | unsigned char pclkfact= uartgetpclkfactor(dev); | |||
|
161 | if(pclkfact==1)return; | |||
|
162 | uartsetpclkfactor(dev,pclkfact/2); | |||
|
163 | pclk = cpuclk / uartgetpclkfactor(dev); | |||
|
164 | } | |||
|
165 | dev->LineCtrl |= 128; | |||
|
166 | dev->RWreg = pclk/(baudRate*16); | |||
|
167 | dev->LineCtrl &= ~(128); | |||
|
168 | } | |||
|
169 | ||||
|
170 | uartDev* uartopen(int count){ | |||
|
171 | uartDev* dev; | |||
|
172 | switch(count) | |||
|
173 | { | |||
|
174 | case 0: | |||
|
175 | dev = (uartDev*)((unsigned long)UART0_BASE_ADDR); | |||
|
176 | break; | |||
|
177 | case 1: | |||
|
178 | dev = (uartDev*)((unsigned long)UART1_BASE_ADDR); | |||
|
179 | break; | |||
|
180 | case 2: | |||
|
181 | dev = (uartDev*)((unsigned long)UART2_BASE_ADDR); | |||
|
182 | break; | |||
|
183 | case 3: | |||
|
184 | dev = (uartDev*)((unsigned long)UART3_BASE_ADDR); | |||
|
185 | break; | |||
|
186 | default: | |||
|
187 | dev = (uartDev*)0; | |||
|
188 | break; | |||
|
189 | } | |||
|
190 | return dev; | |||
|
191 | } |
@@ -0,0 +1,66 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef UART_H | |||
|
23 | #define UART_H | |||
|
24 | #include "LPC23xx.h" | |||
|
25 | ||||
|
26 | ||||
|
27 | #define uartNoParity 0 | |||
|
28 | #define uartOddParity 1 | |||
|
29 | #define uartEvenParity 3 | |||
|
30 | #define uartTrueParity 5 | |||
|
31 | #define uartFalseParity 7 | |||
|
32 | ||||
|
33 | struct uartRegs | |||
|
34 | { | |||
|
35 | unsigned long RWreg; | |||
|
36 | unsigned long IntEN; | |||
|
37 | unsigned long IntIdFIFOctrlr; | |||
|
38 | unsigned long LineCtrl; | |||
|
39 | unsigned long dummy; | |||
|
40 | unsigned long LineStat; | |||
|
41 | unsigned long ScratchPad; | |||
|
42 | }; | |||
|
43 | ||||
|
44 | typedef volatile struct uartRegs uartDev; | |||
|
45 | ||||
|
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); | |||
|
57 | ||||
|
58 | #endif | |||
|
59 | ||||
|
60 | ||||
|
61 | ||||
|
62 | ||||
|
63 | ||||
|
64 | ||||
|
65 | ||||
|
66 |
@@ -0,0 +1,12 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | ARCH = lpc21XX-arm-noabi-gcc | |||
|
3 | TARGET = libuart | |||
|
4 | TARGETINSTALLPATH = $(LIBUC_LIBS_DIR)/UART | |||
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/UART | |||
|
6 | ||||
|
7 | LIBS += CORE | |||
|
8 | ||||
|
9 | SOURCES += uart.c | |||
|
10 | ||||
|
11 | ||||
|
12 | HEADERS += uart.h |
@@ -0,0 +1,112 | |||||
|
1 | #--------------------------------------------------------------------------------- | |||
|
2 | # LIBRARY DEFINITIONS | |||
|
3 | #--------------------------------------------------------------------------------- | |||
|
4 | LIBUC_LIBS = | |||
|
5 | LIBUC_LIBS_CORE = -static -lcore | |||
|
6 | LIBUC_LIBS_UCSTRINGS = -static -lucstrings | |||
|
7 | LIBUC_LIBS_UART = -static -luart | |||
|
8 | LIBUC_LIBS_SPI = -static -lspi | |||
|
9 | LIBUC_LIBS_SSP = -static -lssp | |||
|
10 | LIBUC_LIBS_IIC = -static -liic | |||
|
11 | LIBUC_LIBS_ADC = -static -ladc | |||
|
12 | LIBUC_LIBS_24LC0X = -static -l24lc0X | |||
|
13 | LIBUC_LIBS_SDCARD = -static -lsdcard | |||
|
14 | LIBUC_LIBS_BLKDEVICE = -static -lblkdevice | |||
|
15 | LIBUC_LIBS_FAT32 = -static -lfat32 | |||
|
16 | LIBUC_LIBS_VS10XX = -static -lvs10XX | |||
|
17 | LIBUC_LIBS_UHANDLE = -static -luhandle | |||
|
18 | LIBUC_LIBS_HEXVIEWER = -static -lhexviewer | |||
|
19 | LIBUC_LIBS_MBR = -static -lmbr | |||
|
20 | LIBUC_LIBS_UCDIRENT = -static -lucdirent | |||
|
21 | LIBUC_LIBS_FS = -static -lfs | |||
|
22 | LIBUC_LIBS_ALLFS = $(LIBUC_LIBS_UCDIRENT) $(LIBUC_LIBS_FS) $(LIBUC_LIBS_MBR) $(LIBUC_LIBS_FAT32) $(LIBUC_LIBS_SDCARD) $(LIBUC_LIBS_BLKDEVICE) | |||
|
23 | LIBUC_LIBS_FSEXPLORER = -static -lfsexplorer | |||
|
24 | ||||
|
25 | LIBUC_LIBS_DIR_CORE = $(LIBUC_LIBS_DIR)/CORE | |||
|
26 | LIBUC_LIBS_DIR_UCSTRINGS = $(LIBUC_LIBS_DIR)/STRINGS/$(ARCH) | |||
|
27 | LIBUC_LIBS_DIR_UART = $(LIBUC_LIBS_DIR)/UART | |||
|
28 | LIBUC_LIBS_DIR_SPI = $(LIBUC_LIBS_DIR)/SPI | |||
|
29 | LIBUC_LIBS_DIR_SSP = $(LIBUC_LIBS_DIR)/SSP | |||
|
30 | LIBUC_LIBS_DIR_IIC = $(LIBUC_LIBS_DIR)/IIC | |||
|
31 | LIBUC_LIBS_DIR_ADC = $(LIBUC_LIBS_DIR)/ADC | |||
|
32 | LIBUC_LIBS_DIR_24LC0X = $(LIBUC_LIBS_DIR)/24LCXX/24LC0X | |||
|
33 | LIBUC_LIBS_DIR_SDCARD = $(LIBUC_LIBS_DIR)/SDCARD | |||
|
34 | LIBUC_LIBS_DIR_VS10XX = $(LIBUC_LIBS_DIR)/VS10XX | |||
|
35 | LIBUC_LIBS_DIR_BLKDEVICE = $(LIBUC_LIBS_DIR)/BLKDEVICE | |||
|
36 | LIBUC_LIBS_DIR_FAT32 = $(LIBUC_LIBS_DIR)/FAT32 | |||
|
37 | LIBUC_LIBS_DIR_UHANDLE = $(LIBUC_LIBS_DIR)/UHANDLE | |||
|
38 | LIBUC_LIBS_DIR_HEXVIEWER = $(LIBUC_LIBS_DIR)/HEXVIEWER | |||
|
39 | LIBUC_LIBS_DIR_MBR = $(LIBUC_LIBS_DIR)/MBR | |||
|
40 | LIBUC_LIBS_DIR_UCDIRENT = $(LIBUC_LIBS_DIR)/UCDIRENT | |||
|
41 | LIBUC_LIBS_DIR_FS = $(LIBUC_LIBS_DIR)/FS | |||
|
42 | LIBUC_LIBS_DIR_FSEXPLORER = $(LIBUC_LIBS_DIR)/FSEXPLORER | |||
|
43 | ||||
|
44 | LIBUC_LIBS_DIR_CORE_CMD = -L $(LIBUC_LIBS_DIR_CORE) | |||
|
45 | LIBUC_LIBS_DIR_UCSTRINGS_CMD = -L $(LIBUC_LIBS_DIR_UCSTRINGS) | |||
|
46 | LIBUC_LIBS_DIR_UART_CMD = -L $(LIBUC_LIBS_DIR_UART) | |||
|
47 | LIBUC_LIBS_DIR_SPI_CMD = -L $(LIBUC_LIBS_DIR_SPI) | |||
|
48 | LIBUC_LIBS_DIR_SSP_CMD = -L $(LIBUC_LIBS_DIR_SSP) | |||
|
49 | LIBUC_LIBS_DIR_IIC_CMD = -L $(LIBUC_LIBS_DIR_IIC) | |||
|
50 | LIBUC_LIBS_DIR_ADC_CMD = -L $(LIBUC_LIBS_DIR_ADC) | |||
|
51 | LIBUC_LIBS_DIR_24LC0X_CMD = -L $(LIBUC_LIBS_DIR_24LC0X) | |||
|
52 | LIBUC_LIBS_DIR_SDCARD_CMD = -L $(LIBUC_LIBS_DIR_SDCARD) | |||
|
53 | LIBUC_LIBS_DIR_VS10XX_CMD = -L $(LIBUC_LIBS_DIR_VS10XX) | |||
|
54 | LIBUC_LIBS_DIR_BLKDEVICE_CMD = -L $(LIBUC_LIBS_DIR_BLKDEVICE) | |||
|
55 | LIBUC_LIBS_DIR_FAT32_CMD = -L $(LIBUC_LIBS_DIR_FAT32) | |||
|
56 | LIBUC_LIBS_DIR_UHANDLE_CMD = -L $(LIBUC_LIBS_DIR_UHANDLE) | |||
|
57 | LIBUC_LIBS_DIR_HEXVIEWER_CMD = -L $(LIBUC_LIBS_DIR_HEXVIEWER) | |||
|
58 | LIBUC_LIBS_DIR_MBR_CMD = -L $(LIBUC_LIBS_DIR_MBR) | |||
|
59 | LIBUC_LIBS_DIR_UCDIRENT_CMD = -L $(LIBUC_LIBS_DIR_UCDIRENT) | |||
|
60 | LIBUC_LIBS_DIR_FS_CMD = -L $(LIBUC_LIBS_DIR_FS) | |||
|
61 | LIBUC_LIBS_DIR_ALLFS_CMD = $(LIBUC_LIBS_DIR_UCDIRENT_CMD) $(LIBUC_LIBS_DIR_FS_CMD) $(LIBUC_LIBS_DIR_MBR_CMD) $(LIBUC_LIBS_DIR_FAT32_CMD) $(LIBUC_LIBS_DIR_SDCARD_CMD) $(LIBUC_LIBS_DIR_BLKDEVICE_CMD) | |||
|
62 | LIBUC_LIBS_DIR_FSEXPLORER_CMD = -L $(LIBUC_LIBS_DIR_FSEXPLORER) | |||
|
63 | ||||
|
64 | LIBUC_INC_DIR_CORE = $(LIBUC_INC_DIR)/CORE | |||
|
65 | LIBUC_INC_DIR_UCSTRINGS = $(LIBUC_INC_DIR)/STRINGS/$(ARCH) | |||
|
66 | LIBUC_INC_DIR_UART = $(LIBUC_INC_DIR)/UART | |||
|
67 | LIBUC_INC_DIR_SPI = $(LIBUC_INC_DIR)/SPI | |||
|
68 | LIBUC_INC_DIR_SSP = $(LIBUC_INC_DIR)/SSP | |||
|
69 | LIBUC_INC_DIR_IIC = $(LIBUC_INC_DIR)/IIC | |||
|
70 | LIBUC_INC_DIR_ADC = $(LIBUC_INC_DIR)/ADC | |||
|
71 | LIBUC_INC_DIR_24LC0X = $(LIBUC_INC_DIR)/24LCXX/24LC0X | |||
|
72 | LIBUC_INC_DIR_SDCARD = $(LIBUC_INC_DIR)/SDCARD | |||
|
73 | LIBUC_INC_DIR_VS10XX = $(LIBUC_INC_DIR)/VS10XX | |||
|
74 | LIBUC_INC_DIR_BLKDEVICE = $(LIBUC_INC_DIR)/BLKDEVICE | |||
|
75 | LIBUC_INC_DIR_FAT32 = $(LIBUC_INC_DIR)/FAT32 | |||
|
76 | LIBUC_INC_DIR_UHANDLE = $(LIBUC_INC_DIR)/UHANDLE | |||
|
77 | LIBUC_INC_DIR_HEXVIEWER = $(LIBUC_INC_DIR)/HEXVIEWER | |||
|
78 | LIBUC_INC_DIR_MBR = $(LIBUC_INC_DIR)/MBR | |||
|
79 | LIBUC_INC_DIR_UCDIRENT = $(LIBUC_INC_DIR)/UCDIRENT | |||
|
80 | LIBUC_INC_DIR_FS = $(LIBUC_INC_DIR)/FS | |||
|
81 | LIBUC_INC_DIR_FSEXPLORER = $(LIBUC_INC_DIR)/FSEXPLORER | |||
|
82 | ||||
|
83 | LIBUC_INC_DIR_CORE_CMD = -I $(LIBUC_INC_DIR_CORE) | |||
|
84 | LIBUC_INC_DIR_UCSTRINGS_CMD = -I $(LIBUC_INC_DIR_UCSTRINGS) | |||
|
85 | LIBUC_INC_DIR_UART_CMD = -I $(LIBUC_INC_DIR_UART) | |||
|
86 | LIBUC_INC_DIR_SPI_CMD = -I $(LIBUC_INC_DIR_SPI) | |||
|
87 | LIBUC_INC_DIR_SSP_CMD = -I $(LIBUC_INC_DIR_SSP) | |||
|
88 | LIBUC_INC_DIR_IIC_CMD = -I $(LIBUC_INC_DIR_IIC) | |||
|
89 | LIBUC_INC_DIR_ADC_CMD = -I $(LIBUC_INC_DIR_ADC) | |||
|
90 | LIBUC_INC_DIR_24LC0X_CMD = -I $(LIBUC_INC_DIR_24LC0X) | |||
|
91 | LIBUC_INC_DIR_SDCARD_CMD = -I $(LIBUC_INC_DIR_SDCARD) | |||
|
92 | LIBUC_INC_DIR_VS10XX_CMD = -I $(LIBUC_INC_DIR_VS10XX) | |||
|
93 | LIBUC_INC_DIR_BLKDEVICE_CMD = -I $(LIBUC_INC_DIR_BLKDEVICE) | |||
|
94 | LIBUC_INC_DIR_FAT32_CMD = -I $(LIBUC_INC_DIR_FAT32) | |||
|
95 | LIBUC_INC_DIR_UHANDLE_CMD = -I $(LIBUC_INC_DIR_UHANDLE) | |||
|
96 | LIBUC_INC_DIR_HEXVIEWER_CMD = -I $(LIBUC_INC_DIR_HEXVIEWER) | |||
|
97 | LIBUC_INC_DIR_MBR_CMD = -I $(LIBUC_INC_DIR_MBR) | |||
|
98 | LIBUC_INC_DIR_UCDIRENT_CMD = -I $(LIBUC_INC_DIR_UCDIRENT) | |||
|
99 | LIBUC_INC_DIR_FS_CMD = -I $(LIBUC_INC_DIR_FS) | |||
|
100 | LIBUC_INC_DIR_ALLFS_CMD = $(LIBUC_INC_DIR_UCDIRENT_CMD) $(LIBUC_INC_DIR_FS_CMD) $(LIBUC_INC_DIR_MBR_CMD) $(LIBUC_INC_DIR_FAT32_CMD) $(LIBUC_INC_DIR_SDCARD_CMD) $(LIBUC_INC_DIR_BLKDEVICE_CMD) | |||
|
101 | LIBUC_INC_DIR_FSEXPLORER_CMD = -I $(LIBUC_INC_DIR_FSEXPLORER) | |||
|
102 | ||||
|
103 | ||||
|
104 | ||||
|
105 | ||||
|
106 | ||||
|
107 | ||||
|
108 | ||||
|
109 | ||||
|
110 | ||||
|
111 | ||||
|
112 |
@@ -0,0 +1,127 | |||||
|
1 | /***********************************************************************/ | |||
|
2 | /* */ | |||
|
3 | /* RAM.ld: Linker Script File */ | |||
|
4 | /* */ | |||
|
5 | /***********************************************************************/ | |||
|
6 | ||||
|
7 | ENTRY(_start) | |||
|
8 | STACK_SIZE = 0x800; | |||
|
9 | ||||
|
10 | /* Memory Definitions */ | |||
|
11 | /* lpc2378 mt */ | |||
|
12 | MEMORY | |||
|
13 | { | |||
|
14 | ROM (rx) : ORIGIN = 0x00000000, LENGTH = 512K | |||
|
15 | RAM (rw) : ORIGIN = 0x40000000, LENGTH = 32K | |||
|
16 | } | |||
|
17 | ||||
|
18 | /* Section Definitions */ | |||
|
19 | SECTIONS | |||
|
20 | { | |||
|
21 | /* first section is .text which is used for code */ | |||
|
22 | .text : | |||
|
23 | { | |||
|
24 | *crt0.o (.text) /* Startup code */ | |||
|
25 | *(.text) /* remaining code */ | |||
|
26 | *(.rodata) /* read-only data (constants) */ | |||
|
27 | *(.rodata*) | |||
|
28 | *(.glue_7) | |||
|
29 | *(.glue_7t) | |||
|
30 | } > RAM | |||
|
31 | ||||
|
32 | . = ALIGN(4); | |||
|
33 | ||||
|
34 | /* .ctors .dtors are used for c++ constructors/destructors */ | |||
|
35 | /* added by Martin Thomas 4/2005 based on Anglia Design example */ | |||
|
36 | .ctors : | |||
|
37 | { | |||
|
38 | PROVIDE(__ctors_start__ = .); | |||
|
39 | KEEP(*(SORT(.ctors.*))) | |||
|
40 | KEEP(*(.ctors)) | |||
|
41 | PROVIDE(__ctors_end__ = .); | |||
|
42 | } >RAM | |||
|
43 | ||||
|
44 | .dtors : | |||
|
45 | { | |||
|
46 | PROVIDE(__dtors_start__ = .); | |||
|
47 | KEEP(*(SORT(.dtors.*))) | |||
|
48 | KEEP(*(.dtors)) | |||
|
49 | PROVIDE(__dtors_end__ = .); | |||
|
50 | } >RAM | |||
|
51 | ||||
|
52 | . = ALIGN(4); | |||
|
53 | /* mthomas - end */ | |||
|
54 | ||||
|
55 | _etext = . ; | |||
|
56 | PROVIDE (etext = .); | |||
|
57 | ||||
|
58 | /* .data section which is used for initialized data */ | |||
|
59 | .data : | |||
|
60 | { | |||
|
61 | _data = .; | |||
|
62 | *(.data) | |||
|
63 | } > RAM | |||
|
64 | ||||
|
65 | . = ALIGN(4); | |||
|
66 | _edata = . ; | |||
|
67 | PROVIDE (edata = .); | |||
|
68 | ||||
|
69 | /* .bss section which is used for uninitialized data */ | |||
|
70 | .bss (NOLOAD) : | |||
|
71 | { | |||
|
72 | __bss_start = . ; | |||
|
73 | __bss_start__ = . ; | |||
|
74 | *(.bss) | |||
|
75 | *(COMMON) | |||
|
76 | . = ALIGN(4); | |||
|
77 | } > RAM | |||
|
78 | ||||
|
79 | . = ALIGN(4); | |||
|
80 | __bss_end__ = . ; | |||
|
81 | PROVIDE (__bss_end = .); | |||
|
82 | ||||
|
83 | /* .stack ALIGN(256) : */ | |||
|
84 | .stack : | |||
|
85 | { | |||
|
86 | . = ALIGN(256); | |||
|
87 | . += STACK_SIZE; | |||
|
88 | PROVIDE (_stack = .); | |||
|
89 | } > RAM | |||
|
90 | ||||
|
91 | _end = . ; | |||
|
92 | PROVIDE (end = .); | |||
|
93 | ||||
|
94 | /* Stabs debugging sections. */ | |||
|
95 | .stab 0 : { *(.stab) } | |||
|
96 | .stabstr 0 : { *(.stabstr) } | |||
|
97 | .stab.excl 0 : { *(.stab.excl) } | |||
|
98 | .stab.exclstr 0 : { *(.stab.exclstr) } | |||
|
99 | .stab.index 0 : { *(.stab.index) } | |||
|
100 | .stab.indexstr 0 : { *(.stab.indexstr) } | |||
|
101 | .comment 0 : { *(.comment) } | |||
|
102 | /* DWARF debug sections. | |||
|
103 | Symbols in the DWARF debugging sections are relative to the beginning | |||
|
104 | of the section so we begin them at 0. */ | |||
|
105 | /* DWARF 1 */ | |||
|
106 | .debug 0 : { *(.debug) } | |||
|
107 | .line 0 : { *(.line) } | |||
|
108 | /* GNU DWARF 1 extensions */ | |||
|
109 | .debug_srcinfo 0 : { *(.debug_srcinfo) } | |||
|
110 | .debug_sfnames 0 : { *(.debug_sfnames) } | |||
|
111 | /* DWARF 1.1 and DWARF 2 */ | |||
|
112 | .debug_aranges 0 : { *(.debug_aranges) } | |||
|
113 | .debug_pubnames 0 : { *(.debug_pubnames) } | |||
|
114 | /* DWARF 2 */ | |||
|
115 | .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } | |||
|
116 | .debug_abbrev 0 : { *(.debug_abbrev) } | |||
|
117 | .debug_line 0 : { *(.debug_line) } | |||
|
118 | .debug_frame 0 : { *(.debug_frame) } | |||
|
119 | .debug_str 0 : { *(.debug_str) } | |||
|
120 | .debug_loc 0 : { *(.debug_loc) } | |||
|
121 | .debug_macinfo 0 : { *(.debug_macinfo) } | |||
|
122 | /* SGI/MIPS DWARF 2 extensions */ | |||
|
123 | .debug_weaknames 0 : { *(.debug_weaknames) } | |||
|
124 | .debug_funcnames 0 : { *(.debug_funcnames) } | |||
|
125 | .debug_typenames 0 : { *(.debug_typenames) } | |||
|
126 | .debug_varnames 0 : { *(.debug_varnames) } | |||
|
127 | } |
@@ -0,0 +1,128 | |||||
|
1 | /***********************************************************************/ | |||
|
2 | /* */ | |||
|
3 | /* ROM.ld: Linker Script File */ | |||
|
4 | /* */ | |||
|
5 | /***********************************************************************/ | |||
|
6 | ENTRY(_boot) | |||
|
7 | STACK_SIZE = 0x400; | |||
|
8 | ||||
|
9 | /* Memory Definitions */ | |||
|
10 | /* lpc2378 mt */ | |||
|
11 | MEMORY | |||
|
12 | { | |||
|
13 | ROM (rx) : ORIGIN = 0x00000000, LENGTH = 500K | |||
|
14 | RAM (rw) : ORIGIN = 0x40000000, LENGTH = (0x00008000 - 0x00000400 - 0x20 - 0x100) | |||
|
15 | } | |||
|
16 | ||||
|
17 | /* Section Definitions */ | |||
|
18 | SECTIONS | |||
|
19 | { | |||
|
20 | /* first section is .text which is used for code */ | |||
|
21 | .text : | |||
|
22 | { | |||
|
23 | *crt0.o (.text) /* Startup code */ | |||
|
24 | *(.text) /* remaining code */ | |||
|
25 | *(.rodata) /* read-only data (constants) */ | |||
|
26 | *(.rodata*) | |||
|
27 | *(.glue_7) | |||
|
28 | *(.glue_7t) | |||
|
29 | } > ROM | |||
|
30 | ||||
|
31 | . = ALIGN(4); | |||
|
32 | ||||
|
33 | /* .ctors .dtors are used for c++ constructors/destructors */ | |||
|
34 | /* added by Martin Thomas 4/2005 based on Anglia Design example */ | |||
|
35 | .ctors : | |||
|
36 | { | |||
|
37 | PROVIDE(__ctors_start__ = .); | |||
|
38 | KEEP(*(SORT(.ctors.*))) | |||
|
39 | KEEP(*(.ctors)) | |||
|
40 | PROVIDE(__ctors_end__ = .); | |||
|
41 | } >ROM | |||
|
42 | ||||
|
43 | .dtors : | |||
|
44 | { | |||
|
45 | PROVIDE(__dtors_start__ = .); | |||
|
46 | KEEP(*(SORT(.dtors.*))) | |||
|
47 | KEEP(*(.dtors)) | |||
|
48 | PROVIDE(__dtors_end__ = .); | |||
|
49 | } >ROM | |||
|
50 | ||||
|
51 | . = ALIGN(4); | |||
|
52 | /* mthomas - end */ | |||
|
53 | ||||
|
54 | ||||
|
55 | _etext = . ; | |||
|
56 | PROVIDE (etext = .); | |||
|
57 | ||||
|
58 | /* .data section which is used for initialized data */ | |||
|
59 | .data : AT (_etext) | |||
|
60 | { | |||
|
61 | _data = .; | |||
|
62 | *(.data) | |||
|
63 | SORT(CONSTRUCTORS) /* mt 4/2005 */ | |||
|
64 | } > RAM | |||
|
65 | ||||
|
66 | . = ALIGN(4); | |||
|
67 | _edata = . ; | |||
|
68 | PROVIDE (edata = .); | |||
|
69 | ||||
|
70 | /* .bss section which is used for uninitialized data */ | |||
|
71 | .bss (NOLOAD) : | |||
|
72 | { | |||
|
73 | __bss_start = . ; | |||
|
74 | __bss_start__ = . ; | |||
|
75 | *(.bss) | |||
|
76 | *(COMMON) | |||
|
77 | . = ALIGN(4); | |||
|
78 | } > RAM | |||
|
79 | ||||
|
80 | . = ALIGN(4); | |||
|
81 | __bss_end__ = . ; | |||
|
82 | PROVIDE (__bss_end = .); | |||
|
83 | ||||
|
84 | /* .stack ALIGN(256) : */ | |||
|
85 | .stack : | |||
|
86 | { | |||
|
87 | . = ALIGN(256); | |||
|
88 | . += STACK_SIZE; | |||
|
89 | PROVIDE (_stack = .); | |||
|
90 | } > RAM | |||
|
91 | ||||
|
92 | _end = . ; | |||
|
93 | PROVIDE (end = .); | |||
|
94 | ||||
|
95 | /* Stabs debugging sections. */ | |||
|
96 | .stab 0 : { *(.stab) } | |||
|
97 | .stabstr 0 : { *(.stabstr) } | |||
|
98 | .stab.excl 0 : { *(.stab.excl) } | |||
|
99 | .stab.exclstr 0 : { *(.stab.exclstr) } | |||
|
100 | .stab.index 0 : { *(.stab.index) } | |||
|
101 | .stab.indexstr 0 : { *(.stab.indexstr) } | |||
|
102 | .comment 0 : { *(.comment) } | |||
|
103 | /* DWARF debug sections. | |||
|
104 | Symbols in the DWARF debugging sections are relative to the beginning | |||
|
105 | of the section so we begin them at 0. */ | |||
|
106 | /* DWARF 1 */ | |||
|
107 | .debug 0 : { *(.debug) } | |||
|
108 | .line 0 : { *(.line) } | |||
|
109 | /* GNU DWARF 1 extensions */ | |||
|
110 | .debug_srcinfo 0 : { *(.debug_srcinfo) } | |||
|
111 | .debug_sfnames 0 : { *(.debug_sfnames) } | |||
|
112 | /* DWARF 1.1 and DWARF 2 */ | |||
|
113 | .debug_aranges 0 : { *(.debug_aranges) } | |||
|
114 | .debug_pubnames 0 : { *(.debug_pubnames) } | |||
|
115 | /* DWARF 2 */ | |||
|
116 | .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } | |||
|
117 | .debug_abbrev 0 : { *(.debug_abbrev) } | |||
|
118 | .debug_line 0 : { *(.debug_line) } | |||
|
119 | .debug_frame 0 : { *(.debug_frame) } | |||
|
120 | .debug_str 0 : { *(.debug_str) } | |||
|
121 | .debug_loc 0 : { *(.debug_loc) } | |||
|
122 | .debug_macinfo 0 : { *(.debug_macinfo) } | |||
|
123 | /* SGI/MIPS DWARF 2 extensions */ | |||
|
124 | .debug_weaknames 0 : { *(.debug_weaknames) } | |||
|
125 | .debug_funcnames 0 : { *(.debug_funcnames) } | |||
|
126 | .debug_typenames 0 : { *(.debug_typenames) } | |||
|
127 | .debug_varnames 0 : { *(.debug_varnames) } | |||
|
128 | } |
@@ -0,0 +1,193 | |||||
|
1 | .global main // int main(void) | |||
|
2 | ||||
|
3 | .global _etext // -> .data initial values in ROM | |||
|
4 | .global _data // -> .data area in RAM | |||
|
5 | .global _edata // end of .data area | |||
|
6 | .global __bss_start // -> .bss area in RAM | |||
|
7 | .global __bss_end__ // end of .bss area | |||
|
8 | .global _stack // top of stack | |||
|
9 | ||||
|
10 | // Stack Sizes | |||
|
11 | .set UND_STACK_SIZE, 0x00000004 | |||
|
12 | .set ABT_STACK_SIZE, 0x00000004 | |||
|
13 | .set FIQ_STACK_SIZE, 0x00000004 | |||
|
14 | .set IRQ_STACK_SIZE, 0X00000080 | |||
|
15 | .set SVC_STACK_SIZE, 0x00000004 | |||
|
16 | ||||
|
17 | // Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs | |||
|
18 | .set MODE_USR, 0x10 // User Mode | |||
|
19 | .set MODE_FIQ, 0x11 // FIQ Mode | |||
|
20 | .set MODE_IRQ, 0x12 // IRQ Mode | |||
|
21 | .set MODE_SVC, 0x13 // Supervisor Mode | |||
|
22 | .set MODE_ABT, 0x17 // Abort Mode | |||
|
23 | .set MODE_UND, 0x1B // Undefined Mode | |||
|
24 | .set MODE_SYS, 0x1F // System Mode | |||
|
25 | ||||
|
26 | .equ I_BIT, 0x80 // when I bit is set, IRQ is disabled | |||
|
27 | .equ F_BIT, 0x40 // when F bit is set, FIQ is disabled | |||
|
28 | ||||
|
29 | .text | |||
|
30 | .code 32 | |||
|
31 | .align 2 | |||
|
32 | ||||
|
33 | .global _boot | |||
|
34 | .func _boot | |||
|
35 | _boot: | |||
|
36 | ||||
|
37 | // Runtime Interrupt Vectors | |||
|
38 | // ------------------------- | |||
|
39 | Vectors: | |||
|
40 | b _start // reset - _start | |||
|
41 | ldr pc,_undf // undefined - _undf | |||
|
42 | ldr pc,_swi // SWI - _swi | |||
|
43 | ldr pc,_pabt // program abort - _pabt | |||
|
44 | ldr pc,_dabt // data abort - _dabt | |||
|
45 | nop // reserved | |||
|
46 | ldr pc,[pc,#-0xFF0] // IRQ - read the VIC | |||
|
47 | ldr pc,_fiq // FIQ - _fiq | |||
|
48 | ||||
|
49 | #if 0 | |||
|
50 | // Use this group for production | |||
|
51 | _undf: .word _reset // undefined - _reset | |||
|
52 | _swi: .word _reset // SWI - _reset | |||
|
53 | _pabt: .word _reset // program abort - _reset | |||
|
54 | _dabt: .word _reset // data abort - _reset | |||
|
55 | _irq: .word _reset // IRQ - _reset | |||
|
56 | _fiq: .word _reset // FIQ - _reset | |||
|
57 | ||||
|
58 | #else | |||
|
59 | // Use this group for development | |||
|
60 | _undf: .word __undf // undefined | |||
|
61 | _swi: .word __swi // SWI | |||
|
62 | _pabt: .word __pabt // program abort | |||
|
63 | _dabt: .word __dabt // data abort | |||
|
64 | _irq: .word __irq // IRQ | |||
|
65 | _fiq: .word __fiq // FIQ | |||
|
66 | ||||
|
67 | __undf: b . // undefined | |||
|
68 | __swi: b . // SWI | |||
|
69 | __pabt: b . // program abort | |||
|
70 | __dabt: b . // data abort | |||
|
71 | __irq: b . // IRQ | |||
|
72 | __fiq: b . // FIQ | |||
|
73 | #endif | |||
|
74 | .size _boot, . - _boot | |||
|
75 | .endfunc | |||
|
76 | ||||
|
77 | ||||
|
78 | // Setup the operating mode & stack. | |||
|
79 | // --------------------------------- | |||
|
80 | .global _start, start, _mainCRTStartup | |||
|
81 | .func _start | |||
|
82 | ||||
|
83 | _start: | |||
|
84 | start: | |||
|
85 | _mainCRTStartup: | |||
|
86 | ||||
|
87 | // Initialize Interrupt System | |||
|
88 | // - Set stack location for each mode | |||
|
89 | // - Leave in System Mode with Interrupts Disabled | |||
|
90 | // ----------------------------------------------- | |||
|
91 | ldr r0,=_stack | |||
|
92 | msr CPSR_c,#MODE_UND|I_BIT|F_BIT // Undefined Instruction Mode | |||
|
93 | mov sp,r0 | |||
|
94 | sub r0,r0,#UND_STACK_SIZE | |||
|
95 | msr CPSR_c,#MODE_ABT|I_BIT|F_BIT // Abort Mode | |||
|
96 | mov sp,r0 | |||
|
97 | sub r0,r0,#ABT_STACK_SIZE | |||
|
98 | msr CPSR_c,#MODE_FIQ|I_BIT|F_BIT // FIQ Mode | |||
|
99 | mov sp,r0 | |||
|
100 | sub r0,r0,#FIQ_STACK_SIZE | |||
|
101 | msr CPSR_c,#MODE_IRQ|I_BIT|F_BIT // IRQ Mode | |||
|
102 | mov sp,r0 | |||
|
103 | sub r0,r0,#IRQ_STACK_SIZE | |||
|
104 | msr CPSR_c,#MODE_SVC|I_BIT|F_BIT // Supervisor Mode | |||
|
105 | mov sp,r0 | |||
|
106 | sub r0,r0,#SVC_STACK_SIZE | |||
|
107 | msr CPSR_c,#MODE_SYS|I_BIT|F_BIT // System Mode | |||
|
108 | mov sp,r0 | |||
|
109 | ||||
|
110 | // Copy initialized data to its execution address in RAM | |||
|
111 | // ----------------------------------------------------- | |||
|
112 | #ifdef ROM_RUN | |||
|
113 | ldr r1,=_etext // -> ROM data start | |||
|
114 | ldr r2,=_data // -> data start | |||
|
115 | ldr r3,=_edata // -> end of data | |||
|
116 | 1: cmp r2,r3 // check if data to move | |||
|
117 | ldrlo r0,[r1],#4 // copy it | |||
|
118 | strlo r0,[r2],#4 | |||
|
119 | blo 1b // loop until done | |||
|
120 | #endif | |||
|
121 | // Clear .bss | |||
|
122 | // ---------- | |||
|
123 | mov r0,#0 // get a zero | |||
|
124 | ldr r1,=__bss_start // -> bss start | |||
|
125 | ldr r2,=__bss_end__ // -> bss end | |||
|
126 | 2: cmp r1,r2 // check if data to clear | |||
|
127 | strlo r0,[r1],#4 // clear 4 bytes | |||
|
128 | blo 2b // loop until done | |||
|
129 | ||||
|
130 | /* | |||
|
131 | Call C++ constructors (for objects in "global scope") | |||
|
132 | ctor loop added by Martin Thomas 4/2005 | |||
|
133 | based on a Anglia Design example-application for ST ARM | |||
|
134 | */ | |||
|
135 | ||||
|
136 | LDR r0, =__ctors_start__ | |||
|
137 | LDR r1, =__ctors_end__ | |||
|
138 | ctor_loop: | |||
|
139 | CMP r0, r1 | |||
|
140 | BEQ ctor_end | |||
|
141 | LDR r2, [r0], #4 | |||
|
142 | STMFD sp!, {r0-r1} | |||
|
143 | MOV lr, pc | |||
|
144 | MOV pc, r2 | |||
|
145 | LDMFD sp!, {r0-r1} | |||
|
146 | B ctor_loop | |||
|
147 | ctor_end: | |||
|
148 | ||||
|
149 | // Call main program: main(0) | |||
|
150 | // -------------------------- | |||
|
151 | mov r0,#0 // no arguments (argc = 0) | |||
|
152 | mov r1,r0 | |||
|
153 | mov r2,r0 | |||
|
154 | mov fp,r0 // null frame pointer | |||
|
155 | mov r7,r0 // null frame pointer for thumb | |||
|
156 | ldr r10,=main | |||
|
157 | mov lr,pc | |||
|
158 | bx r10 // enter main() | |||
|
159 | ||||
|
160 | /* "global object"-dtors are never called and it should not be | |||
|
161 | needed since there is no OS to exit to. */ | |||
|
162 | ||||
|
163 | .size _start, . - _start | |||
|
164 | .endfunc | |||
|
165 | ||||
|
166 | .global _reset, reset, exit, abort | |||
|
167 | .func _reset | |||
|
168 | _reset: | |||
|
169 | reset: | |||
|
170 | exit: | |||
|
171 | abort: | |||
|
172 | #if 0 | |||
|
173 | // Disable interrupts, then force a hardware reset by driving P23 low | |||
|
174 | // ------------------------------------------------------------------- | |||
|
175 | mrs r0,cpsr // get PSR | |||
|
176 | orr r0,r0,#I_BIT|F_BIT // disable IRQ and FIQ | |||
|
177 | msr cpsr,r0 // set up status register | |||
|
178 | ||||
|
179 | ldr r1,=(PS_BASE) // PS Base Address | |||
|
180 | ldr r0,=(PS_PIO) // PIO Module | |||
|
181 | str r0,[r1,#PS_PCER_OFF] // enable its clock | |||
|
182 | ldr r1,=(PIO_BASE) // PIO Base Address | |||
|
183 | ldr r0,=(1<<23) // P23 | |||
|
184 | str r0,[r1,#PIO_PER_OFF] // make sure pin is contolled by PIO | |||
|
185 | str r0,[r1,#PIO_CODR_OFF] // set the pin low | |||
|
186 | str r0,[r1,#PIO_OER_OFF] // make it an output | |||
|
187 | #endif | |||
|
188 | b . // loop until reset | |||
|
189 | ||||
|
190 | .size _reset, . - _reset | |||
|
191 | .endfunc | |||
|
192 | ||||
|
193 | .end |
@@ -46,6 +46,37 function Target { | |||||
46 | fi |
|
46 | fi | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
|
49 | ||||
|
50 | function Objdir { | |||
|
51 | if [ -z "$2" ] ; then | |||
|
52 | OBJDIR=`more $1 | grep -i "OBJDIR " | sed s/OBJDIR// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | |||
|
53 | if [ -z "$OBJDIR" ] ; then | |||
|
54 | OBJDIR="obj" | |||
|
55 | fi | |||
|
56 | else | |||
|
57 | OBJDIR=`more $1 | grep -i "$2.OBJDIR " | sed s/$2'\.'OBJDIR// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | |||
|
58 | if [ -z "$OBJDIR" ] ; then | |||
|
59 | OBJDIR="obj" | |||
|
60 | fi | |||
|
61 | fi | |||
|
62 | } | |||
|
63 | ||||
|
64 | ||||
|
65 | function Bindir { | |||
|
66 | if [ -z "$2" ] ; then | |||
|
67 | BINDIR=`more $1 | grep -i "BINDIR " | sed s/BINDIR// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | |||
|
68 | if [ -z "$BINDIR" ] ; then | |||
|
69 | BINDIR="bin" | |||
|
70 | fi | |||
|
71 | else | |||
|
72 | BINDIR=`more $1 | grep -i "$2.OBJDIR " | sed s/$2'\.'BINDIR// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | |||
|
73 | if [ -z "$BINDIR" ] ; then | |||
|
74 | BINDIR="bin" | |||
|
75 | fi | |||
|
76 | fi | |||
|
77 | } | |||
|
78 | ||||
|
79 | ||||
49 | function Targets { |
|
80 | function Targets { | |
50 | TARGETS=`more $1 | grep -i ".SOURCES" | sed 's/\.SOURCES.*//'` |
|
81 | TARGETS=`more $1 | grep -i ".SOURCES" | sed 's/\.SOURCES.*//'` | |
51 | } |
|
82 | } | |
@@ -56,12 +87,14 function Libs_Inc { | |||||
56 | for FILES in $INCLUDEStmp |
|
87 | for FILES in $INCLUDEStmp | |
57 | do |
|
88 | do | |
58 | INCLUDES+='$('"LIBUC_INC_DIR_""$FILES""_CMD) " |
|
89 | INCLUDES+='$('"LIBUC_INC_DIR_""$FILES""_CMD) " | |
|
90 | INC_LIBS_DEPS+='$('"LIBUC_INC_DIR_""$FILES"") " | |||
59 | done |
|
91 | done | |
60 | else |
|
92 | else | |
61 | INCLUDEStmp=`more $1 | grep -i "$2.LIBS " | sed s/$2'\.'LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
93 | INCLUDEStmp=`more $1 | grep -i "$2.LIBS " | sed s/$2'\.'LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` | |
62 | for FILES in $INCLUDEStmp |
|
94 | for FILES in $INCLUDEStmp | |
63 | do |
|
95 | do | |
64 | INCLUDES+='$('"LIBUC_INC_DIR_""$FILES""_CMD) " |
|
96 | INCLUDES+='$('"LIBUC_INC_DIR_""$FILES""_CMD) " | |
|
97 | INC_LIBS_DEPS+='$('"LIBUC_INC_DIR_""$FILES"") " | |||
65 | done |
|
98 | done | |
66 | fi |
|
99 | fi | |
67 |
|
100 | |||
@@ -73,12 +106,14 function Libs_Link { | |||||
73 | for FILES in $LIBRARIEStmp |
|
106 | for FILES in $LIBRARIEStmp | |
74 | do |
|
107 | do | |
75 | LIBRARIES+='$('"LIBUC_LIBS_DIR_""$FILES""_CMD) "'$('"LIBUC_LIBS_$FILES) " |
|
108 | LIBRARIES+='$('"LIBUC_LIBS_DIR_""$FILES""_CMD) "'$('"LIBUC_LIBS_$FILES) " | |
|
109 | BIN_LIBS_DEPS='$('"LIBUC_LIBS_DIR_""$FILES"")" | |||
76 | done |
|
110 | done | |
77 | else |
|
111 | else | |
78 | LIBRARIEStmp=`more $1 | grep -i "$2.LIBS " | sed s/$2'\.'LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
112 | LIBRARIEStmp=`more $1 | grep -i "$2.LIBS " | sed s/$2'\.'LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` | |
79 | for FILES in $LIBRARIEStmp |
|
113 | for FILES in $LIBRARIEStmp | |
80 | do |
|
114 | do | |
81 | LIBRARIES+='$('"LIBUC_LIBS_DIR_""$FILES""_CMD) "'$('"LIBUC_LIBS_$FILES) " |
|
115 | LIBRARIES+='$('"LIBUC_LIBS_DIR_""$FILES""_CMD) "'$('"LIBUC_LIBS_$FILES) " | |
|
116 | BIN_LIBS_DEPS='$('"LIBUC_LIBS_DIR_""$FILES"")" | |||
82 | done |
|
117 | done | |
83 | fi |
|
118 | fi | |
84 |
|
119 |
@@ -20,6 +20,10 | |||||
20 | #-- Author : Alexis Jeandet |
|
20 | #-- Author : Alexis Jeandet | |
21 | #-- Mail : alexis.jeandet@gmail.com |
|
21 | #-- Mail : alexis.jeandet@gmail.com | |
22 | #-------------------------------------------------------------------------------*/ |
|
22 | #-------------------------------------------------------------------------------*/ | |
|
23 | OBJDIR="obj" | |||
|
24 | BINDIR="bin" | |||
|
25 | INC_LIBS_DEPS="" | |||
|
26 | BIN_LIBS_DEPS="" | |||
23 |
|
27 | |||
24 | function template-run { |
|
28 | function template-run { | |
25 | Targets $PROJECTFILE |
|
29 | Targets $PROJECTFILE | |
@@ -27,6 +31,8 function template-run { | |||||
27 | echo "Single Target" |
|
31 | echo "Single Target" | |
28 | Target $PROJECTFILE |
|
32 | Target $PROJECTFILE | |
29 | Arch $PROJECTFILE |
|
33 | Arch $PROJECTFILE | |
|
34 | Objdir $PROJECTFILE | |||
|
35 | Bindir $PROJECTFILE | |||
30 | Libs_Inc $PROJECTFILE |
|
36 | Libs_Inc $PROJECTFILE | |
31 | Libs_Link $PROJECTFILE |
|
37 | Libs_Link $PROJECTFILE | |
32 | HeadersInstallPath $PROJECTFILE |
|
38 | HeadersInstallPath $PROJECTFILE | |
@@ -47,7 +53,10 function template-run { | |||||
47 | echo "=========================================================================" |
|
53 | echo "=========================================================================" | |
48 | echo "" |
|
54 | echo "" | |
49 | echo " Start Writing Makefile ..." |
|
55 | echo " Start Writing Makefile ..." | |
|
56 | echo "OBJDIR = $OBJDIR" >> Makefile | |||
|
57 | echo "BINDIR = $BINDIR" >> Makefile | |||
50 | echo 'OBJECTFILES = $(APPSOURCES:.c=.o)'>> Makefile |
|
58 | echo 'OBJECTFILES = $(APPSOURCES:.c=.o)'>> Makefile | |
|
59 | echo 'OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES))'>> Makefile | |||
51 | echo "ARCH = $ARCH" >> Makefile |
|
60 | echo "ARCH = $ARCH" >> Makefile | |
52 | echo "ARCHFOLDER = "'$(LIBUC)'"/rules/$ARCH" >> Makefile |
|
61 | echo "ARCHFOLDER = "'$(LIBUC)'"/rules/$ARCH" >> Makefile | |
53 | echo "TARGET=$TARGET">> Makefile |
|
62 | echo "TARGET=$TARGET">> Makefile | |
@@ -67,14 +76,14 function template-run { | |||||
67 | echo "" |
|
76 | echo "" | |
68 | else |
|
77 | else | |
69 | echo "Multi targets" |
|
78 | echo "Multi targets" | |
70 | echo "" >> Makefile |
|
|||
71 | echo "all:" >> Makefile |
|
|||
72 | for ITEMS in $TARGETS |
|
79 | for ITEMS in $TARGETS | |
73 | do |
|
80 | do | |
74 | echo 'PROJECTDIR = `pwd`'> $ITEMS.mk |
|
81 | echo 'PROJECTDIR = `pwd`'> $ITEMS.mk | |
75 | echo "LIBUC = $libuc2" >> $ITEMS.mk |
|
82 | echo "LIBUC = $libuc2" >> $ITEMS.mk | |
76 | Target $PROJECTFILE $ITEMS |
|
83 | Target $PROJECTFILE $ITEMS | |
77 | Arch $PROJECTFILE $ITEMS |
|
84 | Arch $PROJECTFILE $ITEMS | |
|
85 | Objdir $PROJECTFILE $ITEMS | |||
|
86 | Bindir $PROJECTFILE $ITEMS | |||
78 | Libs_Inc $PROJECTFILE $ITEMS |
|
87 | Libs_Inc $PROJECTFILE $ITEMS | |
79 | Libs_Link $PROJECTFILE $ITEMS |
|
88 | Libs_Link $PROJECTFILE $ITEMS | |
80 | HeadersInstallPath $PROJECTFILE $ITEMS |
|
89 | HeadersInstallPath $PROJECTFILE $ITEMS | |
@@ -95,7 +104,10 function template-run { | |||||
95 | echo "=========================================================================" |
|
104 | echo "=========================================================================" | |
96 | echo "" |
|
105 | echo "" | |
97 | echo " Start Writing Makefile ..." |
|
106 | echo " Start Writing Makefile ..." | |
98 |
echo |
|
107 | echo "OBJDIR = $OBJDIR" >> $ITEMS.mk | |
|
108 | echo "BINDIR = $BINDIR" >> $ITEMS.mk | |||
|
109 | echo 'OBJECTFILES = $(APPSOURCES:.c=.o)'>> $ITEMS.mk | |||
|
110 | echo 'OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES))'>> $ITEMS.mk | |||
99 | echo "ARCH = $ARCH" >> $ITEMS.mk |
|
111 | echo "ARCH = $ARCH" >> $ITEMS.mk | |
100 | echo "ARCHFOLDER = "'$(LIBUC)'"/rules/$ARCH" >> $ITEMS.mk |
|
112 | echo "ARCHFOLDER = "'$(LIBUC)'"/rules/$ARCH" >> $ITEMS.mk | |
101 | echo "TARGET=$TARGET">> $ITEMS.mk |
|
113 | echo "TARGET=$TARGET">> $ITEMS.mk | |
@@ -113,8 +125,19 function template-run { | |||||
113 | echo "" |
|
125 | echo "" | |
114 | echo "=========================================================================" |
|
126 | echo "=========================================================================" | |
115 | echo "" |
|
127 | echo "" | |
|
128 | done | |||
|
129 | echo "" >> Makefile | |||
|
130 | echo "all:" >> Makefile | |||
|
131 | for ITEMS in $TARGETS | |||
|
132 | do | |||
116 | echo " make -f $ITEMS.mk" >> Makefile |
|
133 | echo " make -f $ITEMS.mk" >> Makefile | |
117 | done |
|
134 | done | |
|
135 | echo "" >> Makefile | |||
|
136 | echo "clean:" >> Makefile | |||
|
137 | for ITEMS in $TARGETS | |||
|
138 | do | |||
|
139 | echo " make clean -f $ITEMS.mk" >> Makefile | |||
|
140 | done | |||
118 | fi |
|
141 | fi | |
119 |
|
142 | |||
120 | } |
|
143 | } |
@@ -27,6 +27,8 function template-run { | |||||
27 | echo "Single Target" |
|
27 | echo "Single Target" | |
28 | Target $PROJECTFILE |
|
28 | Target $PROJECTFILE | |
29 | Arch $PROJECTFILE |
|
29 | Arch $PROJECTFILE | |
|
30 | Objdir $PROJECTFILE | |||
|
31 | Bindir $PROJECTFILE | |||
30 | Libs_Inc $PROJECTFILE |
|
32 | Libs_Inc $PROJECTFILE | |
31 | Libs_Link $PROJECTFILE |
|
33 | Libs_Link $PROJECTFILE | |
32 | HeadersInstallPath $PROJECTFILE |
|
34 | HeadersInstallPath $PROJECTFILE | |
@@ -46,7 +48,10 function template-run { | |||||
46 | echo "=========================================================================" |
|
48 | echo "=========================================================================" | |
47 | echo "" |
|
49 | echo "" | |
48 | echo " Start Writing Makefile ..." |
|
50 | echo " Start Writing Makefile ..." | |
|
51 | echo "OBJDIR = $OBJDIR" >> Makefile | |||
|
52 | echo "BINDIR = $BINDIR" >> Makefile | |||
49 | echo 'OBJECTFILES = $(LIBSOURCES:.c=.o)'>> Makefile |
|
53 | echo 'OBJECTFILES = $(LIBSOURCES:.c=.o)'>> Makefile | |
|
54 | echo 'OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES))'>> Makefile | |||
50 | echo "ARCH = $ARCH" >> Makefile |
|
55 | echo "ARCH = $ARCH" >> Makefile | |
51 | echo "ARCHFOLDER = "'$(LIBUC)'"/rules/$ARCH" >> Makefile |
|
56 | echo "ARCHFOLDER = "'$(LIBUC)'"/rules/$ARCH" >> Makefile | |
52 | echo "TARGET=$TARGET">> Makefile |
|
57 | echo "TARGET=$TARGET">> Makefile | |
@@ -59,6 +64,13 function template-run { | |||||
59 | echo '' >> Makefile |
|
64 | echo '' >> Makefile | |
60 | echo 'all:lib' >> Makefile |
|
65 | echo 'all:lib' >> Makefile | |
61 | echo " @echo Code compiled" >> Makefile |
|
66 | echo " @echo Code compiled" >> Makefile | |
|
67 | echo '' >> Makefile | |||
|
68 | echo 'clean:' >> Makefile | |||
|
69 | echo ' rm -f $(OBJDIR)/*.o' >> Makefile | |||
|
70 | echo ' rm -f $(TARGETINSTALLPATH)/*.a' >> Makefile | |||
|
71 | echo ' rm -f $(HEADERSINSTALLPATH)/*.h' >> Makefile | |||
|
72 | echo ' rm -f $(DEVSOURCESND)' >> Makefile | |||
|
73 | echo ' rm -f *.d' >> Makefile | |||
62 | echo " Makefile writing finished" |
|
74 | echo " Makefile writing finished" | |
63 | echo "" |
|
75 | echo "" | |
64 | echo "=========================================================================" |
|
76 | echo "=========================================================================" | |
@@ -66,14 +78,14 function template-run { | |||||
66 |
|
78 | |||
67 | else |
|
79 | else | |
68 | echo "Multi targets" |
|
80 | echo "Multi targets" | |
69 | echo "" >> Makefile |
|
|||
70 | echo "all:" >> Makefile |
|
|||
71 | for ITEMS in $TARGETS |
|
81 | for ITEMS in $TARGETS | |
72 | do |
|
82 | do | |
73 | echo 'PROJECTDIR = `pwd`'> $ITEMS.mk |
|
83 | echo 'PROJECTDIR = `pwd`'> $ITEMS.mk | |
74 | echo "LIBUC = $libuc2" >> $ITEMS.mk |
|
84 | echo "LIBUC = $libuc2" >> $ITEMS.mk | |
75 | Target $PROJECTFILE $ITEMS |
|
85 | Target $PROJECTFILE $ITEMS | |
76 | Arch $PROJECTFILE $ITEMS |
|
86 | Arch $PROJECTFILE $ITEMS | |
|
87 | Objdir $PROJECTFILE | |||
|
88 | Bindir $PROJECTFILE | |||
77 | Libs_Inc $PROJECTFILE $ITEMS |
|
89 | Libs_Inc $PROJECTFILE $ITEMS | |
78 | Libs_Link $PROJECTFILE $ITEMS |
|
90 | Libs_Link $PROJECTFILE $ITEMS | |
79 | HeadersInstallPath $PROJECTFILE $ITEMS |
|
91 | HeadersInstallPath $PROJECTFILE $ITEMS | |
@@ -93,7 +105,10 function template-run { | |||||
93 | echo "=========================================================================" |
|
105 | echo "=========================================================================" | |
94 | echo "" |
|
106 | echo "" | |
95 | echo " Start Writing Makefile ..." |
|
107 | echo " Start Writing Makefile ..." | |
|
108 | echo "OBJDIR = $OBJDIR" >> $ITEMS.mk | |||
|
109 | echo "BINDIR = $BINDIR" >> $ITEMS.mk | |||
96 | echo 'OBJECTFILES = $(LIBSOURCES:.c=.o)'>> $ITEMS.mk |
|
110 | echo 'OBJECTFILES = $(LIBSOURCES:.c=.o)'>> $ITEMS.mk | |
|
111 | echo 'OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES))'>> $ITEMS.mk | |||
97 | echo "ARCH = $ARCH" >> $ITEMS.mk |
|
112 | echo "ARCH = $ARCH" >> $ITEMS.mk | |
98 | echo "ARCHFOLDER = "'$(LIBUC)'"/rules/$ARCH" >> $ITEMS.mk |
|
113 | echo "ARCHFOLDER = "'$(LIBUC)'"/rules/$ARCH" >> $ITEMS.mk | |
99 | echo "TARGET=$TARGET">> $ITEMS.mk |
|
114 | echo "TARGET=$TARGET">> $ITEMS.mk | |
@@ -106,12 +121,30 function template-run { | |||||
106 | echo '' >> $ITEMS.mk |
|
121 | echo '' >> $ITEMS.mk | |
107 | echo 'all:lib' >> $ITEMS.mk |
|
122 | echo 'all:lib' >> $ITEMS.mk | |
108 | echo " @echo Code compiled" >> $ITEMS.mk |
|
123 | echo " @echo Code compiled" >> $ITEMS.mk | |
|
124 | echo '' >> $ITEMS.mk | |||
|
125 | echo 'clean:' >> $ITEMS.mk | |||
|
126 | echo ' rm -f $(OBJDIR)/*.o' >> $ITEMS.mk | |||
|
127 | echo ' rm -f $(TARGETINSTALLPATH)/*.a' >> $ITEMS.mk | |||
|
128 | echo ' rm -f $(HEADERSINSTALLPATH)/*.h' >> $ITEMS.mk | |||
|
129 | echo ' rm -f $(DEVSOURCESND)' >> $ITEMS.mk | |||
|
130 | echo ' rm -f *.d' >> $ITEMS.mk | |||
109 | echo " Makefile writing finished" |
|
131 | echo " Makefile writing finished" | |
110 | echo "" |
|
132 | echo "" | |
111 | echo "=========================================================================" |
|
133 | echo "=========================================================================" | |
112 | echo "" |
|
134 | echo "" | |
|
135 | done | |||
|
136 | echo "" >> Makefile | |||
|
137 | echo "all:" >> Makefile | |||
|
138 | for ITEMS in $TARGETS | |||
|
139 | do | |||
113 | echo " make -f $ITEMS.mk" >> Makefile |
|
140 | echo " make -f $ITEMS.mk" >> Makefile | |
114 | done |
|
141 | done | |
|
142 | echo "" >> Makefile | |||
|
143 | echo "clean:" >> Makefile | |||
|
144 | for ITEMS in $TARGETS | |||
|
145 | do | |||
|
146 | echo " make clean -f $ITEMS.mk" >> Makefile | |||
|
147 | done | |||
115 | fi |
|
148 | fi | |
116 |
|
149 | |||
117 |
|
150 |
@@ -5,12 +5,15 LIBUC = /opt/libuc2 | |||||
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/LandTiger |
|
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/LandTiger | |
6 | HEADERS += bsp.h |
|
6 | HEADERS += bsp.h | |
7 | LIBSOURCES += bsp.c |
|
7 | LIBSOURCES += bsp.c | |
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
8 | OBJECTFILES = $(LIBSOURCES:.c=.o) |
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
9 | ARCH = lpc17XX-arm-noabi-gcc |
|
12 | ARCH = lpc17XX-arm-noabi-gcc | |
10 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
11 | TARGET=libbsp |
|
14 | TARGET=libbsp | |
12 |
LIBUC_INCLUDES=$(LIBUC_INC_DIR_ |
|
15 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_ALLFS_CMD) $(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_24LC0X_CMD) $(LIBUC_INC_DIR_IIC_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
13 |
LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_S |
|
16 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_ALLFS_CMD) $(LIBUC_LIBS_ALLFS) $(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_24LC0X_CMD) $(LIBUC_LIBS_24LC0X) $(LIBUC_LIBS_DIR_IIC_CMD) $(LIBUC_LIBS_IIC) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
14 | TARGETINSTALLPATH=$(LIBUC_BSP_BIN_DIR)/LandTiger |
|
17 | TARGETINSTALLPATH=$(LIBUC_BSP_BIN_DIR)/LandTiger | |
15 | HEADERSINSTALLPATH=$(LIBUC_BSP_INC_DIR)/LandTiger |
|
18 | HEADERSINSTALLPATH=$(LIBUC_BSP_INC_DIR)/LandTiger | |
16 | BSP=generic |
|
19 | BSP=generic | |
@@ -18,3 +21,10 include $(ARCHFOLDER)/rules.mk | |||||
18 |
|
21 | |||
19 | all:lib |
|
22 | all:lib | |
20 | @echo Code compiled |
|
23 | @echo Code compiled | |
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -28,20 +28,23 unsigned int INTOSC =4000000; | |||||
28 | unsigned int RTCOSC =32768; |
|
28 | unsigned int RTCOSC =32768; | |
29 | unsigned int currentCpuFreq=0; |
|
29 | unsigned int currentCpuFreq=0; | |
30 | float VREF0 =(float)3.3; |
|
30 | float VREF0 =(float)3.3; | |
31 |
uartDev |
|
31 | uartDev UART0=(uartDev)0; | |
32 |
uartDev |
|
32 | uartDev UART1=(uartDev)0; | |
33 |
uartDev |
|
33 | uartDev UART2=(uartDev)0; | |
34 |
uartDev |
|
34 | uartDev UART3=(uartDev)0; | |
35 |
|
35 | |||
36 |
i2cDev |
|
36 | i2cDev IIC0=(i2cDev)0; | |
37 |
i2cDev |
|
37 | i2cDev IIC1=(i2cDev)0; | |
38 |
i2cDev |
|
38 | i2cDev IIC2=(i2cDev)0; | |
39 |
|
39 | |||
40 |
sspDev |
|
40 | sspDev SSP0=(sspDev)0; | |
41 |
sspDev |
|
41 | sspDev SSP1=(sspDev)0; | |
42 |
|
42 | |||
43 | sdcardDev SDCARD0; |
|
43 | sdcardDev SDCARD0; | |
44 | blkdevice BLKDEVSDCARD0; |
|
44 | blkdevice BLKDEVSDCARD0; | |
|
45 | dikpartition PART0; | |||
|
46 | FAT32fs fs0; | |||
|
47 | ucdirent root; | |||
45 |
|
48 | |||
46 | eeprom24lc0xDev eeprom0; |
|
49 | eeprom24lc0xDev eeprom0; | |
47 |
|
50 | |||
@@ -121,9 +124,12 void bsp_SD_init() | |||||
121 | LPC_GPIO3->FIODIR |=1<<26; |
|
124 | LPC_GPIO3->FIODIR |=1<<26; | |
122 | LPC_GPIO3->FIODIR &= ~(1<<25); |
|
125 | LPC_GPIO3->FIODIR &= ~(1<<25); | |
123 | LPC_GPIO3->FIOCLR |=1<<26; |
|
126 | LPC_GPIO3->FIOCLR |=1<<26; | |
124 | sdcardmake(&SDCARD0,SSP0,&sspgetnc,&sspputnc,&sspsetdatarate); |
|
127 | sdcardmake(&SDCARD0,SSP0,&sspgetnc,&sspputnc,&sspsetdatarate,&sspgetdatarate); | |
125 | sdcardmakeblkdev(&BLKDEVSDCARD0,&SDCARD0,&bspsdcardselect,&bsppowersdcard,&bspsdcardpresent,&bspsdcardwriteprotected); |
|
128 | sdcardmakeblkdev(&BLKDEVSDCARD0,&SDCARD0,&bspsdcardselect,&bsppowersdcard,&bspsdcardpresent,&bspsdcardwriteprotected); | |
126 |
|
|
129 | BLKDEVSDCARD0.initialize(&BLKDEVSDCARD0); | |
|
130 | mbropen(&BLKDEVSDCARD0,&PART0,1); | |||
|
131 | fat32open(&fs0,&PART0); | |||
|
132 | fat32mkdirent(&fs0,&root); | |||
127 | } |
|
133 | } | |
128 |
|
134 | |||
129 | void consoleputc(char c) |
|
135 | void consoleputc(char c) |
@@ -28,22 +28,27 | |||||
28 | #include <24LC0X.h> |
|
28 | #include <24LC0X.h> | |
29 | #include <blkdevice.h> |
|
29 | #include <blkdevice.h> | |
30 | #include <sdcard.h> |
|
30 | #include <sdcard.h> | |
|
31 | #include <mbr.h> | |||
|
32 | #include <fat32.h> | |||
31 |
|
33 | |||
32 |
|
34 | |||
33 |
extern uartDev |
|
35 | extern uartDev UART0; | |
34 |
extern uartDev |
|
36 | extern uartDev UART1; | |
35 |
extern uartDev |
|
37 | extern uartDev UART2; | |
36 |
extern uartDev |
|
38 | extern uartDev UART3; | |
37 |
|
39 | |||
38 |
extern i2cDev |
|
40 | extern i2cDev IIC0; | |
39 |
extern i2cDev |
|
41 | extern i2cDev IIC1; | |
40 |
extern i2cDev |
|
42 | extern i2cDev IIC2; | |
41 |
|
43 | |||
42 |
extern sspDev |
|
44 | extern sspDev SSP0; | |
43 |
extern sspDev |
|
45 | extern sspDev SSP1; | |
44 |
|
46 | |||
45 | extern sdcardDev SDCARD0; |
|
47 | extern sdcardDev SDCARD0; | |
46 | extern blkdevice BLKDEVSDCARD0; |
|
48 | extern blkdevice BLKDEVSDCARD0; | |
|
49 | extern dikpartition PART0; | |||
|
50 | extern FAT32fs fs0; | |||
|
51 | extern ucdirent root; | |||
47 |
|
52 | |||
48 | extern eeprom24lc0xDev eeprom0; |
|
53 | extern eeprom24lc0xDev eeprom0; | |
49 |
|
54 |
@@ -4,7 +4,7 TARGET = libbsp | |||||
4 | TARGETINSTALLPATH = $(LIBUC_BSP_BIN_DIR)/LandTiger |
|
4 | TARGETINSTALLPATH = $(LIBUC_BSP_BIN_DIR)/LandTiger | |
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/LandTiger |
|
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/LandTiger | |
6 |
|
6 | |||
7 |
LIBS += |
|
7 | LIBS += ALLFS UART SSP 24LC0X IIC CORE UCSTRINGS UHANDLE | |
8 |
|
8 | |||
9 | SOURCES += bsp.c |
|
9 | SOURCES += bsp.c | |
10 |
|
10 |
@@ -6,12 +6,14 include $(LIBUC)/rules/common/rules.mk | |||||
6 | all:subdir |
|
6 | all:subdir | |
7 | make -C generic |
|
7 | make -C generic | |
8 | make -C LandTiger |
|
8 | make -C LandTiger | |
|
9 | make -C LandTigerdualssp | |||
9 | make -C mbed |
|
10 | make -C mbed | |
10 | @echo Code compiled |
|
11 | @echo Code compiled | |
11 |
|
12 | |||
12 | clean: |
|
13 | clean: | |
13 | make clean -C generic |
|
14 | make clean -C generic | |
14 | make clean -C LandTiger |
|
15 | make clean -C LandTiger | |
|
16 | make clean -C LandTigerdualssp | |||
15 | make clean -C mbed |
|
17 | make clean -C mbed | |
16 | @echo Code compiled |
|
18 | @echo Code compiled | |
17 |
|
19 |
@@ -1,4 +1,5 | |||||
1 | TEMPLATE = dir |
|
1 | TEMPLATE = dir | |
2 | SUBDIRS += generic \ |
|
2 | SUBDIRS += generic \ | |
3 | LandTiger \ |
|
3 | LandTiger \ | |
|
4 | LandTigerdualssp \ | |||
4 | mbed |
|
5 | mbed |
@@ -5,7 +5,10 LIBUC = /opt/libuc2 | |||||
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/generic |
|
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/generic | |
6 | HEADERS += bsp.h |
|
6 | HEADERS += bsp.h | |
7 | LIBSOURCES += bsp.c |
|
7 | LIBSOURCES += bsp.c | |
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
8 | OBJECTFILES = $(LIBSOURCES:.c=.o) |
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
9 | ARCH = lpc17XX-arm-noabi-gcc |
|
12 | ARCH = lpc17XX-arm-noabi-gcc | |
10 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
11 | TARGET=libbsp |
|
14 | TARGET=libbsp | |
@@ -18,3 +21,10 include $(ARCHFOLDER)/rules.mk | |||||
18 |
|
21 | |||
19 | all:lib |
|
22 | all:lib | |
20 | @echo Code compiled |
|
23 | @echo Code compiled | |
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -5,12 +5,15 LIBUC = /opt/libuc2 | |||||
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/mbed |
|
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/mbed | |
6 | HEADERS += bsp.h |
|
6 | HEADERS += bsp.h | |
7 | LIBSOURCES += bsp.c |
|
7 | LIBSOURCES += bsp.c | |
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
8 | OBJECTFILES = $(LIBSOURCES:.c=.o) |
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
9 | ARCH = lpc17XX-arm-noabi-gcc |
|
12 | ARCH = lpc17XX-arm-noabi-gcc | |
10 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
11 | TARGET=libbsp |
|
14 | TARGET=libbsp | |
12 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_CORE_CMD) |
|
15 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
13 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) |
|
16 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
14 | TARGETINSTALLPATH=$(LIBUC_BSP_BIN_DIR)/mbed |
|
17 | TARGETINSTALLPATH=$(LIBUC_BSP_BIN_DIR)/mbed | |
15 | HEADERSINSTALLPATH=$(LIBUC_BSP_INC_DIR)/mbed |
|
18 | HEADERSINSTALLPATH=$(LIBUC_BSP_INC_DIR)/mbed | |
16 | BSP=generic |
|
19 | BSP=generic | |
@@ -18,3 +21,10 include $(ARCHFOLDER)/rules.mk | |||||
18 |
|
21 | |||
19 | all:lib |
|
22 | all:lib | |
20 | @echo Code compiled |
|
23 | @echo Code compiled | |
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -27,10 +27,10 unsigned int OSC0 =12000000; | |||||
27 | unsigned int INTOSC =4000000; |
|
27 | unsigned int INTOSC =4000000; | |
28 | unsigned int RTCOSC =32768; |
|
28 | unsigned int RTCOSC =32768; | |
29 | unsigned int currentCpuFreq=0; |
|
29 | unsigned int currentCpuFreq=0; | |
30 |
uartDev |
|
30 | uartDev UART0=(uartDev)0; | |
31 |
uartDev |
|
31 | uartDev UART1=(uartDev)0; | |
32 |
uartDev |
|
32 | uartDev UART2=(uartDev)0; | |
33 |
uartDev |
|
33 | uartDev UART3=(uartDev)0; | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | int bsp_init() |
|
36 | int bsp_init() |
@@ -24,10 +24,10 | |||||
24 | #include "LPC17xx.h" |
|
24 | #include "LPC17xx.h" | |
25 | #include <uart.h> |
|
25 | #include <uart.h> | |
26 |
|
26 | |||
27 |
extern uartDev |
|
27 | extern uartDev UART0; | |
28 |
extern uartDev |
|
28 | extern uartDev UART1; | |
29 |
extern uartDev |
|
29 | extern uartDev UART2; | |
30 |
extern uartDev |
|
30 | extern uartDev UART3; | |
31 |
|
31 | |||
32 | #define VREF0 (float)3.3 |
|
32 | #define VREF0 (float)3.3 | |
33 |
|
33 |
@@ -4,7 +4,7 TARGET = libbsp | |||||
4 | TARGETINSTALLPATH = $(LIBUC_BSP_BIN_DIR)/mbed |
|
4 | TARGETINSTALLPATH = $(LIBUC_BSP_BIN_DIR)/mbed | |
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/mbed |
|
5 | HEADERSINSTALLPATH = $(LIBUC_BSP_INC_DIR)/mbed | |
6 |
|
6 | |||
7 | LIBS += UART CORE |
|
7 | LIBS += UART CORE UHANDLE | |
8 |
|
8 | |||
9 | SOURCES += bsp.c |
|
9 | SOURCES += bsp.c | |
10 |
|
10 |
@@ -7,11 +7,13 all:subdir | |||||
7 | make -C lpc17XX |
|
7 | make -C lpc17XX | |
8 | make -C SDCARD |
|
8 | make -C SDCARD | |
9 | make -C SDCARD2 |
|
9 | make -C SDCARD2 | |
|
10 | make -C MP3Player | |||
10 | @echo Code compiled |
|
11 | @echo Code compiled | |
11 |
|
12 | |||
12 | clean: |
|
13 | clean: | |
13 | make clean -C lpc17XX |
|
14 | make clean -C lpc17XX | |
14 | make clean -C SDCARD |
|
15 | make clean -C SDCARD | |
15 | make clean -C SDCARD2 |
|
16 | make clean -C SDCARD2 | |
|
17 | make clean -C MP3Player | |||
16 | @echo Code compiled |
|
18 | @echo Code compiled | |
17 |
|
19 |
@@ -4,12 +4,15 LIBUC = /opt/libuc2 | |||||
4 |
|
4 | |||
5 | HEADERS += |
|
5 | HEADERS += | |
6 | APPSOURCES += main.c |
|
6 | APPSOURCES += main.c | |
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
7 | OBJECTFILES = $(APPSOURCES:.c=.o) |
|
9 | OBJECTFILES = $(APPSOURCES:.c=.o) | |
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
8 | ARCH = lpc17XX-arm-noabi-gcc |
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |
9 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
10 | TARGET=lpc1768_SDCARD |
|
13 | TARGET=lpc1768_SDCARD | |
11 |
LIBUC_INCLUDES=$(LIBUC_INC_DIR_ |
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_ALLFS_CMD) $(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_24LC0X_CMD) $(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_IIC_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
12 |
LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_S |
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_ALLFS_CMD) $(LIBUC_LIBS_ALLFS) $(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_24LC0X_CMD) $(LIBUC_LIBS_24LC0X) $(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_IIC_CMD) $(LIBUC_LIBS_IIC) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
13 | TARGETINSTALLPATH= |
|
16 | TARGETINSTALLPATH= | |
14 | HEADERSINSTALLPATH= |
|
17 | HEADERSINSTALLPATH= | |
15 | BSP=LandTiger |
|
18 | BSP=LandTiger |
@@ -3,7 +3,7 ARCH = lpc17XX-arm-noabi-gcc | |||||
3 | TARGET = lpc1768_SDCARD |
|
3 | TARGET = lpc1768_SDCARD | |
4 | BSP = LandTiger |
|
4 | BSP = LandTiger | |
5 |
|
5 | |||
6 |
LIBS += |
|
6 | LIBS += ALLFS UART 24LC0X SSP IIC CORE UCSTRINGS UHANDLE | |
7 |
|
7 | |||
8 | SOURCES += main.c |
|
8 | SOURCES += main.c | |
9 |
|
9 |
@@ -4,12 +4,15 LIBUC = /opt/libuc2 | |||||
4 |
|
4 | |||
5 | HEADERS += |
|
5 | HEADERS += | |
6 | APPSOURCES += main.c |
|
6 | APPSOURCES += main.c | |
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
7 | OBJECTFILES = $(APPSOURCES:.c=.o) |
|
9 | OBJECTFILES = $(APPSOURCES:.c=.o) | |
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
8 | ARCH = lpc17XX-arm-noabi-gcc |
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |
9 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
10 | TARGET=lpc1768_SDCARD |
|
13 | TARGET=lpc1768_SDCARD | |
11 |
LIBUC_INCLUDES=$(LIBUC_INC_DIR_ |
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_FSEXPLORER_CMD) $(LIBUC_INC_DIR_ALLFS_CMD) $(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_24LC0X_CMD) $(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_IIC_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) $(LIBUC_INC_DIR_HEXVIEWER_CMD) | |
12 |
LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_ |
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_FSEXPLORER_CMD) $(LIBUC_LIBS_FSEXPLORER) $(LIBUC_LIBS_DIR_ALLFS_CMD) $(LIBUC_LIBS_ALLFS) $(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_24LC0X_CMD) $(LIBUC_LIBS_24LC0X) $(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_IIC_CMD) $(LIBUC_LIBS_IIC) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) $(LIBUC_LIBS_DIR_HEXVIEWER_CMD) $(LIBUC_LIBS_HEXVIEWER) | |
13 | TARGETINSTALLPATH= |
|
16 | TARGETINSTALLPATH= | |
14 | HEADERSINSTALLPATH= |
|
17 | HEADERSINSTALLPATH= | |
15 | BSP=LandTiger |
|
18 | BSP=LandTiger |
@@ -25,23 +25,26 | |||||
25 | #include "core.h" |
|
25 | #include "core.h" | |
26 | #include "uart.h" |
|
26 | #include "uart.h" | |
27 | #include "libucstrings.h" |
|
27 | #include "libucstrings.h" | |
|
28 | #include <hexviewer.h> | |||
|
29 | #include <ucdirent.h> | |||
|
30 | #include <fsexplorer.h> | |||
|
31 | ||||
28 | #define __delay(t) for(volatile int i=0;i<t;i++); |
|
32 | #define __delay(t) for(volatile int i=0;i<t;i++); | |
29 | #define ledspos1 LED1_OFF;LED2_ON;LED3_OFF;LED4_ON;LED5_OFF;LED6_ON;LED7_OFF;LED8_ON |
|
33 | #define ledspos1 LED1_OFF;LED2_ON;LED3_OFF;LED4_ON;LED5_OFF;LED6_ON;LED7_OFF;LED8_ON | |
30 | #define ledspos2 LED1_ON;LED2_OFF;LED3_ON;LED4_OFF;LED5_ON;LED6_OFF;LED7_ON;LED8_OFF |
|
34 | #define ledspos2 LED1_ON;LED2_OFF;LED3_ON;LED4_OFF;LED5_ON;LED6_OFF;LED7_ON;LED8_OFF | |
|
35 | char sector[512]; | |||
31 |
|
36 | |||
32 | int main (void) |
|
37 | int main (void) | |
33 | { |
|
38 | { | |
34 | int i,n; |
|
39 | int i,n; | |
35 | char a[10]; |
|
40 | char a[10]; | |
|
41 | ||||
|
42 | char ocr[4]; | |||
36 | bsp_init(); |
|
43 | bsp_init(); | |
37 | uartsetbaudrate(UART0,38400); |
|
44 | uartsetbaudrate(UART0,38400); | |
38 | libucprintf("hello\n\r"); |
|
45 | libucprintf("hello\n\r"); | |
39 | BLKDEVSDCARD0.initialize(&BLKDEVSDCARD0,0); |
|
|||
40 | switch(SDCARD0.Stat) |
|
46 | switch(SDCARD0.Stat) | |
41 | { |
|
47 | { | |
42 | case 0: |
|
|||
43 | libucprintf("Card initialized\n\r"); |
|
|||
44 | break; |
|
|||
45 | case STA_NOINIT : |
|
48 | case STA_NOINIT : | |
46 | libucprintf("Card NOT initialized\n\r"); |
|
49 | libucprintf("Card NOT initialized\n\r"); | |
47 | break; |
|
50 | break; | |
@@ -51,6 +54,9 int main (void) | |||||
51 | case STA_PROTECT : |
|
54 | case STA_PROTECT : | |
52 | libucprintf("Card protected\n\r"); |
|
55 | libucprintf("Card protected\n\r"); | |
53 | break; |
|
56 | break; | |
|
57 | case 0: | |||
|
58 | libucprintf("Card initialized\n\r"); | |||
|
59 | break; | |||
54 | default: |
|
60 | default: | |
55 | break; |
|
61 | break; | |
56 | } |
|
62 | } | |
@@ -72,13 +78,39 int main (void) | |||||
72 | default: |
|
78 | default: | |
73 | break; |
|
79 | break; | |
74 | } |
|
80 | } | |
|
81 | if(SDCARD0.Stat==0) | |||
|
82 | { | |||
|
83 | fsexplprintBootSector(&BLKDEVSDCARD0); | |||
|
84 | libucprintf("Part1 is 0x%x\n\r",0xff & PART0.TypeCode); | |||
|
85 | libucprintf("Read FAT32 Vol ID @ %x\n\r",PART0.LBABegin); | |||
|
86 | fsexplprintPartInfos(&PART0); | |||
|
87 | libucprintf("fs0.cluster_begin_lba = %x\n\r",fs0.cluster_begin_lba); | |||
|
88 | libucprintf("fs0.BPB_RsvdSecCnt = %x\n\r",fs0.BPB_RsvdSecCnt); | |||
|
89 | libucprintf("\tPrint few sectors of FAT:\n\r"); | |||
|
90 | for(i=0;i<10;i++) | |||
|
91 | { | |||
|
92 | fsexplprintSector(&BLKDEVSDCARD0,fs0.fat_begin_lba+i); | |||
|
93 | } | |||
|
94 | libucprintf("\tPrint few sectors of first clusters:\n\r"); | |||
|
95 | for(i=0;i<10;i++) | |||
|
96 | { | |||
|
97 | fsexplprintSector(&BLKDEVSDCARD0,fs0.cluster_begin_lba+i); | |||
|
98 | } | |||
|
99 | int res=direntgetroot(root); | |||
|
100 | while(res==DIRENT_noErr) | |||
|
101 | { | |||
|
102 | fsexplprintDirentInfos(&root); | |||
|
103 | res=direntgetnext(root); | |||
|
104 | } | |||
|
105 | libucprintf("Exit because of code %d\n\r",res); | |||
|
106 | ||||
|
107 | } | |||
|
108 | libucprintf("SDCARD speed = %dkbps\n\r",SDCARD0.getspeed(SDCARD0.phy)/1000); | |||
75 | while(1) |
|
109 | while(1) | |
76 | { |
|
110 | { | |
77 | ledspos1; |
|
111 | ledspos1; | |
78 |
|
||||
79 | __delay(1024*1024); |
|
112 | __delay(1024*1024); | |
80 | ledspos2; |
|
113 | ledspos2; | |
81 |
|
||||
82 | __delay(1024*1024); |
|
114 | __delay(1024*1024); | |
83 | } |
|
115 | } | |
84 | return 0; |
|
116 | return 0; | |
@@ -95,3 +127,25 int main (void) | |||||
95 |
|
127 | |||
96 |
|
128 | |||
97 |
|
129 | |||
|
130 | ||||
|
131 | ||||
|
132 | ||||
|
133 | ||||
|
134 | ||||
|
135 | ||||
|
136 | ||||
|
137 | ||||
|
138 | ||||
|
139 | ||||
|
140 | ||||
|
141 | ||||
|
142 | ||||
|
143 | ||||
|
144 | ||||
|
145 | ||||
|
146 | ||||
|
147 | ||||
|
148 | ||||
|
149 | ||||
|
150 | ||||
|
151 |
@@ -3,7 +3,7 ARCH = lpc17XX-arm-noabi-gcc | |||||
3 | TARGET = lpc1768_SDCARD |
|
3 | TARGET = lpc1768_SDCARD | |
4 | BSP = LandTiger |
|
4 | BSP = LandTiger | |
5 |
|
5 | |||
6 |
LIBS += |
|
6 | LIBS += FSEXPLORER ALLFS UART 24LC0X SSP IIC CORE UCSTRINGS UHANDLE HEXVIEWER | |
7 |
|
7 | |||
8 | SOURCES += main.c |
|
8 | SOURCES += main.c | |
9 |
|
9 |
@@ -1,4 +1,5 | |||||
1 | TEMPLATE = dir |
|
1 | TEMPLATE = dir | |
2 | SUBDIRS += lpc17XX \ |
|
2 | SUBDIRS += lpc17XX \ | |
3 | SDCARD \ |
|
3 | SDCARD \ | |
4 | SDCARD2 |
|
4 | SDCARD2 \ | |
|
5 | MP3Player |
@@ -4,12 +4,15 LIBUC = /opt/libuc2 | |||||
4 |
|
4 | |||
5 | HEADERS += |
|
5 | HEADERS += | |
6 | APPSOURCES += main.c |
|
6 | APPSOURCES += main.c | |
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
7 | OBJECTFILES = $(APPSOURCES:.c=.o) |
|
9 | OBJECTFILES = $(APPSOURCES:.c=.o) | |
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
8 | ARCH = lpc17XX-arm-noabi-gcc |
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |
9 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
10 | TARGET=lpc1768_iic |
|
13 | TARGET=lpc1768_iic | |
11 |
LIBUC_INCLUDES=$(LIBUC_INC_DIR_ |
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_ALLFS_CMD) $(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_24LC0X_CMD) $(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_IIC_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
12 |
LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_S |
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_ALLFS_CMD) $(LIBUC_LIBS_ALLFS) $(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_24LC0X_CMD) $(LIBUC_LIBS_24LC0X) $(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_IIC_CMD) $(LIBUC_LIBS_IIC) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
13 | TARGETINSTALLPATH= |
|
16 | TARGETINSTALLPATH= | |
14 | HEADERSINSTALLPATH= |
|
17 | HEADERSINSTALLPATH= | |
15 | BSP=LandTiger |
|
18 | BSP=LandTiger |
@@ -3,7 +3,7 ARCH = lpc17XX-arm-noabi-gcc | |||||
3 | TARGET = lpc1768_iic |
|
3 | TARGET = lpc1768_iic | |
4 | BSP = LandTiger |
|
4 | BSP = LandTiger | |
5 |
|
5 | |||
6 |
LIBS += |
|
6 | LIBS += ALLFS UART 24LC0X SSP IIC CORE UCSTRINGS UHANDLE | |
7 |
|
7 | |||
8 | SOURCES += main.c |
|
8 | SOURCES += main.c | |
9 |
|
9 |
@@ -4,12 +4,15 LIBUC = /opt/libuc2 | |||||
4 |
|
4 | |||
5 | HEADERS += |
|
5 | HEADERS += | |
6 | APPSOURCES += main.c |
|
6 | APPSOURCES += main.c | |
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
7 | OBJECTFILES = $(APPSOURCES:.c=.o) |
|
9 | OBJECTFILES = $(APPSOURCES:.c=.o) | |
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
8 | ARCH = lpc17XX-arm-noabi-gcc |
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |
9 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
10 | TARGET=lpc1768_led_blink |
|
13 | TARGET=lpc1768_led_blink | |
11 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_UART_CMD) |
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_ALLFS_CMD) $(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_24LC0X_CMD) $(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_IIC_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
12 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) |
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_ALLFS_CMD) $(LIBUC_LIBS_ALLFS) $(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_24LC0X_CMD) $(LIBUC_LIBS_24LC0X) $(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_IIC_CMD) $(LIBUC_LIBS_IIC) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
13 | TARGETINSTALLPATH= |
|
16 | TARGETINSTALLPATH= | |
14 | HEADERSINSTALLPATH= |
|
17 | HEADERSINSTALLPATH= | |
15 | BSP=mbed |
|
18 | BSP=mbed |
@@ -3,7 +3,7 ARCH = lpc17XX-arm-noabi-gcc | |||||
3 | TARGET = lpc1768_led_blink |
|
3 | TARGET = lpc1768_led_blink | |
4 | BSP = mbed |
|
4 | BSP = mbed | |
5 |
|
5 | |||
6 | LIBS += UART |
|
6 | LIBS += ALLFS UART 24LC0X SSP IIC CORE UCSTRINGS UHANDLE | |
7 |
|
7 | |||
8 | SOURCES += main.c |
|
8 | SOURCES += main.c | |
9 |
|
9 |
@@ -4,12 +4,15 LIBUC = /opt/libuc2 | |||||
4 |
|
4 | |||
5 | HEADERS += |
|
5 | HEADERS += | |
6 | APPSOURCES += main.c |
|
6 | APPSOURCES += main.c | |
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
7 | OBJECTFILES = $(APPSOURCES:.c=.o) |
|
9 | OBJECTFILES = $(APPSOURCES:.c=.o) | |
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
8 | ARCH = lpc17XX-arm-noabi-gcc |
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |
9 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
10 | TARGET=lpc1768_led_blink |
|
13 | TARGET=lpc1768_led_blink | |
11 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_CORE_CMD) |
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_ALLFS_CMD) $(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_24LC0X_CMD) $(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_IIC_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
12 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) |
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_ALLFS_CMD) $(LIBUC_LIBS_ALLFS) $(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_24LC0X_CMD) $(LIBUC_LIBS_24LC0X) $(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_IIC_CMD) $(LIBUC_LIBS_IIC) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
13 | TARGETINSTALLPATH= |
|
16 | TARGETINSTALLPATH= | |
14 | HEADERSINSTALLPATH= |
|
17 | HEADERSINSTALLPATH= | |
15 | BSP=mbed |
|
18 | BSP=mbed |
@@ -3,7 +3,7 ARCH = lpc17XX-arm-noabi-gcc | |||||
3 | TARGET = lpc1768_led_blink |
|
3 | TARGET = lpc1768_led_blink | |
4 | BSP = mbed |
|
4 | BSP = mbed | |
5 |
|
5 | |||
6 | LIBS += UART CORE |
|
6 | LIBS += ALLFS UART 24LC0X SSP IIC CORE UCSTRINGS UHANDLE | |
7 |
|
7 | |||
8 | SOURCES += main.c |
|
8 | SOURCES += main.c | |
9 |
|
9 |
@@ -4,15 +4,18 LIBUC = /opt/libuc2 | |||||
4 |
|
4 | |||
5 | HEADERS += |
|
5 | HEADERS += | |
6 | APPSOURCES += main.c |
|
6 | APPSOURCES += main.c | |
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
7 | OBJECTFILES = $(APPSOURCES:.c=.o) |
|
9 | OBJECTFILES = $(APPSOURCES:.c=.o) | |
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
8 | ARCH = lpc17XX-arm-noabi-gcc |
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |
9 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
10 | TARGET=lpc1768_ssp |
|
13 | TARGET=lpc1768_ssp | |
11 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_24LC0X_CMD) $(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_IIC_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) |
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_ALLFS_CMD) $(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_24LC0X_CMD) $(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_IIC_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
12 |
LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_ |
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_ALLFS_CMD) $(LIBUC_LIBS_ALLFS) $(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_24LC0X_CMD) $(LIBUC_LIBS_24LC0X) $(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_IIC_CMD) $(LIBUC_LIBS_IIC) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
13 | TARGETINSTALLPATH= |
|
16 | TARGETINSTALLPATH= | |
14 | HEADERSINSTALLPATH= |
|
17 | HEADERSINSTALLPATH= | |
15 | BSP=LandTiger |
|
18 | BSP=LandTigerdualssp | |
16 | include $(ARCHFOLDER)/rules.mk |
|
19 | include $(ARCHFOLDER)/rules.mk | |
17 |
|
20 | |||
18 | all:bin |
|
21 | all:bin |
@@ -1,9 +1,9 | |||||
1 | TEMPLATE = app |
|
1 | TEMPLATE = app | |
2 | ARCH = lpc17XX-arm-noabi-gcc |
|
2 | ARCH = lpc17XX-arm-noabi-gcc | |
3 | TARGET = lpc1768_ssp |
|
3 | TARGET = lpc1768_ssp | |
4 | BSP = LandTiger |
|
4 | BSP = LandTigerdualssp | |
5 |
|
5 | |||
6 |
LIBS += 24LC0X |
|
6 | LIBS += ALLFS UART 24LC0X SSP IIC CORE UCSTRINGS UHANDLE | |
7 |
|
7 | |||
8 | SOURCES += main.c |
|
8 | SOURCES += main.c | |
9 |
|
9 |
@@ -49,7 +49,8 int main (void) | |||||
49 | //uartputs(UART2,"Hello World\n\r"); |
|
49 | //uartputs(UART2,"Hello World\n\r"); | |
50 | libucprintf("test %d \n\r",i++); |
|
50 | libucprintf("test %d \n\r",i++); | |
51 | __delay(1024*1024); |
|
51 | __delay(1024*1024); | |
52 |
sspputw(SSP0,0xA5); |
|
52 | sspputw(SSP0,0x10A5); | |
|
53 | sspputw(SSP1,0xf923); | |||
53 | LED1_ON; |
|
54 | LED1_ON; | |
54 | LED2_OFF; |
|
55 | LED2_OFF; | |
55 | LED3_ON; |
|
56 | LED3_ON; |
@@ -4,12 +4,15 LIBUC = /opt/libuc2 | |||||
4 |
|
4 | |||
5 | HEADERS += |
|
5 | HEADERS += | |
6 | APPSOURCES += main.c |
|
6 | APPSOURCES += main.c | |
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
7 | OBJECTFILES = $(APPSOURCES:.c=.o) |
|
9 | OBJECTFILES = $(APPSOURCES:.c=.o) | |
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
8 | ARCH = lpc17XX-arm-noabi-gcc |
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |
9 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
10 | TARGET=lpc1768_uart |
|
13 | TARGET=lpc1768_uart | |
11 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) |
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_ALLFS_CMD) $(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_24LC0X_CMD) $(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_IIC_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
12 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) |
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_ALLFS_CMD) $(LIBUC_LIBS_ALLFS) $(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_24LC0X_CMD) $(LIBUC_LIBS_24LC0X) $(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_IIC_CMD) $(LIBUC_LIBS_IIC) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
13 | TARGETINSTALLPATH= |
|
16 | TARGETINSTALLPATH= | |
14 | HEADERSINSTALLPATH= |
|
17 | HEADERSINSTALLPATH= | |
15 | BSP=mbed |
|
18 | BSP=mbed |
@@ -3,7 +3,7 ARCH = lpc17XX-arm-noabi-gcc | |||||
3 | TARGET = lpc1768_uart |
|
3 | TARGET = lpc1768_uart | |
4 | BSP = mbed |
|
4 | BSP = mbed | |
5 |
|
5 | |||
6 | LIBS += UART CORE UCSTRINGS |
|
6 | LIBS += ALLFS UART 24LC0X SSP IIC CORE UCSTRINGS UHANDLE | |
7 |
|
7 | |||
8 | SOURCES += main.c |
|
8 | SOURCES += main.c | |
9 |
|
9 |
@@ -4,12 +4,15 LIBUC = /opt/libuc2 | |||||
4 |
|
4 | |||
5 | HEADERS += |
|
5 | HEADERS += | |
6 | APPSOURCES += main.c |
|
6 | APPSOURCES += main.c | |
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
7 | OBJECTFILES = $(APPSOURCES:.c=.o) |
|
9 | OBJECTFILES = $(APPSOURCES:.c=.o) | |
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
8 | ARCH = lpc17XX-arm-noabi-gcc |
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |
9 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
10 | TARGET=lpc1768_uart |
|
13 | TARGET=lpc1768_uart | |
11 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) |
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_ALLFS_CMD) $(LIBUC_INC_DIR_UART_CMD) $(LIBUC_INC_DIR_24LC0X_CMD) $(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_IIC_CMD) $(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UCSTRINGS_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
12 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) |
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_ALLFS_CMD) $(LIBUC_LIBS_ALLFS) $(LIBUC_LIBS_DIR_UART_CMD) $(LIBUC_LIBS_UART) $(LIBUC_LIBS_DIR_24LC0X_CMD) $(LIBUC_LIBS_24LC0X) $(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_IIC_CMD) $(LIBUC_LIBS_IIC) $(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UCSTRINGS_CMD) $(LIBUC_LIBS_UCSTRINGS) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
13 | TARGETINSTALLPATH= |
|
16 | TARGETINSTALLPATH= | |
14 | HEADERSINSTALLPATH= |
|
17 | HEADERSINSTALLPATH= | |
15 | BSP=LandTiger |
|
18 | BSP=LandTiger |
@@ -3,7 +3,7 ARCH = lpc17XX-arm-noabi-gcc | |||||
3 | TARGET = lpc1768_uart |
|
3 | TARGET = lpc1768_uart | |
4 | BSP = LandTiger |
|
4 | BSP = LandTiger | |
5 |
|
5 | |||
6 | LIBS += UART CORE UCSTRINGS |
|
6 | LIBS += ALLFS UART 24LC0X SSP IIC CORE UCSTRINGS UHANDLE | |
7 |
|
7 | |||
8 | SOURCES += main.c |
|
8 | SOURCES += main.c | |
9 |
|
9 |
@@ -4,14 +4,18 LIBUC = /opt/libuc2 | |||||
4 | include $(LIBUC)/rules/common/rules.mk |
|
4 | include $(LIBUC)/rules/common/rules.mk | |
5 |
|
5 | |||
6 | all:subdir |
|
6 | all:subdir | |
|
7 | make -C common/UHANDLE | |||
7 |
|
|
8 | make -C lpc21XX | |
8 | make -C lpc17XX |
|
9 | make -C lpc17XX | |
9 | make -C common |
|
10 | make -C common | |
|
11 | make -C apps | |||
10 | @echo Code compiled |
|
12 | @echo Code compiled | |
11 |
|
13 | |||
12 | clean: |
|
14 | clean: | |
|
15 | make clean -C common/UHANDLE | |||
13 |
|
|
16 | make clean -C lpc21XX | |
14 | make clean -C lpc17XX |
|
17 | make clean -C lpc17XX | |
15 | make clean -C common |
|
18 | make clean -C common | |
|
19 | make clean -C apps | |||
16 | @echo Code compiled |
|
20 | @echo Code compiled | |
17 |
|
21 |
@@ -25,14 +25,14 | |||||
25 | /* |
|
25 | /* | |
26 | struct 24LC0X_str |
|
26 | struct 24LC0X_str | |
27 | { |
|
27 | { | |
28 |
i2cDev |
|
28 | i2cDev iicdev; | |
29 | unsigned char devAddress; |
|
29 | unsigned char devAddress; | |
30 | unsigned char size; |
|
30 | unsigned char size; | |
31 | }; |
|
31 | }; | |
32 | */ |
|
32 | */ | |
33 |
|
33 | |||
34 |
|
34 | |||
35 |
void eeprom24lc0xopen(eeprom24lc0xDev* dev,i2cDev |
|
35 | void eeprom24lc0xopen(eeprom24lc0xDev* dev,i2cDev iicdev,unsigned char A0_A1_A2_val,unsigned int size) | |
36 | { |
|
36 | { | |
37 | dev->iicdev = iicdev; |
|
37 | dev->iicdev = iicdev; | |
38 | dev->devAddress = 0x50 | (A0_A1_A2_val & 0x7); |
|
38 | dev->devAddress = 0x50 | (A0_A1_A2_val & 0x7); |
@@ -23,10 +23,11 | |||||
23 | #define B24LC0X_H |
|
23 | #define B24LC0X_H | |
24 |
|
24 | |||
25 | #include "iic.h" |
|
25 | #include "iic.h" | |
|
26 | #include <uhandle.h> | |||
26 |
|
27 | |||
27 | struct eeprom24LC0X_str |
|
28 | struct eeprom24LC0X_str | |
28 | { |
|
29 | { | |
29 |
i2cDev |
|
30 | i2cDev iicdev; | |
30 | unsigned char devAddress; |
|
31 | unsigned char devAddress; | |
31 | unsigned char size; |
|
32 | unsigned char size; | |
32 | }; |
|
33 | }; | |
@@ -34,7 +35,7 struct eeprom24LC0X_str | |||||
34 | typedef struct eeprom24LC0X_str eeprom24lc0xDev; |
|
35 | typedef struct eeprom24LC0X_str eeprom24lc0xDev; | |
35 |
|
36 | |||
36 |
|
37 | |||
37 |
extern void eeprom24lc0xopen(eeprom24lc0xDev* dev,i2cDev |
|
38 | extern void eeprom24lc0xopen(eeprom24lc0xDev* dev,i2cDev iicdev,unsigned char A0_A1_A2_val,unsigned int size); | |
38 |
|
39 | |||
39 | extern void eeprom24lc0xpagewrite(eeprom24lc0xDev dev,unsigned char address,unsigned char* page); |
|
40 | extern void eeprom24lc0xpagewrite(eeprom24lc0xDev dev,unsigned char address,unsigned char* page); | |
40 | extern void eeprom24lc0xpageread(eeprom24lc0xDev dev,unsigned char address,unsigned char* page); |
|
41 | extern void eeprom24lc0xpageread(eeprom24lc0xDev dev,unsigned char address,unsigned char* page); |
@@ -5,7 +5,7 lpc17XX.TARGET = lib24lc0X | |||||
5 | lpc17XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_24LC0X) |
|
5 | lpc17XX.TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_24LC0X) | |
6 | lpc17XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_24LC0X) |
|
6 | lpc17XX.HEADERSINSTALLPATH = $(LIBUC_INC_DIR_24LC0X) | |
7 |
|
7 | |||
8 | lpc17XX.LIBS += CORE IIC |
|
8 | lpc17XX.LIBS += CORE IIC UHANDLE | |
9 |
|
9 | |||
10 | lpc17XX.SOURCES += 24LC0X.c |
|
10 | lpc17XX.SOURCES += 24LC0X.c | |
11 |
|
11 |
@@ -4,3 +4,6 LIBUC = /opt/libuc2 | |||||
4 |
|
4 | |||
5 | all: |
|
5 | all: | |
6 | make -f lpc17XX.mk |
|
6 | make -f lpc17XX.mk | |
|
7 | ||||
|
8 | clean: | |||
|
9 | make clean -f lpc17XX.mk |
@@ -4,12 +4,15 LIBUC = /opt/libuc2 | |||||
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_24LC0X) |
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_24LC0X) | |
5 | HEADERS += 24LC0X.h |
|
5 | HEADERS += 24LC0X.h | |
6 | LIBSOURCES += 24LC0X.c |
|
6 | LIBSOURCES += 24LC0X.c | |
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
7 | OBJECTFILES = $(LIBSOURCES:.c=.o) |
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
8 | ARCH = lpc17XX-arm-noabi-gcc |
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |
9 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
10 | TARGET=lib24lc0X |
|
13 | TARGET=lib24lc0X | |
11 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_IIC_CMD) |
|
14 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_IIC_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
12 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_IIC_CMD) $(LIBUC_LIBS_IIC) |
|
15 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_IIC_CMD) $(LIBUC_LIBS_IIC) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
13 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_24LC0X) |
|
16 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_24LC0X) | |
14 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_24LC0X) |
|
17 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_24LC0X) | |
15 | BSP=generic |
|
18 | BSP=generic | |
@@ -17,3 +20,10 include $(ARCHFOLDER)/rules.mk | |||||
17 |
|
20 | |||
18 | all:lib |
|
21 | all:lib | |
19 | @echo Code compiled |
|
22 | @echo Code compiled | |
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -4,18 +4,18 LIBUC = /opt/libuc2 | |||||
4 | include $(LIBUC)/rules/common/rules.mk |
|
4 | include $(LIBUC)/rules/common/rules.mk | |
5 |
|
5 | |||
6 | all:subdir |
|
6 | all:subdir | |
|
7 | make -C STRINGS | |||
|
8 | make -C HEXVIEWER | |||
7 |
|
|
9 | make -C 24LCXX | |
8 | make -C STRINGS |
|
|||
9 | make -C VS10XX |
|
10 | make -C VS10XX | |
10 | make -C SDCARD |
|
11 | make -C FILE_SYSTEM | |
11 | make -C BLOCKDEVICES |
|
|||
12 | @echo Code compiled |
|
12 | @echo Code compiled | |
13 |
|
13 | |||
14 | clean: |
|
14 | clean: | |
|
15 | make clean -C STRINGS | |||
|
16 | make clean -C HEXVIEWER | |||
15 |
|
|
17 | make clean -C 24LCXX | |
16 | make clean -C STRINGS |
|
|||
17 | make clean -C VS10XX |
|
18 | make clean -C VS10XX | |
18 |
make clean -C |
|
19 | make clean -C FILE_SYSTEM | |
19 | make clean -C BLOCKDEVICES |
|
|||
20 | @echo Code compiled |
|
20 | @echo Code compiled | |
21 |
|
21 |
@@ -5,3 +5,7 LIBUC = /opt/libuc2 | |||||
5 | all: |
|
5 | all: | |
6 | make -f lpc17XX.mk |
|
6 | make -f lpc17XX.mk | |
7 | make -f lpc21XX.mk |
|
7 | make -f lpc21XX.mk | |
|
8 | ||||
|
9 | clean: | |||
|
10 | make clean -f lpc17XX.mk | |||
|
11 | make clean -f lpc21XX.mk |
@@ -1,4 +1,4 | |||||
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 | #-- | |
@@ -188,11 +188,11 int libucprintf(const char* format,...) | |||||
188 | switch(*format) |
|
188 | switch(*format) | |
189 | { |
|
189 | { | |
190 | case 'c': |
|
190 | case 'c': | |
191 | consoleputc((char)va_arg(ap,int)); |
|
191 | consoleputc((char)(0x7f & va_arg(ap,int))); | |
192 | format++; |
|
192 | format++; | |
193 | break; |
|
193 | break; | |
194 | case 'd': |
|
194 | case 'd': | |
195 |
_d_prtconv_(va_arg(ap,int)) |
|
195 | _d_prtconv_(va_arg(ap,int)); | |
196 | format++; |
|
196 | format++; | |
197 | break; |
|
197 | break; | |
198 | case 'e': |
|
198 | case 'e': |
@@ -1,4 +1,4 | |||||
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 | #-- |
@@ -4,7 +4,10 LIBUC = /opt/libuc2 | |||||
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_UCSTRINGS) |
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_UCSTRINGS) | |
5 | HEADERS += libucstrings.h |
|
5 | HEADERS += libucstrings.h | |
6 | LIBSOURCES += libucstrings.c |
|
6 | LIBSOURCES += libucstrings.c | |
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
7 | OBJECTFILES = $(LIBSOURCES:.c=.o) |
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
8 | ARCH = lpc17XX-arm-noabi-gcc |
|
11 | ARCH = lpc17XX-arm-noabi-gcc | |
9 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
10 | TARGET=libucstrings |
|
13 | TARGET=libucstrings | |
@@ -17,3 +20,10 include $(ARCHFOLDER)/rules.mk | |||||
17 |
|
20 | |||
18 | all:lib |
|
21 | all:lib | |
19 | @echo Code compiled |
|
22 | @echo Code compiled | |
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -4,7 +4,10 LIBUC = /opt/libuc2 | |||||
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_UCSTRINGS) |
|
4 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_UCSTRINGS) | |
5 | HEADERS += libucstrings.h |
|
5 | HEADERS += libucstrings.h | |
6 | LIBSOURCES += libucstrings.c |
|
6 | LIBSOURCES += libucstrings.c | |
|
7 | OBJDIR = obj | |||
|
8 | BINDIR = bin | |||
7 | OBJECTFILES = $(LIBSOURCES:.c=.o) |
|
9 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
|
10 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
8 | ARCH = lpc21XX-arm-noabi-gcc |
|
11 | ARCH = lpc21XX-arm-noabi-gcc | |
9 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc |
|
12 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |
10 | TARGET=libucstrings |
|
13 | TARGET=libucstrings | |
@@ -17,3 +20,10 include $(ARCHFOLDER)/rules.mk | |||||
17 |
|
20 | |||
18 | all:lib |
|
21 | all:lib | |
19 | @echo Code compiled |
|
22 | @echo Code compiled | |
|
23 | ||||
|
24 | clean: | |||
|
25 | rm -f $(OBJDIR)/*.o | |||
|
26 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
27 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
28 | rm -f $(DEVSOURCESND) | |||
|
29 | rm -f *.d |
@@ -5,12 +5,15 LIBUC = /opt/libuc2 | |||||
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_VS10XX) |
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_VS10XX) | |
6 | HEADERS += vs1053.h |
|
6 | HEADERS += vs1053.h | |
7 | LIBSOURCES += vs1053.c |
|
7 | LIBSOURCES += vs1053.c | |
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
8 | OBJECTFILES = $(LIBSOURCES:.c=.o) |
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
9 | ARCH = lpc17XX-arm-noabi-gcc |
|
12 | ARCH = lpc17XX-arm-noabi-gcc | |
10 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
11 | TARGET=libvs10XX |
|
14 | TARGET=libvs10XX | |
12 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_SSP_CMD) |
|
15 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_SSP_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
13 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) |
|
16 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_SSP_CMD) $(LIBUC_LIBS_SSP) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
14 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_VS10XX) |
|
17 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_VS10XX) | |
15 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_VS10XX) |
|
18 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_VS10XX) | |
16 | BSP=generic |
|
19 | BSP=generic | |
@@ -18,3 +21,10 include $(ARCHFOLDER)/rules.mk | |||||
18 |
|
21 | |||
19 | all:lib |
|
22 | all:lib | |
20 | @echo Code compiled |
|
23 | @echo Code compiled | |
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -23,7 +23,7 | |||||
23 | #include "vs1053.h" |
|
23 | #include "vs1053.h" | |
24 | //#include <bsp.h> |
|
24 | //#include <bsp.h> | |
25 |
|
25 | |||
26 |
void vs1053open(vs1053Dev* codec,sspDev |
|
26 | void vs1053open(vs1053Dev* codec,sspDev dev){ | |
27 | codec->SSP_device = dev; |
|
27 | codec->SSP_device = dev; | |
28 |
|
28 | |||
29 | } |
|
29 | } |
@@ -1,4 +1,4 | |||||
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 | #-- | |
@@ -19,7 +19,9 | |||||
19 | #-- Author : Alexis Jeandet |
|
19 | #-- Author : Alexis Jeandet | |
20 | #-- Mail : alexis.jeandet@gmail.com |
|
20 | #-- Mail : alexis.jeandet@gmail.com | |
21 | #-------------------------------------------------------------------------------*/ |
|
21 | #-------------------------------------------------------------------------------*/ | |
22 |
|
22 | #ifndef VS1053_H | ||
|
23 | #define VS1053_H | |||
|
24 | #include <uhandle.h> | |||
23 |
|
25 | |||
24 | #define VSMODE 0 |
|
26 | #define VSMODE 0 | |
25 | #define VSSTATUS 1 |
|
27 | #define VSSTATUS 1 | |
@@ -40,13 +42,13 | |||||
40 |
|
42 | |||
41 | struct vs1053Regs |
|
43 | struct vs1053Regs | |
42 | { |
|
44 | { | |
43 |
sspDev |
|
45 | sspDev SSP_device; | |
44 | int a; |
|
46 | int a; | |
45 | }; |
|
47 | }; | |
46 |
|
48 | |||
47 | typedef struct vs1053Regs vs1053Dev; |
|
49 | typedef struct vs1053Regs vs1053Dev; | |
48 |
|
50 | |||
49 |
void vs1053open(vs1053Dev* codec,sspDev |
|
51 | void vs1053open(vs1053Dev* codec,sspDev dev); | |
50 | void vs1053softreset(vs1053Dev* dev); |
|
52 | void vs1053softreset(vs1053Dev* dev); | |
51 | int vs1053cmdread(vs1053Dev* dev,char address); |
|
53 | int vs1053cmdread(vs1053Dev* dev,char address); | |
52 | void vs1053cmdwrite(vs1053Dev* dev,char address,int value); |
|
54 | void vs1053cmdwrite(vs1053Dev* dev,char address,int value); | |
@@ -55,4 +57,22 extern void vs10XXclearXCS(); | |||||
55 | extern void vs10XXsetXCS(); |
|
57 | extern void vs10XXsetXCS(); | |
56 | extern int vs10XXDREQ(); |
|
58 | extern int vs10XXDREQ(); | |
57 |
|
59 | |||
|
60 | #endif | |||
58 |
|
61 | |||
|
62 | ||||
|
63 | ||||
|
64 | ||||
|
65 | ||||
|
66 | ||||
|
67 | ||||
|
68 | ||||
|
69 | ||||
|
70 | ||||
|
71 | ||||
|
72 | ||||
|
73 | ||||
|
74 | ||||
|
75 | ||||
|
76 | ||||
|
77 | ||||
|
78 |
@@ -4,7 +4,7 TARGET = libvs10XX | |||||
4 | TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_VS10XX) |
|
4 | TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_VS10XX) | |
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_VS10XX) |
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_VS10XX) | |
6 |
|
6 | |||
7 | LIBS += CORE SSP |
|
7 | LIBS += CORE SSP UHANDLE | |
8 |
|
8 | |||
9 | SOURCES += vs1053.c |
|
9 | SOURCES += vs1053.c | |
10 |
|
10 |
@@ -1,6 +1,6 | |||||
1 | TEMPLATE = dir |
|
1 | TEMPLATE = dir | |
2 |
SUBDIRS += |
|
2 | SUBDIRS += STRINGS \ | |
3 | STRINGS \ |
|
3 | HEXVIEWER \ | |
|
4 | 24LCXX \ | |||
4 | VS10XX \ |
|
5 | VS10XX \ | |
5 | SDCARD \ |
|
6 | FILE_SYSTEM | |
6 | BLOCKDEVICES |
|
@@ -1,6 +1,8 | |||||
1 | TEMPLATE = dir |
|
1 | TEMPLATE = dir | |
2 | SUBDIRS += lpc21XX \ |
|
2 | SUBDIRS += common/UHANDLE \ | |
|
3 | lpc21XX \ | |||
3 | lpc17XX \ |
|
4 | lpc17XX \ | |
4 | LEON3 \ |
|
5 | LEON3 \ | |
5 | common |
|
6 | common \ | |
|
7 | apps | |||
6 |
|
8 |
@@ -5,7 +5,10 LIBUC = /opt/libuc2 | |||||
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/CORE |
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/CORE | |
6 | HEADERS += core.h |
|
6 | HEADERS += core.h | |
7 | LIBSOURCES += core.c |
|
7 | LIBSOURCES += core.c | |
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
8 | OBJECTFILES = $(LIBSOURCES:.c=.o) |
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
9 | ARCH = lpc17XX-arm-noabi-gcc |
|
12 | ARCH = lpc17XX-arm-noabi-gcc | |
10 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
11 | TARGET=libcore |
|
14 | TARGET=libcore | |
@@ -18,3 +21,10 include $(ARCHFOLDER)/rules.mk | |||||
18 |
|
21 | |||
19 | all:lib |
|
22 | all:lib | |
20 | @echo Code compiled |
|
23 | @echo Code compiled | |
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -5,12 +5,15 LIBUC = /opt/libuc2 | |||||
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_IIC) |
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_IIC) | |
6 | HEADERS += iic.h |
|
6 | HEADERS += iic.h | |
7 | LIBSOURCES += iic.c |
|
7 | LIBSOURCES += iic.c | |
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
8 | OBJECTFILES = $(LIBSOURCES:.c=.o) |
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
9 | ARCH = lpc17XX-arm-noabi-gcc |
|
12 | ARCH = lpc17XX-arm-noabi-gcc | |
10 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
11 | TARGET=libiic |
|
14 | TARGET=libiic | |
12 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) |
|
15 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
13 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) |
|
16 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
14 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_IIC) |
|
17 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_IIC) | |
15 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_IIC) |
|
18 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_IIC) | |
16 | BSP=generic |
|
19 | BSP=generic | |
@@ -18,3 +21,10 include $(ARCHFOLDER)/rules.mk | |||||
18 |
|
21 | |||
19 | all:lib |
|
22 | all:lib | |
20 | @echo Code compiled |
|
23 | @echo Code compiled | |
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -22,29 +22,27 | |||||
22 | #include "iic.h" |
|
22 | #include "iic.h" | |
23 | #include "core.h" |
|
23 | #include "core.h" | |
24 |
|
24 | |||
25 | #define iicputdata(iicdev,W,IICONSET,IICONCLR) {(iicdev)->I2DAT = (W);\ |
|
25 | #define iicputdata(iicdev,W,IICONSET,IICONCLR) {((_i2cDev)(iicdev))->I2DAT = (W);\ | |
26 | (iicdev)->I2CONSET = (IICONSET);\ |
|
26 | ((_i2cDev)(iicdev))->I2CONSET = (IICONSET);\ | |
27 | (iicdev)->I2CONCLR = (IICONCLR);} |
|
27 | ((_i2cDev)(iicdev))->I2CONCLR = (IICONCLR);} | |
28 |
|
28 | |||
29 | #define iicgetdata(iicdev,W,IICONSET,IICONCLR) {(W) = (iicdev)->I2DAT;\ |
|
29 | #define iicgetdata(iicdev,W,IICONSET,IICONCLR) {(W) = ((_i2cDev)(iicdev))->I2DAT;\ | |
30 | (iicdev)->I2CONSET = (IICONSET);\ |
|
30 | ((_i2cDev)(iicdev))->I2CONSET = (IICONSET);\ | |
31 | (iicdev)->I2CONCLR = (IICONCLR);} |
|
31 | ((_i2cDev)(iicdev))->I2CONCLR = (IICONCLR);} | |
32 |
|
32 | |||
33 |
|
33 | i2ctrl i2cwrite2(i2cDev dev,char address,char*cmd,int* cmdcnt,char*data,int* datcnt) | ||
34 |
|
||||
35 | i2ctrl i2cwrite2(i2cDev* dev,char address,char*cmd,int* cmdcnt,char*data,int* datcnt) |
|
|||
36 | { |
|
34 | { | |
37 | char iicdat=0; |
|
35 | char iicdat=0; | |
38 | dev->I2CONCLR = 0x28; |
|
36 | ((_i2cDev)dev)->I2CONCLR = 0x28; | |
39 | iicdat = (address<<1) & 0xFE; |
|
37 | iicdat = (address<<1) & 0xFE; | |
40 | int count = (*datcnt) + 2; |
|
38 | int count = (*datcnt) + 2; | |
41 | (*datcnt) = 0; |
|
39 | (*datcnt) = 0; | |
42 | while(dev->I2STAT != 0xF8); //waiting for device to be ready /!\ should add timeout |
|
40 | while(((_i2cDev)dev)->I2STAT != 0xF8); //waiting for device to be ready /!\ should add timeout | |
43 | dev->I2CONSET = (1<<5); //initiate transfert |
|
41 | ((_i2cDev)dev)->I2CONSET = (1<<5); //initiate transfert | |
44 | while(count>0) |
|
42 | while(count>0) | |
45 | { |
|
43 | { | |
46 | while((dev->I2CONSET & 0x08)!=0x08); |
|
44 | while((((_i2cDev)dev)->I2CONSET & 0x08)!=0x08); | |
47 | switch(dev->I2STAT) |
|
45 | switch(((_i2cDev)dev)->I2STAT) | |
48 | { |
|
46 | { | |
49 | case 0x08: |
|
47 | case 0x08: | |
50 | iicputdata(dev,iicdat,(1<<2),0x28); |
|
48 | iicputdata(dev,iicdat,(1<<2),0x28); | |
@@ -99,26 +97,26 i2ctrl i2cwrite2(i2cDev* dev,char addres | |||||
99 | } |
|
97 | } | |
100 |
|
98 | |||
101 | } |
|
99 | } | |
102 | dev->I2CONSET = (1<<4) + (1<<2); |
|
100 | ((_i2cDev)dev)->I2CONSET = (1<<4) + (1<<2); | |
103 | dev->I2CONCLR = 1<<3; |
|
101 | ((_i2cDev)dev)->I2CONCLR = 1<<3; | |
104 | return i2noerr; |
|
102 | return i2noerr; | |
105 | } |
|
103 | } | |
106 |
|
104 | |||
107 |
|
105 | |||
108 |
|
106 | |||
109 |
i2ctrl i2cwrite(i2cDev |
|
107 | i2ctrl i2cwrite(i2cDev dev,char address,char*data,int* cnt) | |
110 | { |
|
108 | { | |
111 | char iicdat=0; |
|
109 | char iicdat=0; | |
112 | dev->I2CONCLR = 0x28; |
|
110 | ((_i2cDev)dev)->I2CONCLR = 0x28; | |
113 | iicdat = (address<<1) & 0xFE; |
|
111 | iicdat = (address<<1) & 0xFE; | |
114 | int count = (*cnt) + 1; |
|
112 | int count = (*cnt) + 1; | |
115 | *cnt = 0; |
|
113 | *cnt = 0; | |
116 | while(dev->I2STAT != 0xF8); //waiting for device to be ready /!\ should add timeout |
|
114 | while(((_i2cDev)dev)->I2STAT != 0xF8); //waiting for device to be ready /!\ should add timeout | |
117 | dev->I2CONSET = (1<<5); //initiate transfert |
|
115 | ((_i2cDev)dev)->I2CONSET = (1<<5); //initiate transfert | |
118 | while(count>0) |
|
116 | while(count>0) | |
119 | { |
|
117 | { | |
120 | while((dev->I2CONSET & 0x08)!=0x08); |
|
118 | while((((_i2cDev)dev)->I2CONSET & 0x08)!=0x08); | |
121 | switch(dev->I2STAT) |
|
119 | switch(((_i2cDev)dev)->I2STAT) | |
122 | { |
|
120 | { | |
123 | case 0x08: |
|
121 | case 0x08: | |
124 | iicputdata(dev,iicdat,(1<<2),0x28); |
|
122 | iicputdata(dev,iicdat,(1<<2),0x28); | |
@@ -156,27 +154,27 i2ctrl i2cwrite(i2cDev* dev,char address | |||||
156 | } |
|
154 | } | |
157 |
|
155 | |||
158 | } |
|
156 | } | |
159 | dev->I2CONSET = (1<<4) + (1<<2); |
|
157 | ((_i2cDev)dev)->I2CONSET = (1<<4) + (1<<2); | |
160 | dev->I2CONCLR = 1<<3; |
|
158 | ((_i2cDev)dev)->I2CONCLR = 1<<3; | |
161 | return i2noerr; |
|
159 | return i2noerr; | |
162 | } |
|
160 | } | |
163 |
|
161 | |||
164 |
|
162 | |||
165 |
i2ctrl i2cread(i2cDev |
|
163 | i2ctrl i2cread(i2cDev dev,char address,char*data,int* cnt) | |
166 | { |
|
164 | { | |
167 | char iicdat=0; |
|
165 | char iicdat=0; | |
168 | dev->I2CONCLR = 0x28; |
|
166 | ((_i2cDev)dev)->I2CONCLR = 0x28; | |
169 | iicdat = (address<<1) + 1; |
|
167 | iicdat = (address<<1) + 1; | |
170 | unsigned int count = (*cnt); |
|
168 | unsigned int count = (*cnt); | |
171 | *cnt = 0; |
|
169 | *cnt = 0; | |
172 | while(dev->I2STAT != 0xF8); //waiting for device to be ready /!\ should add timeout |
|
170 | while(((_i2cDev)dev)->I2STAT != 0xF8); //waiting for device to be ready /!\ should add timeout | |
173 | dev->I2CONSET = (1<<5); //initiate transfert |
|
171 | ((_i2cDev)dev)->I2CONSET = (1<<5); //initiate transfert | |
174 | while(count!=0) |
|
172 | while(count!=0) | |
175 | { |
|
173 | { | |
176 | while((dev->I2CONSET & 0x08)!=0x08); |
|
174 | while((((_i2cDev)dev)->I2CONSET & 0x08)!=0x08); | |
177 | switch(dev->I2STAT) |
|
175 | switch(((_i2cDev)dev)->I2STAT) | |
178 | { |
|
176 | { | |
179 | while((dev->I2CONSET & (1<<3))!=(1<<3)); |
|
177 | while((((_i2cDev)dev)->I2CONSET & (1<<3))!=(1<<3)); | |
180 | case 0x08: |
|
178 | case 0x08: | |
181 | iicputdata(dev,iicdat,(1<<2),0x28); |
|
179 | iicputdata(dev,iicdat,(1<<2),0x28); | |
182 | break; |
|
180 | break; | |
@@ -184,9 +182,9 i2ctrl i2cread(i2cDev* dev,char address, | |||||
184 | iicputdata(dev,iicdat,(1<<2),0x28); |
|
182 | iicputdata(dev,iicdat,(1<<2),0x28); | |
185 | break; |
|
183 | break; | |
186 | case 0x40: |
|
184 | case 0x40: | |
187 | if((count!=1)) dev->I2CONSET = (1<<2); |
|
185 | if((count!=1)) ((_i2cDev)dev)->I2CONSET = (1<<2); | |
188 | else dev->I2CONCLR = (1<<2); |
|
186 | else ((_i2cDev)dev)->I2CONCLR = (1<<2); | |
189 | dev->I2CONCLR = 1<<3; |
|
187 | ((_i2cDev)dev)->I2CONCLR = 1<<3; | |
190 | break; |
|
188 | break; | |
191 | case 0x50: |
|
189 | case 0x50: | |
192 | if((count==2)) iicgetdata(dev,iicdat,(0),(0x0c)) |
|
190 | if((count==2)) iicgetdata(dev,iicdat,(0),(0x0c)) | |
@@ -197,8 +195,8 i2ctrl i2cread(i2cDev* dev,char address, | |||||
197 | data++; |
|
195 | data++; | |
198 | break; |
|
196 | break; | |
199 | case 0x48: |
|
197 | case 0x48: | |
200 | dev->I2CONSET = 0x14; |
|
198 | ((_i2cDev)dev)->I2CONSET = 0x14; | |
201 | dev->I2CONCLR = 8; |
|
199 | ((_i2cDev)dev)->I2CONCLR = 8; | |
202 | return i2noerr; |
|
200 | return i2noerr; | |
203 | break; |
|
201 | break; | |
204 | case 0x58: |
|
202 | case 0x58: | |
@@ -214,49 +212,50 i2ctrl i2cread(i2cDev* dev,char address, | |||||
214 | } |
|
212 | } | |
215 |
|
213 | |||
216 | } |
|
214 | } | |
217 |
dev->I2CONSET = (1<<4); |
|
215 | ((_i2cDev)dev)->I2CONSET = (1<<4); | |
218 |
|
|
216 | ((_i2cDev)dev)->I2CONCLR =(1<<2); | |
|
217 | ((_i2cDev)dev)->I2CONCLR = 1<<3; | |||
219 | return i2noerr; |
|
218 | return i2noerr; | |
220 | } |
|
219 | } | |
221 |
|
220 | |||
222 |
|
221 | |||
223 |
void i2csetup(i2cDev |
|
222 | void i2csetup(i2cDev dev,int clkH,int clkL) | |
224 | { |
|
223 | { | |
225 | dev->I2CONCLR = 0x6C; |
|
224 | ((_i2cDev)dev)->I2CONCLR = 0x6C; | |
226 | dev->I2SCLH = clkH; |
|
225 | ((_i2cDev)dev)->I2SCLH = clkH; | |
227 | dev->I2SCLL = clkL; |
|
226 | ((_i2cDev)dev)->I2SCLL = clkL; | |
228 | dev->I2CONSET = 1<<6; //enable I2C block |
|
227 | ((_i2cDev)dev)->I2CONSET = 1<<6; //enable I2C block | |
229 | dev->I2CONCLR = 0x28; |
|
228 | ((_i2cDev)dev)->I2CONCLR = 0x28; | |
230 | } |
|
229 | } | |
231 |
|
230 | |||
232 |
|
231 | |||
233 |
void i2cenable(i2cDev |
|
232 | void i2cenable(i2cDev dev) | |
234 | { |
|
233 | { | |
235 | dev->I2CONSET = 1<<6; |
|
234 | ((_i2cDev)dev)->I2CONSET = 1<<6; | |
236 | } |
|
235 | } | |
237 |
|
236 | |||
238 |
|
237 | |||
239 |
void i2cdisable(i2cDev |
|
238 | void i2cdisable(i2cDev dev) | |
240 | { |
|
239 | { | |
241 | dev->I2CONCLR = (1<<6); |
|
240 | ((_i2cDev)dev)->I2CONCLR = (1<<6); | |
242 | } |
|
241 | } | |
243 |
|
242 | |||
244 |
|
243 | |||
245 |
i2cDev |
|
244 | i2cDev i2copen(int count){ | |
246 |
i2cDev |
|
245 | i2cDev dev; | |
247 | switch(count) |
|
246 | switch(count) | |
248 | { |
|
247 | { | |
249 | case 0: |
|
248 | case 0: | |
250 |
dev = (i2cDev |
|
249 | dev = (i2cDev)((unsigned long)LPC_I2C0_BASE); | |
251 | break; |
|
250 | break; | |
252 | case 1: |
|
251 | case 1: | |
253 |
dev = (i2cDev |
|
252 | dev = (i2cDev)((unsigned long)LPC_I2C1_BASE); | |
254 | break; |
|
253 | break; | |
255 | case 2: |
|
254 | case 2: | |
256 |
dev = (i2cDev |
|
255 | dev = (i2cDev)((unsigned long)LPC_I2C2_BASE); | |
257 | break; |
|
256 | break; | |
258 | default: |
|
257 | default: | |
259 |
dev = (i2cDev |
|
258 | dev = (i2cDev)0; | |
260 | break; |
|
259 | break; | |
261 | } |
|
260 | } | |
262 | return dev; |
|
261 | return dev; | |
@@ -264,7 +263,7 i2cDev* i2copen(int count){ | |||||
264 |
|
263 | |||
265 |
|
264 | |||
266 |
|
265 | |||
267 |
unsigned char i2cgetpclkfactor(i2cDev |
|
266 | unsigned char i2cgetpclkfactor(i2cDev dev) | |
268 | { |
|
267 | { | |
269 | unsigned int clksel=0; |
|
268 | unsigned int clksel=0; | |
270 | const char clkselDec[]={4,1,2,8}; |
|
269 | const char clkselDec[]={4,1,2,8}; | |
@@ -286,7 +285,7 unsigned char i2cgetpclkfactor(i2cDev* d | |||||
286 | } |
|
285 | } | |
287 |
|
286 | |||
288 |
|
287 | |||
289 |
void i2csetpclkfactor(i2cDev |
|
288 | void i2csetpclkfactor(i2cDev dev,unsigned char pclkfactor) | |
290 | { |
|
289 | { | |
291 | const char clkselDec[]={1,1,2,2,0,0,0,0,3}; |
|
290 | const char clkselDec[]={1,1,2,2,0,0,0,0,3}; | |
292 | unsigned int clksel=0; |
|
291 | unsigned int clksel=0; | |
@@ -311,7 +310,7 void i2csetpclkfactor(i2cDev* dev,unsign | |||||
311 | } |
|
310 | } | |
312 |
|
311 | |||
313 |
|
312 | |||
314 |
void i2csetdatarate(i2cDev |
|
313 | void i2csetdatarate(i2cDev dev,unsigned int dataRate) | |
315 | { |
|
314 | { | |
316 | unsigned int pclk = 0; |
|
315 | unsigned int pclk = 0; | |
317 | unsigned int cpuclk=0; |
|
316 | unsigned int cpuclk=0; | |
@@ -324,16 +323,16 void i2csetdatarate(i2cDev* dev,unsigned | |||||
324 | i2csetup(dev,i2csclkl,i2csclkl); |
|
323 | i2csetup(dev,i2csclkl,i2csclkl); | |
325 | } |
|
324 | } | |
326 |
|
325 | |||
327 |
int i2cgetdatarate(i2cDev |
|
326 | int i2cgetdatarate(i2cDev dev) | |
328 | { |
|
327 | { | |
329 | unsigned int dataRate=0; |
|
328 | unsigned int dataRate=0; | |
330 | unsigned int pclk = 0; |
|
329 | unsigned int pclk = 0; | |
331 | unsigned int cpuclk=0; |
|
330 | unsigned int cpuclk=0; | |
332 | unsigned int i2csclkl=0; |
|
331 | unsigned int i2csclkl=0; | |
333 | if(dev==0)return; |
|
332 | if(dev==0)return 0; | |
334 | cpuclk = coregetCpuFreq(); |
|
333 | cpuclk = coregetCpuFreq(); | |
335 | pclk = cpuclk / i2cgetpclkfactor(dev); |
|
334 | pclk = cpuclk / i2cgetpclkfactor(dev); | |
336 | dataRate = pclk /( dev->I2SCLH + dev->I2SCLL); |
|
335 | dataRate = pclk /( ((_i2cDev)dev)->I2SCLH + ((_i2cDev)dev)->I2SCLL); | |
337 | return dataRate; |
|
336 | return dataRate; | |
338 | } |
|
337 | } | |
339 |
|
338 |
@@ -21,7 +21,9 | |||||
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #ifndef IIC_H |
|
22 | #ifndef IIC_H | |
23 | #define IIC_H |
|
23 | #define IIC_H | |
|
24 | ||||
24 | #include "LPC17xx.h" |
|
25 | #include "LPC17xx.h" | |
|
26 | #include <uhandle.h> | |||
25 |
|
27 | |||
26 | enum iicctrlvals |
|
28 | enum iicctrlvals | |
27 | { |
|
29 | { | |
@@ -45,19 +47,20 struct lpc17XXi2cRegs | |||||
45 | unsigned long I2CONCLR; |
|
47 | unsigned long I2CONCLR; | |
46 | }; |
|
48 | }; | |
47 |
|
49 | |||
48 | typedef volatile struct lpc17XXi2cRegs i2cDev; |
|
50 | typedef volatile struct lpc17XXi2cRegs* _i2cDev; | |
|
51 | typedef UHANDLE i2cDev; | |||
49 |
|
52 | |||
50 |
extern i2ctrl i2cwrite(i2cDev |
|
53 | extern i2ctrl i2cwrite(i2cDev dev,char address,char*data,int* cnt); | |
51 |
extern i2ctrl i2cwrite2(i2cDev |
|
54 | extern i2ctrl i2cwrite2(i2cDev dev,char address,char*cmd,int* cmdcnt,char*data,int* datcnt); | |
52 |
extern i2ctrl i2cread(i2cDev |
|
55 | extern i2ctrl i2cread(i2cDev dev,char address,char*data,int* cnt); | |
53 |
extern i2cDev |
|
56 | extern i2cDev i2copen(int count); | |
54 |
extern void i2cenable(i2cDev |
|
57 | extern void i2cenable(i2cDev dev); | |
55 |
extern void i2cdisable(i2cDev |
|
58 | extern void i2cdisable(i2cDev dev); | |
56 |
extern void i2csetup(i2cDev |
|
59 | extern void i2csetup(i2cDev dev,int clkH,int clkL); | |
57 |
extern unsigned char i2cgetpclkfactor(i2cDev |
|
60 | extern unsigned char i2cgetpclkfactor(i2cDev dev); | |
58 |
extern void i2csetpclkfactor(i2cDev |
|
61 | extern void i2csetpclkfactor(i2cDev dev,unsigned char pclkfactor); | |
59 |
extern void i2csetdatarate(i2cDev |
|
62 | extern void i2csetdatarate(i2cDev dev,unsigned int dataRate); | |
60 |
extern int i2cgetdatarate(i2cDev |
|
63 | extern int i2cgetdatarate(i2cDev dev); | |
61 | #endif |
|
64 | #endif | |
62 |
|
65 | |||
63 |
|
66 |
@@ -4,7 +4,7 TARGET = libiic | |||||
4 | TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_IIC) |
|
4 | TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_IIC) | |
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_IIC) |
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_IIC) | |
6 |
|
6 | |||
7 | LIBS += CORE |
|
7 | LIBS += CORE UHANDLE | |
8 |
|
8 | |||
9 | SOURCES += iic.c |
|
9 | SOURCES += iic.c | |
10 |
|
10 |
@@ -5,12 +5,15 LIBUC = /opt/libuc2 | |||||
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_SSP) |
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_SSP) | |
6 | HEADERS += ssp.h |
|
6 | HEADERS += ssp.h | |
7 | LIBSOURCES += ssp.c |
|
7 | LIBSOURCES += ssp.c | |
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
8 | OBJECTFILES = $(LIBSOURCES:.c=.o) |
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
9 | ARCH = lpc17XX-arm-noabi-gcc |
|
12 | ARCH = lpc17XX-arm-noabi-gcc | |
10 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
11 | TARGET=libssp |
|
14 | TARGET=libssp | |
12 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) |
|
15 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
13 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) |
|
16 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
14 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_SSP) |
|
17 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR_SSP) | |
15 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_SSP) |
|
18 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR_SSP) | |
16 | BSP=generic |
|
19 | BSP=generic | |
@@ -18,3 +21,10 include $(ARCHFOLDER)/rules.mk | |||||
18 |
|
21 | |||
19 | all:lib |
|
22 | all:lib | |
20 | @echo Code compiled |
|
23 | @echo Code compiled | |
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -23,99 +23,99 | |||||
23 | #include "core.h" |
|
23 | #include "core.h" | |
24 |
|
24 | |||
25 |
|
25 | |||
26 |
void sspputw(sspDev |
|
26 | void sspputw(sspDev dev,int c) { | |
27 | volatile int a; |
|
27 | volatile int a; | |
28 | dev->SSPDataReg = c; |
|
28 | ((_sspDev)dev)->SSPDataReg = c; | |
29 | while (((dev->SSPStatReg & (1<<4)))); |
|
29 | while (((((_sspDev)dev)->SSPStatReg & (1<<4)))); | |
30 | a=dev->SSPDataReg; |
|
30 | a=((_sspDev)dev)->SSPDataReg; | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 |
void sspputc(sspDev |
|
33 | void sspputc(sspDev dev,char c) { | |
34 | volatile char a; |
|
34 | volatile char a; | |
35 | dev->SSPDataReg = c; |
|
35 | ((_sspDev)dev)->SSPDataReg = c; | |
36 | while (((dev->SSPStatReg & (1<<4)))); |
|
36 | while (((((_sspDev)dev)->SSPStatReg & (1<<4)))); | |
37 | a=dev->SSPDataReg; |
|
37 | a=((_sspDev)dev)->SSPDataReg; | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 |
void sspputnc(sspDev |
|
40 | void sspputnc(sspDev dev,const char *c,unsigned int n) | |
41 | { |
|
41 | { | |
42 | volatile char a; |
|
42 | volatile char a; | |
43 | while(n--) |
|
43 | while(n--) | |
44 | { |
|
44 | { | |
45 | dev->SSPDataReg = *c++; |
|
45 | ((_sspDev)dev)->SSPDataReg = *c++; | |
46 | while (((dev->SSPStatReg & (1<<4)))); |
|
46 | while (((((_sspDev)dev)->SSPStatReg & (1<<4)))); | |
47 | a=dev->SSPDataReg; |
|
47 | a=((_sspDev)dev)->SSPDataReg; | |
48 | } |
|
48 | } | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 |
char sspgetc(sspDev |
|
51 | char sspgetc(sspDev dev) { | |
52 | dev->SSPDataReg = 0xffff; |
|
52 | ((_sspDev)dev)->SSPDataReg = 0xffff; | |
53 | while ((dev->SSPStatReg & (0x10))); |
|
53 | while ((((_sspDev)dev)->SSPStatReg & (0x10))); | |
54 | return ((char)dev->SSPDataReg); |
|
54 | return ((char)((_sspDev)dev)->SSPDataReg); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 |
void sspgetnc(sspDev |
|
57 | void sspgetnc(sspDev dev,char *c,unsigned int n) | |
58 | { |
|
58 | { | |
59 | volatile char a; |
|
59 | volatile char a; | |
60 | while (((dev->SSPStatReg & (1<<2)))) a=dev->SSPDataReg; |
|
60 | while (((((_sspDev)dev)->SSPStatReg & (1<<2)))) a=((_sspDev)dev)->SSPDataReg; | |
61 | while(n) |
|
61 | while(n) | |
62 | { |
|
62 | { | |
63 | dev->SSPDataReg = 0xff; |
|
63 | ((_sspDev)dev)->SSPDataReg = 0xff; | |
64 | while (((dev->SSPStatReg & (1<<4)))); |
|
64 | while (((((_sspDev)dev)->SSPStatReg & (1<<4)))); | |
65 | *c= (char)dev->SSPDataReg; |
|
65 | *c= (char)((_sspDev)dev)->SSPDataReg; | |
66 | c++; |
|
66 | c++; | |
67 | n--; |
|
67 | n--; | |
68 | } |
|
68 | } | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 |
int sspgetw(sspDev |
|
71 | int sspgetw(sspDev dev) { | |
72 | int dummy; |
|
72 | int dummy; | |
73 | while(((dev->SSPStatReg & (1<<2)))) |
|
73 | while(((((_sspDev)dev)->SSPStatReg & (1<<2)))) | |
74 | dummy = dev->SSPDataReg; |
|
74 | dummy = ((_sspDev)dev)->SSPDataReg; | |
75 | dev->SSPDataReg = 0xFFFF; |
|
75 | ((_sspDev)dev)->SSPDataReg = 0xFFFF; | |
76 | while (((dev->SSPStatReg & (1<<4)))); |
|
76 | while (((((_sspDev)dev)->SSPStatReg & (1<<4)))); | |
77 | return (dev->SSPDataReg); |
|
77 | return (((_sspDev)dev)->SSPDataReg); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 |
|
80 | |||
81 |
void sspputs(sspDev |
|
81 | void sspputs(sspDev dev,char *s) { | |
82 | while (*s) sspputc(dev,*s++); |
|
82 | while (*s) sspputc(dev,*s++); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 |
|
85 | |||
86 |
void sspgets(sspDev |
|
86 | void sspgets(sspDev dev,char *s) { | |
87 | while (*s && (*s!=0xd)) *s++ = sspgetc(dev); |
|
87 | while (*s && (*s!=0xd)) *s++ = sspgetc(dev); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 |
void sspsetup(sspDev |
|
90 | void sspsetup(sspDev dev,unsigned char bitscount,int sspCtrlRegValue0,int sspCtrlRegValue1, unsigned int dataRate) | |
91 | { |
|
91 | { | |
92 | dev->SSPCtrlReg0 = sspCtrlRegValue0; |
|
92 | ((_sspDev)dev)->SSPCtrlReg0 = sspCtrlRegValue0; | |
93 | dev->SSPCtrlReg1 = sspCtrlRegValue1; |
|
93 | ((_sspDev)dev)->SSPCtrlReg1 = sspCtrlRegValue1; | |
94 | sspsetupTRsize(dev,bitscount); |
|
94 | sspsetupTRsize(dev,bitscount); | |
95 | sspsetdatarate(dev,dataRate); |
|
95 | sspsetdatarate(dev,dataRate); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 |
void sspsetupTRsize(sspDev |
|
98 | void sspsetupTRsize(sspDev dev,unsigned char value) | |
99 | { |
|
99 | { | |
100 | disableSSP(dev); |
|
100 | disableSSP(dev); | |
101 | if(value < 4)value =4; |
|
101 | if(value < 4)value =4; | |
102 | value--; |
|
102 | value--; | |
103 | dev->SSPCtrlReg0 |= value; |
|
103 | ((_sspDev)dev)->SSPCtrlReg0 |= value; | |
104 | dev->SSPCtrlReg0 &= 0xFFFFFFF0 | value; |
|
104 | ((_sspDev)dev)->SSPCtrlReg0 &= 0xFFFFFFF0 | value; | |
105 | enableSSP(dev); |
|
105 | enableSSP(dev); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 |
void enableSSP(sspDev |
|
108 | void enableSSP(sspDev dev) | |
109 | { |
|
109 | { | |
110 | dev->SSPCtrlReg1 |= 1<<1; |
|
110 | ((_sspDev)dev)->SSPCtrlReg1 |= 1<<1; | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 |
void disableSSP(sspDev |
|
113 | void disableSSP(sspDev dev) | |
114 | { |
|
114 | { | |
115 | dev->SSPCtrlReg1 &= -1 - (1<<1); |
|
115 | ((_sspDev)dev)->SSPCtrlReg1 &= -1 - (1<<1); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 |
void ssppowerup(sspDev |
|
118 | void ssppowerup(sspDev dev) | |
119 | { |
|
119 | { | |
120 | switch((int)dev) |
|
120 | switch((int)dev) | |
121 | { |
|
121 | { | |
@@ -130,7 +130,7 void ssppowerup(sspDev* dev) | |||||
130 | } |
|
130 | } | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 |
void ssppowerdown(sspDev |
|
133 | void ssppowerdown(sspDev dev) | |
134 | { |
|
134 | { | |
135 | switch((int)dev) |
|
135 | switch((int)dev) | |
136 | { |
|
136 | { | |
@@ -146,18 +146,18 void ssppowerdown(sspDev* dev) | |||||
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 |
|
148 | |||
149 |
sspDev |
|
149 | sspDev sspopen(int count){ | |
150 |
sspDev |
|
150 | sspDev dev; | |
151 | switch(count) |
|
151 | switch(count) | |
152 | { |
|
152 | { | |
153 | case 0: |
|
153 | case 0: | |
154 |
dev = (sspDev |
|
154 | dev = (sspDev)((unsigned long)LPC_SSP0_BASE); | |
155 | break; |
|
155 | break; | |
156 | case 1: |
|
156 | case 1: | |
157 |
dev = (sspDev |
|
157 | dev = (sspDev)((unsigned long)LPC_SSP1_BASE); | |
158 | break; |
|
158 | break; | |
159 | default: |
|
159 | default: | |
160 |
dev = (sspDev |
|
160 | dev = (sspDev)0; | |
161 | break; |
|
161 | break; | |
162 | } |
|
162 | } | |
163 | return dev; |
|
163 | return dev; | |
@@ -170,7 +170,7 sspDev* sspopen(int count){ | |||||
170 |
|
170 | |||
171 |
|
171 | |||
172 |
|
172 | |||
173 |
unsigned char sspgetpclkfactor(sspDev |
|
173 | unsigned char sspgetpclkfactor(sspDev dev) | |
174 | { |
|
174 | { | |
175 | unsigned int clksel=0; |
|
175 | unsigned int clksel=0; | |
176 | const char clkselDec[]={4,1,2,8}; |
|
176 | const char clkselDec[]={4,1,2,8}; | |
@@ -189,7 +189,7 unsigned char sspgetpclkfactor(sspDev* d | |||||
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 |
|
191 | |||
192 |
void sspsetpclkfactor(sspDev |
|
192 | void sspsetpclkfactor(sspDev dev,unsigned char pclkfactor) | |
193 | { |
|
193 | { | |
194 | const char clkselDec[]={1,1,2,2,0,0,0,0,3}; |
|
194 | const char clkselDec[]={1,1,2,2,0,0,0,0,3}; | |
195 | unsigned int clksel=0; |
|
195 | unsigned int clksel=0; | |
@@ -212,7 +212,7 void sspsetpclkfactor(sspDev* dev,unsign | |||||
212 |
|
212 | |||
213 |
|
213 | |||
214 |
|
214 | |||
215 |
void sspsetdatarate(sspDev |
|
215 | void sspsetdatarate(sspDev dev,unsigned int dataRate) | |
216 | { |
|
216 | { | |
217 | unsigned int pclk = 0; |
|
217 | unsigned int pclk = 0; | |
218 | unsigned int cpuclk=0; |
|
218 | unsigned int cpuclk=0; | |
@@ -234,7 +234,38 void sspsetdatarate(sspDev* dev,unsigned | |||||
234 | if(sspsclkl<2) sspsclkl = 2; |
|
234 | if(sspsclkl<2) sspsclkl = 2; | |
235 | } |
|
235 | } | |
236 | sspsclkl &= 0xFE; |
|
236 | sspsclkl &= 0xFE; | |
237 | dev->SSPClkPrescReg = sspsclkl; |
|
237 | ((_sspDev)dev)->SSPClkPrescReg = sspsclkl; | |
|
238 | } | |||
|
239 | ||||
|
240 | ||||
|
241 | ||||
|
242 | unsigned int sspgetdatarate(sspDev dev) | |||
|
243 | { | |||
|
244 | unsigned int dataRate; | |||
|
245 | unsigned int pclk = 0; | |||
|
246 | unsigned int cpuclk=0; | |||
|
247 | if(dev==0)return; | |||
|
248 | cpuclk = coregetCpuFreq(); | |||
|
249 | pclk = (cpuclk) / sspgetpclkfactor(dev); | |||
|
250 | dataRate = pclk/((_sspDev)dev)->SSPClkPrescReg; | |||
|
251 | return dataRate; | |||
238 | } |
|
252 | } | |
239 |
|
253 | |||
240 |
|
254 | |||
|
255 | ||||
|
256 | ||||
|
257 | ||||
|
258 | ||||
|
259 | ||||
|
260 | ||||
|
261 | ||||
|
262 | ||||
|
263 | ||||
|
264 | ||||
|
265 | ||||
|
266 | ||||
|
267 | ||||
|
268 | ||||
|
269 | ||||
|
270 | ||||
|
271 |
@@ -19,10 +19,13 | |||||
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@gmail.com |
|
20 | -- Mail : alexis.jeandet@gmail.com | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #include "LPC17xx.h" |
|
|||
23 | #ifndef SSP_H |
|
22 | #ifndef SSP_H | |
24 | #define SSP_H |
|
23 | #define SSP_H | |
25 |
|
24 | |||
|
25 | #include "LPC17xx.h" | |||
|
26 | #include <uhandle.h> | |||
|
27 | ||||
|
28 | ||||
26 | #define l4bits ((1<<1)+(1)) //0011 4 bit transfer |
|
29 | #define l4bits ((1<<1)+(1)) //0011 4 bit transfer | |
27 | #define l5bits ((1<<2)) //0100 5 bit transfer |
|
30 | #define l5bits ((1<<2)) //0100 5 bit transfer | |
28 | #define l6bits ((1<<2)+(1)) //0101 6 bit transfer |
|
31 | #define l6bits ((1<<2)+(1)) //0101 6 bit transfer | |
@@ -57,7 +60,7 | |||||
57 |
|
60 | |||
58 | #define SLAVEOUTPUTDISABLEMODE (1<<3) |
|
61 | #define SLAVEOUTPUTDISABLEMODE (1<<3) | |
59 |
|
62 | |||
60 | #define sspisslave(dev) ((((dev)->SSPCtrlReg1>>2) & 1)==1) |
|
63 | #define sspisslave(dev) ((((((_sspDev)dev))->SSPCtrlReg1>>2) & 1)==1) | |
61 |
|
64 | |||
62 | struct sspRegs |
|
65 | struct sspRegs | |
63 | { |
|
66 | { | |
@@ -73,24 +76,34 struct sspRegs | |||||
73 | unsigned long SSPDMACtrlReg; |
|
76 | unsigned long SSPDMACtrlReg; | |
74 | }; |
|
77 | }; | |
75 |
|
78 | |||
76 | typedef volatile struct sspRegs sspDev; |
|
79 | typedef volatile struct sspRegs* _sspDev; | |
|
80 | typedef UHANDLE sspDev; | |||
77 |
|
81 | |||
78 |
extern sspDev |
|
82 | extern sspDev sspopen(int count); | |
79 |
extern void sspputc(sspDev |
|
83 | extern void sspputc(sspDev dev,char c); | |
80 |
extern void sspputnc(sspDev |
|
84 | extern void sspputnc(sspDev dev,const char *c,unsigned int n); | |
81 |
extern void sspputw(sspDev |
|
85 | extern void sspputw(sspDev dev,int c); | |
82 |
extern void sspputs(sspDev |
|
86 | extern void sspputs(sspDev dev,char *s); | |
83 |
extern void sspgets(sspDev |
|
87 | extern void sspgets(sspDev dev,char *s); | |
84 |
extern char sspgetc(sspDev |
|
88 | extern char sspgetc(sspDev dev); | |
85 |
extern void sspgetnc(sspDev |
|
89 | extern void sspgetnc(sspDev dev,char *c,unsigned int n); | |
86 |
extern int sspgetw(sspDev |
|
90 | extern int sspgetw(sspDev dev); | |
87 |
extern void enableSSP(sspDev |
|
91 | extern void enableSSP(sspDev dev); | |
88 |
extern void disableSSP(sspDev |
|
92 | extern void disableSSP(sspDev dev); | |
89 |
extern void sspsetup(sspDev |
|
93 | extern void sspsetup(sspDev dev,unsigned char bitscount,int sspCtrlRegValue0,int sspCtrlRegValue1, unsigned int dataRate); | |
90 |
extern void sspsetupTRsize(sspDev |
|
94 | extern void sspsetupTRsize(sspDev dev,unsigned char value); | |
91 |
extern unsigned char sspgetpclkfactor(sspDev |
|
95 | extern unsigned char sspgetpclkfactor(sspDev dev); | |
92 |
extern void sspsetpclkfactor(sspDev |
|
96 | extern void sspsetpclkfactor(sspDev dev,unsigned char pclkfactor); | |
93 |
extern void sspsetdatarate(sspDev |
|
97 | extern void sspsetdatarate(sspDev dev,unsigned int dataRate); | |
|
98 | extern unsigned int sspgetdatarate(sspDev dev); | |||
94 |
|
99 | |||
95 | #endif |
|
100 | #endif | |
96 |
|
101 | |||
|
102 | ||||
|
103 | ||||
|
104 | ||||
|
105 | ||||
|
106 | ||||
|
107 | ||||
|
108 | ||||
|
109 |
@@ -4,7 +4,7 TARGET = libssp | |||||
4 | TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_SSP) |
|
4 | TARGETINSTALLPATH = $(LIBUC_LIBS_DIR_SSP) | |
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_SSP) |
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR_SSP) | |
6 |
|
6 | |||
7 | LIBS += CORE |
|
7 | LIBS += CORE UHANDLE | |
8 |
|
8 | |||
9 | SOURCES += ssp.c |
|
9 | SOURCES += ssp.c | |
10 |
|
10 |
@@ -5,12 +5,15 LIBUC = /opt/libuc2 | |||||
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/UART |
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/UART | |
6 | HEADERS += uart.h |
|
6 | HEADERS += uart.h | |
7 | LIBSOURCES += uart.c |
|
7 | LIBSOURCES += uart.c | |
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
8 | OBJECTFILES = $(LIBSOURCES:.c=.o) |
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
9 | ARCH = lpc17XX-arm-noabi-gcc |
|
12 | ARCH = lpc17XX-arm-noabi-gcc | |
10 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc |
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc17XX-arm-noabi-gcc | |
11 | TARGET=libuart |
|
14 | TARGET=libuart | |
12 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) |
|
15 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
13 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) |
|
16 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
14 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR)/UART |
|
17 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR)/UART | |
15 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR)/UART |
|
18 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR)/UART | |
16 | BSP=generic |
|
19 | BSP=generic | |
@@ -18,3 +21,10 include $(ARCHFOLDER)/rules.mk | |||||
18 |
|
21 | |||
19 | all:lib |
|
22 | all:lib | |
20 | @echo Code compiled |
|
23 | @echo Code compiled | |
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -23,23 +23,23 | |||||
23 | #include "uart.h" |
|
23 | #include "uart.h" | |
24 |
|
24 | |||
25 |
|
25 | |||
26 |
void uartputc(uartDev |
|
26 | void uartputc(uartDev dev,char c) { | |
27 | while (!((dev->LineStat & (1<<5)))); |
|
27 | while (!((((_uartDev)dev)->LineStat & (1<<5)))); | |
28 | dev->RWreg = c; |
|
28 | ((_uartDev)dev)->RWreg = c; | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 |
char uartgetc(uartDev |
|
31 | char uartgetc(uartDev dev) { | |
32 | while (!((dev->LineStat & 1))); |
|
32 | while (!((((_uartDev)dev)->LineStat & 1))); | |
33 | return (char)dev->RWreg; |
|
33 | return (char)((_uartDev)dev)->RWreg; | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 |
|
36 | |||
37 |
void uartputs(uartDev |
|
37 | void uartputs(uartDev dev,char *s) { | |
38 | while (*s) uartputc(dev,*s++); |
|
38 | while (*s) uartputc(dev,*s++); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 |
|
41 | |||
42 |
void uartgets(uartDev |
|
42 | void uartgets(uartDev dev,char *s) { | |
43 | while (*s && (*s!=0xd)) *s++ = uartgetc(dev); |
|
43 | while (*s && (*s!=0xd)) *s++ = uartgetc(dev); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
@@ -87,16 +87,16 void uarton(int count) | |||||
87 |
|
87 | |||
88 |
|
88 | |||
89 |
|
89 | |||
90 |
void uartsetup(uartDev |
|
90 | void uartsetup(uartDev dev,unsigned int baudRate,unsigned char WordLength,unsigned char StopBitCnt,unsigned char Parity) | |
91 | { |
|
91 | { | |
92 | if(WordLength>9)WordLength=8; |
|
92 | if(WordLength>9)WordLength=8; | |
93 | if((StopBitCnt>2)||(StopBitCnt==0))StopBitCnt=1; |
|
93 | if((StopBitCnt>2)||(StopBitCnt==0))StopBitCnt=1; | |
94 | if(Parity>7)Parity=0; |
|
94 | if(Parity>7)Parity=0; | |
95 | dev->LineCtrl = (WordLength-5) + ((StopBitCnt-1)<<2) + (Parity<<3); |
|
95 | ((_uartDev)dev)->LineCtrl = (WordLength-5) + ((StopBitCnt-1)<<2) + (Parity<<3); | |
96 | uartsetbaudrate(dev,baudRate); |
|
96 | uartsetbaudrate(dev,baudRate); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 |
unsigned char uartgetpclkfactor(uartDev |
|
99 | unsigned char uartgetpclkfactor(uartDev dev) | |
100 | { |
|
100 | { | |
101 | unsigned int clksel=0; |
|
101 | unsigned int clksel=0; | |
102 | const char clkselDec[]={4,1,2,8}; |
|
102 | const char clkselDec[]={4,1,2,8}; | |
@@ -120,7 +120,7 unsigned char uartgetpclkfactor(uartDev* | |||||
120 | return clkselDec[clksel]; |
|
120 | return clkselDec[clksel]; | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 |
void uartsetpclkfactor(uartDev |
|
123 | void uartsetpclkfactor(uartDev dev,unsigned char pclkfactor) | |
124 | { |
|
124 | { | |
125 | const char clkselDec[]={1,1,2,2,0,0,0,0,3}; |
|
125 | const char clkselDec[]={1,1,2,2,0,0,0,0,3}; | |
126 | unsigned int clksel=0; |
|
126 | unsigned int clksel=0; | |
@@ -147,7 +147,7 void uartsetpclkfactor(uartDev* dev,unsi | |||||
147 | } |
|
147 | } | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 |
void uartsetbaudrate(uartDev |
|
150 | void uartsetbaudrate(uartDev dev,unsigned int baudRate) | |
151 | { |
|
151 | { | |
152 | unsigned int pclk = 0; |
|
152 | unsigned int pclk = 0; | |
153 | unsigned int clksel=0; |
|
153 | unsigned int clksel=0; | |
@@ -162,29 +162,29 void uartsetbaudrate(uartDev* dev,unsign | |||||
162 | uartsetpclkfactor(dev,pclkfact/2); |
|
162 | uartsetpclkfactor(dev,pclkfact/2); | |
163 | pclk = cpuclk / uartgetpclkfactor(dev); |
|
163 | pclk = cpuclk / uartgetpclkfactor(dev); | |
164 | } |
|
164 | } | |
165 | dev->LineCtrl |= 128; |
|
165 | ((_uartDev)dev)->LineCtrl |= 128; | |
166 | dev->RWreg = pclk/(baudRate*16); |
|
166 | ((_uartDev)dev)->RWreg = pclk/(baudRate*16); | |
167 | dev->LineCtrl &= ~(128); |
|
167 | ((_uartDev)dev)->LineCtrl &= ~(128); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 |
uartDev |
|
170 | uartDev uartopen(int count){ | |
171 |
uartDev |
|
171 | uartDev dev; | |
172 | switch(count) |
|
172 | switch(count) | |
173 | { |
|
173 | { | |
174 | case 0: |
|
174 | case 0: | |
175 |
dev = (uartDev |
|
175 | dev = (uartDev)((unsigned long)LPC_UART0_BASE); | |
176 | break; |
|
176 | break; | |
177 | case 1: |
|
177 | case 1: | |
178 |
dev = (uartDev |
|
178 | dev = (uartDev)((unsigned long)LPC_UART1_BASE); | |
179 | break; |
|
179 | break; | |
180 | case 2: |
|
180 | case 2: | |
181 |
dev = (uartDev |
|
181 | dev = (uartDev)((unsigned long)LPC_UART2_BASE); | |
182 | break; |
|
182 | break; | |
183 | case 3: |
|
183 | case 3: | |
184 |
dev = (uartDev |
|
184 | dev = (uartDev)((unsigned long)LPC_UART3_BASE); | |
185 | break; |
|
185 | break; | |
186 | default: |
|
186 | default: | |
187 |
dev = (uartDev |
|
187 | dev = (uartDev)0; | |
188 | break; |
|
188 | break; | |
189 | } |
|
189 | } | |
190 | return dev; |
|
190 | return dev; |
@@ -21,7 +21,9 | |||||
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #ifndef UART_H |
|
22 | #ifndef UART_H | |
23 | #define UART_H |
|
23 | #define UART_H | |
|
24 | ||||
24 | #include "LPC17xx.h" |
|
25 | #include "LPC17xx.h" | |
|
26 | #include <uhandle.h> | |||
25 |
|
27 | |||
26 |
|
28 | |||
27 | #define uartNoParity 0 |
|
29 | #define uartNoParity 0 | |
@@ -41,19 +43,20 struct LPC17XXuartRegs | |||||
41 | unsigned long ScratchPad; |
|
43 | unsigned long ScratchPad; | |
42 | }; |
|
44 | }; | |
43 |
|
45 | |||
44 | typedef volatile struct LPC17XXuartRegs uartDev; |
|
46 | typedef volatile struct LPC17XXuartRegs* _uartDev; | |
|
47 | typedef UHANDLE uartDev; | |||
45 |
|
48 | |||
46 |
extern uartDev |
|
49 | extern uartDev uartopen(int count); | |
47 | extern void uarton(int count); |
|
50 | extern void uarton(int count); | |
48 | extern void uartoff(int count); |
|
51 | extern void uartoff(int count); | |
49 |
extern void uartputc(uartDev |
|
52 | extern void uartputc(uartDev dev,char c); | |
50 |
extern void uartputs(uartDev |
|
53 | extern void uartputs(uartDev dev,char *s); | |
51 |
extern void uartgets(uartDev |
|
54 | extern void uartgets(uartDev dev,char *s); | |
52 |
extern char uartgetc(uartDev |
|
55 | extern char uartgetc(uartDev dev); | |
53 |
extern void uartsetbaudrate(uartDev |
|
56 | extern void uartsetbaudrate(uartDev dev,unsigned int baudRate); | |
54 |
extern unsigned char uartgetpclkfactor(uartDev |
|
57 | extern unsigned char uartgetpclkfactor(uartDev dev); | |
55 |
extern void uartsetpclkfactor(uartDev |
|
58 | extern void uartsetpclkfactor(uartDev dev,unsigned char pclkfactor); | |
56 |
extern void uartsetup(uartDev |
|
59 | extern void uartsetup(uartDev dev,unsigned int baudRate,unsigned char WordLength,unsigned char StopBitCnt,unsigned char Parity); | |
57 |
|
60 | |||
58 | #endif |
|
61 | #endif | |
59 |
|
62 |
@@ -4,7 +4,7 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 += CORE |
|
7 | LIBS += CORE UHANDLE | |
8 |
|
8 | |||
9 | SOURCES += uart.c |
|
9 | SOURCES += uart.c | |
10 |
|
10 |
@@ -5,7 +5,10 LIBUC = /opt/libuc2 | |||||
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/CORE |
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/CORE | |
6 | HEADERS += core.h |
|
6 | HEADERS += core.h | |
7 | LIBSOURCES += core.c |
|
7 | LIBSOURCES += core.c | |
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
8 | OBJECTFILES = $(LIBSOURCES:.c=.o) |
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
9 | ARCH = lpc21XX-arm-noabi-gcc |
|
12 | ARCH = lpc21XX-arm-noabi-gcc | |
10 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc |
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |
11 | TARGET=libcore |
|
14 | TARGET=libcore | |
@@ -18,3 +21,10 include $(ARCHFOLDER)/rules.mk | |||||
18 |
|
21 | |||
19 | all:lib |
|
22 | all:lib | |
20 | @echo Code compiled |
|
23 | @echo Code compiled | |
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -6,10 +6,14 include $(LIBUC)/rules/common/rules.mk | |||||
6 | all:subdir |
|
6 | all:subdir | |
7 | make -C CORE |
|
7 | make -C CORE | |
8 | make -C UART |
|
8 | make -C UART | |
|
9 | make -C IIC | |||
|
10 | make -C SSP | |||
9 | @echo Code compiled |
|
11 | @echo Code compiled | |
10 |
|
12 | |||
11 | clean: |
|
13 | clean: | |
12 | make clean -C CORE |
|
14 | make clean -C CORE | |
13 | make clean -C UART |
|
15 | make clean -C UART | |
|
16 | make clean -C IIC | |||
|
17 | make clean -C SSP | |||
14 | @echo Code compiled |
|
18 | @echo Code compiled | |
15 |
|
19 |
@@ -5,12 +5,15 LIBUC = /opt/libuc2 | |||||
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/UART |
|
5 | HEADERSINSTALLPATH = $(LIBUC_INC_DIR)/UART | |
6 | HEADERS += uart.h |
|
6 | HEADERS += uart.h | |
7 | LIBSOURCES += uart.c |
|
7 | LIBSOURCES += uart.c | |
|
8 | OBJDIR = obj | |||
|
9 | BINDIR = bin | |||
8 | OBJECTFILES = $(LIBSOURCES:.c=.o) |
|
10 | OBJECTFILES = $(LIBSOURCES:.c=.o) | |
|
11 | OBJECTFILES := $(addprefix $(OBJDIR)/,$(OBJECTFILES)) | |||
9 | ARCH = lpc21XX-arm-noabi-gcc |
|
12 | ARCH = lpc21XX-arm-noabi-gcc | |
10 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc |
|
13 | ARCHFOLDER = $(LIBUC)/rules/lpc21XX-arm-noabi-gcc | |
11 | TARGET=libuart |
|
14 | TARGET=libuart | |
12 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) |
|
15 | LIBUC_INCLUDES=$(LIBUC_INC_DIR_CORE_CMD) $(LIBUC_INC_DIR_UHANDLE_CMD) | |
13 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) |
|
16 | LIBUC_LIBRARIES=$(LIBUC_LIBS_DIR_CORE_CMD) $(LIBUC_LIBS_CORE) $(LIBUC_LIBS_DIR_UHANDLE_CMD) $(LIBUC_LIBS_UHANDLE) | |
14 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR)/UART |
|
17 | TARGETINSTALLPATH=$(LIBUC_LIBS_DIR)/UART | |
15 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR)/UART |
|
18 | HEADERSINSTALLPATH=$(LIBUC_INC_DIR)/UART | |
16 | BSP=generic |
|
19 | BSP=generic | |
@@ -18,3 +21,10 include $(ARCHFOLDER)/rules.mk | |||||
18 |
|
21 | |||
19 | all:lib |
|
22 | all:lib | |
20 | @echo Code compiled |
|
23 | @echo Code compiled | |
|
24 | ||||
|
25 | clean: | |||
|
26 | rm -f $(OBJDIR)/*.o | |||
|
27 | rm -f $(TARGETINSTALLPATH)/*.a | |||
|
28 | rm -f $(HEADERSINSTALLPATH)/*.h | |||
|
29 | rm -f $(DEVSOURCESND) | |||
|
30 | rm -f *.d |
@@ -23,23 +23,23 | |||||
23 | #include "uart.h" |
|
23 | #include "uart.h" | |
24 |
|
24 | |||
25 |
|
25 | |||
26 |
void uartputc(uartDev |
|
26 | void uartputc(uartDev dev,char c) { | |
27 | while (!((dev->LineStat & (1<<5)))); |
|
27 | while (!((((_uartDev)dev)->LineStat & (1<<5)))); | |
28 | dev->RWreg = c; |
|
28 | ((_uartDev)dev)->RWreg = c; | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 |
char uartgetc(uartDev |
|
31 | char uartgetc(uartDev dev) { | |
32 | while (!((dev->LineStat & 1))); |
|
32 | while (!((((_uartDev)dev)->LineStat & 1))); | |
33 | return (char)dev->RWreg; |
|
33 | return (char)((_uartDev)dev)->RWreg; | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 |
|
36 | |||
37 |
void uartputs(uartDev |
|
37 | void uartputs(uartDev dev,char *s) { | |
38 | while (*s) uartputc(dev,*s++); |
|
38 | while (*s) uartputc(dev,*s++); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 |
|
41 | |||
42 |
void uartgets(uartDev |
|
42 | void uartgets(uartDev dev,char *s) { | |
43 | while (*s && (*s!=0xd)) *s++ = uartgetc(dev); |
|
43 | while (*s && (*s!=0xd)) *s++ = uartgetc(dev); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
@@ -87,16 +87,16 void uarton(int count) | |||||
87 |
|
87 | |||
88 |
|
88 | |||
89 |
|
89 | |||
90 |
void uartsetup(uartDev |
|
90 | void uartsetup(uartDev dev,unsigned int baudRate,unsigned char WordLength,unsigned char StopBitCnt,unsigned char Parity) | |
91 | { |
|
91 | { | |
92 | if(WordLength>9)WordLength=8; |
|
92 | if(WordLength>9)WordLength=8; | |
93 | if((StopBitCnt>2)||(StopBitCnt==0))StopBitCnt=1; |
|
93 | if((StopBitCnt>2)||(StopBitCnt==0))StopBitCnt=1; | |
94 | if(Parity>7)Parity=0; |
|
94 | if(Parity>7)Parity=0; | |
95 | dev->LineCtrl = (WordLength-5) + ((StopBitCnt-1)<<2) + (Parity<<3); |
|
95 | ((_uartDev)dev)->LineCtrl = (WordLength-5) + ((StopBitCnt-1)<<2) + (Parity<<3); | |
96 | uartsetbaudrate(dev,baudRate); |
|
96 | uartsetbaudrate(dev,baudRate); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 |
unsigned char uartgetpclkfactor(uartDev |
|
99 | unsigned char uartgetpclkfactor(uartDev dev) | |
100 | { |
|
100 | { | |
101 | unsigned int clksel=0; |
|
101 | unsigned int clksel=0; | |
102 | const char clkselDec[]={4,1,2,8}; |
|
102 | const char clkselDec[]={4,1,2,8}; | |
@@ -120,7 +120,7 unsigned char uartgetpclkfactor(uartDev* | |||||
120 | return clkselDec[clksel]; |
|
120 | return clkselDec[clksel]; | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 |
void uartsetpclkfactor(uartDev |
|
123 | void uartsetpclkfactor(uartDev dev,unsigned char pclkfactor) | |
124 | { |
|
124 | { | |
125 | const char clkselDec[]={1,1,2,2,0,0,0,0,3}; |
|
125 | const char clkselDec[]={1,1,2,2,0,0,0,0,3}; | |
126 | unsigned int clksel=0; |
|
126 | unsigned int clksel=0; | |
@@ -147,7 +147,7 void uartsetpclkfactor(uartDev* dev,unsi | |||||
147 | } |
|
147 | } | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 |
void uartsetbaudrate(uartDev |
|
150 | void uartsetbaudrate(uartDev dev,unsigned int baudRate) | |
151 | { |
|
151 | { | |
152 | unsigned int pclk = 0; |
|
152 | unsigned int pclk = 0; | |
153 | unsigned int clksel=0; |
|
153 | unsigned int clksel=0; | |
@@ -162,30 +162,37 void uartsetbaudrate(uartDev* dev,unsign | |||||
162 | uartsetpclkfactor(dev,pclkfact/2); |
|
162 | uartsetpclkfactor(dev,pclkfact/2); | |
163 | pclk = cpuclk / uartgetpclkfactor(dev); |
|
163 | pclk = cpuclk / uartgetpclkfactor(dev); | |
164 | } |
|
164 | } | |
165 | dev->LineCtrl |= 128; |
|
165 | ((_uartDev)dev)->LineCtrl |= 128; | |
166 | dev->RWreg = pclk/(baudRate*16); |
|
166 | ((_uartDev)dev)->RWreg = pclk/(baudRate*16); | |
167 | dev->LineCtrl &= ~(128); |
|
167 | ((_uartDev)dev)->LineCtrl &= ~(128); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 |
uartDev |
|
170 | uartDev uartopen(int count){ | |
171 |
uartDev |
|
171 | uartDev dev; | |
172 | switch(count) |
|
172 | switch(count) | |
173 | { |
|
173 | { | |
174 | case 0: |
|
174 | case 0: | |
175 |
dev = (uartDev |
|
175 | dev = (uartDev)((unsigned long)UART0_BASE_ADDR); | |
176 | break; |
|
176 | break; | |
177 | case 1: |
|
177 | case 1: | |
178 |
dev = (uartDev |
|
178 | dev = (uartDev)((unsigned long)UART1_BASE_ADDR); | |
179 | break; |
|
179 | break; | |
180 | case 2: |
|
180 | case 2: | |
181 |
dev = (uartDev |
|
181 | dev = (uartDev)((unsigned long)UART2_BASE_ADDR); | |
182 | break; |
|
182 | break; | |
183 | case 3: |
|
183 | case 3: | |
184 |
dev = (uartDev |
|
184 | dev = (uartDev)((unsigned long)UART3_BASE_ADDR); | |
185 | break; |
|
185 | break; | |
186 | default: |
|
186 | default: | |
187 |
dev = (uartDev |
|
187 | dev = (uartDev)0; | |
188 | break; |
|
188 | break; | |
189 | } |
|
189 | } | |
190 | return dev; |
|
190 | return dev; | |
191 | } |
|
191 | } | |
|
192 | ||||
|
193 | ||||
|
194 | ||||
|
195 | ||||
|
196 | ||||
|
197 | ||||
|
198 |
@@ -21,7 +21,9 | |||||
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #ifndef UART_H |
|
22 | #ifndef UART_H | |
23 | #define UART_H |
|
23 | #define UART_H | |
|
24 | ||||
24 | #include "LPC23xx.h" |
|
25 | #include "LPC23xx.h" | |
|
26 | #include <uhandle.h> | |||
25 |
|
27 | |||
26 |
|
28 | |||
27 | #define uartNoParity 0 |
|
29 | #define uartNoParity 0 | |
@@ -30,7 +32,7 | |||||
30 | #define uartTrueParity 5 |
|
32 | #define uartTrueParity 5 | |
31 | #define uartFalseParity 7 |
|
33 | #define uartFalseParity 7 | |
32 |
|
34 | |||
33 | struct uartRegs |
|
35 | struct LPC17XXuartRegs | |
34 | { |
|
36 | { | |
35 | unsigned long RWreg; |
|
37 | unsigned long RWreg; | |
36 | unsigned long IntEN; |
|
38 | unsigned long IntEN; | |
@@ -41,19 +43,20 struct uartRegs | |||||
41 | unsigned long ScratchPad; |
|
43 | unsigned long ScratchPad; | |
42 | }; |
|
44 | }; | |
43 |
|
45 | |||
44 | typedef volatile struct uartRegs uartDev; |
|
46 | typedef volatile struct LPC17XXuartRegs* _uartDev; | |
|
47 | typedef UHANDLE uartDev; | |||
45 |
|
48 | |||
46 |
extern uartDev |
|
49 | extern uartDev uartopen(int count); | |
47 | extern void uarton(int count); |
|
50 | extern void uarton(int count); | |
48 | extern void uartoff(int count); |
|
51 | extern void uartoff(int count); | |
49 |
extern void uartputc(uartDev |
|
52 | extern void uartputc(uartDev dev,char c); | |
50 |
extern void uartputs(uartDev |
|
53 | extern void uartputs(uartDev dev,char *s); | |
51 |
extern void uartgets(uartDev |
|
54 | extern void uartgets(uartDev dev,char *s); | |
52 |
extern char uartgetc(uartDev |
|
55 | extern char uartgetc(uartDev dev); | |
53 |
extern void uartsetbaudrate(uartDev |
|
56 | extern void uartsetbaudrate(uartDev dev,unsigned int baudRate); | |
54 |
extern unsigned char uartgetpclkfactor(uartDev |
|
57 | extern unsigned char uartgetpclkfactor(uartDev dev); | |
55 |
extern void uartsetpclkfactor(uartDev |
|
58 | extern void uartsetpclkfactor(uartDev dev,unsigned char pclkfactor); | |
56 |
extern void uartsetup(uartDev |
|
59 | extern void uartsetup(uartDev dev,unsigned int baudRate,unsigned char WordLength,unsigned char StopBitCnt,unsigned char Parity); | |
57 |
|
60 | |||
58 | #endif |
|
61 | #endif | |
59 |
|
62 |
@@ -4,7 +4,7 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 += CORE |
|
7 | LIBS += CORE UHANDLE | |
8 |
|
8 | |||
9 | SOURCES += uart.c |
|
9 | SOURCES += uart.c | |
10 |
|
10 |
@@ -1,3 +1,5 | |||||
1 | TEMPLATE = dir |
|
1 | TEMPLATE = dir | |
2 | SUBDIRS += CORE \ |
|
2 | SUBDIRS += CORE \ | |
3 | UART |
|
3 | UART \ | |
|
4 | IIC \ | |||
|
5 | SSP |
@@ -21,7 +21,7 MEMORY | |||||
21 |
|
21 | |||
22 | /* AHB SRAM - 16k for LPC1756 - often used for USB */ |
|
22 | /* AHB SRAM - 16k for LPC1756 - often used for USB */ | |
23 | IRAM1 (rwx) : ORIGIN = 0x2007C000, LENGTH = 16k |
|
23 | IRAM1 (rwx) : ORIGIN = 0x2007C000, LENGTH = 16k | |
24 |
|
|
24 | IRAM2 (rwx) : ORIGIN = 0x20080000, LENGTH = 16k | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | /* SECTION command : Define mapping of input sections */ |
|
27 | /* SECTION command : Define mapping of input sections */ |
@@ -72,68 +72,9 LIBUC_CXXFLAGS_HARD_FPU = | |||||
72 | # LIBRARY DEFINITIONS |
|
72 | # LIBRARY DEFINITIONS | |
73 | #--------------------------------------------------------------------------------- |
|
73 | #--------------------------------------------------------------------------------- | |
74 |
|
74 | |||
75 | LIBUC_LIBS = |
|
|||
76 | LIBUC_LIBS_CORE = -static -lcore |
|
|||
77 | LIBUC_LIBS_UCSTRINGS = -static -lucstrings |
|
|||
78 | LIBUC_LIBS_UART = -static -luart |
|
|||
79 | LIBUC_LIBS_SPI = -static -lspi |
|
|||
80 | LIBUC_LIBS_SSP = -static -lssp |
|
|||
81 | LIBUC_LIBS_IIC = -static -liic |
|
|||
82 | LIBUC_LIBS_ADC = -static -ladc |
|
|||
83 | LIBUC_LIBS_24LC0X = -static -l24lc0X |
|
|||
84 | LIBUC_LIBS_SDCARD = -static -lsdcard |
|
|||
85 | LIBUC_LIBS_BLKDEVICE = -static -lblkdevice |
|
|||
86 | LIBUC_LIBS_VS10XX = -static -lvs10XX |
|
|||
87 |
|
||||
88 | LIBUC_LIBS_DIR = $(LIBUC)/lib/bin/lpc17XX |
|
75 | LIBUC_LIBS_DIR = $(LIBUC)/lib/bin/lpc17XX | |
89 | LIBUC_LIBS_DIR_CORE = $(LIBUC_LIBS_DIR)/CORE |
|
|||
90 | LIBUC_LIBS_DIR_UCSTRINGS = $(LIBUC_LIBS_DIR)/STRINGS/$(ARCH) |
|
|||
91 | LIBUC_LIBS_DIR_UART = $(LIBUC_LIBS_DIR)/UART |
|
|||
92 | LIBUC_LIBS_DIR_SPI = $(LIBUC_LIBS_DIR)/SPI |
|
|||
93 | LIBUC_LIBS_DIR_SSP = $(LIBUC_LIBS_DIR)/SSP |
|
|||
94 | LIBUC_LIBS_DIR_IIC = $(LIBUC_LIBS_DIR)/IIC |
|
|||
95 | LIBUC_LIBS_DIR_ADC = $(LIBUC_LIBS_DIR)/ADC |
|
|||
96 | LIBUC_LIBS_DIR_24LC0X = $(LIBUC_LIBS_DIR)/24LCXX/24LC0X |
|
|||
97 | LIBUC_LIBS_DIR_SDCARD = $(LIBUC_LIBS_DIR)/SDCARD |
|
|||
98 | LIBUC_LIBS_DIR_VS10XX = $(LIBUC_LIBS_DIR)/VS10XX |
|
|||
99 | LIBUC_LIBS_DIR_BLKDEVICE = $(LIBUC_LIBS_DIR)/BLKDEVICE |
|
|||
100 |
|
||||
101 | LIBUC_LIBS_DIR_CORE_CMD = -L $(LIBUC_LIBS_DIR_CORE) |
|
|||
102 | LIBUC_LIBS_DIR_UCSTRINGS_CMD = -L $(LIBUC_LIBS_DIR_UCSTRINGS) |
|
|||
103 | LIBUC_LIBS_DIR_UART_CMD = -L $(LIBUC_LIBS_DIR_UART) |
|
|||
104 | LIBUC_LIBS_DIR_SPI_CMD = -L $(LIBUC_LIBS_DIR_SPI) |
|
|||
105 | LIBUC_LIBS_DIR_SSP_CMD = -L $(LIBUC_LIBS_DIR_SSP) |
|
|||
106 | LIBUC_LIBS_DIR_IIC_CMD = -L $(LIBUC_LIBS_DIR_IIC) |
|
|||
107 | LIBUC_LIBS_DIR_ADC_CMD = -L $(LIBUC_LIBS_DIR_ADC) |
|
|||
108 | LIBUC_LIBS_DIR_24LC0X_CMD = -L $(LIBUC_LIBS_DIR_24LC0X) |
|
|||
109 | LIBUC_LIBS_DIR_SDCARD_CMD = -L $(LIBUC_LIBS_DIR_SDCARD) |
|
|||
110 | LIBUC_LIBS_DIR_VS10XX_CMD = -L $(LIBUC_LIBS_DIR_VS10XX) |
|
|||
111 | LIBUC_LIBS_DIR_BLKDEVICE_CMD = -L $(LIBUC_LIBS_DIR_BLKDEVICE) |
|
|||
112 |
|
||||
113 | LIBUC_INC_DIR = $(LIBUC)/lib/includes/lpc17XX |
|
76 | LIBUC_INC_DIR = $(LIBUC)/lib/includes/lpc17XX | |
114 | LIBUC_INC_DIR_CORE = $(LIBUC_INC_DIR)/CORE |
|
77 | include $(LIBUC)/rules/common/libsrules.mk | |
115 | LIBUC_INC_DIR_UCSTRINGS = $(LIBUC_INC_DIR)/STRINGS/$(ARCH) |
|
|||
116 | LIBUC_INC_DIR_UART = $(LIBUC_INC_DIR)/UART |
|
|||
117 | LIBUC_INC_DIR_SPI = $(LIBUC_INC_DIR)/SPI |
|
|||
118 | LIBUC_INC_DIR_SSP = $(LIBUC_INC_DIR)/SSP |
|
|||
119 | LIBUC_INC_DIR_IIC = $(LIBUC_INC_DIR)/IIC |
|
|||
120 | LIBUC_INC_DIR_ADC = $(LIBUC_INC_DIR)/ADC |
|
|||
121 | LIBUC_INC_DIR_24LC0X = $(LIBUC_INC_DIR)/24LCXX/24LC0X |
|
|||
122 | LIBUC_INC_DIR_SDCARD = $(LIBUC_INC_DIR)/SDCARD |
|
|||
123 | LIBUC_INC_DIR_VS10XX = $(LIBUC_INC_DIR)/VS10XX |
|
|||
124 | LIBUC_INC_DIR_BLKDEVICE = $(LIBUC_INC_DIR)/BLKDEVICE |
|
|||
125 |
|
||||
126 | LIBUC_INC_DIR_CORE_CMD = -I $(LIBUC_INC_DIR_CORE) |
|
|||
127 | LIBUC_INC_DIR_UCSTRINGS_CMD = -I $(LIBUC_INC_DIR_UCSTRINGS) |
|
|||
128 | LIBUC_INC_DIR_UART_CMD = -I $(LIBUC_INC_DIR_UART) |
|
|||
129 | LIBUC_INC_DIR_SPI_CMD = -I $(LIBUC_INC_DIR_SPI) |
|
|||
130 | LIBUC_INC_DIR_SSP_CMD = -I $(LIBUC_INC_DIR_SSP) |
|
|||
131 | LIBUC_INC_DIR_IIC_CMD = -I $(LIBUC_INC_DIR_IIC) |
|
|||
132 | LIBUC_INC_DIR_ADC_CMD = -I $(LIBUC_INC_DIR_ADC) |
|
|||
133 | LIBUC_INC_DIR_24LC0X_CMD = -I $(LIBUC_INC_DIR_24LC0X) |
|
|||
134 | LIBUC_INC_DIR_SDCARD_CMD = -I $(LIBUC_INC_DIR_SDCARD) |
|
|||
135 | LIBUC_INC_DIR_VS10XX_CMD = -I $(LIBUC_INC_DIR_VS10XX) |
|
|||
136 | LIBUC_INC_DIR_BLKDEVICE_CMD = -I $(LIBUC_INC_DIR_BLKDEVICE) |
|
|||
137 |
|
78 | |||
138 | #--------------------------------------------------------------------------------- |
|
79 | #--------------------------------------------------------------------------------- | |
139 | # BOARD SUPORT PACKAGES |
|
80 | # BOARD SUPORT PACKAGES | |
@@ -147,7 +88,11 LIBUC_BSP_INC = -I $(LIBUC_BSP_INC_DIR)/ | |||||
147 | # DEVICE SPECIAL FILES |
|
88 | # DEVICE SPECIAL FILES | |
148 | #--------------------------------------------------------------------------------- |
|
89 | #--------------------------------------------------------------------------------- | |
149 | LINKER_SCRIPT = $(ARCHFOLDER)/LPC17xx.ld |
|
90 | LINKER_SCRIPT = $(ARCHFOLDER)/LPC17xx.ld | |
150 |
|
|
91 | DEVSOURCES += $(ARCHFOLDER)/startup_LPC17xx.c $(ARCHFOLDER)/core_cm3.c $(ARCHFOLDER)/system_LPC17xx.c | |
|
92 | DEVSOURCESND = $(notdir $(DEVSOURCES)) | |||
|
93 | DEVOBJECTFILES += $(DEVSOURCESND:.c=.o) | |||
|
94 | DEVOBJECTFILES := $(addprefix $(OBJDIR)/,$(DEVOBJECTFILES)) | |||
|
95 | OBJECTFILES += $(DEVOBJECTFILES) | |||
151 | LPC17XX_INCDIR=$(ARCHFOLDER) |
|
96 | LPC17XX_INCDIR=$(ARCHFOLDER) | |
152 |
|
97 | |||
153 |
|
98 | |||
@@ -159,34 +104,43 all: | |||||
159 | @echo "lpc17XX-arm-noabi-gcc rules" |
|
104 | @echo "lpc17XX-arm-noabi-gcc rules" | |
160 |
|
105 | |||
161 |
|
106 | |||
162 | bin: $(TARGET).bin $(TARGET).hex |
|
107 | bin: $(DEVSOURCESND) $(BINDIR)/$(TARGET).bin $(BINDIR)/$(TARGET).hex | |
163 | @echo "compile bin" |
|
108 | @echo "compile bin" | |
164 |
|
109 | |||
165 |
|
110 | $(DEVSOURCESND): $(DEVSOURCES) | ||
|
111 | cp $(DEVSOURCES) ./ | |||
166 |
|
112 | |||
167 | lib: $(TARGET).a |
|
113 | lib: $(TARGETINSTALLPATH)/$(TARGET).a | |
168 | @echo "compile lib" |
|
114 | @echo "compile lib" | |
169 |
|
115 | |||
170 | %.a: $(OBJECTFILES) |
|
116 | %.a: $(OBJECTFILES) | |
171 | mkdir -p $(TARGETINSTALLPATH) |
|
117 | mkdir -p $(TARGETINSTALLPATH) | |
172 | mkdir -p $(HEADERSINSTALLPATH) |
|
118 | mkdir -p $(HEADERSINSTALLPATH) | |
173 |
$(LIBUC_AR) rcs |
|
119 | $(LIBUC_AR) rcs $@ $(OBJECTFILES) #$(LIBUC_AR) rcs $(TARGETINSTALLPATH)/$@ $(OBJECTFILES) | |
174 | cp -f $(HEADERS) $(HEADERSINSTALLPATH)/ |
|
120 | cp -f $(HEADERS) $(HEADERSINSTALLPATH)/ | |
175 |
|
121 | |||
176 |
|
122 | |||
177 | %.o: %.c |
|
123 | #%.o: %.c | |
|
124 | # $(LIBUC_CC) -O3 -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -MM $< -MF $*.d -MP | |||
|
125 | # $(LIBUC_CC) -O3 -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -c $(LIBUC_CFLAGS) $< -o $@ | |||
|
126 | ||||
|
127 | $(OBJECTFILES) : $(OBJDIR)/%.o : %.c $(INC_LIBS_DEPS) $(HEADERS) | |||
|
128 | mkdir -p $(OBJDIR) | |||
178 |
|
|
129 | $(LIBUC_CC) -O3 -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -MM $< -MF $*.d -MP | |
179 | $(LIBUC_CC) -O3 -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 $@ | |
180 |
|
131 | |||
181 |
|
132 | |||
182 | %.elf: $(LINKER_SCRIPT) $(OBJECTFILES) |
|
133 | %.elf: $(LINKER_SCRIPT) $(OBJECTFILES) | |
|
134 | mkdir -p $(BINDIR) | |||
183 |
|
|
135 | $(LIBUC_LD) -Map $(@:.elf=.map) $(LIBUC_LDFLAGS) -T $^ -o $@ $(LIBUC_BSP) $(LIBUC_LIBRARIES) | |
184 | $(LIBUC_OBJDUMP) $(LIBUC_ODFLAGS) $@ > $(@:.elf=.dump) |
|
136 | $(LIBUC_OBJDUMP) $(LIBUC_ODFLAGS) $@ > $(@:.elf=.dump) | |
185 | $(LIBUC_SIZE) $@ |
|
137 | $(LIBUC_SIZE) $@ | |
186 |
|
138 | |||
187 | %.bin: %.elf |
|
139 | ||
|
140 | %.bin: %.elf $(BIN_LIBS_DEPS) | |||
188 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O binary $< $*.bin |
|
141 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O binary $< $*.bin | |
189 |
|
142 | @echo "BIN_LIBS_DEPS" | ||
|
143 | @echo $(BIN_LIBS_DEPS) | |||
190 |
|
144 | |||
191 | %.hex: %.elf |
|
145 | %.hex: %.elf | |
192 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O ihex $< $*.hex |
|
146 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O ihex $< $*.hex | |
@@ -194,6 +148,13 lib: $(TARGET).a | |||||
194 |
|
148 | |||
195 | clean: |
|
149 | clean: | |
196 | rm -f *.o *.d *.bin *.hex *.dump *.map *.a |
|
150 | rm -f *.o *.d *.bin *.hex *.dump *.map *.a | |
|
151 | rm -f $(OBJECTFILES) | |||
|
152 | rm -f $(BINDIR)/*.bin | |||
|
153 | rm -f $(BINDIR)/*.hex | |||
|
154 | rm -f $(BINDIR)/*.dump | |||
|
155 | rm -f $(BINDIR)/*.map | |||
|
156 | rm -f $(BINDIR)/*.a | |||
|
157 | rm -f $(DEVSOURCESND) | |||
197 |
|
158 | |||
198 | distclean: |
|
159 | distclean: | |
199 | rm -f $(TARGETINSTALLPATH)/*.bin |
|
160 | rm -f $(TARGETINSTALLPATH)/*.bin |
@@ -110,8 +110,8 extern int main(void); | |||||
110 | * 0x0000.0000. |
|
110 | * 0x0000.0000. | |
111 | * |
|
111 | * | |
112 | ******************************************************************************/ |
|
112 | ******************************************************************************/ | |
113 |
#define STACK_SIZE 0x00000 |
|
113 | #define STACK_SIZE 0x00000800 /*2kO*/ | |
114 |
|
114 | |||
115 | __attribute__ ((section(".stackarea"))) |
|
115 | __attribute__ ((section(".stackarea"))) | |
116 | /* static */ unsigned long pulStack[STACK_SIZE]; |
|
116 | /* static */ unsigned long pulStack[STACK_SIZE]; | |
117 |
|
117 |
@@ -42,9 +42,9 LIBUC_OBJDUMP=$(LIBUC_PREFIX)objdump | |||||
42 | #--------------------------------------------------------------------------------- |
|
42 | #--------------------------------------------------------------------------------- | |
43 | LIBUC_FMCU = -mcpu=arm7tdmi |
|
43 | LIBUC_FMCU = -mcpu=arm7tdmi | |
44 | LIBUC_CFLAGS = $(LIBUC_FMCU) |
|
44 | LIBUC_CFLAGS = $(LIBUC_FMCU) | |
45 |
LIBUC_CFLAGS = -g -gdwarf-2 |
|
45 | LIBUC_CFLAGS += -g -gdwarf-2 -fomit-frame-pointer | |
46 | LIBUC_CFLAGS += -Wall -Wextra -Wundef -Wcast-align |
|
46 | LIBUC_CFLAGS += -Wall -Wextra -Wundef -Wcast-align -DROM_RUN | |
47 |
LIBUC_LDFLAGS = - |
|
47 | LIBUC_LDFLAGS = -nostartfiles | |
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 | |
@@ -68,72 +68,14 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 | ||||
71 | #--------------------------------------------------------------------------------- |
|
72 | #--------------------------------------------------------------------------------- | |
72 | # LIBRARY DEFINITIONS |
|
73 | # LIBRARY DEFINITIONS | |
73 | #--------------------------------------------------------------------------------- |
|
74 | #--------------------------------------------------------------------------------- | |
74 |
|
||||
75 | LIBUC_LIBS = |
|
|||
76 | LIBUC_LIBS_CORE = -static -lcore |
|
|||
77 | LIBUC_LIBS_UCSTRINGS = -static -lucstrings |
|
|||
78 | LIBUC_LIBS_UART = -static -luart |
|
|||
79 | LIBUC_LIBS_SPI = -static -lspi |
|
|||
80 | LIBUC_LIBS_SSP = -static -lssp |
|
|||
81 | LIBUC_LIBS_IIC = -static -liic |
|
|||
82 | LIBUC_LIBS_ADC = -static -ladc |
|
|||
83 | LIBUC_LIBS_24LC0X = -static -l24lc0X |
|
|||
84 | LIBUC_LIBS_SDCARD = -static -lsdcard |
|
|||
85 | LIBUC_LIBS_BLKDEVICE = -static -lblkdevice |
|
|||
86 | LIBUC_LIBS_VS10XX = -static -lvs10XX |
|
|||
87 |
|
||||
88 | LIBUC_LIBS_DIR = $(LIBUC)/lib/bin/lpc21XX |
|
75 | LIBUC_LIBS_DIR = $(LIBUC)/lib/bin/lpc21XX | |
89 | LIBUC_LIBS_DIR_CORE = $(LIBUC_LIBS_DIR)/CORE |
|
76 | LIBUC_INC_DIR = $(LIBUC)/lib/includes/lpc21XX | |
90 | LIBUC_LIBS_DIR_UCSTRINGS = $(LIBUC_LIBS_DIR)/STRINGS/$(ARCH) |
|
77 | include $(LIBUC)/rules/common/libsrules.mk | |
91 | LIBUC_LIBS_DIR_UART = $(LIBUC_LIBS_DIR)/UART |
|
|||
92 | LIBUC_LIBS_DIR_SPI = $(LIBUC_LIBS_DIR)/SPI |
|
|||
93 | LIBUC_LIBS_DIR_SSP = $(LIBUC_LIBS_DIR)/SSP |
|
|||
94 | LIBUC_LIBS_DIR_IIC = $(LIBUC_LIBS_DIR)/IIC |
|
|||
95 | LIBUC_LIBS_DIR_ADC = $(LIBUC_LIBS_DIR)/ADC |
|
|||
96 | LIBUC_LIBS_DIR_24LC0X = $(LIBUC_LIBS_DIR)/24LCXX/24LC0X |
|
|||
97 | LIBUC_LIBS_DIR_SDCARD = $(LIBUC_LIBS_DIR)/SDCARD |
|
|||
98 | LIBUC_LIBS_DIR_VS10XX = $(LIBUC_LIBS_DIR)/VS10XX |
|
|||
99 | LIBUC_LIBS_DIR_BLKDEVICE = $(LIBUC_LIBS_DIR)/BLKDEVICE |
|
|||
100 |
|
78 | |||
101 | LIBUC_LIBS_DIR_CORE_CMD = -L $(LIBUC_LIBS_DIR_CORE) |
|
|||
102 | LIBUC_LIBS_DIR_UCSTRINGS_CMD = -L $(LIBUC_LIBS_DIR_UCSTRINGS) |
|
|||
103 | LIBUC_LIBS_DIR_UART_CMD = -L $(LIBUC_LIBS_DIR_UART) |
|
|||
104 | LIBUC_LIBS_DIR_SPI_CMD = -L $(LIBUC_LIBS_DIR_SPI) |
|
|||
105 | LIBUC_LIBS_DIR_SSP_CMD = -L $(LIBUC_LIBS_DIR_SSP) |
|
|||
106 | LIBUC_LIBS_DIR_IIC_CMD = -L $(LIBUC_LIBS_DIR_IIC) |
|
|||
107 | LIBUC_LIBS_DIR_ADC_CMD = -L $(LIBUC_LIBS_DIR_ADC) |
|
|||
108 | LIBUC_LIBS_DIR_24LC0X_CMD = -L $(LIBUC_LIBS_DIR_24LC0X) |
|
|||
109 | LIBUC_LIBS_DIR_SDCARD_CMD = -L $(LIBUC_LIBS_DIR_SDCARD) |
|
|||
110 | LIBUC_LIBS_DIR_VS10XX_CMD = -L $(LIBUC_LIBS_DIR_VS10XX) |
|
|||
111 | LIBUC_LIBS_DIR_BLKDEVICE_CMD = -L $(LIBUC_LIBS_DIR_BLKDEVICE) |
|
|||
112 |
|
||||
113 | LIBUC_INC_DIR = $(LIBUC)/lib/includes/lpc21XX |
|
|||
114 | LIBUC_INC_DIR_CORE = $(LIBUC_INC_DIR)/CORE |
|
|||
115 | LIBUC_INC_DIR_UCSTRINGS = $(LIBUC_INC_DIR)/STRINGS/$(ARCH) |
|
|||
116 | LIBUC_INC_DIR_UART = $(LIBUC_INC_DIR)/UART |
|
|||
117 | LIBUC_INC_DIR_SPI = $(LIBUC_INC_DIR)/SPI |
|
|||
118 | LIBUC_INC_DIR_SSP = $(LIBUC_INC_DIR)/SSP |
|
|||
119 | LIBUC_INC_DIR_IIC = $(LIBUC_INC_DIR)/IIC |
|
|||
120 | LIBUC_INC_DIR_ADC = $(LIBUC_INC_DIR)/ADC |
|
|||
121 | LIBUC_INC_DIR_24LC0X = $(LIBUC_INC_DIR)/24LCXX/24LC0X |
|
|||
122 | LIBUC_INC_DIR_SDCARD = $(LIBUC_INC_DIR)/SDCARD |
|
|||
123 | LIBUC_INC_DIR_VS10XX = $(LIBUC_INC_DIR)/VS10XX |
|
|||
124 | LIBUC_INC_DIR_BLKDEVICE = $(LIBUC_INC_DIR)/BLKDEVICE |
|
|||
125 |
|
||||
126 | LIBUC_INC_DIR_CORE_CMD = -I $(LIBUC_INC_DIR_CORE) |
|
|||
127 | LIBUC_INC_DIR_UCSTRINGS_CMD = -I $(LIBUC_INC_DIR_UCSTRINGS) |
|
|||
128 | LIBUC_INC_DIR_UART_CMD = -I $(LIBUC_INC_DIR_UART) |
|
|||
129 | LIBUC_INC_DIR_SPI_CMD = -I $(LIBUC_INC_DIR_SPI) |
|
|||
130 | LIBUC_INC_DIR_SSP_CMD = -I $(LIBUC_INC_DIR_SSP) |
|
|||
131 | LIBUC_INC_DIR_IIC_CMD = -I $(LIBUC_INC_DIR_IIC) |
|
|||
132 | LIBUC_INC_DIR_ADC_CMD = -I $(LIBUC_INC_DIR_ADC) |
|
|||
133 | LIBUC_INC_DIR_24LC0X_CMD = -I $(LIBUC_INC_DIR_24LC0X) |
|
|||
134 | LIBUC_INC_DIR_SDCARD_CMD = -I $(LIBUC_INC_DIR_SDCARD) |
|
|||
135 | LIBUC_INC_DIR_VS10XX_CMD = -I $(LIBUC_INC_DIR_VS10XX) |
|
|||
136 | LIBUC_INC_DIR_BLKDEVICE_CMD = -I $(LIBUC_INC_DIR_BLKDEVICE) |
|
|||
137 |
|
|
79 | ||
138 | #--------------------------------------------------------------------------------- |
|
80 | #--------------------------------------------------------------------------------- | |
139 | # BOARD SUPORT PACKAGES |
|
81 | # BOARD SUPORT PACKAGES | |
@@ -146,9 +88,23 LIBUC_BSP_INC = -I $(LIBUC_BSP_INC_DIR)/ | |||||
146 | #--------------------------------------------------------------------------------- |
|
88 | #--------------------------------------------------------------------------------- | |
147 | # DEVICE SPECIAL FILES |
|
89 | # DEVICE SPECIAL FILES | |
148 | #--------------------------------------------------------------------------------- |
|
90 | #--------------------------------------------------------------------------------- | |
149 |
LINKER_SCRIPT = $(ARCHFOLDER)/LPC2 |
|
91 | LINKER_SCRIPT = $(ARCHFOLDER)/LPC2378-ROM.ld | |
150 | APPSOURCES += $(ARCHFOLDER)/ramstartup-1.S |
|
92 | DEVSOURCES += | |
151 | LPC21XX_INCDIR=$(ARCHFOLDER) |
|
93 | DEVSOURCESND = $(notdir $(DEVSOURCES)) | |
|
94 | DEVOBJECTFILES += $(DEVSOURCESND:.c=.o) | |||
|
95 | DEVOBJECTFILES := $(addprefix $(OBJDIR)/,$(DEVOBJECTFILES)) | |||
|
96 | OBJECTFILES += $(DEVOBJECTFILES) | |||
|
97 | ||||
|
98 | ASMDEVSOURCES += $(ARCHFOLDER)/crt0.S | |||
|
99 | ASMDEVSOURCESND = $(notdir $(ASMDEVSOURCES)) | |||
|
100 | ASMDEVOBJECTFILES += $(ASMDEVSOURCESND:.S=.o) | |||
|
101 | ASMDEVOBJECTFILES := $(addprefix $(OBJDIR)/,$(ASMDEVOBJECTFILES)) | |||
|
102 | ASMOBJECTFILES += $(ASMDEVOBJECTFILES) | |||
|
103 | ||||
|
104 | #RUN_MODE=ROM_RUN | |||
|
105 | #LIBUC_CFLAGS += -D$(RUN_MODE) | |||
|
106 | ||||
|
107 | LPC23XX_INCDIR=$(ARCHFOLDER) | |||
152 |
|
108 | |||
153 |
|
109 | |||
154 | #--------------------------------------------------------------------------------- |
|
110 | #--------------------------------------------------------------------------------- | |
@@ -156,39 +112,56 LPC21XX_INCDIR=$(ARCHFOLDER) | |||||
156 | #--------------------------------------------------------------------------------- |
|
112 | #--------------------------------------------------------------------------------- | |
157 |
|
113 | |||
158 | all: |
|
114 | all: | |
159 |
@echo "lpc2 |
|
115 | @echo "lpc23XX-arm-noabi-gcc rules" | |
160 |
|
116 | |||
161 |
|
117 | |||
162 | bin: $(TARGET).bin $(TARGET).hex |
|
118 | bin: $(ASMDEVSOURCESND) $(DEVSOURCESND) $(BINDIR)/$(TARGET).bin $(BINDIR)/$(TARGET).hex | |
163 | @echo "compile bin" |
|
119 | @echo "compile bin" | |
164 |
|
120 | |||
165 |
|
121 | $(DEVSOURCESND): $(DEVSOURCES) | ||
|
122 | cp -f $(DEVSOURCES) ./ | |||
|
123 | ||||
|
124 | $(ASMDEVSOURCESND): $(ASMDEVSOURCES) | |||
|
125 | cp -f $(ASMDEVSOURCES) ./ | |||
166 |
|
126 | |||
167 | lib: $(TARGET).a |
|
127 | lib: $(TARGETINSTALLPATH)/$(TARGET).a | |
168 | @echo "compile lib" |
|
128 | @echo "compile lib" | |
169 |
|
129 | |||
170 | %.a: $(OBJECTFILES) |
|
130 | %.a: $(OBJECTFILES) | |
171 | mkdir -p $(TARGETINSTALLPATH) |
|
131 | mkdir -p $(TARGETINSTALLPATH) | |
172 | mkdir -p $(HEADERSINSTALLPATH) |
|
132 | mkdir -p $(HEADERSINSTALLPATH) | |
173 |
$(LIBUC_AR) rcs |
|
133 | $(LIBUC_AR) rcs $@ $(OBJECTFILES) #$(LIBUC_AR) rcs $(TARGETINSTALLPATH)/$@ $(OBJECTFILES) | |
174 | cp -f $(HEADERS) $(HEADERSINSTALLPATH)/ |
|
134 | cp -f $(HEADERS) $(HEADERSINSTALLPATH)/ | |
175 |
|
135 | |||
176 | %.o: %.S |
|
136 | ||
177 | $(LIBUC_CC) -O3 -c -o $@ $< $(LIBUC_CFLAGS) |
|
137 | #%.o: %.c | |
|
138 | # $(LIBUC_CC) -O3 -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -MM $< -MF $*.d -MP | |||
|
139 | # $(LIBUC_CC) -O3 -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -c $(LIBUC_CFLAGS) $< -o $@ | |||
178 |
|
140 | |||
179 | %.o: %.c |
|
141 | $(OBJECTFILES) : $(OBJDIR)/%.o : %.c $(INC_LIBS_DEPS) $(HEADERS) | |
180 | $(LIBUC_CC) -O3 -I $(LPC21XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -MM $< -MF $*.d -MP |
|
142 | mkdir -p $(OBJDIR) | |
181 |
$(LIBUC_CC) -O3 -I $(LPC2 |
|
143 | $(LIBUC_CC) -O3 -I $(LPC23XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -MM $< -MF $*.d -MP | |
|
144 | $(LIBUC_CC) -O3 -I $(LPC23XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -c $(LIBUC_CFLAGS) $< -o $@ | |||
|
145 | ||||
182 |
|
146 | |||
183 |
|
147 | |||
184 | %.elf: $(LINKER_SCRIPT) $(OBJECTFILES) |
|
148 | $(ASMOBJECTFILES) : $(OBJDIR)/%.o : %.S $(INC_LIBS_DEPS) $(HEADERS) | |
185 | $(LIBUC_CC) -O3 -nostartfiles -T $^ -o $@ -static $(LIBUC_BSP) $(LIBUC_LIBRARIES) |
|
149 | mkdir -p $(OBJDIR) | |
|
150 | $(LIBUC_CC) -O3 -I $(LPC23XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -c $(LIBUC_CFLAGS) $< -o $@ | |||
|
151 | ||||
|
152 | ||||
|
153 | %.elf: $(LINKER_SCRIPT) $(ASMOBJECTFILES) $(OBJECTFILES) | |||
|
154 | mkdir -p $(BINDIR) | |||
|
155 | $(LIBUC_CC) $(LIBUC_LDFLAGS) $(LIBUC_CFLAGS) -T $^ -o $@ $(LIBUC_BSP) $(LIBUC_LIBRARIES) | |||
186 | $(LIBUC_OBJDUMP) $(LIBUC_ODFLAGS) $@ > $(@:.elf=.dump) |
|
156 | $(LIBUC_OBJDUMP) $(LIBUC_ODFLAGS) $@ > $(@:.elf=.dump) | |
187 | $(LIBUC_SIZE) $@ |
|
157 | $(LIBUC_SIZE) $@ | |
188 |
|
158 | |||
189 | %.bin: %.elf |
|
159 | ||
|
160 | ||||
|
161 | %.bin: %.elf $(BIN_LIBS_DEPS) | |||
190 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O binary $< $*.bin |
|
162 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O binary $< $*.bin | |
191 |
|
163 | @echo "BIN_LIBS_DEPS" | ||
|
164 | @echo $(BIN_LIBS_DEPS) | |||
192 |
|
165 | |||
193 | %.hex: %.elf |
|
166 | %.hex: %.elf | |
194 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O ihex $< $*.hex |
|
167 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O ihex $< $*.hex | |
@@ -196,6 +169,13 lib: $(TARGET).a | |||||
196 |
|
169 | |||
197 | clean: |
|
170 | clean: | |
198 | rm -f *.o *.d *.bin *.hex *.dump *.map *.a |
|
171 | rm -f *.o *.d *.bin *.hex *.dump *.map *.a | |
|
172 | rm -f $(OBJECTFILES) | |||
|
173 | rm -f $(BINDIR)/*.bin | |||
|
174 | rm -f $(BINDIR)/*.hex | |||
|
175 | rm -f $(BINDIR)/*.dump | |||
|
176 | rm -f $(BINDIR)/*.map | |||
|
177 | rm -f $(BINDIR)/*.a | |||
|
178 | rm -f $(DEVSOURCESND) | |||
199 |
|
179 | |||
200 | distclean: |
|
180 | distclean: | |
201 | rm -f $(TARGETINSTALLPATH)/*.bin |
|
181 | rm -f $(TARGETINSTALLPATH)/*.bin | |
@@ -209,3 +189,10 distclean: | |||||
209 |
|
189 | |||
210 |
|
190 | |||
211 |
|
191 | |||
|
192 | ||||
|
193 | ||||
|
194 | ||||
|
195 | ||||
|
196 | ||||
|
197 | ||||
|
198 |
General Comments 0
You need to be logged in to leave comments.
Login now