change tut01 to use global buffer
PATCH 1/1 change tut01 to use global buffer
Hi
As already discussed with Jan, I've changed the tut01. Now :
- it use a global buffer
- tut01-skeleton-app has the same behaviour as tut02-skeleton-app. With no argument, the program read in the device, with an argument, the program write in the device.
regards,
Philippe
PS : the website seems to be down
tut01-skeleton-drv.c +15 -20
@@ -25,7 +25,7 @@* - open: start device usage * - close: ends device usage * - write: store transfered data in an internal buffer -* - read: return previously stored data and erase buffer +* - read: return previously stored data * */
@@ -39,17 +39,18 @@#define DEVICE_NAME "tut01-skeleton-drv01"#define SOME_SUB_CLASS 4711 +/** -* The context of a device instance +* The size of the global buffer * -* A context is created each time a device is opened and passed to -* other device handlers when they are called. +*/ +int global_buffer_size =0 ; + +/** +* A global buffer * */ -typedef struct buffer_s { -int size; -char data[SIZE_MAX ]; -}buffer_t ; +char global_buffer[SIZE_MAX ];/** * Open the device
@@ -60,9 +61,6 @@static int simple_rtdm_open_nrt (struct rtdm_dev_context *context,rtdm_user_info_t * user_info,int oflags) { -buffer_t * buffer = (buffer_t *) context->dev_private; - buffer->size =0 ;/* clear the buffer */ -return 0 ; }
@@ -88,11 +86,9 @@ rtdm_user_info_t * user_info, void *buf, size_t nbyte) { -buffer_t * buffer = (buffer_t *) context->dev_private; -int size = (buffer->size > nbyte) ? nbyte : buffer->size; +int size = (global_buffer_size > nbyte) ? nbyte : global_buffer_size; - buffer->size =0 ; -if (rtdm_safe_copy_to_user (user_info, buf, buffer->data, size)) +if (rtdm_safe_copy_to_user (user_info, buf, global_buffer, size))rtdm_printk ("ERROR : can't copy data from driver\n" );return size;
@@ -108,13 +104,12 @@rtdm_user_info_t * user_info, const void *buf, size_t nbyte) { - buffer_t * buffer = (buffer_t *) context->dev_private; + global_buffer_size = (nbyte >SIZE_MAX ) ?SIZE_MAX : nbyte; - buffer->size = (nbyte >SIZE_MAX ) ?SIZE_MAX : nbyte; -if (rtdm_safe_copy_from_user (user_info, buffer->data, buf, buffer->size)) +if (rtdm_safe_copy_from_user (user_info, global_buffer, buf, global_buffer_size))rtdm_printk ("ERROR : can't copy data to driver\n" ); -return nbyte; +return global_buffer_size; }/**
@@ -125,7 +120,7 @@ .struct_version = RTDM_DEVICE_STRUCT_VER, .device_flags = RTDM_NAMED_DEVICE, - .context_size = sizeof(buffer_t), + .context_size = 0, /* no context for this device */ .device_name = DEVICE_NAME, .open_nrt = simple_rtdm_open_nrt,
tut01-skeleton-app.c +19 -27
82 lines not on this page · raw message