![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
06/21/18
Fork of rtos_threading_with_callback by
EasyFuse_Prog.cpp@4:61f1412310af, 2020-04-02 (annotated)
- Committer:
- CactusSemi
- Date:
- Thu Apr 02 17:44:59 2020 +0000
- Revision:
- 4:61f1412310af
- Parent:
- 3:3e8c16b6620c
Jacaranda Final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CactusSemi | 3:3e8c16b6620c | 1 | #include "mbed.h" |
CactusSemi | 3:3e8c16b6620c | 2 | |
CactusSemi | 3:3e8c16b6620c | 3 | extern Serial pc; |
CactusSemi | 3:3e8c16b6620c | 4 | extern int frequ; //unit kHz |
CactusSemi | 3:3e8c16b6620c | 5 | extern char dev_addr; //fixed |
CactusSemi | 3:3e8c16b6620c | 6 | |
CactusSemi | 3:3e8c16b6620c | 7 | char get_half_byte(int *); //defined in I2C_read.cpp |
CactusSemi | 3:3e8c16b6620c | 8 | |
CactusSemi | 3:3e8c16b6620c | 9 | |
CactusSemi | 3:3e8c16b6620c | 10 | char get_byte(int *flag) { |
CactusSemi | 3:3e8c16b6620c | 11 | char cur_char; |
CactusSemi | 3:3e8c16b6620c | 12 | char temp; |
CactusSemi | 3:3e8c16b6620c | 13 | int flag1 = 0; |
CactusSemi | 3:3e8c16b6620c | 14 | cur_char = get_half_byte(&flag1); |
CactusSemi | 3:3e8c16b6620c | 15 | if (flag1 == 1) { |
CactusSemi | 3:3e8c16b6620c | 16 | cur_char = cur_char << 4; |
CactusSemi | 3:3e8c16b6620c | 17 | temp = get_half_byte(&flag1); |
CactusSemi | 3:3e8c16b6620c | 18 | cur_char = (cur_char | temp); |
CactusSemi | 3:3e8c16b6620c | 19 | } |
CactusSemi | 3:3e8c16b6620c | 20 | *flag = flag1; |
CactusSemi | 3:3e8c16b6620c | 21 | return cur_char; |
CactusSemi | 3:3e8c16b6620c | 22 | } |
CactusSemi | 3:3e8c16b6620c | 23 | |
CactusSemi | 3:3e8c16b6620c | 24 | void print_nvm_reg(uint8_t *max_Vout, uint8_t *max_Vout_trim, uint8_t *high_time, uint8_t *low_time, uint8_t *adc_samp_rate, |
CactusSemi | 3:3e8c16b6620c | 25 | uint8_t *adc_range, uint8_t *adc_time_out, uint8_t *comp_offset, uint8_t *range_trim, uint8_t *PMOS_off, uint8_t *Driver2, uint8_t *Driver3, |
CactusSemi | 3:3e8c16b6620c | 26 | uint8_t *DMOS, uint8_t *CCM_threshold, uint8_t *DMOS_ctrl_trim, uint8_t *adc_op_mode) { |
CactusSemi | 3:3e8c16b6620c | 27 | |
CactusSemi | 3:3e8c16b6620c | 28 | pc.printf("\033[%dm ", 35);//change text color to red |
CactusSemi | 3:3e8c16b6620c | 29 | pc.printf("\n\n\n\r\t Register contents :\n\r\t "); |
CactusSemi | 3:3e8c16b6620c | 30 | for ( int i = 0; i<26; i++) pc.printf("\304"); |
CactusSemi | 3:3e8c16b6620c | 31 | pc.printf("\n\n\r\t 1. max_Vout = 0x%2.2X",*max_Vout); |
CactusSemi | 3:3e8c16b6620c | 32 | pc.printf("\n\n\r\t 2. max_Vout_trim = 0x%2.2X",*max_Vout_trim); |
CactusSemi | 3:3e8c16b6620c | 33 | pc.printf("\n\n\r\t 3. high_time = 0x%2.2X",*high_time); |
CactusSemi | 3:3e8c16b6620c | 34 | pc.printf("\n\n\r\t 4. low_time = 0x%2.2X",*low_time); |
CactusSemi | 3:3e8c16b6620c | 35 | pc.printf("\n\n\r\t 5. adc_samp_rate = 0x%2.2X",*adc_samp_rate); |
CactusSemi | 3:3e8c16b6620c | 36 | pc.printf("\n\n\r\t 6. adc_range = 0x%2.2X",*adc_range); |
CactusSemi | 3:3e8c16b6620c | 37 | pc.printf("\n\n\r\t 7. adc_time_out = 0x%2.2X",*adc_time_out); |
CactusSemi | 3:3e8c16b6620c | 38 | pc.printf("\n\n\r\t 8. comp_offset = 0x%2.2X",*comp_offset); |
CactusSemi | 3:3e8c16b6620c | 39 | pc.printf("\n\n\r\t 9. range_trim = 0x%2.2X",*range_trim); |
CactusSemi | 3:3e8c16b6620c | 40 | pc.printf("\n\n\r\t 10. PMOS_off = 0x%2.2X",*PMOS_off); |
CactusSemi | 3:3e8c16b6620c | 41 | pc.printf("\n\n\r\t 11. Driver2 = 0x%2.2X",*Driver2); |
CactusSemi | 3:3e8c16b6620c | 42 | pc.printf("\n\n\r\t 12. Driver3 = 0x%2.2X",*Driver3); |
CactusSemi | 3:3e8c16b6620c | 43 | pc.printf("\n\n\r\t 13. DMOS = 0x%2.2X",*DMOS); |
CactusSemi | 3:3e8c16b6620c | 44 | pc.printf("\n\n\r\t 14. CCM_threshold = 0x%2.2X",*CCM_threshold); |
CactusSemi | 3:3e8c16b6620c | 45 | pc.printf("\n\n\r\t 15. DMOS_ctrl_trim = 0x%2.2X",*DMOS_ctrl_trim); |
CactusSemi | 3:3e8c16b6620c | 46 | pc.printf("\n\n\r\t 16. adc_op_mode = 0x%2.2X",*adc_op_mode); |
CactusSemi | 3:3e8c16b6620c | 47 | pc.printf("\n\n\r\t "); |
CactusSemi | 3:3e8c16b6620c | 48 | for ( int i = 0; i<26; i++) pc.printf("\315"); |
CactusSemi | 3:3e8c16b6620c | 49 | pc.printf("\033[%dm", 32);//change text color to green |
CactusSemi | 3:3e8c16b6620c | 50 | pc.printf("\n\r"); |
CactusSemi | 3:3e8c16b6620c | 51 | } |
CactusSemi | 3:3e8c16b6620c | 52 | |
CactusSemi | 3:3e8c16b6620c | 53 | void edit_nvm_reg(uint8_t *max_Vout, uint8_t *max_Vout_trim, uint8_t *high_time, uint8_t *low_time, uint8_t *adc_samp_rate, |
CactusSemi | 3:3e8c16b6620c | 54 | uint8_t *adc_range, uint8_t *adc_time_out, uint8_t *comp_offset, uint8_t *range_trim, uint8_t *PMOS_off, uint8_t *Driver2, uint8_t *Driver3, |
CactusSemi | 3:3e8c16b6620c | 55 | uint8_t *DMOS, uint8_t *CCM_threshold, uint8_t *DMOS_ctrl_trim, uint8_t *adc_op_mode) { |
CactusSemi | 3:3e8c16b6620c | 56 | |
CactusSemi | 3:3e8c16b6620c | 57 | char temp; |
CactusSemi | 3:3e8c16b6620c | 58 | int flag1; |
CactusSemi | 3:3e8c16b6620c | 59 | char count; |
CactusSemi | 3:3e8c16b6620c | 60 | char reg_data; |
CactusSemi | 3:3e8c16b6620c | 61 | |
CactusSemi | 3:3e8c16b6620c | 62 | char reg_name[16][15] = {"max_Vout", "max_Vout_trim", "high_time", "low_time", "adc_samp_rate", |
CactusSemi | 3:3e8c16b6620c | 63 | "adc_range", "adc_time_out", "comp_offset", "range_trim", "PMOS_off", "Driver2", "Driver3", |
CactusSemi | 3:3e8c16b6620c | 64 | "DMOS", "CCM_threshold", "DMOS_ctrl_trim", "adc_op_mode" }; |
CactusSemi | 3:3e8c16b6620c | 65 | |
CactusSemi | 3:3e8c16b6620c | 66 | uint8_t *reg_addr[16] = { max_Vout, max_Vout_trim, high_time, low_time, adc_samp_rate, |
CactusSemi | 3:3e8c16b6620c | 67 | adc_range, adc_time_out, comp_offset, range_trim, PMOS_off, Driver2, Driver3, |
CactusSemi | 3:3e8c16b6620c | 68 | DMOS, CCM_threshold, DMOS_ctrl_trim, adc_op_mode}; |
CactusSemi | 3:3e8c16b6620c | 69 | |
CactusSemi | 3:3e8c16b6620c | 70 | pc.printf("\n\n\n \r\tDo you want to edit the registers? (y/n) : "); |
CactusSemi | 3:3e8c16b6620c | 71 | temp = 0; |
CactusSemi | 3:3e8c16b6620c | 72 | while ( temp!='y' && temp!='n') { |
CactusSemi | 3:3e8c16b6620c | 73 | temp = pc.getc(); |
CactusSemi | 3:3e8c16b6620c | 74 | } |
CactusSemi | 3:3e8c16b6620c | 75 | if (temp == 'n') { |
CactusSemi | 3:3e8c16b6620c | 76 | pc.printf("\n\n \r\tContinue with above contents"); |
CactusSemi | 3:3e8c16b6620c | 77 | return; |
CactusSemi | 3:3e8c16b6620c | 78 | } |
CactusSemi | 3:3e8c16b6620c | 79 | temp = 'y'; |
CactusSemi | 3:3e8c16b6620c | 80 | while (temp =='y') { |
CactusSemi | 3:3e8c16b6620c | 81 | //get selection |
CactusSemi | 3:3e8c16b6620c | 82 | flag1 = 0; |
CactusSemi | 3:3e8c16b6620c | 83 | while (!flag1) { |
CactusSemi | 3:3e8c16b6620c | 84 | pc.printf("\n\n\n\r\tEnter (1 - 16) to select the register to edit and hit 'enter' key: "); |
CactusSemi | 3:3e8c16b6620c | 85 | temp = '0'; |
CactusSemi | 3:3e8c16b6620c | 86 | count = 0; |
CactusSemi | 3:3e8c16b6620c | 87 | while (temp != '\r') { //look for enter key |
CactusSemi | 3:3e8c16b6620c | 88 | count = (count * 10) + (temp - '0'); // converting to number |
CactusSemi | 3:3e8c16b6620c | 89 | temp = pc.getc(); |
CactusSemi | 3:3e8c16b6620c | 90 | if ((temp < '0' || temp > '9') && temp !='\r') { |
CactusSemi | 3:3e8c16b6620c | 91 | pc.printf(" \n\r\t\033[%dm Invalid Chracter!! No worries, let us try again \033[%dm",41,40); |
CactusSemi | 3:3e8c16b6620c | 92 | break; |
CactusSemi | 3:3e8c16b6620c | 93 | } |
CactusSemi | 3:3e8c16b6620c | 94 | } |
CactusSemi | 3:3e8c16b6620c | 95 | if (count >= 1 && count <= 16 && temp == '\r') flag1 = 1; |
CactusSemi | 3:3e8c16b6620c | 96 | else if (temp == '\r') pc.printf(" \n\r\t\033[%dm Invalid Chracter!! No worries, let us try again \033[%dm",41,40); |
CactusSemi | 3:3e8c16b6620c | 97 | } |
CactusSemi | 3:3e8c16b6620c | 98 | count = count - 1; //array starts from 0 |
CactusSemi | 3:3e8c16b6620c | 99 | //Read New Register Data |
CactusSemi | 3:3e8c16b6620c | 100 | flag1 = 0; |
CactusSemi | 3:3e8c16b6620c | 101 | while (!flag1) { |
CactusSemi | 3:3e8c16b6620c | 102 | pc.printf("\n\n \r\tEnter new value in hex (00 to ff) for \033[%dm %s \033[%dm register : ",35,reg_name[count],32); |
CactusSemi | 3:3e8c16b6620c | 103 | reg_data = get_half_byte(&flag1); |
CactusSemi | 3:3e8c16b6620c | 104 | if (flag1 == 1) { |
CactusSemi | 3:3e8c16b6620c | 105 | reg_data = reg_data << 4; |
CactusSemi | 3:3e8c16b6620c | 106 | temp = get_half_byte(&flag1); |
CactusSemi | 3:3e8c16b6620c | 107 | reg_data = (reg_data | temp); |
CactusSemi | 3:3e8c16b6620c | 108 | } |
CactusSemi | 3:3e8c16b6620c | 109 | if (flag1==0) pc.printf(" \033[%dm Invalid Chracter!! No worries, let us try again \033[%dm",41,40); |
CactusSemi | 3:3e8c16b6620c | 110 | } |
CactusSemi | 3:3e8c16b6620c | 111 | *(reg_addr[count]) = reg_data; |
CactusSemi | 3:3e8c16b6620c | 112 | |
CactusSemi | 3:3e8c16b6620c | 113 | print_nvm_reg( max_Vout, max_Vout_trim, high_time, low_time, adc_samp_rate, |
CactusSemi | 3:3e8c16b6620c | 114 | adc_range, adc_time_out, comp_offset, range_trim, PMOS_off, Driver2, Driver3, |
CactusSemi | 3:3e8c16b6620c | 115 | DMOS, CCM_threshold, DMOS_ctrl_trim, adc_op_mode); |
CactusSemi | 3:3e8c16b6620c | 116 | |
CactusSemi | 3:3e8c16b6620c | 117 | pc.printf("\n\n \r\tDo you want to make more changes? (y/n) : "); |
CactusSemi | 3:3e8c16b6620c | 118 | temp = pc.getc(); |
CactusSemi | 3:3e8c16b6620c | 119 | } //end of edit while loop |
CactusSemi | 3:3e8c16b6620c | 120 | } |
CactusSemi | 3:3e8c16b6620c | 121 | |
CactusSemi | 3:3e8c16b6620c | 122 | void i2c_write_fn(I2C *i2c_obj, char ptr, char write_data) { |
CactusSemi | 3:3e8c16b6620c | 123 | int flag1; |
CactusSemi | 4:61f1412310af | 124 | wait_us(20); |
CactusSemi | 3:3e8c16b6620c | 125 | (*i2c_obj).start(); |
CactusSemi | 3:3e8c16b6620c | 126 | flag1 = (*i2c_obj).write(dev_addr); |
CactusSemi | 3:3e8c16b6620c | 127 | if (flag1 != 1) pc.printf("\n\n\r\tNo Ack for dev addr :("); |
CactusSemi | 3:3e8c16b6620c | 128 | flag1 = (*i2c_obj).write(ptr); |
CactusSemi | 3:3e8c16b6620c | 129 | if (flag1 != 1) pc.printf("\n\n\r\tNo Ack reg pointer :("); |
CactusSemi | 3:3e8c16b6620c | 130 | flag1 = (*i2c_obj).write(write_data); |
CactusSemi | 3:3e8c16b6620c | 131 | if (flag1 != 1) pc.printf("\n\n\r\tNo Ack data :("); |
CactusSemi | 4:61f1412310af | 132 | wait_us(20); |
CactusSemi | 3:3e8c16b6620c | 133 | (*i2c_obj).stop(); |
CactusSemi | 3:3e8c16b6620c | 134 | } |
CactusSemi | 3:3e8c16b6620c | 135 | |
CactusSemi | 3:3e8c16b6620c | 136 | char i2c_read_fn(I2C *i2c_obj, char ptr) { |
CactusSemi | 3:3e8c16b6620c | 137 | int flag1; |
CactusSemi | 3:3e8c16b6620c | 138 | char read_data; |
CactusSemi | 3:3e8c16b6620c | 139 | wait_us(10); |
CactusSemi | 3:3e8c16b6620c | 140 | (*i2c_obj).start(); |
CactusSemi | 3:3e8c16b6620c | 141 | flag1 = (*i2c_obj).write(dev_addr); |
CactusSemi | 3:3e8c16b6620c | 142 | if (flag1 != 1) pc.printf("\n\n\n\r\tNo Ack for dev addr :("); |
CactusSemi | 3:3e8c16b6620c | 143 | flag1 = (*i2c_obj).write(ptr); |
CactusSemi | 3:3e8c16b6620c | 144 | if (flag1 != 1) pc.printf("\n\n\r\tNo Ack reg pointer :("); |
CactusSemi | 3:3e8c16b6620c | 145 | (*i2c_obj).stop(); |
CactusSemi | 3:3e8c16b6620c | 146 | wait_us(10); |
CactusSemi | 3:3e8c16b6620c | 147 | (*i2c_obj).start(); |
CactusSemi | 3:3e8c16b6620c | 148 | flag1 = (*i2c_obj).write(dev_addr | 0x01); //lsb 1 for read |
CactusSemi | 3:3e8c16b6620c | 149 | if (flag1 != 1) pc.printf("\n\n\r\tNo Ack for dev addr :("); |
CactusSemi | 3:3e8c16b6620c | 150 | read_data = (*i2c_obj).read(0); //0- donot send ack after read is done |
CactusSemi | 3:3e8c16b6620c | 151 | wait_us(5); |
CactusSemi | 3:3e8c16b6620c | 152 | (*i2c_obj).stop(); |
CactusSemi | 3:3e8c16b6620c | 153 | wait_us(120); |
CactusSemi | 3:3e8c16b6620c | 154 | return read_data; |
CactusSemi | 3:3e8c16b6620c | 155 | } |
CactusSemi | 3:3e8c16b6620c | 156 | |
CactusSemi | 3:3e8c16b6620c | 157 | uint64_t EasyFuse_read(I2C *i2c_obj) { |
CactusSemi | 3:3e8c16b6620c | 158 | char reg_ptr = 0x00; |
CactusSemi | 3:3e8c16b6620c | 159 | char reg_data[10]; |
CactusSemi | 3:3e8c16b6620c | 160 | char data; |
CactusSemi | 4:61f1412310af | 161 | uint8_t NVM_PWR_ON = 0x20 ; |
CactusSemi | 4:61f1412310af | 162 | uint8_t NVM_READ = 0x90 ; |
CactusSemi | 3:3e8c16b6620c | 163 | uint8_t NVM_CTLR_ADR = 0x0a ; //Register address for NVM CTRL |
CactusSemi | 3:3e8c16b6620c | 164 | uint64_t NVM_data = 0x0000000000000000; |
CactusSemi | 3:3e8c16b6620c | 165 | |
CactusSemi | 3:3e8c16b6620c | 166 | //Variables to store read data |
CactusSemi | 3:3e8c16b6620c | 167 | uint8_t max_Vout; |
CactusSemi | 3:3e8c16b6620c | 168 | uint8_t max_Vout_trim; |
CactusSemi | 3:3e8c16b6620c | 169 | uint8_t high_time; |
CactusSemi | 3:3e8c16b6620c | 170 | uint8_t low_time; |
CactusSemi | 3:3e8c16b6620c | 171 | uint8_t adc_samp_rate; |
CactusSemi | 3:3e8c16b6620c | 172 | uint8_t adc_range; |
CactusSemi | 3:3e8c16b6620c | 173 | uint8_t adc_time_out; |
CactusSemi | 3:3e8c16b6620c | 174 | uint8_t comp_offset; |
CactusSemi | 3:3e8c16b6620c | 175 | uint8_t range_trim; |
CactusSemi | 3:3e8c16b6620c | 176 | uint8_t PMOS_off; |
CactusSemi | 3:3e8c16b6620c | 177 | uint8_t Driver2; |
CactusSemi | 3:3e8c16b6620c | 178 | uint8_t Driver3; |
CactusSemi | 3:3e8c16b6620c | 179 | uint8_t DMOS; |
CactusSemi | 3:3e8c16b6620c | 180 | uint8_t CCM_threshold; |
CactusSemi | 3:3e8c16b6620c | 181 | uint8_t DMOS_ctrl_trim; |
CactusSemi | 3:3e8c16b6620c | 182 | uint8_t adc_op_mode; |
CactusSemi | 3:3e8c16b6620c | 183 | |
CactusSemi | 3:3e8c16b6620c | 184 | int i; |
CactusSemi | 3:3e8c16b6620c | 185 | char temp; |
CactusSemi | 3:3e8c16b6620c | 186 | |
CactusSemi | 3:3e8c16b6620c | 187 | pc.printf("\n\n\n\r\t"); |
CactusSemi | 3:3e8c16b6620c | 188 | for ( i = 0; i<60; i++) pc.printf("\304"); |
CactusSemi | 3:3e8c16b6620c | 189 | pc.printf("\n\n\n\r\tPerforming an NVM read and loading the contents to the register"); |
CactusSemi | 3:3e8c16b6620c | 190 | pc.printf("\n\n\r\tSwitching to faster clock before reading the NVM"); |
CactusSemi | 3:3e8c16b6620c | 191 | i2c_write_fn(i2c_obj,0x02,0x01); //switching to faster clock for NVM read |
CactusSemi | 3:3e8c16b6620c | 192 | i2c_write_fn(i2c_obj,0x03,0x01); //switching to faster clock for NVM read |
CactusSemi | 4:61f1412310af | 193 | i2c_write_fn(i2c_obj,NVM_CTLR_ADR,NVM_PWR_ON); |
CactusSemi | 3:3e8c16b6620c | 194 | wait_ms(1); |
CactusSemi | 4:61f1412310af | 195 | i2c_write_fn(i2c_obj,NVM_CTLR_ADR,(NVM_PWR_ON + NVM_READ)); //Perform a complete read; will be sucessful only if NVM is not empty |
CactusSemi | 3:3e8c16b6620c | 196 | wait_ms(100); |
CactusSemi | 3:3e8c16b6620c | 197 | |
CactusSemi | 3:3e8c16b6620c | 198 | //check if tm_nvm_read bit has cleared itself |
CactusSemi | 3:3e8c16b6620c | 199 | temp = 0; |
CactusSemi | 3:3e8c16b6620c | 200 | while (temp == 0){ |
CactusSemi | 3:3e8c16b6620c | 201 | data = i2c_read_fn(i2c_obj,NVM_CTLR_ADR); |
CactusSemi | 3:3e8c16b6620c | 202 | data = data & 0x40; |
CactusSemi | 3:3e8c16b6620c | 203 | if (data == 0x00) { |
CactusSemi | 3:3e8c16b6620c | 204 | pc.printf("\n\n\r\ttm_nvm_read has cleared; so loading Register with NVM complete"); |
CactusSemi | 3:3e8c16b6620c | 205 | temp = 1; |
CactusSemi | 3:3e8c16b6620c | 206 | } |
CactusSemi | 3:3e8c16b6620c | 207 | else wait_ms(100); |
CactusSemi | 3:3e8c16b6620c | 208 | } |
CactusSemi | 3:3e8c16b6620c | 209 | |
CactusSemi | 3:3e8c16b6620c | 210 | pc.printf("\n\n\n\r\tReading register 0x00 to 0x09"); |
CactusSemi | 3:3e8c16b6620c | 211 | for( reg_ptr = 0x00; reg_ptr <= 0x09; reg_ptr = reg_ptr+1) { |
CactusSemi | 3:3e8c16b6620c | 212 | reg_data[reg_ptr] = i2c_read_fn(i2c_obj,reg_ptr); |
CactusSemi | 3:3e8c16b6620c | 213 | } |
CactusSemi | 3:3e8c16b6620c | 214 | |
CactusSemi | 3:3e8c16b6620c | 215 | //Storing read data into variables |
CactusSemi | 3:3e8c16b6620c | 216 | max_Vout = reg_data[0] & 0x0f; |
CactusSemi | 3:3e8c16b6620c | 217 | max_Vout_trim = reg_data[1] & 0x1f; |
CactusSemi | 3:3e8c16b6620c | 218 | high_time = reg_data[2] & 0x7f; |
CactusSemi | 3:3e8c16b6620c | 219 | low_time = reg_data[3] & 0x7f; |
CactusSemi | 3:3e8c16b6620c | 220 | adc_samp_rate = reg_data[4]>>4; |
CactusSemi | 3:3e8c16b6620c | 221 | adc_range = (reg_data[4]>>2) & 0x03; |
CactusSemi | 3:3e8c16b6620c | 222 | adc_time_out = reg_data[4] & 0x03; |
CactusSemi | 3:3e8c16b6620c | 223 | comp_offset = reg_data[5] & 0x1f; |
CactusSemi | 3:3e8c16b6620c | 224 | range_trim = reg_data[6] & 0x1f; |
CactusSemi | 3:3e8c16b6620c | 225 | PMOS_off = reg_data[7] & 0x0f; |
CactusSemi | 3:3e8c16b6620c | 226 | Driver2 = reg_data[8] & 0x0f; |
CactusSemi | 3:3e8c16b6620c | 227 | Driver3 = (reg_data[8]>>4) & 0x0f; |
CactusSemi | 3:3e8c16b6620c | 228 | DMOS = (reg_data[9]>>7) & 0x01; |
CactusSemi | 3:3e8c16b6620c | 229 | CCM_threshold = (reg_data[7]>>4) & 0x0f; |
CactusSemi | 3:3e8c16b6620c | 230 | DMOS_ctrl_trim = reg_data[9] & 0x1f; |
CactusSemi | 3:3e8c16b6620c | 231 | adc_op_mode = (reg_data[5]>>7) & 0x01; |
CactusSemi | 3:3e8c16b6620c | 232 | |
CactusSemi | 3:3e8c16b6620c | 233 | pc.printf("\n\n\r\tFollowing data was read from the Register"); |
CactusSemi | 3:3e8c16b6620c | 234 | |
CactusSemi | 3:3e8c16b6620c | 235 | print_nvm_reg(&max_Vout, &max_Vout_trim, &high_time, &low_time, &adc_samp_rate, |
CactusSemi | 3:3e8c16b6620c | 236 | &adc_range, &adc_time_out, &comp_offset, &range_trim, &PMOS_off, &Driver2, &Driver3, |
CactusSemi | 3:3e8c16b6620c | 237 | &DMOS, &CCM_threshold, &DMOS_ctrl_trim, &adc_op_mode); |
CactusSemi | 3:3e8c16b6620c | 238 | |
CactusSemi | 3:3e8c16b6620c | 239 | //push data into NVM_data |
CactusSemi | 3:3e8c16b6620c | 240 | NVM_data = NVM_data | (max_Vout+1); //max_Vout(register) = max_Vout(NVM) - 1 |
CactusSemi | 3:3e8c16b6620c | 241 | NVM_data = (NVM_data<<5) | max_Vout_trim; |
CactusSemi | 3:3e8c16b6620c | 242 | NVM_data = (NVM_data<<7) | high_time; // <<x : x corresponds to no. of bits |
CactusSemi | 3:3e8c16b6620c | 243 | NVM_data = (NVM_data<<7) | low_time; |
CactusSemi | 3:3e8c16b6620c | 244 | NVM_data = (NVM_data<<4) | adc_samp_rate; |
CactusSemi | 3:3e8c16b6620c | 245 | NVM_data = (NVM_data<<2) | adc_range; |
CactusSemi | 3:3e8c16b6620c | 246 | NVM_data = (NVM_data<<2) | adc_time_out; |
CactusSemi | 3:3e8c16b6620c | 247 | NVM_data = (NVM_data<<5) | comp_offset; |
CactusSemi | 3:3e8c16b6620c | 248 | NVM_data = (NVM_data<<5) | range_trim; |
CactusSemi | 3:3e8c16b6620c | 249 | NVM_data = (NVM_data<<4) | PMOS_off; |
CactusSemi | 3:3e8c16b6620c | 250 | NVM_data = (NVM_data<<4) | Driver2; |
CactusSemi | 3:3e8c16b6620c | 251 | NVM_data = (NVM_data<<4) | Driver3; |
CactusSemi | 3:3e8c16b6620c | 252 | NVM_data = (NVM_data<<1) | DMOS; |
CactusSemi | 3:3e8c16b6620c | 253 | NVM_data = (NVM_data<<4) | CCM_threshold; |
CactusSemi | 3:3e8c16b6620c | 254 | NVM_data = (NVM_data<<5) | DMOS_ctrl_trim; |
CactusSemi | 3:3e8c16b6620c | 255 | NVM_data = (NVM_data<<1) | adc_op_mode; |
CactusSemi | 3:3e8c16b6620c | 256 | |
CactusSemi | 3:3e8c16b6620c | 257 | pc.printf("\n\n\n\r\tReconstructed data read from NVM = 0x%016llX",NVM_data); |
CactusSemi | 3:3e8c16b6620c | 258 | return NVM_data; |
CactusSemi | 3:3e8c16b6620c | 259 | } |
CactusSemi | 3:3e8c16b6620c | 260 | |
CactusSemi | 3:3e8c16b6620c | 261 | |
CactusSemi | 3:3e8c16b6620c | 262 | void EasyFuse_prog() { |
CactusSemi | 3:3e8c16b6620c | 263 | uint64_t NVM_data = 0x0000000000000000; |
CactusSemi | 3:3e8c16b6620c | 264 | uint64_t NVM_read_data; |
CactusSemi | 3:3e8c16b6620c | 265 | |
CactusSemi | 3:3e8c16b6620c | 266 | // Register variables |
CactusSemi | 3:3e8c16b6620c | 267 | uint8_t max_Vout = 0x07; |
CactusSemi | 3:3e8c16b6620c | 268 | uint8_t max_Vout_trim = 0x00; |
CactusSemi | 3:3e8c16b6620c | 269 | uint8_t high_time = 0x12; |
CactusSemi | 3:3e8c16b6620c | 270 | uint8_t low_time = 0x29; |
CactusSemi | 3:3e8c16b6620c | 271 | uint8_t adc_samp_rate = 0x06; |
CactusSemi | 3:3e8c16b6620c | 272 | uint8_t adc_range = 0x01; |
CactusSemi | 3:3e8c16b6620c | 273 | uint8_t adc_time_out = 0x02; |
CactusSemi | 3:3e8c16b6620c | 274 | uint8_t comp_offset = 0x00; |
CactusSemi | 3:3e8c16b6620c | 275 | uint8_t range_trim = 0x0f; |
CactusSemi | 3:3e8c16b6620c | 276 | uint8_t PMOS_off = 0x08; |
CactusSemi | 3:3e8c16b6620c | 277 | uint8_t Driver2 = 0x08; |
CactusSemi | 3:3e8c16b6620c | 278 | uint8_t Driver3 = 0x08; |
CactusSemi | 3:3e8c16b6620c | 279 | uint8_t DMOS = 0x01; |
CactusSemi | 3:3e8c16b6620c | 280 | uint8_t CCM_threshold = 0x0f; |
CactusSemi | 3:3e8c16b6620c | 281 | uint8_t DMOS_ctrl_trim = 0x0c; |
CactusSemi | 3:3e8c16b6620c | 282 | uint8_t adc_op_mode = 0x01; |
CactusSemi | 3:3e8c16b6620c | 283 | |
CactusSemi | 3:3e8c16b6620c | 284 | // NVM Register Control Bit locations; PWR_ON set in all the definitions |
CactusSemi | 4:61f1412310af | 285 | uint8_t NVM_RESET = 0x01 ; |
CactusSemi | 3:3e8c16b6620c | 286 | uint8_t NVM_PWE1 = 0x02 ; |
CactusSemi | 4:61f1412310af | 287 | uint8_t NVM_CLK1 = 0x04 ; |
CactusSemi | 4:61f1412310af | 288 | uint8_t NVM_PWR_ON = 0x20 ; |
CactusSemi | 4:61f1412310af | 289 | uint8_t NVM_READ = 0x90 ;//unpdated in Rev1.0 |
CactusSemi | 3:3e8c16b6620c | 290 | |
CactusSemi | 3:3e8c16b6620c | 291 | uint8_t NVM_CTLR_ADR = 0x0a ; //Register address for NVM CTRL |
CactusSemi | 3:3e8c16b6620c | 292 | |
CactusSemi | 3:3e8c16b6620c | 293 | char reg_data = 0xaa; |
CactusSemi | 3:3e8c16b6620c | 294 | char temp; |
CactusSemi | 3:3e8c16b6620c | 295 | char high_time_prog = 0x04; |
CactusSemi | 3:3e8c16b6620c | 296 | char low_time_prog = 0x04; |
CactusSemi | 3:3e8c16b6620c | 297 | int flag1 = 0; |
CactusSemi | 3:3e8c16b6620c | 298 | int i = 0; |
CactusSemi | 3:3e8c16b6620c | 299 | |
CactusSemi | 3:3e8c16b6620c | 300 | int delay1 = 20; |
CactusSemi | 3:3e8c16b6620c | 301 | int delay2 = 2 * delay1; |
CactusSemi | 3:3e8c16b6620c | 302 | |
CactusSemi | 3:3e8c16b6620c | 303 | I2C i2c(p9,p10); |
CactusSemi | 3:3e8c16b6620c | 304 | i2c.frequency((frequ/2)*1000); |
CactusSemi | 3:3e8c16b6620c | 305 | LPC_PINCON->PINMODE_OD0 = (LPC_PINCON->PINMODE_OD0 | 0x0003); // To make p9 & P10 open_drain |
CactusSemi | 3:3e8c16b6620c | 306 | i2c.stop(); //add a stop after hot-read |
CactusSemi | 3:3e8c16b6620c | 307 | |
CactusSemi | 3:3e8c16b6620c | 308 | pc.printf("\n\n\r\tFollowing are the default register data that will be programmed: \n\r "); |
CactusSemi | 3:3e8c16b6620c | 309 | print_nvm_reg(&max_Vout, &max_Vout_trim, &high_time, &low_time, &adc_samp_rate, |
CactusSemi | 3:3e8c16b6620c | 310 | &adc_range, &adc_time_out, &comp_offset, &range_trim, &PMOS_off, &Driver2, &Driver3, |
CactusSemi | 3:3e8c16b6620c | 311 | &DMOS, &CCM_threshold, &DMOS_ctrl_trim, &adc_op_mode); |
CactusSemi | 3:3e8c16b6620c | 312 | |
CactusSemi | 3:3e8c16b6620c | 313 | edit_nvm_reg(&max_Vout, &max_Vout_trim, &high_time, &low_time, &adc_samp_rate, |
CactusSemi | 3:3e8c16b6620c | 314 | &adc_range, &adc_time_out, &comp_offset, &range_trim, &PMOS_off, &Driver2, &Driver3, |
CactusSemi | 3:3e8c16b6620c | 315 | &DMOS, &CCM_threshold, &DMOS_ctrl_trim, &adc_op_mode); |
CactusSemi | 3:3e8c16b6620c | 316 | |
CactusSemi | 3:3e8c16b6620c | 317 | //push data into NVM_data |
CactusSemi | 3:3e8c16b6620c | 318 | NVM_data = NVM_data | (max_Vout+1); //max_Vout(register) = max_Vout(NVM) - 1 |
CactusSemi | 3:3e8c16b6620c | 319 | NVM_data = (NVM_data<<5) | max_Vout_trim; |
CactusSemi | 3:3e8c16b6620c | 320 | NVM_data = (NVM_data<<7) | high_time; // <<x : x corresponds to no. of bits |
CactusSemi | 3:3e8c16b6620c | 321 | NVM_data = (NVM_data<<7) | low_time; |
CactusSemi | 3:3e8c16b6620c | 322 | NVM_data = (NVM_data<<4) | adc_samp_rate; |
CactusSemi | 3:3e8c16b6620c | 323 | NVM_data = (NVM_data<<2) | adc_range; |
CactusSemi | 3:3e8c16b6620c | 324 | NVM_data = (NVM_data<<2) | adc_time_out; |
CactusSemi | 3:3e8c16b6620c | 325 | NVM_data = (NVM_data<<5) | comp_offset; |
CactusSemi | 3:3e8c16b6620c | 326 | NVM_data = (NVM_data<<5) | range_trim; |
CactusSemi | 3:3e8c16b6620c | 327 | NVM_data = (NVM_data<<4) | PMOS_off; |
CactusSemi | 3:3e8c16b6620c | 328 | NVM_data = (NVM_data<<4) | Driver2; |
CactusSemi | 3:3e8c16b6620c | 329 | NVM_data = (NVM_data<<4) | Driver3; |
CactusSemi | 3:3e8c16b6620c | 330 | NVM_data = (NVM_data<<1) | DMOS; |
CactusSemi | 3:3e8c16b6620c | 331 | NVM_data = (NVM_data<<4) | CCM_threshold; |
CactusSemi | 3:3e8c16b6620c | 332 | NVM_data = (NVM_data<<5) | DMOS_ctrl_trim; |
CactusSemi | 3:3e8c16b6620c | 333 | NVM_data = (NVM_data<<1) | adc_op_mode; |
CactusSemi | 3:3e8c16b6620c | 334 | pc.printf("\n\n\n\r\tData to be written into NVM = 0x%016llX",NVM_data); |
CactusSemi | 3:3e8c16b6620c | 335 | pc.printf("\n\n\r\tPlease note that max_Vout has been incremented. max_Vout(NVM) = max_Vout(register) + 1"); |
CactusSemi | 3:3e8c16b6620c | 336 | pc.printf("\n\n\r\t"); |
CactusSemi | 3:3e8c16b6620c | 337 | for ( i = 0; i<80; i++) pc.printf("\304"); |
CactusSemi | 3:3e8c16b6620c | 338 | pc.printf("\n\n\r\tContinue EasyFuse Programming? (y/n): "); |
CactusSemi | 3:3e8c16b6620c | 339 | temp = 0; |
CactusSemi | 3:3e8c16b6620c | 340 | while ( temp!='y' && temp!='n') { |
CactusSemi | 3:3e8c16b6620c | 341 | temp = pc.getc(); |
CactusSemi | 3:3e8c16b6620c | 342 | } |
CactusSemi | 3:3e8c16b6620c | 343 | if (temp == 'n') { |
CactusSemi | 3:3e8c16b6620c | 344 | pc.printf("\n\n\r\tAborting... :("); |
CactusSemi | 3:3e8c16b6620c | 345 | return; |
CactusSemi | 3:3e8c16b6620c | 346 | } |
CactusSemi | 3:3e8c16b6620c | 347 | //EasyFuse Empty check |
CactusSemi | 4:61f1412310af | 348 | pc.printf("\n\n\r\tPerforming NVM Empty check by trying to load register with NVM contents. Connect 4.5V at PROG pin"); |
CactusSemi | 3:3e8c16b6620c | 349 | i2c_write_fn(&i2c,0x02,0x01); //switching to faster clock for NVM read |
CactusSemi | 3:3e8c16b6620c | 350 | i2c_write_fn(&i2c,0x03,0x01); //switching to faster clock for NVM read |
CactusSemi | 3:3e8c16b6620c | 351 | wait_ms(1); |
CactusSemi | 4:61f1412310af | 352 | i2c_write_fn(&i2c,NVM_CTLR_ADR,(NVM_READ + NVM_PWR_ON)); //Force NVM load |
CactusSemi | 3:3e8c16b6620c | 353 | wait_ms(100); |
CactusSemi | 3:3e8c16b6620c | 354 | |
CactusSemi | 3:3e8c16b6620c | 355 | //check if tm_nvm_read bit has cleared itself |
CactusSemi | 3:3e8c16b6620c | 356 | temp = 0; |
CactusSemi | 3:3e8c16b6620c | 357 | while (temp == 0){ |
CactusSemi | 3:3e8c16b6620c | 358 | reg_data = i2c_read_fn(&i2c,NVM_CTLR_ADR); |
CactusSemi | 4:61f1412310af | 359 | reg_data = reg_data & 0x80; //updated in Rev1.0; checking for tm_ld_shdw |
CactusSemi | 3:3e8c16b6620c | 360 | if (reg_data == 0x00) { |
CactusSemi | 4:61f1412310af | 361 | pc.printf("\n\n\r\ttm_ld_shdw has cleared; so loading Register with NVM contents complete"); |
CactusSemi | 3:3e8c16b6620c | 362 | temp = 1; |
CactusSemi | 3:3e8c16b6620c | 363 | } |
CactusSemi | 3:3e8c16b6620c | 364 | else wait_ms(100); |
CactusSemi | 3:3e8c16b6620c | 365 | } |
CactusSemi | 3:3e8c16b6620c | 366 | |
CactusSemi | 3:3e8c16b6620c | 367 | reg_data = i2c_read_fn(&i2c,0x02); |
CactusSemi | 3:3e8c16b6620c | 368 | reg_data = reg_data<<4; |
CactusSemi | 3:3e8c16b6620c | 369 | reg_data = reg_data | i2c_read_fn(&i2c,0x03); |
CactusSemi | 3:3e8c16b6620c | 370 | if (reg_data == 0xff) pc.printf(" |\033[%dm Register read might not be sucessfull \033[%dm ",45,40); |
CactusSemi | 4:61f1412310af | 371 | if (reg_data == 0x00) pc.printf("\n\n\r\t\033[%dm EasyFuse empty \033[%dm",44,40); //address 0x02 & 0x03 changed to 0 |
CactusSemi | 3:3e8c16b6620c | 372 | else { |
CactusSemi | 3:3e8c16b6620c | 373 | pc.printf("\n\n\r\t\033[%dm EasyFuse not empty \033[%dm",45,40); |
CactusSemi | 3:3e8c16b6620c | 374 | pc.printf("\n\n\r\t Better to abort the test.. :("); |
CactusSemi | 3:3e8c16b6620c | 375 | //return; |
CactusSemi | 3:3e8c16b6620c | 376 | } |
CactusSemi | 3:3e8c16b6620c | 377 | |
CactusSemi | 3:3e8c16b6620c | 378 | //added for debug.. delete later |
CactusSemi | 3:3e8c16b6620c | 379 | pc.printf("\n\n\n\r\tWe will next configure the oscillator. Proceed? (y/n): "); |
CactusSemi | 3:3e8c16b6620c | 380 | temp = 0; |
CactusSemi | 3:3e8c16b6620c | 381 | while ( temp!='y' && temp!='n') { |
CactusSemi | 3:3e8c16b6620c | 382 | temp = pc.getc(); |
CactusSemi | 3:3e8c16b6620c | 383 | } |
CactusSemi | 3:3e8c16b6620c | 384 | if (temp == 'n') { |
CactusSemi | 3:3e8c16b6620c | 385 | pc.printf("\n\n\r\tAborting.. :("); |
CactusSemi | 3:3e8c16b6620c | 386 | return; |
CactusSemi | 3:3e8c16b6620c | 387 | } |
CactusSemi | 4:61f1412310af | 388 | i2c_write_fn(&i2c,0x00,0x08); //setting Vout_max to 4.6 |
CactusSemi | 4:61f1412310af | 389 | pc.printf("\n\n\r\tEnabled 'fc_enable' & driver1. Set VINP to 4.0V. Monitor the oscillator at the output of comparator"); |
CactusSemi | 3:3e8c16b6620c | 390 | i2c_write_fn(&i2c,0x0c,0x22); |
CactusSemi | 3:3e8c16b6620c | 391 | osc_trim: |
CactusSemi | 3:3e8c16b6620c | 392 | i2c_write_fn(&i2c,0x02,high_time_prog); //Recommended clocks period |
CactusSemi | 3:3e8c16b6620c | 393 | i2c_write_fn(&i2c,0x03,low_time_prog); // for programming is 10us |
CactusSemi | 3:3e8c16b6620c | 394 | wait_ms(1); |
CactusSemi | 3:3e8c16b6620c | 395 | |
CactusSemi | 3:3e8c16b6620c | 396 | pc.printf("\n\n\n\r\t\033[%dm", 44);//change backround to blue |
CactusSemi | 3:3e8c16b6620c | 397 | pc.printf("Please check if Oscillator period is approx 10us (9.4us to 10.4us) \033[%dm\n\n\r\tPress 'y' to continue; Press 'm' to modify clock trim settings : ",40); |
CactusSemi | 3:3e8c16b6620c | 398 | |
CactusSemi | 3:3e8c16b6620c | 399 | temp = 0; |
CactusSemi | 3:3e8c16b6620c | 400 | while ( temp!='y' && temp!='m' && temp!='m' ) { |
CactusSemi | 3:3e8c16b6620c | 401 | temp = pc.getc(); |
CactusSemi | 3:3e8c16b6620c | 402 | } |
CactusSemi | 3:3e8c16b6620c | 403 | if (temp == 'n') { |
CactusSemi | 3:3e8c16b6620c | 404 | pc.printf("\n\n\r\tAborting.. :("); |
CactusSemi | 3:3e8c16b6620c | 405 | return; |
CactusSemi | 3:3e8c16b6620c | 406 | } |
CactusSemi | 3:3e8c16b6620c | 407 | if (temp == 'm') { |
CactusSemi | 3:3e8c16b6620c | 408 | pc.printf("\n\n\n\n\r\tCurrent high_time trim = 0x%2.2X & low_time trim = 0x%2.2X",high_time_prog,low_time_prog); |
CactusSemi | 3:3e8c16b6620c | 409 | flag1 = 0; |
CactusSemi | 3:3e8c16b6620c | 410 | while (!flag1) { |
CactusSemi | 3:3e8c16b6620c | 411 | pc.printf("\n\n\r\tEnter new high_time trim in hex (00 to ff): 0x"); |
CactusSemi | 3:3e8c16b6620c | 412 | high_time_prog = get_byte(&flag1); |
CactusSemi | 3:3e8c16b6620c | 413 | if (flag1 == 0) pc.printf(" \033[%dm Invalid Chracter!! No worries, let us try again \033[%dm",41,40); |
CactusSemi | 3:3e8c16b6620c | 414 | } |
CactusSemi | 3:3e8c16b6620c | 415 | flag1 = 0; |
CactusSemi | 3:3e8c16b6620c | 416 | while (!flag1) { |
CactusSemi | 3:3e8c16b6620c | 417 | pc.printf("\n\n\r\tEnter new low_time trim in hex (00 to ff) : 0x"); |
CactusSemi | 3:3e8c16b6620c | 418 | low_time_prog = get_byte(&flag1); |
CactusSemi | 3:3e8c16b6620c | 419 | if (flag1 == 0) pc.printf(" \033[%dm Invalid Chracter!! No worries, let us try again \033[%dm",41,40); |
CactusSemi | 3:3e8c16b6620c | 420 | } |
CactusSemi | 3:3e8c16b6620c | 421 | pc.printf("\n\n\r\tProgramming new high_time trim = 0x%2.2X & new low_time trim = 0x%2.2X",high_time_prog,low_time_prog); |
CactusSemi | 3:3e8c16b6620c | 422 | goto osc_trim; |
CactusSemi | 3:3e8c16b6620c | 423 | } |
CactusSemi | 3:3e8c16b6620c | 424 | |
CactusSemi | 3:3e8c16b6620c | 425 | pc.printf("\n\n\r\tDisabled 'fc_enable' & driver1."); |
CactusSemi | 3:3e8c16b6620c | 426 | i2c_write_fn(&i2c,0x0c,0x00); |
CactusSemi | 3:3e8c16b6620c | 427 | wait_ms(delay2); |
CactusSemi | 3:3e8c16b6620c | 428 | pc.printf("\n\n\n\r\tAll set to program the EasyFuse, time to blow up some ploy fuses! ..**BOOOM**\n\n\r"); |
CactusSemi | 3:3e8c16b6620c | 429 | i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_PWR_ON); //turn ON supply to EasyFuse |
CactusSemi | 3:3e8c16b6620c | 430 | wait_ms(100); |
CactusSemi | 4:61f1412310af | 431 | i2c_write_fn(&i2c,NVM_CTLR_ADR,(NVM_RESET + NVM_PWR_ON)); //turn ON supply to EasyFuse & RESETN = 1 |
CactusSemi | 3:3e8c16b6620c | 432 | wait_ms(1); |
CactusSemi | 3:3e8c16b6620c | 433 | i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_PWR_ON); //RESETN = 0, Prog mode enabled: CKL1 = 0 during RESETN = 0, |
CactusSemi | 3:3e8c16b6620c | 434 | temp = 0; |
CactusSemi | 4:61f1412310af | 435 | pc.printf("\n\n\n\r\tConnect PROG to 4.5V & VINP to 5V and press 'c' to continue"); |
CactusSemi | 3:3e8c16b6620c | 436 | while ( temp!='c') { |
CactusSemi | 3:3e8c16b6620c | 437 | temp = pc.getc(); |
CactusSemi | 3:3e8c16b6620c | 438 | } |
CactusSemi | 4:61f1412310af | 439 | pc.printf("\n\n\n\r\t"); |
CactusSemi | 3:3e8c16b6620c | 440 | wait_us(delay2); |
CactusSemi | 4:61f1412310af | 441 | i2c_write_fn(&i2c,NVM_CTLR_ADR,(NVM_RESET + NVM_PWR_ON)); //RESETN = 1, |
CactusSemi | 3:3e8c16b6620c | 442 | wait_us(delay2); |
CactusSemi | 3:3e8c16b6620c | 443 | for ( i = 0; i < 64; i = i+1) { |
CactusSemi | 4:61f1412310af | 444 | if ( ((NVM_data>>i) & 0x0000000000000001) == 1 ) { |
CactusSemi | 4:61f1412310af | 445 | temp = NVM_PWE1; |
CactusSemi | 4:61f1412310af | 446 | pc.printf("1"); |
CactusSemi | 4:61f1412310af | 447 | } |
CactusSemi | 4:61f1412310af | 448 | else { |
CactusSemi | 4:61f1412310af | 449 | temp = 0x00; |
CactusSemi | 4:61f1412310af | 450 | pc.printf("0"); |
CactusSemi | 4:61f1412310af | 451 | } |
CactusSemi | 4:61f1412310af | 452 | temp = (temp | NVM_RESET | NVM_PWR_ON); //NVM_PWE1 if NVM_data[i]=1 & CLK1 de-asserted |
CactusSemi | 4:61f1412310af | 453 | pc.printf("\n\n\n\n\r\ttemp = 0x%2.2X",temp); |
CactusSemi | 3:3e8c16b6620c | 454 | i2c_write_fn(&i2c,NVM_CTLR_ADR,temp); |
CactusSemi | 3:3e8c16b6620c | 455 | wait_us(delay2); |
CactusSemi | 4:61f1412310af | 456 | temp = (NVM_RESET | NVM_PWR_ON); |
CactusSemi | 3:3e8c16b6620c | 457 | i2c_write_fn(&i2c,NVM_CTLR_ADR,temp); //de-assert NVM_PWE1 |
CactusSemi | 3:3e8c16b6620c | 458 | wait_us(delay2); |
CactusSemi | 4:61f1412310af | 459 | temp = (NVM_RESET | NVM_CLK1 | NVM_PWR_ON); |
CactusSemi | 3:3e8c16b6620c | 460 | i2c_write_fn(&i2c,NVM_CTLR_ADR,temp); //assert CLK1 |
CactusSemi | 3:3e8c16b6620c | 461 | wait_us(delay2); |
CactusSemi | 3:3e8c16b6620c | 462 | } |
CactusSemi | 3:3e8c16b6620c | 463 | pc.printf("\n\n\n\r\t\a\033[%dm", 44);//change backround to blue |
CactusSemi | 3:3e8c16b6620c | 464 | pc.printf("Finished programming. Let us confirm if the NVM has been programmed correctly by reading the NVM. Proceed (y/n): "); |
CactusSemi | 3:3e8c16b6620c | 465 | pc.printf("\033[%dm", 40);//change backround to black |
CactusSemi | 3:3e8c16b6620c | 466 | |
CactusSemi | 3:3e8c16b6620c | 467 | temp = 0; |
CactusSemi | 3:3e8c16b6620c | 468 | while ( temp!='y' ) { |
CactusSemi | 3:3e8c16b6620c | 469 | temp = pc.getc(); |
CactusSemi | 3:3e8c16b6620c | 470 | } |
CactusSemi | 3:3e8c16b6620c | 471 | NVM_read_data = EasyFuse_read(&i2c); |
CactusSemi | 3:3e8c16b6620c | 472 | if ( NVM_data == NVM_read_data ) pc.printf("\n\n\r\tData written into NVM matches data read from NVM\n\n\n\r\t\033[%dm NVM PROGRAMMING SUCESSFULL. Hoorayyy!\a \033[%dm\n\r",44,40); |
CactusSemi | 3:3e8c16b6620c | 473 | else pc.printf("\n\n\r\tuh-oh.. Data written into NVM does not match data read from NVM\n\n\n\r\t\033[%dm NVM PROGRAMMING FAILED!\a \033[%dm\n\r",41,40); |
CactusSemi | 3:3e8c16b6620c | 474 | } |