![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
pissa pepper
myf401.cpp@0:a9ea0137c16b, 2018-04-20 (annotated)
- Committer:
- donghuoyinzi
- Date:
- Fri Apr 20 02:49:37 2018 +0000
- Revision:
- 0:a9ea0137c16b
pissa pepper
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donghuoyinzi | 0:a9ea0137c16b | 1 | //#include "mbedOS.h" |
donghuoyinzi | 0:a9ea0137c16b | 2 | #include "mbed.h" |
donghuoyinzi | 0:a9ea0137c16b | 3 | |
donghuoyinzi | 0:a9ea0137c16b | 4 | #include "myf401.h" |
donghuoyinzi | 0:a9ea0137c16b | 5 | |
donghuoyinzi | 0:a9ea0137c16b | 6 | #include "vector" |
donghuoyinzi | 0:a9ea0137c16b | 7 | int f401Act::f401cnt=0; |
donghuoyinzi | 0:a9ea0137c16b | 8 | int f401Act::datacnt=0; |
donghuoyinzi | 0:a9ea0137c16b | 9 | /******iwdg instance*********/ |
donghuoyinzi | 0:a9ea0137c16b | 10 | //IWDG_HandleTypeDef f401Act::hiwdg; //????? |
donghuoyinzi | 0:a9ea0137c16b | 11 | /******pc uart instance*********/ |
donghuoyinzi | 0:a9ea0137c16b | 12 | Serial f401Act::uart(DEBUG_TX, DEBUG_RX); //PA_9, PA_10 to pc debug |
donghuoyinzi | 0:a9ea0137c16b | 13 | /******led instance*********/ |
donghuoyinzi | 0:a9ea0137c16b | 14 | DigitalOut f401Act::led2(LED2); //PC_8 |
donghuoyinzi | 0:a9ea0137c16b | 15 | DigitalOut f401Act::led3(LED3); //PC_9 |
donghuoyinzi | 0:a9ea0137c16b | 16 | /**** time1 intance*****/ |
donghuoyinzi | 0:a9ea0137c16b | 17 | Ticker f401Act::time1; |
donghuoyinzi | 0:a9ea0137c16b | 18 | Ticker f401Act::timerone; |
donghuoyinzi | 0:a9ea0137c16b | 19 | Timer f401Act::outtime; |
donghuoyinzi | 0:a9ea0137c16b | 20 | |
donghuoyinzi | 0:a9ea0137c16b | 21 | extern string send_udp3; |
donghuoyinzi | 0:a9ea0137c16b | 22 | |
donghuoyinzi | 0:a9ea0137c16b | 23 | char f401Act::buf[512]={0x00}; |
donghuoyinzi | 0:a9ea0137c16b | 24 | char bufz[512]=""; |
donghuoyinzi | 0:a9ea0137c16b | 25 | /******************************* |
donghuoyinzi | 0:a9ea0137c16b | 26 | Desc.: f401pc initializations,include iwdg\system tick\key interrupt |
donghuoyinzi | 0:a9ea0137c16b | 27 | Auth.:ZY |
donghuoyinzi | 0:a9ea0137c16b | 28 | Vesion:2017.7.2 |
donghuoyinzi | 0:a9ea0137c16b | 29 | *******************************/ |
donghuoyinzi | 0:a9ea0137c16b | 30 | void f401Act::init(void) |
donghuoyinzi | 0:a9ea0137c16b | 31 | { |
donghuoyinzi | 0:a9ea0137c16b | 32 | /*******iwdg init*******/ |
donghuoyinzi | 0:a9ea0137c16b | 33 | //hiwdg.Instance=IWDG;//?? |
donghuoyinzi | 0:a9ea0137c16b | 34 | //hiwdg.Init.Prescaler=IWDG_PRESCALER_16;//??? 分频因子[4,8,16,32,64,128,256,256] |
donghuoyinzi | 0:a9ea0137c16b | 35 | //hiwdg.Init.Reload=4095;//??? 递减计数0~0XFFF |
donghuoyinzi | 0:a9ea0137c16b | 36 | //HAL_IWDG_Init(&hiwdg); //??? |
donghuoyinzi | 0:a9ea0137c16b | 37 | //set_time(1514806505);//自1970年1月1日0时0分0秒到2018年1月1日11时35分05秒 |
donghuoyinzi | 0:a9ea0137c16b | 38 | f401Act::time1.attach(&isr_tick,1.0); //定时器中断设置 |
donghuoyinzi | 0:a9ea0137c16b | 39 | f401Act::timerone.attach_us(&isr_tick1,1000); //定时器中断配置 |
donghuoyinzi | 0:a9ea0137c16b | 40 | } |
donghuoyinzi | 0:a9ea0137c16b | 41 | |
donghuoyinzi | 0:a9ea0137c16b | 42 | /***************************************** |
donghuoyinzi | 0:a9ea0137c16b | 43 | Desc.: pc ready |
donghuoyinzi | 0:a9ea0137c16b | 44 | Auth.:ZY |
donghuoyinzi | 0:a9ea0137c16b | 45 | Vesion:2017.7.2 |
donghuoyinzi | 0:a9ea0137c16b | 46 | *****************************************/ |
donghuoyinzi | 0:a9ea0137c16b | 47 | void f401Act::ready(void) |
donghuoyinzi | 0:a9ea0137c16b | 48 | { |
donghuoyinzi | 0:a9ea0137c16b | 49 | uart.baud(9600); |
donghuoyinzi | 0:a9ea0137c16b | 50 | uart.attach(&isr_pc,SerialBase::RxIrq); |
donghuoyinzi | 0:a9ea0137c16b | 51 | } |
donghuoyinzi | 0:a9ea0137c16b | 52 | |
donghuoyinzi | 0:a9ea0137c16b | 53 | /***************************************** |
donghuoyinzi | 0:a9ea0137c16b | 54 | Desc.: pc get |
donghuoyinzi | 0:a9ea0137c16b | 55 | Auth.:ZY |
donghuoyinzi | 0:a9ea0137c16b | 56 | Vesion:2017.7.2 |
donghuoyinzi | 0:a9ea0137c16b | 57 | *****************************************/ |
donghuoyinzi | 0:a9ea0137c16b | 58 | void f401Act::get(void) |
donghuoyinzi | 0:a9ea0137c16b | 59 | { |
donghuoyinzi | 0:a9ea0137c16b | 60 | uart.putc(0x31); //接受母钟数据请求(协议) |
donghuoyinzi | 0:a9ea0137c16b | 61 | wait_ms(500); |
donghuoyinzi | 0:a9ea0137c16b | 62 | //for(int i=0;i<datacnt;i++) bufCom[i]=buf[i]; |
donghuoyinzi | 0:a9ea0137c16b | 63 | //for(int i=0;i<datacnt;i++){ |
donghuoyinzi | 0:a9ea0137c16b | 64 | //uart.putc(buf[i]); |
donghuoyinzi | 0:a9ea0137c16b | 65 | //buf[i]=0; |
donghuoyinzi | 0:a9ea0137c16b | 66 | //} |
donghuoyinzi | 0:a9ea0137c16b | 67 | F401script::poC_getS=1; |
donghuoyinzi | 0:a9ea0137c16b | 68 | } |
donghuoyinzi | 0:a9ea0137c16b | 69 | |
donghuoyinzi | 0:a9ea0137c16b | 70 | /***************************************** |
donghuoyinzi | 0:a9ea0137c16b | 71 | Desc.: 呼叫母钟,五次 |
donghuoyinzi | 0:a9ea0137c16b | 72 | Auth.:ZY |
donghuoyinzi | 0:a9ea0137c16b | 73 | Vesion:2017.7.2 |
donghuoyinzi | 0:a9ea0137c16b | 74 | *****************************************/ |
donghuoyinzi | 0:a9ea0137c16b | 75 | void f401Act::put_call(void) |
donghuoyinzi | 0:a9ea0137c16b | 76 | { |
donghuoyinzi | 0:a9ea0137c16b | 77 | outtime.start(); |
donghuoyinzi | 0:a9ea0137c16b | 78 | outtime.reset(); |
donghuoyinzi | 0:a9ea0137c16b | 79 | while(F401script::poC_isrS==0||outtime.read_ms()<=50){ |
donghuoyinzi | 0:a9ea0137c16b | 80 | uart.putc(0x53); |
donghuoyinzi | 0:a9ea0137c16b | 81 | wait_ms(1); |
donghuoyinzi | 0:a9ea0137c16b | 82 | } |
donghuoyinzi | 0:a9ea0137c16b | 83 | outtime.stop(); |
donghuoyinzi | 0:a9ea0137c16b | 84 | if(F401script::poC_isrS==1){ |
donghuoyinzi | 0:a9ea0137c16b | 85 | F401script::poC_isrS=0; |
donghuoyinzi | 0:a9ea0137c16b | 86 | |
donghuoyinzi | 0:a9ea0137c16b | 87 | F401script::poC_putcallS=1; |
donghuoyinzi | 0:a9ea0137c16b | 88 | } |
donghuoyinzi | 0:a9ea0137c16b | 89 | } |
donghuoyinzi | 0:a9ea0137c16b | 90 | |
donghuoyinzi | 0:a9ea0137c16b | 91 | /***************************************** |
donghuoyinzi | 0:a9ea0137c16b | 92 | Desc.:reflesh iwdg |
donghuoyinzi | 0:a9ea0137c16b | 93 | Auth.:ZY |
donghuoyinzi | 0:a9ea0137c16b | 94 | Vesion:2017.7.2 |
donghuoyinzi | 0:a9ea0137c16b | 95 | *****************************************/ |
donghuoyinzi | 0:a9ea0137c16b | 96 | //void f401Act::reiwdg(void) |
donghuoyinzi | 0:a9ea0137c16b | 97 | //{ |
donghuoyinzi | 0:a9ea0137c16b | 98 | //HAL_IWDG_Refresh(&hiwdg); //???? //reflesh iwdg |
donghuoyinzi | 0:a9ea0137c16b | 99 | //} |
donghuoyinzi | 0:a9ea0137c16b | 100 | void f401Act::isr_tick(void) |
donghuoyinzi | 0:a9ea0137c16b | 101 | { |
donghuoyinzi | 0:a9ea0137c16b | 102 | F401script::poC_ticisrS=1; |
donghuoyinzi | 0:a9ea0137c16b | 103 | |
donghuoyinzi | 0:a9ea0137c16b | 104 | } |
donghuoyinzi | 0:a9ea0137c16b | 105 | /***************************************** |
donghuoyinzi | 0:a9ea0137c16b | 106 | Desc.: system ticker ISR |
donghuoyinzi | 0:a9ea0137c16b | 107 | Auth.:ZY |
donghuoyinzi | 0:a9ea0137c16b | 108 | Vesion:2017.7.2 |
donghuoyinzi | 0:a9ea0137c16b | 109 | *****************************************/ |
donghuoyinzi | 0:a9ea0137c16b | 110 | void f401Act::isr_tick1(void) |
donghuoyinzi | 0:a9ea0137c16b | 111 | { |
donghuoyinzi | 0:a9ea0137c16b | 112 | if(F401script::poC_step>0) F401script::poC_step--; |
donghuoyinzi | 0:a9ea0137c16b | 113 | |
donghuoyinzi | 0:a9ea0137c16b | 114 | if(F401script::poC_step==1){ |
donghuoyinzi | 0:a9ea0137c16b | 115 | datacnt=f401cnt; //获取数据个数 |
donghuoyinzi | 0:a9ea0137c16b | 116 | send_udp3.clear(); |
donghuoyinzi | 0:a9ea0137c16b | 117 | //for(int i=0;i<f401cnt;i++) send_udp3.push_back(buf[i]); |
donghuoyinzi | 0:a9ea0137c16b | 118 | send_udp3=bufz; |
donghuoyinzi | 0:a9ea0137c16b | 119 | f401cnt=0; //数据缓存个数清零 |
donghuoyinzi | 0:a9ea0137c16b | 120 | memset(bufz,0,sizeof(buf)); |
donghuoyinzi | 0:a9ea0137c16b | 121 | memset(buf,0,sizeof(buf)); |
donghuoyinzi | 0:a9ea0137c16b | 122 | } |
donghuoyinzi | 0:a9ea0137c16b | 123 | } |
donghuoyinzi | 0:a9ea0137c16b | 124 | /***************************************** |
donghuoyinzi | 0:a9ea0137c16b | 125 | Desc.: pc getc ISR |
donghuoyinzi | 0:a9ea0137c16b | 126 | Auth.:ZY |
donghuoyinzi | 0:a9ea0137c16b | 127 | Vesion:2017.7.2 |
donghuoyinzi | 0:a9ea0137c16b | 128 | *****************************************/ |
donghuoyinzi | 0:a9ea0137c16b | 129 | void f401Act::isr_pc(void) |
donghuoyinzi | 0:a9ea0137c16b | 130 | { |
donghuoyinzi | 0:a9ea0137c16b | 131 | F401script::poC_step=20; //计时3ms |
donghuoyinzi | 0:a9ea0137c16b | 132 | char bufx; |
donghuoyinzi | 0:a9ea0137c16b | 133 | char bufy[40]=""; |
donghuoyinzi | 0:a9ea0137c16b | 134 | bufx=uart.getc(); |
donghuoyinzi | 0:a9ea0137c16b | 135 | buf[f401cnt]=bufx; |
donghuoyinzi | 0:a9ea0137c16b | 136 | sprintf(bufy,"%02X",bufx); |
donghuoyinzi | 0:a9ea0137c16b | 137 | strcat(bufz,bufy); |
donghuoyinzi | 0:a9ea0137c16b | 138 | //if(buf[0]==0x41) F401script::poC_isrS=1; //打印测试发送"AT+QWERTY=1" buf[10]=1 |
donghuoyinzi | 0:a9ea0137c16b | 139 | f401cnt++; |
donghuoyinzi | 0:a9ea0137c16b | 140 | if(f401cnt>512) f401cnt=0; //防止溢出 |
donghuoyinzi | 0:a9ea0137c16b | 141 | } |
donghuoyinzi | 0:a9ea0137c16b | 142 | |
donghuoyinzi | 0:a9ea0137c16b | 143 | |
donghuoyinzi | 0:a9ea0137c16b | 144 |