📄 demo.c
字号:
/*************************************************************************/
/* */
/* Copyright (c) 1993 Accelerated Technology, Inc. */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are governed */
/* by the license agreement. The recipient of this software implicitly */
/* accepts the terms of the license. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* demo.c PLUS/MNT */
/* VERSION 1.1 */
/* COMPONENT */
/* */
/* */
/* */
/* DESCRIPTION */
/* */
/* Demo routines that exercise Nucleus PLUS features. */
/* */
/* AUTHOR */
/* */
/* */
/* */
/* DATA STRUCTURES */
/* */
/* */
/* */
/* FUNCTIONS */
/* */
/* Application_Initialize *
/* task_0 */
/* task_1 */
/* */
/* */
/* */
/* DEPENDENCIES */
/* */
/* stdio.h Service functions */
/* windows.h Service functions */
/* string.h Service functions */
/* hardware.h Hardware functions */
/* nucleus.h Nucleus PLUS functions */
/* */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* B. Haggerty 03-12-1997 Released MNT Version 1.0 */
/* B. Haggerty 08-11-1997 Released MNT Version 1.1 */
/* R. Smith 02-04-1998 Released MNT LV Demo */
/* */
/*************************************************************************/
//#include <stdio.h>
//#include <windows.h>
//#include <string.h>
#include "hardware.h"
#include "Nucleus.h"
#include "kvm/main.h"
#include "kvm/stdlib.h"
/* Define Application data structures. */
NU_TASK Task_0;
NU_TASK Task_1; /* LV limited to 2 tasks */
NU_TASK Task_2;
NU_QUEUE Queue_0; /* LV limited to 1 queue */
NU_MEMORY_POOL System_Memory;
/* Allocate global counters. */
UNSIGNED Task_Time;
UNSIGNED Task_1_messages_received;
UNSIGNED Task_1_invalid_messages;
UNSIGNED Task_0_messages_sent;
/* Define prototypes for function references. */
void task_0(UNSIGNED, void *);
void task_1(UNSIGNED, void *);
//void task_2(UNSIGNED, void *);
#define STACK_SIZE (MINSTACK+40000)
extern NU_QUEUE UART_Queue;
/* screen output handle for apl */
extern HANDLE Con_Apl;
extern void ERC_System_Error();
/* Define the Application_Initialize routine that determines the */
/* initial Nucleus PLUS application environment. */
void Application_Initialize(void *first_available_memory)
{
void *pointer;
void (*oldlisr)(int);
STATUS sts;
/* Create a system memory pool that will be used to allocate task stacks,*/
/* queue areas, etc. */
sts = NU_Create_Memory_Pool(&System_Memory, "SYSMEM",
first_available_memory, MEMORY_SIZE,
50, NU_FIFO);
if (sts != NU_SUCCESS) ERC_System_Error(sts);
/* Create task_0. First we allocate the memory, then we create the task.*/
sts = NU_Allocate_Memory(&System_Memory, &pointer, STACK_SIZE,
NU_NO_SUSPEND);
if (sts != NU_SUCCESS) ERC_System_Error(sts);
sts = NU_Create_Task(&Task_0, "TASK 0", task_0, 0, NU_NULL, pointer,
STACK_SIZE, 1, 10, NU_PREEMPT, NU_START);
if (sts != NU_SUCCESS) ERC_System_Error(sts);
/* Create task_1. First we allocate the memory, then we create the task.*/
sts = NU_Allocate_Memory(&System_Memory, &pointer, STACK_SIZE,
NU_NO_SUSPEND);
if (sts != NU_SUCCESS) ERC_System_Error(sts);
sts = NU_Create_Task(&Task_1, "TASK 1", task_1, 0, NU_NULL, pointer,
STACK_SIZE, 10, 5, NU_PREEMPT, NU_START);
if (sts != NU_SUCCESS) ERC_System_Error(sts);
/* Create communication queue "Queue_0." First we allocate the memory, */
/* then we create the Queue. */
sts = NU_Allocate_Memory(&System_Memory, &pointer, 10*sizeof(UNSIGNED)
, NU_NO_SUSPEND);
if (sts != NU_SUCCESS) ERC_System_Error(sts);
sts = NU_Create_Queue(&Queue_0, "QUEUE 0", pointer, 10, NU_FIXED_SIZE,
1, NU_FIFO);
if (sts != NU_SUCCESS) ERC_System_Error(sts);
/* Register the Clock Timer Interrupt. */
sts = NU_Register_LISR(CLKPRIO, TMT_Timer_Interrupt, &oldlisr);
if (sts != NU_SUCCESS) ERC_System_Error(sts);
}
/* Define the queue sending task. */
/* char buf[128];
DWORD NumWritten;
sprintf(buf,"**********KVM VM Begin***********");
WriteConsole(Con_Apl, buf, strlen(buf),&NumWritten, NULL);//win32程序函数
sprintf(buf,"\n");
WriteConsole(Con_Apl, buf, strlen(buf),&NumWritten, NULL);
*/
extern char *strcpy( char *strDestination, const char *strSource );
void task_0(UNSIGNED argc, void *argv)
{
//虚拟机运行
int result=0;
int argc1=0;
char * argv1[3];
argv1[0]=(char *)malloc(sizeof(char)*256);
argv1[1]=(char *)malloc(sizeof(char)*256);
argc1=0x00000002;
strcpy(argv1[0],".\\Debug\\demo.exe");
strcpy(argv1[1],"Hello");
result=main1(argc1,argv1);
free(argv1[0]);
argv1[0]=0x00;
free(argv1[1]);
argv1[1]=0x00;
/*
E:\kvm_test_main_绿色版\kvm_test_main_绿色版\Debug\main.exe Hello
*/
}
/* Define the queue receiving task. Note that the only things that cause */
/* this task to suspend are queue empty conditions and the time slice */
/* specified in the configuration file. */
void task_1(UNSIGNED argc, void *argv)
{
STATUS status;
UNSIGNED Receive_Message=(UNSIGNED)0;
UNSIGNED received_size=(UNSIGNED)0;
UNSIGNED message_expected;
/* Access argc and argv just to avoid compilation warnings. */
status = (STATUS) argc + (STATUS) argv;
/* Initialize the message counter. */
Task_1_messages_received = 0;
Task_1_invalid_messages = 0;
message_expected = 0;
while(1) {
/* Retrieve a message from Queue_0, which task 0 writes to. */
/* Note that if the source queue is empty this task suspends */
/* until something becomes available. */
status = NU_Receive_From_Queue(&Queue_0, &Receive_Message, 1,
&received_size, NU_SUSPEND);
/* Determine if the message was received successfully. */
if (status == NU_SUCCESS) //成功接受到消息
Task_1_messages_received++;
/* Check the contents of the message against what this task is */
/* expecting.*/
if ((received_size != 1) || (Receive_Message != message_expected))
Task_1_invalid_messages++;
/* Modify the expected contents of the next message. */
message_expected++;
}
}
/*void task_2(UNSIGNED argc, void *argv)
{
char buf[128];
DWORD NumWritten;
sprintf(buf,"**********KVM VM Begin***********");
WriteConsole(Con_Apl, buf, strlen(buf),&NumWritten, NULL);
sprintf(buf,"\n");
WriteConsole(Con_Apl, buf, strlen(buf),&NumWritten, NULL);
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -