K22 processor

Committer:
bosko001
Date:
Sun Mar 21 18:20:52 2021 +0100
Revision:
8:5a96bfb6b6f9
Parent:
6:12b2660d7dff
Child:
9:a4360a7713f5
novi kod

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