#include <sys/robsys.h>
#include <sys/mmap.h>
+#include <sys/process.h>
#include <lib/regfunc.h>
#include <lib/pool.h>
#include <lib/stdio.h>
#include <lib/string.h>
#include <lib/tinyprintf.h>
+#include <lib/syscall.h>
#include <drivers/uart.h>
#include <drivers/led.h>
#include <drivers/st7735s.h>
-#include <lib/syscall.h>
-
-int test3(int i, int j) {
-
- volatile uint32_t * sp = get_msp();
-
- /* asm volatile (
- "tst lr, #4" "\n\t"
- "ite eq" "\n\t"
- "mrseq %0, msp" "\n\t"
- "mrsne r0, psp" : "=r" (sp) ); */
-
- for (int i = 0; (sp + i) < 0x20010000; i++) {
- printf("ADDRESS: %p, VALUE: %x\n", (sp + i), *(sp + i));
- }
+/* Example of multitasking */
+process_t p1;
+process_t p2;
- for(;;);
- return 0xCC;
-
-}
-int test2(int i, int j) {
+uint32_t stackp1[500];
+uint32_t stackp2[500];
- int x = i * j;
- test3(0x3A, 0x3B);
-
+void process1(void);
+void process2(void);
-}
-int test(int i, int j) {
- test2(0x2A, 0x2B);
-
- return 0xAA;
-}
void main()
{
+ /* Load .data segment into SRAM */
+ extern uint32_t * data_lma, data_vma, data_end;
+ int size = (&data_end - &data_vma) * 4;
+ memcpy(&data_vma, &data_lma, size);
+
/* Initialize the clock system, */
clock_init();
/* TFT screen */
// tft_init();
- /* Cortex M* integrated systick, can be replaced
- * by the more accurate RTC.
- systick_init();
- */
-
/* Set up a very small libc library */
init_printf(NULL, putc);
/* On board LEDs*/
led_init();
- /* Real time clock */
- //rtc_init();
-// printf("press any key to start\n");
-// asm volatile ("wfi");
+ /* Real time clock */
+ rtc_init();
+ /* Initialize SVC handler for system calls*/
syscall_init();
- theos_test(0xA1, 0xA2);
+
+ /* System call test */
+ int uptime = theos_uptime();
+ printf("UPTIME: %d\n", uptime);
+
+ /* Multi processes test */
+// int size_stack = sizeof(stackp1);
+// p1.stackptr = ((unsigned int) stackp1) + size_stack - 0x1C;
+// p1.stackptr[6] = (uint32_t) process1;
+// p1.stackptr[7] = 0x01000000;
+// p2.stackptr = ((unsigned int) stackp2) + size_stack - 0x1C;
+// p2.stackptr[6] = (uint32_t) process2;
+// p2.stackptr[7] = 0x01000000;
+// theos_init(&p1);
+
+ /* Cortex M* integrated systick, can be replaced
+ * by the more accurate RTC. */
+ //systick_init();
/* Eeprom Driver
eeprom_at24c_init();
/* ADC Joystick module */
// mk450_init();
-
/* Start up terminal */
terminal();
}
}
+
+void process1(void) {
+
+ while(1) {
+ printf("process 1\n");
+ _block(0xFFFFF);
+ theos_switch(&p1, &p2);
+ }
+
+}
+void process2(void) {
+ while(1) {
+ printf("process 2\n");
+ _block(0xFFFFF);
+ theos_switch(&p2, &p1);
+ }
+
+}