Beispiel #1
0
static void setting_fma(int argc, char **argv)
{
	int c;
	
	/* suspend task haliza utama dulu */
	vTaskSuspend( hdl_tampilan );
	xSerialGetChar(1, &c, 20 );

	/* disable interrupt touchpad */
	//*pFIO_MASKA_S = 0;
	//ssync();
	
	while( 1 )
	{
		if (xSerialGetChar(1, &c, 20 ) == pdTRUE) break;
		cls_layar();
		read_key();
		update_lcd();
	}
	
	//cls_layar();	
	//*pFIO_MASKA_S = PORT_INT_KEYPAD;
	//ssync();
	vTaskResume( hdl_tampilan );

}
Beispiel #2
0
/**
    <btm_rx_msg> :=
        . {<new_msg> | <msg_ack> | <msg_nack> | <btm_status>}
 */
streamlnkresult btm_rx_msg(long lPort)
{
    int ch = 0;
    int seqnum = 0;

    xSerialGetChar(lPort, &ch, portMAX_DELAY);

    switch (ch) {
        case '*':   /* start of new message */
            return btm_rx_new_msg(lPort);
            break;

        case '+':   /* ack of a msg */
            return btm_rx_ack_msg(lPort, &seqnum);
            break;

        case '-':   /* nack of a msg */
            return btm_rx_ack_msg(lPort, &seqnum);
            break;

        case '\r':  /* modem message */
            return btm_rx_status(lPort);
            break;

        default:    /* error */
            return SLNK_PARSE_ERROR;
            break;
    }
}
Beispiel #3
0
/**
    btm_rx_ack_msg :=
        '+' . <seqnum> <lf> |
        '-' . <seqnum> <lf>
 */
static streamlnkresult btm_rx_ack_msg(long lPort, int *seqnum)
{
    int ch = 0;
    streamlnkresult result;

    if ((result = btm_rx_seqnum(lPort, seqnum)) != SLNK_OK) {
        return result;
    }

    do {
        xSerialGetChar(lPort, &ch, portMAX_DELAY);

        switch (ch) {
            case '\r':
                /* receive status message */
                result = btm_rx_status(lPort);
                if (result != SLNK_OK) {
                	return result;
                }
                break;
            
            case '\n':
                return SLNK_OK;
            
            default:
                /* error */
                return SLNK_PARSE_ERROR;
        }
    } while (1);

}
Beispiel #4
0
/* Eat all chars until <lf>.
 * If eat_cr=1, then eat also <cr>, otherwise act on <cr>
 * as usual - as a modem unsolicitated message.
 */
static void btm_eat_till_eom(long lPort, int eat_cr)
{
	int ch = 0;

	do {
		xSerialGetChar(lPort, &ch, portMAX_DELAY);

		switch (ch) {
			case '\n':
				/* end of line */
				return;

			case '\r':
				if (eat_cr == EAT_HONOR_CR) {
					streamlnkresult result = btm_rx_status(lPort);
					if (result == SLNK_RESET) {
						/* state reset, no need to continue eating */
						return;
					}
				}
				break;

			default:
				break;
		}
	} while (1);
}
Beispiel #5
0
/**
    btm_rx_statustext :=
        . <string text, no escaping> <cr> <lf>
 */
static streamlnkresult btm_rx_statustext(long lPort, char *buf, int buflen)
{
    int ch;
    int cnt = 0;

    do {
        if (cnt >= buflen-1) {
            buf[cnt] = 0;
            return SLNK_OOM;
        }

        xSerialGetChar(lPort, &ch, portMAX_DELAY);

        switch (ch) {
            case '\r':  /* modem status msg */
                /* ignore */
                break;

            case '\n':  /* end of codetext */
                buf[cnt++] = ch;
                buf[cnt++] = 0;
                return SLNK_OK;
                break;

            default:
                buf[cnt++] = ch;
                break;
        }
    } while (1);
}
Beispiel #6
0
/**
    escapecode := 
        '\' . <hex-char> <hex-char>
 */
static int btm_rx_escapecode(long lPort, char *cch)
{
    char ch = 0;
    *cch = 0;
    int cnt = 0;

    do {
        xSerialGetChar(lPort, &ch, portMAX_DELAY);

        if (ch == '\r') {
            /* receive status message */
            btm_rx_status(lPort);
            continue;
        }

        if (!isxdigit((unsigned char)ch)) {
            return 1;
        }

        int x = 0;
        if (isdigit((unsigned char)ch)) {
            x = ch - '0';
        } else if (ch >= 'a' && ch <= 'f') {
            x = ch - 'a' + 10;
        } else if (ch >= 'A' && ch <= 'F') {
            x = ch - 'A' + 10;
        }

        *cch = *cch * 16 + x;
        ++cnt;
    } while (cnt < 2);

    return 0;
}
Beispiel #7
0
/**
    <seqnum> :=
        . <digit> <digit>
 */
static streamlnkresult btm_rx_seqnum(long lPort, int *seqnum)
{
    int ch = 0;
    int cnt = 0;
    *seqnum = 0;

    do {
        // xSerialPeekChar(lPort, &ch, portMAX_DELAY);
        xSerialGetChar(lPort, &ch, portMAX_DELAY);

        if (ch == '\r') {
            /* receive status message */
            streamlnkresult result = btm_rx_status(lPort);
            if (result != SLNK_OK) {
            	return result;
            }
            continue;
        }

        if (!isdigit(ch)) {
            /* error: not a digit */
            return SLNK_PARSE_ERROR;
        }

        *seqnum = *seqnum * 10 + (ch - '0');
        ++cnt;
    } while (cnt < 2);

    return SLNK_OK;
}
Beispiel #8
0
int usartGetString(long lPort, char *buf, int buflen, TickType_t xBlockTime)
{
    char ch;
    int cnt = 0;
    while ((cnt < buflen) && (xSerialGetChar(lPort, &ch, xBlockTime) == pdPASS)) {
        buf[cnt++] = ch;
    }
    /* null-terminate, if possible */
    if (cnt < buflen) {
        buf[cnt] = 0;
    }
    return cnt;
}
/*** EndHeader */
int xbee_ser_getchar( xbee_serial_t *serial)
{
	UBaseType_t ch;
	bool_t error;

	XBEE_SER_CHECK( serial);

	error = xSerialGetChar( serial, &ch);

	if (error == FALSE)
		return (int)ch;
	else
		return -ENODATA;
}
/* StartPrintTask function */
void StartPrintTask(void const * argument)
{
  /* USER CODE BEGIN StartPrintTask */
  uint8_t byte;
  /* Infinite loop */
  for(;;)
  {
    /* 从队列取出打印数据 */
    xSerialGetChar( PRINT_QUEUES_HANDLE, &byte, osWaitForever );
    
    /* 将Printf内容发往串口 */
    BSP_USART_SendData( &BSP_USART_PRINT, byte );
    
    osDelay(1);
  }
  /* USER CODE END StartPrintTask */
}
Beispiel #11
0
//////////////////////////////////////////////////////////////////////////
// WELCOME TASK Definition
// This function will clear and display the welcome screen on the terminal
static portTASK_FUNCTION( vWelcomeTask, pvParameters )
{
	// Just to stop compiler warnings.
	( void ) pvParameters;
	// UBaseType_t ubtWM;	// Only Neceesary when debugging through COM port
	
	fnPrintString(txClearReset,7);
	fnPrintString(txStartMessA,22);
	fnPrintString(txStartMessB,28);
	fnPrintString(txStartMessC,25);
	
	char rxChar;
		
	for( ;; )
	{
		// This is can also be the Rx code to interface with the board
		// Block until the first byte is received
		if (xSerialGetChar(xPort, &rxChar, comRX_BLOCK_TIME))
		{
			// DO the following ONLY if the motor is present and functional
			if ( intPhase < 7 && intPhase > 0 ) {
				if ( rxChar == 'r' || rxChar == 'R' ) {	// If the character was R-r (RUN)
					if ( txMode == 'N' ) {	// If the Motor is at Rest
						txMode = 'r';	// Switch Motor mode to RAMP up
						clkElapsed = 0;	// Reset the RAMP timer
					}
				} else if ( rxChar == 's' || rxChar == 'S' ) {	// If the character was S-s (STOP)
					if ( txMode == 'R' )	{	// If the motor is Running
						txMode = 's';	// Switch the mode to RAMP down
						clkElapsed = 0;	// Reset the RAMP timer
					}
				}
				
				// ####### Resume the Ramp Up Task
				vTaskResume( VMOtorRamp_Handle );
			} else {	// The motor is either not present OR it is not functional
				PORTC = mtrCW_Rotate[7];	// Clamp the Motor
				ledTaskRate = LED_TASK_RATE_ERROR;	// Set the Error Status Light
				txMode = 'N';	// Emphasize Motor Status of not-running
			}
		}
		
		//ubtWM = uxTaskGetStackHighWaterMark(NULL);  // GET watermark DATA
		//fnPrintWaterMark(ubtWM,2);
	}	
}
Beispiel #12
0
/**
<code_text> := non-visible chars below space  must be code using escape secquence.
    Their presence here is either an error, or a token <cr>, <lf>.
    <cr> = modem message
    <lf> = end of code_text
    Escape sequences will be expanded in application (presentation) layer, not in the stream layer!
 */
static streamlnkresult btm_rx_codetext(long lPort, char *buf, int buflen)
{
    int ch = 0;
    int cnt = 0;

    do {
        if (cnt >= buflen-1) {
            return SLNK_OOM;
        }

        xSerialGetChar(lPort, &ch, portMAX_DELAY);

        switch (ch) {
            case '\r': { /* modem status msg */
                streamlnkresult result = btm_rx_status(lPort);
                if (result != SLNK_OK) {
                	return result;
                }
                break;
            }

            case '\n':  /* end of codetext */
                buf[cnt++] = ch;
                buf[cnt++] = 0;
                return SLNK_OK;
                break;
#if 0
            case '\\':  /* escape char */
                btm_rx_escapecode(lPort, &ch);
                buf[cnt++] = ch;
                break;
#endif
            default:
                if (ch >= 0 && ch < 32) {
                    /* this char should have been escaped! */
                    return SLNK_PARSE_ERROR;
                }

                buf[cnt++] = ch;
                break;
        }
    } while (1);
}
/*** EndHeader */
int xbee_ser_read( xbee_serial_t *serial, void FAR *buffer, int bufsize)
{
	int16_t read;
	UBaseType_t *buff = (UBaseType_t *)buffer;

	XBEE_SER_CHECK( serial );

	if (! buffer || bufsize < 0)
	{
		return -EINVAL;
	}

	for( read = 0; read < bufsize; ++read )
	{
		if( !(xSerialGetChar( serial, &buff[read] )))	// if there's an error, because we have no bytes
				return -EIO;							// return an error
	}

	return read;										// otherwise return bytes read.
}
Beispiel #14
0
/* Described at the top of this file. */
static void prvUSARTEchoTask( void *pvParameters )
{
signed char cChar;

/* String declared static to ensure it does not end up on the stack, no matter
what the optimisation level. */
static const char *pcLongishString = 
"ABBA was a Swedish pop music group formed in Stockholm in 1972, consisting of Anni-Frid Frida Lyngstad, "
"Björn Ulvaeus, Benny Andersson and Agnetha Fältskog. Throughout the band's existence, Fältskog and Ulvaeus "
"were a married couple, as were Lyngstad and Andersson - although both couples later divorced. They became one "
"of the most commercially successful acts in the history of popular music, and they topped the charts worldwide "
"from 1972 to 1983.  ABBA gained international popularity employing catchy song hooks, simple lyrics, sound "
"effects (reverb, phasing) and a Wall of Sound achieved by overdubbing the female singers' voices in multiple "
"harmonies. As their popularity grew, they were sought after to tour Europe, Australia, and North America, drawing "
"crowds of ardent fans, notably in Australia. Touring became a contentious issue, being particularly cumbersome for "
"Fältskog, but they continued to release studio albums to widespread commercial success. At the height of their "
"popularity, however, both relationships began suffering strain that led ultimately to the collapse of first the "
"Ulvaeus-Fältskog marriage (in 1979) and then of the Andersson-Lyngstad marriage in 1981. In the late 1970s and early "
"1980s these relationship changes began manifesting in the group's music, as they produced more thoughtful, "
"introspective lyrics with different compositions.";

	/* Just to avoid compiler warnings. */
	( void ) pvParameters;

	/* Initialise COM0, which is USART1 according to the STM32 libraries. */
	lCOMPortInit( mainCOM0, mainBAUD_RATE );

	/* Try sending out a string all in one go, as a very basic test of the
    lSerialPutString() function. */
    lSerialPutString( mainCOM0, pcLongishString, strlen( pcLongishString ) );

	for( ;; )
	{
		/* Block to wait for a character to be received on COM0. */
		xSerialGetChar( mainCOM0, &cChar, portMAX_DELAY );

		/* Write the received character back to COM0. */
		xSerialPutChar( mainCOM0, cChar, 0 );
	}
}
Beispiel #15
0
/**
    <btm_status> :=
        <cr> . <lf> <status_text> <cr> <lf>
 */
static streamlnkresult btm_rx_status(long lPort)
{
    int ch;
    streamlnkresult result;

    xSerialGetChar(lPort, &ch, portMAX_DELAY);
    if (ch != '\n') {
        /* expected \n */
        return SLNK_PARSE_ERROR;
    }

    const int buflen = 256;
    char *buf = pvPortMalloc(sizeof(char) * buflen);

    if (!buf) {
        /* malloc failed */
        /* eat till end of message <lf>, including <cr> */
        btm_eat_till_eom(lPort, EAT_ALSO_CR);
        return SLNK_RESET;
    }
    
    if ((result = btm_rx_statustext(lPort, buf, buflen)) != SLNK_OK) {
        /* error reading status message from modem */
        if (result == SLNK_OOM) {
	        /* eat till end of message <lf>, including <cr> */
	        btm_eat_till_eom(lPort, EAT_ALSO_CR);
			result = SLNK_RESET;        	
        }
        return result;
    }

    /* act on the status message */
    if (do_decode_btm_status(buf) == 0) {
        result = SLNK_OK;
    } else {
        result = SLNK_RESET;
    }
    vPortFree(buf);
    return result;
}
Beispiel #16
0
void testUSART(void)
{
    u8 temp,recvNum;
    while(1){
        recvNum=uxQueueMessagesWaiting(xRxedChars);
        printf("Hello world!,rec=%d\r\n",recvNum);
        Delay_Ms(500);

        if(recvNum>0)
        {
            while(recvNum--){
                xSerialGetChar((signed char*)&temp,0);
                xSerialPutChar(temp , 5/portTICK_RATE_MS);
            }
            //xSerialPutChar('\r' , 5/portTICK_RATE_MS);
            //xSerialPutChar('\n' , 5/portTICK_RATE_MS);
        }

        Delay_Ms(300);

    }
}
Beispiel #17
0
/*********************************************************************
 * Function:        void taskSerial(void* pvParameter)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          Does not return
 *
 * Side Effects:    None
 *
 * Overview:
 *
 * Note:
 ********************************************************************/
void taskUART(void* pvParameter)
{
	static GRAPHICS_MSG msg;
        unsigned char val;
//	vTaskSetApplicationTaskTag( NULL, ( void * ) 's' );
        xSerialPortInitMinimal( 115200, 10 );


	while (1) {
     	vTaskDelay( 50 / portTICK_RATE_MS );   // Wait 50ms
	if( xSerialGetChar(NULL, &val, 0xffff ) )
			xSerialPutChar( NULL, val, 0xffff );

//	LATFbits.LATF3 ^= 0x04;
//	LATDbits.LATD0 ^= 0x01;


//	xSerialPutChar( NULL, 'A', 0xffff );
//	xSerialPutChar( NULL, 'B', 0xffff );

        }

}
static int ReceiveCmd(char* buf)
{
    unsigned short idx = -1;

    /* accumulate characters until the enter is hit */
    do {
        /* increment index pointer for each character increment */
        idx++;

        if (xSerialGetChar(xComPort, (signed char *) &buf[idx], portMAX_DELAY) == pdFALSE) {
            continue;
        }

        /* echo the character back to the terminal */
        xSerialPutChar(xComPort, buf[idx], 0);

        /* handle the hit of an backspace by shifting the idx back */
        if(buf[idx] == '\b'){
            idx -= 2;
        }

        /* add some verbosity for the demo */
        if (verbose >= 2) {
            printf("buf[%d] = 0x%02x\n", idx, buf[idx]);
        }
    } while ((buf[idx] != '\n') && (buf[idx] != '\r'));

    /* return the command string without the new line, so we have only the command */
    buf[idx] = '\0';

    if (verbose >= 1){
        mdump(buf, 512);
    }

    /* return the length of the string */
    return idx + 1;
}
static void prvUARTCommandConsoleTask( void *pvParameters )
{
    signed char cRxedChar;
    uint8_t ucInputIndex = 0;
    char *pcOutputString;
    static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];
    BaseType_t xReturned;
    xComPortHandle xPort;

    ( void ) pvParameters;

    /* Obtain the address of the output buffer.  Note there is no mutual
    exclusion on this buffer as it is assumed only one command console interface
    will be used at any one time. */
    pcOutputString = FreeRTOS_CLIGetOutputBuffer();

    /* Initialise the UART. */
    xPort = xSerialPortInitMinimal( configCLI_BAUD_RATE, cmdQUEUE_LENGTH );

    /* Send the welcome message. */
    vSerialPutString( xPort, ( signed char * ) pcWelcomeMessage, ( unsigned short ) strlen( pcWelcomeMessage ) );

    for( ;; )
    {
        /* Wait for the next character.  The while loop is used in case
        INCLUDE_vTaskSuspend is not set to 1 - in which case portMAX_DELAY will
        be a genuine block time rather than an infinite block time. */
        while( xSerialGetChar( xPort, &cRxedChar, portMAX_DELAY ) != pdPASS );

        /* Ensure exclusive access to the UART Tx. */
        if( xSemaphoreTake( xTxMutex, cmdMAX_MUTEX_WAIT ) == pdPASS )
        {
            /* Echo the character back. */
            xSerialPutChar( xPort, cRxedChar, portMAX_DELAY );

            /* Was it the end of the line? */
            if( cRxedChar == '\n' || cRxedChar == '\r' )
            {
                /* Just to space the output from the input. */
                vSerialPutString( xPort, ( signed char * ) pcNewLine, ( unsigned short ) strlen( pcNewLine ) );

                /* See if the command is empty, indicating that the last command
                is to be executed again. */
                if( ucInputIndex == 0 )
                {
                    /* Copy the last command back into the input string. */
                    strcpy( cInputString, cLastInputString );
                }

                /* Pass the received command to the command interpreter.  The
                command interpreter is called repeatedly until it returns
                pdFALSE	(indicating there is no more output) as it might
                generate more than one string. */
                do
                {
                    /* Get the next output string from the command interpreter. */
                    xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );

                    /* Write the generated string to the UART. */
                    vSerialPutString( xPort, ( signed char * ) pcOutputString, ( unsigned short ) strlen( pcOutputString ) );

                } while( xReturned != pdFALSE );

                /* All the strings generated by the input command have been
                sent.  Clear the input string ready to receive the next command.
                Remember the command that was just processed first in case it is
                to be processed again. */
                strcpy( cLastInputString, cInputString );
                ucInputIndex = 0;
                memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );

                vSerialPutString( xPort, ( signed char * ) pcEndOfOutputMessage, ( unsigned short ) strlen( pcEndOfOutputMessage ) );
            }
            else
            {
                if( cRxedChar == '\r' )
                {
                    /* Ignore the character. */
                }
                else if( ( cRxedChar == '\b' ) || ( cRxedChar == cmdASCII_DEL ) )
                {
                    /* Backspace was pressed.  Erase the last character in the
                    string - if any. */
                    if( ucInputIndex > 0 )
                    {
                        ucInputIndex--;
                        cInputString[ ucInputIndex ] = '\0';
                    }
                }
                else
                {
                    /* A character was entered.  Add it to the string entered so
                    far.  When a \n is entered the complete	string will be
                    passed to the command interpreter. */
                    if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
                    {
                        if( ucInputIndex < cmdMAX_INPUT_SIZE )
                        {
                            cInputString[ ucInputIndex ] = cRxedChar;
                            ucInputIndex++;
                        }
                    }
                }
            }

            /* Must ensure to give the mutex back. */
            xSemaphoreGive( xTxMutex );
        }
    }
}
static void prvUARTCommandConsoleTask( void *pvParameters )
{
char cRxedChar, cInputIndex = 0, *pcOutputString;
static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];
portBASE_TYPE xReturned;

	( void ) pvParameters;

	/* Obtain the address of the output buffer.  Note there is no mutual
	exclusion on this buffer as it is assumed only one command console
	interface will be used at any one time. */
	pcOutputString = FreeRTOS_CLIGetOutputBuffer();

	/* Send the welcome message. */
	vSerialPutString( NULL, ( const signed char * ) pcWelcomeMessage, strlen( ( char * ) pcWelcomeMessage ) );

	for( ;; )
	{
		/* Only interested in reading one character at a time. */
		while( xSerialGetChar( NULL, ( signed char * ) &cRxedChar, portMAX_DELAY ) == pdFALSE );

		/* Echo the character back. */
		xSerialPutChar( NULL, cRxedChar, portMAX_DELAY );

		/* Was it the end of the line? */
		if( cRxedChar == '\n' || cRxedChar == '\r' )
		{
			/* Just to space the output from the input. */
			vSerialPutString( NULL, ( const signed char * ) pcNewLine, strlen( ( char * ) pcNewLine ) );

			/* See if the command is empty, indicating that the last command is
			to be executed again. */
			if( cInputIndex == 0 )
			{
				/* Copy the last command back into the input string. */
				strcpy( ( char * ) cInputString, ( char * ) cLastInputString );
			}

			/* Pass the received command to the command interpreter.  The
			command interpreter is called repeatedly until it returns pdFALSE
			(indicating there is no more output) as it might generate more than
			one string. */
			do
			{
				/* Get the next output string from the command interpreter. */
				xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );

				/* Write the generated string to the UART. */
				vSerialPutString( NULL, ( const signed char * ) pcOutputString, strlen( ( char * ) pcOutputString ) );

			} while( xReturned != pdFALSE );

			/* All the strings generated by the input command have been sent.
			Clear the input	string ready to receive the next command.  Remember
			the command that was just processed first in case it is to be
			processed again. */
			strcpy( ( char * ) cLastInputString, ( char * ) cInputString );
			cInputIndex = 0;
			memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
			vSerialPutString( NULL, ( const signed char * ) pcEndOfOutputMessage, strlen( ( char * ) pcEndOfOutputMessage ) );
		}
		else
		{
			if( cRxedChar == '\r' )
			{
				/* Ignore the character. */
			}
			else if( cRxedChar == '\b' )
			{
				/* Backspace was pressed.  Erase the last character in the
				string - if any. */
				if( cInputIndex > 0 )
				{
					cInputIndex--;
					cInputString[ cInputIndex ] = '\0';
				}
			}
			else
			{
				/* A character was entered.  Add it to the string
				entered so far.  When a \n is entered the complete
				string will be passed to the command interpreter. */
				if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
				{
					if( cInputIndex < cmdMAX_INPUT_SIZE )
					{
						cInputString[ cInputIndex ] = cRxedChar;
						cInputIndex++;
					}
				}
			}
		}
	}
}
Beispiel #21
0
static portTASK_FUNCTION( vComRxTask, pvParameters )
{
signed char cExpectedByte, cByteRxed;
portBASE_TYPE xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;

	/* Just to stop compiler warnings. */
	( void ) pvParameters;

	for( ;; )
	{
		/* We expect to receive the characters from comFIRST_BYTE to
		comLAST_BYTE in an incrementing order.  Loop to receive each byte. */
		for( cExpectedByte = comFIRST_BYTE; cExpectedByte <= comLAST_BYTE; cExpectedByte++ )
		{
			/* Block on the queue that contains received bytes until a byte is
			available. */
			if( xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME ) )
			{
				/* Was this the byte we were expecting?  If so, toggle the LED,
				otherwise we are out on sync and should break out of the loop
				until the expected character sequence is about to restart. */
				if( cByteRxed == cExpectedByte )
				{
					vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
				}
				else
				{
					xResyncRequired = pdTRUE;
					break; /*lint !e960 Non-switch break allowed. */
				}
			}
		}

		/* Turn the LED off while we are not doing anything. */
		vParTestSetLED( uxBaseLED + comRX_LED_OFFSET, pdFALSE );

		/* Did we break out of the loop because the characters were received in
		an unexpected order?  If so wait here until the character sequence is
		about to restart. */
		if( xResyncRequired == pdTRUE )
		{
			while( cByteRxed != comLAST_BYTE )
			{
				/* Block until the next char is available. */
				xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME );
			}

			/* Note that an error occurred which caused us to have to resync.
			We use this to stop incrementing the loop counter so
			sAreComTestTasksStillRunning() will return false - indicating an
			error. */
			xErrorOccurred++;

			/* We have now resynced with the Tx task and can continue. */
			xResyncRequired = pdFALSE;
		}
		else
		{
			if( xErrorOccurred < comTOTAL_PERMISSIBLE_ERRORS )
			{
				/* Increment the count of successful loops.  As error
				occurring (i.e. an unexpected character being received) will
				prevent this counter being incremented for the rest of the
				execution.   Don't worry about mutual exclusion on this
				variable - it doesn't really matter as we just want it
				to change. */
				uxRxLoops++;
			}
		}
	}
} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
Beispiel #22
0
static void vComRxTask( void *pvParameters )
{
portBASE_TYPE xState = comtstWAITING_START_OF_STRING, xErrorOccurred = pdFALSE;
signed char *pcExpectedByte, cRxedChar;
const xComPortHandle xPort = NULL;

	/* The parameter is not used in this example. */
	( void ) pvParameters;

	/* Start the Tx timer.  This only needs to be started once, as it will
	reset itself thereafter. */
	xTimerStart( xTxTimer, portMAX_DELAY );

	/* The first expected Rx character is the first in the string that is
	transmitted. */
	pcExpectedByte = ( signed char * ) comTRANSACTED_STRING;

	for( ;; )
	{
		/* Wait for the next character. */
		if( xSerialGetChar( xPort, &cRxedChar, ( comTX_MAX_BLOCK_TIME * 2 ) ) == pdFALSE )
		{
			/* A character definitely should have been received by now.  As a
			character was not received an error must have occurred (which might
			just be that the loopback connector is not fitted). */
			xErrorOccurred = pdTRUE;
		}

		switch( xState )
		{
			case comtstWAITING_START_OF_STRING:
				if( cRxedChar == *pcExpectedByte )
				{
					/* The received character was the first character of the
					string.  Move to the next state to check each character
					as it comes in until the entire string has been received. */
					xState = comtstWAITING_END_OF_STRING;
					pcExpectedByte++;

					/* Block for a short period.  This just allows the Rx queue 
					to contain more than one character, and therefore prevent
					thrashing reads to the queue, and repetitive context 
					switches as	each character is received. */
					vTaskDelay( comSHORT_DELAY );
				}
				break;

			case comtstWAITING_END_OF_STRING:
				if( cRxedChar == *pcExpectedByte )
				{
					/* The received character was the expected character.  Was
					it the last character in the string - i.e. the null
					terminator? */
					if( cRxedChar == 0x00 )
					{
						/* The entire string has been received.  If no errors
						have been latched, then increment the loop counter to
						show this task is still healthy. */
						if( xErrorOccurred == pdFALSE )
						{
							uxRxLoops++;

							/* Toggle an LED to give a visible sign that a
							complete string has been received. */
							vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
						}

						/* Go back to wait for the start of the next string. */
						pcExpectedByte = ( signed char * ) comTRANSACTED_STRING;
						xState = comtstWAITING_START_OF_STRING;
					}
					else
					{
						/* Wait for the next character in the string. */
						pcExpectedByte++;
					}
				}
				else
				{
					/* The character received was not that expected. */
					xErrorOccurred = pdTRUE;
				}
				break;

			default:
				/* Should not get here.  Stop the Rx loop counter from
				incrementing to latch the error. */
				xErrorOccurred = pdTRUE;
				break;
		}
	}
}
Beispiel #23
0
static portTASK_FUNCTION( vComRxTask, pvParameters )		{
signed char cExpectedByte, cByteRxed;
portBASE_TYPE xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
portBASE_TYPE xGotChar;
int ch, mm=0;
char s[30];

	/* Just to stop compiler warnings. */
	( void ) pvParameters;
	vTaskDelay(1);
	
	//vSerialPutString(xPort, "mulakan\r\n", 9);
	
	init_banner();
	//set_env_default();
	baca_konfig_rom();					// hardware/iap.c
	//load_data_rtc();
	
	cmd_shell();
	st_hw.init++;
	
	#ifdef PAKAI_RTC
		//init_RTC_sh();
		start_uptime();
	#endif
	
	#ifdef PAKAI_SDCARD
		st_hw.sdc = 0;
		//disk_initialize(SDC);
		disk_initialize(0);
		set_fs_mount();
		cek_fs_free();
		//mount_disk(0);		// 0: SDCARD
		//uprintf("Cek Memori SDCARD: ...");
		//cek_free_cluster();
		st_hw.sdc = 1;
	#endif
	
	#ifdef configUSE_IDLE_HOOK
		st_hw.init++;
	#endif

	do	{
		vTaskDelay(100);
	} while (st_hw.init != uxTaskGetNumberOfTasks());
	
	//vTaskDelay(100);
	#ifdef PAKAI_SDCARD
	//uprintf("Cek Memori SDCARD: ...");
	//cek_free_cluster();
	#endif
	vTaskDelay(100);
	sprintf(s, "%s$ ", PROMPT);
	
	
	#ifdef PAKAI_FREERTOS_CLI		// gak jadi pake FreeRTOS-CLI
	uprintf(s);
	vRegisterCLICommands();
	
	for(;;)	{
		//uprintf("Merdeka!!!\r\n");
		//vSerialPutString(xPort, "tes\r\n", 5);
		xGotChar = xSerialGetChar( xPort, &ch, 10 );
		if( xGotChar == pdTRUE )		{
			//if( xSerialGetChar( xPort, &ch, comRX_BLOCK_TIME ) )		{ // comRX_BLOCK_TIME = 0xffff
			//tinysh_char_in((unsigned char) ch);
			toogle_led_utama();
			if ((uchr) ch=='\r')	{
				sprintf(s, "\r\n%s$ ", PROMPT);
				uprintf(s);
			}
		}
		vTaskDelay(10);
	}
	#endif
	
	#ifdef PAKAI_TINYSH
	tinysh_set_prompt(s);
	tinysh_char_in('\r');
	vTaskDelay(500);
	for( ;; )	{
		//vTaskDelay(10);
		//printf("testing\r\n");
		xGotChar = xSerialGetChar( xPort, &ch, 10 );
		
		if( xGotChar == pdTRUE )		{
			tinysh_char_in((unsigned char) ch);
			toogle_led_utama();
		}
		if (st_hw.mm>=120)	{			// cron tiap 1 menit
		//if (st_hw.mm >= 10)	{			// cron tiap 10detik
		//if (st_hw.mm>=2)		{			// cron tiap 1 detik
			st_hw.mm = 0;
			st_hw.uuwaktu++;
			#ifdef PAKAI_FILE_SIMPAN
			simpan_file_data();
			#endif
		}
		
		qrprintf(0);
	}
	#endif	
	
	for( ;; )	{
		vTaskDelay(10);
	}
}
Beispiel #24
0
portTASK_FUNCTION(ambilcepat, pvParameters )	{
    vTaskDelay(500);

    int loopambil=0;

#ifdef PAKAI_SHELL
    printf(" Monita : Ambil cepat init !!\r\n");
#endif

#if defined(PAKAI_I2C) && defined(PAKAI_TSC)
    unsigned char st_tsc=0;
    char a;
    int i;
    int c=0;

    if (setup_fma())	printf(" NO ack !\r\n");
    else	{
        printf("Init TSC OK ack !!!\r\n");
        st_tsc = 1;
    }
#endif

#ifdef PAKAI_GPS
    int hasil_gpsnya;
    awal_gps();
#endif

#ifdef PAKAI_ADC
    extern unsigned char status_adcnya;
#endif

#ifdef PAKAI_GPIO_DIMMER
    //init_remang();
#endif

#ifdef PAKAI_PM
    int almtSumber=0;
    int sPM=0;

#ifdef AMBIL_PM
    printf("Init ambil PM ..-ambilcepat-..!!!\r\n");
    vTaskDelay(3000);
#endif
#endif

    int waktunya=0;
    char dataserial[50];

    vTaskDelay(50);
    for(;;) {
        vTaskDelay(1);

#ifdef DATA_RANDOM
        data_f[loopambil%10] = (float) ((rand() % 100));
        //printf("%d: data: %.1f\r\n", loopambil%10, data_f[loopambil%10]);
#endif

        loopambil++;
#ifdef PAKAI_GPS
        if (serPollGPS())
        {
            hasil_gpsnya = proses_gps();
#if 0
            info_gps(hasilGPS);
#endif
        }
#endif

#ifdef PAKAI_PM
#ifdef AMBIL_PM			// AMBIL_PM
        sedot_pm();
#endif
#endif

#ifdef PAKAI_ADC
        if (status_adcnya) {
            proses_data_adc();
            //printf("proses adc ... %d !!\r\n", status_adcnya);

#ifdef BOARD_KOMON_420_SAJA
            hitung_datanya();
#endif

            simpan_ke_data_f();
        }
#endif

#ifdef BOARD_KOMON_KONTER
        if (loopambil%20==0) {		// 5x20 = 100
            hitung_rpm();
        }
        data_frek_rpm();
#endif

#ifdef BOARD_KOMON_KONTER_3_0
        if (loopambil%20==0) {		// 5x20 = 100
            hitung_rpm();
            data_frek_rpm();
        }
#endif

#ifdef PAKAI_I2C
#if 0
        if (st_tsc) {
            if (loopambil%500==0) {	// 2*250: 500ms = 0.5 detik
                printf("__detik: %3d\r\n", c++);
                //baca_register_tsc();

#if 1
                if (int_berganti() == 0)
                {
                    printf("disentuh\r\n");
                }
                else
                    printf("HIGH\r\n");
                //vSerialPutString(0, "HIGH\r\n");
#endif
            }
        }
#endif
#if 0
        if (st_tsc) {
            if (xSerialGetChar(1, &c, 0xFFFF ) == pdTRUE)
            {
                vSerialPutString(0, "Tombol ditekan = ");
                xSerialPutChar(	0, (char ) c);
                vSerialPutString(0, " \r\n");

                if ( (char) c == 's')
                {
                    printf(" Set\r\n");
                    /*
                    if (i2c_set_register(0x68, 1, 8))
                    {
                    	out(" NO ACK !!\r\n");
                    }
                    else
                    	out(" OK\r\n");
                    */

                    if (setup_fma())
                    {
                        printf(" NO ack !\r\n");
                    }
                    else
                        printf(" OK ack !\r\n");


                }
                else
                {
                    printf("====\r\n");
                    for (i=0; i<16; i++)
                    {
                        if (i == 8) printf("****\r\n");

                        if (i2c_read_register(0x68, (0x50 + i), &a))
                        {
                            printf(" Read failed !\r\n");
                        }
                        else
                        {
                            printf(" Read OK =");
                            a = a + '0';
                            printf("%c", (char) a);
                            printf(" \r\n");
                        }
                    }

                    printf("KEY \r\n");
                    if (i2c_read_register(0x68, 0x68, &a))
                    {
                        printf(" Read failed !\r\n");
                    }
                    else
                    {
                        printf(" Read OK =");
                        a = a + '0';
                        printf("%c", (char) a);
                        printf(" \r\n");
                    }
                    //a = read_key();
                    //a = a + '0';
                    //xSerialPutChar(	0, (char ) a);
                }
            }
        }
#endif

#endif


#ifdef PAKAI_GPIO_DIMMER
        //remangkan();
        /*
        loop_pwm++;

        #ifdef DEBUG_PWM_GPIO
        if (loop_pwm>500) {
        	loop_pwm=0;
        	blink_pwm=1-blink_pwm;
        	if (blink_pwm) {
        		FIO1SET = BIT(30);
        	} else {
        		FIO1CLR = BIT(30);
        	}
        }
        #endif
        //*/
#endif
    }

#ifdef PAKAI_GPS
    deinit_gps();
#endif
}
Beispiel #25
0
static void vComRxTask( void *pvParameters )
{
const char * const pcTaskStartMsg = "COM Rx task started.\r\n";
const char * const pcTaskErrorMsg = "COM read error\r\n";
const char * const pcTaskRestartMsg = "COM resynced\r\n";
const char * const pcTaskTimeoutMsg = "COM Rx timed out\r\n";
const portTickType xBlockTime = ( portTickType ) 0xffff / portTICK_RATE_MS;
const char *pcExpectedChar;
portBASE_TYPE xGotChar;
char cRxedChar;
short sResyncRequired, sConsecutiveErrors, sLatchedError;

	/* Stop warnings. */
	( void ) pvParameters;

	/* Queue a message for printing to say the task has started. */
	vPrintDisplayMessage( &pcTaskStartMsg );
	
	/* The first expected character is the first character in the string. */
	pcExpectedChar = pcMessageToExchange;
	sResyncRequired = pdFALSE;
	sConsecutiveErrors = 0;
	sLatchedError = pdFALSE;

	for( ;; )
	{
		/* Receive a message from the com port interrupt routine.  If a message is 
		not yet available the call will block the task. */
		xGotChar = xSerialGetChar( xPort, &cRxedChar, xBlockTime );
		if( xGotChar == pdTRUE )
		{
			if( sResyncRequired == pdTRUE )
			{
				/* We got out of sequence and are waiting for the start of the next 
				transmission of the string. */
				if( cRxedChar == '\n' )
				{
					/* This is the end of the message so we can start again - with 
					the first character in the string being the next thing we expect 
					to receive. */
					pcExpectedChar = pcMessageToExchange;
					sResyncRequired = pdFALSE;

					/* Queue a message for printing to say that we are going to try 
					again. */
					vPrintDisplayMessage( &pcTaskRestartMsg );

					/* Stop incrementing the check variable, if consecutive errors occur. */
					sConsecutiveErrors++;
					if( sConsecutiveErrors >= comMAX_CONSECUTIVE_ERRORS )
					{
						sLatchedError = pdTRUE;
					}
				}
			}
			else
			{
				/* We have received a character, but is it the expected character? */
				if( cRxedChar != *pcExpectedChar )
				{
					/* This was not the expected character so post a message for 
					printing to say that an error has occurred.  We will then wait 
					to resynchronise. */
					vPrintDisplayMessage( &pcTaskErrorMsg );					
					sResyncRequired = pdTRUE;
				}
				else
				{
					/* This was the expected character so next time we will expect 
					the next character in the string.  Wrap back to the beginning 
					of the string when the null terminator has been reached. */
					pcExpectedChar++;
					if( *pcExpectedChar == '\0' )
					{
						pcExpectedChar = pcMessageToExchange;

						/* We have got through the entire string without error. */
						sConsecutiveErrors = 0;
					}
				}
			}

			/* Increment the count that is used to check that this task is still 
			running.  This is only done if an error has never occurred. */
			if( sLatchedError == pdFALSE )
			{
				sRxCount++;			
			}
		}
		else
		{
			vPrintDisplayMessage( &pcTaskTimeoutMsg );
		}
	}
} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
Beispiel #26
0
portTASK_FUNCTION(shell, pvParameters )
{
  	int c;
  	xTaskHandle xHandle;
  	printf("\n%s v%s\r\n", NAMA_BOARD, VERSI_KOMON);

  	printf("Daun Biru Engineering, Des 2008\r\n");
  	printf("=========================================\r\n");
  	printf("ARM-GCC %s : %s : %s\r\n", __VERSION__, __DATE__, __TIME__);
  	printf("CPU = LPC 2387, %d MHz,", configCPU_CLOCK_HZ/1000000);
  	printf(" FreeRTOS 5.1.1\r\n");

	if (configUSE_PREEMPTION == 0)
		printf("NON Preemptive kernel digunakan !\r\n"); 
	else
		printf("Preemptive kernel digunakan !\r\n");
	
	#ifdef USB_TEST
	Host_Init();               /* Initialize the lpc2468 host controller                                    */
    //c = Host_EnumDev();       /* Enumerate the device connected */     
   	// if (c == 0) printf("Ketemu !\r\n");  
   	
   	#if 1
   	if (OHCIInit() == 0)
   	{
   		printf("------------ Init error \r\n");
   	}
   	
   	//install_usb_interrupt();
   	#endif
	#endif
	
	/* 
	 * add command
	 */
  	//tinysh_add_command(&myfoocmd);
  	tinysh_add_command(&printenv_cmd);
	tinysh_add_command(&setenv_cmd);
//	tinysh_add_command(&save_env_cmd);
	tinysh_add_command(&reset_cmd);
	tinysh_add_command(&cek_stack_cmd);
	tinysh_add_command(&uptime_cmd);
	tinysh_add_command(&version_cmd);
	
#ifdef BOARD_KOMON_KONTER
	tinysh_add_command(&cek_rpm_cmd);
	tinysh_add_command(&set_kanal_cmd);
#endif

//#ifdef BOARD_TAMPILAN
#ifdef CARI_SUMBER
	tinysh_add_command(&cek_sumber_cmd);
	tinysh_add_command(&set_sumber_cmd);
	//tinysh_add_command(&cek_mesin_cmd);
	//tinysh_add_command(&set_mesin_cmd);
	//tinysh_add_command(&cek_titik_cmd);
	//tinysh_add_command(&set_titik_cmd);
	
	tinysh_add_command(&save_sumber_cmd);
	//tinysh_add_command(&save_mesin_cmd);
	//tinysh_add_command(&save_titik_cmd);
#endif


#ifdef BOARD_KOMON_A_RTD
	tinysh_add_command(&cek_adc_cmd);
	tinysh_add_command(&set_kanal_cmd);
#endif

#ifdef BOARD_KOMON_420_SAJA
#ifdef PAKAI_ADC
	tinysh_add_command(&cek_adc_cmd);
	tinysh_add_command(&lihat_data_cmd);
#endif
	tinysh_add_command(&set_kanal_cmd);
#endif

#ifdef BOARD_KOMON_420_SABANG
#ifdef PAKAI_ADC
	tinysh_add_command(&cek_adc_cmd);
	//tinysh_add_command(&lihat_data_cmd);

	tinysh_add_command(&set_kanal_cmd);
#endif
#endif

#ifdef BOARD_KOMON_B_THERMO
	tinysh_add_command(&cek_adc_cmd);
	tinysh_add_command(&set_kanal_cmd);
#endif

#ifdef PAKE_TELNETD
	tinysh_add_command(&matikan_telnet_cmd);
#endif

#ifdef PAKAI_PM
//	tinysh_add_command(&cek_pm_cmd);
//	tinysh_add_command(&set_pm_cmd);
//	tinysh_add_command(&cek_konfig_pmnya_cmd);
#endif	
	
#ifdef PAKAI_GSM_FTP
	tinysh_add_command(&set_modem_ftp_cmd);
	tinysh_add_command(&cek_modem_cmd);
	tinysh_add_command(&set_modem_gsm_cmd);
	tinysh_add_command(&gsm_ftp_cmd);
	tinysh_add_command(&cek_ftp_cmd);
	
#endif	

#ifdef PAKAI_SMS
	tinysh_add_command(&cek_pulsa_cmd);
	tinysh_add_command(&kirim_sms_cmd);
	tinysh_add_command(&hapus_sms_cmd);
	tinysh_add_command(&baca_sms_cmd);
	tinysh_add_command(&baca_sms_semua_cmd);
	tinysh_add_command(&sms_monita_cmd);
#endif 

#ifdef PAKAI_CRON
	tinysh_add_command(&set_cron_cmd);
	tinysh_add_command(&cek_cron_cmd);
#endif

//#ifdef CARI_SUMBERNYA
#ifdef BOARD_TAMPILAN
	tinysh_add_command(&cek_group_cmd);
	tinysh_add_command(&set_group_cmd);
	
	//tinysh_add_command(&cek_sumber_cmd);
	//tinysh_add_command(&set_sumber_cmd);
	
	// data
	//tinysh_add_command(&set_data_cmd);
	//tinysh_add_command(&cek_data_cmd);
	//printf("board_tampilan\r\n");

#endif
vTaskDelay(100);
#ifdef BANYAK_SUMBER
	tinysh_add_command(&cek_sumber_cmd);
	tinysh_add_command(&set_sumber_cmd);
	tinysh_add_command(&set_data_cmd);
	tinysh_add_command(&cek_data_cmd);
	//printf("banyak sumber\r\n");
#endif
vTaskDelay(100);

#if (VERSI_KONFIGx == 2)
	tinysh_add_command(&cek_group_cmd);
	tinysh_add_command(&set_group_cmd);
	
	tinysh_add_command(&cek_sumber_cmd);
	tinysh_add_command(&set_sumber_cmd);
	
	// data
	tinysh_add_command(&set_data_cmd);
	tinysh_add_command(&cek_data_cmd);
#endif	

// simpan file
#ifdef PAKAI_FILE_SIMPAN	
	tinysh_add_command(&cek_file_cmd);
	tinysh_add_command(&set_file_cmd);
	tinysh_add_command(&del_direktori_cmd);
	tinysh_add_command(&cari_doku_cmd);
	tinysh_add_command(&hapus_filenya_cmd);
#endif


#ifdef CENDOL
	tinysh_add_command(&cek_konfig_cmd);
	tinysh_add_command(&set_konfig_cmd);
#endif

#ifdef PAKAI_MULTI_SERIAL
	#if defined(PAKAI_SERIAL_1) || defined(PAKAI_SERIAL_2) || defined(PAKAI_SERIAL_3)
		tinysh_add_command(&kirim_serial_cmd);
	#endif
#endif
	/* add sub commands
 	*/
  	//tinysh_add_command(&ctxcmd);
  	//tinysh_add_command(&item1);
  	//tinysh_add_command(&item2);

	/* use a command from the stack
 	* !!! this is only possible because the shell will have exited
 	* before the stack of function main !!!
 	*/
  	/*
	{
    	tinysh_cmd_t quitcmd={0,"quit","exit shell",0,reset_to_0,
                          (void *)&again,0,0};
    	tinysh_add_command(&quitcmd);
  	}*/

	/* add atoxi support test command */
  	//tinysh_add_command(&atoxi_cmd);



	/* add a background command */
  	//tinysh_add_command(&bgcmd);
  	//xTaskCreate( bg_cmd_thread, "bg_cmd", 1000, NULL, 2, &xHandle);

	#ifdef PAKAI_MMC
  	vTaskDelay(340);
  	#else
  	vTaskDelay(450);
  	#endif

	#ifdef PAKAI_SELENOID
		static tinysh_cmd_t set_relay_cmd={0,"set_relay","setting relay", "help default ",set_relay,0,0,0};
		tinysh_add_command(&set_relay_cmd);
	#endif
	
	
//#ifdef BOARD_TAMPILAN	
	#ifdef CARI_SUMBERx	
	// cek ukuran struk
	printf("size struct Mesin  = %d\r\n", sizeof (struct t_mesin) * JML_MESIN);
	printf("size struct Sumber = %d\r\n", sizeof (struct t_sumber) * JML_SUMBER);
	printf("size struct Titik  = %d\r\n", sizeof (struct t_titik) * JML_MESIN * TIAP_MESIN);
	//printf("size struct sambungan = %d\r\n", sizeof (samb));
	#endif
	
	#ifdef BOARD_KOMON_420_SAJA
	kalibrasi_adc1();
	vTaskDelay(100);
	start_adc_1();
	#endif
	
	#ifdef BOARD_KOMON_420_SABANG
		#ifdef PAKAI_ADC
			kalibrasi_adc1();
			vTaskDelay(100);
			start_adc_1();
		#endif
		vTaskDelay(100);
	#endif
	
	#ifdef BOARD_KOMON_A_RTD
	kalibrasi_adc1();
	vTaskDelay(100);
	start_adc_1();
	#endif
	
	#ifdef BOARD_KOMON_B_THERMO
	kalibrasi_adc1();
	vTaskDelay(100);
	start_adc_1();
	#endif
	
	#ifdef BOARD_KOMON_KONTER
		#ifdef PAKAI_RTC
		rtc_init();
		vTaskDelay(100);
		//baca_rtc_mem();
		#endif
	#endif
	
	#ifdef PAKAI_MMC
	tinysh_add_command(&util_ls_cmd);
	tinysh_add_command(&util_mkdir_cmd);
	tinysh_add_command(&util_cd_cmd);
	tinysh_add_command(&util_pwd_cmd);
	tinysh_add_command(&util_view_cmd);
	
	init_gpio_mmc();
	uncs_mmc();
	vTaskDelay(5);
	set_fs_mount();
	vTaskDelay(5);
	status_MMC = cek_fs_free();
	
	struct t_simpan_file *ts;
	ts = (char *) ALMT_SFILE;
	vTaskDelay(5);
	
	if (status_MMC) {
		printf("_____MMC ERROR !!!!_____ %d\r\n", status_MMC);
		if (status_MMC==13) 
			printf("_____MMC FR_NO_FILESYSTEM, kudu diformat FAT32 !!!\r\n");
		
		if (ts->set==1) {
			set_file_mati();
			printf("simpan data ke file dimatikan !!\r\n");
		}
	} else {
		status_MMC = 1;
		printf("MMC aktif. Siap simpan data: %d\r\n", status_MMC);
	}
	/*
	FR_NOT_READY,		3 
	FR_NO_FILE,			4 
	FR_NO_PATH,			5 
	FR_INVALID_NAME,	6 
	FR_DENIED,			7 
	FR_EXIST,			8 
	FR_INVALID_OBJECT,	9 
	FR_WRITE_PROTECTED,	10
	FR_INVALID_DRIVE,	11
	FR_NOT_ENABLED,		12
	FR_NO_FILESYSTEM,	13
	FR_MKFS_ABORTED,	14
	FR_TIMEOUT			15
	//*/
	
	
	sprintf(abs_path, "%s", "");
	#endif
	
	#ifdef PAKAI_RTC	
	tinysh_add_command(&set_date_cmd);
	#endif
	
	
	struct t_env *envx;
	envx = (char *) ALMT_ENV;

	sprintf(str,"%s%d$ ", PROMPT, (envx->IP3));
	tinysh_set_prompt(str);
	//tinysh_set_prompt( PROMPT );
	/* force untuk tampil prompt */
	tinysh_char_in('\r');
	int perdetiknya=0;

	/*
	printf("nChr: %d, nInt: %d, nLInt: %d, nFloat: %d, nDouble: %d\r\n", \
		sizeof(char), sizeof(int), sizeof(long int), sizeof(float), sizeof(double));
	printf("nChr: %d, nInt: %d, nLInt: %d, nFloat: %d, nDouble: %d\r\n", \
		255, 20000000, 20000000, 20000000, 20000000);
	//*/
	/*
	 * main loop shell
  	 */
  	int lop = 0;
  	while(1)
    {
		vTaskDelay(1);
	  lop++;
	  if (xSerialGetChar(1, &c, 100 ) == pdTRUE)
	  {
			lop = 0;
			tinysh_char_in((unsigned char)c);
	  }	
	  
	  /* dilindungi password setiap menit tidak ada aktifitas*/
	  if (lop > 6000)
	  {
			lop = 0;
			printf("\r\nPasswd lock!\r\n");
			while(1)
			{
				if (xSerialGetChar(1, &c, 100) == pdTRUE)	{
					if (proses_passwd( &c ) == 1) break;
				}
				#ifdef PAKAI_MMC
					#ifdef PAKAI_FILE_SIMPAN
						perdetiknya++;
						if (perdetiknya==10 && status_MMC==1) {
							proses_simpan_file();
							perdetiknya=0;
						}
					#endif
				#endif
				
				#ifdef PAKAI_ADC
					#ifdef BOARD_KOMON_A_RTD
					proses_data_adc();
					#endif
					 
					#ifdef BOARD_KOMON_B_THERMO
					proses_data_adc();
					#endif
					
					#ifdef BOARD_KOMON_420_SABANG
					proses_data_adc();
					#endif
					
					#ifdef BOARD_KOMON_420_SAJA
					proses_data_adc();
					hitung_datanya();
					#endif
					
					simpan_ke_data_f();
				#endif
				
				#ifdef BOARD_KOMON_KONTER
					data_frek_rpm();
				#endif
			}
	  }
	  
		// pembacaaan ADC dipindah dari task eth ke shell 1 Okt 2010.
		#ifdef PAKAI_ADC
			#ifdef BOARD_KOMON_A_RTD
				proses_data_adc();
			#endif
		 
			#ifdef BOARD_KOMON_B_THERMO
				proses_data_adc();
			#endif
				 
			#ifdef BOARD_KOMON_420_SAJA
				proses_data_adc();
				hitung_datanya();
			#endif
			
			#ifdef BOARD_KOMON_420_SABANG
				proses_data_adc();
			#endif
			
			simpan_ke_data_f();
		#endif
		
		#ifdef BOARD_KOMON_KONTER
			data_frek_rpm();
		#endif
	  
		#ifdef PAKAI_MMC
			#ifdef PAKAI_FILE_SIMPAN
				perdetiknya++;
				if (perdetiknya==10 && status_MMC==1) {
					proses_simpan_file();
					perdetiknya=0;
				}
			#endif
		#endif
	  
	  #ifdef USB_TEST
	  c = HC_INT_STAT ;
	  {
	  	printf("%4d: usb stat 0x%X\r\n", lop, c);
	  	
	  	HC_INT_STAT |= c;
	  	
	  	usb_terup = 0;
	  }
	  #endif
    }
  	
  	return;
}
Beispiel #27
0
/* Described at the top of this file. */
void BluetoothModemTask( void *pvParameters )
{
    char cChar;

    /* Just to avoid compiler warnings. */
    ( void ) pvParameters;


    /* Initialise COM0, which is USART1 according to the STM32 libraries. */
    lCOMPortInit( comBTM, mainBAUD_RATE );

    /* Reset BTM */
    #if 0
    GPIO_ResetBits(BTM_Reset_Port, BTM_Reset_Pin);
    vTaskDelay( ( TickType_t ) 10 / portTICK_PERIOD_MS );
    GPIO_SetBits(BTM_Reset_Port, BTM_Reset_Pin);
    #endif

    // do { } while (1);

    // const char *atEscape = "^^^";
    const char *atEscapeChar = "^";
    const char *atEOL = "\r";
    const char *atTest = "AT\r";
    
    // after-reset condition: give the BT module some time to init itself.
    vTaskDelay( ( TickType_t ) 1000 / portTICK_PERIOD_MS );

    do {
        #if 1
        // Before the escape sequence there must be silence for 1s
        vTaskDelay( ( TickType_t ) 1200 / portTICK_PERIOD_MS );
        
        lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) );
        vTaskDelay( ( TickType_t ) 120 / portTICK_PERIOD_MS );
        lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) );
        vTaskDelay( ( TickType_t ) 120 / portTICK_PERIOD_MS );
        lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) );
        
        // After the escape sequence there must be silence for 1s
        vTaskDelay( ( TickType_t ) 1200 / portTICK_PERIOD_MS );
        #endif

        LEDs_Set(LED0, LED_INTENS_0, LED_INTENS_100, LED_INTENS_0);

        // Send end of line
        lSerialPutString( comBTM, atEOL, strlen(atEOL) );
        // wait a little bit
        vTaskDelay( ( TickType_t ) 100 / portTICK_PERIOD_MS );
        // empty input buffer
        usartDrainInput(comBTM);            /* this drains possible 'ERROR 05' status */
        
        // vTaskDelay( ( TickType_t ) 10 / portTICK_PERIOD_MS );

        // Send plain AT
        lSerialPutString( comBTM, atTest, strlen(atTest) );
        // vTaskDelay( ( TickType_t ) 20 / portTICK_PERIOD_MS );
        
        // expect "OK\r\n"
    } while (btmExpectOK());

    LEDs_Set(LED0, LED_INTENS_0, LED_INTENS_0, LED_INTENS_100);

    
    GPIO_InitTypeDef GPIO_InitStruct;
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2 /*| GPIO_Pin_1*/;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init( GPIOA, &GPIO_InitStruct );
    do { } while (1);

    // disable local echo
    const char *atDisableEcho = "ATE0\r";
    lSerialPutString( comBTM, atDisableEcho, strlen(atDisableEcho) );
    if (btmExpectOK()) {
        // failed
        assert_failed(__FILE__, __LINE__);
    }

    const char *atSetDeviceName = "AT*agln=\"PIP-Watch\",0\r\n";
    lSerialPutString( comBTM, atSetDeviceName, strlen(atSetDeviceName) );
    if (btmExpectOK()) {
        // failed
        assert_failed(__FILE__, __LINE__);
    }

    const char *atSetPin = "AT*agfp=\"1234\",0\r";
    lSerialPutString( comBTM, atSetPin, strlen(atSetPin) );
    if (btmExpectOK()) {
        // failed
        assert_failed(__FILE__, __LINE__);
    }

    const char *atToDataMode = "AT*addm\r";
    lSerialPutString( comBTM, atToDataMode, strlen(atToDataMode) );
    if (btmExpectOK()) {
        // failed
        assert_failed(__FILE__, __LINE__);
    }


    /* Try sending out a string all in one go, as a very basic test of the
    lSerialPutString() function. */
    // lSerialPutString( comBTM, pcLongishString, strlen( pcLongishString ) );

    int k = 0;
    char *buf = NULL;

    for( ;; )
    {
        /* Block to wait for a character to be received on COM0. */
        xSerialGetChar( comBTM, &cChar, portMAX_DELAY );

        /* Write the received character back to COM0. */
        xSerialPutChar( comBTM, cChar, 0 );

        if (!buf) {
            buf = pvPortMalloc(sizeof(char) * 32);

        #if 0
            /* start ADC conversion by software */
            // ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
            ADC_ClearFlag(ADC1, ADC_FLAG_STRT);
            ADC_Cmd(ADC1, ENABLE);
        #if 0
            ADC_SoftwareStartConvCmd(ADC1, ENABLE);
            /* wait till the conversion starts */
            while (ADC_GetSoftwareStartConvStatus(ADC1) != RESET) { }
        #endif
            /* wait till the conversion ends */
            while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) != SET) { }
        #endif
            
            k = 0;
            // k = itostr(buf, 32, RTC_GetCounter());
            // k = itostr(buf, 32, ADC_GetConversionValue(ADC1));
            // k = itostr(buf, 32, vbat_measured);
            // k = itostr(buf, 32, vbat_percent);

            // ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
        }

        buf[k++] = cChar;
        
        if (cChar == '\r' || k >= 30) {
            buf[k] = '\0';
            
            for (int i = 0; i < k-4; ++i) {
                if (buf[i] == '*') {
                    /* set time: *<hours><minutes> */
                    int hours = (buf[i+1]-'0')*10 + (buf[i+2]-'0');
                    int minutes = (buf[i+3]-'0')*10 + (buf[i+4]-'0');
                    hours %= 24;
                    minutes %= 60;
                    current_rtime.sec = 0;
                    current_rtime.hour = hours;
                    current_rtime.min = minutes;
                    break;
                }
            }

            if (xQueueSend(toDisplayStrQueue, &buf, 0) == pdTRUE) {
                // ok; will alloc new buffer
                buf = NULL;
            } else {
                // fail; ignore, keep buffer
            }

            // motor demo
            GPIO_SetBits(GPIOB, 1 << 13);
            vTaskDelay( ( TickType_t ) 300 / portTICK_PERIOD_MS );
            GPIO_ResetBits(GPIOB, 1 << 13);

            k = 0;
            xSerialPutChar( comBTM, '\n', 0 );
        }

    }
}
/* StartDataParseTask function */
void StartDataParseTask(void const * argument)
{
  /* USER CODE BEGIN StartDataParseTask */
  uint8_t tmp;
  SYS_DEBUG_TRACK();
  
  /* Infinite loop */
  for(;;)
  {
    SYS_DEBUG("one loop!\n");

    /*------------------------接收并解析数据包---------------------------*/
    /* 1. 开始接收数据帧*/
     /*读取帧头1——head1 */
    xSerialGetChar( ReceiveDataQueueHandle, &tmp, osWaitForever ); 

    /*判断是否为帧头1——head1*/
    if( tmp == SENSOR_PROTOCOL_PACK_HEADER0 )                            
    {
      /*读取帧头2——head2*/
      xSerialGetChar( ReceiveDataQueueHandle, &tmp, osWaitForever );

      /*如果读到的还是帧头1,则重新读帧头2;防止重复的帧头1干扰*/
      if( tmp == SENSOR_PROTOCOL_PACK_HEADER0 )                           
      {
        /* 重新读取帧头2 */
        xSerialGetChar( ReceiveDataQueueHandle, &tmp, osWaitForever );        
      }
 
      /* 验证帧头2——head2*/
      if( tmp == SENSOR_PROTOCOL_PACK_HEADER1  )                        
      {
        /* 读取数据段长度 len */
        uint8_t len;
        xSerialGetChar( ReceiveDataQueueHandle, &len, osWaitForever );
        if( len == SENSOR_PROTOCOL_PACK_MAX_DATA_LEN )
        {
          /* 从邮箱申请空间,用来保存读取结果 */
          SensorData_t* pSensorData;
          pSensorData = (SensorData_t *) osMailAlloc( gSenorDataMail, osWaitForever);
          
          /* 读取数据段内容 */
          uint8_t* ptr = (uint8_t*)pSensorData ;
          uint8_t i;
          for( i = 0; i < len; i++ )
          {
            /* 循环接收整个数据段 */
            xSerialGetChar( ReceiveDataQueueHandle, ptr++, osWaitForever ); 
          }
          
          /* 读取校验字节 */
          xSerialGetChar( ReceiveDataQueueHandle, &tmp , osWaitForever ); 
          if( tmp == doSumCheck( (uint8_t*)pSensorData, len ) )
          {
            /* 如果校验通过,则发送缓冲区到队列 */
            if( osOK != osMailPut( gSenorDataMail, pSensorData) )  
            {
              ;   //TODO: Add something here
            }
          }else
          {
            /* 释放内存空间 */
            osMailFree( gSenorDataMail, pSensorData );
          }
          
        }
      }
    }
    
//    osDelay(1);
  }
  /* USER CODE END StartDataParseTask */
}
Beispiel #29
0
void usartDrainInput(long lPort)
{
    char ch;
    while (xSerialGetChar(lPort, &ch, 0) == pdPASS)
        ;
}
Beispiel #30
0
int GetKey(void)
{
	int ch = 0;
	xSerialGetChar(0, &ch, 0);
	return ch;
}