[joyos] r301 committed - Added copy_objects() method to handle copying locked objects[] data in...

1 view
Skip to first unread message

jo...@googlecode.com

unread,
Jan 20, 2011, 8:52:51 PM1/20/11
to joyos...@googlegroups.com
Revision: 301
Author: scot...@gmail.com
Date: Thu Jan 20 17:52:14 2011
Log: Added copy_objects() method to handle copying locked objects[] data
into a user-accessible objects[] array - prevents user from holding
objects_lock too long

http://code.google.com/p/joyos/source/detail?r=301

Modified:
/trunk/src/drivers/rf.c
/trunk/src/inc/rf.h

=======================================
--- /trunk/src/drivers/rf.c Wed Jan 19 20:04:13 2011
+++ /trunk/src/drivers/rf.c Thu Jan 20 17:52:14 2011
@@ -27,7 +27,9 @@

struct lock objects_lock;
volatile board_coord objects[32];
+volatile board_coord locked_objects[32];
volatile uint32_t position_microtime[32];
+volatile uint32_t locked_position_microtime[32];

#ifndef SIMULATE

@@ -290,10 +292,10 @@
}
acquire(&objects_lock);
int offset = (4*rx->seq_no) % 32;
- memcpy((char *)&objects[offset], rx->payload.coords,
sizeof(rx->payload.coords));
+ memcpy((char *)&locked_objects[offset], rx->payload.coords,
sizeof(rx->payload.coords));
uint32_t time_us = get_time_us();
for (uint8_t i=0;i<4;i++)
- position_microtime[i+offset] = time_us;
+ locked_position_microtime[i+offset] = time_us;
release(&objects_lock);
break;

@@ -326,6 +328,14 @@
break;
}
}
+
+//copy the locked_objects[] into the user-accessible objects[] array -
this way users cannot stall the rf thread by holding the objects_lock too
long
+void copy_objects(){
+ acquire(&objects_lock);
+ memcpy(&objects, &locked_objects, sizeof(locked_objects));
+ memcpy(&position_microtime, &locked_position_microtime,
sizeof(locked_position_microtime));
+ release(&objects_lock);
+}

// get a packet; return pipe number
uint8_t rf_get_packet(uint8_t *buf, uint8_t *size) {
=======================================
--- /trunk/src/inc/rf.h Wed Jan 19 20:04:13 2011
+++ /trunk/src/inc/rf.h Thu Jan 20 17:52:14 2011
@@ -12,7 +12,6 @@
* as well as retrieve information received over RF
*/

-extern struct lock objects_lock;
extern volatile board_coord objects[32];
extern volatile uint32_t position_microtime[32];

@@ -49,6 +48,8 @@
*/
uint8_t rf_send_packet(uint8_t address, uint8_t *data, uint8_t len);

+void copy_objects();
+
extern volatile uint8_t robot_id;

/**

Reply all
Reply to author
Forward
0 new messages