센서보드 RF IRQ 테스트 중
Fork of stm-spirit1-rf-driver by
Revision 85:4ca74d007fe7, committed 2018-09-20
- Comitter:
- jmhong
- Date:
- Thu Sep 20 04:46:49 2018 +0000
- Parent:
- 84:45b9ff78a066
- Commit message:
- Environmental test.. temp, etc...
Changed in this revision
diff -r 45b9ff78a066 -r 4ca74d007fe7 source/SimpleSpirit1.cpp --- a/source/SimpleSpirit1.cpp Fri Jun 22 03:42:24 2018 +0000 +++ b/source/SimpleSpirit1.cpp Thu Sep 20 04:46:49 2018 +0000 @@ -14,7 +14,7 @@ //180619 HJM : init 재시작을 위한 카운팅 변수 static int iErrorCounting = 0; -#define MAX_ERROR_COUNTING 10 +#define MAX_ERROR_COUNTING 3 #define RETURN_ERROR_NUMBER 100 @@ -88,7 +88,7 @@ /*cubebite HJM, reset irq disable counter and irq callback & disable irq */ _nr_of_irq_disables = 0; // @@ - disable_spirit_irq(); +// disable_spirit_irq(); /*cubebite HJM, unselect chip */ chip_unselect(); @@ -166,7 +166,7 @@ uint8_t ui8Return; ui8Return = radio_init(&x_radio_init); if (RETURN_ERROR_NUMBER == ui8Return) - {//180621 HJM : 여기서는 reset을 해주는게 맞는게, init 은 전역의 spirit1 의 객체가 생성될 때 호출되기 때문이다. 다시 init을 호출해서 종료 시켜야, 아.. return 이 빠졌네 + { reset_board(); return; } @@ -177,7 +177,7 @@ /*180117 HJM : 송신 신호 세기 */ radio_set_pa_level_dbm(0,POWER_DBM); ///hjm test - // radio_set_pa_level_dbm(0,10.0); +// radio_set_pa_level_dbm(0,10.0); // radio_set_pa_level_dbm(0,CUBEBITE_OUTPUT_POWER_DBM_TEST); radio_set_pa_level_max_index(0); @@ -283,7 +283,8 @@ // printf("\r\n[SEND] 1, MAX_PACKET_LEN : [%d]\n", MAX_PACKET_LEN); // printf("[SEND] 2, payload_len : [%d]\n", payload_len); - if(payload_len > MAX_PACKET_LEN) { + if(payload_len > MAX_PACKET_LEN) + { // printf("[SEND] \n"); return RADIO_TX_ERR; } @@ -296,8 +297,8 @@ - - disable_spirit_irq(); + printf("send [1"); +// disable_spirit_irq(); BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, STATE_TIMEOUT); #ifndef NDEBUG @@ -325,21 +326,19 @@ } //180619 HJM : 아예 여기서 걸리면 흘러가게 냅두면 spirit1 이 꼬인다. -// ++iErrorCounting; - //if (iErrorCounting >= MAX_ERROR_COUNTING) -// { -// iErrorCounting = 0; -// return RADIO_TX_ERR_RESET; -//// -//// reset_board(); -// } + ++iErrorCounting; + if (iErrorCounting >= MAX_ERROR_COUNTING) + { + iErrorCounting = 0; + return RADIO_TX_ERR_RESET; + } // return RADIO_TX_ERR; } iErrorCounting = 0; - + printf(" 2"); //if (SPIRIT1_STATE_RX == SPIRIT1_STATUS()) // { // printf("[SEND] error \n"); @@ -360,10 +359,11 @@ /* Reset State to Ready */ + printf(" 3"); // printf("[SEND] 3, set_ready_state() call, \n"); set_ready_state(); - + printf(" 4"); // printf("[SEND] 4, cmd_strobe() call, SPIRIT1_STROBE_FTX \n"); cmd_strobe(SPIRIT1_STROBE_FTX); // flush TX FIFO buffer @@ -371,6 +371,7 @@ debug_if(!(linear_fifo_read_num_elements_tx_fifo() == 0), "\r\nAssert failed in: %s (%d)\r\n", __func__, __LINE__); #endif + printf(" 5"); // printf("[SEND] 5, pkt_basic_set_payload_length() call, \n"); pkt_basic_set_payload_length(payload_len); // set desired payload len @@ -379,27 +380,32 @@ csma_ca_state(S_ENABLE); // enable CSMA/CA } + printf(" 6"); /* Init buffer & number of bytes to be send */ // printf("[SEND] 7, csma_ca_state() call, \n"); tx_fifo_remaining = payload_len; tx_fifo_buffer = (const uint8_t*)payload; + printf(" 7"); int8_t fifo_available = SPIRIT_MAX_FIFO_LEN; // fill-up whole fifo int8_t to_send = (tx_fifo_remaining > fifo_available) ? fifo_available : tx_fifo_remaining; + printf(" 8"); tx_fifo_remaining -= to_send; + printf(" 9"); /* Fill FIFO Buffer */ if(to_send > 0) { // printf("[SEND] 8, if(to_send > 0), if(to_send > 0) \n"); spi_write_linear_fifo(to_send, (uint8_t*)&tx_fifo_buffer[0]); // printf("[SEND] 9, if(to_send > 0), if(to_send > 0) \n"); } - + printf(" 10"); tx_buffer_pos = to_send; _spirit_tx_started = true; - enable_spirit_irq(); + printf(" 11"); +// enable_spirit_irq(); // printf(" 6"); @@ -418,8 +424,10 @@ /* Start transmitting */ // printf("[SEND] 10, Start transmitting \n"); + printf(" 12"); cmd_strobe(SPIRIT1_STROBE_TX); + printf(" 13"); while(tx_fifo_remaining != 0); // wait until not everything is yet send (evtl. by irq handler) /* @@ -447,7 +455,7 @@ - + printf(" 14"); // printf("[SEND] 11, Start transmitting end, BUSYWAIT_UNTIL \n"); BUSYWAIT_UNTIL(!_spirit_tx_started, STATE_TIMEOUT); @@ -479,7 +487,7 @@ debug("\r\n%s (%d): state=%x, _spirit_tx_started=%d\r\n", __func__, __LINE__, SPIRIT1_STATUS()>>1, _spirit_tx_started); #endif - + printf(" 15"); if(use_csma_ca) { csma_ca_state(S_DISABLE); // disable CSMA/CA } @@ -496,9 +504,11 @@ //180323 HJM : irq가 작동하지 않아 수동으로 irq 값을 읽어 오기로 결정됬다. //이걸 while 로 가둬서 send 하기 전에 검토하면 된다. - + printf(" 16"); int iCounting = 0; - while(1) { + while(1) + { +// printf(" 16-1"); st_lib_spirit_irqs x_irq_status; irq_get_status(&x_irq_status); @@ -510,29 +520,34 @@ // BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_TX, STATE_TIMEOUT); - if(x_irq_status.IRQ_TX_DATA_SENT) { +// printf(" 16-2"); + if(x_irq_status.IRQ_TX_DATA_SENT) + { #ifdef DEBUG_IRQ // uint32_t *tmp = (uint32_t*)&x_irq_status; // debug_if(!((*tmp) & IRQ_TX_DATA_SENT_MASK), "\r\nAssert failed in: %s (%d)\r\n", __func__, __LINE__); // debug_if(tx_fifo_remaining != 0, "\r\nAssert failed in: %s (%d)\r\n", __func__, __LINE__); #endif - - if(_spirit_tx_started) { +// printf(" 16-3"); + if(_spirit_tx_started) + { #ifdef CUBEBITE_DEBUG printf("[IRQ] if(x_irq_status.IRQ_TX_DATA_SENT) in, if(_spirit_tx_started) in \n"); #endif } - +// printf(" 16-4"); x_irq_status.IRQ_TX_FIFO_ALMOST_EMPTY = S_RESET; tx_fifo_buffer = NULL; _spirit_tx_started = false; break; - } else { + } + else + { #ifdef CUBEBITE_DEBUG printf("not yet sent!!!\n"); #endif //CUBEBITE_DEBUG @@ -542,7 +557,7 @@ - +// printf(" 17"); /* The IRQ_TX_FIFO_ALMOST_EMPTY notifies an nearly empty TX fifo */ if(x_irq_status.IRQ_TX_FIFO_ALMOST_EMPTY) { // printf("1\n"); @@ -568,7 +583,8 @@ /* TX FIFO underflow/overflow error */ - if(x_irq_status.IRQ_TX_FIFO_ERROR) { + if(x_irq_status.IRQ_TX_FIFO_ERROR) + { #ifdef CUBEBITE_DEBUG printf("[IRQ] if(x_irq_status.IRQ_TX_FIFO_ERROR) in\n"); #endif //CUBEBITE_DEBUG @@ -595,14 +611,15 @@ - - if (10 == iCounting) { + + if (1000 == iCounting) + { //180327 HJM : 10번이나 검색을 했는데 IRQ가 이상이 있으면 정말 이상이 있다고 생각하고 그냥 break #ifdef CUBEBITE_DEBUG printf("if (1000 == iCounting) \n"); #endif iCounting = 0; - return RADIO_TX_ERR; + return RADIO_TX_ERR_RESET; } @@ -635,27 +652,27 @@ - + printf(" 18"); cmd_strobe(SPIRIT1_STROBE_RX); // Return to RX state // printf("[SEND] 12, Start transmitting end, BUSYWAIT_UNTIL \n"); - disable_spirit_irq(); +// disable_spirit_irq(); if(_spirit_tx_started) { // in case of state timeout _spirit_tx_started = false; - enable_spirit_irq(); +// enable_spirit_irq(); // printf("[SEND] 13, if(_spirit_tx_started), in case of state timeout, return RADIO_TX_ERR \n"); - + printf(" 19, err\n"); return RADIO_TX_ERR; } else { - enable_spirit_irq(); +// enable_spirit_irq(); /* call user callback */ if(_current_irq_callback) { _current_irq_callback(TX_DONE); } // printf("[SEND] 13, else, in case of state timeout, return RADIO_TX_OK \n"); - + printf(" 19, ok\n"); return RADIO_TX_OK; } } @@ -665,7 +682,7 @@ { uint16_t state; - disable_spirit_irq(); +// disable_spirit_irq(); _spirit_tx_started = false; _is_receiving = false; @@ -698,20 +715,20 @@ BUSYWAIT_UNTIL((SPIRIT1_STATUS() == SPIRIT1_STATE_READY) && ((last_state & XO_ON) == XO_ON), STATE_TIMEOUT); if(last_state != (SPIRIT1_STATE_READY | XO_ON)) { error("\r\nSpirit1: failed to become ready (%x) => pls. reset!\r\n", last_state); - enable_spirit_irq(); +// enable_spirit_irq(); return RETURN_ERROR_NUMBER + 2; } irq_clear_status(); - enable_spirit_irq(); +// enable_spirit_irq(); } int SimpleSpirit1::off(void) { if(spirit_on == ON) { /* Disables the mcu to get IRQ from the SPIRIT1 */ - disable_spirit_irq(); +// disable_spirit_irq(); /* first stop rx/tx */ set_ready_state(); @@ -750,7 +767,7 @@ #ifndef NDEBUG debug_if(!(_nr_of_irq_disables == 1), "\r\nAssert failed in: %s (%d)\r\n", __func__, __LINE__); #endif - enable_spirit_irq(); +// enable_spirit_irq(); } #ifndef NDEBUG @@ -773,7 +790,7 @@ int SimpleSpirit1::read(void *buf, unsigned int bufsize) { - disable_spirit_irq(); +// disable_spirit_irq(); printf("read() 1 "); /* Checks if the RX buffer is empty */ @@ -786,12 +803,12 @@ cmd_strobe(SPIRIT1_STROBE_RX); BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, STATE_TIMEOUT); - enable_spirit_irq(); +// enable_spirit_irq(); return 0; } if(bufsize < spirit_rx_len) { - enable_spirit_irq(); +// enable_spirit_irq(); /* If buf has the correct size */ #ifndef NDEBUG @@ -808,7 +825,7 @@ CLEAR_RXBUF(); printf(" 3-2"); - enable_spirit_irq(); +// enable_spirit_irq(); printf(" 3-3 read ok\n"); return bufsize; @@ -834,7 +851,7 @@ } #endif - disable_spirit_irq(); +// disable_spirit_irq(); /* Reset State to Ready */ set_ready_state(); @@ -842,7 +859,7 @@ /* Stores the RSSI value */ rssi_value = qi_get_rssi_dbm(); - enable_spirit_irq(); +// enable_spirit_irq(); /* Puts the SPIRIT1 in its previous state */ if(spirit_state==OFF) { @@ -857,7 +874,7 @@ } #endif } else { - disable_spirit_irq(); +// disable_spirit_irq(); set_ready_state(); @@ -867,7 +884,7 @@ error("\r\nSpirit1: (#2) failed to enter rx (%x) => retry\r\n", last_state>>1); } - enable_spirit_irq(); +// enable_spirit_irq(); #ifndef NDEBUG if(SPIRIT1_STATUS() != SPIRIT1_STATE_RX) {
diff -r 45b9ff78a066 -r 4ca74d007fe7 source/libs/Contiki_STM32_Library/spirit1.h --- a/source/libs/Contiki_STM32_Library/spirit1.h Fri Jun 22 03:42:24 2018 +0000 +++ b/source/libs/Contiki_STM32_Library/spirit1.h Thu Sep 20 04:46:49 2018 +0000 @@ -179,25 +179,83 @@ //------------433Mhz------------ //작동 되는 셋팅 +//#ifdef USE_SPIRIT1_433MHz +//#define CHANNEL_SPACE 20e3 //해봄 +//#define FREQ_DEVIATION 127e3 //recv +////#define FREQ_DEVIATION 50e3 //send +////#define BANDWIDTH 50.0e3 +////#define BANDWIDTH 70.0e3 //printf 다 끄니까 1000바이트정도 보내다가 뻗음 +////#define BANDWIDTH 100.0e3 //printf 다 끄니까 900바이트정도 보내다가 뻗음 +//#define BANDWIDTH 100.5e3 //printf 다 끄니까 900바이트정도 보내다가 뻗음 +// +////#define BANDWIDTH 540.0e3 +//#define MODULATION_SELECT GFSK_BT1 +//#define DATARATE 250000 //180326 HJM : 잘 됨 +////#define DATARATE 500000 //180326 HJM : 잘 안됨 +////#define DATARATE 300000 //180326 HJM : 잘 안됨 +////#define DATARATE 38400 +//#endif //USE_SPIRIT1_433MHz +//------------433Mhz------------ + + + + + + + + + + + + +//------------433Mhz------------ +//HJM : 안테나 변경(방수 안테나)로 인한 셋팅 변경 #ifdef USE_SPIRIT1_433MHz #define CHANNEL_SPACE 20e3 //해봄 #define FREQ_DEVIATION 127e3 //recv //#define FREQ_DEVIATION 50e3 //send -//#define BANDWIDTH 50.0e3 +#define BANDWIDTH 50.0e3 +//#define BANDWIDTH 65.0e3 //printf 다 끄니까 1000바이트정도 보내다가 뻗음 //#define BANDWIDTH 70.0e3 //printf 다 끄니까 1000바이트정도 보내다가 뻗음 //#define BANDWIDTH 100.0e3 //printf 다 끄니까 900바이트정도 보내다가 뻗음 -#define BANDWIDTH 100.5e3 //printf 다 끄니까 900바이트정도 보내다가 뻗음 +//#define BANDWIDTH 100.5e3 //printf 다 끄니까 900바이트정도 보내다가 뻗음 //#define BANDWIDTH 540.0e3 -#define MODULATION_SELECT GFSK_BT1 +//#define MODULATION_SELECT GFSK_BT1 +#define MODULATION_SELECT FSK #define DATARATE 250000 //180326 HJM : 잘 됨 //#define DATARATE 500000 //180326 HJM : 잘 안됨 //#define DATARATE 300000 //180326 HJM : 잘 안됨 +//#define DATARATE 115200 //180326 HJM : 잘 안됨 //#define DATARATE 38400 #endif //USE_SPIRIT1_433MHz //------------433Mhz------------ + + + + + + + + + + + + + + + + + + + + + + + + //#define CHANNEL_SPACE 100e3 //#define FREQ_DEVIATION 127e3 //#define BANDWIDTH 540.0e3
diff -r 45b9ff78a066 -r 4ca74d007fe7 source/libs/spirit1/SPIRIT1_Library/Src/SPIRIT_Management.c --- a/source/libs/spirit1/SPIRIT1_Library/Src/SPIRIT_Management.c Fri Jun 22 03:42:24 2018 +0000 +++ b/source/libs/spirit1/SPIRIT1_Library/Src/SPIRIT_Management.c Thu Sep 20 04:46:49 2018 +0000 @@ -54,7 +54,7 @@ //180619 HJM : init 재시작을 위한 카운팅 변수 static int iSpiritManagementErrorCounting = 0; -#define MAX_ERROR_COUNTING 10 +#define MAX_ERROR_COUNTING 3 #define RETURN_ERROR_NUMBER 100
diff -r 45b9ff78a066 -r 4ca74d007fe7 source/libs/spirit1/SPIRIT1_Library/Src/SPIRIT_Radio.c --- a/source/libs/spirit1/SPIRIT1_Library/Src/SPIRIT_Radio.c Fri Jun 22 03:42:24 2018 +0000 +++ b/source/libs/spirit1/SPIRIT1_Library/Src/SPIRIT_Radio.c Thu Sep 20 04:46:49 2018 +0000 @@ -44,7 +44,7 @@ //180619 HJM : init 재시작을 위한 카운팅 변수 static int iSpiritRadioErrorCounting = 0; -#define MAX_ERROR_COUNTING 10 +#define MAX_ERROR_COUNTING 3 #define RETURN_ERROR_NUMBER 100 /** @addtogroup SPIRIT_Libraries
diff -r 45b9ff78a066 -r 4ca74d007fe7 source/libs/spirit1/SPIRIT1_Library/Src/SPIRIT_Types.c --- a/source/libs/spirit1/SPIRIT1_Library/Src/SPIRIT_Types.c Fri Jun 22 03:42:24 2018 +0000 +++ b/source/libs/spirit1/SPIRIT1_Library/Src/SPIRIT_Types.c Thu Sep 20 04:46:49 2018 +0000 @@ -43,7 +43,7 @@ //180621 HJM : init 재시작을 위한 카운팅 변수 //static int iSpiritTypesErrorCounting = 0; -#define MAX_ERROR_COUNTING 10 +#define MAX_ERROR_COUNTING 3 #define RETURN_ERROR_NUMBER 100