forked from ingeniamc/mcblib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcb_usr.c
132 lines (109 loc) · 2.99 KB
/
mcb_usr.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
125
126
127
128
129
130
131
132
/**
* @file mcb_usr.c
* @brief This file contains functions to be implemented by user to
* migrate platform dependencies
*
* @author Firmware department
* @copyright Ingenia Motion Control (c) 2018. All rights reserved.
*/
#include "mcb_usr.h"
#include "mcb_checksum.h"
/** Struct used when no resource instance defined by user */
volatile bool ptFlag[MCB_NUMBER_RESOURCES];
__attribute__((weak))uint8_t Mcb_IntfReadIRQ(uint16_t u16Id)
{
/*
* Return a 0 which means LOW level indicating that the slave is not
* available
*/
return (uint8_t)0U;
}
__attribute__((weak))uint32_t Mcb_GetMillis(void)
{
/** Return milliseconds */
return (uint32_t)0U;
}
__attribute__((weak))bool Mcb_IntfIsReady(uint16_t u16Id)
{
/** Check if SPI instance is ready for initiate a new transmission */
return false;
}
__attribute__((weak))uint16_t Mcb_IntfComputeCrc(const uint16_t* pu16Buf, uint16_t u16Sz)
{
uint16_t u16Crc = CRC_START_XMODEM;
for (uint16_t u16Idx = 0; u16Idx < u16Sz; u16Idx++)
{
u16Crc = update_crc_ccitt(u16Crc, (pu16Buf[u16Idx] >> 8) & 0xFF);
u16Crc = update_crc_ccitt(u16Crc, (pu16Buf[u16Idx] & 0xFF));
}
return u16Crc;
}
__attribute__((weak))bool Mcb_IntfCheckCrc(uint16_t u16Id, const uint16_t* pu16Buf, uint16_t u16Sz)
{
bool isCrcOk = true;
/** Compute the CRC of the incoming frame, excluding its own CRC */
uint16_t u16CompCrc = Mcb_IntfComputeCrc(pu16Buf, (u16Sz - 1));
if (u16CompCrc != pu16Buf[u16Sz - 1])
{
isCrcOk = false;
}
return isCrcOk;
}
__attribute__((weak))void Mcb_IntfSPITransfer(uint16_t u16Id, uint16_t* pu16In, uint16_t* pu16Out, uint16_t u16Sz)
{
/** Set to low chip select pin */
/** Launch a SPI transfer */
/** Set to high chip select pint */
}
__attribute__((weak))void Mcb_IntfSyncSignal(uint16_t u16Id)
{
}
__attribute__((weak))void Mcb_IntfInitResource(uint16_t u16Id)
{
/** Init the resource instance, release state */
if (u16Id < MCB_NUMBER_RESOURCES)
{
ptFlag[u16Id] = true;
}
}
__attribute__((weak))void Mcb_IntfDeinitResource(uint16_t u16Id)
{
/** Remove the resource instance */
if (u16Id < MCB_NUMBER_RESOURCES)
{
ptFlag[u16Id] = false;
}
}
__attribute__((weak))bool Mcb_IntfTryTakeResource(uint16_t u16Id)
{
/** Non blocking resource take */
bool isResTak = false;
if (u16Id < MCB_NUMBER_RESOURCES)
{
if (ptFlag[u16Id] != false)
{
ptFlag[u16Id] = false;
isResTak = true;
}
}
return isResTak;
}
__attribute__((weak))bool Mcb_IntfTakeResource(uint16_t u16Id)
{
/** Blocking resource take */
bool isResTak = false;
if (u16Id < MCB_NUMBER_RESOURCES)
{
while (ptFlag[u16Id] == false);
ptFlag[u16Id] = false;
isResTak = true;
}
return isResTak;
}
__attribute__((weak))void Mcb_IntfReleaseResource(uint16_t u16Id)
{
if (u16Id < MCB_NUMBER_RESOURCES)
{
ptFlag[u16Id] = true;
}
}