123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- #include "global.h"
- #define IO_FILTER_H 10 //IO滤波高通计数
- #define IO_FILTER_L 10 //IO滤波低通计数
- #define IO_FILTER_JIFTTER 1000 //IO滤波间隔,单位是微秒
- int io_inputs_buffer[IO_PIN_INPUT_NUMBER];
- byte_bits_t io_inputs[(INPUT_NUMBER + 7)>> 3];
- byte_bits_t io_inputs_old[(INPUT_NUMBER + 7)>> 3];
- byte_bits_t io_outputs[(OUTPUT_NUMBER + 7)>> 3];
- static sw_timer_t filter_timer;
- /**
- * IO应用初始化函数
- *
- * @author lxz (2019/5/29/周三)
- */
- void io_app_init(void)
- {
- memset(io_inputs, 0, sizeof(io_inputs));
- memset(io_inputs_old, 0, sizeof(io_inputs_old));
- memset(io_outputs, 0, sizeof(io_outputs));
- sw_timer_start(&filter_timer, 0, 0);
- hw_io_output_disable();
- }
- /**
- * IO滤波输入
- *
- * @author lxz (2019/5/29/周三)
- */
- void io_app_read_input(void)
- {
- int index = 0;
- //读取输
- memcpy(io_inputs_old, io_inputs, sizeof(io_inputs));
- {
- //保存上一次的IO状态
- for (index = 0; index < IO_PIN_INPUT_NUMBER; index++)
- {
- //if((index != 14) || (JIAO_YA_DIN_CUN_CONFIG == 0))
- if(1)
- {
- if (hw_io_pin_input(index))
- {
- if (io_inputs_buffer[index] < IO_FILTER_H)
- {
- io_inputs_buffer[index]++;
- }
- else
- {
- io_inputs[index >> 3].bytes[0] |= 1 << (index & 0x07);
- }
- }
- else if (io_inputs_buffer[index] > IO_FILTER_L)
- {
- io_inputs_buffer[index]--;
- }
- else
- {
- io_inputs[index >> 3].bytes[0] &= ~(1 << (index & 0x07));
- }
- }
- }
- }
-
- //IO数据挂到通讯变量,其实这个也可以不这么干
- memcpy(&middle_coils[(160 + 7) >> 3], io_inputs, sizeof(io_inputs));
- }
- /**
- * 主动输出
- *
- * @author lxz (2019/5/29/周三)
- */
- void io_app_write_ouput(void)
- {
- int index = 0;
- for (index = 0; index < IO_PIN_OUTPUT_NUMBER; index++)
- {
- hw_io_pin_output(index, (io_outputs[index >> 3].bytes[0] & (1 << (index & 0x07))) != 0);
- }
- //IO数据挂到通讯变量,其实这个也可以不这么干
- memcpy(&middle_coils[(240 + 7) >> 3], io_outputs, sizeof(io_outputs));
- }
- void InitTestAction(void)
- {
- user_datas[256] = 0;
- }
- unsigned char JiaoYan(void)
- {
- unsigned short i;
- for(i=0;i<127;i++)
- {
- if(GetData32bits(i*2) != i)
- {
- user_datas[256] = 0;
- return 0;
- }
- }
- return 1;
- }
- /**
- * IO应用行函数执
- *
- * @author lxz (2019/5/29/周三)
- */
- void TestAction(void)
- {
- #if TESTACITON_CONFIG
- static unsigned long dwOutTime = 0,dwMotorTime;
- static unsigned char index = 0;
- unsigned short i;
- if(dwTickCount > dwOutTime)
- {
- dwOutTime = dwTickCount + 200;
- if(index++ > 27)index = 0;
- }
-
- if(dwTickCount >= dwMotorTime)
- {
- if(X_DRV)
- {
- AxisDecStop(X_AXIS);
- }
- else
- {
- if(GetDir(X_AXIS))
- {
- AxisContinueMove(X_AXIS,20,0);
- dwMotorTime = dwTickCount + 1000;
- }
- else
- {
- AxisContinueMove(X_AXIS,20,1);
- dwMotorTime = dwTickCount + 1000;
- }
- }
- }
-
- if((io_inputs[0].value == 0) && (io_inputs[1].value == 0) && (io_inputs[2].value == 0) && (io_inputs[3].value == 0) && (io_inputs[4].value == 0))
- {
- switch(index)
- {
- case 0:
- io_outputs[0].value = 0;
- io_outputs[1].value = 0;
- io_outputs[2].value = 0;
- io_outputs[3].value = 0;
- break;
- case 1:
- Y00 = 1;
- break;
- case 2:
- Y01 = 1;
- break;
- case 3:
- Y02 = 1;
- break;
- case 4:
- Y03 = 1;
- break;
- case 5:
- Y04 = 1;
- break;
- case 6:
- Y05 = 1;
- break;
- case 7:
- Y06 = 1;
- break;
- case 8:
- Y07 = 1;
- break;
- case 9:
- Y10 = 1;
- break;
- case 10:
- Y11 = 1;
- break;
- case 11:
- Y12 = 1;
- break;
- case 12:
- Y13 = 1;
- break;
- case 13:
- Y14 = 1;
- break;
- case 14:
- Y15 = 1;
- break;
- case 16:
- Y20 = 1;
- break;
- case 17:
- Y21 = 1;
- break;
- case 18:
- Y22 = 1;
- break;
- case 19:
- Y23 = 1;
- break;
- case 20:
- Y24 = 1;
- break;
- case 21:
- Y25 = 1;
- break;
- case 22:
- Y26 = 1;
- break;
- case 23:
- Y27 = 1;
- break;
- case 24:
- Y30 = 1;
- break;
- case 25:
- Y31 = 1;
- break;
- case 26:
- Y32 = 1;
- break;
- case 27:
- Y33 = 1;
- break;
- case 28:
- Y34 = 1;
- break;
- }
- }
- else
- {
- Y00 = X00 | X16;
- Y01 = X01 | X17;
- Y02 = X02 | X20;
- Y03 = X03;
- Y04 = X04;
- Y05 = X05;
- Y06 = X06;
- Y07 = X07;
- Y10 = X10;
- Y11 = X11;
- Y12 = X12;
- Y13 = X13;
- Y14 = X14;
- Y15 = X15;
- Y20 = X30;
- Y21 = X31;
- Y22 = X32;
- Y23 = X33;
- Y24 = X34;
- Y25 = X35;
- Y26 = X36;
- Y27 = X37;
- Y30 = X40;
- Y31 = X41;
- Y32 = X42;
- Y33 = X30;
- Y34 = X31;
-
- }
-
-
- if(M0000)
- {
- M0000 = 0;
- for(i=0;i<127;i++)
- {
- SetData32bits(i*2,i);
- }
- user_datas[256] = 1;
- }
-
- if(M0001)
- {
- M0001 = 0;
- hw_flash_data_read(POWEROFF_BACKUP_ADDRESS, user_datas, POWEROFF_SAVE_BLOCK_SIZE);
- /* if(user_datas[256] != 1)
- {
- if(JiaoYan())
- {
- for(i=0;i<127;i++)
- {
- SetData32bits(i*2,0);
- }
- user_datas[256] = 2;
- }
- else
- {
- user_datas[256] = 0;
- }
- }*/
- }
- #endif
- }
|