103 lines
2.3 KiB
C
103 lines
2.3 KiB
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <rtthread.h>
|
|
|
|
#include "chrg_gpio.h"
|
|
#include "chrg_rel.h"
|
|
|
|
struct chrg_rel_t chrgrel[TOTAL_CHS] = {
|
|
[IDX_CH_0] = {GPO_PIN_CH1_P0, GPO_PIN_CH1_P1, GPO_PIN_CH1_P2},
|
|
[IDX_CH_1] = {GPO_PIN_CH2_P0, GPO_PIN_CH2_P1, GPO_PIN_CH2_P2},
|
|
[IDX_CH_2] = {GPO_PIN_CH3_P0, GPO_PIN_CH3_P1, GPO_PIN_CH3_P2},
|
|
[IDX_CH_3] = {GPO_PIN_CH4_P0, GPO_PIN_CH4_P1, GPO_PIN_CH4_P2}
|
|
};
|
|
|
|
// 北向继电器组 组合切换
|
|
void chrg_nor_sw_rel (eIDX_CH ch, eIDX_ID id)
|
|
{
|
|
if (ch >= TOTAL_CHS) {
|
|
return ;
|
|
}
|
|
|
|
if (ID_SOURCE == id) {
|
|
rt_pin_write(chrgrel[ch].p2, PIN_HIGH);
|
|
rt_pin_write(chrgrel[ch].p0, PIN_LOW);
|
|
rt_pin_write(chrgrel[ch].p1, PIN_HIGH);
|
|
} else if (ID_SINK == id) {
|
|
rt_pin_write(chrgrel[ch].p2, PIN_HIGH);
|
|
rt_pin_write(chrgrel[ch].p1, PIN_LOW);
|
|
rt_pin_write(chrgrel[ch].p0, PIN_HIGH);
|
|
} else {
|
|
rt_pin_write(chrgrel[ch].p2, PIN_LOW);
|
|
rt_pin_write(chrgrel[ch].p1, PIN_LOW);
|
|
rt_pin_write(chrgrel[ch].p0, PIN_LOW);
|
|
}
|
|
|
|
}
|
|
|
|
static int chrg_nor_rel_init (void)
|
|
{
|
|
int i = 0;
|
|
|
|
for (i = 0; i < TOTAL_CHS; i++) {
|
|
rt_pin_write(chrgrel[i].p2, PIN_LOW);
|
|
rt_pin_write(chrgrel[i].p0, PIN_LOW);
|
|
rt_pin_write(chrgrel[i].p1, PIN_LOW);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
INIT_DEVICE_EXPORT(chrg_nor_rel_init);
|
|
|
|
#if 1
|
|
int rel_test (int argc, char **argv)
|
|
{
|
|
if (argc < 3) {
|
|
rt_kprintf("help : %s <get|set> <0|1|2|3> [0, 1]", argv[0]);
|
|
return -1;
|
|
}
|
|
|
|
int idx = atoi(argv[2]);
|
|
if ((idx > 3)||(idx < 0)) {
|
|
rt_kprintf("help : %s <get|set> <0|1|2|3> [0, 1]", argv[0]);
|
|
return -1;
|
|
}
|
|
|
|
if (strcmp(argv[1], "set") == 0) {
|
|
if (argc != 4) {
|
|
rt_kprintf("help : %s <get|set> <0|1|2|3> [0, 1]", argv[0]);
|
|
return -1;
|
|
}
|
|
rt_uint8_t val = (rt_uint8_t)atoi(argv[3]);
|
|
chrg_nor_sw_rel((eIDX_CH)idx, (eIDX_ID)val);
|
|
} else if (strcmp(argv[1], "get") == 0) {
|
|
rt_uint8_t data[3] = {0};
|
|
data[0] = rt_pin_read(chrgrel[idx].p0);
|
|
data[1] = rt_pin_read(chrgrel[idx].p1);
|
|
data[2] = rt_pin_read(chrgrel[idx].p2);
|
|
if ((1 == data[0])&&(0 == data[1])&&(1 == data[2])) {
|
|
rt_kprintf("rel connect [%d] : sink\r\n", idx);
|
|
} else if ((0 == data[0])&&(1 == data[1])&&(1 == data[2])) {
|
|
rt_kprintf("rel connect [%d] : source\r\n", idx);
|
|
} else {
|
|
rt_kprintf("rel connect [%d] : p0=%d, p1=%d, p2=%d\r\n",
|
|
idx, data[0], data[1], data[2]);
|
|
}
|
|
|
|
} else {
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
MSH_CMD_EXPORT(rel_test, test rel connect.);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|