Page MenuHomec4science

main.h
No OneTemporary

File Metadata

Created
Tue, Apr 30, 10:49
/** \mainpage HRI board firmware documentation
* \section intro_sec Introduction
* This is the documentation of the HRI board firmware. You will find a
* description of the provided library and drivers. As all the hardware and
* software is very new, please do not hesitate to suggest improvements to the
* course assistants (Romain Baud, Philipp Hörler and Laurent Jenni).
*
* \section code_struct_sec Code structure
* The code is divided into 3 parts:
* - main: this is where the controllers and the communication protocol are
* implemented. The call of all the initialization functions is also made here.
* - library: all the algorithms, data structures that could be used at many
* places, are put into the library.
* - drivers: there is one driver per peripheral. All the hardware-specific
* code is wrapped into these files, so that the user does not have to use a
*
* One module (controller, communication, library or driver) is always splitted
* in two files, .h and .c, like in C++.
* @image html soft_architecture.png
*
* \section lib_how_to How to use the provided library
* For most of the driver/library modules, call x_Init() only once, when the
* program starts (typically in the main()). Then, you can call
* x_Step()/x_Set()/x_Get() everytime as needed, typically in the control
* functions called periodically (ctrl_RegulatePosition()...).
*
* See the "Modules" section of this documentation to see how they work.
*/
#ifndef __MAIN_H
#define __MAIN_H
#include "stm32f4_discovery.h"
#include <math.h>
#include "arm_math.h"
// Clocks configuration.
#define APB1_PRESCALER 4
#define APB2_PRESCALER 2
#define TIM_MULTIPLIER 2
// Interupt priority.
#define CURRENT_LOOP_IRQ_PRIORITY 1 // High freq loop, should not be interrupted.
#define CONTROL_LOOP_IRQ_PRIORITY 2
#define CODER_INDEX_IRQ_PRIORITY 2 // Useless, remove?
#define UART_RX_IRQ_PRIORIY 3
#define DATA_LOOP_IRQ_PRIORITY 4 // Streaming packets, lowest priority.
// Electrical parameters
#define STM_SUPPLY_VOLTAGE 3.3f // [V].
// Mechanical parameters.
#define REDUCTION_RATIO 15.0f
// Status register bit list.
#define STREG_0 ((uint32_t)0x00000001)
#define STREG_1 ((uint32_t)0x00000002)
#define REF_POS_INIT ((uint32_t)0x00000004) // 1 -> Ref position succesfully found
#define CALIBRE ((uint32_t)0x00000008) // 1 -> Calibration done
#define RUN_CURRENT_LOOP ((uint32_t)0x00000010) // 1 -> Current loop active (if motorDrv eneable but RUN_CURRENT_LOOP=false -> fixed 50% PWM on the motor)
#define UN_CONTROL_LOOP ((uint32_t)0x00000020) // 1 -> Control loop active
#define STREG_6 ((uint32_t)0x00000040)
#define STREG_7 ((uint32_t)0x00000080)
#define STREG_8 ((uint32_t)0x00000100)
#define DATA_UPSTREAM_ENB ((uint32_t)0x00000200) // 1 -> data upstream active
#define STREG_10 ((uint32_t)0x00000400)
#define RX_COMPLETED ((uint32_t)0x00000800) // 1 -> packet recieved
#define RX_ERROR ((uint32_t)0x00001000) // 1 -> last received packet incorrect
#define PROCESSING_REQUEST ((uint32_t)0x00002000) // 1 -> processing last received packet in progress (can not receive new data)
#define LAST_REQUEST_IGNORED ((uint32_t)0x00004000)
#define STREG_15 ((uint32_t)0x00008000)
#define STREG_16 ((uint32_t)0x00010000)
#define STREG_17 ((uint32_t)0x00020000)
#define STREG_18 ((uint32_t)0x00040000)
#define STREG_19 ((uint32_t)0x00080000)
#define STREG_20 ((uint32_t)0x00100000)
#define STREG_21 ((uint32_t)0x00200000)
#define STREG_22 ((uint32_t)0x00400000)
#define STREG_23 ((uint32_t)0x00800000)
#define INDEX_ERROR ((uint32_t)0x01000000) // 1 -> wrong step count over 1 rotation
#define STREG_25 ((uint32_t)0x02000000)
#define STREG_26 ((uint32_t)0x04000000)
#define STREG_27 ((uint32_t)0x08000000)
#define STREG_28 ((uint32_t)0x10000000)
#define STREG_29 ((uint32_t)0x20000000)
#define STREG_30 ((uint32_t)0x40000000)
#define STREG_31 ((uint32_t)0x80000000)
#endif

Event Timeline