add missing files not taken with github import
This commit is contained in:
457
tos/vmem_test/sources/bas_printf.c
Normal file
457
tos/vmem_test/sources/bas_printf.c
Normal file
@@ -0,0 +1,457 @@
|
||||
/*
|
||||
* tc.printf.c: A public-domain, minimal printf/sprintf routine that prints
|
||||
* through the putchar() routine. Feel free to use for
|
||||
* anything... -- 7/17/87 Paul Placeway
|
||||
*/
|
||||
/*-
|
||||
* Copyright (c) 1980, 1991 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "MCF5475.h"
|
||||
#include "bas_printf.h"
|
||||
#include "bas_string.h"
|
||||
|
||||
/*
|
||||
* Lexical definitions.
|
||||
*
|
||||
* All lexical space is allocated dynamically.
|
||||
* The eighth/sixteenth bit of characters is used to prevent recognition,
|
||||
* and eventually stripped.
|
||||
*/
|
||||
#define META 0200
|
||||
#define ASCII 0177
|
||||
#define QUOTE ((char) 0200) /* Eighth char bit used for 'ing */
|
||||
#define TRIM 0177 /* Mask to strip quote bit */
|
||||
#define UNDER 0000000 /* No extra bits to do both */
|
||||
#define BOLD 0000000 /* Bold flag */
|
||||
#define STANDOUT META /* Standout flag */
|
||||
#define LITERAL 0000000 /* Literal character flag */
|
||||
#define ATTRIBUTES 0200 /* The bits used for attributes */
|
||||
#define CHAR 0000177 /* Mask to mask out the character */
|
||||
|
||||
#define INF 32766 /* should be bigger than any field to print */
|
||||
|
||||
static char snil[] = "(nil)";
|
||||
|
||||
void xputchar(int c)
|
||||
{
|
||||
__asm__ __volatile__
|
||||
(
|
||||
".extern printf_helper\n\t"
|
||||
"move.b %0,d0\n\t"
|
||||
"bsr printf_helper\n\t"
|
||||
/* output */:
|
||||
/* input */: "r" (c)
|
||||
/* clobber */: "d0","d2","a0","memory"
|
||||
);
|
||||
}
|
||||
|
||||
static void doprnt(void (*addchar)(int), const char *sfmt, va_list ap)
|
||||
{
|
||||
char buf[128];
|
||||
char *bp;
|
||||
const char *f;
|
||||
float flt;
|
||||
long l;
|
||||
unsigned long u;
|
||||
int i;
|
||||
int fmt;
|
||||
unsigned char pad = ' ';
|
||||
int flush_left = 0;
|
||||
int f_width = 0;
|
||||
int prec = INF;
|
||||
int hash = 0;
|
||||
int do_long = 0;
|
||||
int sign = 0;
|
||||
int attributes = 0;
|
||||
|
||||
f = sfmt;
|
||||
for (; *f; f++)
|
||||
{
|
||||
if (*f != '%')
|
||||
{
|
||||
/* then just out the char */
|
||||
(*addchar)((int) (((unsigned char) *f) | attributes));
|
||||
}
|
||||
else
|
||||
{
|
||||
f++; /* skip the % */
|
||||
|
||||
if (*f == '-')
|
||||
{ /* minus: flush left */
|
||||
flush_left = 1;
|
||||
f++;
|
||||
}
|
||||
|
||||
if (*f == '0' || *f == '.')
|
||||
{
|
||||
/* padding with 0 rather than blank */
|
||||
pad = '0';
|
||||
f++;
|
||||
}
|
||||
if (*f == '*')
|
||||
{
|
||||
/* field width */
|
||||
f_width = va_arg(ap, int);
|
||||
f++;
|
||||
}
|
||||
else if (isdigit((unsigned char)*f))
|
||||
{
|
||||
f_width = atoi(f);
|
||||
while (isdigit((unsigned char)*f))
|
||||
f++; /* skip the digits */
|
||||
}
|
||||
|
||||
if (*f == '.')
|
||||
{ /* precision */
|
||||
f++;
|
||||
if (*f == '*')
|
||||
{
|
||||
prec = va_arg(ap, int);
|
||||
f++;
|
||||
}
|
||||
else if (isdigit((unsigned char)*f))
|
||||
{
|
||||
prec = atoi(f);
|
||||
while (isdigit((unsigned char)*f))
|
||||
f++; /* skip the digits */
|
||||
}
|
||||
}
|
||||
|
||||
if (*f == '#')
|
||||
{ /* alternate form */
|
||||
hash = 1;
|
||||
f++;
|
||||
}
|
||||
|
||||
if (*f == 'l')
|
||||
{ /* long format */
|
||||
do_long++;
|
||||
f++;
|
||||
if (*f == 'l')
|
||||
{
|
||||
do_long++;
|
||||
f++;
|
||||
}
|
||||
}
|
||||
|
||||
fmt = (unsigned char) *f;
|
||||
if (fmt != 'S' && fmt != 'Q' && isupper(fmt))
|
||||
{
|
||||
do_long = 1;
|
||||
fmt = tolower(fmt);
|
||||
}
|
||||
bp = buf;
|
||||
switch (fmt)
|
||||
{ /* do the format */
|
||||
case 'd':
|
||||
switch (do_long)
|
||||
{
|
||||
case 0:
|
||||
l = (long) (va_arg(ap, int));
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
l = va_arg(ap, long);
|
||||
break;
|
||||
}
|
||||
|
||||
if (l < 0)
|
||||
{
|
||||
sign = 1;
|
||||
l = -l;
|
||||
}
|
||||
do
|
||||
{
|
||||
*bp++ = (char) (l % 10) + '0';
|
||||
} while ((l /= 10) > 0);
|
||||
if (sign)
|
||||
*bp++ = '-';
|
||||
f_width = f_width - (int) (bp - buf);
|
||||
if (!flush_left)
|
||||
while (f_width-- > 0)
|
||||
(*addchar)((int) (pad | attributes));
|
||||
for (bp--; bp >= buf; bp--)
|
||||
(*addchar)((int) (((unsigned char) *bp) | attributes));
|
||||
if (flush_left)
|
||||
while (f_width-- > 0)
|
||||
(*addchar)((int) (' ' | attributes));
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
/* this is actually more than stupid, but does work for now */
|
||||
flt = (float) (va_arg(ap, double)); /* beware: va_arg() extends float to double! */
|
||||
if (flt < 0)
|
||||
{
|
||||
sign = 1;
|
||||
flt = -flt;
|
||||
}
|
||||
{
|
||||
int quotient, remainder;
|
||||
|
||||
quotient = (int) flt;
|
||||
remainder = (flt - quotient) * 10E5;
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
*bp++ = (char) (remainder % 10) + '0';
|
||||
remainder /= 10;
|
||||
}
|
||||
*bp++ = '.';
|
||||
do
|
||||
{
|
||||
*bp++ = (char) (quotient % 10) + '0';
|
||||
} while ((quotient /= 10) > 0);
|
||||
if (sign)
|
||||
*bp++ = '-';
|
||||
f_width = f_width - (int) (bp - buf);
|
||||
if (!flush_left)
|
||||
while (f_width-- > 0)
|
||||
(*addchar)((int) (pad | attributes));
|
||||
for (bp--; bp >= buf; bp--)
|
||||
(*addchar)((int) (((unsigned char) *bp) | attributes));
|
||||
if (flush_left)
|
||||
while (f_width-- > 0)
|
||||
(*addchar)((int) (' ' | attributes));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
do_long = 1;
|
||||
hash = 1;
|
||||
fmt = 'x';
|
||||
/* no break */
|
||||
case 'o':
|
||||
case 'x':
|
||||
case 'u':
|
||||
switch (do_long)
|
||||
{
|
||||
case 0:
|
||||
u = (unsigned long) (va_arg(ap, unsigned int));
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
u = va_arg(ap, unsigned long);
|
||||
break;
|
||||
}
|
||||
if (fmt == 'u')
|
||||
{ /* unsigned decimal */
|
||||
do
|
||||
{
|
||||
*bp++ = (char) (u % 10) + '0';
|
||||
} while ((u /= 10) > 0);
|
||||
}
|
||||
else if (fmt == 'o')
|
||||
{ /* octal */
|
||||
do
|
||||
{
|
||||
*bp++ = (char) (u % 8) + '0';
|
||||
} while ((u /= 8) > 0);
|
||||
if (hash)
|
||||
*bp++ = '0';
|
||||
}
|
||||
else if (fmt == 'x')
|
||||
{ /* hex */
|
||||
do
|
||||
{
|
||||
i = (int) (u % 16);
|
||||
if (i < 10)
|
||||
*bp++ = i + '0';
|
||||
else
|
||||
*bp++ = i - 10 + 'a';
|
||||
} while ((u /= 16) > 0);
|
||||
if (hash)
|
||||
{
|
||||
*bp++ = 'x';
|
||||
*bp++ = '0';
|
||||
}
|
||||
}
|
||||
i = f_width - (int) (bp - buf);
|
||||
if (!flush_left)
|
||||
while (i-- > 0)
|
||||
(*addchar)((int) (pad | attributes));
|
||||
for (bp--; bp >= buf; bp--)
|
||||
(*addchar)((int) (((unsigned char) *bp) | attributes));
|
||||
if (flush_left)
|
||||
while (i-- > 0)
|
||||
(*addchar)((int) (' ' | attributes));
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
i = va_arg(ap, int);
|
||||
(*addchar)((int) (i | attributes));
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
case 'Q':
|
||||
case 's':
|
||||
case 'q':
|
||||
bp = va_arg(ap, char *);
|
||||
if (!bp)
|
||||
bp = snil;
|
||||
f_width = f_width - strlen((char *) bp);
|
||||
if (!flush_left)
|
||||
while (f_width-- > 0)
|
||||
(*addchar)((int) (pad | attributes));
|
||||
for (i = 0; *bp && i < prec; i++)
|
||||
{
|
||||
if (fmt == 'q' && (*bp & QUOTE))
|
||||
(*addchar)((int) ('\\' | attributes));
|
||||
(*addchar)(
|
||||
(int) (((unsigned char) *bp & TRIM) | attributes));
|
||||
bp++;
|
||||
}
|
||||
if (flush_left)
|
||||
while (f_width-- > 0)
|
||||
(*addchar)((int) (' ' | attributes));
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
attributes = va_arg(ap, int);
|
||||
break;
|
||||
|
||||
case '%':
|
||||
(*addchar)((int) ('%' | attributes));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
flush_left = 0, f_width = 0, prec = INF, hash = 0, do_long = 0;
|
||||
sign = 0;
|
||||
pad = ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static char *xstring, *xestring;
|
||||
|
||||
void xaddchar(int c)
|
||||
{
|
||||
if (xestring == xstring)
|
||||
*xstring = '\0';
|
||||
else
|
||||
*xstring++ = (char) c;
|
||||
}
|
||||
|
||||
int sprintf(char *str, const char *format, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
|
||||
xstring = str;
|
||||
|
||||
doprnt(xaddchar, format, va);
|
||||
va_end(va);
|
||||
*xstring++ = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void xsnprintf(char *str, size_t size, const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
|
||||
xstring = str;
|
||||
xestring = str + size - 1;
|
||||
doprnt(xaddchar, fmt, va);
|
||||
va_end(va);
|
||||
*xstring++ = '\0';
|
||||
}
|
||||
|
||||
void xprintf(const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
doprnt(xputchar, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
void xvprintf(const char *fmt, va_list va)
|
||||
{
|
||||
doprnt(xputchar, fmt, va);
|
||||
}
|
||||
|
||||
void xvsnprintf(char *str, size_t size, const char *fmt, va_list va)
|
||||
{
|
||||
xstring = str;
|
||||
xestring = str + size - 1;
|
||||
doprnt(xaddchar, fmt, va);
|
||||
*xstring++ = '\0';
|
||||
}
|
||||
|
||||
|
||||
void display_progress()
|
||||
{
|
||||
static int _progress_index;
|
||||
char progress_char[] = "|/-\\";
|
||||
|
||||
xputchar(progress_char[_progress_index++ % strlen(progress_char)]);
|
||||
xputchar('\r');
|
||||
}
|
||||
|
||||
void hexdump(volatile uint8_t buffer[], int size)
|
||||
{
|
||||
int i;
|
||||
int line = 0;
|
||||
volatile uint8_t *bp = buffer;
|
||||
|
||||
while (bp < buffer + size) {
|
||||
volatile uint8_t *lbp = bp;
|
||||
|
||||
xprintf("%08x ", line);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
uint8_t c = *lbp++;
|
||||
if (bp + i > buffer + size) {
|
||||
break;
|
||||
}
|
||||
xprintf("%02x ", c);
|
||||
}
|
||||
|
||||
lbp = bp;
|
||||
for (i = 0; i < 16; i++) {
|
||||
volatile int8_t c = *lbp++;
|
||||
|
||||
if (bp + i > buffer + size) {
|
||||
break;
|
||||
}
|
||||
if (c > ' ' && c < '~') {
|
||||
xprintf("%c", c);
|
||||
} else {
|
||||
xprintf(".");
|
||||
}
|
||||
}
|
||||
xprintf("\r\n");
|
||||
|
||||
bp += 16;
|
||||
line += 16;
|
||||
}
|
||||
}
|
||||
156
tos/vmem_test/sources/bas_string.c
Normal file
156
tos/vmem_test/sources/bas_string.c
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* bas_string.c
|
||||
*
|
||||
* This file is part of BaS_gcc.
|
||||
*
|
||||
* BaS_gcc is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* BaS_gcc is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with BaS_gcc. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Created on: 26.02.2013
|
||||
* Author: Markus Fröschle
|
||||
*/
|
||||
|
||||
#include "bas_types.h"
|
||||
#include <stdint.h>
|
||||
#include "bas_string.h"
|
||||
|
||||
void *memcpy(void *dst, const void *src, size_t n)
|
||||
{
|
||||
uint8_t *to = dst;
|
||||
|
||||
while (to < (uint8_t *) dst + n)
|
||||
*to++ = * (uint8_t *) src++;
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
void bzero(void *s, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
((unsigned char *) s)[i] = '\0';
|
||||
}
|
||||
|
||||
void *memset(void *s, int c, size_t n)
|
||||
{
|
||||
uint8_t *dst = s;
|
||||
|
||||
do
|
||||
{
|
||||
*dst++ = c;
|
||||
} while ((dst - (uint8_t *) s) < n);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t max)
|
||||
{
|
||||
int i;
|
||||
int cmp;
|
||||
|
||||
for (i = 0; i < max; i++)
|
||||
{
|
||||
cmp = (* (const char *) s1 - * (const char *) s2);
|
||||
if (cmp != 0) return cmp;
|
||||
}
|
||||
return cmp;
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
int i;
|
||||
int cmp;
|
||||
|
||||
for (i = 0; *s1++ && *s2++; i++)
|
||||
{
|
||||
cmp = (*s1 - *s2);
|
||||
if (cmp != 0) return cmp;
|
||||
}
|
||||
return cmp;
|
||||
}
|
||||
|
||||
int strncmp(const char *s1, const char *s2, size_t max)
|
||||
{
|
||||
int i;
|
||||
int cmp;
|
||||
|
||||
for (i = 0; i < max && *s1++ && *s2++; i++);
|
||||
{
|
||||
cmp = (*s1 - *s2);
|
||||
if (cmp != 0) return cmp;
|
||||
}
|
||||
return cmp;
|
||||
}
|
||||
|
||||
char *strcpy(char *dst, const char *src)
|
||||
{
|
||||
char *ptr = dst;
|
||||
|
||||
while ((*dst++ = *src++) != '\0');
|
||||
return ptr;
|
||||
}
|
||||
|
||||
char *strncpy(char *dst, const char *src, size_t max)
|
||||
{
|
||||
char *ptr = dst;
|
||||
|
||||
while ((*dst++ = *src++) != '\0' && max-- >= 0);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
int atoi(const char *c)
|
||||
{
|
||||
int value = 0;
|
||||
while (isdigit(*c))
|
||||
{
|
||||
value *= 10;
|
||||
value += (int) (*c - '0');
|
||||
c++;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
size_t strlen(const char *s)
|
||||
{
|
||||
const char *start = s;
|
||||
|
||||
while (*s++);
|
||||
|
||||
return s - start - 1;
|
||||
}
|
||||
|
||||
|
||||
char *strcat(char *dst, const char *src)
|
||||
{
|
||||
char *ret = dst;
|
||||
dst = &dst[strlen(dst)];
|
||||
while ((*dst++ = *src++) != '\0');
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *strncat(char *dst, const char *src, size_t max)
|
||||
{
|
||||
size_t i;
|
||||
char *ret = dst;
|
||||
|
||||
dst = &dst[strlen(dst)];
|
||||
for (i = 0; i < max && *src; i++)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
*dst++ = '\0';
|
||||
|
||||
return ret;
|
||||
}
|
||||
38
tos/vmem_test/sources/printf_helper.S
Normal file
38
tos/vmem_test/sources/printf_helper.S
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* printf_helper.S
|
||||
*
|
||||
* assembler trampoline to let printf (compiled -mpcrel) indirectly reference __MBAR
|
||||
*
|
||||
* This file is part of BaS_gcc.
|
||||
*
|
||||
* BaS_gcc is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* BaS_gcc is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with BaS_gcc. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Copyright 2010 - 2012 F. Aschwanden
|
||||
* Copyright 2011 - 2012 V. Riviere
|
||||
* Copyright 2012 - 2025 M. Froeschle
|
||||
*/
|
||||
|
||||
|
||||
.globl printf_helper
|
||||
|
||||
printf_helper:
|
||||
.extern __MBAR
|
||||
|
||||
.wait_txready:
|
||||
move.w __MBAR+0x8604,d2 // PSCSCR0 status register
|
||||
btst #10,d2 // space left in TX fifo?
|
||||
beq.s .wait_txready // no, loop
|
||||
lea __MBAR+0x860C,a0 // PSCSTB0 transmitter buffer register
|
||||
move.b d0,(a0) // send byte
|
||||
rts
|
||||
390
tos/vmem_test/sources/vmem_test.c
Normal file
390
tos/vmem_test/sources/vmem_test.c
Normal file
@@ -0,0 +1,390 @@
|
||||
#include <stdio.h>
|
||||
#include <mint/osbind.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "bas_printf.h"
|
||||
#include "MCF5475.h"
|
||||
#include "driver_vec.h"
|
||||
|
||||
#define FPGA_CONFIG (1 << 2)
|
||||
#define FPGA_CONF_DONE (1 << 5)
|
||||
|
||||
#define SRAM1_START 0xff101000
|
||||
#define SRAM1_END SRAM1_START + 0x1000
|
||||
#define SAFE_STACK SRAM1_END - 4
|
||||
|
||||
#define NOP() __asm__ __volatile__("nop\n\t" : : : "memory")
|
||||
|
||||
#define SYSCLK 132000
|
||||
|
||||
long bas_start = 0xe0000000;
|
||||
extern volatile uint32_t _VRAM[];
|
||||
|
||||
volatile int32_t time, start, end;
|
||||
int i;
|
||||
|
||||
static void wait_pll(void)
|
||||
{
|
||||
int32_t trgt = MCF_SLT0_SCNT - 100000;
|
||||
do
|
||||
{
|
||||
;
|
||||
} while ((* (volatile int16_t *) 0xf0000800 < 0) && MCF_SLT0_SCNT > trgt);
|
||||
}
|
||||
|
||||
static volatile uint8_t *pll_base = (volatile uint8_t *) 0xf0000600;
|
||||
|
||||
static void init_pll(void)
|
||||
{
|
||||
xprintf("FPGA PLL initialization: ");
|
||||
|
||||
wait_pll();
|
||||
* (volatile uint16_t *) (pll_base + 0x48) = 27; /* loopfilter r */
|
||||
|
||||
wait_pll();
|
||||
* (volatile uint16_t *) (pll_base + 0x08) = 1; /* charge pump 1 */
|
||||
|
||||
wait_pll();
|
||||
* (volatile uint16_t *) (pll_base + 0x00) = 12; /* N counter high = 12 */
|
||||
|
||||
wait_pll();
|
||||
* (volatile uint16_t *) (pll_base + 0x40) = 12; /* N counter low = 12 */
|
||||
|
||||
wait_pll();
|
||||
* (volatile uint16_t *) (pll_base + 0x114) = 1; /* ck1 bypass */
|
||||
|
||||
wait_pll();
|
||||
* (volatile uint16_t *) (pll_base + 0x118) = 1; /* ck2 bypass */
|
||||
|
||||
wait_pll();
|
||||
* (volatile uint16_t *) (pll_base + 0x11c) = 1; /* ck3 bypass */
|
||||
|
||||
wait_pll();
|
||||
* (volatile uint16_t *) (pll_base + 0x10) = 1; /* ck0 high = 1 */
|
||||
|
||||
wait_pll();
|
||||
* (volatile uint16_t *) (pll_base + 0x50) = 1; /* ck0 low = 1 */
|
||||
|
||||
wait_pll();
|
||||
* (volatile uint16_t *) (pll_base + 0x144) = 1; /* M odd division */
|
||||
|
||||
wait_pll();
|
||||
* (volatile uint16_t *) (pll_base + 0x44) = 1; /* M low = 1 */
|
||||
|
||||
wait_pll();
|
||||
* (volatile uint16_t *) (pll_base + 0x04) = 145; /* M high = 145 = 146 MHz */
|
||||
|
||||
wait_pll();
|
||||
|
||||
* (volatile uint8_t *) 0xf0000800 = 0; /* set */
|
||||
|
||||
xprintf("finished\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* INIT VIDEO DDR RAM
|
||||
*/
|
||||
static void init_video_ddr(void)
|
||||
{
|
||||
xprintf("init video RAM: ");
|
||||
|
||||
* (volatile uint16_t *) 0xf0000400 = 0xb; /* set cke = 1, cs=1, config = 1 */
|
||||
NOP();
|
||||
|
||||
_VRAM[0] = 0x00050400; /* IPALL */
|
||||
NOP();
|
||||
|
||||
_VRAM[0] = 0x00072000; /* load EMR pll on */
|
||||
NOP();
|
||||
|
||||
_VRAM[0] = 0x00070122; /* load MR: reset pll, cl=2, burst=4lw */
|
||||
NOP();
|
||||
|
||||
_VRAM[0] = 0x00050400; /* IPALL */
|
||||
NOP();
|
||||
|
||||
_VRAM[0] = 0x00060000; /* auto refresh */
|
||||
NOP();
|
||||
|
||||
_VRAM[0] = 0x00060000; /* auto refresh */
|
||||
NOP();
|
||||
|
||||
/* FIXME: what's this? */
|
||||
_VRAM[0] = 0000070022; /* load MR dll on */
|
||||
NOP();
|
||||
|
||||
* (uint32_t *) 0xf0000400 = 0x01070002; /* fifo on, refresh on, ddrcs und cke on, video dac on */
|
||||
|
||||
xprintf("sys_ctr = 0x%08x\r\n", * (uint32_t *) 0xf0000400);
|
||||
xprintf("finished\r\n");
|
||||
}
|
||||
|
||||
void memmove_b(uint8_t *dst, volatile uint8_t *src, size_t size)
|
||||
{
|
||||
while (--size)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
|
||||
void memmove_w(uint16_t *dst, volatile uint16_t *src, size_t size)
|
||||
{
|
||||
size >>= 1;
|
||||
|
||||
while (--size)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
|
||||
void memmove_l(uint32_t *dst, volatile uint32_t *src, size_t size)
|
||||
{
|
||||
size >>= 2;
|
||||
|
||||
while (--size)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void do_tests(void)
|
||||
{
|
||||
// uint32_t version;
|
||||
const int buffer_size = 64;
|
||||
uint8_t buffer[buffer_size * 4];
|
||||
|
||||
xprintf("initialize Firebee video PLL\r\n");
|
||||
init_pll();
|
||||
xprintf("finished\r\n");
|
||||
|
||||
xprintf("initialize video ddr memory\r\n");
|
||||
init_video_ddr();
|
||||
xprintf("finished\r\n");
|
||||
|
||||
#ifdef _NOT_USED_
|
||||
xprintf("try to read Configware version (only works on later configs)\r\n");
|
||||
version = * (uint32_t *) 0xffffffff;
|
||||
|
||||
xprintf("version = 0x%08lx\r\n", version);
|
||||
#endif /* _NOT_USED_ */
|
||||
|
||||
xprintf("try to access Firebee FPGA memory\r\n");
|
||||
|
||||
xprintf("write\r\n");
|
||||
start = MCF_SLT0_SCNT;
|
||||
|
||||
/*
|
||||
* fill 4 lines of video memory with 64 consecutive byte values
|
||||
*/
|
||||
for (i = 0; i < 64; i++)
|
||||
{
|
||||
((uint8_t *) _VRAM)[i] = (uint32_t) i;
|
||||
}
|
||||
end = MCF_SLT0_SCNT;
|
||||
time = (start - end) / (SYSCLK / 1000) / 1000;
|
||||
|
||||
xprintf("finished (took %f seconds).\r\n", time / 1000.0);
|
||||
|
||||
|
||||
/*
|
||||
* read back video memory into local fast ram buffer
|
||||
*/
|
||||
|
||||
xprintf("read\r\n");
|
||||
start = MCF_SLT0_SCNT;
|
||||
|
||||
/*
|
||||
* read byte-wise
|
||||
*/
|
||||
xprintf("byte read\r\n");
|
||||
memmove_b(buffer, (uint8_t *) _VRAM, buffer_size);
|
||||
end = MCF_SLT0_SCNT;
|
||||
time = (start - end) / (SYSCLK / 1000) / 1000;
|
||||
|
||||
xprintf("finished (took %f seconds).\r\n", time / 1000.0);
|
||||
|
||||
hexdump(buffer, 64);
|
||||
|
||||
|
||||
/*
|
||||
* read word-wise
|
||||
*/
|
||||
xprintf("word read\r\n");
|
||||
memmove_w((uint16_t *) buffer, (uint16_t *) _VRAM, buffer_size);
|
||||
end = MCF_SLT0_SCNT;
|
||||
time = (start - end) / (SYSCLK / 1000) / 1000;
|
||||
|
||||
xprintf("finished (took %f seconds).\r\n", time / 1000.0);
|
||||
|
||||
hexdump(buffer, 64);
|
||||
|
||||
/*
|
||||
* read longword-wise
|
||||
*/
|
||||
xprintf("longword read\r\n");
|
||||
memmove_l((uint32_t *) buffer, (uint32_t *) _VRAM, buffer_size);
|
||||
end = MCF_SLT0_SCNT;
|
||||
time = (start - end) / (SYSCLK / 1000) / 1000;
|
||||
|
||||
xprintf("finished (took %f seconds).\r\n", time / 1000.0);
|
||||
|
||||
hexdump(buffer, 64);
|
||||
|
||||
/*
|
||||
* do some Firebee register tests
|
||||
*/
|
||||
|
||||
volatile uint8_t *dbasef = (volatile uint8_t *) 0xffff8200;
|
||||
|
||||
xprintf("dbasef = 0x%02x\r\n", *dbasef);
|
||||
*dbasef = 0x0;
|
||||
xprintf("dbasef after clearing it = 0x%02x\r\n", *dbasef);
|
||||
|
||||
volatile uint8_t *dbaseh = (volatile uint8_t *) 0xffff8201;
|
||||
|
||||
xprintf("dbaseh = 0x%02x\r\n", *dbaseh);
|
||||
*dbaseh = 0x0;
|
||||
xprintf("dbaseh after clearing it = 0x%02x\r\n", *dbaseh);
|
||||
|
||||
volatile uint8_t *dbasel = (volatile uint8_t *) 0xffff8203;
|
||||
xprintf("dbasel = 0x%02x\r\n", *dbasel);
|
||||
*dbasel = 0x0;
|
||||
xprintf("dbasel after clearing it = 0x%02x\r\n", *dbasel);
|
||||
|
||||
volatile uint8_t *dbaselow = (volatile uint8_t *) 0xffff820d;
|
||||
xprintf("dbaselow = 0x%02x\r\n", *dbaselow);
|
||||
*dbaselow = 0x0;
|
||||
xprintf("dbaselow after clearing it = 0x%02x\r\n", *dbaselow);
|
||||
|
||||
volatile uint16_t *linewidth = (volatile uint16_t *) 0xffff820e;
|
||||
xprintf("linewidth = 0x%04x\r\n", *linewidth);
|
||||
*linewidth = 0x0;
|
||||
xprintf("linewidth after clearing it = 0x%04x\r\n", *linewidth);
|
||||
*linewidth = 0x1234;
|
||||
xprintf("linewidth after setting it to 0x1234 = 0x%04x\r\n", *linewidth);
|
||||
|
||||
volatile uint16_t *vwrap = (volatile uint16_t *) 0xffff8210;
|
||||
xprintf("VWRAP = 0x%04x\r\n", *vwrap);
|
||||
*vwrap = 0;
|
||||
xprintf("VWRAP after clearing it = 0x%04x\r\n", *vwrap);
|
||||
*vwrap = 0x1234;
|
||||
xprintf("VWRAP after setting it to 0x1234 = 0x%04x\r\n", *vwrap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wait_for_jtag(void)
|
||||
{
|
||||
long i;
|
||||
|
||||
/* set supervisor stack to end of SRAM1 */
|
||||
__asm__ __volatile__ (
|
||||
" move #0x2700,sr\n\t" /* disable interrupts */
|
||||
" move.l %[stack],d0\n\t" /* 4KB on-chip core SRAM1 */
|
||||
" move.l d0,sp\n\t" /* set stack pointer */
|
||||
:
|
||||
: [stack] "i" (SAFE_STACK)
|
||||
: "d0", "cc" /* clobber */
|
||||
);
|
||||
|
||||
MCF_EPORT_EPIER = 0x0; /* disable EPORT interrupts */
|
||||
MCF_INTC_IMRL = 0xffffffff;
|
||||
MCF_INTC_IMRH = 0xffffffff; /* disable interrupt controller */
|
||||
|
||||
MCF_MMU_MMUCR &= ~MCF_MMU_MMUCR_EN; /* disable MMU */
|
||||
|
||||
xprintf("relocated supervisor stack, disabled interrupts and disabled MMU\r\n");
|
||||
|
||||
/*
|
||||
* configure FEC1L port directions to enable external JTAG configuration download to FPGA
|
||||
*/
|
||||
MCF_GPIO_PDDR_FEC1L = 0 |
|
||||
MCF_GPIO_PDDR_FEC1L_PDDR_FEC1L4; /* bit 4 = LED => output */
|
||||
/* all other bits = input */
|
||||
|
||||
/*
|
||||
* configure DSPI_CS3 as GPIO input to avoid the MCU driving against the FPGA blink
|
||||
*/
|
||||
MCF_PAD_PAR_DSPI &= ~MCF_PAD_PAR_DSPI_PAR_CS3(MCF_PAD_PAR_DSPI_PAR_CS3_DSPICS3);
|
||||
/*
|
||||
* now that GPIO ports have been switched to input, we can poll for FPGA config
|
||||
* started from the JTAG interface (CONF_DONE goes low) and finish (CONF_DONE goes high)
|
||||
*/
|
||||
xprintf("waiting for JTAG configuration start\r\n");
|
||||
while ((MCF_GPIO_PPDSDR_FEC1L & FPGA_CONF_DONE)); /* wait for JTAG config load started */
|
||||
|
||||
xprintf("waiting for JTAG configuration to finish\r\n");
|
||||
while (!(MCF_GPIO_PPDSDR_FEC1L & FPGA_CONF_DONE)); /* wait for JTAG config load finished */
|
||||
|
||||
xprintf("JTAG configuration finished.\r\n");
|
||||
|
||||
/* wait */
|
||||
xprintf("wait a little to let things settle...\r\n");
|
||||
for (i = 0; i < 100000L; i++);
|
||||
|
||||
xprintf("disable caches\r\n");
|
||||
__asm__ __volatile(
|
||||
"move.l #0x01000000,d0 \r\n"
|
||||
"movec d0,CACR \r\n"
|
||||
: /* no output */
|
||||
: /* no input */
|
||||
: "d0", "memory");
|
||||
|
||||
xprintf("init FPGA PLLs\r\n");
|
||||
init_pll();
|
||||
|
||||
xprintf("init video DDR RAM\r\n");
|
||||
init_video_ddr();
|
||||
|
||||
/* begin of tests */
|
||||
|
||||
do_tests();
|
||||
|
||||
xprintf("wait a little to let things settle...\r\n");
|
||||
for (i = 0; i < 100000L; i++);
|
||||
|
||||
xprintf("INFO: endless loop now. Press reset to reboot\r\n");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("FPGA JTAG configuration support\r\n");
|
||||
printf("test FPGA DDR RAM controller\r\n");
|
||||
printf("\xbd 2014 M. F\x94schle\r\n");
|
||||
|
||||
printf("You may now savely load a new FPGA configuration through the JTAG interface\r\n"
|
||||
"and your Firebee will reboot once finished using that new configuration.\r\n");
|
||||
if (argc == 2)
|
||||
{
|
||||
/*
|
||||
* we got an argument. This is supposed to be the address that we need to jump to after JTAG
|
||||
* configuration has been finished. Meant to support BaS in RAM testing
|
||||
*/
|
||||
char *addr_str = argv[1];
|
||||
char *addr = NULL;
|
||||
char *end = NULL;
|
||||
|
||||
addr = (char *) strtol(addr_str, &end, 16);
|
||||
if (addr != NULL && addr <= (char *) 0xe0000000 && addr >= (char *) 0x10000000)
|
||||
{
|
||||
/*
|
||||
* seems to be a valid address
|
||||
*/
|
||||
bas_start = (long) addr;
|
||||
|
||||
printf("BaS start address set to %p\r\n", (void *) bas_start);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\r\nNote: BaS start address %p not valid. Stick to %p.\r\n", addr, (void *) bas_start);
|
||||
}
|
||||
}
|
||||
Supexec(wait_for_jtag);
|
||||
|
||||
return 0; /* just to make the compiler happy, we will never return */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user