Contiki-NG
rom-util.h
Go to the documentation of this file.
1 /*
2  * Original file:
3  * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
4  * All rights reserved.
5  *
6  * Port to Contiki:
7  * Copyright (c) 2013, ADVANSEE - http://www.advansee.com/
8  * Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  *
20  * 3. Neither the name of the copyright holder nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35  * OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 /**
38  * \addtogroup cc2538
39  * @{
40  *
41  * \defgroup cc2538-rom-util cc2538 ROM utility function library
42  *
43  * Driver for the cc2538 ROM utility function library
44  * @{
45  *
46  * \file
47  * Header file for the cc2538 ROM utility function library driver
48  */
49 #ifndef ROM_UTIL_H_
50 #define ROM_UTIL_H_
51 
52 #include "contiki.h"
53 
54 #include <stddef.h>
55 #include <stdint.h>
56 /*---------------------------------------------------------------------------*/
57 /** \name ROM utility function library API access table structure
58  * @{
59  */
60 struct rom_util_api {
61  /** Calculate CRC32 over a given address range */
62  uint32_t (*crc32)(uint8_t *data, uint32_t byte_count);
63 
64  /** Return the flash size */
65  uint32_t (*get_flash_size)(void);
66 
67  /** Return the chip ID */
68  uint32_t (*get_chip_id)(void);
69 
70  /** Erase flash pages */
71  int32_t (*page_erase)(uint32_t flash_addr, uint32_t size);
72 
73  /** Program the flash */
74  int32_t (*program_flash)(uint32_t *ram_data, uint32_t flash_addr,
75  uint32_t byte_count);
76 
77  /** Perform a system reset of the SoC */
78  void (*reset_device)(void);
79 
80  /** Set a memory area to a specified value */
81  void *(*memset)(void *s, int c, size_t n);
82 
83  /** Copy data from one memory area to another */
84  void *(*memcpy)(void *dest, const void *src, size_t n);
85 
86  /** Compare two memory areas */
87  int (*memcmp)(const void *s1, const void *s2, size_t n);
88 
89  /** Move a block of data from one memory area to another */
90  void *(*memmove)(void *dest, const void *src, size_t n);
91 };
92 /** @} */
93 /*---------------------------------------------------------------------------*/
94 /** \name Pointer to the ROM utility function library API table
95  * @{
96  */
97 #define ROM_UTIL_API ((struct rom_util_api *)0x00000048)
98 /** @} */
99 /*---------------------------------------------------------------------------*/
100 /** \name ROM utility function library API accessor macros
101  * @{
102  */
103 #define rom_util_crc32(data, byte_count) \
104  (ROM_UTIL_API->crc32((data), (byte_count)))
105 #define rom_util_get_flash_size() \
106  (ROM_UTIL_API->get_flash_size())
107 #define rom_util_get_chip_id() \
108  (ROM_UTIL_API->get_chip_id())
109 #define rom_util_page_erase(flash_addr, size) \
110  (ROM_UTIL_API->page_erase((flash_addr), (size)))
111 #define rom_util_program_flash(ram_data, flash_addr, byte_count) \
112  (ROM_UTIL_API->program_flash((ram_data), (flash_addr), (byte_count)))
113 #define rom_util_reset_device() \
114  (ROM_UTIL_API->reset_device())
115 #define rom_util_memset(s, c, n) \
116  (ROM_UTIL_API->memset((s), (c), (n)))
117 #define rom_util_memcpy(dest, src, n) \
118  (ROM_UTIL_API->memcpy((dest), (src), (n)))
119 #define rom_util_memcmp(s1, s2, n) \
120  (ROM_UTIL_API->memcmp((s1), (s2), (n)))
121 #define rom_util_memmove(dest, src, n) \
122  (ROM_UTIL_API->memmove((dest), (src), (n)))
123 /** @} */
124 
125 #endif /* ROM_UTIL_H_ */
126 
127 /**
128  * @}
129  * @}
130  */