-
Notifications
You must be signed in to change notification settings - Fork 0
/
processflow.c
108 lines (97 loc) · 2.7 KB
/
processflow.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
#include "processflow.h"
#include "TI_USCI_I2C_master.h"
#define START_ADDRESS 0x0000
unsigned char GetNumApps(void)
{
unsigned char nApps = 0;
I2C_readEEPROM(0x51, START_ADDRESS, 1, &nApps);
return nApps;
}
unsigned int GetAppAddress(unsigned char nApp)
{
unsigned char pData[2];
unsigned int nAddress = 0;
if (nApp < 1) return 0;
if (nApp > GetNumApps()) return 0;
I2C_readEEPROM(0x51, START_ADDRESS + 1 + 2 * (nApp - 1), 2, pData);
nAddress = pData[0];
nAddress = nAddress << 8;
nAddress |= pData[1];
return nAddress;
}
unsigned char GetNumScripts(unsigned int nAppAddress)
{
unsigned char nScripts = 0;
I2C_readEEPROM(0x51, nAppAddress + 16, 1, &nScripts);
return nScripts;
}
unsigned int GetScriptAddress(unsigned int nAppAddress, unsigned char nScript)
{
unsigned char pData[2];
unsigned int nAddress = 0;
if (nScript < 1) return 0;
if (nScript > GetNumScripts(nAppAddress)) return 0;
I2C_readEEPROM(0x51, nAppAddress + 16 + 1 + 2 * (nScript - 1), 2, pData);
nAddress = pData[0];
nAddress = nAddress << 8;
nAddress |= pData[1];
return nAddress;
}
typedef struct
{
unsigned char nType;
unsigned char nI2CAddr;
unsigned char nRegAddr;
unsigned char nCount;
} TCMD;
unsigned int GetNumCmds(unsigned int nScriptAddress)
{
unsigned char pCmds[2];
unsigned int nCmds;
I2C_readEEPROM(0x51, nScriptAddress + 16, 2, pCmds);
nCmds = pCmds[0];
nCmds = nCmds << 8;
nCmds |= pCmds[1];
return nCmds;
}
void LoadScript(unsigned int nScriptAddress)
{
unsigned int nCmds = GetNumCmds(nScriptAddress);
unsigned int nCmd;
unsigned int nAddress = nScriptAddress + 16 + 2;
TCMD cmd;
unsigned char pData[32];
unsigned int nBytes;
unsigned int n;
for (nCmd = 0; nCmd < nCmds; nCmd++)
{
I2C_readEEPROM(0x51, nAddress, 4, (unsigned char *) &cmd);
nAddress += 4;
switch (cmd.nType)
{
case 0x00: // write command
for (n = 0; n < cmd.nCount; n += 32)
{
nBytes = cmd.nCount - n;
if (nBytes > 32) nBytes = 32;
I2C_readEEPROM(0x51, nAddress, nBytes, pData);
//Write nBytes of pData to AIC3254 at cmd.nRegAddr...
I2C_multiWrite(cmd.nI2CAddr >> 1, cmd.nRegAddr, nBytes, pData);
//for (int b = 0; b < nBytes; b++)
// I2C_singleWrite(cmd.nI2CAddr >> 1, cmd.nRegAddr + b, pData[b]);
nAddress += nBytes;
cmd.nRegAddr += nBytes;
}
break;
default:
nAddress += cmd.nCount;
break;
}
}
}
void LoadProcessFlow(unsigned int nApplication, unsigned int nScript)
{
unsigned int nAppAddress = GetAppAddress(nApplication);
unsigned int nScriptAddress = GetScriptAddress(nAppAddress, nScript);
LoadScript(nScriptAddress);
}