Skip to content
Snippets Groups Projects
Select Git revision
  • 5054fdeb41778ad4ac6c8021a930b81ab11aa53f
  • master default protected
  • fix-warnings
  • tvbgone-fixes
  • genofire/ble-follow-py
  • schneider/ble-stability-new-phy-adv
  • schneider/ble-stability
  • msgctl/gfx_rle
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
36 results

main.c

Blame
  • Forked from card10 / firmware
    1718 commits behind the upstream repository.
    Rahix's avatar
    rahix authored
    Hopefully fixes #5.
    
    Signed-off-by: default avatarRahix <rahix@rahix.de>
    5054fdeb
    History
    main.c 1.88 KiB
    #include <stdio.h>
    #include <stdlib.h>
    
    #include "max32665.h"
    #include "uart.h"
    #include "cdcacm.h"
    
    #include "card10.h"
    #include "pmic.h"
    #include "leds.h"
    #include "api/dispatcher.h"
    #include "serial.h"
    
    #include "FreeRTOS.h"
    #include "task.h"
    
    TaskHandle_t dispatcher_task_id;
    
    /* TODO: Move out of main.c */
    void epic_leds_set(int led, uint8_t r, uint8_t g, uint8_t b)
    {
    	leds_set(led, r, g, b);
    	leds_update();
    }
    
    /*
     * API dispatcher task.  This task will sleep until an API call is issued and
     * then wake up to dispatch it.
     */
    void vApiDispatcher(void*pvParameters)
    {
    	while (1) {
    		if (api_dispatcher_poll()) {
    			api_dispatcher_exec();
    		}
    		ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
    	}
    }
    
    static void pmic_button(bool falling)
    {
    	if (falling) {
    		printf("Resetting ...\n");
    		/*
    		 * Give the UART fifo time to clear.
    		 * TODO: Do this properly
    		 */
    		for (int i = 0; i < 0x1000000; i++) {
    			__asm volatile("nop");
    		}
    		MXC_GCR->rstr0 = MXC_F_GCR_RSTR0_SYSTEM;
    	}
    }
    
    int main(void)
    {
    	card10_init();
    	card10_diag();
    
    	/* TODO: Move this to its own function */
    	SCB->SCR |= SCB_SCR_SEVONPEND_Msk;
    
    	pmic_set_button_callback(pmic_button);
    
    	cdcacm_init();
    
    	printf("=> Initializing tasks ...\n");
    
    	/* Serial */
    	if (xTaskCreate(
    		vSerialTask,
    		(const char*)"Serial",
    		configMINIMAL_STACK_SIZE,
    		NULL,
    		tskIDLE_PRIORITY + 1,
    		NULL
    	) != pdPASS) {
    		printf("Failed to create serial-comms task!\n");
    		abort();
    	}
    
    	if (xTaskCreate(
    		vApiDispatcher,
    		(const char*)"API Dispatcher",
    		configMINIMAL_STACK_SIZE,
    		NULL,
    		tskIDLE_PRIORITY  + 2,
    		&dispatcher_task_id
    	) != pdPASS) {
    		printf("Failed to create api dispatcher task!\n");
    		abort();
    	}
    
    	printf("=> Initializing dispatcher ...\n");
    	api_dispatcher_init();
    
    	printf("=> Starting core1 payload ...\n");
    	core1_start();
    
    	printf("=> Starting FreeRTOS ...\n");
    	vTaskStartScheduler();
    	printf("ERROR: FreeRTOS did not start due to unknown error!\n");
    }