|
@@ -85,7 +85,6 @@ static void btn3_handler(const button_state_t);
|
|
|
static void btn4_handler(const button_state_t);
|
|
|
|
|
|
/* Private variables */
|
|
|
-//static virtual_timer_t ina_vt;
|
|
|
static binary_semaphore_t ina_bsem, charger_bsem;
|
|
|
static charger_state_t charger_State;
|
|
|
static uint8_t current_Channel;
|
|
@@ -104,14 +103,12 @@ static btn_hndlr bha[Button_Num] = {btn1_handler, btn2_handler, btn3_handler, bt
|
|
|
/*
|
|
|
* INA process thread.
|
|
|
*/
|
|
|
-static THD_WORKING_AREA(waInaThread, 128);
|
|
|
+static THD_WORKING_AREA(waInaThread, 256);
|
|
|
static THD_FUNCTION(InaThread, arg) {
|
|
|
(void)arg;
|
|
|
- chRegSetThreadName("INA");
|
|
|
|
|
|
while (true) {
|
|
|
chBSemWait(&ina_bsem);
|
|
|
-
|
|
|
ina_Process();
|
|
|
}
|
|
|
}
|
|
@@ -119,7 +116,7 @@ static THD_FUNCTION(InaThread, arg) {
|
|
|
/*
|
|
|
* Charger process thread. Once per second.
|
|
|
*/
|
|
|
-static THD_WORKING_AREA(waChrgThread, 128);
|
|
|
+static THD_WORKING_AREA(waChrgThread, 256);
|
|
|
static THD_FUNCTION(ChrgThread, arg) {
|
|
|
(void)arg;
|
|
|
char buf[16];
|
|
@@ -127,12 +124,25 @@ static THD_FUNCTION(ChrgThread, arg) {
|
|
|
while (true) {
|
|
|
chBSemWait(&charger_bsem);
|
|
|
|
|
|
+ if (Timer.ss < 59) {
|
|
|
+ Timer.ss ++;
|
|
|
+ } else {
|
|
|
+ Timer.ss = 0;
|
|
|
+ if (Timer.mm < 59) {
|
|
|
+ Timer.mm ++;
|
|
|
+ } else {
|
|
|
+ Timer.mm = 0;
|
|
|
+ Timer.hh ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (charger_State != Stop) {
|
|
|
chsnprintf(buf, 12, "T:%02u:%02u:%02u", Timer.hh, Timer.mm, Timer.ss);
|
|
|
} else {
|
|
|
chsnprintf(buf, 12, "T:00:00:00");
|
|
|
}
|
|
|
gdispFillStringBox(1, 153, 158, 29, buf, font2, Red, Gray, gJustifyCenter);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -191,6 +201,12 @@ int main(void) {
|
|
|
*/
|
|
|
buttons_Init(bha);
|
|
|
|
|
|
+ /*
|
|
|
+ * Initializing semaphores in the "taken" state.
|
|
|
+ */
|
|
|
+ chBSemObjectInit(&ina_bsem, true);
|
|
|
+ chBSemObjectInit(&charger_bsem, true);
|
|
|
+
|
|
|
/*
|
|
|
* Creates the blinker thread.
|
|
|
*/
|
|
@@ -240,7 +256,6 @@ int main(void) {
|
|
|
*/
|
|
|
while (true) {
|
|
|
chThdSleepMilliseconds(500);
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -295,6 +310,7 @@ static void prepare_Screen(void) {
|
|
|
|
|
|
static void btn1_handler(button_state_t state) {
|
|
|
if (state == BTN_st_Pressed) {
|
|
|
+
|
|
|
gwinPrintf(GW1, "Button 1 pressed\n");
|
|
|
|
|
|
current_Channel ++;
|
|
@@ -356,7 +372,6 @@ static void ina_Process(void) {
|
|
|
char buf[12];
|
|
|
static int idx = 0;
|
|
|
|
|
|
- palToggleLine(LINE_LED2);
|
|
|
if (INA_Present != 0) {
|
|
|
Current = INA3221_getCurrent(&ina3221, (ina3221_ch_t)current_Channel);
|
|
|
Voltage = INA3221_getVoltage(&ina3221, (ina3221_ch_t)current_Channel);
|
|
@@ -416,23 +431,16 @@ static void gpt_cb(GPTDriver *gptp) {
|
|
|
|
|
|
chSysLockFromISR();
|
|
|
chBSemSignalI(&ina_bsem);
|
|
|
+ chSysUnlockFromISR();
|
|
|
+
|
|
|
cnt ++;
|
|
|
if (cnt >= INA_AVG_FACTOR) {
|
|
|
/* One second */
|
|
|
- palToggleLine(LINE_LED1);
|
|
|
cnt = 0;
|
|
|
+
|
|
|
+ chSysLockFromISR();
|
|
|
chBSemSignalI(&charger_bsem);
|
|
|
- if (Timer.ss < 59) {
|
|
|
- Timer.ss ++;
|
|
|
- } else {
|
|
|
- Timer.ss = 0;
|
|
|
- if (Timer.mm < 59) {
|
|
|
- Timer.mm ++;
|
|
|
- } else {
|
|
|
- Timer.mm = 0;
|
|
|
- Timer.hh ++;
|
|
|
- }
|
|
|
- }
|
|
|
+ chSysUnlockFromISR();
|
|
|
}
|
|
|
- chSysUnlockFromISR();
|
|
|
+// chSysUnlockFromISR();
|
|
|
}
|