123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- #include "global.h"
- #if (LOCAL_INPUT_BITS_NUMBER < IO_PIN_INPUT_NUMBER)
- #undef LOCAL_INPUT_BITS_NUMBER
- #define LOCAL_INPUT_BITS_NUMBER IO_PIN_INPUT_NUMBER
- #endif
- #if (LOCAL_OUTPUT_BITS_NUMBER < IO_PIN_OUTPUT_NUMBER)
- #undef LOCAL_OUTPUT_BITS_NUMBER
- #define LOCAL_OUTPUT_BITS_NUMBER IO_PIN_OUTPUT_NUMBER
- #endif
- #define IO_FILTER_H 10 //IO滤波高通计数
- #define IO_FILTER_L 2 //IO滤波低通计数
- #define IO_FILTER_JIFTTER 1000 //IO滤波间隔,单位是微秒
- int io_inputs_buffer[IO_PIN_INPUT_NUMBER];
- //#if USE_EXTEND_INOUTPUT
- byte_bits_t io_inputs[(LOCAL_INPUT_BITS_NUMBER + EXTEND_IO_INPUT_NUMBER + 7)>> 3];
- byte_bits_t io_inputs_old[(LOCAL_INPUT_BITS_NUMBER + EXTEND_IO_INPUT_NUMBER + 7)>> 3];
- byte_bits_t io_outputs[(LOCAL_OUTPUT_BITS_NUMBER + EXTEND_IO_OUTPUT_NUMBER + 7)>> 3];
- //#else
- //byte_bits_t io_inputs[(LOCAL_INPUT_BITS_NUMBER + 7)>> 3];
- //byte_bits_t io_inputs_old[(LOCAL_INPUT_BITS_NUMBER + 7)>> 3];
- //byte_bits_t io_outputs[(LOCAL_OUTPUT_BITS_NUMBER + 7)>> 3];
- //#endif
- 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()
- if(1)//(index != 14) || (JIAO_YA_DIN_CUN_CONFIG == 0))
- {
- 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));
- }
- }
- else
- {
- 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, (IO_PIN_INPUT_NUMBER+7)>>3);
- }
- /**
- * 主动输出
- *
- * @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, (IO_PIN_OUTPUT_NUMBER+7)>>3);
- }
- 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++ > 25)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 15:
- Y16 = 1;
- break;
- case 16:
- Y17 = 1;
- break;
- case 17:
- Y20 = 1;
- break;
- case 18:
- Y21 = 1;
- break;
- case 19:
- Y22 = 1;
- break;
- case 20:
- Y23 = 1;
- break;
- case 21:
- Y24 = 1;
- break;
- case 22:
- Y25 = 1;
- break;
- case 23:
- Y26 = 1;
- break;
- case 24:
- Y27 = 1;
- break;
- case 25:
- Y30 = 1;
- break;
-
- }
- }
- else
- {
- Y00 = X00 | X23;
- Y01 = X01;
- Y02 = X02;
- Y03 = X03;
- Y04 = X04;
- Y05 = X05;
- Y06 = X06;
- Y07 = X07;
- Y10 = X10;
- Y11 = X11;
- Y12 = X12;
- Y13 = X13;
- Y14 = X14;
- Y15 = X15;
- Y16 = X16;
- Y17 = X17;
- Y20 = X20;
- Y21 = X21;
- Y22 = X22;
-
-
- Y23 = X24 | X32;
- Y24 = X25 | X33;
- Y25 = X26;
- Y26 = X27;
- Y27 = X30;
- Y30 = X31;
- index = 30;
- }
- 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
- }
- /**
- * IO应用行函数执
- *
- * @author lxz (2019/5/29/周三)
- */
- static sw_timer_t iotimer;
- #define TEST_APP
- void io_app_run(void) {
- int index = 0;
- #ifdef TEST_APP
- int flag = 0;
- static int status = 1;
-
- for (index = 0; index<(LOCAL_INPUT_BITS_NUMBER + 6 + 7)>> 3; index++)
- {
- io_outputs[index].bytes[0] = io_inputs[index].bytes[0];
- flag += io_inputs[index].bytes[0];
- }
- if(flag == 0)
- {
- if (sw_timer_expire(&iotimer)) {
- status <<= 1;
- sw_timer_start(&iotimer, 0, 500000);
- }
- if(status==0x2000000) status=1;
- io_outputs[0].bytes[0] = status;
- io_outputs[1].bytes[0] = status>>8;
- io_outputs[2].bytes[0] = status>>16;
- io_outputs[3].bytes[0] = status>>24;
- }
- else {
- sw_timer_start(&iotimer, 0, 500000);
- }
- #else
- for (index = 0; index<(LOCAL_OUTPUT_BITS_NUMBER + 7)>> 3; index++) {
- if (middle_coils[(200 >> 3) + index].bytes[0] != 0) {
- io_outputs[index].bytes[0] ^= middle_coils[(200 >> 3) + index].bytes[0];
- middle_coils[(200 >> 3) + index].bytes[0] = 0;
- }
- }
- #endif
- }
|