Line 10... |
Line 10... |
* Dynamic Link Library
|
* Dynamic Link Library
|
*--------------------------------------------------------------------*/
|
*--------------------------------------------------------------------*/
|
#ifndef __DLL_H__
|
#ifndef __DLL_H__
|
#define __DLL_H__
|
#define __DLL_H__
|
|
|
#define INCLUDE_FILESYS
|
|
#include "rtos.h"
|
#include "rtos.h"
|
#include "tcpip.h"
|
#include "tcpip.h"
|
|
|
typedef void *(*DllFunc)();
|
typedef void *(*DllFunc)();
|
|
|
Line 22... |
Line 21... |
#ifdef DLL_SETUP
|
#ifdef DLL_SETUP
|
|
|
void *DllDummy(void) { printf("Dummy"); return NULL; }
|
void *DllDummy(void) { printf("Dummy"); return NULL; }
|
|
|
const DllFunc DllFuncList[] = {
|
const DllFunc DllFuncList[] = {
|
|
(DllFunc)ConsolePrintf,
|
|
(DllFunc)ConsoleScanf,
|
|
(DllFunc)ConsoleKbhit,
|
|
(DllFunc)ConsoleGetch,
|
(DllFunc)strcpy,
|
(DllFunc)strcpy,
|
(DllFunc)strncpy,
|
(DllFunc)strncpy,
|
(DllFunc)strcat,
|
(DllFunc)strcat,
|
(DllFunc)strncat,
|
(DllFunc)strncat,
|
(DllFunc)strcmp,
|
(DllFunc)strcmp,
|
Line 106... |
Line 109... |
(DllFunc)OS_InterruptRegister,
|
(DllFunc)OS_InterruptRegister,
|
(DllFunc)OS_InterruptStatus,
|
(DllFunc)OS_InterruptStatus,
|
(DllFunc)OS_InterruptMaskSet,
|
(DllFunc)OS_InterruptMaskSet,
|
(DllFunc)OS_InterruptMaskClear,
|
(DllFunc)OS_InterruptMaskClear,
|
(DllFunc)UartPrintf,
|
(DllFunc)UartPrintf,
|
(DllFunc)UartPrintfPoll,
|
(DllFunc)UartPrintfCritical,
|
(DllFunc)UartPrintfCritical,
|
(DllFunc)UartPrintfCritical,
|
(DllFunc)UartScanf,
|
(DllFunc)UartScanf,
|
(DllFunc)OS_puts,
|
(DllFunc)OS_puts,
|
(DllFunc)OS_getch,
|
(DllFunc)OS_getch,
|
(DllFunc)OS_kbhit,
|
(DllFunc)OS_kbhit,
|
(DllFunc)Led,
|
(DllFunc)Led,
|
|
#ifndef WIN32
|
|
(DllFunc)__negsf2,
|
|
(DllFunc)__addsf3,
|
|
(DllFunc)__subsf3,
|
|
(DllFunc)__mulsf3,
|
|
(DllFunc)__divsf3,
|
|
(DllFunc)__fixsfsi,
|
|
(DllFunc)__floatsisf,
|
|
#else
|
|
DllDummy,
|
|
DllDummy,
|
|
DllDummy,
|
|
DllDummy,
|
|
DllDummy,
|
|
DllDummy,
|
|
DllDummy,
|
|
#endif
|
(DllFunc)FP_Sqrt,
|
(DllFunc)FP_Sqrt,
|
(DllFunc)FP_Cos,
|
(DllFunc)FP_Cos,
|
(DllFunc)FP_Sin,
|
(DllFunc)FP_Sin,
|
(DllFunc)FP_Atan,
|
(DllFunc)FP_Atan,
|
(DllFunc)FP_Atan2,
|
(DllFunc)FP_Atan2,
|
(DllFunc)FP_Exp,
|
(DllFunc)FP_Exp,
|
(DllFunc)FP_Log,
|
(DllFunc)FP_Log,
|
(DllFunc)FP_Pow,
|
(DllFunc)FP_Pow,
|
#ifdef INCLUDE_FILESYS
|
#ifndef EXCLUDE_FILESYS
|
(DllFunc)OS_fopen,
|
(DllFunc)OS_fopen,
|
(DllFunc)OS_fclose,
|
(DllFunc)OS_fclose,
|
(DllFunc)OS_fread,
|
(DllFunc)OS_fread,
|
(DllFunc)OS_fwrite,
|
(DllFunc)OS_fwrite,
|
(DllFunc)OS_fseek,
|
(DllFunc)OS_fseek,
|
(DllFunc)OS_fmkdir,
|
(DllFunc)OS_fmkdir,
|
(DllFunc)OS_fdir,
|
(DllFunc)OS_fdir,
|
(DllFunc)OS_fdelete,
|
(DllFunc)OS_fdelete,
|
#else //INCLUDE_FILESYS
|
#else //EXCLUDE_FILESYS
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
DllDummy,
|
#endif //INCLUDE_FILESYS
|
#endif //EXCLUDE_FILESYS
|
#ifndef WIN32
|
#ifndef EXCLUDE_FLASH
|
(DllFunc)FlashRead,
|
(DllFunc)FlashRead,
|
(DllFunc)FlashWrite,
|
(DllFunc)FlashWrite,
|
(DllFunc)FlashErase,
|
(DllFunc)FlashErase,
|
#else //WIN32
|
#else //WIN32
|
DllDummy,
|
DllDummy,
|
Line 157... |
Line 177... |
(DllFunc)IPRead,
|
(DllFunc)IPRead,
|
(DllFunc)IPClose,
|
(DllFunc)IPClose,
|
(DllFunc)IPPrintf,
|
(DllFunc)IPPrintf,
|
(DllFunc)IPResolve,
|
(DllFunc)IPResolve,
|
(DllFunc)IPAddressSelf,
|
(DllFunc)IPAddressSelf,
|
(DllFunc)IPNameValue
|
(DllFunc)IPNameValue,
|
|
DllDummy,
|
|
DllDummy
|
};
|
};
|
|
|
#endif //DLL_SETUP
|
#endif //DLL_SETUP
|
|
|
// Included by DLL to call OS functions via array of function pointers
|
// Included by DLL to call OS functions via array of function pointers
|
#if defined(DLL_CALL) || !defined(DLL_SETUP)
|
#if defined(DLL_CALL) || !defined(DLL_SETUP)
|
|
|
enum {
|
enum {
|
|
ENUM_ConsolePrintf,
|
|
ENUM_ConsoleScanf,
|
|
ENUM_ConsoleKbhit,
|
|
ENUM_ConsoleGetch,
|
ENUM_strcpy,
|
ENUM_strcpy,
|
ENUM_strncpy,
|
ENUM_strncpy,
|
ENUM_strcat,
|
ENUM_strcat,
|
ENUM_strncat,
|
ENUM_strncat,
|
ENUM_strcmp,
|
ENUM_strcmp,
|
Line 241... |
Line 267... |
ENUM_UartScanf,
|
ENUM_UartScanf,
|
ENUM_OS_puts,
|
ENUM_OS_puts,
|
ENUM_OS_getch,
|
ENUM_OS_getch,
|
ENUM_OS_kbhit,
|
ENUM_OS_kbhit,
|
ENUM_Led,
|
ENUM_Led,
|
|
ENUM_NEGSF2,
|
|
ENUM_ADDSF3,
|
|
ENUM_SUBSF3,
|
|
ENUM_MULSF3,
|
|
ENUM_DIVSF3,
|
|
ENUM_FIXSFSI,
|
|
ENUM_FLOATSISF,
|
ENUM_FP_Sqrt,
|
ENUM_FP_Sqrt,
|
ENUM_FP_Cos,
|
ENUM_FP_Cos,
|
ENUM_FP_Sin,
|
ENUM_FP_Sin,
|
ENUM_FP_Atan,
|
ENUM_FP_Atan,
|
ENUM_FP_Atan2,
|
ENUM_FP_Atan2,
|
Line 268... |
Line 301... |
ENUM_IPRead,
|
ENUM_IPRead,
|
ENUM_IPClose,
|
ENUM_IPClose,
|
ENUM_IPPrintf,
|
ENUM_IPPrintf,
|
ENUM_IPResolve,
|
ENUM_IPResolve,
|
ENUM_IPAddressSelf,
|
ENUM_IPAddressSelf,
|
ENUM_IPNameValue
|
ENUM_IPNameValue,
|
|
ENUM_USER0,
|
|
ENUM_USER1,
|
|
ARGV_SOCKET = -2
|
};
|
};
|
|
|
extern const DllFunc *DllF;
|
extern const DllFunc *DllF;
|
|
|
#undef strcpy
|
#undef strcpy
|
|
#undef strncpy
|
#undef strcat
|
#undef strcat
|
#undef strncat
|
#undef strncat
|
#undef strcmp
|
#undef strcmp
|
|
#undef strncmp
|
#undef strlen
|
#undef strlen
|
#undef memcpy
|
#undef memcpy
|
#undef memcmp
|
#undef memcmp
|
|
#undef memmove
|
#undef memset
|
#undef memset
|
#undef abs
|
#undef abs
|
#undef atoi
|
#undef atoi
|
|
#undef itoa
|
|
#undef srand
|
|
#undef rand
|
|
#undef sprintf
|
|
#undef sscanf
|
|
#undef strstr
|
|
#undef strtol
|
|
#undef scanf
|
|
#undef printf
|
|
|
|
#define printf (int)DllF[ENUM_ConsolePrintf]
|
|
#define scanf (int)DllF[ENUM_ConsoleScanf]
|
|
#define kbhit (int)DllF[ENUM_ConsoleKbhit]
|
|
#define getch (int)DllF[ENUM_ConsoleGetch]
|
#define strcpy DllF[ENUM_strcpy]
|
#define strcpy DllF[ENUM_strcpy]
|
#define strncpy DllF[ENUM_strncpy]
|
#define strncpy DllF[ENUM_strncpy]
|
#define strcat DllF[ENUM_strcat]
|
#define strcat DllF[ENUM_strcat]
|
#define strncat DllF[ENUM_strncat]
|
#define strncat DllF[ENUM_strncat]
|
#define strcmp (int)DllF[ENUM_strcmp]
|
#define strcmp (int)DllF[ENUM_strcmp]
|
#define strncmp (int)DllF[ENUM_strncmp]
|
#define strncmp (int)DllF[ENUM_strncmp]
|
#define strstr DllF[ENUM_strstr]
|
#define strstr (char*)DllF[ENUM_strstr]
|
#define strlen (int)DllF[ENUM_strlen]
|
#define strlen (int)DllF[ENUM_strlen]
|
#define memcpy DllF[ENUM_memcpy]
|
#define memcpy DllF[ENUM_memcpy]
|
#define memmove DllF[ENUM_memmove]
|
#define memmove DllF[ENUM_memmove]
|
#define memcmp (int)DllF[ENUM_memcmp]
|
#define memcmp (int)DllF[ENUM_memcmp]
|
#define memset DllF[ENUM_memset]
|
#define memset DllF[ENUM_memset]
|
#define abs (int)DllF[ENUM_abs]
|
#define abs (int)DllF[ENUM_abs]
|
#define rand (int)DllF[ENUM_rand]
|
#define rand (unsigned int)DllF[ENUM_rand]
|
#define srand DllF[ENUM_srand]
|
#define srand DllF[ENUM_srand]
|
#define strtol (int)DllF[ENUM_strtol]
|
#define strtol (int)DllF[ENUM_strtol]
|
#define atoi (int)DllF[ENUM_atoi]
|
#define atoi (int)DllF[ENUM_atoi]
|
#define itoa DllF[ENUM_itoa]
|
#define itoa DllF[ENUM_itoa]
|
#define sprintf DllF[ENUM_sprintf]
|
#define sprintf (int)DllF[ENUM_sprintf]
|
#define sscanf DllF[ENUM_sscanf]
|
#define sscanf (int)DllF[ENUM_sscanf]
|
#define dump DllF[ENUM_dump]
|
#define dump DllF[ENUM_dump]
|
#define qsort DllF[ENUM_qsort]
|
#define qsort DllF[ENUM_qsort]
|
#define bsearch DllF[ENUM_bsearch]
|
#define bsearch DllF[ENUM_bsearch]
|
#define mktime DllF[ENUM_mktime]
|
#define mktime DllF[ENUM_mktime]
|
#define gmtime_r DllF[ENUM_gmtime_r]
|
#define gmtime_r DllF[ENUM_gmtime_r]
|
Line 322... |
Line 374... |
#define OS_HeapRegister DllF[ENUM_OS_HeapRegister]
|
#define OS_HeapRegister DllF[ENUM_OS_HeapRegister]
|
#define OS_ThreadCreate DllF[ENUM_OS_ThreadCreate]
|
#define OS_ThreadCreate DllF[ENUM_OS_ThreadCreate]
|
#define OS_ThreadExit DllF[ENUM_OS_ThreadExit]
|
#define OS_ThreadExit DllF[ENUM_OS_ThreadExit]
|
#define OS_ThreadSelf DllF[ENUM_OS_ThreadSelf]
|
#define OS_ThreadSelf DllF[ENUM_OS_ThreadSelf]
|
#define OS_ThreadSleep DllF[ENUM_OS_ThreadSleep]
|
#define OS_ThreadSleep DllF[ENUM_OS_ThreadSleep]
|
#define OS_ThreadTime DllF[ENUM_OS_ThreadTime]
|
#define OS_ThreadTime (int)DllF[ENUM_OS_ThreadTime]
|
#define OS_ThreadInfoSet DllF[ENUM_OS_ThreadInfoSet]
|
#define OS_ThreadInfoSet DllF[ENUM_OS_ThreadInfoSet]
|
#define OS_ThreadInfoGet DllF[ENUM_OS_ThreadInfoGet]
|
#define OS_ThreadInfoGet DllF[ENUM_OS_ThreadInfoGet]
|
#define OS_ThreadPriorityGet (int)DllF[ENUM_OS_ThreadPriorityGet]
|
#define OS_ThreadPriorityGet (int)DllF[ENUM_OS_ThreadPriorityGet]
|
#define OS_ThreadPrioritySet DllF[ENUM_OS_ThreadPrioritySet]
|
#define OS_ThreadPrioritySet DllF[ENUM_OS_ThreadPrioritySet]
|
#define OS_ThreadProcessId DllF[ENUM_OS_ThreadProcessId]
|
#define OS_ThreadProcessId DllF[ENUM_OS_ThreadProcessId]
|
Line 370... |
Line 422... |
#define FP_Log (float)(int)DllF[ENUM_FP_Log]
|
#define FP_Log (float)(int)DllF[ENUM_FP_Log]
|
#define FP_Pow (float)(int)DllF[ENUM_FP_Pow]
|
#define FP_Pow (float)(int)DllF[ENUM_FP_Pow]
|
#define OS_fopen DllF[ENUM_OS_fopen]
|
#define OS_fopen DllF[ENUM_OS_fopen]
|
#define OS_fclose DllF[ENUM_OS_fclose]
|
#define OS_fclose DllF[ENUM_OS_fclose]
|
#define OS_fread (int)DllF[ENUM_OS_fread]
|
#define OS_fread (int)DllF[ENUM_OS_fread]
|
#define OS_fwrite DllF[ENUM_OS_fwrite]
|
#define OS_fwrite (int)DllF[ENUM_OS_fwrite]
|
#define OS_fseek DllF[ENUM_OS_fseek]
|
#define OS_fseek (int)DllF[ENUM_OS_fseek]
|
#define OS_fmkdir DllF[ENUM_OS_fmkdir]
|
#define OS_fmkdir DllF[ENUM_OS_fmkdir]
|
#define OS_fdir DllF[ENUM_OS_fdir]
|
#define OS_fdir DllF[ENUM_OS_fdir]
|
#define OS_fdelete DllF[ENUM_OS_fdelete]
|
#define OS_fdelete DllF[ENUM_OS_fdelete]
|
#define FlashRead DllF[ENUM_FlashRead]
|
#define FlashRead DllF[ENUM_FlashRead]
|
#define FlashWrite DllF[ENUM_FlashWrite]
|
#define FlashWrite DllF[ENUM_FlashWrite]
|
Line 383... |
Line 435... |
#define IPOpen DllF[ENUM_IPOpen]
|
#define IPOpen DllF[ENUM_IPOpen]
|
#define IPWriteFlush DllF[ENUM_IPWriteFlush]
|
#define IPWriteFlush DllF[ENUM_IPWriteFlush]
|
#define IPWrite (int)DllF[ENUM_IPWrite]
|
#define IPWrite (int)DllF[ENUM_IPWrite]
|
#define IPRead (int)DllF[ENUM_IPRead]
|
#define IPRead (int)DllF[ENUM_IPRead]
|
#define IPClose DllF[ENUM_IPClose]
|
#define IPClose DllF[ENUM_IPClose]
|
#define IPPrintf DllF[ENUM_IPPrintf]
|
#define IPPrintf (int)DllF[ENUM_IPPrintf]
|
#define IPResolve DllF[ENUM_IPResolve]
|
#define IPResolve DllF[ENUM_IPResolve]
|
#define IPAddressSelf (int)DllF[ENUM_IPAddressSelf]
|
#define IPAddressSelf (int)DllF[ENUM_IPAddressSelf]
|
#define IPNameValue DllF[ENUM_IPNameValue]
|
#define IPNameValue DllF[ENUM_IPNameValue]
|
|
#define time(P) OS_ThreadTime()
|
|
|
#endif //DLL_CALL
|
#endif //DLL_CALL
|
|
|
|
|
#if defined(DLL_SETUP) && defined(DLL_CALL)
|
#if defined(DLL_SETUP) && defined(DLL_CALL)
|
Line 401... |
Line 454... |
|
|
|
|
// Included by DLL to initialize the DLL
|
// Included by DLL to initialize the DLL
|
#if defined(DLL_ENTRY) && !defined(NO_DLL_ENTRY)
|
#if defined(DLL_ENTRY) && !defined(NO_DLL_ENTRY)
|
const DllFunc *DllF; //array of function pointers
|
const DllFunc *DllF; //array of function pointers
|
extern void *__bss_start;
|
int main(int argc, char *argv[]);
|
extern void *_end;
|
|
void Start(IPSocket *socket, char *argv[]);
|
|
|
|
//Must be first function in file
|
//Must be first function in file
|
void *__start(DllFunc *DllFuncList)
|
int __start(int argc, char *argv[])
|
{
|
{
|
int *bss;
|
extern void *__bss_start;
|
if(DllFuncList == NULL)
|
extern void *_end;
|
return (void*)__start; //address where DLL should be loaded
|
int *bss = (int*)&__bss_start;
|
for(bss = (int*)&__bss_start; bss < (int*)&_end; ++bss)
|
|
*bss = 0;
|
if(bss == (int*)DllF)
|
DllF = DllFuncList;
|
++bss;
|
return (void*)Start;
|
while(bss < (int*)&_end)
|
|
*bss++ = 0;
|
|
DllF = (DllFunc*)argv[-1];
|
|
return main(argc, argv);
|
}
|
}
|
|
|
|
#ifdef INCLUDE_MATH
|
|
typedef float (*DllFloat)(float);
|
|
typedef float (*DllFloat2)(float,float);
|
|
typedef long (*DllFloat3)(float);
|
|
float __negsf2(float a) {return ((DllFloat)DllF[ENUM_NEGSF2])(a);}
|
|
float __addsf3(float a,float b) {return ((DllFloat2)DllF[ENUM_ADDSF3])(a,b);}
|
|
float __subsf3(float a,float b) {return ((DllFloat2)DllF[ENUM_SUBSF3])(a,b);}
|
|
float __mulsf3(float a,float b) {return ((DllFloat2)DllF[ENUM_MULSF3])(a,b);}
|
|
float __divsf3(float a,float b) {return ((DllFloat2)DllF[ENUM_DIVSF3])(a,b);}
|
|
long __fixsfsi(float a) {return ((DllFloat3)DllF[ENUM_FIXSFSI])(a);}
|
|
float __floatsisf(long a) {return ((DllFloat)DllF[ENUM_FLOATSISF])(a);}
|
|
#endif
|
|
|
#endif //DLL_ENTRY
|
#endif //DLL_ENTRY
|
|
|
|
|
#ifdef DLL_STRINGS
|
#ifdef DLL_STRINGS
|
const char * const DllStrings[] = {
|
const char * const DllStrings[] = {
|
|
"printf",
|
|
"scanf",
|
|
"kbhit",
|
|
"getch",
|
"strcpy",
|
"strcpy",
|
"strncpy",
|
"strncpy",
|
"strcat",
|
"strcat",
|
"strncat",
|
"strncat",
|
"strcmp",
|
"strcmp",
|
Line 488... |
Line 560... |
"OS_TimerStop",
|
"OS_TimerStop",
|
"OS_InterruptRegister",
|
"OS_InterruptRegister",
|
"OS_InterruptStatus",
|
"OS_InterruptStatus",
|
"OS_InterruptMaskSet",
|
"OS_InterruptMaskSet",
|
"OS_InterruptMaskClear",
|
"OS_InterruptMaskClear",
|
"printf", //"UartPrintf",
|
"UartPrintf",
|
"UartPrintfPoll",
|
"UartPrintfPoll",
|
"UartPrintfCritical",
|
"UartPrintfCritical",
|
"scanf", //"UartScanf",
|
"UartScanf",
|
"OS_puts",
|
"OS_puts",
|
"OS_getch",
|
"OS_getch",
|
"OS_kbhit",
|
"OS_kbhit",
|
"Led",
|
"Led",
|
|
"FP_Neg",
|
|
"FP_Add",
|
|
"FP_Sub",
|
|
"FP_Mult",
|
|
"FP_Div",
|
|
"FP_ToInt",
|
|
"FP_ToLong",
|
"FP_Sqrt",
|
"FP_Sqrt",
|
"FP_Cos",
|
"FP_Cos",
|
"FP_Sin",
|
"FP_Sin",
|
"FP_Atan",
|
"FP_Atan",
|
"FP_Atan2",
|
"FP_Atan2",
|