Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Msp430 #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
initial import
  • Loading branch information
jotaemesousa committed May 12, 2014
commit b9aaa6b6a99fc5676b06003d2c543746ec7fe019
6 changes: 6 additions & 0 deletions .directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Dolphin]
Timestamp=2014,5,12,14,1,15
Version=3

[Settings]
HiddenFilesShown=true
61 changes: 61 additions & 0 deletions flash.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* flash.cpp
*
* Created on: Jun 10, 2013
* Author: joao
*/
#include <msp430.h>
#include "flash.h"

void flash_init(void)
{
FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator
}

void write_SegC (unsigned char values[], uint8_t dim)
{
char *Flash_ptr; // Flash pointer
unsigned int i;

Flash_ptr = (char *) 0x1040; // Initialize Flash pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptr = 0; // Dummy write to erase Flash segment

FCTL1 = FWKEY + WRT; // Set WRT bit for write operation

for (i=0; i<64; i++)
{
if(i < dim)
{
*Flash_ptr++ = values[i]; // Write value to flash
}
else
{
*Flash_ptr++ = 0;
}
}

FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}

void read_SegC (unsigned char values[], uint8_t dim, uint8_t offset)
{
char *Flash_ptr; // Flash pointer
unsigned int i;

if(64 - offset - dim > 0)
{
Flash_ptr = (char *) (0x1040 + offset); // Initialize Flash pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit

for (i=0; i<dim; i++)
{
values[i] = *Flash_ptr++; // Write value to flash
}

FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
}
18 changes: 18 additions & 0 deletions flash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* flash.h
*
* Created on: Jun 10, 2013
* Author: joao
*/

#ifndef FLASH_H_
#define FLASH_H_

#include "stdint.h"

// Function prototypes
void flash_init(void);
void write_SegC (unsigned char value[], uint8_t dim);
void read_SegC (unsigned char values[], uint8_t dim, uint8_t offset = 0);

#endif /* FLASH_H_ */
76 changes: 76 additions & 0 deletions include/libemb/conio/conio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* This file is part of the libemb project.
*
* Copyright (C) 2011 Stefan Wendler <sw@kaltpost.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __CONIO_H_
#define __CONIO_H_

/**
* Print a character to the console.
*
* @param[in] c character to print
*/
void cio_printc(char c);

/**
* Print a string to the console.
*
* @param[in] *line string to print
*/
void cio_print(char *line);

/**
* Print an integer to the console.
*
* @param[in] n number to print
*/
void cio_printi(int n);

/**
* Print a number in binary to the console.
*
* @param[in] n number to print
* @param[in] size number of bits to use
*/
void cio_printb(int n, int size);

/**
* Print a formated string. The following formt specifiers could
* be used in the format string:
* <pre>
* String %s
* Char %c
* Integer %i
* Unsigned %u
* Long %l
* unsigned long %n
* heX %x
* </pre>
* @param[in] *format the format string
* @param[in] ... the values to put into the format string
*/
void cio_printf(char *format, ...);

/**
* Read a character form the console.
*
* @return character read from the console
*/
char cio_getc();

#endif
Loading