IO plocana FRDM K64

Committer:
bosko001
Date:
Fri Apr 30 00:06:39 2021 +0200
Revision:
15:3429cdc6e5f4
Parent:
7:4aa3dac73b66
ugradjen privremeni timeout 4s i telegram reseta ploce

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bosko001 7:4aa3dac73b66 1 #include "IOspiConnect.h"
bosko001 7:4aa3dac73b66 2 #include "mbed.h"
bosko001 7:4aa3dac73b66 3 #include "IOspitelegram.h"
bosko001 7:4aa3dac73b66 4
bosko001 7:4aa3dac73b66 5
bosko001 7:4aa3dac73b66 6 #include "Pinovi.h"
bosko001 7:4aa3dac73b66 7
bosko001 15:3429cdc6e5f4 8 //static DigitalOut ledZ(LED2,1); /*test */
bosko001 7:4aa3dac73b66 9
bosko001 7:4aa3dac73b66 10 static DigitalOut tast(IO_TELEGRAM_TAS_PIN,0);
bosko001 7:4aa3dac73b66 11
bosko001 7:4aa3dac73b66 12
bosko001 7:4aa3dac73b66 13 /****************************** C_spiConnect ******************************************* */
bosko001 7:4aa3dac73b66 14 C_spiConnect::C_spiConnect( ): /*C_gpioSpi()*/ C_slaveSpi() // C_gpioSpi()
bosko001 7:4aa3dac73b66 15 { byteCount = 0; clear_bitCount(); }
bosko001 7:4aa3dac73b66 16
bosko001 7:4aa3dac73b66 17 void C_spiConnect::spiByteTransfer( char *tx, char rx)
bosko001 7:4aa3dac73b66 18 { *tx = push_byte(rx); }
bosko001 7:4aa3dac73b66 19
bosko001 7:4aa3dac73b66 20 void C_spiConnect::make_TxTelegram( char txcmnd, char rxcmnd, char data)
bosko001 7:4aa3dac73b66 21 { c_tx.make_telegram( txcmnd, rxcmnd, data); }
bosko001 7:4aa3dac73b66 22
bosko001 7:4aa3dac73b66 23 char C_spiConnect::push_byte( char b )
bosko001 7:4aa3dac73b66 24 {
bosko001 7:4aa3dac73b66 25 char spiWriteData = 0x66;
bosko001 7:4aa3dac73b66 26
bosko001 7:4aa3dac73b66 27 if(byteCount != 3 ) bytecountTimeout();
bosko001 7:4aa3dac73b66 28
bosko001 7:4aa3dac73b66 29 if(!tast)
bosko001 7:4aa3dac73b66 30 {
bosko001 7:4aa3dac73b66 31 c_rx.set_byte(byteCount++, b);
bosko001 7:4aa3dac73b66 32
bosko001 7:4aa3dac73b66 33 if(byteCount == 2) // priprema adresnog bajta predajnog telegrama
bosko001 7:4aa3dac73b66 34 {
bosko001 7:4aa3dac73b66 35 c_tx.set_address( );
bosko001 7:4aa3dac73b66 36 spiWriteData = c_tx.get_byte( 0 ); // IOadresa
bosko001 7:4aa3dac73b66 37 }
bosko001 7:4aa3dac73b66 38 else if(byteCount == 3) // predajnog bajta komande read-a telegrama
bosko001 7:4aa3dac73b66 39 {
bosko001 7:4aa3dac73b66 40 c_tx.set_readCommand(c_rx.get_readCommand());
bosko001 7:4aa3dac73b66 41 c_tx.set_writeCommand( 0 );
bosko001 7:4aa3dac73b66 42 spiWriteData = c_tx.get_byte( 1 ); // IOadresa
bosko001 7:4aa3dac73b66 43 }
bosko001 7:4aa3dac73b66 44 else if(byteCount == 4) // analiza celog predajnog telegrama
bosko001 7:4aa3dac73b66 45 {
bosko001 7:4aa3dac73b66 46
bosko001 15:3429cdc6e5f4 47 //loguj_telegram( "prijem = ", c_rx.get_telegram() );
bosko001 7:4aa3dac73b66 48
bosko001 7:4aa3dac73b66 49 if( c_rx.check_sum() ) // provera ispravnosti
bosko001 7:4aa3dac73b66 50 {
bosko001 7:4aa3dac73b66 51 if( c_rx.check_addressValidy( )) // da li je pojedinacna ili grupna adresa validna
bosko001 7:4aa3dac73b66 52 {
bosko001 7:4aa3dac73b66 53 if( c_rx.get_readCommand( )) // da li ima upit za citanje ?
bosko001 7:4aa3dac73b66 54 {
bosko001 7:4aa3dac73b66 55 if( !c_rx.check_groupAddressValidy() ) // ako ima, da li je pojedinacna adresa ispravna
bosko001 7:4aa3dac73b66 56 {
bosko001 7:4aa3dac73b66 57
bosko001 7:4aa3dac73b66 58 // pakujemo odgovor na upit
bosko001 7:4aa3dac73b66 59 char readCommandResult = do_readCommand( c_rx.get_readCommand(), c_rx.get_data() );
bosko001 7:4aa3dac73b66 60 c_tx.set_data( readCommandResult);
bosko001 7:4aa3dac73b66 61 c_tx.set_sum();
bosko001 7:4aa3dac73b66 62 spiWriteData = c_tx.get_data();
bosko001 7:4aa3dac73b66 63 tast = 1;
bosko001 7:4aa3dac73b66 64
bosko001 15:3429cdc6e5f4 65 // ne treba -- loguj_telegram( "priprema predaje = ", c_tx.get_telegram() );
bosko001 7:4aa3dac73b66 66
bosko001 7:4aa3dac73b66 67 }
bosko001 15:3429cdc6e5f4 68 else
bosko001 15:3429cdc6e5f4 69 {
bosko001 15:3429cdc6e5f4 70 //ledZ = !ledZ;
bosko001 15:3429cdc6e5f4 71 do_readGroupCommand( c_rx.get_readCommand() );
bosko001 15:3429cdc6e5f4 72 loguj_broj(c_rx.get_readCommand());
bosko001 15:3429cdc6e5f4 73 loguj_telegram( " grupni telegram = ", c_rx.get_telegram() );
bosko001 15:3429cdc6e5f4 74 }
bosko001 7:4aa3dac73b66 75 } // treba vremenska zastita tastovanja !!!
bosko001 7:4aa3dac73b66 76
bosko001 7:4aa3dac73b66 77 if( c_rx.get_writeCommand() ) // da li ima upis ?
bosko001 7:4aa3dac73b66 78 do_writeCommand( c_rx.get_writeCommand(), c_rx.get_data() );
bosko001 7:4aa3dac73b66 79 }
bosko001 7:4aa3dac73b66 80 }
bosko001 7:4aa3dac73b66 81 else { byteCount = 0; clear_bitCount(); loguj_poruku((const char*)"checksum wrong\n\r"); }
bosko001 7:4aa3dac73b66 82
bosko001 7:4aa3dac73b66 83 byteCount = 0;
bosko001 7:4aa3dac73b66 84 } // buteCount == 4
bosko001 7:4aa3dac73b66 85 else if(byteCount > 4 ) { byteCount = 0; clear_bitCount(); loguj_poruku((const char*)"broj bajtova > 4\n\r");}
bosko001 7:4aa3dac73b66 86
bosko001 7:4aa3dac73b66 87 }
bosko001 7:4aa3dac73b66 88 else /* Predaja tast = 1 */
bosko001 7:4aa3dac73b66 89 {
bosko001 7:4aa3dac73b66 90 if( byteCount++ == 0 ) spiWriteData = c_tx.get_byte( 3 ); // byteCount krenuo od nule
bosko001 7:4aa3dac73b66 91 else
bosko001 7:4aa3dac73b66 92 {
bosko001 7:4aa3dac73b66 93 spiWriteData = 0x0;
bosko001 7:4aa3dac73b66 94
bosko001 7:4aa3dac73b66 95 if(byteCount > 3)
bosko001 7:4aa3dac73b66 96 {
bosko001 7:4aa3dac73b66 97 tast = 0;
bosko001 7:4aa3dac73b66 98 // spiWriteData = 0x7;
bosko001 7:4aa3dac73b66 99 byteCount = 0;
bosko001 15:3429cdc6e5f4 100 // loguj_telegram( "predaja = ", c_tx.get_telegram() );
bosko001 7:4aa3dac73b66 101 }
bosko001 7:4aa3dac73b66 102 }
bosko001 7:4aa3dac73b66 103 }
bosko001 7:4aa3dac73b66 104
bosko001 7:4aa3dac73b66 105
bosko001 7:4aa3dac73b66 106
bosko001 7:4aa3dac73b66 107 // loguj_string_broj( "predajni bajt:", spiWriteData);
bosko001 7:4aa3dac73b66 108 return spiWriteData;
bosko001 7:4aa3dac73b66 109 }
bosko001 7:4aa3dac73b66 110
bosko001 7:4aa3dac73b66 111 /************************************************************************* */