K22 processor

Committer:
bosko001
Date:
Fri Apr 30 00:06:39 2021 +0200
Revision:
15:3429cdc6e5f4
Parent:
14:b63e4664e2a8
Child:
17:f99cdfd01d4e
ugradjen privremeni timeout 4s i telegram reseta ploce

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 14:b63e4664e2a8 20 #include "ZC_CommandIndication.h"
bosko001 14:b63e4664e2a8 21
bosko001 6:12b2660d7dff 22 #include "IOzcControl.h"
bosko001 6:12b2660d7dff 23
bosko001 6:12b2660d7dff 24
bosko001 6:12b2660d7dff 25 extern vector< S_logTelegram> s_log;
bosko001 0:c06c791ca345 26
bosko001 8:5a96bfb6b6f9 27
bosko001 8:5a96bfb6b6f9 28
bosko001 0:c06c791ca345 29 // Blinking rate in milliseconds
bosko001 0:c06c791ca345 30 #define BLINKING_RATE_MS 200
bosko001 0:c06c791ca345 31
bosko001 14:b63e4664e2a8 32 //DigitalOut ioTest(IO_TEST,0);
bosko001 0:c06c791ca345 33
bosko001 13:7c4ec32f6a54 34
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 15:3429cdc6e5f4 42 static 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 14:b63e4664e2a8 54
bosko001 14:b63e4664e2a8 55
bosko001 14:b63e4664e2a8 56
bosko001 14:b63e4664e2a8 57
bosko001 6:12b2660d7dff 58 C_zeroCrossing c_zeroCrossing( &c_data);
bosko001 14:b63e4664e2a8 59
bosko001 14:b63e4664e2a8 60
bosko001 14:b63e4664e2a8 61
bosko001 6:12b2660d7dff 62 C_zeroCrossing& rc_zc = c_zeroCrossing;
bosko001 6:12b2660d7dff 63
bosko001 6:12b2660d7dff 64 C_zcControl c_zcControl( &c_zeroCrossing, &c_spiProtokol);
bosko001 6:12b2660d7dff 65
bosko001 14:b63e4664e2a8 66 C_ZC_CommandIndication c_zc_ci( &c_data, &c_zeroCrossing);
bosko001 6:12b2660d7dff 67
bosko001 6:12b2660d7dff 68
bosko001 14:b63e4664e2a8 69 //Ticker test_RasaLed;
bosko001 14:b63e4664e2a8 70 //DigitalOut RasaLed(PTE0,1);
bosko001 6:12b2660d7dff 71
bosko001 13:7c4ec32f6a54 72 int tz;
bosko001 13:7c4ec32f6a54 73
bosko001 0:c06c791ca345 74
bosko001 0:c06c791ca345 75 int main()
bosko001 0:c06c791ca345 76 {
bosko001 6:12b2660d7dff 77
bosko001 0:c06c791ca345 78 // Initialise the digital pin LED1 as an output
bosko001 6:12b2660d7dff 79
bosko001 4:fce988d27938 80 printf("\n\n\r ____________ POCETAK IOboard_______________\n\r");
bosko001 0:c06c791ca345 81
bosko001 6:12b2660d7dff 82 s_log.resize(1000);
bosko001 6:12b2660d7dff 83 s_log.clear();
bosko001 6:12b2660d7dff 84
bosko001 6:12b2660d7dff 85 printf( " capacity %d max_size %d size %d\n\r", s_log.capacity(), s_log.max_size(), s_log.size());
bosko001 14:b63e4664e2a8 86 //test_RasaLed.attach_us([=]{ RasaLed = !RasaLed;}, 500000 );
bosko001 13:7c4ec32f6a54 87
bosko001 6:12b2660d7dff 88
bosko001 0:c06c791ca345 89
bosko001 0:c06c791ca345 90 int b = b2;
bosko001 0:c06c791ca345 91
bosko001 6:12b2660d7dff 92 /* konzolu napraciti kao klasu koja nasledjuje C_thread klasu */
bosko001 6:12b2660d7dff 93 extern void consolafun( void );
bosko001 6:12b2660d7dff 94 Thread th_consola;
bosko001 6:12b2660d7dff 95 th_consola.start( consolafun);
bosko001 6:12b2660d7dff 96
bosko001 6:12b2660d7dff 97 /* cekanje da se procita prva ispravna adresa sa dip switch-a */
bosko001 6:12b2660d7dff 98 do { ThisThread::sleep_for(10ms);;c_spiProtokol.inic_address( ); }
bosko001 6:12b2660d7dff 99 while ( c_data.get_address() == 0 );
bosko001 6:12b2660d7dff 100 printf(" adresa je = %d\n\r", c_data.get_address());
bosko001 6:12b2660d7dff 101
bosko001 6:12b2660d7dff 102 // postavljanje sopstvene adrese i prikaz na ledovima
bosko001 6:12b2660d7dff 103 c_spiProtokol.set_myAddress(c_data.get_address());
bosko001 6:12b2660d7dff 104 c_ledControl.set_colorTemplate_Green();
bosko001 6:12b2660d7dff 105 c_ledControl.set_ledView(adresa);
bosko001 6:12b2660d7dff 106
bosko001 4:fce988d27938 107
bosko001 0:c06c791ca345 108 while (true)
bosko001 0:c06c791ca345 109 {
bosko001 0:c06c791ca345 110
bosko001 4:fce988d27938 111
bosko001 0:c06c791ca345 112 if( b!= b2)
bosko001 0:c06c791ca345 113 {
bosko001 0:c06c791ca345 114 b = b2;
bosko001 6:12b2660d7dff 115 if( b ) { ledB = 1;}
bosko001 6:12b2660d7dff 116 else { ledB = 0; //printf( " bitCount = %d, byteCount = %d\n\r", c_spiProtokol.get_bitCount(), c_spiProtokol.get_byteCount());
bosko001 6:12b2660d7dff 117
bosko001 6:12b2660d7dff 118 printf( " zerocrossing timer on = %d off = %d \n\r", c_zeroCrossing.get_zcTimeON(), c_zeroCrossing.get_zcTimeOFF());
bosko001 6:12b2660d7dff 119 // printf(" port in %x\n\r", rc_zc.s_portinMin.get_port() );
bosko001 6:12b2660d7dff 120 printf(" adresa je = %d\n\r", c_data.get_address());
bosko001 6:12b2660d7dff 121 }
bosko001 0:c06c791ca345 122 }
bosko001 6:12b2660d7dff 123
bosko001 6:12b2660d7dff 124 c_spiProtokol.spi_monitor();
bosko001 0:c06c791ca345 125
bosko001 0:c06c791ca345 126
bosko001 0:c06c791ca345 127 thread_sleep_for(BLINKING_RATE_MS);
bosko001 0:c06c791ca345 128 }
bosko001 0:c06c791ca345 129 }
bosko001 0:c06c791ca345 130
bosko001 0:c06c791ca345 131
bosko001 0:c06c791ca345 132
bosko001 0:c06c791ca345 133 void consolafun( void )
bosko001 0:c06c791ca345 134 {
bosko001 0:c06c791ca345 135 while( true )
bosko001 0:c06c791ca345 136 {
bosko001 6:12b2660d7dff 137
bosko001 0:c06c791ca345 138 char uc = getchar( );
bosko001 0:c06c791ca345 139 switch( (unsigned char) uc )
bosko001 0:c06c791ca345 140 {
bosko001 0:c06c791ca345 141 case 'r': case 'R':
bosko001 15:3429cdc6e5f4 142
bosko001 15:3429cdc6e5f4 143 NVIC_SystemReset();
bosko001 0:c06c791ca345 144 break;
bosko001 0:c06c791ca345 145 case 'w': case 'W':
bosko001 0:c06c791ca345 146 {
bosko001 0:c06c791ca345 147 printf("\n\rupis registra, unesi broj registra:");
bosko001 0:c06c791ca345 148 int r;
bosko001 0:c06c791ca345 149 scanf("%x", &r);
bosko001 0:c06c791ca345 150 printf( " %x", r );
bosko001 0:c06c791ca345 151 printf("\n\runesi vrednost registra:");
bosko001 0:c06c791ca345 152 int v;
bosko001 0:c06c791ca345 153 scanf("%x", &v);
bosko001 0:c06c791ca345 154 printf( " %x", v );
bosko001 1:1052d6227111 155 // printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r));
bosko001 0:c06c791ca345 156 }
bosko001 0:c06c791ca345 157 break;
bosko001 4:fce988d27938 158 case 's': case 'S':
bosko001 6:12b2660d7dff 159 // set_shiftspi_signal( );
bosko001 4:fce988d27938 160 break;
bosko001 4:fce988d27938 161
bosko001 6:12b2660d7dff 162 case 'c':
bosko001 6:12b2660d7dff 163 s_log.clear();
bosko001 6:12b2660d7dff 164 //break;
bosko001 6:12b2660d7dff 165 case 'l':
bosko001 6:12b2660d7dff 166 printf( " capacity %d max_size %d size %d\n\r", s_log.capacity(), s_log.max_size(), s_log.size());
bosko001 6:12b2660d7dff 167 break;
bosko001 6:12b2660d7dff 168 case 'p':
bosko001 6:12b2660d7dff 169 int i=1;
bosko001 6:12b2660d7dff 170 if(s_log.size())
bosko001 6:12b2660d7dff 171 {
bosko001 6:12b2660d7dff 172 for( auto it = s_log.end()-1; it != s_log.begin(); it--)
bosko001 6:12b2660d7dff 173 printf( "%3d %s\n\r", i++, (*it).poruka);
bosko001 6:12b2660d7dff 174 auto it = s_log.begin();
bosko001 6:12b2660d7dff 175 printf( "%3d %s\n\r", i++, (*it).poruka );
bosko001 6:12b2660d7dff 176 }
bosko001 6:12b2660d7dff 177 break;
bosko001 0:c06c791ca345 178 }
bosko001 3:71278c5b7c67 179 ThisThread::yield();
bosko001 3:71278c5b7c67 180 thread_sleep_for(100);
bosko001 0:c06c791ca345 181 }
bosko001 0:c06c791ca345 182 }