raspberrypi gpio interrupt rtems

I’m trying to develop an RTEMS application that decodes a message that’s encoded with Manchester encoder transmitted by the transmitter board.
Two Raspberry Pi 2 are mounted on the board, which are connected to each other via GPIO 4 and GND. One of the Rpi is the transmitter, and sends a sequence of pulses every 10s. These pulses encode a message according to the Manchester code. The IEEE version of the code is used. There is a promise that the first bit is a 0 bit.

I’m having trouble getting the signal. For now, I’m only trying to get the signal based on edges, but I’m not getting the signal printed.

I’ve been trying for 2 days but I don’t really now what I’m doing wrong. Any help is greatly appreciated

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#define GPIO_PIN 4
#define MAX_EDGES 4096
#define SIGNAL_GAP_MS 100
volatile int edge_count = 0;
volatile rtems_interval edge_times[MAX_EDGES];
volatile rtems_interval last_edge_time = 0;
volatile uint32_t edge_values[MAX_EDGES];
volatile bool new_signal_ready = false;
void handler(void *arg) {
rtems_interval current_time = rtems_clock_get_ticks_since_boot();
uint8_t value = rtems_gpio_bsp_get_value(0, GPIO_PIN);
rtems_interval time_since_last_edge = current_time - last_edge_time;
if (time_since_last_edge >
rtems_clock_get_ticks_per_second() * SIGNAL_GAP_MS / 1000) {
if (edge_count > 0) {
new_signal_ready = true;
}
edge_count = 0;
}
if (edge_count < MAX_EDGES) {
edge_times[edge_count] = current_time - last_edge_time;
edge_values[edge_count] = value;
edge_count++;
}
last_edge_time = current_time;
}
void init_gpio(void) {
rtems_status_code sc;
sc = rtems_gpio_bsp_select_input(0, GPIO_PIN, NULL);
if (sc != RTEMS_SUCCESSFUL) {
printk("Failed to set GPIO %d as input. Error code: %sn", GPIO_PIN,
rtems_status_text(sc));
return;
}
sc = rtems_gpio_bsp_set_resistor_mode(0, GPIO_PIN, PULL_UP);
if (sc != RTEMS_SUCCESSFUL) {
printk("Failed to set pull-up resistor for GPIO %d. Error code: %sn",
GPIO_PIN, rtems_status_text(sc));
return;
}
printk("GPIO %d initialized as input with pull-up.n", GPIO_PIN);
}
void interrupt_config(void) {
rtems_status_code sc;
sc = rtems_gpio_bsp_enable_interrupt(0, GPIO_PIN, BOTH_EDGES);
if (sc != RTEMS_SUCCESSFUL) {
printk("Failed to enable interrupt on GPIO %d. Error code: %sn", GPIO_PIN,
rtems_status_text(sc));
return;
}
printk("Interrupt enabled on GPIO %d.n", GPIO_PIN);
sc = rtems_interrupt_handler_install(rtems_gpio_bsp_get_vector(0),
"GPIO Interrupt Handler",
RTEMS_INTERRUPT_UNIQUE, handler, NULL);
if (sc != RTEMS_SUCCESSFUL) {
printk("Failed to install interrupt handler. Error code: %sn",
rtems_status_text(sc));
return;
} else {
printk("Interrupt handler installed.n");
}
}
void print_signal(void) {
printk("Signal received with %d edges:n", edge_count);
for (int i = 0; i < edge_count; i++) {
printk("%d", edge_values[i]);
}
printk("nEnd of signal sequence.nn");
}
void reset_signal_data(void) {
edge_count = 0;
for (int i = 0; i < MAX_EDGES; i++) {
edge_times[i] = 0;
edge_values[i] = 0;
}
}
rtems_task Init(rtems_task_argument argument) {
rtems_status_code sc;
printk("Initializing ...n");
sc = rtems_gpio_initialize();
if (sc != RTEMS_SUCCESSFUL) {
printk("Failed to initialize GPIO. Error code: %sn",
rtems_status_text(sc));
return;
} else {
printk("GPIO API initialized.n");
}
init_gpio();
interrupt_config();
while (1) {
if (new_signal_ready) {
print_signal();
new_signal_ready = false;
}
reset_signal_data();
rtems_task_wake_after(1);
}
}
</code>
<code>#define GPIO_PIN 4 #define MAX_EDGES 4096 #define SIGNAL_GAP_MS 100 volatile int edge_count = 0; volatile rtems_interval edge_times[MAX_EDGES]; volatile rtems_interval last_edge_time = 0; volatile uint32_t edge_values[MAX_EDGES]; volatile bool new_signal_ready = false; void handler(void *arg) { rtems_interval current_time = rtems_clock_get_ticks_since_boot(); uint8_t value = rtems_gpio_bsp_get_value(0, GPIO_PIN); rtems_interval time_since_last_edge = current_time - last_edge_time; if (time_since_last_edge > rtems_clock_get_ticks_per_second() * SIGNAL_GAP_MS / 1000) { if (edge_count > 0) { new_signal_ready = true; } edge_count = 0; } if (edge_count < MAX_EDGES) { edge_times[edge_count] = current_time - last_edge_time; edge_values[edge_count] = value; edge_count++; } last_edge_time = current_time; } void init_gpio(void) { rtems_status_code sc; sc = rtems_gpio_bsp_select_input(0, GPIO_PIN, NULL); if (sc != RTEMS_SUCCESSFUL) { printk("Failed to set GPIO %d as input. Error code: %sn", GPIO_PIN, rtems_status_text(sc)); return; } sc = rtems_gpio_bsp_set_resistor_mode(0, GPIO_PIN, PULL_UP); if (sc != RTEMS_SUCCESSFUL) { printk("Failed to set pull-up resistor for GPIO %d. Error code: %sn", GPIO_PIN, rtems_status_text(sc)); return; } printk("GPIO %d initialized as input with pull-up.n", GPIO_PIN); } void interrupt_config(void) { rtems_status_code sc; sc = rtems_gpio_bsp_enable_interrupt(0, GPIO_PIN, BOTH_EDGES); if (sc != RTEMS_SUCCESSFUL) { printk("Failed to enable interrupt on GPIO %d. Error code: %sn", GPIO_PIN, rtems_status_text(sc)); return; } printk("Interrupt enabled on GPIO %d.n", GPIO_PIN); sc = rtems_interrupt_handler_install(rtems_gpio_bsp_get_vector(0), "GPIO Interrupt Handler", RTEMS_INTERRUPT_UNIQUE, handler, NULL); if (sc != RTEMS_SUCCESSFUL) { printk("Failed to install interrupt handler. Error code: %sn", rtems_status_text(sc)); return; } else { printk("Interrupt handler installed.n"); } } void print_signal(void) { printk("Signal received with %d edges:n", edge_count); for (int i = 0; i < edge_count; i++) { printk("%d", edge_values[i]); } printk("nEnd of signal sequence.nn"); } void reset_signal_data(void) { edge_count = 0; for (int i = 0; i < MAX_EDGES; i++) { edge_times[i] = 0; edge_values[i] = 0; } } rtems_task Init(rtems_task_argument argument) { rtems_status_code sc; printk("Initializing ...n"); sc = rtems_gpio_initialize(); if (sc != RTEMS_SUCCESSFUL) { printk("Failed to initialize GPIO. Error code: %sn", rtems_status_text(sc)); return; } else { printk("GPIO API initialized.n"); } init_gpio(); interrupt_config(); while (1) { if (new_signal_ready) { print_signal(); new_signal_ready = false; } reset_signal_data(); rtems_task_wake_after(1); } } </code>
#define GPIO_PIN 4
#define MAX_EDGES 4096
#define SIGNAL_GAP_MS 100

volatile int edge_count = 0;
volatile rtems_interval edge_times[MAX_EDGES];
volatile rtems_interval last_edge_time = 0;
volatile uint32_t edge_values[MAX_EDGES];
volatile bool new_signal_ready = false;

void handler(void *arg) {
  rtems_interval current_time = rtems_clock_get_ticks_since_boot();
  uint8_t value = rtems_gpio_bsp_get_value(0, GPIO_PIN);
  rtems_interval time_since_last_edge = current_time - last_edge_time;

  if (time_since_last_edge >
      rtems_clock_get_ticks_per_second() * SIGNAL_GAP_MS / 1000) {
    if (edge_count > 0) {
      new_signal_ready = true;
    }
    edge_count = 0;
  }

  if (edge_count < MAX_EDGES) {
    edge_times[edge_count] = current_time - last_edge_time;
    edge_values[edge_count] = value;

    edge_count++;
  }

  last_edge_time = current_time;
}

void init_gpio(void) {
  rtems_status_code sc;

  sc = rtems_gpio_bsp_select_input(0, GPIO_PIN, NULL);
  if (sc != RTEMS_SUCCESSFUL) {
    printk("Failed to set GPIO %d as input. Error code: %sn", GPIO_PIN,
           rtems_status_text(sc));
    return;
  }

  sc = rtems_gpio_bsp_set_resistor_mode(0, GPIO_PIN, PULL_UP);
  if (sc != RTEMS_SUCCESSFUL) {
    printk("Failed to set pull-up resistor for GPIO %d. Error code: %sn",
           GPIO_PIN, rtems_status_text(sc));
    return;
  }

  printk("GPIO %d initialized as input with pull-up.n", GPIO_PIN);
}

void interrupt_config(void) {
  rtems_status_code sc;

  sc = rtems_gpio_bsp_enable_interrupt(0, GPIO_PIN, BOTH_EDGES);
  if (sc != RTEMS_SUCCESSFUL) {
    printk("Failed to enable interrupt on GPIO %d. Error code: %sn", GPIO_PIN,
           rtems_status_text(sc));
    return;
  }

  printk("Interrupt enabled on GPIO %d.n", GPIO_PIN);

  sc = rtems_interrupt_handler_install(rtems_gpio_bsp_get_vector(0),
                                       "GPIO Interrupt Handler",
                                       RTEMS_INTERRUPT_UNIQUE, handler, NULL);

  if (sc != RTEMS_SUCCESSFUL) {
    printk("Failed to install interrupt handler. Error code: %sn",
           rtems_status_text(sc));
    return;
  } else {
    printk("Interrupt handler installed.n");
  }
}

void print_signal(void) {
  printk("Signal received with %d edges:n", edge_count);

  for (int i = 0; i < edge_count; i++) {
    printk("%d", edge_values[i]);
  }

  printk("nEnd of signal sequence.nn");
}

void reset_signal_data(void) {
  edge_count = 0;
  for (int i = 0; i < MAX_EDGES; i++) {
    edge_times[i] = 0;
    edge_values[i] = 0;
  }
}

rtems_task Init(rtems_task_argument argument) {
  rtems_status_code sc;

  printk("Initializing ...n");

  sc = rtems_gpio_initialize();
  if (sc != RTEMS_SUCCESSFUL) {
    printk("Failed to initialize GPIO. Error code: %sn",
           rtems_status_text(sc));
    return;
  } else {
    printk("GPIO API initialized.n");
  }

  init_gpio();
  interrupt_config();

  while (1) {
    if (new_signal_ready) {
      print_signal();
      new_signal_ready = false;
    }

    reset_signal_data();
    rtems_task_wake_after(1);
  }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật