|
马上注册,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册 
×
#include <message.h>
#include <pio.h>
#include <stream.h>
#include <source.h>
#include <sink.h>
#include <string.h>
#include <panic.h>
#ifdef DEBUG_PRINT_ENABLED
#include <stdio.h>
#define DEBUG(x) {printf x;}
#else
#define DEBUG(x)
#endif
static TaskData t;
static void tHandler(Task t, MessageId id, Message msg)
{
switch(id)
{
case 0:
{
const char *string = "Hello world";
int length = strlen(string);
int offset;
char *dest;
Sink sink = StreamUartSink();
PanicNull(sink);
offset = SinkClaim(sink, length);
if(offset == 0xFFFF) Panic();
dest = SinkMap(sink);
(void) PanicNull(dest);
memcpy(dest+offset, string, length);
PanicZero(SinkFlush(sink, length));
MessageSendLater(t, 0, 0, 500);
}
break;
case MESSAGE_MORE_DATA:
{
Source source = StreamUartSource();
char *buf = (char *)SourceMap(source);
int len = SourceSize(source);
int i,j;
for(i=0; i<len; i++)
{
DEBUG(("%x ", buf[i]));
j = buf[i];
}
DEBUG(("\n"));
SourceDrop(source, len);
}
break;
default:
DEBUG(("msg %x\n", id));
break;
}
}
int main(void)
{
StreamUartConfigure(VM_UART_RATE_115K2, VM_UART_STOP_ONE, VM_UART_PARITY_NONE);
t.handler = tHandler;
MessageSinkTask(StreamUartSink(), &t);
MessageSendLater(&t, 0, 0, 500);
MessageLoop();
return 0;
} |
|