IO plocana FRDM K64

Committer:
bosko001
Date:
Sun Jan 17 20:03:16 2021 +0100
Revision:
6:12b2660d7dff
Parent:
4:fce988d27938
Child:
8:5a96bfb6b6f9
skoro pa funkcionise kao normalna ploca

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