/*---------------------------------------------------------------------------*/ static int uz2400_read(void *buf, unsigned short bufsize) { uint8_t len; len = uz_rx(buf); /*printf("================================\n"); printf("Reading\n"); printf("================================\n"); int i; for(i = 0; i < len; i++) printf("%2x ", *(UINT8 *)(buf+i)); printf("\n================================\n");*/ if(len > bufsize) { uz_rx_flush(); return 0; } if(len > UZ2400_MAX_PACKET_LEN) { /* Oops, we must be out of sync. */ return 0; } if(len <= AUX_LEN) { return 0; } if(len - AUX_LEN > bufsize) { return 0; } if(len < AUX_LEN) { return 0; } // still bug here, check the datasheet uz2400_last_rssi = buf+(len-1); uz2400_last_correlation = buf+(len-2); // LQI if(len < AUX_LEN) { return 0; } return len - AUX_LEN; //if(len > 0) process_poll(&uz2400_process); //printf("uz2400_read length: %d\n", len); return len; }
void uz2400_process(void) { int len; PRINTF("uz2400_process: started\n\r"); cyg_addrword_t data; MyeCosAlram_t MyAlarmtest; // MyeCosAlarm(&MyAlarmtest,500,0,alarm_func); /* static cyg_uint32 RLedPinspec; RLedPinspec = CYGHWR_HAL_STM32_GPIO( C, 9, OUT_50MHZ , OUT_PUSHPULL ); blink=~blink; CYGHWR_HAL_STM32_GPIO_OUT(RLedPinspec,blink); */ cyg_thread_delay(20); while(1) { // cyg_thread_delay(1); // check_timer_expired( );/////////////////////////////////// // check_rpl_timer_timeout(); if(is_rf_incoming()){ // PRINTF("uz2400_process: calling receiver callback\n"); packetbuf_clear(); // cyg_thread_delay(1); len = uz2400_read(packetbuf_dataptr(), PACKETBUF_SIZE); // cyg_thread_delay(1); uz_rx_flush(); cyg_uint8 tmp = uz_read_rssi(); printf("uz_read_rssi = %i\n", tmp); // if ( tmp<100) //////////////// /* if ( tmp<80) continue; */ if(len > 0) { packetbuf_set_datalen(len); NETSTACK_RDC.input(tmp); // cyg_thread_delay(10); } // IntStatus.Rx =0; // cyg_thread_delay(10); } check_timer_expired( );/////////////////////////////////// check_rpl_timer_timeout(); } }