]> git.sesse.net Git - pistorm/blobdiff - a314/a314.cc
Add Meson build files.
[pistorm] / a314 / a314.cc
index c14e7c188f35c8fb16e0dc2fbed783b13216c36a..38f312a22ffe3cc5971eb0b3ce25edc619493770 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2020 Niklas Ekström
+ * Copyright 2020-2021 Niklas Ekström
  * Based on a314d daemon for A314.
  */
 
@@ -109,6 +109,8 @@ static int server_socket = -1;
 static int epfd = -1;
 static int irq_fds[2];
 
+extern "C" unsigned int ps_read_8(unsigned int address);
+extern "C" void ps_write_8(unsigned int address, unsigned int value);
 extern "C" void ps_write_16(unsigned int address, unsigned int value);
 
 unsigned int a314_base;
@@ -219,14 +221,15 @@ struct OnDemandStart
 
 std::vector<OnDemandStart> on_demand_services;
 
-std::string a314_config_file = "/etc/opt/a314/a314d.conf";
-std::string home_env = "HOME=/home/pi";
+std::string a314_config_file = "./a314/files_pi/a314d.conf";
+std::string home_env = "HOME=./";
 
 static void load_config_file(const char *filename)
 {
     FILE *f = fopen(filename, "rt");
-    if (f == nullptr)
+    if (f == nullptr) {
         return;
+    }
 
     char line[256];
     std::vector<char *> parts;
@@ -413,6 +416,8 @@ static void handle_msg_deregister_req(ClientConnection *cc)
     create_and_send_msg(cc, MSG_DEREGISTER_RES, 0, &result, 1);
 }
 
+uint8_t manual_read_buf[64 * SIZE_KILO];
+
 static void handle_msg_read_mem_req(ClientConnection *cc)
 {
     uint32_t address = *(uint32_t *)&(cc->payload[0]);
@@ -422,9 +427,14 @@ static void handle_msg_read_mem_req(ClientConnection *cc)
         int32_t index = get_mapped_item_by_address(cfg, address);
         uint8_t *map = &cfg->map_data[index][address - cfg->map_offset[index]];
         create_and_send_msg(cc, MSG_READ_MEM_RES, 0, map, length);
+    } else {
+        // No idea if this actually works.
+        for (int i = 0; i < length; i++) {
+            manual_read_buf[i] = (unsigned char)ps_read_8(address + i);
+        }
+        create_and_send_msg(cc, MSG_READ_MEM_RES, 0, manual_read_buf, length);
     }
-    else // FIXME
-        printf("help.\n");
+    
 }
 
 static void handle_msg_write_mem_req(ClientConnection *cc)
@@ -432,14 +442,16 @@ static void handle_msg_write_mem_req(ClientConnection *cc)
     uint32_t address = *(uint32_t *)&(cc->payload[0]);
     uint32_t length = cc->payload.size() - 4;
 
-
     if (get_mapped_item_by_address(cfg, address) != -1) {
         int32_t index = get_mapped_item_by_address(cfg, address);
         uint8_t *map = &cfg->map_data[index][address - cfg->map_offset[index]];
         memcpy(map, &(cc->payload[4]), length);
+    } else {
+        // No idea if this actually works.
+        for (int i = 0; i < length; i++) {
+            ps_write_8(address + i, cc->payload[4 + i]);
+        }
     }
-    else // FIXME
-        printf("help 2.\n");
 
     create_and_send_msg(cc, MSG_WRITE_MEM_RES, 0, nullptr, 0);
 }