K22 processor

Committer:
bosko001
Date:
Sat May 15 13:59:57 2021 +0200
Revision:
17:f99cdfd01d4e
Parent:
15:3429cdc6e5f4
Child:
18:6196688e2a94
pinovi za K64 i K22

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