1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 10:52:44 +01:00

* introduced flashrom driver for msb430

* restructured some files concerning flashrom access
* added some ifdefs to shell commands
This commit is contained in:
Oliver Hahm 2010-12-03 22:22:58 +01:00
parent fb1cb91c75
commit 1eec8e170e
19 changed files with 189 additions and 46 deletions

View File

@ -34,4 +34,5 @@ FLASHFLAGS ?= -d $(FLASH_PORT) -j uif ;
RESET ?= $(FLASHER) $(FLASHFLAGS) reset ;
HDRS += [ FPath $(TOP) board msb-430-common include ] ;
HDRS += [ FPath $(TOP) board msb-430-common drivers include ] ;

View File

@ -1,6 +1,9 @@
#include <stdint.h>
#include <board-conf.h>
#include <config.h>
#include <flashrom.h>
uint8_t config_save(void) {
return 1;
configmem_t mem = { CONFIG_KEY, sysconfig };
return (flashrom_erase((uint8_t*) INFOMEM) && flashrom_write((uint8_t*) INFOMEM, (char*) &mem, sizeof(mem)));
}

View File

@ -0,0 +1,6 @@
#ifndef BOARD_CONF_H
#define BOARD_CONF_H
#define INFOMEM (0x1000)
#endif /* BOARD-CONF_H */

View File

@ -4,5 +4,5 @@
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)));
return (flashrom_erase((uint8_t*) &configmem) && flashrom_write((uint8_t*) &configmem, (char*) &mem, sizeof(mem)));
}

View File

@ -7,6 +7,7 @@
#include <irq.h>
#include <flashrom.h>
#include <iap.h>
#include <lpc2387.h>
//#define ENABLE_DEBUG
@ -31,7 +32,7 @@ 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 flashrom_write(uint32_t dst, char *src, uint32_t size) {
uint8_t flashrom_write(uint8_t *dst, char *src, size_t size) {
char err;
unsigned intstate;
uint8_t sec;
@ -39,7 +40,7 @@ uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size) {
//buffer_vic = VICIntEnable; // save interrupt enable
//VICIntEnClr = 0xFFFFFFFF; // clear vic
sec = flashrom_get_sector(dst);
sec = iap_get_sector((uint32_t) dst);
if (sec == INVALID_ADDRESS) {
DEBUG("Invalid address\n");
return 0;
@ -61,7 +62,7 @@ uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size) {
/* write flash */
else {
intstate = disableIRQ();
err = copy_ram_to_flash(dst, (uint32_t) src, 256);
err = copy_ram_to_flash((uint32_t) dst, (uint32_t) src, 256);
restoreIRQ(intstate);
if(err) {
DEBUG("ERROR: COPY_RAM_TO_FLASH: %u\n", err);
@ -72,7 +73,7 @@ uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size) {
}
/* check result */
else {
err = compare(dst, (uint32_t) src, 256);
err = compare((uint32_t) dst, (uint32_t) src, 256);
if (err) {
DEBUG("ERROR: COMPARE: %i (at position %u)\n", err, iap_result[1]);
/* set interrupts back and return */
@ -91,8 +92,8 @@ uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size) {
}
uint8_t flashrom_erase(uint32_t addr) {
uint8_t sec = flashrom_get_sector(addr);
uint8_t flashrom_erase(uint8_t *addr) {
uint8_t sec = iap_get_sector((uint32_t) addr);
unsigned intstate;
if (sec == INVALID_ADDRESS) {

View File

@ -37,25 +37,6 @@
#define PLLCON_PLLC (0x03) ///< PLL Connect
#define PLLSTAT_PLOCK (0x0400) //</ PLL Lock Status
/*
* @brief Erase sector
*
* @param addr Address within a flash sector to erase
*
* @return 1 on success, 0 otherwise
*/
uint8_t flashrom_erase(uint32_t addr);
/* @brief Write buffer from ram to flash
*
* @param dst Address within a flash sector to write, must be a 256 byte boundary
* @param src Address within ram, must be a word boundary
* @param size Bytes to write
*
* @return 1 on success, 0 otherwise
*/
uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size);
/*
* @brief: Converts 'addr' to sector number
* @note: Sector table (Users Manual P. 610)
@ -64,6 +45,6 @@ uint8_t flashrom_write(uint32_t dst, char *src, uint32_t size);
*
* @return Sector number. 0xFF on error
*/
uint8_t flashrom_get_sector(uint32_t addr);
uint8_t iap_get_sector(uint32_t addr);
#endif /*IAP_H_*/

View File

@ -1,7 +1,8 @@
#include <stdint.h>
#include <flashrom.h>
#include <iap.h>
uint8_t flashrom_get_sector(uint32_t addr) {
uint8_t iap_get_sector(uint32_t addr) {
if ((addr >=0x00000000) && (addr <= 0x00000FFF)) {
return 0;
}

View File

@ -27,7 +27,7 @@
SubDir TOP cpu msp430 ;
Module cpu : msp430-main.c cpu.c atomic.c irq.c ;
Module cpu : msp430-main.c cpu.c atomic.c irq.c flashrom.c ;
Module hwtimer_cpu : hwtimer_cpu.c ;
UseModule cpu ;

80
cpu/msp430/flashrom.c Normal file
View File

@ -0,0 +1,80 @@
#include <stddef.h>
#include <msp430x16x.h>
#include <msp430/flash.h>
#include <irq.h>
uint8_t ie1, ie2;
static uint8_t prepare(void);
static void finish(uint8_t istate);
static inline void busy_wait(void);
/*---------------------------------------------------------------------------*/
uint8_t flashrom_erase(uint8_t *addr) {
uint8_t istate = prepare();
FCTL3 = FWKEY; /* Lock = 0 */
busy_wait();
FCTL1 = FWKEY | ERASE;
*addr = 0; /* erase Flash segment */
busy_wait();
FCTL1 = FWKEY; /* ERASE = 0 */
FCTL3 = FWKEY | LOCK;
finish(istate);
return 1;
}
void flashrom_write(uint8_t *dst, uint8_t *src, size_t size) {
unsigned int i;
FCTL3 = FWKEY; /* Lock = 0 */
busy_wait();
for (i = size; i > 0; i--) {
FCTL1 = FWKEY | WRT;
*dst = *src; /* program Flash word */
while (!(FCTL3 & WAIT)) {
nop();
}
}
busy_wait();
FCTL1 = FWKEY; /* WRT = 0 */
FCTL3 = FWKEY | LOCK; /* Lock = 1 */
}
/*---------------------------------------------------------------------------*/
static uint8_t prepare(void) {
uint8_t istate;
/* Disable all interrupts. */
/* Clear interrupt flag1. */
IFG1 = 0;
/* DCO(SMCLK) is 2,4576MHz, /6 = 409600 Hz
select SMCLK for flash timing, divider 4+1 */
FCTL2 = FWKEY | FSSEL_3 | FN2 | FN0;
/* disable all interrupts to protect CPU
during programming from system crash */
istate = disableIRQ();
/* disable all NMI-Interrupt sources */
ie1 = IE1;
ie2 = IE2;
IE1 = 0x00;
IE2 = 0x00;
return istate;
}
/*---------------------------------------------------------------------------*/
void finish(uint8_t istate) {
/* Enable interrupts. */
IE1 = ie1;
IE2 = ie2;
restoreIRQ(istate);
}
static inline void busy_wait(void) {
/* Wait for BUSY = 0, not needed unless run from RAM */
while(FCTL3 & 0x0001) {
nop();
}
}

View File

@ -0,0 +1,27 @@
#ifndef FLASHROM_H
#define FLASHROM_H
#include <stdint.h>
#include <stddef.h>
/*
* @brief Erase sector
*
* @param addr Address within a flash sector to erase
*
* @return 1 on success, 0 otherwise
*/
uint8_t flashrom_erase(uint8_t *addr);
/* @brief Write buffer from ram to flash
*
* @param dst Address within a flash sector to write, must be a 256 byte boundary
* @param src Address within ram, must be a word boundary
* @param size Bytes to write
*
* @return 1 on success, 0 otherwise
*/
uint8_t flashrom_write(uint8_t *dst, char *src, size_t size);
#endif /* FLASHROM_H */

View File

@ -1,5 +1,5 @@
SubDir TOP projects msb430_cc110x_ng ;
Module msb430_cc110x_ng : main.c : cc110x_ng transceiver ps posix_io uart0 auto_init ;
Module msb430_cc110x_ng : main.c : cc110x_ng transceiver shell shell_commands ps posix_io uart0 auto_init ;
UseModule msb430_cc110x_ng ;

View File

@ -12,13 +12,15 @@
#include <transceiver.h>
#include <cc1100_ng.h>
#define RADIO_STACK_SIZE (1024)
#define SHELL_STACK_SIZE (512)
#define RADIO_STACK_SIZE (512)
#define SND_BUFFER_SIZE (3)
#define RCV_BUFFER_SIZE (4)
#define SENDING_DELAY (5 * 1000)
char shell_stack_buffer[SHELL_STACK_SIZE];
char radio_stack_buffer[RADIO_STACK_SIZE];
uint8_t snd_buffer[SND_BUFFER_SIZE][CC1100_MAX_DATA_LENGTH];
@ -32,6 +34,20 @@ static radio_packet_t p;
void sender(char *count);
void print_buffer(char *unused);
shell_t shell;
const shell_command_t sc[] = {
{"snd", "", sender},
{"buffer", "", print_buffer},
{NULL, NULL, NULL}
};
void shell_runner(void) {
shell_init(&shell, sc, uart0_readc, uart0_putc);
posix_open(uart0_handler_pid, 0);
shell_run(&shell);
}
void sender(char *count) {
unsigned int c = 3;
unsigned int i;
@ -104,11 +120,17 @@ int main(void) {
for (i = 0; i < SND_BUFFER_SIZE; i++) {
memset(snd_buffer[i], i, CC1100_MAX_DATA_LENGTH);
}
thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, shell_runner, "shell");
radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio");
transceiver_init(TRANSCEIVER_CC1100);
transceiver_start();
transceiver_register(TRANSCEIVER_CC1100, radio_pid);
sender(NULL);
printf("Config:\n");
printf("\tid: %u\n", sysconfig.id);
printf("\taddr: %u\n", sysconfig.radio_address);
printf("\tchannel: %u\n", sysconfig.radio_channel);
while (1) {
extern void thread_print_all(void);

View File

@ -1,6 +1,8 @@
#include <stdio.h>
#include <cc1100-interface.h>
#ifdef MODULE_CC110X
void _cc1100_get_address_handler(char *str) {
radio_address_t addr = cc1100_get_address();
printf("cc1100 address: %i\n", addr);
@ -22,3 +24,4 @@ void _cc1100_set_address_handler(char *str) {
}
}
#endif

View File

@ -1,4 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <transceiver.h>
#include <cc1100_ng.h>
@ -16,7 +17,8 @@ void _cc1100_ng_get_set_address_handler(char *addr) {
tcmd.transceivers = TRANSCEIVER_CC1100;
tcmd.data = &a;
mesg.content.ptr = (char*) &tcmd;
if (sscanf(addr, "addr %hi", &a) > 0) {
a = atoi(addr+5);
if (strlen(addr) > 5) {
printf("[cc1100] Trying to set address %i\n", a);
mesg.type = SET_ADDRESS;
}
@ -33,7 +35,8 @@ void _cc1100_ng_get_set_channel_handler(char *chan) {
tcmd.transceivers = TRANSCEIVER_CC1100;
tcmd.data = &c;
mesg.content.ptr = (char*) &tcmd;
if (sscanf(chan, "chan %hi", &c) > 0) {
c = atoi(chan+5);
if (strlen(chan) > 5) {
printf("[cc1100] Trying to set channel %i\n", c);
mesg.type = SET_CHANNEL;
}
@ -51,7 +54,10 @@ void _cc1100_ng_send_handler(char *pkt) {
tcmd.data = &p;
uint16_t addr;
if (sscanf(pkt, "txtsnd %hu %s", &(addr), text_msg) == 2) {
addr = atoi(pkt+7);
memcpy(text_msg, "Text", 5);
/* if (sscanf(pkt, "txtsnd %hu %s", &(addr), text_msg) == 2) {*/
if (1 == 1) {
p.data = (uint8_t*) text_msg;
p.length = strlen(text_msg);
p.dst = addr;
@ -73,7 +79,8 @@ void _cc1100_ng_monitor_handler(char *mode) {
tcmd.transceivers = TRANSCEIVER_CC1100;
tcmd.data = &m;
mesg.content.ptr = (char*) &tcmd;
if (sscanf(mode, "monitor %u", &m) == 1) {
m = atoi(mode+8);
if (strlen(mode) > 8) {
printf("Setting monitor mode: %u\n", m);
mesg.type = SET_MONITOR;
msg_send(&mesg, transceiver_pid, 1);

View File

@ -1,17 +1,20 @@
#include <stdio.h>
#include <string.h>
#include <config.h>
#include <stdlib.h>
void _id_handler(char *id) {
uint16_t newid;
long newid;
if (sscanf(id, "id %hu", &newid) == 1) {
printf("Setting new id %u\n", newid);
newid = atoi(id+3);
if (strlen(id) < 3) {
printf("Current id: %u\n", sysconfig.id);
}
else {
printf("Setting new id %lu\n", newid);
sysconfig.id = newid;
if (!config_save()) {
puts("ERROR setting new id");
}
}
else {
printf("Current id: %u\n", sysconfig.id);
}
}

View File

@ -1,8 +1,10 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#ifdef MODULE_RTC
#include <lpc2387-rtc.h>
#include <sys/time.h>
#include <string.h>
void _gettime_handler(void) {
struct tm now;
@ -46,3 +48,5 @@ void _date_handler(char* c) {
_settime_handler(c);
}
}
#endif

View File

@ -41,13 +41,13 @@ and the mailinglist (subscription via web site)
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#include <sys/unistd.h>
//#include <sys/unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <shell.h>
#include <shell_commands.h>
#include <stdint.h>
#include <stdlib.h>
static void(*find_handler(const shell_command_t *command_list, char *command))(char*) {
const shell_command_t* entry = command_list;

View File

@ -1,4 +1,4 @@
#include <shell.h>
#include <shell_commands.h>
#include <stdlib.h>
extern void _id_handler(char* id);

View File

@ -3,6 +3,8 @@
#include <sht11.h>
#include <string.h>
#ifdef MODULE_SHT11
extern float sht11_temperature_offset;
void _get_humidity_handler(char* unused) {
@ -51,3 +53,5 @@ void _set_offset_handler(char* offset) {
printf("Temperature offset set to %f\n", sht11_temperature_offset);
}
}
#endif