main.cpp
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[Real2Virtual202111]]
#code(c){{
#include "common.h"
//#include "mbed.h"
#include "CommandBuffer.h"
//#include "InBuffer.h"
//#include "OutBuffer.h"
#include "StringQueue.h"
//#include "Initialize.h"
//#include "BufferedSerial.h"
/*
=========================================================...
Name : main.c
Author :
Version :
Copyright : Copyright (C)
Description : main definition
=========================================================...
*/
// Variable to store CRP value in. Will be placed automat...
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
/*
timer interrupt
|
v
next door input 0 routine
|
next door output 0 routine
|
v
face 0 input (photo transister 0) routine
face 1 input (photo transister 1) routine
face 2 input (photo transister 2) routine
|
v
face 0 output routine
face 1 output routine
face 2 output routine
|
V
Interrupt enable
|
v
end
Main routine
|
v
initialize
|
v
start loop
|
v
next door command routine
|
v
face 0 command routine
face 1 command routine
face 2 command routine
|
v
usb command routine
|
v
repeat the loop
input routine
+---------------------------+
| inter face command buffer +---> message interpreter -->
+---------------------------+
+---------------------------+
| command buffer for face 0 +---> message interpreter -->
+---------------------------+
+---------------------------+
| command buffer for face 1 +---> message interpreter -->
+---------------------------+
+---------------------------+
| command buffer for face 2 +---> message interpreter -->
+---------------------------+
*/
/*
USB TERMINAL
mbed NXP LPC1768
1 GND 3.3 Vout 40
2 VIN 5.0v USV vout 39
3 VB IF- 38
4 nR IF+ 37
5 p5 mosi(spi) Ethernet RD- 36
6 p6 miso(spi) Ethernet RD+ 35
7 p7 sck Ethernet TD- 34
8 p8 Ethernet TD+ 33
9 p9 tx(serial) USB D- 32
10 p10 rx(serial) USB D+ 31
11 p11 mosi(spi) p30 30
12 p12 miso(spi) p29 29
13 p13 tx/sck I2C SDA p28 28
14 p14 rx I2C SCL p27 27
15 p15 analog p26 26
16 p16 analog p25 25
17 p17 analog p24 24
18 p18 analog /out p23 23
19 p19 analog p22 22
20 p20 analog p21 21
*/
/*
tesla dice configuration of the LPC1114FN28/102
PIN REG
36 PE0 p30 direction 0 ------R1Kohm--- LED00 LED01 ...
35 PE1 p29 direction 1 ------R1Kohm--- LED10 LED11 ...
34 PE2 p28 direction 2 ------R1Kohm--- LED20 LED21 ...
33 PE3 p27 direction 3 ------R1Kohm--- LEDse30 LED3...
---- | | ...
| | ...
26 PE4 p26 face 0----------------------------+ | ...
25 PE5 p25 face 1-----------------------------------+ ...
24 PE6 p24 face 2--------------------------------------...
23 PE7 p23 face 3--------------------------------------...
22 PE8 p22 face 4--------------------------------------...
21 PE9 p21 face 5--------------------------------------...
PORTx
15 --rx---<<<--serial ---- USB
16 --tx--->>>--serial ---- USB
REG ... photo tr receive
15 PEA p15 face 0 ------<<<-----
16 PEB p16 face 1 ------<<<-----
17 PEC p17 face 2 ------<<<-----
18 PED p18 face 3 ------<<<-----
19 PEE p19 face 4 ------<<<-----
20 PEF p20 face 5 ------<<<-----
○78k0<->78k0 (inter-dice )command
78k0->78k0 "srs." start the recursiv...
78k0<-78k0 "(f<x0>d<y0> f<x1>d<y1> ( ....)...
return the tesla dices...
78k0->78k0 "ask <x0><x1>...<xn>." ask the tesl...
78k0->78k0 "set (<val>) <x0><x1>...<xn>." set ...
○PC <->78k0 command ... プローブは PC<->78k0 で接続。各テ...
pc->78k0 "srs." start the recursiv...
pc<-78k0 "(f<x0>d<y0> f<x1>d<y1> ( ....)...
return the tesla dices...
pc->78k0 "con<x0>." 面<x0> の接続を確認
pc<-78k0 "cf<x1><y1>" ... <x0> は相手側...
または "n" ... 接続なし。
pc->78k0 "prb." この r8 をプローブ...
pc->78k0 "dce." この r8 をテスラダイ...
pc->78k0 "mon<level>." r8<->cpld 間の通信を...
<level>= 0 ... モニター...
<level>= 1 ... r8<-r8 ...
<level>= 2 ... r8<->cpl...
pc->78k0 "?." r8 の状態を問い合わせ
pc<-78k0 ...
OutBuffer.status
0 ... no data
1 ... outputting
2 ... output is done
3 ... buffering
4 ... ready for output
5 ... waiting ack
InBuffer.status
0 ... waiting
1 ... reading bits sequence
2 ... ready for input
inter-face commands
sx ----->
<---- ak
*/
/* */
// TODO: insert other include files here
RawSerial pc(USBTX,USBRX,9600); //9600bps
RawSerial atom(p10,p9,9600); //tx,rx
volatile int led_timer;
CommandBuffer *commandInterpreter;
void tir() {
(*commandInterpreter).interruptProcess();
}
Ticker t;
int main(void) {
int rd,rx;
int fid;
char command[128],received[128];
char *cp;
int isInQuote;
//printf("tesla_scaffold_01_20240511\n");
// TODO: insert code here
//---------------------------
// Initialize System Hardware
//---------------------------
commandInterpreter=new CommandBuffer((unsigned char)0);
// initForComBuffer(&commandInterpreter,(unsigned char...
(*commandInterpreter).initBuffer();
// commandInterpreter.setBuffers(&commandInterpreter);
(*commandInterpreter).setBuffers();
led_timer=1000;
//----------------
// Test Output
//----------------
{
//
// UART_getc(); // wait for any input
static char *sm1="\r\nTESLA DICE for LPC546xx\r\n";
static char *sm2="tesla_caffold_01_20240512\r\n";
// pc.printf(sm1);
// pc.printf(sm2);
// atom.printf(sm1);
// atom.printf(sm2);
xputs(sm1);
xputs(sm2);
}
isInQuote=0;
cp=command;
rd=0;
xputs("\n\rOK.\n\r");
//t.attach_us(&tir, 200); // the address of the objec...
//t.attach_us(&tir,100); //20230510
t.attach_us(&tir,One_Pulse); //20230622
while(1)
{
/* comment out when using api.h*/
// rd=COM_getchar();
// rd=UART_getc_nw();
if(pc.readable()){rd=pc.getc();}
if(atom.readable()){rd=atom.getc();}
if(rd!=0){
// UART_putc((char)rd);
pc.putc((char)rd);
atom.putc((char)rd);
/* */
rx=rd;
*cp=rd;
cp++;
rd=0;
if(cp-command>CMax){
// UART_puts("\n\rtoo long command.\n\r");
// pc.printf("\n\rtoo long command.\n\r");
xputs("\r\ntoo long command.\r\n");
cp=command;
}
if(rx=='\b'){
cp--;
if(cp-command>0){
cp--;
}
}
if(rx=='\"'){
if(isInQuote==0){
isInQuote=1;
}
else{
isInQuote=0;
}
}
if(rx=='\\'){
// rd=UART_getc();
if(pc.readable()) {
rd=pc.getc();
// UART_putc(rd);
pc.putc(rd);
}
if(atom.readable()){
rd=atom.getc();
atom.putc(rd);
}
*cp=rd;
cp++;
if(rd=='\b'){
cp--;
if(cp-command>0){
cp--;
}
}
rd=0;
}
if(rx=='.'){
if(isInQuote==0){
*cp=0;
(*commandInterpreter).putCommand( -1,...
(*commandInterpreter).interpretComman...
(*commandInterpreter).initBuffer();
// UART_puts("\n\rok.\n\r");
// pc.printf("\n\rok.\n\r");
xputs("\r\nok.\r\n");
cp=command;
}
}
else
if(rx=='\n'){
*cp=0;
(*commandInterpreter).putCommand( -1, com...
(*commandInterpreter).interpretCommand((u...
(*commandInterpreter).initBuffer();
// UART_puts("\n\rok.\n\r");
// pc.printf("\n\rok.\n\r");
xputs("\r\nok.\r\n");
cp=command;
}
} // end of if(rd!=0)
fid=(*((*commandInterpreter).getStringQueue())).g...
if(fid>=0){
// char w[50];
// sprintf(w,"fid=%d, received=",(int)fid);
// UART_puts(w);
xputs("fid=");xputd(fid);xputs(", received=")...
// UART_puts("\n\r");
xputs("\n\r");
(*commandInterpreter).putCommand( fid, receiv...
(*commandInterpreter).interpretCommand(fid);
(*commandInterpreter).initBuffer();
xputs("ok\n\r");
}
}
// return 0 ;
}
/*
// SysTickハンドラ
void SysTick_Handler(void) {
static uint16_t count = 0; // (1) カウンタ変...
if (++count >= led_timer) { // (2) 指定時間毎...
// LPC_GPIO0->DATA ^= (1 << 7); // (3) PIO0_7 を...
// LPC_GPIO1->DATA ^= (1 << 5); // PIO1_5 を...
(*commandInterpreter).interruptProcess();
count = 0; // (4) カウンタを...
}
}
void TMR32_Configuration(void) { /...
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 9); /...
LPC_TMR32B0->MCR |= (1 << 10); /...
LPC_TMR32B0->EMR |= (3 << 10); /...
LPC_IOCON->R_PIO0_11 |= 3; /...
}
void UART_Configuration(uint32_t baudrate) { /...
uint32_t DL; /...
LPC_IOCON->PIO1_6 |= 0x01; /...
LPC_IOCON->PIO1_7 |= 0x01; /...
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); /...
LPC_SYSCON->UARTCLKDIV = 0x01; /...
// DL = (SystemCoreClock * LPC_SYSCON->SYSAHBCLKDIV) ...
// / (16 * baudrate * LPC_SYSCON->UARTCLKDIV);
uint32_t DLA= (SystemCoreClock * LPC_SYSCON->SYSAHBCL...
uint32_t DLB= (16 * baudrate * LPC_SYSCON->UARTCLKDIV);
DL=xdiv(DLA,DLB);
LPC_UART->LCR |= (1<<7); /...
// LPC_UART->DLM = DL / 256; ...
// LPC_UART->DLL = DL % 256; ...
uint32_t dlm=DL>>8;
uint32_t dlx=DL-dlm*256;
LPC_UART->DLM=dlm;
LPC_UART->DLL=dlx;
LPC_UART->LCR &= ~(1<<7); /...
LPC_UART->LCR = 0x03; /...
LPC_UART->FCR = 0x07; /...
}
void UART_putc(char data) { /...
while (!(LPC_UART->LSR & (1<<5))); /...
LPC_UART->THR = data; /...
}
void UART_puts(char *str) { /...
while (*str != '\0') { /...
UART_putc(*str); /...
str++; /...
}
}
int UART_getc(void) { /...
while (!(LPC_UART->LSR & 0x01)); /...
return LPC_UART->RBR; /...
}
int UART_getc_nw(void) { /...
int rtn=0;
if(LPC_UART->LSR & 0x01){ // (1...
return LPC_UART->RBR; ...
}
return rtn;
}
*/
void xputs(char *c){
pc.printf("%s",c);
atom.printf("%s",c);
}
void xputc(char c){
pc.putc(c);
atom.putc(c);
}
void xputd(int d){
char w[20];
int pw;
char rw[20];
int prw;
int s=1;
if(d<0) {
s=-1;
d=-d;
}
pw=0;
w[pw]='0';
while(d>0){
// w[pw]='0'+(d%10);
// d=d/10;
w[pw]='0'+xmod(d,10);
d=xdiv(d,10);
pw++;
}
prw=0;
if(s<0){
rw[prw]='-';
prw++;
rw[prw]=0;
}
else{
rw[prw]='0';
}
rw[prw+1]=0;
while(pw>0){
pw--;
rw[prw]=w[pw];
prw++;
rw[prw]=0;
}
xputs(rw);
}
int xdiv(int x, int y){
int s;
s=1;
if(x<0 && y<0){
s=1;
x=-x;
y=-x;
}
else
if(x>=0 && y>=0 ){
s=1;
}
else{
s=-1;
if(x<0){
x=-x;
}
if(y<0){
y=-y;
}
}
if(y==0){
return s*99999999;
}
if(y>x){
return 0;
}
if(x==y){
return s;
}
if(y==1){
return s*x;
}
if(y==2){
return s*(x>>1);
}
if(y==4){
return s*(x>>2);
}
if(y==8){
return s*(x>>3);
}
if(y==16){
return s*(x>>4);
}
int rtn=0;
int scale=1;
while(x>y){
y=y<<1;
scale=scale<<1;
}
y=y>>1;
scale=scale >> 1;
while(scale>0){
if(x>y){
x=x-y;
rtn=rtn+scale;
}
y=y>>1;
scale=scale>>1;
}
return s*rtn;
}
int xmod(int x, int y){
int d=xdiv(x,y);
return x-d*y;
}
/* */
int xstrlen(char *a){
int rtn=0;
while((*a)!=0){
rtn++;
a++;
}
return rtn;
}
void xstrcpy(char *x, char *y){
int l=0;
while((*y)!=0){
if(l>256) break;
*x=*y;
x++;
y++;
l++;
}
*x=0;
}
void xstrcat(char *x, char *y){
char *px;
int maxlen=128;
px=x;
while(*px!=0){
px++;
}
while(*y!=0){
*px=*y;
px++;
y++;
if(px-x>maxlen){
*px=0;
return;
}
}
return;
}
/* */
}}
----
#counter
終了行:
[[Real2Virtual202111]]
#code(c){{
#include "common.h"
//#include "mbed.h"
#include "CommandBuffer.h"
//#include "InBuffer.h"
//#include "OutBuffer.h"
#include "StringQueue.h"
//#include "Initialize.h"
//#include "BufferedSerial.h"
/*
=========================================================...
Name : main.c
Author :
Version :
Copyright : Copyright (C)
Description : main definition
=========================================================...
*/
// Variable to store CRP value in. Will be placed automat...
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
/*
timer interrupt
|
v
next door input 0 routine
|
next door output 0 routine
|
v
face 0 input (photo transister 0) routine
face 1 input (photo transister 1) routine
face 2 input (photo transister 2) routine
|
v
face 0 output routine
face 1 output routine
face 2 output routine
|
V
Interrupt enable
|
v
end
Main routine
|
v
initialize
|
v
start loop
|
v
next door command routine
|
v
face 0 command routine
face 1 command routine
face 2 command routine
|
v
usb command routine
|
v
repeat the loop
input routine
+---------------------------+
| inter face command buffer +---> message interpreter -->
+---------------------------+
+---------------------------+
| command buffer for face 0 +---> message interpreter -->
+---------------------------+
+---------------------------+
| command buffer for face 1 +---> message interpreter -->
+---------------------------+
+---------------------------+
| command buffer for face 2 +---> message interpreter -->
+---------------------------+
*/
/*
USB TERMINAL
mbed NXP LPC1768
1 GND 3.3 Vout 40
2 VIN 5.0v USV vout 39
3 VB IF- 38
4 nR IF+ 37
5 p5 mosi(spi) Ethernet RD- 36
6 p6 miso(spi) Ethernet RD+ 35
7 p7 sck Ethernet TD- 34
8 p8 Ethernet TD+ 33
9 p9 tx(serial) USB D- 32
10 p10 rx(serial) USB D+ 31
11 p11 mosi(spi) p30 30
12 p12 miso(spi) p29 29
13 p13 tx/sck I2C SDA p28 28
14 p14 rx I2C SCL p27 27
15 p15 analog p26 26
16 p16 analog p25 25
17 p17 analog p24 24
18 p18 analog /out p23 23
19 p19 analog p22 22
20 p20 analog p21 21
*/
/*
tesla dice configuration of the LPC1114FN28/102
PIN REG
36 PE0 p30 direction 0 ------R1Kohm--- LED00 LED01 ...
35 PE1 p29 direction 1 ------R1Kohm--- LED10 LED11 ...
34 PE2 p28 direction 2 ------R1Kohm--- LED20 LED21 ...
33 PE3 p27 direction 3 ------R1Kohm--- LEDse30 LED3...
---- | | ...
| | ...
26 PE4 p26 face 0----------------------------+ | ...
25 PE5 p25 face 1-----------------------------------+ ...
24 PE6 p24 face 2--------------------------------------...
23 PE7 p23 face 3--------------------------------------...
22 PE8 p22 face 4--------------------------------------...
21 PE9 p21 face 5--------------------------------------...
PORTx
15 --rx---<<<--serial ---- USB
16 --tx--->>>--serial ---- USB
REG ... photo tr receive
15 PEA p15 face 0 ------<<<-----
16 PEB p16 face 1 ------<<<-----
17 PEC p17 face 2 ------<<<-----
18 PED p18 face 3 ------<<<-----
19 PEE p19 face 4 ------<<<-----
20 PEF p20 face 5 ------<<<-----
○78k0<->78k0 (inter-dice )command
78k0->78k0 "srs." start the recursiv...
78k0<-78k0 "(f<x0>d<y0> f<x1>d<y1> ( ....)...
return the tesla dices...
78k0->78k0 "ask <x0><x1>...<xn>." ask the tesl...
78k0->78k0 "set (<val>) <x0><x1>...<xn>." set ...
○PC <->78k0 command ... プローブは PC<->78k0 で接続。各テ...
pc->78k0 "srs." start the recursiv...
pc<-78k0 "(f<x0>d<y0> f<x1>d<y1> ( ....)...
return the tesla dices...
pc->78k0 "con<x0>." 面<x0> の接続を確認
pc<-78k0 "cf<x1><y1>" ... <x0> は相手側...
または "n" ... 接続なし。
pc->78k0 "prb." この r8 をプローブ...
pc->78k0 "dce." この r8 をテスラダイ...
pc->78k0 "mon<level>." r8<->cpld 間の通信を...
<level>= 0 ... モニター...
<level>= 1 ... r8<-r8 ...
<level>= 2 ... r8<->cpl...
pc->78k0 "?." r8 の状態を問い合わせ
pc<-78k0 ...
OutBuffer.status
0 ... no data
1 ... outputting
2 ... output is done
3 ... buffering
4 ... ready for output
5 ... waiting ack
InBuffer.status
0 ... waiting
1 ... reading bits sequence
2 ... ready for input
inter-face commands
sx ----->
<---- ak
*/
/* */
// TODO: insert other include files here
RawSerial pc(USBTX,USBRX,9600); //9600bps
RawSerial atom(p10,p9,9600); //tx,rx
volatile int led_timer;
CommandBuffer *commandInterpreter;
void tir() {
(*commandInterpreter).interruptProcess();
}
Ticker t;
int main(void) {
int rd,rx;
int fid;
char command[128],received[128];
char *cp;
int isInQuote;
//printf("tesla_scaffold_01_20240511\n");
// TODO: insert code here
//---------------------------
// Initialize System Hardware
//---------------------------
commandInterpreter=new CommandBuffer((unsigned char)0);
// initForComBuffer(&commandInterpreter,(unsigned char...
(*commandInterpreter).initBuffer();
// commandInterpreter.setBuffers(&commandInterpreter);
(*commandInterpreter).setBuffers();
led_timer=1000;
//----------------
// Test Output
//----------------
{
//
// UART_getc(); // wait for any input
static char *sm1="\r\nTESLA DICE for LPC546xx\r\n";
static char *sm2="tesla_caffold_01_20240512\r\n";
// pc.printf(sm1);
// pc.printf(sm2);
// atom.printf(sm1);
// atom.printf(sm2);
xputs(sm1);
xputs(sm2);
}
isInQuote=0;
cp=command;
rd=0;
xputs("\n\rOK.\n\r");
//t.attach_us(&tir, 200); // the address of the objec...
//t.attach_us(&tir,100); //20230510
t.attach_us(&tir,One_Pulse); //20230622
while(1)
{
/* comment out when using api.h*/
// rd=COM_getchar();
// rd=UART_getc_nw();
if(pc.readable()){rd=pc.getc();}
if(atom.readable()){rd=atom.getc();}
if(rd!=0){
// UART_putc((char)rd);
pc.putc((char)rd);
atom.putc((char)rd);
/* */
rx=rd;
*cp=rd;
cp++;
rd=0;
if(cp-command>CMax){
// UART_puts("\n\rtoo long command.\n\r");
// pc.printf("\n\rtoo long command.\n\r");
xputs("\r\ntoo long command.\r\n");
cp=command;
}
if(rx=='\b'){
cp--;
if(cp-command>0){
cp--;
}
}
if(rx=='\"'){
if(isInQuote==0){
isInQuote=1;
}
else{
isInQuote=0;
}
}
if(rx=='\\'){
// rd=UART_getc();
if(pc.readable()) {
rd=pc.getc();
// UART_putc(rd);
pc.putc(rd);
}
if(atom.readable()){
rd=atom.getc();
atom.putc(rd);
}
*cp=rd;
cp++;
if(rd=='\b'){
cp--;
if(cp-command>0){
cp--;
}
}
rd=0;
}
if(rx=='.'){
if(isInQuote==0){
*cp=0;
(*commandInterpreter).putCommand( -1,...
(*commandInterpreter).interpretComman...
(*commandInterpreter).initBuffer();
// UART_puts("\n\rok.\n\r");
// pc.printf("\n\rok.\n\r");
xputs("\r\nok.\r\n");
cp=command;
}
}
else
if(rx=='\n'){
*cp=0;
(*commandInterpreter).putCommand( -1, com...
(*commandInterpreter).interpretCommand((u...
(*commandInterpreter).initBuffer();
// UART_puts("\n\rok.\n\r");
// pc.printf("\n\rok.\n\r");
xputs("\r\nok.\r\n");
cp=command;
}
} // end of if(rd!=0)
fid=(*((*commandInterpreter).getStringQueue())).g...
if(fid>=0){
// char w[50];
// sprintf(w,"fid=%d, received=",(int)fid);
// UART_puts(w);
xputs("fid=");xputd(fid);xputs(", received=")...
// UART_puts("\n\r");
xputs("\n\r");
(*commandInterpreter).putCommand( fid, receiv...
(*commandInterpreter).interpretCommand(fid);
(*commandInterpreter).initBuffer();
xputs("ok\n\r");
}
}
// return 0 ;
}
/*
// SysTickハンドラ
void SysTick_Handler(void) {
static uint16_t count = 0; // (1) カウンタ変...
if (++count >= led_timer) { // (2) 指定時間毎...
// LPC_GPIO0->DATA ^= (1 << 7); // (3) PIO0_7 を...
// LPC_GPIO1->DATA ^= (1 << 5); // PIO1_5 を...
(*commandInterpreter).interruptProcess();
count = 0; // (4) カウンタを...
}
}
void TMR32_Configuration(void) { /...
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 9); /...
LPC_TMR32B0->MCR |= (1 << 10); /...
LPC_TMR32B0->EMR |= (3 << 10); /...
LPC_IOCON->R_PIO0_11 |= 3; /...
}
void UART_Configuration(uint32_t baudrate) { /...
uint32_t DL; /...
LPC_IOCON->PIO1_6 |= 0x01; /...
LPC_IOCON->PIO1_7 |= 0x01; /...
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); /...
LPC_SYSCON->UARTCLKDIV = 0x01; /...
// DL = (SystemCoreClock * LPC_SYSCON->SYSAHBCLKDIV) ...
// / (16 * baudrate * LPC_SYSCON->UARTCLKDIV);
uint32_t DLA= (SystemCoreClock * LPC_SYSCON->SYSAHBCL...
uint32_t DLB= (16 * baudrate * LPC_SYSCON->UARTCLKDIV);
DL=xdiv(DLA,DLB);
LPC_UART->LCR |= (1<<7); /...
// LPC_UART->DLM = DL / 256; ...
// LPC_UART->DLL = DL % 256; ...
uint32_t dlm=DL>>8;
uint32_t dlx=DL-dlm*256;
LPC_UART->DLM=dlm;
LPC_UART->DLL=dlx;
LPC_UART->LCR &= ~(1<<7); /...
LPC_UART->LCR = 0x03; /...
LPC_UART->FCR = 0x07; /...
}
void UART_putc(char data) { /...
while (!(LPC_UART->LSR & (1<<5))); /...
LPC_UART->THR = data; /...
}
void UART_puts(char *str) { /...
while (*str != '\0') { /...
UART_putc(*str); /...
str++; /...
}
}
int UART_getc(void) { /...
while (!(LPC_UART->LSR & 0x01)); /...
return LPC_UART->RBR; /...
}
int UART_getc_nw(void) { /...
int rtn=0;
if(LPC_UART->LSR & 0x01){ // (1...
return LPC_UART->RBR; ...
}
return rtn;
}
*/
void xputs(char *c){
pc.printf("%s",c);
atom.printf("%s",c);
}
void xputc(char c){
pc.putc(c);
atom.putc(c);
}
void xputd(int d){
char w[20];
int pw;
char rw[20];
int prw;
int s=1;
if(d<0) {
s=-1;
d=-d;
}
pw=0;
w[pw]='0';
while(d>0){
// w[pw]='0'+(d%10);
// d=d/10;
w[pw]='0'+xmod(d,10);
d=xdiv(d,10);
pw++;
}
prw=0;
if(s<0){
rw[prw]='-';
prw++;
rw[prw]=0;
}
else{
rw[prw]='0';
}
rw[prw+1]=0;
while(pw>0){
pw--;
rw[prw]=w[pw];
prw++;
rw[prw]=0;
}
xputs(rw);
}
int xdiv(int x, int y){
int s;
s=1;
if(x<0 && y<0){
s=1;
x=-x;
y=-x;
}
else
if(x>=0 && y>=0 ){
s=1;
}
else{
s=-1;
if(x<0){
x=-x;
}
if(y<0){
y=-y;
}
}
if(y==0){
return s*99999999;
}
if(y>x){
return 0;
}
if(x==y){
return s;
}
if(y==1){
return s*x;
}
if(y==2){
return s*(x>>1);
}
if(y==4){
return s*(x>>2);
}
if(y==8){
return s*(x>>3);
}
if(y==16){
return s*(x>>4);
}
int rtn=0;
int scale=1;
while(x>y){
y=y<<1;
scale=scale<<1;
}
y=y>>1;
scale=scale >> 1;
while(scale>0){
if(x>y){
x=x-y;
rtn=rtn+scale;
}
y=y>>1;
scale=scale>>1;
}
return s*rtn;
}
int xmod(int x, int y){
int d=xdiv(x,y);
return x-d*y;
}
/* */
int xstrlen(char *a){
int rtn=0;
while((*a)!=0){
rtn++;
a++;
}
return rtn;
}
void xstrcpy(char *x, char *y){
int l=0;
while((*y)!=0){
if(l>256) break;
*x=*y;
x++;
y++;
l++;
}
*x=0;
}
void xstrcat(char *x, char *y){
char *px;
int maxlen=128;
px=x;
while(*px!=0){
px++;
}
while(*y!=0){
*px=*y;
px++;
y++;
if(px-x>maxlen){
*px=0;
return;
}
}
return;
}
/* */
}}
----
#counter
ページ名: