Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
plc/Digitalio.cpp@2:d1c24eae74d5, 2018-09-16 (annotated)
- Committer:
- citolin
- Date:
- Sun Sep 16 17:28:48 2018 +0000
- Revision:
- 2:d1c24eae74d5
- Parent:
- 0:40a00c231fbd
Added a mutex in the state memory space. Also added a example for power supply station.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| citolin | 0:40a00c231fbd | 1 | /* |
| citolin | 0:40a00c231fbd | 2 | * Digitalio.cpp |
| citolin | 0:40a00c231fbd | 3 | * |
| citolin | 0:40a00c231fbd | 4 | * Created on: Jul 9, 2018 |
| citolin | 0:40a00c231fbd | 5 | * Author: Claudio Pinheiro |
| citolin | 0:40a00c231fbd | 6 | */ |
| citolin | 0:40a00c231fbd | 7 | |
| citolin | 0:40a00c231fbd | 8 | #include <plc/Digitalio.h> |
| citolin | 0:40a00c231fbd | 9 | |
| citolin | 0:40a00c231fbd | 10 | DigitalIO::DigitalIO() : i2cBus1(p9, p10), |
| citolin | 0:40a00c231fbd | 11 | i2cBus2(p28, p27), |
| citolin | 0:40a00c231fbd | 12 | PLC_IO(&i2cBus1, 0, 1), |
| citolin | 0:40a00c231fbd | 13 | EXT0_IO(&i2cBus2, 0, 1), |
| citolin | 0:40a00c231fbd | 14 | EXT1_IO(&i2cBus2, 2, 3), |
| citolin | 0:40a00c231fbd | 15 | EXT2_IO(&i2cBus2, 4, 5), |
| citolin | 0:40a00c231fbd | 16 | EXT3_IO(&i2cBus2, 6, 7), |
| citolin | 0:40a00c231fbd | 17 | pc(USBTX, USBRX) |
| citolin | 0:40a00c231fbd | 18 | { |
| citolin | 0:40a00c231fbd | 19 | boards[0] = &PLC_IO; |
| citolin | 0:40a00c231fbd | 20 | boards[1] = &EXT0_IO; |
| citolin | 0:40a00c231fbd | 21 | boards[2] = &EXT1_IO; |
| citolin | 0:40a00c231fbd | 22 | boards[3] = &EXT2_IO; |
| citolin | 0:40a00c231fbd | 23 | boards[4] = &EXT3_IO; |
| citolin | 0:40a00c231fbd | 24 | |
| citolin | 0:40a00c231fbd | 25 | inputTicker.attach_us(callback(this, &DigitalIO::inputReader), 1000*SAMPLER_PERIOD_MS); |
| citolin | 0:40a00c231fbd | 26 | outputTicker.attach_us(callback(this, &DigitalIO::outputWriter), 1000*SAMPLER_PERIOD_MS); |
| citolin | 0:40a00c231fbd | 27 | |
| citolin | 0:40a00c231fbd | 28 | } |
| citolin | 0:40a00c231fbd | 29 | |
| citolin | 0:40a00c231fbd | 30 | DigitalIO::~DigitalIO() { |
| citolin | 0:40a00c231fbd | 31 | // TODO Auto-generated destructor stub |
| citolin | 0:40a00c231fbd | 32 | } |
| citolin | 0:40a00c231fbd | 33 | |
| citolin | 0:40a00c231fbd | 34 | void DigitalIO::inputReader(void) { |
| citolin | 0:40a00c231fbd | 35 | int i; |
| citolin | 0:40a00c231fbd | 36 | short buffer = 0; |
| citolin | 0:40a00c231fbd | 37 | _mutex.lock(); |
| citolin | 0:40a00c231fbd | 38 | for (i = 0; i < 5; i++) { |
| citolin | 0:40a00c231fbd | 39 | boards[i]->readWord(&buffer); |
| citolin | 0:40a00c231fbd | 40 | ioBuffer[i] = buffer; |
| citolin | 0:40a00c231fbd | 41 | } |
| citolin | 0:40a00c231fbd | 42 | _mutex.unlock(); |
| citolin | 0:40a00c231fbd | 43 | } |
| citolin | 0:40a00c231fbd | 44 | |
| citolin | 0:40a00c231fbd | 45 | void DigitalIO::outputWriter(void) { |
| citolin | 0:40a00c231fbd | 46 | int i; |
| citolin | 0:40a00c231fbd | 47 | short buffer = 0; |
| citolin | 0:40a00c231fbd | 48 | _mutex.lock(); |
| citolin | 0:40a00c231fbd | 49 | for (i = 0; i < 5; i++) { |
| citolin | 0:40a00c231fbd | 50 | buffer = (short) ioBuffer[5 + i].to_ulong(); |
| citolin | 0:40a00c231fbd | 51 | boards[i]->writeWord(buffer); |
| citolin | 0:40a00c231fbd | 52 | //inBuffer_[i] = buffer; |
| citolin | 0:40a00c231fbd | 53 | } |
| citolin | 0:40a00c231fbd | 54 | _mutex.unlock(); |
| citolin | 0:40a00c231fbd | 55 | |
| citolin | 0:40a00c231fbd | 56 | } |