-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemphis.h
188 lines (169 loc) · 4.21 KB
/
memphis.h
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/**
* libmemphis
* @file memphis.h
*
* @author Angelo Elias Dalzotto ([email protected])
* GAPH - Hardware Design Support Group (https://corfu.pucrs.br/)
* PUCRS - Pontifical Catholic University of Rio Grande do Sul (http://pucrs.br/)
*
* @date May 2021
*
* @brief libmemphis API
*/
#pragma once
#include <stdint.h>
#include <stddef.h>
static const unsigned MEMPHIS_KERNEL_MSG = 0x10000000;
static const unsigned MEMPHIS_FORCE_PORT = 0x80000000;
static const int BR_SVC_ALL = 0;
static const int BR_SVC_TGT = 2;
enum _syscall {
SYS_writepipe = 1,
SYS_readpipe,
SYS_gettick,
SYS_realtime = 5,
SYS_getlocation = 9,
SYS_brall,
SYS_monptr,
SYS_brtgt,
SYS_getctx,
SYS_halt,
SYS_sendraw,
SYS_safelog
};
/**
* @brief Struct for storing the Memphis kernel context
*
*/
typedef struct _mctx {
size_t PE_CNT;
size_t PE_X_CNT;
size_t PE_Y_CNT;
size_t PE_SLOTS;
size_t MC_SLOTS;
} mctx_t;
/**
* @brief Gets the PE address of the runnning task
*
* @return The PE address
*/
int memphis_get_addr();
/**
* @brief Sends a message through Hermes
*
* @param msg Pointer to the message
* @param size Message size in bytes
* @param target_id ID of the consumer task
*
* @return 0 on success
* -1 on failure and sets errno
*/
int memphis_send(void *msg, size_t size, int target_id);
/**
* @brief Sends a raw packet through Hermes
*
* @param pkt Pointer to the packet
* @param size Packet size in flits
*
* @return 0 on success
* -1 on failure and sets errno
*/
int memphis_send_raw(void *pkt, size_t size);
/**
* @brief Sends a message through Hermes
*
* @param msg Pointer to the buffer to receive the message
* @param size Maximum size in bytes to receive
* @param target_id ID of the consumer task
*
* @return The number of bytes read on success
* -1 on failure and sets errno
*/
int memphis_receive(void *msg, size_t size, int source_id);
/**
* @brief Gets the current tick count
*
* @return Tick count
*/
unsigned memphis_get_tick();
/**
* @brief Sends a message with a 3-way handshake
*
* @param msg Pointer to the message
* @param size Message size in bytes
* @param target_id ID of the consumer task
*
* @return 0 on success
* -1 on failure and sets errno
*/
int memphis_send_any(void *msg, size_t size, int target_id);
/**
* @brief Receives a message from any producer
*
* @param msg Pointer to the buffer to receive the message
* @param size Maximum size in bytes to receive
*
* @return 0 on success
* -1 on failure and sets errno
*/
int memphis_receive_any(void *msg, size_t size);
/**
* @brief Set the running task as real-time
*
* @details
* Deadline should be less than period
* Execution time should be less than deadline
* % Load = exec_time/period * 100
* Execution time should be discovered via profiling
*
* @param period Task period in ticks
* @param deadline Task deadline in ticks
* @param exec_time Task execution time in ticks
*
* @return 0
*/
int memphis_real_time(int period, int deadline, int exec_time);
/**
* @brief Sends message via broadcast ALL
*
* @param payload Message to send (1 word)
* @param ksvc Message Kernel Service, used for TGT and ALL (check services.h)
*
* @return 0 on success
* -1 on failure and sets errno
*/
int memphis_br_send_all(uint32_t payload, uint8_t ksvc);
/**
* @brief Sends message via broadcast TARGET
*
* @param payload Message to send (1 word)
* @param target Target address to send
* @param ksvc Message Kernel Service, used for TGT and ALL (check services.h)
*
* @return 0 on success
* -1 on failure and sets errno
*/
int memphis_br_send_tgt(uint32_t payload, uint16_t target, uint8_t ksvc);
/**
* @brief Gets the number of processors in the system
*
* @param x Variable to store X processors
* @param y Variable to store Y processors
*
* @return size_t Total number of processors
*/
size_t memphis_get_nprocs(size_t *x, size_t *y);
/**
* @brief Gets the maximum local tasks
*
* @param total Variable to store maximum tasks of the system
*
* @return size_t Number of maximum local tasks
*/
size_t memphis_get_max_tasks(size_t *total);
/**
* @brief Halts the simulation
*
* @return int 0 success, EACCES if not allowed
*/
int memphis_halt();