From: <hoe...@us...> - 2009-03-29 20:08:35
|
Revision: 2729 http://reprap.svn.sourceforge.net/reprap/?rev=2729&view=rev Author: hoekstar Date: 2009-03-29 20:08:29 +0000 (Sun, 29 Mar 2009) Log Message: ----------- hacked on drive ra bit more. micros as feedrate, hacked on circularbuffer. Modified Paths: -------------- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/CircularBuffer2.h trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Configuration.h trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/PacketProcessor.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Timer1.pde Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/CircularBuffer2.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/CircularBuffer2.h 2009-03-29 16:22:01 UTC (rev 2728) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/CircularBuffer2.h 2009-03-29 20:08:29 UTC (rev 2729) @@ -19,11 +19,12 @@ class CircularBuffer { private: uint8_t* buffer; - volatile size_t capacity; - volatile size_t head; - volatile size_t tail; + uint16_t capacity; + uint16_t head; + uint16_t tail; + uint16_t size; public: - CircularBuffer(size_t capacity, uint8_t* pBuf) { + CircularBuffer(uint16_t capacity, uint8_t* pBuf) { this->capacity = capacity; buffer = pBuf; clear(); @@ -35,35 +36,38 @@ /// Reset buffer. (Note: does not zero data.) void clear() { head = tail = 0; + size = 0; } - uint8_t operator[](const size_t i) { - const size_t idx = (i + head) % capacity; + uint8_t operator[](uint16_t i) { + const uint16_t idx = (i + head) % capacity; return buffer[idx]; } /// Check remaining capacity of this vector. - size_t remainingCapacity() { - return capacity - size(); + uint16_t remainingCapacity() { + return capacity - size; } /// Get the current number of elements in the buffer. - size_t size() { - return (capacity + head - tail) % capacity; + uint16_t size() { + return size; } /// Append a character to the end of the circular buffer. void append(const uint8_t datum) { - size_t i = (head + 1) % capacity; + uint16_t i = (head + 1) % capacity; // if we should be storing the received character into the location // just before the tail (meaning that the head would advance to the // current location of the tail), we're about to overflow the buffer // and so we don't write the character or advance the head. - if (i != tail) { + if (size + 1 <= capacity) + { buffer[head] = datum; head = i; + size++; } } @@ -80,12 +84,13 @@ /// Remove and return a character from the start of the /// circular buffer. const uint8_t remove_8() { - if (head == tail) + if (size == 0) return 0; else { uint8_t c = buffer[tail]; tail = (tail + 1) % capacity; + size--; return c; } } Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Configuration.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Configuration.h 2009-03-29 16:22:01 UTC (rev 2728) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Configuration.h 2009-03-29 20:08:29 UTC (rev 2729) @@ -152,5 +152,5 @@ // Explicitly allocate memory at compile time for buffer. #define COMMAND_BUFFER_SIZE 256 #define POINT_QUEUE_SIZE 32 -#define POINT_SIZE 15 // 4 + 4 + 4 + 3 = 15 +#define POINT_SIZE 16 // 4 + 4 + 4 + 4 = 16 #define MAX_PACKET_LENGTH 32 Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/PacketProcessor.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/PacketProcessor.pde 2009-03-29 16:22:01 UTC (rev 2728) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/PacketProcessor.pde 2009-03-29 20:08:29 UTC (rev 2729) @@ -208,8 +208,7 @@ long x; long y; long z; - byte prescaler; - unsigned int count; + unsigned long step_delay; byte cmd; //do we have any commands? @@ -241,27 +240,13 @@ switch(cmd) { //TODO: TEST THOROUGHLY - case HOST_CMD_QUEUE_POINT_INC: - - x = (int)commandBuffer.remove_16(); - y = (int)commandBuffer.remove_16(); - z = (int)commandBuffer.remove_16(); - prescaler = commandBuffer.remove_8(); - count = commandBuffer.remove_16(); - - //queue_incremental_point(x, y, z, prescaler, count); - - break; - - //TODO: TEST THOROUGHLY case HOST_CMD_QUEUE_POINT_ABS: x = (long)commandBuffer.remove_32(); y = (long)commandBuffer.remove_32(); z = (long)commandBuffer.remove_32(); - prescaler = commandBuffer.remove_8(); - count = commandBuffer.remove_16(); + step_delay = (unsigned long)commandBuffer.remove_32(); - queue_absolute_point(x, y, z, prescaler, count); + queue_absolute_point(x, y, z, step_delay); break; @@ -321,7 +306,6 @@ break; - //TODO: TEST case HOST_CMD_DELAY: wait_until_target_reached(); //dont want to get hasty. @@ -329,7 +313,6 @@ delay(commandBuffer.remove_32()); break; - //TODO: TEST case HOST_CMD_CHANGE_TOOL: wait_until_target_reached(); //dont want to get hasty. @@ -337,7 +320,6 @@ select_tool(commandBuffer.remove_8()); break; - //TODO: TEST case HOST_CMD_WAIT_FOR_TOOL: wait_until_target_reached(); //dont want to get hasty. @@ -360,7 +342,6 @@ } break; - //WORKS case HOST_CMD_TOOL_COMMAND: wait_until_target_reached(); //dont want to get hasty. Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde 2009-03-29 16:22:01 UTC (rev 2728) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde 2009-03-29 20:08:29 UTC (rev 2729) @@ -274,8 +274,7 @@ //start the move! disableTimer1Interrupt(); - setTimer1Resolution(pointBuffer.remove_8()); - setTimer1Ceiling(pointBuffer.remove_16()); + setTimer1Micros(pointBuffer.remove_32()); enableTimer1Interrupt(); } } @@ -450,7 +449,7 @@ } //queue a point for us to move to -void queue_incremental_point(int x, int y, int z, byte prescaler, unsigned int count) +void queue_incremental_point(int x, int y, int z, unsigned long micros) { //where we goin? long abs_x = eventual_steps.x + x; @@ -458,11 +457,11 @@ long abs_z = eventual_steps.z + z; //okay, send us there. - queue_absolute_point(abs_x, abs_y, abs_z, prescaler, count); + queue_absolute_point(abs_x, abs_y, abs_z, micros); } //queue a point for us to move to -void queue_absolute_point(long x, long y, long z, byte prescaler, unsigned int count) +void queue_absolute_point(long x, long y, long z, unsigned long micros) { //this is the final position. eventual_steps.x = x; @@ -480,18 +479,12 @@ pointBuffer.append_32(x); pointBuffer.append_32(y); pointBuffer.append_32(z); + pointBuffer.append_32(micros); - // prescaler - pointBuffer.append(prescaler); - - // counter - pointBuffer.append_16(count); - //first point? give us the right timer. if (!firstPoint) { - setTimer1Resolution(prescaler); - setTimer1Ceiling(count); + setTimer1Micros(micros); //turn our interrupt on. enableTimer1Interrupt(); Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Timer1.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Timer1.pde 2009-03-29 16:22:01 UTC (rev 2728) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Timer1.pde 2009-03-29 20:08:29 UTC (rev 2729) @@ -94,6 +94,14 @@ return 5; } +inline void setTimer1Micros(unsigned long micros) +{ + //16 ticks in a microsecond. + unsigned long ticks = micros * 16; + + setTimer1Ticks(ticks); +} + inline void setTimer1Ticks(unsigned long ticks) { // ticks is the delay between interrupts in 62.5 nanosecond ticks. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |