chip_info.h
Go to the documentation of this file.
1 /*
2  * SocialLedge.com - Copyright (C) 2013
3  *
4  * This file is part of free software framework for embedded processors.
5  * You can use it and/or distribute it as long as this copyright header
6  * remains unmodified. The code is free for personal use and requires
7  * permission to use in a commercial product.
8  *
9  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
10  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
12  * I SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
13  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
14  *
15  * You can reach the author of this software at :
16  * p r e e t . w i k i @ g m a i l . c o m
17  */
18 
29 #ifndef CHIP_INFO_H__
30 #define CHIP_INFO_H__
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 #include <stdint.h>
35 #include <string.h> // memcpy()
36 
37 
38 
40 static inline const uint32_t* chip_get_magic_location(void) { return (const uint32_t*) 0xF000; }
41 
43 static inline uint32_t chip_get_prog_count(void) { return *(chip_get_magic_location() + 0); }
44 
46 static inline uint32_t chip_get_prog_modify_count(void) { return *(chip_get_magic_location() + 1); }
47 
49 static inline uint32_t chip_get_prog_max(void) { return *(chip_get_magic_location() + 2); }
50 
52 static inline uint32_t chip_get_prog_min(void) { return *(chip_get_magic_location() + 3); }
53 
55 static inline uint32_t chip_get_prog_time_ms(void) { return *(chip_get_magic_location() + 4); }
56 
57 
58 
63 static inline void chip_program_from_filename(const char* filename)
64 {
65  // These magic constants and memory locations must match up with hyperload bootloader.
66  const uint32_t maxChars = 12;
67  const uint32_t signature = 0xDEADD00D;
68  volatile uint32_t *pCommandReg = &(LPC_RTC->GPREG0);
69  volatile uint32_t *pFilename = &(LPC_RTC->GPREG1);
70 
71  // Do not use strcpy(), it will not work!
72  memcpy((void*) pFilename, filename, maxChars);
73 
74  // Setting the signature is the "command" to program from the filename upon next boot.
75  *pCommandReg = signature;
76 }
77 
78 
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 #endif /* CHIP_INFO_H__ */
#define LPC_RTC
Definition: LPC17xx.h:1026