prva verzija, poslednji bajt je sporan

Committer:
bosko001
Date:
Thu Jul 16 22:14:03 2020 +0200
Revision:
2:190bae43eca9
Parent:
1:dd44d6b64300
Child:
3:3b0754ed31e9
funkconalan kod, puna snaga jedan kanal

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 0:c06c791ca345 8
bosko001 2:190bae43eca9 9 #include "MiWiDrv.h"
bosko001 1:dd44d6b64300 10 #include "SerialCom.h"
bosko001 0:c06c791ca345 11 // Blinking rate in milliseconds
bosko001 0:c06c791ca345 12 #define BLINKING_RATE_MS 200
bosko001 0:c06c791ca345 13
bosko001 1:dd44d6b64300 14 #define MINIMUM( A, B) A<B ? A:B
bosko001 0:c06c791ca345 15
bosko001 0:c06c791ca345 16
bosko001 0:c06c791ca345 17 DigitalIn b2(SW2);
bosko001 0:c06c791ca345 18
bosko001 0:c06c791ca345 19
bosko001 0:c06c791ca345 20
bosko001 0:c06c791ca345 21 char tx_niz[] = { 7,0,1,2,3, 4, 5 , 6, 7, 8};
bosko001 1:dd44d6b64300 22 char rx_niz[100];
bosko001 1:dd44d6b64300 23 int rx_br;
bosko001 0:c06c791ca345 24
bosko001 0:c06c791ca345 25 void consolafun( void );
bosko001 0:c06c791ca345 26 Thread th_consola( consolafun );
bosko001 0:c06c791ca345 27
bosko001 1:dd44d6b64300 28
bosko001 0:c06c791ca345 29 int main()
bosko001 0:c06c791ca345 30 {
bosko001 0:c06c791ca345 31 // Initialise the digital pin LED1 as an output
bosko001 0:c06c791ca345 32 printf("\n\n\r ____________ POCETAK MiWI RX_______________\n\r");
bosko001 0:c06c791ca345 33
bosko001 0:c06c791ca345 34 inic_MiWi( );
bosko001 0:c06c791ca345 35
bosko001 2:190bae43eca9 36 // DigitalOut led(LED1,1);
bosko001 0:c06c791ca345 37 DigitalOut ledB(LED3,1);
bosko001 2:190bae43eca9 38 // DigitalOut ledG(LED2,1);
bosko001 0:c06c791ca345 39
bosko001 0:c06c791ca345 40
bosko001 0:c06c791ca345 41
bosko001 2:190bae43eca9 42 setMiWimode( 3 ); //prijem
bosko001 0:c06c791ca345 43
bosko001 0:c06c791ca345 44
bosko001 0:c06c791ca345 45 int b = b2;
bosko001 0:c06c791ca345 46
bosko001 1:dd44d6b64300 47 start_SerialCom( );
bosko001 2:190bae43eca9 48 start_MiWiRx( );
bosko001 0:c06c791ca345 49
bosko001 0:c06c791ca345 50 while (true)
bosko001 0:c06c791ca345 51 {
bosko001 0:c06c791ca345 52
bosko001 0:c06c791ca345 53 if( b!= b2)
bosko001 0:c06c791ca345 54 {
bosko001 0:c06c791ca345 55 b = b2;
bosko001 0:c06c791ca345 56 if( b ) {/*set_mode( 1 );*/ ledB = 1;}
bosko001 0:c06c791ca345 57 else { ledB = 0; txMiWi( tx_niz ); }
bosko001 0:c06c791ca345 58 }
bosko001 2:190bae43eca9 59
bosko001 0:c06c791ca345 60 thread_sleep_for(BLINKING_RATE_MS);
bosko001 0:c06c791ca345 61 }
bosko001 0:c06c791ca345 62 }
bosko001 0:c06c791ca345 63
bosko001 0:c06c791ca345 64
bosko001 0:c06c791ca345 65
bosko001 0:c06c791ca345 66 void consolafun( void )
bosko001 0:c06c791ca345 67 {
bosko001 0:c06c791ca345 68 while( true )
bosko001 0:c06c791ca345 69 {
bosko001 0:c06c791ca345 70
bosko001 0:c06c791ca345 71 char uc = getchar( );
bosko001 0:c06c791ca345 72 switch( (unsigned char) uc )
bosko001 0:c06c791ca345 73 {
bosko001 0:c06c791ca345 74 case 'r': case 'R':
bosko001 0:c06c791ca345 75
bosko001 2:190bae43eca9 76 printf("\n\rcitanje registra, unesi broj hex:\n\r");
bosko001 0:c06c791ca345 77 int r;
bosko001 0:c06c791ca345 78 scanf("%x", &r);
bosko001 2:190bae43eca9 79 printf( "\n\rregistar hex %x ima vrednost hex %x\n\r", r, readMiWiReg(r));
bosko001 0:c06c791ca345 80
bosko001 0:c06c791ca345 81 break;
bosko001 0:c06c791ca345 82 case 'w': case 'W':
bosko001 0:c06c791ca345 83 {
bosko001 2:190bae43eca9 84 printf("\n\rupis registra, unesi broj registra hex:");
bosko001 0:c06c791ca345 85 int r;
bosko001 0:c06c791ca345 86 scanf("%x", &r);
bosko001 0:c06c791ca345 87 printf( " %x", r );
bosko001 2:190bae43eca9 88 printf("\n\runesi vrednost registra hex:");
bosko001 0:c06c791ca345 89 int v;
bosko001 0:c06c791ca345 90 scanf("%x", &v);
bosko001 0:c06c791ca345 91 printf( " %x", v );
bosko001 2:190bae43eca9 92 printf( "\n\rregistar hex %x ima vrednost hex %x\n\r", r, readMiWiReg(r));
bosko001 0:c06c791ca345 93 }
bosko001 0:c06c791ca345 94 break;
bosko001 1:dd44d6b64300 95 case 's': case 'S':
bosko001 1:dd44d6b64300 96 printf("aktivacija serijala\n\r");
bosko001 1:dd44d6b64300 97 start_SerialCom( );
bosko001 1:dd44d6b64300 98 break;
bosko001 2:190bae43eca9 99 case 'f': case 'F':
bosko001 2:190bae43eca9 100 printMiWiregs( );
bosko001 2:190bae43eca9 101 break;
bosko001 0:c06c791ca345 102 }
bosko001 0:c06c791ca345 103
bosko001 0:c06c791ca345 104 }
bosko001 0:c06c791ca345 105 }