diff --git a/board/Sipeed_LonganNano/eclipse/nRF24L01/main.c b/board/Sipeed_LonganNano/eclipse/nRF24L01/main.c index 883d3d85..367e05b5 100644 --- a/board/Sipeed_LonganNano/eclipse/nRF24L01/main.c +++ b/board/Sipeed_LonganNano/eclipse/nRF24L01/main.c @@ -5,18 +5,21 @@ #if 0 #define TASK_SIZE 1024 - - -k_task_t task1_handle; -k_task_t task2_handle; -k_task_t led_handle; - -uint8_t task1_stk[TASK_SIZE]; +k_task_t task2_handle 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 +#define LED_TASK_SIZE 1024 +k_task_t led_handle; +uint8_t led_stk[LED_TASK_SIZE]; + +k_sem_t sem_led; typedef struct { int port; @@ -30,18 +33,17 @@ Led_t leds[] = { }; -void task1(void *arg) +void task_led(void *arg) { int task_cnt1 = 0; while (1) { printf("hello world from %s cnt: %d\n", __func__, task_cnt1++); - for(int i=0; i - +extern k_sem_t sem_led; +k_sem_t sem_nrf_recv; int flag = 0; #define TASK_SIZE (8*1024) k_task_t task_nrf24_handle; @@ -84,7 +85,7 @@ void EXTI0_IRQHandler(void) nrf_hal_read_reg_byte(REG_STATUS, &status); if(status & _BV(RX_DR)) { - flag = 1; + tos_sem_post(&sem_nrf_recv); } } @@ -110,6 +111,7 @@ void task_nrf24() { if(1) { + tos_sem_create(&sem_nrf_recv, 1); // nrf24 irq pin gpio_init(GPIOB, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_0); gpio_bit_set(GPIOB, GPIO_PIN_0); @@ -160,29 +162,27 @@ void task_nrf24() { while(1) { - while(flag == 0) { - nrf_delay(1); - } - flag = 0; + tos_sem_pend(&sem_nrf_recv, ~0); uint8_t buf[32]; uint8_t len = 0; uint8_t status = 0; 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); nrf_read_payload(buf, &len); + if(pipe >= 6) { + printf("shit happens\n"); + } + nrf_hal_set_reg_bit(REG_STATUS, _BV(RX_DR)); nrf_flush_rx(); printf("received %u bytes from pipe %u: ", len, pipe); + tos_sem_post(&sem_led); for(int i=0; i