Blame view

RIOT/drivers/periph_common/flashpage.c 1.17 KB
fb11e647   vrobic   reseau statique a...
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
  /*
   * Copyright (C) 2016 Freie Universitรคt Berlin
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @ingroup     drivers
   * @{
   *
   * @file
   * @brief       Common flash page functions
   *
   * @author      Hauke Petersen <hauke.petersen@fu-berlin.de>
   *
   * @}
   */
  
  #include <string.h>
  #include "cpu.h"
  #include "assert.h"
  
  /* guard this file, must be done before including periph/flashpage.h
   * TODO: remove as soon as periph drivers can be build selectively */
  #if defined(FLASHPAGE_NUMOF) && defined(FLASHPAGE_SIZE)
  
  #include "periph/flashpage.h"
  
  void flashpage_read(int page, void *data)
  {
      assert(page < FLASHPAGE_NUMOF);
  
      memcpy(data, flashpage_addr(page), FLASHPAGE_SIZE);
  }
  
  int flashpage_verify(int page, void *data)
  {
      assert(page < FLASHPAGE_NUMOF);
  
      if (memcmp(flashpage_addr(page), data, FLASHPAGE_SIZE) == 0) {
          return FLASHPAGE_OK;
      }
      else {
          return FLASHPAGE_NOMATCH;
      }
  }
  
  int flashpage_write_and_verify(int page, void *data)
  {
      flashpage_write(page, data);
      return flashpage_verify(page, data);
  }
  
  #endif