bad dc motor controller with current mode

Dependencies:   mbed FastPWM3

Committer:
bwang
Date:
Sun Feb 03 03:38:05 2019 +0000
Revision:
0:2b1edabdd26b
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bwang 0:2b1edabdd26b 1 #include "PreferenceWriter.h"
bwang 0:2b1edabdd26b 2 #include "FlashWriter.h"
bwang 0:2b1edabdd26b 3
bwang 0:2b1edabdd26b 4 #include "globals.h"
bwang 0:2b1edabdd26b 5
bwang 0:2b1edabdd26b 6 float __float_reg[64];
bwang 0:2b1edabdd26b 7 int __int_reg[64];
bwang 0:2b1edabdd26b 8
bwang 0:2b1edabdd26b 9 PreferenceWriter::PreferenceWriter(uint32_t sector) {
bwang 0:2b1edabdd26b 10 writer = new FlashWriter(sector);
bwang 0:2b1edabdd26b 11 __sector = sector;
bwang 0:2b1edabdd26b 12 __ready = false;
bwang 0:2b1edabdd26b 13 }
bwang 0:2b1edabdd26b 14
bwang 0:2b1edabdd26b 15 void PreferenceWriter::open() {
bwang 0:2b1edabdd26b 16 writer->open();
bwang 0:2b1edabdd26b 17 __ready = true;
bwang 0:2b1edabdd26b 18 }
bwang 0:2b1edabdd26b 19
bwang 0:2b1edabdd26b 20 bool PreferenceWriter::ready() {
bwang 0:2b1edabdd26b 21 return __ready;
bwang 0:2b1edabdd26b 22 }
bwang 0:2b1edabdd26b 23
bwang 0:2b1edabdd26b 24 void PreferenceWriter::write(int x, int index) {
bwang 0:2b1edabdd26b 25 __int_reg[index] = x;
bwang 0:2b1edabdd26b 26 }
bwang 0:2b1edabdd26b 27
bwang 0:2b1edabdd26b 28 void PreferenceWriter::write(float x, int index) {
bwang 0:2b1edabdd26b 29 __float_reg[index] = x;
bwang 0:2b1edabdd26b 30 }
bwang 0:2b1edabdd26b 31
bwang 0:2b1edabdd26b 32 void PreferenceWriter::flush() {
bwang 0:2b1edabdd26b 33 int offs;
bwang 0:2b1edabdd26b 34 for (offs = 0; offs < 64; offs++) {
bwang 0:2b1edabdd26b 35 writer->write(offs, __int_reg[offs]);
bwang 0:2b1edabdd26b 36 }
bwang 0:2b1edabdd26b 37 for (; offs < 128; offs++) {
bwang 0:2b1edabdd26b 38 writer->write(offs, __float_reg[offs - 64]);
bwang 0:2b1edabdd26b 39 }
bwang 0:2b1edabdd26b 40 __ready = false;
bwang 0:2b1edabdd26b 41 }
bwang 0:2b1edabdd26b 42
bwang 0:2b1edabdd26b 43 void PreferenceWriter::load() {
bwang 0:2b1edabdd26b 44 int offs;
bwang 0:2b1edabdd26b 45 for (offs = 0; offs < 64; offs++) {
bwang 0:2b1edabdd26b 46 __int_reg[offs] = flashReadInt(__sector, offs);
bwang 0:2b1edabdd26b 47 }
bwang 0:2b1edabdd26b 48 for(; offs < 128; offs++) {
bwang 0:2b1edabdd26b 49 __float_reg[offs - 64] = flashReadFloat(__sector, offs);
bwang 0:2b1edabdd26b 50 }
bwang 0:2b1edabdd26b 51 }
bwang 0:2b1edabdd26b 52
bwang 0:2b1edabdd26b 53 void PreferenceWriter::close() {
bwang 0:2b1edabdd26b 54 __ready = false;
bwang 0:2b1edabdd26b 55 writer->close();
bwang 0:2b1edabdd26b 56 }