Clock generator @ 145 MHz and 7 mhz
Fork of Check_Si5351A_Clock_generator by
si5351a_check.cpp@1:2b29f68043f7, 2017-01-01 (annotated)
- Committer:
- kenjiArai
- Date:
- Sun Jan 01 01:33:59 2017 +0000
- Revision:
- 1:2b29f68043f7
- Parent:
- 0:d68f1e7f7f49
- Child:
- 2:73d79424daa5
clean up
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:d68f1e7f7f49 | 1 | /* |
kenjiArai | 0:d68f1e7f7f49 | 2 | * mbed Application program / Si5351A sample program |
kenjiArai | 0:d68f1e7f7f49 | 3 | * tested on: |
kenjiArai | 0:d68f1e7f7f49 | 4 | * ST Nucleo-F411RE & F401RE |
kenjiArai | 0:d68f1e7f7f49 | 5 | * LPC1114FN28 |
kenjiArai | 0:d68f1e7f7f49 | 6 | * |
kenjiArai | 0:d68f1e7f7f49 | 7 | * Copyright (c) 2016,'17 Kenji Arai / JH1PJL |
kenjiArai | 0:d68f1e7f7f49 | 8 | * http://www.page.sannet.ne.jp/kenjia/index.html |
kenjiArai | 0:d68f1e7f7f49 | 9 | * http://mbed.org/users/kenjiArai/ |
kenjiArai | 0:d68f1e7f7f49 | 10 | * Created: December 28th, 2016 |
kenjiArai | 0:d68f1e7f7f49 | 11 | * Revised: January 1st, 2017 |
kenjiArai | 0:d68f1e7f7f49 | 12 | * |
kenjiArai | 0:d68f1e7f7f49 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
kenjiArai | 0:d68f1e7f7f49 | 14 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
kenjiArai | 0:d68f1e7f7f49 | 15 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
kenjiArai | 0:d68f1e7f7f49 | 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kenjiArai | 0:d68f1e7f7f49 | 17 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
kenjiArai | 0:d68f1e7f7f49 | 18 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR |
kenjiArai | 0:d68f1e7f7f49 | 19 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kenjiArai | 0:d68f1e7f7f49 | 20 | */ |
kenjiArai | 0:d68f1e7f7f49 | 21 | |
kenjiArai | 0:d68f1e7f7f49 | 22 | // Include -------------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 23 | #include "mbed.h" |
kenjiArai | 0:d68f1e7f7f49 | 24 | #include "si5351a.h" |
kenjiArai | 0:d68f1e7f7f49 | 25 | #include "si5351a_check.h" |
kenjiArai | 0:d68f1e7f7f49 | 26 | |
kenjiArai | 0:d68f1e7f7f49 | 27 | // Definition ----------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 28 | |
kenjiArai | 0:d68f1e7f7f49 | 29 | // Object --------------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 30 | Serial pc(USBTX, USBRX); |
kenjiArai | 0:d68f1e7f7f49 | 31 | //I2C i2c(dp5, dp27); // communication with Si5351A |
kenjiArai | 0:d68f1e7f7f49 | 32 | I2C i2c(I2C_SDA, I2C_SCL); // communication with Si5351A |
kenjiArai | 0:d68f1e7f7f49 | 33 | SI5351A clk(i2c, 25000000UL); // base clock = 25.0MHz |
kenjiArai | 0:d68f1e7f7f49 | 34 | |
kenjiArai | 0:d68f1e7f7f49 | 35 | //------------------------------------------------------------------------------ |
kenjiArai | 0:d68f1e7f7f49 | 36 | // Control Program |
kenjiArai | 0:d68f1e7f7f49 | 37 | //------------------------------------------------------------------------------ |
kenjiArai | 0:d68f1e7f7f49 | 38 | int main() |
kenjiArai | 0:d68f1e7f7f49 | 39 | { |
kenjiArai | 0:d68f1e7f7f49 | 40 | while (true){ test_si5351();} |
kenjiArai | 0:d68f1e7f7f49 | 41 | } |
kenjiArai | 0:d68f1e7f7f49 | 42 | |
kenjiArai | 0:d68f1e7f7f49 | 43 | // Help Massage |
kenjiArai | 0:d68f1e7f7f49 | 44 | void msg_hlp (void) |
kenjiArai | 0:d68f1e7f7f49 | 45 | { |
kenjiArai | 0:d68f1e7f7f49 | 46 | PRINTF(opening_msg); |
kenjiArai | 0:d68f1e7f7f49 | 47 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 48 | PRINTF("0 - Check CLK0 output between 50KHz to 90MHz"); |
kenjiArai | 0:d68f1e7f7f49 | 49 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 50 | PRINTF("1 - Check CLK1 (same as #1)"); |
kenjiArai | 0:d68f1e7f7f49 | 51 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 52 | PRINTF("2 - Check CLK2 (same as #1)"); |
kenjiArai | 0:d68f1e7f7f49 | 53 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 54 | PRINTF("3 - Example CLK0:120.00MHz, CLK1:12.00MHz, CLK2:13.56MHz"); |
kenjiArai | 0:d68f1e7f7f49 | 55 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 56 | PRINTF("4 - Set desired freq. into CLK0"); |
kenjiArai | 0:d68f1e7f7f49 | 57 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 58 | PRINTF("5 - Set desired freq. into CLK0 & CLK1"); |
kenjiArai | 0:d68f1e7f7f49 | 59 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 60 | PRINTF("6 - Set desired freq. into CLK0, CLK1 & CLK2"); |
kenjiArai | 0:d68f1e7f7f49 | 61 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 62 | PRINTF("7 - CLK0: set desired center freq. then shift +/- range"); |
kenjiArai | 0:d68f1e7f7f49 | 63 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 64 | PRINTF("a - All clear registers"); |
kenjiArai | 0:d68f1e7f7f49 | 65 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 66 | PRINTF("c - Show current configration"); |
kenjiArai | 0:d68f1e7f7f49 | 67 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 68 | PRINTF("r - Show current resisters"); |
kenjiArai | 0:d68f1e7f7f49 | 69 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 70 | PRINTF("x - Go to special command"); |
kenjiArai | 0:d68f1e7f7f49 | 71 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 72 | PRINTF("Hit any key then return to prompt screen"); |
kenjiArai | 0:d68f1e7f7f49 | 73 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 74 | PRINTF("Reset mbed board -> please hit key <Alt>+<B>"); |
kenjiArai | 0:d68f1e7f7f49 | 75 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 76 | } |
kenjiArai | 0:d68f1e7f7f49 | 77 | |
kenjiArai | 0:d68f1e7f7f49 | 78 | // ---------- Program starts here! --------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 79 | void test_si5351(void) |
kenjiArai | 0:d68f1e7f7f49 | 80 | { |
kenjiArai | 0:d68f1e7f7f49 | 81 | char *ptr; |
kenjiArai | 0:d68f1e7f7f49 | 82 | int32_t f; |
kenjiArai | 0:d68f1e7f7f49 | 83 | |
kenjiArai | 0:d68f1e7f7f49 | 84 | BAUD(BAUD_RATE); |
kenjiArai | 0:d68f1e7f7f49 | 85 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 86 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 87 | PRINTF("%s [Help:'?' key]", opening_msg); |
kenjiArai | 0:d68f1e7f7f49 | 88 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 89 | clk.all_reset(); |
kenjiArai | 0:d68f1e7f7f49 | 90 | for (;;) { |
kenjiArai | 0:d68f1e7f7f49 | 91 | put_r(); |
kenjiArai | 0:d68f1e7f7f49 | 92 | PUTC('>'); |
kenjiArai | 0:d68f1e7f7f49 | 93 | ptr = linebuf; |
kenjiArai | 0:d68f1e7f7f49 | 94 | get_line(ptr, sizeof(linebuf)); |
kenjiArai | 0:d68f1e7f7f49 | 95 | put_r(); |
kenjiArai | 0:d68f1e7f7f49 | 96 | switch (*ptr++) { |
kenjiArai | 0:d68f1e7f7f49 | 97 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 98 | // test0 |
kenjiArai | 0:d68f1e7f7f49 | 99 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 100 | case '0' : |
kenjiArai | 0:d68f1e7f7f49 | 101 | clk.all_reset(); |
kenjiArai | 0:d68f1e7f7f49 | 102 | test(0); |
kenjiArai | 0:d68f1e7f7f49 | 103 | //put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 104 | break; |
kenjiArai | 0:d68f1e7f7f49 | 105 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 106 | // test1 |
kenjiArai | 0:d68f1e7f7f49 | 107 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 108 | case '1' : |
kenjiArai | 0:d68f1e7f7f49 | 109 | clk.all_reset(); |
kenjiArai | 0:d68f1e7f7f49 | 110 | test(1); |
kenjiArai | 0:d68f1e7f7f49 | 111 | //put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 112 | break; |
kenjiArai | 0:d68f1e7f7f49 | 113 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 114 | // test2 |
kenjiArai | 0:d68f1e7f7f49 | 115 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 116 | case '2' : |
kenjiArai | 0:d68f1e7f7f49 | 117 | clk.all_reset(); |
kenjiArai | 0:d68f1e7f7f49 | 118 | test(2); |
kenjiArai | 0:d68f1e7f7f49 | 119 | //put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 120 | break; |
kenjiArai | 0:d68f1e7f7f49 | 121 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 122 | // test3 |
kenjiArai | 0:d68f1e7f7f49 | 123 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 124 | case '3' : |
kenjiArai | 0:d68f1e7f7f49 | 125 | clk.debug_example_clock(); |
kenjiArai | 0:d68f1e7f7f49 | 126 | //clk.debug_reg_print(); |
kenjiArai | 0:d68f1e7f7f49 | 127 | //put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 128 | break; |
kenjiArai | 0:d68f1e7f7f49 | 129 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 130 | // test4 |
kenjiArai | 0:d68f1e7f7f49 | 131 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 132 | case '4' : |
kenjiArai | 0:d68f1e7f7f49 | 133 | clk.all_reset(); |
kenjiArai | 0:d68f1e7f7f49 | 134 | PRINTF("CLK0 %s", msg0); |
kenjiArai | 0:d68f1e7f7f49 | 135 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 136 | ptr = linebuf; |
kenjiArai | 0:d68f1e7f7f49 | 137 | get_line(ptr, buf_size); |
kenjiArai | 0:d68f1e7f7f49 | 138 | put_r(); |
kenjiArai | 0:d68f1e7f7f49 | 139 | if (xatoi(&ptr,&f)){ |
kenjiArai | 0:d68f1e7f7f49 | 140 | if (f < 0){ break;} |
kenjiArai | 0:d68f1e7f7f49 | 141 | PRINTF("CLK0:%u [Hz]", clk.set_frequency(0, f)); |
kenjiArai | 0:d68f1e7f7f49 | 142 | } else { |
kenjiArai | 0:d68f1e7f7f49 | 143 | PUTC('?'); |
kenjiArai | 0:d68f1e7f7f49 | 144 | } |
kenjiArai | 0:d68f1e7f7f49 | 145 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 146 | break; |
kenjiArai | 0:d68f1e7f7f49 | 147 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 148 | // test5 |
kenjiArai | 0:d68f1e7f7f49 | 149 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 150 | case '5' : |
kenjiArai | 0:d68f1e7f7f49 | 151 | clk.all_reset(); |
kenjiArai | 0:d68f1e7f7f49 | 152 | PRINTF("CLK0 %s", msg0); |
kenjiArai | 0:d68f1e7f7f49 | 153 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 154 | ptr = linebuf; |
kenjiArai | 0:d68f1e7f7f49 | 155 | get_line(ptr, buf_size); |
kenjiArai | 0:d68f1e7f7f49 | 156 | put_r(); |
kenjiArai | 0:d68f1e7f7f49 | 157 | if (xatoi(&ptr,&f)){ |
kenjiArai | 0:d68f1e7f7f49 | 158 | if (f < 0){ break;} |
kenjiArai | 0:d68f1e7f7f49 | 159 | PRINTF("CLK0:%u [Hz]", clk.set_frequency(0, f)); |
kenjiArai | 0:d68f1e7f7f49 | 160 | } else { |
kenjiArai | 0:d68f1e7f7f49 | 161 | PUTC('?'); |
kenjiArai | 0:d68f1e7f7f49 | 162 | } |
kenjiArai | 0:d68f1e7f7f49 | 163 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 164 | PRINTF("CLK1 %s", msg0); |
kenjiArai | 0:d68f1e7f7f49 | 165 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 166 | ptr = linebuf; |
kenjiArai | 0:d68f1e7f7f49 | 167 | get_line(ptr, buf_size); |
kenjiArai | 0:d68f1e7f7f49 | 168 | put_r(); |
kenjiArai | 0:d68f1e7f7f49 | 169 | if (xatoi(&ptr,&f)){ |
kenjiArai | 0:d68f1e7f7f49 | 170 | if (f < 0){ break;} |
kenjiArai | 0:d68f1e7f7f49 | 171 | PRINTF("CLK1:%u [Hz]", clk.set_frequency(1, f)); |
kenjiArai | 0:d68f1e7f7f49 | 172 | } else { |
kenjiArai | 0:d68f1e7f7f49 | 173 | PUTC('?'); |
kenjiArai | 0:d68f1e7f7f49 | 174 | } |
kenjiArai | 0:d68f1e7f7f49 | 175 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 176 | break; |
kenjiArai | 0:d68f1e7f7f49 | 177 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 178 | // test6 |
kenjiArai | 0:d68f1e7f7f49 | 179 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 180 | case '6' : |
kenjiArai | 0:d68f1e7f7f49 | 181 | clk.all_reset(); |
kenjiArai | 0:d68f1e7f7f49 | 182 | PRINTF("CLK0 %s", msg0); |
kenjiArai | 0:d68f1e7f7f49 | 183 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 184 | ptr = linebuf; |
kenjiArai | 0:d68f1e7f7f49 | 185 | get_line(ptr, buf_size); |
kenjiArai | 0:d68f1e7f7f49 | 186 | put_r(); |
kenjiArai | 0:d68f1e7f7f49 | 187 | if (xatoi(&ptr,&f)){ |
kenjiArai | 0:d68f1e7f7f49 | 188 | if (f < 0){ break;} |
kenjiArai | 0:d68f1e7f7f49 | 189 | PRINTF("CLK0:%u [Hz]", clk.set_frequency(0, f)); |
kenjiArai | 0:d68f1e7f7f49 | 190 | } else { |
kenjiArai | 0:d68f1e7f7f49 | 191 | PUTC('?'); |
kenjiArai | 0:d68f1e7f7f49 | 192 | } |
kenjiArai | 0:d68f1e7f7f49 | 193 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 194 | PRINTF("CLK1 %s", msg0); |
kenjiArai | 0:d68f1e7f7f49 | 195 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 196 | PRINTF( |
kenjiArai | 0:d68f1e7f7f49 | 197 | "If you set CLK1 over 100MHz, you cannt set CLK2 anymore"); |
kenjiArai | 0:d68f1e7f7f49 | 198 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 199 | ptr = linebuf; |
kenjiArai | 0:d68f1e7f7f49 | 200 | get_line(ptr, buf_size); |
kenjiArai | 0:d68f1e7f7f49 | 201 | put_r(); |
kenjiArai | 0:d68f1e7f7f49 | 202 | if (xatoi(&ptr,&f)){ |
kenjiArai | 0:d68f1e7f7f49 | 203 | if (f < 0){ break;} |
kenjiArai | 0:d68f1e7f7f49 | 204 | PRINTF("CLK1:%u [Hz]", clk.set_frequency(1, f)); |
kenjiArai | 0:d68f1e7f7f49 | 205 | } else { |
kenjiArai | 0:d68f1e7f7f49 | 206 | PUTC('?'); |
kenjiArai | 0:d68f1e7f7f49 | 207 | } |
kenjiArai | 0:d68f1e7f7f49 | 208 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 209 | PRINTF("CLK2 %s", msg0); |
kenjiArai | 0:d68f1e7f7f49 | 210 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 211 | ptr = linebuf; |
kenjiArai | 0:d68f1e7f7f49 | 212 | get_line(ptr, buf_size); |
kenjiArai | 0:d68f1e7f7f49 | 213 | put_r(); |
kenjiArai | 0:d68f1e7f7f49 | 214 | if (xatoi(&ptr,&f)){ |
kenjiArai | 0:d68f1e7f7f49 | 215 | if (f < 0){ break;} |
kenjiArai | 0:d68f1e7f7f49 | 216 | PRINTF("CLK2:%u [Hz]", clk.set_frequency(2, f)); |
kenjiArai | 0:d68f1e7f7f49 | 217 | } else { |
kenjiArai | 0:d68f1e7f7f49 | 218 | PUTC('?'); |
kenjiArai | 0:d68f1e7f7f49 | 219 | } |
kenjiArai | 0:d68f1e7f7f49 | 220 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 221 | break; |
kenjiArai | 0:d68f1e7f7f49 | 222 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 223 | // test7 CLK0: set desired center freq. then shift +/- range |
kenjiArai | 0:d68f1e7f7f49 | 224 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 225 | case '7' : |
kenjiArai | 0:d68f1e7f7f49 | 226 | clk.all_reset(); |
kenjiArai | 0:d68f1e7f7f49 | 227 | PRINTF("CLK0 %s", msg0); |
kenjiArai | 0:d68f1e7f7f49 | 228 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 229 | ptr = linebuf; |
kenjiArai | 0:d68f1e7f7f49 | 230 | get_line(ptr, buf_size); |
kenjiArai | 0:d68f1e7f7f49 | 231 | put_r(); |
kenjiArai | 0:d68f1e7f7f49 | 232 | if (xatoi(&ptr,&f)){ |
kenjiArai | 0:d68f1e7f7f49 | 233 | if (f < 0){ break;} |
kenjiArai | 0:d68f1e7f7f49 | 234 | PRINTF("CLK0:%u [Hz]", clk.set_frequency(0, f)); |
kenjiArai | 0:d68f1e7f7f49 | 235 | } else { |
kenjiArai | 0:d68f1e7f7f49 | 236 | PUTC('?'); |
kenjiArai | 0:d68f1e7f7f49 | 237 | } |
kenjiArai | 0:d68f1e7f7f49 | 238 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 239 | PRINTF("Please enter sift command [Help: ?]"); |
kenjiArai | 0:d68f1e7f7f49 | 240 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 241 | while (true){ |
kenjiArai | 0:d68f1e7f7f49 | 242 | PRINTF("[S]>"); |
kenjiArai | 0:d68f1e7f7f49 | 243 | ptr = linebuf; |
kenjiArai | 0:d68f1e7f7f49 | 244 | get_line(ptr, buf_size); |
kenjiArai | 0:d68f1e7f7f49 | 245 | put_r(); |
kenjiArai | 0:d68f1e7f7f49 | 246 | switch(*ptr) { |
kenjiArai | 0:d68f1e7f7f49 | 247 | case 'p' : |
kenjiArai | 0:d68f1e7f7f49 | 248 | PRINTF("Shift to %u [Hz]", clk.shift_freq(0, 10)); |
kenjiArai | 0:d68f1e7f7f49 | 249 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 250 | break; |
kenjiArai | 0:d68f1e7f7f49 | 251 | case 'm' : |
kenjiArai | 0:d68f1e7f7f49 | 252 | PRINTF("Shift to %u [Hz]", clk.shift_freq(0, -10)); |
kenjiArai | 0:d68f1e7f7f49 | 253 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 254 | break; |
kenjiArai | 0:d68f1e7f7f49 | 255 | case 's' : |
kenjiArai | 0:d68f1e7f7f49 | 256 | ptr++; |
kenjiArai | 0:d68f1e7f7f49 | 257 | xatoi(&ptr,&f); |
kenjiArai | 0:d68f1e7f7f49 | 258 | PRINTF("offset=%d\r\n", f); |
kenjiArai | 0:d68f1e7f7f49 | 259 | PRINTF("Shift to %u [Hz]", clk.shift_freq(0, f)); |
kenjiArai | 0:d68f1e7f7f49 | 260 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 261 | break; |
kenjiArai | 0:d68f1e7f7f49 | 262 | case '?' : |
kenjiArai | 0:d68f1e7f7f49 | 263 | PRINTF("p -> +10Hz"); |
kenjiArai | 0:d68f1e7f7f49 | 264 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 265 | PRINTF("m -> -10Hz"); |
kenjiArai | 0:d68f1e7f7f49 | 266 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 267 | PRINTF("s -> Shift +/-x Hz (example -100)"); |
kenjiArai | 0:d68f1e7f7f49 | 268 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 269 | PRINTF("? -> You know this"); |
kenjiArai | 0:d68f1e7f7f49 | 270 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 271 | PRINTF("e -> Exit"); |
kenjiArai | 0:d68f1e7f7f49 | 272 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 273 | break; |
kenjiArai | 0:d68f1e7f7f49 | 274 | case 'e' : |
kenjiArai | 0:d68f1e7f7f49 | 275 | break; |
kenjiArai | 0:d68f1e7f7f49 | 276 | default: |
kenjiArai | 0:d68f1e7f7f49 | 277 | PUTC('?'); |
kenjiArai | 0:d68f1e7f7f49 | 278 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 279 | } |
kenjiArai | 0:d68f1e7f7f49 | 280 | if (*ptr == 'e'){ |
kenjiArai | 0:d68f1e7f7f49 | 281 | break; |
kenjiArai | 0:d68f1e7f7f49 | 282 | } |
kenjiArai | 0:d68f1e7f7f49 | 283 | } |
kenjiArai | 0:d68f1e7f7f49 | 284 | break; |
kenjiArai | 0:d68f1e7f7f49 | 285 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 286 | // All clear alll registers |
kenjiArai | 0:d68f1e7f7f49 | 287 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 288 | case 'a' : |
kenjiArai | 0:d68f1e7f7f49 | 289 | clk.all_reset(); |
kenjiArai | 0:d68f1e7f7f49 | 290 | PRINTF("Cleared all of registers!\r\n"); |
kenjiArai | 0:d68f1e7f7f49 | 291 | break; |
kenjiArai | 0:d68f1e7f7f49 | 292 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 293 | // Show configration |
kenjiArai | 0:d68f1e7f7f49 | 294 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 295 | case 'c' : |
kenjiArai | 0:d68f1e7f7f49 | 296 | clk.debug_current_config(); |
kenjiArai | 0:d68f1e7f7f49 | 297 | //put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 298 | break; |
kenjiArai | 0:d68f1e7f7f49 | 299 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 300 | // Show resisters |
kenjiArai | 0:d68f1e7f7f49 | 301 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 302 | case 'r' : |
kenjiArai | 0:d68f1e7f7f49 | 303 | clk.debug_reg_print(); |
kenjiArai | 0:d68f1e7f7f49 | 304 | //put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 305 | break; |
kenjiArai | 0:d68f1e7f7f49 | 306 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 307 | // Go to special command |
kenjiArai | 0:d68f1e7f7f49 | 308 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 309 | case 'x' : |
kenjiArai | 0:d68f1e7f7f49 | 310 | special_command(); |
kenjiArai | 0:d68f1e7f7f49 | 311 | break; |
kenjiArai | 0:d68f1e7f7f49 | 312 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 313 | // help |
kenjiArai | 0:d68f1e7f7f49 | 314 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 315 | case '?' : |
kenjiArai | 0:d68f1e7f7f49 | 316 | msg_hlp(); |
kenjiArai | 0:d68f1e7f7f49 | 317 | break; |
kenjiArai | 0:d68f1e7f7f49 | 318 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 319 | // no support |
kenjiArai | 0:d68f1e7f7f49 | 320 | //-------------------------------------------------------------- |
kenjiArai | 0:d68f1e7f7f49 | 321 | default: |
kenjiArai | 0:d68f1e7f7f49 | 322 | PUTC('?'); |
kenjiArai | 0:d68f1e7f7f49 | 323 | put_rn(); |
kenjiArai | 0:d68f1e7f7f49 | 324 | break; |
kenjiArai | 0:d68f1e7f7f49 | 325 | } |
kenjiArai | 0:d68f1e7f7f49 | 326 | } |
kenjiArai | 0:d68f1e7f7f49 | 327 | } |
kenjiArai | 0:d68f1e7f7f49 | 328 | |
kenjiArai | 1:2b29f68043f7 | 329 | |
kenjiArai | 1:2b29f68043f7 | 330 | #if defined(INCREMENT) |
kenjiArai | 1:2b29f68043f7 | 331 | void test(uint8_t channel) |
kenjiArai | 1:2b29f68043f7 | 332 | { |
kenjiArai | 1:2b29f68043f7 | 333 | uint32_t f_set = 4000; // 4KHz |
kenjiArai | 1:2b29f68043f7 | 334 | double f = 0; |
kenjiArai | 1:2b29f68043f7 | 335 | uint32_t flg = 0; |
kenjiArai | 1:2b29f68043f7 | 336 | clk.all_reset(); |
kenjiArai | 1:2b29f68043f7 | 337 | f = clk.set_frequency(channel, f_set); |
kenjiArai | 1:2b29f68043f7 | 338 | clk.debug_reg_print(); |
kenjiArai | 1:2b29f68043f7 | 339 | PRINTF("CLK%u = %10.6f MHz\r\n", channel, f / 1000000.0f); |
kenjiArai | 1:2b29f68043f7 | 340 | while(true){ |
kenjiArai | 1:2b29f68043f7 | 341 | f = clk.set_frequency(channel, f_set); |
kenjiArai | 1:2b29f68043f7 | 342 | PRINTF("CLK%u = %10.6f MHz\r\n", channel, f / 1000000.0f); |
kenjiArai | 1:2b29f68043f7 | 343 | if (flg){ |
kenjiArai | 1:2b29f68043f7 | 344 | f_set = f * 0.95f; |
kenjiArai | 1:2b29f68043f7 | 345 | if (f_set < 5000){ |
kenjiArai | 1:2b29f68043f7 | 346 | flg = 0; |
kenjiArai | 1:2b29f68043f7 | 347 | } |
kenjiArai | 1:2b29f68043f7 | 348 | } else { |
kenjiArai | 1:2b29f68043f7 | 349 | f_set = f * 1.05f; |
kenjiArai | 1:2b29f68043f7 | 350 | if (f_set > 190000000){ |
kenjiArai | 1:2b29f68043f7 | 351 | flg = 1; |
kenjiArai | 1:2b29f68043f7 | 352 | } |
kenjiArai | 1:2b29f68043f7 | 353 | } |
kenjiArai | 1:2b29f68043f7 | 354 | if (READABLE()) { |
kenjiArai | 1:2b29f68043f7 | 355 | GETC(); |
kenjiArai | 1:2b29f68043f7 | 356 | return; |
kenjiArai | 1:2b29f68043f7 | 357 | } |
kenjiArai | 1:2b29f68043f7 | 358 | wait(1.0); |
kenjiArai | 1:2b29f68043f7 | 359 | } |
kenjiArai | 1:2b29f68043f7 | 360 | } |
kenjiArai | 1:2b29f68043f7 | 361 | #endif |
kenjiArai | 1:2b29f68043f7 | 362 | |
kenjiArai | 1:2b29f68043f7 | 363 | #if defined(TABLE_LOOK) |
kenjiArai | 1:2b29f68043f7 | 364 | void test(uint8_t channel) |
kenjiArai | 1:2b29f68043f7 | 365 | { |
kenjiArai | 1:2b29f68043f7 | 366 | uint32_t f_set = 0; |
kenjiArai | 1:2b29f68043f7 | 367 | uint32_t i,j; |
kenjiArai | 1:2b29f68043f7 | 368 | double f = 0; |
kenjiArai | 1:2b29f68043f7 | 369 | clk.all_reset(); |
kenjiArai | 1:2b29f68043f7 | 370 | while(true){ |
kenjiArai | 1:2b29f68043f7 | 371 | for (i = 0; ; i++){ |
kenjiArai | 1:2b29f68043f7 | 372 | f_set = freq_tbl[i]; |
kenjiArai | 1:2b29f68043f7 | 373 | if (f_set == 0){ |
kenjiArai | 1:2b29f68043f7 | 374 | break; |
kenjiArai | 1:2b29f68043f7 | 375 | } |
kenjiArai | 1:2b29f68043f7 | 376 | f = clk.set_frequency(channel, f_set); |
kenjiArai | 1:2b29f68043f7 | 377 | PRINTF("CLK%u = %10.6f MHz\r\n", channel, f / 1000000.0f); |
kenjiArai | 1:2b29f68043f7 | 378 | if (READABLE()) { |
kenjiArai | 1:2b29f68043f7 | 379 | GETC(); |
kenjiArai | 1:2b29f68043f7 | 380 | return; |
kenjiArai | 1:2b29f68043f7 | 381 | } |
kenjiArai | 1:2b29f68043f7 | 382 | wait(1.0); |
kenjiArai | 1:2b29f68043f7 | 383 | } |
kenjiArai | 1:2b29f68043f7 | 384 | for (j = i - 2; j > 0 ; j--){ |
kenjiArai | 1:2b29f68043f7 | 385 | f_set = freq_tbl[j]; |
kenjiArai | 1:2b29f68043f7 | 386 | f = clk.set_frequency(channel, f_set); |
kenjiArai | 1:2b29f68043f7 | 387 | PRINTF("CLK%u = %10.6f MHz\r\n", channel, f / 1000000.0f); |
kenjiArai | 1:2b29f68043f7 | 388 | if (READABLE()) { |
kenjiArai | 1:2b29f68043f7 | 389 | GETC(); |
kenjiArai | 1:2b29f68043f7 | 390 | return; |
kenjiArai | 1:2b29f68043f7 | 391 | } |
kenjiArai | 1:2b29f68043f7 | 392 | wait(1.0); |
kenjiArai | 1:2b29f68043f7 | 393 | } |
kenjiArai | 1:2b29f68043f7 | 394 | } |
kenjiArai | 1:2b29f68043f7 | 395 | } |
kenjiArai | 1:2b29f68043f7 | 396 | #endif |
kenjiArai | 1:2b29f68043f7 | 397 | |
kenjiArai | 1:2b29f68043f7 | 398 | void special_command(void) |
kenjiArai | 1:2b29f68043f7 | 399 | { |
kenjiArai | 1:2b29f68043f7 | 400 | PRINTF("Not impliment yet"); |
kenjiArai | 1:2b29f68043f7 | 401 | put_rn(); |
kenjiArai | 1:2b29f68043f7 | 402 | } |
kenjiArai | 1:2b29f68043f7 | 403 | |
kenjiArai | 0:d68f1e7f7f49 | 404 | // Put \r\n |
kenjiArai | 0:d68f1e7f7f49 | 405 | void put_rn ( void ) |
kenjiArai | 0:d68f1e7f7f49 | 406 | { |
kenjiArai | 0:d68f1e7f7f49 | 407 | PUTC('\r'); |
kenjiArai | 0:d68f1e7f7f49 | 408 | PUTC('\n'); |
kenjiArai | 0:d68f1e7f7f49 | 409 | } |
kenjiArai | 0:d68f1e7f7f49 | 410 | |
kenjiArai | 0:d68f1e7f7f49 | 411 | // Put \r |
kenjiArai | 0:d68f1e7f7f49 | 412 | void put_r ( void ) |
kenjiArai | 0:d68f1e7f7f49 | 413 | { |
kenjiArai | 0:d68f1e7f7f49 | 414 | PUTC('\r'); |
kenjiArai | 0:d68f1e7f7f49 | 415 | } |
kenjiArai | 0:d68f1e7f7f49 | 416 | |
kenjiArai | 0:d68f1e7f7f49 | 417 | // Change string -> integer |
kenjiArai | 0:d68f1e7f7f49 | 418 | int xatoi (char **str, int32_t *res) |
kenjiArai | 0:d68f1e7f7f49 | 419 | { |
kenjiArai | 0:d68f1e7f7f49 | 420 | uint32_t val; |
kenjiArai | 0:d68f1e7f7f49 | 421 | int8_t c, radix, s = 0; |
kenjiArai | 0:d68f1e7f7f49 | 422 | |
kenjiArai | 0:d68f1e7f7f49 | 423 | while ((c = **str) == ' ') (*str)++; |
kenjiArai | 0:d68f1e7f7f49 | 424 | if (c == '-') { |
kenjiArai | 0:d68f1e7f7f49 | 425 | s = 1; |
kenjiArai | 0:d68f1e7f7f49 | 426 | c = *(++(*str)); |
kenjiArai | 0:d68f1e7f7f49 | 427 | } |
kenjiArai | 0:d68f1e7f7f49 | 428 | if (c == '+') { |
kenjiArai | 0:d68f1e7f7f49 | 429 | c = *(++(*str)); |
kenjiArai | 0:d68f1e7f7f49 | 430 | } |
kenjiArai | 0:d68f1e7f7f49 | 431 | if (c == '0') { |
kenjiArai | 0:d68f1e7f7f49 | 432 | c = *(++(*str)); |
kenjiArai | 0:d68f1e7f7f49 | 433 | if (c <= ' ') { |
kenjiArai | 0:d68f1e7f7f49 | 434 | *res = 0; |
kenjiArai | 0:d68f1e7f7f49 | 435 | return 1; |
kenjiArai | 0:d68f1e7f7f49 | 436 | } |
kenjiArai | 0:d68f1e7f7f49 | 437 | if (c == 'x') { |
kenjiArai | 0:d68f1e7f7f49 | 438 | radix = 16; |
kenjiArai | 0:d68f1e7f7f49 | 439 | c = *(++(*str)); |
kenjiArai | 0:d68f1e7f7f49 | 440 | } else { |
kenjiArai | 0:d68f1e7f7f49 | 441 | if (c == 'b') { |
kenjiArai | 0:d68f1e7f7f49 | 442 | radix = 2; |
kenjiArai | 0:d68f1e7f7f49 | 443 | c = *(++(*str)); |
kenjiArai | 0:d68f1e7f7f49 | 444 | } else { |
kenjiArai | 0:d68f1e7f7f49 | 445 | if ((c >= '0')&&(c <= '9')) { |
kenjiArai | 0:d68f1e7f7f49 | 446 | radix = 8; |
kenjiArai | 0:d68f1e7f7f49 | 447 | } else { |
kenjiArai | 0:d68f1e7f7f49 | 448 | return 0; |
kenjiArai | 0:d68f1e7f7f49 | 449 | } |
kenjiArai | 0:d68f1e7f7f49 | 450 | } |
kenjiArai | 0:d68f1e7f7f49 | 451 | } |
kenjiArai | 0:d68f1e7f7f49 | 452 | } else { |
kenjiArai | 0:d68f1e7f7f49 | 453 | if ((c < '1')||(c > '9')) { |
kenjiArai | 0:d68f1e7f7f49 | 454 | return 0; |
kenjiArai | 0:d68f1e7f7f49 | 455 | } |
kenjiArai | 0:d68f1e7f7f49 | 456 | radix = 10; |
kenjiArai | 0:d68f1e7f7f49 | 457 | } |
kenjiArai | 0:d68f1e7f7f49 | 458 | val = 0; |
kenjiArai | 0:d68f1e7f7f49 | 459 | while (c > ' ') { |
kenjiArai | 0:d68f1e7f7f49 | 460 | if (c >= 'a') c -= 0x20; |
kenjiArai | 0:d68f1e7f7f49 | 461 | c -= '0'; |
kenjiArai | 0:d68f1e7f7f49 | 462 | if (c >= 17) { |
kenjiArai | 0:d68f1e7f7f49 | 463 | c -= 7; |
kenjiArai | 0:d68f1e7f7f49 | 464 | if (c <= 9) return 0; |
kenjiArai | 0:d68f1e7f7f49 | 465 | } |
kenjiArai | 0:d68f1e7f7f49 | 466 | if (c >= radix) return 0; |
kenjiArai | 0:d68f1e7f7f49 | 467 | val = val * radix + c; |
kenjiArai | 0:d68f1e7f7f49 | 468 | c = *(++(*str)); |
kenjiArai | 0:d68f1e7f7f49 | 469 | } |
kenjiArai | 0:d68f1e7f7f49 | 470 | if (s) val = -val; |
kenjiArai | 0:d68f1e7f7f49 | 471 | *res = val; |
kenjiArai | 0:d68f1e7f7f49 | 472 | return 1; |
kenjiArai | 0:d68f1e7f7f49 | 473 | } |
kenjiArai | 0:d68f1e7f7f49 | 474 | |
kenjiArai | 0:d68f1e7f7f49 | 475 | // Get key input data |
kenjiArai | 0:d68f1e7f7f49 | 476 | void get_line (char *buff, int len) |
kenjiArai | 0:d68f1e7f7f49 | 477 | { |
kenjiArai | 0:d68f1e7f7f49 | 478 | char c; |
kenjiArai | 0:d68f1e7f7f49 | 479 | int idx = 0; |
kenjiArai | 0:d68f1e7f7f49 | 480 | |
kenjiArai | 0:d68f1e7f7f49 | 481 | for (;;) { |
kenjiArai | 0:d68f1e7f7f49 | 482 | c = GETC(); |
kenjiArai | 0:d68f1e7f7f49 | 483 | if (c == '\r') { |
kenjiArai | 0:d68f1e7f7f49 | 484 | buff[idx++] = c; |
kenjiArai | 0:d68f1e7f7f49 | 485 | break; |
kenjiArai | 0:d68f1e7f7f49 | 486 | } |
kenjiArai | 0:d68f1e7f7f49 | 487 | if ((c == '\b') && idx) { |
kenjiArai | 0:d68f1e7f7f49 | 488 | idx--; |
kenjiArai | 0:d68f1e7f7f49 | 489 | PUTC(c); |
kenjiArai | 0:d68f1e7f7f49 | 490 | PUTC(' '); |
kenjiArai | 0:d68f1e7f7f49 | 491 | PUTC(c); |
kenjiArai | 0:d68f1e7f7f49 | 492 | } |
kenjiArai | 0:d68f1e7f7f49 | 493 | if (((uint8_t)c >= ' ') && (idx < len - 1)) { |
kenjiArai | 0:d68f1e7f7f49 | 494 | buff[idx++] = c; |
kenjiArai | 0:d68f1e7f7f49 | 495 | PUTC(c); |
kenjiArai | 0:d68f1e7f7f49 | 496 | } |
kenjiArai | 0:d68f1e7f7f49 | 497 | } |
kenjiArai | 0:d68f1e7f7f49 | 498 | buff[idx] = 0; |
kenjiArai | 0:d68f1e7f7f49 | 499 | PUTC('\n'); |
kenjiArai | 0:d68f1e7f7f49 | 500 | } |