/* * Carrega o buffer de saida com uma string localizada na ram */ void usb_tty_print(char *s){ unsigned int i = 0; unsigned int len = 0; char *sb = (char *)s; USB_BUFFER buf; /* verifica se o queue esta funcionando */ if(usb_buffer_queue == 0) return; while(*sb++ != '\0') len++; while(1){ if(len > USB_BUFFER_SIZE){ buf.co = USB_BUFFER_SIZE; len-=USB_BUFFER_SIZE; for(i = 0; i < USB_BUFFER_SIZE; i++){ buf.out[i] = *s++; } xQueueSendToBack(usb_buffer_queue, &buf, 20/portTICK_RATE_MS); } else { if(len > 0){ buf.co = len; for(i = 0; i < len; i++){ buf.out[i] = *s++; } xQueueSendToBack(usb_buffer_queue, &buf, 20/portTICK_RATE_MS); } break; } } }
void qprintf(xQueueHandle tx_queue, const char *format, ...){ va_list ap; va_start(ap, format); int curr_ch = 0; char out_ch[2] = {'\0', '\0'}; char newLine[3] = {'\n' , '\r', '\0'}; char percentage[] = "%"; char *str; char str_num[10]; int out_int; /* Block for 1ms. */ const portTickType xDelay = 0.1; // portTICK_RATE_MS; while( format[curr_ch] != '\0' ){ vTaskDelay( xDelay ); if(format[curr_ch] == '%'){ if(format[curr_ch + 1] == 's'){ str = va_arg(ap, char *); while (!xQueueSendToBack(tx_queue, str, portMAX_DELAY)); //parameter(...,The address of a string which is put in the queue,...) }else if(format[curr_ch + 1] == 'd'){ itoa(va_arg(ap, int), str_num); while (!xQueueSendToBack(tx_queue, str_num, portMAX_DELAY)); }else if(format[curr_ch + 1] == 'c'){ out_ch[0] = (char)va_arg(ap, int); while (!xQueueSendToBack(tx_queue, out_ch, portMAX_DELAY)); }else if(format[curr_ch + 1] == 'x'){
/* * Funcao write utilizado na retrasmissao do STDOUT, usado no printf * referencia: * http://support2.microchip.com/KBSearch/KB_StdProb.aspx?ID=SQ6UJ9A009MTU * https://www.microchip.com/forums/m601123-print.aspx * * Objetivo: Compatibilidade com outras bibliotecas, frameworks com o minimo de alteracao */ int __atribute_libc write(int handle, void *buffer, unsigned int len){ int i = 0; USB_BUFFER printf_buffer; /* verifica se o queue esta funcionando */ if(usb_buffer_queue == 0) return 0; switch(handle){ case 0: // STDOUT case 1: // STDIN case 2: // STDERR if(len > USB_BUFFER_SIZE){ while(len > USB_BUFFER_SIZE){ for(i = 0; i < USB_BUFFER_SIZE; i++){ printf_buffer.out[i] = *(char *)buffer; } len -= USB_BUFFER_SIZE; printf_buffer.co = USB_BUFFER_SIZE; xQueueSendToBack(usb_buffer_queue, &printf_buffer, 20/portTICK_RATE_MS); } goto printf_parte2; } else { printf_parte2: if(len > 0){ for(i = 0; i < len; i++){ printf_buffer.out[i] = *(char *)buffer; } printf_buffer.co = len; xQueueSendToBack(usb_buffer_queue, &printf_buffer, 20/portTICK_RATE_MS); } } break; } return(len); }
void helpCommand(xQueueHandle *outputQueue, char *line) { char str[81]; int str_i, help_i, found_end; xCommandListItem * item = &xRegisteredCommands; // Set last char as NUL str[80] = '\0'; // Print all command names while (item != NULL) { if (strlen(item->command->help) < 81) { if(xQueueSendToBack(*outputQueue, (void *) item->command->help, (portTickType) 100) != pdPASS) { sciDebug("ERROR %s:%d\n\r", __FUNCTION__, __LINE__); } } else { help_i = 0; found_end = 0; // Help text longer than 81 chars, split it up while (found_end == 0) { // Get next partition of the string for (str_i = 0; str_i < 80; str_i++) { str[str_i] = item->command->help[help_i++]; if (str[str_i] == '\0') { found_end = 1; break; } } // Print partition if(xQueueSendToBack(*outputQueue, (void *) str, (portTickType) 100) != pdPASS) { sciDebug("ERROR %s:%d\n\r", __FUNCTION__, __LINE__); } } } item = item->next; } // Send End-of-Text sprintf(str, "\3"); if(xQueueSendToBack(*outputQueue, (void *) str, (portTickType) 100) != pdPASS) { sciDebug("ERROR %s:%d\n\r", __FUNCTION__, __LINE__); } }
void guiTop_ApplyUartSettings(reqUartSettings_t *s) { uart_receiver_msg_t uart_msg; uart_msg.type = UART_APPLY_NEW_SETTINGS; uart_msg.enable = s->enable; uart_msg.parity = s->parity; uart_msg.brate = s->brate; if (s->uart_num == 1) xQueueSendToBack(xQueueUART1RX, &uart_msg, portMAX_DELAY); else xQueueSendToBack(xQueueUART2RX, &uart_msg, portMAX_DELAY); }
/** * Clears SMTP parameter * \return None */ void SMTPParamsClear() { BOOL opok = FALSE; if(mainGSM.HWReady != TRUE) return; // Function cycles until it is not executed while (!opok) { while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE // Check mainOpStatus.ExecStat if (mainOpStatus.ExecStat != OP_EXECUTION) { mainOpStatus.ExecStat = OP_EXECUTION; mainOpStatus.Function = 5; mainOpStatus.ErrorCode = 0; xQueueSendToBack(xQueue,&mainOpStatus.Function,0); // Send COMMAND request to the stack xSemaphoreGive(xSemFrontEnd); // xSemFrontEnd GIVE, the stack can answer to the command opok = TRUE; } else { xSemaphoreGive(xSemFrontEnd); taskYIELD(); } } }
static void vCheckTimerCallback( xTimerHandle xTimer ) { static unsigned short usLastRegTest1Counter = 0, usLastRegTest2Counter = 0; /* Define the status message that is sent to the LCD task. By default the status is PASS. */ static xQueueMessage xStatusMessage = { mainMESSAGE_STATUS, pdPASS }; /* This is the callback function used by the 'check' timer, as described at the top of this file. */ /* The parameter is not used. */ ( void ) xTimer; /* See if the standard demo tasks are executing as expected, changing the message that is sent to the LCD task from PASS to an error code if any tasks set reports an error. */ if( xAreComTestTasksStillRunning() != pdPASS ) { xStatusMessage.ulMessageValue = mainERROR_COM_TEST; } if( xAreDynamicPriorityTasksStillRunning() != pdPASS ) { xStatusMessage.ulMessageValue = mainERROR_DYNAMIC_TASKS; } if( xAreGenericQueueTasksStillRunning() != pdPASS ) { xStatusMessage.ulMessageValue = mainERROR_GEN_QUEUE_TEST; } if( xAreCountingSemaphoreTasksStillRunning() != pdPASS ) { xStatusMessage.ulMessageValue = mainERROR_COUNT_SEM_TEST; } if( xAreTimerDemoTasksStillRunning( ( portTickType ) mainCHECK_TIMER_PERIOD ) != pdPASS ) { xStatusMessage.ulMessageValue = mainERROR_TIMER_TEST; } /* Check the reg test tasks are still cycling. They will stop incrementing their loop counters if they encounter an error. */ if( usRegTest1Counter == usLastRegTest1Counter ) { xStatusMessage.ulMessageValue = mainERROR_REG_TEST; } if( usRegTest2Counter == usLastRegTest2Counter ) { xStatusMessage.ulMessageValue = mainERROR_REG_TEST; } usLastRegTest1Counter = usRegTest1Counter; usLastRegTest2Counter = usRegTest2Counter; /* This is called from a timer callback so must not block! */ xQueueSendToBack( xLCDQueue, &xStatusMessage, mainDONT_BLOCK ); }
static void prvPrintTask(void* pvParameters) { int iIndexToString; // Two instances of this task are created. The task parameter is used to // pass an index into an array of strings into the task. Cast this to the // required type. iIndexToString = (int)pvParameters; for (;;) { // Print out the string, not directly but instead by passing a pointer // to the string to the gatekeeper task via a queue. The queue is created // before the scheduler is started so will already exist by this time // task executes for the first time. A block time is not specified // because there should always be space in the queue. xQueueSendToBack(xPrintQueue, &pcStringsToPrint[iIndexToString], 0); // Wait a pseudo random time. Note that rand() is not necessarily // reentrant, but in this case it does not really matter as the code // does not care what value is returned. In a more secure application // a version of rand() that is known to be reentrant should be used - // or calls to rand() should be protected using a critical section. vTaskDelay(rand() & 0x1FF); } }
/** * UART to SPI protocol handler */ void uart_to_spi_write(uart_packet_t *packet) { for (INT32U i=0; i<packet->datalength; i++) { xQueueSendToBack(uart_to_spi_queue, &packet->data[i], portMAX_DELAY); } }
/** * UDPWrite - Writes on the UDP socket * \param sockwr UDP socket number * \param str2wr String to write * \param lstr String lenght * \return The number of write characters to the specified UDP socket. */ WORD UDPWrite(BYTE sockwr, BYTE* str2wr , int lstr) { while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE xErr = 0; if (xFrontEndStat == 0) { ToSend = 36; xFrontEndStatRet = 2; callbackUdpSocket = sockwr; udpByte = str2wr; udpInt = lstr; xQueueSendToBack(xQueue,&ToSend,0); // Send UDPWrite command to the stack xFrontEndStat = 1; xSemaphoreGive(xSemFrontEnd); // xSemFrontEnd GIVE } else { xErr = 36; xSemaphoreGive(xSemFrontEnd); taskYIELD(); return FALSE; } while (xFrontEndStat != 2); // Waits for stack answer while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE WORD resconn; resconn = udpWord; xFrontEndStat = 0; xSemaphoreGive(xSemFrontEnd); // xSemFrontEnd GIVE taskYIELD(); return resconn; }
static void vBlockingQueueProducer( void *pvParameters ) { unsigned short usValue = 0; xBlockingQueueParameters *pxQueueParameters; const char * const pcTaskStartMsg = "Blocking queue producer started.\r\n"; const char * const pcTaskErrorMsg = "Could not post on blocking queue\r\n"; short sErrorEverOccurred = pdFALSE; pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters; /* Queue a message for printing to say the task has started. */ vPrintDisplayMessage( &pcTaskStartMsg ); for( ;; ) { if( xQueueSendToBack( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS ) { vPrintDisplayMessage( &pcTaskErrorMsg ); sErrorEverOccurred = pdTRUE; } else { /* We have successfully posted a message, so increment the variable used to check we are still running. */ if( sErrorEverOccurred == pdFALSE ) { ( *pxQueueParameters->psCheckVariable )++; } /* Increment the variable we are going to post next time round. The consumer will expect the numbers to follow in numerical order. */ ++usValue; } } }
void ForwardAudioMessage ( const char * sCommand, const char * sFileName ) { struct AAudioMessage xAudioMessage, *pxAudioMessage = & xAudioMessage; strncpy ( xAudioMessage.Command, sCommand, 8 - 1 ); strncpy ( xAudioMessage.Parameter, sFileName, 128 - 1 ); xQueueSendToBack ( xAudioQueue, ( void * ) &pxAudioMessage, ( portTickType ) 0 ); };
/** * TCPisConn - Verifies the connection of a remote TCP device with the socket. It can be useful to catch an incoming new connection to a TCP server. * \param sockconn - The handle of the socket to control (the handle returned by the command TCPServerOpen). * \return TRUE - The remote connection is established. * \return FALSE - The remote connection is not established. */ BOOL TCPisConn(TCP_SOCKET sockconn) { BOOL opok = FALSE; while (!opok) { while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE if (xFrontEndStat == 0) { ToSend = 24; xFrontEndStatRet = 2; xSocket = sockconn; xQueueSendToBack(xQueue,&ToSend,0); // Send TCPIsConnected command to the stack xFrontEndStat = 1; xSemaphoreGive(xSemFrontEnd); // xSemFrontEnd GIVE opok = TRUE; } else { xSemaphoreGive(xSemFrontEnd); taskYIELD(); // If WiFi module if turned OFF, function doesn't do anything if (xFrontEndStat == -1) return FALSE; } } while (xFrontEndStat != 2); // Waits for stack answer while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE BOOL resconn; resconn = xBool; xFrontEndStat = 0; xSemaphoreGive(xSemFrontEnd); // xSemFrontEnd GIVE taskYIELD(); return resconn; }
void runShellCommand(xQueueHandle *outputQueue, char * line) { xCommandListItem * item = &xRegisteredCommands; char * strNotFound = "Command not found, use \"help\" to list available commands.\n\r\3"; int len; while (item != NULL) { len = strlen(item->command->name); // Either line contains only the command or followed by space if (strncmp(line, item->command->name, len) == 0 && (len == strlen(line) || line[len] == ' ')) { (*item->command->func)(outputQueue, line); break; } item = item->next; } if (item == NULL) { // Command was not found if(xQueueSendToBack(*outputQueue, (void *) strNotFound, (portTickType) 100) != pdPASS) { sciDebug("ERROR %s:%d\n\r", __FUNCTION__, __LINE__); } } }
/* This task uses the high level GPIO API (esp_gpio.h) to blink an LED. * */ void ICACHE_FLASH_ATTR readTask(void *pvParameters) { struct userdata *user = (struct userdata *)pvParameters; int a; float temperature; float R; while(1) { // read from sensor output voltage a = LM35; R = (float)(1023-a)*10000/a; // convert to Celsius temperature temperature = 1 / (log(R/10000)/B+1/298.15) - 273.15; // precision temperature = temperature * 100; // send to queue xQueueSendToBack( user->xQueue, (void *) &temperature, portMAX_DELAY ); // Resume the suspended task ourselves. if( user->xHandle != NULL ) { vTaskResume( user->xHandle ); } wait(0.8); } }
void QActive_postFIFO(QActive *me, QEvent const *e) { portBASE_TYPE err; QF_INT_LOCK_KEY_ #ifdef YYY QF_INT_LOCK_(); if (e->dynamic_ != (uint8_t)0) { ++((QEvent *)e)->dynamic_; } QF_INT_UNLOCK_(); #endif // err = xQueueSendToBack(me->eQueue, &e, (portTickType)0); #define XXX #ifdef XXX if (ulCriticalNesting == (unsigned portLONG)0) { /* task level? */ QF_INT_LOCK_(); if (e->dynamic_ != (uint8_t)0) { ++((QEvent *)e)->dynamic_; } QF_INT_UNLOCK_(); err = xQueueSendToBack(me->eQueue, &e, (portTickType)0); } else { /* must be ISR level */ portBASE_TYPE xHigherPriorityTaskWoken; err = xQueueSendToBackFromISR(me->eQueue, &e,&xHigherPriorityTaskWoken); } #endif Q_ASSERT(err == pdPASS); }
esp_err_t esp_event_send(system_event_t *event) { if (s_event_queue == NULL) { ESP_LOGE(TAG, "Event loop not initialized via esp_event_loop_init, but esp_event_send called"); return ESP_ERR_INVALID_STATE; } if (event->event_id == SYSTEM_EVENT_STA_GOT_IP || event->event_id == SYSTEM_EVENT_STA_LOST_IP) { if (g_mesh_event_cb) { mesh_event_t mevent; if (event->event_id == SYSTEM_EVENT_STA_GOT_IP) { mevent.id = MESH_EVENT_ROOT_GOT_IP; memcpy(&mevent.info.got_ip, &event->event_info.got_ip, sizeof(system_event_sta_got_ip_t)); } else { mevent.id = MESH_EVENT_ROOT_LOST_IP; } g_mesh_event_cb(mevent); } } portBASE_TYPE ret = xQueueSendToBack(s_event_queue, event, 0); if (ret != pdPASS) { if (event) { ESP_LOGE(TAG, "e=%d f", event->event_id); } else { ESP_LOGE(TAG, "e null"); } return ESP_FAIL; } return ESP_OK; }
/** * @brief Communications command parse function * @param None * @retval Command ACK or ERR */ command parseCommsCmd(void){ command cmdIn=CMD_ERR; uint8_t error=0; //try to parse command while buffer is not empty /////// do{ cmdIn = giveNextCmd(); switch(cmdIn){ case CMD_GET_CONFIG: xQueueSendToBack(messageQueue, "4SendCommsConfig", portMAX_DELAY); break; case CMD_END:break; default: error = COMMS_INVALID_FEATURE; cmdIn = CMD_ERR; break; } /////// }while(cmdIn != CMD_END && cmdIn != CMD_ERR && error==0); if(error>0){ cmdIn=error; }else{ cmdIn=CMD_END; } return cmdIn; }
// For low-severity errors only. // Note: This function does not halt regular operation, nor is the error fixed at this time. // The only reason this function would return -1 is if sending a message to the FDIR task failed. // 1 should really be returned. // The error should be placed in data[151-148] // The task ID should be placed in data[147] // Additional error code (if applicable) should be placed in data[146] // Any other desired may be placed in the lower bytes (not currently implemented) int errorREPORT(uint8_t task, uint8_t code, uint32_t error, uint32_t* data) { uint8_t i; TickType_t wait_time = 5 * 60 * 1000; for(i = 0; i < 147; i++) { high_error_array[i] = *(data + i); // Load the data into the high_error_array. } high_error_array[151] = (uint8_t)((error & 0xFF000000) >> 24); high_error_array[150] = (uint8_t)((error & 0x00FF0000) >> 16); high_error_array[149] = (uint8_t)((error & 0x0000FF00) > 8); high_error_array[148] = (uint8_t)(error & 0x000000FF); high_error_array[147] = task; high_error_array[146] = code; if (xSemaphoreTake(Lowsev_Mutex, wait_time) == pdTRUE) // Attempt to acquire Mutex, block for max 5 minutes. { if( xQueueSendToBack(low_sev_to_fdir_fifo, high_error_array, wait_time) != pdTRUE) { xSemaphoreGive(Lowsev_Mutex); return -1; } xSemaphoreGive(Lowsev_Mutex); return 1; } else return -1; }
/** * TCPRxLen - Verifies how many bytes can be read from the specified TCP socket. * \param socklen - The handle of the socket to control (the handle returned by the command TCPClientOpen or TCPServerOpen). * \return The number of bytes available to be read. */ WORD TCPRxLen(TCP_SOCKET socklen) { BOOL opok = FALSE; while (!opok) { while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE if (xFrontEndStat == 0) { ToSend=25; xFrontEndStatRet = 2; xSocket = socklen; xQueueSendToBack(xQueue,&ToSend,0); // Send TCPRxLen request to the stack xFrontEndStat = 1; xSemaphoreGive(xSemFrontEnd); // xSemFrontEnd GIVE opok = TRUE; } else { xSemaphoreGive(xSemFrontEnd); taskYIELD(); // If WiFi module if turned OFF, function doesn't do anything if (xFrontEndStat == -1) return 0; } } while (xFrontEndStat != 2); // Waits for stack answer while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE WORD reslen; reslen = xWord; xFrontEndStat = 0; xSemaphoreGive(xSemFrontEnd); // xSemFrontEnd GIVE //taskYIELD(); return reslen; }
/** * TCPpRead - Reads the specified number of characters from a TCP socket and puts them into the specified char array. <B>NOTE:</B> This function does flush the buffer! * \param socktoread - The handle of the socket to read (the handle returned by the command TCPClientOpen or TCPServerOpen). * \param readch - The char array to fill with the read characters. * \param rlen - The number of characters to read. * \param start - The starting point to read. * \warning The length of the array must be AT LEAST = rlen+1, because at the end of the operation the array it's automatically NULL terminated (is added the '\0' character). * \return None. */ void TCPpRead(TCP_SOCKET socktoread , char readch[] , int rlen, int start) { BOOL opok = FALSE; while (!opok) { while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE xErr = 0; if (xFrontEndStat == 0) { ToSend=17; xFrontEndStatRet = 2; xSocket = socktoread; xInt = rlen; xInt2 = start; xByte = (BYTE*)readch; xQueueSendToBack(xQueue,&ToSend,0); // Send cTCPRead command to the stack xFrontEndStat = 1; xSemaphoreGive(xSemFrontEnd); // xSemFrontEnd GIVE while (xFrontEndStat != 2); // Waits for stack answer while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE xFrontEndStat = 0; xSemaphoreGive(xSemFrontEnd); opok = TRUE; taskYIELD(); } else { xSemaphoreGive(xSemFrontEnd); taskYIELD(); // If WiFi module if turned OFF, function doesn't do anything if (xFrontEndStat == -1) return; } } }
static void prvRfidTask(void * parameters) { RfidMessage rfidMessage; MFRC522_PCD_Init(); for (;;) { // Look for new cards, and select one if present if (MFRC522_PICC_IsNewCardPresent() && MFRC522_PICC_ReadCardSerial()) { uint32_t i; rfidMessage.size = uid.size; for(i = 0; i < 10; i++) { rfidMessage.uidByte[i] = uid.uidByte[i]; } xQueueSendToBack(rfidEventQueue, &rfidMessage, 10); for (i = 0; i < uid.size; i++) { UARTprintf("%x", uid.uidByte[i]); } UARTprintf("\n"); MFRC522_PICC_HaltA(); } delay(50); } }
/** * TCPRxFlush - Empty specified TCP socket RX Buffer. * \param sockflush - The handle of the socket to empty (the handle returned by the command TCPClientOpen or TCPServerOpen). * \return none. */ void TCPRxFlush(TCP_SOCKET sockflush) { BOOL opok = FALSE; while (!opok) { while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE xErr = 0; if (xFrontEndStat == 0) { xFrontEndStatRet = 2; ToSend=16; xSocket = sockflush; xQueueSendToBack(xQueue,&ToSend,0); // Send COMMAND to the stack xFrontEndStat = 1; xSemaphoreGive(xSemFrontEnd); // xSemFrontEnd GIVE, the stack can answer to the command while (xFrontEndStat != 2); // Waits for stack answer while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE xFrontEndStat = 0; xSemaphoreGive(xSemFrontEnd); opok = TRUE; taskYIELD(); } else { xSemaphoreGive(xSemFrontEnd); // xSemFrontEnd GIVE taskYIELD(); // If WiFi module if turned OFF, function doesn't do anything if (xFrontEndStat == -1) return; } } }
// This function copies the the given string into the OS queue. If the queue // is full then the rest of the string is ignored. // ToDo: Ignoring a full queue is not good. // ============================================================================ void vDebugString(char *s) { portBASE_TYPE xStatus; while (*s) { xStatus = xQueueSendToBack(xDebugQueue, s++, 0); if (xStatus == errQUEUE_FULL) break; } }
int Uart3Write(char *pWriteData, const int nDataLen) { int i = 0; char *pData = pWriteData; if (!uart3_device.IsDeviceOpen) { return -1; } if( pdTRUE != xSemaphoreTake( xWriteOpLock, ( TickType_t ) 5 )) { return -2; } for (i=0; i < nDataLen; i++) { if(pdPASS != xQueueSendToBack(uart3_tx_queue, (void *)pData++, (TickType_t)3)) { // Failed to post the message, even after 10 ticks. break; } } xSemaphoreGive( xWriteOpLock ); USART_ITConfig(USART3, USART_IT_TXE, ENABLE); return i; }
// synchronous cph_tcp_receive message // this function returns whatever data is received from the port // and copies into the data buffer passed in tcp_result cph_tcp_receive(socket_connection_t *cnx, uint8_t *data) { // TODO: SEMAPHORE TAKE GIVE TASK NOTIFY tcp_result result; comm_request_t request; request.type = REQUEST_RECEIVE; connection_settimeout(cnx, DEFAULT_TCIP_RECEIVETIMEOUT); if(xQueueSendToBack( xCommQueueRequest, &request, (TickType_t)0) == pdTRUE) { result = SYS_TCP_OK; } else { result = SYS_ERR_TCP_FAIL_REQUESTENQUEUE; } if(xSemaphoreTake(tcp_receive_signal, portMAX_DELAY)) { if(cnx->socket->bytes_received > 0) { printf("cph_tcp_receive: bytes %d\r\n", cnx->socket->bytes_received); memcpy(data, cnx->socket->rx_buffer, cnx->socket->bytes_received); } } return result; }
/// @cond debug //***************************************************************************************** // Only internal use // 37 - UDPGenericClose and callback function: close an open UDP socket //***************************************************************************************** BYTE UDPGenericClose(BYTE sock) { while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE xErr = 0; if (xFrontEndStat == 0) { xFrontEndStatRet = 2; ToSend=37; callbackUdpSocket = sock; xQueueSendToBack(xQueue,&ToSend,0); // Send COMMAND to the stack xFrontEndStat = 1; xSemaphoreGive(xSemFrontEnd); // xSemFrontEnd GIVE while (xFrontEndStat != 2); // Waits for stack answer while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE xFrontEndStat = 0; xSemaphoreGive(xSemFrontEnd); taskYIELD(); } else { xErr = 37; xSemaphoreGive(xSemFrontEnd); taskYIELD(); } return 0; }
static void vIntegerGenerator( void *pvParameters ) { portTickType xLastExecutionTime; unsigned portLONG ulValueToSend = 0; int i; /* Initialize the variable used by the call to vTaskDelayUntil(). */ xLastExecutionTime = xTaskGetTickCount(); for( ;; ) { /* This is a periodic task. Block until it is time to run again. The task will execute every 200ms. */ vTaskDelayUntil( &xLastExecutionTime, 200 / portTICK_RATE_MS ); /* Send an incrementing number to the queue five times. These will be read from the queue by the interrupt service routine. A block time is not specified. */ for( i = 0; i < 5; i++ ) { xQueueSendToBack( xIntegerQueue, &ulValueToSend, 0 ); ulValueToSend++; } /* Force an interrupt so the interrupt service routine can read the values from the queue. */ vPrintString( "Generator task - About to generate an interrupt.\n" ); mainTRIGGER_INTERRUPT(); vPrintString( "Generator task - Interrupt generated.\n\n" ); } }
/// @cond debug //***************************************************************************************** // Only internal use: // 35 - UDPGenericOpen and callback function: opens a generic UDP socket //***************************************************************************************** BYTE UDPGenericOpen(char localport[], NODE_INFO* remhost, char remoteport[] ) { BYTE retsock; while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE xErr = 0; if (xFrontEndStat == 0) { xFrontEndStatRet = 2; ToSend=35; xUDPLocalPort = atoi(localport); xUDPRemotePort = atoi(remoteport); udpIPAddress = remhost; xQueueSendToBack(xQueue,&ToSend,0); // Send COMMAND to the stack xFrontEndStat = 1; xSemaphoreGive(xSemFrontEnd); // xSemFrontEnd GIVE } else { xErr = 35; //ToSend; xSemaphoreGive(xSemFrontEnd); taskYIELD(); return 0;//Socket creation error } while (xFrontEndStat != 2); // Waits for stack answer while (xSemaphoreTake(xSemFrontEnd,0) != pdTRUE); // xSemFrontEnd TAKE retsock = callbackUdpSocket; xFrontEndStat = 0; xSemaphoreGive(xSemFrontEnd); // xSemFrontEnd GIVE taskYIELD(); return retsock; }
tcp_result cph_tcp_resume(socket_connection_t *cnx) { // TODO: SEMAPHORE TAKE GIVE TASK NOTIFY tcp_result result; comm_request_t request; request.type = REQUEST_CONNECT; if(xQueueSendToBack( xCommQueueRequest, &request, (TickType_t)0) == pdTRUE) { while(true) { if(cnx->socket->socket_error > 0) { result = SYS_ERR_TCP_FAIL; break; } if(cnx->socket->socket_status == SCK_OPENED) { result = SYS_TCP_OK; break; } } } if(xSemaphoreTake(tcp_suspend_signal, portMAX_DELAY)) { //printf("tcp_connect: connected.\r\n"); } return SYS_TCP_OK; }