bosko lekovic
/
IO_board_K22
K22 processor
main.cpp@13:7c4ec32f6a54, 2021-04-24 (annotated)
- Committer:
- bosko001
- Date:
- Sat Apr 24 18:48:38 2021 +0200
- Revision:
- 13:7c4ec32f6a54
- Parent:
- 10:5de7b6e77c4a
- Child:
- 14:b63e4664e2a8
lagano sredjivanje main-a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko001 | 0:c06c791ca345 | 1 | /* mbed Microcontroller Library |
bosko001 | 0:c06c791ca345 | 2 | * Copyright (c) 2019 ARM Limited |
bosko001 | 0:c06c791ca345 | 3 | * SPDX-License-Identifier: Apache-2.0 |
bosko001 | 0:c06c791ca345 | 4 | */ |
bosko001 | 0:c06c791ca345 | 5 | |
bosko001 | 0:c06c791ca345 | 6 | #include "mbed.h" |
bosko001 | 0:c06c791ca345 | 7 | #include "platform/mbed_thread.h" |
bosko001 | 6:12b2660d7dff | 8 | #include <vector> |
bosko001 | 0:c06c791ca345 | 9 | |
bosko001 | 6:12b2660d7dff | 10 | #include "Pinovi.h" |
bosko001 | 6:12b2660d7dff | 11 | // #include "IOspiLed.h" |
bosko001 | 6:12b2660d7dff | 12 | #include "ledControl.h" |
bosko001 | 6:12b2660d7dff | 13 | |
bosko001 | 6:12b2660d7dff | 14 | |
bosko001 | 6:12b2660d7dff | 15 | // #include "IOgpiospi.h" |
bosko001 | 6:12b2660d7dff | 16 | // #include "IOspitelegram.h" |
bosko001 | 6:12b2660d7dff | 17 | #include "IOspiprotokol.h" |
bosko001 | 6:12b2660d7dff | 18 | |
bosko001 | 6:12b2660d7dff | 19 | #include "ZeroCrossing.h" |
bosko001 | 6:12b2660d7dff | 20 | #include "IOzcControl.h" |
bosko001 | 6:12b2660d7dff | 21 | |
bosko001 | 6:12b2660d7dff | 22 | |
bosko001 | 6:12b2660d7dff | 23 | extern vector< S_logTelegram> s_log; |
bosko001 | 0:c06c791ca345 | 24 | |
bosko001 | 8:5a96bfb6b6f9 | 25 | |
bosko001 | 8:5a96bfb6b6f9 | 26 | |
bosko001 | 0:c06c791ca345 | 27 | // Blinking rate in milliseconds |
bosko001 | 0:c06c791ca345 | 28 | #define BLINKING_RATE_MS 200 |
bosko001 | 0:c06c791ca345 | 29 | |
bosko001 | 6:12b2660d7dff | 30 | DigitalOut ioTest(IO_TEST,0); |
bosko001 | 0:c06c791ca345 | 31 | |
bosko001 | 13:7c4ec32f6a54 | 32 | |
bosko001 | 6:12b2660d7dff | 33 | |
bosko001 | 6:12b2660d7dff | 34 | |
bosko001 | 6:12b2660d7dff | 35 | char verzija = 5; |
bosko001 | 0:c06c791ca345 | 36 | |
bosko001 | 0:c06c791ca345 | 37 | |
bosko001 | 0:c06c791ca345 | 38 | DigitalIn b2(SW2); |
bosko001 | 0:c06c791ca345 | 39 | |
bosko001 | 6:12b2660d7dff | 40 | DigitalOut ledB(LED3,1); |
bosko001 | 0:c06c791ca345 | 41 | |
bosko001 | 0:c06c791ca345 | 42 | |
bosko001 | 3:71278c5b7c67 | 43 | |
bosko001 | 0:c06c791ca345 | 44 | |
bosko001 | 6:12b2660d7dff | 45 | class C_data c_data; |
bosko001 | 6:12b2660d7dff | 46 | |
bosko001 | 6:12b2660d7dff | 47 | |
bosko001 | 6:12b2660d7dff | 48 | C_ledControl c_ledControl(&c_data);//( &c_ledLight); |
bosko001 | 6:12b2660d7dff | 49 | |
bosko001 | 6:12b2660d7dff | 50 | C_spiProtokol c_spiProtokol( &c_data, &c_ledControl ); |
bosko001 | 6:12b2660d7dff | 51 | |
bosko001 | 6:12b2660d7dff | 52 | C_zeroCrossing c_zeroCrossing( &c_data); |
bosko001 | 6:12b2660d7dff | 53 | C_zeroCrossing& rc_zc = c_zeroCrossing; |
bosko001 | 6:12b2660d7dff | 54 | |
bosko001 | 6:12b2660d7dff | 55 | C_zcControl c_zcControl( &c_zeroCrossing, &c_spiProtokol); |
bosko001 | 6:12b2660d7dff | 56 | |
bosko001 | 6:12b2660d7dff | 57 | //DigitalOut pola( PTB20, 0); // test zero crossing ivica |
bosko001 | 6:12b2660d7dff | 58 | |
bosko001 | 6:12b2660d7dff | 59 | |
bosko001 | 6:12b2660d7dff | 60 | Ticker test_RasaLed; |
bosko001 | 6:12b2660d7dff | 61 | DigitalOut RasaLed(PTE0,1); |
bosko001 | 6:12b2660d7dff | 62 | |
bosko001 | 13:7c4ec32f6a54 | 63 | int tz; |
bosko001 | 13:7c4ec32f6a54 | 64 | |
bosko001 | 0:c06c791ca345 | 65 | |
bosko001 | 0:c06c791ca345 | 66 | int main() |
bosko001 | 0:c06c791ca345 | 67 | { |
bosko001 | 6:12b2660d7dff | 68 | |
bosko001 | 0:c06c791ca345 | 69 | // Initialise the digital pin LED1 as an output |
bosko001 | 6:12b2660d7dff | 70 | |
bosko001 | 4:fce988d27938 | 71 | printf("\n\n\r ____________ POCETAK IOboard_______________\n\r"); |
bosko001 | 0:c06c791ca345 | 72 | |
bosko001 | 6:12b2660d7dff | 73 | s_log.resize(1000); |
bosko001 | 6:12b2660d7dff | 74 | s_log.clear(); |
bosko001 | 6:12b2660d7dff | 75 | |
bosko001 | 6:12b2660d7dff | 76 | printf( " capacity %d max_size %d size %d\n\r", s_log.capacity(), s_log.max_size(), s_log.size()); |
bosko001 | 6:12b2660d7dff | 77 | test_RasaLed.attach_us([=]{ RasaLed = !RasaLed;}, 500000 ); |
bosko001 | 6:12b2660d7dff | 78 | |
bosko001 | 6:12b2660d7dff | 79 | /* postavljanje funkcija za komande i indikaciju sinhrono sa zero crossing-om */ |
bosko001 | 6:12b2660d7dff | 80 | |
bosko001 | 13:7c4ec32f6a54 | 81 | static int block_delay = 0; |
bosko001 | 13:7c4ec32f6a54 | 82 | |
bosko001 | 13:7c4ec32f6a54 | 83 | // uzlazni prolaz kroz nulu - izvrsenje komande |
bosko001 | 6:12b2660d7dff | 84 | c_zeroCrossing.set_ontimeONfun( []() |
bosko001 | 6:12b2660d7dff | 85 | { |
bosko001 | 6:12b2660d7dff | 86 | // testPin =! testPin; |
bosko001 | 13:7c4ec32f6a54 | 87 | rc_zc.set_portOut( c_data.get_command() ); // upis komande na port |
bosko001 | 13:7c4ec32f6a54 | 88 | if( c_data.get_newcommand_flag() == true) { block_delay = 1; } // blokirati citanje indikacija posle novodobijene komande |
bosko001 | 13:7c4ec32f6a54 | 89 | else if(block_delay) { block_delay--; } |
bosko001 | 6:12b2660d7dff | 90 | else { c_data.set_messagge(); c_data.set_realIndication();} |
bosko001 | 6:12b2660d7dff | 91 | } |
bosko001 | 6:12b2660d7dff | 92 | ); |
bosko001 | 6:12b2660d7dff | 93 | c_zeroCrossing.set_ontimeOFFfun( [](){ } ); |
bosko001 | 13:7c4ec32f6a54 | 94 | |
bosko001 | 13:7c4ec32f6a54 | 95 | // minimum mreze - rad sa indikacijama ispravnosti sijalica |
bosko001 | 13:7c4ec32f6a54 | 96 | c_zeroCrossing.set_postponeONfun( []() |
bosko001 | 6:12b2660d7dff | 97 | { |
bosko001 | 13:7c4ec32f6a54 | 98 | if(block_delay == 0 && (c_data.check_newcommand_flag()== false) ) |
bosko001 | 6:12b2660d7dff | 99 | { |
bosko001 | 6:12b2660d7dff | 100 | char p1 = rc_zc.get_portInMin(); // dva ocitavanja porta |
bosko001 | 6:12b2660d7dff | 101 | wait_us(10); |
bosko001 | 6:12b2660d7dff | 102 | char p2 = rc_zc.get_portInMin(); |
bosko001 | 6:12b2660d7dff | 103 | p1 &= p2; |
Bosko Lekovic |
10:5de7b6e77c4a | 104 | c_data.set_pMin( p1 ); // upis vrednosti minimuma mreze u C_data |
Bosko Lekovic |
10:5de7b6e77c4a | 105 | c_data.set_indication(); // proracun i upis indikacije u C_data |
Bosko Lekovic |
10:5de7b6e77c4a | 106 | c_data.set_corectness(); // proracun i upis ispravnosti sijalice |
Bosko Lekovic |
10:5de7b6e77c4a | 107 | c_data.set_realIndication(); // izracun aktuelne indikacije - spremna za slanje na LEDove |
bosko001 | 4:fce988d27938 | 108 | |
bosko001 | 13:7c4ec32f6a54 | 109 | |
bosko001 | 6:12b2660d7dff | 110 | } |
bosko001 | 6:12b2660d7dff | 111 | else c_data.clear_pMin(); |
bosko001 | 6:12b2660d7dff | 112 | } |
bosko001 | 6:12b2660d7dff | 113 | ); |
bosko001 | 13:7c4ec32f6a54 | 114 | |
bosko001 | 13:7c4ec32f6a54 | 115 | |
bosko001 | 13:7c4ec32f6a54 | 116 | // maximum mreze - rad sa neispravnim naponom - misem |
bosko001 | 13:7c4ec32f6a54 | 117 | c_zeroCrossing.set_postponeOFFfun( []() |
bosko001 | 6:12b2660d7dff | 118 | { |
bosko001 | 6:12b2660d7dff | 119 | static int i=0, j=0; |
bosko001 | 13:7c4ec32f6a54 | 120 | if(block_delay == 0 && (c_data.check_newcommand_flag()== false)) |
bosko001 | 6:12b2660d7dff | 121 | { |
bosko001 | 6:12b2660d7dff | 122 | ledB =!ledB; |
bosko001 | 6:12b2660d7dff | 123 | char p1 = rc_zc.get_portInMax(); // dva ocitavanja porta |
bosko001 | 6:12b2660d7dff | 124 | wait_us(10); |
bosko001 | 6:12b2660d7dff | 125 | char p2 = rc_zc.get_portInMax(); |
bosko001 | 6:12b2660d7dff | 126 | p1 |= p2; |
bosko001 | 13:7c4ec32f6a54 | 127 | c_data.set_pMax( p1 ); // upis vrednosti maksimuma mreze |
bosko001 | 13:7c4ec32f6a54 | 128 | c_data.set_faultVoltage(); // izracun i upis napona misa |
bosko001 | 13:7c4ec32f6a54 | 129 | |
bosko001 | 6:12b2660d7dff | 130 | |
bosko001 | 13:7c4ec32f6a54 | 131 | } |
bosko001 | 6:12b2660d7dff | 132 | else c_data.clear_pMax(); |
bosko001 | 6:12b2660d7dff | 133 | |
bosko001 | 6:12b2660d7dff | 134 | } ); |
bosko001 | 6:12b2660d7dff | 135 | |
bosko001 | 0:c06c791ca345 | 136 | |
bosko001 | 0:c06c791ca345 | 137 | int b = b2; |
bosko001 | 0:c06c791ca345 | 138 | |
bosko001 | 6:12b2660d7dff | 139 | /* konzolu napraciti kao klasu koja nasledjuje C_thread klasu */ |
bosko001 | 6:12b2660d7dff | 140 | extern void consolafun( void ); |
bosko001 | 6:12b2660d7dff | 141 | Thread th_consola; |
bosko001 | 6:12b2660d7dff | 142 | th_consola.start( consolafun); |
bosko001 | 6:12b2660d7dff | 143 | |
bosko001 | 6:12b2660d7dff | 144 | /* cekanje da se procita prva ispravna adresa sa dip switch-a */ |
bosko001 | 6:12b2660d7dff | 145 | do { ThisThread::sleep_for(10ms);;c_spiProtokol.inic_address( ); } |
bosko001 | 6:12b2660d7dff | 146 | while ( c_data.get_address() == 0 ); |
bosko001 | 6:12b2660d7dff | 147 | printf(" adresa je = %d\n\r", c_data.get_address()); |
bosko001 | 6:12b2660d7dff | 148 | |
bosko001 | 6:12b2660d7dff | 149 | // postavljanje sopstvene adrese i prikaz na ledovima |
bosko001 | 6:12b2660d7dff | 150 | c_spiProtokol.set_myAddress(c_data.get_address()); |
bosko001 | 6:12b2660d7dff | 151 | c_ledControl.set_colorTemplate_Green(); |
bosko001 | 6:12b2660d7dff | 152 | c_ledControl.set_ledView(adresa); |
bosko001 | 6:12b2660d7dff | 153 | |
bosko001 | 4:fce988d27938 | 154 | |
bosko001 | 0:c06c791ca345 | 155 | while (true) |
bosko001 | 0:c06c791ca345 | 156 | { |
bosko001 | 0:c06c791ca345 | 157 | |
bosko001 | 4:fce988d27938 | 158 | |
bosko001 | 0:c06c791ca345 | 159 | if( b!= b2) |
bosko001 | 0:c06c791ca345 | 160 | { |
bosko001 | 0:c06c791ca345 | 161 | b = b2; |
bosko001 | 6:12b2660d7dff | 162 | if( b ) { ledB = 1;} |
bosko001 | 6:12b2660d7dff | 163 | else { ledB = 0; //printf( " bitCount = %d, byteCount = %d\n\r", c_spiProtokol.get_bitCount(), c_spiProtokol.get_byteCount()); |
bosko001 | 6:12b2660d7dff | 164 | |
bosko001 | 6:12b2660d7dff | 165 | printf( " zerocrossing timer on = %d off = %d \n\r", c_zeroCrossing.get_zcTimeON(), c_zeroCrossing.get_zcTimeOFF()); |
bosko001 | 6:12b2660d7dff | 166 | // printf(" port in %x\n\r", rc_zc.s_portinMin.get_port() ); |
bosko001 | 6:12b2660d7dff | 167 | printf(" adresa je = %d\n\r", c_data.get_address()); |
bosko001 | 6:12b2660d7dff | 168 | } |
bosko001 | 0:c06c791ca345 | 169 | } |
bosko001 | 6:12b2660d7dff | 170 | |
bosko001 | 6:12b2660d7dff | 171 | c_spiProtokol.spi_monitor(); |
bosko001 | 0:c06c791ca345 | 172 | |
bosko001 | 0:c06c791ca345 | 173 | |
bosko001 | 0:c06c791ca345 | 174 | thread_sleep_for(BLINKING_RATE_MS); |
bosko001 | 0:c06c791ca345 | 175 | } |
bosko001 | 0:c06c791ca345 | 176 | } |
bosko001 | 0:c06c791ca345 | 177 | |
bosko001 | 0:c06c791ca345 | 178 | |
bosko001 | 0:c06c791ca345 | 179 | |
bosko001 | 0:c06c791ca345 | 180 | void consolafun( void ) |
bosko001 | 0:c06c791ca345 | 181 | { |
bosko001 | 0:c06c791ca345 | 182 | while( true ) |
bosko001 | 0:c06c791ca345 | 183 | { |
bosko001 | 6:12b2660d7dff | 184 | |
bosko001 | 0:c06c791ca345 | 185 | char uc = getchar( ); |
bosko001 | 0:c06c791ca345 | 186 | switch( (unsigned char) uc ) |
bosko001 | 0:c06c791ca345 | 187 | { |
bosko001 | 0:c06c791ca345 | 188 | case 'r': case 'R': |
bosko001 | 0:c06c791ca345 | 189 | |
bosko001 | 0:c06c791ca345 | 190 | printf("\n\rcitanje registra, unesi broj:\n\r"); |
bosko001 | 0:c06c791ca345 | 191 | int r; |
bosko001 | 0:c06c791ca345 | 192 | scanf("%x", &r); |
bosko001 | 1:1052d6227111 | 193 | // printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r)); |
bosko001 | 0:c06c791ca345 | 194 | |
bosko001 | 0:c06c791ca345 | 195 | break; |
bosko001 | 0:c06c791ca345 | 196 | case 'w': case 'W': |
bosko001 | 0:c06c791ca345 | 197 | { |
bosko001 | 0:c06c791ca345 | 198 | printf("\n\rupis registra, unesi broj registra:"); |
bosko001 | 0:c06c791ca345 | 199 | int r; |
bosko001 | 0:c06c791ca345 | 200 | scanf("%x", &r); |
bosko001 | 0:c06c791ca345 | 201 | printf( " %x", r ); |
bosko001 | 0:c06c791ca345 | 202 | printf("\n\runesi vrednost registra:"); |
bosko001 | 0:c06c791ca345 | 203 | int v; |
bosko001 | 0:c06c791ca345 | 204 | scanf("%x", &v); |
bosko001 | 0:c06c791ca345 | 205 | printf( " %x", v ); |
bosko001 | 1:1052d6227111 | 206 | // printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r)); |
bosko001 | 0:c06c791ca345 | 207 | } |
bosko001 | 0:c06c791ca345 | 208 | break; |
bosko001 | 4:fce988d27938 | 209 | case 's': case 'S': |
bosko001 | 6:12b2660d7dff | 210 | // set_shiftspi_signal( ); |
bosko001 | 4:fce988d27938 | 211 | break; |
bosko001 | 4:fce988d27938 | 212 | |
bosko001 | 6:12b2660d7dff | 213 | case 'c': |
bosko001 | 6:12b2660d7dff | 214 | s_log.clear(); |
bosko001 | 6:12b2660d7dff | 215 | //break; |
bosko001 | 6:12b2660d7dff | 216 | case 'l': |
bosko001 | 6:12b2660d7dff | 217 | printf( " capacity %d max_size %d size %d\n\r", s_log.capacity(), s_log.max_size(), s_log.size()); |
bosko001 | 6:12b2660d7dff | 218 | break; |
bosko001 | 6:12b2660d7dff | 219 | case 'p': |
bosko001 | 6:12b2660d7dff | 220 | int i=1; |
bosko001 | 6:12b2660d7dff | 221 | if(s_log.size()) |
bosko001 | 6:12b2660d7dff | 222 | { |
bosko001 | 6:12b2660d7dff | 223 | for( auto it = s_log.end()-1; it != s_log.begin(); it--) |
bosko001 | 6:12b2660d7dff | 224 | printf( "%3d %s\n\r", i++, (*it).poruka); |
bosko001 | 6:12b2660d7dff | 225 | auto it = s_log.begin(); |
bosko001 | 6:12b2660d7dff | 226 | printf( "%3d %s\n\r", i++, (*it).poruka ); |
bosko001 | 6:12b2660d7dff | 227 | } |
bosko001 | 6:12b2660d7dff | 228 | break; |
bosko001 | 0:c06c791ca345 | 229 | } |
bosko001 | 3:71278c5b7c67 | 230 | ThisThread::yield(); |
bosko001 | 3:71278c5b7c67 | 231 | thread_sleep_for(100); |
bosko001 | 0:c06c791ca345 | 232 | } |
bosko001 | 0:c06c791ca345 | 233 | } |