]> gitweb.hamatoma.de Git - cpidjinn/commitdiff
client and cpidjinn work
authorhama <hama@siduction.net>
Mon, 13 Jun 2016 21:52:11 +0000 (23:52 +0200)
committerhama <hama@siduction.net>
Mon, 13 Jun 2016 21:52:11 +0000 (23:52 +0200)
.gitignore
Server/bcm2835.cpp
Server/bcm2835.hpp
Server/client.cpp
Server/gpioprocessor.cpp
Server/gpiotimer.cpp
Server/gpiotimer.hpp
util/timer.cpp

index 8fab6219f3c4329e6e5df15cbb4964e6925f161d..1638e53c687ef50015abd1c638b8f7e2731a8a6b 100644 (file)
@@ -1,4 +1,6 @@
 *.o
+cpidjinn
+client
 Server/cpidjinn
 Server/client
 *.kdev4
index 8a5ba9342db0f2d42e168f336821ad3f47c8ac75..bccf8aa30f585007280fc2754e63ecb069f5e33b 100644 (file)
@@ -46,6 +46,7 @@ Bcm2835::Bcm2835(Announcer* logger, bool simulation) :
                m_bscoBase = m_spioBase + blocksize;
                m_pwmBase = m_bscoBase + blocksize;
                m_bsc1Base = m_pwmBase + blocksize;
+               m_endOfRange = m_bsc1Base + blocksize;
                m_valid = true;
        // for RasPI2 we find the data in the device tree:
        } else {
@@ -217,9 +218,16 @@ void Bcm2835::writeToGPIO(PinNumber pin, PinState state){
  * @param value                value to write
  */
 void Bcm2835::writeWord(volatile uint32_t* address, uint32_t value){
-       // atomic access:
-       __sync_synchronize();
-       *address = value;
-       __sync_synchronize();
+       if (m_simulation && (address < m_bcmBase || address >= m_endOfRange)){
+               m_logger->sayf(LOG_ERROR, "writeWord: invalid address: %lld [%lld, %lld]\n",
+                                          (long long int) address,
+                                         (long long int) m_bcmBase,
+                                          (long long int) m_endOfRange);
+       } else {
+               // atomic access:
+               __sync_synchronize();
+               *address = value;
+               __sync_synchronize();
+       }
 }
 
index 6277d2d83afba960e5ad03d16a58a8e9fbfb23df..6293577e942a14837e4913f68ed23c44ce39362f 100644 (file)
@@ -77,6 +77,7 @@ private:
        volatile uint32_t* m_bscoBase;
        volatile uint32_t* m_pwmBase;
        volatile uint32_t* m_bsc1Base;
+       volatile uint32_t* m_endOfRange;
        uint32_t* m_simulatorMemory;
        Announcer* m_logger;
        PinInfo m_pins[pinCount];
index 5be8432c05da9a3279f791d9e16988abc71660a4..cd28f7a5ffbb519228eb5146c9daf64dd575452b 100644 (file)
@@ -34,12 +34,12 @@ static void prepareMelody(PinNumber pin, DynBuffer& buffer){
        addTone(duration, 659255, buffer);
 }
 static void prepareBlink(PinNumber pin, int count, int high, int low, DynBuffer& buffer){
-       buffer.clear().append("MELO");
+       printf("pin: %d count: %d high: %d low: %d\n", pin, count, high, low);
+       buffer.clear().append("BLNK");
        buffer.appendAsLE((int) pin, 1);
        buffer.appendAsLE(count, 4);
        buffer.appendAsLE(high * 1000, 4);
        buffer.appendAsLE(low * 1000, 4);
-
 }
 void usage(const char* msg, const char* argument){
        printf("Usage: client <opts> <command> [<args>]\n"
@@ -121,6 +121,7 @@ int main (int argc, char **argv) {
        TcpClient client(&logger);
        if (client.connect(host, port)){
                client.sendAndReceive(buffer);
+               printf("Received: %s\n", buffer.str());
        }
        client.disconnect();
        return 0;
index ba835d156fff486d761e2d4d39bda5ef43e1c55e..75a0780717d63f71d31054677d89f61b12b1cc46 100644 (file)
@@ -29,7 +29,7 @@ GPIOProcessor::~GPIOProcessor()
  *                                             OUT: answer for the client
  */
 void GPIOProcessor::blink(DynBuffer& buffer){
-       if (buffer.length() != 4 + 1 + 2*4){
+       if (buffer.length() != 4 + 1 + 3*4){
                buffer.clear().appendFormatted("ERR wrong packet length %d instead of %d",
                                                                        buffer.length(), 4 + 1 + 2*4);
        } else {
@@ -37,7 +37,9 @@ void GPIOProcessor::blink(DynBuffer& buffer){
                int count = buffer.valueOfLE(4, 5);
                int periodHigh = buffer.valueOfLE(4, 5 + 4);
                int periodLow = buffer.valueOfLE(4, 5 + 2*4);
-               new SquareWaveTimer(pin, 0, count, periodHigh, periodLow, m_logger, &m_pool);
+               SquareWaveTimer* timer = new SquareWaveTimer(pin, 0, count, periodHigh, periodLow,
+                                                                                                        this, m_logger, &m_pool);
+               timer->start();
                printf("Pin: %d count: %d high: %d low: %d\n", (int) pin, count, periodHigh, periodLow);
                buffer.set("OK  ");
        }
index 9d168535945d60d48b7c11d1c35066d42d2b2c31..69e8ab997fbfa9329dfb4304b8d8f8edf9d95dc9 100644 (file)
@@ -8,9 +8,11 @@
  * @param logger       the logger
  * @param pool         the pool managing the timer threads
  */
-GPIOTimer::GPIOTimer(PinNumber pin, uint64_t pause, Announcer* logger, ThreadPool* pool) :
+GPIOTimer::GPIOTimer(PinNumber pin, uint64_t pause, GPIOProcessor* gpioProcessor,
+               Announcer* logger, ThreadPool* pool) :
        Timer(1, 0, pause, uMicroSeconds, true, logger, pool),
-       m_pin(pin)
+       m_pin(pin),
+       m_processor(gpioProcessor)
 {
 }
 
@@ -33,17 +35,20 @@ void GPIOTimer::switchState(PinState state){
 /**
  * Constructor.
  *
- * @param pin          the target pin
- * @param pause                the pause (in microseconds) to wait before starting the wave
- * @param count                the number of high states to create
- * @param high         the duration of the high state in microseconds
- * @param low          the duration of the low state in microseconds
- * @param logger       the logger
- * @param pool         the pool managing the timer threads
+ * @param pin                  the target pin
+ * @param pause                        the pause (in microseconds) to wait before starting the wave
+ * @param count                        the number of high states to create
+ * @param high                 the duration of the high state in microseconds
+ * @param low                  the duration of the low state in microseconds
+ * @param gpioProcessor        access to the SoC
+ * @param logger               the logger
+ * @param pool                 the pool managing the timer threads
  */
 SquareWaveTimer::SquareWaveTimer(PinNumber pin, uint64_t pause, int count,
-                                                                uint64_t high, uint64_t low, Announcer* logger, ThreadPool* pool) :
-       GPIOTimer(pin, pause, logger, pool),
+                                                                uint64_t high, uint64_t low,
+                                                                GPIOProcessor* gpioProcessor,
+                                                                Announcer* logger, ThreadPool* pool) :
+       GPIOTimer(pin, pause, gpioProcessor, logger, pool),
        m_pause(pause),
        m_high(high),
        m_low(low),
index 9834b75cf396a67a4a912968389cae3011b0ff70..76a8e4cb521976eef89b117e95d80e832eaaeab0 100644 (file)
@@ -6,7 +6,7 @@
  */
 class GPIOTimer : public Timer {
 public:
-    GPIOTimer(PinNumber pin, uint64_t pause, Announcer* logger, ThreadPool* pool);
+    GPIOTimer(PinNumber pin, uint64_t pause, GPIOProcessor* gpioProcessor, Announcer* logger, ThreadPool* pool);
     virtual ~GPIOTimer();
 private:
        // not implemented, private to avoid usage
@@ -25,7 +25,8 @@ protected:
 class SquareWaveTimer : public GPIOTimer{
 public:
        SquareWaveTimer(PinNumber pin, uint64_t pause, int count,
-                                                                uint64_t high, uint64_t low, Announcer* logger, ThreadPool* pool);
+                               uint64_t high, uint64_t low,
+                               GPIOProcessor* gpioProcessor, Announcer* logger, ThreadPool* pool);
 public:
        virtual void timerTask();
 private:
index 13a0a93affba6d42331b699219d6333c3fb2666d..5b2b0397d1fbab65d69ef296625ecfc0c0535074 100644 (file)
@@ -1,5 +1,5 @@
 #include "util.hpp"
-//#define TRACE_ON
+#define TRACE_ON
 #include "trace.hpp"
 /**
  * Constructor.
@@ -37,7 +37,7 @@ void Timer::run(){
                sleep(m_startDelay);
        }
        while(! m_shouldStop && m_taskCount-- > 0){
-               trace2("Timer::run(%d): %d\n", threadId(), m_count);
+               trace2("Timer::run(%d): %d\n", threadId(), m_taskCount);
                timerTask();
                sleep(m_delay);
        }