Skip to content

Commit 172cf16

Browse files
bigdinotecheriknyquist
authored andcommitted
CODK-M firmware changes
-add CurieSMC library -changes for cdc-acm compatibility -changes for zephyr based firmware compatibility
1 parent 6ee828b commit 172cf16

File tree

6 files changed

+179
-1
lines changed

6 files changed

+179
-1
lines changed

libraries/CurieSMC/keywords.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#######################################
2+
# Syntax Coloring Map For CurieSMC
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
CurieSMC KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
write KEYWORD2
16+
reaD KEYWORD2
17+
begin KEYWORD2
18+
end KEYWORD2
19+
availableForRead KEYWORD2
20+
availableForWrite KEYWORD2
21+
#######################################
22+
# Constants (LITERAL1)
23+
#######################################

libraries/CurieSMC/library.properties

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=CurieSMC
2+
version=1.0
3+
author=Intel
4+
maintainer=Intel <dino.tinitigan@intel.com>
5+
sentence=Enables passing of data between the quark and ARC cores
6+
paragraph=
7+
category=Communication
8+
url=
9+
architectures=arc32

libraries/CurieSMC/src/CurieSMC.cpp

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
#include "CurieSMC.h"
3+
4+
CurieSMC SMC;
5+
void CurieSMC::begin()
6+
{
7+
QUARK_BUFF_HEAD = 0;
8+
QUARK_BUFF_TAIL = 0;
9+
QUARK_BUFF_FLAG = 2;
10+
ARC_BUFF_HEAD = 0;
11+
ARC_BUFF_TAIL = 0;
12+
ARC_BUFF_FLAG = 2;
13+
}
14+
int CurieSMC::write(uint8_t data)
15+
{
16+
//check if buffer is available
17+
if(ARC_BUFF_FLAG == 1)
18+
{
19+
return 1;
20+
}
21+
22+
//lock the buffer
23+
ARC_BUFF_FLAG = 0;
24+
25+
int new_head = (int)(ARC_BUFF_HEAD+1)%SHARED_BUFFER_SIZE;
26+
if(new_head != ARC_BUFF_TAIL)
27+
{
28+
ARC_BUFF[ARC_BUFF_HEAD] = data;
29+
ARC_BUFF_HEAD = new_head;
30+
}
31+
else
32+
{
33+
return 2; //buffer is full
34+
}
35+
36+
//unlock the buffer
37+
ARC_BUFF_FLAG = 2;
38+
39+
return 0;
40+
}
41+
42+
uint8_t CurieSMC::read()
43+
{
44+
//check if buffer is available
45+
if(QUARK_BUFF_FLAG == 1)
46+
return 0;
47+
48+
//lock the buffer
49+
QUARK_BUFF_FLAG = 0;
50+
51+
if(availableForRead())
52+
{
53+
uint8_t data = QUARK_BUFF[QUARK_BUFF_TAIL];
54+
QUARK_BUFF_TAIL = (QUARK_BUFF_TAIL + 1) % SHARED_BUFFER_SIZE;
55+
QUARK_BUFF_FLAG = 2; //unlock the buffer
56+
return data;
57+
}
58+
else
59+
{
60+
QUARK_BUFF_FLAG = 2; //unlock the buffer
61+
return 0;
62+
}
63+
}
64+
65+
int CurieSMC::availableForWrite()
66+
{
67+
int head = ARC_BUFF_HEAD;
68+
int tail = ARC_BUFF_TAIL;
69+
70+
if(head >= tail)
71+
return SHARED_BUFFER_SIZE - head + tail - 1;
72+
return tail - head - 1;
73+
}
74+
75+
int CurieSMC::availableForRead()
76+
{
77+
return (int)(SHARED_BUFFER_SIZE + QUARK_BUFF_HEAD-QUARK_BUFF_TAIL) % SHARED_BUFFER_SIZE;
78+
}

libraries/CurieSMC/src/CurieSMC.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
#define QUARK_BUFF shared_data->quark_to_ARC.data
3+
#define QUARK_BUFF_HEAD shared_data->quark_to_ARC.head
4+
#define QUARK_BUFF_TAIL shared_data->quark_to_ARC.tail
5+
#define QUARK_BUFF_FLAG shared_data->quark_to_ARC.flag
6+
#define ARC_BUFF shared_data->ARC_to_quark.data
7+
#define ARC_BUFF_HEAD shared_data->ARC_to_quark.head
8+
#define ARC_BUFF_TAIL shared_data->ARC_to_quark.tail
9+
#define ARC_BUFF_FLAG shared_data->ARC_to_quark.flag
10+
11+
#include "Arduino.h"
12+
#include "platform.h"
13+
14+
class CurieSMC
15+
{
16+
public:
17+
CurieSMC()
18+
{
19+
}
20+
21+
void begin();
22+
void end();
23+
int write(uint8_t data);
24+
uint8_t read();
25+
int availableForWrite();
26+
int availableForRead();
27+
28+
private:
29+
};
30+
31+
extern CurieSMC SMC;

system/libarc32_arduino101/framework/include/platform.h

+37
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define NUM_CPU 4
4141

4242
#define CDCACM_BUFFER_SIZE 256
43+
#define SHARED_BUFFER_SIZE 64
4344

4445
struct cdc_ring_buffer
4546
{
@@ -62,6 +63,30 @@ struct cdc_acm_shared_data {
6263
int device_open;
6364
};
6465

66+
struct shared_ring_buffer
67+
{
68+
/** Ring buffer data */
69+
volatile uint8_t data[SHARED_BUFFER_SIZE];
70+
/** Ring buffer head index, modified by producer */
71+
volatile int head;
72+
/** Ring buffer tail index, modified by consumer */
73+
volatile int tail;
74+
75+
/** Buffer status
76+
* 0 - locked by X86 core
77+
* 1 - locked by arc core
78+
* 2 - available to be taken by any core
79+
**/
80+
volatile int flag;
81+
};
82+
83+
struct ipm_shared_data
84+
{
85+
struct shared_ring_buffer *quark_buffer;
86+
struct shared_ring_buffer *arc_buffer;
87+
};
88+
89+
6590
/**
6691
* LMT / ARC global shared structure. This structure lies in the beginning of
6792
* the RAM.
@@ -109,6 +134,18 @@ struct platform_shared_block_ {
109134
* The ARC core counts on QRK to find valid pointers in place.
110135
*/
111136
struct cdc_acm_shared_data * cdc_acm_buffers;
137+
138+
struct cdc_acm_shared_data cdc_acm_buffers_obj;
139+
140+
struct cdc_ring_buffer cdc_acm_shared_rx_buffer;
141+
struct cdc_ring_buffer cdc_acm_shared_tx_buffer;
142+
143+
struct ipm_shared_data *ipm_shared_data_ptr;
144+
145+
struct ipm_shared_data ipm_shared_data_obj;
146+
147+
struct shared_ring_buffer quark_to_ARC;
148+
struct shared_ring_buffer ARC_to_quark;
112149
};
113150

114151
#define RAM_START 0xA8000000

variants/arduino_101/linker_scripts/flash.ld

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ OUTPUT_FORMAT("elf32-littlearc", "elf32-bigarc", "elf32-littlearc")
4040
MEMORY
4141
{
4242
FLASH (rx) : ORIGIN = 0x40034000, LENGTH = 152K
43-
SRAM (wx) : ORIGIN = 0xa800e000, LENGTH = 24K
43+
SRAM (wx) : ORIGIN = 0xa8000400, LENGTH = 24K
4444
DCCM (wx) : ORIGIN = 0x80000000, LENGTH = 8K
4545
}
4646

0 commit comments

Comments
 (0)