12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958 |
- //#include "usr_config.h"
- //#include "bsp_time.h"
- //#include "system.h"
- //#include "nrf_gpio.h"
- //#include "app_charge.h"
- //#include "app_flash.h"
- //#include "ble_comm.h"
- //#include "bsp_adc.h"
- //#include "app_pair_chargerpin.h"
- //#include "hal_led.h"
- //#include "hal_charge.h"
- //#include "hal_mt.h"
- //extern void adc_check(void);
- ////发送协议
- ////Host MAC[0] MAC[1] MAC[2]>>>>>> Client
- ////Client MAC[3] MAC[4] MAC[5]>>>>>> Host
- //#define HOST_PEAR 1
- //#define PIN_LED_RUN 1
- //#define DATA_LENGTH 4
- //#define BITWIDTH 30
- //#define LOW_BIT_DELAY 15
- //#define DELAY_SEND 100
- //#define DELAY_REPLY 100
- //#define DELAY_CHECK 100
- //#define DELAY_LEDON (BITWIDTH*(8*DATA_LENGTH+3)*2+DELAY_SEND+DELAY_REPLY+DELAY_CHECK+5*BITWIDTH)
- //#define LEDON_KEEP 100
- //static uint8_t leddisplay_count=0;
- //unsigned static char rxbuf[DATA_LENGTH];
- //unsigned static char txbuf[DATA_LENGTH];
- //__IO static char writefig=0;
- //unsigned static char savebuf[DATA_LENGTH];
- //static char one_ms_status = 0;
- //static void chargerpin_one_ms_pcs(void* t)
- //{
- // unsigned int ms = *(unsigned int*)t;
- // static unsigned int bit_width = 0;
- // static unsigned int now_bit = 0;
- // static unsigned int delay_send_count = 0;
- // static unsigned int delay_reply_count = 0;
- // static unsigned int delay_check_count = 0;
- // static unsigned int delay_ledon_count = 0;
- // static int bitindex = 0;
- // static int bytesindes = 0;
- // static int value = 0;
- // static int txrxcount = 0;
- // static char lowbitdelay=0;
- // switch (one_ms_status)
- // {
- // case 0://init
- // bit_width = 0;
- // now_bit = 0;
- // delay_send_count = 0;
- // delay_reply_count = 0;
- // delay_check_count = 0;
- // delay_ledon_count = 0;
- // bitindex = 0;
- // bytesindes = 0;
- // value = 0;
- // txrxcount = 0;
- // one_ms_status = 0;
- // lowbitdelay=0;
- // nrf_gpio_cfg(
- // PIN_CHARGING,
- // NRF_GPIO_PIN_DIR_OUTPUT,
- // NRF_GPIO_PIN_INPUT_CONNECT,
- // NRF_GPIO_PIN_NOPULL,
- // NRF_GPIO_PIN_D0H1,
- // NRF_GPIO_PIN_NOSENSE);
- // nrf_gpio_cfg_watcher(PIN_CHARGING);
- // one_ms_status = 1;
- // nrf_gpio_pin_clear(PIN_CHARGING);
- // PAIR_CHARGERPIN_PRINT("nrf_gpio_cfg_watcher(PIN_CHARGING); clear.%d\r\n", ms);
- // break;
- // case 1:
- // if (now_bit == nrf_gpio_pin_read(PIN_CHARGING))
- // {
- // bit_width++;
- // }
- // else
- // {
- // //由高电平切换到低电平,下降信号
- // if (now_bit == 1)
- // {
- // now_bit = 0;
- // if ((bit_width > 1.5 * BITWIDTH - LOW_BIT_DELAY/3) && (bit_width < 1.5 * BITWIDTH + LOW_BIT_DELAY/3))
- // {
- // one_ms_status = 3;
- // txrxcount = 1.5 * BITWIDTH;
- // value = 30;
- // if (mFlash.isHost == 0)
- // {
- // delay_ledon_count = 1.5 * BITWIDTH + DELAY_SEND;
- // PAIR_CHARGERPIN_PRINT("delay_ledon_count = 1.5 * BITWIDTH + DELAY_SEND.%d\r\n", txrxcount);
- // }
- // else
- // {
- // delay_ledon_count = 2.5 * BITWIDTH + DELAY_SEND + BITWIDTH * 8 * DATA_LENGTH + 1.5 * BITWIDTH + DELAY_REPLY;
- // PAIR_CHARGERPIN_PRINT("delay_ledon_count = 2.5 * BITWIDTH + DELAY_SEND + BITWIDTH*8*DATA_LENGTH + 1.5 * BITWIDTH + DELAY_REPLY .%d\r\n", txrxcount);
- // }
- // PAIR_CHARGERPIN_PRINT("-----------------------RX MODE start .%d\r\n", bit_width);
- // break;
- // }
- // else
- // {
- // if (mFlash.isHost)
- // {
- // delay_send_count = 1; //左边鞋发送数据
- // }
- // PAIR_CHARGERPIN_INFO("EXTI CHARGEING MOID.%d bit_width %d \r\n", ms,bit_width);
- // }
- // }
- // else
- // {
- // now_bit = 1;
- // delay_send_count = 0;
- // delay_reply_count = 0;
- // delay_check_count = 0;
- // nrf_gpio_pin_write(PIN_LED_RUN, 0);
- // delay_ledon_count = 0;
- // PAIR_CHARGERPIN_PRINT("delay_ledon_count = 0 .%d\r\n", txrxcount);
- // PAIR_CHARGERPIN_INFO("INTO CHARGEING MOID.%d\r\n", ms);
- // }
- // bit_width = 0;
- // }
- //
- // if (delay_send_count != 0)
- // {
- // delay_send_count++;
- // }
- // if (delay_send_count > DELAY_SEND)
- // {
- // unsigned char macbuff[32];
- // delay_send_count = 0;
- // PAIR_CHARGERPIN_PRINT("BEGIN send MAC.%d\r\n", ms);
- // Get_MACaddr(macbuff);
- // macbuff[DATA_LENGTH - 1] = 0;
- // for (int i = 0; i < DATA_LENGTH - 1; i++)
- // {
- // macbuff[DATA_LENGTH - 1] += macbuff[i];
- // }
- // memcpy(txbuf, macbuff, DATA_LENGTH);
- // PAIR_CHARGERPIN_PRINT("host_mac send.%d\r\n", ms);
- // one_ms_status = 2;
- //
- // txrxcount = 0;
- // for (int i = 0; i < DATA_LENGTH; i++)
- // {
- // PAIR_CHARGERPIN_PRINT("txbuf.%x\r\n", txbuf[i]);
- // }
- // break;
- // }
- // if (delay_reply_count != 0)
- // {
- // delay_reply_count++;
- // }
- // if (delay_reply_count > DELAY_REPLY)
- // {
- // unsigned char macbuff[16];
- // delay_reply_count = 0;
- // PAIR_CHARGERPIN_PRINT("BEGIN send MAC.%d\r\n", ms);
- // Get_MACaddr(macbuff);
- // memcpy(txbuf, &macbuff[3], DATA_LENGTH);
- // txbuf[DATA_LENGTH - 1] = 0;
- // for (int i = 0; i < DATA_LENGTH - 1; i++)
- // {
- // txbuf[DATA_LENGTH - 1] += txbuf[i];
- // }
- // PAIR_CHARGERPIN_PRINT("host_mac send.%d\r\n", ms);
- // one_ms_status = 2;
- // txrxcount = 0;
- // for (int i = 0; i < DATA_LENGTH; i++)
- // {
- // PAIR_CHARGERPIN_PRINT("txbuf.%x\r\n", txbuf[i]);
- // }
- // break;
- // }
- // if (delay_check_count != 0)
- // {
- // delay_check_count++;
- // }
- // if (delay_check_count > DELAY_CHECK)
- // {
- // delay_check_count = 0;
- // one_ms_status = 4;
- // txrxcount = 0;
- // PAIR_CHARGERPIN_PRINT("CHECK start.%d\r\n", ms);
- // break;
- // }
- // else if (delay_check_count > 0)
- // {
- // if (now_bit > 0)
- // {
- // delay_check_count = 0;
- // PAIR_CHARGERPIN_PRINT("CANCEL CHECK.%d\r\n", ms);
- // }
- // }
- // break;
- // case 2://tx
- // {
- // lowbitdelay++;
- // static char send_interrupt = 0;
- // if ((now_bit == 0) && (nrf_gpio_pin_read(PIN_CHARGING)) && (lowbitdelay>LOW_BIT_DELAY))
- // {
- // if (mFlash.isHost)
- // {
- // one_ms_status = 1;
- // nrf_gpio_pin_clear(PIN_CHARGING);
- // PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
- // delay_ledon_count = 0;
- // PAIR_CHARGERPIN_PRINT("delay_ledon_count1 = 0;\r\n", txrxcount);
- // PAIR_CHARGERPIN_PRINT("EXTI SEND MODE.CAN NOT SET LOW %d\r\n", txrxcount);
- // send_interrupt = 0;
- // break;
- // }
- // else
- // {
- // nrf_gpio_pin_clear(PIN_CHARGING);
- // PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
- // send_interrupt = 1;
- // }
- // }
- // if ((txrxcount == 0) && (send_interrupt == 0))
- // {
- // nrf_gpio_pin_set(PIN_CHARGING);
- // PAIR_CHARGERPIN_PRINT("set.%d\r\n", ms);
- // now_bit = 1;
- // }
- // if ((txrxcount == 1.5 * BITWIDTH) && (send_interrupt == 0))
- // {
- // nrf_gpio_pin_clear(PIN_CHARGING);
- // PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
- // now_bit = 0;
- // lowbitdelay=0;
- // }
- // if ((txrxcount >= (int)(2.5 * BITWIDTH) && (txrxcount - (int)(2.5 * BITWIDTH)) % BITWIDTH == 0) && (send_interrupt == 0))
- // {
- // bytesindes = ((txrxcount - (int)(2.5 * BITWIDTH)) / BITWIDTH) / 8;
- // bitindex = 7 - ((txrxcount - (int)(2.5 * BITWIDTH)) / BITWIDTH) % 8;
- // nrf_gpio_pin_write(PIN_CHARGING, (txbuf[bytesindes] >> bitindex) & 0x01);
- // lowbitdelay=0;
- // PAIR_CHARGERPIN_PRINT("write.%d %d\r\n", ((txbuf[bytesindes] >> bitindex) & 0x01), ms);
- // now_bit = (txbuf[bytesindes] >> bitindex) & 0x01;
- // PAIR_CHARGERPIN_PRINT("%d %d %d %d %x\r\n", (txrxcount - (int)(2.5 * BITWIDTH)) / BITWIDTH
- // , bytesindes
- // , bitindex
- // , (txbuf[bytesindes] >> bitindex) & 0x01
- // , txbuf[bytesindes]
- // );
- // }
- // if (send_interrupt)
- // {
- // if (nrf_gpio_pin_read(PIN_CHARGING) == 0)
- // {
- // send_interrupt = 0;
- // delay_ledon_count = DELAY_SEND;
- // PAIR_CHARGERPIN_PRINT("delay_ledon_count = DELAY_SEND;.%d\r\n", txrxcount);
- // PAIR_CHARGERPIN_PRINT("RX SEND MODE MAC START.%d\r\n", txrxcount);
- // txrxcount = 0;
- // break;
- // }
- // }
- //
- // if (txrxcount == BITWIDTH * (8 * DATA_LENGTH + 2.5) - 1)
- // {
- // nrf_gpio_pin_clear(PIN_CHARGING);
- // PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
- // if (mFlash.isHost == 0)
- // {
- // delay_check_count = 1;
- // }
- // }
- // if(delay_check_count!=0)delay_check_count++;
- // if (txrxcount >= BITWIDTH * (8 * DATA_LENGTH + 2.5) - 1 + LOW_BIT_DELAY)
- // {
- // one_ms_status = 1;
- // send_interrupt = 0;
- // now_bit = 0;
- // bit_width = 0;
- // PAIR_CHARGERPIN_PRINT("SEDN DONE .%d pin one_ms_status %d\r\n", ms,nrf_gpio_pin_read(PIN_CHARGING));
- // break;
- // }
- // txrxcount++;
- // }
- // break;
- // case 3://rx
- // if (now_bit == nrf_gpio_pin_read(PIN_CHARGING))
- // {
- // bit_width++;
- // }
- // else
- // {
- // if (now_bit == 1)
- // {
- // now_bit = 0;
- // if ((bit_width > 1.5 * BITWIDTH - 3) && (bit_width < 1.8 * BITWIDTH + 3))
- // {
- // txrxcount = 1.5 * BITWIDTH;
- // value = 30;
- // delay_ledon_count = DELAY_SEND + 1.5 * BITWIDTH;
- // PAIR_CHARGERPIN_PRINT("DELAY_SEND + 1.5 * BITWIDTHt .%d\r\n", txrxcount);
- // PAIR_CHARGERPIN_PRINT("RX MODE restart .%d\r\n", ms);
- // }
- // }
- // else
- // {
- // now_bit = 1;
- // }
- // bit_width = 0;
- // }
- // if (txrxcount >= (int)(3.5 * BITWIDTH) && (txrxcount - (int)(3.5 * BITWIDTH)) % BITWIDTH == 0)
- // {
- // bytesindes = ((txrxcount - (int)(3.5 * BITWIDTH)) / BITWIDTH) / 8;
- // bitindex = 7 - ((txrxcount - (int)(3.5 * BITWIDTH)) / BITWIDTH) % 8;
- // if (value > 0)
- // {
- // rxbuf[bytesindes] |= 0x01 << bitindex;
- // }
- // else
- // {
- // rxbuf[bytesindes] &= ~(0x01 << bitindex);
- // }
- // PAIR_CHARGERPIN_PRINT("%d %d %d %d %x\r\n", txrxcount
- // , bytesindes
- // , bitindex
- // , value
- // , rxbuf[bytesindes]
- // );
- // value = 0;
- // nrf_gpio_pin_toggle(PIN_LED_RUN);
- // }
- // else
- // {
- // if (now_bit)
- // {
- // value++;
- // }
- // else
- // {
- // value--;
- // }
- // }
- // if (txrxcount >= BITWIDTH * (8 * DATA_LENGTH + 2.5))
- // {
- // unsigned char dataerrcheck = 0;
- // unsigned char crc = 0;
- // one_ms_status = 1;
- // PAIR_CHARGERPIN_PRINT("RECEVIC DONE .%d\r\n", txrxcount);
- // nrf_gpio_pin_clear(PIN_LED_RUN);
- // PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
- // for (int i = 0; i < DATA_LENGTH - 1; i++)
- // {
- // crc += rxbuf[i];
- // }
- // for (int i = 0; i < DATA_LENGTH - 1; i++)
- // {
- // if (rxbuf[i] == 0)
- // {
- // dataerrcheck++;
- // }
- // }
- // if (dataerrcheck == DATA_LENGTH - 1)
- // {
- // PAIR_CHARGERPIN_PRINT("CRC ERROR ALL 0x00.%x\r\n", crc);
- // delay_ledon_count = 0;
- // PAIR_CHARGERPIN_PRINT("delay_ledon_count 2= 0;\r\n", txrxcount);
- // break;
- // }
- // dataerrcheck = 0;
- // for (int i = 0; i < DATA_LENGTH - 1; i++)
- // {
- // if (rxbuf[i] == 0xff)
- // {
- // dataerrcheck++;
- // }
- // }
- // if (dataerrcheck == DATA_LENGTH - 1)
- // {
- // PAIR_CHARGERPIN_PRINT("CRC ERROR ALL 0xFF.%x\r\n", crc);
- // delay_ledon_count = 0;
- // PAIR_CHARGERPIN_PRINT("delay_ledon_count 3= 0;\r\n", txrxcount);
- // break;
- // }
- // if (crc == rxbuf[DATA_LENGTH - 1])
- // {
- // if (mFlash.isHost)
- // {
- // delay_check_count = 1; //延时校验计数器
- // }
- // else
- // {
- // delay_reply_count = 1; //延时回复计数器
- // }
- // PAIR_CHARGERPIN_PRINT("---------------CRC SUCCESS .%x----------------\r\n", crc);
- // }
- // else
- // {
- // PAIR_CHARGERPIN_PRINT("CRC ERROR .%x\r\n", crc);
- // delay_ledon_count = 0;
- // PAIR_CHARGERPIN_PRINT("delay_ledon_count 4= 0;\r\n", txrxcount);
- // }
- // for (int i = 0; i < DATA_LENGTH; i++)
- // {
- // PAIR_CHARGERPIN_PRINT("rxbuf[%d].%x\r\n",i, rxbuf[i]);
- // }
- // }
- // txrxcount++;
- // break;
- // case 4:
- // if (nrf_gpio_pin_read(PIN_CHARGING))
- // {
- // value++;
- // }
- // else
- // {
- // value--;
- // }
- // if (mFlash.isHost)
- // {
- // if (txrxcount == 0)
- // {
- // value = 0;
- // nrf_gpio_pin_set(PIN_CHARGING);
- // PAIR_CHARGERPIN_PRINT("set.%d\r\n", ms);
- // }
- // if (txrxcount == 3 * BITWIDTH)
- // {
- // nrf_gpio_pin_clear(PIN_CHARGING);
- // PAIR_CHARGERPIN_PRINT("clear.%d\r\n", delay_ledon_count);
- // }
- // if (txrxcount >= 3 * BITWIDTH + LOW_BIT_DELAY)
- // {
- // value = 0;
- // one_ms_status = 1;
- // now_bit = 0;
- // bit_width = 0;
- // }
- // }
- // else
- // {
- // if (txrxcount == 0)
- // {
- // value = 0;
- // }
- // if (txrxcount > 3 * BITWIDTH)
- // {
- // if (value < 2 * BITWIDTH)
- // {
- // PAIR_CHARGERPIN_PRINT("CHECK ERROR .%d\r\n", txrxcount);
- // delay_ledon_count = 0;
- // PAIR_CHARGERPIN_PRINT("delay_ledon_count 5= 0;\r\n", txrxcount);
- // }
- // else
- // {
- // PAIR_CHARGERPIN_PRINT("CHECK DONE .%d\r\n", txrxcount);
- // }
- // value = 0;
- // one_ms_status = 1;
- // nrf_gpio_pin_clear(PIN_CHARGING);
- // PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
- // now_bit = 1;
- // bit_width = 0;
- // }
- // }
- // txrxcount++;
- // break;
- // }
- // if (delay_ledon_count != 0)
- // {
- // delay_ledon_count++;
- // }
- // if (delay_ledon_count == DELAY_LEDON)
- // {
- // PAIR_CHARGERPIN_PRINT("LEDCOPEN.%d\r\n", ms);
- // memcpy(savebuf,rxbuf,DATA_LENGTH-1);
- // writefig=1;
- // }
- // if ((delay_ledon_count > DELAY_LEDON )
- // && (delay_ledon_count - DELAY_LEDON == LEDON_KEEP))
- // {
- // delay_ledon_count = 0;
- // PAIR_CHARGERPIN_PRINT("delay_ledon_count 6= 0;\r\n", txrxcount);
- // PAIR_CHARGERPIN_PRINT("LEDCLOSE.%d\r\n", ms);
- // }
- //}
- //void pair_led_pcs(void)
- //{
- // leddisplay_count++;
- // if(leddisplay_count%2==0)
- // {
- // LED_Start(LED_PAIR,COLOR_BLACK);
- // PAIR_CHARGERPIN_PRINT("LED_Start(LED_PAIR,COLOR_BLACK);.%d\r\n");
- // }
- // else
- // {
- // LED_Start(LED_PAIR,COLOR_WHITE);
- // }
- // if(leddisplay_count>20)
- // {
- // leddisplay_count=0;
- // LED_Stop(LED_PAIR);PAIR_CHARGERPIN_PRINT("!!!!!!!!---->>>LED_Stop(LED_PAIR);\r\n");
- // Process_SetHoldOn(pair_led_pcs,0);
- // Process_Stop(pair_led_pcs);
- // }
- //}
- //void stop_pair_led(void)
- //{
- // if(leddisplay_count==0)return;
- // Process_SetHoldOn(pair_led_pcs,0);
- // Process_Stop(pair_led_pcs);
- // leddisplay_count=0;
- //}
- //PAIR_START_REGISTER(stop_pair_led);
- //void mtrun(void)
- //{
- // //MT_Run(200);
- //}
- //PAIR_START_REGISTER(mtrun);
- ////写配对相关的flish
- //static int pair_writeflish(unsigned char* macAddr_L, unsigned char* macAddr_R)
- //{
- // uint8_t offest =0;
- // if(mFlash.isHost){offest =3;}
- //
- // if (memcmp(macAddr_R, mFlash.mClient.macAddr+offest, 3) != 0)
- // {
- // goto writein;
- // }
- // if (mFlash.mClient.isConfig != 'C')
- // {
- // goto writein;
- // }
- // PAIR_CHARGERPIN_PRINT("mFlash.mClient.isConfig:%X\n", mFlash.mClient.isConfig);
- // PAIR_CHARGERPIN_PRINT("mFlash.mClient.macAddr:%02X %02X %02X\n", mFlash.mClient.macAddr[0], mFlash.mClient.macAddr[1], mFlash.mClient.macAddr[2]);
- // PAIR_CHARGERPIN_PRINT("mFlash.macHost:%02X %02X %02X\n", mFlash.macHost[0], mFlash.macHost[1], mFlash.macHost[2]);
- // return 0;
- //writein:
- // mFlash.mClient.isConfig = 'C';
- // uint8_t i=0;
- // for (i = 0; i < 6; i++){mFlash.macHost[i] = macAddr_L[i];}
- //
- // for (i = 0; i < 3; i++)
- // mFlash.mClient.macAddr[i+offest] = macAddr_R[i]; //从机自身mac地址
- //
- // //保存数据到备份区域里面
- // for( i=0; i<RecordMacAddrL; i++){
- // mBackup.macAddr_L[i] = mFlash.macHost[i]; //主机地址
- // mBackup.macAddr_R[i] = mFlash.mClient.macAddr[i];//从机地址
- // }
- //
- // mBackup.hardVersion = mFlash.mClient.hardVersion;
- // mBackup.sotfVersion = mFlash.mClient.sotfVersion;
- // mBackup.isConfig = mFlash.mClient.isConfig;
- //
- // if(Flash_SaveBackup() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Pair,"pair save backup fail");
- //
- // DEBUG_LOG("mFlash.mClient.isConfig:%X\n", mFlash.mClient.isConfig);
- // DEBUG_LOG("mFlash.mClient.macAddr:%02X %02X %02X\n", mFlash.mClient.macAddr[0], mFlash.mClient.macAddr[1], mFlash.mClient.macAddr[2]);
- // DEBUG_LOG("mFlash.macHost:%02X %02X %02X \n", mFlash.macHost[0], mFlash.macHost[1], mFlash.macHost[2]);
- // if(Flash_DeleteAllStep() != ZONE_OP_SUCCESS){Except_TxError(EXCEPT_Pair,"pair clear step fail");return 0;}
- // memset(&mFlash.mStep,0,sizeof(FlashStep_t));
- // if(Flash_SaveInfomation() != ZONE_OP_SUCCESS){Except_TxError(EXCEPT_Pair,"Flash_SaveInfomation fail");return 0;}
- // return 1;
- //}
- //static void load_adv_name_from_flish(void)
- //{
- // char buf[16];
- // memset(buf, 0, sizeof(buf));
- // advertising_stop();
- // sprintf(buf, "%02X%02X%02X%02X%02X%02X", mFlash.mClient.macAddr[0],mFlash.mClient.macAddr[1],mFlash.mClient.macAddr[2],mFlash.macHost[3],mFlash.macHost[4],mFlash.macHost[5]);
- // DEBUG_LOG("advName(%d):%s\n", strlen(buf), buf);
- // slave_set_adv_name(buf, strlen(buf));
- // slave_adv_init();
- //}
- //static void load_scan_name_from_flish(void)
- //{
- // char buf[16];
- // memset(buf, 0, sizeof(buf));
- // sprintf(buf, "%02X%02X%02X%02X%02X%02X", mFlash.macHost[0], mFlash.macHost[1], mFlash.macHost[2], mFlash.mClient.macAddr[3], mFlash.mClient.macAddr[4], mFlash.mClient.macAddr[5]);
- // DEBUG_LOG("scanName1(%d):%s\n", strlen(buf), buf);
- // host_set_scan_name(buf, strlen(buf));
- //}
- //static unsigned char reconnect_pcs_status=0;
- //static void reconnect_pcs(void)
- //{
- // switch(reconnect_pcs_status)
- // {
- // case 0:
- // if(mFlash.isHost)
- // {
- // reconnect_pcs_status=1;
- // if(host_isconnect()==1)host_disconnect();
- // }
- // else
- // {
- // reconnect_pcs_status=2;
- // if(slave_isconnect()==1)slave_disconnect();
- // }
- // break;
- // case 1:
- // if(host_isconnect()==0)
- // {
- // load_scan_name_from_flish();
- // scan_start();
- // reconnect_pcs_status=4;
- // }
- // break;
- // case 2:
- // if(slave_isconnect()==0)
- // {
- // load_adv_name_from_flish();
- // advertising_start();
- // reconnect_pcs_status=4;
- // }
- // break;
- // case 4:
- // Process_SetHoldOn(reconnect_pcs,0);
- // Process_Stop(reconnect_pcs);
- // reconnect_pcs_status=5;
- // leddisplay_count =0;
- // Process_Start(500,"pair_led_pcs",pair_led_pcs);
- // Process_SetHoldOn(pair_led_pcs,1);
- // break;
- // case 5:
- //
- // break;
- // }
- //}
- //static void app_pair_chargerpin_pcs(void)
- //{
- // int rev=0;
- // if(writefig==1)
- // {
- // unsigned char Lbuff[6];
- // unsigned char Rbuff[3];
- // Get_MACaddr(Lbuff);
- // Rbuff[0]=savebuf[0];Rbuff[1]=savebuf[1];Rbuff[2]=savebuf[2];
- // rev=pair_writeflish(Lbuff,Rbuff);
- //
- // if(rev)
- // {
- // Process_Start(10,"reconnect_pcs",reconnect_pcs);
- // Process_SetHoldOn(reconnect_pcs,1);
- // reconnect_pcs_status=0;
- // }
- // else
- // {
- // leddisplay_count =0;
- // Process_Start(500,"pair_led_pcs",pair_led_pcs);
- // Process_SetHoldOn(pair_led_pcs,1);
- // }
- // writefig=0;
- // }
- //}
- //void pair_start_pcs(void)
- //{
- // extern void *pair_start$$Base;
- // extern void *pair_start$$Limit;
- // typedef void (*main_init_t)(void);
- // for (int p = (unsigned int)&pair_start$$Base; p < (unsigned int)&pair_start$$Limit; p += 4)
- // {
- // (*(main_init_t *)p)();
- // }
- //}
- //void pair_done_pcs(void)
- //{
- // extern void *pair_done$$Base;
- // extern void *pair_done$$Limit;
- // typedef void (*main_init_t)(void);
- // for (int p = (unsigned int)&pair_done$$Base; p < (unsigned int)&pair_done$$Limit; p += 4)
- // {
- // (*(main_init_t *)p)();
- // }
- //}
- //typedef enum
- //{
- // CHARGE=0,
- // CONNECT_NO_CHARGE,
- // DISCONNECT_CHARGE,
- //}pair_line_t;
- //#define ADC_CHECKMS 1000
- //#define DELAY_PAIR_COUNT 100
- //void null_pcs(void)
- //{
- //}
- //short left_adc_value=0;
- //void adc_cab(short adc_value)
- //{
- // left_adc_value=adc_value;
- // adc_check();
- //
- // PAIR_CHARGERPIN_PRINT("ADC_Read_CallBack_Once call -%d\n",adc_value);
- //
- //}
- //unsigned int pulluppcs_timer=0;
- //void tim_read_cb(void *t)
- //{
- // if(TIME_GetTicks()-pulluppcs_timer>=3)
- // {
- // PAIR_CHARGERPIN_PRINT("tim_read_cb 3ms \n",mFlash.isHost);
- // if(ADC_OP_SUCCESS!=ADC_Read_CallBack_Once(PIN_CHARGING_CHANNEL,adc_cab))
- // {
- // adc_check();
- // PAIR_CHARGERPIN_PRINT("adc_check init \n",mFlash.isHost);
- // }
- // Process_Stop(null_pcs);
- // TIME_UnRegist(tim_read_cb);
- // }
- //}
- //static pair_line_t pair_line = DISCONNECT_CHARGE;
- //void Delegate_up_pin(void *t)
- //{
- //typedef void (*cbdull)(void);
- // cbdull cbh = adc_check;
- // if(TIME_GetTicks()-pulluppcs_timer>=3)
- // {
- // TIME_UnRegist(Delegate_up_pin);
- // Process_Stop(null_pcs);
- // PAIR_CHARGERPIN_PRINT("Delegate_up_pin %d\n",mFlash.isHost);
- // }
- //}
- //void adc_check(void)
- //{
- // static unsigned char status=0;
- // short ADC_value=0;
- //
- // static unsigned int delay_pair_count=0;
- // static unsigned int overtime=0;
- // static unsigned char ishost;
- // switch(status)
- // {
- // case 0:
- // ishost=mFlash.isHost;
- // ADC_Disable();
- // ADC_SetPinChannel(PIN_CHARGING,PIN_CHARGING_CHANNEL,NRF_GPIO_PIN_NOPULL);
- // ADC_Initialize();
- // Process_UpdatePeroid(adc_check,ADC_CHECKMS);
- // Process_SetHoldOn(adc_check,0);
- // nrf_gpio_pin_write(PIN_LED_RUN, 0);
- // pair_done_pcs();
- // status=1;
- // break;
- // case 1:
- // if(ishost!=mFlash.isHost)
- // {
- // status=0;
- // PAIR_CHARGERPIN_PRINT("mFlash.isHost change %d\n",mFlash.isHost);
- // }
- //
- // if(ADC_OP_SUCCESS!=ADC_Read(PIN_CHARGING_CHANNEL,&ADC_value))
- // {
- // PAIR_CHARGERPIN_PRINT("ADC_Read ERROR %d\n",mFlash.isHost);
- // }
- //
- // if(mFlash.isHost)
- // {
- // pulluppcs_timer=TIME_GetTicks();
- // nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_NOPULL);
- // }
- //
- // PAIR_CHARGERPIN_PRINT( "ADC ( %d ):isHost %d pair_line %d\n", ADC_value,mFlash.isHost,pair_line);
- //
- // if((ADC_value<CHARGE_ADC)&&(pair_line == CHARGE)&&(mFlash.isHost))
- // {
- //// Process_Stop(charge_uppin_pcs);
- // PAIR_CHARGERPIN_PRINT("--------------------------------------------------------EXIT CHARGE_ADC \n");
- // }
- //
- // if(ADC_value>=CHARGE_ADC)
- // {
- // PAIR_CHARGERPIN_PRINT(" CHARGE_ADC \n");
- // if((pair_line != CHARGE)&&(mFlash.isHost))
- // {
- // PAIR_CHARGERPIN_PRINT("--------------------------------------------------------------------INTO CHARGE_ADC \n");
- //// Process_Start(ADC_CHECKMS,"charge_uppin_pcs",charge_uppin_pcs);
- // }
- // pair_line=CHARGE;
- // }
- // else if((ADC_value>=CONN_MIN_ADC)&&(ADC_value<=CONN_MAX_ADC)&&(mFlash.isHost==0))
- // {
- // PAIR_CHARGERPIN_PRINT(" CONN_ADC %d \n",pair_line);
- // connect:
- // if(pair_line!=CONNECT_NO_CHARGE)
- // {
- // PAIR_CHARGERPIN_PRINT(" Process_SetHoldOn(adc_check,1); ms %d\n",TIME_GetTicks());
- //
- // if(mFlash.isHost)Process_Start(ADC_CHECKMS,"adc_check",adc_check);
- //
- // Process_UpdatePeroid(adc_check,10);
- // Process_SetHoldOn(adc_check,1);
- // overtime=TIME_GetTicks();
- // pair_start_pcs();
- //
- // if(mFlash.isHost)
- // {
- // status=2;
- // nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_PULLUP);
- // delay_pair_count=TIME_GetTicks();
- // PAIR_CHARGERPIN_PRINT(" SEND PAIR TAG HIGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH; %d \n",TIME_GetTicks());
- // }
- // else
- // {
- // status=5;
- // TIME_Regist(chargerpin_one_ms_pcs);
- // one_ms_status = 0;
- // }
- // }
- // pair_line=CONNECT_NO_CHARGE;
- // }
- // else
- // {
- // if(mFlash.isHost)
- // {
- // if((ADC_value<=DISCON_L_MAX_ADC)&&(ADC_value>=DISCON_L_MIN_ADC))
- // {
- // PAIR_CHARGERPIN_PRINT("L DISCON_L_ADC \n");
- // pair_line=DISCONNECT_CHARGE;
- // }
- // else if((ADC_value<=CON_L_MAX_ADC)&&(ADC_value>=CON_L_MIN_ADC) && !MT_GetState())
- // {
- // PAIR_CHARGERPIN_PRINT("L CON_L_MAX_ADC \n");
- // goto connect;
- // }
- // }
- // else
- // {
- // if(ADC_value<=DISCON_R_MAX_ADC)
- // {
- // PAIR_CHARGERPIN_PRINT("R DISCON_R_MAX_ADC \n");
- // pair_line=DISCONNECT_CHARGE;
- // }
- // }
- // }
- // break;
- // case 2://
- // if(TIME_GetTicks()- delay_pair_count > ADC_CHECKMS)
- // {
- // TIME_Regist(chargerpin_one_ms_pcs);
- // one_ms_status = 0;
- // status=3;
- // PAIR_CHARGERPIN_PRINT(" TIME_Regist(chargerpin_one_ms_pcs); %d \n",TIME_GetTicks());
- // }
- // break;
- // case 3:
- // if(TIME_GetTicks()- delay_pair_count > DELAY_PAIR_COUNT)
- // {
- // nrf_gpio_pin_set(PIN_CHARGING);
- // PAIR_CHARGERPIN_PRINT(" SEND PAIR TAG HIG; %d \n",TIME_GetTicks());
- // status=4;
- // }
- // break;
- // case 4:
- // if(TIME_GetTicks()- delay_pair_count>(DELAY_PAIR_COUNT+100))
- // {
- // nrf_gpio_pin_clear(PIN_CHARGING);
- // PAIR_CHARGERPIN_PRINT(" SEND PAIR TAG LOW; %d \n",TIME_GetTicks());
- // status=5;
- // }
- // break;
- // case 5:
- // if(writefig==1)
- // {
- // app_pair_chargerpin_pcs();
- // TIME_UnRegist(chargerpin_one_ms_pcs);
- // status=0;
- //// MT_Run(500);
- // PAIR_CHARGERPIN_PRINT(" ---------------------------PAIR SUCESS------------- \n");
- // }
- // if(TIME_GetTicks()-overtime > DELAY_LEDON+ADC_CHECKMS + DELAY_PAIR_COUNT + 100 + 300)
- // {
- // TIME_UnRegist(chargerpin_one_ms_pcs);
- // status=0;
- // PAIR_CHARGERPIN_PRINT(" ---------------------------PAIR OVER TIME %d------------- \n",TIME_GetTicks());
- // }
- // break;
- // }
- //}
- //void write_on(void)
- //{
- // LED_Stop(LED_PAIR);
- // LED_Start(LED_PAIR,COLOR_WHITE);
- // PAIR_CHARGERPIN_PRINT(" --------------------------LED_Start(LED_PAIR,COLOR_WHITE)------------- \n");
- //}
- //PAIR_START_REGISTER(write_on);
- //static volatile uint32_t adctim =0;
- ////void app_adc_test(void){
- //// int16_t adc =0;
- //// uint8_t state =0;
- //// uint32_t errcode = ADC_ReadChargePin(PIN_CHARGING_CHANNEL);
- //// if(errcode==0){
- //// Process_SetHoldOn(app_adc_test,1);
- //// }
- //// DEBUG_LOG(">>>>> app_adc_test:%d\r\n",errcode);
- //// state = bsp_Get_ChargePinADC(&adc);
- //// if(state){
- //// Process_SetHoldOn(app_adc_test,0);
- //// nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_NOPULL);
- //// DEBUG_LOG(">>>>> ReadAdc:%d\r\n",adc);
- //// }
- ////}
- ////void ReadAdc_timcallback(void* t){
- ////
- //// int16_t adc =0;
- //// uint8_t state =0;
- //// static volatile uint8_t temp =0;
- //// if(0 == temp){temp =1;
- //// nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_PULLUP);
- //// adctim = TIME_GetTicks();
- //// Process_SetHoldOn(app_adc_test,1);
- //// }
- //// else if(TIME_GetTicks() - adctim >= 3){adctim = TIME_GetTicks();
- //// uint32_t errcode = ADC_ReadChargePin(PIN_CHARGING_CHANNEL);
- //// if(errcode){
- //// temp =0;
- //// TIME_Regist(ReadAdc_timcallback);
- //// nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_NOPULL);
- //// DEBUG_LOG(">>>>> ReadAdc:%d\r\n",adc);
- //// }
- //// }
- ////}
- //static volatile uint8_t temp =0;
- //void app_adc_test(void){
- // nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_PULLUP);
- // temp =0;
- // adctim = TIME_GetTicks();
- // Process_SetHoldOn(app_adc_test,1);
- //}
- //void ReadAdc_timcallback(void* t){
- //
- // int16_t adc =0;
- // uint8_t state =0;
- //
- // if(0 == temp){
- // if(TIME_GetTicks() - adctim >= 3){
- // uint32_t errcode = ADC_ReadChargePin(PIN_CHARGING_CHANNEL);
- // if(ADC_OP_SUCCESS == errcode){temp =1;
- // }
- // }
- // }
- // else if(temp ==1){
- // state = bsp_Get_ChargePinADC(&adc);
- // if(state){temp =2;
- // Process_SetHoldOn(app_adc_test,0);
- // nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_NOPULL);
- // DEBUG_LOG(">>>>> ReadAdc:%d\r\n",adc);
- // }
- // }
- //
- //}
- //void app_pair_chargerpin_Init(void)
- //{
- // Process_Start(ADC_CHECKMS,"adc_check",adc_check);
- //// Process_Start(1000,"app_adc_test",app_adc_test);
- //// TIME_Regist(ReadAdc_timcallback);
- //// ADC_Disable();
- //// ADC_SetPinChannel(PIN_CHARGING,PIN_CHARGING_CHANNEL,NRF_GPIO_PIN_NOPULL);
- //// ADC_Initialize();
- //}
- #include "usr_config.h"
- #include "bsp_time.h"
- #include "system.h"
- #include "nrf_gpio.h"
- #include "app_charge.h"
- #include "app_flash.h"
- #include "ble_comm.h"
- #include "bsp_adc.h"
- #include "app_pair_chargerpin.h"
- #include "hal_led.h"
- #include "hal_charge.h"
- #include "hal_mt.h"
- extern void adc_check(void);
- //发送协议
- //Host MAC[0] MAC[1] MAC[2]>>>>>> Client
- //Client MAC[3] MAC[4] MAC[5]>>>>>> Host
- #define HOST_PEAR 1
- #define PIN_LED_RUN 2
- #define DATA_LENGTH 4
- #define BITWIDTH 30
- #define LOW_BIT_DELAY 15
- #define DELAY_SEND 100
- #define DELAY_REPLY 100
- #define DELAY_CHECK 100
- #define DELAY_LEDON (BITWIDTH*(8*DATA_LENGTH+3)*2+DELAY_SEND+DELAY_REPLY+DELAY_CHECK+5*BITWIDTH)
- #define LEDON_KEEP 100
- static uint8_t leddisplay_count=0;
- unsigned static char rxbuf[DATA_LENGTH];
- unsigned static char txbuf[DATA_LENGTH];
- __IO static char writefig=0;
- unsigned static char savebuf[DATA_LENGTH];
- static char one_ms_status = 0;
- static void chargerpin_one_ms_pcs(void* t)
- {
- unsigned int ms = *(unsigned int*)t;
- static unsigned int bit_width = 0;
- static unsigned int now_bit = 0;
- static unsigned int delay_send_count = 0;
- static unsigned int delay_reply_count = 0;
- static unsigned int delay_check_count = 0;
- static unsigned int delay_ledon_count = 0;
- static int bitindex = 0;
- static int bytesindes = 0;
- static int value = 0;
- static int txrxcount = 0;
- static char lowbitdelay=0;
- switch (one_ms_status)
- {
- case 0://init
- bit_width = 0;
- now_bit = 0;
- delay_send_count = 0;
- delay_reply_count = 0;
- delay_check_count = 0;
- delay_ledon_count = 0;
- bitindex = 0;
- bytesindes = 0;
- value = 0;
- txrxcount = 0;
- one_ms_status = 0;
- lowbitdelay=0;
- nrf_gpio_cfg(
- PIN_CHARGING,
- NRF_GPIO_PIN_DIR_OUTPUT,
- NRF_GPIO_PIN_INPUT_CONNECT,
- NRF_GPIO_PIN_NOPULL,
- NRF_GPIO_PIN_D0H1,
- NRF_GPIO_PIN_NOSENSE);
- nrf_gpio_cfg_watcher(PIN_CHARGING);
- one_ms_status = 1;
- nrf_gpio_pin_clear(PIN_CHARGING);
- PAIR_CHARGERPIN_PRINT("nrf_gpio_cfg_watcher(PIN_CHARGING); clear.%d\r\n", ms);
- break;
- case 1:
- if (now_bit == nrf_gpio_pin_read(PIN_CHARGING))
- {
- bit_width++;
- }
- else
- {
- //由高电平切换到低电平,下降信号
- if (now_bit == 1)
- {
- now_bit = 0;
- if ((bit_width > 1.5 * BITWIDTH - LOW_BIT_DELAY/3) && (bit_width < 1.5 * BITWIDTH + LOW_BIT_DELAY/3))
- {
- one_ms_status = 3;
- txrxcount = 1.5 * BITWIDTH;
- value = 30;
- if (mFlash.isHost == 0)
- {
- delay_ledon_count = 1.5 * BITWIDTH + DELAY_SEND;
- PAIR_CHARGERPIN_PRINT("delay_ledon_count = 1.5 * BITWIDTH + DELAY_SEND.%d\r\n", txrxcount);
- }
- else
- {
- delay_ledon_count = 2.5 * BITWIDTH + DELAY_SEND + BITWIDTH * 8 * DATA_LENGTH + 1.5 * BITWIDTH + DELAY_REPLY;
- PAIR_CHARGERPIN_PRINT("delay_ledon_count = 2.5 * BITWIDTH + DELAY_SEND + BITWIDTH*8*DATA_LENGTH + 1.5 * BITWIDTH + DELAY_REPLY .%d\r\n", txrxcount);
- }
- PAIR_CHARGERPIN_PRINT("-----------------------RX MODE start .%d\r\n", bit_width);
- break;
- }
- else
- {
- if (mFlash.isHost)
- {
- delay_send_count = 1; //左边鞋发送数据
- }
- PAIR_CHARGERPIN_INFO("EXTI CHARGEING MOID.%d bit_width %d \r\n", ms,bit_width);
- }
- }
- else
- {
- now_bit = 1;
- delay_send_count = 0;
- delay_reply_count = 0;
- delay_check_count = 0;
- nrf_gpio_pin_write(PIN_LED_RUN, 0);
- delay_ledon_count = 0;
- PAIR_CHARGERPIN_PRINT("delay_ledon_count = 0 .%d\r\n", txrxcount);
- PAIR_CHARGERPIN_INFO("INTO CHARGEING MOID.%d\r\n", ms);
- }
- bit_width = 0;
- }
-
- if (delay_send_count != 0)
- {
- delay_send_count++;
- }
- if (delay_send_count > DELAY_SEND)
- {
- unsigned char macbuff[32];
- delay_send_count = 0;
- PAIR_CHARGERPIN_PRINT("BEGIN send MAC.%d\r\n", ms);
- Get_MACaddr(macbuff);
- macbuff[DATA_LENGTH - 1] = 0;
- for (int i = 0; i < DATA_LENGTH - 1; i++)
- {
- macbuff[DATA_LENGTH - 1] += macbuff[i];
- }
- memcpy(txbuf, macbuff, DATA_LENGTH);
- PAIR_CHARGERPIN_PRINT("host_mac send.%d\r\n", ms);
- one_ms_status = 2;
-
- txrxcount = 0;
- for (int i = 0; i < DATA_LENGTH; i++)
- {
- PAIR_CHARGERPIN_PRINT("txbuf.%x\r\n", txbuf[i]);
- }
- break;
- }
- if (delay_reply_count != 0)
- {
- delay_reply_count++;
- }
- if (delay_reply_count > DELAY_REPLY)
- {
- unsigned char macbuff[16];
- delay_reply_count = 0;
- PAIR_CHARGERPIN_PRINT("BEGIN send MAC.%d\r\n", ms);
- Get_MACaddr(macbuff);
- memcpy(txbuf, &macbuff[3], DATA_LENGTH);
- txbuf[DATA_LENGTH - 1] = 0;
- for (int i = 0; i < DATA_LENGTH - 1; i++)
- {
- txbuf[DATA_LENGTH - 1] += txbuf[i];
- }
- PAIR_CHARGERPIN_PRINT("host_mac send.%d\r\n", ms);
- one_ms_status = 2;
- txrxcount = 0;
- for (int i = 0; i < DATA_LENGTH; i++)
- {
- PAIR_CHARGERPIN_PRINT("txbuf.%x\r\n", txbuf[i]);
- }
- break;
- }
- if (delay_check_count != 0)
- {
- delay_check_count++;
- }
- if (delay_check_count > DELAY_CHECK)
- {
- delay_check_count = 0;
- one_ms_status = 4;
- txrxcount = 0;
- PAIR_CHARGERPIN_PRINT("CHECK start.%d\r\n", ms);
- break;
- }
- else if (delay_check_count > 0)
- {
- if (now_bit > 0)
- {
- delay_check_count = 0;
- PAIR_CHARGERPIN_PRINT("CANCEL CHECK.%d\r\n", ms);
- }
- }
- break;
- case 2://tx
- {
- lowbitdelay++;
- static char send_interrupt = 0;
- if ((now_bit == 0) && (nrf_gpio_pin_read(PIN_CHARGING)) && (lowbitdelay>LOW_BIT_DELAY))
- {
- if (mFlash.isHost)
- {
- one_ms_status = 1;
- nrf_gpio_pin_clear(PIN_CHARGING);
- PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
- delay_ledon_count = 0;
- PAIR_CHARGERPIN_PRINT("delay_ledon_count1 = 0;\r\n", txrxcount);
- PAIR_CHARGERPIN_PRINT("EXTI SEND MODE.CAN NOT SET LOW %d\r\n", txrxcount);
- send_interrupt = 0;
- break;
- }
- else
- {
- nrf_gpio_pin_clear(PIN_CHARGING);
- PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
- send_interrupt = 1;
- }
- }
- if ((txrxcount == 0) && (send_interrupt == 0))
- {
- nrf_gpio_pin_set(PIN_CHARGING);
- PAIR_CHARGERPIN_PRINT("set.%d\r\n", ms);
- now_bit = 1;
- }
- if ((txrxcount == 1.5 * BITWIDTH) && (send_interrupt == 0))
- {
- nrf_gpio_pin_clear(PIN_CHARGING);
- PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
- now_bit = 0;
- lowbitdelay=0;
- }
- if ((txrxcount >= (int)(2.5 * BITWIDTH) && (txrxcount - (int)(2.5 * BITWIDTH)) % BITWIDTH == 0) && (send_interrupt == 0))
- {
- bytesindes = ((txrxcount - (int)(2.5 * BITWIDTH)) / BITWIDTH) / 8;
- bitindex = 7 - ((txrxcount - (int)(2.5 * BITWIDTH)) / BITWIDTH) % 8;
- nrf_gpio_pin_write(PIN_CHARGING, (txbuf[bytesindes] >> bitindex) & 0x01);
- lowbitdelay=0;
- PAIR_CHARGERPIN_PRINT("write.%d %d\r\n", ((txbuf[bytesindes] >> bitindex) & 0x01), ms);
- now_bit = (txbuf[bytesindes] >> bitindex) & 0x01;
- PAIR_CHARGERPIN_PRINT("%d %d %d %d %x\r\n", (txrxcount - (int)(2.5 * BITWIDTH)) / BITWIDTH
- , bytesindes
- , bitindex
- , (txbuf[bytesindes] >> bitindex) & 0x01
- , txbuf[bytesindes]
- );
- }
- if (send_interrupt)
- {
- if (nrf_gpio_pin_read(PIN_CHARGING) == 0)
- {
- send_interrupt = 0;
- delay_ledon_count = DELAY_SEND;
- PAIR_CHARGERPIN_PRINT("delay_ledon_count = DELAY_SEND;.%d\r\n", txrxcount);
- PAIR_CHARGERPIN_PRINT("RX SEND MODE MAC START.%d\r\n", txrxcount);
- txrxcount = 0;
- break;
- }
- }
-
- if (txrxcount == BITWIDTH * (8 * DATA_LENGTH + 2.5) - 1)
- {
- nrf_gpio_pin_clear(PIN_CHARGING);
- PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
- if (mFlash.isHost == 0)
- {
- delay_check_count = 1;
- }
- }
- if(delay_check_count!=0)delay_check_count++;
- if (txrxcount >= BITWIDTH * (8 * DATA_LENGTH + 2.5) - 1 + LOW_BIT_DELAY)
- {
- one_ms_status = 1;
- send_interrupt = 0;
- now_bit = 0;
- bit_width = 0;
- PAIR_CHARGERPIN_PRINT("SEDN DONE .%d pin one_ms_status %d\r\n", ms,nrf_gpio_pin_read(PIN_CHARGING));
- break;
- }
- txrxcount++;
- }
- break;
- case 3://rx
- if (now_bit == nrf_gpio_pin_read(PIN_CHARGING))
- {
- bit_width++;
- }
- else
- {
- if (now_bit == 1)
- {
- now_bit = 0;
- if ((bit_width > 1.5 * BITWIDTH - 3) && (bit_width < 1.8 * BITWIDTH + 3))
- {
- txrxcount = 1.5 * BITWIDTH;
- value = 30;
- delay_ledon_count = DELAY_SEND + 1.5 * BITWIDTH;
- PAIR_CHARGERPIN_PRINT("DELAY_SEND + 1.5 * BITWIDTHt .%d\r\n", txrxcount);
- PAIR_CHARGERPIN_PRINT("RX MODE restart .%d\r\n", ms);
- }
- }
- else
- {
- now_bit = 1;
- }
- bit_width = 0;
- }
- if (txrxcount >= (int)(3.5 * BITWIDTH) && (txrxcount - (int)(3.5 * BITWIDTH)) % BITWIDTH == 0)
- {
- bytesindes = ((txrxcount - (int)(3.5 * BITWIDTH)) / BITWIDTH) / 8;
- bitindex = 7 - ((txrxcount - (int)(3.5 * BITWIDTH)) / BITWIDTH) % 8;
- if (value > 0)
- {
- rxbuf[bytesindes] |= 0x01 << bitindex;
- }
- else
- {
- rxbuf[bytesindes] &= ~(0x01 << bitindex);
- }
- PAIR_CHARGERPIN_PRINT("%d %d %d %d %x\r\n", txrxcount
- , bytesindes
- , bitindex
- , value
- , rxbuf[bytesindes]
- );
- value = 0;
- nrf_gpio_pin_toggle(PIN_LED_RUN);
- }
- else
- {
- if (now_bit)
- {
- value++;
- }
- else
- {
- value--;
- }
- }
- if (txrxcount >= BITWIDTH * (8 * DATA_LENGTH + 2.5))
- {
- unsigned char dataerrcheck = 0;
- unsigned char crc = 0;
- one_ms_status = 1;
- PAIR_CHARGERPIN_PRINT("RECEVIC DONE .%d\r\n", txrxcount);
- nrf_gpio_pin_clear(PIN_LED_RUN);
- PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
- for (int i = 0; i < DATA_LENGTH - 1; i++)
- {
- crc += rxbuf[i];
- }
- for (int i = 0; i < DATA_LENGTH - 1; i++)
- {
- if (rxbuf[i] == 0)
- {
- dataerrcheck++;
- }
- }
- if (dataerrcheck == DATA_LENGTH - 1)
- {
- PAIR_CHARGERPIN_PRINT("CRC ERROR ALL 0x00.%x\r\n", crc);
- delay_ledon_count = 0;
- PAIR_CHARGERPIN_PRINT("delay_ledon_count 2= 0;\r\n", txrxcount);
- break;
- }
- dataerrcheck = 0;
- for (int i = 0; i < DATA_LENGTH - 1; i++)
- {
- if (rxbuf[i] == 0xff)
- {
- dataerrcheck++;
- }
- }
- if (dataerrcheck == DATA_LENGTH - 1)
- {
- PAIR_CHARGERPIN_PRINT("CRC ERROR ALL 0xFF.%x\r\n", crc);
- delay_ledon_count = 0;
- PAIR_CHARGERPIN_PRINT("delay_ledon_count 3= 0;\r\n", txrxcount);
- break;
- }
- if (crc == rxbuf[DATA_LENGTH - 1])
- {
- if (mFlash.isHost)
- {
- delay_check_count = 1; //延时校验计数器
- }
- else
- {
- delay_reply_count = 1; //延时回复计数器
- }
- PAIR_CHARGERPIN_PRINT("---------------CRC SUCCESS .%x----------------\r\n", crc);
- }
- else
- {
- PAIR_CHARGERPIN_PRINT("CRC ERROR .%x\r\n", crc);
- delay_ledon_count = 0;
- PAIR_CHARGERPIN_PRINT("delay_ledon_count 4= 0;\r\n", txrxcount);
- }
- for (int i = 0; i < DATA_LENGTH; i++)
- {
- PAIR_CHARGERPIN_PRINT("rxbuf[%d].%x\r\n",i, rxbuf[i]);
- }
- }
- txrxcount++;
- break;
- case 4:
- if (nrf_gpio_pin_read(PIN_CHARGING))
- {
- value++;
- }
- else
- {
- value--;
- }
- if (mFlash.isHost)
- {
- if (txrxcount == 0)
- {
- value = 0;
- nrf_gpio_pin_set(PIN_CHARGING);
- PAIR_CHARGERPIN_PRINT("set.%d\r\n", ms);
- }
- if (txrxcount == 3 * BITWIDTH)
- {
- nrf_gpio_pin_clear(PIN_CHARGING);
- PAIR_CHARGERPIN_PRINT("clear.%d\r\n", delay_ledon_count);
- }
- if (txrxcount >= 3 * BITWIDTH + LOW_BIT_DELAY)
- {
- value = 0;
- one_ms_status = 1;
- now_bit = 0;
- bit_width = 0;
- }
- }
- else
- {
- if (txrxcount == 0)
- {
- value = 0;
- }
- if (txrxcount > 3 * BITWIDTH)
- {
- if (value < 2 * BITWIDTH)
- {
- PAIR_CHARGERPIN_PRINT("CHECK ERROR .%d\r\n", txrxcount);
- delay_ledon_count = 0;
- PAIR_CHARGERPIN_PRINT("delay_ledon_count 5= 0;\r\n", txrxcount);
- }
- else
- {
- PAIR_CHARGERPIN_PRINT("CHECK DONE .%d\r\n", txrxcount);
- }
- value = 0;
- one_ms_status = 1;
- nrf_gpio_pin_clear(PIN_CHARGING);
- PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
- now_bit = 1;
- bit_width = 0;
- }
- }
- txrxcount++;
- break;
- }
- if (delay_ledon_count != 0)
- {
- delay_ledon_count++;
- }
- if (delay_ledon_count == DELAY_LEDON)
- {
- PAIR_CHARGERPIN_PRINT("LEDCOPEN.%d\r\n", ms);
- memcpy(savebuf,rxbuf,DATA_LENGTH-1);
- writefig=1;
- }
- if ((delay_ledon_count > DELAY_LEDON )
- && (delay_ledon_count - DELAY_LEDON == LEDON_KEEP))
- {
- delay_ledon_count = 0;
- PAIR_CHARGERPIN_PRINT("delay_ledon_count 6= 0;\r\n", txrxcount);
- PAIR_CHARGERPIN_PRINT("LEDCLOSE.%d\r\n", ms);
- }
- }
- void pair_led_pcs(void)
- {
- leddisplay_count++;
- if(leddisplay_count%2==0)
- {
- LED_Start(LED_PAIR,COLOR_BLACK);
- }
- else
- {
- LED_Start(LED_PAIR,COLOR_WHITE);
- }
- if(leddisplay_count>20)
- {
- leddisplay_count=0;
- LED_Stop(LED_PAIR);
- Process_SetHoldOn(pair_led_pcs,0);
- Process_Stop(pair_led_pcs);
- }
- }
- void stop_pair_led(void)
- {
- if(leddisplay_count==0)return;
- LED_Start(LED_PAIR,COLOR_BLACK);
- Process_SetHoldOn(pair_led_pcs,0);
- Process_Stop(pair_led_pcs);
- leddisplay_count=0;
- }
- PAIR_START_REGISTER(stop_pair_led);
- void mtrun(void)
- {
- MT_Run(200);
- }
- PAIR_START_REGISTER(mtrun);
- //写配对相关的flish
- static int pair_writeflish(unsigned char* macAddr_L, unsigned char* macAddr_R)
- {
- uint8_t offest =0;
- if(mFlash.isHost){offest =3;}
-
- if (memcmp(macAddr_R, mFlash.mClient.macAddr+offest, 3) != 0)
- {
- goto writein;
- }
- if (mFlash.mClient.isConfig != 'C')
- {
- goto writein;
- }
- PAIR_CHARGERPIN_PRINT("mFlash.mClient.isConfig:%X\n", mFlash.mClient.isConfig);
- PAIR_CHARGERPIN_PRINT("mFlash.mClient.macAddr:%02X %02X %02X\n", mFlash.mClient.macAddr[0], mFlash.mClient.macAddr[1], mFlash.mClient.macAddr[2]);
- PAIR_CHARGERPIN_PRINT("mFlash.macHost:%02X %02X %02X\n", mFlash.macHost[0], mFlash.macHost[1], mFlash.macHost[2]);
- return 0;
- writein:
- mFlash.mClient.isConfig = 'C';
- uint8_t i=0;
- for (i = 0; i < 6; i++){mFlash.macHost[i] = macAddr_L[i];}
-
- for (i = 0; i < 3; i++)
- mFlash.mClient.macAddr[i+offest] = macAddr_R[i]; //从机自身mac地址
-
- //保存数据到备份区域里面
- for( i=0; i<RecordMacAddrL; i++){
- mBackup.macAddr_L[i] = mFlash.macHost[i]; //主机地址
- mBackup.macAddr_R[i] = mFlash.mClient.macAddr[i];//从机地址
- }
-
- mBackup.hardVersion = mFlash.mClient.hardVersion;
- mBackup.sotfVersion = mFlash.mClient.sotfVersion;
- mBackup.isConfig = mFlash.mClient.isConfig;
-
- if(Flash_SaveBackup() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Pair,"pair save backup fail");
-
- DEBUG_LOG("mFlash.mClient.isConfig:%X\n", mFlash.mClient.isConfig);
- DEBUG_LOG("mFlash.mClient.macAddr:%02X %02X %02X\n", mFlash.mClient.macAddr[0], mFlash.mClient.macAddr[1], mFlash.mClient.macAddr[2]);
- DEBUG_LOG("mFlash.macHost:%02X %02X %02X \n", mFlash.macHost[0], mFlash.macHost[1], mFlash.macHost[2]);
- if(Flash_DeleteAllStep() != ZONE_OP_SUCCESS){Except_TxError(EXCEPT_Pair,"pair clear step fail");return 0;}
- memset(&mFlash.mStep,0,sizeof(FlashStep_t));
- if(Flash_SaveInfomation() != ZONE_OP_SUCCESS){Except_TxError(EXCEPT_Pair,"Flash_SaveInfomation fail");return 0;}
- return 1;
- }
- static void load_adv_name_from_flish(void)
- {
- char buf[16];
- memset(buf, 0, sizeof(buf));
- advertising_stop();
- sprintf(buf, "%02X%02X%02X%02X%02X%02X", mFlash.mClient.macAddr[0],mFlash.mClient.macAddr[1],mFlash.mClient.macAddr[2],mFlash.macHost[3],mFlash.macHost[4],mFlash.macHost[5]);
- DEBUG_LOG("advName(%d):%s\n", strlen(buf), buf);
- slave_set_adv_name(buf, strlen(buf));
- slave_adv_init();
- }
- static void load_scan_name_from_flish(void)
- {
- char buf[16];
- memset(buf, 0, sizeof(buf));
- sprintf(buf, "%02X%02X%02X%02X%02X%02X", mFlash.macHost[0], mFlash.macHost[1], mFlash.macHost[2], mFlash.mClient.macAddr[3], mFlash.mClient.macAddr[4], mFlash.mClient.macAddr[5]);
- DEBUG_LOG("scanName1(%d):%s\n", strlen(buf), buf);
- host_set_scan_name(buf, strlen(buf));
- }
- static unsigned char reconnect_pcs_status=0;
- static void reconnect_pcs(void)
- {
- switch(reconnect_pcs_status)
- {
- case 0:
- if(mFlash.isHost)
- {
- reconnect_pcs_status=1;
- if(host_isconnect()==1)host_disconnect();
- }
- else
- {
- reconnect_pcs_status=2;
- if(slave_isconnect()==1)slave_disconnect();
- }
- break;
- case 1:
- if(host_isconnect()==0)
- {
- load_scan_name_from_flish();
- scan_start();
- reconnect_pcs_status=4;
- }
- break;
- case 2:
- if(slave_isconnect()==0)
- {
- load_adv_name_from_flish();
- advertising_start();
- reconnect_pcs_status=4;
- }
- break;
- case 4:
- Process_SetHoldOn(reconnect_pcs,0);
- Process_Stop(reconnect_pcs);
- reconnect_pcs_status=5;
- leddisplay_count =0;
- Process_Start(500,"pair_led_pcs",pair_led_pcs);
- Process_SetHoldOn(pair_led_pcs,1);
- break;
- case 5:
-
- break;
- }
- }
- static void app_pair_chargerpin_pcs(void)
- {
- int rev=0;
- if(writefig==1)
- {
- unsigned char Lbuff[6];
- unsigned char Rbuff[3];
- Get_MACaddr(Lbuff);
- Rbuff[0]=savebuf[0];Rbuff[1]=savebuf[1];Rbuff[2]=savebuf[2];
- rev=pair_writeflish(Lbuff,Rbuff);
-
- if(rev)
- {
- Process_Start(10,"reconnect_pcs",reconnect_pcs);
- Process_SetHoldOn(reconnect_pcs,1);
- reconnect_pcs_status=0;
- }
- else
- {
- leddisplay_count =0;
- Process_Start(500,"pair_led_pcs",pair_led_pcs);
- Process_SetHoldOn(pair_led_pcs,1);
- }
- writefig=0;
- }
- }
- void pair_start_pcs(void)
- {
- extern void *pair_start$$Base;
- extern void *pair_start$$Limit;
- typedef void (*main_init_t)(void);
- for (int p = (unsigned int)&pair_start$$Base; p < (unsigned int)&pair_start$$Limit; p += 4)
- {
- (*(main_init_t *)p)();
- }
- }
- void pair_done_pcs(void)
- {
- extern void *pair_done$$Base;
- extern void *pair_done$$Limit;
- typedef void (*main_init_t)(void);
- for (int p = (unsigned int)&pair_done$$Base; p < (unsigned int)&pair_done$$Limit; p += 4)
- {
- (*(main_init_t *)p)();
- }
- }
- typedef enum
- {
- CHARGE=0,
- CONNECT_NO_CHARGE,
- DISCONNECT_CHARGE,
- }pair_line_t;
- #define ADC_CHECKMS 1000
- #define DELAY_PAIR_COUNT 100
- void null_pcs(void)
- {
- }
- short left_adc_value=0;
- void adc_cab(short adc_value)
- {
- left_adc_value=adc_value;
- adc_check();
-
- PAIR_CHARGERPIN_PRINT("ADC_Read_CallBack_Once call -%d\n",adc_value);
-
- }
- unsigned int pulluppcs_timer=0;
- void tim_read_cb(void *t)
- {
- if(TIME_GetTicks()-pulluppcs_timer>=3)
- {
- PAIR_CHARGERPIN_PRINT("tim_read_cb 3ms \n",mFlash.isHost);
- if(ADC_OP_SUCCESS!=ADC_Read_CallBack_Once(PIN_CHARGING_CHANNEL,adc_cab))
- {
- adc_check();
- PAIR_CHARGERPIN_PRINT("adc_check init \n",mFlash.isHost);
- }
- Process_Stop(null_pcs);
- TIME_UnRegist(tim_read_cb);
- }
- }
- static pair_line_t pair_line = DISCONNECT_CHARGE;
- //#include "queue.h"
- //extern queue_t Delegate;
- static short Left_adc=0;
- char pingup=0;
- void Delegate_up_pin(void *t)
- {
- unsigned int count=TIME_GetTicks()-pulluppcs_timer;
- if(count<3)
- {
- return;
- }
- if(count==3)
- {
- uint32_t errcode = ADC_ReadChargePin(PIN_CHARGING_CHANNEL);
- }
- else if((count>3)&&(count<300))
- {
- unsigned char state = bsp_Get_ChargePinADC(&Left_adc);
- if(state){
- TIME_UnRegist(Delegate_up_pin);
- Process_Stop(null_pcs);
- PAIR_CHARGERPIN_PRINT("Delegate_up_pin %d\n",mFlash.isHost);
- adc_check();
- }
- }
- else
- {
- PAIR_CHARGERPIN_PRINT("------------------------------adc overtime error -------------------\n",mFlash.isHost);
- }
- }
- extern short ChargeADC_value;
- void adc_check(void)
- {
- static unsigned char status=0;
- short ADC_value=0;
-
- static unsigned int delay_pair_count=0;
- static unsigned int overtime=0;
- static unsigned char ishost;
- switch(status)
- {
- case 0:
- ishost=mFlash.isHost;
- ADC_Disable();
- ADC_SetPinChannel(PIN_CHARGING,PIN_CHARGING_CHANNEL,NRF_GPIO_PIN_NOPULL);
- ADC_Initialize();
- Process_UpdatePeroid(adc_check,ADC_CHECKMS);
- Process_SetHoldOn(adc_check,0);
- nrf_gpio_pin_write(PIN_LED_RUN, 0);
- pair_done_pcs();
- status=1;
- break;
- case 1:
- if(ishost!=mFlash.isHost)
- {
- status=0;
- PAIR_CHARGERPIN_PRINT("mFlash.isHost change %d\n",mFlash.isHost);
- }
-
- if(mFlash.isHost)
- {
- if(pingup==0)
- {
- pingup=1;
- nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_PULLUP);
- pulluppcs_timer = TIME_GetTicks();
- Process_Start(0,"null_pcs",null_pcs);
- Process_SetHoldOn(null_pcs,1);
- TIME_Regist(Delegate_up_pin);
- return;
- }
- else
- {
- ADC_value=Left_adc;
- nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_NOPULL);
- pingup=0;
- }
- }
- if(mFlash.isHost==0){
- if(ADC_OP_SUCCESS!=ADC_Read(PIN_CHARGING_CHANNEL,&ADC_value))
- {
- PAIR_CHARGERPIN_PRINT("ADC_Read ERROR %d\n",mFlash.isHost);
- }
- }
-
- PAIR_CHARGERPIN_PRINT( "ADC ( %d ):isHost %d pair_line %d\n", ADC_value,mFlash.isHost,pair_line);
- ChargeADC_value = ADC_value;
-
- if((ADC_value<CHARGE_ADC)&&(pair_line == CHARGE)&&(mFlash.isHost))
- {
- // Process_Stop(charge_uppin_pcs);
- PAIR_CHARGERPIN_PRINT("--------------------------------------------------------EXIT CHARGE_ADC \n");
- }
-
- if(ADC_value>=CHARGE_ADC)
- {
- PAIR_CHARGERPIN_PRINT(" CHARGE_ADC \n");
- if((pair_line != CHARGE)&&(mFlash.isHost))
- {
- PAIR_CHARGERPIN_PRINT("--------------------------------------------------------------------INTO CHARGE_ADC \n");
- // Process_Start(ADC_CHECKMS,"charge_uppin_pcs",charge_uppin_pcs);
- }
- pair_line=CHARGE;
- }
- else if((ADC_value>=CONN_MIN_ADC)&&(ADC_value<=CONN_MAX_ADC)&&(mFlash.isHost==0))
- {
- PAIR_CHARGERPIN_PRINT(" CONN_ADC %d \n",pair_line);
- connect:
- if(pair_line!=CONNECT_NO_CHARGE)
- {
- PAIR_CHARGERPIN_PRINT(" Process_SetHoldOn(adc_check,1); ms %d\n",TIME_GetTicks());
-
- if(mFlash.isHost)Process_Start(ADC_CHECKMS,"adc_check",adc_check);
-
- Process_UpdatePeroid(adc_check,10);
- Process_SetHoldOn(adc_check,1);
- overtime=TIME_GetTicks();
- pair_start_pcs();
-
- if(mFlash.isHost)
- {
- status=2;
- nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_PULLUP);
- delay_pair_count=TIME_GetTicks();
- PAIR_CHARGERPIN_PRINT(" SEND PAIR TAG HIGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH; %d \n",TIME_GetTicks());
- }
- else
- {
- status=5;
- TIME_Regist(chargerpin_one_ms_pcs);
- one_ms_status = 0;
- }
- }
- pair_line=CONNECT_NO_CHARGE;
- }
- else
- {
- if(mFlash.isHost)
- {
- if((ADC_value<=DISCON_L_MAX_ADC)&&(ADC_value>=DISCON_L_MIN_ADC))
- {
- PAIR_CHARGERPIN_PRINT("L DISCON_L_ADC \n");
- pair_line=DISCONNECT_CHARGE;
- }
- else if((ADC_value<=CON_L_MAX_ADC)&&(ADC_value>=CON_L_MIN_ADC))
- {
- PAIR_CHARGERPIN_PRINT("L CON_L_MAX_ADC \n");
- goto connect;
- }
- }
- else
- {
- if(ADC_value<=DISCON_R_MAX_ADC)
- {
- PAIR_CHARGERPIN_PRINT("R DISCON_R_MAX_ADC \n");
- pair_line=DISCONNECT_CHARGE;
- }
- }
- }
- break;
- case 2://
- if(TIME_GetTicks()- delay_pair_count > ADC_CHECKMS)
- {
- TIME_Regist(chargerpin_one_ms_pcs);
- one_ms_status = 0;
- status=3;
- PAIR_CHARGERPIN_PRINT(" TIME_Regist(chargerpin_one_ms_pcs); %d \n",TIME_GetTicks());
- }
- break;
- case 3:
- if(TIME_GetTicks()- delay_pair_count > DELAY_PAIR_COUNT)
- {
- nrf_gpio_pin_set(PIN_CHARGING);
- PAIR_CHARGERPIN_PRINT(" SEND PAIR TAG HIG; %d \n",TIME_GetTicks());
- status=4;
- }
- break;
- case 4:
- if(TIME_GetTicks()- delay_pair_count>(DELAY_PAIR_COUNT+100))
- {
- nrf_gpio_pin_clear(PIN_CHARGING);
- PAIR_CHARGERPIN_PRINT(" SEND PAIR TAG LOW; %d \n",TIME_GetTicks());
- status=5;
- }
- break;
- case 5:
- if(writefig==1)
- {
- app_pair_chargerpin_pcs();
- TIME_UnRegist(chargerpin_one_ms_pcs);
- status=0;
- MT_Run(500);
- PAIR_CHARGERPIN_PRINT(" ---------------------------PAIR SUCESS------------- \n");
- }
- if(TIME_GetTicks()-overtime > DELAY_LEDON+ADC_CHECKMS + DELAY_PAIR_COUNT + 100 + 300)
- {
- LED_Stop(LED_PAIR);
- TIME_UnRegist(chargerpin_one_ms_pcs);
- status=0;
- PAIR_CHARGERPIN_PRINT(" ---------------------------PAIR OVER TIME %d------------- \n",TIME_GetTicks());
- }
- break;
- }
- }
- void write_on(void)
- {
- LED_Start(LED_PAIR,COLOR_WHITE);
- }
- PAIR_START_REGISTER(write_on);
- void app_pair_chargerpin_Init(void)
- {
- Process_Start(ADC_CHECKMS,"adc_check",adc_check);
- }
|