X-Git-Url: https://robinkrens.nl/gitweb/?a=blobdiff_plain;f=main.c;h=ac01416abdfbb5f1ef46dc50ff420be7f38e767d;hb=0fb50a530c9823ef39a820e1078e0d5789c03f32;hp=2b6fdbae3a3a078f57126b98f90e65c0e1784de9;hpb=41d25ed67df8b6acd6126c41c8b0882586db0b0d;p=cortex-from-scratch diff --git a/main.c b/main.c index 2b6fdba..ac01416 100644 --- a/main.c +++ b/main.c @@ -1,57 +1,179 @@ +/* (CC-BY-NC-SA) ROBIN KRENS - ROBIN @ ROBINKRENS.NL + * + * $LOG$ + * 2019/7/20 - ROBIN KRENS + * Initial version + * + * $DESCRIPTION$ + * Main initialize basic components of the board + * and jumps to a terminal + * + * */ + #include #include #include -#include // <-- my own header file located located in ./include -#include +#include +#include +#include -void *memcpy(void *dest, void *src, size_t count) -{ - const char *sp = (const char *)src; - char *dp = (char *)dest; - for(; count != 0; count--) *dp++ = *sp++; - return dest; -} +#include +#include +#include +#include +#include -/* fillout memory with 'val' (i.e. all zeroes) - */ -void *memset(void *dest, unsigned char val, size_t count) -{ - char *temp = (char *)dest; - for( ; count != 0; count--) *temp++ = val; - return dest; -} +#include +#include +//#include +//#include +//#include +//#include +#include -/* same as above but shorter */ -unsigned short *memsetw(unsigned short *dest, unsigned short val, size_t count) -{ - unsigned short *temp = (unsigned short *)dest; - for( ; count != 0; count--) *temp++ = val; - return dest; -} +#include + + +process_t p1; +process_t p2; + +uint32_t stackp1[500]; +uint32_t stackp2[500]; + +extern int count; + +void switch_usermode() { + + // user mode + //asm volatile ("mov r0, 0x1" "\n\t" + //"msr control, r0" "\n\t" + //"isb" "\n\t"); + + // system init call -int strlen(const char *str) -{ - int retval; - for(retval = 0; *str != '\0'; str++) retval++; - return retval; } +void process1(void) { + + while(1) { + //uint32_t control = 0xFFFFFFFF; + printf("process 1\n"); + //asm volatile("msr control, %0" "\n\t" + // "dsb" : : "r" (control)); + //printf("control: %x", control); + //for(;;); + _block(100); + theos_switch(&p1, &p2); + } +} +void process2(void) { + while(1) { + printf("process 2\n"); + _block(100); + theos_switch(&p2, &p1); + } + +} +int test_data_segment = 99; 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(); + + /* Setup the interrupt vector table */ ivt_init(); + + /* Initialze basic input and output over serial */ uart_init(); + + /* TFT screen */ + // tft_init(); - systick_init(); + /* Set up a very small libc library */ + init_printf(NULL, putc); + + /* Heap init */ + //kheap_init(); + //printf("%p\n", get_kheap()); + /* Display some basic info at startup */ sysinfo(); - terminal(); + /* On board LEDs*/ + led_init(); + + + /* Real time clock */ + rtc_init(); + + +// printf("press any key to start\n"); +// asm volatile ("cpsid f"); // doesn't work in qemu + + syscall_init(); + //int ret; + //ret = theos_test(0x1, 0x2, 0x3); + //ret = theos_uptime(); + + //printf("ret: %d\n", ret); + + 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(); + + // switch_usermode(); + + //printf("without system call"); +// theos_test(0xA1, 0xA2); + + /* Eeprom Driver + eeprom_at24c_init(); + eeprom_test(); + */ + + /* LED Segment Driver */ + //tm1637_init(); + + /* ASM Blocking routine */ + //for (int i = 0; i < 1000; i++) + // _block(10000); + + /* TEMP SENSOR + tsensor_printid(); + uint16_t temp = tsensor_get_temp(); + printf("Current temperature: %d °C\n", temp); */ + + /* ADC Joystick module */ + // mk450_init(); + + + /* Start up terminal */ + terminal(); + + /* Should not be here, endless loop */ for(;;) { }