add led blink when recv data from nrf24l01
This commit is contained in:
@@ -5,18 +5,21 @@
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#define TASK_SIZE 1024
|
#define TASK_SIZE 1024
|
||||||
|
k_task_t task2_handle
|
||||||
|
|
||||||
k_task_t task1_handle;
|
|
||||||
k_task_t task2_handle;
|
|
||||||
k_task_t led_handle;
|
|
||||||
|
|
||||||
uint8_t task1_stk[TASK_SIZE];
|
|
||||||
uint8_t task2_stk[TASK_SIZE*1];
|
uint8_t task2_stk[TASK_SIZE*1];
|
||||||
uint8_t led_stk[TASK_SIZE/2];
|
|
||||||
|
|
||||||
|
#define LCD_TASK_SIZE 1024
|
||||||
|
k_task_t lcd_handle;
|
||||||
|
uint8_t lcd_stk[LCD_TASK_SIZE];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define LED_TASK_SIZE 1024
|
||||||
|
k_task_t led_handle;
|
||||||
|
uint8_t led_stk[LED_TASK_SIZE];
|
||||||
|
|
||||||
|
k_sem_t sem_led;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int port;
|
int port;
|
||||||
@@ -30,18 +33,17 @@ Led_t leds[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void task1(void *arg)
|
void task_led(void *arg)
|
||||||
{
|
{
|
||||||
int task_cnt1 = 0;
|
int task_cnt1 = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("hello world from %s cnt: %d\n", __func__, task_cnt1++);
|
printf("hello world from %s cnt: %d\n", __func__, task_cnt1++);
|
||||||
|
|
||||||
for(int i=0; i<sizeof(leds)/sizeof(Led_t); i++) {
|
tos_sem_pend(&sem_led, ~0);
|
||||||
int on = !(task_cnt1 & (1 << i));
|
|
||||||
gpio_bit_write(leds[i].port, leds[i].pin, on);
|
|
||||||
}
|
|
||||||
|
|
||||||
tos_task_delay(1000);
|
gpio_bit_reset(LEDR_GPIO_PORT, LEDR_PIN);
|
||||||
|
tos_task_delay(50);
|
||||||
|
gpio_bit_set(LEDR_GPIO_PORT, LEDR_PIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +57,7 @@ void task2(void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void task_led(void *arg)
|
void task_lcd(void *arg)
|
||||||
{
|
{
|
||||||
uint16_t color_table[] = { WHITE, BLUE, RED, GREEN, CYAN, YELLOW, GRAY};
|
uint16_t color_table[] = { WHITE, BLUE, RED, GREEN, CYAN, YELLOW, GRAY};
|
||||||
|
|
||||||
@@ -92,9 +94,11 @@ void main(void) {
|
|||||||
|
|
||||||
nrf24l01_init();
|
nrf24l01_init();
|
||||||
|
|
||||||
//tos_task_create(&task1_handle, "task1", task1, NULL, 2, task1_stk, TASK_SIZE, 0);
|
|
||||||
|
tos_sem_create(&sem_led, 1);
|
||||||
|
tos_task_create(&led_handle, "led", task_led, NULL, 6, led_stk, LED_TASK_SIZE, 0);
|
||||||
//tos_task_create(&task2_handle, "task2", task2, NULL, 3, task2_stk, TASK_SIZE*1, 0);
|
//tos_task_create(&task2_handle, "task2", task2, NULL, 3, task2_stk, TASK_SIZE*1, 0);
|
||||||
//tos_task_create(&led_handle, "led", task_led, NULL, 2, led_stk, TASK_SIZE/2, 0);
|
//tos_task_create(&lcd_handle, "lcd", task_lcd, NULL, 2, lcd_stk, TASK_SIZE, 0);
|
||||||
|
|
||||||
tos_knl_start();
|
tos_knl_start();
|
||||||
|
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
#include "nrf24.h"
|
#include "nrf24.h"
|
||||||
#include "tos_k.h"
|
#include "tos_k.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
extern k_sem_t sem_led;
|
||||||
|
k_sem_t sem_nrf_recv;
|
||||||
int flag = 0;
|
int flag = 0;
|
||||||
#define TASK_SIZE (8*1024)
|
#define TASK_SIZE (8*1024)
|
||||||
k_task_t task_nrf24_handle;
|
k_task_t task_nrf24_handle;
|
||||||
@@ -84,7 +85,7 @@ void EXTI0_IRQHandler(void)
|
|||||||
nrf_hal_read_reg_byte(REG_STATUS, &status);
|
nrf_hal_read_reg_byte(REG_STATUS, &status);
|
||||||
|
|
||||||
if(status & _BV(RX_DR)) {
|
if(status & _BV(RX_DR)) {
|
||||||
flag = 1;
|
tos_sem_post(&sem_nrf_recv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +111,7 @@ void task_nrf24() {
|
|||||||
|
|
||||||
if(1)
|
if(1)
|
||||||
{
|
{
|
||||||
|
tos_sem_create(&sem_nrf_recv, 1);
|
||||||
// nrf24 irq pin
|
// nrf24 irq pin
|
||||||
gpio_init(GPIOB, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_0);
|
gpio_init(GPIOB, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_0);
|
||||||
gpio_bit_set(GPIOB, GPIO_PIN_0);
|
gpio_bit_set(GPIOB, GPIO_PIN_0);
|
||||||
@@ -160,29 +162,27 @@ void task_nrf24() {
|
|||||||
|
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
while(flag == 0) {
|
tos_sem_pend(&sem_nrf_recv, ~0);
|
||||||
nrf_delay(1);
|
|
||||||
}
|
|
||||||
flag = 0;
|
|
||||||
|
|
||||||
uint8_t buf[32];
|
uint8_t buf[32];
|
||||||
uint8_t len = 0;
|
uint8_t len = 0;
|
||||||
uint8_t status = 0;
|
uint8_t status = 0;
|
||||||
nrf_hal_read_reg_byte(REG_STATUS, &status);
|
nrf_hal_read_reg_byte(REG_STATUS, &status);
|
||||||
|
|
||||||
if((status & _BV(RX_DR)) == 0) {
|
|
||||||
printf("nodata %x\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t pipe = ((status>>1) & 0x07);
|
uint8_t pipe = ((status>>1) & 0x07);
|
||||||
nrf_read_payload(buf, &len);
|
nrf_read_payload(buf, &len);
|
||||||
|
|
||||||
|
if(pipe >= 6) {
|
||||||
|
printf("shit happens\n");
|
||||||
|
}
|
||||||
|
|
||||||
nrf_hal_set_reg_bit(REG_STATUS, _BV(RX_DR));
|
nrf_hal_set_reg_bit(REG_STATUS, _BV(RX_DR));
|
||||||
|
|
||||||
nrf_flush_rx();
|
nrf_flush_rx();
|
||||||
|
|
||||||
printf("received %u bytes from pipe %u: ", len, pipe);
|
printf("received %u bytes from pipe %u: ", len, pipe);
|
||||||
|
|
||||||
|
tos_sem_post(&sem_led);
|
||||||
|
|
||||||
for(int i=0; i<len; i++) {
|
for(int i=0; i<len; i++) {
|
||||||
printf("%x ", buf[i]);
|
printf("%x ", buf[i]);
|
||||||
|
Reference in New Issue
Block a user