Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- xQueueHandle xQPedestrian;
- ...
- main:
- xQPedestrian = xQueueCreate(1, sizeof(int));
- if (xQPedestrian == NULL) {
- printf("Error creating xQPedestrian function: %s, line %d\n",
- __FUNCTION__, __LINE__);
- } else {
- /* Q successfully created
- * We disable the pedestrian functionality by default
- * and give xQueueSend 10 ticks to send it */
- if (xQueueSend( xQPedestrian, ( void * ) &DisallowPedestrianVar, ( portTickType ) 10 )
- != pdPASS) {
- printf("Error failed to send on xQPedestrian: %s, line %d\n",
- __FUNCTION__, __LINE__);
- }
- } /* xQPedestrian */
- ...
- /* shell task */
- void vTask1(void *pvParameters) {
- const char *pcTaskName = "Task 1 is running\n";
- char s[100];
- int delayVal;
- static int first_time = 1;
- int AllowPedestrianVar = 1;
- portBASE_TYPE QReceiveRetVal, QSendRetVal;
- int *pxPedestrianFlushMessage;
- /* As per most tasks, this task is implemented in an infinite loop. */
- for (;;) {
- /* Delay for a random period. */
- delayVal = rand() % (RAND_HIGH - RAND_LOW + 1) + RAND_LOW;
- vTaskDelay(delayVal / portTICK_RATE_MS);
- if (GetUseInputVal() == 1) {
- vPrintString("shell>");
- /* Wait for input
- * the brain dead library is blocking
- * also output, so we need to do some ugly tricks
- */
- scanf("%s", s);
- }
- if (strcmp("c", s) == 0) {
- vPrintString("continue\n");
- }
- else if (strcmp("p", s) == 0) {
- vPrintString("let the pedestrian go\n");
- //pedestrian=1;
- QSendRetVal
- =xQueueSend( xQPedestrian, ( void * ) &AllowPedestrianVar, ( portTickType ) 10 );
- if (QSendRetVal == errQUEUE_FULL) {
- /* this can happen the first time, since we sent a 0 over
- * and the Q is only one element long
- * so let's try to empty the queue
- */
- printf(
- "Warning failed to send on xQPedestrian first time: %s, line %d\n",
- __FUNCTION__, __LINE__);
- QReceiveRetVal
- =xQueueReceive( xQPedestrian, &( pxPedestrianFlushMessage ), ( portTickType ) 0 );
- if (QReceiveRetVal != pdTRUE) {
- /* something more serious happened here */
- printf(
- "Error failed to receive on xQPedestrian: %s, line %d\n",
- __FUNCTION__, __LINE__);
- } else {
- /* retry to send after trying to empty Q */
- QSendRetVal
- =xQueueSend( xQPedestrian, ( void * ) &AllowPedestrianVar, ( portTickType ) 10 );
- }
- }
- if (QSendRetVal != pdTRUE) {
- /* something more serious happened here */
- printf("Error failed to send on xQPedestrian: %s, line %d\n",
- __FUNCTION__, __LINE__);
- }
- } else if (strcmp("exit", s) == 0) {
- SetUseInputVal(0);
- if (first_time == 1) {
- vPrintString("killing shell\n");
- first_time = 0;
- }
- } else if (strcmp("help", s) == 0) {
- vPrintString("help:\n");
- vPrintString(" c to continue\n");
- vPrintString(" exit to kill the shell\n");
- vPrintString(" p let the pedestrian go\n");
- } else {
- vPrintString("unknown command\n");
- }
- }
- }
- -----
- #if 1
- /* don't block on message */
- ...
- ----
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement