示例#1
0
static void int_msg_init(void)
{
	OBJECT_INT_MSG *p_msg1;
	OBJECT_INT_MSG *p_msg2;
	RAW_U32 number;

	msg_event_handler.handle_event = int_msg_handler;

	number = OBJECT_INT_MSG_SIZE;

	raw_memset(object_int_msg, 0, sizeof(object_int_msg));
	
	free_object_int_msg = object_int_msg;
	
	/*init the free msg list*/
	p_msg1 = object_int_msg;
	p_msg2 = object_int_msg;
	p_msg2++;

	while (--number) { 

		p_msg1->next = p_msg2;

		p_msg1++;
		p_msg2++;
	}

	/*init  the last free msg*/ 
	p_msg1->next = 0;                      
	
}
示例#2
0
/*
 * Memory allocate  and clear
 */
static void *_mem_calloc( RAW_U32 nmemb, RAW_U32 size, MACB *macb )
{
	
	RAW_U32	sz = nmemb * size;
	void	*p;

	/* Allocate memory */
	p = _mem_malloc(sz, macb);
	if ( p == 0 ) {
		return 0;
	}

	/* Memory clear */
	return raw_memset(p, 0, sz);
}
示例#3
0
static RAW_U32 command_case_three_parameters(RAW_S8 *pcWriteBuffer, size_t xWriteBufferLen, const RAW_S8 *pcCommandString )
{
	RAW_S8 *pcParameter;
	RAW_U32 lParameterStringLength, xReturn;
	

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the 
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	

	if( lParameterNumber == 0 )
	{
		/* The first time the function is called after the command has been
		entered just a header string is returned. */
		raw_sprintf( ( char * ) pcWriteBuffer, "The three parameters were:\r\n" );

		/* Next time the function is called the first parameter will be echoed
		back. */
		lParameterNumber = 1L;

		/* There is more data to be returned as no parameters have been echoed
		back yet. */
		xReturn = 0;
	}
	else
	{
		/* Obtain the parameter string. */
		pcParameter = (RAW_S8 *) rsh_get_parameter
									( 
										pcCommandString,		/* The command string itself. */
										lParameterNumber,		/* Return the next parameter. */
										&lParameterStringLength	/* Store the parameter string length. */
									);

		/* Sanity check something was returned. */
		if (pcParameter == 0) {

			RAW_ASSERT(0);
		}

		/* Return the parameter string. */
		raw_memset( pcWriteBuffer, 0x00, xWriteBufferLen );
		raw_sprintf( ( char * ) pcWriteBuffer, "%d: ", lParameterNumber );
		raw_strncat( ( char * ) pcWriteBuffer, ( const char * ) pcParameter, lParameterStringLength );
		raw_strncat( ( char * ) pcWriteBuffer, "\r\n", raw_strlen( "\r\n" ) );

		/* If this is the last of the three parameters then there are no more
		strings to return after this one. */
		if( lParameterNumber == 3L )
		{
			/* If this is the last of the three parameters then there are no more
			strings to return after this one. */
			xReturn = 1;
			lParameterNumber = 0L;
		}
		else
		{
			/* There are more parameters to return after this one. */
			xReturn = 0;
			lParameterNumber++;
		}
	}

	return xReturn;
}
示例#4
0
RAW_S32 rsh_process_command( const RAW_S8 * const pcCommandInput, RAW_S8 *pcWriteBuffer, size_t xWriteBufferLen  )
{
	RAW_S32 xReturn = 0;
	const RAW_S8 *pcRegisteredCommandString;
	RAW_U8 s_input_length;
	RAW_U8 s_command_length;
	RAW_U8 s_commpare_length;

	/* Check the parameter is not NULL. */
	if (pcCommandInput == 0) {

		RAW_ASSERT(0);
	}


	if (pcWriteBuffer == 0) {

		RAW_ASSERT(0);
	}


	if (xWriteBufferLen == 0) {

		RAW_ASSERT(0);

	}
	
	/* Note:  This function is not re-entrant.  It must not be called from more
	thank one task. */

	if (current_process_command_point == 0) {

		/* Search for the command string in the list of registered commands. */
		for (current_process_command_point = &xRegisteredCommands; current_process_command_point != 0; current_process_command_point = current_process_command_point->pxNext) {
		
			pcRegisteredCommandString = current_process_command_point->pxCommandLineDefinition->pcCommand;
			s_command_length = command_length_get((const RAW_S8 *)pcRegisteredCommandString);
			s_input_length = command_length_get((const RAW_S8 *)pcCommandInput);

			if (s_input_length > s_command_length) {

				s_commpare_length = s_input_length;
			}

			else {

				s_commpare_length = s_command_length;
			}
			
			if (raw_strncmp((const char *)pcCommandInput, (const char *)pcRegisteredCommandString, s_commpare_length) == 0 ) {
			
				/* The command has been found.  Check it has the expected
				number of parameters.  If cExpectedNumberOfParameters is -1,
				then there could be a variable number of parameters and no
				check is made. */
				if (current_process_command_point->pxCommandLineDefinition->cExpectedNumberOfParameters >= 0) {
				
					if (rsh_get_parameters_numbers( pcCommandInput ) != current_process_command_point->pxCommandLineDefinition->cExpectedNumberOfParameters) {
					
						xReturn = 1;
					}
				}

				break;
			}
		}
	}

	if (current_process_command_point && (xReturn == 1)) {
	
		/* The command was found, but the number of parameters with the command
		was incorrect. */
		raw_strncpy( ( char * ) pcWriteBuffer, "\rIncorrect command parameter(s).  Enter \"help\" to view a list of available commands.\r\n\r\n", xWriteBufferLen );
		current_process_command_point = 0;
	}
	
	else if (current_process_command_point != 0) {
	
		raw_memset(pcWriteBuffer, 0, xWriteBufferLen);
		/* Call the callback function that is registered to this command. */
		xReturn = current_process_command_point->pxCommandLineDefinition->pxCommandInterpreter(pcWriteBuffer, xWriteBufferLen, pcCommandInput);

		/* If xReturn is 1, then no further strings will be returned
		after this one, and	pxCommand can be reset to NULL ready to search 
		for the next entered command. */
		if (xReturn == 1) {
			
			current_process_command_point = 0;
		}
	}
	
	else {
	
		/* pxCommand was NULL, the command was not found. */
		raw_strncpy( ( char * ) pcWriteBuffer, (const char *) "\rCommand not recognised.  Enter \"help\" to view a list of available commands.\r\n\r\n", xWriteBufferLen );
		xReturn = 1;
	}

	return xReturn;
}