Mercurial > nand-ecoscentric
comparison host/tools/ecostest/common/eCosTestSerialFilter.cpp @ 82:6736c52df507 ecos-sw-2000-04-14
Merge from eCos master repository on 2000-04-14-13:35:46-BST
| author | jlarmour |
|---|---|
| date | Tue, 18 Apr 2000 21:51:55 +0000 |
| parents | 2085233a121a |
| children | 489eb5632bc3 |
comparison
equal
deleted
inserted
replaced
| 81:89fef2181d7d | 82:6736c52df507 |
|---|---|
| 49 // o Clean up the mess in this file.... | 49 // o Clean up the mess in this file.... |
| 50 //####DESCRIPTIONEND#### | 50 //####DESCRIPTIONEND#### |
| 51 | 51 |
| 52 #include "eCosStd.h" | 52 #include "eCosStd.h" |
| 53 | 53 |
| 54 #define SER_FILTER_VER "$Id: eCosTestSerialFilter.cpp,v 1.3 2000/04/07 07:45:09 jlarmour Exp $" | 54 #define SER_FILTER_VER "$Id: eCosTestSerialFilter.cpp,v 1.4 2000/04/18 21:51:58 jlarmour Exp $" |
| 55 #include "eCosTestSerialFilter.h" | 55 #include "eCosTestSerialFilter.h" |
| 56 #include "eCosThreadUtils.h" | |
| 56 | 57 |
| 57 char msg_ok[] = "OK"; | 58 char msg_ok[] = "OK"; |
| 58 char msg_er[] = "ER"; | 59 char msg_er[] = "ER"; |
| 59 | 60 |
| 60 | 61 |
| 227 d1 += count; | 228 d1 += count; |
| 228 } | 229 } |
| 229 } | 230 } |
| 230 | 231 |
| 231 void | 232 void |
| 232 CeCosTestSerialFilter::TargetWrite(CeCosTestSerial &pSer, | 233 CeCosTestSerialFilter::TargetWrite(CeCosSerial &pSer, |
| 233 const unsigned char* buffer, int len) | 234 const unsigned char* buffer, int len) |
| 234 { | 235 { |
| 235 unsigned int __written; | 236 unsigned int __written; |
| 236 | 237 |
| 237 if (m_bOptFilterTrace) | 238 if (m_bOptFilterTrace) |
| 249 | 250 |
| 250 } | 251 } |
| 251 | 252 |
| 252 | 253 |
| 253 bool | 254 bool |
| 254 CeCosTestSerialFilter::TargetRead(CeCosTestSerial &pSer, | 255 CeCosTestSerialFilter::TargetRead(CeCosSerial &pSer, |
| 255 unsigned char* buffer, int len) | 256 unsigned char* buffer, int len) |
| 256 { | 257 { |
| 257 unsigned int __read; | 258 unsigned int __read; |
| 258 int __total_read = 0; | 259 int __total_read = 0; |
| 259 unsigned char* __buffer_base = buffer; | 260 unsigned char* __buffer_base = buffer; |
| 310 throw msg; | 311 throw msg; |
| 311 } | 312 } |
| 312 } | 313 } |
| 313 | 314 |
| 314 if (0 == __read) { | 315 if (0 == __read) { |
| 315 Sleep(20); | 316 CeCosThreadUtils::Sleep(20); |
| 316 __timeouts++; | 317 __timeouts++; |
| 317 if (25 == __timeouts) { | 318 if (25 == __timeouts) { |
| 318 __timeouts = 0; | 319 __timeouts = 0; |
| 319 if (5 == __timeout_failure++) { | 320 if (5 == __timeout_failure++) { |
| 320 Log("FAIL:<target timed out>\n"); | 321 Log("FAIL:<target timed out>\n"); |
| 348 return true; | 349 return true; |
| 349 } | 350 } |
| 350 | 351 |
| 351 // Send C ASCII string to target. | 352 // Send C ASCII string to target. |
| 352 void | 353 void |
| 353 CeCosTestSerialFilter::TargetASCIIWrite(CeCosTestSerial &pSer, const char* s) | 354 CeCosTestSerialFilter::TargetASCIIWrite(CeCosSerial &pSer, const char* s) |
| 354 { | 355 { |
| 355 TargetWrite(pSer, (const unsigned char*) s, strlen(s)); | 356 TargetWrite(pSer, (const unsigned char*) s, strlen(s)); |
| 356 } | 357 } |
| 357 | 358 |
| 358 //------------------------ | 359 //------------------------ |
| 359 // Configuration Command. | 360 // Configuration Command. |
| 360 // Set serial configuration. | 361 // Set serial configuration. |
| 361 bool | 362 bool |
| 362 CeCosTestSerialFilter::SetConfig(CeCosTestSerial &pSer, | 363 CeCosTestSerialFilter::SetConfig(CeCosSerial &pSer, |
| 363 const ser_cfg_t* new_cfg, | 364 const ser_cfg_t* new_cfg, |
| 364 ser_cfg_t* old_cfg) | 365 ser_cfg_t* old_cfg) |
| 365 { | 366 { |
| 366 if (old_cfg) { | 367 if (old_cfg) { |
| 367 old_cfg->baud_rate = pSer.GetBaud(); | 368 old_cfg->baud_rate = pSer.GetBaud(); |
| 376 return pSer.SetStopBits(new_cfg->stop_bits, true); // apply settings | 377 return pSer.SetStopBits(new_cfg->stop_bits, true); // apply settings |
| 377 } | 378 } |
| 378 | 379 |
| 379 // Return false if the serial configuration is not valid for the host. | 380 // Return false if the serial configuration is not valid for the host. |
| 380 bool | 381 bool |
| 381 CeCosTestSerialFilter::VerifyConfig(CeCosTestSerial &pSer, ser_cfg_t* new_cfg) | 382 CeCosTestSerialFilter::VerifyConfig(CeCosSerial &pSer, ser_cfg_t* new_cfg) |
| 382 { | 383 { |
| 383 ser_cfg_t old_cfg; | 384 ser_cfg_t old_cfg; |
| 384 bool rc; | 385 bool rc; |
| 385 | 386 |
| 386 // Try changing to the new config, recording the result. Then restore | 387 // Try changing to the new config, recording the result. Then restore |
| 425 // | 426 // |
| 426 // To Do: | 427 // To Do: |
| 427 // Host&protocol currently only supports: | 428 // Host&protocol currently only supports: |
| 428 // - no/even parity | 429 // - no/even parity |
| 429 void | 430 void |
| 430 CeCosTestSerialFilter::CMD_ChangeConfig(CeCosTestSerial &pSer, char* cfg_str) | 431 CeCosTestSerialFilter::CMD_ChangeConfig(CeCosSerial &pSer, char* cfg_str) |
| 431 { | 432 { |
| 432 ser_cfg_t new_cfg, old_cfg; | 433 ser_cfg_t new_cfg, old_cfg; |
| 433 | 434 |
| 434 ParseConfig(cfg_str, &new_cfg); | 435 ParseConfig(cfg_str, &new_cfg); |
| 435 | 436 |
| 440 } | 441 } |
| 441 | 442 |
| 442 // Tell target we're ready to go, wait 1/10 sec, and then change | 443 // Tell target we're ready to go, wait 1/10 sec, and then change |
| 443 // the config. | 444 // the config. |
| 444 TargetASCIIWrite(pSer, "OK"); | 445 TargetASCIIWrite(pSer, "OK"); |
| 445 Sleep(100); | 446 CeCosThreadUtils::Sleep(100); |
| 446 SetConfig(pSer, &new_cfg, &old_cfg); | 447 SetConfig(pSer, &new_cfg, &old_cfg); |
| 447 | 448 |
| 448 int loops; | 449 int loops; |
| 449 for (loops = 0; loops < 3; loops++) { | 450 for (loops = 0; loops < 3; loops++) { |
| 450 unsigned int len, read; | 451 unsigned int len, read; |
| 489 } else { | 490 } else { |
| 490 // Resend Sync message. | 491 // Resend Sync message. |
| 491 TargetASCIIWrite(pSer, "S"); | 492 TargetASCIIWrite(pSer, "S"); |
| 492 } | 493 } |
| 493 | 494 |
| 494 Sleep(1); | 495 CeCosThreadUtils::Sleep(1); |
| 495 delay_mticks++; | 496 delay_mticks++; |
| 496 // Timeout. | 497 // Timeout. |
| 497 if (100 == delay_mticks/10) | 498 if (100 == delay_mticks/10) |
| 498 break; | 499 break; |
| 499 } | 500 } |
| 514 throw msg; | 515 throw msg; |
| 515 } | 516 } |
| 516 | 517 |
| 517 // Set default configuration. | 518 // Set default configuration. |
| 518 void | 519 void |
| 519 CeCosTestSerialFilter::CMD_DefaultConfig(CeCosTestSerial &pSer) | 520 CeCosTestSerialFilter::CMD_DefaultConfig(CeCosSerial &pSer) |
| 520 { | 521 { |
| 521 static const ser_cfg_t default_ser_cfg = { 9600, | 522 static const ser_cfg_t default_ser_cfg = { 9600, |
| 522 8, | 523 8, |
| 523 CeCosTestSerial::ONE_STOP_BIT, | 524 CeCosSerial::ONE_STOP_BIT, |
| 524 false }; | 525 false }; |
| 525 | 526 |
| 526 TargetASCIIWrite(pSer, "OK"); | 527 TargetASCIIWrite(pSer, "OK"); |
| 527 SetConfig(pSer, &default_ser_cfg, NULL); | 528 SetConfig(pSer, &default_ser_cfg, NULL); |
| 528 } | 529 } |
| 532 // <baud rate>:<data bits>:<stop bits>:<parity>:.... | 533 // <baud rate>:<data bits>:<stop bits>:<parity>:.... |
| 533 void | 534 void |
| 534 CeCosTestSerialFilter::ParseConfig(char* args, ser_cfg_t* new_cfg) | 535 CeCosTestSerialFilter::ParseConfig(char* args, ser_cfg_t* new_cfg) |
| 535 { | 536 { |
| 536 int ecos_parity, ecos_stop_bits, ecos_baud_rate; | 537 int ecos_parity, ecos_stop_bits, ecos_baud_rate; |
| 537 CeCosTestSerial::StopBitsType t2h_stop_bits[3] = { | 538 CeCosSerial::StopBitsType t2h_stop_bits[3] = { |
| 538 CeCosTestSerial::ONE_STOP_BIT, | 539 CeCosSerial::ONE_STOP_BIT, |
| 539 CeCosTestSerial::ONE_POINT_FIVE_STOP_BITS, | 540 CeCosSerial::ONE_POINT_FIVE_STOP_BITS, |
| 540 CeCosTestSerial::TWO_STOP_BITS}; | 541 CeCosSerial::TWO_STOP_BITS}; |
| 541 INIT_VALUE(args); | 542 INIT_VALUE(args); |
| 542 | 543 |
| 543 SET_VALUE(int, ecos_baud_rate); | 544 SET_VALUE(int, ecos_baud_rate); |
| 544 SET_VALUE(int, new_cfg->data_bits); | 545 SET_VALUE(int, new_cfg->data_bits); |
| 545 SET_VALUE(int, ecos_stop_bits); | 546 SET_VALUE(int, ecos_stop_bits); |
| 605 | 606 |
| 606 return i; | 607 return i; |
| 607 } | 608 } |
| 608 | 609 |
| 609 void | 610 void |
| 610 CeCosTestSerialFilter::SendChecksum(CeCosTestSerial &pSer, int crc) | 611 CeCosTestSerialFilter::SendChecksum(CeCosSerial &pSer, int crc) |
| 611 { | 612 { |
| 612 char buffer[128]; | 613 char buffer[128]; |
| 613 int len; | 614 int len; |
| 614 | 615 |
| 615 len = sprintf(buffer, "%d!", crc); | 616 len = sprintf(buffer, "%d!", crc); |
| 616 | 617 |
| 617 TargetWrite(pSer, (const unsigned char*)buffer, len); | 618 TargetWrite(pSer, (const unsigned char*)buffer, len); |
| 618 } | 619 } |
| 619 | 620 |
| 620 void | 621 void |
| 621 CeCosTestSerialFilter::SendStatus(CeCosTestSerial &pSer, int state) | 622 CeCosTestSerialFilter::SendStatus(CeCosSerial &pSer, int state) |
| 622 { | 623 { |
| 623 if (state) | 624 if (state) |
| 624 TargetWrite(pSer, (unsigned char*) &msg_ok, 2); | 625 TargetWrite(pSer, (unsigned char*) &msg_ok, 2); |
| 625 else | 626 else |
| 626 TargetWrite(pSer, (unsigned char*) &msg_er, 2); | 627 TargetWrite(pSer, (unsigned char*) &msg_er, 2); |
| 627 } | 628 } |
| 628 | 629 |
| 629 | 630 |
| 630 // Receive test DONE message from target. | 631 // Receive test DONE message from target. |
| 631 void | 632 void |
| 632 CeCosTestSerialFilter::ReceiveDone(CeCosTestSerial &pSer, | 633 CeCosTestSerialFilter::ReceiveDone(CeCosSerial &pSer, |
| 633 unsigned char* data_in, int size) | 634 unsigned char* data_in, int size) |
| 634 { | 635 { |
| 635 static const char msg_done[] = "DONE"; | 636 static const char msg_done[] = "DONE"; |
| 636 unsigned char data_reply[4]; | 637 unsigned char data_reply[4]; |
| 637 int first = 1; | 638 int first = 1; |
| 677 // Test that 0xff gets masked off accordingly when transfered. | 678 // Test that 0xff gets masked off accordingly when transfered. |
| 678 // (This should be an INFO result if failing) | 679 // (This should be an INFO result if failing) |
| 679 // o Clean up the DUPLEX_ECHO implementation. Currently it's an ugly hack | 680 // o Clean up the DUPLEX_ECHO implementation. Currently it's an ugly hack |
| 680 // that doesn't match the arguments / behavior of the two other modes. | 681 // that doesn't match the arguments / behavior of the two other modes. |
| 681 void | 682 void |
| 682 CeCosTestSerialFilter::CMD_TestBinary(CeCosTestSerial &pSer, char* args) | 683 CeCosTestSerialFilter::CMD_TestBinary(CeCosSerial &pSer, char* args) |
| 683 { | 684 { |
| 684 int size; | 685 int size; |
| 685 cyg_mode_t mode; | 686 cyg_mode_t mode; |
| 686 unsigned char *data_out, *data_in; | 687 unsigned char *data_out, *data_in; |
| 687 int i; | 688 int i; |
| 873 // Send OK/ER reply when done. | 874 // Send OK/ER reply when done. |
| 874 // | 875 // |
| 875 // To Do: | 876 // To Do: |
| 876 // Implement. | 877 // Implement. |
| 877 void | 878 void |
| 878 CeCosTestSerialFilter::CMD_TestText(CeCosTestSerial &pSer, char* args) | 879 CeCosTestSerialFilter::CMD_TestText(CeCosSerial &pSer, char* /*args*/) |
| 879 { | 880 { |
| 880 CYG_UNUSED_PARAM(args); | |
| 881 | |
| 882 SendStatus(pSer, 1); | 881 SendStatus(pSer, 1); |
| 883 } | 882 } |
| 884 | 883 |
| 885 //----------------------------------------------------------------------------- | 884 //----------------------------------------------------------------------------- |
| 886 // Reply to PING packet from target. | 885 // Reply to PING packet from target. |
| 887 // Format in: | 886 // Format in: |
| 888 // "!" | 887 // "!" |
| 889 // Format out: | 888 // Format out: |
| 890 // OK | 889 // OK |
| 891 void | 890 void |
| 892 CeCosTestSerialFilter::CMD_TestPing(CeCosTestSerial &pSer, char* args) | 891 CeCosTestSerialFilter::CMD_TestPing(CeCosSerial &pSer, char* /*args*/) |
| 893 { | 892 { |
| 894 CYG_UNUSED_PARAM(args); | |
| 895 | |
| 896 SendStatus(pSer, 1); | 893 SendStatus(pSer, 1); |
| 897 } | 894 } |
| 898 | 895 |
| 899 //----------------------------------------------------------------------------- | 896 //----------------------------------------------------------------------------- |
| 900 // Dispatch test command. | 897 // Dispatch test command. |
| 901 void | 898 void |
| 902 CeCosTestSerialFilter::DispatchCommand(CeCosTestSerial &pSer, char* cmd) | 899 CeCosTestSerialFilter::DispatchCommand(CeCosSerial &pSer, char* cmd) |
| 903 { | 900 { |
| 904 char* args; | 901 char* args; |
| 905 | 902 |
| 906 args = strchr(cmd, (int) ':'); | 903 args = strchr(cmd, (int) ':'); |
| 907 if (!args) { | 904 if (!args) { |
| 936 } | 933 } |
| 937 | 934 |
| 938 bool CALLBACK | 935 bool CALLBACK |
| 939 SerialFilterFunction(void*& pBuf, | 936 SerialFilterFunction(void*& pBuf, |
| 940 unsigned int& nRead, | 937 unsigned int& nRead, |
| 941 CeCosTestSerial& serial, | 938 CeCosSerial& serial, |
| 942 CeCosTestSocket& socket, | 939 CeCosSocket& socket, |
| 943 void* pParem) | 940 void* pParem) |
| 944 { | 941 { |
| 945 CeCosTestSerialFilter* p = (CeCosTestSerialFilter*) pParem; | 942 CeCosTestSerialFilter* p = (CeCosTestSerialFilter*) pParem; |
| 946 return p->FilterFunctionProper(pBuf, nRead, serial, socket); | 943 return p->FilterFunctionProper(pBuf, nRead, serial, socket); |
| 947 } | 944 } |
| 948 | 945 |
| 949 bool | 946 bool |
| 950 CeCosTestSerialFilter::FilterFunctionProper(void*& pBuf, | 947 CeCosTestSerialFilter::FilterFunctionProper(void*& pBuf, |
| 951 unsigned int& nRead, | 948 unsigned int& nRead, |
| 952 CeCosTestSerial& serial, | 949 CeCosSerial& serial, |
| 953 CeCosTestSocket& socket) | 950 CeCosSocket& socket) |
| 954 { | 951 { |
| 955 char* buffer = (char*) pBuf; | 952 char* buffer = (char*) pBuf; |
| 956 | 953 |
| 957 // Don't do anything in the null filter mode. | 954 // Don't do anything in the null filter mode. |
| 958 if (m_bNullFilter) | 955 if (m_bNullFilter) |
