K22 processor

Committer:
bosko001
Date:
Sun Mar 21 18:20:15 2021 +0100
Revision:
7:4aa3dac73b66
Child:
15:3429cdc6e5f4
novi pocetak

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 7:4aa3dac73b66 8
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 7:4aa3dac73b66 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 7:4aa3dac73b66 65 loguj_telegram( "priprema predaje = ", c_tx.get_telegram() );
bosko001 7:4aa3dac73b66 66
bosko001 7:4aa3dac73b66 67 }
bosko001 7:4aa3dac73b66 68 else c_rx.do_readGroupCommand( c_rx.get_readCommand() );
bosko001 7:4aa3dac73b66 69 } // treba vremenska zastita tastovanja !!!
bosko001 7:4aa3dac73b66 70
bosko001 7:4aa3dac73b66 71 if( c_rx.get_writeCommand() ) // da li ima upis ?
bosko001 7:4aa3dac73b66 72 do_writeCommand( c_rx.get_writeCommand(), c_rx.get_data() );
bosko001 7:4aa3dac73b66 73 }
bosko001 7:4aa3dac73b66 74 }
bosko001 7:4aa3dac73b66 75 else { byteCount = 0; clear_bitCount(); loguj_poruku((const char*)"checksum wrong\n\r"); }
bosko001 7:4aa3dac73b66 76
bosko001 7:4aa3dac73b66 77 byteCount = 0;
bosko001 7:4aa3dac73b66 78 } // buteCount == 4
bosko001 7:4aa3dac73b66 79 else if(byteCount > 4 ) { byteCount = 0; clear_bitCount(); loguj_poruku((const char*)"broj bajtova > 4\n\r");}
bosko001 7:4aa3dac73b66 80
bosko001 7:4aa3dac73b66 81 }
bosko001 7:4aa3dac73b66 82 else /* Predaja tast = 1 */
bosko001 7:4aa3dac73b66 83 {
bosko001 7:4aa3dac73b66 84 if( byteCount++ == 0 ) spiWriteData = c_tx.get_byte( 3 ); // byteCount krenuo od nule
bosko001 7:4aa3dac73b66 85 else
bosko001 7:4aa3dac73b66 86 {
bosko001 7:4aa3dac73b66 87 spiWriteData = 0x0;
bosko001 7:4aa3dac73b66 88
bosko001 7:4aa3dac73b66 89 if(byteCount > 3)
bosko001 7:4aa3dac73b66 90 {
bosko001 7:4aa3dac73b66 91 tast = 0;
bosko001 7:4aa3dac73b66 92 // spiWriteData = 0x7;
bosko001 7:4aa3dac73b66 93 byteCount = 0;
bosko001 7:4aa3dac73b66 94 loguj_telegram( "predaja = ", c_tx.get_telegram() );
bosko001 7:4aa3dac73b66 95 }
bosko001 7:4aa3dac73b66 96 }
bosko001 7:4aa3dac73b66 97 }
bosko001 7:4aa3dac73b66 98
bosko001 7:4aa3dac73b66 99
bosko001 7:4aa3dac73b66 100
bosko001 7:4aa3dac73b66 101 // loguj_string_broj( "predajni bajt:", spiWriteData);
bosko001 7:4aa3dac73b66 102 return spiWriteData;
bosko001 7:4aa3dac73b66 103 }
bosko001 7:4aa3dac73b66 104
bosko001 7:4aa3dac73b66 105 /************************************************************************* */