Advertisement
ebak32

main.c

Apr 9th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.72 KB | None | 0 0
  1. #include <string.h>
  2.  
  3. /* SmartFusion */
  4. #include "a2fxxxm3.h"
  5. #include "core_cm3.h"
  6. #include "mss_gpio.h"
  7. #include "mss_watchdog.h"
  8. #include "mss_uart.h"
  9. #include "mss_pdma.h"
  10.  
  11. /* FreeRTOS */
  12. #include "FreeRTOS.h"
  13. #include "task.h"
  14.  
  15. /**/
  16. #include "printf.h"
  17. #include "utils.h"
  18.  
  19. #include "LoggerTask.h"
  20.  
  21. void vApplicationIdleHook( void ) {
  22.     SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  23. }
  24.  
  25. static void taskBlink(void * params) {
  26.     while (1) {
  27.         MSS_WD_reload();
  28.         GPIO->GPIO_OUT ^= MSS_GPIO_28_MASK;
  29.         vTaskDelay(pdMS_TO_TICKS(250));
  30.     }
  31. }
  32.  
  33. static volatile uint8_t pdmaChannel0TxCompleted = 0;
  34.  
  35. static void pdmaChannel0IsrHandler() {
  36.     pdmaChannel0TxCompleted = 1;
  37.     PDMA_disable_irq(PDMA_CHANNEL_0);   /* Important! */
  38. }
  39.  
  40. static void welcome() {
  41.     char buf[256];
  42.     printUART("Welcome! (polled transmit)\n");
  43.     PDMA_configure(
  44.         PDMA_CHANNEL_0,
  45.         PDMA_TO_UART_0,
  46.         PDMA_LOW_PRIORITY | PDMA_BYTE_TRANSFER | PDMA_INC_SRC_ONE_BYTE,
  47.         PDMA_DEFAULT_WRITE_ADJ
  48.     );
  49.     PDMA_set_irq_handler(PDMA_CHANNEL_0, pdmaChannel0IsrHandler);
  50.     sprintf(buf, "Welcome! (DMA transmit)\n");
  51.     PDMA_start(
  52.         PDMA_CHANNEL_0,
  53.         (uint32_t)buf,  /* Important! Source must be in RAM not eNVM !!! */
  54.         PDMA_UART0_TX_REGISTER,
  55.         strlen(buf)
  56.     );
  57.     while (!pdmaChannel0TxCompleted);
  58. }
  59.  
  60. static void init() {
  61.     MSS_GPIO_init();
  62.     MSS_GPIO_config( MSS_GPIO_31 , MSS_GPIO_OUTPUT_MODE );
  63.     MSS_GPIO_config( MSS_GPIO_30 , MSS_GPIO_OUTPUT_MODE );
  64.     MSS_GPIO_config( MSS_GPIO_29 , MSS_GPIO_OUTPUT_MODE );
  65.     MSS_GPIO_config( MSS_GPIO_28 , MSS_GPIO_OUTPUT_MODE );
  66.     MSS_GPIO_set_outputs(
  67.         MSS_GPIO_28_MASK | MSS_GPIO_29_MASK | MSS_GPIO_30_MASK | MSS_GPIO_31_MASK);
  68.  
  69.     SystemCoreClockUpdate();
  70.  
  71.     MSS_UART_init(
  72.         &g_mss_uart0,
  73.         MSS_UART_460800_BAUD, /*MSS_UART_19200_BAUD,*/ /* MSS_UART_921600_BAUD, */
  74.         MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT
  75.     );
  76.  
  77.     NVIC_SetPriority(DMA_IRQn, 5);
  78.     PDMA_init();
  79.     PDMA_set_priority_ratio(PDMA_ROUND_ROBIN);
  80. }
  81.  
  82. void taskPrintTest(void *params) {
  83.     uint32_t cnt = 0;
  84.     while (1) {
  85.         printf("TaskName: %s, cnt: %d\n", pcTaskGetTaskName(NULL), cnt++);
  86.         vTaskDelay(pdMS_TO_TICKS(250));
  87.         /* TODO look for why only "pr2" is scheduled when the delay is removed !!! */
  88.     }
  89. }
  90.  
  91. int main() {
  92.     init();
  93.     welcome();
  94.  
  95.     initLoggerTask();
  96.  
  97.     xTaskCreate(
  98.         taskBlink, "blink", configMINIMAL_STACK_SIZE, NULL, 3, NULL);
  99.     xTaskCreate(
  100.         taskLogger, "logger", configMINIMAL_STACK_SIZE, NULL, 3, NULL);
  101.     xTaskCreate(
  102.         taskPrintTest, "pr0", configMINIMAL_STACK_SIZE, NULL, 3, NULL);
  103.     xTaskCreate(
  104.         taskPrintTest, "pr1", configMINIMAL_STACK_SIZE, NULL, 3, NULL);
  105.     xTaskCreate(
  106.         taskPrintTest, "pr2", configMINIMAL_STACK_SIZE, NULL, 3, NULL);
  107.     vTaskStartScheduler();
  108.  
  109.     while (1);  // should never be reached
  110.     return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement