• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

UART通信を用いた組み込みデバッグ用途向けメモリモニタ


Commit MetaInfo

Révision9ccc89b4932c34df9c3238a974e5907e328efa8d (tree)
l'heure2018-05-10 22:55:30
AuteurYasushi Tanaka <tanaka_yasushi2008@yaho...>
CommiterYasushi Tanaka

Message de Log

YMODEMを追加

Change Summary

Modification

--- a/DebugMonitor/DebugMonitor.vcxproj
+++ b/DebugMonitor/DebugMonitor.vcxproj
@@ -82,6 +82,7 @@
8282 <ItemGroup>
8383 <ClInclude Include="src\app\app.h" />
8484 <ClInclude Include="src\comm\comm.h" />
85+ <ClInclude Include="src\comm\ymodem.h" />
8586 <ClInclude Include="src\framework\bdlist.h" />
8687 <ClInclude Include="src\framework\cons.h" />
8788 <ClInclude Include="src\framework\header.h" />
@@ -93,6 +94,7 @@
9394 <ItemGroup>
9495 <ClCompile Include="src\app\app.c" />
9596 <ClCompile Include="src\comm\comm.c" />
97+ <ClCompile Include="src\comm\ymodem.c" />
9698 <ClCompile Include="src\framework\bdlist.c" />
9799 <ClCompile Include="src\framework\cons.c" />
98100 <ClCompile Include="src\framework\logwin.c" />
--- a/DebugMonitor/DebugMonitor.vcxproj.filters
+++ b/DebugMonitor/DebugMonitor.vcxproj.filters
@@ -60,6 +60,9 @@
6060 <ClInclude Include="src\app\app.h">
6161 <Filter>ヘッダー ファイル\app</Filter>
6262 </ClInclude>
63+ <ClInclude Include="src\comm\ymodem.h">
64+ <Filter>ヘッダー ファイル\comm</Filter>
65+ </ClInclude>
6366 </ItemGroup>
6467 <ItemGroup>
6568 <ClCompile Include="src\framework\winmain.c">
@@ -86,5 +89,8 @@
8689 <ClCompile Include="src\app\app.c">
8790 <Filter>ソース ファイル\app</Filter>
8891 </ClCompile>
92+ <ClCompile Include="src\comm\ymodem.c">
93+ <Filter>ソース ファイル\comm</Filter>
94+ </ClCompile>
8995 </ItemGroup>
9096 </Project>
\ No newline at end of file
--- a/DebugMonitor/src/comm/comm.c
+++ b/DebugMonitor/src/comm/comm.c
@@ -10,6 +10,22 @@
1010 #include "comm.h"
1111
1212 /*
13+ * 定数
14+ */
15+
16+/* 不定な通信ポート数 */
17+#define INVALID_COMM_PORTS 0xffffffff
18+
19+/* ボーレート */
20+#define COMM_PORT_BAUDRATE 115200
21+
22+/* 受信バッファサイズ */
23+#define COMM_INQUEUE_BYTES 0x1000
24+
25+/* 送信バッファサイズ */
26+#define COMM_OUTQUEUE_BYTES 0x1000
27+
28+/*
1329 * static変数
1430 */
1531
@@ -39,12 +55,32 @@ static void comm_port_init(COMM_PORT *port)
3955
4056 /*
4157 * 通信ポート
58+ * ポートのクローズ
59+ */
60+static void comm_port_close(COMM_PORT *port)
61+{
62+ assert(NULL != port);
63+
64+ /* オープンされていれば */
65+ if (INVALID_HANDLE_VALUE != port->file_handle)
66+ {
67+ /* クローズ */
68+ CloseHandle(port->file_handle);
69+ port->file_handle = INVALID_HANDLE_VALUE;
70+ }
71+}
72+
73+/*
74+ * 通信ポート
4275 * ポートの破棄
4376 */
4477 static void comm_port_destroy(COMM_PORT *port)
4578 {
4679 assert(NULL != port);
4780
81+ /* ポートのクローズ */
82+ comm_port_close(port);
83+
4884 /* ポートネーム */
4985 if (NULL != port->port_name)
5086 {
@@ -465,6 +501,28 @@ static UINT comm_allport_getnum(void)
465501
466502 /*
467503 * 通信ポート
504+ * ポートインデックスからポートを取得
505+ */
506+static COMM_PORT* comm_allport_getport(UINT index)
507+{
508+ COMM_PORT *port;
509+ UINT loop;
510+
511+ /* 初期化 */
512+ port = g_comm_port_head;
513+
514+ /* ループ */
515+ for (loop = 0; loop < index; loop++)
516+ {
517+ assert(NULL != port);
518+ port = (COMM_PORT*)port->bdlist.bdlist_next;
519+ }
520+
521+ return port;
522+}
523+
524+/*
525+ * 通信ポート
468526 * 初期化
469527 */
470528 void comm_init(void)
@@ -472,8 +530,8 @@ void comm_init(void)
472530 /* 通信ポートなし */
473531 g_comm_port_head = NULL;
474532
475- /* ポート数を最大値に初期化 */
476- g_comm_port_num = 0xFFFFFFFF;
533+ /* ポート数を不定値に初期化 */
534+ g_comm_port_num = INVALID_COMM_PORTS;
477535 }
478536
479537 /*
@@ -498,6 +556,7 @@ void comm_enum(void)
498556 HDEVINFO hDevInfo;
499557 UINT num;
500558 COMM_PORT *port;
559+ UINT loop;
501560
502561 /* ポートがオープンされていれば何もしない */
503562 result = comm_allport_isopen();
@@ -554,11 +613,312 @@ void comm_enum(void)
554613 logwin_printf("COMポートが%uポート見つかりました", num);
555614
556615 /* ポートループ */
557- port = g_comm_port_head;
558- while (NULL != port)
616+ for (loop = 0; loop < num; loop++)
559617 {
618+ port = comm_allport_getport(loop);
619+ assert(NULL != port);
620+
621+ /* フレンドリネームをログ出力 */
560622 logwin_printfw(port->friendly_name);
561- port = (COMM_PORT*)port->bdlist.bdlist_next;
562623 }
563624 }
564625 }
626+
627+/*
628+ * 通信ポート
629+ * ポート数取得
630+ */
631+UINT comm_get_portnum(void)
632+{
633+ /* 初期値であれば0を返す */
634+ if (INVALID_COMM_PORTS == g_comm_port_num)
635+ {
636+ return 0;
637+ }
638+
639+ /* それ以外はグローバル変数を返す */
640+ return g_comm_port_num;
641+}
642+
643+/*
644+ * 通信ポート
645+ * オープン
646+ */
647+BOOL comm_open(UINT index)
648+{
649+ COMM_PORT *port;
650+ DCB dcb;
651+ COMMTIMEOUTS cto;
652+ BOOL result;
653+
654+ /* 通信ポートを取得 */
655+ port = comm_allport_getport(index);
656+ if (NULL == port)
657+ {
658+ /* ポートオブジェクトが見つからない */
659+ return FALSE;
660+ }
661+
662+ /* 既にオープンされていればTRUEを返す */
663+ if (INVALID_HANDLE_VALUE != port->file_handle)
664+ {
665+ /* 既にオープンされている */
666+ return TRUE;
667+ }
668+
669+ /* オープンを試みる */
670+ port->file_handle = CreateFile(
671+ port->port_file,
672+ GENERIC_READ | GENERIC_WRITE,
673+ 0,
674+ NULL,
675+ OPEN_EXISTING,
676+ 0,
677+ NULL);
678+ if (INVALID_HANDLE_VALUE == port->file_handle)
679+ {
680+ return FALSE;
681+ }
682+
683+ /* DCBを取得 */
684+ memset(&dcb, 0, sizeof(dcb));
685+ dcb.DCBlength = sizeof(dcb);
686+ result = GetCommState(port->file_handle, &dcb);
687+ assert(FALSE != result);
688+ if (FALSE == result)
689+ {
690+ comm_port_close(port);
691+ return FALSE;
692+ }
693+
694+ /* DCBを設定 */
695+ dcb.BaudRate = COMM_PORT_BAUDRATE;
696+ dcb.fBinary = TRUE;
697+ dcb.fParity = FALSE;
698+ dcb.fOutxCtsFlow = FALSE;
699+ dcb.fOutxDsrFlow = FALSE;
700+ dcb.fDtrControl = DTR_CONTROL_ENABLE;
701+ dcb.fDsrSensitivity = FALSE;
702+ dcb.fTXContinueOnXoff = TRUE;
703+ dcb.fOutX = FALSE;
704+ dcb.fInX = FALSE;
705+ dcb.fErrorChar = FALSE;
706+ dcb.fNull = FALSE;
707+ dcb.fRtsControl = RTS_CONTROL_ENABLE;
708+ dcb.fAbortOnError = FALSE;
709+ dcb.ByteSize = 8;
710+ dcb.Parity = NOPARITY;
711+ dcb.StopBits = ONESTOPBIT;
712+ result = SetCommState(port->file_handle, &dcb);
713+ assert(FALSE != result);
714+ if (FALSE == result)
715+ {
716+ comm_port_close(port);
717+ return FALSE;
718+ }
719+
720+ /* タイムアウトの設定 */
721+ memset(&cto, 0, sizeof(cto));
722+ cto.ReadIntervalTimeout = MAXDWORD;
723+ cto.ReadTotalTimeoutConstant = 0;
724+ cto.ReadTotalTimeoutMultiplier = 0;
725+ cto.WriteTotalTimeoutConstant = 0;
726+ cto.WriteTotalTimeoutMultiplier = 0;
727+ result = SetCommTimeouts(port->file_handle, &cto);
728+ assert(FALSE != result);
729+ if (FALSE == result)
730+ {
731+ comm_port_close(port);
732+ return FALSE;
733+ }
734+
735+ /* 入出力バッファサイズの設定 */
736+ result = SetupComm(port->file_handle, COMM_INQUEUE_BYTES, COMM_OUTQUEUE_BYTES);
737+ assert(FALSE != result);
738+ if (FALSE == result)
739+ {
740+ comm_port_close(port);
741+ return FALSE;
742+ }
743+
744+ /* イベントマスクの設定 */
745+ result = SetCommMask(port->file_handle, 0);
746+ assert(FALSE != result);
747+ if (FALSE == result)
748+ {
749+ comm_port_close(port);
750+ return FALSE;
751+ }
752+
753+ /* ブレーク状態の解除 */
754+ result = ClearCommBreak(port->file_handle);
755+ assert(FALSE != result);
756+ if (FALSE == result)
757+ {
758+ comm_port_close(port);
759+ return FALSE;
760+ }
761+
762+ /* 送受信バッファのクリア */
763+ result = PurgeComm(port->file_handle, PURGE_RXCLEAR | PURGE_TXCLEAR);
764+ assert(FALSE != result);
765+ if (FALSE == result)
766+ {
767+ comm_port_close(port);
768+ return FALSE;
769+ }
770+
771+ /* オープン成功 */
772+ return TRUE;
773+}
774+
775+/*
776+ * 通信ポート
777+ * クローズ
778+ */
779+void comm_close(UINT index)
780+{
781+ COMM_PORT *port;
782+
783+ /* 通信ポートを取得 */
784+ port = comm_allport_getport(index);
785+ if (NULL == port)
786+ {
787+ /* ポートオブジェクトが見つからない */
788+ return;
789+ }
790+
791+ /* クローズ */
792+ comm_port_close(port);
793+}
794+
795+/*
796+ * 通信ポート
797+ * 受信バイト数の取得
798+ */
799+UINT comm_get_bytes(UINT index)
800+{
801+ COMM_PORT *port;
802+ DWORD errors;
803+ COMSTAT stat;
804+ BOOL result;
805+
806+ /* 通信ポートを取得 */
807+ port = comm_allport_getport(index);
808+ if (NULL == port)
809+ {
810+ /* ポートオブジェクトが見つからない */
811+ return 0;
812+ }
813+
814+ /* オープンされているか */
815+ if (INVALID_HANDLE_VALUE == port->file_handle)
816+ {
817+ /* オープンされていない */
818+ return 0;
819+ }
820+
821+ /* エラーをクリアし、情報を取得 */
822+ result = ClearCommError(port->file_handle, &errors, &stat);
823+ if (FALSE == result)
824+ {
825+ /* ポートが消滅した */
826+ comm_port_close(port);
827+ return 0;
828+ }
829+
830+ /* 受信バイト数を返す */
831+ return (UINT)stat.cbInQue;
832+}
833+
834+/*
835+ * 通信ポート
836+ * 受信
837+ */
838+UINT comm_recv(UINT index, LPBYTE buf, UINT buflen)
839+{
840+ COMM_PORT *port;
841+ UINT inque;
842+ DWORD bytes;
843+ BOOL result;
844+
845+ assert(NULL != buf);
846+
847+ /* 受信バイト数を得る */
848+ inque = comm_get_bytes(index);
849+ if (0 == inque)
850+ {
851+ /* 受信バッファにデータなし */
852+ return 0;
853+ }
854+
855+ /* inqueとbuflenのうち、小さい方に揃える */
856+ if (buflen < inque)
857+ {
858+ inque = buflen;
859+ }
860+
861+ /* ポートを得る */
862+ port = comm_allport_getport(index);
863+ assert(NULL != port);
864+
865+ /* 受信 */
866+ result = ReadFile(
867+ port->file_handle,
868+ buf,
869+ (DWORD)inque,
870+ &bytes,
871+ NULL);
872+ if (result == FALSE)
873+ {
874+ /* ポートが消滅した */
875+ comm_port_close(port);
876+ return 0;
877+ }
878+
879+ /* 受信バイト数を返す */
880+ return (UINT)bytes;
881+}
882+
883+/*
884+ * 通信ポート
885+ * 送信
886+ */
887+UINT comm_send(UINT index, LPBYTE buf, UINT buflen)
888+{
889+ COMM_PORT *port;
890+ DWORD written;
891+ BOOL result;
892+
893+ /* 通信ポートを取得 */
894+ port = comm_allport_getport(index);
895+ if (NULL == port)
896+ {
897+ /* ポートオブジェクトが見つからない */
898+ return 0;
899+ }
900+
901+ /* オープンされているか */
902+ if (INVALID_HANDLE_VALUE == port->file_handle)
903+ {
904+ /* オープンされていない */
905+ return 0;
906+ }
907+
908+ /* 送信 */
909+ result = WriteFile(
910+ port->file_handle,
911+ buf,
912+ (DWORD)buflen,
913+ &written,
914+ NULL);
915+ if (result == FALSE)
916+ {
917+ /* ポートが消滅した */
918+ comm_port_close(port);
919+ return 0;
920+ }
921+
922+ /* 送信バイト数を返す */
923+ return (UINT)written;
924+}
--- a/DebugMonitor/src/comm/comm.h
+++ b/DebugMonitor/src/comm/comm.h
@@ -45,3 +45,21 @@ void comm_deinit(void);
4545
4646 /* ポートを列挙 */
4747 void comm_enum(void);
48+
49+/* ポート数を取得 */
50+UINT comm_get_portnum(void);
51+
52+/* オープン */
53+BOOL comm_open(UINT index);
54+
55+/* クローズ */
56+void comm_close(UINT index);
57+
58+/* 受信バイト数の取得 */
59+UINT comm_get_bytes(UINT index);
60+
61+/* 受信 */
62+UINT comm_recv(UINT index, LPBYTE buf, UINT buflen);
63+
64+/* 送信 */
65+UINT comm_send(UINT index, LPBYTE buf, UINT buflen);
--- /dev/null
+++ b/DebugMonitor/src/comm/ymodem.c
@@ -0,0 +1,69 @@
1+/*
2+ * Debug Monitor Framework
3+ * Author: Yasushi Tanaka
4+ *
5+ * [ YMODEM ]
6+ */
7+
8+#include "header.h"
9+#include "logwin.h"
10+#include "comm.h"
11+#include "ymodem.h"
12+
13+/*
14+ * 定数
15+ */
16+
17+/*
18+ * static変数
19+ */
20+
21+/*
22+ * YMODEM
23+ * 初期化
24+ */
25+void ymodem_init(UINT comm_index)
26+{
27+}
28+
29+/*
30+ * YMODEM
31+ * アイドル
32+ */
33+void ymodem_idle(void)
34+{
35+}
36+
37+/*
38+ * YMODEM
39+ * 送信開始
40+ */
41+BOOL ymodem_send(const char* filename, UINT filesize)
42+{
43+ return FALSE;
44+}
45+
46+/*
47+ * YMODEM
48+ * 受信開始
49+ */
50+BOOL ymodem_recv(void)
51+{
52+ return FALSE;
53+}
54+
55+/*
56+ * YMODEM
57+ * ステータス取得
58+ */
59+UINT ymodem_get_status(void)
60+{
61+ return 0;
62+}
63+
64+/* ファイルネーム取得 */
65+const char* ymodem_get_filename(void)
66+{
67+ return NULL;
68+}
69+
--- /dev/null
+++ b/DebugMonitor/src/comm/ymodem.h
@@ -0,0 +1,47 @@
1+/*
2+ * Debug Monitor Framework
3+ * Author: Yasushi Tanaka
4+ *
5+ * [ YMODEM送受信 ]
6+ */
7+
8+#pragma once
9+
10+/*
11+ * 定数
12+ */
13+
14+#define YMODEM_SUCCESS 0 /* 成功 */
15+#define YMODEM_BUSY 1 /* 動作中 */
16+#define YMODEM_SIZEOVER 2 /* バッファサイズ溢れ */
17+#define YMODEM_TIMEOUT 3 /* タイムアウト */
18+#define YMODEM_CANCEL 4 /* キャンセル要求受信 */
19+#define YMODEM_CLOSED 5 /* ポートクローズ */
20+
21+/*
22+ * グローバル関数
23+ */
24+
25+/* 初期化 */
26+void ymodem_init(UINT comm_index);
27+
28+/* アイドル */
29+void ymodem_idle(void);
30+
31+/* 送信開始 */
32+BOOL ymodem_send(const char *filename, UINT filesize);
33+
34+/* 受信開始 */
35+BOOL ymodem_recv(void);
36+
37+/* ステータス取得 */
38+UINT ymodem_get_status(void);
39+
40+/* ファイルネーム取得 */
41+const char* ymodem_get_filename(void);
42+
43+/* ファイルサイズ取得 */
44+UINT ymodem_get_filesize(void);
45+
46+/* バッファポインタ取得 */
47+LPBYTE ymodem_get_filebuf(void);
--- a/DebugMonitor/src/framework/winmain.c
+++ b/DebugMonitor/src/framework/winmain.c
@@ -580,7 +580,7 @@ static BOOL RegisterWindowClass(void)
580580 /* ゼロクリア */
581581 memset(&wcex, 0, sizeof(wcex));
582582
583- /* 構造体サイズ */
583+ /* 構造体サイズ */
584584 wcex.cbSize = sizeof(wcex);
585585
586586 /* ウィンドウスタイル */