#define MSG_SDS_UPD 'u'
#define MSG_SPEC 'c'
+#define LOOPDELAY 100
+
void read_message(void)
{
//Find next task
}
}
+unsigned long loopmillis = 0;
void loop(void)
{
+#ifdef ARDUINO_ESP8266_NODEMCU
+ if(getmillis()-loopmillis < LOOPDELAY){
+ return;
+ }
+#endif
+
int ct;
long cyclestart;
struct task *curtask;
#endif
//Initialize systems
- setup();
+ real_setup();
sds_init();
task_init();
debug("sending device spec");
+
+#ifndef ARDUINO_ESP8266_NODEMCU
while(true){
//Check for newtasks
loop();
- msdelay(100);
+ msdelay(LOOPDELAY);
}
-#ifndef ARDUINO_ESP8266_NODEMCU
return 0;
#endif
}
#ifndef INTERFACE_H
#define INTERFACE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <stdbool.h>
#include <stdint.h>
#include <stdarg.h>
#endif
/* Delay and communication */
-long getmillis(void);
-void msdelay(long ms);
+unsigned long getmillis(void);
+void msdelay(unsigned long ms);
/* Auxilliary */
-void setup(void);
+void real_setup(void);
void debug(char *fmt, ...);
void pdie(char *s);
void die(char *fmt, ...);
+#ifdef __cplusplus
+}
+#endif
#endif
char stack[STACKSIZE] = {0};
debug("Running task with length: %d", plen);
while(pc < plen){
-// debug("program: %d", program[pc]);
-// debug("stack: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
-// stack[0], stack[1], stack[2], stack[3], stack[4],
-// stack[5], stack[6], stack[7], stack[8], stack[9]);
-
switch(program[pc++]){
case BCNOP: trace("nop");
break;
#define STACKSIZE 1024
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <stdint.h>
#include <stdbool.h>
void run_task(struct task *task);
+#ifdef __cplusplus
+}
+#endif
#endif
(void)i;
}
-void setup(void)
+void real_setup(void)
{
int port = 8123, opti = 1;
//Register signal handler
--- /dev/null
+#include <Arduino.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+unsigned long getmillis(void)
+{
+ return millis();
+}
+
+void msdelay(unsigned long ms)
+{
+ delay(ms);
+}
+
+bool input_available(void)
+{
+ return Serial.available();
+}
+
+uint8_t read_byte(void)
+{
+ return Serial.read();
+}
+
+void write_byte(uint8_t b)
+{
+ Serial.write(b);
+}
+
+void real_setup(void)
+{
+ Serial.begin(115200);
+ Serial.println("Hello world!");
+}
+
+void debug(char *fmt, ...)
+{
+ Serial.print(fmt);
+}
+
+void die(char *fmt, ...)
+{
+ Serial.print(fmt);
+ while(1){
+ msdelay(100);
+ Serial.print("die");
+ }
+}
+
+void pdie(char *s)
+{
+ die(s);
+}
#ifndef SDS_H
#define SDS_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <stdbool.h>
struct sds {
int sds_fetch(int id);
void sds_store(int id, int val);
+#ifdef __cplusplus
+}
+#endif
#endif
#ifndef SPEC_H
#define SPEC_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
void spec_send(void);
+#ifdef __cplusplus
+}
+#endif
+
#endif
chThdSleepMilliseconds(ms);
}
-void setup(void)
+void real_setup(void)
{
// palSetPadMode(GPIOG, 9, PAL_MODE_ALTERNATE(8)); // USART6 TX
// palSetPadMode(GPIOG, 14, PAL_MODE_ALTERNATE(8)); // USART6 RX
#define MAXTASKSIZE 1024
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <stdint.h>
#include <stdbool.h>
void task_delete(void);
struct task *task_get(int num);
+#ifdef __cplusplus
+}
+#endif
#endif