Guten Tag zusammen
und zwar habe ich im Moment einen Arduino due im Einsatz wo ich versuche ein RTOS drauf zu installieren, welches auch so weit funktioniert (bei den Beispiel Skatches). Ich habe leider das Problem, dass er bei meinem Skatch hängen bleibt beim "beginn" eines Oled oder Ethernet.
Jetzt hier in meinen runter gekürzten Skatch ist es das Ethernet. Das Shield für das Ethernet ist eins mit einem SD karten slot und dem chip W5500.(ARD SHD W5500 mit mega2560)
Hauptteil
#include "system.h"
volatile uint32_t count = 0;
SemaphoreHandle_t shSPI;
void setup() {
Serial.begin(SYSTEM_MAIN_SERIAL_BAUD);
Serial.print (F("FlexOS "));
Serial.print (F(VERSION));
Serial.println (F(" is booting."));
// create semaphore for SPI interface
vWATCHDOGInit();
vEthernetInit();
vWatchdogStart ();
Serial.println("TaskScheduler is starting now....");
vTaskStartScheduler();
Serial.println(F("System died...;("));
while (1);
}
void loop() {}
Ethernet Teil
#define REQ_BUF_SZ 60
#define ChoseArduinoET '1' //Der Arduino wird nur angesteuert
#define ServerAdress 80
#define fileWebsite "index.htm"
EthernetServer server(ServerAdress); // create a server at port 80
File webFile; // the web page file on the SD card
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0; // index into HTTP_req buffer
/******************************************************************************/
static void vEthernetTask(void *pvParameters) {
while (1) {
vTaskDelay((SYSTEM_TASK_TIME_ETHERNET * configTICK_RATE_HZ) / 1000L);
vEthernetStandard();
}
}
/******************************************************************************/
void vEthernetStandard() {
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (req_index < (REQ_BUF_SZ - 1)) {
HTTP_req[req_index] = c; // save HTTP request character
req_index++;
}
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
if (StrContains(HTTP_req, "ajax_inputs")) {
client.println("Content-Type: text/xml");
client.println("Connection: keep-alive");
client.println();
vSetGRBLBefehle();
}
else { // web page request
client.println("Content-Type: text/html");
client.println("Connection: keep-alive");
client.println();
// send web page
webFile = SD.open(fileWebsite);
if (webFile) {
while (webFile.available()) {
client.write(webFile.read());
}
webFile.close();
}
}
#if defined DebugEthernetCommand
Serial.print(HTTP_req);
#endif
req_index = 0;
StrClear(HTTP_req, REQ_BUF_SZ);
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}
// checks if received HTTP request is switching on/off LEDs
// also saves the state of the LEDs
void vSetGRBLBefehle(void) {
}
// sets every element of str to 0 (clears array)
void StrClear(char *str, char length) {
for (int i = 0; i < length; i++) {
str[i] = 0;
}
}
// searches for the string sfind in the string str
// returns 1 if string found
// returns 0 if string not found
char StrContains(char *str, char *sfind) {
char found = 0;
char index = 0;
char len;
len = strlen(str);
if (strlen(sfind) > len) {
return 0;
}
while (index < len) {
if (str[index] == sfind[found]) {
found++;
if (strlen(sfind) == found) {
return 1;
}
}
else {
found = 0;
}
index++;
}
return 0;
}
void vEthernetInit () {
xTaskCreate(vEthernetTask,
"TaskE",
configMINIMAL_STACK_SIZE + 512,
NULL,
tskIDLE_PRIORITY + SYSTEM_TASK_PRIORITY_ETHERNET,
ðernet);
// disable Ethernet chip
// pinMode(10, OUTPUT);
//digitalWrite(10, HIGH);
// initialize SD card
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("ERROR - SD card initialization failed!");
}
else {
Serial.println("SUCCESS - SD card initialized.");
}
// check for fileWebsite file
if (!SD.exists(fileWebsite)) {
Serial.println("ERROR - Can't find fileWebsite file!");
}
else{
Serial.println("SUCCESS - Found fileWebsite file.");
}
Serial.println("bin vor Ethernet Beginnnn");
Ethernet.begin(aucMac, ip); // initialize Ethernet device
Serial.println("Ethernet hat begonnen");
server.begin(); // start to listen for clients
Serial.println("Server ist gestartet");
}
Konfig (System.h)
#include <FreeRTOS_ARM.h>
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
byte aucMac[] = {0x90, 0xA2, 0xDA, 0x00, 0x51, 0x06};
IPAddress ip (192, 168, 137, 2);
#define VERSION "Version0.1"
#define SYSTEM_PIN_DEBUG_LED 13
#define SYSTEM_MAIN_SERIAL_BAUD 19200
#define watchdogTime 2000
#define SYSTEM_TASK_PRIORITY_WATCHDOG 0
#define SYSTEM_TASK_PRIORITY_ETHERNET 1
#define SYSTEM_TASK_TIME_WATCHDOG 400L
#define SYSTEM_TASK_TIME_ETHERNET 500L
#define SYSTEM_SIGN_WATCHDOG 0x00000080
#define SYSTEM_SIGN_ETHERNET 0x00000400
TaskHandle_t watchdog;
TaskHandle_t ethernet;
Watchdog
static void vWatchdogTask(void *pvParameters) {
TickType_t xLastExecutionTime;
bool bToggle = false;
while (1) {
vTaskDelayUntil(&xLastExecutionTime, SYSTEM_TASK_TIME_WATCHDOG/portTICK_PERIOD_MS);
watchdogReset();
bToggle = !bToggle;
digitalWrite (SYSTEM_PIN_DEBUG_LED, bToggle);
}
}
void vWATCHDOGInit() {
xTaskCreate(vWatchdogTask,
"TaskW",
configMINIMAL_STACK_SIZE + 100,
NULL,
SYSTEM_TASK_PRIORITY_WATCHDOG,
&watchdog);
pinMode (SYSTEM_PIN_DEBUG_LED, OUTPUT);
// ulSystemInitState |= SYSTEM_SIGN_WATCHDOG;
Serial.println (F("--> watchdog created + PIN13 LED"));
}
void vWatchdogStart () {
watchdogEnable(watchdogTime);
Serial.println (F("Watchdog started..."));
}
der Skatch besteht hast vier Teilen. Habe auch schon ein wenig rumprobiert etc. Das der Ethernet Skatch nicht komplett ist, ist meine Absicht. Der wäre ein wenig zu lang und da er sowieso sich beim Initialisieren aufhängt ist dieser sowieso Irrelevant.