Clock generator @ 145 MHz and 7 mhz

Dependencies:   Si5351A

Fork of Check_Si5351A_Clock_generator by Kenji Arai

Committer:
kenjiArai
Date:
Sun Jan 01 01:28:25 2017 +0000
Revision:
0:d68f1e7f7f49
Child:
1:2b29f68043f7
Si5351A function test program

Who changed what in which revision?

UserRevisionLine numberNew 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 #if defined(INCREMENT)
kenjiArai 0:d68f1e7f7f49 79 void test(uint8_t channel)
kenjiArai 0:d68f1e7f7f49 80 {
kenjiArai 0:d68f1e7f7f49 81 uint32_t f_set = 4000; // 4KHz
kenjiArai 0:d68f1e7f7f49 82 double f = 0;
kenjiArai 0:d68f1e7f7f49 83 uint32_t flg = 0;
kenjiArai 0:d68f1e7f7f49 84 clk.all_reset();
kenjiArai 0:d68f1e7f7f49 85 f = clk.set_frequency(channel, f_set);
kenjiArai 0:d68f1e7f7f49 86 clk.debug_reg_print();
kenjiArai 0:d68f1e7f7f49 87 PRINTF("CLK%u = %10.6f MHz\r\n", channel, f / 1000000.0f);
kenjiArai 0:d68f1e7f7f49 88 while(true){
kenjiArai 0:d68f1e7f7f49 89 f = clk.set_frequency(channel, f_set);
kenjiArai 0:d68f1e7f7f49 90 PRINTF("CLK%u = %10.6f MHz\r\n", channel, f / 1000000.0f);
kenjiArai 0:d68f1e7f7f49 91 if (flg){
kenjiArai 0:d68f1e7f7f49 92 f_set = f * 0.95f;
kenjiArai 0:d68f1e7f7f49 93 if (f_set < 5000){
kenjiArai 0:d68f1e7f7f49 94 flg = 0;
kenjiArai 0:d68f1e7f7f49 95 }
kenjiArai 0:d68f1e7f7f49 96 } else {
kenjiArai 0:d68f1e7f7f49 97 f_set = f * 1.05f;
kenjiArai 0:d68f1e7f7f49 98 if (f_set > 190000000){
kenjiArai 0:d68f1e7f7f49 99 flg = 1;
kenjiArai 0:d68f1e7f7f49 100 }
kenjiArai 0:d68f1e7f7f49 101 }
kenjiArai 0:d68f1e7f7f49 102 if (READABLE()) {
kenjiArai 0:d68f1e7f7f49 103 GETC();
kenjiArai 0:d68f1e7f7f49 104 return;
kenjiArai 0:d68f1e7f7f49 105 }
kenjiArai 0:d68f1e7f7f49 106 wait(1.0);
kenjiArai 0:d68f1e7f7f49 107 }
kenjiArai 0:d68f1e7f7f49 108 }
kenjiArai 0:d68f1e7f7f49 109 #endif
kenjiArai 0:d68f1e7f7f49 110
kenjiArai 0:d68f1e7f7f49 111 #if defined(TABLE_LOOK)
kenjiArai 0:d68f1e7f7f49 112 void test(uint8_t channel)
kenjiArai 0:d68f1e7f7f49 113 {
kenjiArai 0:d68f1e7f7f49 114 uint32_t f_set = 0;
kenjiArai 0:d68f1e7f7f49 115 uint32_t i,j;
kenjiArai 0:d68f1e7f7f49 116 double f = 0;
kenjiArai 0:d68f1e7f7f49 117 clk.all_reset();
kenjiArai 0:d68f1e7f7f49 118 while(true){
kenjiArai 0:d68f1e7f7f49 119 for (i = 0; ; i++){
kenjiArai 0:d68f1e7f7f49 120 f_set = freq_tbl[i];
kenjiArai 0:d68f1e7f7f49 121 if (f_set == 0){
kenjiArai 0:d68f1e7f7f49 122 break;
kenjiArai 0:d68f1e7f7f49 123 }
kenjiArai 0:d68f1e7f7f49 124 f = clk.set_frequency(channel, f_set);
kenjiArai 0:d68f1e7f7f49 125 PRINTF("CLK%u = %10.6f MHz\r\n", channel, f / 1000000.0f);
kenjiArai 0:d68f1e7f7f49 126 if (READABLE()) {
kenjiArai 0:d68f1e7f7f49 127 GETC();
kenjiArai 0:d68f1e7f7f49 128 return;
kenjiArai 0:d68f1e7f7f49 129 }
kenjiArai 0:d68f1e7f7f49 130 wait(1.0);
kenjiArai 0:d68f1e7f7f49 131 }
kenjiArai 0:d68f1e7f7f49 132 for (j = i - 2; j > 0 ; j--){
kenjiArai 0:d68f1e7f7f49 133 f_set = freq_tbl[j];
kenjiArai 0:d68f1e7f7f49 134 f = clk.set_frequency(channel, f_set);
kenjiArai 0:d68f1e7f7f49 135 PRINTF("CLK%u = %10.6f MHz\r\n", channel, f / 1000000.0f);
kenjiArai 0:d68f1e7f7f49 136 if (READABLE()) {
kenjiArai 0:d68f1e7f7f49 137 GETC();
kenjiArai 0:d68f1e7f7f49 138 return;
kenjiArai 0:d68f1e7f7f49 139 }
kenjiArai 0:d68f1e7f7f49 140 wait(1.0);
kenjiArai 0:d68f1e7f7f49 141 }
kenjiArai 0:d68f1e7f7f49 142 }
kenjiArai 0:d68f1e7f7f49 143 }
kenjiArai 0:d68f1e7f7f49 144 #endif
kenjiArai 0:d68f1e7f7f49 145
kenjiArai 0:d68f1e7f7f49 146 void special_command(void)
kenjiArai 0:d68f1e7f7f49 147 {
kenjiArai 0:d68f1e7f7f49 148 PRINTF("Not impliment yet");
kenjiArai 0:d68f1e7f7f49 149 put_rn();
kenjiArai 0:d68f1e7f7f49 150 }
kenjiArai 0:d68f1e7f7f49 151
kenjiArai 0:d68f1e7f7f49 152 // ---------- Program starts here! ---------------------------------------------
kenjiArai 0:d68f1e7f7f49 153 void test_si5351(void)
kenjiArai 0:d68f1e7f7f49 154 {
kenjiArai 0:d68f1e7f7f49 155 char *ptr;
kenjiArai 0:d68f1e7f7f49 156 int32_t f;
kenjiArai 0:d68f1e7f7f49 157
kenjiArai 0:d68f1e7f7f49 158 BAUD(BAUD_RATE);
kenjiArai 0:d68f1e7f7f49 159 put_rn();
kenjiArai 0:d68f1e7f7f49 160 put_rn();
kenjiArai 0:d68f1e7f7f49 161 PRINTF("%s [Help:'?' key]", opening_msg);
kenjiArai 0:d68f1e7f7f49 162 put_rn();
kenjiArai 0:d68f1e7f7f49 163 clk.all_reset();
kenjiArai 0:d68f1e7f7f49 164 for (;;) {
kenjiArai 0:d68f1e7f7f49 165 put_r();
kenjiArai 0:d68f1e7f7f49 166 PUTC('>');
kenjiArai 0:d68f1e7f7f49 167 ptr = linebuf;
kenjiArai 0:d68f1e7f7f49 168 get_line(ptr, sizeof(linebuf));
kenjiArai 0:d68f1e7f7f49 169 put_r();
kenjiArai 0:d68f1e7f7f49 170 switch (*ptr++) {
kenjiArai 0:d68f1e7f7f49 171 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 172 // test0
kenjiArai 0:d68f1e7f7f49 173 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 174 case '0' :
kenjiArai 0:d68f1e7f7f49 175 clk.all_reset();
kenjiArai 0:d68f1e7f7f49 176 test(0);
kenjiArai 0:d68f1e7f7f49 177 //put_rn();
kenjiArai 0:d68f1e7f7f49 178 break;
kenjiArai 0:d68f1e7f7f49 179 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 180 // test1
kenjiArai 0:d68f1e7f7f49 181 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 182 case '1' :
kenjiArai 0:d68f1e7f7f49 183 clk.all_reset();
kenjiArai 0:d68f1e7f7f49 184 test(1);
kenjiArai 0:d68f1e7f7f49 185 //put_rn();
kenjiArai 0:d68f1e7f7f49 186 break;
kenjiArai 0:d68f1e7f7f49 187 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 188 // test2
kenjiArai 0:d68f1e7f7f49 189 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 190 case '2' :
kenjiArai 0:d68f1e7f7f49 191 clk.all_reset();
kenjiArai 0:d68f1e7f7f49 192 test(2);
kenjiArai 0:d68f1e7f7f49 193 //put_rn();
kenjiArai 0:d68f1e7f7f49 194 break;
kenjiArai 0:d68f1e7f7f49 195 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 196 // test3
kenjiArai 0:d68f1e7f7f49 197 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 198 case '3' :
kenjiArai 0:d68f1e7f7f49 199 clk.debug_example_clock();
kenjiArai 0:d68f1e7f7f49 200 //clk.debug_reg_print();
kenjiArai 0:d68f1e7f7f49 201 //put_rn();
kenjiArai 0:d68f1e7f7f49 202 break;
kenjiArai 0:d68f1e7f7f49 203 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 204 // test4
kenjiArai 0:d68f1e7f7f49 205 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 206 case '4' :
kenjiArai 0:d68f1e7f7f49 207 clk.all_reset();
kenjiArai 0:d68f1e7f7f49 208 PRINTF("CLK0 %s", msg0);
kenjiArai 0:d68f1e7f7f49 209 put_rn();
kenjiArai 0:d68f1e7f7f49 210 ptr = linebuf;
kenjiArai 0:d68f1e7f7f49 211 get_line(ptr, buf_size);
kenjiArai 0:d68f1e7f7f49 212 put_r();
kenjiArai 0:d68f1e7f7f49 213 if (xatoi(&ptr,&f)){
kenjiArai 0:d68f1e7f7f49 214 if (f < 0){ break;}
kenjiArai 0:d68f1e7f7f49 215 PRINTF("CLK0:%u [Hz]", clk.set_frequency(0, f));
kenjiArai 0:d68f1e7f7f49 216 } else {
kenjiArai 0:d68f1e7f7f49 217 PUTC('?');
kenjiArai 0:d68f1e7f7f49 218 }
kenjiArai 0:d68f1e7f7f49 219 put_rn();
kenjiArai 0:d68f1e7f7f49 220 break;
kenjiArai 0:d68f1e7f7f49 221 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 222 // test5
kenjiArai 0:d68f1e7f7f49 223 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 224 case '5' :
kenjiArai 0:d68f1e7f7f49 225 clk.all_reset();
kenjiArai 0:d68f1e7f7f49 226 PRINTF("CLK0 %s", msg0);
kenjiArai 0:d68f1e7f7f49 227 put_rn();
kenjiArai 0:d68f1e7f7f49 228 ptr = linebuf;
kenjiArai 0:d68f1e7f7f49 229 get_line(ptr, buf_size);
kenjiArai 0:d68f1e7f7f49 230 put_r();
kenjiArai 0:d68f1e7f7f49 231 if (xatoi(&ptr,&f)){
kenjiArai 0:d68f1e7f7f49 232 if (f < 0){ break;}
kenjiArai 0:d68f1e7f7f49 233 PRINTF("CLK0:%u [Hz]", clk.set_frequency(0, f));
kenjiArai 0:d68f1e7f7f49 234 } else {
kenjiArai 0:d68f1e7f7f49 235 PUTC('?');
kenjiArai 0:d68f1e7f7f49 236 }
kenjiArai 0:d68f1e7f7f49 237 put_rn();
kenjiArai 0:d68f1e7f7f49 238 PRINTF("CLK1 %s", msg0);
kenjiArai 0:d68f1e7f7f49 239 put_rn();
kenjiArai 0:d68f1e7f7f49 240 ptr = linebuf;
kenjiArai 0:d68f1e7f7f49 241 get_line(ptr, buf_size);
kenjiArai 0:d68f1e7f7f49 242 put_r();
kenjiArai 0:d68f1e7f7f49 243 if (xatoi(&ptr,&f)){
kenjiArai 0:d68f1e7f7f49 244 if (f < 0){ break;}
kenjiArai 0:d68f1e7f7f49 245 PRINTF("CLK1:%u [Hz]", clk.set_frequency(1, f));
kenjiArai 0:d68f1e7f7f49 246 } else {
kenjiArai 0:d68f1e7f7f49 247 PUTC('?');
kenjiArai 0:d68f1e7f7f49 248 }
kenjiArai 0:d68f1e7f7f49 249 put_rn();
kenjiArai 0:d68f1e7f7f49 250 break;
kenjiArai 0:d68f1e7f7f49 251 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 252 // test6
kenjiArai 0:d68f1e7f7f49 253 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 254 case '6' :
kenjiArai 0:d68f1e7f7f49 255 clk.all_reset();
kenjiArai 0:d68f1e7f7f49 256 PRINTF("CLK0 %s", msg0);
kenjiArai 0:d68f1e7f7f49 257 put_rn();
kenjiArai 0:d68f1e7f7f49 258 ptr = linebuf;
kenjiArai 0:d68f1e7f7f49 259 get_line(ptr, buf_size);
kenjiArai 0:d68f1e7f7f49 260 put_r();
kenjiArai 0:d68f1e7f7f49 261 if (xatoi(&ptr,&f)){
kenjiArai 0:d68f1e7f7f49 262 if (f < 0){ break;}
kenjiArai 0:d68f1e7f7f49 263 PRINTF("CLK0:%u [Hz]", clk.set_frequency(0, f));
kenjiArai 0:d68f1e7f7f49 264 } else {
kenjiArai 0:d68f1e7f7f49 265 PUTC('?');
kenjiArai 0:d68f1e7f7f49 266 }
kenjiArai 0:d68f1e7f7f49 267 put_rn();
kenjiArai 0:d68f1e7f7f49 268 PRINTF("CLK1 %s", msg0);
kenjiArai 0:d68f1e7f7f49 269 put_rn();
kenjiArai 0:d68f1e7f7f49 270 PRINTF(
kenjiArai 0:d68f1e7f7f49 271 "If you set CLK1 over 100MHz, you cannt set CLK2 anymore");
kenjiArai 0:d68f1e7f7f49 272 put_rn();
kenjiArai 0:d68f1e7f7f49 273 ptr = linebuf;
kenjiArai 0:d68f1e7f7f49 274 get_line(ptr, buf_size);
kenjiArai 0:d68f1e7f7f49 275 put_r();
kenjiArai 0:d68f1e7f7f49 276 if (xatoi(&ptr,&f)){
kenjiArai 0:d68f1e7f7f49 277 if (f < 0){ break;}
kenjiArai 0:d68f1e7f7f49 278 PRINTF("CLK1:%u [Hz]", clk.set_frequency(1, f));
kenjiArai 0:d68f1e7f7f49 279 } else {
kenjiArai 0:d68f1e7f7f49 280 PUTC('?');
kenjiArai 0:d68f1e7f7f49 281 }
kenjiArai 0:d68f1e7f7f49 282 put_rn();
kenjiArai 0:d68f1e7f7f49 283 PRINTF("CLK2 %s", msg0);
kenjiArai 0:d68f1e7f7f49 284 put_rn();
kenjiArai 0:d68f1e7f7f49 285 ptr = linebuf;
kenjiArai 0:d68f1e7f7f49 286 get_line(ptr, buf_size);
kenjiArai 0:d68f1e7f7f49 287 put_r();
kenjiArai 0:d68f1e7f7f49 288 if (xatoi(&ptr,&f)){
kenjiArai 0:d68f1e7f7f49 289 if (f < 0){ break;}
kenjiArai 0:d68f1e7f7f49 290 PRINTF("CLK2:%u [Hz]", clk.set_frequency(2, f));
kenjiArai 0:d68f1e7f7f49 291 } else {
kenjiArai 0:d68f1e7f7f49 292 PUTC('?');
kenjiArai 0:d68f1e7f7f49 293 }
kenjiArai 0:d68f1e7f7f49 294 put_rn();
kenjiArai 0:d68f1e7f7f49 295 break;
kenjiArai 0:d68f1e7f7f49 296 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 297 // test7 CLK0: set desired center freq. then shift +/- range
kenjiArai 0:d68f1e7f7f49 298 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 299 case '7' :
kenjiArai 0:d68f1e7f7f49 300 clk.all_reset();
kenjiArai 0:d68f1e7f7f49 301 PRINTF("CLK0 %s", msg0);
kenjiArai 0:d68f1e7f7f49 302 put_rn();
kenjiArai 0:d68f1e7f7f49 303 ptr = linebuf;
kenjiArai 0:d68f1e7f7f49 304 get_line(ptr, buf_size);
kenjiArai 0:d68f1e7f7f49 305 put_r();
kenjiArai 0:d68f1e7f7f49 306 if (xatoi(&ptr,&f)){
kenjiArai 0:d68f1e7f7f49 307 if (f < 0){ break;}
kenjiArai 0:d68f1e7f7f49 308 PRINTF("CLK0:%u [Hz]", clk.set_frequency(0, f));
kenjiArai 0:d68f1e7f7f49 309 } else {
kenjiArai 0:d68f1e7f7f49 310 PUTC('?');
kenjiArai 0:d68f1e7f7f49 311 }
kenjiArai 0:d68f1e7f7f49 312 put_rn();
kenjiArai 0:d68f1e7f7f49 313 PRINTF("Please enter sift command [Help: ?]");
kenjiArai 0:d68f1e7f7f49 314 put_rn();
kenjiArai 0:d68f1e7f7f49 315 while (true){
kenjiArai 0:d68f1e7f7f49 316 PRINTF("[S]>");
kenjiArai 0:d68f1e7f7f49 317 ptr = linebuf;
kenjiArai 0:d68f1e7f7f49 318 get_line(ptr, buf_size);
kenjiArai 0:d68f1e7f7f49 319 put_r();
kenjiArai 0:d68f1e7f7f49 320 switch(*ptr) {
kenjiArai 0:d68f1e7f7f49 321 case 'p' :
kenjiArai 0:d68f1e7f7f49 322 PRINTF("Shift to %u [Hz]", clk.shift_freq(0, 10));
kenjiArai 0:d68f1e7f7f49 323 put_rn();
kenjiArai 0:d68f1e7f7f49 324 break;
kenjiArai 0:d68f1e7f7f49 325 case 'm' :
kenjiArai 0:d68f1e7f7f49 326 PRINTF("Shift to %u [Hz]", clk.shift_freq(0, -10));
kenjiArai 0:d68f1e7f7f49 327 put_rn();
kenjiArai 0:d68f1e7f7f49 328 break;
kenjiArai 0:d68f1e7f7f49 329 case 's' :
kenjiArai 0:d68f1e7f7f49 330 ptr++;
kenjiArai 0:d68f1e7f7f49 331 xatoi(&ptr,&f);
kenjiArai 0:d68f1e7f7f49 332 PRINTF("offset=%d\r\n", f);
kenjiArai 0:d68f1e7f7f49 333 PRINTF("Shift to %u [Hz]", clk.shift_freq(0, f));
kenjiArai 0:d68f1e7f7f49 334 put_rn();
kenjiArai 0:d68f1e7f7f49 335 break;
kenjiArai 0:d68f1e7f7f49 336 case '?' :
kenjiArai 0:d68f1e7f7f49 337 PRINTF("p -> +10Hz");
kenjiArai 0:d68f1e7f7f49 338 put_rn();
kenjiArai 0:d68f1e7f7f49 339 PRINTF("m -> -10Hz");
kenjiArai 0:d68f1e7f7f49 340 put_rn();
kenjiArai 0:d68f1e7f7f49 341 PRINTF("s -> Shift +/-x Hz (example -100)");
kenjiArai 0:d68f1e7f7f49 342 put_rn();
kenjiArai 0:d68f1e7f7f49 343 PRINTF("? -> You know this");
kenjiArai 0:d68f1e7f7f49 344 put_rn();
kenjiArai 0:d68f1e7f7f49 345 PRINTF("e -> Exit");
kenjiArai 0:d68f1e7f7f49 346 put_rn();
kenjiArai 0:d68f1e7f7f49 347 break;
kenjiArai 0:d68f1e7f7f49 348 case 'e' :
kenjiArai 0:d68f1e7f7f49 349 break;
kenjiArai 0:d68f1e7f7f49 350 default:
kenjiArai 0:d68f1e7f7f49 351 PUTC('?');
kenjiArai 0:d68f1e7f7f49 352 put_rn();
kenjiArai 0:d68f1e7f7f49 353 }
kenjiArai 0:d68f1e7f7f49 354 if (*ptr == 'e'){
kenjiArai 0:d68f1e7f7f49 355 break;
kenjiArai 0:d68f1e7f7f49 356 }
kenjiArai 0:d68f1e7f7f49 357 }
kenjiArai 0:d68f1e7f7f49 358 break;
kenjiArai 0:d68f1e7f7f49 359 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 360 // All clear alll registers
kenjiArai 0:d68f1e7f7f49 361 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 362 case 'a' :
kenjiArai 0:d68f1e7f7f49 363 clk.all_reset();
kenjiArai 0:d68f1e7f7f49 364 PRINTF("Cleared all of registers!\r\n");
kenjiArai 0:d68f1e7f7f49 365 break;
kenjiArai 0:d68f1e7f7f49 366 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 367 // Show configration
kenjiArai 0:d68f1e7f7f49 368 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 369 case 'c' :
kenjiArai 0:d68f1e7f7f49 370 clk.debug_current_config();
kenjiArai 0:d68f1e7f7f49 371 //put_rn();
kenjiArai 0:d68f1e7f7f49 372 break;
kenjiArai 0:d68f1e7f7f49 373 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 374 // Show resisters
kenjiArai 0:d68f1e7f7f49 375 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 376 case 'r' :
kenjiArai 0:d68f1e7f7f49 377 clk.debug_reg_print();
kenjiArai 0:d68f1e7f7f49 378 //put_rn();
kenjiArai 0:d68f1e7f7f49 379 break;
kenjiArai 0:d68f1e7f7f49 380 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 381 // Go to special command
kenjiArai 0:d68f1e7f7f49 382 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 383 case 'x' :
kenjiArai 0:d68f1e7f7f49 384 special_command();
kenjiArai 0:d68f1e7f7f49 385 break;
kenjiArai 0:d68f1e7f7f49 386 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 387 // help
kenjiArai 0:d68f1e7f7f49 388 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 389 case '?' :
kenjiArai 0:d68f1e7f7f49 390 msg_hlp();
kenjiArai 0:d68f1e7f7f49 391 break;
kenjiArai 0:d68f1e7f7f49 392 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 393 // no support
kenjiArai 0:d68f1e7f7f49 394 //--------------------------------------------------------------
kenjiArai 0:d68f1e7f7f49 395 default:
kenjiArai 0:d68f1e7f7f49 396 PUTC('?');
kenjiArai 0:d68f1e7f7f49 397 put_rn();
kenjiArai 0:d68f1e7f7f49 398 break;
kenjiArai 0:d68f1e7f7f49 399 }
kenjiArai 0:d68f1e7f7f49 400 }
kenjiArai 0:d68f1e7f7f49 401 }
kenjiArai 0:d68f1e7f7f49 402
kenjiArai 0:d68f1e7f7f49 403 // Put \r\n
kenjiArai 0:d68f1e7f7f49 404 void put_rn ( void )
kenjiArai 0:d68f1e7f7f49 405 {
kenjiArai 0:d68f1e7f7f49 406 PUTC('\r');
kenjiArai 0:d68f1e7f7f49 407 PUTC('\n');
kenjiArai 0:d68f1e7f7f49 408 }
kenjiArai 0:d68f1e7f7f49 409
kenjiArai 0:d68f1e7f7f49 410 // Put \r
kenjiArai 0:d68f1e7f7f49 411 void put_r ( void )
kenjiArai 0:d68f1e7f7f49 412 {
kenjiArai 0:d68f1e7f7f49 413 PUTC('\r');
kenjiArai 0:d68f1e7f7f49 414 }
kenjiArai 0:d68f1e7f7f49 415
kenjiArai 0:d68f1e7f7f49 416 // Change string -> integer
kenjiArai 0:d68f1e7f7f49 417 int xatoi (char **str, int32_t *res)
kenjiArai 0:d68f1e7f7f49 418 {
kenjiArai 0:d68f1e7f7f49 419 uint32_t val;
kenjiArai 0:d68f1e7f7f49 420 int8_t c, radix, s = 0;
kenjiArai 0:d68f1e7f7f49 421
kenjiArai 0:d68f1e7f7f49 422 while ((c = **str) == ' ') (*str)++;
kenjiArai 0:d68f1e7f7f49 423 if (c == '-') {
kenjiArai 0:d68f1e7f7f49 424 s = 1;
kenjiArai 0:d68f1e7f7f49 425 c = *(++(*str));
kenjiArai 0:d68f1e7f7f49 426 }
kenjiArai 0:d68f1e7f7f49 427 if (c == '+') {
kenjiArai 0:d68f1e7f7f49 428 c = *(++(*str));
kenjiArai 0:d68f1e7f7f49 429 }
kenjiArai 0:d68f1e7f7f49 430 if (c == '0') {
kenjiArai 0:d68f1e7f7f49 431 c = *(++(*str));
kenjiArai 0:d68f1e7f7f49 432 if (c <= ' ') {
kenjiArai 0:d68f1e7f7f49 433 *res = 0;
kenjiArai 0:d68f1e7f7f49 434 return 1;
kenjiArai 0:d68f1e7f7f49 435 }
kenjiArai 0:d68f1e7f7f49 436 if (c == 'x') {
kenjiArai 0:d68f1e7f7f49 437 radix = 16;
kenjiArai 0:d68f1e7f7f49 438 c = *(++(*str));
kenjiArai 0:d68f1e7f7f49 439 } else {
kenjiArai 0:d68f1e7f7f49 440 if (c == 'b') {
kenjiArai 0:d68f1e7f7f49 441 radix = 2;
kenjiArai 0:d68f1e7f7f49 442 c = *(++(*str));
kenjiArai 0:d68f1e7f7f49 443 } else {
kenjiArai 0:d68f1e7f7f49 444 if ((c >= '0')&&(c <= '9')) {
kenjiArai 0:d68f1e7f7f49 445 radix = 8;
kenjiArai 0:d68f1e7f7f49 446 } else {
kenjiArai 0:d68f1e7f7f49 447 return 0;
kenjiArai 0:d68f1e7f7f49 448 }
kenjiArai 0:d68f1e7f7f49 449 }
kenjiArai 0:d68f1e7f7f49 450 }
kenjiArai 0:d68f1e7f7f49 451 } else {
kenjiArai 0:d68f1e7f7f49 452 if ((c < '1')||(c > '9')) {
kenjiArai 0:d68f1e7f7f49 453 return 0;
kenjiArai 0:d68f1e7f7f49 454 }
kenjiArai 0:d68f1e7f7f49 455 radix = 10;
kenjiArai 0:d68f1e7f7f49 456 }
kenjiArai 0:d68f1e7f7f49 457 val = 0;
kenjiArai 0:d68f1e7f7f49 458 while (c > ' ') {
kenjiArai 0:d68f1e7f7f49 459 if (c >= 'a') c -= 0x20;
kenjiArai 0:d68f1e7f7f49 460 c -= '0';
kenjiArai 0:d68f1e7f7f49 461 if (c >= 17) {
kenjiArai 0:d68f1e7f7f49 462 c -= 7;
kenjiArai 0:d68f1e7f7f49 463 if (c <= 9) return 0;
kenjiArai 0:d68f1e7f7f49 464 }
kenjiArai 0:d68f1e7f7f49 465 if (c >= radix) return 0;
kenjiArai 0:d68f1e7f7f49 466 val = val * radix + c;
kenjiArai 0:d68f1e7f7f49 467 c = *(++(*str));
kenjiArai 0:d68f1e7f7f49 468 }
kenjiArai 0:d68f1e7f7f49 469 if (s) val = -val;
kenjiArai 0:d68f1e7f7f49 470 *res = val;
kenjiArai 0:d68f1e7f7f49 471 return 1;
kenjiArai 0:d68f1e7f7f49 472 }
kenjiArai 0:d68f1e7f7f49 473
kenjiArai 0:d68f1e7f7f49 474 #if 0
kenjiArai 0:d68f1e7f7f49 475 int xatoi ( /* 0:Failed, 1:Successful */
kenjiArai 0:d68f1e7f7f49 476 char **str, /* Pointer to pointer to the string */
kenjiArai 0:d68f1e7f7f49 477 long *res /* Pointer to the valiable to store the value */
kenjiArai 0:d68f1e7f7f49 478 )
kenjiArai 0:d68f1e7f7f49 479 {
kenjiArai 0:d68f1e7f7f49 480 unsigned long val;
kenjiArai 0:d68f1e7f7f49 481 unsigned char c, r, s = 0;
kenjiArai 0:d68f1e7f7f49 482
kenjiArai 0:d68f1e7f7f49 483
kenjiArai 0:d68f1e7f7f49 484 *res = 0;
kenjiArai 0:d68f1e7f7f49 485
kenjiArai 0:d68f1e7f7f49 486 while ((c = **str) == ' ') (*str)++; /* Skip leading spaces */
kenjiArai 0:d68f1e7f7f49 487
kenjiArai 0:d68f1e7f7f49 488 if (c == '-') { /* negative? */
kenjiArai 0:d68f1e7f7f49 489 s = 1;
kenjiArai 0:d68f1e7f7f49 490 c = *(++(*str));
kenjiArai 0:d68f1e7f7f49 491 }
kenjiArai 0:d68f1e7f7f49 492
kenjiArai 0:d68f1e7f7f49 493 if (c == '0') {
kenjiArai 0:d68f1e7f7f49 494 c = *(++(*str));
kenjiArai 0:d68f1e7f7f49 495 switch (c) {
kenjiArai 0:d68f1e7f7f49 496 case 'x': /* hexdecimal */
kenjiArai 0:d68f1e7f7f49 497 r = 16; c = *(++(*str));
kenjiArai 0:d68f1e7f7f49 498 break;
kenjiArai 0:d68f1e7f7f49 499 case 'b': /* binary */
kenjiArai 0:d68f1e7f7f49 500 r = 2; c = *(++(*str));
kenjiArai 0:d68f1e7f7f49 501 break;
kenjiArai 0:d68f1e7f7f49 502 default:
kenjiArai 0:d68f1e7f7f49 503 if (c <= ' ') return 1; /* single zero */
kenjiArai 0:d68f1e7f7f49 504 if (c < '0' || c > '9') return 0; /* invalid char */
kenjiArai 0:d68f1e7f7f49 505 r = 8; /* octal */
kenjiArai 0:d68f1e7f7f49 506 }
kenjiArai 0:d68f1e7f7f49 507 } else {
kenjiArai 0:d68f1e7f7f49 508 if (c < '0' || c > '9') return 0; /* EOL or invalid char */
kenjiArai 0:d68f1e7f7f49 509 r = 10; /* decimal */
kenjiArai 0:d68f1e7f7f49 510 }
kenjiArai 0:d68f1e7f7f49 511
kenjiArai 0:d68f1e7f7f49 512 val = 0;
kenjiArai 0:d68f1e7f7f49 513 while (c > ' ') {
kenjiArai 0:d68f1e7f7f49 514 if (c >= 'a') c -= 0x20;
kenjiArai 0:d68f1e7f7f49 515 c -= '0';
kenjiArai 0:d68f1e7f7f49 516 if (c >= 17) {
kenjiArai 0:d68f1e7f7f49 517 c -= 7;
kenjiArai 0:d68f1e7f7f49 518 if (c <= 9) return 0; /* invalid char */
kenjiArai 0:d68f1e7f7f49 519 }
kenjiArai 0:d68f1e7f7f49 520 if (c >= r) return 0; /* invalid char for current radix */
kenjiArai 0:d68f1e7f7f49 521 val = val * r + c;
kenjiArai 0:d68f1e7f7f49 522 c = *(++(*str));
kenjiArai 0:d68f1e7f7f49 523 }
kenjiArai 0:d68f1e7f7f49 524 if (s) val = 0 - val; /* apply sign if needed */
kenjiArai 0:d68f1e7f7f49 525
kenjiArai 0:d68f1e7f7f49 526 *res = val;
kenjiArai 0:d68f1e7f7f49 527 return 1;
kenjiArai 0:d68f1e7f7f49 528 }
kenjiArai 0:d68f1e7f7f49 529 #endif
kenjiArai 0:d68f1e7f7f49 530
kenjiArai 0:d68f1e7f7f49 531 // Get key input data
kenjiArai 0:d68f1e7f7f49 532 void get_line (char *buff, int len)
kenjiArai 0:d68f1e7f7f49 533 {
kenjiArai 0:d68f1e7f7f49 534 char c;
kenjiArai 0:d68f1e7f7f49 535 int idx = 0;
kenjiArai 0:d68f1e7f7f49 536
kenjiArai 0:d68f1e7f7f49 537 for (;;) {
kenjiArai 0:d68f1e7f7f49 538 c = GETC();
kenjiArai 0:d68f1e7f7f49 539 if (c == '\r') {
kenjiArai 0:d68f1e7f7f49 540 buff[idx++] = c;
kenjiArai 0:d68f1e7f7f49 541 break;
kenjiArai 0:d68f1e7f7f49 542 }
kenjiArai 0:d68f1e7f7f49 543 if ((c == '\b') && idx) {
kenjiArai 0:d68f1e7f7f49 544 idx--;
kenjiArai 0:d68f1e7f7f49 545 PUTC(c);
kenjiArai 0:d68f1e7f7f49 546 PUTC(' ');
kenjiArai 0:d68f1e7f7f49 547 PUTC(c);
kenjiArai 0:d68f1e7f7f49 548 }
kenjiArai 0:d68f1e7f7f49 549 if (((uint8_t)c >= ' ') && (idx < len - 1)) {
kenjiArai 0:d68f1e7f7f49 550 buff[idx++] = c;
kenjiArai 0:d68f1e7f7f49 551 PUTC(c);
kenjiArai 0:d68f1e7f7f49 552 }
kenjiArai 0:d68f1e7f7f49 553 }
kenjiArai 0:d68f1e7f7f49 554 buff[idx] = 0;
kenjiArai 0:d68f1e7f7f49 555 PUTC('\n');
kenjiArai 0:d68f1e7f7f49 556 }