Advertisement
Guest User

arm

a guest
Oct 21st, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.96 KB | None | 0 0
  1. #include "stm32f4xx.h"
  2. #include "stm32f4_discovery_audio_codec/stm32f4_discovery_audio_codec.h"
  3.  
  4. #include "stm32f4_discovery.h"
  5. #include "STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_tim.h"
  6. #include "STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_rcc.h"
  7. #include <math.h>
  8.  
  9. #include "FreeRTOS/include/FreeRTOS.h"
  10. #include "FreeRTOS/include/task.h"
  11. #include "FreeRTOS/include/semphr.h"
  12.  
  13. uint64_t u64IdleTicksCnt=0; // Counts when the OS has no task to execute.
  14. uint64_t tickTime=0;        // Counts OS ticks (default = 1000Hz).
  15.  
  16. void GPIO_A0_Init(void);
  17.  
  18. void vButtonTask (void * pvparameters);
  19.  
  20. void InitializeTimer()
  21. {
  22.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
  23.  
  24.     TIM_TimeBaseInitTypeDef timerInitStructure;
  25.     timerInitStructure.TIM_Prescaler = 40000;
  26.     timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
  27.     timerInitStructure.TIM_Period = 500;
  28.     timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  29.     timerInitStructure.TIM_RepetitionCounter = 0;
  30.     TIM_TimeBaseInit(TIM2, &timerInitStructure);
  31.     TIM_Cmd(TIM2, ENABLE);
  32. }
  33.  
  34. //TIM_Channel_3
  35.  
  36. //TIM_Break_Disable
  37. //TIM_Break_Enable
  38.  
  39. //TIM_BreakPolarity_Low
  40.  
  41. /*
  42.  * When FreeRTOS crashes, you often end up in a hard fault.
  43.  */
  44. void HardFault_Handler (void){
  45.     STM_EVAL_LEDOn(LED3);
  46.     STM_EVAL_LEDOn(LED4);
  47.     STM_EVAL_LEDOn(LED5);
  48.     STM_EVAL_LEDOn(LED6);
  49. }
  50.  
  51.  
  52. int main(void)
  53. {
  54.     STM_EVAL_LEDInit(LED3);
  55.     STM_EVAL_LEDInit(LED4);
  56.     STM_EVAL_LEDInit(LED5);
  57.     STM_EVAL_LEDInit(LED6);
  58.     STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);
  59.  
  60.     xTaskCreate( vButtonTask, ( signed char * ) "Button Task", 100, NULL, 1, NULL );
  61.  
  62.     xTaskCreate( TIM5_Task, ( signed char * ) "Timer5 Task", 100, NULL, 1, NULL );
  63.  
  64.     vTaskStartScheduler(); // This should never return.
  65.  
  66.  
  67.     while(1)
  68.     {
  69.  
  70.     }
  71.  
  72.     return 1;
  73. }
  74.  
  75. // zakladam ze tick timera to jakies 10 ms, a taska 200 ms
  76.  
  77. void TIM5_Task( void *pvparameters )
  78. {
  79.  
  80.     uint32_t i1 = 0;  // poprzedni odczyt
  81.     uint32_t i2;  // aktualny odczyt
  82.  
  83.     uint32_t i3; // podziel przez czas task, a wyjdzie impulsy na czas
  84.  
  85.     uint32_t i4; // impulsy przez sekunde
  86.  
  87.     for (;;)
  88.     {
  89.         i2 = TIM_GetCounter(TIM2);
  90.  
  91.         i3 = i2 - i1;
  92.         i2 = i3;
  93.  
  94.  
  95.         // i4 jest naszym wynikiem i idzie dalej do funkcji co go wyswietli w odpowiednim formacie.
  96.         i4 = (i3 / 0,2);
  97.  
  98.  
  99.  
  100.  
  101.         if ( TIM_GetCounter(TIM2) == 2000 ) // zabezpieczenie przekroczenia zakresu gdy brak impulsow
  102.         {
  103.             i1 = i2 = i3 = i4 = 0;
  104.         }
  105.  
  106.         vTaskDelay(200 / portTICK_RATE_MS);
  107.     }
  108. }
  109.  
  110. /*
  111.  * A task that read reads and debounces the user's button
  112.  */
  113. void vButtonTask( void *pvparameters )
  114. {
  115.  
  116.     uint8_t wasPressed = 0;
  117.  
  118.     for (;;){
  119.  
  120.         while (STM_EVAL_PBGetState(BUTTON_USER) == 1) {
  121.             wasPressed = 1;
  122.         }
  123.  
  124.         if (wasPressed){
  125.             STM_EVAL_LEDToggle(LED4);
  126.             wasPressed = 0;
  127.         }
  128.  
  129.         vTaskDelay(30 / portTICK_RATE_MS);
  130.     }
  131. }
  132.  
  133. // This FreeRTOS callback function gets called once per tick (default = 1000Hz).
  134. // ----------------------------------------------------------------------------
  135. void vApplicationTickHook( void ) {
  136.     ++tickTime;
  137. }
  138.  
  139. // This FreeRTOS call-back function gets when no other task is ready to execute.
  140. // On a completely unloaded system this is getting called at over 2.5MHz!
  141. // ----------------------------------------------------------------------------
  142. void vApplicationIdleHook( void ) {
  143.     ++u64IdleTicksCnt;
  144. }
  145.  
  146. // A required FreeRTOS function.
  147. // ----------------------------------------------------------------------------
  148. void vApplicationMallocFailedHook( void ) {
  149.     configASSERT( 0 );  // Latch on any failure / error.
  150. }
  151.  
  152.  
  153. /*
  154.  * Required callbacks for audio playback
  155.  */
  156. uint16_t EVAL_AUDIO_GetSampleCallBack(void)
  157. {
  158.     return 1;
  159. }
  160.  
  161. void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size)
  162. {
  163. }
  164.  
  165. void EVAL_AUDIO_HalfTransfer_CallBack(uint32_t pBuffer, uint32_t Size)
  166. {
  167. }
  168.  
  169. void EVAL_AUDIO_Error_CallBack(void* pData)
  170. {
  171.     while(1);
  172. }
  173.  
  174. uint32_t Codec_TIMEOUT_UserCallback(void)
  175. {
  176.     while(1);
  177.     return 1;
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement