@@ -0,0 +1,219 | |||
|
1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
|
2 | <?fileVersion 4.0.0?> | |
|
3 | ||
|
4 | <cproject> | |
|
5 | <storageModule moduleId="org.eclipse.cdt.core.settings"> | |
|
6 | <cconfiguration id="cdt.managedbuild.config.gnu.exe.release.1568263498"> | |
|
7 | <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.1568263498" moduleId="org.eclipse.cdt.core.settings" name="Release"> | |
|
8 | <externalSettings/> | |
|
9 | <extensions> | |
|
10 | <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> | |
|
11 | <extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |
|
12 | <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |
|
13 | <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |
|
14 | <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |
|
15 | </extensions> | |
|
16 | </storageModule> | |
|
17 | <storageModule moduleId="cdtBuildSystem" version="4.0.0"> | |
|
18 | <configuration artifactName="Control_Module" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.1568263498" name="Release" parent="cdt.managedbuild.config.gnu.exe.release"> | |
|
19 | <folderInfo id="cdt.managedbuild.config.gnu.exe.release.1568263498." name="/" resourcePath=""> | |
|
20 | <toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.785297601" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release"> | |
|
21 | <targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.release.1008424557" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/> | |
|
22 | <builder buildPath="${workspace_loc:/Control_Module/Release}" id="cdt.managedbuild.target.gnu.builder.exe.release.365458410" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.release"/> | |
|
23 | <tool id="cdt.managedbuild.tool.gnu.archiver.base.1343949145" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/> | |
|
24 | <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.57926565" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release"> | |
|
25 | <option id="gnu.cpp.compiler.exe.release.option.optimization.level.35312113" name="Optimization Level" superClass="gnu.cpp.compiler.exe.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/> | |
|
26 | <option id="gnu.cpp.compiler.exe.release.option.debugging.level.936269591" name="Debug Level" superClass="gnu.cpp.compiler.exe.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/> | |
|
27 | </tool> | |
|
28 | <tool command="arm-unknown-linux-gnu-gcc" id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.1796829929" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.release"> | |
|
29 | <option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.exe.release.option.optimization.level.499243164" name="Optimization Level" superClass="gnu.c.compiler.exe.release.option.optimization.level" valueType="enumerated"/> | |
|
30 | <option id="gnu.c.compiler.exe.release.option.debugging.level.1960011250" name="Debug Level" superClass="gnu.c.compiler.exe.release.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/> | |
|
31 | <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1347535566" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> | |
|
32 | </tool> | |
|
33 | <tool command="arm-unknown-linux-gnu-gcc" id="cdt.managedbuild.tool.gnu.c.linker.exe.release.1288648685" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release"> | |
|
34 | <inputType id="cdt.managedbuild.tool.gnu.c.linker.input.2046701530" superClass="cdt.managedbuild.tool.gnu.c.linker.input"> | |
|
35 | <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> | |
|
36 | <additionalInput kind="additionalinput" paths="$(LIBS)"/> | |
|
37 | </inputType> | |
|
38 | </tool> | |
|
39 | <tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.release.1068281678" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.release"/> | |
|
40 | <tool id="cdt.managedbuild.tool.gnu.assembler.exe.release.796779267" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.release"> | |
|
41 | <inputType id="cdt.managedbuild.tool.gnu.assembler.input.690094510" superClass="cdt.managedbuild.tool.gnu.assembler.input"/> | |
|
42 | </tool> | |
|
43 | </toolChain> | |
|
44 | </folderInfo> | |
|
45 | </configuration> | |
|
46 | </storageModule> | |
|
47 | <storageModule moduleId="scannerConfiguration"> | |
|
48 | <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/> | |
|
49 | <profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"> | |
|
50 | <buildOutputProvider> | |
|
51 | <openAction enabled="true" filePath=""/> | |
|
52 | <parser enabled="true"/> | |
|
53 | </buildOutputProvider> | |
|
54 | <scannerInfoProvider id="specsFile"> | |
|
55 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> | |
|
56 | <parser enabled="true"/> | |
|
57 | </scannerInfoProvider> | |
|
58 | </profile> | |
|
59 | <profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"> | |
|
60 | <buildOutputProvider> | |
|
61 | <openAction enabled="true" filePath=""/> | |
|
62 | <parser enabled="true"/> | |
|
63 | </buildOutputProvider> | |
|
64 | <scannerInfoProvider id="makefileGenerator"> | |
|
65 | <runAction arguments="-f ${project_name}_scd.mk" command="make" useDefault="true"/> | |
|
66 | <parser enabled="true"/> | |
|
67 | </scannerInfoProvider> | |
|
68 | </profile> | |
|
69 | <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile"> | |
|
70 | <buildOutputProvider> | |
|
71 | <openAction enabled="true" filePath=""/> | |
|
72 | <parser enabled="true"/> | |
|
73 | </buildOutputProvider> | |
|
74 | <scannerInfoProvider id="specsFile"> | |
|
75 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> | |
|
76 | <parser enabled="true"/> | |
|
77 | </scannerInfoProvider> | |
|
78 | </profile> | |
|
79 | <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"> | |
|
80 | <buildOutputProvider> | |
|
81 | <openAction enabled="true" filePath=""/> | |
|
82 | <parser enabled="true"/> | |
|
83 | </buildOutputProvider> | |
|
84 | <scannerInfoProvider id="specsFile"> | |
|
85 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.cpp" command="g++" useDefault="true"/> | |
|
86 | <parser enabled="true"/> | |
|
87 | </scannerInfoProvider> | |
|
88 | </profile> | |
|
89 | <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"> | |
|
90 | <buildOutputProvider> | |
|
91 | <openAction enabled="true" filePath=""/> | |
|
92 | <parser enabled="true"/> | |
|
93 | </buildOutputProvider> | |
|
94 | <scannerInfoProvider id="specsFile"> | |
|
95 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.c" command="gcc" useDefault="true"/> | |
|
96 | <parser enabled="true"/> | |
|
97 | </scannerInfoProvider> | |
|
98 | </profile> | |
|
99 | <profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile"> | |
|
100 | <buildOutputProvider> | |
|
101 | <openAction enabled="true" filePath=""/> | |
|
102 | <parser enabled="true"/> | |
|
103 | </buildOutputProvider> | |
|
104 | <scannerInfoProvider id="specsFile"> | |
|
105 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> | |
|
106 | <parser enabled="true"/> | |
|
107 | </scannerInfoProvider> | |
|
108 | </profile> | |
|
109 | <profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP"> | |
|
110 | <buildOutputProvider> | |
|
111 | <openAction enabled="true" filePath=""/> | |
|
112 | <parser enabled="true"/> | |
|
113 | </buildOutputProvider> | |
|
114 | <scannerInfoProvider id="specsFile"> | |
|
115 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.cpp" command="g++" useDefault="true"/> | |
|
116 | <parser enabled="true"/> | |
|
117 | </scannerInfoProvider> | |
|
118 | </profile> | |
|
119 | <profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC"> | |
|
120 | <buildOutputProvider> | |
|
121 | <openAction enabled="true" filePath=""/> | |
|
122 | <parser enabled="true"/> | |
|
123 | </buildOutputProvider> | |
|
124 | <scannerInfoProvider id="specsFile"> | |
|
125 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.c" command="gcc" useDefault="true"/> | |
|
126 | <parser enabled="true"/> | |
|
127 | </scannerInfoProvider> | |
|
128 | </profile> | |
|
129 | <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1568263498;cdt.managedbuild.config.gnu.exe.release.1568263498.;cdt.managedbuild.tool.gnu.c.compiler.exe.release.1796829929;cdt.managedbuild.tool.gnu.c.compiler.input.1347535566"> | |
|
130 | <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/> | |
|
131 | <profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"> | |
|
132 | <buildOutputProvider> | |
|
133 | <openAction enabled="true" filePath=""/> | |
|
134 | <parser enabled="true"/> | |
|
135 | </buildOutputProvider> | |
|
136 | <scannerInfoProvider id="specsFile"> | |
|
137 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> | |
|
138 | <parser enabled="true"/> | |
|
139 | </scannerInfoProvider> | |
|
140 | </profile> | |
|
141 | <profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"> | |
|
142 | <buildOutputProvider> | |
|
143 | <openAction enabled="true" filePath=""/> | |
|
144 | <parser enabled="true"/> | |
|
145 | </buildOutputProvider> | |
|
146 | <scannerInfoProvider id="makefileGenerator"> | |
|
147 | <runAction arguments="-f ${project_name}_scd.mk" command="make" useDefault="true"/> | |
|
148 | <parser enabled="true"/> | |
|
149 | </scannerInfoProvider> | |
|
150 | </profile> | |
|
151 | <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile"> | |
|
152 | <buildOutputProvider> | |
|
153 | <openAction enabled="true" filePath=""/> | |
|
154 | <parser enabled="true"/> | |
|
155 | </buildOutputProvider> | |
|
156 | <scannerInfoProvider id="specsFile"> | |
|
157 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> | |
|
158 | <parser enabled="true"/> | |
|
159 | </scannerInfoProvider> | |
|
160 | </profile> | |
|
161 | <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"> | |
|
162 | <buildOutputProvider> | |
|
163 | <openAction enabled="true" filePath=""/> | |
|
164 | <parser enabled="true"/> | |
|
165 | </buildOutputProvider> | |
|
166 | <scannerInfoProvider id="specsFile"> | |
|
167 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.cpp" command="g++" useDefault="true"/> | |
|
168 | <parser enabled="true"/> | |
|
169 | </scannerInfoProvider> | |
|
170 | </profile> | |
|
171 | <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"> | |
|
172 | <buildOutputProvider> | |
|
173 | <openAction enabled="true" filePath=""/> | |
|
174 | <parser enabled="true"/> | |
|
175 | </buildOutputProvider> | |
|
176 | <scannerInfoProvider id="specsFile"> | |
|
177 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.c" command="gcc" useDefault="true"/> | |
|
178 | <parser enabled="true"/> | |
|
179 | </scannerInfoProvider> | |
|
180 | </profile> | |
|
181 | <profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile"> | |
|
182 | <buildOutputProvider> | |
|
183 | <openAction enabled="true" filePath=""/> | |
|
184 | <parser enabled="true"/> | |
|
185 | </buildOutputProvider> | |
|
186 | <scannerInfoProvider id="specsFile"> | |
|
187 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> | |
|
188 | <parser enabled="true"/> | |
|
189 | </scannerInfoProvider> | |
|
190 | </profile> | |
|
191 | <profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP"> | |
|
192 | <buildOutputProvider> | |
|
193 | <openAction enabled="true" filePath=""/> | |
|
194 | <parser enabled="true"/> | |
|
195 | </buildOutputProvider> | |
|
196 | <scannerInfoProvider id="specsFile"> | |
|
197 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.cpp" command="g++" useDefault="true"/> | |
|
198 | <parser enabled="true"/> | |
|
199 | </scannerInfoProvider> | |
|
200 | </profile> | |
|
201 | <profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC"> | |
|
202 | <buildOutputProvider> | |
|
203 | <openAction enabled="true" filePath=""/> | |
|
204 | <parser enabled="true"/> | |
|
205 | </buildOutputProvider> | |
|
206 | <scannerInfoProvider id="specsFile"> | |
|
207 | <runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.c" command="gcc" useDefault="true"/> | |
|
208 | <parser enabled="true"/> | |
|
209 | </scannerInfoProvider> | |
|
210 | </profile> | |
|
211 | </scannerConfigBuildInfo> | |
|
212 | </storageModule> | |
|
213 | <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> | |
|
214 | </cconfiguration> | |
|
215 | </storageModule> | |
|
216 | <storageModule moduleId="cdtBuildSystem" version="4.0.0"> | |
|
217 | <project id="Control_Module.cdt.managedbuild.target.gnu.exe.1941602615" name="Executable" projectType="cdt.managedbuild.target.gnu.exe"/> | |
|
218 | </storageModule> | |
|
219 | </cproject> |
@@ -0,0 +1,81 | |||
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
|
2 | <projectDescription> | |
|
3 | <name>Control_Module</name> | |
|
4 | <comment></comment> | |
|
5 | <projects> | |
|
6 | </projects> | |
|
7 | <buildSpec> | |
|
8 | <buildCommand> | |
|
9 | <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> | |
|
10 | <triggers>clean,full,incremental,</triggers> | |
|
11 | <arguments> | |
|
12 | <dictionary> | |
|
13 | <key>?name?</key> | |
|
14 | <value></value> | |
|
15 | </dictionary> | |
|
16 | <dictionary> | |
|
17 | <key>org.eclipse.cdt.make.core.append_environment</key> | |
|
18 | <value>true</value> | |
|
19 | </dictionary> | |
|
20 | <dictionary> | |
|
21 | <key>org.eclipse.cdt.make.core.autoBuildTarget</key> | |
|
22 | <value>all</value> | |
|
23 | </dictionary> | |
|
24 | <dictionary> | |
|
25 | <key>org.eclipse.cdt.make.core.buildArguments</key> | |
|
26 | <value></value> | |
|
27 | </dictionary> | |
|
28 | <dictionary> | |
|
29 | <key>org.eclipse.cdt.make.core.buildCommand</key> | |
|
30 | <value>make</value> | |
|
31 | </dictionary> | |
|
32 | <dictionary> | |
|
33 | <key>org.eclipse.cdt.make.core.buildLocation</key> | |
|
34 | <value>${workspace_loc:/Control_Module/Release}</value> | |
|
35 | </dictionary> | |
|
36 | <dictionary> | |
|
37 | <key>org.eclipse.cdt.make.core.cleanBuildTarget</key> | |
|
38 | <value>clean</value> | |
|
39 | </dictionary> | |
|
40 | <dictionary> | |
|
41 | <key>org.eclipse.cdt.make.core.contents</key> | |
|
42 | <value>org.eclipse.cdt.make.core.activeConfigSettings</value> | |
|
43 | </dictionary> | |
|
44 | <dictionary> | |
|
45 | <key>org.eclipse.cdt.make.core.enableAutoBuild</key> | |
|
46 | <value>false</value> | |
|
47 | </dictionary> | |
|
48 | <dictionary> | |
|
49 | <key>org.eclipse.cdt.make.core.enableCleanBuild</key> | |
|
50 | <value>true</value> | |
|
51 | </dictionary> | |
|
52 | <dictionary> | |
|
53 | <key>org.eclipse.cdt.make.core.enableFullBuild</key> | |
|
54 | <value>true</value> | |
|
55 | </dictionary> | |
|
56 | <dictionary> | |
|
57 | <key>org.eclipse.cdt.make.core.fullBuildTarget</key> | |
|
58 | <value>all</value> | |
|
59 | </dictionary> | |
|
60 | <dictionary> | |
|
61 | <key>org.eclipse.cdt.make.core.stopOnError</key> | |
|
62 | <value>true</value> | |
|
63 | </dictionary> | |
|
64 | <dictionary> | |
|
65 | <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key> | |
|
66 | <value>true</value> | |
|
67 | </dictionary> | |
|
68 | </arguments> | |
|
69 | </buildCommand> | |
|
70 | <buildCommand> | |
|
71 | <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name> | |
|
72 | <arguments> | |
|
73 | </arguments> | |
|
74 | </buildCommand> | |
|
75 | </buildSpec> | |
|
76 | <natures> | |
|
77 | <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> | |
|
78 | <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> | |
|
79 | <nature>org.eclipse.cdt.core.cnature</nature> | |
|
80 | </natures> | |
|
81 | </projectDescription> |
@@ -0,0 +1,102 | |||
|
1 | /* | |
|
2 | * This programmer uses AT91' GPIO lines | |
|
3 | * | |
|
4 | * 2006 by Carlos Camargo | |
|
5 | * 2007.May.10 Andres Calderon | |
|
6 | * 2009.Aug.26 Jose Francisco Quenta | |
|
7 | */ | |
|
8 | ||
|
9 | #include <stdint.h> | |
|
10 | #include <stdlib.h> | |
|
11 | #include <stdio.h> | |
|
12 | #include <unistd.h> | |
|
13 | ||
|
14 | ||
|
15 | #include <sys/types.h> | |
|
16 | #include <sys/stat.h> | |
|
17 | #include <sys/mman.h> | |
|
18 | #include <fcntl.h> | |
|
19 | ||
|
20 | #include "./Librerias/AT91gpio_Funciones.h" | |
|
21 | ||
|
22 | void pio_out(AT91S_PIO * pio, int mask, unsigned long val, int opcion) | |
|
23 | { | |
|
24 | if (opcion == 1) | |
|
25 | pio->PIO_SODR = mask & val; | |
|
26 | else | |
|
27 | pio->PIO_CODR = mask & val; | |
|
28 | } | |
|
29 | ||
|
30 | ||
|
31 | int pio_in(AT91S_PIO * pio, int mask) | |
|
32 | { | |
|
33 | return (pio->PIO_PDSR & mask); | |
|
34 | } | |
|
35 | ||
|
36 | ||
|
37 | AT91S_PIO *pio_map(unsigned int piobase) | |
|
38 | { | |
|
39 | int fd; | |
|
40 | void *base; | |
|
41 | ||
|
42 | AT91S_PIO *pio; | |
|
43 | ||
|
44 | off_t addr = piobase; | |
|
45 | ||
|
46 | if ((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) { | |
|
47 | fprintf(stderr, "Cannot open /dev/mem.\n"); | |
|
48 | exit(EXIT_FAILURE); | |
|
49 | } | |
|
50 | ||
|
51 | fprintf(stderr, "/dev/mem opened.\n"); | |
|
52 | ||
|
53 | base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, addr & ~MAP_MASK); | |
|
54 | ||
|
55 | if (base == (void *) -1) { | |
|
56 | fprintf(stderr, "Cannot open /dev/mem.\n"); | |
|
57 | exit(EXIT_FAILURE); | |
|
58 | } | |
|
59 | ||
|
60 | fprintf(stderr, "Memory mapped at address %p.\n", base); | |
|
61 | ||
|
62 | pio = base + (addr & MAP_MASK); | |
|
63 | ||
|
64 | return pio; | |
|
65 | } | |
|
66 | ||
|
67 | ||
|
68 | void pio_enable(AT91S_PIO * pio, int mask) | |
|
69 | { | |
|
70 | pio->PIO_PER = mask; /* Enable PIO */ | |
|
71 | } | |
|
72 | ||
|
73 | void pio_output_enable(AT91S_PIO * pio, int mask) | |
|
74 | { | |
|
75 | pio->PIO_OER = mask; /* Set TDI, TMS and TCK as outputs */ | |
|
76 | } | |
|
77 | ||
|
78 | void pio_input_enable(AT91S_PIO * pio, int mask) | |
|
79 | { | |
|
80 | pio->PIO_ODR = mask; /* Set TDO as input */ | |
|
81 | pio->PIO_IFER = mask; /* Enable Input Filter */ | |
|
82 | } | |
|
83 | ||
|
84 | void pio_disable_irq(AT91S_PIO * pio, int mask) | |
|
85 | { | |
|
86 | pio->PIO_IDR = mask; /* Disable pin interrupts */ | |
|
87 | } | |
|
88 | ||
|
89 | void pio_disable_multiple_driver(AT91S_PIO * pio, int mask) | |
|
90 | { | |
|
91 | pio->PIO_MDDR = mask; /* Disable Multiple Diver */ | |
|
92 | } | |
|
93 | ||
|
94 | void pio_disable_pull_ups(AT91S_PIO * pio, int mask) | |
|
95 | { | |
|
96 | pio->PIO_PUDR = mask; /* Disable Pull-Ups */ | |
|
97 | } | |
|
98 | ||
|
99 | void pio_synchronous_data_output(AT91S_PIO * pio, int mask) | |
|
100 | { | |
|
101 | pio->PIO_OWDR = mask; /* Synchronous Data Output Write in PIO_ */ | |
|
102 | } |
@@ -0,0 +1,131 | |||
|
1 | /* | |
|
2 | * This programmer uses AT91' GPIO lines | |
|
3 | * | |
|
4 | * 2006 by Carlos Camargo | |
|
5 | * 2007.May.10 Andres Calderon | |
|
6 | * 2009.Aug.26 Jose Francisco Quenta | |
|
7 | */ | |
|
8 | ||
|
9 | #ifndef ECB_AT91_H | |
|
10 | #define ECB_AT91_H | |
|
11 | ||
|
12 | ||
|
13 | #define MAP_SIZE 4096Ul | |
|
14 | #define MAP_MASK (MAP_SIZE - 1) | |
|
15 | ||
|
16 | #define PIOA_BASE 0xFFFFF400 | |
|
17 | #define PIOB_BASE 0xFFFFF600 | |
|
18 | #define PIOC_BASE 0xFFFFF800 | |
|
19 | #define PIOD_BASE 0xFFFFFA00 | |
|
20 | ||
|
21 | #define PB0 (1 << 0) | |
|
22 | #define PB1 (1 << 1) | |
|
23 | #define PB2 (1 << 2) | |
|
24 | #define PB3 (1 << 3) | |
|
25 | #define PB8 (1 << 8) | |
|
26 | #define PB9 (1 << 9) | |
|
27 | #define PB10 (1 << 10) | |
|
28 | #define PB11 (1 << 11) | |
|
29 | #define PB16 (1 << 16) | |
|
30 | #define PB17 (1 << 17) | |
|
31 | #define PB18 (1 << 18) | |
|
32 | #define PB19 (1 << 19) | |
|
33 | #define PB20 (1 << 20) | |
|
34 | #define PB21 (1 << 21) | |
|
35 | #define PB22 (1 << 22) | |
|
36 | #define PB23 (1 << 23) | |
|
37 | #define PB24 (1 << 24) | |
|
38 | #define PB25 (1 << 25) | |
|
39 | #define PB30 (1 << 30) | |
|
40 | #define PB31 (1 << 31) | |
|
41 | ||
|
42 | #define PC0 (1 << 0) | |
|
43 | #define PC1 (1 << 1) | |
|
44 | #define PC4 (1 << 4) | |
|
45 | #define PC5 (1 << 5) | |
|
46 | #define PC6 (1 << 6) | |
|
47 | #define PC7 (1 << 7) | |
|
48 | #define PC8 (1 << 8) | |
|
49 | #define PC9 (1 << 9) | |
|
50 | #define PC10 (1 << 10) | |
|
51 | #define PC11 (1 << 11) | |
|
52 | #define PC16 (1 << 16) | |
|
53 | #define PC17 (1 << 17) | |
|
54 | #define PC18 (1 << 18) | |
|
55 | #define PC19 (1 << 19) | |
|
56 | #define PC20 (1 << 20) | |
|
57 | #define PC21 (1 << 21) | |
|
58 | #define PC22 (1 << 22) | |
|
59 | #define PC23 (1 << 23) | |
|
60 | #define PC24 (1 << 24) | |
|
61 | #define PC25 (1 << 25) | |
|
62 | #define PC26 (1 << 26) | |
|
63 | #define PC27 (1 << 27) | |
|
64 | #define PC28 (1 << 28) | |
|
65 | #define PC29 (1 << 29) | |
|
66 | #define PC30 (1 << 30) | |
|
67 | #define PC31 (1 << 31) | |
|
68 | ||
|
69 | ||
|
70 | typedef volatile unsigned int AT91_REG; | |
|
71 | /* Hardware register definition */ | |
|
72 | ||
|
73 | typedef struct _AT91S_PIO { | |
|
74 | AT91_REG PIO_PER; /* PIO Enable Register */ | |
|
75 | AT91_REG PIO_PDR; /* PIO Disable Register */ | |
|
76 | AT91_REG PIO_PSR; /* PIO Status Register */ | |
|
77 | AT91_REG Reserved0[1]; | |
|
78 | AT91_REG PIO_OER; /* Output Enable Register */ | |
|
79 | AT91_REG PIO_ODR; /* Output Disable Registerr */ | |
|
80 | AT91_REG PIO_OSR; /* Output Status Register */ | |
|
81 | AT91_REG Reserved1[1]; | |
|
82 | AT91_REG PIO_IFER; /* Input Filter Enable Register */ | |
|
83 | AT91_REG PIO_IFDR; /* Input Filter Disable Register */ | |
|
84 | AT91_REG PIO_IFSR; /* Input Filter Status Register */ | |
|
85 | AT91_REG Reserved2[1]; | |
|
86 | AT91_REG PIO_SODR; /* Set Output Data Register */ | |
|
87 | AT91_REG PIO_CODR; /* Clear Output Data Register */ | |
|
88 | AT91_REG PIO_ODSR; /* Output Data Status Register */ | |
|
89 | AT91_REG PIO_PDSR; /* Pin Data Status Register */ | |
|
90 | AT91_REG PIO_IER; /* Interrupt Enable Register */ | |
|
91 | AT91_REG PIO_IDR; /* Interrupt Disable Register */ | |
|
92 | AT91_REG PIO_IMR; /* Interrupt Mask Register */ | |
|
93 | AT91_REG PIO_ISR; /* Interrupt Status Register */ | |
|
94 | AT91_REG PIO_MDER; /* Multi-driver Enable Register */ | |
|
95 | AT91_REG PIO_MDDR; /* Multi-driver Disable Register */ | |
|
96 | AT91_REG PIO_MDSR; /* Multi-driver Status Register */ | |
|
97 | AT91_REG Reserved3[1]; | |
|
98 | AT91_REG PIO_PUDR; /* Pull-up Disable Register */ | |
|
99 | AT91_REG PIO_PUER; /* Pull-up Enable Register */ | |
|
100 | AT91_REG PIO_PUSR; /* Pad Pull-up Status Register */ | |
|
101 | AT91_REG Reserved4[1]; | |
|
102 | AT91_REG PIO_ASR; /* Select A Register */ | |
|
103 | AT91_REG PIO_BSR; /* Select B Register */ | |
|
104 | AT91_REG PIO_ABSR; /* AB Select Status Register */ | |
|
105 | AT91_REG Reserved5[9]; | |
|
106 | AT91_REG PIO_OWER; /* Output Write Enable Register */ | |
|
107 | AT91_REG PIO_OWDR; /* Output Write Disable Register */ | |
|
108 | AT91_REG PIO_OWSR; /* Output Write Status Register */ | |
|
109 | } AT91S_PIO, *AT91PS_PIO; | |
|
110 | ||
|
111 | void pio_out(AT91S_PIO * pio, int mask, unsigned long val, int opcion); | |
|
112 | ||
|
113 | int pio_in(AT91S_PIO * pio, int mask); | |
|
114 | ||
|
115 | AT91S_PIO *pio_map(unsigned int piobase); | |
|
116 | ||
|
117 | void pio_enable(AT91S_PIO * pio, int mask); | |
|
118 | ||
|
119 | void pio_output_enable(AT91S_PIO * pio, int mask); | |
|
120 | ||
|
121 | void pio_input_enable(AT91S_PIO * pio, int mask); | |
|
122 | ||
|
123 | void pio_disable_irq(AT91S_PIO * pio, int mask); | |
|
124 | ||
|
125 | void pio_disable_multiple_driver(AT91S_PIO * pio, int mask); | |
|
126 | ||
|
127 | void pio_disable_pull_ups(AT91S_PIO * pio, int mask); | |
|
128 | ||
|
129 | void pio_synchronous_data_output(AT91S_PIO * pio, int mask); | |
|
130 | ||
|
131 | #endif |
@@ -0,0 +1,19 | |||
|
1 | /* | |
|
2 | * Funciones_ControlERs.h | |
|
3 | * | |
|
4 | * Created on: Jan 14, 2010 | |
|
5 | * Author: redes | |
|
6 | */ | |
|
7 | ||
|
8 | #ifndef FUNCIONES_CONTROLERS_H_ | |
|
9 | #define FUNCIONES_CONTROLERS_H_ | |
|
10 | ||
|
11 | int estado_ERemota(char dir_red[],int dir_inicio,int dir_fin); | |
|
12 | ||
|
13 | int envia_experimento(char valor[], int base); | |
|
14 | ||
|
15 | int trae_monitoreo(char valor[], int base); | |
|
16 | ||
|
17 | int ClienteUDP(char *opcion, char *valor); | |
|
18 | ||
|
19 | #endif /* FUNCIONES_CONTROLERS_H_ */ |
@@ -0,0 +1,17 | |||
|
1 | /* | |
|
2 | * Mensajes.h | |
|
3 | * | |
|
4 | * Created on: Nov 12, 2009 | |
|
5 | * Author: redes | |
|
6 | */ | |
|
7 | ||
|
8 | #ifndef MENSAJES_H_ | |
|
9 | #define MENSAJES_H_ | |
|
10 | ||
|
11 | void LOG_SERVIDOR(char *mensaje); | |
|
12 | void LOG_CLIENTE(char *mensaje); | |
|
13 | void ERROR_FATAL(char *mensaje); | |
|
14 | void ERROR(char *mensaje); | |
|
15 | ||
|
16 | ||
|
17 | #endif /* MENSAJES_H_ */ |
@@ -0,0 +1,39 | |||
|
1 | /* | |
|
2 | * Mensajes.c | |
|
3 | * | |
|
4 | * Created on: Nov 12, 2009 | |
|
5 | * Author: Jose Francisco Quenta | |
|
6 | */ | |
|
7 | ||
|
8 | #include <stdio.h> | |
|
9 | #include <stdlib.h> | |
|
10 | ||
|
11 | /* | |
|
12 | * Imprime mensajes del servidor | |
|
13 | */ | |
|
14 | void LOG_SERVIDOR(char *mensaje){ | |
|
15 | printf("SERVIDOR: %s\n",mensaje); | |
|
16 | } | |
|
17 | ||
|
18 | /* | |
|
19 | * Imprime mensajes del cliente | |
|
20 | */ | |
|
21 | void LOG_CLIENTE(char *mensaje){ | |
|
22 | printf("CLIENTE: %s\n",mensaje); | |
|
23 | } | |
|
24 | ||
|
25 | /* | |
|
26 | * Error no fatal, permite la continuación del programa | |
|
27 | */ | |
|
28 | void ERROR(char *mensaje){ | |
|
29 | fprintf(stderr, "ERROR. %s\n", mensaje); | |
|
30 | } | |
|
31 | ||
|
32 | /* | |
|
33 | * Error fatal, aborta la ejecución del programa con código de salida de error | |
|
34 | */ | |
|
35 | void ERROR_FATAL(char *mensaje){ | |
|
36 | fprintf(stderr, "ERROR FATAL. %s\n", mensaje); | |
|
37 | exit(EXIT_FAILURE); | |
|
38 | } | |
|
39 |
@@ -0,0 +1,324 | |||
|
1 | /* | |
|
2 | * Servidor.c | |
|
3 | * | |
|
4 | * Created on: Nov 3, 2009 | |
|
5 | * Author: Jose Francisco Quenta | |
|
6 | * | |
|
7 | * Se implementa: | |
|
8 | * -Carga en memoria los apuntes contenidos en un archivo de experimentos: apunte0 -> GPIO | |
|
9 | * -Cambio de apunte. | |
|
10 | * -Lectura del estado actual del apunte y grabado del mismo en un archivo | |
|
11 | */ | |
|
12 | ||
|
13 | #include <stdio.h> | |
|
14 | #include <stdlib.h> | |
|
15 | #include <string.h> | |
|
16 | #include <unistd.h> | |
|
17 | #include <errno.h> | |
|
18 | ||
|
19 | #include <sys/types.h> | |
|
20 | #include <sys/socket.h> | |
|
21 | #include <netinet/in.h> | |
|
22 | #include <arpa/inet.h> | |
|
23 | #include <netdb.h> | |
|
24 | ||
|
25 | #include "./Librerias/AT91gpio_Funciones.h" | |
|
26 | #include "./Librerias/Mensajes.h" | |
|
27 | ||
|
28 | #define PUERTO_SERVIDOR 5500 | |
|
29 | #define TAM_BUFFER 100 | |
|
30 | ||
|
31 | #define maskc_out PC30+PC28+PC26+PC24+PC22+PC20 //MSB-UP-LSB MSB-DOWN-LSB //APUNTE | |
|
32 | ||
|
33 | #define maskb_in PB16+PB18+PB20+PB30+PB24+PB22 //MSB-UP-LSB MSB-DOWN-LSB //VERIFICACION | |
|
34 | ||
|
35 | #define bit_up_2 0x00010000 //Mascara de cada bit a revisar: bit_up_2 es MSB | |
|
36 | #define bit_up_1 0x00040000 | |
|
37 | #define bit_up_0 0x00100000 | |
|
38 | #define bit_dow_2 0x40000000 | |
|
39 | #define bit_dow_1 0x01000000 | |
|
40 | #define bit_dow_0 0x00400000 | |
|
41 | ||
|
42 | #define MyID 11 | |
|
43 | ||
|
44 | char *buff_experimento= NULL; | |
|
45 | ||
|
46 | AT91S_PIO *pioc; | |
|
47 | AT91S_PIO *piob; | |
|
48 | ||
|
49 | /* | |
|
50 | * Zona de declaracion de cabeceras. | |
|
51 | */ | |
|
52 | void inicializa_gpio(); | |
|
53 | int procesa_peticion(char *buff_peticion); | |
|
54 | int cambia_apuntamiento(char *puntero_char); | |
|
55 | int carga_experimento(char *nombre_archivo); | |
|
56 | int chequeo_sistema(char *numero_muestras); | |
|
57 | ||
|
58 | /* | |
|
59 | * | |
|
60 | */ | |
|
61 | int main(){ | |
|
62 | ||
|
63 | int conexion_servidorFd; | |
|
64 | struct sockaddr_in inf_servidor; | |
|
65 | struct sockaddr_storage inf_cliente; | |
|
66 | int resultado; | |
|
67 | int numbytes_recibidos; | |
|
68 | int rpta; | |
|
69 | ||
|
70 | char *buff_peticion = (char *) malloc(TAM_BUFFER); | |
|
71 | ||
|
72 | size_t addr_len; | |
|
73 | ||
|
74 | memset(&inf_servidor, 0, sizeof(inf_servidor)); | |
|
75 | inf_servidor.sin_family= AF_INET; | |
|
76 | inf_servidor.sin_port= htons(PUERTO_SERVIDOR); | |
|
77 | inf_servidor.sin_addr.s_addr= INADDR_ANY; | |
|
78 | ||
|
79 | /* Se establece el socket */ | |
|
80 | conexion_servidorFd = socket(AF_INET,SOCK_DGRAM,0); | |
|
81 | if (conexion_servidorFd == -1){ | |
|
82 | ERROR_FATAL("No se establecio correctamente el socket: socket()"); | |
|
83 | } | |
|
84 | ||
|
85 | /* Se asocia el socket a un puerto y una IP */ | |
|
86 | resultado = bind(conexion_servidorFd,(struct sockaddr *)&inf_servidor,sizeof(inf_servidor)); | |
|
87 | if (resultado== -1){ | |
|
88 | ERROR_FATAL("No se establecio correctamente el socket: bind()"); | |
|
89 | } | |
|
90 | ||
|
91 | /* Inicializamos el puerto GPIO del sistema embebido GSBC-9260S */ | |
|
92 | inicializa_gpio(); | |
|
93 | ||
|
94 | while(1){ | |
|
95 | LOG_SERVIDOR("Esperando solicitud de cliente...\n"); | |
|
96 | ||
|
97 | /* Se espera hasta que un cliente se conecte */ | |
|
98 | addr_len = sizeof(inf_cliente); | |
|
99 | numbytes_recibidos = recvfrom(conexion_servidorFd, buff_peticion, TAM_BUFFER-1, 0, (struct sockaddr *)&inf_cliente, &addr_len); | |
|
100 | if (numbytes_recibidos == -1){ | |
|
101 | ERROR_FATAL("Error en la recepcion de datos: recvfrom()"); | |
|
102 | } | |
|
103 | ||
|
104 | /* Se procede a procesar los datos recibidos */ | |
|
105 | buff_peticion[numbytes_recibidos]= '\0'; | |
|
106 | ||
|
107 | /* procesamiento de la peticion */ | |
|
108 | rpta = procesa_peticion(buff_peticion); | |
|
109 | ||
|
110 | //Respuesta del modulo de control | |
|
111 | // | |
|
112 | ||
|
113 | ||
|
114 | } | |
|
115 | } | |
|
116 | ||
|
117 | ||
|
118 | ||
|
119 | /* | |
|
120 | * Esta funcion incializa el puerto GPIO | |
|
121 | */ | |
|
122 | void inicializa_gpio(){ | |
|
123 | ||
|
124 | // Configuracion de los pines de APUNTE | |
|
125 | pioc = pio_map(PIOC_BASE); | |
|
126 | pio_enable(pioc, maskc_out); | |
|
127 | pio_disable_irq(pioc, maskc_out); | |
|
128 | pio_disable_multiple_driver(pioc, maskc_out); | |
|
129 | pio_disable_pull_ups(pioc, maskc_out); | |
|
130 | pio_synchronous_data_output(pioc, maskc_out); | |
|
131 | pio_output_enable(pioc, maskc_out); | |
|
132 | ||
|
133 | // Configuracion de los pines de VERIFICACION | |
|
134 | piob = pio_map(PIOB_BASE); | |
|
135 | pio_enable(piob, maskb_in); | |
|
136 | pio_disable_irq(piob, maskb_in); | |
|
137 | pio_disable_multiple_driver(piob, maskb_in); | |
|
138 | pio_disable_pull_ups(piob, maskb_in); | |
|
139 | pio_input_enable(piob, maskb_in); | |
|
140 | ||
|
141 | } | |
|
142 | ||
|
143 | /* | |
|
144 | * Esta funcion procesa el mensaje de peticion y genera respuesta | |
|
145 | */ | |
|
146 | int procesa_peticion(char *buff_peticion){ | |
|
147 | int rpta; | |
|
148 | // char *header = strtok(buff_peticion, ":"); | |
|
149 | // char *ipSource = strtok(buff_peticion, ":"); | |
|
150 | // char *ipDestino = strtok(buff_peticion, ":"); | |
|
151 | char *comando = strtok(buff_peticion, ":"); | |
|
152 | char *valor = strtok(NULL, ":"); | |
|
153 | ||
|
154 | if ((comando == NULL) || (valor == NULL)){ | |
|
155 | ERROR("procesarPeticion: formato de mensaje incorrecto"); | |
|
156 | } | |
|
157 | else{ | |
|
158 | if(strcmp(comando,"CARGA") == 0) | |
|
159 | rpta = carga_experimento(valor); | |
|
160 | else if(strcmp(comando,"CAMBIA") == 0) | |
|
161 | rpta = cambia_apuntamiento(valor); | |
|
162 | else if(strcmp(comando,"CHEQUEO") == 0) | |
|
163 | rpta = chequeo_sistema(valor); | |
|
164 | else | |
|
165 | ERROR("procesa_peticion: comando no reconocido"); | |
|
166 | } | |
|
167 | ||
|
168 | return rpta; | |
|
169 | } | |
|
170 | ||
|
171 | ||
|
172 | /* | |
|
173 | * Esta funcion carga un archivo en un buffer que esta ubicado en memoria, luego | |
|
174 | * este buffer es usado en la funcion "cambia_apuntamiento" para obtener el dato | |
|
175 | * que sera usado en el cambio de apuntamiento. | |
|
176 | */ | |
|
177 | int carga_experimento(char *nombre_archivo){ | |
|
178 | ||
|
179 | FILE *Archivo_Fd; | |
|
180 | ||
|
181 | char *cadena = (char *) malloc(25); | |
|
182 | ||
|
183 | int longitud_cadena; | |
|
184 | int num_bytes= 0; | |
|
185 | int num_filas= 0; | |
|
186 | ||
|
187 | char ruta_archivo[50]; // Se crea la ruta para abrir el archivo | |
|
188 | strcpy(ruta_archivo,"/mnt/sd/archivos/"); | |
|
189 | strcat(ruta_archivo,nombre_archivo); | |
|
190 | ||
|
191 | Archivo_Fd = fopen(ruta_archivo,"r"); // Se procede a abrir el archivo, segun la ruta especificada | |
|
192 | if(!Archivo_Fd){ | |
|
193 | ERROR("carga_archivo: No se pudo abrir el archivo!!! --> fopen()\n"); | |
|
194 | return -1; | |
|
195 | }else{ | |
|
196 | ||
|
197 | while(!feof(Archivo_Fd)){ // Se procede a calcular la longitud del archivo para separar memoria | |
|
198 | fgets(cadena,20,Archivo_Fd); | |
|
199 | longitud_cadena= strlen(cadena); | |
|
200 | cadena[longitud_cadena-1] = '\0'; | |
|
201 | num_bytes = num_bytes + longitud_cadena; | |
|
202 | num_filas++; | |
|
203 | } | |
|
204 | ||
|
205 | rewind(Archivo_Fd); // Se reinicia el puntero del archivo | |
|
206 | ||
|
207 | char *buffer_temporal = (char *) malloc(num_bytes+1); // Se separa espacio de memoria segun | |
|
208 | // la longitud del archivo | |
|
209 | fread(buffer_temporal, sizeof(char), num_bytes, Archivo_Fd); | |
|
210 | ||
|
211 | char *puntero= strstr(buffer_temporal,".abs"); // Se procede a eliminar la cabecera del archivo | |
|
212 | puntero= puntero + 12; | |
|
213 | ||
|
214 | buff_experimento = (char *) malloc(7*(num_filas-3)); // num_bytes_fila*(num_filas-3); | |
|
215 | strncpy(buff_experimento,puntero,7*(num_filas-3)); // Se carga en memoria la informacion del archivo | |
|
216 | ||
|
217 | fclose(Archivo_Fd); | |
|
218 | ||
|
219 | cambia_apuntamiento("0"); // Se apunta a la direccion 0 | |
|
220 | ||
|
221 | return 1; | |
|
222 | } | |
|
223 | } | |
|
224 | ||
|
225 | /* | |
|
226 | * Esta funcion recibe un numero en formato char, el dato se transforma a su equivalente en | |
|
227 | * un numero entero, que sera usado para sacar un dato del buffer "buff_experimento", esta | |
|
228 | * dato es el valor que se enviara al sistema de conmutacion RF para el cambio de apunte a | |
|
229 | * traves del puerto GPIO. | |
|
230 | */ | |
|
231 | int cambia_apuntamiento(char *puntero_char){ | |
|
232 | ||
|
233 | /*MSB-UP-LSB MSB-DOWN-LSB*/ | |
|
234 | int desplazamiento[6]={30,28,26,24,22,20}; // Defino los dezplazamientos que se aplicara | |
|
235 | // al dato que ingresa para formar el número | |
|
236 | // entero que se le pasara al puerto GPIO | |
|
237 | // Estos números son los pines del puerto GPIO | |
|
238 | // que se estan usando para el control | |
|
239 | ||
|
240 | int puntero= atoi(puntero_char); // Se convierte a entero la direccion del puntero | |
|
241 | ||
|
242 | int base= 7*puntero; // base= cantidad_bytes del dato x puntero | |
|
243 | // cantidad de bytes es el numero de bytes que | |
|
244 | printf("%i\n",puntero); // contiene cada dato, para este caso es 7 | |
|
245 | // porque es 6 bits de datos + 1 bit del cambio | |
|
246 | // de linea. | |
|
247 | char valor_char; | |
|
248 | unsigned long valor; | |
|
249 | unsigned long acumulado_ceros=0; | |
|
250 | unsigned long acumulado_unos=0; | |
|
251 | ||
|
252 | int offset; // Defino offset para el desplazamiento a traves | |
|
253 | for(offset=0;offset<6;offset++){ // de cada dato que se obtiene del "buff_experimento" | |
|
254 | ||
|
255 | valor_char= buff_experimento[base+offset]; // Obtengo el dato | |
|
256 | ||
|
257 | if (valor_char == '0'){ // Obtengo el número acumulado segun sea un cero o un uno | |
|
258 | valor= 0; | |
|
259 | acumulado_ceros= acumulado_ceros + (1 << desplazamiento[offset]); | |
|
260 | }else{ | |
|
261 | valor= 1; | |
|
262 | acumulado_unos= acumulado_unos + (1 << desplazamiento[offset]); | |
|
263 | } | |
|
264 | ||
|
265 | } | |
|
266 | ||
|
267 | pio_out(pioc, maskc_out, acumulado_unos, 1); | |
|
268 | pio_out(pioc, maskc_out, acumulado_ceros, 0); | |
|
269 | ||
|
270 | return 1; | |
|
271 | ||
|
272 | } | |
|
273 | ||
|
274 | /* | |
|
275 | * Esta funcion lee "n" veces el estado del APUNTE actual y lo guarda en el | |
|
276 | * archivo Verificacion. | |
|
277 | */ | |
|
278 | ||
|
279 | int chequeo_sistema(char *numero_muestras){ | |
|
280 | ||
|
281 | char valor[7]; | |
|
282 | int i,cnt; | |
|
283 | unsigned int entradac= 0; | |
|
284 | FILE *fd; | |
|
285 | fd=fopen("/mnt/sd/archivos/Verificacion","w"); | |
|
286 | fprintf(fd,"%s\n","Verificacion"); | |
|
287 | fprintf(fd,"%s\n","------------"); | |
|
288 | cnt=0; | |
|
289 | do | |
|
290 | { | |
|
291 | //Inicializando arreglo | |
|
292 | for(i=0;i<6;i++) | |
|
293 | valor[i]='0'; | |
|
294 | ||
|
295 | valor[6]='\0'; | |
|
296 | ||
|
297 | //Lectura de puerto | |
|
298 | entradac= pio_in(piob,maskb_in); | |
|
299 | ||
|
300 | //Dandole formato al dato | |
|
301 | if (!(entradac & bit_up_2)) | |
|
302 | valor[0] = '1'; | |
|
303 | if (!(entradac & bit_up_1)) | |
|
304 | valor[1] = '1'; | |
|
305 | if (!(entradac & bit_up_0)) | |
|
306 | valor[2] = '1'; | |
|
307 | if (!(entradac & bit_dow_2)) | |
|
308 | valor[3] = '1'; | |
|
309 | if (!(entradac & bit_dow_1)) | |
|
310 | valor[4] = '1'; | |
|
311 | if (!(entradac & bit_dow_0)) | |
|
312 | valor[5] = '1'; | |
|
313 | ||
|
314 | //Escribiendo en archivo | |
|
315 | fprintf(fd,"%s\n",valor); | |
|
316 | cnt=cnt+1; | |
|
317 | usleep(1*1000*1000); | |
|
318 | ||
|
319 | }while(cnt < atoi(numero_muestras)); | |
|
320 | ||
|
321 | fclose(fd); | |
|
322 | ||
|
323 | return 1; | |
|
324 | } |
@@ -0,0 +1,322 | |||
|
1 | /* | |
|
2 | * Servidor.c | |
|
3 | * | |
|
4 | * Created on: Nov 3, 2009 | |
|
5 | * Author: Jose Francisco Quenta | |
|
6 | * | |
|
7 | * Se implementa: | |
|
8 | * -Carga en memoria los apuntes contenidos en un archivo de experimentos: apunte0 -> GPIO | |
|
9 | * -Cambio de apunte. | |
|
10 | * -Lectura del estado actual del apunte y grabado del mismo en un archivo | |
|
11 | */ | |
|
12 | ||
|
13 | #include <stdio.h> | |
|
14 | #include <stdlib.h> | |
|
15 | #include <string.h> | |
|
16 | #include <unistd.h> | |
|
17 | #include <errno.h> | |
|
18 | ||
|
19 | #include <sys/types.h> | |
|
20 | #include <sys/socket.h> | |
|
21 | #include <netinet/in.h> | |
|
22 | #include <arpa/inet.h> | |
|
23 | #include <netdb.h> | |
|
24 | ||
|
25 | #include "./Librerias/AT91gpio_Funciones.h" | |
|
26 | #include "./Librerias/Mensajes.h" | |
|
27 | ||
|
28 | #define PUERTO_SERVIDOR 5500 | |
|
29 | #define TAM_BUFFER 100 | |
|
30 | ||
|
31 | #define maskc_out PC30+PC28+PC26+PC24+PC22+PC20 //MSB-UP-LSB MSB-DOWN-LSB //APUNTE | |
|
32 | ||
|
33 | #define maskb_in PB16+PB18+PB20+PB30+PB24+PB22 //MSB-UP-LSB MSB-DOWN-LSB //VERIFICACION | |
|
34 | ||
|
35 | #define bit_up_2 0x00010000 //Mascara de cada bit a revisar: bit_up_2 es MSB | |
|
36 | #define bit_up_1 0x00040000 | |
|
37 | #define bit_up_0 0x00100000 | |
|
38 | #define bit_dow_2 0x40000000 | |
|
39 | #define bit_dow_1 0x01000000 | |
|
40 | #define bit_dow_0 0x00400000 | |
|
41 | ||
|
42 | #define MyID 11 | |
|
43 | ||
|
44 | char *buff_experimento= NULL; | |
|
45 | ||
|
46 | AT91S_PIO *pioc; | |
|
47 | AT91S_PIO *piob; | |
|
48 | ||
|
49 | /* | |
|
50 | * Zona de declaracion de cabeceras. | |
|
51 | */ | |
|
52 | void inicializa_gpio(); | |
|
53 | int procesa_peticion(char *buff_peticion); | |
|
54 | int cambia_apuntamiento(char *puntero_char); | |
|
55 | int carga_experimento(char *nombre_archivo); | |
|
56 | int chequeo_sistema(char *numero_muestras); | |
|
57 | ||
|
58 | /* | |
|
59 | * | |
|
60 | */ | |
|
61 | int main(){ | |
|
62 | ||
|
63 | int conexion_servidorFd; | |
|
64 | struct sockaddr_in inf_servidor; | |
|
65 | struct sockaddr_storage inf_cliente; | |
|
66 | int resultado; | |
|
67 | int numbytes_recibidos; | |
|
68 | int rpta; | |
|
69 | ||
|
70 | char *buff_peticion = (char *) malloc(TAM_BUFFER); | |
|
71 | ||
|
72 | size_t addr_len; | |
|
73 | ||
|
74 | memset(&inf_servidor, 0, sizeof(inf_servidor)); | |
|
75 | inf_servidor.sin_family= AF_INET; | |
|
76 | inf_servidor.sin_port= htons(PUERTO_SERVIDOR); | |
|
77 | inf_servidor.sin_addr.s_addr= INADDR_ANY; | |
|
78 | ||
|
79 | /* Se establece el socket */ | |
|
80 | conexion_servidorFd = socket(AF_INET,SOCK_DGRAM,0); | |
|
81 | if (conexion_servidorFd == -1){ | |
|
82 | ERROR_FATAL("No se establecio correctamente el socket: socket()"); | |
|
83 | } | |
|
84 | ||
|
85 | /* Se asocia el socket a un puerto y una IP */ | |
|
86 | resultado = bind(conexion_servidorFd,(struct sockaddr *)&inf_servidor,sizeof(inf_servidor)); | |
|
87 | if (resultado== -1){ | |
|
88 | ERROR_FATAL("No se establecio correctamente el socket: bind()"); | |
|
89 | } | |
|
90 | ||
|
91 | /* Inicializamos el puerto GPIO del sistema embebido GSBC-9260S */ | |
|
92 | inicializa_gpio(); | |
|
93 | ||
|
94 | while(1){ | |
|
95 | LOG_SERVIDOR("Esperando solicitud de cliente...\n"); | |
|
96 | ||
|
97 | /* Se espera hasta que un cliente se conecte */ | |
|
98 | addr_len = sizeof(inf_cliente); | |
|
99 | numbytes_recibidos = recvfrom(conexion_servidorFd, buff_peticion, TAM_BUFFER-1, 0, (struct sockaddr *)&inf_cliente, &addr_len); | |
|
100 | if (numbytes_recibidos == -1){ | |
|
101 | ERROR_FATAL("Error en la recepcion de datos: recvfrom()"); | |
|
102 | } | |
|
103 | ||
|
104 | /* Se procede a procesar los datos recibidos */ | |
|
105 | buff_peticion[numbytes_recibidos]= '\0'; | |
|
106 | ||
|
107 | /* procesamiento de la peticion */ | |
|
108 | rpta = procesa_peticion(buff_peticion); | |
|
109 | ||
|
110 | //Respuesta del modulo de control | |
|
111 | // | |
|
112 | ||
|
113 | ||
|
114 | } | |
|
115 | } | |
|
116 | ||
|
117 | /* | |
|
118 | * Esta funcion incializa el puerto GPIO | |
|
119 | */ | |
|
120 | void inicializa_gpio(){ | |
|
121 | ||
|
122 | // Configuracion de los pines de APUNTE | |
|
123 | pioc = pio_map(PIOC_BASE); | |
|
124 | pio_enable(pioc, maskc_out); | |
|
125 | pio_disable_irq(pioc, maskc_out); | |
|
126 | pio_disable_multiple_driver(pioc, maskc_out); | |
|
127 | pio_disable_pull_ups(pioc, maskc_out); | |
|
128 | pio_synchronous_data_output(pioc, maskc_out); | |
|
129 | pio_output_enable(pioc, maskc_out); | |
|
130 | ||
|
131 | // Configuracion de los pines de VERIFICACION | |
|
132 | piob = pio_map(PIOB_BASE); | |
|
133 | pio_enable(piob, maskb_in); | |
|
134 | pio_disable_irq(piob, maskb_in); | |
|
135 | pio_disable_multiple_driver(piob, maskb_in); | |
|
136 | pio_disable_pull_ups(piob, maskb_in); | |
|
137 | pio_input_enable(piob, maskb_in); | |
|
138 | ||
|
139 | } | |
|
140 | ||
|
141 | /* | |
|
142 | * Esta funcion procesa el mensaje de peticion y genera respuesta | |
|
143 | */ | |
|
144 | int procesa_peticion(char *buff_peticion){ | |
|
145 | int rpta; | |
|
146 | // char *header = strtok(buff_peticion, ":"); | |
|
147 | // char *ipSource = strtok(buff_peticion, ":"); | |
|
148 | // char *ipDestino = strtok(buff_peticion, ":"); | |
|
149 | char *comando = strtok(buff_peticion, ":"); | |
|
150 | char *valor = strtok(NULL, ":"); | |
|
151 | ||
|
152 | if ((comando == NULL) || (valor == NULL)){ | |
|
153 | ERROR("procesarPeticion: formato de mensaje incorrecto"); | |
|
154 | } | |
|
155 | else{ | |
|
156 | if(strcmp(comando,"CARGA") == 0) | |
|
157 | rpta = carga_experimento(valor); | |
|
158 | else if(strcmp(comando,"CAMBIA") == 0) | |
|
159 | rpta = cambia_apuntamiento(valor); | |
|
160 | else if(strcmp(comando,"CHEQUEO") == 0) | |
|
161 | rpta = chequeo_sistema(valor); | |
|
162 | else | |
|
163 | ERROR("procesa_peticion: comando no reconocido"); | |
|
164 | } | |
|
165 | ||
|
166 | return rpta; | |
|
167 | } | |
|
168 | ||
|
169 | ||
|
170 | /* | |
|
171 | * Esta funcion carga un archivo en un buffer que esta ubicado en memoria, luego | |
|
172 | * este buffer es usado en la funcion "cambia_apuntamiento" para obtener el dato | |
|
173 | * que sera usado en el cambio de apuntamiento. | |
|
174 | */ | |
|
175 | int carga_experimento(char *nombre_archivo){ | |
|
176 | ||
|
177 | FILE *Archivo_Fd; | |
|
178 | ||
|
179 | char *cadena = (char *) malloc(25); | |
|
180 | ||
|
181 | int longitud_cadena; | |
|
182 | int num_bytes= 0; | |
|
183 | int num_filas= 0; | |
|
184 | ||
|
185 | char ruta_archivo[50]; // Se crea la ruta para abrir el archivo | |
|
186 | strcpy(ruta_archivo,"/mnt/sd/archivos/"); | |
|
187 | strcat(ruta_archivo,nombre_archivo); | |
|
188 | ||
|
189 | Archivo_Fd = fopen(ruta_archivo,"r"); // Se procede a abrir el archivo, segun la ruta especificada | |
|
190 | if(!Archivo_Fd){ | |
|
191 | ERROR("carga_archivo: No se pudo abrir el archivo!!! --> fopen()\n"); | |
|
192 | return -1; | |
|
193 | }else{ | |
|
194 | ||
|
195 | while(!feof(Archivo_Fd)){ // Se procede a calcular la longitud del archivo para separar memoria | |
|
196 | fgets(cadena,20,Archivo_Fd); | |
|
197 | longitud_cadena= strlen(cadena); | |
|
198 | cadena[longitud_cadena-1] = '\0'; | |
|
199 | num_bytes = num_bytes + longitud_cadena; | |
|
200 | num_filas++; | |
|
201 | } | |
|
202 | ||
|
203 | rewind(Archivo_Fd); // Se reinicia el puntero del archivo | |
|
204 | ||
|
205 | char *buffer_temporal = (char *) malloc(num_bytes+1); // Se separa espacio de memoria segun | |
|
206 | // la longitud del archivo | |
|
207 | fread(buffer_temporal, sizeof(char), num_bytes, Archivo_Fd); | |
|
208 | ||
|
209 | char *puntero= strstr(buffer_temporal,".abs"); // Se procede a eliminar la cabecera del archivo | |
|
210 | puntero= puntero + 12; | |
|
211 | ||
|
212 | buff_experimento = (char *) malloc(7*(num_filas-3)); // num_bytes_fila*(num_filas-3); | |
|
213 | strncpy(buff_experimento,puntero,7*(num_filas-3)); // Se carga en memoria la informacion del archivo | |
|
214 | ||
|
215 | fclose(Archivo_Fd); | |
|
216 | ||
|
217 | cambia_apuntamiento("0"); // Se apunta a la direccion 0 | |
|
218 | ||
|
219 | return 1; | |
|
220 | } | |
|
221 | } | |
|
222 | ||
|
223 | /* | |
|
224 | * Esta funcion recibe un numero en formato char, el dato se transforma a su equivalente en | |
|
225 | * un numero entero, que sera usado para sacar un dato del buffer "buff_experimento", esta | |
|
226 | * dato es el valor que se enviara al sistema de conmutacion RF para el cambio de apunte a | |
|
227 | * traves del puerto GPIO. | |
|
228 | */ | |
|
229 | int cambia_apuntamiento(char *puntero_char){ | |
|
230 | ||
|
231 | /*MSB-UP-LSB MSB-DOWN-LSB*/ | |
|
232 | int desplazamiento[6]={30,28,26,24,22,20}; // Defino los dezplazamientos que se aplicara | |
|
233 | // al dato que ingresa para formar el número | |
|
234 | // entero que se le pasara al puerto GPIO | |
|
235 | // Estos números son los pines del puerto GPIO | |
|
236 | // que se estan usando para el control | |
|
237 | ||
|
238 | int puntero= atoi(puntero_char); // Se convierte a entero la direccion del puntero | |
|
239 | ||
|
240 | int base= 7*puntero; // base= cantidad_bytes del dato x puntero | |
|
241 | // cantidad de bytes es el numero de bytes que | |
|
242 | printf("%i\n",puntero); // contiene cada dato, para este caso es 7 | |
|
243 | // porque es 6 bits de datos + 1 bit del cambio | |
|
244 | // de linea. | |
|
245 | char valor_char; | |
|
246 | unsigned long valor; | |
|
247 | unsigned long acumulado_ceros=0; | |
|
248 | unsigned long acumulado_unos=0; | |
|
249 | ||
|
250 | int offset; // Defino offset para el desplazamiento a traves | |
|
251 | for(offset=0;offset<6;offset++){ // de cada dato que se obtiene del "buff_experimento" | |
|
252 | ||
|
253 | valor_char= buff_experimento[base+offset]; // Obtengo el dato | |
|
254 | ||
|
255 | if (valor_char == '0'){ // Obtengo el número acumulado segun sea un cero o un uno | |
|
256 | valor= 0; | |
|
257 | acumulado_ceros= acumulado_ceros + (1 << desplazamiento[offset]); | |
|
258 | }else{ | |
|
259 | valor= 1; | |
|
260 | acumulado_unos= acumulado_unos + (1 << desplazamiento[offset]); | |
|
261 | } | |
|
262 | ||
|
263 | } | |
|
264 | ||
|
265 | pio_out(pioc, maskc_out, acumulado_unos, 1); | |
|
266 | pio_out(pioc, maskc_out, acumulado_ceros, 0); | |
|
267 | ||
|
268 | return 1; | |
|
269 | ||
|
270 | } | |
|
271 | ||
|
272 | /* | |
|
273 | * Esta funcion lee "n" veces el estado del APUNTE actual y lo guarda en el | |
|
274 | * archivo Verificacion. | |
|
275 | */ | |
|
276 | ||
|
277 | int chequeo_sistema(char *numero_muestras){ | |
|
278 | ||
|
279 | char valor[7]; | |
|
280 | int i,cnt; | |
|
281 | unsigned int entradac= 0; | |
|
282 | FILE *fd; | |
|
283 | fd=fopen("/mnt/sd/archivos/Verificacion","w"); | |
|
284 | fprintf(fd,"%s\n","Verificacion"); | |
|
285 | fprintf(fd,"%s\n","------------"); | |
|
286 | cnt=0; | |
|
287 | do | |
|
288 | { | |
|
289 | //Inicializando arreglo | |
|
290 | for(i=0;i<6;i++) | |
|
291 | valor[i]='0'; | |
|
292 | ||
|
293 | valor[6]='\0'; | |
|
294 | ||
|
295 | //Lectura de puerto | |
|
296 | entradac= pio_in(piob,maskb_in); | |
|
297 | ||
|
298 | //Dandole formato al dato | |
|
299 | if (!(entradac & bit_up_2)) | |
|
300 | valor[0] = '1'; | |
|
301 | if (!(entradac & bit_up_1)) | |
|
302 | valor[1] = '1'; | |
|
303 | if (!(entradac & bit_up_0)) | |
|
304 | valor[2] = '1'; | |
|
305 | if (!(entradac & bit_dow_2)) | |
|
306 | valor[3] = '1'; | |
|
307 | if (!(entradac & bit_dow_1)) | |
|
308 | valor[4] = '1'; | |
|
309 | if (!(entradac & bit_dow_0)) | |
|
310 | valor[5] = '1'; | |
|
311 | ||
|
312 | //Escribiendo en archivo | |
|
313 | fprintf(fd,"%s\n",valor); | |
|
314 | cnt=cnt+1; | |
|
315 | usleep(1*1000*1000); | |
|
316 | ||
|
317 | }while(cnt < atoi(numero_muestras)); | |
|
318 | ||
|
319 | fclose(fd); | |
|
320 | ||
|
321 | return 1; | |
|
322 | } |
General Comments 0
You need to be logged in to leave comments.
Login now