Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

RTOS driver examples or guidelines?

Status
Not open for further replies.

jgpeiro

Newbie level 4
Newbie level 4
Joined
Jul 7, 2009
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Spain
Activity points
1,318
rtos examples

I am thinking about developing a collection of drivers for the peripheral ones of the PIC24 of Microchip based on FreeRTOS, but I am not sure that it must make driver.
Until the moment I believe that driver it must allow the different tasks of using the peripheral one without causing problems.

The typical functions that are available so that the application controls the peripheral one are: Init, Reset, Open, Close, Read, Write.

Somebody knows some page Web or some text in pdf about this subject?
 

rtos driver

I have written a lightweight rtos for Pic24 and posted it on eda board here.



It has full source code and documentation plus examples.

Take a look, maybe you can base your system on the code.
 

rtos drivers

This is the first version of UART DRIVER for PIC24 and FreeRTOS.
NOTE THAT THIS VERSION NOT WORKS!!

Code:
// UART_DRIVER.H

#ifndef UART_DRIVER_H
#define UART_DRIVER_H

#include "UART.H"
#include "FreeRTOS.h"
#include "queue.h"
#include "semphr.h"

int InitUART1_driver(void);
void OpenUART1_driver(unsigned int config1,unsigned int config2, unsigned int ubrg);
void CloseUART1_driver(void);
unsigned int ReadUART1_driver(void);
void WriteUART1_driver(unsigned int data);
//void _ISR _U2TXInterrupt(void);
//void _ISR _U2RXInterrupt(void);

#endif	// #ifndef UART_DRIVER_H

Code:
// UART_DRIVER.C

#ifndef UART_DRIVER_C
#define UART_DRIVER_C

#include "UART_DRIVER.H"

static xSemaphoreHandle xMutexUartDriver;
static xQueueHandle xQueueUartDriverTx; 
static xQueueHandle xQueueUartDriverRx; 


int InitUART1_driver(void){

    if( NULL == ( xMutexUartDriver = xSemaphoreCreateMutex() ) )
    	return -1;
	
	if( NULL == ( xQueueUartDriverTx = xQueueCreate( 4, sizeof( unsigned int ) ) ) )
		return -1;
	
	if( NULL == ( xQueueUartDriverRx = xQueueCreate( 4, sizeof( unsigned int ) ) ) )
		return -1;
	
	vQueueAddToRegistry( xMutexUartDriver, ( signed portCHAR * ) "xMutexUartDriver" );
	vQueueAddToRegistry( xQueueUartDriverTx, ( signed portCHAR * ) "xQueueUartDriverTx" );
	vQueueAddToRegistry( xQueueUartDriverRx, ( signed portCHAR * ) "xQueueUartDriverRx" );
	return 0;
}

void OpenUART1_driver(unsigned int config1,unsigned int config2, unsigned int ubrg){

	if( pdTRUE == xSemaphoreTake( xMutexUartDriver, portMAX_DELAY ) ){
		OpenUART1( config1, config2, ubrg );
		ConfigIntUART1( UART_RX_INT_EN & UART_RX_INT_PR7 & UART_TX_INT_EN & UART_TX_INT_PR7 ); // Como trabajar correctamente con los defines de uart.h?
	}
	
	return;
}


void CloseUART1_driver(void){
	CloseUART1();
	ConfigIntUART1( UART_RX_INT_DIS & UART_TX_INT_DIS );// Como trabajar correctamente con los defines de uart.h?
	xSemaphoreGive( xMutexUartDriver );
	return;
}


unsigned int ReadUART1_driver(void){
	unsigned int data;
	xQueueReceive( xQueueUartDriverRx, &data,  portMAX_DELAY );
	return data;
}


void WriteUART1_driver(unsigned int data){
	
	xQueueSend( xQueueUartDriverTx, ( void * ) &data, portMAX_DELAY );
	
	if( uxQueueMessagesWaiting( xQueueUartDriverTx ) )		// ¿¿??
		IFS0bits.U1TXIF = 1;								// ¿¿??
	
	return;
}

void _ISR __attribute__((interrupt)) _U1RXInterrupt( void ){
//void __attribute__((__interrupt__, auto_psv)) _U1RXInterrupt( void ){
	
	unsigned int data;
	IFS0bits.U1RXIF = 0;	// Clear flag
	portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
	
	data = ReadUART1();
	
	
	xQueueSendFromISR( xQueueUartDriverRx, &data, &xHigherPriorityTaskWoken );
	
	return;
}

void _ISR __attribute__((interrupt)) _U1TXInterrupt( void ){
//void __attribute__((__interrupt__, auto_psv)) _U1TXInterrupt( void ){

	unsigned int data;
	IFS0bits.U1TXIF = 0;	// Clear flag
	portBASE_TYPE xTaskWokenByReceive = pdFALSE;
    
    xQueueReceiveFromISR( xQueueUartDriverTx, ( void * ) &data, &xTaskWokenByReceive );
    WriteUART1( data );
	       
    return;
}


#endif	// #ifndef UART_DRIVER_C




Code:
void vTaskUARTTEST( void * pvParameters ){
 	
 	unsigned int value1=0, value2=0, value3=0, value4=0;
 	 	
 	AD1PCFG = 0xFFFF; 							// Configura los pines del puerto A como digitales. Solo para el PIC24.

	asm volatile ( "MOV #OSCCON, w1 \n" "MOV #0x46, w2 \n" "MOV #0x57, w3 \n" "MOV.b w2, [w1] \n" "MOV.b w3, [w1] \n" "BCLR OSCCON,#6");
	RPOR7bits.RP15R = 3;	// RP15 is UART1TX
	RPINR18bits.U1RXR = 14;	// UART1RX is RP14
	asm volatile ( "MOV #OSCCON, w1 \n" "MOV #0x46, w2 \n" "MOV #0x57, w3 \n" "MOV.b w2, [w1] \n" "MOV.b w3, [w1] \n" "BSET OSCCON, #6" );
	
 	while(1){

 	OpenUART1_driver( 0x8000, 0x0400, 12 );
	
		unsigned int data = 100;
		do{	
		
			WriteUART1_driver( data );
			data = ReadUART1_driver();
	
		}while( data != 100 );
	
 		CloseUART1_driver();
        }
}

int main(){
	if( InitUART1_driver() )
		return -1;
	
	if( pdPASS != ( xTaskCreate( vTaskUARTTEST, ( signed portCHAR * ) "UARTTEST,", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, &xHandleADC ) ) )
		return -1;

	vTaskStartScheduler();
 

Check a course "Architecture Design of Device Drivers" by D. Kalinsky.
--
Amr
 

Check **broken link removed**, here you have a list of developed drivers for FREERTOS with a specific microcontroller but the code serves as example to extrapolate to other microcontrollers.

Hope you find it useful.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top