Browse Source

Removed timers use from 1wire, timers disabled, fixed overflow bug

Ondřej Hruška 1 year ago
parent
commit
887887b675
Signed by: Ondřej Hruška <ondra@ondrovo.com> GPG key ID: 2C5FD5035250423D
5 changed files with 19 additions and 26 deletions
  1. 1 1
      FreeRTOSConfig.h
  2. 3 1
      cortex_handlers.c
  3. 1 1
      freertos.c
  4. 0 12
      units/1wire/_ow_init.c
  5. 14 11
      units/1wire/unit_1wire.c

+ 1 - 1
FreeRTOSConfig.h View File

@@ -110,7 +110,7 @@ extern uint32_t SystemCoreClock;
110 110
 #define configCHECK_FOR_STACK_OVERFLOW           2
111 111
 #define configENABLE_BACKWARD_COMPATIBILITY      0
112 112
 
113
-#define configUSE_TIMERS                         1
113
+#define configUSE_TIMERS                         0
114 114
 #define configTIMER_TASK_PRIORITY                TSK_TIMERS_PRIO // above normal
115 115
 #define configTIMER_TASK_STACK_DEPTH             TSK_STACK_TIMERS //128
116 116
 #define configTIMER_QUEUE_LENGTH                 4

+ 3 - 1
cortex_handlers.c View File

@@ -13,8 +13,10 @@
13 13
 
14 14
 void SysTick_Handler(void)
15 15
 {
16
-    GEX_MsTick();
16
+    // OS first, avoids jitter
17 17
     osSystickHandler();
18
+    // GEX periodic updates
19
+    GEX_MsTick();
18 20
 }
19 21
 
20 22
 

+ 1 - 1
freertos.c View File

@@ -147,7 +147,7 @@ void MX_FREERTOS_Init(void) {
147 147
   stackmon_register("Main", mainTaskStack, sizeof(mainTaskStack));
148 148
   stackmon_register("Job+Msg", msgJobQueTaskStack, sizeof(msgJobQueTaskStack));
149 149
   stackmon_register("Idle", xIdleStack, sizeof(xIdleStack));
150
-  stackmon_register("Timers", xTimersStack, sizeof(xTimersStack));
150
+//  stackmon_register("Timers", xTimersStack, sizeof(xTimersStack));
151 151
   /* USER CODE END Init */
152 152
 
153 153
   /* Create the mutex(es) */

+ 0 - 12
units/1wire/_ow_init.c View File

@@ -14,15 +14,6 @@ error_t OW_preInit(Unit *unit)
14 14
     struct priv *priv = unit->data = calloc_ck(1, sizeof(struct priv));
15 15
     if (priv == NULL) return E_OUT_OF_MEM;
16 16
 
17
-    // the timer is not started until needed
18
-    priv->busyWaitTimer = xTimerCreate("1w_tim", // name
19
-                                       750,      // interval (will be changed when starting it)
20
-                                       true,     // periodic (we use this only for the polling variant, the one-shot will stop the timer in the CB)
21
-                                       unit,     // user data
22
-                                       OW_TimerCb); // callback
23
-
24
-    if (priv->busyWaitTimer == NULL) return E_OUT_OF_MEM;
25
-
26 17
     // some defaults
27 18
     priv->pin_number = 0;
28 19
     priv->port_name = 'A';
@@ -63,9 +54,6 @@ void OW_deInit(Unit *unit)
63 54
     // Release all resources
64 55
     rsc_teardown(unit);
65 56
 
66
-    // Delete the software timer
67
-    assert_param(pdPASS == xTimerDelete(priv->busyWaitTimer, 1000));
68
-
69 57
     // Free memory
70 58
     free_ck(unit->data);
71 59
 }

+ 14 - 11
units/1wire/unit_1wire.c View File

@@ -38,12 +38,13 @@ static void OW_TimerRespCb(Job *job)
38 38
  *
39 39
  * @param xTimer
40 40
  */
41
-void OW_TimerCb(TimerHandle_t xTimer)
41
+void OW_tickHandler(Unit *unit)
42 42
 {
43
-    Unit *unit = pvTimerGetTimerID(xTimer);
44
-    assert_param(unit);
45 43
     struct priv *priv = unit->data;
46
-    assert_param(priv->busy);
44
+    if(!priv->busy) {
45
+        dbg("ow tick should be disabled now!");
46
+        return;
47
+    }
47 48
 
48 49
     if (priv->parasitic) {
49 50
         // this is the end of the 750ms measurement time
@@ -56,7 +57,8 @@ void OW_TimerCb(TimerHandle_t xTimer)
56 57
 
57 58
         uint32_t time = PTIM_GetTime();
58 59
         if (time - priv->busyStart > 1000) {
59
-            xTimerStop(xTimer, 100);
60
+            unit->tick_interval = 0;
61
+            unit->_tick_cnt = 0;
60 62
 
61 63
             Job j = {
62 64
                 .unit = unit,
@@ -69,7 +71,8 @@ void OW_TimerCb(TimerHandle_t xTimer)
69 71
 
70 72
     return;
71 73
 halt_ok:
72
-    xTimerStop(xTimer, 100);
74
+    unit->tick_interval = 0;
75
+    unit->_tick_cnt = 0;
73 76
 
74 77
     Job j = {
75 78
         .unit = unit,
@@ -79,7 +82,6 @@ halt_ok:
79 82
     scheduleJob(&j);
80 83
 }
81 84
 
82
-
83 85
 enum PinCmd_ {
84 86
     CMD_CHECK_PRESENCE = 0, // simply tests that any devices are attached
85 87
     CMD_SEARCH_ADDR = 1,    // perform a scan of the bus, retrieving all found device ROMs
@@ -120,13 +122,13 @@ static error_t OW_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, Pay
120 122
          */
121 123
         case CMD_POLL_FOR_1:
122 124
             // This can't be exposed via the UU API, due to being async
125
+            unit->_tick_cnt = 0;
126
+            unit->tick_interval = 750;
123 127
             if (priv->parasitic) {
124
-                assert_param(pdPASS == xTimerChangePeriod(priv->busyWaitTimer, 750, 100));
128
+                unit->tick_interval = 750;
125 129
             } else {
126
-                // every 10 ticks
127
-                assert_param(pdPASS == xTimerChangePeriod(priv->busyWaitTimer, 10, 100));
130
+                unit->tick_interval = 10;
128 131
             }
129
-            assert_param(pdPASS == xTimerStart(priv->busyWaitTimer, 100));
130 132
             priv->busy = true;
131 133
             priv->busyStart = PTIM_GetTime();
132 134
             priv->busyRequestId = frame_id;
@@ -242,4 +244,5 @@ const UnitDriver UNIT_1WIRE = {
242 244
     .deInit = OW_deInit,
243 245
     // Function
244 246
     .handleRequest = OW_handleRequest,
247
+    .updateTick = OW_tickHandler,
245 248
 };