aboutsummaryrefslogtreecommitdiffstats
path: root/demos/STM32/RT-STM32F070RB-NUCLEO64/main.c
blob: 008949cd8c9f667bfa18a34cb35c724e6e567083 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
    ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

#include "ch.h"
#include "hal.h"
#include "rt_test_root.h"
#include "oslib_test_root.h"

/*
 * Green LED blinker thread, times are in milliseconds.
 */
static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {

  (void)arg;
  chRegSetThreadName("blinker");
  while (true) {
    palClearPad(GPIOA, GPIOA_LED_GREEN);
    chThdSleepMilliseconds(500);
    palSetPad(GPIOA, GPIOA_LED_GREEN);
    chThdSleepMilliseconds(500);
  }
}

/*
 * Application entry point.
 */
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Activates the serial driver 2 using the driver default configuration.
   */
  sdStart(&SD2, NULL);

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  /*
   * Normal main() thread activity, in this demo it does nothing except
   * sleeping in a loop and check the button state.
   */
  while (true) {
    if (!palReadPad(GPIOC, GPIOC_BUTTON)) {
      test_execute((BaseSequentialStream *)&SD2, &rt_test_suite);
      test_execute((BaseSequentialStream *)&SD2, &oslib_test_suite);
    }
    chThdSleepMilliseconds(500);
  }
}
Low_Bound => 2, Table_Initial => 128); package Chunkt is new Tables (Table_Component_Type => Chunk_Type, Table_Index_Type => Chunk_Index_Type, Table_Low_Bound => 1, Table_Initial => 128); Chunk_Free_List : Chunk_Index_Type := No_Chunk_Index; procedure Free_Chunk (Idx : Chunk_Index_Type) is begin Chunkt.Table (Idx).Next := Chunk_Free_List; Chunk_Free_List := Idx; end Free_Chunk; function Get_Free_Chunk return Chunk_Index_Type is Res : Chunk_Index_Type; begin if Chunk_Free_List /= No_Chunk_Index then Res := Chunk_Free_List; Chunk_Free_List := Chunkt.Table (Res).Next; return Res; else return Chunkt.Allocate; end if; end Get_Free_Chunk; function Get_Nbr_Elements (List: List_Type) return Natural is begin return Listt.Table (List).Nbr; end Get_Nbr_Elements; function Is_Empty (List : List_Type) return Boolean is begin return Listt.Table (List).Nbr = 0; end Is_Empty; procedure Append_Element (List: List_Type; Element: El_Type) is L : List_Record renames Listt.Table (List); C : Chunk_Index_Type; begin L.Chunk_Idx := L.Chunk_Idx + 1; if L.Chunk_Idx < Chunk_Len then Chunkt.Table (L.Last).Els (L.Chunk_Idx) := Element; else C := Get_Free_Chunk; Chunkt.Table (C).Next := No_Chunk_Index; Chunkt.Table (C).Els (0) := Element; L.Chunk_Idx := 0; if L.Nbr = 0 then L.First := C; else Chunkt.Table (L.Last).Next := C; end if; L.Last := C; end if; L.Nbr := L.Nbr + 1; end Append_Element; function Get_First_Element (List: List_Type) return El_Type is L : List_Record renames Listt.Table (List); begin pragma Assert (L.Nbr > 0); return Chunkt.Table (L.First).Els (0); end Get_First_Element; -- Add (append) an element only if it was not already present in the list. procedure Add_Element (List: List_Type; El: El_Type) is It : Iterator; begin It := Iterate (List); while Is_Valid (It) loop if Get_Element (It) = El then return; end if; Next (It); end loop; Append_Element (List, El); end Add_Element; -- Chain of unused lists. List_Free_Chain : List_Type := Null_List; function Create_List return List_Type is Res : List_Type; begin if List_Free_Chain = Null_List then Listt.Increment_Last; Res := Listt.Last; else Res := List_Free_Chain; List_Free_Chain := List_Type (Listt.Table (Res).Chunk_Idx); end if; Listt.Table (Res) := List_Record'(First => No_Chunk_Index, Last => No_Chunk_Index, Chunk_Idx => Chunk_Len, Nbr => 0); return Res; end Create_List; procedure Destroy_List (List : in out List_Type) is C, Next_C : Chunk_Index_Type; begin if List = Null_List then return; end if; C := Listt.Table (List).First; while C /= No_Chunk_Index loop Next_C := Chunkt.Table (C).Next; Free_Chunk (C); C := Next_C; end loop; Listt.Table (List).Chunk_Idx := Nat32 (List_Free_Chain); List_Free_Chain := List; List := Null_List; end Destroy_List; procedure Finalize is begin Listt.Free; Chunkt.Free; end Finalize; procedure Initialize is begin Listt.Init; Chunkt.Init; List_Free_Chain := Null_List; Chunk_Free_List := No_Chunk_Index; end Initialize; function Iterate (List : List_Valid_Type) return Iterator is L : List_Record renames Listt.Table (List); begin return Iterator'(Chunk => L.First, Chunk_Idx => 0, Remain => Int32 (L.Nbr)); end Iterate; function Iterate_Safe (List : List_Type) return Iterator is begin if List = Null_List then return Iterator'(Chunk => No_Chunk_Index, Chunk_Idx => 0, Remain => 0); end if; return Iterate (List); end Iterate_Safe; function Is_Valid (It : Iterator) return Boolean is begin return It.Remain > 0; end Is_Valid; procedure Next (It : in out Iterator) is begin It.Chunk_Idx := It.Chunk_Idx + 1; if It.Chunk_Idx = Chunk_Len then It.Chunk := Chunkt.Table (It.Chunk).Next; It.Chunk_Idx := 0; end if; It.Remain := It.Remain - 1; end Next; function Get_Element (It : Iterator) return El_Type is begin return Chunkt.Table (It.Chunk).Els (It.Chunk_Idx); end Get_Element; procedure Set_Element (It : Iterator; El : El_Type) is begin Chunkt.Table (It.Chunk).Els (It.Chunk_Idx) := El; end Set_Element; end Lists;