Skip to content

Commit b725dd3

Browse files
bigdinotechcalvinatintel
authored andcommitted
CurieSMC library fixes
-properly set flags for both cores during read() and write() -add example sketch for CurieSMC library
1 parent 4a5a009 commit b725dd3

File tree

2 files changed

+67
-11
lines changed

2 files changed

+67
-11
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
5+
6+
/*
7+
* This sketch example demonstrates a simple way to use the Shared Memory Communication library between
8+
* the ARC and Quark cores.
9+
* It requires that the firmware be upgraded to one that supports the Shared Memory Communication library.
10+
* This sketch example will need to be used with the smc example built using the CODK-M tree.
11+
*
12+
* This sketch sends values to the Quark core which then reads those values, doubles them and sends it back to the ARC core.
13+
* This sketch then reads those values and displays the doubled values.
14+
*/
15+
16+
#include <CurieSMC.h>
17+
18+
void setup()
19+
{
20+
Serial.begin(384000);
21+
while(!Serial);
22+
SMC.begin();
23+
}
24+
25+
void loop()
26+
{
27+
for(int i = 0; i < 32; i++)
28+
{
29+
Serial.print("writing : ");
30+
Serial.println(i);
31+
SMC.write(i);
32+
}
33+
while(SMC.availableForRead())
34+
{
35+
Serial.print("data: ");
36+
Serial.println(SMC.read());
37+
}
38+
39+
delay(1000);
40+
}
41+
42+
/*
43+
Copyright (c) 2016 Intel Corporation. All rights reserved.
44+
45+
This library is free software; you can redistribute it and/or
46+
modify it under the terms of the GNU Lesser General Public
47+
License as published by the Free Software Foundation; either
48+
version 2.1 of the License, or (at your option) any later version.
49+
50+
This library is distributed in the hope that it will be useful,
51+
but WITHOUT ANY WARRANTY; without even the implied warranty of
52+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
53+
Lesser General Public License for more details.
54+
55+
You should have received a copy of the GNU Lesser General Public
56+
License along with this library; if not, write to the Free Software
57+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
58+
59+
*/
60+

libraries/CurieSMC/src/CurieSMC.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ void CurieSMC::begin()
1414
int CurieSMC::write(uint8_t data)
1515
{
1616
//check if buffer is available
17-
if(ARC_BUFF_FLAG == 1)
18-
{
17+
if(ARC_BUFF_FLAG == 0)
1918
return 1;
20-
}
2119

2220
//lock the buffer
23-
ARC_BUFF_FLAG = 0;
21+
ARC_BUFF_FLAG = 1;
2422

2523
int new_head = (int)(ARC_BUFF_HEAD+1)%SHARED_BUFFER_SIZE;
2624
if(new_head != ARC_BUFF_TAIL)
@@ -30,23 +28,21 @@ int CurieSMC::write(uint8_t data)
3028
}
3129
else
3230
{
31+
ARC_BUFF_FLAG = 2; //unlock the buffer
3332
return 2; //buffer is full
3433
}
35-
36-
//unlock the buffer
37-
ARC_BUFF_FLAG = 2;
38-
34+
35+
ARC_BUFF_FLAG = 2; //unlock the buffer
3936
return 0;
4037
}
4138

4239
uint8_t CurieSMC::read()
4340
{
4441
//check if buffer is available
45-
if(QUARK_BUFF_FLAG == 1)
46-
return 0;
42+
while(QUARK_BUFF_FLAG == 0); //wait for Quark core to release the buffer
4743

4844
//lock the buffer
49-
QUARK_BUFF_FLAG = 0;
45+
QUARK_BUFF_FLAG = 1;
5046

5147
if(availableForRead())
5248
{

0 commit comments

Comments
 (0)