bosko lekovic
/
IO_board_K22
K22 processor
main.cpp@18:6196688e2a94, 2021-05-16 (annotated)
- Committer:
- bosko001
- Date:
- Sun May 16 22:01:47 2021 +0200
- Revision:
- 18:6196688e2a94
- Parent:
- 17:f99cdfd01d4e
korigovan PeripheralPins.c u mbedOS
Who changed what in which revision?
User | Revision | Line number | New 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 | 18:6196688e2a94 | 47 | C_ledControl c_ledControl(&c_data);//( &c_ledLight); |
bosko001 | 6:12b2660d7dff | 48 | |
bosko001 | 18:6196688e2a94 | 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 | 18:6196688e2a94 | 54 | C_zeroCrossing c_zeroCrossing( &c_data); |
bosko001 | 14:b63e4664e2a8 | 55 | |
bosko001 | 14:b63e4664e2a8 | 56 | |
bosko001 | 14:b63e4664e2a8 | 57 | |
bosko001 | 18:6196688e2a94 | 58 | // C_zeroCrossing& rc_zc = c_zeroCrossing; |
bosko001 | 6:12b2660d7dff | 59 | |
bosko001 | 18:6196688e2a94 | 60 | // C_zcControl c_zcControl( &c_zeroCrossing, &c_spiProtokol); |
bosko001 | 6:12b2660d7dff | 61 | |
bosko001 | 18:6196688e2a94 | 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 | 18:6196688e2a94 | 78 | // s_log.resize(1000); |
bosko001 | 18:6196688e2a94 | 79 | // s_log.clear(); |
bosko001 | 6:12b2660d7dff | 80 | |
bosko001 | 18:6196688e2a94 | 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 | 18:6196688e2a94 | 84 | // //test_RasaLed.attach_us([=]{ RasaLed = !RasaLed;}, 500000 ); |
bosko001 | 13:7c4ec32f6a54 | 85 | |
bosko001 | 6:12b2660d7dff | 86 | |
bosko001 | 0:c06c791ca345 | 87 | |
bosko001 | 18:6196688e2a94 | 88 | // int b = b2; |
bosko001 | 0:c06c791ca345 | 89 | |
bosko001 | 18:6196688e2a94 | 90 | // /* konzolu napraciti kao klasu koja nasledjuje C_thread klasu */ |
bosko001 | 18:6196688e2a94 | 91 | // extern void consolafun( void ); |
bosko001 | 17:f99cdfd01d4e | 92 | |
bosko001 | 18:6196688e2a94 | 93 | // Thread th_consola; |
bosko001 | 18:6196688e2a94 | 94 | // th_consola.start( consolafun); |
bosko001 | 6:12b2660d7dff | 95 | |
bosko001 | 17:f99cdfd01d4e | 96 | |
bosko001 | 17:f99cdfd01d4e | 97 | |
bosko001 | 18:6196688e2a94 | 98 | // /* cekanje da se procita prva ispravna adresa sa dip switch-a */ |
bosko001 | 17:f99cdfd01d4e | 99 | |
bosko001 | 17:f99cdfd01d4e | 100 | |
bosko001 | 18:6196688e2a94 | 101 | // do { ThisThread::sleep_for(10ms);;c_spiProtokol.inic_address( ); } |
bosko001 | 18:6196688e2a94 | 102 | // while ( c_data.get_address() == 0 ); |
bosko001 | 18:6196688e2a94 | 103 | // printf(" adresa je = %d\n\r", c_data.get_address()); |
bosko001 | 6:12b2660d7dff | 104 | |
bosko001 | 18:6196688e2a94 | 105 | // // postavljanje sopstvene adrese i prikaz na ledovima |
bosko001 | 18:6196688e2a94 | 106 | // c_spiProtokol.set_myAddress(c_data.get_address()); |
bosko001 | 18:6196688e2a94 | 107 | // c_ledControl.set_colorTemplate_Green(); |
bosko001 | 18:6196688e2a94 | 108 | // c_ledControl.set_ledView(adresa); |
bosko001 | 6:12b2660d7dff | 109 | |
bosko001 | 4:fce988d27938 | 110 | |
bosko001 | 18:6196688e2a94 | 111 | // while (true) |
bosko001 | 18:6196688e2a94 | 112 | // { |
bosko001 | 0:c06c791ca345 | 113 | |
bosko001 | 4:fce988d27938 | 114 | |
bosko001 | 18:6196688e2a94 | 115 | // if( b!= b2) |
bosko001 | 18:6196688e2a94 | 116 | // { |
bosko001 | 18:6196688e2a94 | 117 | // b = b2; |
bosko001 | 18:6196688e2a94 | 118 | // if( b ) { ledB = 1;} |
bosko001 | 18:6196688e2a94 | 119 | // else { ledB = 0; //printf( " bitCount = %d, byteCount = %d\n\r", c_spiProtokol.get_bitCount(), c_spiProtokol.get_byteCount()); |
bosko001 | 6:12b2660d7dff | 120 | |
bosko001 | 18:6196688e2a94 | 121 | // printf( " zerocrossing timer on = %d off = %d \n\r", c_zeroCrossing.get_zcTimeON(), c_zeroCrossing.get_zcTimeOFF()); |
bosko001 | 18:6196688e2a94 | 122 | // // printf(" port in %x\n\r", rc_zc.s_portinMin.get_port() ); |
bosko001 | 18:6196688e2a94 | 123 | // printf(" adresa je = %d\n\r", c_data.get_address()); |
bosko001 | 18:6196688e2a94 | 124 | // } |
bosko001 | 18:6196688e2a94 | 125 | // } |
bosko001 | 6:12b2660d7dff | 126 | |
bosko001 | 18:6196688e2a94 | 127 | // c_spiProtokol.spi_monitor(); |
bosko001 | 0:c06c791ca345 | 128 | |
bosko001 | 0:c06c791ca345 | 129 | |
bosko001 | 18:6196688e2a94 | 130 | // thread_sleep_for(BLINKING_RATE_MS); |
bosko001 | 18:6196688e2a94 | 131 | // } |
bosko001 | 18:6196688e2a94 | 132 | |
bosko001 | 18:6196688e2a94 | 133 | while(1); |
bosko001 | 18:6196688e2a94 | 134 | } |
bosko001 | 0:c06c791ca345 | 135 | |
bosko001 | 0:c06c791ca345 | 136 | |
bosko001 | 0:c06c791ca345 | 137 | |
bosko001 | 0:c06c791ca345 | 138 | void consolafun( void ) |
bosko001 | 0:c06c791ca345 | 139 | { |
bosko001 | 0:c06c791ca345 | 140 | while( true ) |
bosko001 | 0:c06c791ca345 | 141 | { |
bosko001 | 6:12b2660d7dff | 142 | |
bosko001 | 0:c06c791ca345 | 143 | char uc = getchar( ); |
bosko001 | 0:c06c791ca345 | 144 | switch( (unsigned char) uc ) |
bosko001 | 0:c06c791ca345 | 145 | { |
bosko001 | 0:c06c791ca345 | 146 | case 'r': case 'R': |
bosko001 | 15:3429cdc6e5f4 | 147 | |
bosko001 | 15:3429cdc6e5f4 | 148 | NVIC_SystemReset(); |
bosko001 | 0:c06c791ca345 | 149 | break; |
bosko001 | 0:c06c791ca345 | 150 | case 'w': case 'W': |
bosko001 | 0:c06c791ca345 | 151 | { |
bosko001 | 0:c06c791ca345 | 152 | printf("\n\rupis registra, unesi broj registra:"); |
bosko001 | 0:c06c791ca345 | 153 | int r; |
bosko001 | 0:c06c791ca345 | 154 | scanf("%x", &r); |
bosko001 | 0:c06c791ca345 | 155 | printf( " %x", r ); |
bosko001 | 0:c06c791ca345 | 156 | printf("\n\runesi vrednost registra:"); |
bosko001 | 0:c06c791ca345 | 157 | int v; |
bosko001 | 0:c06c791ca345 | 158 | scanf("%x", &v); |
bosko001 | 0:c06c791ca345 | 159 | printf( " %x", v ); |
bosko001 | 1:1052d6227111 | 160 | // printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r)); |
bosko001 | 0:c06c791ca345 | 161 | } |
bosko001 | 0:c06c791ca345 | 162 | break; |
bosko001 | 4:fce988d27938 | 163 | case 's': case 'S': |
bosko001 | 6:12b2660d7dff | 164 | // set_shiftspi_signal( ); |
bosko001 | 4:fce988d27938 | 165 | break; |
bosko001 | 4:fce988d27938 | 166 | |
bosko001 | 6:12b2660d7dff | 167 | case 'c': |
bosko001 | 6:12b2660d7dff | 168 | s_log.clear(); |
bosko001 | 6:12b2660d7dff | 169 | //break; |
bosko001 | 6:12b2660d7dff | 170 | case 'l': |
bosko001 | 6:12b2660d7dff | 171 | printf( " capacity %d max_size %d size %d\n\r", s_log.capacity(), s_log.max_size(), s_log.size()); |
bosko001 | 6:12b2660d7dff | 172 | break; |
bosko001 | 6:12b2660d7dff | 173 | case 'p': |
bosko001 | 6:12b2660d7dff | 174 | int i=1; |
bosko001 | 6:12b2660d7dff | 175 | if(s_log.size()) |
bosko001 | 6:12b2660d7dff | 176 | { |
bosko001 | 6:12b2660d7dff | 177 | for( auto it = s_log.end()-1; it != s_log.begin(); it--) |
bosko001 | 6:12b2660d7dff | 178 | printf( "%3d %s\n\r", i++, (*it).poruka); |
bosko001 | 6:12b2660d7dff | 179 | auto it = s_log.begin(); |
bosko001 | 6:12b2660d7dff | 180 | printf( "%3d %s\n\r", i++, (*it).poruka ); |
bosko001 | 6:12b2660d7dff | 181 | } |
bosko001 | 6:12b2660d7dff | 182 | break; |
bosko001 | 0:c06c791ca345 | 183 | } |
bosko001 | 3:71278c5b7c67 | 184 | ThisThread::yield(); |
bosko001 | 3:71278c5b7c67 | 185 | thread_sleep_for(100); |
bosko001 | 0:c06c791ca345 | 186 | } |
bosko001 | 18:6196688e2a94 | 187 | |
bosko001 | 0:c06c791ca345 | 188 | } |