Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1 #include "platform/CallChain.h"
switches 0:5c4d7b2438d3 2 #include "cmsis.h"
switches 0:5c4d7b2438d3 3 #include "platform/critical.h"
switches 0:5c4d7b2438d3 4
switches 0:5c4d7b2438d3 5 namespace mbed {
switches 0:5c4d7b2438d3 6
switches 0:5c4d7b2438d3 7 class CallChainLink {
switches 0:5c4d7b2438d3 8 public:
switches 0:5c4d7b2438d3 9 CallChainLink(): cb(), next(NULL) {
switches 0:5c4d7b2438d3 10 // No work to do
switches 0:5c4d7b2438d3 11 }
switches 0:5c4d7b2438d3 12
switches 0:5c4d7b2438d3 13 CallChainLink(Callback<void()> &callback): cb(callback), next(NULL) {
switches 0:5c4d7b2438d3 14 // No work to do
switches 0:5c4d7b2438d3 15 }
switches 0:5c4d7b2438d3 16 Callback<void()> cb;
switches 0:5c4d7b2438d3 17 CallChainLink * next;
switches 0:5c4d7b2438d3 18 };
switches 0:5c4d7b2438d3 19
switches 0:5c4d7b2438d3 20 CallChain::CallChain(int size) : _chain(NULL) {
switches 0:5c4d7b2438d3 21 // No work to do
switches 0:5c4d7b2438d3 22 }
switches 0:5c4d7b2438d3 23
switches 0:5c4d7b2438d3 24 CallChain::~CallChain() {
switches 0:5c4d7b2438d3 25 clear();
switches 0:5c4d7b2438d3 26 }
switches 0:5c4d7b2438d3 27
switches 0:5c4d7b2438d3 28 pFunctionPointer_t CallChain::add(Callback<void()> func) {
switches 0:5c4d7b2438d3 29 CallChainLink *new_link = new CallChainLink(func);
switches 0:5c4d7b2438d3 30 if (NULL == _chain) {
switches 0:5c4d7b2438d3 31 _chain = new_link;
switches 0:5c4d7b2438d3 32 return &new_link->cb;
switches 0:5c4d7b2438d3 33 }
switches 0:5c4d7b2438d3 34
switches 0:5c4d7b2438d3 35 CallChainLink *link = _chain;
switches 0:5c4d7b2438d3 36 while (true) {
switches 0:5c4d7b2438d3 37 if (NULL == link->next) {
switches 0:5c4d7b2438d3 38 link->next = new_link;
switches 0:5c4d7b2438d3 39 return &new_link->cb;
switches 0:5c4d7b2438d3 40 }
switches 0:5c4d7b2438d3 41 link = link->next;
switches 0:5c4d7b2438d3 42 }
switches 0:5c4d7b2438d3 43 }
switches 0:5c4d7b2438d3 44
switches 0:5c4d7b2438d3 45 pFunctionPointer_t CallChain::add_front(Callback<void()> func) {
switches 0:5c4d7b2438d3 46 CallChainLink *link = new CallChainLink(func);
switches 0:5c4d7b2438d3 47 link->next = _chain;
switches 0:5c4d7b2438d3 48 _chain = link;
switches 0:5c4d7b2438d3 49 return &link->cb;
switches 0:5c4d7b2438d3 50 }
switches 0:5c4d7b2438d3 51
switches 0:5c4d7b2438d3 52 int CallChain::size() const {
switches 0:5c4d7b2438d3 53 CallChainLink *link = _chain;
switches 0:5c4d7b2438d3 54 int elements = 0;
switches 0:5c4d7b2438d3 55 while (link != NULL) {
switches 0:5c4d7b2438d3 56 elements++;
switches 0:5c4d7b2438d3 57 link = link->next;
switches 0:5c4d7b2438d3 58 }
switches 0:5c4d7b2438d3 59 return elements;
switches 0:5c4d7b2438d3 60 }
switches 0:5c4d7b2438d3 61
switches 0:5c4d7b2438d3 62 pFunctionPointer_t CallChain::get(int idx) const {
switches 0:5c4d7b2438d3 63 CallChainLink *link = _chain;
switches 0:5c4d7b2438d3 64 for (int i = 0; i < idx; i++) {
switches 0:5c4d7b2438d3 65 if (NULL == link) {
switches 0:5c4d7b2438d3 66 break;
switches 0:5c4d7b2438d3 67 }
switches 0:5c4d7b2438d3 68 link = link->next;
switches 0:5c4d7b2438d3 69 }
switches 0:5c4d7b2438d3 70 return &link->cb;
switches 0:5c4d7b2438d3 71 }
switches 0:5c4d7b2438d3 72
switches 0:5c4d7b2438d3 73 int CallChain::find(pFunctionPointer_t f) const {
switches 0:5c4d7b2438d3 74 CallChainLink *link = _chain;
switches 0:5c4d7b2438d3 75 int i = 0;
switches 0:5c4d7b2438d3 76 while (link != NULL) {
switches 0:5c4d7b2438d3 77 if (f == &link->cb) {
switches 0:5c4d7b2438d3 78 return i;
switches 0:5c4d7b2438d3 79 }
switches 0:5c4d7b2438d3 80 i++;
switches 0:5c4d7b2438d3 81 link = link->next;
switches 0:5c4d7b2438d3 82 }
switches 0:5c4d7b2438d3 83 return -1;
switches 0:5c4d7b2438d3 84 }
switches 0:5c4d7b2438d3 85
switches 0:5c4d7b2438d3 86 void CallChain::clear() {
switches 0:5c4d7b2438d3 87 CallChainLink *link = _chain;
switches 0:5c4d7b2438d3 88 _chain = NULL;
switches 0:5c4d7b2438d3 89 while (link != NULL) {
switches 0:5c4d7b2438d3 90 CallChainLink *temp = link->next;
switches 0:5c4d7b2438d3 91 delete link;
switches 0:5c4d7b2438d3 92 link = temp;
switches 0:5c4d7b2438d3 93 }
switches 0:5c4d7b2438d3 94 }
switches 0:5c4d7b2438d3 95
switches 0:5c4d7b2438d3 96 bool CallChain::remove(pFunctionPointer_t f) {
switches 0:5c4d7b2438d3 97 CallChainLink *link = _chain;
switches 0:5c4d7b2438d3 98 while (link != NULL) {
switches 0:5c4d7b2438d3 99 if (f == &link->cb) {
switches 0:5c4d7b2438d3 100 delete link;
switches 0:5c4d7b2438d3 101 return true;
switches 0:5c4d7b2438d3 102 }
switches 0:5c4d7b2438d3 103 link = link->next;
switches 0:5c4d7b2438d3 104 }
switches 0:5c4d7b2438d3 105 return false;
switches 0:5c4d7b2438d3 106 }
switches 0:5c4d7b2438d3 107
switches 0:5c4d7b2438d3 108 void CallChain::call() {
switches 0:5c4d7b2438d3 109 CallChainLink *link = _chain;
switches 0:5c4d7b2438d3 110 while (link != NULL) {
switches 0:5c4d7b2438d3 111 link->cb.call();
switches 0:5c4d7b2438d3 112 link = link->next;
switches 0:5c4d7b2438d3 113 }
switches 0:5c4d7b2438d3 114 }
switches 0:5c4d7b2438d3 115
switches 0:5c4d7b2438d3 116 } // namespace mbed