📄 main2.c
字号:
/*
* File: main.c
*
* uC/OS Real-time multitasking kernel for the ARM processor.
*
* This program is an example of using semaphore to
* implement task rendevous.
*
* Created by Marco Graziano (marcog@crl.com).
*
*/
//#include "includes.h" /* uC/OS interface */
#include "debug.h"
#include "opt.h"
#include "def.h"
#include "mem.h"
#include "pbuf.h"
#include "sys.h"
#include "tcpip.h"
#include "api.h"
#include "arp.h"
#include "loopif.h"
//yangye 2003-1-23
#include "ne2kif.h"
#include "sys_arch.h"
#include "skyeye_stdio.h"
/* allocate memory for tasks' stacks */
#ifdef SEMIHOSTED
#define STACKSIZE (SEMIHOSTED_STACK_NEEDS+64)
#else
#define STACKSIZE 128
#endif
unsigned int Stack1[STACKSIZE];
unsigned int Stack2[STACKSIZE];
unsigned int Stack3[STACKSIZE];
/* semaphores event control blocks */
//OS_EVENT *Sem1;
//OS_EVENT *Sem2;
//OS_EVENT *Sem3;
/*
* Task running at the highest priority.
*/
void
Task1(void *i)
{
INT8U Reply, n;
for (;;)
{
/* wait for the semaphore */
//OSSemPend(Sem1, 0, &Reply);
uHALr_printf("\nTask1 running");
//Uart_Printf("1+");
/* wait a short while */
for(n=0;n<1;n++)
{
LED0(1);
OSTimeDly(500);
LED0(0);
OSTimeDly(500);
}
uHALr_printf("\nTask1 exit");
//Uart_Printf("1-");
/* signal the semaphore */
//OSSemPost(Sem1);
}
}
void
Task2(void *i)
{
INT8U Reply, n;
for (;;)
{
uHALr_printf("\nTask2 running");
/* wait a short while */
for(n=0;n<1;n++)
{
LED1(1);
OSTimeDly(1000);
LED1(0);
OSTimeDly(1000);
}
uHALr_printf("\nTask2 exit");
}
}
void
Task3(void *i)
{
INT8U Reply, n;
for (;;)
{
uHALr_printf("\nTask3 running");
/* wait a short while */
for(n=0;n<1;n++)
{
LED2(1);
OSTimeDly(2000);
LED2(0);
OSTimeDly(2000);
}
uHALr_printf("\nTask3 exit");
}
}
const static char indexdata[] =
"<html> \
<head><title>A test page</title></head> \
<body> \
This is a small test page. \
</body> \
</html>";
const static char http_html_hdr[] =
"Content-type: text/html\r\n\r\n";
/* This function processes an incomming connection. */
static void process_connection(struct netconn *conn)
{
struct netbuf *inbuf;
char *rq;
u16_t len;
/* Read data from the connection into the netbuf inbuf.
We assume that the full request is in the netbuf. */
inbuf = netconn_recv(conn);
/* Get the pointer to the data in the first netbuf
fragment which we hope contains the request. */
netbuf_data(inbuf, (void *)&rq, &len);
/* Check if the request was an HTTP "GET /\r\n". */
if(rq[0] == 'G' && rq[1] == 'E' &&
rq[2] == 'T' && rq[3] == ' ' &&
rq[4] == '/' && rq[5] == '\r' &&
rq[6] == '\n') {
/* Send the header. */
netconn_write(conn, (void *)http_html_hdr, sizeof(http_html_hdr),
NETCONN_NOCOPY);
/* Send the actual web page. */
netconn_write(conn, (void *)indexdata, sizeof(indexdata),
NETCONN_NOCOPY);
/* Close the connection. */
netconn_close(conn);
}
}
/*
* Main function.
*/
void Main(void)
{
char Id1 = '1';
char Id2 = '2';
char Id3 = '3';
Port_Init();
Uart_Init(0,57600);
Delay(1000);
Uart_Select(0); //Select UART0
Uart_Printf("Uc-OS ii will run at once!");
/* do target (uHAL based ARM system) initialisation */
// ARMTargetInit();
/* needed by uC/OS */
// OSInit();
// OSTimeSet(0);
/*
* create the semaphores
*/
//Sem1 = OSSemCreate(1);
//Sem2 = OSSemCreate(1);
//Sem3 = OSSemCreate(1);
/*
* create the tasks in uC/OS and assign decreasing
* priority to them
*/
// OSTaskCreate(Task1, (void *)&Id1, (void *)&Stack1[STACKSIZE - 1], 1);
// OSTaskCreate(Task2, (void *)&Id2, (void *)&Stack2[STACKSIZE - 1], 2);
// OSTaskCreate(Task3, (void *)&Id3, (void *)&Stack3[STACKSIZE - 1], 3);
/* Start the (uHAL based ARM system) system running */
// ARMTargetStart();
/* start the game */
// OSStart();
/* never reached */
/* A simple HTTP/1.0 server using the minimal API. */
/* This is the data for the actual web page.
Most compilers would place this in ROM. */
struct netconn *conn, *newconn;
/* Create a new TCP connection handle. */
conn = netconn_new(NETCONN_TCP);
/* Bind the connection to port 80 on any
local IP address. */
netconn_bind(conn, (ip_addr *)NULL, 80);
/* Put the connection into LISTEN state. */
netconn_listen(conn);
/* Loop forever. */
while(1) {
/* Accept a new connection. */
newconn = netconn_accept(conn);
/* Process the incomming connection. */
process_connection(newconn);
/* Deallocate connection handle. */
netconn_delete(newconn);
}
return 0;
} /* main */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -