*.o
+cpidjinn
+client
Server/cpidjinn
Server/client
*.kdev4
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 {
* @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();
+ }
}
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];
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"
TcpClient client(&logger);
if (client.connect(host, port)){
client.sendAndReceive(buffer);
+ printf("Received: %s\n", buffer.str());
}
client.disconnect();
return 0;
* 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 {
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 ");
}
* @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)
{
}
/**
* 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),
*/
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
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:
#include "util.hpp"
-//#define TRACE_ON
+#define TRACE_ON
#include "trace.hpp"
/**
* Constructor.
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);
}