code sanitizations

This commit is contained in:
Klaus K Wilting 2018-07-23 08:25:23 +02:00
parent 957a813226
commit 337fc64602
12 changed files with 86 additions and 65 deletions

21
src/button.cpp Normal file
View File

@ -0,0 +1,21 @@
#ifdef HAS_BUTTON
#include "globals.h"
// Local logging tag
static const char TAG[] = "main";
void IRAM_ATTR ButtonIRQ() { ButtonPressedIRQ++; }
void readButton() {
if (ButtonPressedIRQ) {
portENTER_CRITICAL(&timerMux);
ButtonPressedIRQ = 0;
portEXIT_CRITICAL(&timerMux);
ESP_LOGI(TAG, "Button pressed");
payload.reset();
payload.addButton(0x01);
senddata(BUTTONPORT);
}
}
#endif

8
src/button.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _BUTTON_H
#define _BUTTON_H
void IRAM_ATTR ButtonIRQ(void);
void readButton(void);
#endif

View File

@ -170,4 +170,19 @@ void refreshtheDisplay() {
#endif // HAS_LORA
} // refreshDisplay()
void IRAM_ATTR DisplayIRQ() {
portENTER_CRITICAL_ISR(&timerMux);
DisplayTimerIRQ++;
portEXIT_CRITICAL_ISR(&timerMux);
}
void updateDisplay() {
if (DisplayTimerIRQ) {
portENTER_CRITICAL(&timerMux);
DisplayTimerIRQ = 0;
portEXIT_CRITICAL(&timerMux);
refreshtheDisplay();
}
}
#endif // HAS_DISPLAY

View File

@ -8,5 +8,7 @@ extern uint8_t DisplayState;
void init_display(const char *Productname, const char *Version);
void refreshtheDisplay(void);
void DisplayKey(const uint8_t *key, uint8_t len, bool lsb);
void updateDisplay(void);
void DisplayIRQ(void);
#endif

View File

@ -44,7 +44,8 @@ extern uint16_t macs_total, macs_wifi, macs_ble, batt_voltage; // display values
extern std::set<uint16_t> macs; // temp storage for MACs
extern hw_timer_t *channelSwitch, *sendCycle;
extern portMUX_TYPE timerMux;
extern volatile int SendCycleTimerIRQ;
extern volatile int SendCycleTimerIRQ, HomeCycleIRQ, DisplayTimerIRQ,
ChannelTimerIRQ, ButtonPressedIRQ;
#ifdef HAS_GPS
#include "gps.h"
@ -60,6 +61,10 @@ extern volatile int SendCycleTimerIRQ;
#include "display.h"
#endif
#ifdef HAS_BUTTON
#include "button.h"
#endif
#ifdef BLECOUNTER
#include "blescan.h"
#endif

View File

@ -38,3 +38,18 @@ void doHomework() {
reset_salt(); // get new salt for salting hashes
}
}
void checkHousekeeping() {
if (HomeCycleIRQ) {
portENTER_CRITICAL(&timerMux);
HomeCycleIRQ = 0;
portEXIT_CRITICAL(&timerMux);
doHomework();
}
}
void IRAM_ATTR homeCycleIRQ() {
portENTER_CRITICAL(&timerMux);
HomeCycleIRQ++;
portEXIT_CRITICAL(&timerMux);
}

View File

@ -2,5 +2,7 @@
#define _HOMECYCLE_H
void doHomework(void);
void checkHousekeeping(void);
void homeCycleIRQ(void);
#endif

View File

@ -16,7 +16,8 @@ static wifi_country_t wifi_country = {WIFI_MY_COUNTRY, WIFI_CHANNEL_MIN,
*/
static wifi_country_t wifi_country = {WIFI_MY_COUNTRY, WIFI_CHANNEL_MIN,
WIFI_CHANNEL_MAX, WIFI_COUNTRY_POLICY_MANUAL};
WIFI_CHANNEL_MAX,
WIFI_COUNTRY_POLICY_MANUAL};
// globals
uint16_t salt;
@ -138,3 +139,9 @@ IRAM_ATTR void wifi_sniffer_packet_handler(void *buff,
mac_add(p, ppkt->rx_ctrl.rssi, MAC_SNIFF_WIFI);
}
}
void IRAM_ATTR ChannelSwitchIRQ() {
portENTER_CRITICAL(&timerMux);
ChannelTimerIRQ++;
portEXIT_CRITICAL(&timerMux);
}

View File

@ -31,5 +31,6 @@ void wifi_sniffer_init(void);
void wifi_sniffer_set_channel(uint8_t channel);
void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type);
bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type);
void ChannelSwitchIRQ(void);
#endif

View File

@ -98,68 +98,6 @@ void lorawan_loop(void *pvParameters) {
#endif // HAS_LORA
// Setup IRQ handler routines
// attn see https://github.com/espressif/arduino-esp32/issues/855
void IRAM_ATTR ChannelSwitchIRQ() {
portENTER_CRITICAL(&timerMux);
ChannelTimerIRQ++;
portEXIT_CRITICAL(&timerMux);
}
void IRAM_ATTR SendCycleIRQ() {
portENTER_CRITICAL(&timerMux);
SendCycleTimerIRQ++;
portEXIT_CRITICAL(&timerMux);
}
void IRAM_ATTR homeCycleIRQ() {
portENTER_CRITICAL(&timerMux);
HomeCycleIRQ++;
portEXIT_CRITICAL(&timerMux);
}
#ifdef HAS_DISPLAY
void IRAM_ATTR DisplayIRQ() {
portENTER_CRITICAL_ISR(&timerMux);
DisplayTimerIRQ++;
portEXIT_CRITICAL_ISR(&timerMux);
}
void updateDisplay() {
if (DisplayTimerIRQ) {
portENTER_CRITICAL(&timerMux);
DisplayTimerIRQ = 0;
portEXIT_CRITICAL(&timerMux);
refreshtheDisplay();
}
}
#endif
void checkHousekeeping() {
if (HomeCycleIRQ) {
portENTER_CRITICAL(&timerMux);
HomeCycleIRQ = 0;
portEXIT_CRITICAL(&timerMux);
doHomework();
}
}
#ifdef HAS_BUTTON
void IRAM_ATTR ButtonIRQ() { ButtonPressedIRQ++; }
void readButton() {
if (ButtonPressedIRQ) {
portENTER_CRITICAL(&timerMux);
ButtonPressedIRQ = 0;
portEXIT_CRITICAL(&timerMux);
ESP_LOGI(TAG, "Button pressed");
payload.reset();
payload.addButton(0x01);
senddata(BUTTONPORT);
}
}
#endif
// Wifi channel rotation task
void wifi_channel_loop(void *pvParameters) {

View File

@ -66,3 +66,9 @@ void sendPayload() {
senddata(COUNTERPORT);
}
} // sendpayload();
void IRAM_ATTR SendCycleIRQ() {
portENTER_CRITICAL(&timerMux);
SendCycleTimerIRQ++;
portEXIT_CRITICAL(&timerMux);
}

View File

@ -3,5 +3,6 @@
void senddata(uint8_t port);
void sendPayload(void);
void SendCycleIRQ(void);
#endif // _SENDDATA_H_