PowerBlocks SDK
 
Loading...
Searching...
No Matches
system.h
Go to the documentation of this file.
1
11
12#pragma once
13
14#include <stdint.h>
15#include <stddef.h>
16
18
24#define SYSTEM_BUS_CLOCK_HZ 243000000
25
31#define SYSTEM_CORE_CLOCK_HZ 729000000
32
39 #define SYSTEM_TB_CLOCK_HZ (SYSTEM_BUS_CLOCK_HZ / 4)
40
46#define SYSTEM_US_TO_TICKS(us) (SYSTEM_TB_CLOCK_HZ / 1000000 * (us))
47
53#define SYSTEM_MS_TO_TICKS(ms) (SYSTEM_TB_CLOCK_HZ / 1000 * (ms))
54
60#define SYSTEM_S_TO_TICKS(s) (SYSTEM_TB_CLOCK_HZ * (s))
61
68#define SYSTEM_MEM_UNCACHED(address) (((uint32_t)(address) & 0x1FFFFFFF) | 0xC0000000)
69
76#define SYSTEM_MEM_CACHED(address) (((uint32_t)(address) & 0x1FFFFFFF) | 0x80000000)
77
84#define SYSTEM_MEM_PHYSICAL(address) ((uint32_t)(address) & 0x1FFFFFFF)
85
89typedef struct {
90 int magic; // Supposed to be 0x5f617267, checked by system init
91 const char* command_line;
92 int command_line_length;
93 int argc;
94 char **argv;
95 char **end_argv;
97
98extern system_argv_t system_argv;
99
105#define PACKED __attribute__((packed))
106
112#define MEM2 __attribute__((section(".mem2")))
113
121#define SYSTEM_MAIN_STACK_SIZE (1024*1024*4) // 4 MB
122
128#define SYSTEM_GET_MSR(msr) \
129 __asm__ __volatile__( \
130 "mfmsr %0" : "=r"(msr) \
131 );
132
138#define SYSTEM_SET_MSR(msr) \
139 __asm__ __volatile__( \
140 "mtmsr %0" : : "r"(msr) \
141 );
142
149#define SYSTEM_GET_DEC(msr) \
150 __asm__ __volatile__( \
151 "mfdec %0" : "=r"(msr) \
152 );
153
160#define SYSTEM_SET_DEC(msr) \
161 __asm__ __volatile__( \
162 "mtdec %0" : : "r"(msr) \
163 );
164
170#define SYSTEM_DISABLE_ISR(ee_enabled) \
171 do { \
172 uint32_t msr; \
173 SYSTEM_GET_MSR(msr); \
174 ee_enabled = (msr >> 15) & 1; \
175 msr &= ~(0x8000); \
176 SYSTEM_SET_MSR(msr); \
177 } while(0)
178
186#define SYSTEM_ENABLE_ISR(ee_enabled) \
187 if(ee_enabled) { \
188 uint32_t msr; \
189 SYSTEM_GET_MSR(msr); \
190 msr |= 0x8000; \
191 SYSTEM_SET_MSR(msr); \
192 }
193
199#define SYSTEM_SYNC() \
200 __asm__ __volatile__( \
201 "sync" \
202 );
203
209#define SYSTEM_ISYNC() \
210 __asm__ __volatile__( \
211 "isync" \
212 );
213
219#define ASSERT(x) \
220 if((x) == 0) { \
221 SYSCALL_ASSERT("ASSERTION FAILED", __LINE__, __FILE__); \
222 }
223
233#define ASSERT_OUT_OF_MEMORY(x) \
234 if((x) == 0) { \
235 SYSCALL_ASSERT("OUT OF MEMORY", __LINE__, __FILE__); \
236 }
237
243#define ALIGN(x) __attribute__((aligned(x)))
244
251#define SYSTEM_SWITCH_SP(x) \
252 __asm__ __volatile__ ( \
253 "lis r3, pxCurrentTCB@ha\n\t" \
254 "lwz r4, pxCurrentTCB@l(r3)\n\t" /* r4 = pxCurrentTCB */ \
255 "mr r5, r1\n\t" /* r5 = current SP */ \
256 "stw r5, 0(r4)\n\t" /* pxCurrentTCB->pxTopOfStack = SP */ \
257 \
258 /* Call vTaskSwitchContext() */ \
259 "bl vTaskSwitchContext\n\t" \
260 \
261 "lis r3, pxCurrentTCB@ha\n\t" \
262 "lwz r4, pxCurrentTCB@l(r3)\n\t" /* r4 = pxCurrentTCB */ \
263 "lwz r1, 0(r4)\n\t" /* SP = pxCurrentTCB->pxTopOfStack */ \
264 )
265
266
267
276extern uint64_t system_get_time_base_int();
277
289extern void system_delay_int(uint64_t ticks);
290
300extern void system_flush_dcache(const void* data, uint32_t size);
301
308extern void system_invalidate_dcache(void* data, uint32_t size);
309
319extern void system_invalidate_icache(void* data, uint32_t size);
320
332extern void* system_aligned_malloc(uint32_t bytes, uint32_t alignment);
333
339extern void system_aligned_free(void* ptr);
340
347extern void system_initialize();
348
365extern void system_get_boot_path(const char* device, char* buffer, size_t length);
366
367#include <stdint.h>
Command line arguments passed to us from launcher.
Definition system.h:89
Handle syscall exceptions.
void system_initialize()
Initializes the system.
Definition system.c:56
void system_invalidate_icache(void *data, uint32_t size)
Invalidates the instruction cache in a range.
uint64_t system_get_time_base_int()
Gets the time base register of the CPU.
void * system_aligned_malloc(uint32_t bytes, uint32_t alignment)
Allocate memory with alignment.
Definition system.c:35
void system_aligned_free(void *ptr)
Free allocated memory with alignment.
Definition system.c:50
void system_get_boot_path(const char *device, char *buffer, size_t length)
Looks in the argv command line for a specific boot path.
Definition system.c:87
void system_invalidate_dcache(void *data, uint32_t size)
Invalidates data cache in a range.
void system_delay_int(uint64_t ticks)
Sleeps for a certain number of ticks.
Definition system.c:29
void system_flush_dcache(const void *data, uint32_t size)
Flushes data cache in a range.