Revision bc7aed20

View differences:

core/src/aos_main.cpp
123 123
 * @param[in] mask    The event mask.
124 124
 * @param[in] flags   The event flags.
125 125
 */
126
static inline void _unexpectedEventError(const eventmask_t mask, const eventflags_t flags)
126
inline void _unexpectedEventError(const eventmask_t mask, const eventflags_t flags)
127 127
{
128 128
#if (AMIROOS_CFG_DBG == true)
129
  aosprintf("CTRL: unexpected/unknown event received. mask: 0x%08X; flags: 0x%08X\n", mask, flags);
129
  aosDbgPrintf("CTRL: unexpected/unknown event received. mask: 0x%08X; flags: 0x%08X\n", mask, flags);
130 130
#else /* (AMIROOS_CFG_DBG == true) */
131 131
  (void)(mask);
132 132
  (void)(flags);
......
134 134
  return;
135 135
}
136 136

  
137
/**
138
 * @brief   Helper function to serialize data.
139
 *
140
 * @param[out]  dst   Pointer to the output buffer.
141
 * @param[in]   src   Data to be serialized.
142
 * @param[in]   n     Number of bytes to serialize.
143
 */
144
inline void _serialize(uint8_t* dst, const uint64_t src, const uint8_t n)
145
{
146
  aosDbgCheck(dst != NULL);
147
  aosDbgCheck(n > 0 && n <= 8);
148

  
149
  for (uint8_t byte = 0; byte < n; ++byte) {
150
    dst[byte] = (uint8_t)((src >> (byte * 8)) & 0xFF);
151
  }
152

  
153
  return;
154
}
155

  
156
/**
157
 * @brief   Helper function to deserialize data.
158
 *
159
 * @param[in] src   Pointer to the buffer of data to be deserialzed.
160
 * @param[in] n     Number of bytes to deserialize.
161
 *
162
 * @return    The deserialized 32 bit data.
163
 */
164
inline uint64_t _deserialize(uint8_t* src, const uint8_t n)
165
{
166
  aosDbgCheck(src != NULL);
167
  aosDbgCheck(n > 0 && n <= 8);
168

  
169
  uint64_t result = 0;
170
  for (uint8_t byte = 0; byte < n; ++byte) {
171
    result |= ((uint64_t)src[byte]) << (byte * 8);
172
  }
173

  
174
  return result;
175
}
176

  
177
#if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__)
137
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (HAL_USE_RTC == TRUE)) || defined(__DOXYGEN__)
138
#if (AMIROOS_CFG_SSSP_MASTER == true) || defined(__DOXYGEN__)
178 139

  
179 140
/**
180 141
 * @brief   Converter function to encode a TM value to a single unsigned 64 bit integer.
......
209 170
}
210 171

  
211 172
/**
173
 * @brief   Serializes 64 bit unsigned integer input and stores it in a byte array.
174
 * @details Serialization is performed in big-endian fashion.
175
 *
176
 * @param[out]  dst   Pointer to the output buffer.
177
 * @param[in]   src   Data to be serialized.
178
 */
179
inline void _serializeU64(uint8_t* dst, const uint64_t src)
180
{
181
  aosDbgCheck(dst != NULL);
182

  
183
  for (uint8_t byte = 0; byte < sizeof(uint64_t); ++byte) {
184
    dst[byte] = ((src >> ((sizeof(uint64_t) - (byte+1)) * 8)) & 0xFF);
185
  }
186

  
187
  return;
188
}
189

  
190
#endif /* (AMIROOS_CFG_SSSP_MASTER == true) */
191
#if (AMIROOS_CFG_SSSP_MASTER != true) || defined(__DOXYGEN__)
192

  
193
/**
194
 * @brief   Deserialize 64 bit unsigned integer data from a buffer.
195
 * @details Data is assumed to be serialized in big-endian fashion.
196
 *
197
 * @param[in] src   Pointer to the buffer of data to be deserialzed.
198
 *
199
 * @return    Deserialized 64 bit data.
200
 */
201
inline uint64_t _deserializeU64(uint8_t* src)
202
{
203
  aosDbgCheck(src != NULL);
204

  
205
  uint64_t result = 0;
206
  for (uint8_t byte = 0; byte < sizeof(uint64_t); ++byte) {
207
    result |= ((uint64_t)src[byte] << ((sizeof(uint64_t) - (byte+1)) * 8));
208
  }
209

  
210
  return result;
211
}
212

  
213
/**
212 214
 * @brief   Converter functiomn to retrieve the encoded TM value from an unsigned 64 bit integer.
213 215
 *
214 216
 * @details For information on the encoding, please refer to @p _TM2U64 function.
......
233 235
  return;
234 236
}
235 237

  
236
#endif /* (HAL_USE_RTC == TRUE) */
238
#endif /* (AMIROOS_CFG_SSSP_MASTER != true) */
239
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (HAL_USE_RTC == TRUE) */
237 240

  
238 241
/**
239 242
 * @brief   Application entry point.
......
657 660

  
658 661
#if (HAL_USE_RTC == TRUE)
659 662

  
660
  //TODO: Calendar synchronization
663
  /*
664
   * calendar synchronization
665
   *
666
   * Although calendar synchronization does not inherently rely on SSSP, this
667
   * implementation uses the moduleSsspBcbX() functions, defined by SSSP in
668
   * order to save redundant code. Furthermore, it is rather unlikely that
669
   * system wide synchronization of calendars is desired when SSSP is disabled
670
   * anyway.
671
   */
672
 if (shutdown == AOS_SHUTDOWN_NONE) {
673
#if (AMIROOS_CFG_SSSP_MASTER == true)
674
   // temporary variables
675
   struct tm t;
676
   uint8_t buffer[sizeof(uint64_t)];
677

  
678
   // get current date/time
679
   aosSysGetDateTime(&t);
680
   // encode & serialize
681
   _serializeU64(buffer, _TM2U64(&t));
682
   // transmit
683
   aosDbgPrintf("transmitting current date/time...\t");
684
   if (moduleSsspBcbTransmit(buffer, sizeof(uint64_t)) == AOS_SSSP_BCB_SUCCESS) {
685
     aosDbgPrintf("ok\n");
686
   } else {
687
     aosDbgPrintf("fail\n");
688
   }
689
#else /* (AMIROOS_CFG_SSSP_MASTER == true) */
690
   // temporary variables
691
   aos_timestamp_t start, now;
692
   aos_ssspbcbstatus_t bcbstatus;
693
   uint8_t buffer[sizeof(uint64_t)];
694
   struct tm t;
695

  
696
   // receive
697
   aosDbgPrintf("receiving current date/time...\t");
698
   aosSysGetUptime(&start);
699
   do {
700
     bcbstatus = moduleSsspBcbReceive(buffer, sizeof(uint64_t));
701
     aosSysGetUptime(&now);
702
   } while ((bcbstatus != AOS_SSSP_BCB_SUCCESS) && ((now - start) < AOS_SSSP_TIMEOUT));
703
   // if something was received
704
   if (bcbstatus == AOS_SSSP_BCB_SUCCESS) {
705
     // deserialize & decode
706
     _U642TM(&t, _deserializeU64(buffer));
707
     // set current date/time
708
     aosSysSetDateTime(&t);
709
     aosDbgPrintf("ok\n");
710
   } else {
711
     aosDbgPrintf("fail\n");
712
   }
713
#endif /* (AMIROOS_CFG_SSSP_MASTER == true) */
714
 }
661 715

  
662 716
#endif /* (HAL_USE_RTC == TRUE) */
663 717
#endif /* (AMIROOS_CFG_SSSP_MSI == true) */
core/src/aos_sssp.c
324 324
    {
325 325
      buffer[0] = message.type;
326 326
      for (size_t byte = 0; byte < sizeof(aos_ssspmoduleid_t); ++byte) {
327
        buffer[byte+1] = (message.payload.id >> (8 * (sizeof(aos_ssspmoduleid_t) - (byte+1)))) & 0xFF;
327
        buffer[byte+1] = (message.payload.id >> ((sizeof(aos_ssspmoduleid_t) - (byte+1)) * 8)) & 0xFF;
328 328
      }
329 329
      return AOS_SUCCESS;
330 330
    }
......
361 361
    {
362 362
      message->payload.id = 0;
363 363
      for (size_t byte = 0; byte < sizeof(aos_ssspmoduleid_t); ++byte) {
364
        message->payload.id |= (aos_ssspmoduleid_t)(buffer[byte+1] << (8 * (sizeof(aos_ssspmoduleid_t) - (byte+1))));
364
        message->payload.id |= (aos_ssspmoduleid_t)(buffer[byte+1] << ((sizeof(aos_ssspmoduleid_t) - (byte+1)) * 8));
365 365
      }
366 366
      return AOS_SUCCESS;
367 367
    }

Also available in: Unified diff