コード例 #1
0
//------------------------------------------------------------------------------------
static int gTR_E05(void)
{

	// Envio el comando AT para abrir el socket

size_t xBytes;

	cTimer = 5;	// Consulto c/5s si abrio el socket
	pTryes = 6;	// Lo hago 6 veces.

	FreeRTOS_ioctl( &pdUART0,ioctl_UART_CLEAR_RX_BUFFER, NULL);
	FreeRTOS_ioctl( &pdUART0,ioctl_UART_CLEAR_TX_BUFFER, NULL);
	g_flushRXBuffer();

	xBytes = snprintf_P( gprs_printfBuff,sizeof(gprs_printfBuff),PSTR("AT*E2IPO=1,\"%s\",%s\r\n\0"),systemVars.serverAddress,systemVars.serverPort);
	FreeRTOS_write( &pdUART0, gprs_printfBuff, sizeof(gprs_printfBuff) );

	// Debug
	tickCount = xTaskGetTickCount();
	snprintf_P( gprs_printfBuff,sizeof(gprs_printfBuff),PSTR(".[%06lu] tkGprs: OPEN SOCKET (%d)\r\n\0"),tickCount,qTryes );
	u_debugPrint(D_GPRS, gprs_printfBuff, sizeof(gprs_printfBuff) );

	g_printExitMsg("E05\0");
	return(gSST_OPENSOCKET_04);
}
コード例 #2
0
ファイル: mcp_sp5K.c プロジェクト: ppeluffo/sp5KV4_8CH
/*------------------------------------------------------------------------------------*/
s08 MCP_read( u08 deviceId, u08 byteAddr, u08 *retValue )
{
size_t xReturn = 0U;
u16 val = 0;
u08 xBytes = 0;

	// Lo primero es obtener el semaforo
	FreeRTOS_ioctl(&pdI2C,ioctlOBTAIN_BUS_SEMPH, NULL);
	// Luego indicamos el periferico i2c en el cual queremos leer
	val = deviceId;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_DEVADDRESS, &val);
	// Luego indicamos en que posicion del periferico queremos leer: largo
	val = 1;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESSLENGTH, &val);
	// y direccion
	val = byteAddr;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	// Por ultimo leemos 1 byte.
	xBytes = 1;
	xReturn = FreeRTOS_read(&pdI2C, retValue, xBytes);
	// Y libero el semaforo.
	FreeRTOS_ioctl(&pdI2C,ioctlRELEASE_BUS_SEMPH, NULL);

	if (xReturn != xBytes ) {
		return ( FALSE );
	}

	return(TRUE);

}
コード例 #3
0
//------------------------------------------------------------------------------------
static int gTR_E00(void)
{

	// Evento inicial. Solo salta al primer estado operativo.
	// Inicializo cTimer para esperar hasta 10s que cierre el socket si
	// esta abierto

	// Cierro el socket por las dudas.
	FreeRTOS_ioctl( &pdUART0,ioctl_UART_CLEAR_RX_BUFFER, NULL);
	FreeRTOS_ioctl( &pdUART0,ioctl_UART_CLEAR_TX_BUFFER, NULL);
	g_flushRXBuffer();

	// Paso primero a modo comando
	FreeRTOS_write( &pdUART0, "+++AT\r\0", sizeof("+++AT\r\0") );
	vTaskDelay( ( TickType_t)( 500 / portTICK_RATE_MS ) );
	// Y mando el comando de cerrar el socket. Si esta cerrado va a responder ERROR pero no importa
	FreeRTOS_write( &pdUART0, "AT*E2IPC=1\r\0", sizeof("AT*E2IPC=1\r\0") );
	vTaskDelay( ( TickType_t)( 500 / portTICK_RATE_MS ) );

	// No muestro la respuesta del modem ya que si esta cerrado va a indicar ERROR y
	// puede confundir al operador.
	//g_printRxBuffer();

	cTimer = 30;	// Espero hasta 30s que el socket este cerrado.

	g_printExitMsg("E00\0");
	return(gSST_OPENSOCKET_01);
}
コード例 #4
0
static void prvCANWriteTask( void *pvParameters )
{
static Peripheral_Descriptor_t xCAN = NULL;
portTickType xLastWakeTime;
const portTickType xFrequency = 100;

xLastWakeTime = xTaskGetTickCount ();

uint64_t cTxedChar=0xC3C3C3C3C3C3;
uint64_t cRxedChar=0;
uint32_t *id=(void *)0x00012340;
uint8_t *frame_type=0;
uint8_t *frame_length=6;
uint8_t *use_irq=1;

	( void ) pvParameters;

	xCAN=FreeRTOS_open( boardCAN, ( uint32_t ) cmdPARAMTER_NOT_USED );

	FreeRTOS_ioctl( xCAN,ioctlSET_CAN_FRAME_TYPE ,(void *)frame_type);


	FreeRTOS_ioctl( xCAN,ioctlSET_CAN_FRAME_LENGTH,(void *)frame_length);
	FreeRTOS_write(xCAN, &cTxedChar,sizeof(cTxedChar));
	//FreeRTOS_ioctl( xCAN,ioctlUSE_INTERRUPTS,(void *)use_irq);
	//FreeRTOS_read( xCAN, &cRxedChar,sizeof(cRxedChar));

	for( ;; )
	{
		vTaskDelayUntil( &xLastWakeTime, xFrequency );
		FreeRTOS_ioctl( xCAN,ioctlSET_CAN_EXT_ID,(void *)id);
		FreeRTOS_write(xCAN, &cTxedChar,sizeof(cTxedChar));
	}
}
コード例 #5
0
ファイル: mcp_sp5K.c プロジェクト: ppeluffo/sp5KV4_8CH
//------------------------------------------------------------------------------------
// Funciones de uso general
//------------------------------------------------------------------------------------
s08 MCP_write( u08 deviceId, u08 byteAddr, u08 value )
{
u08 regValue;
size_t xReturn = 0U;
u16 val = 0;
u08 xBytes = 0;

	// Lo primero es obtener el semaforo
	FreeRTOS_ioctl(&pdI2C,ioctlOBTAIN_BUS_SEMPH, NULL);
	// Luego indicamos el periferico i2c en el cual queremos leer
	val = deviceId;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_DEVADDRESS, &val);
	// Luego indicamos la direccion del dispositivo: largo
	val = 1;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESSLENGTH, &val);
	// y direccion
	val = byteAddr;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	// Por ultimo indico la direccion interna a leer
	// Por ultimo leemos 1 byte.
	xBytes = 1;
	regValue = value;
	xReturn = FreeRTOS_write(&pdI2C, &regValue, xBytes);
	// Y libero el semaforo.
	FreeRTOS_ioctl(&pdI2C,ioctlRELEASE_BUS_SEMPH, NULL);

	if (xReturn != xBytes ) {
		return ( FALSE );
	}

	return(TRUE);

}
コード例 #6
0
//------------------------------------------------------------------------------------
static int gTR_A12(void)
{
	// Envio un comando AT y espero 1s para evaluar la respuesta

size_t pos;

	FreeRTOS_ioctl( &pdUART0,ioctl_UART_CLEAR_RX_BUFFER, NULL);
	FreeRTOS_ioctl( &pdUART0,ioctl_UART_CLEAR_TX_BUFFER, NULL);

	g_flushRXBuffer();
	FreeRTOS_write( &pdUART0, "AT\r\0", sizeof("AT\r\0") );

	vTaskDelay( ( TickType_t)( 1000 / portTICK_RATE_MS ) );

	// Leo y Evaluo la respuesta al comando AT
	GPRS_flags.modemResponse = MRSP_NONE;
	if ( g_strstr("OK\0", &pos ) == TRUE ) {
		GPRS_flags.modemResponse = MRSP_OK;
	}

	// Muestro el resultado.
	g_printRxBuffer();

	g_printExitMsg("A12\0");
	return(gSST_OFF_06);
}
コード例 #7
0
ファイル: I2C.c プロジェクト: stmich/BAC2
void vI2C_Initialize( void )
{

    /* Open the I2C port used for writing to both the OLED and the EEPROM.  The
     second parameter (ulFlags) is not used in this case.  The port is opened in
     polling mode.  It is changed to interrupt driven mode later in this
     function. */
    xI2CPort = FreeRTOS_open(board_I2C_PORT,
            (uint32_t) i2cPARAMETER_NOT_USED);
    configASSERT( xI2CPort );

    /* Switch to interrupt driven zero copy Tx mode and interrupt driven
     circular buffer Rx mode (with a limited time out). */
    FreeRTOS_ioctl(xI2CPort, ioctlUSE_ZERO_COPY_TX, i2cPARAMETER_NOT_USED);
    FreeRTOS_ioctl(xI2CPort, ioctlUSE_CIRCULAR_BUFFER_RX,
            i2cCIRCULAR_BUFFER_SIZE);
    FreeRTOS_ioctl(xI2CPort, ioctlSET_RX_TIMEOUT, i2c200MS_TIMEOUT);

    /* By default, the I2C interrupt priority will have been set to
     the lowest possible.  It must be kept at or below
     configMAX_LIBRARY_INTERRUPT_PRIORITY, but can be raised above
     its default priority using a FreeRTOS_ioctl() call with the
     ioctlSET_INTERRUPT_PRIORITY command. */
    FreeRTOS_ioctl(xI2CPort, ioctlSET_INTERRUPT_PRIORITY,
            (void *) configI2C_INTERRUPT_PRIORITY);

    xOLEDMutex = xSemaphoreCreateMutex();
}
コード例 #8
0
ファイル: file_sp5K.c プロジェクト: ppeluffo/sp5KV4
//------------------------------------------------------------------------------------
s08 FF_seek(void)
{
	// Ajusta la posicion del puntero de lectura al primer registro a leer, es decir
	// al DELptr.
	FreeRTOS_ioctl(&pdI2C,ioctlOBTAIN_BUS_SEMPH, NULL);
	FCB.ff_stat.RD = FCB.ff_stat.TAIL;
	FreeRTOS_ioctl(&pdI2C,ioctlRELEASE_BUS_SEMPH, NULL);
	return(TRUE);

}
コード例 #9
0
ファイル: file_sp5K.c プロジェクト: ppeluffo/sp5KV4
//------------------------------------------------------------------------------------
s08 FF_del(void)
{
	// Borra un registro apuntado por TAIL.

u16 val = 0;
size_t xReturn = 0U;
s08 retS = FALSE;

	// Lo primero es obtener el semaforo del I2C
	FreeRTOS_ioctl(&pdI2C,ioctlOBTAIN_BUS_SEMPH, NULL);
	FCB.ff_stat.errno = pdFF_ERRNO_NONE;

	// Si la memoria esta vacia salgo
	if ( FCB.ff_stat.rcdsFree == FF_MAX_RCDS ) {
		goto quit;
	}

	// Voy a escribir en c/registro un registro en blanco
	memset( FCB.ff_buffer,0, sizeof(FCB.ff_buffer) );
	// Indicamos el periferico i2c en el cual queremos leer
	val = EE_ADDR;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_DEVADDRESS, &val);
	// Luego indicamos la direccion a escribir del dispositivo: largo ( en la ee son 2 bytes )
	val = 2;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESSLENGTH, &val);
	// y la direccion interna en la EE.(comienzo del registro / frontera)
	val = FF_ADDR_START + FCB.ff_stat.TAIL * FF_RECD_SIZE;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	// Por ultimo escribo la memoria. Escribo un pagina entera, 64 bytes.
	xReturn = FreeRTOS_write(&pdI2C, &FCB.ff_buffer, FF_RECD_SIZE);

	// Por ahora no controlo los errores de borrado
	FCB.ff_stat.rcdsFree++;
	FCB.ff_stat.TAIL = (++FCB.ff_stat.TAIL == FF_MAX_RCDS) ?  0 : FCB.ff_stat.TAIL;
	retS = TRUE;

quit:

	// libero los semaforos
	FreeRTOS_ioctl(&pdI2C,ioctlRELEASE_BUS_SEMPH, NULL);
	return(retS);
}
コード例 #10
0
ファイル: file_sp5K.c プロジェクト: ppeluffo/sp5KV4
//------------------------------------------------------------------------------------
void FF_stat( StatBuffer_t *pxStatBuffer )
{
	// Debe calcularse el contador de los registros ocupados que pueden ser borrados.( ya leidos )
	FreeRTOS_ioctl(&pdI2C,ioctlOBTAIN_BUS_SEMPH, NULL);

	// Caso 1: Memoria vacia:
	if ( FCB.ff_stat.rcdsFree == FF_MAX_RCDS ) {
		FCB.ff_stat.rcds4del = 0;
		goto quit;
	}

	// Caso 2: Memoria llena:
	if ( FCB.ff_stat.rcdsFree == 0 ) {
		FCB.ff_stat.rcds4del = FCB.ff_stat.RD - FCB.ff_stat.TAIL;
		goto quit;
	}

	// El puntero RD debe estar en un bloque 'leible'
	if ( ( FCB.ff_stat.HEAD > FCB.ff_stat.TAIL) && ( FCB.ff_stat.RD >= FCB.ff_stat.TAIL ) && ( FCB.ff_stat.RD <= FCB.ff_stat.HEAD ) ) {
		FCB.ff_stat.rcds4del = FCB.ff_stat.RD - FCB.ff_stat.TAIL;
		goto quit;
	}

	if ( ( FCB.ff_stat.HEAD < FCB.ff_stat.TAIL) && ( FCB.ff_stat.RD >= FCB.ff_stat.TAIL ) ) {
		FCB.ff_stat.rcds4del = FCB.ff_stat.RD - FCB.ff_stat.TAIL;
		goto quit;
	}

	if ( ( FCB.ff_stat.HEAD < FCB.ff_stat.TAIL ) && ( FCB.ff_stat.RD <= FCB.ff_stat.HEAD ) ) {
		FCB.ff_stat.rcds4del = FF_MAX_RCDS - FCB.ff_stat.TAIL + FCB.ff_stat.RD;
		goto quit;
	}

quit:
	memcpy( pxStatBuffer, &FCB.ff_stat, sizeof(StatBuffer_t));
	FreeRTOS_ioctl(&pdI2C,ioctlRELEASE_BUS_SEMPH, NULL);

}
コード例 #11
0
ファイル: I2C-to-and-from-EEPROM.c プロジェクト: jabv/ZumoBot
static uint8_t prvSetSlaveAddress( Peripheral_Descriptor_t xI2CPort, uint32_t ulByteAddress )
{
uint32_t ulSlaveAddress;

	/* The bottom two bits of the slave address are used as the two most
	significant bits of the byte address within the EEPROM. */
	ulSlaveAddress = ulByteAddress;
	ulSlaveAddress >>= 8UL;
	ulSlaveAddress &= 0x03UL;
	ulSlaveAddress |= i2cEEPROM_SLAVE_ADDRESS;
	FreeRTOS_ioctl( xI2CPort, ioctlSET_I2C_SLAVE_ADDRESS, ( void * ) ulSlaveAddress );

	return ( uint8_t ) ulByteAddress;
}
void vOutputString( const uint8_t * const pucMessage )
{
	/* Obtaining the write mutex prevents strings output using this function
	from corrupting strings output by the command interpreter task (and visa
	versa).  It does not, however, prevent complete strings output using this
	function intermingling with complete strings output from the command
	interpreter as the command interpreter only holds the mutex on an output
	string by output string basis. */
	if( xConsoleUART != NULL )
	{
		if( FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd500ms ) == pdPASS )
		{
			FreeRTOS_write( xConsoleUART, pucMessage, strlen( ( char * ) pucMessage ) );
		}
	}
}
コード例 #13
0
ファイル: sp5KV5_PZ_tkCmd.c プロジェクト: ppeluffo/sp5KV5_PZ
/*------------------------------------------------------------------------------------*/
void tkCmd(void * pvParameters)
{

u08 c;
u08 ticks;
( void ) pvParameters;

	while ( !startTask )
		vTaskDelay( ( TickType_t)( 100 / portTICK_RATE_MS ) );

	cmdlineInit();
	cmdlineSetOutputFunc(pvFreeRTOS_UART1_writeChar);

	cmdlineAddCommand((u08 *)("cls"), cmdClearScreen );
	cmdlineAddCommand((u08 *)("help"), cmdHelpFunction);
	cmdlineAddCommand((u08 *)("reset"), cmdResetFunction);
	cmdlineAddCommand((u08 *)("read"), cmdReadFunction);
	cmdlineAddCommand((u08 *)("write"), cmdWriteFunction);
	cmdlineAddCommand((u08 *)("redial"), cmdRedialFunction);
	cmdlineAddCommand((u08 *)("status"), cmdStatusFunction);


	// Espero la notificacion para arrancar
	vTaskDelay( ( TickType_t)( 500 / portTICK_RATE_MS ) );

	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("starting tkCmd..\r\n\0"));
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	ticks = 1;
	FreeRTOS_ioctl( &pdUART1,ioctlSET_TIMEOUT, &ticks );

	// loop
	for( ;; )
	{
		u_clearWdg(WDG_CMD);

		c = '\0';	// Lo borro para que luego del un CR no resetee siempre el timer.
		// el read se bloquea 50ms. lo que genera la espera.
		while ( FreeRTOS_read( &pdUART1, &c, 1 ) == 1 ) {
			cmdlineInputFunc(c);
		}

		/* run the cmdline execution functions */
		cmdlineMainLoop();
	}
}
コード例 #14
0
ファイル: I2C-to-and-from-EEPROM.c プロジェクト: jabv/ZumoBot
static void prvWritePageToEEPROM( Peripheral_Descriptor_t xI2CPort, uint32_t ulByteAddress )
{
int32_t lReturned;
const uint32_t ulMaxDelay = ( 500UL / portTICK_RATE_MS );

	/* The first byte of the transmitted data contains the least significant
	byte of the EEPROM byte address.  The slave address holds the most
	significant bits of the EEPROM byte address. */
	ucDataBuffer[ 0 ] = prvSetSlaveAddress( xI2CPort, ulByteAddress );

	/* Write the buffer to the EEPROM. */
	lReturned = FreeRTOS_write( xI2CPort, ucDataBuffer, i2cPAGE_SIZE + 1 );
	configASSERT( lReturned == ( i2cPAGE_SIZE + 1 ) );

	/* Wait until the write in complete, then allow it to program.  This is a
	very crude way of doing it - the EEPROM could alternatively be polled. */
	FreeRTOS_ioctl( xI2CPort, ioctlOBTAIN_WRITE_MUTEX, ( void * ) ulMaxDelay );
	vTaskDelay( i2cWRITE_CYCLE_DELAY );
}
コード例 #15
0
ファイル: file_sp5K.c プロジェクト: ppeluffo/sp5KV4
//------------------------------------------------------------------------------------
size_t FF_fwrite( const void *pvBuffer, size_t xSize)
{
	// El archivo es del tipo circular FirstIN-LastOUT.
	// Escribe un registro en la posicion apuntada por el HEAD.
	// El registro que se pasa en pvBuffer es del tipo 'frameData_t' de 38 bytes
	// pero en la memoria voy a escribir de a paginas de 64 bytes.
	// Retorna el nro.de bytes escritos y setea la variable 'errno' del FCB
	// En la posicion 63 grabo un tag con el valor 0xC5 para poder luego
	// determinar si el registro esta ocupado o vacio.

	// TESTING:
	// Memoria vacia: OK
	// Memoria llena: OK
	// Memoria con HEAD(10) > TAIL(4), Free(10) OK
	// Memoria con HEAD(3) < TAIL(8), Free(5) OK
	// Condicion de borde 1: HEAD(15), TAIL(0), Free(1) OK
	// Condicion de borde 2: HEAD(0), TAIL(1), Free(1) OK

u16 val = 0;
size_t xReturn = 0U;
u16 tryes;

	// Lo primero es obtener el semaforo del I2C
	FreeRTOS_ioctl(&pdI2C,ioctlOBTAIN_BUS_SEMPH, NULL);
	FCB.ff_stat.errno = pdFF_ERRNO_NONE;

	// Si la memoria esta llena no puedo escribir: salgo
	if ( FCB.ff_stat.rcdsFree == 0 ) {
		FCB.ff_stat.errno = pdFF_ERRNO_MEMFULL;
		goto quit;
	}

	// inicializo la estructura lineal temporal en el FCB para copiar ahi los datos y
	// calcular el checksum antes de grabarlo en memoria.
	memset( FCB.ff_buffer,0, sizeof(FCB.ff_buffer) );
	// copio los datos recibidos del frame al buffer ( 0..(xSize-1))
	memcpy ( FCB.ff_buffer, pvBuffer, xSize );
	// Calculo y grabo el checksum a continuacion del frame (en la pos.xSize)
	// El checksum es solo del dataFrame por eso paso dicho size.
	FCB.ff_buffer[xSize] = pv_memChecksum(FCB.ff_buffer, xSize );
	// Grabo el tag para indicar que el registro esta escrito.
	FCB.ff_buffer[sizeof(FCB.ff_buffer) - 1] = FF_WRTAG;

	// EE WRITE:
	// Luego indicamos el periferico i2c en el cual queremos leer
	val = EE_ADDR;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_DEVADDRESS, &val);
	// Luego indicamos la direccion a escribir del dispositivo: largo ( en la ee son 2 bytes )
	val = 2;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESSLENGTH, &val);
	// y direccion interna en la EE.(comienzo del registro / frontera)
	val = FF_ADDR_START + FCB.ff_stat.HEAD * FF_RECD_SIZE;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);

	// Por ultimo escribo la memoria. Escribo un pagina entera, 64 bytes.
	// Reintento hasta 3 veces.
	for ( tryes = 0; tryes < 3; tryes++ ) {
		// Write
		xReturn = FreeRTOS_write(&pdI2C, &FCB.ff_buffer, FF_RECD_SIZE);
		taskYIELD();
		// Verify
		FreeRTOS_read(&pdI2C, &FCB.check_buffer, FF_RECD_SIZE);

		if ( memcmp (&FCB.check_buffer, &FCB.ff_buffer, FF_RECD_SIZE) == 0 )
			break;

		if  ( tryes == 3 ) {
			snprintf_P( debug_printfBuff,sizeof(debug_printfBuff),PSTR("FS WR ERR: [%d]\r\n\0"), val);
			FreeRTOS_write( &pdUART1, debug_printfBuff, sizeof(debug_printfBuff) );
			FCB.ff_stat.errno = pdFF_ERRNO_MEMWR;
			xReturn = 0U;
			goto quit;
		}
	}

	if (xReturn != FF_RECD_SIZE ) {
		// Errores de escritura ?
		FCB.ff_stat.errno = pdFF_ERRNO_MEMWR;
		xReturn = 0U;
		goto quit;
	} else {
		xReturn = xSize;
		// Avanzo el puntero de WR en modo circular
		FCB.ff_stat.HEAD = (++FCB.ff_stat.HEAD == FF_MAX_RCDS) ?  0 : FCB.ff_stat.HEAD;
		FCB.ff_stat.rcdsFree--;
	}

quit:
	// libero los semaforos
	FreeRTOS_ioctl(&pdI2C,ioctlRELEASE_BUS_SEMPH, NULL);
	return(xReturn);

}
コード例 #16
0
ファイル: file_sp5K.c プロジェクト: ppeluffo/sp5KV4
//------------------------------------------------------------------------------------
size_t FF_fread( void *pvBuffer, size_t xSize)
{
	// Lee un registro apuntado por RD.
	// Retorna la cantidad de bytes leidos.
	// Las condiciones de lectura son:
	// - la memoria debe tener al menos algun dato
	// - el puntero RD debe apuntar dentro del bloque 'leible'
	//
	// Lee un registro ( como string ) y lo copia al espacio de memoria apuntado
	// *pvBuffer. El puntero es void y entonces debemos pasar el tamaño de la estructura
	// a la que apunta.
	// En caso que tenga problemas para leer o de checksum, debo continuar e indicar
	// el error.

u16 val = 0;
size_t xReturn = 0U;
u08 rdCheckSum;

	// Lo primero es obtener el semaforo del I2C
//	a = xTaskGetTickCount();
	FreeRTOS_ioctl(&pdI2C,ioctlOBTAIN_BUS_SEMPH, NULL);
//	b = xTaskGetTickCount();
	FCB.ff_stat.errno = pdFF_ERRNO_NONE;

	// Si la memoria esta vacia salgo ( todos los registros libres )
	if ( FCB.ff_stat.rcdsFree == FF_MAX_RCDS ) {
		FCB.ff_stat.errno = pdFF_ERRNO_MEMEMPTY;
		goto quit;
	}

	// Si el registro no corresponde al bloque 'leible', salgo
	if ( ( FCB.ff_stat.HEAD > FCB.ff_stat.TAIL) && ( ( FCB.ff_stat.RD >= FCB.ff_stat.HEAD ) || ( FCB.ff_stat.RD < FCB.ff_stat.TAIL ) ) ) {
		FCB.ff_stat.errno = pdFF_ERRNO_MEMEMPTY;
		goto quit;
	}
	if ( ( FCB.ff_stat.HEAD < FCB.ff_stat.TAIL) && ( ( FCB.ff_stat.RD >= FCB.ff_stat.HEAD ) && ( FCB.ff_stat.RD < FCB.ff_stat.TAIL ) ) ) {
		FCB.ff_stat.errno = pdFF_ERRNO_MEMEMPTY;
		goto quit;
	}

	// Aqui es que estoy dentro de un bloque 'leible'

	// inicializo la estructura lineal temporal en el FCB.
	memset( FCB.ff_buffer,0, sizeof(FCB.ff_buffer) );
	// EE READ:
	// Indicamos el periferico i2c al cual quiero acceder
	val = EE_ADDR;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_DEVADDRESS, &val);
	// Luego indicamos la direccion desde donde leer del dispositivo: largo ( en la ee son 2 bytes )
	val = 2;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESSLENGTH, &val);
	// y direccion interna en la EE.(comienzo del registro / frontera)
	val = FF_ADDR_START + FCB.ff_stat.RD * FF_RECD_SIZE;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	// Por ultimo leo la memoria: un pagina entera, (recd) 64 bytes.
//	c = xTaskGetTickCount();
	xReturn = FreeRTOS_read(&pdI2C, &FCB.ff_buffer, FF_RECD_SIZE);
//	d = xTaskGetTickCount();
	// Avanzo el puntero de RD en modo circular siempre !!
	FCB.ff_stat.RD = (++FCB.ff_stat.RD == FF_MAX_RCDS) ?  0 : FCB.ff_stat.RD;

	// Copio los datos a la estructura de salida.: aun no se si estan correctos
	memcpy( pvBuffer, &FCB.ff_buffer, xSize );

	// Errores de lectura ?
	// Solo indico los errores, pero igual devuelvo el recd. para no trancarme
	if (xReturn != FF_RECD_SIZE ) {
		FCB.ff_stat.errno = pdFF_ERRNO_MEMRD;
		xReturn = 0U;
		goto quit;
	}

	// Verifico los datos leidos ( checksum )
	// El checksum es solo del dataFrame por eso paso dicho size.
	rdCheckSum = pv_memChecksum(FCB.ff_buffer, xSize );
//	e = xTaskGetTickCount();
	if ( rdCheckSum != FCB.ff_buffer[xSize] ) {
		FCB.ff_stat.errno = pdFF_ERRNO_RDCKS;
		xReturn = 0U;
		goto quit;
	}

	// Vemos si la ultima posicion tiene el tag de ocupado.
	if ( ( FCB.ff_buffer[sizeof(FCB.ff_buffer) - 1] )  != FF_WRTAG ) {
		FCB.ff_stat.errno = pdFF_ERRNO_RDNOTAG;
		xReturn = 0U;
		goto quit;
	}

	// Datos leidos correctamente
	xReturn = xSize;

quit:
	// libero los semaforos
	FreeRTOS_ioctl(&pdI2C,ioctlRELEASE_BUS_SEMPH, NULL);

//	snprintf_P( debug_printfBuff,sizeof(debug_printfBuff),PSTR("DEBUG RD:[%06lu][%06lu][%06lu][%06lu][%06lu]\r\n\0"),a,b,c,d,e  );
//	FreeRTOS_write( &pdUART1, debug_printfBuff, sizeof(debug_printfBuff) );

	return(xReturn);
}
コード例 #17
0
ファイル: mcp_sp5K.c プロジェクト: ppeluffo/sp5KV4_8CH
//------------------------------------------------------------------------------------
void pvMCP_init_MCP1(u08 modo)
{
	// Inicializo el MCP23018 de la placa analogica
	// El modo 0 indica uso normal, el modo 1 uso por reconfiguracion por lo que el log es por D_DEBUG

u08 data;
size_t xReturn = 0U;
u16 val = 0;
u08 xBytes = 0;

	// Lo primero es obtener el semaforo
	FreeRTOS_ioctl(&pdI2C,ioctlOBTAIN_BUS_SEMPH, NULL);
	val = MCP1_ADDR;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_DEVADDRESS, &val);

	// IOCON
	val = MCP1_IOCON;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 0x63; // 0110 0011
	//                      1->INTCC:Read INTCAP clear interrupt
	//                     1-->INTPOL: INT out pin active high
	//                    0--->ORDR: Active driver output. INTPOL set the polarity
	//                   0---->X
	//                 0----->X
	//                1------>SEQOP: sequential disabled. Address ptr does not increment
	//               1------->MIRROR: INT pins are ored
	//              0-------->BANK: registers are in the same bank, address sequential
	xBytes = sizeof(data);
	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);
	//
	// DIRECCION
	// 0->output
	// 1->input
	val = MCP1_IODIRA;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 0x80; // 1000 0000 ( GPA0..GPA6: outputs, GPA7 input )
	xBytes = sizeof(data);
	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);

	val = MCP1_IODIRB;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 0x64; // 0110 0100
	xBytes = sizeof(data);
	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);
	//
	// PULL-UPS
	// 0->disabled
	// 1->enabled
	// Los dejo en 0 para ahorrar ma.
	val = MCP1_GPPUA;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 0x00; // 1111 1111
	xBytes = sizeof(data);
	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);

	val = MCP1_GPPUB;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 0xF0; // 0000 1111
	xBytes = sizeof(data);
	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);
	//
	// Valores iniciales de las salidas en 0
	val = MCP1_OLATA;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 0x00;
	xBytes = sizeof(data);
	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);

	val = MCP1_OLATB;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 0x00;
	xBytes = sizeof(data);
	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);
	//
	// GPINTEN: inputs interrupt on change.
	// Habilito que DIN0/1 generen una interrupcion on-change.
	// El portA no genera interrupciones
//	val = MCP1_GPINTENA;
//	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
//	data = 0;
//	xBytes = sizeof(data);
//	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);
	//data = 0x60; // 0110 0000
	//data |= ( BV(MCP1_GPIO_DIN0) | BV(MCP1_GPIO_DIN1) );
//	val = MCP1_GPINTENB;
//	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
//	data = 0;
//	xBytes = sizeof(data);
//	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);
	//
	// DEFVALB: valores por defecto para comparar e interrumpir
	//data = 0;
	//status = pvMCP_write( MCP1_DEFVALB, MCP_ADDR2, 1, &data);

	// INTCON: controlo como comparo para generar la interrupcion.
	// Con 1, comparo contra el valor fijado en DEFVAL
	// Con 0 vs. su valor anterior.
//	val = MCP1_INTCONB;
//	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	//data |= ( BV(MCP1_GPIO_DIN0) | BV(MCP1_GPIO_DIN1) );
//	data = 0;
//	xBytes = sizeof(data);
//	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);
	// Borro interrupciones pendientes
//	val = MCP1_INTCAPB;
//	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
//	data = 0;
//	xBytes = sizeof(data);
//	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);

	// libero el semaforo.
	FreeRTOS_ioctl(&pdI2C,ioctlRELEASE_BUS_SEMPH, NULL);

	if ( modo == 0 ) {
		FreeRTOS_write( &pdUART1, "MCP1 init OK\r\n\0", sizeof("MCP1 init OK\r\n\0") );
	} else {
		snprintf_P( debug_printfBuff,sizeof(debug_printfBuff),PSTR("**DEBUG:: MCP1 init !!\r\n\0"));
		u_debugPrint(D_DEBUG, debug_printfBuff, sizeof(debug_printfBuff) );
	}
}
コード例 #18
0
static void prvUARTRxOperationModesTestTask( void *pvParameters )
{
portBASE_TYPE xTestLoops, xReturned;
uint8_t *pcRxBuffer;
size_t xRxedChars, xStringLength, xReceivedCharacters;
const size_t xRxBufferSize = strlen( ( char * ) pcTestMessage3 ) + ( size_t ) 1;
portTickType xTimeBefore, xTimeAfter;

	( void ) pvParameters;

	/* Create a buffer that is large enough to receive the longest of the
	strings. */
	pcRxBuffer = pvPortMalloc( xRxBufferSize );
	prvCheckTestResult( ( pcRxBuffer != NULL ), __LINE__ );

	/* At this point the Tx task should not have executed, and therefore the
	UART should not have been opened. */
	prvCheckTestResult( ( xTestUART == NULL ), __LINE__);

	/*************************************************************************
	 * Test 1.  Polling Tx and polling Rx.
	 *************************************************************************/

	/* This task has the higher priority so will run before the Tx task.
	Suspend this task to allow the lower priority Tx task to run.  The Tx task
	will unsuspend (resume) this task when it is ready. */
	vTaskSuspend( NULL );

	/* The Tx task should have opened the UART before unsuspending this
	task. */
	prvCheckTestResult( ( xTestUART != NULL ), __LINE__ );

	/* Clear any characters that may already be in the UART buffers/FIFO. */
	while( FreeRTOS_read( xTestUART, &( pcRxBuffer[ 0 ] ), sizeof( uint8_t ) ) != 0 );

	/* The UART has been opened, but not yet configured.  It will
	use the default configuration, which is to poll rather than use interrupts,
	and to use 115200 baud.  Try reading out a message a few times to check the
	default functionality.  The task must block when no characters are
	available otherwise the lower priority Tx task will be starved of CPU
	time. */
	xStringLength = strlen( ( char * ) pcTestMessage1 );
	for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ )
	{
		/* Clear the Rx buffer, then poll for characters one at a time, placing
		them in the Rx buffer. */
		memset( pcRxBuffer, 0x00, xRxBufferSize );
		xRxedChars = 0;
		while( xRxedChars < xStringLength )
		{
			xReturned = FreeRTOS_read( xTestUART, &( pcRxBuffer[ xRxedChars ] ), sizeof( uint8_t ) );

			/* It should only be possible to have received either 1 of zero
			bytes. */
			prvCheckTestResult( ( ( xReturned == 1 ) || ( xReturned == 0 ) ), __LINE__ );

			if( xReturned == 0 )
			{
				/* No characters were returned, so allow the Tx task to
				execute. */
				vTaskDelay( ( portTickType ) uartstEXTREMELY_SHORT_BLOCK_TIME );
			}
			else
			{
				xRxedChars++;
			}
		}

		/* The whole string should now have been received.  Is it correct? */
		xReturned = strcmp( ( char * ) pcRxBuffer, ( char * ) pcTestMessage1 );
		prvCheckTestResult( ( xReturned == 0 ), __LINE__ );
	}


	for( ;; )
	{
		/* Suspend again to wait for the Tx task to be ready for test 2. */
		vTaskSuspend( NULL );


		/*************************************************************************
		 * Test 2.  Interrupt driven, zero copy Tx, circular buffer Rx.
		 *************************************************************************/

		/* The Tx task will now have configured the UART to use interrupts and
		a circular buffer for receiving.  The default configuration will have
		an infinite block time.  Set this down, but leave the block time long
		enough for the entire string to be received. */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_RX_TIMEOUT, uartstVERY_LONG_BLOCK_TIME );
		prvCheckTestResult( xReturned, __LINE__ );

		xStringLength = strlen( ( char * ) pcTestMessage2 );
		for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ )
		{
			/* Clear the Rx buffer. */
			memset( pcRxBuffer, 0x00, xRxBufferSize );

			/* Read as many characters as possible in one go, up to the total
			number of expected characters in the string being received. */
			xReturned = FreeRTOS_read( xTestUART, pcRxBuffer, xStringLength );

			prvCheckTestResult( ( xReturned == ( portBASE_TYPE ) xStringLength ), __LINE__ );

			/* The whole string should now have been received.  Is it
			correct? */
			xReturned = strcmp( ( char * ) pcRxBuffer, ( char * ) pcTestMessage2 );
			prvCheckTestResult( ( xReturned == 0 ), __LINE__ );
		}

		/* This time, try receiving the characters one at a time. */
		for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ )
		{
			/* Clear the Rx buffer. */
			memset( pcRxBuffer, 0x00, xRxBufferSize );
			xReceivedCharacters = 0;

			/* Read one character at a time until the total number of expected
			characters in the string have been received. */
			while( xReceivedCharacters < xStringLength )
			{
				xReturned = FreeRTOS_read( xTestUART, &( pcRxBuffer[ xReceivedCharacters ] ), sizeof( uint8_t ) );
				prvCheckTestResult( ( xReturned == ( portBASE_TYPE ) sizeof( uint8_t ) ), __LINE__ );
				xReceivedCharacters += sizeof( uint8_t );

				/* Make sure not to get stuck here. */
				if( xReturned == 0 )
				{
					break;
				}
			}

			/* The whole string should now have been received.  Is it
			correct? */
			xReturned = strcmp( ( char * ) pcRxBuffer, ( char * ) pcTestMessage2 );
			prvCheckTestResult( ( xReturned == 0 ), __LINE__ );
		}

		/* Next, shorten the block time and try receiving more characters.  At
		this time, the Tx task will not be transmitting, so the read commands
		should	return after the configured block time has expired.

		First change the block time itself. */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_RX_TIMEOUT, uartstVERY_SHORT_TX_BLOCK_TIME );
		prvCheckTestResult( xReturned, __LINE__ );

		/* Attempt a read, taking note of the time both before and after the
		call to read(). */
		memset( pcRxBuffer, 0x00, xRxBufferSize );
		xTimeBefore = xTaskGetTickCount();
		xReturned = FreeRTOS_read( xTestUART, pcRxBuffer, xStringLength );
		prvCheckTestResult( ( ( xTaskGetTickCount() - xTimeBefore ) <= ( ( portTickType ) uartstVERY_SHORT_TX_BLOCK_TIME + uartstTIME_MARGIN ) ), __LINE__ );

		/* Nothing should have been returned. */
		prvCheckTestResult( ( xReturned == 0 ), __LINE__ );

		/* Repeat, using a different block time. */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_RX_TIMEOUT, ( void * ) ( ( portTickType ) uartstVERY_SHORT_TX_BLOCK_TIME * 2U ) );
		prvCheckTestResult( xReturned, __LINE__ );
		xTimeBefore = xTaskGetTickCount();
		xReturned = FreeRTOS_read( xTestUART, pcRxBuffer, xStringLength );
		prvCheckTestResult( ( ( xTaskGetTickCount() - xTimeBefore ) <= ( ( ( portTickType ) uartstVERY_SHORT_TX_BLOCK_TIME * 2U ) + uartstTIME_MARGIN ) ), __LINE__ );
		prvCheckTestResult( ( xReturned == 0 ), __LINE__ );

		/* Suspend again to wait for the Tx task to be ready for test 3. */
		vTaskSuspend( NULL );




		/*************************************************************************
		 * Test 3.  Character queue Rx/Tx
		 *************************************************************************/

		/* The Tx task will have set both the Rx and Tx models to use a
		character by character queue.  Set the Rx block time back up so it is
		long enough to read the entire string. */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_RX_TIMEOUT, uartstVERY_LONG_BLOCK_TIME );
		prvCheckTestResult( xReturned, __LINE__ );

		xStringLength = strlen( ( char * ) pcTestMessage3 );
		for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ )
		{
			/* Clear the Rx buffer. */
			memset( pcRxBuffer, 0x00, xRxBufferSize );

			/* Read as many characters as possible in one go, up to the total
			number of expected characters in the string being received. */
			xReturned = FreeRTOS_read( xTestUART, pcRxBuffer, xStringLength );

			prvCheckTestResult( ( xReturned == ( portBASE_TYPE ) xStringLength ), __LINE__ );

			/* The whole string should now have been received.  Is it correct? */
			xReturned = strcmp( ( char * ) pcRxBuffer, ( char * ) pcTestMessage3 );
			prvCheckTestResult( ( xReturned == 0 ), __LINE__ );
		}




		/*************************************************************************
		 * Test 4.  Character queue Rx/Tx block times
		 *************************************************************************/


		/* Reading characters from an Rx queue has a block time.  This is the
		total time spent trying to read characters from the Rx queue if the
		queue is already empty.  If the task finds the queue empty then it is
		held in the	Blocked state until data becomes available, so no CPU time
		is wasted polling.  If the block time expires before all the characters
		have been read from the queue then the FreeRTOS_read() call returns the
		number of characters that were successfully read (as normal). */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_RX_TIMEOUT, uartstVERY_SHORT_RX_BLOCK_TIME );
		prvCheckTestResult( xReturned, __LINE__ );

		for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ )
		{
			/* Try reading a string again, still using the character by
			character queue, but this time using a very short block time so not
			all the	characters will make it from the queue. */
			xTimeBefore = xTaskGetTickCount();
			xReturned = FreeRTOS_read( xTestUART, pcRxBuffer, xStringLength );
			xTimeAfter = xTaskGetTickCount();

			prvCheckTestResult( ( ( xReturned != 0 ) && ( xReturned != ( portBASE_TYPE ) xStringLength ) ), __LINE__ );
			prvCheckTestResult( ( ( xTimeAfter - xTimeBefore ) < ( ( portTickType ) uartstVERY_SHORT_RX_BLOCK_TIME + ( portTickType ) 2 ) ), __LINE__ );
		}

		/* Clear any characters that remain UART buffers/FIFO before
		continuing. */
		while( FreeRTOS_read( xTestUART, &( pcRxBuffer[ 0 ] ), sizeof( uint8_t ) ) != 0 );
		while( FreeRTOS_read( xTestUART, &( pcRxBuffer[ 0 ] ), sizeof( uint8_t ) ) != 0 );
		while( FreeRTOS_read( xTestUART, &( pcRxBuffer[ 0 ] ), sizeof( uint8_t ) ) != 0 );
	}
}
コード例 #19
0
static void prvUARTTxOperationModesTestTask( void *pvParameters )
{
portBASE_TYPE xReturned, xTestLoops;
portTickType xTimeBefore, xTimeAfter;

	( void ) pvParameters;

	/* Open the UART port used for console input.  The second parameter
	(ulFlags) is not used in this case. */
	xTestUART = FreeRTOS_open( boardCOMMAND_CONSOLE_UART, ( uint32_t ) uarttstPARAMTER_NOT_USED );
	prvCheckTestResult( ( xTestUART != NULL ), __LINE__ );

	/*************************************************************************
	 * Test 1.  Polling Tx and polling Rx.
	 *************************************************************************/

	/* When this task starts, the Rx task will already have started as the
	Rx task has the higher priority.  The Rx task should have placed itself
	into the Suspended state to wait for the Tx task to be ready. */
	xReturned = xTaskIsTaskSuspended( xRxTaskHandle );
	prvCheckTestResult( xReturned, __LINE__ );

	/* Resume the Rx task.  It will start polling for received characters,
	but put itself in the Blocked state when no characters are present to
	ensure this task does not get starved of CPU time. */
	vTaskResume( xRxTaskHandle );

	/* The UART has been opened, but not yet configured.  It will
	use the default configuration, which is to poll rather than use interrupts,
	and to use 115200 baud.  Try writing out a message a few times to check the
	default functionality. */
	for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ )
	{
		xReturned = FreeRTOS_write( xTestUART, pcTestMessage1, strlen( ( char * ) pcTestMessage1 ) );
		prvCheckTestResult( ( xReturned == ( portBASE_TYPE ) strlen( ( char * ) pcTestMessage1 ) ), __LINE__ );
	}


	for( ;; )
	{
		/* Allow the Rx task to complete previous test. */
		while( xTaskIsTaskSuspended( xRxTaskHandle ) != pdTRUE )
		{
			vTaskDelay( ( portTickType ) uartstVERY_SHORT_TX_BLOCK_TIME );
		}



		/**********************************************************************
		 * Test 2.  Interrupt driven, zero copy Tx, ring buffer Rx.
		 **********************************************************************/

		/* Now the UART configuration is going to change.  First set the baud
		rate to 115200 - which it is already as that is the default so this is
		just for test purposes.  Setting it to any other value would require
		the terminal baud rate to change too.  As the UART is still in polled
		mode there is no need to wait for it to be free. */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_SPEED, ( void * ) boardDEFAULT_UART_BAUD );
		prvCheckTestResult( xReturned, __LINE__ );

		/* Next, change the Tx usage model from straight polled mode to use
		zero copy buffers with interrupts.  In this mode, the UART will
		transmit characters directly from the buffer passed to the
		FreeRTOS_write() function.  This	call will cause UART interrupts to
		be enabled and the interrupt priority to be set to the minimum
		possible. */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlUSE_ZERO_COPY_TX, uarttstPARAMTER_NOT_USED );
		prvCheckTestResult( xReturned, __LINE__ );

		/* Change the Rx usage model from polled to instead use a ring buffer.
		The	Rx driver created the circular buffer itself.  This call will cause
		UART interrupts to be enabled and the interrupt priority to be set to
		the	minimum possible. */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlUSE_CIRCULAR_BUFFER_RX, uartstCIRCULAR_BUFFER_SIZE );
		prvCheckTestResult( xReturned, __LINE__ );

		/* By default, the UART interrupt priority will have been set to the
		lowest possible.  It must be kept at or below
		configMAX_LIBRARY_INTERRUPT_PRIORITY, but can be raised above its
		default priority. */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_INTERRUPT_PRIORITY, ( void * ) configMAX_LIBRARY_INTERRUPT_PRIORITY );
		prvCheckTestResult( xReturned, __LINE__ );

		/* Zero copy transmit requires a task to obtain exclusive access to the
		peripheral before attempting a FreeRTOS_write() call.  A mutex is by
		the FreeRTOS+IO code to grant access.  Attempting a write here, without
		first obtaining the mutex, should result in no bytes being
		transmitted.  Only attempt this if configASSERT() is not defined,
		otherwise attempting a write without first holding the mutex will cause
		an assertion. */
		/* _RB_ Test this path. */
		#ifndef configASSERT
		{
			xReturned = FreeRTOS_write( xTestUART, pcTestMessage2, strlen( ( char * ) pcTestMessage2 ) );
			prvCheckTestResult( ( xReturned == 0U ), __LINE__ );
		}
		#endif /* configASSERT(). */

		/* Unsuspend the Rx task ready for this test. */
		vTaskResume( xRxTaskHandle );

		for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ )
		{
			/* Try writing a string again, this time using a zero copy
			interrupt driven mode.

			First obtain exclusive write access to the UART.  Obtaining write
			access not only ensure mutually exclusive access, it also ensures
			any previous transmit activity has been completed (important when
			using zero copy buffers to ensure a buffer being that is still
			being transmitted is not overwritten).  This task will wait
			indefinitely in the Blocked state while waiting for UART access to
			be granted,	so no CPU time is wasted polling. */
			xReturned = FreeRTOS_ioctl( xTestUART, ioctlOBTAIN_WRITE_MUTEX, ( void * ) uartstVERY_LONG_BLOCK_TIME );
			prvCheckTestResult( xReturned, __LINE__ );

			/* Write the string.  The write access mutex will be returned
			by the UART ISR once the entire string has been transmitted. */
			xReturned = FreeRTOS_write( xTestUART, pcTestMessage2, strlen( ( char * ) pcTestMessage2 ) );
			prvCheckTestResult( ( xReturned == ( portBASE_TYPE ) strlen( ( char * ) pcTestMessage2 ) ), __LINE__ );
		}

		/* Send the same string another uartstNUM_TEST_TRANSACTIONS times.  This
		time the Rx task will receive the characters one by one. */
		for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ )
		{
			xReturned = FreeRTOS_ioctl( xTestUART, ioctlOBTAIN_WRITE_MUTEX, ( void * ) uartstVERY_LONG_BLOCK_TIME );
			prvCheckTestResult( xReturned, __LINE__ );

			xReturned = FreeRTOS_write( xTestUART, pcTestMessage2, strlen( ( char * ) pcTestMessage2 ) );
			prvCheckTestResult( ( xReturned == ( portBASE_TYPE ) strlen( ( char * ) pcTestMessage2 ) ), __LINE__ );
		}

		/* Take the write mutex again.  This will only be obtainable when the
		UART has completed transmitting the last string sent to it in the loop
		above.	 Normally the write mutex is released again by the UART ISR
		when it has	completed transmitting a string sent to it by a call to
		FreeRTOS_write().  In this case it is not going to be released, as it
		will be deleted when the UART mode is switched in the next part of
		this test anyway. */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlOBTAIN_WRITE_MUTEX, ( void * ) uartstVERY_LONG_BLOCK_TIME );
		prvCheckTestResult( xReturned, __LINE__ );

		/* Allow the Rx task to complete test 2. */
		while( xTaskIsTaskSuspended( xRxTaskHandle ) != pdTRUE )
		{
			vTaskDelay( ( portTickType ) uartstVERY_SHORT_TX_BLOCK_TIME );
		}




		/*************************************************************************
		 * Test 3.  Character queue Rx/Tx
		 *************************************************************************/

		/* Change the Tx usage model from zero copy with interrupts to use a
		character by character queue.  Real applications should not change
		interrupt usage modes in this manner!  It is done here purely for test
		purposes.  Character by character Tx queues are a convenient and easy
		transmit method.  They can, however, be inefficient if a lot of data is
		being transmitted quickly.  This command will always result in UART
		interrupts becoming enabled, with the interrupt priority set to the
		minimum possible. */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlUSE_CHARACTER_QUEUE_TX, uartstQUEUE_LENGTH );
		prvCheckTestResult( xReturned, __LINE__ );

		/* Set a maximum transmit block time to ensure tasks that perform a
		FreeRTOS_write() on a peripheral that is using an interrupt driven
		character queue transfer mode do not block indefinitely if their
		requested number of characters cannot be written to the queue. */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_TX_TIMEOUT, uartstVERY_LONG_BLOCK_TIME );
		prvCheckTestResult( xReturned, __LINE__ );

		/* Likewise, change the Rx usage model from circular buffer, to use a
		character by character queue.  Character by character Rx queue are a
		convenient receive method.  They can, however, be inefficient if a lot
		of data is being received quickly.  This command will always result in
		UART interrupts becoming enabled, with the interrupt priority set to
		the minimum	possible.  The Rx block time was set when the reception was
		set to use the circular buffer transfer mode. */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlUSE_CHARACTER_QUEUE_RX, uartstQUEUE_LENGTH );
		prvCheckTestResult( xReturned, __LINE__ );

		/* By default, the UART interrupt priority will have been reset to the
		lowest possible when the usage mode was changed.  It must be at or kept
		below configMAX_LIBRARY_INTERRUPT_PRIORITY, but can be raised above its
		default	priority again. */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_INTERRUPT_PRIORITY, ( void * ) configMAX_LIBRARY_INTERRUPT_PRIORITY );
		prvCheckTestResult( xReturned, __LINE__ );

		/* Unsuspend the Rx task ready for this test. */
		vTaskResume( xRxTaskHandle );

		for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ )
		{
			/* Try writing a string again, this time using a character by
			character Tx queue, still with interrupts enabled. */
			xReturned = FreeRTOS_write( xTestUART, pcTestMessage3, strlen( ( char * ) pcTestMessage3 ) );
			prvCheckTestResult( ( xReturned == ( portBASE_TYPE ) strlen( ( char * ) pcTestMessage3 ) ), __LINE__ );
		}

		/*************************************************************************
		 * Test 4.  Character queue Rx/Tx block times
		 *************************************************************************/

		/* Writing characters to a Tx queue has a block time.  This is the
		total time spent trying to write the characters to the Tx queue if the
		queue is already full.  If the task finds the queue full then it is
		held in the	Blocked state until space becomes available, so no CPU time
		is wasted polling.  If the block time expires before all the characters
		have been written to the queue then the FreeRTOS_write() call returns
		the number of characters that were successfully sent (as normal). */
		xReturned = FreeRTOS_ioctl( xTestUART, ioctlSET_TX_TIMEOUT, uartstVERY_SHORT_TX_BLOCK_TIME );
		prvCheckTestResult( xReturned, __LINE__ );

		for( xTestLoops = 0; xTestLoops < uartstNUM_TEST_TRANSACTIONS; xTestLoops++ )
		{
			/* Try writing a string again, still using the character by
			character queue, but this time using a very short block time so not
			all the	characters will make it into the queue. */
			xTimeBefore = xTaskGetTickCount();
			xReturned = FreeRTOS_write( xTestUART, pcTestMessage4, strlen( ( char * ) pcTestMessage4 ) );
			xTimeAfter = xTaskGetTickCount();

			prvCheckTestResult( ( xReturned != ( portBASE_TYPE ) strlen( ( char * ) pcTestMessage4 ) ), __LINE__ );
			prvCheckTestResult( ( ( xTimeAfter - xTimeBefore ) < ( ( portTickType ) uartstVERY_SHORT_TX_BLOCK_TIME + ( portTickType ) 2 ) ), __LINE__ );
			FreeRTOS_write( xTestUART, "\r\n", strlen( ( char * ) "\r\n" ) );
		}
	}
}
コード例 #20
0
ファイル: file_sp5K.c プロジェクト: ppeluffo/sp5KV4
//------------------------------------------------------------------------------------
s08 FF_rewind(void)
{
	// Borra el archivo y lo lleva a su condicion inicial.
	// Inicializa la memoria. Como lleva bastante tiempo, tenemos problemas con el
	// watchdog. Por esto desde donde la invocamos debemos desactivarlo y esta
	// funcion SOLO debe usarse desde CMD.

u16 val = 0;
u16 tryes;
u16 xPos;

	wdt_reset();

	// Lo primero es obtener el semaforo del I2C
	FreeRTOS_ioctl(&pdI2C,ioctlOBTAIN_BUS_SEMPH, NULL);

	// inicializo la estructura lineal temporal del FCB.
	memset( FCB.ff_buffer,0, sizeof(FCB.ff_buffer) );

	// EE WRITE:
	// Luego indicamos el periferico i2c en el cual queremos leer
	val = EE_ADDR;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_DEVADDRESS, &val);
	// Luego indicamos la direccion a escribir del dispositivo: largo ( en la ee son 2 bytes )
	val = 2;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESSLENGTH, &val);
	// Ciclo de borrado
	for ( xPos = 0; xPos < FF_MAX_RCDS; xPos++) {
		// direccion interna en la EE.(comienzo del registro / frontera)
		val = FF_ADDR_START + xPos * FF_RECD_SIZE;
		FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);

		for ( tryes = 0; tryes < 3; tryes++ ) {
			// Borro: escribo un pagina entera, 64 bytes con los '\0'
			FreeRTOS_write(&pdI2C, &FCB.ff_buffer, FF_RECD_SIZE);
			taskYIELD();
			// Leo y verifico
			FreeRTOS_read(&pdI2C, &FCB.check_buffer, FF_RECD_SIZE);
			if ( memcmp (&FCB.check_buffer, &FCB.ff_buffer, FF_RECD_SIZE) == 0 )
				break;
			if  ( tryes == 3 ) {
				snprintf_P( debug_printfBuff,sizeof(debug_printfBuff),PSTR("FFrew ERR: %d,%d\r\n\0"),xPos, val);
				FreeRTOS_write( &pdUART1, debug_printfBuff, sizeof(debug_printfBuff) );
			}

		}
		// Imprimo realimentacion c/32 recs.
		if ( (xPos % 32) == 0 ) {
			FreeRTOS_write( &pdUART1, ".\0", sizeof(".\0") );
		}

		// Para no salir por wdg reset
		if ( (xPos % 64) == 0 ) {
			wdt_reset();
		}
	}

	FreeRTOS_write( &pdUART1, "\r\n\0", sizeof("\r\n\0") );
	FreeRTOS_ioctl(&pdI2C,ioctlRELEASE_BUS_SEMPH, NULL);
	// RESET
	u_reset();

}
コード例 #21
0
ファイル: mcp_sp5K.c プロジェクト: ppeluffo/sp5KV4_8CH
// FUNCIONES PRIVADAS
//------------------------------------------------------------------------------------
static void pvMCP_init_MCP0(void)
{
	// inicializa el MCP23008 de la placa de logica
	// NO CONTROLO ERRORES.

u08 data;
size_t xReturn = 0U;
u16 val = 0;
u08 xBytes = 0;

	// Lo primero es obtener el semaforo
	FreeRTOS_ioctl(&pdI2C,ioctlOBTAIN_BUS_SEMPH, NULL);
	// Luego indicamos el periferico i2c en el cual queremos leer
	val = MCP0_ADDR;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_DEVADDRESS, &val);
	// Luego indicamos en que posicion del periferico queremos leer: largo
	val = 1;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESSLENGTH, &val);
	// y direccion

	// MCP0_IODIR: inputs(1)/outputs(0)
	val = MCP0_IODIR;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 0;
	data |= ( BV(MCP0_GPIO_IGPRSDCD) | BV(MCP0_GPIO_IGPRSRI) );
	xBytes = sizeof(data);
	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);

	// MCP0_IPOL: polaridad normal
	val = MCP0_IPOL;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 0;
	xBytes = sizeof(data);
	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);

	// MCP0_GPINTEN: inputs interrupt on change.
	val = MCP0_GPINTEN;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 0;
	//data |= ( BV(MCP_GPIO_IGPRSDCD) | BV(MCP_GPIO_IGPRSRI) | BV(MCP_GPIO_ITERMPWRSW) );
	data |=  BV(MCP0_GPIO_IGPRSDCD);
	xBytes = sizeof(data);
	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);

	// MCP0_INTCON: Compara contra su valor anterior
	val = MCP0_INTCON;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 0;
	xBytes = sizeof(data);
	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);

	// MCP0_IOCON: INT active H
	val = MCP0_IOCON;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 2;
	xBytes = sizeof(data);
	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);

	// MCP0_GPPU: pull-ups
	// Habilito los pull-ups en DCD
	val = MCP0_GPPU;
//	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 0;
	xBytes = sizeof(data);
//	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);

	// TERMPWR ON
	// Al arrancar prendo la terminal para los logs iniciales.
	val = MCP0_OLAT;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	data = 0;
	data |= BV(MCP0_GPIO_OTERMPWR);	// TERMPWR = 1
	xBytes = sizeof(data);
	xReturn = FreeRTOS_write(&pdI2C, &data, xBytes);

	// libero el semaforo.
	FreeRTOS_ioctl(&pdI2C,ioctlRELEASE_BUS_SEMPH, NULL);

	FreeRTOS_write( &pdUART1, "MCP0 init OK\r\n\0", sizeof("MCP0 init OK\r\n\0") );
}
コード例 #22
0
ファイル: mcp_sp5K.c プロジェクト: ppeluffo/sp5KV4_8CH
/*------------------------------------------------------------------------------------*/
s08 pvMCP_testAndSet( u08 deviceId, u08 byteAddr, u08 value, u08 bitMask )
{
size_t xReturn = 0U;
u16 val = 0;
u08 xBytes = 0;
u08 regValue;
s08 retS = FALSE;

//	snprintf_P( debug_printfBuff,sizeof(debug_printfBuff),PSTR("MCPT&S [dev=%d][addr=%d][val=%d][msk=%d].\r\n\0"),deviceId, byteAddr, value,bitMask );
//	FreeRTOS_write( &pdUART1, debug_printfBuff, sizeof(debug_printfBuff) );

	// CONTROLO QUE SI EL MCP ES 23018 ESTE BIEN CONFIGURADO ANTES
	if ( deviceId == MCP1_ADDR ) {
		pvMCP_checkConfiguration();
	}

	// Lo primero es obtener el semaforo
	FreeRTOS_ioctl(&pdI2C,ioctlOBTAIN_BUS_SEMPH, NULL);
	// Luego indicamos el periferico i2c en el cual queremos leer
	val = deviceId;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_DEVADDRESS, &val);
	// Luego indicamos cuantos bytes queremos leer del dispositivo: largo.
	// En los MCP se lee y escribe de a 1 registro.
	val = 1;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESSLENGTH, &val);
	// Ahora indicamos desde que posicion queremos leer: direccion
	val = byteAddr;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	// Por ultimo leemos.
	xBytes = 1;
	xReturn = FreeRTOS_read(&pdI2C, &regValue, xBytes);

	if (xReturn != xBytes ) {
		goto quit;
	}

//	snprintf_P( debug_printfBuff,sizeof(debug_printfBuff),PSTR("MCPT&S [rdVal=%d]\r\n\0"),regValue );
//	FreeRTOS_write( &pdUART1, debug_printfBuff, sizeof(debug_printfBuff) );

	// Modifico el registro
	if  (value == 0) {
		regValue &= ~BV(bitMask);
	} else {
		regValue |= BV(bitMask);
	}

	// Escribo en el MCP
	xBytes = 1;
	xReturn = FreeRTOS_write(&pdI2C, &regValue, xBytes);
	if (xReturn != xBytes ) {
		goto quit;
	}

//	snprintf_P( debug_printfBuff,sizeof(debug_printfBuff),PSTR("MCPT&S [wrVal=%d]\r\n\0"),regValue );
//	FreeRTOS_write( &pdUART1, debug_printfBuff, sizeof(debug_printfBuff) );

	retS = TRUE;

quit:
	// Y libero el semaforo.
	FreeRTOS_ioctl(&pdI2C,ioctlRELEASE_BUS_SEMPH, NULL);
	return(retS);
}
コード例 #23
0
ファイル: pwmctrl.c プロジェクト: vvskrn/V2Bot-FreeRTOS
void prvArmController( void *prvParameters ) {

	uint8_t cCommand, cServoPosition[5];
	int8_t sParameters[4];

	( void ) prvParameters;

	/* At startup, initialize the pins on the LPC1769 for PWM. */
	prvInitPWM();

	for(;;) {

		/* For for the Op-Code and the PWM position. */
		xQueueReceive( xOpCodeQueue, &cCommand, portMAX_DELAY );
		xQueueReceive( xPWMQueue, sParameters, portMAX_DELAY );

		if ( 'r' == cCommand || 'a' == cCommand ) {

			/* The PWM positions received via the UART receiver allow for control of the servos with a
			 * maximum resolution of 128 per 1000 pulses (the servos bounded by more restricted pulse
			 * width will have, obviously, less). PWM positions are calculated by multiplying the byte
			 * value by 8. For the relative (0x72) command, this number is simply added to the current
			 * value in the match register; for absolute, the new position is calculated as this number
			 * plus 1000 (the minimum pulse width).
			 *
			 * Current position of servo 1: 1500
			 * sParameters[0] = 0x2a
			 * The new position calculated from the 'a' (0x61) command is (8 * 0x2a) + 1000 = 1336.
			 * The new position calcualted form the 'r' (0x72) command is 1500 + (8 * 0x2a) = 1836.
			 *
			 * Note: the parameters bytes can also be negative (e.g., 0xa4), and this would cause a
			 * subtraction from the relative position (no effect on absolute).
			 */

			/* An 'r' command (byte 0x72) move the servo to a new position relative to its current. */
			if ( 'r' == cCommand ) {
				LPC_PWM1->MR1 += 8 * sParameters[0];
				LPC_PWM1->MR2 += 8 * sParameters[1];
				LPC_PWM1->MR3 += 8 * sParameters[2];
				LPC_PWM1->MR4 += 8 * sParameters[3];

			/* An 'a' command (byte 0x61) sets the servo to an absolute position between 1000 and 2000. */
			} else if ( 'a' == cCommand ) {
				LPC_PWM1->MR1 = 1000 + ( 4 * ( uint8_t )sParameters[0] );
				LPC_PWM1->MR2 = 1000 + ( 4 * ( uint8_t )sParameters[1] );
				LPC_PWM1->MR3 = 1000 + ( 4 * ( uint8_t )sParameters[2] );
				LPC_PWM1->MR4 = 1000 + ( 4 * ( uint8_t )sParameters[2] );

			}

			/* The following lines check to make sure the servo positions are not going over or under their
			 * safe working positions, and sets them to the maximum or minimum value if this is the case.
			 */
			LPC_PWM1->MR1 = ( 2000 < LPC_PWM1->MR1 ) ? 2000 :
							( 1000 > LPC_PWM1->MR1 ) ? 1000 :
							LPC_PWM1->MR1;

			LPC_PWM1->MR2 = ( 1650 < LPC_PWM1->MR2 ) ? 1650 :
							( 1350 > LPC_PWM1->MR2 ) ? 1350 :
							LPC_PWM1->MR2;

			LPC_PWM1->MR3 = ( 1500 < LPC_PWM1->MR3 ) ? 1500 :
							( 1050 > LPC_PWM1->MR3 ) ? 1050 :
							LPC_PWM1->MR3;

			LPC_PWM1->MR4 = ( 1500 < LPC_PWM1->MR4 ) ? 1500 :
							( 1000 > LPC_PWM1->MR4 ) ? 1000 :
							LPC_PWM1->MR4;

			/* Set the latch enable register to latch MRs 1, 2, and 4 */
			LPC_PWM1->LER = ( 1 << 1 ) | ( 1 << 2 ) | ( 1 << 3) | ( 1 << 4 );

		/* The 'p' command return the position of the selected servo, in hex. */
		} else if ('p' == cCommand ) {
			if ( sParameters[0] )
				itoa( LPC_PWM1->MR1, cServoPosition, 16);
			else if ( sParameters[1] )
				itoa( LPC_PWM1->MR2, cServoPosition, 16);
			else if ( sParameters[2] )
				itoa( LPC_PWM1->MR3, cServoPosition, 16);
			else
				itoa( 0, cServoPosition, 16);
			if ( FreeRTOS_ioctl( xUART3, ioctlOBTAIN_WRITE_MUTEX, pwmctrl50ms ) == pdPASS ) {
				FreeRTOS_write( xUART3, cServoPosition, strlen( cServoPosition ) );
			}
		}

		/* Finally, clear the queues and wait for the next command */
		xQueueReset( xOpCodeQueue );
		xQueueReset( xPWMQueue );
	}
}
コード例 #24
0
ファイル: file_sp5K.c プロジェクト: ppeluffo/sp5KV4
//------------------------------------------------------------------------------------
size_t FF_fopen(void)
{
	/*  Debe correrse luego de iniciado el FRTOS ya que utiliza funciones de este !!!
	    Abre el archivo de memoria extEE.
	    Lo recorre buscando el ppio. y el final e inicializa el FCB
	 	Inicializa el sistema de la memoria ( punteros )
		Recorro la memoria buscando transiciones VACIO->DATO y DATO->VACIO.
		La transicion VACIO->DATO determina el puntero DELptr
		La transicion DATO->VACIO determina el puntero WRptr.
		Si no hay transiciones y todos son datos, la memoria esta llena.
		Si no hay transicions y todos son blancos, la memoria esta vacia.
		Si todo anda bien, retorna en ERRNO un NONE.
		En otro caso retorna el recdNbr del error y setea la variable ERRNO

		// Testing con buffer de 16 posiciones:
		// Memoria vacia: OK
		// Memoria llena: OK
		// Memoria con HEAD(10) > TAIL(4), Free(10) OK
		// Memoria con HEAD(3) < TAIL(8), Free(5) OK
		// Condicion de borde 1: HEAD(15), TAIL(0), Free(1) OK
		// Condicion de borde 2: HEAD(0), TAIL(1), Free(1) OK
		// Condicion de borde 3: HEAD(0), TAIL(15), Free(15) OK
		// Condicion de borde 4: HEAD(1), TAIL(0), Free(15) OK

	 */

u08 mark_Z, mark;
u16 xPos;
s08 transicion = FALSE;
u16 val = 0;
size_t xReturn = 0U;

	// Lo primero es obtener el semaforo del I2C
	FreeRTOS_ioctl(&pdI2C,ioctlOBTAIN_BUS_SEMPH, NULL);
	FCB.ff_stat.errno = pdFF_ERRNO_NONE;
	// Indicamos el periferico i2c al cual quiero acceder
	val = EE_ADDR;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_DEVADDRESS, &val);
	// Luego indicamos la direccion desde donde leer del dispositivo: largo ( en la ee son 2 bytes )
	val = 2;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESSLENGTH, &val);

	// El primer registro que leo es el ultimo del archivo
	// direccion de lectura
	xPos = (FF_MAX_RCDS -1);
	val = FF_ADDR_START +  xPos * FF_RECD_SIZE;
	FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
	// leo una pagina entera, (recd) 64 bytes.
	memset( FCB.ff_buffer,0, sizeof(FCB.ff_buffer) );
	xReturn = FreeRTOS_read(&pdI2C, &FCB.ff_buffer, FF_RECD_SIZE);

#ifdef DEBUG_FF
	snprintf_P( debug_printfBuff,sizeof(debug_printfBuff),PSTR("FO: [%d][%d]\r\n\0"),FF_RECD_SIZE, xReturn);
	FreeRTOS_write( &pdUART1, debug_printfBuff, sizeof(debug_printfBuff) );
#endif

	if ( xReturn != FF_RECD_SIZE ) {
		xReturn = xPos;
		FCB.ff_stat.errno = pdFF_ERRNO_INIT;
		goto quit;
	}
	mark_Z = FCB.ff_buffer[sizeof(FCB.ff_buffer) - 1];

	// Recorro toda la memoria EE buscando transiciones.
	for ( xPos=0; xPos < FF_MAX_RCDS; xPos++) {

		// Para no salir por wdg reset
		if ( (xPos % 128) == 0 ) {
			wdt_reset();
		}

		val = FF_ADDR_START + xPos * FF_RECD_SIZE;
		FreeRTOS_ioctl(&pdI2C,ioctl_I2C_SET_BYTEADDRESS,&val);
		// leo una pagina entera, (recd) 64 bytes.
		memset( FCB.ff_buffer,0, sizeof(FCB.ff_buffer) );
		xReturn = FreeRTOS_read(&pdI2C, &FCB.ff_buffer, FF_RECD_SIZE);

#ifdef DEBUG_FF
//		snprintf_P( debug_printfBuff,sizeof(debug_printfBuff),PSTR("FO: [%d][%d][%d][%d]\r\n\0"),xPos, val,FF_RECD_SIZE, xReturn);
//		FreeRTOS_write( &pdUART1, debug_printfBuff, sizeof(debug_printfBuff) );
#endif
		if ( xReturn != FF_RECD_SIZE )  {
			FCB.ff_stat.errno = pdFF_ERRNO_INIT;
			goto quit;
		}

		mark = FCB.ff_buffer[sizeof(FCB.ff_buffer) - 1];

#ifdef DEBUG_FF
		if ( mark == FF_WRTAG ) {
			snprintf_P( debug_printfBuff,sizeof(debug_printfBuff),PSTR("FO: [%d][%d][%d][%d][0X%03x]\r\n\0"),xPos, val,FF_RECD_SIZE, xReturn, mark);
			FreeRTOS_write( &pdUART1, debug_printfBuff, sizeof(debug_printfBuff) );
		}
#endif

		// busco transiciones:
		if ( ( mark_Z == 0) && ( mark == FF_WRTAG ) ) {
			// Tengo una transicion VACIO->DATO.
			FCB.ff_stat.TAIL = xPos;
			transicion = TRUE;
		}

		if ( ( mark_Z == FF_WRTAG ) && ( mark == 0) ) {
			// Tengo una transicion DATO->VACIO.
			FCB.ff_stat.HEAD = xPos;
			transicion = TRUE;
		}

		mark_Z = mark;
	}

	// Recorri toda la memoria. Analizo las transiciones...
	if ( ! transicion ) {
		// Si no hubieron transiciones es que la memoria esta llena o vacia.
		if ( mark == 0 ) {
			// Memoria vacia.
			FCB.ff_stat.HEAD = 0;
			FCB.ff_stat.TAIL = 0;
			FCB.ff_stat.RD  = FCB.ff_stat.TAIL;
			FCB.ff_stat.rcdsFree = FF_MAX_RCDS;
		} else {
			// Memoria llena
			FCB.ff_stat.HEAD = 0;
			FCB.ff_stat.TAIL = 0;
			FCB.ff_stat.RD  = FCB.ff_stat.TAIL;
			FCB.ff_stat.rcdsFree = 0;
		}
	} else {
		// Memoria con datos. Calculo los registro ocupados.
		if ( FCB.ff_stat.HEAD > FCB.ff_stat.TAIL) {
			FCB.ff_stat.RD  = FCB.ff_stat.TAIL;
			FCB.ff_stat.rcdsFree = FF_MAX_RCDS - FCB.ff_stat.HEAD + FCB.ff_stat.TAIL;
		} else {
			FCB.ff_stat.RD  = FCB.ff_stat.TAIL;
			FCB.ff_stat.rcdsFree = FCB.ff_stat.TAIL - FCB.ff_stat.HEAD;
		}
	}

quit:

	FreeRTOS_ioctl(&pdI2C,ioctlRELEASE_BUS_SEMPH, NULL);

#ifdef DEBUG_FF
		snprintf_P( debug_printfBuff,sizeof(debug_printfBuff),PSTR("FO: [%d][%d]\r\n\0"),xPos, FCB.ff_stat.errno);
		FreeRTOS_write( &pdUART1, debug_printfBuff, sizeof(debug_printfBuff) );
#endif

	return(xPos);

}
コード例 #25
0
static void prvSPIToSDCardTask( void *pvParameters )
{
Peripheral_Descriptor_t xSPIPortUsedByMMCDriver;
extern Peripheral_Descriptor_t xMMCGetSPIPortHandle( void );
FIL *pxFile = NULL;

	( void ) pvParameters;

	/* Wait until the disk is present. */
	while( disk_initialize( spiDRIVE_NUMBER ) != FR_OK )
	{
		vTaskDelay( spiLONG_DELAY );

		/* Is the SD card inserted?  Are the jumpers set correctly to connect
		the SD card to the SPI bus?  See the web documentation for jumper
		settings. */
		configASSERT( ( volatile void * ) NULL );
	}

	/* Mount the drive.  This need not be in a loop. */
	while( f_mount( spiDRIVE_NUMBER, &xFatfs ) != FR_OK )
	{
		/* The drive could not be mounted.  Wait a while, then try again. */
		vTaskDelay( spiLONG_DELAY );
	}

	/* Initialising the disk will have opened an SSP port in SPI mode.  Obtain
	the handle to the opened port from the MMC driver so it can be manipulated
	from this test/demo file. */
	xSPIPortUsedByMMCDriver = xMMCGetSPIPortHandle();

	/* The FIL object is too large to store on the stack of this task.  It is
	instead created dynamically here, and it is never freed because if the
	allocation succeeds the FIL object is used for the lifetime of the task. */
	pxFile = pvPortMalloc( sizeof( FIL ) );
	configASSERT( pxFile );

	if( pxFile != NULL )
	{
		/* Mounting the drive will have opened the SPI port in polled mode.
		Demonstrate FreeRTOS+IO accessing an SPI port (in the SD card driver
		implemented in mmc.c) in polled mode by creating a set of files, then
		reading the files back to ensure they were created correctly. */
		prvWriteFilesToDisk( ( int8_t * ) "poll", pxFile );
		prvReadBackCreatedFiles( ( int8_t * ) "poll", pxFile );

		/* Now set the SPI Tx to use zero copy mode and Rx to use circular buffer
		mode, before creating and reading back the files again. */
		FreeRTOS_ioctl( xSPIPortUsedByMMCDriver, ioctlUSE_ZERO_COPY_TX, cmdPARAMTER_NOT_USED );
		FreeRTOS_ioctl( xSPIPortUsedByMMCDriver, ioctlUSE_CIRCULAR_BUFFER_RX, ( void * ) spiBUFFER_SIZE );

		/* The SPI port is now fully interrupt driven.	 Demonstrate FreeRTOS+IO
		accessing an SPI port in this mode (in the SD card driver implemented in
		mmc.c) by creating the set of files again, then again reading the files
		back to ensure they were created correctly. */
		prvWriteFilesToDisk( ( int8_t * ) "int", pxFile );
		prvReadBackCreatedFiles( ( int8_t * ) "int", pxFile );

		/* Now set the SPI Tx to use interrupt driven character queue Rx and Tx. */
		FreeRTOS_ioctl( xSPIPortUsedByMMCDriver, ioctlUSE_CHARACTER_QUEUE_TX, ( void * ) spiBUFFER_SIZE );
		FreeRTOS_ioctl( xSPIPortUsedByMMCDriver, ioctlUSE_CHARACTER_QUEUE_RX, ( void * ) spiBUFFER_SIZE );
		FreeRTOS_ioctl( xSPIPortUsedByMMCDriver, ioctlSET_RX_TIMEOUT, ( void * ) 5000UL );
		FreeRTOS_ioctl( xSPIPortUsedByMMCDriver, ioctlSET_TX_TIMEOUT, ( void * ) 5000UL );

		/* The SPI port is fully interrupt driven, and using FreeRTOS queues to
		send and receive data into and out of the SPI interrupt.  NOTE: This is not
		an efficient method when large blocks of data are being transferred - it is
		done here purely to demonstrate the method on an SPI port. */
		prvWriteFilesToDisk( ( int8_t * ) "Q", pxFile );
		prvReadBackCreatedFiles( ( int8_t * ) "Q", pxFile );
	}

	/* From here on the files exist, and disk and directory structure queried
	using the command interpreter.  There is nothing more for this task to do.
	The task could be deleted, but in this case it is left running so its stack
	usage can be inspected. */
	for( ;; )
	{
		vTaskDelay( 1000 );
	}
}
//
//
//
//lecture - many features are from FREERTOS+CLI subsystem - explore related headers and
//          source files as needed ???
//
//lecture - several calls are to FREERTOS+IO subsystems - explore related headers and
//          source files as needed ???
//
//
//
//
//
static void prvUARTCommandConsoleTask( void *pvParameters )
{
int8_t cRxedChar, cInputIndex = 0, *pcOutputString;
static int8_t 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();

	/* Open the UART port used for console input.  The second parameter
	(ulFlags) is not used in this case.  The default board rate is set by the
	boardDEFAULT_UART_BAUD parameter.  The baud rate can be changed using a
	FreeRTOS_ioctl() call with the ioctlSET_SPEED command. */
	//lecture - UART - refer to FreeRTOS_DriverInterface.c for FreeRTOS_open() api
	//        - UART - refer to LPCXpresso17xx-base-board.h for
	//                 boardCOMMAND_CONSOLE_UART - it is UART3 of the four UARTs
	//
	//
	//lecture - UART - we will receive NULL, if there is a failure
	//
	//
	xConsoleUART = FreeRTOS_open( boardCOMMAND_CONSOLE_UART, ( uint32_t ) cmdPARAMTER_NOT_USED );
	configASSERT( xConsoleUART );

	//
	//lecture - UART - refer to FreeRTOS_DriverInterface.c for FreeRTOS_ioctl() api
	//
	//
#if 1
	/* Change the Tx usage model from straight polled mode to use zero copy
	buffers with interrupts.  In this mode, the UART will transmit characters
	directly from the buffer passed to the FreeRTOS_write()	function. */
//	xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_ZERO_COPY_TX, cmdPARAMTER_NOT_USED );
	//configASSERT( xReturned );

	xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_TASKNOTIFICATION_TX, uartstCIRCULAR_BUFFER_SIZE );
	configASSERT( xReturned );


#endif


#if 1

	//xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_CIRCULAR_BUFFER_RX, uartstCIRCULAR_BUFFER_SIZE );
	//configASSERT( xReturned );
	xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_TASKNOTIFICATION_RX, uartstCIRCULAR_BUFFER_SIZE );
	configASSERT( xReturned );
#endif

    //
	//
	//
	//lecture -UART - refer to FreeRTOS_DriverInterface.c for FreeRTOS_ioctl() api
	//
    //
	/* Change the Rx usage model from straight polled mode to use a character
	queue.  Character queue reception is appropriate in this case as characters
	can only be received as quickly as they can be typed, and need to be parsed
	character by character. */
	//xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_CHARACTER_QUEUE_RX, ( void * ) cmdMAX_INPUT_SIZE );
	//configASSERT( xReturned );

	//
	//lecture - UART - refer to refer to FreeRTOS_DriverInterface.c for FreeRTOS_ioctl() api -
	//                 eventually, invokes the uart specific ioctl method and respective setting
	//
	//lecture - UART - may set different priorities and check ???
	//
	/* By default, the UART interrupt priority will have been set to the lowest
	possible.  It must be kept at or below configMAX_LIBRARY_INTERRUPT_PRIORITY,
	but	can be raised above its default priority using a FreeRTOS_ioctl() call
	with the ioctlSET_INTERRUPT_PRIORITY command. */
	xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlSET_INTERRUPT_PRIORITY, ( void * ) ( configMIN_LIBRARY_INTERRUPT_PRIORITY - 1 ) );
	configASSERT( xReturned );
    //
	//
	//
	//lecture - UART - as per zero copy tx mode, we must first acquire the mutex, before we can
	//                 initiate a write on the device instance - in this case, it is uart
	//
	//lecture - UART - refer to FreeRTOS_DriverInterface.c for code and details of FreeRTOS_ioctl()
	//
	//
#if 1
	//
	/* Send the welcome message. */
//	if( FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms ) == pdPASS )
	{
		FreeRTOS_write( xConsoleUART, pcWelcomeMessage, strlen( ( char * ) pcWelcomeMessage ) );
	}
#endif

#if 0
	if(FreeRTOS_ioctl( xConsoleUART, ioctlRELEASE_WRITE_MUTEX, cmd50ms ) == pdPASS )
	{
	   printf("mutex released\n");
	}
#endif

	//FreeRTOS_write( xConsoleUART, pcWelcomeMessage, strlen( ( char * ) pcWelcomeMessage ) );
	//for(;;); //aaa-zzz  : for testing

	for( ;; )
	{
		xReturned = FreeRTOS_read( xConsoleUART, &cRxedChar, sizeof( cRxedChar ) );
		configASSERT( xReturned );

		//printf("LSR=%d",)
		/* Echo the character back. */
		if( FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms ) == pdPASS )
		{
			FreeRTOS_write( xConsoleUART, &cRxedChar, sizeof( cRxedChar ) );
		}

		if( cRxedChar == '\n' )
		{
			/* The input command string is complete.  Ensure the previous
			UART transmission has finished before sending any more data.
			This task will be held in the Blocked state while the Tx completes,
			if it has not already done so, so no CPU time will be wasted by
			polling. */
	//		if( FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms ) == pdPASS )
			{
				/* Start to transmit a line separator, just to make the output
				easier to read. */
				FreeRTOS_write( xConsoleUART, pcNewLine, strlen( ( char * ) pcNewLine ) );
			}

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

			/* Pass the received command to the command interpreter.  The
			command interpreter is called repeatedly until it returns
			pdFALSE as it might generate more than one string. */
			do
			{
				/* Once again, just check to ensure the UART has completed
				sending whatever it was sending last.  This task will be held
				in the Blocked state while the Tx completes, if it has not
				already done so, so no CPU time	is wasted polling. */
				xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms );
				if( xReturned == pdPASS )
				{
					/* Get the string to write to the UART from the command
					interpreter. */
					xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );

					/* Write the generated string to the UART. */
					FreeRTOS_write( xConsoleUART, 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 );

			/* Ensure the last string to be transmitted has completed. */
			if( FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms ) == pdPASS )
			{
				/* Start to transmit a line separator, just to make the output
				easier to read. */
				FreeRTOS_write( xConsoleUART, pcEndOfCommandOutputString, strlen( ( char * ) pcEndOfCommandOutputString ) );
			}
		}
		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++;
					}
				}
			}
		}
	}
}
コード例 #27
0
ファイル: pwmctrl.c プロジェクト: vvskrn/V2Bot-FreeRTOS
void prvUARTReceiver( void * prvParameters ) {
	int8_t cRxedChar, cInputIndex = 0;
	static int8_t cInputString[ pwmctrlMAX_INPUT_SIZE ];
	portBASE_TYPE xReturned;

	( void ) prvParameters;

	/* Open the UART port used for console input.  The second parameter
	(ulFlags) is not used in this case.  The default board rate is set by the
	boardDEFAULT_UART_BAUD parameter.  The baud rate can be changed using a
	FreeRTOS_ioctl() call with the ioctlSET_SPEED command. */
	xUART3 = FreeRTOS_open( boardUART3, ( uint32_t ) pwmctrlPARAMETER_NOT_USED );
	configASSERT( xUART3 );

	/* Change the Tx usage model from straight polled mode to use zero copy
	buffers with interrupts.  In this mode, the UART will transmit characters
	directly from the buffer passed to the FreeRTOS_write()	function. */
	xReturned = FreeRTOS_ioctl( xUART3, ioctlUSE_ZERO_COPY_TX, pwmctrlPARAMETER_NOT_USED );
	configASSERT( xReturned );

	/* Change the Rx usage model from straight polled mode to use a character
	queue.  Character queue reception is appropriate in this case as characters
	can only be received as quickly as they can be typed, and need to be parsed
	character by character. */
	xReturned = FreeRTOS_ioctl( xUART3, ioctlUSE_CHARACTER_QUEUE_RX, ( void * ) pwmctrlMAX_INPUT_SIZE );
	configASSERT( xReturned );

	/* By default, the UART interrupt priority will have been set to the lowest
	possible.  It must be kept at or below configMAX_LIBRARY_INTERRUPT_PRIORITY,
	but	can be raised above its default priority using a FreeRTOS_ioctl() call
	with the ioctlSET_INTERRUPT_PRIORITY command. */
	xReturned = FreeRTOS_ioctl( xUART3, ioctlSET_INTERRUPT_PRIORITY, ( void * ) ( configMIN_LIBRARY_INTERRUPT_PRIORITY - 1 ) );
	configASSERT( xReturned );

	for(;;) {
		/* Only interested in reading one character at a time (for now). */
		FreeRTOS_read( xUART3, &cRxedChar, sizeof( cRxedChar ) );

		/* For debugging purposes, echo back each character received to the terminal */
#if pwmctrlDEBUG
		if( FreeRTOS_ioctl( xUART3, ioctlOBTAIN_WRITE_MUTEX, pwmctrl50ms ) == pdPASS ) {
			FreeRTOS_write( xUART3, &cRxedChar, sizeof( cRxedChar ) );
		}
#endif
		/* If we receive the STOP character, stop taking input and begin parsing the command. */
		if ( cRxedChar == pwmctrlSTOP ) {

		/* Again, for debugging we're just adding a carriage return to make the output look nice. */
#if pwmctrlDEBUG
			if( FreeRTOS_ioctl( xUART3, ioctlOBTAIN_WRITE_MUTEX, pwmctrl50ms ) == pdPASS ) {
				FreeRTOS_write( xUART3, "\r", 1 );
			}
#endif
			/* Run the method to parse the input received over UART, then reset cInputString to be ready for the next command  */
			prvParseCommand( cInputString );
			cInputIndex = 0;
			memset( cInputString, 0x00, pwmctrlMAX_INPUT_SIZE );

		/* Otherwise, increment the cInputIndex and continue receiving bytes */
		} else {
			if( cInputIndex < pwmctrlMAX_INPUT_SIZE ) {
				cInputString[ cInputIndex ] = cRxedChar;
				cInputIndex++;
			}
		}
	}
}
コード例 #28
0
ファイル: I2C-to-and-from-EEPROM.c プロジェクト: jabv/ZumoBot
void vI2C_EEPROMTest( Peripheral_Descriptor_t xI2CPort )
{
uint32_t ulStartAddress = 0UL, ulPage;
const uint32_t ulMaxDelay = 500UL / portTICK_RATE_MS;
static uint8_t ucByte, ucValue;
int32_t lReturned;

	/* The I2C port is opened and configured in the I2C-coordinator.c file.
	The opened handle is passed in to this file - which just uses the I2C
	FreeRTOS+IO driver with whatever configuration it happens to have at that
	time.  Sometimes it	will be operating in polled mode, and other in
	interrupt driven zero copy Tx with interrupt driven circular buffer Rx. */

	/* Set the clock frequency to be correct for the EEPROM. */
	FreeRTOS_ioctl( xI2CPort, ioctlSET_SPEED, i2cEEPROM_CLOCK );

	/* The write mutex is obtained in the code below, but it is possible that
	it is already held by this task - in which case the attempt to obtain it
	will fail.  Release the mutex first, just in case. */
	FreeRTOS_ioctl( xI2CPort, ioctlRELEASE_WRITE_MUTEX, i2cPARAMETER_NOT_USED );

	/* Wait until any writes already in progress have completed. */
	FreeRTOS_ioctl( xI2CPort, ioctlOBTAIN_WRITE_MUTEX, ( void * ) ulMaxDelay );

	/* Fill the EEPROM with 0x00, one page at a time. */
	memset( ucDataBuffer, 0x00, sizeof( ucDataBuffer ) );
	for( ulPage = 0UL; ulPage < ( i2cTOTAL_EEPROM_SIZE / i2cPAGE_SIZE ); ulPage++ )
	{
		prvWritePageToEEPROM( xI2CPort, ulStartAddress );

		/* Move to the next page. */
		ulStartAddress += i2cPAGE_SIZE;
	}

	/* Check all data read from the EEPROM reads as 0x00.  Start by setting the
	read address back to the start of the EEPROM. */
	ucDataBuffer[ 0 ] = 0x00;
	lReturned = FreeRTOS_write( xI2CPort, ucDataBuffer, sizeof( ucDataBuffer[ 0 ] ) );
	configASSERT( lReturned == sizeof( ucDataBuffer[ 0 ] ) );

	/* Wait until the write completes. */
	FreeRTOS_ioctl( xI2CPort, ioctlOBTAIN_WRITE_MUTEX, ( void * ) ulMaxDelay );

	for( ulPage = 0UL; ulPage < ( i2cTOTAL_EEPROM_SIZE / i2cPAGE_SIZE ); ulPage++ )
	{
		/* Ensure the data buffer does not contain 0x00 already. */
		memset( ucDataBuffer, 0xff, sizeof( ucDataBuffer ) );

		/* Read a page back from the EEPROM. */
		lReturned = FreeRTOS_read( xI2CPort, ucDataBuffer, i2cPAGE_SIZE );
		configASSERT( lReturned == i2cPAGE_SIZE );

		/* Check each byte in the page just read contains 0. */
		for( ucByte = 0U; ucByte < i2cPAGE_SIZE; ucByte++ )
		{
			configASSERT( ucDataBuffer[ ucByte ] == 0U );
		}
	}

	/* Do the same, but this time write a different value into each location
	(the value will overflow). */
	ucValue = 0x00U;
	ulStartAddress = 0UL;
	for( ulPage = 0UL; ulPage < ( i2cTOTAL_EEPROM_SIZE / i2cPAGE_SIZE ); ulPage++ )
	{
		for( ucByte = 0U; ucByte < i2cPAGE_SIZE; ucByte++ )
		{
			/* ucDataBuffer[ 0 ] holds the byte address so is skipped. */
			ucDataBuffer[ ucByte + 1 ] = ucValue;
			ucValue++;
		}

		prvWritePageToEEPROM( xI2CPort, ulStartAddress );

		/* Move to the next page. */
		ulStartAddress += i2cPAGE_SIZE;
	}

	/* Check all data read from the EEPROM reads as written.  Start by setting
	the	read address back to the start of the EEPROM. */
	ucDataBuffer[ 0 ] = 0x00;
	lReturned = FreeRTOS_write( xI2CPort, ucDataBuffer, sizeof( ucDataBuffer[ 0 ] ) );
	configASSERT( lReturned == sizeof( ucDataBuffer[ 0 ] ) );

	/* Wait until the write completes. */
	FreeRTOS_ioctl( xI2CPort, ioctlOBTAIN_WRITE_MUTEX, ( void * ) ulMaxDelay );

	ucValue = 0U;
	for( ulPage = 0UL; ulPage < ( i2cTOTAL_EEPROM_SIZE / i2cPAGE_SIZE ); ulPage++ )
	{
		/* Ensure the data buffer starts clear. */
		memset( ucDataBuffer, 0xff, sizeof( ucDataBuffer ) );

		/* Read a page back from the EEPROM. */
		lReturned = FreeRTOS_read( xI2CPort, ucDataBuffer, i2cPAGE_SIZE );
		configASSERT( lReturned == i2cPAGE_SIZE );

		/* Check each byte in the page contains the expected value. */
		for( ucByte = 0U; ucByte < i2cPAGE_SIZE; ucByte++ )
		{
			configASSERT( ucDataBuffer[ ucByte ] == ucValue );
			ucValue++;
		}
	}
}
コード例 #29
0
ファイル: sp5KV5_PZ_tkCmd.c プロジェクト: ppeluffo/sp5KV5_PZ
/*------------------------------------------------------------------------------------*/
static void cmdWriteFunction(void)
{
s08 retS = FALSE;
u08 argc;

	argc = pv_makeArgv();

	// SAVE
	if (!strcmp_P( strupr(argv[1]), PSTR("SAVE\0"))) {
		retS = u_saveSystemParams();
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// PASSWD
	if (!strcmp_P( strupr(argv[1]), PSTR("PASSWD\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			memset(systemVars.passwd, '\0', sizeof(systemVars.passwd));
			memcpy(systemVars.passwd, argv[2], sizeof(systemVars.passwd));
			systemVars.passwd[PASSWD_LENGTH - 1] = '\0';
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// DLGID
	if (!strcmp_P( strupr(argv[1]), PSTR("DLGID\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			memcpy(systemVars.dlgId, argv[2], sizeof(systemVars.dlgId));
			systemVars.dlgId[DLGID_LENGTH - 1] = '\0';
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// APN
	if (!strcmp_P( strupr(argv[1]), PSTR("APN\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			memset(systemVars.apn, '\0', sizeof(systemVars.apn));
			memcpy(systemVars.apn, argv[2], sizeof(systemVars.apn));
			systemVars.apn[APN_LENGTH - 1] = '\0';
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// ROAMING
	if (!strcmp_P( strupr(argv[1]), PSTR("ROAMING\0"))) {
		if (!strcmp_P( strupr(argv[2]), PSTR("ON"))) { systemVars.roaming = TRUE; }
		if (!strcmp_P( strupr(argv[2]), PSTR("OFF"))) { systemVars.roaming = FALSE; }
		pv_snprintfP_OK();
		return;
	}

	// SERVER PORT
	if (!strcmp_P( strupr(argv[1]), PSTR("PORT\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			memset(systemVars.serverPort, '\0', sizeof(systemVars.serverPort));
			memcpy(systemVars.serverPort, argv[2], sizeof(systemVars.serverPort));
			systemVars.serverPort[PORT_LENGTH - 1] = '\0';
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// SERVER IP
	if (!strcmp_P( strupr(argv[1]), PSTR("IP\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			memset(systemVars.serverAddress, '\0', sizeof(systemVars.serverAddress));
			memcpy(systemVars.serverAddress, argv[2], sizeof(systemVars.serverAddress));
			systemVars.serverAddress[IP_LENGTH - 1] = '\0';
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// SERVER SCRIPT
	if (!strcmp_P( strupr(argv[1]), PSTR("SCRIPT\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			memset(systemVars.serverScript, '\0', sizeof(systemVars.serverScript));
			memcpy(systemVars.serverScript, argv[2], sizeof(systemVars.serverScript));
			systemVars.serverScript[SCRIPT_LENGTH - 1] = '\0';
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	/* DEBUGLEVEL */
	if (!strcmp_P( strupr(argv[1]), PSTR("DEBUGLEVEL\0"))) {
		retS = pv_cmdWrDebugLevel(argv[2]);
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	/* DEBUGLEVEL */
	if (!strcmp_P( strupr(argv[1]), PSTR("LOG\0"))) {
		retS = pv_cmdWrLog(argv[2]);
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	/* WRKMODE */
	if (!strcmp_P( strupr(argv[1]), PSTR("WRKMODE\0"))) {
		retS = pv_cmdWrkMode(argv[2],argv[3]);
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// CANALES ANALOGICOS
	if (!strcmp_P( strupr(argv[1]), PSTR("A0\0"))) {
		retS = u_configAnalogCh( 0, argv[2] );
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	if (!strcmp_P( strupr(argv[1]), PSTR("A1\0"))) {
		retS = u_configAnalogCh( 1, argv[2] );
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	if (!strcmp_P( strupr(argv[1]), PSTR("A2\0"))) {
		retS = u_configAnalogCh( 2, argv[2] );
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// TIMERPOLL
	if (!strcmp_P( strupr(argv[1]), PSTR("TIMERPOLL\0"))) {
		retS = u_configTimerPoll(argv[2]);

		// tk_range: notifico en modo persistente. Si no puedo, me voy a resetear por watchdog. !!!!
		while ( xTaskNotify(xHandle_tkRange, TK_PARAM_RELOAD , eSetBits ) != pdPASS ) {
			vTaskDelay( ( TickType_t)( 100 / portTICK_RATE_MS ) );
		}

		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// RTC
	if (!strcmp_P( strupr(argv[1]), PSTR("RTC\0"))) {
		retS = u_wrRtc(argv[2]);
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	//----------------------------------------------------------------------
	// COMANDOS USADOS PARA DIAGNOSTICO
	// DEBEMOS ESTAR EN MODO SERVICE
	//----------------------------------------------------------------------

	// GSMBAND:
	// Debo estar en modo service ya que para que tome el valor debe resetearse
	if (!strcmp_P( strupr(argv[1]), PSTR("GSMBAND\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			systemVars.gsmBand = atoi(argv[2]);
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// EE: write ee pos string
	if (!strcmp_P( strupr(argv[1]), PSTR("EE\0")) && ( systemVars.wrkMode == WK_SERVICE) ) {
		retS = pv_cmdWrEE( argv[2], argv[3]);
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// gprsPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("GPRSPWR\0")) && ( systemVars.wrkMode == WK_SERVICE) ) {
		retS = MCP_setGprsPwr( (u08) atoi(argv[2]) );
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// gprsSW
	if (!strcmp_P( strupr(argv[1]), PSTR("GPRSSW\0")) && ( systemVars.wrkMode == WK_SERVICE) ) {
		retS = MCP_setGprsSw( (u08) atoi(argv[2]) );
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// MCP
	// write mcp 0|1|2 addr value
	if (!strcmp_P( strupr(argv[1]), PSTR("MCP\0")) && ( systemVars.wrkMode == WK_SERVICE) ) {
		switch( atoi(argv[2] )) {
		case 0:
			retS = MCP_write( MCP0_ADDR, atoi(argv[3]), atoi(argv[4]) );
			break;
		case 1:
			retS = MCP_write( MCP1_ADDR, atoi(argv[3]), atoi(argv[4]) );
			break;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// ATCMD
	// Envia un comando al modem.
	if (!strcmp_P( strupr(argv[1]), PSTR("ATCMD\0")) && ( systemVars.wrkMode == WK_SERVICE) ) {
		snprintf( cmd_printfBuff,sizeof(cmd_printfBuff),"%s\r",argv[2] );
		FreeRTOS_ioctl( &pdUART0,ioctl_UART_CLEAR_RX_BUFFER, NULL);
		FreeRTOS_ioctl( &pdUART0,ioctl_UART_CLEAR_TX_BUFFER, NULL);
		FreeRTOS_write( &pdUART0, cmd_printfBuff, sizeof(cmd_printfBuff) );

		snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("sent->%s\r\n\0"),argv[2] );
		FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );
		return;
	}

	// RANGE control
	if (!strcmp_P( strupr(argv[1]), PSTR("RANGECTL\0")) && ( systemVars.wrkMode == WK_SERVICE) ) {
		if (!strcmp_P( strupr(argv[2]), PSTR("RUN"))) {
			u_rangeSignal(RUN);
			retS = TRUE;
		}
		if (!strcmp_P( strupr(argv[2]), PSTR("STOP"))) {
			u_rangeSignal(STOP);
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// CMD NOT FOUND
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("ERROR\r\nCMD NOT DEFINED\r\n"));
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );
	return;
}
コード例 #30
0
static void prvI2CTask( void *pvParameters )
{
Peripheral_Descriptor_t xI2CPort;
const uint32_t ulMaxDelay = 500UL / portTICK_RATE_MS;

	( void ) pvParameters;

	/* Open the I2C port used for writing to both the OLED and the EEPROM.  The
	second parameter (ulFlags) is not used in this case.  The port is opened in
	polling mode.  It is changed to interrupt driven mode later in this
	function. */
	xI2CPort = FreeRTOS_open( boardOLED_I2C_PORT, ( uint32_t ) i2cPARAMETER_NOT_USED );
	configASSERT( xI2CPort );

	/* The OLED must be initialised before it is used. */
	vI2C_OLEDInitialise( xI2CPort );

	/* Write and read-back operations are to be performed on the EEPROM while
	the I2C bus is in polling mode.  Indicate this on the OLED. */
	vOLEDPutString( 0U, ( uint8_t * ) "Testing EEPROM", OLED_COLOR_WHITE, OLED_COLOR_BLACK );
	vOLEDPutString( oledCHARACTER_HEIGHT, ( uint8_t * ) "in polling mode", OLED_COLOR_WHITE, OLED_COLOR_BLACK );
	vOLEDRefreshDisplay();

	/* Perform the polling mode EEPROM tests/examples. */
	vI2C_EEPROMTest( xI2CPort );

	/* Perform the polling mode OLED write example. */
	vI2C_OLEDTest( xI2CPort, ( uint8_t * ) "in polling mode" );

	/* Switch to interrupt driven zero copy Tx mode and interrupt driven
	circular buffer Rx mode (with a limited time out). */
	FreeRTOS_ioctl( xI2CPort, ioctlUSE_ZERO_COPY_TX, i2cPARAMETER_NOT_USED );
	FreeRTOS_ioctl( xI2CPort, ioctlUSE_CIRCULAR_BUFFER_RX, i2cCIRCULAR_BUFFER_SIZE );
	FreeRTOS_ioctl( xI2CPort, ioctlSET_RX_TIMEOUT, i2c200MS_TIMEOUT );

	/* By default, the I2C interrupt priority will have been set to
	the lowest possible.  It must be kept at or below
	configMAX_LIBRARY_INTERRUPT_PRIORITY, but can be raised above
	its default priority using a FreeRTOS_ioctl() call with the
	ioctlSET_INTERRUPT_PRIORITY command. */
	FreeRTOS_ioctl( xI2CPort, ioctlSET_INTERRUPT_PRIORITY, ( void * ) ( configMIN_LIBRARY_INTERRUPT_PRIORITY - 1 ) );

	/* Write and read-back operations are to be performed on the EEPROM while
	the I2C bus is in interrupt driven zero copy Tx, and interrupt driven
	circular buffer Rx mode.  Indicate this on the OLED. */
	vOLEDPutString( 0U, ( uint8_t * ) "Testing EEPROM", OLED_COLOR_WHITE, OLED_COLOR_BLACK );
	vOLEDPutString( oledCHARACTER_HEIGHT, ( uint8_t * ) "in intrpt mode", OLED_COLOR_WHITE, OLED_COLOR_BLACK );

	/* Using zero copy Tx mode means the write mutex must be obtained prior to
	calling vOLEDRefreshDisplay().  The write mutex is retained when
	vOLEDRefreshDisplay() returns. */
	FreeRTOS_ioctl( xI2CPort, ioctlOBTAIN_WRITE_MUTEX, ( void * ) ulMaxDelay );
	vOLEDRefreshDisplay();

	/* Perform the interrupt driven mode EEPROM tests/examples. */
	vI2C_EEPROMTest( xI2CPort );

	/* Finish off by just continuously writing a scrolling message to the
	OLED. */
	for( ;; )
	{
		vI2C_OLEDTest( xI2CPort, ( uint8_t * ) "in intrpt mode" );
	}
}