LMS 2012
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
d_pwm.c File Reference
#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)
 

Enumerations

enum  {
  SAMPLES_BELOW_SPEED_25 = 0, SAMPLES_SPEED_25_50 = 1, SAMPLES_SPEED_50_75 = 2, SAMPLES_ABOVE_SPEED_75 = 3,
  NO_OF_SAMPLE_STEPS = 4
}
 
enum  { CFGCHIP1 = 0x60 }
 
enum  { TBCLKSYNC = 0x00001000 }
 
enum  {
  REVID = 0, EMUMGT = 1, GPINTGPEN = 2, GPDATGPDIR = 3,
  TIM12 = 4, TIM34 = 5, PRD12 = 6, PRD34 = 7,
  TCR = 8, TGCR = 9, WDTCR = 10, NOTUSED1 = 11,
  NOTUSED2 = 12, REL12 = 13, REL34 = 14, CAP12 = 15,
  CAP34 = 16, NOTUSED3 = 17, NOTUSED4 = 18, NOTUSED5 = 19,
  NOTUSED6 = 20, NOTUSED7 = 21, NOTUSED8 = 22, INTCTLSTAT = 23,
  CMP0 = 24, CMP1 = 25, CMP2 = 26, CMP3 = 27,
  CMP4 = 28, CMP5 = 39, CMP6 = 30, CMP7 = 31
}
 
enum  {
  TSCTR = 0, CTRPHS = 2, CAP1 = 4, CAP2 = 6,
  CAP3 = 8, CAP4 = 10, ECCTL1 = 20, ECCTL2 = 21,
  ECEINT = 22, ECFLG = 23, ECCLR = 24, ECFRC = 25,
  ECAP_REVID = 46
}
 
enum  { FORWARD, BACKWARD, BRAKE, COAST }
 
enum  {
  UNLIMITED_UNREG, UNLIMITED_REG, LIMITED_REG_STEPUP, LIMITED_REG_STEPCONST,
  LIMITED_REG_STEPDOWN, LIMITED_UNREG_STEPUP, LIMITED_UNREG_STEPCONST, LIMITED_UNREG_STEPDOWN,
  LIMITED_REG_TIMEUP, LIMITED_REG_TIMECONST, LIMITED_REG_TIMEDOWN, LIMITED_UNREG_TIMEUP,
  LIMITED_UNREG_TIMECONST, LIMITED_UNREG_TIMEDOWN, LIMITED_STEP_SYNC, LIMITED_TURN_SYNC,
  LIMITED_DIFF_TURN_SYNC, SYNCED_SLAVE, RAMP_DOWN_SYNC, HOLD,
  BRAKED, STOP_MOTOR, IDLE
}
 
enum  { UNUSED_SYNC_MOTOR = 0xFF }
 
enum  OutputPortPins {
  OUTPUT_PORT_PIN1, OUTPUT_PORT_PIN2, OUTPUT_PORT_PIN5W, OUTPUT_PORT_PIN5R,
  OUTPUT_PORT_PIN6, OUTPUT_PORT_PINS, OUTPUT_PORT_VALUE, PWM,
  DIR0, DIR1, INT, DIR,
  SLEEP, FAULT, OUTPUT_PORT_PINS
}
 

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]
 
INPINpOutputPortPin []
 

Macro Definition Documentation

#define AQCTLA   0xB

Definition at line 99 of file d_pwm.c.

#define AQCTLB   0xC

Definition at line 100 of file d_pwm.c.

#define CC_A_SHADOW   0x00

Definition at line 89 of file d_pwm.c.

#define CC_B_SHADOW   0x00

Definition at line 90 of file d_pwm.c.

#define CC_CTR_A_ZERO   0x0

Definition at line 87 of file d_pwm.c.

#define CC_CTR_B_ZERO   0x0

Definition at line 88 of file d_pwm.c.

#define CLEARTachoArray (   No)
Value:
{\
Motor[No].DirChgPtr = 0;\
memset(&TachoSamples[No], 0, sizeof(TACHOSAMPLES));\
}

Definition at line 622 of file d_pwm.c.

#define CMPA   0x9

Definition at line 97 of file d_pwm.c.

#define CMPB   0xA

Definition at line 98 of file d_pwm.c.

#define CMPCTL   0x7

Definition at line 96 of file d_pwm.c.

#define COUNTS_PER_PULSE_LM   12800L

Definition at line 56 of file d_pwm.c.

#define COUNTS_PER_PULSE_MM   8100L

Definition at line 57 of file d_pwm.c.

#define DEVICE1_NAME   PWM_DEVICE

Definition at line 34 of file d_pwm.c.

#define DEVICE2_NAME   MOTOR_DEVICE

Definition at line 35 of file d_pwm.c.

#define EHRPWMClkDis
Value:
{\
}
#define TB_COUNT_FREEZE
Definition: d_pwm.c:75
#define TB_SYNC_DISABLE
Definition: d_pwm.c:80
#define TB_DISABLE
Definition: d_pwm.c:76
#define TB_HDIV1
Definition: d_pwm.c:81
#define TB_DIV1
Definition: d_pwm.c:82
#define TB_UP
Definition: d_pwm.c:83
#define TBCTL
Definition: d_pwm.c:92
#define TB_SHADOW
Definition: d_pwm.c:78

Definition at line 644 of file d_pwm.c.

#define EHRPWMClkEna
Value:
{\
iowrite32((ioread32(&SYSCFG0[CFGCHIP1]) | TBCLKSYNC),&SYSCFG0[CFGCHIP1]); /*This is the clock to all eHRPWM's*/\
}
#define REGLock
Definition: am1808.h:235
#define REGUnlock
Definition: am1808.h:230
#define TB_SYNC_DISABLE
Definition: d_pwm.c:80
#define TB_DISABLE
Definition: d_pwm.c:76
#define TB_HDIV1
Definition: d_pwm.c:81
#define TB_DIV1
Definition: d_pwm.c:82
#define TB_UP
Definition: d_pwm.c:83
#define TBCTL
Definition: d_pwm.c:92
#define TB_COUNT_UP
Definition: d_pwm.c:74
#define TB_SHADOW
Definition: d_pwm.c:78

Definition at line 648 of file d_pwm.c.

#define FLOATFaultPins
Value:
{\
if (((pOutputPortPin[Hw])[(0 * OUTPUT_PORT_PINS) + FAULT].Pin) != -1)\
{\
(*pOutputPortPin[Hw][(0 * OUTPUT_PORT_PINS) + FAULT].pGpio).dir |= pOutputPortPin[Hw][(0 * OUTPUT_PORT_PINS) + FAULT].Mask;\
}\
if (((pOutputPortPin[Hw])[(2 * OUTPUT_PORT_PINS) + FAULT].Pin) != -1)\
{\
(*pOutputPortPin[Hw][(2 * OUTPUT_PORT_PINS) + FAULT].pGpio).dir |= pOutputPortPin[Hw][(2 * OUTPUT_PORT_PINS) + FAULT].Mask;\
}\
}
INPIN * pOutputPortPin[]
Definition: d_pwm.c:467
Definition: d_pwm.c:331
int Hw
Definition: d_pwm.c:30

Definition at line 553 of file d_pwm.c.

#define FREERunning24bittimer   ((ULONG)((((ULONG*)(TIMER64P3))[TIM34])>>8))

Definition at line 620 of file d_pwm.c.

#define HW_ID_SUPPORT

Definition at line 25 of file d_pwm.c.

#define INV   -1

Definition at line 172 of file d_pwm.c.

#define IRQA_PINNO   ((pOutputPortPin[Hw])[(0 * OUTPUT_PORT_PINS) + INT].Pin)

Definition at line 336 of file d_pwm.c.

#define IRQB_PINNO   ((pOutputPortPin[Hw])[(1 * OUTPUT_PORT_PINS) + INT].Pin)

Definition at line 337 of file d_pwm.c.

#define IRQC_PINNO   ((pOutputPortPin[Hw])[(2 * OUTPUT_PORT_PINS) + INT].Pin)

Definition at line 338 of file d_pwm.c.

#define IRQD_PINNO   ((pOutputPortPin[Hw])[(3 * OUTPUT_PORT_PINS) + INT].Pin)

Definition at line 339 of file d_pwm.c.

#define MAX_PWM_CNT   (10000)

Definition at line 47 of file d_pwm.c.

#define MAX_SPEED   (100)

Definition at line 48 of file d_pwm.c.

#define MAX_SYNC_MOTORS   (2)

Definition at line 51 of file d_pwm.c.

#define MODULE_NAME   "pwm_module"

Definition at line 33 of file d_pwm.c.

#define NO_OF_OUTPUT_PORTS   4

Definition at line 45 of file d_pwm.c.

#define NO_OF_TACHO_SAMPLES   128

Definition at line 44 of file d_pwm.c.

#define NON_INV   1

Definition at line 171 of file d_pwm.c.

#define NPAGES   ((SHM_LENGTH + PAGE_SIZE - 1) / PAGE_SIZE)

Definition at line 4095 of file d_pwm.c.

#define OutputFloat (   port,
  pin 
)
Value:
{\
(*pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].pGpio).dir |= pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].Mask;\
}
INPIN * pOutputPortPin[]
Definition: d_pwm.c:467
int Hw
Definition: d_pwm.c:30

Definition at line 627 of file d_pwm.c.

#define OutputHigh (   port,
  pin 
)
Value:
{\
(*pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].pGpio).set_data = pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].Mask;\
(*pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].pGpio).dir &= ~pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].Mask;\
}
INPIN * pOutputPortPin[]
Definition: d_pwm.c:467
int Hw
Definition: d_pwm.c:30

Definition at line 633 of file d_pwm.c.

#define OutputLow (   port,
  pin 
)
Value:
{\
(*pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].pGpio).clr_data = pOutputPortPin[Hw][(OUTPUT_PORT_PINS * port) + pin].Mask;\
(*pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].pGpio).dir &= ~pOutputPortPin[Hw][(OUTPUT_PORT_PINS * port) + pin].Mask;\
}
INPIN * pOutputPortPin[]
Definition: d_pwm.c:467
int Hw
Definition: d_pwm.c:30

Definition at line 638 of file d_pwm.c.

#define OutputRead (   port,
  pin 
)    ((*pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].pGpio).in_data & pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].Mask)

Definition at line 631 of file d_pwm.c.

#define OutputReadDir (   port,
  pin 
)    ((HwInvBits ^ (*pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].pGpio).in_data) & pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].Mask)

Definition at line 475 of file d_pwm.c.

#define RAMP_FACTOR   (1000)

Definition at line 50 of file d_pwm.c.

#define READDirA   OutputReadDir(0,DIR)

Definition at line 476 of file d_pwm.c.

#define READDirB   OutputReadDir(1,DIR)

Definition at line 477 of file d_pwm.c.

#define READDirC   OutputReadDir(2,DIR)

Definition at line 478 of file d_pwm.c.

#define READDirD   OutputReadDir(3,DIR)

Definition at line 479 of file d_pwm.c.

#define READIntA   OutputRead(0,INT)

Definition at line 703 of file d_pwm.c.

#define READIntB   OutputRead(1,INT)

Definition at line 704 of file d_pwm.c.

#define READIntC   OutputRead(2,INT)

Definition at line 705 of file d_pwm.c.

#define READIntD   OutputRead(3,INT)

Definition at line 706 of file d_pwm.c.

#define SETAvgTachoCount (   Port,
  Speed 
)
Value:
{\
if (Speed > 80)\
{\
AVG_TACHO_COUNTS[Port] = SamplesPerSpeed[Port][3];\
AVG_COUNTS[Port] = SamplesPerSpeed[Port][3] * CountsPerPulse[Port];\
}\
else\
{\
if (Speed > 60)\
{\
AVG_TACHO_COUNTS[Port] = SamplesPerSpeed[Port][2];\
AVG_COUNTS[Port] = SamplesPerSpeed[Port][2] * CountsPerPulse[Port];\
}\
else\
{\
if (Speed > 40)\
{\
AVG_TACHO_COUNTS[Port] = SamplesPerSpeed[Port][1];\
AVG_COUNTS[Port] = SamplesPerSpeed[Port][1] * CountsPerPulse[Port];\
}\
else\
{\
AVG_TACHO_COUNTS[Port] = SamplesPerSpeed[Port][0];\
AVG_COUNTS[Port] = SamplesPerSpeed[Port][0] * CountsPerPulse[Port];\
}\
}\
}\
}

Definition at line 591 of file d_pwm.c.

#define SETMotorType (   Port,
  NewType 
)
Value:
{\
Motor[Port].Type = NewType;\
if (TYPE_MINITACHO == NewType)\
{\
CountsPerPulse[Port] = COUNTS_PER_PULSE_MM;\
SamplesPerSpeed[Port] = SamplesMediumMotor;\
}\
else\
{\
CountsPerPulse[Port] = COUNTS_PER_PULSE_LM;\
SamplesPerSpeed[Port] = SamplesLargeMotor;\
}\
}
#define COUNTS_PER_PULSE_LM
Definition: d_pwm.c:56
#define COUNTS_PER_PULSE_MM
Definition: d_pwm.c:57
Device is a mini tacho motor.
Definition: lms2012.h:572

Definition at line 577 of file d_pwm.c.

#define SETPwmFreqKHz (   KHz)
Value:
{\
eHRPWM1[TBPRD] = KHz; /* For Motor A and Motor B */\
eCAP0[CAP1] = KHz; /* For Motor C */\
eCAP1[CAP1] = KHz; /* For Motor D */\
}
#define TBPRD
Definition: d_pwm.c:95
Definition: d_pwm.c:157

Definition at line 664 of file d_pwm.c.

#define SETSleepPins
Value:
{\
if (((pOutputPortPin[Hw])[(0 * OUTPUT_PORT_PINS) + SLEEP].Pin) != -1)\
{\
(*pOutputPortPin[Hw][(0 * OUTPUT_PORT_PINS) + SLEEP].pGpio).set_data = pOutputPortPin[Hw][(0 * OUTPUT_PORT_PINS) + SLEEP].Mask;\
(*pOutputPortPin[Hw][(0 * OUTPUT_PORT_PINS) + SLEEP].pGpio).dir &= ~pOutputPortPin[Hw][(0 * OUTPUT_PORT_PINS) + SLEEP].Mask;\
}\
if (((pOutputPortPin[Hw])[(2 * OUTPUT_PORT_PINS) + SLEEP].Pin) != -1)\
{\
(*pOutputPortPin[Hw][(2 * OUTPUT_PORT_PINS) + SLEEP].pGpio).set_data = pOutputPortPin[Hw][(2 * OUTPUT_PORT_PINS) + SLEEP].Mask;\
(*pOutputPortPin[Hw][(2 * OUTPUT_PORT_PINS) + SLEEP].pGpio).dir &= ~pOutputPortPin[Hw][(2 * OUTPUT_PORT_PINS) + SLEEP].Mask;\
}\
}
INPIN * pOutputPortPin[]
Definition: d_pwm.c:467
int Hw
Definition: d_pwm.c:30
Definition: d_pwm.c:330

Definition at line 564 of file d_pwm.c.

#define SETUPPwmModules

Definition at line 670 of file d_pwm.c.

#define SHM_LENGTH   (sizeof(MotorData))

Definition at line 4094 of file d_pwm.c.

#define SOFT_TIMER_MS   2

Definition at line 38 of file d_pwm.c.

#define SOFT_TIMER_SETUP   (SOFT_TIMER_MS * 1000000)

Definition at line 39 of file d_pwm.c.

#define SPEED_PWMCNT_REL   (100)

Definition at line 49 of file d_pwm.c.

#define STOPPwm
Value:
{\
iowrite16(0x00, &eCAP0[0x15]);\
iowrite16(0x00, &eCAP1[0x15]);\
TIMER64P3[TGCR] = 0x00000000;\
iowrite16(0x00, &eHRPWM1[TBCTL]);\
iowrite16(0x00, &eHRPWM1[CMPCTL]);\
}
#define CMPCTL
Definition: d_pwm.c:96
Definition: d_pwm.c:127
#define TBCTL
Definition: d_pwm.c:92
#define EHRPWMClkDis
Definition: d_pwm.c:644

Definition at line 655 of file d_pwm.c.

#define TB_COUNT_FREEZE   0x3

Definition at line 75 of file d_pwm.c.

#define TB_COUNT_UP   0x0

Definition at line 74 of file d_pwm.c.

#define TB_DISABLE   0x0

Definition at line 76 of file d_pwm.c.

#define TB_DIV1   0x0

Definition at line 82 of file d_pwm.c.

#define TB_ENABLE   0x4

Definition at line 77 of file d_pwm.c.

#define TB_HDIV1   0x0

Definition at line 81 of file d_pwm.c.

#define TB_IMMEDIATE   0x8

Definition at line 79 of file d_pwm.c.

#define TB_SHADOW   0x0

Definition at line 78 of file d_pwm.c.

#define TB_SYNC_DISABLE   0x30

Definition at line 80 of file d_pwm.c.

#define TB_UP   0x2000

Definition at line 83 of file d_pwm.c.

#define TBCNT   0x4

Definition at line 94 of file d_pwm.c.

#define TBCTL   0x0

Definition at line 92 of file d_pwm.c.

#define TBPHS   0x3

Definition at line 93 of file d_pwm.c.

#define TBPRD   0x5

Definition at line 95 of file d_pwm.c.

Enumeration Type Documentation

anonymous enum
Enumerator
SAMPLES_BELOW_SPEED_25 
SAMPLES_SPEED_25_50 
SAMPLES_SPEED_50_75 
SAMPLES_ABOVE_SPEED_75 
NO_OF_SAMPLE_STEPS 

Definition at line 59 of file d_pwm.c.

anonymous enum
Enumerator
CFGCHIP1 

Definition at line 104 of file d_pwm.c.

anonymous enum
Enumerator
TBCLKSYNC 

Definition at line 109 of file d_pwm.c.

anonymous enum
Enumerator
REVID 
EMUMGT 
GPINTGPEN 
GPDATGPDIR 
TIM12 
TIM34 
PRD12 
PRD34 
TCR 
TGCR 
WDTCR 
NOTUSED1 
NOTUSED2 
REL12 
REL34 
CAP12 
CAP34 
NOTUSED3 
NOTUSED4 
NOTUSED5 
NOTUSED6 
NOTUSED7 
NOTUSED8 
INTCTLSTAT 
CMP0 
CMP1 
CMP2 
CMP3 
CMP4 
CMP5 
CMP6 
CMP7 

Definition at line 116 of file d_pwm.c.

anonymous enum
Enumerator
TSCTR 
CTRPHS 
CAP1 
CAP2 
CAP3 
CAP4 
ECCTL1 
ECCTL2 
ECEINT 
ECFLG 
ECCLR 
ECFRC 
ECAP_REVID 

Definition at line 153 of file d_pwm.c.

anonymous enum
Enumerator
FORWARD 
BACKWARD 
BRAKE 
COAST 

Definition at line 175 of file d_pwm.c.

anonymous enum
Enumerator
UNLIMITED_UNREG 
UNLIMITED_REG 
LIMITED_REG_STEPUP 
LIMITED_REG_STEPCONST 
LIMITED_REG_STEPDOWN 
LIMITED_UNREG_STEPUP 
LIMITED_UNREG_STEPCONST 
LIMITED_UNREG_STEPDOWN 
LIMITED_REG_TIMEUP 
LIMITED_REG_TIMECONST 
LIMITED_REG_TIMEDOWN 
LIMITED_UNREG_TIMEUP 
LIMITED_UNREG_TIMECONST 
LIMITED_UNREG_TIMEDOWN 
LIMITED_STEP_SYNC 
LIMITED_TURN_SYNC 
LIMITED_DIFF_TURN_SYNC 
SYNCED_SLAVE 
RAMP_DOWN_SYNC 
HOLD 
BRAKED 
STOP_MOTOR 
IDLE 

Definition at line 183 of file d_pwm.c.

anonymous enum
Enumerator
UNUSED_SYNC_MOTOR 

Definition at line 210 of file d_pwm.c.

Enumerator
OUTPUT_PORT_PIN1 
OUTPUT_PORT_PIN2 
OUTPUT_PORT_PIN5W 
OUTPUT_PORT_PIN5R 
OUTPUT_PORT_PIN6 
OUTPUT_PORT_PINS 
OUTPUT_PORT_VALUE 
PWM 
DIR0 
DIR1 
INT 
DIR 
SLEEP 
FAULT 
OUTPUT_PORT_PINS 

Definition at line 323 of file d_pwm.c.

Function Documentation

void BrakeMotor ( UBYTE  No,
SLONG  TachoCnt 
)

Definition at line 1318 of file d_pwm.c.

void CalcRampDownFactor ( UBYTE  No,
ULONG  CurrentPower,
ULONG  Counts 
)

Definition at line 1371 of file d_pwm.c.

void CheckforEndOfSync ( void  )

Definition at line 2163 of file d_pwm.c.

UBYTE CheckLessThanSpecial ( SLONG  Param1,
SLONG  Param2,
SLONG  Inv 
)

Definition at line 725 of file d_pwm.c.

void CheckSpeedPowerLimits ( SBYTE pCheckVal)

Definition at line 712 of file d_pwm.c.

void ClearPIDParameters ( UBYTE  No)

Definition at line 926 of file d_pwm.c.

UBYTE dCalculateSpeed ( UBYTE  No,
SBYTE pSpeed 
)

dCalculateSpeed

  • Calculates the actual speed for a motor
  • Returns TRUE when a new speed has been calculated, FALSE if otherwise
  • Time is sampled every edge on the tacho
    • Timer used is 64bit timer plus (P3) module (dual 32bit un-chained mode)
    • 64bit timer is running 33Mhz (24Mhz (Osc) * 22 (Multiplier) / 2 (Post divider) / 2 (DIV2)) / 4 (T64 prescaler)
    • When reading the timer it is divided by 256 => timer is a factor 256 slower
  • Tacho counter is updated on every edge of the tacho INTx pin signal
  • Time capture is updated on every edge of the tacho INTx pin signal
  • Speed is calculated from the following parameters
    • Time is measured edge to edge of the tacho interrupt pin. Average of time is always minimum 2 pulses (1 high + 1 low period or 1 low + 1 high period) because the duty of the high and low period of the tacho pulses are not always 50%.
      • Average of the large motor
        • Above speed 80 it is: 64 samples
        • Between speed 60 - 80 it is: 32 samples
        • Between speed 40 - 60 it is: 16 samples
        • below speed 40 it is: 4 samples
      • Average of the medium motor
        • Above speed 80 it is: 16 samples
        • Between speed 60 - 80 it is: 8 samples
        • Between speed 40 - 60 it is: 4 samples
        • below speed 40 it is: 2 sample
    • Number of samples is always determined based on 1 sample meaning 1 low period nor 1 high period, this is to enable fast adoption to changes in speed. Medium motor has the critical timing because it can change speed and direction very fast.
    • Large Motor
      • Maximum speed of the Large motor is approximately 2mS per tacho pulse (low + high period) resulting in minimum timer value of: 2mS / (1/(33MHz / 256)) = 256 T64 timer ticks. Because 1 sample is based on only half a period minimum speed is 256/2 = 128.
      • Minimum speed of the large motor is a factor of 100 less than max. speed max. speed timer ticks * 100 => 256 * 100 = 25600 T64 timer ticks Because 1 sample is based on only half a period minimum speed is 25600/2 = 12800.
- 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
  • Parameters:
    • Input:
      • No : Motor output number
      • *pSpeed : Pointer to the speed value
    • Output:
      • Status : Indication of new speed available or not
  • Tacho pulse examples:
    • Normal

| | | | | | | | | | | | | | ----— ----— ----— — 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++

Definition at line 3978 of file d_pwm.c.

void DecSpeed ( SBYTE  Dir,
SBYTE pSpeed 
)

Definition at line 753 of file d_pwm.c.

void dRegulateSpeed ( UBYTE  No)

dRegulateSpeed

  • Calculates the new motor power value (duty cycle)
  • Regulation method: To be defined
  • Parameters:

    • Input:
      • No: Motor output number

    -Output:

    • None

Definition at line 1270 of file d_pwm.c.

void FloatSyncedMotors ( void  )

Definition at line 1440 of file d_pwm.c.

void GetCompareCounts ( UBYTE  No,
SLONG Counts,
SLONG CompareCounts 
)

Definition at line 1381 of file d_pwm.c.

void GetPeriphealBasePtr ( ULONG  Address,
ULONG  Size,
ULONG **  Ptr 
)

GetPeriphealBasePtr.

Helper function for getting the peripheal HW base address

Definition at line 3140 of file d_pwm.c.

void GetSyncDurationCnt ( SLONG pCount0,
SLONG pCount1 
)

Definition at line 2148 of file d_pwm.c.

UWORD GetTachoDir ( UBYTE  Port)

Definition at line 794 of file d_pwm.c.

UWORD GetTachoInt ( UBYTE  Port)

Definition at line 800 of file d_pwm.c.

void IncSpeed ( SBYTE  Dir,
SBYTE pSpeed 
)

Definition at line 737 of file d_pwm.c.

void InitGpio ( void  )

Definition at line 3312 of file d_pwm.c.

MODULE_AUTHOR ( "The LEGO Group"  )
MODULE_DESCRIPTION ( MODULE_NAME  )
module_exit ( ModuleExit  )
module_init ( ModuleInit  )
MODULE_LICENSE ( "GPL"  )
module_param ( HwId  ,
charp  ,
 
)
MODULE_SUPPORTED_DEVICE ( DEVICE1_NAME  )
UBYTE RampDownToBrake ( UBYTE  No,
SLONG  CurrentCnt,
SLONG  TargetCnt,
SLONG  Dir 
)

Definition at line 1340 of file d_pwm.c.

void SetBrake ( UBYTE  Port)

Definition at line 781 of file d_pwm.c.

void SetCoast ( UBYTE  Port)

Definition at line 787 of file d_pwm.c.

void SetDirFwd ( UBYTE  Port)

Definition at line 775 of file d_pwm.c.

void SetDirRwd ( UBYTE  Port)

Definition at line 769 of file d_pwm.c.

void SetDutyMA ( ULONG  Duty)

Definition at line 908 of file d_pwm.c.

void SetDutyMB ( ULONG  Duty)

Definition at line 912 of file d_pwm.c.

void SetDutyMC ( ULONG  Duty)

Definition at line 916 of file d_pwm.c.

void SetDutyMD ( ULONG  Duty)

Definition at line 920 of file d_pwm.c.

void SetGpio ( int  Pin)

Definition at line 3273 of file d_pwm.c.

void SetGpioRisingIrq ( UBYTE  PinNo,
irqreturn_t(*)(int, void *)  IntFuncPtr 
)

Definition at line 3342 of file d_pwm.c.

void SetPower ( UBYTE  Port,
SLONG  Power 
)

Definition at line 806 of file d_pwm.c.

void SetRegulationPower ( UBYTE  Port,
SLONG  Power 
)

Definition at line 857 of file d_pwm.c.

UBYTE StepPowerCheckTachoCntConst ( UBYTE  No,
SLONG  AdjustTachoValue 
)

StepPowerCheckTachoCntConst.

Helper function Checks if step power should have a constant power sequense

Parameters: No: The motor number AdjustTachoValue: The value that the tacho should be decremented

Definition at line 1186 of file d_pwm.c.

void StepPowerCheckTachoCntDown ( UBYTE  No,
SLONG  AdjustTachoValue 
)

StepPowerCheckTachoCntDown.

Helper function Checks if step power should ramp down or stop

Parameters: No: The motor number AdjustTachoValue: The value that the tacho should be decremented

Definition at line 1231 of file d_pwm.c.

UBYTE StepPowerCheckTachoCntUp ( UBYTE  No)

StepPowerCheckTachoCntUp.

Helper function Checks if step power should have a Count up sequence

Parameters: No: The motor number

Definition at line 1142 of file d_pwm.c.

void StepPowerStopMotor ( UBYTE  No,
SLONG  AdjustTachoValue 
)

StepPowerStopMotor.

Helper function Checks how the motor should stop

Parameters: No: The motor number AdjustTachoValue: The value that the tacho should be decremented

Definition at line 951 of file d_pwm.c.

UBYTE StepSpeedCheckTachoCntConst ( UBYTE  No,
SLONG  AdjustTachoValue 
)

StepPowerCheckTachoCntConst.

Helper function Checks if step power should have a constant power sequence

Parameters: No: The motor number AdjustTachoValue: The value that the tacho should be decremented

Definition at line 1065 of file d_pwm.c.

void StepSpeedCheckTachoCntDown ( UBYTE  No,
SLONG  AdjustTachoValue 
)

StepSpeedCheckTachoCntDown.

Helper function Checks if step power should ramp down or stop

Parameters: No: The motor number AdjustTachoValue: The value that the tacho should be decremented

Definition at line 1109 of file d_pwm.c.

UBYTE StepSpeedCheckTachoCntUp ( UBYTE  No)

StepSpeedCheckTachoCntUp.

Helper function Checks if step power should have a Count up sequence

Parameters: No: The motor number

Definition at line 1000 of file d_pwm.c.

void StopAndBrakeMotor ( UBYTE  MotorNo)

Definition at line 1412 of file d_pwm.c.

void StopAndFloatMotor ( UBYTE  MotorNo)

Definition at line 1426 of file d_pwm.c.

void TestAndFloatSyncedMotors ( UBYTE  MotorBitField,
UBYTE  SyncCmd 
)

Definition at line 1464 of file d_pwm.c.

Variable Documentation

INPIN EP2_OutputPortPin[][OUTPUT_PORT_PINS]

Definition at line 343 of file d_pwm.c.

INPIN FINAL_OutputPortPin[][OUTPUT_PORT_PINS]

Definition at line 426 of file d_pwm.c.

INPIN FINALB_OutputPortPin[][OUTPUT_PORT_PINS]

Definition at line 385 of file d_pwm.c.

int Hw = 0

Definition at line 30 of file d_pwm.c.

int HwInvBits = 0

Definition at line 31 of file d_pwm.c.

INPIN* pOutputPortPin[]
Initial value:
=
{
}
Definition: am1808.h:222
#define EP2
Schematics revision D.
Definition: lms2012.h:99
INPIN EP2_OutputPortPin[][OUTPUT_PORT_PINS]
Definition: d_pwm.c:343
#define FINAL
Final prototype.
Definition: lms2012.h:101
INPIN FINAL_OutputPortPin[][OUTPUT_PORT_PINS]
Definition: d_pwm.c:426
#define FINALB
Schematics revision B and C.
Definition: lms2012.h:100
INPIN FINALB_OutputPortPin[][OUTPUT_PORT_PINS]
Definition: d_pwm.c:385

Definition at line 467 of file d_pwm.c.