mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
* introduced identifiers (include shell commands to get and set)
* introduced a system wide configuration
This commit is contained in:
parent
5ebbd2c92e
commit
a46cdf189a
@ -27,7 +27,7 @@
|
||||
|
||||
SubDir TOP board msba2 ;
|
||||
|
||||
Module board : board_init.c ;
|
||||
Module board : board_init.c config.c ;
|
||||
UseModule board ;
|
||||
UseModule board_common ;
|
||||
|
||||
|
@ -42,12 +42,21 @@ and the mailinglist (subscription via web site)
|
||||
*/
|
||||
#include <board.h>
|
||||
#include <lpc23xx.h>
|
||||
#include "VIC.h"
|
||||
#include "cpu.h"
|
||||
#include <VIC.h>
|
||||
#include <cpu.h>
|
||||
#include <config.h>
|
||||
#include <string.h>
|
||||
#include <flashrom.h>
|
||||
|
||||
#define PCRTC BIT9
|
||||
#define CL_CPU_DIV 4
|
||||
|
||||
config_t sysconfig = {
|
||||
0, ///< default ID
|
||||
0, ///< default radio address
|
||||
0, ///< default radio channel
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Enabling MAM and setting number of clocks used for Flash memory fetch
|
||||
@ -154,3 +163,13 @@ void bl_blink(void) {
|
||||
LED_GREEN_OFF;
|
||||
}
|
||||
|
||||
void bl_config_init(void) {
|
||||
extern char configmem[];
|
||||
if (*((uint16_t*) configmem) == CONFIG_KEY) {
|
||||
memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig));
|
||||
LED_GREEN_TOGGLE;
|
||||
}
|
||||
else {
|
||||
config_save();
|
||||
}
|
||||
}
|
||||
|
8
board/msba2/config.c
Normal file
8
board/msba2/config.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <stdint.h>
|
||||
#include <config.h>
|
||||
#include <flashrom.h>
|
||||
|
||||
uint8_t config_save(void) {
|
||||
configmem_t mem = { CONFIG_KEY, sysconfig };
|
||||
return (flashrom_erase((uint32_t) configmem) && flashrom_write((uint32_t) configmem, (char*) &mem, sizeof(mem)));
|
||||
}
|
27
core/include/config.h
Normal file
27
core/include/config.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define CONFIG_KEY (0x1701)
|
||||
|
||||
extern char configmem[];
|
||||
|
||||
/* @brief: Stores configuration data of the node */
|
||||
typedef struct {
|
||||
uint16_t id; ///< unique node identifier
|
||||
uint8_t radio_address; ///< address for radio communication
|
||||
uint8_t radio_channel; ///< current frequency
|
||||
} config_t;
|
||||
|
||||
/* @brief: Element to store in flashrom */
|
||||
typedef struct {
|
||||
uint16_t magic_key; ///< validity check
|
||||
config_t config; ///< the node's configuration
|
||||
} configmem_t;
|
||||
|
||||
extern config_t sysconfig;
|
||||
|
||||
uint8_t config_save(void);
|
||||
|
||||
#endif /* CONFIG_H */
|
@ -165,6 +165,7 @@ void bootloader(void) {
|
||||
extern void bl_init_ports(void);
|
||||
extern void bl_init_clks(void);
|
||||
extern void bl_blink(void);
|
||||
extern void bl_config_init(void);
|
||||
|
||||
/* board specific setup of clocks */
|
||||
bl_init_clks();
|
||||
@ -177,6 +178,9 @@ void bootloader(void) {
|
||||
/* board specific setup of UART */
|
||||
bl_uart_init();
|
||||
|
||||
/* initialize board configuration */
|
||||
bl_config_init();
|
||||
|
||||
printf("Board initialized.\n");
|
||||
}
|
||||
|
||||
|
@ -5,12 +5,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iap.h>
|
||||
#include <irq.h>
|
||||
#include <flashrom.h>
|
||||
#include <lpc2387.h>
|
||||
|
||||
#define ENABLE_DEBUG
|
||||
#include <debug.h>
|
||||
|
||||
/* pointer to reserved flash rom section for configuration data */
|
||||
__attribute ((aligned(256))) char configmem[256] __attribute__ ((section (".configmem")));
|
||||
|
||||
static unsigned int iap_command[5]; // contains parameters for IAP command
|
||||
static unsigned int iap_result[2]; // contains results
|
||||
typedef void (*IAP) (unsigned int[],unsigned int[]); // typedefinition for IAP entry function
|
||||
@ -27,15 +31,19 @@ static uint32_t iap(uint32_t code, uint32_t p1, uint32_t p2, uint32_t p3, uint32
|
||||
/******************************************************************************
|
||||
* P U B L I C F U N C T I O N S
|
||||
*****************************************************************************/
|
||||
uint8_t iap_write(uint32_t dst, char *src, uint32_t size) {
|
||||
uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size) {
|
||||
char err;
|
||||
uint32_t buffer_vic;
|
||||
unsigned intstate;
|
||||
uint8_t sec;
|
||||
|
||||
buffer_vic = VICIntEnable; // save interrupt enable
|
||||
VICIntEnClr = 0xFFFFFFFF; // clear vic
|
||||
//buffer_vic = VICIntEnable; // save interrupt enable
|
||||
//VICIntEnClr = 0xFFFFFFFF; // clear vic
|
||||
|
||||
sec = iap_get_sector(dst);
|
||||
sec = flashrom_get_sector(dst);
|
||||
if (sec == INVALID_ADDRESS) {
|
||||
DEBUG("Invalid address\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check sector */
|
||||
if(blank_check_sector(sec, sec) == SECTOR_NOT_BLANK) {
|
||||
@ -43,35 +51,39 @@ uint8_t iap_write(uint32_t dst, char *src, uint32_t size) {
|
||||
}
|
||||
|
||||
/* prepare sector */
|
||||
err = prepare_sectors(iap_get_sector(dst), iap_get_sector(dst));
|
||||
err = prepare_sectors(sec, sec);
|
||||
if (err) {
|
||||
DEBUG("\n-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION: %u", err);
|
||||
DEBUG("\n-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION: %u\n", err);
|
||||
/* set interrupts back and return */
|
||||
VICIntEnable = buffer_vic;
|
||||
// VICIntEnable = buffer_vic;
|
||||
return 0;
|
||||
}
|
||||
/* write flash */
|
||||
else {
|
||||
err = copy_ram_to_flash(dst, (uint32_t) src, size);
|
||||
intstate = disableIRQ();
|
||||
err = copy_ram_to_flash(dst, (uint32_t) src, 256);
|
||||
restoreIRQ(intstate);
|
||||
if(err) {
|
||||
DEBUG("ERROR: COPY_RAM_TO_FLASH: %u\n", err);
|
||||
/* set interrupts back and return */
|
||||
VICIntEnable = buffer_vic;
|
||||
restoreIRQ(intstate);
|
||||
// VICIntEnable = buffer_vic;
|
||||
return 0;
|
||||
}
|
||||
/* check result */
|
||||
else {
|
||||
err = compare(dst, (uint32_t) src, size);
|
||||
err = compare(dst, (uint32_t) src, 256);
|
||||
if (err) {
|
||||
DEBUG("ERROR: COMPARE: %i (at position %u)\n", err, iap_result[1]);
|
||||
/* set interrupts back and return */
|
||||
VICIntEnable = buffer_vic;
|
||||
// VICIntEnable = buffer_vic;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG("Data successfully written!\n");
|
||||
/* set interrupts back and return */
|
||||
// VICIntEnable = buffer_vic;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -79,24 +91,35 @@ uint8_t iap_write(uint32_t dst, char *src, uint32_t size) {
|
||||
}
|
||||
|
||||
|
||||
uint8_t iap_erase(uint32_t addr) {
|
||||
uint8_t flashrom_erase(uint32_t addr) {
|
||||
uint8_t sec = flashrom_get_sector(addr);
|
||||
unsigned intstate;
|
||||
|
||||
if (sec == INVALID_ADDRESS) {
|
||||
DEBUG("Invalid address\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check sector */
|
||||
if (!blank_check_sector(iap_get_sector(addr), iap_get_sector(addr))) {
|
||||
if (!blank_check_sector(sec, sec)) {
|
||||
DEBUG("Sector already blank!\n");
|
||||
return 1;
|
||||
}
|
||||
/* prepare sector */
|
||||
if (prepare_sectors(iap_get_sector(addr), iap_get_sector(addr))) {
|
||||
if (prepare_sectors(sec, sec)) {
|
||||
DEBUG("-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION --\n");
|
||||
return 0;
|
||||
}
|
||||
intstate = disableIRQ();
|
||||
/* erase sector */
|
||||
if (erase_sectors(iap_get_sector(addr), iap_get_sector(addr))) {
|
||||
if (erase_sectors(sec, sec)) {
|
||||
DEBUG("-- ERROR: ERASE SECTOR --\n");
|
||||
restoreIRQ(intstate);
|
||||
return 0;
|
||||
}
|
||||
restoreIRQ(intstate);
|
||||
/* check again */
|
||||
if (blank_check_sector(iap_get_sector(addr), iap_get_sector(addr))) {
|
||||
if (blank_check_sector(sec, sec)) {
|
||||
DEBUG("-- ERROR: BLANK_CHECK_SECTOR\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -26,6 +26,8 @@
|
||||
#define COMPARE_ERROR (10)
|
||||
#define BUSY (11)
|
||||
|
||||
#define INVALID_ADDRESS (0xFF)
|
||||
|
||||
/* IAP start location on flash */
|
||||
#define IAP_LOCATION (0x7FFFFFF1)
|
||||
|
||||
@ -42,7 +44,7 @@
|
||||
*
|
||||
* @return 1 on success, 0 otherwise
|
||||
*/
|
||||
uint8_t iap_erase(uint32_t addr);
|
||||
uint8_t flashrom_erase(uint32_t addr);
|
||||
|
||||
/* @brief Write buffer from ram to flash
|
||||
*
|
||||
@ -52,7 +54,7 @@ uint8_t iap_erase(uint32_t addr);
|
||||
*
|
||||
* @return 1 on success, 0 otherwise
|
||||
*/
|
||||
uint8_t iap_write(uint32_t dst, char *src, uint32_t size);
|
||||
uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size);
|
||||
|
||||
/*
|
||||
* @brief: Converts 'addr' to sector number
|
||||
@ -62,6 +64,6 @@ uint8_t iap_write(uint32_t dst, char *src, uint32_t size);
|
||||
*
|
||||
* @return Sector number. 0xFF on error
|
||||
*/
|
||||
uint8_t iap_get_sector(uint32_t addr);
|
||||
uint8_t flashrom_get_sector(uint32_t addr);
|
||||
|
||||
#endif /*IAP_H_*/
|
@ -1,6 +1,7 @@
|
||||
#include <stdint.h>
|
||||
#include <flashrom.h>
|
||||
|
||||
uint8_t iap_get_sector(uint32_t addr) {
|
||||
uint8_t flashrom_get_sector(uint32_t addr) {
|
||||
if ((addr >=0x00000000) && (addr <= 0x00000FFF)) {
|
||||
return 0;
|
||||
}
|
||||
@ -88,5 +89,5 @@ uint8_t iap_get_sector(uint32_t addr) {
|
||||
}
|
||||
|
||||
/* no valid address within flash */
|
||||
return 0xFF;
|
||||
return INVALID_ADDRESS;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
SubDir TOP sys shell ;
|
||||
|
||||
Module shell : shell.c ;
|
||||
Module shell_commands : shell_commands.c rtc.c sht11.c ltc4150.c cc1100.c cc1100_ng.c : shell ;
|
||||
Module shell_commands : shell_commands.c id.c rtc.c sht11.c ltc4150.c cc1100.c cc1100_ng.c : shell ;
|
||||
|
||||
Module ps : ps.c ;
|
||||
|
||||
|
17
sys/shell/id.c
Normal file
17
sys/shell/id.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <config.h>
|
||||
|
||||
void _id_handler(char *id) {
|
||||
uint16_t newid;
|
||||
|
||||
if (sscanf(id, "id %hu", &newid) == 1) {
|
||||
printf("Setting new id %u\n", newid);
|
||||
sysconfig.id = newid;
|
||||
if (!config_save()) {
|
||||
puts("ERROR setting new id");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("Current id: %u\n", sysconfig.id);
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
#include <shell.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
extern void _id_handler(char* id);
|
||||
|
||||
#ifdef MODULE_PS
|
||||
extern void _ps_handler(char* unused);
|
||||
#endif
|
||||
@ -36,11 +38,12 @@ extern void _cc1100_ng_monitor_handler(char *mode);
|
||||
#endif
|
||||
|
||||
const shell_command_t _shell_command_list[] = {
|
||||
{"id", "Gets or sets the node's id.", _id_handler},
|
||||
#ifdef MODULE_PS
|
||||
{"ps", "Prints information about running threads.", _ps_handler},
|
||||
#endif
|
||||
#ifdef MODULE_RTC
|
||||
{"date", "Geets or gets current date and time.", _date_handler},
|
||||
{"date", "Gets or sets current date and time.", _date_handler},
|
||||
#endif
|
||||
#ifdef MODULE_SHT11
|
||||
{"temp", "Prints measured temperature.", _get_temperature_handler},
|
||||
|
Loading…
Reference in New Issue
Block a user