Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed BufferedSerial
Diff: main.cpp
- Revision:
- 1:c6e8a41200d9
- Parent:
- 0:7c6ad253848a
- Child:
- 2:52002844d0c6
--- a/main.cpp Sat Jul 19 02:12:20 2014 +0000 +++ b/main.cpp Sat Jul 26 23:58:24 2014 +0000 @@ -51,15 +51,96 @@ #include "ctype.h" LocalFileSystem local("local"); // local file systemの設定 -Serial pc(USBTX, USBRX); // usb-serialの設定 +//Serial pc(USBTX, USBRX); // usb-serialの設定 +Serial pc(p9, p10); +Timeout txSend; // 送信間隔作成用 DigitalOut ledopen(LED1); // 1:file open 0:file close -//DigitalOut ledout(LED2); // 1: serial out +DigitalOut ledout(LED2); // 1: serial out //DigitalOut lederror(LED4); char buffer[500]; // 読みだしたデータの保管先 +// 送信処理状態遷移 +typedef enum { + Z_txIdle, + Z_txStart, + Z_txSend +} txSend_t; +txSend_t M_txSend = Z_txIdle; // 0:受信完了(STX送信待ち) 1:STX以降CRまでの送信中 + + +/** + * 割り込み処理 + * 送信データ送信処理 + * 受信完了から送信開始の20[ms]の遅延 + * 送信データ1byte毎に2[ms]の遅延 + * を入れて送信する + */ +void txDataSend(void) +{ + static char *p; + + switch(M_txSend) { + + case Z_txStart: + // STX ~ CR 送信 + p = buffer; + M_txSend = Z_txSend; + //brak; + case Z_txSend: + if(*p != 0x00) { + pc.putc(*p++); + txSend.attach_us(&txDataSend, 1); // 次回送信開始まで2[us]セット(時間は可変設定にする) + } + + else { + // 送信完了 + M_txSend = Z_txIdle; + txSend.detach(); + } + break; + case Z_txIdle: // defaultと同じ処理 + default: + // nothing + break; + } + +} + +/** + * main処理 + * 受信終了から送信開始までの20[ms]遅延設定 + * + */ +void txDataWait(int wait_ms) +{ + txSend.attach_us(&txDataSend, wait_ms * 1000); // 受信完了から20[ms]経過待ち + M_txSend = Z_txStart; +} + +/** + * 送信終了判定 + * @@para int 戻り値 送信処理状況 1:送信完了 0:送信中 + */ +int txSendEndCheck(void) +{ + int ans; + if(M_txSend == Z_txIdle) { + ans = 1; + } else { + ans = 0; + } + + return(ans); +} + + + + + + int main() { @@ -107,7 +188,14 @@ } else { // 出力文字列として処理する - pc.printf("%s\n",buffer); + + txDataWait(1); + while(txSendEndCheck() == 0){ + // 割り込みで送信中 + ledout = !ledout; // この行がないとwhile文から抜けなくなる。原因不明 + } + + // pc.printf("%s\n",buffer); wait_ms(timer); } } else {