OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 301 to Rev 302
    Reverse comparison

Rev 301 → Rev 302

/trunk/kernel/filesys.c
20,16 → 20,13
* OS_fwrite() //write file entry into directory
* BlockRead() //flush changes to directory
*--------------------------------------------------------------------*/
#ifndef WIN32
#include "rtos.h"
#else
#ifdef WIN32
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
#define _LIBC
#endif
#include "rtos.h"
 
#define BLOCK_SIZE 512
#define FILE_NAME_SIZE 40
73,6 → 70,7
};
 
static OS_FileEntry_t rootFileEntry;
static OS_Mutex_t *mutexFilesys;
 
// Public prototypes
#ifndef _FILESYS_
89,12 → 87,94
 
 
/***************** Media Functions Start ***********************/
#ifdef INCLUDE_FLASH
#define FLASH_BASE 1024*128
#define FLASH_BLOCKS 1024*1024*16/BLOCK_SIZE
#define FLASH_OFFSET (FLASH_BASE+FLASH_BLOCKS/8*2)/BLOCK_SIZE
static unsigned char FlashBlockEmpty[FLASH_BLOCKS/8];
static unsigned char FlashBlockUsed[FLASH_BLOCKS/8];
static int FlashOffset;
 
 
//Free unused flash blocks
static int MediaBlockCleanup(void)
{
int i, j, k, count=0;
unsigned char *buf;
 
printf("FlashCleanup\n");
buf = (unsigned char*)malloc(1024*128);
if(buf == NULL)
return 0;
for(j = 1; j < 128; ++j)
{
FlashRead((uint16*)buf, 1024*128*j, 1024*128);
if(j == 1)
{
for(i = 0; i < FLASH_BLOCKS/8; ++i)
FlashBlockEmpty[i] |= ~FlashBlockUsed[i];
memcpy(buf, FlashBlockEmpty, sizeof(FlashBlockEmpty));
memset(FlashBlockUsed, 0xff, sizeof(FlashBlockUsed));
memset(buf+sizeof(FlashBlockEmpty), 0xff, sizeof(FlashBlockUsed));
}
//Erase empty blocks
for(k = 0; k < 256; ++k)
{
i = j*256 + k;
if(FlashBlockEmpty[i >> 3] & (1 << (i & 7)))
{
memset(buf + BLOCK_SIZE*k, 0xff, BLOCK_SIZE);
++count;
}
}
FlashErase(1024*128*j);
FlashWrite((uint16*)buf, 1024*128*j, 1024*128);
}
free(buf);
return count;
}
 
 
int MediaBlockInit(void)
{
FlashRead((uint16*)FlashBlockEmpty, FLASH_BASE, sizeof(FlashBlockEmpty));
FlashRead((uint16*)FlashBlockUsed, FLASH_BASE+4096, sizeof(FlashBlockUsed));
FlashOffset = FLASH_OFFSET;
return FlashBlockEmpty[FlashOffset >> 3] & (1 << (FlashOffset & 7));
}
#endif
 
 
static uint32 MediaBlockMalloc(OS_FILE *file)
{
int i, j;
(void)i; (void)j;
 
if(file->fileEntry.mediaType == FILE_MEDIA_RAM)
return (uint32)malloc(file->fileEntry.blockSize);
else
return (uint32)malloc(file->fileEntry.blockSize); //TODO
#ifdef INCLUDE_FLASH
//Find empty flash block
for(i = FlashOffset; i < FLASH_BLOCKS; ++i)
{
if(FlashBlockEmpty[i >> 3] & (1 << (i & 7)))
{
FlashOffset = i + 1;
FlashBlockEmpty[i >> 3] &= ~(1 << (i & 7));
j = i >> 3;
j &= ~1;
FlashWrite((uint16*)(FlashBlockEmpty + j), FLASH_BASE + j, 2);
return i;
}
}
 
i = MediaBlockCleanup();
if(i == 0)
return 0;
FlashOffset = FLASH_OFFSET;
return MediaBlockMalloc(file);
#else
return 0;
#endif
}
 
 
102,8 → 182,16
{
if(file->fileEntry.mediaType == FILE_MEDIA_RAM)
free((void*)blockIndex);
#ifdef INCLUDE_FLASH
else
free((void*)blockIndex); //TODO
{
int i=blockIndex, j;
FlashBlockUsed[i >> 3] &= ~(1 << (i & 7));
j = i >> 3;
j &= ~1;
FlashWrite((uint16*)(FlashBlockUsed + j), FLASH_BASE + sizeof(FlashBlockEmpty) + j, 2);
}
#endif
}
 
 
111,20 → 199,26
{
if(file->fileEntry.mediaType == FILE_MEDIA_RAM)
file->block = (OS_Block_t*)blockIndex;
#ifdef INCLUDE_FLASH
else
{
if(file->blockLocal == NULL)
file->blockLocal = (OS_Block_t*)malloc(file->fileEntry.blockSize);
file->blockLocal = (OS_Block_t*)malloc(BLOCK_SIZE);
file->block = file->blockLocal;
memcpy(file->block, (void*)blockIndex, file->fileEntry.blockSize); //TODO
FlashRead((uint16*)file->block, blockIndex << 9, BLOCK_SIZE);
}
#endif
}
 
 
static void MediaBlockWrite(OS_FILE *file)
static void MediaBlockWrite(OS_FILE *file, uint32 blockIndex)
{
(void)file;
(void)blockIndex;
#ifdef INCLUDE_FLASH
if(file->fileEntry.mediaType != FILE_MEDIA_RAM)
memcpy((void*)file->blockIndex, file->block, file->fileEntry.blockSize); //TODO
FlashWrite((uint16*)file->block, blockIndex << 9, BLOCK_SIZE);
#endif
}
 
/***************** Media Functions End *************************/
133,6 → 227,8
static void BlockRead(OS_FILE *file, uint32 blockIndex)
{
uint32 blockIndexSave = blockIndex;
 
OS_MutexPend(mutexFilesys);
if(blockIndex == BLOCK_MALLOC)
{
// Get a new block
149,11 → 245,14
if(file->block && file->blockModified)
{
// Write block back to flash or disk
MediaBlockWrite(file);
MediaBlockWrite(file, file->blockIndex);
file->blockModified = 0;
}
if(blockIndex == BLOCK_EOF)
{
OS_MutexPost(mutexFilesys);
return;
}
file->blockIndex = blockIndex;
file->blockOffset = 0;
MediaBlockRead(file, blockIndex);
162,6 → 261,7
memset(file->block, 0xff, file->fileEntry.blockSize);
file->blockModified = 1;
}
OS_MutexPost(mutexFilesys);
}
 
 
196,6 → 296,7
int items, bytes;
uint8 *buf = (uint8*)buffer;
 
OS_MutexPend(mutexFilesys);
file->blockModified = 1;
for(items = 0; items < count; ++items)
{
222,6 → 323,7
file->fileModified = 1;
if(file->fileOffset > file->fileEntry.length)
file->fileEntry.length = file->fileOffset;
OS_MutexPost(mutexFilesys);
return items;
}
 
373,6 → 475,7
if(rootFileEntry.blockIndex == 0)
{
// Mount file system
mutexFilesys = OS_MutexCreate("filesys");
memset(&dir, 0, sizeof(OS_FILE));
dir.fileEntry.blockSize = BLOCK_SIZE;
//dir.fileEntry.mediaType = FILE_MEDIA_FLASH; //Test flash
383,14 → 486,32
rootFileEntry.blockSize = dir.fileEntry.blockSize;
rootFileEntry.isDirectory = 1;
BlockRead(&dir, BLOCK_EOF); //Flush data
#ifdef INCLUDE_FLASH
file = OS_fopen("flash", "w+");
if(file == NULL)
return NULL;
file->fileEntry.isDirectory = 1;
file->fileEntry.mediaType = FILE_MEDIA_FLASH;
file->blockLocal = file->block;
file->block = NULL;
rc = MediaBlockInit();
if(rc == 1)
BlockRead(file, BLOCK_MALLOC);
else
BlockRead(file, FLASH_OFFSET);
file->fileEntry.blockIndex = file->blockIndex;
OS_fclose(file);
#endif
}
 
file = (OS_FILE*)malloc(sizeof(OS_FILE));
if(file == NULL)
return NULL;
OS_MutexPend(mutexFilesys);
if(name[0] == 0 || strcmp(name, "/") == 0)
{
FileOpen(file, NULL, NULL);
OS_MutexPost(mutexFilesys);
return file;
}
if(strcmp(mode, "w") == 0)
401,11 → 522,13
if(rc == -2 || (rc && mode[0] == 'r'))
{
free(file);
OS_MutexPost(mutexFilesys);
return NULL;
}
rc = FileOpen(file, filename, &fileEntry); //Open file
file->fullname[0] = 0;
strncat(file->fullname, name, FULL_NAME_SIZE);
OS_MutexPost(mutexFilesys);
return file;
}
 
420,6 → 543,7
if(file->fileModified)
{
// Write file->fileEntry into parent directory
OS_MutexPend(mutexFilesys);
BlockRead(file, BLOCK_EOF);
rc = FileFindRecursive(&dir, file->fullname, &fileEntry, filename);
if(file->fileEntry.mediaType == FILE_MEDIA_FLASH && rc == 0)
433,6 → 557,7
BlockRead(&dir, BLOCK_EOF); //flush data
if(dir.blockLocal)
free(dir.blockLocal);
OS_MutexPost(mutexFilesys);
}
if(file->blockLocal)
free(file->blockLocal);
460,6 → 585,7
uint32 blockIndex;
char filename[FILE_NAME_SIZE]; //Name without directories
 
OS_MutexPend(mutexFilesys);
rc = FileFindRecursive(&dir, name, &fileEntry, filename);
if(rc == 0)
{
478,6 → 604,7
}
if(dir.blockLocal)
free(dir.blockLocal);
OS_MutexPost(mutexFilesys);
}
 
 
/trunk/kernel/http.c
75,6 → 75,7
void HttpServer(IPSocket *socket)
{
uint8 buf[600];
char filename[80];
int bytes, i, length, len, needFooter;
char *name=NULL, *page=NULL;
const char *header, *header2;
108,7 → 109,15
ptr = strstr(name, " ");
if(ptr)
*ptr = 0;
file = fopen(name, "rb");
strcpy(filename, "/web/");
strncat(filename, name, 60);
file = fopen(filename, "rb");
if(file == NULL)
{
strcpy(filename, "/flash/web/");
strncat(filename, name, 60);
file = fopen(filename, "rb");
}
if(file)
{
if(strstr(name, ".htm"))
/trunk/kernel/tcpip.c
29,28 → 29,6
#include "rtos.h"
#include "tcpip.h"
 
#ifdef WIN32
#undef OS_CriticalBegin
#undef OS_CriticalEnd
#define OS_CriticalBegin() 0
#define OS_CriticalEnd(A)
#define OS_ThreadCreate(A,B,C,D,E) 0
#define OS_ThreadSleep(A)
#define OS_ThreadTime() 0
#define OS_ThreadSelf() 0
#define OS_MutexCreate(A) NULL
#define OS_MutexPend(A)
#define OS_MutexPost(A)
#define OS_MQueueCreate(A,B,C) 0
#define OS_MQueueSend(A,B) 0
#define OS_MQueueGet(A,B,C) 0
#define UartPacketConfig(A,B,C)
#define UartPacketSend(A,B)
#define UartPrintf printf
#define UartPrintfCritical printf
#define Led(A)
#define OS_Job(A,B,C,D) A(B,C,D)
#endif
 
//ETHER FIELD OFFSET LENGTH VALUE
#define ETHERNET_DEST 0 //6
1123,9 → 1101,11
FrameFreeHead = frame;
}
FrameFreeCount = FRAME_COUNT;
#ifndef WIN32
UartPacketConfig(MyPacketGet, PACKET_SIZE, IPMQueue);
if(frameSendFunction == NULL)
IPThread = OS_ThreadCreate("TCP/IP", IPMainThread, NULL, 240, 6000);
#endif
IPDhcp(NULL, 360, 1); //Send DHCP request
}
 
1290,6 → 1270,7
//Rate limit output
if(socket->seq - socket->seqReceived >= 5120)
{
//printf("l(%d,%d,%d) ", socket->seq - socket->seqReceived, socket->seq, socket->seqReceived);
if(self == IPThread || ++tries > 200)
break;
else
1305,6 → 1286,7
socket->sendOffset = 0;
if(socket->frameSend == NULL)
{
//printf("L");
if(self == IPThread || ++tries > 200)
break;
else
1508,7 → 1490,7
{
frame2 = frame;
frame = frame->next;
frame2->timeout -= ticks - ticksPrev2;
frame2->timeout = (short)(frame2->timeout - (ticks - ticksPrev2));
if(--frame2->timeout <= 0)
{
if(IPVerbose)
/trunk/kernel/os_stubs.c
0,0 → 1,71
/*--------------------------------------------------------------------
* TITLE: OS stubs
* AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
* DATE CREATED: 2/18/08
* FILENAME: os_stubs.c
* PROJECT: Plasma CPU core
* COPYRIGHT: Software placed into the public domain by the author.
* Software 'as is' without warranty. Author liable for nothing.
* DESCRIPTION:
*--------------------------------------------------------------------*/
#include <stdlib.h>
#include "plasma.h"
#include "rtos.h"
 
unsigned char *flash;
int beenInit;
 
 
void FlashRead(uint16 *dst, uint32 byteOffset, int bytes)
{
if(beenInit == 0)
{
beenInit = 1;
flash = (unsigned char*)malloc(1024*1024*16);
memset(flash, 0xff, sizeof(flash));
}
memcpy(dst, flash+byteOffset, bytes);
}
 
 
void FlashWrite(uint16 *src, uint32 byteOffset, int bytes)
{
memcpy(flash+byteOffset, src, bytes);
}
 
 
void FlashErase(uint32 byteOffset)
{
memset(flash+byteOffset, 0xff, 1024*128);
}
 
 
//Stub out RTOS functions
void UartPrintfCritical(const char *format, ...) {(void)format;}
uint32 OS_AsmInterruptEnable(uint32 state) {(void)state; return 0;}
void OS_Assert(void) {}
OS_Thread_t *OS_ThreadSelf(void) {return NULL;}
void OS_ThreadSleep(int ticks) {(void)ticks;}
uint32 OS_ThreadTime(void) {return 0;}
OS_Mutex_t *OS_MutexCreate(const char *name) {(void)name; return NULL; }
void OS_MutexDelete(OS_Mutex_t *semaphore) {(void)semaphore;}
void OS_MutexPend(OS_Mutex_t *semaphore) {(void)semaphore;}
void OS_MutexPost(OS_Mutex_t *semaphore) {(void)semaphore;}
 
OS_MQueue_t *OS_MQueueCreate(const char *name,
int messageCount,
int messageBytes)
{(void)name;(void)messageCount;(void)messageBytes; return NULL;}
 
void OS_MQueueDelete(OS_MQueue_t *mQueue) {(void)mQueue;}
 
int OS_MQueueSend(OS_MQueue_t *mQueue, void *message)
{(void)mQueue;(void)message; return 0;}
 
int OS_MQueueGet(OS_MQueue_t *mQueue, void *message, int ticks)
{(void)mQueue;(void)message;(void)ticks; return 0;}
 
void OS_Job(void (*funcPtr)(), void *arg0, void *arg1, void *arg2)
{funcPtr(arg0, arg1, arg2);}
 
 
/trunk/kernel/netutil.c
10,6 → 10,7
* Plasma FTP server and FTP client and TFTP server and client
* and Telnet server.
*--------------------------------------------------------------------*/
#define INCLUDE_FILESYS
#ifdef WIN32
#include <stdio.h>
#include <stdlib.h>
16,19 → 17,9
#include <string.h>
#include <ctype.h>
#define _LIBC
#undef INCLUDE_FILESYS
#define INCLUDE_FILESYS
#else
#define INCLUDE_FILESYS
#endif
#include "rtos.h"
#include "tcpip.h"
#ifdef WIN32
#define UartPrintf printf
#define OS_MQueueCreate(A,B,C) 0
#define OS_MQueueGet(A,B,C) 0
#define OS_ThreadCreate(A,B,C,D,E) 0
#endif
 
 
//******************* FTP Server ************************
537,7 → 528,7
}
if(strncmp(command, "help", 4) == 0)
{
sprintf((char*)bufOut, "Commands: help, exit, cat, cp, ls, mkdir, rm");
sprintf((char*)bufOut, "Commands: help, exit, cat, cp, ls, mkdir, rm, flasherase");
for(i = 0; TelnetFuncList[i].name; ++i)
{
strcat((char*)bufOut, ", ");
678,6 → 669,26
}
return 0;
}
#ifdef INCLUDE_FLASH
else if(strcmp(bufA, "flasherase") == 0)
{
strcpy(bufD, "\r\nErasing");
IPWrite(socket, (uint8*)bufD, strlen(bufD));
IPWriteFlush(socket);
strcpy(bufD, ".");
for(bytes = 1024*128; bytes < 1024*1024*16; bytes += 1024*128)
{
IPWrite(socket, (uint8*)bufD, strlen(bufD));
IPWriteFlush(socket);
FlashErase(bytes);
}
strcpy(bufD, "\r\nMust Reboot\r\n");
IPWrite(socket, (uint8*)bufD, strlen(bufD));
IPWriteFlush(socket);
OS_ThreadSleep(OS_WAIT_FOREVER);
return 0;
}
#endif
return -1;
}
 
/trunk/kernel/rtos.c
905,6 → 905,8
{
jobQueue = OS_MQueueCreate("job", 100, 16);
jobThread = OS_ThreadCreate("job", JobThread, NULL, 150, 4000);
OS_ThreadCreate("job2", JobThread, NULL, 150, 4000);
OS_ThreadCreate("job3", JobThread, NULL, 150, 4000);
}
OS_SemaphorePost(SemaphoreLock);
 
/trunk/kernel/libc.c
205,7 → 205,7
}
 
 
long strtol(const char *s, const char **end, int base)
long strtol(const char *s, char **end, int base)
{
int i;
unsigned long ch, value=0, neg=0;
234,7 → 234,7
value = value * base + ch;
}
if(end)
*end = s - 1;
*end = (char*)s - 1;
if(neg)
value = -(int)value;
return value;
396,9 → 396,9
if(f == 0)
return argc;
if(f == 'd')
*(int*)argv[argc++] = strtol(s, &s, 10);
*(int*)argv[argc++] = strtol(s, (char**)&s, 10);
else if(f == 'x')
*(int*)argv[argc++] = strtol(s, &s, 16);
*(int*)argv[argc++] = strtol(s, (char**)&s, 16);
else if(f == 'c')
*(char*)argv[argc++] = *s++;
else if(f == 's')
/trunk/kernel/math.c
593,6 → 593,7
#ifdef WIN32
#include <math.h>
#undef printf
#undef getch
int printf(const char *, ...);
struct {
char *name;
628,7 → 629,7
printf("%10f %10f %10f %10f %10f\n",
(double)a, (double)b, (double)(a/b), (double)c, (double)(a/b-c));
}
getch();
//getch();
 
for(test = 0; test < 6; ++test)
{
642,7 → 643,7
d = b - c;
printf("%s %10f %10f %10f %10f\n", test_info[test].name, a, b, c, d);
}
getch();
//getch();
}
 
a = FP_ToFloat((long)6.0);
656,7 → 657,7
printf("mult %f %f\n", (double)(a * b), (double)c);
c = FP_Div(a, b);
printf("div %f %f\n", (double)(a / b), (double)c);
getch();
//getch();
 
for(a = (float)-13756.54; a < (float)17400.0; a += (float)64.45)
{
678,12 → 679,12
(double)FP_ToFloat((long)a));
printf(" %f %f %f %f\n", (double)error1, (double)error2,
(double)error3, (double)error4);
if(error5 > 0.001)
getch();
//if(error5 > 0.001)
// getch();
}
}
printf("done.\n");
getch();
//getch();
}
#endif
 
/trunk/kernel/makefile
118,8 → 118,8
$(GCC_MIPS) math.c
$(GCC_MIPS) tcpip.c
$(GCC_MIPS) http.c -DINCLUDE_FILESYS
$(GCC_MIPS) netutil.c
$(GCC_MIPS) filesys.c
$(GCC_MIPS) netutil.c -DINCLUDE_FLASH
$(GCC_MIPS) filesys.c -DINCLUDE_FLASH
$(GCC_MIPS) ethernet.c
$(GCC_MIPS) flash.c
$(GCC_MIPS) -I. ..\app\html.c -DMainThread=HtmlThread
153,8 → 153,9
@$(CC_X86) /c filesys.c
@$(CC_X86) /c libc.c /I..\tools
@$(CC_X86) /c /DSIMULATE_PLASMA ..\tools\etermip.c
@$(CC_X86) /c os_stubs.c
@$(CC_X86) -o testip.exe etermip.obj ..\tools\wpcap.lib \
tcpip.obj http.obj netutil.obj filesys.obj libc.c
tcpip.obj http.obj netutil.obj filesys.obj libc.c os_stubs.c
@echo Try http://plasmb/. Try telnet plasmb. Try ftp plasmb.
testip.exe
 
/trunk/kernel/rtos.h
15,15 → 15,6
// Symmetric Multi-Processing
#define OS_CPU_COUNT 1
 
// Standard C library calls
#define printf UartPrintf
//#define printf UartPrintfPoll
#define scanf UartScanf
#ifndef WIN32
#define malloc(S) OS_HeapMalloc(NULL, S)
#define free(S) OS_HeapFree(S)
#endif
 
// Typedefs
typedef unsigned int uint32;
typedef unsigned short uint16;
41,6 → 32,14
 
/***************** LibC ******************/
#if !defined(_LIBC) && !defined(_CTYPE_DEFINED)
#define printf UartPrintf
//#define printf UartPrintfPoll
#define scanf UartScanf
#ifndef WIN32
#define malloc(S) OS_HeapMalloc(NULL, S)
#define free(S) OS_HeapFree(S)
#endif
 
#ifndef NULL
#define NULL (void*)0
#endif
54,6 → 53,7
#define isupper(c) ('A'<=(c)&&(c)<='Z')
#define isalpha(c) (islower(c)||isupper(c))
#define isalnum(c) (isalpha(c)||isdigit(c))
#undef min
#define min(a,b) ((a)<(b)?(a):(b))
#define strcpy strcpy2 //don't use intrinsic functions
#define strcat strcat2
80,12 → 80,12
int abs(int n);
int rand(void);
void srand(unsigned int seed);
long strtol(const char *s, const char **end, int base);
long strtol(const char *s, char **end, int base);
int atoi(const char *s);
char *itoa(int num, char *dst, int base);
#ifndef NO_ELLIPSIS
int sprintf(char *s, const char *format, ...);
int sscanf(char *s, const char *format, ...);
int sscanf(const char *s, const char *format, ...);
#endif
#ifdef INCLUDE_DUMP
void dump(const unsigned char *data, int length);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.