IO plocana FRDM K64

Committer:
bosko001
Date:
Sun Mar 21 22:20:23 2021 +0100
Revision:
9:a4360a7713f5
Parent:
8:5a96bfb6b6f9
Child:
10:5de7b6e77c4a
IO_board

Who changed what in which revision?

UserRevisionLine numberNew 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 8:5a96bfb6b6f9 27
bosko001 9:a4360a7713f5 28
bosko001 0:c06c791ca345 29 // Blinking rate in milliseconds
bosko001 0:c06c791ca345 30 #define BLINKING_RATE_MS 200
bosko001 0:c06c791ca345 31
bosko001 6:12b2660d7dff 32 DigitalOut ioTest(IO_TEST,0);
bosko001 0:c06c791ca345 33
bosko001 6:12b2660d7dff 34 DigitalOut testPin(PTE24, 0 );
bosko001 6:12b2660d7dff 35
bosko001 6:12b2660d7dff 36
bosko001 6:12b2660d7dff 37 char verzija = 5;
bosko001 0:c06c791ca345 38
bosko001 0:c06c791ca345 39
bosko001 0:c06c791ca345 40 DigitalIn b2(SW2);
bosko001 0:c06c791ca345 41
bosko001 6:12b2660d7dff 42 DigitalOut ledB(LED3,1);
bosko001 0:c06c791ca345 43
bosko001 0:c06c791ca345 44
bosko001 3:71278c5b7c67 45
bosko001 0:c06c791ca345 46
bosko001 6:12b2660d7dff 47 class C_data c_data;
bosko001 6:12b2660d7dff 48
bosko001 6:12b2660d7dff 49
bosko001 6:12b2660d7dff 50 C_ledControl c_ledControl(&c_data);//( &c_ledLight);
bosko001 6:12b2660d7dff 51
bosko001 6:12b2660d7dff 52 C_spiProtokol c_spiProtokol( &c_data, &c_ledControl );
bosko001 6:12b2660d7dff 53
bosko001 6:12b2660d7dff 54 C_zeroCrossing c_zeroCrossing( &c_data);
bosko001 6:12b2660d7dff 55 C_zeroCrossing& rc_zc = c_zeroCrossing;
bosko001 6:12b2660d7dff 56
bosko001 6:12b2660d7dff 57 C_zcControl c_zcControl( &c_zeroCrossing, &c_spiProtokol);
bosko001 6:12b2660d7dff 58
bosko001 6:12b2660d7dff 59 //DigitalOut pola( PTB20, 0); // test zero crossing ivica
bosko001 6:12b2660d7dff 60
bosko001 6:12b2660d7dff 61
bosko001 6:12b2660d7dff 62 Ticker test_RasaLed;
bosko001 6:12b2660d7dff 63 DigitalOut RasaLed(PTE0,1);
bosko001 6:12b2660d7dff 64
bosko001 6:12b2660d7dff 65 long t; int tz;
bosko001 6:12b2660d7dff 66 int v1, v2, v3, v4,v5,v6,f=0;
bosko001 6:12b2660d7dff 67 int time_delay = 0, time_flag=0;
bosko001 0:c06c791ca345 68
bosko001 0:c06c791ca345 69 int main()
bosko001 0:c06c791ca345 70 {
bosko001 6:12b2660d7dff 71
bosko001 0:c06c791ca345 72 // Initialise the digital pin LED1 as an output
bosko001 6:12b2660d7dff 73
bosko001 4:fce988d27938 74 printf("\n\n\r ____________ POCETAK IOboard_______________\n\r");
bosko001 0:c06c791ca345 75
bosko001 6:12b2660d7dff 76 s_log.resize(1000);
bosko001 6:12b2660d7dff 77 s_log.clear();
bosko001 6:12b2660d7dff 78
bosko001 6:12b2660d7dff 79 printf( " capacity %d max_size %d size %d\n\r", s_log.capacity(), s_log.max_size(), s_log.size());
bosko001 6:12b2660d7dff 80 test_RasaLed.attach_us([=]{ RasaLed = !RasaLed;}, 500000 );
bosko001 6:12b2660d7dff 81
bosko001 6:12b2660d7dff 82 /* postavljanje funkcija za komande i indikaciju sinhrono sa zero crossing-om */
bosko001 6:12b2660d7dff 83
bosko001 6:12b2660d7dff 84
bosko001 6:12b2660d7dff 85 c_zeroCrossing.set_ontimeONfun( []()
bosko001 6:12b2660d7dff 86 {
bosko001 6:12b2660d7dff 87 // testPin =! testPin;
bosko001 6:12b2660d7dff 88 rc_zc.set_portOut( c_data.get_command() );//
bosko001 6:12b2660d7dff 89 if( c_data.get_newcommand_flag() == true) { time_delay = 1; t = (long)Kernel::get_ms_count(); }// vreme = time_delay * 20ms
bosko001 6:12b2660d7dff 90 else if(time_delay) { time_delay--; if( time_delay == 0 ) time_flag = 1; }
bosko001 6:12b2660d7dff 91 else { c_data.set_messagge(); c_data.set_realIndication();}
bosko001 6:12b2660d7dff 92 }
bosko001 6:12b2660d7dff 93 );
bosko001 6:12b2660d7dff 94 c_zeroCrossing.set_ontimeOFFfun( [](){ } );
bosko001 6:12b2660d7dff 95 c_zeroCrossing.set_postponeONfun( []() // minimum mreze - rad sa indikacijama ispravnosti sijalica
bosko001 6:12b2660d7dff 96 {
bosko001 6:12b2660d7dff 97 if(time_delay == 0 && (c_data.check_newcommand_flag()== false) )
bosko001 6:12b2660d7dff 98 {
bosko001 6:12b2660d7dff 99 char p1 = rc_zc.get_portInMin(); // dva ocitavanja porta
bosko001 6:12b2660d7dff 100 wait_us(10);
bosko001 6:12b2660d7dff 101 char p2 = rc_zc.get_portInMin();
bosko001 6:12b2660d7dff 102 p1 &= p2;
bosko001 6:12b2660d7dff 103 c_data.set_pMin( p1 );
bosko001 6:12b2660d7dff 104 c_data.set_indication();
bosko001 6:12b2660d7dff 105 c_data.set_corectness();
bosko001 6:12b2660d7dff 106 c_data.set_realIndication();
bosko001 4:fce988d27938 107
bosko001 6:12b2660d7dff 108 // ledB =!ledB;
bosko001 6:12b2660d7dff 109 // static int i=0;
bosko001 6:12b2660d7dff 110 // if(i++ > 100) { i = 0; f = 1;
bosko001 6:12b2660d7dff 111 // v1 = c_data.pMin;
bosko001 6:12b2660d7dff 112 // v2 = c_data.get_command();
bosko001 6:12b2660d7dff 113 // v3 = c_data.get_indication();
bosko001 6:12b2660d7dff 114 // }
bosko001 6:12b2660d7dff 115 }
bosko001 6:12b2660d7dff 116 else c_data.clear_pMin();
bosko001 6:12b2660d7dff 117 }
bosko001 6:12b2660d7dff 118 );
bosko001 6:12b2660d7dff 119 c_zeroCrossing.set_postponeOFFfun( []() // maximum mreze - rad sa neispravnim naponom - misem
bosko001 6:12b2660d7dff 120 {
bosko001 6:12b2660d7dff 121 static int i=0, j=0;
bosko001 6:12b2660d7dff 122 if(time_delay == 0 && (c_data.check_newcommand_flag()== false))
bosko001 6:12b2660d7dff 123 {
bosko001 6:12b2660d7dff 124 ledB =!ledB;
bosko001 6:12b2660d7dff 125 char p1 = rc_zc.get_portInMax(); // dva ocitavanja porta
bosko001 6:12b2660d7dff 126 wait_us(10);
bosko001 6:12b2660d7dff 127 char p2 = rc_zc.get_portInMax();
bosko001 6:12b2660d7dff 128 p1 |= p2;
bosko001 6:12b2660d7dff 129 v1 = c_data.set_pMax( v4 = p1 );
bosko001 6:12b2660d7dff 130 c_data.set_faultVoltage();
bosko001 6:12b2660d7dff 131 v2 = c_data.get_command();
bosko001 6:12b2660d7dff 132 v3 = c_data.get_faultVoltage();
bosko001 6:12b2660d7dff 133
bosko001 6:12b2660d7dff 134 if(time_flag)
bosko001 6:12b2660d7dff 135 {
bosko001 6:12b2660d7dff 136 testPin =! testPin;
bosko001 6:12b2660d7dff 137 f = 1; time_flag--;
bosko001 6:12b2660d7dff 138 v1 = c_data.pMax;
bosko001 6:12b2660d7dff 139 v6 = (long)Kernel::get_ms_count()-t;
bosko001 6:12b2660d7dff 140 }
bosko001 6:12b2660d7dff 141 }
bosko001 6:12b2660d7dff 142 else c_data.clear_pMax();
bosko001 6:12b2660d7dff 143
bosko001 6:12b2660d7dff 144 } );
bosko001 6:12b2660d7dff 145
bosko001 0:c06c791ca345 146
bosko001 0:c06c791ca345 147 int b = b2;
bosko001 0:c06c791ca345 148
bosko001 6:12b2660d7dff 149 /* konzolu napraciti kao klasu koja nasledjuje C_thread klasu */
bosko001 6:12b2660d7dff 150 extern void consolafun( void );
bosko001 6:12b2660d7dff 151 Thread th_consola;
bosko001 6:12b2660d7dff 152 th_consola.start( consolafun);
bosko001 6:12b2660d7dff 153
bosko001 6:12b2660d7dff 154 /* cekanje da se procita prva ispravna adresa sa dip switch-a */
bosko001 6:12b2660d7dff 155 do { ThisThread::sleep_for(10ms);;c_spiProtokol.inic_address( ); }
bosko001 6:12b2660d7dff 156 while ( c_data.get_address() == 0 );
bosko001 6:12b2660d7dff 157 printf(" adresa je = %d\n\r", c_data.get_address());
bosko001 6:12b2660d7dff 158
bosko001 6:12b2660d7dff 159 // postavljanje sopstvene adrese i prikaz na ledovima
bosko001 6:12b2660d7dff 160 c_spiProtokol.set_myAddress(c_data.get_address());
bosko001 6:12b2660d7dff 161 c_ledControl.set_colorTemplate_Green();
bosko001 6:12b2660d7dff 162 c_ledControl.set_ledView(adresa);
bosko001 6:12b2660d7dff 163
bosko001 4:fce988d27938 164
bosko001 0:c06c791ca345 165 while (true)
bosko001 0:c06c791ca345 166 {
bosko001 0:c06c791ca345 167
bosko001 6:12b2660d7dff 168 /* if(f==1)
bosko001 6:12b2660d7dff 169 {
bosko001 6:12b2660d7dff 170 f=0;
bosko001 6:12b2660d7dff 171 printf( "det = %x %x %x %x %d vreme = %d %d\n\r", v1, v2, v3, v4, v5, v6, t);
bosko001 6:12b2660d7dff 172 }
bosko001 6:12b2660d7dff 173 */
bosko001 4:fce988d27938 174
bosko001 0:c06c791ca345 175 if( b!= b2)
bosko001 0:c06c791ca345 176 {
bosko001 0:c06c791ca345 177 b = b2;
bosko001 6:12b2660d7dff 178 if( b ) { ledB = 1;}
bosko001 6:12b2660d7dff 179 else { ledB = 0; //printf( " bitCount = %d, byteCount = %d\n\r", c_spiProtokol.get_bitCount(), c_spiProtokol.get_byteCount());
bosko001 6:12b2660d7dff 180
bosko001 6:12b2660d7dff 181 printf( " zerocrossing timer on = %d off = %d \n\r", c_zeroCrossing.get_zcTimeON(), c_zeroCrossing.get_zcTimeOFF());
bosko001 6:12b2660d7dff 182 // printf(" port in %x\n\r", rc_zc.s_portinMin.get_port() );
bosko001 6:12b2660d7dff 183 printf(" adresa je = %d\n\r", c_data.get_address());
bosko001 6:12b2660d7dff 184 }
bosko001 0:c06c791ca345 185 }
bosko001 6:12b2660d7dff 186
bosko001 6:12b2660d7dff 187 c_spiProtokol.spi_monitor();
bosko001 0:c06c791ca345 188
bosko001 0:c06c791ca345 189
bosko001 0:c06c791ca345 190 thread_sleep_for(BLINKING_RATE_MS);
bosko001 0:c06c791ca345 191 }
bosko001 0:c06c791ca345 192 }
bosko001 0:c06c791ca345 193
bosko001 0:c06c791ca345 194
bosko001 0:c06c791ca345 195
bosko001 0:c06c791ca345 196 void consolafun( void )
bosko001 0:c06c791ca345 197 {
bosko001 0:c06c791ca345 198 while( true )
bosko001 0:c06c791ca345 199 {
bosko001 6:12b2660d7dff 200
bosko001 0:c06c791ca345 201 char uc = getchar( );
bosko001 0:c06c791ca345 202 switch( (unsigned char) uc )
bosko001 0:c06c791ca345 203 {
bosko001 0:c06c791ca345 204 case 'r': case 'R':
bosko001 0:c06c791ca345 205
bosko001 0:c06c791ca345 206 printf("\n\rcitanje registra, unesi broj:\n\r");
bosko001 0:c06c791ca345 207 int r;
bosko001 0:c06c791ca345 208 scanf("%x", &r);
bosko001 1:1052d6227111 209 // printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r));
bosko001 0:c06c791ca345 210
bosko001 0:c06c791ca345 211 break;
bosko001 0:c06c791ca345 212 case 'w': case 'W':
bosko001 0:c06c791ca345 213 {
bosko001 0:c06c791ca345 214 printf("\n\rupis registra, unesi broj registra:");
bosko001 0:c06c791ca345 215 int r;
bosko001 0:c06c791ca345 216 scanf("%x", &r);
bosko001 0:c06c791ca345 217 printf( " %x", r );
bosko001 0:c06c791ca345 218 printf("\n\runesi vrednost registra:");
bosko001 0:c06c791ca345 219 int v;
bosko001 0:c06c791ca345 220 scanf("%x", &v);
bosko001 0:c06c791ca345 221 printf( " %x", v );
bosko001 1:1052d6227111 222 // printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r));
bosko001 0:c06c791ca345 223 }
bosko001 0:c06c791ca345 224 break;
bosko001 4:fce988d27938 225 case 's': case 'S':
bosko001 6:12b2660d7dff 226 // set_shiftspi_signal( );
bosko001 4:fce988d27938 227 break;
bosko001 4:fce988d27938 228
bosko001 6:12b2660d7dff 229 case 'c':
bosko001 6:12b2660d7dff 230 s_log.clear();
bosko001 6:12b2660d7dff 231 //break;
bosko001 6:12b2660d7dff 232 case 'l':
bosko001 6:12b2660d7dff 233 printf( " capacity %d max_size %d size %d\n\r", s_log.capacity(), s_log.max_size(), s_log.size());
bosko001 6:12b2660d7dff 234 break;
bosko001 6:12b2660d7dff 235 case 'p':
bosko001 6:12b2660d7dff 236 int i=1;
bosko001 6:12b2660d7dff 237 if(s_log.size())
bosko001 6:12b2660d7dff 238 {
bosko001 6:12b2660d7dff 239 for( auto it = s_log.end()-1; it != s_log.begin(); it--)
bosko001 6:12b2660d7dff 240 printf( "%3d %s\n\r", i++, (*it).poruka);
bosko001 6:12b2660d7dff 241 auto it = s_log.begin();
bosko001 6:12b2660d7dff 242 printf( "%3d %s\n\r", i++, (*it).poruka );
bosko001 6:12b2660d7dff 243 }
bosko001 6:12b2660d7dff 244 break;
bosko001 0:c06c791ca345 245 }
bosko001 3:71278c5b7c67 246 ThisThread::yield();
bosko001 3:71278c5b7c67 247 thread_sleep_for(100);
bosko001 0:c06c791ca345 248 }
bosko001 0:c06c791ca345 249 }