Test Code for TEA5767 radio module
Dependencies: MODSERIAL TEA5767 mbed
main.cpp@3:7371a6837350, 2013-10-05 (annotated)
- Committer:
- edodm85
- Date:
- Sat Oct 05 11:49:03 2013 +0000
- Revision:
- 3:7371a6837350
- Parent:
- 2:cf890ba22614
Added header
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
edodm85 | 2:cf890ba22614 | 1 | /* |
edodm85 | 2:cf890ba22614 | 2 | * Author: Edoardo De Marchi |
edodm85 | 2:cf890ba22614 | 3 | * Date: 05/10/13 |
edodm85 | 2:cf890ba22614 | 4 | * Notes: Test code for TEA5767 radio module |
edodm85 | 2:cf890ba22614 | 5 | */ |
edodm85 | 0:de2102ba3121 | 6 | |
edodm85 | 2:cf890ba22614 | 7 | #include "main.h" |
edodm85 | 0:de2102ba3121 | 8 | |
edodm85 | 0:de2102ba3121 | 9 | void rxCallback(MODSERIAL_IRQ_INFO *q) |
edodm85 | 0:de2102ba3121 | 10 | { |
edodm85 | 0:de2102ba3121 | 11 | new_send = true; |
edodm85 | 0:de2102ba3121 | 12 | } |
edodm85 | 0:de2102ba3121 | 13 | |
edodm85 | 0:de2102ba3121 | 14 | |
edodm85 | 0:de2102ba3121 | 15 | int main() |
edodm85 | 0:de2102ba3121 | 16 | { |
edodm85 | 0:de2102ba3121 | 17 | // INIT WATCHDOG |
edodm85 | 0:de2102ba3121 | 18 | w.kick(2.5); |
edodm85 | 0:de2102ba3121 | 19 | |
edodm85 | 0:de2102ba3121 | 20 | pc.baud(921600); |
edodm85 | 0:de2102ba3121 | 21 | pc.attach(&rxCallback, MODSERIAL::RxIrq); |
edodm85 | 0:de2102ba3121 | 22 | |
edodm85 | 0:de2102ba3121 | 23 | if(radio.CheckDevice() == 0) |
edodm85 | 0:de2102ba3121 | 24 | { |
edodm85 | 0:de2102ba3121 | 25 | pc.printf("Addr I2C found\r\n"); |
edodm85 | 0:de2102ba3121 | 26 | led2 = 1; |
edodm85 | 0:de2102ba3121 | 27 | }else |
edodm85 | 0:de2102ba3121 | 28 | { |
edodm85 | 0:de2102ba3121 | 29 | pc.printf("Addr I2C not found\r\n"); |
edodm85 | 0:de2102ba3121 | 30 | led2 = 0; |
edodm85 | 0:de2102ba3121 | 31 | } |
edodm85 | 0:de2102ba3121 | 32 | |
edodm85 | 0:de2102ba3121 | 33 | while(1) |
edodm85 | 0:de2102ba3121 | 34 | { |
edodm85 | 0:de2102ba3121 | 35 | if(new_send){ |
edodm85 | 0:de2102ba3121 | 36 | int i = 0; |
edodm85 | 0:de2102ba3121 | 37 | |
edodm85 | 0:de2102ba3121 | 38 | while(pc.readable()) |
edodm85 | 0:de2102ba3121 | 39 | { |
edodm85 | 0:de2102ba3121 | 40 | word[i] = pc.getc(); |
edodm85 | 0:de2102ba3121 | 41 | i++; |
edodm85 | 0:de2102ba3121 | 42 | } |
edodm85 | 0:de2102ba3121 | 43 | parse_cmd(); |
edodm85 | 0:de2102ba3121 | 44 | } |
edodm85 | 0:de2102ba3121 | 45 | wait_ms(50); |
edodm85 | 0:de2102ba3121 | 46 | w.kick(); |
edodm85 | 0:de2102ba3121 | 47 | } |
edodm85 | 0:de2102ba3121 | 48 | } |
edodm85 | 0:de2102ba3121 | 49 | |
edodm85 | 0:de2102ba3121 | 50 | |
edodm85 | 2:cf890ba22614 | 51 | // US-EUROPE 87.5-108MHz JAPANESE 76-91MHz |
edodm85 | 0:de2102ba3121 | 52 | float i = 0.2; |
edodm85 | 0:de2102ba3121 | 53 | void parse_cmd() |
edodm85 | 0:de2102ba3121 | 54 | { |
edodm85 | 0:de2102ba3121 | 55 | new_send = false; |
edodm85 | 0:de2102ba3121 | 56 | |
edodm85 | 0:de2102ba3121 | 57 | if(strncmp("freq", word, 4) == 0) |
edodm85 | 0:de2102ba3121 | 58 | { |
edodm85 | 0:de2102ba3121 | 59 | char word_temp[6]; |
edodm85 | 0:de2102ba3121 | 60 | strncpy(word_temp, &word[5], 6); |
edodm85 | 0:de2102ba3121 | 61 | |
edodm85 | 0:de2102ba3121 | 62 | n = atof(word_temp); // Convert string to double |
edodm85 | 0:de2102ba3121 | 63 | |
edodm85 | 0:de2102ba3121 | 64 | if((n >= StartFreq) && (n <= EndFreq)) |
edodm85 | 0:de2102ba3121 | 65 | { |
edodm85 | 0:de2102ba3121 | 66 | radio.SetFrequency(n); |
edodm85 | 0:de2102ba3121 | 67 | |
edodm85 | 0:de2102ba3121 | 68 | wait_ms(200); |
edodm85 | 0:de2102ba3121 | 69 | |
edodm85 | 0:de2102ba3121 | 70 | pc.printf("signal: %2.0d", radio.SignalLevel()); |
edodm85 | 0:de2102ba3121 | 71 | pc.printf("freq: %000.2f ", radio.FreqCurrent()); |
edodm85 | 0:de2102ba3121 | 72 | delete [] reg; |
edodm85 | 0:de2102ba3121 | 73 | wait_ms(100); |
edodm85 | 0:de2102ba3121 | 74 | |
edodm85 | 0:de2102ba3121 | 75 | }else |
edodm85 | 0:de2102ba3121 | 76 | { |
edodm85 | 0:de2102ba3121 | 77 | pc.printf("Out of range \r\n"); |
edodm85 | 0:de2102ba3121 | 78 | } |
edodm85 | 0:de2102ba3121 | 79 | }else |
edodm85 | 0:de2102ba3121 | 80 | if(strncmp("available", word, 9) == 0) |
edodm85 | 0:de2102ba3121 | 81 | { |
edodm85 | 0:de2102ba3121 | 82 | pc.printf("\r\n"); |
edodm85 | 0:de2102ba3121 | 83 | pc.printf("Current_Frequency: %.2fMHz\r\n", radio.FreqCurrent()); |
edodm85 | 0:de2102ba3121 | 84 | pc.printf("Signal_Level: %2.0d\r\n", radio.SignalLevel()); |
edodm85 | 0:de2102ba3121 | 85 | }else |
edodm85 | 0:de2102ba3121 | 86 | if(strncmp("search_up", word, 9) == 0) |
edodm85 | 0:de2102ba3121 | 87 | { |
edodm85 | 0:de2102ba3121 | 88 | float freq_av = radio.FreqCurrent(); |
edodm85 | 0:de2102ba3121 | 89 | if(freq_av-i > 108) |
edodm85 | 0:de2102ba3121 | 90 | { |
edodm85 | 0:de2102ba3121 | 91 | freq_av = 108; |
edodm85 | 0:de2102ba3121 | 92 | } |
edodm85 | 0:de2102ba3121 | 93 | radio.SearchUp(freq_av+i); |
edodm85 | 1:6ad6d1d3bbdf | 94 | wait_ms(700); |
edodm85 | 0:de2102ba3121 | 95 | pc.printf("signal: %2.0d", radio.SignalLevel()); |
edodm85 | 0:de2102ba3121 | 96 | pc.printf("freq: %000.2f ", radio.FreqCurrent()); |
edodm85 | 0:de2102ba3121 | 97 | }else |
edodm85 | 0:de2102ba3121 | 98 | if(strncmp("search_down", word, 11) == 0) |
edodm85 | 0:de2102ba3121 | 99 | { |
edodm85 | 0:de2102ba3121 | 100 | float freq_av = radio.FreqCurrent(); |
edodm85 | 0:de2102ba3121 | 101 | if(freq_av-i < 87.5) |
edodm85 | 0:de2102ba3121 | 102 | { |
edodm85 | 0:de2102ba3121 | 103 | freq_av = 87.5; |
edodm85 | 0:de2102ba3121 | 104 | } |
edodm85 | 0:de2102ba3121 | 105 | radio.SearchUp(freq_av-i); |
edodm85 | 1:6ad6d1d3bbdf | 106 | wait_ms(700); |
edodm85 | 0:de2102ba3121 | 107 | pc.printf("signal: %2.0d", radio.SignalLevel()); |
edodm85 | 0:de2102ba3121 | 108 | pc.printf("freq: %000.2f ", radio.FreqCurrent()); |
edodm85 | 0:de2102ba3121 | 109 | }else |
edodm85 | 0:de2102ba3121 | 110 | if(strncmp("band", word, 4) == 0) |
edodm85 | 0:de2102ba3121 | 111 | { |
edodm85 | 0:de2102ba3121 | 112 | char word_temp[2]; |
edodm85 | 0:de2102ba3121 | 113 | strncpy(word_temp, &word[5], 2); |
edodm85 | 0:de2102ba3121 | 114 | pc.printf("string: %s\r\n", word_temp); |
edodm85 | 0:de2102ba3121 | 115 | |
edodm85 | 0:de2102ba3121 | 116 | if(strncmp("EU", word_temp, 2) == 0) |
edodm85 | 0:de2102ba3121 | 117 | { |
edodm85 | 0:de2102ba3121 | 118 | radio.SetBand('e'); |
edodm85 | 0:de2102ba3121 | 119 | StartFreq = 87.5; |
edodm85 | 0:de2102ba3121 | 120 | EndFreq = 108; |
edodm85 | 0:de2102ba3121 | 121 | }else |
edodm85 | 0:de2102ba3121 | 122 | if(strncmp("JP", word_temp, 2) == 0) |
edodm85 | 0:de2102ba3121 | 123 | { |
edodm85 | 0:de2102ba3121 | 124 | radio.SetBand('j'); |
edodm85 | 0:de2102ba3121 | 125 | StartFreq = 76; |
edodm85 | 0:de2102ba3121 | 126 | EndFreq = 91; |
edodm85 | 0:de2102ba3121 | 127 | } |
edodm85 | 0:de2102ba3121 | 128 | } |
edodm85 | 0:de2102ba3121 | 129 | |
edodm85 | 0:de2102ba3121 | 130 | memset(word, 0, sizeof(word)); |
edodm85 | 0:de2102ba3121 | 131 | } |
edodm85 | 0:de2102ba3121 | 132 |