dos2unix
parent
53f5b78356
commit
02f992a97b
@ -1,18 +1,18 @@
|
|||||||
-D
|
-D
|
||||||
__AVR_ATmega2560__
|
__AVR_ATmega2560__
|
||||||
-D
|
-D
|
||||||
F_CPU=16000000UL
|
F_CPU=16000000UL
|
||||||
-D
|
-D
|
||||||
_WIZCHIP_=W5100
|
_WIZCHIP_=W5100
|
||||||
-I
|
-I
|
||||||
/usr/lib/avr/include
|
/usr/lib/avr/include
|
||||||
-I
|
-I
|
||||||
Internet
|
Internet
|
||||||
-I
|
-I
|
||||||
Internet/MQTT
|
Internet/MQTT
|
||||||
-I
|
-I
|
||||||
Internet/MQTT/MQTTPacket/src
|
Internet/MQTT/MQTTPacket/src
|
||||||
-I
|
-I
|
||||||
Ethernet
|
Ethernet
|
||||||
-I
|
-I
|
||||||
Ethernet/W5500
|
Ethernet/W5500
|
||||||
|
|||||||
@ -1,345 +1,345 @@
|
|||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <avr/wdt.h> // WatchDog
|
#include <avr/wdt.h> // WatchDog
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "Ethernet/socket.h"
|
#include "Ethernet/socket.h"
|
||||||
#include "Ethernet/wizchip_conf.h"
|
#include "Ethernet/wizchip_conf.h"
|
||||||
|
|
||||||
#include "Internet/MQTT/mqtt_interface.h"
|
#include "Internet/MQTT/mqtt_interface.h"
|
||||||
#include "Internet/MQTT/MQTTClient.h"
|
#include "Internet/MQTT/MQTTClient.h"
|
||||||
|
|
||||||
#include "avrIOhelper/io-helper.h"
|
#include "avrIOhelper/io-helper.h"
|
||||||
#include "millis.h"
|
#include "millis.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
|
|
||||||
#include "util/delay.h"
|
#include "util/delay.h"
|
||||||
|
|
||||||
#define PLC_MQTT_ENABLED 1
|
#define PLC_MQTT_ENABLED 1
|
||||||
|
|
||||||
Client mqtt_client;
|
Client mqtt_client;
|
||||||
|
|
||||||
//***********Prologue for fast WDT disable & and save reason of reset/power-up: BEGIN
|
//***********Prologue for fast WDT disable & and save reason of reset/power-up: BEGIN
|
||||||
uint8_t mcucsr_mirror __attribute__ ((section (".noinit")));
|
uint8_t mcucsr_mirror __attribute__ ((section (".noinit")));
|
||||||
|
|
||||||
// This is for fast WDT disable & and save reason of reset/power-up
|
// This is for fast WDT disable & and save reason of reset/power-up
|
||||||
void get_mcusr(void) \
|
void get_mcusr(void) \
|
||||||
__attribute__((naked)) \
|
__attribute__((naked)) \
|
||||||
__attribute__((section(".init3")));
|
__attribute__((section(".init3")));
|
||||||
void get_mcusr(void)
|
void get_mcusr(void)
|
||||||
{
|
{
|
||||||
mcucsr_mirror = MCUSR;
|
mcucsr_mirror = MCUSR;
|
||||||
MCUSR = 0;
|
MCUSR = 0;
|
||||||
wdt_disable();
|
wdt_disable();
|
||||||
}
|
}
|
||||||
//***********Prologue for fast WDT disable & and save reason of reset/power-up: END
|
//***********Prologue for fast WDT disable & and save reason of reset/power-up: END
|
||||||
|
|
||||||
|
|
||||||
//FUNC headers
|
//FUNC headers
|
||||||
static void avr_init(void);
|
static void avr_init(void);
|
||||||
void timer0_init(void);
|
void timer0_init(void);
|
||||||
void print_network_information(void);
|
void print_network_information(void);
|
||||||
|
|
||||||
void IO_LIBRARY_Init(void) {
|
void IO_LIBRARY_Init(void) {
|
||||||
uint8_t bufSize[] = {2, 2, 2, 2, 2, 2, 2, 2};
|
uint8_t bufSize[] = {2, 2, 2, 2, 2, 2, 2, 2};
|
||||||
|
|
||||||
reg_wizchip_cs_cbfunc(spi_select, spi_deselect);
|
reg_wizchip_cs_cbfunc(spi_select, spi_deselect);
|
||||||
reg_wizchip_spi_cbfunc(spi_read, spi_write);
|
reg_wizchip_spi_cbfunc(spi_read, spi_write);
|
||||||
//reg_wizchip_spiburst_cbfunc(spi_rb_burst, spi_wb_burst);
|
//reg_wizchip_spiburst_cbfunc(spi_rb_burst, spi_wb_burst);
|
||||||
|
|
||||||
wizchip_init(bufSize, bufSize);
|
wizchip_init(bufSize, bufSize);
|
||||||
wizchip_setnetinfo(&netInfo);
|
wizchip_setnetinfo(&netInfo);
|
||||||
//wizchip_setinterruptmask(IK_SOCK_0);
|
//wizchip_setinterruptmask(IK_SOCK_0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STEP_SIZE 5
|
#define STEP_SIZE 5
|
||||||
#define TOP_VALUE 40
|
#define TOP_VALUE 40
|
||||||
void do_luefter(){
|
void do_luefter(){
|
||||||
static uint8_t fan_value = TOP_VALUE*0.5;
|
static uint8_t fan_value = TOP_VALUE*0.5;
|
||||||
static uint8_t fan_state = 0;
|
static uint8_t fan_state = 0;
|
||||||
|
|
||||||
|
|
||||||
if(!read_Input(IN_ANLAGE_EIN, LEVEL)){
|
if(!read_Input(IN_ANLAGE_EIN, LEVEL)){
|
||||||
fan_state = 0;
|
fan_state = 0;
|
||||||
ioHelperSetBit(outStates, LED_LUEFTER, 0);
|
ioHelperSetBit(outStates, LED_LUEFTER, 0);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (read_Input(BTN_LUEFTER_EIN, RISING)) {
|
if (read_Input(BTN_LUEFTER_EIN, RISING)) {
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Luefter", "ein", 3);
|
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Luefter", "ein", 3);
|
||||||
#endif
|
#endif
|
||||||
OCR3B = TOP_VALUE/2;
|
OCR3B = TOP_VALUE/2;
|
||||||
fan_state = 1;
|
fan_state = 1;
|
||||||
ioHelperSetBit(outStates, LED_LUEFTER, 1);
|
ioHelperSetBit(outStates, LED_LUEFTER, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_Input(BTN_LUEFTER_AUS, RISING)) {
|
if (read_Input(BTN_LUEFTER_AUS, RISING)) {
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Luefter", "aus", 3);
|
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Luefter", "aus", 3);
|
||||||
#endif
|
#endif
|
||||||
fan_state = 0;
|
fan_state = 0;
|
||||||
ioHelperSetBit(outStates, LED_LUEFTER, 0);
|
ioHelperSetBit(outStates, LED_LUEFTER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_Input(BTN_LUEFTER_PLUS, RISING) && (fan_value+STEP_SIZE <= TOP_VALUE)) {
|
if (read_Input(BTN_LUEFTER_PLUS, RISING) && (fan_value+STEP_SIZE <= TOP_VALUE)) {
|
||||||
fan_value += STEP_SIZE;
|
fan_value += STEP_SIZE;
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
char _msg[3];
|
char _msg[3];
|
||||||
sprintf(_msg, "%d", fan_value * 100 / 40);
|
sprintf(_msg, "%d", fan_value * 100 / 40);
|
||||||
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/LuefterSpeed", _msg, 3);
|
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/LuefterSpeed", _msg, 3);
|
||||||
#endif
|
#endif
|
||||||
printf("luefter %d\n\r", fan_value);
|
printf("luefter %d\n\r", fan_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_Input(BTN_LUEFTER_MINUS, RISING) && (fan_value-STEP_SIZE >= STEP_SIZE)) {
|
if (read_Input(BTN_LUEFTER_MINUS, RISING) && (fan_value-STEP_SIZE >= STEP_SIZE)) {
|
||||||
fan_value -= STEP_SIZE;
|
fan_value -= STEP_SIZE;
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
char _msg[3];
|
char _msg[3];
|
||||||
sprintf(_msg, "%d", fan_value * 100 / 40);
|
sprintf(_msg, "%d", fan_value * 100 / 40);
|
||||||
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/LuefterSpeed", _msg, 3);
|
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/LuefterSpeed", _msg, 3);
|
||||||
#endif
|
#endif
|
||||||
printf("luefter %d\n\r", fan_value);
|
printf("luefter %d\n\r", fan_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fan_state)
|
if(fan_state)
|
||||||
OCR3B = fan_value;
|
OCR3B = fan_value;
|
||||||
else
|
else
|
||||||
OCR3B = 0;
|
OCR3B = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_zumbach(){
|
void do_zumbach(){
|
||||||
|
|
||||||
if (read_Input(BTN_ZUMBACH_EIN, RISING) && read_Input(IN_ANLAGE_EIN, LEVEL)) {
|
if (read_Input(BTN_ZUMBACH_EIN, RISING) && read_Input(IN_ANLAGE_EIN, LEVEL)) {
|
||||||
ioHelperSetBit(outStates, SCHUETZ_ZUMBACH, 1);
|
ioHelperSetBit(outStates, SCHUETZ_ZUMBACH, 1);
|
||||||
ioHelperSetBit(outStates, LED_ZUMBACH, 1);
|
ioHelperSetBit(outStates, LED_ZUMBACH, 1);
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Zumbach", "ein", 3);
|
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Zumbach", "ein", 3);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_Input(BTN_ZUMBACH_AUS, RISING) || read_Input(IN_ANLAGE_EIN, FALLING)) {
|
if (read_Input(BTN_ZUMBACH_AUS, RISING) || read_Input(IN_ANLAGE_EIN, FALLING)) {
|
||||||
ioHelperSetBit(outStates, SCHUETZ_ZUMBACH, 0);
|
ioHelperSetBit(outStates, SCHUETZ_ZUMBACH, 0);
|
||||||
ioHelperSetBit(outStates, LED_ZUMBACH, 0);
|
ioHelperSetBit(outStates, LED_ZUMBACH, 0);
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Zumbach", "aus", 3);
|
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Zumbach", "aus", 3);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_notaus(){
|
void do_notaus(){
|
||||||
if(read_Input(IN_NOTAUS_ANLAGE, LEVEL) || read_Input(IN_NOTAUS_SCHRANK, LEVEL)){ // NOTAUS
|
if(read_Input(IN_NOTAUS_ANLAGE, LEVEL) || read_Input(IN_NOTAUS_SCHRANK, LEVEL)){ // NOTAUS
|
||||||
set_Output(LED_GRN_NOTAUS_SCHRANK, OFF); // disable green lamps
|
set_Output(LED_GRN_NOTAUS_SCHRANK, OFF); // disable green lamps
|
||||||
set_Output(LED_GRN_NOTAUS_ANLAGE, OFF);
|
set_Output(LED_GRN_NOTAUS_ANLAGE, OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(read_Input(IN_NOTAUS_ANLAGE, LEVEL) && read_Input(IN_NOTAUS_SCHRANK, LEVEL)){ // both activated
|
if(read_Input(IN_NOTAUS_ANLAGE, LEVEL) && read_Input(IN_NOTAUS_SCHRANK, LEVEL)){ // both activated
|
||||||
set_Output(LED_ROT_NOTAUS_ANLAGE, BLINK);
|
set_Output(LED_ROT_NOTAUS_ANLAGE, BLINK);
|
||||||
set_Output(LED_ROT_NOTAUS_SCHRANK, BLINK);
|
set_Output(LED_ROT_NOTAUS_SCHRANK, BLINK);
|
||||||
}
|
}
|
||||||
else if(read_Input(IN_NOTAUS_ANLAGE, LEVEL)){ // top one activated
|
else if(read_Input(IN_NOTAUS_ANLAGE, LEVEL)){ // top one activated
|
||||||
set_Output(LED_ROT_NOTAUS_ANLAGE, BLINK);
|
set_Output(LED_ROT_NOTAUS_ANLAGE, BLINK);
|
||||||
set_Output(LED_ROT_NOTAUS_SCHRANK, ON);
|
set_Output(LED_ROT_NOTAUS_SCHRANK, ON);
|
||||||
}
|
}
|
||||||
else if(read_Input(IN_NOTAUS_SCHRANK, LEVEL)){ // bottom one activated
|
else if(read_Input(IN_NOTAUS_SCHRANK, LEVEL)){ // bottom one activated
|
||||||
set_Output(LED_ROT_NOTAUS_SCHRANK, BLINK);
|
set_Output(LED_ROT_NOTAUS_SCHRANK, BLINK);
|
||||||
set_Output(LED_ROT_NOTAUS_ANLAGE, ON);
|
set_Output(LED_ROT_NOTAUS_ANLAGE, ON);
|
||||||
}
|
}
|
||||||
else{ // none activated
|
else{ // none activated
|
||||||
set_Output(LED_ROT_NOTAUS_SCHRANK, OFF);
|
set_Output(LED_ROT_NOTAUS_SCHRANK, OFF);
|
||||||
set_Output(LED_ROT_NOTAUS_ANLAGE, OFF);
|
set_Output(LED_ROT_NOTAUS_ANLAGE, OFF);
|
||||||
if(read_Input(IN_ANLAGE_EIN, LEVEL)){
|
if(read_Input(IN_ANLAGE_EIN, LEVEL)){
|
||||||
set_Output(LED_GRN_NOTAUS_ANLAGE, ON);
|
set_Output(LED_GRN_NOTAUS_ANLAGE, ON);
|
||||||
set_Output(LED_GRN_NOTAUS_SCHRANK, ON);
|
set_Output(LED_GRN_NOTAUS_SCHRANK, ON);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
set_Output(LED_GRN_NOTAUS_ANLAGE, ON);
|
set_Output(LED_GRN_NOTAUS_ANLAGE, ON);
|
||||||
set_Output(LED_GRN_NOTAUS_SCHRANK, ON);
|
set_Output(LED_GRN_NOTAUS_SCHRANK, ON);
|
||||||
set_Output(LED_ROT_NOTAUS_ANLAGE, ON);
|
set_Output(LED_ROT_NOTAUS_ANLAGE, ON);
|
||||||
set_Output(LED_ROT_NOTAUS_SCHRANK, ON);
|
set_Output(LED_ROT_NOTAUS_SCHRANK, ON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// INIT MCU
|
// INIT MCU
|
||||||
avr_init();
|
avr_init();
|
||||||
spi_init(); //SPI Master, MODE0, 4Mhz(DIV4), CS_PB.3=HIGH - suitable for WIZNET 5x00(1/2/5)
|
spi_init(); //SPI Master, MODE0, 4Mhz(DIV4), CS_PB.3=HIGH - suitable for WIZNET 5x00(1/2/5)
|
||||||
//spi_speed_tst(); / Here on SPI pins: MOSI 400Khz freq out, on SCLK 3.2MhzOUT (Witk SPI CLK 4Mhz)
|
//spi_speed_tst(); / Here on SPI pins: MOSI 400Khz freq out, on SCLK 3.2MhzOUT (Witk SPI CLK 4Mhz)
|
||||||
|
|
||||||
ioHelperInitBuffer();
|
ioHelperInitBuffer();
|
||||||
ioHelperIoConf();
|
ioHelperIoConf();
|
||||||
|
|
||||||
//Wizchip WIZ5500 Ethernet initialize
|
//Wizchip WIZ5500 Ethernet initialize
|
||||||
IO_LIBRARY_Init(); //After that ping must working
|
IO_LIBRARY_Init(); //After that ping must working
|
||||||
print_network_information();
|
print_network_information();
|
||||||
|
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
//****************MQTT client initialize
|
//****************MQTT client initialize
|
||||||
//Find MQTT broker and connect with it
|
//Find MQTT broker and connect with it
|
||||||
uint8_t mqtt_buf[100];
|
uint8_t mqtt_buf[100];
|
||||||
int32_t mqtt_rc = 0;
|
int32_t mqtt_rc = 0;
|
||||||
Network mqtt_network;
|
Network mqtt_network;
|
||||||
mqtt_network.my_socket = SOCK_MQTT;
|
mqtt_network.my_socket = SOCK_MQTT;
|
||||||
|
|
||||||
printf(">>Trying connect to MQTT broker: %d.%d.%d.%d ..\r\n", MQTT_targetIP[0], MQTT_targetIP[1], MQTT_targetIP[2], MQTT_targetIP[3]);
|
printf(">>Trying connect to MQTT broker: %d.%d.%d.%d ..\r\n", MQTT_targetIP[0], MQTT_targetIP[1], MQTT_targetIP[2], MQTT_targetIP[3]);
|
||||||
NewNetwork(&mqtt_network);
|
NewNetwork(&mqtt_network);
|
||||||
ConnectNetwork(&mqtt_network, MQTT_targetIP, 1883);
|
ConnectNetwork(&mqtt_network, MQTT_targetIP, 1883);
|
||||||
MQTTClient(&mqtt_client, &mqtt_network, 1000, mqtt_buf, 100, mqtt_readBuffer, MQTT_BUFFER_SIZE);
|
MQTTClient(&mqtt_client, &mqtt_network, 1000, mqtt_buf, 100, mqtt_readBuffer, MQTT_BUFFER_SIZE);
|
||||||
|
|
||||||
//Connection to MQTT broker
|
//Connection to MQTT broker
|
||||||
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
|
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
|
||||||
data.willFlag = 0;
|
data.willFlag = 0;
|
||||||
data.MQTTVersion = 4;//3;
|
data.MQTTVersion = 4;//3;
|
||||||
data.clientID.cstring = (char*)"controllino_messmodul";
|
data.clientID.cstring = (char*)"controllino_messmodul";
|
||||||
data.username.cstring = (char*)"Messmodul";
|
data.username.cstring = (char*)"Messmodul";
|
||||||
data.password.cstring = (char*)"\0";
|
data.password.cstring = (char*)"\0";
|
||||||
data.keepAliveInterval = 10;
|
data.keepAliveInterval = 10;
|
||||||
data.cleansession = 1;
|
data.cleansession = 1;
|
||||||
mqtt_rc = MQTTConnect(&mqtt_client, &data);
|
mqtt_rc = MQTTConnect(&mqtt_client, &data);
|
||||||
if (mqtt_rc == SUCCESSS)
|
if (mqtt_rc == SUCCESSS)
|
||||||
{
|
{
|
||||||
printf("++MQTT Connected SUCCESS: %ld\r\n", mqtt_rc);
|
printf("++MQTT Connected SUCCESS: %ld\r\n", mqtt_rc);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("--MQTT Connected ERROR: %ld\r\n", mqtt_rc);
|
printf("--MQTT Connected ERROR: %ld\r\n", mqtt_rc);
|
||||||
//while(1); //Reboot the board
|
//while(1); //Reboot the board
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscribe to all topics
|
// Subscribe to all topics
|
||||||
char SubString[] = "/Filamentanlage/04_Messmodul/set/#";
|
char SubString[] = "/Filamentanlage/04_Messmodul/set/#";
|
||||||
mqtt_rc = MQTTSubscribe(&mqtt_client, SubString, QOS0, messageArrived);
|
mqtt_rc = MQTTSubscribe(&mqtt_client, SubString, QOS0, messageArrived);
|
||||||
printf("Subscribed (%s) %ld\r\n", SubString, mqtt_rc);
|
printf("Subscribed (%s) %ld\r\n", SubString, mqtt_rc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
ioHelperSetBit(outStatesBlinking, LED_PLC_OK, 1);
|
ioHelperSetBit(outStatesBlinking, LED_PLC_OK, 1);
|
||||||
|
|
||||||
uint32_t timer_blink_outs = millis();
|
uint32_t timer_blink_outs = millis();
|
||||||
uint32_t timer_send_uptime = millis();
|
uint32_t timer_send_uptime = millis();
|
||||||
|
|
||||||
OCR3B = 127;
|
OCR3B = 127;
|
||||||
|
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Luefter", "aus", 3);
|
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Luefter", "aus", 3);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
wdt_reset(); // WDT reset at least every sec
|
wdt_reset(); // WDT reset at least every sec
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//if (flag_refresh_inStates) {
|
//if (flag_refresh_inStates) {
|
||||||
ioHelperReadPins();
|
ioHelperReadPins();
|
||||||
ioHelperDebounce();
|
ioHelperDebounce();
|
||||||
ioHelperEdgeDetector();
|
ioHelperEdgeDetector();
|
||||||
// flag_refresh_inStates = 0;
|
// flag_refresh_inStates = 0;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// Toggle all outs which are set to blinking
|
// Toggle all outs which are set to blinking
|
||||||
if(millis() - timer_blink_outs > 500){
|
if(millis() - timer_blink_outs > 500){
|
||||||
outStates[0] ^= outStatesBlinking[0];
|
outStates[0] ^= outStatesBlinking[0];
|
||||||
outStates[1] ^= outStatesBlinking[1];
|
outStates[1] ^= outStatesBlinking[1];
|
||||||
timer_blink_outs = millis();
|
timer_blink_outs = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
// send misc info
|
// send misc info
|
||||||
if(millis() - timer_send_uptime > 5000){
|
if(millis() - timer_send_uptime > 5000){
|
||||||
timer_send_uptime += 5000;
|
timer_send_uptime += 5000;
|
||||||
char msg[64];
|
char msg[64];
|
||||||
sprintf(msg, "%ld", millis()/1000);
|
sprintf(msg, "%ld", millis()/1000);
|
||||||
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/uptime", msg, strlen(msg));
|
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/uptime", msg, strlen(msg));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if(read_Input(BTN_ANLAGE_EIN, RISING)){
|
if(read_Input(BTN_ANLAGE_EIN, RISING)){
|
||||||
printf("anlage in: %x\n\r", read_Input(IN_ANLAGE_EIN, LEVEL));
|
printf("anlage in: %x\n\r", read_Input(IN_ANLAGE_EIN, LEVEL));
|
||||||
}
|
}
|
||||||
// ioHelperSetBit(outStates, LED_GRN_NOTAUS_SCHRANK, 1);
|
// ioHelperSetBit(outStates, LED_GRN_NOTAUS_SCHRANK, 1);
|
||||||
//}
|
//}
|
||||||
//else{
|
//else{
|
||||||
// ioHelperSetBit(outStates, LED_GRN_NOTAUS_SCHRANK, 0);
|
// ioHelperSetBit(outStates, LED_GRN_NOTAUS_SCHRANK, 0);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
do_luefter();
|
do_luefter();
|
||||||
do_notaus();
|
do_notaus();
|
||||||
do_zumbach();
|
do_zumbach();
|
||||||
|
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
ioHelperSetBit(outStates, LED_BUS_OK, 1);
|
ioHelperSetBit(outStates, LED_BUS_OK, 1);
|
||||||
ioHelperSetOuts();
|
ioHelperSetOuts();
|
||||||
MQTTYield(&mqtt_client, 10); //blocking call
|
MQTTYield(&mqtt_client, 10); //blocking call
|
||||||
ioHelperSetBit(outStates, LED_BUS_OK, 0);
|
ioHelperSetBit(outStates, LED_BUS_OK, 0);
|
||||||
#endif
|
#endif
|
||||||
ioHelperSetOuts();
|
ioHelperSetOuts();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timer0
|
// Timer0
|
||||||
// 1ms IRQ
|
// 1ms IRQ
|
||||||
// Used for millis() timing
|
// Used for millis() timing
|
||||||
void timer0_init(void)
|
void timer0_init(void)
|
||||||
{
|
{
|
||||||
TCCR0A = (1<<WGM01); //TIMER0 SET-UP: CTC MODE
|
TCCR0A = (1<<WGM01); //TIMER0 SET-UP: CTC MODE
|
||||||
TCCR0B = (1<<CS01)|(1<<CS00); // PS 1:64
|
TCCR0B = (1<<CS01)|(1<<CS00); // PS 1:64
|
||||||
OCR0A = 249; // 1ms reach for clear (16mz:64=>250kHz:250-=>1kHz)
|
OCR0A = 249; // 1ms reach for clear (16mz:64=>250kHz:250-=>1kHz)
|
||||||
TIMSK0 |= 1<<OCIE0A; //IRQ on TIMER0 output compareA
|
TIMSK0 |= 1<<OCIE0A; //IRQ on TIMER0 output compareA
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer3_init(void)
|
void timer3_init(void)
|
||||||
{
|
{
|
||||||
TCCR3A |= (1<<WGM30); // PWM Mode with ocra top
|
TCCR3A |= (1<<WGM30); // PWM Mode with ocra top
|
||||||
TCCR3B |= (1<<WGM33);
|
TCCR3B |= (1<<WGM33);
|
||||||
OCR3A = TOP_VALUE;
|
OCR3A = TOP_VALUE;
|
||||||
|
|
||||||
TCCR3B |= (0<<CS32)|(1<<CS31)|(0<<CS30); // PS 1:1
|
TCCR3B |= (0<<CS32)|(1<<CS31)|(0<<CS30); // PS 1:1
|
||||||
TCCR3A |= (1<<COM3B1) | (0<<COM3B0);
|
TCCR3A |= (1<<COM3B1) | (0<<COM3B0);
|
||||||
DDRE |= 1 << 4;
|
DDRE |= 1 << 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void avr_init(void)
|
static void avr_init(void)
|
||||||
{
|
{
|
||||||
// Initialize device here.
|
// Initialize device here.
|
||||||
// WatchDog INIT
|
// WatchDog INIT
|
||||||
wdt_enable(WDTO_8S); // set up wdt reset interval 2 second
|
wdt_enable(WDTO_8S); // set up wdt reset interval 2 second
|
||||||
wdt_reset(); // wdt reset ~ every <2000ms
|
wdt_reset(); // wdt reset ~ every <2000ms
|
||||||
|
|
||||||
timer0_init();// Timer0 millis engine init
|
timer0_init();// Timer0 millis engine init
|
||||||
timer3_init();
|
timer3_init();
|
||||||
uart_init();
|
uart_init();
|
||||||
|
|
||||||
sei(); //re-enable global interrupts
|
sei(); //re-enable global interrupts
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_network_information(void)
|
void print_network_information(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint8_t tmpstr[6] = {0,};
|
uint8_t tmpstr[6] = {0,};
|
||||||
ctlwizchip(CW_GET_ID,(void*)tmpstr); // Get WIZCHIP name
|
ctlwizchip(CW_GET_ID,(void*)tmpstr); // Get WIZCHIP name
|
||||||
printf("\r\n=======================================\r\n");
|
printf("\r\n=======================================\r\n");
|
||||||
printf(" WIZnet chip: %s \r\n", tmpstr);
|
printf(" WIZnet chip: %s \r\n", tmpstr);
|
||||||
printf("=======================================\r\n");
|
printf("=======================================\r\n");
|
||||||
|
|
||||||
wiz_NetInfo gWIZNETINFO;
|
wiz_NetInfo gWIZNETINFO;
|
||||||
wizchip_getnetinfo(&gWIZNETINFO);
|
wizchip_getnetinfo(&gWIZNETINFO);
|
||||||
if (gWIZNETINFO.dhcp == NETINFO_STATIC)
|
if (gWIZNETINFO.dhcp == NETINFO_STATIC)
|
||||||
printf("STATIC IP\r\n");
|
printf("STATIC IP\r\n");
|
||||||
else
|
else
|
||||||
printf("DHCP IP\r\n");
|
printf("DHCP IP\r\n");
|
||||||
printf("Mac address: %02x:%02x:%02x:%02x:%02x:%02x\n\r",gWIZNETINFO.mac[0],gWIZNETINFO.mac[1],gWIZNETINFO.mac[2],gWIZNETINFO.mac[3],gWIZNETINFO.mac[4],gWIZNETINFO.mac[5]);
|
printf("Mac address: %02x:%02x:%02x:%02x:%02x:%02x\n\r",gWIZNETINFO.mac[0],gWIZNETINFO.mac[1],gWIZNETINFO.mac[2],gWIZNETINFO.mac[3],gWIZNETINFO.mac[4],gWIZNETINFO.mac[5]);
|
||||||
printf("IP address : %d.%d.%d.%d\n\r",gWIZNETINFO.ip[0],gWIZNETINFO.ip[1],gWIZNETINFO.ip[2],gWIZNETINFO.ip[3]);
|
printf("IP address : %d.%d.%d.%d\n\r",gWIZNETINFO.ip[0],gWIZNETINFO.ip[1],gWIZNETINFO.ip[2],gWIZNETINFO.ip[3]);
|
||||||
printf("SM Mask : %d.%d.%d.%d\n\r",gWIZNETINFO.sn[0],gWIZNETINFO.sn[1],gWIZNETINFO.sn[2],gWIZNETINFO.sn[3]);
|
printf("SM Mask : %d.%d.%d.%d\n\r",gWIZNETINFO.sn[0],gWIZNETINFO.sn[1],gWIZNETINFO.sn[2],gWIZNETINFO.sn[3]);
|
||||||
printf("Gate way : %d.%d.%d.%d\n\r",gWIZNETINFO.gw[0],gWIZNETINFO.gw[1],gWIZNETINFO.gw[2],gWIZNETINFO.gw[3]);
|
printf("Gate way : %d.%d.%d.%d\n\r",gWIZNETINFO.gw[0],gWIZNETINFO.gw[1],gWIZNETINFO.gw[2],gWIZNETINFO.gw[3]);
|
||||||
printf("DNS Server : %d.%d.%d.%d\n\r",gWIZNETINFO.dns[0],gWIZNETINFO.dns[1],gWIZNETINFO.dns[2],gWIZNETINFO.dns[3]);
|
printf("DNS Server : %d.%d.%d.%d\n\r",gWIZNETINFO.dns[0],gWIZNETINFO.dns[1],gWIZNETINFO.dns[2],gWIZNETINFO.dns[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue