Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 1 file changed
  • 0 comments
  • 1 contributor

Showing 1 changed file with 89 additions and 4 deletions. Show diff stats Hide diff stats

  1. 93  src/shellext.c
93  src/shellext.c
@@ -23,14 +23,22 @@
23 23
 #include <sys/ioctl.h>
24 24
 #include <sys/types.h>
25 25
 #include <sys/stat.h>
  26
+#include <sys/ioctl.h>
26 27
 #include <fcntl.h>
27 28
 #include <unistd.h>
28 29
 #include <stdlib.h>
29 30
 #include <stdio.h>
  31
+#include <string.h>
  32
+#include <bsp/milkymist_pfpu.h>
  33
+#include <bsp/milkymist_tmu.h>
30 34
 
31 35
 #include "shellext.h"
32 36
 #include "fbgrab.h"
33 37
 
  38
+#ifndef PFPU_SPREG_COUNT
  39
+#define	PFPU_SPREG_COUNT 2
  40
+#endif
  41
+
34 42
 static int main_viwrite(int argc, char **argv)
35 43
 {
36 44
 	unsigned int reg, val;
@@ -149,7 +157,75 @@ static int main_fbgrab(int argc, char **argv)
149 157
 	return ret;
150 158
 }
151 159
 
152  
-rtems_shell_cmd_t shellext_viwrite = {
  160
+static int main_pfpu(int argc, char **argv)
  161
+{
  162
+	static unsigned int dummy[2]
  163
+	    __attribute__((aligned(sizeof(struct tmu_vertex))));
  164
+	union {
  165
+		float f;
  166
+		unsigned i;
  167
+	} u;
  168
+	unsigned int program[PFPU_PROGSIZE];
  169
+	float regs[PFPU_REG_COUNT];
  170
+	struct pfpu_td td = {
  171
+		.output = dummy,
  172
+		.hmeshlast = 0,
  173
+		.vmeshlast = 0,
  174
+		.program = program,
  175
+		.progsize = 0,
  176
+		.registers = regs,
  177
+		.update = true,
  178
+		.invalidate = false
  179
+	};
  180
+	char **arg;
  181
+	float *r = regs+PFPU_SPREG_COUNT, *rr;
  182
+	int hex = 0;
  183
+	int fd, res;
  184
+
  185
+	for(arg = argv+1; arg != argv+argc; arg++) {
  186
+		if(strchr(*arg, '.')) {
  187
+			*r++ = atof(*arg);
  188
+		} else if(!strncmp(*arg, "0x", 2)) {
  189
+			u.i = strtoul(*arg, NULL, 0);
  190
+			*r++ = u.f;
  191
+			hex = 1;
  192
+		} else if(strlen(*arg) == 8) {
  193
+			program[td.progsize++] = strtoul(*arg, NULL, 16);
  194
+		} else {
  195
+			fprintf(stderr, "don't understand \"%s\"\n", *arg);
  196
+			return 1;
  197
+		}
  198
+	}
  199
+
  200
+	fd = open("/dev/pfpu", O_RDWR);
  201
+	if(fd < 0) {
  202
+		perror("/dev/pfpu");
  203
+		return 2;
  204
+	}
  205
+	res = ioctl(fd, PFPU_EXECUTE, &td);
  206
+	close(fd);
  207
+
  208
+	if(res < 0) {
  209
+		perror("ioctl(PFPU_EXECUTE)");
  210
+		return 2;
  211
+	}
  212
+
  213
+	for(rr = regs+PFPU_SPREG_COUNT; r != rr; rr++) {
  214
+		if(rr != regs+PFPU_SPREG_COUNT)
  215
+			putchar(' ');
  216
+		if(hex) {
  217
+			u.f = *rr;
  218
+			printf("0x%08x", u.i);
  219
+		} else {
  220
+			printf("%g", *rr);
  221
+		}
  222
+	}
  223
+	putchar('\n');
  224
+
  225
+	return 0;
  226
+}
  227
+
  228
+static rtems_shell_cmd_t shellext_viwrite = {
153 229
 	"viwrite",			/* name */
154 230
 	"viwrite register value",	/* usage */
155 231
 	"flickernoise",			/* topic */
@@ -158,7 +234,7 @@ rtems_shell_cmd_t shellext_viwrite = {
158 234
 	NULL				/* next */
159 235
 };
160 236
 
161  
-rtems_shell_cmd_t shellext_viread = {
  237
+static rtems_shell_cmd_t shellext_viread = {
162 238
 	"viread",			/* name */
163 239
 	"viread register",		/* usage */
164 240
 	"flickernoise",			/* topic */
@@ -167,7 +243,7 @@ rtems_shell_cmd_t shellext_viread = {
167 243
 	&shellext_viwrite		/* next */
168 244
 };
169 245
 
170  
-rtems_shell_cmd_t shellext_erase = {
  246
+static rtems_shell_cmd_t shellext_erase = {
171 247
 	"erase",			/* name */
172 248
 	"erase device",			/* usage */
173 249
 	"flickernoise",			/* topic */
@@ -176,7 +252,7 @@ rtems_shell_cmd_t shellext_erase = {
176 252
 	&shellext_viread		/* next */
177 253
 };
178 254
 
179  
-rtems_shell_cmd_t shellext = {
  255
+static rtems_shell_cmd_t shellext_fbgrab = {
180 256
 	"fbgrab",			/* name */
181 257
 	"fbgrab file.png",		/* usage */
182 258
 	"flickernoise",			/* topic */
@@ -184,3 +260,12 @@ rtems_shell_cmd_t shellext = {
184 260
 	NULL,				/* alias */
185 261
 	&shellext_erase			/* next */
186 262
 };
  263
+
  264
+rtems_shell_cmd_t shellext = {
  265
+	"pfpu",				/* name */
  266
+	"pfpu reg ... code ...",	/* usage */
  267
+	"flickernoise",			/* topic */
  268
+	main_pfpu,			/* command */
  269
+	NULL,				/* alias */
  270
+	&shellext_fbgrab		/* next */
  271
+};

No commit comments for this range

Something went wrong with that request. Please try again.