bosko lekovic
/
IO_board
IO plocana FRDM K64
main.cpp@0:c06c791ca345, 2020-07-10 (annotated)
- Committer:
- bosko001
- Date:
- Fri Jul 10 09:28:30 2020 +0000
- Revision:
- 0:c06c791ca345
- Child:
- 1:1052d6227111
miwi
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 | 0:c06c791ca345 | 8 | |
bosko001 | 0:c06c791ca345 | 9 | #include "MiWiApp.h" |
bosko001 | 0:c06c791ca345 | 10 | |
bosko001 | 0:c06c791ca345 | 11 | // Blinking rate in milliseconds |
bosko001 | 0:c06c791ca345 | 12 | #define BLINKING_RATE_MS 200 |
bosko001 | 0:c06c791ca345 | 13 | |
bosko001 | 0:c06c791ca345 | 14 | |
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 | 0:c06c791ca345 | 22 | |
bosko001 | 0:c06c791ca345 | 23 | void consolafun( void ); |
bosko001 | 0:c06c791ca345 | 24 | Thread th_consola( consolafun ); |
bosko001 | 0:c06c791ca345 | 25 | |
bosko001 | 0:c06c791ca345 | 26 | int main() |
bosko001 | 0:c06c791ca345 | 27 | { |
bosko001 | 0:c06c791ca345 | 28 | // Initialise the digital pin LED1 as an output |
bosko001 | 0:c06c791ca345 | 29 | printf("\n\n\r ____________ POCETAK MiWI RX_______________\n\r"); |
bosko001 | 0:c06c791ca345 | 30 | |
bosko001 | 0:c06c791ca345 | 31 | inic_MiWi( ); |
bosko001 | 0:c06c791ca345 | 32 | |
bosko001 | 0:c06c791ca345 | 33 | DigitalOut led(LED1,1); |
bosko001 | 0:c06c791ca345 | 34 | DigitalOut ledB(LED3,1); |
bosko001 | 0:c06c791ca345 | 35 | |
bosko001 | 0:c06c791ca345 | 36 | |
bosko001 | 0:c06c791ca345 | 37 | |
bosko001 | 0:c06c791ca345 | 38 | set_mode( 3 ); //prijem |
bosko001 | 0:c06c791ca345 | 39 | |
bosko001 | 0:c06c791ca345 | 40 | |
bosko001 | 0:c06c791ca345 | 41 | //for( int i=0; i<10; i++) |
bosko001 | 0:c06c791ca345 | 42 | { |
bosko001 | 0:c06c791ca345 | 43 | char r = readMiWiReg( 0x14 ); // read GCONFIG |
bosko001 | 0:c06c791ca345 | 44 | printf("rssi = %d\n\r", r ); |
bosko001 | 0:c06c791ca345 | 45 | print_regs(); |
bosko001 | 0:c06c791ca345 | 46 | } |
bosko001 | 0:c06c791ca345 | 47 | |
bosko001 | 0:c06c791ca345 | 48 | int b = b2; |
bosko001 | 0:c06c791ca345 | 49 | |
bosko001 | 0:c06c791ca345 | 50 | |
bosko001 | 0:c06c791ca345 | 51 | while (true) |
bosko001 | 0:c06c791ca345 | 52 | { |
bosko001 | 0:c06c791ca345 | 53 | // led = !led; |
bosko001 | 0:c06c791ca345 | 54 | |
bosko001 | 0:c06c791ca345 | 55 | extern DigitalIn pin_irq0, pin_irq1; |
bosko001 | 0:c06c791ca345 | 56 | // |
bosko001 | 0:c06c791ca345 | 57 | // unsigned char r = readMiWiReg( 0x14 ); // read GCONFIG |
bosko001 | 0:c06c791ca345 | 58 | // printf("rssi = %d ", r ); |
bosko001 | 0:c06c791ca345 | 59 | // printf(" irq0=%d irq1=%d\n\r", pin_irq0.read(), pin_irq1.read() ); fflush(stdout); |
bosko001 | 0:c06c791ca345 | 60 | ////if( r> 50 ) |
bosko001 | 0:c06c791ca345 | 61 | |
bosko001 | 0:c06c791ca345 | 62 | if( get_mode( ) == 3 ) |
bosko001 | 0:c06c791ca345 | 63 | { |
bosko001 | 0:c06c791ca345 | 64 | if( pin_irq0.read() ) |
bosko001 | 0:c06c791ca345 | 65 | { |
bosko001 | 0:c06c791ca345 | 66 | led = 0; |
bosko001 | 0:c06c791ca345 | 67 | print_regs(); |
bosko001 | 0:c06c791ca345 | 68 | while( pin_irq0.read() ) |
bosko001 | 0:c06c791ca345 | 69 | { |
bosko001 | 0:c06c791ca345 | 70 | printf(" %x ", readMiWiData( )); |
bosko001 | 0:c06c791ca345 | 71 | // printf("\n\r irq0=%d irq1=%d\n\r", pin_irq0.read(), pin_irq1.read() ); |
bosko001 | 0:c06c791ca345 | 72 | } |
bosko001 | 0:c06c791ca345 | 73 | printf("\n\r"); |
bosko001 | 0:c06c791ca345 | 74 | print_regs(); |
bosko001 | 0:c06c791ca345 | 75 | } |
bosko001 | 0:c06c791ca345 | 76 | else { if(!led ) led = 1; } |
bosko001 | 0:c06c791ca345 | 77 | } |
bosko001 | 0:c06c791ca345 | 78 | // else |
bosko001 | 0:c06c791ca345 | 79 | { |
bosko001 | 0:c06c791ca345 | 80 | |
bosko001 | 0:c06c791ca345 | 81 | if( b!= b2) |
bosko001 | 0:c06c791ca345 | 82 | { |
bosko001 | 0:c06c791ca345 | 83 | b = b2; |
bosko001 | 0:c06c791ca345 | 84 | if( b ) {/*set_mode( 1 );*/ ledB = 1;} |
bosko001 | 0:c06c791ca345 | 85 | else { ledB = 0; txMiWi( tx_niz ); } |
bosko001 | 0:c06c791ca345 | 86 | } |
bosko001 | 0:c06c791ca345 | 87 | |
bosko001 | 0:c06c791ca345 | 88 | } |
bosko001 | 0:c06c791ca345 | 89 | |
bosko001 | 0:c06c791ca345 | 90 | |
bosko001 | 0:c06c791ca345 | 91 | |
bosko001 | 0:c06c791ca345 | 92 | thread_sleep_for(BLINKING_RATE_MS); |
bosko001 | 0:c06c791ca345 | 93 | } |
bosko001 | 0:c06c791ca345 | 94 | } |
bosko001 | 0:c06c791ca345 | 95 | |
bosko001 | 0:c06c791ca345 | 96 | |
bosko001 | 0:c06c791ca345 | 97 | |
bosko001 | 0:c06c791ca345 | 98 | |
bosko001 | 0:c06c791ca345 | 99 | void consolafun( void ) |
bosko001 | 0:c06c791ca345 | 100 | { |
bosko001 | 0:c06c791ca345 | 101 | while( true ) |
bosko001 | 0:c06c791ca345 | 102 | { |
bosko001 | 0:c06c791ca345 | 103 | |
bosko001 | 0:c06c791ca345 | 104 | char uc = getchar( ); |
bosko001 | 0:c06c791ca345 | 105 | switch( (unsigned char) uc ) |
bosko001 | 0:c06c791ca345 | 106 | { |
bosko001 | 0:c06c791ca345 | 107 | case 'r': case 'R': |
bosko001 | 0:c06c791ca345 | 108 | |
bosko001 | 0:c06c791ca345 | 109 | printf("\n\rcitanje registra, unesi broj:\n\r"); |
bosko001 | 0:c06c791ca345 | 110 | int r; |
bosko001 | 0:c06c791ca345 | 111 | scanf("%x", &r); |
bosko001 | 0:c06c791ca345 | 112 | printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r)); |
bosko001 | 0:c06c791ca345 | 113 | |
bosko001 | 0:c06c791ca345 | 114 | break; |
bosko001 | 0:c06c791ca345 | 115 | case 'w': case 'W': |
bosko001 | 0:c06c791ca345 | 116 | { |
bosko001 | 0:c06c791ca345 | 117 | printf("\n\rupis registra, unesi broj registra:"); |
bosko001 | 0:c06c791ca345 | 118 | int r; |
bosko001 | 0:c06c791ca345 | 119 | scanf("%x", &r); |
bosko001 | 0:c06c791ca345 | 120 | printf( " %x", r ); |
bosko001 | 0:c06c791ca345 | 121 | printf("\n\runesi vrednost registra:"); |
bosko001 | 0:c06c791ca345 | 122 | int v; |
bosko001 | 0:c06c791ca345 | 123 | scanf("%x", &v); |
bosko001 | 0:c06c791ca345 | 124 | printf( " %x", v ); |
bosko001 | 0:c06c791ca345 | 125 | printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r)); |
bosko001 | 0:c06c791ca345 | 126 | } |
bosko001 | 0:c06c791ca345 | 127 | break; |
bosko001 | 0:c06c791ca345 | 128 | } |
bosko001 | 0:c06c791ca345 | 129 | |
bosko001 | 0:c06c791ca345 | 130 | } |
bosko001 | 0:c06c791ca345 | 131 | } |