Compare commits

..

6 Commits

12 changed files with 99 additions and 45 deletions

View File

@ -7,6 +7,7 @@
#include <stdlib.h>
#include <msp430g2553.h>
#include "PontCoopScheduler.h"
@ -15,7 +16,7 @@ tTask tasks[MAX_NUM_OF_TASKS];
void schInit() {
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
tasks[i].delay = 0;
tasks[i].period = 0;
tasks[i].run = 0;
@ -25,7 +26,7 @@ void schInit() {
}
void schAdd(void (*exec)(void *), void *handle, uint32_t delay, uint32_t period) {
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
if (tasks[i].exec == NULL) {
tasks[i].delay = delay;
tasks[i].period = period;
@ -41,23 +42,34 @@ void schAdd(void (*exec)(void *), void *handle, uint32_t delay, uint32_t period)
}
}
/*
void schDel(void (*exec)(void *), void *handle) {
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
if ((tasks[i].exec == exec) && (tasks[i].handle == handle)) {
tasks[i].exec = NULL;
break;
}
}
}
*/
void schExec() {
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
// synchronize access to tasks[].run
__disable_interrupt();
if (tasks[i].exec != NULL && tasks[i].run > 0) {
tasks[i].run--;
// synchronize access to tasks[].run
// reenable interrupts before actually executing task
__enable_interrupt();
tasks[i].exec(tasks[i].handle);
if (tasks[i].period == 0) {
tasks[i].exec = NULL;
}
} else {
// synchronize access to tasks[].run
// reenable interrupts in case task is not yet executable
__enable_interrupt();
}
}
}
@ -65,7 +77,7 @@ void schExec() {
void schUpdate() {
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
if (tasks[i].exec != NULL) {
if (tasks[i].delay == 0) {
tasks[i].delay = tasks[i].period;
@ -76,13 +88,3 @@ void schUpdate() {
}
}
}
uint8_t schTaskCnt() {
uint8_t cnt = 0;
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
if (tasks[i].exec != NULL){
cnt++;
}
}
return cnt;
}

View File

@ -28,4 +28,6 @@ void canvasShow() {
displayDriverTransferCanvas();
}
void canvasSetPixel(uint8_t column, uint8_t row, uint8_t color) {
*((canvas.canvas) + (row * canvas.width + column)) = (color + 0x80);
}

View File

@ -17,6 +17,7 @@ typedef struct {
void canvasInit();
canvas_t *canvasGet();
void canvasShow();
void canvasSetPixel(uint8_t column, uint8_t row, uint8_t color);

View File

@ -34,7 +34,7 @@ void displayDriverInit() {
UCB0CTL0 = UCMST;
// SPI timing config
UCB0CTL1 = UCSSEL_3;
UCB0BR0 = 8;
UCB0BR0 = 4; // 2 would be too fast and ends up with errors
UCB0BR1 = 0;
// BIT5: UCB0CLK

View File

@ -4,19 +4,84 @@
static canvas_t *canvas;
static uint8_t lastPixel = 0xff;
static uint8_t currentPixel = 0;
#define MAX_COLOR 0x0d
void displayTestExec(void *args) {
if (lastPixel != 0xff) {
*((canvas->canvas)+lastPixel) = 0x80;
static uint8_t last = 0xff;
static uint8_t current = 0;
static uint8_t color = 0x01;
static uint8_t state = 1;
switch (state) {
case 0:
for (uint16_t i = 0; i < canvas->height; i++) {
canvasSetPixel(last, i, 0);
}
last = 0xff;
state = 1;
case 1:
if (last != 0xff) {
*((canvas->canvas)+last) = 0x80;
}
last = current;
*((canvas->canvas)+current) = (color + 0x80);
current++;
if (current >= canvas->size) {
current = 0;
state = 2;
}
break;
case 2:
*((canvas->canvas)+last) = 0x80;
last = 0xff;
state = 3;
case 3:
if (last != 0xff) {
for (uint16_t i = 0; i < canvas->width; i++) {
canvasSetPixel(i, last, 0);
}
}
last = current;
for (uint16_t i = 0; i < canvas->width; i++) {
canvasSetPixel(i, current, color);
}
current++;
if (current >= canvas->height) {
current = 0;
state = 4;
}
break;
case 4:
for (uint16_t i = 0; i < canvas->width; i++) {
canvasSetPixel(i, last, 0);
}
last = 0xff;
state = 5;
case 5:
if (last != 0xff) {
for (uint16_t i = 0; i < canvas->height; i++) {
canvasSetPixel(last, i, 0);
}
}
last = current;
for (uint16_t i = 0; i < canvas->height; i++) {
canvasSetPixel(current, i, color);
}
current++;
if (current >= canvas->width) {
current = 0;
state = 0;
}
break;
}
lastPixel = currentPixel;
*((canvas->canvas)+currentPixel) = 0x81;
currentPixel++;
if (currentPixel >= canvas->size) {
currentPixel = 0;
color++;
if (color > MAX_COLOR) {
color = 1;
}
canvasShow();

BIN
docs/1second.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
docs/one-color.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
docs/working-transfer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

4
led.c
View File

@ -21,7 +21,7 @@ void ledBlueOff() {
}
void ledExec(void *args) {
static int i = 0;
static uint16_t i = 0;
if (i == 0) {
ledGreenOff();
@ -41,7 +41,7 @@ void ledInit() {
ledBlueOff();
// schAdd(ledExec, NULL, 0, 50);
schAdd(ledExec, NULL, 0, 500);
}

2
main.c
View File

@ -29,7 +29,7 @@ int main() {
ledInit();
displayDriverInit();
canvasInit();
displayTestInit();
displayTestInit();
__enable_interrupt();

14
time.c
View File

@ -1,30 +1,16 @@
#include <msp430g2553.h>
#include <stdint.h>
#include "time.h"
#include "PontCoopScheduler.h"
volatile uint32_t timestamp;
void __attribute__ ((interrupt (TIMER0_A0_VECTOR))) ta0_isr() {
timestamp++;
schUpdate();
}
void timeInit() {
timestamp = 0;
TACCR0 = 32;
TACCTL0 = CCIE;
TACTL = MC_1 | ID_0 | TASSEL_1 | TACLR;
}
uint32_t getMillis() {
return timestamp;
}
void ms_active_delay(uint16_t delay) {
uint32_t start = timestamp;
while (start + delay > timestamp);
}

2
time.h
View File

@ -4,8 +4,6 @@
#include <stdint.h>
void timeInit();
uint32_t getMillis();
void ms_active_delay(uint16_t delay);