diff --git a/src/os/CMakeLists.txt b/src/os/CMakeLists.txt index 5edf2a5..306e59b 100644 --- a/src/os/CMakeLists.txt +++ b/src/os/CMakeLists.txt @@ -25,14 +25,34 @@ target_link_libraries(boot hardware_exception hardware_sync pico_multicore - hagl_hal + hardware_spi + hardware_dma hagl + hagl_hal ) target_compile_definitions(boot PRIVATE - HAGL_HAL_USE_DOUBLE_BUFFER - HAGL_HAL_DEBUG + HAGL_HAL_USE_SINGLE_BUFFER + HAGL_HAL_USE_DMA + HAGL_HAL_DEBUG + MIPI_DISPLAY_PIN_CS=9 + MIPI_DISPLAY_PIN_DC=8 + MIPI_DISPLAY_PIN_RST=12 + MIPI_DISPLAY_PIN_BL=13 + MIPI_DISPLAY_PIN_CLK=10 + MIPI_DISPLAY_PIN_MOSI=11 + MIPI_DISPLAY_PIN_MISO=-1 + MIPI_DISPLAY_SPI_PORT=spi1 +# MIPI_DISPLAY_SPI_CLOCK_SPEED_HZ=680000 + +# MIPI_DISPLAY_PIXEL_FORMAT=MIPI_DCS_PIXEL_FORMAT_16BIT +# MIPI_DISPLAY_ADDRESS_MODE=MIPI_DCS_ADDRESS_MODE_RGB + + MIPI_DISPLAY_WIDTH=320 + MIPI_DISPLAY_HEIGHT=480 + MIPI_DISPLAY_OFFSET_X=0 + MIPI_DISPLAY_OFFSET_Y=0 ) # create map/bin/hex/uf2 file in addition to ELF. -pico_add_extra_outputs(boot) \ No newline at end of file +pico_add_extra_outputs(boot) diff --git a/src/os/boot.c b/src/os/boot.c index b65152f..b2e2cff 100644 --- a/src/os/boot.c +++ b/src/os/boot.c @@ -8,236 +8,60 @@ #include "pico/stdlib.h" #include #include "pico/malloc.h" -#include "hardware/structs/systick.h" -#include "hardware/exception.h" #include "pico/multicore.h" #include "kernel/lock_core.h" -#include "pico/sem.h" #include "kernel/kernel.h" -const uint LED_PIN = 14; -volatile extern uint32_t tickct; -volatile extern int32_t sleep_time; -volatile extern int32_t sleep_core; -volatile extern int32_t sleep_ct; +#include +#include +#include - semaphore_t talking_stick; +hagl_backend_t *display; -/* - * This task blinks the LED. It also holds the semaphore talking_stick - * while the LED is off. This is used to gate the reporter task and keep it - * from printing. - */ -void blinker(void) { - gpio_init(LED_PIN); - gpio_set_dir(LED_PIN, GPIO_OUT); - while (true) { - gpio_put(LED_PIN, 1); - sem_release(&talking_stick); - piccolo_sleep(2000); - gpio_put(LED_PIN, 0); - sem_acquire_blocking(&talking_stick); - piccolo_sleep(2000); - } -} - - -int is_prime(unsigned int n) -{ - unsigned int p; - if (!(n & 1) || n < 2 ) return n == 2; - - // comparing p*p <= n can overflow - for (p = 3; p <= n/p; p += 2) - if (!(n % p)) return 0; - return 1; -} - -/* - * Prime number computing task. Just to burn CPU time - * Note that it never calls piccolo_yield() - */ -uint32_t primes[2], totalPrimes; -piccolo_os_task_t * reporter; - -void find_primes(void) { - int p; - - printf("task2: Created!\n"); - while (1) { - for (p=5;p;p+=2) if(is_prime(p)==1) { - totalPrimes++; - primes[get_core_num()]++; - // every 4096 prime numbers, send the reporter a signal - if(!(totalPrimes & 0xFFF)) piccolo_send_signal(reporter); - } - } -} -/* - * Report on the progress of the prime number finder. Wait until he sends a signal - * Then get the "talking stick" semaphore from the LED blinker task. We can only - * talk when the green light is on! Then print a report. We also report on - * how many tasks the garbage collector has reclaimed using a counter which - * is only there as a debug feature at the moment... - */ -extern uint32_t kills; -void reporter_task(void){ - printf("Reporter Started\n"); - while(1) { - piccolo_get_signal_all_blocking(); - if(!sem_acquire_timeout_ms(&talking_stick,10000)) printf("sem acquire timeout SHOULD NOT have failed\n"); - - printf("Total primes %d, cores 0/1 %d/%d kills %d recycled %d bytes\n", - totalPrimes,primes[0], primes[1], kills, kills*sizeof(piccolo_os_task_t)); - sem_release(&talking_stick); +void continuousDraw(void) { + while (1) { + sleep_ms(2000); + + color_t color = rand() % 0xffff; + + hagl_fill_rectangle(display, 0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, color); + hagl_flush(display); } } -/* - * The next two tasks are created periodically by the stress_tester task - * only to quickly delete themselves. "z" dies immediatly whicle "sz" yields - * once first. - */ -void sz(){ - piccolo_yield(); - return; -} +bool isPrime(unsigned int number) { + for (unsigned int i = 3; i <= number / i; i += 2) { + if (number % i == 0) return true; + } -void z(){ - int a = 1; - return; + return false; } -void stress_tester(void) { - /** - * Force a slew of task create and deletes by creating lots of tasks - * that die very quickly. Do this every few seconds. Note that we - * are perfectly safe creating multiple tasks running the same function - * since they all have seperate stacks. - * - */ - while(1) { - piccolo_create_task(z); - piccolo_create_task(z); - piccolo_create_task(z); - piccolo_create_task(sz); - piccolo_create_task(sz); - piccolo_create_task(sz); - piccolo_create_task(z); - piccolo_create_task(sz); - piccolo_create_task(z); - piccolo_create_task(sz); - piccolo_create_task(sz); - - piccolo_sleep(3000); +void calcPrimes(void) { + unsigned int i = 3; + while (1) { + if (isPrime(i)) printf("%d\n", i); + i += 2; } } +int main() { -void spinner2(void){ - piccolo_os_task_t * task; - task = piccolo_get_task_id(); - while(!piccolo_get_signal()) piccolo_yield(); // spin until we get a signal - piccolo_get_signal_blocking(); // hang until we get a second one -// printf(" signal hang2 task %8X in %d out %d limit %d\n",task,task->signal_in,task->signal_out,task->signal_limit); - piccolo_get_signal_blocking(); // hang until we get a third one -// printf(" semaphore hang task %8X in %d out %d limit %d\n",task,task->signal_in,task->signal_out,task->signal_limit); - sem_acquire_blocking(&talking_stick); // then hang on the semaphore -// printf(" semaphore exit task %8X in %d out %d limit %d\n",task,task->signal_in,task->signal_out,task->signal_limit); - return; // and exit -} -void spinner(){ - int i,yielding=1,blocking=1, semaphore; - absolute_time_t start; - uint64_t time; - piccolo_os_task_t *spin1, *spin2; -#define loops 1000 - piccolo_sleep(10); - start = get_absolute_time(); - for(i=0;i