-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIO.c
124 lines (99 loc) · 3.53 KB
/
IO.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*******************************************************************************
Project: stepRocker Mini-TMCL
Module: IO.c
I/O routines and some other useful stuff
Copyright (C) 2011 TRINAMIC Motion Control GmbH & Co KG
Waterloohain 5
D - 22769 Hamburg, Germany
http://www.trinamic.com/
This program is free software; you can redistribute it and/or modify it
freely.
This program is distributed "as is" in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
*******************************************************************************/
/**
\file IO.c
\author Trinamic Motion Control GmbH & Co KG
\version 1.00
\brief I/O functions
This file provides functions for intializing and
using the I/O ports and some other miscellaneous
stuff.
*/
#include <stdlib.h>
#include "csp.h"
#include "bits.h"
#include "stepRocker.h"
#include "TMC262.h"
/*********************************************//**
\fn InitIO(void)
\brief Initialize I/O
This function initalizes all I/O port pins of
the CPU that are not initialized in somewhere
else in other initialization functions.
*************************************************/
void InitIO(void)
{
// GPIO init
GPIO0->CEDR = 1;
GPIO0->SRR = 1;
GPIO0->OER = (1UL << 10)|(1UL << 5)|(1UL << 3)|(1UL << 1)|(1UL << 0);
GPIO0->CODR = (1UL << 5);
GPIO0->ODR = (1UL << 31)|(1UL << 30)|(1UL << 4)|(1UL << 2);
GPIO1->CEDR = 1;
GPIO1->SRR = 1;
GPIO1->ODR = (1UL << 20)|(1UL << 19)|(1UL << 18);
GPIO1->OER = (1UL << 22)|(1UL << 11)|(1UL << 10)|(1UL << 9)|(1UL << 8)|(1UL << 7)|(1UL << 6)|(1UL << 5);
GPIO1->WODR = (1UL << 9)|(1UL << 8); // set open drain transistors
CSP_IOFunctionConfigure(GROUP1, IO_Port21, IOCONF_F1);
}
/***************************************************************//**
\fn EnableInterrupts(void)
\brief Enable all interrupts
This function globally enables all interrupts.
********************************************************************/
void EnableInterrupts(void)
{
asm volatile("CPSIE I\n");
}
/***************************************************************//**
\fn DisableInterrupts(void)
\brief Disable all interrupts
This function globally disables all interrupts.
********************************************************************/
void DisableInterrupts(void)
{
asm volatile("CPSID I\n");
}
/***************************************************************//**
\fn SetMotorCurrent(UCHAR Motor, UCHAR Current)
\brief Set motor current
\param Motor Motor number (with stepRocker always 0)
\param Current Motor current scaled to 0..255
This function sets the motor current, scaled to 0..255 as
usual in TMCL.
********************************************************************/
void SetMotorCurrent(UCHAR Motor, UCHAR Current)
{
Set262StallGuardCurrentScale(WHICH_262(Motor), Current>>3);
}
/***************************************************************//**
\fn GetStallState(UCHAR Motor)
\brief Get stall flag state of motor driver
\param Motor Motor number (with stepRocker always 0)
\return TRUE stall\n
FALSE no stall
This function reads the state of the SG_TEST pin of the TMC262.
********************************************************************/
UCHAR GetStallState(UCHAR Motor)
{
if(Motor==0)
{
if(GPIO1->PDSR & BIT20)
return TRUE;
else
return FALSE;
}
else return FALSE;
}