Other Parts Discussed in Thread: CC2640
Tool/software: Code Composer Studio
previously on this issue:
Now my issue is when switching uart RX pin from GPIO with interrupt to uart function pin, the pinhandle variable is modified somewhere i'm not aware of.
My design:
Do not initialize uart in the initialization of the uart task and configure rx pin as input with interrupt.wait
initialize uart when necessary, for example there's data to be sent, remove pin configuration of RX pin ( input& interrupt) and init uart (so the rx pin will be used as uart function)
After transmission, in the uart_write_callback, close uart and configure RX pin and input with interrupt.
When data coming from the host, the exit interrupt on rx pin would be triggered and then re-init uart and start to receive data
(the rx part is remained to be completed, so no detail presents here)
When i complete the design and run the code, the program crashes down. Finally i find that pin handle of the rx pin is modified unaware.
The log:
corresponding codes:
static PIN_Handle pinHandle; PIN_Config pinConfig[] = { CC2640R2_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, PIN_TERMINATE // Terminate list }; static void Temp_uarthalinit(void) { UART_Params params; // Initialize the UART driver UART_init(); // Configure UART parameters. UART_Params_init(¶ms); params.baudRate = NPI_UART_BR; params.readDataMode = UART_DATA_BINARY; params.writeDataMode = UART_DATA_BINARY; params.dataLength = UART_LEN_8; params.stopBits = UART_STOP_ONE; params.readMode = UART_MODE_CALLBACK; params.writeMode = UART_MODE_CALLBACK; params.readEcho = UART_ECHO_OFF; params.readCallback = NPITLUART_readCallBack; params.writeCallback = NPITLUART_writeCallBack; // PIN_remove(pinHandle, CC2640R2_LAUNCHXL_UART_RX);// modified by zch 20181211 // Open / power on the UART. uartHandle = UART_open(Board_UART0, ¶ms); if (uartHandle == NULL) { // An error occured, or indexed UART peripheral is already opened HAL_ASSERT( HAL_ASSERT_CAUSE_UNEXPECTED_ERROR ); } //Enable Partial Reads on all subsequent UART_read() UART_control(uartHandle, UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE, NULL); //UART_control(uartHandle, UART_CMD_RXDISABLE, NULL); } void NPITLUART_initializeTransport(npiCB_t npiCBack)//(Char *tRxBuf, Char *tTxBuf, npiCB_t npiCBack) { PIN_State pinState; npiTransmitCB = npiCBack; // Open PIN driver and configure chip select pin callback pinHandle = PIN_open(&pinState, pinConfig); if(pinHandle == NULL) { // Error initializing button pins SC_Log_info0("fail to open pin"); //while(1); } SC_Log_info1("pin open, %d",pinHandle->portMask); if (PIN_registerIntCb(pinHandle, NPITLUART_RXPinIntCallback) != PIN_SUCCESS) { // Error registering callback function SC_Log_info0("fail to register int callback"); //while(1); }/**/ SC_Log_info1("pin open after register, %d",pinHandle->portMask); return; } static void NPITLUART_writeCallBack(UART_Handle handle, void *ptr, size_t size) { ICall_CSState key; key = ICall_enterCriticalSection(); ..... TransmitCB //inform uplayer that tx is over ..... NPITLUART_RXPinIdleConfig(); ICall_leaveCriticalSection(key); } static void NPITLUART_RXPinIntCallback(PIN_Handle handle, PIN_Id pinId) { // PIN_clrPendInterrupt(handle, pinId); if(PIN_remove(handle, pinId) != PIN_SUCCESS) { SC_Log_info0("pin remove fail"); return; } SC_Log_info1("pin open, %d",handle->portMask); SC_Log_info1("pin remove pinId %d", pinId); Temp_uarthalinit(); SC_Log_info0("hardware io interrupt"); } void NPITLUART_RXPinIdleConfig(void) { PIN_State pinState; // UART_readCancel(uartHandle); UART_close(uartHandle); // Open PIN driver and configure chip select pin callback pinHandle = PIN_open(&pinState, pinConfig); if(pinHandle == NULL) { // Error initializing button pins SC_Log_info0("fail to open pin"); //while(1); } SC_Log_info1("pin open, %d",pinHandle->portMask); if (PIN_registerIntCb(pinHandle, NPITLUART_RXPinIntCallback) != PIN_SUCCESS) { // Error registering button callback function SC_Log_info0("fail to register int callback"); //while(1); }/**/ SC_Log_info1("pin open after register, %d",pinHandle->portMask); SC_Log_info0("npi uart rx idle cfg"); } uint16 NPITLUART_writeTransport(uint8 *p, uint16 len) { ICall_CSState key; static bool flag = true; if(PIN_remove(pinHandle, CC2640R2_LAUNCHXL_UART_RX) != PIN_SUCCESS) //opration here failed if pinhanble->portmask is modified { SC_Log_info1("pin remove fail-write,%d",pinHandle->portMask); return 0; } key = ICall_enterCriticalSection(); Temp_uarthalinit(); UART_readCancel(uartHandle); .... uart_write... ... ICall_leaveCriticalSection(key); return TransportTxLen; }
Codes may seems a lot here but logical relation ship is simple. Please pay attention to it T_T
1.why i must use pin_remove before re-init uart in NPITLUART_writeTransport function, i tried without this function, the program would directly crash down, so it's necessary.
Q:
Operations about pinhandle is simply above, please help me to analyze what's wrong.
Looking forward to your reply.