yarf 0.1
Yet Another RepRap Firmware
Defines | Functions | Variables
src/movement/block_handler.c File Reference

The block handler component is responsible for executing blocks placed into the planning queue by the planner component. More...

#include "block_handler.h"
#include "yarf.h"
#include "movement/planner_queue.h"
#include "hardware/steppers.h"
#include "hardware/endstops.h"
#include "hardware/usart.h"
#include "scheduling/realtime_timer.h"
#include "util/math.h"
#include "advance.h"
#include <stdlib.h>
#include <util/delay.h>
#include <util/atomic.h>

Go to the source code of this file.

Defines

#define BLOCK_HANDLER_START_DELAY_TICKS   1L
 The number of timer ticks to pass as the delay when starting the block handler thread.

Functions

static void block_progress_init (void)
 Initializes the bp variable.
static void enable_steppers (void)
 Enables each of the stepper motors that needs to be stepped for the current block.
static void disable_steppers (void)
 Disables each of the stepper motors that need not be held after executing a block.
static void block_finished (void)
 Cleans up some data structures after finishing the execution of a block.
static void cancel_block (void)
 Cancels the execution of the current block in execution.
static void update_advance (void)
 Updates the current block's advance field, if the advance pressure management system is enabled.
static void block_handler_run (void)
 Main block handler implementation.
void block_handler_init (void)
 Initializes the block handler component.
void block_handler_start (void)
 Starts the block handler thread.
void block_handler_pause (void)
 Pauses the block handler thread.
void block_handler_stop (void)
 Stops the block handler thread.
bool block_handler_running (void)
 Returns whether the block handler thread is running.

Variables

static bool handler_running
 Indicates whether the block handler thread is running.
static realtime_task_t handler_task
 Structure representing the block handler task.
static block_tb
 Pointer to the block currently being executed.
static steps_t counter [NUM_AXES]
 Counter for each axis, used to calculate whether an axis' stepper motor needs to take a step in the block_handler_run procedure.

Detailed Description

The block handler component is responsible for executing blocks placed into the planning queue by the planner component.

Author:
Pieter Agten (pieter.agten@gmail.com)
Date:
23 sep 2011

Definition in file block_handler.c.


Function Documentation

void block_handler_init ( void  )

Initializes the block handler component.

Needs to be called only once, on boot. Note that this does not actually start the block handler thread.

See also:
block_handler_start

Definition at line 427 of file block_handler.c.

void block_handler_pause ( void  )

Pauses the block handler thread.

This stops the block handler procedure from being executed, so no more steps will be taken until the thread is restarted. Note however that this will not cancel the current block. So the block handler thread will continue with the current block when it is restarted.

Definition at line 452 of file block_handler.c.

static void block_handler_run ( void  ) [static]

Main block handler implementation.

This procedure is called from a seperate thread (an interrupt) whenever the real-time timer rings. It makes the stepper motors take one linear step of the current block on each call. If there is no current block, it first tries to get one from the planning queue. It calculates which stepper motors need to be stepped on each call. After stepping those stepper motors, the procedure calculates how many timer ticks need to pass before the step must occur and reschedules the real-time timer accordingly. The number of timer ticks between steps changes during acceleration and deceleration.

Before this procedure steps any one of the stepper motors, it checks whether the end stop of that motor in the specified direction is pressed and, if so, cancels the block being executed and calls the collision_handler function pointer of the block.

Definition at line 269 of file block_handler.c.

bool block_handler_running ( void  )

Returns whether the block handler thread is running.

Returns:
Whether the block handler thread is running.

Definition at line 477 of file block_handler.c.

void block_handler_start ( void  )

Starts the block handler thread.

Note that the block handler thread stops automatically when the planning queue is empty.

Definition at line 443 of file block_handler.c.

void block_handler_stop ( void  )

Stops the block handler thread.

This stops the block handler procedure from being executed and cancels the current block. The block handler thread will continue with the next block in the planning queue when it is restarted.

Definition at line 463 of file block_handler.c.

static void block_progress_init ( void  ) [static]

Initializes the bp variable.

Called whenever a new block is taken from the planning queue to be executed.

Definition at line 109 of file block_handler.c.

static void enable_steppers ( void  ) [inline, static]

Enables each of the stepper motors that needs to be stepped for the current block.

Called whenever a new block is taken from the planning queue to be executed.

Definition at line 123 of file block_handler.c.


Variable Documentation

Structure representing the block handler task.

This structure is passed to the real-time timer, so it will know what function to execute when the timer rings.

Definition at line 61 of file block_handler.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines