led green blinking on network status

This commit is contained in:
Wolfgang Hottgenroth 2020-11-17 15:04:34 +01:00
parent fb04857772
commit eb64cc8dce
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
5 changed files with 48 additions and 51 deletions

View File

@ -4,9 +4,16 @@
#include <stdint.h> #include <stdint.h>
typedef enum { DEBUG_1, DEBUG_2, LED_RED, LED_GREEN } signalPin_t; typedef enum {
typedef enum { ON, OFF, TOGGLE } signalAction_t; DEBUG_1 = 0,
DEBUG_2 = 1,
LED_RED = 2,
LED_GREEN = 3
} signalPin_t;
typedef enum { ON, OFF, TOGGLE, BLINK } signalAction_t;
void showInit();
void show(signalPin_t signalPin, signalAction_t action); void show(signalPin_t signalPin, signalAction_t action);

View File

@ -60,10 +60,6 @@ void syslog(char *msg) {
} }
} }
static void flashGreenLed(void *handle) {
show(LED_GREEN, TOGGLE);
}
static int innerLogMsg(const char *pre, const char *post, bool syslogToo, const char *format, va_list vl) { static int innerLogMsg(const char *pre, const char *post, bool syslogToo, const char *format, va_list vl) {
const static char SYSLOG_HEADER[] = "<133>1 "; const static char SYSLOG_HEADER[] = "<133>1 ";
#define MAX_PREFIX_SIZE 20 #define MAX_PREFIX_SIZE 20
@ -99,11 +95,6 @@ static int innerLogMsg(const char *pre, const char *post, bool syslogToo, const
res = ringbufferPut(&logBuffer, (uint8_t*) (bufferStart - preSize), strlen(bufferStart - preSize)); res = ringbufferPut(&logBuffer, (uint8_t*) (bufferStart - preSize), strlen(bufferStart - preSize));
HAL_NVIC_EnableIRQ(UART4_IRQn); HAL_NVIC_EnableIRQ(UART4_IRQn);
if (-1 == res) {
// blink the green light or so
flashGreenLed(NULL);
schAdd(flashGreenLed, NULL, 100, 0);
}
debugTxCpltCallback(NULL); debugTxCpltCallback(NULL);
} }

View File

@ -24,6 +24,7 @@
void my_setup_1() { void my_setup_1() {
schInit(); schInit();
logInit(); logInit();
showInit();
} }
void my_errorHandler() { void my_errorHandler() {
@ -186,7 +187,7 @@ void scheduleMBusRequest(void *handle) {
void my_setup_2() { void my_setup_2() {
show(LED_RED, OFF); show(LED_RED, OFF);
show(LED_GREEN, ON); show(LED_GREEN, BLINK);
logMsg("Application starting"); logMsg("Application starting");
eepromInit(); eepromInit();

View File

@ -1,49 +1,46 @@
#include <main.h> #include <main.h>
#include <show.h> #include <show.h>
#include <PontCoopScheduler.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <stm32f103xe.h> #include <stm32f103xe.h>
void show(signalPin_t signalPin, signalAction_t action) { typedef struct {
GPIO_TypeDef *port = NULL; GPIO_TypeDef *port;
uint16_t pin = 0; uint16_t pin;
signalAction_t currentState;
} showElement_t;
switch (signalPin) { showElement_t showElement[] = {
case DEBUG_1: { .port = Debug_Signal_1_GPIO_Port, .pin = Debug_Signal_1_Pin, .currentState = OFF },
port = Debug_Signal_1_GPIO_Port; { .port = Debug_Signal_2_GPIO_Port, .pin = Debug_Signal_2_Pin, .currentState = OFF },
pin = Debug_Signal_1_Pin; { .port = LED_Red_GPIO_Port, .pin = LED_Red_Pin, .currentState = OFF },
break; { .port = LED_Green_GPIO_Port, .pin = LED_Green_Pin, .currentState = OFF },
{ .port = NULL, .pin = 0, .currentState = OFF }
};
case DEBUG_2: static void showHandler(void *handle) {
port = Debug_Signal_2_GPIO_Port; uint8_t idx = 0;
pin = Debug_Signal_2_Pin; while (showElement[idx].port) {
break; if (showElement[idx].currentState == BLINK) {
HAL_GPIO_TogglePin(showElement[idx].port, showElement[idx].pin);
case LED_RED:
port = LED_Red_GPIO_Port;
pin = LED_Red_Pin;
break;
case LED_GREEN:
port = LED_Green_GPIO_Port;
pin = LED_Green_Pin;
break;
}
if (port != NULL) {
switch (action) {
case ON:
HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET);
break;
case OFF:
HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET);
break;
case TOGGLE:
HAL_GPIO_TogglePin(port, pin);
break;
} }
idx++;
} }
} }
void show(signalPin_t signalPin, signalAction_t action) {
showElement[signalPin].currentState = action;
if (action == ON || action == OFF) {
HAL_GPIO_WritePin(showElement[signalPin].port, showElement[signalPin].pin, ((action == ON) ? GPIO_PIN_SET : GPIO_PIN_RESET));
} else if (action == TOGGLE) {
HAL_GPIO_TogglePin(showElement[signalPin].port, showElement[signalPin].pin);
}
}
void showInit() {
schAdd(showHandler, NULL, 0, 250);
}

View File

@ -1,5 +1,4 @@
#include <wizHelper.h> #include <wizHelper.h>
#include <stdint.h> #include <stdint.h>
#include <main2.h> #include <main2.h>
#include <spi.h> #include <spi.h>
@ -10,7 +9,7 @@
#include <wizchip_conf.h> #include <wizchip_conf.h>
#include <string.h> #include <string.h>
#include <dhcp.h> #include <dhcp.h>
#include <show.h>
wiz_NetInfo netInfo = { wiz_NetInfo netInfo = {
.mac = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0D }, .mac = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0D },
@ -74,6 +73,7 @@ static void wizDHCPAssign() {
coloredMsg(LOG_BLUE, false, "wizda, set netinfo again"); coloredMsg(LOG_BLUE, false, "wizda, set netinfo again");
networkAvailable = true; networkAvailable = true;
show(LED_GREEN, ON);
coloredMsg(LOG_BLUE, false, "wizda, network is available"); coloredMsg(LOG_BLUE, false, "wizda, network is available");
} }
@ -127,6 +127,7 @@ static void wizPhyLinkHandler(void *handle) {
dhcpInitialized = true; dhcpInitialized = true;
} else { } else {
networkAvailable = false; networkAvailable = false;
show(LED_GREEN, BLINK);
coloredMsg(LOG_BLUE, false, "wizplh, network is unavailable"); coloredMsg(LOG_BLUE, false, "wizplh, network is unavailable");
// stop DHCP handler // stop DHCP handler