![]() |
LMS 2012
|
#include "../../lms2012/source/lms2012.h"
#include "../../lms2012/source/am1808.h"
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/ioport.h>
#include <asm/gpio.h>
#include <asm/uaccess.h>
#include <linux/module.h>
#include <linux/miscdevice.h>
#include <linux/mm.h>
#include <linux/hrtimer.h>
#include <linux/init.h>
#include <asm/siginfo.h>
#include <linux/rcupdate.h>
#include <linux/uaccess.h>
#include <linux/debugfs.h>
#include <asm/io.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <mach/mux.h>
Go to the source code of this file.
Data Structures | |
struct | MOTOR |
struct | TACHOSAMPLES |
Macros | |
#define | HW_ID_SUPPORT |
#define | MODULE_NAME "pwm_module" |
#define | DEVICE1_NAME PWM_DEVICE |
#define | DEVICE2_NAME MOTOR_DEVICE |
#define | SOFT_TIMER_MS 2 |
#define | SOFT_TIMER_SETUP (SOFT_TIMER_MS * 1000000) |
#define | NO_OF_TACHO_SAMPLES 128 |
#define | NO_OF_OUTPUT_PORTS 4 |
#define | MAX_PWM_CNT (10000) |
#define | MAX_SPEED (100) |
#define | SPEED_PWMCNT_REL (100) |
#define | RAMP_FACTOR (1000) |
#define | MAX_SYNC_MOTORS (2) |
#define | COUNTS_PER_PULSE_LM 12800L |
#define | COUNTS_PER_PULSE_MM 8100L |
#define | TB_COUNT_UP 0x0 |
#define | TB_COUNT_FREEZE 0x3 |
#define | TB_DISABLE 0x0 |
#define | TB_ENABLE 0x4 |
#define | TB_SHADOW 0x0 |
#define | TB_IMMEDIATE 0x8 |
#define | TB_SYNC_DISABLE 0x30 |
#define | TB_HDIV1 0x0 |
#define | TB_DIV1 0x0 |
#define | TB_UP 0x2000 |
#define | CC_CTR_A_ZERO 0x0 |
#define | CC_CTR_B_ZERO 0x0 |
#define | CC_A_SHADOW 0x00 |
#define | CC_B_SHADOW 0x00 |
#define | TBCTL 0x0 |
#define | TBPHS 0x3 |
#define | TBCNT 0x4 |
#define | TBPRD 0x5 |
#define | CMPCTL 0x7 |
#define | CMPA 0x9 |
#define | CMPB 0xA |
#define | AQCTLA 0xB |
#define | AQCTLB 0xC |
#define | NON_INV 1 |
#define | INV -1 |
#define | IRQA_PINNO ((pOutputPortPin[Hw])[(0 * OUTPUT_PORT_PINS) + INT].Pin) |
#define | IRQB_PINNO ((pOutputPortPin[Hw])[(1 * OUTPUT_PORT_PINS) + INT].Pin) |
#define | IRQC_PINNO ((pOutputPortPin[Hw])[(2 * OUTPUT_PORT_PINS) + INT].Pin) |
#define | IRQD_PINNO ((pOutputPortPin[Hw])[(3 * OUTPUT_PORT_PINS) + INT].Pin) |
#define | OutputReadDir(port, pin) ((HwInvBits ^ (*pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].pGpio).in_data) & pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].Mask) |
#define | READDirA OutputReadDir(0,DIR) |
#define | READDirB OutputReadDir(1,DIR) |
#define | READDirC OutputReadDir(2,DIR) |
#define | READDirD OutputReadDir(3,DIR) |
#define | FLOATFaultPins |
#define | SETSleepPins |
#define | SETMotorType(Port, NewType) |
#define | SETAvgTachoCount(Port, Speed) |
#define | FREERunning24bittimer ((ULONG)((((ULONG*)(TIMER64P3))[TIM34])>>8)) |
#define | CLEARTachoArray(No) |
#define | OutputFloat(port, pin) |
#define | OutputRead(port, pin) ((*pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].pGpio).in_data & pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].Mask) |
#define | OutputHigh(port, pin) |
#define | OutputLow(port, pin) |
#define | EHRPWMClkDis |
#define | EHRPWMClkEna |
#define | STOPPwm |
#define | SETPwmFreqKHz(KHz) |
#define | SETUPPwmModules |
#define | READIntA OutputRead(0,INT) |
#define | READIntB OutputRead(1,INT) |
#define | READIntC OutputRead(2,INT) |
#define | READIntD OutputRead(3,INT) |
#define | SHM_LENGTH (sizeof(MotorData)) |
#define | NPAGES ((SHM_LENGTH + PAGE_SIZE - 1) / PAGE_SIZE) |
Functions | |
UBYTE | dCalculateSpeed (UBYTE No, SBYTE *pSpeed) |
dCalculateSpeed More... | |
void | SetGpioRisingIrq (UBYTE PinNo, irqreturn_t(*IntFuncPtr)(int, void *)) |
void | GetSyncDurationCnt (SLONG *pCount0, SLONG *pCount1) |
void | CheckforEndOfSync (void) |
void | SetDutyMA (ULONG Duty) |
void | SetDutyMB (ULONG Duty) |
void | SetDutyMC (ULONG Duty) |
void | SetDutyMD (ULONG Duty) |
MODULE_LICENSE ("GPL") | |
MODULE_AUTHOR ("The LEGO Group") | |
MODULE_DESCRIPTION (MODULE_NAME) | |
MODULE_SUPPORTED_DEVICE (DEVICE1_NAME) | |
module_init (ModuleInit) | |
module_exit (ModuleExit) | |
void | CheckSpeedPowerLimits (SBYTE *pCheckVal) |
UBYTE | CheckLessThanSpecial (SLONG Param1, SLONG Param2, SLONG Inv) |
void | IncSpeed (SBYTE Dir, SBYTE *pSpeed) |
void | DecSpeed (SBYTE Dir, SBYTE *pSpeed) |
void | SetDirRwd (UBYTE Port) |
void | SetDirFwd (UBYTE Port) |
void | SetBrake (UBYTE Port) |
void | SetCoast (UBYTE Port) |
UWORD | GetTachoDir (UBYTE Port) |
UWORD | GetTachoInt (UBYTE Port) |
void | SetPower (UBYTE Port, SLONG Power) |
void | SetRegulationPower (UBYTE Port, SLONG Power) |
void | ClearPIDParameters (UBYTE No) |
void | StepPowerStopMotor (UBYTE No, SLONG AdjustTachoValue) |
StepPowerStopMotor. More... | |
UBYTE | StepSpeedCheckTachoCntUp (UBYTE No) |
StepSpeedCheckTachoCntUp. More... | |
UBYTE | StepSpeedCheckTachoCntConst (UBYTE No, SLONG AdjustTachoValue) |
StepPowerCheckTachoCntConst. More... | |
void | StepSpeedCheckTachoCntDown (UBYTE No, SLONG AdjustTachoValue) |
StepSpeedCheckTachoCntDown. More... | |
UBYTE | StepPowerCheckTachoCntUp (UBYTE No) |
StepPowerCheckTachoCntUp. More... | |
UBYTE | StepPowerCheckTachoCntConst (UBYTE No, SLONG AdjustTachoValue) |
StepPowerCheckTachoCntConst. More... | |
void | StepPowerCheckTachoCntDown (UBYTE No, SLONG AdjustTachoValue) |
StepPowerCheckTachoCntDown. More... | |
void | dRegulateSpeed (UBYTE No) |
dRegulateSpeed More... | |
void | BrakeMotor (UBYTE No, SLONG TachoCnt) |
UBYTE | RampDownToBrake (UBYTE No, SLONG CurrentCnt, SLONG TargetCnt, SLONG Dir) |
void | CalcRampDownFactor (UBYTE No, ULONG CurrentPower, ULONG Counts) |
void | GetCompareCounts (UBYTE No, SLONG *Counts, SLONG *CompareCounts) |
void | StopAndBrakeMotor (UBYTE MotorNo) |
void | StopAndFloatMotor (UBYTE MotorNo) |
void | FloatSyncedMotors (void) |
void | TestAndFloatSyncedMotors (UBYTE MotorBitField, UBYTE SyncCmd) |
void | GetPeriphealBasePtr (ULONG Address, ULONG Size, ULONG **Ptr) |
GetPeriphealBasePtr. More... | |
void | SetGpio (int Pin) |
void | InitGpio (void) |
module_param (HwId, charp, 0) | |
Variables | |
int | Hw = 0 |
int | HwInvBits = 0 |
INPIN | EP2_OutputPortPin [][OUTPUT_PORT_PINS] |
INPIN | FINALB_OutputPortPin [][OUTPUT_PORT_PINS] |
INPIN | FINAL_OutputPortPin [][OUTPUT_PORT_PINS] |
INPIN * | pOutputPortPin [] |
#define CLEARTachoArray | ( | No | ) |
#define EHRPWMClkDis |
#define EHRPWMClkEna |
#define FLOATFaultPins |
#define IRQA_PINNO ((pOutputPortPin[Hw])[(0 * OUTPUT_PORT_PINS) + INT].Pin) |
#define IRQB_PINNO ((pOutputPortPin[Hw])[(1 * OUTPUT_PORT_PINS) + INT].Pin) |
#define IRQC_PINNO ((pOutputPortPin[Hw])[(2 * OUTPUT_PORT_PINS) + INT].Pin) |
#define IRQD_PINNO ((pOutputPortPin[Hw])[(3 * OUTPUT_PORT_PINS) + INT].Pin) |
#define NPAGES ((SHM_LENGTH + PAGE_SIZE - 1) / PAGE_SIZE) |
#define OutputFloat | ( | port, | |
pin | |||
) |
#define OutputHigh | ( | port, | |
pin | |||
) |
#define OutputLow | ( | port, | |
pin | |||
) |
#define OutputRead | ( | port, | |
pin | |||
) | ((*pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].pGpio).in_data & pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].Mask) |
#define OutputReadDir | ( | port, | |
pin | |||
) | ((HwInvBits ^ (*pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].pGpio).in_data) & pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].Mask) |
#define READDirA OutputReadDir(0,DIR) |
#define READDirB OutputReadDir(1,DIR) |
#define READDirC OutputReadDir(2,DIR) |
#define READDirD OutputReadDir(3,DIR) |
#define READIntA OutputRead(0,INT) |
#define READIntB OutputRead(1,INT) |
#define READIntC OutputRead(2,INT) |
#define READIntD OutputRead(3,INT) |
#define SETAvgTachoCount | ( | Port, | |
Speed | |||
) |
#define SETMotorType | ( | Port, | |
NewType | |||
) |
#define SETPwmFreqKHz | ( | KHz | ) |
#define SETSleepPins |
#define SOFT_TIMER_SETUP (SOFT_TIMER_MS * 1000000) |
#define STOPPwm |
anonymous enum |
anonymous enum |
anonymous enum |
anonymous enum |
enum OutputPortPins |
dCalculateSpeed
- Medium Motor - Maximum speed of the medium motor is approximately 1,25mS per tacho pulse (low + high period) resulting in minimum timer value og: 1,25mS / (1/(33MHz / 256)) = 162 (approximately) Because 1 sample is based on only half a period minimum speed is 162/2 = 81. - Minimum speed of the medium motor is a factor of 100 less than max. speed max. speed timer ticks * 100 => 162 * 100 = 16200 T64 timer ticks Because 1 sample is based on only half a period minimum speed is 16200/2 = 8100. - Actual speed is then calculated as: - Medium motor: 8100 * number of samples / actual time elapsed for number of samples - Large motor: 12800 * number of samples / actual time elapsed for number of samples
| | | | | | | | | | | | | | ----— ----— ----— — DIRx signal
---- ------ ------ ------ INTx signal | | | | | | | | | | | | ------- ------- ------- ^ ^ ^ ^ ^ ^ | | | | | | | Timer | Timer | Timer | + | + | + | Counter | Counter | Counter | | | Timer Timer Timer + + + Counter Counter Counter
Direction change
DirChgPtr variable is used to indicate how many timer samples have been sampled since direction has been changed. DirChgPtr is set to 0 when tacho interrupt detects direction change and then it is counted up for every timer sample. So when DirChgPtr has the value of 2 then there must be 2 timer samples in the the same direction available.
| | | | | | | | | | | | | | | | ----— ----— ----— ----— DIRx signal
------ ------------- ------ ------INTx signal | | | | | | | | | | | | ------- ------- ------- ^ ^ ^ ^ ^ ^ | | | | | | Timer | Timer | Timer | + | + | + | Counter | Counter | Counter | + | + | + | DirChgPtr++ | DirChgPtr=0 |DirChgPtr++ | Timer Timer Timer + + + Counter Counter Counter + + + DirChgPtr++ DirChgPtr++ DirChgPtr++ ---- ------ ------ ---- | | | | | | | | | | | | ------- ------------- ------- DIRx signal ------ ------ ------ ------ INTx signal | | | | | | | | | | | | | | ------- ------- ------- ---- ^ ^ ^ ^ ^ ^ ^ | | | | | | | Timer | Timer | Timer | Timer + | + | + | + Counter | Counter | Counter | Counter + | + | + | + DirChgPtr++| DirChgPtr++| DirChgPtr++| DirChgPtr++ Timer Timer Timer + + + Counter Counter Counter + + + DirChgPtr++ DirChgPtr=0 DirChgPtr++
void dRegulateSpeed | ( | UBYTE | No | ) |
MODULE_AUTHOR | ( | "The LEGO Group" | ) |
MODULE_DESCRIPTION | ( | MODULE_NAME | ) |
module_exit | ( | ModuleExit | ) |
module_init | ( | ModuleInit | ) |
MODULE_LICENSE | ( | "GPL" | ) |
module_param | ( | HwId | , |
charp | , | ||
0 | |||
) |
MODULE_SUPPORTED_DEVICE | ( | DEVICE1_NAME | ) |
void SetGpioRisingIrq | ( | UBYTE | PinNo, |
irqreturn_t(*)(int, void *) | IntFuncPtr | ||
) |
INPIN EP2_OutputPortPin[][OUTPUT_PORT_PINS] |
INPIN FINAL_OutputPortPin[][OUTPUT_PORT_PINS] |
INPIN FINALB_OutputPortPin[][OUTPUT_PORT_PINS] |
INPIN* pOutputPortPin[] |