123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #include "io_app.h"
- #include "board.h"
- //#include "user_app.h"
- #include "variable.h"
- #include <string.h>
- #define INPUT_BITS_NUMBER 12
- #define OUTPUT_BITS_NUMBER 12
- #if (INPUT_BITS_NUMBER < IO_PIN_INPUT_NUMBER)
- #undef INPUT_BITS_NUMBER
- #define INPUT_BITS_NUMBER IO_PIN_INPUT_NUMBER
- #endif
- #if (OUTPUT_BITS_NUMBER < IO_PIN_OUTPUT_NUMBER)
- #undef OUTPUT_BITS_NUMBER
- #define OUTPUT_BITS_NUMBER IO_PIN_OUTPUT_NUMBER
- #endif
- #define IO_FILTER_H 2 //IO皛斗郭擃㗛�朞恣�?
- #define IO_FILTER_L 0 //IO皛斗郭雿𡡞�朞恣�?
- #define IO_FILTER_JIFTTER 1000 //IO皛斗郭�湧�嚗��雿齿糓敺桃�
- int io_inputs_buffer[IO_PIN_INPUT_NUMBER];
- byte_bits_t io_inputs[(INPUT_BITS_NUMBER + 7)>> 3];
- byte_bits_t io_inputs_old[(INPUT_BITS_NUMBER + 7)>> 3];
- byte_bits_t io_outputs[(OUTPUT_BITS_NUMBER + 7)>> 3];
- byte_bits_t io_outputsen;
- 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_enable();
- }
- /**
- * IO皛斗郭颲枏�
- *
- * @author lxz (2019/5/29/�其�)
- */
- void io_app_read_input(void) {
- int index = 0;
- memcpy(io_inputs_old, io_inputs, sizeof(io_inputs));
- if (bSoftwareInputEnable) { //頧臭辣颲枏�嚗諹��箔縑�瑞眏M0160撘�憪𧢲㺭�格𤜯隞?
- //IO�唳旿����朞悖�㗛�嚗��摰噼�銝芯��臭誑銝滩�銋�僕
- memcpy(io_inputs, &middle_coils[160 >> 3], sizeof(io_inputs));
- }
- else {
- //霂餃�颲枏�
- if (sw_timer_expire(&filter_timer)) {
- sw_timer_start(&filter_timer, 0, IO_FILTER_JIFTTER);
- //靽嘥�銝𠹺�甈∠�IO�嗆�?
- for (index = 0; index < IO_PIN_INPUT_NUMBER; index++) {
- if (hw_io_pin_input(index)) {
- if (io_inputs_buffer[index] < IO_FILTER_H) {
- io_inputs_buffer[index]++;
- }
- else {
- io_inputs[index >> 3].value |= 1 << (index & 0x07);
- }
- }
- else if (io_inputs_buffer[index] > IO_FILTER_L) {
- io_inputs_buffer[index]--;
- }
- else {
- io_inputs[index >> 3].value &= ~(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;
- if (bSoftwareOutputEnable) { //頧臭辣颲枏枂嚗諹��箔縑�瑞眏M0240撘�憪𧢲㺭�格𤜯隞?
- for (index = 0; index < IO_PIN_OUTPUT_NUMBER; index++) {
- hw_io_pin_output(index, (middle_coils[(240 + index) >> 3].value & (1 << (index & 0x07))) != 0);
- }
- }
- else {
- 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));
- }
- //memcpy(&middle_coils[(256 + 7) >> 3], &io_outputsen, 1);
- }
- /**
- * �喲𡡒颲枏枂嚗𣬚眏step�亦&摰𡁻�閬���凋�銋�甅����亥��?
- *
- * @author lxz (2019/6/16/�冽𠯫)
- *
- * @param void
- */
- void io_app_close_output(char step) {
- if (step == 1) {
- io_outputs[0].value = 0;
- io_outputs[1].value = 0;
- }
- else {
- io_outputs[0].value = 0;
- io_outputs[1].value = 0;
- }
- }
- /**
- * IO摨𠉛鍂銵�遆�唳�
- *
- * @author lxz (2019/5/29/�其�)
- */
- #define TEST_APP
- void io_app_run(void) {
- int index = 0;
- #ifdef TEST_APP
- int flag = 0;
- static int status = 1;
- static sw_timer_t timer;
- // for (index = 0; index<(OUTPUT_BITS_NUMBER + 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(&timer)) {
- status <<= 1;
- sw_timer_start(&timer, 0, 500000);
- }
- io_outputs[0].bytes[0] = status;
- io_outputs[1].bytes[0] = status>>8;
- if(status==0x1000) status=1;
- }
- else {
- sw_timer_start(&timer, 0, 500000);
- }
- #else
- for (index = 0; index<(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
- }
|