bosko lekovic
/
IO_board
IO plocana FRDM K64
main.cpp
- Committer:
- bosko001
- Date:
- 2021-04-24
- Revision:
- 13:7c4ec32f6a54
- Parent:
- 10:5de7b6e77c4a
- Child:
- 14:b63e4664e2a8
File content as of revision 13:7c4ec32f6a54:
/* mbed Microcontroller Library * Copyright (c) 2019 ARM Limited * SPDX-License-Identifier: Apache-2.0 */ #include "mbed.h" #include "platform/mbed_thread.h" #include <vector> #include "Pinovi.h" // #include "IOspiLed.h" #include "ledControl.h" // #include "IOgpiospi.h" // #include "IOspitelegram.h" #include "IOspiprotokol.h" #include "ZeroCrossing.h" #include "IOzcControl.h" extern vector< S_logTelegram> s_log; // Blinking rate in milliseconds #define BLINKING_RATE_MS 200 DigitalOut ioTest(IO_TEST,0); char verzija = 5; DigitalIn b2(SW2); DigitalOut ledB(LED3,1); class C_data c_data; C_ledControl c_ledControl(&c_data);//( &c_ledLight); C_spiProtokol c_spiProtokol( &c_data, &c_ledControl ); C_zeroCrossing c_zeroCrossing( &c_data); C_zeroCrossing& rc_zc = c_zeroCrossing; C_zcControl c_zcControl( &c_zeroCrossing, &c_spiProtokol); //DigitalOut pola( PTB20, 0); // test zero crossing ivica Ticker test_RasaLed; DigitalOut RasaLed(PTE0,1); int tz; int main() { // Initialise the digital pin LED1 as an output printf("\n\n\r ____________ POCETAK IOboard_______________\n\r"); s_log.resize(1000); s_log.clear(); printf( " capacity %d max_size %d size %d\n\r", s_log.capacity(), s_log.max_size(), s_log.size()); test_RasaLed.attach_us([=]{ RasaLed = !RasaLed;}, 500000 ); /* postavljanje funkcija za komande i indikaciju sinhrono sa zero crossing-om */ static int block_delay = 0; // uzlazni prolaz kroz nulu - izvrsenje komande c_zeroCrossing.set_ontimeONfun( []() { // testPin =! testPin; rc_zc.set_portOut( c_data.get_command() ); // upis komande na port if( c_data.get_newcommand_flag() == true) { block_delay = 1; } // blokirati citanje indikacija posle novodobijene komande else if(block_delay) { block_delay--; } else { c_data.set_messagge(); c_data.set_realIndication();} } ); c_zeroCrossing.set_ontimeOFFfun( [](){ } ); // minimum mreze - rad sa indikacijama ispravnosti sijalica c_zeroCrossing.set_postponeONfun( []() { if(block_delay == 0 && (c_data.check_newcommand_flag()== false) ) { char p1 = rc_zc.get_portInMin(); // dva ocitavanja porta wait_us(10); char p2 = rc_zc.get_portInMin(); p1 &= p2; c_data.set_pMin( p1 ); // upis vrednosti minimuma mreze u C_data c_data.set_indication(); // proracun i upis indikacije u C_data c_data.set_corectness(); // proracun i upis ispravnosti sijalice c_data.set_realIndication(); // izracun aktuelne indikacije - spremna za slanje na LEDove } else c_data.clear_pMin(); } ); // maximum mreze - rad sa neispravnim naponom - misem c_zeroCrossing.set_postponeOFFfun( []() { static int i=0, j=0; if(block_delay == 0 && (c_data.check_newcommand_flag()== false)) { ledB =!ledB; char p1 = rc_zc.get_portInMax(); // dva ocitavanja porta wait_us(10); char p2 = rc_zc.get_portInMax(); p1 |= p2; c_data.set_pMax( p1 ); // upis vrednosti maksimuma mreze c_data.set_faultVoltage(); // izracun i upis napona misa } else c_data.clear_pMax(); } ); int b = b2; /* konzolu napraciti kao klasu koja nasledjuje C_thread klasu */ extern void consolafun( void ); Thread th_consola; th_consola.start( consolafun); /* cekanje da se procita prva ispravna adresa sa dip switch-a */ do { ThisThread::sleep_for(10ms);;c_spiProtokol.inic_address( ); } while ( c_data.get_address() == 0 ); printf(" adresa je = %d\n\r", c_data.get_address()); // postavljanje sopstvene adrese i prikaz na ledovima c_spiProtokol.set_myAddress(c_data.get_address()); c_ledControl.set_colorTemplate_Green(); c_ledControl.set_ledView(adresa); while (true) { if( b!= b2) { b = b2; if( b ) { ledB = 1;} else { ledB = 0; //printf( " bitCount = %d, byteCount = %d\n\r", c_spiProtokol.get_bitCount(), c_spiProtokol.get_byteCount()); printf( " zerocrossing timer on = %d off = %d \n\r", c_zeroCrossing.get_zcTimeON(), c_zeroCrossing.get_zcTimeOFF()); // printf(" port in %x\n\r", rc_zc.s_portinMin.get_port() ); printf(" adresa je = %d\n\r", c_data.get_address()); } } c_spiProtokol.spi_monitor(); thread_sleep_for(BLINKING_RATE_MS); } } void consolafun( void ) { while( true ) { char uc = getchar( ); switch( (unsigned char) uc ) { case 'r': case 'R': printf("\n\rcitanje registra, unesi broj:\n\r"); int r; scanf("%x", &r); // printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r)); break; case 'w': case 'W': { printf("\n\rupis registra, unesi broj registra:"); int r; scanf("%x", &r); printf( " %x", r ); printf("\n\runesi vrednost registra:"); int v; scanf("%x", &v); printf( " %x", v ); // printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r)); } break; case 's': case 'S': // set_shiftspi_signal( ); break; case 'c': s_log.clear(); //break; case 'l': printf( " capacity %d max_size %d size %d\n\r", s_log.capacity(), s_log.max_size(), s_log.size()); break; case 'p': int i=1; if(s_log.size()) { for( auto it = s_log.end()-1; it != s_log.begin(); it--) printf( "%3d %s\n\r", i++, (*it).poruka); auto it = s_log.begin(); printf( "%3d %s\n\r", i++, (*it).poruka ); } break; } ThisThread::yield(); thread_sleep_for(100); } }