signal
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
const int CTRL_OUT = 16;
|
||||
const int INTR_IN = 19;
|
||||
@ -61,8 +61,10 @@ const uint8_t MDR1_F_CY = 0b10000000;
|
||||
|
||||
|
||||
volatile uint32_t ec = 0;
|
||||
volatile uint32_t savedCounter = 0;
|
||||
uint32_t lastSavedCounter = 0;
|
||||
volatile uint32_t diff = 0;
|
||||
|
||||
pthread_mutex_t eventMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t eventSignal = PTHREAD_COND_INITIALIZER;
|
||||
|
||||
void writeCmd(uint8_t c) {
|
||||
uint8_t buf[1];
|
||||
@ -93,8 +95,18 @@ uint32_t read32(uint8_t c) {
|
||||
}
|
||||
|
||||
void isr() {
|
||||
savedCounter = read32(CMD_RD | REG_OTR);
|
||||
static uint32_t lastCounter = 0;
|
||||
|
||||
uint32_t currentCounter = read32(CMD_RD | REG_OTR);
|
||||
|
||||
diff = currentCounter - lastCounter;
|
||||
lastCounter = currentCounter;
|
||||
|
||||
ec++;
|
||||
|
||||
pthread_mutex_lock(&eventMutex);
|
||||
pthread_cond_signal(&eventSignal);
|
||||
pthread_mutex_unlock(&eventMutex);
|
||||
}
|
||||
|
||||
void init() {
|
||||
@ -120,10 +132,10 @@ int main (void) {
|
||||
initCounter();
|
||||
|
||||
while (1) {
|
||||
uint32_t diff = savedCounter - lastSavedCounter;
|
||||
lastSavedCounter = savedCounter;
|
||||
printf("%d %d\n", ec, diff);
|
||||
pthread_mutex_lock(&eventMutex);
|
||||
pthread_cond_wait(&eventSignal, &eventMutex);
|
||||
pthread_mutex_unlock(&eventMutex);
|
||||
|
||||
sleep(1);
|
||||
printf("%d %d\n", ec, diff);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user