Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- /* SmartFusion */
- #include "a2fxxxm3.h"
- #include "core_cm3.h"
- #include "mss_gpio.h"
- #include "mss_watchdog.h"
- #include "mss_uart.h"
- #include "mss_pdma.h"
- /* FreeRTOS */
- #include "FreeRTOS.h"
- #include "task.h"
- /**/
- #include "printf.h"
- #include "utils.h"
- #include "LoggerTask.h"
- void vApplicationIdleHook( void ) {
- SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
- }
- static void taskBlink(void * params) {
- while (1) {
- MSS_WD_reload();
- GPIO->GPIO_OUT ^= MSS_GPIO_28_MASK;
- vTaskDelay(pdMS_TO_TICKS(250));
- }
- }
- static volatile uint8_t pdmaChannel0TxCompleted = 0;
- static void pdmaChannel0IsrHandler() {
- pdmaChannel0TxCompleted = 1;
- PDMA_disable_irq(PDMA_CHANNEL_0); /* Important! */
- }
- static void welcome() {
- char buf[256];
- printUART("Welcome! (polled transmit)\n");
- PDMA_configure(
- PDMA_CHANNEL_0,
- PDMA_TO_UART_0,
- PDMA_LOW_PRIORITY | PDMA_BYTE_TRANSFER | PDMA_INC_SRC_ONE_BYTE,
- PDMA_DEFAULT_WRITE_ADJ
- );
- PDMA_set_irq_handler(PDMA_CHANNEL_0, pdmaChannel0IsrHandler);
- sprintf(buf, "Welcome! (DMA transmit)\n");
- PDMA_start(
- PDMA_CHANNEL_0,
- (uint32_t)buf, /* Important! Source must be in RAM not eNVM !!! */
- PDMA_UART0_TX_REGISTER,
- strlen(buf)
- );
- while (!pdmaChannel0TxCompleted);
- }
- static void init() {
- MSS_GPIO_init();
- MSS_GPIO_config( MSS_GPIO_31 , MSS_GPIO_OUTPUT_MODE );
- MSS_GPIO_config( MSS_GPIO_30 , MSS_GPIO_OUTPUT_MODE );
- MSS_GPIO_config( MSS_GPIO_29 , MSS_GPIO_OUTPUT_MODE );
- MSS_GPIO_config( MSS_GPIO_28 , MSS_GPIO_OUTPUT_MODE );
- MSS_GPIO_set_outputs(
- MSS_GPIO_28_MASK | MSS_GPIO_29_MASK | MSS_GPIO_30_MASK | MSS_GPIO_31_MASK);
- SystemCoreClockUpdate();
- MSS_UART_init(
- &g_mss_uart0,
- MSS_UART_460800_BAUD, /*MSS_UART_19200_BAUD,*/ /* MSS_UART_921600_BAUD, */
- MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT
- );
- NVIC_SetPriority(DMA_IRQn, 5);
- PDMA_init();
- PDMA_set_priority_ratio(PDMA_ROUND_ROBIN);
- }
- void taskPrintTest(void *params) {
- uint32_t cnt = 0;
- while (1) {
- printf("TaskName: %s, cnt: %d\n", pcTaskGetTaskName(NULL), cnt++);
- vTaskDelay(pdMS_TO_TICKS(250));
- /* TODO look for why only "pr2" is scheduled when the delay is removed !!! */
- }
- }
- int main() {
- init();
- welcome();
- initLoggerTask();
- xTaskCreate(
- taskBlink, "blink", configMINIMAL_STACK_SIZE, NULL, 3, NULL);
- xTaskCreate(
- taskLogger, "logger", configMINIMAL_STACK_SIZE, NULL, 3, NULL);
- xTaskCreate(
- taskPrintTest, "pr0", configMINIMAL_STACK_SIZE, NULL, 3, NULL);
- xTaskCreate(
- taskPrintTest, "pr1", configMINIMAL_STACK_SIZE, NULL, 3, NULL);
- xTaskCreate(
- taskPrintTest, "pr2", configMINIMAL_STACK_SIZE, NULL, 3, NULL);
- vTaskStartScheduler();
- while (1); // should never be reached
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement