센서보드 RF IRQ 테스트 중 and bug fix?
Fork of EV-COG-AD3029LZ by
Revision 85:38de5ee78824, committed 2018-09-20
- Comitter:
- jmhong
- Date:
- Thu Sep 20 06:34:33 2018 +0000
- Parent:
- 84:45b9ff78a066
- Commit message:
- bug fix?
Changed in this revision
diff -r 45b9ff78a066 -r 38de5ee78824 source/SimpleSpirit1.cpp --- a/source/SimpleSpirit1.cpp Fri Jun 22 03:42:24 2018 +0000 +++ b/source/SimpleSpirit1.cpp Thu Sep 20 06:34:33 2018 +0000 @@ -11,10 +11,12 @@ //#define DEBUG_IRQ //#define HEAVY_DEBUG +//#define DEBUG_PRINT_SEND + //180619 HJM : init 재시작을 위한 카운팅 변수 static int iErrorCounting = 0; -#define MAX_ERROR_COUNTING 10 +#define MAX_ERROR_COUNTING 3 #define RETURN_ERROR_NUMBER 100 @@ -22,6 +24,8 @@ //#define SPIRIT_GPIO_IRQ (SPIRIT_GPIO_2) //#define SPIRIT_GPIO_IRQ (SPIRIT_GPIO_1) //EV-COG-AD3029LZ -> GPIO 8 -> P0_08 +static int iIsResetStartCountingSimpleSpirit1 = 0; + static uint16_t last_state; #define SPIRIT1_STATUS() ((last_state = (uint16_t)refresh_state()) & SPIRIT1_STATE_STATEBITS) @@ -81,12 +85,13 @@ /** Init Function **/ void SimpleSpirit1::init() { - printf("[INIT_REVISE]init start...\n"); + printf("[RF] init start"); //if (false == isItDoItSPIInit) // { // isItDoItSPIInit = true; /*cubebite HJM, reset irq disable counter and irq callback & disable irq */ + _nr_of_irq_disables = 0; // @@ disable_spirit_irq(); @@ -97,7 +102,7 @@ _spi.format(8, 0); /* 8-bit, mode = 0, [order = SPI_MSB] only available in mbed3 */ _spi.frequency(_uint32SpiClkSettingValue); //HJM 초기 값, 6500000 - printf("Setting spi clk : [%d]\r\n", _uint32SpiClkSettingValue); +// printf("Setting spi clk : [%d]\r\n", _uint32SpiClkSettingValue); // _spi.frequency(13000000); // 13MHz (i.e. max speed allowed for Spirit1) // _spi.frequency(6500000); // 6.5MHz (i.e. max speed allowed for Spirit1) @@ -115,6 +120,7 @@ //180619 HJM : 여기서 부터 sprit1 init 부분 /*cubebite HJM, install irq handler */ _irq.mode(PullUp); +// _irq.mode(PullDown); _irq.fall(Callback<void()>(this, &SimpleSpirit1::IrqHandler)); @@ -126,7 +132,7 @@ /*cubebite HJM, set frequencies */ - printf("[INIT_REVISE]set frequencies..."); + printf("\n set frequencies..."); radio_set_xtal_freq(XTAL_FREQUENCY); //cubebite HJM, 50MHz, 180619 HJM : 단순히 변수 셋팅 mgmt_set_freq_base((uint32_t)BASE_FREQUENCY); // @@ printf("OK\n"); @@ -147,7 +153,7 @@ //180619 HJM : 여기서 부터는 init while문이 들어감. /*cubebite HJM, Configures the SPIRIT1 radio part */ //180119 HJM : 433MHz 설정으로 변경 후 테스트. - printf("[INIT_REVISE]set SPIRIT1 radio...\n"); +// printf("[INIT_REVISE]set SPIRIT1 radio...\n"); SRadioInit x_radio_init = { XTAL_OFFSET_PPM, // Xtal offset in ppm (uint32_t)BASE_FREQUENCY, // HJM 수정 후 테스트 중 base frequency @@ -163,10 +169,11 @@ + printf("\n radio_init()\n"); 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 +184,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,7.0); // radio_set_pa_level_dbm(0,CUBEBITE_OUTPUT_POWER_DBM_TEST); radio_set_pa_level_max_index(0); @@ -267,7 +274,7 @@ #endif // USE_STANDBY_STATE // } - printf("[INIT_REVISE]init end.\n"); + printf("(OK)\n"); } @@ -279,11 +286,13 @@ static const volatile uint8_t *tx_fifo_buffer = NULL; // to be used in irq handler int SimpleSpirit1::send(const void *payload, unsigned int payload_len, bool use_csma_ca) { + int iRet = 0; /* Checks if the payload length is supported */ // 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; } @@ -295,51 +304,51 @@ - - +#ifdef DEBUG_PRINT_SEND + printf("send [1"); +#endif disable_spirit_irq(); BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, STATE_TIMEOUT); -#ifndef NDEBUG - if((last_state & SPIRIT1_STATE_STATEBITS) != SPIRIT1_STATE_RX) { - debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, last_state>>1); - } -#endif +//#ifndef NDEBUG +// if((last_state & SPIRIT1_STATE_STATEBITS) != SPIRIT1_STATE_RX) { +// debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, last_state>>1); +// } +//#endif if((last_state & SPIRIT1_STATE_STATEBITS) != SPIRIT1_STATE_RX) { //180619 HJM : 여기서 뻗지는 않음, 그냥 send error 만 띄울 뿐. 하지만 이것도 카운팅 걸어두고 몇 번(MAX_ERROR_COUNTING) 이상이면 init을 타도록 해야 하겠다. - debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, last_state>>1); +// debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, last_state>>1); printf("[SEND] error \n"); if (0x3 == (last_state>>1)) { - return RADIO_TX_ERR_RESET; + return RADIO_TX_ERR; // reset_board(); } if (0x40 == (last_state>>1)) { - return RADIO_TX_ERR_RESET; + return RADIO_TX_ERR; } //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; + } // return RADIO_TX_ERR; } iErrorCounting = 0; - - +#ifdef DEBUG_PRINT_SEND + printf(" 2"); +#endif //if (SPIRIT1_STATE_RX == SPIRIT1_STATUS()) // { // printf("[SEND] error \n"); @@ -360,17 +369,41 @@ /* Reset State to Ready */ +#ifdef DEBUG_PRINT_SEND + printf(" 3"); +#endif // printf("[SEND] 3, set_ready_state() call, \n"); - set_ready_state(); - + iRet = set_ready_state(); + if (iRet == RETURN_ERROR_NUMBER) + { + return RETURN_ERROR_NUMBER; + } + + //if (iRet == RETURN_ERROR_NUMBER) +// { +// ++iErrorCounting; +// if (iErrorCounting >= MAX_ERROR_COUNTING) +// { +// iErrorCounting = 0; +// return RADIO_TX_ERR_RESET; +// } +// +// return RADIO_TX_ERR; +// } + +#ifdef DEBUG_PRINT_SEND + printf(" 4"); +#endif // printf("[SEND] 4, cmd_strobe() call, SPIRIT1_STROBE_FTX \n"); cmd_strobe(SPIRIT1_STROBE_FTX); // flush TX FIFO buffer -#ifndef NDEBUG - debug_if(!(linear_fifo_read_num_elements_tx_fifo() == 0), "\r\nAssert failed in: %s (%d)\r\n", __func__, __LINE__); +//#ifndef NDEBUG +// debug_if(!(linear_fifo_read_num_elements_tx_fifo() == 0), "\r\nAssert failed in: %s (%d)\r\n", __func__, __LINE__); +//#endif +#ifdef DEBUG_PRINT_SEND + printf(" 5"); #endif - // printf("[SEND] 5, pkt_basic_set_payload_length() call, \n"); pkt_basic_set_payload_length(payload_len); // set desired payload len @@ -378,27 +411,40 @@ // printf("[SEND] 6, csma_ca_state() call, \n"); csma_ca_state(S_ENABLE); // enable CSMA/CA } - +#ifdef DEBUG_PRINT_SEND + printf(" 6"); +#endif /* 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; - +#ifdef DEBUG_PRINT_SEND + printf(" 7"); +#endif 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; - +#ifdef DEBUG_PRINT_SEND + printf(" 8"); +#endif tx_fifo_remaining -= to_send; - +#ifdef DEBUG_PRINT_SEND + printf(" 9"); +#endif /* Fill FIFO Buffer */ - if(to_send > 0) { + 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"); } - +#ifdef DEBUG_PRINT_SEND + printf(" 10"); +#endif tx_buffer_pos = to_send; _spirit_tx_started = true; - +#ifdef DEBUG_PRINT_SEND + printf(" 11"); +#endif enable_spirit_irq(); // printf(" 6"); @@ -418,8 +464,13 @@ /* Start transmitting */ // printf("[SEND] 10, Start transmitting \n"); +#ifdef DEBUG_PRINT_SEND + printf(" 12"); +#endif cmd_strobe(SPIRIT1_STROBE_TX); - +#ifdef DEBUG_PRINT_SEND + printf(" 13"); +#endif while(tx_fifo_remaining != 0); // wait until not everything is yet send (evtl. by irq handler) /* @@ -446,8 +497,9 @@ - - +#ifdef DEBUG_PRINT_SEND + printf(" 14"); +#endif // printf("[SEND] 11, Start transmitting end, BUSYWAIT_UNTIL \n"); BUSYWAIT_UNTIL(!_spirit_tx_started, STATE_TIMEOUT); @@ -475,11 +527,12 @@ -#ifdef HEAVY_DEBUG - debug("\r\n%s (%d): state=%x, _spirit_tx_started=%d\r\n", __func__, __LINE__, SPIRIT1_STATUS()>>1, _spirit_tx_started); +//#ifdef HEAVY_DEBUG +// debug("\r\n%s (%d): state=%x, _spirit_tx_started=%d\r\n", __func__, __LINE__, SPIRIT1_STATUS()>>1, _spirit_tx_started); +//#endif +#ifdef DEBUG_PRINT_SEND + printf(" 15"); #endif - - if(use_csma_ca) { csma_ca_state(S_DISABLE); // disable CSMA/CA } @@ -496,9 +549,13 @@ //180323 HJM : irq가 작동하지 않아 수동으로 irq 값을 읽어 오기로 결정됬다. //이걸 while 로 가둬서 send 하기 전에 검토하면 된다. - +#ifdef DEBUG_PRINT_SEND + printf(" 16"); +#endif 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 +567,33 @@ // 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,9 +603,10 @@ - +// printf(" 17"); /* The IRQ_TX_FIFO_ALMOST_EMPTY notifies an nearly empty TX fifo */ - if(x_irq_status.IRQ_TX_FIFO_ALMOST_EMPTY) { + if(x_irq_status.IRQ_TX_FIFO_ALMOST_EMPTY) + { // printf("1\n"); // printf("[IRQ] if(x_irq_status.IRQ_TX_FIFO_ALMOST_EMPTY) in\n"); @@ -559,7 +621,8 @@ tx_fifo_remaining -= to_send; /* Fill FIFO Buffer */ - if(to_send > 0) { + if(to_send > 0) + { spi_write_linear_fifo(to_send, (uint8_t*)&tx_fifo_buffer[tx_buffer_pos]); } tx_buffer_pos += to_send; @@ -568,7 +631,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,18 +659,17 @@ - - if (10 == iCounting) { - //180327 HJM : 10번이나 검색을 했는데 IRQ가 이상이 있으면 정말 이상이 있다고 생각하고 그냥 break + + if (1000 == iCounting) + { + //180327 HJM : 50번이나 검색을 했는데 IRQ가 이상이 있으면 정말 이상이 있다고 생각하고 그냥 break #ifdef CUBEBITE_DEBUG printf("if (1000 == iCounting) \n"); #endif - iCounting = 0; + iCounting = 0; + return RADIO_TX_ERR; - } - - } @@ -634,28 +697,46 @@ - - +#ifdef DEBUG_PRINT_SEND + printf(" 18"); +#endif cmd_strobe(SPIRIT1_STROBE_RX); // Return to RX state // printf("[SEND] 12, Start transmitting end, BUSYWAIT_UNTIL \n"); disable_spirit_irq(); - if(_spirit_tx_started) { + if(_spirit_tx_started) + { // in case of state timeout _spirit_tx_started = false; enable_spirit_irq(); // printf("[SEND] 13, if(_spirit_tx_started), in case of state timeout, return RADIO_TX_ERR \n"); - +#ifdef DEBUG_PRINT_SEND + printf(" 19, err\n"); +#endif + ++iIsResetStartCountingSimpleSpirit1; + + if (10 < iIsResetStartCountingSimpleSpirit1) + { + iIsResetStartCountingSimpleSpirit1 = 0; + return RADIO_TX_ERR_RESET; + } + return RADIO_TX_ERR; - } else { + } + else + { enable_spirit_irq(); /* call user callback */ - if(_current_irq_callback) { + if(_current_irq_callback) + { _current_irq_callback(TX_DONE); } // printf("[SEND] 13, else, in case of state timeout, return RADIO_TX_OK \n"); - +#ifdef DEBUG_PRINT_SEND + printf(" 19, ok\n"); +#endif + iIsResetStartCountingSimpleSpirit1 = 0; return RADIO_TX_OK; } } @@ -676,18 +757,23 @@ CLEAR_TXBUF(); state = SPIRIT1_STATUS(); - if(state == SPIRIT1_STATE_STANDBY) { + if(state == SPIRIT1_STATE_STANDBY) + { // printf("[SEND] 3-1, set_ready_state() call, if(state == SPIRIT1_STATE_STANDBY) in \n"); cmd_strobe(SPIRIT1_STROBE_READY); - } else if(state == SPIRIT1_STATE_RX) { + } + else if(state == SPIRIT1_STATE_RX) + { // printf("[SEND] 3-2, set_ready_state() call, if(state == SPIRIT1_STATE_RX) in \n"); cmd_strobe(SPIRIT1_STROBE_SABORT); } else if(state != SPIRIT1_STATE_READY) { -#ifndef NDEBUG - debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, state>>1); -#endif - return RETURN_ERROR_NUMBER; + return RETURN_ERROR_NUMBER; + +//#ifndef NDEBUG +// debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, state>>1); +//#endif +// return RETURN_ERROR_NUMBER; // off(); // reset_board(); @@ -696,10 +782,11 @@ } 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(); - return RETURN_ERROR_NUMBER + 2; + if(last_state != (SPIRIT1_STATE_READY | XO_ON)) + { + enable_spirit_irq(); + return RETURN_ERROR_NUMBER; +// error("\r\nSpirit1: failed to become ready (%x) => pls. reset!\r\n", last_state); } irq_clear_status(); @@ -709,20 +796,27 @@ int SimpleSpirit1::off(void) { - if(spirit_on == ON) { + if(spirit_on == ON) + { /* Disables the mcu to get IRQ from the SPIRIT1 */ disable_spirit_irq(); /* first stop rx/tx */ - set_ready_state(); + int iRet = 0; + iRet = set_ready_state(); + if (RETURN_ERROR_NUMBER == iRet) + { + return RETURN_ERROR_NUMBER; + } #ifdef USE_STANDBY_STATE /* Puts the SPIRIT1 in STANDBY */ cmd_strobe(SPIRIT1_STROBE_STANDBY); BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_STANDBY, STATE_TIMEOUT); - if((last_state & SPIRIT1_STATE_STATEBITS) != SPIRIT1_STATE_STANDBY) { - error("\r\nSpirit1: failed to enter standby (%x)\r\n", last_state>>1); - return 1; + if((last_state & SPIRIT1_STATE_STATEBITS) != SPIRIT1_STATE_STANDBY) + { + return RETURN_ERROR_NUMBER; +// error("\r\nSpirit1: failed to enter standby (%x)\r\n", last_state>>1); } #endif // USE_STANDBY_STATE @@ -734,28 +828,38 @@ int SimpleSpirit1::on(void) { - if(spirit_on == OFF) { - set_ready_state(); + if(spirit_on == OFF) + { + int iRet = 0; + iRet = set_ready_state(); + if (RETURN_ERROR_NUMBER == iRet) + { + return RETURN_ERROR_NUMBER; + } /* now we go to Rx */ cmd_strobe(SPIRIT1_STROBE_RX); BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, STATE_TIMEOUT); - if((last_state & SPIRIT1_STATE_STATEBITS) != SPIRIT1_STATE_RX) { - error("\r\nSpirit1: failed to enter rx (%x) => retry\r\n", last_state>>1); + if((last_state & SPIRIT1_STATE_STATEBITS) != SPIRIT1_STATE_RX) + { + return RETURN_ERROR_NUMBER; +// error("\r\nSpirit1: failed to enter rx (%x) => retry\r\n", last_state>>1); } /* Enables the mcu to get IRQ from the SPIRIT1 */ spirit_on = ON; -#ifndef NDEBUG - debug_if(!(_nr_of_irq_disables == 1), "\r\nAssert failed in: %s (%d)\r\n", __func__, __LINE__); -#endif +//#ifndef NDEBUG +// debug_if(!(_nr_of_irq_disables == 1), "\r\nAssert failed in: %s (%d)\r\n", __func__, __LINE__); +//#endif enable_spirit_irq(); } #ifndef NDEBUG - if(SPIRIT1_STATUS() != SPIRIT1_STATE_RX) { - debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, last_state>>1); + if(SPIRIT1_STATUS() != SPIRIT1_STATE_RX) + { + return RETURN_ERROR_NUMBER; +// debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, last_state>>1); } #endif @@ -774,14 +878,16 @@ int SimpleSpirit1::read(void *buf, unsigned int bufsize) { disable_spirit_irq(); - printf("read() 1 "); +// printf("read() 1 "); /* Checks if the RX buffer is empty */ - if(IS_RXBUF_EMPTY()) { -#ifndef NDEBUG - debug("\r\nBuffer is empty\r\n"); -#endif - printf("[DEBUG] 2-1"); + if(IS_RXBUF_EMPTY()) + { +//#ifndef NDEBUG +// debug("\r\nBuffer is empty\r\n"); +//#endif +// printf("[DEBUG] 2-1"); + set_ready_state(); cmd_strobe(SPIRIT1_STROBE_RX); @@ -794,9 +900,9 @@ enable_spirit_irq(); /* If buf has the correct size */ -#ifndef NDEBUG - debug("\r\nTOO SMALL BUF\r\n"); -#endif +//#ifndef NDEBUG +// debug("\r\nTOO SMALL BUF\r\n"); +//#endif return 0; } else { /* Copies the packet received */ @@ -829,8 +935,10 @@ } #ifndef NDEBUG - if(SPIRIT1_STATUS() != SPIRIT1_STATE_RX) { - debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, last_state>>1); + if(SPIRIT1_STATUS() != SPIRIT1_STATE_RX) + { + return RETURN_ERROR_NUMBER; +// debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, last_state>>1); } #endif @@ -851,9 +959,11 @@ #ifdef USE_STANDBY_STATE if(SPIRIT1_STATUS() != SPIRIT1_STATE_STANDBY) { #else - if(SPIRIT1_STATUS() != SPIRIT1_STATE_READY) { + if(SPIRIT1_STATUS() != SPIRIT1_STATE_READY) + { + return RETURN_ERROR_NUMBER; #endif - debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, last_state>>1); +// debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, last_state>>1); } #endif } else { @@ -863,15 +973,20 @@ cmd_strobe(SPIRIT1_STROBE_RX); BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, STATE_TIMEOUT); - if((last_state & SPIRIT1_STATE_STATEBITS) != SPIRIT1_STATE_RX) { - error("\r\nSpirit1: (#2) failed to enter rx (%x) => retry\r\n", last_state>>1); + if((last_state & SPIRIT1_STATE_STATEBITS) != SPIRIT1_STATE_RX) + { + return RETURN_ERROR_NUMBER; + +// error("\r\nSpirit1: (#2) failed to enter rx (%x) => retry\r\n", last_state>>1); } enable_spirit_irq(); #ifndef NDEBUG - if(SPIRIT1_STATUS() != SPIRIT1_STATE_RX) { - debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, last_state>>1); + if(SPIRIT1_STATUS() != SPIRIT1_STATE_RX) + { + return RETURN_ERROR_NUMBER; +// debug("\r\nAssert failed in: %s (%d): state=%x\r\n", __func__, __LINE__, last_state>>1); } #endif } @@ -903,7 +1018,8 @@ irq_get_status(&x_irq_status); /* The IRQ_TX_DATA_SENT notifies the packet has been sent. Puts the SPIRIT1 in RX */ - if(x_irq_status.IRQ_TX_DATA_SENT) { + if(x_irq_status.IRQ_TX_DATA_SENT) + { /* betzw - NOTE: MUST be handled before `IRQ_RX_DATA_READY` for Nanostack integration! Logically, Nanostack only expects the "DONE" after "SUCCESS" (if it gets DONE before SUCCESS, it assumes you're not going to bother to send SUCCESS).
diff -r 45b9ff78a066 -r 38de5ee78824 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 06:34:33 2018 +0000 @@ -103,6 +103,10 @@ #ifdef USE_SPIRIT1_433MHz #define BASE_FREQUENCY 433.4e6 +//#define BASE_FREQUENCY 433.3e6 +//#define BASE_FREQUENCY 433.2e6 +//#define BASE_FREQUENCY 433.1e6 +//#define BASE_FREQUENCY 433.0e6 #endif #ifdef USE_SPIRIT1_868MHz @@ -179,25 +183,123 @@ //------------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 100e3 +//#define FREQ_DEVIATION 127e3 +//#define BANDWIDTH 540.0e3 +////#define MODULATION_SELECT GFSK_BT1 +//#define MODULATION_SELECT FSK +//#define DATARATE 250000 + +//인터넷 검색 후 설정 값_1 +//#define FREQ_DEVIATION 4800 +//#define BANDWIDTH 16000 + +//인터넷 검색 후 설정 값_2 +//#define CHANNEL_SPACE 20e3 +//#define MODULATION_SELECT FSK +////#define DATARATE 38400 +////#define DATARATE 19200 +//#define DATARATE 9600 +//#define FREQ_DEVIATION 20e3 +////#define FREQ_DEVIATION 127e3 +//#define BANDWIDTH 100E3 + + #define CHANNEL_SPACE 20e3 //해봄 +//#define CHANNEL_SPACE 30e3 #define FREQ_DEVIATION 127e3 //recv //#define FREQ_DEVIATION 50e3 //send -//#define BANDWIDTH 50.0e3 +//#define FREQ_DEVIATION 20e3 //send +//#define FREQ_DEVIATION 70e3 //send +#define BANDWIDTH 50.0e3 +//#define BANDWIDTH 60.0e3 //printf 다 끄니까 1000바이트정도 보내다가 뻗음 //#define BANDWIDTH 70.0e3 //printf 다 끄니까 1000바이트정도 보내다가 뻗음 +//#define BANDWIDTH 80.0e3 //printf 다 끄니까 1000바이트정도 보내다가 뻗음 +//#define BANDWIDTH 90.0e3 +//#define BANDWIDTH 115.0e3 +//#define BANDWIDTH 200.0e3 //#define BANDWIDTH 100.0e3 //printf 다 끄니까 900바이트정도 보내다가 뻗음 -#define BANDWIDTH 100.5e3 //printf 다 끄니까 900바이트정도 보내다가 뻗음 +//#define BANDWIDTH 100.0e3 //printf 다 끄니까 900바이트정도 보내다가 뻗음 +//#define BANDWIDTH 100.5e3 //printf 다 끄니까 900바이트정도 보내다가 뻗음 +//#define BANDWIDTH 540.0e3 //#define BANDWIDTH 540.0e3 -#define MODULATION_SELECT GFSK_BT1 -#define DATARATE 250000 //180326 HJM : 잘 됨 +//#define MODULATION_SELECT GFSK_BT1 +#define MODULATION_SELECT FSK +//#define DATARATE 250000 //180326 HJM : 잘 됨 +//#define DATARATE 125000 // +//#define DATARATE 62500 // +//#define DATARATE 230400 // //#define DATARATE 500000 //180326 HJM : 잘 안됨 //#define DATARATE 300000 //180326 HJM : 잘 안됨 +//#define DATARATE 115200 //180326 HJM : 잘 안됨 +#define DATARATE 57600 //180326 HJM : 잘 안됨 +//#define DATARATE 38400 //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 38de5ee78824 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 06:34:33 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 @@ -241,16 +241,16 @@ SpiritCalibrationVco(S_ENABLE); SpiritRefreshStatus(); - printf("test 9-3 g_xStatus.MC_STATE : [0x%02X] \n", g_xStatus.MC_STATE); +// printf("test 9-3 g_xStatus.MC_STATE : [0x%02X] \n", g_xStatus.MC_STATE); if(g_xStatus.MC_STATE == MC_STATE_STANDBY) { cStandby = 1; SpiritCmdStrobeReady(); - printf("test 9-3 1 g_xStatus.MC_STATE : [0x%02X] \n", g_xStatus.MC_STATE); +// printf("test 9-3 1 g_xStatus.MC_STATE : [0x%02X] \n", g_xStatus.MC_STATE); do { SpiritRefreshStatus(); - printf("test 9-3 2 g_xStatus.MC_STATE : [0x%02X]\n", g_xStatus.MC_STATE); +// printf("test 9-3 2 g_xStatus.MC_STATE : [0x%02X]\n", g_xStatus.MC_STATE); if(g_xStatus.MC_STATE == 0x13) { return 1; @@ -272,11 +272,11 @@ SpiritCmdStrobeLockTx(); - printf("test 9-4 g_xStatus.MC_STATE : [0x%02X] \n", g_xStatus.MC_STATE); +// printf("test 9-4 g_xStatus.MC_STATE : [0x%02X] \n", g_xStatus.MC_STATE); do { SpiritRefreshStatus(); - printf("test 9-4 1 g_xStatus.MC_STATE : [0x%02X] \n", g_xStatus.MC_STATE); +// printf("test 9-4 1 g_xStatus.MC_STATE : [0x%02X] \n", g_xStatus.MC_STATE); if(g_xStatus.MC_STATE == 0x13) { return 1; @@ -299,7 +299,7 @@ s_cVcoWordTx = SpiritCalibrationGetVcoCalData(); SpiritCmdStrobeReady(); - printf("test 9-5 g_xStatus.MC_STATE : [0x%02X] \n", g_xStatus.MC_STATE); +// printf("test 9-5 g_xStatus.MC_STATE : [0x%02X] \n", g_xStatus.MC_STATE); do{ SpiritRefreshStatus();
diff -r 45b9ff78a066 -r 38de5ee78824 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 06:34:33 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 @@ -192,23 +192,23 @@ */ uint8_t SpiritRadioInit(SRadioInit* pxSRadioInitStruct) { - printf("[INIT_REVISE]SpiritRadioInit start...\n"); +// printf("[INIT_REVISE]SpiritRadioInit start...\n"); int32_t FOffsetTmp; uint8_t anaRadioRegArray[8], digRadioRegArray[4]; int16_t xtalOffsetFactor; uint8_t drM, drE, FdevM, FdevE, bwM, bwE; /* Workaround for Vtune */ - printf("test 9-1\n"); +// printf("test 9-1\n"); uint8_t value = 0xA0; SpiritSpiWriteRegisters(0x9F, 1, &value); /* Calculates the offset respect to RF frequency and according to xtal_ppm parameter: (xtal_ppm*FBase)/10^6 */ - printf("test 9-2\n"); +// printf("test 9-2\n"); FOffsetTmp = (int32_t)(((float)pxSRadioInitStruct->nXtalOffsetPpm*pxSRadioInitStruct->lFrequencyBase)/PPM_FACTOR); /* Check the parameters */ - printf("test 9-3\n"); +// printf("test 9-3\n"); s_assert_param(IS_FREQUENCY_BAND(pxSRadioInitStruct->lFrequencyBase)); s_assert_param(IS_MODULATION_SELECTED(pxSRadioInitStruct->xModulationSelect)); s_assert_param(IS_DATARATE(pxSRadioInitStruct->lDatarate)); @@ -217,7 +217,7 @@ s_assert_param(IS_F_DEV(pxSRadioInitStruct->lFreqDev,s_lXtalFrequency)); /* Disable the digital, ADC, SMPS reference clock divider if fXO>24MHz or fXO<26MHz */ - printf("test 9-4\n"); +// printf("test 9-4\n"); SpiritSpiCommandStrobes(COMMAND_STANDBY); do{ /* Delay for state transition */ @@ -225,7 +225,7 @@ /* Reads the MC_STATUS register */ SpiritRefreshStatus(); - printf("test 9-4 g_xStatus.MC_STATE : [0x%02X]\n", g_xStatus.MC_STATE); +// printf("test 9-4 g_xStatus.MC_STATE : [0x%02X]\n", g_xStatus.MC_STATE); ++iSpiritRadioErrorCounting; if (iSpiritRadioErrorCounting >= MAX_ERROR_COUNTING) { @@ -259,7 +259,7 @@ /* Goes in READY state */ - printf("test 9-5\n"); +// printf("test 9-5\n"); SpiritSpiCommandStrobes(COMMAND_READY); do{ /* Delay for state transition */ @@ -267,7 +267,7 @@ /* Reads the MC_STATUS register */ SpiritRefreshStatus(); - printf("test 9-5 g_xStatus.MC_STATE : [%d]\n", g_xStatus.MC_STATE); +// printf("test 9-5 g_xStatus.MC_STATE : [%d]\n", g_xStatus.MC_STATE); ++iSpiritRadioErrorCounting; if (iSpiritRadioErrorCounting >= MAX_ERROR_COUNTING) { @@ -279,13 +279,13 @@ iSpiritRadioErrorCounting = 0; /* Calculates the FC_OFFSET parameter and cast as signed int: FOffsetTmp = (Fxtal/2^18)*FC_OFFSET */ - printf("test 9-6\n"); +// printf("test 9-6\n"); xtalOffsetFactor = (int16_t)(((float)FOffsetTmp*FBASE_DIVIDER)/s_lXtalFrequency); anaRadioRegArray[2] = (uint8_t)((((uint16_t)xtalOffsetFactor)>>8)&0x0F); anaRadioRegArray[3] = (uint8_t)(xtalOffsetFactor); /* Calculates the channel space factor */ - printf("test 9-7\n"); +// printf("test 9-7\n"); anaRadioRegArray[0] =((uint32_t)pxSRadioInitStruct->nChannelSpace<<9)/(s_lXtalFrequency>>6)+1; SpiritManagementWaTRxFcMem(pxSRadioInitStruct->lFrequencyBase); @@ -296,32 +296,32 @@ /* 2nd order DEM algorithm enabling */ - printf("test 9-8\n"); +// printf("test 9-8\n"); uint8_t tmpreg; SpiritSpiReadRegisters(0xA3, 1, &tmpreg); tmpreg &= ~0x02; SpiritSpiWriteRegisters(0xA3, 1, &tmpreg); /* Check the channel center frequency is in one of the possible range */ - printf("test 9-9\n"); +// printf("test 9-9\n"); s_assert_param(IS_FREQUENCY_BAND((pxSRadioInitStruct->lFrequencyBase + ((xtalOffsetFactor*s_lXtalFrequency)/FBASE_DIVIDER) + pxSRadioInitStruct->nChannelSpace * pxSRadioInitStruct->cChannelNumber))); /* Calculates the datarate mantissa and exponent */ - printf("test 9-10\n"); +// printf("test 9-10\n"); SpiritRadioSearchDatarateME(pxSRadioInitStruct->lDatarate, &drM, &drE); digRadioRegArray[0] = (uint8_t)(drM); digRadioRegArray[1] = (uint8_t)(0x00 | pxSRadioInitStruct->xModulationSelect |drE); /* Read the fdev register to preserve the clock recovery algo bit */ - printf("test 9-11\n"); +// printf("test 9-11\n"); SpiritSpiReadRegisters(0x1C, 1, &tmpreg); /* Calculates the frequency deviation mantissa and exponent */ - printf("test 9-12\n"); +// printf("test 9-12\n"); SpiritRadioSearchFreqDevME(pxSRadioInitStruct->lFreqDev, &FdevM, &FdevE); digRadioRegArray[2] = (uint8_t)((FdevE<<4) | (tmpreg&0x08) | FdevM); /* Calculates the channel filter mantissa and exponent */ - printf("test 9-13\n"); +// printf("test 9-13\n"); SpiritRadioSearchChannelBwME(pxSRadioInitStruct->lBandwidth, &bwM, &bwE); @@ -376,7 +376,7 @@ /* Sets Xtal configuration */ - printf("test 9-14\n"); +// printf("test 9-14\n"); if(s_lXtalFrequency>DOUBLE_XTAL_THR) { SpiritRadioSetXtalFlag(XTAL_FLAG((s_lXtalFrequency/2))); @@ -387,28 +387,28 @@ } /* Sets the channel number in the corresponding register */ - printf("test 9-15\n"); +// printf("test 9-15\n"); SpiritSpiWriteRegisters(CHNUM_BASE, 1, &pxSRadioInitStruct->cChannelNumber); /* Configures the Analog Radio registers */ - printf("test 9-16\n"); +// printf("test 9-16\n"); SpiritSpiWriteRegisters(CHSPACE_BASE, 4, anaRadioRegArray); /* Configures the Digital Radio registers */ - printf("test 9-17\n"); +// printf("test 9-17\n"); g_xStatus = SpiritSpiWriteRegisters(MOD1_BASE, 4, digRadioRegArray); /* Enable the freeze option of the AFC on the SYNC word */ - printf("test 9-18\n"); +// printf("test 9-18\n"); SpiritRadioAFCFreezeOnSync(S_ENABLE); /* Set the IQC correction optimal value */ - printf("test 9-19\n"); +// printf("test 9-19\n"); anaRadioRegArray[0]=0x80; anaRadioRegArray[1]=0xE3; g_xStatus = SpiritSpiWriteRegisters(0x99, 2, anaRadioRegArray); - printf("[INIT_REVISE]SpiritRadioInit end.\n"); +// printf("[INIT_REVISE]SpiritRadioInit end.\n"); return SpiritRadioSetFrequencyBase(pxSRadioInitStruct->lFrequencyBase); } @@ -3112,13 +3112,13 @@ //값을 읽어 왔을때, Reserved 영역의 니블 값이 1011 임. int iMask = 1; - printf("\n !!!!!!!!!!!\n"); - for (int i = 8; i > 0; --i) - { - //값 찍기 - printf("%d",(tempRegValue & (iMask << i-1))?1:0); - } - printf("\n !!!!!!!!!!!\n"); +// printf("\n !!!!!!!!!!!\n"); +// for (int i = 8; i > 0; --i) +// { +// //값 찍기 +// printf("%d",(tempRegValue & (iMask << i-1))?1:0); +// } +// printf("\n !!!!!!!!!!!\n");
diff -r 45b9ff78a066 -r 38de5ee78824 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 06:34:33 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
diff -r 45b9ff78a066 -r 38de5ee78824 stm-spirit1-rf-driver/SimpleSpirit1.h --- a/stm-spirit1-rf-driver/SimpleSpirit1.h Fri Jun 22 03:42:24 2018 +0000 +++ b/stm-spirit1-rf-driver/SimpleSpirit1.h Thu Sep 20 06:34:33 2018 +0000 @@ -15,7 +15,6 @@ #include "spirit1-config.h" #include "spirit1-const.h" - // betzw: enable beyond macro if you want debug messages also from IRQ handler // #define DEBUG_IRQ @@ -47,6 +46,7 @@ + /*** Missing Cube External Declarations ***/ extern "C" void SpiritManagementSetFrequencyBase(uint32_t); @@ -548,7 +548,8 @@ /** Set Channel */ - void set_channel(uint8_t channel) { + void set_channel(uint8_t channel) + { SpiritRadioSetChannel(channel); }