change south switch order

This commit is contained in:
wmano
2025-10-16 22:30:43 +08:00
parent c8032dd1c6
commit 1e6443a767
9 changed files with 61 additions and 36 deletions
+26 -13
View File
@@ -75,38 +75,51 @@ int chrg_switch_south_lv1 (eIDX_CH ch)
int chrg_switch_south_lv2_1 (eIDX_CH ch) int chrg_switch_south_lv2_1 (eIDX_CH ch)
{ {
if (ch >= TOTAL_CHS) { int ret = -1;
return -1;
if (IDX_CH_0 == ch) {
ret = chrg_switch_ch(PIN_SW_SOUTH_LV2_A1, PIN_SW_SOUTH_LV2_B1, IDX_CH_2);
} else if (IDX_CH_1 == ch) {
ret = chrg_switch_ch(PIN_SW_SOUTH_LV2_A1, PIN_SW_SOUTH_LV2_B1, IDX_CH_0);
} }
return chrg_switch_ch(PIN_SW_SOUTH_LV2_A1, PIN_SW_SOUTH_LV2_B1, ch); return ret;
} }
int chrg_switch_south_lv2_2 (eIDX_CH ch) int chrg_switch_south_lv2_2 (eIDX_CH ch)
{ {
if (ch >= TOTAL_CHS) { int ret = -1;
if (IDX_CH_0 == ch) {
ret = chrg_switch_ch(PIN_SW_SOUTH_LV2_A2, PIN_SW_SOUTH_LV2_B2, IDX_CH_2);
} else if (IDX_CH_1 == ch) {
ret = chrg_switch_ch(PIN_SW_SOUTH_LV2_A2, PIN_SW_SOUTH_LV2_B2, IDX_CH_0);
} else {
return -1; return -1;
} }
return chrg_switch_ch(PIN_SW_SOUTH_LV2_A2, PIN_SW_SOUTH_LV2_B2, ch); return ret;
} }
// 南向通道选择 // 南向通道选择
int chrg_switch_south (eIDX_SOUTH_CH ch) int chrg_switch_south (eIDX_SOUTH_CH ch)
{ {
if (ch >= TOTAL_SOUTH_CHS) { int ret = -1;
if (ch >= TOTAL_SOU_CHS) {
return -1; return -1;
} }
if (ch < IDX_SOUTH_4) { if ((IDX_SOU_CH1 == ch)||(IDX_SOU_CH2 == ch)) {
chrg_switch_south_lv1(IDX_CH_0); ret = chrg_switch_south_lv1(IDX_CH_1);
chrg_switch_south_lv2_1((eIDX_CH)ch); ret |= chrg_switch_south_lv2_2((eIDX_CH)ch);
} else if ((IDX_SOU_CH3 == ch)||(IDX_SOU_CH4 == ch)) {
ret = chrg_switch_south_lv1(IDX_CH_0);
ret |= chrg_switch_south_lv2_1((eIDX_CH)(ch-IDX_SOU_CH3));
} else { } else {
chrg_switch_south_lv1(IDX_CH_1); return -1;
chrg_switch_south_lv2_2((eIDX_CH)(ch-IDX_SOUTH_4));
} }
return 0; return ret;
} }
static int chrg_switch_south_pins_init (void) static int chrg_switch_south_pins_init (void)
@@ -128,7 +141,7 @@ static int chrg_switch_init (void)
chrg_switch_south_pins_init(); chrg_switch_south_pins_init();
chrg_switch_north(IDX_CH_0); chrg_switch_north(IDX_CH_0);
chrg_switch_south(IDX_SOUTH_0); chrg_switch_south(IDX_SOU_CH1);
return 0; return 0;
} }
+7 -11
View File
@@ -14,25 +14,21 @@ typedef enum {
// U14 U23 U24 U25 // U14 U23 U24 U25
// ---------------- // ----------------
IDX_CH_0 = 0, // J3 U24 J12 J16 IDX_CH_0 = 0, // J3 U24 J12 J16
IDX_CH_1, // J4 U25 J13 J17 IDX_CH_1, // J4 U25 -J13 -J17
IDX_CH_2, // J9 - J14 J18 IDX_CH_2, // J9 - J14 J18
IDX_CH_3, // J10 - J15 J19 IDX_CH_3, // J10 - -J15 -J19
TOTAL_CHS TOTAL_CHS
} eIDX_CH; } eIDX_CH;
// 南向选择 组合 // 南向选择 组合
typedef enum { typedef enum {
IDX_SOUTH_0 = 0, // U24_J12 IDX_SOU_CH1 = 0, // U25_J18
IDX_SOUTH_1, // U24_J13 IDX_SOU_CH2, // U25_J16
IDX_SOUTH_2, // U24_J14 IDX_SOU_CH3, // U24_J14
IDX_SOUTH_3, // U24_J15 IDX_SOU_CH4, // U24_J12
IDX_SOUTH_4, // U25_J16
IDX_SOUTH_5, // U25_J17
IDX_SOUTH_6, // U25_J18
IDX_SOUTH_7, // U25_J19
TOTAL_SOUTH_CHS TOTAL_SOU_CHS
} eIDX_SOUTH_CH; } eIDX_SOUTH_CH;
+1 -1
View File
@@ -44,7 +44,7 @@ void chrg_north_sw_uart (eIDX_CH ch, eIDX_ID id)
if (ID_SOURCE == id) { if (ID_SOURCE == id) {
rt_pin_write(sw_uart[ch], PIN_HIGH); rt_pin_write(sw_uart[ch], PIN_HIGH);
} else { } else if (ID_SINK == id) {
rt_pin_write(sw_uart[ch], PIN_LOW); rt_pin_write(sw_uart[ch], PIN_LOW);
} }
+11 -9
View File
@@ -15,7 +15,7 @@ struct chrg_roll_t chrgroll = {
.tid = RT_NULL, .tid = RT_NULL,
.idx = 0, .idx = 0,
.en_nor = {1, 1, 1, 1}, .en_nor = {1, 1, 1, 1},
.en_sou = {1, 1, 1, 1, 0, 0, 0, 0}, .en_sou = {1, 1, 1, 1},
}; };
rt_uint8_t chrg_roll_get_idx (void) rt_uint8_t chrg_roll_get_idx (void)
@@ -46,7 +46,7 @@ static void chrg_roll_thread_entry (void *data)
return ; return ;
} }
rt_uint8_t idx = 0; rt_uint8_t idx = 0, sou_idx = 0;
rt_err_t ret = RT_EOK; rt_err_t ret = RT_EOK;
rt_uint32_t recved = 0; rt_uint32_t recved = 0;
struct chrg_north_t *pNOR = &chrgnorth; struct chrg_north_t *pNOR = &chrgnorth;
@@ -55,7 +55,7 @@ static void chrg_roll_thread_entry (void *data)
while (1) { while (1) {
rt_mutex_take(pROLL->mutex, RT_WAITING_FOREVER); rt_mutex_take(pROLL->mutex, RT_WAITING_FOREVER);
pROLL->idx = idx%(TOTAL_CHS+TOTAL_SOUTH_CHS); pROLL->idx = idx%(TOTAL_CHS+TOTAL_SOU_CHS);
rt_mutex_release(pROLL->mutex); rt_mutex_release(pROLL->mutex);
if (pROLL->idx < TOTAL_CHS) { if (pROLL->idx < TOTAL_CHS) {
@@ -75,23 +75,25 @@ static void chrg_roll_thread_entry (void *data)
chrg_north_sw_uart(pNOR->idx, ID_SINK); chrg_north_sw_uart(pNOR->idx, ID_SINK);
sink_get_vc(pSW->sink.loadv, pSW->sink.loadc); sink_get_vc(pSW->sink.loadv, pSW->sink.loadc);
} }
rt_kprintf("Nor[%d].%d\r\n", pNOR->idx, pSW->id);
} }
} else { } else {
if (0 == pROLL->en_sou[pROLL->idx]) { sou_idx = pROLL->idx - TOTAL_CHS;
if (0 == pROLL->en_sou[sou_idx]) {
idx++; idx++;
rt_thread_mdelay(1); rt_thread_mdelay(1);
continue; continue;
} else { } else {
pSOU->idx = (eIDX_SOUTH_CH)(pROLL->idx - TOTAL_CHS); pSOU->idx = (eIDX_SOUTH_CH)sou_idx;
chrg_switch_south(pSOU->idx); chrg_switch_south(pSOU->idx);
pSW = &pSOU->sw[pSOU->idx]; pSW = &pSOU->sw[pSOU->idx];
if (ID_SOURCE == pSW->id) { // todo pkg send
if (ID_ELOAD == pSW->id) {
source_get_vc(pSW->source.voltage, pSW->source.current); source_get_vc(pSW->source.voltage, pSW->source.current);
} else if (ID_SINK == pSW->id) {
sink_get_vc(pSW->sink.loadv, pSW->sink.loadc);
} }
rt_kprintf("Sou[%d].%d\r\n", pSOU->idx, pSW->id);
} }
} }
+1 -1
View File
@@ -20,7 +20,7 @@ struct chrg_roll_t {
rt_uint8_t idx; // 轮巡索引 0-3:nor 4-11:sou rt_uint8_t idx; // 轮巡索引 0-3:nor 4-11:sou
rt_uint8_t en_nor[TOTAL_CHS]; // 北向通路使能 rt_uint8_t en_nor[TOTAL_CHS]; // 北向通路使能
rt_uint8_t en_sou[TOTAL_SOUTH_CHS]; // 南向通路使能 rt_uint8_t en_sou[TOTAL_SOU_CHS]; // 南向通路使能
}; };
extern struct chrg_roll_t chrgroll; extern struct chrg_roll_t chrgroll;
@@ -15,6 +15,19 @@ struct chrg_south_t chrgsouth = {
.tid = RT_NULL, .tid = RT_NULL,
.tty = RT_NULL, .tty = RT_NULL,
.rx_len = 0, .rx_len = 0,
.sw[IDX_SOU_CH1] = {
.id = ID_ELOAD,
},
.sw[IDX_SOU_CH2] = {
.id = ID_ELOAD,
},
.sw[IDX_SOU_CH3] = {
.id = ID_ELOAD,
},
.sw[IDX_SOU_CH4] = {
.id = ID_ELOAD,
},
}; };
int chrg_south_send (rt_uint8_t *data, rt_size_t length) int chrg_south_send (rt_uint8_t *data, rt_size_t length)
+1 -1
View File
@@ -20,7 +20,7 @@ struct chrg_south_t {
rt_uint8_t rx_buf[SIZE_BUF_TTY]; rt_uint8_t rx_buf[SIZE_BUF_TTY];
eIDX_SOUTH_CH idx; // 当前通路 eIDX_SOUTH_CH idx; // 当前通路
struct chrg_switch_t sw[TOTAL_SOUTH_CHS]; struct chrg_switch_t sw[TOTAL_SOU_CHS];
}; };
extern struct chrg_south_t chrgsouth; extern struct chrg_south_t chrgsouth;
+1
View File
@@ -7,6 +7,7 @@
typedef enum { typedef enum {
ID_SINK = 0x01, // SINK 的 ID 为 1, 波特率 200K ID_SINK = 0x01, // SINK 的 ID 为 1, 波特率 200K
ID_SOURCE = 0x02, // SOURCE 的 ID 为 2, 波特率 200K ID_SOURCE = 0x02, // SOURCE 的 ID 为 2, 波特率 200K
ID_ELOAD = 0x03, // LOAD ID 3 波特率 115200
} eIDX_ID; } eIDX_ID;
// 电压电流极值 // 电压电流极值